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