@flight-framework/router 0.3.1 → 0.3.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.
@@ -1,461 +1,465 @@
1
- import {
2
- __commonJS,
3
- __require,
4
- clearPrefetchCache,
5
- findRoute,
6
- generatePath,
7
- getRouterContext,
8
- initRouter,
9
- isActive,
10
- isPrefetched,
11
- matchRoute,
12
- navigate,
13
- observeForPrefetch,
14
- parseParams,
15
- prefetch,
16
- prefetchAll,
17
- prefetchPages,
18
- prefetchWhenIdle,
19
- redirect,
20
- setupIntentPrefetch,
21
- subscribe
22
- } from "../chunk-6WPAKUMC.js";
23
-
24
- // ../../node_modules/.pnpm/react-dom@19.2.3_react@19.2.3/node_modules/react-dom/cjs/react-dom.production.js
25
- var require_react_dom_production = __commonJS({
26
- "../../node_modules/.pnpm/react-dom@19.2.3_react@19.2.3/node_modules/react-dom/cjs/react-dom.production.js"(exports) {
27
- "use strict";
28
- var React3 = __require("react");
29
- function formatProdErrorMessage(code) {
30
- var url = "https://react.dev/errors/" + code;
31
- if (1 < arguments.length) {
32
- url += "?args[]=" + encodeURIComponent(arguments[1]);
33
- for (var i = 2; i < arguments.length; i++)
34
- url += "&args[]=" + encodeURIComponent(arguments[i]);
35
- }
36
- return "Minified React error #" + code + "; visit " + url + " for the full message or use the non-minified dev environment for full errors and additional helpful warnings.";
37
- }
38
- function noop() {
39
- }
40
- var Internals = {
41
- d: {
42
- f: noop,
43
- r: function() {
44
- throw Error(formatProdErrorMessage(522));
45
- },
46
- D: noop,
47
- C: noop,
48
- L: noop,
49
- m: noop,
50
- X: noop,
51
- S: noop,
52
- M: noop
53
- },
54
- p: 0,
55
- findDOMNode: null
56
- };
57
- var REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal");
58
- function createPortal$1(children, containerInfo, implementation) {
59
- var key = 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null;
60
- return {
61
- $$typeof: REACT_PORTAL_TYPE,
62
- key: null == key ? null : "" + key,
63
- children,
64
- containerInfo,
65
- implementation
66
- };
67
- }
68
- var ReactSharedInternals = React3.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
69
- function getCrossOriginStringAs(as, input) {
70
- if ("font" === as) return "";
71
- if ("string" === typeof input)
72
- return "use-credentials" === input ? input : "";
73
- }
74
- exports.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = Internals;
75
- exports.createPortal = function(children, container) {
76
- var key = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : null;
77
- if (!container || 1 !== container.nodeType && 9 !== container.nodeType && 11 !== container.nodeType)
78
- throw Error(formatProdErrorMessage(299));
79
- return createPortal$1(children, container, null, key);
80
- };
81
- exports.flushSync = function(fn) {
82
- var previousTransition = ReactSharedInternals.T, previousUpdatePriority = Internals.p;
83
- try {
84
- if (ReactSharedInternals.T = null, Internals.p = 2, fn) return fn();
85
- } finally {
86
- ReactSharedInternals.T = previousTransition, Internals.p = previousUpdatePriority, Internals.d.f();
87
- }
88
- };
89
- exports.preconnect = function(href, options) {
90
- "string" === typeof href && (options ? (options = options.crossOrigin, options = "string" === typeof options ? "use-credentials" === options ? options : "" : void 0) : options = null, Internals.d.C(href, options));
91
- };
92
- exports.prefetchDNS = function(href) {
93
- "string" === typeof href && Internals.d.D(href);
94
- };
95
- exports.preinit = function(href, options) {
96
- if ("string" === typeof href && options && "string" === typeof options.as) {
97
- var as = options.as, crossOrigin = getCrossOriginStringAs(as, options.crossOrigin), integrity = "string" === typeof options.integrity ? options.integrity : void 0, fetchPriority = "string" === typeof options.fetchPriority ? options.fetchPriority : void 0;
98
- "style" === as ? Internals.d.S(
99
- href,
100
- "string" === typeof options.precedence ? options.precedence : void 0,
101
- {
102
- crossOrigin,
103
- integrity,
104
- fetchPriority
105
- }
106
- ) : "script" === as && Internals.d.X(href, {
107
- crossOrigin,
108
- integrity,
109
- fetchPriority,
110
- nonce: "string" === typeof options.nonce ? options.nonce : void 0
1
+ // src/context.ts
2
+ var isBrowser = typeof window !== "undefined";
3
+ var currentContext = {
4
+ path: "/",
5
+ searchParams: new URLSearchParams(),
6
+ navigate: () => {
7
+ },
8
+ back: () => {
9
+ },
10
+ forward: () => {
11
+ }
12
+ };
13
+ var subscribers = /* @__PURE__ */ new Set();
14
+ function subscribe(callback) {
15
+ subscribers.add(callback);
16
+ return () => subscribers.delete(callback);
17
+ }
18
+ function getRouterContext() {
19
+ return currentContext;
20
+ }
21
+ function updateContext(updates) {
22
+ currentContext = { ...currentContext, ...updates };
23
+ subscribers.forEach((cb) => cb(currentContext));
24
+ }
25
+ function navigateTo(to, options = {}) {
26
+ if (!isBrowser) return;
27
+ const { replace = false, scroll = true, state } = options;
28
+ if (replace) {
29
+ window.history.replaceState(state ?? null, "", to);
30
+ } else {
31
+ window.history.pushState(state ?? null, "", to);
32
+ }
33
+ const url = new URL(to, window.location.origin);
34
+ updateContext({
35
+ path: url.pathname,
36
+ searchParams: url.searchParams
37
+ });
38
+ if (scroll) {
39
+ window.scrollTo({ top: 0, left: 0, behavior: "instant" });
40
+ }
41
+ }
42
+ function initRouter(options = {}) {
43
+ const { initialPath, basePath = "" } = options;
44
+ let path;
45
+ let searchParams;
46
+ if (isBrowser) {
47
+ path = window.location.pathname;
48
+ searchParams = new URLSearchParams(window.location.search);
49
+ } else {
50
+ path = initialPath || "/";
51
+ searchParams = new URLSearchParams();
52
+ }
53
+ if (basePath && path.startsWith(basePath)) {
54
+ path = path.slice(basePath.length) || "/";
55
+ }
56
+ currentContext = {
57
+ path,
58
+ searchParams,
59
+ navigate: navigateTo,
60
+ back: () => isBrowser && window.history.back(),
61
+ forward: () => isBrowser && window.history.forward()
62
+ };
63
+ if (isBrowser) {
64
+ window.addEventListener("popstate", () => {
65
+ updateContext({
66
+ path: window.location.pathname,
67
+ searchParams: new URLSearchParams(window.location.search)
68
+ });
69
+ });
70
+ const originalPushState = history.pushState.bind(history);
71
+ const originalReplaceState = history.replaceState.bind(history);
72
+ history.pushState = function(state, unused, url) {
73
+ originalPushState(state, unused, url);
74
+ if (url) {
75
+ const newUrl = new URL(url.toString(), window.location.origin);
76
+ updateContext({
77
+ path: newUrl.pathname,
78
+ searchParams: newUrl.searchParams
111
79
  });
112
80
  }
113
81
  };
114
- exports.preinitModule = function(href, options) {
115
- if ("string" === typeof href)
116
- if ("object" === typeof options && null !== options) {
117
- if (null == options.as || "script" === options.as) {
118
- var crossOrigin = getCrossOriginStringAs(
119
- options.as,
120
- options.crossOrigin
121
- );
122
- Internals.d.M(href, {
123
- crossOrigin,
124
- integrity: "string" === typeof options.integrity ? options.integrity : void 0,
125
- nonce: "string" === typeof options.nonce ? options.nonce : void 0
126
- });
127
- }
128
- } else null == options && Internals.d.M(href);
129
- };
130
- exports.preload = function(href, options) {
131
- if ("string" === typeof href && "object" === typeof options && null !== options && "string" === typeof options.as) {
132
- var as = options.as, crossOrigin = getCrossOriginStringAs(as, options.crossOrigin);
133
- Internals.d.L(href, as, {
134
- crossOrigin,
135
- integrity: "string" === typeof options.integrity ? options.integrity : void 0,
136
- nonce: "string" === typeof options.nonce ? options.nonce : void 0,
137
- type: "string" === typeof options.type ? options.type : void 0,
138
- fetchPriority: "string" === typeof options.fetchPriority ? options.fetchPriority : void 0,
139
- referrerPolicy: "string" === typeof options.referrerPolicy ? options.referrerPolicy : void 0,
140
- imageSrcSet: "string" === typeof options.imageSrcSet ? options.imageSrcSet : void 0,
141
- imageSizes: "string" === typeof options.imageSizes ? options.imageSizes : void 0,
142
- media: "string" === typeof options.media ? options.media : void 0
82
+ history.replaceState = function(state, unused, url) {
83
+ originalReplaceState(state, unused, url);
84
+ if (url) {
85
+ const newUrl = new URL(url.toString(), window.location.origin);
86
+ updateContext({
87
+ path: newUrl.pathname,
88
+ searchParams: newUrl.searchParams
143
89
  });
144
90
  }
145
91
  };
146
- exports.preloadModule = function(href, options) {
147
- if ("string" === typeof href)
148
- if (options) {
149
- var crossOrigin = getCrossOriginStringAs(options.as, options.crossOrigin);
150
- Internals.d.m(href, {
151
- as: "string" === typeof options.as && "script" !== options.as ? options.as : void 0,
152
- crossOrigin,
153
- integrity: "string" === typeof options.integrity ? options.integrity : void 0
154
- });
155
- } else Internals.d.m(href);
156
- };
157
- exports.requestFormReset = function(form) {
158
- Internals.d.r(form);
159
- };
160
- exports.unstable_batchedUpdates = function(fn, a) {
161
- return fn(a);
162
- };
163
- exports.useFormState = function(action, initialState, permalink) {
164
- return ReactSharedInternals.H.useFormState(action, initialState, permalink);
165
- };
166
- exports.useFormStatus = function() {
167
- return ReactSharedInternals.H.useHostTransitionStatus();
168
- };
169
- exports.version = "19.2.3";
170
92
  }
171
- });
172
-
173
- // ../../node_modules/.pnpm/react-dom@19.2.3_react@19.2.3/node_modules/react-dom/cjs/react-dom.development.js
174
- var require_react_dom_development = __commonJS({
175
- "../../node_modules/.pnpm/react-dom@19.2.3_react@19.2.3/node_modules/react-dom/cjs/react-dom.development.js"(exports) {
176
- "use strict";
177
- "production" !== process.env.NODE_ENV && (function() {
178
- function noop() {
179
- }
180
- function testStringCoercion(value) {
181
- return "" + value;
182
- }
183
- function createPortal$1(children, containerInfo, implementation) {
184
- var key = 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null;
185
- try {
186
- testStringCoercion(key);
187
- var JSCompiler_inline_result = false;
188
- } catch (e) {
189
- JSCompiler_inline_result = true;
190
- }
191
- JSCompiler_inline_result && (console.error(
192
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
193
- "function" === typeof Symbol && Symbol.toStringTag && key[Symbol.toStringTag] || key.constructor.name || "Object"
194
- ), testStringCoercion(key));
195
- return {
196
- $$typeof: REACT_PORTAL_TYPE,
197
- key: null == key ? null : "" + key,
198
- children,
199
- containerInfo,
200
- implementation
201
- };
202
- }
203
- function getCrossOriginStringAs(as, input) {
204
- if ("font" === as) return "";
205
- if ("string" === typeof input)
206
- return "use-credentials" === input ? input : "";
207
- }
208
- function getValueDescriptorExpectingObjectForWarning(thing) {
209
- return null === thing ? "`null`" : void 0 === thing ? "`undefined`" : "" === thing ? "an empty string" : 'something with type "' + typeof thing + '"';
210
- }
211
- function getValueDescriptorExpectingEnumForWarning(thing) {
212
- return null === thing ? "`null`" : void 0 === thing ? "`undefined`" : "" === thing ? "an empty string" : "string" === typeof thing ? JSON.stringify(thing) : "number" === typeof thing ? "`" + thing + "`" : 'something with type "' + typeof thing + '"';
213
- }
214
- function resolveDispatcher() {
215
- var dispatcher = ReactSharedInternals.H;
216
- null === dispatcher && console.error(
217
- "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem."
218
- );
219
- return dispatcher;
220
- }
221
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
222
- var React3 = __require("react"), Internals = {
223
- d: {
224
- f: noop,
225
- r: function() {
226
- throw Error(
227
- "Invalid form element. requestFormReset must be passed a form that was rendered by React."
228
- );
229
- },
230
- D: noop,
231
- C: noop,
232
- L: noop,
233
- m: noop,
234
- X: noop,
235
- S: noop,
236
- M: noop
237
- },
238
- p: 0,
239
- findDOMNode: null
240
- }, REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal"), ReactSharedInternals = React3.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
241
- "function" === typeof Map && null != Map.prototype && "function" === typeof Map.prototype.forEach && "function" === typeof Set && null != Set.prototype && "function" === typeof Set.prototype.clear && "function" === typeof Set.prototype.forEach || console.error(
242
- "React depends on Map and Set built-in types. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills"
243
- );
244
- exports.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = Internals;
245
- exports.createPortal = function(children, container) {
246
- var key = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : null;
247
- if (!container || 1 !== container.nodeType && 9 !== container.nodeType && 11 !== container.nodeType)
248
- throw Error("Target container is not a DOM element.");
249
- return createPortal$1(children, container, null, key);
250
- };
251
- exports.flushSync = function(fn) {
252
- var previousTransition = ReactSharedInternals.T, previousUpdatePriority = Internals.p;
253
- try {
254
- if (ReactSharedInternals.T = null, Internals.p = 2, fn)
255
- return fn();
256
- } finally {
257
- ReactSharedInternals.T = previousTransition, Internals.p = previousUpdatePriority, Internals.d.f() && console.error(
258
- "flushSync was called from inside a lifecycle method. React cannot flush when React is already rendering. Consider moving this call to a scheduler task or micro task."
259
- );
260
- }
261
- };
262
- exports.preconnect = function(href, options) {
263
- "string" === typeof href && href ? null != options && "object" !== typeof options ? console.error(
264
- "ReactDOM.preconnect(): Expected the `options` argument (second) to be an object but encountered %s instead. The only supported option at this time is `crossOrigin` which accepts a string.",
265
- getValueDescriptorExpectingEnumForWarning(options)
266
- ) : null != options && "string" !== typeof options.crossOrigin && console.error(
267
- "ReactDOM.preconnect(): Expected the `crossOrigin` option (second argument) to be a string but encountered %s instead. Try removing this option or passing a string value instead.",
268
- getValueDescriptorExpectingObjectForWarning(options.crossOrigin)
269
- ) : console.error(
270
- "ReactDOM.preconnect(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.",
271
- getValueDescriptorExpectingObjectForWarning(href)
272
- );
273
- "string" === typeof href && (options ? (options = options.crossOrigin, options = "string" === typeof options ? "use-credentials" === options ? options : "" : void 0) : options = null, Internals.d.C(href, options));
274
- };
275
- exports.prefetchDNS = function(href) {
276
- if ("string" !== typeof href || !href)
277
- console.error(
278
- "ReactDOM.prefetchDNS(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.",
279
- getValueDescriptorExpectingObjectForWarning(href)
280
- );
281
- else if (1 < arguments.length) {
282
- var options = arguments[1];
283
- "object" === typeof options && options.hasOwnProperty("crossOrigin") ? console.error(
284
- "ReactDOM.prefetchDNS(): Expected only one argument, `href`, but encountered %s as a second argument instead. This argument is reserved for future options and is currently disallowed. It looks like the you are attempting to set a crossOrigin property for this DNS lookup hint. Browsers do not perform DNS queries using CORS and setting this attribute on the resource hint has no effect. Try calling ReactDOM.prefetchDNS() with just a single string argument, `href`.",
285
- getValueDescriptorExpectingEnumForWarning(options)
286
- ) : console.error(
287
- "ReactDOM.prefetchDNS(): Expected only one argument, `href`, but encountered %s as a second argument instead. This argument is reserved for future options and is currently disallowed. Try calling ReactDOM.prefetchDNS() with just a single string argument, `href`.",
288
- getValueDescriptorExpectingEnumForWarning(options)
289
- );
290
- }
291
- "string" === typeof href && Internals.d.D(href);
292
- };
293
- exports.preinit = function(href, options) {
294
- "string" === typeof href && href ? null == options || "object" !== typeof options ? console.error(
295
- "ReactDOM.preinit(): Expected the `options` argument (second) to be an object with an `as` property describing the type of resource to be preinitialized but encountered %s instead.",
296
- getValueDescriptorExpectingEnumForWarning(options)
297
- ) : "style" !== options.as && "script" !== options.as && console.error(
298
- 'ReactDOM.preinit(): Expected the `as` property in the `options` argument (second) to contain a valid value describing the type of resource to be preinitialized but encountered %s instead. Valid values for `as` are "style" and "script".',
299
- getValueDescriptorExpectingEnumForWarning(options.as)
300
- ) : console.error(
301
- "ReactDOM.preinit(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.",
302
- getValueDescriptorExpectingObjectForWarning(href)
303
- );
304
- if ("string" === typeof href && options && "string" === typeof options.as) {
305
- var as = options.as, crossOrigin = getCrossOriginStringAs(as, options.crossOrigin), integrity = "string" === typeof options.integrity ? options.integrity : void 0, fetchPriority = "string" === typeof options.fetchPriority ? options.fetchPriority : void 0;
306
- "style" === as ? Internals.d.S(
307
- href,
308
- "string" === typeof options.precedence ? options.precedence : void 0,
309
- {
310
- crossOrigin,
311
- integrity,
312
- fetchPriority
93
+ }
94
+ var initialized = false;
95
+ if (isBrowser && !initialized) {
96
+ initialized = true;
97
+ initRouter();
98
+ }
99
+ var RouterContext = null;
100
+ var RouterProvider = null;
101
+ var useRouter = getRouterContext;
102
+ if (typeof globalThis !== "undefined") {
103
+ try {
104
+ const React3 = globalThis.React;
105
+ if (React3?.createContext) {
106
+ const { createContext: createContext2, useState: useState2, useEffect: useEffect3, useContext: useContext3 } = React3;
107
+ const ReactRouterContext = createContext2(currentContext);
108
+ RouterContext = ReactRouterContext;
109
+ RouterProvider = function FlightRouterProvider({
110
+ children,
111
+ initialPath,
112
+ basePath = ""
113
+ }) {
114
+ const [routerState, setRouterState] = useState2(() => {
115
+ const path = isBrowser ? window.location.pathname : initialPath || "/";
116
+ const searchParams = isBrowser ? new URLSearchParams(window.location.search) : new URLSearchParams();
117
+ return {
118
+ path: basePath && path.startsWith(basePath) ? path.slice(basePath.length) || "/" : path,
119
+ searchParams,
120
+ navigate: navigateTo,
121
+ back: () => isBrowser && window.history.back(),
122
+ forward: () => isBrowser && window.history.forward()
123
+ };
124
+ });
125
+ useEffect3(() => {
126
+ if (!isBrowser) return;
127
+ const handlePopState = () => {
128
+ let path = window.location.pathname;
129
+ if (basePath && path.startsWith(basePath)) {
130
+ path = path.slice(basePath.length) || "/";
313
131
  }
314
- ) : "script" === as && Internals.d.X(href, {
315
- crossOrigin,
316
- integrity,
317
- fetchPriority,
318
- nonce: "string" === typeof options.nonce ? options.nonce : void 0
132
+ setRouterState((prev) => ({
133
+ ...prev,
134
+ path,
135
+ searchParams: new URLSearchParams(window.location.search)
136
+ }));
137
+ };
138
+ window.addEventListener("popstate", handlePopState);
139
+ return () => window.removeEventListener("popstate", handlePopState);
140
+ }, [basePath]);
141
+ useEffect3(() => {
142
+ return subscribe((ctx) => {
143
+ setRouterState((prev) => ({
144
+ ...prev,
145
+ path: ctx.path,
146
+ searchParams: ctx.searchParams
147
+ }));
319
148
  });
320
- }
321
- };
322
- exports.preinitModule = function(href, options) {
323
- var encountered = "";
324
- "string" === typeof href && href || (encountered += " The `href` argument encountered was " + getValueDescriptorExpectingObjectForWarning(href) + ".");
325
- void 0 !== options && "object" !== typeof options ? encountered += " The `options` argument encountered was " + getValueDescriptorExpectingObjectForWarning(options) + "." : options && "as" in options && "script" !== options.as && (encountered += " The `as` option encountered was " + getValueDescriptorExpectingEnumForWarning(options.as) + ".");
326
- if (encountered)
327
- console.error(
328
- "ReactDOM.preinitModule(): Expected up to two arguments, a non-empty `href` string and, optionally, an `options` object with a valid `as` property.%s",
329
- encountered
330
- );
331
- else
332
- switch (encountered = options && "string" === typeof options.as ? options.as : "script", encountered) {
333
- case "script":
334
- break;
335
- default:
336
- encountered = getValueDescriptorExpectingEnumForWarning(encountered), console.error(
337
- 'ReactDOM.preinitModule(): Currently the only supported "as" type for this function is "script" but received "%s" instead. This warning was generated for `href` "%s". In the future other module types will be supported, aligning with the import-attributes proposal. Learn more here: (https://github.com/tc39/proposal-import-attributes)',
338
- encountered,
339
- href
340
- );
341
- }
342
- if ("string" === typeof href)
343
- if ("object" === typeof options && null !== options) {
344
- if (null == options.as || "script" === options.as)
345
- encountered = getCrossOriginStringAs(
346
- options.as,
347
- options.crossOrigin
348
- ), Internals.d.M(href, {
349
- crossOrigin: encountered,
350
- integrity: "string" === typeof options.integrity ? options.integrity : void 0,
351
- nonce: "string" === typeof options.nonce ? options.nonce : void 0
352
- });
353
- } else null == options && Internals.d.M(href);
354
- };
355
- exports.preload = function(href, options) {
356
- var encountered = "";
357
- "string" === typeof href && href || (encountered += " The `href` argument encountered was " + getValueDescriptorExpectingObjectForWarning(href) + ".");
358
- null == options || "object" !== typeof options ? encountered += " The `options` argument encountered was " + getValueDescriptorExpectingObjectForWarning(options) + "." : "string" === typeof options.as && options.as || (encountered += " The `as` option encountered was " + getValueDescriptorExpectingObjectForWarning(options.as) + ".");
359
- encountered && console.error(
360
- 'ReactDOM.preload(): Expected two arguments, a non-empty `href` string and an `options` object with an `as` property valid for a `<link rel="preload" as="..." />` tag.%s',
361
- encountered
149
+ }, []);
150
+ return React3.createElement(
151
+ ReactRouterContext.Provider,
152
+ { value: routerState },
153
+ children
362
154
  );
363
- if ("string" === typeof href && "object" === typeof options && null !== options && "string" === typeof options.as) {
364
- encountered = options.as;
365
- var crossOrigin = getCrossOriginStringAs(
366
- encountered,
367
- options.crossOrigin
368
- );
369
- Internals.d.L(href, encountered, {
370
- crossOrigin,
371
- integrity: "string" === typeof options.integrity ? options.integrity : void 0,
372
- nonce: "string" === typeof options.nonce ? options.nonce : void 0,
373
- type: "string" === typeof options.type ? options.type : void 0,
374
- fetchPriority: "string" === typeof options.fetchPriority ? options.fetchPriority : void 0,
375
- referrerPolicy: "string" === typeof options.referrerPolicy ? options.referrerPolicy : void 0,
376
- imageSrcSet: "string" === typeof options.imageSrcSet ? options.imageSrcSet : void 0,
377
- imageSizes: "string" === typeof options.imageSizes ? options.imageSizes : void 0,
378
- media: "string" === typeof options.media ? options.media : void 0
379
- });
380
- }
381
155
  };
382
- exports.preloadModule = function(href, options) {
383
- var encountered = "";
384
- "string" === typeof href && href || (encountered += " The `href` argument encountered was " + getValueDescriptorExpectingObjectForWarning(href) + ".");
385
- void 0 !== options && "object" !== typeof options ? encountered += " The `options` argument encountered was " + getValueDescriptorExpectingObjectForWarning(options) + "." : options && "as" in options && "string" !== typeof options.as && (encountered += " The `as` option encountered was " + getValueDescriptorExpectingObjectForWarning(options.as) + ".");
386
- encountered && console.error(
387
- 'ReactDOM.preloadModule(): Expected two arguments, a non-empty `href` string and, optionally, an `options` object with an `as` property valid for a `<link rel="modulepreload" as="..." />` tag.%s',
388
- encountered
389
- );
390
- "string" === typeof href && (options ? (encountered = getCrossOriginStringAs(
391
- options.as,
392
- options.crossOrigin
393
- ), Internals.d.m(href, {
394
- as: "string" === typeof options.as && "script" !== options.as ? options.as : void 0,
395
- crossOrigin: encountered,
396
- integrity: "string" === typeof options.integrity ? options.integrity : void 0
397
- })) : Internals.d.m(href));
398
- };
399
- exports.requestFormReset = function(form) {
400
- Internals.d.r(form);
401
- };
402
- exports.unstable_batchedUpdates = function(fn, a) {
403
- return fn(a);
156
+ useRouter = function useFlightRouter() {
157
+ return useContext3(ReactRouterContext);
404
158
  };
405
- exports.useFormState = function(action, initialState, permalink) {
406
- return resolveDispatcher().useFormState(action, initialState, permalink);
407
- };
408
- exports.useFormStatus = function() {
409
- return resolveDispatcher().useHostTransitionStatus();
159
+ }
160
+ } catch {
161
+ }
162
+ }
163
+
164
+ // src/navigate.ts
165
+ var isBrowser2 = typeof window !== "undefined";
166
+ function navigate(to, options = {}) {
167
+ const { navigate: routerNavigate } = getRouterContext();
168
+ routerNavigate(to, options);
169
+ }
170
+ function patternToRegex(pattern) {
171
+ const paramNames = [];
172
+ let regexStr = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\\\[\.\.\.(\w+)\\\]/g, (_, name) => {
173
+ paramNames.push(name);
174
+ return "(.+)";
175
+ }).replace(/\\\[(\w+)\\\]/g, (_, name) => {
176
+ paramNames.push(name);
177
+ return "([^/]+)";
178
+ }).replace(/:(\w+)/g, (_, name) => {
179
+ paramNames.push(name);
180
+ return "([^/]+)";
181
+ });
182
+ regexStr = `^${regexStr}$`;
183
+ return {
184
+ regex: new RegExp(regexStr),
185
+ paramNames
186
+ };
187
+ }
188
+ function matchRoute(pathname, pattern) {
189
+ const { regex, paramNames } = patternToRegex(pattern);
190
+ const match = pathname.match(regex);
191
+ if (!match) {
192
+ return { matched: false, params: {} };
193
+ }
194
+ const params = {};
195
+ paramNames.forEach((name, index) => {
196
+ params[name] = match[index + 1] || "";
197
+ });
198
+ return { matched: true, params };
199
+ }
200
+ function parseParams(pathname, pattern) {
201
+ const { params } = matchRoute(pathname, pattern);
202
+ return params;
203
+ }
204
+ function findRoute(pathname, routes) {
205
+ for (const route of routes) {
206
+ const { matched, params } = matchRoute(pathname, route.path);
207
+ if (matched) {
208
+ return {
209
+ route,
210
+ params,
211
+ pathname
410
212
  };
411
- exports.version = "19.2.3";
412
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
413
- })();
213
+ }
214
+ }
215
+ return null;
216
+ }
217
+ function generatePath(pattern, params = {}) {
218
+ let path = pattern;
219
+ path = path.replace(/\[(\w+)\]/g, (_, name) => {
220
+ return params[name] || "";
221
+ });
222
+ path = path.replace(/:(\w+)/g, (_, name) => {
223
+ return params[name] || "";
224
+ });
225
+ return path;
226
+ }
227
+ function isActive(pattern) {
228
+ const { path } = getRouterContext();
229
+ const { matched } = matchRoute(path, pattern);
230
+ return matched;
231
+ }
232
+ function redirect(url) {
233
+ if (isBrowser2) {
234
+ window.location.href = url;
414
235
  }
415
- });
236
+ throw new Error(`Redirect to: ${url}`);
237
+ }
416
238
 
417
- // ../../node_modules/.pnpm/react-dom@19.2.3_react@19.2.3/node_modules/react-dom/index.js
418
- var require_react_dom = __commonJS({
419
- "../../node_modules/.pnpm/react-dom@19.2.3_react@19.2.3/node_modules/react-dom/index.js"(exports, module) {
420
- "use strict";
421
- function checkDCE() {
422
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined" || typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE !== "function") {
423
- return;
424
- }
425
- if (process.env.NODE_ENV !== "production") {
426
- throw new Error("^_^");
427
- }
428
- try {
429
- __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(checkDCE);
430
- } catch (err) {
431
- console.error(err);
239
+ // src/prefetch.ts
240
+ var isBrowser3 = typeof window !== "undefined";
241
+ var supportsIntersectionObserver = isBrowser3 && "IntersectionObserver" in window;
242
+ var prefetchedUrls = /* @__PURE__ */ new Set();
243
+ var prefetchingUrls = /* @__PURE__ */ new Set();
244
+ var viewportObservers = /* @__PURE__ */ new Map();
245
+ function prefetch(href, options = {}) {
246
+ if (!isBrowser3) return;
247
+ const {
248
+ priority = "auto",
249
+ includeModules = true,
250
+ includeData = false
251
+ } = options;
252
+ const url = normalizeUrl(href);
253
+ if (prefetchedUrls.has(url) || prefetchingUrls.has(url)) {
254
+ return;
255
+ }
256
+ prefetchingUrls.add(url);
257
+ createPrefetchLink(url, "document", priority);
258
+ if (includeModules) {
259
+ prefetchModules(url, priority);
260
+ }
261
+ if (includeData) {
262
+ prefetchData(url, priority);
263
+ }
264
+ prefetchedUrls.add(url);
265
+ prefetchingUrls.delete(url);
266
+ }
267
+ function prefetchAll(hrefs, options = {}) {
268
+ for (const href of hrefs) {
269
+ prefetch(href, options);
270
+ }
271
+ }
272
+ function isPrefetched(href) {
273
+ return prefetchedUrls.has(normalizeUrl(href));
274
+ }
275
+ function clearPrefetchCache() {
276
+ prefetchedUrls.clear();
277
+ prefetchingUrls.clear();
278
+ }
279
+ function createPrefetchLink(href, as, priority) {
280
+ if (!isBrowser3) return null;
281
+ const existing = document.querySelector(
282
+ `link[rel="prefetch"][href="${href}"], link[rel="modulepreload"][href="${href}"]`
283
+ );
284
+ if (existing) return existing;
285
+ const link = document.createElement("link");
286
+ if (as === "script") {
287
+ link.rel = "modulepreload";
288
+ } else {
289
+ link.rel = "prefetch";
290
+ link.as = as;
291
+ }
292
+ link.href = href;
293
+ if (priority !== "auto" && "fetchPriority" in link) {
294
+ link.fetchPriority = priority;
295
+ }
296
+ if (priority === "low" && "requestIdleCallback" in window) {
297
+ window.requestIdleCallback(() => {
298
+ document.head.appendChild(link);
299
+ });
300
+ } else {
301
+ document.head.appendChild(link);
302
+ }
303
+ return link;
304
+ }
305
+ function prefetchModules(href, priority) {
306
+ const manifest = window.__FLIGHT_MANIFEST__;
307
+ if (!manifest?.routes) return;
308
+ const routeModules = manifest.routes[href];
309
+ if (!routeModules) return;
310
+ for (const module of routeModules) {
311
+ createPrefetchLink(module, "script", priority);
312
+ }
313
+ }
314
+ function prefetchData(href, priority) {
315
+ const dataUrl = `/_flight/data${href === "/" ? "/index" : href}.json`;
316
+ createPrefetchLink(dataUrl, "fetch", priority);
317
+ }
318
+ var sharedObserver = null;
319
+ var observerCallbacks = /* @__PURE__ */ new Map();
320
+ function getViewportObserver() {
321
+ if (!supportsIntersectionObserver) return null;
322
+ if (!sharedObserver) {
323
+ sharedObserver = new IntersectionObserver(
324
+ (entries) => {
325
+ for (const entry of entries) {
326
+ if (entry.isIntersecting) {
327
+ const callback = observerCallbacks.get(entry.target);
328
+ if (callback) {
329
+ callback();
330
+ sharedObserver?.unobserve(entry.target);
331
+ observerCallbacks.delete(entry.target);
332
+ }
333
+ }
334
+ }
335
+ },
336
+ {
337
+ // Start prefetching when link is 25% visible or within 100px of viewport
338
+ rootMargin: "100px",
339
+ threshold: 0.25
432
340
  }
341
+ );
342
+ }
343
+ return sharedObserver;
344
+ }
345
+ function observeForPrefetch(element, href) {
346
+ if (!supportsIntersectionObserver) {
347
+ return () => {
348
+ };
349
+ }
350
+ const observer = getViewportObserver();
351
+ if (!observer) return () => {
352
+ };
353
+ const callback = () => {
354
+ prefetch(href, { priority: "low" });
355
+ };
356
+ observerCallbacks.set(element, callback);
357
+ observer.observe(element);
358
+ const cleanup = () => {
359
+ observer.unobserve(element);
360
+ observerCallbacks.delete(element);
361
+ viewportObservers.delete(element);
362
+ };
363
+ viewportObservers.set(element, cleanup);
364
+ return cleanup;
365
+ }
366
+ function setupIntentPrefetch(element, href) {
367
+ if (!isBrowser3) return () => {
368
+ };
369
+ let prefetchTriggered = false;
370
+ const handleIntent = () => {
371
+ if (!prefetchTriggered) {
372
+ prefetchTriggered = true;
373
+ prefetch(href, { priority: "auto" });
433
374
  }
434
- if (process.env.NODE_ENV === "production") {
435
- checkDCE();
436
- module.exports = require_react_dom_production();
437
- } else {
438
- module.exports = require_react_dom_development();
375
+ };
376
+ element.addEventListener("mouseenter", handleIntent, { passive: true });
377
+ element.addEventListener("focus", handleIntent, { passive: true });
378
+ element.addEventListener("touchstart", handleIntent, { passive: true });
379
+ return () => {
380
+ element.removeEventListener("mouseenter", handleIntent);
381
+ element.removeEventListener("focus", handleIntent);
382
+ element.removeEventListener("touchstart", handleIntent);
383
+ };
384
+ }
385
+ function normalizeUrl(href) {
386
+ if (isBrowser3 && !href.startsWith("http")) {
387
+ try {
388
+ const url = new URL(href, window.location.origin);
389
+ return url.pathname + url.search;
390
+ } catch {
391
+ return href;
439
392
  }
440
393
  }
441
- });
394
+ return href;
395
+ }
442
396
 
443
- // src/react/Link.tsx
444
- import { useCallback, useEffect, useRef } from "react";
445
- import { jsx } from "react/jsx-runtime";
446
- var isBrowser = typeof window !== "undefined";
447
- var flushSyncFn = null;
448
- if (isBrowser) {
397
+ // src/prefetch-links.ts
398
+ var isBrowser4 = typeof window !== "undefined";
399
+ var PrefetchPageLinks = null;
400
+ if (typeof globalThis !== "undefined") {
449
401
  try {
450
- const ReactDOM = require_react_dom();
451
- if (ReactDOM && "flushSync" in ReactDOM) {
452
- flushSyncFn = ReactDOM.flushSync;
402
+ const React3 = globalThis.React;
403
+ if (React3?.createElement && "useEffect" in React3) {
404
+ const { useEffect: useEffect3, useState: useState2 } = React3;
405
+ PrefetchPageLinks = function FlightPrefetchPageLinks({
406
+ page,
407
+ options = {}
408
+ }) {
409
+ const [shouldRender, setShouldRender] = useState2(false);
410
+ useEffect3(() => {
411
+ if (!isBrowser4) return;
412
+ if (isPrefetched(page)) {
413
+ return;
414
+ }
415
+ prefetch(page, {
416
+ priority: "low",
417
+ includeModules: true,
418
+ ...options
419
+ });
420
+ setShouldRender(false);
421
+ }, [page, options]);
422
+ return null;
423
+ };
453
424
  }
454
425
  } catch {
455
426
  }
456
427
  }
428
+ function prefetchPages(pages, options = {}) {
429
+ if (!isBrowser4) return;
430
+ for (const page of pages) {
431
+ if (!isPrefetched(page)) {
432
+ prefetch(page, {
433
+ priority: "low",
434
+ ...options
435
+ });
436
+ }
437
+ }
438
+ }
439
+ function prefetchWhenIdle(page, options = {}) {
440
+ if (!isBrowser4) return;
441
+ const doPrefetch = () => {
442
+ if (!isPrefetched(page)) {
443
+ prefetch(page, {
444
+ priority: "low",
445
+ ...options
446
+ });
447
+ }
448
+ };
449
+ if ("requestIdleCallback" in window) {
450
+ window.requestIdleCallback(doPrefetch, { timeout: 3e3 });
451
+ } else {
452
+ setTimeout(doPrefetch, 100);
453
+ }
454
+ }
455
+
456
+ // src/react/Link.tsx
457
+ import { useCallback, useEffect, useRef } from "react";
458
+ import { flushSync } from "react-dom";
459
+ import { jsx } from "react/jsx-runtime";
460
+ var isBrowser5 = typeof window !== "undefined";
457
461
  function isViewTransitionSupported() {
458
- return isBrowser && "startViewTransition" in document;
462
+ return isBrowser5 && "startViewTransition" in document;
459
463
  }
460
464
  function isExternalUrl(href) {
461
465
  if (!href) return false;
@@ -478,18 +482,14 @@ function handleLinkClick(href, options, event) {
478
482
  const { viewTransition, ...navOptions } = options;
479
483
  if (viewTransition && isViewTransitionSupported()) {
480
484
  document.startViewTransition(() => {
481
- if (flushSyncFn) {
482
- flushSyncFn(() => {
483
- navigate2(href, navOptions);
484
- });
485
- } else {
485
+ flushSync(() => {
486
486
  navigate2(href, navOptions);
487
- }
487
+ });
488
488
  });
489
489
  } else {
490
490
  navigate2(href, navOptions);
491
491
  }
492
- if (options.scroll !== false && isBrowser) {
492
+ if (options.scroll !== false && isBrowser5) {
493
493
  window.scrollTo({ top: 0, left: 0, behavior: "instant" });
494
494
  }
495
495
  }
@@ -522,7 +522,7 @@ function Link({
522
522
  [href, isExternal, target, replace, scroll, viewTransition, onClick]
523
523
  );
524
524
  useEffect(() => {
525
- if (isExternal || !isBrowser || prefetchStrategy === "none") {
525
+ if (isExternal || !isBrowser5 || prefetchStrategy === "none") {
526
526
  return;
527
527
  }
528
528
  const link = linkRef.current;
@@ -558,9 +558,9 @@ function Link({
558
558
  // src/react/RouterProvider.tsx
559
559
  import { createContext, useContext, useState, useEffect as useEffect2 } from "react";
560
560
  import { jsx as jsx2 } from "react/jsx-runtime";
561
- var isBrowser2 = typeof window !== "undefined";
562
- function navigateTo(to, options = {}) {
563
- if (!isBrowser2) return;
561
+ var isBrowser6 = typeof window !== "undefined";
562
+ function navigateTo2(to, options = {}) {
563
+ if (!isBrowser6) return;
564
564
  const { replace = false, scroll = true, state } = options;
565
565
  if (replace) {
566
566
  window.history.replaceState(state ?? null, "", to);
@@ -574,22 +574,22 @@ function navigateTo(to, options = {}) {
574
574
  var defaultContext = {
575
575
  path: "/",
576
576
  searchParams: new URLSearchParams(),
577
- navigate: navigateTo,
578
- back: () => isBrowser2 && window.history.back(),
579
- forward: () => isBrowser2 && window.history.forward()
577
+ navigate: navigateTo2,
578
+ back: () => isBrowser6 && window.history.back(),
579
+ forward: () => isBrowser6 && window.history.forward()
580
580
  };
581
- var RouterContext = createContext(defaultContext);
582
- function useRouter() {
583
- return useContext(RouterContext);
581
+ var RouterContext2 = createContext(defaultContext);
582
+ function useRouter2() {
583
+ return useContext(RouterContext2);
584
584
  }
585
- function RouterProvider({
585
+ function RouterProvider2({
586
586
  children,
587
587
  initialPath,
588
588
  basePath = ""
589
589
  }) {
590
590
  const [routerState, setRouterState] = useState(() => {
591
- const path = isBrowser2 ? window.location.pathname : initialPath || "/";
592
- const searchParams = isBrowser2 ? new URLSearchParams(window.location.search) : new URLSearchParams();
591
+ const path = isBrowser6 ? window.location.pathname : initialPath || "/";
592
+ const searchParams = isBrowser6 ? new URLSearchParams(window.location.search) : new URLSearchParams();
593
593
  let normalizedPath = path;
594
594
  if (basePath && path.startsWith(basePath)) {
595
595
  normalizedPath = path.slice(basePath.length) || "/";
@@ -597,13 +597,13 @@ function RouterProvider({
597
597
  return {
598
598
  path: normalizedPath,
599
599
  searchParams,
600
- navigate: navigateTo,
601
- back: () => isBrowser2 && window.history.back(),
602
- forward: () => isBrowser2 && window.history.forward()
600
+ navigate: navigateTo2,
601
+ back: () => isBrowser6 && window.history.back(),
602
+ forward: () => isBrowser6 && window.history.forward()
603
603
  };
604
604
  });
605
605
  useEffect2(() => {
606
- if (!isBrowser2) return;
606
+ if (!isBrowser6) return;
607
607
  const handlePopState = () => {
608
608
  let path = window.location.pathname;
609
609
  if (basePath && path.startsWith(basePath)) {
@@ -631,20 +631,20 @@ function RouterProvider({
631
631
  }));
632
632
  });
633
633
  }, [basePath]);
634
- return /* @__PURE__ */ jsx2(RouterContext.Provider, { value: routerState, children });
634
+ return /* @__PURE__ */ jsx2(RouterContext2.Provider, { value: routerState, children });
635
635
  }
636
636
 
637
637
  // src/react/hooks.ts
638
638
  import { useContext as useContext2, useSyncExternalStore } from "react";
639
- var isBrowser3 = typeof window !== "undefined";
639
+ var isBrowser7 = typeof window !== "undefined";
640
640
  function getPathnameSnapshot() {
641
- return isBrowser3 ? window.location.pathname : "/";
641
+ return isBrowser7 ? window.location.pathname : "/";
642
642
  }
643
643
  function getPathnameServerSnapshot() {
644
644
  return "/";
645
645
  }
646
646
  function subscribeToPathname(callback) {
647
- if (!isBrowser3) return () => {
647
+ if (!isBrowser7) return () => {
648
648
  };
649
649
  window.addEventListener("popstate", callback);
650
650
  const unsubscribe = subscribe(callback);
@@ -661,7 +661,7 @@ function usePathname() {
661
661
  );
662
662
  }
663
663
  function useSearchParams() {
664
- const { searchParams } = useContext2(RouterContext);
664
+ const { searchParams } = useContext2(RouterContext2);
665
665
  return searchParams;
666
666
  }
667
667
  function useParams() {
@@ -669,8 +669,8 @@ function useParams() {
669
669
  }
670
670
  export {
671
671
  Link,
672
- RouterContext,
673
- RouterProvider,
672
+ RouterContext2 as RouterContext,
673
+ RouterProvider2 as RouterProvider,
674
674
  clearPrefetchCache,
675
675
  findRoute,
676
676
  generatePath,
@@ -691,30 +691,6 @@ export {
691
691
  subscribe,
692
692
  useParams,
693
693
  usePathname,
694
- useRouter,
694
+ useRouter2 as useRouter,
695
695
  useSearchParams
696
696
  };
697
- /*! Bundled license information:
698
-
699
- react-dom/cjs/react-dom.production.js:
700
- (**
701
- * @license React
702
- * react-dom.production.js
703
- *
704
- * Copyright (c) Meta Platforms, Inc. and affiliates.
705
- *
706
- * This source code is licensed under the MIT license found in the
707
- * LICENSE file in the root directory of this source tree.
708
- *)
709
-
710
- react-dom/cjs/react-dom.development.js:
711
- (**
712
- * @license React
713
- * react-dom.development.js
714
- *
715
- * Copyright (c) Meta Platforms, Inc. and affiliates.
716
- *
717
- * This source code is licensed under the MIT license found in the
718
- * LICENSE file in the root directory of this source tree.
719
- *)
720
- */