@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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -0
  3. package/dist/babel-OGRQKOZA.mjs +2 -0
  4. package/dist/chunk-3SAEGOMQ.mjs +1 -0
  5. package/dist/codegen/backend.cjs +1 -0
  6. package/dist/codegen/backend.d.ts +22 -0
  7. package/dist/codegen/backend.d.ts.map +1 -0
  8. package/dist/codegen/backend.js +1 -0
  9. package/dist/codegen/backend.mjs +0 -0
  10. package/dist/codegen/backends/imperative.cjs +1 -0
  11. package/dist/codegen/backends/imperative.d.ts +3 -0
  12. package/dist/codegen/backends/imperative.d.ts.map +1 -0
  13. package/dist/codegen/backends/imperative.js +152 -0
  14. package/dist/codegen/backends/imperative.mjs +1 -0
  15. package/dist/codegen/contract.cjs +1 -0
  16. package/dist/codegen/contract.d.ts +25 -0
  17. package/dist/codegen/contract.d.ts.map +1 -0
  18. package/dist/codegen/contract.js +30 -0
  19. package/dist/codegen/contract.mjs +1 -0
  20. package/dist/frontend/babel/build-ir.cjs +1 -0
  21. package/dist/frontend/babel/build-ir.d.ts +23 -0
  22. package/dist/frontend/babel/build-ir.d.ts.map +1 -0
  23. package/dist/frontend/babel/build-ir.js +224 -0
  24. package/dist/frontend/babel/build-ir.mjs +1 -0
  25. package/dist/frontend/babel/index.cjs +2 -0
  26. package/dist/frontend/babel/index.d.ts +34 -0
  27. package/dist/frontend/babel/index.d.ts.map +1 -0
  28. package/dist/frontend/babel/index.js +65 -0
  29. package/dist/frontend/babel/index.mjs +2 -0
  30. package/dist/frontend/babel/plugin.cjs +2 -0
  31. package/dist/frontend/babel/plugin.d.ts +122 -0
  32. package/dist/frontend/babel/plugin.d.ts.map +1 -0
  33. package/dist/frontend/babel/plugin.js +1509 -0
  34. package/dist/frontend/babel/plugin.mjs +2 -0
  35. package/dist/frontend/babel/server-functions.cjs +1 -0
  36. package/dist/frontend/babel/server-functions.d.ts +11 -0
  37. package/dist/frontend/babel/server-functions.d.ts.map +1 -0
  38. package/dist/frontend/babel/server-functions.js +88 -0
  39. package/dist/frontend/babel/server-functions.mjs +1 -0
  40. package/dist/frontend/babel/types.cjs +1 -0
  41. package/dist/frontend/babel/types.d.ts +34 -0
  42. package/dist/frontend/babel/types.d.ts.map +1 -0
  43. package/dist/frontend/babel/types.js +1 -0
  44. package/dist/frontend/babel/types.mjs +0 -0
  45. package/dist/frontend/types.cjs +1 -0
  46. package/dist/frontend/types.d.ts +26 -0
  47. package/dist/frontend/types.d.ts.map +1 -0
  48. package/dist/frontend/types.js +1 -0
  49. package/dist/frontend/types.mjs +0 -0
  50. package/dist/index.cjs +1 -0
  51. package/dist/index.d.ts +19 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +20 -0
  54. package/dist/index.mjs +1 -0
  55. package/dist/integrations.cjs +12 -0
  56. package/dist/integrations.d.ts +251 -0
  57. package/dist/integrations.d.ts.map +1 -0
  58. package/dist/integrations.js +790 -0
  59. package/dist/integrations.mjs +11 -0
  60. package/dist/ir/nodes.cjs +1 -0
  61. package/dist/ir/nodes.d.ts +80 -0
  62. package/dist/ir/nodes.d.ts.map +1 -0
  63. package/dist/ir/nodes.js +1 -0
  64. package/dist/ir/nodes.mjs +0 -0
  65. package/dist/options.cjs +1 -0
  66. package/dist/options.d.ts +18 -0
  67. package/dist/options.d.ts.map +1 -0
  68. package/dist/options.js +9 -0
  69. package/dist/options.mjs +1 -0
  70. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  71. package/package.json +70 -0
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Babel front-end: build the host-agnostic IR from a JSX AST node.
3
+ *
4
+ * This is the parsing-end half of the pipeline (AST -> IR); the imperative
5
+ * backend's emit() is the codegen half (IR -> code). Keeping the JSX analysis
6
+ * here and the code generation in the backend is what lets a future swc
7
+ * front-end reuse the exact same backend.
8
+ *
9
+ * JSX can appear nested inside arbitrary expressions (render-props, ternaries,
10
+ * `fallback={<p/>}`, `arr.map(x => <li/>)`, `() => cond && <div/>`, …). The IR
11
+ * models prop/child *expressions* as code strings, so any JSX inside such an
12
+ * expression is recursively compiled (build-ir -> emit) and spliced back in,
13
+ * with the runtime symbols it uses collected into `used` for import injection.
14
+ */
15
+ import { types as t, traverse, template } from '@babel/core';
16
+ import _generate from '@babel/generator';
17
+ import { imperativeBackend } from '../../codegen/backends/imperative.js';
18
+ // @babel/generator's ESM/CJS interop default (its types aren't callable under nodenext).
19
+ const generate = _generate.default ?? _generate;
20
+ /** Stringify an AST node back to source. */
21
+ function gen(node) {
22
+ return generate(node, { concise: true }).code;
23
+ }
24
+ /**
25
+ * Replace every JSX node nested inside `node` with the imperative code emitted
26
+ * for it (build-ir -> emit), so the resulting expression is plain JS. Runtime
27
+ * symbols used by the nested code are added to `used`.
28
+ */
29
+ function transformNestedJSX(node, used) {
30
+ const clone = t.cloneNode(node, true);
31
+ const file = t.file(t.program([t.expressionStatement(clone)]));
32
+ let changed = false;
33
+ traverse(file, {
34
+ 'JSXElement|JSXFragment'(path) {
35
+ const jsx = path.node;
36
+ const { code, imports } = imperativeBackend.emit(buildIR(jsx, used), {});
37
+ for (const s of imports)
38
+ used.add(s);
39
+ const replacement = template.expression(code, { placeholderPattern: false })();
40
+ path.replaceWith(replacement);
41
+ path.skip(); // build-ir already handled this subtree (incl. its nested JSX)
42
+ changed = true;
43
+ },
44
+ });
45
+ return changed
46
+ ? file.program.body[0].expression
47
+ : node;
48
+ }
49
+ /** Stringify an expression, compiling any JSX nested inside it first. */
50
+ function genExpr(node, used) {
51
+ return gen(transformNestedJSX(node, used));
52
+ }
53
+ const SVG_TAGS = new Set([
54
+ 'svg', 'path', 'circle', 'rect', 'line', 'polygon', 'polyline',
55
+ 'ellipse', 'g', 'defs', 'clipPath', 'text',
56
+ ]);
57
+ const EVENT_RE = /^on[A-Z]/;
58
+ const DELEGATED = new Set([
59
+ 'click', 'dblclick', 'input', 'change', 'submit', 'focus', 'blur',
60
+ 'keydown', 'keyup', 'keypress', 'mousedown', 'mouseup',
61
+ ]);
62
+ /** A JSX tag is a component when its name is capitalized / a member / namespaced. */
63
+ function tagInfo(name) {
64
+ if (t.isJSXIdentifier(name)) {
65
+ const isComponent = name.name[0] !== name.name[0].toLowerCase();
66
+ return { tag: name.name, component: isComponent };
67
+ }
68
+ if (t.isJSXMemberExpression(name))
69
+ return { tag: gen(name), component: true };
70
+ if (t.isJSXNamespacedName(name)) {
71
+ return { tag: `${name.namespace.name}:${name.name.name}`, component: false };
72
+ }
73
+ return { tag: 'div', component: false };
74
+ }
75
+ function attrName(name) {
76
+ if (t.isJSXIdentifier(name))
77
+ return name.name === 'class' ? 'className' : name.name;
78
+ if (t.isJSXNamespacedName(name))
79
+ return `${name.namespace.name}:${name.name.name}`;
80
+ return 'unknown';
81
+ }
82
+ /**
83
+ * Reactivity heuristic, aligned with the babel transform: calls and member
84
+ * accesses (e.g. `count()`, `store.value`) are wired reactively; bare
85
+ * identifiers and literals are passed through as-is.
86
+ */
87
+ function isReactiveExpr(node) {
88
+ if (t.isCallExpression(node) || t.isOptionalCallExpression(node))
89
+ return true;
90
+ if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
91
+ // `props.children` (any `.children` access) is a stable subtree reference,
92
+ // not a reactive value. Compiling it to a `() => props.children` thunk adds
93
+ // an insert layer that fully unwraps the children's Suspense/memo to a static
94
+ // node, severing the reactive binding — so a nested lazy/Suspense that
95
+ // resolves later never propagates up through the component-children hop.
96
+ // Passing it through non-reactive (insert(el, props.children)) keeps the
97
+ // child's memo intact so insert binds to it (mirrors a direct <Outlet/>).
98
+ if (!node.computed && t.isIdentifier(node.property, { name: 'children' }))
99
+ return false;
100
+ return true;
101
+ }
102
+ if (t.isConditionalExpression(node)) {
103
+ return isReactiveExpr(node.test) || isReactiveExpr(node.consequent) || isReactiveExpr(node.alternate);
104
+ }
105
+ if (t.isLogicalExpression(node) || t.isBinaryExpression(node)) {
106
+ return isReactiveExpr(node.left) || isReactiveExpr(node.right);
107
+ }
108
+ if (t.isTemplateLiteral(node))
109
+ return node.expressions.some((e) => isReactiveExpr(e));
110
+ return false;
111
+ }
112
+ function buildAttr(attr, used) {
113
+ const name = attrName(attr.name);
114
+ const isEvent = EVENT_RE.test(name);
115
+ const kind = isEvent ? 'event' : 'attr';
116
+ const base = { name, kind };
117
+ if (isEvent) {
118
+ base.event = { name: name.slice(2).toLowerCase(), delegated: DELEGATED.has(name.slice(2).toLowerCase()) };
119
+ }
120
+ const v = attr.value;
121
+ if (v == null) {
122
+ base.literal = true; // valueless attribute
123
+ return base;
124
+ }
125
+ if (t.isStringLiteral(v)) {
126
+ base.literal = v.value;
127
+ return base;
128
+ }
129
+ if (t.isJSXExpressionContainer(v) && !t.isJSXEmptyExpression(v.expression)) {
130
+ const expr = v.expression;
131
+ if (t.isStringLiteral(expr) || t.isNumericLiteral(expr) || t.isBooleanLiteral(expr)) {
132
+ base.literal = expr.value;
133
+ return base;
134
+ }
135
+ base.expr = genExpr(expr, used);
136
+ base.reactive = isEvent ? false : isReactiveExpr(expr);
137
+ if (t.isJSXElement(expr) || t.isJSXFragment(expr))
138
+ base.jsxElement = true;
139
+ return base;
140
+ }
141
+ base.literal = true;
142
+ return base;
143
+ }
144
+ function buildProps(attrs, used) {
145
+ const props = [];
146
+ for (const a of attrs) {
147
+ if (t.isJSXSpreadAttribute(a)) {
148
+ props.push({ name: '', kind: 'spread', expr: genExpr(a.argument, used) });
149
+ }
150
+ else if (t.isJSXAttribute(a)) {
151
+ props.push(buildAttr(a, used));
152
+ }
153
+ }
154
+ return props;
155
+ }
156
+ /** Canonical JSX text cleaning — kept identical to plugin.ts cleanJSXText. */
157
+ function cleanJSXText(value) {
158
+ const lines = value.split(/\r\n|\n|\r/);
159
+ let lastNonEmpty = 0;
160
+ for (let i = 0; i < lines.length; i++) {
161
+ if (/[^ \t]/.test(lines[i]))
162
+ lastNonEmpty = i;
163
+ }
164
+ let out = '';
165
+ for (let i = 0; i < lines.length; i++) {
166
+ let line = lines[i].replace(/\t/g, ' ');
167
+ if (i !== 0)
168
+ line = line.replace(/^ +/, '');
169
+ if (i !== lines.length - 1)
170
+ line = line.replace(/ +$/, '');
171
+ if (!line)
172
+ continue;
173
+ if (i !== lastNonEmpty)
174
+ line += ' ';
175
+ out += line;
176
+ }
177
+ return out;
178
+ }
179
+ function buildChildren(children, used) {
180
+ const out = [];
181
+ for (const child of children) {
182
+ if (t.isJSXText(child)) {
183
+ // Canonical JSX whitespace (kept in sync with plugin.ts cleanJSXText):
184
+ // drop whitespace-only text spanning a newline so a lone child stays lone
185
+ // (an array insert won't reactively bind a memo/component inside it).
186
+ const text = cleanJSXText(child.value);
187
+ if (text)
188
+ out.push({ kind: 'text', value: text });
189
+ }
190
+ else if (t.isJSXExpressionContainer(child)) {
191
+ if (!t.isJSXEmptyExpression(child.expression)) {
192
+ const expr = child.expression;
193
+ out.push({ kind: 'expr', code: genExpr(expr, used), reactive: isReactiveExpr(expr) });
194
+ }
195
+ }
196
+ else if (t.isJSXElement(child)) {
197
+ out.push(buildIR(child, used));
198
+ }
199
+ else if (t.isJSXFragment(child)) {
200
+ out.push(buildIR(child, used));
201
+ }
202
+ else if (t.isJSXSpreadChild(child)) {
203
+ out.push({ kind: 'expr', code: genExpr(child.expression, used), reactive: false });
204
+ }
205
+ }
206
+ return out;
207
+ }
208
+ /**
209
+ * Build IR from a JSXElement or JSXFragment. `used` accumulates the runtime
210
+ * symbols emitted for any JSX nested inside expressions (so the caller can
211
+ * inject the right imports).
212
+ */
213
+ export function buildIR(node, used = new Set()) {
214
+ if (t.isJSXFragment(node)) {
215
+ return { kind: 'fragment', children: buildChildren(node.children, used) };
216
+ }
217
+ const { tag, component } = tagInfo(node.openingElement.name);
218
+ const props = buildProps(node.openingElement.attributes, used);
219
+ const children = buildChildren(node.children, used);
220
+ if (component) {
221
+ return { kind: 'component', name: tag, props, children };
222
+ }
223
+ return { kind: 'element', tag, svg: SVG_TAGS.has(tag), props, children, static: false };
224
+ }
@@ -0,0 +1 @@
1
+ import{types as i,traverse as b,template as k}from"@babel/core";import h from"@babel/generator";var f={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},B={version:2,module:"@fluixi/dom",symbols:[...f.symbols,"template","cloneTemplate","walk"]};var R={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function v(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function x(e){return v(e)?e:JSON.stringify(e)}function C(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 X(e,t,n){let r=e.filter(a=>a.kind==="spread"),o=e.filter(a=>a.kind!=="spread").map(a=>`${x(a.name)}: ${C(a)}`);t!=null&&o.push(`children: ${t}`);let p=`{ ${o.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(a=>a.expr).join(", ")}, ${p})`):p}function S(e,t){return e.length===1?m(e[0],t):`[${e.map(n=>m(n,t)).join(", ")}]`}function d(e,t,n,r){r.add("createMemo"),r.add("createComponent");let s=t.filter(c=>c.kind==="spread"),p=t.filter(c=>c.kind!=="spread").map(c=>`get ${x(c.name)}() { return ${I(c)}; }`);n.length>0&&p.push(`get children() { return ${S(n,r)}; }`);let a=`{ ${p.join(", ")} }`;return s.length>0&&(r.add("mergeProps"),a=`mergeProps(${s.map(c=>c.expr).join(", ")}, ${a})`),`createMemo(() => createComponent(${e}, ${a}))`}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":S(e.children,t);case"component":return d(e.name,e.props,e.children,t);case"control":{let n=R[e.control]??e.control;return t.add(n),d(n,e.props,e.children,t)}case"element":{t.add("createNativeElement");let n=JSON.stringify(e.tag),r="_el$",s=[],o=e.svg?`${n}, true`:n;if(s.push(`const ${r} = createNativeElement(${o});`),e.props.length>0){t.add("spread");let p=e.svg?", isSVG: true":"";s.push(`spread({ element: ${r}, props: ${X(e.props,null,t)}${p} });`)}for(let p of e.children){t.add("insert");let a=m(p,t),c=p.kind==="expr"&&p.reactive||p.kind==="component"||p.kind==="control";s.push(c?`insert(${r}, ${a}, null);`:`insert(${r}, ${a});`)}return s.push(`return ${r};`),`(() => { ${s.join(" ")} })()`}}}var E={name:"imperative",contract:f,emit(e,t){let n=new Set;return{code:m(e,n),imports:Array.from(n)}}};var P=h.default??h;function $(e){return P(e,{concise:!0}).code}function A(e,t){let n=i.cloneNode(e,!0),r=i.file(i.program([i.expressionStatement(n)])),s=!1;return b(r,{"JSXElement|JSXFragment"(o){let p=o.node,{code:a,imports:c}=E.emit(g(p,t),{});for(let J of c)t.add(J);let N=k.expression(a,{placeholderPattern:!1})();o.replaceWith(N),o.skip(),s=!0}}),s?r.program.body[0].expression:e}function u(e,t){return $(A(e,t))}var w=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),T=/^on[A-Z]/,O=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function j(e){if(i.isJSXIdentifier(e)){let t=e.name[0]!==e.name[0].toLowerCase();return{tag:e.name,component:t}}return i.isJSXMemberExpression(e)?{tag:$(e),component:!0}:i.isJSXNamespacedName(e)?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function _(e){return i.isJSXIdentifier(e)?e.name==="class"?"className":e.name:i.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:"unknown"}function l(e){return i.isCallExpression(e)||i.isOptionalCallExpression(e)?!0:i.isMemberExpression(e)||i.isOptionalMemberExpression(e)?!(!e.computed&&i.isIdentifier(e.property,{name:"children"})):i.isConditionalExpression(e)?l(e.test)||l(e.consequent)||l(e.alternate):i.isLogicalExpression(e)||i.isBinaryExpression(e)?l(e.left)||l(e.right):i.isTemplateLiteral(e)?e.expressions.some(t=>l(t)):!1}function M(e,t){let n=_(e.name),r=T.test(n),o={name:n,kind:r?"event":"attr"};r&&(o.event={name:n.slice(2).toLowerCase(),delegated:O.has(n.slice(2).toLowerCase())});let p=e.value;if(p==null)return o.literal=!0,o;if(i.isStringLiteral(p))return o.literal=p.value,o;if(i.isJSXExpressionContainer(p)&&!i.isJSXEmptyExpression(p.expression)){let a=p.expression;return i.isStringLiteral(a)||i.isNumericLiteral(a)||i.isBooleanLiteral(a)?(o.literal=a.value,o):(o.expr=u(a,t),o.reactive=r?!1:l(a),(i.isJSXElement(a)||i.isJSXFragment(a))&&(o.jsxElement=!0),o)}return o.literal=!0,o}function L(e,t){let n=[];for(let r of e)i.isJSXSpreadAttribute(r)?n.push({name:"",kind:"spread",expr:u(r.argument,t)}):i.isJSXAttribute(r)&&n.push(M(r,t));return n}function F(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let s=0;s<t.length;s++)/[^ \t]/.test(t[s])&&(n=s);let r="";for(let s=0;s<t.length;s++){let o=t[s].replace(/\t/g," ");s!==0&&(o=o.replace(/^ +/,"")),s!==t.length-1&&(o=o.replace(/ +$/,"")),o&&(s!==n&&(o+=" "),r+=o)}return r}function y(e,t){let n=[];for(let r of e)if(i.isJSXText(r)){let s=F(r.value);s&&n.push({kind:"text",value:s})}else if(i.isJSXExpressionContainer(r)){if(!i.isJSXEmptyExpression(r.expression)){let s=r.expression;n.push({kind:"expr",code:u(s,t),reactive:l(s)})}}else i.isJSXElement(r)||i.isJSXFragment(r)?n.push(g(r,t)):i.isJSXSpreadChild(r)&&n.push({kind:"expr",code:u(r.expression,t),reactive:!1});return n}function g(e,t=new Set){if(i.isJSXFragment(e))return{kind:"fragment",children:y(e.children,t)};let{tag:n,component:r}=j(e.openingElement.name),s=L(e.openingElement.attributes,t),o=y(e.children,t);return r?{kind:"component",name:n,props:s,children:o}:{kind:"element",tag:n,svg:w.has(n),props:s,children:o,static:!1}}export{g as buildIR};
@@ -0,0 +1,2 @@
1
+ "use strict";var be=Object.create;var $=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var Ce=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var ve=(e,n)=>{for(var r in n)$(e,r,{get:n[r],enumerable:!0})},Q=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Je(n))!Xe.call(e,s)&&s!==r&&$(e,s,{get:()=>n[s],enumerable:!(i=ye(n,s))||i.enumerable});return e};var we=(e,n,r)=>(r=e!=null?be(Ce(e)):{},Q(n||!e||!e.__esModule?$(r,"default",{value:e,enumerable:!0}):r,e)),Fe=e=>Q($({},"__esModule",{value:!0}),e);var ut={};ve(ut,{babelPluginReactiveJSX:()=>lt,createPlugin:()=>ct,createPreset:()=>B,default:()=>L,presets:()=>pt});module.exports=Fe(ut);var ae=require("@babel/helper-plugin-utils"),t=require("@babel/core");var p=require("@babel/core"),G=we(require("@babel/generator"),1);var q={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},mt={version:2,module:"@fluixi/dom",symbols:[...q.symbols,"template","cloneTemplate","walk"]};var je={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Pe(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function ee(e){return Pe(e)?e:JSON.stringify(e)}function Ie(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function Le(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function Me(e,n,r){let i=e.filter(l=>l.kind==="spread"),o=e.filter(l=>l.kind!=="spread").map(l=>`${ee(l.name)}: ${Ie(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 te(e,n){return e.length===1?D(e[0],n):`[${e.map(r=>D(r,n)).join(", ")}]`}function Y(e,n,r,i){i.add("createMemo"),i.add("createComponent");let s=n.filter(u=>u.kind==="spread"),a=n.filter(u=>u.kind!=="spread").map(u=>`get ${ee(u.name)}() { return ${Le(u)}; }`);r.length>0&&a.push(`get children() { return ${te(r,i)}; }`);let l=`{ ${a.join(", ")} }`;return s.length>0&&(i.add("mergeProps"),l=`mergeProps(${s.map(u=>u.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${e}, ${l}))`}function D(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":te(e.children,n);case"component":return Y(e.name,e.props,e.children,n);case"control":{let r=je[e.control]??e.control;return n.add(r),Y(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: ${Me(e.props,null,n)}${a} });`)}for(let a of e.children){n.add("insert");let l=D(a,n),u=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";s.push(u?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return s.push(`return ${i};`),`(() => { ${s.join(" ")} })()`}}}var V={name:"imperative",contract:q,emit(e,n){let r=new Set;return{code:D(e,r),imports:Array.from(r)}}};var Ne=G.default.default??G.default;function re(e){return Ne(e,{concise:!0}).code}function Ae(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:u}=V.emit(R(a,n),{});for(let b of u)n.add(b);let g=p.template.expression(l,{placeholderPattern:!1})();o.replaceWith(g),o.skip(),s=!0}}),s?i.program.body[0].expression:e}function _(e,n){return re(Ae(e,n))}var Re=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),Oe=/^on[A-Z]/,ke=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Te(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:re(e),component:!0}:p.types.isJSXNamespacedName(e)?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function $e(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 De(e,n){let r=$e(e.name),i=Oe.test(r),o={name:r,kind:i?"event":"attr"};i&&(o.event={name:r.slice(2).toLowerCase(),delegated:ke.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=_(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 Ve(e,n){let r=[];for(let i of e)p.types.isJSXSpreadAttribute(i)?r.push({name:"",kind:"spread",expr:_(i.argument,n)}):p.types.isJSXAttribute(i)&&r.push(De(i,n));return r}function _e(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 ne(e,n){let r=[];for(let i of e)if(p.types.isJSXText(i)){let s=_e(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:_(s,n),reactive:F(s)})}}else p.types.isJSXElement(i)||p.types.isJSXFragment(i)?r.push(R(i,n)):p.types.isJSXSpreadChild(i)&&r.push({kind:"expr",code:_(i.expression,n),reactive:!1});return r}function R(e,n=new Set){if(p.types.isJSXFragment(e))return{kind:"fragment",children:ne(e.children,n)};let{tag:r,component:i}=Te(e.openingElement.name),s=Ve(e.openingElement.attributes,n),o=ne(e.children,n);return i?{kind:"component",name:r,props:s,children:o}:{kind:"element",tag:r,svg:Re.has(r),props:s,children:o,static:!1}}var le=new Set(["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary","Suspense"]),ze={Show:"when",For:"each",Index:"each",Match:"when"};var ce=/^on[A-Z]/,pe=["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave"],L=(0,ae.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:u=!0,hoistStatics:g=!0,delegateEvents:b=!0,delegatedEvents:m=pe,optimizeControlFlow:y=!0,sourceMaps:P=!0,signalModule:J="@fluixi/dom",controlFlowModule:w="@fluixi/dom",reactiveModule:M="@fluixi/reactive/signal",autoShowTransform:K=!1,backend:X="imperative",codegen:N="inline"}=n,he={backend:X,codegen:N,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,he)},visitor:{ImportDeclaration(f,c){f.node.source.value==="@fluixi/core/rx"&&(f.node.source=t.types.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:K,staticCounter:0,libModule:"@fluixi/core",backend:X,codegen:N,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(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("signal"),t.types.identifier("signal"))],t.types.stringLiteral(J))),c.needsLitrxImport&&!f.scope.hasBinding("litrx")&&d.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("litrx"),t.types.identifier("litrx"))],t.types.stringLiteral(c.libModule)))),c.hasJSX){if(X==="imperative"&&N==="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"]),E=Array.from(c.irImports),v=h=>t.types.importSpecifier(t.types.identifier(h),t.types.identifier(h)),I=h=>!f.scope.hasBinding(h),W=E.filter(h=>S.has(h)&&I(h)),T=E.filter(h=>!x.has(h)&&!S.has(h)&&I(h)),A=E.filter(h=>x.has(h)&&I(h));W.length>0&&d.push(t.types.importDeclaration(W.map(v),t.types.stringLiteral(M))),T.length>0&&d.push(t.types.importDeclaration(T.map(v),t.types.stringLiteral(J))),A.length>0&&d.push(t.types.importDeclaration(A.map(v),t.types.stringLiteral(w)))}else if(X==="imperative"){let S=[[!!c.needsCreateNativeElement,"createNativeElement"],[!!c.needsSpread,"spread"],[!!c.needsInsert,"insert"],[!!c.needsCreateComponent,"createComponent"],[!!c.needsMergeProps,"mergeProps"]].filter(([E,v])=>E&&!f.scope.hasBinding(v)).map(([,E])=>t.types.importSpecifier(t.types.identifier(E),t.types.identifier(E)));S.length>0&&d.push(t.types.importDeclaration(S,t.types.stringLiteral(J)))}else if(r==="automatic"){let x=[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&&x.push(t.types.importSpecifier(t.types.identifier("jsxDEV"),t.types.identifier("jsxDEV"))),c.needsMergeProps&&x.push(t.types.importSpecifier(t.types.identifier("mergeProps"),t.types.identifier("mergeProps"))),d.push(t.types.importDeclaration(x,t.types.stringLiteral(i)))}if(c.needsCreateMemo&&!f.scope.hasBinding("createMemo")&&d.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("createMemo"),t.types.identifier("createMemo"))],t.types.stringLiteral(X==="imperative"?M: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(E=>t.types.importSpecifier(t.types.identifier(E),t.types.identifier(E)));d.push(t.types.importDeclaration(S,t.types.stringLiteral(w)))}}if(b&&c.delegatedEvents.size>0){d.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("delegateEvents"),t.types.identifier("delegateEvents"))],t.types.stringLiteral(X==="imperative"?J:"@fluixi/jsx")));let x=t.types.arrayExpression(Array.from(c.delegatedEvents).map(E=>t.types.stringLiteral(E))),S=t.types.expressionStatement(t.types.callExpression(t.types.identifier("delegateEvents"),[x]));f.node.body.unshift(S)}if(g&&c.staticElements.size>0){let x=[];c.staticElements.forEach((S,E)=>{x.push(t.types.variableDeclaration("const",[t.types.variableDeclarator(t.types.identifier(E),S)]))}),f.node.body.unshift(...x)}}d.length>0&&f.node.body.unshift(...d)}},JSXElement(f,c){if(c.hasJSX=!0,X==="imperative"&&N==="ir"){f.replaceWith(se(f.node,c));return}let d=f.node,x=d.openingElement;if(t.types.isJSXIdentifier(x.name)&&le.has(x.name.name)&&(c.controlFlowComponents.add(x.name.name),y)){let E=st(d,c);if(E){f.replaceWith(E);return}}if(g&&X!=="imperative"&&Se(d,c)){let E=it(d,c);if(E){f.replaceWith(E);return}}let S=Be(d,c,{runtime:r,pragma:s,development:a,detectReactivity:l,useLitHTML:u,autoShow:K});f.replaceWith(S)},JSXFragment(f,c){if(c.hasJSX=!0,X==="imperative"&&N==="ir"){f.replaceWith(se(f.node,c));return}let d=z(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,t.types.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,E)=>{let v=S.node,I=x.quasis[E].value.raw;if(I.trim().endsWith("=")||I.match(/@[\w-]+$/))return;let T=!1,A=!1;if(t.types.isMemberExpression(v)){let h=v.property;t.types.isIdentifier(h)&&(h.name=h.name.replace("$",""),c.needsLitrxImport=!0,A=!0)}(T||A)&&S.replaceWith(t.types.callExpression(t.types.identifier("((window as any).Fluixi.litrx || litrx)"),[t.types.arrowFunctionExpression([],v)]))})}}}});function Be(e,n,r){let{runtime:i,pragma:s,development:o,autoShow:a=!0}=r;return i==="automatic"?k(e,n,o,a):He(e,n,s)}var We=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]);function ie(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 ue(e){return e.length===1?e[0]:t.types.arrayExpression(e)}function qe(e,n,r,i,s,o){if(!n){let m=[...r];return s.length>0&&m.push(t.types.objectMethod("get",t.types.identifier("children"),[],t.types.blockStatement([t.types.returnStatement(ue(s))]))),fe(e,ie(m,i,o),o)}let a=e.value,l=We.has(a),u=t.types.identifier("_el$"),g=[];o.needsCreateNativeElement=!0;let b=[e];if(l&&b.push(t.types.booleanLiteral(!0)),g.push(t.types.variableDeclaration("const",[t.types.variableDeclarator(u,t.types.callExpression(t.types.identifier("createNativeElement"),b))])),r.length>0||i.length>0){o.needsSpread=!0;let m=[t.types.objectProperty(t.types.identifier("element"),u),t.types.objectProperty(t.types.identifier("props"),ie(r,i,o))];l&&m.push(t.types.objectProperty(t.types.identifier("isSVG"),t.types.booleanLiteral(!0))),g.push(t.types.expressionStatement(t.types.callExpression(t.types.identifier("spread"),[t.types.objectExpression(m)])))}if(s.length>0){o.needsInsert=!0;for(let m of s){let P=t.types.isArrowFunctionExpression(m)||t.types.isFunctionExpression(m)||t.types.isCallExpression(m)&&t.types.isIdentifier(m.callee)&&m.callee.name==="createMemo"?[t.types.cloneNode(u),m,t.types.nullLiteral()]:[t.types.cloneNode(u),m];g.push(t.types.expressionStatement(t.types.callExpression(t.types.identifier("insert"),P)))}}return g.push(t.types.returnStatement(u)),t.types.callExpression(t.types.arrowFunctionExpression([],t.types.blockStatement(g)),[])}function fe(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 se(e,n){let r=new Set,i=R(e,r),{code:s,imports:o}=V.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 Ge(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 k(e,n,r,i=!0){let s=e.openingElement,o=e.children,a=me(s.name),l=t.types.isJSXIdentifier(s.name)&&/^[a-z]/.test(s.name.name),u=ge(s.attributes,n,l,t.types.isJSXIdentifier(s.name)?s.name.name:""),g=u.props,b=u.spreads;l||(g=Ge(g));let m=Z(o,n,i);if(n.backend==="imperative")return qe(a,l,g,b,m,n);if(m.length>0){let w=m.length===1?m[0]:t.types.arrayExpression(m);g.push(t.types.objectProperty(t.types.identifier("children"),w))}let y;if(b.length>0){let w=g.length>0?t.types.objectExpression(g):t.types.objectExpression([]);n.needsMergeProps=!0,y=t.types.callExpression(t.types.identifier("mergeProps"),[...b,w])}else y=t.types.objectExpression(g);let P=r?"jsxDEV":m.length>1?"jsxs":"jsx",J=[a,y];return r&&J.push(t.types.identifier("undefined"),t.types.booleanLiteral(!1),t.types.identifier("undefined"),t.types.identifier("undefined")),t.types.callExpression(t.types.identifier(P),J)}function He(e,n,r){let i=e.openingElement,s=e.children,o=me(i.name),a=t.types.isJSXIdentifier(i.name)&&/^[a-z]/.test(i.name.name),{props:l,spreads:u}=ge(i.attributes,n,a,t.types.isJSXIdentifier(i.name)?i.name.name:""),g=Z(s,n,n.autoShow??!0),b;if(u.length>0){let y=l.length>0?t.types.objectExpression(l):t.types.objectExpression([]);n.needsMergeProps=!0,b=t.types.callExpression(t.types.identifier("mergeProps"),[...u,y])}else b=l.length>0?t.types.objectExpression(l):t.types.nullLiteral();let m=[o,b,...g];return t.types.callExpression(t.types.identifier(r),m)}function z(e,n,r){let{runtime:i,pragmaFrag:s,development:o}=r,a=Z(e.children,n,n.autoShow??!0);if(n.backend==="imperative")return a.length===0?t.types.nullLiteral():ue(a);if(i==="automatic"){let l=o?"jsxDEV":a.length>1?"jsxs":"jsx",u=t.types.objectExpression([t.types.objectProperty(t.types.identifier("children"),a.length===1?a[0]:t.types.arrayExpression(a))]),g=[t.types.identifier("Fragment"),u];return o&&g.push(t.types.identifier("undefined"),t.types.booleanLiteral(!1),t.types.identifier("undefined"),t.types.identifier("undefined")),t.types.callExpression(t.types.identifier(l),g)}else return t.types.callExpression(t.types.identifier(s),a)}function me(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)?de(e):t.types.isJSXNamespacedName(e)?t.types.stringLiteral(`${e.namespace.name}:${e.name.name}`):t.types.stringLiteral("div")}function de(e){let n;return t.types.isJSXIdentifier(e.object)?n=t.types.identifier(e.object.name):n=de(e.object),t.types.memberExpression(n,t.types.identifier(e.property.name))}function Ze(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)}function ge(e,n,r=!0,i=""){let s=[],o=[],a=ze[i];for(let l of e)if(t.types.isJSXSpreadAttribute(l))o.push(l.argument);else if(t.types.isJSXAttribute(l)){let u=Ue(l.name),g=Ke(l.value,n,u,r);if(ce.test(u)){let M=u.slice(2).toLowerCase();pe.includes(M)&&n.delegatedEvents.add(M)}let b=Ze(u)?t.types.identifier(u):t.types.stringLiteral(u),m=l.value,y=t.types.isJSXElement(m)||t.types.isJSXFragment(m)||t.types.isJSXExpressionContainer(m)&&(t.types.isJSXElement(m.expression)||t.types.isJSXFragment(m.expression)),P=!r&&u===a,J=t.types.isJSXExpressionContainer(m)&&!t.types.isJSXEmptyExpression(m.expression)?m.expression:null,w=!r&&!!J&&Ee(J,u);!r&&y||P||w?s.push(t.types.objectMethod("get",b,[],t.types.blockStatement([t.types.returnStatement(g)]))):s.push(t.types.objectProperty(b,g))}return{props:s,spreads:o}}function Ue(e){return t.types.isJSXIdentifier(e)?e.name==="class"?"className":e.name:t.types.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:"unknown"}function Ke(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&&Ee(s,r)?t.types.arrowFunctionExpression([],s):s}return t.types.isJSXElement(e)?k(e,n,!1,n.autoShow??!0):t.types.isJSXFragment(e)?z(e,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1}):t.types.booleanLiteral(!0)}function Ee(e,n){return ce.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 Qe(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 Z(e,n,r=!0){let i=[];for(let s of e)if(t.types.isJSXText(s)){let o=Qe(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=Ye(o,n)??et(o,n);if(a){i.push(a);continue}}else{let a=tt(o,n);if(a){i.push(a);continue}}rt(o)?i.push(t.types.arrowFunctionExpression([],o)):i.push(o)}}else t.types.isJSXElement(s)?i.push(k(s,n,!1,n.autoShow??!0)):t.types.isJSXFragment(s)?i.push(z(s,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})):t.types.isJSXSpreadChild(s)&&i.push(s.expression);return i}function Ye(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 O(j(r.left),i,null,n)}if(t.types.isConditionalExpression(r)){let i=C(r.consequent);if(i){let s=U(r.alternate,n);return O(j(r.test),i,s,n,!0)}}return null}function et(e,n){if(t.types.isLogicalExpression(e)&&e.operator==="&&"){let r=C(e.right);if(r)return O(j(e.left),r,null,n)}if(t.types.isConditionalExpression(e)){let r=C(e.consequent);if(r){let i=U(e.alternate,n);return O(j(e.test),r,i,n)}}return null}function tt(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,u=t.types.conditionalExpression(i,o,l);return H(r.consequent)||H(r.alternate)?null:(n.needsCreateMemo=!0,t.types.callExpression(t.types.identifier("createMemo"),[t.types.arrowFunctionExpression([],u)]))}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 H(r.right)?null:(n.needsCreateMemo=!0,t.types.callExpression(t.types.identifier("createMemo"),[t.types.arrowFunctionExpression([],a)]))}return null}function U(e,n){if(nt(e))return null;let r=C(e);if(r)return xe(r,n);if(t.types.isConditionalExpression(e)){let i=e,s=C(i.consequent);if(s){let o=U(i.alternate,n);return O(j(i.test),s,o,n)}}return e}function oe(e){return t.types.isJSXElement(e)||t.types.isJSXFragment(e)}function H(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 oe(e)?e:t.types.isArrowFunctionExpression(e)&&e.params.length===0&&!e.async&&oe(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 nt(e){return t.types.isNullLiteral(e)||t.types.isIdentifier(e)&&e.name==="undefined"||t.types.isBooleanLiteral(e)&&e.value===!1}function xe(e,n){return t.types.isJSXElement(e)?k(e,n,!1,n.autoShow??!0):z(e,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})}function O(e,n,r,i,s=!1){i.controlFlowComponents.add("Show"),i.needsControlFlowImport=!0;let o=xe(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)),fe(t.types.identifier("Show"),t.types.objectExpression(a),i)}function rt(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 Se(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)&&!Se(s,n)||t.types.isJSXExpressionContainer(s))return!1;return!0}function it(e,n){let r=`_$static${n.staticCounter++}`,i=k(e,n,!1);return n.staticElements.set(r,i),t.types.identifier(r)}function st(e,n){let r=e.openingElement.name.name;return r==="Show"?ot(e,n):r==="For"?at(e,n):null}function ot(e,n){return null}function at(e,n){return null}var lt=L;function ct(e){return[L,e]}function B(e={}){return{plugins:[[L,{runtime:"automatic",importSource:"@fluixi/jsx",development:!1,detectReactivity:!0,useLitHTML:!0,hoistStatics:!0,delegateEvents:!0,optimizeControlFlow:!0,sourceMaps:!0,...e}]]}}var pt={production:B({development:!1,hoistStatics:!0,delegateEvents:!0,optimizeControlFlow:!0}),development:B({development:!0,hoistStatics:!1,sourceMaps:!0}),minimal:B({detectReactivity:!1,useLitHTML:!1,hoistStatics:!1,delegateEvents:!1,optimizeControlFlow:!1})};
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @fileoverview Babel front-end adapter for the Fluixi compiler.
3
+ * @module @fluixi/compiler/babel
4
+ *
5
+ * This is one of the compiler's front-end adapters: it parses with @babel and
6
+ * runs the JSX transform. The transform/codegen it currently performs is the
7
+ * existing behaviour (emits the jsx() automatic runtime) — switching codegen to
8
+ * the IR-driven backends (see ../../codegen) is a later step. SWC/other
9
+ * front-ends will plug in alongside this without touching the rest of the pipeline.
10
+ */
11
+ export { default } from './plugin.js';
12
+ export type { PluginOptions } from './plugin.js';
13
+ export * from './types.js';
14
+ /** Named export for explicit usage */
15
+ export declare const babelPluginReactiveJSX: (api: object, options: import("./plugin.js").PluginOptions | null | undefined, dirname: string) => import("@babel/core").PluginObj<import("@babel/core").PluginPass>;
16
+ /** Helper to create plugin with options */
17
+ export declare function createPlugin(options?: any): any[];
18
+ /** Preset with recommended configuration */
19
+ export declare function createPreset(options?: any): {
20
+ plugins: any[][];
21
+ };
22
+ /** Quick setup presets */
23
+ export declare const presets: {
24
+ production: {
25
+ plugins: any[][];
26
+ };
27
+ development: {
28
+ plugins: any[][];
29
+ };
30
+ minimal: {
31
+ plugins: any[][];
32
+ };
33
+ };
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/frontend/babel/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,cAAc,YAAY,CAAC;AAK3B,sCAAsC;AACtC,eAAO,MAAM,sBAAsB,sKAAS,CAAC;AAE7C,2CAA2C;AAC3C,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,SAEzC;AAED,4CAA4C;AAC5C,wBAAgB,YAAY,CAAC,OAAO,GAAE,GAAQ;;EAoB7C;AAED,0BAA0B;AAC1B,eAAO,MAAM,OAAO;;;;;;;;;;CAmBnB,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @fileoverview Babel front-end adapter for the Fluixi compiler.
3
+ * @module @fluixi/compiler/babel
4
+ *
5
+ * This is one of the compiler's front-end adapters: it parses with @babel and
6
+ * runs the JSX transform. The transform/codegen it currently performs is the
7
+ * existing behaviour (emits the jsx() automatic runtime) — switching codegen to
8
+ * the IR-driven backends (see ../../codegen) is a later step. SWC/other
9
+ * front-ends will plug in alongside this without touching the rest of the pipeline.
10
+ */
11
+ // Export the main plugin
12
+ export { default } from './plugin.js';
13
+ // Export types
14
+ export * from './types.js';
15
+ // Re-export for convenience
16
+ import plugin from './plugin.js';
17
+ /** Named export for explicit usage */
18
+ export const babelPluginReactiveJSX = plugin;
19
+ /** Helper to create plugin with options */
20
+ export function createPlugin(options) {
21
+ return [plugin, options];
22
+ }
23
+ /** Preset with recommended configuration */
24
+ export function createPreset(options = {}) {
25
+ return {
26
+ plugins: [
27
+ [
28
+ plugin,
29
+ {
30
+ runtime: 'automatic',
31
+ importSource: '@fluixi/jsx',
32
+ development: process.env.NODE_ENV === 'development',
33
+ detectReactivity: true,
34
+ useLitHTML: true,
35
+ hoistStatics: true,
36
+ delegateEvents: true,
37
+ optimizeControlFlow: true,
38
+ sourceMaps: true,
39
+ ...options,
40
+ },
41
+ ],
42
+ ],
43
+ };
44
+ }
45
+ /** Quick setup presets */
46
+ export const presets = {
47
+ production: createPreset({
48
+ development: false,
49
+ hoistStatics: true,
50
+ delegateEvents: true,
51
+ optimizeControlFlow: true,
52
+ }),
53
+ development: createPreset({
54
+ development: true,
55
+ hoistStatics: false,
56
+ sourceMaps: true,
57
+ }),
58
+ minimal: createPreset({
59
+ detectReactivity: false,
60
+ useLitHTML: false,
61
+ hoistStatics: false,
62
+ delegateEvents: false,
63
+ optimizeControlFlow: false,
64
+ }),
65
+ };
@@ -0,0 +1,2 @@
1
+ import{declare as Ae}from"@babel/helper-plugin-utils";import{types as e,template as Re}from"@babel/core";import{types as u,traverse as Je,template as Ce}from"@babel/core";import Y from"@babel/generator";var B={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},tt={version:2,module:"@fluixi/dom",symbols:[...B.symbols,"template","cloneTemplate","walk"]};var xe={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Se(t){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(t)}function K(t){return Se(t)?t:JSON.stringify(t)}function he(t){return t.expr!==void 0?t.reactive?`() => (${t.expr})`:`(${t.expr})`:JSON.stringify(t.literal??!0)}function be(t){return t.expr!==void 0?`(${t.expr})`:JSON.stringify(t.literal??!0)}function ye(t,n,r){let i=t.filter(l=>l.kind==="spread"),o=t.filter(l=>l.kind!=="spread").map(l=>`${K(l.name)}: ${he(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 Q(t,n){return t.length===1?$(t[0],n):`[${t.map(r=>$(r,n)).join(", ")}]`}function U(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 ${K(p.name)}() { return ${be(p)}; }`);r.length>0&&a.push(`get children() { return ${Q(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":Q(t.children,n);case"component":return U(t.name,t.props,t.children,n);case"control":{let r=xe[t.control]??t.control;return n.add(r),U(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: ${ye(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 D={name:"imperative",contract:B,emit(t,n){let r=new Set;return{code:$(t,r),imports:Array.from(r)}}};var Xe=Y.default??Y;function te(t){return Xe(t,{concise:!0}).code}function ve(t,n){let r=u.cloneNode(t,!0),i=u.file(u.program([u.expressionStatement(r)])),s=!1;return Je(i,{"JSXElement|JSXFragment"(o){let a=o.node,{code:l,imports:p}=D.emit(A(a,n),{});for(let b of p)n.add(b);let g=Ce.expression(l,{placeholderPattern:!1})();o.replaceWith(g),o.skip(),s=!0}}),s?i.program.body[0].expression:t}function V(t,n){return te(ve(t,n))}var we=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),Fe=/^on[A-Z]/,je=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Pe(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:te(t),component:!0}:u.isJSXNamespacedName(t)?{tag:`${t.namespace.name}:${t.name.name}`,component:!1}:{tag:"div",component:!1}}function Ie(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 Le(t,n){let r=Ie(t.name),i=Fe.test(r),o={name:r,kind:i?"event":"attr"};i&&(o.event={name:r.slice(2).toLowerCase(),delegated:je.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=V(l,n),o.reactive=i?!1:F(l),(u.isJSXElement(l)||u.isJSXFragment(l))&&(o.jsxElement=!0),o)}return o.literal=!0,o}function Me(t,n){let r=[];for(let i of t)u.isJSXSpreadAttribute(i)?r.push({name:"",kind:"spread",expr:V(i.argument,n)}):u.isJSXAttribute(i)&&r.push(Le(i,n));return r}function Ne(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 ee(t,n){let r=[];for(let i of t)if(u.isJSXText(i)){let s=Ne(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:V(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:V(i.expression,n),reactive:!1});return r}function A(t,n=new Set){if(u.isJSXFragment(t))return{kind:"fragment",children:ee(t.children,n)};let{tag:r,component:i}=Pe(t.openingElement.name),s=Me(t.openingElement.attributes,n),o=ee(t.children,n);return i?{kind:"component",name:r,props:s,children:o}:{kind:"element",tag:r,svg:we.has(r),props:s,children:o,static:!1}}var se=new Set(["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary","Suspense"]),Oe={Show:"when",For:"each",Index:"each",Match:"when"};var oe=/^on[A-Z]/,ae=["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave"],O=Ae((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:g=!0,delegateEvents:b=!0,delegatedEvents:m=ae,optimizeControlFlow:y=!0,sourceMaps:P=!0,signalModule:J="@fluixi/dom",controlFlowModule:w="@fluixi/dom",reactiveModule:L="@fluixi/reactive/signal",autoShowTransform:Z=!1,backend:X="imperative",codegen:M="inline"}=n,Ee={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,Ee)},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:Z,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"]),E=Array.from(c.irImports),v=h=>e.importSpecifier(e.identifier(h),e.identifier(h)),I=h=>!f.scope.hasBinding(h),z=E.filter(h=>S.has(h)&&I(h)),T=E.filter(h=>!x.has(h)&&!S.has(h)&&I(h)),N=E.filter(h=>x.has(h)&&I(h));z.length>0&&d.push(e.importDeclaration(z.map(v),e.stringLiteral(L))),T.length>0&&d.push(e.importDeclaration(T.map(v),e.stringLiteral(J))),N.length>0&&d.push(e.importDeclaration(N.map(v),e.stringLiteral(w)))}else if(X==="imperative"){let S=[[!!c.needsCreateNativeElement,"createNativeElement"],[!!c.needsSpread,"spread"],[!!c.needsInsert,"insert"],[!!c.needsCreateComponent,"createComponent"],[!!c.needsMergeProps,"mergeProps"]].filter(([E,v])=>E&&!f.scope.hasBinding(v)).map(([,E])=>e.importSpecifier(e.identifier(E),e.identifier(E)));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(E=>e.importSpecifier(e.identifier(E),e.identifier(E)));d.push(e.importDeclaration(S,e.stringLiteral(w)))}}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(E=>e.stringLiteral(E))),S=e.expressionStatement(e.callExpression(e.identifier("delegateEvents"),[x]));f.node.body.unshift(S)}if(g&&c.staticElements.size>0){let x=[];c.staticElements.forEach((S,E)=>{x.push(e.variableDeclaration("const",[e.variableDeclarator(e.identifier(E),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(re(f.node,c));return}let d=f.node,x=d.openingElement;if(e.isJSXIdentifier(x.name)&&se.has(x.name.name)&&(c.controlFlowComponents.add(x.name.name),y)){let E=Qe(d,c);if(E){f.replaceWith(E);return}}if(g&&X!=="imperative"&&ge(d,c)){let E=Ke(d,c);if(E){f.replaceWith(E);return}}let S=ke(d,c,{runtime:r,pragma:s,development:a,detectReactivity:l,useLitHTML:p,autoShow:Z});f.replaceWith(S)},JSXFragment(f,c){if(c.hasJSX=!0,X==="imperative"&&M==="ir"){f.replaceWith(re(f.node,c));return}let d=_(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,E)=>{let v=S.node,I=x.quasis[E].value.raw;if(I.trim().endsWith("=")||I.match(/@[\w-]+$/))return;let T=!1,N=!1;if(e.isMemberExpression(v)){let h=v.property;e.isIdentifier(h)&&(h.name=h.name.replace("$",""),c.needsLitrxImport=!0,N=!0)}(T||N)&&S.replaceWith(e.callExpression(e.identifier("((window as any).Fluixi.litrx || litrx)"),[e.arrowFunctionExpression([],v)]))})}}}});function ke(t,n,r){let{runtime:i,pragma:s,development:o,autoShow:a=!0}=r;return i==="automatic"?k(t,n,o,a):Ve(t,n,s)}var Te=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]);function ne(t,n,r){return n.length>0?(r.needsMergeProps=!0,e.callExpression(e.identifier("mergeProps"),[...n,e.objectExpression(t)])):e.objectExpression(t)}function le(t){return t.length===1?t[0]:e.arrayExpression(t)}function $e(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(le(s))]))),ce(t,ne(m,i,o),o)}let a=t.value,l=Te.has(a),p=e.identifier("_el$"),g=[];o.needsCreateNativeElement=!0;let b=[t];if(l&&b.push(e.booleanLiteral(!0)),g.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"),ne(r,i,o))];l&&m.push(e.objectProperty(e.identifier("isSVG"),e.booleanLiteral(!0))),g.push(e.expressionStatement(e.callExpression(e.identifier("spread"),[e.objectExpression(m)])))}if(s.length>0){o.needsInsert=!0;for(let m of s){let P=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];g.push(e.expressionStatement(e.callExpression(e.identifier("insert"),P)))}}return g.push(e.returnStatement(p)),e.callExpression(e.arrowFunctionExpression([],e.blockStatement(g)),[])}function ce(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 re(t,n){let r=new Set,i=A(t,r),{code:s,imports:o}=D.emit(i,{});for(let a of o)r.add(a);for(let a of r)n.irImports.add(a);return Re.expression(s,{placeholderPattern:!1})()}function De(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 k(t,n,r,i=!0){let s=t.openingElement,o=t.children,a=pe(s.name),l=e.isJSXIdentifier(s.name)&&/^[a-z]/.test(s.name.name),p=fe(s.attributes,n,l,e.isJSXIdentifier(s.name)?s.name.name:""),g=p.props,b=p.spreads;l||(g=De(g));let m=q(o,n,i);if(n.backend==="imperative")return $e(a,l,g,b,m,n);if(m.length>0){let w=m.length===1?m[0]:e.arrayExpression(m);g.push(e.objectProperty(e.identifier("children"),w))}let y;if(b.length>0){let w=g.length>0?e.objectExpression(g):e.objectExpression([]);n.needsMergeProps=!0,y=e.callExpression(e.identifier("mergeProps"),[...b,w])}else y=e.objectExpression(g);let P=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(P),J)}function Ve(t,n,r){let i=t.openingElement,s=t.children,o=pe(i.name),a=e.isJSXIdentifier(i.name)&&/^[a-z]/.test(i.name.name),{props:l,spreads:p}=fe(i.attributes,n,a,e.isJSXIdentifier(i.name)?i.name.name:""),g=q(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,...g];return e.callExpression(e.identifier(r),m)}function _(t,n,r){let{runtime:i,pragmaFrag:s,development:o}=r,a=q(t.children,n,n.autoShow??!0);if(n.backend==="imperative")return a.length===0?e.nullLiteral():le(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))]),g=[e.identifier("Fragment"),p];return o&&g.push(e.identifier("undefined"),e.booleanLiteral(!1),e.identifier("undefined"),e.identifier("undefined")),e.callExpression(e.identifier(l),g)}else return e.callExpression(e.identifier(s),a)}function pe(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)?ue(t):e.isJSXNamespacedName(t)?e.stringLiteral(`${t.namespace.name}:${t.name.name}`):e.stringLiteral("div")}function ue(t){let n;return e.isJSXIdentifier(t.object)?n=e.identifier(t.object.name):n=ue(t.object),e.memberExpression(n,e.identifier(t.property.name))}function _e(t){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t)}function fe(t,n,r=!0,i=""){let s=[],o=[],a=Oe[i];for(let l of t)if(e.isJSXSpreadAttribute(l))o.push(l.argument);else if(e.isJSXAttribute(l)){let p=ze(l.name),g=Be(l.value,n,p,r);if(oe.test(p)){let L=p.slice(2).toLowerCase();ae.includes(L)&&n.delegatedEvents.add(L)}let b=_e(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)),P=!r&&p===a,J=e.isJSXExpressionContainer(m)&&!e.isJSXEmptyExpression(m.expression)?m.expression:null,w=!r&&!!J&&me(J,p);!r&&y||P||w?s.push(e.objectMethod("get",b,[],e.blockStatement([e.returnStatement(g)]))):s.push(e.objectProperty(b,g))}return{props:s,spreads:o}}function ze(t){return e.isJSXIdentifier(t)?t.name==="class"?"className":t.name:e.isJSXNamespacedName(t)?`${t.namespace.name}:${t.name.name}`:"unknown"}function Be(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&&me(s,r)?e.arrowFunctionExpression([],s):s}return e.isJSXElement(t)?k(t,n,!1,n.autoShow??!0):e.isJSXFragment(t)?_(t,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1}):e.booleanLiteral(!0)}function me(t,n){return oe.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 We(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,r=!0){let i=[];for(let s of t)if(e.isJSXText(s)){let o=We(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=qe(o,n)??Ge(o,n);if(a){i.push(a);continue}}else{let a=He(o,n);if(a){i.push(a);continue}}Ue(o)?i.push(e.arrowFunctionExpression([],o)):i.push(o)}}else e.isJSXElement(s)?i.push(k(s,n,!1,n.autoShow??!0)):e.isJSXFragment(s)?i.push(_(s,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})):e.isJSXSpreadChild(s)&&i.push(s.expression);return i}function qe(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=G(r.alternate,n);return R(j(r.test),i,s,n,!0)}}return null}function Ge(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=G(t.alternate,n);return R(j(t.test),r,i,n)}}return null}function He(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 W(r.consequent)||W(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 W(r.right)?null:(n.needsCreateMemo=!0,e.callExpression(e.identifier("createMemo"),[e.arrowFunctionExpression([],a)]))}return null}function G(t,n){if(Ze(t))return null;let r=C(t);if(r)return de(r,n);if(e.isConditionalExpression(t)){let i=t,s=C(i.consequent);if(s){let o=G(i.alternate,n);return R(j(i.test),s,o,n)}}return t}function ie(t){return e.isJSXElement(t)||e.isJSXFragment(t)}function W(t){let n=C(t);if(!n||!e.isJSXElement(n))return!1;let r=n.openingElement.name;return e.isJSXIdentifier(r)&&se.has(r.name)}function C(t){return ie(t)?t:e.isArrowFunctionExpression(t)&&t.params.length===0&&!t.async&&ie(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 Ze(t){return e.isNullLiteral(t)||e.isIdentifier(t)&&t.name==="undefined"||e.isBooleanLiteral(t)&&t.value===!1}function de(t,n){return e.isJSXElement(t)?k(t,n,!1,n.autoShow??!0):_(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=de(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)),ce(e.identifier("Show"),e.objectExpression(a),i)}function Ue(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 ge(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)&&!ge(s,n)||e.isJSXExpressionContainer(s))return!1;return!0}function Ke(t,n){let r=`_$static${n.staticCounter++}`,i=k(t,n,!1);return n.staticElements.set(r,i),e.identifier(r)}function Qe(t,n){let r=t.openingElement.name.name;return r==="Show"?Ye(t,n):r==="For"?et(t,n):null}function Ye(t,n){return null}function et(t,n){return null}var Et=O;function xt(t){return[O,t]}function H(t={}){return{plugins:[[O,{runtime:"automatic",importSource:"@fluixi/jsx",development:!1,detectReactivity:!0,useLitHTML:!0,hoistStatics:!0,delegateEvents:!0,optimizeControlFlow:!0,sourceMaps:!0,...t}]]}}var St={production:H({development:!1,hoistStatics:!0,delegateEvents:!0,optimizeControlFlow:!0}),development:H({development:!0,hoistStatics:!1,sourceMaps:!0}),minimal:H({detectReactivity:!1,useLitHTML:!1,hoistStatics:!1,delegateEvents:!1,optimizeControlFlow:!1})};export{Et as babelPluginReactiveJSX,xt as createPlugin,H as createPreset,O as default,St as presets};
@@ -0,0 +1,2 @@
1
+ "use strict";var Se=Object.create;var $=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,Je=Object.prototype.hasOwnProperty;var Ce=(e,n)=>{for(var r in n)$(e,r,{get:n[r],enumerable:!0})},U=(e,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of be(n))!Je.call(e,s)&&s!==r&&$(e,s,{get:()=>n[s],enumerable:!(i=he(n,s))||i.enumerable});return e};var Xe=(e,n,r)=>(r=e!=null?Se(ye(e)):{},U(n||!e||!e.__esModule?$(r,"default",{value:e,enumerable:!0}):r,e)),we=e=>U($({},"__esModule",{value:!0}),e);var at={};Ce(at,{default:()=>_e});module.exports=we(at);var se=require("@babel/helper-plugin-utils"),t=require("@babel/core");var p=require("@babel/core"),W=Xe(require("@babel/generator"),1);var B={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},ct={version:2,module:"@fluixi/dom",symbols:[...B.symbols,"template","cloneTemplate","walk"]};var ve={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Fe(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function Q(e){return Fe(e)?e:JSON.stringify(e)}function je(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function Ie(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function Pe(e,n,r){let i=e.filter(l=>l.kind==="spread"),o=e.filter(l=>l.kind!=="spread").map(l=>`${Q(l.name)}: ${je(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 Y(e,n){return e.length===1?T(e[0],n):`[${e.map(r=>T(r,n)).join(", ")}]`}function K(e,n,r,i){i.add("createMemo"),i.add("createComponent");let s=n.filter(u=>u.kind==="spread"),a=n.filter(u=>u.kind!=="spread").map(u=>`get ${Q(u.name)}() { return ${Ie(u)}; }`);r.length>0&&a.push(`get children() { return ${Y(r,i)}; }`);let l=`{ ${a.join(", ")} }`;return s.length>0&&(i.add("mergeProps"),l=`mergeProps(${s.map(u=>u.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${e}, ${l}))`}function T(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":Y(e.children,n);case"component":return K(e.name,e.props,e.children,n);case"control":{let r=ve[e.control]??e.control;return n.add(r),K(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: ${Pe(e.props,null,n)}${a} });`)}for(let a of e.children){n.add("insert");let l=T(a,n),u=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";s.push(u?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return s.push(`return ${i};`),`(() => { ${s.join(" ")} })()`}}}var D={name:"imperative",contract:B,emit(e,n){let r=new Set;return{code:T(e,r),imports:Array.from(r)}}};var Le=W.default.default??W.default;function te(e){return Le(e,{concise:!0}).code}function Me(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:u}=D.emit(A(a,n),{});for(let b of u)n.add(b);let E=p.template.expression(l,{placeholderPattern:!1})();o.replaceWith(E),o.skip(),s=!0}}),s?i.program.body[0].expression:e}function V(e,n){return te(Me(e,n))}var Ne=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),Ae=/^on[A-Z]/,Re=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Oe(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:te(e),component:!0}:p.types.isJSXNamespacedName(e)?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function ke(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 $e(e,n){let r=ke(e.name),i=Ae.test(r),o={name:r,kind:i?"event":"attr"};i&&(o.event={name:r.slice(2).toLowerCase(),delegated:Re.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=V(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 Te(e,n){let r=[];for(let i of e)p.types.isJSXSpreadAttribute(i)?r.push({name:"",kind:"spread",expr:V(i.argument,n)}):p.types.isJSXAttribute(i)&&r.push($e(i,n));return r}function De(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 ee(e,n){let r=[];for(let i of e)if(p.types.isJSXText(i)){let s=De(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:V(s,n),reactive:F(s)})}}else p.types.isJSXElement(i)||p.types.isJSXFragment(i)?r.push(A(i,n)):p.types.isJSXSpreadChild(i)&&r.push({kind:"expr",code:V(i.expression,n),reactive:!1});return r}function A(e,n=new Set){if(p.types.isJSXFragment(e))return{kind:"fragment",children:ee(e.children,n)};let{tag:r,component:i}=Oe(e.openingElement.name),s=Te(e.openingElement.attributes,n),o=ee(e.children,n);return i?{kind:"component",name:r,props:s,children:o}:{kind:"element",tag:r,svg:Ne.has(r),props:s,children:o,static:!1}}var oe=new Set(["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary","Suspense"]),Ve={Show:"when",For:"each",Index:"each",Match:"when"};var ae=/^on[A-Z]/,le=["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave"],_e=(0,se.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:u=!0,hoistStatics:E=!0,delegateEvents:b=!0,delegatedEvents:m=le,optimizeControlFlow:y=!0,sourceMaps:I=!0,signalModule:J="@fluixi/dom",controlFlowModule:v="@fluixi/dom",reactiveModule:L="@fluixi/reactive/signal",autoShowTransform:H=!1,backend:X="imperative",codegen:M="inline"}=n,xe={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,xe)},visitor:{ImportDeclaration(f,c){f.node.source.value==="@fluixi/core/rx"&&(f.node.source=t.types.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:H,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(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("signal"),t.types.identifier("signal"))],t.types.stringLiteral(J))),c.needsLitrxImport&&!f.scope.hasBinding("litrx")&&d.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("litrx"),t.types.identifier("litrx"))],t.types.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=>t.types.importSpecifier(t.types.identifier(h),t.types.identifier(h)),P=h=>!f.scope.hasBinding(h),z=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));z.length>0&&d.push(t.types.importDeclaration(z.map(w),t.types.stringLiteral(L))),k.length>0&&d.push(t.types.importDeclaration(k.map(w),t.types.stringLiteral(J))),N.length>0&&d.push(t.types.importDeclaration(N.map(w),t.types.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])=>t.types.importSpecifier(t.types.identifier(g),t.types.identifier(g)));S.length>0&&d.push(t.types.importDeclaration(S,t.types.stringLiteral(J)))}else if(r==="automatic"){let x=[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&&x.push(t.types.importSpecifier(t.types.identifier("jsxDEV"),t.types.identifier("jsxDEV"))),c.needsMergeProps&&x.push(t.types.importSpecifier(t.types.identifier("mergeProps"),t.types.identifier("mergeProps"))),d.push(t.types.importDeclaration(x,t.types.stringLiteral(i)))}if(c.needsCreateMemo&&!f.scope.hasBinding("createMemo")&&d.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("createMemo"),t.types.identifier("createMemo"))],t.types.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=>t.types.importSpecifier(t.types.identifier(g),t.types.identifier(g)));d.push(t.types.importDeclaration(S,t.types.stringLiteral(v)))}}if(b&&c.delegatedEvents.size>0){d.push(t.types.importDeclaration([t.types.importSpecifier(t.types.identifier("delegateEvents"),t.types.identifier("delegateEvents"))],t.types.stringLiteral(X==="imperative"?J:"@fluixi/jsx")));let x=t.types.arrayExpression(Array.from(c.delegatedEvents).map(g=>t.types.stringLiteral(g))),S=t.types.expressionStatement(t.types.callExpression(t.types.identifier("delegateEvents"),[x]));f.node.body.unshift(S)}if(E&&c.staticElements.size>0){let x=[];c.staticElements.forEach((S,g)=>{x.push(t.types.variableDeclaration("const",[t.types.variableDeclarator(t.types.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(re(f.node,c));return}let d=f.node,x=d.openingElement;if(t.types.isJSXIdentifier(x.name)&&oe.has(x.name.name)&&(c.controlFlowComponents.add(x.name.name),y)){let g=it(d,c);if(g){f.replaceWith(g);return}}if(E&&X!=="imperative"&&ge(d,c)){let g=rt(d,c);if(g){f.replaceWith(g);return}}let S=ze(d,c,{runtime:r,pragma:s,development:a,detectReactivity:l,useLitHTML:u,autoShow:H});f.replaceWith(S)},JSXFragment(f,c){if(c.hasJSX=!0,X==="imperative"&&M==="ir"){f.replaceWith(re(f.node,c));return}let d=_(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,t.types.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(t.types.isMemberExpression(w)){let h=w.property;t.types.isIdentifier(h)&&(h.name=h.name.replace("$",""),c.needsLitrxImport=!0,N=!0)}(k||N)&&S.replaceWith(t.types.callExpression(t.types.identifier("((window as any).Fluixi.litrx || litrx)"),[t.types.arrowFunctionExpression([],w)]))})}}}});function ze(e,n,r){let{runtime:i,pragma:s,development:o,autoShow:a=!0}=r;return i==="automatic"?O(e,n,o,a):Ge(e,n,s)}var Be=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]);function ne(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 ce(e){return e.length===1?e[0]:t.types.arrayExpression(e)}function We(e,n,r,i,s,o){if(!n){let m=[...r];return s.length>0&&m.push(t.types.objectMethod("get",t.types.identifier("children"),[],t.types.blockStatement([t.types.returnStatement(ce(s))]))),pe(e,ne(m,i,o),o)}let a=e.value,l=Be.has(a),u=t.types.identifier("_el$"),E=[];o.needsCreateNativeElement=!0;let b=[e];if(l&&b.push(t.types.booleanLiteral(!0)),E.push(t.types.variableDeclaration("const",[t.types.variableDeclarator(u,t.types.callExpression(t.types.identifier("createNativeElement"),b))])),r.length>0||i.length>0){o.needsSpread=!0;let m=[t.types.objectProperty(t.types.identifier("element"),u),t.types.objectProperty(t.types.identifier("props"),ne(r,i,o))];l&&m.push(t.types.objectProperty(t.types.identifier("isSVG"),t.types.booleanLiteral(!0))),E.push(t.types.expressionStatement(t.types.callExpression(t.types.identifier("spread"),[t.types.objectExpression(m)])))}if(s.length>0){o.needsInsert=!0;for(let m of s){let I=t.types.isArrowFunctionExpression(m)||t.types.isFunctionExpression(m)||t.types.isCallExpression(m)&&t.types.isIdentifier(m.callee)&&m.callee.name==="createMemo"?[t.types.cloneNode(u),m,t.types.nullLiteral()]:[t.types.cloneNode(u),m];E.push(t.types.expressionStatement(t.types.callExpression(t.types.identifier("insert"),I)))}}return E.push(t.types.returnStatement(u)),t.types.callExpression(t.types.arrowFunctionExpression([],t.types.blockStatement(E)),[])}function pe(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 re(e,n){let r=new Set,i=A(e,r),{code:s,imports:o}=D.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 qe(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 O(e,n,r,i=!0){let s=e.openingElement,o=e.children,a=ue(s.name),l=t.types.isJSXIdentifier(s.name)&&/^[a-z]/.test(s.name.name),u=me(s.attributes,n,l,t.types.isJSXIdentifier(s.name)?s.name.name:""),E=u.props,b=u.spreads;l||(E=qe(E));let m=G(o,n,i);if(n.backend==="imperative")return We(a,l,E,b,m,n);if(m.length>0){let v=m.length===1?m[0]:t.types.arrayExpression(m);E.push(t.types.objectProperty(t.types.identifier("children"),v))}let y;if(b.length>0){let v=E.length>0?t.types.objectExpression(E):t.types.objectExpression([]);n.needsMergeProps=!0,y=t.types.callExpression(t.types.identifier("mergeProps"),[...b,v])}else y=t.types.objectExpression(E);let I=r?"jsxDEV":m.length>1?"jsxs":"jsx",J=[a,y];return r&&J.push(t.types.identifier("undefined"),t.types.booleanLiteral(!1),t.types.identifier("undefined"),t.types.identifier("undefined")),t.types.callExpression(t.types.identifier(I),J)}function Ge(e,n,r){let i=e.openingElement,s=e.children,o=ue(i.name),a=t.types.isJSXIdentifier(i.name)&&/^[a-z]/.test(i.name.name),{props:l,spreads:u}=me(i.attributes,n,a,t.types.isJSXIdentifier(i.name)?i.name.name:""),E=G(s,n,n.autoShow??!0),b;if(u.length>0){let y=l.length>0?t.types.objectExpression(l):t.types.objectExpression([]);n.needsMergeProps=!0,b=t.types.callExpression(t.types.identifier("mergeProps"),[...u,y])}else b=l.length>0?t.types.objectExpression(l):t.types.nullLiteral();let m=[o,b,...E];return t.types.callExpression(t.types.identifier(r),m)}function _(e,n,r){let{runtime:i,pragmaFrag:s,development:o}=r,a=G(e.children,n,n.autoShow??!0);if(n.backend==="imperative")return a.length===0?t.types.nullLiteral():ce(a);if(i==="automatic"){let l=o?"jsxDEV":a.length>1?"jsxs":"jsx",u=t.types.objectExpression([t.types.objectProperty(t.types.identifier("children"),a.length===1?a[0]:t.types.arrayExpression(a))]),E=[t.types.identifier("Fragment"),u];return o&&E.push(t.types.identifier("undefined"),t.types.booleanLiteral(!1),t.types.identifier("undefined"),t.types.identifier("undefined")),t.types.callExpression(t.types.identifier(l),E)}else return t.types.callExpression(t.types.identifier(s),a)}function ue(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)?fe(e):t.types.isJSXNamespacedName(e)?t.types.stringLiteral(`${e.namespace.name}:${e.name.name}`):t.types.stringLiteral("div")}function fe(e){let n;return t.types.isJSXIdentifier(e.object)?n=t.types.identifier(e.object.name):n=fe(e.object),t.types.memberExpression(n,t.types.identifier(e.property.name))}function Ze(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)}function me(e,n,r=!0,i=""){let s=[],o=[],a=Ve[i];for(let l of e)if(t.types.isJSXSpreadAttribute(l))o.push(l.argument);else if(t.types.isJSXAttribute(l)){let u=He(l.name),E=Ue(l.value,n,u,r);if(ae.test(u)){let L=u.slice(2).toLowerCase();le.includes(L)&&n.delegatedEvents.add(L)}let b=Ze(u)?t.types.identifier(u):t.types.stringLiteral(u),m=l.value,y=t.types.isJSXElement(m)||t.types.isJSXFragment(m)||t.types.isJSXExpressionContainer(m)&&(t.types.isJSXElement(m.expression)||t.types.isJSXFragment(m.expression)),I=!r&&u===a,J=t.types.isJSXExpressionContainer(m)&&!t.types.isJSXEmptyExpression(m.expression)?m.expression:null,v=!r&&!!J&&de(J,u);!r&&y||I||v?s.push(t.types.objectMethod("get",b,[],t.types.blockStatement([t.types.returnStatement(E)]))):s.push(t.types.objectProperty(b,E))}return{props:s,spreads:o}}function He(e){return t.types.isJSXIdentifier(e)?e.name==="class"?"className":e.name:t.types.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:"unknown"}function Ue(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)?O(e,n,!1,n.autoShow??!0):t.types.isJSXFragment(e)?_(e,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1}):t.types.booleanLiteral(!0)}function de(e,n){return ae.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 Ke(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 G(e,n,r=!0){let i=[];for(let s of e)if(t.types.isJSXText(s)){let o=Ke(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=Qe(o,n)??Ye(o,n);if(a){i.push(a);continue}}else{let a=et(o,n);if(a){i.push(a);continue}}nt(o)?i.push(t.types.arrowFunctionExpression([],o)):i.push(o)}}else t.types.isJSXElement(s)?i.push(O(s,n,!1,n.autoShow??!0)):t.types.isJSXFragment(s)?i.push(_(s,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})):t.types.isJSXSpreadChild(s)&&i.push(s.expression);return i}function Qe(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 R(j(r.left),i,null,n)}if(t.types.isConditionalExpression(r)){let i=C(r.consequent);if(i){let s=Z(r.alternate,n);return R(j(r.test),i,s,n,!0)}}return null}function Ye(e,n){if(t.types.isLogicalExpression(e)&&e.operator==="&&"){let r=C(e.right);if(r)return R(j(e.left),r,null,n)}if(t.types.isConditionalExpression(e)){let r=C(e.consequent);if(r){let i=Z(e.alternate,n);return R(j(e.test),r,i,n)}}return null}function et(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,u=t.types.conditionalExpression(i,o,l);return q(r.consequent)||q(r.alternate)?null:(n.needsCreateMemo=!0,t.types.callExpression(t.types.identifier("createMemo"),[t.types.arrowFunctionExpression([],u)]))}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 q(r.right)?null:(n.needsCreateMemo=!0,t.types.callExpression(t.types.identifier("createMemo"),[t.types.arrowFunctionExpression([],a)]))}return null}function Z(e,n){if(tt(e))return null;let r=C(e);if(r)return Ee(r,n);if(t.types.isConditionalExpression(e)){let i=e,s=C(i.consequent);if(s){let o=Z(i.alternate,n);return R(j(i.test),s,o,n)}}return e}function ie(e){return t.types.isJSXElement(e)||t.types.isJSXFragment(e)}function q(e){let n=C(e);if(!n||!t.types.isJSXElement(n))return!1;let r=n.openingElement.name;return t.types.isJSXIdentifier(r)&&oe.has(r.name)}function C(e){return ie(e)?e:t.types.isArrowFunctionExpression(e)&&e.params.length===0&&!e.async&&ie(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 tt(e){return t.types.isNullLiteral(e)||t.types.isIdentifier(e)&&e.name==="undefined"||t.types.isBooleanLiteral(e)&&e.value===!1}function Ee(e,n){return t.types.isJSXElement(e)?O(e,n,!1,n.autoShow??!0):_(e,n,{runtime:"automatic",pragmaFrag:"Fragment",development:!1})}function R(e,n,r,i,s=!1){i.controlFlowComponents.add("Show"),i.needsControlFlowImport=!0;let o=Ee(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)),pe(t.types.identifier("Show"),t.types.objectExpression(a),i)}function nt(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 ge(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)&&!ge(s,n)||t.types.isJSXExpressionContainer(s))return!1;return!0}function rt(e,n){let r=`_$static${n.staticCounter++}`,i=O(e,n,!1);return n.staticElements.set(r,i),t.types.identifier(r)}function it(e,n){let r=e.openingElement.name.name;return r==="Show"?st(e,n):r==="For"?ot(e,n):null}function st(e,n){return null}function ot(e,n){return null}