@tonyclaw/llm-inspector 1.9.6 → 1.9.8

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.
Files changed (49) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/assets/index-Cc1oV0hF.css +1 -0
  3. package/.output/public/assets/index-DuukpBQJ.js +122 -0
  4. package/.output/public/assets/index-NIg9RFlA.js +11 -0
  5. package/.output/server/_chunks/ssr-renderer.mjs +1 -0
  6. package/.output/server/_libs/@radix-ui/react-use-controllable-state+[...].mjs +1 -1
  7. package/.output/server/_libs/ajv-formats.mjs +18 -18
  8. package/.output/server/_libs/ajv.mjs +196 -196
  9. package/.output/server/_libs/cookie-es.mjs +7 -21
  10. package/.output/server/_libs/h3-v2.mjs +18 -7
  11. package/.output/server/_libs/h3.mjs +24 -16
  12. package/.output/server/_libs/jszip.mjs +28 -28
  13. package/.output/server/_libs/pako.mjs +13 -13
  14. package/.output/server/_libs/radix-ui__react-collection.mjs +1 -1
  15. package/.output/server/_libs/radix-ui__react-id.mjs +1 -1
  16. package/.output/server/_libs/react-dom.mjs +5 -5
  17. package/.output/server/_libs/react.mjs +43 -43
  18. package/.output/server/_libs/readable-stream.mjs +15 -15
  19. package/.output/server/_libs/safe-buffer.mjs +3 -3
  20. package/.output/server/_libs/semver.mjs +10 -10
  21. package/.output/server/_libs/seroval-plugins.mjs +5 -5
  22. package/.output/server/_libs/seroval.mjs +606 -596
  23. package/.output/server/_libs/srvx.mjs +110 -46
  24. package/.output/server/_libs/swr.mjs +1 -1
  25. package/.output/server/_libs/tanstack__history.mjs +31 -44
  26. package/.output/server/_libs/tanstack__react-router.mjs +781 -1090
  27. package/.output/server/_libs/tanstack__router-core.mjs +2223 -2328
  28. package/.output/server/_libs/tslib.mjs +5 -5
  29. package/.output/server/_libs/use-sync-external-store.mjs +1 -1
  30. package/.output/server/_libs/zod.mjs +503 -205
  31. package/.output/server/_ssr/empty-plugin-adapters-BFgPZ6_d.mjs +6 -0
  32. package/.output/server/_ssr/{index--OdB29Fv.mjs → index-BnKtV0Rq.mjs} +31 -13
  33. package/.output/server/_ssr/index.mjs +1100 -777
  34. package/.output/server/_ssr/{router-CY_hgLPo.mjs → router-CQ7QyRWm.mjs} +26 -7
  35. package/.output/server/_tanstack-start-manifest_v-CKgCX0Gs.mjs +4 -0
  36. package/.output/server/index.mjs +28 -27
  37. package/README.md +50 -11
  38. package/package.json +1 -1
  39. package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +35 -2
  40. package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +25 -11
  41. package/src/proxy/formats/openai/schemas.ts +6 -0
  42. package/src/proxy/formats/openai/stream.ts +8 -0
  43. package/src/proxy/handler.ts +6 -2
  44. package/.output/public/assets/index-Bjuk3Pry.css +0 -1
  45. package/.output/public/assets/index-DtK6Ymig.js +0 -97
  46. package/.output/public/assets/main-ClWp6y0D.js +0 -17
  47. package/.output/server/_libs/tiny-invariant.mjs +0 -12
  48. package/.output/server/_libs/tiny-warning.mjs +0 -5
  49. package/.output/server/_tanstack-start-manifest_v-bpFJzmyh.mjs +0 -4
@@ -1,36 +1,40 @@
1
- import { j as jsxRuntimeExports, r as reactExports, R as React, a as React$1 } from "./react.mjs";
2
- import { w as warning } from "./tiny-warning.mjs";
3
- import { i as isNotFound, d as defaultGetScrollRestorationKey, r as restoreScroll, e as escapeHtml, s as storageKey, a as rootRouteId, b as isRedirect, g as getLocationChangeInfo, t as transformReadableStreamWithRouter, c as transformPipeableStreamWithRouter, f as isDangerousProtocol, h as exactPathTest, j as removeTrailingSlash, k as deepEqual, l as functionalUpdate, B as BaseRootRoute, m as BaseRoute, n as isModuleNotFoundError, R as RouterCore } from "./tanstack__router-core.mjs";
4
- import { i as invariant } from "./tiny-invariant.mjs";
5
- import { PassThrough } from "node:stream";
1
+ import { i as invariant, a as isDangerousProtocol, e as exactPathTest, r as removeTrailingSlash, h as hasKeys, d as deepEqual, f as functionalUpdate, B as BaseRootRoute, b as BaseRoute, c as isModuleNotFoundError, g as isNotFound, j as getScrollRestorationScriptForRouter, k as rootRouteId, l as isServer, m as isRedirect, n as createNonReactiveReadonlyStore, o as createNonReactiveMutableStore, R as RouterCore, p as escapeHtml, q as getAssetCrossOrigin, s as getScriptPreloadAttrs, t as appendUniqueUserTags, u as resolveManifestCssLink, v as transformReadableStreamWithRouter, w as createSsrStreamResponse, x as transformPipeableStreamWithRouter } from "./tanstack__router-core.mjs";
2
+ import { r as reactExports, j as jsxRuntimeExports, R as React } from "./react.mjs";
6
3
  import { R as ReactDOMServer } from "./react-dom.mjs";
4
+ import { PassThrough } from "node:stream";
7
5
  import { i as isbot } from "./isbot.mjs";
6
+ var reactUse = reactExports.use;
7
+ function useForwardedRef(ref) {
8
+ const innerRef = reactExports.useRef(null);
9
+ reactExports.useImperativeHandle(ref, () => innerRef.current, []);
10
+ return innerRef;
11
+ }
8
12
  function CatchBoundary(props) {
9
13
  const errorComponent = props.errorComponent ?? ErrorComponent;
10
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
11
- CatchBoundaryImpl,
12
- {
13
- getResetKey: props.getResetKey,
14
- onCatch: props.onCatch,
15
- children: ({ error, reset }) => {
16
- if (error) {
17
- return reactExports.createElement(errorComponent, {
18
- error,
19
- reset
20
- });
21
- }
22
- return props.children;
23
- }
14
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(CatchBoundaryImpl, {
15
+ getResetKey: props.getResetKey,
16
+ onCatch: props.onCatch,
17
+ children: ({ error, reset }) => {
18
+ if (error) return reactExports.createElement(errorComponent, {
19
+ error,
20
+ reset
21
+ });
22
+ return props.children;
24
23
  }
25
- );
24
+ });
26
25
  }
27
- class CatchBoundaryImpl extends reactExports.Component {
28
- constructor() {
29
- super(...arguments);
26
+ var CatchBoundaryImpl = class extends reactExports.Component {
27
+ constructor(..._args) {
28
+ super(..._args);
30
29
  this.state = { error: null };
31
30
  }
32
- static getDerivedStateFromProps(props) {
33
- return { resetKey: props.getResetKey() };
31
+ static getDerivedStateFromProps(props, state) {
32
+ const resetKey = props.getResetKey();
33
+ if (state.error && state.resetKey !== resetKey) return {
34
+ resetKey,
35
+ error: null
36
+ };
37
+ return { resetKey };
34
38
  }
35
39
  static getDerivedStateFromError(error) {
36
40
  return { error };
@@ -38,33 +42,36 @@ class CatchBoundaryImpl extends reactExports.Component {
38
42
  reset() {
39
43
  this.setState({ error: null });
40
44
  }
41
- componentDidUpdate(prevProps, prevState) {
42
- if (prevState.error && prevState.resetKey !== this.state.resetKey) {
43
- this.reset();
44
- }
45
- }
46
45
  componentDidCatch(error, errorInfo) {
47
- if (this.props.onCatch) {
48
- this.props.onCatch(error, errorInfo);
49
- }
46
+ if (this.props.onCatch) this.props.onCatch(error, errorInfo);
50
47
  }
51
48
  render() {
52
49
  return this.props.children({
53
- error: this.state.resetKey !== this.props.getResetKey() ? null : this.state.error,
50
+ error: this.state.error,
54
51
  reset: () => {
55
52
  this.reset();
56
53
  }
57
54
  });
58
55
  }
59
- }
56
+ };
60
57
  function ErrorComponent({ error }) {
61
58
  const [show, setShow] = reactExports.useState(false);
62
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { padding: ".5rem", maxWidth: "100%" }, children: [
63
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { display: "flex", alignItems: "center", gap: ".5rem" }, children: [
64
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { style: { fontSize: "1rem" }, children: "Something went wrong!" }),
65
- /* @__PURE__ */ jsxRuntimeExports.jsx(
66
- "button",
67
- {
59
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", {
60
+ style: {
61
+ padding: ".5rem",
62
+ maxWidth: "100%"
63
+ },
64
+ children: [
65
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", {
66
+ style: {
67
+ display: "flex",
68
+ alignItems: "center",
69
+ gap: ".5rem"
70
+ },
71
+ children: [/* @__PURE__ */ jsxRuntimeExports.jsx("strong", {
72
+ style: { fontSize: "1rem" },
73
+ children: "Something went wrong!"
74
+ }), /* @__PURE__ */ jsxRuntimeExports.jsx("button", {
68
75
  style: {
69
76
  appearance: "none",
70
77
  fontSize: ".6em",
@@ -75,13 +82,10 @@ function ErrorComponent({ error }) {
75
82
  },
76
83
  onClick: () => setShow((d) => !d),
77
84
  children: show ? "Hide Error" : "Show Error"
78
- }
79
- )
80
- ] }),
81
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { height: ".25rem" } }),
82
- show ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
83
- "pre",
84
- {
85
+ })]
86
+ }),
87
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { height: ".25rem" } }),
88
+ show ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("pre", {
85
89
  style: {
86
90
  fontSize: ".7em",
87
91
  border: "1px solid red",
@@ -91,496 +95,40 @@ function ErrorComponent({ error }) {
91
95
  overflow: "auto"
92
96
  },
93
97
  children: error.message ? /* @__PURE__ */ jsxRuntimeExports.jsx("code", { children: error.message }) : null
94
- }
95
- ) }) : null
96
- ] });
97
- }
98
- const routerContext = reactExports.createContext(null);
99
- function getRouterContext() {
100
- if (typeof document === "undefined") {
101
- return routerContext;
102
- }
103
- if (window.__TSR_ROUTER_CONTEXT__) {
104
- return window.__TSR_ROUTER_CONTEXT__;
105
- }
106
- window.__TSR_ROUTER_CONTEXT__ = routerContext;
107
- return routerContext;
108
- }
109
- function useRouter(opts) {
110
- const value = reactExports.useContext(getRouterContext());
111
- warning(
112
- !((opts?.warn ?? true) && !value)
113
- );
114
- return value;
115
- }
116
- function useRouterState(opts) {
117
- const contextRouter = useRouter({
118
- warn: opts?.router === void 0
119
- });
120
- const router = opts?.router || contextRouter;
121
- {
122
- const state = router.state;
123
- return opts?.select ? opts.select(state) : state;
124
- }
125
- }
126
- const REACT_USE = "use";
127
- const reactUse = React[REACT_USE];
128
- function useForwardedRef(ref) {
129
- const innerRef = reactExports.useRef(null);
130
- reactExports.useImperativeHandle(ref, () => innerRef.current, []);
131
- return innerRef;
132
- }
133
- const matchContext = reactExports.createContext(void 0);
134
- const dummyMatchContext = reactExports.createContext(
135
- void 0
136
- );
137
- function CatchNotFound(props) {
138
- const resetKey = useRouterState({
139
- select: (s) => `not-found-${s.location.pathname}-${s.status}`
98
+ }) }) : null
99
+ ]
140
100
  });
141
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
142
- CatchBoundary,
143
- {
144
- getResetKey: () => resetKey,
145
- onCatch: (error, errorInfo) => {
146
- if (isNotFound(error)) {
147
- props.onCatch?.(error, errorInfo);
148
- } else {
149
- throw error;
150
- }
151
- },
152
- errorComponent: ({ error }) => {
153
- if (isNotFound(error)) {
154
- return props.fallback?.(error);
155
- } else {
156
- throw error;
157
- }
158
- },
159
- children: props.children
160
- }
161
- );
162
- }
163
- function DefaultGlobalNotFound() {
164
- return /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: "Not Found" });
165
- }
166
- function SafeFragment(props) {
167
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: props.children });
168
- }
169
- function renderRouteNotFound(router, route, data) {
170
- if (!route.options.notFoundComponent) {
171
- if (router.options.defaultNotFoundComponent) {
172
- return /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.defaultNotFoundComponent, { ...data });
173
- }
174
- return /* @__PURE__ */ jsxRuntimeExports.jsx(DefaultGlobalNotFound, {});
175
- }
176
- return /* @__PURE__ */ jsxRuntimeExports.jsx(route.options.notFoundComponent, { ...data });
177
- }
178
- function ScriptOnce({ children }) {
179
- const router = useRouter();
180
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
181
- "script",
182
- {
183
- nonce: router.options.ssr?.nonce,
184
- dangerouslySetInnerHTML: {
185
- __html: children + ";document.currentScript.remove()"
186
- }
187
- }
188
- );
189
- }
190
- function ScrollRestoration() {
191
- const router = useRouter();
192
- if (!router.isScrollRestoring || false) {
193
- return null;
194
- }
195
- if (typeof router.options.scrollRestoration === "function") {
196
- const shouldRestore = router.options.scrollRestoration({
197
- location: router.latestLocation
198
- });
199
- if (!shouldRestore) {
200
- return null;
201
- }
202
- }
203
- const getKey = router.options.getScrollRestorationKey || defaultGetScrollRestorationKey;
204
- const userKey = getKey(router.latestLocation);
205
- const resolvedKey = userKey !== defaultGetScrollRestorationKey(router.latestLocation) ? userKey : void 0;
206
- const restoreScrollOptions = {
207
- storageKey,
208
- shouldScrollRestoration: true
209
- };
210
- if (resolvedKey) {
211
- restoreScrollOptions.key = resolvedKey;
212
- }
213
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
214
- ScriptOnce,
215
- {
216
- children: `(${restoreScroll.toString()})(${escapeHtml(JSON.stringify(restoreScrollOptions))})`
217
- }
218
- );
219
101
  }
220
102
  function ClientOnly({ children, fallback = null }) {
221
- return useHydrated() ? /* @__PURE__ */ jsxRuntimeExports.jsx(React$1.Fragment, { children }) : /* @__PURE__ */ jsxRuntimeExports.jsx(React$1.Fragment, { children: fallback });
103
+ return useHydrated() ? /* @__PURE__ */ jsxRuntimeExports.jsx(React.Fragment, { children }) : /* @__PURE__ */ jsxRuntimeExports.jsx(React.Fragment, { children: fallback });
222
104
  }
223
105
  function useHydrated() {
224
- return React$1.useSyncExternalStore(
225
- subscribe,
226
- () => true,
227
- () => false
228
- );
106
+ return React.useSyncExternalStore(subscribe, () => true, () => false);
229
107
  }
230
108
  function subscribe() {
231
109
  return () => {
232
110
  };
233
111
  }
234
- const Match = reactExports.memo(function MatchImpl({
235
- matchId
236
- }) {
237
- const router = useRouter();
238
- const matchState = useRouterState({
239
- select: (s) => {
240
- const matchIndex = s.matches.findIndex((d) => d.id === matchId);
241
- const match = s.matches[matchIndex];
242
- invariant(
243
- match
244
- );
245
- return {
246
- routeId: match.routeId,
247
- ssr: match.ssr,
248
- _displayPending: match._displayPending,
249
- resetKey: s.loadedAt,
250
- parentRouteId: s.matches[matchIndex - 1]?.routeId
251
- };
252
- },
253
- structuralSharing: true
254
- });
255
- const route = router.routesById[matchState.routeId];
256
- const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent;
257
- const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(PendingComponent, {}) : null;
258
- const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent;
259
- const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch;
260
- const routeNotFoundComponent = route.isRoot ? (
261
- // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component
262
- route.options.notFoundComponent ?? router.options.notFoundRoute?.options.component
263
- ) : route.options.notFoundComponent;
264
- const resolvedNoSsr = matchState.ssr === false || matchState.ssr === "data-only";
265
- const ResolvedSuspenseBoundary = (
266
- // If we're on the root route, allow forcefully wrapping in suspense
267
- (!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) && (route.options.wrapInSuspense ?? PendingComponent ?? (route.options.errorComponent?.preload || resolvedNoSsr)) ? reactExports.Suspense : SafeFragment
268
- );
269
- const ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary : SafeFragment;
270
- const ResolvedNotFoundBoundary = routeNotFoundComponent ? CatchNotFound : SafeFragment;
271
- const ShellComponent = route.isRoot ? route.options.shellComponent ?? SafeFragment : SafeFragment;
272
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(ShellComponent, { children: [
273
- /* @__PURE__ */ jsxRuntimeExports.jsx(matchContext.Provider, { value: matchId, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResolvedSuspenseBoundary, { fallback: pendingElement, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
274
- ResolvedCatchBoundary,
275
- {
276
- getResetKey: () => matchState.resetKey,
277
- errorComponent: routeErrorComponent || ErrorComponent,
278
- onCatch: (error, errorInfo) => {
279
- if (isNotFound(error)) throw error;
280
- routeOnCatch?.(error, errorInfo);
281
- },
282
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
283
- ResolvedNotFoundBoundary,
284
- {
285
- fallback: (error) => {
286
- if (!routeNotFoundComponent || error.routeId && error.routeId !== matchState.routeId || !error.routeId && !route.isRoot)
287
- throw error;
288
- return reactExports.createElement(routeNotFoundComponent, error);
289
- },
290
- children: resolvedNoSsr || matchState._displayPending ? /* @__PURE__ */ jsxRuntimeExports.jsx(ClientOnly, { fallback: pendingElement, children: /* @__PURE__ */ jsxRuntimeExports.jsx(MatchInner, { matchId }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(MatchInner, { matchId })
291
- }
292
- )
293
- }
294
- ) }) }),
295
- matchState.parentRouteId === rootRouteId && router.options.scrollRestoration ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
296
- /* @__PURE__ */ jsxRuntimeExports.jsx(OnRendered, {}),
297
- /* @__PURE__ */ jsxRuntimeExports.jsx(ScrollRestoration, {})
298
- ] }) : null
299
- ] });
300
- });
301
- function OnRendered() {
302
- const router = useRouter();
303
- const prevLocationRef = reactExports.useRef(
304
- void 0
305
- );
306
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
307
- "script",
308
- {
309
- suppressHydrationWarning: true,
310
- ref: (el) => {
311
- if (el && (prevLocationRef.current === void 0 || prevLocationRef.current.href !== router.latestLocation.href)) {
312
- router.emit({
313
- type: "onRendered",
314
- ...getLocationChangeInfo(router.state)
315
- });
316
- prevLocationRef.current = router.latestLocation;
317
- }
318
- }
319
- },
320
- router.latestLocation.state.__TSR_key
321
- );
322
- }
323
- const MatchInner = reactExports.memo(function MatchInnerImpl({
324
- matchId
325
- }) {
326
- const router = useRouter();
327
- const { match, key, routeId } = useRouterState({
328
- select: (s) => {
329
- const match2 = s.matches.find((d) => d.id === matchId);
330
- const routeId2 = match2.routeId;
331
- const remountFn = router.routesById[routeId2].options.remountDeps ?? router.options.defaultRemountDeps;
332
- const remountDeps = remountFn?.({
333
- routeId: routeId2,
334
- loaderDeps: match2.loaderDeps,
335
- params: match2._strictParams,
336
- search: match2._strictSearch
337
- });
338
- const key2 = remountDeps ? JSON.stringify(remountDeps) : void 0;
339
- return {
340
- key: key2,
341
- routeId: routeId2,
342
- match: {
343
- id: match2.id,
344
- status: match2.status,
345
- error: match2.error,
346
- invalid: match2.invalid,
347
- _forcePending: match2._forcePending,
348
- _displayPending: match2._displayPending
349
- }
350
- };
351
- },
352
- structuralSharing: true
353
- });
354
- const route = router.routesById[routeId];
355
- const out = reactExports.useMemo(() => {
356
- const Comp = route.options.component ?? router.options.defaultComponent;
357
- if (Comp) {
358
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Comp, {}, key);
359
- }
360
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Outlet, {});
361
- }, [key, route.options.component, router.options.defaultComponent]);
362
- if (match._displayPending) {
363
- throw router.getMatch(match.id)?._nonReactive.displayPendingPromise;
364
- }
365
- if (match._forcePending) {
366
- throw router.getMatch(match.id)?._nonReactive.minPendingPromise;
367
- }
368
- if (match.status === "pending") {
369
- const pendingMinMs = route.options.pendingMinMs ?? router.options.defaultPendingMinMs;
370
- if (pendingMinMs) {
371
- const routerMatch = router.getMatch(match.id);
372
- if (routerMatch && !routerMatch._nonReactive.minPendingPromise) ;
373
- }
374
- throw router.getMatch(match.id)?._nonReactive.loadPromise;
375
- }
376
- if (match.status === "notFound") {
377
- invariant(isNotFound(match.error));
378
- return renderRouteNotFound(router, route, match.error);
379
- }
380
- if (match.status === "redirected") {
381
- invariant(isRedirect(match.error));
382
- throw router.getMatch(match.id)?._nonReactive.loadPromise;
383
- }
384
- if (match.status === "error") {
385
- {
386
- const RouteErrorComponent = (route.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent;
387
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
388
- RouteErrorComponent,
389
- {
390
- error: match.error,
391
- reset: void 0,
392
- info: {
393
- componentStack: ""
394
- }
395
- }
396
- );
397
- }
398
- }
399
- return out;
400
- });
401
- const Outlet = reactExports.memo(function OutletImpl() {
402
- const router = useRouter();
403
- const matchId = reactExports.useContext(matchContext);
404
- const routeId = useRouterState({
405
- select: (s) => s.matches.find((d) => d.id === matchId)?.routeId
406
- });
407
- const route = router.routesById[routeId];
408
- const parentGlobalNotFound = useRouterState({
409
- select: (s) => {
410
- const matches = s.matches;
411
- const parentMatch = matches.find((d) => d.id === matchId);
412
- invariant(
413
- parentMatch
414
- );
415
- return parentMatch.globalNotFound;
416
- }
417
- });
418
- const childMatchId = useRouterState({
419
- select: (s) => {
420
- const matches = s.matches;
421
- const index = matches.findIndex((d) => d.id === matchId);
422
- return matches[index + 1]?.id;
423
- }
424
- });
425
- const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.defaultPendingComponent, {}) : null;
426
- if (parentGlobalNotFound) {
427
- return renderRouteNotFound(router, route, void 0);
428
- }
429
- if (!childMatchId) {
430
- return null;
431
- }
432
- const nextMatch = /* @__PURE__ */ jsxRuntimeExports.jsx(Match, { matchId: childMatchId });
433
- if (routeId === rootRouteId) {
434
- return /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.Suspense, { fallback: pendingElement, children: nextMatch });
435
- }
436
- return nextMatch;
437
- });
438
- function Matches() {
439
- const router = useRouter();
440
- const rootRoute = router.routesById[rootRouteId];
441
- const PendingComponent = rootRoute.options.pendingComponent ?? router.options.defaultPendingComponent;
442
- const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(PendingComponent, {}) : null;
443
- const ResolvedSuspense = SafeFragment;
444
- const inner = /* @__PURE__ */ jsxRuntimeExports.jsxs(ResolvedSuspense, { fallback: pendingElement, children: [
445
- false,
446
- /* @__PURE__ */ jsxRuntimeExports.jsx(MatchesInner, {})
447
- ] });
448
- return router.options.InnerWrap ? /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.InnerWrap, { children: inner }) : inner;
112
+ var routerContext = reactExports.createContext(null);
113
+ function useRouter(opts) {
114
+ const value = reactExports.useContext(routerContext);
115
+ return value;
449
116
  }
450
- function MatchesInner() {
117
+ var matchContext = reactExports.createContext(void 0);
118
+ var dummyMatchContext = reactExports.createContext(void 0);
119
+ function useMatch(opts) {
451
120
  const router = useRouter();
452
- const matchId = useRouterState({
453
- select: (s) => {
454
- return s.matches[0]?.id;
455
- }
456
- });
457
- const resetKey = useRouterState({
458
- select: (s) => s.loadedAt
459
- });
460
- const matchComponent = matchId ? /* @__PURE__ */ jsxRuntimeExports.jsx(Match, { matchId }) : null;
461
- return /* @__PURE__ */ jsxRuntimeExports.jsx(matchContext.Provider, { value: matchId, children: router.options.disableGlobalCatchBoundary ? matchComponent : /* @__PURE__ */ jsxRuntimeExports.jsx(
462
- CatchBoundary,
463
- {
464
- getResetKey: () => resetKey,
465
- errorComponent: ErrorComponent,
466
- onCatch: (error) => {
467
- warning(false, error.message || error.toString());
468
- },
469
- children: matchComponent
470
- }
471
- ) });
472
- }
473
- function RouterContextProvider({
474
- router,
475
- children,
476
- ...rest
477
- }) {
478
- if (Object.keys(rest).length > 0) {
479
- router.update({
480
- ...router.options,
481
- ...rest,
482
- context: {
483
- ...router.options.context,
484
- ...rest.context
485
- }
486
- });
487
- }
488
- const routerContext2 = getRouterContext();
489
- const provider = /* @__PURE__ */ jsxRuntimeExports.jsx(routerContext2.Provider, { value: router, children });
490
- if (router.options.Wrap) {
491
- return /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.Wrap, { children: provider });
492
- }
493
- return provider;
494
- }
495
- function RouterProvider({ router, ...rest }) {
496
- return /* @__PURE__ */ jsxRuntimeExports.jsx(RouterContextProvider, { router, ...rest, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Matches, {}) });
497
- }
498
- const renderRouterToStream = async ({
499
- request,
500
- router,
501
- responseHeaders,
502
- children
503
- }) => {
504
- if (typeof ReactDOMServer.renderToReadableStream === "function") {
505
- const stream = await ReactDOMServer.renderToReadableStream(children, {
506
- signal: request.signal,
507
- nonce: router.options.ssr?.nonce,
508
- progressiveChunkSize: Number.POSITIVE_INFINITY
509
- });
510
- if (isbot(request.headers.get("User-Agent"))) {
511
- await stream.allReady;
512
- }
513
- const responseStream = transformReadableStreamWithRouter(
514
- router,
515
- stream
516
- );
517
- return new Response(responseStream, {
518
- status: router.state.statusCode,
519
- headers: responseHeaders
520
- });
521
- }
522
- if (typeof ReactDOMServer.renderToPipeableStream === "function") {
523
- const reactAppPassthrough = new PassThrough();
524
- try {
525
- const pipeable = ReactDOMServer.renderToPipeableStream(children, {
526
- nonce: router.options.ssr?.nonce,
527
- progressiveChunkSize: Number.POSITIVE_INFINITY,
528
- ...isbot(request.headers.get("User-Agent")) ? {
529
- onAllReady() {
530
- pipeable.pipe(reactAppPassthrough);
531
- }
532
- } : {
533
- onShellReady() {
534
- pipeable.pipe(reactAppPassthrough);
535
- }
536
- },
537
- onError: (error, info) => {
538
- console.error("Error in renderToPipeableStream:", error, info);
539
- if (!reactAppPassthrough.destroyed) {
540
- reactAppPassthrough.destroy(
541
- error instanceof Error ? error : new Error(String(error))
542
- );
543
- }
544
- }
545
- });
546
- } catch (e) {
547
- console.error("Error in renderToPipeableStream:", e);
548
- reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)));
121
+ const nearestMatchId = reactExports.useContext(opts.from ? dummyMatchContext : matchContext);
122
+ const key = opts.from ?? nearestMatchId;
123
+ const matchStore = key ? opts.from ? router.stores.getRouteMatchStore(key) : router.stores.matchStores.get(key) : void 0;
124
+ {
125
+ const match = matchStore?.get();
126
+ if ((opts.shouldThrow ?? true) && !match) {
127
+ invariant();
549
128
  }
550
- const responseStream = transformPipeableStreamWithRouter(
551
- router,
552
- reactAppPassthrough
553
- );
554
- return new Response(responseStream, {
555
- status: router.state.statusCode,
556
- headers: responseHeaders
557
- });
129
+ if (match === void 0) return;
130
+ return opts.select ? opts.select(match) : match;
558
131
  }
559
- throw new Error(
560
- "No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming."
561
- );
562
- };
563
- function useMatch(opts) {
564
- const nearestMatchId = reactExports.useContext(
565
- opts.from ? dummyMatchContext : matchContext
566
- );
567
- const matchSelection = useRouterState({
568
- select: (state) => {
569
- const match = state.matches.find(
570
- (d) => opts.from ? opts.from === d.routeId : d.id === nearestMatchId
571
- );
572
- invariant(
573
- !((opts.shouldThrow ?? true) && !match),
574
- `Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`
575
- );
576
- if (match === void 0) {
577
- return void 0;
578
- }
579
- return opts.select ? opts.select(match) : match;
580
- },
581
- structuralSharing: opts.structuralSharing
582
- });
583
- return matchSelection;
584
132
  }
585
133
  function useLoaderData(opts) {
586
134
  return useMatch({
@@ -626,196 +174,121 @@ function useSearch(opts) {
626
174
  }
627
175
  function useNavigate(_defaultOpts) {
628
176
  const router = useRouter();
629
- return reactExports.useCallback(
630
- (options) => {
631
- return router.navigate({
632
- ...options,
633
- from: options.from ?? _defaultOpts?.from
634
- });
635
- },
636
- [_defaultOpts?.from, router]
637
- );
177
+ return reactExports.useCallback((options) => {
178
+ return router.navigate({
179
+ ...options,
180
+ from: options.from ?? _defaultOpts?.from
181
+ });
182
+ }, [_defaultOpts?.from, router]);
183
+ }
184
+ function useRouteContext(opts) {
185
+ return useMatch({
186
+ ...opts,
187
+ select: (match) => opts.select ? opts.select(match.context) : match.context
188
+ });
638
189
  }
639
190
  function useLinkProps(options, forwardedRef) {
640
191
  const router = useRouter();
641
192
  const innerRef = useForwardedRef(forwardedRef);
642
- const {
643
- // custom props
644
- activeProps,
645
- inactiveProps,
646
- activeOptions,
647
- to,
648
- preload: userPreload,
649
- preloadDelay: userPreloadDelay,
650
- hashScrollIntoView,
651
- replace,
652
- startTransition,
653
- resetScroll,
654
- viewTransition,
655
- // element props
656
- children,
657
- target,
658
- disabled,
659
- style,
660
- className,
661
- onClick,
662
- onFocus,
663
- onMouseEnter,
664
- onMouseLeave,
665
- onTouchStart,
666
- ignoreBlocker,
667
- // prevent these from being returned
668
- params: _params,
669
- search: _search,
670
- hash: _hash,
671
- state: _state,
672
- mask: _mask,
673
- reloadDocument: _reloadDocument,
674
- unsafeRelative: _unsafeRelative,
675
- from: _from,
676
- _fromLocation,
677
- ...propsSafeToSpread
678
- } = options;
193
+ const { activeProps, inactiveProps, activeOptions, to, preload: userPreload, preloadDelay: userPreloadDelay, preloadIntentProximity: _preloadIntentProximity, hashScrollIntoView, replace, startTransition, resetScroll, viewTransition, children, target, disabled, style, className, onClick, onBlur, onFocus, onMouseEnter, onMouseLeave, onTouchStart, ignoreBlocker, params: _params, search: _search, hash: _hash, state: _state, mask: _mask, reloadDocument: _reloadDocument, unsafeRelative: _unsafeRelative, from: _from, _fromLocation, ...propsSafeToSpread } = options;
679
194
  {
680
195
  const safeInternal = isSafeInternal(to);
681
- if (typeof to === "string" && !safeInternal && // Quick checks to avoid `new URL` in common internal-like cases
682
- to.indexOf(":") > -1) {
683
- try {
684
- new URL(to);
685
- if (isDangerousProtocol(to, router.protocolAllowlist)) {
686
- if (false) ;
687
- return {
688
- ...propsSafeToSpread,
689
- ref: innerRef,
690
- href: void 0,
691
- ...children && { children },
692
- ...target && { target },
693
- ...disabled && { disabled },
694
- ...style && { style },
695
- ...className && { className }
696
- };
697
- }
196
+ if (typeof to === "string" && !safeInternal && to.indexOf(":") > -1) try {
197
+ new URL(to);
198
+ if (isDangerousProtocol(to, router.protocolAllowlist)) {
199
+ if (false) ;
698
200
  return {
699
201
  ...propsSafeToSpread,
700
202
  ref: innerRef,
701
- href: to,
203
+ href: void 0,
702
204
  ...children && { children },
703
205
  ...target && { target },
704
206
  ...disabled && { disabled },
705
207
  ...style && { style },
706
208
  ...className && { className }
707
209
  };
708
- } catch {
709
210
  }
211
+ return {
212
+ ...propsSafeToSpread,
213
+ ref: innerRef,
214
+ href: to,
215
+ ...children && { children },
216
+ ...target && { target },
217
+ ...disabled && { disabled },
218
+ ...style && { style },
219
+ ...className && { className }
220
+ };
221
+ } catch {
710
222
  }
711
- const next2 = router.buildLocation({ ...options, from: options.from });
712
- const hrefOptionPublicHref2 = next2.maskedLocation ? next2.maskedLocation.publicHref : next2.publicHref;
713
- const hrefOptionExternal2 = next2.maskedLocation ? next2.maskedLocation.external : next2.external;
714
- const hrefOption2 = getHrefOption(
715
- hrefOptionPublicHref2,
716
- hrefOptionExternal2,
717
- router.history,
718
- disabled
719
- );
223
+ const next2 = router.buildLocation({
224
+ ...options,
225
+ from: options.from
226
+ });
227
+ const hrefOption2 = getHrefOption(next2.maskedLocation ? next2.maskedLocation.publicHref : next2.publicHref, next2.maskedLocation ? next2.maskedLocation.external : next2.external, router.history, disabled);
720
228
  const externalLink2 = (() => {
721
229
  if (hrefOption2?.external) {
722
230
  if (isDangerousProtocol(hrefOption2.href, router.protocolAllowlist)) {
723
- return void 0;
231
+ return;
724
232
  }
725
233
  return hrefOption2.href;
726
234
  }
727
235
  if (safeInternal) return void 0;
728
- if (typeof to === "string" && to.indexOf(":") > -1) {
729
- try {
730
- new URL(to);
731
- if (isDangerousProtocol(to, router.protocolAllowlist)) {
732
- if (false) ;
733
- return void 0;
734
- }
735
- return to;
736
- } catch {
236
+ if (typeof to === "string" && to.indexOf(":") > -1) try {
237
+ new URL(to);
238
+ if (isDangerousProtocol(to, router.protocolAllowlist)) {
239
+ if (false) ;
240
+ return;
737
241
  }
242
+ return to;
243
+ } catch {
738
244
  }
739
- return void 0;
740
245
  })();
741
246
  const isActive2 = (() => {
742
247
  if (externalLink2) return false;
743
- const currentLocation = router.state.location;
248
+ const currentLocation2 = router.stores.location.get();
744
249
  const exact = activeOptions?.exact ?? false;
745
250
  if (exact) {
746
- const testExact = exactPathTest(
747
- currentLocation.pathname,
748
- next2.pathname,
749
- router.basepath
750
- );
751
- if (!testExact) {
752
- return false;
753
- }
251
+ if (!exactPathTest(currentLocation2.pathname, next2.pathname, router.basepath)) return false;
754
252
  } else {
755
- const currentPathSplit = removeTrailingSlash(
756
- currentLocation.pathname,
757
- router.basepath
758
- );
759
- const nextPathSplit = removeTrailingSlash(
760
- next2.pathname,
761
- router.basepath
762
- );
763
- const pathIsFuzzyEqual = currentPathSplit.startsWith(nextPathSplit) && (currentPathSplit.length === nextPathSplit.length || currentPathSplit[nextPathSplit.length] === "/");
764
- if (!pathIsFuzzyEqual) {
765
- return false;
766
- }
253
+ const currentPathSplit = removeTrailingSlash(currentLocation2.pathname, router.basepath);
254
+ const nextPathSplit = removeTrailingSlash(next2.pathname, router.basepath);
255
+ if (!(currentPathSplit.startsWith(nextPathSplit) && (currentPathSplit.length === nextPathSplit.length || currentPathSplit[nextPathSplit.length] === "/"))) return false;
767
256
  }
768
- const includeSearch = activeOptions?.includeSearch ?? true;
769
- if (includeSearch) {
770
- if (currentLocation.search !== next2.search) {
771
- const currentSearchEmpty = !currentLocation.search || typeof currentLocation.search === "object" && Object.keys(currentLocation.search).length === 0;
772
- const nextSearchEmpty = !next2.search || typeof next2.search === "object" && Object.keys(next2.search).length === 0;
257
+ if (activeOptions?.includeSearch ?? true) {
258
+ if (currentLocation2.search !== next2.search) {
259
+ const currentSearchEmpty = !currentLocation2.search || typeof currentLocation2.search === "object" && !hasKeys(currentLocation2.search);
260
+ const nextSearchEmpty = !next2.search || typeof next2.search === "object" && !hasKeys(next2.search);
773
261
  if (!(currentSearchEmpty && nextSearchEmpty)) {
774
- const searchTest = deepEqual(currentLocation.search, next2.search, {
262
+ if (!deepEqual(currentLocation2.search, next2.search, {
775
263
  partial: !exact,
776
264
  ignoreUndefined: !activeOptions?.explicitUndefined
777
- });
778
- if (!searchTest) {
779
- return false;
780
- }
265
+ })) return false;
781
266
  }
782
267
  }
783
268
  }
784
- if (activeOptions?.includeHash) {
785
- return false;
786
- }
269
+ if (activeOptions?.includeHash) return false;
787
270
  return true;
788
271
  })();
789
- if (externalLink2) {
790
- return {
791
- ...propsSafeToSpread,
792
- ref: innerRef,
793
- href: externalLink2,
794
- ...children && { children },
795
- ...target && { target },
796
- ...disabled && { disabled },
797
- ...style && { style },
798
- ...className && { className }
799
- };
800
- }
272
+ if (externalLink2) return {
273
+ ...propsSafeToSpread,
274
+ ref: innerRef,
275
+ href: externalLink2,
276
+ ...children && { children },
277
+ ...target && { target },
278
+ ...disabled && { disabled },
279
+ ...style && { style },
280
+ ...className && { className }
281
+ };
801
282
  const resolvedActiveProps2 = isActive2 ? functionalUpdate(activeProps, {}) ?? STATIC_ACTIVE_OBJECT : STATIC_EMPTY_OBJECT;
802
283
  const resolvedInactiveProps2 = isActive2 ? STATIC_EMPTY_OBJECT : functionalUpdate(inactiveProps, {}) ?? STATIC_EMPTY_OBJECT;
803
284
  const resolvedStyle2 = (() => {
804
285
  const baseStyle = style;
805
286
  const activeStyle = resolvedActiveProps2.style;
806
287
  const inactiveStyle = resolvedInactiveProps2.style;
807
- if (!baseStyle && !activeStyle && !inactiveStyle) {
808
- return void 0;
809
- }
810
- if (baseStyle && !activeStyle && !inactiveStyle) {
811
- return baseStyle;
812
- }
813
- if (!baseStyle && activeStyle && !inactiveStyle) {
814
- return activeStyle;
815
- }
816
- if (!baseStyle && !activeStyle && inactiveStyle) {
817
- return inactiveStyle;
818
- }
288
+ if (!baseStyle && !activeStyle && !inactiveStyle) return;
289
+ if (baseStyle && !activeStyle && !inactiveStyle) return baseStyle;
290
+ if (!baseStyle && activeStyle && !inactiveStyle) return activeStyle;
291
+ if (!baseStyle && !activeStyle && inactiveStyle) return inactiveStyle;
819
292
  return {
820
293
  ...baseStyle,
821
294
  ...activeStyle,
@@ -826,19 +299,11 @@ function useLinkProps(options, forwardedRef) {
826
299
  const baseClassName = className;
827
300
  const activeClassName = resolvedActiveProps2.className;
828
301
  const inactiveClassName = resolvedInactiveProps2.className;
829
- if (!baseClassName && !activeClassName && !inactiveClassName) {
830
- return "";
831
- }
302
+ if (!baseClassName && !activeClassName && !inactiveClassName) return "";
832
303
  let out = "";
833
- if (baseClassName) {
834
- out = baseClassName;
835
- }
836
- if (activeClassName) {
837
- out = out ? `${out} ${activeClassName}` : activeClassName;
838
- }
839
- if (inactiveClassName) {
840
- out = out ? `${out} ${inactiveClassName}` : inactiveClassName;
841
- }
304
+ if (baseClassName) out = baseClassName;
305
+ if (activeClassName) out = out ? `${out} ${activeClassName}` : activeClassName;
306
+ if (inactiveClassName) out = out ? `${out} ${inactiveClassName}` : inactiveClassName;
842
307
  return out;
843
308
  })();
844
309
  return {
@@ -856,15 +321,22 @@ function useLinkProps(options, forwardedRef) {
856
321
  };
857
322
  }
858
323
  }
859
- const STATIC_EMPTY_OBJECT = {};
860
- const STATIC_ACTIVE_OBJECT = { className: "active" };
861
- const STATIC_DISABLED_PROPS = { role: "link", "aria-disabled": true };
862
- const STATIC_ACTIVE_PROPS = { "data-status": "active", "aria-current": "page" };
324
+ var STATIC_EMPTY_OBJECT = {};
325
+ var STATIC_ACTIVE_OBJECT = { className: "active" };
326
+ var STATIC_DISABLED_PROPS = {
327
+ role: "link",
328
+ "aria-disabled": true
329
+ };
330
+ var STATIC_ACTIVE_PROPS = {
331
+ "data-status": "active",
332
+ "aria-current": "page"
333
+ };
863
334
  function getHrefOption(publicHref, external, history, disabled) {
864
335
  if (disabled) return void 0;
865
- if (external) {
866
- return { href: publicHref, external: true };
867
- }
336
+ if (external) return {
337
+ href: publicHref,
338
+ external: true
339
+ };
868
340
  return {
869
341
  href: history.createHref(publicHref) || "/",
870
342
  external: false
@@ -876,24 +348,20 @@ function isSafeInternal(to) {
876
348
  if (zero === 47) return to.charCodeAt(1) !== 47;
877
349
  return zero === 46;
878
350
  }
879
- const Link = reactExports.forwardRef(
880
- (props, ref) => {
881
- const { _asChild, ...rest } = props;
882
- const { type: _type, ...linkProps } = useLinkProps(rest, ref);
883
- const children = typeof rest.children === "function" ? rest.children({
884
- isActive: linkProps["data-status"] === "active"
885
- }) : rest.children;
886
- if (!_asChild) {
887
- const { disabled: _, ...rest2 } = linkProps;
888
- return reactExports.createElement("a", rest2, children);
889
- }
890
- return reactExports.createElement(_asChild, linkProps, children);
351
+ var Link = reactExports.forwardRef((props, ref) => {
352
+ const { _asChild, ...rest } = props;
353
+ const { type: _type, ...linkProps } = useLinkProps(rest, ref);
354
+ const children = typeof rest.children === "function" ? rest.children({ isActive: linkProps["data-status"] === "active" }) : rest.children;
355
+ if (!_asChild) {
356
+ const { disabled: _, ...rest2 } = linkProps;
357
+ return reactExports.createElement("a", rest2, children);
891
358
  }
892
- );
893
- class Route extends BaseRoute {
359
+ return reactExports.createElement(_asChild, linkProps, children);
360
+ });
361
+ var Route = class extends BaseRoute {
894
362
  /**
895
- * @deprecated Use the `createRoute` function instead.
896
- */
363
+ * @deprecated Use the `createRoute` function instead.
364
+ */
897
365
  constructor(options) {
898
366
  super(options);
899
367
  this.useMatch = (opts) => {
@@ -904,10 +372,9 @@ class Route extends BaseRoute {
904
372
  });
905
373
  };
906
374
  this.useRouteContext = (opts) => {
907
- return useMatch({
375
+ return useRouteContext({
908
376
  ...opts,
909
- from: this.id,
910
- select: (d) => opts?.select ? opts.select(d.context) : d.context
377
+ from: this.id
911
378
  });
912
379
  };
913
380
  this.useSearch = (opts) => {
@@ -925,32 +392,36 @@ class Route extends BaseRoute {
925
392
  });
926
393
  };
927
394
  this.useLoaderDeps = (opts) => {
928
- return useLoaderDeps({ ...opts, from: this.id });
395
+ return useLoaderDeps({
396
+ ...opts,
397
+ from: this.id
398
+ });
929
399
  };
930
400
  this.useLoaderData = (opts) => {
931
- return useLoaderData({ ...opts, from: this.id });
401
+ return useLoaderData({
402
+ ...opts,
403
+ from: this.id
404
+ });
932
405
  };
933
406
  this.useNavigate = () => {
934
407
  return useNavigate({ from: this.fullPath });
935
408
  };
936
- this.Link = React$1.forwardRef(
937
- (props, ref) => {
938
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { ref, from: this.fullPath, ...props });
939
- }
940
- );
941
- this.$$typeof = /* @__PURE__ */ Symbol.for("react.memo");
409
+ this.Link = React.forwardRef((props, ref) => {
410
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, {
411
+ ref,
412
+ from: this.fullPath,
413
+ ...props
414
+ });
415
+ });
942
416
  }
943
- }
417
+ };
944
418
  function createRoute(options) {
945
- return new Route(
946
- // TODO: Help us TypeChris, you're our only hope!
947
- options
948
- );
419
+ return new Route(options);
949
420
  }
950
- class RootRoute extends BaseRootRoute {
421
+ var RootRoute = class extends BaseRootRoute {
951
422
  /**
952
- * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
953
- */
423
+ * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
424
+ */
954
425
  constructor(options) {
955
426
  super(options);
956
427
  this.useMatch = (opts) => {
@@ -961,10 +432,9 @@ class RootRoute extends BaseRootRoute {
961
432
  });
962
433
  };
963
434
  this.useRouteContext = (opts) => {
964
- return useMatch({
435
+ return useRouteContext({
965
436
  ...opts,
966
- from: this.id,
967
- select: (d) => opts?.select ? opts.select(d.context) : d.context
437
+ from: this.id
968
438
  });
969
439
  };
970
440
  this.useSearch = (opts) => {
@@ -982,121 +452,67 @@ class RootRoute extends BaseRootRoute {
982
452
  });
983
453
  };
984
454
  this.useLoaderDeps = (opts) => {
985
- return useLoaderDeps({ ...opts, from: this.id });
455
+ return useLoaderDeps({
456
+ ...opts,
457
+ from: this.id
458
+ });
986
459
  };
987
460
  this.useLoaderData = (opts) => {
988
- return useLoaderData({ ...opts, from: this.id });
461
+ return useLoaderData({
462
+ ...opts,
463
+ from: this.id
464
+ });
989
465
  };
990
466
  this.useNavigate = () => {
991
467
  return useNavigate({ from: this.fullPath });
992
468
  };
993
- this.Link = React$1.forwardRef(
994
- (props, ref) => {
995
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { ref, from: this.fullPath, ...props });
996
- }
997
- );
998
- this.$$typeof = /* @__PURE__ */ Symbol.for("react.memo");
469
+ this.Link = React.forwardRef((props, ref) => {
470
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, {
471
+ ref,
472
+ from: this.fullPath,
473
+ ...props
474
+ });
475
+ });
999
476
  }
1000
- }
477
+ };
1001
478
  function createRootRoute(options) {
1002
479
  return new RootRoute(options);
1003
480
  }
1004
481
  function createFileRoute(path) {
1005
- if (typeof path === "object") {
1006
- return new FileRoute(path, {
1007
- silent: true
1008
- }).createRoute(path);
1009
- }
1010
- return new FileRoute(path, {
1011
- silent: true
1012
- }).createRoute;
482
+ return new FileRoute(path, { silent: true }).createRoute;
1013
483
  }
1014
- class FileRoute {
484
+ var FileRoute = class {
1015
485
  constructor(path, _opts) {
1016
486
  this.path = path;
1017
487
  this.createRoute = (options) => {
1018
- warning(
1019
- this.silent
1020
- );
1021
488
  const route = createRoute(options);
1022
489
  route.isRoot = false;
1023
490
  return route;
1024
491
  };
1025
492
  this.silent = _opts?.silent;
1026
493
  }
1027
- }
1028
- class LazyRoute {
1029
- constructor(opts) {
1030
- this.useMatch = (opts2) => {
1031
- return useMatch({
1032
- select: opts2?.select,
1033
- from: this.options.id,
1034
- structuralSharing: opts2?.structuralSharing
1035
- });
1036
- };
1037
- this.useRouteContext = (opts2) => {
1038
- return useMatch({
1039
- from: this.options.id,
1040
- select: (d) => opts2?.select ? opts2.select(d.context) : d.context
1041
- });
1042
- };
1043
- this.useSearch = (opts2) => {
1044
- return useSearch({
1045
- select: opts2?.select,
1046
- structuralSharing: opts2?.structuralSharing,
1047
- from: this.options.id
1048
- });
1049
- };
1050
- this.useParams = (opts2) => {
1051
- return useParams({
1052
- select: opts2?.select,
1053
- structuralSharing: opts2?.structuralSharing,
1054
- from: this.options.id
1055
- });
1056
- };
1057
- this.useLoaderDeps = (opts2) => {
1058
- return useLoaderDeps({ ...opts2, from: this.options.id });
1059
- };
1060
- this.useLoaderData = (opts2) => {
1061
- return useLoaderData({ ...opts2, from: this.options.id });
1062
- };
1063
- this.useNavigate = () => {
1064
- const router = useRouter();
1065
- return useNavigate({ from: router.routesById[this.options.id].fullPath });
1066
- };
1067
- this.options = opts;
1068
- this.$$typeof = /* @__PURE__ */ Symbol.for("react.memo");
1069
- }
1070
- }
1071
- function createLazyFileRoute(id) {
1072
- if (typeof id === "object") {
1073
- return new LazyRoute(id);
1074
- }
1075
- return (opts) => new LazyRoute({ id, ...opts });
1076
- }
494
+ };
1077
495
  function lazyRouteComponent(importer, exportName) {
1078
496
  let loadPromise;
1079
497
  let comp;
1080
498
  let error;
1081
499
  let reload;
1082
500
  const load = () => {
1083
- if (!loadPromise) {
1084
- loadPromise = importer().then((res) => {
1085
- loadPromise = void 0;
1086
- comp = res[exportName];
1087
- }).catch((err) => {
1088
- error = err;
1089
- if (isModuleNotFoundError(error)) {
1090
- if (error instanceof Error && typeof window !== "undefined" && typeof sessionStorage !== "undefined") {
1091
- const storageKey2 = `tanstack_router_reload:${error.message}`;
1092
- if (!sessionStorage.getItem(storageKey2)) {
1093
- sessionStorage.setItem(storageKey2, "1");
1094
- reload = true;
1095
- }
501
+ if (!loadPromise) loadPromise = importer().then((res) => {
502
+ loadPromise = void 0;
503
+ comp = res[exportName];
504
+ }).catch((err) => {
505
+ error = err;
506
+ if (isModuleNotFoundError(error)) {
507
+ if (error instanceof Error && typeof window !== "undefined" && typeof sessionStorage !== "undefined") {
508
+ const storageKey = `tanstack_router_reload:${error.message}`;
509
+ if (!sessionStorage.getItem(storageKey)) {
510
+ sessionStorage.setItem(storageKey, "1");
511
+ reload = true;
1096
512
  }
1097
513
  }
1098
- });
1099
- }
514
+ }
515
+ });
1100
516
  return loadPromise;
1101
517
  };
1102
518
  const lazyComp = function Lazy(props) {
@@ -1105,68 +521,305 @@ function lazyRouteComponent(importer, exportName) {
1105
521
  throw new Promise(() => {
1106
522
  });
1107
523
  }
1108
- if (error) {
1109
- throw error;
1110
- }
1111
- if (!comp) {
1112
- if (reactUse) {
1113
- reactUse(load());
1114
- } else {
1115
- throw load();
1116
- }
1117
- }
524
+ if (error) throw error;
525
+ if (!comp) if (reactUse) reactUse(load());
526
+ else throw load();
1118
527
  return reactExports.createElement(comp, props);
1119
528
  };
1120
529
  lazyComp.preload = load;
1121
530
  return lazyComp;
1122
531
  }
1123
- const createRouter = (options) => {
532
+ function CatchNotFound(props) {
533
+ const router = useRouter();
534
+ {
535
+ const resetKey = `not-found-${router.stores.location.get().pathname}-${router.stores.status.get()}`;
536
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(CatchBoundary, {
537
+ getResetKey: () => resetKey,
538
+ onCatch: (error, errorInfo) => {
539
+ if (isNotFound(error)) props.onCatch?.(error, errorInfo);
540
+ else throw error;
541
+ },
542
+ errorComponent: ({ error }) => {
543
+ if (isNotFound(error)) return props.fallback?.(error);
544
+ else throw error;
545
+ },
546
+ children: props.children
547
+ });
548
+ }
549
+ }
550
+ function DefaultGlobalNotFound() {
551
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: "Not Found" });
552
+ }
553
+ function ScriptOnce({ children }) {
554
+ const router = useRouter();
555
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("script", {
556
+ nonce: router.options.ssr?.nonce,
557
+ dangerouslySetInnerHTML: { __html: children + ";document.currentScript.remove()" }
558
+ });
559
+ }
560
+ function SafeFragment(props) {
561
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: props.children });
562
+ }
563
+ function renderRouteNotFound(router, route, data) {
564
+ if (!route.options.notFoundComponent) {
565
+ if (router.options.defaultNotFoundComponent) return /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.defaultNotFoundComponent, { ...data });
566
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(DefaultGlobalNotFound, {});
567
+ }
568
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(route.options.notFoundComponent, { ...data });
569
+ }
570
+ function ScrollRestoration() {
571
+ const script = getScrollRestorationScriptForRouter(useRouter());
572
+ if (!script) return null;
573
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(ScriptOnce, { children: script });
574
+ }
575
+ var Match = reactExports.memo(function MatchImpl({ matchId }) {
576
+ const router = useRouter();
577
+ {
578
+ const match2 = router.stores.matchStores.get(matchId)?.get();
579
+ if (!match2) {
580
+ invariant();
581
+ }
582
+ const routeId = match2.routeId;
583
+ const parentRouteId = router.routesById[routeId].parentRoute?.id;
584
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(MatchView, {
585
+ router,
586
+ matchId,
587
+ resetKey: router.stores.loadedAt.get(),
588
+ matchState: {
589
+ routeId,
590
+ ssr: match2.ssr,
591
+ _displayPending: match2._displayPending,
592
+ parentRouteId
593
+ }
594
+ });
595
+ }
596
+ });
597
+ function MatchView({ router, matchId, resetKey, matchState }) {
598
+ const route = router.routesById[matchState.routeId];
599
+ const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent;
600
+ const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(PendingComponent, {}) : null;
601
+ const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent;
602
+ const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch;
603
+ const routeNotFoundComponent = route.isRoot ? route.options.notFoundComponent ?? router.options.notFoundRoute?.options.component : route.options.notFoundComponent;
604
+ const resolvedNoSsr = matchState.ssr === false || matchState.ssr === "data-only";
605
+ const ResolvedSuspenseBoundary = (!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) && (route.options.wrapInSuspense ?? PendingComponent ?? (route.options.errorComponent?.preload || resolvedNoSsr)) ? reactExports.Suspense : SafeFragment;
606
+ const ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary : SafeFragment;
607
+ const ResolvedNotFoundBoundary = routeNotFoundComponent ? CatchNotFound : SafeFragment;
608
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(route.isRoot ? route.options.shellComponent ?? SafeFragment : SafeFragment, { children: [/* @__PURE__ */ jsxRuntimeExports.jsx(matchContext.Provider, {
609
+ value: matchId,
610
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResolvedSuspenseBoundary, {
611
+ fallback: pendingElement,
612
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResolvedCatchBoundary, {
613
+ getResetKey: () => resetKey,
614
+ errorComponent: routeErrorComponent || ErrorComponent,
615
+ onCatch: (error, errorInfo) => {
616
+ if (isNotFound(error)) {
617
+ error.routeId ??= matchState.routeId;
618
+ throw error;
619
+ }
620
+ routeOnCatch?.(error, errorInfo);
621
+ },
622
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResolvedNotFoundBoundary, {
623
+ fallback: (error) => {
624
+ error.routeId ??= matchState.routeId;
625
+ if (!routeNotFoundComponent || error.routeId && error.routeId !== matchState.routeId || !error.routeId && !route.isRoot) throw error;
626
+ return reactExports.createElement(routeNotFoundComponent, error);
627
+ },
628
+ children: resolvedNoSsr || matchState._displayPending ? /* @__PURE__ */ jsxRuntimeExports.jsx(ClientOnly, {
629
+ fallback: pendingElement,
630
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(MatchInner, { matchId })
631
+ }) : /* @__PURE__ */ jsxRuntimeExports.jsx(MatchInner, { matchId })
632
+ })
633
+ })
634
+ })
635
+ }), matchState.parentRouteId === rootRouteId ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [/* @__PURE__ */ jsxRuntimeExports.jsx(OnRendered, { resetKey }), router.options.scrollRestoration && isServer ? /* @__PURE__ */ jsxRuntimeExports.jsx(ScrollRestoration, {}) : null] }) : null] });
636
+ }
637
+ function OnRendered({ resetKey }) {
638
+ useRouter();
639
+ return null;
640
+ }
641
+ var MatchInner = reactExports.memo(function MatchInnerImpl({ matchId }) {
642
+ const router = useRouter();
643
+ const getMatchPromise = (match2, key2) => {
644
+ return router.getMatch(match2.id)?._nonReactive[key2] ?? match2._nonReactive[key2];
645
+ };
646
+ {
647
+ const match2 = router.stores.matchStores.get(matchId)?.get();
648
+ if (!match2) {
649
+ invariant();
650
+ }
651
+ const routeId2 = match2.routeId;
652
+ const route2 = router.routesById[routeId2];
653
+ const remountDeps = (router.routesById[routeId2].options.remountDeps ?? router.options.defaultRemountDeps)?.({
654
+ routeId: routeId2,
655
+ loaderDeps: match2.loaderDeps,
656
+ params: match2._strictParams,
657
+ search: match2._strictSearch
658
+ });
659
+ const key2 = remountDeps ? JSON.stringify(remountDeps) : void 0;
660
+ const Comp = route2.options.component ?? router.options.defaultComponent;
661
+ const out2 = Comp ? /* @__PURE__ */ jsxRuntimeExports.jsx(Comp, {}, key2) : /* @__PURE__ */ jsxRuntimeExports.jsx(Outlet, {});
662
+ if (match2._displayPending) throw getMatchPromise(match2, "displayPendingPromise");
663
+ if (match2._forcePending) throw getMatchPromise(match2, "minPendingPromise");
664
+ if (match2.status === "pending") throw getMatchPromise(match2, "loadPromise");
665
+ if (match2.status === "notFound") {
666
+ if (!isNotFound(match2.error)) {
667
+ invariant();
668
+ }
669
+ return renderRouteNotFound(router, route2, match2.error);
670
+ }
671
+ if (match2.status === "redirected") {
672
+ if (!isRedirect(match2.error)) {
673
+ invariant();
674
+ }
675
+ throw getMatchPromise(match2, "loadPromise");
676
+ }
677
+ if (match2.status === "error") return /* @__PURE__ */ jsxRuntimeExports.jsx((route2.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent, {
678
+ error: match2.error,
679
+ reset: void 0,
680
+ info: { componentStack: "" }
681
+ });
682
+ return out2;
683
+ }
684
+ });
685
+ var Outlet = reactExports.memo(function OutletImpl() {
686
+ const router = useRouter();
687
+ const matchId = reactExports.useContext(matchContext);
688
+ let routeId;
689
+ let parentGlobalNotFound = false;
690
+ let childMatchId;
691
+ {
692
+ const matches = router.stores.matches.get();
693
+ const parentIndex = matchId ? matches.findIndex((match) => match.id === matchId) : -1;
694
+ const parentMatch = parentIndex >= 0 ? matches[parentIndex] : void 0;
695
+ routeId = parentMatch?.routeId;
696
+ parentGlobalNotFound = parentMatch?.globalNotFound ?? false;
697
+ childMatchId = parentIndex >= 0 ? matches[parentIndex + 1]?.id : void 0;
698
+ }
699
+ const route = routeId ? router.routesById[routeId] : void 0;
700
+ const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.defaultPendingComponent, {}) : null;
701
+ if (parentGlobalNotFound) {
702
+ if (!route) {
703
+ invariant();
704
+ }
705
+ return renderRouteNotFound(router, route, void 0);
706
+ }
707
+ if (!childMatchId) return null;
708
+ const nextMatch = /* @__PURE__ */ jsxRuntimeExports.jsx(Match, { matchId: childMatchId });
709
+ if (routeId === rootRouteId) return /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.Suspense, {
710
+ fallback: pendingElement,
711
+ children: nextMatch
712
+ });
713
+ return nextMatch;
714
+ });
715
+ function Matches() {
716
+ const router = useRouter();
717
+ const PendingComponent = router.routesById[rootRouteId].options.pendingComponent ?? router.options.defaultPendingComponent;
718
+ const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(PendingComponent, {}) : null;
719
+ const inner = /* @__PURE__ */ jsxRuntimeExports.jsxs(SafeFragment, {
720
+ fallback: pendingElement,
721
+ children: [false, /* @__PURE__ */ jsxRuntimeExports.jsx(MatchesInner, {})]
722
+ });
723
+ return router.options.InnerWrap ? /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.InnerWrap, { children: inner }) : inner;
724
+ }
725
+ function MatchesInner() {
726
+ const router = useRouter();
727
+ const matchId = router.stores.firstId.get();
728
+ const resetKey = router.stores.loadedAt.get();
729
+ const matchComponent = matchId ? /* @__PURE__ */ jsxRuntimeExports.jsx(Match, { matchId }) : null;
730
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(matchContext.Provider, {
731
+ value: matchId,
732
+ children: router.options.disableGlobalCatchBoundary ? matchComponent : /* @__PURE__ */ jsxRuntimeExports.jsx(CatchBoundary, {
733
+ getResetKey: () => resetKey,
734
+ errorComponent: ErrorComponent,
735
+ onCatch: void 0,
736
+ children: matchComponent
737
+ })
738
+ });
739
+ }
740
+ var getStoreFactory = (opts) => {
741
+ return {
742
+ createMutableStore: createNonReactiveMutableStore,
743
+ createReadonlyStore: createNonReactiveReadonlyStore,
744
+ batch: (fn) => fn()
745
+ };
746
+ };
747
+ var createRouter = (options) => {
1124
748
  return new Router(options);
1125
749
  };
1126
- class Router extends RouterCore {
750
+ var Router = class extends RouterCore {
1127
751
  constructor(options) {
1128
- super(options);
752
+ super(options, getStoreFactory);
1129
753
  }
754
+ };
755
+ function RouterContextProvider({ router, children, ...rest }) {
756
+ if (hasKeys(rest)) router.update({
757
+ ...router.options,
758
+ ...rest,
759
+ context: {
760
+ ...router.options.context,
761
+ ...rest.context
762
+ }
763
+ });
764
+ const provider = /* @__PURE__ */ jsxRuntimeExports.jsx(routerContext.Provider, {
765
+ value: router,
766
+ children
767
+ });
768
+ if (router.options.Wrap) return /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.Wrap, { children: provider });
769
+ return provider;
1130
770
  }
1131
- if (typeof globalThis !== "undefined") {
1132
- globalThis.createFileRoute = createFileRoute;
1133
- globalThis.createLazyFileRoute = createLazyFileRoute;
1134
- } else if (typeof window !== "undefined") {
1135
- window.createFileRoute = createFileRoute;
1136
- window.createLazyFileRoute = createLazyFileRoute;
771
+ function RouterProvider({ router, ...rest }) {
772
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RouterContextProvider, {
773
+ router,
774
+ ...rest,
775
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(Matches, {})
776
+ });
1137
777
  }
1138
- function Asset({
1139
- tag,
1140
- attrs,
1141
- children,
1142
- nonce
1143
- }) {
1144
- switch (tag) {
778
+ var noopScriptHandler = () => {
779
+ };
780
+ function setScriptAttrs(script, attrs) {
781
+ if (!attrs) return;
782
+ for (const [key, value] of Object.entries(attrs)) if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) script.setAttribute(key, typeof value === "boolean" ? "" : String(value));
783
+ }
784
+ function Asset(asset) {
785
+ const { attrs, children, nonce, preventScriptHoist } = asset;
786
+ switch (asset.tag) {
1145
787
  case "title":
1146
- return /* @__PURE__ */ jsxRuntimeExports.jsx("title", { ...attrs, suppressHydrationWarning: true, children });
788
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("title", {
789
+ ...attrs,
790
+ suppressHydrationWarning: true,
791
+ children
792
+ });
1147
793
  case "meta":
1148
- return /* @__PURE__ */ jsxRuntimeExports.jsx("meta", { ...attrs, suppressHydrationWarning: true });
794
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("meta", {
795
+ ...attrs,
796
+ suppressHydrationWarning: true
797
+ });
1149
798
  case "link":
1150
- return /* @__PURE__ */ jsxRuntimeExports.jsx("link", { ...attrs, nonce, suppressHydrationWarning: true });
799
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("link", {
800
+ ...attrs,
801
+ precedence: attrs?.precedence ?? (attrs?.rel === "stylesheet" ? "default" : void 0),
802
+ nonce,
803
+ suppressHydrationWarning: true
804
+ });
1151
805
  case "style":
1152
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
1153
- "style",
1154
- {
1155
- ...attrs,
1156
- dangerouslySetInnerHTML: { __html: children },
1157
- nonce
1158
- }
1159
- );
806
+ if (asset.inlineCss && false) ;
807
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("style", {
808
+ ...attrs,
809
+ dangerouslySetInnerHTML: { __html: children },
810
+ nonce
811
+ });
1160
812
  case "script":
1161
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Script, { attrs, children });
813
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Script, {
814
+ attrs,
815
+ preventScriptHoist,
816
+ children
817
+ });
1162
818
  default:
1163
819
  return null;
1164
820
  }
1165
821
  }
1166
- function Script({
1167
- attrs,
1168
- children
1169
- }) {
822
+ function Script({ attrs, children, preventScriptHoist }) {
1170
823
  useRouter();
1171
824
  useHydrated();
1172
825
  const dataScript = typeof attrs?.type === "string" && attrs.type !== "" && attrs.type !== "text/javascript" && attrs.type !== "module";
@@ -1181,291 +834,329 @@ function Script({
1181
834
  return attrs.src;
1182
835
  }
1183
836
  })();
1184
- const existingScript = Array.from(
1185
- document.querySelectorAll("script[src]")
1186
- ).find((el) => el.src === normSrc);
1187
- if (existingScript) {
1188
- return;
1189
- }
837
+ for (const el of document.querySelectorAll("script[src]")) if (el.src === normSrc) return;
1190
838
  const script = document.createElement("script");
1191
- for (const [key, value] of Object.entries(attrs)) {
1192
- if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) {
1193
- script.setAttribute(
1194
- key,
1195
- typeof value === "boolean" ? "" : String(value)
1196
- );
1197
- }
1198
- }
839
+ setScriptAttrs(script, attrs);
1199
840
  document.head.appendChild(script);
1200
- return () => {
1201
- if (script.parentNode) {
1202
- script.parentNode.removeChild(script);
1203
- }
1204
- };
841
+ return () => script.remove();
1205
842
  }
1206
843
  if (typeof children === "string") {
1207
844
  const typeAttr = typeof attrs?.type === "string" ? attrs.type : "text/javascript";
1208
845
  const nonceAttr = typeof attrs?.nonce === "string" ? attrs.nonce : void 0;
1209
- const existingScript = Array.from(
1210
- document.querySelectorAll("script:not([src])")
1211
- ).find((el) => {
1212
- if (!(el instanceof HTMLScriptElement)) return false;
846
+ for (const el of document.querySelectorAll("script:not([src])")) {
847
+ if (!(el instanceof HTMLScriptElement)) continue;
1213
848
  const sType = el.getAttribute("type") ?? "text/javascript";
1214
849
  const sNonce = el.getAttribute("nonce") ?? void 0;
1215
- return el.textContent === children && sType === typeAttr && sNonce === nonceAttr;
1216
- });
1217
- if (existingScript) {
1218
- return;
850
+ if (el.textContent === children && sType === typeAttr && sNonce === nonceAttr) return;
1219
851
  }
1220
852
  const script = document.createElement("script");
1221
853
  script.textContent = children;
1222
- if (attrs) {
1223
- for (const [key, value] of Object.entries(attrs)) {
1224
- if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) {
1225
- script.setAttribute(
1226
- key,
1227
- typeof value === "boolean" ? "" : String(value)
1228
- );
1229
- }
1230
- }
1231
- }
854
+ setScriptAttrs(script, attrs);
1232
855
  document.head.appendChild(script);
1233
- return () => {
1234
- if (script.parentNode) {
1235
- script.parentNode.removeChild(script);
1236
- }
1237
- };
856
+ return () => script.remove();
1238
857
  }
1239
- return void 0;
1240
- }, [attrs, children, dataScript]);
858
+ }, [
859
+ attrs,
860
+ children,
861
+ dataScript
862
+ ]);
1241
863
  {
1242
864
  if (attrs?.src) {
1243
- return /* @__PURE__ */ jsxRuntimeExports.jsx("script", { ...attrs, suppressHydrationWarning: true });
1244
- }
1245
- if (typeof children === "string") {
1246
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
1247
- "script",
1248
- {
1249
- ...attrs,
1250
- dangerouslySetInnerHTML: { __html: children },
1251
- suppressHydrationWarning: true
1252
- }
1253
- );
865
+ if (!preventScriptHoist) return /* @__PURE__ */ jsxRuntimeExports.jsx("script", {
866
+ ...attrs,
867
+ suppressHydrationWarning: true
868
+ });
869
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("script", {
870
+ ...attrs,
871
+ onLoad: noopScriptHandler,
872
+ suppressHydrationWarning: true
873
+ });
1254
874
  }
875
+ if (typeof children === "string") return /* @__PURE__ */ jsxRuntimeExports.jsx("script", {
876
+ ...attrs,
877
+ dangerouslySetInnerHTML: { __html: children },
878
+ suppressHydrationWarning: true
879
+ });
1255
880
  return null;
1256
881
  }
1257
882
  }
1258
- const useTags = () => {
1259
- const router = useRouter();
1260
- const nonce = router.options.ssr?.nonce;
1261
- const routeMeta = useRouterState({
1262
- select: (state) => {
1263
- return state.matches.map((match) => match.meta).filter(Boolean);
1264
- }
1265
- });
1266
- const meta = reactExports.useMemo(() => {
1267
- const resultMeta = [];
1268
- const metaByAttribute = {};
1269
- let title;
1270
- for (let i = routeMeta.length - 1; i >= 0; i--) {
1271
- const metas = routeMeta[i];
1272
- for (let j = metas.length - 1; j >= 0; j--) {
1273
- const m = metas[j];
1274
- if (!m) continue;
1275
- if (m.title) {
1276
- if (!title) {
1277
- title = {
1278
- tag: "title",
1279
- children: m.title
1280
- };
1281
- }
1282
- } else if ("script:ld+json" in m) {
1283
- try {
1284
- const json = JSON.stringify(m["script:ld+json"]);
1285
- resultMeta.push({
1286
- tag: "script",
1287
- attrs: {
1288
- type: "application/ld+json"
1289
- },
1290
- children: escapeHtml(json)
1291
- });
1292
- } catch {
1293
- }
1294
- } else {
1295
- const attribute = m.name ?? m.property;
1296
- if (attribute) {
1297
- if (metaByAttribute[attribute]) {
1298
- continue;
1299
- } else {
1300
- metaByAttribute[attribute] = true;
1301
- }
883
+ function buildTagsFromMatches(router, nonce, matches, assetCrossOrigin) {
884
+ const routeMeta = matches.map((match) => match.meta).filter((meta) => meta !== void 0);
885
+ const resultMeta = [];
886
+ const metaByAttribute = {};
887
+ let title;
888
+ for (let i = routeMeta.length - 1; i >= 0; i--) {
889
+ const metas = routeMeta[i];
890
+ for (let j = metas.length - 1; j >= 0; j--) {
891
+ const m = metas[j];
892
+ if (!m) continue;
893
+ if (m.title) {
894
+ if (!title) title = {
895
+ tag: "title",
896
+ children: m.title
897
+ };
898
+ } else if ("script:ld+json" in m) try {
899
+ const json = JSON.stringify(m["script:ld+json"]);
900
+ resultMeta.push({
901
+ tag: "script",
902
+ attrs: { type: "application/ld+json" },
903
+ children: escapeHtml(json)
904
+ });
905
+ } catch {
906
+ }
907
+ else {
908
+ const attribute = m.name ?? m.property;
909
+ if (attribute) if (metaByAttribute[attribute]) continue;
910
+ else metaByAttribute[attribute] = true;
911
+ resultMeta.push({
912
+ tag: "meta",
913
+ attrs: {
914
+ ...m,
915
+ nonce
1302
916
  }
1303
- resultMeta.push({
1304
- tag: "meta",
1305
- attrs: {
1306
- ...m,
1307
- nonce
1308
- }
1309
- });
1310
- }
917
+ });
1311
918
  }
1312
919
  }
1313
- if (title) {
1314
- resultMeta.push(title);
920
+ }
921
+ if (title) resultMeta.push(title);
922
+ if (nonce) resultMeta.push({
923
+ tag: "meta",
924
+ attrs: {
925
+ property: "csp-nonce",
926
+ content: nonce
1315
927
  }
1316
- if (nonce) {
1317
- resultMeta.push({
1318
- tag: "meta",
1319
- attrs: {
1320
- property: "csp-nonce",
1321
- content: nonce
1322
- }
1323
- });
928
+ });
929
+ resultMeta.reverse();
930
+ const constructedLinks = matches.flatMap((match) => match.links ?? []).filter((link) => link !== void 0).map((link) => ({
931
+ tag: "link",
932
+ attrs: {
933
+ ...link,
934
+ nonce
1324
935
  }
1325
- resultMeta.reverse();
1326
- return resultMeta;
1327
- }, [routeMeta, nonce]);
1328
- const links = useRouterState({
1329
- select: (state) => {
1330
- const constructed = state.matches.map((match) => match.links).filter(Boolean).flat(1).map((link) => ({
1331
- tag: "link",
1332
- attrs: {
1333
- ...link,
1334
- nonce
1335
- }
1336
- }));
1337
- const manifest = router.ssr?.manifest;
1338
- const assets = state.matches.map((match) => manifest?.routes[match.routeId]?.assets ?? []).filter(Boolean).flat(1).filter((asset) => asset.tag === "link").map(
1339
- (asset) => ({
936
+ }));
937
+ const manifest = router.ssr?.manifest;
938
+ const manifestCssTags = [];
939
+ if (manifest) {
940
+ matches.forEach((match) => {
941
+ manifest.routes[match.routeId]?.css?.forEach((link) => {
942
+ const resolvedLink = resolveManifestCssLink(link);
943
+ manifestCssTags.push({
1340
944
  tag: "link",
1341
945
  attrs: {
1342
- ...asset.attrs,
946
+ rel: "stylesheet",
947
+ ...resolvedLink,
948
+ crossOrigin: getAssetCrossOrigin(assetCrossOrigin, "stylesheet") ?? resolvedLink.crossOrigin,
1343
949
  suppressHydrationWarning: true,
1344
950
  nonce
1345
951
  }
1346
- })
1347
- );
1348
- return [...constructed, ...assets];
1349
- },
1350
- structuralSharing: true
1351
- });
1352
- const preloadLinks = useRouterState({
1353
- select: (state) => {
1354
- const preloadLinks2 = [];
1355
- state.matches.map((match) => router.looseRoutesById[match.routeId]).forEach(
1356
- (route) => router.ssr?.manifest?.routes[route.id]?.preloads?.filter(Boolean).forEach((preload) => {
1357
- preloadLinks2.push({
1358
- tag: "link",
1359
- attrs: {
1360
- rel: "modulepreload",
1361
- href: preload,
1362
- nonce
1363
- }
1364
- });
1365
- })
1366
- );
1367
- return preloadLinks2;
1368
- },
1369
- structuralSharing: true
1370
- });
1371
- const styles = useRouterState({
1372
- select: (state) => state.matches.map((match) => match.styles).flat(1).filter(Boolean).map(({ children, ...attrs }) => ({
952
+ });
953
+ });
954
+ });
955
+ if (manifest.inlineStyle) manifestCssTags.push({
1373
956
  tag: "style",
1374
957
  attrs: {
1375
- ...attrs,
1376
- nonce
1377
- },
1378
- children
1379
- })),
1380
- structuralSharing: true
1381
- });
1382
- const headScripts = useRouterState({
1383
- select: (state) => state.matches.map((match) => match.headScripts).flat(1).filter(Boolean).map(({ children, ...script }) => ({
1384
- tag: "script",
1385
- attrs: {
1386
- ...script,
958
+ ...manifest.inlineStyle.attrs,
1387
959
  nonce
1388
960
  },
1389
- children
1390
- })),
1391
- structuralSharing: true
1392
- });
1393
- return uniqBy(
1394
- [
1395
- ...meta,
1396
- ...preloadLinks,
1397
- ...links,
1398
- ...styles,
1399
- ...headScripts
1400
- ],
1401
- (d) => {
1402
- return JSON.stringify(d);
1403
- }
1404
- );
1405
- };
1406
- function uniqBy(arr, fn) {
1407
- const seen = /* @__PURE__ */ new Set();
1408
- return arr.filter((item) => {
1409
- const key = fn(item);
1410
- if (seen.has(key)) {
1411
- return false;
1412
- }
1413
- seen.add(key);
1414
- return true;
961
+ children: manifest.inlineStyle.children,
962
+ inlineCss: true
963
+ });
964
+ }
965
+ const preloadLinks = [];
966
+ if (manifest) matches.forEach((match) => {
967
+ manifest.routes[match.routeId]?.preloads?.forEach((preload) => {
968
+ preloadLinks.push({
969
+ tag: "link",
970
+ attrs: {
971
+ ...getScriptPreloadAttrs(manifest, preload, assetCrossOrigin),
972
+ nonce
973
+ }
974
+ });
975
+ });
1415
976
  });
977
+ const styles = matches.flatMap((match) => match.styles ?? []).filter((style) => style !== void 0).map(({ children, ...attrs }) => ({
978
+ tag: "style",
979
+ attrs: {
980
+ ...attrs,
981
+ nonce
982
+ },
983
+ children
984
+ }));
985
+ const headScripts = matches.flatMap((match) => match.headScripts ?? []).filter((script) => script !== void 0).map(({ children, ...script }) => ({
986
+ tag: "script",
987
+ attrs: {
988
+ ...script,
989
+ nonce
990
+ },
991
+ children
992
+ }));
993
+ const tags = [];
994
+ appendUniqueUserTags(tags, resultMeta);
995
+ tags.push(...preloadLinks);
996
+ appendUniqueUserTags(tags, constructedLinks);
997
+ tags.push(...manifestCssTags);
998
+ appendUniqueUserTags(tags, styles);
999
+ appendUniqueUserTags(tags, headScripts);
1000
+ return tags;
1416
1001
  }
1417
- function HeadContent() {
1418
- const tags = useTags();
1002
+ var useTags = (assetCrossOrigin) => {
1419
1003
  const router = useRouter();
1420
1004
  const nonce = router.options.ssr?.nonce;
1421
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: tags.map((tag) => /* @__PURE__ */ reactExports.createElement(Asset, { ...tag, key: `tsr-meta-${JSON.stringify(tag)}`, nonce })) });
1005
+ return buildTagsFromMatches(router, nonce, router.stores.matches.get(), assetCrossOrigin);
1006
+ };
1007
+ function HeadContent(props) {
1008
+ const tags = useTags(props.assetCrossOrigin);
1009
+ const nonce = useRouter().options.ssr?.nonce;
1010
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: tags.map((tag) => /* @__PURE__ */ reactExports.createElement(Asset, {
1011
+ ...tag,
1012
+ key: `tsr-meta-${JSON.stringify(tag)}`,
1013
+ nonce
1014
+ })) });
1422
1015
  }
1423
- const Scripts = () => {
1016
+ var Scripts = () => {
1424
1017
  const router = useRouter();
1425
1018
  const nonce = router.options.ssr?.nonce;
1426
- const assetScripts = useRouterState({
1427
- select: (state) => {
1428
- const assetScripts2 = [];
1429
- const manifest = router.ssr?.manifest;
1430
- if (!manifest) {
1431
- return [];
1432
- }
1433
- state.matches.map((match) => router.looseRoutesById[match.routeId]).forEach(
1434
- (route) => manifest.routes[route.id]?.assets?.filter((d) => d.tag === "script").forEach((asset) => {
1435
- assetScripts2.push({
1436
- tag: "script",
1437
- attrs: { ...asset.attrs, nonce },
1438
- children: asset.children
1439
- });
1440
- })
1441
- );
1442
- return assetScripts2;
1443
- },
1444
- structuralSharing: true
1445
- });
1446
- const { scripts } = useRouterState({
1447
- select: (state) => ({
1448
- scripts: state.matches.map((match) => match.scripts).flat(1).filter(Boolean).map(({ children, ...script }) => ({
1019
+ const getAssetScripts = (matches) => {
1020
+ const assetScripts = [];
1021
+ const manifest = router.ssr?.manifest;
1022
+ if (!manifest) return [];
1023
+ for (const match of matches) {
1024
+ const scripts = manifest.routes[match.routeId]?.scripts;
1025
+ if (!scripts) continue;
1026
+ for (const asset of scripts) assetScripts.push({
1449
1027
  tag: "script",
1450
1028
  attrs: {
1451
- ...script,
1452
- suppressHydrationWarning: true,
1029
+ ...asset.attrs,
1453
1030
  nonce
1454
1031
  },
1455
- children
1456
- }))
1457
- }),
1458
- structuralSharing: true
1459
- });
1460
- let serverBufferedScript = void 0;
1461
- if (router.serverSsr) {
1462
- serverBufferedScript = router.serverSsr.takeBufferedScripts();
1032
+ children: asset.children,
1033
+ ...typeof asset.attrs?.src === "string" ? { preventScriptHoist: true } : {}
1034
+ });
1035
+ }
1036
+ return assetScripts;
1037
+ };
1038
+ const getScripts = (matches) => matches.map((match) => match.scripts).flat(1).filter(Boolean).map(({ children, ...script }) => ({
1039
+ tag: "script",
1040
+ attrs: {
1041
+ ...script,
1042
+ suppressHydrationWarning: true,
1043
+ nonce
1044
+ },
1045
+ children
1046
+ }));
1047
+ {
1048
+ const activeMatches = router.stores.matches.get();
1049
+ const assetScripts = getAssetScripts(activeMatches);
1050
+ return renderScripts(router, getScripts(activeMatches), assetScripts);
1463
1051
  }
1052
+ };
1053
+ function renderScripts(router, scripts, assetScripts) {
1464
1054
  const allScripts = [...scripts, ...assetScripts];
1465
- if (serverBufferedScript) {
1466
- allScripts.unshift(serverBufferedScript);
1055
+ if (router.serverSsr) {
1056
+ const serverBufferedScript = router.serverSsr.takeBufferedScripts();
1057
+ if (serverBufferedScript) allScripts.unshift(serverBufferedScript);
1058
+ }
1059
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: allScripts.map((asset, i) => /* @__PURE__ */ reactExports.createElement(Asset, {
1060
+ ...asset,
1061
+ key: `tsr-scripts-${asset.tag}-${i}`
1062
+ })) });
1063
+ }
1064
+ var noop = () => {
1065
+ };
1066
+ async function waitForReadyOrAbort(ready, signal) {
1067
+ let cleanup = noop;
1068
+ try {
1069
+ await Promise.race([ready, new Promise((resolve) => {
1070
+ const onAbort = () => resolve();
1071
+ cleanup = () => signal.removeEventListener("abort", onAbort);
1072
+ signal.addEventListener("abort", onAbort, { once: true });
1073
+ if (signal.aborted) resolve();
1074
+ })]);
1075
+ } finally {
1076
+ cleanup();
1077
+ }
1078
+ }
1079
+ var renderRouterToStream = async ({ request, router, responseHeaders, children }) => {
1080
+ if (typeof ReactDOMServer.renderToReadableStream === "function") {
1081
+ const stream = await ReactDOMServer.renderToReadableStream(children, {
1082
+ signal: request.signal,
1083
+ nonce: router.options.ssr?.nonce,
1084
+ progressiveChunkSize: Number.POSITIVE_INFINITY
1085
+ });
1086
+ if (isbot(request.headers.get("User-Agent"))) await waitForReadyOrAbort(stream.allReady, request.signal);
1087
+ const responseStream = transformReadableStreamWithRouter(router, stream, { onAbort: () => stream.cancel().catch(() => {
1088
+ }) });
1089
+ return createSsrStreamResponse(router, new Response(responseStream, {
1090
+ status: router.stores.statusCode.get(),
1091
+ headers: responseHeaders
1092
+ }));
1093
+ }
1094
+ if (typeof ReactDOMServer.renderToPipeableStream === "function") {
1095
+ const reactAppPassthrough = new PassThrough();
1096
+ let pipeable;
1097
+ let responseAttached = false;
1098
+ let aborted = false;
1099
+ let endedBeforeAttach = false;
1100
+ let pendingAbortReason;
1101
+ const toError = (reason) => reason instanceof Error ? reason : new Error(String(reason ?? "SSR aborted"));
1102
+ const destroyError = (reason) => reason === void 0 ? void 0 : toError(reason);
1103
+ const pendingDestroyError = () => pendingAbortReason === void 0 ? toError(pendingAbortReason) : destroyError(pendingAbortReason);
1104
+ const finishPassThrough = (reason, opts) => {
1105
+ if (reactAppPassthrough.destroyed) return;
1106
+ if (responseAttached) reactAppPassthrough.destroy(opts?.defaultError ? toError(reason) : destroyError(reason));
1107
+ else endedBeforeAttach = true;
1108
+ };
1109
+ const abortPipeable = (reason, opts) => {
1110
+ if (aborted) return;
1111
+ aborted = true;
1112
+ pendingAbortReason = reason;
1113
+ const err = toError(reason);
1114
+ try {
1115
+ pipeable?.abort(err);
1116
+ } catch {
1117
+ }
1118
+ finishPassThrough(reason, opts);
1119
+ };
1120
+ if (request.signal.aborted) abortPipeable(request.signal.reason);
1121
+ else {
1122
+ const onRequestAbort = () => abortPipeable(request.signal.reason);
1123
+ request.signal.addEventListener("abort", onRequestAbort, { once: true });
1124
+ router.serverSsr?.onCleanup(() => {
1125
+ request.signal.removeEventListener("abort", onRequestAbort);
1126
+ });
1127
+ }
1128
+ try {
1129
+ pipeable = ReactDOMServer.renderToPipeableStream(children, {
1130
+ nonce: router.options.ssr?.nonce,
1131
+ progressiveChunkSize: Number.POSITIVE_INFINITY,
1132
+ ...isbot(request.headers.get("User-Agent")) ? { onAllReady() {
1133
+ pipeable.pipe(reactAppPassthrough);
1134
+ } } : { onShellReady() {
1135
+ pipeable.pipe(reactAppPassthrough);
1136
+ } },
1137
+ onError: (error, info) => {
1138
+ console.error("Error in renderToPipeableStream:", error, info);
1139
+ abortPipeable(error, { defaultError: true });
1140
+ }
1141
+ });
1142
+ } catch (e) {
1143
+ console.error("Error in renderToPipeableStream:", e);
1144
+ router.serverSsr?.cleanup();
1145
+ throw e;
1146
+ }
1147
+ const responseStream = transformPipeableStreamWithRouter(router, reactAppPassthrough, { onAbort: abortPipeable });
1148
+ responseAttached = true;
1149
+ if (endedBeforeAttach) reactAppPassthrough.destroy(pendingDestroyError());
1150
+ if (aborted && pipeable) try {
1151
+ pipeable.abort(toError(pendingAbortReason));
1152
+ } catch {
1153
+ }
1154
+ return createSsrStreamResponse(router, new Response(responseStream, {
1155
+ status: router.stores.statusCode.get(),
1156
+ headers: responseHeaders
1157
+ }));
1467
1158
  }
1468
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: allScripts.map((asset, i) => /* @__PURE__ */ reactExports.createElement(Asset, { ...asset, key: `tsr-scripts-${asset.tag}-${i}` })) });
1159
+ throw new Error("No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming.");
1469
1160
  };
1470
1161
  export {
1471
1162
  HeadContent as H,