@voltro/web 0.51.0 → 0.53.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,840 +0,0 @@
1
- import { t as e } from "./globalContext-d4A-ugDg.js";
2
- import { l as t, n, t as r } from "./defaultFallbacks-B4Ak-R6R.js";
3
- import { f as i, i as a } from "./routerState-DAT472IC.js";
4
- import { Component as o, useCallback as s, useContext as c, useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
5
- import { jsx as p, jsxs as m } from "react/jsx-runtime";
6
- //#region src/routeEventBus.ts
7
- var h = {
8
- pathname: "/",
9
- params: {},
10
- loaderData: void 0
11
- }, g = /* @__PURE__ */ new Set(), ee = (e) => {
12
- h = e;
13
- for (let e of g) e();
14
- }, _ = () => h, v = (e) => (g.add(e), () => {
15
- g.delete(e);
16
- }), y = class extends Error {
17
- _voltroControl = "not-found";
18
- constructor(e) {
19
- super(e ? `Not found: ${e}` : "Not found"), this.name = "NotFoundError";
20
- }
21
- }, b = class extends Error {
22
- _voltroControl = "redirect";
23
- location;
24
- status;
25
- constructor(e, t) {
26
- super(`Redirect: ${e}`), this.name = "RedirectError", this.location = e, this.status = t?.status ?? 303;
27
- }
28
- }, x = (e) => {
29
- throw new y(e);
30
- }, S = (e, t) => {
31
- throw new b(e, t);
32
- }, te = (e) => e instanceof Error && e._voltroControl === "not-found", C = (e) => e instanceof Error && e._voltroControl === "redirect" && typeof e.location == "string", ne = [
33
- "static",
34
- "spa",
35
- "ssr",
36
- "isr"
37
- ], w = 0, re = 1, T = 2, E = 3, D = (e) => e.startsWith("[[...") && e.endsWith("]]") ? {
38
- source: "(.*)",
39
- paramName: e.slice(5, -2),
40
- weight: T
41
- } : e.startsWith("[...") && e.endsWith("]") ? {
42
- source: "(.+)",
43
- paramName: e.slice(4, -1),
44
- weight: E
45
- } : e.startsWith("[") && e.endsWith("]") ? {
46
- source: "([^/]+)",
47
- paramName: e.slice(1, -1),
48
- weight: re
49
- } : {
50
- source: e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
51
- paramName: null,
52
- weight: w
53
- }, ie = (e) => {
54
- let t = e.pattern.split("/").map(D);
55
- for (let n = 0; n < t.length - 1; n++) {
56
- let r = t[n];
57
- if (r.weight === E || r.weight === T) throw Error(`Route ${JSON.stringify(e.pattern)}: catch-all segment must be last. Anything after a catch-all is unreachable.`);
58
- }
59
- let n, r = t[t.length - 1];
60
- n = r && r.weight === T ? `${t.slice(0, -1).map((e) => e.source).join("/")}(?:/(.*))?` : t.map((e) => e.source).join("/");
61
- let i = t.map((e) => e.paramName).filter((e) => e !== null), a = t.reduce((e, t) => e + t.weight, 0);
62
- return {
63
- ...e,
64
- regex: RegExp(`^${n}$`),
65
- paramNames: i,
66
- priority: a
67
- };
68
- }, ae = (e) => [...e].map((e, t) => ({
69
- route: e,
70
- index: t
71
- })).sort((e, t) => e.route.priority === t.route.priority ? e.index - t.index : e.route.priority - t.route.priority).map(({ route: e }) => e), O = (e, t) => {
72
- let n = ae(e);
73
- for (let e of n) {
74
- let n = e.regex.exec(t);
75
- if (n) {
76
- let t = {};
77
- for (let r = 0; r < e.paramNames.length; r++) {
78
- let i = n[r + 1];
79
- t[e.paramNames[r]] = i === void 0 ? "" : decodeURIComponent(i);
80
- }
81
- return {
82
- route: e,
83
- params: t
84
- };
85
- }
86
- }
87
- return null;
88
- }, oe = (e, t, n) => k(`${e}__seg${t}`, n), k = (e, t) => `${e}\u0000${Object.entries(t).sort(([e], [t]) => e < t ? -1 : 1).map(([e, t]) => `${e}=${t}`).join("")}`, se = (e, t) => {
89
- let n = e(t);
90
- return n instanceof Promise ? n.then(i) : i(n);
91
- }, ce = (e, t, n, r) => e === void 0 ? null : typeof e == "function" ? e({
92
- params: t,
93
- loaderData: n,
94
- locale: r ?? "en"
95
- }) : e, le = (e, t) => {
96
- let n = null, r = -1;
97
- for (let i of e) (i.prefix === "" || t === i.prefix || t.startsWith(`${i.prefix}/`)) && i.prefix.length > r && (n = i, r = i.prefix.length);
98
- return n;
99
- }, ue = (e, t, n) => {
100
- if (e) for (let r = n; r >= 0; r--) {
101
- let n = e[r]?.[t];
102
- if (n !== void 0) return n;
103
- }
104
- }, de = class {
105
- entries = /* @__PURE__ */ new Map();
106
- get(e) {
107
- return this.entries.get(e);
108
- }
109
- start(e, t) {
110
- let n = this.entries.get(e);
111
- if (n) return n;
112
- let r = new AbortController(), i;
113
- try {
114
- i = Promise.resolve(t(r.signal));
115
- } catch (e) {
116
- i = Promise.reject(e);
117
- }
118
- let a = {
119
- status: "pending",
120
- promise: i.then((t) => {
121
- r.signal.aborted || this.entries.set(e, {
122
- status: "success",
123
- data: t
124
- });
125
- }, (t) => {
126
- r.signal.aborted || this.entries.set(e, {
127
- status: "error",
128
- error: t
129
- });
130
- }),
131
- controller: r
132
- };
133
- return this.entries.set(e, a), a;
134
- }
135
- abort(e) {
136
- let t = this.entries.get(e);
137
- t?.status === "pending" && (t.controller.abort(), this.entries.delete(e));
138
- }
139
- invalidate(e) {
140
- let t = `${e}\u0000`;
141
- for (let e of this.entries.keys()) e.startsWith(t) && this.entries.delete(e);
142
- }
143
- seed(e, t) {
144
- this.entries.has(e) || this.entries.set(e, {
145
- status: "success",
146
- data: t
147
- });
148
- }
149
- clear() {
150
- this.entries.clear();
151
- }
152
- }, A = { kind: "native" }, fe = (e, t) => {
153
- if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return A;
154
- let n = e.target, r = n instanceof Element ? n.closest("a") : null;
155
- if (!r) return A;
156
- let i = r.getAttribute("href");
157
- if (i === null) return A;
158
- let a = r.getAttribute("target");
159
- if (a && a !== "_self" || r.hasAttribute("download") || r.hasAttribute("data-no-spa")) return A;
160
- let o = r.getAttribute("rel");
161
- if (o && /(^|\s)external(\s|$)/i.test(o)) return A;
162
- let s, c;
163
- try {
164
- c = new URL(t), s = new URL(i, c);
165
- } catch {
166
- return A;
167
- }
168
- return s.origin !== c.origin || s.pathname === c.pathname && s.search === c.search && s.hash !== "" ? A : {
169
- kind: "spa",
170
- to: s.pathname + s.search + s.hash
171
- };
172
- }, j = (e) => {
173
- let t = e.replace(/^#/, "");
174
- try {
175
- return decodeURIComponent(t);
176
- } catch {
177
- return t;
178
- }
179
- }, M = (e) => {
180
- let t = j(e);
181
- return t ? document.getElementById(t) ?? document.getElementsByName(t)[0] ?? null : null;
182
- }, pe = (e) => {
183
- if (typeof window.requestAnimationFrame == "function") {
184
- window.requestAnimationFrame(e);
185
- return;
186
- }
187
- window.setTimeout(e, 0);
188
- }, me = (e) => {
189
- if (!e.hash) {
190
- window.scrollTo(0, 0);
191
- return;
192
- }
193
- pe(() => {
194
- let t = M(e.hash);
195
- if (t) {
196
- t.scrollIntoView();
197
- return;
198
- }
199
- window.scrollTo(0, 0);
200
- });
201
- }, N = 0, he = () => {
202
- let e = typeof crypto < "u" ? crypto : void 0;
203
- return e && typeof e.randomUUID == "function" ? e.randomUUID() : (N += 1, `k${Date.now().toString(36)}-${N}`);
204
- }, P = e("router", null), F = () => {
205
- let e = c(P);
206
- if (!e) throw Error("Router hooks must be used inside <Router>.");
207
- return e;
208
- }, I = Symbol.for("@voltro/web/loaderData:absent"), L = e("loaderData", I), ge = (e, t) => {
209
- if (!e || e.pathname !== t) return;
210
- let n = {};
211
- for (let [t, r] of e.segments) n[t] = r;
212
- return {
213
- page: e.page,
214
- segments: n
215
- };
216
- }, _e = (e, t) => {
217
- if (e === t) return !0;
218
- if (!e || !t || !Object.is(e.page, t.page)) return !1;
219
- let n = Object.keys(e.segments), r = Object.keys(t.segments);
220
- return n.length === r.length && n.every((n) => Object.is(e.segments[Number(n)], t.segments[Number(n)]));
221
- }, ve = () => {
222
- if (typeof document > "u") return;
223
- let e = document.cookie.match(/(?:^|;\s*)voltro:locale=([^;]*)/);
224
- return e ? decodeURIComponent(e[1]) : void 0;
225
- }, ye = (e) => {
226
- if (e === null || typeof document > "u") return () => {};
227
- let t = document.title, n = [], r = [], i = [], a = [], o = [];
228
- typeof e.title == "string" && (document.title = e.title);
229
- let s = (e, t) => {
230
- let i = e.name ? `meta[name="${e.name}"]` : e.property ? `meta[property="${e.property}"]` : null;
231
- if (!i) return;
232
- let a = document.head.querySelector(i);
233
- if (a) r.push({
234
- el: a,
235
- previous: a.content
236
- }), a.content = t;
237
- else {
238
- let r = document.createElement("meta");
239
- e.name && r.setAttribute("name", e.name), e.property && r.setAttribute("property", e.property), r.setAttribute("content", t), document.head.appendChild(r), n.push(r);
240
- }
241
- };
242
- if (typeof e.description == "string" && s({ name: "description" }, e.description), e.noIndex && s({ name: "robots" }, "noindex, nofollow"), e.tags) for (let t of e.tags) s(t, t.content);
243
- if (e.canonical) {
244
- let t = document.head.querySelector("link[rel=\"canonical\"]");
245
- if (t) a.push({
246
- el: t,
247
- previous: t.href
248
- }), t.href = e.canonical;
249
- else {
250
- let t = document.createElement("link");
251
- t.rel = "canonical", t.href = e.canonical, document.head.appendChild(t), i.push(t);
252
- }
253
- }
254
- if (e.links) for (let t of e.links) {
255
- let e = document.createElement("link");
256
- e.rel = t.rel, e.href = t.href, t.hreflang && e.setAttribute("hreflang", t.hreflang), t.type && (e.type = t.type), t.title && (e.title = t.title), document.head.appendChild(e), i.push(e);
257
- }
258
- if (e.jsonLd) for (let t of e.jsonLd) {
259
- let e = document.createElement("script");
260
- e.type = "application/ld+json", e.setAttribute("data-voltro-page-jsonld", ""), e.textContent = be(t), document.head.appendChild(e), o.push(e);
261
- }
262
- return () => {
263
- document.title = t;
264
- for (let e of n) e.parentNode?.removeChild(e);
265
- for (let e of i) e.parentNode?.removeChild(e);
266
- for (let e of o) e.parentNode?.removeChild(e);
267
- for (let { el: e, previous: t } of r) e.content = t;
268
- for (let { el: e, previous: t } of a) e.href = t;
269
- };
270
- }, be = (e) => JSON.stringify(e).replace(/<\/(script)/gi, "<\\/$1").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029"), xe = class extends o {
271
- state = { error: null };
272
- static getDerivedStateFromError(e) {
273
- return { error: e };
274
- }
275
- componentDidUpdate(e) {
276
- e.resetKey !== this.props.resetKey && this.state.error !== null && this.setState({ error: null });
277
- }
278
- componentDidCatch(e, t) {
279
- console.error("[@voltro/web] route render error:", e, t);
280
- }
281
- reset = () => {
282
- this.setState({ error: null });
283
- };
284
- render() {
285
- if (this.state.error !== null) {
286
- let { Fallback: e } = this.props;
287
- return /* @__PURE__ */ p(e, {
288
- error: this.state.error,
289
- reset: this.reset
290
- });
291
- }
292
- return this.props.children;
293
- }
294
- }, Se = "data-voltro-page-slot", Ce = () => /* @__PURE__ */ p("div", { [Se]: "" }), R = ({ routes: e, notFounds: i = [], notFound: o = n, errorFallback: c = r }) => {
295
- let [m, h] = f(() => window.location.pathname), [g, _] = f(() => window.location.pathname), [v, y] = f(() => window.location.search + window.location.hash), b = v.split("#")[0] ?? "", x = d(new de()), S = d(/* @__PURE__ */ new Map()), [ne, w] = f(null), re = s((e, t) => (S.current.set(e, t), () => {
296
- S.current.delete(e);
297
- }), []), T = d(/* @__PURE__ */ new Map()), E = d(null), D = u(() => ae(e.map(ie)), [e]);
298
- l(() => {
299
- if (typeof window > "u") return;
300
- let e = window.history.scrollRestoration;
301
- try {
302
- window.history.scrollRestoration = "manual";
303
- } catch {}
304
- return window.history.state?.__vwebKey || window.history.replaceState({
305
- ...window.history.state,
306
- __vwebKey: he()
307
- }, ""), () => {
308
- try {
309
- window.history.scrollRestoration = e;
310
- } catch {}
311
- };
312
- }, []);
313
- let A = () => window.history.state?.__vwebKey ?? "initial";
314
- l(() => {
315
- let e = () => {
316
- let e = T.current.get(A());
317
- E.current = e ?? {
318
- x: 0,
319
- y: 0
320
- }, h(window.location.pathname), y(window.location.search + window.location.hash);
321
- };
322
- return window.addEventListener("popstate", e), () => window.removeEventListener("popstate", e);
323
- }, []);
324
- let j = s((e, t, n) => {
325
- T.current.set(A(), {
326
- x: window.scrollX,
327
- y: window.scrollY
328
- });
329
- let r = { __vwebKey: he() };
330
- n?.replace ? window.history.replaceState(r, "", e) : window.history.pushState(r, "", e), h(t.pathname), y(t.search + t.hash), n?.scroll !== !1 && me(t);
331
- }, []), M = s((e, t) => {
332
- let n = new URL(window.location.href), r = new URL(e, n);
333
- if (r.pathname !== n.pathname || r.search !== n.search || r.hash !== n.hash) {
334
- for (let n of S.current.values()) if (n({
335
- to: e,
336
- ...t ? { opts: t } : {}
337
- })) {
338
- w({
339
- to: e,
340
- ...t ? { opts: t } : {},
341
- retry: () => {
342
- w(null), j(e, r, t);
343
- },
344
- reset: () => w(null)
345
- });
346
- return;
347
- }
348
- j(e, r, t);
349
- }
350
- }, [j]);
351
- l(() => {
352
- if (typeof document > "u") return;
353
- let e = (e) => {
354
- let t = fe(e, window.location.href);
355
- t.kind === "spa" && (e.preventDefault(), M(t.to));
356
- };
357
- return document.addEventListener("click", e), () => document.removeEventListener("click", e);
358
- }, [M]);
359
- let N = u(() => O(D, m), [D, m]), P = d(/* @__PURE__ */ new Map()), [F, be] = f(0), Se = N?.route.load ? N.route.pattern : null;
360
- l(() => {
361
- let e = N?.route;
362
- if (!e?.load || P.current.has(e.pattern)) return;
363
- let t = !1;
364
- return e.load().then((n) => {
365
- t || (P.current.set(e.pattern, n), be((e) => e + 1));
366
- }).catch(() => {}), () => {
367
- t = !0;
368
- };
369
- }, [Se]);
370
- let R = d(/* @__PURE__ */ new Set()), Te = s((e) => {
371
- let t = e.load;
372
- t && (P.current.has(e.pattern) || R.current.has(e.pattern) || (R.current.add(e.pattern), t().then((t) => {
373
- P.current.set(e.pattern, t);
374
- }).catch(() => {
375
- R.current.delete(e.pattern);
376
- })));
377
- }, []), z = u(() => {
378
- if (!N) return null;
379
- let e = N.route;
380
- if (!e.load) return e;
381
- let t = P.current.get(e.pattern);
382
- return t ? {
383
- ...e,
384
- ...Pe(t),
385
- load: void 0
386
- } : null;
387
- }, [N, F]), B = u(() => O(D, g), [D, g]), V = u(() => {
388
- if (!B) return null;
389
- let e = B.route;
390
- if (!e.load) return e;
391
- let t = P.current.get(e.pattern);
392
- return t ? {
393
- ...e,
394
- ...Pe(t),
395
- load: void 0
396
- } : null;
397
- }, [B, F]), Oe = s((e) => {
398
- let t = new URL(e, window.location.origin), n = O(D, t.pathname);
399
- if (!n) return;
400
- let r = (e, r) => {
401
- x.current.start(e, (e) => se(r, {
402
- params: n.params,
403
- pathname: t.pathname,
404
- search: t.search,
405
- signal: e,
406
- isServer: !1
407
- }));
408
- };
409
- Te(n.route), n.route.loader && r(k(n.route.pattern, n.params), n.route.loader), n.route.chain?.forEach((e, t) => {
410
- e.loader && r(oe(n.route.pattern, t, n.params), e.loader);
411
- });
412
- }, [D, Te]), [H, U] = f({ status: "idle" }), W = d(void 0);
413
- W.current === void 0 && (W.current = a());
414
- let ke = d(!1), [Ae, je] = f(() => W.current?.pageClientOnly === !0 && W.current.pathname === m);
415
- l(() => {
416
- je(!1);
417
- }, []);
418
- let [G, Me] = f(() => ({
419
- pathname: m,
420
- data: ge(W.current ?? null, m),
421
- chain: N?.route.chain
422
- }));
423
- l(() => {
424
- let e = (e) => {
425
- _(m), Me((t) => t.pathname === m && _e(t.data, e) ? t : {
426
- pathname: m,
427
- data: e,
428
- chain: N?.route.chain
429
- });
430
- };
431
- if (!N) {
432
- U({ status: "idle" }), e(void 0);
433
- return;
434
- }
435
- if (!z) {
436
- U({
437
- status: "pending",
438
- key: k(N.route.pattern, N.params)
439
- });
440
- return;
441
- }
442
- let t = z, { params: n } = N, r = t.chain, i = (t.Pending ?? ue(r, "Pending", r ? r.length - 1 : -1)) !== void 0, a = [];
443
- if (t.loader) {
444
- let e = t.loader;
445
- a.push({
446
- cacheKey: k(t.pattern, n),
447
- target: "page",
448
- run: (t) => se(e, {
449
- params: n,
450
- pathname: m,
451
- search: b,
452
- signal: t,
453
- isServer: !1
454
- })
455
- });
456
- }
457
- if (t.chain?.forEach((e, r) => {
458
- if (e.loader) {
459
- let i = e.loader;
460
- a.push({
461
- cacheKey: oe(t.pattern, r, n),
462
- target: r,
463
- run: (e) => se(i, {
464
- params: n,
465
- pathname: m,
466
- search: b,
467
- signal: e,
468
- isServer: !1
469
- })
470
- });
471
- }
472
- }), a.length === 0) {
473
- U({ status: "idle" }), e(void 0);
474
- return;
475
- }
476
- let o = k(t.pattern, n), s = W.current;
477
- if (s && !ke.current && m === s.pathname) {
478
- ke.current = !0;
479
- for (let e of a) e.target === "page" ? s.pageRan && x.current.seed(e.cacheKey, s.page) : s.segments.has(e.target) && x.current.seed(e.cacheKey, s.segments.get(e.target));
480
- }
481
- let c = a.map((e) => ({
482
- spec: e,
483
- entry: x.current.start(e.cacheKey, e.run)
484
- })), l = () => {
485
- let e = {}, t;
486
- for (let { spec: n } of c) {
487
- let r = x.current.get(n.cacheKey);
488
- if (!r || r.status === "pending") return null;
489
- if (r.status === "error") return {
490
- ok: !1,
491
- error: r.error
492
- };
493
- n.target === "page" ? t = r.data : e[n.target] = r.data;
494
- }
495
- return {
496
- ok: !0,
497
- data: {
498
- page: t,
499
- segments: e
500
- }
501
- };
502
- }, u = l();
503
- if (u) {
504
- u.ok ? (U({
505
- status: "success",
506
- key: o,
507
- data: u.data
508
- }), e(u.data)) : (U({
509
- status: "error",
510
- key: o,
511
- error: u.error
512
- }), C(u.error) || e(void 0));
513
- return;
514
- }
515
- U({
516
- status: "pending",
517
- key: o
518
- }), i && _(m);
519
- let d = !1, f = c.map(({ entry: e }) => e.status === "pending" ? e.promise : Promise.resolve());
520
- return Promise.all(f).then(() => {
521
- if (d) return;
522
- let t = l();
523
- t && (t.ok ? (U({
524
- status: "success",
525
- key: o,
526
- data: t.data
527
- }), e(t.data)) : (U({
528
- status: "error",
529
- key: o,
530
- error: t.error
531
- }), C(t.error) || e(void 0)));
532
- }), () => {
533
- d = !0;
534
- };
535
- }, [
536
- N,
537
- z,
538
- m
539
- ]);
540
- let K = G.data?.page, q = g === m, J = G.pathname === g, Ne = J ? G.data?.page : void 0, Fe = V?.loader === void 0 ? I : Ne, Ie = ve(), Y = u(() => {
541
- if (!B) return null;
542
- let e = B.params.locale ?? Ie;
543
- return ce(V?.meta, B.params, K, e);
544
- }, [
545
- B,
546
- V,
547
- K,
548
- Ie
549
- ]);
550
- l(() => ye(Y), [Y]);
551
- let [X, Z] = f(""), Q = d(!1), [Le, Re] = f(!1);
552
- l(() => {
553
- if (!Q.current) {
554
- Q.current = !0, Re(!0);
555
- return;
556
- }
557
- let e = Y?.title ?? (typeof document < "u" ? document.title : "");
558
- Z(e && e.length > 0 ? e : g);
559
- }, [g, Y]), l(() => {
560
- let e = E.current;
561
- e && (E.current = null, pe(() => window.scrollTo(e.x, e.y)));
562
- }, [g]);
563
- let ze = u(() => ({
564
- pathname: g,
565
- search: v,
566
- navigate: M,
567
- params: B?.params ?? {},
568
- prefetch: Oe,
569
- loaderData: K,
570
- registerBlocker: re,
571
- blocked: ne
572
- }), [
573
- g,
574
- v,
575
- M,
576
- B,
577
- Oe,
578
- K,
579
- re,
580
- ne
581
- ]);
582
- l(() => {
583
- if (typeof window > "u") return;
584
- let e = (e) => {
585
- let t = !1;
586
- for (let e of S.current.values()) if (e({ to: window.location.pathname })) {
587
- t = !0;
588
- break;
589
- }
590
- t && (e.preventDefault(), e.returnValue = "");
591
- };
592
- return window.addEventListener("beforeunload", e), () => window.removeEventListener("beforeunload", e);
593
- }, []), l(() => {
594
- ee({
595
- pathname: g,
596
- params: B?.params ?? {},
597
- loaderData: K
598
- });
599
- }, [
600
- g,
601
- B,
602
- K
603
- ]), l(() => {
604
- if (H.status === "pending") return t({
605
- id: "voltro:router:loader",
606
- kind: "loading",
607
- label: "Loading…"
608
- });
609
- }, [H.status]), l(() => {
610
- if (H.status === "error") return t({
611
- id: "voltro:router:loader-error",
612
- kind: "error",
613
- label: "Loader failed"
614
- });
615
- }, [H.status]), l(() => {
616
- H.status === "error" && C(H.error) && M(H.error.location, { replace: !0 });
617
- }, [H, M]);
618
- let Be = () => {
619
- let e = le(i, g);
620
- if (e) {
621
- let { Component: t, chain: n } = e;
622
- return De(n, /* @__PURE__ */ p(t, {}), g, c);
623
- }
624
- return /* @__PURE__ */ p(o, {});
625
- }, Ve = q && B && H.status === "error" ? H.error : void 0, $;
626
- if (!B) $ = Be();
627
- else if (te(Ve)) $ = Be();
628
- else {
629
- let e = B.route.chain, t = e ? e.length - 1 : -1, n = V?.ErrorBoundary ?? ue(e, "Error", t) ?? c, r;
630
- if (Ae) r = /* @__PURE__ */ p(Ce, {});
631
- else if (q && H.status === "error" && !C(H.error)) r = /* @__PURE__ */ p(n, {
632
- error: H.error,
633
- reset: () => {
634
- x.current.invalidate(B.route.pattern), h((e) => e), U({ status: "idle" });
635
- }
636
- });
637
- else if (q && H.status === "pending") {
638
- let i = V?.Pending ?? ue(e, "Pending", t);
639
- if (i) r = /* @__PURE__ */ p(i, {});
640
- else if (V?.Component) {
641
- let e = V.Component;
642
- r = /* @__PURE__ */ p(xe, {
643
- resetKey: g,
644
- Fallback: n,
645
- children: /* @__PURE__ */ p(L.Provider, {
646
- value: Fe,
647
- children: /* @__PURE__ */ p(e, {})
648
- })
649
- });
650
- } else r = null;
651
- } else {
652
- let e = V?.Component;
653
- r = e ? /* @__PURE__ */ p(xe, {
654
- resetKey: g,
655
- Fallback: n,
656
- children: /* @__PURE__ */ p(L.Provider, {
657
- value: Fe,
658
- children: /* @__PURE__ */ p(e, {})
659
- })
660
- }) : null;
661
- }
662
- $ = De(e, r, g, c, (t) => {
663
- if (J) return G.data?.segments[t];
664
- let n = e?.[t]?.Layout;
665
- return n !== void 0 && n === G.chain?.[t]?.Layout ? G.data?.segments[t] : void 0;
666
- });
667
- }
668
- return /* @__PURE__ */ p(we, {
669
- value: ze,
670
- announcer: Le ? /* @__PURE__ */ p(Ee, { message: X }) : null,
671
- children: $
672
- });
673
- }, we = ({ value: e, announcer: t, children: n }) => /* @__PURE__ */ m(P.Provider, {
674
- value: e,
675
- children: [n, t]
676
- }), Te = (e, t) => /* @__PURE__ */ p(we, {
677
- value: e,
678
- announcer: null,
679
- children: t
680
- }), z = {
681
- position: "absolute",
682
- width: 1,
683
- height: 1,
684
- padding: 0,
685
- margin: -1,
686
- overflow: "hidden",
687
- clip: "rect(0, 0, 0, 0)",
688
- whiteSpace: "nowrap",
689
- border: 0
690
- }, Ee = ({ message: e }) => /* @__PURE__ */ p("div", {
691
- "data-vweb-route-announcer": "",
692
- role: "status",
693
- "aria-live": "assertive",
694
- "aria-atomic": "true",
695
- style: z,
696
- children: e
697
- }), De = (e, t, n, r, i) => {
698
- if (!e || e.length === 0) return t;
699
- let a = t;
700
- for (let t = e.length - 1; t >= 0; t--) {
701
- let r = e[t];
702
- if (r.Layout) {
703
- let e = r.Layout;
704
- a = /* @__PURE__ */ p(L.Provider, {
705
- value: r.loader === void 0 ? I : i?.(t),
706
- children: /* @__PURE__ */ p(e, { children: a })
707
- });
708
- }
709
- if (r.Error) {
710
- let e = r.Error;
711
- a = /* @__PURE__ */ p(xe, {
712
- resetKey: n,
713
- Fallback: e,
714
- children: a
715
- });
716
- }
717
- }
718
- return a;
719
- }, B = () => F().pathname, V = () => F().navigate, Oe = () => F().params, H = () => {
720
- let e = c(L);
721
- if (e === I) throw Error("useLoaderData() was called at a level that declares no `loader`. Export `loader` from this page/layout, or — if this component is shared between routes that have one and routes that do not — read it with `useOptionalLoaderData()`, which returns `undefined` here instead of throwing. The React component stack below names the component.");
722
- return e;
723
- }, U = () => {
724
- let e = c(L);
725
- return e === I ? void 0 : e;
726
- }, W = () => F().prefetch, ke = (e) => {
727
- let { registerBlocker: t, blocked: n } = F(), r = d(Symbol("voltro:blocker")), i = d(e);
728
- return i.current = e, l(() => {
729
- let e = r.current;
730
- return t(e, (e) => {
731
- let t = i.current;
732
- return typeof t == "function" ? t(e) : t;
733
- });
734
- }, [t]), n ? {
735
- blocked: !0,
736
- to: n.to,
737
- retry: n.retry,
738
- reset: n.reset
739
- } : { blocked: !1 };
740
- }, Ae = (e) => e instanceof URLSearchParams ? e : new URLSearchParams(e), je = () => {
741
- let { navigate: e } = F();
742
- return s((t, n) => {
743
- let r = new URLSearchParams(typeof window < "u" ? window.location.search : ""), i = Ae(typeof t == "function" ? t(r) : t).toString(), a = typeof window < "u" ? window.location.pathname : "/", o = i ? `${a}?${i}` : a;
744
- e(o, {
745
- replace: !n?.push,
746
- ...n?.scroll === void 0 ? {} : { scroll: n.scroll }
747
- });
748
- }, [e]);
749
- }, G = (e) => e, Me = (e, t) => {
750
- let n = new URLSearchParams();
751
- for (let [e, r] of Object.entries(t)) r !== void 0 && n.append(e, String(r));
752
- let r = n.toString();
753
- return r ? `${e}?${r}` : e;
754
- }, K = (e, t) => `${e}#${t.replace(/^#/, "")}`, q = (e) => /^([a-z][a-z0-9+.-]*:|\/\/|#)/i.test(e), J = ({ to: e, children: t, onClick: n, prefetch: r = !1, replace: i = !1, onMouseEnter: a, onFocus: o, ref: c, ...u }) => {
755
- let f = V(), m = W(), h = q(e), g = d(null), ee = s((e) => {
756
- g.current = e, typeof c == "function" ? c(e) : c && (c.current = e);
757
- }, [c]);
758
- l(() => {
759
- if (r !== "visible" || h) return;
760
- let t = g.current;
761
- if (!t || typeof IntersectionObserver > "u") return;
762
- let n = new IntersectionObserver((t) => {
763
- t.some((e) => e.isIntersecting) && (n.disconnect(), m(e));
764
- }, { rootMargin: "128px" });
765
- return n.observe(t), () => n.disconnect();
766
- }, [
767
- r,
768
- h,
769
- e,
770
- m
771
- ]);
772
- let _ = (t) => {
773
- h || t.metaKey || t.ctrlKey || t.shiftKey || t.altKey || t.button !== 0 || (t.preventDefault(), n?.(t), f(e, i ? { replace: i } : void 0));
774
- }, v = (t) => {
775
- r && !h && m(e), a?.(t);
776
- }, y = (t) => {
777
- r && !h && m(e), o?.(t);
778
- };
779
- return /* @__PURE__ */ p("a", {
780
- ...u,
781
- ref: ee,
782
- href: e,
783
- onClick: _,
784
- onMouseEnter: v,
785
- onFocus: y,
786
- children: t
787
- });
788
- }, Ne = (e) => J({
789
- ...e,
790
- to: e.to
791
- }), Pe = (e) => ({
792
- Component: e.default,
793
- meta: e.meta,
794
- loader: e.loader,
795
- ErrorBoundary: e.ErrorBoundary,
796
- Pending: e.Pending,
797
- renderMode: e.renderMode,
798
- interactive: e.interactive
799
- }), Fe = (e, t, n = {}) => ({
800
- pattern: e,
801
- ...Pe(t),
802
- chain: n.chain
803
- }), Ie = (e, t, n = {}) => ({
804
- pattern: e,
805
- load: t,
806
- chain: n.chain
807
- }), Y = async (e, t) => {
808
- let n = O(e.map(ie), t)?.route.load;
809
- if (n) try {
810
- await n();
811
- } catch {}
812
- }, X = e("serverRequest", null), Z = () => c(X), Q = () => {
813
- let e = Z();
814
- if (e !== null) {
815
- let t = e.url.indexOf("?");
816
- return new URLSearchParams(t >= 0 ? e.url.slice(t + 1) : "");
817
- }
818
- return typeof window < "u" ? new URLSearchParams(window.location.search) : new URLSearchParams();
819
- }, Le = ({ value: e, children: t }) => /* @__PURE__ */ p(X.Provider, {
820
- value: e,
821
- children: t
822
- }), Re = (e) => {
823
- let t = {};
824
- if (!e) return t;
825
- for (let n of e.split(";")) {
826
- let e = n.indexOf("=");
827
- if (e < 0) continue;
828
- let r = n.slice(0, e).trim();
829
- if (!r) continue;
830
- let i = n.slice(e + 1).trim();
831
- i.startsWith("\"") && i.endsWith("\"") && (i = i.slice(1, -1));
832
- try {
833
- i = decodeURIComponent(i);
834
- } catch {}
835
- t[r] = i;
836
- }
837
- return t;
838
- };
839
- //#endregion
840
- export { H as A, b as B, Y as C, oe as D, ce as E, W as F, _ as G, C as H, je as I, ee as K, K as L, V as M, U as N, ae as O, Oe as P, Me as R, Fe as S, fe as T, x as U, te as V, S as W, G as _, Z as a, k as b, L as c, Ce as d, Ne as f, ie as g, P as h, Q as i, B as j, ke as k, I as l, R as m, Le as n, J as o, ne as p, v as q, Re as r, de as s, X as t, Se as u, le as v, Te as w, O as x, Ie as y, y as z };