@jasonshimmy/custom-elements-runtime 2.4.0 → 2.5.0

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.
@@ -1,273 +1,453 @@
1
- import { component as T, html as P, useOnConnected as U, useOnDisconnected as W, useProps as M, useStyle as V } from "./custom-elements-runtime.es.js";
2
- import { r as O, c as b } from "./namespace-helpers-Dw1mgQab.js";
3
- import { createStore as D } from "./custom-elements-runtime.store.es.js";
4
- import { d as A, a as $ } from "./logger-BuUYv7C_.js";
5
- import { match as z } from "./custom-elements-runtime.directives.es.js";
6
- const I = (n) => n ? typeof URLSearchParams > "u" ? {} : Object.fromEntries(new URLSearchParams(n)) : {}, F = /* @__PURE__ */ new WeakMap();
7
- function H(n) {
8
- return n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1
+ import { component as tt, html as z, useOnConnected as et, useOnDisconnected as nt, useProps as st, useStyle as it } from "./custom-elements-runtime.es.js";
2
+ import { r as V, c as T } from "./namespace-helpers-Dw1mgQab.js";
3
+ import { createStore as rt } from "./custom-elements-runtime.store.es.js";
4
+ import { d as F, a as P } from "./logger-BuUYv7C_.js";
5
+ import { match as ct } from "./custom-elements-runtime.directives.es.js";
6
+ const Q = (o) => o ? typeof URLSearchParams > "u" ? {} : Object.fromEntries(new URLSearchParams(o)) : {}, lt = (o) => {
7
+ if (!o || Object.keys(o).length === 0) return "";
8
+ try {
9
+ return "?" + new URLSearchParams(o).toString();
10
+ } catch {
11
+ return "";
12
+ }
13
+ }, at = (o) => o ? /^\s*javascript\s*:/i.test(o) : !1, ot = /* @__PURE__ */ new WeakMap();
14
+ function ut(o) {
15
+ return o.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9
16
  }
10
- function _(n) {
11
- if (!n) return "/";
12
- let r = n.replace(/\/+/g, "/");
13
- return r.startsWith("/") || (r = "/" + r), r.length > 1 && r.endsWith("/") && (r = r.slice(0, -1)), r;
17
+ function k(o) {
18
+ if (!o) return "/";
19
+ let i = o.replace(/\/+/g, "/");
20
+ return i.startsWith("/") || (i = "/" + i), i.length > 1 && i.endsWith("/") && (i = i.slice(0, -1)), i;
14
21
  }
15
- function Q(n) {
16
- const r = n.path || "/", t = _(r), h = t === "/" ? [] : t.split("/").filter(Boolean), o = [], s = [];
17
- for (let u = 0; u < h.length; u++) {
18
- const d = h[u];
19
- if (d === "*") {
20
- if (u !== h.length - 1)
21
- return $(
22
- `Route '${n.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`
22
+ function ft(o) {
23
+ const i = o.path || "/", s = k(i), d = s === "/" ? [] : s.split("/").filter(Boolean), h = [], l = [];
24
+ for (let c = 0; c < d.length; c++) {
25
+ const p = d[c];
26
+ if (p === "*") {
27
+ if (c !== d.length - 1)
28
+ return P(
29
+ `Route '${o.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`
23
30
  ), { invalid: !0 };
24
- const p = `splat${o.length}`;
25
- o.push(p), s.push("__SPLAT__");
31
+ const g = `splat${h.length}`;
32
+ h.push(g), l.push("__SPLAT__");
26
33
  continue;
27
34
  }
28
- const y = d.match(/^:([A-Za-z0-9_-]+)(\*)?$/);
29
- if (y) {
30
- const p = y[1], w = !!y[2];
31
- if (w && u !== h.length - 1)
32
- return $(
33
- `Route '${n.path}' contains a splat param ':${p}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`
35
+ const b = p.match(/^:([A-Za-z0-9_-]+)(\*)?$/);
36
+ if (b) {
37
+ const g = b[1], q = !!b[2];
38
+ if (q && c !== d.length - 1)
39
+ return P(
40
+ `Route '${o.path}' contains a splat param ':${g}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`
34
41
  ), { invalid: !0 };
35
- o.push(p), s.push(w ? "__SPLAT__" : "([^/]+)");
42
+ h.push(g), l.push(q ? "__SPLAT__" : "([^/]+)");
36
43
  continue;
37
44
  }
38
- s.push(H(d));
45
+ l.push(ut(p));
39
46
  }
40
- let c;
41
- if (s.length === 0)
42
- c = "^/$";
43
- else if (s[s.length - 1] === "__SPLAT__") {
44
- const d = s.slice(0, -1).join("/");
45
- d ? c = `^/${d}(?:/(.*))?(?:/)?$` : c = "^(?:/(.*))?(?:/)?$";
47
+ let m;
48
+ if (l.length === 0)
49
+ m = "^/$";
50
+ else if (l[l.length - 1] === "__SPLAT__") {
51
+ const p = l.slice(0, -1).join("/");
52
+ p ? m = `^/${p}(?:/(.*))?(?:/)?$` : m = "^(?:/(.*))?(?:/)?$";
46
53
  } else
47
- c = `^/${s.join("/")}(?:/)?$`;
54
+ m = `^/${l.join("/")}(?:/)?$`;
48
55
  try {
49
- return { regex: new RegExp(c), paramNames: o };
50
- } catch (u) {
51
- return $(`Failed to compile route regex for '${n.path}': ${String(u)}`), { invalid: !0 };
56
+ return { regex: new RegExp(m), paramNames: h };
57
+ } catch (c) {
58
+ return P(`Failed to compile route regex for '${o.path}': ${String(c)}`), { invalid: !0 };
52
59
  }
53
60
  }
54
- const C = (n, r) => {
55
- const t = _(r);
56
- for (const h of n) {
57
- let o = F.get(h);
58
- if (o || (o = Q(h), F.set(h, o)), o.invalid) continue;
59
- const { regex: s, paramNames: c } = o, u = s.exec(t);
60
- if (u) {
61
- const d = {}, y = (p) => {
61
+ const M = (o, i) => {
62
+ const s = k(i);
63
+ for (const d of o) {
64
+ let h = ot.get(d);
65
+ if (h || (h = ft(d), ot.set(d, h)), h.invalid) continue;
66
+ const { regex: l, paramNames: m } = h, c = l.exec(s);
67
+ if (c) {
68
+ const p = {}, b = (g) => {
62
69
  try {
63
- return decodeURIComponent(p);
70
+ return decodeURIComponent(g);
64
71
  } catch {
65
- return p;
72
+ return g;
66
73
  }
67
74
  };
68
- for (let p = 0; p < c.length; p++) {
69
- const w = u[p + 1] || "";
70
- d[c[p]] = w ? y(w) : "";
75
+ for (let g = 0; g < m.length; g++) {
76
+ const q = c[g + 1] || "";
77
+ p[m[g]] = q ? b(q) : "";
71
78
  }
72
- return { route: h, params: d };
79
+ return { route: d, params: p };
73
80
  }
74
81
  }
75
82
  return { route: null, params: {} };
76
83
  };
77
- function L(n, r) {
78
- for (const t of n)
79
- if (C([t], r).route !== null) return t;
84
+ function K(o, i) {
85
+ for (const s of o)
86
+ if (M([s], i).route !== null) return s;
80
87
  return null;
81
88
  }
82
- const j = {};
83
- async function Z(n) {
84
- if (n.component) return n.component;
85
- if (n.load) {
86
- if (j[n.path]) return j[n.path];
89
+ const H = {};
90
+ async function ht(o) {
91
+ if (o.component) return o.component;
92
+ if (o.load) {
93
+ if (H[o.path]) return H[o.path];
87
94
  try {
88
- const r = await n.load();
89
- return j[n.path] = r.default, r.default;
95
+ const i = await o.load();
96
+ return H[o.path] = i.default, i.default;
90
97
  } catch {
91
- throw new Error(`Failed to load component for route: ${n.path}`);
98
+ throw new Error(`Failed to load component for route: ${o.path}`);
92
99
  }
93
100
  }
94
- throw new Error(`No component or loader defined for route: ${n.path}`);
101
+ throw new Error(`No component or loader defined for route: ${o.path}`);
95
102
  }
96
- function G(n) {
97
- const { routes: r, base: t = "", initialUrl: h } = n;
98
- let o, s, c, u, d, y, p;
99
- const w = async (f, i) => {
100
- const e = L(r, f.path);
101
- if (!e || !e.beforeEnter) return !0;
103
+ function pt(o) {
104
+ const { routes: i, base: s = "", initialUrl: d, scrollToFragment: h = !0 } = o, l = (() => {
105
+ if (!s) return "";
106
+ const r = k(s);
107
+ return r === "/" ? "" : r;
108
+ })(), m = typeof h == "boolean" ? { enabled: !!h, offset: 0, timeoutMs: 2e3 } : {
109
+ enabled: h.enabled ?? !0,
110
+ offset: h.offset ?? 0,
111
+ timeoutMs: h.timeoutMs ?? 2e3
112
+ };
113
+ let c, p, b, g, q, B, D;
114
+ const Y = async (r, e) => {
115
+ const t = K(i, r.path);
116
+ if (!t || !t.beforeEnter) return !0;
102
117
  try {
103
- const a = await e.beforeEnter(f, i);
104
- return typeof a == "string" ? (await R(a, !0), !1) : a !== !1;
105
- } catch (a) {
106
- return A("beforeEnter error", a), !1;
118
+ const n = await t.beforeEnter(r, e);
119
+ return typeof n == "string" ? (await y(n, !0), !1) : n !== !1;
120
+ } catch (n) {
121
+ return F("beforeEnter error", n), !1;
107
122
  }
108
- }, q = async (f, i) => {
109
- const e = L(r, f.path);
110
- if (!e || !e.onEnter) return !0;
123
+ }, X = async (r, e) => {
124
+ const t = K(i, r.path);
125
+ if (!t || !t.onEnter) return !0;
111
126
  try {
112
- const a = await e.onEnter(f, i);
113
- return typeof a == "string" ? (await R(a, !0), !1) : a !== !1;
114
- } catch (a) {
115
- return A("onEnter error", a), !1;
127
+ const n = await t.onEnter(r, e);
128
+ return typeof n == "string" ? (await y(n, !0), !1) : n !== !1;
129
+ } catch (n) {
130
+ return F("onEnter error", n), !1;
116
131
  }
117
- }, N = (f, i) => {
118
- const e = L(r, f.path);
119
- if (!(!e || !e.afterEnter))
132
+ }, Z = (r, e) => {
133
+ const t = K(i, r.path);
134
+ if (!(!t || !t.afterEnter))
120
135
  try {
121
- e.afterEnter(f, i);
122
- } catch (a) {
123
- A("afterEnter error", a);
136
+ t.afterEnter(r, e);
137
+ } catch (n) {
138
+ F("afterEnter error", n);
124
139
  }
125
- }, R = async (f, i = !1) => {
140
+ };
141
+ let w = 0, C = null, O = null, L = null;
142
+ async function a(r, e = 0) {
126
143
  try {
127
- const e = f.indexOf("#"), a = e >= 0 ? f.slice(e + 1) : "", l = {
128
- path: (e >= 0 ? f.slice(0, e) : f).replace(t, "") || "/",
129
- query: {},
130
- fragment: a
131
- }, m = C(r, l.path);
132
- if (!m.route) throw new Error(`No route found for ${l.path}`);
133
- const v = c.getState(), E = {
134
- path: l.path,
135
- params: m.params,
136
- query: l.query,
137
- fragment: l.fragment
144
+ const t = document.getElementById(r);
145
+ if (!t) return !1;
146
+ if (e && e > 0)
147
+ try {
148
+ const n = t.getBoundingClientRect(), E = Math.max(0, window.scrollY + n.top - e);
149
+ typeof window.scrollTo == "function" && window.scrollTo({ top: E, behavior: "auto" });
150
+ } catch {
151
+ try {
152
+ t.scrollIntoView();
153
+ } catch {
154
+ }
155
+ }
156
+ else if (typeof t.scrollIntoView == "function")
157
+ try {
158
+ t.scrollIntoView({
159
+ behavior: "auto",
160
+ block: "start",
161
+ inline: "nearest"
162
+ });
163
+ } catch {
164
+ try {
165
+ t.scrollIntoView();
166
+ } catch {
167
+ }
168
+ }
169
+ return !0;
170
+ } catch {
171
+ return !1;
172
+ }
173
+ }
174
+ function u() {
175
+ if (C) {
176
+ try {
177
+ C.disconnect();
178
+ } catch {
179
+ }
180
+ C = null;
181
+ }
182
+ if (O) {
183
+ try {
184
+ clearTimeout(O);
185
+ } catch {
186
+ }
187
+ O = null;
188
+ }
189
+ }
190
+ function v(r, e, t) {
191
+ w += 1;
192
+ const n = w;
193
+ if (L) {
194
+ try {
195
+ L(!1);
196
+ } catch {
197
+ }
198
+ L = null;
199
+ }
200
+ return u(), new Promise((E) => {
201
+ L = E;
202
+ const f = (A) => {
203
+ if (n === w) {
204
+ u();
205
+ try {
206
+ E(A);
207
+ } finally {
208
+ L = null;
209
+ }
210
+ }
138
211
  };
139
- if (!await w(E, v) || !await q(E, v)) return;
140
- typeof window < "u" && typeof document < "u" && (i ? window.history.replaceState({}, "", t + f) : window.history.pushState({}, "", t + f)), c.setState(E), N(E, v);
141
- } catch (e) {
142
- A("Navigation error:", e);
212
+ queueMicrotask(async () => {
213
+ if (n !== w) return f(!1);
214
+ if (await a(r, e)) return f(!0);
215
+ if (typeof window.requestAnimationFrame == "function")
216
+ window.requestAnimationFrame(async () => {
217
+ if (n !== w) return f(!1);
218
+ if (await a(r, e)) return f(!0);
219
+ if (n !== w) return f(!1);
220
+ const A = document.querySelector("router-view") || document.body;
221
+ try {
222
+ const x = new MutationObserver(async () => {
223
+ n === w && await a(r, e) && f(!0);
224
+ });
225
+ C = x, x.observe(A, {
226
+ childList: !0,
227
+ subtree: !0,
228
+ attributes: !1
229
+ }), O = window.setTimeout(() => {
230
+ if (n === w) {
231
+ try {
232
+ x.disconnect();
233
+ } catch {
234
+ }
235
+ C = null, O = null, f(!1);
236
+ }
237
+ }, t ?? 2e3);
238
+ } catch {
239
+ let R = 0;
240
+ const S = async () => {
241
+ if (n !== w) return f(!1);
242
+ if (await a(r, e)) return f(!0);
243
+ R += 1, R < 40 ? window.setTimeout(S, 50) : f(!1);
244
+ };
245
+ S();
246
+ }
247
+ });
248
+ else {
249
+ const A = document.querySelector("router-view") || document.body;
250
+ try {
251
+ const x = new MutationObserver(async () => {
252
+ n === w && await a(r, e) && f(!0);
253
+ });
254
+ C = x, x.observe(A, {
255
+ childList: !0,
256
+ subtree: !0,
257
+ attributes: !1
258
+ }), O = window.setTimeout(() => {
259
+ if (n === w) {
260
+ try {
261
+ x.disconnect();
262
+ } catch {
263
+ }
264
+ C = null, O = null, f(!1);
265
+ }
266
+ }, t ?? 2e3);
267
+ } catch {
268
+ let R = 0;
269
+ const S = async () => {
270
+ if (n !== w) return f(!1);
271
+ if (await a(r, e)) return f(!0);
272
+ R += 1, R < 40 ? window.setTimeout(S, 50) : f(!1);
273
+ };
274
+ S();
275
+ }
276
+ }
277
+ });
278
+ });
279
+ }
280
+ const y = async (r, e = !1) => {
281
+ try {
282
+ const t = r.indexOf("#"), n = t >= 0 ? r.slice(t + 1) : "", E = t >= 0 ? r.slice(0, t) : r, f = E.indexOf("?"), $ = f >= 0 ? E.slice(0, f) : E, A = f >= 0 ? Q(E.slice(f)) : {}, x = $.startsWith(l) ? $.slice(l.length) : $, R = {
283
+ path: k(x || "/"),
284
+ query: A,
285
+ fragment: n
286
+ }, S = M(i, R.path);
287
+ if (!S.route) throw new Error(`No route found for ${R.path}`);
288
+ const N = b.getState(), W = {
289
+ path: R.path,
290
+ params: S.params,
291
+ query: R.query,
292
+ fragment: R.fragment
293
+ };
294
+ if (!await Y(W, N) || !await X(W, N)) return;
295
+ if (typeof window < "u" && typeof document < "u") {
296
+ const _ = lt(R.query), J = l + R.path + (_ || "") + (R.fragment ? "#" + R.fragment : "");
297
+ e ? window.history.replaceState({}, "", J) : window.history.pushState({}, "", J);
298
+ }
299
+ b.setState(W), Z(W, N);
300
+ try {
301
+ const _ = W.fragment;
302
+ m.enabled && _ && typeof window < "u" && typeof document < "u" && v(
303
+ String(_),
304
+ m.offset,
305
+ m.timeoutMs
306
+ ).catch(() => {
307
+ });
308
+ } catch {
309
+ }
310
+ } catch (t) {
311
+ F("Navigation error:", t);
143
312
  }
144
313
  };
145
- if (typeof window < "u" && typeof document < "u" && typeof h > "u") {
146
- o = () => {
147
- const i = new URL(window.location.href), e = i.pathname.replace(t, "") || "/", a = I(i.search), g = i.hash && i.hash.length ? i.hash.slice(1) : "";
148
- return { path: e, query: a, fragment: g };
149
- }, s = o();
150
- const f = C(r, s.path);
151
- c = D({
152
- path: s.path,
153
- params: f.params,
154
- query: s.query,
155
- fragment: s.fragment
156
- }), u = async (i = !1) => {
157
- const e = o();
158
- await R(e.path, i);
159
- }, window.addEventListener("popstate", () => u(!0)), d = (i) => R(i, !1), y = (i) => R(i, !0), p = () => window.history.back();
314
+ if (typeof window < "u" && typeof document < "u" && typeof d > "u") {
315
+ c = () => {
316
+ const e = new URL(window.location.href), t = e.pathname, n = t.startsWith(l) ? t.slice(l.length) : t, E = k(n || "/"), f = Q(e.search), $ = e.hash && e.hash.length ? e.hash.slice(1) : "";
317
+ return { path: E, query: f, fragment: $ };
318
+ }, p = c();
319
+ const r = M(i, p.path);
320
+ b = rt({
321
+ path: p.path,
322
+ params: r.params,
323
+ query: p.query,
324
+ fragment: p.fragment
325
+ }), g = async (e = !1) => {
326
+ const t = c();
327
+ await y(t.path, e);
328
+ }, window.addEventListener("popstate", () => g(!0)), q = (e) => y(e, !1), B = (e) => y(e, !0), D = () => window.history.back();
160
329
  } else {
161
- o = () => {
162
- const e = new URL(h || "/", "http://localhost"), a = e.pathname.replace(t, "") || "/", g = I(e.search), l = e.hash && e.hash.length ? e.hash.slice(1) : "";
163
- return { path: a, query: g, fragment: l };
164
- }, s = o();
165
- const f = C(r, s.path);
166
- c = D({
167
- path: s.path,
168
- params: f.params,
169
- query: s.query,
170
- fragment: s.fragment
171
- }), u = async () => {
172
- const e = o();
173
- await i(e.path);
330
+ c = () => {
331
+ const t = new URL(d || "/", "http://localhost"), n = t.pathname, E = n.startsWith(l) ? n.slice(l.length) : n, f = k(E || "/"), $ = Q(t.search), A = t.hash && t.hash.length ? t.hash.slice(1) : "";
332
+ return { path: f, query: $, fragment: A };
333
+ }, p = c();
334
+ const r = M(i, p.path);
335
+ b = rt({
336
+ path: p.path,
337
+ params: r.params,
338
+ query: p.query,
339
+ fragment: p.fragment
340
+ }), g = async () => {
341
+ const t = c();
342
+ await e(t.path);
174
343
  };
175
- const i = async (e) => {
344
+ const e = async (t) => {
176
345
  try {
177
- const a = e.indexOf("#"), g = a >= 0 ? e.slice(a + 1) : "", m = {
178
- path: (a >= 0 ? e.slice(0, a) : e).replace(t, "") || "/",
179
- query: {},
180
- fragment: g
181
- }, v = C(r, m.path);
182
- if (!v.route) throw new Error(`No route found for ${m.path}`);
183
- const E = c.getState(), k = {
184
- path: m.path,
185
- params: v.params,
186
- query: m.query,
187
- fragment: m.fragment
188
- }, x = L(r, k.path);
189
- if (x?.beforeEnter) {
190
- const S = await x.beforeEnter(k, E);
191
- if (typeof S == "string") {
192
- await i(S);
346
+ const n = t.indexOf("#"), E = n >= 0 ? t.slice(n + 1) : "", f = n >= 0 ? t.slice(0, n) : t, $ = f.indexOf("?"), A = $ >= 0 ? f.slice(0, $) : f, x = $ >= 0 ? Q(f.slice($)) : {}, U = A.startsWith(l) ? A.slice(l.length) : A, S = {
347
+ path: k(U || "/"),
348
+ query: x,
349
+ fragment: E
350
+ }, N = M(i, S.path);
351
+ if (!N.route) throw new Error(`No route found for ${S.path}`);
352
+ const W = b.getState(), j = {
353
+ path: S.path,
354
+ params: N.params,
355
+ query: S.query,
356
+ fragment: S.fragment
357
+ }, I = K(i, j.path);
358
+ if (I?.beforeEnter) {
359
+ const _ = await I.beforeEnter(j, W);
360
+ if (typeof _ == "string") {
361
+ await e(_);
193
362
  return;
194
363
  }
195
- if (S === !1) return;
364
+ if (_ === !1) return;
196
365
  }
197
- if (x?.onEnter) {
198
- const S = await x.onEnter(k, E);
199
- if (typeof S == "string") {
200
- await i(S);
366
+ if (I?.onEnter) {
367
+ const _ = await I.onEnter(j, W);
368
+ if (typeof _ == "string") {
369
+ await e(_);
201
370
  return;
202
371
  }
203
- if (S === !1) return;
372
+ if (_ === !1) return;
204
373
  }
205
- c.setState(k), x?.afterEnter && x.afterEnter(k, E);
206
- } catch (a) {
207
- throw A("SSR navigation error:", a), a;
374
+ b.setState(j), I?.afterEnter && I.afterEnter(j, W);
375
+ } catch (n) {
376
+ throw F("SSR navigation error:", n), n;
208
377
  }
209
378
  };
210
- d = async (e) => i(e), y = async (e) => i(e), p = () => {
379
+ q = async (t) => e(t), B = async (t) => e(t), D = () => {
211
380
  };
212
381
  }
213
382
  return {
214
- store: c,
215
- push: d,
216
- replace: y,
217
- back: p,
218
- subscribe: c.subscribe,
219
- matchRoute: (f) => C(r, f),
220
- getCurrent: () => c.getState(),
221
- resolveRouteComponent: Z
383
+ store: b,
384
+ push: q,
385
+ replace: B,
386
+ back: D,
387
+ subscribe: b.subscribe,
388
+ matchRoute: (r) => M(i, r),
389
+ getCurrent: () => b.getState(),
390
+ resolveRouteComponent: ht,
391
+ base: l,
392
+ // Public API: allow components or tests to explicitly request scrolling to
393
+ // a fragment when they know their DOM is ready. Returns true if scrolled.
394
+ scrollToFragment: (r) => {
395
+ const e = r || b.getState().fragment;
396
+ return !e || typeof window > "u" || typeof document > "u" ? Promise.resolve(!1) : v(
397
+ String(e),
398
+ m.offset,
399
+ m.timeoutMs
400
+ );
401
+ }
222
402
  };
223
403
  }
224
- function et(n, r) {
225
- return C(n, r);
404
+ function vt(o, i) {
405
+ return M(o, i);
226
406
  }
227
- let B = null;
228
- function rt(n) {
229
- const r = G(n);
230
- return B = r, T("router-view", async () => {
231
- const t = B || r;
232
- if (!t) return P`<div>Router not initialized.</div>`;
233
- const h = O(t.getCurrent());
234
- let o;
235
- U(() => {
407
+ let G = null;
408
+ function bt(o) {
409
+ const i = pt(o);
410
+ return G = i, tt("router-view", async () => {
411
+ const s = G || i;
412
+ if (!s) return z`<div>Router not initialized.</div>`;
413
+ const d = V(s.getCurrent());
414
+ let h;
415
+ et(() => {
236
416
  try {
237
- t && typeof t.subscribe == "function" && (o = t.subscribe((c) => {
417
+ s && typeof s.subscribe == "function" && (h = s.subscribe((m) => {
238
418
  try {
239
- h.value = c;
240
- } catch (u) {
241
- $("router-view subscription update failed", u);
419
+ d.value = m;
420
+ } catch (c) {
421
+ P("router-view subscription update failed", c);
242
422
  }
243
423
  }));
244
- } catch (c) {
245
- $("router-view subscribe failed", c);
424
+ } catch (m) {
425
+ P("router-view subscribe failed", m);
246
426
  }
247
- }), W(() => {
248
- if (typeof o == "function")
427
+ }), nt(() => {
428
+ if (typeof h == "function")
249
429
  try {
250
- o();
251
- } catch (c) {
252
- $("router-view unsubscribe failed", c);
430
+ h();
431
+ } catch (m) {
432
+ P("router-view unsubscribe failed", m);
253
433
  }
254
434
  });
255
- const s = t.matchRoute(h.value.path);
256
- if (!s || !s.route) return P`<div>Not found</div>`;
435
+ const l = s.matchRoute(d.value.path);
436
+ if (!l || !l.route) return z`<div>Not found</div>`;
257
437
  try {
258
- const u = await t.resolveRouteComponent(s.route);
259
- if (typeof u == "string")
260
- return { tag: u, props: {}, children: [] };
261
- if (typeof u == "function") {
262
- const d = u();
263
- return (d instanceof Promise ? d : Promise.resolve(d)).then((p) => typeof p == "string" ? { tag: p, props: {}, children: [] } : p);
438
+ const c = await s.resolveRouteComponent(l.route);
439
+ if (typeof c == "string")
440
+ return { tag: c, props: {}, children: [] };
441
+ if (typeof c == "function") {
442
+ const p = c();
443
+ return (p instanceof Promise ? p : Promise.resolve(p)).then((g) => typeof g == "string" ? { tag: g, props: {}, children: [] } : g);
264
444
  }
265
- return P`<div>Invalid route component</div>`;
445
+ return z`<div>Invalid route component</div>`;
266
446
  } catch {
267
- return P`<div>Invalid route component</div>`;
447
+ return z`<div>Invalid route component</div>`;
268
448
  }
269
- }), T("router-link", () => {
270
- const t = M({
449
+ }), tt("router-link", () => {
450
+ const s = st({
271
451
  to: "",
272
452
  tag: "a",
273
453
  replace: !1,
@@ -280,120 +460,154 @@ function rt(n) {
280
460
  // allow host `class` and `style` attributes to be read via useProps
281
461
  class: "",
282
462
  style: ""
283
- }), h = B || r, o = O(h.getCurrent());
284
- let s;
285
- V(() => "a,button{display:inline-block;}");
286
- const c = O(t.class || ""), u = O(t.style || "");
287
- U((g) => {
463
+ }), d = G || i, h = V(d.getCurrent());
464
+ let l;
465
+ it(() => "a,button{display:inline-block;}");
466
+ const m = V(s.class || ""), c = V(s.style || "");
467
+ et((a) => {
288
468
  try {
289
- h && typeof h.subscribe == "function" && (s = h.subscribe((l) => {
469
+ d && typeof d.subscribe == "function" && (l = d.subscribe((u) => {
290
470
  try {
291
- o.value = l;
292
- } catch (m) {
293
- $("router-link subscription update failed", m);
471
+ h.value = u;
472
+ } catch (v) {
473
+ P("router-link subscription update failed", v);
294
474
  }
295
475
  }));
296
- } catch (l) {
297
- $("router-link subscribe failed", l);
476
+ } catch (u) {
477
+ P("router-link subscribe failed", u);
298
478
  }
299
479
  try {
300
- const l = g?._host;
301
- if (l instanceof HTMLElement) {
302
- const m = l.getAttribute("class"), v = l.getAttribute("style");
303
- m && (c.value = m), v && (u.value = v), m !== null && l.removeAttribute("class"), v !== null && l.removeAttribute("style");
480
+ const u = a?._host;
481
+ if (u instanceof HTMLElement) {
482
+ const v = u.getAttribute("class"), y = u.getAttribute("style");
483
+ v && (m.value = v), y && (c.value = y), v !== null && u.removeAttribute("class"), y !== null && u.removeAttribute("style");
304
484
  }
305
- } catch (l) {
306
- $("router-link host migration failed", l);
485
+ } catch (u) {
486
+ P("router-link host migration failed", u);
307
487
  }
308
- }), W(() => {
309
- if (typeof s == "function")
488
+ }), nt(() => {
489
+ if (typeof l == "function")
310
490
  try {
311
- s();
312
- } catch (g) {
313
- $("router-link unsubscribe failed", g);
491
+ l();
492
+ } catch (a) {
493
+ P("router-link unsubscribe failed", a);
314
494
  }
315
495
  });
316
- const d = b(() => {
317
- const l = (t.to || "").split("#")[0];
496
+ const p = T(() => {
497
+ const a = d?.base ?? "", u = s.to || "";
498
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(u) || u.startsWith("//"))
499
+ return !1;
500
+ const v = (u.split("#")[0] || "/").split("?")[0];
318
501
  try {
319
- return _(o.value.path) === _(l);
502
+ let y = v;
503
+ a && y.startsWith(a) && (y = y.slice(a.length) || "/");
504
+ const r = k(h.value.path), e = k(y);
505
+ return r === e;
320
506
  } catch {
321
- return o.value.path === l;
507
+ return h.value.path === v;
322
508
  }
323
- }), y = b(() => {
324
- const l = (t.to || "").split("#")[0];
325
- if (t.exact) return d.value;
509
+ }), b = T(() => {
510
+ const a = d?.base ?? "", u = s.to || "";
511
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(u) || u.startsWith("//"))
512
+ return !1;
513
+ const v = (u.split("#")[0] || "/").split("?")[0];
514
+ if (s.exact) return p.value;
326
515
  try {
327
- const m = _(o.value.path), v = _(l);
328
- return m.startsWith(v);
516
+ let y = v;
517
+ a && y.startsWith(a) && (y = y.slice(a.length) || "/");
518
+ const r = k(h.value.path), e = k(y);
519
+ return e === "/" ? r === "/" : r === e ? !0 : r.startsWith(e.endsWith("/") ? e : e + "/");
329
520
  } catch {
330
- return o.value && typeof o.value.path == "string" && o.value.path.startsWith(l);
521
+ return h.value && typeof h.value.path == "string" && h.value.path.startsWith(v);
331
522
  }
332
- }), p = b(() => {
333
- const l = (c && c.value || t.class || "").split(/\s+/).filter(Boolean), m = {};
334
- for (const v of l) m[v] = !0;
335
- return m;
336
- }), w = b(() => ({
337
- ...p.value,
338
- [t.activeClass || "active"]: y.value,
339
- [t.exactActiveClass || "exact-active"]: d.value
340
- })), q = b(
341
- () => Object.keys(w.value).filter((g) => w.value[g]).join(" ")
342
- ), N = b(() => t.tag === "button"), R = b(
343
- () => d.value ? t.ariaCurrentValue : ""
344
- ), f = b(() => !!t.disabled), i = b(
345
- () => !!t.external && (t.tag === "a" || !t.tag)
346
- ), e = b(
347
- () => u && u.value || t.style || ""
348
- ), a = (g) => {
349
- if (t.disabled) {
350
- g.preventDefault();
523
+ }), g = T(() => {
524
+ const a = String(s.to || "");
525
+ if (at(a)) return null;
526
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(a) || a.startsWith("//"))
527
+ return a;
528
+ const [u, v] = a.split("#"), [y, r] = (u || "").split("?"), e = d?.base ?? "";
529
+ let t = y || "/";
530
+ e && t.startsWith(e) && (t = t.slice(e.length) || "/");
531
+ const n = k(t || "/");
532
+ return e + n + (r ? "?" + r : "") + (v ? "#" + v : "");
533
+ }), q = T(() => {
534
+ const u = (m && m.value || s.class || "").split(/\s+/).filter(Boolean), v = {};
535
+ for (const y of u) v[y] = !0;
536
+ return v;
537
+ }), B = T(() => ({
538
+ ...q.value,
539
+ [s.activeClass || "active"]: b.value,
540
+ [s.exactActiveClass || "exact-active"]: p.value
541
+ })), D = T(
542
+ () => Object.keys(B.value).filter((a) => B.value[a]).join(" ")
543
+ ), Y = T(() => s.tag || "a"), X = T(() => Y.value === "button"), Z = T(
544
+ () => p.value ? s.ariaCurrentValue : null
545
+ ), w = T(() => !!s.disabled), C = T(() => {
546
+ const a = String(s.to || "");
547
+ return (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(a) || a.startsWith("//") || !!s.external) && Y.value === "a";
548
+ }), O = T(
549
+ () => c && c.value || s.style || ""
550
+ ), L = (a) => {
551
+ if (a.defaultPrevented || a.button !== 0 || a.metaKey || a.altKey || a.ctrlKey || a.shiftKey)
552
+ return;
553
+ if (w.value) {
554
+ a.preventDefault();
555
+ return;
556
+ }
557
+ const u = String(s.to || "");
558
+ if (at(u)) {
559
+ try {
560
+ a.preventDefault();
561
+ } catch {
562
+ }
563
+ P("Blocked unsafe javascript: URI in router-link.to");
351
564
  return;
352
565
  }
353
- t.external && (t.tag === "a" || !t.tag) || (g.preventDefault(), t.replace ? h.replace(t.to) : h.push(t.to));
566
+ C.value || (a.preventDefault(), s.replace ? d.replace(s.to) : d.push(s.to));
354
567
  };
355
- return P`
356
- ${z().when(
357
- N.value,
358
- P`
568
+ return z`
569
+ ${ct().when(
570
+ X.value,
571
+ z`
359
572
  <button
360
573
  part="button"
361
- class="${q.value}"
362
- style="${e.value || null}"
363
- aria-current="${R.value}"
364
- disabled="${f.value ? "" : null}"
365
- aria-disabled="${f.value ? "true" : null}"
366
- tabindex="${f.value ? "-1" : null}"
367
- @click="${a}"
574
+ class="${D.value}"
575
+ style="${O.value || null}"
576
+ aria-current="${Z.value}"
577
+ disabled="${w.value ? "" : null}"
578
+ aria-disabled="${w.value ? "true" : null}"
579
+ tabindex="${w.value ? "-1" : null}"
580
+ @click="${L}"
368
581
  >
369
582
  <slot></slot>
370
583
  </button>
371
584
  `
372
- ).otherwise(P`
585
+ ).otherwise(z`
373
586
  <a
374
587
  part="link"
375
- href="${t.to}"
376
- class="${q.value}"
377
- style="${e.value || null}"
378
- aria-current="${R.value}"
379
- aria-disabled="${f.value ? "true" : null}"
380
- tabindex="${f.value ? "-1" : null}"
381
- target="${i.value ? "_blank" : null}"
382
- rel="${i.value ? "noopener noreferrer" : null}"
383
- @click="${a}"
588
+ href="${w.value ? null : g.value}"
589
+ class="${D.value}"
590
+ style="${O.value || null}"
591
+ aria-current="${Z.value}"
592
+ aria-disabled="${w.value ? "true" : null}"
593
+ tabindex="${w.value ? "-1" : null}"
594
+ target="${C.value ? "_blank" : null}"
595
+ rel="${C.value ? "noopener noreferrer" : null}"
596
+ @click="${L}"
384
597
  ><slot></slot
385
598
  ></a>
386
599
  `).done()}
387
600
  `;
388
- }), r;
601
+ }), i;
389
602
  }
390
603
  export {
391
- rt as initRouter,
392
- C as matchRoute,
393
- et as matchRouteSSR,
394
- _ as normalizePathForRoute,
395
- I as parseQuery,
396
- Z as resolveRouteComponent,
397
- G as useRouter
604
+ bt as initRouter,
605
+ M as matchRoute,
606
+ vt as matchRouteSSR,
607
+ k as normalizePathForRoute,
608
+ Q as parseQuery,
609
+ ht as resolveRouteComponent,
610
+ lt as serializeQuery,
611
+ pt as useRouter
398
612
  };
399
613
  //# sourceMappingURL=custom-elements-runtime.router.es.js.map