solely 0.0.23 → 0.0.29

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,644 @@ 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);
271
- break;
272
- case "slot":
376
+ Gt(e);
273
377
  break;
274
378
  default:
275
- Ct(e, t);
379
+ Kt(t, e);
276
380
  break;
277
381
  }
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);
382
+ }, ut = (t, e, n) => {
383
+ n && n.parentNode === t ? t.insertBefore(e, n) : t.appendChild(e);
384
+ }, Jt = (t, e, n) => {
385
+ const s = yt(e), r = document.createTextNode(s);
386
+ e.elm = r, ut(t, r, n);
387
+ }, Nt = (t, e, n) => {
388
+ const s = e.content, r = document.createComment(s);
389
+ e.elm = r, ut(t, r, n);
390
+ }, Xt = (t, e, n, s) => {
391
+ e.tagName === "svg" && (s = zt);
392
+ const r = s ? document.createElementNS(s, e.tagName) : document.createElement(e.tagName);
393
+ Object.keys(e.attrs).forEach((o) => {
394
+ const a = e.attrs[o] || "";
395
+ 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);
396
+ }), Object.keys(e.on).forEach((o) => {
397
+ kt(r, o, e);
398
+ }), 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) => {
399
+ N(r, o, void 0, s);
400
+ }), typeof e.onMounted == "function" && requestAnimationFrame(() => {
401
+ e.onMounted(r, e.loops || []);
296
402
  });
297
- }, N = (e, t, n, s) => {
298
- switch (t.tagName) {
403
+ }, N = (t, e, n, s) => {
404
+ switch (e.tagName) {
299
405
  case "comment":
300
- Rt(e, t, n);
406
+ Nt(t, e, n);
301
407
  break;
302
408
  case "text":
303
- At(e, t, n);
409
+ Jt(t, e, n);
304
410
  break;
305
411
  default:
306
- It(e, t, n, s);
412
+ Xt(t, e, n, s);
307
413
  break;
308
414
  }
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);
415
+ }, Zt = (t) => t && (t.tagName === "ElseIf" || t.tagName === "comment"), Yt = (t) => t && t.tagName === "Else", F = (t, e, n = [], s = "0", r) => {
416
+ var i, f, d;
417
+ let o = 0, a = 0;
418
+ for (let l = 0; l < e.length; l++) {
419
+ const c = e[l];
420
+ if (c.tagName === "If") {
421
+ let u = !1;
422
+ o++;
423
+ let p = 1;
424
+ 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]); )
425
+ ((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++;
426
+ l + 1 < e.length && Yt(e[l + 1]) && (u || (F(t, e[l + 1].children, n, `${s}-if-${o}-${p}`, p), u = !0), l++);
427
+ } else if (c.tagName === "For") {
428
+ a++;
429
+ const { item: u = "item", index: p = "index" } = c.attrs;
430
+ (c.fn(n) || []).forEach((A, R) => {
431
+ const Q = { item: u, value: A, index: p, valueIndex: R };
432
+ F(t, c.children, [...n, Q], `${s}-for-${a}-${R}`, 1);
323
433
  });
324
434
  } else {
325
- const l = {
326
- ...i,
435
+ const u = {
436
+ ...c,
327
437
  loops: n,
328
438
  children: [],
329
439
  rootId: s,
330
440
  ifId: r,
331
- key: i.key || `${s}-${h}`
441
+ key: c.key || `${s}-${l}`
332
442
  // 添加 key 属性
333
443
  };
334
- y(l.children, i.children, n, `${s}-${h}`), e.push(l);
444
+ F(u.children, c.children, n, `${s}-${l}`), t.push(u);
335
445
  }
336
446
  }
337
- }, at = (e, t, n) => {
338
- var o, c, h;
447
+ }, At = (t, e, n) => {
448
+ var a, i, f, d, l;
339
449
  const s = /* @__PURE__ */ new Map();
340
- t.forEach((i, l) => s.set(i.key, { node: i, index: l }));
341
- let r = 0, a = 0;
450
+ e.forEach((c, u) => s.set(c.key, { node: c, index: u }));
451
+ let r = 0, o = 0;
342
452
  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++;
453
+ const c = n[r], u = s.get(c.key);
454
+ if (u) {
455
+ const p = u.node;
456
+ if (p.tagName !== c.tagName) {
457
+ (a = p.elm) == null || a.remove();
458
+ const $ = (i = e[o + 1]) == null ? void 0 : i.elm;
459
+ N(t, c, $), s.delete(c.key), o++;
460
+ } else {
461
+ if (c.ifId && p.ifId !== c.ifId) {
462
+ (f = p.elm) == null || f.remove();
463
+ const $ = (d = e[o + 1]) == null ? void 0 : d.elm;
464
+ N(t, c, $);
465
+ } else
466
+ Qt(p, c);
467
+ s.delete(c.key), o++;
468
+ }
347
469
  } else {
348
- const u = (h = t[a]) == null ? void 0 : h.elm;
349
- N(e, i, u);
470
+ const p = (l = e[o]) == null ? void 0 : l.elm;
471
+ N(t, c, p);
350
472
  }
351
473
  r++;
352
474
  }
353
- s.forEach(({ node: i }) => {
354
- var l;
355
- return (l = i.elm) == null ? void 0 : l.remove();
475
+ s.forEach(({ node: c }) => {
476
+ var u;
477
+ return (u = c.elm) == null ? void 0 : u.remove();
356
478
  });
357
- }, U = (e, t, n = []) => {
358
- if (!t || t.length === 0) return [];
479
+ }, Ct = (t, e, n = []) => {
480
+ if (!e || e.length === 0) return [];
359
481
  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));
482
+ return F(s, e || [], [], "0"), At(t, n, s), s;
483
+ }, j = (t) => {
484
+ if (t === null || typeof t != "object") return !1;
485
+ const e = Object.prototype.toString.call(t);
486
+ return ![
487
+ "[object Function]",
488
+ "[object Date]",
489
+ "[object RegExp]",
490
+ "[object Map]",
491
+ "[object Set]",
492
+ "[object WeakMap]",
493
+ "[object WeakSet]"
494
+ ].includes(e);
495
+ };
496
+ function te(t = window.location) {
497
+ let e;
498
+ typeof t == "string" ? e = new URL(t).hash : e = t.hash;
499
+ const n = e.split("?"), s = n[0].substring(2), r = n[1], o = {};
500
+ return r && r.split("&").forEach((a) => {
501
+ const [i, f] = a.split("=");
502
+ i && f && (o[decodeURIComponent(i)] = decodeURIComponent(f));
369
503
  }), {
370
504
  path: s.split("/"),
371
505
  // 将路径分割成数组
372
- query: a
506
+ query: o
373
507
  // 查询参数对象
374
508
  };
375
509
  }
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() {
510
+ function pt(t, e, n = {}) {
511
+ 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] : [];
512
+ let c = [], u = null, p = !0;
513
+ const $ = (h, m, v = /* @__PURE__ */ new WeakMap()) => {
514
+ if (h === m) return !0;
515
+ if (h == null || m == null || typeof h != "object" || typeof m != "object") return h === m;
516
+ if (v.has(h)) return v.get(h) === m;
517
+ if (v.set(h, m), Array.isArray(h) && Array.isArray(m)) {
518
+ if (h.length !== m.length) return !1;
519
+ for (let g = 0; g < h.length; g++)
520
+ if (!$(h[g], m[g], v)) return !1;
521
+ return !0;
522
+ }
523
+ if (Array.isArray(h) !== Array.isArray(m)) return !1;
524
+ const b = Object.keys(h), y = Object.keys(m);
525
+ if (b.length !== y.length) return !1;
526
+ for (const g of b)
527
+ if (!Object.prototype.hasOwnProperty.call(m, g) || !$(h[g], m[g], v)) return !1;
528
+ return !0;
529
+ }, A = (h) => {
530
+ if (l.length === 0) return !0;
531
+ const m = h.map(String).join(".");
532
+ return l.some((v) => {
533
+ if (!v) return !0;
534
+ try {
535
+ return new RegExp(
536
+ "^" + v.replace(/\./g, "\\.").replace(/\[\*\]/g, "(\\.\\d+)?").replace(/\*\*/g, "(.+)").replace(/\*/g, "[^.]+") + "$"
537
+ ).test(m);
538
+ } catch {
539
+ return !0;
540
+ }
541
+ });
542
+ }, R = (h, m, v) => {
543
+ p && A(h) && (a > 0 ? (c.push({ path: h, newValue: m, oldValue: v }), u || (u = setTimeout(() => {
544
+ if (!p) {
545
+ u = null;
546
+ return;
547
+ }
548
+ const b = c;
549
+ c = [], u = null, f && f(b);
550
+ for (const y of b)
551
+ e(y.path, y.newValue, y.oldValue);
552
+ }, a))) : (e(h, m, v), f && f([{ path: h, newValue: m, oldValue: v }])));
553
+ }, Q = (h, m) => {
554
+ if (!j(h) || !(Array.isArray(h) || Object.prototype.toString.call(h) === "[object Object]")) return h;
555
+ const v = {};
556
+ if (["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].forEach((y) => {
557
+ const g = Array.prototype[y];
558
+ v[y] = function(...E) {
559
+ if (!p) return Reflect.apply(g, h, E);
560
+ const C = [...h], S = g.apply(h, E);
561
+ return $(h, C) || R(m, h, C), S;
562
+ };
563
+ }), s.has(h)) {
564
+ const y = s.get(h);
565
+ return o.set(y, m), y;
566
+ }
567
+ r.add(h);
568
+ const b = new Proxy(h, {
569
+ get(y, g, E) {
570
+ if (Array.isArray(y) && v.hasOwnProperty(g))
571
+ return Reflect.get(v, g, E);
572
+ const C = Reflect.get(y, g, E);
573
+ if (j(C)) {
574
+ const J = [...o.get(b) || [], g], nt = Q(C, J);
575
+ return o.set(nt, J), nt;
576
+ }
577
+ return C;
578
+ },
579
+ set(y, g, E, C) {
580
+ const S = Reflect.get(y, g, C), J = j(E) && !(E instanceof Date || E instanceof RegExp || E instanceof Map || E instanceof Set);
581
+ if (i && J ? $(S, E) : S === E) return !0;
582
+ const Mt = Reflect.set(y, g, E, C), Pt = o.get(b) || m;
583
+ return R([...Pt, g], E, S), Mt;
584
+ },
585
+ deleteProperty(y, g) {
586
+ if (Reflect.has(y, g)) {
587
+ const E = y[g], C = Reflect.deleteProperty(y, g), S = o.get(b) || [];
588
+ return C && r.has(y) && R([...S, g], void 0, E), C;
589
+ }
590
+ return !1;
591
+ }
592
+ });
593
+ return s.set(h, b), o.set(b, m), b;
594
+ }, Rt = Q(t, []);
595
+ if (d) {
596
+ const h = (m, v, b = /* @__PURE__ */ new WeakSet()) => {
597
+ if (!(!j(m) || !p || b.has(m))) {
598
+ b.add(m);
599
+ for (const y of Object.keys(m)) {
600
+ const g = [...v, y], E = m[y];
601
+ A(g) && e(g, E, void 0), j(E) && h(E, g, b);
602
+ }
603
+ }
604
+ };
605
+ h(t, []);
606
+ }
607
+ return { proxy: Rt, unobserve: () => {
608
+ p && (p = !1, c = [], u && (clearTimeout(u), u = null));
609
+ }, resume: () => {
610
+ p = !0;
611
+ } };
612
+ }
613
+ var V, z, G, L, K, D, _, w, U, it;
614
+ class le extends HTMLElement {
615
+ // 停止数据监听函数
616
+ // -----------------------------------------------------
617
+ /**
618
+ * 构造函数
619
+ * -------------------------------------------------------
620
+ * 初始化模板、响应式数据和渲染根节点。
621
+ * 样式注入延迟到 connectedCallback 阶段。
622
+ */
623
+ constructor(n = {}) {
624
+ var a;
386
625
  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);
626
+ M(this, w);
627
+ // ---------------------- 私有属性 ----------------------
628
+ M(this, V);
629
+ // 响应式数据(Proxy)
630
+ M(this, z, []);
631
+ // 模板解析后的虚拟节点 AST
632
+ M(this, G, []);
633
+ // 上一次渲染的虚拟节点
634
+ M(this, L, !1);
635
+ // 节流刷新,防止重复 patch
636
+ M(this, K, !1);
637
+ // 是否已挂载
638
+ M(this, D);
639
+ // 渲染根节点(Shadow DOM 优先)
640
+ M(this, _);
641
+ const s = this._manifest || {};
642
+ k(this, D, (a = s.shadowDOM) != null && a.use ? this.attachShadow({ mode: s.shadowDOM.mode || "open" }) : this);
643
+ const { proxy: r, unobserve: o } = pt(n, () => W(this, w, U).call(this));
644
+ 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());
398
645
  }
646
+ /** Web Components 标准方法:声明哪些属性变化会触发 attributeChangedCallback */
647
+ static get observedAttributes() {
648
+ const n = this._manifest || this.prototype._manifest;
649
+ return n != null && n.props ? n.props.map((s) => typeof s == "string" ? s : s.name) : [];
650
+ }
651
+ // ---------------------- $data getter/setter ----------------------
652
+ /** 获取当前组件数据 */
399
653
  get $data() {
400
- let n = E(this, A);
401
- return ot(n) && (n = it(n, () => M(this, k, H).call(this))), n;
654
+ return x(this, V);
402
655
  }
656
+ /** 更新组件数据 */
403
657
  set $data(n) {
404
- f(this, A, n || {}), M(this, k, H).call(this);
658
+ j(n) || (n = {}), x(this, _) && x(this, _).call(this);
659
+ const { proxy: s, unobserve: r } = pt(n, () => W(this, w, U).call(this));
660
+ k(this, V, s), k(this, _, r), W(this, w, U).call(this);
661
+ }
662
+ /**
663
+ * 手动刷新组件
664
+ * 外部可调用,用于数据未触发 observe 或强制刷新
665
+ */
666
+ refresh() {
667
+ W(this, w, U).call(this);
405
668
  }
669
+ // ---------------------- Web Components 生命周期 ----------------------
406
670
  connectedCallback() {
407
671
  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);
672
+ if ((n.className || n.tagName || "").split(" ").forEach((r) => r && this.classList.add(r)), n.styles && !x(this, D).querySelector("style[data-manifest-style]")) {
673
+ const r = document.createElement("style");
674
+ r.setAttribute("data-manifest-style", "true"), r.textContent = n.styles, x(this, D).appendChild(r);
675
+ }
676
+ if (n.props && j(this.$data))
677
+ for (const r of n.props) {
678
+ 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];
679
+ if (this.hasAttribute(o)) {
680
+ const d = this.getAttribute(o);
681
+ this.$data[i] = W(this, w, it).call(this, d, f, a);
682
+ }
683
+ }
684
+ W(this, w, U).call(this);
685
+ }
686
+ disconnectedCallback() {
687
+ var n;
688
+ this.isConnected && (this.unmounted(), (n = x(this, _)) == null || n.call(this), k(this, _, void 0));
411
689
  }
690
+ attributeChangedCallback(n, s, r) {
691
+ if (s === r || !j(this.$data)) return;
692
+ const o = n.replace(/-([a-z])/g, (i, f) => f.toUpperCase()), a = this.$data[o];
693
+ this.$data[o] = W(this, w, it).call(this, r, a);
694
+ }
695
+ // ---------------------- 自定义生命周期钩子 ----------------------
696
+ /** 兼容旧组件的初始化钩子(首次 mounted 后调用) */
412
697
  onInit() {
413
698
  }
414
- disconnectedCallback() {
699
+ /** 组件创建完成(构造函数结束时调用) */
700
+ created() {
701
+ }
702
+ /** 组件首次挂载到 DOM 后调用 */
703
+ mounted() {
704
+ }
705
+ /** 每次更新前调用 */
706
+ beforeUpdate() {
707
+ }
708
+ /** 每次更新完成后调用 */
709
+ updated() {
710
+ }
711
+ /** 组件从 DOM 中卸载时调用 */
712
+ unmounted() {
415
713
  }
416
714
  }
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());
715
+ V = new WeakMap(), z = new WeakMap(), G = new WeakMap(), L = new WeakMap(), K = new WeakMap(), D = new WeakMap(), _ = new WeakMap(), w = new WeakSet(), // ---------------------- 渲染核心逻辑 ----------------------
716
+ /** 内部刷新函数,由 observe() 或外部调用触发 */
717
+ U = function() {
718
+ x(this, L) || (k(this, L, !0), Dt(() => {
719
+ var n;
720
+ if (!this.isConnected) {
721
+ k(this, L, !1);
722
+ return;
723
+ }
724
+ 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
725
  }));
726
+ }, // ---------------------- 属性类型转换工具 ----------------------
727
+ it = function(n, s, r) {
728
+ if (n === null) return s;
729
+ switch (r || typeof s) {
730
+ case "number":
731
+ const a = Number(n);
732
+ return isNaN(a) ? s : a;
733
+ case "boolean":
734
+ return n === "true";
735
+ case "object":
736
+ try {
737
+ return JSON.parse(n);
738
+ } catch {
739
+ return s;
740
+ }
741
+ default:
742
+ return n;
743
+ }
421
744
  };
422
- const Ht = (e) => (t) => {
423
- if (customElements.get(e.tagName)) {
424
- console.warn(`标签名称 "${e.tagName}" 已经被注册`);
745
+ const ee = (t) => (e) => {
746
+ if (customElements.get(t.tagName)) {
747
+ console.warn(`标签名称 "${t.tagName}" 已经被注册`);
425
748
  return;
426
749
  }
427
- return t.prototype._manifest = Ot(e), customElements.define(e.tagName, t), t;
428
- }, Ot = (e) => (e = Object.assign({
750
+ return e.prototype._manifest = ne(t), customElements.define(t.tagName, e), e;
751
+ }, ne = (t) => (t = Object.assign({
429
752
  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 {
753
+ }, t), t);
754
+ var se = Object.getOwnPropertyDescriptor, xt = (t) => {
755
+ throw TypeError(t);
756
+ }, re = (t, e, n, s) => {
757
+ for (var r = s > 1 ? void 0 : s ? se(e, n) : e, o = t.length - 1, a; o >= 0; o--)
758
+ (a = t[o]) && (r = a(r) || r);
759
+ return r;
760
+ }, 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;
761
+ function dt(t) {
762
+ return t instanceof HTMLElement && t.isRouterView === !0;
763
+ }
764
+ let mt = class extends HTMLElement {
439
765
  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, {});
766
+ 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
767
  }
768
+ // #endregion
769
+ // #region 公共属性和访问器
442
770
  get isRouterView() {
443
771
  return !0;
444
772
  }
445
773
  get $routes() {
446
- return g(this, b);
774
+ return P(this, q);
447
775
  }
448
- set $routes(e) {
449
- p(this, b, e), this.onHashChange();
776
+ set $routes(t) {
777
+ T(this, q, t), this.onHashChange();
450
778
  }
451
779
  get $remainingPath() {
452
- return g(this, O);
780
+ return P(this, tt);
453
781
  }
454
782
  get $matchedRoute() {
455
- return g(this, x);
783
+ return P(this, et);
456
784
  }
457
- set $pipe(e) {
458
- p(this, L, e || {}), this.onHashChange();
785
+ set $pipe(t) {
786
+ T(this, X, t || {}), this.onHashChange();
459
787
  }
788
+ // #endregion
789
+ // #region 生命周期回调
460
790
  connectedCallback() {
461
- window.addEventListener("hashchange", this.onHashChange.bind(this)), this.onHashChange();
791
+ window.addEventListener("hashchange", P(this, Z)), this.onHashChange();
462
792
  }
463
793
  disconnectedCallback() {
464
- window.removeEventListener("hashchange", this.onHashChange.bind(this));
794
+ window.removeEventListener("hashchange", P(this, Z));
465
795
  }
796
+ // #endregion
797
+ /**
798
+ * Hash 变化时的核心处理函数
799
+ */
466
800
  onHashChange() {
467
- var n;
801
+ var e;
468
802
  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;
803
+ const t = this.findAncestorRouterView();
804
+ if (t)
805
+ T(this, B, t.$remainingPath), T(this, q, ((e = t.$matchedRoute) == null ? void 0 : e.children) || []);
806
+ else {
807
+ const { path: n } = te(window.location);
808
+ T(this, B, n);
809
+ }
810
+ oe(this, ct, wt).call(this);
811
+ }
812
+ /**
813
+ * 准备传递给子组件的 props 和事件监听
814
+ * @param params 从路由中解析出的参数
815
+ * @returns 包含 props 和 on 的对象
816
+ */
817
+ prepareComponentData(t) {
818
+ const e = {}, n = {};
819
+ for (const [s, r] of Object.entries(t))
820
+ e[s] = () => r;
821
+ for (const [s, r] of Object.entries(P(this, X))) {
822
+ const o = s.toLowerCase();
823
+ let a = null;
824
+ 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;
825
+ }
826
+ return { props: e, on: n };
827
+ }
828
+ /**
829
+ * 在路由表中查找与当前路径匹配的路由
830
+ * @param routes 路由配置数组
831
+ * @param pathSegments URL 路径分段数组
832
+ * @returns 匹配结果
833
+ */
834
+ matchRoute(t, e) {
835
+ for (const n of t) {
836
+ const s = n.path.split("/").filter((a) => a), r = {};
837
+ if (s.length > e.length && !s.includes("*"))
838
+ continue;
839
+ let o = !0;
840
+ for (let a = 0; a < s.length; a++) {
841
+ const i = s[a], f = e[a];
842
+ if (i.startsWith(":"))
843
+ r[i.substring(1)] = f;
844
+ else {
845
+ if (i === "*")
846
+ return {
847
+ matchedRoute: n,
848
+ params: r,
849
+ remainingPath: []
850
+ // 通配符消耗所有剩余路径
851
+ };
852
+ if (i !== f) {
853
+ o = !1;
854
+ break;
855
+ }
487
856
  }
488
857
  }
489
- if (r)
858
+ if (o)
490
859
  return {
491
860
  matchedRoute: n,
492
- params: a,
493
- remainingPath: t.slice(s.length)
861
+ params: r,
862
+ remainingPath: e.slice(s.length)
494
863
  };
495
864
  }
496
- return {
497
- matchedRoute: null,
498
- params: {},
499
- remainingPath: t
500
- };
865
+ return { matchedRoute: null, params: {}, remainingPath: e };
501
866
  }
502
- propagateRoutes(e) {
503
- for (const t of e.childNodes)
504
- t.isRouterView ? t.onHashChange() : this.propagateRoutes(t);
867
+ /**
868
+ * 递归通知所有子节点中的 router-view 进行更新
869
+ * @param node 当前遍历的起始节点
870
+ */
871
+ propagateToChildRouterViews(t = this) {
872
+ for (const e of t.childNodes)
873
+ dt(e) ? e.onHashChange() : this.propagateToChildRouterViews(e);
505
874
  }
506
- findAncestorWithRouterView(e) {
507
- let t = e.parentNode;
875
+ /**
876
+ * 沿 DOM 树向上查找最近的父 router-view 实例
877
+ * @returns 父 RouterViewElement 实例或 null
878
+ */
879
+ findAncestorRouterView() {
880
+ let t = this.parentElement;
508
881
  for (; t; ) {
509
- if (t.isRouterView)
882
+ if (dt(t))
510
883
  return t;
511
884
  t = t.parentElement;
512
885
  }
513
886
  return null;
514
887
  }
515
888
  };
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: "",
889
+ Y = /* @__PURE__ */ new WeakMap();
890
+ tt = /* @__PURE__ */ new WeakMap();
891
+ et = /* @__PURE__ */ new WeakMap();
892
+ B = /* @__PURE__ */ new WeakMap();
893
+ q = /* @__PURE__ */ new WeakMap();
894
+ X = /* @__PURE__ */ new WeakMap();
895
+ Z = /* @__PURE__ */ new WeakMap();
896
+ ct = /* @__PURE__ */ new WeakSet();
897
+ wt = function() {
898
+ const t = P(this, B) || [], { matchedRoute: e, params: n, remainingPath: s } = this.matchRoute(P(this, q), t);
899
+ T(this, tt, s), T(this, et, e);
900
+ const r = (e == null ? void 0 : e.tagName) || "comment", { props: o, on: a } = this.prepareComponentData(n);
901
+ T(this, Y, Ct(this, [{
902
+ tagName: r,
903
+ rootId: "0",
904
+ // 假设 rootId 是固定的
905
+ attrs: {},
906
+ props: o,
907
+ on: a,
545
908
  children: []
546
- }), this.propagateRoutes(this);
909
+ }], P(this, Y))), this.propagateToChildRouterViews();
547
910
  };
548
- X = Tt([
549
- Ht({
911
+ mt = re([
912
+ ee({
550
913
  tagName: "router-view"
551
914
  })
552
- ], X);
915
+ ], mt);
553
916
  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
917
+ le as BaseElement,
918
+ ee as CustomElement,
919
+ mt as RouterViewElement,
920
+ lt as createFunction,
921
+ j as isObject,
922
+ gt as listeners,
923
+ pt as observe,
924
+ te as parseHashUrl,
925
+ Tt as parseHtml,
926
+ Ct as patch,
927
+ Dt as runInAsyncQueue
565
928
  };