@fluixi/compiler 1.0.0-alpha.82 → 1.0.0-alpha.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dist/analyze/expr-shape.cjs +62 -1
  2. package/dist/analyze/expr-shape.d.cts +14 -0
  3. package/dist/analyze/expr-shape.mjs +41 -1
  4. package/dist/analyze/intrinsics.cjs +80 -1
  5. package/dist/analyze/intrinsics.d.cts +66 -0
  6. package/dist/analyze/intrinsics.mjs +59 -1
  7. package/dist/analyze/paren.cjs +134 -0
  8. package/dist/analyze/paren.d.cts +23 -0
  9. package/dist/analyze/paren.d.ts +24 -0
  10. package/dist/analyze/paren.d.ts.map +1 -0
  11. package/dist/analyze/paren.js +168 -0
  12. package/dist/analyze/paren.mjs +113 -0
  13. package/dist/analyze/props-destructure.cjs +226 -1
  14. package/dist/analyze/props-destructure.d.cts +83 -0
  15. package/dist/analyze/props-destructure.mjs +205 -1
  16. package/dist/analyze/reactive-bindings.cjs +190 -1
  17. package/dist/analyze/reactive-bindings.d.cts +42 -0
  18. package/dist/analyze/reactive-bindings.mjs +167 -1
  19. package/dist/analyze/reactive-expr.cjs +38 -1
  20. package/dist/analyze/reactive-expr.d.cts +38 -0
  21. package/dist/analyze/reactive-expr.mjs +17 -1
  22. package/dist/analyze/static-graph.cjs +811 -0
  23. package/dist/analyze/static-graph.d.cts +102 -0
  24. package/dist/analyze/static-graph.d.ts +103 -0
  25. package/dist/analyze/static-graph.d.ts.map +1 -0
  26. package/dist/analyze/static-graph.js +869 -0
  27. package/dist/analyze/static-graph.mjs +793 -0
  28. package/dist/babel-NRW4EFTG.mjs +636 -0
  29. package/dist/chunk-3YKZ4GNH.mjs +11 -0
  30. package/dist/chunk-EZR7NZOY.mjs +1718 -0
  31. package/dist/chunk-FSSWUXUR.mjs +16 -0
  32. package/dist/chunk-MJV3UXIL.mjs +158 -0
  33. package/dist/chunk-R2VHAZAX.mjs +1078 -0
  34. package/dist/codegen/backend.cjs +18 -1
  35. package/dist/codegen/backend.d.cts +35 -0
  36. package/dist/codegen/backends/imperative.cjs +542 -1
  37. package/dist/codegen/backends/imperative.d.cts +11 -0
  38. package/dist/codegen/backends/imperative.d.ts.map +1 -1
  39. package/dist/codegen/backends/imperative.js +68 -13
  40. package/dist/codegen/backends/imperative.mjs +519 -1
  41. package/dist/codegen/contract.cjs +52 -1
  42. package/dist/codegen/contract.d.cts +24 -0
  43. package/dist/codegen/contract.mjs +31 -1
  44. package/dist/codegen/partial-template.cjs +176 -1
  45. package/dist/codegen/partial-template.d.cts +61 -0
  46. package/dist/codegen/partial-template.mjs +153 -1
  47. package/dist/codegen/serialize-static.cjs +125 -1
  48. package/dist/codegen/serialize-static.d.cts +38 -0
  49. package/dist/codegen/serialize-static.d.ts +16 -0
  50. package/dist/codegen/serialize-static.d.ts.map +1 -1
  51. package/dist/codegen/serialize-static.js +25 -0
  52. package/dist/codegen/serialize-static.mjs +104 -1
  53. package/dist/frontend/babel/build-ir-lit.cjs +1509 -1
  54. package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
  55. package/dist/frontend/babel/build-ir-lit.mjs +1478 -1
  56. package/dist/frontend/babel/build-ir.cjs +1524 -1
  57. package/dist/frontend/babel/build-ir.d.cts +35 -0
  58. package/dist/frontend/babel/build-ir.mjs +1495 -1
  59. package/dist/frontend/babel/index.cjs +2186 -1
  60. package/dist/frontend/babel/index.d.cts +33 -0
  61. package/dist/frontend/babel/index.mjs +2156 -1
  62. package/dist/frontend/babel/lower-template.cjs +1507 -1
  63. package/dist/frontend/babel/lower-template.d.cts +23 -0
  64. package/dist/frontend/babel/lower-template.mjs +1478 -1
  65. package/dist/frontend/babel/plugin.cjs +2132 -1
  66. package/dist/frontend/babel/plugin.d.cts +95 -0
  67. package/dist/frontend/babel/plugin.mjs +2103 -1
  68. package/dist/frontend/babel/server-functions.cjs +110 -1
  69. package/dist/frontend/babel/server-functions.d.cts +10 -0
  70. package/dist/frontend/babel/server-functions.mjs +89 -1
  71. package/dist/frontend/babel/types.cjs +18 -1
  72. package/dist/frontend/babel/types.d.cts +33 -0
  73. package/dist/frontend/types.cjs +18 -1
  74. package/dist/frontend/types.d.cts +25 -0
  75. package/dist/frontend/vocabulary.cjs +98 -0
  76. package/dist/frontend/vocabulary.d.cts +79 -0
  77. package/dist/frontend/vocabulary.d.ts +80 -0
  78. package/dist/frontend/vocabulary.d.ts.map +1 -0
  79. package/dist/frontend/vocabulary.js +124 -0
  80. package/dist/frontend/vocabulary.mjs +77 -0
  81. package/dist/index.cjs +1594 -13
  82. package/dist/index.d.cts +27 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +3 -0
  85. package/dist/index.mjs +1574 -13
  86. package/dist/integrations.cjs +4307 -25
  87. package/dist/integrations.d.cts +215 -0
  88. package/dist/integrations.d.ts +16 -0
  89. package/dist/integrations.d.ts.map +1 -1
  90. package/dist/integrations.js +21 -2
  91. package/dist/integrations.mjs +531 -17
  92. package/dist/ir/nodes.cjs +18 -1
  93. package/dist/ir/nodes.d.cts +168 -0
  94. package/dist/ir/nodes.d.ts +46 -0
  95. package/dist/ir/nodes.d.ts.map +1 -1
  96. package/dist/lower/compile-template.cjs +1356 -1
  97. package/dist/lower/compile-template.d.cts +69 -0
  98. package/dist/lower/compile-template.d.ts +12 -0
  99. package/dist/lower/compile-template.d.ts.map +1 -1
  100. package/dist/lower/compile-template.js +5 -1
  101. package/dist/lower/compile-template.mjs +1336 -1
  102. package/dist/lower/jsx.cjs +529 -1
  103. package/dist/lower/jsx.d.cts +25 -0
  104. package/dist/lower/jsx.d.ts +2 -0
  105. package/dist/lower/jsx.d.ts.map +1 -1
  106. package/dist/lower/jsx.js +27 -4
  107. package/dist/lower/jsx.mjs +506 -1
  108. package/dist/lower/template.cjs +1061 -1
  109. package/dist/lower/template.d.cts +53 -0
  110. package/dist/lower/template.d.ts +14 -1
  111. package/dist/lower/template.d.ts.map +1 -1
  112. package/dist/lower/template.js +106 -19
  113. package/dist/lower/template.mjs +1042 -1
  114. package/dist/lower/text.cjs +42 -1
  115. package/dist/lower/text.d.cts +10 -0
  116. package/dist/lower/text.mjs +21 -1
  117. package/dist/optimize/analyze-static.cjs +112 -1
  118. package/dist/optimize/analyze-static.d.cts +39 -0
  119. package/dist/optimize/analyze-static.mjs +91 -1
  120. package/dist/optimize/collapse-strategies.cjs +90 -1
  121. package/dist/optimize/collapse-strategies.d.cts +30 -0
  122. package/dist/optimize/collapse-strategies.mjs +67 -1
  123. package/dist/options.cjs +33 -1
  124. package/dist/options.d.cts +39 -0
  125. package/dist/options.mjs +12 -1
  126. package/dist/resolve/builtins.cjs +73 -1
  127. package/dist/resolve/builtins.d.cts +68 -0
  128. package/dist/resolve/builtins.mjs +53 -1
  129. package/dist/resolve/component-globals.cjs +233 -13
  130. package/dist/resolve/component-globals.d.cts +80 -0
  131. package/dist/resolve/component-globals.mjs +210 -13
  132. package/dist/resolve/component-resolver.cjs +80 -1
  133. package/dist/resolve/component-resolver.d.cts +68 -0
  134. package/dist/resolve/component-resolver.mjs +59 -1
  135. package/dist/resolve/load-directive.cjs +93 -1
  136. package/dist/resolve/load-directive.d.cts +53 -0
  137. package/dist/resolve/load-directive.mjs +72 -1
  138. package/dist/resolve/resolve-ir.cjs +108 -1
  139. package/dist/resolve/resolve-ir.d.cts +53 -0
  140. package/dist/resolve/resolve-ir.mjs +85 -1
  141. package/dist/resolve/write-globals.cjs +318 -13
  142. package/dist/resolve/write-globals.d.cts +30 -0
  143. package/dist/resolve/write-globals.mjs +297 -13
  144. package/dist/server-fns-4ZXN6DYU.mjs +78 -0
  145. package/dist/server-functions-V6D6DRIA.mjs +82 -0
  146. package/dist/transform/bindings.cjs +71 -1
  147. package/dist/transform/bindings.d.cts +16 -0
  148. package/dist/transform/bindings.mjs +50 -1
  149. package/dist/transform/index.cjs +2732 -8
  150. package/dist/transform/index.d.cts +15 -0
  151. package/dist/transform/index.mjs +3773 -17
  152. package/dist/transform/intrinsics.cjs +216 -3
  153. package/dist/transform/intrinsics.d.cts +21 -0
  154. package/dist/transform/intrinsics.mjs +193 -3
  155. package/dist/transform/props.cjs +441 -3
  156. package/dist/transform/props.d.cts +45 -0
  157. package/dist/transform/props.mjs +1482 -12
  158. package/dist/transform/server-fn-id.cjs +35 -1
  159. package/dist/transform/server-fn-id.d.cts +9 -0
  160. package/dist/transform/server-fn-id.mjs +14 -1
  161. package/dist/transform/server-fns.cjs +114 -2
  162. package/dist/transform/server-fns.d.cts +12 -0
  163. package/dist/transform/server-fns.mjs +1155 -11
  164. package/dist/transform/source-locations.cjs +330 -0
  165. package/dist/transform/source-locations.d.cts +43 -0
  166. package/dist/transform/source-locations.d.ts +44 -0
  167. package/dist/transform/source-locations.d.ts.map +1 -0
  168. package/dist/transform/source-locations.js +238 -0
  169. package/dist/transform/source-locations.mjs +307 -0
  170. package/dist/transform/templates.cjs +2701 -7
  171. package/dist/transform/templates.d.cts +69 -0
  172. package/dist/transform/templates.d.ts +12 -4
  173. package/dist/transform/templates.d.ts.map +1 -1
  174. package/dist/transform/templates.js +72 -7
  175. package/dist/transform/templates.mjs +3743 -16
  176. package/dist/transform-BT4MMASR.mjs +893 -0
  177. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  178. package/package.json +6 -5
  179. package/dist/babel-4JUDAR2G.mjs +0 -1
  180. package/dist/chunk-3SAEGOMQ.mjs +0 -1
  181. package/dist/chunk-IBRM4W7I.mjs +0 -10
  182. package/dist/chunk-OHHZCYIQ.mjs +0 -1
  183. package/dist/chunk-PVR2SN3B.mjs +0 -1
  184. package/dist/chunk-QUIYULS2.mjs +0 -1
  185. package/dist/chunk-YR3SAEO7.mjs +0 -1
  186. package/dist/server-fns-6QM243HC.mjs +0 -2
  187. package/dist/server-functions-E3LKCZ4R.mjs +0 -1
  188. package/dist/transform-5WC4FWJE.mjs +0 -8
package/dist/index.mjs CHANGED
@@ -1,22 +1,1583 @@
1
- var Ie="children";function Ee(t){switch(t.kind){case"call":return!0;case"member":return t.property!==Ie;case"compound":return t.parts.some(Ee);case"opaque":return!1}}import{parseTemplate as Je}from"@fluixi/template-parser";var $={kind:"eager"},Ce=["pointerdown","focusin","keydown"],q=new Set(["eager","idle","visible","interaction","media","never"]),x=class extends Error{};function K(t,e){let n=t.slice(5);if(!q.has(n))throw new x(`Unknown load strategy 'load:${n}'. Expected one of ${[...q].join(", ")}.`);switch(n){case"eager":return $;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return e?{kind:"visible",rootMargin:e}:{kind:"visible"};case"interaction":return{kind:"interaction",events:e?$e(e):[...Ce]};case"media":if(!e)throw new x(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new x(`Unhandled load strategy '${n}'.`)}}function $e(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new x("'load:interaction' was given no event names.");return e}function Z(t){return t.kind!=="eager"&&t.kind!=="never"}var we=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Y={className:"class",htmlFor:"for"},Se=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Te=new Set(["script","style","textarea","title"]);function L(t){return Te.has(t)}function X(t){return Y[t]??t}function k(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!Se.has(t.name)}function _(t){if(!t.static||L(t.tag))return!1;for(let e of t.props)if(!k(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&_(e)))return!1;return!0}function y(t){let e=t.props.map(Me).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return we.has(t.tag)?n:`${n}${t.children.map(Oe).join("")}</${t.tag}>`}function Oe(t){if(t.kind==="text")return Ae(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return y(t)}function Me(t){let e=Y[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${Pe(String(n))}"`}function Pe(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Ae(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var je="<!--fx-->",De="<!--fx/-->";function S(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function Le(t){return t.kind==="text"||t.kind==="element"&&Q(t)}function Q(t){return t.svg||L(t.tag)||!t.props.every(e=>k(e))?!1:t.children.every(e=>Le(e)||S(e))}function w(t){if(S(t))return!0;let e=t.children;return e?e.some(w):!1}function ee(t){for(let e=0;e<t.children.length;e++){let n=t.children[e];if(n.kind==="text"&&(n.value===""||t.children[e+1]?.kind==="text"))return!1}return t.children.every(e=>e.kind!=="element"||ee(e))}function te(t){if(!Q(t)||!ee(t)||!t.children.some(w))return null;let e=[],n=[],o=0,r=a=>{let s=`_n$${o++}`;return e.push({ref:s,expr:a}),s};return i(t,"_el$"),{html:_e(t),tag:t.tag,steps:e,holes:n};function i(a,s){let l=-1;a.children.forEach((d,p)=>{w(d)&&(l=p)});let c=null;for(let d=0;d<=l;d++){let p=a.children[d],m=c?`${c}.nextSibling`:`${s}.firstChild`;if(S(p)){let R=r(m),D=r(`holeEnd(${R})`);n.push({parentRef:s,startRef:R,endRef:D,node:p}),c=D;continue}let g=r(m);p.kind==="element"&&w(p)&&i(p,g),c=g}}}function _e(t){return y(ne(t)).split(re).join(je+De)}function ne(t){return{...t,children:t.children.map(e=>S(e)?{kind:"text",value:re}:e.kind==="element"?ne(e):e)}}var re="\0fx-hole\0";var B={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},ft={version:2,module:"@fluixi/dom",symbols:[...B.symbols,"template","cloneTemplate","walk"]};var Be={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function He(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function ie(t){return He(t)?t:JSON.stringify(t)}function Fe(t){return t.expr!==void 0?t.reactive?`() => (${t.expr})`:`(${t.expr})`:JSON.stringify(t.literal??!0)}function Ge(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function We(t,e,n){let o=t.filter(s=>s.kind==="spread"),i=t.filter(s=>s.kind!=="spread").map(s=>`${ie(s.name)}: ${Fe(s)}`);e!=null&&i.push(`children: ${e}`);let a=`{ ${i.join(", ")} }`;return o.length>0?(n.add("mergeProps"),`mergeProps(${o.map(s=>s.expr).join(", ")}, ${a})`):a}function se(t,e,n){return t.length===1?N(t[0],e,n):`[${t.map(o=>N(o,e,n)).join(", ")}]`}function oe(t,e,n,o,r){o.add("createMemo"),o.add("createComponent");let i=e.filter(c=>c.kind==="spread"),s=e.filter(c=>c.kind!=="spread").map(c=>`get ${ie(c.name)}() { return ${Ge(c)}; }`);n.length>0&&s.push(`get children() { return ${se(n,o,r)}; }`);let l=`{ ${s.join(", ")} }`;return i.length>0&&(o.add("mergeProps"),l=`mergeProps(${i.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${t}, ${l}))`}function Ue(t,e){let n=X(e.name),o=e.literal;return o===!0||o===void 0?`${t}.setAttribute(${JSON.stringify(n)}, "");`:o===!1||o===null?"":`${t}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(o))});`}var ae=!1;function N(t,e,n){switch(t.kind){case"text":return JSON.stringify(t.value);case"expr":return t.reactive?`() => (${t.code})`:`(${t.code})`;case"fragment":return t.children.length===0?"null":se(t.children,e,n);case"component":return oe(t.name,t.props,t.children,e,n);case"control":{let o=Be[t.control]??t.control;return e.add(o),oe(o,t.props,t.children,e,n)}case"element":{if(n&&t.static&&!t.svg&&_(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;return n.push({id:s,html:y(t),tag:t.tag,svg:!1}),`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&ae){let s=te(t);if(s){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let l=`_tmpl$${n.length}`;n.push({id:l,html:s.html,tag:s.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(s.tag)}, true);`];for(let d of s.steps)c.push(`const ${d.ref} = ${d.expr};`);for(let d of s.holes)c.push(`insert(${d.parentRef}, holeScope(${d.startRef}, () => (${N(d.node,e,n)})), ${d.endRef}, holeContent(${d.startRef}, ${d.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let o=JSON.stringify(t.tag),r="_el$",i=[],a=t.svg?`${o}, true`:o;if(i.push(`const ${r} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every(k))for(let s of t.props)i.push(Ue(r,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";i.push(`spread({ element: ${r}, props: ${We(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let l=N(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";i.push(c?`insert(${r}, ${l}, null);`:`insert(${r}, ${l});`)}return i.push(`return ${r};`),`(() => { ${i.join(" ")} })()`}}}function T(t,e){if(!e||e.length===0)return t;let n=new Map(e.map(o=>[o.id,JSON.stringify(o.html)]));return t.replace(/_tmpl\$\d+/g,o=>n.get(o)??o)}var h={name:"imperative",contract:B,emit(t,e){let n=new Set,o=e?.templateClone!==!1?[]:void 0;return ae=e?.partialTemplates===!0,{code:N(t,n,o),imports:Array.from(n),templates:o}}};function O(t){let e=t.split(/\r\n|\n|\r/),n=0;for(let r=0;r<e.length;r++)/[^ \t]/.test(e[r])&&(n=r);let o="";for(let r=0;r<e.length;r++){let i=e[r].replace(/\t/g," ");r!==0&&(i=i.replace(/^ +/,"")),r!==e.length-1&&(i=i.replace(/ +$/,"")),i&&(r!==n&&(i+=" "),o+=i)}return o}var le=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function ze(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function ce(t){return t.charAt(0).toUpperCase()+t.slice(1)}var H=class{constructor(e,n){this.holes=e;this.used=n}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:n,imports:o,templates:r}=h.emit(e,{});for(let i of o)this.used.add(i);return T(n,r)}lowerRoot(e){let n=this.lowerChildren(e);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(e){let n=[];for(let o=0;o<e.length;o++){let r=e[o];if(r.kind==="Element"||r.kind==="Component"){let a=r.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=o+1;s<e.length&&this.isBlankText(e[s])&&s++;let l=e[s],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(d=>d.kind==="ElseDirective");n.push(this.lowerIf(r,a.hole,c?l:null)),c&&(o=s);continue}if(r.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(r));continue}}let i=this.lowerNode(r);i&&n.push(i)}return n}isBlankText(e){return e.kind==="Text"&&!e.raw&&O(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=O(e.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(e.hole);return{kind:"expr",code:n.code,reactive:n.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(e.children)};case"Element":return this.lowerElement(e);case"Component":return this.lowerComponent(e);default:return null}}lowerElement(e){let n=e.attributes.find(o=>o.kind==="Attribute"&&o.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let o=e.attributes.filter(i=>i!==n),r=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:o});return r.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),r}return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1}}lowerComponent(e){let n=e.tagHole!=null?this.hole(e.tagHole).code:e.tag,o=this.lowerAttributes(e.attributes),{slots:r,rest:i}=this.partitionSlots(e.children);for(let[l,c]of r){let d=c.length===1?c[0]:{kind:"fragment",children:c},p={name:l,kind:"attr",expr:this.emit(d),jsxElement:!0},m=o.findIndex(g=>g.name===l);m>=0?o[m]=p:o.push(p)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?K(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:o,children:this.lowerChildren(i),...s?{load:s}:{}}}partitionSlots(e){let n=new Map,o=[];for(let r of e){if(r.kind==="Element"||r.kind==="Component"){let i=r.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(i&&i.value&&i.value.kind==="static"){let a={...r,attributes:r.attributes.filter(c=>c!==i)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),l=n.get(i.value.value)??[];l.push(s),n.set(i.value.value,l);continue}}o.push(r)}return{slots:n,rest:o}}lowerIf(e,n,o){let r=this.hole(n),i=[{name:"when",kind:"attr",expr:r.code,reactive:r.reactive}];if(o){let s=this.stripAndLower(o,l=>l.kind==="ElseDirective");i.push({name:"fallback",kind:"attr",expr:this.emit(s),jsxElement:!0})}let a=this.stripAndLower(e,s=>s.kind==="IfDirective");return{kind:"component",name:"Show",props:i,children:[a]}}lowerEach(e){let n=e.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(e);let o=this.hole(n.hole),r=[{name:"each",kind:"attr",expr:o.code,reactive:o.reactive}];if(n.key){let l="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;r.push({name:"by",kind:"attr",expr:l})}let i=this.itemArrow(e),a;if(i){let l={kind:"expr",code:i.body,reactive:i.bodyReactive},c=this.rebuildWithChildren(e,[l]);a=`(${i.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");a=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:r,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(e){let n=e.children.filter(o=>!this.isBlankText(o));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(e,n){let o={...e,attributes:e.attributes.filter(r=>!n(r))};return o.kind==="Element"?this.lowerElement(o):this.lowerComponent(o)}rebuildWithChildren(e,n){let o=this.lowerAttributes(e.attributes.filter(r=>r.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:o,children:n,static:!1}:{kind:"component",name:e.tag,props:o,children:n}}lowerAttributes(e){let n=[],o=[],r=!1,i=[],a=!1,s=[];for(let l of e)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":n.push(this.plainAttr(l));break;case"PropertyBinding":n.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"EventBinding":n.push(this.eventProp(l));break;case"RefBinding":n.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let c=this.hole(l.hole);o.push(`${JSON.stringify(l.name)}: ${c.code}`),r=r||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);i.push(`${JSON.stringify(l.name)}: ${c.code}`),a=a||c.reactive;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole).code));break;case"UseDirective":{let c=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!c)break;s.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return o.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:r}),i.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${i.join(", ")} }`,reactive:a}),s.length>0&&n.push({name:"use",kind:"attr",expr:`[${s.join(", ")}]`}),n}eventProp(e){let n=e.name.toLowerCase(),o=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+ce(e.name),kind:"event",event:{name:n,delegated:le.has(n)},expr:o};let i=this.wrapHandler(o,e.modifiers),a=this.eventOptions(e.modifiers),s=a?`[${i}, ${a}]`:i;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(e,n){let o=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",r=[];return n.includes("prevent")&&r.push("e.preventDefault();"),n.includes("stop")&&r.push("e.stopPropagation();"),!o&&r.length===0?e:`(e) => { ${o}${r.join(" ")} return (${e})(e); }`}eventOptions(e){let n=[];return e.includes("capture")&&n.push("capture: true"),e.includes("once")&&n.push("once: true"),e.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(e,n){let o=e==="checked",r=o?"change":"input",i=o?"checked":"value";this.used.add("bindPair");let a=`bindPair(${n})`;return[{name:e,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+ce(r),kind:"event",event:{name:r,delegated:le.has(r)},expr:`(e) => ${a}[1](e.target.${i})`}]}plainAttr(e){let n=e.value,o=e.name;e.name==="class"?o=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":e.name==="html"&&(o="innerHTML");let i={name:o,kind:"attr"};if(n==null)return i.literal=!0,i;if(n.kind==="static")return i.literal=n.value,i;if(n.kind==="hole"){let l=this.hole(n.hole);return i.expr=l.code,i.reactive=l.reactive,i}let a=!1,s=n.parts.map(l=>{if("text"in l)return ze(l.text);let c=this.hole(l.hole);return a=a||c.reactive,"${"+c.code+"}"}).join("");return i.expr="`"+s+"`",i.reactive=a,i}};function F(t,e,n,o={}){let{root:r}=Je(t,{svg:o.svg});return new H(e,n).lowerRoot(r.children)}function Ve(t){switch(t.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return t.reactive?"reactive-prop":t.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function pe(t){let e=[],n=new Map,o=r=>{switch(r.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let i of r.children)o(i);return!1;case"fragment":for(let i of r.children)o(i);return!1;case"element":{let i=!0;for(let s of r.children)o(s)||(i=!1);let a;for(let s of r.props)if(a=Ve(s),a)break;return!a&&!i&&(a=qe(r)),r.static=!a,a?n.set(r,a):e.push(r),r.static}default:return!1}};for(let r of Array.isArray(t)?t:[t])o(r);return{staticElements:e,reasons:n}}function qe(t){for(let e of t.children){if(e.kind==="expr")return"expression-child";if(e.kind==="component")return"component-child";if(e.kind==="control")return"control-child";if(e.kind==="element"&&!e.static||e.kind==="fragment")return"expression-child"}return"expression-child"}var G=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],W=["Suspense","SuspenseList","Await"],I=["Router","Outlet","Redirect","Link"],$t=[...G,...W,...I],U=new Set([...G,...W]);function E(t={}){let{controlFlowModule:e="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:o="@fluixi/core/router"}=t,r={};for(let i of G)r[i]=e;for(let i of W)r[i]=n;for(let i of I)r[i]=o;return r}function wt(t={}){return{components:E(t)}}function St(t){let e=t??"@fluixi/core/router";return{components:Object.fromEntries(I.map(n=>[n,e]))}}function de(t,e={}){let{resolver:n,isBound:o,modules:r,strategyFor:i}=e,a=E(r),s=new Map,l=new Set,c=p=>{let{name:m}=p;if(!m||m.includes(".")||o?.(m))return;let g=d(m);if(!g){l.add(m);return}let R=g.origin==="builtin"&&U.has(m)?$:i?.(p)??$;p.source={...g,loading:R},s.set(m,p.source)},d=p=>{if(U.has(p))return{module:a[p],export:p,origin:"builtin"};let m=n?.resolve(p);if(m)return{module:m.module,export:m.export,origin:"rule"};if(I.includes(p))return{module:a[p],export:p,origin:"builtin"}};return M(t,p=>{p.kind==="component"&&c(p)}),{resolved:s,unresolved:[...l]}}function M(t,e){let n=Array.isArray(t)?t:[t];for(let o of n){e(o);let r=o.children;r&&M(r,e)}}function ue(t){let e=[];M(t,i=>{i.kind==="component"&&i.source&&e.push(i)});let n=new Set,o=new Set;for(let i of e){let{module:a,loading:s}=i.source;s.kind==="eager"&&n.add(a),s.kind==="never"&&o.add(a)}let r=new Map;for(let i of e){let a=i.source;Z(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},r.set(a.module,(r.get(a.module)??0)+1))}return{collapsed:r,conflicted:[...o].filter(i=>n.has(i))}}var Ke=t=>"components"in t;function me(t,e){return t.replace(/\$(\d+)/g,(n,o)=>e[Number(o)]??n)}function Ze(t,e){return typeof e=="string"?{module:e,export:t}:e}function P(t=[]){let e=new Map,n=[],o=[];for(let a of t){if(!Ke(a)){o.push(a);continue}for(let[s,l]of Object.entries(a.components)){let c=Ze(s,l),d=e.get(s);if(d&&d.module!==c.module){let p=n.find(m=>m.name===s);p?p.modules.push(c.module):n.push({name:s,modules:[d.module,c.module]});continue}e.set(s,c)}}let r=new Map;return{resolve:a=>{if(r.has(a))return r.get(a);let s=e.get(a);if(!s)for(let l of o){let c=a.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){s={module:me(l.module,c),export:l.export?me(l.export,c):a};break}}return r.set(a,s),s},names:()=>[...e.keys()],conflicts:()=>n}}function Ye(t){let e=[],n=0;return t.statics.forEach((o,r)=>{if(e.push({kind:"static",text:o,start:n}),n+=o.length,r<t.holes.length){let i=n+t.holes[r].code.length;e.push({kind:"hole",index:r,start:n,end:i}),n=i}}),e}function Ut(t,e={}){if(t.statics.length!==t.holes.length+1)throw new Error(`[fluixi] compileTemplate: ${t.statics.length} static runs for ${t.holes.length} holes — a template always has exactly one more.`);return Xe(Ye(t),t.holes,e)}function Xe(t,e,n={}){let o=new Set,r=F(t,[...e],o,{svg:n.svg});pe(r),de(r,{resolver:P(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:l=>l.load}),ue(r);let{code:i,imports:a,templates:s}=h.emit(r,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let l of a)o.add(l);return n.hoistTemplates?{code:i,imports:[...o],ir:r,templates:s}:{code:T(i,s),imports:[...o],ir:r}}var v="@fluixi/reactive/signal",A={$signal:{export:"signal",module:v,returns:"signal-handle"},$memo:{export:"memo",module:v,returns:"memo-handle"},$effect:{export:"effect",module:v,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:v,returns:"resource-handle"},$selector:{export:"createSelector",module:v,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:v,returns:"memo-accessor"},$untrack:{export:"untrack",module:v,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}};var zt=new RegExp(`\\$(?:${Object.keys(A).map(t=>t.slice(1)).join("|")})\\s*\\(`);var Qe=new Set(["Text","Image","Option","Audio","Comment","Range","Selection","Notification","Event","Document","Element","Node","Screen","Window","Location","History","Storage","Response","Request","Headers"]);function et(t){if(t.startsWith(".")||t.startsWith("/")||/^[~@]\//.test(t))return;let e=t.split("/");return t.startsWith("@")?e.slice(0,2).join("/"):e[0]}function J(t){return`_${t.replace(/[^A-Za-z0-9]/g,"_")}`}function fe(t,e={}){let{available:n,builtins:o=!0,intrinsics:r=!0,generator:i="@fluixi/compiler",specifier:a=u=>u}=e,s=[...t];o&&s.push({components:E()});let l=P(s),c=n?new Set(n):void 0,d=[],p=[],m=[],g=new Map;for(let u of[...l.names()].sort()){let f=l.resolve(u);if(!f)continue;let b=et(f.module);Qe.has(u)?p.push(u):c&&b&&!c.has(b)?m.push(u):(d.push(u),g.set(u,f))}let R=r?[...new Set(Object.values(A).map(u=>u.module))]:[],V=[...new Set([...d.map(u=>g.get(u).module),...R])].sort().map(u=>`import * as ${J(u)} from '${a(u)}';`),be=d.map(u=>{let f=g.get(u),b=J(f.module);return f.export==="default"?` const ${u}: typeof ${b}.default;`:` export import ${u} = ${b}.${f.export};`}),ke=p.length>0?`//
1
+ /*! @fluixi/compiler v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
+
3
+ // src/analyze/reactive-expr.ts
4
+ var STABLE_MEMBER = "children";
5
+ function isReactiveShape(shape) {
6
+ switch (shape.kind) {
7
+ case "call":
8
+ return true;
9
+ case "member":
10
+ return shape.property !== STABLE_MEMBER;
11
+ case "compound":
12
+ return shape.parts.some(isReactiveShape);
13
+ case "opaque":
14
+ return false;
15
+ }
16
+ }
17
+
18
+ // src/lower/template.ts
19
+ import {
20
+ parseTemplate
21
+ } from "@fluixi/template-parser";
22
+
23
+ // src/resolve/load-directive.ts
24
+ var EAGER = { kind: "eager" };
25
+ var DEFAULT_INTERACTION_EVENTS = ["pointerdown", "focusin", "keydown"];
26
+ var STRATEGIES = /* @__PURE__ */ new Set(["eager", "idle", "visible", "interaction", "media", "never"]);
27
+ var LoadDirectiveError = class extends Error {
28
+ };
29
+ function parseLoadDirective(name, value) {
30
+ const strategy = name.slice("load:".length);
31
+ if (!STRATEGIES.has(strategy)) {
32
+ throw new LoadDirectiveError(
33
+ `Unknown load strategy 'load:${strategy}'. Expected one of ${[...STRATEGIES].join(", ")}.`
34
+ );
35
+ }
36
+ switch (strategy) {
37
+ case "eager":
38
+ return EAGER;
39
+ case "idle":
40
+ return { kind: "idle" };
41
+ case "never":
42
+ return { kind: "never" };
43
+ case "visible":
44
+ return value ? { kind: "visible", rootMargin: value } : { kind: "visible" };
45
+ case "interaction":
46
+ return {
47
+ kind: "interaction",
48
+ events: value ? splitEvents(value) : [...DEFAULT_INTERACTION_EVENTS]
49
+ };
50
+ case "media":
51
+ if (!value) {
52
+ throw new LoadDirectiveError(
53
+ `'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`
54
+ );
55
+ }
56
+ return { kind: "media", query: value };
57
+ default:
58
+ throw new LoadDirectiveError(`Unhandled load strategy '${strategy}'.`);
59
+ }
60
+ }
61
+ function splitEvents(value) {
62
+ const events = value.split(/[\s,]+/).map((e) => e.trim()).filter(Boolean);
63
+ if (events.length === 0) {
64
+ throw new LoadDirectiveError(`'load:interaction' was given no event names.`);
65
+ }
66
+ return events;
67
+ }
68
+ function isDeferred(strategy) {
69
+ return strategy.kind !== "eager" && strategy.kind !== "never";
70
+ }
71
+
72
+ // src/codegen/serialize-static.ts
73
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
74
+ "area",
75
+ "base",
76
+ "br",
77
+ "col",
78
+ "embed",
79
+ "hr",
80
+ "img",
81
+ "input",
82
+ "link",
83
+ "meta",
84
+ "param",
85
+ "source",
86
+ "track",
87
+ "wbr"
88
+ ]);
89
+ var HTML_NAME = {
90
+ className: "class",
91
+ htmlFor: "for"
92
+ };
93
+ var PROPERTY_ONLY = /* @__PURE__ */ new Set([
94
+ "innerHTML",
95
+ "outerHTML",
96
+ "innerText",
97
+ "textContent",
98
+ "value",
99
+ "checked",
100
+ "selected",
101
+ "muted",
102
+ "defaultValue",
103
+ "defaultChecked",
104
+ "children",
105
+ "ref"
106
+ ]);
107
+ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style", "textarea", "title"]);
108
+ function isRawTextElement(tag) {
109
+ return RAW_TEXT_ELEMENTS.has(tag);
110
+ }
111
+ function htmlAttrName(name) {
112
+ return HTML_NAME[name] ?? name;
113
+ }
114
+ function isPlainLiteralAttr(prop) {
115
+ if (prop.kind !== "attr") return false;
116
+ if (prop.expr !== void 0) return false;
117
+ if (prop.name.includes(":")) return false;
118
+ return !PROPERTY_ONLY.has(prop.name);
119
+ }
120
+ function isSerializable(node) {
121
+ if (!node.static) return false;
122
+ if (isRawTextElement(node.tag)) return false;
123
+ for (const prop of node.props) {
124
+ if (!isPlainLiteralAttr(prop)) return false;
125
+ }
126
+ for (const child of node.children) {
127
+ if (child.kind === "text") continue;
128
+ if (child.kind === "element" && isSerializable(child)) continue;
129
+ return false;
130
+ }
131
+ return true;
132
+ }
133
+ function serializeStatic(node) {
134
+ const attrs = node.props.map(serializeProp).filter(Boolean).join("");
135
+ const open = `<${node.tag}${attrs}>`;
136
+ if (VOID_ELEMENTS.has(node.tag)) return open;
137
+ return `${open}${node.children.map(serializeChild).join("")}</${node.tag}>`;
138
+ }
139
+ function serializeChild(child) {
140
+ if (child.kind === "text") return escapeText(child.value);
141
+ if (child.kind !== "element") throw new Error(`serializeStatic: unexpected ${child.kind}`);
142
+ return serializeStatic(child);
143
+ }
144
+ function serializeProp(prop) {
145
+ const name = HTML_NAME[prop.name] ?? prop.name;
146
+ const value = prop.literal;
147
+ if (value === true || value === void 0) return ` ${name}`;
148
+ if (value === false || value === null) return "";
149
+ return ` ${name}="${escapeAttr(String(value))}"`;
150
+ }
151
+ function escapeAttr(value) {
152
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
153
+ }
154
+ function escapeText(value) {
155
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
156
+ }
157
+ function templatePositions(root) {
158
+ const pos = [];
159
+ let file;
160
+ const walk2 = (el) => {
161
+ file ??= el.at?.file;
162
+ pos.push(el.at?.line ?? 0, el.at?.column ?? 0);
163
+ for (const child of el.children) if (child.kind === "element") walk2(child);
164
+ };
165
+ walk2(root);
166
+ return file && pos.some((n) => n !== 0) ? { file, pos } : void 0;
167
+ }
168
+
169
+ // src/codegen/partial-template.ts
170
+ var HOLE_START = "<!--fx-->";
171
+ var HOLE_END = "<!--fx/-->";
172
+ function isHole(node) {
173
+ return node.kind === "expr" || node.kind === "component" || node.kind === "control";
174
+ }
175
+ function isTemplateChild(node) {
176
+ return node.kind === "text" || node.kind === "element" && isTemplateElement(node);
177
+ }
178
+ function isTemplateElement(node) {
179
+ if (node.svg) return false;
180
+ if (isRawTextElement(node.tag)) return false;
181
+ if (!node.props.every((p) => isPlainLiteralAttr(p))) return false;
182
+ return node.children.every((c) => isTemplateChild(c) || isHole(c));
183
+ }
184
+ function containsHole(node) {
185
+ if (isHole(node)) return true;
186
+ const children = node.children;
187
+ return children ? children.some(containsHole) : false;
188
+ }
189
+ function addressable(el) {
190
+ for (let i = 0; i < el.children.length; i++) {
191
+ const child = el.children[i];
192
+ if (child.kind === "text") {
193
+ if (child.value === "") return false;
194
+ if (el.children[i + 1]?.kind === "text") return false;
195
+ }
196
+ }
197
+ return el.children.every((c) => c.kind !== "element" || addressable(c));
198
+ }
199
+ function planPartialTemplate(root) {
200
+ if (!isTemplateElement(root)) return null;
201
+ if (!addressable(root)) return null;
202
+ if (!root.children.some(containsHole)) return null;
203
+ const steps = [];
204
+ const holes = [];
205
+ let refCount = 0;
206
+ const declare = (expr) => {
207
+ const ref = `_n$${refCount++}`;
208
+ steps.push({ ref, expr });
209
+ return ref;
210
+ };
211
+ walk2(root, "_el$");
212
+ return { html: serializeWithMarkers(root), tag: root.tag, steps, holes };
213
+ function walk2(el, elementRef) {
214
+ let last = -1;
215
+ el.children.forEach((child, i) => {
216
+ if (containsHole(child)) last = i;
217
+ });
218
+ let previous = null;
219
+ for (let i = 0; i <= last; i++) {
220
+ const child = el.children[i];
221
+ const expr = previous ? `${previous}.nextSibling` : `${elementRef}.firstChild`;
222
+ if (isHole(child)) {
223
+ const startRef = declare(expr);
224
+ const endRef = declare(`holeEnd(${startRef})`);
225
+ holes.push({ parentRef: elementRef, startRef, endRef, node: child });
226
+ previous = endRef;
227
+ continue;
228
+ }
229
+ const ref = declare(expr);
230
+ if (child.kind === "element" && containsHole(child)) walk2(child, ref);
231
+ previous = ref;
232
+ }
233
+ }
234
+ }
235
+ function serializeWithMarkers(el) {
236
+ return serializeStatic(withSentinels(el)).split(SENTINEL).join(HOLE_START + HOLE_END);
237
+ }
238
+ function withSentinels(el) {
239
+ return {
240
+ ...el,
241
+ children: el.children.map(
242
+ (child) => isHole(child) ? { kind: "text", value: SENTINEL } : child.kind === "element" ? withSentinels(child) : child
243
+ )
244
+ };
245
+ }
246
+ var SENTINEL = "\0fx-hole\0";
247
+
248
+ // src/codegen/contract.ts
249
+ var RUNTIME_CONTRACT_V1 = {
250
+ version: 1,
251
+ module: "@fluixi/dom",
252
+ symbols: [
253
+ "createNativeElement",
254
+ "insert",
255
+ "spread",
256
+ "setAttribute",
257
+ "delegateEvents",
258
+ "createComponent",
259
+ "createMemo",
260
+ "untrack",
261
+ "Show",
262
+ "For",
263
+ "Index",
264
+ "Switch",
265
+ "Match",
266
+ "Dynamic",
267
+ "ErrorBoundary"
268
+ ]
269
+ };
270
+ var RUNTIME_CONTRACT_V2 = {
271
+ version: 2,
272
+ module: "@fluixi/dom",
273
+ symbols: [...RUNTIME_CONTRACT_V1.symbols, "template", "cloneTemplate", "walk"]
274
+ };
275
+
276
+ // src/analyze/intrinsics.ts
277
+ var REACTIVE_MODULE = "@fluixi/reactive/signal";
278
+ var INTRINSICS = {
279
+ $signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
280
+ $memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
281
+ $effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
282
+ $store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
283
+ $resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
284
+ // No short runtime form for these yet, so the intrinsic stands for the `create*`
285
+ // name. Still worth having — no import to write — and when a shorter form is
286
+ // designed, the change is this line rather than a compiler pass.
287
+ $selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
288
+ $deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
289
+ // Not value constructors, but the compiler has to know them: they change what a read
290
+ // does. `untrack` suppresses dependency collection, which is exactly the kind of thing
291
+ // dependency analysis must not guess at.
292
+ $untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
293
+ $untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" }
294
+ };
295
+ var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
296
+
297
+ // src/transform/source-locations.ts
298
+ var SOURCE_MARKER = "__fx_source";
299
+ var HOLE_MARKER = "__fx_hole";
300
+ var markHole = (accessor, line, column, name) => `(globalThis.${HOLE_MARKER} ?? ((f) => f))(${accessor},${line},${column}${name === void 0 ? "" : `,${JSON.stringify(name)}`})`;
301
+ var PROPS_MARKER = "__fx_props";
302
+ var markProps = (object, at) => `(globalThis.${PROPS_MARKER} ?? ((p) => p))(${object},${JSON.stringify(at)})`;
303
+
304
+ // src/analyze/paren.ts
305
+ function skipQuoted(src, start) {
306
+ const quote = src[start];
307
+ for (let i = start + 1; i < src.length; i++) {
308
+ const c = src[i];
309
+ if (c === "\\") i++;
310
+ else if (c === quote) return i + 1;
311
+ else if (c === "\n") return -1;
312
+ }
313
+ return -1;
314
+ }
315
+ function skipTemplate(src, start) {
316
+ let i = start + 1;
317
+ while (i < src.length) {
318
+ const c = src[i];
319
+ if (c === "\\") {
320
+ i += 2;
321
+ } else if (c === "`") {
322
+ return i + 1;
323
+ } else if (c === "$" && src[i + 1] === "{") {
324
+ let depth = 1;
325
+ i += 2;
326
+ while (i < src.length && depth > 0) {
327
+ const k = src[i];
328
+ if (k === "\\") i += 2;
329
+ else if (k === "`") {
330
+ const end = skipTemplate(src, i);
331
+ if (end < 0) return -1;
332
+ i = end;
333
+ } else if (k === '"' || k === "'") {
334
+ const end = skipQuoted(src, i);
335
+ if (end < 0) return -1;
336
+ i = end;
337
+ } else {
338
+ if (k === "{") depth++;
339
+ else if (k === "}") depth--;
340
+ i++;
341
+ }
342
+ }
343
+ } else {
344
+ i++;
345
+ }
346
+ }
347
+ return -1;
348
+ }
349
+ function skipRegex(src, start) {
350
+ let inClass = false;
351
+ for (let i = start + 1; i < src.length; i++) {
352
+ const c = src[i];
353
+ if (c === "\\") i++;
354
+ else if (c === "[") inClass = true;
355
+ else if (c === "]") inClass = false;
356
+ else if (c === "\n") return -1;
357
+ else if (c === "/" && !inClass) {
358
+ let end = i + 1;
359
+ while (end < src.length && /[a-z]/i.test(src[end])) end++;
360
+ return end;
361
+ }
362
+ }
363
+ return -1;
364
+ }
365
+ function divides(prev) {
366
+ return prev !== "" && /[A-Za-z0-9_$)\]]/.test(prev);
367
+ }
368
+ function topLevelComma(src) {
369
+ let depth = 0;
370
+ let prev = "";
371
+ let i = 0;
372
+ while (i < src.length) {
373
+ const c = src[i];
374
+ if (c === '"' || c === "'") {
375
+ const end = skipQuoted(src, i);
376
+ if (end < 0) return null;
377
+ i = end;
378
+ prev = c;
379
+ } else if (c === "`") {
380
+ const end = skipTemplate(src, i);
381
+ if (end < 0) return null;
382
+ i = end;
383
+ prev = c;
384
+ } else if (c === "/" && src[i + 1] === "/") {
385
+ return null;
386
+ } else if (c === "/" && src[i + 1] === "*") {
387
+ const end = src.indexOf("*/", i + 2);
388
+ if (end < 0) return null;
389
+ i = end + 2;
390
+ } else if (c === "/" && !divides(prev)) {
391
+ const end = skipRegex(src, i);
392
+ if (end < 0) return null;
393
+ i = end;
394
+ prev = "/";
395
+ } else {
396
+ if (c === "(" || c === "[" || c === "{") depth++;
397
+ else if (c === ")" || c === "]" || c === "}") {
398
+ depth--;
399
+ if (depth < 0) return null;
400
+ } else if (c === "," && depth === 0) return true;
401
+ if (!/\s/.test(c)) prev = c;
402
+ i++;
403
+ }
404
+ }
405
+ return depth === 0 ? false : null;
406
+ }
407
+ function paren(code, position) {
408
+ const src = code.trim();
409
+ if (src === "") return `(${code})`;
410
+ if (position === "arrowBody" && src[0] === "{") return `(${code})`;
411
+ return topLevelComma(src) === false ? code : `(${code})`;
412
+ }
413
+
414
+ // src/codegen/backends/imperative.ts
415
+ var CONTROL_COMPONENT = {
416
+ show: "Show",
417
+ for: "For",
418
+ index: "Index",
419
+ switch: "Switch",
420
+ match: "Match",
421
+ dynamic: "Dynamic",
422
+ errorBoundary: "ErrorBoundary",
423
+ suspense: "Suspense"
424
+ };
425
+ function isIdent(name) {
426
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
427
+ }
428
+ function propKey(name) {
429
+ return isIdent(name) ? name : JSON.stringify(name);
430
+ }
431
+ function propValue(p) {
432
+ if (p.expr !== void 0) {
433
+ if (p.name === "ref" && p.at)
434
+ return markHole(paren(p.expr, "value"), p.at.line, p.at.column, p.expr);
435
+ if (!p.reactive) return paren(p.expr, "value");
436
+ const accessor = `() => ${paren(p.expr, "arrowBody")}`;
437
+ return p.at ? markHole(accessor, p.at.line, p.at.column, p.directive) : accessor;
438
+ }
439
+ return JSON.stringify(p.literal ?? true);
440
+ }
441
+ function componentPropValue(p) {
442
+ if (p.expr !== void 0) return paren(p.expr, "value");
443
+ return JSON.stringify(p.literal ?? true);
444
+ }
445
+ function emitProps(props, childrenExpr, used) {
446
+ const spreads = props.filter((p) => p.kind === "spread");
447
+ const normal = props.filter((p) => p.kind !== "spread");
448
+ const entries = normal.map((p) => `${propKey(p.name)}: ${propValue(p)}`);
449
+ if (childrenExpr != null) entries.push(`children: ${childrenExpr}`);
450
+ const obj = `{ ${entries.join(", ")} }`;
451
+ if (spreads.length > 0) {
452
+ used.add("mergeProps");
453
+ return `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
454
+ }
455
+ return obj;
456
+ }
457
+ function markBind(code, at) {
458
+ return at ? markHole(code, at.line, at.column) : code;
459
+ }
460
+ function emitChildren(children, used, templates) {
461
+ if (children.length === 1) return emitNode(children[0], used, templates);
462
+ return `[${children.map((c) => emitNode(c, used, templates)).join(", ")}]`;
463
+ }
464
+ function emitComponent(name, props, children, used, templates, at) {
465
+ used.add("createMemo");
466
+ used.add("createComponent");
467
+ const spreads = props.filter((p) => p.kind === "spread");
468
+ const normal = props.filter((p) => p.kind !== "spread");
469
+ const entries = normal.map(
470
+ (p) => `get ${propKey(p.name)}() { return ${componentPropValue(p)}; }`
471
+ );
472
+ if (children.length > 0) {
473
+ entries.push(`get children() { return ${emitChildren(children, used, templates)}; }`);
474
+ }
475
+ let obj = `{ ${entries.join(", ")} }`;
476
+ if (spreads.length > 0) {
477
+ used.add("mergeProps");
478
+ obj = `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
479
+ }
480
+ const propAt = {};
481
+ for (const p of normal) if (p.at) propAt[p.name] = [p.at.line, p.at.column];
482
+ if (Object.keys(propAt).length) obj = markProps(obj, propAt);
483
+ const mark = at ? `globalThis.${SOURCE_MARKER}?.(${JSON.stringify(at.file)},${at.line},${at.column},${JSON.stringify(name)}), ` : "";
484
+ return `createMemo(${paren(`${mark}() => createComponent(${name}, ${obj})`, "value")})`;
485
+ }
486
+ function staticAttrAssignment(el, prop) {
487
+ const name = htmlAttrName(prop.name);
488
+ const value = prop.literal;
489
+ if (value === true || value === void 0) return `${el}.setAttribute(${JSON.stringify(name)}, "");`;
490
+ if (value === false || value === null) return "";
491
+ return `${el}.setAttribute(${JSON.stringify(name)}, ${JSON.stringify(String(value))});`;
492
+ }
493
+ var partial = false;
494
+ function emitNode(node, used, templates) {
495
+ switch (node.kind) {
496
+ case "text":
497
+ return JSON.stringify(node.value);
498
+ case "expr": {
499
+ if (!node.reactive) return paren(node.code, "value");
500
+ const accessor = `() => ${paren(node.code, "arrowBody")}`;
501
+ return node.at ? markHole(accessor, node.at.line, node.at.column) : accessor;
502
+ }
503
+ case "fragment":
504
+ if (node.children.length === 0) return "null";
505
+ return emitChildren(node.children, used, templates);
506
+ case "component":
507
+ return markBind(emitComponent(node.name, node.props, node.children, used, templates, node.at), node.bindAt ?? node.at);
508
+ case "control": {
509
+ const name = CONTROL_COMPONENT[node.control] ?? node.control;
510
+ used.add(name);
511
+ return markBind(emitComponent(name, node.props, node.children, used, templates), node.bindAt);
512
+ }
513
+ case "element": {
514
+ if (templates && node.static && !node.svg && isSerializable(node)) {
515
+ used.add("templateNode");
516
+ const id = `_tmpl$${templates.length}`;
517
+ templates.push({ id, html: serializeStatic(node), tag: node.tag, svg: false });
518
+ const at = templatePositions(node);
519
+ return at ? `templateNode(${id}, ${JSON.stringify(node.tag)}, false, false, ${JSON.stringify(at)})` : `templateNode(${id}, ${JSON.stringify(node.tag)})`;
520
+ }
521
+ if (templates && partial) {
522
+ const plan = planPartialTemplate(node);
523
+ if (plan) {
524
+ used.add("templateNode");
525
+ used.add("insert");
526
+ used.add("holeEnd");
527
+ used.add("holeContent");
528
+ used.add("holeScope");
529
+ const id = `_tmpl$${templates.length}`;
530
+ templates.push({ id, html: plan.html, tag: plan.tag, svg: false });
531
+ const at = templatePositions(node);
532
+ const lines = [
533
+ `const _el$ = templateNode(${id}, ${JSON.stringify(plan.tag)}, true${at ? `, false, ${JSON.stringify(at)}` : ""});`
534
+ ];
535
+ for (const step of plan.steps) lines.push(`const ${step.ref} = ${step.expr};`);
536
+ for (const hole of plan.holes) {
537
+ lines.push(
538
+ `insert(${hole.parentRef}, holeScope(${hole.startRef}, () => ${paren(emitNode(hole.node, used, templates), "arrowBody")}), ${hole.endRef}, holeContent(${hole.startRef}, ${hole.endRef}));`
539
+ );
540
+ }
541
+ lines.push("return _el$;");
542
+ return `(() => { ${lines.join(" ")} })()`;
543
+ }
544
+ }
545
+ used.add("createNativeElement");
546
+ const tag = JSON.stringify(node.tag);
547
+ const el = "_el$";
548
+ const parts = [];
549
+ const createArgs = node.at ? `${tag}, ${node.svg}, ${JSON.stringify(node.at)}` : node.svg ? `${tag}, true` : tag;
550
+ parts.push(`const ${el} = createNativeElement(${createArgs});`);
551
+ if (node.props.length > 0) {
552
+ if (!node.svg && node.props.every(isPlainLiteralAttr)) {
553
+ for (const p of node.props) parts.push(staticAttrAssignment(el, p));
554
+ } else {
555
+ used.add("spread");
556
+ const svgFlag = node.svg ? ", isSVG: true" : "";
557
+ parts.push(`spread({ element: ${el}, props: ${emitProps(node.props, null, used)}${svgFlag} });`);
558
+ }
559
+ }
560
+ for (const child of node.children) {
561
+ used.add("insert");
562
+ const childCode = emitNode(child, used, templates);
563
+ const isFn = child.kind === "expr" && child.reactive || child.kind === "component" || child.kind === "control";
564
+ parts.push(isFn ? `insert(${el}, ${childCode}, null);` : `insert(${el}, ${childCode});`);
565
+ }
566
+ parts.push(`return ${el};`);
567
+ return `(() => { ${parts.join(" ")} })()`;
568
+ }
569
+ }
570
+ }
571
+ function inlineTemplates(code, templates) {
572
+ if (!templates || templates.length === 0) return code;
573
+ const byId = new Map(templates.map((t) => [t.id, JSON.stringify(t.html)]));
574
+ return code.replace(/_tmpl\$\d+/g, (id) => byId.get(id) ?? id);
575
+ }
576
+ var imperativeBackend = {
577
+ name: "imperative",
578
+ contract: RUNTIME_CONTRACT_V1,
579
+ emit(node, options) {
580
+ const used = /* @__PURE__ */ new Set();
581
+ const templates = options?.templateClone !== false ? [] : void 0;
582
+ partial = options?.partialTemplates === true;
583
+ const code = emitNode(node, used, templates);
584
+ return { code, imports: Array.from(used), templates };
585
+ }
586
+ };
587
+
588
+ // src/lower/text.ts
589
+ function cleanTemplateText(value) {
590
+ const lines = value.split(/\r\n|\n|\r/);
591
+ let lastNonEmpty = 0;
592
+ for (let i = 0; i < lines.length; i++) {
593
+ if (/[^ \t]/.test(lines[i])) lastNonEmpty = i;
594
+ }
595
+ let out = "";
596
+ for (let i = 0; i < lines.length; i++) {
597
+ let line = lines[i].replace(/\t/g, " ");
598
+ if (i !== 0) line = line.replace(/^ +/, "");
599
+ if (i !== lines.length - 1) line = line.replace(/ +$/, "");
600
+ if (!line) continue;
601
+ if (i !== lastNonEmpty) line += " ";
602
+ out += line;
603
+ }
604
+ return out;
605
+ }
606
+
607
+ // src/lower/template.ts
608
+ var DELEGATED = /* @__PURE__ */ new Set([
609
+ "click",
610
+ "dblclick",
611
+ "input",
612
+ "change",
613
+ "submit",
614
+ "focus",
615
+ "blur",
616
+ "keydown",
617
+ "keyup",
618
+ "keypress",
619
+ "mousedown",
620
+ "mouseup"
621
+ ]);
622
+ function escapeTemplate(s) {
623
+ return s.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
624
+ }
625
+ function capitalize(s) {
626
+ return s.charAt(0).toUpperCase() + s.slice(1);
627
+ }
628
+ var Lowerer = class {
629
+ constructor(holes, used, sourceFile, positionAt) {
630
+ this.holes = holes;
631
+ this.used = used;
632
+ this.sourceFile = sourceFile;
633
+ this.positionAt = positionAt;
634
+ }
635
+ /**
636
+ * Where a tag is written, for the mark a component node carries.
637
+ *
638
+ * The parser reports offsets, and they are offsets into the file: the pieces it was given
639
+ * carry the positions the front-end recorded. Only built when the host asked for source
640
+ * locations, which is the only time either of these is set.
641
+ */
642
+ tagAt(node) {
643
+ const start = node.loc?.start;
644
+ if (!this.sourceFile || !this.positionAt || start == null) return void 0;
645
+ const { line, column } = this.positionAt(start);
646
+ return { file: this.sourceFile, line, column };
647
+ }
648
+ hole(i) {
649
+ return this.holes[i] ?? { code: "undefined", reactive: false };
650
+ }
651
+ /** Emit a nested IR subtree to code (for `Show` fallback / `For` children). */
652
+ emit(node) {
653
+ const { code, imports, templates } = imperativeBackend.emit(node, {});
654
+ for (const s of imports) this.used.add(s);
655
+ return inlineTemplates(code, templates);
656
+ }
657
+ // --- content ------------------------------------------------------------
658
+ lowerRoot(children) {
659
+ const nodes = this.lowerChildren(children);
660
+ if (nodes.length === 1) return nodes[0];
661
+ return { kind: "fragment", children: nodes };
662
+ }
663
+ /** Lower a sibling list, handling text-drop and if/else/each restructuring. */
664
+ lowerChildren(children) {
665
+ const out = [];
666
+ for (let i = 0; i < children.length; i++) {
667
+ const child = children[i];
668
+ if (child.kind === "Element" || child.kind === "Component") {
669
+ const ifDir = child.attributes.find((a) => a.kind === "IfDirective");
670
+ if (ifDir && ifDir.kind === "IfDirective") {
671
+ let elseIdx = i + 1;
672
+ if (elseIdx < children.length && this.isBlankText(children[elseIdx])) elseIdx++;
673
+ const elseNode = children[elseIdx];
674
+ const hasElse = elseNode && (elseNode.kind === "Element" || elseNode.kind === "Component") && elseNode.attributes.some((a) => a.kind === "ElseDirective");
675
+ out.push(this.lowerIf(child, ifDir.hole, hasElse ? elseNode : null));
676
+ if (hasElse) i = elseIdx;
677
+ continue;
678
+ }
679
+ if (child.attributes.some((a) => a.kind === "EachDirective")) {
680
+ out.push(this.lowerEach(child));
681
+ continue;
682
+ }
683
+ }
684
+ const node = this.lowerNode(child);
685
+ if (node) out.push(node);
686
+ }
687
+ return out;
688
+ }
689
+ isBlankText(n) {
690
+ return n.kind === "Text" && !n.raw && cleanTemplateText(n.value) === "";
691
+ }
692
+ lowerNode(node) {
693
+ switch (node.kind) {
694
+ case "Text": {
695
+ if (node.raw) return { kind: "text", value: node.value };
696
+ const cleaned = cleanTemplateText(node.value);
697
+ return cleaned ? { kind: "text", value: cleaned } : null;
698
+ }
699
+ case "Comment":
700
+ return null;
701
+ // dropped, like JSX comments
702
+ case "Expression": {
703
+ const h = this.hole(node.hole);
704
+ return { kind: "expr", code: h.code, reactive: h.reactive, ...h.at ? { at: h.at } : {} };
705
+ }
706
+ case "Fragment":
707
+ return { kind: "fragment", children: this.lowerChildren(node.children) };
708
+ case "Element":
709
+ return this.lowerElement(node);
710
+ case "Component":
711
+ return this.lowerComponent(node);
712
+ default:
713
+ return null;
714
+ }
715
+ }
716
+ lowerElement(el) {
717
+ const isAttr = el.attributes.find((a) => a.kind === "Attribute" && a.name === "is");
718
+ if (el.tag === "component" && isAttr && isAttr.value && isAttr.value.kind === "hole") {
719
+ const rest = el.attributes.filter((a) => a !== isAttr);
720
+ const node = this.lowerComponent({ ...el, kind: "Component", tag: "Dynamic", tagHole: null, attributes: rest });
721
+ node.props.unshift({ name: "component", kind: "attr", expr: `() => ${paren(this.hole(isAttr.value.hole).code, "arrowBody")}` });
722
+ return node;
723
+ }
724
+ const at = this.tagAt(el);
725
+ return {
726
+ kind: "element",
727
+ tag: el.tag,
728
+ svg: el.namespace === "svg",
729
+ props: this.lowerAttributes(el.attributes),
730
+ children: this.lowerChildren(el.children),
731
+ static: false,
732
+ ...at ? { at } : {}
733
+ };
734
+ }
735
+ lowerComponent(el) {
736
+ const name = el.tagHole != null ? this.hole(el.tagHole).code : el.tag;
737
+ const props = this.lowerAttributes(el.attributes);
738
+ const { slots, rest } = this.partitionSlots(el.children);
739
+ for (const [slotName, nodes] of slots) {
740
+ const ir = nodes.length === 1 ? nodes[0] : { kind: "fragment", children: nodes };
741
+ const slotProp = {
742
+ name: slotName,
743
+ kind: "attr",
744
+ expr: this.emit(ir),
745
+ jsxElement: true
746
+ };
747
+ const clash = props.findIndex((p) => p.name === slotName);
748
+ if (clash >= 0) props[clash] = slotProp;
749
+ else props.push(slotProp);
750
+ }
751
+ const loadAttr = el.attributes.find((a) => a.kind === "LoadDirective");
752
+ const load = loadAttr ? parseLoadDirective(`load:${loadAttr.strategy}`, loadAttr.modifier) : void 0;
753
+ const bindAt = props.find((p) => p.at && p.reactive)?.at;
754
+ const at = this.tagAt(el);
755
+ return {
756
+ kind: "component",
757
+ name,
758
+ props,
759
+ children: this.lowerChildren(rest),
760
+ ...at ? { at } : {},
761
+ ...bindAt ? { bindAt } : {},
762
+ ...load ? { load } : {}
763
+ };
764
+ }
765
+ /** Split a component's children into named slots (`slot="x"`) and the rest. */
766
+ partitionSlots(children) {
767
+ const slots = /* @__PURE__ */ new Map();
768
+ const rest = [];
769
+ for (const child of children) {
770
+ if (child.kind === "Element" || child.kind === "Component") {
771
+ const slot = child.attributes.find(
772
+ (a) => a.kind === "Attribute" && a.name === "slot"
773
+ );
774
+ if (slot && slot.value && slot.value.kind === "static") {
775
+ const stripped = { ...child, attributes: child.attributes.filter((a) => a !== slot) };
776
+ const ir = stripped.kind === "Element" ? this.lowerElement(stripped) : this.lowerComponent(stripped);
777
+ const bucket = slots.get(slot.value.value) ?? [];
778
+ bucket.push(ir);
779
+ slots.set(slot.value.value, bucket);
780
+ continue;
781
+ }
782
+ }
783
+ rest.push(child);
784
+ }
785
+ return { slots, rest };
786
+ }
787
+ // --- control-flow sugar -------------------------------------------------
788
+ /** `<el if=${cond}>…</el>` (+ optional `<el else>`) → `<Show when fallback>`. */
789
+ lowerIf(el, condHole, elseEl) {
790
+ const cond = this.hole(condHole);
791
+ const props = [
792
+ { name: "when", kind: "attr", expr: cond.code, reactive: cond.reactive, ...cond.at ? { at: cond.at } : {} }
793
+ ];
794
+ if (elseEl) {
795
+ const elseIR = this.stripAndLower(elseEl, (a) => a.kind === "ElseDirective");
796
+ props.push({ name: "fallback", kind: "attr", expr: this.emit(elseIR), jsxElement: true });
797
+ }
798
+ const child = this.stripAndLower(el, (a) => a.kind === "IfDirective");
799
+ const at = this.tagAt(el);
800
+ return { kind: "component", name: "Show", props, children: [child], ...at ? { at } : {}, ...cond.at ? { bindAt: cond.at } : {} };
801
+ }
802
+ /** `<el each=${items} key?>${item => …}</el>` → `<For each>{item => <el>…</el>}</For>`. */
803
+ lowerEach(el) {
804
+ const eachDir = el.attributes.find((a) => a.kind === "EachDirective");
805
+ if (!eachDir || eachDir.kind !== "EachDirective") return this.lowerNode(el);
806
+ const each = this.hole(eachDir.hole);
807
+ const props = [{ name: "each", kind: "attr", expr: each.code, reactive: each.reactive, ...each.at ? { at: each.at } : {} }];
808
+ if (eachDir.key) {
809
+ const by = "static" in eachDir.key ? `(item) => item[${JSON.stringify(eachDir.key.static)}]` : this.hole(eachDir.key.hole).code;
810
+ props.push({ name: "by", kind: "attr", expr: by });
811
+ }
812
+ const arrow = this.itemArrow(el);
813
+ let childrenCode;
814
+ if (arrow) {
815
+ const bodyIR = { kind: "expr", code: arrow.body, reactive: arrow.bodyReactive };
816
+ const repeated = this.rebuildWithChildren(el, [bodyIR]);
817
+ childrenCode = `(${arrow.params.join(", ")}) => ${paren(this.emit(repeated), "arrowBody")}`;
818
+ } else {
819
+ const repeated = this.stripAndLower(el, (a) => a.kind === "EachDirective");
820
+ childrenCode = `() => ${paren(this.emit(repeated), "arrowBody")}`;
821
+ }
822
+ const children = [{ kind: "expr", code: childrenCode, reactive: false }];
823
+ const at = this.tagAt(el);
824
+ return { kind: "component", name: "For", props, children, ...at ? { at } : {}, ...each.at ? { bindAt: each.at } : {} };
825
+ }
826
+ /** The single `${item => expr}` child arrow, if that's the element's content. */
827
+ itemArrow(el) {
828
+ const kids = el.children.filter((c) => !this.isBlankText(c));
829
+ if (kids.length !== 1 || kids[0].kind !== "Expression") return null;
830
+ return this.hole(kids[0].hole).arrow ?? null;
831
+ }
832
+ /** Lower an element to IR, dropping the directive attribute matched by `drop`. */
833
+ stripAndLower(el, drop) {
834
+ const clone = { ...el, attributes: el.attributes.filter((a) => !drop(a)) };
835
+ return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
836
+ }
837
+ /** Same element (minus each/key) but with explicit IR children. */
838
+ rebuildWithChildren(el, children) {
839
+ const props = this.lowerAttributes(
840
+ el.attributes.filter((a) => a.kind !== "EachDirective")
841
+ );
842
+ if (el.kind === "Element") {
843
+ const at = this.tagAt(el);
844
+ return {
845
+ kind: "element",
846
+ tag: el.tag,
847
+ svg: el.namespace === "svg",
848
+ props,
849
+ children,
850
+ static: false,
851
+ ...at ? { at } : {}
852
+ };
853
+ }
854
+ return { kind: "component", name: el.tag, props, children };
855
+ }
856
+ // --- attributes ---------------------------------------------------------
857
+ lowerAttributes(attrs) {
858
+ const props = [];
859
+ const classEntries = [];
860
+ let classReactive = false;
861
+ let classAt;
862
+ const styleEntries = [];
863
+ let styleReactive = false;
864
+ let styleAt;
865
+ const usePairs = [];
866
+ for (const a of attrs) {
867
+ switch (a.kind) {
868
+ case "IfDirective":
869
+ case "EachDirective":
870
+ case "ElseDirective":
871
+ break;
872
+ // handled as control-flow at the parent level
873
+ case "Attribute":
874
+ props.push(this.plainAttr(a));
875
+ break;
876
+ case "PropertyBinding":
877
+ props.push({
878
+ name: a.name,
879
+ kind: "prop",
880
+ expr: this.hole(a.hole).code,
881
+ reactive: this.hole(a.hole).reactive,
882
+ ...this.hole(a.hole).at ? { at: this.hole(a.hole).at } : {}
883
+ });
884
+ break;
885
+ case "EventBinding":
886
+ props.push(this.eventProp(a));
887
+ break;
888
+ case "RefBinding":
889
+ props.push({
890
+ name: "ref",
891
+ kind: "ref",
892
+ expr: this.hole(a.hole).code,
893
+ reactive: this.hole(a.hole).reactive,
894
+ // Which variable ends up holding the element, and where it was written.
895
+ ...this.hole(a.hole).at ? { at: this.hole(a.hole).at } : {}
896
+ });
897
+ break;
898
+ case "Spread":
899
+ props.push({ name: "", kind: "spread", expr: this.hole(a.hole).code });
900
+ break;
901
+ case "ClassDirective": {
902
+ const h = this.hole(a.hole);
903
+ classEntries.push(`${JSON.stringify(a.name)}: ${h.code}`);
904
+ classReactive = classReactive || h.reactive;
905
+ classAt ??= h.at;
906
+ break;
907
+ }
908
+ case "StyleDirective": {
909
+ const h = this.hole(a.hole);
910
+ styleEntries.push(`${JSON.stringify(a.name)}: ${h.code}`);
911
+ styleReactive = styleReactive || h.reactive;
912
+ styleAt ??= h.at;
913
+ break;
914
+ }
915
+ case "BindDirective":
916
+ props.push(...this.bindProps(a.name, this.hole(a.hole)));
917
+ break;
918
+ case "UseDirective": {
919
+ const dir = a.name ?? (a.hole != null ? this.hole(a.hole).code : null);
920
+ if (!dir) break;
921
+ usePairs.push(a.name != null && a.hole != null ? `[${dir}, () => ${paren(this.hole(a.hole).code, "arrowBody")}]` : `[${dir}]`);
922
+ break;
923
+ }
924
+ }
925
+ }
926
+ if (classEntries.length > 0) {
927
+ props.push({
928
+ name: "classList",
929
+ kind: "attr",
930
+ expr: `{ ${classEntries.join(", ")} }`,
931
+ reactive: classReactive,
932
+ ...classAt ? { at: classAt } : {}
933
+ });
934
+ }
935
+ if (styleEntries.length > 0) {
936
+ props.push({
937
+ name: "style",
938
+ kind: "attr",
939
+ expr: `{ ${styleEntries.join(", ")} }`,
940
+ reactive: styleReactive,
941
+ ...styleAt ? { at: styleAt } : {}
942
+ });
943
+ }
944
+ if (usePairs.length > 0) {
945
+ props.push({ name: "use", kind: "attr", expr: `[${usePairs.join(", ")}]` });
946
+ }
947
+ return props;
948
+ }
949
+ /**
950
+ * Lower an event binding. Plain `@click`/`onClick` (no modifiers) stays a
951
+ * DELEGATED handler (unchanged, byte-identical with JSX). `on:click` or any
952
+ * modifier (`.capture`/`.once`/`.passive`/`.prevent`/`.stop`/`.self`) emits a
953
+ * NATIVE `on:name` prop the runtime attaches via addEventListener.
954
+ */
955
+ eventProp(a) {
956
+ const dom = a.name.toLowerCase();
957
+ const handler = this.hole(a.hole).code;
958
+ const native = a.syntax === "colon" || a.modifiers.length > 0;
959
+ if (!native) {
960
+ return {
961
+ name: "on" + capitalize(a.name),
962
+ kind: "event",
963
+ event: { name: dom, delegated: DELEGATED.has(dom) },
964
+ expr: handler
965
+ };
966
+ }
967
+ const wrapped = this.wrapHandler(handler, a.modifiers);
968
+ const options = this.eventOptions(a.modifiers);
969
+ const value = options ? `[${wrapped}, ${options}]` : wrapped;
970
+ return { name: "on:" + dom, kind: "attr", expr: value };
971
+ }
972
+ /** Wrap a handler for `.prevent`/`.stop`/`.self` (no wrap when none apply). */
973
+ wrapHandler(handler, mods) {
974
+ const guard = mods.includes("self") ? "if (e.target !== e.currentTarget) return; " : "";
975
+ const pre = [];
976
+ if (mods.includes("prevent")) pre.push("e.preventDefault();");
977
+ if (mods.includes("stop")) pre.push("e.stopPropagation();");
978
+ if (!guard && pre.length === 0) return handler;
979
+ return `(e) => { ${guard}${pre.join(" ")} return (${handler})(e); }`;
980
+ }
981
+ /** addEventListener options object from `.capture`/`.once`/`.passive`, or null. */
982
+ eventOptions(mods) {
983
+ const opts = [];
984
+ if (mods.includes("capture")) opts.push("capture: true");
985
+ if (mods.includes("once")) opts.push("once: true");
986
+ if (mods.includes("passive")) opts.push("passive: true");
987
+ return opts.length ? `{ ${opts.join(", ")} }` : null;
988
+ }
989
+ /** `bind:value=${sig}` → `value={read()}` + `onInput={e => write(e…value)}`. */
990
+ bindProps(prop, h) {
991
+ const sigCode = h.code;
992
+ const checked = prop === "checked";
993
+ const evt = checked ? "change" : "input";
994
+ const accessor = checked ? "checked" : "value";
995
+ this.used.add("bindPair");
996
+ const sig = `bindPair(${sigCode})`;
997
+ return [
998
+ {
999
+ name: prop,
1000
+ kind: "attr",
1001
+ expr: `${sig}[0]()`,
1002
+ reactive: true,
1003
+ directive: `bind:${prop}`,
1004
+ ...h.at ? { at: h.at } : {}
1005
+ },
1006
+ {
1007
+ name: "on" + capitalize(evt),
1008
+ kind: "event",
1009
+ event: { name: evt, delegated: DELEGATED.has(evt) },
1010
+ // delegated handler: `target` is the bound element (currentTarget is the root)
1011
+ expr: `(e) => ${sig}[1](e.target.${accessor})`
1012
+ }
1013
+ ];
1014
+ }
1015
+ /** A plain attribute (incl. lit `?bool`, mixed values) — old `mkProp` behavior. */
1016
+ plainAttr(a) {
1017
+ const v = a.value;
1018
+ let name = a.name;
1019
+ if (a.name === "class") {
1020
+ name = v && v.kind === "hole" && this.hole(v.hole).object ? "classList" : "className";
1021
+ } else if (a.name === "html") {
1022
+ name = "innerHTML";
1023
+ }
1024
+ const kind = "attr";
1025
+ const base = { name, kind };
1026
+ if (v == null) {
1027
+ base.literal = true;
1028
+ return base;
1029
+ }
1030
+ if (v.kind === "static") {
1031
+ base.literal = v.value;
1032
+ return base;
1033
+ }
1034
+ if (v.kind === "hole") {
1035
+ const h = this.hole(v.hole);
1036
+ base.expr = h.code;
1037
+ base.reactive = h.reactive;
1038
+ if (h.at) base.at = h.at;
1039
+ return base;
1040
+ }
1041
+ let reactive = false;
1042
+ let at;
1043
+ const body = v.parts.map((p) => {
1044
+ if ("text" in p) return escapeTemplate(p.text);
1045
+ const h = this.hole(p.hole);
1046
+ reactive = reactive || h.reactive;
1047
+ at ??= h.at;
1048
+ return "${" + h.code + "}";
1049
+ }).join("");
1050
+ base.expr = "`" + body + "`";
1051
+ base.reactive = reactive;
1052
+ if (at) base.at = at;
1053
+ return base;
1054
+ }
1055
+ };
1056
+ function lowerTemplate(pieces, holes, used, opts = {}) {
1057
+ const { root } = parseTemplate(pieces, { svg: opts.svg });
1058
+ return new Lowerer(holes, used, opts.sourceFile, opts.positionAt).lowerRoot(root.children);
1059
+ }
1060
+
1061
+ // src/optimize/analyze-static.ts
1062
+ function propReason(prop) {
1063
+ switch (prop.kind) {
1064
+ case "event":
1065
+ return "event";
1066
+ case "ref":
1067
+ return "ref";
1068
+ case "spread":
1069
+ return "spread";
1070
+ case "class":
1071
+ case "style":
1072
+ return "class-or-style-directive";
1073
+ case "attr":
1074
+ case "prop":
1075
+ if (prop.reactive) return "reactive-prop";
1076
+ if (prop.expr !== void 0) return "expression-prop";
1077
+ return void 0;
1078
+ /* c8 ignore next 2 */
1079
+ default:
1080
+ return "expression-prop";
1081
+ }
1082
+ }
1083
+ function analyzeStatic(root) {
1084
+ const staticElements = [];
1085
+ const reasons = /* @__PURE__ */ new Map();
1086
+ const visit = (node) => {
1087
+ switch (node.kind) {
1088
+ case "text":
1089
+ return true;
1090
+ case "expr":
1091
+ return false;
1092
+ case "component":
1093
+ case "control":
1094
+ for (const child of node.children) visit(child);
1095
+ return false;
1096
+ case "fragment":
1097
+ for (const child of node.children) visit(child);
1098
+ return false;
1099
+ case "element": {
1100
+ let childrenStatic = true;
1101
+ for (const child of node.children) {
1102
+ if (!visit(child)) childrenStatic = false;
1103
+ }
1104
+ let reason;
1105
+ for (const prop of node.props) {
1106
+ reason = propReason(prop);
1107
+ if (reason) break;
1108
+ }
1109
+ if (!reason && !childrenStatic) {
1110
+ reason = childReason(node);
1111
+ }
1112
+ node.static = !reason;
1113
+ if (reason) reasons.set(node, reason);
1114
+ else staticElements.push(node);
1115
+ return node.static;
1116
+ }
1117
+ /* c8 ignore next 2 */
1118
+ default:
1119
+ return false;
1120
+ }
1121
+ };
1122
+ for (const node of Array.isArray(root) ? root : [root]) visit(node);
1123
+ return { staticElements, reasons };
1124
+ }
1125
+ function childReason(node) {
1126
+ for (const child of node.children) {
1127
+ if (child.kind === "expr") return "expression-child";
1128
+ if (child.kind === "component") return "component-child";
1129
+ if (child.kind === "control") return "control-child";
1130
+ if (child.kind === "element" && !child.static) return "expression-child";
1131
+ if (child.kind === "fragment") return "expression-child";
1132
+ }
1133
+ return "expression-child";
1134
+ }
1135
+
1136
+ // src/resolve/builtins.ts
1137
+ var DOM_CONTROL_FLOW = [
1138
+ "Show",
1139
+ "For",
1140
+ "Index",
1141
+ "Switch",
1142
+ "Match",
1143
+ "Portal",
1144
+ "Dynamic",
1145
+ "ErrorBoundary"
1146
+ ];
1147
+ var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
1148
+ var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
1149
+ var BUILTIN_COMPONENTS = [
1150
+ ...DOM_CONTROL_FLOW,
1151
+ ...CORE_CONTROL_FLOW,
1152
+ ...ROUTER_COMPONENTS
1153
+ ];
1154
+ var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
1155
+ ...DOM_CONTROL_FLOW,
1156
+ ...CORE_CONTROL_FLOW
1157
+ ]);
1158
+ function builtinComponentMap(modules = {}) {
1159
+ const {
1160
+ controlFlowModule = "@fluixi/dom",
1161
+ coreModule = "@fluixi/core",
1162
+ routerModule = "@fluixi/core/router"
1163
+ } = modules;
1164
+ const map = {};
1165
+ for (const name of DOM_CONTROL_FLOW) map[name] = controlFlowModule;
1166
+ for (const name of CORE_CONTROL_FLOW) map[name] = coreModule;
1167
+ for (const name of ROUTER_COMPONENTS) map[name] = routerModule;
1168
+ return map;
1169
+ }
1170
+ function builtinComponents(modules = {}) {
1171
+ return { components: builtinComponentMap(modules) };
1172
+ }
1173
+ function routerComponents(routerModule) {
1174
+ const module = routerModule ?? "@fluixi/core/router";
1175
+ return { components: Object.fromEntries(ROUTER_COMPONENTS.map((n) => [n, module])) };
1176
+ }
1177
+
1178
+ // src/resolve/resolve-ir.ts
1179
+ function resolveComponentSources(root, options = {}) {
1180
+ const { resolver, isBound, modules, strategyFor } = options;
1181
+ const builtins = builtinComponentMap(modules);
1182
+ const resolved = /* @__PURE__ */ new Map();
1183
+ const unresolved = /* @__PURE__ */ new Set();
1184
+ const annotate = (node) => {
1185
+ const { name } = node;
1186
+ if (!name || name.includes(".")) return;
1187
+ if (isBound?.(name)) return;
1188
+ const source = sourceFor(name);
1189
+ if (!source) {
1190
+ unresolved.add(name);
1191
+ return;
1192
+ }
1193
+ const loading = source.origin === "builtin" && RESERVED_COMPONENTS.has(name) ? EAGER : strategyFor?.(node) ?? EAGER;
1194
+ node.source = { ...source, loading };
1195
+ resolved.set(name, node.source);
1196
+ };
1197
+ const sourceFor = (name) => {
1198
+ if (RESERVED_COMPONENTS.has(name)) {
1199
+ return { module: builtins[name], export: name, origin: "builtin" };
1200
+ }
1201
+ const rule = resolver?.resolve(name);
1202
+ if (rule) return { module: rule.module, export: rule.export, origin: "rule" };
1203
+ if (ROUTER_COMPONENTS.includes(name)) {
1204
+ return { module: builtins[name], export: name, origin: "builtin" };
1205
+ }
1206
+ return void 0;
1207
+ };
1208
+ walk(root, (node) => {
1209
+ if (node.kind === "component") annotate(node);
1210
+ });
1211
+ return { resolved, unresolved: [...unresolved] };
1212
+ }
1213
+ function walk(root, visit) {
1214
+ const nodes = Array.isArray(root) ? root : [root];
1215
+ for (const node of nodes) {
1216
+ visit(node);
1217
+ const children = node.children;
1218
+ if (children) walk(children, visit);
1219
+ }
1220
+ }
1221
+
1222
+ // src/optimize/collapse-strategies.ts
1223
+ function collapseStrategies(root) {
1224
+ const components = [];
1225
+ walk(root, (node) => {
1226
+ if (node.kind === "component" && node.source) components.push(node);
1227
+ });
1228
+ const eager = /* @__PURE__ */ new Set();
1229
+ const never = /* @__PURE__ */ new Set();
1230
+ for (const node of components) {
1231
+ const { module, loading } = node.source;
1232
+ if (loading.kind === "eager") eager.add(module);
1233
+ if (loading.kind === "never") never.add(module);
1234
+ }
1235
+ const collapsed = /* @__PURE__ */ new Map();
1236
+ for (const node of components) {
1237
+ const source = node.source;
1238
+ if (!isDeferred(source.loading)) continue;
1239
+ if (!eager.has(source.module)) continue;
1240
+ source.loading = { kind: "eager" };
1241
+ collapsed.set(source.module, (collapsed.get(source.module) ?? 0) + 1);
1242
+ }
1243
+ return {
1244
+ collapsed,
1245
+ conflicted: [...never].filter((m) => eager.has(m))
1246
+ };
1247
+ }
1248
+
1249
+ // src/resolve/component-resolver.ts
1250
+ var isMapRule = (rule) => "components" in rule;
1251
+ function substitute(template, match) {
1252
+ return template.replace(/\$(\d+)/g, (whole, index) => {
1253
+ const group = match[Number(index)];
1254
+ return group ?? whole;
1255
+ });
1256
+ }
1257
+ function normalise(name, entry) {
1258
+ return typeof entry === "string" ? { module: entry, export: name } : entry;
1259
+ }
1260
+ function createComponentResolver(rules = []) {
1261
+ const exact = /* @__PURE__ */ new Map();
1262
+ const conflicts = [];
1263
+ const patterns = [];
1264
+ for (const rule of rules) {
1265
+ if (!isMapRule(rule)) {
1266
+ patterns.push(rule);
1267
+ continue;
1268
+ }
1269
+ for (const [name, entry] of Object.entries(rule.components)) {
1270
+ const resolved = normalise(name, entry);
1271
+ const existing = exact.get(name);
1272
+ if (existing && existing.module !== resolved.module) {
1273
+ const conflict = conflicts.find((c) => c.name === name);
1274
+ if (conflict) conflict.modules.push(resolved.module);
1275
+ else conflicts.push({ name, modules: [existing.module, resolved.module] });
1276
+ continue;
1277
+ }
1278
+ exact.set(name, resolved);
1279
+ }
1280
+ }
1281
+ const cache = /* @__PURE__ */ new Map();
1282
+ const resolve = (name) => {
1283
+ if (cache.has(name)) return cache.get(name);
1284
+ let result = exact.get(name);
1285
+ if (!result) {
1286
+ for (const rule of patterns) {
1287
+ const match = name.match(new RegExp(rule.match.source, rule.match.flags.replace("g", "")));
1288
+ if (!match) continue;
1289
+ result = {
1290
+ module: substitute(rule.module, match),
1291
+ export: rule.export ? substitute(rule.export, match) : name
1292
+ };
1293
+ break;
1294
+ }
1295
+ }
1296
+ cache.set(name, result);
1297
+ return result;
1298
+ };
1299
+ return {
1300
+ resolve,
1301
+ names: () => [...exact.keys()],
1302
+ conflicts: () => conflicts
1303
+ };
1304
+ }
1305
+
1306
+ // src/lower/compile-template.ts
1307
+ function toPieces(source) {
1308
+ const pieces = [];
1309
+ let offset = 0;
1310
+ source.statics.forEach((text, i) => {
1311
+ pieces.push({ kind: "static", text, start: offset });
1312
+ offset += text.length;
1313
+ if (i < source.holes.length) {
1314
+ const end = offset + source.holes[i].code.length;
1315
+ pieces.push({ kind: "hole", index: i, start: offset, end });
1316
+ offset = end;
1317
+ }
1318
+ });
1319
+ return pieces;
1320
+ }
1321
+ function compileTemplate(source, options = {}) {
1322
+ if (source.statics.length !== source.holes.length + 1) {
1323
+ throw new Error(
1324
+ `[fluixi] compileTemplate: ${source.statics.length} static runs for ${source.holes.length} holes — a template always has exactly one more.`
1325
+ );
1326
+ }
1327
+ return compilePieces(toPieces(source), source.holes, options);
1328
+ }
1329
+ function compilePieces(pieces, holes, options = {}) {
1330
+ const used = /* @__PURE__ */ new Set();
1331
+ const ir = lowerTemplate(pieces, [...holes], used, {
1332
+ svg: options.svg,
1333
+ ...options.sourceFile ? { sourceFile: options.sourceFile } : {},
1334
+ ...options.positionAt ? { positionAt: options.positionAt } : {}
1335
+ });
1336
+ analyzeStatic(ir);
1337
+ resolveComponentSources(ir, {
1338
+ resolver: createComponentResolver(options.resolve ?? []),
1339
+ modules: {
1340
+ controlFlowModule: options.controlFlowModule ?? "@fluixi/dom",
1341
+ coreModule: options.coreModule ?? "@fluixi/core",
1342
+ routerModule: options.routerModule ?? "@fluixi/core/router"
1343
+ },
1344
+ strategyFor: (node) => node.load
1345
+ });
1346
+ collapseStrategies(ir);
1347
+ const { code, imports, templates } = imperativeBackend.emit(ir, {
1348
+ templateClone: options.templateClone,
1349
+ partialTemplates: options.partialTemplates
1350
+ });
1351
+ for (const symbol of imports) used.add(symbol);
1352
+ if (options.hoistTemplates) return { code, imports: [...used], ir, templates };
1353
+ return { code: inlineTemplates(code, templates), imports: [...used], ir };
1354
+ }
1355
+
1356
+ // src/resolve/component-globals.ts
1357
+ var DOM_GLOBALS = /* @__PURE__ */ new Set([
1358
+ "Text",
1359
+ "Image",
1360
+ "Option",
1361
+ "Audio",
1362
+ "Comment",
1363
+ "Range",
1364
+ "Selection",
1365
+ "Notification",
1366
+ "Event",
1367
+ "Document",
1368
+ "Element",
1369
+ "Node",
1370
+ "Screen",
1371
+ "Window",
1372
+ "Location",
1373
+ "History",
1374
+ "Storage",
1375
+ "Response",
1376
+ "Request",
1377
+ "Headers"
1378
+ ]);
1379
+ function packageOf(specifier) {
1380
+ if (specifier.startsWith(".") || specifier.startsWith("/")) return void 0;
1381
+ if (/^[~@]\//.test(specifier)) return void 0;
1382
+ const parts = specifier.split("/");
1383
+ return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
1384
+ }
1385
+ function namespaceAlias(module) {
1386
+ return `_${module.replace(/[^A-Za-z0-9]/g, "_")}`;
1387
+ }
1388
+ function componentGlobals(rules, options = {}) {
1389
+ const {
1390
+ available: availableList,
1391
+ builtins = true,
1392
+ intrinsics = true,
1393
+ generator = "@fluixi/compiler",
1394
+ specifier = (module) => module
1395
+ } = options;
1396
+ const all = [...rules];
1397
+ if (builtins) {
1398
+ all.push({ components: builtinComponentMap() });
1399
+ }
1400
+ const resolver = createComponentResolver(all);
1401
+ const available = availableList ? new Set(availableList) : void 0;
1402
+ const declared = [];
1403
+ const shadowedByDom = [];
1404
+ const unavailable = [];
1405
+ const resolved = /* @__PURE__ */ new Map();
1406
+ for (const name of [...resolver.names()].sort()) {
1407
+ const target = resolver.resolve(name);
1408
+ if (!target) continue;
1409
+ const pkg = packageOf(target.module);
1410
+ if (DOM_GLOBALS.has(name)) shadowedByDom.push(name);
1411
+ else if (available && pkg && !available.has(pkg)) unavailable.push(name);
1412
+ else {
1413
+ declared.push(name);
1414
+ resolved.set(name, target);
1415
+ }
1416
+ }
1417
+ const intrinsicModules = intrinsics ? [...new Set(Object.values(INTRINSICS).map((i) => i.module))] : [];
1418
+ const modules = [
1419
+ .../* @__PURE__ */ new Set([...declared.map((name) => resolved.get(name).module), ...intrinsicModules])
1420
+ ].sort();
1421
+ const imports = modules.map(
1422
+ (m) => `import * as ${namespaceAlias(m)} from '${specifier(m)}';`
1423
+ );
1424
+ const lines = declared.map((name) => {
1425
+ const target = resolved.get(name);
1426
+ const ns = namespaceAlias(target.module);
1427
+ return target.export === "default" ? ` const ${name}: typeof ${ns}.default;` : ` export import ${name} = ${ns}.${target.export};`;
1428
+ });
1429
+ const note = shadowedByDom.length > 0 ? `//
2
1430
  // Import these explicitly — lib.dom already declares the name, so an ambient
3
1431
  // declaration cannot win:
4
- `+p.map(u=>{let f=l.resolve(u)?.module;return`// import { ${u} } from '${f?a(f):""}';
5
- `}).join(""):"",ye=r?Object.entries(A).map(([u,f])=>` const ${u}: typeof ${J(f.module)}.${f.export};`):[],C=t.filter(u=>"match"in u).length,Ne=C>0?`//
6
- // ${C} pattern rule${C===1?"":"s"} cannot be declared:
1432
+ ` + shadowedByDom.map((n) => {
1433
+ const module = resolver.resolve(n)?.module;
1434
+ return `// import { ${n} } from '${module ? specifier(module) : ""}';
1435
+ `;
1436
+ }).join("") : "";
1437
+ const intrinsicLines = intrinsics ? Object.entries(INTRINSICS).map(
1438
+ ([name, intrinsic]) => ` const ${name}: typeof ${namespaceAlias(intrinsic.module)}.${intrinsic.export};`
1439
+ ) : [];
1440
+ const patternRules = rules.filter((rule) => "match" in rule).length;
1441
+ const patternNote = patternRules > 0 ? `//
1442
+ // ${patternRules} pattern rule${patternRules === 1 ? "" : "s"} cannot be declared:
7
1443
  // a pattern matches unboundedly many names, so there is no list to emit. Those
8
1444
  // tags still resolve at build time; declare them by hand if the editor needs them.
9
- `:"";return{source:`// GENERATED by ${i} — do not edit.
1445
+ ` : "";
1446
+ const source = `// GENERATED by ${generator} — do not edit.
10
1447
  //
11
1448
  // The components \`resolve\` supplies without an import. This describes what the
12
1449
  // compiler already does; it does not enable it.
13
- `+ke+Ne+(V.length>0?`
14
- ${V.join(`
15
- `)}
16
- `:`
17
- `)+`
1450
+ ` + note + patternNote + (imports.length > 0 ? `
1451
+ ${imports.join("\n")}
1452
+ ` : "\n") + `
18
1453
  declare global {
19
- ${[...be,...ye].join(`
20
- `)}
1454
+ ${[...lines, ...intrinsicLines].join("\n")}
1455
+ }
1456
+ `;
1457
+ return { source, declared, shadowedByDom, unavailable, patternRules };
1458
+ }
1459
+
1460
+ // src/resolve/write-globals.ts
1461
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
1462
+ import { dirname, relative, sep, resolve as resolvePath } from "node:path";
1463
+ var GENERATED_MARKER = "GENERATED by @fluixi/compiler";
1464
+ var DEFAULT_GLOBALS_PATH = "fluixi.d.ts";
1465
+ function coveredByInclude(root, target) {
1466
+ let config;
1467
+ try {
1468
+ const raw = readFileSync(resolvePath(root, "tsconfig.json"), "utf8");
1469
+ config = JSON.parse(raw.replace(/^\s*\/\/.*$/gm, ""));
1470
+ } catch {
1471
+ return void 0;
1472
+ }
1473
+ if (config.extends !== void 0) return void 0;
1474
+ if (!Array.isArray(config.include)) return true;
1475
+ const relative2 = relativePosix(root, target);
1476
+ return config.include.some((entry) => {
1477
+ if (typeof entry !== "string") return false;
1478
+ const pattern = entry.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "(?:.*/)?").replace(/\*/g, "[^/]*");
1479
+ return new RegExp(`^${pattern}(?:/.*)?$`).test(relative2);
1480
+ });
1481
+ }
1482
+ function relativePosix(from, to) {
1483
+ return relative(from, to).split(sep).join("/");
1484
+ }
1485
+ function forTypeScript(module, outDir, root) {
1486
+ if (!module.startsWith("/")) return module;
1487
+ const absolute = resolvePath(root, module.slice(1));
1488
+ let rel = relative(outDir, absolute).split(sep).join("/");
1489
+ if (!rel.startsWith(".")) rel = `./${rel}`;
1490
+ return rel.replace(/\.(tsx|ts|jsx|mts|cts)$/, ".js");
1491
+ }
1492
+ function projectDependencies(root) {
1493
+ try {
1494
+ const manifest = JSON.parse(readFileSync(resolvePath(root, "package.json"), "utf8"));
1495
+ return [
1496
+ ...Object.keys(manifest.dependencies ?? {}),
1497
+ ...Object.keys(manifest.devDependencies ?? {}),
1498
+ ...Object.keys(manifest.peerDependencies ?? {})
1499
+ ];
1500
+ } catch {
1501
+ return void 0;
1502
+ }
1503
+ }
1504
+ function writeComponentGlobals(options, root) {
1505
+ if (options.globals === false) return { status: "skipped", reason: "disabled" };
1506
+ const rules = options.resolve ?? [];
1507
+ const target = resolvePath(root, options.globals ?? DEFAULT_GLOBALS_PATH);
1508
+ let existing;
1509
+ try {
1510
+ existing = readFileSync(target, "utf8");
1511
+ } catch {
1512
+ existing = void 0;
1513
+ }
1514
+ if (existing !== void 0 && !existing.includes(GENERATED_MARKER)) {
1515
+ return { status: "skipped", reason: "foreign-file", path: target };
1516
+ }
1517
+ const { source, declared } = componentGlobals(rules, {
1518
+ available: projectDependencies(root),
1519
+ specifier: (module) => forTypeScript(module, dirname(target), root)
1520
+ });
1521
+ if (existing === source) {
1522
+ return {
1523
+ status: "unchanged",
1524
+ path: target,
1525
+ declared: declared.length,
1526
+ warning: warnIfUnreachable(root, target)
1527
+ };
1528
+ }
1529
+ mkdirSync(dirname(target), { recursive: true });
1530
+ writeFileSync(target, source);
1531
+ return {
1532
+ status: "written",
1533
+ path: target,
1534
+ declared: declared.length,
1535
+ warning: warnIfUnreachable(root, target)
1536
+ };
1537
+ }
1538
+ function warnIfUnreachable(root, target) {
1539
+ if (coveredByInclude(root, target) !== false) return void 0;
1540
+ const relative2 = relativePosix(root, target);
1541
+ return `[fluixi] ${relative2} is not covered by "include" in tsconfig.json, so TypeScript will ignore it and every resolved component stays "Cannot find name". Add "${relative2}" to "include".`;
21
1542
  }
22
- `,declared:d,shadowedByDom:p,unavailable:m,patternRules:C}}import{mkdirSync as tt,readFileSync as z,writeFileSync as nt}from"node:fs";import{dirname as ge,relative as ve,sep as Re,resolve as j}from"node:path";var rt="GENERATED by @fluixi/compiler",ot="fluixi.d.ts";function it(t,e){let n;try{let r=z(j(t,"tsconfig.json"),"utf8");n=JSON.parse(r.replace(/^\s*\/\/.*$/gm,""))}catch{return}if(n.extends!==void 0)return;if(!Array.isArray(n.include))return!0;let o=xe(t,e);return n.include.some(r=>{if(typeof r!="string")return!1;let i=r.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*\//g,"(?:.*/)?").replace(/\*/g,"[^/]*");return new RegExp(`^${i}(?:/.*)?$`).test(o)})}function xe(t,e){return ve(t,e).split(Re).join("/")}function st(t,e,n){if(!t.startsWith("/"))return t;let o=j(n,t.slice(1)),r=ve(e,o).split(Re).join("/");return r.startsWith(".")||(r=`./${r}`),r.replace(/\.(tsx|ts|jsx|mts|cts)$/,".js")}function at(t){try{let e=JSON.parse(z(j(t,"package.json"),"utf8"));return[...Object.keys(e.dependencies??{}),...Object.keys(e.devDependencies??{}),...Object.keys(e.peerDependencies??{})]}catch{return}}function tn(t,e){if(t.globals===!1)return{status:"skipped",reason:"disabled"};let n=t.resolve??[],o=j(e,t.globals??ot),r;try{r=z(o,"utf8")}catch{r=void 0}if(r!==void 0&&!r.includes(rt))return{status:"skipped",reason:"foreign-file",path:o};let{source:i,declared:a}=fe(n,{available:at(e),specifier:s=>st(s,ge(o),e)});return r===i?{status:"unchanged",path:o,declared:a.length,warning:he(e,o)}:(tt(ge(o),{recursive:!0}),nt(o,i),{status:"written",path:o,declared:a.length,warning:he(e,o)})}function he(t,e){if(it(t,e)!==!1)return;let n=xe(t,e);return`[fluixi] ${n} is not covered by "include" in tsconfig.json, so TypeScript will ignore it and every resolved component stays "Cannot find name". Add "${n}" to "include".`}var rn={backend:"imperative",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};var an={imperative:h};export{$t as BUILTIN_COMPONENTS,W as CORE_CONTROL_FLOW,ot as DEFAULT_GLOBALS_PATH,G as DOM_CONTROL_FLOW,U as RESERVED_COMPONENTS,I as ROUTER_COMPONENTS,B as RUNTIME_CONTRACT_V1,ft as RUNTIME_CONTRACT_V2,an as backends,E as builtinComponentMap,wt as builtinComponents,O as cleanTemplateText,Xe as compilePieces,Ut as compileTemplate,fe as componentGlobals,P as createComponentResolver,rn as defaultOptions,h as imperativeBackend,Ee as isReactiveShape,F as lowerTemplate,de as resolveComponentSources,St as routerComponents,M as walk,tn as writeComponentGlobals};
1543
+
1544
+ // src/options.ts
1545
+ var defaultOptions = {
1546
+ backend: "imperative",
1547
+ moduleName: "@fluixi/dom",
1548
+ delegateEvents: true,
1549
+ hydratable: false,
1550
+ sourceMaps: true,
1551
+ dev: false
1552
+ };
1553
+
1554
+ // src/index.ts
1555
+ var backends = {
1556
+ imperative: imperativeBackend
1557
+ };
1558
+ export {
1559
+ BUILTIN_COMPONENTS,
1560
+ CORE_CONTROL_FLOW,
1561
+ DEFAULT_GLOBALS_PATH,
1562
+ DOM_CONTROL_FLOW,
1563
+ RESERVED_COMPONENTS,
1564
+ ROUTER_COMPONENTS,
1565
+ RUNTIME_CONTRACT_V1,
1566
+ RUNTIME_CONTRACT_V2,
1567
+ backends,
1568
+ builtinComponentMap,
1569
+ builtinComponents,
1570
+ cleanTemplateText,
1571
+ compilePieces,
1572
+ compileTemplate,
1573
+ componentGlobals,
1574
+ createComponentResolver,
1575
+ defaultOptions,
1576
+ imperativeBackend,
1577
+ isReactiveShape,
1578
+ lowerTemplate,
1579
+ resolveComponentSources,
1580
+ routerComponents,
1581
+ walk,
1582
+ writeComponentGlobals
1583
+ };