@jasonshimmy/custom-elements-runtime 2.3.1 → 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,267 +1,453 @@
1
- import { component as O, html as S, useOnConnected as N, useOnDisconnected as j, useProps as W, useStyle as F } from "./custom-elements-runtime.es.js";
2
- import { r as _, c as g } from "./namespace-helpers-Dw1mgQab.js";
3
- import { createStore as B } from "./custom-elements-runtime.store.es.js";
4
- import { d as C, a as $ } from "./logger-BuUYv7C_.js";
5
- import { match as M } from "./custom-elements-runtime.directives.es.js";
6
- const T = (n) => n ? typeof URLSearchParams > "u" ? {} : Object.fromEntries(new URLSearchParams(n)) : {}, U = /* @__PURE__ */ new WeakMap();
7
- function V(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 D(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 z(n) {
16
- const r = n.path || "/", t = D(r), f = t === "/" ? [] : t.split("/").filter(Boolean), s = [], i = [];
17
- for (let c = 0; c < f.length; c++) {
18
- const d = f[c];
19
- if (d === "*") {
20
- if (c !== f.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${s.length}`;
25
- s.push(p), i.push("__SPLAT__");
31
+ const g = `splat${h.length}`;
32
+ h.push(g), l.push("__SPLAT__");
26
33
  continue;
27
34
  }
28
- const w = d.match(/^:([A-Za-z0-9_-]+)(\*)?$/);
29
- if (w) {
30
- const p = w[1], b = !!w[2];
31
- if (b && c !== f.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
- s.push(p), i.push(b ? "__SPLAT__" : "([^/]+)");
42
+ h.push(g), l.push(q ? "__SPLAT__" : "([^/]+)");
36
43
  continue;
37
44
  }
38
- i.push(V(d));
45
+ l.push(ut(p));
39
46
  }
40
- let o;
41
- if (i.length === 0)
42
- o = "^/$";
43
- else if (i[i.length - 1] === "__SPLAT__") {
44
- const d = i.slice(0, -1).join("/");
45
- d ? o = `^/${d}(?:/(.*))?(?:/)?$` : o = "^(?:/(.*))?(?:/)?$";
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
- o = `^/${i.join("/")}(?:/)?$`;
54
+ m = `^/${l.join("/")}(?:/)?$`;
48
55
  try {
49
- return { regex: new RegExp(o), paramNames: s };
56
+ return { regex: new RegExp(m), paramNames: h };
50
57
  } catch (c) {
51
- return $(`Failed to compile route regex for '${n.path}': ${String(c)}`), { invalid: !0 };
58
+ return P(`Failed to compile route regex for '${o.path}': ${String(c)}`), { invalid: !0 };
52
59
  }
53
60
  }
54
- const x = (n, r) => {
55
- const t = D(r);
56
- for (const f of n) {
57
- let s = U.get(f);
58
- if (s || (s = z(f), U.set(f, s)), s.invalid) continue;
59
- const { regex: i, paramNames: o } = s, c = i.exec(t);
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);
60
67
  if (c) {
61
- const d = {}, w = (p) => {
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 < o.length; p++) {
69
- const b = c[p + 1] || "";
70
- d[o[p]] = b ? w(b) : "";
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: f, params: d };
79
+ return { route: d, params: p };
73
80
  }
74
81
  }
75
82
  return { route: null, params: {} };
76
83
  };
77
- function A(n, r) {
78
- for (const t of n)
79
- if (x([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 L = {};
83
- async function H(n) {
84
- if (n.component) return n.component;
85
- if (n.load) {
86
- if (L[n.path]) return L[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 L[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 I(n) {
97
- const { routes: r, base: t = "", initialUrl: f } = n;
98
- let s, i, o, c, d, w, p;
99
- const b = async (u, l) => {
100
- const e = A(r, u.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(u, l);
104
- return typeof a == "string" ? (await R(a, !0), !1) : a !== !1;
105
- } catch (a) {
106
- return C("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
- }, k = async (u, l) => {
109
- const e = A(r, u.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(u, l);
113
- return typeof a == "string" ? (await R(a, !0), !1) : a !== !1;
114
- } catch (a) {
115
- return C("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
- }, q = (u, l) => {
118
- const e = A(r, u.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(u, l);
122
- } catch (a) {
123
- C("afterEnter error", a);
136
+ t.afterEnter(r, e);
137
+ } catch (n) {
138
+ F("afterEnter error", n);
124
139
  }
125
- }, R = async (u, l = !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 = {
128
- path: u.replace(t, "") || "/",
129
- query: {}
130
- }, a = x(r, e.path);
131
- if (!a.route) throw new Error(`No route found for ${e.path}`);
132
- const m = o.getState(), h = {
133
- path: e.path,
134
- params: a.params,
135
- query: e.query
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
+ }
136
211
  };
137
- if (!await b(h, m) || !await k(h, m)) return;
138
- typeof window < "u" && typeof document < "u" && (l ? window.history.replaceState({}, "", t + u) : window.history.pushState({}, "", t + u)), o.setState(h), q(h, m);
139
- } catch (e) {
140
- C("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);
141
312
  }
142
313
  };
143
- if (typeof window < "u" && typeof document < "u" && typeof f > "u") {
144
- s = () => {
145
- const l = new URL(window.location.href), e = l.pathname.replace(t, "") || "/", a = T(l.search);
146
- return { path: e, query: a };
147
- }, i = s();
148
- const u = x(r, i.path);
149
- o = B({
150
- path: i.path,
151
- params: u.params,
152
- query: i.query
153
- }), c = async (l = !1) => {
154
- const e = s();
155
- await R(e.path, l);
156
- }, window.addEventListener("popstate", () => c(!0)), d = (l) => R(l, !1), w = (l) => R(l, !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();
157
329
  } else {
158
- s = () => {
159
- const e = new URL(f || "/", "http://localhost"), a = e.pathname.replace(t, "") || "/", m = T(e.search);
160
- return { path: a, query: m };
161
- }, i = s();
162
- const u = x(r, i.path);
163
- o = B({
164
- path: i.path,
165
- params: u.params,
166
- query: i.query
167
- }), c = async () => {
168
- const e = s();
169
- await l(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);
170
343
  };
171
- const l = async (e) => {
344
+ const e = async (t) => {
172
345
  try {
173
- const a = {
174
- path: e.replace(t, "") || "/",
175
- query: {}
176
- }, m = x(r, a.path);
177
- if (!m.route) throw new Error(`No route found for ${a.path}`);
178
- const h = o.getState(), v = {
179
- path: a.path,
180
- params: m.params,
181
- query: a.query
182
- }, y = A(r, v.path);
183
- if (y?.beforeEnter) {
184
- const E = await y.beforeEnter(v, h);
185
- if (typeof E == "string") {
186
- await l(E);
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(_);
187
362
  return;
188
363
  }
189
- if (E === !1) return;
364
+ if (_ === !1) return;
190
365
  }
191
- if (y?.onEnter) {
192
- const E = await y.onEnter(v, h);
193
- if (typeof E == "string") {
194
- await l(E);
366
+ if (I?.onEnter) {
367
+ const _ = await I.onEnter(j, W);
368
+ if (typeof _ == "string") {
369
+ await e(_);
195
370
  return;
196
371
  }
197
- if (E === !1) return;
372
+ if (_ === !1) return;
198
373
  }
199
- o.setState(v), y?.afterEnter && y.afterEnter(v, h);
200
- } catch (a) {
201
- throw C("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;
202
377
  }
203
378
  };
204
- d = async (e) => l(e), w = async (e) => l(e), p = () => {
379
+ q = async (t) => e(t), B = async (t) => e(t), D = () => {
205
380
  };
206
381
  }
207
382
  return {
208
- store: o,
209
- push: d,
210
- replace: w,
211
- back: p,
212
- subscribe: o.subscribe,
213
- matchRoute: (u) => x(r, u),
214
- getCurrent: () => o.getState(),
215
- resolveRouteComponent: H
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
+ }
216
402
  };
217
403
  }
218
- function X(n, r) {
219
- return x(n, r);
404
+ function vt(o, i) {
405
+ return M(o, i);
220
406
  }
221
- let P = null;
222
- function Y(n) {
223
- const r = I(n);
224
- return P = r, O("router-view", async () => {
225
- const t = P || r;
226
- if (!t) return S`<div>Router not initialized.</div>`;
227
- const f = _(t.getCurrent());
228
- let s;
229
- N(() => {
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(() => {
230
416
  try {
231
- t && typeof t.subscribe == "function" && (s = t.subscribe((o) => {
417
+ s && typeof s.subscribe == "function" && (h = s.subscribe((m) => {
232
418
  try {
233
- f.value = o;
419
+ d.value = m;
234
420
  } catch (c) {
235
- $("router-view subscription update failed", c);
421
+ P("router-view subscription update failed", c);
236
422
  }
237
423
  }));
238
- } catch (o) {
239
- $("router-view subscribe failed", o);
424
+ } catch (m) {
425
+ P("router-view subscribe failed", m);
240
426
  }
241
- }), j(() => {
242
- if (typeof s == "function")
427
+ }), nt(() => {
428
+ if (typeof h == "function")
243
429
  try {
244
- s();
245
- } catch (o) {
246
- $("router-view unsubscribe failed", o);
430
+ h();
431
+ } catch (m) {
432
+ P("router-view unsubscribe failed", m);
247
433
  }
248
434
  });
249
- const i = t.matchRoute(f.value.path);
250
- if (!i || !i.route) return S`<div>Not found</div>`;
435
+ const l = s.matchRoute(d.value.path);
436
+ if (!l || !l.route) return z`<div>Not found</div>`;
251
437
  try {
252
- const c = await t.resolveRouteComponent(i.route);
438
+ const c = await s.resolveRouteComponent(l.route);
253
439
  if (typeof c == "string")
254
440
  return { tag: c, props: {}, children: [] };
255
441
  if (typeof c == "function") {
256
- const d = c();
257
- return (d instanceof Promise ? d : Promise.resolve(d)).then((p) => typeof p == "string" ? { tag: p, props: {}, children: [] } : p);
442
+ const p = c();
443
+ return (p instanceof Promise ? p : Promise.resolve(p)).then((g) => typeof g == "string" ? { tag: g, props: {}, children: [] } : g);
258
444
  }
259
- return S`<div>Invalid route component</div>`;
445
+ return z`<div>Invalid route component</div>`;
260
446
  } catch {
261
- return S`<div>Invalid route component</div>`;
447
+ return z`<div>Invalid route component</div>`;
262
448
  }
263
- }), O("router-link", () => {
264
- const t = W({
449
+ }), tt("router-link", () => {
450
+ const s = st({
265
451
  to: "",
266
452
  tag: "a",
267
453
  replace: !1,
@@ -274,107 +460,154 @@ function Y(n) {
274
460
  // allow host `class` and `style` attributes to be read via useProps
275
461
  class: "",
276
462
  style: ""
277
- }), f = P || r, s = _(f.getCurrent());
278
- let i;
279
- F(() => "a,button{display:inline-block;}");
280
- const o = _(t.class || ""), c = _(t.style || "");
281
- N((m) => {
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) => {
282
468
  try {
283
- f && typeof f.subscribe == "function" && (i = f.subscribe((h) => {
469
+ d && typeof d.subscribe == "function" && (l = d.subscribe((u) => {
284
470
  try {
285
- s.value = h;
471
+ h.value = u;
286
472
  } catch (v) {
287
- $("router-link subscription update failed", v);
473
+ P("router-link subscription update failed", v);
288
474
  }
289
475
  }));
290
- } catch (h) {
291
- $("router-link subscribe failed", h);
476
+ } catch (u) {
477
+ P("router-link subscribe failed", u);
292
478
  }
293
479
  try {
294
- const h = m?._host;
295
- if (h instanceof HTMLElement) {
296
- const v = h.getAttribute("class"), y = h.getAttribute("style");
297
- v && (o.value = v), y && (c.value = y), v !== null && h.removeAttribute("class"), y !== null && h.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");
298
484
  }
299
- } catch (h) {
300
- $("router-link host migration failed", h);
485
+ } catch (u) {
486
+ P("router-link host migration failed", u);
301
487
  }
302
- }), j(() => {
303
- if (typeof i == "function")
488
+ }), nt(() => {
489
+ if (typeof l == "function")
304
490
  try {
305
- i();
306
- } catch (m) {
307
- $("router-link unsubscribe failed", m);
491
+ l();
492
+ } catch (a) {
493
+ P("router-link unsubscribe failed", a);
308
494
  }
309
495
  });
310
- const d = g(
311
- () => s.value.path === t.to
312
- ), w = g(
313
- () => t.exact ? d.value : s.value && typeof s.value.path == "string" ? s.value.path.startsWith(t.to) : !1
314
- ), p = g(() => {
315
- const h = (o && o.value || t.class || "").split(/\s+/).filter(Boolean), v = {};
316
- for (const y of h) v[y] = !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];
501
+ try {
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;
506
+ } catch {
507
+ return h.value.path === v;
508
+ }
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;
515
+ try {
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 + "/");
520
+ } catch {
521
+ return h.value && typeof h.value.path == "string" && h.value.path.startsWith(v);
522
+ }
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;
317
536
  return v;
318
- }), b = g(() => ({
319
- ...p.value,
320
- [t.activeClass || "active"]: w.value,
321
- [t.exactActiveClass || "exact-active"]: d.value
322
- })), k = g(
323
- () => Object.keys(b.value).filter((m) => b.value[m]).join(" ")
324
- ), q = g(() => t.tag === "button"), R = g(
325
- () => d.value ? t.ariaCurrentValue : ""
326
- ), u = g(() => !!t.disabled), l = g(
327
- () => !!t.external && (t.tag === "a" || !t.tag)
328
- ), e = g(
329
- () => c && c.value || t.style || ""
330
- ), a = (m) => {
331
- if (t.disabled) {
332
- m.preventDefault();
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");
333
564
  return;
334
565
  }
335
- t.external && (t.tag === "a" || !t.tag) || (m.preventDefault(), t.replace ? f.replace(t.to) : f.push(t.to));
566
+ C.value || (a.preventDefault(), s.replace ? d.replace(s.to) : d.push(s.to));
336
567
  };
337
- return S`
338
- ${M().when(
339
- q.value,
340
- S`
568
+ return z`
569
+ ${ct().when(
570
+ X.value,
571
+ z`
341
572
  <button
342
573
  part="button"
343
- class="${k.value}"
344
- style="${e.value || null}"
345
- aria-current="${R.value}"
346
- disabled="${u.value ? "" : null}"
347
- aria-disabled="${u.value ? "true" : null}"
348
- tabindex="${u.value ? "-1" : null}"
349
- @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}"
350
581
  >
351
582
  <slot></slot>
352
583
  </button>
353
584
  `
354
- ).otherwise(S`
585
+ ).otherwise(z`
355
586
  <a
356
587
  part="link"
357
- href="${t.to}"
358
- class="${k.value}"
359
- style="${e.value || null}"
360
- aria-current="${R.value}"
361
- aria-disabled="${u.value ? "true" : null}"
362
- tabindex="${u.value ? "-1" : null}"
363
- target="${l.value ? "_blank" : null}"
364
- rel="${l.value ? "noopener noreferrer" : null}"
365
- @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}"
366
597
  ><slot></slot
367
598
  ></a>
368
599
  `).done()}
369
600
  `;
370
- }), r;
601
+ }), i;
371
602
  }
372
603
  export {
373
- Y as initRouter,
374
- x as matchRoute,
375
- X as matchRouteSSR,
376
- T as parseQuery,
377
- H as resolveRouteComponent,
378
- I 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
379
612
  };
380
613
  //# sourceMappingURL=custom-elements-runtime.router.es.js.map