{"version":3,"file":"lithentFTags.mjs","sources":["../src/index.ts"],"sourcesContent":["import { h, Fragment, isPropType, lmountComponentSet } from 'lithent';\nimport type {\n  Props,\n  WDom,\n  FragmentFunction,\n  MiddleStateWDom,\n  Component,\n  LComponent,\n  TagFunction,\n} from 'lithent';\n\ntype FFunction = (...param: (Props | MiddleStateWDom)[]) => WDom;\ntype FTags = {\n  [tagName: string]: FFunction;\n};\n\nexport const fTags: FTags = new Proxy(\n  {},\n  {\n    get(_: {}, tagName: string) {\n      return (...param: (Props | MiddleStateWDom)[]) => {\n        const props = param[0];\n        const childrens = param.slice(1);\n\n        if (isPropType(props)) {\n          return h(tagName, props || {}, ...childrens);\n        } else if (props !== undefined) {\n          return h(tagName, {}, props, ...childrens);\n        }\n\n        return h(tagName, {}, ...childrens);\n      };\n    },\n  }\n);\n\nexport const fFragment = (...children: MiddleStateWDom[]) => {\n  return h(Fragment as FragmentFunction, {}, ...children);\n};\n\nexport const fMount = <T>(component: Component<T>) => {\n  const tagFunction = (_props: T, _children: WDom[]) => component;\n\n  return (\n    ...param: unknown extends T\n      ? (Props | MiddleStateWDom)[]\n      : [T, ...MiddleStateWDom[]]\n  ) => {\n    const props = param[0];\n    const children = param.slice(1) as MiddleStateWDom[];\n\n    if (isPropType(props)) {\n      return h(tagFunction as TagFunction, props || {}, ...children);\n    } else if (props !== undefined) {\n      return h(tagFunction as TagFunction, {}, props, ...children);\n    }\n\n    return h(tagFunction as TagFunction, {}, ...children);\n  };\n};\n\nexport const flMount = <T>(component: LComponent<T>) => {\n  const tagFunction = (_props: T, _children: WDom[]) => component;\n\n  // Register component in lmountComponentSet for automatic state management\n  lmountComponentSet.add(component);\n\n  return (\n    ...param: unknown extends T\n      ? (Props | MiddleStateWDom)[]\n      : [T, ...MiddleStateWDom[]]\n  ) => {\n    const props = param[0];\n    const children = param.slice(1) as MiddleStateWDom[];\n\n    if (isPropType(props)) {\n      return h(tagFunction as unknown as TagFunction, props || {}, ...children);\n    } else if (props !== undefined) {\n      return h(tagFunction as unknown as TagFunction, {}, props, ...children);\n    }\n\n    return h(tagFunction as unknown as TagFunction, {}, ...children);\n  };\n};\n"],"names":["fTags","_","tagName","param","props","childrens","isPropType","h","fFragment","children","Fragment","fMount","component","tagFunction","_props","_children","flMount","lmountComponentSet"],"mappings":";AAgBO,MAAMA,IAAe,IAAI;AAAA,EAC9B,CAAC;AAAA,EACD;AAAA,IACE,IAAIC,GAAOC,GAAiB;AAC1B,aAAO,IAAIC,MAAuC;AAC1C,cAAAC,IAAQD,EAAM,CAAC,GACfE,IAAYF,EAAM,MAAM,CAAC;AAE3B,eAAAG,EAAWF,CAAK,IACXG,EAAEL,GAASE,KAAS,CAAA,GAAI,GAAGC,CAAS,IAClCD,MAAU,SACZG,EAAEL,GAAS,CAAA,GAAIE,GAAO,GAAGC,CAAS,IAGpCE,EAAEL,GAAS,IAAI,GAAGG,CAAS;AAAA,MAAA;AAAA,IAEtC;AAAA,EACF;AACF,GAEaG,IAAY,IAAIC,MACpBF,EAAEG,GAA8B,IAAI,GAAGD,CAAQ,GAG3CE,IAAS,CAAIC,MAA4B;AAC9C,QAAAC,IAAc,CAACC,GAAWC,MAAsBH;AAEtD,SAAO,IACFT,MAGA;AACG,UAAAC,IAAQD,EAAM,CAAC,GACfM,IAAWN,EAAM,MAAM,CAAC;AAE1B,WAAAG,EAAWF,CAAK,IACXG,EAAEM,GAA4BT,KAAS,CAAA,GAAI,GAAGK,CAAQ,IACpDL,MAAU,SACZG,EAAEM,GAA4B,CAAA,GAAIT,GAAO,GAAGK,CAAQ,IAGtDF,EAAEM,GAA4B,IAAI,GAAGJ,CAAQ;AAAA,EAAA;AAExD,GAEaO,IAAU,CAAIJ,MAA6B;AAChD,QAAAC,IAAc,CAACC,GAAWC,MAAsBH;AAGtD,SAAAK,EAAmB,IAAIL,CAAS,GAEzB,IACFT,MAGA;AACG,UAAAC,IAAQD,EAAM,CAAC,GACfM,IAAWN,EAAM,MAAM,CAAC;AAE1B,WAAAG,EAAWF,CAAK,IACXG,EAAEM,GAAuCT,KAAS,CAAA,GAAI,GAAGK,CAAQ,IAC/DL,MAAU,SACZG,EAAEM,GAAuC,CAAA,GAAIT,GAAO,GAAGK,CAAQ,IAGjEF,EAAEM,GAAuC,IAAI,GAAGJ,CAAQ;AAAA,EAAA;AAEnE;"}