@fluixi/compiler 1.0.0-alpha.82 → 1.0.0-alpha.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyze/static-graph.cjs +1 -0
- package/dist/analyze/static-graph.d.ts +103 -0
- package/dist/analyze/static-graph.d.ts.map +1 -0
- package/dist/analyze/static-graph.js +869 -0
- package/dist/analyze/static-graph.mjs +1 -0
- package/dist/{babel-4JUDAR2G.mjs → babel-VXKH6MRQ.mjs} +1 -1
- package/dist/chunk-5KMMN5QP.mjs +1 -0
- package/dist/chunk-YKZ54NVE.mjs +1 -0
- package/dist/codegen/backends/imperative.cjs +1 -1
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +62 -11
- package/dist/codegen/backends/imperative.mjs +1 -1
- package/dist/codegen/partial-template.cjs +1 -1
- package/dist/codegen/partial-template.mjs +1 -1
- package/dist/codegen/serialize-static.cjs +1 -1
- package/dist/codegen/serialize-static.d.ts +16 -0
- package/dist/codegen/serialize-static.d.ts.map +1 -1
- package/dist/codegen/serialize-static.js +25 -0
- package/dist/codegen/serialize-static.mjs +1 -1
- package/dist/frontend/babel/build-ir-lit.cjs +1 -1
- package/dist/frontend/babel/build-ir-lit.mjs +1 -1
- package/dist/frontend/babel/build-ir.cjs +1 -1
- package/dist/frontend/babel/build-ir.mjs +1 -1
- package/dist/frontend/babel/index.cjs +1 -1
- package/dist/frontend/babel/index.mjs +1 -1
- package/dist/frontend/babel/lower-template.cjs +1 -1
- package/dist/frontend/babel/lower-template.mjs +1 -1
- package/dist/frontend/babel/plugin.cjs +1 -1
- package/dist/frontend/babel/plugin.mjs +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.mjs +8 -8
- package/dist/integrations.cjs +18 -18
- package/dist/integrations.d.ts +16 -0
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +21 -2
- package/dist/integrations.mjs +5 -5
- package/dist/ir/nodes.cjs +1 -1
- package/dist/ir/nodes.d.ts +46 -0
- package/dist/ir/nodes.d.ts.map +1 -1
- package/dist/lower/compile-template.cjs +1 -1
- package/dist/lower/compile-template.d.ts +12 -0
- package/dist/lower/compile-template.d.ts.map +1 -1
- package/dist/lower/compile-template.js +5 -1
- package/dist/lower/compile-template.mjs +1 -1
- package/dist/lower/jsx.cjs +1 -1
- package/dist/lower/jsx.d.ts +2 -0
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +25 -3
- package/dist/lower/jsx.mjs +1 -1
- package/dist/lower/template.cjs +1 -1
- package/dist/lower/template.d.ts +14 -1
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +101 -15
- package/dist/lower/template.mjs +1 -1
- package/dist/transform/index.cjs +5 -5
- package/dist/transform/index.mjs +12 -12
- package/dist/transform/source-locations.cjs +1 -0
- package/dist/transform/source-locations.d.ts +44 -0
- package/dist/transform/source-locations.d.ts.map +1 -0
- package/dist/transform/source-locations.js +238 -0
- package/dist/transform/source-locations.mjs +1 -0
- package/dist/transform/templates.cjs +4 -4
- package/dist/transform/templates.d.ts +12 -4
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +72 -7
- package/dist/transform/templates.mjs +11 -11
- package/dist/transform-C4ZXRVGP.mjs +8 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/chunk-PVR2SN3B.mjs +0 -1
- package/dist/chunk-QUIYULS2.mjs +0 -1
- package/dist/chunk-YR3SAEO7.mjs +0 -1
- package/dist/transform-5WC4FWJE.mjs +0 -8
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Record where each reactive primitive was created, for the devtools graph.
|
|
3
|
+
*
|
|
4
|
+
* const count = signal(0);
|
|
5
|
+
* → globalThis.__fx_source?.("src/App.ts",1,14,"count"); const count = signal(0);
|
|
6
|
+
*
|
|
7
|
+
* A statement in front of the one that creates the node, not a wrapper round the call: the
|
|
8
|
+
* call may already be being rewritten — `$signal` becomes `signal` — and two passes editing
|
|
9
|
+
* one span is a splice over a splice.
|
|
10
|
+
*
|
|
11
|
+
* A global rather than an import, so the author's modules do not each take a dependency on
|
|
12
|
+
* @fluixi/devtools to carry a debug string. Nothing installs it by default.
|
|
13
|
+
*
|
|
14
|
+
* Positions come from the original source, before any pass moves anything.
|
|
15
|
+
*
|
|
16
|
+
* Development only, and one mark per statement — the runtime keeps a single slot, so
|
|
17
|
+
* marking two calls in one statement would hand the first node the second's location.
|
|
18
|
+
*/
|
|
19
|
+
import { INTRINSICS, isIntrinsicName } from '../analyze/intrinsics.js';
|
|
20
|
+
import { resolveReactiveBindings } from '../analyze/reactive-bindings.js';
|
|
21
|
+
/** Installed by @fluixi/devtools; undefined everywhere else. */
|
|
22
|
+
export const SOURCE_MARKER = '__fx_source';
|
|
23
|
+
/** Where a component was declared. Keyed by name, since that is all the runtime carries. */
|
|
24
|
+
export const COMPONENT_MARKER = '__fx_component';
|
|
25
|
+
/**
|
|
26
|
+
* Where one reactive hole was written. This one wraps: the position has to travel with the
|
|
27
|
+
* accessor to wherever the dom wires it up. A template is emitted as one overwrite, so the
|
|
28
|
+
* source map has a single entry for the root and every hole traces back to it.
|
|
29
|
+
*
|
|
30
|
+
* `?? (f => f)` and not `?.()`: the value is the accessor, and returning undefined would
|
|
31
|
+
* delete the binding.
|
|
32
|
+
*/
|
|
33
|
+
export const HOLE_MARKER = '__fx_hole';
|
|
34
|
+
/**
|
|
35
|
+
* `_(() => x(), 9, 25)`, or the accessor untouched when nothing is watching.
|
|
36
|
+
*
|
|
37
|
+
* `name` is the source text the value came from, for a `ref` where knowing which variable
|
|
38
|
+
* holds the element is the whole question.
|
|
39
|
+
*/
|
|
40
|
+
export const markHole = (accessor, line, column, name) => `(globalThis.${HOLE_MARKER} ?? ((f) => f))(${accessor},${line},${column}${name === undefined ? '' : `,${JSON.stringify(name)}`})`;
|
|
41
|
+
/**
|
|
42
|
+
* Where each prop of a component tag was written.
|
|
43
|
+
*
|
|
44
|
+
* The props object is built as getters, so nothing in it can carry a position of its own.
|
|
45
|
+
* The marker takes the object and a name-to-position map, and hands the object straight
|
|
46
|
+
* back — devtools keeps the map, and a build without it passes the object through.
|
|
47
|
+
*/
|
|
48
|
+
export const PROPS_MARKER = '__fx_props';
|
|
49
|
+
/** `_({ get a() {…} }, {"a":[9,25]})`, or the object untouched when nothing is watching. */
|
|
50
|
+
export const markProps = (object, at) => `(globalThis.${PROPS_MARKER} ?? ((p) => p))(${object},${JSON.stringify(at)})`;
|
|
51
|
+
/** The runtime names that make a node. */
|
|
52
|
+
const RUNTIME_PRIMITIVES = new Set([
|
|
53
|
+
'signal', 'memo', 'effect', 'store', 'resource', 'watch',
|
|
54
|
+
'createSignal', 'createMemo', 'createEffect', 'createStore', 'createResource',
|
|
55
|
+
]);
|
|
56
|
+
/** Cheap enough to run before parsing. */
|
|
57
|
+
export function mayHaveReactiveCall(code) {
|
|
58
|
+
for (const name of RUNTIME_PRIMITIVES) {
|
|
59
|
+
if (code.includes(name))
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return code.includes('$signal') || code.includes('$memo') || code.includes('$effect') || code.includes('$store');
|
|
63
|
+
}
|
|
64
|
+
/** Positions where the grammar allows exactly one statement, so a second one changes it. */
|
|
65
|
+
const SINGLE_STATEMENT_PARENTS = new Set([
|
|
66
|
+
'IfStatement', 'ForStatement', 'ForInStatement', 'ForOfStatement',
|
|
67
|
+
'WhileStatement', 'DoWhileStatement', 'LabeledStatement', 'WithStatement',
|
|
68
|
+
]);
|
|
69
|
+
function isLoneBranch(statement, parent) {
|
|
70
|
+
if (!parent || statement.type === 'BlockStatement')
|
|
71
|
+
return false;
|
|
72
|
+
return SINGLE_STATEMENT_PARENTS.has(parent.type);
|
|
73
|
+
}
|
|
74
|
+
function isExport(node) {
|
|
75
|
+
return node.type === 'ExportNamedDeclaration' || node.type === 'ExportDefaultDeclaration';
|
|
76
|
+
}
|
|
77
|
+
function isStatement(node) {
|
|
78
|
+
return node.type.endsWith('Statement') || node.type === 'VariableDeclaration';
|
|
79
|
+
}
|
|
80
|
+
function walk(node, visit, stack = []) {
|
|
81
|
+
if (!node || typeof node.type !== 'string')
|
|
82
|
+
return;
|
|
83
|
+
visit(node, stack);
|
|
84
|
+
stack.push(node);
|
|
85
|
+
for (const key of Object.keys(node)) {
|
|
86
|
+
if (key === 'loc' || key === 'parent')
|
|
87
|
+
continue;
|
|
88
|
+
const value = node[key];
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
for (const child of value)
|
|
91
|
+
walk(child, visit, stack);
|
|
92
|
+
}
|
|
93
|
+
else if (value && typeof value.type === 'string') {
|
|
94
|
+
walk(value, visit, stack);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
stack.pop();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* const count = signal(0) → count
|
|
101
|
+
* const [count, setCount] = … → count, the accessor rather than the setter
|
|
102
|
+
* effect(() => …) → nothing
|
|
103
|
+
*/
|
|
104
|
+
function nameFor(stack) {
|
|
105
|
+
const declarator = stack[stack.length - 1];
|
|
106
|
+
if (declarator?.type !== 'VariableDeclarator')
|
|
107
|
+
return undefined;
|
|
108
|
+
const id = declarator.id;
|
|
109
|
+
if (id?.type === 'Identifier')
|
|
110
|
+
return id.name;
|
|
111
|
+
if (id?.type === 'ArrayPattern') {
|
|
112
|
+
const first = id.elements?.[0];
|
|
113
|
+
if (first?.type === 'Identifier')
|
|
114
|
+
return first.name;
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
/** A capitalised function is how JSX tells a component from an element. */
|
|
119
|
+
function componentName(node) {
|
|
120
|
+
if (node.type === 'FunctionDeclaration') {
|
|
121
|
+
const name = node.id?.name;
|
|
122
|
+
return name && name[0] === name[0]?.toUpperCase() ? name : undefined;
|
|
123
|
+
}
|
|
124
|
+
if (node.type === 'VariableDeclarator') {
|
|
125
|
+
const id = node.id;
|
|
126
|
+
const init = node.init;
|
|
127
|
+
if (id?.type !== 'Identifier' || !init)
|
|
128
|
+
return undefined;
|
|
129
|
+
if (init.type !== 'ArrowFunctionExpression' && init.type !== 'FunctionExpression')
|
|
130
|
+
return undefined;
|
|
131
|
+
const name = id.name;
|
|
132
|
+
return name[0] === name[0]?.toUpperCase() ? name : undefined;
|
|
133
|
+
}
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
export function collectSourceEdits(program, filename) {
|
|
137
|
+
const edits = [];
|
|
138
|
+
// A single slot cannot describe more than the first primitive in a statement.
|
|
139
|
+
const claimed = new Set();
|
|
140
|
+
const { primitives, shadowed } = resolveReactiveBindings(program);
|
|
141
|
+
walk(program, (node, stack) => {
|
|
142
|
+
// The compiler wraps every component in a memo, and the memo is what the graph sees. It
|
|
143
|
+
// has no way back to the declaration, so the declaration says where it is by name.
|
|
144
|
+
const component = componentName(node);
|
|
145
|
+
if (component) {
|
|
146
|
+
const at = node.loc?.start;
|
|
147
|
+
// After the whole declaration, not after the function: `const Row = () => <b/>` ends
|
|
148
|
+
// where its jsx ends, and an insertion on that boundary is inside the span the
|
|
149
|
+
// template pass overwrites.
|
|
150
|
+
//
|
|
151
|
+
// Only through what wraps a declaration. Anything else above it is a block or an
|
|
152
|
+
// argument list, and a statement appended there lands outside the grammar —
|
|
153
|
+
// `function Page(){}` inside `it('…', () => { … })` ended up between the `}` and the
|
|
154
|
+
// `)`, which is a syntax error in a file that compiled a moment earlier.
|
|
155
|
+
let end = node.end;
|
|
156
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
157
|
+
const up = stack[i];
|
|
158
|
+
if (up.type !== 'VariableDeclaration' &&
|
|
159
|
+
up.type !== 'ExportNamedDeclaration' &&
|
|
160
|
+
up.type !== 'ExportDefaultDeclaration') {
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
end = up.end;
|
|
164
|
+
}
|
|
165
|
+
if (at) {
|
|
166
|
+
edits.push({
|
|
167
|
+
start: end,
|
|
168
|
+
end,
|
|
169
|
+
code: `;globalThis.${COMPONENT_MARKER}?.(${JSON.stringify(component)},${JSON.stringify(filename)},${at.line},${at.column});`,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (node.type !== 'CallExpression')
|
|
174
|
+
return;
|
|
175
|
+
const callee = node.callee;
|
|
176
|
+
if (callee?.type !== 'Identifier')
|
|
177
|
+
return;
|
|
178
|
+
const name = callee.name;
|
|
179
|
+
// The same test the intrinsics pass makes, so the two agree on what is a primitive.
|
|
180
|
+
const intrinsic = isIntrinsicName(name) && !shadowed.has(name) ? INTRINSICS[name] : undefined;
|
|
181
|
+
// resolveReactiveBindings has followed the import, so `signal as state` is covered and
|
|
182
|
+
// a local function of the same name is not.
|
|
183
|
+
const imported = primitives.has(name) || RUNTIME_PRIMITIVES.has(name);
|
|
184
|
+
if (!intrinsic && !imported)
|
|
185
|
+
return;
|
|
186
|
+
const position = node.loc?.start;
|
|
187
|
+
if (!position)
|
|
188
|
+
return;
|
|
189
|
+
// The mark goes in front of the statement, clear of any span another pass rewrites.
|
|
190
|
+
let statement;
|
|
191
|
+
let parent;
|
|
192
|
+
let index = -1;
|
|
193
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
194
|
+
if (isStatement(stack[i]) || isExport(stack[i])) {
|
|
195
|
+
statement = stack[i];
|
|
196
|
+
parent = stack[i - 1];
|
|
197
|
+
index = i;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (!statement)
|
|
202
|
+
return;
|
|
203
|
+
// `export const [cart] = createStore(…)` finds the declaration, which starts after the
|
|
204
|
+
// keyword — a mark there splits `export` from what it exports.
|
|
205
|
+
let start = statement.start;
|
|
206
|
+
let end = statement.end;
|
|
207
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
208
|
+
if (!isExport(stack[i]))
|
|
209
|
+
break;
|
|
210
|
+
start = stack[i].start;
|
|
211
|
+
end = stack[i].end;
|
|
212
|
+
parent = stack[i - 1];
|
|
213
|
+
}
|
|
214
|
+
if (claimed.has(start))
|
|
215
|
+
return;
|
|
216
|
+
claimed.add(start);
|
|
217
|
+
const label = nameFor(stack);
|
|
218
|
+
const args = [
|
|
219
|
+
JSON.stringify(filename),
|
|
220
|
+
String(position.line),
|
|
221
|
+
String(position.column),
|
|
222
|
+
label ? JSON.stringify(label) : undefined,
|
|
223
|
+
]
|
|
224
|
+
.filter((a) => a !== undefined)
|
|
225
|
+
.join(',');
|
|
226
|
+
const mark = `globalThis.${SOURCE_MARKER}?.(${args});`;
|
|
227
|
+
// `if (c) effect(…)` has one statement where the grammar allows one statement, so
|
|
228
|
+
// putting the mark in front of it moves the branch body out of the branch. Braces are
|
|
229
|
+
// added around both rather than skipping the mark.
|
|
230
|
+
if (isLoneBranch(statement, parent)) {
|
|
231
|
+
edits.push({ start, end: start, code: `{${mark}` });
|
|
232
|
+
edits.push({ start: end, end, code: '}' });
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
edits.push({ start, end: start, code: mark });
|
|
236
|
+
});
|
|
237
|
+
return { edits, marked: edits.length };
|
|
238
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var u="@fluixi/reactive/signal",d={$signal:{export:"signal",module:u,returns:"signal-handle"},$memo:{export:"memo",module:u,returns:"memo-handle"},$effect:{export:"effect",module:u,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:u,returns:"resource-handle"},$selector:{export:"createSelector",module:u,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:u,returns:"memo-accessor"},$untrack:{export:"untrack",module:u,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}},D={signal:"signal-handle",memo:"memo-handle",effect:"effect",store:"store-handle",createSignal:["signal-accessor","signal-setter"],createMemo:"memo-accessor",createEffect:"effect",createRenderEffect:"effect",createStore:"reactive-object",resource:"resource-handle",createResource:"reactive-object",createSelector:"memo-accessor",createDeferred:"memo-accessor"},F=["@fluixi/reactive","@fluixi/reactive/signal","@fluixi/reactive/store","@fluixi/core"],z=new RegExp(`\\$(?:${Object.keys(d).map(e=>e.slice(1)).join("|")})\\s*\\(`);function M(e){return Object.prototype.hasOwnProperty.call(d,e)}function _(e){return F.includes(e)}function c(e,n){if(e)switch(e.type){case"Identifier":n.add(e.name);return;case"ObjectPattern":for(let r of e.properties??[])r.type==="RestElement"?c(r.argument,n):c(r.value,n);return;case"ArrayPattern":for(let r of e.elements??[])c(r,n);return;case"AssignmentPattern":c(e.left,n);return;case"RestElement":c(e.argument,n);return}}function N(e,n){if(!(!e||typeof e!="object"||typeof e.type!="string")){n(e);for(let r of Object.keys(e)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let t=e[r];if(Array.isArray(t))for(let i of t)N(i,n);else t&&typeof t=="object"&&N(t,n)}}}function j(e,n){if(e.type!=="CallExpression")return;let r=e.callee;if(r?.type!=="Identifier")return;let t=r.name,i=n.primitives.get(t);if(i)return i;let o=d[t];if(o&&!n.shadowed.has(t))return o.returns}function V(e,n,r){if(Array.isArray(n)){e.type==="ArrayPattern"&&e.elements.forEach((t,i)=>{let o=n[i];t?.type==="Identifier"&&o&&r.set(t.name,o)});return}e.type==="Identifier"&&r.set(e.name,n)}function A(e){let n={kinds:new Map,primitives:new Map,shadowed:new Set},r=e;N(r,t=>{let i=new Set;if(t.type==="VariableDeclarator")c(t.id,i);else if(t.type==="FunctionDeclaration"||t.type==="ClassDeclaration")c(t.id,i);else if(t.type==="ImportDefaultSpecifier"||t.type==="ImportNamespaceSpecifier")c(t.local,i);else if(t.type==="ImportSpecifier")c(t.local,i);else if(t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="FunctionDeclaration")for(let o of t.params??[])c(o,i);for(let o of i)d[o]&&n.shadowed.add(o)});for(let t of r.body??[])if(t.type==="ImportDeclaration"&&_(t.source?.value))for(let i of t.specifiers??[]){if(i.type!=="ImportSpecifier")continue;let o=i.imported,l=o.type==="Identifier"?o.name:o.value,a=D[l];a&&n.primitives.set(i.local.name,a)}return N(r,t=>{if(t.type!=="VariableDeclarator"||!t.init)return;let i=j(t.init,n);i&&V(t.id,i,n.kinds)}),n}var K="__fx_source",L="__fx_component",B="__fx_hole",te=(e,n,r,t)=>`(globalThis.${B} ?? ((f) => f))(${e},${n},${r}${t===void 0?"":`,${JSON.stringify(t)}`})`,U="__fx_props",ne=(e,n)=>`(globalThis.${U} ?? ((p) => p))(${e},${JSON.stringify(n)})`,C=new Set(["signal","memo","effect","store","resource","watch","createSignal","createMemo","createEffect","createStore","createResource"]);function re(e){for(let n of C)if(e.includes(n))return!0;return e.includes("$signal")||e.includes("$memo")||e.includes("$effect")||e.includes("$store")}var J=new Set(["IfStatement","ForStatement","ForInStatement","ForOfStatement","WhileStatement","DoWhileStatement","LabeledStatement","WithStatement"]);function H(e,n){return!n||e.type==="BlockStatement"?!1:J.has(n.type)}function T(e){return e.type==="ExportNamedDeclaration"||e.type==="ExportDefaultDeclaration"}function W(e){return e.type.endsWith("Statement")||e.type==="VariableDeclaration"}function h(e,n,r=[]){if(!(!e||typeof e.type!="string")){n(e,r),r.push(e);for(let t of Object.keys(e)){if(t==="loc"||t==="parent")continue;let i=e[t];if(Array.isArray(i))for(let o of i)h(o,n,r);else i&&typeof i.type=="string"&&h(i,n,r)}r.pop()}}function G(e){let n=e[e.length-1];if(n?.type!=="VariableDeclarator")return;let r=n.id;if(r?.type==="Identifier")return r.name;if(r?.type==="ArrayPattern"){let t=r.elements?.[0];if(t?.type==="Identifier")return t.name}}function q(e){if(e.type==="FunctionDeclaration"){let n=e.id?.name;return n&&n[0]===n[0]?.toUpperCase()?n:void 0}if(e.type==="VariableDeclarator"){let n=e.id,r=e.init;if(n?.type!=="Identifier"||!r||r.type!=="ArrowFunctionExpression"&&r.type!=="FunctionExpression")return;let t=n.name;return t[0]===t[0]?.toUpperCase()?t:void 0}}function ie(e,n){let r=[],t=new Set,{primitives:i,shadowed:o}=A(e);return h(e,(l,a)=>{let E=q(l);if(E){let s=l.loc?.start,I=l.end;for(let R=a.length-1;R>=0;R--){let g=a[R];if(g.type!=="VariableDeclaration"&&g.type!=="ExportNamedDeclaration"&&g.type!=="ExportDefaultDeclaration")break;I=g.end}s&&r.push({start:I,end:I,code:`;globalThis.${L}?.(${JSON.stringify(E)},${JSON.stringify(n)},${s.line},${s.column});`})}if(l.type!=="CallExpression")return;let b=l.callee;if(b?.type!=="Identifier")return;let p=b.name,O=M(p)&&!o.has(p)?d[p]:void 0,P=i.has(p)||C.has(p);if(!O&&!P)return;let y=l.loc?.start;if(!y)return;let m,S,v=-1;for(let s=a.length-1;s>=0;s--)if(W(a[s])||T(a[s])){m=a[s],S=a[s-1],v=s;break}if(!m)return;let f=m.start,x=m.end;for(let s=v-1;s>=0&&T(a[s]);s--)f=a[s].start,x=a[s].end,S=a[s-1];if(t.has(f))return;t.add(f);let $=G(a),k=[JSON.stringify(n),String(y.line),String(y.column),$?JSON.stringify($):void 0].filter(s=>s!==void 0).join(","),w=`globalThis.${K}?.(${k});`;if(H(m,S)){r.push({start:f,end:f,code:`{${w}`}),r.push({start:x,end:x,code:"}"});return}r.push({start:f,end:f,code:w})}),{edits:r,marked:r.length}}export{L as COMPONENT_MARKER,B as HOLE_MARKER,U as PROPS_MARKER,K as SOURCE_MARKER,ie as collectSourceEdits,te as markHole,ne as markProps,re as mayHaveReactiveCall};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var ht=Object.create;var K=Object.defineProperty;var yt=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var vt=Object.getPrototypeOf,xt=Object.prototype.hasOwnProperty;var Rt=(e,t)=>{for(var n in t)K(e,n,{get:t[n],enumerable:!0})},Ee=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Nt(t))!xt.call(e,o)&&o!==n&&K(e,o,{get:()=>t[o],enumerable:!(r=yt(t,o))||r.enumerable});return e};var Ie=(e,t,n)=>(n=e!=null?ht(vt(e)):{},Ee(t||!e||!e.__esModule?K(n,"default",{value:e,enumerable:!0}):n,e)),kt=e=>Ee(K({},"__esModule",{value:!0}),e);var Pn={};Rt(Pn,{transformTemplates:()=>Cn});module.exports=kt(Pn);var dt=require("@babel/parser"),ut=Ie(require("magic-string"),1);function bt(e){switch(e.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return e.reactive?"reactive-prop":e.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function P(e){let t=[],n=new Map,r=o=>{switch(o.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of o.children)r(s);return!1;case"fragment":for(let s of o.children)r(s);return!1;case"element":{let s=!0;for(let a of o.children)r(a)||(s=!1);let i;for(let a of o.props)if(i=bt(a),i)break;return!i&&!s&&(i=St(o)),o.static=!i,i?n.set(o,i):t.push(o),o.static}default:return!1}};for(let o of Array.isArray(e)?e:[e])r(o);return{staticElements:t,reasons:n}}function St(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 G={kind:"eager"},Et=["pointerdown","focusin","keydown"],we=new Set(["eager","idle","visible","interaction","media","never"]),I=class extends Error{};function le(e){return e.startsWith("load:")}function Z(e,t){let n=e.slice(5);if(!we.has(n))throw new I(`Unknown load strategy 'load:${n}'. Expected one of ${[...we].join(", ")}.`);switch(n){case"eager":return G;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?It(t):[...Et]};case"media":if(!t)throw new I(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new I(`Unhandled load strategy '${n}'.`)}}function It(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new I("'load:interaction' was given no event names.");return t}function L(e){return e.kind!=="eager"&&e.kind!=="never"}var j=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],J=["Suspense","SuspenseList","Await"],M=["Router","Outlet","Redirect","Link"],An=[...j,...J,...M],ce=new Set([...j,...J]);function Ce(e={}){let{controlFlowModule:t="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:r="@fluixi/core/router"}=e,o={};for(let s of j)o[s]=t;for(let s of J)o[s]=n;for(let s of M)o[s]=r;return o}function Y(e,t={}){let{resolver:n,isBound:r,modules:o,strategyFor:s}=t,i=Ce(o),a=new Map,l=new Set,c=f=>{let{name:d}=f;if(!d||d.includes(".")||r?.(d))return;let g=p(d);if(!g){l.add(d);return}let m=g.origin==="builtin"&&ce.has(d)?G:s?.(f)??G;f.source={...g,loading:m},a.set(d,f.source)},p=f=>{if(ce.has(f))return{module:i[f],export:f,origin:"builtin"};let d=n?.resolve(f);if(d)return{module:d.module,export:d.export,origin:"rule"};if(M.includes(f))return{module:i[f],export:f,origin:"builtin"}};return Q(e,f=>{f.kind==="component"&&c(f)}),{resolved:a,unresolved:[...l]}}function Q(e,t){let n=Array.isArray(e)?e:[e];for(let r of n){t(r);let o=r.children;o&&Q(o,t)}}function ee(e){let t=[];Q(e,s=>{s.kind==="component"&&s.source&&t.push(s)});let n=new Set,r=new Set;for(let s of t){let{module:i,loading:a}=s.source;a.kind==="eager"&&n.add(i),a.kind==="never"&&r.add(i)}let o=new Map;for(let s of t){let i=s.source;L(i.loading)&&n.has(i.module)&&(i.loading={kind:"eager"},o.set(i.module,(o.get(i.module)??0)+1))}return{collapsed:o,conflicted:[...r].filter(s=>n.has(s))}}var wt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),$e={className:"class",htmlFor:"for"},Ct=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),$t=new Set(["script","style","textarea","title"]);function pe(e){return $t.has(e)}function Te(e){return $e[e]??e}function B(e){return e.kind!=="attr"||e.expr!==void 0||e.name.includes(":")?!1:!Ct.has(e.name)}function de(e){if(!e.static||pe(e.tag))return!1;for(let t of e.props)if(!B(t))return!1;for(let t of e.children)if(t.kind!=="text"&&!(t.kind==="element"&&de(t)))return!1;return!0}function _(e){let t=e.props.map(Pt).filter(Boolean).join(""),n=`<${e.tag}${t}>`;return wt.has(e.tag)?n:`${n}${e.children.map(Tt).join("")}</${e.tag}>`}function Tt(e){if(e.kind==="text")return Ot(e.value);if(e.kind!=="element")throw new Error(`serializeStatic: unexpected ${e.kind}`);return _(e)}function Pt(e){let t=$e[e.name]??e.name,n=e.literal;return n===!0||n===void 0?` ${t}`:n===!1||n===null?"":` ${t}="${Mt(String(n))}"`}function Mt(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function Ot(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var Dt="<!--fx-->",At="<!--fx/-->";function ne(e){return e.kind==="expr"||e.kind==="component"||e.kind==="control"}function Lt(e){return e.kind==="text"||e.kind==="element"&&Pe(e)}function Pe(e){return e.svg||pe(e.tag)||!e.props.every(t=>B(t))?!1:e.children.every(t=>Lt(t)||ne(t))}function te(e){if(ne(e))return!0;let t=e.children;return t?t.some(te):!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 Oe(e){if(!Pe(e)||!Me(e)||!e.children.some(te))return null;let t=[],n=[],r=0,o=i=>{let a=`_n$${r++}`;return t.push({ref:a,expr:i}),a};return s(e,"_el$"),{html:jt(e),tag:e.tag,steps:t,holes:n};function s(i,a){let l=-1;i.children.forEach((p,f)=>{te(p)&&(l=f)});let c=null;for(let p=0;p<=l;p++){let f=i.children[p],d=c?`${c}.nextSibling`:`${a}.firstChild`;if(ne(f)){let m=o(d),h=o(`holeEnd(${m})`);n.push({parentRef:a,startRef:m,endRef:h,node:f}),c=h;continue}let g=o(d);f.kind==="element"&&te(f)&&s(f,g),c=g}}}function jt(e){return _(De(e)).split(Ae).join(Dt+At)}function De(e){return{...e,children:e.children.map(t=>ne(t)?{kind:"text",value:Ae}:t.kind==="element"?De(t):t)}}var Ae="\0fx-hole\0";var ue={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},zn={version:2,module:"@fluixi/dom",symbols:[...ue.symbols,"template","cloneTemplate","walk"]};var Jt={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function Bt(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function je(e){return Bt(e)?e:JSON.stringify(e)}function _t(e){return e.expr!==void 0?e.reactive?`() => (${e.expr})`:`(${e.expr})`:JSON.stringify(e.literal??!0)}function Ft(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function Ht(e,t,n){let r=e.filter(a=>a.kind==="spread"),s=e.filter(a=>a.kind!=="spread").map(a=>`${je(a.name)}: ${_t(a)}`);t!=null&&s.push(`children: ${t}`);let i=`{ ${s.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(a=>a.expr).join(", ")}, ${i})`):i}function Je(e,t,n){return e.length===1?F(e[0],t,n):`[${e.map(r=>F(r,t,n)).join(", ")}]`}function Le(e,t,n,r,o){r.add("createMemo"),r.add("createComponent");let s=t.filter(c=>c.kind==="spread"),a=t.filter(c=>c.kind!=="spread").map(c=>`get ${je(c.name)}() { return ${Ft(c)}; }`);n.length>0&&a.push(`get children() { return ${Je(n,r,o)}; }`);let l=`{ ${a.join(", ")} }`;return s.length>0&&(r.add("mergeProps"),l=`mergeProps(${s.map(c=>c.expr).join(", ")}, ${l})`),`createMemo(() => createComponent(${e}, ${l}))`}function Vt(e,t){let n=Te(t.name),r=t.literal;return r===!0||r===void 0?`${e}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${e}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var Be=!1;function F(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":Je(e.children,t,n);case"component":return Le(e.name,e.props,e.children,t,n);case"control":{let r=Jt[e.control]??e.control;return t.add(r),Le(r,e.props,e.children,t,n)}case"element":{if(n&&e.static&&!e.svg&&de(e)){t.add("templateNode");let a=`_tmpl$${n.length}`;return n.push({id:a,html:_(e),tag:e.tag,svg:!1}),`templateNode(${a}, ${JSON.stringify(e.tag)})`}if(n&&Be){let a=Oe(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 p of a.steps)c.push(`const ${p.ref} = ${p.expr};`);for(let p of a.holes)c.push(`insert(${p.parentRef}, holeScope(${p.startRef}, () => (${F(p.node,t,n)})), ${p.endRef}, holeContent(${p.startRef}, ${p.endRef}));`);return c.push("return _el$;"),`(() => { ${c.join(" ")} })()`}}t.add("createNativeElement");let r=JSON.stringify(e.tag),o="_el$",s=[],i=e.svg?`${r}, true`:r;if(s.push(`const ${o} = createNativeElement(${i});`),e.props.length>0)if(!e.svg&&e.props.every(B))for(let a of e.props)s.push(Vt(o,a));else{t.add("spread");let a=e.svg?", isSVG: true":"";s.push(`spread({ element: ${o}, props: ${Ht(e.props,null,t)}${a} });`)}for(let a of e.children){t.add("insert");let l=F(a,t,n),c=a.kind==="expr"&&a.reactive||a.kind==="component"||a.kind==="control";s.push(c?`insert(${o}, ${l}, null);`:`insert(${o}, ${l});`)}return s.push(`return ${o};`),`(() => { ${s.join(" ")} })()`}}}function re(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(r=>[r.id,JSON.stringify(r.html)]));return e.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var O={name:"imperative",contract:ue,emit(e,t){let n=new Set,r=t?.templateClone!==!1?[]:void 0;return Be=t?.partialTemplates===!0,{code:F(e,n,r),imports:Array.from(n),templates:r}}};var Xt=e=>"components"in e;function _e(e,t){return e.replace(/\$(\d+)/g,(n,r)=>t[Number(r)]??n)}function Ut(e,t){return typeof t=="string"?{module:t,export:e}:t}function oe(e=[]){let t=new Map,n=[],r=[];for(let i of e){if(!Xt(i)){r.push(i);continue}for(let[a,l]of Object.entries(i.components)){let c=Ut(a,l),p=t.get(a);if(p&&p.module!==c.module){let f=n.find(d=>d.name===a);f?f.modules.push(c.module):n.push({name:a,modules:[p.module,c.module]});continue}t.set(a,c)}}let o=new Map;return{resolve:i=>{if(o.has(i))return o.get(i);let a=t.get(i);if(!a)for(let l of r){let c=i.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){a={module:_e(l.module,c),export:l.export?_e(l.export,c):i};break}}return o.set(i,a),a},names:()=>[...t.keys()],conflicts:()=>n}}var Ve=require("@fluixi/template-parser");function H(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let o=0;o<t.length;o++)/[^ \t]/.test(t[o])&&(n=o);let r="";for(let o=0;o<t.length;o++){let s=t[o].replace(/\t/g," ");o!==0&&(s=s.replace(/^ +/,"")),o!==t.length-1&&(s=s.replace(/ +$/,"")),s&&(o!==n&&(s+=" "),r+=s)}return r}var Fe=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function zt(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function He(e){return e.charAt(0).toUpperCase()+e.slice(1)}var fe=class{constructor(t,n){this.holes=t;this.used=n}hole(t){return this.holes[t]??{code:"undefined",reactive:!1}}emit(t){let{code:n,imports:r,templates:o}=O.emit(t,{});for(let s of r)this.used.add(s);return re(n,o)}lowerRoot(t){let n=this.lowerChildren(t);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(t){let n=[];for(let r=0;r<t.length;r++){let o=t[r];if(o.kind==="Element"||o.kind==="Component"){let i=o.attributes.find(a=>a.kind==="IfDirective");if(i&&i.kind==="IfDirective"){let a=r+1;a<t.length&&this.isBlankText(t[a])&&a++;let l=t[a],c=l&&(l.kind==="Element"||l.kind==="Component")&&l.attributes.some(p=>p.kind==="ElseDirective");n.push(this.lowerIf(o,i.hole,c?l:null)),c&&(r=a);continue}if(o.attributes.some(a=>a.kind==="EachDirective")){n.push(this.lowerEach(o));continue}}let s=this.lowerNode(o);s&&n.push(s)}return n}isBlankText(t){return t.kind==="Text"&&!t.raw&&H(t.value)===""}lowerNode(t){switch(t.kind){case"Text":{if(t.raw)return{kind:"text",value:t.value};let n=H(t.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(t.hole);return{kind:"expr",code:n.code,reactive:n.reactive}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(t.children)};case"Element":return this.lowerElement(t);case"Component":return this.lowerComponent(t);default:return null}}lowerElement(t){let n=t.attributes.find(r=>r.kind==="Attribute"&&r.name==="is");if(t.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let r=t.attributes.filter(s=>s!==n),o=this.lowerComponent({...t,kind:"Component",tag:"Dynamic",tagHole:null,attributes:r});return o.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),o}return{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:this.lowerAttributes(t.attributes),children:this.lowerChildren(t.children),static:!1}}lowerComponent(t){let n=t.tagHole!=null?this.hole(t.tagHole).code:t.tag,r=this.lowerAttributes(t.attributes),{slots:o,rest:s}=this.partitionSlots(t.children);for(let[l,c]of o){let p=c.length===1?c[0]:{kind:"fragment",children:c},f={name:l,kind:"attr",expr:this.emit(p),jsxElement:!0},d=r.findIndex(g=>g.name===l);d>=0?r[d]=f:r.push(f)}let i=t.attributes.find(l=>l.kind==="LoadDirective"),a=i?Z(`load:${i.strategy}`,i.modifier):void 0;return{kind:"component",name:n,props:r,children:this.lowerChildren(s),...a?{load:a}:{}}}partitionSlots(t){let n=new Map,r=[];for(let o of t){if(o.kind==="Element"||o.kind==="Component"){let s=o.attributes.find(i=>i.kind==="Attribute"&&i.name==="slot");if(s&&s.value&&s.value.kind==="static"){let i={...o,attributes:o.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}}r.push(o)}return{slots:n,rest:r}}lowerIf(t,n,r){let o=this.hole(n),s=[{name:"when",kind:"attr",expr:o.code,reactive:o.reactive}];if(r){let a=this.stripAndLower(r,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 r=this.hole(n.hole),o=[{name:"each",kind:"attr",expr:r.code,reactive:r.reactive}];if(n.key){let l="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;o.push({name:"by",kind:"attr",expr:l})}let s=this.itemArrow(t),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:o,children:[{kind:"expr",code:i,reactive:!1}]}}itemArrow(t){let n=t.children.filter(r=>!this.isBlankText(r));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(t,n){let r={...t,attributes:t.attributes.filter(o=>!n(o))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(t,n){let r=this.lowerAttributes(t.attributes.filter(o=>o.kind!=="EachDirective"));return t.kind==="Element"?{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:r,children:n,static:!1}:{kind:"component",name:t.tag,props:r,children:n}}lowerAttributes(t){let n=[],r=[],o=!1,s=[],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);r.push(`${JSON.stringify(l.name)}: ${c.code}`),o=o||c.reactive;break}case"StyleDirective":{let c=this.hole(l.hole);s.push(`${JSON.stringify(l.name)}: ${c.code}`),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 r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:o}),s.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${s.join(", ")} }`,reactive:i}),a.length>0&&n.push({name:"use",kind:"attr",expr:`[${a.join(", ")}]`}),n}eventProp(t){let n=t.name.toLowerCase(),r=this.hole(t.hole).code;if(!(t.syntax==="colon"||t.modifiers.length>0))return{name:"on"+He(t.name),kind:"event",event:{name:n,delegated:Fe.has(n)},expr:r};let s=this.wrapHandler(r,t.modifiers),i=this.eventOptions(t.modifiers),a=i?`[${s}, ${i}]`:s;return{name:"on:"+n,kind:"attr",expr:a}}wrapHandler(t,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",o=[];return n.includes("prevent")&&o.push("e.preventDefault();"),n.includes("stop")&&o.push("e.stopPropagation();"),!r&&o.length===0?t:`(e) => { ${r}${o.join(" ")} return (${t})(e); }`}eventOptions(t){let n=[];return t.includes("capture")&&n.push("capture: true"),t.includes("once")&&n.push("once: true"),t.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(t,n){let r=t==="checked",o=r?"change":"input",s=r?"checked":"value";this.used.add("bindPair");let i=`bindPair(${n})`;return[{name:t,kind:"attr",expr:`${i}[0]()`,reactive:!0},{name:"on"+He(o),kind:"event",event:{name:o,delegated:Fe.has(o)},expr:`(e) => ${i}[1](e.target.${s})`}]}plainAttr(t){let n=t.value,r=t.name;t.name==="class"?r=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":t.name==="html"&&(r="innerHTML");let s={name:r,kind:"attr"};if(n==null)return s.literal=!0,s;if(n.kind==="static")return s.literal=n.value,s;if(n.kind==="hole"){let l=this.hole(n.hole);return s.expr=l.code,s.reactive=l.reactive,s}let i=!1,a=n.parts.map(l=>{if("text"in l)return zt(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 Xe(e,t,n,r={}){let{root:o}=(0,Ve.parseTemplate)(e,{svg:r.svg});return new fe(t,n).lowerRoot(o.children)}function Ue(e,t,n={}){let r=new Set,o=Xe(e,[...t],r,{svg:n.svg});P(o),Y(o,{resolver:oe(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:l=>l.load}),ee(o);let{code:s,imports:i,templates:a}=O.emit(o,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let l of i)r.add(l);return n.hoistTemplates?{code:s,imports:[...r],ir:o,templates:a}:{code:re(s,a),imports:[...r],ir:o}}var Wt="children";function D(e){switch(e.kind){case"call":return!0;case"member":return e.property!==Wt;case"compound":return e.parts.some(D);case"opaque":return!1}}var qt=new Set(["CallExpression","OptionalCallExpression"]),Kt=new Set(["MemberExpression","OptionalMemberExpression"]);function A(e){if(!e)return{kind:"opaque"};if(qt.has(e.type))return{kind:"call"};if(Kt.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(V)}:e.type==="LogicalExpression"||e.type==="BinaryExpression"?{kind:"compound",parts:[e.left,e.right].map(V)}:e.type==="TemplateLiteral"?{kind:"compound",parts:e.expressions.map(V)}:e.type==="ObjectExpression"?{kind:"compound",parts:e.properties.filter(n=>(n.type==="ObjectProperty"||n.type==="Property")&&n.computed!==!0).map(n=>V(n.value))}:e.type==="ArrayExpression"?{kind:"compound",parts:e.elements.filter(n=>n!=null&&n.type!=="SpreadElement").map(V)}:{kind:"opaque"}}var V=e=>A(e);var Gt=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),Zt=/^on[A-Z]/,Yt=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),qe=e=>D(A(e));function X(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 me=e=>!!e&&typeof X(e)=="string";function Qt(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 ge(e){return e.type==="JSXIdentifier"?e.name==="class"?"className":e.name:e.type==="JSXNamespacedName"?`${e.namespace.name}:${e.name.name}`:"unknown"}function en(e,t){let n=ge(e.name),r=Zt.test(n),o=r||n.startsWith("on:")||n==="ref",i={name:n,kind:r?"event":"attr"};if(r){let l=n.slice(2).toLowerCase();i.event={name:l,delegated:Yt.has(l)}}let a=e.value;if(a==null)return i.literal=!0,i;if(me(a))return i.literal=X(a),i;if(a.type==="JSXExpressionContainer"&&a.expression?.type!=="JSXEmptyExpression"){let l=a.expression,c=X(l);return c!==void 0?(i.literal=c,i):(i.expr=t.code(l),i.reactive=o?!1:qe(l),(l.type==="JSXElement"||l.type==="JSXFragment")&&(i.jsxElement=!0),i)}return i.literal=!0,i}function ze(e,t){let n=e.value;return n==null?null:me(n)?JSON.stringify(X(n)):n.type==="JSXExpressionContainer"&&n.expression?.type!=="JSXEmptyExpression"?t.code(n.expression):null}function tn(e,t){let n=[],r=[];for(let o of e){if(o.type==="JSXSpreadAttribute"){n.push({name:"",kind:"spread",expr:t.code(o.argument)});continue}if(o.type!=="JSXAttribute"||le(ge(o.name)))continue;let s=o.name.type==="JSXNamespacedName"?o.name.namespace.name:null;if(s==="use"){let i=o.name.name.name;t.used.add(i);let a=ze(o,t);r.push(a!=null?`[${i}, () => (${a})]`:`[${i}]`);continue}if(s==="oncapture"){let i=o.name.name.name.toLowerCase(),a=ze(o,t)??"undefined";n.push({name:"on:"+i,kind:"attr",expr:`[${a}, { capture: true }]`});continue}n.push(en(o,t))}return r.length>0&&n.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),n}function We(e,t){let n=[];for(let r of e)if(r.type==="JSXText"){let o=H(r.value);o&&n.push({kind:"text",value:o})}else if(r.type==="JSXExpressionContainer"){if(r.expression?.type!=="JSXEmptyExpression"){let o=r.expression;n.push({kind:"expr",code:t.code(o),reactive:qe(o)})}}else r.type==="JSXElement"||r.type==="JSXFragment"?n.push(Ke(r,t)):r.type==="JSXSpreadChild"&&n.push({kind:"expr",code:t.code(r.expression),reactive:!1});return n}function nn(e){for(let t of e){if(t.type!=="JSXAttribute")continue;let n=ge(t.name);if(le(n)){if(t.value&&!me(t.value))throw new I(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return Z(n,t.value?X(t.value):null)}}}function Ke(e,t){if(e.type==="JSXFragment")return{kind:"fragment",children:We(e.children,t)};let{tag:n,component:r}=Qt(e.openingElement.name,t),o=tn(e.openingElement.attributes,t),s=We(e.children,t);if(r){let i=nn(e.openingElement.attributes);return{kind:"component",name:n,props:o,children:s,...i?{load:i}:{}}}return{kind:"element",tag:n,svg:Gt.has(n),props:o,children:s,static:!1}}function Ge(e,t){let n=Ke(e,t);return P(n),n}function w(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"?w(n.argument,t):w(n.value,t);return;case"ArrayPattern":for(let n of e.elements)w(n,t);return;case"AssignmentPattern":w(e.left,t);return;case"RestElement":w(e.argument,t);return}}function Ze(e,t){switch(e.type){case"ImportDeclaration":for(let n of e.specifiers)w(n.local,t);return;case"VariableDeclaration":for(let n of e.declarations)w(n.id,t);return;case"FunctionDeclaration":case"ClassDeclaration":w(e.id,t);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&Ze(e.declaration,t);return}}function he(e){let t=new Set;for(let n of e.body)Ze(n,t);return t}var sn=require("@babel/parser"),an=Ie(require("magic-string"),1);function k(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?k(n.argument,t):k(n.value,t);return;case"ArrayPattern":for(let n of e.elements)k(n,t);return;case"AssignmentPattern":k(e.left,t);return;case"RestElement":k(e.argument,t);return}}function ye(e){switch(e.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"NullLiteral":case"BigIntLiteral":case"RegExpLiteral":case"Identifier":return!0;case"Literal":return!0;case"TemplateLiteral":return e.expressions.every(ye);case"UnaryExpression":return ye(e.argument);case"MemberExpression":return!1;default:return!1}}function se(e,t){if(!(!e||typeof e!="object")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="range"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let o of r)o&&typeof o=="object"&&se(o,t);else r&&typeof r=="object"&&typeof r.type=="string"&&se(r,t)}}}function rn(e){let t=new Set;return se(e,n=>{if(n.type==="AssignmentExpression")k(n.left,t);else if(n.type==="UpdateExpression"){let r=n.argument;r?.type==="Identifier"&&t.add(r.name)}}),t}function on(e,t){let n=new Set,r=o=>{let s=new Set;k(o,s);for(let i of s)t.has(i)&&n.add(i)};return se(e,o=>{switch(o.type){case"VariableDeclarator":r(o.id);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":r(o.id);for(let s of o.params??[])r(s);return;case"CatchClause":r(o.param);return;case"ClassDeclaration":case"ClassExpression":r(o.id);return}}),n}function Ye(e,t,n){for(let r of e.properties??[]){if(r.type==="RestElement"){let p=r.argument;if(p?.type!=="Identifier"||t.length>0){let f=new Set;k(p,f);for(let d of f)n.bails.push({name:d,reason:"rest"});continue}n.rest={name:p.name,keys:[]};continue}if(r.computed){let p=new Set;k(r.value,p);for(let f of p)n.bails.push({name:f,reason:"computed"});continue}let o=r.key,s=o.type==="Identifier"?o.name:o.value,i=r.value,a;i.type==="AssignmentPattern"&&(a=i.right,i=i.left);let l=[...t,s];if(i.type==="Identifier"){if(a&&!ye(a)){n.bails.push({name:i.name,reason:"unsafe-default"});continue}n.reads.push({name:i.name,path:l,...a?{fallback:a}:{}});continue}if(i.type==="ObjectPattern"){if(a){let p=new Set;k(i,p);for(let f of p)n.bails.push({name:f,reason:"unsafe-default"});continue}Ye(i,l,n);continue}let c=new Set;k(i,c);for(let p of c)n.bails.push({name:p,reason:"computed"})}}function Qe(e,t){let n={reads:[],bails:[]};if(e?.type!=="ObjectPattern"||(Ye(e,[],n),n.rest&&(t?.type!=="BlockStatement"?(n.bails.push({name:n.rest.name,reason:"rest"}),delete n.rest):n.rest.keys=(e.properties??[]).filter(a=>a.type!=="RestElement"&&!a.computed).map(a=>{let l=a.key;return l.type==="Identifier"?l.name:l.value})),n.reads.length===0&&!n.rest))return n;let r=new Set(n.reads.map(a=>a.name));n.rest&&r.add(n.rest.name);let o=rn(t),s=on(t,r),i=[];for(let a of n.reads)o.has(a.name)?n.bails.push({name:a.name,reason:"reassigned"}):s.has(a.name)?n.bails.push({name:a.name,reason:"shadowed"}):i.push(a);return n.reads=i,n.rest&&o.has(n.rest.name)?(n.bails.push({name:n.rest.name,reason:"reassigned"}),delete n.rest):n.rest&&s.has(n.rest.name)&&(n.bails.push({name:n.rest.name,reason:"shadowed"}),delete n.rest),n}function et(e){switch(e){case"rest":return"this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";case"computed":return"the property is not known until it runs";case"reassigned":return"the binding is assigned to, and props are read-only";case"shadowed":return"an inner scope binds the same name";case"unsafe-default":return"the default would have to run again on every read"}}function U(e,t,n=null){if(!(!e||typeof e!="object"||typeof e.type!="string")&&!e.type.startsWith("TS")&&t(e,n)!==!1)for(let r of Object.keys(e)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let o=e[r];if(Array.isArray(o))for(let s of o)U(s,t,e);else o&&typeof o=="object"&&U(o,t,e)}}function tt(e){return!!e&&e[0]>="A"&&e[0]<="Z"}function ln(e){let t=[];return U(e,n=>{if(n.type==="FunctionDeclaration"&&tt(n.id?.name)){t.push(n);return}if(n.type==="VariableDeclarator"&&tt(n.id?.name)){let r=n.init;r&&(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")&&t.push(r)}}),t}function cn(e){let t=new Set;return U(e,n=>{n.type==="Identifier"&&t.add(n.name)}),t}function pn(e,t){if(!t)return!0;switch(t.type){case"MemberExpression":case"OptionalMemberExpression":return!(t.property===e&&!t.computed);case"ObjectProperty":case"ObjectMethod":case"ClassProperty":case"ClassMethod":return!(t.key===e&&!t.computed);case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return t.label!==e;case"ImportSpecifier":case"ExportSpecifier":return!1;default:return!0}}function nt(e,t,n={}){let r=[],o=[],s=new Set;for(let i of ln(e)){let a=i.params?.[0];if(a?.type!=="ObjectPattern")continue;let l=Qe(a,i.body);for(let m of l.bails)o.push({name:m.name,reason:m.reason,message:et(m.reason),start:a.start});if(l.bails.length>0||l.reads.length===0&&!l.rest)continue;let c=cn(i),p=n.parameterName??"props";for(;c.has(p);)p=`_${p}`;let f=new Map;for(let m of l.reads){let h=`${p}.${m.path.join(".")}`,v=m.fallback;f.set(m.name,v?`(${h} === undefined ? ${t.slice(v.start,v.end)} : ${h})`:h)}let d=a.typeAnnotation;if(r.push({start:a.start,end:d?.start??a.end,code:p}),l.rest){let m=l.rest.keys.map(v=>JSON.stringify(v)).join(", "),h=i.body;r.push({start:h.start+1,end:h.start+1,code:`
|
|
2
|
-
const [, ${
|
|
1
|
+
"use strict";var Tt=Object.create;var ne=Object.defineProperty;var Pt=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var Ot=Object.getPrototypeOf,At=Object.prototype.hasOwnProperty;var Dt=(e,t)=>{for(var n in t)ne(e,n,{get:t[n],enumerable:!0})},De=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Mt(t))!At.call(e,i)&&i!==n&&ne(e,i,{get:()=>t[i],enumerable:!(r=Pt(t,i))||r.enumerable});return e};var Le=(e,t,n)=>(n=e!=null?Tt(Ot(e)):{},De(t||!e||!e.__esModule?ne(n,"default",{value:e,enumerable:!0}):n,e)),Lt=e=>De(ne({},"__esModule",{value:!0}),e);var tr={};Dt(tr,{transformTemplates:()=>Yn});module.exports=Lt(tr);var Et=require("@babel/parser"),It=Le(require("magic-string"),1);function jt(e){switch(e.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return e.reactive?"reactive-prop":e.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function j(e){let t=[],n=new Map,r=i=>{switch(i.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let o of i.children)r(o);return!1;case"fragment":for(let o of i.children)r(o);return!1;case"element":{let o=!0;for(let s of i.children)r(s)||(o=!1);let a;for(let s of i.props)if(a=jt(s),a)break;return!a&&!o&&(a=Jt(i)),i.static=!a,a?n.set(i,a):t.push(i),i.static}default:return!1}};for(let i of Array.isArray(e)?e:[e])r(i);return{staticElements:t,reasons:n}}function Jt(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 re={kind:"eager"},_t=["pointerdown","focusin","keydown"],je=new Set(["eager","idle","visible","interaction","media","never"]),P=class extends Error{};function ye(e){return e.startsWith("load:")}function ie(e,t){let n=e.slice(5);if(!je.has(n))throw new P(`Unknown load strategy 'load:${n}'. Expected one of ${[...je].join(", ")}.`);switch(n){case"eager":return re;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?Ft(t):[..._t]};case"media":if(!t)throw new P(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new P(`Unhandled load strategy '${n}'.`)}}function Ft(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new P("'load:interaction' was given no event names.");return t}function H(e){return e.kind!=="eager"&&e.kind!=="never"}var V=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],U=["Suspense","SuspenseList","Await"],J=["Router","Outlet","Redirect","Link"],or=[...V,...U,...J],Ne=new Set([...V,...U]);function Je(e={}){let{controlFlowModule:t="@fluixi/dom",coreModule:n="@fluixi/core",routerModule:r="@fluixi/core/router"}=e,i={};for(let o of V)i[o]=t;for(let o of U)i[o]=n;for(let o of J)i[o]=r;return i}function oe(e,t={}){let{resolver:n,isBound:r,modules:i,strategyFor:o}=t,a=Je(i),s=new Map,c=new Set,p=d=>{let{name:u}=d;if(!u||u.includes(".")||r?.(u))return;let g=l(u);if(!g){c.add(u);return}let m=g.origin==="builtin"&&Ne.has(u)?re:o?.(d)??re;d.source={...g,loading:m},s.set(u,d.source)},l=d=>{if(Ne.has(d))return{module:a[d],export:d,origin:"builtin"};let u=n?.resolve(d);if(u)return{module:u.module,export:u.export,origin:"rule"};if(J.includes(d))return{module:a[d],export:d,origin:"builtin"}};return se(e,d=>{d.kind==="component"&&p(d)}),{resolved:s,unresolved:[...c]}}function se(e,t){let n=Array.isArray(e)?e:[e];for(let r of n){t(r);let i=r.children;i&&se(i,t)}}function ae(e){let t=[];se(e,o=>{o.kind==="component"&&o.source&&t.push(o)});let n=new Set,r=new Set;for(let o of t){let{module:a,loading:s}=o.source;s.kind==="eager"&&n.add(a),s.kind==="never"&&r.add(a)}let i=new Map;for(let o of t){let a=o.source;H(a.loading)&&n.has(a.module)&&(a.loading={kind:"eager"},i.set(a.module,(i.get(a.module)??0)+1))}return{collapsed:i,conflicted:[...r].filter(o=>n.has(o))}}var Bt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),_e={className:"class",htmlFor:"for"},Ht=new Set(["innerHTML","outerHTML","innerText","textContent","value","checked","selected","muted","defaultValue","defaultChecked","children","ref"]),Vt=new Set(["script","style","textarea","title"]);function ve(e){return Vt.has(e)}function Fe(e){return _e[e]??e}function X(e){return e.kind!=="attr"||e.expr!==void 0||e.name.includes(":")?!1:!Ht.has(e.name)}function Re(e){if(!e.static||ve(e.tag))return!1;for(let t of e.props)if(!X(t))return!1;for(let t of e.children)if(t.kind!=="text"&&!(t.kind==="element"&&Re(t)))return!1;return!0}function W(e){let t=e.props.map(Xt).filter(Boolean).join(""),n=`<${e.tag}${t}>`;return Bt.has(e.tag)?n:`${n}${e.children.map(Ut).join("")}</${e.tag}>`}function Ut(e){if(e.kind==="text")return zt(e.value);if(e.kind!=="element")throw new Error(`serializeStatic: unexpected ${e.kind}`);return W(e)}function Xt(e){let t=_e[e.name]??e.name,n=e.literal;return n===!0||n===void 0?` ${t}`:n===!1||n===null?"":` ${t}="${Wt(String(n))}"`}function Wt(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function zt(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function xe(e){let t=[],n,r=i=>{n??=i.at?.file,t.push(i.at?.line??0,i.at?.column??0);for(let o of i.children)o.kind==="element"&&r(o)};return r(e),n&&t.some(i=>i!==0)?{file:n,pos:t}:void 0}var Kt="<!--fx-->",qt="<!--fx/-->";function ce(e){return e.kind==="expr"||e.kind==="component"||e.kind==="control"}function Gt(e){return e.kind==="text"||e.kind==="element"&&Be(e)}function Be(e){return e.svg||ve(e.tag)||!e.props.every(t=>X(t))?!1:e.children.every(t=>Gt(t)||ce(t))}function le(e){if(ce(e))return!0;let t=e.children;return t?t.some(le):!1}function He(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"||He(t))}function Ve(e){if(!Be(e)||!He(e)||!e.children.some(le))return null;let t=[],n=[],r=0,i=a=>{let s=`_n$${r++}`;return t.push({ref:s,expr:a}),s};return o(e,"_el$"),{html:Zt(e),tag:e.tag,steps:t,holes:n};function o(a,s){let c=-1;a.children.forEach((l,d)=>{le(l)&&(c=d)});let p=null;for(let l=0;l<=c;l++){let d=a.children[l],u=p?`${p}.nextSibling`:`${s}.firstChild`;if(ce(d)){let m=i(u),y=i(`holeEnd(${m})`);n.push({parentRef:s,startRef:m,endRef:y,node:d}),p=y;continue}let g=i(u);d.kind==="element"&&le(d)&&o(d,g),p=g}}}function Zt(e){return W(Ue(e)).split(Xe).join(Kt+qt)}function Ue(e){return{...e,children:e.children.map(t=>ce(t)?{kind:"text",value:Xe}:t.kind==="element"?Ue(t):t)}}var Xe="\0fx-hole\0";var be={version:1,module:"@fluixi/dom",symbols:["createNativeElement","insert","spread","setAttribute","delegateEvents","createComponent","createMemo","untrack","Show","For","Index","Switch","Match","Dynamic","ErrorBoundary"]},hr={version:2,module:"@fluixi/dom",symbols:[...be.symbols,"template","cloneTemplate","walk"]};var D="@fluixi/reactive/signal",w={$signal:{export:"signal",module:D,returns:"signal-handle"},$memo:{export:"memo",module:D,returns:"memo-handle"},$effect:{export:"effect",module:D,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:D,returns:"resource-handle"},$selector:{export:"createSelector",module:D,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:D,returns:"memo-accessor"},$untrack:{export:"untrack",module:D,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}},We={signal:"signal-handle",memo:"memo-handle",effect:"effect",store:"store-handle",createSignal:["signal-accessor","signal-setter"],createMemo:"memo-accessor",createEffect:"effect",createRenderEffect:"effect",createStore:"reactive-object",resource:"resource-handle",createResource:"reactive-object",createSelector:"memo-accessor",createDeferred:"memo-accessor"},Yt=["@fluixi/reactive","@fluixi/reactive/signal","@fluixi/reactive/store","@fluixi/core"],Qt=new RegExp(`\\$(?:${Object.keys(w).map(e=>e.slice(1)).join("|")})\\s*\\(`);function ze(e){return Qt.test(e)}function ue(e){return Object.prototype.hasOwnProperty.call(w,e)}function Ke(e){return Yt.includes(e)}function v(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties??[])n.type==="RestElement"?v(n.argument,t):v(n.value,t);return;case"ArrayPattern":for(let n of e.elements??[])v(n,t);return;case"AssignmentPattern":v(e.left,t);return;case"RestElement":v(e.argument,t);return}}function z(e,t){if(!(!e||typeof e!="object"||typeof e.type!="string")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let i of r)z(i,t);else r&&typeof r=="object"&&z(r,t)}}}function en(e,t){if(e.type!=="CallExpression")return;let n=e.callee;if(n?.type!=="Identifier")return;let r=n.name,i=t.primitives.get(r);if(i)return i;let o=w[r];if(o&&!t.shadowed.has(r))return o.returns}function tn(e,t,n){if(Array.isArray(t)){e.type==="ArrayPattern"&&e.elements.forEach((r,i)=>{let o=t[i];r?.type==="Identifier"&&o&&n.set(r.name,o)});return}e.type==="Identifier"&&n.set(e.name,t)}function qe(e){let t=new Set;return z(e,n=>{switch(n.type){case"VariableDeclarator":v(n.id,t);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":v(n.id,t);for(let r of n.params??[])v(r,t);return;case"ClassDeclaration":case"ClassExpression":v(n.id,t);return;case"ImportSpecifier":case"ImportDefaultSpecifier":case"ImportNamespaceSpecifier":v(n.local,t);return;case"CatchClause":v(n.param,t);return}}),t}function pe(e){let t={kinds:new Map,primitives:new Map,shadowed:new Set},n=e;z(n,r=>{let i=new Set;if(r.type==="VariableDeclarator")v(r.id,i);else if(r.type==="FunctionDeclaration"||r.type==="ClassDeclaration")v(r.id,i);else if(r.type==="ImportDefaultSpecifier"||r.type==="ImportNamespaceSpecifier")v(r.local,i);else if(r.type==="ImportSpecifier")v(r.local,i);else if(r.type==="FunctionExpression"||r.type==="ArrowFunctionExpression"||r.type==="FunctionDeclaration")for(let o of r.params??[])v(o,i);for(let o of i)w[o]&&t.shadowed.add(o)});for(let r of n.body??[])if(r.type==="ImportDeclaration"&&Ke(r.source?.value))for(let i of r.specifiers??[]){if(i.type!=="ImportSpecifier")continue;let o=i.imported,a=o.type==="Identifier"?o.name:o.value,s=We[a];s&&t.primitives.set(i.local.name,s)}return z(n,r=>{if(r.type!=="VariableDeclarator"||!r.init)return;let i=en(r.init,t);i&&tn(r.id,i,t.kinds)}),t}var ke="__fx_source",nn="__fx_component",rn="__fx_hole",K=(e,t,n,r)=>`(globalThis.${rn} ?? ((f) => f))(${e},${t},${n}${r===void 0?"":`,${JSON.stringify(r)}`})`,on="__fx_props",Ze=(e,t)=>`(globalThis.${on} ?? ((p) => p))(${e},${JSON.stringify(t)})`,Ye=new Set(["signal","memo","effect","store","resource","watch","createSignal","createMemo","createEffect","createStore","createResource"]);function Qe(e){for(let t of Ye)if(e.includes(t))return!0;return e.includes("$signal")||e.includes("$memo")||e.includes("$effect")||e.includes("$store")}var sn=new Set(["IfStatement","ForStatement","ForInStatement","ForOfStatement","WhileStatement","DoWhileStatement","LabeledStatement","WithStatement"]);function an(e,t){return!t||e.type==="BlockStatement"?!1:sn.has(t.type)}function Ge(e){return e.type==="ExportNamedDeclaration"||e.type==="ExportDefaultDeclaration"}function ln(e){return e.type.endsWith("Statement")||e.type==="VariableDeclaration"}function Se(e,t,n=[]){if(!(!e||typeof e.type!="string")){t(e,n),n.push(e);for(let r of Object.keys(e)){if(r==="loc"||r==="parent")continue;let i=e[r];if(Array.isArray(i))for(let o of i)Se(o,t,n);else i&&typeof i.type=="string"&&Se(i,t,n)}n.pop()}}function cn(e){let t=e[e.length-1];if(t?.type!=="VariableDeclarator")return;let n=t.id;if(n?.type==="Identifier")return n.name;if(n?.type==="ArrayPattern"){let r=n.elements?.[0];if(r?.type==="Identifier")return r.name}}function un(e){if(e.type==="FunctionDeclaration"){let t=e.id?.name;return t&&t[0]===t[0]?.toUpperCase()?t:void 0}if(e.type==="VariableDeclarator"){let t=e.id,n=e.init;if(t?.type!=="Identifier"||!n||n.type!=="ArrowFunctionExpression"&&n.type!=="FunctionExpression")return;let r=t.name;return r[0]===r[0]?.toUpperCase()?r:void 0}}function et(e,t){let n=[],r=new Set,{primitives:i,shadowed:o}=pe(e);return Se(e,(a,s)=>{let c=un(a);if(c){let h=a.loc?.start,C=a.end;for(let L=s.length-1;L>=0;L--){let A=s[L];if(A.type!=="VariableDeclaration"&&A.type!=="ExportNamedDeclaration"&&A.type!=="ExportDefaultDeclaration")break;C=A.end}h&&n.push({start:C,end:C,code:`;globalThis.${nn}?.(${JSON.stringify(c)},${JSON.stringify(t)},${h.line},${h.column});`})}if(a.type!=="CallExpression")return;let p=a.callee;if(p?.type!=="Identifier")return;let l=p.name,d=ue(l)&&!o.has(l)?w[l]:void 0,u=i.has(l)||Ye.has(l);if(!d&&!u)return;let g=a.loc?.start;if(!g)return;let m,y,b=-1;for(let h=s.length-1;h>=0;h--)if(ln(s[h])||Ge(s[h])){m=s[h],y=s[h-1],b=h;break}if(!m)return;let x=m.start,N=m.end;for(let h=b-1;h>=0&&Ge(s[h]);h--)x=s[h].start,N=s[h].end,y=s[h-1];if(r.has(x))return;r.add(x);let $=cn(s),O=[JSON.stringify(t),String(g.line),String(g.column),$?JSON.stringify($):void 0].filter(h=>h!==void 0).join(","),I=`globalThis.${ke}?.(${O});`;if(an(m,y)){n.push({start:x,end:x,code:`{${I}`}),n.push({start:N,end:N,code:"}"});return}n.push({start:x,end:x,code:I})}),{edits:n,marked:n.length}}var pn={show:"Show",for:"For",index:"Index",switch:"Switch",match:"Match",dynamic:"Dynamic",errorBoundary:"ErrorBoundary",suspense:"Suspense"};function dn(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function rt(e){return dn(e)?e:JSON.stringify(e)}function fn(e){if(e.expr!==void 0){if(e.name==="ref"&&e.at)return K(`(${e.expr})`,e.at.line,e.at.column,e.expr);if(!e.reactive)return`(${e.expr})`;let t=`() => (${e.expr})`;return e.at?K(t,e.at.line,e.at.column,e.directive):t}return JSON.stringify(e.literal??!0)}function mn(e){return e.expr!==void 0?`(${e.expr})`:JSON.stringify(e.literal??!0)}function gn(e,t,n){let r=e.filter(s=>s.kind==="spread"),o=e.filter(s=>s.kind!=="spread").map(s=>`${rt(s.name)}: ${fn(s)}`);t!=null&&o.push(`children: ${t}`);let a=`{ ${o.join(", ")} }`;return r.length>0?(n.add("mergeProps"),`mergeProps(${r.map(s=>s.expr).join(", ")}, ${a})`):a}function tt(e,t){return t?K(e,t.line,t.column):e}function it(e,t,n){return e.length===1?q(e[0],t,n):`[${e.map(r=>q(r,t,n)).join(", ")}]`}function nt(e,t,n,r,i,o){r.add("createMemo"),r.add("createComponent");let a=t.filter(u=>u.kind==="spread"),s=t.filter(u=>u.kind!=="spread"),c=s.map(u=>`get ${rt(u.name)}() { return ${mn(u)}; }`);n.length>0&&c.push(`get children() { return ${it(n,r,i)}; }`);let p=`{ ${c.join(", ")} }`;a.length>0&&(r.add("mergeProps"),p=`mergeProps(${a.map(u=>u.expr).join(", ")}, ${p})`);let l={};for(let u of s)u.at&&(l[u.name]=[u.at.line,u.at.column]);return Object.keys(l).length&&(p=Ze(p,l)),`createMemo((${o?`globalThis.${ke}?.(${JSON.stringify(o.file)},${o.line},${o.column},${JSON.stringify(e)}), `:""}() => createComponent(${e}, ${p})))`}function hn(e,t){let n=Fe(t.name),r=t.literal;return r===!0||r===void 0?`${e}.setAttribute(${JSON.stringify(n)}, "");`:r===!1||r===null?"":`${e}.setAttribute(${JSON.stringify(n)}, ${JSON.stringify(String(r))});`}var ot=!1;function q(e,t,n){switch(e.kind){case"text":return JSON.stringify(e.value);case"expr":{if(!e.reactive)return`(${e.code})`;let r=`() => (${e.code})`;return e.at?K(r,e.at.line,e.at.column):r}case"fragment":return e.children.length===0?"null":it(e.children,t,n);case"component":return tt(nt(e.name,e.props,e.children,t,n,e.at),e.bindAt??e.at);case"control":{let r=pn[e.control]??e.control;return t.add(r),tt(nt(r,e.props,e.children,t,n),e.bindAt)}case"element":{if(n&&e.static&&!e.svg&&Re(e)){t.add("templateNode");let s=`_tmpl$${n.length}`;n.push({id:s,html:W(e),tag:e.tag,svg:!1});let c=xe(e);return c?`templateNode(${s}, ${JSON.stringify(e.tag)}, false, false, ${JSON.stringify(c)})`:`templateNode(${s}, ${JSON.stringify(e.tag)})`}if(n&&ot){let s=Ve(e);if(s){t.add("templateNode"),t.add("insert"),t.add("holeEnd"),t.add("holeContent"),t.add("holeScope");let c=`_tmpl$${n.length}`;n.push({id:c,html:s.html,tag:s.tag,svg:!1});let p=xe(e),l=[`const _el$ = templateNode(${c}, ${JSON.stringify(s.tag)}, true${p?`, false, ${JSON.stringify(p)}`:""});`];for(let d of s.steps)l.push(`const ${d.ref} = ${d.expr};`);for(let d of s.holes)l.push(`insert(${d.parentRef}, holeScope(${d.startRef}, () => (${q(d.node,t,n)})), ${d.endRef}, holeContent(${d.startRef}, ${d.endRef}));`);return l.push("return _el$;"),`(() => { ${l.join(" ")} })()`}}t.add("createNativeElement");let r=JSON.stringify(e.tag),i="_el$",o=[],a=e.at?`${r}, ${e.svg}, ${JSON.stringify(e.at)}`:e.svg?`${r}, true`:r;if(o.push(`const ${i} = createNativeElement(${a});`),e.props.length>0)if(!e.svg&&e.props.every(X))for(let s of e.props)o.push(hn(i,s));else{t.add("spread");let s=e.svg?", isSVG: true":"";o.push(`spread({ element: ${i}, props: ${gn(e.props,null,t)}${s} });`)}for(let s of e.children){t.add("insert");let c=q(s,t,n),p=s.kind==="expr"&&s.reactive||s.kind==="component"||s.kind==="control";o.push(p?`insert(${i}, ${c}, null);`:`insert(${i}, ${c});`)}return o.push(`return ${i};`),`(() => { ${o.join(" ")} })()`}}}function de(e,t){if(!t||t.length===0)return e;let n=new Map(t.map(r=>[r.id,JSON.stringify(r.html)]));return e.replace(/_tmpl\$\d+/g,r=>n.get(r)??r)}var _={name:"imperative",contract:be,emit(e,t){let n=new Set,r=t?.templateClone!==!1?[]:void 0;return ot=t?.partialTemplates===!0,{code:q(e,n,r),imports:Array.from(n),templates:r}}};var yn=e=>"components"in e;function st(e,t){return e.replace(/\$(\d+)/g,(n,r)=>t[Number(r)]??n)}function Nn(e,t){return typeof t=="string"?{module:t,export:e}:t}function fe(e=[]){let t=new Map,n=[],r=[];for(let a of e){if(!yn(a)){r.push(a);continue}for(let[s,c]of Object.entries(a.components)){let p=Nn(s,c),l=t.get(s);if(l&&l.module!==p.module){let d=n.find(u=>u.name===s);d?d.modules.push(p.module):n.push({name:s,modules:[l.module,p.module]});continue}t.set(s,p)}}let i=new Map;return{resolve:a=>{if(i.has(a))return i.get(a);let s=t.get(a);if(!s)for(let c of r){let p=a.match(new RegExp(c.match.source,c.match.flags.replace("g","")));if(p){s={module:st(c.module,p),export:c.export?st(c.export,p):a};break}}return i.set(a,s),s},names:()=>[...t.keys()],conflicts:()=>n}}var ct=require("@fluixi/template-parser");function G(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let i=0;i<t.length;i++)/[^ \t]/.test(t[i])&&(n=i);let r="";for(let i=0;i<t.length;i++){let o=t[i].replace(/\t/g," ");i!==0&&(o=o.replace(/^ +/,"")),i!==t.length-1&&(o=o.replace(/ +$/,"")),o&&(i!==n&&(o+=" "),r+=o)}return r}var at=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]);function vn(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}function lt(e){return e.charAt(0).toUpperCase()+e.slice(1)}var Ee=class{constructor(t,n,r,i){this.holes=t;this.used=n;this.sourceFile=r;this.positionAt=i}tagAt(t){let n=t.loc?.start;if(!this.sourceFile||!this.positionAt||n==null)return;let{line:r,column:i}=this.positionAt(n);return{file:this.sourceFile,line:r,column:i}}hole(t){return this.holes[t]??{code:"undefined",reactive:!1}}emit(t){let{code:n,imports:r,templates:i}=_.emit(t,{});for(let o of r)this.used.add(o);return de(n,i)}lowerRoot(t){let n=this.lowerChildren(t);return n.length===1?n[0]:{kind:"fragment",children:n}}lowerChildren(t){let n=[];for(let r=0;r<t.length;r++){let i=t[r];if(i.kind==="Element"||i.kind==="Component"){let a=i.attributes.find(s=>s.kind==="IfDirective");if(a&&a.kind==="IfDirective"){let s=r+1;s<t.length&&this.isBlankText(t[s])&&s++;let c=t[s],p=c&&(c.kind==="Element"||c.kind==="Component")&&c.attributes.some(l=>l.kind==="ElseDirective");n.push(this.lowerIf(i,a.hole,p?c:null)),p&&(r=s);continue}if(i.attributes.some(s=>s.kind==="EachDirective")){n.push(this.lowerEach(i));continue}}let o=this.lowerNode(i);o&&n.push(o)}return n}isBlankText(t){return t.kind==="Text"&&!t.raw&&G(t.value)===""}lowerNode(t){switch(t.kind){case"Text":{if(t.raw)return{kind:"text",value:t.value};let n=G(t.value);return n?{kind:"text",value:n}:null}case"Comment":return null;case"Expression":{let n=this.hole(t.hole);return{kind:"expr",code:n.code,reactive:n.reactive,...n.at?{at:n.at}:{}}}case"Fragment":return{kind:"fragment",children:this.lowerChildren(t.children)};case"Element":return this.lowerElement(t);case"Component":return this.lowerComponent(t);default:return null}}lowerElement(t){let n=t.attributes.find(i=>i.kind==="Attribute"&&i.name==="is");if(t.tag==="component"&&n&&n.value&&n.value.kind==="hole"){let i=t.attributes.filter(a=>a!==n),o=this.lowerComponent({...t,kind:"Component",tag:"Dynamic",tagHole:null,attributes:i});return o.props.unshift({name:"component",kind:"attr",expr:`() => (${this.hole(n.value.hole).code})`}),o}let r=this.tagAt(t);return{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:this.lowerAttributes(t.attributes),children:this.lowerChildren(t.children),static:!1,...r?{at:r}:{}}}lowerComponent(t){let n=t.tagHole!=null?this.hole(t.tagHole).code:t.tag,r=this.lowerAttributes(t.attributes),{slots:i,rest:o}=this.partitionSlots(t.children);for(let[l,d]of i){let u=d.length===1?d[0]:{kind:"fragment",children:d},g={name:l,kind:"attr",expr:this.emit(u),jsxElement:!0},m=r.findIndex(y=>y.name===l);m>=0?r[m]=g:r.push(g)}let a=t.attributes.find(l=>l.kind==="LoadDirective"),s=a?ie(`load:${a.strategy}`,a.modifier):void 0,c=r.find(l=>l.at&&l.reactive)?.at,p=this.tagAt(t);return{kind:"component",name:n,props:r,children:this.lowerChildren(o),...p?{at:p}:{},...c?{bindAt:c}:{},...s?{load:s}:{}}}partitionSlots(t){let n=new Map,r=[];for(let i of t){if(i.kind==="Element"||i.kind==="Component"){let o=i.attributes.find(a=>a.kind==="Attribute"&&a.name==="slot");if(o&&o.value&&o.value.kind==="static"){let a={...i,attributes:i.attributes.filter(p=>p!==o)},s=a.kind==="Element"?this.lowerElement(a):this.lowerComponent(a),c=n.get(o.value.value)??[];c.push(s),n.set(o.value.value,c);continue}}r.push(i)}return{slots:n,rest:r}}lowerIf(t,n,r){let i=this.hole(n),o=[{name:"when",kind:"attr",expr:i.code,reactive:i.reactive,...i.at?{at:i.at}:{}}];if(r){let c=this.stripAndLower(r,p=>p.kind==="ElseDirective");o.push({name:"fallback",kind:"attr",expr:this.emit(c),jsxElement:!0})}let a=this.stripAndLower(t,c=>c.kind==="IfDirective"),s=this.tagAt(t);return{kind:"component",name:"Show",props:o,children:[a],...s?{at:s}:{},...i.at?{bindAt:i.at}:{}}}lowerEach(t){let n=t.attributes.find(p=>p.kind==="EachDirective");if(!n||n.kind!=="EachDirective")return this.lowerNode(t);let r=this.hole(n.hole),i=[{name:"each",kind:"attr",expr:r.code,reactive:r.reactive,...r.at?{at:r.at}:{}}];if(n.key){let p="static"in n.key?`(item) => item[${JSON.stringify(n.key.static)}]`:this.hole(n.key.hole).code;i.push({name:"by",kind:"attr",expr:p})}let o=this.itemArrow(t),a;if(o){let p={kind:"expr",code:o.body,reactive:o.bodyReactive},l=this.rebuildWithChildren(t,[p]);a=`(${o.params.join(", ")}) => (${this.emit(l)})`}else{let p=this.stripAndLower(t,l=>l.kind==="EachDirective");a=`() => (${this.emit(p)})`}let s=[{kind:"expr",code:a,reactive:!1}],c=this.tagAt(t);return{kind:"component",name:"For",props:i,children:s,...c?{at:c}:{},...r.at?{bindAt:r.at}:{}}}itemArrow(t){let n=t.children.filter(r=>!this.isBlankText(r));return n.length!==1||n[0].kind!=="Expression"?null:this.hole(n[0].hole).arrow??null}stripAndLower(t,n){let r={...t,attributes:t.attributes.filter(i=>!n(i))};return r.kind==="Element"?this.lowerElement(r):this.lowerComponent(r)}rebuildWithChildren(t,n){let r=this.lowerAttributes(t.attributes.filter(i=>i.kind!=="EachDirective"));if(t.kind==="Element"){let i=this.tagAt(t);return{kind:"element",tag:t.tag,svg:t.namespace==="svg",props:r,children:n,static:!1,...i?{at:i}:{}}}return{kind:"component",name:t.tag,props:r,children:n}}lowerAttributes(t){let n=[],r=[],i=!1,o,a=[],s=!1,c,p=[];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,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});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,...this.hole(l.hole).at?{at:this.hole(l.hole).at}:{}});break;case"Spread":n.push({name:"",kind:"spread",expr:this.hole(l.hole).code});break;case"ClassDirective":{let d=this.hole(l.hole);r.push(`${JSON.stringify(l.name)}: ${d.code}`),i=i||d.reactive,o??=d.at;break}case"StyleDirective":{let d=this.hole(l.hole);a.push(`${JSON.stringify(l.name)}: ${d.code}`),s=s||d.reactive,c??=d.at;break}case"BindDirective":n.push(...this.bindProps(l.name,this.hole(l.hole)));break;case"UseDirective":{let d=l.name??(l.hole!=null?this.hole(l.hole).code:null);if(!d)break;p.push(l.name!=null&&l.hole!=null?`[${d}, () => (${this.hole(l.hole).code})]`:`[${d}]`);break}}return r.length>0&&n.push({name:"classList",kind:"attr",expr:`{ ${r.join(", ")} }`,reactive:i,...o?{at:o}:{}}),a.length>0&&n.push({name:"style",kind:"attr",expr:`{ ${a.join(", ")} }`,reactive:s,...c?{at:c}:{}}),p.length>0&&n.push({name:"use",kind:"attr",expr:`[${p.join(", ")}]`}),n}eventProp(t){let n=t.name.toLowerCase(),r=this.hole(t.hole).code;if(!(t.syntax==="colon"||t.modifiers.length>0))return{name:"on"+lt(t.name),kind:"event",event:{name:n,delegated:at.has(n)},expr:r};let o=this.wrapHandler(r,t.modifiers),a=this.eventOptions(t.modifiers),s=a?`[${o}, ${a}]`:o;return{name:"on:"+n,kind:"attr",expr:s}}wrapHandler(t,n){let r=n.includes("self")?"if (e.target !== e.currentTarget) return; ":"",i=[];return n.includes("prevent")&&i.push("e.preventDefault();"),n.includes("stop")&&i.push("e.stopPropagation();"),!r&&i.length===0?t:`(e) => { ${r}${i.join(" ")} return (${t})(e); }`}eventOptions(t){let n=[];return t.includes("capture")&&n.push("capture: true"),t.includes("once")&&n.push("once: true"),t.includes("passive")&&n.push("passive: true"),n.length?`{ ${n.join(", ")} }`:null}bindProps(t,n){let r=n.code,i=t==="checked",o=i?"change":"input",a=i?"checked":"value";this.used.add("bindPair");let s=`bindPair(${r})`;return[{name:t,kind:"attr",expr:`${s}[0]()`,reactive:!0,directive:`bind:${t}`,...n.at?{at:n.at}:{}},{name:"on"+lt(o),kind:"event",event:{name:o,delegated:at.has(o)},expr:`(e) => ${s}[1](e.target.${a})`}]}plainAttr(t){let n=t.value,r=t.name;t.name==="class"?r=n&&n.kind==="hole"&&this.hole(n.hole).object?"classList":"className":t.name==="html"&&(r="innerHTML");let o={name:r,kind:"attr"};if(n==null)return o.literal=!0,o;if(n.kind==="static")return o.literal=n.value,o;if(n.kind==="hole"){let p=this.hole(n.hole);return o.expr=p.code,o.reactive=p.reactive,p.at&&(o.at=p.at),o}let a=!1,s,c=n.parts.map(p=>{if("text"in p)return vn(p.text);let l=this.hole(p.hole);return a=a||l.reactive,s??=l.at,"${"+l.code+"}"}).join("");return o.expr="`"+c+"`",o.reactive=a,s&&(o.at=s),o}};function ut(e,t,n,r={}){let{root:i}=(0,ct.parseTemplate)(e,{svg:r.svg});return new Ee(t,n,r.sourceFile,r.positionAt).lowerRoot(i.children)}function pt(e,t,n={}){let r=new Set,i=ut(e,[...t],r,{svg:n.svg,...n.sourceFile?{sourceFile:n.sourceFile}:{},...n.positionAt?{positionAt:n.positionAt}:{}});j(i),oe(i,{resolver:fe(n.resolve??[]),modules:{controlFlowModule:n.controlFlowModule??"@fluixi/dom",coreModule:n.coreModule??"@fluixi/core",routerModule:n.routerModule??"@fluixi/core/router"},strategyFor:c=>c.load}),ae(i);let{code:o,imports:a,templates:s}=_.emit(i,{templateClone:n.templateClone,partialTemplates:n.partialTemplates});for(let c of a)r.add(c);return n.hoistTemplates?{code:o,imports:[...r],ir:i,templates:s}:{code:de(o,s),imports:[...r],ir:i}}var Rn="children";function F(e){switch(e.kind){case"call":return!0;case"member":return e.property!==Rn;case"compound":return e.parts.some(F);case"opaque":return!1}}var xn=new Set(["CallExpression","OptionalCallExpression"]),bn=new Set(["MemberExpression","OptionalMemberExpression"]);function B(e){if(!e)return{kind:"opaque"};if(xn.has(e.type))return{kind:"call"};if(bn.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(Z)}:e.type==="LogicalExpression"||e.type==="BinaryExpression"?{kind:"compound",parts:[e.left,e.right].map(Z)}:e.type==="TemplateLiteral"?{kind:"compound",parts:e.expressions.map(Z)}:e.type==="ObjectExpression"?{kind:"compound",parts:e.properties.filter(n=>(n.type==="ObjectProperty"||n.type==="Property")&&n.computed!==!0).map(n=>Z(n.value))}:e.type==="ArrayExpression"?{kind:"compound",parts:e.elements.filter(n=>n!=null&&n.type!=="SpreadElement").map(Z)}:{kind:"opaque"}}var Z=e=>B(e);var Sn=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),kn=/^on[A-Z]/,En=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),mt=e=>F(B(e)),Y=(e,t)=>{if(!t.sourceFile)return;let n=e.loc?.start;return n?{line:n.line,column:n.column}:void 0};function Q(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 Ie=e=>!!e&&typeof Q(e)=="string";function In(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 we(e){return e.type==="JSXIdentifier"?e.name==="class"?"className":e.name:e.type==="JSXNamespacedName"?`${e.namespace.name}:${e.name.name}`:"unknown"}function wn(e,t){let n=we(e.name),r=kn.test(n),i=r||n.startsWith("on:")||n==="ref",a={name:n,kind:r?"event":"attr"};if(r){let c=n.slice(2).toLowerCase();a.event={name:c,delegated:En.has(c)}}let s=e.value;if(s==null)return a.literal=!0,a.at=Y(e,t),a;if(Ie(s))return a.literal=Q(s),a.at=Y(s,t),a;if(s.type==="JSXExpressionContainer"&&s.expression?.type!=="JSXEmptyExpression"){let c=s.expression,p=Q(c);return p!==void 0?(a.literal=p,a.at=Y(c,t),a):(a.expr=t.code(c),a.reactive=i?!1:mt(c),a.at=Y(c,t),(c.type==="JSXElement"||c.type==="JSXFragment")&&(a.jsxElement=!0),a)}return a.literal=!0,a}function dt(e,t){let n=e.value;return n==null?null:Ie(n)?JSON.stringify(Q(n)):n.type==="JSXExpressionContainer"&&n.expression?.type!=="JSXEmptyExpression"?t.code(n.expression):null}function $n(e,t){let n=[],r=[];for(let i of e){if(i.type==="JSXSpreadAttribute"){n.push({name:"",kind:"spread",expr:t.code(i.argument)});continue}if(i.type!=="JSXAttribute"||ye(we(i.name)))continue;let o=i.name.type==="JSXNamespacedName"?i.name.namespace.name:null;if(o==="use"){let a=i.name.name.name;t.used.add(a);let s=dt(i,t);r.push(s!=null?`[${a}, () => (${s})]`:`[${a}]`);continue}if(o==="oncapture"){let a=i.name.name.name.toLowerCase(),s=dt(i,t)??"undefined";n.push({name:"on:"+a,kind:"attr",expr:`[${s}, { capture: true }]`});continue}n.push(wn(i,t))}return r.length>0&&n.push({name:"use",kind:"attr",expr:`[${r.join(", ")}]`}),n}function ft(e,t){let n=[];for(let r of e)if(r.type==="JSXText"){let i=G(r.value);i&&n.push({kind:"text",value:i})}else if(r.type==="JSXExpressionContainer"){if(r.expression?.type!=="JSXEmptyExpression"){let i=r.expression,o=mt(i);n.push({kind:"expr",code:t.code(i),reactive:o,...o?{at:Y(i,t)}:{}})}}else r.type==="JSXElement"||r.type==="JSXFragment"?n.push(gt(r,t)):r.type==="JSXSpreadChild"&&n.push({kind:"expr",code:t.code(r.expression),reactive:!1});return n}function Cn(e){for(let t of e){if(t.type!=="JSXAttribute")continue;let n=we(t.name);if(ye(n)){if(t.value&&!Ie(t.value))throw new P(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return ie(n,t.value?Q(t.value):null)}}}function gt(e,t){if(e.type==="JSXFragment")return{kind:"fragment",children:ft(e.children,t)};let{tag:n,component:r}=In(e.openingElement.name,t),i=$n(e.openingElement.attributes,t),o=ft(e.children,t),a=t.sourceFile&&e.loc?.start?{file:t.sourceFile,line:e.loc.start.line,column:e.loc.start.column}:void 0;if(r){let s=Cn(e.openingElement.attributes);return{kind:"component",name:n,props:i,children:o,...s?{load:s}:{},...a?{at:a}:{}}}return{kind:"element",tag:n,svg:Sn.has(n),props:i,children:o,static:!1,...a?{at:a}:{}}}function ht(e,t){let n=gt(e,t);return j(n),n}function M(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"?M(n.argument,t):M(n.value,t);return;case"ArrayPattern":for(let n of e.elements)M(n,t);return;case"AssignmentPattern":M(e.left,t);return;case"RestElement":M(e.argument,t);return}}function yt(e,t){switch(e.type){case"ImportDeclaration":for(let n of e.specifiers)M(n.local,t);return;case"VariableDeclaration":for(let n of e.declarations)M(n.id,t);return;case"FunctionDeclaration":case"ClassDeclaration":M(e.id,t);return;case"ExportNamedDeclaration":case"ExportDefaultDeclaration":e.declaration&&yt(e.declaration,t);return}}function $e(e){let t=new Set;for(let n of e.body)yt(n,t);return t}var Mn=require("@babel/parser"),On=Le(require("magic-string"),1);function E(e,t){if(e)switch(e.type){case"Identifier":t.add(e.name);return;case"ObjectPattern":for(let n of e.properties)n.type==="RestElement"?E(n.argument,t):E(n.value,t);return;case"ArrayPattern":for(let n of e.elements)E(n,t);return;case"AssignmentPattern":E(e.left,t);return;case"RestElement":E(e.argument,t);return}}function Ce(e){switch(e.type){case"StringLiteral":case"NumericLiteral":case"BooleanLiteral":case"NullLiteral":case"BigIntLiteral":case"RegExpLiteral":case"Identifier":return!0;case"Literal":return!0;case"TemplateLiteral":return e.expressions.every(Ce);case"UnaryExpression":return Ce(e.argument);case"MemberExpression":return!1;default:return!1}}function me(e,t){if(!(!e||typeof e!="object")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="range"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let i of r)i&&typeof i=="object"&&me(i,t);else r&&typeof r=="object"&&typeof r.type=="string"&&me(r,t)}}}function Tn(e){let t=new Set;return me(e,n=>{if(n.type==="AssignmentExpression")E(n.left,t);else if(n.type==="UpdateExpression"){let r=n.argument;r?.type==="Identifier"&&t.add(r.name)}}),t}function Pn(e,t){let n=new Set,r=i=>{let o=new Set;E(i,o);for(let a of o)t.has(a)&&n.add(a)};return me(e,i=>{switch(i.type){case"VariableDeclarator":r(i.id);return;case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":r(i.id);for(let o of i.params??[])r(o);return;case"CatchClause":r(i.param);return;case"ClassDeclaration":case"ClassExpression":r(i.id);return}}),n}function Nt(e,t,n){for(let r of e.properties??[]){if(r.type==="RestElement"){let l=r.argument;if(l?.type!=="Identifier"||t.length>0){let d=new Set;E(l,d);for(let u of d)n.bails.push({name:u,reason:"rest"});continue}n.rest={name:l.name,keys:[]};continue}if(r.computed){let l=new Set;E(r.value,l);for(let d of l)n.bails.push({name:d,reason:"computed"});continue}let i=r.key,o=i.type==="Identifier"?i.name:i.value,a=r.value,s;a.type==="AssignmentPattern"&&(s=a.right,a=a.left);let c=[...t,o];if(a.type==="Identifier"){if(s&&!Ce(s)){n.bails.push({name:a.name,reason:"unsafe-default"});continue}n.reads.push({name:a.name,path:c,...s?{fallback:s}:{}});continue}if(a.type==="ObjectPattern"){if(s){let l=new Set;E(a,l);for(let d of l)n.bails.push({name:d,reason:"unsafe-default"});continue}Nt(a,c,n);continue}let p=new Set;E(a,p);for(let l of p)n.bails.push({name:l,reason:"computed"})}}function vt(e,t){let n={reads:[],bails:[]};if(e?.type!=="ObjectPattern"||(Nt(e,[],n),n.rest&&(t?.type!=="BlockStatement"?(n.bails.push({name:n.rest.name,reason:"rest"}),delete n.rest):n.rest.keys=(e.properties??[]).filter(s=>s.type!=="RestElement"&&!s.computed).map(s=>{let c=s.key;return c.type==="Identifier"?c.name:c.value})),n.reads.length===0&&!n.rest))return n;let r=new Set(n.reads.map(s=>s.name));n.rest&&r.add(n.rest.name);let i=Tn(t),o=Pn(t,r),a=[];for(let s of n.reads)i.has(s.name)?n.bails.push({name:s.name,reason:"reassigned"}):o.has(s.name)?n.bails.push({name:s.name,reason:"shadowed"}):a.push(s);return n.reads=a,n.rest&&i.has(n.rest.name)?(n.bails.push({name:n.rest.name,reason:"reassigned"}),delete n.rest):n.rest&&o.has(n.rest.name)&&(n.bails.push({name:n.rest.name,reason:"shadowed"}),delete n.rest),n}function Rt(e){switch(e){case"rest":return"this rest element cannot be served by splitProps, and copying the props into a plain object would lose the getters";case"computed":return"the property is not known until it runs";case"reassigned":return"the binding is assigned to, and props are read-only";case"shadowed":return"an inner scope binds the same name";case"unsafe-default":return"the default would have to run again on every read"}}function ee(e,t,n=null){if(!(!e||typeof e!="object"||typeof e.type!="string")&&!e.type.startsWith("TS")&&t(e,n)!==!1)for(let r of Object.keys(e)){if(r==="loc"||r==="leadingComments"||r==="trailingComments")continue;let i=e[r];if(Array.isArray(i))for(let o of i)ee(o,t,e);else i&&typeof i=="object"&&ee(i,t,e)}}function xt(e){return!!e&&e[0]>="A"&&e[0]<="Z"}function An(e){let t=[];return ee(e,n=>{if(n.type==="FunctionDeclaration"&&xt(n.id?.name)){t.push(n);return}if(n.type==="VariableDeclarator"&&xt(n.id?.name)){let r=n.init;r&&(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")&&t.push(r)}}),t}function Dn(e){let t=new Set;return ee(e,n=>{n.type==="Identifier"&&t.add(n.name)}),t}function Ln(e,t){if(!t)return!0;switch(t.type){case"MemberExpression":case"OptionalMemberExpression":return!(t.property===e&&!t.computed);case"ObjectProperty":case"ObjectMethod":case"ClassProperty":case"ClassMethod":return!(t.key===e&&!t.computed);case"LabeledStatement":case"BreakStatement":case"ContinueStatement":return t.label!==e;case"ImportSpecifier":case"ExportSpecifier":return!1;default:return!0}}function bt(e,t,n={}){let r=[],i=[],o=new Set;for(let a of An(e)){let s=a.params?.[0];if(s?.type!=="ObjectPattern")continue;let c=vt(s,a.body);for(let m of c.bails)i.push({name:m.name,reason:m.reason,message:Rt(m.reason),start:s.start});if(c.bails.length>0||c.reads.length===0&&!c.rest)continue;let p=Dn(a),l=n.parameterName??"props";for(;p.has(l);)l=`_${l}`;let d=new Map;for(let m of c.reads){let y=`${l}.${m.path.join(".")}`,b=m.fallback;d.set(m.name,b?`(${y} === undefined ? ${t.slice(b.start,b.end)} : ${y})`:y)}let u=s.typeAnnotation;if(r.push({start:s.start,end:u?.start??s.end,code:l}),c.rest){let m=c.rest.keys.map(b=>JSON.stringify(b)).join(", "),y=a.body;r.push({start:y.start+1,end:y.start+1,code:`
|
|
2
|
+
const [, ${c.rest.name}] = splitProps(${l}, [${m}]);`}),o.add("splitProps")}let g=[];ee(a.body,(m,y)=>{if(m.type!=="Identifier")return;let b=d.get(m.name);if(!b)return;let x=y?.type==="ObjectProperty"&&y.shorthand&&y.value===m;if(!x&&!Ln(m,y))return;let N=c.reads.find($=>$.name===m.name).path;g.push({node:m,parent:x?y:null,text:b,property:N[N.length-1]})});for(let m of g)m.parent?r.push({start:m.parent.start,end:m.parent.end,code:`${m.node.name}: ${m.text}`}):r.push({start:m.node.start,end:m.node.end,code:m.text}),jn(m.node,l,m.property)}return{edits:r,diagnostics:i,used:o}}function jn(e,t,n){e.type="MemberExpression",e.computed=!1,e.optional=!1,e.object={type:"Identifier",name:t,start:e.start,end:e.start},e.property={type:"Identifier",name:n,start:e.end,end:e.end},delete e.name}function Te(e,t){if(!(!e||typeof e!="object"||typeof e.type!="string")){t(e);for(let n of Object.keys(e)){if(n==="loc"||n==="leadingComments"||n==="trailingComments")continue;let r=e[n];if(Array.isArray(r))for(let i of r)Te(i,t);else r&&typeof r=="object"&&Te(r,t)}}}function St(e){let t=[],n=[],r=new Map,i=new Set,{shadowed:o}=pe(e);return Te(e,a=>{if(a.type!=="CallExpression")return;let s=a.callee;if(s?.type!=="Identifier")return;let c=s.name;if(!ue(c))return;if(o.has(c)){i.has(c)||(i.add(c),n.push({name:c,message:`${c} is reserved for the compiler, and this module binds it. The call keeps your binding's meaning; rename it to use the intrinsic.`,start:s.start}));return}let p=w[c];t.push({start:s.start,end:s.end,code:p.export});let l=r.get(p.module)??new Set;l.add(p.export),r.set(p.module,l)}),{edits:t,diagnostics:n,imports:r}}function kt(e,t){let n=[];for(let[r,i]of[...e.imports].sort(([o],[a])=>o.localeCompare(a))){let o=[...i].filter(a=>!t.has(a)).sort();o.length&&n.push(`import { ${o.join(", ")} } from ${JSON.stringify(r)};`)}return n.length?`${n.join(`
|
|
3
3
|
`)}
|
|
4
|
-
`:""}var
|
|
5
|
-
`?
|
|
4
|
+
`:""}var Jn=new Set(V),_n=new Set(U),Fn=new Set(J),Bn=new Set(["createMemo","createEffect","createRenderEffect","createRoot","createSignal","onCleanup","batch","untrack"]);function he(e,t,n=null,r=""){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let i of e)he(i,t,n,r);return}typeof e.type=="string"&&t(e,n,r);for(let i of Object.keys(e))i==="loc"||i==="leadingComments"||i==="trailingComments"||he(e[i],t,typeof e.type=="string"?e:n,i)}}var Pe=e=>e.type==="JSXElement"||e.type==="JSXFragment";function Hn(e,t,n){return Pe(e)?!(t&&Pe(t)&&n==="children"):!1}function Vn(e,t){return e.type==="TaggedTemplateExpression"&&e.tag?.type==="Identifier"&&(e.tag.name===t||e.tag.name==="svg")}function wt(e){return e.filter(t=>!e.some(n=>n!==t&&n.start<=t.start&&n.end>=t.end&&n.end-n.start>t.end-t.start&&!(t.start===t.end&&(t.start===n.start||t.start===n.end))))}function ge(e,t,n,r){let i=wt(r.filter(a=>a.start>=t&&a.end<=n)).sort((a,s)=>s.start-a.start),o=e.slice(t,n);for(let a of i)o=o.slice(0,a.start-t)+a.code+o.slice(a.end-t);return o}function Un(e,t,n,r=!1){let i=r?t.loc?.start:void 0,o={code:ge(e,t.start,t.end,n),reactive:F(B(t)),...i?{at:{line:i.line,column:i.column}}:{}};return t.type==="ArrowFunctionExpression"&&t.body?.type!=="BlockStatement"&&(o.arrow={params:t.params.map(a=>ge(e,a.start,a.end,n)),body:ge(e,t.body.start,t.body.end,n),bodyReactive:F(B(t.body))}),t.type==="ObjectExpression"&&(o.object=!0),o}function $t(e,t,n){if(!t||t.length===0)return e;let r=new Map;for(let i of t){let o=`${i.svg?"svg:":""}${i.html}`,a=n.get(o);a||(a=`_fxTmpl$${n.size}`,n.set(o,a)),r.set(i.id,a)}return e.replace(/_tmpl\$\d+/g,i=>r.get(i)??i)}function Me(e,t){if(e.kind==="component"&&e.load&&!e.source&&H(e.load)&&(t.ignoredLoad.has(e.name)||t.ignoredLoad.set(e.name,e.load)),e.kind==="component"&&e.source){let n=e.source;n.origin==="builtin"?t.builtins.add(e.name):H(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)Me(n,t)}function Xn(e,t){for(let n of e.body??[])if(n.type==="ImportDeclaration")for(let r of n.specifiers??[]){if(r.local?.name!==t)continue;if(r.type==="ImportNamespaceSpecifier")return;let i=r.type==="ImportDefaultSpecifier"?"default":r.imported?.name??r.imported?.value;return{module:n.source.value,export:i,declaration:n,specifier:r}}}function Wn(e,t){for(let n of e.body??[])if(n.type==="ImportDeclaration"){for(let r of n.specifiers??[])if(r.type==="ImportNamespaceSpecifier"&&r.local?.name===t)return!0}return!1}function zn(e,t,n){let r=!1;return he(e,i=>{r||i.type!=="Identifier"||i.name!==t||i.start===n.local?.start&&i.end===n.local?.end||(r=!0)}),r}function Kn(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 qn(e){let t=[0];for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&t.push(n+1);return n=>{let r=0,i=t.length-1;for(;r<i;){let o=r+i+1>>1;t[o]<=n?r=o:i=o-1}return{line:r+1,column:n-t[r]}}}function Gn(e){let t=[];return e.quasi.quasis.forEach((n,r)=>{if(t.push({kind:"static",text:n.value.cooked??n.value.raw,start:n.start}),r<e.quasi.expressions.length){let i=e.quasi.expressions[r];t.push({kind:"hole",index:r,start:i.start,end:i.end})}}),t}function Zn(e,t){if(!t)return e;let n=t.endsWith("/")?t:`${t}/`;return e.startsWith(n)?e.slice(n.length):e}function Yn(e,t,n={}){let r=n.litTag??"html",i=n.format??"both",o=i!=="jsx",a=i!=="lit",s=o&&(e.includes(`${r}\``)||e.includes("svg`")),c=n.intrinsics!==!1&&ze(e),p=n.sourceLocations===!0&&Qe(e),l=Zn(t,n.sourceRoot);if(!s&&!(a&&e.includes("<"))&&!c&&!p)return null;let d=(0,Et.parse)(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:!0}),u=[];he(d.program,(f,S,R)=>{(o&&Vn(f,r)||a&&Hn(f,S,R))&&u.push(f)});let g=n.propsDestructure===!1?{edits:[],diagnostics:[],used:new Set}:bt(d.program,e,{runtimeModule:n.runtimeModule}),m=n.intrinsics===!1?{edits:[],diagnostics:[],imports:new Map}:St(d.program),y=n.sourceLocations===!0?et(d.program,l):{edits:[],marked:0};if(u.length===0&&g.edits.length===0&&y.edits.length===0&&m.edits.length===0&&m.diagnostics.length===0&&g.diagnostics.length===0)return null;u.sort((f,S)=>S.start-f.start||f.end-S.end);let x=new Set(g.used),N={builtins:new Set,resolved:new Map,deferred:new Map,delegatedEvents:new Set,ignoredLoad:new Map,unresolved:new Set,declared:qe(d.program)},$=new Map,O=[...g.edits,...m.edits,...y.edits];for(let f of u){let S=u.some(k=>k!==f&&k.start<=f.start&&k.end>=f.end&&k.end-k.start>f.end-f.start);if(Pe(f)){O.push({start:f.start,end:f.end,code:Qn(e,f,O,S,x,N,$,n,l)});continue}let R=f.quasi.expressions.map(k=>Un(e,k,O,n.sourceLocations===!0)),T=pt(Gn(f),R,{...n,hoistTemplates:!0,...n.sourceLocations===!0?{sourceFile:l,positionAt:qn(e)}:{},templateClone:n.templateClone??!0,partialTemplates:S?!1:n.partialTemplates??!0,svg:f.tag.name==="svg"});for(let k of T.imports)x.add(k);Me(T.ir,N),O.push({start:f.start,end:f.end,code:$t(T.code,T.templates,$)})}let I=new It.default(e);for(let f of wt(O))f.start===f.end?I.appendLeft(f.start,f.code):I.overwrite(f.start,f.end,f.code);let h=$e(d.program),C=new Map;for(let[f]of N.ignoredLoad)h.has(f)||C.set(f,"unsupplied");for(let[f,S]of[...N.ignoredLoad]){if(!h.has(f))continue;let R=Xn(d.program,f);if(!R){C.set(f,Wn(d.program,f)?"namespace":"local");continue}if(zn(d.program,f,R.specifier)){C.set(f,"value");continue}let T=R.declaration.specifiers.filter(te=>te!==R.specifier),k=T.length===0&&e[R.declaration.end]===`
|
|
5
|
+
`?R.declaration.end+1:R.declaration.end;I.overwrite(R.declaration.start,k,T.length===0?"":`import { ${T.map(te=>e.slice(te.start,te.end)).join(", ")} } from ${JSON.stringify(R.declaration.source.value)};`),N.deferred.set(f,{module:R.module,export:R.export,origin:"rule",loading:S}),h.delete(f),N.ignoredLoad.delete(f)}let L=er(x,N,$,h,n);L&&I.prepend(L);let A=kt(m,h);A&&I.prepend(A);let Ct={value:f=>`${f} is used as a value here, not only as a tag, so its import has to stay — deferring would hand those references a lazy wrapper instead of the component. Defer it at the point it is rendered, or keep it eager.`,namespace:f=>`${f} came in through a namespace import, which has no single export to defer. Import ${f} by name.`,local:f=>`${f} is declared in this file, so there is no module to load separately. Move it to its own file and import it.`,unsupplied:f=>`nothing supplies ${f}, so there is no import to defer. Import it, or add a \`resolve\` rule for it.`},Oe=[...N.ignoredLoad].map(([f,S])=>({name:f,strategy:S,message:`load:${S.kind} has no effect on <${f}>: ${Ct[C.get(f)??"unsupplied"](f)}`})),Ae=[...N.unresolved].map(f=>({name:f,message:`<${f}> is not defined: nothing imports it and no \`resolve\` rule supplies it. This compiles to a reference to a name that does not exist, so the component renders nothing. Import ${f}, or add a \`resolve\` rule for it.`}));return{code:I.toString(),map:I.generateMap({source:t,includeContent:!0,hires:!0}),...Oe.length?{loadDiagnostics:Oe}:{},...Ae.length?{unresolvedDiagnostics:Ae}:{},...g.diagnostics.length?{propsDiagnostics:g.diagnostics}:{},...m.diagnostics.length?{intrinsicDiagnostics:m.diagnostics}:{}}}function Qn(e,t,n,r,i,o,a,s,c){let p=ht(t,{code:u=>ge(e,u.start,u.end,n),used:i,...s.sourceLocations===!0&&c?{sourceFile:c}:{}});j(p);let l=oe(p,{resolver:fe(s.resolve??[]),isBound:u=>o.declared.has(u),modules:{controlFlowModule:s.controlFlowModule??s.runtimeModule??"@fluixi/dom",coreModule:s.coreModule??"@fluixi/core",routerModule:s.routerModule??"@fluixi/core/router"},strategyFor:u=>u.load});for(let u of l.unresolved)o.unresolved.add(u);ae(p);let d=_.emit(p,{templateClone:s.templateClone??!0,partialTemplates:r?!1:s.partialTemplates??!0});for(let u of d.imports)i.add(u);return Me(p,o),$t(d.code,d.templates,a)}function er(e,t,n,r,i){let o=i.runtimeModule??"@fluixi/dom",a=i.coreModule??"@fluixi/core",s=new Map,c=(u,g)=>s.set(u,[...s.get(u)??[],g]),p=new Set(e);for(let u of t.builtins)p.add(u);t.delegatedEvents.size>0&&p.add("delegateEvents");for(let u of[...p].sort())r.has(u)||(Bn.has(u)?c(i.reactiveModule??"@fluixi/reactive/signal",u):Fn.has(u)?c(i.routerModule??"@fluixi/core/router",u):_n.has(u)?c(a,u):Jn.has(u)?c(i.controlFlowModule??o,u):c(o,u));for(let[u,g]of t.resolved)r.has(u)||c(g.module,g.export==="default"?`default as ${u}`:u===g.export?u:`${g.export} as ${u}`);let l=[];for(let[u,g]of s)l.push(`import { ${g.join(", ")} } from ${JSON.stringify(u)};`);let d=[...t.deferred].filter(([u])=>!r.has(u));if(d.length>0){r.has("deferred")||l.push(`import { deferred } from ${JSON.stringify(a)};`);for(let[u,g]of d)l.push(`const ${u} = deferred(() => import(${JSON.stringify(g.module)}), { strategy: ${Kn(g.loading)}, export: ${JSON.stringify(g.export)} });`)}for(let[u,g]of n)l.push(`const ${g} = ${JSON.stringify(u.startsWith("svg:")?u.slice(4):u)};`);return t.delegatedEvents.size>0&&l.push(`delegateEvents(${JSON.stringify([...t.delegatedEvents])});`),l.length>0?l.join(`
|
|
6
6
|
`)+`
|
|
7
7
|
`:null}
|
|
@@ -24,6 +24,18 @@ export interface TransformOptions extends CompileTemplateOptions {
|
|
|
24
24
|
* @default true
|
|
25
25
|
*/
|
|
26
26
|
propsDestructure?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Record where each reactive primitive was created, so the devtools graph can say where a
|
|
29
|
+
* node comes from. Development tooling: leave it off for production, which then carries
|
|
30
|
+
* none of it.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
sourceLocations?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Trim this prefix off the file name a source mark records, so a location reads
|
|
36
|
+
* `src/app.tsx:5:16` rather than an absolute path that means nothing to whoever opens it.
|
|
37
|
+
*/
|
|
38
|
+
sourceRoot?: string;
|
|
27
39
|
/**
|
|
28
40
|
* Compile the `$` reactive intrinsics — `$signal`, `$memo`, `$effect`, `$store` — into
|
|
29
41
|
* the runtime calls they stand for, importing what they need.
|
|
@@ -54,9 +66,5 @@ export interface TransformResult {
|
|
|
54
66
|
/** Capitalised tags nothing supplies — they compile to an undefined reference. */
|
|
55
67
|
unresolvedDiagnostics?: UnresolvedDiagnostic[];
|
|
56
68
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Compile every template in `code`. Returns null when the module has none, so a
|
|
59
|
-
* bundler can skip the file untouched.
|
|
60
|
-
*/
|
|
61
69
|
export declare function transformTemplates(code: string, id: string, options?: TransformOptions): TransformResult | null;
|
|
62
70
|
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/transform/templates.ts"],"names":[],"mappings":"AASA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAG1F,OAAO,KAAK,EAAqB,cAAc,EAAU,MAAM,gBAAgB,CAAC;AAWhF,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAA2C,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/transform/templates.ts"],"names":[],"mappings":"AASA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAG1F,OAAO,KAAK,EAAqB,cAAc,EAAU,MAAM,gBAAgB,CAAC;AAWhF,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAA2C,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAoBpG,MAAM,WAAW,gBAAiB,SAAQ,sBAAsB;IAC9D;;;;OAIG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAChC,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;IAC5C,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IACrC,wEAAwE;IACxE,oBAAoB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC7C,8DAA8D;IAC9D,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;IACnC,kFAAkF;IAClF,qBAAqB,CAAC,EAAE,oBAAoB,EAAE,CAAC;CAChD;AAwTD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,gBAAqB,GAC7B,eAAe,GAAG,IAAI,CAiNxB"}
|