UNPKG

flexium

Version:

A lightweight, signals-based UI framework with cross-platform renderers

1 lines 6.56 kB
{"version":3,"sources":["../src/jsx-runtime.ts"],"names":["flattenChildren","children","result","i","child","flattened","j","filterChildren","jsx","type","props","key","restProps","k","normalizedChildren","createVNode","jsxs","Fragment"],"mappings":"4CAwCA,SAASA,CAAAA,CAAgBC,EAAwB,CAC/C,IAAMC,EAAgB,EAAC,CAEvB,IAAA,IAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAIF,EAAS,MAAA,CAAQE,CAAAA,EAAAA,CAAK,CACxC,IAAMC,CAAAA,CAAQH,CAAAA,CAASE,CAAC,CAAA,CACxB,GAAI,KAAA,CAAM,OAAA,CAAQC,CAAK,CAAA,CAAG,CACxB,IAAMC,CAAAA,CAAYL,EAAgBI,CAAK,CAAA,CACvC,QAASE,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAID,CAAAA,CAAU,MAAA,CAAQC,CAAAA,EAAAA,CACpCJ,EAAO,IAAA,CAAKG,CAAAA,CAAUC,CAAC,CAAC,EAE5B,CAAA,KACEJ,EAAO,IAAA,CAAKE,CAAK,EAErB,CAEA,OAAOF,CACT,CAMA,SAASK,CAAAA,CAAeN,EAAwB,CAC9C,IAAMC,EAAgB,EAAC,CACvB,IAAA,IAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAIF,EAAS,MAAA,CAAQE,CAAAA,EAAAA,CAAK,CACxC,IAAMC,CAAAA,CAAQH,CAAAA,CAASE,CAAC,CAAA,CACpBC,CAAAA,EAAU,IAAA,EAA+BA,CAAAA,GAAU,KAAA,EACrDF,CAAAA,CAAO,KAAKE,CAAK,EAErB,CACA,OAAOF,CACT,CASO,SAASM,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACO,CAGP,IAAMC,CAAAA,CAAMD,EAAM,GAAA,CACZE,CAAAA,CAAiC,EAAC,CAExC,IAAA,IAAWC,CAAAA,IAAKH,EACVG,CAAAA,GAAM,KAAA,EAASA,CAAAA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Flexium.\n * It implements the new JSX transform introduced in React 17+.\n *\n * With automatic JSX runtime, you no longer need to import `h`:\n *\n * Before (classic):\n * ```tsx\n * import { h } from 'flexium/dom'\n * function App() {\n * return <div>Hello</div>\n * }\n * ```\n *\n * After (automatic):\n * ```tsx\n * function App() {\n * return <div>Hello</div>\n * }\n * ```\n *\n * Usage in tsconfig.json:\n * ```json\n * {\n * \"compilerOptions\": {\n * \"jsx\": \"react-jsx\",\n * \"jsxImportSource\": \"flexium\"\n * }\n * }\n * ```\n */\n\nimport type { VNode } from './core/renderer';\nimport { createVNode } from './core/vnode';\n\n/**\n * Flatten nested children arrays\n */\nfunction flattenChildren(children: any[]): any[] {\n const result: any[] = [];\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (Array.isArray(child)) {\n const flattened = flattenChildren(child);\n for (let j = 0; j < flattened.length; j++) {\n result.push(flattened[j]);\n }\n } else {\n result.push(child);\n }\n }\n\n return result;\n}\n\n/**\n * Filter out null, undefined, and false children\n * Optimized for performance using a simple loop\n */\nfunction filterChildren(children: any[]): any[] {\n const result: any[] = [];\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (child !== null && child !== undefined && child !== false) {\n result.push(child);\n }\n }\n return result;\n}\n\n/**\n * JSX runtime function for elements with multiple children\n *\n * @param type - Element type (string for built-in, function for components)\n * @param props - Element properties including children\n * @returns Virtual node\n */\nexport function jsx(\n type: string | Function,\n props: Record<string, any>\n): VNode {\n // Extract children from props\n // Manual extraction is faster than destructuring\n const key = props.key;\n const restProps: Record<string, any> = {};\n \n for (const k in props) {\n if (k !== 'key' && k !== 'children') {\n restProps[k] = props[k];\n }\n }\n\n let children = props.children;\n let normalizedChildren: any[] = [];\n\n if (children !== undefined) {\n if (Array.isArray(children)) {\n // Recursively flatten and then filter\n normalizedChildren = filterChildren(flattenChildren(children));\n } else if (children !== null && children !== false) {\n // Single child optimization\n normalizedChildren = [children];\n }\n }\n\n return createVNode(type, restProps, normalizedChildren, key);\n}\n\n/**\n * JSX runtime function for elements with static children\n * (optimization hint from the compiler)\n *\n * @param type - Element type\n * @param props - Element properties\n * @returns Virtual node\n */\nexport function jsxs(\n type: string | Function,\n props: Record<string, any>\n): VNode {\n // For jsxs, we know children is an array passed as a prop\n // We can skip flattening, but we still need to filter\n \n const key = props.key;\n const restProps: Record<string, any> = {};\n \n for (const k in props) {\n if (k !== 'key' && k !== 'children') {\n restProps[k] = props[k];\n }\n }\n\n let normalizedChildren: any[] = [];\n const children = props.children;\n\n if (Array.isArray(children)) {\n // Skip recursive flattening for jsxs, just filter\n normalizedChildren = filterChildren(children);\n } else if (children !== undefined && children !== null && children !== false) {\n normalizedChildren = [children];\n }\n\n return createVNode(type, restProps, normalizedChildren, key);\n}\n\n/**\n * Fragment component for JSX\n * Renders children without a wrapper element\n */\nexport function Fragment(props: { children?: any[] }): VNode {\n return createVNode('fragment', {}, props.children || []);\n}\n\n/**\n * JSX runtime for development (same as production for now)\n */\nexport { jsx as jsxDEV };\n\nexport namespace JSX {\n export interface IntrinsicElements {\n [elemName: string]: any;\n }\n export type Element = any;\n export interface ElementClass {\n render: any;\n }\n export interface ElementAttributesProperty {\n props: any;\n }\n export interface ElementChildrenAttribute {\n children: {};\n }\n}\n"]}