@rpcbase/router 0.102.0 → 0.104.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/dist/index.js CHANGED
@@ -1,976 +1,820 @@
1
- import { UNSAFE_DataRouterContext, matchRoutes, Link as Link$1, useLocation, useNavigate } from "react-router";
2
- export * from "react-router";
3
- import { jsx } from "react/jsx-runtime";
1
+ import { Link as Link$1, UNSAFE_DataRouterContext, matchRoutes, useLocation, useNavigate } from "react-router";
4
2
  import { c } from "react/compiler-runtime";
5
- import { createContext, useContext, useRef, forwardRef, useEffect } from "react";
6
- const ROUTE_MODULE_IMPORTER_HANDLE = "__rpcbaseRouteModuleImporter";
7
- const ROUTE_PREFETCH_DATA_HANDLE = "prefetchData";
8
- const isHandleObject = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
9
- const getRouteModuleImporterFromHandle = (handle) => {
10
- if (!isHandleObject(handle)) return null;
11
- const importer = handle[ROUTE_MODULE_IMPORTER_HANDLE];
12
- return typeof importer === "function" ? importer : null;
13
- };
14
- const getRoutePrefetchDataFromHandle = (handle, key = ROUTE_PREFETCH_DATA_HANDLE) => {
15
- if (!isHandleObject(handle)) return void 0;
16
- const value = handle[key];
17
- return typeof value === "boolean" ? value : void 0;
18
- };
19
- const mergeRouteHandle = (handle, {
20
- importer,
21
- prefetchData,
22
- prefetchDataKey = ROUTE_PREFETCH_DATA_HANDLE
23
- }) => {
24
- const nextHandle = isHandleObject(handle) ? {
25
- ...handle
26
- } : {};
27
- if (importer) {
28
- nextHandle[ROUTE_MODULE_IMPORTER_HANDLE] = importer;
29
- }
30
- if (typeof prefetchData === "boolean") {
31
- nextHandle[prefetchDataKey] = prefetchData;
32
- }
33
- return nextHandle;
3
+ import { createContext, forwardRef, useContext, useEffect, useRef } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ export * from "react-router";
6
+ //#region src/routePrefetchHandles.ts
7
+ var ROUTE_MODULE_IMPORTER_HANDLE = "__rpcbaseRouteModuleImporter";
8
+ var ROUTE_PREFETCH_DATA_HANDLE = "prefetchData";
9
+ var isHandleObject = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
10
+ var getRouteModuleImporterFromHandle = (handle) => {
11
+ if (!isHandleObject(handle)) return null;
12
+ const importer = handle[ROUTE_MODULE_IMPORTER_HANDLE];
13
+ return typeof importer === "function" ? importer : null;
34
14
  };
35
- const noop = async () => {
15
+ var getRoutePrefetchDataFromHandle = (handle, key = ROUTE_PREFETCH_DATA_HANDLE) => {
16
+ if (!isHandleObject(handle)) return void 0;
17
+ const value = handle[key];
18
+ return typeof value === "boolean" ? value : void 0;
36
19
  };
37
- const DEFAULT_PREFETCH_API = {
38
- defaultPrefetch: "none",
39
- prefetch: noop,
40
- prefetchCode: noop,
41
- prefetchData: noop
20
+ var mergeRouteHandle = (handle, { importer, prefetchData, prefetchDataKey = ROUTE_PREFETCH_DATA_HANDLE }) => {
21
+ const nextHandle = isHandleObject(handle) ? { ...handle } : {};
22
+ if (importer) nextHandle[ROUTE_MODULE_IMPORTER_HANDLE] = importer;
23
+ if (typeof prefetchData === "boolean") nextHandle[prefetchDataKey] = prefetchData;
24
+ return nextHandle;
42
25
  };
43
- const RoutePrefetchContext = createContext(DEFAULT_PREFETCH_API);
44
- const normalizeHref = (href) => {
45
- if (typeof window === "undefined") return null;
46
- try {
47
- const url = new URL(href, window.location.origin);
48
- if (url.origin !== window.location.origin) return null;
49
- return {
50
- pathWithSearch: `${url.pathname}${url.search}`,
51
- pathname: url.pathname,
52
- search: url.search,
53
- hash: url.hash
54
- };
55
- } catch {
56
- return null;
57
- }
26
+ //#endregion
27
+ //#region src/routePrefetch.tsx
28
+ var noop = async () => {};
29
+ var RoutePrefetchContext = createContext({
30
+ defaultPrefetch: "none",
31
+ prefetch: noop,
32
+ prefetchCode: noop,
33
+ prefetchData: noop
34
+ });
35
+ var normalizeHref = (href) => {
36
+ if (typeof window === "undefined") return null;
37
+ try {
38
+ const url = new URL(href, window.location.origin);
39
+ if (url.origin !== window.location.origin) return null;
40
+ return {
41
+ pathWithSearch: `${url.pathname}${url.search}`,
42
+ pathname: url.pathname,
43
+ search: url.search,
44
+ hash: url.hash
45
+ };
46
+ } catch {
47
+ return null;
48
+ }
58
49
  };
59
- const pruneDataCache = (cache, now) => {
60
- cache.forEach((value, key) => {
61
- if (value.expiresAt <= now) {
62
- cache.delete(key);
63
- }
64
- });
50
+ var pruneDataCache = (cache, now) => {
51
+ cache.forEach((value, key) => {
52
+ if (value.expiresAt <= now) cache.delete(key);
53
+ });
65
54
  };
66
- const resolveDataPrefetchFlag = (route, explicitPrefetchData, dataPrefetchHandleKey) => {
67
- if (typeof explicitPrefetchData === "boolean") {
68
- return explicitPrefetchData;
69
- }
70
- const routeHandlePrefetchData = getRoutePrefetchDataFromHandle(route.handle, dataPrefetchHandleKey);
71
- if (typeof routeHandlePrefetchData === "boolean") {
72
- return routeHandlePrefetchData;
73
- }
74
- return false;
55
+ var resolveDataPrefetchFlag = (route, explicitPrefetchData, dataPrefetchHandleKey) => {
56
+ if (typeof explicitPrefetchData === "boolean") return explicitPrefetchData;
57
+ const routeHandlePrefetchData = getRoutePrefetchDataFromHandle(route.handle, dataPrefetchHandleKey);
58
+ if (typeof routeHandlePrefetchData === "boolean") return routeHandlePrefetchData;
59
+ return false;
75
60
  };
76
- const RoutePrefetchProvider = (t0) => {
77
- const $ = c(20);
78
- const {
79
- children,
80
- defaultPrefetch: t1,
81
- dataPrefetchTtlMs: t2,
82
- dataPrefetchHandleKey: t3
83
- } = t0;
84
- const defaultPrefetch = t1 === void 0 ? "intent" : t1;
85
- const dataPrefetchTtlMs = t2 === void 0 ? 3e4 : t2;
86
- const dataPrefetchHandleKey = t3 === void 0 ? ROUTE_PREFETCH_DATA_HANDLE : t3;
87
- const dataRouterContext = useContext(UNSAFE_DataRouterContext);
88
- let t4;
89
- if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
90
- t4 = /* @__PURE__ */ new Map();
91
- $[0] = t4;
92
- } else {
93
- t4 = $[0];
94
- }
95
- const routeModuleCacheRef = useRef(t4);
96
- let t5;
97
- if ($[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
98
- t5 = /* @__PURE__ */ new Map();
99
- $[1] = t5;
100
- } else {
101
- t5 = $[1];
102
- }
103
- const routeDataCacheRef = useRef(t5);
104
- let t6;
105
- if ($[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
106
- t6 = async (route) => {
107
- const routeId = route.id;
108
- if (!routeId) {
109
- return null;
110
- }
111
- const cached = routeModuleCacheRef.current.get(routeId);
112
- if (cached) {
113
- return cached;
114
- }
115
- const lazyRouteLoader = typeof route.lazy === "function" ? route.lazy : null;
116
- const routeModuleImporter = getRouteModuleImporterFromHandle(route.handle);
117
- if (!lazyRouteLoader && !routeModuleImporter) {
118
- return null;
119
- }
120
- const prefetchPromise = Promise.resolve(lazyRouteLoader ? lazyRouteLoader() : routeModuleImporter()).then(_temp$2).catch((error) => {
121
- routeModuleCacheRef.current.delete(routeId);
122
- throw error;
123
- });
124
- routeModuleCacheRef.current.set(routeId, prefetchPromise);
125
- return prefetchPromise;
126
- };
127
- $[2] = t6;
128
- } else {
129
- t6 = $[2];
130
- }
131
- const prefetchRouteModule = t6;
132
- let t7;
133
- if ($[3] !== dataPrefetchTtlMs) {
134
- t7 = async (router, route_0, href) => {
135
- const routeId_0 = route_0.id;
136
- if (!routeId_0) {
137
- return;
138
- }
139
- const now = Date.now();
140
- pruneDataCache(routeDataCacheRef.current, now);
141
- const cacheKey = `${routeId_0}|${href}`;
142
- const cached_0 = routeDataCacheRef.current.get(cacheKey);
143
- if (cached_0 && cached_0.expiresAt > now) {
144
- await cached_0.promise;
145
- return;
146
- }
147
- let hasLoader = typeof route_0.loader === "function";
148
- if (!hasLoader) {
149
- const loadedRouteModule = await prefetchRouteModule(route_0).catch(_temp2$1);
150
- hasLoader = typeof loadedRouteModule?.loader === "function";
151
- }
152
- if (!hasLoader) {
153
- return;
154
- }
155
- const fetcherKey = `rb:prefetch:${routeId_0}:${href}`;
156
- const prefetchPromise_0 = Promise.resolve(router.fetch(fetcherKey, routeId_0, href)).catch((error_0) => {
157
- routeDataCacheRef.current.delete(cacheKey);
158
- throw error_0;
159
- }).finally(() => {
160
- try {
161
- router.deleteFetcher(fetcherKey);
162
- } catch {
163
- return;
164
- }
165
- });
166
- const ttl = Math.max(1, dataPrefetchTtlMs);
167
- routeDataCacheRef.current.set(cacheKey, {
168
- expiresAt: now + ttl,
169
- promise: prefetchPromise_0
170
- });
171
- await prefetchPromise_0;
172
- };
173
- $[3] = dataPrefetchTtlMs;
174
- $[4] = t7;
175
- } else {
176
- t7 = $[4];
177
- }
178
- const prefetchRouteData = t7;
179
- let t8;
180
- if ($[5] !== dataPrefetchHandleKey || $[6] !== dataRouterContext?.router || $[7] !== prefetchRouteData) {
181
- t8 = async (href_0, opts) => {
182
- const normalized = normalizeHref(href_0);
183
- if (!normalized) {
184
- return;
185
- }
186
- const currentPathWithSearch = typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`;
187
- if (normalized.pathWithSearch === currentPathWithSearch) {
188
- return;
189
- }
190
- const router_0 = dataRouterContext?.router;
191
- if (!router_0) {
192
- return;
193
- }
194
- const matches = matchRoutes(router_0.routes, {
195
- pathname: normalized.pathname,
196
- search: normalized.search,
197
- hash: normalized.hash
198
- }, router_0.basename);
199
- if (!matches || matches.length === 0) {
200
- return;
201
- }
202
- const matchedRoutes = matches.map(_temp3);
203
- if (opts?.prefetchCode !== false) {
204
- await Promise.all(matchedRoutes.map(async (route_1) => {
205
- try {
206
- await prefetchRouteModule(route_1);
207
- } catch {
208
- return;
209
- }
210
- }));
211
- }
212
- await Promise.all(matchedRoutes.map(async (route_2) => {
213
- if (!resolveDataPrefetchFlag(route_2, opts?.prefetchData, dataPrefetchHandleKey)) {
214
- return;
215
- }
216
- try {
217
- await prefetchRouteData(router_0, route_2, normalized.pathWithSearch);
218
- } catch {
219
- return;
220
- }
221
- }));
222
- };
223
- $[5] = dataPrefetchHandleKey;
224
- $[6] = dataRouterContext?.router;
225
- $[7] = prefetchRouteData;
226
- $[8] = t8;
227
- } else {
228
- t8 = $[8];
229
- }
230
- const prefetch = t8;
231
- let t10;
232
- let t9;
233
- if ($[9] !== prefetch) {
234
- t9 = async (href_1) => prefetch(href_1, {
235
- prefetchCode: true,
236
- prefetchData: false
237
- });
238
- t10 = async (href_2) => prefetch(href_2, {
239
- prefetchCode: false,
240
- prefetchData: true
241
- });
242
- $[9] = prefetch;
243
- $[10] = t10;
244
- $[11] = t9;
245
- } else {
246
- t10 = $[10];
247
- t9 = $[11];
248
- }
249
- let t11;
250
- if ($[12] !== defaultPrefetch || $[13] !== prefetch || $[14] !== t10 || $[15] !== t9) {
251
- t11 = {
252
- defaultPrefetch,
253
- prefetch,
254
- prefetchCode: t9,
255
- prefetchData: t10
256
- };
257
- $[12] = defaultPrefetch;
258
- $[13] = prefetch;
259
- $[14] = t10;
260
- $[15] = t9;
261
- $[16] = t11;
262
- } else {
263
- t11 = $[16];
264
- }
265
- let t12;
266
- if ($[17] !== children || $[18] !== t11) {
267
- t12 = /* @__PURE__ */ jsx(RoutePrefetchContext.Provider, { value: t11, children });
268
- $[17] = children;
269
- $[18] = t11;
270
- $[19] = t12;
271
- } else {
272
- t12 = $[19];
273
- }
274
- return t12;
61
+ var RoutePrefetchProvider = (t0) => {
62
+ const $ = c(20);
63
+ const { children, defaultPrefetch: t1, dataPrefetchTtlMs: t2, dataPrefetchHandleKey: t3 } = t0;
64
+ const defaultPrefetch = t1 === void 0 ? "intent" : t1;
65
+ const dataPrefetchTtlMs = t2 === void 0 ? 3e4 : t2;
66
+ const dataPrefetchHandleKey = t3 === void 0 ? ROUTE_PREFETCH_DATA_HANDLE : t3;
67
+ const dataRouterContext = useContext(UNSAFE_DataRouterContext);
68
+ let t4;
69
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
70
+ t4 = /* @__PURE__ */ new Map();
71
+ $[0] = t4;
72
+ } else t4 = $[0];
73
+ const routeModuleCacheRef = useRef(t4);
74
+ let t5;
75
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
76
+ t5 = /* @__PURE__ */ new Map();
77
+ $[1] = t5;
78
+ } else t5 = $[1];
79
+ const routeDataCacheRef = useRef(t5);
80
+ let t6;
81
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
82
+ t6 = async (route) => {
83
+ const routeId = route.id;
84
+ if (!routeId) return null;
85
+ const cached = routeModuleCacheRef.current.get(routeId);
86
+ if (cached) return cached;
87
+ const lazyRouteLoader = typeof route.lazy === "function" ? route.lazy : null;
88
+ const routeModuleImporter = getRouteModuleImporterFromHandle(route.handle);
89
+ if (!lazyRouteLoader && !routeModuleImporter) return null;
90
+ const prefetchPromise = Promise.resolve(lazyRouteLoader ? lazyRouteLoader() : routeModuleImporter()).then(_temp$2).catch((error) => {
91
+ routeModuleCacheRef.current.delete(routeId);
92
+ throw error;
93
+ });
94
+ routeModuleCacheRef.current.set(routeId, prefetchPromise);
95
+ return prefetchPromise;
96
+ };
97
+ $[2] = t6;
98
+ } else t6 = $[2];
99
+ const prefetchRouteModule = t6;
100
+ let t7;
101
+ if ($[3] !== dataPrefetchTtlMs) {
102
+ t7 = async (router, route_0, href) => {
103
+ const routeId_0 = route_0.id;
104
+ if (!routeId_0) return;
105
+ const now = Date.now();
106
+ pruneDataCache(routeDataCacheRef.current, now);
107
+ const cacheKey = `${routeId_0}|${href}`;
108
+ const cached_0 = routeDataCacheRef.current.get(cacheKey);
109
+ if (cached_0 && cached_0.expiresAt > now) {
110
+ await cached_0.promise;
111
+ return;
112
+ }
113
+ let hasLoader = typeof route_0.loader === "function";
114
+ if (!hasLoader) hasLoader = typeof (await prefetchRouteModule(route_0).catch(_temp2$1))?.loader === "function";
115
+ if (!hasLoader) return;
116
+ const fetcherKey = `rb:prefetch:${routeId_0}:${href}`;
117
+ const prefetchPromise_0 = Promise.resolve(router.fetch(fetcherKey, routeId_0, href)).catch((error_0) => {
118
+ routeDataCacheRef.current.delete(cacheKey);
119
+ throw error_0;
120
+ }).finally(() => {
121
+ try {
122
+ router.deleteFetcher(fetcherKey);
123
+ } catch {
124
+ return;
125
+ }
126
+ });
127
+ const ttl = Math.max(1, dataPrefetchTtlMs);
128
+ routeDataCacheRef.current.set(cacheKey, {
129
+ expiresAt: now + ttl,
130
+ promise: prefetchPromise_0
131
+ });
132
+ await prefetchPromise_0;
133
+ };
134
+ $[3] = dataPrefetchTtlMs;
135
+ $[4] = t7;
136
+ } else t7 = $[4];
137
+ const prefetchRouteData = t7;
138
+ let t8;
139
+ if ($[5] !== dataPrefetchHandleKey || $[6] !== dataRouterContext?.router || $[7] !== prefetchRouteData) {
140
+ t8 = async (href_0, opts) => {
141
+ const normalized = normalizeHref(href_0);
142
+ if (!normalized) return;
143
+ const currentPathWithSearch = typeof window === "undefined" ? "" : `${window.location.pathname}${window.location.search}`;
144
+ if (normalized.pathWithSearch === currentPathWithSearch) return;
145
+ const router_0 = dataRouterContext?.router;
146
+ if (!router_0) return;
147
+ const matches = matchRoutes(router_0.routes, {
148
+ pathname: normalized.pathname,
149
+ search: normalized.search,
150
+ hash: normalized.hash
151
+ }, router_0.basename);
152
+ if (!matches || matches.length === 0) return;
153
+ const matchedRoutes = matches.map(_temp3);
154
+ if (opts?.prefetchCode !== false) await Promise.all(matchedRoutes.map(async (route_1) => {
155
+ try {
156
+ await prefetchRouteModule(route_1);
157
+ } catch {
158
+ return;
159
+ }
160
+ }));
161
+ await Promise.all(matchedRoutes.map(async (route_2) => {
162
+ if (!resolveDataPrefetchFlag(route_2, opts?.prefetchData, dataPrefetchHandleKey)) return;
163
+ try {
164
+ await prefetchRouteData(router_0, route_2, normalized.pathWithSearch);
165
+ } catch {
166
+ return;
167
+ }
168
+ }));
169
+ };
170
+ $[5] = dataPrefetchHandleKey;
171
+ $[6] = dataRouterContext?.router;
172
+ $[7] = prefetchRouteData;
173
+ $[8] = t8;
174
+ } else t8 = $[8];
175
+ const prefetch = t8;
176
+ let t10;
177
+ let t9;
178
+ if ($[9] !== prefetch) {
179
+ t9 = async (href_1) => prefetch(href_1, {
180
+ prefetchCode: true,
181
+ prefetchData: false
182
+ });
183
+ t10 = async (href_2) => prefetch(href_2, {
184
+ prefetchCode: false,
185
+ prefetchData: true
186
+ });
187
+ $[9] = prefetch;
188
+ $[10] = t10;
189
+ $[11] = t9;
190
+ } else {
191
+ t10 = $[10];
192
+ t9 = $[11];
193
+ }
194
+ let t11;
195
+ if ($[12] !== defaultPrefetch || $[13] !== prefetch || $[14] !== t10 || $[15] !== t9) {
196
+ t11 = {
197
+ defaultPrefetch,
198
+ prefetch,
199
+ prefetchCode: t9,
200
+ prefetchData: t10
201
+ };
202
+ $[12] = defaultPrefetch;
203
+ $[13] = prefetch;
204
+ $[14] = t10;
205
+ $[15] = t9;
206
+ $[16] = t11;
207
+ } else t11 = $[16];
208
+ let t12;
209
+ if ($[17] !== children || $[18] !== t11) {
210
+ t12 = /* @__PURE__ */ jsx(RoutePrefetchContext.Provider, {
211
+ value: t11,
212
+ children
213
+ });
214
+ $[17] = children;
215
+ $[18] = t11;
216
+ $[19] = t12;
217
+ } else t12 = $[19];
218
+ return t12;
275
219
  };
276
- const useRoutePrefetch = () => {
277
- return useContext(RoutePrefetchContext);
220
+ var useRoutePrefetch = () => {
221
+ return useContext(RoutePrefetchContext);
278
222
  };
279
223
  function _temp$2(module) {
280
- if (!module || typeof module !== "object") {
281
- return null;
282
- }
283
- return module;
224
+ if (!module || typeof module !== "object") return null;
225
+ return module;
284
226
  }
285
227
  function _temp2$1() {
286
- return null;
228
+ return null;
287
229
  }
288
230
  function _temp3(match) {
289
- return match.route;
231
+ return match.route;
290
232
  }
291
- const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
292
- const assignRef = (ref, value) => {
293
- if (!ref) return;
294
- if (typeof ref === "function") {
295
- ref(value);
296
- return;
297
- }
298
- ref.current = value;
233
+ //#endregion
234
+ //#region src/Link.tsx
235
+ var ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
236
+ var assignRef = (ref, value) => {
237
+ if (!ref) return;
238
+ if (typeof ref === "function") {
239
+ ref(value);
240
+ return;
241
+ }
242
+ ref.current = value;
299
243
  };
300
- const composeEventHandlers = (theirHandler, ourHandler) => {
301
- return (event) => {
302
- theirHandler?.(event);
303
- if (!event.defaultPrevented) {
304
- ourHandler();
305
- }
306
- };
244
+ var composeEventHandlers = (theirHandler, ourHandler) => {
245
+ return (event) => {
246
+ theirHandler?.(event);
247
+ if (!event.defaultPrevented) ourHandler();
248
+ };
307
249
  };
308
- const shouldPrefetchLink = ({
309
- prefetch,
310
- reloadDocument,
311
- target,
312
- to
313
- }) => {
314
- if (prefetch === "none") return false;
315
- if (reloadDocument) return false;
316
- if (typeof target === "string" && target !== "_self") return false;
317
- if (typeof to === "string" && ABSOLUTE_URL_REGEX.test(to)) return false;
318
- return true;
250
+ var shouldPrefetchLink = ({ prefetch, reloadDocument, target, to }) => {
251
+ if (prefetch === "none") return false;
252
+ if (reloadDocument) return false;
253
+ if (typeof target === "string" && target !== "_self") return false;
254
+ if (typeof to === "string" && ABSOLUTE_URL_REGEX.test(to)) return false;
255
+ return true;
319
256
  };
320
- const usePrefetchLink = (prefetchData) => {
321
- const $ = c(5);
322
- const localRef = useRef(null);
323
- const {
324
- prefetch
325
- } = useRoutePrefetch();
326
- let t0;
327
- let t1;
328
- if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
329
- t0 = (node) => {
330
- localRef.current = node;
331
- };
332
- t1 = () => localRef.current;
333
- $[0] = t0;
334
- $[1] = t1;
335
- } else {
336
- t0 = $[0];
337
- t1 = $[1];
338
- }
339
- let t2;
340
- if ($[2] !== prefetch || $[3] !== prefetchData) {
341
- t2 = {
342
- anchorRef: t0,
343
- getAnchorElement: t1,
344
- prefetchHref: () => {
345
- const href = localRef.current?.getAttribute("href");
346
- if (!href) {
347
- return;
348
- }
349
- prefetch(href, {
350
- prefetchData
351
- });
352
- }
353
- };
354
- $[2] = prefetch;
355
- $[3] = prefetchData;
356
- $[4] = t2;
357
- } else {
358
- t2 = $[4];
359
- }
360
- return t2;
257
+ var usePrefetchLink = (prefetchData) => {
258
+ const $ = c(5);
259
+ const localRef = useRef(null);
260
+ const { prefetch } = useRoutePrefetch();
261
+ let t0;
262
+ let t1;
263
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
264
+ t0 = (node) => {
265
+ localRef.current = node;
266
+ };
267
+ t1 = () => localRef.current;
268
+ $[0] = t0;
269
+ $[1] = t1;
270
+ } else {
271
+ t0 = $[0];
272
+ t1 = $[1];
273
+ }
274
+ let t2;
275
+ if ($[2] !== prefetch || $[3] !== prefetchData) {
276
+ t2 = {
277
+ anchorRef: t0,
278
+ getAnchorElement: t1,
279
+ prefetchHref: () => {
280
+ const href = localRef.current?.getAttribute("href");
281
+ if (!href) return;
282
+ prefetch(href, { prefetchData });
283
+ }
284
+ };
285
+ $[2] = prefetch;
286
+ $[3] = prefetchData;
287
+ $[4] = t2;
288
+ } else t2 = $[4];
289
+ return t2;
361
290
  };
362
- const Link = forwardRef((t0, forwardedRef) => {
363
- const $ = c(54);
364
- let onFocus;
365
- let onMouseEnter;
366
- let onTouchStart;
367
- let prefetchData;
368
- let prefetchProp;
369
- let props;
370
- let reloadDocument;
371
- let target;
372
- let to;
373
- if ($[0] !== t0) {
374
- ({
375
- prefetch: prefetchProp,
376
- prefetchData,
377
- onMouseEnter,
378
- onFocus,
379
- onTouchStart,
380
- reloadDocument,
381
- target,
382
- to,
383
- ...props
384
- } = t0);
385
- $[0] = t0;
386
- $[1] = onFocus;
387
- $[2] = onMouseEnter;
388
- $[3] = onTouchStart;
389
- $[4] = prefetchData;
390
- $[5] = prefetchProp;
391
- $[6] = props;
392
- $[7] = reloadDocument;
393
- $[8] = target;
394
- $[9] = to;
395
- } else {
396
- onFocus = $[1];
397
- onMouseEnter = $[2];
398
- onTouchStart = $[3];
399
- prefetchData = $[4];
400
- prefetchProp = $[5];
401
- props = $[6];
402
- reloadDocument = $[7];
403
- target = $[8];
404
- to = $[9];
405
- }
406
- const {
407
- defaultPrefetch
408
- } = useRoutePrefetch();
409
- const prefetchBehavior = prefetchProp ?? defaultPrefetch;
410
- const viewportPrefetchedRef = useRef(false);
411
- const {
412
- anchorRef,
413
- prefetchHref,
414
- getAnchorElement
415
- } = usePrefetchLink(prefetchData);
416
- let t1;
417
- if ($[10] !== prefetchBehavior || $[11] !== reloadDocument || $[12] !== target || $[13] !== to) {
418
- t1 = shouldPrefetchLink({
419
- prefetch: prefetchBehavior,
420
- reloadDocument,
421
- target,
422
- to
423
- });
424
- $[10] = prefetchBehavior;
425
- $[11] = reloadDocument;
426
- $[12] = target;
427
- $[13] = to;
428
- $[14] = t1;
429
- } else {
430
- t1 = $[14];
431
- }
432
- const canPrefetch = t1;
433
- let t2;
434
- if ($[15] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
435
- t2 = () => {
436
- viewportPrefetchedRef.current = false;
437
- };
438
- $[15] = t2;
439
- } else {
440
- t2 = $[15];
441
- }
442
- let t3;
443
- if ($[16] !== to) {
444
- t3 = [to];
445
- $[16] = to;
446
- $[17] = t3;
447
- } else {
448
- t3 = $[17];
449
- }
450
- useEffect(t2, t3);
451
- let t4;
452
- let t5;
453
- if ($[18] !== canPrefetch || $[19] !== prefetchBehavior || $[20] !== prefetchHref) {
454
- t4 = () => {
455
- if (!canPrefetch || prefetchBehavior !== "render") {
456
- return;
457
- }
458
- prefetchHref();
459
- };
460
- t5 = [canPrefetch, prefetchBehavior, prefetchHref];
461
- $[18] = canPrefetch;
462
- $[19] = prefetchBehavior;
463
- $[20] = prefetchHref;
464
- $[21] = t4;
465
- $[22] = t5;
466
- } else {
467
- t4 = $[21];
468
- t5 = $[22];
469
- }
470
- useEffect(t4, t5);
471
- let t6;
472
- let t7;
473
- if ($[23] !== canPrefetch || $[24] !== getAnchorElement || $[25] !== prefetchBehavior || $[26] !== prefetchHref) {
474
- t6 = () => {
475
- if (!canPrefetch || prefetchBehavior !== "viewport") {
476
- return;
477
- }
478
- const element = getAnchorElement();
479
- if (!element || typeof IntersectionObserver === "undefined") {
480
- return;
481
- }
482
- const observer = new IntersectionObserver((entries) => {
483
- const isVisible = entries.some(_temp$1);
484
- if (!isVisible || viewportPrefetchedRef.current) {
485
- return;
486
- }
487
- viewportPrefetchedRef.current = true;
488
- prefetchHref();
489
- }, {
490
- threshold: 0.5
491
- });
492
- observer.observe(element);
493
- return () => {
494
- observer.disconnect();
495
- };
496
- };
497
- t7 = [canPrefetch, prefetchBehavior, prefetchHref, getAnchorElement];
498
- $[23] = canPrefetch;
499
- $[24] = getAnchorElement;
500
- $[25] = prefetchBehavior;
501
- $[26] = prefetchHref;
502
- $[27] = t6;
503
- $[28] = t7;
504
- } else {
505
- t6 = $[27];
506
- t7 = $[28];
507
- }
508
- useEffect(t6, t7);
509
- let t8;
510
- if ($[29] !== canPrefetch || $[30] !== prefetchBehavior || $[31] !== prefetchHref) {
511
- t8 = () => {
512
- if (!canPrefetch || prefetchBehavior !== "intent") {
513
- return;
514
- }
515
- prefetchHref();
516
- };
517
- $[29] = canPrefetch;
518
- $[30] = prefetchBehavior;
519
- $[31] = prefetchHref;
520
- $[32] = t8;
521
- } else {
522
- t8 = $[32];
523
- }
524
- const handleIntentPrefetch = t8;
525
- let t9;
526
- if ($[33] !== handleIntentPrefetch || $[34] !== onMouseEnter) {
527
- t9 = composeEventHandlers(onMouseEnter, handleIntentPrefetch);
528
- $[33] = handleIntentPrefetch;
529
- $[34] = onMouseEnter;
530
- $[35] = t9;
531
- } else {
532
- t9 = $[35];
533
- }
534
- let t10;
535
- if ($[36] !== handleIntentPrefetch || $[37] !== onFocus) {
536
- t10 = composeEventHandlers(onFocus, handleIntentPrefetch);
537
- $[36] = handleIntentPrefetch;
538
- $[37] = onFocus;
539
- $[38] = t10;
540
- } else {
541
- t10 = $[38];
542
- }
543
- let t11;
544
- if ($[39] !== handleIntentPrefetch || $[40] !== onTouchStart) {
545
- t11 = composeEventHandlers(onTouchStart, handleIntentPrefetch);
546
- $[39] = handleIntentPrefetch;
547
- $[40] = onTouchStart;
548
- $[41] = t11;
549
- } else {
550
- t11 = $[41];
551
- }
552
- let t12;
553
- if ($[42] !== anchorRef || $[43] !== forwardedRef) {
554
- t12 = (node) => {
555
- assignRef(forwardedRef, node);
556
- assignRef(anchorRef, node);
557
- };
558
- $[42] = anchorRef;
559
- $[43] = forwardedRef;
560
- $[44] = t12;
561
- } else {
562
- t12 = $[44];
563
- }
564
- let t13;
565
- if ($[45] !== props || $[46] !== reloadDocument || $[47] !== t10 || $[48] !== t11 || $[49] !== t12 || $[50] !== t9 || $[51] !== target || $[52] !== to) {
566
- t13 = /* @__PURE__ */ jsx(Link$1, { ...props, to, target, reloadDocument, prefetch: "none", onMouseEnter: t9, onFocus: t10, onTouchStart: t11, ref: t12 });
567
- $[45] = props;
568
- $[46] = reloadDocument;
569
- $[47] = t10;
570
- $[48] = t11;
571
- $[49] = t12;
572
- $[50] = t9;
573
- $[51] = target;
574
- $[52] = to;
575
- $[53] = t13;
576
- } else {
577
- t13 = $[53];
578
- }
579
- return t13;
291
+ var Link = forwardRef((t0, forwardedRef) => {
292
+ const $ = c(54);
293
+ let onFocus;
294
+ let onMouseEnter;
295
+ let onTouchStart;
296
+ let prefetchData;
297
+ let prefetchProp;
298
+ let props;
299
+ let reloadDocument;
300
+ let target;
301
+ let to;
302
+ if ($[0] !== t0) {
303
+ ({prefetch: prefetchProp, prefetchData, onMouseEnter, onFocus, onTouchStart, reloadDocument, target, to, ...props} = t0);
304
+ $[0] = t0;
305
+ $[1] = onFocus;
306
+ $[2] = onMouseEnter;
307
+ $[3] = onTouchStart;
308
+ $[4] = prefetchData;
309
+ $[5] = prefetchProp;
310
+ $[6] = props;
311
+ $[7] = reloadDocument;
312
+ $[8] = target;
313
+ $[9] = to;
314
+ } else {
315
+ onFocus = $[1];
316
+ onMouseEnter = $[2];
317
+ onTouchStart = $[3];
318
+ prefetchData = $[4];
319
+ prefetchProp = $[5];
320
+ props = $[6];
321
+ reloadDocument = $[7];
322
+ target = $[8];
323
+ to = $[9];
324
+ }
325
+ const { defaultPrefetch } = useRoutePrefetch();
326
+ const prefetchBehavior = prefetchProp ?? defaultPrefetch;
327
+ const viewportPrefetchedRef = useRef(false);
328
+ const { anchorRef, prefetchHref, getAnchorElement } = usePrefetchLink(prefetchData);
329
+ let t1;
330
+ if ($[10] !== prefetchBehavior || $[11] !== reloadDocument || $[12] !== target || $[13] !== to) {
331
+ t1 = shouldPrefetchLink({
332
+ prefetch: prefetchBehavior,
333
+ reloadDocument,
334
+ target,
335
+ to
336
+ });
337
+ $[10] = prefetchBehavior;
338
+ $[11] = reloadDocument;
339
+ $[12] = target;
340
+ $[13] = to;
341
+ $[14] = t1;
342
+ } else t1 = $[14];
343
+ const canPrefetch = t1;
344
+ let t2;
345
+ if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
346
+ t2 = () => {
347
+ viewportPrefetchedRef.current = false;
348
+ };
349
+ $[15] = t2;
350
+ } else t2 = $[15];
351
+ let t3;
352
+ if ($[16] !== to) {
353
+ t3 = [to];
354
+ $[16] = to;
355
+ $[17] = t3;
356
+ } else t3 = $[17];
357
+ useEffect(t2, t3);
358
+ let t4;
359
+ let t5;
360
+ if ($[18] !== canPrefetch || $[19] !== prefetchBehavior || $[20] !== prefetchHref) {
361
+ t4 = () => {
362
+ if (!canPrefetch || prefetchBehavior !== "render") return;
363
+ prefetchHref();
364
+ };
365
+ t5 = [
366
+ canPrefetch,
367
+ prefetchBehavior,
368
+ prefetchHref
369
+ ];
370
+ $[18] = canPrefetch;
371
+ $[19] = prefetchBehavior;
372
+ $[20] = prefetchHref;
373
+ $[21] = t4;
374
+ $[22] = t5;
375
+ } else {
376
+ t4 = $[21];
377
+ t5 = $[22];
378
+ }
379
+ useEffect(t4, t5);
380
+ let t6;
381
+ let t7;
382
+ if ($[23] !== canPrefetch || $[24] !== getAnchorElement || $[25] !== prefetchBehavior || $[26] !== prefetchHref) {
383
+ t6 = () => {
384
+ if (!canPrefetch || prefetchBehavior !== "viewport") return;
385
+ const element = getAnchorElement();
386
+ if (!element || typeof IntersectionObserver === "undefined") return;
387
+ const observer = new IntersectionObserver((entries) => {
388
+ if (!entries.some(_temp$1) || viewportPrefetchedRef.current) return;
389
+ viewportPrefetchedRef.current = true;
390
+ prefetchHref();
391
+ }, { threshold: .5 });
392
+ observer.observe(element);
393
+ return () => {
394
+ observer.disconnect();
395
+ };
396
+ };
397
+ t7 = [
398
+ canPrefetch,
399
+ prefetchBehavior,
400
+ prefetchHref,
401
+ getAnchorElement
402
+ ];
403
+ $[23] = canPrefetch;
404
+ $[24] = getAnchorElement;
405
+ $[25] = prefetchBehavior;
406
+ $[26] = prefetchHref;
407
+ $[27] = t6;
408
+ $[28] = t7;
409
+ } else {
410
+ t6 = $[27];
411
+ t7 = $[28];
412
+ }
413
+ useEffect(t6, t7);
414
+ let t8;
415
+ if ($[29] !== canPrefetch || $[30] !== prefetchBehavior || $[31] !== prefetchHref) {
416
+ t8 = () => {
417
+ if (!canPrefetch || prefetchBehavior !== "intent") return;
418
+ prefetchHref();
419
+ };
420
+ $[29] = canPrefetch;
421
+ $[30] = prefetchBehavior;
422
+ $[31] = prefetchHref;
423
+ $[32] = t8;
424
+ } else t8 = $[32];
425
+ const handleIntentPrefetch = t8;
426
+ let t9;
427
+ if ($[33] !== handleIntentPrefetch || $[34] !== onMouseEnter) {
428
+ t9 = composeEventHandlers(onMouseEnter, handleIntentPrefetch);
429
+ $[33] = handleIntentPrefetch;
430
+ $[34] = onMouseEnter;
431
+ $[35] = t9;
432
+ } else t9 = $[35];
433
+ let t10;
434
+ if ($[36] !== handleIntentPrefetch || $[37] !== onFocus) {
435
+ t10 = composeEventHandlers(onFocus, handleIntentPrefetch);
436
+ $[36] = handleIntentPrefetch;
437
+ $[37] = onFocus;
438
+ $[38] = t10;
439
+ } else t10 = $[38];
440
+ let t11;
441
+ if ($[39] !== handleIntentPrefetch || $[40] !== onTouchStart) {
442
+ t11 = composeEventHandlers(onTouchStart, handleIntentPrefetch);
443
+ $[39] = handleIntentPrefetch;
444
+ $[40] = onTouchStart;
445
+ $[41] = t11;
446
+ } else t11 = $[41];
447
+ let t12;
448
+ if ($[42] !== anchorRef || $[43] !== forwardedRef) {
449
+ t12 = (node) => {
450
+ assignRef(forwardedRef, node);
451
+ assignRef(anchorRef, node);
452
+ };
453
+ $[42] = anchorRef;
454
+ $[43] = forwardedRef;
455
+ $[44] = t12;
456
+ } else t12 = $[44];
457
+ let t13;
458
+ if ($[45] !== props || $[46] !== reloadDocument || $[47] !== t10 || $[48] !== t11 || $[49] !== t12 || $[50] !== t9 || $[51] !== target || $[52] !== to) {
459
+ t13 = /* @__PURE__ */ jsx(Link$1, {
460
+ ...props,
461
+ to,
462
+ target,
463
+ reloadDocument,
464
+ prefetch: "none",
465
+ onMouseEnter: t9,
466
+ onFocus: t10,
467
+ onTouchStart: t11,
468
+ ref: t12
469
+ });
470
+ $[45] = props;
471
+ $[46] = reloadDocument;
472
+ $[47] = t10;
473
+ $[48] = t11;
474
+ $[49] = t12;
475
+ $[50] = t9;
476
+ $[51] = target;
477
+ $[52] = to;
478
+ $[53] = t13;
479
+ } else t13 = $[53];
480
+ return t13;
580
481
  });
581
482
  Link.displayName = "Link";
582
483
  function _temp$1(entry) {
583
- return entry.isIntersecting;
484
+ return entry.isIntersecting;
584
485
  }
585
- const memoizeImporter = (importer) => {
586
- let promise = null;
587
- return async () => {
588
- if (!promise) {
589
- promise = importer().catch((error) => {
590
- promise = null;
591
- throw error;
592
- });
593
- }
594
- return promise;
595
- };
486
+ //#endregion
487
+ //#region src/lazyRoute.tsx
488
+ var memoizeImporter = (importer) => {
489
+ let promise = null;
490
+ return async () => {
491
+ if (!promise) promise = importer().catch((error) => {
492
+ promise = null;
493
+ throw error;
494
+ });
495
+ return promise;
496
+ };
596
497
  };
597
- const lazyRoute = (importer, opts) => {
598
- const loadModule = memoizeImporter(importer);
599
- return {
600
- lazy: async () => {
601
- const module = await loadModule();
602
- const lazyRouteModule = {
603
- Component: module.default
604
- };
605
- if (typeof module.loader === "function") {
606
- lazyRouteModule.loader = module.loader;
607
- }
608
- return lazyRouteModule;
609
- },
610
- handle: mergeRouteHandle(opts?.handle, {
611
- importer: loadModule,
612
- prefetchData: opts?.prefetchData,
613
- prefetchDataKey: opts?.prefetchDataKey
614
- })
615
- };
498
+ var lazyRoute = (importer, opts) => {
499
+ const loadModule = memoizeImporter(importer);
500
+ return {
501
+ lazy: async () => {
502
+ const module = await loadModule();
503
+ const lazyRouteModule = { Component: module.default };
504
+ if (typeof module.loader === "function") lazyRouteModule.loader = module.loader;
505
+ return lazyRouteModule;
506
+ },
507
+ handle: mergeRouteHandle(opts?.handle, {
508
+ importer: loadModule,
509
+ prefetchData: opts?.prefetchData,
510
+ prefetchDataKey: opts?.prefetchDataKey
511
+ })
512
+ };
616
513
  };
617
- const useApplyMeta = (t0) => {
618
- const $ = c(12);
619
- let t1;
620
- if ($[0] !== t0) {
621
- t1 = t0 === void 0 ? {} : t0;
622
- $[0] = t0;
623
- $[1] = t1;
624
- } else {
625
- t1 = $[1];
626
- }
627
- const {
628
- defaultTitle: t2,
629
- defaultMeta: t3,
630
- pagesMeta: t4
631
- } = t1;
632
- const defaultTitle = t2 === void 0 ? "" : t2;
633
- let t5;
634
- if ($[2] !== t3) {
635
- t5 = t3 === void 0 ? [] : t3;
636
- $[2] = t3;
637
- $[3] = t5;
638
- } else {
639
- t5 = $[3];
640
- }
641
- const defaultMeta = t5;
642
- let t6;
643
- if ($[4] !== t4) {
644
- t6 = t4 === void 0 ? {} : t4;
645
- $[4] = t4;
646
- $[5] = t6;
647
- } else {
648
- t6 = $[5];
649
- }
650
- const pagesMeta = t6;
651
- const location = useLocation();
652
- let t7;
653
- let t8;
654
- if ($[6] !== defaultMeta || $[7] !== defaultTitle || $[8] !== location.pathname || $[9] !== pagesMeta) {
655
- t7 = () => {
656
- const loadMeta = async () => {
657
- let pageMeta = pagesMeta[location.pathname];
658
- if (!pageMeta) {
659
- pageMeta = {
660
- title: defaultTitle,
661
- meta: defaultMeta
662
- };
663
- }
664
- document.title = pageMeta.title;
665
- document.querySelectorAll("[data-react-meta]").forEach(_temp);
666
- pageMeta.meta.forEach(_temp2);
667
- const canonicalUrl = `${window.location.origin}${location.pathname}`;
668
- const existingCanonical = document.querySelector('link[rel="canonical"]');
669
- if (existingCanonical) {
670
- existingCanonical.remove();
671
- }
672
- const canonicalLink = document.createElement("link");
673
- canonicalLink.setAttribute("rel", "canonical");
674
- canonicalLink.setAttribute("href", canonicalUrl);
675
- canonicalLink.setAttribute("data-react-meta", "true");
676
- document.head.appendChild(canonicalLink);
677
- };
678
- loadMeta();
679
- };
680
- t8 = [location.pathname, defaultTitle, defaultMeta, pagesMeta];
681
- $[6] = defaultMeta;
682
- $[7] = defaultTitle;
683
- $[8] = location.pathname;
684
- $[9] = pagesMeta;
685
- $[10] = t7;
686
- $[11] = t8;
687
- } else {
688
- t7 = $[10];
689
- t8 = $[11];
690
- }
691
- useEffect(t7, t8);
514
+ //#endregion
515
+ //#region src/useApplyMeta.tsx
516
+ var useApplyMeta = (t0) => {
517
+ const $ = c(12);
518
+ let t1;
519
+ if ($[0] !== t0) {
520
+ t1 = t0 === void 0 ? {} : t0;
521
+ $[0] = t0;
522
+ $[1] = t1;
523
+ } else t1 = $[1];
524
+ const { defaultTitle: t2, defaultMeta: t3, pagesMeta: t4 } = t1;
525
+ const defaultTitle = t2 === void 0 ? "" : t2;
526
+ let t5;
527
+ if ($[2] !== t3) {
528
+ t5 = t3 === void 0 ? [] : t3;
529
+ $[2] = t3;
530
+ $[3] = t5;
531
+ } else t5 = $[3];
532
+ const defaultMeta = t5;
533
+ let t6;
534
+ if ($[4] !== t4) {
535
+ t6 = t4 === void 0 ? {} : t4;
536
+ $[4] = t4;
537
+ $[5] = t6;
538
+ } else t6 = $[5];
539
+ const pagesMeta = t6;
540
+ const location = useLocation();
541
+ let t7;
542
+ let t8;
543
+ if ($[6] !== defaultMeta || $[7] !== defaultTitle || $[8] !== location.pathname || $[9] !== pagesMeta) {
544
+ t7 = () => {
545
+ const loadMeta = async () => {
546
+ let pageMeta = pagesMeta[location.pathname];
547
+ if (!pageMeta) pageMeta = {
548
+ title: defaultTitle,
549
+ meta: defaultMeta
550
+ };
551
+ document.title = pageMeta.title;
552
+ document.querySelectorAll("[data-react-meta]").forEach(_temp);
553
+ pageMeta.meta.forEach(_temp2);
554
+ const canonicalUrl = `${window.location.origin}${location.pathname}`;
555
+ const existingCanonical = document.querySelector("link[rel=\"canonical\"]");
556
+ if (existingCanonical) existingCanonical.remove();
557
+ const canonicalLink = document.createElement("link");
558
+ canonicalLink.setAttribute("rel", "canonical");
559
+ canonicalLink.setAttribute("href", canonicalUrl);
560
+ canonicalLink.setAttribute("data-react-meta", "true");
561
+ document.head.appendChild(canonicalLink);
562
+ };
563
+ loadMeta();
564
+ };
565
+ t8 = [
566
+ location.pathname,
567
+ defaultTitle,
568
+ defaultMeta,
569
+ pagesMeta
570
+ ];
571
+ $[6] = defaultMeta;
572
+ $[7] = defaultTitle;
573
+ $[8] = location.pathname;
574
+ $[9] = pagesMeta;
575
+ $[10] = t7;
576
+ $[11] = t8;
577
+ } else {
578
+ t7 = $[10];
579
+ t8 = $[11];
580
+ }
581
+ useEffect(t7, t8);
692
582
  };
693
583
  function _temp(tag) {
694
- return tag.remove();
584
+ return tag.remove();
695
585
  }
696
586
  function _temp2(meta) {
697
- const metaElement = document.createElement("meta");
698
- metaElement.setAttribute("data-react-meta", "true");
699
- Object.entries(meta).forEach((t0) => {
700
- const [key, value] = t0;
701
- if (value) {
702
- metaElement.setAttribute(key, value.toString());
703
- }
704
- });
705
- document.head.appendChild(metaElement);
587
+ const metaElement = document.createElement("meta");
588
+ metaElement.setAttribute("data-react-meta", "true");
589
+ Object.entries(meta).forEach((t0) => {
590
+ const [key, value] = t0;
591
+ if (value) metaElement.setAttribute(key, value.toString());
592
+ });
593
+ document.head.appendChild(metaElement);
706
594
  }
707
- const NAVIGATION_GUARDS_STORE_KEY = "__rpcbaseNavigationGuardsStore";
708
- const getNavigationGuardsStore = () => {
709
- const globalAny = globalThis;
710
- const existing = globalAny[NAVIGATION_GUARDS_STORE_KEY];
711
- if (existing) {
712
- return existing;
713
- }
714
- const created = {
715
- guards: /* @__PURE__ */ new Map(),
716
- listeners: /* @__PURE__ */ new Set()
717
- };
718
- globalAny[NAVIGATION_GUARDS_STORE_KEY] = created;
719
- return created;
720
- };
721
- const notify = () => {
722
- getNavigationGuardsStore().listeners.forEach((listener) => {
723
- listener();
724
- });
595
+ //#endregion
596
+ //#region src/navigationGuards.ts
597
+ var NAVIGATION_GUARDS_STORE_KEY = "__rpcbaseNavigationGuardsStore";
598
+ var getNavigationGuardsStore = () => {
599
+ const globalAny = globalThis;
600
+ const existing = globalAny[NAVIGATION_GUARDS_STORE_KEY];
601
+ if (existing) return existing;
602
+ const created = {
603
+ guards: /* @__PURE__ */ new Map(),
604
+ listeners: /* @__PURE__ */ new Set()
605
+ };
606
+ globalAny[NAVIGATION_GUARDS_STORE_KEY] = created;
607
+ return created;
725
608
  };
726
- const isSameGuard = (a, b) => a.id === b.id && a.enabled === b.enabled && a.priority === b.priority && a.message === b.message && a.blockOnSearch === b.blockOnSearch && a.shouldBlockNavigation === b.shouldBlockNavigation && a.shouldBlockUnload === b.shouldBlockUnload;
727
- const upsertNavigationGuard = (guard) => {
728
- const guards = getNavigationGuardsStore().guards;
729
- const prev = guards.get(guard.id);
730
- if (prev && isSameGuard(prev, guard)) {
731
- return;
732
- }
733
- guards.set(guard.id, guard);
734
- notify();
609
+ var notify = () => {
610
+ getNavigationGuardsStore().listeners.forEach((listener) => {
611
+ listener();
612
+ });
735
613
  };
736
- const removeNavigationGuard = (id) => {
737
- const guards = getNavigationGuardsStore().guards;
738
- const didDelete = guards.delete(id);
739
- if (didDelete) {
740
- notify();
741
- }
614
+ var isSameGuard = (a, b) => a.id === b.id && a.enabled === b.enabled && a.priority === b.priority && a.message === b.message && a.blockOnSearch === b.blockOnSearch && a.shouldBlockNavigation === b.shouldBlockNavigation && a.shouldBlockUnload === b.shouldBlockUnload;
615
+ var upsertNavigationGuard = (guard) => {
616
+ const guards = getNavigationGuardsStore().guards;
617
+ const prev = guards.get(guard.id);
618
+ if (prev && isSameGuard(prev, guard)) return;
619
+ guards.set(guard.id, guard);
620
+ notify();
742
621
  };
743
- const getNavigationGuards = () => Array.from(getNavigationGuardsStore().guards.values());
744
- const subscribeNavigationGuards = (listener) => {
745
- const listeners = getNavigationGuardsStore().listeners;
746
- listeners.add(listener);
747
- return () => {
748
- listeners.delete(listener);
749
- };
622
+ var removeNavigationGuard = (id) => {
623
+ if (getNavigationGuardsStore().guards.delete(id)) notify();
750
624
  };
751
- const useRegisterNavigationGuard = (guard) => {
752
- const latestGuardRef = useRef(guard);
753
- latestGuardRef.current = guard;
754
- const lastIdRef = useRef(null);
755
- useEffect(() => {
756
- const lastId = lastIdRef.current;
757
- if (lastId && lastId !== guard.id) {
758
- removeNavigationGuard(lastId);
759
- }
760
- lastIdRef.current = guard.id;
761
- if (!guard.enabled) {
762
- removeNavigationGuard(guard.id);
763
- return;
764
- }
765
- upsertNavigationGuard(latestGuardRef.current);
766
- return () => {
767
- removeNavigationGuard(guard.id);
768
- };
769
- }, [guard.id, guard.enabled, guard.message, guard.priority, guard.blockOnSearch, guard.shouldBlockNavigation, guard.shouldBlockUnload]);
625
+ var getNavigationGuards = () => Array.from(getNavigationGuardsStore().guards.values());
626
+ var subscribeNavigationGuards = (listener) => {
627
+ const listeners = getNavigationGuardsStore().listeners;
628
+ listeners.add(listener);
629
+ return () => {
630
+ listeners.delete(listener);
631
+ };
770
632
  };
771
- const useQueryOverlay = (t0) => {
772
- const $ = c(21);
773
- const {
774
- param,
775
- parse
776
- } = t0;
777
- const location = useLocation();
778
- const navigate = useNavigate();
779
- let t1;
780
- if ($[0] !== location.hash || $[1] !== location.pathname || $[2] !== location.search || $[3] !== param) {
781
- t1 = (nextValue) => {
782
- const searchParams = new URLSearchParams(location.search);
783
- if (nextValue === null) {
784
- searchParams.delete(param);
785
- } else {
786
- searchParams.set(param, nextValue);
787
- }
788
- const nextSearch = searchParams.toString();
789
- return `${location.pathname}${nextSearch ? `?${nextSearch}` : ""}${location.hash}`;
790
- };
791
- $[0] = location.hash;
792
- $[1] = location.pathname;
793
- $[2] = location.search;
794
- $[3] = param;
795
- $[4] = t1;
796
- } else {
797
- t1 = $[4];
798
- }
799
- const buildHref = t1;
800
- let t2;
801
- if ($[5] !== location.search || $[6] !== param || $[7] !== parse) {
802
- t2 = parse(new URLSearchParams(location.search).get(param));
803
- $[5] = location.search;
804
- $[6] = param;
805
- $[7] = parse;
806
- $[8] = t2;
807
- } else {
808
- t2 = $[8];
809
- }
810
- const value = t2;
811
- let t3;
812
- if ($[9] !== buildHref || $[10] !== navigate) {
813
- t3 = (nextValue_0) => {
814
- navigate(buildHref(nextValue_0), {
815
- replace: true
816
- });
817
- };
818
- $[9] = buildHref;
819
- $[10] = navigate;
820
- $[11] = t3;
821
- } else {
822
- t3 = $[11];
823
- }
824
- const openOverlay = t3;
825
- let t4;
826
- if ($[12] !== buildHref || $[13] !== navigate) {
827
- t4 = () => {
828
- navigate(buildHref(null), {
829
- replace: true
830
- });
831
- };
832
- $[12] = buildHref;
833
- $[13] = navigate;
834
- $[14] = t4;
835
- } else {
836
- t4 = $[14];
837
- }
838
- const closeOverlay = t4;
839
- const t5 = value !== null;
840
- let t6;
841
- if ($[15] !== buildHref || $[16] !== closeOverlay || $[17] !== openOverlay || $[18] !== t5 || $[19] !== value) {
842
- t6 = {
843
- value,
844
- isOpen: t5,
845
- buildHref,
846
- openOverlay,
847
- closeOverlay
848
- };
849
- $[15] = buildHref;
850
- $[16] = closeOverlay;
851
- $[17] = openOverlay;
852
- $[18] = t5;
853
- $[19] = value;
854
- $[20] = t6;
855
- } else {
856
- t6 = $[20];
857
- }
858
- return t6;
633
+ var useRegisterNavigationGuard = (guard) => {
634
+ const latestGuardRef = useRef(guard);
635
+ latestGuardRef.current = guard;
636
+ const lastIdRef = useRef(null);
637
+ useEffect(() => {
638
+ const lastId = lastIdRef.current;
639
+ if (lastId && lastId !== guard.id) removeNavigationGuard(lastId);
640
+ lastIdRef.current = guard.id;
641
+ if (!guard.enabled) {
642
+ removeNavigationGuard(guard.id);
643
+ return;
644
+ }
645
+ upsertNavigationGuard(latestGuardRef.current);
646
+ return () => {
647
+ removeNavigationGuard(guard.id);
648
+ };
649
+ }, [
650
+ guard.id,
651
+ guard.enabled,
652
+ guard.message,
653
+ guard.priority,
654
+ guard.blockOnSearch,
655
+ guard.shouldBlockNavigation,
656
+ guard.shouldBlockUnload
657
+ ]);
859
658
  };
860
- const normalizeKey = (key) => key.toLowerCase();
861
- const defaultIsTypingTarget = (target) => {
862
- const element = target;
863
- const tagName = element?.tagName;
864
- return element?.isContentEditable === true || tagName === "INPUT" || tagName === "TEXTAREA" || tagName === "SELECT";
659
+ //#endregion
660
+ //#region src/queryOverlay.ts
661
+ var useQueryOverlay = (t0) => {
662
+ const $ = c(21);
663
+ const { param, parse } = t0;
664
+ const location = useLocation();
665
+ const navigate = useNavigate();
666
+ let t1;
667
+ if ($[0] !== location.hash || $[1] !== location.pathname || $[2] !== location.search || $[3] !== param) {
668
+ t1 = (nextValue) => {
669
+ const searchParams = new URLSearchParams(location.search);
670
+ if (nextValue === null) searchParams.delete(param);
671
+ else searchParams.set(param, nextValue);
672
+ const nextSearch = searchParams.toString();
673
+ return `${location.pathname}${nextSearch ? `?${nextSearch}` : ""}${location.hash}`;
674
+ };
675
+ $[0] = location.hash;
676
+ $[1] = location.pathname;
677
+ $[2] = location.search;
678
+ $[3] = param;
679
+ $[4] = t1;
680
+ } else t1 = $[4];
681
+ const buildHref = t1;
682
+ let t2;
683
+ if ($[5] !== location.search || $[6] !== param || $[7] !== parse) {
684
+ t2 = parse(new URLSearchParams(location.search).get(param));
685
+ $[5] = location.search;
686
+ $[6] = param;
687
+ $[7] = parse;
688
+ $[8] = t2;
689
+ } else t2 = $[8];
690
+ const value = t2;
691
+ let t3;
692
+ if ($[9] !== buildHref || $[10] !== navigate) {
693
+ t3 = (nextValue_0) => {
694
+ navigate(buildHref(nextValue_0), { replace: true });
695
+ };
696
+ $[9] = buildHref;
697
+ $[10] = navigate;
698
+ $[11] = t3;
699
+ } else t3 = $[11];
700
+ const openOverlay = t3;
701
+ let t4;
702
+ if ($[12] !== buildHref || $[13] !== navigate) {
703
+ t4 = () => {
704
+ navigate(buildHref(null), { replace: true });
705
+ };
706
+ $[12] = buildHref;
707
+ $[13] = navigate;
708
+ $[14] = t4;
709
+ } else t4 = $[14];
710
+ const closeOverlay = t4;
711
+ const t5 = value !== null;
712
+ let t6;
713
+ if ($[15] !== buildHref || $[16] !== closeOverlay || $[17] !== openOverlay || $[18] !== t5 || $[19] !== value) {
714
+ t6 = {
715
+ value,
716
+ isOpen: t5,
717
+ buildHref,
718
+ openOverlay,
719
+ closeOverlay
720
+ };
721
+ $[15] = buildHref;
722
+ $[16] = closeOverlay;
723
+ $[17] = openOverlay;
724
+ $[18] = t5;
725
+ $[19] = value;
726
+ $[20] = t6;
727
+ } else t6 = $[20];
728
+ return t6;
865
729
  };
866
- const matchesShortcutKeyDown = (event, shortcut) => {
867
- if (normalizeKey(event.key) !== normalizeKey(shortcut.key)) return false;
868
- if (typeof shortcut.mod === "boolean") {
869
- const hasMod = event.metaKey || event.ctrlKey;
870
- if (hasMod !== shortcut.mod) return false;
871
- }
872
- if (typeof shortcut.ctrl === "boolean" && event.ctrlKey !== shortcut.ctrl) return false;
873
- if (typeof shortcut.meta === "boolean" && event.metaKey !== shortcut.meta) return false;
874
- if (typeof shortcut.alt === "boolean" && event.altKey !== shortcut.alt) return false;
875
- if (typeof shortcut.shift === "boolean" && event.shiftKey !== shortcut.shift) return false;
876
- return true;
730
+ //#endregion
731
+ //#region src/shortcutPrefetchNavigate.ts
732
+ var normalizeKey = (key) => key.toLowerCase();
733
+ var defaultIsTypingTarget = (target) => {
734
+ const element = target;
735
+ const tagName = element?.tagName;
736
+ return element?.isContentEditable === true || tagName === "INPUT" || tagName === "TEXTAREA" || tagName === "SELECT";
877
737
  };
878
- const callMaybeAsync = (fn, href) => {
879
- if (!fn) return;
880
- void Promise.resolve(fn(href));
738
+ var matchesShortcutKeyDown = (event, shortcut) => {
739
+ if (normalizeKey(event.key) !== normalizeKey(shortcut.key)) return false;
740
+ if (typeof shortcut.mod === "boolean") {
741
+ if ((event.metaKey || event.ctrlKey) !== shortcut.mod) return false;
742
+ }
743
+ if (typeof shortcut.ctrl === "boolean" && event.ctrlKey !== shortcut.ctrl) return false;
744
+ if (typeof shortcut.meta === "boolean" && event.metaKey !== shortcut.meta) return false;
745
+ if (typeof shortcut.alt === "boolean" && event.altKey !== shortcut.alt) return false;
746
+ if (typeof shortcut.shift === "boolean" && event.shiftKey !== shortcut.shift) return false;
747
+ return true;
881
748
  };
882
- const useShortcutPrefetchNavigate = ({
883
- shortcut,
884
- getHref,
885
- prefetch,
886
- navigate,
887
- trigger = "keyup",
888
- enabled = true,
889
- preventDefault = true,
890
- ignoreTypingTarget = true,
891
- isTypingTarget = defaultIsTypingTarget
892
- }) => {
893
- const routerNavigate = useNavigate();
894
- const shortcutRef = useRef(shortcut);
895
- const getHrefRef = useRef(getHref);
896
- const prefetchRef = useRef(prefetch);
897
- const navigateRef = useRef(navigate ?? routerNavigate);
898
- const triggerRef = useRef(trigger);
899
- const enabledRef = useRef(enabled);
900
- const preventDefaultRef = useRef(preventDefault);
901
- const ignoreTypingTargetRef = useRef(ignoreTypingTarget);
902
- const isTypingTargetRef = useRef(isTypingTarget);
903
- const waitingForShortcutKeyUpRef = useRef(false);
904
- shortcutRef.current = shortcut;
905
- getHrefRef.current = getHref;
906
- prefetchRef.current = prefetch;
907
- navigateRef.current = navigate ?? routerNavigate;
908
- triggerRef.current = trigger;
909
- enabledRef.current = enabled;
910
- preventDefaultRef.current = preventDefault;
911
- ignoreTypingTargetRef.current = ignoreTypingTarget;
912
- isTypingTargetRef.current = isTypingTarget;
913
- if (!enabled || trigger !== "keyup") {
914
- waitingForShortcutKeyUpRef.current = false;
915
- }
916
- useEffect(() => {
917
- if (typeof window === "undefined") return;
918
- const onKeyDown = (event) => {
919
- if (!enabledRef.current) return;
920
- if (ignoreTypingTargetRef.current && isTypingTargetRef.current(event.target)) return;
921
- if (event.repeat) return;
922
- if (!matchesShortcutKeyDown(event, shortcutRef.current)) return;
923
- if (preventDefaultRef.current) {
924
- event.preventDefault();
925
- }
926
- const href = getHrefRef.current();
927
- if (!href) return;
928
- callMaybeAsync(prefetchRef.current, href);
929
- if (triggerRef.current === "keydown") {
930
- callMaybeAsync(navigateRef.current, href);
931
- return;
932
- }
933
- waitingForShortcutKeyUpRef.current = true;
934
- };
935
- const onKeyUp = (event_0) => {
936
- if (!enabledRef.current) return;
937
- if (triggerRef.current !== "keyup") return;
938
- if (!waitingForShortcutKeyUpRef.current) return;
939
- if (normalizeKey(event_0.key) !== normalizeKey(shortcutRef.current.key)) return;
940
- waitingForShortcutKeyUpRef.current = false;
941
- if (ignoreTypingTargetRef.current && isTypingTargetRef.current(event_0.target)) return;
942
- if (preventDefaultRef.current) {
943
- event_0.preventDefault();
944
- }
945
- const href_0 = getHrefRef.current();
946
- if (!href_0) return;
947
- callMaybeAsync(navigateRef.current, href_0);
948
- };
949
- const onBlur = () => {
950
- waitingForShortcutKeyUpRef.current = false;
951
- };
952
- window.addEventListener("keydown", onKeyDown);
953
- window.addEventListener("keyup", onKeyUp);
954
- window.addEventListener("blur", onBlur);
955
- return () => {
956
- window.removeEventListener("keydown", onKeyDown);
957
- window.removeEventListener("keyup", onKeyUp);
958
- window.removeEventListener("blur", onBlur);
959
- };
960
- }, []);
749
+ var callMaybeAsync = (fn, href) => {
750
+ if (!fn) return;
751
+ Promise.resolve(fn(href));
961
752
  };
962
- export {
963
- Link,
964
- RoutePrefetchProvider,
965
- getNavigationGuards,
966
- lazyRoute,
967
- removeNavigationGuard,
968
- subscribeNavigationGuards,
969
- upsertNavigationGuard,
970
- useApplyMeta,
971
- useQueryOverlay,
972
- useRegisterNavigationGuard,
973
- useRoutePrefetch,
974
- useShortcutPrefetchNavigate
753
+ var useShortcutPrefetchNavigate = ({ shortcut, getHref, prefetch, navigate, trigger = "keyup", enabled = true, preventDefault = true, ignoreTypingTarget = true, isTypingTarget = defaultIsTypingTarget }) => {
754
+ const routerNavigate = useNavigate();
755
+ const shortcutRef = useRef(shortcut);
756
+ const getHrefRef = useRef(getHref);
757
+ const prefetchRef = useRef(prefetch);
758
+ const navigateRef = useRef(navigate ?? routerNavigate);
759
+ const triggerRef = useRef(trigger);
760
+ const enabledRef = useRef(enabled);
761
+ const preventDefaultRef = useRef(preventDefault);
762
+ const ignoreTypingTargetRef = useRef(ignoreTypingTarget);
763
+ const isTypingTargetRef = useRef(isTypingTarget);
764
+ const waitingForShortcutKeyUpRef = useRef(false);
765
+ shortcutRef.current = shortcut;
766
+ getHrefRef.current = getHref;
767
+ prefetchRef.current = prefetch;
768
+ navigateRef.current = navigate ?? routerNavigate;
769
+ triggerRef.current = trigger;
770
+ enabledRef.current = enabled;
771
+ preventDefaultRef.current = preventDefault;
772
+ ignoreTypingTargetRef.current = ignoreTypingTarget;
773
+ isTypingTargetRef.current = isTypingTarget;
774
+ if (!enabled || trigger !== "keyup") waitingForShortcutKeyUpRef.current = false;
775
+ useEffect(() => {
776
+ if (typeof window === "undefined") return;
777
+ const onKeyDown = (event) => {
778
+ if (!enabledRef.current) return;
779
+ if (ignoreTypingTargetRef.current && isTypingTargetRef.current(event.target)) return;
780
+ if (event.repeat) return;
781
+ if (!matchesShortcutKeyDown(event, shortcutRef.current)) return;
782
+ if (preventDefaultRef.current) event.preventDefault();
783
+ const href = getHrefRef.current();
784
+ if (!href) return;
785
+ callMaybeAsync(prefetchRef.current, href);
786
+ if (triggerRef.current === "keydown") {
787
+ callMaybeAsync(navigateRef.current, href);
788
+ return;
789
+ }
790
+ waitingForShortcutKeyUpRef.current = true;
791
+ };
792
+ const onKeyUp = (event_0) => {
793
+ if (!enabledRef.current) return;
794
+ if (triggerRef.current !== "keyup") return;
795
+ if (!waitingForShortcutKeyUpRef.current) return;
796
+ if (normalizeKey(event_0.key) !== normalizeKey(shortcutRef.current.key)) return;
797
+ waitingForShortcutKeyUpRef.current = false;
798
+ if (ignoreTypingTargetRef.current && isTypingTargetRef.current(event_0.target)) return;
799
+ if (preventDefaultRef.current) event_0.preventDefault();
800
+ const href_0 = getHrefRef.current();
801
+ if (!href_0) return;
802
+ callMaybeAsync(navigateRef.current, href_0);
803
+ };
804
+ const onBlur = () => {
805
+ waitingForShortcutKeyUpRef.current = false;
806
+ };
807
+ window.addEventListener("keydown", onKeyDown);
808
+ window.addEventListener("keyup", onKeyUp);
809
+ window.addEventListener("blur", onBlur);
810
+ return () => {
811
+ window.removeEventListener("keydown", onKeyDown);
812
+ window.removeEventListener("keyup", onKeyUp);
813
+ window.removeEventListener("blur", onBlur);
814
+ };
815
+ }, []);
975
816
  };
976
- //# sourceMappingURL=index.js.map
817
+ //#endregion
818
+ export { Link, RoutePrefetchProvider, getNavigationGuards, lazyRoute, removeNavigationGuard, subscribeNavigationGuards, upsertNavigationGuard, useApplyMeta, useQueryOverlay, useRegisterNavigationGuard, useRoutePrefetch, useShortcutPrefetchNavigate };
819
+
820
+ //# sourceMappingURL=index.js.map