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