routerino 2.3.4 → 2.4.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.
- package/README.md +17 -2
- package/dist/routerino.js +304 -246
- package/dist/routerino.umd.cjs +1 -1
- package/package.json +2 -1
- package/routerino-forge.js +176 -51
- package/routerino-image.jsx +139 -56
- package/types/routerino.d.ts +0 -1
package/dist/routerino.js
CHANGED
|
@@ -1,177 +1,226 @@
|
|
|
1
|
-
import { jsx as g, jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
return !!(
|
|
1
|
+
import { jsx as g, jsxs as B, Fragment as G } from "react/jsx-runtime";
|
|
2
|
+
import { useState as z, useEffect as _, useMemo as J, createContext as N, Component as Q, useContext as X } from "react";
|
|
3
|
+
import o from "prop-types";
|
|
4
|
+
const Y = [480, 800, 1200, 1920], ee = "(max-width: 480px) 100vw, (max-width: 800px) 800px, (max-width: 1200px) 1200px, 1920px", H = /* @__PURE__ */ new Map();
|
|
5
|
+
function te(i, e = "") {
|
|
6
|
+
const r = i.toLowerCase(), n = e.toLowerCase();
|
|
7
|
+
return !!(r.includes("hero") || r.includes("banner") || n.includes("hero") || n.includes("banner") || n.includes("h-screen") || n.includes("h-full"));
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
const n =
|
|
11
|
-
return e.map((
|
|
9
|
+
function q(i, e, r = null) {
|
|
10
|
+
const n = i.replace(/\.(jpe?g|png|webp)$/i, ""), u = r ? `.${r}` : i.match(/\.(jpe?g|png|webp)$/i)?.[0] || ".jpg";
|
|
11
|
+
return e.map((a) => `${n}-${a}w${u} ${a}w`).join(", ");
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function oe(i) {
|
|
14
14
|
const {
|
|
15
15
|
src: e = "",
|
|
16
|
-
alt:
|
|
16
|
+
alt: r = "",
|
|
17
17
|
priority: n,
|
|
18
|
-
widths:
|
|
19
|
-
sizes:
|
|
20
|
-
className:
|
|
21
|
-
style:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
widths: u = Y,
|
|
19
|
+
sizes: a = ee,
|
|
20
|
+
className: m = "",
|
|
21
|
+
style: O = {},
|
|
22
|
+
width: E,
|
|
23
|
+
height: S,
|
|
24
|
+
loading: I,
|
|
25
|
+
decoding: L = "async",
|
|
26
|
+
fetchpriority: f,
|
|
27
|
+
...T
|
|
28
|
+
} = i || {}, W = typeof window > "u", b = !W && typeof document < "u" && typeof HTMLElement < "u" && document.createElement("div") instanceof HTMLElement, R = b && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1"), c = n ?? te(e, m), k = I || (c ? "eager" : "lazy"), P = f || (c ? "high" : void 0), [y, s] = z(null);
|
|
29
|
+
_(() => {
|
|
30
|
+
if (!b || R || !e) return;
|
|
31
|
+
const h = new window.Image();
|
|
32
|
+
h.onload = () => {
|
|
33
|
+
s({
|
|
34
|
+
width: h.naturalWidth,
|
|
35
|
+
height: h.naturalHeight
|
|
36
|
+
});
|
|
37
|
+
}, h.src = e;
|
|
38
|
+
}, [e, b, R]);
|
|
39
|
+
const v = J(() => y ? u.filter((h) => y.width >= h) : u, [y, u]), [j, F] = z(null);
|
|
40
|
+
_(() => {
|
|
41
|
+
if (!b || R) return;
|
|
42
|
+
let h = !1;
|
|
43
|
+
return (async () => {
|
|
44
|
+
const x = e.replace(/\.(jpe?g|png|webp)$/i, ""), A = e.match(/\.(jpe?g|png|webp)$/i)?.[0] || ".jpg", D = [];
|
|
45
|
+
for (const M of v) {
|
|
46
|
+
const C = `${x}-${M}w${A}`;
|
|
47
|
+
if (H.has(C)) {
|
|
48
|
+
H.get(C) && D.push(M);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const V = await fetch(C, { method: "HEAD" });
|
|
53
|
+
H.set(C, V.ok), V.ok && D.push(M);
|
|
54
|
+
} catch {
|
|
55
|
+
H.set(C, !1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
h || F(
|
|
59
|
+
D.length > 0 ? D : v
|
|
60
|
+
);
|
|
61
|
+
})(), () => {
|
|
62
|
+
h = !0;
|
|
63
|
+
};
|
|
64
|
+
}, [e, v, b, R]);
|
|
65
|
+
const U = j ?? v, t = {};
|
|
66
|
+
E != null && (t.width = E), S != null && (t.height = S), y && E == null && S == null && (t.width = y.width, t.height = y.height);
|
|
67
|
+
const l = {
|
|
68
|
+
maxWidth: "100%",
|
|
69
|
+
height: "auto",
|
|
70
|
+
...O
|
|
71
|
+
};
|
|
72
|
+
if (R)
|
|
28
73
|
return /* @__PURE__ */ g(
|
|
29
74
|
"img",
|
|
30
75
|
{
|
|
31
76
|
src: e,
|
|
32
|
-
alt:
|
|
33
|
-
loading:
|
|
34
|
-
decoding:
|
|
35
|
-
fetchPriority:
|
|
36
|
-
className:
|
|
37
|
-
style:
|
|
38
|
-
...
|
|
77
|
+
alt: r,
|
|
78
|
+
loading: k,
|
|
79
|
+
decoding: L,
|
|
80
|
+
fetchPriority: P,
|
|
81
|
+
className: m,
|
|
82
|
+
style: l,
|
|
83
|
+
...t,
|
|
84
|
+
...T
|
|
39
85
|
}
|
|
40
86
|
);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
}, y.src = e;
|
|
51
|
-
}, [e, S]);
|
|
52
|
-
const b = T ? h.filter((y) => T.width >= y) : h, [c, k] = I(b);
|
|
53
|
-
O(() => {
|
|
54
|
-
(async () => {
|
|
55
|
-
if (typeof window > "u") {
|
|
56
|
-
k(b);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const U = e.replace(/\.(jpe?g|png|webp)$/i, ""), o = e.match(/\.(jpe?g|png|webp)$/i)?.[0] || ".jpg", a = [];
|
|
60
|
-
for (const w of b) {
|
|
61
|
-
const f = `${U}-${w}w${o}`;
|
|
62
|
-
try {
|
|
63
|
-
(await fetch(f, { method: "HEAD" })).ok && a.push(w);
|
|
64
|
-
} catch {
|
|
87
|
+
if (W)
|
|
88
|
+
return /* @__PURE__ */ B("picture", { "data-routerino-image": "true", "data-original-src": e, children: [
|
|
89
|
+
/* @__PURE__ */ g(
|
|
90
|
+
"source",
|
|
91
|
+
{
|
|
92
|
+
srcSet: q(e, u, "webp"),
|
|
93
|
+
type: "image/webp",
|
|
94
|
+
sizes: a
|
|
65
95
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
96
|
+
),
|
|
97
|
+
/* @__PURE__ */ g(
|
|
98
|
+
"img",
|
|
99
|
+
{
|
|
100
|
+
src: e,
|
|
101
|
+
alt: r,
|
|
102
|
+
srcSet: q(e, u),
|
|
103
|
+
sizes: a,
|
|
104
|
+
loading: k,
|
|
105
|
+
decoding: "async",
|
|
106
|
+
fetchPriority: P,
|
|
107
|
+
className: m,
|
|
108
|
+
style: l,
|
|
109
|
+
...t,
|
|
110
|
+
...T
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
] });
|
|
114
|
+
const w = q(e, U, "webp"), d = q(e, U);
|
|
115
|
+
return /* @__PURE__ */ B("picture", { "data-routerino-image": "true", "data-original-src": e, children: [
|
|
116
|
+
/* @__PURE__ */ g("source", { srcSet: w, type: "image/webp", sizes: a }),
|
|
73
117
|
/* @__PURE__ */ g(
|
|
74
118
|
"img",
|
|
75
119
|
{
|
|
76
120
|
src: e,
|
|
77
|
-
alt:
|
|
78
|
-
srcSet:
|
|
79
|
-
sizes:
|
|
80
|
-
loading:
|
|
81
|
-
decoding:
|
|
82
|
-
fetchPriority:
|
|
83
|
-
className:
|
|
84
|
-
style:
|
|
85
|
-
...
|
|
121
|
+
alt: r,
|
|
122
|
+
srcSet: d,
|
|
123
|
+
sizes: a,
|
|
124
|
+
loading: k,
|
|
125
|
+
decoding: L,
|
|
126
|
+
fetchPriority: P,
|
|
127
|
+
className: m,
|
|
128
|
+
style: l,
|
|
129
|
+
...t,
|
|
130
|
+
...T
|
|
86
131
|
}
|
|
87
132
|
)
|
|
88
133
|
] });
|
|
89
134
|
}
|
|
90
|
-
|
|
135
|
+
oe.propTypes = {
|
|
91
136
|
/** Image source URL (required) */
|
|
92
|
-
src:
|
|
137
|
+
src: o.string.isRequired,
|
|
93
138
|
/** Alt text for accessibility (required) */
|
|
94
|
-
alt:
|
|
139
|
+
alt: o.string.isRequired,
|
|
95
140
|
/** Override lazy loading for hero/LCP images */
|
|
96
|
-
priority:
|
|
141
|
+
priority: o.bool,
|
|
97
142
|
/** Responsive widths to generate (defaults to [480, 800, 1200, 1920]) */
|
|
98
|
-
widths:
|
|
143
|
+
widths: o.arrayOf(o.number),
|
|
99
144
|
/** Responsive sizes attribute (has smart default) */
|
|
100
|
-
sizes:
|
|
145
|
+
sizes: o.string,
|
|
101
146
|
/** CSS classes (Tailwind/DaisyUI ready) */
|
|
102
|
-
className:
|
|
147
|
+
className: o.string,
|
|
103
148
|
/** Inline styles */
|
|
104
|
-
style:
|
|
149
|
+
style: o.object,
|
|
150
|
+
/** Explicit width for CLS prevention */
|
|
151
|
+
width: o.number,
|
|
152
|
+
/** Explicit height for CLS prevention */
|
|
153
|
+
height: o.number,
|
|
105
154
|
/** Loading behavior (auto-set based on priority) */
|
|
106
|
-
loading:
|
|
155
|
+
loading: o.oneOf(["lazy", "eager"]),
|
|
107
156
|
/** Decode timing */
|
|
108
|
-
decoding:
|
|
157
|
+
decoding: o.oneOf(["sync", "async", "auto"]),
|
|
109
158
|
/** Fetch priority (auto-set based on priority) */
|
|
110
|
-
fetchpriority:
|
|
159
|
+
fetchpriority: o.oneOf(["high", "low", "auto"])
|
|
111
160
|
};
|
|
112
|
-
const
|
|
113
|
-
function
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
161
|
+
const K = N(null);
|
|
162
|
+
function le() {
|
|
163
|
+
const i = X(K);
|
|
164
|
+
if (!i)
|
|
116
165
|
throw new Error(
|
|
117
166
|
"useRouterino must be used within a Routerino router. Make sure your component is rendered inside a <Routerino> component."
|
|
118
167
|
);
|
|
119
|
-
return
|
|
168
|
+
return i;
|
|
120
169
|
}
|
|
121
|
-
function
|
|
122
|
-
const n = Object.keys(
|
|
170
|
+
function p({ tag: i = "meta", soft: e = !1, ...r }) {
|
|
171
|
+
const n = Object.keys(r);
|
|
123
172
|
if (n.length < 1)
|
|
124
173
|
return console.error(
|
|
125
|
-
`[Routerino] updateHeadTag() received no attributes to set for ${
|
|
174
|
+
`[Routerino] updateHeadTag() received no attributes to set for ${i} tag`
|
|
126
175
|
);
|
|
127
|
-
let
|
|
128
|
-
for (let
|
|
129
|
-
`${
|
|
130
|
-
)), !
|
|
176
|
+
let u = null;
|
|
177
|
+
for (let a = 0; a < n.length && (n[a] !== "content" && (u = document.querySelector(
|
|
178
|
+
`${i}[${n[a]}='${r[n[a]]}']`
|
|
179
|
+
)), !u); a++)
|
|
131
180
|
;
|
|
132
|
-
|
|
181
|
+
u && e || (u || (u = document.createElement(i)), n.forEach((a) => u.setAttribute(a, r[a])), document.querySelector("head").appendChild(u));
|
|
133
182
|
}
|
|
134
|
-
function
|
|
135
|
-
let
|
|
136
|
-
return n.forEach((
|
|
137
|
-
|
|
138
|
-
}),
|
|
183
|
+
function ne({ routePattern: i, currentRoute: e }) {
|
|
184
|
+
let r = {}, n = i.split("/"), u = e.split("/");
|
|
185
|
+
return n.forEach((a, m) => {
|
|
186
|
+
a.startsWith(":") && (r[a.slice(1)] = u[m]);
|
|
187
|
+
}), r;
|
|
139
188
|
}
|
|
140
|
-
class
|
|
189
|
+
class Z extends Q {
|
|
141
190
|
constructor(e) {
|
|
142
191
|
super(e), this.state = { hasError: !1 };
|
|
143
192
|
}
|
|
144
193
|
static getDerivedStateFromError() {
|
|
145
194
|
return { hasError: !0 };
|
|
146
195
|
}
|
|
147
|
-
componentDidCatch(e,
|
|
196
|
+
componentDidCatch(e, r) {
|
|
148
197
|
this.props.debug && (console.group(
|
|
149
198
|
"%c[Routerino]%c Error Boundary Caught an Error",
|
|
150
199
|
"color: #ff6b6b; font-weight: bold",
|
|
151
200
|
"",
|
|
152
201
|
e
|
|
153
|
-
), console.error("[Routerino] Component Stack:",
|
|
202
|
+
), console.error("[Routerino] Component Stack:", r.componentStack), this.props.routePath && console.error("[Routerino] Failed Route:", this.props.routePath), console.error("[Routerino] Error occurred at:", (/* @__PURE__ */ new Date()).toISOString()), console.groupEnd()), document.title = this.props.errorTitleString, this.props.usePrerenderTags && p({ name: "prerender-status-code", content: "500" });
|
|
154
203
|
}
|
|
155
204
|
render() {
|
|
156
205
|
return this.state.hasError ? this.props.fallback : this.props.children;
|
|
157
206
|
}
|
|
158
207
|
}
|
|
159
|
-
|
|
208
|
+
Z.propTypes = {
|
|
160
209
|
/** The child components to render when there's no error */
|
|
161
|
-
children:
|
|
210
|
+
children: o.node,
|
|
162
211
|
/** The fallback UI to display when an error is caught */
|
|
163
|
-
fallback:
|
|
212
|
+
fallback: o.node,
|
|
164
213
|
/** The document title to set when an error occurs */
|
|
165
|
-
errorTitleString:
|
|
214
|
+
errorTitleString: o.string.isRequired,
|
|
166
215
|
/** Whether to set prerender meta tags (status code 500) on error */
|
|
167
|
-
usePrerenderTags:
|
|
216
|
+
usePrerenderTags: o.bool,
|
|
168
217
|
/** The current route path for better error context (optional) */
|
|
169
|
-
routePath:
|
|
218
|
+
routePath: o.string,
|
|
170
219
|
/** Whether to log debug messages to console (optional) */
|
|
171
|
-
debug:
|
|
220
|
+
debug: o.bool
|
|
172
221
|
};
|
|
173
|
-
function
|
|
174
|
-
routes:
|
|
222
|
+
function re({
|
|
223
|
+
routes: i = [
|
|
175
224
|
{
|
|
176
225
|
path: "/",
|
|
177
226
|
element: /* @__PURE__ */ g("p", { children: "This is the default route. Pass an array of routes to the Routerino component in order to configure your own pages. Each route is a dictionary with at least `path` and `element` defined." }),
|
|
@@ -180,148 +229,157 @@ function Q({
|
|
|
180
229
|
tags: [{ property: "og:locale", content: "en_US" }]
|
|
181
230
|
}
|
|
182
231
|
],
|
|
183
|
-
notFoundTemplate: e = /* @__PURE__ */
|
|
232
|
+
notFoundTemplate: e = /* @__PURE__ */ B(G, { children: [
|
|
184
233
|
/* @__PURE__ */ g("p", { children: "No page found for this URL. [404]" }),
|
|
185
234
|
/* @__PURE__ */ g("p", { children: /* @__PURE__ */ g("a", { href: "/", children: "Home" }) })
|
|
186
235
|
] }),
|
|
187
|
-
notFoundTitle:
|
|
188
|
-
errorTemplate: n = /* @__PURE__ */
|
|
236
|
+
notFoundTitle: r = "Page not found [404]",
|
|
237
|
+
errorTemplate: n = /* @__PURE__ */ B(G, { children: [
|
|
189
238
|
/* @__PURE__ */ g("p", { children: "Page failed to load. [500]" }),
|
|
190
239
|
/* @__PURE__ */ g("p", { children: /* @__PURE__ */ g("a", { href: "/", children: "Home" }) })
|
|
191
240
|
] }),
|
|
192
|
-
errorTitle:
|
|
193
|
-
useTrailingSlash:
|
|
194
|
-
usePrerenderTags:
|
|
195
|
-
baseUrl:
|
|
196
|
-
title:
|
|
197
|
-
separator:
|
|
198
|
-
imageUrl:
|
|
199
|
-
touchIconUrl:
|
|
200
|
-
debug:
|
|
241
|
+
errorTitle: u = "Page error [500]",
|
|
242
|
+
useTrailingSlash: a = !0,
|
|
243
|
+
usePrerenderTags: m = !1,
|
|
244
|
+
baseUrl: O = null,
|
|
245
|
+
title: E = "",
|
|
246
|
+
separator: S = " | ",
|
|
247
|
+
imageUrl: I = null,
|
|
248
|
+
touchIconUrl: L = null,
|
|
249
|
+
debug: f = !1
|
|
201
250
|
}) {
|
|
202
|
-
const T = `${
|
|
251
|
+
const T = `${u}${S}${E}`, W = `${r}${S}${E}`;
|
|
203
252
|
try {
|
|
204
|
-
if (
|
|
205
|
-
const
|
|
206
|
-
(w,
|
|
253
|
+
if (f) {
|
|
254
|
+
const t = i.map((w) => w.path), l = t.filter(
|
|
255
|
+
(w, d) => t.indexOf(w) !== d
|
|
207
256
|
);
|
|
208
|
-
|
|
257
|
+
l.length > 0 && (console.warn(
|
|
209
258
|
"%c[Routerino]%c Duplicate route paths detected:",
|
|
210
259
|
"color: #f59e0b; font-weight: bold",
|
|
211
260
|
"",
|
|
212
|
-
[...new Set(
|
|
261
|
+
[...new Set(l)]
|
|
213
262
|
), console.warn(
|
|
214
263
|
"%c[Routerino]%c The first matching route will be used",
|
|
215
264
|
"color: #f59e0b; font-weight: bold",
|
|
216
265
|
""
|
|
217
266
|
));
|
|
218
267
|
}
|
|
219
|
-
const [
|
|
220
|
-
|
|
268
|
+
const [b, R] = z(window?.location?.href ?? "/");
|
|
269
|
+
_(() => {
|
|
221
270
|
if (typeof window > "u" || typeof document > "u")
|
|
222
271
|
return;
|
|
223
|
-
const
|
|
224
|
-
|
|
272
|
+
const t = (w) => {
|
|
273
|
+
f && console.debug(
|
|
225
274
|
"%c[Routerino]%c click occurred",
|
|
226
275
|
"color: #6b7280; font-weight: bold",
|
|
227
276
|
""
|
|
228
277
|
);
|
|
229
|
-
let
|
|
230
|
-
for (;
|
|
231
|
-
|
|
232
|
-
if (
|
|
233
|
-
|
|
278
|
+
let d = w.target;
|
|
279
|
+
for (; d.tagName !== "A" && d.parentElement; )
|
|
280
|
+
d = d.parentElement;
|
|
281
|
+
if (d.tagName !== "A") {
|
|
282
|
+
f && console.debug(
|
|
234
283
|
"%c[Routerino]%c no anchor tag found during click",
|
|
235
284
|
"color: #6b7280; font-weight: bold",
|
|
236
285
|
""
|
|
237
286
|
);
|
|
238
287
|
return;
|
|
239
288
|
}
|
|
240
|
-
const
|
|
241
|
-
if (!
|
|
242
|
-
|
|
289
|
+
const h = d.getAttribute("href") || d.href;
|
|
290
|
+
if (!h) {
|
|
291
|
+
f && console.debug(
|
|
243
292
|
"%c[Routerino]%c anchor tag has no href",
|
|
244
293
|
"color: #6b7280; font-weight: bold",
|
|
245
294
|
""
|
|
246
295
|
);
|
|
247
296
|
return;
|
|
248
297
|
}
|
|
249
|
-
if (!/^(https?:\/\/|\/|\.\/|\.\.\/|[^:]+$)/i.test(
|
|
250
|
-
|
|
298
|
+
if (!/^(https?:\/\/|\/|\.\/|\.\.\/|[^:]+$)/i.test(h)) {
|
|
299
|
+
f && console.debug(
|
|
251
300
|
"%c[Routerino]%c skipping non-http URL:",
|
|
252
301
|
"color: #6b7280; font-weight: bold",
|
|
253
302
|
"",
|
|
254
|
-
|
|
303
|
+
h
|
|
255
304
|
);
|
|
256
305
|
return;
|
|
257
306
|
}
|
|
258
|
-
|
|
307
|
+
f && console.debug(
|
|
259
308
|
"%c[Routerino]%c click target href:",
|
|
260
309
|
"color: #6b7280; font-weight: bold",
|
|
261
310
|
"",
|
|
262
|
-
|
|
311
|
+
h
|
|
263
312
|
);
|
|
264
|
-
let
|
|
313
|
+
let $;
|
|
265
314
|
try {
|
|
266
|
-
|
|
267
|
-
} catch (
|
|
268
|
-
|
|
315
|
+
$ = new URL(h, window.location.href);
|
|
316
|
+
} catch (x) {
|
|
317
|
+
f && console.debug(
|
|
269
318
|
"%c[Routerino]%c Invalid URL:",
|
|
270
319
|
"color: #6b7280; font-weight: bold",
|
|
271
320
|
"",
|
|
272
|
-
|
|
273
|
-
|
|
321
|
+
h,
|
|
322
|
+
x
|
|
274
323
|
);
|
|
275
324
|
return;
|
|
276
325
|
}
|
|
277
|
-
|
|
326
|
+
if (f && console.debug(
|
|
278
327
|
"%c[Routerino]%c targetUrl:",
|
|
279
328
|
"color: #6b7280; font-weight: bold",
|
|
280
329
|
"",
|
|
281
|
-
|
|
330
|
+
$,
|
|
282
331
|
"current:",
|
|
283
332
|
window.location
|
|
284
|
-
),
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
333
|
+
), $ && window.location.origin === $.origin)
|
|
334
|
+
if (f && console.debug(
|
|
335
|
+
"%c[Routerino]%c target link is same origin, will use push-state transitioning",
|
|
336
|
+
"color: #6b7280; font-weight: bold",
|
|
337
|
+
""
|
|
338
|
+
), w.preventDefault(), d.href !== window.location.href && (R(d.href), window.history.pushState({}, "", d.href)), d.hash) {
|
|
339
|
+
const x = decodeURIComponent(d.hash.slice(1));
|
|
340
|
+
setTimeout(() => {
|
|
341
|
+
const A = document.getElementById(x);
|
|
342
|
+
A ? A.scrollIntoView({ behavior: "auto" }) : window.scrollTo({ top: 0, behavior: "auto" });
|
|
343
|
+
}, 0);
|
|
344
|
+
} else
|
|
345
|
+
window.scrollTo({
|
|
346
|
+
top: 0,
|
|
347
|
+
behavior: "auto"
|
|
348
|
+
});
|
|
349
|
+
else f && console.debug(
|
|
292
350
|
"%c[Routerino]%c target link does not share an origin, standard browser link handling applies",
|
|
293
351
|
"color: #6b7280; font-weight: bold",
|
|
294
352
|
""
|
|
295
353
|
);
|
|
296
354
|
};
|
|
297
|
-
document.addEventListener("click",
|
|
298
|
-
const
|
|
299
|
-
|
|
355
|
+
document.addEventListener("click", t);
|
|
356
|
+
const l = () => {
|
|
357
|
+
f && console.debug(
|
|
300
358
|
"%c[Routerino]%c route change ->",
|
|
301
359
|
"color: #6b7280; font-weight: bold",
|
|
302
360
|
"",
|
|
303
361
|
window.location.pathname
|
|
304
|
-
),
|
|
362
|
+
), R(window.location.href);
|
|
305
363
|
};
|
|
306
|
-
return window.addEventListener("popstate",
|
|
307
|
-
document.removeEventListener("click",
|
|
364
|
+
return window.addEventListener("popstate", l), () => {
|
|
365
|
+
document.removeEventListener("click", t), window.removeEventListener("popstate", l);
|
|
308
366
|
};
|
|
309
|
-
}, [
|
|
367
|
+
}, [b]);
|
|
310
368
|
let c = window?.location?.pathname ?? "/";
|
|
311
369
|
(c === "/index.html" || c === "") && (c = "/");
|
|
312
|
-
const k =
|
|
313
|
-
(
|
|
314
|
-
),
|
|
315
|
-
const
|
|
316
|
-
return
|
|
317
|
-
}), s = k ?? P ??
|
|
318
|
-
if (
|
|
370
|
+
const k = i.find((t) => t.path === c), P = i.find(
|
|
371
|
+
(t) => `${t.path}/` === c || t.path === `${c}/`
|
|
372
|
+
), y = i.find((t) => {
|
|
373
|
+
const l = t.path.endsWith("/") ? t.path.slice(0, -1) : t.path, w = c.endsWith("/") ? c.slice(0, -1) : c, d = l.split("/").filter(Boolean), h = w.split("/").filter(Boolean);
|
|
374
|
+
return d.length !== h.length ? !1 : d.every(($, x) => $.startsWith(":") ? !0 : $ === h[x]);
|
|
375
|
+
}), s = k ?? P ?? y;
|
|
376
|
+
if (f && console.debug(
|
|
319
377
|
"%c[Routerino]%c Route matching:",
|
|
320
378
|
"color: #6b7280; font-weight: bold",
|
|
321
379
|
"",
|
|
322
|
-
{ match: s, exactMatch: k, addSlashMatch: P, paramsMatch:
|
|
380
|
+
{ match: s, exactMatch: k, addSlashMatch: P, paramsMatch: y }
|
|
323
381
|
), !s)
|
|
324
|
-
return
|
|
382
|
+
return f && (console.group(
|
|
325
383
|
"%c[Routerino]%c 404 - No matching route",
|
|
326
384
|
"color: #f59e0b; font-weight: bold",
|
|
327
385
|
""
|
|
@@ -334,79 +392,79 @@ function Q({
|
|
|
334
392
|
"%c[Routerino]%c Available routes:",
|
|
335
393
|
"color: #f59e0b; font-weight: bold",
|
|
336
394
|
"",
|
|
337
|
-
|
|
338
|
-
), console.groupEnd()), document.title =
|
|
339
|
-
if (
|
|
340
|
-
const
|
|
395
|
+
i.map((t) => t.path)
|
|
396
|
+
), console.groupEnd()), document.title = W, m && p({ name: "prerender-status-code", content: "404" }), e;
|
|
397
|
+
if (m) {
|
|
398
|
+
const t = document.querySelector(
|
|
341
399
|
'meta[name="prerender-status-code"]'
|
|
342
400
|
);
|
|
343
|
-
|
|
344
|
-
const
|
|
401
|
+
t && t.remove();
|
|
402
|
+
const l = document.querySelector(
|
|
345
403
|
'meta[name="prerender-header"]'
|
|
346
404
|
);
|
|
347
|
-
|
|
405
|
+
l && l.remove();
|
|
348
406
|
}
|
|
349
|
-
const
|
|
407
|
+
const v = a && !c.endsWith("/") && c !== "/", j = !a && c.endsWith("/") && c !== "/", F = v ? `${c}/` : j ? c.slice(0, -1) : c, U = `${O ?? window?.location?.origin ?? ""}${F}`;
|
|
350
408
|
if (s.title) {
|
|
351
|
-
const
|
|
352
|
-
document.title =
|
|
409
|
+
const t = `${s.title}${S}${E}`;
|
|
410
|
+
document.title = t, p({
|
|
353
411
|
tag: "link",
|
|
354
412
|
rel: "canonical",
|
|
355
413
|
href: U
|
|
356
|
-
}), s.tags?.find(({ property:
|
|
414
|
+
}), s.tags?.find(({ property: l }) => l === "og:title") || p({
|
|
357
415
|
property: "og:title",
|
|
358
|
-
content:
|
|
359
|
-
}), s.tags?.find(({ property:
|
|
416
|
+
content: t
|
|
417
|
+
}), s.tags?.find(({ property: l }) => l === "og:url") || p({
|
|
360
418
|
property: "og:url",
|
|
361
419
|
content: U
|
|
362
420
|
});
|
|
363
421
|
}
|
|
364
|
-
if (s.description && (
|
|
422
|
+
if (s.description && (p({ name: "description", content: s.description }), s.tags?.find(({ property: t }) => t === "og:description") || p({
|
|
365
423
|
property: "og:description",
|
|
366
424
|
content: s.description
|
|
367
|
-
})), (
|
|
425
|
+
})), (I || s.imageUrl) && p({
|
|
368
426
|
property: "og:image",
|
|
369
|
-
content: s.imageUrl ??
|
|
370
|
-
}), s.tags?.find(({ property:
|
|
427
|
+
content: s.imageUrl ?? I
|
|
428
|
+
}), s.tags?.find(({ property: t }) => t === "twitter:card") || p({
|
|
371
429
|
name: "twitter:card",
|
|
372
430
|
content: "summary_large_image"
|
|
373
|
-
}),
|
|
431
|
+
}), L && p({
|
|
374
432
|
tag: "link",
|
|
375
433
|
rel: "apple-touch-icon",
|
|
376
|
-
href:
|
|
377
|
-
}),
|
|
434
|
+
href: L
|
|
435
|
+
}), m && (v || j) && (p({ name: "prerender-status-code", content: "301" }), p({
|
|
378
436
|
name: "prerender-header",
|
|
379
437
|
content: `Location: ${U}`
|
|
380
|
-
})), s.tags && s.tags.length ? (s.tags.find(({ property:
|
|
381
|
-
const
|
|
438
|
+
})), s.tags && s.tags.length ? (s.tags.find(({ property: t }) => t === "og:type") || p({ property: "og:type", content: "website" }), s.tags.forEach((t) => p(t))) : p({ property: "og:type", content: "website" }), s.element) {
|
|
439
|
+
const t = ne({
|
|
382
440
|
routePattern: s.path,
|
|
383
441
|
currentRoute: c
|
|
384
|
-
}),
|
|
442
|
+
}), l = {
|
|
385
443
|
currentRoute: c,
|
|
386
|
-
params:
|
|
444
|
+
params: t,
|
|
387
445
|
routePattern: s.path,
|
|
388
|
-
updateHeadTag:
|
|
446
|
+
updateHeadTag: p
|
|
389
447
|
};
|
|
390
|
-
return /* @__PURE__ */ g(
|
|
391
|
-
|
|
448
|
+
return /* @__PURE__ */ g(K.Provider, { value: l, children: /* @__PURE__ */ g(
|
|
449
|
+
Z,
|
|
392
450
|
{
|
|
393
451
|
fallback: n,
|
|
394
452
|
errorTitleString: T,
|
|
395
|
-
usePrerenderTags:
|
|
453
|
+
usePrerenderTags: m,
|
|
396
454
|
routePath: c,
|
|
397
|
-
debug:
|
|
455
|
+
debug: f,
|
|
398
456
|
children: s.element
|
|
399
457
|
}
|
|
400
458
|
) });
|
|
401
459
|
}
|
|
402
|
-
return
|
|
460
|
+
return f && console.error(
|
|
403
461
|
"%c[Routerino]%c No route found for",
|
|
404
462
|
"color: #ff6b6b; font-weight: bold",
|
|
405
463
|
"",
|
|
406
464
|
c
|
|
407
|
-
), document.title =
|
|
408
|
-
} catch (
|
|
409
|
-
return
|
|
465
|
+
), document.title = W, m && p({ name: "prerender-status-code", content: "404" }), e;
|
|
466
|
+
} catch (b) {
|
|
467
|
+
return f && (console.group(
|
|
410
468
|
"%c[Routerino]%c Fatal Error",
|
|
411
469
|
"color: #ff6b6b; font-weight: bold",
|
|
412
470
|
""
|
|
@@ -418,64 +476,64 @@ function Q({
|
|
|
418
476
|
"%c[Routerino]%c Error:",
|
|
419
477
|
"color: #ff6b6b; font-weight: bold",
|
|
420
478
|
"",
|
|
421
|
-
|
|
479
|
+
b
|
|
422
480
|
), console.error(
|
|
423
481
|
"%c[Routerino]%c This typically means an issue with route configuration or router setup",
|
|
424
482
|
"color: #ff6b6b; font-weight: bold",
|
|
425
483
|
""
|
|
426
|
-
), console.groupEnd()),
|
|
484
|
+
), console.groupEnd()), m && p({ name: "prerender-status-code", content: "500" }), document.title = T, n;
|
|
427
485
|
}
|
|
428
486
|
}
|
|
429
|
-
const
|
|
430
|
-
path: (
|
|
431
|
-
const n =
|
|
487
|
+
const ie = o.exact({
|
|
488
|
+
path: (i, e, r) => {
|
|
489
|
+
const n = i[e];
|
|
432
490
|
return n == null ? new Error(
|
|
433
|
-
`The prop \`${e}\` is marked as required in \`${
|
|
491
|
+
`The prop \`${e}\` is marked as required in \`${r}\`, but its value is \`${n}\`.`
|
|
434
492
|
) : typeof n != "string" ? new Error(
|
|
435
|
-
`Invalid prop \`${e}\` of type \`${typeof n}\` supplied to \`${
|
|
493
|
+
`Invalid prop \`${e}\` of type \`${typeof n}\` supplied to \`${r}\`, expected \`string\`.`
|
|
436
494
|
) : n.startsWith("/") ? null : new Error(
|
|
437
|
-
`Invalid prop \`${e}\` value \`${n}\` supplied to \`${
|
|
495
|
+
`Invalid prop \`${e}\` value \`${n}\` supplied to \`${r}\`. Route paths must start with a forward slash (/).`
|
|
438
496
|
);
|
|
439
497
|
},
|
|
440
|
-
element:
|
|
441
|
-
title:
|
|
442
|
-
description:
|
|
443
|
-
tags:
|
|
444
|
-
imageUrl:
|
|
498
|
+
element: o.element.isRequired,
|
|
499
|
+
title: o.string,
|
|
500
|
+
description: o.string,
|
|
501
|
+
tags: o.arrayOf(o.object),
|
|
502
|
+
imageUrl: o.string
|
|
445
503
|
});
|
|
446
|
-
|
|
447
|
-
routes:
|
|
448
|
-
title:
|
|
449
|
-
separator:
|
|
450
|
-
notFoundTemplate:
|
|
451
|
-
notFoundTitle:
|
|
452
|
-
errorTemplate:
|
|
453
|
-
errorTitle:
|
|
454
|
-
useTrailingSlash:
|
|
455
|
-
usePrerenderTags:
|
|
456
|
-
baseUrl: (
|
|
457
|
-
const n =
|
|
504
|
+
re.propTypes = {
|
|
505
|
+
routes: o.arrayOf(ie),
|
|
506
|
+
title: o.string,
|
|
507
|
+
separator: o.string,
|
|
508
|
+
notFoundTemplate: o.element,
|
|
509
|
+
notFoundTitle: o.string,
|
|
510
|
+
errorTemplate: o.element,
|
|
511
|
+
errorTitle: o.string,
|
|
512
|
+
useTrailingSlash: o.bool,
|
|
513
|
+
usePrerenderTags: o.bool,
|
|
514
|
+
baseUrl: (i, e, r) => {
|
|
515
|
+
const n = i[e];
|
|
458
516
|
if (n != null) {
|
|
459
517
|
if (typeof n != "string")
|
|
460
518
|
return new Error(
|
|
461
|
-
`Invalid prop \`${e}\` of type \`${typeof n}\` supplied to \`${
|
|
519
|
+
`Invalid prop \`${e}\` of type \`${typeof n}\` supplied to \`${r}\`, expected \`string\`.`
|
|
462
520
|
);
|
|
463
521
|
if (n.endsWith("/"))
|
|
464
522
|
return new Error(
|
|
465
|
-
`Invalid prop \`${e}\` supplied to \`${
|
|
523
|
+
`Invalid prop \`${e}\` supplied to \`${r}\`. The baseUrl should not end with a slash. Got: "${n}"`
|
|
466
524
|
);
|
|
467
525
|
}
|
|
468
526
|
return null;
|
|
469
527
|
},
|
|
470
|
-
imageUrl:
|
|
471
|
-
touchIconUrl:
|
|
472
|
-
debug:
|
|
528
|
+
imageUrl: o.string,
|
|
529
|
+
touchIconUrl: o.string,
|
|
530
|
+
debug: o.bool
|
|
473
531
|
};
|
|
474
532
|
export {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
533
|
+
Z as ErrorBoundary,
|
|
534
|
+
oe as Image,
|
|
535
|
+
re as Routerino,
|
|
536
|
+
re as default,
|
|
537
|
+
p as updateHeadTag,
|
|
538
|
+
le as useRouterino
|
|
481
539
|
};
|