solely 0.0.22 → 0.0.28
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/LICENSE +21 -21
- package/README.md +457 -275
- package/dist/base/base-element.d.ts +48 -6
- package/dist/base/decorators.d.ts +15 -3
- package/dist/base/router-view.d.ts +25 -2
- package/dist/solely.js +695 -322
- package/dist/solely.umd.cjs +3 -1
- package/dist/utils/html-parse.d.ts +22 -1
- package/dist/utils/observe.d.ts +57 -5
- package/package.json +17 -4
- package/dist/utils/functions copy 2.d.ts +0 -2
- package/dist/utils/functions copy.d.ts +0 -2
package/dist/solely.js
CHANGED
|
@@ -1,87 +1,132 @@
|
|
|
1
|
-
var
|
|
2
|
-
throw TypeError(
|
|
1
|
+
var ft = (t) => {
|
|
2
|
+
throw TypeError(t);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
return
|
|
4
|
+
var st = (t, e, n) => e.has(t) || ft("Cannot " + n);
|
|
5
|
+
var x = (t, e, n) => (st(t, e, "read from private field"), n ? n.call(t) : e.get(t)), M = (t, e, n) => e.has(t) ? ft("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), k = (t, e, n, s) => (st(t, e, "write to private field"), s ? s.call(t, n) : e.set(t, n), n), W = (t, e, n) => (st(t, e, "access private method"), n);
|
|
6
|
+
const _t = /<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g, St = /<\/?([^\s]+?)[/\s>]/, Wt = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g, It = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"], rt = /\{\{(.+?)\}\}/g;
|
|
7
|
+
function Ot(t) {
|
|
8
|
+
return t.replace(/>\s+</g, "><").replace(/\s+/g, " ");
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
const n = (
|
|
12
|
-
rootId: 0,
|
|
10
|
+
function jt(t, e) {
|
|
11
|
+
const n = (e.match(St) || [])[1] || "", s = {
|
|
12
|
+
rootId: "0",
|
|
13
13
|
tagName: n,
|
|
14
14
|
attrs: {},
|
|
15
15
|
props: {},
|
|
16
16
|
on: {},
|
|
17
17
|
children: []
|
|
18
|
-
}, r = new RegExp(
|
|
18
|
+
}, r = new RegExp(Wt);
|
|
19
19
|
for (; ; ) {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
if (!
|
|
23
|
-
const [
|
|
24
|
-
if (
|
|
25
|
-
s
|
|
26
|
-
else if (
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const o = r.exec(e);
|
|
21
|
+
if (o === null) break;
|
|
22
|
+
if (!o[0].trim()) continue;
|
|
23
|
+
const [a, i] = o[1] ? o[1].trim().split("=") : [o[2], o[3].trim().slice(1, -1)];
|
|
24
|
+
if (a === "onMounted" || a === "onUpdated")
|
|
25
|
+
s[a] = Ht(t, i);
|
|
26
|
+
else if (gt.includes(a) || a.startsWith("on-"))
|
|
27
|
+
s.on[a.startsWith("on-") ? a.slice(3) : a.slice(2)] = H(t, i);
|
|
28
|
+
else if (a.startsWith("s-")) {
|
|
29
|
+
const f = a.slice(2);
|
|
30
|
+
switch (f) {
|
|
29
31
|
case "model":
|
|
30
32
|
s.model = i;
|
|
31
33
|
break;
|
|
32
34
|
case "style":
|
|
33
|
-
s.styles = (
|
|
35
|
+
s.styles = (d) => O(t, i, d);
|
|
34
36
|
break;
|
|
35
37
|
case "class":
|
|
36
|
-
s.classes = (
|
|
38
|
+
s.classes = (d) => O(t, i, d);
|
|
37
39
|
break;
|
|
38
40
|
case "readonly":
|
|
39
|
-
s.props.readOnly = (
|
|
41
|
+
s.props.readOnly = (d) => O(t, i, d);
|
|
40
42
|
break;
|
|
41
43
|
default:
|
|
42
|
-
s.props[
|
|
44
|
+
s.props[f] = (d) => O(t, i, d);
|
|
43
45
|
break;
|
|
44
46
|
}
|
|
45
47
|
} else
|
|
46
|
-
s.attrs[
|
|
48
|
+
s.attrs[a] = i;
|
|
47
49
|
r.lastIndex--;
|
|
48
50
|
}
|
|
49
|
-
if (n === "For" ? s.fn = (
|
|
50
|
-
const
|
|
51
|
-
|
|
51
|
+
if (n === "For" ? s.fn = (o) => O(t, s.attrs.each, o) : (n === "If" || n === "ElseIf") && (s.fn = (o) => O(t, s.attrs.condition, o)), s.model) {
|
|
52
|
+
const o = s.model.replace("this.", "").replace("$data.", ""), a = (f) => O(t, `$data.${o}`, f), i = (f, d) => {
|
|
53
|
+
if (s.on[f]) {
|
|
54
|
+
const l = s.on[f];
|
|
55
|
+
s.on[f] = (c, u) => {
|
|
56
|
+
d(c, u), l(c, u);
|
|
57
|
+
};
|
|
58
|
+
} else
|
|
59
|
+
s.on[f] = d;
|
|
60
|
+
};
|
|
61
|
+
if (n === "input") {
|
|
62
|
+
const f = s.attrs.type || "text";
|
|
63
|
+
if (f === "checkbox")
|
|
64
|
+
s.props.checked = a, i("change", H(t, `$data.${o}=checked`));
|
|
65
|
+
else if (f === "radio") {
|
|
66
|
+
const d = s.attrs.value;
|
|
67
|
+
s.props.checked = (l) => a(l) == d, i("change", H(t, `if(checked){$data.${o}='${d}'}`));
|
|
68
|
+
} else
|
|
69
|
+
s.props.value = a, i("input", H(t, `$data.${o}=value`));
|
|
70
|
+
} else if (n === "textarea")
|
|
71
|
+
s.props.value = a, i("input", H(t, `$data.${o}=value`));
|
|
72
|
+
else if (n === "select") {
|
|
73
|
+
const f = "multiple" in s.attrs;
|
|
74
|
+
f ? i(
|
|
75
|
+
"change",
|
|
76
|
+
H(t, `
|
|
77
|
+
$data.${o} = Array.from(event.target.selectedOptions).map(o => o.value);
|
|
78
|
+
`)
|
|
79
|
+
) : (i("change", H(t, `$data.${o}=value`)), s.props.value = a);
|
|
80
|
+
const d = (u, p = []) => {
|
|
81
|
+
const $ = a(p);
|
|
82
|
+
if (f) {
|
|
83
|
+
const A = Array.isArray($) ? $ : $ != null ? [$] : [];
|
|
84
|
+
for (const R of u.options)
|
|
85
|
+
R.selected = A.includes(R.value);
|
|
86
|
+
} else {
|
|
87
|
+
const A = $ ?? "";
|
|
88
|
+
u.value !== A && (u.value = A);
|
|
89
|
+
}
|
|
90
|
+
}, l = s.onMounted, c = s.onUpdated;
|
|
91
|
+
s.onMounted = (u, p) => {
|
|
92
|
+
l == null || l(u, p), d(u, p || []);
|
|
93
|
+
}, s.onUpdated = (u, p) => {
|
|
94
|
+
c == null || c(u, p), d(u, p || []);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
52
97
|
}
|
|
53
98
|
return s;
|
|
54
99
|
}
|
|
55
|
-
function
|
|
100
|
+
function Tt(t, e) {
|
|
56
101
|
const n = [];
|
|
57
|
-
if (!
|
|
58
|
-
|
|
59
|
-
const s = [], r = [],
|
|
102
|
+
if (!e) return n;
|
|
103
|
+
e = Ot(e);
|
|
104
|
+
const s = [], r = [], o = () => {
|
|
60
105
|
var i;
|
|
61
106
|
return s.length === 0 ? n : (i = s[s.length - 1]).children || (i.children = []);
|
|
62
107
|
};
|
|
63
|
-
let
|
|
64
|
-
return
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
rootId: 0,
|
|
108
|
+
let a = 0;
|
|
109
|
+
return e.replace(_t, (i, f) => {
|
|
110
|
+
const d = o();
|
|
111
|
+
if (f > a) {
|
|
112
|
+
const l = e.substring(a, f).trim();
|
|
113
|
+
if (l) {
|
|
114
|
+
rt.lastIndex = 0;
|
|
115
|
+
const u = !rt.test(l) ? l : (p) => l.replace(rt, ($, A) => O(t, A, p));
|
|
116
|
+
d.push({
|
|
117
|
+
rootId: "0",
|
|
73
118
|
tagName: "text",
|
|
74
119
|
attrs: {},
|
|
75
120
|
props: {},
|
|
76
121
|
on: {},
|
|
77
|
-
content:
|
|
122
|
+
content: u,
|
|
78
123
|
children: []
|
|
79
124
|
});
|
|
80
125
|
}
|
|
81
126
|
}
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
rootId: 0,
|
|
127
|
+
if (a = f + i.length, i.startsWith("<!--") && i.endsWith("-->"))
|
|
128
|
+
d.push({
|
|
129
|
+
rootId: "0",
|
|
85
130
|
tagName: "comment",
|
|
86
131
|
attrs: {},
|
|
87
132
|
props: {},
|
|
@@ -90,32 +135,94 @@ function Et(e, t) {
|
|
|
90
135
|
children: []
|
|
91
136
|
});
|
|
92
137
|
else if (i.startsWith("</")) {
|
|
93
|
-
const
|
|
94
|
-
for (; s.length > 0 && s[s.length - 1].tagName !==
|
|
138
|
+
const l = r.pop();
|
|
139
|
+
for (; s.length > 0 && s[s.length - 1].tagName !== l; )
|
|
95
140
|
s.pop();
|
|
96
141
|
s.pop();
|
|
97
142
|
} else {
|
|
98
|
-
const
|
|
99
|
-
|
|
143
|
+
const l = jt(t, i), c = i.endsWith("/>") || It.includes(l.tagName);
|
|
144
|
+
d.push(l), c || (s.push(l), r.push(l.tagName));
|
|
100
145
|
}
|
|
101
146
|
return "";
|
|
102
|
-
}),
|
|
103
|
-
rootId: 0,
|
|
147
|
+
}), e.length > a && n.push({
|
|
148
|
+
rootId: "0",
|
|
104
149
|
tagName: "text",
|
|
105
150
|
attrs: {},
|
|
106
151
|
props: {},
|
|
107
152
|
on: {},
|
|
108
|
-
content:
|
|
153
|
+
content: e.substring(a).trim(),
|
|
109
154
|
children: []
|
|
110
155
|
}), n;
|
|
111
156
|
}
|
|
112
|
-
const
|
|
157
|
+
const O = (t, e, n) => {
|
|
113
158
|
try {
|
|
114
|
-
return
|
|
159
|
+
return lt([
|
|
160
|
+
"$data",
|
|
161
|
+
...n.map((r) => r.item),
|
|
162
|
+
...n.map((r) => r.index),
|
|
163
|
+
// 表达式求值,返回结果
|
|
164
|
+
`return (${e})`
|
|
165
|
+
]).bind(t)(
|
|
166
|
+
t.$data,
|
|
167
|
+
...n.map((r) => r.value),
|
|
168
|
+
...n.map((r) => r.valueIndex)
|
|
169
|
+
);
|
|
115
170
|
} catch (s) {
|
|
116
|
-
console.error(
|
|
171
|
+
return console.error(
|
|
172
|
+
`[BaseElement][${t.tagName}] Error evaluating expression: {{ ${e} }}`,
|
|
173
|
+
t,
|
|
174
|
+
s
|
|
175
|
+
), "";
|
|
176
|
+
}
|
|
177
|
+
}, H = (t, e) => (n, s) => {
|
|
178
|
+
var r, o;
|
|
179
|
+
try {
|
|
180
|
+
return lt([
|
|
181
|
+
"$data",
|
|
182
|
+
"event",
|
|
183
|
+
"value",
|
|
184
|
+
"checked",
|
|
185
|
+
...s.map((i) => i.item),
|
|
186
|
+
...s.map((i) => i.index),
|
|
187
|
+
e
|
|
188
|
+
]).bind(t)(
|
|
189
|
+
t.$data,
|
|
190
|
+
n,
|
|
191
|
+
(r = n == null ? void 0 : n.target) == null ? void 0 : r.value,
|
|
192
|
+
(o = n == null ? void 0 : n.target) == null ? void 0 : o.checked,
|
|
193
|
+
...s.map((i) => i.value),
|
|
194
|
+
...s.map((i) => i.valueIndex)
|
|
195
|
+
);
|
|
196
|
+
} catch (a) {
|
|
197
|
+
console.error(
|
|
198
|
+
`[BaseElement][${t.tagName}] Error executing event handler "${e}"`,
|
|
199
|
+
t,
|
|
200
|
+
a
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}, Ht = (t, e) => (n, s = []) => {
|
|
204
|
+
try {
|
|
205
|
+
lt([
|
|
206
|
+
"$data",
|
|
207
|
+
"elm",
|
|
208
|
+
...s.map((o) => o.item),
|
|
209
|
+
...s.map((o) => o.index),
|
|
210
|
+
// 执行语句块(无 return)
|
|
211
|
+
`(function(){ ${e} }).call(this)`
|
|
212
|
+
]).bind(t)(
|
|
213
|
+
t.$data,
|
|
214
|
+
n,
|
|
215
|
+
...s.map((o) => o.value),
|
|
216
|
+
...s.map((o) => o.valueIndex)
|
|
217
|
+
);
|
|
218
|
+
} catch (r) {
|
|
219
|
+
console.error(
|
|
220
|
+
`[BaseElement][${t.tagName}] Error executing lifecycle handler "${e}"`,
|
|
221
|
+
t,
|
|
222
|
+
r
|
|
223
|
+
);
|
|
117
224
|
}
|
|
118
|
-
},
|
|
225
|
+
}, gt = [
|
|
119
226
|
"onabort",
|
|
120
227
|
"onautocomplete",
|
|
121
228
|
"onautocompleteerror",
|
|
@@ -178,148 +285,153 @@ const g = (e, t, n) => {
|
|
|
178
285
|
"ontoggle",
|
|
179
286
|
"onvolumechange",
|
|
180
287
|
"onwaiting"
|
|
181
|
-
],
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const t = e.map((n) => n.replace(/[',"]/g, "")).join(",");
|
|
191
|
-
if (!q[t]) {
|
|
192
|
-
const n = e[e.length - 1];
|
|
288
|
+
], Lt = typeof requestAnimationFrame == "function" ? (t) => requestAnimationFrame(t) : typeof Promise < "u" ? (t) => Promise.resolve().then(t) : (t) => setTimeout(t, 0), Dt = (t, ...e) => {
|
|
289
|
+
if (typeof t != "function")
|
|
290
|
+
throw new Error("runInAsyncQueue expects a function as its first argument");
|
|
291
|
+
Lt(() => t(...e));
|
|
292
|
+
}, ot = {};
|
|
293
|
+
function lt(t) {
|
|
294
|
+
const e = t.map((n) => n.replace(/[',"]/g, "")).join(",");
|
|
295
|
+
if (!ot[e]) {
|
|
296
|
+
const n = t[t.length - 1];
|
|
193
297
|
if (n.trim() === "")
|
|
194
298
|
throw new Error("Function body cannot be empty");
|
|
195
|
-
if (
|
|
299
|
+
if (Ut(n))
|
|
196
300
|
throw new Error("Input contains potentially dangerous code: " + n);
|
|
197
|
-
|
|
301
|
+
ot[e] = new Function(...t);
|
|
198
302
|
}
|
|
199
|
-
return
|
|
303
|
+
return ot[e];
|
|
200
304
|
}
|
|
201
|
-
const
|
|
202
|
-
function
|
|
203
|
-
return
|
|
305
|
+
const Ft = ["eval", "Function", "process", "require"];
|
|
306
|
+
function Ut(t) {
|
|
307
|
+
return Ft.some((e) => new RegExp(`\\b${e}\\b`, "g").test(t));
|
|
204
308
|
}
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
n.textContent !==
|
|
208
|
-
},
|
|
209
|
-
Object.keys(
|
|
210
|
-
const r =
|
|
211
|
-
|
|
309
|
+
const qt = "http://www.w3.org/1999/xlink", Vt = "http://www.w3.org/2000/xmlns/", Bt = "http://www.w3.org/XML/1998/namespace", zt = "http://www.w3.org/2000/svg", yt = (t) => typeof t.content == "function" ? t.content(t.loops || []) : t.content || "", Gt = (t) => {
|
|
310
|
+
const e = yt(t), n = t.elm;
|
|
311
|
+
n.textContent !== e && (n.textContent = e);
|
|
312
|
+
}, Et = (t, e, n = []) => {
|
|
313
|
+
Object.keys(e).forEach((s) => {
|
|
314
|
+
const r = e[s](n);
|
|
315
|
+
t[s] !== r && (t[s] = r);
|
|
212
316
|
});
|
|
213
|
-
},
|
|
214
|
-
const { styles: n, loops: s = [] } =
|
|
317
|
+
}, vt = (t, e) => {
|
|
318
|
+
const { styles: n, loops: s = [] } = e;
|
|
215
319
|
if (!n) return;
|
|
216
|
-
const r = n(s),
|
|
217
|
-
Object.entries(
|
|
218
|
-
|
|
320
|
+
const r = n(s), o = at(r);
|
|
321
|
+
Object.entries(o).forEach(([a, i]) => {
|
|
322
|
+
t.style[a] = i;
|
|
219
323
|
});
|
|
220
|
-
},
|
|
221
|
-
const { classes: n, loops: s = [] } =
|
|
324
|
+
}, $t = (t, e) => {
|
|
325
|
+
const { classes: n, loops: s = [] } = e;
|
|
222
326
|
if (!n) return;
|
|
223
|
-
const r = n(s),
|
|
224
|
-
Object.entries(
|
|
225
|
-
i ?
|
|
327
|
+
const r = n(s), o = bt(r);
|
|
328
|
+
Object.entries(o).forEach(([a, i]) => {
|
|
329
|
+
i ? t.classList.add(a) : t.classList.remove(a);
|
|
226
330
|
});
|
|
227
|
-
},
|
|
228
|
-
let
|
|
229
|
-
return typeof
|
|
331
|
+
}, at = (t) => {
|
|
332
|
+
let e = {};
|
|
333
|
+
return typeof t == "object" && t !== null && !Array.isArray(t) ? Object.entries(t).forEach(([n, s]) => {
|
|
230
334
|
if (typeof s == "object" && s !== null && !Array.isArray(s)) {
|
|
231
|
-
const r =
|
|
232
|
-
Object.entries(r).forEach(([
|
|
233
|
-
|
|
335
|
+
const r = at(s);
|
|
336
|
+
Object.entries(r).forEach(([o, a]) => {
|
|
337
|
+
e[`${n}-${o}`] = a;
|
|
234
338
|
});
|
|
235
|
-
} else typeof s == "string" || typeof s == "number" ?
|
|
236
|
-
}) : typeof
|
|
237
|
-
const [s, r] = n.split(":").map((
|
|
238
|
-
s && r && (
|
|
239
|
-
}) : Array.isArray(
|
|
240
|
-
const s =
|
|
241
|
-
Object.entries(s).forEach(([r,
|
|
242
|
-
|
|
339
|
+
} else typeof s == "string" || typeof s == "number" ? e[n] = `${s}` : e[n] = String(s);
|
|
340
|
+
}) : typeof t == "string" ? t.split(";").forEach((n) => {
|
|
341
|
+
const [s, r] = n.split(":").map((o) => o.trim());
|
|
342
|
+
s && r && (e[s] = r);
|
|
343
|
+
}) : Array.isArray(t) && t.forEach((n) => {
|
|
344
|
+
const s = at(n);
|
|
345
|
+
Object.entries(s).forEach(([r, o]) => {
|
|
346
|
+
e[r] = o;
|
|
243
347
|
});
|
|
244
|
-
}),
|
|
245
|
-
},
|
|
246
|
-
let
|
|
247
|
-
return typeof
|
|
248
|
-
|
|
249
|
-
}) : typeof
|
|
250
|
-
n !== "" && (
|
|
251
|
-
}) : Array.isArray(
|
|
252
|
-
const s =
|
|
253
|
-
Object.entries(s).forEach(([r,
|
|
254
|
-
|
|
348
|
+
}), e;
|
|
349
|
+
}, bt = (t) => {
|
|
350
|
+
let e = {};
|
|
351
|
+
return typeof t == "object" && !Array.isArray(t) ? Object.entries(t).forEach(([n, s]) => {
|
|
352
|
+
e[n] = !!s;
|
|
353
|
+
}) : typeof t == "string" ? t.split(" ").forEach((n) => {
|
|
354
|
+
n !== "" && (e[n] = !0);
|
|
355
|
+
}) : Array.isArray(t) && t.forEach((n) => {
|
|
356
|
+
const s = bt(n);
|
|
357
|
+
Object.entries(s).forEach(([r, o]) => {
|
|
358
|
+
e[r] = o;
|
|
255
359
|
});
|
|
256
|
-
}),
|
|
257
|
-
},
|
|
258
|
-
const s = (r) => n.on[
|
|
259
|
-
|
|
260
|
-
},
|
|
261
|
-
const n =
|
|
262
|
-
Object.keys(
|
|
263
|
-
|
|
264
|
-
}),
|
|
265
|
-
|
|
266
|
-
|
|
360
|
+
}), e;
|
|
361
|
+
}, kt = (t, e, n) => {
|
|
362
|
+
const s = (r) => n.on[e](r, n.loops || []);
|
|
363
|
+
t.addEventListener(e, s, !1), n.handlers = n.handlers || {}, n.handlers[e] = s;
|
|
364
|
+
}, Kt = (t, e) => {
|
|
365
|
+
const n = e.elm;
|
|
366
|
+
Object.keys(e.on).forEach((s) => {
|
|
367
|
+
t.handlers && t.handlers[s] && n.removeEventListener(s, t.handlers[s], !1), kt(n, s, e);
|
|
368
|
+
}), Et(n, e.props, e.loops), $t(n, e), vt(n, e), typeof e.onUpdated == "function" && requestAnimationFrame(() => {
|
|
369
|
+
e.onUpdated(n, e.loops || []);
|
|
370
|
+
}), At(n, t.children, e.children);
|
|
371
|
+
}, Qt = (t, e) => {
|
|
372
|
+
switch (e.elm = t.elm, e.tagName) {
|
|
267
373
|
case "comment":
|
|
268
374
|
break;
|
|
269
375
|
case "text":
|
|
270
|
-
|
|
376
|
+
Gt(e);
|
|
271
377
|
break;
|
|
272
378
|
case "slot":
|
|
273
379
|
break;
|
|
274
380
|
default:
|
|
275
|
-
|
|
381
|
+
Kt(t, e);
|
|
276
382
|
break;
|
|
277
383
|
}
|
|
278
|
-
},
|
|
279
|
-
n ?
|
|
280
|
-
},
|
|
281
|
-
const s =
|
|
282
|
-
|
|
283
|
-
},
|
|
284
|
-
const s =
|
|
285
|
-
|
|
286
|
-
},
|
|
287
|
-
|
|
288
|
-
const r = s ? document.createElementNS(s,
|
|
289
|
-
Object.keys(
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
}), Object.keys(
|
|
293
|
-
|
|
294
|
-
}),
|
|
295
|
-
|
|
384
|
+
}, ut = (t, e, n) => {
|
|
385
|
+
n && n.parentNode === t ? t.insertBefore(e, n) : t.appendChild(e);
|
|
386
|
+
}, Jt = (t, e, n) => {
|
|
387
|
+
const s = yt(e), r = document.createTextNode(s);
|
|
388
|
+
e.elm = r, ut(t, r, n);
|
|
389
|
+
}, Nt = (t, e, n) => {
|
|
390
|
+
const s = e.content, r = document.createComment(s);
|
|
391
|
+
e.elm = r, ut(t, r, n);
|
|
392
|
+
}, Xt = (t, e, n, s) => {
|
|
393
|
+
e.tagName === "svg" && (s = zt);
|
|
394
|
+
const r = s ? document.createElementNS(s, e.tagName) : document.createElement(e.tagName);
|
|
395
|
+
Object.keys(e.attrs).forEach((o) => {
|
|
396
|
+
const a = e.attrs[o] || "";
|
|
397
|
+
o.charAt(0) !== "x" ? r.setAttribute(o, a) : o.startsWith("xml:") ? r.setAttributeNS(Bt, o, a) : o.startsWith("xlink:") ? r.setAttributeNS(qt, o, a) : o.startsWith("xmlns:") ? r.setAttributeNS(Vt, o, a) : r.setAttribute(o, a);
|
|
398
|
+
}), Object.keys(e.on).forEach((o) => {
|
|
399
|
+
kt(r, o, e);
|
|
400
|
+
}), Et(r, e.props, e.loops), $t(r, e), vt(r, e), e.elm = r, ut(t, r, n), e.tagName === "foreignObject" && (s = void 0), e.children.forEach((o) => {
|
|
401
|
+
N(r, o, void 0, s);
|
|
402
|
+
}), typeof e.onMounted == "function" && requestAnimationFrame(() => {
|
|
403
|
+
e.onMounted(r, e.loops || []);
|
|
296
404
|
});
|
|
297
|
-
},
|
|
298
|
-
switch (
|
|
405
|
+
}, N = (t, e, n, s) => {
|
|
406
|
+
switch (e.tagName) {
|
|
299
407
|
case "comment":
|
|
300
|
-
|
|
408
|
+
Nt(t, e, n);
|
|
301
409
|
break;
|
|
302
410
|
case "text":
|
|
303
|
-
|
|
411
|
+
Jt(t, e, n);
|
|
304
412
|
break;
|
|
305
413
|
default:
|
|
306
|
-
|
|
414
|
+
Xt(t, e, n, s);
|
|
307
415
|
break;
|
|
308
416
|
}
|
|
309
|
-
},
|
|
310
|
-
var
|
|
311
|
-
|
|
312
|
-
|
|
417
|
+
}, Zt = (t) => t && (t.tagName === "ElseIf" || t.tagName === "comment"), Yt = (t) => t && t.tagName === "Else", F = (t, e, n = [], s = "0", r) => {
|
|
418
|
+
var i, f, d;
|
|
419
|
+
let o = 0, a = 0;
|
|
420
|
+
for (let l = 0; l < e.length; l++) {
|
|
421
|
+
const c = e[l];
|
|
313
422
|
if (c.tagName === "If") {
|
|
314
|
-
let u = !1
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
423
|
+
let u = !1;
|
|
424
|
+
o++;
|
|
425
|
+
let p = 1;
|
|
426
|
+
for (((i = c.fn) == null ? void 0 : i.call(c, n)) && (F(t, c.children, n, `${s}-if-${o}-${p}`, p), u = !0), p++; l + 1 < e.length && Zt(e[l + 1]); )
|
|
427
|
+
((d = (f = e[l + 1]).fn) == null ? void 0 : d.call(f, n)) && !u && (F(t, e[l + 1].children, n, `${s}-if-${o}-${p}`, p), u = !0), l++, p++;
|
|
428
|
+
l + 1 < e.length && Yt(e[l + 1]) && (u || (F(t, e[l + 1].children, n, `${s}-if-${o}-${p}`, p), u = !0), l++);
|
|
318
429
|
} else if (c.tagName === "For") {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
430
|
+
a++;
|
|
431
|
+
const { item: u = "item", index: p = "index" } = c.attrs;
|
|
432
|
+
(c.fn(n) || []).forEach((A, R) => {
|
|
433
|
+
const Q = { item: u, value: A, index: p, valueIndex: R };
|
|
434
|
+
F(t, c.children, [...n, Q], `${s}-for-${a}-${R}`, 1);
|
|
323
435
|
});
|
|
324
436
|
} else {
|
|
325
437
|
const u = {
|
|
@@ -327,231 +439,492 @@ const wt = "http://www.w3.org/1999/xlink", _t = "http://www.w3.org/2000/xmlns/",
|
|
|
327
439
|
loops: n,
|
|
328
440
|
children: [],
|
|
329
441
|
rootId: s,
|
|
330
|
-
ifId:
|
|
442
|
+
ifId: r,
|
|
443
|
+
key: c.key || `${s}-${l}`
|
|
444
|
+
// 添加 key 属性
|
|
331
445
|
};
|
|
332
|
-
|
|
446
|
+
F(u.children, c.children, n, `${s}-${l}`), t.push(u);
|
|
333
447
|
}
|
|
334
|
-
r && s++;
|
|
335
448
|
}
|
|
336
|
-
},
|
|
337
|
-
var a,
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
c.rootId === u.rootId ? (u.ifId && c.ifId !== u.ifId ? ((a = c.elm) == null || a.remove(), M(e, u, (o = t[s + 1]) == null ? void 0 : o.elm)) : At(c, u), r++, s++) : c.rootId > u.rootId ? ((i = c.elm) == null || i.remove(), s++) : (M(e, u, (h = t[s + 1]) == null ? void 0 : h.elm), r++);
|
|
342
|
-
}
|
|
343
|
-
for (; s < t.length; )
|
|
344
|
-
(l = t[s].elm) == null || l.remove(), s++;
|
|
449
|
+
}, At = (t, e, n) => {
|
|
450
|
+
var a, i, f, d, l;
|
|
451
|
+
const s = /* @__PURE__ */ new Map();
|
|
452
|
+
e.forEach((c, u) => s.set(c.key, { node: c, index: u }));
|
|
453
|
+
let r = 0, o = 0;
|
|
345
454
|
for (; r < n.length; ) {
|
|
346
|
-
const c = n[r];
|
|
347
|
-
|
|
455
|
+
const c = n[r], u = s.get(c.key);
|
|
456
|
+
if (u) {
|
|
457
|
+
const p = u.node;
|
|
458
|
+
if (p.tagName !== c.tagName) {
|
|
459
|
+
(a = p.elm) == null || a.remove();
|
|
460
|
+
const $ = (i = e[o + 1]) == null ? void 0 : i.elm;
|
|
461
|
+
N(t, c, $), s.delete(c.key), o++;
|
|
462
|
+
} else {
|
|
463
|
+
if (c.ifId && p.ifId !== c.ifId) {
|
|
464
|
+
(f = p.elm) == null || f.remove();
|
|
465
|
+
const $ = (d = e[o + 1]) == null ? void 0 : d.elm;
|
|
466
|
+
N(t, c, $);
|
|
467
|
+
} else
|
|
468
|
+
Qt(p, c);
|
|
469
|
+
s.delete(c.key), o++;
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
const p = (l = e[o]) == null ? void 0 : l.elm;
|
|
473
|
+
N(t, c, p);
|
|
474
|
+
}
|
|
475
|
+
r++;
|
|
348
476
|
}
|
|
349
|
-
|
|
350
|
-
|
|
477
|
+
s.forEach(({ node: c }) => {
|
|
478
|
+
var u;
|
|
479
|
+
return (u = c.elm) == null ? void 0 : u.remove();
|
|
480
|
+
});
|
|
481
|
+
}, Ct = (t, e, n = []) => {
|
|
482
|
+
if (!e || e.length === 0) return [];
|
|
351
483
|
const s = [];
|
|
352
|
-
return
|
|
353
|
-
},
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
484
|
+
return F(s, e || [], [], "0"), At(t, n, s), s;
|
|
485
|
+
}, j = (t) => {
|
|
486
|
+
if (t === null || typeof t != "object") return !1;
|
|
487
|
+
const e = Object.prototype.toString.call(t);
|
|
488
|
+
return ![
|
|
489
|
+
"[object Function]",
|
|
490
|
+
"[object Date]",
|
|
491
|
+
"[object RegExp]",
|
|
492
|
+
"[object Map]",
|
|
493
|
+
"[object Set]",
|
|
494
|
+
"[object WeakMap]",
|
|
495
|
+
"[object WeakSet]"
|
|
496
|
+
].includes(e);
|
|
497
|
+
};
|
|
498
|
+
function te(t = window.location) {
|
|
499
|
+
let e;
|
|
500
|
+
typeof t == "string" ? e = new URL(t).hash : e = t.hash;
|
|
501
|
+
const n = e.split("?"), s = n[0].substring(2), r = n[1], o = {};
|
|
502
|
+
return r && r.split("&").forEach((a) => {
|
|
503
|
+
const [i, f] = a.split("=");
|
|
504
|
+
i && f && (o[decodeURIComponent(i)] = decodeURIComponent(f));
|
|
361
505
|
}), {
|
|
362
506
|
path: s.split("/"),
|
|
363
507
|
// 将路径分割成数组
|
|
364
|
-
query:
|
|
508
|
+
query: o
|
|
365
509
|
// 查询参数对象
|
|
366
510
|
};
|
|
367
511
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
512
|
+
function pt(t, e, n = {}) {
|
|
513
|
+
const s = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new WeakSet(), o = /* @__PURE__ */ new WeakMap(), { throttle: a = 0, deepCompare: i = !1, onBatch: f = null, immediate: d = !1 } = n, l = Array.isArray(n.filter) ? n.filter : n.filter ? [n.filter] : [];
|
|
514
|
+
let c = [], u = null, p = !0;
|
|
515
|
+
const $ = (h, m, v = /* @__PURE__ */ new WeakMap()) => {
|
|
516
|
+
if (h === m) return !0;
|
|
517
|
+
if (h == null || m == null || typeof h != "object" || typeof m != "object") return h === m;
|
|
518
|
+
if (v.has(h)) return v.get(h) === m;
|
|
519
|
+
if (v.set(h, m), Array.isArray(h) && Array.isArray(m)) {
|
|
520
|
+
if (h.length !== m.length) return !1;
|
|
521
|
+
for (let g = 0; g < h.length; g++)
|
|
522
|
+
if (!$(h[g], m[g], v)) return !1;
|
|
523
|
+
return !0;
|
|
524
|
+
}
|
|
525
|
+
if (Array.isArray(h) !== Array.isArray(m)) return !1;
|
|
526
|
+
const b = Object.keys(h), y = Object.keys(m);
|
|
527
|
+
if (b.length !== y.length) return !1;
|
|
528
|
+
for (const g of b)
|
|
529
|
+
if (!Object.prototype.hasOwnProperty.call(m, g) || !$(h[g], m[g], v)) return !1;
|
|
530
|
+
return !0;
|
|
531
|
+
}, A = (h) => {
|
|
532
|
+
if (l.length === 0) return !0;
|
|
533
|
+
const m = h.map(String).join(".");
|
|
534
|
+
return l.some((v) => {
|
|
535
|
+
if (!v) return !0;
|
|
536
|
+
try {
|
|
537
|
+
return new RegExp(
|
|
538
|
+
"^" + v.replace(/\./g, "\\.").replace(/\[\*\]/g, "(\\.\\d+)?").replace(/\*\*/g, "(.+)").replace(/\*/g, "[^.]+") + "$"
|
|
539
|
+
).test(m);
|
|
540
|
+
} catch {
|
|
541
|
+
return !0;
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
}, R = (h, m, v) => {
|
|
545
|
+
p && A(h) && (a > 0 ? (c.push({ path: h, newValue: m, oldValue: v }), u || (u = setTimeout(() => {
|
|
546
|
+
if (!p) {
|
|
547
|
+
u = null;
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const b = c;
|
|
551
|
+
c = [], u = null, f && f(b);
|
|
552
|
+
for (const y of b)
|
|
553
|
+
e(y.path, y.newValue, y.oldValue);
|
|
554
|
+
}, a))) : (e(h, m, v), f && f([{ path: h, newValue: m, oldValue: v }])));
|
|
555
|
+
}, Q = (h, m) => {
|
|
556
|
+
if (!j(h) || !(Array.isArray(h) || Object.prototype.toString.call(h) === "[object Object]")) return h;
|
|
557
|
+
const v = {};
|
|
558
|
+
if (["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].forEach((y) => {
|
|
559
|
+
const g = Array.prototype[y];
|
|
560
|
+
v[y] = function(...E) {
|
|
561
|
+
if (!p) return Reflect.apply(g, h, E);
|
|
562
|
+
const C = [...h], S = g.apply(h, E);
|
|
563
|
+
return $(h, C) || R(m, h, C), S;
|
|
564
|
+
};
|
|
565
|
+
}), s.has(h)) {
|
|
566
|
+
const y = s.get(h);
|
|
567
|
+
return o.set(y, m), y;
|
|
568
|
+
}
|
|
569
|
+
r.add(h);
|
|
570
|
+
const b = new Proxy(h, {
|
|
571
|
+
get(y, g, E) {
|
|
572
|
+
if (Array.isArray(y) && v.hasOwnProperty(g))
|
|
573
|
+
return Reflect.get(v, g, E);
|
|
574
|
+
const C = Reflect.get(y, g, E);
|
|
575
|
+
if (j(C)) {
|
|
576
|
+
const J = [...o.get(b) || [], g], nt = Q(C, J);
|
|
577
|
+
return o.set(nt, J), nt;
|
|
578
|
+
}
|
|
579
|
+
return C;
|
|
580
|
+
},
|
|
581
|
+
set(y, g, E, C) {
|
|
582
|
+
const S = Reflect.get(y, g, C), J = j(E) && !(E instanceof Date || E instanceof RegExp || E instanceof Map || E instanceof Set);
|
|
583
|
+
if (i && J ? $(S, E) : S === E) return !0;
|
|
584
|
+
const Mt = Reflect.set(y, g, E, C), Pt = o.get(b) || m;
|
|
585
|
+
return R([...Pt, g], E, S), Mt;
|
|
586
|
+
},
|
|
587
|
+
deleteProperty(y, g) {
|
|
588
|
+
if (Reflect.has(y, g)) {
|
|
589
|
+
const E = y[g], C = Reflect.deleteProperty(y, g), S = o.get(b) || [];
|
|
590
|
+
return C && r.has(y) && R([...S, g], void 0, E), C;
|
|
591
|
+
}
|
|
592
|
+
return !1;
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
return s.set(h, b), o.set(b, m), b;
|
|
596
|
+
}, Rt = Q(t, []);
|
|
597
|
+
if (d) {
|
|
598
|
+
const h = (m, v, b = /* @__PURE__ */ new WeakSet()) => {
|
|
599
|
+
if (!(!j(m) || !p || b.has(m))) {
|
|
600
|
+
b.add(m);
|
|
601
|
+
for (const y of Object.keys(m)) {
|
|
602
|
+
const g = [...v, y], E = m[y];
|
|
603
|
+
A(g) && e(g, E, void 0), j(E) && h(E, g, b);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
h(t, []);
|
|
608
|
+
}
|
|
609
|
+
return { proxy: Rt, unobserve: () => {
|
|
610
|
+
p && (p = !1, c = [], u && (clearTimeout(u), u = null));
|
|
611
|
+
}, resume: () => {
|
|
612
|
+
p = !0;
|
|
613
|
+
} };
|
|
614
|
+
}
|
|
615
|
+
var V, z, G, L, K, D, _, w, U, it;
|
|
616
|
+
class le extends HTMLElement {
|
|
617
|
+
// 停止数据监听函数
|
|
618
|
+
// -----------------------------------------------------
|
|
619
|
+
/**
|
|
620
|
+
* 构造函数
|
|
621
|
+
* -------------------------------------------------------
|
|
622
|
+
* 初始化模板、响应式数据和渲染根节点。
|
|
623
|
+
* 样式注入延迟到 connectedCallback 阶段。
|
|
624
|
+
*/
|
|
625
|
+
constructor(n = {}) {
|
|
626
|
+
var a;
|
|
378
627
|
super();
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
628
|
+
M(this, w);
|
|
629
|
+
// ---------------------- 私有属性 ----------------------
|
|
630
|
+
M(this, V);
|
|
631
|
+
// 响应式数据(Proxy)
|
|
632
|
+
M(this, z, []);
|
|
633
|
+
// 模板解析后的虚拟节点 AST
|
|
634
|
+
M(this, G, []);
|
|
635
|
+
// 上一次渲染的虚拟节点
|
|
636
|
+
M(this, L, !1);
|
|
637
|
+
// 节流刷新,防止重复 patch
|
|
638
|
+
M(this, K, !1);
|
|
639
|
+
// 是否已挂载
|
|
640
|
+
M(this, D);
|
|
641
|
+
// 渲染根节点(Shadow DOM 优先)
|
|
642
|
+
M(this, _);
|
|
643
|
+
const s = this._manifest || {};
|
|
644
|
+
k(this, D, (a = s.shadowDOM) != null && a.use ? this.attachShadow({ mode: s.shadowDOM.mode || "open" }) : this);
|
|
645
|
+
const { proxy: r, unobserve: o } = pt(n, () => W(this, w, U).call(this));
|
|
646
|
+
k(this, V, r), k(this, _, o), s.template && typeof s.template == "string" && k(this, z, Tt(this, s.template)), Promise.resolve().then(() => this.created());
|
|
390
647
|
}
|
|
648
|
+
/** Web Components 标准方法:声明哪些属性变化会触发 attributeChangedCallback */
|
|
649
|
+
static get observedAttributes() {
|
|
650
|
+
const n = this._manifest || this.prototype._manifest;
|
|
651
|
+
return n != null && n.props ? n.props.map((s) => typeof s == "string" ? s : s.name) : [];
|
|
652
|
+
}
|
|
653
|
+
// ---------------------- $data getter/setter ----------------------
|
|
654
|
+
/** 获取当前组件数据 */
|
|
391
655
|
get $data() {
|
|
392
|
-
|
|
393
|
-
return ot(n) && (n = it(n, () => H(this, x, O).call(this))), n;
|
|
656
|
+
return x(this, V);
|
|
394
657
|
}
|
|
658
|
+
/** 更新组件数据 */
|
|
395
659
|
set $data(n) {
|
|
396
|
-
|
|
660
|
+
j(n) || (n = {}), x(this, _) && x(this, _).call(this);
|
|
661
|
+
const { proxy: s, unobserve: r } = pt(n, () => W(this, w, U).call(this));
|
|
662
|
+
k(this, V, s), k(this, _, r), W(this, w, U).call(this);
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* 手动刷新组件
|
|
666
|
+
* 外部可调用,用于数据未触发 observe 或强制刷新
|
|
667
|
+
*/
|
|
668
|
+
refresh() {
|
|
669
|
+
W(this, w, U).call(this);
|
|
397
670
|
}
|
|
671
|
+
// ---------------------- Web Components 生命周期 ----------------------
|
|
398
672
|
connectedCallback() {
|
|
399
673
|
const n = this._manifest || {};
|
|
400
|
-
(n.className || n.tagName || "").split(" ").forEach((r) => {
|
|
401
|
-
r
|
|
402
|
-
|
|
674
|
+
if ((n.className || n.tagName || "").split(" ").forEach((r) => r && this.classList.add(r)), n.styles && !x(this, D).querySelector("style[data-manifest-style]")) {
|
|
675
|
+
const r = document.createElement("style");
|
|
676
|
+
r.setAttribute("data-manifest-style", "true"), r.textContent = n.styles, x(this, D).appendChild(r);
|
|
677
|
+
}
|
|
678
|
+
if (n.props && j(this.$data))
|
|
679
|
+
for (const r of n.props) {
|
|
680
|
+
const o = typeof r == "string" ? r : r.name, a = typeof r == "object" && "type" in r ? r.type : void 0, i = o.replace(/-([a-z])/g, (d, l) => l.toUpperCase()), f = this.$data[i];
|
|
681
|
+
if (this.hasAttribute(o)) {
|
|
682
|
+
const d = this.getAttribute(o);
|
|
683
|
+
this.$data[i] = W(this, w, it).call(this, d, f, a);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
W(this, w, U).call(this);
|
|
687
|
+
}
|
|
688
|
+
disconnectedCallback() {
|
|
689
|
+
var n;
|
|
690
|
+
this.isConnected && (this.unmounted(), (n = x(this, _)) == null || n.call(this), k(this, _, void 0));
|
|
403
691
|
}
|
|
692
|
+
attributeChangedCallback(n, s, r) {
|
|
693
|
+
if (s === r || !j(this.$data)) return;
|
|
694
|
+
const o = n.replace(/-([a-z])/g, (i, f) => f.toUpperCase()), a = this.$data[o];
|
|
695
|
+
this.$data[o] = W(this, w, it).call(this, r, a);
|
|
696
|
+
}
|
|
697
|
+
// ---------------------- 自定义生命周期钩子 ----------------------
|
|
698
|
+
/** 兼容旧组件的初始化钩子(首次 mounted 后调用) */
|
|
404
699
|
onInit() {
|
|
405
700
|
}
|
|
406
|
-
|
|
701
|
+
/** 组件创建完成(构造函数结束时调用) */
|
|
702
|
+
created() {
|
|
703
|
+
}
|
|
704
|
+
/** 组件首次挂载到 DOM 后调用 */
|
|
705
|
+
mounted() {
|
|
706
|
+
}
|
|
707
|
+
/** 每次更新前调用 */
|
|
708
|
+
beforeUpdate() {
|
|
709
|
+
}
|
|
710
|
+
/** 每次更新完成后调用 */
|
|
711
|
+
updated() {
|
|
712
|
+
}
|
|
713
|
+
/** 组件从 DOM 中卸载时调用 */
|
|
714
|
+
unmounted() {
|
|
407
715
|
}
|
|
408
716
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
717
|
+
V = new WeakMap(), z = new WeakMap(), G = new WeakMap(), L = new WeakMap(), K = new WeakMap(), D = new WeakMap(), _ = new WeakMap(), w = new WeakSet(), // ---------------------- 渲染核心逻辑 ----------------------
|
|
718
|
+
/** 内部刷新函数,由 observe() 或外部调用触发 */
|
|
719
|
+
U = function() {
|
|
720
|
+
x(this, L) || (k(this, L, !0), Dt(() => {
|
|
721
|
+
var n;
|
|
722
|
+
if (!this.isConnected) {
|
|
723
|
+
k(this, L, !1);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
this.beforeUpdate(), k(this, G, Ct(x(this, D), x(this, z), x(this, G))), k(this, L, !1), x(this, K) ? this.updated() : (k(this, K, !0), this.mounted(), (n = this.onInit) == null || n.call(this));
|
|
412
727
|
}));
|
|
728
|
+
}, // ---------------------- 属性类型转换工具 ----------------------
|
|
729
|
+
it = function(n, s, r) {
|
|
730
|
+
if (n === null) return s;
|
|
731
|
+
switch (r || typeof s) {
|
|
732
|
+
case "number":
|
|
733
|
+
const a = Number(n);
|
|
734
|
+
return isNaN(a) ? s : a;
|
|
735
|
+
case "boolean":
|
|
736
|
+
return n === "true";
|
|
737
|
+
case "object":
|
|
738
|
+
try {
|
|
739
|
+
return JSON.parse(n);
|
|
740
|
+
} catch {
|
|
741
|
+
return s;
|
|
742
|
+
}
|
|
743
|
+
default:
|
|
744
|
+
return n;
|
|
745
|
+
}
|
|
413
746
|
};
|
|
414
|
-
const
|
|
415
|
-
if (customElements.get(
|
|
416
|
-
console.warn(`标签名称 "${
|
|
747
|
+
const ee = (t) => (e) => {
|
|
748
|
+
if (customElements.get(t.tagName)) {
|
|
749
|
+
console.warn(`标签名称 "${t.tagName}" 已经被注册`);
|
|
417
750
|
return;
|
|
418
751
|
}
|
|
419
|
-
return
|
|
420
|
-
},
|
|
752
|
+
return e.prototype._manifest = ne(t), customElements.define(t.tagName, e), e;
|
|
753
|
+
}, ne = (t) => (t = Object.assign({
|
|
421
754
|
hasConfig: !1
|
|
422
|
-
},
|
|
423
|
-
var
|
|
424
|
-
throw TypeError(
|
|
425
|
-
},
|
|
426
|
-
for (var r = s > 1 ? void 0 : s ?
|
|
427
|
-
(
|
|
428
|
-
return
|
|
429
|
-
},
|
|
430
|
-
|
|
755
|
+
}, t), t);
|
|
756
|
+
var se = Object.getOwnPropertyDescriptor, xt = (t) => {
|
|
757
|
+
throw TypeError(t);
|
|
758
|
+
}, re = (t, e, n, s) => {
|
|
759
|
+
for (var r = s > 1 ? void 0 : s ? se(e, n) : e, o = t.length - 1, a; o >= 0; o--)
|
|
760
|
+
(a = t[o]) && (r = a(r) || r);
|
|
761
|
+
return r;
|
|
762
|
+
}, ht = (t, e, n) => e.has(t) || xt("Cannot " + n), P = (t, e, n) => (ht(t, e, "read from private field"), n ? n.call(t) : e.get(t)), I = (t, e, n) => e.has(t) ? xt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), T = (t, e, n, s) => (ht(t, e, "write to private field"), e.set(t, n), n), oe = (t, e, n) => (ht(t, e, "access private method"), n), Y, tt, et, B, q, X, Z, ct, wt;
|
|
763
|
+
function dt(t) {
|
|
764
|
+
return t instanceof HTMLElement && t.isRouterView === !0;
|
|
765
|
+
}
|
|
766
|
+
let mt = class extends HTMLElement {
|
|
431
767
|
constructor() {
|
|
432
|
-
super(...arguments),
|
|
768
|
+
super(...arguments), I(this, ct), I(this, Y, []), I(this, tt, []), I(this, et, null), I(this, B), I(this, q, []), I(this, X, {}), I(this, Z, this.onHashChange.bind(this));
|
|
433
769
|
}
|
|
770
|
+
// #endregion
|
|
771
|
+
// #region 公共属性和访问器
|
|
434
772
|
get isRouterView() {
|
|
435
773
|
return !0;
|
|
436
774
|
}
|
|
437
775
|
get $routes() {
|
|
438
|
-
return
|
|
776
|
+
return P(this, q);
|
|
439
777
|
}
|
|
440
|
-
set $routes(
|
|
441
|
-
|
|
778
|
+
set $routes(t) {
|
|
779
|
+
T(this, q, t), this.onHashChange();
|
|
442
780
|
}
|
|
443
781
|
get $remainingPath() {
|
|
444
|
-
return
|
|
782
|
+
return P(this, tt);
|
|
445
783
|
}
|
|
446
784
|
get $matchedRoute() {
|
|
447
|
-
return
|
|
785
|
+
return P(this, et);
|
|
448
786
|
}
|
|
449
|
-
set $pipe(
|
|
450
|
-
|
|
787
|
+
set $pipe(t) {
|
|
788
|
+
T(this, X, t || {}), this.onHashChange();
|
|
451
789
|
}
|
|
790
|
+
// #endregion
|
|
791
|
+
// #region 生命周期回调
|
|
452
792
|
connectedCallback() {
|
|
453
|
-
window.addEventListener("hashchange",
|
|
793
|
+
window.addEventListener("hashchange", P(this, Z)), this.onHashChange();
|
|
454
794
|
}
|
|
455
795
|
disconnectedCallback() {
|
|
456
|
-
window.removeEventListener("hashchange",
|
|
796
|
+
window.removeEventListener("hashchange", P(this, Z));
|
|
457
797
|
}
|
|
798
|
+
// #endregion
|
|
799
|
+
/**
|
|
800
|
+
* Hash 变化时的核心处理函数
|
|
801
|
+
*/
|
|
458
802
|
onHashChange() {
|
|
459
|
-
var
|
|
803
|
+
var e;
|
|
460
804
|
if (!this.isConnected) return;
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
805
|
+
const t = this.findAncestorRouterView();
|
|
806
|
+
if (t)
|
|
807
|
+
T(this, B, t.$remainingPath), T(this, q, ((e = t.$matchedRoute) == null ? void 0 : e.children) || []);
|
|
808
|
+
else {
|
|
809
|
+
const { path: n } = te(window.location);
|
|
810
|
+
T(this, B, n);
|
|
811
|
+
}
|
|
812
|
+
oe(this, ct, wt).call(this);
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* 准备传递给子组件的 props 和事件监听
|
|
816
|
+
* @param params 从路由中解析出的参数
|
|
817
|
+
* @returns 包含 props 和 on 的对象
|
|
818
|
+
*/
|
|
819
|
+
prepareComponentData(t) {
|
|
820
|
+
const e = {}, n = {};
|
|
821
|
+
for (const [s, r] of Object.entries(t))
|
|
822
|
+
e[s] = () => r;
|
|
823
|
+
for (const [s, r] of Object.entries(P(this, X))) {
|
|
824
|
+
const o = s.toLowerCase();
|
|
825
|
+
let a = null;
|
|
826
|
+
o.startsWith("on-") ? a = o.slice(3) : o.startsWith("on") && gt.includes(o.slice(2)) && (a = o.slice(2)), a ? n[a] = r : e[s] = () => r;
|
|
827
|
+
}
|
|
828
|
+
return { props: e, on: n };
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* 在路由表中查找与当前路径匹配的路由
|
|
832
|
+
* @param routes 路由配置数组
|
|
833
|
+
* @param pathSegments URL 路径分段数组
|
|
834
|
+
* @returns 匹配结果
|
|
835
|
+
*/
|
|
836
|
+
matchRoute(t, e) {
|
|
837
|
+
for (const n of t) {
|
|
838
|
+
const s = n.path.split("/").filter((a) => a), r = {};
|
|
839
|
+
if (s.length > e.length && !s.includes("*"))
|
|
840
|
+
continue;
|
|
841
|
+
let o = !0;
|
|
842
|
+
for (let a = 0; a < s.length; a++) {
|
|
843
|
+
const i = s[a], f = e[a];
|
|
471
844
|
if (i.startsWith(":"))
|
|
472
|
-
|
|
473
|
-
else
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
845
|
+
r[i.substring(1)] = f;
|
|
846
|
+
else {
|
|
847
|
+
if (i === "*")
|
|
848
|
+
return {
|
|
849
|
+
matchedRoute: n,
|
|
850
|
+
params: r,
|
|
851
|
+
remainingPath: []
|
|
852
|
+
// 通配符消耗所有剩余路径
|
|
853
|
+
};
|
|
854
|
+
if (i !== f) {
|
|
855
|
+
o = !1;
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
479
858
|
}
|
|
480
859
|
}
|
|
481
|
-
if (
|
|
860
|
+
if (o)
|
|
482
861
|
return {
|
|
483
862
|
matchedRoute: n,
|
|
484
|
-
params:
|
|
485
|
-
remainingPath:
|
|
863
|
+
params: r,
|
|
864
|
+
remainingPath: e.slice(s.length)
|
|
486
865
|
};
|
|
487
866
|
}
|
|
488
|
-
return {
|
|
489
|
-
matchedRoute: null,
|
|
490
|
-
params: {},
|
|
491
|
-
remainingPath: t
|
|
492
|
-
};
|
|
867
|
+
return { matchedRoute: null, params: {}, remainingPath: e };
|
|
493
868
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
869
|
+
/**
|
|
870
|
+
* 递归通知所有子节点中的 router-view 进行更新
|
|
871
|
+
* @param node 当前遍历的起始节点
|
|
872
|
+
*/
|
|
873
|
+
propagateToChildRouterViews(t = this) {
|
|
874
|
+
for (const e of t.childNodes)
|
|
875
|
+
dt(e) ? e.onHashChange() : this.propagateToChildRouterViews(e);
|
|
497
876
|
}
|
|
498
|
-
|
|
499
|
-
|
|
877
|
+
/**
|
|
878
|
+
* 沿 DOM 树向上查找最近的父 router-view 实例
|
|
879
|
+
* @returns 父 RouterViewElement 实例或 null
|
|
880
|
+
*/
|
|
881
|
+
findAncestorRouterView() {
|
|
882
|
+
let t = this.parentElement;
|
|
500
883
|
for (; t; ) {
|
|
501
|
-
if (t
|
|
884
|
+
if (dt(t))
|
|
502
885
|
return t;
|
|
503
886
|
t = t.parentElement;
|
|
504
887
|
}
|
|
505
888
|
return null;
|
|
506
889
|
}
|
|
507
890
|
};
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
const r = (
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
rootId: 0,
|
|
528
|
-
attrs: {},
|
|
529
|
-
props: a,
|
|
530
|
-
on: o,
|
|
531
|
-
children: []
|
|
532
|
-
}
|
|
533
|
-
];
|
|
534
|
-
((h = E(this, A)) == null ? void 0 : h.tagName) !== r ? (this.innerHTML = "", p(this, k, z(this, i, []))) : p(this, k, z(this, i, E(this, k))), p(this, A, t || {
|
|
535
|
-
tagName: "comment",
|
|
536
|
-
path: "",
|
|
891
|
+
Y = /* @__PURE__ */ new WeakMap();
|
|
892
|
+
tt = /* @__PURE__ */ new WeakMap();
|
|
893
|
+
et = /* @__PURE__ */ new WeakMap();
|
|
894
|
+
B = /* @__PURE__ */ new WeakMap();
|
|
895
|
+
q = /* @__PURE__ */ new WeakMap();
|
|
896
|
+
X = /* @__PURE__ */ new WeakMap();
|
|
897
|
+
Z = /* @__PURE__ */ new WeakMap();
|
|
898
|
+
ct = /* @__PURE__ */ new WeakSet();
|
|
899
|
+
wt = function() {
|
|
900
|
+
const t = P(this, B) || [], { matchedRoute: e, params: n, remainingPath: s } = this.matchRoute(P(this, q), t);
|
|
901
|
+
T(this, tt, s), T(this, et, e);
|
|
902
|
+
const r = (e == null ? void 0 : e.tagName) || "comment", { props: o, on: a } = this.prepareComponentData(n);
|
|
903
|
+
T(this, Y, Ct(this, [{
|
|
904
|
+
tagName: r,
|
|
905
|
+
rootId: "0",
|
|
906
|
+
// 假设 rootId 是固定的
|
|
907
|
+
attrs: {},
|
|
908
|
+
props: o,
|
|
909
|
+
on: a,
|
|
537
910
|
children: []
|
|
538
|
-
}), this.
|
|
911
|
+
}], P(this, Y))), this.propagateToChildRouterViews();
|
|
539
912
|
};
|
|
540
|
-
|
|
541
|
-
|
|
913
|
+
mt = re([
|
|
914
|
+
ee({
|
|
542
915
|
tagName: "router-view"
|
|
543
916
|
})
|
|
544
|
-
],
|
|
917
|
+
], mt);
|
|
545
918
|
export {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
919
|
+
le as BaseElement,
|
|
920
|
+
ee as CustomElement,
|
|
921
|
+
mt as RouterViewElement,
|
|
922
|
+
lt as createFunction,
|
|
923
|
+
j as isObject,
|
|
924
|
+
gt as listeners,
|
|
925
|
+
pt as observe,
|
|
926
|
+
te as parseHashUrl,
|
|
927
|
+
Tt as parseHtml,
|
|
928
|
+
Ct as patch,
|
|
929
|
+
Dt as runInAsyncQueue
|
|
557
930
|
};
|