solely 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +117 -1
  2. package/dist/compiler/index.cjs +1 -0
  3. package/dist/compiler/index.js +1 -0
  4. package/dist/compiler/ir/buildIR.cjs +1 -0
  5. package/dist/compiler/ir/buildIR.js +1 -0
  6. package/dist/compiler/parser/parser.cjs +1 -0
  7. package/dist/compiler/parser/parser.js +1 -0
  8. package/dist/index.cjs +1 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +1 -1948
  11. package/dist/plugin.cjs +1 -0
  12. package/dist/plugin.d.ts +39 -1
  13. package/dist/plugin.js +1 -0
  14. package/dist/plugins/index.d.ts +7 -1
  15. package/dist/plugins/solely-vite-plugin.cjs +1 -0
  16. package/dist/plugins/solely-vite-plugin.d.ts +28 -0
  17. package/dist/plugins/solely-vite-plugin.js +1 -0
  18. package/dist/router/core.cjs +1 -0
  19. package/dist/{runtime/router → router}/core.d.ts +1 -0
  20. package/dist/router/core.js +1 -0
  21. package/dist/router/index.cjs +1 -0
  22. package/dist/router/index.js +1 -0
  23. package/dist/router/router-link.cjs +1 -0
  24. package/dist/{runtime/router → router}/router-link.d.ts +1 -1
  25. package/dist/router/router-link.js +1 -0
  26. package/dist/router/router-view.cjs +1 -0
  27. package/dist/{runtime/router → router}/router-view.d.ts +1 -1
  28. package/dist/router/router-view.js +1 -0
  29. package/dist/router/routes copy.d.ts +6 -0
  30. package/dist/runtime/component/base-element.cjs +1 -0
  31. package/dist/runtime/component/base-element.js +1 -0
  32. package/dist/runtime/component/decorators.cjs +1 -0
  33. package/dist/runtime/component/decorators.d.ts +1 -1
  34. package/dist/runtime/component/decorators.js +1 -0
  35. package/dist/runtime/index.cjs +1 -0
  36. package/dist/runtime/index.d.ts +0 -1
  37. package/dist/runtime/index.js +1 -0
  38. package/dist/runtime/reactivity/observe.cjs +1 -0
  39. package/dist/runtime/reactivity/observe.js +1 -0
  40. package/dist/runtime/renderer/renderIR.cjs +1 -0
  41. package/dist/runtime/renderer/renderIR.js +1 -0
  42. package/dist/shared/env.cjs +1 -0
  43. package/dist/shared/env.js +1 -0
  44. package/dist/shared/event-listeners.cjs +1 -0
  45. package/dist/shared/event-listeners.js +1 -0
  46. package/dist/shared/functions.cjs +1 -0
  47. package/dist/shared/functions.js +1 -0
  48. package/dist/shared/gen-function copy.d.ts +6 -0
  49. package/dist/shared/gen-function.cjs +1 -0
  50. package/dist/shared/gen-function.d.ts +1 -0
  51. package/dist/shared/gen-function.js +1 -0
  52. package/dist/shared/index.cjs +1 -0
  53. package/dist/shared/index.js +1 -0
  54. package/dist/shared/is-object.cjs +1 -0
  55. package/dist/shared/is-object.js +1 -0
  56. package/dist/shared/templateError.cjs +1 -0
  57. package/dist/shared/templateError.js +1 -0
  58. package/dist/shared/url.cjs +1 -0
  59. package/dist/shared/url.js +1 -0
  60. package/dist/types/ast.cjs +1 -0
  61. package/dist/types/ast.js +1 -0
  62. package/dist/types/index.cjs +1 -0
  63. package/dist/types/index.js +1 -0
  64. package/dist/types/ir.d.ts +73 -61
  65. package/dist/types/lifecycle.cjs +1 -0
  66. package/dist/types/lifecycle.js +1 -0
  67. package/package.json +211 -58
  68. package/dist/index.umd.cjs +0 -47
  69. package/dist/plugins/html-parse-precompile.d.ts +0 -1
  70. package/dist/plugins/html-precompile.d.ts +0 -1
  71. /package/dist/{runtime/router → router}/index.d.ts +0 -0
  72. /package/dist/{runtime/router → router}/types.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,1948 +1 @@
1
- var re = Object.defineProperty;
2
- var _t = (n) => {
3
- throw TypeError(n);
4
- };
5
- var ie = (n, t, e) => t in n ? re(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
6
- var x = (n, t, e) => ie(n, typeof t != "symbol" ? t + "" : t, e), gt = (n, t, e) => t.has(n) || _t("Cannot " + e);
7
- var C = (n, t, e) => (gt(n, t, "read from private field"), e ? e.call(n) : t.get(n)), P = (n, t, e) => t.has(n) ? _t("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, e), A = (n, t, e, s) => (gt(n, t, "write to private field"), s ? s.call(n, e) : t.set(n, e), e), M = (n, t, e) => (gt(n, t, "access private method"), e);
8
- const oe = {
9
- dark: {
10
- gutter: "#858585",
11
- errorLineBg: "#3c1e1e",
12
- errorLineFg: "#f8f8f2",
13
- arrow: "#ff6b6b",
14
- badgeBg: "#ff6b6b",
15
- badgeFg: "#ffffff",
16
- exprLabel: "#a0a0a0",
17
- exprCode: "#5ddcff"
18
- }
19
- }, I = oe.dark;
20
- function it(n) {
21
- let t = 0;
22
- for (let e = 0; e < n.length; ) {
23
- const s = n.codePointAt(e);
24
- if (n[e] === " ") {
25
- t += 4, e++;
26
- continue;
27
- }
28
- s >= 9472 && s <= 9599 || s > 255 ? t += 2 : t += 1, e += s > 65535 ? 2 : 1;
29
- }
30
- return t;
31
- }
32
- function Nt(n, t = {}) {
33
- const { lineIndex: e = 0, totalLines: s = 1 } = t, r = Math.max(1, Math.floor(n));
34
- return (s <= 1 || e === 0 ? "^" : "~").repeat(r);
35
- }
36
- function ae(n, t = "", e, s = "component") {
37
- var st;
38
- const r = (n == null ? void 0 : n.message) ?? String(n), o = `%cTemplate Error%c in <${s}> → ${r}`, i = [
39
- `color:${I.badgeFg};background:${I.badgeBg};padding:4px 10px;border-radius:6px;font-weight:bold;`,
40
- `color:${I.arrow};font-weight:bold;`
41
- ];
42
- if (!t || !(e != null && e.loc) || e.loc.length < 2) {
43
- console.error(o, ...i), e != null && e.expr && console.log(`Expression: ${e.expr.trim()}`);
44
- return;
45
- }
46
- const l = e.loc;
47
- let a = l[0] || 0, c = l[1] || 0;
48
- a |= 0, c |= 0, a < 1 && (a = 1), c < 1 && (c = 1);
49
- const h = t.split(`
50
- `);
51
- if (a > h.length) {
52
- console.error(`[Template Error] 行号 ${a} 超出范围`);
53
- return;
54
- }
55
- const u = a - 1, p = Math.max(0, u - 3), v = Math.min(h.length - 1, u + 3), f = String(v + 1).length, d = ((st = e.expr) == null ? void 0 : st.trim()) ?? "", $ = d ? d.split(`
56
- `) : [], m = d ? Math.max(...$.map(it)) : 0, y = $.length > 1, g = `color:${I.gutter};`, b = `color:${I.arrow};font-weight:bold;`, E = `color:${I.gutter};`, S = `color:${I.errorLineFg};background:${I.errorLineBg};padding:0 4px;`, R = `color:${I.gutter};`, L = `color:${I.arrow};font-weight:bold;padding:0 4px;`;
57
- console.groupCollapsed(
58
- `${o} %c(Line:${a}, Col:${c})`,
59
- ...i,
60
- `color:${I.gutter};font-weight:normal;`
61
- );
62
- for (let q = p; q <= v; q++) {
63
- const dt = h[q], Lt = String(q + 1).padStart(f, " ");
64
- if (!(q === u)) {
65
- console.log(`%c${Lt} │%c ${dt}`, g, E);
66
- continue;
67
- }
68
- const te = dt.slice(0, Math.max(0, c - 1)), Mt = it(te), It = " ".repeat(f + 3), ee = Lt.padEnd(f, " ");
69
- if (console.log(`%c${ee} │%c ${dt}`, b, S), y)
70
- for (let T = 0; T < $.length; T++) {
71
- const pt = $[T], J = u + T;
72
- let mt = 0;
73
- if (T === 0)
74
- mt = Mt;
75
- else if (J < h.length) {
76
- const X = h[J], rt = X.search(/\S/), se = rt === -1 ? X : X.slice(0, rt);
77
- mt = it(se);
78
- }
79
- const ne = Math.max(1, it(pt.trim())), Pt = Nt(ne, { lineIndex: T, totalLines: $.length }), Ot = It + " ".repeat(mt);
80
- if (T === 0)
81
- console.log(`%c${Ot}%c${Pt}`, R, L);
82
- else if (J < h.length) {
83
- const X = String(J + 1).padEnd(f, " "), rt = h[J];
84
- console.log(`%c${X} │%c ${rt}`, b, S), console.log(`%c${Ot}%c${Pt}`, R, L);
85
- }
86
- }
87
- else {
88
- const T = It + " ".repeat(Mt), pt = Nt(m || 1);
89
- console.log(`%c${T}%c${pt}`, R, L);
90
- }
91
- }
92
- d && console.log(
93
- `%cExpression:%c ${d}`,
94
- `color:${I.exprLabel};font-weight:bold;`,
95
- `color:${I.exprCode};font-family:monospace;`
96
- ), console.groupEnd();
97
- }
98
- function ce(n) {
99
- if (n[n.length - 1].trim() === "")
100
- throw new Error("Function body cannot be empty");
101
- return new Function(...n);
102
- }
103
- const _ = (() => {
104
- var n, t, e;
105
- return !!(typeof window < "u" && ((n = window.location) != null && n.search.includes("debug") || globalThis.__DEBUG__ === !0 || globalThis.__IS_DEV__ === !0) || typeof process < "u" && ((t = process.env) == null ? void 0 : t.NODE_ENV) === "development" || typeof window < "u" && ["localhost", "127.0.0.1", "0.0.0.0"].includes(((e = window.location) == null ? void 0 : e.hostname) || ""));
106
- })(), on = !_, le = /\{\{\{\s*[\s\S]*?\s*\}\}\}/, ue = /\{\{\s*([\s\S]*?)\s*\}\}/g, he = 1e3, D = /* @__PURE__ */ new Map();
107
- function fe(n, t) {
108
- if (!(n != null && n.trim())) return { processed: "" };
109
- if (le.test(n))
110
- return {
111
- processed: n,
112
- error: "Illegal interpolation syntax: use {{ }} instead of {{{ }}}"
113
- };
114
- if (t === "template")
115
- try {
116
- return { processed: n.replace(ue, (s, r) => `\${${r.trim()}}`) };
117
- } catch (e) {
118
- return {
119
- processed: n,
120
- error: `Template parse error: ${e instanceof Error ? e.message : String(e)}`
121
- };
122
- }
123
- return { processed: n };
124
- }
125
- function de(n, t) {
126
- const e = (s) => s.endsWith(";") ? s : s + ";";
127
- switch (t) {
128
- case "template":
129
- return `return \`${n}\`;`;
130
- case "expression":
131
- return `return (${n});`;
132
- case "handler":
133
- case "lifecycle":
134
- return e(n);
135
- default:
136
- return "return undefined;";
137
- }
138
- }
139
- function pe(n) {
140
- if (!n.length) return { loopValues: "", loopIndices: "" };
141
- const t = n.map((s) => s.item).join(", "), e = n.map((s) => s.index).join(", ");
142
- return {
143
- loopValues: `var [${t}] = loops.map(l => l.itmVal);`,
144
- loopIndices: `var [${e}] = loops.map(l => l.idxVal);`
145
- };
146
- }
147
- function me(n) {
148
- let t = 0;
149
- for (let e = 0; e < n.length; e++)
150
- t = (t << 5) - t + n.charCodeAt(e), t |= 0;
151
- return Math.abs(t).toString(36);
152
- }
153
- function ge(n, t, e, s, r) {
154
- const o = n === "lifecycle" ? ["el", "loops"] : n === "handler" ? ["event", "loops"] : ["loops"], i = n === "handler" ? "const { value, checked } = event?.target || {};" : "";
155
- let l = "";
156
- if (_) {
157
- const c = me(r);
158
- l = `
159
- //# sourceURL=vm:///${n}_${c}.js`;
160
- }
161
- const a = `
162
- const { $data } = this;
163
- ${i}
164
- ${e}
165
- ${s}
166
- ${t}${l}
167
- `.replace(/^\s+|\s+$/gm, "");
168
- return o.push(a), o;
169
- }
170
- function ye(n, t, e) {
171
- if (!(n != null && n.trim())) return () => "";
172
- const s = e.map((a) => `${a.item}:${a.index}`).join(","), r = `${t}|${n}|${s}`;
173
- if (D.has(r)) {
174
- const a = D.get(r);
175
- return D.delete(r), D.set(r, a), a;
176
- }
177
- const { processed: o, error: i } = fe(n, t);
178
- let l;
179
- if (i)
180
- l = function() {
181
- throw new Error(`[Compile Error] ${i} Original: ${n}`);
182
- };
183
- else
184
- try {
185
- const a = de(o, t), { loopValues: c, loopIndices: h } = pe(e), u = ge(t, a, c, h, n);
186
- l = ce(u);
187
- } catch (a) {
188
- const c = a instanceof Error ? a.message : String(a);
189
- l = function() {
190
- throw new Error(`[Parse Error] ${c} Original: ${n}`);
191
- };
192
- }
193
- if (D.size >= he) {
194
- const a = D.keys().next().value;
195
- a && D.delete(a);
196
- }
197
- return D.set(r, l), l;
198
- }
199
- const be = /* @__PURE__ */ new Set([
200
- "onabort",
201
- "onautocomplete",
202
- "onautocompleteerror",
203
- "onblur",
204
- "oncancel",
205
- "oncanplay",
206
- "oncanplaythrough",
207
- "onchange",
208
- "onclick",
209
- "onclose",
210
- "oncontextmenu",
211
- "oncuechange",
212
- "ondblclick",
213
- "ondrag",
214
- "ondragend",
215
- "ondragenter",
216
- "ondragexit",
217
- "ondragleave",
218
- "ondragover",
219
- "ondragstart",
220
- "ondrop",
221
- "ondurationchange",
222
- "onemptied",
223
- "onended",
224
- "onerror",
225
- "onfocus",
226
- "oninput",
227
- "oninvalid",
228
- "onkeydown",
229
- "onkeypress",
230
- "onkeyup",
231
- "onload",
232
- "onloadeddata",
233
- "onloadedmetadata",
234
- "onloadstart",
235
- "onmousedown",
236
- "onmouseenter",
237
- "onmouseleave",
238
- "onmousemove",
239
- "onmouseout",
240
- "onmouseover",
241
- "onmouseup",
242
- "onwheel",
243
- "onpause",
244
- "onplay",
245
- "onplaying",
246
- "onprogress",
247
- "onratechange",
248
- "onreset",
249
- "onresize",
250
- "onscroll",
251
- "onseeked",
252
- "onseeking",
253
- "onselect",
254
- "onshow",
255
- "onstalled",
256
- "onsubmit",
257
- "onsuspend",
258
- "ontimeupdate",
259
- "ontoggle",
260
- "onvolumechange",
261
- "onwaiting"
262
- ]), j = (n) => {
263
- if (n === null || typeof n != "object") return !1;
264
- const t = Object.prototype.toString.call(n);
265
- return ![
266
- "[object Function]",
267
- "[object Date]",
268
- "[object RegExp]",
269
- "[object Map]",
270
- "[object Set]",
271
- "[object WeakMap]",
272
- "[object WeakSet]"
273
- ].includes(t);
274
- };
275
- function an(n = window.location) {
276
- let t;
277
- typeof n == "string" ? t = new URL(n).hash : t = n.hash;
278
- const e = t.split("?");
279
- let s = e[0];
280
- const r = e[1], o = {};
281
- return s = s.replace(/^#\/?/, ""), r && r.split("&").forEach((i) => {
282
- const [l, a] = i.split("=");
283
- l && a && (o[decodeURIComponent(l)] = decodeURIComponent(a));
284
- }), {
285
- path: s.split("/").filter(Boolean),
286
- // 将路径分割成数组并过滤空字符串
287
- query: o
288
- // 查询参数对象
289
- };
290
- }
291
- var w = /* @__PURE__ */ ((n) => (n[n.Element = 0] = "Element", n[n.Text = 1] = "Text", n[n.Comment = 2] = "Comment", n[n.If = 3] = "If", n[n.ElseIf = 4] = "ElseIf", n[n.Else = 5] = "Else", n[n.For = 6] = "For", n[n.Conditional = 7] = "Conditional", n[n.Other = 99] = "Other", n))(w || {});
292
- const we = {
293
- // 可选别名
294
- onMounted: "mounted",
295
- onUpdated: "updated",
296
- onUnmounted: "unmounted"
297
- };
298
- function Ee(n) {
299
- return we[n] ?? null;
300
- }
301
- function ve(n) {
302
- return n === "mounted" || n === "updated" || n === "unmounted";
303
- }
304
- const Et = Symbol.for("solely.irMeta"), $e = /\{\{[\s\S]*?\}\}/;
305
- class Se {
306
- constructor() {
307
- x(this, "compilers", /* @__PURE__ */ new Map());
308
- }
309
- get(t = "anonymous") {
310
- let e = this.compilers.get(t);
311
- return e || (e = new xe(), this.compilers.set(t, e)), e;
312
- }
313
- clear(t) {
314
- var e;
315
- if (t)
316
- (e = this.compilers.get(t)) == null || e.clear(), this.compilers.delete(t);
317
- else {
318
- for (const s of this.compilers.values()) s.clear();
319
- this.compilers.clear();
320
- }
321
- }
322
- }
323
- const Gt = new Se();
324
- class xe {
325
- constructor() {
326
- x(this, "cache", /* @__PURE__ */ new Map());
327
- x(this, "functions", []);
328
- }
329
- // 缓存 key 生成优化:避免每次都重新分配数组
330
- makeCacheKey(t, e, s) {
331
- if (s.length === 0) return `${t}:${e}`;
332
- const r = s.map((o) => Object.keys(o).sort().join(",")).join(";");
333
- return `${t}:${e}:${r}`;
334
- }
335
- compile(t, e, s) {
336
- const r = e == null ? void 0 : e.trim();
337
- if (!r) return 0;
338
- const o = this.makeCacheKey(t, r, s), i = this.cache.get(o);
339
- if (i !== void 0) return i;
340
- let l;
341
- try {
342
- l = ye(r, t, s);
343
- } catch (c) {
344
- _ && console.error(`[IR Compile Error] Type: ${t}, Expr: "${r}"`, c), l = () => "";
345
- }
346
- const a = this.functions.push(l);
347
- return this.cache.set(o, a), a;
348
- }
349
- getFunctions() {
350
- return this.functions;
351
- }
352
- getStats() {
353
- return { total: this.functions.length, cached: this.cache.size };
354
- }
355
- clear() {
356
- this.cache.clear(), this.functions = [];
357
- }
358
- }
359
- function Ut(n) {
360
- const t = n[0];
361
- return t === ":" ? { isDynamic: !0, type: "expression" } : t === "@" ? { isDynamic: !0, type: "handler" } : ve(n) ? { isDynamic: !0, type: "lifecycle" } : { isDynamic: !1, type: null };
362
- }
363
- function ke(n) {
364
- return n ? $e.test(n) : !1;
365
- }
366
- function vt(n, t, e) {
367
- _ && (n[Et] = { expr: t ?? "", loc: e ?? null });
368
- }
369
- function Ce(n) {
370
- if (!n.attrs) return;
371
- const t = n.attrs.find((a) => a.key === "s-model");
372
- if (!t) return;
373
- const e = "$data." + t.value.replace("this.", "").replace("$data.", ""), s = t.loc, r = (n.tag || "").toLowerCase(), o = n.attrs.find((a) => a.key === "type"), i = (o == null ? void 0 : o.value) ?? "text";
374
- n.attrs = n.attrs.filter((a) => a !== t);
375
- const l = (a, c, h) => {
376
- var u;
377
- (u = n.attrs) == null || u.push({ key: a, value: c, role: h, loc: s });
378
- };
379
- if (r === "input") {
380
- if (i === "checkbox") {
381
- const a = n.attrs.find((p) => p.key === "value"), c = a ? JSON.stringify(a.value) : '"on"', h = `Array.isArray(${e}) ? ${e}.includes(${c}) : ${e}`;
382
- l(":checked", h);
383
- const u = `
384
- const _v = ${c};
385
- if(Array.isArray(${e})) {
386
- const _i = ${e}.indexOf(_v);
387
- if(checked && _i === -1) ${e}.push(_v);
388
- else if(!checked && _i > -1) ${e}.splice(_i,1);
389
- } else {
390
- ${e} = checked;
391
- }`;
392
- l("@change", u, "model");
393
- return;
394
- }
395
- if (i === "radio") {
396
- const a = n.attrs.find((h) => h.key === "value"), c = (a == null ? void 0 : a.value) ?? "null";
397
- l(":checked", `${e} == ${JSON.stringify(c)}`), l("@change", `if (checked) ${e} = ${JSON.stringify(c)}`, "model");
398
- return;
399
- }
400
- l(":value", e), l("@input", `${e} = value`, "model");
401
- return;
402
- }
403
- if (r === "textarea") {
404
- l(":value", e), l("@input", `${e} = value`, "model");
405
- return;
406
- }
407
- if (r === "select") {
408
- n.attrs.some((c) => c.key === "multiple") ? (l("updated", `
409
- const values = Array.isArray(${e}) ? ${e} : ${e} != null ? [${e}] : [];
410
- for (const opt of el.options) {
411
- opt.selected = values.includes(opt.value);
412
- }`), l("@change", `${e} = Array.from(event.target.selectedOptions).map(o => o.value)`, "model")) : (l(":value", e), l("@change", `${e} = value`, "model"));
413
- return;
414
- }
415
- l(":value", e), l("@input", `${e} = $event`, "model");
416
- }
417
- function ct(n, t, e, s = null) {
418
- if (!n.attrs || n.attrs.length === 0) return [];
419
- const r = [];
420
- for (const o of n.attrs) {
421
- if (s && s.has(o.key)) continue;
422
- const { key: i, value: l, role: a } = o, { isDynamic: c, type: h } = Ut(i);
423
- if (c && h) {
424
- const u = e.compile(h, l ?? "", t), p = { key: i, fid: u, dynamic: 1, role: a };
425
- vt(p, l, o.loc ?? n.loc), r.push(p);
426
- } else
427
- r.push({ key: i, value: l, dynamic: 0, role: a });
428
- }
429
- return r;
430
- }
431
- function Re(n, t, e) {
432
- var o, i, l, a, c, h;
433
- const s = { type: n.type, dynamic: 0 };
434
- let r = !1;
435
- switch (n.type === w.Text ? ke(n.content) && (r = !0) : ((o = n.attrs) != null && o.some((u) => u.key === "s-model" || Ut(u.key).isDynamic) && (r = !0), n.type === w.For && (r = !0)), s.dynamic = r ? 1 : 0, n.type) {
436
- case w.Text: {
437
- const u = n.content ?? "";
438
- r ? (s.fid = e.compile("template", u, t), vt(s, u, n.loc)) : s.txt = u;
439
- break;
440
- }
441
- case w.Element: {
442
- s.tag = n.tag, Ce(n), s.attrs = ct(n, t, e), n.children && (s.children = Q(n.children, t, e));
443
- break;
444
- }
445
- case w.For: {
446
- const u = (i = n.attrs) == null ? void 0 : i.find((d) => d.key === "each"), p = (u == null ? void 0 : u.value) ?? "";
447
- s.fid = e.compile("expression", p, t), s.item = ((a = (l = n.attrs) == null ? void 0 : l.find((d) => d.key === "item")) == null ? void 0 : a.value) ?? "item", s.index = ((h = (c = n.attrs) == null ? void 0 : c.find((d) => d.key === "index")) == null ? void 0 : h.value) ?? "index", vt(s, p, (u == null ? void 0 : u.loc) ?? n.loc);
448
- const v = /* @__PURE__ */ new Set(["each", "item", "index"]);
449
- s.attrs = ct(n, t, e, v);
450
- const f = [...t, { item: s.item, index: s.index }];
451
- n.children && (s.children = Q(n.children, f, e));
452
- break;
453
- }
454
- case w.If:
455
- case w.ElseIf:
456
- case w.Else: {
457
- _ && console.warn(`[IR] Orphaned conditional node found: ${w[n.type]}`), s.attrs = ct(n, t, e), n.children && (s.children = Q(n.children, t, e));
458
- break;
459
- }
460
- case w.Comment: {
461
- s.txt = n.content ?? "";
462
- break;
463
- }
464
- }
465
- return s;
466
- }
467
- function Q(n, t, e) {
468
- var o;
469
- const s = [];
470
- let r = 0;
471
- for (; r < n.length; ) {
472
- const i = n[r];
473
- if (i.type === w.If) {
474
- const l = [];
475
- let a = r;
476
- for (; a < n.length; ) {
477
- const c = n[a], h = c.type;
478
- if (h !== w.If && h !== w.ElseIf && h !== w.Else || h === w.If && l.length > 0)
479
- break;
480
- let u = null, p = "", v = null;
481
- if (h !== w.Else) {
482
- const m = (o = c.attrs) == null ? void 0 : o.find(
483
- (y) => y.key === "test" || y.key === "condition"
484
- );
485
- p = (m == null ? void 0 : m.value) ?? "false", u = e.compile("expression", p, t), v = (m == null ? void 0 : m.loc) ?? c.loc;
486
- }
487
- const f = c.children ? Q(c.children, t, e) : [], $ = ct(c, t, e, /* @__PURE__ */ new Set(["test", "condition"]));
488
- if (l.push({
489
- condFid: u,
490
- children: f,
491
- attrs: $.length > 0 ? $ : void 0,
492
- [Et]: _ ? { expr: p, loc: v } : void 0
493
- }), a++, h === w.Else) break;
494
- }
495
- s.push({
496
- type: w.Conditional,
497
- dynamic: 1,
498
- branches: l,
499
- ..._ && { [Et]: { loc: i.loc } }
500
- }), r = a;
501
- } else
502
- s.push(Re(i, t, e)), r++;
503
- }
504
- return s;
505
- }
506
- function Ae(n, t = {}) {
507
- const { filename: e = "anonymous", source: s } = t, r = Gt.get(e);
508
- r.clear();
509
- const o = performance.now(), i = Q(n, [], r), l = performance.now(), a = r.getStats(), c = i.filter((u) => u.dynamic === 1).length, h = {
510
- type: "root",
511
- version: "1.1.0",
512
- // Bump version
513
- functions: r.getFunctions(),
514
- // 获取函数列表快照
515
- nodes: i,
516
- stats: {
517
- totalFunctions: a.total,
518
- cachedFunctions: a.cached,
519
- dynamicNodes: c,
520
- totalNodes: i.length
521
- },
522
- metadata: {
523
- compiledAt: (/* @__PURE__ */ new Date()).toISOString(),
524
- astSize: n.length,
525
- filename: e,
526
- ...s && { source: s }
527
- }
528
- };
529
- return _ && console.log(
530
- `[IRBuilder] ${e} | ${(l - o).toFixed(2)}ms | Nodes: ${i.length} | Fns: ${a.total}`
531
- ), h;
532
- }
533
- function cn(n) {
534
- Gt.clear(n);
535
- }
536
- const Le = /<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/, Me = /* @__PURE__ */ new Set([
537
- "area",
538
- "base",
539
- "br",
540
- "col",
541
- "embed",
542
- "hr",
543
- "img",
544
- "input",
545
- "link",
546
- "meta",
547
- "param",
548
- "source",
549
- "track",
550
- "wbr"
551
- ]), Ie = /\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;
552
- function Pe(n, t) {
553
- const e = [];
554
- let s;
555
- const r = n.replace(/^\s*[^\s"'/>]+/, ""), o = n.length - r.length;
556
- for (; (s = Ie.exec(r)) !== null; ) {
557
- const i = s[1];
558
- if (!i) continue;
559
- const l = s[2] ?? s[3] ?? s[4] ?? "";
560
- let a = i;
561
- be.has(i) && (a = a.replace(/^on/, "@")), a !== "s-model" && (a = a.replace(/^on-/, "@").replace(/^s-/, ":")), a = Ee(a) || a;
562
- const c = s[0], h = c.indexOf("=");
563
- let u;
564
- if (h === -1)
565
- u = c.indexOf(i) + i.length;
566
- else {
567
- let m = h + 1;
568
- for (; m < c.length && /\s/.test(c[m]); ) m++;
569
- if (c[m] === '"' || c[m] === "'") {
570
- let y = m + 1;
571
- for (; y < c.length && /\s/.test(c[y]); )
572
- y++;
573
- u = y;
574
- } else {
575
- let y = m;
576
- for (; y < c.length && /\s/.test(c[y]); ) y++;
577
- u = y;
578
- }
579
- }
580
- let p = s.index + u + o;
581
- const f = n.slice(0, p).split(`
582
- `), d = t[0] + f.length - 1, $ = f.length > 1 ? f[f.length - 1].length + 1 : t[1] + p;
583
- e.push({ key: a, value: l, loc: [d, $] });
584
- }
585
- return e;
586
- }
587
- function Oe(n, t) {
588
- var i;
589
- const e = ((i = (n.match(Le) || [])[1]) == null ? void 0 : i.toLowerCase()) ?? "", s = Pe(n, t);
590
- return {
591
- type: {
592
- for: w.For,
593
- if: w.If,
594
- elseif: w.ElseIf,
595
- else: w.Else
596
- }[e] ?? w.Element,
597
- tag: e,
598
- loc: t,
599
- children: [],
600
- attrs: s
601
- };
602
- }
603
- function _e(n, t) {
604
- const e = n.length;
605
- if (n.startsWith("!--", t)) {
606
- const i = n.indexOf("-->", t + 3);
607
- return i === -1 ? -1 : i + 2;
608
- }
609
- if (n.startsWith("![CDATA[", t)) {
610
- const i = n.indexOf("]]>", t + 8);
611
- return i === -1 ? -1 : i + 2;
612
- }
613
- if (n[t] === "!")
614
- return n.indexOf(">", t + 1);
615
- if (n[t] === "?") {
616
- const i = n.indexOf("?>", t + 1);
617
- return i === -1 ? -1 : i + 1;
618
- }
619
- let s = !1, r = !1, o = t;
620
- for (; o < e; ) {
621
- const i = n[o];
622
- if (i === "'" && !r)
623
- s = !s;
624
- else if (i === '"' && !s)
625
- r = !r;
626
- else if (i === ">" && !s && !r)
627
- return o;
628
- o++;
629
- }
630
- return -1;
631
- }
632
- function Ne(n) {
633
- const t = [];
634
- if (!n) return [];
635
- const e = [], s = [], r = () => {
636
- var c;
637
- return e.length === 0 ? t : (c = e[e.length - 1]).children || (c.children = []);
638
- };
639
- let o = 0;
640
- const i = n.length, l = [0];
641
- for (let c = 0; c < i; c++) n[c] === `
642
- ` && l.push(c + 1);
643
- function a(c) {
644
- let h = 0;
645
- for (let u = 1; u < l.length && !(l[u] > c); u++)
646
- h = u;
647
- return [h + 1, c - l[h] + 1];
648
- }
649
- for (; o < i; ) {
650
- const c = n.indexOf("<", o);
651
- if (c === -1 || c > o) {
652
- const g = n.substring(o, c === -1 ? void 0 : c), b = g.trim();
653
- if (b) {
654
- const E = g.indexOf(b), S = o + E, R = a(S);
655
- r().push({
656
- type: w.Text,
657
- tag: "text",
658
- content: b,
659
- loc: R,
660
- children: []
661
- });
662
- }
663
- if (c === -1) break;
664
- o = c;
665
- }
666
- const h = _e(n, o + 1);
667
- if (h === -1) {
668
- const g = n.substring(o);
669
- g.trim() && r().push({
670
- type: w.Text,
671
- tag: "text",
672
- content: g.trim(),
673
- children: [],
674
- loc: a(o)
675
- });
676
- break;
677
- }
678
- const u = n.substring(o, h + 1), p = r(), v = a(o);
679
- if (u.startsWith("<!--")) {
680
- p.push({
681
- type: w.Comment,
682
- tag: "comment",
683
- content: u.slice(4, -3),
684
- loc: v,
685
- children: []
686
- }), o = h + 1;
687
- continue;
688
- }
689
- if (u.startsWith("<![CDATA[")) {
690
- p.push({
691
- type: w.Text,
692
- tag: "text",
693
- content: u.slice(9, -3),
694
- loc: v,
695
- children: []
696
- }), o = h + 1;
697
- continue;
698
- }
699
- if (u.startsWith("<!") && !u.startsWith("<!--")) {
700
- p.push({
701
- type: w.Comment,
702
- tag: "comment",
703
- content: u.slice(2, -1),
704
- loc: v,
705
- children: []
706
- }), o = h + 1;
707
- continue;
708
- }
709
- if (u.startsWith("<?")) {
710
- p.push({
711
- type: w.Comment,
712
- tag: "comment",
713
- content: u.slice(2, -2),
714
- loc: v,
715
- children: []
716
- }), o = h + 1;
717
- continue;
718
- }
719
- if (u.startsWith("</")) {
720
- const g = s.pop();
721
- for (; e.length > 0; ) {
722
- if ((e[e.length - 1].tag || "").toLowerCase() === (g == null ? void 0 : g.toLowerCase())) {
723
- e.pop();
724
- break;
725
- }
726
- e.pop();
727
- }
728
- o = h + 1;
729
- continue;
730
- }
731
- const f = Oe(u, v);
732
- p.push(f);
733
- const d = f.tag || "", $ = d.toLowerCase().startsWith("script"), m = d.toLowerCase().startsWith("style"), y = u.endsWith("/>") || Me.has(d.toLowerCase());
734
- if (($ || m) && !y) {
735
- const g = `</${d}>`, b = n.toLowerCase().indexOf(g, h + 1);
736
- if (b !== -1) {
737
- const E = n.substring(h + 1, b);
738
- E.length && f.children.push({
739
- type: w.Text,
740
- tag: "text",
741
- content: E,
742
- loc: a(h + 1),
743
- children: []
744
- }), o = b + g.length;
745
- continue;
746
- } else {
747
- const E = n.substring(h + 1);
748
- E.length && f.children.push({
749
- type: w.Text,
750
- tag: "text",
751
- content: E,
752
- loc: a(h + 1),
753
- children: []
754
- }), o = i;
755
- continue;
756
- }
757
- }
758
- !y && f.type !== w.Text && f.type !== w.Comment && (e.push(f), s.push(d)), o = h + 1;
759
- }
760
- return t;
761
- }
762
- const ut = Symbol("solely.raw"), B = /* @__PURE__ */ new WeakMap(), Tt = /* @__PURE__ */ new WeakMap(), At = /* @__PURE__ */ new WeakMap(), Wt = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap();
763
- function Te(n) {
764
- if (n && typeof n == "object") {
765
- const t = n[ut];
766
- if (t) return t;
767
- }
768
- return n;
769
- }
770
- const Dt = (n) => !n || typeof n != "object" ? !1 : n instanceof File || n instanceof Blob || n instanceof FormData || n instanceof ArrayBuffer || n instanceof Response || n instanceof Request;
771
- function We(n) {
772
- return !!(n && n[ut]);
773
- }
774
- const $t = (n, t, e = /* @__PURE__ */ new WeakMap()) => {
775
- if (n === t) return !0;
776
- if (n == null || t == null || typeof n != "object" || typeof t != "object") return n === t;
777
- if (Array.isArray(n) !== Array.isArray(t)) return !1;
778
- if (e.has(n))
779
- return e.get(n) === t;
780
- if (e.set(n, t), Array.isArray(n) && Array.isArray(t)) {
781
- if (n.length !== t.length) return !1;
782
- for (let r = 0; r < n.length; r++)
783
- if (!$t(n[r], t[r], e)) return !1;
784
- return !0;
785
- }
786
- const s = Reflect.ownKeys(n);
787
- if (s.length !== Reflect.ownKeys(t).length) return !1;
788
- for (const r of s) {
789
- if (!Reflect.has(t, r)) return !1;
790
- const o = n[r], i = t[r];
791
- if (!$t(o, i, e)) return !1;
792
- }
793
- return !0;
794
- }, Ft = (n) => {
795
- const t = [];
796
- let e = n;
797
- for (; e; ) {
798
- const s = At.get(e);
799
- if (!s || s.key == null) break;
800
- t.unshift(s.key), e = s.parent;
801
- }
802
- return t;
803
- }, De = (n) => n.map((t) => {
804
- if (t === "") return /^.*$/;
805
- const e = t.replace(/\./g, "\\.").replace(/\*\*/g, "(.+)").replace(/\*/g, "[^.]+").replace(/\[\d+\]/g, "\\[\\d+\\]");
806
- return new RegExp(`^${e}$`);
807
- }), Fe = (n, t) => {
808
- if (t.length === 0) return !0;
809
- const e = n.map(String).join(".");
810
- return t.some((s) => s.test(e));
811
- }, N = (n, t) => {
812
- const e = Ft(n);
813
- let s = n;
814
- for (; s; ) {
815
- const r = B.get(s);
816
- r && r.forEach((i) => {
817
- var h;
818
- if (!i.active) return;
819
- const l = Ft(s), a = [...l, ...e.slice(l.length)];
820
- if (!Fe(a, i.filterRegexes)) return;
821
- const c = { ...t, path: a };
822
- i.throttle > 0 ? (i.pending.push(c), i.timer || (i.timer = setTimeout(() => {
823
- var p;
824
- if (!i.active) return;
825
- const u = [...i.pending];
826
- i.pending = [], i.timer = null, u.length > 0 && ((p = i.onBatch) == null || p.call(i, u), u.forEach((v) => i.callback(v)));
827
- }, i.throttle))) : ((h = i.onBatch) == null || h.call(i, [c]), i.callback(c));
828
- });
829
- const o = At.get(s);
830
- s = (o == null ? void 0 : o.parent) || null;
831
- }
832
- };
833
- function Ve(n, t, e = {}) {
834
- const { throttle: s = 0, onBatch: r, immediate: o = !1, deepCompare: i = !1 } = e, l = Array.isArray(e.filter) ? e.filter : e.filter ? [e.filter] : [], a = De(l), c = {
835
- callback: t,
836
- onBatch: r,
837
- throttle: s,
838
- filterRegexes: a,
839
- pending: [],
840
- timer: null,
841
- active: !0
842
- }, h = (f, d) => {
843
- const $ = {};
844
- return ["push", "pop", "shift", "unshift", "splice"].forEach((m) => {
845
- $[m] = function(...y) {
846
- if (!d) return;
847
- const g = F.get(d) || 0;
848
- F.set(d, g + 1);
849
- const b = f[m].apply(f, y);
850
- if (F.set(d, g), m === "push")
851
- N(d, { type: "array-push", index: f.length - y.length, values: y });
852
- else if (m === "unshift")
853
- N(d, { type: "array-push", index: 0, values: y });
854
- else if (m === "pop")
855
- N(d, { type: "array-splice", index: f.length, deleteCount: 1, insert: [] });
856
- else if (m === "shift")
857
- N(d, { type: "array-splice", index: 0, deleteCount: 1, insert: [] });
858
- else if (m === "splice") {
859
- const [E, S, ...R] = y;
860
- N(d, { type: "array-splice", index: E, deleteCount: S, insert: R });
861
- }
862
- return b;
863
- };
864
- }), ["sort", "reverse", "fill", "copyWithin"].forEach((m) => {
865
- $[m] = function(...y) {
866
- if (!d) return;
867
- const g = F.get(d) || 0;
868
- F.set(d, g + 1);
869
- const b = f[m].apply(f, y);
870
- return F.set(d, g), N(d, { type: "array-reset", method: m }), b;
871
- };
872
- }), ["indexOf", "lastIndexOf", "includes"].forEach((m) => {
873
- $[m] = function(y, ...g) {
874
- let b = f[m].apply(f, [y, ...g]);
875
- return (b === -1 || b === !1) && We(y) && (b = f[m].apply(f, [Te(y), ...g])), b;
876
- };
877
- }), $;
878
- }, u = (f, d, $) => {
879
- if (!Object.isExtensible(f) || Dt(f) || f[ut])
880
- return f;
881
- const m = Tt.get(f);
882
- if (m)
883
- return m;
884
- const y = {
885
- get(b, E, S) {
886
- if (E === ut) return b;
887
- if (Array.isArray(b)) {
888
- const L = Wt.get(g);
889
- if (L && Object.prototype.hasOwnProperty.call(L, E))
890
- return Reflect.get(L, E, S);
891
- }
892
- const R = Reflect.get(b, E, S);
893
- return typeof E == "symbol" ? R : j(R) && !Dt(R) ? u(R, g, E) : R;
894
- },
895
- set(b, E, S, R) {
896
- const L = b[E];
897
- if (i ? $t(L, S) : L === S) return !0;
898
- const st = Reflect.set(b, E, S, R);
899
- return (F.get(g) || 0) === 0 && (Array.isArray(L) && Array.isArray(S) ? N(g, { type: "array-replace", oldValue: L, newValue: S }) : N(g, { type: "set", key: E, newValue: S, oldValue: L })), st;
900
- },
901
- deleteProperty(b, E) {
902
- if (!Reflect.has(b, E)) return !1;
903
- const S = b[E], R = Reflect.deleteProperty(b, E), L = F.get(g) || 0;
904
- return R && L === 0 && N(g, { type: "delete", key: E, oldValue: S }), R;
905
- }
906
- }, g = new Proxy(f, y);
907
- return Tt.set(f, g), At.set(g, { parent: d, key: $ }), Array.isArray(f) && Wt.set(g, h(f, g)), g;
908
- }, p = u(n, null, null);
909
- let v = B.get(p);
910
- if (v || (v = /* @__PURE__ */ new Set(), B.set(p, v)), v.add(c), o) {
911
- const f = (d, $, m = /* @__PURE__ */ new WeakSet()) => {
912
- !j(d) || m.has(d) || (m.add(d), Reflect.ownKeys(d).forEach((y) => {
913
- const g = d[y];
914
- j(g) && m.has(g) || (N($, { type: "set", key: y, newValue: g, oldValue: void 0 }), j(g) && f(g, u(g, $, y), m));
915
- }));
916
- };
917
- f(n, p);
918
- }
919
- return {
920
- proxy: p,
921
- unobserve: () => {
922
- c.active = !1, c.pending = [], c.timer && (clearTimeout(c.timer), c.timer = null);
923
- const f = B.get(p);
924
- f && f.delete(c);
925
- },
926
- resume: () => {
927
- if (c.active) return;
928
- c.active = !0;
929
- let f = B.get(p);
930
- f || (f = /* @__PURE__ */ new Set(), B.set(p, f)), f.has(c) || f.add(c);
931
- },
932
- dispose: () => {
933
- c.active = !1, c.pending = [], c.timer && (clearTimeout(c.timer), c.timer = null);
934
- const f = B.get(p);
935
- f && f.delete(c), c.callback = () => {
936
- }, c.onBatch = void 0;
937
- }
938
- };
939
- }
940
- const ot = Symbol("solely.irCtx"), at = Symbol("solely.irEvents"), O = Symbol.for("solely.irMeta"), yt = Symbol("solely.prevClassObj"), bt = Symbol("solely.prevStyleObj"), Be = {
941
- xml: "http://www.w3.org/XML/1998/namespace",
942
- xlink: "http://www.w3.org/1999/xlink",
943
- xmlns: "http://www.w3.org/2000/xmlns/"
944
- }, Vt = {
945
- readonly: "readOnly",
946
- for: "htmlFor",
947
- tabindex: "tabIndex",
948
- contenteditable: "contentEditable",
949
- maxlength: "maxLength"
950
- }, je = /* @__PURE__ */ new Set(["data-", "aria-", "role", "form"]), Ge = /* @__PURE__ */ new Set([
951
- "value",
952
- "selectedIndex"
953
- ]);
954
- function Ue(n, t) {
955
- var s;
956
- const e = (s = t.attrs) == null ? void 0 : s.find((r) => r.key === "class" && !r.dynamic);
957
- e != null && e.value && n.setAttribute("class", e.value);
958
- }
959
- function qe(n, t) {
960
- var o;
961
- if (!n.style) return;
962
- const s = (o = t.attrs) == null ? void 0 : o.find((i) => i.key === "style" && !i.dynamic), r = s ? qt(s.value) : {};
963
- for (const i in r) {
964
- const l = r[i];
965
- i.startsWith("--") ? n.style.setProperty(i, l) : n.style[i] = l;
966
- }
967
- }
968
- const ze = (n, t) => {
969
- const e = n, s = qt(t), r = e[bt];
970
- if (!r) {
971
- for (const i in s) {
972
- const l = s[i];
973
- i.startsWith("--") ? n.style.setProperty(i, l) : n.style[i] = l;
974
- }
975
- e[bt] = s;
976
- return;
977
- }
978
- let o = !1;
979
- for (const i in r)
980
- i in s || (i.startsWith("--") ? n.style.removeProperty(i) : n.style[i] = "", o = !0);
981
- for (const i in s) {
982
- const l = s[i], a = r[i];
983
- l !== a && (i.startsWith("--") ? n.style.setProperty(i, l) : n.style[i] = l, o = !0);
984
- }
985
- o && (e[bt] = s);
986
- }, Ke = (n, t) => {
987
- const e = n, s = e[yt], r = He(t);
988
- if (!s) {
989
- for (const i in r)
990
- n.classList.add(i);
991
- e[yt] = r;
992
- return;
993
- }
994
- let o = !1;
995
- for (const i in s)
996
- r[i] || (n.classList.remove(i), o = !0);
997
- for (const i in r)
998
- s[i] || (n.classList.add(i), o = !0);
999
- o && (e[yt] = r);
1000
- };
1001
- function qt(n) {
1002
- const t = {}, e = [[n]];
1003
- for (; e.length; ) {
1004
- const [s, r] = e.pop();
1005
- if (s) {
1006
- if (typeof s == "string") {
1007
- const o = /([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g;
1008
- let i;
1009
- for (; (i = o.exec(s)) !== null; ) {
1010
- const l = i[1].trim(), a = i[2].trim();
1011
- l && a && (t[l] = a);
1012
- }
1013
- continue;
1014
- }
1015
- if (Array.isArray(s)) {
1016
- for (let o = s.length - 1; o >= 0; o--)
1017
- e.push([s[o]]);
1018
- continue;
1019
- }
1020
- if (typeof s == "object")
1021
- for (const o in s) {
1022
- const i = s[o];
1023
- if (i == null) continue;
1024
- const l = r ? `${r}-${o}` : o;
1025
- typeof i == "object" && !Array.isArray(i) ? e.push([i, l]) : t[l] = String(i);
1026
- }
1027
- }
1028
- }
1029
- return t;
1030
- }
1031
- function He(n) {
1032
- const t = {}, e = [n];
1033
- for (; e.length; ) {
1034
- const s = e.pop();
1035
- if (s) {
1036
- if (typeof s == "string") {
1037
- const r = s.split(" ");
1038
- for (let o = 0; o < r.length; o++) {
1039
- const i = r[o].trim();
1040
- i && (t[i] = !0);
1041
- }
1042
- } else if (Array.isArray(s))
1043
- for (let r = s.length - 1; r >= 0; r--)
1044
- e.push(s[r]);
1045
- else if (typeof s == "object")
1046
- for (const r in s)
1047
- s[r] && (t[r] = !0);
1048
- }
1049
- }
1050
- return t;
1051
- }
1052
- function St(n, t, e) {
1053
- const s = e == null ? "" : String(e), r = t.indexOf(":");
1054
- if (r > 0) {
1055
- const o = t.slice(0, r), i = Be[o];
1056
- if (i) {
1057
- n.getAttributeNS(i, t) !== s && n.setAttributeNS(i, t, s);
1058
- return;
1059
- }
1060
- }
1061
- n.getAttribute(t) !== s && n.setAttribute(t, s);
1062
- }
1063
- function Bt(n, t, e) {
1064
- const s = Vt[t] || t;
1065
- if (t.startsWith("data-") || t.startsWith("aria-") || je.has(t)) {
1066
- St(n, t, e);
1067
- return;
1068
- }
1069
- const r = n, o = r.tagName;
1070
- if (e == null) {
1071
- if (typeof r[s] == "boolean")
1072
- r[s] !== !1 && (r[s] = !1);
1073
- else {
1074
- const l = r[s];
1075
- l !== "" && l !== void 0 && (r[s] = ""), n.hasAttribute(t) && n.removeAttribute(t);
1076
- }
1077
- return;
1078
- }
1079
- if (s === "src" || s === "href") {
1080
- const l = String(e);
1081
- if (r[s] === l || n.getAttribute(s) === l)
1082
- return;
1083
- }
1084
- if (s === "value" && (o === "INPUT" || o === "TEXTAREA") && r.value === e)
1085
- return;
1086
- if (typeof e == "boolean") {
1087
- if (r[s] === e)
1088
- return;
1089
- r[s] = e;
1090
- return;
1091
- }
1092
- (n instanceof SVGElement || r.ownerSVGElement !== void 0) && !Vt[t] ? St(n, t, e) : r[s] !== e && (r[s] = e);
1093
- }
1094
- class Ye {
1095
- constructor(t, e, s = {}) {
1096
- x(this, "nodeMap", /* @__PURE__ */ new Map());
1097
- x(this, "marker", !1);
1098
- this.ir = t, this.container = e, this.scope = s;
1099
- }
1100
- evalIR(t, e, s) {
1101
- var o;
1102
- const r = this.ir.functions[t - 1];
1103
- try {
1104
- return r ? r.apply(this.scope, e) : "";
1105
- } catch (i) {
1106
- return ae(i.message || i.toString(), ((o = this.ir.metadata) == null ? void 0 : o.source) || "", s, this.scope.tagName), "";
1107
- }
1108
- }
1109
- // ================ 创建节点 ================
1110
- createElement(t, e) {
1111
- const s = t.tag;
1112
- return e instanceof SVGElement || s === "svg" ? document.createElementNS("http://www.w3.org/2000/svg", s) : document.createElement(s);
1113
- }
1114
- createText(t, e) {
1115
- const s = t.dynamic ? this.evalIR(t.fid, [e], t[O]) : t.txt || "";
1116
- return document.createTextNode(s);
1117
- }
1118
- createComment(t, e) {
1119
- const s = t.dynamic ? this.evalIR(t.fid, [e], t[O]) : t.txt || "";
1120
- return document.createComment(s);
1121
- }
1122
- // ================ 属性全量应用(创建或更新时用) ================
1123
- applyAttrs(t, e, s, r = !1) {
1124
- const o = [], i = t;
1125
- i[ot] || (i[ot] = {
1126
- loops: null
1127
- }), i[ot].loops = s, i[at] || (i[at] = /* @__PURE__ */ Object.create(null));
1128
- let l, a = !1, c, h = !1;
1129
- for (const u of e) {
1130
- const { key: p, fid: v, dynamic: f, value: d } = u;
1131
- if (p === ":class") {
1132
- l = this.evalIR(v, [s], u[O]), a = !0;
1133
- continue;
1134
- }
1135
- if (p === ":style") {
1136
- c = this.evalIR(v, [s], u[O]), h = !0;
1137
- continue;
1138
- }
1139
- if (p === "class" || p === "style")
1140
- continue;
1141
- const $ = p[0];
1142
- if ($ === "@") {
1143
- const y = p.slice(1), g = u.role ?? "user";
1144
- let b = i[at][y];
1145
- if (b || (b = i[at][y] = {
1146
- model: [],
1147
- user: []
1148
- }, t.addEventListener(y, (E) => {
1149
- for (const S of b.model)
1150
- S(E);
1151
- for (const S of b.user)
1152
- S(E);
1153
- })), !r) {
1154
- const E = (S) => this.evalIR(
1155
- v,
1156
- [S, i[ot].loops],
1157
- u[O]
1158
- );
1159
- b[g].push(E);
1160
- }
1161
- continue;
1162
- }
1163
- if (p === "mounted") {
1164
- r || requestAnimationFrame(
1165
- () => this.evalIR(v, [t, s], u[O])
1166
- );
1167
- continue;
1168
- }
1169
- if (p === "updated") {
1170
- r && requestAnimationFrame(
1171
- () => this.evalIR(v, [t, s], u[O])
1172
- );
1173
- continue;
1174
- }
1175
- if (p === "ref" && d) {
1176
- this.scope.$refs = this.scope.$refs || {}, this.scope.$refs[d] = t;
1177
- continue;
1178
- }
1179
- const m = f ? this.evalIR(v, [s], u[O]) : d ?? "";
1180
- if ($ === ":") {
1181
- const y = p.slice(1);
1182
- t.tagName === "SELECT" && Ge.has(y) ? o.push(() => Bt(t, y, m)) : Bt(t, y, m);
1183
- } else r || St(t, p, String(m));
1184
- }
1185
- return a && Ke(t, l), h && ze(t, c), o;
1186
- }
1187
- // ================ 更新已有节点 Text Or Comment ================
1188
- updateNode(t, e, s) {
1189
- const r = e.dynamic ? this.evalIR(e.fid, [s], e[O]) : e.txt || "";
1190
- e.dynamic && t.textContent !== r && (t.textContent = r);
1191
- }
1192
- // ================ 核心遍历 ================
1193
- irToNode(t, e, s, r, o) {
1194
- var c, h, u, p;
1195
- const i = s + "-" + e, l = this.nodeMap.get(i);
1196
- let a;
1197
- if (l) {
1198
- a = l.node, l.marker = this.marker;
1199
- let v = [];
1200
- t.dynamic && (t.type === w.Element ? v = this.applyAttrs(
1201
- a,
1202
- t.attrs ?? [],
1203
- o,
1204
- !0
1205
- ) : this.updateNode(a, t, o)), (c = t.children) == null || c.forEach((f, d) => {
1206
- this.irToNode(f, d, i, a, o);
1207
- }), v.forEach((f) => f());
1208
- } else
1209
- switch (t.type) {
1210
- case w.Element:
1211
- a = this.createElement(t, r), Ue(a, t), qe(a, t);
1212
- const v = this.applyAttrs(a, t.attrs ?? [], o);
1213
- r.appendChild(a), this.nodeMap.set(i, { irNode: t, node: a, loops: o, marker: this.marker }), (h = t.children) == null || h.forEach((f, d) => {
1214
- this.irToNode(f, d, i, a, o);
1215
- }), v.forEach((f) => f());
1216
- break;
1217
- case w.Text:
1218
- a = this.createText(t, o), r.appendChild(a), this.nodeMap.set(i, { irNode: t, node: a, loops: o, marker: this.marker });
1219
- break;
1220
- case w.Comment:
1221
- a = this.createComment(t, o), r.appendChild(a), this.nodeMap.set(i, { irNode: t, node: a, loops: o, marker: this.marker });
1222
- break;
1223
- case w.For: {
1224
- const f = `${i}-end`;
1225
- let d = (u = this.nodeMap.get(f)) == null ? void 0 : u.node;
1226
- d ? this.nodeMap.get(f).marker = this.marker : (d = document.createComment(`for:${i}`), r.appendChild(d), this.nodeMap.set(f, {
1227
- irNode: { type: w.Comment },
1228
- node: d,
1229
- loops: o,
1230
- marker: this.marker
1231
- }));
1232
- const $ = this.evalIR(t.fid, [o], t[O]) || [], m = document.createDocumentFragment();
1233
- $.forEach((y, g) => {
1234
- var E;
1235
- const b = [...o, { itmVal: y, idxVal: g }];
1236
- (E = t.children) == null || E.forEach((S, R) => {
1237
- this.irToNode(S, R, `${i}-for-${g}`, m, b);
1238
- });
1239
- }), d.parentNode.insertBefore(m, d);
1240
- break;
1241
- }
1242
- case w.Conditional: {
1243
- const f = `${i}-end`;
1244
- let d = (p = this.nodeMap.get(f)) == null ? void 0 : p.node;
1245
- d ? this.nodeMap.get(f).marker = this.marker : (d = document.createComment(`if:${i}`), r.appendChild(d), this.nodeMap.set(f, { irNode: {}, node: d, loops: o, marker: this.marker }));
1246
- for (let $ = 0; $ < (t.branches || []).length; $++) {
1247
- const m = t.branches[$];
1248
- if (m.condFid === null || this.evalIR(m.condFid, [o], m[O])) {
1249
- const g = document.createDocumentFragment();
1250
- m.children.forEach((b, E) => {
1251
- this.irToNode(b, E, `${i}-if-${$}`, g, o);
1252
- }), d.parentNode.insertBefore(g, d);
1253
- break;
1254
- }
1255
- }
1256
- break;
1257
- }
1258
- }
1259
- }
1260
- // ================ 清理被删除的节点 ================
1261
- cleanupOldNodes() {
1262
- for (const [t, e] of this.nodeMap.entries())
1263
- if (e.marker !== this.marker) {
1264
- const { irNode: s, node: r, loops: o } = e;
1265
- if (s.attrs) {
1266
- const i = s.attrs.find((a) => a.key === "unmounted");
1267
- i && requestAnimationFrame(() => {
1268
- this.evalIR(
1269
- i.fid,
1270
- [r, o],
1271
- i[O]
1272
- );
1273
- });
1274
- const l = s.attrs.find((a) => a.key === "ref");
1275
- l && l.value && delete this.scope.$refs[l.value];
1276
- }
1277
- r == null || r.remove(), this.nodeMap.delete(t);
1278
- }
1279
- }
1280
- // ================ 公共 API ================
1281
- mount() {
1282
- this.marker = !this.marker, this.ir.nodes.forEach((t, e) => {
1283
- this.irToNode(t, e, "root", this.container, []);
1284
- }), this.cleanupOldNodes();
1285
- }
1286
- update() {
1287
- this.marker = !this.marker, this.ir.nodes.forEach((t, e) => {
1288
- this.irToNode(t, e, "root", this.container, []);
1289
- }), this.cleanupOldNodes();
1290
- }
1291
- destroy() {
1292
- this.container.innerHTML = "", this.nodeMap.clear();
1293
- }
1294
- }
1295
- const Ze = (n, t, e = {}) => {
1296
- const s = new Ye(n, t, e);
1297
- return s.mount(), {
1298
- update: () => s.update(),
1299
- destroy: () => s.destroy()
1300
- };
1301
- }, jt = Symbol.for("solely.manifest");
1302
- var W, V, K, et, H, G, Y, Z, U, nt, k, zt, xt, Kt, Ht, kt, lt, Yt, Zt, Ct;
1303
- const tt = class tt extends HTMLElement {
1304
- /* -------------------- 构造 -------------------- */
1305
- constructor(e = {}) {
1306
- var o;
1307
- super();
1308
- P(this, k);
1309
- P(this, W);
1310
- P(this, V);
1311
- P(this, K);
1312
- P(this, et);
1313
- P(this, H);
1314
- P(this, G);
1315
- P(this, Y, !1);
1316
- P(this, Z, !1);
1317
- P(this, U, !1);
1318
- P(this, nt, !1);
1319
- const s = this.constructor;
1320
- A(this, W, s[jt] || { tagName: "base-element" });
1321
- const r = C(this, W);
1322
- A(this, H, (o = r.shadowDOM) != null && o.use ? this.attachShadow({ mode: r.shadowDOM.mode || "open" }) : this), M(this, k, xt).call(this, e), M(this, k, Ht).call(this, r), queueMicrotask(() => M(this, k, Ct).call(this));
1323
- }
1324
- // 需要在元素定义前设置的属性列表(Upgrade Property)
1325
- /* -------------------- observedAttributes -------------------- */
1326
- static get observedAttributes() {
1327
- const e = this[jt];
1328
- return e != null && e.propMap ? Array.from(e.propMap.keys()) : [];
1329
- }
1330
- /* -------------------- $data -------------------- */
1331
- get $data() {
1332
- return C(this, et);
1333
- }
1334
- set $data(e) {
1335
- var s;
1336
- j(e) || (e = {}), (s = C(this, G)) == null || s.call(this), M(this, k, xt).call(this, e), M(this, k, lt).call(this);
1337
- }
1338
- refresh() {
1339
- M(this, k, lt).call(this);
1340
- }
1341
- /* -------------------- 生命周期 -------------------- */
1342
- connectedCallback() {
1343
- var l;
1344
- const s = this.constructor.upgradeProps;
1345
- let r;
1346
- Array.isArray(s) ? r = s.includes("$data") ? s : [...s, "$data"] : r = ["$data"], M(this, k, zt).call(this, r), M(this, k, Ct).call(this);
1347
- const o = C(this, W);
1348
- if ((o.className || o.tagName || "").split(" ").forEach((a) => a && this.classList.add(a)), M(this, k, Zt).call(this), o.propMap && j(this.$data))
1349
- for (const [a, c] of o.propMap) {
1350
- const h = c.name;
1351
- if (this.hasAttribute(a)) {
1352
- const u = this.getAttribute(a), p = M(this, k, kt).call(this, u, c.default, c.type);
1353
- this.$data[h] = p;
1354
- } else "default" in c && (this.$data[h] = c.default);
1355
- }
1356
- C(this, K) && A(this, V, Ze(
1357
- C(this, K),
1358
- C(this, H),
1359
- this
1360
- )), this.mounted(), (l = this.onInit) == null || l.call(this);
1361
- }
1362
- disconnectedCallback() {
1363
- var e, s, r;
1364
- this.unmounted(), (e = C(this, G)) == null || e.call(this), A(this, G, void 0), (r = (s = C(this, V)) == null ? void 0 : s.destroy) == null || r.call(s), A(this, V, null);
1365
- }
1366
- attributeChangedCallback(e, s, r) {
1367
- var h;
1368
- if (s === r || !j(this.$data)) return;
1369
- const i = (h = C(this, W).propMap) == null ? void 0 : h.get(e);
1370
- if (!i) return;
1371
- const l = i.name, a = this.$data[l], c = M(this, k, kt).call(this, r, i.default ?? a, i.type);
1372
- this.$data[l] = c, A(this, U, !0), this.attributeChanged(e, a, c);
1373
- }
1374
- /* -------------------- 事件派发 -------------------- */
1375
- emit(e, s, r) {
1376
- this.dispatchEvent(
1377
- new CustomEvent(e, {
1378
- bubbles: !0,
1379
- composed: !0,
1380
- detail: s,
1381
- ...r
1382
- })
1383
- );
1384
- }
1385
- /* -------------------- 钩子 -------------------- */
1386
- onInit() {
1387
- }
1388
- created() {
1389
- }
1390
- mounted() {
1391
- }
1392
- beforeUpdate() {
1393
- }
1394
- updated() {
1395
- }
1396
- unmounted() {
1397
- }
1398
- attributeChanged(e, s, r) {
1399
- }
1400
- beforeAttributesUpdate() {
1401
- }
1402
- afterAttributesUpdate() {
1403
- }
1404
- };
1405
- W = new WeakMap(), V = new WeakMap(), K = new WeakMap(), et = new WeakMap(), H = new WeakMap(), G = new WeakMap(), Y = new WeakMap(), Z = new WeakMap(), U = new WeakMap(), nt = new WeakMap(), k = new WeakSet(), // 升级属性(Upgrade Property), 保障在元素被定义前设置的属性能正确触发响应式更新
1406
- zt = function(e) {
1407
- for (const s of e)
1408
- if (this.hasOwnProperty(s)) {
1409
- const r = this[s];
1410
- delete this[s], this[s] = r;
1411
- }
1412
- }, /* -------------------- 初始化 -------------------- */
1413
- xt = function(e) {
1414
- const { proxy: s, dispose: r } = Ve(e, (o) => {
1415
- var i, l;
1416
- if (o.type === "set") {
1417
- const { key: a, newValue: c } = o, h = C(this, W), u = String(a), p = ((i = h.propMap) == null ? void 0 : i.get(
1418
- u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()
1419
- )) || Array.from(((l = h.propMap) == null ? void 0 : l.values()) || []).find((v) => v.name === u);
1420
- p != null && p.reflect && M(this, k, Kt).call(this, p, c);
1421
- }
1422
- this.emit("change", {
1423
- source: "state",
1424
- ...o
1425
- }), M(this, k, lt).call(this);
1426
- });
1427
- A(this, et, s), A(this, G, r);
1428
- }, Kt = function(e, s) {
1429
- const r = e.name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
1430
- if (e.type === "boolean")
1431
- s ? this.setAttribute(r, "") : this.removeAttribute(r);
1432
- else {
1433
- const o = typeof s == "object" ? JSON.stringify(s) : String(s);
1434
- this.setAttribute(r, o);
1435
- }
1436
- }, Ht = function(e) {
1437
- e.ir && A(this, K, e.ir);
1438
- }, kt = function(e, s, r) {
1439
- if (e === null)
1440
- return r === "boolean" ? s ?? !1 : s;
1441
- switch (r) {
1442
- case "boolean":
1443
- return !0;
1444
- case "number": {
1445
- const o = Number(e);
1446
- return isNaN(o) ? s : o;
1447
- }
1448
- case "object":
1449
- try {
1450
- return JSON.parse(e);
1451
- } catch {
1452
- return s;
1453
- }
1454
- default:
1455
- return e;
1456
- }
1457
- }, /* -------------------- 刷新调度 -------------------- */
1458
- lt = function() {
1459
- C(this, Z) || !C(this, V) || (A(this, Z, !0), queueMicrotask(() => {
1460
- A(this, Z, !1), M(this, k, Yt).call(this);
1461
- }));
1462
- }, Yt = function() {
1463
- C(this, Y) || !this.isConnected || (A(this, Y, !0), C(this, U) && this.beforeAttributesUpdate(), this.beforeUpdate(), C(this, V).update(), this.updated(), C(this, U) && (this.afterAttributesUpdate(), A(this, U, !1)), A(this, Y, !1));
1464
- }, Zt = function() {
1465
- const e = C(this, W);
1466
- if (!e.styles) return;
1467
- const s = C(this, H);
1468
- if (e.sheet && s instanceof ShadowRoot && "adoptedStyleSheets" in s) {
1469
- s.adoptedStyleSheets.includes(e.sheet) || (s.adoptedStyleSheets = [...s.adoptedStyleSheets, e.sheet]);
1470
- return;
1471
- }
1472
- const r = s instanceof ShadowRoot ? s : document.head, o = `solely-style-${e.tagName}`;
1473
- if (!r.querySelector(`#${o}`)) {
1474
- const i = document.createElement("style");
1475
- i.id = o, i.textContent = e.styles, r.appendChild(i);
1476
- }
1477
- }, /* -------------------- created 保障 -------------------- */
1478
- Ct = function() {
1479
- C(this, nt) || (A(this, nt, !0), this.created());
1480
- }, x(tt, "upgradeProps"), (() => {
1481
- if (_) {
1482
- const e = customElements.define, s = /* @__PURE__ */ new WeakSet();
1483
- customElements.define = function(r, o, i) {
1484
- if (tt.isPrototypeOf(o) && !s.has(o)) {
1485
- s.add(o);
1486
- const l = o.prototype, a = [
1487
- "connectedCallback",
1488
- "disconnectedCallback",
1489
- "attributeChangedCallback"
1490
- ];
1491
- for (const c of a)
1492
- l[c] !== tt.prototype[c] && console.error(
1493
- `[${r}] 禁止重写 ${c}(),请使用框架钩子`
1494
- );
1495
- }
1496
- return e.call(this, r, o, i);
1497
- };
1498
- }
1499
- })();
1500
- let ht = tt;
1501
- const Je = Symbol.for("solely.manifest"), Jt = (n) => {
1502
- const t = n;
1503
- return (e) => {
1504
- const { tagName: s } = t;
1505
- if (customElements.get(s))
1506
- return _ && console.warn(`[Solely] 标签名称 "${s}" 已经被注册,跳过重复定义。`), e;
1507
- if (typeof t.template == "string" && !t.ir)
1508
- try {
1509
- const o = Ne(t.template);
1510
- t.ir = Ae(o, {
1511
- source: t.template,
1512
- filename: s
1513
- });
1514
- } catch (o) {
1515
- console.error(`[Compiler Error] <${s}>:`, o);
1516
- }
1517
- if (t.styles && !t.sheet && "CSSStyleSheet" in window)
1518
- try {
1519
- const o = new CSSStyleSheet();
1520
- typeof o.replaceSync == "function" && (o.replaceSync(t.styles), t.sheet = o);
1521
- } catch {
1522
- _ && console.warn(`[Style Warning] <${s}>: CSSStyleSheet 不可用,将使用 style 标签回退方案`);
1523
- }
1524
- if (t.props && !t.propMap) {
1525
- const o = /* @__PURE__ */ new Map();
1526
- t.props.forEach((i) => {
1527
- const l = typeof i == "string" ? { name: i } : i, a = l.name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c = a.replace(/-([a-z])/g, (h, u) => u.toUpperCase());
1528
- o.set(a, { ...l, name: c });
1529
- }), t.propMap = o;
1530
- }
1531
- class r extends e {
1532
- }
1533
- return r[Je] = t, customElements.define(s, r), r;
1534
- };
1535
- };
1536
- let z = null, Xt;
1537
- const Qt = new Promise((n) => {
1538
- Xt = n;
1539
- });
1540
- function ln(n) {
1541
- return z || (z = new Xe(n), Xt(z), z);
1542
- }
1543
- function wt() {
1544
- return z;
1545
- }
1546
- class Xe {
1547
- constructor(t) {
1548
- x(this, "routes");
1549
- x(this, "base");
1550
- x(this, "mode");
1551
- x(this, "beforeEachGuard");
1552
- x(this, "afterEachGuard");
1553
- x(this, "currentRoute", null);
1554
- x(this, "listeners", /* @__PURE__ */ new Set());
1555
- x(this, "isStarted", !1);
1556
- this.routes = t.routes, this.base = t.base ?? "/", this.mode = t.mode || "history", this.beforeEachGuard = t.beforeEach, this.afterEachGuard = t.afterEach;
1557
- }
1558
- // --- 核心匹配逻辑 ---
1559
- matchRoute(t = "/") {
1560
- const e = t.startsWith("/") ? t : "/" + t, [s, r] = e.split("?"), o = s.split("/").filter(Boolean), i = this.parseQuery(r), l = this.recursiveMatch(this.routes, o);
1561
- if (l) {
1562
- const a = l.matched[l.matched.length - 1];
1563
- return a.config.redirect ? this.matchRoute(a.config.redirect) : {
1564
- matched: l.matched,
1565
- // 这里的结构已经是 [{config, params}, ...]
1566
- params: l.params,
1567
- // 全局合并后的 params
1568
- query: i,
1569
- fullPath: e,
1570
- // 合并所有层级的 meta
1571
- meta: l.matched.reduce((c, h) => ({ ...c, ...h.config.meta || {} }), {})
1572
- };
1573
- }
1574
- return null;
1575
- }
1576
- recursiveMatch(t, e) {
1577
- const s = [...t].sort((r, o) => this.calculateScore(o.path) - this.calculateScore(r.path));
1578
- for (const r of s) {
1579
- const o = r.path.split("/").filter(Boolean), i = {};
1580
- let l = !0;
1581
- if (o.length === 0 && e.length === 0)
1582
- return {
1583
- matched: [{ config: r, params: {} }],
1584
- params: {}
1585
- };
1586
- for (let a = 0; a < o.length; a++) {
1587
- const c = o[a], h = e[a];
1588
- if (c.startsWith(":")) {
1589
- if (!h) {
1590
- l = !1;
1591
- break;
1592
- }
1593
- i[c.slice(1)] = h;
1594
- } else if (c === "*") {
1595
- l = !0;
1596
- break;
1597
- } else if (c !== h) {
1598
- l = !1;
1599
- break;
1600
- }
1601
- }
1602
- if (l) {
1603
- const a = o.length, c = e.slice(a), h = { config: r, params: i };
1604
- if (c.length > 0 && r.children) {
1605
- const u = this.recursiveMatch(r.children, c);
1606
- if (u)
1607
- return {
1608
- matched: [h, ...u.matched],
1609
- params: { ...i, ...u.params }
1610
- // 全局合并 params
1611
- };
1612
- } else if (c.length === 0 || o.includes("*"))
1613
- return {
1614
- matched: [h],
1615
- params: i
1616
- };
1617
- }
1618
- }
1619
- return null;
1620
- }
1621
- calculateScore(t = "/") {
1622
- const e = t.split("/").filter(Boolean);
1623
- return e.length === 0 ? 1 : e.reduce((s, r) => r.startsWith(":") ? s + 5 : r === "*" ? s + 0 : s + 10, 0);
1624
- }
1625
- parseQuery(t) {
1626
- const e = {};
1627
- return t && new URLSearchParams(t).forEach((r, o) => {
1628
- e[o] = r;
1629
- }), e;
1630
- }
1631
- normalizePath(t = "/") {
1632
- let e = t && typeof t == "string" ? t : "/";
1633
- return e.startsWith("/") || (e = "/" + e), e.length > 1 && e.endsWith("/") && (e = e.slice(0, -1)), e;
1634
- }
1635
- // --- 导航逻辑 ---
1636
- getPath() {
1637
- let t;
1638
- try {
1639
- t = this.mode === "hash" ? window.location.hash.slice(1) || "/" : window.location.pathname || "/";
1640
- } catch {
1641
- t = "/";
1642
- }
1643
- const e = this.base || "/";
1644
- return e !== "/" && t.startsWith(e) && (t = t.slice(e.length) || "/"), this.normalizePath(t);
1645
- }
1646
- updateBrowserHistory(t = "/", e) {
1647
- const s = this.normalizePath(t), r = this.base || "/";
1648
- if (this.mode === "hash")
1649
- e ? window.location.replace(`#${s}`) : window.location.hash = s;
1650
- else {
1651
- const o = r.endsWith("/") ? r.slice(0, -1) : r, i = o === "/" ? s : o + s;
1652
- e ? window.history.replaceState({ path: i }, "", i) : window.history.pushState({ path: i }, "", i);
1653
- }
1654
- }
1655
- /**
1656
- * @param fromEvent 标志位:是否由浏览器 popstate 事件触发
1657
- */
1658
- async navigate(t = "/", e = !1, s = !1) {
1659
- const r = this.normalizePath(t), o = this.currentRoute, i = this.matchRoute(r);
1660
- if (!i) return { success: !1, error: `No route matched: ${r}` };
1661
- if (o && o.fullPath === i.fullPath) return { success: !0 };
1662
- if (this.beforeEachGuard)
1663
- try {
1664
- const l = await this.beforeEachGuard(i, o);
1665
- if (l === !1) return { success: !1, cancelled: !0 };
1666
- if (typeof l == "string") return this.navigate(l, e);
1667
- } catch (l) {
1668
- return { success: !1, error: l instanceof Error ? l.message : "Guard Error" };
1669
- }
1670
- return this.currentRoute = i, s || this.updateBrowserHistory(r, e), this.notifyListeners(), this.afterEachGuard && this.afterEachGuard(i, o), { success: !0 };
1671
- }
1672
- // --- 路径解析逻辑 ---
1673
- /**
1674
- * 将逻辑路径解析为浏览器真实的 URL 路径
1675
- * 供 RouterLink 等组件生成 href 使用
1676
- */
1677
- resolve(t = "/") {
1678
- const e = this.normalizePath(t);
1679
- if (this.mode === "hash") return `#${e}`;
1680
- const s = this.base.endsWith("/") ? this.base.slice(0, -1) : this.base;
1681
- return s === "/" ? e : s + e;
1682
- }
1683
- /**
1684
- * 获取当前模式(供外部组件判断,如 RouterLink)
1685
- */
1686
- get modeType() {
1687
- return this.mode;
1688
- }
1689
- pushWithQuery(t = "/", e) {
1690
- const s = new URLSearchParams(e).toString(), r = t.includes("?") ? "&" : "?";
1691
- return this.push(t + (s ? r + s : ""));
1692
- }
1693
- push(t = "/") {
1694
- return this.navigate(t, !1);
1695
- }
1696
- replace(t = "/") {
1697
- return this.navigate(t, !0);
1698
- }
1699
- back() {
1700
- window.history.back();
1701
- }
1702
- listen(t) {
1703
- return this.listeners.add(t), () => this.listeners.delete(t);
1704
- }
1705
- notifyListeners() {
1706
- this.listeners.forEach((t) => t());
1707
- }
1708
- setupListeners() {
1709
- if (this.isStarted) return;
1710
- const t = () => {
1711
- this.navigate(this.getPath(), !0, !0);
1712
- };
1713
- window.addEventListener("popstate", t), this.mode === "hash" && !window.location.hash && (window.location.hash = "/"), this.navigate(this.getPath(), !0);
1714
- }
1715
- getCurrentRoute() {
1716
- return this.currentRoute;
1717
- }
1718
- }
1719
- var Qe = Object.getOwnPropertyDescriptor, tn = (n, t, e, s) => {
1720
- for (var r = s > 1 ? void 0 : s ? Qe(t, e) : t, o = n.length - 1, i; o >= 0; o--)
1721
- (i = n[o]) && (r = i(r) || r);
1722
- return r;
1723
- };
1724
- let ft = class extends ht {
1725
- constructor() {
1726
- super(...arguments);
1727
- x(this, "unsubscribe");
1728
- x(this, "level", 0);
1729
- x(this, "currentElement", null);
1730
- x(this, "currentTagName", null);
1731
- x(this, "routerAttrs", /* @__PURE__ */ new Set());
1732
- x(this, "prevPropKeys", /* @__PURE__ */ new Set());
1733
- x(this, "scheduled", !1);
1734
- x(this, "cache", /* @__PURE__ */ new Map());
1735
- x(this, "latestLoadId", 0);
1736
- }
1737
- /* -------------------- 生命周期 -------------------- */
1738
- async mounted() {
1739
- this.detectLevel();
1740
- const t = await Qt;
1741
- this.unsubscribe = t.listen(() => {
1742
- this.scheduleLoad(t.getCurrentRoute());
1743
- }), this.loadRoute(t.getCurrentRoute());
1744
- }
1745
- unmounted() {
1746
- var t;
1747
- (t = this.unsubscribe) == null || t.call(this), this.cache.forEach((e) => e.remove()), this.cache.clear();
1748
- }
1749
- /* -------------------- 逻辑核心 -------------------- */
1750
- scheduleLoad(t) {
1751
- this.scheduled || (this.scheduled = !0, queueMicrotask(() => {
1752
- this.scheduled = !1, this.loadRoute(t);
1753
- }));
1754
- }
1755
- detectLevel() {
1756
- let t = 0, e = this.parentElement;
1757
- for (; e; )
1758
- e instanceof ft && t++, e = e.parentElement;
1759
- this.level = t;
1760
- }
1761
- async loadRoute(t) {
1762
- const e = ++this.latestLoadId, s = t == null ? void 0 : t.matched[this.level];
1763
- if (!s) {
1764
- this.handleEmptyRoute();
1765
- return;
1766
- }
1767
- const { config: r } = s;
1768
- let o = r.tagName;
1769
- if (!o && typeof r.component == "function") {
1770
- this.renderLoading();
1771
- try {
1772
- const l = await r.component();
1773
- o = typeof l == "string" ? l : l.tagName;
1774
- } catch (l) {
1775
- this.renderError(`Load Error: ${l}`);
1776
- return;
1777
- }
1778
- }
1779
- if (e !== this.latestLoadId) return;
1780
- if (!o) {
1781
- this.clear();
1782
- return;
1783
- }
1784
- if (!r.forceReload && this.currentElement && this.currentTagName === o.toLowerCase()) {
1785
- this.syncState(this.currentElement, t == null ? void 0 : t.params, (t == null ? void 0 : t.query) || {}, r.props);
1786
- return;
1787
- }
1788
- this.clear(r.keepAlive);
1789
- const i = this.getOrCreateComponent(o, r);
1790
- this.syncState(i, t == null ? void 0 : t.params, (t == null ? void 0 : t.query) || {}, r.props), this.appendChild(i), this.currentElement = i, this.currentTagName = o.toLowerCase();
1791
- }
1792
- getOrCreateComponent(t, e) {
1793
- const s = t.toLowerCase();
1794
- if (e.keepAlive && this.cache.has(s))
1795
- return this.cache.get(s);
1796
- const r = document.createElement(t);
1797
- return e.keepAlive && this.cache.set(s, r), r;
1798
- }
1799
- syncState(t, e, s, r = {}) {
1800
- const o = (a) => a.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i = /* @__PURE__ */ new Map();
1801
- Object.entries(e).forEach(([a, c]) => i.set(o(a), String(c))), Object.entries(s).forEach(([a, c]) => i.set(`query-${o(a)}`, String(c))), this.routerAttrs.forEach((a) => {
1802
- i.has(a) || (t.removeAttribute(a), this.routerAttrs.delete(a));
1803
- }), i.forEach((a, c) => {
1804
- t.getAttribute(c) !== a && t.setAttribute(c, a), this.routerAttrs.add(c);
1805
- });
1806
- const l = new Set(Object.keys(r));
1807
- this.prevPropKeys.forEach((a) => {
1808
- l.has(a) || (t[a] = void 0);
1809
- }), Object.entries(r).forEach(([a, c]) => {
1810
- t[a] !== c && (t[a] = c);
1811
- }), this.prevPropKeys = l;
1812
- }
1813
- handleEmptyRoute() {
1814
- this.clear(), this.level === 0 && this.renderError("404 Not Found");
1815
- }
1816
- renderLoading() {
1817
- this.innerHTML = '<div style="padding:20px; color:#999;">Loading...</div>';
1818
- }
1819
- renderError(t) {
1820
- this.innerHTML = `<div style="padding:20px; color:#ff4d4f;">${t}</div>`;
1821
- }
1822
- clear(t = !1) {
1823
- this.currentElement ? this.contains(this.currentElement) && this.removeChild(this.currentElement) : t || (this.innerHTML = ""), this.currentElement = null, this.currentTagName = null, this.routerAttrs.clear(), this.prevPropKeys.clear();
1824
- }
1825
- };
1826
- ft = tn([
1827
- Jt({
1828
- tagName: "router-view"
1829
- // 注意:删除了 shadowDOM 配置,默认为 false
1830
- })
1831
- ], ft);
1832
- const un = ft;
1833
- var en = Object.getOwnPropertyDescriptor, nn = (n, t, e, s) => {
1834
- for (var r = s > 1 ? void 0 : s ? en(t, e) : t, o = n.length - 1, i; o >= 0; o--)
1835
- (i = n[o]) && (r = i(r) || r);
1836
- return r;
1837
- };
1838
- let Rt = class extends ht {
1839
- constructor() {
1840
- super(...arguments);
1841
- x(this, "_prefetched", !1);
1842
- }
1843
- set to(t) {
1844
- this.$data.to = t, this.updateState();
1845
- }
1846
- get to() {
1847
- return this.$data.to;
1848
- }
1849
- async mounted() {
1850
- (await Qt).listen(() => this.updateState()), this.updateState(), this.addEventListener("click", (e) => {
1851
- var r, o;
1852
- e.defaultPrevented || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.button !== 0 || (r = e.target.closest("a")) != null && r.getAttribute("target") || (e.preventDefault(), (o = wt()) == null || o.push(this.$data.to));
1853
- }), this.addEventListener("mouseenter", () => {
1854
- this.prefetchRoute();
1855
- }, { once: !0 });
1856
- }
1857
- updateState() {
1858
- const t = wt();
1859
- if (!t) return;
1860
- this.$data.href = t.resolve(this.$data.to);
1861
- let e = !1;
1862
- if (this.$data.active)
1863
- e = !0;
1864
- else {
1865
- const r = t.getCurrentRoute();
1866
- if (r) {
1867
- const o = r.fullPath;
1868
- this.hasAttribute("exact") ? e = o === this.$data.to : e = o === this.$data.to || o.startsWith(this.$data.to + "/");
1869
- }
1870
- }
1871
- this.$data.isActive = e;
1872
- const s = this.$data.activeClass || "active";
1873
- this.classList.toggle(s, e);
1874
- }
1875
- // 预加载路由的具体实现
1876
- prefetchRoute() {
1877
- if (this._prefetched || !this.hasAttribute("prefetch")) return;
1878
- const t = wt();
1879
- t && typeof t.prefetch == "function" && (t.prefetch(this.$data.to), this._prefetched = !0);
1880
- }
1881
- };
1882
- Rt = nn([
1883
- Jt({
1884
- tagName: "router-link",
1885
- // template 中 slot 包裹 label 作为 fallback:
1886
- // 如果有子节点,显示子节点;如果没有,显示 label 属性的内容。
1887
- template: `
1888
- <a part="link" :href="$data.href" :class="{active: $data.isActive}">
1889
- <slot>{{$data.label || ''}}</slot>
1890
- </a>
1891
- `,
1892
- styles: `
1893
- :host {
1894
- }
1895
-
1896
- a {
1897
- text-decoration: none;
1898
- color: inherit;
1899
- cursor: pointer;
1900
- }
1901
-
1902
- /* 内部 <a> 标签的默认高亮 */
1903
- a.active {
1904
- font-weight: 600;
1905
- }
1906
-
1907
- /* custom 模式:消除包裹 a 标签的视觉/布局影响,由 slot 内部元素接管 */
1908
- :host([custom]) a {
1909
- display: contents;
1910
- }
1911
- `,
1912
- shadowDOM: { use: !0, mode: "open" },
1913
- // 注册所有支持的 props
1914
- props: ["to", "active", "exact", "label", "custom", "activeClass", "prefetch"]
1915
- })
1916
- ], Rt);
1917
- const hn = Rt;
1918
- export {
1919
- w as ASTType,
1920
- ht as BaseElement,
1921
- Jt as CustomElement,
1922
- Ye as IRRenderer,
1923
- _ as IS_DEV,
1924
- on as IS_PROD,
1925
- we as LIFECYCLE_ATTRS_MAP,
1926
- Xe as Router,
1927
- hn as RouterLink,
1928
- un as RouterView,
1929
- Ae as buildIR,
1930
- cn as clearIRCache,
1931
- ce as createFunction,
1932
- Ze as createRender,
1933
- ln as createRouter,
1934
- ye as genFunction,
1935
- wt as getRouter,
1936
- ve as isLifecycleKind,
1937
- j as isObject,
1938
- We as isProxy,
1939
- be as listeners,
1940
- Ee as mapAttrKeyToLifecycleKind,
1941
- Ve as observe,
1942
- an as parseHashUrl,
1943
- Ne as parseHtml,
1944
- Qt as routerReady,
1945
- ae as showTemplateError,
1946
- Te as toRaw,
1947
- Ce as transformModel
1948
- };
1
+ import{Router as r,createRouter as e,getRouter as o,routerReady as t}from"./router/core.js";import{default as s}from"./router/router-view.js";import{default as m}from"./router/router-link.js";import{showTemplateError as i}from"./shared/templateError.js";import{genFunction as p}from"./shared/gen-function.js";import{createFunction as a}from"./shared/functions.js";import{default as f}from"./shared/event-listeners.js";import{isObject as n}from"./shared/is-object.js";import{parseHashUrl as j}from"./shared/url.js";import{IS_DEV as u,IS_PROD as l}from"./shared/env.js";import{ASTType as d}from"./types/ast.js";import{LIFECYCLE_ATTRS_MAP as c,isLifecycleKind as h,mapAttrKeyToLifecycleKind as v}from"./types/lifecycle.js";import{default as b}from"./runtime/component/base-element.js";import{buildIR as y,clearIRCache as R,transformModel as k}from"./compiler/ir/buildIR.js";import{parseHtml as w}from"./compiler/parser/parser.js";import{isProxy as E,observe as I,toRaw as g}from"./runtime/reactivity/observe.js";import{CustomElement as x}from"./runtime/component/decorators.js";import{IRRenderer as B,createRender as L}from"./runtime/renderer/renderIR.js";export{d as ASTType,b as BaseElement,x as CustomElement,B as IRRenderer,u as IS_DEV,l as IS_PROD,c as LIFECYCLE_ATTRS_MAP,r as Router,m as RouterLink,s as RouterView,y as buildIR,R as clearIRCache,a as createFunction,L as createRender,e as createRouter,p as genFunction,o as getRouter,h as isLifecycleKind,n as isObject,E as isProxy,f as listeners,v as mapAttrKeyToLifecycleKind,I as observe,j as parseHashUrl,w as parseHtml,t as routerReady,i as showTemplateError,g as toRaw,k as transformModel};