@fluixi/compiler 1.0.0-alpha.53
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/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/babel-OGRQKOZA.mjs +2 -0
- package/dist/chunk-3SAEGOMQ.mjs +1 -0
- package/dist/codegen/backend.cjs +1 -0
- package/dist/codegen/backend.d.ts +22 -0
- package/dist/codegen/backend.d.ts.map +1 -0
- package/dist/codegen/backend.js +1 -0
- package/dist/codegen/backend.mjs +0 -0
- package/dist/codegen/backends/imperative.cjs +1 -0
- package/dist/codegen/backends/imperative.d.ts +3 -0
- package/dist/codegen/backends/imperative.d.ts.map +1 -0
- package/dist/codegen/backends/imperative.js +152 -0
- package/dist/codegen/backends/imperative.mjs +1 -0
- package/dist/codegen/contract.cjs +1 -0
- package/dist/codegen/contract.d.ts +25 -0
- package/dist/codegen/contract.d.ts.map +1 -0
- package/dist/codegen/contract.js +30 -0
- package/dist/codegen/contract.mjs +1 -0
- package/dist/frontend/babel/build-ir.cjs +1 -0
- package/dist/frontend/babel/build-ir.d.ts +23 -0
- package/dist/frontend/babel/build-ir.d.ts.map +1 -0
- package/dist/frontend/babel/build-ir.js +224 -0
- package/dist/frontend/babel/build-ir.mjs +1 -0
- package/dist/frontend/babel/index.cjs +2 -0
- package/dist/frontend/babel/index.d.ts +34 -0
- package/dist/frontend/babel/index.d.ts.map +1 -0
- package/dist/frontend/babel/index.js +65 -0
- package/dist/frontend/babel/index.mjs +2 -0
- package/dist/frontend/babel/plugin.cjs +2 -0
- package/dist/frontend/babel/plugin.d.ts +122 -0
- package/dist/frontend/babel/plugin.d.ts.map +1 -0
- package/dist/frontend/babel/plugin.js +1509 -0
- package/dist/frontend/babel/plugin.mjs +2 -0
- package/dist/frontend/babel/server-functions.cjs +1 -0
- package/dist/frontend/babel/server-functions.d.ts +11 -0
- package/dist/frontend/babel/server-functions.d.ts.map +1 -0
- package/dist/frontend/babel/server-functions.js +88 -0
- package/dist/frontend/babel/server-functions.mjs +1 -0
- package/dist/frontend/babel/types.cjs +1 -0
- package/dist/frontend/babel/types.d.ts +34 -0
- package/dist/frontend/babel/types.d.ts.map +1 -0
- package/dist/frontend/babel/types.js +1 -0
- package/dist/frontend/babel/types.mjs +0 -0
- package/dist/frontend/types.cjs +1 -0
- package/dist/frontend/types.d.ts +26 -0
- package/dist/frontend/types.d.ts.map +1 -0
- package/dist/frontend/types.js +1 -0
- package/dist/frontend/types.mjs +0 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.mjs +1 -0
- package/dist/integrations.cjs +12 -0
- package/dist/integrations.d.ts +251 -0
- package/dist/integrations.d.ts.map +1 -0
- package/dist/integrations.js +790 -0
- package/dist/integrations.mjs +11 -0
- package/dist/ir/nodes.cjs +1 -0
- package/dist/ir/nodes.d.ts +80 -0
- package/dist/ir/nodes.d.ts.map +1 -0
- package/dist/ir/nodes.js +1 -0
- package/dist/ir/nodes.mjs +0 -0
- package/dist/options.cjs +1 -0
- package/dist/options.d.ts +18 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +9 -0
- package/dist/options.mjs +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{declare as Me}from"@babel/helper-plugin-utils";import{types as e,template as Ne}from"@babel/core";import{types as u,traverse as be,template as ye}from"@babel/core";import K from"@babel/generator";var z={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Ye={version:2,module:"@fluixi/dom",symbols:[...z.symbols,"template","cloneTemplate","walk"]};var Ee={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function ge(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function H(t){return ge(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 Se(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function he(t,n,r){let i=t.filter(l=>l.kind==="spread"),o=t.filter(l=>l.kind!=="spread").map(l=>`${H(l.name)}: ${xe(l)}`);n!=null&&o.push(`children: ${n}`);let a=`{ ${o.join(", ")} }`;return i.length>0?(r.add("mergeProps"),`mergeProps(${i.map(l=>l.expr).join(", ")}, ${a})`):a}function U(t,n){return t.length===1?$(t[0],n):`[${t.map(r=>$(r,n)).join(", ")}]`}function Z(t,n,r,i){i.add("createMemo"),i.add("createComponent");let s=n.filter(p=>p.kind==="spread"),a=n.filter(p=>p.kind!=="spread").map(p=>`get ${H(p.name)}() { return ${Se(p)}; }`);r.length>0&&a.push(`get children() { return ${U(r,i)}; }`);let l=`{ ${a.join(", ")} }`;return s.length>0&&(i.add("mergeProps"),l=`mergeProps(${s.map(p=>p.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${t}, ${l}))`}function $(t,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,n);case"component":return Z(t.name,t.props,t.children,n);case"control":{let r=Ee[t.control]??t.control;return n.add(r),Z(r,t.props,t.children,n)}case"element":{n.add("createNativeElement");let r=JSON.stringify(t.tag),i="_el$",s=[],o=t.svg?`${r}, true`:r;if(s.push(`const ${i} = createNativeElement(${o});`),t.props.length>0){n.add("spread");let a=t.svg?", isSVG: true":"";s.push(`spread({ element: ${i}, props: ${he(t.props,null,n)}${a} });`)}for(let a of t.children){n.add("insert");let l=$(a,n),p=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";s.push(p?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return s.push(`return ${i};`),`(() => { ${s.join(" ")} })()`}}}var T={name:"imperative",contract:z,emit(t,n){let r=new Set;return{code:$(t,r),imports:Array.from(r)}}};var Je=K.default??K;function Y(t){return Je(t,{concise:!0}).code}function Ce(t,n){let r=u.cloneNode(t,!0),i=u.file(u.program([u.expressionStatement(r)])),s=!1;return be(i,{"JSXElement|JSXFragment"(o){let a=o.node,{code:l,imports:p}=T.emit(A(a,n),{});for(let b of p)n.add(b);let E=ye.expression(l,{placeholderPattern:!1})();o.replaceWith(E),o.skip(),s=!0}}),s?i.program.body[0].expression:t}function D(t,n){return Y(Ce(t,n))}var Xe=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),we=/^on[A-Z]/,ve=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Fe(t){if(u.isJSXIdentifier(t)){let n=t.name[0]!==t.name[0].toLowerCase();return{tag:t.name,component:n}}return u.isJSXMemberExpression(t)?{tag:Y(t),component:!0}:u.isJSXNamespacedName(t)?{tag:`${t.namespace.name}:${t.name.name}`,component:!1}:{tag:"div",component:!1}}function je(t){return u.isJSXIdentifier(t)?t.name==="class"?"className":t.name:u.isJSXNamespacedName(t)?`${t.namespace.name}:${t.name.name}`:"unknown"}function F(t){return u.isCallExpression(t)||u.isOptionalCallExpression(t)?!0:u.isMemberExpression(t)||u.isOptionalMemberExpression(t)?!(!t.computed&&u.isIdentifier(t.property,{name:"children"})):u.isConditionalExpression(t)?F(t.test)||F(t.consequent)||F(t.alternate):u.isLogicalExpression(t)||u.isBinaryExpression(t)?F(t.left)||F(t.right):u.isTemplateLiteral(t)?t.expressions.some(n=>F(n)):!1}function Ie(t,n){let r=je(t.name),i=we.test(r),o={name:r,kind:i?"event":"attr"};i&&(o.event={name:r.slice(2).toLowerCase(),delegated:ve.has(r.slice(2).toLowerCase())});let a=t.value;if(a==null)return o.literal=!0,o;if(u.isStringLiteral(a))return o.literal=a.value,o;if(u.isJSXExpressionContainer(a)&&!u.isJSXEmptyExpression(a.expression)){let l=a.expression;return u.isStringLiteral(l)||u.isNumericLiteral(l)||u.isBooleanLiteral(l)?(o.literal=l.value,o):(o.expr=D(l,n),o.reactive=i?!1:F(l),(u.isJSXElement(l)||u.isJSXFragment(l))&&(o.jsxElement=!0),o)}return o.literal=!0,o}function Pe(t,n){let r=[];for(let i of t)u.isJSXSpreadAttribute(i)?r.push({name:"",kind:"spread",expr:D(i.argument,n)}):u.isJSXAttribute(i)&&r.push(Ie(i,n));return r}function Le(t){let n=t.split(/\r\n|\n|\r/),r=0;for(let s=0;s<n.length;s++)/[^ \t]/.test(n[s])&&(r=s);let i="";for(let s=0;s<n.length;s++){let o=n[s].replace(/\t/g," ");s!==0&&(o=o.replace(/^ +/,"")),s!==n.length-1&&(o=o.replace(/ +$/,"")),o&&(s!==r&&(o+=" "),i+=o)}return i}function Q(t,n){let r=[];for(let i of t)if(u.isJSXText(i)){let s=Le(i.value);s&&r.push({kind:"text",value:s})}else if(u.isJSXExpressionContainer(i)){if(!u.isJSXEmptyExpression(i.expression)){let s=i.expression;r.push({kind:"expr",code:D(s,n),reactive:F(s)})}}else u.isJSXElement(i)||u.isJSXFragment(i)?r.push(A(i,n)):u.isJSXSpreadChild(i)&&r.push({kind:"expr",code:D(i.expression,n),reactive:!1});return r}function A(t,n=new Set){if(u.isJSXFragment(t))return{kind:"fragment",children:Q(t.children,n)};let{tag:r,component:i}=Fe(t.openingElement.name),s=Pe(t.openingElement.attributes,n),o=Q(t.children,n);return i?{kind:"component",name:r,props:s,children:o}:{kind:"element",tag:r,svg:Xe.has(r),props:s,children:o,static:!1}}var re=new Set(["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary","Suspense"]),Ae={Show:"when",For:"each",Index:"each",Match:"when"};var ie=/^on[A-Z]/,se=["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave"],ft=Me((t,n={})=>{t.assertVersion(7);let{runtime:r="automatic",importSource:i="@fluixi/jsx",pragma:s="jsx",pragmaFrag:o="Fragment",development:a=!1,detectReactivity:l=!0,useLitHTML:p=!0,hoistStatics:E=!0,delegateEvents:b=!0,delegatedEvents:m=se,optimizeControlFlow:y=!0,sourceMaps:I=!0,signalModule:J="@fluixi/dom",controlFlowModule:v="@fluixi/dom",reactiveModule:L="@fluixi/reactive/signal",autoShowTransform:G=!1,backend:X="imperative",codegen:M="inline"}=n,de={backend:X,codegen:M,irImports:new Set,libModule:"@fluixi/core",hasJSX:!1,hasReactivity:!1,hasLitHTML:!1,needsSignalImport:!1,needsControlFlowImport:!1,needsCreateMemo:!1,controlFlowComponents:new Set,delegatedEvents:new Set,staticElements:new Map,staticCounter:0};return{name:"@fluixi/babel-plugin-jsx",manipulateOptions(f,c){c.plugins.push("jsx","typescript")},pre(f){Object.assign(f,de)},visitor:{ImportDeclaration(f,c){f.node.source.value==="@fluixi/core/rx"&&(f.node.source=e.stringLiteral("@fluixi/reactive"))},Program:{enter(f,c){Object.assign(c,{hasJSX:!1,hasReactivity:!1,hasLitHTML:!1,needsSignalImport:!1,needsLitrxImport:!1,needsControlFlowImport:!1,needsCreateMemo:!1,controlFlowComponents:new Set,delegatedEvents:new Set,staticElements:new Map,autoShow:G,staticCounter:0,libModule:"@fluixi/core",backend:X,codegen:M,irImports:new Set,needsCreateNativeElement:!1,needsInsert:!1,needsSpread:!1,needsCreateComponent:!1,needsMergeProps:!1})},exit(f,c){let d=[];if(c.hasJSX||(c.needsSignalImport&&d.push(e.importDeclaration([e.importSpecifier(e.identifier("signal"),e.identifier("signal"))],e.stringLiteral(J))),c.needsLitrxImport&&!f.scope.hasBinding("litrx")&&d.push(e.importDeclaration([e.importSpecifier(e.identifier("litrx"),e.identifier("litrx"))],e.stringLiteral(c.libModule)))),c.hasJSX){if(X==="imperative"&&M==="ir"){let x=new Set(["Show","For","Index","Switch","Match","Dynamic","ErrorBoundary","Portal","Suspense"]),S=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]),g=Array.from(c.irImports),w=h=>e.importSpecifier(e.identifier(h),e.identifier(h)),P=h=>!f.scope.hasBinding(h),_=g.filter(h=>S.has(h)&&P(h)),k=g.filter(h=>!x.has(h)&&!S.has(h)&&P(h)),N=g.filter(h=>x.has(h)&&P(h));_.length>0&&d.push(e.importDeclaration(_.map(w),e.stringLiteral(L))),k.length>0&&d.push(e.importDeclaration(k.map(w),e.stringLiteral(J))),N.length>0&&d.push(e.importDeclaration(N.map(w),e.stringLiteral(v)))}else if(X==="imperative"){let S=[[!!c.needsCreateNativeElement,"createNativeElement"],[!!c.needsSpread,"spread"],[!!c.needsInsert,"insert"],[!!c.needsCreateComponent,"createComponent"],[!!c.needsMergeProps,"mergeProps"]].filter(([g,w])=>g&&!f.scope.hasBinding(w)).map(([,g])=>e.importSpecifier(e.identifier(g),e.identifier(g)));S.length>0&&d.push(e.importDeclaration(S,e.stringLiteral(J)))}else if(r==="automatic"){let x=[e.importSpecifier(e.identifier("jsx"),e.identifier("jsx")),e.importSpecifier(e.identifier("jsxs"),e.identifier("jsxs")),e.importSpecifier(e.identifier("Fragment"),e.identifier("Fragment"))];a&&x.push(e.importSpecifier(e.identifier("jsxDEV"),e.identifier("jsxDEV"))),c.needsMergeProps&&x.push(e.importSpecifier(e.identifier("mergeProps"),e.identifier("mergeProps"))),d.push(e.importDeclaration(x,e.stringLiteral(i)))}if(c.needsCreateMemo&&!f.scope.hasBinding("createMemo")&&d.push(e.importDeclaration([e.importSpecifier(e.identifier("createMemo"),e.identifier("createMemo"))],e.stringLiteral(X==="imperative"?L:c.libModule??"@fluixi/core"))),c.needsControlFlowImport&&c.controlFlowComponents.size>0){let x=Array.from(c.controlFlowComponents).filter(S=>!f.scope.hasBinding(S));if(x.length>0){let S=x.map(g=>e.importSpecifier(e.identifier(g),e.identifier(g)));d.push(e.importDeclaration(S,e.stringLiteral(v)))}}if(b&&c.delegatedEvents.size>0){d.push(e.importDeclaration([e.importSpecifier(e.identifier("delegateEvents"),e.identifier("delegateEvents"))],e.stringLiteral(X==="imperative"?J:"@fluixi/jsx")));let x=e.arrayExpression(Array.from(c.delegatedEvents).map(g=>e.stringLiteral(g))),S=e.expressionStatement(e.callExpression(e.identifier("delegateEvents"),[x]));f.node.body.unshift(S)}if(E&&c.staticElements.size>0){let x=[];c.staticElements.forEach((S,g)=>{x.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(g),S)]))}),f.node.body.unshift(...x)}}d.length>0&&f.node.body.unshift(...d)}},JSXElement(f,c){if(c.hasJSX=!0,X==="imperative"&&M==="ir"){f.replaceWith(te(f.node,c));return}let d=f.node,x=d.openingElement;if(e.isJSXIdentifier(x.name)&&re.has(x.name.name)&&(c.controlFlowComponents.add(x.name.name),y)){let g=Ue(d,c);if(g){f.replaceWith(g);return}}if(E&&X!=="imperative"&&me(d,c)){let g=He(d,c);if(g){f.replaceWith(g);return}}let S=Re(d,c,{runtime:r,pragma:s,development:a,detectReactivity:l,useLitHTML:p,autoShow:G});f.replaceWith(S)},JSXFragment(f,c){if(c.hasJSX=!0,X==="imperative"&&M==="ir"){f.replaceWith(te(f.node,c));return}let d=V(f.node,c,{runtime:r,pragmaFrag:o,development:a});f.replaceWith(d)},CallExpression(f,c){if(!l)return;let d=f.node.callee;d.name,e.isIdentifier(d)&&(d.name==="createSignal"||d.name==="createStore"||d.name==="useContext"||d.name==="useLocation")&&(c.hasReactivity=!0)},JSXExpressionContainer(f){},TaggedTemplateExpression(f,c){let{tag:d,quasi:x}=f.node;f.get("quasi").get("expressions").forEach((S,g)=>{let w=S.node,P=x.quasis[g].value.raw;if(P.trim().endsWith("=")||P.match(/@[\w-]+$/))return;let k=!1,N=!1;if(e.isMemberExpression(w)){let h=w.property;e.isIdentifier(h)&&(h.name=h.name.replace("$",""),c.needsLitrxImport=!0,N=!0)}(k||N)&&S.replaceWith(e.callExpression(e.identifier("((window as any).Fluixi.litrx || litrx)"),[e.arrowFunctionExpression([],w)]))})}}}});function Re(t,n,r){let{runtime:i,pragma:s,development:o,autoShow:a=!0}=r;return i==="automatic"?O(t,n,o,a):Te(t,n,s)}var Oe=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]);function ee(t,n,r){return n.length>0?(r.needsMergeProps=!0,e.callExpression(e.identifier("mergeProps"),[...n,e.objectExpression(t)])):e.objectExpression(t)}function oe(t){return t.length===1?t[0]:e.arrayExpression(t)}function ke(t,n,r,i,s,o){if(!n){let m=[...r];return s.length>0&&m.push(e.objectMethod("get",e.identifier("children"),[],e.blockStatement([e.returnStatement(oe(s))]))),ae(t,ee(m,i,o),o)}let a=t.value,l=Oe.has(a),p=e.identifier("_el$"),E=[];o.needsCreateNativeElement=!0;let b=[t];if(l&&b.push(e.booleanLiteral(!0)),E.push(e.variableDeclaration("const",[e.variableDeclarator(p,e.callExpression(e.identifier("createNativeElement"),b))])),r.length>0||i.length>0){o.needsSpread=!0;let m=[e.objectProperty(e.identifier("element"),p),e.objectProperty(e.identifier("props"),ee(r,i,o))];l&&m.push(e.objectProperty(e.identifier("isSVG"),e.booleanLiteral(!0))),E.push(e.expressionStatement(e.callExpression(e.identifier("spread"),[e.objectExpression(m)])))}if(s.length>0){o.needsInsert=!0;for(let m of s){let I=e.isArrowFunctionExpression(m)||e.isFunctionExpression(m)||e.isCallExpression(m)&&e.isIdentifier(m.callee)&&m.callee.name==="createMemo"?[e.cloneNode(p),m,e.nullLiteral()]:[e.cloneNode(p),m];E.push(e.expressionStatement(e.callExpression(e.identifier("insert"),I)))}}return E.push(e.returnStatement(p)),e.callExpression(e.arrowFunctionExpression([],e.blockStatement(E)),[])}function ae(t,n,r){return r.backend==="imperative"?(r.needsCreateComponent=!0,r.needsCreateMemo=!0,e.callExpression(e.identifier("createMemo"),[e.arrowFunctionExpression([],e.callExpression(e.identifier("createComponent"),[t,n]))])):e.callExpression(e.identifier("jsx"),[t,n])}function te(t,n){let r=new Set,i=A(t,r),{code:s,imports:o}=T.emit(i,{});for(let a of o)r.add(a);for(let a of r)n.irImports.add(a);return Ne.expression(s,{placeholderPattern:!1})()}function $e(t){return t.map(n=>{if(e.isObjectProperty(n)){let r=n.key,i=n.computed,s=n.value;return e.objectMethod("get",r,[],e.blockStatement([e.returnStatement(s)]),i)}return n})}function O(t,n,r,i=!0){let s=t.openingElement,o=t.children,a=le(s.name),l=e.isJSXIdentifier(s.name)&&/^[a-z]/.test(s.name.name),p=pe(s.attributes,n,l,e.isJSXIdentifier(s.name)?s.name.name:""),E=p.props,b=p.spreads;l||(E=$e(E));let m=W(o,n,i);if(n.backend==="imperative")return ke(a,l,E,b,m,n);if(m.length>0){let v=m.length===1?m[0]:e.arrayExpression(m);E.push(e.objectProperty(e.identifier("children"),v))}let y;if(b.length>0){let v=E.length>0?e.objectExpression(E):e.objectExpression([]);n.needsMergeProps=!0,y=e.callExpression(e.identifier("mergeProps"),[...b,v])}else y=e.objectExpression(E);let I=r?"jsxDEV":m.length>1?"jsxs":"jsx",J=[a,y];return r&&J.push(e.identifier("undefined"),e.booleanLiteral(!1),e.identifier("undefined"),e.identifier("undefined")),e.callExpression(e.identifier(I),J)}function Te(t,n,r){let i=t.openingElement,s=t.children,o=le(i.name),a=e.isJSXIdentifier(i.name)&&/^[a-z]/.test(i.name.name),{props:l,spreads:p}=pe(i.attributes,n,a,e.isJSXIdentifier(i.name)?i.name.name:""),E=W(s,n,n.autoShow??!0),b;if(p.length>0){let y=l.length>0?e.objectExpression(l):e.objectExpression([]);n.needsMergeProps=!0,b=e.callExpression(e.identifier("mergeProps"),[...p,y])}else b=l.length>0?e.objectExpression(l):e.nullLiteral();let m=[o,b,...E];return e.callExpression(e.identifier(r),m)}function V(t,n,r){let{runtime:i,pragmaFrag:s,development:o}=r,a=W(t.children,n,n.autoShow??!0);if(n.backend==="imperative")return a.length===0?e.nullLiteral():oe(a);if(i==="automatic"){let l=o?"jsxDEV":a.length>1?"jsxs":"jsx",p=e.objectExpression([e.objectProperty(e.identifier("children"),a.length===1?a[0]:e.arrayExpression(a))]),E=[e.identifier("Fragment"),p];return o&&E.push(e.identifier("undefined"),e.booleanLiteral(!1),e.identifier("undefined"),e.identifier("undefined")),e.callExpression(e.identifier(l),E)}else return e.callExpression(e.identifier(s),a)}function le(t){if(e.isJSXIdentifier(t)){let n=t.name;return n[0]===n[0].toLowerCase()?e.stringLiteral(n):e.identifier(n)}return e.isJSXMemberExpression(t)?ce(t):e.isJSXNamespacedName(t)?e.stringLiteral(`${t.namespace.name}:${t.name.name}`):e.stringLiteral("div")}function ce(t){let n;return e.isJSXIdentifier(t.object)?n=e.identifier(t.object.name):n=ce(t.object),e.memberExpression(n,e.identifier(t.property.name))}function De(t){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t)}function pe(t,n,r=!0,i=""){let s=[],o=[],a=Ae[i];for(let l of t)if(e.isJSXSpreadAttribute(l))o.push(l.argument);else if(e.isJSXAttribute(l)){let p=Ve(l.name),E=_e(l.value,n,p,r);if(ie.test(p)){let L=p.slice(2).toLowerCase();se.includes(L)&&n.delegatedEvents.add(L)}let b=De(p)?e.identifier(p):e.stringLiteral(p),m=l.value,y=e.isJSXElement(m)||e.isJSXFragment(m)||e.isJSXExpressionContainer(m)&&(e.isJSXElement(m.expression)||e.isJSXFragment(m.expression)),I=!r&&p===a,J=e.isJSXExpressionContainer(m)&&!e.isJSXEmptyExpression(m.expression)?m.expression:null,v=!r&&!!J&&ue(J,p);!r&&y||I||v?s.push(e.objectMethod("get",b,[],e.blockStatement([e.returnStatement(E)]))):s.push(e.objectProperty(b,E))}return{props:s,spreads:o}}function Ve(t){return e.isJSXIdentifier(t)?t.name==="class"?"className":t.name:e.isJSXNamespacedName(t)?`${t.namespace.name}:${t.name.name}`:"unknown"}function _e(t,n,r="",i=!0){if(t===null)return e.booleanLiteral(!0);if(e.isStringLiteral(t))return t.value.includes(`
|
|
2
|
+
`)?e.stringLiteral(t.value.replace(/\s+/g," ").trim()):t;if(e.isJSXExpressionContainer(t)){if(e.isJSXEmptyExpression(t.expression))return e.booleanLiteral(!0);let s=t.expression;return i&&ue(s,r)?e.arrowFunctionExpression([],s):s}return e.isJSXElement(t)?O(t,n,!1,n.autoShow??!0):e.isJSXFragment(t)?V(t,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1}):e.booleanLiteral(!0)}function ue(t,n){return ie.test(n)||n.startsWith("on:")||n==="ref"||n.startsWith("use:")||e.isArrowFunctionExpression(t)||e.isFunctionExpression(t)||e.isIdentifier(t)||e.isStringLiteral(t)||e.isNumericLiteral(t)||e.isBooleanLiteral(t)||e.isNullLiteral(t)?!1:!!(e.isCallExpression(t)||e.isOptionalCallExpression(t)||e.isMemberExpression(t)||e.isOptionalMemberExpression(t)||e.isLogicalExpression(t)||e.isConditionalExpression(t)||e.isBinaryExpression(t)||e.isUnaryExpression(t)||e.isTemplateLiteral(t)||e.isObjectExpression(t)||e.isArrayExpression(t))}function ze(t){let n=t.split(/\r\n|\n|\r/),r=0;for(let s=0;s<n.length;s++)/[^ \t]/.test(n[s])&&(r=s);let i="";for(let s=0;s<n.length;s++){let o=n[s].replace(/\t/g," ");s!==0&&(o=o.replace(/^ +/,"")),s!==n.length-1&&(o=o.replace(/ +$/,"")),o&&(s!==r&&(o+=" "),i+=o)}return i}function W(t,n,r=!0){let i=[];for(let s of t)if(e.isJSXText(s)){let o=ze(s.value);o&&i.push(e.stringLiteral(o))}else if(e.isJSXExpressionContainer(s)){if(!e.isJSXEmptyExpression(s.expression)){let o=s.expression;if(r){let a=Be(o,n)??We(o,n);if(a){i.push(a);continue}}else{let a=qe(o,n);if(a){i.push(a);continue}}Ze(o)?i.push(e.arrowFunctionExpression([],o)):i.push(o)}}else e.isJSXElement(s)?i.push(O(s,n,!1,n.autoShow??!0)):e.isJSXFragment(s)?i.push(V(s,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})):e.isJSXSpreadChild(s)&&i.push(s.expression);return i}function Be(t,n){if(!e.isArrowFunctionExpression(t)||t.params.length!==0||t.async)return null;let r=t.body;if(e.isLogicalExpression(r)&&r.operator==="&&"){let i=C(r.right);if(i)return R(j(r.left),i,null,n)}if(e.isConditionalExpression(r)){let i=C(r.consequent);if(i){let s=q(r.alternate,n);return R(j(r.test),i,s,n,!0)}}return null}function We(t,n){if(e.isLogicalExpression(t)&&t.operator==="&&"){let r=C(t.right);if(r)return R(j(t.left),r,null,n)}if(e.isConditionalExpression(t)){let r=C(t.consequent);if(r){let i=q(t.alternate,n);return R(j(t.test),r,i,n)}}return null}function qe(t,n){let r=e.isArrowFunctionExpression(t)&&t.params.length===0&&!t.async&&e.isExpression(t.body)?t.body:t;if(e.isConditionalExpression(r)){let i=j(r.test),o=C(r.consequent)??r.consequent,l=C(r.alternate)??r.alternate,p=e.conditionalExpression(i,o,l);return B(r.consequent)||B(r.alternate)?null:(n.needsCreateMemo=!0,e.callExpression(e.identifier("createMemo"),[e.arrowFunctionExpression([],p)]))}if(e.isLogicalExpression(r)&&r.operator==="&&"){let i=j(r.left),o=C(r.right)??r.right,a=e.logicalExpression("&&",i,o);return B(r.right)?null:(n.needsCreateMemo=!0,e.callExpression(e.identifier("createMemo"),[e.arrowFunctionExpression([],a)]))}return null}function q(t,n){if(Ge(t))return null;let r=C(t);if(r)return fe(r,n);if(e.isConditionalExpression(t)){let i=t,s=C(i.consequent);if(s){let o=q(i.alternate,n);return R(j(i.test),s,o,n)}}return t}function ne(t){return e.isJSXElement(t)||e.isJSXFragment(t)}function B(t){let n=C(t);if(!n||!e.isJSXElement(n))return!1;let r=n.openingElement.name;return e.isJSXIdentifier(r)&&re.has(r.name)}function C(t){return ne(t)?t:e.isArrowFunctionExpression(t)&&t.params.length===0&&!t.async&&ne(t.body)?t.body:null}function j(t){return e.isArrowFunctionExpression(t)&&t.params.length===0&&!t.async&&e.isExpression(t.body)?t.body:t}function Ge(t){return e.isNullLiteral(t)||e.isIdentifier(t)&&t.name==="undefined"||e.isBooleanLiteral(t)&&t.value===!1}function fe(t,n){return e.isJSXElement(t)?O(t,n,!1,n.autoShow??!0):V(t,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})}function R(t,n,r,i,s=!1){i.controlFlowComponents.add("Show"),i.needsControlFlowImport=!0;let o=fe(n,i),a=[e.objectProperty(e.identifier("when"),e.arrowFunctionExpression([],t)),e.objectProperty(e.identifier("children"),o)];return r&&a.push(e.objectProperty(e.identifier("fallback"),r)),ae(e.identifier("Show"),e.objectExpression(a),i)}function Ze(t){return e.isMemberExpression(t)||e.isOptionalMemberExpression(t)?!(!t.computed&&e.isIdentifier(t.property,{name:"children"})):e.isCallExpression(t)||e.isOptionalCallExpression(t)?!0:e.isIdentifier(t)?!1:!!(e.isLogicalExpression(t)||e.isConditionalExpression(t)||e.isBinaryExpression(t)||e.isUnaryExpression(t)||e.isTemplateLiteral(t))}function me(t,n){let r=t.openingElement;if(!e.isJSXIdentifier(r.name))return!1;let i=r.name.name;if(i[0]!==i[0].toLowerCase())return!1;for(let s of r.attributes){if(e.isJSXSpreadAttribute(s))return!1;if(e.isJSXAttribute(s)){let o=s.value;if(e.isJSXExpressionContainer(o)&&!e.isStringLiteral(o.expression)&&!e.isNumericLiteral(o.expression))return!1}}for(let s of t.children)if(e.isJSXElement(s)&&!me(s,n)||e.isJSXExpressionContainer(s))return!1;return!0}function He(t,n){let r=`_$static${n.staticCounter++}`,i=O(t,n,!1);return n.staticElements.set(r,i),e.identifier(r)}function Ue(t,n){let r=t.openingElement.name.name;return r==="Show"?Ke(t,n):r==="For"?Qe(t,n):null}function Ke(t,n){return null}function Qe(t,n){return null}export{ft as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var v=(n,e)=>{for(var r in e)l(n,r,{get:e[r],enumerable:!0})},y=(n,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of x(e))!g.call(n,o)&&o!==r&&l(n,o,{get:()=>e[o],enumerable:!(i=m(e,o))||i.enumerable});return n};var F=n=>y(l({},"__esModule",{value:!0}),n);var U={};v(U,{transformServerFunctions:()=>E});module.exports=F(U);var u=require("@babel/core"),b="@fluixi/start/server-fn";function S(n){let e=5381;for(let r=0;r<n.length;r++)e=e*33^n.charCodeAt(r);return(e>>>0).toString(16)}function D({types:n}){return{name:"fluixi-server-functions",visitor:{Program:{enter(e,r){r.fxIndex=0,r.fxUsed=null},exit(e,r){r.fxUsed&&e.unshiftContainer("body",n.importDeclaration([n.importSpecifier(n.identifier(r.fxUsed),n.identifier(r.fxUsed))],n.stringLiteral(r.opts.runtimeModule||b)))}},"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression":(e,r)=>{let i=e.node.body;if(!n.isBlockStatement(i))return;let t=(i.directives||[]).findIndex(p=>p.value.value==="use server");if(t<0)return;i.directives.splice(t,1);let d=(r.opts.filename||r.filename||"unknown").replace(r.opts.root?r.opts.root+"/":"",""),c=`${S(d)}:${r.fxIndex++}`,a=!!r.opts.ssr,s=a?"$$registerServerFn":"$$createServerReference";r.fxUsed=s;let f=a?n.callExpression(n.identifier(s),[n.stringLiteral(c),e.isFunctionDeclaration()?n.functionExpression(null,e.node.params,i,e.node.generator,e.node.async):e.node]):n.callExpression(n.identifier(s),[n.stringLiteral(c)]);e.isFunctionDeclaration()?e.replaceWith(n.variableDeclaration("const",[n.variableDeclarator(e.node.id,f)])):e.replaceWith(f),e.skip()}}}}function E(n,e){if(!n.includes("use server"))return null;let r=(0,u.transformSync)(n,{filename:e.filename,configFile:!1,babelrc:!1,sourceMaps:!0,parserOpts:{plugins:["typescript","jsx"]},plugins:[[D,e]]});return r?.code?{code:r.code,map:r.map}:null}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ServerFnTransformOptions {
|
|
2
|
+
ssr: boolean;
|
|
3
|
+
filename: string;
|
|
4
|
+
root?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Returns `{ code, map }`, or null when the source has no `"use server"`. */
|
|
7
|
+
export declare function transformServerFunctions(code: string, opts: ServerFnTransformOptions): {
|
|
8
|
+
code: string;
|
|
9
|
+
map: any;
|
|
10
|
+
} | null;
|
|
11
|
+
//# sourceMappingURL=server-functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-functions.d.ts","sourceRoot":"","sources":["../../../src/frontend/babel/server-functions.ts"],"names":[],"mappings":"AA8FA,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,8EAA8E;AAC9E,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,wBAAwB,GAC7B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,GAAG,IAAI,CAYnC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `"use server"` transform. A function carrying the directive is a server function:
|
|
3
|
+
* it runs only on the server, callable from the client over RPC.
|
|
4
|
+
*
|
|
5
|
+
* const getUser = async (id) => { 'use server'; return db.users.find(id); };
|
|
6
|
+
*
|
|
7
|
+
* - **Server build** (`ssr: true`): keep the body, register it by a stable id so the
|
|
8
|
+
* RPC dispatcher can find it → `$$registerServerFn("id", async (id) => {…})`.
|
|
9
|
+
* - **Client build** (`ssr: false`): drop the body (server-only code never ships) and
|
|
10
|
+
* replace it with an RPC stub → `$$createServerReference("id")`.
|
|
11
|
+
*
|
|
12
|
+
* The id is `hash(relativeFile) + ':' + indexWithinFile`, computed identically on both
|
|
13
|
+
* builds (same source, same order) so client stub and server registration agree.
|
|
14
|
+
*/
|
|
15
|
+
import { transformSync } from '@babel/core';
|
|
16
|
+
const RUNTIME = '@fluixi/start/server-fn';
|
|
17
|
+
// djb2 — tiny, stable, dependency-free. Hex, so the id is a valid identifier suffix.
|
|
18
|
+
function hash(s) {
|
|
19
|
+
let h = 5381;
|
|
20
|
+
for (let i = 0; i < s.length; i++)
|
|
21
|
+
h = (h * 33) ^ s.charCodeAt(i);
|
|
22
|
+
return (h >>> 0).toString(16);
|
|
23
|
+
}
|
|
24
|
+
function serverFunctionsBabelPlugin({ types: t }) {
|
|
25
|
+
return {
|
|
26
|
+
name: 'fluixi-server-functions',
|
|
27
|
+
visitor: {
|
|
28
|
+
Program: {
|
|
29
|
+
enter(_path, state) {
|
|
30
|
+
state.fxIndex = 0;
|
|
31
|
+
state.fxUsed = null; // imported helper name
|
|
32
|
+
},
|
|
33
|
+
exit(path, state) {
|
|
34
|
+
if (!state.fxUsed)
|
|
35
|
+
return;
|
|
36
|
+
path.unshiftContainer('body', t.importDeclaration([t.importSpecifier(t.identifier(state.fxUsed), t.identifier(state.fxUsed))], t.stringLiteral(state.opts.runtimeModule || RUNTIME)));
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': (path, state) => {
|
|
40
|
+
const body = path.node.body;
|
|
41
|
+
if (!t.isBlockStatement(body))
|
|
42
|
+
return; // arrow with expression body can't carry a directive
|
|
43
|
+
const dirs = body.directives || [];
|
|
44
|
+
const di = dirs.findIndex((d) => d.value.value === 'use server');
|
|
45
|
+
if (di < 0)
|
|
46
|
+
return;
|
|
47
|
+
body.directives.splice(di, 1); // strip the directive
|
|
48
|
+
const rel = (state.opts.filename || state.filename || 'unknown').replace(state.opts.root ? state.opts.root + '/' : '', '');
|
|
49
|
+
const id = `${hash(rel)}:${state.fxIndex++}`;
|
|
50
|
+
const ssr = !!state.opts.ssr;
|
|
51
|
+
const helper = ssr ? '$$registerServerFn' : '$$createServerReference';
|
|
52
|
+
state.fxUsed = helper;
|
|
53
|
+
const replacement = ssr
|
|
54
|
+
? t.callExpression(t.identifier(helper), [
|
|
55
|
+
t.stringLiteral(id),
|
|
56
|
+
path.isFunctionDeclaration()
|
|
57
|
+
? t.functionExpression(null, path.node.params, body, path.node.generator, path.node.async)
|
|
58
|
+
: path.node,
|
|
59
|
+
])
|
|
60
|
+
: t.callExpression(t.identifier(helper), [t.stringLiteral(id)]);
|
|
61
|
+
if (path.isFunctionDeclaration()) {
|
|
62
|
+
// function f(){…} → const f = wrap(…) (loses hoisting; acceptable)
|
|
63
|
+
path.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(path.node.id, replacement)]));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
path.replaceWith(replacement);
|
|
67
|
+
}
|
|
68
|
+
path.skip();
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Returns `{ code, map }`, or null when the source has no `"use server"`. */
|
|
74
|
+
export function transformServerFunctions(code, opts) {
|
|
75
|
+
if (!code.includes('use server'))
|
|
76
|
+
return null;
|
|
77
|
+
const result = transformSync(code, {
|
|
78
|
+
filename: opts.filename,
|
|
79
|
+
configFile: false,
|
|
80
|
+
babelrc: false,
|
|
81
|
+
sourceMaps: true,
|
|
82
|
+
parserOpts: { plugins: ['typescript', 'jsx'] },
|
|
83
|
+
plugins: [[serverFunctionsBabelPlugin, opts]],
|
|
84
|
+
});
|
|
85
|
+
if (!result?.code)
|
|
86
|
+
return null;
|
|
87
|
+
return { code: result.code, map: result.map };
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{transformSync as u}from"@babel/core";var d="@fluixi/start/server-fn";function p(n){let r=5381;for(let e=0;e<n.length;e++)r=r*33^n.charCodeAt(e);return(r>>>0).toString(16)}function m({types:n}){return{name:"fluixi-server-functions",visitor:{Program:{enter(r,e){e.fxIndex=0,e.fxUsed=null},exit(r,e){e.fxUsed&&r.unshiftContainer("body",n.importDeclaration([n.importSpecifier(n.identifier(e.fxUsed),n.identifier(e.fxUsed))],n.stringLiteral(e.opts.runtimeModule||d)))}},"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression":(r,e)=>{let i=r.node.body;if(!n.isBlockStatement(i))return;let s=(i.directives||[]).findIndex(f=>f.value.value==="use server");if(s<0)return;i.directives.splice(s,1);let a=(e.opts.filename||e.filename||"unknown").replace(e.opts.root?e.opts.root+"/":"",""),l=`${p(a)}:${e.fxIndex++}`,t=!!e.opts.ssr,o=t?"$$registerServerFn":"$$createServerReference";e.fxUsed=o;let c=t?n.callExpression(n.identifier(o),[n.stringLiteral(l),r.isFunctionDeclaration()?n.functionExpression(null,r.node.params,i,r.node.generator,r.node.async):r.node]):n.callExpression(n.identifier(o),[n.stringLiteral(l)]);r.isFunctionDeclaration()?r.replaceWith(n.variableDeclaration("const",[n.variableDeclarator(r.node.id,c)])):r.replaceWith(c),r.skip()}}}}function v(n,r){if(!n.includes("use server"))return null;let e=u(n,{filename:r.filename,configFile:!1,babelrc:!1,sourceMaps:!0,parserOpts:{plugins:["typescript","jsx"]},plugins:[[m,r]]});return e?.code?{code:e.code,map:e.map}:null}export{v as transformServerFunctions};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var a=(t,e,n,p)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of s(e))!x.call(t,r)&&r!==n&&o(t,r,{get:()=>e[r],enumerable:!(p=i(e,r))||p.enumerable});return t};var S=t=>a(o({},"__esModule",{value:!0}),t);var m={};module.exports=S(m);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { types as t } from '@babel/core';
|
|
2
|
+
export type JSXElement = t.JSXElement;
|
|
3
|
+
export type JSXFragment = t.JSXFragment;
|
|
4
|
+
export type JSXExpressionContainer = t.JSXExpressionContainer;
|
|
5
|
+
export type JSXSpreadAttribute = t.JSXSpreadAttribute;
|
|
6
|
+
export type JSXAttribute = t.JSXAttribute;
|
|
7
|
+
export type JSXText = t.JSXText;
|
|
8
|
+
export type JSXSpreadChild = t.JSXSpreadChild;
|
|
9
|
+
export type JSXEmptyExpression = t.JSXEmptyExpression;
|
|
10
|
+
export type Expression = t.Expression;
|
|
11
|
+
export type Identifier = t.Identifier;
|
|
12
|
+
export type StringLiteral = t.StringLiteral;
|
|
13
|
+
export type CallExpression = t.CallExpression;
|
|
14
|
+
export type MemberExpression = t.MemberExpression;
|
|
15
|
+
export type ObjectProperty = t.ObjectProperty;
|
|
16
|
+
export type ObjectExpression = t.ObjectExpression;
|
|
17
|
+
export type ArrowFunctionExpression = t.ArrowFunctionExpression;
|
|
18
|
+
export type Program = t.Program;
|
|
19
|
+
export type JSXOpeningElement = t.JSXOpeningElement;
|
|
20
|
+
export type JSXClosingElement = t.JSXClosingElement;
|
|
21
|
+
export type JSXIdentifier = t.JSXIdentifier;
|
|
22
|
+
export type JSXMemberExpression = t.JSXMemberExpression;
|
|
23
|
+
export type JSXNamespacedName = t.JSXNamespacedName;
|
|
24
|
+
export interface TransformState {
|
|
25
|
+
opts: {
|
|
26
|
+
runtime: 'automatic' | 'classic';
|
|
27
|
+
importSource: string;
|
|
28
|
+
development: boolean;
|
|
29
|
+
pragma: string;
|
|
30
|
+
pragmaFrag: string;
|
|
31
|
+
signalDetection: boolean;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/frontend/babel/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;AACtC,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC;AACxC,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,sBAAsB,CAAC;AAC9D,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,kBAAkB,CAAC;AACtD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC;AAC1C,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;AAChC,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,cAAc,CAAC;AAC9C,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,kBAAkB,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;AACtC,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;AACtC,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC;AAC5C,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,cAAc,CAAC;AAC9C,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,gBAAgB,CAAC;AAClD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,cAAc,CAAC;AAC9C,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,gBAAgB,CAAC;AAClD,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,uBAAuB,CAAC;AAChE,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;AAChC,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,iBAAiB,CAAC;AACpD,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,iBAAiB,CAAC;AACpD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC;AAC5C,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,mBAAmB,CAAC;AACxD,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,iBAAiB,CAAC;AAEpD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE;QACJ,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;QACjC,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,OAAO,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,EAAE,OAAO,CAAC;KAC1B,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var a=(t,n,i,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of p(n))!m.call(t,o)&&o!==i&&r(t,o,{get:()=>n[o],enumerable:!(e=s(n,o))||e.enumerable});return t};var d=t=>a(r({},"__esModule",{value:!0}),t);var l={};module.exports=d(l);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CompilerOptions } from '../options.js';
|
|
2
|
+
/**
|
|
3
|
+
* A front-end adapter parses source (TS/JSX) and runs the Fluixi JSX transform
|
|
4
|
+
* for one module, producing code (and a source map). Front-ends are the swap
|
|
5
|
+
* point at the *parsing* end of the pipeline, mirroring CodegenBackend at the
|
|
6
|
+
* emit end:
|
|
7
|
+
*
|
|
8
|
+
* FrontEnd (babel now, swc later) -> IR -> CodegenBackend -> code
|
|
9
|
+
*
|
|
10
|
+
* The babel front-end (frontend/babel) is the reference implementation. An SWC
|
|
11
|
+
* front-end would implement this same interface (see the compiler README for the
|
|
12
|
+
* feasibility notes).
|
|
13
|
+
*/
|
|
14
|
+
export interface FrontEndResult {
|
|
15
|
+
code: string;
|
|
16
|
+
map?: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface FrontEnd {
|
|
19
|
+
/** stable id, e.g. 'babel' | 'swc' */
|
|
20
|
+
name: string;
|
|
21
|
+
/** file extensions this front-end can handle, e.g. ['.tsx', '.jsx', '.ts'] */
|
|
22
|
+
extensions: readonly string[];
|
|
23
|
+
/** parse + transform a single module */
|
|
24
|
+
transform(code: string, filename: string, options: CompilerOptions): FrontEndResult | Promise<FrontEndResult>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/frontend/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,wCAAwC;IACxC,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,eAAe,GACvB,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var d=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var r in t)d(e,r,{get:t[r],enumerable:!0})},v=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of h(t))!x.call(e,o)&&o!==r&&d(e,o,{get:()=>t[o],enumerable:!(n=$(t,o))||n.enumerable});return e};var y=e=>v(d({},"__esModule",{value:!0}),e);var P={};C(P,{RUNTIME_CONTRACT_V1:()=>p,RUNTIME_CONTRACT_V2:()=>R,backends:()=>j,defaultOptions:()=>N,imperativeBackend:()=>l});module.exports=y(P);var N={backend:"imperative",generate:"dom",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};var p={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},R={version:2,module:"@fluixi/dom",symbols:[...p.symbols,"template","cloneTemplate","walk"]};var k={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function b(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function g(e){return b(e)?e:JSON.stringify(e)}function O(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function I(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function S(e,t,r){let n=e.filter(i=>i.kind==="spread"),c=e.filter(i=>i.kind!=="spread").map(i=>`${g(i.name)}: ${O(i)}`);t!=null&&c.push(`children: ${t}`);let s=`{ ${c.join(", ")} }`;return n.length>0?(r.add("mergeProps"),`mergeProps(${n.map(i=>i.expr).join(", ")}, ${s})`):s}function f(e,t){return e.length===1?m(e[0],t):`[${e.map(r=>m(r,t)).join(", ")}]`}function u(e,t,r,n){n.add("createMemo"),n.add("createComponent");let o=t.filter(a=>a.kind==="spread"),s=t.filter(a=>a.kind!=="spread").map(a=>`get ${g(a.name)}() { return ${I(a)}; }`);r.length>0&&s.push(`get children() { return ${f(r,n)}; }`);let i=`{ ${s.join(", ")} }`;return o.length>0&&(n.add("mergeProps"),i=`mergeProps(${o.map(a=>a.expr).join(", ")}, ${i})`),`createMemo(() => createComponent(${e}, ${i}))`}function m(e,t){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":f(e.children,t);case"component":return u(e.name,e.props,e.children,t);case"control":{let r=k[e.control]??e.control;return t.add(r),u(r,e.props,e.children,t)}case"element":{t.add("createNativeElement");let r=JSON.stringify(e.tag),n="_el$",o=[],c=e.svg?`${r}, true`:r;if(o.push(`const ${n} = createNativeElement(${c});`),e.props.length>0){t.add("spread");let s=e.svg?", isSVG: true":"";o.push(`spread({ element: ${n}, props: ${S(e.props,null,t)}${s} });`)}for(let s of e.children){t.add("insert");let i=m(s,t),a=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";o.push(a?`insert(${n}, ${i}, null);`:`insert(${n}, ${i});`)}return o.push(`return ${n};`),`(() => { ${o.join(" ")} })()`}}}var l={name:"imperative",contract:p,emit(e,t){let r=new Set;return{code:m(e,r),imports:Array.from(r)}}};var j={imperative:l};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fluixi/compiler — host-agnostic JSX compiler for Fluixi.
|
|
3
|
+
*
|
|
4
|
+
* Pipeline: front-end adapters (babel now, swc later) → IR → analyze →
|
|
5
|
+
* transform → codegen backends (imperative now, template-clone later) emitting
|
|
6
|
+
* against a versioned RuntimeContract.
|
|
7
|
+
*
|
|
8
|
+
* The babel front-end is exposed at the '@fluixi/compiler/babel' subpath.
|
|
9
|
+
*/
|
|
10
|
+
export * from './ir/nodes.js';
|
|
11
|
+
export * from './options.js';
|
|
12
|
+
export * from './frontend/types.js';
|
|
13
|
+
export * from './codegen/contract.js';
|
|
14
|
+
export * from './codegen/backend.js';
|
|
15
|
+
export { imperativeBackend } from './codegen/backends/imperative.js';
|
|
16
|
+
import type { CodegenBackend } from './codegen/backend.js';
|
|
17
|
+
/** Registry of available codegen backends (keyed by CompilerOptions.backend). */
|
|
18
|
+
export declare const backends: Record<string, CodegenBackend>;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,iFAAiF;AACjF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAEnD,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fluixi/compiler — host-agnostic JSX compiler for Fluixi.
|
|
3
|
+
*
|
|
4
|
+
* Pipeline: front-end adapters (babel now, swc later) → IR → analyze →
|
|
5
|
+
* transform → codegen backends (imperative now, template-clone later) emitting
|
|
6
|
+
* against a versioned RuntimeContract.
|
|
7
|
+
*
|
|
8
|
+
* The babel front-end is exposed at the '@fluixi/compiler/babel' subpath.
|
|
9
|
+
*/
|
|
10
|
+
export * from './ir/nodes.js';
|
|
11
|
+
export * from './options.js';
|
|
12
|
+
export * from './frontend/types.js';
|
|
13
|
+
export * from './codegen/contract.js';
|
|
14
|
+
export * from './codegen/backend.js';
|
|
15
|
+
export { imperativeBackend } from './codegen/backends/imperative.js';
|
|
16
|
+
import { imperativeBackend } from './codegen/backends/imperative.js';
|
|
17
|
+
/** Registry of available codegen backends (keyed by CompilerOptions.backend). */
|
|
18
|
+
export const backends = {
|
|
19
|
+
imperative: imperativeBackend,
|
|
20
|
+
};
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var v={backend:"imperative",generate:"dom",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};var m={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},N={version:2,module:"@fluixi/dom",symbols:[...m.symbols,"template","cloneTemplate","walk"]};var f={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function $(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function u(e){return $(e)?e:JSON.stringify(e)}function h(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function x(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function C(e,t,r){let o=e.filter(n=>n.kind==="spread"),c=e.filter(n=>n.kind!=="spread").map(n=>`${u(n.name)}: ${h(n)}`);t!=null&&c.push(`children: ${t}`);let i=`{ ${c.join(", ")} }`;return o.length>0?(r.add("mergeProps"),`mergeProps(${o.map(n=>n.expr).join(", ")}, ${i})`):i}function g(e,t){return e.length===1?p(e[0],t):`[${e.map(r=>p(r,t)).join(", ")}]`}function d(e,t,r,o){o.add("createMemo"),o.add("createComponent");let a=t.filter(s=>s.kind==="spread"),i=t.filter(s=>s.kind!=="spread").map(s=>`get ${u(s.name)}() { return ${x(s)}; }`);r.length>0&&i.push(`get children() { return ${g(r,o)}; }`);let n=`{ ${i.join(", ")} }`;return a.length>0&&(o.add("mergeProps"),n=`mergeProps(${a.map(s=>s.expr).join(", ")}, ${n})`),`createMemo(() => createComponent(${e}, ${n}))`}function p(e,t){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":g(e.children,t);case"component":return d(e.name,e.props,e.children,t);case"control":{let r=f[e.control]??e.control;return t.add(r),d(r,e.props,e.children,t)}case"element":{t.add("createNativeElement");let r=JSON.stringify(e.tag),o="_el$",a=[],c=e.svg?`${r}, true`:r;if(a.push(`const ${o} = createNativeElement(${c});`),e.props.length>0){t.add("spread");let i=e.svg?", isSVG: true":"";a.push(`spread({ element: ${o}, props: ${C(e.props,null,t)}${i} });`)}for(let i of e.children){t.add("insert");let n=p(i,t),s=i.kind==="expr"&&i.reactive||i.kind==="component"||i.kind==="control";a.push(s?`insert(${o}, ${n}, null);`:`insert(${o}, ${n});`)}return a.push(`return ${o};`),`(() => { ${a.join(" ")} })()`}}}var l={name:"imperative",contract:m,emit(e,t){let r=new Set;return{code:p(e,r),imports:Array.from(r)}}};var I={imperative:l};export{m as RUNTIME_CONTRACT_V1,N as RUNTIME_CONTRACT_V2,I as backends,v as defaultOptions,l as imperativeBackend};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";var nt=Object.create;var V=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var it=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty;var L=(e,n)=>()=>(e&&(n=e(e=0)),n);var Se=(e,n)=>{for(var r in n)V(e,r,{get:n[r],enumerable:!0})},he=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of it(n))!ot.call(e,s)&&s!==r&&V(e,s,{get:()=>n[s],enumerable:!(i=rt(n,s))||i.enumerable});return e};var ee=(e,n,r)=>(r=e!=null?nt(st(e)):{},he(n||!e||!e.__esModule?V(r,"default",{value:e,enumerable:!0}):r,e)),at=e=>he(V({},"__esModule",{value:!0}),e);var te,on,be=L(()=>{"use strict";te={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},on={version:2,module:"@fluixi/dom",symbols:[...te.symbols,"template","cloneTemplate","walk"]}});function ft(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function Ce(e){return ft(e)?e:JSON.stringify(e)}function mt(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function dt(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function gt(e,n,r){let i=e.filter(l=>l.kind==="spread"),o=e.filter(l=>l.kind!=="spread").map(l=>`${Ce(l.name)}: ${mt(l)}`);n!=null&&o.push(`children: ${n}`);let a=`{ ${o.join(", ")} }`;return i.length>0?(r.add("mergeProps"),`mergeProps(${i.map(l=>l.expr).join(", ")}, ${a})`):a}function Je(e,n){return e.length===1?B(e[0],n):`[${e.map(r=>B(r,n)).join(", ")}]`}function ve(e,n,r,i){i.add("createMemo"),i.add("createComponent");let s=n.filter(c=>c.kind==="spread"),a=n.filter(c=>c.kind!=="spread").map(c=>`get ${Ce(c.name)}() { return ${dt(c)}; }`);r.length>0&&a.push(`get children() { return ${Je(r,i)}; }`);let l=`{ ${a.join(", ")} }`;return s.length>0&&(i.add("mergeProps"),l=`mergeProps(${s.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${e}, ${l}))`}function B(e,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":Je(e.children,n);case"component":return ve(e.name,e.props,e.children,n);case"control":{let r=pt[e.control]??e.control;return n.add(r),ve(r,e.props,e.children,n)}case"element":{n.add("createNativeElement");let r=JSON.stringify(e.tag),i="_el$",s=[],o=e.svg?`${r}, true`:r;if(s.push(`const ${i} = createNativeElement(${o});`),e.props.length>0){n.add("spread");let a=e.svg?", isSVG: true":"";s.push(`spread({ element: ${i}, props: ${gt(e.props,null,n)}${a} });`)}for(let a of e.children){n.add("insert");let l=B(a,n),c=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";s.push(c?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return s.push(`return ${i};`),`(() => { ${s.join(" ")} })()`}}}var pt,W,ne=L(()=>{"use strict";be();pt={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};W={name:"imperative",contract:te,emit(e,n){let r=new Set;return{code:B(e,r),imports:Array.from(r)}}}});function Xe(e){return xt(e,{concise:!0}).code}function Et(e,n){let r=p.types.cloneNode(e,!0),i=p.types.file(p.types.program([p.types.expressionStatement(r)])),s=!1;return(0,p.traverse)(i,{"JSXElement|JSXFragment"(o){let a=o.node,{code:l,imports:c}=W.emit(O(a,n),{});for(let x of c)n.add(x);let m=p.template.expression(l,{placeholderPattern:!1})();o.replaceWith(m),o.skip(),s=!0}}),s?i.program.body[0].expression:e}function q(e,n){return Xe(Et(e,n))}function bt(e){if(p.types.isJSXIdentifier(e)){let n=e.name[0]!==e.name[0].toLowerCase();return{tag:e.name,component:n}}return p.types.isJSXMemberExpression(e)?{tag:Xe(e),component:!0}:p.types.isJSXNamespacedName(e)?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function vt(e){return p.types.isJSXIdentifier(e)?e.name==="class"?"className":e.name:p.types.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:"unknown"}function F(e){return p.types.isCallExpression(e)||p.types.isOptionalCallExpression(e)?!0:p.types.isMemberExpression(e)||p.types.isOptionalMemberExpression(e)?!(!e.computed&&p.types.isIdentifier(e.property,{name:"children"})):p.types.isConditionalExpression(e)?F(e.test)||F(e.consequent)||F(e.alternate):p.types.isLogicalExpression(e)||p.types.isBinaryExpression(e)?F(e.left)||F(e.right):p.types.isTemplateLiteral(e)?e.expressions.some(n=>F(n)):!1}function Ct(e,n){let r=vt(e.name),i=ht.test(r),o={name:r,kind:i?"event":"attr"};i&&(o.event={name:r.slice(2).toLowerCase(),delegated:yt.has(r.slice(2).toLowerCase())});let a=e.value;if(a==null)return o.literal=!0,o;if(p.types.isStringLiteral(a))return o.literal=a.value,o;if(p.types.isJSXExpressionContainer(a)&&!p.types.isJSXEmptyExpression(a.expression)){let l=a.expression;return p.types.isStringLiteral(l)||p.types.isNumericLiteral(l)||p.types.isBooleanLiteral(l)?(o.literal=l.value,o):(o.expr=q(l,n),o.reactive=i?!1:F(l),(p.types.isJSXElement(l)||p.types.isJSXFragment(l))&&(o.jsxElement=!0),o)}return o.literal=!0,o}function Jt(e,n){let r=[];for(let i of e)p.types.isJSXSpreadAttribute(i)?r.push({name:"",kind:"spread",expr:q(i.argument,n)}):p.types.isJSXAttribute(i)&&r.push(Ct(i,n));return r}function wt(e){let n=e.split(/\r\n|\n|\r/),r=0;for(let s=0;s<n.length;s++)/[^ \t]/.test(n[s])&&(r=s);let i="";for(let s=0;s<n.length;s++){let o=n[s].replace(/\t/g," ");s!==0&&(o=o.replace(/^ +/,"")),s!==n.length-1&&(o=o.replace(/ +$/,"")),o&&(s!==r&&(o+=" "),i+=o)}return i}function we(e,n){let r=[];for(let i of e)if(p.types.isJSXText(i)){let s=wt(i.value);s&&r.push({kind:"text",value:s})}else if(p.types.isJSXExpressionContainer(i)){if(!p.types.isJSXEmptyExpression(i.expression)){let s=i.expression;r.push({kind:"expr",code:q(s,n),reactive:F(s)})}}else p.types.isJSXElement(i)||p.types.isJSXFragment(i)?r.push(O(i,n)):p.types.isJSXSpreadChild(i)&&r.push({kind:"expr",code:q(i.expression,n),reactive:!1});return r}function O(e,n=new Set){if(p.types.isJSXFragment(e))return{kind:"fragment",children:we(e.children,n)};let{tag:r,component:i}=bt(e.openingElement.name),s=Jt(e.openingElement.attributes,n),o=we(e.children,n);return i?{kind:"component",name:r,props:s,children:o}:{kind:"element",tag:r,svg:St.has(r),props:s,children:o,static:!1}}var p,re,xt,St,ht,yt,Fe=L(()=>{"use strict";p=require("@babel/core"),re=ee(require("@babel/generator"),1);ne();xt=re.default.default??re.default;St=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),ht=/^on[A-Z]/,yt=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"])});function Ft(e,n,r){let{runtime:i,pragma:s,development:o,autoShow:a=!0}=r;return i==="automatic"?D(e,n,o,a):$t(e,n,s)}function je(e,n,r){return n.length>0?(r.needsMergeProps=!0,t.types.callExpression(t.types.identifier("mergeProps"),[...n,t.types.objectExpression(e)])):t.types.objectExpression(e)}function Re(e){return e.length===1?e[0]:t.types.arrayExpression(e)}function Mt(e,n,r,i,s,o){if(!n){let f=[...r];return s.length>0&&f.push(t.types.objectMethod("get",t.types.identifier("children"),[],t.types.blockStatement([t.types.returnStatement(Re(s))]))),Ae(e,je(f,i,o),o)}let a=e.value,l=jt.has(a),c=t.types.identifier("_el$"),m=[];o.needsCreateNativeElement=!0;let x=[e];if(l&&x.push(t.types.booleanLiteral(!0)),m.push(t.types.variableDeclaration("const",[t.types.variableDeclarator(c,t.types.callExpression(t.types.identifier("createNativeElement"),x))])),r.length>0||i.length>0){o.needsSpread=!0;let f=[t.types.objectProperty(t.types.identifier("element"),c),t.types.objectProperty(t.types.identifier("props"),je(r,i,o))];l&&f.push(t.types.objectProperty(t.types.identifier("isSVG"),t.types.booleanLiteral(!0))),m.push(t.types.expressionStatement(t.types.callExpression(t.types.identifier("spread"),[t.types.objectExpression(f)])))}if(s.length>0){o.needsInsert=!0;for(let f of s){let P=t.types.isArrowFunctionExpression(f)||t.types.isFunctionExpression(f)||t.types.isCallExpression(f)&&t.types.isIdentifier(f.callee)&&f.callee.name==="createMemo"?[t.types.cloneNode(c),f,t.types.nullLiteral()]:[t.types.cloneNode(c),f];m.push(t.types.expressionStatement(t.types.callExpression(t.types.identifier("insert"),P)))}}return m.push(t.types.returnStatement(c)),t.types.callExpression(t.types.arrowFunctionExpression([],t.types.blockStatement(m)),[])}function Ae(e,n,r){return r.backend==="imperative"?(r.needsCreateComponent=!0,r.needsCreateMemo=!0,t.types.callExpression(t.types.identifier("createMemo"),[t.types.arrowFunctionExpression([],t.types.callExpression(t.types.identifier("createComponent"),[e,n]))])):t.types.callExpression(t.types.identifier("jsx"),[e,n])}function Me(e,n){let r=new Set,i=O(e,r),{code:s,imports:o}=W.emit(i,{});for(let a of o)r.add(a);for(let a of r)n.irImports.add(a);return t.template.expression(s,{placeholderPattern:!1})()}function Pt(e){return e.map(n=>{if(t.types.isObjectProperty(n)){let r=n.key,i=n.computed,s=n.value;return t.types.objectMethod("get",r,[],t.types.blockStatement([t.types.returnStatement(s)]),i)}return n})}function D(e,n,r,i=!0){let s=e.openingElement,o=e.children,a=Ne(s.name),l=t.types.isJSXIdentifier(s.name)&&/^[a-z]/.test(s.name.name),c=ke(s.attributes,n,l,t.types.isJSXIdentifier(s.name)?s.name.name:""),m=c.props,x=c.spreads;l||(m=Pt(m));let f=se(o,n,i);if(n.backend==="imperative")return Mt(a,l,m,x,f,n);if(f.length>0){let X=f.length===1?f[0]:t.types.arrayExpression(f);m.push(t.types.objectProperty(t.types.identifier("children"),X))}let b;if(x.length>0){let X=m.length>0?t.types.objectExpression(m):t.types.objectExpression([]);n.needsMergeProps=!0,b=t.types.callExpression(t.types.identifier("mergeProps"),[...x,X])}else b=t.types.objectExpression(m);let P=r?"jsxDEV":f.length>1?"jsxs":"jsx",v=[a,b];return r&&v.push(t.types.identifier("undefined"),t.types.booleanLiteral(!1),t.types.identifier("undefined"),t.types.identifier("undefined")),t.types.callExpression(t.types.identifier(P),v)}function $t(e,n,r){let i=e.openingElement,s=e.children,o=Ne(i.name),a=t.types.isJSXIdentifier(i.name)&&/^[a-z]/.test(i.name.name),{props:l,spreads:c}=ke(i.attributes,n,a,t.types.isJSXIdentifier(i.name)?i.name.name:""),m=se(s,n,n.autoShow??!0),x;if(c.length>0){let b=l.length>0?t.types.objectExpression(l):t.types.objectExpression([]);n.needsMergeProps=!0,x=t.types.callExpression(t.types.identifier("mergeProps"),[...c,b])}else x=l.length>0?t.types.objectExpression(l):t.types.nullLiteral();let f=[o,x,...m];return t.types.callExpression(t.types.identifier(r),f)}function H(e,n,r){let{runtime:i,pragmaFrag:s,development:o}=r,a=se(e.children,n,n.autoShow??!0);if(n.backend==="imperative")return a.length===0?t.types.nullLiteral():Re(a);if(i==="automatic"){let l=o?"jsxDEV":a.length>1?"jsxs":"jsx",c=t.types.objectExpression([t.types.objectProperty(t.types.identifier("children"),a.length===1?a[0]:t.types.arrayExpression(a))]),m=[t.types.identifier("Fragment"),c];return o&&m.push(t.types.identifier("undefined"),t.types.booleanLiteral(!1),t.types.identifier("undefined"),t.types.identifier("undefined")),t.types.callExpression(t.types.identifier(l),m)}else return t.types.callExpression(t.types.identifier(s),a)}function Ne(e){if(t.types.isJSXIdentifier(e)){let n=e.name;return n[0]===n[0].toLowerCase()?t.types.stringLiteral(n):t.types.identifier(n)}return t.types.isJSXMemberExpression(e)?Oe(e):t.types.isJSXNamespacedName(e)?t.types.stringLiteral(`${e.namespace.name}:${e.name.name}`):t.types.stringLiteral("div")}function Oe(e){let n;return t.types.isJSXIdentifier(e.object)?n=t.types.identifier(e.object.name):n=Oe(e.object),t.types.memberExpression(n,t.types.identifier(e.property.name))}function Lt(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)}function ke(e,n,r=!0,i=""){let s=[],o=[],a=Xt[i];for(let l of e)if(t.types.isJSXSpreadAttribute(l))o.push(l.argument);else if(t.types.isJSXAttribute(l)){let c=It(l.name),m=Tt(l.value,n,c,r);if(Ie.test(c)){let R=c.slice(2).toLowerCase();Te.includes(R)&&n.delegatedEvents.add(R)}let x=Lt(c)?t.types.identifier(c):t.types.stringLiteral(c),f=l.value,b=t.types.isJSXElement(f)||t.types.isJSXFragment(f)||t.types.isJSXExpressionContainer(f)&&(t.types.isJSXElement(f.expression)||t.types.isJSXFragment(f.expression)),P=!r&&c===a,v=t.types.isJSXExpressionContainer(f)&&!t.types.isJSXEmptyExpression(f.expression)?f.expression:null,X=!r&&!!v&&De(v,c);!r&&b||P||X?s.push(t.types.objectMethod("get",x,[],t.types.blockStatement([t.types.returnStatement(m)]))):s.push(t.types.objectProperty(x,m))}return{props:s,spreads:o}}function It(e){return t.types.isJSXIdentifier(e)?e.name==="class"?"className":e.name:t.types.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:"unknown"}function Tt(e,n,r="",i=!0){if(e===null)return t.types.booleanLiteral(!0);if(t.types.isStringLiteral(e))return e.value.includes(`
|
|
2
|
+
`)?t.types.stringLiteral(e.value.replace(/\s+/g," ").trim()):e;if(t.types.isJSXExpressionContainer(e)){if(t.types.isJSXEmptyExpression(e.expression))return t.types.booleanLiteral(!0);let s=e.expression;return i&&De(s,r)?t.types.arrowFunctionExpression([],s):s}return t.types.isJSXElement(e)?D(e,n,!1,n.autoShow??!0):t.types.isJSXFragment(e)?H(e,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1}):t.types.booleanLiteral(!0)}function De(e,n){return Ie.test(n)||n.startsWith("on:")||n==="ref"||n.startsWith("use:")||t.types.isArrowFunctionExpression(e)||t.types.isFunctionExpression(e)||t.types.isIdentifier(e)||t.types.isStringLiteral(e)||t.types.isNumericLiteral(e)||t.types.isBooleanLiteral(e)||t.types.isNullLiteral(e)?!1:!!(t.types.isCallExpression(e)||t.types.isOptionalCallExpression(e)||t.types.isMemberExpression(e)||t.types.isOptionalMemberExpression(e)||t.types.isLogicalExpression(e)||t.types.isConditionalExpression(e)||t.types.isBinaryExpression(e)||t.types.isUnaryExpression(e)||t.types.isTemplateLiteral(e)||t.types.isObjectExpression(e)||t.types.isArrayExpression(e))}function Rt(e){let n=e.split(/\r\n|\n|\r/),r=0;for(let s=0;s<n.length;s++)/[^ \t]/.test(n[s])&&(r=s);let i="";for(let s=0;s<n.length;s++){let o=n[s].replace(/\t/g," ");s!==0&&(o=o.replace(/^ +/,"")),s!==n.length-1&&(o=o.replace(/ +$/,"")),o&&(s!==r&&(o+=" "),i+=o)}return i}function se(e,n,r=!0){let i=[];for(let s of e)if(t.types.isJSXText(s)){let o=Rt(s.value);o&&i.push(t.types.stringLiteral(o))}else if(t.types.isJSXExpressionContainer(s)){if(!t.types.isJSXEmptyExpression(s.expression)){let o=s.expression;if(r){let a=At(o,n)??Nt(o,n);if(a){i.push(a);continue}}else{let a=Ot(o,n);if(a){i.push(a);continue}}Dt(o)?i.push(t.types.arrowFunctionExpression([],o)):i.push(o)}}else t.types.isJSXElement(s)?i.push(D(s,n,!1,n.autoShow??!0)):t.types.isJSXFragment(s)?i.push(H(s,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})):t.types.isJSXSpreadChild(s)&&i.push(s.expression);return i}function At(e,n){if(!t.types.isArrowFunctionExpression(e)||e.params.length!==0||e.async)return null;let r=e.body;if(t.types.isLogicalExpression(r)&&r.operator==="&&"){let i=C(r.right);if(i)return k(j(r.left),i,null,n)}if(t.types.isConditionalExpression(r)){let i=C(r.consequent);if(i){let s=oe(r.alternate,n);return k(j(r.test),i,s,n,!0)}}return null}function Nt(e,n){if(t.types.isLogicalExpression(e)&&e.operator==="&&"){let r=C(e.right);if(r)return k(j(e.left),r,null,n)}if(t.types.isConditionalExpression(e)){let r=C(e.consequent);if(r){let i=oe(e.alternate,n);return k(j(e.test),r,i,n)}}return null}function Ot(e,n){let r=t.types.isArrowFunctionExpression(e)&&e.params.length===0&&!e.async&&t.types.isExpression(e.body)?e.body:e;if(t.types.isConditionalExpression(r)){let i=j(r.test),o=C(r.consequent)??r.consequent,l=C(r.alternate)??r.alternate,c=t.types.conditionalExpression(i,o,l);return ie(r.consequent)||ie(r.alternate)?null:(n.needsCreateMemo=!0,t.types.callExpression(t.types.identifier("createMemo"),[t.types.arrowFunctionExpression([],c)]))}if(t.types.isLogicalExpression(r)&&r.operator==="&&"){let i=j(r.left),o=C(r.right)??r.right,a=t.types.logicalExpression("&&",i,o);return ie(r.right)?null:(n.needsCreateMemo=!0,t.types.callExpression(t.types.identifier("createMemo"),[t.types.arrowFunctionExpression([],a)]))}return null}function oe(e,n){if(kt(e))return null;let r=C(e);if(r)return _e(r,n);if(t.types.isConditionalExpression(e)){let i=e,s=C(i.consequent);if(s){let o=oe(i.alternate,n);return k(j(i.test),s,o,n)}}return e}function Pe(e){return t.types.isJSXElement(e)||t.types.isJSXFragment(e)}function ie(e){let n=C(e);if(!n||!t.types.isJSXElement(n))return!1;let r=n.openingElement.name;return t.types.isJSXIdentifier(r)&&Le.has(r.name)}function C(e){return Pe(e)?e:t.types.isArrowFunctionExpression(e)&&e.params.length===0&&!e.async&&Pe(e.body)?e.body:null}function j(e){return t.types.isArrowFunctionExpression(e)&&e.params.length===0&&!e.async&&t.types.isExpression(e.body)?e.body:e}function kt(e){return t.types.isNullLiteral(e)||t.types.isIdentifier(e)&&e.name==="undefined"||t.types.isBooleanLiteral(e)&&e.value===!1}function _e(e,n){return t.types.isJSXElement(e)?D(e,n,!1,n.autoShow??!0):H(e,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})}function k(e,n,r,i,s=!1){i.controlFlowComponents.add("Show"),i.needsControlFlowImport=!0;let o=_e(n,i),a=[t.types.objectProperty(t.types.identifier("when"),t.types.arrowFunctionExpression([],e)),t.types.objectProperty(t.types.identifier("children"),o)];return r&&a.push(t.types.objectProperty(t.types.identifier("fallback"),r)),Ae(t.types.identifier("Show"),t.types.objectExpression(a),i)}function Dt(e){return t.types.isMemberExpression(e)||t.types.isOptionalMemberExpression(e)?!(!e.computed&&t.types.isIdentifier(e.property,{name:"children"})):t.types.isCallExpression(e)||t.types.isOptionalCallExpression(e)?!0:t.types.isIdentifier(e)?!1:!!(t.types.isLogicalExpression(e)||t.types.isConditionalExpression(e)||t.types.isBinaryExpression(e)||t.types.isUnaryExpression(e)||t.types.isTemplateLiteral(e))}function Ve(e,n){let r=e.openingElement;if(!t.types.isJSXIdentifier(r.name))return!1;let i=r.name.name;if(i[0]!==i[0].toLowerCase())return!1;for(let s of r.attributes){if(t.types.isJSXSpreadAttribute(s))return!1;if(t.types.isJSXAttribute(s)){let o=s.value;if(t.types.isJSXExpressionContainer(o)&&!t.types.isStringLiteral(o.expression)&&!t.types.isNumericLiteral(o.expression))return!1}}for(let s of e.children)if(t.types.isJSXElement(s)&&!Ve(s,n)||t.types.isJSXExpressionContainer(s))return!1;return!0}function _t(e,n){let r=`_$static${n.staticCounter++}`,i=D(e,n,!1);return n.staticElements.set(r,i),t.types.identifier(r)}function Vt(e,n){let r=e.openingElement.name.name;return r==="Show"?zt(e,n):r==="For"?Bt(e,n):null}function zt(e,n){return null}function Bt(e,n){return null}var $e,t,Le,Xt,Ie,Te,I,jt,ae=L(()=>{"use strict";$e=require("@babel/helper-plugin-utils"),t=require("@babel/core");Fe();ne();Le=new Set(["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary","Suspense"]),Xt={Show:"when",For:"each",Index:"each",Match:"when"},Ie=/^on[A-Z]/,Te=["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave"],I=(0,$e.declare)((e,n={})=>{e.assertVersion(7);let{runtime:r="automatic",importSource:i="@fluixi/jsx",pragma:s="jsx",pragmaFrag:o="Fragment",development:a=!1,detectReactivity:l=!0,useLitHTML:c=!0,hoistStatics:m=!0,delegateEvents:x=!0,delegatedEvents:f=Te,optimizeControlFlow:b=!0,sourceMaps:P=!0,signalModule:v="@fluixi/dom",controlFlowModule:X="@fluixi/dom",reactiveModule:R="@fluixi/reactive/signal",autoShowTransform:Ee=!1,backend:J="imperative",codegen:A="inline"}=n,tt={backend:J,codegen:A,irImports:new Set,libModule:"@fluixi/core",hasJSX:!1,hasReactivity:!1,hasLitHTML:!1,needsSignalImport:!1,needsControlFlowImport:!1,needsCreateMemo:!1,controlFlowComponents:new Set,delegatedEvents:new Set,staticElements:new Map,staticCounter:0};return{name:"@fluixi/babel-plugin-jsx",manipulateOptions(d,u){u.plugins.push("jsx","typescript")},pre(d){Object.assign(d,tt)},visitor:{ImportDeclaration(d,u){d.node.source.value==="@fluixi/core/rx"&&(d.node.source=t.types.stringLiteral("@fluixi/reactive"))},Program:{enter(d,u){Object.assign(u,{hasJSX:!1,hasReactivity:!1,hasLitHTML:!1,needsSignalImport:!1,needsLitrxImport:!1,needsControlFlowImport:!1,needsCreateMemo:!1,controlFlowComponents:new Set,delegatedEvents:new Set,staticElements:new Map,autoShow:Ee,staticCounter:0,libModule:"@fluixi/core",backend:J,codegen:A,irImports:new Set,needsCreateNativeElement:!1,needsInsert:!1,needsSpread:!1,needsCreateComponent:!1,needsMergeProps:!1})},exit(d,u){let g=[];if(u.hasJSX||(u.needsSignalImport&&g.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("signal"),t.types.identifier("signal"))],t.types.stringLiteral(v))),u.needsLitrxImport&&!d.scope.hasBinding("litrx")&&g.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("litrx"),t.types.identifier("litrx"))],t.types.stringLiteral(u.libModule)))),u.hasJSX){if(J==="imperative"&&A==="ir"){let S=new Set(["Show","For","Index","Switch","Match","Dynamic","ErrorBoundary","Portal","Suspense"]),h=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]),E=Array.from(u.irImports),w=y=>t.types.importSpecifier(t.types.identifier(y),t.types.identifier(y)),$=y=>!d.scope.hasBinding(y),Y=E.filter(y=>h.has(y)&&$(y)),_=E.filter(y=>!S.has(y)&&!h.has(y)&&$(y)),N=E.filter(y=>S.has(y)&&$(y));Y.length>0&&g.push(t.types.importDeclaration(Y.map(w),t.types.stringLiteral(R))),_.length>0&&g.push(t.types.importDeclaration(_.map(w),t.types.stringLiteral(v))),N.length>0&&g.push(t.types.importDeclaration(N.map(w),t.types.stringLiteral(X)))}else if(J==="imperative"){let h=[[!!u.needsCreateNativeElement,"createNativeElement"],[!!u.needsSpread,"spread"],[!!u.needsInsert,"insert"],[!!u.needsCreateComponent,"createComponent"],[!!u.needsMergeProps,"mergeProps"]].filter(([E,w])=>E&&!d.scope.hasBinding(w)).map(([,E])=>t.types.importSpecifier(t.types.identifier(E),t.types.identifier(E)));h.length>0&&g.push(t.types.importDeclaration(h,t.types.stringLiteral(v)))}else if(r==="automatic"){let S=[t.types.importSpecifier(t.types.identifier("jsx"),t.types.identifier("jsx")),t.types.importSpecifier(t.types.identifier("jsxs"),t.types.identifier("jsxs")),t.types.importSpecifier(t.types.identifier("Fragment"),t.types.identifier("Fragment"))];a&&S.push(t.types.importSpecifier(t.types.identifier("jsxDEV"),t.types.identifier("jsxDEV"))),u.needsMergeProps&&S.push(t.types.importSpecifier(t.types.identifier("mergeProps"),t.types.identifier("mergeProps"))),g.push(t.types.importDeclaration(S,t.types.stringLiteral(i)))}if(u.needsCreateMemo&&!d.scope.hasBinding("createMemo")&&g.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("createMemo"),t.types.identifier("createMemo"))],t.types.stringLiteral(J==="imperative"?R:u.libModule??"@fluixi/core"))),u.needsControlFlowImport&&u.controlFlowComponents.size>0){let S=Array.from(u.controlFlowComponents).filter(h=>!d.scope.hasBinding(h));if(S.length>0){let h=S.map(E=>t.types.importSpecifier(t.types.identifier(E),t.types.identifier(E)));g.push(t.types.importDeclaration(h,t.types.stringLiteral(X)))}}if(x&&u.delegatedEvents.size>0){g.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("delegateEvents"),t.types.identifier("delegateEvents"))],t.types.stringLiteral(J==="imperative"?v:"@fluixi/jsx")));let S=t.types.arrayExpression(Array.from(u.delegatedEvents).map(E=>t.types.stringLiteral(E))),h=t.types.expressionStatement(t.types.callExpression(t.types.identifier("delegateEvents"),[S]));d.node.body.unshift(h)}if(m&&u.staticElements.size>0){let S=[];u.staticElements.forEach((h,E)=>{S.push(t.types.variableDeclaration("const",[t.types.variableDeclarator(t.types.identifier(E),h)]))}),d.node.body.unshift(...S)}}g.length>0&&d.node.body.unshift(...g)}},JSXElement(d,u){if(u.hasJSX=!0,J==="imperative"&&A==="ir"){d.replaceWith(Me(d.node,u));return}let g=d.node,S=g.openingElement;if(t.types.isJSXIdentifier(S.name)&&Le.has(S.name.name)&&(u.controlFlowComponents.add(S.name.name),b)){let E=Vt(g,u);if(E){d.replaceWith(E);return}}if(m&&J!=="imperative"&&Ve(g,u)){let E=_t(g,u);if(E){d.replaceWith(E);return}}let h=Ft(g,u,{runtime:r,pragma:s,development:a,detectReactivity:l,useLitHTML:c,autoShow:Ee});d.replaceWith(h)},JSXFragment(d,u){if(u.hasJSX=!0,J==="imperative"&&A==="ir"){d.replaceWith(Me(d.node,u));return}let g=H(d.node,u,{runtime:r,pragmaFrag:o,development:a});d.replaceWith(g)},CallExpression(d,u){if(!l)return;let g=d.node.callee;g.name,t.types.isIdentifier(g)&&(g.name==="createSignal"||g.name==="createStore"||g.name==="useContext"||g.name==="useLocation")&&(u.hasReactivity=!0)},JSXExpressionContainer(d){},TaggedTemplateExpression(d,u){let{tag:g,quasi:S}=d.node;d.get("quasi").get("expressions").forEach((h,E)=>{let w=h.node,$=S.quasis[E].value.raw;if($.trim().endsWith("=")||$.match(/@[\w-]+$/))return;let _=!1,N=!1;if(t.types.isMemberExpression(w)){let y=w.property;t.types.isIdentifier(y)&&(y.name=y.name.replace("$",""),u.needsLitrxImport=!0,N=!0)}(_||N)&&h.replaceWith(t.types.callExpression(t.types.identifier("((window as any).Fluixi.litrx || litrx)"),[t.types.arrowFunctionExpression([],w)]))})}}}});jt=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"])});var ze=L(()=>{"use strict"});var Be={};Se(Be,{babelPluginReactiveJSX:()=>Wt,createPlugin:()=>qt,createPreset:()=>U,default:()=>I,presets:()=>Ht});function qt(e){return[I,e]}function U(e={}){return{plugins:[[I,{runtime:"automatic",importSource:"@fluixi/jsx",development:!1,detectReactivity:!0,useLitHTML:!0,hoistStatics:!0,delegateEvents:!0,optimizeControlFlow:!0,sourceMaps:!0,...e}]]}}var Wt,Ht,We=L(()=>{"use strict";ae();ze();ae();Wt=I;Ht={production:U({development:!1,hoistStatics:!0,delegateEvents:!0,optimizeControlFlow:!0}),development:U({development:!0,hoistStatics:!1,sourceMaps:!0}),minimal:U({detectReactivity:!1,useLitHTML:!1,hoistStatics:!1,delegateEvents:!1,optimizeControlFlow:!1})}});var nn={};Se(nn,{analyzeProp:()=>G,analyzeProps:()=>Z,createBabelPlugin:()=>T,createESBuildPlugin:()=>Ye,createRollupPlugin:()=>Qe,createTypeScriptTransformer:()=>Ge,createVitePlugin:()=>Ze,createWebpackLoader:()=>Ke,default:()=>tn,generateChildrenCode:()=>pe,generateCreateElement:()=>He,generateEventDelegation:()=>ge,generateLitHTMLTemplate:()=>fe,generatePropsCode:()=>ue,hoistStatic:()=>de,isLitTemplate:()=>qe,optimizeSpreads:()=>Ue,optimizeStatic:()=>me,serverFunctionsVitePlugin:()=>en,shouldUseLitTemplate:()=>ce,transform:()=>M,transformServerFunctions:()=>z});module.exports=at(nn);var ye=require("@babel/core"),lt="@fluixi/start/server-fn";function ct(e){let n=5381;for(let r=0;r<e.length;r++)n=n*33^e.charCodeAt(r);return(n>>>0).toString(16)}function ut({types:e}){return{name:"fluixi-server-functions",visitor:{Program:{enter(n,r){r.fxIndex=0,r.fxUsed=null},exit(n,r){r.fxUsed&&n.unshiftContainer("body",e.importDeclaration([e.importSpecifier(e.identifier(r.fxUsed),e.identifier(r.fxUsed))],e.stringLiteral(r.opts.runtimeModule||lt)))}},"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression":(n,r)=>{let i=n.node.body;if(!e.isBlockStatement(i))return;let o=(i.directives||[]).findIndex(f=>f.value.value==="use server");if(o<0)return;i.directives.splice(o,1);let a=(r.opts.filename||r.filename||"unknown").replace(r.opts.root?r.opts.root+"/":"",""),l=`${ct(a)}:${r.fxIndex++}`,c=!!r.opts.ssr,m=c?"$$registerServerFn":"$$createServerReference";r.fxUsed=m;let x=c?e.callExpression(e.identifier(m),[e.stringLiteral(l),n.isFunctionDeclaration()?e.functionExpression(null,n.node.params,i,n.node.generator,n.node.async):n.node]):e.callExpression(e.identifier(m),[e.stringLiteral(l)]);n.isFunctionDeclaration()?n.replaceWith(e.variableDeclaration("const",[e.variableDeclarator(n.node.id,x)])):n.replaceWith(x),n.skip()}}}}function z(e,n){if(!e.includes("use server"))return null;let r=(0,ye.transformSync)(e,{filename:n.filename,configFile:!1,babelrc:!1,sourceMaps:!0,parserOpts:{plugins:["typescript","jsx"]},plugins:[[ut,n]]});return r?.code?{code:r.code,map:r.map}:null}var Q=require("node:fs"),xe=require("node:path"),Ut=new Set(["key","ref","children"]),Gt=[/\(\)\s*=>/,/function\s*\(\)/,/\w+\(\)/,/\w+\.\w+/,/\w+\[.+\]/,/createSignal/,/createStore/,/createMemo/,/createEffect/],Zt=/^on[A-Z]/;function G(e,n){let r={name:e,isStatic:!0,isReactive:!1,isEvent:Zt.test(e),isRef:e==="ref",isSpread:e.startsWith("...")};if(Ut.has(e))return r;if(r.isEvent||r.isRef)return r.isStatic=!1,r;if(typeof n=="string"){let i=n;for(let s of Gt)if(s.test(i)){r.isStatic=!1,r.isReactive=!0;break}i.includes("${")&&(r.isStatic=!1,r.isReactive=!0)}else typeof n=="function"?(r.isStatic=!1,r.isReactive=!0):typeof n=="object"&&n!==null&&(r.isStatic=!1);return r}function Z(e){let n=new Map;for(let[r,i]of Object.entries(e))n.set(r,G(r,i));return n}function ce(e,n,r){if(typeof e!="string")return!1;let i=Z(n);for(let s of i.values()){if(s.isSpread)return!1;s.isReactive&&s.isEvent}return!0}function qe(e){return e&&typeof e=="object"&&"_$litType$"in e}function He(e,n,r,i={}){let s=["svg","path","circle","rect","g"].includes(e),o=ue(n,i),a=r.length>0?`, ${pe(r)}`:"";return i.useLitHTML!==!1&&ce(e,n,r)?fe(e,n,r,s):`jsx('${e}', ${o}${a})`}function ue(e,n={}){if(Object.keys(e).length===0)return"{}";let r=Z(e),i=[];for(let[s,o]of Object.entries(e)){let a=r.get(s);a.isReactive&&!a.isStatic?i.push(`${s}: () => ${o}`):typeof o=="string"?i.push(`${s}: "${o}"`):typeof o=="number"||typeof o=="boolean"?i.push(`${s}: ${o}`):i.push(`${s}: ${o}`)}return`{ ${i.join(", ")} }`}function pe(e){return e.length===0?"undefined":e.length===1?String(e[0]):`[${e.join(", ")}]`}function fe(e,n,r,i=!1){let s=i?"svg":"html",o=`<${e}`,a=[];for(let[l,c]of Object.entries(n)){if(l==="children"||l==="key"||l==="ref")continue;let m=G(l,c);if(m.isEvent){let x=l.slice(2).toLowerCase();o+=` @${x}=\${${a.length}}`,a.push(String(c))}else m.isReactive?(o+=` ${l}=\${${a.length}}`,a.push(`signal(() => ${c})`)):typeof c=="string"?o+=` ${l}="${c}"`:(o+=` ${l}=\${${a.length}}`,a.push(String(c)))}if(o+=">",r.length>0)for(let l of r)typeof l=="string"?o+=l:(o+=`\${${a.length}}`,a.push(String(l)));return o+=`</${e}>`,`${s}\`${o}\`${a.length>0?`, ${a.join(", ")}`:""}`}function me(e){return e=e.replace(/jsx\('([^']+)',\s*{},\s*"([^"]+)"\s*\)/g,(n,r,i)=>`_$staticNode('${r}', '${i}')`),e}function Ue(e){return e}function de(e){let n=[],r=0;return e=e.replace(/jsx\('([^']+)',\s*{([^}]*)},\s*([^)]*)\)/g,(i,s,o,a)=>{if(!o.includes("()")&&!o.includes("=>")){let l=`_$static${r++}`;return n.push(`const ${l} = ${i};`),l}return i}),n.length>0?n.join(`
|
|
3
|
+
`)+`
|
|
4
|
+
`+e:e}function ge(e,n={}){let r=n.delegatedEvents||["click","input","change","submit"],i=e.filter(s=>r.includes(s.toLowerCase()));return i.length===0?"":`delegateEvents([${i.map(s=>`'${s}'`).join(", ")}]);`}function M(e,n={}){let r={hasSignals:/createSignal|signal\(/.test(e),hasStores:/createStore|store\(/.test(e),hasLitHTML:/html`|svg`/.test(e),staticProps:new Set,dynamicProps:new Set,components:new Set},i=e;if(n.optimize!==!1&&(i=me(i),i=de(i)),n.delegateEvents!==!1){let s=Kt(e),o=ge(s,n);o&&(i=o+`
|
|
5
|
+
`+i)}return i=Qt(i,r,n),{code:i,metadata:r}}function Kt(e){let n=new Set,r=/on([A-Z][a-z]+)/g,i;for(;(i=r.exec(e))!==null;)n.add(i[1].toLowerCase());return Array.from(n)}function Qt(e,n,r){let i=[],s=r.importSource||"@fluixi/jsx";return i.push(`import { jsx, jsxs, Fragment, spread } from '${s}';`),n.hasSignals&&i.push("import { signal } from '@fluixi/dom/reactive';"),(e.includes("<Show")||e.includes("<For")||e.includes("<Switch"))&&i.push("import { Show, For, Index, Switch, Match } from '@fluixi/dom/control-flow';"),r.delegateEvents!==!1&&i.push("import { delegateEvents } from '@fluixi/dom/runtime';"),i.join(`
|
|
6
|
+
`)+`
|
|
7
|
+
|
|
8
|
+
`+e}async function T(e={}){let n=null;try{n=await Promise.resolve().then(()=>(We(),Be))}catch(r){console.warn("Could not load the babel front-end:",r)}return{name:"babel-fluixi-jsx",plugin:n?n.default||n:null,getOptions(){return{runtime:"automatic",importSource:e.importSource||"@fluixi/jsx",pragma:e.pragma||"jsx",pragmaFrag:e.pragmaFrag||"Fragment",development:e.development||!1,detectReactivity:!0,useLitHTML:e.useLitHTML!==!1,hoistStatics:e.optimize!==!1,delegateEvents:e.delegateEvents!==!1,delegatedEvents:e.delegatedEvents||["click","input","change","submit"],optimizeControlFlow:e.optimize!==!1,sourceMaps:e.sourceMaps!==!1,backend:e.backend||"imperative",...e.codegen?{codegen:e.codegen}:{},...e.signalModule?{signalModule:e.signalModule}:{},...e.controlFlowModule?{controlFlowModule:e.controlFlowModule}:{},...e.reactiveModule?{reactiveModule:e.reactiveModule}:{}}}}}function Ge(e={}){let n=K("typescript");return n?r=>{let i=s=>n.isJsxElement(s)||n.isJsxSelfClosingElement(s)?Yt(s,e,n):n.visitEachChild(s,i,r);return s=>n.visitNode(s,i)}:(console.warn("TypeScript not found, transformer unavailable"),r=>i=>i)}function Yt(e,n,r){return e}function K(e){try{return require(e)}catch{return null}}function Ze(e={}){return{name:"vite-fluixi-jsx",enforce:"pre",config(){return{esbuild:{jsx:"automatic",jsxImportSource:e.importSource||"@fluixi/jsx"}}},async transform(n,r){let i=await T(e);if(!/\.(jsx|tsx|ts)$/i.test(r))return null;try{let s=await import("@babel/core").catch(()=>null);if(!s)return{code:M(n,e).code,map:null};let o=/\.tsx$/.test(r),a=/\.ts$/.test(r),l=[],c=[];if(o||a){let x=await import("@babel/preset-typescript").then(f=>f.default||f).catch(()=>null);x&&l.push([x,{isTSX:o,allExtensions:!0,jsxPragma:e.pragma||"jsx",jsxPragmaFrag:e.pragmaFrag||"Fragment",onlyRemoveTypeImports:!0}])}i&&i.plugin?c.push([i.plugin,i.getOptions()]):console.warn("[createVitePlugin] custom babel plugin not found");let m=await s.transformAsync(n,{filename:r,configFile:!1,babelrc:!1,presets:l,plugins:c,sourceMaps:e.sourceMaps!==!1});return{code:m?.code||n,map:m?.map}}catch(s){console.error("Transform error:",s);try{return{code:M(n,e).code,map:null}}catch(o){return console.error("Fallback transform also failed:",o),null}}}}}function Ke(e={}){return async function(n){let r=this.async(),i=K("@babel/core"),s=await T(e);if(!i||!s.plugin){let o=M(n,e);r(null,o.code);return}i.transformAsync(n,{filename:this.resourcePath,plugins:[[s.plugin,s.getOptions()]],sourceMaps:e.sourceMaps!==!1}).then(o=>{r(null,o?.code,o?.map)}).catch(o=>{r(o)})}}function Qe(e={}){return{name:"rollup-fluixi-jsx",async transform(n,r){let i=await T(e);if(!/\.[jt]sx$/.test(r))return null;try{let s=K("@babel/core");if(!s||!i.plugin)return{code:M(n,e).code,map:null};let o=await s.transformAsync(n,{filename:r,plugins:[[i.plugin,i.getOptions()]],sourceMaps:e.sourceMaps!==!1});return{code:o?.code||n,map:o?.map}}catch(s){return console.error("Transform error:",s),null}}}}function Ye(e={}){return{name:"esbuild-fluixi-jsx",setup(n){n.onLoad({filter:/\.[jt]sx$/},async r=>{let i=K("@babel/core"),s=await T(e),a=require("fs").readFileSync(r.path,"utf8");try{return!i||!s.plugin?{contents:M(a,e).code,loader:"js"}:{contents:(await i.transformAsync(a,{filename:r.path,plugins:[[s.plugin,s.getOptions()]],sourceMaps:!1}))?.code||a,loader:"js"}}catch(l){return{errors:[{text:`Transform error: ${l}`}]}}})}}}var le="virtual:fluixi-server-fns";function et(e,n=[]){let r;try{r=(0,Q.readdirSync)(e,{withFileTypes:!0})}catch{return n}for(let i of r){if(i.name==="node_modules"||i.name==="dist"||i.name.startsWith("."))continue;let s=(0,xe.join)(e,i.name);if(i.isDirectory())et(s,n);else if(/\.[jt]sx?$/.test(i.name))try{(0,Q.readFileSync)(s,"utf8").includes("use server")&&n.push(s)}catch{}}return n}function en(){let e=process.cwd();return{name:"fluixi-server-functions",enforce:"pre",configResolved(n){e=n.root||e},resolveId(n){return n===le?"\0"+le:null},load(n){if(n!=="\0"+le)return null;let r=et((0,xe.join)(e,"src")),i=`import '@fluixi/start/server-fn-setup';
|
|
9
|
+
`,s=r.map(a=>`import ${JSON.stringify(a)};`).join(`
|
|
10
|
+
`);return i+s+`
|
|
11
|
+
export { isServerFnRequest, handleServerFn } from '@fluixi/start/server-fn';
|
|
12
|
+
`},transform(n,r,i){return!/\.[jt]sx?$/.test(r)||!n.includes("use server")?null:z(n,{ssr:!!i?.ssr,filename:r,root:e})}}}var tn={analyzeProp:G,analyzeProps:Z,shouldUseLitTemplate:ce,isLitTemplate:qe,generateCreateElement:He,generatePropsCode:ue,generateChildrenCode:pe,generateLitHTMLTemplate:fe,optimizeStatic:me,optimizeSpreads:Ue,hoistStatic:de,generateEventDelegation:ge,transform:M,createBabelPlugin:T,createTypeScriptTransformer:Ge,createVitePlugin:Ze,createWebpackLoader:Ke,createRollupPlugin:Qe,createESBuildPlugin:Ye};
|