solely 0.0.30 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +817 -507
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/ir/buildIR.d.ts +12 -0
- package/dist/compiler/ir/index.d.ts +1 -0
- package/dist/compiler/parser/index.d.ts +1 -0
- package/dist/compiler/parser/parser.d.ts +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1768 -0
- package/dist/index.umd.cjs +46 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugins/html-parse-precompile.d.ts +1 -0
- package/dist/plugins/html-precompile.d.ts +1 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/runtime/component/base-element.d.ts +24 -0
- package/dist/{base → runtime/component}/decorators.d.ts +6 -4
- package/dist/runtime/component/index.d.ts +2 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/reactivity/index.d.ts +2 -0
- package/dist/runtime/reactivity/observe.d.ts +47 -0
- package/dist/{utils/observe.d.ts → runtime/reactivity/types.d.ts} +0 -8
- package/dist/runtime/renderer/index.d.ts +1 -0
- package/dist/runtime/renderer/renderIR.d.ts +25 -0
- package/dist/runtime/router/core.d.ts +43 -0
- package/dist/runtime/router/index.d.ts +6 -0
- package/dist/runtime/router/router-link.d.ts +19 -0
- package/dist/runtime/router/router-view.d.ts +25 -0
- package/dist/runtime/router/types.d.ts +65 -0
- package/dist/shared/event-listeners.d.ts +2 -0
- package/dist/shared/gen-function.d.ts +3 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/templateError.d.ts +9 -0
- package/dist/types/ast.d.ts +38 -0
- package/dist/types/component.d.ts +66 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/ir.d.ts +67 -0
- package/dist/types/lifecycle.d.ts +4 -0
- package/dist/types/loop.d.ts +4 -0
- package/package.json +24 -6
- package/dist/base/base-element.d.ts +0 -56
- package/dist/base/index.d.ts +0 -5
- package/dist/base/router-view.d.ts +0 -43
- package/dist/solely.d.ts +0 -2
- package/dist/solely.js +0 -941
- package/dist/solely.umd.cjs +0 -3
- package/dist/utils/ast-processor.d.ts +0 -2
- package/dist/utils/async-queue.d.ts +0 -1
- package/dist/utils/event-listeners.d.ts +0 -2
- package/dist/utils/html-parse.d.ts +0 -45
- package/dist/utils/index.d.ts +0 -8
- /package/dist/{utils → shared}/functions.d.ts +0 -0
- /package/dist/{utils → shared}/is-object.d.ts +0 -0
- /package/dist/{utils → shared}/url.d.ts +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1768 @@
|
|
|
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), vt = (n, t, e) => t.has(n) || Nt("Cannot " + e);
|
|
7
|
+
var k = (n, t, e) => (vt(n, t, "read from private field"), e ? e.call(n) : t.get(n)), O = (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 = (n, t, e, s) => (vt(n, t, "write to private field"), s ? s.call(n, e) : t.set(n, e), e), _ = (n, t, e) => (vt(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
|
+
}, T = 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 _t(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:${T.badgeFg};background:${T.badgeBg};padding:4px 10px;border-radius:6px;font-weight:bold;`,
|
|
39
|
+
`color:${T.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:${T.gutter};`, R = `color:${T.arrow};font-weight:bold;`, f = `color:${T.gutter};`, w = `color:${T.errorLineFg};background:${T.errorLineBg};padding:0 4px;`, E = `color:${T.gutter};`, y = `color:${T.arrow};font-weight:bold;padding:0 4px;`;
|
|
56
|
+
console.groupCollapsed(
|
|
57
|
+
`${i} %c(Line:${a}, Col:${l})`,
|
|
58
|
+
...o,
|
|
59
|
+
`color:${T.gutter};font-weight:normal;`
|
|
60
|
+
);
|
|
61
|
+
for (let x = p; x <= v; x++) {
|
|
62
|
+
const M = u[x], P = String(x + 1).padStart(m, " ");
|
|
63
|
+
if (!(x === h)) {
|
|
64
|
+
console.log(`%c${P} │%c ${M}`, S, f);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const F = M.slice(0, Math.max(0, l - 1)), D = lt(F), at = " ".repeat(m + 3), Zt = P.padEnd(m, " ");
|
|
68
|
+
if (console.log(`%c${Zt} │%c ${M}`, R, w), $)
|
|
69
|
+
for (let B = 0; B < C.length; B++) {
|
|
70
|
+
const bt = C[B], et = h + B;
|
|
71
|
+
let wt = 0;
|
|
72
|
+
if (B === 0)
|
|
73
|
+
wt = D;
|
|
74
|
+
else if (et < u.length) {
|
|
75
|
+
const nt = u[et], ct = nt.search(/\S/), Qt = ct === -1 ? nt : nt.slice(0, ct);
|
|
76
|
+
wt = lt(Qt);
|
|
77
|
+
}
|
|
78
|
+
const Jt = Math.max(1, lt(bt)), Pt = _t(Jt, !0), Ot = at + " ".repeat(wt);
|
|
79
|
+
if (B === 0)
|
|
80
|
+
console.log(`%c${Ot}%c${Pt}`, E, y);
|
|
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${Ot}%c${Pt}`, E, y);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const B = at + " ".repeat(D), bt = _t(b || 1, !1);
|
|
88
|
+
console.log(`%c${B}%c${bt}`, E, y);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
d && console.log(
|
|
92
|
+
`%cExpression:%c ${d}`,
|
|
93
|
+
`color:${T.exprLabel};font-weight:bold;`,
|
|
94
|
+
`color:${T.exprCode};font-family:monospace;`
|
|
95
|
+
), console.groupEnd();
|
|
96
|
+
}
|
|
97
|
+
const Et = {};
|
|
98
|
+
function se(n) {
|
|
99
|
+
const t = n.map((e) => e.replace(/[',"]/g, "")).join(",");
|
|
100
|
+
if (!Et[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
|
+
Et[t] = new Function(...n);
|
|
107
|
+
}
|
|
108
|
+
return Et[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
|
+
]), Y = (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 g = /* @__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))(g || {});
|
|
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 $t = Symbol.for("solely.irMeta"), tt = process.env.NODE_ENV !== "production", me = /\{\{.*?\}\}/;
|
|
261
|
+
class ge {
|
|
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 ye(), 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 jt = new ge();
|
|
280
|
+
class ye {
|
|
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 St(n, t, e) {
|
|
323
|
+
tt && (n[$t] = { 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
|
+
St(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 === g.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 === g.For && (r = !0)), s.dynamic = r ? 1 : 0, n.type) {
|
|
392
|
+
case g.Text: {
|
|
393
|
+
const h = n.content ?? "";
|
|
394
|
+
r ? (s.fid = e.compile("template", h, t), St(s, h, n.loc)) : s.txt = h;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
case g.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 g.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", St(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 g.If:
|
|
411
|
+
case g.ElseIf:
|
|
412
|
+
case g.Else: {
|
|
413
|
+
tt && console.warn(`[IR] Orphaned conditional node found: ${g[n.type]}`), s.attrs = ft(n, t, e), n.children && (s.children = st(n.children, t, e));
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
case g.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 === g.If) {
|
|
430
|
+
const c = [];
|
|
431
|
+
let a = r;
|
|
432
|
+
for (; a < n.length; ) {
|
|
433
|
+
const l = n[a], u = l.type;
|
|
434
|
+
if (u !== g.If && u !== g.ElseIf && u !== g.Else)
|
|
435
|
+
break;
|
|
436
|
+
let h = null, p = "";
|
|
437
|
+
if (u !== g.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
|
+
[$t]: tt ? { expr: p, loc: l.loc } : void 0
|
|
449
|
+
}), a++, u === g.Else) break;
|
|
450
|
+
}
|
|
451
|
+
s.push({
|
|
452
|
+
type: g.Conditional,
|
|
453
|
+
dynamic: 1,
|
|
454
|
+
branches: c,
|
|
455
|
+
...tt && { [$t]: { 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 = jt.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
|
+
jt.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: g.For,
|
|
549
|
+
if: g.If,
|
|
550
|
+
elseif: g.ElseIf,
|
|
551
|
+
else: g.Else
|
|
552
|
+
}[e] ?? g.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: g.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: g.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: g.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: g.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: g.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: g.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: g.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: g.Text,
|
|
706
|
+
tag: "text",
|
|
707
|
+
content: f,
|
|
708
|
+
loc: a(u + 1),
|
|
709
|
+
children: []
|
|
710
|
+
}), i = o;
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
!$ && m.type !== g.Text && m.type !== g.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 kt = (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 (!kt(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) || !kt(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 y = E.replace(/\./g, "\\.").replace(/\*\*/g, "(.+)").replace(/\*/g, "[^.]+").replace(/\[\d+\]/g, "\\[\\d+\\]");
|
|
755
|
+
return new RegExp(`^${y}$`).test(w);
|
|
756
|
+
});
|
|
757
|
+
}, C = (f) => {
|
|
758
|
+
const w = [];
|
|
759
|
+
let E = f;
|
|
760
|
+
for (; E; ) {
|
|
761
|
+
const y = p.get(E);
|
|
762
|
+
if (!y || y.key == null) break;
|
|
763
|
+
w.unshift(y.key), E = y.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 y = { ...w, path: E };
|
|
771
|
+
s > 0 ? (l.push(y), a || (a = setTimeout(() => {
|
|
772
|
+
const I = [...l];
|
|
773
|
+
l = [], a = null, c && (r == null || r(I), I.forEach(t));
|
|
774
|
+
}, s))) : (r == null || r([y]), t(y));
|
|
775
|
+
}, $ = (f, w) => {
|
|
776
|
+
const E = {};
|
|
777
|
+
return ["push", "pop", "shift", "unshift", "splice"].forEach((y) => {
|
|
778
|
+
E[y] = function(...I) {
|
|
779
|
+
u++;
|
|
780
|
+
const x = f[y].apply(f, I);
|
|
781
|
+
if (u--, y === "push")
|
|
782
|
+
b(w, { type: "array-push", index: f.length - I.length, values: I });
|
|
783
|
+
else if (y === "unshift")
|
|
784
|
+
b(w, { type: "array-push", index: 0, values: I });
|
|
785
|
+
else if (y === "pop")
|
|
786
|
+
b(w, { type: "array-splice", index: f.length, deleteCount: 1, insert: [] });
|
|
787
|
+
else if (y === "shift")
|
|
788
|
+
b(w, { type: "array-splice", index: 0, deleteCount: 1, insert: [] });
|
|
789
|
+
else if (y === "splice") {
|
|
790
|
+
const [M, P, ...W] = I;
|
|
791
|
+
b(w, { type: "array-splice", index: M, deleteCount: P, insert: W });
|
|
792
|
+
}
|
|
793
|
+
return x;
|
|
794
|
+
};
|
|
795
|
+
}), ["sort", "reverse", "fill", "copyWithin"].forEach((y) => {
|
|
796
|
+
E[y] = function(...I) {
|
|
797
|
+
u++;
|
|
798
|
+
const x = f[y].apply(f, I);
|
|
799
|
+
return u--, b(w, { type: "array-reset", method: y }), x;
|
|
800
|
+
};
|
|
801
|
+
}), ["indexOf", "lastIndexOf", "includes"].forEach((y) => {
|
|
802
|
+
E[y] = function(I, ...x) {
|
|
803
|
+
let M = f[y].apply(f, [I, ...x]);
|
|
804
|
+
return (M === -1 || M === !1) && Ae(I) && (M = f[y].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 y = h.get(f);
|
|
811
|
+
if (y)
|
|
812
|
+
return p.set(y, { parent: w, key: E }), y;
|
|
813
|
+
const I = {
|
|
814
|
+
get(M, P, W) {
|
|
815
|
+
if (P === pt) return M;
|
|
816
|
+
if (Array.isArray(M)) {
|
|
817
|
+
const D = v.get(x);
|
|
818
|
+
if (D && Object.prototype.hasOwnProperty.call(D, P))
|
|
819
|
+
return Reflect.get(D, P, W);
|
|
820
|
+
}
|
|
821
|
+
const F = Reflect.get(M, P, W);
|
|
822
|
+
return typeof P == "symbol" ? F : Y(F) ? S(F, x, P) : F;
|
|
823
|
+
},
|
|
824
|
+
set(M, P, W, F) {
|
|
825
|
+
const D = M[P];
|
|
826
|
+
if (o ? kt(D, W) : D === W) return !0;
|
|
827
|
+
const at = Reflect.set(M, P, W, F);
|
|
828
|
+
return u === 0 && (Array.isArray(D) && Array.isArray(W) ? b(x, { type: "array-replace", oldValue: D, newValue: W }) : b(x, { type: "set", key: P, newValue: W, oldValue: D })), at;
|
|
829
|
+
},
|
|
830
|
+
deleteProperty(M, P) {
|
|
831
|
+
if (!Reflect.has(M, P)) return !1;
|
|
832
|
+
const W = M[P], F = Reflect.deleteProperty(M, P);
|
|
833
|
+
return F && u === 0 && b(x, { type: "delete", key: P, oldValue: W }), F;
|
|
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, y = /* @__PURE__ */ new WeakSet()) => {
|
|
840
|
+
!Y(w) || y.has(w) || (y.add(w), Reflect.ownKeys(w).forEach((I) => {
|
|
841
|
+
const x = w[I];
|
|
842
|
+
b(E, { type: "set", key: I, newValue: x, oldValue: void 0 }), Y(x) && f(x, S(x, E, I), y);
|
|
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, G, Q, X, K, it, ot, z, A, Ct, qt, Rt, Lt, dt, Gt, Kt, At, Mt;
|
|
859
|
+
const j = class j extends HTMLElement {
|
|
860
|
+
/* -------------------- 构造 -------------------- */
|
|
861
|
+
constructor(e = {}) {
|
|
862
|
+
var r;
|
|
863
|
+
super();
|
|
864
|
+
O(this, A);
|
|
865
|
+
O(this, q);
|
|
866
|
+
O(this, H);
|
|
867
|
+
O(this, Z);
|
|
868
|
+
O(this, rt);
|
|
869
|
+
O(this, J);
|
|
870
|
+
O(this, G);
|
|
871
|
+
O(this, Q, !1);
|
|
872
|
+
O(this, X, !1);
|
|
873
|
+
O(this, K, !1);
|
|
874
|
+
O(this, it, !1);
|
|
875
|
+
N(this, q, this.constructor[Wt] || {});
|
|
876
|
+
const s = k(this, q);
|
|
877
|
+
N(this, J, (r = s.shadowDOM) != null && r.use ? this.attachShadow({ mode: s.shadowDOM.mode || "open" }) : this), _(this, A, Ct).call(this, e), _(this, A, qt).call(this, s), queueMicrotask(() => _(this, A, At).call(this));
|
|
878
|
+
}
|
|
879
|
+
static get observedAttributes() {
|
|
880
|
+
if (k(j, z).has(this))
|
|
881
|
+
return k(j, z).get(this);
|
|
882
|
+
const e = this[Wt];
|
|
883
|
+
if (!(e != null && e.props))
|
|
884
|
+
return k(j, z).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(j, z).set(this, s), s;
|
|
887
|
+
}
|
|
888
|
+
/* -------------------- $data -------------------- */
|
|
889
|
+
get $data() {
|
|
890
|
+
return k(this, rt);
|
|
891
|
+
}
|
|
892
|
+
set $data(e) {
|
|
893
|
+
var s;
|
|
894
|
+
Y(e) || (e = {}), (s = k(this, G)) == null || s.call(this), _(this, A, Ct).call(this, e), _(this, A, dt).call(this);
|
|
895
|
+
}
|
|
896
|
+
refresh() {
|
|
897
|
+
_(this, A, dt).call(this);
|
|
898
|
+
}
|
|
899
|
+
/* -------------------- 生命周期 -------------------- */
|
|
900
|
+
connectedCallback() {
|
|
901
|
+
var r;
|
|
902
|
+
_(this, A, At).call(this);
|
|
903
|
+
const e = k(this, q);
|
|
904
|
+
if ((e.className || e.tagName || "").split(" ").forEach((i) => i && this.classList.add(i)), _(this, A, Kt).call(this), e.props && Y(this.$data))
|
|
905
|
+
for (const i of e.props) {
|
|
906
|
+
const o = typeof i == "string" ? i : i.name, c = _(this, A, Rt).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 = _(this, A, Lt).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) && N(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, G)) == null || e.call(this), N(this, G, void 0);
|
|
924
|
+
}
|
|
925
|
+
attributeChangedCallback(e, s, r) {
|
|
926
|
+
if (s === r || !Y(this.$data)) return;
|
|
927
|
+
const i = _(this, A, Rt).call(this, e), o = e.replace(/-([a-z])/g, (l, u) => u.toUpperCase()), c = this.$data[o], a = _(this, A, Lt).call(this, r, (i == null ? void 0 : i.default) ?? c, i == null ? void 0 : i.type);
|
|
928
|
+
this.$data[o] = a, N(this, K, !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(), G = new WeakMap(), Q = new WeakMap(), X = new WeakMap(), K = new WeakMap(), it = new WeakMap(), ot = new WeakMap(), z = new WeakMap(), A = new WeakSet(), /* -------------------- 初始化 -------------------- */
|
|
967
|
+
Ct = function(e) {
|
|
968
|
+
const { proxy: s, unobserve: r } = Ie(e, (i) => {
|
|
969
|
+
this.emit("change", {
|
|
970
|
+
source: "state",
|
|
971
|
+
...i
|
|
972
|
+
}), _(this, A, dt).call(this);
|
|
973
|
+
});
|
|
974
|
+
N(this, rt, s), N(this, G, r);
|
|
975
|
+
}, qt = function(e) {
|
|
976
|
+
const s = e.template;
|
|
977
|
+
if (typeof s == "string") {
|
|
978
|
+
const r = Le(s);
|
|
979
|
+
N(this, Z, Ee(r, {
|
|
980
|
+
source: s,
|
|
981
|
+
filename: e.tagName
|
|
982
|
+
}));
|
|
983
|
+
}
|
|
984
|
+
}, /* -------------------- Prop 工具 -------------------- */
|
|
985
|
+
Rt = 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
|
+
}, Lt = 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) || (N(this, X, !0), queueMicrotask(() => {
|
|
1014
|
+
N(this, X, !1), _(this, A, Gt).call(this);
|
|
1015
|
+
}));
|
|
1016
|
+
}, Gt = function() {
|
|
1017
|
+
k(this, Q) || !this.isConnected || (N(this, Q, !0), k(this, K) && this.beforeAttributesUpdate(), this.beforeUpdate(), k(this, H).update(), this.updated(), k(this, K) && (this.afterAttributesUpdate(), N(this, K, !1)), N(this, Q, !1));
|
|
1018
|
+
}, Kt = 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(j, ot).get(s);
|
|
1025
|
+
o || (o = new CSSStyleSheet(), o.replaceSync(s), k(j, 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
|
+
At = function() {
|
|
1036
|
+
k(this, it) || (N(this, it, !0), this.created());
|
|
1037
|
+
}, Mt = new WeakMap(), O(j, ot, /* @__PURE__ */ new Map()), /* -------------------- observedAttributes -------------------- */
|
|
1038
|
+
O(j, z, /* @__PURE__ */ new WeakMap()), /* -------------------- DEV define 保护 -------------------- */
|
|
1039
|
+
O(j, Mt, !1);
|
|
1040
|
+
let mt = j;
|
|
1041
|
+
const Me = Symbol.for("solely.manifest"), zt = (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
|
+
}, gt = Symbol("solely.isSVG"), ut = Symbol("solely.irCtx"), ht = Symbol("solely.irEvents"), V = Symbol.for("solely.irMeta"), Tt = Symbol("solely.lastDynamicClass"), Dt = Symbol("solely.dynamicStyleLast"), Pe = {
|
|
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
|
+
}, Oe = {
|
|
1052
|
+
readonly: "readOnly",
|
|
1053
|
+
for: "htmlFor",
|
|
1054
|
+
tabindex: "tabIndex",
|
|
1055
|
+
contenteditable: "contentEditable",
|
|
1056
|
+
maxlength: "maxLength"
|
|
1057
|
+
}, Ne = /* @__PURE__ */ new Set(["data-", "aria-", "role", "form"]), _e = /* @__PURE__ */ new Set([
|
|
1058
|
+
"value",
|
|
1059
|
+
"selectedIndex"
|
|
1060
|
+
]);
|
|
1061
|
+
function We(n, t) {
|
|
1062
|
+
var i;
|
|
1063
|
+
const e = n, s = (i = t.attrs) == null ? void 0 : i.find((o) => o.key === "class" && !o.dynamic), r = s ? s.value : "";
|
|
1064
|
+
r && (e[gt] ? e.className.baseVal = r : e.className = r);
|
|
1065
|
+
}
|
|
1066
|
+
function Te(n, t) {
|
|
1067
|
+
var r;
|
|
1068
|
+
const e = (r = t.attrs) == null ? void 0 : r.find((i) => i.key === "style" && !i.dynamic), s = e ? Ut(e.value) : {};
|
|
1069
|
+
for (const i in s) {
|
|
1070
|
+
const o = s[i];
|
|
1071
|
+
i.startsWith("--") ? n.style.setProperty(i, o) : n.style[i] = o;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
const De = (n, t) => {
|
|
1075
|
+
const e = n, s = Ut(t), r = e[Dt] || {};
|
|
1076
|
+
for (const i in r)
|
|
1077
|
+
i in s || (i.startsWith("--") ? n.style.removeProperty(i) : n.style[i] = "");
|
|
1078
|
+
for (const i in s) {
|
|
1079
|
+
const o = s[i];
|
|
1080
|
+
i.startsWith("--") ? n.style.setProperty(i, o) : n.style[i] = o;
|
|
1081
|
+
}
|
|
1082
|
+
e[Dt] = s;
|
|
1083
|
+
}, Fe = (n, t) => {
|
|
1084
|
+
const e = n, s = e[Tt] || {}, r = je(t);
|
|
1085
|
+
for (const i in s)
|
|
1086
|
+
s[i] && !r[i] && (e[gt] ? e.className.baseVal = e.className.baseVal.replace(new RegExp(`\\b${i}\\b`, "g"), "").trim() : e.classList.remove(i));
|
|
1087
|
+
for (const i in r)
|
|
1088
|
+
if (r[i])
|
|
1089
|
+
if (e[gt]) {
|
|
1090
|
+
const o = e.className.baseVal.split(/\s+/);
|
|
1091
|
+
o.includes(i) || (o.push(i), e.className.baseVal = o.join(" "));
|
|
1092
|
+
} else
|
|
1093
|
+
e.classList.add(i);
|
|
1094
|
+
e[Tt] = r;
|
|
1095
|
+
};
|
|
1096
|
+
function Ut(n) {
|
|
1097
|
+
const t = {}, e = [[n]];
|
|
1098
|
+
for (; e.length; ) {
|
|
1099
|
+
const [s, r] = e.pop();
|
|
1100
|
+
if (typeof s == "string") {
|
|
1101
|
+
s.split(";").forEach((i) => {
|
|
1102
|
+
const [o, c] = i.split(":").map((a) => a.trim());
|
|
1103
|
+
o && c && (t[o] = c);
|
|
1104
|
+
});
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
if (Array.isArray(s)) {
|
|
1108
|
+
s.forEach((i) => e.push([i]));
|
|
1109
|
+
continue;
|
|
1110
|
+
}
|
|
1111
|
+
if (s && typeof s == "object")
|
|
1112
|
+
for (const [i, o] of Object.entries(s)) {
|
|
1113
|
+
const c = r ? `${r}-${i}` : i;
|
|
1114
|
+
o && typeof o == "object" && !Array.isArray(o) ? e.push([o, c]) : t[c] = String(o ?? "");
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return t;
|
|
1118
|
+
}
|
|
1119
|
+
function je(n) {
|
|
1120
|
+
const t = {}, e = [n];
|
|
1121
|
+
for (; e.length; ) {
|
|
1122
|
+
const s = e.pop();
|
|
1123
|
+
if (s) {
|
|
1124
|
+
if (typeof s == "string")
|
|
1125
|
+
s.split(/\s+/).forEach((r) => r && (t[r] = !0));
|
|
1126
|
+
else if (Array.isArray(s))
|
|
1127
|
+
e.push(...s);
|
|
1128
|
+
else if (typeof s == "object")
|
|
1129
|
+
for (const [r, i] of Object.entries(s))
|
|
1130
|
+
t[r] = !!i;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return t;
|
|
1134
|
+
}
|
|
1135
|
+
function Ve(n, t, e) {
|
|
1136
|
+
const s = t.indexOf(":");
|
|
1137
|
+
if (s > 0) {
|
|
1138
|
+
const r = t.slice(0, s), i = Pe[r];
|
|
1139
|
+
if (i) return n.setAttributeNS(i, t, e);
|
|
1140
|
+
}
|
|
1141
|
+
n.setAttribute(t, e);
|
|
1142
|
+
}
|
|
1143
|
+
function Ft(n, t, e) {
|
|
1144
|
+
if (t.startsWith("data-") || t.startsWith("aria-") || Ne.has(t)) {
|
|
1145
|
+
n.setAttribute(t, e);
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
const s = Oe[t] || t;
|
|
1149
|
+
n[s] = e;
|
|
1150
|
+
}
|
|
1151
|
+
class Be {
|
|
1152
|
+
constructor(t, e, s = {}) {
|
|
1153
|
+
L(this, "nodeMap", /* @__PURE__ */ new Map());
|
|
1154
|
+
L(this, "marker", !1);
|
|
1155
|
+
this.ir = t, this.container = e, this.scope = s;
|
|
1156
|
+
}
|
|
1157
|
+
evalIR(t, e, s) {
|
|
1158
|
+
var i;
|
|
1159
|
+
const r = this.ir.functions[t - 1];
|
|
1160
|
+
try {
|
|
1161
|
+
return r ? r.apply(this.scope, e) : "";
|
|
1162
|
+
} catch (o) {
|
|
1163
|
+
return ne(o.message || o.toString(), ((i = this.ir.metadata) == null ? void 0 : i.source) || "", s, this.scope.tagName), "";
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
// ================ 创建节点 ================
|
|
1167
|
+
createElement(t, e) {
|
|
1168
|
+
const s = t.tag, r = e instanceof SVGElement || s === "svg", i = r ? document.createElementNS("http://www.w3.org/2000/svg", s) : document.createElement(s);
|
|
1169
|
+
return i[gt] = r, i;
|
|
1170
|
+
}
|
|
1171
|
+
createText(t, e) {
|
|
1172
|
+
const s = t.dynamic ? this.evalIR(t.fid, [e], t[V]) : t.txt || "";
|
|
1173
|
+
return document.createTextNode(s);
|
|
1174
|
+
}
|
|
1175
|
+
createComment(t, e) {
|
|
1176
|
+
const s = t.dynamic ? this.evalIR(t.fid, [e], t[V]) : t.txt || "";
|
|
1177
|
+
return document.createComment(s);
|
|
1178
|
+
}
|
|
1179
|
+
// ================ 属性全量应用(创建或更新时用) ================
|
|
1180
|
+
applyAttrs(t, e, s, r = !1) {
|
|
1181
|
+
const i = [], o = t;
|
|
1182
|
+
o[ut] || (o[ut] = {
|
|
1183
|
+
loops: null
|
|
1184
|
+
}), o[ut].loops = s, o[ht] || (o[ht] = /* @__PURE__ */ Object.create(null));
|
|
1185
|
+
let c, a = !1, l, u = !1;
|
|
1186
|
+
for (const h of e) {
|
|
1187
|
+
const { key: p, fid: v, dynamic: m, value: d } = h;
|
|
1188
|
+
if (p === ":class") {
|
|
1189
|
+
c = this.evalIR(v, [s]), a = !0;
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1192
|
+
if (p === ":style") {
|
|
1193
|
+
l = this.evalIR(v, [s]), u = !0;
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
if (p === "class" || p === "style")
|
|
1197
|
+
continue;
|
|
1198
|
+
const C = p[0];
|
|
1199
|
+
if (C === "@") {
|
|
1200
|
+
const $ = p.slice(1), S = h.role ?? "user";
|
|
1201
|
+
let R = o[ht][$];
|
|
1202
|
+
if (R || (R = o[ht][$] = {
|
|
1203
|
+
model: [],
|
|
1204
|
+
user: []
|
|
1205
|
+
}, t.addEventListener($, (f) => {
|
|
1206
|
+
for (const w of R.model)
|
|
1207
|
+
w(f);
|
|
1208
|
+
for (const w of R.user)
|
|
1209
|
+
w(f);
|
|
1210
|
+
})), !r) {
|
|
1211
|
+
const f = (w) => this.evalIR(
|
|
1212
|
+
v,
|
|
1213
|
+
[w, o[ut].loops],
|
|
1214
|
+
h[V]
|
|
1215
|
+
);
|
|
1216
|
+
R[S].push(f);
|
|
1217
|
+
}
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
if (p === "mounted") {
|
|
1221
|
+
r || requestAnimationFrame(
|
|
1222
|
+
() => this.evalIR(v, [t, s], h[V])
|
|
1223
|
+
);
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
if (p === "updated") {
|
|
1227
|
+
r && requestAnimationFrame(
|
|
1228
|
+
() => this.evalIR(v, [t, s], h[V])
|
|
1229
|
+
);
|
|
1230
|
+
continue;
|
|
1231
|
+
}
|
|
1232
|
+
if (p === "ref" && d) {
|
|
1233
|
+
this.scope.$refs = this.scope.$refs || {}, this.scope.$refs[d] = t;
|
|
1234
|
+
continue;
|
|
1235
|
+
}
|
|
1236
|
+
const b = m ? this.evalIR(v, [s], h[V]) : d ?? "";
|
|
1237
|
+
if (C === ":") {
|
|
1238
|
+
const $ = p.slice(1);
|
|
1239
|
+
t.tagName === "SELECT" && _e.has($) ? i.push(() => Ft(t, $, b)) : Ft(t, $, b);
|
|
1240
|
+
} else
|
|
1241
|
+
Ve(t, p, String(b));
|
|
1242
|
+
}
|
|
1243
|
+
return (a || !r) && Fe(t, c), (u || !r) && De(t, l), i;
|
|
1244
|
+
}
|
|
1245
|
+
// ================ 更新已有节点 Text Or Comment ================
|
|
1246
|
+
updateNode(t, e, s) {
|
|
1247
|
+
const r = e.dynamic ? this.evalIR(e.fid, [s], e[V]) : e.txt || "";
|
|
1248
|
+
e.dynamic && t.textContent !== r && (t.textContent = r);
|
|
1249
|
+
}
|
|
1250
|
+
// ================ 核心遍历 ================
|
|
1251
|
+
irToNode(t, e, s, r, i) {
|
|
1252
|
+
var l, u, h, p;
|
|
1253
|
+
const o = s + "-" + e, c = this.nodeMap.get(o);
|
|
1254
|
+
let a;
|
|
1255
|
+
if (c) {
|
|
1256
|
+
a = c.node, c.marker = this.marker;
|
|
1257
|
+
let v = [];
|
|
1258
|
+
t.dynamic && (t.type === g.Element ? v = this.applyAttrs(
|
|
1259
|
+
a,
|
|
1260
|
+
t.attrs ?? [],
|
|
1261
|
+
i,
|
|
1262
|
+
!0
|
|
1263
|
+
) : this.updateNode(a, t, i)), (l = t.children) == null || l.forEach((m, d) => {
|
|
1264
|
+
this.irToNode(m, d, o, a, i);
|
|
1265
|
+
}), v.forEach((m) => m());
|
|
1266
|
+
} else
|
|
1267
|
+
switch (t.type) {
|
|
1268
|
+
case g.Element:
|
|
1269
|
+
a = this.createElement(t, r), We(a, t), Te(a, t);
|
|
1270
|
+
const v = this.applyAttrs(a, t.attrs ?? [], i);
|
|
1271
|
+
r.appendChild(a), this.nodeMap.set(o, { irNode: t, node: a, loops: i, marker: this.marker }), (u = t.children) == null || u.forEach((m, d) => {
|
|
1272
|
+
this.irToNode(m, d, o, a, i);
|
|
1273
|
+
}), v.forEach((m) => m());
|
|
1274
|
+
break;
|
|
1275
|
+
case g.Text:
|
|
1276
|
+
a = this.createText(t, i), r.appendChild(a), this.nodeMap.set(o, { irNode: t, node: a, loops: i, marker: this.marker });
|
|
1277
|
+
break;
|
|
1278
|
+
case g.Comment:
|
|
1279
|
+
a = this.createComment(t, i), r.appendChild(a), this.nodeMap.set(o, { irNode: t, node: a, loops: i, marker: this.marker });
|
|
1280
|
+
break;
|
|
1281
|
+
case g.For: {
|
|
1282
|
+
const m = `${o}-end`;
|
|
1283
|
+
let d = (h = this.nodeMap.get(m)) == null ? void 0 : h.node;
|
|
1284
|
+
d ? this.nodeMap.get(m).marker = this.marker : (d = document.createComment(`for:${o}`), r.appendChild(d), this.nodeMap.set(m, {
|
|
1285
|
+
irNode: { type: g.Comment },
|
|
1286
|
+
node: d,
|
|
1287
|
+
loops: i,
|
|
1288
|
+
marker: this.marker
|
|
1289
|
+
}));
|
|
1290
|
+
const C = this.evalIR(t.fid, [i], t[V]) || [], b = document.createDocumentFragment();
|
|
1291
|
+
C.forEach(($, S) => {
|
|
1292
|
+
var f;
|
|
1293
|
+
const R = [...i, { itmVal: $, idxVal: S }];
|
|
1294
|
+
(f = t.children) == null || f.forEach((w, E) => {
|
|
1295
|
+
this.irToNode(w, E, `${o}-for-${S}`, b, R);
|
|
1296
|
+
});
|
|
1297
|
+
}), d.parentNode.insertBefore(b, d);
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
case g.Conditional: {
|
|
1301
|
+
const m = `${o}-end`;
|
|
1302
|
+
let d = (p = this.nodeMap.get(m)) == null ? void 0 : p.node;
|
|
1303
|
+
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 }));
|
|
1304
|
+
for (let C = 0; C < (t.branches || []).length; C++) {
|
|
1305
|
+
const b = t.branches[C];
|
|
1306
|
+
if (b.condFid === null || this.evalIR(b.condFid, [i], b[V])) {
|
|
1307
|
+
const S = document.createDocumentFragment();
|
|
1308
|
+
b.children.forEach((R, f) => {
|
|
1309
|
+
this.irToNode(R, f, `${o}-if-${C}`, S, i);
|
|
1310
|
+
}), d.parentNode.insertBefore(S, d);
|
|
1311
|
+
break;
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
// ================ 清理被删除的节点 ================
|
|
1319
|
+
cleanupOldNodes() {
|
|
1320
|
+
for (const [t, e] of this.nodeMap.entries())
|
|
1321
|
+
if (e.marker !== this.marker) {
|
|
1322
|
+
const { irNode: s, node: r, loops: i } = e;
|
|
1323
|
+
if (s.attrs) {
|
|
1324
|
+
const o = s.attrs.find((a) => a.key === "unmounted");
|
|
1325
|
+
o && requestAnimationFrame(() => {
|
|
1326
|
+
this.evalIR(
|
|
1327
|
+
o.fid,
|
|
1328
|
+
[r, i],
|
|
1329
|
+
o[V]
|
|
1330
|
+
);
|
|
1331
|
+
});
|
|
1332
|
+
const c = s.attrs.find((a) => a.key === "ref");
|
|
1333
|
+
c && c.value && delete this.scope.$refs[c.value];
|
|
1334
|
+
}
|
|
1335
|
+
r == null || r.remove(), this.nodeMap.delete(t);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
// ================ 公共 API ================
|
|
1339
|
+
mount() {
|
|
1340
|
+
this.marker = !this.marker, this.ir.nodes.forEach((t, e) => {
|
|
1341
|
+
this.irToNode(t, e, "root", this.container, []);
|
|
1342
|
+
}), this.cleanupOldNodes();
|
|
1343
|
+
}
|
|
1344
|
+
update() {
|
|
1345
|
+
this.marker = !this.marker, this.ir.nodes.forEach((t, e) => {
|
|
1346
|
+
this.irToNode(t, e, "root", this.container, []);
|
|
1347
|
+
}), this.cleanupOldNodes();
|
|
1348
|
+
}
|
|
1349
|
+
destroy() {
|
|
1350
|
+
this.container.innerHTML = "", this.nodeMap.clear();
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
const qe = (n, t, e = {}) => {
|
|
1354
|
+
const s = new Be(n, t, e);
|
|
1355
|
+
return s.mount(), {
|
|
1356
|
+
update: () => s.update(),
|
|
1357
|
+
destroy: () => s.destroy()
|
|
1358
|
+
};
|
|
1359
|
+
};
|
|
1360
|
+
let U = null, Yt;
|
|
1361
|
+
const Ht = new Promise((n) => {
|
|
1362
|
+
Yt = n;
|
|
1363
|
+
});
|
|
1364
|
+
function Qe(n) {
|
|
1365
|
+
return U || (U = new Ge(n), Yt(U), U);
|
|
1366
|
+
}
|
|
1367
|
+
function xt() {
|
|
1368
|
+
return U;
|
|
1369
|
+
}
|
|
1370
|
+
class Ge {
|
|
1371
|
+
constructor(t) {
|
|
1372
|
+
L(this, "routes");
|
|
1373
|
+
L(this, "base");
|
|
1374
|
+
L(this, "mode");
|
|
1375
|
+
L(this, "beforeEachGuard");
|
|
1376
|
+
L(this, "afterEachGuard");
|
|
1377
|
+
L(this, "currentRoute", null);
|
|
1378
|
+
L(this, "listeners", /* @__PURE__ */ new Set());
|
|
1379
|
+
L(this, "isStarted", !1);
|
|
1380
|
+
this.routes = t.routes, this.base = t.base ?? "/", this.mode = t.mode || "history", this.beforeEachGuard = t.beforeEach, this.afterEachGuard = t.afterEach;
|
|
1381
|
+
}
|
|
1382
|
+
// --- 核心匹配逻辑 ---
|
|
1383
|
+
matchRoute(t = "/") {
|
|
1384
|
+
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);
|
|
1385
|
+
if (c) {
|
|
1386
|
+
const a = c.matched[c.matched.length - 1];
|
|
1387
|
+
return a.config.redirect ? this.matchRoute(a.config.redirect) : {
|
|
1388
|
+
matched: c.matched,
|
|
1389
|
+
// 这里的结构已经是 [{config, params}, ...]
|
|
1390
|
+
params: c.params,
|
|
1391
|
+
// 全局合并后的 params
|
|
1392
|
+
query: o,
|
|
1393
|
+
fullPath: e,
|
|
1394
|
+
// 合并所有层级的 meta
|
|
1395
|
+
meta: c.matched.reduce((l, u) => ({ ...l, ...u.config.meta || {} }), {})
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1398
|
+
return null;
|
|
1399
|
+
}
|
|
1400
|
+
recursiveMatch(t, e) {
|
|
1401
|
+
const s = [...t].sort((r, i) => this.calculateScore(i.path) - this.calculateScore(r.path));
|
|
1402
|
+
for (const r of s) {
|
|
1403
|
+
const i = r.path.split("/").filter(Boolean), o = {};
|
|
1404
|
+
let c = !0;
|
|
1405
|
+
if (i.length === 0 && e.length === 0)
|
|
1406
|
+
return {
|
|
1407
|
+
matched: [{ config: r, params: {} }],
|
|
1408
|
+
params: {}
|
|
1409
|
+
};
|
|
1410
|
+
for (let a = 0; a < i.length; a++) {
|
|
1411
|
+
const l = i[a], u = e[a];
|
|
1412
|
+
if (l.startsWith(":")) {
|
|
1413
|
+
if (!u) {
|
|
1414
|
+
c = !1;
|
|
1415
|
+
break;
|
|
1416
|
+
}
|
|
1417
|
+
o[l.slice(1)] = u;
|
|
1418
|
+
} else if (l === "*") {
|
|
1419
|
+
c = !0;
|
|
1420
|
+
break;
|
|
1421
|
+
} else if (l !== u) {
|
|
1422
|
+
c = !1;
|
|
1423
|
+
break;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
if (c) {
|
|
1427
|
+
const a = i.length, l = e.slice(a), u = { config: r, params: o };
|
|
1428
|
+
if (l.length > 0 && r.children) {
|
|
1429
|
+
const h = this.recursiveMatch(r.children, l);
|
|
1430
|
+
if (h)
|
|
1431
|
+
return {
|
|
1432
|
+
matched: [u, ...h.matched],
|
|
1433
|
+
params: { ...o, ...h.params }
|
|
1434
|
+
// 全局合并 params
|
|
1435
|
+
};
|
|
1436
|
+
} else if (l.length === 0 || i.includes("*"))
|
|
1437
|
+
return {
|
|
1438
|
+
matched: [u],
|
|
1439
|
+
params: o
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
return null;
|
|
1444
|
+
}
|
|
1445
|
+
calculateScore(t = "/") {
|
|
1446
|
+
const e = t.split("/").filter(Boolean);
|
|
1447
|
+
return e.length === 0 ? 1 : e.reduce((s, r) => r.startsWith(":") ? s + 5 : r === "*" ? s + 0 : s + 10, 0);
|
|
1448
|
+
}
|
|
1449
|
+
parseQuery(t) {
|
|
1450
|
+
const e = {};
|
|
1451
|
+
return t && new URLSearchParams(t).forEach((r, i) => {
|
|
1452
|
+
e[i] = r;
|
|
1453
|
+
}), e;
|
|
1454
|
+
}
|
|
1455
|
+
normalizePath(t = "/") {
|
|
1456
|
+
let e = t && typeof t == "string" ? t : "/";
|
|
1457
|
+
return e.startsWith("/") || (e = "/" + e), e.length > 1 && e.endsWith("/") && (e = e.slice(0, -1)), e;
|
|
1458
|
+
}
|
|
1459
|
+
// --- 导航逻辑 ---
|
|
1460
|
+
getPath() {
|
|
1461
|
+
let t;
|
|
1462
|
+
try {
|
|
1463
|
+
t = this.mode === "hash" ? window.location.hash.slice(1) || "/" : window.location.pathname || "/";
|
|
1464
|
+
} catch {
|
|
1465
|
+
t = "/";
|
|
1466
|
+
}
|
|
1467
|
+
const e = this.base || "/";
|
|
1468
|
+
return e !== "/" && t.startsWith(e) && (t = t.slice(e.length) || "/"), this.normalizePath(t);
|
|
1469
|
+
}
|
|
1470
|
+
updateBrowserHistory(t = "/", e) {
|
|
1471
|
+
const s = this.normalizePath(t), r = this.base || "/";
|
|
1472
|
+
if (this.mode === "hash")
|
|
1473
|
+
e ? window.location.replace(`#${s}`) : window.location.hash = s;
|
|
1474
|
+
else {
|
|
1475
|
+
const i = r.endsWith("/") ? r.slice(0, -1) : r, o = i === "/" ? s : i + s;
|
|
1476
|
+
e ? window.history.replaceState({ path: o }, "", o) : window.history.pushState({ path: o }, "", o);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* @param fromEvent 标志位:是否由浏览器 popstate 事件触发
|
|
1481
|
+
*/
|
|
1482
|
+
async navigate(t = "/", e = !1, s = !1) {
|
|
1483
|
+
const r = this.normalizePath(t), i = this.currentRoute, o = this.matchRoute(r);
|
|
1484
|
+
if (!o) return { success: !1, error: `No route matched: ${r}` };
|
|
1485
|
+
if (i && i.fullPath === o.fullPath) return { success: !0 };
|
|
1486
|
+
if (this.beforeEachGuard)
|
|
1487
|
+
try {
|
|
1488
|
+
const c = await this.beforeEachGuard(o, i);
|
|
1489
|
+
if (c === !1) return { success: !1, cancelled: !0 };
|
|
1490
|
+
if (typeof c == "string") return this.navigate(c, e);
|
|
1491
|
+
} catch (c) {
|
|
1492
|
+
return { success: !1, error: c instanceof Error ? c.message : "Guard Error" };
|
|
1493
|
+
}
|
|
1494
|
+
return this.currentRoute = o, s || this.updateBrowserHistory(r, e), this.notifyListeners(), this.afterEachGuard && this.afterEachGuard(o, i), { success: !0 };
|
|
1495
|
+
}
|
|
1496
|
+
// --- 路径解析逻辑 ---
|
|
1497
|
+
/**
|
|
1498
|
+
* 将逻辑路径解析为浏览器真实的 URL 路径
|
|
1499
|
+
* 供 RouterLink 等组件生成 href 使用
|
|
1500
|
+
*/
|
|
1501
|
+
resolve(t = "/") {
|
|
1502
|
+
const e = this.normalizePath(t);
|
|
1503
|
+
if (this.mode === "hash") return `#${e}`;
|
|
1504
|
+
const s = this.base.endsWith("/") ? this.base.slice(0, -1) : this.base;
|
|
1505
|
+
return s === "/" ? e : s + e;
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* 获取当前模式(供外部组件判断,如 RouterLink)
|
|
1509
|
+
*/
|
|
1510
|
+
get modeType() {
|
|
1511
|
+
return this.mode;
|
|
1512
|
+
}
|
|
1513
|
+
pushWithQuery(t = "/", e) {
|
|
1514
|
+
const s = new URLSearchParams(e).toString(), r = t.includes("?") ? "&" : "?";
|
|
1515
|
+
return this.push(t + (s ? r + s : ""));
|
|
1516
|
+
}
|
|
1517
|
+
push(t = "/") {
|
|
1518
|
+
return this.navigate(t, !1);
|
|
1519
|
+
}
|
|
1520
|
+
replace(t = "/") {
|
|
1521
|
+
return this.navigate(t, !0);
|
|
1522
|
+
}
|
|
1523
|
+
back() {
|
|
1524
|
+
window.history.back();
|
|
1525
|
+
}
|
|
1526
|
+
listen(t) {
|
|
1527
|
+
return this.listeners.add(t), () => this.listeners.delete(t);
|
|
1528
|
+
}
|
|
1529
|
+
notifyListeners() {
|
|
1530
|
+
this.listeners.forEach((t) => t());
|
|
1531
|
+
}
|
|
1532
|
+
setupListeners() {
|
|
1533
|
+
if (this.isStarted) return;
|
|
1534
|
+
const t = () => {
|
|
1535
|
+
this.navigate(this.getPath(), !0, !0);
|
|
1536
|
+
};
|
|
1537
|
+
window.addEventListener("popstate", t), this.mode === "hash" && !window.location.hash && (window.location.hash = "/"), this.navigate(this.getPath(), !0);
|
|
1538
|
+
}
|
|
1539
|
+
getCurrentRoute() {
|
|
1540
|
+
return this.currentRoute;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
var Ke = Object.getOwnPropertyDescriptor, ze = (n, t, e, s) => {
|
|
1544
|
+
for (var r = s > 1 ? void 0 : s ? Ke(t, e) : t, i = n.length - 1, o; i >= 0; i--)
|
|
1545
|
+
(o = n[i]) && (r = o(r) || r);
|
|
1546
|
+
return r;
|
|
1547
|
+
};
|
|
1548
|
+
let yt = class extends mt {
|
|
1549
|
+
constructor() {
|
|
1550
|
+
super(...arguments);
|
|
1551
|
+
L(this, "unsubscribe");
|
|
1552
|
+
L(this, "level", 0);
|
|
1553
|
+
L(this, "currentElement", null);
|
|
1554
|
+
L(this, "currentTagName", null);
|
|
1555
|
+
L(this, "routerAttrs", /* @__PURE__ */ new Set());
|
|
1556
|
+
L(this, "prevPropKeys", /* @__PURE__ */ new Set());
|
|
1557
|
+
L(this, "scheduled", !1);
|
|
1558
|
+
L(this, "cache", /* @__PURE__ */ new Map());
|
|
1559
|
+
L(this, "latestLoadId", 0);
|
|
1560
|
+
}
|
|
1561
|
+
/* -------------------- 生命周期 -------------------- */
|
|
1562
|
+
async mounted() {
|
|
1563
|
+
this.detectLevel();
|
|
1564
|
+
const t = await Ht;
|
|
1565
|
+
this.unsubscribe = t.listen(() => {
|
|
1566
|
+
this.scheduleLoad(t.getCurrentRoute());
|
|
1567
|
+
}), this.loadRoute(t.getCurrentRoute());
|
|
1568
|
+
}
|
|
1569
|
+
unmounted() {
|
|
1570
|
+
var t;
|
|
1571
|
+
(t = this.unsubscribe) == null || t.call(this), this.cache.forEach((e) => e.remove()), this.cache.clear();
|
|
1572
|
+
}
|
|
1573
|
+
/* -------------------- 逻辑核心 -------------------- */
|
|
1574
|
+
scheduleLoad(t) {
|
|
1575
|
+
this.scheduled || (this.scheduled = !0, queueMicrotask(() => {
|
|
1576
|
+
this.scheduled = !1, this.loadRoute(t);
|
|
1577
|
+
}));
|
|
1578
|
+
}
|
|
1579
|
+
detectLevel() {
|
|
1580
|
+
let t = 0, e = this.parentElement;
|
|
1581
|
+
for (; e; )
|
|
1582
|
+
e instanceof yt && t++, e = e.parentElement;
|
|
1583
|
+
this.level = t;
|
|
1584
|
+
}
|
|
1585
|
+
async loadRoute(t) {
|
|
1586
|
+
const e = ++this.latestLoadId, s = t == null ? void 0 : t.matched[this.level];
|
|
1587
|
+
if (!s) {
|
|
1588
|
+
this.handleEmptyRoute();
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
const { config: r } = s;
|
|
1592
|
+
let i = r.tagName;
|
|
1593
|
+
if (!i && typeof r.component == "function") {
|
|
1594
|
+
this.renderLoading();
|
|
1595
|
+
try {
|
|
1596
|
+
const c = await r.component();
|
|
1597
|
+
i = typeof c == "string" ? c : c.tagName;
|
|
1598
|
+
} catch (c) {
|
|
1599
|
+
this.renderError(`Load Error: ${c}`);
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
if (e !== this.latestLoadId) return;
|
|
1604
|
+
if (!i) {
|
|
1605
|
+
this.clear();
|
|
1606
|
+
return;
|
|
1607
|
+
}
|
|
1608
|
+
if (!r.forceReload && this.currentElement && this.currentTagName === i.toLowerCase()) {
|
|
1609
|
+
this.syncState(this.currentElement, t == null ? void 0 : t.params, (t == null ? void 0 : t.query) || {}, r.props);
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
this.clear(r.keepAlive);
|
|
1613
|
+
const o = this.getOrCreateComponent(i, r);
|
|
1614
|
+
this.syncState(o, t == null ? void 0 : t.params, (t == null ? void 0 : t.query) || {}, r.props), this.appendChild(o), this.currentElement = o, this.currentTagName = i.toLowerCase();
|
|
1615
|
+
}
|
|
1616
|
+
getOrCreateComponent(t, e) {
|
|
1617
|
+
const s = t.toLowerCase();
|
|
1618
|
+
if (e.keepAlive && this.cache.has(s))
|
|
1619
|
+
return this.cache.get(s);
|
|
1620
|
+
const r = document.createElement(t);
|
|
1621
|
+
return e.keepAlive && this.cache.set(s, r), r;
|
|
1622
|
+
}
|
|
1623
|
+
syncState(t, e, s, r = {}) {
|
|
1624
|
+
const i = (a) => a.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o = /* @__PURE__ */ new Map();
|
|
1625
|
+
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) => {
|
|
1626
|
+
o.has(a) || (t.removeAttribute(a), this.routerAttrs.delete(a));
|
|
1627
|
+
}), o.forEach((a, l) => {
|
|
1628
|
+
t.getAttribute(l) !== a && t.setAttribute(l, a), this.routerAttrs.add(l);
|
|
1629
|
+
});
|
|
1630
|
+
const c = new Set(Object.keys(r));
|
|
1631
|
+
this.prevPropKeys.forEach((a) => {
|
|
1632
|
+
c.has(a) || (t[a] = void 0);
|
|
1633
|
+
}), Object.entries(r).forEach(([a, l]) => {
|
|
1634
|
+
t[a] !== l && (t[a] = l);
|
|
1635
|
+
}), this.prevPropKeys = c;
|
|
1636
|
+
}
|
|
1637
|
+
handleEmptyRoute() {
|
|
1638
|
+
this.clear(), this.level === 0 && this.renderError("404 Not Found");
|
|
1639
|
+
}
|
|
1640
|
+
renderLoading() {
|
|
1641
|
+
this.innerHTML = '<div style="padding:20px; color:#999;">Loading...</div>';
|
|
1642
|
+
}
|
|
1643
|
+
renderError(t) {
|
|
1644
|
+
this.innerHTML = `<div style="padding:20px; color:#ff4d4f;">${t}</div>`;
|
|
1645
|
+
}
|
|
1646
|
+
clear(t = !1) {
|
|
1647
|
+
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();
|
|
1648
|
+
}
|
|
1649
|
+
};
|
|
1650
|
+
yt = ze([
|
|
1651
|
+
zt({
|
|
1652
|
+
tagName: "router-view"
|
|
1653
|
+
// 注意:删除了 shadowDOM 配置,默认为 false
|
|
1654
|
+
})
|
|
1655
|
+
], yt);
|
|
1656
|
+
const Xe = yt;
|
|
1657
|
+
var Ue = Object.getOwnPropertyDescriptor, Ye = (n, t, e, s) => {
|
|
1658
|
+
for (var r = s > 1 ? void 0 : s ? Ue(t, e) : t, i = n.length - 1, o; i >= 0; i--)
|
|
1659
|
+
(o = n[i]) && (r = o(r) || r);
|
|
1660
|
+
return r;
|
|
1661
|
+
};
|
|
1662
|
+
let It = class extends mt {
|
|
1663
|
+
constructor() {
|
|
1664
|
+
super(...arguments);
|
|
1665
|
+
L(this, "_prefetched", !1);
|
|
1666
|
+
}
|
|
1667
|
+
set to(t) {
|
|
1668
|
+
this.$data.to = t, this.updateState();
|
|
1669
|
+
}
|
|
1670
|
+
get to() {
|
|
1671
|
+
return this.$data.to;
|
|
1672
|
+
}
|
|
1673
|
+
async mounted() {
|
|
1674
|
+
(await Ht).listen(() => this.updateState()), this.updateState(), this.addEventListener("click", (e) => {
|
|
1675
|
+
var r, i;
|
|
1676
|
+
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 = xt()) == null || i.push(this.$data.to));
|
|
1677
|
+
}), this.addEventListener("mouseenter", () => {
|
|
1678
|
+
this.prefetchRoute();
|
|
1679
|
+
}, { once: !0 });
|
|
1680
|
+
}
|
|
1681
|
+
updateState() {
|
|
1682
|
+
const t = xt();
|
|
1683
|
+
if (!t) return;
|
|
1684
|
+
this.$data.href = t.resolve(this.$data.to);
|
|
1685
|
+
let e = !1;
|
|
1686
|
+
if (this.$data.active)
|
|
1687
|
+
e = !0;
|
|
1688
|
+
else {
|
|
1689
|
+
const r = t.getCurrentRoute();
|
|
1690
|
+
if (r) {
|
|
1691
|
+
const i = r.fullPath;
|
|
1692
|
+
this.hasAttribute("exact") ? e = i === this.$data.to : e = i === this.$data.to || i.startsWith(this.$data.to + "/");
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
this.$data.isActive = e;
|
|
1696
|
+
const s = this.$data.activeClass || "active";
|
|
1697
|
+
this.classList.toggle(s, e);
|
|
1698
|
+
}
|
|
1699
|
+
// 预加载路由的具体实现
|
|
1700
|
+
prefetchRoute() {
|
|
1701
|
+
if (this._prefetched || !this.hasAttribute("prefetch")) return;
|
|
1702
|
+
const t = xt();
|
|
1703
|
+
t && typeof t.prefetch == "function" && (t.prefetch(this.$data.to), this._prefetched = !0);
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
It = Ye([
|
|
1707
|
+
zt({
|
|
1708
|
+
tagName: "router-link",
|
|
1709
|
+
// template 中 slot 包裹 label 作为 fallback:
|
|
1710
|
+
// 如果有子节点,显示子节点;如果没有,显示 label 属性的内容。
|
|
1711
|
+
template: `
|
|
1712
|
+
<a part="link" :href="$data.href" :class="{active: $data.isActive}">
|
|
1713
|
+
<slot>{{$data.label || ''}}</slot>
|
|
1714
|
+
</a>
|
|
1715
|
+
`,
|
|
1716
|
+
styles: `
|
|
1717
|
+
:host {
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
a {
|
|
1721
|
+
text-decoration: none;
|
|
1722
|
+
color: inherit;
|
|
1723
|
+
cursor: pointer;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
/* 内部 <a> 标签的默认高亮 */
|
|
1727
|
+
a.active {
|
|
1728
|
+
font-weight: 600;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
/* custom 模式:消除包裹 a 标签的视觉/布局影响,由 slot 内部元素接管 */
|
|
1732
|
+
:host([custom]) a {
|
|
1733
|
+
display: contents;
|
|
1734
|
+
}
|
|
1735
|
+
`,
|
|
1736
|
+
shadowDOM: { use: !0, mode: "open" },
|
|
1737
|
+
// 注册所有支持的 props
|
|
1738
|
+
props: ["to", "active", "exact", "label", "custom", "activeClass", "prefetch"]
|
|
1739
|
+
})
|
|
1740
|
+
], It);
|
|
1741
|
+
const tn = It;
|
|
1742
|
+
export {
|
|
1743
|
+
g as ASTType,
|
|
1744
|
+
mt as BaseElement,
|
|
1745
|
+
zt as CustomElement,
|
|
1746
|
+
Be as IRRenderer,
|
|
1747
|
+
fe as LIFECYCLE_ATTRS_MAP,
|
|
1748
|
+
Ge as Router,
|
|
1749
|
+
tn as RouterLink,
|
|
1750
|
+
Xe as RouterView,
|
|
1751
|
+
Ee as buildIR,
|
|
1752
|
+
Je as clearIRCache,
|
|
1753
|
+
se as createFunction,
|
|
1754
|
+
qe as createRender,
|
|
1755
|
+
Qe as createRouter,
|
|
1756
|
+
ue as genFunction,
|
|
1757
|
+
xt as getRouter,
|
|
1758
|
+
pe as isLifecycleKind,
|
|
1759
|
+
Y as isObject,
|
|
1760
|
+
he as listeners,
|
|
1761
|
+
de as mapAttrKeyToLifecycleKind,
|
|
1762
|
+
Ie as observe,
|
|
1763
|
+
Ze as parseHashUrl,
|
|
1764
|
+
Le as parseHtml,
|
|
1765
|
+
Ht as routerReady,
|
|
1766
|
+
ne as showTemplateError,
|
|
1767
|
+
we as transformModel
|
|
1768
|
+
};
|