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