@fluixi/compiler 1.0.0-alpha.81 → 1.0.0-alpha.83
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.
- package/dist/analyze/static-graph.cjs +1 -0
- package/dist/analyze/static-graph.d.ts +103 -0
- package/dist/analyze/static-graph.d.ts.map +1 -0
- package/dist/analyze/static-graph.js +869 -0
- package/dist/analyze/static-graph.mjs +1 -0
- package/dist/{babel-4JUDAR2G.mjs → babel-VXKH6MRQ.mjs} +1 -1
- package/dist/chunk-5KMMN5QP.mjs +1 -0
- package/dist/chunk-YKZ54NVE.mjs +1 -0
- package/dist/codegen/backends/imperative.cjs +1 -1
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +62 -11
- package/dist/codegen/backends/imperative.mjs +1 -1
- package/dist/codegen/partial-template.cjs +1 -1
- package/dist/codegen/partial-template.mjs +1 -1
- package/dist/codegen/serialize-static.cjs +1 -1
- package/dist/codegen/serialize-static.d.ts +16 -0
- package/dist/codegen/serialize-static.d.ts.map +1 -1
- package/dist/codegen/serialize-static.js +25 -0
- package/dist/codegen/serialize-static.mjs +1 -1
- package/dist/frontend/babel/build-ir-lit.cjs +1 -1
- package/dist/frontend/babel/build-ir-lit.mjs +1 -1
- package/dist/frontend/babel/build-ir.cjs +1 -1
- package/dist/frontend/babel/build-ir.mjs +1 -1
- package/dist/frontend/babel/index.cjs +1 -1
- package/dist/frontend/babel/index.mjs +1 -1
- package/dist/frontend/babel/lower-template.cjs +1 -1
- package/dist/frontend/babel/lower-template.mjs +1 -1
- package/dist/frontend/babel/plugin.cjs +1 -1
- package/dist/frontend/babel/plugin.mjs +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.mjs +8 -8
- package/dist/integrations.cjs +18 -18
- package/dist/integrations.d.ts +16 -0
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +21 -2
- package/dist/integrations.mjs +5 -5
- package/dist/ir/nodes.cjs +1 -1
- package/dist/ir/nodes.d.ts +46 -0
- package/dist/ir/nodes.d.ts.map +1 -1
- package/dist/lower/compile-template.cjs +1 -1
- package/dist/lower/compile-template.d.ts +12 -0
- package/dist/lower/compile-template.d.ts.map +1 -1
- package/dist/lower/compile-template.js +5 -1
- package/dist/lower/compile-template.mjs +1 -1
- package/dist/lower/jsx.cjs +1 -1
- package/dist/lower/jsx.d.ts +2 -0
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +25 -3
- package/dist/lower/jsx.mjs +1 -1
- package/dist/lower/template.cjs +1 -1
- package/dist/lower/template.d.ts +14 -1
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +101 -15
- package/dist/lower/template.mjs +1 -1
- package/dist/transform/index.cjs +5 -5
- package/dist/transform/index.mjs +12 -12
- package/dist/transform/source-locations.cjs +1 -0
- package/dist/transform/source-locations.d.ts +44 -0
- package/dist/transform/source-locations.d.ts.map +1 -0
- package/dist/transform/source-locations.js +238 -0
- package/dist/transform/source-locations.mjs +1 -0
- package/dist/transform/templates.cjs +4 -4
- package/dist/transform/templates.d.ts +12 -4
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +72 -7
- package/dist/transform/templates.mjs +11 -11
- package/dist/transform-C4ZXRVGP.mjs +8 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/chunk-PVR2SN3B.mjs +0 -1
- package/dist/chunk-QUIYULS2.mjs +0 -1
- package/dist/chunk-YR3SAEO7.mjs +0 -1
- package/dist/transform-5WC4FWJE.mjs +0 -8
package/dist/index.cjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
"use strict";var W=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var we=Object.prototype.hasOwnProperty;var Se=(t,e)=>{for(var n in e)W(t,n,{get:e[n],enumerable:!0})},Te=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of $e(e))!we.call(t,r)&&r!==n&&W(t,r,{get:()=>e[r],enumerable:!(o=Ce(e,r))||o.enumerable});return t};var Oe=t=>Te(W({},"__esModule",{value:!0}),t);var Rt={};Se(Rt,{BUILTIN_COMPONENTS:()=>nt,CORE_CONTROL_FLOW:()=>B,DEFAULT_GLOBALS_PATH:()=>be,DOM_CONTROL_FLOW:()=>_,RESERVED_COMPONENTS:()=>H,ROUTER_COMPONENTS:()=>y,RUNTIME_CONTRACT_V1:()=>j,RUNTIME_CONTRACT_V2:()=>ze,backends:()=>vt,builtinComponentMap:()=>N,builtinComponents:()=>rt,cleanTemplateText:()=>w,compilePieces:()=>Re,compileTemplate:()=>lt,componentGlobals:()=>K,createComponentResolver:()=>T,defaultOptions:()=>ht,imperativeBackend:()=>v,isReactiveShape:()=>Y,lowerTemplate:()=>L,resolveComponentSources:()=>V,routerComponents:()=>ot,walk:()=>S,writeComponentGlobals:()=>gt});module.exports=Oe(Rt);var Me="children";function Y(t){switch(t.kind){case"call":return!0;case"member":return t.property!==Me;case"compound":return t.parts.some(Y);case"opaque":return!1}}var fe=require("@fluixi/template-parser");var M={kind:"eager"},Pe=["pointerdown","focusin","keydown"],X=new Set(["eager","idle","visible","interaction","media","never"]),k=class extends Error{};function Q(t,e){let n=t.slice(5);if(!X.has(n))throw new k(`Unknown load strategy 'load:${n}'. Expected one of ${[...X].join(", ")}.`);switch(n){case"eager":return M;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?Ae(e):[...Pe]};case"media":if(!e)throw new k(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new k(`Unhandled load strategy '${n}'.`)}}function Ae(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new k("'load:interaction' was given no event names.");return e}function ee(t){return t.kind!=="eager"&&t.kind!=="never"}var je=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),te={className:"class",htmlFor:"for"},De=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Le=new Set(["script","style","textarea","title"]);function U(t){return Le.has(t)}function ne(t){return te[t]??t}function E(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!De.has(t.name)}function J(t){if(!t.static||U(t.tag))return!1;for(let e of t.props)if(!E(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&J(e)))return!1;return!0}function C(t){let e=t.props.map(Be).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return je.has(t.tag)?n:`${n}${t.children.map(_e).join("")}</${t.tag}>`}function _e(t){if(t.kind==="text")return Fe(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return C(t)}function Be(t){let e=te[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${He(String(n))}"`}function He(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Fe(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var Ge="<!--fx-->",We="<!--fx/-->";function A(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function Ue(t){return t.kind==="text"||t.kind==="element"&&re(t)}function re(t){return t.svg||U(t.tag)||!t.props.every(e=>E(e))?!1:t.children.every(e=>Ue(e)||A(e))}function P(t){if(A(t))return!0;let e=t.children;return e?e.some(P):!1}function oe(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"||oe(e))}function ie(t){if(!re(t)||!oe(t)||!t.children.some(P))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:Je(t),tag:t.tag,steps:e,holes:n};function i(a,s){let l=-1;a.children.forEach((d,p)=>{P(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(A(p)){let b=r(m),G=r(`holeEnd(${b})`);n.push({parentRef:s,startRef:b,endRef:G,node:p}),c=G;continue}let h=r(m);p.kind==="element"&&P(p)&&i(p,h),c=h}}}function Je(t){return C(se(t)).split(ae).join(Ge+We)}function se(t){return{...t,children:t.children.map(e=>A(e)?{kind:"text",value:ae}:e.kind==="element"?se(e):e)}}var ae="\0fx-hole\0";var j={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},ze={version:2,module:"@fluixi/dom",symbols:[...j.symbols,"template","cloneTemplate","walk"]};var Ve={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function qe(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function ce(t){return qe(t)?t:JSON.stringify(t)}function Ke(t){return t.expr!==void 0?t.reactive?`() => (${t.expr})`:`(${t.expr})`:JSON.stringify(t.literal??!0)}function Ze(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function Ye(t,e,n){let o=t.filter(s=>s.kind==="spread"),i=t.filter(s=>s.kind!=="spread").map(s=>`${ce(s.name)}: ${Ke(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 pe(t,e,n){return t.length===1?$(t[0],e,n):`[${t.map(o=>$(o,e,n)).join(", ")}]`}function le(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 ${ce(c.name)}() { return ${Ze(c)}; }`);n.length>0&&s.push(`get children() { return ${pe(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 Xe(t,e){let n=ne(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 de=!1;function $(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":pe(t.children,e,n);case"component":return le(t.name,t.props,t.children,e,n);case"control":{let o=Ve[t.control]??t.control;return e.add(o),le(o,t.props,t.children,e,n)}case"element":{if(n&&t.static&&!t.svg&&J(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;return n.push({id:s,html:C(t),tag:t.tag,svg:!1}),`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&de){let s=ie(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}, () => (${$(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(E))for(let s of t.props)i.push(Xe(r,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";i.push(`spread({ element: ${r}, props: ${Ye(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let l=$(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 D(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 v={name:"imperative",contract:j,emit(t,e){let n=new Set,o=e?.templateClone!==!1?[]:void 0;return de=e?.partialTemplates===!0,{code:$(t,n,o),imports:Array.from(n),templates:o}}};function w(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 ue=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Qe(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function me(t){return t.charAt(0).toUpperCase()+t.slice(1)}var z=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}=v.emit(e,{});for(let i of o)this.used.add(i);return D(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&&w(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=w(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(h=>h.name===l);m>=0?o[m]=p:o.push(p)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?Q(`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"+me(e.name),kind:"event",event:{name:n,delegated:ue.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"+me(r),kind:"event",event:{name:r,delegated:ue.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 Qe(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 L(t,e,n,o={}){let{root:r}=(0,fe.parseTemplate)(t,{svg:o.svg});return new z(e,n).lowerRoot(r.children)}function et(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 ge(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=et(s),a)break;return!a&&!i&&(a=tt(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 tt(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 _=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],B=["Suspense","SuspenseList","Await"],y=["Router","Outlet","Redirect","Link"],nt=[..._,...B,...y],H=new Set([..._,...B]);function N(t={}){let{controlFlowModule:e="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:o="@fluixi/core/router"}=t,r={};for(let i of _)r[i]=e;for(let i of B)r[i]=n;for(let i of y)r[i]=o;return r}function rt(t={}){return{components:N(t)}}function ot(t){let e=t??"@fluixi/core/router";return{components:Object.fromEntries(y.map(n=>[n,e]))}}function V(t,e={}){let{resolver:n,isBound:o,modules:r,strategyFor:i}=e,a=N(r),s=new Map,l=new Set,c=p=>{let{name:m}=p;if(!m||m.includes(".")||o?.(m))return;let h=d(m);if(!h){l.add(m);return}let b=h.origin==="builtin"&&H.has(m)?M:i?.(p)??M;p.source={...h,loading:b},s.set(m,p.source)},d=p=>{if(H.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(y.includes(p))return{module:a[p],export:p,origin:"builtin"}};return S(t,p=>{p.kind==="component"&&c(p)}),{resolved:s,unresolved:[...l]}}function S(t,e){let n=Array.isArray(t)?t:[t];for(let o of n){e(o);let r=o.children;r&&S(r,e)}}function he(t){let e=[];S(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;ee(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 it=t=>"components"in t;function ve(t,e){return t.replace(/\$(\d+)/g,(n,o)=>e[Number(o)]??n)}function st(t,e){return typeof e=="string"?{module:e,export:t}:e}function T(t=[]){let e=new Map,n=[],o=[];for(let a of t){if(!it(a)){o.push(a);continue}for(let[s,l]of Object.entries(a.components)){let c=st(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:ve(l.module,c),export:l.export?ve(l.export,c):a};break}}return r.set(a,s),s},names:()=>[...e.keys()],conflicts:()=>n}}function at(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 lt(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 Re(at(t),t.holes,e)}function Re(t,e,n={}){let o=new Set,r=L(t,[...e],o,{svg:n.svg});ge(r),V(r,{resolver:T(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:l=>l.load}),he(r);let{code:i,imports:a,templates:s}=v.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:D(i,s),imports:[...o],ir:r}}var x="@fluixi/reactive/signal",F={$signal:{export:"signal",module:x,returns:"signal-handle"},$memo:{export:"memo",module:x,returns:"memo-handle"},$effect:{export:"effect",module:x,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:x,returns:"resource-handle"},$selector:{export:"createSelector",module:x,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:x,returns:"memo-accessor"},$untrack:{export:"untrack",module:x,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}};var Xt=new RegExp(`\\$(?:${Object.keys(F).map(t=>t.slice(1)).join("|")})\\s*\\(`);var ct=new Set(["Text","Image","Option","Audio","Comment","Range","Selection","Notification","Event","Document","Element","Node","Screen","Window","Location","History","Storage","Response","Request","Headers"]);function pt(t){if(t.startsWith(".")||t.startsWith("/")||/^[~@]\//.test(t))return;let e=t.split("/");return t.startsWith("@")?e.slice(0,2).join("/"):e[0]}function q(t){return`_${t.replace(/[^A-Za-z0-9]/g,"_")}`}function K(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:N()});let l=T(s),c=n?new Set(n):void 0,d=[],p=[],m=[],h=new Map;for(let u of[...l.names()].sort()){let g=l.resolve(u);if(!g)continue;let I=pt(g.module);ct.has(u)?p.push(u):c&&I&&!c.has(I)?m.push(u):(d.push(u),h.set(u,g))}let b=r?[...new Set(Object.values(F).map(u=>u.module))]:[],Z=[...new Set([...d.map(u=>h.get(u).module),...b])].sort().map(u=>`import * as ${q(u)} from '${a(u)}';`),ye=d.map(u=>{let g=h.get(u),I=q(g.module);return g.export==="default"?` const ${u}: typeof ${I}.default;`:` export import ${u} = ${I}.${g.export};`}),Ne=p.length>0?`//
|
|
1
|
+
"use strict";var U=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var Me=(t,e)=>{for(var n in e)U(t,n,{get:e[n],enumerable:!0})},De=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Oe(e))!Pe.call(t,r)&&r!==n&&U(t,r,{get:()=>e[r],enumerable:!(o=Ae(e,r))||o.enumerable});return t};var je=t=>De(U({},"__esModule",{value:!0}),t);var Et={};Me(Et,{BUILTIN_COMPONENTS:()=>ct,CORE_CONTROL_FLOW:()=>J,DEFAULT_GLOBALS_PATH:()=>Ee,DOM_CONTROL_FLOW:()=>H,RESERVED_COMPONENTS:()=>W,ROUTER_COMPONENTS:()=>k,RUNTIME_CONTRACT_V1:()=>L,RUNTIME_CONTRACT_V2:()=>Ye,backends:()=>It,builtinComponentMap:()=>I,builtinComponents:()=>pt,cleanTemplateText:()=>A,compilePieces:()=>ke,compileTemplate:()=>gt,componentGlobals:()=>Y,createComponentResolver:()=>P,defaultOptions:()=>kt,imperativeBackend:()=>v,isReactiveShape:()=>Q,lowerTemplate:()=>F,resolveComponentSources:()=>q,routerComponents:()=>ut,walk:()=>O,writeComponentGlobals:()=>Nt});module.exports=je(Et);var _e="children";function Q(t){switch(t.kind){case"call":return!0;case"member":return t.property!==_e;case"compound":return t.parts.some(Q);case"opaque":return!1}}var xe=require("@fluixi/template-parser");var D={kind:"eager"},Le=["pointerdown","focusin","keydown"],ee=new Set(["eager","idle","visible","interaction","media","never"]),b=class extends Error{};function te(t,e){let n=t.slice(5);if(!ee.has(n))throw new b(`Unknown load strategy 'load:${n}'. Expected one of ${[...ee].join(", ")}.`);switch(n){case"eager":return D;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?Be(e):[...Le]};case"media":if(!e)throw new b(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new b(`Unhandled load strategy '${n}'.`)}}function Be(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new b("'load:interaction' was given no event names.");return e}function ne(t){return t.kind!=="eager"&&t.kind!=="never"}var Fe=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),re={className:"class",htmlFor:"for"},He=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Je=new Set(["script","style","textarea","title"]);function V(t){return Je.has(t)}function oe(t){return re[t]??t}function $(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!He.has(t.name)}function G(t){if(!t.static||V(t.tag))return!1;for(let e of t.props)if(!$(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&G(e)))return!1;return!0}function C(t){let e=t.props.map(Ue).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return Fe.has(t.tag)?n:`${n}${t.children.map(We).join("")}</${t.tag}>`}function We(t){if(t.kind==="text")return Ge(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return C(t)}function Ue(t){let e=re[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${Ve(String(n))}"`}function Ve(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Ge(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function K(t){let e=[],n,o=r=>{n??=r.at?.file,e.push(r.at?.line??0,r.at?.column??0);for(let i of r.children)i.kind==="element"&&o(i)};return o(t),n&&e.some(r=>r!==0)?{file:n,pos:e}:void 0}var Ke="<!--fx-->",ze="<!--fx/-->";function _(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function qe(t){return t.kind==="text"||t.kind==="element"&&ie(t)}function ie(t){return t.svg||V(t.tag)||!t.props.every(e=>$(e))?!1:t.children.every(e=>qe(e)||_(e))}function j(t){if(_(t))return!0;let e=t.children;return e?e.some(j):!1}function se(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"||se(e))}function ae(t){if(!ie(t)||!se(t)||!t.children.some(j))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:Ze(t),tag:t.tag,steps:e,holes:n};function i(a,s){let p=-1;a.children.forEach((l,u)=>{j(l)&&(p=u)});let c=null;for(let l=0;l<=p;l++){let u=a.children[l],d=c?`${c}.nextSibling`:`${s}.firstChild`;if(_(u)){let R=r(d),E=r(`holeEnd(${R})`);n.push({parentRef:s,startRef:R,endRef:E,node:u}),c=E;continue}let g=r(d);u.kind==="element"&&j(u)&&i(u,g),c=g}}}function Ze(t){return C(le(t)).split(ce).join(Ke+ze)}function le(t){return{...t,children:t.children.map(e=>_(e)?{kind:"text",value:ce}:e.kind==="element"?le(e):e)}}var ce="\0fx-hole\0";var L={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Ye={version:2,module:"@fluixi/dom",symbols:[...L.symbols,"template","cloneTemplate","walk"]};var y="@fluixi/reactive/signal",N={$signal:{export:"signal",module:y,returns:"signal-handle"},$memo:{export:"memo",module:y,returns:"memo-handle"},$effect:{export:"effect",module:y,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:y,returns:"resource-handle"},$selector:{export:"createSelector",module:y,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:y,returns:"memo-accessor"},$untrack:{export:"untrack",module:y,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}};var Mt=new RegExp(`\\$(?:${Object.keys(N).map(t=>t.slice(1)).join("|")})\\s*\\(`);var pe="__fx_source";var Xe="__fx_hole",w=(t,e,n,o)=>`(globalThis.${Xe} ?? ((f) => f))(${t},${e},${n}${o===void 0?"":`,${JSON.stringify(o)}`})`,Qe="__fx_props",ue=(t,e)=>`(globalThis.${Qe} ?? ((p) => p))(${t},${JSON.stringify(e)})`;var et={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function tt(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function fe(t){return tt(t)?t:JSON.stringify(t)}function nt(t){if(t.expr!==void 0){if(t.name==="ref"&&t.at)return w(`(${t.expr})`,t.at.line,t.at.column,t.expr);if(!t.reactive)return`(${t.expr})`;let e=`() => (${t.expr})`;return t.at?w(e,t.at.line,t.at.column,t.directive):e}return JSON.stringify(t.literal??!0)}function rt(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function ot(t,e,n){let o=t.filter(s=>s.kind==="spread"),i=t.filter(s=>s.kind!=="spread").map(s=>`${fe(s.name)}: ${nt(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 de(t,e){return e?w(t,e.line,e.column):t}function ge(t,e,n){return t.length===1?T(t[0],e,n):`[${t.map(o=>T(o,e,n)).join(", ")}]`}function me(t,e,n,o,r,i){o.add("createMemo"),o.add("createComponent");let a=e.filter(d=>d.kind==="spread"),s=e.filter(d=>d.kind!=="spread"),p=s.map(d=>`get ${fe(d.name)}() { return ${rt(d)}; }`);n.length>0&&p.push(`get children() { return ${ge(n,o,r)}; }`);let c=`{ ${p.join(", ")} }`;a.length>0&&(o.add("mergeProps"),c=`mergeProps(${a.map(d=>d.expr).join(", ")}, ${c})`);let l={};for(let d of s)d.at&&(l[d.name]=[d.at.line,d.at.column]);return Object.keys(l).length&&(c=ue(c,l)),`createMemo((${i?`globalThis.${pe}?.(${JSON.stringify(i.file)},${i.line},${i.column},${JSON.stringify(t)}), `:""}() => createComponent(${t}, ${c})))`}function it(t,e){let n=oe(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 he=!1;function T(t,e,n){switch(t.kind){case"text":return JSON.stringify(t.value);case"expr":{if(!t.reactive)return`(${t.code})`;let o=`() => (${t.code})`;return t.at?w(o,t.at.line,t.at.column):o}case"fragment":return t.children.length===0?"null":ge(t.children,e,n);case"component":return de(me(t.name,t.props,t.children,e,n,t.at),t.bindAt??t.at);case"control":{let o=et[t.control]??t.control;return e.add(o),de(me(o,t.props,t.children,e,n),t.bindAt)}case"element":{if(n&&t.static&&!t.svg&&G(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;n.push({id:s,html:C(t),tag:t.tag,svg:!1});let p=K(t);return p?`templateNode(${s}, ${JSON.stringify(t.tag)}, false, false, ${JSON.stringify(p)})`:`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&he){let s=ae(t);if(s){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let p=`_tmpl$${n.length}`;n.push({id:p,html:s.html,tag:s.tag,svg:!1});let c=K(t),l=[`const _el$ = templateNode(${p}, ${JSON.stringify(s.tag)}, true${c?`, false, ${JSON.stringify(c)}`:""});`];for(let u of s.steps)l.push(`const ${u.ref} = ${u.expr};`);for(let u of s.holes)l.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${T(u.node,e,n)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return l.push("return _el$;"),`(() => { ${l.join(" ")} })()`}}e.add("createNativeElement");let o=JSON.stringify(t.tag),r="_el$",i=[],a=t.at?`${o}, ${t.svg}, ${JSON.stringify(t.at)}`:t.svg?`${o}, true`:o;if(i.push(`const ${r} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every($))for(let s of t.props)i.push(it(r,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";i.push(`spread({ element: ${r}, props: ${ot(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let p=T(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";i.push(c?`insert(${r}, ${p}, null);`:`insert(${r}, ${p});`)}return i.push(`return ${r};`),`(() => { ${i.join(" ")} })()`}}}function B(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 v={name:"imperative",contract:L,emit(t,e){let n=new Set,o=e?.templateClone!==!1?[]:void 0;return he=e?.partialTemplates===!0,{code:T(t,n,o),imports:Array.from(n),templates:o}}};function A(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 Re=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function st(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function ve(t){return t.charAt(0).toUpperCase()+t.slice(1)}var z=class{constructor(e,n,o,r){this.holes=e;this.used=n;this.sourceFile=o;this.positionAt=r}tagAt(e){let n=e.loc?.start;if(!this.sourceFile||!this.positionAt||n==null)return;let{line:o,column:r}=this.positionAt(n);return{file:this.sourceFile,line:o,column:r}}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:n,imports:o,templates:r}=v.emit(e,{});for(let i of o)this.used.add(i);return B(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 p=e[s],c=p&&(p.kind==="Element"||p.kind==="Component")&&p.attributes.some(l=>l.kind==="ElseDirective");n.push(this.lowerIf(r,a.hole,c?p: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&&A(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=A(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,...n.at?{at:n.at}:{}}}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(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=e.attributes.filter(a=>a!==n),i=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return i.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),i}let o=this.tagAt(e);return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1,...o?{at:o}:{}}}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,u]of r){let d=u.length===1?u[0]:{kind:"fragment",children:u},g={name:l,kind:"attr",expr:this.emit(d),jsxElement:!0},R=o.findIndex(E=>E.name===l);R>=0?o[R]=g:o.push(g)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?te(`load:${a.strategy}`,a.modifier):void 0,p=o.find(l=>l.at&&l.reactive)?.at,c=this.tagAt(e);return{kind:"component",name:n,props:o,children:this.lowerChildren(i),...c?{at:c}:{},...p?{bindAt:p}:{},...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),p=n.get(i.value.value)??[];p.push(s),n.set(i.value.value,p);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,...r.at?{at:r.at}:{}}];if(o){let p=this.stripAndLower(o,c=>c.kind==="ElseDirective");i.push({name:"fallback",kind:"attr",expr:this.emit(p),jsxElement:!0})}let a=this.stripAndLower(e,p=>p.kind==="IfDirective"),s=this.tagAt(e);return{kind:"component",name:"Show",props:i,children:[a],...s?{at:s}:{},...r.at?{bindAt:r.at}:{}}}lowerEach(e){let n=e.attributes.find(c=>c.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,...o.at?{at:o.at}:{}}];if(n.key){let c="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;r.push({name:"by",kind:"attr",expr:c})}let i=this.itemArrow(e),a;if(i){let c={kind:"expr",code:i.body,reactive:i.bodyReactive},l=this.rebuildWithChildren(e,[c]);a=`(${i.params.join(", ")}) => (${this.emit(l)})`}else{let c=this.stripAndLower(e,l=>l.kind==="EachDirective");a=`() => (${this.emit(c)})`}let s=[{kind:"expr",code:a,reactive:!1}],p=this.tagAt(e);return{kind:"component",name:"For",props:r,children:s,...p?{at:p}:{},...o.at?{bindAt:o.at}:{}}}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"));if(e.kind==="Element"){let r=this.tagAt(e);return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:o,children:n,static:!1,...r?{at:r}:{}}}return{kind:"component",name:e.tag,props:o,children:n}}lowerAttributes(e){let n=[],o=[],r=!1,i,a=[],s=!1,p,c=[];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,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});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,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let u=this.hole(l.hole);o.push(`${JSON.stringify(l.name)}: ${u.code}`),r=r||u.reactive,i??=u.at;break}case"StyleDirective":{let u=this.hole(l.hole);a.push(`${JSON.stringify(l.name)}: ${u.code}`),s=s||u.reactive,p??=u.at;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole)));break;case"UseDirective":{let u=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!u)break;c.push(l.name!=null&&l.hole!=null?`[${u}, () => (${this.hole(l.hole).code})]`:`[${u}]`);break}}return o.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:r,...i?{at:i}:{}}),a.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${a.join(", ")} }`,reactive:s,...p?{at:p}:{}}),c.length>0&&n.push({name:"use",kind:"attr",expr:`[${c.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"+ve(e.name),kind:"event",event:{name:n,delegated:Re.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=n.code,r=e==="checked",i=r?"change":"input",a=r?"checked":"value";this.used.add("bindPair");let s=`bindPair(${o})`;return[{name:e,kind:"attr",expr:`${s}[0]()`,reactive:!0,directive:`bind:${e}`,...n.at?{at:n.at}:{}},{name:"on"+ve(i),kind:"event",event:{name:i,delegated:Re.has(i)},expr:`(e) => ${s}[1](e.target.${a})`}]}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 c=this.hole(n.hole);return i.expr=c.code,i.reactive=c.reactive,c.at&&(i.at=c.at),i}let a=!1,s,p=n.parts.map(c=>{if("text"in c)return st(c.text);let l=this.hole(c.hole);return a=a||l.reactive,s??=l.at,"${"+l.code+"}"}).join("");return i.expr="`"+p+"`",i.reactive=a,s&&(i.at=s),i}};function F(t,e,n,o={}){let{root:r}=(0,xe.parseTemplate)(t,{svg:o.svg});return new z(e,n,o.sourceFile,o.positionAt).lowerRoot(r.children)}function at(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 ye(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=at(s),a)break;return!a&&!i&&(a=lt(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 lt(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 H=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],J=["Suspense","SuspenseList","Await"],k=["Router","Outlet","Redirect","Link"],ct=[...H,...J,...k],W=new Set([...H,...J]);function I(t={}){let{controlFlowModule:e="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:o="@fluixi/core/router"}=t,r={};for(let i of H)r[i]=e;for(let i of J)r[i]=n;for(let i of k)r[i]=o;return r}function pt(t={}){return{components:I(t)}}function ut(t){let e=t??"@fluixi/core/router";return{components:Object.fromEntries(k.map(n=>[n,e]))}}function q(t,e={}){let{resolver:n,isBound:o,modules:r,strategyFor:i}=e,a=I(r),s=new Map,p=new Set,c=u=>{let{name:d}=u;if(!d||d.includes(".")||o?.(d))return;let g=l(d);if(!g){p.add(d);return}let R=g.origin==="builtin"&&W.has(d)?D:i?.(u)??D;u.source={...g,loading:R},s.set(d,u.source)},l=u=>{if(W.has(u))return{module:a[u],export:u,origin:"builtin"};let d=n?.resolve(u);if(d)return{module:d.module,export:d.export,origin:"rule"};if(k.includes(u))return{module:a[u],export:u,origin:"builtin"}};return O(t,u=>{u.kind==="component"&&c(u)}),{resolved:s,unresolved:[...p]}}function O(t,e){let n=Array.isArray(t)?t:[t];for(let o of n){e(o);let r=o.children;r&&O(r,e)}}function be(t){let e=[];O(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;ne(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 dt=t=>"components"in t;function Ne(t,e){return t.replace(/\$(\d+)/g,(n,o)=>e[Number(o)]??n)}function mt(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(!dt(a)){o.push(a);continue}for(let[s,p]of Object.entries(a.components)){let c=mt(s,p),l=e.get(s);if(l&&l.module!==c.module){let u=n.find(d=>d.name===s);u?u.modules.push(c.module):n.push({name:s,modules:[l.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 p of o){let c=a.match(new RegExp(p.match.source,p.match.flags.replace("g","")));if(c){s={module:Ne(p.module,c),export:p.export?Ne(p.export,c):a};break}}return r.set(a,s),s},names:()=>[...e.keys()],conflicts:()=>n}}function ft(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 gt(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 ke(ft(t),t.holes,e)}function ke(t,e,n={}){let o=new Set,r=F(t,[...e],o,{svg:n.svg,...n.sourceFile?{sourceFile:n.sourceFile}:{},...n.positionAt?{positionAt:n.positionAt}:{}});ye(r),q(r,{resolver:P(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:p=>p.load}),be(r);let{code:i,imports:a,templates:s}=v.emit(r,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let p of a)o.add(p);return n.hoistTemplates?{code:i,imports:[...o],ir:r,templates:s}:{code:B(i,s),imports:[...o],ir:r}}var ht=new Set(["Text","Image","Option","Audio","Comment","Range","Selection","Notification","Event","Document","Element","Node","Screen","Window","Location","History","Storage","Response","Request","Headers"]);function Rt(t){if(t.startsWith(".")||t.startsWith("/")||/^[~@]\//.test(t))return;let e=t.split("/");return t.startsWith("@")?e.slice(0,2).join("/"):e[0]}function Z(t){return`_${t.replace(/[^A-Za-z0-9]/g,"_")}`}function Y(t,e={}){let{available:n,builtins:o=!0,intrinsics:r=!0,generator:i="@fluixi/compiler",specifier:a=m=>m}=e,s=[...t];o&&s.push({components:I()});let p=P(s),c=n?new Set(n):void 0,l=[],u=[],d=[],g=new Map;for(let m of[...p.names()].sort()){let h=p.resolve(m);if(!h)continue;let S=Rt(h.module);ht.has(m)?u.push(m):c&&S&&!c.has(S)?d.push(m):(l.push(m),g.set(m,h))}let R=r?[...new Set(Object.values(N).map(m=>m.module))]:[],X=[...new Set([...l.map(m=>g.get(m).module),...R])].sort().map(m=>`import * as ${Z(m)} from '${a(m)}';`),$e=l.map(m=>{let h=g.get(m),S=Z(h.module);return h.export==="default"?` const ${m}: typeof ${S}.default;`:` export import ${m} = ${S}.${h.export};`}),Ce=u.length>0?`//
|
|
2
2
|
// Import these explicitly — lib.dom already declares the name, so an ambient
|
|
3
3
|
// declaration cannot win:
|
|
4
|
-
`+
|
|
5
|
-
`}).join(""):"",
|
|
6
|
-
// ${
|
|
4
|
+
`+u.map(m=>{let h=p.resolve(m)?.module;return`// import { ${m} } from '${h?a(h):""}';
|
|
5
|
+
`}).join(""):"",we=r?Object.entries(N).map(([m,h])=>` const ${m}: typeof ${Z(h.module)}.${h.export};`):[],M=t.filter(m=>"match"in m).length,Te=M>0?`//
|
|
6
|
+
// ${M} pattern rule${M===1?"":"s"} cannot be declared:
|
|
7
7
|
// a pattern matches unboundedly many names, so there is no list to emit. Those
|
|
8
8
|
// tags still resolve at build time; declare them by hand if the editor needs them.
|
|
9
9
|
`:"";return{source:`// GENERATED by ${i} — do not edit.
|
|
10
10
|
//
|
|
11
11
|
// The components \`resolve\` supplies without an import. This describes what the
|
|
12
12
|
// compiler already does; it does not enable it.
|
|
13
|
-
`+
|
|
14
|
-
${
|
|
13
|
+
`+Ce+Te+(X.length>0?`
|
|
14
|
+
${X.join(`
|
|
15
15
|
`)}
|
|
16
16
|
`:`
|
|
17
17
|
`)+`
|
|
18
18
|
declare global {
|
|
19
|
-
${[
|
|
19
|
+
${[...$e,...we].join(`
|
|
20
20
|
`)}
|
|
21
21
|
}
|
|
22
|
-
`,declared:
|
|
22
|
+
`,declared:l,shadowedByDom:u,unavailable:d,patternRules:M}}var x=require("node:fs"),f=require("node:path");var vt="GENERATED by @fluixi/compiler",Ee="fluixi.d.ts";function xt(t,e){let n;try{let r=(0,x.readFileSync)((0,f.resolve)(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=Se(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 Se(t,e){return(0,f.relative)(t,e).split(f.sep).join("/")}function yt(t,e,n){if(!t.startsWith("/"))return t;let o=(0,f.resolve)(n,t.slice(1)),r=(0,f.relative)(e,o).split(f.sep).join("/");return r.startsWith(".")||(r=`./${r}`),r.replace(/\.(tsx|ts|jsx|mts|cts)$/,".js")}function bt(t){try{let e=JSON.parse((0,x.readFileSync)((0,f.resolve)(t,"package.json"),"utf8"));return[...Object.keys(e.dependencies??{}),...Object.keys(e.devDependencies??{}),...Object.keys(e.peerDependencies??{})]}catch{return}}function Nt(t,e){if(t.globals===!1)return{status:"skipped",reason:"disabled"};let n=t.resolve??[],o=(0,f.resolve)(e,t.globals??Ee),r;try{r=(0,x.readFileSync)(o,"utf8")}catch{r=void 0}if(r!==void 0&&!r.includes(vt))return{status:"skipped",reason:"foreign-file",path:o};let{source:i,declared:a}=Y(n,{available:bt(e),specifier:s=>yt(s,(0,f.dirname)(o),e)});return r===i?{status:"unchanged",path:o,declared:a.length,warning:Ie(e,o)}:((0,x.mkdirSync)((0,f.dirname)(o),{recursive:!0}),(0,x.writeFileSync)(o,i),{status:"written",path:o,declared:a.length,warning:Ie(e,o)})}function Ie(t,e){if(xt(t,e)!==!1)return;let n=Se(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 kt={backend:"imperative",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};var It={imperative:v};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,eAAe,CAAC;AAG9B,cAAc,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,eAAe,CAAC;AAG9B,cAAc,4BAA4B,CAAC;AAM3C,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,cAAc,6BAA6B,CAAC;AAG5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,iFAAiF;AACjF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAEnD,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,9 @@ export * from './ir/nodes.js';
|
|
|
11
11
|
// The reactivity rule, expressed over shapes rather than a parser's AST — so a
|
|
12
12
|
// front-end supplies the mapping and inherits the semantics.
|
|
13
13
|
export * from './analyze/reactive-expr.js';
|
|
14
|
+
// analyzeReactiveGraph is not here: it parses, and this entry reaches no babel — the
|
|
15
|
+
// ts-plugin imports it and a stray parser is a module that fails to resolve for it. It is
|
|
16
|
+
// `@fluixi/compiler/analyze`.
|
|
14
17
|
// Template lowering + the Babel-free compile entry. `compileTemplate` goes from
|
|
15
18
|
// a parsed template to runtime calls without a JavaScript toolchain in the path.
|
|
16
19
|
export { lowerTemplate } from './lower/template.js';
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
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,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Ae(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}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
|
+
var we="children";function Te(t){switch(t.kind){case"call":return!0;case"member":return t.property!==we;case"compound":return t.parts.some(Te);case"opaque":return!1}}import{parseTemplate as Xe}from"@fluixi/template-parser";var T={kind:"eager"},Ae=["pointerdown","focusin","keydown"],Z=new Set(["eager","idle","visible","interaction","media","never"]),x=class extends Error{};function Y(t,e){let n=t.slice(5);if(!Z.has(n))throw new x(`Unknown load strategy 'load:${n}'. Expected one of ${[...Z].join(", ")}.`);switch(n){case"eager":return T;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?Oe(e):[...Ae]};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 Oe(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 X(t){return t.kind!=="eager"&&t.kind!=="never"}var Pe=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Q={className:"class",htmlFor:"for"},Me=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),De=new Set(["script","style","textarea","title"]);function L(t){return De.has(t)}function ee(t){return Q[t]??t}function k(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!Me.has(t.name)}function B(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"&&B(e)))return!1;return!0}function I(t){let e=t.props.map(_e).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return Pe.has(t.tag)?n:`${n}${t.children.map(je).join("")}</${t.tag}>`}function je(t){if(t.kind==="text")return Be(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return I(t)}function _e(t){let e=Q[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${Le(String(n))}"`}function Le(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Be(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function F(t){let e=[],n,o=r=>{n??=r.at?.file,e.push(r.at?.line??0,r.at?.column??0);for(let i of r.children)i.kind==="element"&&o(i)};return o(t),n&&e.some(r=>r!==0)?{file:n,pos:e}:void 0}var Fe="<!--fx-->",He="<!--fx/-->";function O(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function Je(t){return t.kind==="text"||t.kind==="element"&&te(t)}function te(t){return t.svg||L(t.tag)||!t.props.every(e=>k(e))?!1:t.children.every(e=>Je(e)||O(e))}function A(t){if(O(t))return!0;let e=t.children;return e?e.some(A):!1}function ne(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"||ne(e))}function re(t){if(!te(t)||!ne(t)||!t.children.some(A))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:We(t),tag:t.tag,steps:e,holes:n};function i(a,s){let p=-1;a.children.forEach((l,u)=>{A(l)&&(p=u)});let c=null;for(let l=0;l<=p;l++){let u=a.children[l],d=c?`${c}.nextSibling`:`${s}.firstChild`;if(O(u)){let h=r(d),b=r(`holeEnd(${h})`);n.push({parentRef:s,startRef:h,endRef:b,node:u}),c=b;continue}let f=r(d);u.kind==="element"&&A(u)&&i(u,f),c=f}}}function We(t){return I(oe(t)).split(ie).join(Fe+He)}function oe(t){return{...t,children:t.children.map(e=>O(e)?{kind:"text",value:ie}:e.kind==="element"?oe(e):e)}}var ie="\0fx-hole\0";var H={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},bt={version:2,module:"@fluixi/dom",symbols:[...H.symbols,"template","cloneTemplate","walk"]};var R="@fluixi/reactive/signal",y={$signal:{export:"signal",module:R,returns:"signal-handle"},$memo:{export:"memo",module:R,returns:"memo-handle"},$effect:{export:"effect",module:R,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:R,returns:"resource-handle"},$selector:{export:"createSelector",module:R,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:R,returns:"memo-accessor"},$untrack:{export:"untrack",module:R,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}};var kt=new RegExp(`\\$(?:${Object.keys(y).map(t=>t.slice(1)).join("|")})\\s*\\(`);var se="__fx_source";var Ue="__fx_hole",E=(t,e,n,o)=>`(globalThis.${Ue} ?? ((f) => f))(${t},${e},${n}${o===void 0?"":`,${JSON.stringify(o)}`})`,Ve="__fx_props",ae=(t,e)=>`(globalThis.${Ve} ?? ((p) => p))(${t},${JSON.stringify(e)})`;var Ge={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Ke(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function pe(t){return Ke(t)?t:JSON.stringify(t)}function ze(t){if(t.expr!==void 0){if(t.name==="ref"&&t.at)return E(`(${t.expr})`,t.at.line,t.at.column,t.expr);if(!t.reactive)return`(${t.expr})`;let e=`() => (${t.expr})`;return t.at?E(e,t.at.line,t.at.column,t.directive):e}return JSON.stringify(t.literal??!0)}function qe(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function Ze(t,e,n){let o=t.filter(s=>s.kind==="spread"),i=t.filter(s=>s.kind!=="spread").map(s=>`${pe(s.name)}: ${ze(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 le(t,e){return e?E(t,e.line,e.column):t}function ue(t,e,n){return t.length===1?S(t[0],e,n):`[${t.map(o=>S(o,e,n)).join(", ")}]`}function ce(t,e,n,o,r,i){o.add("createMemo"),o.add("createComponent");let a=e.filter(d=>d.kind==="spread"),s=e.filter(d=>d.kind!=="spread"),p=s.map(d=>`get ${pe(d.name)}() { return ${qe(d)}; }`);n.length>0&&p.push(`get children() { return ${ue(n,o,r)}; }`);let c=`{ ${p.join(", ")} }`;a.length>0&&(o.add("mergeProps"),c=`mergeProps(${a.map(d=>d.expr).join(", ")}, ${c})`);let l={};for(let d of s)d.at&&(l[d.name]=[d.at.line,d.at.column]);return Object.keys(l).length&&(c=ae(c,l)),`createMemo((${i?`globalThis.${se}?.(${JSON.stringify(i.file)},${i.line},${i.column},${JSON.stringify(t)}), `:""}() => createComponent(${t}, ${c})))`}function Ye(t,e){let n=ee(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 de=!1;function S(t,e,n){switch(t.kind){case"text":return JSON.stringify(t.value);case"expr":{if(!t.reactive)return`(${t.code})`;let o=`() => (${t.code})`;return t.at?E(o,t.at.line,t.at.column):o}case"fragment":return t.children.length===0?"null":ue(t.children,e,n);case"component":return le(ce(t.name,t.props,t.children,e,n,t.at),t.bindAt??t.at);case"control":{let o=Ge[t.control]??t.control;return e.add(o),le(ce(o,t.props,t.children,e,n),t.bindAt)}case"element":{if(n&&t.static&&!t.svg&&B(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;n.push({id:s,html:I(t),tag:t.tag,svg:!1});let p=F(t);return p?`templateNode(${s}, ${JSON.stringify(t.tag)}, false, false, ${JSON.stringify(p)})`:`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&de){let s=re(t);if(s){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let p=`_tmpl$${n.length}`;n.push({id:p,html:s.html,tag:s.tag,svg:!1});let c=F(t),l=[`const _el$ = templateNode(${p}, ${JSON.stringify(s.tag)}, true${c?`, false, ${JSON.stringify(c)}`:""});`];for(let u of s.steps)l.push(`const ${u.ref} = ${u.expr};`);for(let u of s.holes)l.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${S(u.node,e,n)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return l.push("return _el$;"),`(() => { ${l.join(" ")} })()`}}e.add("createNativeElement");let o=JSON.stringify(t.tag),r="_el$",i=[],a=t.at?`${o}, ${t.svg}, ${JSON.stringify(t.at)}`: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(Ye(r,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";i.push(`spread({ element: ${r}, props: ${Ze(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let p=S(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";i.push(c?`insert(${r}, ${p}, null);`:`insert(${r}, ${p});`)}return i.push(`return ${r};`),`(() => { ${i.join(" ")} })()`}}}function P(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 v={name:"imperative",contract:H,emit(t,e){let n=new Set,o=e?.templateClone!==!1?[]:void 0;return de=e?.partialTemplates===!0,{code:S(t,n,o),imports:Array.from(n),templates:o}}};function M(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 me=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Qe(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function fe(t){return t.charAt(0).toUpperCase()+t.slice(1)}var J=class{constructor(e,n,o,r){this.holes=e;this.used=n;this.sourceFile=o;this.positionAt=r}tagAt(e){let n=e.loc?.start;if(!this.sourceFile||!this.positionAt||n==null)return;let{line:o,column:r}=this.positionAt(n);return{file:this.sourceFile,line:o,column:r}}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:n,imports:o,templates:r}=v.emit(e,{});for(let i of o)this.used.add(i);return P(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 p=e[s],c=p&&(p.kind==="Element"||p.kind==="Component")&&p.attributes.some(l=>l.kind==="ElseDirective");n.push(this.lowerIf(r,a.hole,c?p: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&&M(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=M(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,...n.at?{at:n.at}:{}}}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(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=e.attributes.filter(a=>a!==n),i=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return i.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),i}let o=this.tagAt(e);return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1,...o?{at:o}:{}}}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,u]of r){let d=u.length===1?u[0]:{kind:"fragment",children:u},f={name:l,kind:"attr",expr:this.emit(d),jsxElement:!0},h=o.findIndex(b=>b.name===l);h>=0?o[h]=f:o.push(f)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?Y(`load:${a.strategy}`,a.modifier):void 0,p=o.find(l=>l.at&&l.reactive)?.at,c=this.tagAt(e);return{kind:"component",name:n,props:o,children:this.lowerChildren(i),...c?{at:c}:{},...p?{bindAt:p}:{},...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),p=n.get(i.value.value)??[];p.push(s),n.set(i.value.value,p);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,...r.at?{at:r.at}:{}}];if(o){let p=this.stripAndLower(o,c=>c.kind==="ElseDirective");i.push({name:"fallback",kind:"attr",expr:this.emit(p),jsxElement:!0})}let a=this.stripAndLower(e,p=>p.kind==="IfDirective"),s=this.tagAt(e);return{kind:"component",name:"Show",props:i,children:[a],...s?{at:s}:{},...r.at?{bindAt:r.at}:{}}}lowerEach(e){let n=e.attributes.find(c=>c.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,...o.at?{at:o.at}:{}}];if(n.key){let c="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;r.push({name:"by",kind:"attr",expr:c})}let i=this.itemArrow(e),a;if(i){let c={kind:"expr",code:i.body,reactive:i.bodyReactive},l=this.rebuildWithChildren(e,[c]);a=`(${i.params.join(", ")}) => (${this.emit(l)})`}else{let c=this.stripAndLower(e,l=>l.kind==="EachDirective");a=`() => (${this.emit(c)})`}let s=[{kind:"expr",code:a,reactive:!1}],p=this.tagAt(e);return{kind:"component",name:"For",props:r,children:s,...p?{at:p}:{},...o.at?{bindAt:o.at}:{}}}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"));if(e.kind==="Element"){let r=this.tagAt(e);return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:o,children:n,static:!1,...r?{at:r}:{}}}return{kind:"component",name:e.tag,props:o,children:n}}lowerAttributes(e){let n=[],o=[],r=!1,i,a=[],s=!1,p,c=[];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,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});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,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let u=this.hole(l.hole);o.push(`${JSON.stringify(l.name)}: ${u.code}`),r=r||u.reactive,i??=u.at;break}case"StyleDirective":{let u=this.hole(l.hole);a.push(`${JSON.stringify(l.name)}: ${u.code}`),s=s||u.reactive,p??=u.at;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole)));break;case"UseDirective":{let u=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!u)break;c.push(l.name!=null&&l.hole!=null?`[${u}, () => (${this.hole(l.hole).code})]`:`[${u}]`);break}}return o.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:r,...i?{at:i}:{}}),a.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${a.join(", ")} }`,reactive:s,...p?{at:p}:{}}),c.length>0&&n.push({name:"use",kind:"attr",expr:`[${c.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"+fe(e.name),kind:"event",event:{name:n,delegated:me.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=n.code,r=e==="checked",i=r?"change":"input",a=r?"checked":"value";this.used.add("bindPair");let s=`bindPair(${o})`;return[{name:e,kind:"attr",expr:`${s}[0]()`,reactive:!0,directive:`bind:${e}`,...n.at?{at:n.at}:{}},{name:"on"+fe(i),kind:"event",event:{name:i,delegated:me.has(i)},expr:`(e) => ${s}[1](e.target.${a})`}]}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 c=this.hole(n.hole);return i.expr=c.code,i.reactive=c.reactive,c.at&&(i.at=c.at),i}let a=!1,s,p=n.parts.map(c=>{if("text"in c)return Qe(c.text);let l=this.hole(c.hole);return a=a||l.reactive,s??=l.at,"${"+l.code+"}"}).join("");return i.expr="`"+p+"`",i.reactive=a,s&&(i.at=s),i}};function W(t,e,n,o={}){let{root:r}=Xe(t,{svg:o.svg});return new J(e,n,o.sourceFile,o.positionAt).lowerRoot(r.children)}function et(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 ge(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=et(s),a)break;return!a&&!i&&(a=tt(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 tt(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 U=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],V=["Suspense","SuspenseList","Await"],$=["Router","Outlet","Redirect","Link"],Gt=[...U,...V,...$],G=new Set([...U,...V]);function C(t={}){let{controlFlowModule:e="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:o="@fluixi/core/router"}=t,r={};for(let i of U)r[i]=e;for(let i of V)r[i]=n;for(let i of $)r[i]=o;return r}function Kt(t={}){return{components:C(t)}}function zt(t){let e=t??"@fluixi/core/router";return{components:Object.fromEntries($.map(n=>[n,e]))}}function he(t,e={}){let{resolver:n,isBound:o,modules:r,strategyFor:i}=e,a=C(r),s=new Map,p=new Set,c=u=>{let{name:d}=u;if(!d||d.includes(".")||o?.(d))return;let f=l(d);if(!f){p.add(d);return}let h=f.origin==="builtin"&&G.has(d)?T:i?.(u)??T;u.source={...f,loading:h},s.set(d,u.source)},l=u=>{if(G.has(u))return{module:a[u],export:u,origin:"builtin"};let d=n?.resolve(u);if(d)return{module:d.module,export:d.export,origin:"rule"};if($.includes(u))return{module:a[u],export:u,origin:"builtin"}};return D(t,u=>{u.kind==="component"&&c(u)}),{resolved:s,unresolved:[...p]}}function D(t,e){let n=Array.isArray(t)?t:[t];for(let o of n){e(o);let r=o.children;r&&D(r,e)}}function Re(t){let e=[];D(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;X(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 nt=t=>"components"in t;function ve(t,e){return t.replace(/\$(\d+)/g,(n,o)=>e[Number(o)]??n)}function rt(t,e){return typeof e=="string"?{module:e,export:t}:e}function j(t=[]){let e=new Map,n=[],o=[];for(let a of t){if(!nt(a)){o.push(a);continue}for(let[s,p]of Object.entries(a.components)){let c=rt(s,p),l=e.get(s);if(l&&l.module!==c.module){let u=n.find(d=>d.name===s);u?u.modules.push(c.module):n.push({name:s,modules:[l.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 p of o){let c=a.match(new RegExp(p.match.source,p.match.flags.replace("g","")));if(c){s={module:ve(p.module,c),export:p.export?ve(p.export,c):a};break}}return r.set(a,s),s},names:()=>[...e.keys()],conflicts:()=>n}}function ot(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 pn(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 it(ot(t),t.holes,e)}function it(t,e,n={}){let o=new Set,r=W(t,[...e],o,{svg:n.svg,...n.sourceFile?{sourceFile:n.sourceFile}:{},...n.positionAt?{positionAt:n.positionAt}:{}});ge(r),he(r,{resolver:j(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:p=>p.load}),Re(r);let{code:i,imports:a,templates:s}=v.emit(r,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let p of a)o.add(p);return n.hoistTemplates?{code:i,imports:[...o],ir:r,templates:s}:{code:P(i,s),imports:[...o],ir:r}}var st=new Set(["Text","Image","Option","Audio","Comment","Range","Selection","Notification","Event","Document","Element","Node","Screen","Window","Location","History","Storage","Response","Request","Headers"]);function at(t){if(t.startsWith(".")||t.startsWith("/")||/^[~@]\//.test(t))return;let e=t.split("/");return t.startsWith("@")?e.slice(0,2).join("/"):e[0]}function K(t){return`_${t.replace(/[^A-Za-z0-9]/g,"_")}`}function xe(t,e={}){let{available:n,builtins:o=!0,intrinsics:r=!0,generator:i="@fluixi/compiler",specifier:a=m=>m}=e,s=[...t];o&&s.push({components:C()});let p=j(s),c=n?new Set(n):void 0,l=[],u=[],d=[],f=new Map;for(let m of[...p.names()].sort()){let g=p.resolve(m);if(!g)continue;let N=at(g.module);st.has(m)?u.push(m):c&&N&&!c.has(N)?d.push(m):(l.push(m),f.set(m,g))}let h=r?[...new Set(Object.values(y).map(m=>m.module))]:[],q=[...new Set([...l.map(m=>f.get(m).module),...h])].sort().map(m=>`import * as ${K(m)} from '${a(m)}';`),Ee=l.map(m=>{let g=f.get(m),N=K(g.module);return g.export==="default"?` const ${m}: typeof ${N}.default;`:` export import ${m} = ${N}.${g.export};`}),Se=u.length>0?`//
|
|
2
2
|
// Import these explicitly — lib.dom already declares the name, so an ambient
|
|
3
3
|
// declaration cannot win:
|
|
4
|
-
`+
|
|
5
|
-
`}).join(""):""
|
|
6
|
-
// ${
|
|
4
|
+
`+u.map(m=>{let g=p.resolve(m)?.module;return`// import { ${m} } from '${g?a(g):""}';
|
|
5
|
+
`}).join(""):"",$e=r?Object.entries(y).map(([m,g])=>` const ${m}: typeof ${K(g.module)}.${g.export};`):[],w=t.filter(m=>"match"in m).length,Ce=w>0?`//
|
|
6
|
+
// ${w} pattern rule${w===1?"":"s"} cannot be declared:
|
|
7
7
|
// a pattern matches unboundedly many names, so there is no list to emit. Those
|
|
8
8
|
// tags still resolve at build time; declare them by hand if the editor needs them.
|
|
9
9
|
`:"";return{source:`// GENERATED by ${i} — do not edit.
|
|
10
10
|
//
|
|
11
11
|
// The components \`resolve\` supplies without an import. This describes what the
|
|
12
12
|
// compiler already does; it does not enable it.
|
|
13
|
-
`+
|
|
14
|
-
${
|
|
13
|
+
`+Se+Ce+(q.length>0?`
|
|
14
|
+
${q.join(`
|
|
15
15
|
`)}
|
|
16
16
|
`:`
|
|
17
17
|
`)+`
|
|
18
18
|
declare global {
|
|
19
|
-
${[...
|
|
19
|
+
${[...Ee,...$e].join(`
|
|
20
20
|
`)}
|
|
21
21
|
}
|
|
22
|
-
`,declared:
|
|
22
|
+
`,declared:l,shadowedByDom:u,unavailable:d,patternRules:w}}import{mkdirSync as lt,readFileSync as z,writeFileSync as ct}from"node:fs";import{dirname as ye,relative as Ne,sep as ke,resolve as _}from"node:path";var pt="GENERATED by @fluixi/compiler",ut="fluixi.d.ts";function dt(t,e){let n;try{let r=z(_(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=Ie(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 Ie(t,e){return Ne(t,e).split(ke).join("/")}function mt(t,e,n){if(!t.startsWith("/"))return t;let o=_(n,t.slice(1)),r=Ne(e,o).split(ke).join("/");return r.startsWith(".")||(r=`./${r}`),r.replace(/\.(tsx|ts|jsx|mts|cts)$/,".js")}function ft(t){try{let e=JSON.parse(z(_(t,"package.json"),"utf8"));return[...Object.keys(e.dependencies??{}),...Object.keys(e.devDependencies??{}),...Object.keys(e.peerDependencies??{})]}catch{return}}function xn(t,e){if(t.globals===!1)return{status:"skipped",reason:"disabled"};let n=t.resolve??[],o=_(e,t.globals??ut),r;try{r=z(o,"utf8")}catch{r=void 0}if(r!==void 0&&!r.includes(pt))return{status:"skipped",reason:"foreign-file",path:o};let{source:i,declared:a}=xe(n,{available:ft(e),specifier:s=>mt(s,ye(o),e)});return r===i?{status:"unchanged",path:o,declared:a.length,warning:be(e,o)}:(lt(ye(o),{recursive:!0}),ct(o,i),{status:"written",path:o,declared:a.length,warning:be(e,o)})}function be(t,e){if(dt(t,e)!==!1)return;let n=Ie(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 bn={backend:"imperative",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};var In={imperative:v};export{Gt as BUILTIN_COMPONENTS,V as CORE_CONTROL_FLOW,ut as DEFAULT_GLOBALS_PATH,U as DOM_CONTROL_FLOW,G as RESERVED_COMPONENTS,$ as ROUTER_COMPONENTS,H as RUNTIME_CONTRACT_V1,bt as RUNTIME_CONTRACT_V2,In as backends,C as builtinComponentMap,Kt as builtinComponents,M as cleanTemplateText,it as compilePieces,pn as compileTemplate,xe as componentGlobals,j as createComponentResolver,bn as defaultOptions,v as imperativeBackend,Te as isReactiveShape,W as lowerTemplate,he as resolveComponentSources,zt as routerComponents,D as walk,xn as writeComponentGlobals};
|