@aminnairi/react-router 3.0.0 → 3.0.2
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 +127 -60
- package/dist/index.d.ts +63 -0
- package/dist/index.js +689 -0
- package/package.json +10 -4
- package/index.tsx +0 -527
package/dist/index.js
ADDED
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region ../../node_modules/react/cjs/react.production.min.js
|
|
5
|
+
/**
|
|
6
|
+
* @license React
|
|
7
|
+
* react.production.min.js
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the MIT license found in the
|
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
|
13
|
+
*/
|
|
14
|
+
var require_react_production_min = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
15
|
+
var l = Symbol.for("react.element"), n = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Symbol.for("react.strict_mode"), r = Symbol.for("react.profiler"), t = Symbol.for("react.provider"), u = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), x = Symbol.for("react.memo"), y = Symbol.for("react.lazy"), z = Symbol.iterator;
|
|
16
|
+
function A(a) {
|
|
17
|
+
if (null === a || "object" !== typeof a) return null;
|
|
18
|
+
a = z && a[z] || a["@@iterator"];
|
|
19
|
+
return "function" === typeof a ? a : null;
|
|
20
|
+
}
|
|
21
|
+
var B = {
|
|
22
|
+
isMounted: function() {
|
|
23
|
+
return !1;
|
|
24
|
+
},
|
|
25
|
+
enqueueForceUpdate: function() {},
|
|
26
|
+
enqueueReplaceState: function() {},
|
|
27
|
+
enqueueSetState: function() {}
|
|
28
|
+
}, C = Object.assign, D = {};
|
|
29
|
+
function E(a, b, e) {
|
|
30
|
+
this.props = a;
|
|
31
|
+
this.context = b;
|
|
32
|
+
this.refs = D;
|
|
33
|
+
this.updater = e || B;
|
|
34
|
+
}
|
|
35
|
+
E.prototype.isReactComponent = {};
|
|
36
|
+
E.prototype.setState = function(a, b) {
|
|
37
|
+
if ("object" !== typeof a && "function" !== typeof a && null != a) throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");
|
|
38
|
+
this.updater.enqueueSetState(this, a, b, "setState");
|
|
39
|
+
};
|
|
40
|
+
E.prototype.forceUpdate = function(a) {
|
|
41
|
+
this.updater.enqueueForceUpdate(this, a, "forceUpdate");
|
|
42
|
+
};
|
|
43
|
+
function F() {}
|
|
44
|
+
F.prototype = E.prototype;
|
|
45
|
+
function G(a, b, e) {
|
|
46
|
+
this.props = a;
|
|
47
|
+
this.context = b;
|
|
48
|
+
this.refs = D;
|
|
49
|
+
this.updater = e || B;
|
|
50
|
+
}
|
|
51
|
+
var H = G.prototype = new F();
|
|
52
|
+
H.constructor = G;
|
|
53
|
+
C(H, E.prototype);
|
|
54
|
+
H.isPureReactComponent = !0;
|
|
55
|
+
var I = Array.isArray, J = Object.prototype.hasOwnProperty, K = { current: null }, L = {
|
|
56
|
+
key: !0,
|
|
57
|
+
ref: !0,
|
|
58
|
+
__self: !0,
|
|
59
|
+
__source: !0
|
|
60
|
+
};
|
|
61
|
+
function M(a, b, e) {
|
|
62
|
+
var d, c = {}, k = null, h = null;
|
|
63
|
+
if (null != b) for (d in void 0 !== b.ref && (h = b.ref), void 0 !== b.key && (k = "" + b.key), b) J.call(b, d) && !L.hasOwnProperty(d) && (c[d] = b[d]);
|
|
64
|
+
var g = arguments.length - 2;
|
|
65
|
+
if (1 === g) c.children = e;
|
|
66
|
+
else if (1 < g) {
|
|
67
|
+
for (var f = Array(g), m = 0; m < g; m++) f[m] = arguments[m + 2];
|
|
68
|
+
c.children = f;
|
|
69
|
+
}
|
|
70
|
+
if (a && a.defaultProps) for (d in g = a.defaultProps, g) void 0 === c[d] && (c[d] = g[d]);
|
|
71
|
+
return {
|
|
72
|
+
$$typeof: l,
|
|
73
|
+
type: a,
|
|
74
|
+
key: k,
|
|
75
|
+
ref: h,
|
|
76
|
+
props: c,
|
|
77
|
+
_owner: K.current
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function N(a, b) {
|
|
81
|
+
return {
|
|
82
|
+
$$typeof: l,
|
|
83
|
+
type: a.type,
|
|
84
|
+
key: b,
|
|
85
|
+
ref: a.ref,
|
|
86
|
+
props: a.props,
|
|
87
|
+
_owner: a._owner
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function O(a) {
|
|
91
|
+
return "object" === typeof a && null !== a && a.$$typeof === l;
|
|
92
|
+
}
|
|
93
|
+
function escape(a) {
|
|
94
|
+
var b = {
|
|
95
|
+
"=": "=0",
|
|
96
|
+
":": "=2"
|
|
97
|
+
};
|
|
98
|
+
return "$" + a.replace(/[=:]/g, function(a) {
|
|
99
|
+
return b[a];
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
var P = /\/+/g;
|
|
103
|
+
function Q(a, b) {
|
|
104
|
+
return "object" === typeof a && null !== a && null != a.key ? escape("" + a.key) : b.toString(36);
|
|
105
|
+
}
|
|
106
|
+
function R(a, b, e, d, c) {
|
|
107
|
+
var k = typeof a;
|
|
108
|
+
if ("undefined" === k || "boolean" === k) a = null;
|
|
109
|
+
var h = !1;
|
|
110
|
+
if (null === a) h = !0;
|
|
111
|
+
else switch (k) {
|
|
112
|
+
case "string":
|
|
113
|
+
case "number":
|
|
114
|
+
h = !0;
|
|
115
|
+
break;
|
|
116
|
+
case "object": switch (a.$$typeof) {
|
|
117
|
+
case l:
|
|
118
|
+
case n: h = !0;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (h) return h = a, c = c(h), a = "" === d ? "." + Q(h, 0) : d, I(c) ? (e = "", null != a && (e = a.replace(P, "$&/") + "/"), R(c, b, e, "", function(a) {
|
|
122
|
+
return a;
|
|
123
|
+
})) : null != c && (O(c) && (c = N(c, e + (!c.key || h && h.key === c.key ? "" : ("" + c.key).replace(P, "$&/") + "/") + a)), b.push(c)), 1;
|
|
124
|
+
h = 0;
|
|
125
|
+
d = "" === d ? "." : d + ":";
|
|
126
|
+
if (I(a)) for (var g = 0; g < a.length; g++) {
|
|
127
|
+
k = a[g];
|
|
128
|
+
var f = d + Q(k, g);
|
|
129
|
+
h += R(k, b, e, f, c);
|
|
130
|
+
}
|
|
131
|
+
else if (f = A(a), "function" === typeof f) for (a = f.call(a), g = 0; !(k = a.next()).done;) k = k.value, f = d + Q(k, g++), h += R(k, b, e, f, c);
|
|
132
|
+
else if ("object" === k) throw b = String(a), Error("Objects are not valid as a React child (found: " + ("[object Object]" === b ? "object with keys {" + Object.keys(a).join(", ") + "}" : b) + "). If you meant to render a collection of children, use an array instead.");
|
|
133
|
+
return h;
|
|
134
|
+
}
|
|
135
|
+
function S(a, b, e) {
|
|
136
|
+
if (null == a) return a;
|
|
137
|
+
var d = [], c = 0;
|
|
138
|
+
R(a, d, "", "", function(a) {
|
|
139
|
+
return b.call(e, a, c++);
|
|
140
|
+
});
|
|
141
|
+
return d;
|
|
142
|
+
}
|
|
143
|
+
function T(a) {
|
|
144
|
+
if (-1 === a._status) {
|
|
145
|
+
var b = a._result;
|
|
146
|
+
b = b();
|
|
147
|
+
b.then(function(b) {
|
|
148
|
+
if (0 === a._status || -1 === a._status) a._status = 1, a._result = b;
|
|
149
|
+
}, function(b) {
|
|
150
|
+
if (0 === a._status || -1 === a._status) a._status = 2, a._result = b;
|
|
151
|
+
});
|
|
152
|
+
-1 === a._status && (a._status = 0, a._result = b);
|
|
153
|
+
}
|
|
154
|
+
if (1 === a._status) return a._result.default;
|
|
155
|
+
throw a._result;
|
|
156
|
+
}
|
|
157
|
+
var U = { current: null }, V = { transition: null }, W = {
|
|
158
|
+
ReactCurrentDispatcher: U,
|
|
159
|
+
ReactCurrentBatchConfig: V,
|
|
160
|
+
ReactCurrentOwner: K
|
|
161
|
+
};
|
|
162
|
+
function X() {
|
|
163
|
+
throw Error("act(...) is not supported in production builds of React.");
|
|
164
|
+
}
|
|
165
|
+
exports.Children = {
|
|
166
|
+
map: S,
|
|
167
|
+
forEach: function(a, b, e) {
|
|
168
|
+
S(a, function() {
|
|
169
|
+
b.apply(this, arguments);
|
|
170
|
+
}, e);
|
|
171
|
+
},
|
|
172
|
+
count: function(a) {
|
|
173
|
+
var b = 0;
|
|
174
|
+
S(a, function() {
|
|
175
|
+
b++;
|
|
176
|
+
});
|
|
177
|
+
return b;
|
|
178
|
+
},
|
|
179
|
+
toArray: function(a) {
|
|
180
|
+
return S(a, function(a) {
|
|
181
|
+
return a;
|
|
182
|
+
}) || [];
|
|
183
|
+
},
|
|
184
|
+
only: function(a) {
|
|
185
|
+
if (!O(a)) throw Error("React.Children.only expected to receive a single React element child.");
|
|
186
|
+
return a;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
exports.Component = E;
|
|
190
|
+
exports.Fragment = p;
|
|
191
|
+
exports.Profiler = r;
|
|
192
|
+
exports.PureComponent = G;
|
|
193
|
+
exports.StrictMode = q;
|
|
194
|
+
exports.Suspense = w;
|
|
195
|
+
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = W;
|
|
196
|
+
exports.act = X;
|
|
197
|
+
exports.cloneElement = function(a, b, e) {
|
|
198
|
+
if (null === a || void 0 === a) throw Error("React.cloneElement(...): The argument must be a React element, but you passed " + a + ".");
|
|
199
|
+
var d = C({}, a.props), c = a.key, k = a.ref, h = a._owner;
|
|
200
|
+
if (null != b) {
|
|
201
|
+
void 0 !== b.ref && (k = b.ref, h = K.current);
|
|
202
|
+
void 0 !== b.key && (c = "" + b.key);
|
|
203
|
+
if (a.type && a.type.defaultProps) var g = a.type.defaultProps;
|
|
204
|
+
for (f in b) J.call(b, f) && !L.hasOwnProperty(f) && (d[f] = void 0 === b[f] && void 0 !== g ? g[f] : b[f]);
|
|
205
|
+
}
|
|
206
|
+
var f = arguments.length - 2;
|
|
207
|
+
if (1 === f) d.children = e;
|
|
208
|
+
else if (1 < f) {
|
|
209
|
+
g = Array(f);
|
|
210
|
+
for (var m = 0; m < f; m++) g[m] = arguments[m + 2];
|
|
211
|
+
d.children = g;
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
$$typeof: l,
|
|
215
|
+
type: a.type,
|
|
216
|
+
key: c,
|
|
217
|
+
ref: k,
|
|
218
|
+
props: d,
|
|
219
|
+
_owner: h
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
exports.createContext = function(a) {
|
|
223
|
+
a = {
|
|
224
|
+
$$typeof: u,
|
|
225
|
+
_currentValue: a,
|
|
226
|
+
_currentValue2: a,
|
|
227
|
+
_threadCount: 0,
|
|
228
|
+
Provider: null,
|
|
229
|
+
Consumer: null,
|
|
230
|
+
_defaultValue: null,
|
|
231
|
+
_globalName: null
|
|
232
|
+
};
|
|
233
|
+
a.Provider = {
|
|
234
|
+
$$typeof: t,
|
|
235
|
+
_context: a
|
|
236
|
+
};
|
|
237
|
+
return a.Consumer = a;
|
|
238
|
+
};
|
|
239
|
+
exports.createElement = M;
|
|
240
|
+
exports.createFactory = function(a) {
|
|
241
|
+
var b = M.bind(null, a);
|
|
242
|
+
b.type = a;
|
|
243
|
+
return b;
|
|
244
|
+
};
|
|
245
|
+
exports.createRef = function() {
|
|
246
|
+
return { current: null };
|
|
247
|
+
};
|
|
248
|
+
exports.forwardRef = function(a) {
|
|
249
|
+
return {
|
|
250
|
+
$$typeof: v,
|
|
251
|
+
render: a
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
exports.isValidElement = O;
|
|
255
|
+
exports.lazy = function(a) {
|
|
256
|
+
return {
|
|
257
|
+
$$typeof: y,
|
|
258
|
+
_payload: {
|
|
259
|
+
_status: -1,
|
|
260
|
+
_result: a
|
|
261
|
+
},
|
|
262
|
+
_init: T
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
exports.memo = function(a, b) {
|
|
266
|
+
return {
|
|
267
|
+
$$typeof: x,
|
|
268
|
+
type: a,
|
|
269
|
+
compare: void 0 === b ? null : b
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
exports.startTransition = function(a) {
|
|
273
|
+
var b = V.transition;
|
|
274
|
+
V.transition = {};
|
|
275
|
+
try {
|
|
276
|
+
a();
|
|
277
|
+
} finally {
|
|
278
|
+
V.transition = b;
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
exports.unstable_act = X;
|
|
282
|
+
exports.useCallback = function(a, b) {
|
|
283
|
+
return U.current.useCallback(a, b);
|
|
284
|
+
};
|
|
285
|
+
exports.useContext = function(a) {
|
|
286
|
+
return U.current.useContext(a);
|
|
287
|
+
};
|
|
288
|
+
exports.useDebugValue = function() {};
|
|
289
|
+
exports.useDeferredValue = function(a) {
|
|
290
|
+
return U.current.useDeferredValue(a);
|
|
291
|
+
};
|
|
292
|
+
exports.useEffect = function(a, b) {
|
|
293
|
+
return U.current.useEffect(a, b);
|
|
294
|
+
};
|
|
295
|
+
exports.useId = function() {
|
|
296
|
+
return U.current.useId();
|
|
297
|
+
};
|
|
298
|
+
exports.useImperativeHandle = function(a, b, e) {
|
|
299
|
+
return U.current.useImperativeHandle(a, b, e);
|
|
300
|
+
};
|
|
301
|
+
exports.useInsertionEffect = function(a, b) {
|
|
302
|
+
return U.current.useInsertionEffect(a, b);
|
|
303
|
+
};
|
|
304
|
+
exports.useLayoutEffect = function(a, b) {
|
|
305
|
+
return U.current.useLayoutEffect(a, b);
|
|
306
|
+
};
|
|
307
|
+
exports.useMemo = function(a, b) {
|
|
308
|
+
return U.current.useMemo(a, b);
|
|
309
|
+
};
|
|
310
|
+
exports.useReducer = function(a, b, e) {
|
|
311
|
+
return U.current.useReducer(a, b, e);
|
|
312
|
+
};
|
|
313
|
+
exports.useRef = function(a) {
|
|
314
|
+
return U.current.useRef(a);
|
|
315
|
+
};
|
|
316
|
+
exports.useState = function(a) {
|
|
317
|
+
return U.current.useState(a);
|
|
318
|
+
};
|
|
319
|
+
exports.useSyncExternalStore = function(a, b, e) {
|
|
320
|
+
return U.current.useSyncExternalStore(a, b, e);
|
|
321
|
+
};
|
|
322
|
+
exports.useTransition = function() {
|
|
323
|
+
return U.current.useTransition();
|
|
324
|
+
};
|
|
325
|
+
exports.version = "18.3.1";
|
|
326
|
+
}));
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region ../../node_modules/react/index.js
|
|
329
|
+
var require_react = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
330
|
+
module.exports = require_react_production_min();
|
|
331
|
+
}));
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region ../../node_modules/react/cjs/react-jsx-runtime.production.min.js
|
|
334
|
+
/**
|
|
335
|
+
* @license React
|
|
336
|
+
* react-jsx-runtime.production.min.js
|
|
337
|
+
*
|
|
338
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
339
|
+
*
|
|
340
|
+
* This source code is licensed under the MIT license found in the
|
|
341
|
+
* LICENSE file in the root directory of this source tree.
|
|
342
|
+
*/
|
|
343
|
+
var require_react_jsx_runtime_production_min = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
344
|
+
var f = require_react(), k = Symbol.for("react.element"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = {
|
|
345
|
+
key: !0,
|
|
346
|
+
ref: !0,
|
|
347
|
+
__self: !0,
|
|
348
|
+
__source: !0
|
|
349
|
+
};
|
|
350
|
+
function q(c, a, g) {
|
|
351
|
+
var b, d = {}, e = null, h = null;
|
|
352
|
+
void 0 !== g && (e = "" + g);
|
|
353
|
+
void 0 !== a.key && (e = "" + a.key);
|
|
354
|
+
void 0 !== a.ref && (h = a.ref);
|
|
355
|
+
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
356
|
+
if (c && c.defaultProps) for (b in a = c.defaultProps, a) void 0 === d[b] && (d[b] = a[b]);
|
|
357
|
+
return {
|
|
358
|
+
$$typeof: k,
|
|
359
|
+
type: c,
|
|
360
|
+
key: e,
|
|
361
|
+
ref: h,
|
|
362
|
+
props: d,
|
|
363
|
+
_owner: n.current
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
exports.jsx = q;
|
|
367
|
+
}));
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region ../../node_modules/react/jsx-runtime.js
|
|
370
|
+
var require_jsx_runtime = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
371
|
+
module.exports = require_react_jsx_runtime_production_min();
|
|
372
|
+
}));
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region index.tsx
|
|
375
|
+
var import_react = require_react();
|
|
376
|
+
var import_jsx_runtime = require_jsx_runtime();
|
|
377
|
+
function normalize(uri) {
|
|
378
|
+
return uri.trim().toLowerCase().replace(/\/+/g, "/").replace(/^\/+|\/$/g, "");
|
|
379
|
+
}
|
|
380
|
+
function matchPath(path, pathname) {
|
|
381
|
+
const pathParts = normalize(path).split("/").filter(Boolean);
|
|
382
|
+
const pathnameParts = normalize(pathname).split("/").filter(Boolean);
|
|
383
|
+
return pathParts.length === pathnameParts.length && pathParts.every((pathPart, index) => {
|
|
384
|
+
return pathPart.startsWith(":") || pathPart === pathnameParts.at(index);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
function matchParameters(path, pathname) {
|
|
388
|
+
const pathParts = normalize(path).split("/").filter(Boolean);
|
|
389
|
+
const pathnameParts = normalize(pathname).split("/").filter(Boolean);
|
|
390
|
+
if (pathParts.length !== pathnameParts.length) return {};
|
|
391
|
+
return pathParts.reduce((parameters, pathPart, index) => {
|
|
392
|
+
if (!pathPart.startsWith(":")) return parameters;
|
|
393
|
+
return {
|
|
394
|
+
...parameters,
|
|
395
|
+
[pathPart.slice(1)]: pathnameParts.at(index) ?? ""
|
|
396
|
+
};
|
|
397
|
+
}, {});
|
|
398
|
+
}
|
|
399
|
+
var Uri = class Uri {
|
|
400
|
+
constructor(path, prefix, locale) {
|
|
401
|
+
this.path = path;
|
|
402
|
+
this.prefix = prefix;
|
|
403
|
+
this.locale = locale;
|
|
404
|
+
}
|
|
405
|
+
static from(uri, expectedPrefix, expectedLocales) {
|
|
406
|
+
const [prefixOrLocale, localeOrNothing, ...parts] = normalize(uri).split("/");
|
|
407
|
+
const locales = expectedLocales ?? [];
|
|
408
|
+
if (expectedPrefix && prefixOrLocale && prefixOrLocale === normalize(expectedPrefix)) {
|
|
409
|
+
const locale = locales.find((expectedLocale) => expectedLocale === localeOrNothing);
|
|
410
|
+
if (locale) return new Uri(parts.join("/"), prefixOrLocale, locale);
|
|
411
|
+
return new Uri([localeOrNothing, ...parts].join("/"), prefixOrLocale, null);
|
|
412
|
+
}
|
|
413
|
+
const locale = locales.find((expectedLocale) => expectedLocale === prefixOrLocale);
|
|
414
|
+
if (locale) return new Uri([localeOrNothing, ...parts].join("/"), null, locale);
|
|
415
|
+
return new Uri([
|
|
416
|
+
prefixOrLocale,
|
|
417
|
+
localeOrNothing,
|
|
418
|
+
...parts
|
|
419
|
+
].join("/"), null, null);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
var ErrorBoundary = class extends import_react.Component {
|
|
423
|
+
constructor(props) {
|
|
424
|
+
super(props);
|
|
425
|
+
this.state = {
|
|
426
|
+
error: null,
|
|
427
|
+
resetError: this.resetError.bind(this)
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
resetError() {
|
|
431
|
+
this.setState({ error: null });
|
|
432
|
+
}
|
|
433
|
+
static getDerivedStateFromError(error) {
|
|
434
|
+
return { error };
|
|
435
|
+
}
|
|
436
|
+
componentDidCatch(error) {
|
|
437
|
+
this.setState({ error: error instanceof Error ? error : new Error(String(error)) });
|
|
438
|
+
}
|
|
439
|
+
render() {
|
|
440
|
+
if (this.state.error) {
|
|
441
|
+
const Issue = this.props.issue;
|
|
442
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Issue, {
|
|
443
|
+
error: this.state.error,
|
|
444
|
+
resetError: this.state.resetError
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
return this.props.children;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
function createPage(page) {
|
|
451
|
+
return {
|
|
452
|
+
...page,
|
|
453
|
+
path: normalize(page.path)
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
const scaleFadeTransition = async (direction, next) => {
|
|
457
|
+
try {
|
|
458
|
+
await document.startViewTransition(() => {
|
|
459
|
+
next();
|
|
460
|
+
}).ready;
|
|
461
|
+
document.documentElement.animate([{
|
|
462
|
+
transform: "scale(1)",
|
|
463
|
+
opacity: 1
|
|
464
|
+
}, {
|
|
465
|
+
transform: direction === "forward" ? "scale(1.04)" : "scale(0.96)",
|
|
466
|
+
opacity: 0
|
|
467
|
+
}], {
|
|
468
|
+
duration: 200,
|
|
469
|
+
easing: "ease-in-out",
|
|
470
|
+
fill: "both",
|
|
471
|
+
pseudoElement: `::view-transition-old(root)`
|
|
472
|
+
});
|
|
473
|
+
document.documentElement.animate([{
|
|
474
|
+
transform: direction === "forward" ? "scale(0.96)" : "scale(1.04)",
|
|
475
|
+
opacity: 0
|
|
476
|
+
}, {
|
|
477
|
+
transform: "scale(1)",
|
|
478
|
+
opacity: 1
|
|
479
|
+
}], {
|
|
480
|
+
duration: 200,
|
|
481
|
+
easing: "ease-in-out",
|
|
482
|
+
fill: "both",
|
|
483
|
+
pseudoElement: `::view-transition-new(root)`
|
|
484
|
+
});
|
|
485
|
+
} catch (error) {
|
|
486
|
+
console.error(error);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
const crossFadeTransition = async (direction, next) => {
|
|
490
|
+
try {
|
|
491
|
+
await document.startViewTransition(() => {
|
|
492
|
+
next();
|
|
493
|
+
}).ready;
|
|
494
|
+
document.documentElement.animate([{ opacity: 1 }, { opacity: 0 }], {
|
|
495
|
+
duration: 200,
|
|
496
|
+
easing: "ease-in-out",
|
|
497
|
+
fill: "both",
|
|
498
|
+
pseudoElement: `::view-transition-old(root)`
|
|
499
|
+
});
|
|
500
|
+
document.documentElement.animate([{ opacity: 0 }, { opacity: 1 }], {
|
|
501
|
+
duration: 200,
|
|
502
|
+
easing: "ease-in-out",
|
|
503
|
+
fill: "both",
|
|
504
|
+
pseudoElement: `::view-transition-new(root)`
|
|
505
|
+
});
|
|
506
|
+
} catch (error) {
|
|
507
|
+
console.error(error);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
const slideHorizontalTransition = async (direction, next) => {
|
|
511
|
+
try {
|
|
512
|
+
await document.startViewTransition(() => {
|
|
513
|
+
next();
|
|
514
|
+
}).ready;
|
|
515
|
+
document.documentElement.animate([{ transform: "translateX(0)" }, { transform: direction === "forward" ? "translateX(-100%)" : "translateX(100%)" }], {
|
|
516
|
+
duration: 200,
|
|
517
|
+
easing: "ease-in-out",
|
|
518
|
+
fill: "both",
|
|
519
|
+
pseudoElement: `::view-transition-old(root)`
|
|
520
|
+
});
|
|
521
|
+
document.documentElement.animate([{ transform: direction === "forward" ? "translateX(100%)" : "translateX(-100%)" }, { transform: "translateX(0)" }], {
|
|
522
|
+
duration: 200,
|
|
523
|
+
easing: "ease-in-out",
|
|
524
|
+
fill: "both",
|
|
525
|
+
pseudoElement: `::view-transition-new(root)`
|
|
526
|
+
});
|
|
527
|
+
} catch (error) {
|
|
528
|
+
console.error(error);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
const slideVerticalTransition = async (direction, next) => {
|
|
532
|
+
try {
|
|
533
|
+
await document.startViewTransition(() => {
|
|
534
|
+
next();
|
|
535
|
+
}).ready;
|
|
536
|
+
document.documentElement.animate([{ transform: "translateY(0)" }, { transform: direction === "forward" ? "translateY(-100%)" : "translateY(100%)" }], {
|
|
537
|
+
duration: 200,
|
|
538
|
+
easing: "ease-in-out",
|
|
539
|
+
fill: "both",
|
|
540
|
+
pseudoElement: `::view-transition-old(root)`
|
|
541
|
+
});
|
|
542
|
+
document.documentElement.animate([{ transform: direction === "forward" ? "translateY(100%)" : "translateY(-100%)" }, { transform: "translateY(0)" }], {
|
|
543
|
+
duration: 200,
|
|
544
|
+
easing: "ease-in-out",
|
|
545
|
+
fill: "both",
|
|
546
|
+
pseudoElement: `::view-transition-new(root)`
|
|
547
|
+
});
|
|
548
|
+
} catch (error) {
|
|
549
|
+
console.error(error);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
function createRouter({ prefix: expectedPrefix, locales, pages, fallback: Fallback, issue: Issue, transition }) {
|
|
553
|
+
const RouterContext = (0, import_react.createContext)({
|
|
554
|
+
locale: null,
|
|
555
|
+
prefix: null,
|
|
556
|
+
path: "/",
|
|
557
|
+
setLocale: () => {}
|
|
558
|
+
});
|
|
559
|
+
function useIsActivePage(page) {
|
|
560
|
+
const { path } = usePath();
|
|
561
|
+
return matchPath(page.path, path);
|
|
562
|
+
}
|
|
563
|
+
function useLocale() {
|
|
564
|
+
const context = (0, import_react.useContext)(RouterContext);
|
|
565
|
+
if (!context) throw new Error("component using the useLocale hook has not been wrapped inside RouterProvider.");
|
|
566
|
+
return {
|
|
567
|
+
locale: context.locale,
|
|
568
|
+
setLocale: (locale) => {
|
|
569
|
+
if (!locales?.includes(locale)) return;
|
|
570
|
+
window.history.pushState(null, "", `/${normalize(`${context.prefix ?? ""}/${locale}/${context.path}`)}`);
|
|
571
|
+
window.dispatchEvent(new Event("pushstate"));
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
function usePrefix() {
|
|
576
|
+
const context = (0, import_react.useContext)(RouterContext);
|
|
577
|
+
if (!context) throw new Error("Component using the usePrefix hook has not been wrapped inside RouterProvider");
|
|
578
|
+
return { prefix: context.prefix };
|
|
579
|
+
}
|
|
580
|
+
function usePath() {
|
|
581
|
+
const context = (0, import_react.useContext)(RouterContext);
|
|
582
|
+
if (!context) throw new Error("Component using the usePath hook has not been wrapped inside RouterProvider");
|
|
583
|
+
return { path: context.path };
|
|
584
|
+
}
|
|
585
|
+
function useNavigateToPage(page) {
|
|
586
|
+
const { locale } = useLocale();
|
|
587
|
+
const { prefix } = usePrefix();
|
|
588
|
+
return (0, import_react.useCallback)((...[params]) => {
|
|
589
|
+
const path = Object.entries(params ?? {}).reduce((oldParams, [name, value]) => {
|
|
590
|
+
return oldParams.replace(`:${name}`, String(value));
|
|
591
|
+
}, page.path);
|
|
592
|
+
const pathname = `/${normalize(`${prefix ?? ""}/${locale ?? ""}/${path}`)}`;
|
|
593
|
+
console.log({ pathname });
|
|
594
|
+
window.history.pushState(null, "", pathname);
|
|
595
|
+
window.dispatchEvent(new Event("pushstate"));
|
|
596
|
+
}, [
|
|
597
|
+
page,
|
|
598
|
+
locale,
|
|
599
|
+
prefix
|
|
600
|
+
]);
|
|
601
|
+
}
|
|
602
|
+
function RouterProvider({ children }) {
|
|
603
|
+
const uri = (0, import_react.useMemo)(() => Uri.from(window.location.pathname, expectedPrefix, locales), [expectedPrefix, locales]);
|
|
604
|
+
const [locale, setLocale] = (0, import_react.useState)(uri.locale);
|
|
605
|
+
const [path, setPath] = (0, import_react.useState)(uri.path);
|
|
606
|
+
const [prefix, setPrefix] = (0, import_react.useState)(uri.prefix);
|
|
607
|
+
function setHash(newHash) {
|
|
608
|
+
window.location.hash = newHash;
|
|
609
|
+
}
|
|
610
|
+
const value = (0, import_react.useMemo)(() => {
|
|
611
|
+
return {
|
|
612
|
+
locale,
|
|
613
|
+
path,
|
|
614
|
+
prefix: prefix ?? null,
|
|
615
|
+
setLocale,
|
|
616
|
+
setHash
|
|
617
|
+
};
|
|
618
|
+
}, [
|
|
619
|
+
locale,
|
|
620
|
+
prefix,
|
|
621
|
+
path
|
|
622
|
+
]);
|
|
623
|
+
const onNavigation = (0, import_react.useEffectEvent)((direction) => {
|
|
624
|
+
const pathname = normalize(window.location.pathname);
|
|
625
|
+
const uri = Uri.from(pathname, expectedPrefix, locales);
|
|
626
|
+
const defaultTransition = (_, next) => {
|
|
627
|
+
next();
|
|
628
|
+
};
|
|
629
|
+
(transition ?? defaultTransition)(direction, () => {
|
|
630
|
+
setLocale(uri.locale);
|
|
631
|
+
setPath(uri.path);
|
|
632
|
+
setPrefix(uri.prefix);
|
|
633
|
+
});
|
|
634
|
+
});
|
|
635
|
+
const onMount = (0, import_react.useEffectEvent)(() => {
|
|
636
|
+
const pathname = `/${normalize(window.location.pathname)}`;
|
|
637
|
+
const uri = Uri.from(pathname, expectedPrefix, [locale, ...locales ?? []]);
|
|
638
|
+
const newPathname = `/${normalize(`${uri.prefix ?? expectedPrefix ?? ""}/${uri.locale ?? locales?.at(0) ?? ""}/${uri.path}`)}`;
|
|
639
|
+
if (newPathname !== pathname) {
|
|
640
|
+
window.history.pushState(null, "", newPathname);
|
|
641
|
+
window.dispatchEvent(new Event("pushstate"));
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
(0, import_react.useEffect)(() => {
|
|
645
|
+
const abortController = new AbortController();
|
|
646
|
+
window.addEventListener("pushstate", () => {
|
|
647
|
+
onNavigation("forward");
|
|
648
|
+
}, abortController);
|
|
649
|
+
window.addEventListener("popstate", () => {
|
|
650
|
+
onNavigation("backward");
|
|
651
|
+
}, abortController);
|
|
652
|
+
onMount();
|
|
653
|
+
return () => {
|
|
654
|
+
abortController.abort();
|
|
655
|
+
};
|
|
656
|
+
}, []);
|
|
657
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RouterContext.Provider, {
|
|
658
|
+
value,
|
|
659
|
+
children
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
function RouterView() {
|
|
663
|
+
const { path } = usePath();
|
|
664
|
+
const foundPage = (0, import_react.useMemo)(() => {
|
|
665
|
+
return pages.find((page) => {
|
|
666
|
+
return matchPath(page.path, path);
|
|
667
|
+
});
|
|
668
|
+
}, [path, pages]);
|
|
669
|
+
if (foundPage) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, {
|
|
670
|
+
issue: Issue,
|
|
671
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(foundPage.element, { parameters: matchParameters(foundPage.path, path) })
|
|
672
|
+
});
|
|
673
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, {
|
|
674
|
+
issue: Issue,
|
|
675
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Fallback, {})
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
RouterProvider,
|
|
680
|
+
RouterView,
|
|
681
|
+
useLocale,
|
|
682
|
+
usePrefix,
|
|
683
|
+
usePath,
|
|
684
|
+
useNavigateToPage,
|
|
685
|
+
useIsActivePage
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
//#endregion
|
|
689
|
+
export { Uri, createPage, createRouter, crossFadeTransition, scaleFadeTransition, slideHorizontalTransition, slideVerticalTransition };
|