@jasonshimmy/custom-elements-runtime 2.2.4 → 2.2.5

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