@jasonshimmy/custom-elements-runtime 2.5.0 → 2.5.1

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.
@@ -20,63 +20,63 @@ function k(o) {
20
20
  return i.startsWith("/") || (i = "/" + i), i.length > 1 && i.endsWith("/") && (i = i.slice(0, -1)), i;
21
21
  }
22
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];
23
+ const i = o.path || "/", s = k(i), m = s === "/" ? [] : s.split("/").filter(Boolean), h = [], l = [];
24
+ for (let c = 0; c < m.length; c++) {
25
+ const p = m[c];
26
26
  if (p === "*") {
27
- if (c !== d.length - 1)
27
+ if (c !== m.length - 1)
28
28
  return P(
29
29
  `Route '${o.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`
30
30
  ), { invalid: !0 };
31
- const g = `splat${h.length}`;
32
- h.push(g), l.push("__SPLAT__");
31
+ const w = `splat${h.length}`;
32
+ h.push(w), l.push("__SPLAT__");
33
33
  continue;
34
34
  }
35
35
  const b = p.match(/^:([A-Za-z0-9_-]+)(\*)?$/);
36
36
  if (b) {
37
- const g = b[1], q = !!b[2];
38
- if (q && c !== d.length - 1)
37
+ const w = b[1], q = !!b[2];
38
+ if (q && c !== m.length - 1)
39
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.`
40
+ `Route '${o.path}' contains a splat param ':${w}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`
41
41
  ), { invalid: !0 };
42
- h.push(g), l.push(q ? "__SPLAT__" : "([^/]+)");
42
+ h.push(w), l.push(q ? "__SPLAT__" : "([^/]+)");
43
43
  continue;
44
44
  }
45
45
  l.push(ut(p));
46
46
  }
47
- let m;
47
+ let d;
48
48
  if (l.length === 0)
49
- m = "^/$";
49
+ d = "^/$";
50
50
  else if (l[l.length - 1] === "__SPLAT__") {
51
51
  const p = l.slice(0, -1).join("/");
52
- p ? m = `^/${p}(?:/(.*))?(?:/)?$` : m = "^(?:/(.*))?(?:/)?$";
52
+ p ? d = `^/${p}(?:/(.*))?(?:/)?$` : d = "^(?:/(.*))?(?:/)?$";
53
53
  } else
54
- m = `^/${l.join("/")}(?:/)?$`;
54
+ d = `^/${l.join("/")}(?:/)?$`;
55
55
  try {
56
- return { regex: new RegExp(m), paramNames: h };
56
+ return { regex: new RegExp(d), paramNames: h };
57
57
  } catch (c) {
58
58
  return P(`Failed to compile route regex for '${o.path}': ${String(c)}`), { invalid: !0 };
59
59
  }
60
60
  }
61
61
  const M = (o, i) => {
62
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);
63
+ for (const m of o) {
64
+ let h = ot.get(m);
65
+ if (h || (h = ft(m), ot.set(m, h)), h.invalid) continue;
66
+ const { regex: l, paramNames: d } = h, c = l.exec(s);
67
67
  if (c) {
68
- const p = {}, b = (g) => {
68
+ const p = {}, b = (w) => {
69
69
  try {
70
- return decodeURIComponent(g);
70
+ return decodeURIComponent(w);
71
71
  } catch {
72
- return g;
72
+ return w;
73
73
  }
74
74
  };
75
- for (let g = 0; g < m.length; g++) {
76
- const q = c[g + 1] || "";
77
- p[m[g]] = q ? b(q) : "";
75
+ for (let w = 0; w < d.length; w++) {
76
+ const q = c[w + 1] || "";
77
+ p[d[w]] = q ? b(q) : "";
78
78
  }
79
- return { route: d, params: p };
79
+ return { route: m, params: p };
80
80
  }
81
81
  }
82
82
  return { route: null, params: {} };
@@ -101,22 +101,22 @@ async function ht(o) {
101
101
  throw new Error(`No component or loader defined for route: ${o.path}`);
102
102
  }
103
103
  function pt(o) {
104
- const { routes: i, base: s = "", initialUrl: d, scrollToFragment: h = !0 } = o, l = (() => {
104
+ const { routes: i, base: s = "", initialUrl: m, scrollToFragment: h = !0 } = o, l = (() => {
105
105
  if (!s) return "";
106
106
  const r = k(s);
107
107
  return r === "/" ? "" : r;
108
- })(), m = typeof h == "boolean" ? { enabled: !!h, offset: 0, timeoutMs: 2e3 } : {
108
+ })(), d = typeof h == "boolean" ? { enabled: !!h, offset: 0, timeoutMs: 2e3 } : {
109
109
  enabled: h.enabled ?? !0,
110
110
  offset: h.offset ?? 0,
111
111
  timeoutMs: h.timeoutMs ?? 2e3
112
112
  };
113
- let c, p, b, g, q, B, D;
113
+ let c, p, b, w, q, B, D;
114
114
  const Y = async (r, e) => {
115
115
  const t = K(i, r.path);
116
116
  if (!t || !t.beforeEnter) return !0;
117
117
  try {
118
118
  const n = await t.beforeEnter(r, e);
119
- return typeof n == "string" ? (await y(n, !0), !1) : n !== !1;
119
+ return typeof n == "string" ? (await g(n, !0), !1) : n !== !1;
120
120
  } catch (n) {
121
121
  return F("beforeEnter error", n), !1;
122
122
  }
@@ -125,7 +125,7 @@ function pt(o) {
125
125
  if (!t || !t.onEnter) return !0;
126
126
  try {
127
127
  const n = await t.onEnter(r, e);
128
- return typeof n == "string" ? (await y(n, !0), !1) : n !== !1;
128
+ return typeof n == "string" ? (await g(n, !0), !1) : n !== !1;
129
129
  } catch (n) {
130
130
  return F("onEnter error", n), !1;
131
131
  }
@@ -138,7 +138,7 @@ function pt(o) {
138
138
  F("afterEnter error", n);
139
139
  }
140
140
  };
141
- let w = 0, C = null, O = null, L = null;
141
+ let v = 0, C = null, O = null, L = null;
142
142
  async function a(r, e = 0) {
143
143
  try {
144
144
  const t = document.getElementById(r);
@@ -187,9 +187,9 @@ function pt(o) {
187
187
  O = null;
188
188
  }
189
189
  }
190
- function v(r, e, t) {
191
- w += 1;
192
- const n = w;
190
+ function y(r, e, t) {
191
+ v += 1;
192
+ const n = v;
193
193
  if (L) {
194
194
  try {
195
195
  L(!1);
@@ -200,7 +200,7 @@ function pt(o) {
200
200
  return u(), new Promise((E) => {
201
201
  L = E;
202
202
  const f = (A) => {
203
- if (n === w) {
203
+ if (n === v) {
204
204
  u();
205
205
  try {
206
206
  E(A);
@@ -210,24 +210,24 @@ function pt(o) {
210
210
  }
211
211
  };
212
212
  queueMicrotask(async () => {
213
- if (n !== w) return f(!1);
213
+ if (n !== v) return f(!1);
214
214
  if (await a(r, e)) return f(!0);
215
215
  if (typeof window.requestAnimationFrame == "function")
216
216
  window.requestAnimationFrame(async () => {
217
- if (n !== w) return f(!1);
217
+ if (n !== v) return f(!1);
218
218
  if (await a(r, e)) return f(!0);
219
- if (n !== w) return f(!1);
219
+ if (n !== v) return f(!1);
220
220
  const A = document.querySelector("router-view") || document.body;
221
221
  try {
222
222
  const x = new MutationObserver(async () => {
223
- n === w && await a(r, e) && f(!0);
223
+ n === v && await a(r, e) && f(!0);
224
224
  });
225
225
  C = x, x.observe(A, {
226
226
  childList: !0,
227
227
  subtree: !0,
228
228
  attributes: !1
229
229
  }), O = window.setTimeout(() => {
230
- if (n === w) {
230
+ if (n === v) {
231
231
  try {
232
232
  x.disconnect();
233
233
  } catch {
@@ -238,7 +238,7 @@ function pt(o) {
238
238
  } catch {
239
239
  let R = 0;
240
240
  const S = async () => {
241
- if (n !== w) return f(!1);
241
+ if (n !== v) return f(!1);
242
242
  if (await a(r, e)) return f(!0);
243
243
  R += 1, R < 40 ? window.setTimeout(S, 50) : f(!1);
244
244
  };
@@ -249,14 +249,14 @@ function pt(o) {
249
249
  const A = document.querySelector("router-view") || document.body;
250
250
  try {
251
251
  const x = new MutationObserver(async () => {
252
- n === w && await a(r, e) && f(!0);
252
+ n === v && await a(r, e) && f(!0);
253
253
  });
254
254
  C = x, x.observe(A, {
255
255
  childList: !0,
256
256
  subtree: !0,
257
257
  attributes: !1
258
258
  }), O = window.setTimeout(() => {
259
- if (n === w) {
259
+ if (n === v) {
260
260
  try {
261
261
  x.disconnect();
262
262
  } catch {
@@ -267,7 +267,7 @@ function pt(o) {
267
267
  } catch {
268
268
  let R = 0;
269
269
  const S = async () => {
270
- if (n !== w) return f(!1);
270
+ if (n !== v) return f(!1);
271
271
  if (await a(r, e)) return f(!0);
272
272
  R += 1, R < 40 ? window.setTimeout(S, 50) : f(!1);
273
273
  };
@@ -277,7 +277,7 @@ function pt(o) {
277
277
  });
278
278
  });
279
279
  }
280
- const y = async (r, e = !1) => {
280
+ const g = async (r, e = !1) => {
281
281
  try {
282
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
283
  path: k(x || "/"),
@@ -299,10 +299,10 @@ function pt(o) {
299
299
  b.setState(W), Z(W, N);
300
300
  try {
301
301
  const _ = W.fragment;
302
- m.enabled && _ && typeof window < "u" && typeof document < "u" && v(
302
+ d.enabled && _ && typeof window < "u" && typeof document < "u" && y(
303
303
  String(_),
304
- m.offset,
305
- m.timeoutMs
304
+ d.offset,
305
+ d.timeoutMs
306
306
  ).catch(() => {
307
307
  });
308
308
  } catch {
@@ -311,7 +311,7 @@ function pt(o) {
311
311
  F("Navigation error:", t);
312
312
  }
313
313
  };
314
- if (typeof window < "u" && typeof document < "u" && typeof d > "u") {
314
+ if (typeof window < "u" && typeof document < "u" && typeof m > "u") {
315
315
  c = () => {
316
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
317
  return { path: E, query: f, fragment: $ };
@@ -322,13 +322,13 @@ function pt(o) {
322
322
  params: r.params,
323
323
  query: p.query,
324
324
  fragment: p.fragment
325
- }), g = async (e = !1) => {
325
+ }), w = async (e = !1) => {
326
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();
327
+ await g(t.path, e);
328
+ }, window.addEventListener("popstate", () => w(!0)), q = (e) => g(e, !1), B = (e) => g(e, !0), D = () => window.history.back();
329
329
  } else {
330
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) : "";
331
+ const t = new URL(m || "/", "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
332
  return { path: f, query: $, fragment: A };
333
333
  }, p = c();
334
334
  const r = M(i, p.path);
@@ -337,7 +337,7 @@ function pt(o) {
337
337
  params: r.params,
338
338
  query: p.query,
339
339
  fragment: p.fragment
340
- }), g = async () => {
340
+ }), w = async () => {
341
341
  const t = c();
342
342
  await e(t.path);
343
343
  };
@@ -393,10 +393,10 @@ function pt(o) {
393
393
  // a fragment when they know their DOM is ready. Returns true if scrolled.
394
394
  scrollToFragment: (r) => {
395
395
  const e = r || b.getState().fragment;
396
- return !e || typeof window > "u" || typeof document > "u" ? Promise.resolve(!1) : v(
396
+ return !e || typeof window > "u" || typeof document > "u" ? Promise.resolve(!1) : y(
397
397
  String(e),
398
- m.offset,
399
- m.timeoutMs
398
+ d.offset,
399
+ d.timeoutMs
400
400
  );
401
401
  }
402
402
  };
@@ -408,39 +408,39 @@ let G = null;
408
408
  function bt(o) {
409
409
  const i = pt(o);
410
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());
411
+ const s = () => G || i;
412
+ if (!s()) return z`<div>Router not initialized.</div>`;
413
+ const m = V(s().getCurrent());
414
414
  let h;
415
415
  et(() => {
416
416
  try {
417
- s && typeof s.subscribe == "function" && (h = s.subscribe((m) => {
417
+ s() && typeof s().subscribe == "function" && (h = s().subscribe((d) => {
418
418
  try {
419
- d.value = m;
419
+ m.value = d;
420
420
  } catch (c) {
421
421
  P("router-view subscription update failed", c);
422
422
  }
423
423
  }));
424
- } catch (m) {
425
- P("router-view subscribe failed", m);
424
+ } catch (d) {
425
+ P("router-view subscribe failed", d);
426
426
  }
427
427
  }), nt(() => {
428
428
  if (typeof h == "function")
429
429
  try {
430
430
  h();
431
- } catch (m) {
432
- P("router-view unsubscribe failed", m);
431
+ } catch (d) {
432
+ P("router-view unsubscribe failed", d);
433
433
  }
434
434
  });
435
- const l = s.matchRoute(d.value.path);
435
+ const l = s().matchRoute(m.value.path);
436
436
  if (!l || !l.route) return z`<div>Not found</div>`;
437
437
  try {
438
- const c = await s.resolveRouteComponent(l.route);
438
+ const c = await s().resolveRouteComponent(l.route);
439
439
  if (typeof c == "string")
440
440
  return { tag: c, props: {}, children: [] };
441
441
  if (typeof c == "function") {
442
442
  const p = c();
443
- return (p instanceof Promise ? p : Promise.resolve(p)).then((g) => typeof g == "string" ? { tag: g, props: {}, children: [] } : g);
443
+ return (p instanceof Promise ? p : Promise.resolve(p)).then((w) => typeof w == "string" ? { tag: w, props: {}, children: [] } : w);
444
444
  }
445
445
  return z`<div>Invalid route component</div>`;
446
446
  } catch {
@@ -460,17 +460,17 @@ function bt(o) {
460
460
  // allow host `class` and `style` attributes to be read via useProps
461
461
  class: "",
462
462
  style: ""
463
- }), d = G || i, h = V(d.getCurrent());
463
+ }), m = () => G || i, h = V(m().getCurrent());
464
464
  let l;
465
465
  it(() => "a,button{display:inline-block;}");
466
- const m = V(s.class || ""), c = V(s.style || "");
466
+ const d = V(s.class || ""), c = V(s.style || "");
467
467
  et((a) => {
468
468
  try {
469
- d && typeof d.subscribe == "function" && (l = d.subscribe((u) => {
469
+ m() && typeof m().subscribe == "function" && (l = m().subscribe((u) => {
470
470
  try {
471
471
  h.value = u;
472
- } catch (v) {
473
- P("router-link subscription update failed", v);
472
+ } catch (y) {
473
+ P("router-link subscription update failed", y);
474
474
  }
475
475
  }));
476
476
  } catch (u) {
@@ -479,8 +479,8 @@ function bt(o) {
479
479
  try {
480
480
  const u = a?._host;
481
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");
482
+ const y = u.getAttribute("class"), g = u.getAttribute("style");
483
+ y && (d.value = y), g && (c.value = g), y !== null && u.removeAttribute("class"), g !== null && u.removeAttribute("style");
484
484
  }
485
485
  } catch (u) {
486
486
  P("router-link host migration failed", u);
@@ -494,46 +494,46 @@ function bt(o) {
494
494
  }
495
495
  });
496
496
  const p = T(() => {
497
- const a = d?.base ?? "", u = s.to || "";
497
+ const a = m().base ?? "", u = s.to || "";
498
498
  if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(u) || u.startsWith("//"))
499
499
  return !1;
500
- const v = (u.split("#")[0] || "/").split("?")[0];
500
+ const y = (u.split("#")[0] || "/").split("?")[0];
501
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);
502
+ let g = y;
503
+ a && g.startsWith(a) && (g = g.slice(a.length) || "/");
504
+ const r = k(h.value.path), e = k(g);
505
505
  return r === e;
506
506
  } catch {
507
- return h.value.path === v;
507
+ return h.value.path === y;
508
508
  }
509
509
  }), b = T(() => {
510
- const a = d?.base ?? "", u = s.to || "";
510
+ const a = m().base ?? "", u = s.to || "";
511
511
  if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(u) || u.startsWith("//"))
512
512
  return !1;
513
- const v = (u.split("#")[0] || "/").split("?")[0];
513
+ const y = (u.split("#")[0] || "/").split("?")[0];
514
514
  if (s.exact) return p.value;
515
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);
516
+ let g = y;
517
+ a && g.startsWith(a) && (g = g.slice(a.length) || "/");
518
+ const r = k(h.value.path), e = k(g);
519
519
  return e === "/" ? r === "/" : r === e ? !0 : r.startsWith(e.endsWith("/") ? e : e + "/");
520
520
  } catch {
521
- return h.value && typeof h.value.path == "string" && h.value.path.startsWith(v);
521
+ return h.value && typeof h.value.path == "string" && h.value.path.startsWith(y);
522
522
  }
523
- }), g = T(() => {
523
+ }), w = T(() => {
524
524
  const a = String(s.to || "");
525
525
  if (at(a)) return null;
526
526
  if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(a) || a.startsWith("//"))
527
527
  return a;
528
- const [u, v] = a.split("#"), [y, r] = (u || "").split("?"), e = d?.base ?? "";
529
- let t = y || "/";
528
+ const [u, y] = a.split("#"), [g, r] = (u || "").split("?"), e = m().base ?? "";
529
+ let t = g || "/";
530
530
  e && t.startsWith(e) && (t = t.slice(e.length) || "/");
531
531
  const n = k(t || "/");
532
- return e + n + (r ? "?" + r : "") + (v ? "#" + v : "");
532
+ return e + n + (r ? "?" + r : "") + (y ? "#" + y : "");
533
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;
534
+ const u = (d && d.value || s.class || "").split(/\s+/).filter(Boolean), y = {};
535
+ for (const g of u) y[g] = !0;
536
+ return y;
537
537
  }), B = T(() => ({
538
538
  ...q.value,
539
539
  [s.activeClass || "active"]: b.value,
@@ -542,7 +542,7 @@ function bt(o) {
542
542
  () => Object.keys(B.value).filter((a) => B.value[a]).join(" ")
543
543
  ), Y = T(() => s.tag || "a"), X = T(() => Y.value === "button"), Z = T(
544
544
  () => p.value ? s.ariaCurrentValue : null
545
- ), w = T(() => !!s.disabled), C = T(() => {
545
+ ), v = T(() => !!s.disabled), C = T(() => {
546
546
  const a = String(s.to || "");
547
547
  return (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(a) || a.startsWith("//") || !!s.external) && Y.value === "a";
548
548
  }), O = T(
@@ -550,7 +550,7 @@ function bt(o) {
550
550
  ), L = (a) => {
551
551
  if (a.defaultPrevented || a.button !== 0 || a.metaKey || a.altKey || a.ctrlKey || a.shiftKey)
552
552
  return;
553
- if (w.value) {
553
+ if (v.value) {
554
554
  a.preventDefault();
555
555
  return;
556
556
  }
@@ -563,7 +563,10 @@ function bt(o) {
563
563
  P("Blocked unsafe javascript: URI in router-link.to");
564
564
  return;
565
565
  }
566
- C.value || (a.preventDefault(), s.replace ? d.replace(s.to) : d.push(s.to));
566
+ if (C.value) return;
567
+ a.preventDefault();
568
+ const y = m();
569
+ s.replace ? y.replace(s.to) : y.push(s.to);
567
570
  };
568
571
  return z`
569
572
  ${ct().when(
@@ -574,9 +577,9 @@ function bt(o) {
574
577
  class="${D.value}"
575
578
  style="${O.value || null}"
576
579
  aria-current="${Z.value}"
577
- disabled="${w.value ? "" : null}"
578
- aria-disabled="${w.value ? "true" : null}"
579
- tabindex="${w.value ? "-1" : null}"
580
+ disabled="${v.value ? "" : null}"
581
+ aria-disabled="${v.value ? "true" : null}"
582
+ tabindex="${v.value ? "-1" : null}"
580
583
  @click="${L}"
581
584
  >
582
585
  <slot></slot>
@@ -585,12 +588,12 @@ function bt(o) {
585
588
  ).otherwise(z`
586
589
  <a
587
590
  part="link"
588
- href="${w.value ? null : g.value}"
591
+ href="${v.value ? null : w.value}"
589
592
  class="${D.value}"
590
593
  style="${O.value || null}"
591
594
  aria-current="${Z.value}"
592
- aria-disabled="${w.value ? "true" : null}"
593
- tabindex="${w.value ? "-1" : null}"
595
+ aria-disabled="${v.value ? "true" : null}"
596
+ tabindex="${v.value ? "-1" : null}"
594
597
  target="${C.value ? "_blank" : null}"
595
598
  rel="${C.value ? "noopener noreferrer" : null}"
596
599
  @click="${L}"