@fluixi/compiler 1.0.0-alpha.71 → 1.0.0-alpha.72
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/{babel-DFIRSRWC.mjs → babel-E7EQLX36.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.d.ts.map +1 -1
- package/dist/frontend/babel/build-ir.js +5 -2
- 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/integrations.cjs +1 -1
- package/dist/integrations.mjs +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ue=Object.create;var y=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var fe=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var ge=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0})},B=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of me(e))!he.call(t,i)&&i!==n&&y(t,i,{get:()=>e[i],enumerable:!(r=de(e,i))||r.enumerable});return t};var H=(t,e,n)=>(n=t!=null?ue(fe(t)):{},B(e||!t||!t.__esModule?y(n,"default",{value:t,enumerable:!0}):n,t)),ve=t=>B(y({},"__esModule",{value:!0}),t);var Ye={};ge(Ye,{SVG_TAGS:()=>ce,buildIR:()=>pe,cleanJSXText:()=>S,genExpr:()=>f,isReactiveExpr:()=>m});module.exports=ve(Ye);var p=require("@babel/core"),D=H(require("@babel/generator"),1);var xe=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),F={className:"class",htmlFor:"for"},ke=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Ee=new Set(["script","style","textarea","title"]);function C(t){return Ee.has(t)}function z(t){return F[t]??t}function v(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!ke.has(t.name)}function A(t){if(!t.static||C(t.tag))return!1;for(let e of t.props)if(!v(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&A(e)))return!1;return!0}function x(t){let e=t.props.map(Ne).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return xe.has(t.tag)?n:`${n}${t.children.map(Re).join("")}</${t.tag}>`}function Re(t){if(t.kind==="text")return be(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return x(t)}function Ne(t){let e=F[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${Se(String(n))}"`}function Se(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function be(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var ye="<!--fx-->",Ie="<!--fx/-->";function $(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function $e(t){return t.kind==="text"||t.kind==="element"&&V(t)}function V(t){return t.svg||C(t.tag)||!t.props.every(e=>v(e))?!1:t.children.every(e=>$e(e)||$(e))}function I(t){if($(t))return!0;let e=t.children;return e?e.some(I):!1}function W(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"||W(e))}function U(t){if(!V(t)||!W(t)||!t.children.some(I))return null;let e=[],n=[],r=0,i=a=>{let s=`_n$${r++}`;return e.push({ref:s,expr:a}),s};return o(t,"_el$"),{html:we(t),tag:t.tag,steps:e,holes:n};function o(a,s){let l=-1;a.children.forEach((u,d)=>{I(u)&&(l=d)});let c=null;for(let u=0;u<=l;u++){let d=a.children[u],g=c?`${c}.nextSibling`:`${s}.firstChild`;if($(d)){let _=i(g),M=i(`holeEnd(${_})`);n.push({parentRef:s,startRef:_,endRef:M,node:d}),c=M;continue}let b=i(g);d.kind==="element"&&I(d)&&o(d,b),c=b}}}function we(t){return x(G(t)).split(K).join(ye+Ie)}function G(t){return{...t,children:t.children.map(e=>$(e)?{kind:"text",value:K}:e.kind==="element"?G(e):e)}}var K="\0fx-hole\0";var P={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},rt={version:2,module:"@fluixi/dom",symbols:[...P.symbols,"template","cloneTemplate","walk"]};var Te={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Ce(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function Z(t){return Ce(t)?t:JSON.stringify(t)}function Ae(t){return t.expr!==void 0?t.reactive?`() => (${t.expr})`:`(${t.expr})`:JSON.stringify(t.literal??!0)}function Pe(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function Je(t,e,n){let r=t.filter(s=>s.kind==="spread"),o=t.filter(s=>s.kind!=="spread").map(s=>`${Z(s.name)}: ${Ae(s)}`);e!=null&&o.push(`children: ${e}`);let a=`{ ${o.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(s=>s.expr).join(", ")}, ${a})`):a}function Y(t,e,n){return t.length===1?k(t[0],e,n):`[${t.map(r=>k(r,e,n)).join(", ")}]`}function q(t,e,n,r,i){r.add("createMemo"),r.add("createComponent");let o=e.filter(c=>c.kind==="spread"),s=e.filter(c=>c.kind!=="spread").map(c=>`get ${Z(c.name)}() { return ${Pe(c)}; }`);n.length>0&&s.push(`get children() { return ${Y(n,r,i)}; }`);let l=`{ ${s.join(", ")} }`;return o.length>0&&(r.add("mergeProps"),l=`mergeProps(${o.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${t}, ${l}))`}function Le(t,e){let n=z(e.name),r=e.literal;return r===!0||r===void 0?`${t}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${t}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var Q=!1;function k(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":Y(t.children,e,n);case"component":return q(t.name,t.props,t.children,e,n);case"control":{let r=Te[t.control]??t.control;return e.add(r),q(r,t.props,t.children,e,n)}case"element":{if(n&&t.static&&!t.svg&&A(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;return n.push({id:s,html:x(t),tag:t.tag,svg:!1}),`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&Q){let s=U(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 u of s.steps)c.push(`const ${u.ref} = ${u.expr};`);for(let u of s.holes)c.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${k(u.node,e,n)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let r=JSON.stringify(t.tag),i="_el$",o=[],a=t.svg?`${r}, true`:r;if(o.push(`const ${i} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every(v))for(let s of t.props)o.push(Le(i,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";o.push(`spread({ element: ${i}, props: ${Je(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let l=k(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";o.push(c?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return o.push(`return ${i};`),`(() => { ${o.join(" ")} })()`}}}function E(t,e){if(!e||e.length===0)return t;let n=new Map(e.map(r=>[r.id,JSON.stringify(r.html)]));return t.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var R={name:"imperative",contract:P,emit(t,e){let n=new Set,r=e?.templateClone!==!1?[]:void 0;return Q=e?.partialTemplates===!0,{code:k(t,n,r),imports:Array.from(n),templates:r}}};var N=require("@babel/core"),L=H(require("@babel/generator"),1),re=require("@fluixi/template-parser");var Xe={kind:"eager"},De=["pointerdown","focusin","keydown"],ee=new Set(["eager","idle","visible","interaction","media","never"]),h=class extends Error{};function J(t){return t.startsWith("load:")}function w(t,e){let n=t.slice(5);if(!ee.has(n))throw new h(`Unknown load strategy 'load:${n}'. Expected one of ${[...ee].join(", ")}.`);switch(n){case"eager":return Xe;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?je(e):[...De]};case"media":if(!e)throw new h(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new h(`Unhandled load strategy '${n}'.`)}}function je(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new h("'load:interaction' was given no event names.");return e}var Oe=L.default.default??L.default;function _e(t){return Oe(t,{concise:!0}).code}var te=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Me(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function ne(t){return t.charAt(0).toUpperCase()+t.slice(1)}var X=class{constructor(e,n){this.holes=e;this.used=n}hole(e){return this.holes[e]??{node:N.types.identifier("undefined"),code:"undefined",reactive:!1}}emit(e){let{code:n,imports:r,templates:i}=R.emit(e,{});for(let o of r)this.used.add(o);return E(n,i)}lowerRoot(e){let n=this.lowerChildren(e);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.kind==="Element"||i.kind==="Component"){let a=i.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=r+1;s<e.length&&this.isBlankText(e[s])&&s++;let l=e[s],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(u=>u.kind==="ElseDirective");n.push(this.lowerIf(i,a.hole,c?l:null)),c&&(r=s);continue}if(i.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(i));continue}}let o=this.lowerNode(i);o&&n.push(o)}return n}isBlankText(e){return e.kind==="Text"&&!e.raw&&S(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=S(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(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=e.attributes.filter(o=>o!==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}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,r=this.lowerAttributes(e.attributes),{slots:i,rest:o}=this.partitionSlots(e.children);for(let[l,c]of i){let u=c.length===1?c[0]:{kind:"fragment",children:c},d={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},g=r.findIndex(b=>b.name===l);g>=0?r[g]=d:r.push(d)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?w(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:r,children:this.lowerChildren(o),...s?{load:s}:{}}}partitionSlots(e){let n=new Map,r=[];for(let i of e){if(i.kind==="Element"||i.kind==="Component"){let o=i.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(o&&o.value&&o.value.kind==="static"){let a={...i,attributes:i.attributes.filter(c=>c!==o)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),l=n.get(o.value.value)??[];l.push(s),n.set(o.value.value,l);continue}}r.push(i)}return{slots:n,rest:r}}lowerIf(e,n,r){let i=this.hole(n),o=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive}];if(r){let s=this.stripAndLower(r,l=>l.kind==="ElseDirective");o.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:o,children:[a]}}lowerEach(e){let n=e.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(e);let r=this.hole(n.hole),i=[{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;i.push({name:"by",kind:"attr",expr:l})}let o=this.itemArrow(e),a;if(o){let l=o.body,c={kind:"expr",code:f(l,this.used),reactive:m(l)},u=this.rebuildWithChildren(e,[c]);a=`(${o.params.map(d=>_e(d)).join(", ")}) => (${this.emit(u)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");a=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:i,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(e){let n=e.children.filter(i=>!this.isBlankText(i));if(n.length!==1||n[0].kind!=="Expression")return null;let r=this.hole(n[0].hole).node;return N.types.isArrowFunctionExpression(r)&&!N.types.isBlockStatement(r.body)?r:null}stripAndLower(e,n){let r={...e,attributes:e.attributes.filter(i=>!n(i))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(e,n){let r=this.lowerAttributes(e.attributes.filter(i=>i.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:r,children:n,static:!1}:{kind:"component",name:e.tag,props:r,children:n}}lowerAttributes(e){let n=[],r=[],i=!1,o=[],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);r.push(`${JSON.stringify(l.name)}: ${c.code}`),i=i||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);o.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 r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:i}),o.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:a}),s.length>0&&n.push({name:"use",kind:"attr",expr:`[${s.join(", ")}]`}),n}eventProp(e){let n=e.name.toLowerCase(),r=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+ne(e.name),kind:"event",event:{name:n,delegated:te.has(n)},expr:r};let o=this.wrapHandler(r,e.modifiers),a=this.eventOptions(e.modifiers),s=a?`[${o}, ${a}]`:o;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(e,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return n.includes("prevent")&&i.push("e.preventDefault();"),n.includes("stop")&&i.push("e.stopPropagation();"),!r&&i.length===0?e:`(e) => { ${r}${i.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 r=e==="checked",i=r?"change":"input",o=r?"checked":"value",a=`(${n})`;return[{name:e,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+ne(i),kind:"event",event:{name:i,delegated:te.has(i)},expr:`(e) => ${a}[1](e.target.${o})`}]}plainAttr(e){let n=e.value,r=e.name;e.name==="class"?r=n&&n.kind==="hole"&&N.types.isObjectExpression(this.hole(n.hole).node)?"classList":"className":e.name==="html"&&(r="innerHTML");let o={name:r,kind:"attr"};if(n==null)return o.literal=!0,o;if(n.kind==="static")return o.literal=n.value,o;if(n.kind==="hole"){let l=this.hole(n.hole);return o.expr=l.code,o.reactive=l.reactive,o}let a=!1,s=n.parts.map(l=>{if("text"in l)return Me(l.text);let c=this.hole(l.hole);return a=a||c.reactive,"${"+c.code+"}"}).join("");return o.expr="`"+s+"`",o.reactive=a,o}};function ie(t,e,n={}){let r=t.quasi,i=r.expressions.map(s=>{let l=s;return{node:l,code:f(l,e),reactive:m(l)}}),o=Be(r),{root:a}=(0,re.parseTemplate)(o,{svg:n.svg});return new X(i,e).lowerRoot(a.children)}function Be(t){let e=[];return t.quasis.forEach((n,r)=>{let i=n.value.cooked??n.value.raw;if(e.push({kind:"static",text:i,start:n.start??0}),r<t.expressions.length){let o=t.expressions[r];e.push({kind:"hole",index:r,start:o.start??0,end:o.end??0})}}),e}function He(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 T(t){let e=[],n=new Map,r=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let o of i.children)r(o);return!1;case"fragment":for(let o of i.children)r(o);return!1;case"element":{let o=!0;for(let s of i.children)r(s)||(o=!1);let a;for(let s of i.props)if(a=He(s),a)break;return!a&&!o&&(a=Fe(i)),i.static=!a,a?n.set(i,a):e.push(i),i.static}default:return!1}};for(let i of Array.isArray(t)?t:[t])r(i);return{staticElements:e,reasons:n}}function Fe(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"}function se(t,e=new Set,n={}){let r=ie(t,e,n);return T(r),r}var ze=D.default.default??D.default;function le(t){return ze(t,{concise:!0}).code}function Ve(t,e){let n=p.types.cloneNode(t,!0),r=p.types.file(p.types.program([p.types.expressionStatement(n)])),i=!1,o=(a,s,l)=>{for(let c of l)e.add(c);a.replaceWith(p.template.expression(s,{placeholderPattern:!1,plugins:["typescript"]})()),a.skip(),i=!0};return(0,p.traverse)(r,{"JSXElement|JSXFragment"(a){let s=a.node,{code:l,imports:c,templates:u}=R.emit(pe(s,e),{});o(a,E(l,u),c)},TaggedTemplateExpression(a){let s=a.node.tag;if(!p.types.isIdentifier(s)||s.name!=="html"&&s.name!=="svg")return;let l=se(a.node,e,{svg:s.name==="svg"}),{code:c,imports:u,templates:d}=R.emit(l,{});o(a,E(c,d),u)}}),i?r.program.body[0].expression:t}function f(t,e){return le(Ve(t,e))}var ce=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),We=/^on[A-Z]/,Ue=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Ge(t){if(p.types.isJSXIdentifier(t)){let e=t.name[0]!==t.name[0].toLowerCase();return{tag:t.name,component:e}}return p.types.isJSXMemberExpression(t)?{tag:le(t),component:!0}:p.types.isJSXNamespacedName(t)?{tag:`${t.namespace.name}:${t.name.name}`,component:!1}:{tag:"div",component:!1}}function O(t){return p.types.isJSXIdentifier(t)?t.name==="class"?"className":t.name:p.types.isJSXNamespacedName(t)?`${t.namespace.name}:${t.name.name}`:"unknown"}function m(t){return p.types.isCallExpression(t)||p.types.isOptionalCallExpression(t)?!0:p.types.isMemberExpression(t)||p.types.isOptionalMemberExpression(t)?!(!t.computed&&p.types.isIdentifier(t.property,{name:"children"})):p.types.isConditionalExpression(t)?m(t.test)||m(t.consequent)||m(t.alternate):p.types.isLogicalExpression(t)||p.types.isBinaryExpression(t)?m(t.left)||m(t.right):p.types.isTemplateLiteral(t)?t.expressions.some(e=>m(e)):p.types.isObjectExpression(t)?t.properties.some(e=>p.types.isObjectProperty(e)&&!e.computed&&m(e.value)):p.types.isArrayExpression(t)?t.elements.some(e=>e!=null&&!p.types.isSpreadElement(e)&&m(e)):!1}function Ke(t,e){let n=O(t.name),r=We.test(n),i=r||n.startsWith("on:"),a={name:n,kind:r?"event":"attr"};r&&(a.event={name:n.slice(2).toLowerCase(),delegated:Ue.has(n.slice(2).toLowerCase())});let s=t.value;if(s==null)return a.literal=!0,a;if(p.types.isStringLiteral(s))return a.literal=s.value,a;if(p.types.isJSXExpressionContainer(s)&&!p.types.isJSXEmptyExpression(s.expression)){let l=s.expression;return p.types.isStringLiteral(l)||p.types.isNumericLiteral(l)||p.types.isBooleanLiteral(l)?(a.literal=l.value,a):(a.expr=f(l,e),a.reactive=i?!1:m(l),(p.types.isJSXElement(l)||p.types.isJSXFragment(l))&&(a.jsxElement=!0),a)}return a.literal=!0,a}function oe(t,e){let n=t.value;return n==null?null:p.types.isStringLiteral(n)?JSON.stringify(n.value):p.types.isJSXExpressionContainer(n)&&!p.types.isJSXEmptyExpression(n.expression)?f(n.expression,e):null}function qe(t,e){let n=[],r=[];for(let i of t){if(p.types.isJSXSpreadAttribute(i)){n.push({name:"",kind:"spread",expr:f(i.argument,e)});continue}if(!p.types.isJSXAttribute(i)||J(O(i.name)))continue;let o=p.types.isJSXNamespacedName(i.name)?i.name.namespace.name:null;if(o==="use"){let a=i.name.name.name;e.add(a);let s=oe(i,e);r.push(s!=null?`[${a}, () => (${s})]`:`[${a}]`);continue}if(o==="oncapture"){let a=i.name.name.name.toLowerCase(),s=oe(i,e)??"undefined";n.push({name:"on:"+a,kind:"attr",expr:`[${s}, { capture: true }]`});continue}n.push(Ke(i,e))}return r.length>0&&n.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),n}function S(t){let e=t.split(/\r\n|\n|\r/),n=0;for(let i=0;i<e.length;i++)/[^ \t]/.test(e[i])&&(n=i);let r="";for(let i=0;i<e.length;i++){let o=e[i].replace(/\t/g," ");i!==0&&(o=o.replace(/^ +/,"")),i!==e.length-1&&(o=o.replace(/ +$/,"")),o&&(i!==n&&(o+=" "),r+=o)}return r}function ae(t,e){let n=[];for(let r of t)if(p.types.isJSXText(r)){let i=S(r.value);i&&n.push({kind:"text",value:i})}else if(p.types.isJSXExpressionContainer(r)){if(!p.types.isJSXEmptyExpression(r.expression)){let i=r.expression;n.push({kind:"expr",code:f(i,e),reactive:m(i)})}}else p.types.isJSXElement(r)||p.types.isJSXFragment(r)?n.push(j(r,e)):p.types.isJSXSpreadChild(r)&&n.push({kind:"expr",code:f(r.expression,e),reactive:!1});return n}function pe(t,e=new Set){let n=j(t,e);return T(n),n}function j(t,e){if(p.types.isJSXFragment(t))return{kind:"fragment",children:ae(t.children,e)};let{tag:n,component:r}=Ge(t.openingElement.name),i=qe(t.openingElement.attributes,e),o=ae(t.children,e);if(r){let a=Ze(t.openingElement.attributes);return{kind:"component",name:n,props:i,children:o,...a?{load:a}:{}}}return{kind:"element",tag:n,svg:ce.has(n),props:i,children:o,static:!1}}function Ze(t){for(let e of t){if(!p.types.isJSXAttribute(e))continue;let n=O(e.name);if(J(n)){if(e.value&&!p.types.isStringLiteral(e.value))throw new h(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return w(n,e.value?e.value.value:null)}}}
|
|
1
|
+
"use strict";var ue=Object.create;var y=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var fe=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var ge=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0})},B=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of me(e))!he.call(t,i)&&i!==n&&y(t,i,{get:()=>e[i],enumerable:!(r=de(e,i))||r.enumerable});return t};var H=(t,e,n)=>(n=t!=null?ue(fe(t)):{},B(e||!t||!t.__esModule?y(n,"default",{value:t,enumerable:!0}):n,t)),ve=t=>B(y({},"__esModule",{value:!0}),t);var Ye={};ge(Ye,{SVG_TAGS:()=>ce,buildIR:()=>pe,cleanJSXText:()=>S,genExpr:()=>f,isReactiveExpr:()=>m});module.exports=ve(Ye);var p=require("@babel/core"),D=H(require("@babel/generator"),1);var xe=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),F={className:"class",htmlFor:"for"},ke=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Ee=new Set(["script","style","textarea","title"]);function C(t){return Ee.has(t)}function z(t){return F[t]??t}function v(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!ke.has(t.name)}function A(t){if(!t.static||C(t.tag))return!1;for(let e of t.props)if(!v(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&A(e)))return!1;return!0}function x(t){let e=t.props.map(Ne).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return xe.has(t.tag)?n:`${n}${t.children.map(Re).join("")}</${t.tag}>`}function Re(t){if(t.kind==="text")return be(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return x(t)}function Ne(t){let e=F[t.name]??t.name,n=t.literal;return n===!0||n===void 0?` ${e}`:n===!1||n===null?"":` ${e}="${Se(String(n))}"`}function Se(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function be(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var ye="<!--fx-->",Ie="<!--fx/-->";function $(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function $e(t){return t.kind==="text"||t.kind==="element"&&V(t)}function V(t){return t.svg||C(t.tag)||!t.props.every(e=>v(e))?!1:t.children.every(e=>$e(e)||$(e))}function I(t){if($(t))return!0;let e=t.children;return e?e.some(I):!1}function W(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"||W(e))}function U(t){if(!V(t)||!W(t)||!t.children.some(I))return null;let e=[],n=[],r=0,i=a=>{let s=`_n$${r++}`;return e.push({ref:s,expr:a}),s};return o(t,"_el$"),{html:we(t),tag:t.tag,steps:e,holes:n};function o(a,s){let l=-1;a.children.forEach((u,d)=>{I(u)&&(l=d)});let c=null;for(let u=0;u<=l;u++){let d=a.children[u],g=c?`${c}.nextSibling`:`${s}.firstChild`;if($(d)){let _=i(g),M=i(`holeEnd(${_})`);n.push({parentRef:s,startRef:_,endRef:M,node:d}),c=M;continue}let b=i(g);d.kind==="element"&&I(d)&&o(d,b),c=b}}}function we(t){return x(G(t)).split(K).join(ye+Ie)}function G(t){return{...t,children:t.children.map(e=>$(e)?{kind:"text",value:K}:e.kind==="element"?G(e):e)}}var K="\0fx-hole\0";var P={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},rt={version:2,module:"@fluixi/dom",symbols:[...P.symbols,"template","cloneTemplate","walk"]};var Te={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Ce(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function Z(t){return Ce(t)?t:JSON.stringify(t)}function Ae(t){return t.expr!==void 0?t.reactive?`() => (${t.expr})`:`(${t.expr})`:JSON.stringify(t.literal??!0)}function Pe(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function Je(t,e,n){let r=t.filter(s=>s.kind==="spread"),o=t.filter(s=>s.kind!=="spread").map(s=>`${Z(s.name)}: ${Ae(s)}`);e!=null&&o.push(`children: ${e}`);let a=`{ ${o.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(s=>s.expr).join(", ")}, ${a})`):a}function Y(t,e,n){return t.length===1?k(t[0],e,n):`[${t.map(r=>k(r,e,n)).join(", ")}]`}function q(t,e,n,r,i){r.add("createMemo"),r.add("createComponent");let o=e.filter(c=>c.kind==="spread"),s=e.filter(c=>c.kind!=="spread").map(c=>`get ${Z(c.name)}() { return ${Pe(c)}; }`);n.length>0&&s.push(`get children() { return ${Y(n,r,i)}; }`);let l=`{ ${s.join(", ")} }`;return o.length>0&&(r.add("mergeProps"),l=`mergeProps(${o.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${t}, ${l}))`}function Le(t,e){let n=z(e.name),r=e.literal;return r===!0||r===void 0?`${t}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${t}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var Q=!1;function k(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":Y(t.children,e,n);case"component":return q(t.name,t.props,t.children,e,n);case"control":{let r=Te[t.control]??t.control;return e.add(r),q(r,t.props,t.children,e,n)}case"element":{if(n&&t.static&&!t.svg&&A(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;return n.push({id:s,html:x(t),tag:t.tag,svg:!1}),`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&Q){let s=U(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 u of s.steps)c.push(`const ${u.ref} = ${u.expr};`);for(let u of s.holes)c.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${k(u.node,e,n)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let r=JSON.stringify(t.tag),i="_el$",o=[],a=t.svg?`${r}, true`:r;if(o.push(`const ${i} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every(v))for(let s of t.props)o.push(Le(i,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";o.push(`spread({ element: ${i}, props: ${Je(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let l=k(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";o.push(c?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return o.push(`return ${i};`),`(() => { ${o.join(" ")} })()`}}}function E(t,e){if(!e||e.length===0)return t;let n=new Map(e.map(r=>[r.id,JSON.stringify(r.html)]));return t.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var R={name:"imperative",contract:P,emit(t,e){let n=new Set,r=e?.templateClone!==!1?[]:void 0;return Q=e?.partialTemplates===!0,{code:k(t,n,r),imports:Array.from(n),templates:r}}};var N=require("@babel/core"),L=H(require("@babel/generator"),1),re=require("@fluixi/template-parser");var Xe={kind:"eager"},De=["pointerdown","focusin","keydown"],ee=new Set(["eager","idle","visible","interaction","media","never"]),h=class extends Error{};function J(t){return t.startsWith("load:")}function w(t,e){let n=t.slice(5);if(!ee.has(n))throw new h(`Unknown load strategy 'load:${n}'. Expected one of ${[...ee].join(", ")}.`);switch(n){case"eager":return Xe;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?je(e):[...De]};case"media":if(!e)throw new h(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new h(`Unhandled load strategy '${n}'.`)}}function je(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new h("'load:interaction' was given no event names.");return e}var Oe=L.default.default??L.default;function _e(t){return Oe(t,{concise:!0}).code}var te=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Me(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function ne(t){return t.charAt(0).toUpperCase()+t.slice(1)}var X=class{constructor(e,n){this.holes=e;this.used=n}hole(e){return this.holes[e]??{node:N.types.identifier("undefined"),code:"undefined",reactive:!1}}emit(e){let{code:n,imports:r,templates:i}=R.emit(e,{});for(let o of r)this.used.add(o);return E(n,i)}lowerRoot(e){let n=this.lowerChildren(e);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.kind==="Element"||i.kind==="Component"){let a=i.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=r+1;s<e.length&&this.isBlankText(e[s])&&s++;let l=e[s],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(u=>u.kind==="ElseDirective");n.push(this.lowerIf(i,a.hole,c?l:null)),c&&(r=s);continue}if(i.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(i));continue}}let o=this.lowerNode(i);o&&n.push(o)}return n}isBlankText(e){return e.kind==="Text"&&!e.raw&&S(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=S(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(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=e.attributes.filter(o=>o!==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}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,r=this.lowerAttributes(e.attributes),{slots:i,rest:o}=this.partitionSlots(e.children);for(let[l,c]of i){let u=c.length===1?c[0]:{kind:"fragment",children:c},d={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},g=r.findIndex(b=>b.name===l);g>=0?r[g]=d:r.push(d)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?w(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:r,children:this.lowerChildren(o),...s?{load:s}:{}}}partitionSlots(e){let n=new Map,r=[];for(let i of e){if(i.kind==="Element"||i.kind==="Component"){let o=i.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(o&&o.value&&o.value.kind==="static"){let a={...i,attributes:i.attributes.filter(c=>c!==o)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),l=n.get(o.value.value)??[];l.push(s),n.set(o.value.value,l);continue}}r.push(i)}return{slots:n,rest:r}}lowerIf(e,n,r){let i=this.hole(n),o=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive}];if(r){let s=this.stripAndLower(r,l=>l.kind==="ElseDirective");o.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:o,children:[a]}}lowerEach(e){let n=e.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(e);let r=this.hole(n.hole),i=[{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;i.push({name:"by",kind:"attr",expr:l})}let o=this.itemArrow(e),a;if(o){let l=o.body,c={kind:"expr",code:f(l,this.used),reactive:m(l)},u=this.rebuildWithChildren(e,[c]);a=`(${o.params.map(d=>_e(d)).join(", ")}) => (${this.emit(u)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");a=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:i,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(e){let n=e.children.filter(i=>!this.isBlankText(i));if(n.length!==1||n[0].kind!=="Expression")return null;let r=this.hole(n[0].hole).node;return N.types.isArrowFunctionExpression(r)&&!N.types.isBlockStatement(r.body)?r:null}stripAndLower(e,n){let r={...e,attributes:e.attributes.filter(i=>!n(i))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(e,n){let r=this.lowerAttributes(e.attributes.filter(i=>i.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:r,children:n,static:!1}:{kind:"component",name:e.tag,props:r,children:n}}lowerAttributes(e){let n=[],r=[],i=!1,o=[],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);r.push(`${JSON.stringify(l.name)}: ${c.code}`),i=i||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);o.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 r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:i}),o.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:a}),s.length>0&&n.push({name:"use",kind:"attr",expr:`[${s.join(", ")}]`}),n}eventProp(e){let n=e.name.toLowerCase(),r=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+ne(e.name),kind:"event",event:{name:n,delegated:te.has(n)},expr:r};let o=this.wrapHandler(r,e.modifiers),a=this.eventOptions(e.modifiers),s=a?`[${o}, ${a}]`:o;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(e,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return n.includes("prevent")&&i.push("e.preventDefault();"),n.includes("stop")&&i.push("e.stopPropagation();"),!r&&i.length===0?e:`(e) => { ${r}${i.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 r=e==="checked",i=r?"change":"input",o=r?"checked":"value",a=`(${n})`;return[{name:e,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+ne(i),kind:"event",event:{name:i,delegated:te.has(i)},expr:`(e) => ${a}[1](e.target.${o})`}]}plainAttr(e){let n=e.value,r=e.name;e.name==="class"?r=n&&n.kind==="hole"&&N.types.isObjectExpression(this.hole(n.hole).node)?"classList":"className":e.name==="html"&&(r="innerHTML");let o={name:r,kind:"attr"};if(n==null)return o.literal=!0,o;if(n.kind==="static")return o.literal=n.value,o;if(n.kind==="hole"){let l=this.hole(n.hole);return o.expr=l.code,o.reactive=l.reactive,o}let a=!1,s=n.parts.map(l=>{if("text"in l)return Me(l.text);let c=this.hole(l.hole);return a=a||c.reactive,"${"+c.code+"}"}).join("");return o.expr="`"+s+"`",o.reactive=a,o}};function ie(t,e,n={}){let r=t.quasi,i=r.expressions.map(s=>{let l=s;return{node:l,code:f(l,e),reactive:m(l)}}),o=Be(r),{root:a}=(0,re.parseTemplate)(o,{svg:n.svg});return new X(i,e).lowerRoot(a.children)}function Be(t){let e=[];return t.quasis.forEach((n,r)=>{let i=n.value.cooked??n.value.raw;if(e.push({kind:"static",text:i,start:n.start??0}),r<t.expressions.length){let o=t.expressions[r];e.push({kind:"hole",index:r,start:o.start??0,end:o.end??0})}}),e}function He(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 T(t){let e=[],n=new Map,r=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let o of i.children)r(o);return!1;case"fragment":for(let o of i.children)r(o);return!1;case"element":{let o=!0;for(let s of i.children)r(s)||(o=!1);let a;for(let s of i.props)if(a=He(s),a)break;return!a&&!o&&(a=Fe(i)),i.static=!a,a?n.set(i,a):e.push(i),i.static}default:return!1}};for(let i of Array.isArray(t)?t:[t])r(i);return{staticElements:e,reasons:n}}function Fe(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"}function se(t,e=new Set,n={}){let r=ie(t,e,n);return T(r),r}var ze=D.default.default??D.default;function le(t){return ze(t,{concise:!0}).code}function Ve(t,e){let n=p.types.cloneNode(t,!0),r=p.types.file(p.types.program([p.types.expressionStatement(n)])),i=!1,o=(a,s,l)=>{for(let c of l)e.add(c);a.replaceWith(p.template.expression(s,{placeholderPattern:!1,plugins:["typescript"]})()),a.skip(),i=!0};return(0,p.traverse)(r,{"JSXElement|JSXFragment"(a){let s=a.node,{code:l,imports:c,templates:u}=R.emit(pe(s,e),{});o(a,E(l,u),c)},TaggedTemplateExpression(a){let s=a.node.tag;if(!p.types.isIdentifier(s)||s.name!=="html"&&s.name!=="svg")return;let l=se(a.node,e,{svg:s.name==="svg"}),{code:c,imports:u,templates:d}=R.emit(l,{});o(a,E(c,d),u)}}),i?r.program.body[0].expression:t}function f(t,e){return le(Ve(t,e))}var ce=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),We=/^on[A-Z]/,Ue=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Ge(t){if(p.types.isJSXIdentifier(t)){let e=t.name[0]!==t.name[0].toLowerCase();return{tag:t.name,component:e}}return p.types.isJSXMemberExpression(t)?{tag:le(t),component:!0}:p.types.isJSXNamespacedName(t)?{tag:`${t.namespace.name}:${t.name.name}`,component:!1}:{tag:"div",component:!1}}function O(t){return p.types.isJSXIdentifier(t)?t.name==="class"?"className":t.name:p.types.isJSXNamespacedName(t)?`${t.namespace.name}:${t.name.name}`:"unknown"}function m(t){return p.types.isCallExpression(t)||p.types.isOptionalCallExpression(t)?!0:p.types.isMemberExpression(t)||p.types.isOptionalMemberExpression(t)?!(!t.computed&&p.types.isIdentifier(t.property,{name:"children"})):p.types.isConditionalExpression(t)?m(t.test)||m(t.consequent)||m(t.alternate):p.types.isLogicalExpression(t)||p.types.isBinaryExpression(t)?m(t.left)||m(t.right):p.types.isTemplateLiteral(t)?t.expressions.some(e=>m(e)):p.types.isObjectExpression(t)?t.properties.some(e=>p.types.isObjectProperty(e)&&!e.computed&&m(e.value)):p.types.isArrayExpression(t)?t.elements.some(e=>e!=null&&!p.types.isSpreadElement(e)&&m(e)):!1}function Ke(t,e){let n=O(t.name),r=We.test(n),i=r||n.startsWith("on:")||n==="ref",a={name:n,kind:r?"event":"attr"};r&&(a.event={name:n.slice(2).toLowerCase(),delegated:Ue.has(n.slice(2).toLowerCase())});let s=t.value;if(s==null)return a.literal=!0,a;if(p.types.isStringLiteral(s))return a.literal=s.value,a;if(p.types.isJSXExpressionContainer(s)&&!p.types.isJSXEmptyExpression(s.expression)){let l=s.expression;return p.types.isStringLiteral(l)||p.types.isNumericLiteral(l)||p.types.isBooleanLiteral(l)?(a.literal=l.value,a):(a.expr=f(l,e),a.reactive=i?!1:m(l),(p.types.isJSXElement(l)||p.types.isJSXFragment(l))&&(a.jsxElement=!0),a)}return a.literal=!0,a}function oe(t,e){let n=t.value;return n==null?null:p.types.isStringLiteral(n)?JSON.stringify(n.value):p.types.isJSXExpressionContainer(n)&&!p.types.isJSXEmptyExpression(n.expression)?f(n.expression,e):null}function qe(t,e){let n=[],r=[];for(let i of t){if(p.types.isJSXSpreadAttribute(i)){n.push({name:"",kind:"spread",expr:f(i.argument,e)});continue}if(!p.types.isJSXAttribute(i)||J(O(i.name)))continue;let o=p.types.isJSXNamespacedName(i.name)?i.name.namespace.name:null;if(o==="use"){let a=i.name.name.name;e.add(a);let s=oe(i,e);r.push(s!=null?`[${a}, () => (${s})]`:`[${a}]`);continue}if(o==="oncapture"){let a=i.name.name.name.toLowerCase(),s=oe(i,e)??"undefined";n.push({name:"on:"+a,kind:"attr",expr:`[${s}, { capture: true }]`});continue}n.push(Ke(i,e))}return r.length>0&&n.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),n}function S(t){let e=t.split(/\r\n|\n|\r/),n=0;for(let i=0;i<e.length;i++)/[^ \t]/.test(e[i])&&(n=i);let r="";for(let i=0;i<e.length;i++){let o=e[i].replace(/\t/g," ");i!==0&&(o=o.replace(/^ +/,"")),i!==e.length-1&&(o=o.replace(/ +$/,"")),o&&(i!==n&&(o+=" "),r+=o)}return r}function ae(t,e){let n=[];for(let r of t)if(p.types.isJSXText(r)){let i=S(r.value);i&&n.push({kind:"text",value:i})}else if(p.types.isJSXExpressionContainer(r)){if(!p.types.isJSXEmptyExpression(r.expression)){let i=r.expression;n.push({kind:"expr",code:f(i,e),reactive:m(i)})}}else p.types.isJSXElement(r)||p.types.isJSXFragment(r)?n.push(j(r,e)):p.types.isJSXSpreadChild(r)&&n.push({kind:"expr",code:f(r.expression,e),reactive:!1});return n}function pe(t,e=new Set){let n=j(t,e);return T(n),n}function j(t,e){if(p.types.isJSXFragment(t))return{kind:"fragment",children:ae(t.children,e)};let{tag:n,component:r}=Ge(t.openingElement.name),i=qe(t.openingElement.attributes,e),o=ae(t.children,e);if(r){let a=Ze(t.openingElement.attributes);return{kind:"component",name:n,props:i,children:o,...a?{load:a}:{}}}return{kind:"element",tag:n,svg:ce.has(n),props:i,children:o,static:!1}}function Ze(t){for(let e of t){if(!p.types.isJSXAttribute(e))continue;let n=O(e.name);if(J(n)){if(e.value&&!p.types.isStringLiteral(e.value))throw new h(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return w(n,e.value?e.value.value:null)}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-ir.d.ts","sourceRoot":"","sources":["../../../src/frontend/babel/build-ir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,KAAK,IAAI,CAAC,EAAsB,MAAM,aAAa,CAAC;AAW7D,OAAO,KAAK,EACV,MAAM,EAGP,MAAM,mBAAmB,CAAC;AAgD3B,yEAAyE;AACzE,wBAAgB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAErE;AAED,eAAO,MAAM,QAAQ,aAGnB,CAAC;AA2BH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,GAAG,OAAO,CA+B1D;
|
|
1
|
+
{"version":3,"file":"build-ir.d.ts","sourceRoot":"","sources":["../../../src/frontend/babel/build-ir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,KAAK,IAAI,CAAC,EAAsB,MAAM,aAAa,CAAC;AAW7D,OAAO,KAAK,EACV,MAAM,EAGP,MAAM,mBAAmB,CAAC;AAgD3B,yEAAyE;AACzE,wBAAgB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAErE;AAED,eAAO,MAAM,QAAQ,aAGnB,CAAC;AA2BH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,GAAG,OAAO,CA+B1D;AA2FD,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgBlD;AA2BD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,WAAW,EAAE,IAAI,GAAE,GAAG,CAAC,MAAM,CAAa,GAAG,MAAM,CAMjG"}
|
|
@@ -137,8 +137,11 @@ export function isReactiveExpr(node) {
|
|
|
137
137
|
function buildAttr(attr, used) {
|
|
138
138
|
const name = attrName(attr.name);
|
|
139
139
|
const isEvent = EVENT_RE.test(name);
|
|
140
|
-
// on: passes through to the runtime as a native listener; a handler, never reactive
|
|
141
|
-
|
|
140
|
+
// on: passes through to the runtime as a native listener; a handler, never reactive.
|
|
141
|
+
// `ref` joins them: the runtime CALLS it with the element, so wrapping it in a thunk
|
|
142
|
+
// means the thunk gets called and the real ref never sees the element — the callback
|
|
143
|
+
// silently does nothing, along with everything that depended on it.
|
|
144
|
+
const isHandler = isEvent || name.startsWith('on:') || name === 'ref';
|
|
142
145
|
const kind = isEvent ? 'event' : 'attr';
|
|
143
146
|
const base = { name, kind };
|
|
144
147
|
if (isEvent) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{types as p,traverse as Pe,template as Je}from"@babel/core";import te from"@babel/generator";var se=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),O={className:"class",htmlFor:"for"},oe=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),ae=new Set(["script","style","textarea","title"]);function T(t){return ae.has(t)}function _(t){return O[t]??t}function v(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!oe.has(t.name)}function C(t){if(!t.static||T(t.tag))return!1;for(let e of t.props)if(!v(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&C(e)))return!1;return!0}function x(t){let e=t.props.map(ce).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return se.has(t.tag)?n:`${n}${t.children.map(le).join("")}</${t.tag}>`}function le(t){if(t.kind==="text")return ue(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return x(t)}function ce(t){let e=O[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 ue(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var de="<!--fx-->",me="<!--fx/-->";function b(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function fe(t){return t.kind==="text"||t.kind==="element"&&M(t)}function M(t){return t.svg||T(t.tag)||!t.props.every(e=>v(e))?!1:t.children.every(e=>fe(e)||b(e))}function S(t){if(b(t))return!0;let e=t.children;return e?e.some(S):!1}function B(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"||B(e))}function H(t){if(!M(t)||!B(t)||!t.children.some(S))return null;let e=[],n=[],r=0,i=a=>{let s=`_n$${r++}`;return e.push({ref:s,expr:a}),s};return o(t,"_el$"),{html:he(t),tag:t.tag,steps:e,holes:n};function o(a,s){let l=-1;a.children.forEach((u,d)=>{S(u)&&(l=d)});let c=null;for(let u=0;u<=l;u++){let d=a.children[u],g=c?`${c}.nextSibling`:`${s}.firstChild`;if(b(d)){let D=i(g),j=i(`holeEnd(${D})`);n.push({parentRef:s,startRef:D,endRef:j,node:d}),c=j;continue}let N=i(g);d.kind==="element"&&S(d)&&o(d,N),c=N}}}function he(t){return x(F(t)).split(z).join(de+me)}function F(t){return{...t,children:t.children.map(e=>b(e)?{kind:"text",value:z}:e.kind==="element"?F(e):e)}}var z="\0fx-hole\0";var A={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Ue={version:2,module:"@fluixi/dom",symbols:[...A.symbols,"template","cloneTemplate","walk"]};var ge={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function ve(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function W(t){return ve(t)?t:JSON.stringify(t)}function xe(t){return t.expr!==void 0?t.reactive?`() => (${t.expr})`:`(${t.expr})`:JSON.stringify(t.literal??!0)}function ke(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function Ee(t,e,n){let r=t.filter(s=>s.kind==="spread"),o=t.filter(s=>s.kind!=="spread").map(s=>`${W(s.name)}: ${xe(s)}`);e!=null&&o.push(`children: ${e}`);let a=`{ ${o.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(s=>s.expr).join(", ")}, ${a})`):a}function U(t,e,n){return t.length===1?k(t[0],e,n):`[${t.map(r=>k(r,e,n)).join(", ")}]`}function V(t,e,n,r,i){r.add("createMemo"),r.add("createComponent");let o=e.filter(c=>c.kind==="spread"),s=e.filter(c=>c.kind!=="spread").map(c=>`get ${W(c.name)}() { return ${ke(c)}; }`);n.length>0&&s.push(`get children() { return ${U(n,r,i)}; }`);let l=`{ ${s.join(", ")} }`;return o.length>0&&(r.add("mergeProps"),l=`mergeProps(${o.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${t}, ${l}))`}function Re(t,e){let n=_(e.name),r=e.literal;return r===!0||r===void 0?`${t}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${t}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var G=!1;function k(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":U(t.children,e,n);case"component":return V(t.name,t.props,t.children,e,n);case"control":{let r=ge[t.control]??t.control;return e.add(r),V(r,t.props,t.children,e,n)}case"element":{if(n&&t.static&&!t.svg&&C(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;return n.push({id:s,html:x(t),tag:t.tag,svg:!1}),`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&G){let s=H(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 u of s.steps)c.push(`const ${u.ref} = ${u.expr};`);for(let u of s.holes)c.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${k(u.node,e,n)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let r=JSON.stringify(t.tag),i="_el$",o=[],a=t.svg?`${r}, true`:r;if(o.push(`const ${i} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every(v))for(let s of t.props)o.push(Re(i,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";o.push(`spread({ element: ${i}, props: ${Ee(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let l=k(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";o.push(c?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return o.push(`return ${i};`),`(() => { ${o.join(" ")} })()`}}}function E(t,e){if(!e||e.length===0)return t;let n=new Map(e.map(r=>[r.id,JSON.stringify(r.html)]));return t.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var R={name:"imperative",contract:A,emit(t,e){let n=new Set,r=e?.templateClone!==!1?[]:void 0;return G=e?.partialTemplates===!0,{code:k(t,n,r),imports:Array.from(n),templates:r}}};import{types as I}from"@babel/core";import q from"@babel/generator";import{parseTemplate as ye}from"@fluixi/template-parser";var Ne={kind:"eager"},Se=["pointerdown","focusin","keydown"],K=new Set(["eager","idle","visible","interaction","media","never"]),f=class extends Error{};function P(t){return t.startsWith("load:")}function y(t,e){let n=t.slice(5);if(!K.has(n))throw new f(`Unknown load strategy 'load:${n}'. Expected one of ${[...K].join(", ")}.`);switch(n){case"eager":return Ne;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):[...Se]};case"media":if(!e)throw new f(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new f(`Unhandled load strategy '${n}'.`)}}function be(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new f("'load:interaction' was given no event names.");return e}var Ie=q.default??q;function $e(t){return Ie(t,{concise:!0}).code}var Z=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function we(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Y(t){return t.charAt(0).toUpperCase()+t.slice(1)}var J=class{constructor(e,n){this.holes=e;this.used=n}hole(e){return this.holes[e]??{node:I.identifier("undefined"),code:"undefined",reactive:!1}}emit(e){let{code:n,imports:r,templates:i}=R.emit(e,{});for(let o of r)this.used.add(o);return E(n,i)}lowerRoot(e){let n=this.lowerChildren(e);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.kind==="Element"||i.kind==="Component"){let a=i.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=r+1;s<e.length&&this.isBlankText(e[s])&&s++;let l=e[s],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(u=>u.kind==="ElseDirective");n.push(this.lowerIf(i,a.hole,c?l:null)),c&&(r=s);continue}if(i.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(i));continue}}let o=this.lowerNode(i);o&&n.push(o)}return n}isBlankText(e){return e.kind==="Text"&&!e.raw&&$(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=$(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(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=e.attributes.filter(o=>o!==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}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,r=this.lowerAttributes(e.attributes),{slots:i,rest:o}=this.partitionSlots(e.children);for(let[l,c]of i){let u=c.length===1?c[0]:{kind:"fragment",children:c},d={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},g=r.findIndex(N=>N.name===l);g>=0?r[g]=d:r.push(d)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?y(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:r,children:this.lowerChildren(o),...s?{load:s}:{}}}partitionSlots(e){let n=new Map,r=[];for(let i of e){if(i.kind==="Element"||i.kind==="Component"){let o=i.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(o&&o.value&&o.value.kind==="static"){let a={...i,attributes:i.attributes.filter(c=>c!==o)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),l=n.get(o.value.value)??[];l.push(s),n.set(o.value.value,l);continue}}r.push(i)}return{slots:n,rest:r}}lowerIf(e,n,r){let i=this.hole(n),o=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive}];if(r){let s=this.stripAndLower(r,l=>l.kind==="ElseDirective");o.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:o,children:[a]}}lowerEach(e){let n=e.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(e);let r=this.hole(n.hole),i=[{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;i.push({name:"by",kind:"attr",expr:l})}let o=this.itemArrow(e),a;if(o){let l=o.body,c={kind:"expr",code:h(l,this.used),reactive:m(l)},u=this.rebuildWithChildren(e,[c]);a=`(${o.params.map(d=>$e(d)).join(", ")}) => (${this.emit(u)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");a=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:i,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(e){let n=e.children.filter(i=>!this.isBlankText(i));if(n.length!==1||n[0].kind!=="Expression")return null;let r=this.hole(n[0].hole).node;return I.isArrowFunctionExpression(r)&&!I.isBlockStatement(r.body)?r:null}stripAndLower(e,n){let r={...e,attributes:e.attributes.filter(i=>!n(i))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(e,n){let r=this.lowerAttributes(e.attributes.filter(i=>i.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:r,children:n,static:!1}:{kind:"component",name:e.tag,props:r,children:n}}lowerAttributes(e){let n=[],r=[],i=!1,o=[],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);r.push(`${JSON.stringify(l.name)}: ${c.code}`),i=i||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);o.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 r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:i}),o.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:a}),s.length>0&&n.push({name:"use",kind:"attr",expr:`[${s.join(", ")}]`}),n}eventProp(e){let n=e.name.toLowerCase(),r=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+Y(e.name),kind:"event",event:{name:n,delegated:Z.has(n)},expr:r};let o=this.wrapHandler(r,e.modifiers),a=this.eventOptions(e.modifiers),s=a?`[${o}, ${a}]`:o;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(e,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return n.includes("prevent")&&i.push("e.preventDefault();"),n.includes("stop")&&i.push("e.stopPropagation();"),!r&&i.length===0?e:`(e) => { ${r}${i.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 r=e==="checked",i=r?"change":"input",o=r?"checked":"value",a=`(${n})`;return[{name:e,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+Y(i),kind:"event",event:{name:i,delegated:Z.has(i)},expr:`(e) => ${a}[1](e.target.${o})`}]}plainAttr(e){let n=e.value,r=e.name;e.name==="class"?r=n&&n.kind==="hole"&&I.isObjectExpression(this.hole(n.hole).node)?"classList":"className":e.name==="html"&&(r="innerHTML");let o={name:r,kind:"attr"};if(n==null)return o.literal=!0,o;if(n.kind==="static")return o.literal=n.value,o;if(n.kind==="hole"){let l=this.hole(n.hole);return o.expr=l.code,o.reactive=l.reactive,o}let a=!1,s=n.parts.map(l=>{if("text"in l)return we(l.text);let c=this.hole(l.hole);return a=a||c.reactive,"${"+c.code+"}"}).join("");return o.expr="`"+s+"`",o.reactive=a,o}};function Q(t,e,n={}){let r=t.quasi,i=r.expressions.map(s=>{let l=s;return{node:l,code:h(l,e),reactive:m(l)}}),o=Te(r),{root:a}=ye(o,{svg:n.svg});return new J(i,e).lowerRoot(a.children)}function Te(t){let e=[];return t.quasis.forEach((n,r)=>{let i=n.value.cooked??n.value.raw;if(e.push({kind:"static",text:i,start:n.start??0}),r<t.expressions.length){let o=t.expressions[r];e.push({kind:"hole",index:r,start:o.start??0,end:o.end??0})}}),e}function Ce(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 w(t){let e=[],n=new Map,r=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let o of i.children)r(o);return!1;case"fragment":for(let o of i.children)r(o);return!1;case"element":{let o=!0;for(let s of i.children)r(s)||(o=!1);let a;for(let s of i.props)if(a=Ce(s),a)break;return!a&&!o&&(a=Ae(i)),i.static=!a,a?n.set(i,a):e.push(i),i.static}default:return!1}};for(let i of Array.isArray(t)?t:[t])r(i);return{staticElements:e,reasons:n}}function Ae(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"}function ee(t,e=new Set,n={}){let r=Q(t,e,n);return w(r),r}var Le=te.default??te;function ie(t){return Le(t,{concise:!0}).code}function Xe(t,e){let n=p.cloneNode(t,!0),r=p.file(p.program([p.expressionStatement(n)])),i=!1,o=(a,s,l)=>{for(let c of l)e.add(c);a.replaceWith(Je.expression(s,{placeholderPattern:!1,plugins:["typescript"]})()),a.skip(),i=!0};return Pe(r,{"JSXElement|JSXFragment"(a){let s=a.node,{code:l,imports:c,templates:u}=R.emit(He(s,e),{});o(a,E(l,u),c)},TaggedTemplateExpression(a){let s=a.node.tag;if(!p.isIdentifier(s)||s.name!=="html"&&s.name!=="svg")return;let l=ee(a.node,e,{svg:s.name==="svg"}),{code:c,imports:u,templates:d}=R.emit(l,{});o(a,E(c,d),u)}}),i?r.program.body[0].expression:t}function h(t,e){return ie(Xe(t,e))}var De=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),je=/^on[A-Z]/,Oe=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function _e(t){if(p.isJSXIdentifier(t)){let e=t.name[0]!==t.name[0].toLowerCase();return{tag:t.name,component:e}}return p.isJSXMemberExpression(t)?{tag:ie(t),component:!0}:p.isJSXNamespacedName(t)?{tag:`${t.namespace.name}:${t.name.name}`,component:!1}:{tag:"div",component:!1}}function X(t){return p.isJSXIdentifier(t)?t.name==="class"?"className":t.name:p.isJSXNamespacedName(t)?`${t.namespace.name}:${t.name.name}`:"unknown"}function m(t){return p.isCallExpression(t)||p.isOptionalCallExpression(t)?!0:p.isMemberExpression(t)||p.isOptionalMemberExpression(t)?!(!t.computed&&p.isIdentifier(t.property,{name:"children"})):p.isConditionalExpression(t)?m(t.test)||m(t.consequent)||m(t.alternate):p.isLogicalExpression(t)||p.isBinaryExpression(t)?m(t.left)||m(t.right):p.isTemplateLiteral(t)?t.expressions.some(e=>m(e)):p.isObjectExpression(t)?t.properties.some(e=>p.isObjectProperty(e)&&!e.computed&&m(e.value)):p.isArrayExpression(t)?t.elements.some(e=>e!=null&&!p.isSpreadElement(e)&&m(e)):!1}function Me(t,e){let n=X(t.name),r=je.test(n),i=r||n.startsWith("on:"),a={name:n,kind:r?"event":"attr"};r&&(a.event={name:n.slice(2).toLowerCase(),delegated:Oe.has(n.slice(2).toLowerCase())});let s=t.value;if(s==null)return a.literal=!0,a;if(p.isStringLiteral(s))return a.literal=s.value,a;if(p.isJSXExpressionContainer(s)&&!p.isJSXEmptyExpression(s.expression)){let l=s.expression;return p.isStringLiteral(l)||p.isNumericLiteral(l)||p.isBooleanLiteral(l)?(a.literal=l.value,a):(a.expr=h(l,e),a.reactive=i?!1:m(l),(p.isJSXElement(l)||p.isJSXFragment(l))&&(a.jsxElement=!0),a)}return a.literal=!0,a}function ne(t,e){let n=t.value;return n==null?null:p.isStringLiteral(n)?JSON.stringify(n.value):p.isJSXExpressionContainer(n)&&!p.isJSXEmptyExpression(n.expression)?h(n.expression,e):null}function Be(t,e){let n=[],r=[];for(let i of t){if(p.isJSXSpreadAttribute(i)){n.push({name:"",kind:"spread",expr:h(i.argument,e)});continue}if(!p.isJSXAttribute(i)||P(X(i.name)))continue;let o=p.isJSXNamespacedName(i.name)?i.name.namespace.name:null;if(o==="use"){let a=i.name.name.name;e.add(a);let s=ne(i,e);r.push(s!=null?`[${a}, () => (${s})]`:`[${a}]`);continue}if(o==="oncapture"){let a=i.name.name.name.toLowerCase(),s=ne(i,e)??"undefined";n.push({name:"on:"+a,kind:"attr",expr:`[${s}, { capture: true }]`});continue}n.push(Me(i,e))}return r.length>0&&n.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),n}function $(t){let e=t.split(/\r\n|\n|\r/),n=0;for(let i=0;i<e.length;i++)/[^ \t]/.test(e[i])&&(n=i);let r="";for(let i=0;i<e.length;i++){let o=e[i].replace(/\t/g," ");i!==0&&(o=o.replace(/^ +/,"")),i!==e.length-1&&(o=o.replace(/ +$/,"")),o&&(i!==n&&(o+=" "),r+=o)}return r}function re(t,e){let n=[];for(let r of t)if(p.isJSXText(r)){let i=$(r.value);i&&n.push({kind:"text",value:i})}else if(p.isJSXExpressionContainer(r)){if(!p.isJSXEmptyExpression(r.expression)){let i=r.expression;n.push({kind:"expr",code:h(i,e),reactive:m(i)})}}else p.isJSXElement(r)||p.isJSXFragment(r)?n.push(L(r,e)):p.isJSXSpreadChild(r)&&n.push({kind:"expr",code:h(r.expression,e),reactive:!1});return n}function He(t,e=new Set){let n=L(t,e);return w(n),n}function L(t,e){if(p.isJSXFragment(t))return{kind:"fragment",children:re(t.children,e)};let{tag:n,component:r}=_e(t.openingElement.name),i=Be(t.openingElement.attributes,e),o=re(t.children,e);if(r){let a=Fe(t.openingElement.attributes);return{kind:"component",name:n,props:i,children:o,...a?{load:a}:{}}}return{kind:"element",tag:n,svg:De.has(n),props:i,children:o,static:!1}}function Fe(t){for(let e of t){if(!p.isJSXAttribute(e))continue;let n=X(e.name);if(P(n)){if(e.value&&!p.isStringLiteral(e.value))throw new f(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return y(n,e.value?e.value.value:null)}}}export{De as SVG_TAGS,He as buildIR,$ as cleanJSXText,h as genExpr,m as isReactiveExpr};
|
|
1
|
+
import{types as p,traverse as Pe,template as Je}from"@babel/core";import te from"@babel/generator";var se=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),O={className:"class",htmlFor:"for"},oe=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),ae=new Set(["script","style","textarea","title"]);function T(t){return ae.has(t)}function _(t){return O[t]??t}function v(t){return t.kind!=="attr"||t.expr!==void 0||t.name.includes(":")?!1:!oe.has(t.name)}function C(t){if(!t.static||T(t.tag))return!1;for(let e of t.props)if(!v(e))return!1;for(let e of t.children)if(e.kind!=="text"&&!(e.kind==="element"&&C(e)))return!1;return!0}function x(t){let e=t.props.map(ce).filter(Boolean).join(""),n=`<${t.tag}${e}>`;return se.has(t.tag)?n:`${n}${t.children.map(le).join("")}</${t.tag}>`}function le(t){if(t.kind==="text")return ue(t.value);if(t.kind!=="element")throw new Error(`serializeStatic: unexpected ${t.kind}`);return x(t)}function ce(t){let e=O[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 ue(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var de="<!--fx-->",me="<!--fx/-->";function b(t){return t.kind==="expr"||t.kind==="component"||t.kind==="control"}function fe(t){return t.kind==="text"||t.kind==="element"&&M(t)}function M(t){return t.svg||T(t.tag)||!t.props.every(e=>v(e))?!1:t.children.every(e=>fe(e)||b(e))}function S(t){if(b(t))return!0;let e=t.children;return e?e.some(S):!1}function B(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"||B(e))}function H(t){if(!M(t)||!B(t)||!t.children.some(S))return null;let e=[],n=[],r=0,i=a=>{let s=`_n$${r++}`;return e.push({ref:s,expr:a}),s};return o(t,"_el$"),{html:he(t),tag:t.tag,steps:e,holes:n};function o(a,s){let l=-1;a.children.forEach((u,d)=>{S(u)&&(l=d)});let c=null;for(let u=0;u<=l;u++){let d=a.children[u],g=c?`${c}.nextSibling`:`${s}.firstChild`;if(b(d)){let D=i(g),j=i(`holeEnd(${D})`);n.push({parentRef:s,startRef:D,endRef:j,node:d}),c=j;continue}let N=i(g);d.kind==="element"&&S(d)&&o(d,N),c=N}}}function he(t){return x(F(t)).split(z).join(de+me)}function F(t){return{...t,children:t.children.map(e=>b(e)?{kind:"text",value:z}:e.kind==="element"?F(e):e)}}var z="\0fx-hole\0";var A={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Ue={version:2,module:"@fluixi/dom",symbols:[...A.symbols,"template","cloneTemplate","walk"]};var ge={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function ve(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function W(t){return ve(t)?t:JSON.stringify(t)}function xe(t){return t.expr!==void 0?t.reactive?`() => (${t.expr})`:`(${t.expr})`:JSON.stringify(t.literal??!0)}function ke(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function Ee(t,e,n){let r=t.filter(s=>s.kind==="spread"),o=t.filter(s=>s.kind!=="spread").map(s=>`${W(s.name)}: ${xe(s)}`);e!=null&&o.push(`children: ${e}`);let a=`{ ${o.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(s=>s.expr).join(", ")}, ${a})`):a}function U(t,e,n){return t.length===1?k(t[0],e,n):`[${t.map(r=>k(r,e,n)).join(", ")}]`}function V(t,e,n,r,i){r.add("createMemo"),r.add("createComponent");let o=e.filter(c=>c.kind==="spread"),s=e.filter(c=>c.kind!=="spread").map(c=>`get ${W(c.name)}() { return ${ke(c)}; }`);n.length>0&&s.push(`get children() { return ${U(n,r,i)}; }`);let l=`{ ${s.join(", ")} }`;return o.length>0&&(r.add("mergeProps"),l=`mergeProps(${o.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${t}, ${l}))`}function Re(t,e){let n=_(e.name),r=e.literal;return r===!0||r===void 0?`${t}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${t}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var G=!1;function k(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":U(t.children,e,n);case"component":return V(t.name,t.props,t.children,e,n);case"control":{let r=ge[t.control]??t.control;return e.add(r),V(r,t.props,t.children,e,n)}case"element":{if(n&&t.static&&!t.svg&&C(t)){e.add("templateNode");let s=`_tmpl$${n.length}`;return n.push({id:s,html:x(t),tag:t.tag,svg:!1}),`templateNode(${s}, ${JSON.stringify(t.tag)})`}if(n&&G){let s=H(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 u of s.steps)c.push(`const ${u.ref} = ${u.expr};`);for(let u of s.holes)c.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${k(u.node,e,n)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let r=JSON.stringify(t.tag),i="_el$",o=[],a=t.svg?`${r}, true`:r;if(o.push(`const ${i} = createNativeElement(${a});`),t.props.length>0)if(!t.svg&&t.props.every(v))for(let s of t.props)o.push(Re(i,s));else{e.add("spread");let s=t.svg?", isSVG: true":"";o.push(`spread({ element: ${i}, props: ${Ee(t.props,null,e)}${s} });`)}for(let s of t.children){e.add("insert");let l=k(s,e,n),c=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";o.push(c?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return o.push(`return ${i};`),`(() => { ${o.join(" ")} })()`}}}function E(t,e){if(!e||e.length===0)return t;let n=new Map(e.map(r=>[r.id,JSON.stringify(r.html)]));return t.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var R={name:"imperative",contract:A,emit(t,e){let n=new Set,r=e?.templateClone!==!1?[]:void 0;return G=e?.partialTemplates===!0,{code:k(t,n,r),imports:Array.from(n),templates:r}}};import{types as I}from"@babel/core";import q from"@babel/generator";import{parseTemplate as ye}from"@fluixi/template-parser";var Ne={kind:"eager"},Se=["pointerdown","focusin","keydown"],K=new Set(["eager","idle","visible","interaction","media","never"]),f=class extends Error{};function P(t){return t.startsWith("load:")}function y(t,e){let n=t.slice(5);if(!K.has(n))throw new f(`Unknown load strategy 'load:${n}'. Expected one of ${[...K].join(", ")}.`);switch(n){case"eager":return Ne;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):[...Se]};case"media":if(!e)throw new f(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new f(`Unhandled load strategy '${n}'.`)}}function be(t){let e=t.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(e.length===0)throw new f("'load:interaction' was given no event names.");return e}var Ie=q.default??q;function $e(t){return Ie(t,{concise:!0}).code}var Z=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function we(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Y(t){return t.charAt(0).toUpperCase()+t.slice(1)}var J=class{constructor(e,n){this.holes=e;this.used=n}hole(e){return this.holes[e]??{node:I.identifier("undefined"),code:"undefined",reactive:!1}}emit(e){let{code:n,imports:r,templates:i}=R.emit(e,{});for(let o of r)this.used.add(o);return E(n,i)}lowerRoot(e){let n=this.lowerChildren(e);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.kind==="Element"||i.kind==="Component"){let a=i.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=r+1;s<e.length&&this.isBlankText(e[s])&&s++;let l=e[s],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(u=>u.kind==="ElseDirective");n.push(this.lowerIf(i,a.hole,c?l:null)),c&&(r=s);continue}if(i.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(i));continue}}let o=this.lowerNode(i);o&&n.push(o)}return n}isBlankText(e){return e.kind==="Text"&&!e.raw&&$(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let n=$(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(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=e.attributes.filter(o=>o!==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}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,r=this.lowerAttributes(e.attributes),{slots:i,rest:o}=this.partitionSlots(e.children);for(let[l,c]of i){let u=c.length===1?c[0]:{kind:"fragment",children:c},d={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},g=r.findIndex(N=>N.name===l);g>=0?r[g]=d:r.push(d)}let a=e.attributes.find(l=>l.kind==="LoadDirective"),s=a?y(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:r,children:this.lowerChildren(o),...s?{load:s}:{}}}partitionSlots(e){let n=new Map,r=[];for(let i of e){if(i.kind==="Element"||i.kind==="Component"){let o=i.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(o&&o.value&&o.value.kind==="static"){let a={...i,attributes:i.attributes.filter(c=>c!==o)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),l=n.get(o.value.value)??[];l.push(s),n.set(o.value.value,l);continue}}r.push(i)}return{slots:n,rest:r}}lowerIf(e,n,r){let i=this.hole(n),o=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive}];if(r){let s=this.stripAndLower(r,l=>l.kind==="ElseDirective");o.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:o,children:[a]}}lowerEach(e){let n=e.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(e);let r=this.hole(n.hole),i=[{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;i.push({name:"by",kind:"attr",expr:l})}let o=this.itemArrow(e),a;if(o){let l=o.body,c={kind:"expr",code:h(l,this.used),reactive:m(l)},u=this.rebuildWithChildren(e,[c]);a=`(${o.params.map(d=>$e(d)).join(", ")}) => (${this.emit(u)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");a=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:i,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(e){let n=e.children.filter(i=>!this.isBlankText(i));if(n.length!==1||n[0].kind!=="Expression")return null;let r=this.hole(n[0].hole).node;return I.isArrowFunctionExpression(r)&&!I.isBlockStatement(r.body)?r:null}stripAndLower(e,n){let r={...e,attributes:e.attributes.filter(i=>!n(i))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(e,n){let r=this.lowerAttributes(e.attributes.filter(i=>i.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:r,children:n,static:!1}:{kind:"component",name:e.tag,props:r,children:n}}lowerAttributes(e){let n=[],r=[],i=!1,o=[],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);r.push(`${JSON.stringify(l.name)}: ${c.code}`),i=i||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);o.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 r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:i}),o.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:a}),s.length>0&&n.push({name:"use",kind:"attr",expr:`[${s.join(", ")}]`}),n}eventProp(e){let n=e.name.toLowerCase(),r=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+Y(e.name),kind:"event",event:{name:n,delegated:Z.has(n)},expr:r};let o=this.wrapHandler(r,e.modifiers),a=this.eventOptions(e.modifiers),s=a?`[${o}, ${a}]`:o;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(e,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return n.includes("prevent")&&i.push("e.preventDefault();"),n.includes("stop")&&i.push("e.stopPropagation();"),!r&&i.length===0?e:`(e) => { ${r}${i.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 r=e==="checked",i=r?"change":"input",o=r?"checked":"value",a=`(${n})`;return[{name:e,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+Y(i),kind:"event",event:{name:i,delegated:Z.has(i)},expr:`(e) => ${a}[1](e.target.${o})`}]}plainAttr(e){let n=e.value,r=e.name;e.name==="class"?r=n&&n.kind==="hole"&&I.isObjectExpression(this.hole(n.hole).node)?"classList":"className":e.name==="html"&&(r="innerHTML");let o={name:r,kind:"attr"};if(n==null)return o.literal=!0,o;if(n.kind==="static")return o.literal=n.value,o;if(n.kind==="hole"){let l=this.hole(n.hole);return o.expr=l.code,o.reactive=l.reactive,o}let a=!1,s=n.parts.map(l=>{if("text"in l)return we(l.text);let c=this.hole(l.hole);return a=a||c.reactive,"${"+c.code+"}"}).join("");return o.expr="`"+s+"`",o.reactive=a,o}};function Q(t,e,n={}){let r=t.quasi,i=r.expressions.map(s=>{let l=s;return{node:l,code:h(l,e),reactive:m(l)}}),o=Te(r),{root:a}=ye(o,{svg:n.svg});return new J(i,e).lowerRoot(a.children)}function Te(t){let e=[];return t.quasis.forEach((n,r)=>{let i=n.value.cooked??n.value.raw;if(e.push({kind:"static",text:i,start:n.start??0}),r<t.expressions.length){let o=t.expressions[r];e.push({kind:"hole",index:r,start:o.start??0,end:o.end??0})}}),e}function Ce(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 w(t){let e=[],n=new Map,r=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let o of i.children)r(o);return!1;case"fragment":for(let o of i.children)r(o);return!1;case"element":{let o=!0;for(let s of i.children)r(s)||(o=!1);let a;for(let s of i.props)if(a=Ce(s),a)break;return!a&&!o&&(a=Ae(i)),i.static=!a,a?n.set(i,a):e.push(i),i.static}default:return!1}};for(let i of Array.isArray(t)?t:[t])r(i);return{staticElements:e,reasons:n}}function Ae(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"}function ee(t,e=new Set,n={}){let r=Q(t,e,n);return w(r),r}var Le=te.default??te;function ie(t){return Le(t,{concise:!0}).code}function Xe(t,e){let n=p.cloneNode(t,!0),r=p.file(p.program([p.expressionStatement(n)])),i=!1,o=(a,s,l)=>{for(let c of l)e.add(c);a.replaceWith(Je.expression(s,{placeholderPattern:!1,plugins:["typescript"]})()),a.skip(),i=!0};return Pe(r,{"JSXElement|JSXFragment"(a){let s=a.node,{code:l,imports:c,templates:u}=R.emit(He(s,e),{});o(a,E(l,u),c)},TaggedTemplateExpression(a){let s=a.node.tag;if(!p.isIdentifier(s)||s.name!=="html"&&s.name!=="svg")return;let l=ee(a.node,e,{svg:s.name==="svg"}),{code:c,imports:u,templates:d}=R.emit(l,{});o(a,E(c,d),u)}}),i?r.program.body[0].expression:t}function h(t,e){return ie(Xe(t,e))}var De=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),je=/^on[A-Z]/,Oe=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function _e(t){if(p.isJSXIdentifier(t)){let e=t.name[0]!==t.name[0].toLowerCase();return{tag:t.name,component:e}}return p.isJSXMemberExpression(t)?{tag:ie(t),component:!0}:p.isJSXNamespacedName(t)?{tag:`${t.namespace.name}:${t.name.name}`,component:!1}:{tag:"div",component:!1}}function X(t){return p.isJSXIdentifier(t)?t.name==="class"?"className":t.name:p.isJSXNamespacedName(t)?`${t.namespace.name}:${t.name.name}`:"unknown"}function m(t){return p.isCallExpression(t)||p.isOptionalCallExpression(t)?!0:p.isMemberExpression(t)||p.isOptionalMemberExpression(t)?!(!t.computed&&p.isIdentifier(t.property,{name:"children"})):p.isConditionalExpression(t)?m(t.test)||m(t.consequent)||m(t.alternate):p.isLogicalExpression(t)||p.isBinaryExpression(t)?m(t.left)||m(t.right):p.isTemplateLiteral(t)?t.expressions.some(e=>m(e)):p.isObjectExpression(t)?t.properties.some(e=>p.isObjectProperty(e)&&!e.computed&&m(e.value)):p.isArrayExpression(t)?t.elements.some(e=>e!=null&&!p.isSpreadElement(e)&&m(e)):!1}function Me(t,e){let n=X(t.name),r=je.test(n),i=r||n.startsWith("on:")||n==="ref",a={name:n,kind:r?"event":"attr"};r&&(a.event={name:n.slice(2).toLowerCase(),delegated:Oe.has(n.slice(2).toLowerCase())});let s=t.value;if(s==null)return a.literal=!0,a;if(p.isStringLiteral(s))return a.literal=s.value,a;if(p.isJSXExpressionContainer(s)&&!p.isJSXEmptyExpression(s.expression)){let l=s.expression;return p.isStringLiteral(l)||p.isNumericLiteral(l)||p.isBooleanLiteral(l)?(a.literal=l.value,a):(a.expr=h(l,e),a.reactive=i?!1:m(l),(p.isJSXElement(l)||p.isJSXFragment(l))&&(a.jsxElement=!0),a)}return a.literal=!0,a}function ne(t,e){let n=t.value;return n==null?null:p.isStringLiteral(n)?JSON.stringify(n.value):p.isJSXExpressionContainer(n)&&!p.isJSXEmptyExpression(n.expression)?h(n.expression,e):null}function Be(t,e){let n=[],r=[];for(let i of t){if(p.isJSXSpreadAttribute(i)){n.push({name:"",kind:"spread",expr:h(i.argument,e)});continue}if(!p.isJSXAttribute(i)||P(X(i.name)))continue;let o=p.isJSXNamespacedName(i.name)?i.name.namespace.name:null;if(o==="use"){let a=i.name.name.name;e.add(a);let s=ne(i,e);r.push(s!=null?`[${a}, () => (${s})]`:`[${a}]`);continue}if(o==="oncapture"){let a=i.name.name.name.toLowerCase(),s=ne(i,e)??"undefined";n.push({name:"on:"+a,kind:"attr",expr:`[${s}, { capture: true }]`});continue}n.push(Me(i,e))}return r.length>0&&n.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),n}function $(t){let e=t.split(/\r\n|\n|\r/),n=0;for(let i=0;i<e.length;i++)/[^ \t]/.test(e[i])&&(n=i);let r="";for(let i=0;i<e.length;i++){let o=e[i].replace(/\t/g," ");i!==0&&(o=o.replace(/^ +/,"")),i!==e.length-1&&(o=o.replace(/ +$/,"")),o&&(i!==n&&(o+=" "),r+=o)}return r}function re(t,e){let n=[];for(let r of t)if(p.isJSXText(r)){let i=$(r.value);i&&n.push({kind:"text",value:i})}else if(p.isJSXExpressionContainer(r)){if(!p.isJSXEmptyExpression(r.expression)){let i=r.expression;n.push({kind:"expr",code:h(i,e),reactive:m(i)})}}else p.isJSXElement(r)||p.isJSXFragment(r)?n.push(L(r,e)):p.isJSXSpreadChild(r)&&n.push({kind:"expr",code:h(r.expression,e),reactive:!1});return n}function He(t,e=new Set){let n=L(t,e);return w(n),n}function L(t,e){if(p.isJSXFragment(t))return{kind:"fragment",children:re(t.children,e)};let{tag:n,component:r}=_e(t.openingElement.name),i=Be(t.openingElement.attributes,e),o=re(t.children,e);if(r){let a=Fe(t.openingElement.attributes);return{kind:"component",name:n,props:i,children:o,...a?{load:a}:{}}}return{kind:"element",tag:n,svg:De.has(n),props:i,children:o,static:!1}}function Fe(t){for(let e of t){if(!p.isJSXAttribute(e))continue;let n=X(e.name);if(P(n)){if(e.value&&!p.isStringLiteral(e.value))throw new f(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return y(n,e.value?e.value.value:null)}}}export{De as SVG_TAGS,He as buildIR,$ as cleanJSXText,h as genExpr,m as isReactiveExpr};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var It=Object.create;var re=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var kt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Mt=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},Xe=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Nt(t))!Lt.call(e,i)&&i!==n&&re(e,i,{get:()=>t[i],enumerable:!(o=wt(t,i))||o.enumerable});return e};var $e=(e,t,n)=>(n=e!=null?It(kt(e)):{},Xe(t||!e||!e.__esModule?re(n,"default",{value:e,enumerable:!0}):n,e)),Jt=e=>Xe(re({},"__esModule",{value:!0}),e);var Bn={};Mt(Bn,{babelPluginReactiveJSX:()=>Fn,createPlugin:()=>Dn,createPreset:()=>me,default:()=>z,presets:()=>_n});module.exports=Jt(Bn);var ct=require("@babel/helper-plugin-utils");var Tt=e=>"components"in e;function Ae(e,t){return e.replace(/\$(\d+)/g,(n,o)=>t[Number(o)]??n)}function Pt(e,t){return typeof t=="string"?{module:t,export:e}:t}function je(e=[]){let t=new Map,n=[],o=[];for(let a of e){if(!Tt(a)){o.push(a);continue}for(let[l,c]of Object.entries(a.components)){let p=Pt(l,c),f=t.get(l);if(f&&f.module!==p.module){let u=n.find(h=>h.name===l);u?u.modules.push(p.module):n.push({name:l,modules:[f.module,p.module]});continue}t.set(l,p)}}let i=new Map;return{resolve:a=>{if(i.has(a))return i.get(a);let l=t.get(a);if(!l)for(let c of o){let p=a.match(new RegExp(c.match.source,c.match.flags.replace("g","")));if(p){l={module:Ae(c.module,p),export:c.export?Ae(c.export,p):a};break}}return i.set(a,l),l},names:()=>[...t.keys()],conflicts:()=>n}}var U=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],D=["Suspense","SuspenseList","Await"],_=["Router","Outlet","Redirect","Link"],Wn=[...U,...D,..._],fe=new Set([...U,...D]);function Oe(e={}){let{controlFlowModule:t="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:o="@fluixi/core/router-next"}=e,i={};for(let s of U)i[s]=t;for(let s of D)i[s]=n;for(let s of _)i[s]=o;return i}var j={kind:"eager"},Xt=["pointerdown","focusin","keydown"],Fe=new Set(["eager","idle","visible","interaction","media","never"]),J=class extends Error{};function q(e){return e.startsWith("load:")}function B(e,t){let n=e.slice(5);if(!Fe.has(n))throw new J(`Unknown load strategy 'load:${n}'. Expected one of ${[...Fe].join(", ")}.`);switch(n){case"eager":return j;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?$t(t):[...Xt]};case"media":if(!t)throw new J(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new J(`Unhandled load strategy '${n}'.`)}}function $t(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new J("'load:interaction' was given no event names.");return t}function X(e){return e.kind!=="eager"&&e.kind!=="never"}function ge(e,t={}){let{resolver:n,isBound:o,modules:i,strategyFor:s}=t,a=Oe(i),l=new Map,c=new Set,p=u=>{let{name:h}=u;if(!h||h.includes(".")||o?.(h))return;let y=f(h);if(!y){c.add(h);return}let C=y.origin==="builtin"&&fe.has(h)?j:s?.(u)??j;u.source={...y,loading:C},l.set(h,u.source)},f=u=>{if(fe.has(u))return{module:a[u],export:u,origin:"builtin"};let h=n?.resolve(u);if(h)return{module:h.module,export:h.export,origin:"rule"};if(_.includes(u))return{module:a[u],export:u,origin:"builtin"}};return ie(e,u=>{u.kind==="component"&&p(u)}),{resolved:l,unresolved:[...c]}}function ie(e,t){let n=Array.isArray(e)?e:[e];for(let o of n){t(o);let i=o.children;i&&ie(i,t)}}function he(e){let t=[];ie(e,s=>{s.kind==="component"&&s.source&&t.push(s)});let n=new Set,o=new Set;for(let s of t){let{module:a,loading:l}=s.source;l.kind==="eager"&&n.add(a),l.kind==="never"&&o.add(a)}let i=new Map;for(let s of t){let a=s.source;X(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},i.set(a.module,(i.get(a.module)??0)+1))}return{collapsed:i,conflicted:[...o].filter(s=>n.has(s))}}var r=require("@babel/core");var m=require("@babel/core"),ye=$e(require("@babel/generator"),1);var At=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),De={className:"class",htmlFor:"for"},jt=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Ot=new Set(["script","style","textarea","title"]);function Ee(e){return Ot.has(e)}function _e(e){return De[e]??e}function G(e){return e.kind!=="attr"||e.expr!==void 0||e.name.includes(":")?!1:!jt.has(e.name)}function xe(e){if(!e.static||Ee(e.tag))return!1;for(let t of e.props)if(!G(t))return!1;for(let t of e.children)if(t.kind!=="text"&&!(t.kind==="element"&&xe(t)))return!1;return!0}function K(e){let t=e.props.map(Dt).filter(Boolean).join(""),n=`<${e.tag}${t}>`;return At.has(e.tag)?n:`${n}${e.children.map(Ft).join("")}</${e.tag}>`}function Ft(e){if(e.kind==="text")return Bt(e.value);if(e.kind!=="element")throw new Error(`serializeStatic: unexpected ${e.kind}`);return K(e)}function Dt(e){let t=De[e.name]??e.name,n=e.literal;return n===!0||n===void 0?` ${t}`:n===!1||n===null?"":` ${t}="${_t(String(n))}"`}function _t(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Bt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var zt="<!--fx-->",Vt="<!--fx/-->";function se(e){return e.kind==="expr"||e.kind==="component"||e.kind==="control"}function Wt(e){return e.kind==="text"||e.kind==="element"&&Be(e)}function Be(e){return e.svg||Ee(e.tag)||!e.props.every(t=>G(t))?!1:e.children.every(t=>Wt(t)||se(t))}function oe(e){if(se(e))return!0;let t=e.children;return t?t.some(oe):!1}function ze(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"||ze(t))}function Ve(e){if(!Be(e)||!ze(e)||!e.children.some(oe))return null;let t=[],n=[],o=0,i=a=>{let l=`_n$${o++}`;return t.push({ref:l,expr:a}),l};return s(e,"_el$"),{html:Ht(e),tag:e.tag,steps:t,holes:n};function s(a,l){let c=-1;a.children.forEach((f,u)=>{oe(f)&&(c=u)});let p=null;for(let f=0;f<=c;f++){let u=a.children[f],h=p?`${p}.nextSibling`:`${l}.firstChild`;if(se(u)){let C=i(h),I=i(`holeEnd(${C})`);n.push({parentRef:l,startRef:C,endRef:I,node:u}),p=I;continue}let y=i(h);u.kind==="element"&&oe(u)&&s(u,y),p=y}}}function Ht(e){return K(We(e)).split(He).join(zt+Vt)}function We(e){return{...e,children:e.children.map(t=>se(t)?{kind:"text",value:He}:t.kind==="element"?We(t):t)}}var He="\0fx-hole\0";var Se={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},rr={version:2,module:"@fluixi/dom",symbols:[...Se.symbols,"template","cloneTemplate","walk"]};var Ut={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function qt(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function qe(e){return qt(e)?e:JSON.stringify(e)}function Gt(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function Kt(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function Zt(e,t,n){let o=e.filter(l=>l.kind==="spread"),s=e.filter(l=>l.kind!=="spread").map(l=>`${qe(l.name)}: ${Gt(l)}`);t!=null&&s.push(`children: ${t}`);let a=`{ ${s.join(", ")} }`;return o.length>0?(n.add("mergeProps"),`mergeProps(${o.map(l=>l.expr).join(", ")}, ${a})`):a}function Ge(e,t,n){return e.length===1?Z(e[0],t,n):`[${e.map(o=>Z(o,t,n)).join(", ")}]`}function Ue(e,t,n,o,i){o.add("createMemo"),o.add("createComponent");let s=t.filter(p=>p.kind==="spread"),l=t.filter(p=>p.kind!=="spread").map(p=>`get ${qe(p.name)}() { return ${Kt(p)}; }`);n.length>0&&l.push(`get children() { return ${Ge(n,o,i)}; }`);let c=`{ ${l.join(", ")} }`;return s.length>0&&(o.add("mergeProps"),c=`mergeProps(${s.map(p=>p.expr).join(", ")}, ${c})`),`createMemo(() => createComponent(${e}, ${c}))`}function Yt(e,t){let n=_e(t.name),o=t.literal;return o===!0||o===void 0?`${e}.setAttribute(${JSON.stringify(n)}, "");`:o===!1||o===null?"":`${e}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(o))});`}var Ke=!1;function Z(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":Ge(e.children,t,n);case"component":return Ue(e.name,e.props,e.children,t,n);case"control":{let o=Ut[e.control]??e.control;return t.add(o),Ue(o,e.props,e.children,t,n)}case"element":{if(n&&e.static&&!e.svg&&xe(e)){t.add("templateNode");let l=`_tmpl$${n.length}`;return n.push({id:l,html:K(e),tag:e.tag,svg:!1}),`templateNode(${l}, ${JSON.stringify(e.tag)})`}if(n&&Ke){let l=Ve(e);if(l){t.add("templateNode"),t.add("insert"),t.add("holeEnd"),t.add("holeContent"),t.add("holeScope");let c=`_tmpl$${n.length}`;n.push({id:c,html:l.html,tag:l.tag,svg:!1});let p=[`const _el$ = templateNode(${c}, ${JSON.stringify(l.tag)}, true);`];for(let f of l.steps)p.push(`const ${f.ref} = ${f.expr};`);for(let f of l.holes)p.push(`insert(${f.parentRef}, holeScope(${f.startRef}, () => (${Z(f.node,t,n)})), ${f.endRef}, holeContent(${f.startRef}, ${f.endRef}));`);return p.push("return _el$;"),`(() => { ${p.join(" ")} })()`}}t.add("createNativeElement");let o=JSON.stringify(e.tag),i="_el$",s=[],a=e.svg?`${o}, true`:o;if(s.push(`const ${i} = createNativeElement(${a});`),e.props.length>0)if(!e.svg&&e.props.every(G))for(let l of e.props)s.push(Yt(i,l));else{t.add("spread");let l=e.svg?", isSVG: true":"";s.push(`spread({ element: ${i}, props: ${Zt(e.props,null,t)}${l} });`)}for(let l of e.children){t.add("insert");let c=Z(l,t,n),p=l.kind==="expr"&&l.reactive||l.kind==="component"||l.kind==="control";s.push(p?`insert(${i}, ${c}, null);`:`insert(${i}, ${c});`)}return s.push(`return ${i};`),`(() => { ${s.join(" ")} })()`}}}function Y(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(o=>[o.id,JSON.stringify(o.html)]));return e.replace(/_tmpl\$\d+/g,o=>n.get(o)??o)}var $={name:"imperative",contract:Se,emit(e,t){let n=new Set,o=t?.templateClone!==!1?[]:void 0;return Ke=t?.partialTemplates===!0,{code:Z(e,n,o),imports:Array.from(n),templates:o}}};var Q=require("@babel/core"),ve=$e(require("@babel/generator"),1),Qe=require("@fluixi/template-parser");var Qt=ve.default.default??ve.default;function en(e){return Qt(e,{concise:!0}).code}var Ze=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function tn(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Ye(e){return e.charAt(0).toUpperCase()+e.slice(1)}var be=class{constructor(t,n){this.holes=t;this.used=n}hole(t){return this.holes[t]??{node:Q.types.identifier("undefined"),code:"undefined",reactive:!1}}emit(t){let{code:n,imports:o,templates:i}=$.emit(t,{});for(let s of o)this.used.add(s);return Y(n,i)}lowerRoot(t){let n=this.lowerChildren(t);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(t){let n=[];for(let o=0;o<t.length;o++){let i=t[o];if(i.kind==="Element"||i.kind==="Component"){let a=i.attributes.find(l=>l.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let l=o+1;l<t.length&&this.isBlankText(t[l])&&l++;let c=t[l],p=c&&(c.kind==="Element"||c.kind==="Component")&&c.attributes.some(f=>f.kind==="ElseDirective");n.push(this.lowerIf(i,a.hole,p?c:null)),p&&(o=l);continue}if(i.attributes.some(l=>l.kind==="EachDirective")){n.push(this.lowerEach(i));continue}}let s=this.lowerNode(i);s&&n.push(s)}return n}isBlankText(t){return t.kind==="Text"&&!t.raw&&ae(t.value)===""}lowerNode(t){switch(t.kind){case"Text":{if(t.raw)return{kind:"text",value:t.value};let n=ae(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(o=>o.kind==="Attribute"&&o.name==="is");if(t.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let o=t.attributes.filter(s=>s!==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}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,o=this.lowerAttributes(t.attributes),{slots:i,rest:s}=this.partitionSlots(t.children);for(let[c,p]of i){let f=p.length===1?p[0]:{kind:"fragment",children:p},u={name:c,kind:"attr",expr:this.emit(f),jsxElement:!0},h=o.findIndex(y=>y.name===c);h>=0?o[h]=u:o.push(u)}let a=t.attributes.find(c=>c.kind==="LoadDirective"),l=a?B(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:o,children:this.lowerChildren(s),...l?{load:l}:{}}}partitionSlots(t){let n=new Map,o=[];for(let i of t){if(i.kind==="Element"||i.kind==="Component"){let s=i.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(s&&s.value&&s.value.kind==="static"){let a={...i,attributes:i.attributes.filter(p=>p!==s)},l=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),c=n.get(s.value.value)??[];c.push(l),n.set(s.value.value,c);continue}}o.push(i)}return{slots:n,rest:o}}lowerIf(t,n,o){let i=this.hole(n),s=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive}];if(o){let l=this.stripAndLower(o,c=>c.kind==="ElseDirective");s.push({name:"fallback",kind:"attr",expr:this.emit(l),jsxElement:!0})}let a=this.stripAndLower(t,l=>l.kind==="IfDirective");return{kind:"component",name:"Show",props:s,children:[a]}}lowerEach(t){let n=t.attributes.find(c=>c.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(t);let o=this.hole(n.hole),i=[{name:"each",kind:"attr",expr:o.code,reactive:o.reactive}];if(n.key){let c="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;i.push({name:"by",kind:"attr",expr:c})}let s=this.itemArrow(t),a;if(s){let c=s.body,p={kind:"expr",code:A(c,this.used),reactive:N(c)},f=this.rebuildWithChildren(t,[p]);a=`(${s.params.map(u=>en(u)).join(", ")}) => (${this.emit(f)})`}else{let c=this.stripAndLower(t,p=>p.kind==="EachDirective");a=`() => (${this.emit(c)})`}return{kind:"component",name:"For",props:i,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(t){let n=t.children.filter(i=>!this.isBlankText(i));if(n.length!==1||n[0].kind!=="Expression")return null;let o=this.hole(n[0].hole).node;return Q.types.isArrowFunctionExpression(o)&&!Q.types.isBlockStatement(o.body)?o:null}stripAndLower(t,n){let o={...t,attributes:t.attributes.filter(i=>!n(i))};return o.kind==="Element"?this.lowerElement(o):this.lowerComponent(o)}rebuildWithChildren(t,n){let o=this.lowerAttributes(t.attributes.filter(i=>i.kind!=="EachDirective"));return t.kind==="Element"?{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:o,children:n,static:!1}:{kind:"component",name:t.tag,props:o,children:n}}lowerAttributes(t){let n=[],o=[],i=!1,s=[],a=!1,l=[];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});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});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(c.hole).code});break;case"ClassDirective":{let p=this.hole(c.hole);o.push(`${JSON.stringify(c.name)}: ${p.code}`),i=i||p.reactive;break}case"StyleDirective":{let p=this.hole(c.hole);s.push(`${JSON.stringify(c.name)}: ${p.code}`),a=a||p.reactive;break}case"BindDirective":n.push(...this.bindProps(c.name,this.hole(c.hole).code));break;case"UseDirective":{let p=c.name??(c.hole!=null?this.hole(c.hole).code:null);if(!p)break;l.push(c.name!=null&&c.hole!=null?`[${p}, () => (${this.hole(c.hole).code})]`:`[${p}]`);break}}return o.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:i}),s.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${s.join(", ")} }`,reactive:a}),l.length>0&&n.push({name:"use",kind:"attr",expr:`[${l.join(", ")}]`}),n}eventProp(t){let n=t.name.toLowerCase(),o=this.hole(t.hole).code;if(!(t.syntax==="colon"||t.modifiers.length>0))return{name:"on"+Ye(t.name),kind:"event",event:{name:n,delegated:Ze.has(n)},expr:o};let s=this.wrapHandler(o,t.modifiers),a=this.eventOptions(t.modifiers),l=a?`[${s}, ${a}]`:s;return{name:"on:"+n,kind:"attr",expr:l}}wrapHandler(t,n){let o=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return n.includes("prevent")&&i.push("e.preventDefault();"),n.includes("stop")&&i.push("e.stopPropagation();"),!o&&i.length===0?t:`(e) => { ${o}${i.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 o=t==="checked",i=o?"change":"input",s=o?"checked":"value",a=`(${n})`;return[{name:t,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+Ye(i),kind:"event",event:{name:i,delegated:Ze.has(i)},expr:`(e) => ${a}[1](e.target.${s})`}]}plainAttr(t){let n=t.value,o=t.name;t.name==="class"?o=n&&n.kind==="hole"&&Q.types.isObjectExpression(this.hole(n.hole).node)?"classList":"className":t.name==="html"&&(o="innerHTML");let s={name:o,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 c=this.hole(n.hole);return s.expr=c.code,s.reactive=c.reactive,s}let a=!1,l=n.parts.map(c=>{if("text"in c)return tn(c.text);let p=this.hole(c.hole);return a=a||p.reactive,"${"+p.code+"}"}).join("");return s.expr="`"+l+"`",s.reactive=a,s}};function et(e,t,n={}){let o=e.quasi,i=o.expressions.map(l=>{let c=l;return{node:c,code:A(c,t),reactive:N(c)}}),s=nn(o),{root:a}=(0,Qe.parseTemplate)(s,{svg:n.svg});return new be(i,t).lowerRoot(a.children)}function nn(e){let t=[];return e.quasis.forEach((n,o)=>{let i=n.value.cooked??n.value.raw;if(t.push({kind:"static",text:i,start:n.start??0}),o<e.expressions.length){let s=e.expressions[o];t.push({kind:"hole",index:o,start:s.start??0,end:s.end??0})}}),t}function rn(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 le(e){let t=[],n=new Map,o=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of i.children)o(s);return!1;case"fragment":for(let s of i.children)o(s);return!1;case"element":{let s=!0;for(let l of i.children)o(l)||(s=!1);let a;for(let l of i.props)if(a=rn(l),a)break;return!a&&!s&&(a=on(i)),i.static=!a,a?n.set(i,a):t.push(i),i.static}default:return!1}};for(let i of Array.isArray(e)?e:[e])o(i);return{staticElements:t,reasons:n}}function on(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"}function ce(e,t=new Set,n={}){let o=et(e,t,n);return le(o),o}var sn=ye.default.default??ye.default;function rt(e){return sn(e,{concise:!0}).code}function an(e,t){let n=m.types.cloneNode(e,!0),o=m.types.file(m.types.program([m.types.expressionStatement(n)])),i=!1,s=(a,l,c)=>{for(let p of c)t.add(p);a.replaceWith(m.template.expression(l,{placeholderPattern:!1,plugins:["typescript"]})()),a.skip(),i=!0};return(0,m.traverse)(o,{"JSXElement|JSXFragment"(a){let l=a.node,{code:c,imports:p,templates:f}=$.emit(Ie(l,t),{});s(a,Y(c,f),p)},TaggedTemplateExpression(a){let l=a.node.tag;if(!m.types.isIdentifier(l)||l.name!=="html"&&l.name!=="svg")return;let c=ce(a.node,t,{svg:l.name==="svg"}),{code:p,imports:f,templates:u}=$.emit(c,{});s(a,Y(p,u),f)}}),i?o.program.body[0].expression:e}function A(e,t){return rt(an(e,t))}var ln=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),cn=/^on[A-Z]/,pn=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function un(e){if(m.types.isJSXIdentifier(e)){let t=e.name[0]!==e.name[0].toLowerCase();return{tag:e.name,component:t}}return m.types.isJSXMemberExpression(e)?{tag:rt(e),component:!0}:m.types.isJSXNamespacedName(e)?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function Ce(e){return m.types.isJSXIdentifier(e)?e.name==="class"?"className":e.name:m.types.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:"unknown"}function N(e){return m.types.isCallExpression(e)||m.types.isOptionalCallExpression(e)?!0:m.types.isMemberExpression(e)||m.types.isOptionalMemberExpression(e)?!(!e.computed&&m.types.isIdentifier(e.property,{name:"children"})):m.types.isConditionalExpression(e)?N(e.test)||N(e.consequent)||N(e.alternate):m.types.isLogicalExpression(e)||m.types.isBinaryExpression(e)?N(e.left)||N(e.right):m.types.isTemplateLiteral(e)?e.expressions.some(t=>N(t)):m.types.isObjectExpression(e)?e.properties.some(t=>m.types.isObjectProperty(t)&&!t.computed&&N(t.value)):m.types.isArrayExpression(e)?e.elements.some(t=>t!=null&&!m.types.isSpreadElement(t)&&N(t)):!1}function dn(e,t){let n=Ce(e.name),o=cn.test(n),i=o||n.startsWith("on:"),a={name:n,kind:o?"event":"attr"};o&&(a.event={name:n.slice(2).toLowerCase(),delegated:pn.has(n.slice(2).toLowerCase())});let l=e.value;if(l==null)return a.literal=!0,a;if(m.types.isStringLiteral(l))return a.literal=l.value,a;if(m.types.isJSXExpressionContainer(l)&&!m.types.isJSXEmptyExpression(l.expression)){let c=l.expression;return m.types.isStringLiteral(c)||m.types.isNumericLiteral(c)||m.types.isBooleanLiteral(c)?(a.literal=c.value,a):(a.expr=A(c,t),a.reactive=i?!1:N(c),(m.types.isJSXElement(c)||m.types.isJSXFragment(c))&&(a.jsxElement=!0),a)}return a.literal=!0,a}function tt(e,t){let n=e.value;return n==null?null:m.types.isStringLiteral(n)?JSON.stringify(n.value):m.types.isJSXExpressionContainer(n)&&!m.types.isJSXEmptyExpression(n.expression)?A(n.expression,t):null}function mn(e,t){let n=[],o=[];for(let i of e){if(m.types.isJSXSpreadAttribute(i)){n.push({name:"",kind:"spread",expr:A(i.argument,t)});continue}if(!m.types.isJSXAttribute(i)||q(Ce(i.name)))continue;let s=m.types.isJSXNamespacedName(i.name)?i.name.namespace.name:null;if(s==="use"){let a=i.name.name.name;t.add(a);let l=tt(i,t);o.push(l!=null?`[${a}, () => (${l})]`:`[${a}]`);continue}if(s==="oncapture"){let a=i.name.name.name.toLowerCase(),l=tt(i,t)??"undefined";n.push({name:"on:"+a,kind:"attr",expr:`[${l}, { capture: true }]`});continue}n.push(dn(i,t))}return o.length>0&&n.push({name:"use",kind:"attr",expr:`[${o.join(", ")}]`}),n}function ae(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let i=0;i<t.length;i++)/[^ \t]/.test(t[i])&&(n=i);let o="";for(let i=0;i<t.length;i++){let s=t[i].replace(/\t/g," ");i!==0&&(s=s.replace(/^ +/,"")),i!==t.length-1&&(s=s.replace(/ +$/,"")),s&&(i!==n&&(s+=" "),o+=s)}return o}function nt(e,t){let n=[];for(let o of e)if(m.types.isJSXText(o)){let i=ae(o.value);i&&n.push({kind:"text",value:i})}else if(m.types.isJSXExpressionContainer(o)){if(!m.types.isJSXEmptyExpression(o.expression)){let i=o.expression;n.push({kind:"expr",code:A(i,t),reactive:N(i)})}}else m.types.isJSXElement(o)||m.types.isJSXFragment(o)?n.push(Re(o,t)):m.types.isJSXSpreadChild(o)&&n.push({kind:"expr",code:A(o.expression,t),reactive:!1});return n}function Ie(e,t=new Set){let n=Re(e,t);return le(n),n}function Re(e,t){if(m.types.isJSXFragment(e))return{kind:"fragment",children:nt(e.children,t)};let{tag:n,component:o}=un(e.openingElement.name),i=mn(e.openingElement.attributes,t),s=nt(e.children,t);if(o){let a=fn(e.openingElement.attributes);return{kind:"component",name:n,props:i,children:s,...a?{load:a}:{}}}return{kind:"element",tag:n,svg:ln.has(n),props:i,children:s,static:!1}}function fn(e){for(let t of e){if(!m.types.isJSXAttribute(t))continue;let n=Ce(t.name);if(q(n)){if(t.value&&!m.types.isStringLiteral(t.value))throw new J(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return B(n,t.value?t.value.value:null)}}}var ue=new Set([...U,...D]),it=new Set(D),pe=new Set(_),gn={Show:"when",For:"each",Index:"each",Match:"when"};var pt=/^on[A-Z]/,ut=["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave"],z=(0,ct.declare)((e,t={})=>{e.assertVersion(7);let{runtime:n="automatic",importSource:o="@fluixi/jsx",pragma:i="jsx",pragmaFrag:s="Fragment",development:a=!1,detectReactivity:l=!0,useLitHTML:c=!0,hoistStatics:p=!0,delegateEvents:f=!0,delegatedEvents:u=ut,optimizeControlFlow:h=!0,sourceMaps:y=!0,signalModule:C="@fluixi/dom",controlFlowModule:I="@fluixi/dom",routerModule:V="@fluixi/core/router-next",reactiveModule:P="@fluixi/reactive/signal",autoShowTransform:W=!1,backend:M="imperative",codegen:H="ir",templateClone:Me=!0,partialTemplates:Je=!0,format:Te="both",litTag:bt="html",resolve:yt=[]}=t,Pe=je(yt),Rt=Te==="lit"||Te==="both",Ct={backend:M,codegen:H,irImports:new Set,libModule:"@fluixi/core",controlFlowModule:I,routerModule:V,templateClone:Me,partialTemplates:Je,hasJSX:!1,hasReactivity:!1,hasLitHTML:!1,needsSignalImport:!1,needsControlFlowImport:!1,needsCreateMemo:!1,controlFlowComponents:new Set,resolvedComponents:new Map,deferredComponents:new Map,componentResolver:Pe,delegatedEvents:new Set,staticElements:new Map,staticTemplates:new Map,staticCounter:0};return{name:"@fluixi/babel-plugin-jsx",manipulateOptions(g,d){d.plugins.push("jsx","typescript")},pre(g){Object.assign(g,Ct)},visitor:{ImportDeclaration(g,d){g.node.source.value==="@fluixi/core/rx"&&(g.node.source=r.types.stringLiteral("@fluixi/reactive"))},Program:{enter(g,d){Object.assign(d,{hasJSX:!1,hasReactivity:!1,hasLitHTML:!1,hasLitIR:!1,needsSignalImport:!1,needsControlFlowImport:!1,needsCreateMemo:!1,controlFlowComponents:new Set,resolvedComponents:new Map,deferredComponents:new Map,componentResolver:Pe,delegatedEvents:new Set,staticElements:new Map,staticTemplates:new Map,autoShow:W,staticCounter:0,libModule:"@fluixi/core",controlFlowModule:I,routerModule:V,templateClone:Me,partialTemplates:Je,backend:M,codegen:H,irImports:new Set,needsCreateNativeElement:!1,needsInsert:!1,needsSpread:!1,needsCreateComponent:!1,needsMergeProps:!1})},exit(g,d){let E=[];if(d.hasJSX||d.needsSignalImport&&E.push(r.types.importDeclaration([r.types.importSpecifier(r.types.identifier("signal"),r.types.identifier("signal"))],r.types.stringLiteral(C))),d.hasJSX||d.hasLitIR){if(d.irImports.size>0){let S=new Set(["Show","For","Index","Switch","Match","Dynamic","ErrorBoundary","Portal","Suspense"]),x=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]),v=Array.from(d.irImports),R=b=>r.types.importSpecifier(r.types.identifier(b),r.types.identifier(b)),L=b=>!g.scope.hasBinding(b),F=v.filter(b=>x.has(b)&&L(b)),w=v.filter(b=>!S.has(b)&&!x.has(b)&&L(b)),ne=v.filter(b=>S.has(b)&&L(b));F.length>0&&E.push(r.types.importDeclaration(F.map(R),r.types.stringLiteral(P))),w.length>0&&E.push(r.types.importDeclaration(w.map(R),r.types.stringLiteral(C))),ne.length>0&&E.push(r.types.importDeclaration(ne.map(R),r.types.stringLiteral(I)))}if(d.hasJSX&&M==="imperative"&&H!=="ir"){let x=[[!!d.needsCreateNativeElement,"createNativeElement"],[!!d.needsSpread,"spread"],[!!d.needsInsert,"insert"],[!!d.needsCreateComponent,"createComponent"],[!!d.needsMergeProps,"mergeProps"]].filter(([v,R])=>v&&!g.scope.hasBinding(R)).map(([,v])=>r.types.importSpecifier(r.types.identifier(v),r.types.identifier(v)));x.length>0&&E.push(r.types.importDeclaration(x,r.types.stringLiteral(C)))}else if(d.hasJSX&&n==="automatic"&&M!=="imperative"){let S=[r.types.importSpecifier(r.types.identifier("jsx"),r.types.identifier("jsx")),r.types.importSpecifier(r.types.identifier("jsxs"),r.types.identifier("jsxs")),r.types.importSpecifier(r.types.identifier("Fragment"),r.types.identifier("Fragment"))];a&&S.push(r.types.importSpecifier(r.types.identifier("jsxDEV"),r.types.identifier("jsxDEV"))),d.needsMergeProps&&S.push(r.types.importSpecifier(r.types.identifier("mergeProps"),r.types.identifier("mergeProps"))),E.push(r.types.importDeclaration(S,r.types.stringLiteral(o)))}if(d.needsCreateMemo&&!g.scope.hasBinding("createMemo")&&E.push(r.types.importDeclaration([r.types.importSpecifier(r.types.identifier("createMemo"),r.types.identifier("createMemo"))],r.types.stringLiteral(M==="imperative"?P:d.libModule??"@fluixi/core"))),d.needsControlFlowImport&&d.controlFlowComponents.size>0){let S=Array.from(d.controlFlowComponents).filter(w=>!g.scope.hasBinding(w)),x=d.libModule??"@fluixi/core",v=S.filter(w=>pe.has(w)),R=S.filter(w=>it.has(w)),L=S.filter(w=>!it.has(w)&&!pe.has(w)),F=(w,ne)=>r.types.importDeclaration(w.map(b=>r.types.importSpecifier(r.types.identifier(b),r.types.identifier(b))),r.types.stringLiteral(ne));L.length>0&&E.push(F(L,I)),R.length>0&&E.push(F(R,x)),v.length>0&&E.push(F(v,V))}let k=[];if(d.deferredComponents.size>0){for(let[S,x]of d.deferredComponents)g.scope.hasBinding(S)||k.push(r.types.variableDeclaration("const",[r.types.variableDeclarator(r.types.identifier(S),r.types.callExpression(r.types.identifier("deferred"),[r.types.arrowFunctionExpression([],r.types.callExpression(r.types.import(),[r.types.stringLiteral(x.module)])),r.types.objectExpression([r.types.objectProperty(r.types.identifier("strategy"),vn(x.strategy)),r.types.objectProperty(r.types.identifier("export"),r.types.stringLiteral(x.export))])]))]));k.length>0&&!g.scope.hasBinding("deferred")&&E.push(r.types.importDeclaration([r.types.importSpecifier(r.types.identifier("deferred"),r.types.identifier("deferred"))],r.types.stringLiteral(d.libModule??"@fluixi/core")))}if(d.resolvedComponents.size>0){let S=new Map;for(let[x,v]of d.resolvedComponents){if(g.scope.hasBinding(x))continue;let R=S.get(v.module)??[];R.push({local:x,exported:v.export}),S.set(v.module,R)}for(let[x,v]of S)E.push(r.types.importDeclaration(v.map(({local:R,exported:L})=>L==="default"?r.types.importDefaultSpecifier(r.types.identifier(R)):r.types.importSpecifier(r.types.identifier(R),r.types.identifier(L))),r.types.stringLiteral(x)))}if(f&&d.delegatedEvents.size>0){E.push(r.types.importDeclaration([r.types.importSpecifier(r.types.identifier("delegateEvents"),r.types.identifier("delegateEvents"))],r.types.stringLiteral(M==="imperative"?C:"@fluixi/jsx")));let S=r.types.arrayExpression(Array.from(d.delegatedEvents).map(v=>r.types.stringLiteral(v))),x=r.types.expressionStatement(r.types.callExpression(r.types.identifier("delegateEvents"),[S]));g.node.body.unshift(x)}if(p&&d.staticElements.size>0){let S=[];d.staticElements.forEach((x,v)=>{S.push(r.types.variableDeclaration("const",[r.types.variableDeclarator(r.types.identifier(v),x)]))}),g.node.body.unshift(...S)}if(k.length>0&&g.node.body.unshift(...k),d.staticTemplates.size>0){let S=[];for(let[x,v]of d.staticTemplates){let L=x.startsWith("svg:")?x.slice(4):x;S.push(r.types.variableDeclaration("const",[r.types.variableDeclarator(r.types.identifier(v),r.types.stringLiteral(L))]))}g.node.body.unshift(...S)}}E.length>0&&g.node.body.unshift(...yn(E))}},JSXElement(g,d){if(d.hasJSX=!0,M==="imperative"&&H==="ir"){g.replaceWith(st(g.node,d));return}let E=g.node,k=E.openingElement;if(r.types.isJSXIdentifier(k.name)&&pe.has(k.name.name)&&!d.componentResolver?.resolve(k.name.name)&&(d.controlFlowComponents.add(k.name.name),d.needsControlFlowImport=!0),r.types.isJSXIdentifier(k.name)&&ue.has(k.name.name)&&(d.controlFlowComponents.add(k.name.name),h)){let x=An(E,d);if(x){g.replaceWith(x);return}}if(p&&M!=="imperative"&&vt(E,d)){let x=$n(E,d);if(x){g.replaceWith(x);return}}let S=hn(E,d,{runtime:n,pragma:i,development:a,detectReactivity:l,useLitHTML:c,autoShow:W});g.replaceWith(S)},JSXFragment(g,d){if(d.hasJSX=!0,M==="imperative"&&H==="ir"){g.replaceWith(st(g.node,d));return}let E=de(g.node,d,{runtime:n,pragmaFrag:s,development:a});g.replaceWith(E)},CallExpression(g,d){if(!l)return;let E=g.node.callee;E.name,r.types.isIdentifier(E)&&(E.name==="createSignal"||E.name==="createStore"||E.name==="useContext"||E.name==="useLocation")&&(d.hasReactivity=!0)},JSXExpressionContainer(g){},TaggedTemplateExpression(g,d){if(Rt&&M==="imperative"&&r.types.isIdentifier(g.node.tag)&&(g.node.tag.name===bt||g.node.tag.name==="svg")){g.replaceWith(Rn(g.node,d));return}}}}});function hn(e,t,n){let{runtime:o,pragma:i,development:s,autoShow:a=!0}=n;return o==="automatic"?te(e,t,s,a):wn(e,t,i)}var En=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]);function ot(e,t,n){return t.length>0?(n.needsMergeProps=!0,r.types.callExpression(r.types.identifier("mergeProps"),[...t,r.types.objectExpression(e)])):r.types.objectExpression(e)}function dt(e){return e.length===1?e[0]:r.types.arrayExpression(e)}function xn(e,t,n,o,i,s){if(!t){let u=[...n];return i.length>0&&u.push(r.types.objectMethod("get",r.types.identifier("children"),[],r.types.blockStatement([r.types.returnStatement(dt(i))]))),mt(e,ot(u,o,s),s)}let a=e.value,l=En.has(a),c=r.types.identifier("_el$"),p=[];s.needsCreateNativeElement=!0;let f=[e];if(l&&f.push(r.types.booleanLiteral(!0)),p.push(r.types.variableDeclaration("const",[r.types.variableDeclarator(c,r.types.callExpression(r.types.identifier("createNativeElement"),f))])),n.length>0||o.length>0){s.needsSpread=!0;let u=[r.types.objectProperty(r.types.identifier("element"),c),r.types.objectProperty(r.types.identifier("props"),ot(n,o,s))];l&&u.push(r.types.objectProperty(r.types.identifier("isSVG"),r.types.booleanLiteral(!0))),p.push(r.types.expressionStatement(r.types.callExpression(r.types.identifier("spread"),[r.types.objectExpression(u)])))}if(i.length>0){s.needsInsert=!0;for(let u of i){let y=r.types.isArrowFunctionExpression(u)||r.types.isFunctionExpression(u)||r.types.isCallExpression(u)&&r.types.isIdentifier(u.callee)&&u.callee.name==="createMemo"?[r.types.cloneNode(c),u,r.types.nullLiteral()]:[r.types.cloneNode(c),u];p.push(r.types.expressionStatement(r.types.callExpression(r.types.identifier("insert"),y)))}}return p.push(r.types.returnStatement(c)),r.types.callExpression(r.types.arrowFunctionExpression([],r.types.blockStatement(p)),[])}function Sn(e,t){let n=null;if(t.value)if(r.types.isStringLiteral(t.value))n=t.value.value;else throw new J(`'${e}' needs a literal value, not an expression — the strategy is compile-time.`);return B(e,n)}function vn(e){let t=[r.types.objectProperty(r.types.identifier("kind"),r.types.stringLiteral(e.kind))];return e.kind==="visible"&&e.rootMargin&&t.push(r.types.objectProperty(r.types.identifier("rootMargin"),r.types.stringLiteral(e.rootMargin))),e.kind==="interaction"&&t.push(r.types.objectProperty(r.types.identifier("events"),r.types.arrayExpression(e.events.map(n=>r.types.stringLiteral(n))))),e.kind==="media"&&t.push(r.types.objectProperty(r.types.identifier("query"),r.types.stringLiteral(e.query))),r.types.objectExpression(t)}function bn(e,t){return!X(e)||!X(t)?j:e}function mt(e,t,n){r.types.isIdentifier(e)&&ue.has(e.name)&&(n.controlFlowComponents.add(e.name),n.needsControlFlowImport=!0);let o=!1;if(r.types.isIdentifier(e)&&!ue.has(e.name)&&n.componentResolver){let i=n.componentResolver.resolve(e.name);if(i){let s=n.pendingLoad??j,a=n.resolvedComponents.has(e.name);if(X(s)&&!a){let l=n.deferredComponents.get(e.name),c=l?bn(l.strategy,s):s;X(c)?n.deferredComponents.set(e.name,{...i,strategy:c}):(n.deferredComponents.delete(e.name),n.resolvedComponents.set(e.name,i))}else n.deferredComponents.delete(e.name),n.resolvedComponents.set(e.name,i);o=!0}}return n.pendingLoad=void 0,!o&&r.types.isIdentifier(e)&&pe.has(e.name)&&(n.controlFlowComponents.add(e.name),n.needsControlFlowImport=!0),n.backend==="imperative"?(n.needsCreateComponent=!0,n.needsCreateMemo=!0,r.types.callExpression(r.types.identifier("createMemo"),[r.types.arrowFunctionExpression([],r.types.callExpression(r.types.identifier("createComponent"),[e,t]))])):r.types.callExpression(r.types.identifier("jsx"),[e,t])}function ft(e,t,n){if(!t||t.length===0)return e;let o=new Map;for(let i of t){let s=`${i.svg?"svg:":""}${i.html}`,a=n.staticTemplates.get(s);a||(a=`_tmpl$${n.staticTemplates.size}`,n.staticTemplates.set(s,a)),o.set(i.id,a)}return e.replace(/_tmpl\$\d+/g,i=>o.get(i)??i)}function st(e,t){let n=new Set,o=Ie(e,n);ge(o,{resolver:t.componentResolver,modules:{controlFlowModule:t.controlFlowModule,coreModule:t.libModule,routerModule:t.routerModule},strategyFor:c=>c.load}),he(o);let{code:i,imports:s,templates:a}=$.emit(o,{templateClone:t.templateClone,partialTemplates:t.partialTemplates});for(let c of s)n.add(c);for(let c of n)t.irImports.add(c);Ne(o,t);let l=ft(i,a,t);return r.template.expression(l,{placeholderPattern:!1,plugins:["typescript"]})()}function yn(e){let t=new Map,n=[];for(let o of e){let i=o.source.value;if(!o.specifiers.every(l=>r.types.isImportSpecifier(l))){n.push(o);continue}let a=t.get(i);if(!a){let l=new Set(o.specifiers.map(c=>c.local.name));t.set(i,{decl:o,names:l}),n.push(o);continue}for(let l of o.specifiers)a.names.has(l.local.name)||(a.names.add(l.local.name),a.decl.specifiers.push(l))}return n}function Rn(e,t){let n=new Set,o=r.types.isIdentifier(e.tag)&&e.tag.name==="svg",i=ce(e,n,{svg:o});ge(i,{resolver:t.componentResolver,modules:{controlFlowModule:t.controlFlowModule,coreModule:t.libModule,routerModule:t.routerModule},strategyFor:p=>p.load}),he(i);let{code:s,imports:a,templates:l}=$.emit(i,{templateClone:t.templateClone,partialTemplates:t.partialTemplates});for(let p of a)n.add(p);for(let p of n)t.irImports.add(p);Ne(i,t),t.hasLitIR=!0;let c=r.template.expression(ft(s,l,t),{placeholderPattern:!1,plugins:["typescript"]})();return Cn(c,e),c}function Cn(e,t){if(!t.loc)return;let n=new Set,o=i=>{if(!n.has(i)){n.add(i),i.loc||(i.loc=t.loc,i.start=t.start,i.end=t.end);for(let s of r.types.VISITOR_KEYS[i.type]??[]){let a=i[s];if(Array.isArray(a))for(let l of a)l&&typeof l=="object"&&"type"in l&&o(l);else a&&typeof a=="object"&&"type"in a&&o(a)}}};o(e)}function Ne(e,t){if(e.kind==="component"&&e.source&&(e.source.origin==="builtin"?(t.controlFlowComponents.add(e.name),t.needsControlFlowImport=!0):X(e.source.loading)&&!t.resolvedComponents.has(e.name)?t.deferredComponents.set(e.name,{module:e.source.module,export:e.source.export,strategy:e.source.loading}):(t.deferredComponents.delete(e.name),t.resolvedComponents.set(e.name,{module:e.source.module,export:e.source.export}))),(e.kind==="element"||e.kind==="component"||e.kind==="control")&&"props"in e)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)Ne(n,t)}function In(e){return e.map(t=>{if(r.types.isObjectProperty(t)){let n=t.key,o=t.computed,i=t.value;return r.types.objectMethod("get",n,[],r.types.blockStatement([r.types.returnStatement(i)]),o)}return t})}function te(e,t,n,o=!0){let i=e.openingElement,s=e.children,a=gt(i.name),l=r.types.isJSXIdentifier(i.name)&&/^[a-z]/.test(i.name.name),c=Et(i.attributes,t,l,r.types.isJSXIdentifier(i.name)?i.name.name:""),p=c.props,f=c.spreads;l||(p=In(p));let u=ke(s,t,o);if(t.backend==="imperative")return xn(a,l,p,f,u,t);if(u.length>0){let I=u.length===1?u[0]:r.types.arrayExpression(u);p.push(r.types.objectProperty(r.types.identifier("children"),I))}let h;if(f.length>0){let I=p.length>0?r.types.objectExpression(p):r.types.objectExpression([]);t.needsMergeProps=!0,h=r.types.callExpression(r.types.identifier("mergeProps"),[...f,I])}else h=r.types.objectExpression(p);let y=n?"jsxDEV":u.length>1?"jsxs":"jsx",C=[a,h];return n&&C.push(r.types.identifier("undefined"),r.types.booleanLiteral(!1),r.types.identifier("undefined"),r.types.identifier("undefined")),r.types.callExpression(r.types.identifier(y),C)}function wn(e,t,n){let o=e.openingElement,i=e.children,s=gt(o.name),a=r.types.isJSXIdentifier(o.name)&&/^[a-z]/.test(o.name.name),{props:l,spreads:c}=Et(o.attributes,t,a,r.types.isJSXIdentifier(o.name)?o.name.name:""),p=ke(i,t,t.autoShow??!0),f;if(c.length>0){let h=l.length>0?r.types.objectExpression(l):r.types.objectExpression([]);t.needsMergeProps=!0,f=r.types.callExpression(r.types.identifier("mergeProps"),[...c,h])}else f=l.length>0?r.types.objectExpression(l):r.types.nullLiteral();let u=[s,f,...p];return r.types.callExpression(r.types.identifier(n),u)}function de(e,t,n){let{runtime:o,pragmaFrag:i,development:s}=n,a=ke(e.children,t,t.autoShow??!0);if(t.backend==="imperative")return a.length===0?r.types.nullLiteral():dt(a);if(o==="automatic"){let l=s?"jsxDEV":a.length>1?"jsxs":"jsx",c=r.types.objectExpression([r.types.objectProperty(r.types.identifier("children"),a.length===1?a[0]:r.types.arrayExpression(a))]),p=[r.types.identifier("Fragment"),c];return s&&p.push(r.types.identifier("undefined"),r.types.booleanLiteral(!1),r.types.identifier("undefined"),r.types.identifier("undefined")),r.types.callExpression(r.types.identifier(l),p)}else return r.types.callExpression(r.types.identifier(i),a)}function gt(e){if(r.types.isJSXIdentifier(e)){let t=e.name;return t[0]===t[0].toLowerCase()?r.types.stringLiteral(t):r.types.identifier(t)}return r.types.isJSXMemberExpression(e)?ht(e):r.types.isJSXNamespacedName(e)?r.types.stringLiteral(`${e.namespace.name}:${e.name.name}`):r.types.stringLiteral("div")}function ht(e){let t;return r.types.isJSXIdentifier(e.object)?t=r.types.identifier(e.object.name):t=ht(e.object),r.types.memberExpression(t,r.types.identifier(e.property.name))}function Nn(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)}function Et(e,t,n=!0,o=""){let i=[],s=[],a=gn[o],l=[];t.pendingLoad=void 0;for(let c of e)if(r.types.isJSXSpreadAttribute(c))s.push(c.argument);else if(r.types.isJSXAttribute(c)){let p=kn(c.name);if(q(p)){t.pendingLoad=Sn(p,c);continue}if(r.types.isJSXNamespacedName(c.name)&&c.name.namespace.name==="use"){let P=r.types.identifier(c.name.name.name),W=c.value===null?null:at(c.value,t,p,n);l.push(r.types.arrayExpression(W?[P,r.types.arrowFunctionExpression([],W)]:[P]));continue}let f=at(c.value,t,p,n);if(pt.test(p)){let P=p.slice(2).toLowerCase();ut.includes(P)&&t.delegatedEvents.add(P)}let u=Nn(p)?r.types.identifier(p):r.types.stringLiteral(p),h=c.value,y=r.types.isJSXElement(h)||r.types.isJSXFragment(h)||r.types.isJSXExpressionContainer(h)&&(r.types.isJSXElement(h.expression)||r.types.isJSXFragment(h.expression)),C=!n&&p===a,I=r.types.isJSXExpressionContainer(h)&&!r.types.isJSXEmptyExpression(h.expression)?h.expression:null,V=!n&&!!I&&xt(I,p);!n&&y||C||V?i.push(r.types.objectMethod("get",u,[],r.types.blockStatement([r.types.returnStatement(f)]))):i.push(r.types.objectProperty(u,f))}return l.length>0&&i.push(r.types.objectProperty(r.types.identifier("use"),r.types.arrayExpression(l))),{props:i,spreads:s}}function kn(e){return r.types.isJSXIdentifier(e)?e.name==="class"?"className":e.name:r.types.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:"unknown"}function at(e,t,n="",o=!0){if(e===null)return r.types.booleanLiteral(!0);if(r.types.isStringLiteral(e))return e.value.includes(`
|
|
1
|
+
"use strict";var It=Object.create;var re=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var kt=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var Mt=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},Xe=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Nt(t))!Lt.call(e,i)&&i!==n&&re(e,i,{get:()=>t[i],enumerable:!(o=wt(t,i))||o.enumerable});return e};var $e=(e,t,n)=>(n=e!=null?It(kt(e)):{},Xe(t||!e||!e.__esModule?re(n,"default",{value:e,enumerable:!0}):n,e)),Jt=e=>Xe(re({},"__esModule",{value:!0}),e);var Bn={};Mt(Bn,{babelPluginReactiveJSX:()=>Fn,createPlugin:()=>Dn,createPreset:()=>me,default:()=>z,presets:()=>_n});module.exports=Jt(Bn);var ct=require("@babel/helper-plugin-utils");var Tt=e=>"components"in e;function Ae(e,t){return e.replace(/\$(\d+)/g,(n,o)=>t[Number(o)]??n)}function Pt(e,t){return typeof t=="string"?{module:t,export:e}:t}function je(e=[]){let t=new Map,n=[],o=[];for(let a of e){if(!Tt(a)){o.push(a);continue}for(let[l,c]of Object.entries(a.components)){let p=Pt(l,c),f=t.get(l);if(f&&f.module!==p.module){let u=n.find(h=>h.name===l);u?u.modules.push(p.module):n.push({name:l,modules:[f.module,p.module]});continue}t.set(l,p)}}let i=new Map;return{resolve:a=>{if(i.has(a))return i.get(a);let l=t.get(a);if(!l)for(let c of o){let p=a.match(new RegExp(c.match.source,c.match.flags.replace("g","")));if(p){l={module:Ae(c.module,p),export:c.export?Ae(c.export,p):a};break}}return i.set(a,l),l},names:()=>[...t.keys()],conflicts:()=>n}}var U=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],D=["Suspense","SuspenseList","Await"],_=["Router","Outlet","Redirect","Link"],Wn=[...U,...D,..._],fe=new Set([...U,...D]);function Oe(e={}){let{controlFlowModule:t="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:o="@fluixi/core/router-next"}=e,i={};for(let s of U)i[s]=t;for(let s of D)i[s]=n;for(let s of _)i[s]=o;return i}var j={kind:"eager"},Xt=["pointerdown","focusin","keydown"],Fe=new Set(["eager","idle","visible","interaction","media","never"]),J=class extends Error{};function q(e){return e.startsWith("load:")}function B(e,t){let n=e.slice(5);if(!Fe.has(n))throw new J(`Unknown load strategy 'load:${n}'. Expected one of ${[...Fe].join(", ")}.`);switch(n){case"eager":return j;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?$t(t):[...Xt]};case"media":if(!t)throw new J(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new J(`Unhandled load strategy '${n}'.`)}}function $t(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new J("'load:interaction' was given no event names.");return t}function X(e){return e.kind!=="eager"&&e.kind!=="never"}function ge(e,t={}){let{resolver:n,isBound:o,modules:i,strategyFor:s}=t,a=Oe(i),l=new Map,c=new Set,p=u=>{let{name:h}=u;if(!h||h.includes(".")||o?.(h))return;let y=f(h);if(!y){c.add(h);return}let C=y.origin==="builtin"&&fe.has(h)?j:s?.(u)??j;u.source={...y,loading:C},l.set(h,u.source)},f=u=>{if(fe.has(u))return{module:a[u],export:u,origin:"builtin"};let h=n?.resolve(u);if(h)return{module:h.module,export:h.export,origin:"rule"};if(_.includes(u))return{module:a[u],export:u,origin:"builtin"}};return ie(e,u=>{u.kind==="component"&&p(u)}),{resolved:l,unresolved:[...c]}}function ie(e,t){let n=Array.isArray(e)?e:[e];for(let o of n){t(o);let i=o.children;i&&ie(i,t)}}function he(e){let t=[];ie(e,s=>{s.kind==="component"&&s.source&&t.push(s)});let n=new Set,o=new Set;for(let s of t){let{module:a,loading:l}=s.source;l.kind==="eager"&&n.add(a),l.kind==="never"&&o.add(a)}let i=new Map;for(let s of t){let a=s.source;X(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},i.set(a.module,(i.get(a.module)??0)+1))}return{collapsed:i,conflicted:[...o].filter(s=>n.has(s))}}var r=require("@babel/core");var m=require("@babel/core"),ye=$e(require("@babel/generator"),1);var At=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),De={className:"class",htmlFor:"for"},jt=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Ot=new Set(["script","style","textarea","title"]);function Ee(e){return Ot.has(e)}function _e(e){return De[e]??e}function G(e){return e.kind!=="attr"||e.expr!==void 0||e.name.includes(":")?!1:!jt.has(e.name)}function xe(e){if(!e.static||Ee(e.tag))return!1;for(let t of e.props)if(!G(t))return!1;for(let t of e.children)if(t.kind!=="text"&&!(t.kind==="element"&&xe(t)))return!1;return!0}function K(e){let t=e.props.map(Dt).filter(Boolean).join(""),n=`<${e.tag}${t}>`;return At.has(e.tag)?n:`${n}${e.children.map(Ft).join("")}</${e.tag}>`}function Ft(e){if(e.kind==="text")return Bt(e.value);if(e.kind!=="element")throw new Error(`serializeStatic: unexpected ${e.kind}`);return K(e)}function Dt(e){let t=De[e.name]??e.name,n=e.literal;return n===!0||n===void 0?` ${t}`:n===!1||n===null?"":` ${t}="${_t(String(n))}"`}function _t(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Bt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var zt="<!--fx-->",Vt="<!--fx/-->";function se(e){return e.kind==="expr"||e.kind==="component"||e.kind==="control"}function Wt(e){return e.kind==="text"||e.kind==="element"&&Be(e)}function Be(e){return e.svg||Ee(e.tag)||!e.props.every(t=>G(t))?!1:e.children.every(t=>Wt(t)||se(t))}function oe(e){if(se(e))return!0;let t=e.children;return t?t.some(oe):!1}function ze(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"||ze(t))}function Ve(e){if(!Be(e)||!ze(e)||!e.children.some(oe))return null;let t=[],n=[],o=0,i=a=>{let l=`_n$${o++}`;return t.push({ref:l,expr:a}),l};return s(e,"_el$"),{html:Ht(e),tag:e.tag,steps:t,holes:n};function s(a,l){let c=-1;a.children.forEach((f,u)=>{oe(f)&&(c=u)});let p=null;for(let f=0;f<=c;f++){let u=a.children[f],h=p?`${p}.nextSibling`:`${l}.firstChild`;if(se(u)){let C=i(h),I=i(`holeEnd(${C})`);n.push({parentRef:l,startRef:C,endRef:I,node:u}),p=I;continue}let y=i(h);u.kind==="element"&&oe(u)&&s(u,y),p=y}}}function Ht(e){return K(We(e)).split(He).join(zt+Vt)}function We(e){return{...e,children:e.children.map(t=>se(t)?{kind:"text",value:He}:t.kind==="element"?We(t):t)}}var He="\0fx-hole\0";var Se={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},rr={version:2,module:"@fluixi/dom",symbols:[...Se.symbols,"template","cloneTemplate","walk"]};var Ut={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function qt(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function qe(e){return qt(e)?e:JSON.stringify(e)}function Gt(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function Kt(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function Zt(e,t,n){let o=e.filter(l=>l.kind==="spread"),s=e.filter(l=>l.kind!=="spread").map(l=>`${qe(l.name)}: ${Gt(l)}`);t!=null&&s.push(`children: ${t}`);let a=`{ ${s.join(", ")} }`;return o.length>0?(n.add("mergeProps"),`mergeProps(${o.map(l=>l.expr).join(", ")}, ${a})`):a}function Ge(e,t,n){return e.length===1?Z(e[0],t,n):`[${e.map(o=>Z(o,t,n)).join(", ")}]`}function Ue(e,t,n,o,i){o.add("createMemo"),o.add("createComponent");let s=t.filter(p=>p.kind==="spread"),l=t.filter(p=>p.kind!=="spread").map(p=>`get ${qe(p.name)}() { return ${Kt(p)}; }`);n.length>0&&l.push(`get children() { return ${Ge(n,o,i)}; }`);let c=`{ ${l.join(", ")} }`;return s.length>0&&(o.add("mergeProps"),c=`mergeProps(${s.map(p=>p.expr).join(", ")}, ${c})`),`createMemo(() => createComponent(${e}, ${c}))`}function Yt(e,t){let n=_e(t.name),o=t.literal;return o===!0||o===void 0?`${e}.setAttribute(${JSON.stringify(n)}, "");`:o===!1||o===null?"":`${e}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(o))});`}var Ke=!1;function Z(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":Ge(e.children,t,n);case"component":return Ue(e.name,e.props,e.children,t,n);case"control":{let o=Ut[e.control]??e.control;return t.add(o),Ue(o,e.props,e.children,t,n)}case"element":{if(n&&e.static&&!e.svg&&xe(e)){t.add("templateNode");let l=`_tmpl$${n.length}`;return n.push({id:l,html:K(e),tag:e.tag,svg:!1}),`templateNode(${l}, ${JSON.stringify(e.tag)})`}if(n&&Ke){let l=Ve(e);if(l){t.add("templateNode"),t.add("insert"),t.add("holeEnd"),t.add("holeContent"),t.add("holeScope");let c=`_tmpl$${n.length}`;n.push({id:c,html:l.html,tag:l.tag,svg:!1});let p=[`const _el$ = templateNode(${c}, ${JSON.stringify(l.tag)}, true);`];for(let f of l.steps)p.push(`const ${f.ref} = ${f.expr};`);for(let f of l.holes)p.push(`insert(${f.parentRef}, holeScope(${f.startRef}, () => (${Z(f.node,t,n)})), ${f.endRef}, holeContent(${f.startRef}, ${f.endRef}));`);return p.push("return _el$;"),`(() => { ${p.join(" ")} })()`}}t.add("createNativeElement");let o=JSON.stringify(e.tag),i="_el$",s=[],a=e.svg?`${o}, true`:o;if(s.push(`const ${i} = createNativeElement(${a});`),e.props.length>0)if(!e.svg&&e.props.every(G))for(let l of e.props)s.push(Yt(i,l));else{t.add("spread");let l=e.svg?", isSVG: true":"";s.push(`spread({ element: ${i}, props: ${Zt(e.props,null,t)}${l} });`)}for(let l of e.children){t.add("insert");let c=Z(l,t,n),p=l.kind==="expr"&&l.reactive||l.kind==="component"||l.kind==="control";s.push(p?`insert(${i}, ${c}, null);`:`insert(${i}, ${c});`)}return s.push(`return ${i};`),`(() => { ${s.join(" ")} })()`}}}function Y(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(o=>[o.id,JSON.stringify(o.html)]));return e.replace(/_tmpl\$\d+/g,o=>n.get(o)??o)}var $={name:"imperative",contract:Se,emit(e,t){let n=new Set,o=t?.templateClone!==!1?[]:void 0;return Ke=t?.partialTemplates===!0,{code:Z(e,n,o),imports:Array.from(n),templates:o}}};var Q=require("@babel/core"),ve=$e(require("@babel/generator"),1),Qe=require("@fluixi/template-parser");var Qt=ve.default.default??ve.default;function en(e){return Qt(e,{concise:!0}).code}var Ze=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function tn(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Ye(e){return e.charAt(0).toUpperCase()+e.slice(1)}var be=class{constructor(t,n){this.holes=t;this.used=n}hole(t){return this.holes[t]??{node:Q.types.identifier("undefined"),code:"undefined",reactive:!1}}emit(t){let{code:n,imports:o,templates:i}=$.emit(t,{});for(let s of o)this.used.add(s);return Y(n,i)}lowerRoot(t){let n=this.lowerChildren(t);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(t){let n=[];for(let o=0;o<t.length;o++){let i=t[o];if(i.kind==="Element"||i.kind==="Component"){let a=i.attributes.find(l=>l.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let l=o+1;l<t.length&&this.isBlankText(t[l])&&l++;let c=t[l],p=c&&(c.kind==="Element"||c.kind==="Component")&&c.attributes.some(f=>f.kind==="ElseDirective");n.push(this.lowerIf(i,a.hole,p?c:null)),p&&(o=l);continue}if(i.attributes.some(l=>l.kind==="EachDirective")){n.push(this.lowerEach(i));continue}}let s=this.lowerNode(i);s&&n.push(s)}return n}isBlankText(t){return t.kind==="Text"&&!t.raw&&ae(t.value)===""}lowerNode(t){switch(t.kind){case"Text":{if(t.raw)return{kind:"text",value:t.value};let n=ae(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(o=>o.kind==="Attribute"&&o.name==="is");if(t.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let o=t.attributes.filter(s=>s!==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}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,o=this.lowerAttributes(t.attributes),{slots:i,rest:s}=this.partitionSlots(t.children);for(let[c,p]of i){let f=p.length===1?p[0]:{kind:"fragment",children:p},u={name:c,kind:"attr",expr:this.emit(f),jsxElement:!0},h=o.findIndex(y=>y.name===c);h>=0?o[h]=u:o.push(u)}let a=t.attributes.find(c=>c.kind==="LoadDirective"),l=a?B(`load:${a.strategy}`,a.modifier):void 0;return{kind:"component",name:n,props:o,children:this.lowerChildren(s),...l?{load:l}:{}}}partitionSlots(t){let n=new Map,o=[];for(let i of t){if(i.kind==="Element"||i.kind==="Component"){let s=i.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(s&&s.value&&s.value.kind==="static"){let a={...i,attributes:i.attributes.filter(p=>p!==s)},l=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),c=n.get(s.value.value)??[];c.push(l),n.set(s.value.value,c);continue}}o.push(i)}return{slots:n,rest:o}}lowerIf(t,n,o){let i=this.hole(n),s=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive}];if(o){let l=this.stripAndLower(o,c=>c.kind==="ElseDirective");s.push({name:"fallback",kind:"attr",expr:this.emit(l),jsxElement:!0})}let a=this.stripAndLower(t,l=>l.kind==="IfDirective");return{kind:"component",name:"Show",props:s,children:[a]}}lowerEach(t){let n=t.attributes.find(c=>c.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(t);let o=this.hole(n.hole),i=[{name:"each",kind:"attr",expr:o.code,reactive:o.reactive}];if(n.key){let c="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;i.push({name:"by",kind:"attr",expr:c})}let s=this.itemArrow(t),a;if(s){let c=s.body,p={kind:"expr",code:A(c,this.used),reactive:N(c)},f=this.rebuildWithChildren(t,[p]);a=`(${s.params.map(u=>en(u)).join(", ")}) => (${this.emit(f)})`}else{let c=this.stripAndLower(t,p=>p.kind==="EachDirective");a=`() => (${this.emit(c)})`}return{kind:"component",name:"For",props:i,children:[{kind:"expr",code:a,reactive:!1}]}}itemArrow(t){let n=t.children.filter(i=>!this.isBlankText(i));if(n.length!==1||n[0].kind!=="Expression")return null;let o=this.hole(n[0].hole).node;return Q.types.isArrowFunctionExpression(o)&&!Q.types.isBlockStatement(o.body)?o:null}stripAndLower(t,n){let o={...t,attributes:t.attributes.filter(i=>!n(i))};return o.kind==="Element"?this.lowerElement(o):this.lowerComponent(o)}rebuildWithChildren(t,n){let o=this.lowerAttributes(t.attributes.filter(i=>i.kind!=="EachDirective"));return t.kind==="Element"?{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:o,children:n,static:!1}:{kind:"component",name:t.tag,props:o,children:n}}lowerAttributes(t){let n=[],o=[],i=!1,s=[],a=!1,l=[];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});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});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(c.hole).code});break;case"ClassDirective":{let p=this.hole(c.hole);o.push(`${JSON.stringify(c.name)}: ${p.code}`),i=i||p.reactive;break}case"StyleDirective":{let p=this.hole(c.hole);s.push(`${JSON.stringify(c.name)}: ${p.code}`),a=a||p.reactive;break}case"BindDirective":n.push(...this.bindProps(c.name,this.hole(c.hole).code));break;case"UseDirective":{let p=c.name??(c.hole!=null?this.hole(c.hole).code:null);if(!p)break;l.push(c.name!=null&&c.hole!=null?`[${p}, () => (${this.hole(c.hole).code})]`:`[${p}]`);break}}return o.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:i}),s.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${s.join(", ")} }`,reactive:a}),l.length>0&&n.push({name:"use",kind:"attr",expr:`[${l.join(", ")}]`}),n}eventProp(t){let n=t.name.toLowerCase(),o=this.hole(t.hole).code;if(!(t.syntax==="colon"||t.modifiers.length>0))return{name:"on"+Ye(t.name),kind:"event",event:{name:n,delegated:Ze.has(n)},expr:o};let s=this.wrapHandler(o,t.modifiers),a=this.eventOptions(t.modifiers),l=a?`[${s}, ${a}]`:s;return{name:"on:"+n,kind:"attr",expr:l}}wrapHandler(t,n){let o=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return n.includes("prevent")&&i.push("e.preventDefault();"),n.includes("stop")&&i.push("e.stopPropagation();"),!o&&i.length===0?t:`(e) => { ${o}${i.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 o=t==="checked",i=o?"change":"input",s=o?"checked":"value",a=`(${n})`;return[{name:t,kind:"attr",expr:`${a}[0]()`,reactive:!0},{name:"on"+Ye(i),kind:"event",event:{name:i,delegated:Ze.has(i)},expr:`(e) => ${a}[1](e.target.${s})`}]}plainAttr(t){let n=t.value,o=t.name;t.name==="class"?o=n&&n.kind==="hole"&&Q.types.isObjectExpression(this.hole(n.hole).node)?"classList":"className":t.name==="html"&&(o="innerHTML");let s={name:o,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 c=this.hole(n.hole);return s.expr=c.code,s.reactive=c.reactive,s}let a=!1,l=n.parts.map(c=>{if("text"in c)return tn(c.text);let p=this.hole(c.hole);return a=a||p.reactive,"${"+p.code+"}"}).join("");return s.expr="`"+l+"`",s.reactive=a,s}};function et(e,t,n={}){let o=e.quasi,i=o.expressions.map(l=>{let c=l;return{node:c,code:A(c,t),reactive:N(c)}}),s=nn(o),{root:a}=(0,Qe.parseTemplate)(s,{svg:n.svg});return new be(i,t).lowerRoot(a.children)}function nn(e){let t=[];return e.quasis.forEach((n,o)=>{let i=n.value.cooked??n.value.raw;if(t.push({kind:"static",text:i,start:n.start??0}),o<e.expressions.length){let s=e.expressions[o];t.push({kind:"hole",index:o,start:s.start??0,end:s.end??0})}}),t}function rn(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 le(e){let t=[],n=new Map,o=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of i.children)o(s);return!1;case"fragment":for(let s of i.children)o(s);return!1;case"element":{let s=!0;for(let l of i.children)o(l)||(s=!1);let a;for(let l of i.props)if(a=rn(l),a)break;return!a&&!s&&(a=on(i)),i.static=!a,a?n.set(i,a):t.push(i),i.static}default:return!1}};for(let i of Array.isArray(e)?e:[e])o(i);return{staticElements:t,reasons:n}}function on(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"}function ce(e,t=new Set,n={}){let o=et(e,t,n);return le(o),o}var sn=ye.default.default??ye.default;function rt(e){return sn(e,{concise:!0}).code}function an(e,t){let n=m.types.cloneNode(e,!0),o=m.types.file(m.types.program([m.types.expressionStatement(n)])),i=!1,s=(a,l,c)=>{for(let p of c)t.add(p);a.replaceWith(m.template.expression(l,{placeholderPattern:!1,plugins:["typescript"]})()),a.skip(),i=!0};return(0,m.traverse)(o,{"JSXElement|JSXFragment"(a){let l=a.node,{code:c,imports:p,templates:f}=$.emit(Ie(l,t),{});s(a,Y(c,f),p)},TaggedTemplateExpression(a){let l=a.node.tag;if(!m.types.isIdentifier(l)||l.name!=="html"&&l.name!=="svg")return;let c=ce(a.node,t,{svg:l.name==="svg"}),{code:p,imports:f,templates:u}=$.emit(c,{});s(a,Y(p,u),f)}}),i?o.program.body[0].expression:e}function A(e,t){return rt(an(e,t))}var ln=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),cn=/^on[A-Z]/,pn=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function un(e){if(m.types.isJSXIdentifier(e)){let t=e.name[0]!==e.name[0].toLowerCase();return{tag:e.name,component:t}}return m.types.isJSXMemberExpression(e)?{tag:rt(e),component:!0}:m.types.isJSXNamespacedName(e)?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function Ce(e){return m.types.isJSXIdentifier(e)?e.name==="class"?"className":e.name:m.types.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:"unknown"}function N(e){return m.types.isCallExpression(e)||m.types.isOptionalCallExpression(e)?!0:m.types.isMemberExpression(e)||m.types.isOptionalMemberExpression(e)?!(!e.computed&&m.types.isIdentifier(e.property,{name:"children"})):m.types.isConditionalExpression(e)?N(e.test)||N(e.consequent)||N(e.alternate):m.types.isLogicalExpression(e)||m.types.isBinaryExpression(e)?N(e.left)||N(e.right):m.types.isTemplateLiteral(e)?e.expressions.some(t=>N(t)):m.types.isObjectExpression(e)?e.properties.some(t=>m.types.isObjectProperty(t)&&!t.computed&&N(t.value)):m.types.isArrayExpression(e)?e.elements.some(t=>t!=null&&!m.types.isSpreadElement(t)&&N(t)):!1}function dn(e,t){let n=Ce(e.name),o=cn.test(n),i=o||n.startsWith("on:")||n==="ref",a={name:n,kind:o?"event":"attr"};o&&(a.event={name:n.slice(2).toLowerCase(),delegated:pn.has(n.slice(2).toLowerCase())});let l=e.value;if(l==null)return a.literal=!0,a;if(m.types.isStringLiteral(l))return a.literal=l.value,a;if(m.types.isJSXExpressionContainer(l)&&!m.types.isJSXEmptyExpression(l.expression)){let c=l.expression;return m.types.isStringLiteral(c)||m.types.isNumericLiteral(c)||m.types.isBooleanLiteral(c)?(a.literal=c.value,a):(a.expr=A(c,t),a.reactive=i?!1:N(c),(m.types.isJSXElement(c)||m.types.isJSXFragment(c))&&(a.jsxElement=!0),a)}return a.literal=!0,a}function tt(e,t){let n=e.value;return n==null?null:m.types.isStringLiteral(n)?JSON.stringify(n.value):m.types.isJSXExpressionContainer(n)&&!m.types.isJSXEmptyExpression(n.expression)?A(n.expression,t):null}function mn(e,t){let n=[],o=[];for(let i of e){if(m.types.isJSXSpreadAttribute(i)){n.push({name:"",kind:"spread",expr:A(i.argument,t)});continue}if(!m.types.isJSXAttribute(i)||q(Ce(i.name)))continue;let s=m.types.isJSXNamespacedName(i.name)?i.name.namespace.name:null;if(s==="use"){let a=i.name.name.name;t.add(a);let l=tt(i,t);o.push(l!=null?`[${a}, () => (${l})]`:`[${a}]`);continue}if(s==="oncapture"){let a=i.name.name.name.toLowerCase(),l=tt(i,t)??"undefined";n.push({name:"on:"+a,kind:"attr",expr:`[${l}, { capture: true }]`});continue}n.push(dn(i,t))}return o.length>0&&n.push({name:"use",kind:"attr",expr:`[${o.join(", ")}]`}),n}function ae(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let i=0;i<t.length;i++)/[^ \t]/.test(t[i])&&(n=i);let o="";for(let i=0;i<t.length;i++){let s=t[i].replace(/\t/g," ");i!==0&&(s=s.replace(/^ +/,"")),i!==t.length-1&&(s=s.replace(/ +$/,"")),s&&(i!==n&&(s+=" "),o+=s)}return o}function nt(e,t){let n=[];for(let o of e)if(m.types.isJSXText(o)){let i=ae(o.value);i&&n.push({kind:"text",value:i})}else if(m.types.isJSXExpressionContainer(o)){if(!m.types.isJSXEmptyExpression(o.expression)){let i=o.expression;n.push({kind:"expr",code:A(i,t),reactive:N(i)})}}else m.types.isJSXElement(o)||m.types.isJSXFragment(o)?n.push(Re(o,t)):m.types.isJSXSpreadChild(o)&&n.push({kind:"expr",code:A(o.expression,t),reactive:!1});return n}function Ie(e,t=new Set){let n=Re(e,t);return le(n),n}function Re(e,t){if(m.types.isJSXFragment(e))return{kind:"fragment",children:nt(e.children,t)};let{tag:n,component:o}=un(e.openingElement.name),i=mn(e.openingElement.attributes,t),s=nt(e.children,t);if(o){let a=fn(e.openingElement.attributes);return{kind:"component",name:n,props:i,children:s,...a?{load:a}:{}}}return{kind:"element",tag:n,svg:ln.has(n),props:i,children:s,static:!1}}function fn(e){for(let t of e){if(!m.types.isJSXAttribute(t))continue;let n=Ce(t.name);if(q(n)){if(t.value&&!m.types.isStringLiteral(t.value))throw new J(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return B(n,t.value?t.value.value:null)}}}var ue=new Set([...U,...D]),it=new Set(D),pe=new Set(_),gn={Show:"when",For:"each",Index:"each",Match:"when"};var pt=/^on[A-Z]/,ut=["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave"],z=(0,ct.declare)((e,t={})=>{e.assertVersion(7);let{runtime:n="automatic",importSource:o="@fluixi/jsx",pragma:i="jsx",pragmaFrag:s="Fragment",development:a=!1,detectReactivity:l=!0,useLitHTML:c=!0,hoistStatics:p=!0,delegateEvents:f=!0,delegatedEvents:u=ut,optimizeControlFlow:h=!0,sourceMaps:y=!0,signalModule:C="@fluixi/dom",controlFlowModule:I="@fluixi/dom",routerModule:V="@fluixi/core/router-next",reactiveModule:P="@fluixi/reactive/signal",autoShowTransform:W=!1,backend:M="imperative",codegen:H="ir",templateClone:Me=!0,partialTemplates:Je=!0,format:Te="both",litTag:bt="html",resolve:yt=[]}=t,Pe=je(yt),Rt=Te==="lit"||Te==="both",Ct={backend:M,codegen:H,irImports:new Set,libModule:"@fluixi/core",controlFlowModule:I,routerModule:V,templateClone:Me,partialTemplates:Je,hasJSX:!1,hasReactivity:!1,hasLitHTML:!1,needsSignalImport:!1,needsControlFlowImport:!1,needsCreateMemo:!1,controlFlowComponents:new Set,resolvedComponents:new Map,deferredComponents:new Map,componentResolver:Pe,delegatedEvents:new Set,staticElements:new Map,staticTemplates:new Map,staticCounter:0};return{name:"@fluixi/babel-plugin-jsx",manipulateOptions(g,d){d.plugins.push("jsx","typescript")},pre(g){Object.assign(g,Ct)},visitor:{ImportDeclaration(g,d){g.node.source.value==="@fluixi/core/rx"&&(g.node.source=r.types.stringLiteral("@fluixi/reactive"))},Program:{enter(g,d){Object.assign(d,{hasJSX:!1,hasReactivity:!1,hasLitHTML:!1,hasLitIR:!1,needsSignalImport:!1,needsControlFlowImport:!1,needsCreateMemo:!1,controlFlowComponents:new Set,resolvedComponents:new Map,deferredComponents:new Map,componentResolver:Pe,delegatedEvents:new Set,staticElements:new Map,staticTemplates:new Map,autoShow:W,staticCounter:0,libModule:"@fluixi/core",controlFlowModule:I,routerModule:V,templateClone:Me,partialTemplates:Je,backend:M,codegen:H,irImports:new Set,needsCreateNativeElement:!1,needsInsert:!1,needsSpread:!1,needsCreateComponent:!1,needsMergeProps:!1})},exit(g,d){let E=[];if(d.hasJSX||d.needsSignalImport&&E.push(r.types.importDeclaration([r.types.importSpecifier(r.types.identifier("signal"),r.types.identifier("signal"))],r.types.stringLiteral(C))),d.hasJSX||d.hasLitIR){if(d.irImports.size>0){let S=new Set(["Show","For","Index","Switch","Match","Dynamic","ErrorBoundary","Portal","Suspense"]),x=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]),v=Array.from(d.irImports),R=b=>r.types.importSpecifier(r.types.identifier(b),r.types.identifier(b)),L=b=>!g.scope.hasBinding(b),F=v.filter(b=>x.has(b)&&L(b)),w=v.filter(b=>!S.has(b)&&!x.has(b)&&L(b)),ne=v.filter(b=>S.has(b)&&L(b));F.length>0&&E.push(r.types.importDeclaration(F.map(R),r.types.stringLiteral(P))),w.length>0&&E.push(r.types.importDeclaration(w.map(R),r.types.stringLiteral(C))),ne.length>0&&E.push(r.types.importDeclaration(ne.map(R),r.types.stringLiteral(I)))}if(d.hasJSX&&M==="imperative"&&H!=="ir"){let x=[[!!d.needsCreateNativeElement,"createNativeElement"],[!!d.needsSpread,"spread"],[!!d.needsInsert,"insert"],[!!d.needsCreateComponent,"createComponent"],[!!d.needsMergeProps,"mergeProps"]].filter(([v,R])=>v&&!g.scope.hasBinding(R)).map(([,v])=>r.types.importSpecifier(r.types.identifier(v),r.types.identifier(v)));x.length>0&&E.push(r.types.importDeclaration(x,r.types.stringLiteral(C)))}else if(d.hasJSX&&n==="automatic"&&M!=="imperative"){let S=[r.types.importSpecifier(r.types.identifier("jsx"),r.types.identifier("jsx")),r.types.importSpecifier(r.types.identifier("jsxs"),r.types.identifier("jsxs")),r.types.importSpecifier(r.types.identifier("Fragment"),r.types.identifier("Fragment"))];a&&S.push(r.types.importSpecifier(r.types.identifier("jsxDEV"),r.types.identifier("jsxDEV"))),d.needsMergeProps&&S.push(r.types.importSpecifier(r.types.identifier("mergeProps"),r.types.identifier("mergeProps"))),E.push(r.types.importDeclaration(S,r.types.stringLiteral(o)))}if(d.needsCreateMemo&&!g.scope.hasBinding("createMemo")&&E.push(r.types.importDeclaration([r.types.importSpecifier(r.types.identifier("createMemo"),r.types.identifier("createMemo"))],r.types.stringLiteral(M==="imperative"?P:d.libModule??"@fluixi/core"))),d.needsControlFlowImport&&d.controlFlowComponents.size>0){let S=Array.from(d.controlFlowComponents).filter(w=>!g.scope.hasBinding(w)),x=d.libModule??"@fluixi/core",v=S.filter(w=>pe.has(w)),R=S.filter(w=>it.has(w)),L=S.filter(w=>!it.has(w)&&!pe.has(w)),F=(w,ne)=>r.types.importDeclaration(w.map(b=>r.types.importSpecifier(r.types.identifier(b),r.types.identifier(b))),r.types.stringLiteral(ne));L.length>0&&E.push(F(L,I)),R.length>0&&E.push(F(R,x)),v.length>0&&E.push(F(v,V))}let k=[];if(d.deferredComponents.size>0){for(let[S,x]of d.deferredComponents)g.scope.hasBinding(S)||k.push(r.types.variableDeclaration("const",[r.types.variableDeclarator(r.types.identifier(S),r.types.callExpression(r.types.identifier("deferred"),[r.types.arrowFunctionExpression([],r.types.callExpression(r.types.import(),[r.types.stringLiteral(x.module)])),r.types.objectExpression([r.types.objectProperty(r.types.identifier("strategy"),vn(x.strategy)),r.types.objectProperty(r.types.identifier("export"),r.types.stringLiteral(x.export))])]))]));k.length>0&&!g.scope.hasBinding("deferred")&&E.push(r.types.importDeclaration([r.types.importSpecifier(r.types.identifier("deferred"),r.types.identifier("deferred"))],r.types.stringLiteral(d.libModule??"@fluixi/core")))}if(d.resolvedComponents.size>0){let S=new Map;for(let[x,v]of d.resolvedComponents){if(g.scope.hasBinding(x))continue;let R=S.get(v.module)??[];R.push({local:x,exported:v.export}),S.set(v.module,R)}for(let[x,v]of S)E.push(r.types.importDeclaration(v.map(({local:R,exported:L})=>L==="default"?r.types.importDefaultSpecifier(r.types.identifier(R)):r.types.importSpecifier(r.types.identifier(R),r.types.identifier(L))),r.types.stringLiteral(x)))}if(f&&d.delegatedEvents.size>0){E.push(r.types.importDeclaration([r.types.importSpecifier(r.types.identifier("delegateEvents"),r.types.identifier("delegateEvents"))],r.types.stringLiteral(M==="imperative"?C:"@fluixi/jsx")));let S=r.types.arrayExpression(Array.from(d.delegatedEvents).map(v=>r.types.stringLiteral(v))),x=r.types.expressionStatement(r.types.callExpression(r.types.identifier("delegateEvents"),[S]));g.node.body.unshift(x)}if(p&&d.staticElements.size>0){let S=[];d.staticElements.forEach((x,v)=>{S.push(r.types.variableDeclaration("const",[r.types.variableDeclarator(r.types.identifier(v),x)]))}),g.node.body.unshift(...S)}if(k.length>0&&g.node.body.unshift(...k),d.staticTemplates.size>0){let S=[];for(let[x,v]of d.staticTemplates){let L=x.startsWith("svg:")?x.slice(4):x;S.push(r.types.variableDeclaration("const",[r.types.variableDeclarator(r.types.identifier(v),r.types.stringLiteral(L))]))}g.node.body.unshift(...S)}}E.length>0&&g.node.body.unshift(...yn(E))}},JSXElement(g,d){if(d.hasJSX=!0,M==="imperative"&&H==="ir"){g.replaceWith(st(g.node,d));return}let E=g.node,k=E.openingElement;if(r.types.isJSXIdentifier(k.name)&&pe.has(k.name.name)&&!d.componentResolver?.resolve(k.name.name)&&(d.controlFlowComponents.add(k.name.name),d.needsControlFlowImport=!0),r.types.isJSXIdentifier(k.name)&&ue.has(k.name.name)&&(d.controlFlowComponents.add(k.name.name),h)){let x=An(E,d);if(x){g.replaceWith(x);return}}if(p&&M!=="imperative"&&vt(E,d)){let x=$n(E,d);if(x){g.replaceWith(x);return}}let S=hn(E,d,{runtime:n,pragma:i,development:a,detectReactivity:l,useLitHTML:c,autoShow:W});g.replaceWith(S)},JSXFragment(g,d){if(d.hasJSX=!0,M==="imperative"&&H==="ir"){g.replaceWith(st(g.node,d));return}let E=de(g.node,d,{runtime:n,pragmaFrag:s,development:a});g.replaceWith(E)},CallExpression(g,d){if(!l)return;let E=g.node.callee;E.name,r.types.isIdentifier(E)&&(E.name==="createSignal"||E.name==="createStore"||E.name==="useContext"||E.name==="useLocation")&&(d.hasReactivity=!0)},JSXExpressionContainer(g){},TaggedTemplateExpression(g,d){if(Rt&&M==="imperative"&&r.types.isIdentifier(g.node.tag)&&(g.node.tag.name===bt||g.node.tag.name==="svg")){g.replaceWith(Rn(g.node,d));return}}}}});function hn(e,t,n){let{runtime:o,pragma:i,development:s,autoShow:a=!0}=n;return o==="automatic"?te(e,t,s,a):wn(e,t,i)}var En=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]);function ot(e,t,n){return t.length>0?(n.needsMergeProps=!0,r.types.callExpression(r.types.identifier("mergeProps"),[...t,r.types.objectExpression(e)])):r.types.objectExpression(e)}function dt(e){return e.length===1?e[0]:r.types.arrayExpression(e)}function xn(e,t,n,o,i,s){if(!t){let u=[...n];return i.length>0&&u.push(r.types.objectMethod("get",r.types.identifier("children"),[],r.types.blockStatement([r.types.returnStatement(dt(i))]))),mt(e,ot(u,o,s),s)}let a=e.value,l=En.has(a),c=r.types.identifier("_el$"),p=[];s.needsCreateNativeElement=!0;let f=[e];if(l&&f.push(r.types.booleanLiteral(!0)),p.push(r.types.variableDeclaration("const",[r.types.variableDeclarator(c,r.types.callExpression(r.types.identifier("createNativeElement"),f))])),n.length>0||o.length>0){s.needsSpread=!0;let u=[r.types.objectProperty(r.types.identifier("element"),c),r.types.objectProperty(r.types.identifier("props"),ot(n,o,s))];l&&u.push(r.types.objectProperty(r.types.identifier("isSVG"),r.types.booleanLiteral(!0))),p.push(r.types.expressionStatement(r.types.callExpression(r.types.identifier("spread"),[r.types.objectExpression(u)])))}if(i.length>0){s.needsInsert=!0;for(let u of i){let y=r.types.isArrowFunctionExpression(u)||r.types.isFunctionExpression(u)||r.types.isCallExpression(u)&&r.types.isIdentifier(u.callee)&&u.callee.name==="createMemo"?[r.types.cloneNode(c),u,r.types.nullLiteral()]:[r.types.cloneNode(c),u];p.push(r.types.expressionStatement(r.types.callExpression(r.types.identifier("insert"),y)))}}return p.push(r.types.returnStatement(c)),r.types.callExpression(r.types.arrowFunctionExpression([],r.types.blockStatement(p)),[])}function Sn(e,t){let n=null;if(t.value)if(r.types.isStringLiteral(t.value))n=t.value.value;else throw new J(`'${e}' needs a literal value, not an expression — the strategy is compile-time.`);return B(e,n)}function vn(e){let t=[r.types.objectProperty(r.types.identifier("kind"),r.types.stringLiteral(e.kind))];return e.kind==="visible"&&e.rootMargin&&t.push(r.types.objectProperty(r.types.identifier("rootMargin"),r.types.stringLiteral(e.rootMargin))),e.kind==="interaction"&&t.push(r.types.objectProperty(r.types.identifier("events"),r.types.arrayExpression(e.events.map(n=>r.types.stringLiteral(n))))),e.kind==="media"&&t.push(r.types.objectProperty(r.types.identifier("query"),r.types.stringLiteral(e.query))),r.types.objectExpression(t)}function bn(e,t){return!X(e)||!X(t)?j:e}function mt(e,t,n){r.types.isIdentifier(e)&&ue.has(e.name)&&(n.controlFlowComponents.add(e.name),n.needsControlFlowImport=!0);let o=!1;if(r.types.isIdentifier(e)&&!ue.has(e.name)&&n.componentResolver){let i=n.componentResolver.resolve(e.name);if(i){let s=n.pendingLoad??j,a=n.resolvedComponents.has(e.name);if(X(s)&&!a){let l=n.deferredComponents.get(e.name),c=l?bn(l.strategy,s):s;X(c)?n.deferredComponents.set(e.name,{...i,strategy:c}):(n.deferredComponents.delete(e.name),n.resolvedComponents.set(e.name,i))}else n.deferredComponents.delete(e.name),n.resolvedComponents.set(e.name,i);o=!0}}return n.pendingLoad=void 0,!o&&r.types.isIdentifier(e)&&pe.has(e.name)&&(n.controlFlowComponents.add(e.name),n.needsControlFlowImport=!0),n.backend==="imperative"?(n.needsCreateComponent=!0,n.needsCreateMemo=!0,r.types.callExpression(r.types.identifier("createMemo"),[r.types.arrowFunctionExpression([],r.types.callExpression(r.types.identifier("createComponent"),[e,t]))])):r.types.callExpression(r.types.identifier("jsx"),[e,t])}function ft(e,t,n){if(!t||t.length===0)return e;let o=new Map;for(let i of t){let s=`${i.svg?"svg:":""}${i.html}`,a=n.staticTemplates.get(s);a||(a=`_tmpl$${n.staticTemplates.size}`,n.staticTemplates.set(s,a)),o.set(i.id,a)}return e.replace(/_tmpl\$\d+/g,i=>o.get(i)??i)}function st(e,t){let n=new Set,o=Ie(e,n);ge(o,{resolver:t.componentResolver,modules:{controlFlowModule:t.controlFlowModule,coreModule:t.libModule,routerModule:t.routerModule},strategyFor:c=>c.load}),he(o);let{code:i,imports:s,templates:a}=$.emit(o,{templateClone:t.templateClone,partialTemplates:t.partialTemplates});for(let c of s)n.add(c);for(let c of n)t.irImports.add(c);Ne(o,t);let l=ft(i,a,t);return r.template.expression(l,{placeholderPattern:!1,plugins:["typescript"]})()}function yn(e){let t=new Map,n=[];for(let o of e){let i=o.source.value;if(!o.specifiers.every(l=>r.types.isImportSpecifier(l))){n.push(o);continue}let a=t.get(i);if(!a){let l=new Set(o.specifiers.map(c=>c.local.name));t.set(i,{decl:o,names:l}),n.push(o);continue}for(let l of o.specifiers)a.names.has(l.local.name)||(a.names.add(l.local.name),a.decl.specifiers.push(l))}return n}function Rn(e,t){let n=new Set,o=r.types.isIdentifier(e.tag)&&e.tag.name==="svg",i=ce(e,n,{svg:o});ge(i,{resolver:t.componentResolver,modules:{controlFlowModule:t.controlFlowModule,coreModule:t.libModule,routerModule:t.routerModule},strategyFor:p=>p.load}),he(i);let{code:s,imports:a,templates:l}=$.emit(i,{templateClone:t.templateClone,partialTemplates:t.partialTemplates});for(let p of a)n.add(p);for(let p of n)t.irImports.add(p);Ne(i,t),t.hasLitIR=!0;let c=r.template.expression(ft(s,l,t),{placeholderPattern:!1,plugins:["typescript"]})();return Cn(c,e),c}function Cn(e,t){if(!t.loc)return;let n=new Set,o=i=>{if(!n.has(i)){n.add(i),i.loc||(i.loc=t.loc,i.start=t.start,i.end=t.end);for(let s of r.types.VISITOR_KEYS[i.type]??[]){let a=i[s];if(Array.isArray(a))for(let l of a)l&&typeof l=="object"&&"type"in l&&o(l);else a&&typeof a=="object"&&"type"in a&&o(a)}}};o(e)}function Ne(e,t){if(e.kind==="component"&&e.source&&(e.source.origin==="builtin"?(t.controlFlowComponents.add(e.name),t.needsControlFlowImport=!0):X(e.source.loading)&&!t.resolvedComponents.has(e.name)?t.deferredComponents.set(e.name,{module:e.source.module,export:e.source.export,strategy:e.source.loading}):(t.deferredComponents.delete(e.name),t.resolvedComponents.set(e.name,{module:e.source.module,export:e.source.export}))),(e.kind==="element"||e.kind==="component"||e.kind==="control")&&"props"in e)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)Ne(n,t)}function In(e){return e.map(t=>{if(r.types.isObjectProperty(t)){let n=t.key,o=t.computed,i=t.value;return r.types.objectMethod("get",n,[],r.types.blockStatement([r.types.returnStatement(i)]),o)}return t})}function te(e,t,n,o=!0){let i=e.openingElement,s=e.children,a=gt(i.name),l=r.types.isJSXIdentifier(i.name)&&/^[a-z]/.test(i.name.name),c=Et(i.attributes,t,l,r.types.isJSXIdentifier(i.name)?i.name.name:""),p=c.props,f=c.spreads;l||(p=In(p));let u=ke(s,t,o);if(t.backend==="imperative")return xn(a,l,p,f,u,t);if(u.length>0){let I=u.length===1?u[0]:r.types.arrayExpression(u);p.push(r.types.objectProperty(r.types.identifier("children"),I))}let h;if(f.length>0){let I=p.length>0?r.types.objectExpression(p):r.types.objectExpression([]);t.needsMergeProps=!0,h=r.types.callExpression(r.types.identifier("mergeProps"),[...f,I])}else h=r.types.objectExpression(p);let y=n?"jsxDEV":u.length>1?"jsxs":"jsx",C=[a,h];return n&&C.push(r.types.identifier("undefined"),r.types.booleanLiteral(!1),r.types.identifier("undefined"),r.types.identifier("undefined")),r.types.callExpression(r.types.identifier(y),C)}function wn(e,t,n){let o=e.openingElement,i=e.children,s=gt(o.name),a=r.types.isJSXIdentifier(o.name)&&/^[a-z]/.test(o.name.name),{props:l,spreads:c}=Et(o.attributes,t,a,r.types.isJSXIdentifier(o.name)?o.name.name:""),p=ke(i,t,t.autoShow??!0),f;if(c.length>0){let h=l.length>0?r.types.objectExpression(l):r.types.objectExpression([]);t.needsMergeProps=!0,f=r.types.callExpression(r.types.identifier("mergeProps"),[...c,h])}else f=l.length>0?r.types.objectExpression(l):r.types.nullLiteral();let u=[s,f,...p];return r.types.callExpression(r.types.identifier(n),u)}function de(e,t,n){let{runtime:o,pragmaFrag:i,development:s}=n,a=ke(e.children,t,t.autoShow??!0);if(t.backend==="imperative")return a.length===0?r.types.nullLiteral():dt(a);if(o==="automatic"){let l=s?"jsxDEV":a.length>1?"jsxs":"jsx",c=r.types.objectExpression([r.types.objectProperty(r.types.identifier("children"),a.length===1?a[0]:r.types.arrayExpression(a))]),p=[r.types.identifier("Fragment"),c];return s&&p.push(r.types.identifier("undefined"),r.types.booleanLiteral(!1),r.types.identifier("undefined"),r.types.identifier("undefined")),r.types.callExpression(r.types.identifier(l),p)}else return r.types.callExpression(r.types.identifier(i),a)}function gt(e){if(r.types.isJSXIdentifier(e)){let t=e.name;return t[0]===t[0].toLowerCase()?r.types.stringLiteral(t):r.types.identifier(t)}return r.types.isJSXMemberExpression(e)?ht(e):r.types.isJSXNamespacedName(e)?r.types.stringLiteral(`${e.namespace.name}:${e.name.name}`):r.types.stringLiteral("div")}function ht(e){let t;return r.types.isJSXIdentifier(e.object)?t=r.types.identifier(e.object.name):t=ht(e.object),r.types.memberExpression(t,r.types.identifier(e.property.name))}function Nn(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)}function Et(e,t,n=!0,o=""){let i=[],s=[],a=gn[o],l=[];t.pendingLoad=void 0;for(let c of e)if(r.types.isJSXSpreadAttribute(c))s.push(c.argument);else if(r.types.isJSXAttribute(c)){let p=kn(c.name);if(q(p)){t.pendingLoad=Sn(p,c);continue}if(r.types.isJSXNamespacedName(c.name)&&c.name.namespace.name==="use"){let P=r.types.identifier(c.name.name.name),W=c.value===null?null:at(c.value,t,p,n);l.push(r.types.arrayExpression(W?[P,r.types.arrowFunctionExpression([],W)]:[P]));continue}let f=at(c.value,t,p,n);if(pt.test(p)){let P=p.slice(2).toLowerCase();ut.includes(P)&&t.delegatedEvents.add(P)}let u=Nn(p)?r.types.identifier(p):r.types.stringLiteral(p),h=c.value,y=r.types.isJSXElement(h)||r.types.isJSXFragment(h)||r.types.isJSXExpressionContainer(h)&&(r.types.isJSXElement(h.expression)||r.types.isJSXFragment(h.expression)),C=!n&&p===a,I=r.types.isJSXExpressionContainer(h)&&!r.types.isJSXEmptyExpression(h.expression)?h.expression:null,V=!n&&!!I&&xt(I,p);!n&&y||C||V?i.push(r.types.objectMethod("get",u,[],r.types.blockStatement([r.types.returnStatement(f)]))):i.push(r.types.objectProperty(u,f))}return l.length>0&&i.push(r.types.objectProperty(r.types.identifier("use"),r.types.arrayExpression(l))),{props:i,spreads:s}}function kn(e){return r.types.isJSXIdentifier(e)?e.name==="class"?"className":e.name:r.types.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:"unknown"}function at(e,t,n="",o=!0){if(e===null)return r.types.booleanLiteral(!0);if(r.types.isStringLiteral(e))return e.value.includes(`
|
|
2
2
|
`)?r.types.stringLiteral(e.value.replace(/\s+/g," ").trim()):e;if(r.types.isJSXExpressionContainer(e)){if(r.types.isJSXEmptyExpression(e.expression))return r.types.booleanLiteral(!0);let i=e.expression;return o&&xt(i,n)?r.types.arrowFunctionExpression([],i):i}return r.types.isJSXElement(e)?te(e,t,!1,t.autoShow??!0):r.types.isJSXFragment(e)?de(e,t,{runtime:"automatic",pragmaFrag:"Fragment",development:!1}):r.types.booleanLiteral(!0)}function xt(e,t){return pt.test(t)||t.startsWith("on:")||t==="ref"||t.startsWith("use:")||r.types.isArrowFunctionExpression(e)||r.types.isFunctionExpression(e)||r.types.isIdentifier(e)||r.types.isStringLiteral(e)||r.types.isNumericLiteral(e)||r.types.isBooleanLiteral(e)||r.types.isNullLiteral(e)?!1:!!(r.types.isCallExpression(e)||r.types.isOptionalCallExpression(e)||r.types.isMemberExpression(e)||r.types.isOptionalMemberExpression(e)||r.types.isLogicalExpression(e)||r.types.isConditionalExpression(e)||r.types.isBinaryExpression(e)||r.types.isUnaryExpression(e)||r.types.isTemplateLiteral(e)||r.types.isObjectExpression(e)||r.types.isArrayExpression(e))}function Ln(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let i=0;i<t.length;i++)/[^ \t]/.test(t[i])&&(n=i);let o="";for(let i=0;i<t.length;i++){let s=t[i].replace(/\t/g," ");i!==0&&(s=s.replace(/^ +/,"")),i!==t.length-1&&(s=s.replace(/ +$/,"")),s&&(i!==n&&(s+=" "),o+=s)}return o}function ke(e,t,n=!0){let o=[];for(let i of e)if(r.types.isJSXText(i)){let s=Ln(i.value);s&&o.push(r.types.stringLiteral(s))}else if(r.types.isJSXExpressionContainer(i)){if(!r.types.isJSXEmptyExpression(i.expression)){let s=i.expression;if(n){let a=Mn(s,t)??Jn(s,t);if(a){o.push(a);continue}}else{let a=Tn(s,t);if(a){o.push(a);continue}}Xn(s)?o.push(r.types.arrowFunctionExpression([],s)):o.push(s)}}else r.types.isJSXElement(i)?o.push(te(i,t,!1,t.autoShow??!0)):r.types.isJSXFragment(i)?o.push(de(i,t,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})):r.types.isJSXSpreadChild(i)&&o.push(i.expression);return o}function Mn(e,t){if(!r.types.isArrowFunctionExpression(e)||e.params.length!==0||e.async)return null;let n=e.body;if(r.types.isLogicalExpression(n)&&n.operator==="&&"){let o=T(n.right);if(o)return ee(O(n.left),o,null,t)}if(r.types.isConditionalExpression(n)){let o=T(n.consequent);if(o){let i=Le(n.alternate,t);return ee(O(n.test),o,i,t,!0)}}return null}function Jn(e,t){if(r.types.isLogicalExpression(e)&&e.operator==="&&"){let n=T(e.right);if(n)return ee(O(e.left),n,null,t)}if(r.types.isConditionalExpression(e)){let n=T(e.consequent);if(n){let o=Le(e.alternate,t);return ee(O(e.test),n,o,t)}}return null}function Tn(e,t){let n=r.types.isArrowFunctionExpression(e)&&e.params.length===0&&!e.async&&r.types.isExpression(e.body)?e.body:e;if(r.types.isConditionalExpression(n)){let o=O(n.test),s=T(n.consequent)??n.consequent,l=T(n.alternate)??n.alternate,c=r.types.conditionalExpression(o,s,l);return we(n.consequent)||we(n.alternate)?null:(t.needsCreateMemo=!0,r.types.callExpression(r.types.identifier("createMemo"),[r.types.arrowFunctionExpression([],c)]))}if(r.types.isLogicalExpression(n)&&n.operator==="&&"){let o=O(n.left),s=T(n.right)??n.right,a=r.types.logicalExpression("&&",o,s);return we(n.right)?null:(t.needsCreateMemo=!0,r.types.callExpression(r.types.identifier("createMemo"),[r.types.arrowFunctionExpression([],a)]))}return null}function Le(e,t){if(Pn(e))return null;let n=T(e);if(n)return St(n,t);if(r.types.isConditionalExpression(e)){let o=e,i=T(o.consequent);if(i){let s=Le(o.alternate,t);return ee(O(o.test),i,s,t)}}return e}function lt(e){return r.types.isJSXElement(e)||r.types.isJSXFragment(e)}function we(e){let t=T(e);if(!t||!r.types.isJSXElement(t))return!1;let n=t.openingElement.name;return r.types.isJSXIdentifier(n)&&ue.has(n.name)}function T(e){return lt(e)?e:r.types.isArrowFunctionExpression(e)&&e.params.length===0&&!e.async&<(e.body)?e.body:null}function O(e){return r.types.isArrowFunctionExpression(e)&&e.params.length===0&&!e.async&&r.types.isExpression(e.body)?e.body:e}function Pn(e){return r.types.isNullLiteral(e)||r.types.isIdentifier(e)&&e.name==="undefined"||r.types.isBooleanLiteral(e)&&e.value===!1}function St(e,t){return r.types.isJSXElement(e)?te(e,t,!1,t.autoShow??!0):de(e,t,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})}function ee(e,t,n,o,i=!1){o.controlFlowComponents.add("Show"),o.needsControlFlowImport=!0;let s=St(t,o),a=[r.types.objectProperty(r.types.identifier("when"),r.types.arrowFunctionExpression([],e)),r.types.objectProperty(r.types.identifier("children"),s)];return n&&a.push(r.types.objectProperty(r.types.identifier("fallback"),n)),mt(r.types.identifier("Show"),r.types.objectExpression(a),o)}function Xn(e){return r.types.isMemberExpression(e)||r.types.isOptionalMemberExpression(e)?!(!e.computed&&r.types.isIdentifier(e.property,{name:"children"})):r.types.isCallExpression(e)||r.types.isOptionalCallExpression(e)?!0:r.types.isIdentifier(e)?!1:!!(r.types.isLogicalExpression(e)||r.types.isConditionalExpression(e)||r.types.isBinaryExpression(e)||r.types.isUnaryExpression(e)||r.types.isTemplateLiteral(e))}function vt(e,t){let n=e.openingElement;if(!r.types.isJSXIdentifier(n.name))return!1;let o=n.name.name;if(o[0]!==o[0].toLowerCase())return!1;for(let i of n.attributes){if(r.types.isJSXSpreadAttribute(i))return!1;if(r.types.isJSXAttribute(i)){let s=i.value;if(r.types.isJSXExpressionContainer(s)&&!r.types.isStringLiteral(s.expression)&&!r.types.isNumericLiteral(s.expression))return!1}}for(let i of e.children)if(r.types.isJSXElement(i)&&!vt(i,t)||r.types.isJSXExpressionContainer(i))return!1;return!0}function $n(e,t){let n=`_$static${t.staticCounter++}`,o=te(e,t,!1);return t.staticElements.set(n,o),r.types.identifier(n)}function An(e,t){let n=e.openingElement.name.name;return n==="Show"?jn(e,t):n==="For"?On(e,t):null}function jn(e,t){return null}function On(e,t){return null}var Fn=z;function Dn(e){return[z,e]}function me(e={}){return{plugins:[[z,{runtime:"automatic",importSource:"@fluixi/jsx",development:!1,detectReactivity:!0,useLitHTML:!0,hoistStatics:!0,delegateEvents:!0,optimizeControlFlow:!0,sourceMaps:!0,...e}]]}}var _n={production:me({development:!1,hoistStatics:!0,delegateEvents:!0,optimizeControlFlow:!0}),development:me({development:!0,hoistStatics:!1,sourceMaps:!0}),minimal:me({detectReactivity:!1,useLitHTML:!1,hoistStatics:!1,delegateEvents:!1,optimizeControlFlow:!1})};
|