solely 0.0.11 → 0.0.14

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.
@@ -0,0 +1,22 @@
1
+ import { IRouter } from './router';
2
+ interface IQueryParams {
3
+ [key: string]: string;
4
+ }
5
+ interface IRouteParams {
6
+ [key: string]: string;
7
+ }
8
+ export declare class RouterViewElement extends HTMLElement {
9
+ #private;
10
+ $elm: HTMLElement;
11
+ $routes: IRouter[];
12
+ $matchedRoute: IRouter | null;
13
+ $remainingPath: string[];
14
+ $query: IQueryParams;
15
+ $params: IRouteParams;
16
+ constructor();
17
+ connectedCallback(): void;
18
+ disconnectedCallback(): void;
19
+ matchRoute(): void;
20
+ findAncestorWithRouterView(node: Element): Element | null;
21
+ }
22
+ export {};
@@ -0,0 +1,17 @@
1
+ export interface IRouter {
2
+ path: string;
3
+ tagName: string;
4
+ children?: IRouter[];
5
+ elm?: HTMLElement;
6
+ }
7
+ declare class Router {
8
+ #private;
9
+ subscribers: ((routes: IRouter[]) => void)[];
10
+ constructor();
11
+ setRoutes(routes: IRouter[]): void;
12
+ getRoutes(): IRouter[];
13
+ subscribe(callback: any): void;
14
+ unsubscribe(callback: any): void;
15
+ }
16
+ export declare const router: Router;
17
+ export {};
package/dist/solely.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from './utils';
2
- export { default as BaseElement } from './elements/base/base-element';
3
- export { CustomElement } from './elements/base/decorators';
4
- export type { Manifest } from './elements/base/decorators';
2
+ export { default as BaseElement } from './base/base-element';
3
+ export { CustomElement } from './base/decorators';
4
+ export type { Manifest } from './base/decorators';
5
+ export { RouterViewElement } from './base/router-view';
6
+ export type { IRouter } from './base/router';
7
+ export { router } from './base/router';
package/dist/solely.js CHANGED
@@ -1,121 +1,123 @@
1
- var M = (e) => {
1
+ var lt = Object.defineProperty;
2
+ var U = (e) => {
2
3
  throw TypeError(e);
3
4
  };
4
- var S = (e, t, n) => t.has(e) || M("Cannot " + n);
5
- var h = (e, t, n) => (S(e, t, "read from private field"), n ? n.call(e) : t.get(e)), y = (e, t, n) => t.has(e) ? M("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), g = (e, t, n, s) => (S(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), k = (e, t, n) => (S(e, t, "access private method"), n);
6
- const Q = /<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g, X = /<\/?([^\s]+?)[/\s>]/, J = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g, K = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"], w = /\{\{(.+?)\}\}/g;
7
- function Z(e) {
5
+ var ut = (e, t, s) => t in e ? lt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
6
+ var z = (e, t, s) => ut(e, typeof t != "symbol" ? t + "" : t, s), T = (e, t, s) => t.has(e) || U("Cannot " + s);
7
+ var f = (e, t, s) => (T(e, t, "read from private field"), s ? s.call(e) : t.get(e)), m = (e, t, s) => t.has(e) ? U("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), p = (e, t, s, n) => (T(e, t, "write to private field"), n ? n.call(e, s) : t.set(e, s), s), k = (e, t, s) => (T(e, t, "access private method"), s);
8
+ const ht = /<!--(?:.|\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"], q = /\{\{(.+?)\}\}/g;
9
+ function dt(e) {
8
10
  return e.replace(/>\s+</g, "><").replace(/\s+/g, " ");
9
11
  }
10
- function G(e, t) {
11
- const n = (t.match(X) || [])[1] || "", s = {
12
+ function gt(e, t) {
13
+ const s = (t.match(ft) || [])[1] || "", n = {
12
14
  rootId: 0,
13
- tagName: n,
15
+ tagName: s,
14
16
  attrs: {},
15
17
  props: {},
16
18
  on: {},
17
19
  children: []
18
- }, o = new RegExp(J);
20
+ }, r = new RegExp(mt);
19
21
  for (; ; ) {
20
- const r = o.exec(t);
21
- if (r === null) break;
22
- if (!r[0].trim()) continue;
23
- const [a, i] = r[1] ? r[1].trim().split("=") : [r[2], r[3].trim().slice(1, -1)];
24
- if (U.includes(a) || a.startsWith("on-"))
25
- s.on[a.startsWith("on-") ? a.slice(3) : a.slice(2)] = R(e, `return (${i})`);
26
- else if (a.startsWith("s-")) {
27
- const m = a.slice(2);
28
- switch (m) {
22
+ const o = r.exec(t);
23
+ if (o === null) break;
24
+ if (!o[0].trim()) continue;
25
+ const [i, a] = o[1] ? o[1].trim().split("=") : [o[2], o[3].trim().slice(1, -1)];
26
+ if (Et.includes(i) || i.startsWith("on-"))
27
+ n.on[i.startsWith("on-") ? i.slice(3) : i.slice(2)] = B(e, `return (${a})`);
28
+ else if (i.startsWith("s-")) {
29
+ const h = i.slice(2);
30
+ switch (h) {
29
31
  case "model":
30
- s.model = i;
32
+ n.model = a;
31
33
  break;
32
34
  case "style":
33
- s.styles = (l) => f(e, i, l);
35
+ n.styles = (l) => d(e, a, l);
34
36
  break;
35
37
  case "class":
36
- s.classes = (l) => f(e, i, l);
38
+ n.classes = (l) => d(e, a, l);
37
39
  break;
38
40
  case "readonly":
39
- s.props.readOnly = (l) => f(e, i, l);
41
+ n.props.readOnly = (l) => d(e, a, l);
40
42
  break;
41
43
  default:
42
- s.props[m] = (l) => f(e, i, l);
44
+ n.props[h] = (l) => d(e, a, l);
43
45
  break;
44
46
  }
45
47
  } else
46
- s.attrs[a] = i;
47
- o.lastIndex--;
48
+ n.attrs[i] = a;
49
+ r.lastIndex--;
48
50
  }
49
- if (n === "For" ? s.fn = (r) => f(e, s.attrs.each, r) : (n === "If" || n === "ElseIf") && (s.fn = (r) => f(e, s.attrs.condition, r)), s.model) {
50
- const r = s.model.replace("this.", "").replace("$data.", ""), a = (m) => f(e, `$data.${r}`, m), i = (m) => R(e, `$data.${r}=${m}`);
51
- n === "input" ? s.attrs.type === "checkbox" || s.attrs.type === "radio" ? (s.props.checked = a, s.on.change = i("checked")) : (s.props.value = a, s.on.input = i("value")) : n === "textarea" ? (s.props.value = a, s.on.input = i("value")) : n === "select" && (s.props.value = a, s.on.change = i("value"));
51
+ if (s === "For" ? n.fn = (o) => d(e, n.attrs.each, o) : (s === "If" || s === "ElseIf") && (n.fn = (o) => d(e, n.attrs.condition, o)), n.model) {
52
+ const o = n.model.replace("this.", "").replace("$data.", ""), i = (h) => d(e, `$data.${o}`, h), a = (h) => B(e, `$data.${o}=${h}`);
53
+ s === "input" ? n.attrs.type === "checkbox" || n.attrs.type === "radio" ? (n.props.checked = i, n.on.change = a("checked")) : (n.props.value = i, n.on.input = a("value")) : s === "textarea" ? (n.props.value = i, n.on.input = a("value")) : s === "select" && (n.props.value = i, n.on.change = a("value"));
52
54
  }
53
- return s;
55
+ return n;
54
56
  }
55
- function N(e, t) {
56
- const n = [];
57
- if (!t) return n;
58
- t = Z(t);
59
- const s = [], o = [], r = () => {
60
- var i;
61
- return s.length === 0 ? n : (i = s[s.length - 1]).children || (i.children = []);
57
+ function bt(e, t) {
58
+ const s = [];
59
+ if (!t) return s;
60
+ t = dt(t);
61
+ const n = [], r = [], o = () => {
62
+ var a;
63
+ return n.length === 0 ? s : (a = n[n.length - 1]).children || (a.children = []);
62
64
  };
63
- let a = 0;
64
- return t.replace(Q, (i, m) => {
65
- const l = r();
66
- if (m > a) {
67
- const c = t.substring(a, m).trim();
65
+ let i = 0;
66
+ return t.replace(ht, (a, h) => {
67
+ const l = o();
68
+ if (h > i) {
69
+ const c = t.substring(i, h).trim();
68
70
  if (c) {
69
- w.lastIndex = 0;
70
- const A = !w.test(c) ? c : ($) => c.replace(w, (L, C) => f(e, C, $));
71
+ q.lastIndex = 0;
72
+ const I = !q.test(c) ? c : (W) => c.replace(q, (D, O) => d(e, O, W));
71
73
  l.push({
72
74
  rootId: 0,
73
75
  tagName: "text",
74
76
  attrs: {},
75
77
  props: {},
76
78
  on: {},
77
- content: A,
79
+ content: I,
78
80
  children: []
79
81
  });
80
82
  }
81
83
  }
82
- if (a = m + i.length, i.startsWith("<!--") && i.endsWith("-->"))
84
+ if (i = h + a.length, a.startsWith("<!--") && a.endsWith("-->"))
83
85
  l.push({
84
86
  rootId: 0,
85
87
  tagName: "comment",
86
88
  attrs: {},
87
89
  props: {},
88
90
  on: {},
89
- content: i.slice(4, -3),
91
+ content: a.slice(4, -3),
90
92
  children: []
91
93
  });
92
- else if (i.startsWith("</")) {
93
- const c = o.pop();
94
- for (; s.length > 0 && s[s.length - 1].tagName !== c; )
95
- s.pop();
96
- s.pop();
94
+ else if (a.startsWith("</")) {
95
+ const c = r.pop();
96
+ for (; n.length > 0 && n[n.length - 1].tagName !== c; )
97
+ n.pop();
98
+ n.pop();
97
99
  } else {
98
- const c = G(e, i), u = i.endsWith("/>") || K.includes(c.tagName);
99
- l.push(c), u || (s.push(c), o.push(c.tagName));
100
+ const c = gt(e, a), u = a.endsWith("/>") || pt.includes(c.tagName);
101
+ l.push(c), u || (n.push(c), r.push(c.tagName));
100
102
  }
101
103
  return "";
102
- }), t.length > a && n.push({
104
+ }), t.length > i && s.push({
103
105
  rootId: 0,
104
106
  tagName: "text",
105
107
  attrs: {},
106
108
  props: {},
107
109
  on: {},
108
- content: t.substring(a).trim(),
110
+ content: t.substring(i).trim(),
109
111
  children: []
110
- }), n;
112
+ }), s;
111
113
  }
112
- const f = (e, t, n) => {
114
+ const d = (e, t, s) => {
113
115
  try {
114
- return P(["$data", ...n.map((o) => o.item), `return (${t})`]).bind(e)(e.$data, ...n.map((o) => o.value));
115
- } catch (s) {
116
- console.error(s);
116
+ return J(["$data", ...s.map((r) => r.item), `return (${t})`]).bind(e)(e.$data, ...s.map((r) => r.value));
117
+ } catch (n) {
118
+ console.error(n);
117
119
  }
118
- }, R = (e, t) => (n, s) => P(["$data", "event", "value", "checked", ...s.map((r) => r.item), t]).bind(e)(e.$data, n, n.target.value, n.target.checked, ...s.map((r) => r.value)), U = [
120
+ }, B = (e, t) => (s, n) => J(["$data", "event", "value", "checked", ...n.map((o) => o.item), t]).bind(e)(e.$data, s, s.target.value, s.target.checked, ...n.map((o) => o.value)), Et = [
119
121
  "onabort",
120
122
  "onautocomplete",
121
123
  "onautocompleteerror",
@@ -178,28 +180,28 @@ const f = (e, t, n) => {
178
180
  "ontoggle",
179
181
  "onvolumechange",
180
182
  "onwaiting"
181
- ], Y = /* @__PURE__ */ (() => {
183
+ ], vt = /* @__PURE__ */ (() => {
182
184
  const e = typeof requestAnimationFrame == "function" ? (t) => requestAnimationFrame(t) : typeof Promise < "u" ? (t) => Promise.resolve().then(t) : (t) => setTimeout(t, 0);
183
- return (t, ...n) => {
185
+ return (t, ...s) => {
184
186
  if (typeof t != "function")
185
187
  throw new Error("runInAsyncQueue expects a function as its first argument");
186
- e(() => t(...n));
188
+ e(() => t(...s));
187
189
  };
188
- })(), T = {};
189
- function P(e) {
190
+ })(), L = {};
191
+ function J(e) {
190
192
  const t = e.join(",");
191
- if (!T[t]) {
192
- const n = e[e.length - 1];
193
- if (n.trim() === "")
193
+ if (!L[t]) {
194
+ const s = e[e.length - 1];
195
+ if (s.trim() === "")
194
196
  throw new Error("Function body is empty");
195
- if (tt(n))
196
- throw new Error("Input contains potentially dangerous code: " + n);
197
- const s = new Function(...e);
198
- T[t] = s;
197
+ if ($t(s))
198
+ throw new Error("Input contains potentially dangerous code: " + s);
199
+ const n = new Function(...e);
200
+ L[t] = n;
199
201
  }
200
- return T[t];
202
+ return L[t];
201
203
  }
202
- function tt(e) {
204
+ function $t(e) {
203
205
  return [
204
206
  "eval",
205
207
  "Function",
@@ -218,149 +220,202 @@ function tt(e) {
218
220
  "String.raw",
219
221
  "Object.prototype",
220
222
  "JSON.parse"
221
- ].some((n) => e.includes(n));
223
+ ].some((s) => e.includes(s));
222
224
  }
223
- const et = "http://www.w3.org/1999/xlink", nt = "http://www.w3.org/2000/xmlns/", st = "http://www.w3.org/XML/1998/namespace", rt = "http://www.w3.org/2000/svg", V = (e) => typeof e.content == "function" ? e.content(e.loops || []) : e.content || "", ot = (e) => {
224
- const t = V(e), n = e.elm;
225
- n.textContent !== t && (n.textContent = t);
226
- }, D = (e, t, n = []) => {
227
- Object.keys(t).forEach((s) => {
228
- const o = t[s](n);
229
- e[s] !== o && (e[s] = o);
225
+ const yt = "http://www.w3.org/1999/xlink", wt = "http://www.w3.org/2000/xmlns/", At = "http://www.w3.org/XML/1998/namespace", xt = "http://www.w3.org/2000/svg", K = (e) => typeof e.content == "function" ? e.content(e.loops || []) : e.content || "", Ct = (e) => {
226
+ const t = K(e), s = e.elm;
227
+ s.textContent !== t && (s.textContent = t);
228
+ }, Z = (e, t, s = []) => {
229
+ Object.keys(t).forEach((n) => {
230
+ const r = t[n](s);
231
+ e[n] !== r && (e[n] = r);
232
+ });
233
+ }, G = (e, t) => {
234
+ const { styles: s, loops: n = [] } = t;
235
+ if (!s) return;
236
+ const r = s(n), o = H(r);
237
+ Object.entries(o).forEach(([i, a]) => {
238
+ e.style[i] = a;
230
239
  });
231
- }, O = (e, t) => {
232
- const { styles: n, attrs: s, loops: o = [] } = t;
233
- if (!n) return;
234
- const r = [];
235
- s != null && s.style && r.push(s.style);
236
- const a = n(o);
237
- r.push(...at(a)), e.style.cssText = r.join(";");
238
- }, _ = (e, t) => {
239
- const { classes: n, attrs: s, loops: o = [] } = t;
240
- if (!n) return;
241
- const r = [];
242
- s != null && s.class && r.push(...s.class.split(" ").filter((i) => i !== ""));
243
- const a = n(o);
244
- r.push(...ct(a)), e.className = Array.from(new Set(r)).join(" ");
245
- }, at = (e) => typeof e == "object" && !Array.isArray(e) ? Object.keys(e).map((t) => `${t}:${e[t]}`) : typeof e == "string" ? [e] : Array.isArray(e) ? e.flatMap(
246
- (t) => typeof t == "string" ? [t] : Object.keys(t).map((n) => `${n}:${t[n]}`)
247
- ) : [], ct = (e) => typeof e == "object" && !Array.isArray(e) ? Object.keys(e).filter((t) => e[t]).map((t) => t) : typeof e == "string" ? e.split(" ").filter((t) => t !== "") : Array.isArray(e) ? e.flatMap(
248
- (t) => typeof t == "string" ? t.split(" ").filter((n) => n !== "") : Object.keys(t).filter((n) => t[n])
249
- ) : [], it = (e, t) => {
250
- const n = t.elm;
251
- D(n, t.props, t.loops), _(n, t), O(n, t), z(n, e.children, t.children);
252
- }, lt = (e, t) => {
240
+ }, Y = (e, t) => {
241
+ const { classes: s, loops: n = [] } = t;
242
+ if (!s) return;
243
+ const r = s(n), o = N(r);
244
+ Object.entries(o).forEach(([i, a]) => {
245
+ a ? e.classList.add(i) : e.classList.remove(i);
246
+ });
247
+ }, H = (e) => {
248
+ let t = {};
249
+ return typeof e == "object" && e !== null && !Array.isArray(e) ? Object.entries(e).forEach(([s, n]) => {
250
+ if (typeof n == "object" && n !== null && !Array.isArray(n)) {
251
+ const r = H(n);
252
+ Object.entries(r).forEach(([o, i]) => {
253
+ t[`${s}-${o}`] = i;
254
+ });
255
+ } else typeof n == "string" || typeof n == "number" ? t[s] = `${n}` : t[s] = String(n);
256
+ }) : typeof e == "string" ? e.split(";").forEach((s) => {
257
+ const [n, r] = s.split(":").map((o) => o.trim());
258
+ n && r && (t[n] = r);
259
+ }) : Array.isArray(e) && e.forEach((s) => {
260
+ const n = H(s);
261
+ Object.entries(n).forEach(([r, o]) => {
262
+ t[r] = o;
263
+ });
264
+ }), t;
265
+ }, N = (e) => {
266
+ let t = {};
267
+ return typeof e == "object" && !Array.isArray(e) ? Object.entries(e).forEach(([s, n]) => {
268
+ t[s] = !!n;
269
+ }) : typeof e == "string" ? e.split(" ").forEach((s) => {
270
+ s !== "" && (t[s] = !0);
271
+ }) : Array.isArray(e) && e.forEach((s) => {
272
+ const n = N(s);
273
+ Object.entries(n).forEach(([r, o]) => {
274
+ t[r] = o;
275
+ });
276
+ }), t;
277
+ }, tt = (e, t, s) => {
278
+ const n = (r) => s.on[t](r, s.loops || []);
279
+ e.addEventListener(t, n, !1), s.handlers = s.handlers || {}, s.handlers[t] = n;
280
+ }, Rt = (e, t) => {
281
+ const s = t.elm;
282
+ Object.keys(t.on).forEach((n) => {
283
+ e.handlers && e.handlers[n] && s.removeEventListener(n, e.handlers[n], !1), tt(s, n, t);
284
+ }), Z(s, t.props, t.loops), Y(s, t), G(s, t), et(s, e.children, t.children);
285
+ }, It = (e, t) => {
253
286
  switch (t.elm = e.elm, t.tagName) {
254
287
  case "comment":
255
288
  break;
256
289
  case "text":
257
- ot(t);
290
+ Ct(t);
258
291
  break;
259
292
  case "slot":
260
293
  break;
261
294
  default:
262
- it(e, t);
295
+ Rt(e, t);
263
296
  break;
264
297
  }
265
- }, H = (e, t, n) => {
266
- n ? e.insertBefore(t, n) : e.appendChild(t);
267
- }, ut = (e, t, n) => {
268
- const s = V(t), o = document.createTextNode(s);
269
- t.elm = o, H(e, o, n);
270
- }, mt = (e, t, n) => {
271
- const s = t.content, o = document.createComment(s);
272
- t.elm = o, H(e, o, n);
273
- }, ft = (e, t, n, s) => {
274
- t.tagName === "svg" && (s = rt);
275
- const o = s ? document.createElementNS(s, t.tagName) : document.createElement(t.tagName);
276
- Object.keys(t.attrs).forEach((r) => {
277
- const a = t.attrs[r] || "";
278
- r.charAt(0) !== "x" ? o.setAttribute(r, a) : r.startsWith("xml:") ? o.setAttributeNS(st, r, a) : r.startsWith("xlink:") ? o.setAttributeNS(et, r, a) : r.startsWith("xmlns:") ? o.setAttributeNS(nt, r, a) : o.setAttribute(r, a);
279
- }), Object.keys(t.on).forEach((r) => {
280
- o.addEventListener(r, (a) => t.on[r](a, t.loops || []), !1);
281
- }), D(o, t.props, t.loops), _(o, t), O(o, t), t.elm = o, H(e, o, n), t.tagName === "foreignObject" && (s = void 0), t.children.forEach((r) => {
282
- I(o, r, void 0, s);
298
+ }, V = (e, t, s) => {
299
+ s ? e.insertBefore(t, s) : e.appendChild(t);
300
+ }, kt = (e, t, s) => {
301
+ const n = K(t), r = document.createTextNode(n);
302
+ t.elm = r, V(e, r, s);
303
+ }, St = (e, t, s) => {
304
+ const n = t.content, r = document.createComment(n);
305
+ t.elm = r, V(e, r, s);
306
+ }, _t = (e, t, s, n) => {
307
+ t.tagName === "svg" && (n = xt);
308
+ const r = n ? document.createElementNS(n, t.tagName) : document.createElement(t.tagName);
309
+ Object.keys(t.attrs).forEach((o) => {
310
+ const i = t.attrs[o] || "";
311
+ o.charAt(0) !== "x" ? r.setAttribute(o, i) : o.startsWith("xml:") ? r.setAttributeNS(At, o, i) : o.startsWith("xlink:") ? r.setAttributeNS(yt, o, i) : o.startsWith("xmlns:") ? r.setAttributeNS(wt, o, i) : r.setAttribute(o, i);
312
+ }), Object.keys(t.on).forEach((o) => {
313
+ tt(r, o, t);
314
+ }), Z(r, t.props, t.loops), Y(r, t), G(r, t), t.elm = r, V(e, r, s), t.tagName === "foreignObject" && (n = void 0), t.children.forEach((o) => {
315
+ S(r, o, void 0, n);
283
316
  });
284
- }, I = (e, t, n, s) => {
317
+ }, S = (e, t, s, n) => {
285
318
  switch (t.tagName) {
286
319
  case "comment":
287
- mt(e, t, n);
320
+ St(e, t, s);
288
321
  break;
289
322
  case "text":
290
- ut(e, t, n);
323
+ kt(e, t, s);
291
324
  break;
292
325
  default:
293
- ft(e, t, n, s);
326
+ _t(e, t, s, n);
294
327
  break;
295
328
  }
296
- }, pt = (e) => e && (e.tagName === "ElseIf" || e.tagName === "comment"), ht = (e) => e && e.tagName === "Else", b = (e, t, n = [], s = 0, o = !0, r = !1) => {
297
- var a, i, m;
329
+ }, Pt = (e) => e && (e.tagName === "ElseIf" || e.tagName === "comment"), Wt = (e) => e && e.tagName === "Else", v = (e, t, s = [], n = 0, r = !0, o = !1) => {
330
+ var i, a, h;
298
331
  for (let l = 0; l < t.length; l++) {
299
332
  const c = t[l];
300
333
  if (c.tagName === "If") {
301
334
  let u = !1;
302
- for (((a = c.fn) == null ? void 0 : a.call(c, n)) && (b(e, c.children, n, s, !1, !0), u = !0); l + 1 < t.length && pt(t[l + 1]); )
303
- ((m = (i = t[l + 1]).fn) == null ? void 0 : m.call(i, n)) && !u && (b(e, t[l + 1].children, n, s, !1, !0), u = !0), l++;
304
- l + 1 < t.length && ht(t[l + 1]) && !u && (b(e, t[l + 1].children, n, s, !1, !0), u = !0), l++;
335
+ for (((i = c.fn) == null ? void 0 : i.call(c, s)) && (v(e, c.children, s, n, !1, !0), u = !0); l + 1 < t.length && Pt(t[l + 1]); )
336
+ ((h = (a = t[l + 1]).fn) == null ? void 0 : h.call(a, s)) && !u && (v(e, t[l + 1].children, s, n, !1, !0), u = !0), l++;
337
+ l + 1 < t.length && Wt(t[l + 1]) && (u || (v(e, t[l + 1].children, s, n, !1, !0), u = !0), l++);
305
338
  } else if (c.tagName === "For") {
306
- const { item: u = "item", index: A = "index" } = c.attrs;
307
- (c.fn(n) || []).forEach((L, C) => {
308
- const B = { item: u, value: L, index: A, valueIndex: C };
309
- b(e, c.children, [...n, B], s, !1);
339
+ const { item: u = "item", index: I = "index" } = c.attrs;
340
+ (c.fn(s) || []).forEach((D, O) => {
341
+ const ct = { item: u, value: D, index: I, valueIndex: O };
342
+ v(e, c.children, [...s, ct], n, !1);
310
343
  });
311
344
  } else {
312
345
  const u = {
313
346
  ...c,
314
- loops: n,
347
+ loops: s,
315
348
  children: [],
316
- rootId: s,
317
- isIf: r
349
+ rootId: n,
350
+ isIf: o
318
351
  };
319
- b(u.children, c.children, n), e.push(u);
352
+ v(u.children, c.children, s), e.push(u);
320
353
  }
321
- o && s++;
354
+ r && n++;
322
355
  }
323
- }, z = (e, t, n) => {
324
- var r, a, i, m, l;
325
- let s = 0, o = 0;
326
- for (; s < t.length && o < n.length; ) {
327
- const c = t[s], u = n[o];
328
- c.rootId === u.rootId ? (u.isIf ? ((r = c.elm) == null || r.remove(), I(e, u, (a = t[s + 1]) == null ? void 0 : a.elm)) : lt(c, u), o++, s++) : c.rootId > u.rootId ? ((i = c.elm) == null || i.remove(), s++) : (I(e, u, (m = t[s + 1]) == null ? void 0 : m.elm), o++);
356
+ }, et = (e, t, s) => {
357
+ var o, i, a, h, l;
358
+ let n = 0, r = 0;
359
+ for (; n < t.length && r < s.length; ) {
360
+ const c = t[n], u = s[r];
361
+ c.rootId === u.rootId ? (u.isIf ? ((o = c.elm) == null || o.remove(), S(e, u, (i = t[n + 1]) == null ? void 0 : i.elm)) : It(c, u), r++, n++) : c.rootId > u.rootId ? ((a = c.elm) == null || a.remove(), n++) : (S(e, u, (h = t[n + 1]) == null ? void 0 : h.elm), r++);
329
362
  }
330
- for (; s < t.length; )
331
- (l = t[s].elm) == null || l.remove(), s++;
332
- for (; o < n.length; ) {
333
- const c = n[o];
334
- I(e, c), o++;
363
+ for (; n < t.length; )
364
+ (l = t[n].elm) == null || l.remove(), n++;
365
+ for (; r < s.length; ) {
366
+ const c = s[r];
367
+ S(e, c), r++;
335
368
  }
336
- }, j = (e, t, n = []) => {
369
+ }, Q = (e, t, s = []) => {
337
370
  if (!t || t.length === 0) return [];
338
- const s = [];
339
- return b(s, t || [], [], 0, !0), z(e, n, s), s;
340
- }, q = (e) => typeof e == "object" && e != null;
341
- var x, E, d, v, p, W, F;
342
- class yt extends HTMLElement {
371
+ const n = [];
372
+ return v(n, t || [], [], 0, !0), et(e, s, n), n;
373
+ }, st = (e) => typeof e == "object" && e != null;
374
+ function Ot(e = window.location) {
375
+ let t;
376
+ typeof e == "string" ? t = new URL(e).hash : t = e.hash;
377
+ const s = t.split("?"), n = s[0].substring(2), r = s[1], o = {};
378
+ return r && r.split("&").forEach((i) => {
379
+ const [a, h] = i.split("=");
380
+ a && h && (o[decodeURIComponent(a)] = decodeURIComponent(h));
381
+ }), {
382
+ path: n.split("/"),
383
+ // 将路径分割成数组
384
+ query: o
385
+ // 查询参数对象
386
+ };
387
+ }
388
+ const nt = (e, t) => new Proxy(e, {
389
+ get: (s, n) => {
390
+ let r = s[n];
391
+ return st(r) && (r = nt(r, t)), r;
392
+ },
393
+ set: (s, n, r) => (s[n] !== r && (s[n] = r, t(n, r)), !0)
394
+ });
395
+ var C, $, b, y, R, j;
396
+ class Dt extends HTMLElement {
343
397
  constructor() {
344
398
  super();
345
- y(this, p);
346
- y(this, x, {});
347
- y(this, E, []);
348
- y(this, d, []);
349
- y(this, v, !1);
350
- const n = this._manifest || {};
351
- n.template && typeof n.template == "string" && g(this, E, N(this, n.template)), (n.className || n.tagName || "").split(" ").forEach((o) => {
352
- this.classList.add(o);
353
- });
399
+ m(this, R);
400
+ m(this, C, {});
401
+ m(this, $, []);
402
+ m(this, b, []);
403
+ m(this, y, !1);
404
+ const s = this._manifest || {};
405
+ s.template && typeof s.template == "string" && p(this, $, bt(this, s.template));
354
406
  }
355
407
  get $data() {
356
- let n = h(this, x);
357
- return q(n) && (n = k(this, p, W).call(this, n)), n;
408
+ let s = f(this, C);
409
+ return st(s) && (s = nt(s, () => k(this, R, j).call(this))), s;
358
410
  }
359
- set $data(n) {
360
- g(this, x, n), k(this, p, F).call(this);
411
+ set $data(s) {
412
+ p(this, C, s || {}), k(this, R, j).call(this);
361
413
  }
362
414
  connectedCallback() {
363
- g(this, d, j(this, h(this, E), h(this, d))), this.onInit();
415
+ const s = this._manifest || {};
416
+ (s.className || s.tagName || "").split(" ").forEach((r) => {
417
+ this.classList.add(r);
418
+ }), p(this, b, Q(this, f(this, $), f(this, b))), this.onInit();
364
419
  }
365
420
  onInit() {
366
421
  }
@@ -368,35 +423,145 @@ class yt extends HTMLElement {
368
423
  console.log("disconnectedCallback");
369
424
  }
370
425
  }
371
- x = new WeakMap(), E = new WeakMap(), d = new WeakMap(), v = new WeakMap(), p = new WeakSet(), W = function(n) {
372
- return new Proxy(n, {
373
- get: (s, o) => {
374
- let r = s[o];
375
- return q(r) && (r = k(this, p, W).call(this, r)), r;
376
- },
377
- set: (s, o, r) => (s[o] !== r && (s[o] = r, k(this, p, F).call(this)), !0)
378
- });
379
- }, F = function() {
380
- h(this, v) || (g(this, v, !0), Y(() => {
381
- g(this, d, j(this, h(this, E), h(this, d))), g(this, v, !1);
426
+ C = new WeakMap(), $ = new WeakMap(), b = new WeakMap(), y = new WeakMap(), R = new WeakSet(), j = function() {
427
+ f(this, y) || (p(this, y, !0), vt(() => {
428
+ p(this, b, Q(this, f(this, $), f(this, b))), p(this, y, !1);
382
429
  }));
383
430
  };
384
- const bt = (e) => (t) => {
431
+ const Tt = (e) => (t) => {
385
432
  if (customElements.get(e.tagName)) {
386
433
  console.warn(`标签名称 "${e.tagName}" 已经被注册`);
387
434
  return;
388
435
  }
389
- return t.prototype._manifest = gt(e), customElements.define(e.tagName, t), t;
390
- }, gt = (e) => (e = Object.assign({
436
+ return t.prototype._manifest = qt(e), customElements.define(e.tagName, t), t;
437
+ }, qt = (e) => (e = Object.assign({
391
438
  hasConfig: !1
392
439
  }, e), e);
440
+ var w, A, P, rt;
441
+ const g = class g {
442
+ constructor() {
443
+ m(this, P);
444
+ m(this, A, []);
445
+ // 存储订阅者回调函数
446
+ z(this, "subscribers", []);
447
+ if (new.target === g)
448
+ return f(g, w) || p(g, w, this), f(g, w);
449
+ }
450
+ // 设置路由数据
451
+ setRoutes(t) {
452
+ p(this, A, t), k(this, P, rt).call(this);
453
+ }
454
+ // 获取路由数据
455
+ getRoutes() {
456
+ return f(this, A);
457
+ }
458
+ // 订阅路由更新事件
459
+ subscribe(t) {
460
+ this.subscribers.push(t);
461
+ }
462
+ // 取消订阅
463
+ unsubscribe(t) {
464
+ const s = this.subscribers.indexOf(t);
465
+ s > -1 && this.subscribers.splice(s, 1);
466
+ }
467
+ };
468
+ w = new WeakMap(), A = new WeakMap(), P = new WeakSet(), // 通知所有订阅者路由数据已更新
469
+ rt = function() {
470
+ this.subscribers.forEach((t) => t(f(this, A)));
471
+ }, // 单例模式
472
+ m(g, w);
473
+ let M = g;
474
+ const ot = new M();
475
+ var it = Object.defineProperty, Lt = Object.getOwnPropertyDescriptor, at = (e) => {
476
+ throw TypeError(e);
477
+ }, Ft = (e, t, s) => t in e ? it(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, Ht = (e, t, s, n) => {
478
+ for (var r = n > 1 ? void 0 : n ? Lt(t, s) : t, o = e.length - 1, i; o >= 0; o--)
479
+ (i = e[o]) && (r = (n ? i(t, s, r) : i(r)) || r);
480
+ return n && r && it(t, s, r), r;
481
+ }, E = (e, t, s) => Ft(e, typeof t != "symbol" ? t + "" : t, s), jt = (e, t, s) => t.has(e) || at("Cannot " + s), Mt = (e, t, s) => t.has(e) ? at("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), F = (e, t, s) => (jt(e, t, "access private method"), s), x, _;
482
+ let X = class extends HTMLElement {
483
+ // 路由参数
484
+ constructor() {
485
+ super(), Mt(this, x), E(this, "$elm"), E(this, "$routes", []), E(this, "$matchedRoute", null), E(this, "$remainingPath", []), E(this, "$query", {}), E(this, "$params", {}), this.$elm = this, window.addEventListener("hashchange", F(this, x, _).bind(this));
486
+ }
487
+ connectedCallback() {
488
+ F(this, x, _).call(this), ot.subscribe(() => {
489
+ F(this, x, _).call(this);
490
+ });
491
+ }
492
+ disconnectedCallback() {
493
+ }
494
+ matchRoute() {
495
+ for (const e of this.$routes) {
496
+ const t = e.path.split("/");
497
+ let s = !0;
498
+ for (let n = 0; n < t.length; n++)
499
+ if (t[n].startsWith(":"))
500
+ this.$params[t[n].substring(1)] = this.$remainingPath[n];
501
+ else {
502
+ if (t[n] === "*")
503
+ break;
504
+ if (t[n] !== this.$remainingPath[n]) {
505
+ s = !1;
506
+ break;
507
+ }
508
+ }
509
+ if (s) {
510
+ this.$matchedRoute = e, this.$remainingPath = this.$remainingPath.slice(t.length);
511
+ return;
512
+ }
513
+ }
514
+ this.$matchedRoute = null;
515
+ }
516
+ // 寻找包含 'router-view' 属性的祖辈节点
517
+ findAncestorWithRouterView(e) {
518
+ let t = e.parentNode;
519
+ for (; t; ) {
520
+ if (t.hasAttribute("router-view"))
521
+ return t;
522
+ t = t.parentElement;
523
+ }
524
+ return null;
525
+ }
526
+ };
527
+ x = /* @__PURE__ */ new WeakSet();
528
+ _ = function() {
529
+ const e = this.findAncestorWithRouterView(this.$elm);
530
+ if (e)
531
+ this.$remainingPath = e.$remainingPath, this.$query = e.$query, this.$routes = e.$matchRoute.children || [];
532
+ else {
533
+ const { path: s, query: n } = Ot(window.location);
534
+ this.$remainingPath = s, this.$query = n, this.$routes = ot.getRoutes();
535
+ }
536
+ this.matchRoute();
537
+ let t;
538
+ if (this.$matchedRoute) {
539
+ t = this.$matchedRoute.elm || document.createElement(this.$matchedRoute.tagName);
540
+ for (const [s, n] of Object.entries(this.$params))
541
+ t.setAttribute(s, n);
542
+ for (const [s, n] of Object.entries(this.$query))
543
+ t.setAttribute(s, n);
544
+ this.$matchedRoute.elm = t;
545
+ } else
546
+ t = document.createElement("error-not-found"), t.innerHTML = "<h1>404 Not Found</h1>";
547
+ this.$elm !== t && (this.$elm.replaceWith(t), this.$elm = t);
548
+ };
549
+ X = Ht([
550
+ Tt({
551
+ tagName: "router-view"
552
+ })
553
+ ], X);
393
554
  export {
394
- yt as BaseElement,
395
- bt as CustomElement,
396
- P as createFunction,
397
- q as isObject,
398
- U as listeners,
399
- N as parseHtml,
400
- j as patch,
401
- Y as runInAsyncQueue
555
+ Dt as BaseElement,
556
+ Tt as CustomElement,
557
+ X as RouterViewElement,
558
+ J as createFunction,
559
+ st as isObject,
560
+ Et as listeners,
561
+ nt as observe,
562
+ Ot as parseHashUrl,
563
+ bt as parseHtml,
564
+ Q as patch,
565
+ ot as router,
566
+ vt as runInAsyncQueue
402
567
  };
@@ -1 +1 @@
1
- (function(i,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(i=typeof globalThis<"u"?globalThis:i||self,f(i.solely={}))})(this,function(i){"use strict";var G=i=>{throw TypeError(i)};var O=(i,f,h)=>f.has(i)||G("Cannot "+h);var b=(i,f,h)=>(O(i,f,"read from private field"),h?h.call(i):f.get(i)),I=(i,f,h)=>f.has(i)?G("Cannot add the same private member more than once"):f instanceof WeakSet?f.add(i):f.set(i,h),E=(i,f,h,S)=>(O(i,f,"write to private field"),S?S.call(i,h):f.set(i,h),h),C=(i,f,h)=>(O(i,f,"access private method"),h);var x,k,y,A,g,P,q;const f=/<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g,h=/<\/?([^\s]+?)[/\s>]/,S=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g,N=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],w=/\{\{(.+?)\}\}/g;function U(e){return e.replace(/>\s+</g,"><").replace(/\s+/g," ")}function Y(e,t){const n=(t.match(h)||[])[1]||"",s={rootId:0,tagName:n,attrs:{},props:{},on:{},children:[]},r=new RegExp(S);for(;;){const o=r.exec(t);if(o===null)break;if(!o[0].trim())continue;const[a,l]=o[1]?o[1].trim().split("="):[o[2],o[3].trim().slice(1,-1)];if(D.includes(a)||a.startsWith("on-"))s.on[a.startsWith("on-")?a.slice(3):a.slice(2)]=B(e,`return (${l})`);else if(a.startsWith("s-")){const p=a.slice(2);switch(p){case"model":s.model=l;break;case"style":s.styles=u=>d(e,l,u);break;case"class":s.classes=u=>d(e,l,u);break;case"readonly":s.props.readOnly=u=>d(e,l,u);break;default:s.props[p]=u=>d(e,l,u);break}}else s.attrs[a]=l;r.lastIndex--}if(n==="For"?s.fn=o=>d(e,s.attrs.each,o):(n==="If"||n==="ElseIf")&&(s.fn=o=>d(e,s.attrs.condition,o)),s.model){const o=s.model.replace("this.","").replace("$data.",""),a=p=>d(e,`$data.${o}`,p),l=p=>B(e,`$data.${o}=${p}`);n==="input"?s.attrs.type==="checkbox"||s.attrs.type==="radio"?(s.props.checked=a,s.on.change=l("checked")):(s.props.value=a,s.on.input=l("value")):n==="textarea"?(s.props.value=a,s.on.input=l("value")):n==="select"&&(s.props.value=a,s.on.change=l("value"))}return s}function V(e,t){const n=[];if(!t)return n;t=U(t);const s=[],r=[],o=()=>{var l;return s.length===0?n:(l=s[s.length-1]).children||(l.children=[])};let a=0;return t.replace(f,(l,p)=>{const u=o();if(p>a){const c=t.substring(a,p).trim();if(c){w.lastIndex=0;const T=!w.test(c)?c:L=>c.replace(w,(Z,R)=>d(e,R,L));u.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:T,children:[]})}}if(a=p+l.length,l.startsWith("<!--")&&l.endsWith("-->"))u.push({rootId:0,tagName:"comment",attrs:{},props:{},on:{},content:l.slice(4,-3),children:[]});else if(l.startsWith("</")){const c=r.pop();for(;s.length>0&&s[s.length-1].tagName!==c;)s.pop();s.pop()}else{const c=Y(e,l),m=l.endsWith("/>")||N.includes(c.tagName);u.push(c),m||(s.push(c),r.push(c.tagName))}return""}),t.length>a&&n.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:t.substring(a).trim(),children:[]}),n}const d=(e,t,n)=>{try{return W(["$data",...n.map(r=>r.item),`return (${t})`]).bind(e)(e.$data,...n.map(r=>r.value))}catch(s){console.error(s)}},B=(e,t)=>(n,s)=>W(["$data","event","value","checked",...s.map(o=>o.item),t]).bind(e)(e.$data,n,n.target.value,n.target.checked,...s.map(o=>o.value)),D=["onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragexit","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onwheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting"],Q=(()=>{const e=typeof requestAnimationFrame=="function"?t=>requestAnimationFrame(t):typeof Promise<"u"?t=>Promise.resolve().then(t):t=>setTimeout(t,0);return(t,...n)=>{if(typeof t!="function")throw new Error("runInAsyncQueue expects a function as its first argument");e(()=>t(...n))}})(),F={};function W(e){const t=e.join(",");if(!F[t]){const n=e[e.length-1];if(n.trim()==="")throw new Error("Function body is empty");if(tt(n))throw new Error("Input contains potentially dangerous code: "+n);const s=new Function(...e);F[t]=s}return F[t]}function tt(e){return["eval","Function","setTimeout","setInterval","window","global","require","XMLHttpRequest","fetch","console","debugger","process","document","importScripts","String.raw","Object.prototype","JSON.parse"].some(n=>e.includes(n))}const et="http://www.w3.org/1999/xlink",nt="http://www.w3.org/2000/xmlns/",st="http://www.w3.org/XML/1998/namespace",ot="http://www.w3.org/2000/svg",_=e=>typeof e.content=="function"?e.content(e.loops||[]):e.content||"",rt=e=>{const t=_(e),n=e.elm;n.textContent!==t&&(n.textContent=t)},z=(e,t,n=[])=>{Object.keys(t).forEach(s=>{const r=t[s](n);e[s]!==r&&(e[s]=r)})},X=(e,t)=>{const{styles:n,attrs:s,loops:r=[]}=t;if(!n)return;const o=[];s!=null&&s.style&&o.push(s.style);const a=n(r);o.push(...at(a)),e.style.cssText=o.join(";")},J=(e,t)=>{const{classes:n,attrs:s,loops:r=[]}=t;if(!n)return;const o=[];s!=null&&s.class&&o.push(...s.class.split(" ").filter(l=>l!==""));const a=n(r);o.push(...ct(a)),e.className=Array.from(new Set(o)).join(" ")},at=e=>typeof e=="object"&&!Array.isArray(e)?Object.keys(e).map(t=>`${t}:${e[t]}`):typeof e=="string"?[e]:Array.isArray(e)?e.flatMap(t=>typeof t=="string"?[t]:Object.keys(t).map(n=>`${n}:${t[n]}`)):[],ct=e=>typeof e=="object"&&!Array.isArray(e)?Object.keys(e).filter(t=>e[t]).map(t=>t):typeof e=="string"?e.split(" ").filter(t=>t!==""):Array.isArray(e)?e.flatMap(t=>typeof t=="string"?t.split(" ").filter(n=>n!==""):Object.keys(t).filter(n=>t[n])):[],it=(e,t)=>{const n=t.elm;z(n,t.props,t.loops),J(n,t),X(n,t),K(n,e.children,t.children)},lt=(e,t)=>{switch(t.elm=e.elm,t.tagName){case"comment":break;case"text":rt(t);break;case"slot":break;default:it(e,t);break}},j=(e,t,n)=>{n?e.insertBefore(t,n):e.appendChild(t)},ut=(e,t,n)=>{const s=_(t),r=document.createTextNode(s);t.elm=r,j(e,r,n)},ft=(e,t,n)=>{const s=t.content,r=document.createComment(s);t.elm=r,j(e,r,n)},mt=(e,t,n,s)=>{t.tagName==="svg"&&(s=ot);const r=s?document.createElementNS(s,t.tagName):document.createElement(t.tagName);Object.keys(t.attrs).forEach(o=>{const a=t.attrs[o]||"";o.charAt(0)!=="x"?r.setAttribute(o,a):o.startsWith("xml:")?r.setAttributeNS(st,o,a):o.startsWith("xlink:")?r.setAttributeNS(et,o,a):o.startsWith("xmlns:")?r.setAttributeNS(nt,o,a):r.setAttribute(o,a)}),Object.keys(t.on).forEach(o=>{r.addEventListener(o,a=>t.on[o](a,t.loops||[]),!1)}),z(r,t.props,t.loops),J(r,t),X(r,t),t.elm=r,j(e,r,n),t.tagName==="foreignObject"&&(s=void 0),t.children.forEach(o=>{$(r,o,void 0,s)})},$=(e,t,n,s)=>{switch(t.tagName){case"comment":ft(e,t,n);break;case"text":ut(e,t,n);break;default:mt(e,t,n,s);break}},pt=e=>e&&(e.tagName==="ElseIf"||e.tagName==="comment"),ht=e=>e&&e.tagName==="Else",v=(e,t,n=[],s=0,r=!0,o=!1)=>{var a,l,p;for(let u=0;u<t.length;u++){const c=t[u];if(c.tagName==="If"){let m=!1;for(((a=c.fn)==null?void 0:a.call(c,n))&&(v(e,c.children,n,s,!1,!0),m=!0);u+1<t.length&&pt(t[u+1]);)((p=(l=t[u+1]).fn)==null?void 0:p.call(l,n))&&!m&&(v(e,t[u+1].children,n,s,!1,!0),m=!0),u++;u+1<t.length&&ht(t[u+1])&&!m&&(v(e,t[u+1].children,n,s,!1,!0),m=!0),u++}else if(c.tagName==="For"){const{item:m="item",index:T="index"}=c.attrs;(c.fn(n)||[]).forEach((Z,R)=>{const bt={item:m,value:Z,index:T,valueIndex:R};v(e,c.children,[...n,bt],s,!1)})}else{const m={...c,loops:n,children:[],rootId:s,isIf:o};v(m.children,c.children,n),e.push(m)}r&&s++}},K=(e,t,n)=>{var o,a,l,p,u;let s=0,r=0;for(;s<t.length&&r<n.length;){const c=t[s],m=n[r];c.rootId===m.rootId?(m.isIf?((o=c.elm)==null||o.remove(),$(e,m,(a=t[s+1])==null?void 0:a.elm)):lt(c,m),r++,s++):c.rootId>m.rootId?((l=c.elm)==null||l.remove(),s++):($(e,m,(p=t[s+1])==null?void 0:p.elm),r++)}for(;s<t.length;)(u=t[s].elm)==null||u.remove(),s++;for(;r<n.length;){const c=n[r];$(e,c),r++}},H=(e,t,n=[])=>{if(!t||t.length===0)return[];const s=[];return v(s,t||[],[],0,!0),K(e,n,s),s},M=e=>typeof e=="object"&&e!=null;class dt extends HTMLElement{constructor(){super();I(this,g);I(this,x,{});I(this,k,[]);I(this,y,[]);I(this,A,!1);const n=this._manifest||{};n.template&&typeof n.template=="string"&&E(this,k,V(this,n.template)),(n.className||n.tagName||"").split(" ").forEach(r=>{this.classList.add(r)})}get $data(){let n=b(this,x);return M(n)&&(n=C(this,g,P).call(this,n)),n}set $data(n){E(this,x,n),C(this,g,q).call(this)}connectedCallback(){E(this,y,H(this,b(this,k),b(this,y))),this.onInit()}onInit(){}disconnectedCallback(){console.log("disconnectedCallback")}}x=new WeakMap,k=new WeakMap,y=new WeakMap,A=new WeakMap,g=new WeakSet,P=function(n){return new Proxy(n,{get:(s,r)=>{let o=s[r];return M(o)&&(o=C(this,g,P).call(this,o)),o},set:(s,r,o)=>(s[r]!==o&&(s[r]=o,C(this,g,q).call(this)),!0)})},q=function(){b(this,A)||(E(this,A,!0),Q(()=>{E(this,y,H(this,b(this,k),b(this,y))),E(this,A,!1)}))};const gt=e=>t=>{if(customElements.get(e.tagName)){console.warn(`标签名称 "${e.tagName}" 已经被注册`);return}return t.prototype._manifest=yt(e),customElements.define(e.tagName,t),t},yt=e=>(e=Object.assign({hasConfig:!1},e),e);i.BaseElement=dt,i.CustomElement=gt,i.createFunction=W,i.isObject=M,i.listeners=D,i.parseHtml=V,i.patch=H,i.runInAsyncQueue=Q,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.solely={}))})(this,function(a){"use strict";var Vt=Object.defineProperty;var mt=a=>{throw TypeError(a)};var Mt=(a,u,m)=>u in a?Vt(a,u,{enumerable:!0,configurable:!0,writable:!0,value:m}):a[u]=m;var pt=(a,u,m)=>Mt(a,typeof u!="symbol"?u+"":u,m),K=(a,u,m)=>u.has(a)||mt("Cannot "+m);var d=(a,u,m)=>(K(a,u,"read from private field"),m?m.call(a):u.get(a)),g=(a,u,m)=>u.has(a)?mt("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(a):u.set(a,m),b=(a,u,m,_)=>(K(a,u,"write to private field"),_?_.call(a,m):u.set(a,m),m),H=(a,u,m)=>(K(a,u,"access private method"),m);var k,A,v,C,P,Z,R,I,W,dt;const u=/<!--(?:.|\s)*?-->|<[a-zA-Z0-9\-/](?:"[^"]*"|'[^']*'|[^'">])*>/g,m=/<\/?([^\s]+?)[/\s>]/,_=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g,gt=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],j=/\{\{(.+?)\}\}/g;function bt(n){return n.replace(/>\s+</g,"><").replace(/\s+/g," ")}function Et(n,t){const e=(t.match(m)||[])[1]||"",s={rootId:0,tagName:e,attrs:{},props:{},on:{},children:[]},r=new RegExp(_);for(;;){const i=r.exec(t);if(i===null)break;if(!i[0].trim())continue;const[o,c]=i[1]?i[1].trim().split("="):[i[2],i[3].trim().slice(1,-1)];if(N.includes(o)||o.startsWith("on-"))s.on[o.startsWith("on-")?o.slice(3):o.slice(2)]=Y(n,`return (${c})`);else if(o.startsWith("s-")){const p=o.slice(2);switch(p){case"model":s.model=c;break;case"style":s.styles=h=>E(n,c,h);break;case"class":s.classes=h=>E(n,c,h);break;case"readonly":s.props.readOnly=h=>E(n,c,h);break;default:s.props[p]=h=>E(n,c,h);break}}else s.attrs[o]=c;r.lastIndex--}if(e==="For"?s.fn=i=>E(n,s.attrs.each,i):(e==="If"||e==="ElseIf")&&(s.fn=i=>E(n,s.attrs.condition,i)),s.model){const i=s.model.replace("this.","").replace("$data.",""),o=p=>E(n,`$data.${i}`,p),c=p=>Y(n,`$data.${i}=${p}`);e==="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")):e==="textarea"?(s.props.value=o,s.on.input=c("value")):e==="select"&&(s.props.value=o,s.on.change=c("value"))}return s}function G(n,t){const e=[];if(!t)return e;t=bt(t);const s=[],r=[],i=()=>{var c;return s.length===0?e:(c=s[s.length-1]).children||(c.children=[])};let o=0;return t.replace(u,(c,p)=>{const h=i();if(p>o){const l=t.substring(o,p).trim();if(l){j.lastIndex=0;const x=!j.test(l)?l:X=>l.replace(j,(ft,J)=>E(n,J,X));h.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:x,children:[]})}}if(o=p+c.length,c.startsWith("<!--")&&c.endsWith("-->"))h.push({rootId:0,tagName:"comment",attrs:{},props:{},on:{},content:c.slice(4,-3),children:[]});else if(c.startsWith("</")){const l=r.pop();for(;s.length>0&&s[s.length-1].tagName!==l;)s.pop();s.pop()}else{const l=Et(n,c),f=c.endsWith("/>")||gt.includes(l.tagName);h.push(l),f||(s.push(l),r.push(l.tagName))}return""}),t.length>o&&e.push({rootId:0,tagName:"text",attrs:{},props:{},on:{},content:t.substring(o).trim(),children:[]}),e}const E=(n,t,e)=>{try{return F(["$data",...e.map(r=>r.item),`return (${t})`]).bind(n)(n.$data,...e.map(r=>r.value))}catch(s){console.error(s)}},Y=(n,t)=>(e,s)=>F(["$data","event","value","checked",...s.map(i=>i.item),t]).bind(n)(n.$data,e,e.target.value,e.target.checked,...s.map(i=>i.value)),N=["onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragexit","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onwheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting"],tt=(()=>{const n=typeof requestAnimationFrame=="function"?t=>requestAnimationFrame(t):typeof Promise<"u"?t=>Promise.resolve().then(t):t=>setTimeout(t,0);return(t,...e)=>{if(typeof t!="function")throw new Error("runInAsyncQueue expects a function as its first argument");n(()=>t(...e))}})(),q={};function F(n){const t=n.join(",");if(!q[t]){const e=n[n.length-1];if(e.trim()==="")throw new Error("Function body is empty");if(vt(e))throw new Error("Input contains potentially dangerous code: "+e);const s=new Function(...n);q[t]=s}return q[t]}function vt(n){return["eval","Function","setTimeout","setInterval","window","global","require","XMLHttpRequest","fetch","console","debugger","process","document","importScripts","String.raw","Object.prototype","JSON.parse"].some(e=>n.includes(e))}const yt="http://www.w3.org/1999/xlink",$t="http://www.w3.org/2000/xmlns/",wt="http://www.w3.org/XML/1998/namespace",At="http://www.w3.org/2000/svg",et=n=>typeof n.content=="function"?n.content(n.loops||[]):n.content||"",Ct=n=>{const t=et(n),e=n.elm;e.textContent!==t&&(e.textContent=t)},nt=(n,t,e=[])=>{Object.keys(t).forEach(s=>{const r=t[s](e);n[s]!==r&&(n[s]=r)})},st=(n,t)=>{const{styles:e,loops:s=[]}=t;if(!e)return;const r=e(s),i=L(r);Object.entries(i).forEach(([o,c])=>{n.style[o]=c})},rt=(n,t)=>{const{classes:e,loops:s=[]}=t;if(!e)return;const r=e(s),i=it(r);Object.entries(i).forEach(([o,c])=>{c?n.classList.add(o):n.classList.remove(o)})},L=n=>{let t={};return typeof n=="object"&&n!==null&&!Array.isArray(n)?Object.entries(n).forEach(([e,s])=>{if(typeof s=="object"&&s!==null&&!Array.isArray(s)){const r=L(s);Object.entries(r).forEach(([i,o])=>{t[`${e}-${i}`]=o})}else typeof s=="string"||typeof s=="number"?t[e]=`${s}`:t[e]=String(s)}):typeof n=="string"?n.split(";").forEach(e=>{const[s,r]=e.split(":").map(i=>i.trim());s&&r&&(t[s]=r)}):Array.isArray(n)&&n.forEach(e=>{const s=L(e);Object.entries(s).forEach(([r,i])=>{t[r]=i})}),t},it=n=>{let t={};return typeof n=="object"&&!Array.isArray(n)?Object.entries(n).forEach(([e,s])=>{t[e]=!!s}):typeof n=="string"?n.split(" ").forEach(e=>{e!==""&&(t[e]=!0)}):Array.isArray(n)&&n.forEach(e=>{const s=it(e);Object.entries(s).forEach(([r,i])=>{t[r]=i})}),t},ot=(n,t,e)=>{const s=r=>e.on[t](r,e.loops||[]);n.addEventListener(t,s,!1),e.handlers=e.handlers||{},e.handlers[t]=s},Rt=(n,t)=>{const e=t.elm;Object.keys(t.on).forEach(s=>{n.handlers&&n.handlers[s]&&e.removeEventListener(s,n.handlers[s],!1),ot(e,s,t)}),nt(e,t.props,t.loops),rt(e,t),st(e,t),at(e,n.children,t.children)},It=(n,t)=>{switch(t.elm=n.elm,t.tagName){case"comment":break;case"text":Ct(t);break;case"slot":break;default:Rt(n,t);break}},V=(n,t,e)=>{e?n.insertBefore(t,e):n.appendChild(t)},St=(n,t,e)=>{const s=et(t),r=document.createTextNode(s);t.elm=r,V(n,r,e)},kt=(n,t,e)=>{const s=t.content,r=document.createComment(s);t.elm=r,V(n,r,e)},Pt=(n,t,e,s)=>{t.tagName==="svg"&&(s=At);const r=s?document.createElementNS(s,t.tagName):document.createElement(t.tagName);Object.keys(t.attrs).forEach(i=>{const o=t.attrs[i]||"";i.charAt(0)!=="x"?r.setAttribute(i,o):i.startsWith("xml:")?r.setAttributeNS(wt,i,o):i.startsWith("xlink:")?r.setAttributeNS(yt,i,o):i.startsWith("xmlns:")?r.setAttributeNS($t,i,o):r.setAttribute(i,o)}),Object.keys(t.on).forEach(i=>{ot(r,i,t)}),nt(r,t.props,t.loops),rt(r,t),st(r,t),t.elm=r,V(n,r,e),t.tagName==="foreignObject"&&(s=void 0),t.children.forEach(i=>{O(r,i,void 0,s)})},O=(n,t,e,s)=>{switch(t.tagName){case"comment":kt(n,t,e);break;case"text":St(n,t,e);break;default:Pt(n,t,e,s);break}},_t=n=>n&&(n.tagName==="ElseIf"||n.tagName==="comment"),Ot=n=>n&&n.tagName==="Else",$=(n,t,e=[],s=0,r=!0,i=!1)=>{var o,c,p;for(let h=0;h<t.length;h++){const l=t[h];if(l.tagName==="If"){let f=!1;for(((o=l.fn)==null?void 0:o.call(l,e))&&($(n,l.children,e,s,!1,!0),f=!0);h+1<t.length&&_t(t[h+1]);)((p=(c=t[h+1]).fn)==null?void 0:p.call(c,e))&&!f&&($(n,t[h+1].children,e,s,!1,!0),f=!0),h++;h+1<t.length&&Ot(t[h+1])&&(f||($(n,t[h+1].children,e,s,!1,!0),f=!0),h++)}else if(l.tagName==="For"){const{item:f="item",index:x="index"}=l.attrs;(l.fn(e)||[]).forEach((ft,J)=>{const Lt={item:f,value:ft,index:x,valueIndex:J};$(n,l.children,[...e,Lt],s,!1)})}else{const f={...l,loops:e,children:[],rootId:s,isIf:i};$(f.children,l.children,e),n.push(f)}r&&s++}},at=(n,t,e)=>{var i,o,c,p,h;let s=0,r=0;for(;s<t.length&&r<e.length;){const l=t[s],f=e[r];l.rootId===f.rootId?(f.isIf?((i=l.elm)==null||i.remove(),O(n,f,(o=t[s+1])==null?void 0:o.elm)):It(l,f),r++,s++):l.rootId>f.rootId?((c=l.elm)==null||c.remove(),s++):(O(n,f,(p=t[s+1])==null?void 0:p.elm),r++)}for(;s<t.length;)(h=t[s].elm)==null||h.remove(),s++;for(;r<e.length;){const l=e[r];O(n,l),r++}},M=(n,t,e=[])=>{if(!t||t.length===0)return[];const s=[];return $(s,t||[],[],0,!0),at(n,e,s),s},D=n=>typeof n=="object"&&n!=null;function ct(n=window.location){let t;typeof n=="string"?t=new URL(n).hash:t=n.hash;const e=t.split("?"),s=e[0].substring(2),r=e[1],i={};return r&&r.split("&").forEach(o=>{const[c,p]=o.split("=");c&&p&&(i[decodeURIComponent(c)]=decodeURIComponent(p))}),{path:s.split("/"),query:i}}const U=(n,t)=>new Proxy(n,{get:(e,s)=>{let r=e[s];return D(r)&&(r=U(r,t)),r},set:(e,s,r)=>(e[s]!==r&&(e[s]=r,t(s,r)),!0)});class Tt extends HTMLElement{constructor(){super();g(this,P);g(this,k,{});g(this,A,[]);g(this,v,[]);g(this,C,!1);const e=this._manifest||{};e.template&&typeof e.template=="string"&&b(this,A,G(this,e.template))}get $data(){let e=d(this,k);return D(e)&&(e=U(e,()=>H(this,P,Z).call(this))),e}set $data(e){b(this,k,e||{}),H(this,P,Z).call(this)}connectedCallback(){const e=this._manifest||{};(e.className||e.tagName||"").split(" ").forEach(r=>{this.classList.add(r)}),b(this,v,M(this,d(this,A),d(this,v))),this.onInit()}onInit(){}disconnectedCallback(){console.log("disconnectedCallback")}}k=new WeakMap,A=new WeakMap,v=new WeakMap,C=new WeakMap,P=new WeakSet,Z=function(){d(this,C)||(b(this,C,!0),tt(()=>{b(this,v,M(this,d(this,A),d(this,v))),b(this,C,!1)}))};const lt=n=>t=>{if(customElements.get(n.tagName)){console.warn(`标签名称 "${n.tagName}" 已经被注册`);return}return t.prototype._manifest=Wt(n),customElements.define(n.tagName,t),t},Wt=n=>(n=Object.assign({hasConfig:!1},n),n),y=class y{constructor(){g(this,W);g(this,I,[]);pt(this,"subscribers",[]);if(new.target===y)return d(y,R)||b(y,R,this),d(y,R)}setRoutes(t){b(this,I,t),H(this,W,dt).call(this)}getRoutes(){return d(this,I)}subscribe(t){this.subscribers.push(t)}unsubscribe(t){const e=this.subscribers.indexOf(t);e>-1&&this.subscribers.splice(e,1)}};R=new WeakMap,I=new WeakMap,W=new WeakSet,dt=function(){this.subscribers.forEach(t=>t(d(this,I)))},g(y,R);let B=y;const Q=new B;var ut=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,ht=n=>{throw TypeError(n)},Ht=(n,t,e)=>t in n?ut(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,jt=(n,t,e,s)=>{for(var r=s>1?void 0:s?xt(t,e):t,i=n.length-1,o;i>=0;i--)(o=n[i])&&(r=(s?o(t,e,r):o(r))||r);return s&&r&&ut(t,e,r),r},w=(n,t,e)=>Ht(n,typeof t!="symbol"?t+"":t,e),qt=(n,t,e)=>t.has(n)||ht("Cannot "+e),Ft=(n,t,e)=>t.has(n)?ht("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(n):t.set(n,e),z=(n,t,e)=>(qt(n,t,"access private method"),e),S,T;a.RouterViewElement=class extends HTMLElement{constructor(){super(),Ft(this,S),w(this,"$elm"),w(this,"$routes",[]),w(this,"$matchedRoute",null),w(this,"$remainingPath",[]),w(this,"$query",{}),w(this,"$params",{}),this.$elm=this,window.addEventListener("hashchange",z(this,S,T).bind(this))}connectedCallback(){z(this,S,T).call(this),Q.subscribe(()=>{z(this,S,T).call(this)})}disconnectedCallback(){}matchRoute(){for(const t of this.$routes){const e=t.path.split("/");let s=!0;for(let r=0;r<e.length;r++)if(e[r].startsWith(":"))this.$params[e[r].substring(1)]=this.$remainingPath[r];else{if(e[r]==="*")break;if(e[r]!==this.$remainingPath[r]){s=!1;break}}if(s){this.$matchedRoute=t,this.$remainingPath=this.$remainingPath.slice(e.length);return}}this.$matchedRoute=null}findAncestorWithRouterView(t){let e=t.parentNode;for(;e;){if(e.hasAttribute("router-view"))return e;e=e.parentElement}return null}},S=new WeakSet,T=function(){const n=this.findAncestorWithRouterView(this.$elm);if(n)this.$remainingPath=n.$remainingPath,this.$query=n.$query,this.$routes=n.$matchRoute.children||[];else{const{path:e,query:s}=ct(window.location);this.$remainingPath=e,this.$query=s,this.$routes=Q.getRoutes()}this.matchRoute();let t;if(this.$matchedRoute){t=this.$matchedRoute.elm||document.createElement(this.$matchedRoute.tagName);for(const[e,s]of Object.entries(this.$params))t.setAttribute(e,s);for(const[e,s]of Object.entries(this.$query))t.setAttribute(e,s);this.$matchedRoute.elm=t}else t=document.createElement("error-not-found"),t.innerHTML="<h1>404 Not Found</h1>";this.$elm!==t&&(this.$elm.replaceWith(t),this.$elm=t)},a.RouterViewElement=jt([lt({tagName:"router-view"})],a.RouterViewElement),a.BaseElement=Tt,a.CustomElement=lt,a.createFunction=F,a.isObject=D,a.listeners=N,a.observe=U,a.parseHashUrl=ct,a.parseHtml=G,a.patch=M,a.router=Q,a.runInAsyncQueue=tt,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
@@ -5,6 +5,7 @@ export interface Loop {
5
5
  valueIndex: number;
6
6
  }
7
7
  export interface ASTNode {
8
+ handlers?: Record<string, EventListenerOrEventListenerObject>;
8
9
  rootId: number;
9
10
  tagName: string;
10
11
  attrs: Record<string, string>;
@@ -4,3 +4,5 @@ export { runInAsyncQueue } from './async-queue';
4
4
  export { createFunction, type FunctionCreator } from './functions';
5
5
  export { patch } from './ast-processor';
6
6
  export { isObject } from './is-object';
7
+ export { parseHashUrl } from './url';
8
+ export { observe } from './observe';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 观察 value 的变化,并在变化时调用 callback
3
+ * @param value
4
+ * @param callback
5
+ * @returns
6
+ */
7
+ export declare const observe: (value: any, callback: (property: string | symbol, newValue: any) => void) => any;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 获取url参数,包含hash参数和查询参数
3
+ * @param location - 浏览器的location对象或者URL字符串
4
+ * @returns
5
+ */
6
+ export declare function parseHashUrl(location?: Location | string): {
7
+ path: string[];
8
+ query: {
9
+ [key: string]: string;
10
+ };
11
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solely",
3
3
  "private": false,
4
- "version": "0.0.11",
4
+ "version": "0.0.14",
5
5
  "type": "module",
6
6
  "module": "./dist/solely.js",
7
7
  "types": "./dist/solely.d.ts",
@@ -19,7 +19,9 @@
19
19
  "preview": "vite preview"
20
20
  },
21
21
  "devDependencies": {
22
+ "sass": "^1.83.0",
22
23
  "typescript": "~5.6.2",
23
- "vite": "^5.4.10"
24
+ "vite": "^5.4.10",
25
+ "vite-plugin-dts": "^4.4.0"
24
26
  }
25
- }
27
+ }
File without changes
File without changes