solely 0.0.29 → 0.1.0

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