@jasonshimmy/custom-elements-runtime 3.1.1 → 3.1.3

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,4 +1,4 @@
1
- import { a as g, d as q } from "./logger-BvkEbVM4.js";
1
+ import { a as g, d as _ } from "./logger-BvkEbVM4.js";
2
2
  import { j as nt, r as et, w as it, x as lt, b as St, z as Rt, d as I } from "./hooks-xWZhQHco.js";
3
3
  import { c as ut, h as U } from "./template-compiler-ZhSg1yPh.js";
4
4
  import { createStore as ft } from "./custom-elements-runtime.store.es.js";
@@ -36,10 +36,10 @@ function xt(t) {
36
36
  }
37
37
  function Pt(t) {
38
38
  const r = t.path || "/", d = C(r), a = d === "/" ? [] : d.split("/").filter(Boolean), c = [], o = [];
39
- for (let i = 0; i < a.length; i++) {
40
- const l = a[i];
41
- if (l === "*") {
42
- if (i !== a.length - 1)
39
+ for (let l = 0; l < a.length; l++) {
40
+ const i = a[l];
41
+ if (i === "*") {
42
+ if (l !== a.length - 1)
43
43
  return g(
44
44
  `Route '${t.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`
45
45
  ), { invalid: !0 };
@@ -47,30 +47,30 @@ function Pt(t) {
47
47
  c.push(A), o.push("__SPLAT__");
48
48
  continue;
49
49
  }
50
- const y = l.match(/^:([A-Za-z0-9_-]+)(\*)?$/);
50
+ const y = i.match(/^:([A-Za-z0-9_-]+)(\*)?$/);
51
51
  if (y) {
52
52
  const A = y[1], x = !!y[2];
53
- if (x && i !== a.length - 1)
53
+ if (x && l !== a.length - 1)
54
54
  return g(
55
55
  `Route '${t.path}' contains a splat param ':${A}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`
56
56
  ), { invalid: !0 };
57
57
  c.push(A), o.push(x ? "__SPLAT__" : "([^/]+)");
58
58
  continue;
59
59
  }
60
- o.push(xt(l));
60
+ o.push(xt(i));
61
61
  }
62
62
  let w;
63
63
  if (o.length === 0)
64
64
  w = "^/$";
65
65
  else if (o[o.length - 1] === "__SPLAT__") {
66
- const l = o.slice(0, -1).join("/");
67
- l ? w = `^/${l}(?:/(.*))?(?:/)?$` : w = "^(?:/(.*))?(?:/)?$";
66
+ const i = o.slice(0, -1).join("/");
67
+ i ? w = `^/${i}(?:/(.*))?(?:/)?$` : w = "^(?:/(.*))?(?:/)?$";
68
68
  } else
69
69
  w = `^/${o.join("/")}(?:/)?$`;
70
70
  try {
71
71
  return { regex: new RegExp(w), paramNames: c };
72
- } catch (i) {
73
- return g(`Failed to compile route regex for '${t.path}': ${String(i)}`), { invalid: !0 };
72
+ } catch (l) {
73
+ return g(`Failed to compile route regex for '${t.path}': ${String(l)}`), { invalid: !0 };
74
74
  }
75
75
  }
76
76
  const Q = (t, r) => {
@@ -78,14 +78,14 @@ const Q = (t, r) => {
78
78
  for (const a of t) {
79
79
  let c = dt.get(a);
80
80
  if (c || (c = Pt(a), dt.set(a, c)), c.invalid) continue;
81
- const { regex: o, paramNames: w } = c, i = o.exec(d);
82
- if (i) {
83
- const l = {};
81
+ const { regex: o, paramNames: w } = c, l = o.exec(d);
82
+ if (l) {
83
+ const i = {};
84
84
  for (let y = 0; y < w.length; y++) {
85
- const A = i[y + 1] || "";
86
- l[w[y]] = A ? Ct(A) : "";
85
+ const A = l[y + 1] || "";
86
+ i[w[y]] = A ? Ct(A) : "";
87
87
  }
88
- return { route: a, params: l };
88
+ return { route: a, params: i };
89
89
  }
90
90
  }
91
91
  return { route: null, params: {} };
@@ -136,7 +136,7 @@ async function qt(t) {
136
136
  }).catch((c) => {
137
137
  delete B[t.path];
138
138
  const o = c instanceof Error ? c.message : String(c);
139
- throw d && q(
139
+ throw d && _(
140
140
  `SSR component load failed for route: ${t.path}. ${o}`
141
141
  ), new Error(
142
142
  `Failed to load component for route: ${t.path}. ${o}`
@@ -299,10 +299,10 @@ const E = {
299
299
  };
300
300
  function Mt(t) {
301
301
  const { routes: r, base: d = "", initialUrl: a, scrollToFragment: c = !0 } = t, o = At(d), w = typeof c == "boolean" ? { ...ht, enabled: c } : { ...ht, ...c };
302
- let i, l, y, A, x, F, V, X = () => {
302
+ let l, i, y, A, x, F, V, X = () => {
303
303
  };
304
304
  const T = /* @__PURE__ */ new Set(), j = 10;
305
- let k = 0;
305
+ let q = 0;
306
306
  const G = async (s, u) => {
307
307
  const e = rt(r, s.path);
308
308
  if (!e || !e.beforeEnter) return !0;
@@ -310,11 +310,11 @@ function Mt(t) {
310
310
  const n = await e.beforeEnter(s, u);
311
311
  if (typeof n == "string") {
312
312
  const h = `${s.path}->${n}`;
313
- return T.has(h) || k >= j ? (q(`Redirect loop detected: ${h}`), !1) : n;
313
+ return T.has(h) || q >= j ? (_(`Redirect loop detected: ${h}`), !1) : n;
314
314
  }
315
315
  return n !== !1;
316
316
  } catch (n) {
317
- q("beforeEnter error", n);
317
+ _("beforeEnter error", n);
318
318
  try {
319
319
  y.setState(u);
320
320
  } catch {
@@ -328,11 +328,11 @@ function Mt(t) {
328
328
  const n = await e.onEnter(s, u);
329
329
  if (typeof n == "string") {
330
330
  const h = `${s.path}->${n}`;
331
- return T.has(h) || k >= j ? (q(`Redirect loop detected: ${h}`), !1) : n;
331
+ return T.has(h) || q >= j ? (_(`Redirect loop detected: ${h}`), !1) : n;
332
332
  }
333
333
  return n !== !1;
334
334
  } catch (n) {
335
- q("onEnter error", n);
335
+ _("onEnter error", n);
336
336
  try {
337
337
  y.setState(u);
338
338
  } catch {
@@ -345,10 +345,10 @@ function Mt(t) {
345
345
  try {
346
346
  const n = e.afterEnter(s, u);
347
347
  n instanceof Promise && n.catch((h) => {
348
- q("afterEnter async error", h);
348
+ _("afterEnter async error", h);
349
349
  });
350
350
  } catch (n) {
351
- q("afterEnter error", n);
351
+ _("afterEnter error", n);
352
352
  }
353
353
  }, P = /* @__PURE__ */ new Map(), W = 100, M = (s) => {
354
354
  if (P.has(s))
@@ -432,16 +432,16 @@ function Mt(t) {
432
432
  });
433
433
  }
434
434
  let f = !1;
435
- const _ = async (s, u = !1) => {
435
+ const k = async (s, u = !1) => {
436
436
  if (f) {
437
437
  g(`Navigation to ${s} blocked - navigation already in progress`);
438
438
  return;
439
439
  }
440
- f = !0, k = 0, T.clear();
440
+ f = !0, q = 0, T.clear();
441
441
  try {
442
442
  await L(s, u);
443
443
  } finally {
444
- f = !1, k = 0, T.clear();
444
+ f = !1, q = 0, T.clear();
445
445
  }
446
446
  }, O = (s) => {
447
447
  const u = s.indexOf("#"), e = u >= 0 ? s.slice(u + 1) : "", n = u >= 0 ? s.slice(0, u) : s, h = n.indexOf("?"), v = h >= 0 ? n.slice(0, h) : n, b = h >= 0 ? st(n.slice(h)) : {}, $ = v.startsWith(o) ? v.slice(o.length) : v;
@@ -462,7 +462,7 @@ function Mt(t) {
462
462
  }, b = await G(v, h);
463
463
  if (b === !1) return;
464
464
  if (typeof b == "string") {
465
- k++;
465
+ q++;
466
466
  const S = `${v.path}->${b}`;
467
467
  T.add(S), await L(b, !0);
468
468
  return;
@@ -470,7 +470,7 @@ function Mt(t) {
470
470
  const $ = await at(v, h);
471
471
  if ($ === !1) return;
472
472
  if (typeof $ == "string") {
473
- k++;
473
+ q++;
474
474
  const S = `${v.path}->${$}`;
475
475
  T.add(S), await L($, !0);
476
476
  return;
@@ -491,7 +491,7 @@ function Mt(t) {
491
491
  } catch {
492
492
  }
493
493
  } catch (e) {
494
- if (q("Navigation error:", e), e instanceof Error && (e.stack?.includes("runBeforeEnter") || e.stack?.includes("runOnEnter")))
494
+ if (_("Navigation error:", e), e instanceof Error && (e.stack?.includes("runBeforeEnter") || e.stack?.includes("runOnEnter")))
495
495
  throw e;
496
496
  try {
497
497
  const n = y.getState();
@@ -507,7 +507,7 @@ function Mt(t) {
507
507
  query: {}
508
508
  });
509
509
  } else
510
- q("No fallback route available for error recovery");
510
+ _("No fallback route available for error recovery");
511
511
  }
512
512
  } catch (n) {
513
513
  g(
@@ -519,11 +519,11 @@ function Mt(t) {
519
519
  };
520
520
  if (((s) => {
521
521
  if (!s || s.length === 0)
522
- return q("Router configuration error: No routes provided"), !1;
522
+ return _("Router configuration error: No routes provided"), !1;
523
523
  const u = /* @__PURE__ */ new Set();
524
524
  for (const e of s) {
525
525
  if (!e.path)
526
- return q("Router configuration error: Route missing path", e), !1;
526
+ return _("Router configuration error: Route missing path", e), !1;
527
527
  u.has(e.path) && g(`Duplicate route path detected: ${e.path}`), u.add(e.path), !e.component && !e.load && g(`Route '${e.path}' has no component or load function`);
528
528
  }
529
529
  return !0;
@@ -533,28 +533,32 @@ function Mt(t) {
533
533
  g(`Pre-compiled ${r.length} routes for SSR`);
534
534
  }
535
535
  if (typeof window < "u" && typeof document < "u" && typeof a > "u") {
536
- i = () => {
536
+ l = () => {
537
537
  try {
538
538
  const e = new URL(window.location.href), n = e.pathname, h = n.startsWith(o) ? n.slice(o.length) : n, v = C(h || "/"), b = st(e.search), $ = e.hash && e.hash.length ? e.hash.slice(1) : "";
539
539
  return { path: v, query: b, fragment: $ };
540
540
  } catch (e) {
541
541
  return g("Invalid URL detected, falling back to safe defaults", e), { path: "/", query: {}, fragment: "" };
542
542
  }
543
- }, l = i();
544
- const s = M(l.path);
543
+ }, i = l();
544
+ const s = M(i.path);
545
545
  y = ft({
546
- path: l.path,
546
+ path: i.path,
547
547
  params: s.params,
548
- query: l.query,
549
- fragment: l.fragment
548
+ query: i.query,
549
+ fragment: i.fragment
550
550
  }), A = async (e = !1) => {
551
- const n = i();
552
- await _(n.path, e);
551
+ const n = l();
552
+ await k(n.path, e);
553
553
  };
554
554
  const u = () => A(!0);
555
- window.addEventListener("popstate", u), X = () => window.removeEventListener("popstate", u), x = (e) => _(e, !1), F = (e) => _(e, !0), V = () => window.history.back();
555
+ window.addEventListener("popstate", u), X = () => window.removeEventListener("popstate", u), x = (e) => k(e, !1), F = (e) => k(e, !0), V = () => window.history.back(), queueMicrotask(() => {
556
+ k(i.path, !0).catch((e) => {
557
+ _("Initial navigation error:", e);
558
+ });
559
+ });
556
560
  } else {
557
- i = () => {
561
+ l = () => {
558
562
  try {
559
563
  const e = new URL(a || "/", "http://localhost"), n = e.pathname, h = n.startsWith(o) ? n.slice(o.length) : n, v = C(h || "/"), b = st(e.search), $ = e.hash && e.hash.length ? e.hash.slice(1) : "";
560
564
  return { path: v, query: b, fragment: $ };
@@ -564,20 +568,20 @@ function Mt(t) {
564
568
  e
565
569
  ), { path: "/", query: {}, fragment: "" };
566
570
  }
567
- }, l = i();
568
- const s = M(l.path);
571
+ }, i = l();
572
+ const s = M(i.path);
569
573
  y = ft({
570
- path: l.path,
574
+ path: i.path,
571
575
  params: s.params,
572
- query: l.query,
573
- fragment: l.fragment
576
+ query: i.query,
577
+ fragment: i.fragment
574
578
  }), A = async () => {
575
- const e = i();
579
+ const e = l();
576
580
  await u(e.path);
577
581
  };
578
582
  const u = async (e) => {
579
- if (k++, k > j) {
580
- q(`SSR redirect depth exceeded for path: ${e}`);
583
+ if (q++, q > j) {
584
+ _(`SSR redirect depth exceeded for path: ${e}`);
581
585
  return;
582
586
  }
583
587
  try {
@@ -609,10 +613,10 @@ function Mt(t) {
609
613
  }
610
614
  y.setState(b), $?.afterEnter && $.afterEnter(b, v);
611
615
  } catch (n) {
612
- throw q("SSR navigation error:", n), n;
616
+ throw _("SSR navigation error:", n), n;
613
617
  }
614
618
  };
615
- x = async (e) => (k = 0, T.clear(), u(e)), F = async (e) => (k = 0, T.clear(), u(e)), V = () => {
619
+ x = async (e) => (q = 0, T.clear(), u(e)), F = async (e) => (q = 0, T.clear(), u(e)), V = () => {
616
620
  };
617
621
  }
618
622
  return {
@@ -676,26 +680,26 @@ function jt(t) {
676
680
  let o;
677
681
  c || (it(() => {
678
682
  try {
679
- typeof E.subscribe == "function" && (o = E.subscribe((i) => {
683
+ typeof E.subscribe == "function" && (o = E.subscribe((l) => {
680
684
  try {
681
- i && typeof i == "object" && typeof i.path == "string" ? a.value = i : (g("router-view received invalid state", i), a.value = { path: "/", params: {}, query: {} });
682
- } catch (l) {
683
- g("router-view subscription update failed", l);
685
+ l && typeof l == "object" && typeof l.path == "string" ? a.value = l : (g("router-view received invalid state", l), a.value = { path: "/", params: {}, query: {} });
686
+ } catch (i) {
687
+ g("router-view subscription update failed", i);
684
688
  try {
685
689
  a.value = { path: "/", params: {}, query: {} };
686
690
  } catch {
687
691
  }
688
692
  }
689
693
  }));
690
- } catch (i) {
691
- g("router-view subscribe failed", i);
694
+ } catch (l) {
695
+ g("router-view subscribe failed", l);
692
696
  }
693
697
  }), lt(() => {
694
698
  if (typeof o == "function") {
695
699
  try {
696
700
  o();
697
- } catch (i) {
698
- g("router-view unsubscribe failed", i);
701
+ } catch (l) {
702
+ g("router-view unsubscribe failed", l);
699
703
  }
700
704
  o = void 0;
701
705
  }
@@ -703,13 +707,13 @@ function jt(t) {
703
707
  const w = E.matchRoute(a.value.path);
704
708
  if (!w || !w.route) return U`<div>Not found</div>`;
705
709
  try {
706
- const l = await E.resolveRouteComponent(
710
+ const i = await E.resolveRouteComponent(
707
711
  w.route
708
712
  );
709
- if (typeof l == "string")
710
- return { tag: l, props: {}, children: [] };
711
- if (typeof l == "function") {
712
- const y = l();
713
+ if (typeof i == "string")
714
+ return { tag: i, props: { attrs: { ...a.value.params } }, children: [] };
715
+ if (typeof i == "function") {
716
+ const y = i();
713
717
  return (y instanceof Promise ? y : Promise.resolve(y)).then((x) => typeof x == "string" ? { tag: x, props: {}, children: [] } : x);
714
718
  }
715
719
  return U`<div>Invalid route component</div>`;
@@ -730,18 +734,18 @@ function jt(t) {
730
734
  // allow host `class` and `style` attributes to be read via useProps
731
735
  class: "",
732
736
  style: ""
733
- }), c = typeof window > "u", o = et(E.getCurrent()), w = o.value?.path || "/", i = String(a.to || ""), l = c ? {
737
+ }), c = typeof window > "u", o = et(E.getCurrent()), w = o.value?.path || "/", l = String(a.to || ""), i = c ? {
734
738
  isExactActive: gt(
735
739
  w,
736
- i,
740
+ l,
737
741
  E.base
738
742
  ),
739
743
  isActive: vt(
740
744
  w,
741
- i,
745
+ l,
742
746
  E.base
743
747
  ),
744
- isExternal: Z(i) || !!a.external
748
+ isExternal: Z(l) || !!a.external
745
749
  } : null;
746
750
  let y;
747
751
  Rt(() => "a,button{display:inline-block;}");
@@ -754,8 +758,8 @@ function jt(t) {
754
758
  y = E.subscribe((f) => {
755
759
  try {
756
760
  f && typeof f == "object" && typeof f.path == "string" ? o.value = f : (g("router-link received invalid state", f), o.value = { path: "/", params: {}, query: {} });
757
- } catch (_) {
758
- g("router-link subscription update failed", _);
761
+ } catch (k) {
762
+ g("router-link subscription update failed", k);
759
763
  try {
760
764
  o.value = { path: "/", params: {}, query: {} };
761
765
  } catch {
@@ -782,8 +786,8 @@ function jt(t) {
782
786
  try {
783
787
  const f = R?._host;
784
788
  if (f instanceof HTMLElement) {
785
- const _ = f.getAttribute("class"), O = f.getAttribute("style");
786
- _ && (A.value = _), O && (x.value = O), _ !== null && f.removeAttribute("class"), O !== null && f.removeAttribute("style");
789
+ const k = f.getAttribute("class"), O = f.getAttribute("style");
790
+ k && (A.value = k), O && (x.value = O), k !== null && f.removeAttribute("class"), O !== null && f.removeAttribute("style");
787
791
  try {
788
792
  R?._requestRender?.();
789
793
  try {
@@ -816,8 +820,8 @@ function jt(t) {
816
820
  });
817
821
  }
818
822
  const F = I(() => {
819
- if (c && l)
820
- return l.isExactActive;
823
+ if (c && i)
824
+ return i.isExactActive;
821
825
  try {
822
826
  const p = E.base ?? "", R = a.to || "";
823
827
  return !o.value || typeof o.value.path != "string" ? !1 : gt(o.value.path, R, p);
@@ -825,8 +829,8 @@ function jt(t) {
825
829
  return g("isExactActive computation error", p), !1;
826
830
  }
827
831
  }), V = I(() => {
828
- if (c && l)
829
- return l.isActive;
832
+ if (c && i)
833
+ return i.isActive;
830
834
  try {
831
835
  const p = E.base ?? "", R = a.to || "";
832
836
  return !o.value || typeof o.value.path != "string" ? !1 : a.exact ? F.value : vt(o.value.path, R, p);
@@ -837,8 +841,8 @@ function jt(t) {
837
841
  const p = String(a.to || "");
838
842
  if (pt(p)) return null;
839
843
  if (Z(p)) return p;
840
- const [R, f] = p.split("#"), [_, O] = (R || "").split("?"), L = E.base ?? "";
841
- let H = _ || "/";
844
+ const [R, f] = p.split("#"), [k, O] = (R || "").split("?"), L = E.base ?? "";
845
+ let H = k || "/";
842
846
  if (L && L !== "/") {
843
847
  const ot = C(L), s = C(H);
844
848
  s.startsWith(ot) ? H = s.slice(ot.length) || "/" : H = s;
@@ -847,13 +851,13 @@ function jt(t) {
847
851
  return L + ct + (O ? "?" + O : "") + (f ? "#" + f : "");
848
852
  }), T = I(() => {
849
853
  const R = (A && A.value || a.class || "").split(/\s+/).filter(Boolean), f = {};
850
- for (const _ of R) f[_] = !0;
854
+ for (const k of R) f[k] = !0;
851
855
  return f;
852
856
  }), j = I(() => ({
853
857
  ...T.value,
854
858
  [a.activeClass || "active"]: V.value,
855
859
  [a.exactActiveClass || "exact-active"]: F.value
856
- })), k = I(
860
+ })), q = I(
857
861
  () => Object.keys(j.value).filter((p) => j.value[p]).join(" ")
858
862
  ), G = I(() => a.tag || "a"), at = I(() => G.value === "button"), Y = I(
859
863
  () => F.value ? a.ariaCurrentValue : null
@@ -886,7 +890,7 @@ function jt(t) {
886
890
  U`
887
891
  <button
888
892
  part="button"
889
- class="${k.value}"
893
+ class="${q.value}"
890
894
  style="${M.value || null}"
891
895
  aria-current="${Y.value}"
892
896
  disabled="${P.value ? "" : null}"
@@ -901,7 +905,7 @@ function jt(t) {
901
905
  <a
902
906
  part="link"
903
907
  href="${P.value ? null : X.value}"
904
- class="${k.value}"
908
+ class="${q.value}"
905
909
  style="${M.value || null}"
906
910
  aria-current="${Y.value}"
907
911
  aria-disabled="${P.value ? "true" : null}"
@@ -919,8 +923,8 @@ function gt(t, r, d) {
919
923
  if (Z(r)) return !1;
920
924
  let c = (r.split("#")[0] || "/").split("?")[0];
921
925
  if (d && d !== "/") {
922
- const i = C(d), l = C(c);
923
- l.startsWith(i) ? c = l.slice(i.length) || "/" : c = l;
926
+ const l = C(d), i = C(c);
927
+ i.startsWith(l) ? c = i.slice(l.length) || "/" : c = i;
924
928
  }
925
929
  const o = C(t), w = C(c);
926
930
  return o === w;
@@ -929,8 +933,8 @@ function vt(t, r, d) {
929
933
  if (Z(r)) return !1;
930
934
  let c = (r.split("#")[0] || "/").split("?")[0];
931
935
  if (d && d !== "/") {
932
- const i = C(d), l = C(c);
933
- l.startsWith(i) ? c = l.slice(i.length) || "/" : c = l;
936
+ const l = C(d), i = C(c);
937
+ i.startsWith(l) ? c = i.slice(l.length) || "/" : c = i;
934
938
  }
935
939
  const o = C(t), w = C(c);
936
940
  return w === "/" ? o === "/" : o === w ? !0 : o.startsWith(w.endsWith("/") ? w : w + "/");