@fluixi/compiler 1.0.0-alpha.73 → 1.0.0-alpha.74

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 (109) hide show
  1. package/README.md +41 -16
  2. package/dist/analyze/expr-shape.cjs +1 -0
  3. package/dist/analyze/expr-shape.d.ts +15 -0
  4. package/dist/analyze/expr-shape.d.ts.map +1 -0
  5. package/dist/analyze/expr-shape.js +37 -0
  6. package/dist/analyze/expr-shape.mjs +1 -0
  7. package/dist/analyze/reactive-expr.cjs +1 -0
  8. package/dist/analyze/reactive-expr.d.ts +39 -0
  9. package/dist/analyze/reactive-expr.d.ts.map +1 -0
  10. package/dist/analyze/reactive-expr.js +31 -0
  11. package/dist/analyze/reactive-expr.mjs +1 -0
  12. package/dist/babel-GXO3KAVI.mjs +1 -0
  13. package/dist/chunk-3SAEGOMQ.mjs +1 -0
  14. package/dist/chunk-E2PW2OZU.mjs +1 -0
  15. package/dist/chunk-IBRM4W7I.mjs +10 -0
  16. package/dist/chunk-OHHZCYIQ.mjs +1 -0
  17. package/dist/chunk-TIE4XNAM.mjs +1 -0
  18. package/dist/frontend/babel/build-ir-lit.cjs +1 -1
  19. package/dist/frontend/babel/build-ir-lit.d.ts +1 -0
  20. package/dist/frontend/babel/build-ir-lit.d.ts.map +1 -1
  21. package/dist/frontend/babel/build-ir-lit.mjs +1 -1
  22. package/dist/frontend/babel/build-ir.cjs +1 -1
  23. package/dist/frontend/babel/build-ir.d.ts +13 -11
  24. package/dist/frontend/babel/build-ir.d.ts.map +1 -1
  25. package/dist/frontend/babel/build-ir.js +27 -217
  26. package/dist/frontend/babel/build-ir.mjs +1 -1
  27. package/dist/frontend/babel/index.cjs +1 -2
  28. package/dist/frontend/babel/index.mjs +1 -2
  29. package/dist/frontend/babel/lower-template.cjs +1 -1
  30. package/dist/frontend/babel/lower-template.d.ts +12 -9
  31. package/dist/frontend/babel/lower-template.d.ts.map +1 -1
  32. package/dist/frontend/babel/lower-template.js +33 -445
  33. package/dist/frontend/babel/lower-template.mjs +1 -1
  34. package/dist/frontend/babel/plugin.cjs +1 -2
  35. package/dist/frontend/babel/plugin.d.ts +24 -85
  36. package/dist/frontend/babel/plugin.d.ts.map +1 -1
  37. package/dist/frontend/babel/plugin.js +52 -1285
  38. package/dist/frontend/babel/plugin.mjs +1 -2
  39. package/dist/frontend/babel/server-functions.cjs +1 -1
  40. package/dist/frontend/babel/server-functions.d.ts.map +1 -1
  41. package/dist/frontend/babel/server-functions.js +2 -9
  42. package/dist/frontend/babel/server-functions.mjs +1 -1
  43. package/dist/index.cjs +8 -8
  44. package/dist/index.d.ts +4 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +8 -0
  47. package/dist/index.mjs +9 -9
  48. package/dist/integrations.cjs +15 -19
  49. package/dist/integrations.d.ts +39 -151
  50. package/dist/integrations.d.ts.map +1 -1
  51. package/dist/integrations.js +79 -491
  52. package/dist/integrations.mjs +11 -17
  53. package/dist/lower/compile-template.cjs +1 -0
  54. package/dist/lower/compile-template.d.ts +57 -0
  55. package/dist/lower/compile-template.d.ts.map +1 -0
  56. package/dist/lower/compile-template.js +72 -0
  57. package/dist/lower/compile-template.mjs +1 -0
  58. package/dist/lower/jsx.cjs +1 -0
  59. package/dist/lower/jsx.d.ts +24 -0
  60. package/dist/lower/jsx.d.ts.map +1 -0
  61. package/dist/lower/jsx.js +193 -0
  62. package/dist/lower/jsx.mjs +1 -0
  63. package/dist/lower/template.cjs +1 -0
  64. package/dist/lower/template.d.ts +41 -0
  65. package/dist/lower/template.d.ts.map +1 -0
  66. package/dist/lower/template.js +445 -0
  67. package/dist/lower/template.mjs +1 -0
  68. package/dist/lower/text.cjs +1 -0
  69. package/dist/lower/text.d.ts +11 -0
  70. package/dist/lower/text.d.ts.map +1 -0
  71. package/dist/lower/text.js +31 -0
  72. package/dist/lower/text.mjs +1 -0
  73. package/dist/options.cjs +1 -1
  74. package/dist/options.d.ts +0 -2
  75. package/dist/options.d.ts.map +1 -1
  76. package/dist/options.js +0 -1
  77. package/dist/options.mjs +1 -1
  78. package/dist/server-fns-6QM243HC.mjs +2 -0
  79. package/dist/server-functions-E3LKCZ4R.mjs +1 -0
  80. package/dist/transform/bindings.cjs +1 -0
  81. package/dist/transform/bindings.d.ts +17 -0
  82. package/dist/transform/bindings.d.ts.map +1 -0
  83. package/dist/transform/bindings.js +69 -0
  84. package/dist/transform/bindings.mjs +1 -0
  85. package/dist/transform/index.cjs +3 -0
  86. package/dist/transform/index.d.ts +12 -0
  87. package/dist/transform/index.d.ts.map +1 -0
  88. package/dist/transform/index.js +10 -0
  89. package/dist/transform/index.mjs +12 -0
  90. package/dist/transform/server-fn-id.cjs +1 -0
  91. package/dist/transform/server-fn-id.d.ts +10 -0
  92. package/dist/transform/server-fn-id.d.ts.map +1 -0
  93. package/dist/transform/server-fn-id.js +18 -0
  94. package/dist/transform/server-fn-id.mjs +1 -0
  95. package/dist/transform/server-fns.cjs +2 -0
  96. package/dist/transform/server-fns.d.ts +13 -0
  97. package/dist/transform/server-fns.d.ts.map +1 -0
  98. package/dist/transform/server-fns.js +94 -0
  99. package/dist/transform/server-fns.mjs +11 -0
  100. package/dist/transform/templates.cjs +3 -0
  101. package/dist/transform/templates.d.ts +26 -0
  102. package/dist/transform/templates.d.ts.map +1 -0
  103. package/dist/transform/templates.js +347 -0
  104. package/dist/transform/templates.mjs +12 -0
  105. package/dist/transform-PJX2GNSV.mjs +3 -0
  106. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  107. package/package.json +29 -8
  108. package/dist/babel-E7EQLX36.mjs +0 -2
  109. package/dist/chunk-EF6V4GTD.mjs +0 -1
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Whitespace handling for template text runs.
3
+ *
4
+ * JSX and `` html`...` `` collapse a text run the same way — the rule came from
5
+ * JSX and the template syntax adopted it so an author moving between the two
6
+ * gets the same output. It is pure string work with no parser in it, so it lives
7
+ * here rather than in a front-end, where both can reach it and neither owns it.
8
+ */
9
+ /** Canonical JSX text cleaning — kept identical to plugin.ts cleanTemplateText. */
10
+ export function cleanTemplateText(value) {
11
+ const lines = value.split(/\r\n|\n|\r/);
12
+ let lastNonEmpty = 0;
13
+ for (let i = 0; i < lines.length; i++) {
14
+ if (/[^ \t]/.test(lines[i]))
15
+ lastNonEmpty = i;
16
+ }
17
+ let out = '';
18
+ for (let i = 0; i < lines.length; i++) {
19
+ let line = lines[i].replace(/\t/g, ' ');
20
+ if (i !== 0)
21
+ line = line.replace(/^ +/, '');
22
+ if (i !== lines.length - 1)
23
+ line = line.replace(/ +$/, '');
24
+ if (!line)
25
+ continue;
26
+ if (i !== lastNonEmpty)
27
+ line += ' ';
28
+ out += line;
29
+ }
30
+ return out;
31
+ }
@@ -0,0 +1 @@
1
+ function f(r){let l=r.split(/\r\n|\n|\r/),n=0;for(let t=0;t<l.length;t++)/[^ \t]/.test(l[t])&&(n=t);let i="";for(let t=0;t<l.length;t++){let e=l[t].replace(/\t/g," ");t!==0&&(e=e.replace(/^ +/,"")),t!==l.length-1&&(e=e.replace(/ +$/,"")),e&&(t!==n&&(e+=" "),i+=e)}return i}export{f as cleanTemplateText};
package/dist/options.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var m=(o,e)=>{for(var t in e)l(o,t,{get:e[t],enumerable:!0})},d=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of s(e))!p.call(o,a)&&a!==t&&l(o,a,{get:()=>e[a],enumerable:!(r=n(e,a))||r.enumerable});return o};var i=o=>d(l({},"__esModule",{value:!0}),o);var b={};m(b,{defaultOptions:()=>v});module.exports=i(b);var v={backend:"imperative",generate:"dom",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};
1
+ "use strict";var t=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var m=(o,e)=>{for(var a in e)t(o,a,{get:e[a],enumerable:!0})},i=(o,e,a,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of p(e))!s.call(o,l)&&l!==a&&t(o,l,{get:()=>e[l],enumerable:!(n=r(e,l))||n.enumerable});return o};var d=o=>i(t({},"__esModule",{value:!0}),o);var b={};m(b,{defaultOptions:()=>v});module.exports=d(b);var v={backend:"imperative",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};
package/dist/options.d.ts CHANGED
@@ -24,8 +24,6 @@ export interface CompilerOptions {
24
24
  partialTemplates?: boolean;
25
25
  /** which codegen backend to use */
26
26
  backend?: 'imperative' | 'template-clone';
27
- /** output target */
28
- generate?: 'dom' | 'ssr' | 'hydrate';
29
27
  /** runtime module emitted symbols are imported from */
30
28
  moduleName?: string;
31
29
  delegateEvents?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAE7E;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B,mCAAmC;IACnC,OAAO,CAAC,EAAE,YAAY,GAAG,gBAAgB,CAAC;IAC1C,oBAAoB;IACpB,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;IACrC,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC5C;AAED,eAAO,MAAM,cAAc,EAAE,eAQ5B,CAAC"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAE7E;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B,mCAAmC;IACnC,OAAO,CAAC,EAAE,YAAY,GAAG,gBAAgB,CAAC;IAC1C,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC5C;AAED,eAAO,MAAM,cAAc,EAAE,eAO5B,CAAC"}
package/dist/options.js CHANGED
@@ -1,6 +1,5 @@
1
1
  export const defaultOptions = {
2
2
  backend: 'imperative',
3
- generate: 'dom',
4
3
  moduleName: '@fluixi/dom',
5
4
  delegateEvents: true,
6
5
  hydratable: false,
package/dist/options.mjs CHANGED
@@ -1 +1 @@
1
- var e={backend:"imperative",generate:"dom",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};export{e as defaultOptions};
1
+ var e={backend:"imperative",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};export{e as defaultOptions};
@@ -0,0 +1,2 @@
1
+ import{a as d}from"./chunk-IBRM4W7I.mjs";import{a as p}from"./chunk-OHHZCYIQ.mjs";import"./chunk-3SAEGOMQ.mjs";import{parse as g}from"@babel/parser";var y="@fluixi/start/server-fn",v=new Set(["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression"]);function N(e){if(!v.has(e.type))return null;let r=e.body;if(!r||r.type!=="BlockStatement")return null;for(let t of r.directives??[])if(t.value?.value==="use server")return t;return null}function u(e,r){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let t of e)u(t,r);return}if(typeof e.type=="string"){let t=N(e);if(t){r.push({fn:e,directive:t});return}}for(let t of Object.keys(e))t==="loc"||t==="leadingComments"||t==="trailingComments"||u(e[t],r)}}function b(e,r){if(!e.includes("use server"))return null;let t=g(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),s=[];if(u(t.program,s),s.length===0)return null;let o=r.ssr?"$$registerServerFn":"$$createServerReference",n=new d(e);return s.forEach(({fn:i,directive:f},m)=>{let a=p(r.filename,r.root,m),c=i.type==="FunctionDeclaration";if(!r.ssr){let l=`${o}(${JSON.stringify(a)})`;n.overwrite(i.start,i.end,c?`const ${i.id.name} = ${l};`:l);return}n.remove(f.start,f.end),n.appendLeft(i.start,c?`const ${i.id.name} = ${o}(${JSON.stringify(a)}, `:`${o}(${JSON.stringify(a)}, `),n.appendRight(i.end,c?");":")")}),n.prepend(`import { ${o} } from ${JSON.stringify(r.runtimeModule??y)};
2
+ `),{code:n.toString(),map:n.generateMap({source:r.filename,includeContent:!0,hires:!0})}}export{b as transformServerFns};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-OHHZCYIQ.mjs";import"./chunk-3SAEGOMQ.mjs";import{transformSync as u}from"@babel/core";var d="@fluixi/start/server-fn";function p({types:e}){return{name:"fluixi-server-functions",visitor:{Program:{enter(r,n){n.fxIndex=0,n.fxUsed=null},exit(r,n){n.fxUsed&&r.unshiftContainer("body",e.importDeclaration([e.importSpecifier(e.identifier(n.fxUsed),e.identifier(n.fxUsed))],e.stringLiteral(n.opts.runtimeModule||d)))}},"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression":(r,n)=>{let i=r.node.body;if(!e.isBlockStatement(i))return;let o=(i.directives||[]).findIndex(f=>f.value.value==="use server");if(o<0)return;i.directives.splice(o,1);let l=a(n.opts.filename||n.filename||"unknown",n.opts.root,n.fxIndex++),c=!!n.opts.ssr,s=c?"$$registerServerFn":"$$createServerReference";n.fxUsed=s;let t=c?e.callExpression(e.identifier(s),[e.stringLiteral(l),r.isFunctionDeclaration()?e.functionExpression(null,r.node.params,i,r.node.generator,r.node.async):r.node]):e.callExpression(e.identifier(s),[e.stringLiteral(l)]);r.isFunctionDeclaration()?r.replaceWith(e.variableDeclaration("const",[e.variableDeclarator(r.node.id,t)])):r.replaceWith(t),r.skip()}}}}function y(e,r){if(!e.includes("use server"))return null;let n=u(e,{filename:r.filename,configFile:!1,babelrc:!1,sourceMaps:!0,parserOpts:{plugins:["typescript","jsx"]},plugins:[[p,r]]});return n?.code?{code:n.code,map:n.map}:null}export{y as transformServerFunctions};
@@ -0,0 +1 @@
1
+ "use strict";var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var a in t)s(e,a,{get:t[a],enumerable:!0})},N=(e,t,a,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of l(t))!d.call(e,n)&&n!==a&&s(e,n,{get:()=>t[n],enumerable:!(i=c(t,n))||i.enumerable});return e};var u=e=>N(s({},"__esModule",{value:!0}),e);var p={};f(p,{moduleBindings:()=>m});module.exports=u(p);function r(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let a of e.properties)a.type==="RestElement"?r(a.argument,t):r(a.value,t);return;case"ArrayPattern":for(let a of e.elements)r(a,t);return;case"AssignmentPattern":r(e.left,t);return;case"RestElement":r(e.argument,t);return}}function o(e,t){switch(e.type){case"ImportDeclaration":for(let a of e.specifiers)r(a.local,t);return;case"VariableDeclaration":for(let a of e.declarations)r(a.id,t);return;case"FunctionDeclaration":case"ClassDeclaration":r(e.id,t);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&o(e.declaration,t);return}}function m(e){let t=new Set;for(let a of e.body)o(a,t);return t}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Names bound at module scope.
3
+ *
4
+ * Injected imports are skipped when the name already exists, so a file with its
5
+ * own `Show` keeps it. Only module scope matters: a `const insert = …` inside a
6
+ * function shadows our import there but cannot collide with it, which is the same
7
+ * answer `path.scope.hasBinding` gives on the Program path.
8
+ *
9
+ * Missing a binding emits a duplicate declaration — a syntax error. Reporting one
10
+ * that isn't there drops an import the code needs. Both are loud, neither is
11
+ * subtle, and the corpus in bindings.spec.ts covers the patterns that bind.
12
+ */
13
+ /** Collect the names bound at the top level of a parsed module. */
14
+ export declare function moduleBindings(program: {
15
+ body: unknown[];
16
+ }): Set<string>;
17
+ //# sourceMappingURL=bindings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../../src/transform/bindings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoDH,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAIxE"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Names bound at module scope.
3
+ *
4
+ * Injected imports are skipped when the name already exists, so a file with its
5
+ * own `Show` keeps it. Only module scope matters: a `const insert = …` inside a
6
+ * function shadows our import there but cannot collide with it, which is the same
7
+ * answer `path.scope.hasBinding` gives on the Program path.
8
+ *
9
+ * Missing a binding emits a duplicate declaration — a syntax error. Reporting one
10
+ * that isn't there drops an import the code needs. Both are loud, neither is
11
+ * subtle, and the corpus in bindings.spec.ts covers the patterns that bind.
12
+ */
13
+ /** Every name a destructuring pattern (or plain identifier) introduces. */
14
+ function patternNames(node, out) {
15
+ if (!node)
16
+ return;
17
+ switch (node.type) {
18
+ case 'Identifier':
19
+ out.add(node.name);
20
+ return;
21
+ case 'ObjectPattern':
22
+ for (const p of node.properties) {
23
+ if (p.type === 'RestElement')
24
+ patternNames(p.argument, out);
25
+ else
26
+ patternNames(p.value, out);
27
+ }
28
+ return;
29
+ case 'ArrayPattern':
30
+ for (const e of node.elements)
31
+ patternNames(e, out);
32
+ return;
33
+ case 'AssignmentPattern':
34
+ patternNames(node.left, out);
35
+ return;
36
+ case 'RestElement':
37
+ patternNames(node.argument, out);
38
+ return;
39
+ }
40
+ }
41
+ function declared(node, out) {
42
+ switch (node.type) {
43
+ case 'ImportDeclaration':
44
+ for (const s of node.specifiers)
45
+ patternNames(s.local, out);
46
+ return;
47
+ case 'VariableDeclaration':
48
+ for (const d of node.declarations)
49
+ patternNames(d.id, out);
50
+ return;
51
+ case 'FunctionDeclaration':
52
+ case 'ClassDeclaration':
53
+ patternNames(node.id, out);
54
+ return;
55
+ case 'ExportNamedDeclaration':
56
+ case 'ExportDefaultDeclaration':
57
+ // `export const x = 1` / `export function f() {}` bind too.
58
+ if (node.declaration)
59
+ declared(node.declaration, out);
60
+ return;
61
+ }
62
+ }
63
+ /** Collect the names bound at the top level of a parsed module. */
64
+ export function moduleBindings(program) {
65
+ const names = new Set();
66
+ for (const statement of program.body)
67
+ declared(statement, names);
68
+ return names;
69
+ }
@@ -0,0 +1 @@
1
+ function r(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let a of e.properties)a.type==="RestElement"?r(a.argument,t):r(a.value,t);return;case"ArrayPattern":for(let a of e.elements)r(a,t);return;case"AssignmentPattern":r(e.left,t);return;case"RestElement":r(e.argument,t);return}}function n(e,t){switch(e.type){case"ImportDeclaration":for(let a of e.specifiers)r(a.local,t);return;case"VariableDeclaration":for(let a of e.declarations)r(a.id,t);return;case"FunctionDeclaration":case"ClassDeclaration":r(e.id,t);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&n(e.declaration,t);return}}function s(e){let t=new Set;for(let a of e.body)n(a,t);return t}export{s as moduleBindings};
@@ -0,0 +1,3 @@
1
+ "use strict";var De=Object.create;var L=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Fe=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var Xe=(e,t)=>{for(var n in t)L(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Be(t))!He.call(e,r)&&r!==n&&L(e,r,{get:()=>t[r],enumerable:!(o=_e(t,r))||o.enumerable});return e};var ze=(e,t,n)=>(n=e!=null?De(Fe(e)):{},ae(t||!e||!e.__esModule?L(n,"default",{value:e,enumerable:!0}):n,e)),qe=e=>ae(L({},"__esModule",{value:!0}),e);var jt={};Xe(jt,{moduleBindings:()=>V,shapeOf:()=>R,transformTemplates:()=>je});module.exports=qe(jt);var Pe=require("@babel/parser"),Ae=ze(require("magic-string"),1);function Ve(e){switch(e.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return e.reactive?"reactive-prop":e.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function N(e){let t=[],n=new Map,o=r=>{switch(r.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of r.children)o(s);return!1;case"fragment":for(let s of r.children)o(s);return!1;case"element":{let s=!0;for(let a of r.children)o(a)||(s=!1);let i;for(let a of r.props)if(i=Ve(a),i)break;return!i&&!s&&(i=We(r)),r.static=!i,i?n.set(r,i):t.push(r),r.static}default:return!1}};for(let r of Array.isArray(e)?e:[e])o(r);return{staticElements:t,reasons:n}}function We(e){for(let t of e.children){if(t.kind==="expr")return"expression-child";if(t.kind==="component")return"component-child";if(t.kind==="control")return"control-child";if(t.kind==="element"&&!t.static||t.kind==="fragment")return"expression-child"}return"expression-child"}var J={kind:"eager"},Ue=["pointerdown","focusin","keydown"],le=new Set(["eager","idle","visible","interaction","media","never"]),v=class extends Error{};function G(e){return e.startsWith("load:")}function j(e,t){let n=e.slice(5);if(!le.has(n))throw new v(`Unknown load strategy 'load:${n}'. Expected one of ${[...le].join(", ")}.`);switch(n){case"eager":return J;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return t?{kind:"visible",rootMargin:t}:{kind:"visible"};case"interaction":return{kind:"interaction",events:t?Ge(t):[...Ue]};case"media":if(!t)throw new v(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new v(`Unhandled load strategy '${n}'.`)}}function Ge(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new v("'load:interaction' was given no event names.");return t}function D(e){return e.kind!=="eager"&&e.kind!=="never"}var b=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],C=["Suspense","SuspenseList","Await"],k=["Router","Outlet","Redirect","Link"],Ft=[...b,...C,...k],K=new Set([...b,...C]);function ce(e={}){let{controlFlowModule:t="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:o="@fluixi/core/router-next"}=e,r={};for(let s of b)r[s]=t;for(let s of C)r[s]=n;for(let s of k)r[s]=o;return r}function _(e,t={}){let{resolver:n,isBound:o,modules:r,strategyFor:s}=t,i=ce(r),a=new Map,l=new Set,c=d=>{let{name:p}=d;if(!p||p.includes(".")||o?.(p))return;let f=u(p);if(!f){l.add(p);return}let g=f.origin==="builtin"&&K.has(p)?J:s?.(d)??J;d.source={...f,loading:g},a.set(p,d.source)},u=d=>{if(K.has(d))return{module:i[d],export:d,origin:"builtin"};let p=n?.resolve(d);if(p)return{module:p.module,export:p.export,origin:"rule"};if(k.includes(d))return{module:i[d],export:d,origin:"builtin"}};return B(e,d=>{d.kind==="component"&&c(d)}),{resolved:a,unresolved:[...l]}}function B(e,t){let n=Array.isArray(e)?e:[e];for(let o of n){t(o);let r=o.children;r&&B(r,t)}}function F(e){let t=[];B(e,s=>{s.kind==="component"&&s.source&&t.push(s)});let n=new Set,o=new Set;for(let s of t){let{module:i,loading:a}=s.source;a.kind==="eager"&&n.add(i),a.kind==="never"&&o.add(i)}let r=new Map;for(let s of t){let i=s.source;D(i.loading)&&n.has(i.module)&&(i.loading={kind:"eager"},r.set(i.module,(r.get(i.module)??0)+1))}return{collapsed:r,conflicted:[...o].filter(s=>n.has(s))}}var Ke=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),pe={className:"class",htmlFor:"for"},Ye=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Ze=new Set(["script","style","textarea","title"]);function Y(e){return Ze.has(e)}function ue(e){return pe[e]??e}function I(e){return e.kind!=="attr"||e.expr!==void 0||e.name.includes(":")?!1:!Ye.has(e.name)}function Z(e){if(!e.static||Y(e.tag))return!1;for(let t of e.props)if(!I(t))return!1;for(let t of e.children)if(t.kind!=="text"&&!(t.kind==="element"&&Z(t)))return!1;return!0}function T(e){let t=e.props.map(et).filter(Boolean).join(""),n=`<${e.tag}${t}>`;return Ke.has(e.tag)?n:`${n}${e.children.map(Qe).join("")}</${e.tag}>`}function Qe(e){if(e.kind==="text")return nt(e.value);if(e.kind!=="element")throw new Error(`serializeStatic: unexpected ${e.kind}`);return T(e)}function et(e){let t=pe[e.name]??e.name,n=e.literal;return n===!0||n===void 0?` ${t}`:n===!1||n===null?"":` ${t}="${tt(String(n))}"`}function tt(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function nt(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var rt="<!--fx-->",ot="<!--fx/-->";function X(e){return e.kind==="expr"||e.kind==="component"||e.kind==="control"}function it(e){return e.kind==="text"||e.kind==="element"&&de(e)}function de(e){return e.svg||Y(e.tag)||!e.props.every(t=>I(t))?!1:e.children.every(t=>it(t)||X(t))}function H(e){if(X(e))return!0;let t=e.children;return t?t.some(H):!1}function me(e){for(let t=0;t<e.children.length;t++){let n=e.children[t];if(n.kind==="text"&&(n.value===""||e.children[t+1]?.kind==="text"))return!1}return e.children.every(t=>t.kind!=="element"||me(t))}function fe(e){if(!de(e)||!me(e)||!e.children.some(H))return null;let t=[],n=[],o=0,r=i=>{let a=`_n$${o++}`;return t.push({ref:a,expr:i}),a};return s(e,"_el$"),{html:st(e),tag:e.tag,steps:t,holes:n};function s(i,a){let l=-1;i.children.forEach((u,d)=>{H(u)&&(l=d)});let c=null;for(let u=0;u<=l;u++){let d=i.children[u],p=c?`${c}.nextSibling`:`${a}.firstChild`;if(X(d)){let g=r(p),P=r(`holeEnd(${g})`);n.push({parentRef:a,startRef:g,endRef:P,node:d}),c=P;continue}let f=r(p);d.kind==="element"&&H(d)&&s(d,f),c=f}}}function st(e){return T(ge(e)).split(he).join(rt+ot)}function ge(e){return{...e,children:e.children.map(t=>X(t)?{kind:"text",value:he}:t.kind==="element"?ge(t):t)}}var he="\0fx-hole\0";var Q={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},Zt={version:2,module:"@fluixi/dom",symbols:[...Q.symbols,"template","cloneTemplate","walk"]};var at={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function lt(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function Re(e){return lt(e)?e:JSON.stringify(e)}function ct(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function pt(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function ut(e,t,n){let o=e.filter(a=>a.kind==="spread"),s=e.filter(a=>a.kind!=="spread").map(a=>`${Re(a.name)}: ${ct(a)}`);t!=null&&s.push(`children: ${t}`);let i=`{ ${s.join(", ")} }`;return o.length>0?(n.add("mergeProps"),`mergeProps(${o.map(a=>a.expr).join(", ")}, ${i})`):i}function ye(e,t,n){return e.length===1?w(e[0],t,n):`[${e.map(o=>w(o,t,n)).join(", ")}]`}function ve(e,t,n,o,r){o.add("createMemo"),o.add("createComponent");let s=t.filter(c=>c.kind==="spread"),a=t.filter(c=>c.kind!=="spread").map(c=>`get ${Re(c.name)}() { return ${pt(c)}; }`);n.length>0&&a.push(`get children() { return ${ye(n,o,r)}; }`);let l=`{ ${a.join(", ")} }`;return s.length>0&&(o.add("mergeProps"),l=`mergeProps(${s.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${e}, ${l}))`}function dt(e,t){let n=ue(t.name),o=t.literal;return o===!0||o===void 0?`${e}.setAttribute(${JSON.stringify(n)}, "");`:o===!1||o===null?"":`${e}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(o))});`}var xe=!1;function w(e,t,n){switch(e.kind){case"text":return JSON.stringify(e.value);case"expr":return e.reactive?`() => (${e.code})`:`(${e.code})`;case"fragment":return e.children.length===0?"null":ye(e.children,t,n);case"component":return ve(e.name,e.props,e.children,t,n);case"control":{let o=at[e.control]??e.control;return t.add(o),ve(o,e.props,e.children,t,n)}case"element":{if(n&&e.static&&!e.svg&&Z(e)){t.add("templateNode");let a=`_tmpl$${n.length}`;return n.push({id:a,html:T(e),tag:e.tag,svg:!1}),`templateNode(${a}, ${JSON.stringify(e.tag)})`}if(n&&xe){let a=fe(e);if(a){t.add("templateNode"),t.add("insert"),t.add("holeEnd"),t.add("holeContent"),t.add("holeScope");let l=`_tmpl$${n.length}`;n.push({id:l,html:a.html,tag:a.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(a.tag)}, true);`];for(let u of a.steps)c.push(`const ${u.ref} = ${u.expr};`);for(let u of a.holes)c.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${w(u.node,t,n)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}t.add("createNativeElement");let o=JSON.stringify(e.tag),r="_el$",s=[],i=e.svg?`${o}, true`:o;if(s.push(`const ${r} = createNativeElement(${i});`),e.props.length>0)if(!e.svg&&e.props.every(I))for(let a of e.props)s.push(dt(r,a));else{t.add("spread");let a=e.svg?", isSVG: true":"";s.push(`spread({ element: ${r}, props: ${ut(e.props,null,t)}${a} });`)}for(let a of e.children){t.add("insert");let l=w(a,t,n),c=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";s.push(c?`insert(${r}, ${l}, null);`:`insert(${r}, ${l});`)}return s.push(`return ${r};`),`(() => { ${s.join(" ")} })()`}}}function z(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(o=>[o.id,JSON.stringify(o.html)]));return e.replace(/_tmpl\$\d+/g,o=>n.get(o)??o)}var E={name:"imperative",contract:Q,emit(e,t){let n=new Set,o=t?.templateClone!==!1?[]:void 0;return xe=t?.partialTemplates===!0,{code:w(e,n,o),imports:Array.from(n),templates:o}}};var mt=e=>"components"in e;function Ne(e,t){return e.replace(/\$(\d+)/g,(n,o)=>t[Number(o)]??n)}function ft(e,t){return typeof t=="string"?{module:t,export:e}:t}function q(e=[]){let t=new Map,n=[],o=[];for(let i of e){if(!mt(i)){o.push(i);continue}for(let[a,l]of Object.entries(i.components)){let c=ft(a,l),u=t.get(a);if(u&&u.module!==c.module){let d=n.find(p=>p.name===a);d?d.modules.push(c.module):n.push({name:a,modules:[u.module,c.module]});continue}t.set(a,c)}}let r=new Map;return{resolve:i=>{if(r.has(i))return r.get(i);let a=t.get(i);if(!a)for(let l of o){let c=i.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){a={module:Ne(l.module,c),export:l.export?Ne(l.export,c):i};break}}return r.set(i,a),a},names:()=>[...t.keys()],conflicts:()=>n}}var Se=require("@fluixi/template-parser");function $(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let r=0;r<t.length;r++)/[^ \t]/.test(t[r])&&(n=r);let o="";for(let r=0;r<t.length;r++){let s=t[r].replace(/\t/g," ");r!==0&&(s=s.replace(/^ +/,"")),r!==t.length-1&&(s=s.replace(/ +$/,"")),s&&(r!==n&&(s+=" "),o+=s)}return o}var ke=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function gt(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Ee(e){return e.charAt(0).toUpperCase()+e.slice(1)}var ee=class{constructor(t,n){this.holes=t;this.used=n}hole(t){return this.holes[t]??{code:"undefined",reactive:!1}}emit(t){let{code:n,imports:o,templates:r}=E.emit(t,{});for(let s of o)this.used.add(s);return z(n,r)}lowerRoot(t){let n=this.lowerChildren(t);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(t){let n=[];for(let o=0;o<t.length;o++){let r=t[o];if(r.kind==="Element"||r.kind==="Component"){let i=r.attributes.find(a=>a.kind==="IfDirective");if(i&&i.kind==="IfDirective"){let a=o+1;a<t.length&&this.isBlankText(t[a])&&a++;let l=t[a],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(u=>u.kind==="ElseDirective");n.push(this.lowerIf(r,i.hole,c?l:null)),c&&(o=a);continue}if(r.attributes.some(a=>a.kind==="EachDirective")){n.push(this.lowerEach(r));continue}}let s=this.lowerNode(r);s&&n.push(s)}return n}isBlankText(t){return t.kind==="Text"&&!t.raw&&$(t.value)===""}lowerNode(t){switch(t.kind){case"Text":{if(t.raw)return{kind:"text",value:t.value};let n=$(t.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(t.hole);return{kind:"expr",code:n.code,reactive:n.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(t.children)};case"Element":return this.lowerElement(t);case"Component":return this.lowerComponent(t);default:return null}}lowerElement(t){let n=t.attributes.find(o=>o.kind==="Attribute"&&o.name==="is");if(t.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let o=t.attributes.filter(s=>s!==n),r=this.lowerComponent({...t,kind:"Component",tag:"Dynamic",tagHole:null,attributes:o});return r.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),r}return{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:this.lowerAttributes(t.attributes),children:this.lowerChildren(t.children),static:!1}}lowerComponent(t){let n=t.tagHole!=null?this.hole(t.tagHole).code:t.tag,o=this.lowerAttributes(t.attributes),{slots:r,rest:s}=this.partitionSlots(t.children);for(let[l,c]of r){let u=c.length===1?c[0]:{kind:"fragment",children:c},d={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},p=o.findIndex(f=>f.name===l);p>=0?o[p]=d:o.push(d)}let i=t.attributes.find(l=>l.kind==="LoadDirective"),a=i?j(`load:${i.strategy}`,i.modifier):void 0;return{kind:"component",name:n,props:o,children:this.lowerChildren(s),...a?{load:a}:{}}}partitionSlots(t){let n=new Map,o=[];for(let r of t){if(r.kind==="Element"||r.kind==="Component"){let s=r.attributes.find(i=>i.kind==="Attribute"&&i.name==="slot");if(s&&s.value&&s.value.kind==="static"){let i={...r,attributes:r.attributes.filter(c=>c!==s)},a=i.kind==="Element"?this.lowerElement(i):this.lowerComponent(i),l=n.get(s.value.value)??[];l.push(a),n.set(s.value.value,l);continue}}o.push(r)}return{slots:n,rest:o}}lowerIf(t,n,o){let r=this.hole(n),s=[{name:"when",kind:"attr",expr:r.code,reactive:r.reactive}];if(o){let a=this.stripAndLower(o,l=>l.kind==="ElseDirective");s.push({name:"fallback",kind:"attr",expr:this.emit(a),jsxElement:!0})}let i=this.stripAndLower(t,a=>a.kind==="IfDirective");return{kind:"component",name:"Show",props:s,children:[i]}}lowerEach(t){let n=t.attributes.find(l=>l.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(t);let o=this.hole(n.hole),r=[{name:"each",kind:"attr",expr:o.code,reactive:o.reactive}];if(n.key){let l="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;r.push({name:"by",kind:"attr",expr:l})}let s=this.itemArrow(t),i;if(s){let l={kind:"expr",code:s.body,reactive:s.bodyReactive},c=this.rebuildWithChildren(t,[l]);i=`(${s.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(t,c=>c.kind==="EachDirective");i=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:r,children:[{kind:"expr",code:i,reactive:!1}]}}itemArrow(t){let n=t.children.filter(o=>!this.isBlankText(o));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(t,n){let o={...t,attributes:t.attributes.filter(r=>!n(r))};return o.kind==="Element"?this.lowerElement(o):this.lowerComponent(o)}rebuildWithChildren(t,n){let o=this.lowerAttributes(t.attributes.filter(r=>r.kind!=="EachDirective"));return t.kind==="Element"?{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:o,children:n,static:!1}:{kind:"component",name:t.tag,props:o,children:n}}lowerAttributes(t){let n=[],o=[],r=!1,s=[],i=!1,a=[];for(let l of t)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":n.push(this.plainAttr(l));break;case"PropertyBinding":n.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"EventBinding":n.push(this.eventProp(l));break;case"RefBinding":n.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let c=this.hole(l.hole);o.push(`${JSON.stringify(l.name)}: ${c.code}`),r=r||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);s.push(`${JSON.stringify(l.name)}: ${c.code}`),i=i||c.reactive;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole).code));break;case"UseDirective":{let c=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!c)break;a.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return o.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:r}),s.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${s.join(", ")} }`,reactive:i}),a.length>0&&n.push({name:"use",kind:"attr",expr:`[${a.join(", ")}]`}),n}eventProp(t){let n=t.name.toLowerCase(),o=this.hole(t.hole).code;if(!(t.syntax==="colon"||t.modifiers.length>0))return{name:"on"+Ee(t.name),kind:"event",event:{name:n,delegated:ke.has(n)},expr:o};let s=this.wrapHandler(o,t.modifiers),i=this.eventOptions(t.modifiers),a=i?`[${s}, ${i}]`:s;return{name:"on:"+n,kind:"attr",expr:a}}wrapHandler(t,n){let o=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",r=[];return n.includes("prevent")&&r.push("e.preventDefault();"),n.includes("stop")&&r.push("e.stopPropagation();"),!o&&r.length===0?t:`(e) => { ${o}${r.join(" ")} return (${t})(e); }`}eventOptions(t){let n=[];return t.includes("capture")&&n.push("capture: true"),t.includes("once")&&n.push("once: true"),t.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(t,n){let o=t==="checked",r=o?"change":"input",s=o?"checked":"value",i=`(${n})`;return[{name:t,kind:"attr",expr:`${i}[0]()`,reactive:!0},{name:"on"+Ee(r),kind:"event",event:{name:r,delegated:ke.has(r)},expr:`(e) => ${i}[1](e.target.${s})`}]}plainAttr(t){let n=t.value,o=t.name;t.name==="class"?o=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":t.name==="html"&&(o="innerHTML");let s={name:o,kind:"attr"};if(n==null)return s.literal=!0,s;if(n.kind==="static")return s.literal=n.value,s;if(n.kind==="hole"){let l=this.hole(n.hole);return s.expr=l.code,s.reactive=l.reactive,s}let i=!1,a=n.parts.map(l=>{if("text"in l)return gt(l.text);let c=this.hole(l.hole);return i=i||c.reactive,"${"+c.code+"}"}).join("");return s.expr="`"+a+"`",s.reactive=i,s}};function be(e,t,n,o={}){let{root:r}=(0,Se.parseTemplate)(e,{svg:o.svg});return new ee(t,n).lowerRoot(r.children)}function Ce(e,t,n={}){let o=new Set,r=be(e,[...t],o,{svg:n.svg});N(r),_(r,{resolver:q(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router-next"},strategyFor:l=>l.load}),F(r);let{code:s,imports:i,templates:a}=E.emit(r,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let l of i)o.add(l);return n.hoistTemplates?{code:s,imports:[...o],ir:r,templates:a}:{code:z(s,a),imports:[...o],ir:r}}var ht="children";function S(e){switch(e.kind){case"call":return!0;case"member":return e.property!==ht;case"compound":return e.parts.some(S);case"opaque":return!1}}var vt=new Set(["CallExpression","OptionalCallExpression"]),Rt=new Set(["MemberExpression","OptionalMemberExpression"]);function R(e){if(!e)return{kind:"opaque"};if(vt.has(e.type))return{kind:"call"};if(Rt.has(e.type)){let t=e.property;return{kind:"member",property:!(e.computed===!0)&&t?.type==="Identifier"?t.name:null}}return e.type==="ConditionalExpression"?{kind:"compound",parts:[e.test,e.consequent,e.alternate].map(O)}:e.type==="LogicalExpression"||e.type==="BinaryExpression"?{kind:"compound",parts:[e.left,e.right].map(O)}:e.type==="TemplateLiteral"?{kind:"compound",parts:e.expressions.map(O)}:e.type==="ObjectExpression"?{kind:"compound",parts:e.properties.filter(n=>(n.type==="ObjectProperty"||n.type==="Property")&&n.computed!==!0).map(n=>O(n.value))}:e.type==="ArrayExpression"?{kind:"compound",parts:e.elements.filter(n=>n!=null&&n.type!=="SpreadElement").map(O)}:{kind:"opaque"}}var O=e=>R(e);var yt=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),xt=/^on[A-Z]/,Nt=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),we=e=>S(R(e));function M(e){if(e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral"||e.type==="Literal"&&(typeof e.value=="string"||typeof e.value=="number"||typeof e.value=="boolean"))return e.value}var te=e=>!!e&&typeof M(e)=="string";function kt(e,t){return e.type==="JSXIdentifier"?{tag:e.name,component:e.name[0]!==e.name[0].toLowerCase()}:e.type==="JSXMemberExpression"?{tag:t.code(e),component:!0}:e.type==="JSXNamespacedName"?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function ne(e){return e.type==="JSXIdentifier"?e.name==="class"?"className":e.name:e.type==="JSXNamespacedName"?`${e.namespace.name}:${e.name.name}`:"unknown"}function Et(e,t){let n=ne(e.name),o=xt.test(n),r=o||n.startsWith("on:")||n==="ref",i={name:n,kind:o?"event":"attr"};if(o){let l=n.slice(2).toLowerCase();i.event={name:l,delegated:Nt.has(l)}}let a=e.value;if(a==null)return i.literal=!0,i;if(te(a))return i.literal=M(a),i;if(a.type==="JSXExpressionContainer"&&a.expression?.type!=="JSXEmptyExpression"){let l=a.expression,c=M(l);return c!==void 0?(i.literal=c,i):(i.expr=t.code(l),i.reactive=r?!1:we(l),(l.type==="JSXElement"||l.type==="JSXFragment")&&(i.jsxElement=!0),i)}return i.literal=!0,i}function Ie(e,t){let n=e.value;return n==null?null:te(n)?JSON.stringify(M(n)):n.type==="JSXExpressionContainer"&&n.expression?.type!=="JSXEmptyExpression"?t.code(n.expression):null}function St(e,t){let n=[],o=[];for(let r of e){if(r.type==="JSXSpreadAttribute"){n.push({name:"",kind:"spread",expr:t.code(r.argument)});continue}if(r.type!=="JSXAttribute"||G(ne(r.name)))continue;let s=r.name.type==="JSXNamespacedName"?r.name.namespace.name:null;if(s==="use"){let i=r.name.name.name;t.used.add(i);let a=Ie(r,t);o.push(a!=null?`[${i}, () => (${a})]`:`[${i}]`);continue}if(s==="oncapture"){let i=r.name.name.name.toLowerCase(),a=Ie(r,t)??"undefined";n.push({name:"on:"+i,kind:"attr",expr:`[${a}, { capture: true }]`});continue}n.push(Et(r,t))}return o.length>0&&n.push({name:"use",kind:"attr",expr:`[${o.join(", ")}]`}),n}function Te(e,t){let n=[];for(let o of e)if(o.type==="JSXText"){let r=$(o.value);r&&n.push({kind:"text",value:r})}else if(o.type==="JSXExpressionContainer"){if(o.expression?.type!=="JSXEmptyExpression"){let r=o.expression;n.push({kind:"expr",code:t.code(r),reactive:we(r)})}}else o.type==="JSXElement"||o.type==="JSXFragment"?n.push($e(o,t)):o.type==="JSXSpreadChild"&&n.push({kind:"expr",code:t.code(o.expression),reactive:!1});return n}function bt(e){for(let t of e){if(t.type!=="JSXAttribute")continue;let n=ne(t.name);if(G(n)){if(t.value&&!te(t.value))throw new v(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return j(n,t.value?M(t.value):null)}}}function $e(e,t){if(e.type==="JSXFragment")return{kind:"fragment",children:Te(e.children,t)};let{tag:n,component:o}=kt(e.openingElement.name,t),r=St(e.openingElement.attributes,t),s=Te(e.children,t);if(o){let i=bt(e.openingElement.attributes);return{kind:"component",name:n,props:r,children:s,...i?{load:i}:{}}}return{kind:"element",tag:n,svg:yt.has(n),props:r,children:s,static:!1}}function Oe(e,t){let n=$e(e,t);return N(n),n}function y(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?y(n.argument,t):y(n.value,t);return;case"ArrayPattern":for(let n of e.elements)y(n,t);return;case"AssignmentPattern":y(e.left,t);return;case"RestElement":y(e.argument,t);return}}function Me(e,t){switch(e.type){case"ImportDeclaration":for(let n of e.specifiers)y(n.local,t);return;case"VariableDeclaration":for(let n of e.declarations)y(n.id,t);return;case"FunctionDeclaration":case"ClassDeclaration":y(e.id,t);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&Me(e.declaration,t);return}}function V(e){let t=new Set;for(let n of e.body)Me(n,t);return t}var Ct=new Set(b),It=new Set(C),Tt=new Set(k),wt=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]);function re(e,t,n=null,o=""){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let r of e)re(r,t,n,o);return}typeof e.type=="string"&&t(e,n,o);for(let r of Object.keys(e))r==="loc"||r==="leadingComments"||r==="trailingComments"||re(e[r],t,typeof e.type=="string"?e:n,r)}}var oe=e=>e.type==="JSXElement"||e.type==="JSXFragment";function $t(e,t,n){return oe(e)?!(t&&oe(t)&&n==="children"):!1}function Ot(e,t){return e.type==="TaggedTemplateExpression"&&e.tag?.type==="Identifier"&&(e.tag.name===t||e.tag.name==="svg")}function Le(e){return e.filter(t=>!e.some(n=>n!==t&&n.start<=t.start&&n.end>=t.end&&n.end-n.start>t.end-t.start))}function W(e,t,n,o){let r=Le(o.filter(i=>i.start>=t&&i.end<=n)).sort((i,a)=>a.start-i.start),s=e.slice(t,n);for(let i of r)s=s.slice(0,i.start-t)+i.code+s.slice(i.end-t);return s}function Mt(e,t,n){let o={code:W(e,t.start,t.end,n),reactive:S(R(t))};return t.type==="ArrowFunctionExpression"&&t.body?.type!=="BlockStatement"&&(o.arrow={params:t.params.map(r=>W(e,r.start,r.end,n)),body:W(e,t.body.start,t.body.end,n),bodyReactive:S(R(t.body))}),t.type==="ObjectExpression"&&(o.object=!0),o}function Je(e,t,n){if(!t||t.length===0)return e;let o=new Map;for(let r of t){let s=`${r.svg?"svg:":""}${r.html}`,i=n.get(s);i||(i=`_fxTmpl$${n.size}`,n.set(s,i)),o.set(r.id,i)}return e.replace(/_tmpl\$\d+/g,r=>o.get(r)??r)}function ie(e,t){if(e.kind==="component"&&e.source){let n=e.source;n.origin==="builtin"?t.builtins.add(e.name):D(n.loading)&&!t.resolved.has(e.name)?t.deferred.set(e.name,n):(t.deferred.delete(e.name),t.resolved.set(e.name,n))}if("props"in e&&e.props)for(let n of e.props)n.kind==="event"&&n.event?.delegated&&t.delegatedEvents.add(n.event.name);if("children"in e&&e.children)for(let n of e.children)ie(n,t)}function Pt(e){let t=[`kind: ${JSON.stringify(e.kind)}`];return e.kind==="visible"&&e.rootMargin&&t.push(`rootMargin: ${JSON.stringify(e.rootMargin)}`),e.kind==="interaction"&&t.push(`events: ${JSON.stringify(e.events)}`),e.kind==="media"&&t.push(`query: ${JSON.stringify(e.query)}`),`{ ${t.join(", ")} }`}function At(e){let t=[];return e.quasi.quasis.forEach((n,o)=>{if(t.push({kind:"static",text:n.value.cooked??n.value.raw,start:n.start}),o<e.quasi.expressions.length){let r=e.quasi.expressions[o];t.push({kind:"hole",index:o,start:r.start,end:r.end})}}),t}function je(e,t,n={}){let o=n.litTag??"html",r=n.format??"both",s=r!=="jsx",i=r!=="lit";if(!(s&&(e.includes(`${o}\``)||e.includes("svg`")))&&!(i&&e.includes("<")))return null;let l=(0,Pe.parse)(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),c=[];if(re(l.program,(m,x,U)=>{(s&&Ot(m,o)||i&&$t(m,x,U))&&c.push(m)}),c.length===0)return null;c.sort((m,x)=>x.start-m.start||m.end-x.end);let u=new Set,d={builtins:new Set,resolved:new Map,deferred:new Map,delegatedEvents:new Set},p=new Map,f=[];for(let m of c){let x=c.some(h=>h!==m&&h.start<=m.start&&h.end>=m.end&&h.end-h.start>m.end-m.start);if(oe(m)){f.push({start:m.start,end:m.end,code:Lt(e,m,f,x,u,d,p,n)});continue}let U=m.quasi.expressions.map(h=>Mt(e,h,f)),A=Ce(At(m),U,{...n,hoistTemplates:!0,templateClone:n.templateClone??!0,partialTemplates:x?!1:n.partialTemplates??!0,svg:m.tag.name==="svg"});for(let h of A.imports)u.add(h);ie(A.ir,d),f.push({start:m.start,end:m.end,code:Je(A.code,A.templates,p)})}let g=new Ae.default(e);for(let m of Le(f))g.overwrite(m.start,m.end,m.code);let P=V(l.program),se=Jt(u,d,p,P,n);se&&g.prepend(se);for(let m of l.program.body)m.type==="ImportDeclaration"&&m.source?.value==="@fluixi/core/rx"&&g.overwrite(m.source.start,m.source.end,JSON.stringify("@fluixi/reactive"));return{code:g.toString(),map:g.generateMap({source:t,includeContent:!0,hires:!0})}}function Lt(e,t,n,o,r,s,i,a){let l=Oe(t,{code:u=>W(e,u.start,u.end,n),used:r});N(l),_(l,{resolver:q(a.resolve??[]),modules:{controlFlowModule:a.controlFlowModule??a.runtimeModule??"@fluixi/dom",coreModule:a.coreModule??"@fluixi/core",routerModule:a.routerModule??"@fluixi/core/router-next"},strategyFor:u=>u.load}),F(l);let c=E.emit(l,{templateClone:a.templateClone??!0,partialTemplates:o?!1:a.partialTemplates??!0});for(let u of c.imports)r.add(u);return ie(l,s),Je(c.code,c.templates,i)}function Jt(e,t,n,o,r){let s=r.runtimeModule??"@fluixi/dom",i=r.coreModule??"@fluixi/core",a=new Map,l=(p,f)=>a.set(p,[...a.get(p)??[],f]),c=new Set(e);for(let p of t.builtins)c.add(p);t.delegatedEvents.size>0&&c.add("delegateEvents");for(let p of[...c].sort())o.has(p)||(wt.has(p)?l(r.reactiveModule??"@fluixi/reactive/signal",p):Tt.has(p)?l(r.routerModule??"@fluixi/core/router-next",p):It.has(p)?l(i,p):Ct.has(p)?l(r.controlFlowModule??s,p):l(s,p));for(let[p,f]of t.resolved)o.has(p)||l(f.module,f.export==="default"?`default as ${p}`:p===f.export?p:`${f.export} as ${p}`);let u=[];for(let[p,f]of a)u.push(`import { ${f.join(", ")} } from ${JSON.stringify(p)};`);let d=[...t.deferred].filter(([p])=>!o.has(p));if(d.length>0){o.has("deferred")||u.push(`import { deferred } from ${JSON.stringify(i)};`);for(let[p,f]of d)u.push(`const ${p} = deferred(() => import(${JSON.stringify(f.module)}), { strategy: ${Pt(f.loading)}, export: ${JSON.stringify(f.export)} });`)}for(let[p,f]of n)u.push(`const ${f} = ${JSON.stringify(p.startsWith("svg:")?p.slice(4):p)};`);return t.delegatedEvents.size>0&&u.push(`delegateEvents(${JSON.stringify([...t.delegatedEvents])});`),u.length>0?u.join(`
2
+ `)+`
3
+ `:null}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The Fluixi transform: source in, source out, positions preserved.
3
+ *
4
+ * Runs the compiler over a module directly instead of as a plugin inside a
5
+ * JavaScript toolchain. A parser is used as a library; nothing round-trips
6
+ * through a host AST, so holes keep the author's text and edits carry a map.
7
+ */
8
+ export { transformTemplates } from './templates.js';
9
+ export type { TransformOptions, TransformResult } from './templates.js';
10
+ export { moduleBindings } from './bindings.js';
11
+ export { shapeOf } from '../analyze/expr-shape.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transform/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The Fluixi transform: source in, source out, positions preserved.
3
+ *
4
+ * Runs the compiler over a module directly instead of as a plugin inside a
5
+ * JavaScript toolchain. A parser is used as a library; nothing round-trips
6
+ * through a host AST, so holes keep the author's text and edits carry a map.
7
+ */
8
+ export { transformTemplates } from './templates.js';
9
+ export { moduleBindings } from './bindings.js';
10
+ export { shapeOf } from '../analyze/expr-shape.js';
@@ -0,0 +1,12 @@
1
+ import{parse as Dt}from"@babel/parser";var ze=44,We=59,he="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ve=new Uint8Array(64),Ge=new Uint8Array(128);for(let n=0;n<he.length;n++){let e=he.charCodeAt(n);ve[n]=e,Ge[e]=n}function N(n,e,t){let r=e-t;r=r<0?-r<<1|1:r<<1;do{let i=r&31;r>>>=5,r>0&&(i|=32),n.write(ve[i])}while(r>0);return e}var me=1024*16,ge=typeof TextDecoder<"u"?new TextDecoder:typeof Buffer<"u"?{decode(n){return Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString()}}:{decode(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return e}},Ve=class{constructor(){this.pos=0,this.out="",this.buffer=new Uint8Array(me)}write(n){let{buffer:e}=this;e[this.pos++]=n,this.pos===me&&(this.out+=ge.decode(e),this.pos=0)}flush(){let{buffer:n,out:e,pos:t}=this;return t>0?e+ge.decode(n.subarray(0,t)):e}};function xe(n){let e=new Ve,t=0,r=0,i=0,o=0;for(let s=0;s<n.length;s++){let a=n[s];if(s>0&&e.write(We),a.length===0)continue;let l=0;for(let c=0;c<a.length;c++){let u=a[c];c>0&&e.write(ze),l=N(e,u[0],l),u.length!==1&&(t=N(e,u[1],t),r=N(e,u[2],r),i=N(e,u[3],i),u.length!==4&&(o=N(e,u[4],o)))}}return e.flush()}var D=class n{constructor(e){this.bits=e instanceof n?e.bits.slice():[]}add(e){this.bits[e>>5]|=1<<(e&31)}has(e){return!!(this.bits[e>>5]&1<<(e&31))}},J=class n{constructor(e,t,r){this.start=e,this.end=t,this.original=r,this.intro="",this.outro="",this.content=r,this.storeName=!1,this.edited=!1,this.previous=null,this.next=null}appendLeft(e){this.outro+=e}appendRight(e){this.intro=this.intro+e}clone(){let e=new n(this.start,this.end,this.original);return e.intro=this.intro,e.outro=this.outro,e.content=this.content,e.storeName=this.storeName,e.edited=this.edited,e}contains(e){return this.start<e&&e<this.end}eachNext(e){let t=this;for(;t;)e(t),t=t.next}eachPrevious(e){let t=this;for(;t;)e(t),t=t.previous}edit(e,t,r){return this.content=e,r||(this.intro="",this.outro=""),this.storeName=t,this.edited=!0,this}prependLeft(e){this.outro=e+this.outro}prependRight(e){this.intro=e+this.intro}reset(){this.intro="",this.outro="",this.edited&&(this.content=this.original,this.storeName=!1,this.edited=!1)}split(e){let t=e-this.start,r=this.original.slice(0,t),i=this.original.slice(t);this.original=r;let o=new n(e,this.end,i);return o.outro=this.outro,this.outro="",this.end=e,this.edited?(o.edit("",!1),this.content=""):this.content=r,o.next=this.next,o.next&&(o.next.previous=o),o.previous=this,this.next=o,o}toString(){return this.intro+this.content+this.outro}trimEnd(e){if(this.outro=this.outro.replace(e,""),this.outro.length)return!0;let t=this.content.replace(e,"");if(t.length)return t!==this.content&&(this.split(this.start+t.length).edit("",void 0,!0),this.edited&&this.edit(t,this.storeName,!0)),!0;if(this.edit("",void 0,!0),this.intro=this.intro.replace(e,""),this.intro.length)return!0}trimStart(e){if(this.intro=this.intro.replace(e,""),this.intro.length)return!0;let t=this.content.replace(e,"");if(t.length){if(t!==this.content){let r=this.split(this.end-t.length);this.edited&&r.edit(t,this.storeName,!0),this.edit("",void 0,!0)}return!0}else if(this.edit("",void 0,!0),this.outro=this.outro.replace(e,""),this.outro.length)return!0}};function Ke(){return typeof globalThis<"u"&&typeof globalThis.btoa=="function"?n=>globalThis.btoa(unescape(encodeURIComponent(n))):typeof Buffer=="function"?n=>Buffer.from(n,"utf-8").toString("base64"):()=>{throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.")}}var Ye=Ke(),Q=class{constructor(e){this.version=3,this.file=e.file,this.sources=e.sources,this.sourcesContent=e.sourcesContent,this.names=e.names,this.mappings=xe(e.mappings),typeof e.x_google_ignoreList<"u"&&(this.x_google_ignoreList=e.x_google_ignoreList),typeof e.debugId<"u"&&(this.debugId=e.debugId)}toString(){return JSON.stringify(this)}toUrl(){return"data:application/json;charset=utf-8;base64,"+Ye(this.toString())}};function Ze(n){let e=n.split(`
2
+ `),t=e.filter(o=>/^\t+/.test(o)),r=e.filter(o=>/^ {2,}/.test(o));if(t.length===0&&r.length===0)return null;if(t.length>=r.length)return" ";let i=r.reduce((o,s)=>{let a=/^ +/.exec(s)[0].length;return Math.min(a,o)},1/0);return new Array(i+1).join(" ")}function Qe(n,e){let t=n.split(/[/\\]/),r=e.split(/[/\\]/);for(t.pop();t[0]===r[0];)t.shift(),r.shift();if(t.length){let i=t.length;for(;i--;)t[i]=".."}return t.concat(r).join("/")}var et=Object.prototype.toString;function tt(n){return et.call(n)==="[object Object]"}function ye(n){let e=n.split(`
3
+ `),t=[];for(let r=0,i=0;r<e.length;r++)t.push(i),i+=e[r].length+1;return function(i){let o=0,s=t.length;for(;o<s;){let c=o+s>>1;i<t[c]?s=c:o=c+1}let a=o-1,l=i-t[a];return{line:a,column:l}}}var nt=/\w/,ee=class{constructor(e){this.hires=e,this.generatedCodeLine=0,this.generatedCodeColumn=0,this.raw=[],this.rawSegments=this.raw[this.generatedCodeLine]=[],this.pending=null}addEdit(e,t,r,i){if(t.length){let o=t.length-1,s=t.indexOf(`
4
+ `,0),a=-1;for(;s>=0&&o>s;){let c=[this.generatedCodeColumn,e,r.line,r.column];i>=0&&c.push(i),this.rawSegments.push(c),this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,a=s,s=t.indexOf(`
5
+ `,s+1)}let l=[this.generatedCodeColumn,e,r.line,r.column];i>=0&&l.push(i),this.rawSegments.push(l),this.advance(t.slice(a+1))}else this.pending&&(this.rawSegments.push(this.pending),this.advance(t));this.pending=null}addUneditedChunk(e,t,r,i,o){let s=t.start,a=!0,l=!1;for(;s<t.end;){if(r[s]===`
6
+ `)i.line+=1,i.column=0,this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,a=!0,l=!1;else{if(this.hires||a||o.has(s)){let c=[this.generatedCodeColumn,e,i.line,i.column];this.hires==="boundary"?nt.test(r[s])?l||(this.rawSegments.push(c),l=!0):(this.rawSegments.push(c),l=!1):this.rawSegments.push(c)}i.column+=1,this.generatedCodeColumn+=1,a=!1}s+=1}this.pending=null}advance(e){if(!e)return;let t=e.split(`
7
+ `);if(t.length>1){for(let r=0;r<t.length-1;r++)this.generatedCodeLine++,this.raw[this.generatedCodeLine]=this.rawSegments=[];this.generatedCodeColumn=0}this.generatedCodeColumn+=t[t.length-1].length}},E=`
8
+ `,R={insertLeft:!1,insertRight:!1,storeName:!1},B=class n{constructor(e,t={}){let r=new J(0,e.length,e);Object.defineProperties(this,{original:{writable:!0,value:e},outro:{writable:!0,value:""},intro:{writable:!0,value:""},firstChunk:{writable:!0,value:r},lastChunk:{writable:!0,value:r},lastSearchedChunk:{writable:!0,value:r},byStart:{writable:!0,value:{}},byEnd:{writable:!0,value:{}},filename:{writable:!0,value:t.filename},indentExclusionRanges:{writable:!0,value:t.indentExclusionRanges},sourcemapLocations:{writable:!0,value:new D},storedNames:{writable:!0,value:{}},indentStr:{writable:!0,value:void 0},ignoreList:{writable:!0,value:t.ignoreList},offset:{writable:!0,value:t.offset||0}}),this.byStart[0]=r,this.byEnd[e.length]=r}addSourcemapLocation(e){this.sourcemapLocations.add(e)}append(e){if(typeof e!="string")throw new TypeError("outro content must be a string");return this.outro+=e,this}appendLeft(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byEnd[e];return r?r.appendLeft(t):this.intro+=t,this}appendRight(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byStart[e];return r?r.appendRight(t):this.outro+=t,this}clone(){let e=new n(this.original,{filename:this.filename,offset:this.offset}),t=this.firstChunk,r=e.firstChunk=e.lastSearchedChunk=t.clone();for(;t;){e.byStart[r.start]=r,e.byEnd[r.end]=r;let i=t.next,o=i&&i.clone();o&&(r.next=o,o.previous=r,r=o),t=i}return e.lastChunk=r,this.indentExclusionRanges&&(e.indentExclusionRanges=this.indentExclusionRanges.slice()),e.sourcemapLocations=new D(this.sourcemapLocations),e.intro=this.intro,e.outro=this.outro,e}generateDecodedMap(e){e=e||{};let t=0,r=Object.keys(this.storedNames),i=new ee(e.hires),o=ye(this.original);return this.intro&&i.advance(this.intro),this.firstChunk.eachNext(s=>{let a=o(s.start);s.intro.length&&i.advance(s.intro),s.edited?i.addEdit(t,s.content,a,s.storeName?r.indexOf(s.original):-1):i.addUneditedChunk(t,s,this.original,a,this.sourcemapLocations),s.outro.length&&i.advance(s.outro)}),this.outro&&i.advance(this.outro),{file:e.file?e.file.split(/[/\\]/).pop():void 0,sources:[e.source?Qe(e.file||"",e.source):e.file||""],sourcesContent:e.includeContent?[this.original]:void 0,names:r,mappings:i.raw,x_google_ignoreList:this.ignoreList?[t]:void 0}}generateMap(e){return new Q(this.generateDecodedMap(e))}_ensureindentStr(){this.indentStr===void 0&&(this.indentStr=Ze(this.original))}_getRawIndentString(){return this._ensureindentStr(),this.indentStr}getIndentString(){return this._ensureindentStr(),this.indentStr===null?" ":this.indentStr}indent(e,t){let r=/^[^\r\n]/gm;if(tt(e)&&(t=e,e=void 0),e===void 0&&(this._ensureindentStr(),e=this.indentStr||" "),e==="")return this;t=t||{};let i={};t.exclude&&(typeof t.exclude[0]=="number"?[t.exclude]:t.exclude).forEach(u=>{for(let p=u[0];p<u[1];p+=1)i[p]=!0});let o=t.indentStart!==!1,s=c=>o?`${e}${c}`:(o=!0,c);this.intro=this.intro.replace(r,s);let a=0,l=this.firstChunk;for(;l;){let c=l.end;if(l.edited)i[a]||(l.content=l.content.replace(r,s),l.content.length&&(o=l.content[l.content.length-1]===`
9
+ `));else for(a=l.start;a<c;){if(!i[a]){let u=this.original[a];u===`
10
+ `?o=!0:u!=="\r"&&o&&(o=!1,a===l.start||(this._splitChunk(l,a),l=l.next),l.prependRight(e))}a+=1}a=l.end,l=l.next}return this.outro=this.outro.replace(r,s),this}insert(){throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)")}insertLeft(e,t){return R.insertLeft||(console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"),R.insertLeft=!0),this.appendLeft(e,t)}insertRight(e,t){return R.insertRight||(console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"),R.insertRight=!0),this.prependRight(e,t)}move(e,t,r){if(e=e+this.offset,t=t+this.offset,r=r+this.offset,r>=e&&r<=t)throw new Error("Cannot move a selection inside itself");this._split(e),this._split(t),this._split(r);let i=this.byStart[e],o=this.byEnd[t],s=i.previous,a=o.next,l=this.byStart[r];if(!l&&o===this.lastChunk)return this;let c=l?l.previous:this.lastChunk;return s&&(s.next=a),a&&(a.previous=s),c&&(c.next=i),l&&(l.previous=o),i.previous||(this.firstChunk=o.next),o.next||(this.lastChunk=i.previous,this.lastChunk.next=null),i.previous=c,o.next=l||null,c||(this.firstChunk=i),l||(this.lastChunk=o),this}overwrite(e,t,r,i){return i=i||{},this.update(e,t,r,{...i,overwrite:!i.contentOnly})}update(e,t,r,i){if(e=e+this.offset,t=t+this.offset,typeof r!="string")throw new TypeError("replacement content must be a string");if(this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(t>this.original.length)throw new Error("end is out of bounds");if(e===t)throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");this._split(e),this._split(t),i===!0&&(R.storeName||(console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"),R.storeName=!0),i={storeName:!0});let o=i!==void 0?i.storeName:!1,s=i!==void 0?i.overwrite:!1;if(o){let c=this.original.slice(e,t);Object.defineProperty(this.storedNames,c,{writable:!0,value:!0,enumerable:!0})}let a=this.byStart[e],l=this.byEnd[t];if(a){let c=a;for(;c!==l;){if(c.next!==this.byStart[c.end])throw new Error("Cannot overwrite across a split point");c=c.next,c.edit("",!1)}a.edit(r,o,!s)}else{let c=new J(e,t,"").edit(r,o);l.next=c,c.previous=l}return this}prepend(e){if(typeof e!="string")throw new TypeError("outro content must be a string");return this.intro=e+this.intro,this}prependLeft(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byEnd[e];return r?r.prependLeft(t):this.intro=t+this.intro,this}prependRight(e,t){if(e=e+this.offset,typeof t!="string")throw new TypeError("inserted content must be a string");this._split(e);let r=this.byStart[e];return r?r.prependRight(t):this.outro=t+this.outro,this}remove(e,t){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let r=this.byStart[e];for(;r;)r.intro="",r.outro="",r.edit(""),r=t>r.end?this.byStart[r.end]:null;return this}reset(e,t){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw new Error("Character is out of bounds");if(e>t)throw new Error("end must be greater than start");this._split(e),this._split(t);let r=this.byStart[e];for(;r;)r.reset(),r=t>r.end?this.byStart[r.end]:null;return this}lastChar(){if(this.outro.length)return this.outro[this.outro.length-1];let e=this.lastChunk;do{if(e.outro.length)return e.outro[e.outro.length-1];if(e.content.length)return e.content[e.content.length-1];if(e.intro.length)return e.intro[e.intro.length-1]}while(e=e.previous);return this.intro.length?this.intro[this.intro.length-1]:""}lastLine(){let e=this.outro.lastIndexOf(E);if(e!==-1)return this.outro.substr(e+1);let t=this.outro,r=this.lastChunk;do{if(r.outro.length>0){if(e=r.outro.lastIndexOf(E),e!==-1)return r.outro.substr(e+1)+t;t=r.outro+t}if(r.content.length>0){if(e=r.content.lastIndexOf(E),e!==-1)return r.content.substr(e+1)+t;t=r.content+t}if(r.intro.length>0){if(e=r.intro.lastIndexOf(E),e!==-1)return r.intro.substr(e+1)+t;t=r.intro+t}}while(r=r.previous);return e=this.intro.lastIndexOf(E),e!==-1?this.intro.substr(e+1)+t:this.intro+t}slice(e=0,t=this.original.length-this.offset){if(e=e+this.offset,t=t+this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}let r="",i=this.firstChunk;for(;i&&(i.start>e||i.end<=e);){if(i.start<t&&i.end>=t)return r;i=i.next}if(i&&i.edited&&i.start!==e)throw new Error(`Cannot use replaced character ${e} as slice start anchor.`);let o=i;for(;i;){i.intro&&(o!==i||i.start===e)&&(r+=i.intro);let s=i.start<t&&i.end>=t;if(s&&i.edited&&i.end!==t)throw new Error(`Cannot use replaced character ${t} as slice end anchor.`);let a=o===i?e-i.start:0,l=s?i.content.length+t-i.end:i.content.length;if(r+=i.content.slice(a,l),i.outro&&(!s||i.end===t)&&(r+=i.outro),s)break;i=i.next}return r}snip(e,t){let r=this.clone();return r.remove(0,e),r.remove(t,r.original.length),r}_split(e){if(this.byStart[e]||this.byEnd[e])return;let t=this.lastSearchedChunk,r=t,i=e>t.end;for(;t;){if(t.contains(e))return this._splitChunk(t,e);if(t=i?this.byStart[t.end]:this.byEnd[t.start],t===r)return;r=t}}_splitChunk(e,t){if(e.edited&&e.content.length){let i=ye(this.original)(t);throw new Error(`Cannot split a chunk that has already been edited (${i.line}:${i.column} – "${e.original}")`)}let r=e.split(t);return this.byEnd[t]=e,this.byStart[t]=r,this.byEnd[r.end]=r,e===this.lastChunk&&(this.lastChunk=r),this.lastSearchedChunk=e,!0}toString(){let e=this.intro,t=this.firstChunk;for(;t;)e+=t.toString(),t=t.next;return e+this.outro}isEmpty(){let e=this.firstChunk;do if(e.intro.length&&e.intro.trim()||e.content.length&&e.content.trim()||e.outro.length&&e.outro.trim())return!1;while(e=e.next);return!0}length(){let e=this.firstChunk,t=0;do t+=e.intro.length+e.content.length+e.outro.length;while(e=e.next);return t}trimLines(){return this.trim("[\\r\\n]")}trim(e){return this.trimStart(e).trimEnd(e)}trimEndAborted(e){let t=new RegExp((e||"\\s")+"+$");if(this.outro=this.outro.replace(t,""),this.outro.length)return!0;let r=this.lastChunk;do{let i=r.end,o=r.trimEnd(t);if(r.end!==i&&(this.lastChunk===r&&(this.lastChunk=r.next),this.byEnd[r.end]=r,this.byStart[r.next.start]=r.next,this.byEnd[r.next.end]=r.next),o)return!0;r=r.previous}while(r);return!1}trimEnd(e){return this.trimEndAborted(e),this}trimStartAborted(e){let t=new RegExp("^"+(e||"\\s")+"+");if(this.intro=this.intro.replace(t,""),this.intro.length)return!0;let r=this.firstChunk;do{let i=r.end,o=r.trimStart(t);if(r.end!==i&&(r===this.lastChunk&&(this.lastChunk=r.next),this.byEnd[r.end]=r,this.byStart[r.next.start]=r.next,this.byEnd[r.next.end]=r.next),o)return!0;r=r.next}while(r);return!1}trimStart(e){return this.trimStartAborted(e),this}hasChanged(){return this.original!==this.toString()}_replaceRegexp(e,t){function r(o,s){return typeof t=="string"?t.replace(/\$(\$|&|\d+)/g,(a,l)=>l==="$"?"$":l==="&"?o[0]:+l<o.length?o[+l]:`$${l}`):t(...o,o.index,s,o.groups)}function i(o,s){let a,l=[];for(;a=o.exec(s);)l.push(a);return l}if(e.global)i(e,this.original).forEach(s=>{if(s.index!=null){let a=r(s,this.original);a!==s[0]&&this.overwrite(s.index,s.index+s[0].length,a)}});else{let o=this.original.match(e);if(o&&o.index!=null){let s=r(o,this.original);s!==o[0]&&this.overwrite(o.index,o.index+o[0].length,s)}}return this}_replaceString(e,t){let{original:r}=this,i=r.indexOf(e);return i!==-1&&(typeof t=="function"&&(t=t(e,i,r)),e!==t&&this.overwrite(i,i+e.length,t)),this}replace(e,t){return typeof e=="string"?this._replaceString(e,t):this._replaceRegexp(e,t)}_replaceAllString(e,t){let{original:r}=this,i=e.length;for(let o=r.indexOf(e);o!==-1;o=r.indexOf(e,o+i)){let s=r.slice(o,o+i),a=t;typeof t=="function"&&(a=t(s,o,r)),s!==a&&this.overwrite(o,o+i,a)}return this}replaceAll(e,t){if(typeof e=="string")return this._replaceAllString(e,t);if(!e.global)throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");return this._replaceRegexp(e,t)}};function rt(n){switch(n.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return n.reactive?"reactive-prop":n.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function w(n){let e=[],t=new Map,r=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let o of i.children)r(o);return!1;case"fragment":for(let o of i.children)r(o);return!1;case"element":{let o=!0;for(let a of i.children)r(a)||(o=!1);let s;for(let a of i.props)if(s=rt(a),s)break;return!s&&!o&&(s=it(i)),i.static=!s,s?t.set(i,s):e.push(i),i.static}default:return!1}};for(let i of Array.isArray(n)?n:[n])r(i);return{staticElements:e,reasons:t}}function it(n){for(let e of n.children){if(e.kind==="expr")return"expression-child";if(e.kind==="component")return"component-child";if(e.kind==="control")return"control-child";if(e.kind==="element"&&!e.static||e.kind==="fragment")return"expression-child"}return"expression-child"}var F={kind:"eager"},ot=["pointerdown","focusin","keydown"],be=new Set(["eager","idle","visible","interaction","media","never"]),v=class extends Error{};function te(n){return n.startsWith("load:")}function H(n,e){let t=n.slice(5);if(!be.has(t))throw new v(`Unknown load strategy 'load:${t}'. Expected one of ${[...be].join(", ")}.`);switch(t){case"eager":return F;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return e?{kind:"visible",rootMargin:e}:{kind:"visible"};case"interaction":return{kind:"interaction",events:e?st(e):[...ot]};case"media":if(!e)throw new v(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:e};default:throw new v(`Unhandled load strategy '${t}'.`)}}function st(n){let e=n.split(/[\s,]+/).map(t=>t.trim()).filter(Boolean);if(e.length===0)throw new v("'load:interaction' was given no event names.");return e}function q(n){return n.kind!=="eager"&&n.kind!=="never"}var I=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],T=["Suspense","SuspenseList","Await"],S=["Router","Outlet","Redirect","Link"],rn=[...I,...T,...S],ne=new Set([...I,...T]);function Re(n={}){let{controlFlowModule:e="@fluixi/dom",coreModule:t="@fluixi/core",routerModule:r="@fluixi/core/router-next"}=n,i={};for(let o of I)i[o]=e;for(let o of T)i[o]=t;for(let o of S)i[o]=r;return i}function U(n,e={}){let{resolver:t,isBound:r,modules:i,strategyFor:o}=e,s=Re(i),a=new Map,l=new Set,c=p=>{let{name:d}=p;if(!d||d.includes(".")||r?.(d))return;let h=u(d);if(!h){l.add(d);return}let m=h.origin==="builtin"&&ne.has(d)?F:o?.(p)??F;p.source={...h,loading:m},a.set(d,p.source)},u=p=>{if(ne.has(p))return{module:s[p],export:p,origin:"builtin"};let d=t?.resolve(p);if(d)return{module:d.module,export:d.export,origin:"rule"};if(S.includes(p))return{module:s[p],export:p,origin:"builtin"}};return X(n,p=>{p.kind==="component"&&c(p)}),{resolved:a,unresolved:[...l]}}function X(n,e){let t=Array.isArray(n)?n:[n];for(let r of t){e(r);let i=r.children;i&&X(i,e)}}function z(n){let e=[];X(n,o=>{o.kind==="component"&&o.source&&e.push(o)});let t=new Set,r=new Set;for(let o of e){let{module:s,loading:a}=o.source;a.kind==="eager"&&t.add(s),a.kind==="never"&&r.add(s)}let i=new Map;for(let o of e){let s=o.source;q(s.loading)&&t.has(s.module)&&(s.loading={kind:"eager"},i.set(s.module,(i.get(s.module)??0)+1))}return{collapsed:i,conflicted:[...r].filter(o=>t.has(o))}}var at=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),we={className:"class",htmlFor:"for"},lt=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),ct=new Set(["script","style","textarea","title"]);function re(n){return ct.has(n)}function Se(n){return we[n]??n}function $(n){return n.kind!=="attr"||n.expr!==void 0||n.name.includes(":")?!1:!lt.has(n.name)}function ie(n){if(!n.static||re(n.tag))return!1;for(let e of n.props)if(!$(e))return!1;for(let e of n.children)if(e.kind!=="text"&&!(e.kind==="element"&&ie(e)))return!1;return!0}function O(n){let e=n.props.map(dt).filter(Boolean).join(""),t=`<${n.tag}${e}>`;return at.has(n.tag)?t:`${t}${n.children.map(ut).join("")}</${n.tag}>`}function ut(n){if(n.kind==="text")return ft(n.value);if(n.kind!=="element")throw new Error(`serializeStatic: unexpected ${n.kind}`);return O(n)}function dt(n){let e=we[n.name]??n.name,t=n.literal;return t===!0||t===void 0?` ${e}`:t===!1||t===null?"":` ${e}="${pt(String(t))}"`}function pt(n){return n.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ft(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var ht="<!--fx-->",mt="<!--fx/-->";function G(n){return n.kind==="expr"||n.kind==="component"||n.kind==="control"}function gt(n){return n.kind==="text"||n.kind==="element"&&Ce(n)}function Ce(n){return n.svg||re(n.tag)||!n.props.every(e=>$(e))?!1:n.children.every(e=>gt(e)||G(e))}function W(n){if(G(n))return!0;let e=n.children;return e?e.some(W):!1}function ke(n){for(let e=0;e<n.children.length;e++){let t=n.children[e];if(t.kind==="text"&&(t.value===""||n.children[e+1]?.kind==="text"))return!1}return n.children.every(e=>e.kind!=="element"||ke(e))}function Ne(n){if(!Ce(n)||!ke(n)||!n.children.some(W))return null;let e=[],t=[],r=0,i=s=>{let a=`_n$${r++}`;return e.push({ref:a,expr:s}),a};return o(n,"_el$"),{html:vt(n),tag:n.tag,steps:e,holes:t};function o(s,a){let l=-1;s.children.forEach((u,p)=>{W(u)&&(l=p)});let c=null;for(let u=0;u<=l;u++){let p=s.children[u],d=c?`${c}.nextSibling`:`${a}.firstChild`;if(G(p)){let m=i(d),_=i(`holeEnd(${m})`);t.push({parentRef:a,startRef:m,endRef:_,node:p}),c=_;continue}let h=i(d);p.kind==="element"&&W(p)&&o(p,h),c=h}}}function vt(n){return O(Ee(n)).split(Ie).join(ht+mt)}function Ee(n){return{...n,children:n.children.map(e=>G(e)?{kind:"text",value:Ie}:e.kind==="element"?Ee(e):e)}}var Ie="\0fx-hole\0";var oe={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},mn={version:2,module:"@fluixi/dom",symbols:[...oe.symbols,"template","cloneTemplate","walk"]};var xt={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function yt(n){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n)}function $e(n){return yt(n)?n:JSON.stringify(n)}function bt(n){return n.expr!==void 0?n.reactive?`() => (${n.expr})`:`(${n.expr})`:JSON.stringify(n.literal??!0)}function Rt(n){return n.expr!==void 0?`(${n.expr})`:JSON.stringify(n.literal??!0)}function wt(n,e,t){let r=n.filter(a=>a.kind==="spread"),o=n.filter(a=>a.kind!=="spread").map(a=>`${$e(a.name)}: ${bt(a)}`);e!=null&&o.push(`children: ${e}`);let s=`{ ${o.join(", ")} }`;return r.length>0?(t.add("mergeProps"),`mergeProps(${r.map(a=>a.expr).join(", ")}, ${s})`):s}function Oe(n,e,t){return n.length===1?L(n[0],e,t):`[${n.map(r=>L(r,e,t)).join(", ")}]`}function Te(n,e,t,r,i){r.add("createMemo"),r.add("createComponent");let o=e.filter(c=>c.kind==="spread"),a=e.filter(c=>c.kind!=="spread").map(c=>`get ${$e(c.name)}() { return ${Rt(c)}; }`);t.length>0&&a.push(`get children() { return ${Oe(t,r,i)}; }`);let l=`{ ${a.join(", ")} }`;return o.length>0&&(r.add("mergeProps"),l=`mergeProps(${o.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${n}, ${l}))`}function St(n,e){let t=Se(e.name),r=e.literal;return r===!0||r===void 0?`${n}.setAttribute(${JSON.stringify(t)}, "");`:r===!1||r===null?"":`${n}.setAttribute(${JSON.stringify(t)}, ${JSON.stringify(String(r))});`}var Le=!1;function L(n,e,t){switch(n.kind){case"text":return JSON.stringify(n.value);case"expr":return n.reactive?`() => (${n.code})`:`(${n.code})`;case"fragment":return n.children.length===0?"null":Oe(n.children,e,t);case"component":return Te(n.name,n.props,n.children,e,t);case"control":{let r=xt[n.control]??n.control;return e.add(r),Te(r,n.props,n.children,e,t)}case"element":{if(t&&n.static&&!n.svg&&ie(n)){e.add("templateNode");let a=`_tmpl$${t.length}`;return t.push({id:a,html:O(n),tag:n.tag,svg:!1}),`templateNode(${a}, ${JSON.stringify(n.tag)})`}if(t&&Le){let a=Ne(n);if(a){e.add("templateNode"),e.add("insert"),e.add("holeEnd"),e.add("holeContent"),e.add("holeScope");let l=`_tmpl$${t.length}`;t.push({id:l,html:a.html,tag:a.tag,svg:!1});let c=[`const _el$ = templateNode(${l}, ${JSON.stringify(a.tag)}, true);`];for(let u of a.steps)c.push(`const ${u.ref} = ${u.expr};`);for(let u of a.holes)c.push(`insert(${u.parentRef}, holeScope(${u.startRef}, () => (${L(u.node,e,t)})), ${u.endRef}, holeContent(${u.startRef}, ${u.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}e.add("createNativeElement");let r=JSON.stringify(n.tag),i="_el$",o=[],s=n.svg?`${r}, true`:r;if(o.push(`const ${i} = createNativeElement(${s});`),n.props.length>0)if(!n.svg&&n.props.every($))for(let a of n.props)o.push(St(i,a));else{e.add("spread");let a=n.svg?", isSVG: true":"";o.push(`spread({ element: ${i}, props: ${wt(n.props,null,e)}${a} });`)}for(let a of n.children){e.add("insert");let l=L(a,e,t),c=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";o.push(c?`insert(${i}, ${l}, null);`:`insert(${i}, ${l});`)}return o.push(`return ${i};`),`(() => { ${o.join(" ")} })()`}}}function V(n,e){if(!e||e.length===0)return n;let t=new Map(e.map(r=>[r.id,JSON.stringify(r.html)]));return n.replace(/_tmpl\$\d+/g,r=>t.get(r)??r)}var C={name:"imperative",contract:oe,emit(n,e){let t=new Set,r=e?.templateClone!==!1?[]:void 0;return Le=e?.partialTemplates===!0,{code:L(n,t,r),imports:Array.from(t),templates:r}}};var Ct=n=>"components"in n;function Me(n,e){return n.replace(/\$(\d+)/g,(t,r)=>e[Number(r)]??t)}function kt(n,e){return typeof e=="string"?{module:e,export:n}:e}function K(n=[]){let e=new Map,t=[],r=[];for(let s of n){if(!Ct(s)){r.push(s);continue}for(let[a,l]of Object.entries(s.components)){let c=kt(a,l),u=e.get(a);if(u&&u.module!==c.module){let p=t.find(d=>d.name===a);p?p.modules.push(c.module):t.push({name:a,modules:[u.module,c.module]});continue}e.set(a,c)}}let i=new Map;return{resolve:s=>{if(i.has(s))return i.get(s);let a=e.get(s);if(!a)for(let l of r){let c=s.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){a={module:Me(l.module,c),export:l.export?Me(l.export,c):s};break}}return i.set(s,a),a},names:()=>[...e.keys()],conflicts:()=>t}}import{parseTemplate as Nt}from"@fluixi/template-parser";function M(n){let e=n.split(/\r\n|\n|\r/),t=0;for(let i=0;i<e.length;i++)/[^ \t]/.test(e[i])&&(t=i);let r="";for(let i=0;i<e.length;i++){let o=e[i].replace(/\t/g," ");i!==0&&(o=o.replace(/^ +/,"")),i!==e.length-1&&(o=o.replace(/ +$/,"")),o&&(i!==t&&(o+=" "),r+=o)}return r}var Pe=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function Et(n){return n.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function Ae(n){return n.charAt(0).toUpperCase()+n.slice(1)}var se=class{constructor(e,t){this.holes=e;this.used=t}hole(e){return this.holes[e]??{code:"undefined",reactive:!1}}emit(e){let{code:t,imports:r,templates:i}=C.emit(e,{});for(let o of r)this.used.add(o);return V(t,i)}lowerRoot(e){let t=this.lowerChildren(e);return t.length===1?t[0]:{kind:"fragment",children:t}}lowerChildren(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.kind==="Element"||i.kind==="Component"){let s=i.attributes.find(a=>a.kind==="IfDirective");if(s&&s.kind==="IfDirective"){let a=r+1;a<e.length&&this.isBlankText(e[a])&&a++;let l=e[a],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(u=>u.kind==="ElseDirective");t.push(this.lowerIf(i,s.hole,c?l:null)),c&&(r=a);continue}if(i.attributes.some(a=>a.kind==="EachDirective")){t.push(this.lowerEach(i));continue}}let o=this.lowerNode(i);o&&t.push(o)}return t}isBlankText(e){return e.kind==="Text"&&!e.raw&&M(e.value)===""}lowerNode(e){switch(e.kind){case"Text":{if(e.raw)return{kind:"text",value:e.value};let t=M(e.value);return t?{kind:"text",value:t}:null}case"Comment":return null;case"Expression":{let t=this.hole(e.hole);return{kind:"expr",code:t.code,reactive:t.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(e.children)};case"Element":return this.lowerElement(e);case"Component":return this.lowerComponent(e);default:return null}}lowerElement(e){let t=e.attributes.find(r=>r.kind==="Attribute"&&r.name==="is");if(e.tag==="component"&&t&&t.value&&t.value.kind==="hole"){let r=e.attributes.filter(o=>o!==t),i=this.lowerComponent({...e,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return i.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(t.value.hole).code})`}),i}return{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:this.lowerAttributes(e.attributes),children:this.lowerChildren(e.children),static:!1}}lowerComponent(e){let t=e.tagHole!=null?this.hole(e.tagHole).code:e.tag,r=this.lowerAttributes(e.attributes),{slots:i,rest:o}=this.partitionSlots(e.children);for(let[l,c]of i){let u=c.length===1?c[0]:{kind:"fragment",children:c},p={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},d=r.findIndex(h=>h.name===l);d>=0?r[d]=p:r.push(p)}let s=e.attributes.find(l=>l.kind==="LoadDirective"),a=s?H(`load:${s.strategy}`,s.modifier):void 0;return{kind:"component",name:t,props:r,children:this.lowerChildren(o),...a?{load:a}:{}}}partitionSlots(e){let t=new Map,r=[];for(let i of e){if(i.kind==="Element"||i.kind==="Component"){let o=i.attributes.find(s=>s.kind==="Attribute"&&s.name==="slot");if(o&&o.value&&o.value.kind==="static"){let s={...i,attributes:i.attributes.filter(c=>c!==o)},a=s.kind==="Element"?this.lowerElement(s):this.lowerComponent(s),l=t.get(o.value.value)??[];l.push(a),t.set(o.value.value,l);continue}}r.push(i)}return{slots:t,rest:r}}lowerIf(e,t,r){let i=this.hole(t),o=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive}];if(r){let a=this.stripAndLower(r,l=>l.kind==="ElseDirective");o.push({name:"fallback",kind:"attr",expr:this.emit(a),jsxElement:!0})}let s=this.stripAndLower(e,a=>a.kind==="IfDirective");return{kind:"component",name:"Show",props:o,children:[s]}}lowerEach(e){let t=e.attributes.find(l=>l.kind==="EachDirective");if(!t||t.kind!=="EachDirective")return this.lowerNode(e);let r=this.hole(t.hole),i=[{name:"each",kind:"attr",expr:r.code,reactive:r.reactive}];if(t.key){let l="static"in t.key?`(item) => item[${JSON.stringify(t.key.static)}]`:this.hole(t.key.hole).code;i.push({name:"by",kind:"attr",expr:l})}let o=this.itemArrow(e),s;if(o){let l={kind:"expr",code:o.body,reactive:o.bodyReactive},c=this.rebuildWithChildren(e,[l]);s=`(${o.params.join(", ")}) => (${this.emit(c)})`}else{let l=this.stripAndLower(e,c=>c.kind==="EachDirective");s=`() => (${this.emit(l)})`}return{kind:"component",name:"For",props:i,children:[{kind:"expr",code:s,reactive:!1}]}}itemArrow(e){let t=e.children.filter(r=>!this.isBlankText(r));return t.length!==1||t[0].kind!=="Expression"?null:this.hole(t[0].hole).arrow??null}stripAndLower(e,t){let r={...e,attributes:e.attributes.filter(i=>!t(i))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(e,t){let r=this.lowerAttributes(e.attributes.filter(i=>i.kind!=="EachDirective"));return e.kind==="Element"?{kind:"element",tag:e.tag,svg:e.namespace==="svg",props:r,children:t,static:!1}:{kind:"component",name:e.tag,props:r,children:t}}lowerAttributes(e){let t=[],r=[],i=!1,o=[],s=!1,a=[];for(let l of e)switch(l.kind){case"IfDirective":case"EachDirective":case"ElseDirective":break;case"Attribute":t.push(this.plainAttr(l));break;case"PropertyBinding":t.push({name:l.name,kind:"prop",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"EventBinding":t.push(this.eventProp(l));break;case"RefBinding":t.push({name:"ref",kind:"ref",expr:this.hole(l.hole).code,reactive:this.hole(l.hole).reactive});break;case"Spread":t.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let c=this.hole(l.hole);r.push(`${JSON.stringify(l.name)}: ${c.code}`),i=i||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);o.push(`${JSON.stringify(l.name)}: ${c.code}`),s=s||c.reactive;break}case"BindDirective":t.push(...this.bindProps(l.name,this.hole(l.hole).code));break;case"UseDirective":{let c=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!c)break;a.push(l.name!=null&&l.hole!=null?`[${c}, () => (${this.hole(l.hole).code})]`:`[${c}]`);break}}return r.length>0&&t.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:i}),o.length>0&&t.push({name:"style",kind:"attr",expr:`{ ${o.join(", ")} }`,reactive:s}),a.length>0&&t.push({name:"use",kind:"attr",expr:`[${a.join(", ")}]`}),t}eventProp(e){let t=e.name.toLowerCase(),r=this.hole(e.hole).code;if(!(e.syntax==="colon"||e.modifiers.length>0))return{name:"on"+Ae(e.name),kind:"event",event:{name:t,delegated:Pe.has(t)},expr:r};let o=this.wrapHandler(r,e.modifiers),s=this.eventOptions(e.modifiers),a=s?`[${o}, ${s}]`:o;return{name:"on:"+t,kind:"attr",expr:a}}wrapHandler(e,t){let r=t.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return t.includes("prevent")&&i.push("e.preventDefault();"),t.includes("stop")&&i.push("e.stopPropagation();"),!r&&i.length===0?e:`(e) => { ${r}${i.join(" ")} return (${e})(e); }`}eventOptions(e){let t=[];return e.includes("capture")&&t.push("capture: true"),e.includes("once")&&t.push("once: true"),e.includes("passive")&&t.push("passive: true"),t.length?`{ ${t.join(", ")} }`:null}bindProps(e,t){let r=e==="checked",i=r?"change":"input",o=r?"checked":"value",s=`(${t})`;return[{name:e,kind:"attr",expr:`${s}[0]()`,reactive:!0},{name:"on"+Ae(i),kind:"event",event:{name:i,delegated:Pe.has(i)},expr:`(e) => ${s}[1](e.target.${o})`}]}plainAttr(e){let t=e.value,r=e.name;e.name==="class"?r=t&&t.kind==="hole"&&this.hole(t.hole).object?"classList":"className":e.name==="html"&&(r="innerHTML");let o={name:r,kind:"attr"};if(t==null)return o.literal=!0,o;if(t.kind==="static")return o.literal=t.value,o;if(t.kind==="hole"){let l=this.hole(t.hole);return o.expr=l.code,o.reactive=l.reactive,o}let s=!1,a=t.parts.map(l=>{if("text"in l)return Et(l.text);let c=this.hole(l.hole);return s=s||c.reactive,"${"+c.code+"}"}).join("");return o.expr="`"+a+"`",o.reactive=s,o}};function _e(n,e,t,r={}){let{root:i}=Nt(n,{svg:r.svg});return new se(e,t).lowerRoot(i.children)}function je(n,e,t={}){let r=new Set,i=_e(n,[...e],r,{svg:t.svg});w(i),U(i,{resolver:K(t.resolve??[]),modules:{controlFlowModule:t.controlFlowModule??"@fluixi/dom",coreModule:t.coreModule??"@fluixi/core",routerModule:t.routerModule??"@fluixi/core/router-next"},strategyFor:l=>l.load}),z(i);let{code:o,imports:s,templates:a}=C.emit(i,{templateClone:t.templateClone,partialTemplates:t.partialTemplates});for(let l of s)r.add(l);return t.hoistTemplates?{code:o,imports:[...r],ir:i,templates:a}:{code:V(o,a),imports:[...r],ir:i}}var It="children";function k(n){switch(n.kind){case"call":return!0;case"member":return n.property!==It;case"compound":return n.parts.some(k);case"opaque":return!1}}var Tt=new Set(["CallExpression","OptionalCallExpression"]),$t=new Set(["MemberExpression","OptionalMemberExpression"]);function b(n){if(!n)return{kind:"opaque"};if(Tt.has(n.type))return{kind:"call"};if($t.has(n.type)){let e=n.property;return{kind:"member",property:!(n.computed===!0)&&e?.type==="Identifier"?e.name:null}}return n.type==="ConditionalExpression"?{kind:"compound",parts:[n.test,n.consequent,n.alternate].map(P)}:n.type==="LogicalExpression"||n.type==="BinaryExpression"?{kind:"compound",parts:[n.left,n.right].map(P)}:n.type==="TemplateLiteral"?{kind:"compound",parts:n.expressions.map(P)}:n.type==="ObjectExpression"?{kind:"compound",parts:n.properties.filter(t=>(t.type==="ObjectProperty"||t.type==="Property")&&t.computed!==!0).map(t=>P(t.value))}:n.type==="ArrayExpression"?{kind:"compound",parts:n.elements.filter(t=>t!=null&&t.type!=="SpreadElement").map(P)}:{kind:"opaque"}}var P=n=>b(n);var Ot=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),Lt=/^on[A-Z]/,Mt=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),Be=n=>k(b(n));function A(n){if(n.type==="StringLiteral"||n.type==="NumericLiteral"||n.type==="BooleanLiteral"||n.type==="Literal"&&(typeof n.value=="string"||typeof n.value=="number"||typeof n.value=="boolean"))return n.value}var ae=n=>!!n&&typeof A(n)=="string";function Pt(n,e){return n.type==="JSXIdentifier"?{tag:n.name,component:n.name[0]!==n.name[0].toLowerCase()}:n.type==="JSXMemberExpression"?{tag:e.code(n),component:!0}:n.type==="JSXNamespacedName"?{tag:`${n.namespace.name}:${n.name.name}`,component:!1}:{tag:"div",component:!1}}function le(n){return n.type==="JSXIdentifier"?n.name==="class"?"className":n.name:n.type==="JSXNamespacedName"?`${n.namespace.name}:${n.name.name}`:"unknown"}function At(n,e){let t=le(n.name),r=Lt.test(t),i=r||t.startsWith("on:")||t==="ref",s={name:t,kind:r?"event":"attr"};if(r){let l=t.slice(2).toLowerCase();s.event={name:l,delegated:Mt.has(l)}}let a=n.value;if(a==null)return s.literal=!0,s;if(ae(a))return s.literal=A(a),s;if(a.type==="JSXExpressionContainer"&&a.expression?.type!=="JSXEmptyExpression"){let l=a.expression,c=A(l);return c!==void 0?(s.literal=c,s):(s.expr=e.code(l),s.reactive=i?!1:Be(l),(l.type==="JSXElement"||l.type==="JSXFragment")&&(s.jsxElement=!0),s)}return s.literal=!0,s}function De(n,e){let t=n.value;return t==null?null:ae(t)?JSON.stringify(A(t)):t.type==="JSXExpressionContainer"&&t.expression?.type!=="JSXEmptyExpression"?e.code(t.expression):null}function _t(n,e){let t=[],r=[];for(let i of n){if(i.type==="JSXSpreadAttribute"){t.push({name:"",kind:"spread",expr:e.code(i.argument)});continue}if(i.type!=="JSXAttribute"||te(le(i.name)))continue;let o=i.name.type==="JSXNamespacedName"?i.name.namespace.name:null;if(o==="use"){let s=i.name.name.name;e.used.add(s);let a=De(i,e);r.push(a!=null?`[${s}, () => (${a})]`:`[${s}]`);continue}if(o==="oncapture"){let s=i.name.name.name.toLowerCase(),a=De(i,e)??"undefined";t.push({name:"on:"+s,kind:"attr",expr:`[${a}, { capture: true }]`});continue}t.push(At(i,e))}return r.length>0&&t.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),t}function Je(n,e){let t=[];for(let r of n)if(r.type==="JSXText"){let i=M(r.value);i&&t.push({kind:"text",value:i})}else if(r.type==="JSXExpressionContainer"){if(r.expression?.type!=="JSXEmptyExpression"){let i=r.expression;t.push({kind:"expr",code:e.code(i),reactive:Be(i)})}}else r.type==="JSXElement"||r.type==="JSXFragment"?t.push(Fe(r,e)):r.type==="JSXSpreadChild"&&t.push({kind:"expr",code:e.code(r.expression),reactive:!1});return t}function jt(n){for(let e of n){if(e.type!=="JSXAttribute")continue;let t=le(e.name);if(te(t)){if(e.value&&!ae(e.value))throw new v(`'${t}' needs a literal value, not an expression — the strategy is compile-time.`);return H(t,e.value?A(e.value):null)}}}function Fe(n,e){if(n.type==="JSXFragment")return{kind:"fragment",children:Je(n.children,e)};let{tag:t,component:r}=Pt(n.openingElement.name,e),i=_t(n.openingElement.attributes,e),o=Je(n.children,e);if(r){let s=jt(n.openingElement.attributes);return{kind:"component",name:t,props:i,children:o,...s?{load:s}:{}}}return{kind:"element",tag:t,svg:Ot.has(t),props:i,children:o,static:!1}}function He(n,e){let t=Fe(n,e);return w(t),t}function x(n,e){if(n)switch(n.type){case"Identifier":e.add(n.name);return;case"ObjectPattern":for(let t of n.properties)t.type==="RestElement"?x(t.argument,e):x(t.value,e);return;case"ArrayPattern":for(let t of n.elements)x(t,e);return;case"AssignmentPattern":x(n.left,e);return;case"RestElement":x(n.argument,e);return}}function qe(n,e){switch(n.type){case"ImportDeclaration":for(let t of n.specifiers)x(t.local,e);return;case"VariableDeclaration":for(let t of n.declarations)x(t.id,e);return;case"FunctionDeclaration":case"ClassDeclaration":x(n.id,e);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":n.declaration&&qe(n.declaration,e);return}}function ce(n){let e=new Set;for(let t of n.body)qe(t,e);return e}var Jt=new Set(I),Bt=new Set(T),Ft=new Set(S),Ht=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]);function ue(n,e,t=null,r=""){if(!(!n||typeof n!="object")){if(Array.isArray(n)){for(let i of n)ue(i,e,t,r);return}typeof n.type=="string"&&e(n,t,r);for(let i of Object.keys(n))i==="loc"||i==="leadingComments"||i==="trailingComments"||ue(n[i],e,typeof n.type=="string"?n:t,i)}}var de=n=>n.type==="JSXElement"||n.type==="JSXFragment";function qt(n,e,t){return de(n)?!(e&&de(e)&&t==="children"):!1}function Ut(n,e){return n.type==="TaggedTemplateExpression"&&n.tag?.type==="Identifier"&&(n.tag.name===e||n.tag.name==="svg")}function Ue(n){return n.filter(e=>!n.some(t=>t!==e&&t.start<=e.start&&t.end>=e.end&&t.end-t.start>e.end-e.start))}function Y(n,e,t,r){let i=Ue(r.filter(s=>s.start>=e&&s.end<=t)).sort((s,a)=>a.start-s.start),o=n.slice(e,t);for(let s of i)o=o.slice(0,s.start-e)+s.code+o.slice(s.end-e);return o}function Xt(n,e,t){let r={code:Y(n,e.start,e.end,t),reactive:k(b(e))};return e.type==="ArrowFunctionExpression"&&e.body?.type!=="BlockStatement"&&(r.arrow={params:e.params.map(i=>Y(n,i.start,i.end,t)),body:Y(n,e.body.start,e.body.end,t),bodyReactive:k(b(e.body))}),e.type==="ObjectExpression"&&(r.object=!0),r}function Xe(n,e,t){if(!e||e.length===0)return n;let r=new Map;for(let i of e){let o=`${i.svg?"svg:":""}${i.html}`,s=t.get(o);s||(s=`_fxTmpl$${t.size}`,t.set(o,s)),r.set(i.id,s)}return n.replace(/_tmpl\$\d+/g,i=>r.get(i)??i)}function pe(n,e){if(n.kind==="component"&&n.source){let t=n.source;t.origin==="builtin"?e.builtins.add(n.name):q(t.loading)&&!e.resolved.has(n.name)?e.deferred.set(n.name,t):(e.deferred.delete(n.name),e.resolved.set(n.name,t))}if("props"in n&&n.props)for(let t of n.props)t.kind==="event"&&t.event?.delegated&&e.delegatedEvents.add(t.event.name);if("children"in n&&n.children)for(let t of n.children)pe(t,e)}function zt(n){let e=[`kind: ${JSON.stringify(n.kind)}`];return n.kind==="visible"&&n.rootMargin&&e.push(`rootMargin: ${JSON.stringify(n.rootMargin)}`),n.kind==="interaction"&&e.push(`events: ${JSON.stringify(n.events)}`),n.kind==="media"&&e.push(`query: ${JSON.stringify(n.query)}`),`{ ${e.join(", ")} }`}function Wt(n){let e=[];return n.quasi.quasis.forEach((t,r)=>{if(e.push({kind:"static",text:t.value.cooked??t.value.raw,start:t.start}),r<n.quasi.expressions.length){let i=n.quasi.expressions[r];e.push({kind:"hole",index:r,start:i.start,end:i.end})}}),e}function Gt(n,e,t={}){let r=t.litTag??"html",i=t.format??"both",o=i!=="jsx",s=i!=="lit";if(!(o&&(n.includes(`${r}\``)||n.includes("svg`")))&&!(s&&n.includes("<")))return null;let l=Dt(n,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),c=[];if(ue(l.program,(f,y,Z)=>{(o&&Ut(f,r)||s&&qt(f,y,Z))&&c.push(f)}),c.length===0)return null;c.sort((f,y)=>y.start-f.start||f.end-y.end);let u=new Set,p={builtins:new Set,resolved:new Map,deferred:new Map,delegatedEvents:new Set},d=new Map,h=[];for(let f of c){let y=c.some(g=>g!==f&&g.start<=f.start&&g.end>=f.end&&g.end-g.start>f.end-f.start);if(de(f)){h.push({start:f.start,end:f.end,code:Vt(n,f,h,y,u,p,d,t)});continue}let Z=f.quasi.expressions.map(g=>Xt(n,g,h)),j=je(Wt(f),Z,{...t,hoistTemplates:!0,templateClone:t.templateClone??!0,partialTemplates:y?!1:t.partialTemplates??!0,svg:f.tag.name==="svg"});for(let g of j.imports)u.add(g);pe(j.ir,p),h.push({start:f.start,end:f.end,code:Xe(j.code,j.templates,d)})}let m=new B(n);for(let f of Ue(h))m.overwrite(f.start,f.end,f.code);let _=ce(l.program),fe=Kt(u,p,d,_,t);fe&&m.prepend(fe);for(let f of l.program.body)f.type==="ImportDeclaration"&&f.source?.value==="@fluixi/core/rx"&&m.overwrite(f.source.start,f.source.end,JSON.stringify("@fluixi/reactive"));return{code:m.toString(),map:m.generateMap({source:e,includeContent:!0,hires:!0})}}function Vt(n,e,t,r,i,o,s,a){let l=He(e,{code:u=>Y(n,u.start,u.end,t),used:i});w(l),U(l,{resolver:K(a.resolve??[]),modules:{controlFlowModule:a.controlFlowModule??a.runtimeModule??"@fluixi/dom",coreModule:a.coreModule??"@fluixi/core",routerModule:a.routerModule??"@fluixi/core/router-next"},strategyFor:u=>u.load}),z(l);let c=C.emit(l,{templateClone:a.templateClone??!0,partialTemplates:r?!1:a.partialTemplates??!0});for(let u of c.imports)i.add(u);return pe(l,o),Xe(c.code,c.templates,s)}function Kt(n,e,t,r,i){let o=i.runtimeModule??"@fluixi/dom",s=i.coreModule??"@fluixi/core",a=new Map,l=(d,h)=>a.set(d,[...a.get(d)??[],h]),c=new Set(n);for(let d of e.builtins)c.add(d);e.delegatedEvents.size>0&&c.add("delegateEvents");for(let d of[...c].sort())r.has(d)||(Ht.has(d)?l(i.reactiveModule??"@fluixi/reactive/signal",d):Ft.has(d)?l(i.routerModule??"@fluixi/core/router-next",d):Bt.has(d)?l(s,d):Jt.has(d)?l(i.controlFlowModule??o,d):l(o,d));for(let[d,h]of e.resolved)r.has(d)||l(h.module,h.export==="default"?`default as ${d}`:d===h.export?d:`${h.export} as ${d}`);let u=[];for(let[d,h]of a)u.push(`import { ${h.join(", ")} } from ${JSON.stringify(d)};`);let p=[...e.deferred].filter(([d])=>!r.has(d));if(p.length>0){r.has("deferred")||u.push(`import { deferred } from ${JSON.stringify(s)};`);for(let[d,h]of p)u.push(`const ${d} = deferred(() => import(${JSON.stringify(h.module)}), { strategy: ${zt(h.loading)}, export: ${JSON.stringify(h.export)} });`)}for(let[d,h]of t)u.push(`const ${h} = ${JSON.stringify(d.startsWith("svg:")?d.slice(4):d)};`);return e.delegatedEvents.size>0&&u.push(`delegateEvents(${JSON.stringify([...e.delegatedEvents])});`),u.length>0?u.join(`
11
+ `)+`
12
+ `:null}export{ce as moduleBindings,b as shapeOf,Gt as transformTemplates};
@@ -0,0 +1 @@
1
+ "use strict";var g=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var h=(r,n)=>{for(var t in n)g(r,t,{get:n[t],enumerable:!0})},l=(r,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of u(n))!c.call(r,e)&&e!==t&&g(r,e,{get:()=>n[e],enumerable:!(i=s(n,e))||i.enumerable});return r};var d=r=>l(g({},"__esModule",{value:!0}),r);var a={};h(a,{hash:()=>o,serverFnId:()=>f});module.exports=d(a);function o(r){let n=5381;for(let t=0;t<r.length;t++)n=n*33^r.charCodeAt(t);return(n>>>0).toString(16)}function f(r,n,t){let i=(r||"unknown").replace(n?n+"/":"","");return`${o(i)}:${t}`}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The id a server function is registered and called by.
3
+ *
4
+ * Client stub and server registration are produced by separate builds of the
5
+ * same file, so this has to agree across them exactly — same hash, same
6
+ * relative path, same index. Shared rather than duplicated for that reason.
7
+ */
8
+ export declare function hash(s: string): string;
9
+ export declare function serverFnId(filename: string, root: string | undefined, index: number): string;
10
+ //# sourceMappingURL=server-fn-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-fn-id.d.ts","sourceRoot":"","sources":["../../src/transform/server-fn-id.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAItC;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG5F"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The id a server function is registered and called by.
3
+ *
4
+ * Client stub and server registration are produced by separate builds of the
5
+ * same file, so this has to agree across them exactly — same hash, same
6
+ * relative path, same index. Shared rather than duplicated for that reason.
7
+ */
8
+ // djb2 — tiny, stable, dependency-free. Hex, so the id is a valid identifier suffix.
9
+ export function hash(s) {
10
+ let h = 5381;
11
+ for (let i = 0; i < s.length; i++)
12
+ h = (h * 33) ^ s.charCodeAt(i);
13
+ return (h >>> 0).toString(16);
14
+ }
15
+ export function serverFnId(filename, root, index) {
16
+ const rel = (filename || 'unknown').replace(root ? root + '/' : '', '');
17
+ return `${hash(rel)}:${index}`;
18
+ }
@@ -0,0 +1 @@
1
+ function i(t){let n=5381;for(let r=0;r<t.length;r++)n=n*33^t.charCodeAt(r);return(n>>>0).toString(16)}function g(t,n,r){let e=(t||"unknown").replace(n?n+"/":"","");return`${i(e)}:${r}`}export{i as hash,g as serverFnId};
@@ -0,0 +1,2 @@
1
+ "use strict";var N=Object.create;var u=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var b=(e,r)=>{for(var t in r)u(e,t,{get:r[t],enumerable:!0})},p=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of $(r))!F.call(e,n)&&n!==t&&u(e,n,{get:()=>r[n],enumerable:!(i=S(r,n))||i.enumerable});return e};var x=(e,r,t)=>(t=e!=null?N(h(e)):{},p(r||!e||!e.__esModule?u(t,"default",{value:e,enumerable:!0}):t,e)),O=e=>p(u({},"__esModule",{value:!0}),e);var E={};b(E,{transformServerFns:()=>C});module.exports=O(E);var m=require("@babel/parser"),y=x(require("magic-string"),1);function M(e){let r=5381;for(let t=0;t<e.length;t++)r=r*33^e.charCodeAt(t);return(r>>>0).toString(16)}function g(e,r,t){let i=(e||"unknown").replace(r?r+"/":"","");return`${M(i)}:${t}`}var A="@fluixi/start/server-fn",k=new Set(["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression"]);function w(e){if(!k.has(e.type))return null;let r=e.body;if(!r||r.type!=="BlockStatement")return null;for(let t of r.directives??[])if(t.value?.value==="use server")return t;return null}function f(e,r){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let t of e)f(t,r);return}if(typeof e.type=="string"){let t=w(e);if(t){r.push({fn:e,directive:t});return}}for(let t of Object.keys(e))t==="loc"||t==="leadingComments"||t==="trailingComments"||f(e[t],r)}}function C(e,r){if(!e.includes("use server"))return null;let t=(0,m.parse)(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),i=[];if(f(t.program,i),i.length===0)return null;let n=r.ssr?"$$registerServerFn":"$$createServerReference",o=new y.default(e);return i.forEach(({fn:s,directive:l},v)=>{let c=g(r.filename,r.root,v),a=s.type==="FunctionDeclaration";if(!r.ssr){let d=`${n}(${JSON.stringify(c)})`;o.overwrite(s.start,s.end,a?`const ${s.id.name} = ${d};`:d);return}o.remove(l.start,l.end),o.appendLeft(s.start,a?`const ${s.id.name} = ${n}(${JSON.stringify(c)}, `:`${n}(${JSON.stringify(c)}, `),o.appendRight(s.end,a?");":")")}),o.prepend(`import { ${n} } from ${JSON.stringify(r.runtimeModule??A)};
2
+ `),{code:o.toString(),map:o.generateMap({source:r.filename,includeContent:!0,hires:!0})}}
@@ -0,0 +1,13 @@
1
+ import MagicString from 'magic-string';
2
+ export interface ServerFnOptions {
3
+ ssr: boolean;
4
+ filename: string;
5
+ root?: string;
6
+ runtimeModule?: string;
7
+ }
8
+ /** Returns `{ code, map }`, or null when the source has no `"use server"`. */
9
+ export declare function transformServerFns(code: string, options: ServerFnOptions): {
10
+ code: string;
11
+ map: ReturnType<MagicString['generateMap']>;
12
+ } | null;
13
+ //# sourceMappingURL=server-fns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-fns.d.ts","sourceRoot":"","sources":["../../src/transform/server-fns.ts"],"names":[],"mappings":"AAYA,OAAO,WAAW,MAAM,cAAc,CAAC;AAYvC,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AA2CD,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAA;CAAE,GAAG,IAAI,CAuCtE"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * `"use server"` — a function carrying the directive runs only on the server and
3
+ * is callable from the client over RPC.
4
+ *
5
+ * const getUser = async (id) => { 'use server'; return db.users.find(id); };
6
+ *
7
+ * Server build keeps the body and registers it under a stable id; client build
8
+ * drops the body entirely and leaves a stub that calls it. The id is
9
+ * `hash(relativeFile):indexInFile` and has to come out the same on both builds,
10
+ * so the walk order matters as much as the hash does.
11
+ */
12
+ import { parse } from '@babel/parser';
13
+ import MagicString from 'magic-string';
14
+ import { serverFnId } from './server-fn-id.js';
15
+ const RUNTIME = '@fluixi/start/server-fn';
16
+ const FUNCTION_TYPES = new Set([
17
+ 'FunctionDeclaration',
18
+ 'FunctionExpression',
19
+ 'ArrowFunctionExpression',
20
+ ]);
21
+ /** The `'use server'` directive on a function's block body, if it carries one. */
22
+ function directive(node) {
23
+ if (!FUNCTION_TYPES.has(node.type))
24
+ return null;
25
+ const body = node.body;
26
+ if (!body || body.type !== 'BlockStatement')
27
+ return null; // an expression body cannot carry one
28
+ for (const d of (body.directives ?? [])) {
29
+ if (d.value?.value === 'use server')
30
+ return d;
31
+ }
32
+ return null;
33
+ }
34
+ /**
35
+ * Server functions in source order, not descending into one already found — a
36
+ * nested `"use server"` belongs to the body that is about to be replaced or
37
+ * shipped whole, exactly as the babel visitor's `path.skip()` decided.
38
+ */
39
+ function findServerFns(node, out) {
40
+ if (!node || typeof node !== 'object')
41
+ return;
42
+ if (Array.isArray(node)) {
43
+ for (const child of node)
44
+ findServerFns(child, out);
45
+ return;
46
+ }
47
+ if (typeof node.type === 'string') {
48
+ const found = directive(node);
49
+ if (found) {
50
+ out.push({ fn: node, directive: found });
51
+ return; // do not descend
52
+ }
53
+ }
54
+ for (const key of Object.keys(node)) {
55
+ if (key === 'loc' || key === 'leadingComments' || key === 'trailingComments')
56
+ continue;
57
+ findServerFns(node[key], out);
58
+ }
59
+ }
60
+ /** Returns `{ code, map }`, or null when the source has no `"use server"`. */
61
+ export function transformServerFns(code, options) {
62
+ if (!code.includes('use server'))
63
+ return null;
64
+ const ast = parse(code, {
65
+ sourceType: 'module',
66
+ plugins: ['jsx', 'typescript'],
67
+ errorRecovery: true,
68
+ });
69
+ const found = [];
70
+ findServerFns(ast.program, found);
71
+ if (found.length === 0)
72
+ return null;
73
+ const helper = options.ssr ? '$$registerServerFn' : '$$createServerReference';
74
+ const out = new MagicString(code);
75
+ found.forEach(({ fn, directive: dir }, index) => {
76
+ const id = serverFnId(options.filename, options.root, index);
77
+ const declaration = fn.type === 'FunctionDeclaration';
78
+ if (!options.ssr) {
79
+ // The body never reaches the client — it is replaced, not emptied.
80
+ const stub = `${helper}(${JSON.stringify(id)})`;
81
+ out.overwrite(fn.start, fn.end, declaration ? `const ${fn.id.name} = ${stub};` : stub);
82
+ return;
83
+ }
84
+ // Keep the body, drop the directive, wrap the function in its registration.
85
+ out.remove(dir.start, dir.end);
86
+ out.appendLeft(fn.start, declaration ? `const ${fn.id.name} = ${helper}(${JSON.stringify(id)}, ` : `${helper}(${JSON.stringify(id)}, `);
87
+ out.appendRight(fn.end, declaration ? ');' : ')');
88
+ });
89
+ out.prepend(`import { ${helper} } from ${JSON.stringify(options.runtimeModule ?? RUNTIME)};\n`);
90
+ return {
91
+ code: out.toString(),
92
+ map: out.generateMap({ source: options.filename, includeContent: true, hires: true }),
93
+ };
94
+ }