@jasonshimmy/custom-elements-runtime 2.2.4 → 2.2.5
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/custom-elements-runtime.cjs.js +5 -5
- package/dist/custom-elements-runtime.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.es.js +232 -216
- package/dist/custom-elements-runtime.es.js.map +1 -1
- package/dist/custom-elements-runtime.router.cjs.js +19 -17
- package/dist/custom-elements-runtime.router.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.router.es.js +181 -165
- package/dist/custom-elements-runtime.router.es.js.map +1 -1
- package/dist/custom-elements-runtime.transitions.cjs.js +1 -1
- package/dist/custom-elements-runtime.transitions.es.js +1 -1
- package/dist/router.d.ts +2 -2
- package/dist/{transitions-m6FraTTL.js → transitions-DCIjMqzG.js} +35 -34
- package/dist/{transitions-m6FraTTL.js.map → transitions-DCIjMqzG.js.map} +1 -1
- package/dist/{transitions-Bv8lUAOe.cjs → transitions-DHQuI3AY.cjs} +2 -2
- package/dist/{transitions-Bv8lUAOe.cjs.map → transitions-DHQuI3AY.cjs.map} +1 -1
- package/package.json +1 -1
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { component as P, html as R, useOnConnected as
|
|
2
|
-
import { r as
|
|
3
|
-
import { createStore as
|
|
4
|
-
import { d as
|
|
5
|
-
import { match as
|
|
6
|
-
const
|
|
1
|
+
import { component as P, html as R, useOnConnected as B, useOnDisconnected as U, useProps as V, useStyle as H } from "./custom-elements-runtime.es.js";
|
|
2
|
+
import { r as q, c as m } from "./namespace-helpers-Vwt2Fzds.js";
|
|
3
|
+
import { createStore as j } from "./custom-elements-runtime.store.es.js";
|
|
4
|
+
import { d as x, a as $ } from "./logger-BpibrmKL.js";
|
|
5
|
+
import { match as F } from "./custom-elements-runtime.directives.es.js";
|
|
6
|
+
const D = (c) => c ? typeof URLSearchParams > "u" ? {} : Object.fromEntries(new URLSearchParams(c)) : {}, S = (c, o) => {
|
|
7
7
|
for (const t of c) {
|
|
8
|
-
const
|
|
8
|
+
const h = [], l = t.path.replace(/:[^/]+/g, (i) => (h.push(i.slice(1)), "([^/]+)")), f = new RegExp(`^${l}$`), s = o.match(f);
|
|
9
9
|
if (s) {
|
|
10
|
-
const
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
}), { route: t, params:
|
|
10
|
+
const i = {};
|
|
11
|
+
return h.forEach((v, b) => {
|
|
12
|
+
i[v] = s[b + 1];
|
|
13
|
+
}), { route: t, params: i };
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
return { route: null, params: {} };
|
|
17
17
|
};
|
|
18
|
-
function
|
|
18
|
+
function A(c, o) {
|
|
19
19
|
for (const t of c)
|
|
20
|
-
if (
|
|
20
|
+
if (S([t], o).route !== null) return t;
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
const O = {};
|
|
24
|
-
async function
|
|
24
|
+
async function I(c) {
|
|
25
25
|
if (c.component) return c.component;
|
|
26
26
|
if (c.load) {
|
|
27
27
|
if (O[c.path]) return O[c.path];
|
|
@@ -34,175 +34,175 @@ async function W(c) {
|
|
|
34
34
|
}
|
|
35
35
|
throw new Error(`No component or loader defined for route: ${c.path}`);
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
const { routes: o, base: t = "", initialUrl:
|
|
39
|
-
let
|
|
40
|
-
const
|
|
41
|
-
const e =
|
|
37
|
+
function M(c) {
|
|
38
|
+
const { routes: o, base: t = "", initialUrl: h } = c;
|
|
39
|
+
let l, f, s, i, v, b, w;
|
|
40
|
+
const k = async (n, a) => {
|
|
41
|
+
const e = A(o, n.path);
|
|
42
42
|
if (!e || !e.beforeEnter) return !0;
|
|
43
43
|
try {
|
|
44
|
-
const r = await e.beforeEnter(
|
|
45
|
-
return typeof r == "string" ? (await
|
|
44
|
+
const r = await e.beforeEnter(n, a);
|
|
45
|
+
return typeof r == "string" ? (await g(r, !0), !1) : r !== !1;
|
|
46
46
|
} catch (r) {
|
|
47
|
-
return
|
|
47
|
+
return x("beforeEnter error", r), !1;
|
|
48
48
|
}
|
|
49
|
-
},
|
|
50
|
-
const e =
|
|
49
|
+
}, C = async (n, a) => {
|
|
50
|
+
const e = A(o, n.path);
|
|
51
51
|
if (!e || !e.onEnter) return !0;
|
|
52
52
|
try {
|
|
53
|
-
const r = await e.onEnter(
|
|
54
|
-
return typeof r == "string" ? (await
|
|
53
|
+
const r = await e.onEnter(n, a);
|
|
54
|
+
return typeof r == "string" ? (await g(r, !0), !1) : r !== !1;
|
|
55
55
|
} catch (r) {
|
|
56
|
-
return
|
|
56
|
+
return x("onEnter error", r), !1;
|
|
57
57
|
}
|
|
58
|
-
},
|
|
59
|
-
const e =
|
|
58
|
+
}, L = (n, a) => {
|
|
59
|
+
const e = A(o, n.path);
|
|
60
60
|
if (!(!e || !e.afterEnter))
|
|
61
61
|
try {
|
|
62
|
-
e.afterEnter(
|
|
62
|
+
e.afterEnter(n, a);
|
|
63
63
|
} catch (r) {
|
|
64
|
-
|
|
64
|
+
x("afterEnter error", r);
|
|
65
65
|
}
|
|
66
|
-
},
|
|
66
|
+
}, g = async (n, a = !1) => {
|
|
67
67
|
try {
|
|
68
68
|
const e = {
|
|
69
|
-
path:
|
|
69
|
+
path: n.replace(t, "") || "/",
|
|
70
70
|
query: {}
|
|
71
|
-
}, r =
|
|
71
|
+
}, r = S(o, e.path);
|
|
72
72
|
if (!r.route) throw new Error(`No route found for ${e.path}`);
|
|
73
|
-
const
|
|
73
|
+
const p = s.getState(), u = {
|
|
74
74
|
path: e.path,
|
|
75
75
|
params: r.params,
|
|
76
76
|
query: e.query
|
|
77
77
|
};
|
|
78
|
-
if (!await
|
|
79
|
-
typeof window < "u" && typeof document < "u" && (
|
|
78
|
+
if (!await k(u, p) || !await C(u, p)) return;
|
|
79
|
+
typeof window < "u" && typeof document < "u" && (a ? window.history.replaceState({}, "", t + n) : window.history.pushState({}, "", t + n)), s.setState(u), L(u, p);
|
|
80
80
|
} catch (e) {
|
|
81
|
-
|
|
81
|
+
x("Navigation error:", e);
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
|
-
if (typeof window < "u" && typeof document < "u" && typeof
|
|
85
|
-
|
|
86
|
-
const
|
|
84
|
+
if (typeof window < "u" && typeof document < "u" && typeof h > "u") {
|
|
85
|
+
l = () => {
|
|
86
|
+
const a = new URL(window.location.href), e = a.pathname.replace(t, "") || "/", r = D(a.search);
|
|
87
87
|
return { path: e, query: r };
|
|
88
|
-
},
|
|
89
|
-
const
|
|
90
|
-
s =
|
|
91
|
-
path:
|
|
92
|
-
params:
|
|
93
|
-
query:
|
|
94
|
-
}),
|
|
95
|
-
const e =
|
|
96
|
-
await
|
|
97
|
-
}, window.addEventListener("popstate", () =>
|
|
88
|
+
}, f = l();
|
|
89
|
+
const n = S(o, f.path);
|
|
90
|
+
s = j({
|
|
91
|
+
path: f.path,
|
|
92
|
+
params: n.params,
|
|
93
|
+
query: f.query
|
|
94
|
+
}), i = async (a = !1) => {
|
|
95
|
+
const e = l();
|
|
96
|
+
await g(e.path, a);
|
|
97
|
+
}, window.addEventListener("popstate", () => i(!0)), v = (a) => g(a, !1), b = (a) => g(a, !0), w = () => window.history.back();
|
|
98
98
|
} else {
|
|
99
|
-
|
|
100
|
-
const e = new URL(
|
|
101
|
-
return { path: r, query:
|
|
102
|
-
},
|
|
103
|
-
const
|
|
104
|
-
s =
|
|
105
|
-
path:
|
|
106
|
-
params:
|
|
107
|
-
query:
|
|
108
|
-
}),
|
|
109
|
-
const e =
|
|
110
|
-
await
|
|
99
|
+
l = () => {
|
|
100
|
+
const e = new URL(h || "/", "http://localhost"), r = e.pathname.replace(t, "") || "/", p = D(e.search);
|
|
101
|
+
return { path: r, query: p };
|
|
102
|
+
}, f = l();
|
|
103
|
+
const n = S(o, f.path);
|
|
104
|
+
s = j({
|
|
105
|
+
path: f.path,
|
|
106
|
+
params: n.params,
|
|
107
|
+
query: f.query
|
|
108
|
+
}), i = async () => {
|
|
109
|
+
const e = l();
|
|
110
|
+
await a(e.path);
|
|
111
111
|
};
|
|
112
|
-
const
|
|
112
|
+
const a = async (e) => {
|
|
113
113
|
try {
|
|
114
114
|
const r = {
|
|
115
115
|
path: e.replace(t, "") || "/",
|
|
116
116
|
query: {}
|
|
117
|
-
},
|
|
118
|
-
if (!
|
|
119
|
-
const
|
|
117
|
+
}, p = S(o, r.path);
|
|
118
|
+
if (!p.route) throw new Error(`No route found for ${r.path}`);
|
|
119
|
+
const u = s.getState(), d = {
|
|
120
120
|
path: r.path,
|
|
121
|
-
params:
|
|
121
|
+
params: p.params,
|
|
122
122
|
query: r.query
|
|
123
|
-
},
|
|
124
|
-
if (
|
|
125
|
-
const E = await
|
|
123
|
+
}, y = A(o, d.path);
|
|
124
|
+
if (y?.beforeEnter) {
|
|
125
|
+
const E = await y.beforeEnter(d, u);
|
|
126
126
|
if (typeof E == "string") {
|
|
127
|
-
await
|
|
127
|
+
await a(E);
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
130
|
if (E === !1) return;
|
|
131
131
|
}
|
|
132
|
-
if (
|
|
133
|
-
const E = await
|
|
132
|
+
if (y?.onEnter) {
|
|
133
|
+
const E = await y.onEnter(d, u);
|
|
134
134
|
if (typeof E == "string") {
|
|
135
|
-
await
|
|
135
|
+
await a(E);
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
138
138
|
if (E === !1) return;
|
|
139
139
|
}
|
|
140
|
-
s.setState(
|
|
140
|
+
s.setState(d), y?.afterEnter && y.afterEnter(d, u);
|
|
141
141
|
} catch (r) {
|
|
142
|
-
throw
|
|
142
|
+
throw x("SSR navigation error:", r), r;
|
|
143
143
|
}
|
|
144
144
|
};
|
|
145
|
-
|
|
145
|
+
v = async (e) => a(e), b = async (e) => a(e), w = () => {
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
148
|
return {
|
|
149
149
|
store: s,
|
|
150
|
-
push:
|
|
151
|
-
replace:
|
|
152
|
-
back:
|
|
150
|
+
push: v,
|
|
151
|
+
replace: b,
|
|
152
|
+
back: w,
|
|
153
153
|
subscribe: s.subscribe,
|
|
154
|
-
matchRoute: (
|
|
154
|
+
matchRoute: (n) => S(o, n),
|
|
155
155
|
getCurrent: () => s.getState(),
|
|
156
|
-
resolveRouteComponent:
|
|
156
|
+
resolveRouteComponent: I
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
-
function
|
|
160
|
-
return
|
|
159
|
+
function G(c, o) {
|
|
160
|
+
return S(c, o);
|
|
161
161
|
}
|
|
162
162
|
let N = null;
|
|
163
|
-
function
|
|
164
|
-
const o =
|
|
163
|
+
function J(c) {
|
|
164
|
+
const o = M(c);
|
|
165
165
|
return N = o, P("router-view", async () => {
|
|
166
166
|
const t = N || o;
|
|
167
167
|
if (!t) return R`<div>Router not initialized.</div>`;
|
|
168
|
-
const
|
|
169
|
-
let
|
|
170
|
-
|
|
168
|
+
const h = q(t.getCurrent());
|
|
169
|
+
let l;
|
|
170
|
+
B(() => {
|
|
171
171
|
try {
|
|
172
|
-
t && typeof t.subscribe == "function" && (
|
|
172
|
+
t && typeof t.subscribe == "function" && (l = t.subscribe((s) => {
|
|
173
173
|
try {
|
|
174
|
-
|
|
175
|
-
} catch (
|
|
176
|
-
|
|
174
|
+
h.value = s;
|
|
175
|
+
} catch (i) {
|
|
176
|
+
$("router-view subscription update failed", i);
|
|
177
177
|
}
|
|
178
178
|
}));
|
|
179
179
|
} catch (s) {
|
|
180
|
-
|
|
180
|
+
$("router-view subscribe failed", s);
|
|
181
181
|
}
|
|
182
|
-
}),
|
|
183
|
-
if (typeof
|
|
182
|
+
}), U(() => {
|
|
183
|
+
if (typeof l == "function")
|
|
184
184
|
try {
|
|
185
|
-
|
|
185
|
+
l();
|
|
186
186
|
} catch (s) {
|
|
187
|
-
|
|
187
|
+
$("router-view unsubscribe failed", s);
|
|
188
188
|
}
|
|
189
189
|
});
|
|
190
|
-
const
|
|
191
|
-
if (!
|
|
190
|
+
const f = t.matchRoute(h.value.path);
|
|
191
|
+
if (!f || !f.route) return R`<div>Not found</div>`;
|
|
192
192
|
try {
|
|
193
|
-
const
|
|
194
|
-
if (typeof
|
|
195
|
-
return { tag:
|
|
196
|
-
if (typeof
|
|
197
|
-
const
|
|
198
|
-
return (
|
|
193
|
+
const i = await t.resolveRouteComponent(f.route);
|
|
194
|
+
if (typeof i == "string")
|
|
195
|
+
return { tag: i, props: {}, children: [] };
|
|
196
|
+
if (typeof i == "function") {
|
|
197
|
+
const v = i();
|
|
198
|
+
return (v instanceof Promise ? v : Promise.resolve(v)).then((w) => typeof w == "string" ? { tag: w, props: {}, children: [] } : w);
|
|
199
199
|
}
|
|
200
200
|
return R`<div>Invalid route component</div>`;
|
|
201
201
|
} catch {
|
|
202
202
|
return R`<div>Invalid route component</div>`;
|
|
203
203
|
}
|
|
204
204
|
}), P("router-link", () => {
|
|
205
|
-
const t =
|
|
205
|
+
const t = V({
|
|
206
206
|
to: "",
|
|
207
207
|
tag: "a",
|
|
208
208
|
replace: !1,
|
|
@@ -212,67 +212,82 @@ function K(c) {
|
|
|
212
212
|
ariaCurrentValue: "page",
|
|
213
213
|
disabled: !1,
|
|
214
214
|
external: !1,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
),
|
|
215
|
+
// allow host `class` and `style` attributes to be read via useProps
|
|
216
|
+
class: "",
|
|
217
|
+
style: ""
|
|
218
|
+
}), h = N || o, l = q(h.getCurrent());
|
|
219
|
+
let f;
|
|
220
|
+
H(() => "a,button{display:inline-block;}");
|
|
221
|
+
const s = q(t.class || ""), i = q(t.style || "");
|
|
222
|
+
B((p) => {
|
|
222
223
|
try {
|
|
223
|
-
|
|
224
|
+
h && typeof h.subscribe == "function" && (f = h.subscribe((u) => {
|
|
224
225
|
try {
|
|
225
|
-
|
|
226
|
-
} catch (
|
|
227
|
-
|
|
226
|
+
l.value = u;
|
|
227
|
+
} catch (d) {
|
|
228
|
+
$("router-link subscription update failed", d);
|
|
228
229
|
}
|
|
229
230
|
}));
|
|
230
|
-
} catch (
|
|
231
|
-
|
|
231
|
+
} catch (u) {
|
|
232
|
+
$("router-link subscribe failed", u);
|
|
232
233
|
}
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
try {
|
|
235
|
+
const u = p?._host;
|
|
236
|
+
if (u instanceof HTMLElement) {
|
|
237
|
+
const d = u.getAttribute("class"), y = u.getAttribute("style");
|
|
238
|
+
d && (s.value = d), y && (i.value = y), d !== null && u.removeAttribute("class"), y !== null && u.removeAttribute("style");
|
|
239
|
+
}
|
|
240
|
+
} catch (u) {
|
|
241
|
+
$("router-link host migration failed", u);
|
|
242
|
+
}
|
|
243
|
+
}), U(() => {
|
|
244
|
+
if (typeof f == "function")
|
|
235
245
|
try {
|
|
236
|
-
|
|
237
|
-
} catch (
|
|
238
|
-
|
|
246
|
+
f();
|
|
247
|
+
} catch (p) {
|
|
248
|
+
$("router-link unsubscribe failed", p);
|
|
239
249
|
}
|
|
240
250
|
});
|
|
241
|
-
const
|
|
242
|
-
() =>
|
|
243
|
-
),
|
|
244
|
-
() => t.exact ?
|
|
245
|
-
),
|
|
246
|
-
const
|
|
247
|
-
for (const
|
|
248
|
-
return
|
|
249
|
-
}),
|
|
250
|
-
...
|
|
251
|
-
[t.activeClass || "active"]:
|
|
252
|
-
[t.exactActiveClass || "exact-active"]:
|
|
253
|
-
})),
|
|
254
|
-
() =>
|
|
255
|
-
),
|
|
251
|
+
const v = m(
|
|
252
|
+
() => l.value.path === t.to
|
|
253
|
+
), b = m(
|
|
254
|
+
() => t.exact ? v.value : l.value && typeof l.value.path == "string" ? l.value.path.startsWith(t.to) : !1
|
|
255
|
+
), w = m(() => {
|
|
256
|
+
const u = (s && s.value || t.class || "").split(/\s+/).filter(Boolean), d = {};
|
|
257
|
+
for (const y of u) d[y] = !0;
|
|
258
|
+
return d;
|
|
259
|
+
}), k = m(() => ({
|
|
260
|
+
...w.value,
|
|
261
|
+
[t.activeClass || "active"]: b.value,
|
|
262
|
+
[t.exactActiveClass || "exact-active"]: v.value
|
|
263
|
+
})), C = m(
|
|
264
|
+
() => Object.keys(k.value).filter((p) => k.value[p]).join(" ")
|
|
265
|
+
), L = m(() => t.tag === "button"), g = m(
|
|
266
|
+
() => v.value ? t.ariaCurrentValue : ""
|
|
267
|
+
), n = m(() => !!t.disabled), a = m(
|
|
256
268
|
() => !!t.external && (t.tag === "a" || !t.tag)
|
|
257
|
-
),
|
|
269
|
+
), e = m(
|
|
270
|
+
() => i && i.value || t.style || ""
|
|
271
|
+
), r = (p) => {
|
|
258
272
|
if (t.disabled) {
|
|
259
|
-
|
|
273
|
+
p.preventDefault();
|
|
260
274
|
return;
|
|
261
275
|
}
|
|
262
|
-
t.external && (t.tag === "a" || !t.tag) || (
|
|
276
|
+
t.external && (t.tag === "a" || !t.tag) || (p.preventDefault(), t.replace ? h.replace(t.to) : h.push(t.to));
|
|
263
277
|
};
|
|
264
278
|
return R`
|
|
265
|
-
${
|
|
266
|
-
|
|
279
|
+
${F().when(
|
|
280
|
+
L.value,
|
|
267
281
|
R`
|
|
268
282
|
<button
|
|
269
283
|
part="button"
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
284
|
+
class="${C.value}"
|
|
285
|
+
style="${e.value || null}"
|
|
286
|
+
aria-current="${g.value}"
|
|
287
|
+
disabled="${n.value ? "" : null}"
|
|
288
|
+
aria-disabled="${n.value ? "true" : null}"
|
|
289
|
+
tabindex="${n.value ? "-1" : null}"
|
|
290
|
+
@click="${r}"
|
|
276
291
|
>
|
|
277
292
|
<slot></slot>
|
|
278
293
|
</button>
|
|
@@ -281,13 +296,14 @@ function K(c) {
|
|
|
281
296
|
<a
|
|
282
297
|
part="link"
|
|
283
298
|
href="${t.to}"
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
aria-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
299
|
+
class="${C.value}"
|
|
300
|
+
style="${e.value || null}"
|
|
301
|
+
aria-current="${g.value}"
|
|
302
|
+
aria-disabled="${n.value ? "true" : null}"
|
|
303
|
+
tabindex="${n.value ? "-1" : null}"
|
|
304
|
+
target="${a.value ? "_blank" : null}"
|
|
305
|
+
rel="${a.value ? "noopener noreferrer" : null}"
|
|
306
|
+
@click="${r}"
|
|
291
307
|
><slot></slot
|
|
292
308
|
></a>
|
|
293
309
|
`).done()}
|
|
@@ -295,11 +311,11 @@ function K(c) {
|
|
|
295
311
|
}), o;
|
|
296
312
|
}
|
|
297
313
|
export {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
314
|
+
J as initRouter,
|
|
315
|
+
S as matchRoute,
|
|
316
|
+
G as matchRouteSSR,
|
|
317
|
+
D as parseQuery,
|
|
318
|
+
I as resolveRouteComponent,
|
|
319
|
+
M as useRouter
|
|
304
320
|
};
|
|
305
321
|
//# sourceMappingURL=custom-elements-runtime.router.es.js.map
|