@fluixi/compiler 1.0.0-alpha.82 → 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/transform/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var xt=Object.create;var G=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var bt=Object.getPrototypeOf,St=Object.prototype.hasOwnProperty;var Et=(e,t)=>{for(var n in t)G(e,n,{get:t[n],enumerable:!0})},Ce=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kt(t))!St.call(e,o)&&o!==n&&G(e,o,{get:()=>t[o],enumerable:!(r=Rt(t,o))||r.enumerable});return e};var $e=(e,t,n)=>(n=e!=null?xt(bt(e)):{},Ce(t||!e||!e.__esModule?G(n,"default",{value:e,enumerable:!0}):n,e)),It=e=>Ce(G({},"__esModule",{value:!0}),e);var Mn={};Et(Mn,{explainBail:()=>le,moduleBindings:()=>L,planPropsDestructure:()=>ae,shapeOf:()=>w,transformProps:()=>st,transformTemplates:()=>Nt});module.exports=It(Mn);var mt=require("@babel/parser"),gt=$e(require("magic-string"),1);function wt(e){switch(e.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 e.reactive?"reactive-prop":e.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function M(e){let t=[],n=new Map,r=o=>{switch(o.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of o.children)r(s);return!1;case"fragment":for(let s of o.children)r(s);return!1;case"element":{let s=!0;for(let i of o.children)r(i)||(s=!1);let a;for(let i of o.props)if(a=wt(i),a)break;return!a&&!s&&(a=Ct(o)),o.static=!a,a?n.set(o,a):t.push(o),o.static}default:return!1}};for(let o of Array.isArray(e)?e:[e])r(o);return{staticElements:t,reasons:n}}function Ct(e){for(let t of e.children){if(t.kind==="expr")return"expression-child";if(t.kind==="component")return"component-child";if(t.kind==="control")return"control-child";if(t.kind==="element"&&!t.static||t.kind==="fragment")return"expression-child"}return"expression-child"}var Z={kind:"eager"},$t=["pointerdown","focusin","keydown"],Te=new Set(["eager","idle","visible","interaction","media","never"]),I=class extends Error{};function de(e){return e.startsWith("load:")}function Y(e,t){let n=e.slice(5);if(!Te.has(n))throw new I(`Unknown load strategy 'load:${n}'. Expected one of ${[...Te].join(", ")}.`);switch(n){case"eager":return Z;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return t?{kind:"visible",rootMargin:t}:{kind:"visible"};case"interaction":return{kind:"interaction",events:t?Tt(t):[...$t]};case"media":if(!t)throw new I(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new I(`Unhandled load strategy '${n}'.`)}}function Tt(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new I("'load:interaction' was given no event names.");return t}function j(e){return e.kind!=="eager"&&e.kind!=="never"}var J=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],B=["Suspense","SuspenseList","Await"],O=["Router","Outlet","Redirect","Link"],Ln=[...J,...B,...O],ue=new Set([...J,...B]);function Pe(e={}){let{controlFlowModule:t="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:r="@fluixi/core/router"}=e,o={};for(let s of J)o[s]=t;for(let s of B)o[s]=n;for(let s of O)o[s]=r;return o}function Q(e,t={}){let{resolver:n,isBound:r,modules:o,strategyFor:s}=t,a=Pe(o),i=new Map,l=new Set,c=f=>{let{name:d}=f;if(!d||d.includes(".")||r?.(d))return;let g=p(d);if(!g){l.add(d);return}let m=g.origin==="builtin"&&ue.has(d)?Z:s?.(f)??Z;f.source={...g,loading:m},i.set(d,f.source)},p=f=>{if(ue.has(f))return{module:a[f],export:f,origin:"builtin"};let d=n?.resolve(f);if(d)return{module:d.module,export:d.export,origin:"rule"};if(O.includes(f))return{module:a[f],export:f,origin:"builtin"}};return ee(e,f=>{f.kind==="component"&&c(f)}),{resolved:i,unresolved:[...l]}}function ee(e,t){let n=Array.isArray(e)?e:[e];for(let r of n){t(r);let o=r.children;o&&ee(o,t)}}function te(e){let t=[];ee(e,s=>{s.kind==="component"&&s.source&&t.push(s)});let n=new Set,r=new Set;for(let s of t){let{module:a,loading:i}=s.source;i.kind==="eager"&&n.add(a),i.kind==="never"&&r.add(a)}let o=new Map;for(let s of t){let a=s.source;j(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},o.set(a.module,(o.get(a.module)??0)+1))}return{collapsed:o,conflicted:[...r].filter(s=>n.has(s))}}var Pt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Me={className:"class",htmlFor:"for"},Mt=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Ot=new Set(["script","style","textarea","title"]);function fe(e){return Ot.has(e)}function Oe(e){return Me[e]??e}function _(e){return e.kind!=="attr"||e.expr!==void 0||e.name.includes(":")?!1:!Mt.has(e.name)}function me(e){if(!e.static||fe(e.tag))return!1;for(let t of e.props)if(!_(t))return!1;for(let t of e.children)if(t.kind!=="text"&&!(t.kind==="element"&&me(t)))return!1;return!0}function F(e){let t=e.props.map(At).filter(Boolean).join(""),n=`<${e.tag}${t}>`;return Pt.has(e.tag)?n:`${n}${e.children.map(Dt).join("")}</${e.tag}>`}function Dt(e){if(e.kind==="text")return jt(e.value);if(e.kind!=="element")throw new Error(`serializeStatic: unexpected ${e.kind}`);return F(e)}function At(e){let t=Me[e.name]??e.name,n=e.literal;return n===!0||n===void 0?` ${t}`:n===!1||n===null?"":` ${t}="${Lt(String(n))}"`}function Lt(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function jt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var Jt="<!--fx-->",Bt="<!--fx/-->";function re(e){return e.kind==="expr"||e.kind==="component"||e.kind==="control"}function _t(e){return e.kind==="text"||e.kind==="element"&&De(e)}function De(e){return e.svg||fe(e.tag)||!e.props.every(t=>_(t))?!1:e.children.every(t=>_t(t)||re(t))}function ne(e){if(re(e))return!0;let t=e.children;return t?t.some(ne):!1}function Ae(e){for(let t=0;t<e.children.length;t++){let n=e.children[t];if(n.kind==="text"&&(n.value===""||e.children[t+1]?.kind==="text"))return!1}return e.children.every(t=>t.kind!=="element"||Ae(t))}function Le(e){if(!De(e)||!Ae(e)||!e.children.some(ne))return null;let t=[],n=[],r=0,o=a=>{let i=`_n$${r++}`;return t.push({ref:i,expr:a}),i};return s(e,"_el$"),{html:Ft(e),tag:e.tag,steps:t,holes:n};function s(a,i){let l=-1;a.children.forEach((p,f)=>{ne(p)&&(l=f)});let c=null;for(let p=0;p<=l;p++){let f=a.children[p],d=c?`${c}.nextSibling`:`${i}.firstChild`;if(re(f)){let m=o(d),h=o(`holeEnd(${m})`);n.push({parentRef:i,startRef:m,endRef:h,node:f}),c=h;continue}let g=o(d);f.kind==="element"&&ne(f)&&s(f,g),c=g}}}function Ft(e){return F(je(e)).split(Je).join(Jt+Bt)}function je(e){return{...e,children:e.children.map(t=>re(t)?{kind:"text",value:Je}:t.kind==="element"?je(t):t)}}var Je="\0fx-hole\0";var ge={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Wn={version:2,module:"@fluixi/dom",symbols:[...ge.symbols,"template","cloneTemplate","walk"]};var Ht={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Vt(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function _e(e){return Vt(e)?e:JSON.stringify(e)}function Xt(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function zt(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function Ut(e,t,n){let r=e.filter(i=>i.kind==="spread"),s=e.filter(i=>i.kind!=="spread").map(i=>`${_e(i.name)}: ${Xt(i)}`);t!=null&&s.push(`children: ${t}`);let a=`{ ${s.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(i=>i.expr).join(", ")}, ${a})`):a}function Fe(e,t,n){return e.length===1?H(e[0],t,n):`[${e.map(r=>H(r,t,n)).join(", ")}]`}function Be(e,t,n,r,o){r.add("createMemo"),r.add("createComponent");let s=t.filter(c=>c.kind==="spread"),i=t.filter(c=>c.kind!=="spread").map(c=>`get ${_e(c.name)}() { return ${zt(c)}; }`);n.length>0&&i.push(`get children() { return ${Fe(n,r,o)}; }`);let l=`{ ${i.join(", ")} }`;return s.length>0&&(r.add("mergeProps"),l=`mergeProps(${s.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${e}, ${l}))`}function Wt(e,t){let n=Oe(t.name),r=t.literal;return r===!0||r===void 0?`${e}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${e}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var He=!1;function H(e,t,n){switch(e.kind){case"text":return JSON.stringify(e.value);case"expr":return e.reactive?`() => (${e.code})`:`(${e.code})`;case"fragment":return e.children.length===0?"null":Fe(e.children,t,n);case"component":return Be(e.name,e.props,e.children,t,n);case"control":{let r=Ht[e.control]??e.control;return t.add(r),Be(r,e.props,e.children,t,n)}case"element":{if(n&&e.static&&!e.svg&&me(e)){t.add("templateNode");let i=`_tmpl$${n.length}`;return n.push({id:i,html:F(e),tag:e.tag,svg:!1}),`templateNode(${i}, ${JSON.stringify(e.tag)})`}if(n&&He){let i=Le(e);if(i){t.add("templateNode"),t.add("insert"),t.add("holeEnd"),t.add("holeContent"),t.add("holeScope");let l=`_tmpl$${n.length}`;n.push({id:l,html:i.html,tag:i.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(i.tag)}, true);`];for(let p of i.steps)c.push(`const ${p.ref} = ${p.expr};`);for(let p of i.holes)c.push(`insert(${p.parentRef}, holeScope(${p.startRef}, () => (${H(p.node,t,n)})), ${p.endRef}, holeContent(${p.startRef}, ${p.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}t.add("createNativeElement");let r=JSON.stringify(e.tag),o="_el$",s=[],a=e.svg?`${r}, true`:r;if(s.push(`const ${o} = createNativeElement(${a});`),e.props.length>0)if(!e.svg&&e.props.every(_))for(let i of e.props)s.push(Wt(o,i));else{t.add("spread");let i=e.svg?", isSVG: true":"";s.push(`spread({ element: ${o}, props: ${Ut(e.props,null,t)}${i} });`)}for(let i of e.children){t.add("insert");let l=H(i,t,n),c=i.kind==="expr"&&i.reactive||i.kind==="component"||i.kind==="control";s.push(c?`insert(${o}, ${l}, null);`:`insert(${o}, ${l});`)}return s.push(`return ${o};`),`(() => { ${s.join(" ")} })()`}}}function oe(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(r=>[r.id,JSON.stringify(r.html)]));return e.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var D={name:"imperative",contract:ge,emit(e,t){let n=new Set,r=t?.templateClone!==!1?[]:void 0;return He=t?.partialTemplates===!0,{code:H(e,n,r),imports:Array.from(n),templates:r}}};var qt=e=>"components"in e;function Ve(e,t){return e.replace(/\$(\d+)/g,(n,r)=>t[Number(r)]??n)}function Kt(e,t){return typeof t=="string"?{module:t,export:e}:t}function se(e=[]){let t=new Map,n=[],r=[];for(let a of e){if(!qt(a)){r.push(a);continue}for(let[i,l]of Object.entries(a.components)){let c=Kt(i,l),p=t.get(i);if(p&&p.module!==c.module){let f=n.find(d=>d.name===i);f?f.modules.push(c.module):n.push({name:i,modules:[p.module,c.module]});continue}t.set(i,c)}}let o=new Map;return{resolve:a=>{if(o.has(a))return o.get(a);let i=t.get(a);if(!i)for(let l of r){let c=a.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){i={module:Ve(l.module,c),export:l.export?Ve(l.export,c):a};break}}return o.set(a,i),i},names:()=>[...t.keys()],conflicts:()=>n}}var Ue=require("@fluixi/template-parser");function V(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let o=0;o<t.length;o++)/[^ \t]/.test(t[o])&&(n=o);let r="";for(let o=0;o<t.length;o++){let s=t[o].replace(/\t/g," ");o!==0&&(s=s.replace(/^ +/,"")),o!==t.length-1&&(s=s.replace(/ +$/,"")),s&&(o!==n&&(s+=" "),r+=s)}return r}var Xe=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Gt(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function ze(e){return e.charAt(0).toUpperCase()+e.slice(1)}var he=class{constructor(t,n){this.holes=t;this.used=n}hole(t){return this.holes[t]??{code:"undefined",reactive:!1}}emit(t){let{code:n,imports:r,templates:o}=D.emit(t,{});for(let s of r)this.used.add(s);return oe(n,o)}lowerRoot(t){let n=this.lowerChildren(t);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(t){let n=[];for(let r=0;r<t.length;r++){let o=t[r];if(o.kind==="Element"||o.kind==="Component"){let a=o.attributes.find(i=>i.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let i=r+1;i<t.length&&this.isBlankText(t[i])&&i++;let l=t[i],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(p=>p.kind==="ElseDirective");n.push(this.lowerIf(o,a.hole,c?l:null)),c&&(r=i);continue}if(o.attributes.some(i=>i.kind==="EachDirective")){n.push(this.lowerEach(o));continue}}let s=this.lowerNode(o);s&&n.push(s)}return n}isBlankText(t){return t.kind==="Text"&&!t.raw&&V(t.value)===""}lowerNode(t){switch(t.kind){case"Text":{if(t.raw)return{kind:"text",value:t.value};let n=V(t.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(t.hole);return{kind:"expr",code:n.code,reactive:n.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(t.children)};case"Element":return this.lowerElement(t);case"Component":return this.lowerComponent(t);default:return null}}lowerElement(t){let n=t.attributes.find(r=>r.kind==="Attribute"&&r.name==="is");if(t.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=t.attributes.filter(s=>s!==n),o=this.lowerComponent({...t,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return o.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),o}return{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:this.lowerAttributes(t.attributes),children:this.lowerChildren(t.children),static:!1}}lowerComponent(t){let n=t.tagHole!=null?this.hole(t.tagHole).code:t.tag,r=this.lowerAttributes(t.attributes),{slots:o,rest:s}=this.partitionSlots(t.children);for(let[l,c]of o){let p=c.length===1?c[0]:{kind:"fragment",children:c},f={name:l,kind:"attr",expr:this.emit(p),jsxElement:!0},d=r.findIndex(g=>g.name===l);d>=0?r[d]=f:r.push(f)}let a=t.attributes.find(l=>l.kind==="LoadDirective"),i=a?Y(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:r,children:this.lowerChildren(s),...i?{load:i}:{}}}partitionSlots(t){let n=new Map,r=[];for(let o of t){if(o.kind==="Element"||o.kind==="Component"){let s=o.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(s&&s.value&&s.value.kind==="static"){let a={...o,attributes:o.attributes.filter(c=>c!==s)},i=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),l=n.get(s.value.value)??[];l.push(i),n.set(s.value.value,l);continue}}r.push(o)}return{slots:n,rest:r}}lowerIf(t,n,r){let o=this.hole(n),s=[{name:"when",kind:"attr",expr:o.code,reactive:o.reactive}];if(r){let i=this.stripAndLower(r,l=>l.kind==="ElseDirective");s.push({name:"fallback",kind:"attr",expr:this.emit(i),jsxElement:!0})}let a=this.stripAndLower(t,i=>i.kind==="IfDirective");return{kind:"component",name:"Show",props:s,children:[a]}}lowerEach(t){let n=t.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(t);let r=this.hole(n.hole),o=[{name:"each",kind:"attr",expr:r.code,reactive:r.reactive}];if(n.key){let l="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;o.push({name:"by",kind:"attr",expr:l})}let s=this.itemArrow(t),a;if(s){let l={kind:"expr",code:s.body,reactive:s.bodyReactive},c=this.rebuildWithChildren(t,[l]);a=`(${s.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(t,c=>c.kind==="EachDirective");a=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:o,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(t){let n=t.children.filter(r=>!this.isBlankText(r));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(t,n){let r={...t,attributes:t.attributes.filter(o=>!n(o))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(t,n){let r=this.lowerAttributes(t.attributes.filter(o=>o.kind!=="EachDirective"));return t.kind==="Element"?{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:r,children:n,static:!1}:{kind:"component",name:t.tag,props:r,children:n}}lowerAttributes(t){let n=[],r=[],o=!1,s=[],a=!1,i=[];for(let l of t)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);r.push(`${JSON.stringify(l.name)}: ${c.code}`),o=o||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);s.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;i.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:o}),s.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${s.join(", ")} }`,reactive:a}),i.length>0&&n.push({name:"use",kind:"attr",expr:`[${i.join(", ")}]`}),n}eventProp(t){let n=t.name.toLowerCase(),r=this.hole(t.hole).code;if(!(t.syntax==="colon"||t.modifiers.length>0))return{name:"on"+ze(t.name),kind:"event",event:{name:n,delegated:Xe.has(n)},expr:r};let s=this.wrapHandler(r,t.modifiers),a=this.eventOptions(t.modifiers),i=a?`[${s}, ${a}]`:s;return{name:"on:"+n,kind:"attr",expr:i}}wrapHandler(t,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",o=[];return n.includes("prevent")&&o.push("e.preventDefault();"),n.includes("stop")&&o.push("e.stopPropagation();"),!r&&o.length===0?t:`(e) => { ${r}${o.join(" ")} return (${t})(e); }`}eventOptions(t){let n=[];return t.includes("capture")&&n.push("capture: true"),t.includes("once")&&n.push("once: true"),t.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(t,n){let r=t==="checked",o=r?"change":"input",s=r?"checked":"value";this.used.add("bindPair");let a=`bindPair(${n})`;return[{name:t,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+ze(o),kind:"event",event:{name:o,delegated:Xe.has(o)},expr:`(e) => ${a}[1](e.target.${s})`}]}plainAttr(t){let n=t.value,r=t.name;t.name==="class"?r=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":t.name==="html"&&(r="innerHTML");let s={name:r,kind:"attr"};if(n==null)return s.literal=!0,s;if(n.kind==="static")return s.literal=n.value,s;if(n.kind==="hole"){let l=this.hole(n.hole);return s.expr=l.code,s.reactive=l.reactive,s}let a=!1,i=n.parts.map(l=>{if("text"in l)return Gt(l.text);let c=this.hole(l.hole);return a=a||c.reactive,"${"+c.code+"}"}).join("");return s.expr="`"+i+"`",s.reactive=a,s}};function We(e,t,n,r={}){let{root:o}=(0,Ue.parseTemplate)(e,{svg:r.svg});return new he(t,n).lowerRoot(o.children)}function qe(e,t,n={}){let r=new Set,o=We(e,[...t],r,{svg:n.svg});M(o),Q(o,{resolver:se(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:l=>l.load}),te(o);let{code:s,imports:a,templates:i}=D.emit(o,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let l of a)r.add(l);return n.hoistTemplates?{code:s,imports:[...r],ir:o,templates:i}:{code:oe(s,i),imports:[...r],ir:o}}var Zt="children";function A(e){switch(e.kind){case"call":return!0;case"member":return e.property!==Zt;case"compound":return e.parts.some(A);case"opaque":return!1}}var Yt=new Set(["CallExpression","OptionalCallExpression"]),Qt=new Set(["MemberExpression","OptionalMemberExpression"]);function w(e){if(!e)return{kind:"opaque"};if(Yt.has(e.type))return{kind:"call"};if(Qt.has(e.type)){let t=e.property;return{kind:"member",property:!(e.computed===!0)&&t?.type==="Identifier"?t.name:null}}return e.type==="ConditionalExpression"?{kind:"compound",parts:[e.test,e.consequent,e.alternate].map(X)}:e.type==="LogicalExpression"||e.type==="BinaryExpression"?{kind:"compound",parts:[e.left,e.right].map(X)}:e.type==="TemplateLiteral"?{kind:"compound",parts:e.expressions.map(X)}:e.type==="ObjectExpression"?{kind:"compound",parts:e.properties.filter(n=>(n.type==="ObjectProperty"||n.type==="Property")&&n.computed!==!0).map(n=>X(n.value))}:e.type==="ArrayExpression"?{kind:"compound",parts:e.elements.filter(n=>n!=null&&n.type!=="SpreadElement").map(X)}:{kind:"opaque"}}var X=e=>w(e);var en=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),tn=/^on[A-Z]/,nn=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),Ze=e=>A(w(e));function z(e){if(e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral"||e.type==="Literal"&&(typeof e.value=="string"||typeof e.value=="number"||typeof e.value=="boolean"))return e.value}var ye=e=>!!e&&typeof z(e)=="string";function rn(e,t){return e.type==="JSXIdentifier"?{tag:e.name,component:e.name[0]!==e.name[0].toLowerCase()}:e.type==="JSXMemberExpression"?{tag:t.code(e),component:!0}:e.type==="JSXNamespacedName"?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function Ne(e){return e.type==="JSXIdentifier"?e.name==="class"?"className":e.name:e.type==="JSXNamespacedName"?`${e.namespace.name}:${e.name.name}`:"unknown"}function on(e,t){let n=Ne(e.name),r=tn.test(n),o=r||n.startsWith("on:")||n==="ref",a={name:n,kind:r?"event":"attr"};if(r){let l=n.slice(2).toLowerCase();a.event={name:l,delegated:nn.has(l)}}let i=e.value;if(i==null)return a.literal=!0,a;if(ye(i))return a.literal=z(i),a;if(i.type==="JSXExpressionContainer"&&i.expression?.type!=="JSXEmptyExpression"){let l=i.expression,c=z(l);return c!==void 0?(a.literal=c,a):(a.expr=t.code(l),a.reactive=o?!1:Ze(l),(l.type==="JSXElement"||l.type==="JSXFragment")&&(a.jsxElement=!0),a)}return a.literal=!0,a}function Ke(e,t){let n=e.value;return n==null?null:ye(n)?JSON.stringify(z(n)):n.type==="JSXExpressionContainer"&&n.expression?.type!=="JSXEmptyExpression"?t.code(n.expression):null}function sn(e,t){let n=[],r=[];for(let o of e){if(o.type==="JSXSpreadAttribute"){n.push({name:"",kind:"spread",expr:t.code(o.argument)});continue}if(o.type!=="JSXAttribute"||de(Ne(o.name)))continue;let s=o.name.type==="JSXNamespacedName"?o.name.namespace.name:null;if(s==="use"){let a=o.name.name.name;t.used.add(a);let i=Ke(o,t);r.push(i!=null?`[${a}, () => (${i})]`:`[${a}]`);continue}if(s==="oncapture"){let a=o.name.name.name.toLowerCase(),i=Ke(o,t)??"undefined";n.push({name:"on:"+a,kind:"attr",expr:`[${i}, { capture: true }]`});continue}n.push(on(o,t))}return r.length>0&&n.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),n}function Ge(e,t){let n=[];for(let r of e)if(r.type==="JSXText"){let o=V(r.value);o&&n.push({kind:"text",value:o})}else if(r.type==="JSXExpressionContainer"){if(r.expression?.type!=="JSXEmptyExpression"){let o=r.expression;n.push({kind:"expr",code:t.code(o),reactive:Ze(o)})}}else r.type==="JSXElement"||r.type==="JSXFragment"?n.push(Ye(r,t)):r.type==="JSXSpreadChild"&&n.push({kind:"expr",code:t.code(r.expression),reactive:!1});return n}function an(e){for(let t of e){if(t.type!=="JSXAttribute")continue;let n=Ne(t.name);if(de(n)){if(t.value&&!ye(t.value))throw new I(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return Y(n,t.value?z(t.value):null)}}}function Ye(e,t){if(e.type==="JSXFragment")return{kind:"fragment",children:Ge(e.children,t)};let{tag:n,component:r}=rn(e.openingElement.name,t),o=sn(e.openingElement.attributes,t),s=Ge(e.children,t);if(r){let a=an(e.openingElement.attributes);return{kind:"component",name:n,props:o,children:s,...a?{load:a}:{}}}return{kind:"element",tag:n,svg:en.has(n),props:o,children:s,static:!1}}function Qe(e,t){let n=Ye(e,t);return M(n),n}function C(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?C(n.argument,t):C(n.value,t);return;case"ArrayPattern":for(let n of e.elements)C(n,t);return;case"AssignmentPattern":C(e.left,t);return;case"RestElement":C(e.argument,t);return}}function et(e,t){switch(e.type){case"ImportDeclaration":for(let n of e.specifiers)C(n.local,t);return;case"VariableDeclaration":for(let n of e.declarations)C(n.id,t);return;case"FunctionDeclaration":case"ClassDeclaration":C(e.id,t);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&et(e.declaration,t);return}}function L(e){let t=new Set;for(let n of e.body)et(n,t);return t}var rt=require("@babel/parser"),ot=$e(require("magic-string"),1);function k(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?k(n.argument,t):k(n.value,t);return;case"ArrayPattern":for(let n of e.elements)k(n,t);return;case"AssignmentPattern":k(e.left,t);return;case"RestElement":k(e.argument,t);return}}function ve(e){switch(e.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"NullLiteral":case"BigIntLiteral":case"RegExpLiteral":case"Identifier":return!0;case"Literal":return!0;case"TemplateLiteral":return e.expressions.every(ve);case"UnaryExpression":return ve(e.argument);case"MemberExpression":return!1;default:return!1}}function ie(e,t){if(!(!e||typeof e!="object")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="range"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let o of r)o&&typeof o=="object"&&ie(o,t);else r&&typeof r=="object"&&typeof r.type=="string"&&ie(r,t)}}}function ln(e){let t=new Set;return ie(e,n=>{if(n.type==="AssignmentExpression")k(n.left,t);else if(n.type==="UpdateExpression"){let r=n.argument;r?.type==="Identifier"&&t.add(r.name)}}),t}function cn(e,t){let n=new Set,r=o=>{let s=new Set;k(o,s);for(let a of s)t.has(a)&&n.add(a)};return ie(e,o=>{switch(o.type){case"VariableDeclarator":r(o.id);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":r(o.id);for(let s of o.params??[])r(s);return;case"CatchClause":r(o.param);return;case"ClassDeclaration":case"ClassExpression":r(o.id);return}}),n}function tt(e,t,n){for(let r of e.properties??[]){if(r.type==="RestElement"){let p=r.argument;if(p?.type!=="Identifier"||t.length>0){let f=new Set;k(p,f);for(let d of f)n.bails.push({name:d,reason:"rest"});continue}n.rest={name:p.name,keys:[]};continue}if(r.computed){let p=new Set;k(r.value,p);for(let f of p)n.bails.push({name:f,reason:"computed"});continue}let o=r.key,s=o.type==="Identifier"?o.name:o.value,a=r.value,i;a.type==="AssignmentPattern"&&(i=a.right,a=a.left);let l=[...t,s];if(a.type==="Identifier"){if(i&&!ve(i)){n.bails.push({name:a.name,reason:"unsafe-default"});continue}n.reads.push({name:a.name,path:l,...i?{fallback:i}:{}});continue}if(a.type==="ObjectPattern"){if(i){let p=new Set;k(a,p);for(let f of p)n.bails.push({name:f,reason:"unsafe-default"});continue}tt(a,l,n);continue}let c=new Set;k(a,c);for(let p of c)n.bails.push({name:p,reason:"computed"})}}function ae(e,t){let n={reads:[],bails:[]};if(e?.type!=="ObjectPattern"||(tt(e,[],n),n.rest&&(t?.type!=="BlockStatement"?(n.bails.push({name:n.rest.name,reason:"rest"}),delete n.rest):n.rest.keys=(e.properties??[]).filter(i=>i.type!=="RestElement"&&!i.computed).map(i=>{let l=i.key;return l.type==="Identifier"?l.name:l.value})),n.reads.length===0&&!n.rest))return n;let r=new Set(n.reads.map(i=>i.name));n.rest&&r.add(n.rest.name);let o=ln(t),s=cn(t,r),a=[];for(let i of n.reads)o.has(i.name)?n.bails.push({name:i.name,reason:"reassigned"}):s.has(i.name)?n.bails.push({name:i.name,reason:"shadowed"}):a.push(i);return n.reads=a,n.rest&&o.has(n.rest.name)?(n.bails.push({name:n.rest.name,reason:"reassigned"}),delete n.rest):n.rest&&s.has(n.rest.name)&&(n.bails.push({name:n.rest.name,reason:"shadowed"}),delete n.rest),n}function le(e){switch(e){case"rest":return"this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";case"computed":return"the property is not known until it runs";case"reassigned":return"the binding is assigned to, and props are read-only";case"shadowed":return"an inner scope binds the same name";case"unsafe-default":return"the default would have to run again on every read"}}function U(e,t,n=null){if(!(!e||typeof e!="object"||typeof e.type!="string")&&!e.type.startsWith("TS")&&t(e,n)!==!1)for(let r of Object.keys(e)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let o=e[r];if(Array.isArray(o))for(let s of o)U(s,t,e);else o&&typeof o=="object"&&U(o,t,e)}}function nt(e){return!!e&&e[0]>="A"&&e[0]<="Z"}function pn(e){let t=[];return U(e,n=>{if(n.type==="FunctionDeclaration"&&nt(n.id?.name)){t.push(n);return}if(n.type==="VariableDeclarator"&&nt(n.id?.name)){let r=n.init;r&&(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")&&t.push(r)}}),t}function dn(e){let t=new Set;return U(e,n=>{n.type==="Identifier"&&t.add(n.name)}),t}function un(e,t){if(!t)return!0;switch(t.type){case"MemberExpression":case"OptionalMemberExpression":return!(t.property===e&&!t.computed);case"ObjectProperty":case"ObjectMethod":case"ClassProperty":case"ClassMethod":return!(t.key===e&&!t.computed);case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return t.label!==e;case"ImportSpecifier":case"ExportSpecifier":return!1;default:return!0}}function xe(e,t,n={}){let r=[],o=[],s=new Set;for(let a of pn(e)){let i=a.params?.[0];if(i?.type!=="ObjectPattern")continue;let l=ae(i,a.body);for(let m of l.bails)o.push({name:m.name,reason:m.reason,message:le(m.reason),start:i.start});if(l.bails.length>0||l.reads.length===0&&!l.rest)continue;let c=dn(a),p=n.parameterName??"props";for(;c.has(p);)p=`_${p}`;let f=new Map;for(let m of l.reads){let h=`${p}.${m.path.join(".")}`,v=m.fallback;f.set(m.name,v?`(${h} === undefined ? ${t.slice(v.start,v.end)} : ${h})`:h)}let d=i.typeAnnotation;if(r.push({start:i.start,end:d?.start??i.end,code:p}),l.rest){let m=l.rest.keys.map(v=>JSON.stringify(v)).join(", "),h=a.body;r.push({start:h.start+1,end:h.start+1,code:`
|
|
2
|
-
const [, ${l.rest.name}] = splitProps(${
|
|
3
|
-
`),{code:
|
|
1
|
+
"use strict";var At=Object.create;var re=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames;var jt=Object.getPrototypeOf,Jt=Object.prototype.hasOwnProperty;var _t=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},Je=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Lt(t))!Jt.call(e,o)&&o!==n&&re(e,o,{get:()=>t[o],enumerable:!(r=Dt(t,o))||r.enumerable});return e};var _e=(e,t,n)=>(n=e!=null?At(jt(e)):{},Je(t||!e||!e.__esModule?re(n,"default",{value:e,enumerable:!0}):n,e)),Ft=e=>Je(re({},"__esModule",{value:!0}),e);var nr={};_t(nr,{explainBail:()=>ye,moduleBindings:()=>H,planPropsDestructure:()=>he,shapeOf:()=>M,transformProps:()=>Et,transformTemplates:()=>Mt});module.exports=Ft(nr);var $t=require("@babel/parser"),Ct=_e(require("magic-string"),1);function Bt(e){switch(e.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 e.reactive?"reactive-prop":e.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function J(e){let t=[],n=new Map,r=o=>{switch(o.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let i of o.children)r(i);return!1;case"fragment":for(let i of o.children)r(i);return!1;case"element":{let i=!0;for(let s of o.children)r(s)||(i=!1);let a;for(let s of o.props)if(a=Bt(s),a)break;return!a&&!i&&(a=Ht(o)),o.static=!a,a?n.set(o,a):t.push(o),o.static}default:return!1}};for(let o of Array.isArray(e)?e:[e])r(o);return{staticElements:t,reasons:n}}function Ht(e){for(let t of e.children){if(t.kind==="expr")return"expression-child";if(t.kind==="component")return"component-child";if(t.kind==="control")return"control-child";if(t.kind==="element"&&!t.static||t.kind==="fragment")return"expression-child"}return"expression-child"}var oe={kind:"eager"},Vt=["pointerdown","focusin","keydown"],Fe=new Set(["eager","idle","visible","interaction","media","never"]),P=class extends Error{};function xe(e){return e.startsWith("load:")}function ie(e,t){let n=e.slice(5);if(!Fe.has(n))throw new P(`Unknown load strategy 'load:${n}'. Expected one of ${[...Fe].join(", ")}.`);switch(n){case"eager":return oe;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return t?{kind:"visible",rootMargin:t}:{kind:"visible"};case"interaction":return{kind:"interaction",events:t?Ut(t):[...Vt]};case"media":if(!t)throw new P(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new P(`Unhandled load strategy '${n}'.`)}}function Ut(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new P("'load:interaction' was given no event names.");return t}function V(e){return e.kind!=="eager"&&e.kind!=="never"}var U=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],X=["Suspense","SuspenseList","Await"],_=["Router","Outlet","Redirect","Link"],sr=[...U,...X,..._],Re=new Set([...U,...X]);function Be(e={}){let{controlFlowModule:t="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:r="@fluixi/core/router"}=e,o={};for(let i of U)o[i]=t;for(let i of X)o[i]=n;for(let i of _)o[i]=r;return o}function se(e,t={}){let{resolver:n,isBound:r,modules:o,strategyFor:i}=t,a=Be(o),s=new Map,l=new Set,p=d=>{let{name:u}=d;if(!u||u.includes(".")||r?.(u))return;let g=c(u);if(!g){l.add(u);return}let m=g.origin==="builtin"&&Re.has(u)?oe:i?.(d)??oe;d.source={...g,loading:m},s.set(u,d.source)},c=d=>{if(Re.has(d))return{module:a[d],export:d,origin:"builtin"};let u=n?.resolve(d);if(u)return{module:u.module,export:u.export,origin:"rule"};if(_.includes(d))return{module:a[d],export:d,origin:"builtin"}};return ae(e,d=>{d.kind==="component"&&p(d)}),{resolved:s,unresolved:[...l]}}function ae(e,t){let n=Array.isArray(e)?e:[e];for(let r of n){t(r);let o=r.children;o&&ae(o,t)}}function le(e){let t=[];ae(e,i=>{i.kind==="component"&&i.source&&t.push(i)});let n=new Set,r=new Set;for(let i of t){let{module:a,loading:s}=i.source;s.kind==="eager"&&n.add(a),s.kind==="never"&&r.add(a)}let o=new Map;for(let i of t){let a=i.source;V(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},o.set(a.module,(o.get(a.module)??0)+1))}return{collapsed:o,conflicted:[...r].filter(i=>n.has(i))}}var Xt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),He={className:"class",htmlFor:"for"},zt=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Wt=new Set(["script","style","textarea","title"]);function be(e){return Wt.has(e)}function Ve(e){return He[e]??e}function z(e){return e.kind!=="attr"||e.expr!==void 0||e.name.includes(":")?!1:!zt.has(e.name)}function Se(e){if(!e.static||be(e.tag))return!1;for(let t of e.props)if(!z(t))return!1;for(let t of e.children)if(t.kind!=="text"&&!(t.kind==="element"&&Se(t)))return!1;return!0}function W(e){let t=e.props.map(qt).filter(Boolean).join(""),n=`<${e.tag}${t}>`;return Xt.has(e.tag)?n:`${n}${e.children.map(Kt).join("")}</${e.tag}>`}function Kt(e){if(e.kind==="text")return Zt(e.value);if(e.kind!=="element")throw new Error(`serializeStatic: unexpected ${e.kind}`);return W(e)}function qt(e){let t=He[e.name]??e.name,n=e.literal;return n===!0||n===void 0?` ${t}`:n===!1||n===null?"":` ${t}="${Gt(String(n))}"`}function Gt(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Zt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function ke(e){let t=[],n,r=o=>{n??=o.at?.file,t.push(o.at?.line??0,o.at?.column??0);for(let i of o.children)i.kind==="element"&&r(i)};return r(e),n&&t.some(o=>o!==0)?{file:n,pos:t}:void 0}var Yt="<!--fx-->",Qt="<!--fx/-->";function ue(e){return e.kind==="expr"||e.kind==="component"||e.kind==="control"}function en(e){return e.kind==="text"||e.kind==="element"&&Ue(e)}function Ue(e){return e.svg||be(e.tag)||!e.props.every(t=>z(t))?!1:e.children.every(t=>en(t)||ue(t))}function ce(e){if(ue(e))return!0;let t=e.children;return t?t.some(ce):!1}function Xe(e){for(let t=0;t<e.children.length;t++){let n=e.children[t];if(n.kind==="text"&&(n.value===""||e.children[t+1]?.kind==="text"))return!1}return e.children.every(t=>t.kind!=="element"||Xe(t))}function ze(e){if(!Ue(e)||!Xe(e)||!e.children.some(ce))return null;let t=[],n=[],r=0,o=a=>{let s=`_n$${r++}`;return t.push({ref:s,expr:a}),s};return i(e,"_el$"),{html:tn(e),tag:e.tag,steps:t,holes:n};function i(a,s){let l=-1;a.children.forEach((c,d)=>{ce(c)&&(l=d)});let p=null;for(let c=0;c<=l;c++){let d=a.children[c],u=p?`${p}.nextSibling`:`${s}.firstChild`;if(ue(d)){let m=o(u),y=o(`holeEnd(${m})`);n.push({parentRef:s,startRef:m,endRef:y,node:d}),p=y;continue}let g=o(u);d.kind==="element"&&ce(d)&&i(d,g),p=g}}}function tn(e){return W(We(e)).split(Ke).join(Yt+Qt)}function We(e){return{...e,children:e.children.map(t=>ue(t)?{kind:"text",value:Ke}:t.kind==="element"?We(t):t)}}var Ke="\0fx-hole\0";var Ee={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},yr={version:2,module:"@fluixi/dom",symbols:[...Ee.symbols,"template","cloneTemplate","walk"]};var L="@fluixi/reactive/signal",w={$signal:{export:"signal",module:L,returns:"signal-handle"},$memo:{export:"memo",module:L,returns:"memo-handle"},$effect:{export:"effect",module:L,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:L,returns:"resource-handle"},$selector:{export:"createSelector",module:L,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:L,returns:"memo-accessor"},$untrack:{export:"untrack",module:L,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}},qe={signal:"signal-handle",memo:"memo-handle",effect:"effect",store:"store-handle",createSignal:["signal-accessor","signal-setter"],createMemo:"memo-accessor",createEffect:"effect",createRenderEffect:"effect",createStore:"reactive-object",resource:"resource-handle",createResource:"reactive-object",createSelector:"memo-accessor",createDeferred:"memo-accessor"},nn=["@fluixi/reactive","@fluixi/reactive/signal","@fluixi/reactive/store","@fluixi/core"],rn=new RegExp(`\\$(?:${Object.keys(w).map(e=>e.slice(1)).join("|")})\\s*\\(`);function Ge(e){return rn.test(e)}function pe(e){return Object.prototype.hasOwnProperty.call(w,e)}function Ze(e){return nn.includes(e)}function v(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties??[])n.type==="RestElement"?v(n.argument,t):v(n.value,t);return;case"ArrayPattern":for(let n of e.elements??[])v(n,t);return;case"AssignmentPattern":v(e.left,t);return;case"RestElement":v(e.argument,t);return}}function K(e,t){if(!(!e||typeof e!="object"||typeof e.type!="string")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let o of r)K(o,t);else r&&typeof r=="object"&&K(r,t)}}}function on(e,t){if(e.type!=="CallExpression")return;let n=e.callee;if(n?.type!=="Identifier")return;let r=n.name,o=t.primitives.get(r);if(o)return o;let i=w[r];if(i&&!t.shadowed.has(r))return i.returns}function sn(e,t,n){if(Array.isArray(t)){e.type==="ArrayPattern"&&e.elements.forEach((r,o)=>{let i=t[o];r?.type==="Identifier"&&i&&n.set(r.name,i)});return}e.type==="Identifier"&&n.set(e.name,t)}function Ye(e){let t=new Set;return K(e,n=>{switch(n.type){case"VariableDeclarator":v(n.id,t);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":v(n.id,t);for(let r of n.params??[])v(r,t);return;case"ClassDeclaration":case"ClassExpression":v(n.id,t);return;case"ImportSpecifier":case"ImportDefaultSpecifier":case"ImportNamespaceSpecifier":v(n.local,t);return;case"CatchClause":v(n.param,t);return}}),t}function de(e){let t={kinds:new Map,primitives:new Map,shadowed:new Set},n=e;K(n,r=>{let o=new Set;if(r.type==="VariableDeclarator")v(r.id,o);else if(r.type==="FunctionDeclaration"||r.type==="ClassDeclaration")v(r.id,o);else if(r.type==="ImportDefaultSpecifier"||r.type==="ImportNamespaceSpecifier")v(r.local,o);else if(r.type==="ImportSpecifier")v(r.local,o);else if(r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression"||r.type==="FunctionDeclaration")for(let i of r.params??[])v(i,o);for(let i of o)w[i]&&t.shadowed.add(i)});for(let r of n.body??[])if(r.type==="ImportDeclaration"&&Ze(r.source?.value))for(let o of r.specifiers??[]){if(o.type!=="ImportSpecifier")continue;let i=o.imported,a=i.type==="Identifier"?i.name:i.value,s=qe[a];s&&t.primitives.set(o.local.name,s)}return K(n,r=>{if(r.type!=="VariableDeclarator"||!r.init)return;let o=on(r.init,t);o&&sn(r.id,o,t.kinds)}),t}var we="__fx_source",an="__fx_component",ln="__fx_hole",q=(e,t,n,r)=>`(globalThis.${ln} ?? ((f) => f))(${e},${t},${n}${r===void 0?"":`,${JSON.stringify(r)}`})`,cn="__fx_props",et=(e,t)=>`(globalThis.${cn} ?? ((p) => p))(${e},${JSON.stringify(t)})`,tt=new Set(["signal","memo","effect","store","resource","watch","createSignal","createMemo","createEffect","createStore","createResource"]);function nt(e){for(let t of tt)if(e.includes(t))return!0;return e.includes("$signal")||e.includes("$memo")||e.includes("$effect")||e.includes("$store")}var un=new Set(["IfStatement","ForStatement","ForInStatement","ForOfStatement","WhileStatement","DoWhileStatement","LabeledStatement","WithStatement"]);function pn(e,t){return!t||e.type==="BlockStatement"?!1:un.has(t.type)}function Qe(e){return e.type==="ExportNamedDeclaration"||e.type==="ExportDefaultDeclaration"}function dn(e){return e.type.endsWith("Statement")||e.type==="VariableDeclaration"}function Ie(e,t,n=[]){if(!(!e||typeof e.type!="string")){t(e,n),n.push(e);for(let r of Object.keys(e)){if(r==="loc"||r==="parent")continue;let o=e[r];if(Array.isArray(o))for(let i of o)Ie(i,t,n);else o&&typeof o.type=="string"&&Ie(o,t,n)}n.pop()}}function fn(e){let t=e[e.length-1];if(t?.type!=="VariableDeclarator")return;let n=t.id;if(n?.type==="Identifier")return n.name;if(n?.type==="ArrayPattern"){let r=n.elements?.[0];if(r?.type==="Identifier")return r.name}}function mn(e){if(e.type==="FunctionDeclaration"){let t=e.id?.name;return t&&t[0]===t[0]?.toUpperCase()?t:void 0}if(e.type==="VariableDeclarator"){let t=e.id,n=e.init;if(t?.type!=="Identifier"||!n||n.type!=="ArrowFunctionExpression"&&n.type!=="FunctionExpression")return;let r=t.name;return r[0]===r[0]?.toUpperCase()?r:void 0}}function rt(e,t){let n=[],r=new Set,{primitives:o,shadowed:i}=de(e);return Ie(e,(a,s)=>{let l=mn(a);if(l){let h=a.loc?.start,C=a.end;for(let j=s.length-1;j>=0;j--){let D=s[j];if(D.type!=="VariableDeclaration"&&D.type!=="ExportNamedDeclaration"&&D.type!=="ExportDefaultDeclaration")break;C=D.end}h&&n.push({start:C,end:C,code:`;globalThis.${an}?.(${JSON.stringify(l)},${JSON.stringify(t)},${h.line},${h.column});`})}if(a.type!=="CallExpression")return;let p=a.callee;if(p?.type!=="Identifier")return;let c=p.name,d=pe(c)&&!i.has(c)?w[c]:void 0,u=o.has(c)||tt.has(c);if(!d&&!u)return;let g=a.loc?.start;if(!g)return;let m,y,b=-1;for(let h=s.length-1;h>=0;h--)if(dn(s[h])||Qe(s[h])){m=s[h],y=s[h-1],b=h;break}if(!m)return;let R=m.start,N=m.end;for(let h=b-1;h>=0&&Qe(s[h]);h--)R=s[h].start,N=s[h].end,y=s[h-1];if(r.has(R))return;r.add(R);let $=fn(s),A=[JSON.stringify(t),String(g.line),String(g.column),$?JSON.stringify($):void 0].filter(h=>h!==void 0).join(","),I=`globalThis.${we}?.(${A});`;if(pn(m,y)){n.push({start:R,end:R,code:`{${I}`}),n.push({start:N,end:N,code:"}"});return}n.push({start:R,end:R,code:I})}),{edits:n,marked:n.length}}var gn={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function hn(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function st(e){return hn(e)?e:JSON.stringify(e)}function yn(e){if(e.expr!==void 0){if(e.name==="ref"&&e.at)return q(`(${e.expr})`,e.at.line,e.at.column,e.expr);if(!e.reactive)return`(${e.expr})`;let t=`() => (${e.expr})`;return e.at?q(t,e.at.line,e.at.column,e.directive):t}return JSON.stringify(e.literal??!0)}function Nn(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function vn(e,t,n){let r=e.filter(s=>s.kind==="spread"),i=e.filter(s=>s.kind!=="spread").map(s=>`${st(s.name)}: ${yn(s)}`);t!=null&&i.push(`children: ${t}`);let a=`{ ${i.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(s=>s.expr).join(", ")}, ${a})`):a}function ot(e,t){return t?q(e,t.line,t.column):e}function at(e,t,n){return e.length===1?G(e[0],t,n):`[${e.map(r=>G(r,t,n)).join(", ")}]`}function it(e,t,n,r,o,i){r.add("createMemo"),r.add("createComponent");let a=t.filter(u=>u.kind==="spread"),s=t.filter(u=>u.kind!=="spread"),l=s.map(u=>`get ${st(u.name)}() { return ${Nn(u)}; }`);n.length>0&&l.push(`get children() { return ${at(n,r,o)}; }`);let p=`{ ${l.join(", ")} }`;a.length>0&&(r.add("mergeProps"),p=`mergeProps(${a.map(u=>u.expr).join(", ")}, ${p})`);let c={};for(let u of s)u.at&&(c[u.name]=[u.at.line,u.at.column]);return Object.keys(c).length&&(p=et(p,c)),`createMemo((${i?`globalThis.${we}?.(${JSON.stringify(i.file)},${i.line},${i.column},${JSON.stringify(e)}), `:""}() => createComponent(${e}, ${p})))`}function xn(e,t){let n=Ve(t.name),r=t.literal;return r===!0||r===void 0?`${e}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${e}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var lt=!1;function G(e,t,n){switch(e.kind){case"text":return JSON.stringify(e.value);case"expr":{if(!e.reactive)return`(${e.code})`;let r=`() => (${e.code})`;return e.at?q(r,e.at.line,e.at.column):r}case"fragment":return e.children.length===0?"null":at(e.children,t,n);case"component":return ot(it(e.name,e.props,e.children,t,n,e.at),e.bindAt??e.at);case"control":{let r=gn[e.control]??e.control;return t.add(r),ot(it(r,e.props,e.children,t,n),e.bindAt)}case"element":{if(n&&e.static&&!e.svg&&Se(e)){t.add("templateNode");let s=`_tmpl$${n.length}`;n.push({id:s,html:W(e),tag:e.tag,svg:!1});let l=ke(e);return l?`templateNode(${s}, ${JSON.stringify(e.tag)}, false, false, ${JSON.stringify(l)})`:`templateNode(${s}, ${JSON.stringify(e.tag)})`}if(n&<){let s=ze(e);if(s){t.add("templateNode"),t.add("insert"),t.add("holeEnd"),t.add("holeContent"),t.add("holeScope");let l=`_tmpl$${n.length}`;n.push({id:l,html:s.html,tag:s.tag,svg:!1});let p=ke(e),c=[`const _el$ = templateNode(${l}, ${JSON.stringify(s.tag)}, true${p?`, false, ${JSON.stringify(p)}`:""});`];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}, () => (${G(d.node,t,n)})), ${d.endRef}, holeContent(${d.startRef}, ${d.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}t.add("createNativeElement");let r=JSON.stringify(e.tag),o="_el$",i=[],a=e.at?`${r}, ${e.svg}, ${JSON.stringify(e.at)}`:e.svg?`${r}, true`:r;if(i.push(`const ${o} = createNativeElement(${a});`),e.props.length>0)if(!e.svg&&e.props.every(z))for(let s of e.props)i.push(xn(o,s));else{t.add("spread");let s=e.svg?", isSVG: true":"";i.push(`spread({ element: ${o}, props: ${vn(e.props,null,t)}${s} });`)}for(let s of e.children){t.add("insert");let l=G(s,t,n),p=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";i.push(p?`insert(${o}, ${l}, null);`:`insert(${o}, ${l});`)}return i.push(`return ${o};`),`(() => { ${i.join(" ")} })()`}}}function fe(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(r=>[r.id,JSON.stringify(r.html)]));return e.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var F={name:"imperative",contract:Ee,emit(e,t){let n=new Set,r=t?.templateClone!==!1?[]:void 0;return lt=t?.partialTemplates===!0,{code:G(e,n,r),imports:Array.from(n),templates:r}}};var Rn=e=>"components"in e;function ct(e,t){return e.replace(/\$(\d+)/g,(n,r)=>t[Number(r)]??n)}function bn(e,t){return typeof t=="string"?{module:t,export:e}:t}function me(e=[]){let t=new Map,n=[],r=[];for(let a of e){if(!Rn(a)){r.push(a);continue}for(let[s,l]of Object.entries(a.components)){let p=bn(s,l),c=t.get(s);if(c&&c.module!==p.module){let d=n.find(u=>u.name===s);d?d.modules.push(p.module):n.push({name:s,modules:[c.module,p.module]});continue}t.set(s,p)}}let o=new Map;return{resolve:a=>{if(o.has(a))return o.get(a);let s=t.get(a);if(!s)for(let l of r){let p=a.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(p){s={module:ct(l.module,p),export:l.export?ct(l.export,p):a};break}}return o.set(a,s),s},names:()=>[...t.keys()],conflicts:()=>n}}var dt=require("@fluixi/template-parser");function Z(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let o=0;o<t.length;o++)/[^ \t]/.test(t[o])&&(n=o);let r="";for(let o=0;o<t.length;o++){let i=t[o].replace(/\t/g," ");o!==0&&(i=i.replace(/^ +/,"")),o!==t.length-1&&(i=i.replace(/ +$/,"")),i&&(o!==n&&(i+=" "),r+=i)}return r}var ut=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Sn(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function pt(e){return e.charAt(0).toUpperCase()+e.slice(1)}var $e=class{constructor(t,n,r,o){this.holes=t;this.used=n;this.sourceFile=r;this.positionAt=o}tagAt(t){let n=t.loc?.start;if(!this.sourceFile||!this.positionAt||n==null)return;let{line:r,column:o}=this.positionAt(n);return{file:this.sourceFile,line:r,column:o}}hole(t){return this.holes[t]??{code:"undefined",reactive:!1}}emit(t){let{code:n,imports:r,templates:o}=F.emit(t,{});for(let i of r)this.used.add(i);return fe(n,o)}lowerRoot(t){let n=this.lowerChildren(t);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(t){let n=[];for(let r=0;r<t.length;r++){let o=t[r];if(o.kind==="Element"||o.kind==="Component"){let a=o.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=r+1;s<t.length&&this.isBlankText(t[s])&&s++;let l=t[s],p=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(c=>c.kind==="ElseDirective");n.push(this.lowerIf(o,a.hole,p?l:null)),p&&(r=s);continue}if(o.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(o));continue}}let i=this.lowerNode(o);i&&n.push(i)}return n}isBlankText(t){return t.kind==="Text"&&!t.raw&&Z(t.value)===""}lowerNode(t){switch(t.kind){case"Text":{if(t.raw)return{kind:"text",value:t.value};let n=Z(t.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(t.hole);return{kind:"expr",code:n.code,reactive:n.reactive,...n.at?{at:n.at}:{}}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(t.children)};case"Element":return this.lowerElement(t);case"Component":return this.lowerComponent(t);default:return null}}lowerElement(t){let n=t.attributes.find(o=>o.kind==="Attribute"&&o.name==="is");if(t.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let o=t.attributes.filter(a=>a!==n),i=this.lowerComponent({...t,kind:"Component",tag:"Dynamic",tagHole:null,attributes:o});return i.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),i}let r=this.tagAt(t);return{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:this.lowerAttributes(t.attributes),children:this.lowerChildren(t.children),static:!1,...r?{at:r}:{}}}lowerComponent(t){let n=t.tagHole!=null?this.hole(t.tagHole).code:t.tag,r=this.lowerAttributes(t.attributes),{slots:o,rest:i}=this.partitionSlots(t.children);for(let[c,d]of o){let u=d.length===1?d[0]:{kind:"fragment",children:d},g={name:c,kind:"attr",expr:this.emit(u),jsxElement:!0},m=r.findIndex(y=>y.name===c);m>=0?r[m]=g:r.push(g)}let a=t.attributes.find(c=>c.kind==="LoadDirective"),s=a?ie(`load:${a.strategy}`,a.modifier):void 0,l=r.find(c=>c.at&&c.reactive)?.at,p=this.tagAt(t);return{kind:"component",name:n,props:r,children:this.lowerChildren(i),...p?{at:p}:{},...l?{bindAt:l}:{},...s?{load:s}:{}}}partitionSlots(t){let n=new Map,r=[];for(let o of t){if(o.kind==="Element"||o.kind==="Component"){let i=o.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(i&&i.value&&i.value.kind==="static"){let a={...o,attributes:o.attributes.filter(p=>p!==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}}r.push(o)}return{slots:n,rest:r}}lowerIf(t,n,r){let o=this.hole(n),i=[{name:"when",kind:"attr",expr:o.code,reactive:o.reactive,...o.at?{at:o.at}:{}}];if(r){let l=this.stripAndLower(r,p=>p.kind==="ElseDirective");i.push({name:"fallback",kind:"attr",expr:this.emit(l),jsxElement:!0})}let a=this.stripAndLower(t,l=>l.kind==="IfDirective"),s=this.tagAt(t);return{kind:"component",name:"Show",props:i,children:[a],...s?{at:s}:{},...o.at?{bindAt:o.at}:{}}}lowerEach(t){let n=t.attributes.find(p=>p.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(t);let r=this.hole(n.hole),o=[{name:"each",kind:"attr",expr:r.code,reactive:r.reactive,...r.at?{at:r.at}:{}}];if(n.key){let p="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;o.push({name:"by",kind:"attr",expr:p})}let i=this.itemArrow(t),a;if(i){let p={kind:"expr",code:i.body,reactive:i.bodyReactive},c=this.rebuildWithChildren(t,[p]);a=`(${i.params.join(", ")}) => (${this.emit(c)})`}else{let p=this.stripAndLower(t,c=>c.kind==="EachDirective");a=`() => (${this.emit(p)})`}let s=[{kind:"expr",code:a,reactive:!1}],l=this.tagAt(t);return{kind:"component",name:"For",props:o,children:s,...l?{at:l}:{},...r.at?{bindAt:r.at}:{}}}itemArrow(t){let n=t.children.filter(r=>!this.isBlankText(r));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(t,n){let r={...t,attributes:t.attributes.filter(o=>!n(o))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(t,n){let r=this.lowerAttributes(t.attributes.filter(o=>o.kind!=="EachDirective"));if(t.kind==="Element"){let o=this.tagAt(t);return{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:r,children:n,static:!1,...o?{at:o}:{}}}return{kind:"component",name:t.tag,props:r,children:n}}lowerAttributes(t){let n=[],r=[],o=!1,i,a=[],s=!1,l,p=[];for(let c of t)switch(c.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":n.push(this.plainAttr(c));break;case"PropertyBinding":n.push({name:c.name,kind:"prop",expr:this.hole(c.hole).code,reactive:this.hole(c.hole).reactive,...this.hole(c.hole).at?{at:this.hole(c.hole).at}:{}});break;case"EventBinding":n.push(this.eventProp(c));break;case"RefBinding":n.push({name:"ref",kind:"ref",expr:this.hole(c.hole).code,reactive:this.hole(c.hole).reactive,...this.hole(c.hole).at?{at:this.hole(c.hole).at}:{}});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(c.hole).code});break;case"ClassDirective":{let d=this.hole(c.hole);r.push(`${JSON.stringify(c.name)}: ${d.code}`),o=o||d.reactive,i??=d.at;break}case"StyleDirective":{let d=this.hole(c.hole);a.push(`${JSON.stringify(c.name)}: ${d.code}`),s=s||d.reactive,l??=d.at;break}case"BindDirective":n.push(...this.bindProps(c.name,this.hole(c.hole)));break;case"UseDirective":{let d=c.name??(c.hole!=null?this.hole(c.hole).code:null);if(!d)break;p.push(c.name!=null&&c.hole!=null?`[${d}, () => (${this.hole(c.hole).code})]`:`[${d}]`);break}}return r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:o,...i?{at:i}:{}}),a.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${a.join(", ")} }`,reactive:s,...l?{at:l}:{}}),p.length>0&&n.push({name:"use",kind:"attr",expr:`[${p.join(", ")}]`}),n}eventProp(t){let n=t.name.toLowerCase(),r=this.hole(t.hole).code;if(!(t.syntax==="colon"||t.modifiers.length>0))return{name:"on"+pt(t.name),kind:"event",event:{name:n,delegated:ut.has(n)},expr:r};let i=this.wrapHandler(r,t.modifiers),a=this.eventOptions(t.modifiers),s=a?`[${i}, ${a}]`:i;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(t,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",o=[];return n.includes("prevent")&&o.push("e.preventDefault();"),n.includes("stop")&&o.push("e.stopPropagation();"),!r&&o.length===0?t:`(e) => { ${r}${o.join(" ")} return (${t})(e); }`}eventOptions(t){let n=[];return t.includes("capture")&&n.push("capture: true"),t.includes("once")&&n.push("once: true"),t.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(t,n){let r=n.code,o=t==="checked",i=o?"change":"input",a=o?"checked":"value";this.used.add("bindPair");let s=`bindPair(${r})`;return[{name:t,kind:"attr",expr:`${s}[0]()`,reactive:!0,directive:`bind:${t}`,...n.at?{at:n.at}:{}},{name:"on"+pt(i),kind:"event",event:{name:i,delegated:ut.has(i)},expr:`(e) => ${s}[1](e.target.${a})`}]}plainAttr(t){let n=t.value,r=t.name;t.name==="class"?r=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":t.name==="html"&&(r="innerHTML");let i={name:r,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 p=this.hole(n.hole);return i.expr=p.code,i.reactive=p.reactive,p.at&&(i.at=p.at),i}let a=!1,s,l=n.parts.map(p=>{if("text"in p)return Sn(p.text);let c=this.hole(p.hole);return a=a||c.reactive,s??=c.at,"${"+c.code+"}"}).join("");return i.expr="`"+l+"`",i.reactive=a,s&&(i.at=s),i}};function ft(e,t,n,r={}){let{root:o}=(0,dt.parseTemplate)(e,{svg:r.svg});return new $e(t,n,r.sourceFile,r.positionAt).lowerRoot(o.children)}function mt(e,t,n={}){let r=new Set,o=ft(e,[...t],r,{svg:n.svg,...n.sourceFile?{sourceFile:n.sourceFile}:{},...n.positionAt?{positionAt:n.positionAt}:{}});J(o),se(o,{resolver:me(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:l=>l.load}),le(o);let{code:i,imports:a,templates:s}=F.emit(o,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let l of a)r.add(l);return n.hoistTemplates?{code:i,imports:[...r],ir:o,templates:s}:{code:fe(i,s),imports:[...r],ir:o}}var kn="children";function B(e){switch(e.kind){case"call":return!0;case"member":return e.property!==kn;case"compound":return e.parts.some(B);case"opaque":return!1}}var En=new Set(["CallExpression","OptionalCallExpression"]),In=new Set(["MemberExpression","OptionalMemberExpression"]);function M(e){if(!e)return{kind:"opaque"};if(En.has(e.type))return{kind:"call"};if(In.has(e.type)){let t=e.property;return{kind:"member",property:!(e.computed===!0)&&t?.type==="Identifier"?t.name:null}}return e.type==="ConditionalExpression"?{kind:"compound",parts:[e.test,e.consequent,e.alternate].map(Y)}:e.type==="LogicalExpression"||e.type==="BinaryExpression"?{kind:"compound",parts:[e.left,e.right].map(Y)}:e.type==="TemplateLiteral"?{kind:"compound",parts:e.expressions.map(Y)}:e.type==="ObjectExpression"?{kind:"compound",parts:e.properties.filter(n=>(n.type==="ObjectProperty"||n.type==="Property")&&n.computed!==!0).map(n=>Y(n.value))}:e.type==="ArrayExpression"?{kind:"compound",parts:e.elements.filter(n=>n!=null&&n.type!=="SpreadElement").map(Y)}:{kind:"opaque"}}var Y=e=>M(e);var wn=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),$n=/^on[A-Z]/,Cn=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),yt=e=>B(M(e)),Q=(e,t)=>{if(!t.sourceFile)return;let n=e.loc?.start;return n?{line:n.line,column:n.column}:void 0};function ee(e){if(e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral"||e.type==="Literal"&&(typeof e.value=="string"||typeof e.value=="number"||typeof e.value=="boolean"))return e.value}var Ce=e=>!!e&&typeof ee(e)=="string";function Tn(e,t){return e.type==="JSXIdentifier"?{tag:e.name,component:e.name[0]!==e.name[0].toLowerCase()}:e.type==="JSXMemberExpression"?{tag:t.code(e),component:!0}:e.type==="JSXNamespacedName"?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function Te(e){return e.type==="JSXIdentifier"?e.name==="class"?"className":e.name:e.type==="JSXNamespacedName"?`${e.namespace.name}:${e.name.name}`:"unknown"}function Pn(e,t){let n=Te(e.name),r=$n.test(n),o=r||n.startsWith("on:")||n==="ref",a={name:n,kind:r?"event":"attr"};if(r){let l=n.slice(2).toLowerCase();a.event={name:l,delegated:Cn.has(l)}}let s=e.value;if(s==null)return a.literal=!0,a.at=Q(e,t),a;if(Ce(s))return a.literal=ee(s),a.at=Q(s,t),a;if(s.type==="JSXExpressionContainer"&&s.expression?.type!=="JSXEmptyExpression"){let l=s.expression,p=ee(l);return p!==void 0?(a.literal=p,a.at=Q(l,t),a):(a.expr=t.code(l),a.reactive=o?!1:yt(l),a.at=Q(l,t),(l.type==="JSXElement"||l.type==="JSXFragment")&&(a.jsxElement=!0),a)}return a.literal=!0,a}function gt(e,t){let n=e.value;return n==null?null:Ce(n)?JSON.stringify(ee(n)):n.type==="JSXExpressionContainer"&&n.expression?.type!=="JSXEmptyExpression"?t.code(n.expression):null}function Mn(e,t){let n=[],r=[];for(let o of e){if(o.type==="JSXSpreadAttribute"){n.push({name:"",kind:"spread",expr:t.code(o.argument)});continue}if(o.type!=="JSXAttribute"||xe(Te(o.name)))continue;let i=o.name.type==="JSXNamespacedName"?o.name.namespace.name:null;if(i==="use"){let a=o.name.name.name;t.used.add(a);let s=gt(o,t);r.push(s!=null?`[${a}, () => (${s})]`:`[${a}]`);continue}if(i==="oncapture"){let a=o.name.name.name.toLowerCase(),s=gt(o,t)??"undefined";n.push({name:"on:"+a,kind:"attr",expr:`[${s}, { capture: true }]`});continue}n.push(Pn(o,t))}return r.length>0&&n.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),n}function ht(e,t){let n=[];for(let r of e)if(r.type==="JSXText"){let o=Z(r.value);o&&n.push({kind:"text",value:o})}else if(r.type==="JSXExpressionContainer"){if(r.expression?.type!=="JSXEmptyExpression"){let o=r.expression,i=yt(o);n.push({kind:"expr",code:t.code(o),reactive:i,...i?{at:Q(o,t)}:{}})}}else r.type==="JSXElement"||r.type==="JSXFragment"?n.push(Nt(r,t)):r.type==="JSXSpreadChild"&&n.push({kind:"expr",code:t.code(r.expression),reactive:!1});return n}function On(e){for(let t of e){if(t.type!=="JSXAttribute")continue;let n=Te(t.name);if(xe(n)){if(t.value&&!Ce(t.value))throw new P(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return ie(n,t.value?ee(t.value):null)}}}function Nt(e,t){if(e.type==="JSXFragment")return{kind:"fragment",children:ht(e.children,t)};let{tag:n,component:r}=Tn(e.openingElement.name,t),o=Mn(e.openingElement.attributes,t),i=ht(e.children,t),a=t.sourceFile&&e.loc?.start?{file:t.sourceFile,line:e.loc.start.line,column:e.loc.start.column}:void 0;if(r){let s=On(e.openingElement.attributes);return{kind:"component",name:n,props:o,children:i,...s?{load:s}:{},...a?{at:a}:{}}}return{kind:"element",tag:n,svg:wn.has(n),props:o,children:i,static:!1,...a?{at:a}:{}}}function vt(e,t){let n=Nt(e,t);return J(n),n}function O(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?O(n.argument,t):O(n.value,t);return;case"ArrayPattern":for(let n of e.elements)O(n,t);return;case"AssignmentPattern":O(e.left,t);return;case"RestElement":O(e.argument,t);return}}function xt(e,t){switch(e.type){case"ImportDeclaration":for(let n of e.specifiers)O(n.local,t);return;case"VariableDeclaration":for(let n of e.declarations)O(n.id,t);return;case"FunctionDeclaration":case"ClassDeclaration":O(e.id,t);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&xt(e.declaration,t);return}}function H(e){let t=new Set;for(let n of e.body)xt(n,t);return t}var St=require("@babel/parser"),kt=_e(require("magic-string"),1);function E(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?E(n.argument,t):E(n.value,t);return;case"ArrayPattern":for(let n of e.elements)E(n,t);return;case"AssignmentPattern":E(e.left,t);return;case"RestElement":E(e.argument,t);return}}function Pe(e){switch(e.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"NullLiteral":case"BigIntLiteral":case"RegExpLiteral":case"Identifier":return!0;case"Literal":return!0;case"TemplateLiteral":return e.expressions.every(Pe);case"UnaryExpression":return Pe(e.argument);case"MemberExpression":return!1;default:return!1}}function ge(e,t){if(!(!e||typeof e!="object")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="range"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let o of r)o&&typeof o=="object"&&ge(o,t);else r&&typeof r=="object"&&typeof r.type=="string"&&ge(r,t)}}}function An(e){let t=new Set;return ge(e,n=>{if(n.type==="AssignmentExpression")E(n.left,t);else if(n.type==="UpdateExpression"){let r=n.argument;r?.type==="Identifier"&&t.add(r.name)}}),t}function Dn(e,t){let n=new Set,r=o=>{let i=new Set;E(o,i);for(let a of i)t.has(a)&&n.add(a)};return ge(e,o=>{switch(o.type){case"VariableDeclarator":r(o.id);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":r(o.id);for(let i of o.params??[])r(i);return;case"CatchClause":r(o.param);return;case"ClassDeclaration":case"ClassExpression":r(o.id);return}}),n}function Rt(e,t,n){for(let r of e.properties??[]){if(r.type==="RestElement"){let c=r.argument;if(c?.type!=="Identifier"||t.length>0){let d=new Set;E(c,d);for(let u of d)n.bails.push({name:u,reason:"rest"});continue}n.rest={name:c.name,keys:[]};continue}if(r.computed){let c=new Set;E(r.value,c);for(let d of c)n.bails.push({name:d,reason:"computed"});continue}let o=r.key,i=o.type==="Identifier"?o.name:o.value,a=r.value,s;a.type==="AssignmentPattern"&&(s=a.right,a=a.left);let l=[...t,i];if(a.type==="Identifier"){if(s&&!Pe(s)){n.bails.push({name:a.name,reason:"unsafe-default"});continue}n.reads.push({name:a.name,path:l,...s?{fallback:s}:{}});continue}if(a.type==="ObjectPattern"){if(s){let c=new Set;E(a,c);for(let d of c)n.bails.push({name:d,reason:"unsafe-default"});continue}Rt(a,l,n);continue}let p=new Set;E(a,p);for(let c of p)n.bails.push({name:c,reason:"computed"})}}function he(e,t){let n={reads:[],bails:[]};if(e?.type!=="ObjectPattern"||(Rt(e,[],n),n.rest&&(t?.type!=="BlockStatement"?(n.bails.push({name:n.rest.name,reason:"rest"}),delete n.rest):n.rest.keys=(e.properties??[]).filter(s=>s.type!=="RestElement"&&!s.computed).map(s=>{let l=s.key;return l.type==="Identifier"?l.name:l.value})),n.reads.length===0&&!n.rest))return n;let r=new Set(n.reads.map(s=>s.name));n.rest&&r.add(n.rest.name);let o=An(t),i=Dn(t,r),a=[];for(let s of n.reads)o.has(s.name)?n.bails.push({name:s.name,reason:"reassigned"}):i.has(s.name)?n.bails.push({name:s.name,reason:"shadowed"}):a.push(s);return n.reads=a,n.rest&&o.has(n.rest.name)?(n.bails.push({name:n.rest.name,reason:"reassigned"}),delete n.rest):n.rest&&i.has(n.rest.name)&&(n.bails.push({name:n.rest.name,reason:"shadowed"}),delete n.rest),n}function ye(e){switch(e){case"rest":return"this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";case"computed":return"the property is not known until it runs";case"reassigned":return"the binding is assigned to, and props are read-only";case"shadowed":return"an inner scope binds the same name";case"unsafe-default":return"the default would have to run again on every read"}}function te(e,t,n=null){if(!(!e||typeof e!="object"||typeof e.type!="string")&&!e.type.startsWith("TS")&&t(e,n)!==!1)for(let r of Object.keys(e)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let o=e[r];if(Array.isArray(o))for(let i of o)te(i,t,e);else o&&typeof o=="object"&&te(o,t,e)}}function bt(e){return!!e&&e[0]>="A"&&e[0]<="Z"}function Ln(e){let t=[];return te(e,n=>{if(n.type==="FunctionDeclaration"&&bt(n.id?.name)){t.push(n);return}if(n.type==="VariableDeclarator"&&bt(n.id?.name)){let r=n.init;r&&(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")&&t.push(r)}}),t}function jn(e){let t=new Set;return te(e,n=>{n.type==="Identifier"&&t.add(n.name)}),t}function Jn(e,t){if(!t)return!0;switch(t.type){case"MemberExpression":case"OptionalMemberExpression":return!(t.property===e&&!t.computed);case"ObjectProperty":case"ObjectMethod":case"ClassProperty":case"ClassMethod":return!(t.key===e&&!t.computed);case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return t.label!==e;case"ImportSpecifier":case"ExportSpecifier":return!1;default:return!0}}function Me(e,t,n={}){let r=[],o=[],i=new Set;for(let a of Ln(e)){let s=a.params?.[0];if(s?.type!=="ObjectPattern")continue;let l=he(s,a.body);for(let m of l.bails)o.push({name:m.name,reason:m.reason,message:ye(m.reason),start:s.start});if(l.bails.length>0||l.reads.length===0&&!l.rest)continue;let p=jn(a),c=n.parameterName??"props";for(;p.has(c);)c=`_${c}`;let d=new Map;for(let m of l.reads){let y=`${c}.${m.path.join(".")}`,b=m.fallback;d.set(m.name,b?`(${y} === undefined ? ${t.slice(b.start,b.end)} : ${y})`:y)}let u=s.typeAnnotation;if(r.push({start:s.start,end:u?.start??s.end,code:c}),l.rest){let m=l.rest.keys.map(b=>JSON.stringify(b)).join(", "),y=a.body;r.push({start:y.start+1,end:y.start+1,code:`
|
|
2
|
+
const [, ${l.rest.name}] = splitProps(${c}, [${m}]);`}),i.add("splitProps")}let g=[];te(a.body,(m,y)=>{if(m.type!=="Identifier")return;let b=d.get(m.name);if(!b)return;let R=y?.type==="ObjectProperty"&&y.shorthand&&y.value===m;if(!R&&!Jn(m,y))return;let N=l.reads.find($=>$.name===m.name).path;g.push({node:m,parent:R?y:null,text:b,property:N[N.length-1]})});for(let m of g)m.parent?r.push({start:m.parent.start,end:m.parent.end,code:`${m.node.name}: ${m.text}`}):r.push({start:m.node.start,end:m.node.end,code:m.text}),_n(m.node,c,m.property)}return{edits:r,diagnostics:o,used:i}}function _n(e,t,n){e.type="MemberExpression",e.computed=!1,e.optional=!1,e.object={type:"Identifier",name:t,start:e.start,end:e.start},e.property={type:"Identifier",name:n,start:e.end,end:e.end},delete e.name}function Et(e,t="module.tsx",n={}){let r=(0,St.parse)(e,{sourceType:"module",plugins:["typescript","jsx"],errorRecovery:!0}),{edits:o,diagnostics:i,used:a}=Me(r.program,e,n),s=new kt.default(e);for(let l of o)l.start===l.end?s.appendLeft(l.start,l.code):s.overwrite(l.start,l.end,l.code);return a.has("splitProps")&&!H(r.program).has("splitProps")&&s.prepend(`import { splitProps } from ${JSON.stringify(n.runtimeModule??"@fluixi/dom")};
|
|
3
|
+
`),{code:s.toString(),map:s.generateMap({source:t,includeContent:!0,hires:!0}),diagnostics:i,rewritten:o.filter(l=>l.code!==(n.parameterName??"props")).length}}function Oe(e,t){if(!(!e||typeof e!="object"||typeof e.type!="string")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let o of r)Oe(o,t);else r&&typeof r=="object"&&Oe(r,t)}}}function It(e){let t=[],n=[],r=new Map,o=new Set,{shadowed:i}=de(e);return Oe(e,a=>{if(a.type!=="CallExpression")return;let s=a.callee;if(s?.type!=="Identifier")return;let l=s.name;if(!pe(l))return;if(i.has(l)){o.has(l)||(o.add(l),n.push({name:l,message:`${l} is reserved for the compiler, and this module binds it. The call keeps your binding's meaning; rename it to use the intrinsic.`,start:s.start}));return}let p=w[l];t.push({start:s.start,end:s.end,code:p.export});let c=r.get(p.module)??new Set;c.add(p.export),r.set(p.module,c)}),{edits:t,diagnostics:n,imports:r}}function wt(e,t){let n=[];for(let[r,o]of[...e.imports].sort(([i],[a])=>i.localeCompare(a))){let i=[...o].filter(a=>!t.has(a)).sort();i.length&&n.push(`import { ${i.join(", ")} } from ${JSON.stringify(r)};`)}return n.length?`${n.join(`
|
|
4
4
|
`)}
|
|
5
|
-
`:""}var
|
|
6
|
-
`?
|
|
5
|
+
`:""}var Fn=new Set(U),Bn=new Set(X),Hn=new Set(_),Vn=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]);function ve(e,t,n=null,r=""){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let o of e)ve(o,t,n,r);return}typeof e.type=="string"&&t(e,n,r);for(let o of Object.keys(e))o==="loc"||o==="leadingComments"||o==="trailingComments"||ve(e[o],t,typeof e.type=="string"?e:n,o)}}var Ae=e=>e.type==="JSXElement"||e.type==="JSXFragment";function Un(e,t,n){return Ae(e)?!(t&&Ae(t)&&n==="children"):!1}function Xn(e,t){return e.type==="TaggedTemplateExpression"&&e.tag?.type==="Identifier"&&(e.tag.name===t||e.tag.name==="svg")}function Tt(e){return e.filter(t=>!e.some(n=>n!==t&&n.start<=t.start&&n.end>=t.end&&n.end-n.start>t.end-t.start&&!(t.start===t.end&&(t.start===n.start||t.start===n.end))))}function Ne(e,t,n,r){let o=Tt(r.filter(a=>a.start>=t&&a.end<=n)).sort((a,s)=>s.start-a.start),i=e.slice(t,n);for(let a of o)i=i.slice(0,a.start-t)+a.code+i.slice(a.end-t);return i}function zn(e,t,n,r=!1){let o=r?t.loc?.start:void 0,i={code:Ne(e,t.start,t.end,n),reactive:B(M(t)),...o?{at:{line:o.line,column:o.column}}:{}};return t.type==="ArrowFunctionExpression"&&t.body?.type!=="BlockStatement"&&(i.arrow={params:t.params.map(a=>Ne(e,a.start,a.end,n)),body:Ne(e,t.body.start,t.body.end,n),bodyReactive:B(M(t.body))}),t.type==="ObjectExpression"&&(i.object=!0),i}function Pt(e,t,n){if(!t||t.length===0)return e;let r=new Map;for(let o of t){let i=`${o.svg?"svg:":""}${o.html}`,a=n.get(i);a||(a=`_fxTmpl$${n.size}`,n.set(i,a)),r.set(o.id,a)}return e.replace(/_tmpl\$\d+/g,o=>r.get(o)??o)}function De(e,t){if(e.kind==="component"&&e.load&&!e.source&&V(e.load)&&(t.ignoredLoad.has(e.name)||t.ignoredLoad.set(e.name,e.load)),e.kind==="component"&&e.source){let n=e.source;n.origin==="builtin"?t.builtins.add(e.name):V(n.loading)&&!t.resolved.has(e.name)?t.deferred.set(e.name,n):(t.deferred.delete(e.name),t.resolved.set(e.name,n))}if("props"in e&&e.props)for(let n of e.props)n.kind==="event"&&n.event?.delegated&&t.delegatedEvents.add(n.event.name);if("children"in e&&e.children)for(let n of e.children)De(n,t)}function Wn(e,t){for(let n of e.body??[])if(n.type==="ImportDeclaration")for(let r of n.specifiers??[]){if(r.local?.name!==t)continue;if(r.type==="ImportNamespaceSpecifier")return;let o=r.type==="ImportDefaultSpecifier"?"default":r.imported?.name??r.imported?.value;return{module:n.source.value,export:o,declaration:n,specifier:r}}}function Kn(e,t){for(let n of e.body??[])if(n.type==="ImportDeclaration"){for(let r of n.specifiers??[])if(r.type==="ImportNamespaceSpecifier"&&r.local?.name===t)return!0}return!1}function qn(e,t,n){let r=!1;return ve(e,o=>{r||o.type!=="Identifier"||o.name!==t||o.start===n.local?.start&&o.end===n.local?.end||(r=!0)}),r}function Gn(e){let t=[`kind: ${JSON.stringify(e.kind)}`];return e.kind==="visible"&&e.rootMargin&&t.push(`rootMargin: ${JSON.stringify(e.rootMargin)}`),e.kind==="interaction"&&t.push(`events: ${JSON.stringify(e.events)}`),e.kind==="media"&&t.push(`query: ${JSON.stringify(e.query)}`),`{ ${t.join(", ")} }`}function Zn(e){let t=[0];for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&t.push(n+1);return n=>{let r=0,o=t.length-1;for(;r<o;){let i=r+o+1>>1;t[i]<=n?r=i:o=i-1}return{line:r+1,column:n-t[r]}}}function Yn(e){let t=[];return e.quasi.quasis.forEach((n,r)=>{if(t.push({kind:"static",text:n.value.cooked??n.value.raw,start:n.start}),r<e.quasi.expressions.length){let o=e.quasi.expressions[r];t.push({kind:"hole",index:r,start:o.start,end:o.end})}}),t}function Qn(e,t){if(!t)return e;let n=t.endsWith("/")?t:`${t}/`;return e.startsWith(n)?e.slice(n.length):e}function Mt(e,t,n={}){let r=n.litTag??"html",o=n.format??"both",i=o!=="jsx",a=o!=="lit",s=i&&(e.includes(`${r}\``)||e.includes("svg`")),l=n.intrinsics!==!1&&Ge(e),p=n.sourceLocations===!0&&nt(e),c=Qn(t,n.sourceRoot);if(!s&&!(a&&e.includes("<"))&&!l&&!p)return null;let d=(0,$t.parse)(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),u=[];ve(d.program,(f,S,x)=>{(i&&Xn(f,r)||a&&Un(f,S,x))&&u.push(f)});let g=n.propsDestructure===!1?{edits:[],diagnostics:[],used:new Set}:Me(d.program,e,{runtimeModule:n.runtimeModule}),m=n.intrinsics===!1?{edits:[],diagnostics:[],imports:new Map}:It(d.program),y=n.sourceLocations===!0?rt(d.program,c):{edits:[],marked:0};if(u.length===0&&g.edits.length===0&&y.edits.length===0&&m.edits.length===0&&m.diagnostics.length===0&&g.diagnostics.length===0)return null;u.sort((f,S)=>S.start-f.start||f.end-S.end);let R=new Set(g.used),N={builtins:new Set,resolved:new Map,deferred:new Map,delegatedEvents:new Set,ignoredLoad:new Map,unresolved:new Set,declared:Ye(d.program)},$=new Map,A=[...g.edits,...m.edits,...y.edits];for(let f of u){let S=u.some(k=>k!==f&&k.start<=f.start&&k.end>=f.end&&k.end-k.start>f.end-f.start);if(Ae(f)){A.push({start:f.start,end:f.end,code:er(e,f,A,S,R,N,$,n,c)});continue}let x=f.quasi.expressions.map(k=>zn(e,k,A,n.sourceLocations===!0)),T=mt(Yn(f),x,{...n,hoistTemplates:!0,...n.sourceLocations===!0?{sourceFile:c,positionAt:Zn(e)}:{},templateClone:n.templateClone??!0,partialTemplates:S?!1:n.partialTemplates??!0,svg:f.tag.name==="svg"});for(let k of T.imports)R.add(k);De(T.ir,N),A.push({start:f.start,end:f.end,code:Pt(T.code,T.templates,$)})}let I=new Ct.default(e);for(let f of Tt(A))f.start===f.end?I.appendLeft(f.start,f.code):I.overwrite(f.start,f.end,f.code);let h=H(d.program),C=new Map;for(let[f]of N.ignoredLoad)h.has(f)||C.set(f,"unsupplied");for(let[f,S]of[...N.ignoredLoad]){if(!h.has(f))continue;let x=Wn(d.program,f);if(!x){C.set(f,Kn(d.program,f)?"namespace":"local");continue}if(qn(d.program,f,x.specifier)){C.set(f,"value");continue}let T=x.declaration.specifiers.filter(ne=>ne!==x.specifier),k=T.length===0&&e[x.declaration.end]===`
|
|
6
|
+
`?x.declaration.end+1:x.declaration.end;I.overwrite(x.declaration.start,k,T.length===0?"":`import { ${T.map(ne=>e.slice(ne.start,ne.end)).join(", ")} } from ${JSON.stringify(x.declaration.source.value)};`),N.deferred.set(f,{module:x.module,export:x.export,origin:"rule",loading:S}),h.delete(f),N.ignoredLoad.delete(f)}let j=tr(R,N,$,h,n);j&&I.prepend(j);let D=wt(m,h);D&&I.prepend(D);let Ot={value:f=>`${f} is used as a value here, not only as a tag, so its import has to stay — deferring would hand those references a lazy wrapper instead of the component. Defer it at the point it is rendered, or keep it eager.`,namespace:f=>`${f} came in through a namespace import, which has no single export to defer. Import ${f} by name.`,local:f=>`${f} is declared in this file, so there is no module to load separately. Move it to its own file and import it.`,unsupplied:f=>`nothing supplies ${f}, so there is no import to defer. Import it, or add a \`resolve\` rule for it.`},Le=[...N.ignoredLoad].map(([f,S])=>({name:f,strategy:S,message:`load:${S.kind} has no effect on <${f}>: ${Ot[C.get(f)??"unsupplied"](f)}`})),je=[...N.unresolved].map(f=>({name:f,message:`<${f}> is not defined: nothing imports it and no \`resolve\` rule supplies it. This compiles to a reference to a name that does not exist, so the component renders nothing. Import ${f}, or add a \`resolve\` rule for it.`}));return{code:I.toString(),map:I.generateMap({source:t,includeContent:!0,hires:!0}),...Le.length?{loadDiagnostics:Le}:{},...je.length?{unresolvedDiagnostics:je}:{},...g.diagnostics.length?{propsDiagnostics:g.diagnostics}:{},...m.diagnostics.length?{intrinsicDiagnostics:m.diagnostics}:{}}}function er(e,t,n,r,o,i,a,s,l){let p=vt(t,{code:u=>Ne(e,u.start,u.end,n),used:o,...s.sourceLocations===!0&&l?{sourceFile:l}:{}});J(p);let c=se(p,{resolver:me(s.resolve??[]),isBound:u=>i.declared.has(u),modules:{controlFlowModule:s.controlFlowModule??s.runtimeModule??"@fluixi/dom",coreModule:s.coreModule??"@fluixi/core",routerModule:s.routerModule??"@fluixi/core/router"},strategyFor:u=>u.load});for(let u of c.unresolved)i.unresolved.add(u);le(p);let d=F.emit(p,{templateClone:s.templateClone??!0,partialTemplates:r?!1:s.partialTemplates??!0});for(let u of d.imports)o.add(u);return De(p,i),Pt(d.code,d.templates,a)}function tr(e,t,n,r,o){let i=o.runtimeModule??"@fluixi/dom",a=o.coreModule??"@fluixi/core",s=new Map,l=(u,g)=>s.set(u,[...s.get(u)??[],g]),p=new Set(e);for(let u of t.builtins)p.add(u);t.delegatedEvents.size>0&&p.add("delegateEvents");for(let u of[...p].sort())r.has(u)||(Vn.has(u)?l(o.reactiveModule??"@fluixi/reactive/signal",u):Hn.has(u)?l(o.routerModule??"@fluixi/core/router",u):Bn.has(u)?l(a,u):Fn.has(u)?l(o.controlFlowModule??i,u):l(i,u));for(let[u,g]of t.resolved)r.has(u)||l(g.module,g.export==="default"?`default as ${u}`:u===g.export?u:`${g.export} as ${u}`);let c=[];for(let[u,g]of s)c.push(`import { ${g.join(", ")} } from ${JSON.stringify(u)};`);let d=[...t.deferred].filter(([u])=>!r.has(u));if(d.length>0){r.has("deferred")||c.push(`import { deferred } from ${JSON.stringify(a)};`);for(let[u,g]of d)c.push(`const ${u} = deferred(() => import(${JSON.stringify(g.module)}), { strategy: ${Gn(g.loading)}, export: ${JSON.stringify(g.export)} });`)}for(let[u,g]of n)c.push(`const ${g} = ${JSON.stringify(u.startsWith("svg:")?u.slice(4):u)};`);return t.delegatedEvents.size>0&&c.push(`delegateEvents(${JSON.stringify([...t.delegatedEvents])});`),c.length>0?c.join(`
|
|
7
7
|
`)+`
|
|
8
8
|
`:null}
|