solely 0.0.23 → 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/dist/solely.js CHANGED
@@ -1,121 +1,228 @@
1
- var Q = (e) => {
2
- throw TypeError(e);
1
+ var ft = (t) => {
2
+ throw TypeError(t);
3
3
  };
4
- var V = (e, t, n) => t.has(e) || Q("Cannot " + n);
5
- var E = (e, t, n) => (V(e, t, "read from private field"), n ? n.call(e) : t.get(e)), m = (e, t, n) => t.has(e) ? Q("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), f = (e, t, n, s) => (V(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), M = (e, t, n) => (V(e, t, "access private method"), n);
6
- const ht = /<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g, ut = /<\/?([^\s]+?)[/\s>]/, ft = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g, pt = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"], F = /\{\{(.+?)\}\}/g;
7
- function mt(e) {
8
- return e.replace(/>\s+</g, "><").replace(/\s+/g, " ");
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 dt(e, t) {
11
- const n = (t.match(ut) || [])[1] || "", s = {
10
+ function jt(t, e) {
11
+ const n = (e.match(St) || [])[1] || "", s = {
12
12
  rootId: "0",
13
13
  tagName: n,
14
14
  attrs: {},
15
15
  props: {},
16
16
  on: {},
17
17
  children: []
18
- }, r = new RegExp(ft);
18
+ }, r = new RegExp(Wt);
19
19
  for (; ; ) {
20
- const a = r.exec(t);
21
- if (a === null) break;
22
- if (!a[0].trim()) continue;
23
- const [o, c] = a[1] ? a[1].trim().split("=") : [a[2], a[3].trim().slice(1, -1)];
24
- if (Z.includes(o) || o.startsWith("on-"))
25
- s.on[o.startsWith("on-") ? o.slice(3) : o.slice(2)] = K(e, c);
26
- else if (o.startsWith("s-")) {
27
- const h = o.slice(2);
28
- switch (h) {
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
- s.model = c;
32
+ s.model = i;
31
33
  break;
32
34
  case "style":
33
- s.styles = (i) => d(e, c, i);
35
+ s.styles = (d) => O(t, i, d);
34
36
  break;
35
37
  case "class":
36
- s.classes = (i) => d(e, c, i);
38
+ s.classes = (d) => O(t, i, d);
37
39
  break;
38
40
  case "readonly":
39
- s.props.readOnly = (i) => d(e, c, i);
41
+ s.props.readOnly = (d) => O(t, i, d);
40
42
  break;
41
43
  default:
42
- s.props[h] = (i) => d(e, c, i);
44
+ s.props[f] = (d) => O(t, i, d);
43
45
  break;
44
46
  }
45
47
  } else
46
- s.attrs[o] = c;
48
+ s.attrs[a] = i;
47
49
  r.lastIndex--;
48
50
  }
49
- if (n === "For" ? s.fn = (a) => d(e, s.attrs.each, a) : (n === "If" || n === "ElseIf") && (s.fn = (a) => d(e, s.attrs.condition, a)), s.model) {
50
- const a = s.model.replace("this.", "").replace("$data.", ""), o = (h) => d(e, `$data.${a}`, h), c = (h) => K(e, `$data.${a}=${h}`);
51
- n === "input" ? s.attrs.type === "checkbox" || s.attrs.type === "radio" ? (s.props.checked = o, s.on.change = c("checked")) : (s.props.value = o, s.on.input = c("value")) : n === "textarea" ? (s.props.value = o, s.on.input = c("value")) : n === "select" && (s.props.value = o, s.on.change = c("value"));
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 gt(e, t) {
100
+ function Tt(t, e) {
56
101
  const n = [];
57
- if (!t) return n;
58
- t = mt(t);
59
- const s = [], r = [], a = () => {
60
- var c;
61
- return s.length === 0 ? n : (c = s[s.length - 1]).children || (c.children = []);
102
+ if (!e) return n;
103
+ e = Ot(e);
104
+ const s = [], r = [], o = () => {
105
+ var i;
106
+ return s.length === 0 ? n : (i = s[s.length - 1]).children || (i.children = []);
62
107
  };
63
- let o = 0;
64
- return t.replace(ht, (c, h) => {
65
- const i = a();
66
- if (h > o) {
67
- const l = t.substring(o, h).trim();
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();
68
113
  if (l) {
69
- F.lastIndex = 0;
70
- const P = !F.test(l) ? l : (W) => l.replace(F, (T, D) => d(e, D, W));
71
- i.push({
114
+ rt.lastIndex = 0;
115
+ const u = !rt.test(l) ? l : (p) => l.replace(rt, ($, A) => O(t, A, p));
116
+ d.push({
72
117
  rootId: "0",
73
118
  tagName: "text",
74
119
  attrs: {},
75
120
  props: {},
76
121
  on: {},
77
- content: P,
122
+ content: u,
78
123
  children: []
79
124
  });
80
125
  }
81
126
  }
82
- if (o = h + c.length, c.startsWith("<!--") && c.endsWith("-->"))
83
- i.push({
127
+ if (a = f + i.length, i.startsWith("<!--") && i.endsWith("-->"))
128
+ d.push({
84
129
  rootId: "0",
85
130
  tagName: "comment",
86
131
  attrs: {},
87
132
  props: {},
88
133
  on: {},
89
- content: c.slice(4, -3),
134
+ content: i.slice(4, -3),
90
135
  children: []
91
136
  });
92
- else if (c.startsWith("</")) {
137
+ else if (i.startsWith("</")) {
93
138
  const l = r.pop();
94
139
  for (; s.length > 0 && s[s.length - 1].tagName !== l; )
95
140
  s.pop();
96
141
  s.pop();
97
142
  } else {
98
- const l = dt(e, c), u = c.endsWith("/>") || pt.includes(l.tagName);
99
- i.push(l), u || (s.push(l), r.push(l.tagName));
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
- }), t.length > o && n.push({
147
+ }), e.length > a && n.push({
103
148
  rootId: "0",
104
149
  tagName: "text",
105
150
  attrs: {},
106
151
  props: {},
107
152
  on: {},
108
- content: t.substring(o).trim(),
153
+ content: e.substring(a).trim(),
109
154
  children: []
110
155
  }), n;
111
156
  }
112
- const d = (e, t, n) => {
157
+ const O = (t, e, n) => {
113
158
  try {
114
- return J(["$data", ...n.map((r) => r.item), ...n.map((r) => r.index), `return (${t})`]).bind(e)(e.$data, ...n.map((r) => r.value), ...n.map((r) => r.valueIndex));
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(s);
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
- }, K = (e, t) => (n, s) => J(["$data", "event", "value", "checked", ...s.map((a) => a.item), ...s.map((a) => a.index), t]).bind(e)(e.$data, n, n.target.value, n.target.checked, ...s.map((a) => a.value), ...s.map((a) => a.valueIndex)), Z = [
225
+ }, gt = [
119
226
  "onabort",
120
227
  "onautocomplete",
121
228
  "onautocompleteerror",
@@ -178,388 +285,646 @@ const d = (e, t, n) => {
178
285
  "ontoggle",
179
286
  "onvolumechange",
180
287
  "onwaiting"
181
- ], Et = /* @__PURE__ */ (() => {
182
- const e = typeof requestAnimationFrame == "function" ? (t) => requestAnimationFrame(t) : typeof Promise < "u" ? (t) => Promise.resolve().then(t) : (t) => setTimeout(t, 0);
183
- return (t, ...n) => {
184
- if (typeof t != "function")
185
- throw new Error("runInAsyncQueue expects a function as its first argument");
186
- e(() => t(...n));
187
- };
188
- })(), j = {};
189
- function J(e) {
190
- const t = e.map((n) => n.replace(/[',"]/g, "")).join(",");
191
- if (!j[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 (yt(n))
299
+ if (Ut(n))
196
300
  throw new Error("Input contains potentially dangerous code: " + n);
197
- j[t] = new Function(...e);
301
+ ot[e] = new Function(...t);
198
302
  }
199
- return j[t];
303
+ return ot[e];
200
304
  }
201
- const vt = ["eval", "Function", "process", "require"];
202
- function yt(e) {
203
- return vt.some((t) => new RegExp(`\\b${t}\\b`, "g").test(e));
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 bt = "http://www.w3.org/1999/xlink", wt = "http://www.w3.org/2000/xmlns/", $t = "http://www.w3.org/XML/1998/namespace", kt = "http://www.w3.org/2000/svg", Y = (e) => typeof e.content == "function" ? e.content(e.loops || []) : e.content || "", _t = (e) => {
206
- const t = Y(e), n = e.elm;
207
- n.textContent !== t && (n.textContent = t);
208
- }, tt = (e, t, n = []) => {
209
- Object.keys(t).forEach((s) => {
210
- const r = t[s](n);
211
- e[s] !== r && (e[s] = r);
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
- }, et = (e, t) => {
214
- const { styles: n, loops: s = [] } = t;
317
+ }, vt = (t, e) => {
318
+ const { styles: n, loops: s = [] } = e;
215
319
  if (!n) return;
216
- const r = n(s), a = q(r);
217
- Object.entries(a).forEach(([o, c]) => {
218
- e.style[o] = c;
320
+ const r = n(s), o = at(r);
321
+ Object.entries(o).forEach(([a, i]) => {
322
+ t.style[a] = i;
219
323
  });
220
- }, nt = (e, t) => {
221
- const { classes: n, loops: s = [] } = t;
324
+ }, $t = (t, e) => {
325
+ const { classes: n, loops: s = [] } = e;
222
326
  if (!n) return;
223
- const r = n(s), a = st(r);
224
- Object.entries(a).forEach(([o, c]) => {
225
- c ? e.classList.add(o) : e.classList.remove(o);
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
- }, q = (e) => {
228
- let t = {};
229
- return typeof e == "object" && e !== null && !Array.isArray(e) ? Object.entries(e).forEach(([n, s]) => {
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 = q(s);
232
- Object.entries(r).forEach(([a, o]) => {
233
- t[`${n}-${a}`] = o;
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" ? t[n] = `${s}` : t[n] = String(s);
236
- }) : typeof e == "string" ? e.split(";").forEach((n) => {
237
- const [s, r] = n.split(":").map((a) => a.trim());
238
- s && r && (t[s] = r);
239
- }) : Array.isArray(e) && e.forEach((n) => {
240
- const s = q(n);
241
- Object.entries(s).forEach(([r, a]) => {
242
- t[r] = a;
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
- }), t;
245
- }, st = (e) => {
246
- let t = {};
247
- return typeof e == "object" && !Array.isArray(e) ? Object.entries(e).forEach(([n, s]) => {
248
- t[n] = !!s;
249
- }) : typeof e == "string" ? e.split(" ").forEach((n) => {
250
- n !== "" && (t[n] = !0);
251
- }) : Array.isArray(e) && e.forEach((n) => {
252
- const s = st(n);
253
- Object.entries(s).forEach(([r, a]) => {
254
- t[r] = a;
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
- }), t;
257
- }, rt = (e, t, n) => {
258
- const s = (r) => n.on[t](r, n.loops || []);
259
- e.addEventListener(t, s, !1), n.handlers = n.handlers || {}, n.handlers[t] = s;
260
- }, Ct = (e, t) => {
261
- const n = t.elm;
262
- Object.keys(t.on).forEach((s) => {
263
- e.handlers && e.handlers[s] && n.removeEventListener(s, e.handlers[s], !1), rt(n, s, t);
264
- }), tt(n, t.props, t.loops), nt(n, t), et(n, t), at(n, e.children, t.children);
265
- }, xt = (e, t) => {
266
- switch (t.elm = e.elm, t.tagName) {
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
- _t(t);
376
+ Gt(e);
271
377
  break;
272
378
  case "slot":
273
379
  break;
274
380
  default:
275
- Ct(e, t);
381
+ Kt(t, e);
276
382
  break;
277
383
  }
278
- }, B = (e, t, n) => {
279
- n ? e.insertBefore(t, n) : e.appendChild(t);
280
- }, At = (e, t, n) => {
281
- const s = Y(t), r = document.createTextNode(s);
282
- t.elm = r, B(e, r, n);
283
- }, Rt = (e, t, n) => {
284
- const s = t.content, r = document.createComment(s);
285
- t.elm = r, B(e, r, n);
286
- }, It = (e, t, n, s) => {
287
- t.tagName === "svg" && (s = kt);
288
- const r = s ? document.createElementNS(s, t.tagName) : document.createElement(t.tagName);
289
- Object.keys(t.attrs).forEach((a) => {
290
- const o = t.attrs[a] || "";
291
- a.charAt(0) !== "x" ? r.setAttribute(a, o) : a.startsWith("xml:") ? r.setAttributeNS($t, a, o) : a.startsWith("xlink:") ? r.setAttributeNS(bt, a, o) : a.startsWith("xmlns:") ? r.setAttributeNS(wt, a, o) : r.setAttribute(a, o);
292
- }), Object.keys(t.on).forEach((a) => {
293
- rt(r, a, t);
294
- }), tt(r, t.props, t.loops), nt(r, t), et(r, t), t.elm = r, B(e, r, n), t.tagName === "foreignObject" && (s = void 0), t.children.forEach((a) => {
295
- N(r, a, void 0, s);
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
- }, N = (e, t, n, s) => {
298
- switch (t.tagName) {
405
+ }, N = (t, e, n, s) => {
406
+ switch (e.tagName) {
299
407
  case "comment":
300
- Rt(e, t, n);
408
+ Nt(t, e, n);
301
409
  break;
302
410
  case "text":
303
- At(e, t, n);
411
+ Jt(t, e, n);
304
412
  break;
305
413
  default:
306
- It(e, t, n, s);
414
+ Xt(t, e, n, s);
307
415
  break;
308
416
  }
309
- }, St = (e) => e && (e.tagName === "ElseIf" || e.tagName === "comment"), Wt = (e) => e && e.tagName === "Else", y = (e, t, n = [], s = "0", r) => {
310
- var a, o, c;
311
- for (let h = 0; h < t.length; h++) {
312
- const i = t[h];
313
- if (i.tagName === "If") {
314
- let l = !1, u = 1;
315
- for (((a = i.fn) == null ? void 0 : a.call(i, n)) && (y(e, i.children, n, `${s}-if-${u}`, u), l = !0), u++; h + 1 < t.length && St(t[h + 1]); )
316
- ((c = (o = t[h + 1]).fn) == null ? void 0 : c.call(o, n)) && !l && (y(e, t[h + 1].children, n, `${s}-if-${u}`, u), l = !0), h++, u++;
317
- h + 1 < t.length && Wt(t[h + 1]) && (l || (y(e, t[h + 1].children, n, `${s}-if-${u}`, u), l = !0), h++);
318
- } else if (i.tagName === "For") {
319
- const { item: l = "item", index: u = "index" } = i.attrs;
320
- (i.fn(n) || []).forEach((W, T) => {
321
- const D = { item: l, value: W, index: u, valueIndex: T };
322
- y(e, i.children, [...n, D], `${s}-for-${T}`, 1);
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];
422
+ if (c.tagName === "If") {
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++);
429
+ } else if (c.tagName === "For") {
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
- const l = {
326
- ...i,
437
+ const u = {
438
+ ...c,
327
439
  loops: n,
328
440
  children: [],
329
441
  rootId: s,
330
442
  ifId: r,
331
- key: i.key || `${s}-${h}`
443
+ key: c.key || `${s}-${l}`
332
444
  // 添加 key 属性
333
445
  };
334
- y(l.children, i.children, n, `${s}-${h}`), e.push(l);
446
+ F(u.children, c.children, n, `${s}-${l}`), t.push(u);
335
447
  }
336
448
  }
337
- }, at = (e, t, n) => {
338
- var o, c, h;
449
+ }, At = (t, e, n) => {
450
+ var a, i, f, d, l;
339
451
  const s = /* @__PURE__ */ new Map();
340
- t.forEach((i, l) => s.set(i.key, { node: i, index: l }));
341
- let r = 0, a = 0;
452
+ e.forEach((c, u) => s.set(c.key, { node: c, index: u }));
453
+ let r = 0, o = 0;
342
454
  for (; r < n.length; ) {
343
- const i = n[r], l = s.get(i.key);
344
- if (l) {
345
- const u = l.node;
346
- i.ifId && u.ifId !== i.ifId ? ((o = u.elm) == null || o.remove(), N(e, i, (c = t[a + 1]) == null ? void 0 : c.elm)) : xt(u, i), s.delete(i.key), a++;
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
+ }
347
471
  } else {
348
- const u = (h = t[a]) == null ? void 0 : h.elm;
349
- N(e, i, u);
472
+ const p = (l = e[o]) == null ? void 0 : l.elm;
473
+ N(t, c, p);
350
474
  }
351
475
  r++;
352
476
  }
353
- s.forEach(({ node: i }) => {
354
- var l;
355
- return (l = i.elm) == null ? void 0 : l.remove();
477
+ s.forEach(({ node: c }) => {
478
+ var u;
479
+ return (u = c.elm) == null ? void 0 : u.remove();
356
480
  });
357
- }, U = (e, t, n = []) => {
358
- if (!t || t.length === 0) return [];
481
+ }, Ct = (t, e, n = []) => {
482
+ if (!e || e.length === 0) return [];
359
483
  const s = [];
360
- return y(s, t || [], [], "0"), at(e, n, s), s;
361
- }, ot = (e) => typeof e == "object" && e != null;
362
- function Mt(e = window.location) {
363
- let t;
364
- typeof e == "string" ? t = new URL(e).hash : t = e.hash;
365
- const n = t.split("?"), s = n[0].substring(2), r = n[1], a = {};
366
- return r && r.split("&").forEach((o) => {
367
- const [c, h] = o.split("=");
368
- c && h && (a[decodeURIComponent(c)] = decodeURIComponent(h));
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));
369
505
  }), {
370
506
  path: s.split("/"),
371
507
  // 将路径分割成数组
372
- query: a
508
+ query: o
373
509
  // 查询参数对象
374
510
  };
375
511
  }
376
- const it = (e, t) => new Proxy(e, {
377
- get: (n, s) => {
378
- let r = n[s];
379
- return ot(r) && (r = it(r, t)), r;
380
- },
381
- set: (n, s, r) => (n[s] !== r && (n[s] = r, t(s, r)), !0)
382
- });
383
- var A, R, I, w, S, $, k, H;
384
- class Ft extends HTMLElement {
385
- constructor() {
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;
386
627
  super();
387
- m(this, k);
388
- m(this, A, {});
389
- m(this, R, []);
390
- m(this, I, []);
391
- m(this, w, !1);
392
- m(this, S, !1);
393
- m(this, $);
394
- const n = this._manifest || {};
395
- n.template && typeof n.template == "string" && f(this, R, gt(this, n.template)), n.shadowDOM && n.shadowDOM.use ? f(this, $, this.attachShadow({
396
- mode: n.shadowDOM.mode || "open"
397
- })) : f(this, $, this);
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());
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) : [];
398
652
  }
653
+ // ---------------------- $data getter/setter ----------------------
654
+ /** 获取当前组件数据 */
399
655
  get $data() {
400
- let n = E(this, A);
401
- return ot(n) && (n = it(n, () => M(this, k, H).call(this))), n;
656
+ return x(this, V);
402
657
  }
658
+ /** 更新组件数据 */
403
659
  set $data(n) {
404
- f(this, A, n || {}), M(this, k, H).call(this);
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);
405
663
  }
664
+ /**
665
+ * 手动刷新组件
666
+ * 外部可调用,用于数据未触发 observe 或强制刷新
667
+ */
668
+ refresh() {
669
+ W(this, w, U).call(this);
670
+ }
671
+ // ---------------------- Web Components 生命周期 ----------------------
406
672
  connectedCallback() {
407
673
  const n = this._manifest || {};
408
- (n.className || n.tagName || "").split(" ").forEach((r) => {
409
- r && this.classList.add(r);
410
- }), M(this, k, H).call(this);
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));
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);
411
696
  }
697
+ // ---------------------- 自定义生命周期钩子 ----------------------
698
+ /** 兼容旧组件的初始化钩子(首次 mounted 后调用) */
412
699
  onInit() {
413
700
  }
414
- disconnectedCallback() {
701
+ /** 组件创建完成(构造函数结束时调用) */
702
+ created() {
703
+ }
704
+ /** 组件首次挂载到 DOM 后调用 */
705
+ mounted() {
706
+ }
707
+ /** 每次更新前调用 */
708
+ beforeUpdate() {
709
+ }
710
+ /** 每次更新完成后调用 */
711
+ updated() {
712
+ }
713
+ /** 组件从 DOM 中卸载时调用 */
714
+ unmounted() {
415
715
  }
416
716
  }
417
- A = new WeakMap(), R = new WeakMap(), I = new WeakMap(), w = new WeakMap(), S = new WeakMap(), $ = new WeakMap(), k = new WeakSet(), H = function() {
418
- E(this, w) || (f(this, w, !0), Et(() => {
419
- f(this, I, U(E(this, $), E(this, R), E(this, I))), f(this, w, !1), this.isConnected && !E(this, S) && (f(this, S, !0), this.onInit());
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));
420
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
+ }
421
746
  };
422
- const Ht = (e) => (t) => {
423
- if (customElements.get(e.tagName)) {
424
- console.warn(`标签名称 "${e.tagName}" 已经被注册`);
747
+ const ee = (t) => (e) => {
748
+ if (customElements.get(t.tagName)) {
749
+ console.warn(`标签名称 "${t.tagName}" 已经被注册`);
425
750
  return;
426
751
  }
427
- return t.prototype._manifest = Ot(e), customElements.define(e.tagName, t), t;
428
- }, Ot = (e) => (e = Object.assign({
752
+ return e.prototype._manifest = ne(t), customElements.define(t.tagName, e), e;
753
+ }, ne = (t) => (t = Object.assign({
429
754
  hasConfig: !1
430
- }, e), e);
431
- var Lt = Object.defineProperty, Pt = Object.getOwnPropertyDescriptor, ct = (e) => {
432
- throw TypeError(e);
433
- }, Tt = (e, t, n, s) => {
434
- for (var r = s > 1 ? void 0 : s ? Pt(t, n) : t, a = e.length - 1, o; a >= 0; a--)
435
- (o = e[a]) && (r = (s ? o(t, n, r) : o(r)) || r);
436
- return s && r && Lt(t, n, r), r;
437
- }, G = (e, t, n) => t.has(e) || ct("Cannot " + n), g = (e, t, n) => (G(e, t, "read from private field"), n ? n.call(e) : t.get(e)), v = (e, t, n) => t.has(e) ? ct("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), p = (e, t, n, s) => (G(e, t, "write to private field"), t.set(e, n), n), Dt = (e, t, n) => (G(e, t, "access private method"), n), _, O, x, C, b, L, z, lt;
438
- let X = class extends HTMLElement {
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 {
439
767
  constructor() {
440
- super(...arguments), v(this, z), v(this, _, []), v(this, O, []), v(this, x, null), v(this, C), v(this, b, []), v(this, L, {});
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));
441
769
  }
770
+ // #endregion
771
+ // #region 公共属性和访问器
442
772
  get isRouterView() {
443
773
  return !0;
444
774
  }
445
775
  get $routes() {
446
- return g(this, b);
776
+ return P(this, q);
447
777
  }
448
- set $routes(e) {
449
- p(this, b, e), this.onHashChange();
778
+ set $routes(t) {
779
+ T(this, q, t), this.onHashChange();
450
780
  }
451
781
  get $remainingPath() {
452
- return g(this, O);
782
+ return P(this, tt);
453
783
  }
454
784
  get $matchedRoute() {
455
- return g(this, x);
785
+ return P(this, et);
456
786
  }
457
- set $pipe(e) {
458
- p(this, L, e || {}), this.onHashChange();
787
+ set $pipe(t) {
788
+ T(this, X, t || {}), this.onHashChange();
459
789
  }
790
+ // #endregion
791
+ // #region 生命周期回调
460
792
  connectedCallback() {
461
- window.addEventListener("hashchange", this.onHashChange.bind(this)), this.onHashChange();
793
+ window.addEventListener("hashchange", P(this, Z)), this.onHashChange();
462
794
  }
463
795
  disconnectedCallback() {
464
- window.removeEventListener("hashchange", this.onHashChange.bind(this));
796
+ window.removeEventListener("hashchange", P(this, Z));
465
797
  }
798
+ // #endregion
799
+ /**
800
+ * Hash 变化时的核心处理函数
801
+ */
466
802
  onHashChange() {
467
- var n;
803
+ var e;
468
804
  if (!this.isConnected) return;
469
- const { path: e } = Mt(window.location), t = this.findAncestorWithRouterView(this);
470
- t ? (p(this, C, t.$remainingPath), p(this, b, ((n = t.$matchedRoute) == null ? void 0 : n.children) || [])) : p(this, C, e), Dt(this, z, lt).call(this);
471
- }
472
- matchRoute(e, t) {
473
- for (const n of e) {
474
- const s = n.path.split("/");
475
- let r = !0;
476
- const a = {};
477
- for (let o = 0; o < s.length; o++) {
478
- const c = s[o];
479
- if (c.startsWith(":"))
480
- a[c.substring(1)] = t[o];
481
- else if (c === "*") {
482
- r = !0;
483
- break;
484
- } else if (c !== t[o]) {
485
- r = !1;
486
- break;
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];
844
+ if (i.startsWith(":"))
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
+ }
487
858
  }
488
859
  }
489
- if (r)
860
+ if (o)
490
861
  return {
491
862
  matchedRoute: n,
492
- params: a,
493
- remainingPath: t.slice(s.length)
863
+ params: r,
864
+ remainingPath: e.slice(s.length)
494
865
  };
495
866
  }
496
- return {
497
- matchedRoute: null,
498
- params: {},
499
- remainingPath: t
500
- };
867
+ return { matchedRoute: null, params: {}, remainingPath: e };
501
868
  }
502
- propagateRoutes(e) {
503
- for (const t of e.childNodes)
504
- t.isRouterView ? t.onHashChange() : this.propagateRoutes(t);
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);
505
876
  }
506
- findAncestorWithRouterView(e) {
507
- let t = e.parentNode;
877
+ /**
878
+ * 沿 DOM 树向上查找最近的父 router-view 实例
879
+ * @returns 父 RouterViewElement 实例或 null
880
+ */
881
+ findAncestorRouterView() {
882
+ let t = this.parentElement;
508
883
  for (; t; ) {
509
- if (t.isRouterView)
884
+ if (dt(t))
510
885
  return t;
511
886
  t = t.parentElement;
512
887
  }
513
888
  return null;
514
889
  }
515
890
  };
516
- _ = /* @__PURE__ */ new WeakMap();
517
- O = /* @__PURE__ */ new WeakMap();
518
- x = /* @__PURE__ */ new WeakMap();
519
- C = /* @__PURE__ */ new WeakMap();
520
- b = /* @__PURE__ */ new WeakMap();
521
- L = /* @__PURE__ */ new WeakMap();
522
- z = /* @__PURE__ */ new WeakSet();
523
- lt = function() {
524
- var h;
525
- const e = g(this, C) || [], { matchedRoute: t, params: n, remainingPath: s } = this.matchRoute(g(this, b), e);
526
- p(this, O, s);
527
- const r = (t == null ? void 0 : t.tagName) || "comment", a = {}, o = {};
528
- for (const [i, l] of Object.entries(n))
529
- a[i] = () => l;
530
- for (const [i, l] of Object.entries(g(this, L)))
531
- Z.includes(i) || i.startsWith("on-") ? o[i.startsWith("on-") ? i.slice(3) : i.slice(2)] = l : a[i] = () => l;
532
- const c = [
533
- {
534
- tagName: r,
535
- rootId: "0",
536
- attrs: {},
537
- props: a,
538
- on: o,
539
- children: []
540
- }
541
- ];
542
- ((h = g(this, x)) == null ? void 0 : h.tagName) !== r ? (this.innerHTML = "", p(this, _, U(this, c, []))) : p(this, _, U(this, c, g(this, _))), p(this, x, t || {
543
- tagName: "comment",
544
- 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,
545
910
  children: []
546
- }), this.propagateRoutes(this);
911
+ }], P(this, Y))), this.propagateToChildRouterViews();
547
912
  };
548
- X = Tt([
549
- Ht({
913
+ mt = re([
914
+ ee({
550
915
  tagName: "router-view"
551
916
  })
552
- ], X);
917
+ ], mt);
553
918
  export {
554
- Ft as BaseElement,
555
- Ht as CustomElement,
556
- X as RouterViewElement,
557
- J as createFunction,
558
- ot as isObject,
559
- Z as listeners,
560
- it as observe,
561
- Mt as parseHashUrl,
562
- gt as parseHtml,
563
- U as patch,
564
- Et as runInAsyncQueue
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
565
930
  };