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/dist/solely.js CHANGED
@@ -1,87 +1,132 @@
1
- var K = (e) => {
2
- throw TypeError(e);
1
+ var ft = (t) => {
2
+ throw TypeError(t);
3
3
  };
4
- var F = (e, t, n) => t.has(e) || K("Cannot " + n);
5
- var v = (e, t, n) => (F(e, t, "read from private field"), n ? n.call(e) : t.get(e)), d = (e, t, n) => t.has(e) ? K("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), m = (e, t, n, s) => (F(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), H = (e, t, n) => (F(e, t, "access private method"), n);
6
- const ut = /<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g, ft = /<\/?([^\s]+?)[/\s>]/, mt = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g, pt = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"], j = /\{\{(.+?)\}\}/g;
7
- function dt(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 gt(e, t) {
11
- const n = (t.match(ft) || [])[1] || "", s = {
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(mt);
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, i] = a[1] ? a[1].trim().split("=") : [a[2], a[3].trim().slice(1, -1)];
24
- if (J.includes(o) || o.startsWith("on-"))
25
- s.on[o.startsWith("on-") ? o.slice(3) : o.slice(2)] = X(e, i);
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
32
  s.model = i;
31
33
  break;
32
34
  case "style":
33
- s.styles = (l) => g(e, i, l);
35
+ s.styles = (d) => O(t, i, d);
34
36
  break;
35
37
  case "class":
36
- s.classes = (l) => g(e, i, l);
38
+ s.classes = (d) => O(t, i, d);
37
39
  break;
38
40
  case "readonly":
39
- s.props.readOnly = (l) => g(e, i, l);
41
+ s.props.readOnly = (d) => O(t, i, d);
40
42
  break;
41
43
  default:
42
- s.props[h] = (l) => g(e, i, l);
44
+ s.props[f] = (d) => O(t, i, d);
43
45
  break;
44
46
  }
45
47
  } else
46
- s.attrs[o] = i;
48
+ s.attrs[a] = i;
47
49
  r.lastIndex--;
48
50
  }
49
- if (n === "For" ? s.fn = (a) => g(e, s.attrs.each, a) : (n === "If" || n === "ElseIf") && (s.fn = (a) => g(e, s.attrs.condition, a)), s.model) {
50
- const a = s.model.replace("this.", "").replace("$data.", ""), o = (h) => g(e, `$data.${a}`, h), i = (h) => X(e, `$data.${a}=${h}`);
51
- n === "input" ? s.attrs.type === "checkbox" || s.attrs.type === "radio" ? (s.props.checked = o, s.on.change = i("checked")) : (s.props.value = o, s.on.input = i("value")) : n === "textarea" ? (s.props.value = o, s.on.input = i("value")) : n === "select" && (s.props.value = o, s.on.change = i("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 Et(e, t) {
100
+ function Tt(t, e) {
56
101
  const n = [];
57
- if (!t) return n;
58
- t = dt(t);
59
- const s = [], r = [], a = () => {
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 o = 0;
64
- return t.replace(ut, (i, h) => {
65
- const l = a();
66
- if (h > o) {
67
- const c = t.substring(o, h).trim();
68
- if (c) {
69
- j.lastIndex = 0;
70
- const f = !j.test(c) ? c : (T) => c.replace(j, (D, V) => g(e, V, T));
71
- l.push({
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: f,
122
+ content: u,
78
123
  children: []
79
124
  });
80
125
  }
81
126
  }
82
- if (o = h + i.length, i.startsWith("<!--") && i.endsWith("-->"))
83
- l.push({
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 c = r.pop();
94
- for (; s.length > 0 && s[s.length - 1].tagName !== c; )
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 c = gt(e, i), u = i.endsWith("/>") || pt.includes(c.tagName);
99
- l.push(c), u || (s.push(c), r.push(c.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({
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: t.substring(o).trim(),
153
+ content: e.substring(a).trim(),
109
154
  children: []
110
155
  }), n;
111
156
  }
112
- const g = (e, t, n) => {
157
+ const O = (t, e, n) => {
113
158
  try {
114
- return N(["$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
- }, X = (e, t) => (n, s) => N(["$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)), J = [
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
- ], vt = /* @__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
- })(), q = {};
189
- function N(e) {
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 (yt(n))
299
+ if (Ut(n))
196
300
  throw new Error("Input contains potentially dangerous code: " + n);
197
- q[t] = new Function(...e);
301
+ ot[e] = new Function(...t);
198
302
  }
199
- return q[t];
303
+ return ot[e];
200
304
  }
201
- const bt = ["eval", "Function", "process", "require"];
202
- function yt(e) {
203
- return bt.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 wt = "http://www.w3.org/1999/xlink", _t = "http://www.w3.org/2000/xmlns/", Ct = "http://www.w3.org/XML/1998/namespace", xt = "http://www.w3.org/2000/svg", Y = (e) => typeof e.content == "function" ? e.content(e.loops || []) : e.content || "", kt = (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 = U(r);
217
- Object.entries(a).forEach(([o, i]) => {
218
- e.style[o] = i;
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, i]) => {
225
- i ? 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
- }, U = (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 = U(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 = U(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
- }, It = (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
- }, At = (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
- kt(t);
376
+ Gt(e);
271
377
  break;
272
378
  case "slot":
273
379
  break;
274
380
  default:
275
- It(e, t);
381
+ Kt(t, e);
276
382
  break;
277
383
  }
278
- }, G = (e, t, n) => {
279
- n ? e.insertBefore(t, n) : e.appendChild(t);
280
- }, Rt = (e, t, n) => {
281
- const s = Y(t), r = document.createTextNode(s);
282
- t.elm = r, G(e, r, n);
283
- }, $t = (e, t, n) => {
284
- const s = t.content, r = document.createComment(s);
285
- t.elm = r, G(e, r, n);
286
- }, St = (e, t, n, s) => {
287
- t.tagName === "svg" && (s = xt);
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(Ct, a, o) : a.startsWith("xlink:") ? r.setAttributeNS(wt, a, o) : a.startsWith("xmlns:") ? r.setAttributeNS(_t, 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, G(e, r, n), t.tagName === "foreignObject" && (s = void 0), t.children.forEach((a) => {
295
- M(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
- }, M = (e, t, n, s) => {
298
- switch (t.tagName) {
405
+ }, N = (t, e, n, s) => {
406
+ switch (e.tagName) {
299
407
  case "comment":
300
- $t(e, t, n);
408
+ Nt(t, e, n);
301
409
  break;
302
410
  case "text":
303
- Rt(e, t, n);
411
+ Jt(t, e, n);
304
412
  break;
305
413
  default:
306
- St(e, t, n, s);
414
+ Xt(t, e, n, s);
307
415
  break;
308
416
  }
309
- }, Wt = (e) => e && (e.tagName === "ElseIf" || e.tagName === "comment"), Ht = (e) => e && e.tagName === "Else", y = (e, t, n = [], s = 0, r = !0, a) => {
310
- var o, i, h;
311
- for (let l = 0; l < t.length; l++) {
312
- const c = t[l];
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, f = 1;
315
- for (((o = c.fn) == null ? void 0 : o.call(c, n)) && (y(e, c.children, n, s, !1, f), u = !0), f++; l + 1 < t.length && Wt(t[l + 1]); )
316
- ((h = (i = t[l + 1]).fn) == null ? void 0 : h.call(i, n)) && !u && (y(e, t[l + 1].children, n, s, !1, f), u = !0), l++, f++;
317
- l + 1 < t.length && Ht(t[l + 1]) && (u || (y(e, t[l + 1].children, n, s, !1, f), u = !0), l++);
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
- const { item: u = "item", index: f = "index" } = c.attrs;
320
- (c.fn(n) || []).forEach((D, V) => {
321
- const ht = { item: u, value: D, index: f, valueIndex: V };
322
- y(e, c.children, [...n, ht], s, !1);
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: a
442
+ ifId: r,
443
+ key: c.key || `${s}-${l}`
444
+ // 添加 key 属性
331
445
  };
332
- y(u.children, c.children, n), e.push(u);
446
+ F(u.children, c.children, n, `${s}-${l}`), t.push(u);
333
447
  }
334
- r && s++;
335
448
  }
336
- }, at = (e, t, n) => {
337
- var a, o, i, h, l;
338
- let s = 0, r = 0;
339
- for (; s < t.length && r < n.length; ) {
340
- const c = t[s], u = n[r];
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
- M(e, c), r++;
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
- }, z = (e, t, n = []) => {
350
- if (!t || t.length === 0) return [];
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 y(s, t || [], [], 0, !0), at(e, n, s), s;
353
- }, ot = (e) => typeof e == "object" && e != null;
354
- function Mt(e = window.location) {
355
- let t;
356
- typeof e == "string" ? t = new URL(e).hash : t = e.hash;
357
- const n = t.split("?"), s = n[0].substring(2), r = n[1], a = {};
358
- return r && r.split("&").forEach((o) => {
359
- const [i, h] = o.split("=");
360
- i && h && (a[decodeURIComponent(i)] = 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));
361
505
  }), {
362
506
  path: s.split("/"),
363
507
  // 将路径分割成数组
364
- query: a
508
+ query: o
365
509
  // 查询参数对象
366
510
  };
367
511
  }
368
- const it = (e, t) => new Proxy(e, {
369
- get: (n, s) => {
370
- let r = n[s];
371
- return ot(r) && (r = it(r, t)), r;
372
- },
373
- set: (n, s, r) => (n[s] !== r && (n[s] = r, t(s, r)), !0)
374
- });
375
- var R, $, S, _, W, C, x, O;
376
- class jt extends HTMLElement {
377
- 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;
378
627
  super();
379
- d(this, x);
380
- d(this, R, {});
381
- d(this, $, []);
382
- d(this, S, []);
383
- d(this, _, !1);
384
- d(this, W, !1);
385
- d(this, C);
386
- const n = this._manifest || {};
387
- n.template && typeof n.template == "string" && m(this, $, Et(this, n.template)), n.shadowDOM && n.shadowDOM.use ? m(this, C, this.attachShadow({
388
- mode: n.shadowDOM.mode || "open"
389
- })) : m(this, C, 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());
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
- let n = v(this, R);
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
- m(this, R, n || {}), H(this, x, O).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);
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 && this.classList.add(r);
402
- }), H(this, x, O).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));
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
- disconnectedCallback() {
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
- R = new WeakMap(), $ = new WeakMap(), S = new WeakMap(), _ = new WeakMap(), W = new WeakMap(), C = new WeakMap(), x = new WeakSet(), O = function() {
410
- v(this, _) || (m(this, _, !0), vt(() => {
411
- m(this, S, z(v(this, C), v(this, $), v(this, S))), m(this, _, !1), this.isConnected && !v(this, W) && (m(this, W, !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));
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 Ot = (e) => (t) => {
415
- if (customElements.get(e.tagName)) {
416
- console.warn(`标签名称 "${e.tagName}" 已经被注册`);
747
+ const ee = (t) => (e) => {
748
+ if (customElements.get(t.tagName)) {
749
+ console.warn(`标签名称 "${t.tagName}" 已经被注册`);
417
750
  return;
418
751
  }
419
- return t.prototype._manifest = Lt(e), customElements.define(e.tagName, t), t;
420
- }, Lt = (e) => (e = Object.assign({
752
+ return e.prototype._manifest = ne(t), customElements.define(t.tagName, e), e;
753
+ }, ne = (t) => (t = Object.assign({
421
754
  hasConfig: !1
422
- }, e), e);
423
- var Pt = Object.defineProperty, Tt = Object.getOwnPropertyDescriptor, ct = (e) => {
424
- throw TypeError(e);
425
- }, Dt = (e, t, n, s) => {
426
- for (var r = s > 1 ? void 0 : s ? Tt(t, n) : t, a = e.length - 1, o; a >= 0; a--)
427
- (o = e[a]) && (r = (s ? o(t, n, r) : o(r)) || r);
428
- return s && r && Pt(t, n, r), r;
429
- }, Q = (e, t, n) => t.has(e) || ct("Cannot " + n), E = (e, t, n) => (Q(e, t, "read from private field"), n ? n.call(e) : t.get(e)), b = (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) => (Q(e, t, "write to private field"), t.set(e, n), n), Vt = (e, t, n) => (Q(e, t, "access private method"), n), k, L, A, I, w, P, B, lt;
430
- let Z = 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 {
431
767
  constructor() {
432
- super(...arguments), b(this, B), b(this, k, []), b(this, L, []), b(this, A, null), b(this, I), b(this, w, []), b(this, P, {});
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 E(this, w);
776
+ return P(this, q);
439
777
  }
440
- set $routes(e) {
441
- p(this, w, e), this.onHashChange();
778
+ set $routes(t) {
779
+ T(this, q, t), this.onHashChange();
442
780
  }
443
781
  get $remainingPath() {
444
- return E(this, L);
782
+ return P(this, tt);
445
783
  }
446
784
  get $matchedRoute() {
447
- return E(this, A);
785
+ return P(this, et);
448
786
  }
449
- set $pipe(e) {
450
- p(this, P, e || {}), this.onHashChange();
787
+ set $pipe(t) {
788
+ T(this, X, t || {}), this.onHashChange();
451
789
  }
790
+ // #endregion
791
+ // #region 生命周期回调
452
792
  connectedCallback() {
453
- window.addEventListener("hashchange", this.onHashChange.bind(this)), this.onHashChange();
793
+ window.addEventListener("hashchange", P(this, Z)), this.onHashChange();
454
794
  }
455
795
  disconnectedCallback() {
456
- window.removeEventListener("hashchange", this.onHashChange.bind(this));
796
+ window.removeEventListener("hashchange", P(this, Z));
457
797
  }
798
+ // #endregion
799
+ /**
800
+ * Hash 变化时的核心处理函数
801
+ */
458
802
  onHashChange() {
459
- var n;
803
+ var e;
460
804
  if (!this.isConnected) return;
461
- const { path: e } = Mt(window.location), t = this.findAncestorWithRouterView(this);
462
- t ? (p(this, I, t.$remainingPath), p(this, w, ((n = t.$matchedRoute) == null ? void 0 : n.children) || [])) : p(this, I, e), Vt(this, B, lt).call(this);
463
- }
464
- matchRoute(e, t) {
465
- for (const n of e) {
466
- const s = n.path.split("/");
467
- let r = !0;
468
- const a = {};
469
- for (let o = 0; o < s.length; o++) {
470
- const i = s[o];
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
- a[i.substring(1)] = t[o];
473
- else if (i === "*") {
474
- r = !0;
475
- break;
476
- } else if (i !== t[o]) {
477
- r = !1;
478
- break;
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 (r)
860
+ if (o)
482
861
  return {
483
862
  matchedRoute: n,
484
- params: a,
485
- remainingPath: t.slice(s.length)
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
- propagateRoutes(e) {
495
- for (const t of e.childNodes)
496
- 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);
497
876
  }
498
- findAncestorWithRouterView(e) {
499
- let t = e.parentNode;
877
+ /**
878
+ * 沿 DOM 树向上查找最近的父 router-view 实例
879
+ * @returns 父 RouterViewElement 实例或 null
880
+ */
881
+ findAncestorRouterView() {
882
+ let t = this.parentElement;
500
883
  for (; t; ) {
501
- if (t.isRouterView)
884
+ if (dt(t))
502
885
  return t;
503
886
  t = t.parentElement;
504
887
  }
505
888
  return null;
506
889
  }
507
890
  };
508
- k = /* @__PURE__ */ new WeakMap();
509
- L = /* @__PURE__ */ new WeakMap();
510
- A = /* @__PURE__ */ new WeakMap();
511
- I = /* @__PURE__ */ new WeakMap();
512
- w = /* @__PURE__ */ new WeakMap();
513
- P = /* @__PURE__ */ new WeakMap();
514
- B = /* @__PURE__ */ new WeakSet();
515
- lt = function() {
516
- var h;
517
- const e = E(this, I) || [], { matchedRoute: t, params: n, remainingPath: s } = this.matchRoute(E(this, w), e);
518
- p(this, L, s);
519
- const r = (t == null ? void 0 : t.tagName) || "comment", a = {}, o = {};
520
- for (const [l, c] of Object.entries(n))
521
- a[l] = () => c;
522
- for (const [l, c] of Object.entries(E(this, P)))
523
- J.includes(l) || l.startsWith("on-") ? o[l.startsWith("on-") ? l.slice(3) : l.slice(2)] = c : a[l] = () => c;
524
- const i = [
525
- {
526
- tagName: r,
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.propagateRoutes(this);
911
+ }], P(this, Y))), this.propagateToChildRouterViews();
539
912
  };
540
- Z = Dt([
541
- Ot({
913
+ mt = re([
914
+ ee({
542
915
  tagName: "router-view"
543
916
  })
544
- ], Z);
917
+ ], mt);
545
918
  export {
546
- jt as BaseElement,
547
- Ot as CustomElement,
548
- Z as RouterViewElement,
549
- N as createFunction,
550
- ot as isObject,
551
- J as listeners,
552
- it as observe,
553
- Mt as parseHashUrl,
554
- Et as parseHtml,
555
- z as patch,
556
- vt 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
557
930
  };