@tanstack/router-core 1.168.4 → 1.168.5

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 (43) hide show
  1. package/dist/cjs/hash-scroll.cjs +20 -0
  2. package/dist/cjs/hash-scroll.cjs.map +1 -0
  3. package/dist/cjs/hash-scroll.d.cts +7 -0
  4. package/dist/cjs/index.cjs +3 -3
  5. package/dist/cjs/index.d.cts +2 -1
  6. package/dist/cjs/scroll-restoration-inline.cjs +6 -0
  7. package/dist/cjs/scroll-restoration-inline.cjs.map +1 -0
  8. package/dist/cjs/scroll-restoration-inline.d.cts +6 -0
  9. package/dist/cjs/scroll-restoration-script/client.cjs +9 -0
  10. package/dist/cjs/scroll-restoration-script/client.cjs.map +1 -0
  11. package/dist/cjs/scroll-restoration-script/client.d.cts +2 -0
  12. package/dist/cjs/scroll-restoration-script/server.cjs +30 -0
  13. package/dist/cjs/scroll-restoration-script/server.cjs.map +1 -0
  14. package/dist/cjs/scroll-restoration-script/server.d.cts +2 -0
  15. package/dist/cjs/scroll-restoration.cjs +130 -142
  16. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  17. package/dist/cjs/scroll-restoration.d.cts +15 -38
  18. package/dist/cjs/ssr/tsrScript.cjs +1 -1
  19. package/dist/esm/hash-scroll.d.ts +7 -0
  20. package/dist/esm/hash-scroll.js +20 -0
  21. package/dist/esm/hash-scroll.js.map +1 -0
  22. package/dist/esm/index.d.ts +2 -1
  23. package/dist/esm/index.js +3 -2
  24. package/dist/esm/scroll-restoration-inline.d.ts +6 -0
  25. package/dist/esm/scroll-restoration-inline.js +6 -0
  26. package/dist/esm/scroll-restoration-inline.js.map +1 -0
  27. package/dist/esm/scroll-restoration-script/client.d.ts +2 -0
  28. package/dist/esm/scroll-restoration-script/client.js +8 -0
  29. package/dist/esm/scroll-restoration-script/client.js.map +1 -0
  30. package/dist/esm/scroll-restoration-script/server.d.ts +2 -0
  31. package/dist/esm/scroll-restoration-script/server.js +29 -0
  32. package/dist/esm/scroll-restoration-script/server.js.map +1 -0
  33. package/dist/esm/scroll-restoration.d.ts +15 -38
  34. package/dist/esm/scroll-restoration.js +131 -141
  35. package/dist/esm/scroll-restoration.js.map +1 -1
  36. package/dist/esm/ssr/tsrScript.js +1 -1
  37. package/package.json +21 -1
  38. package/src/hash-scroll.ts +21 -0
  39. package/src/index.ts +3 -3
  40. package/src/scroll-restoration-inline.ts +81 -0
  41. package/src/scroll-restoration-script/client.ts +5 -0
  42. package/src/scroll-restoration-script/server.ts +64 -0
  43. package/src/scroll-restoration.ts +243 -271
@@ -1,26 +1,22 @@
1
1
  import { AnyRouter } from './router.cjs';
2
2
  import { ParsedLocation } from './location.cjs';
3
3
  import { NonNullableUpdater } from './utils.cjs';
4
- import { HistoryLocation } from '@tanstack/history';
5
4
  export type ScrollRestorationEntry = {
6
5
  scrollX: number;
7
6
  scrollY: number;
8
7
  };
9
- export type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>;
10
- export type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>;
11
- export type ScrollRestorationCache = {
12
- state: ScrollRestorationByKey;
8
+ type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>;
9
+ type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>;
10
+ type ScrollRestorationCache = {
11
+ readonly state: ScrollRestorationByKey;
13
12
  set: (updater: NonNullableUpdater<ScrollRestorationByKey>) => void;
13
+ persist: () => void;
14
14
  };
15
15
  export type ScrollRestorationOptions = {
16
16
  getKey?: (location: ParsedLocation) => string;
17
17
  scrollBehavior?: ScrollToOptions['behavior'];
18
18
  };
19
- /** SessionStorage key used to persist scroll restoration state. */
20
- /** SessionStorage key used to store scroll positions across navigations. */
21
- /** SessionStorage key used to store scroll positions across navigations. */
22
19
  export declare const storageKey = "tsr-scroll-restoration-v1_3";
23
- /** In-memory handle to the persisted scroll restoration cache. */
24
20
  export declare const scrollRestorationCache: ScrollRestorationCache | null;
25
21
  /**
26
22
  * The default `getKey` function for `useScrollRestoration`.
@@ -28,34 +24,15 @@ export declare const scrollRestorationCache: ScrollRestorationCache | null;
28
24
  *
29
25
  * The `location.href` is used as a fallback to support the use case where the location state is not available like the initial render.
30
26
  */
31
- /**
32
- * Default scroll restoration cache key: location state key or full href.
33
- */
34
27
  export declare const defaultGetScrollRestorationKey: (location: ParsedLocation) => string;
35
- /** Best-effort nth-child CSS selector for a given element. */
36
- export declare function getCssSelector(el: any): string;
37
- export declare function restoreScroll({ storageKey, key, behavior, shouldScrollRestoration, scrollToTopSelectors, location, }: {
38
- storageKey: string;
39
- key?: string;
40
- behavior?: ScrollToOptions['behavior'];
41
- shouldScrollRestoration?: boolean;
42
- scrollToTopSelectors?: Array<string | (() => Element | null | undefined)>;
43
- location?: HistoryLocation;
44
- }): void;
45
- /** Setup global listeners and hooks to support scroll restoration. */
46
- /** Setup global listeners and hooks to support scroll restoration. */
28
+ export declare function getElementScrollRestorationEntry(router: AnyRouter, options: ({
29
+ id: string;
30
+ getElement?: () => Window | Element | undefined | null;
31
+ } | {
32
+ id?: string;
33
+ getElement: () => Window | Element | undefined | null;
34
+ }) & {
35
+ getKey?: (location: ParsedLocation) => string;
36
+ }): ScrollRestorationEntry | undefined;
47
37
  export declare function setupScrollRestoration(router: AnyRouter, force?: boolean): void;
48
- /**
49
- * @private
50
- * Handles hash-based scrolling after navigation completes.
51
- * To be used in framework-specific <Transitioner> components during the onResolved event.
52
- *
53
- * Provides hash scrolling for programmatic navigation when default browser handling is prevented.
54
- * @param router The router instance containing current location and state
55
- */
56
- /**
57
- * @private
58
- * Handles hash-based scrolling after navigation completes.
59
- * To be used in framework-specific Transitioners.
60
- */
61
- export declare function handleHashScroll(router: AnyRouter): void;
38
+ export {};
@@ -1,5 +1,5 @@
1
1
  //#region src/ssr/tsrScript.ts?script-string
2
- var tsrScript_default = "self.$_TSR={h(){this.hydrated=!0,this.c()},e(){this.streamEnded=!0,this.c()},c(){this.hydrated&&this.streamEnded&&(delete self.$_TSR,delete self.$R.tsr)},p(e){this.initialized?e():this.buffer.push(e)},buffer:[]};\n";
2
+ var tsrScript_default = "self.$_TSR={h(){this.hydrated=!0,this.c()},e(){this.streamEnded=!0,this.c()},c(){this.hydrated&&this.streamEnded&&(delete self.$_TSR,delete self.$R.tsr)},p(e){this.initialized?e():this.buffer.push(e)},buffer:[]}";
3
3
  //#endregion
4
4
  exports.default = tsrScript_default;
5
5
 
@@ -0,0 +1,7 @@
1
+ import { AnyRouter } from './router.js';
2
+ /**
3
+ * @private
4
+ * Handles hash-based scrolling after navigation completes.
5
+ * To be used in framework-specific <Transitioner> components during the onResolved event.
6
+ */
7
+ export declare function handleHashScroll(router: AnyRouter): void;
@@ -0,0 +1,20 @@
1
+ //#region src/hash-scroll.ts
2
+ /**
3
+ * @private
4
+ * Handles hash-based scrolling after navigation completes.
5
+ * To be used in framework-specific <Transitioner> components during the onResolved event.
6
+ */
7
+ function handleHashScroll(router) {
8
+ if (typeof document !== "undefined" && document.querySelector) {
9
+ const location = router.stores.location.state;
10
+ const hashScrollIntoViewOptions = location.state.__hashScrollIntoViewOptions ?? true;
11
+ if (hashScrollIntoViewOptions && location.hash !== "") {
12
+ const el = document.getElementById(location.hash);
13
+ if (el) el.scrollIntoView(hashScrollIntoViewOptions);
14
+ }
15
+ }
16
+ }
17
+ //#endregion
18
+ export { handleHashScroll };
19
+
20
+ //# sourceMappingURL=hash-scroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-scroll.js","names":[],"sources":["../../src/hash-scroll.ts"],"sourcesContent":["import type { AnyRouter } from './router'\n\n/**\n * @private\n * Handles hash-based scrolling after navigation completes.\n * To be used in framework-specific <Transitioner> components during the onResolved event.\n */\nexport function handleHashScroll(router: AnyRouter) {\n if (typeof document !== 'undefined' && (document as any).querySelector) {\n const location = router.stores.location.state\n const hashScrollIntoViewOptions =\n location.state.__hashScrollIntoViewOptions ?? true\n\n if (hashScrollIntoViewOptions && location.hash !== '') {\n const el = document.getElementById(location.hash)\n if (el) {\n el.scrollIntoView(hashScrollIntoViewOptions)\n }\n }\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,iBAAiB,QAAmB;AAClD,KAAI,OAAO,aAAa,eAAgB,SAAiB,eAAe;EACtE,MAAM,WAAW,OAAO,OAAO,SAAS;EACxC,MAAM,4BACJ,SAAS,MAAM,+BAA+B;AAEhD,MAAI,6BAA6B,SAAS,SAAS,IAAI;GACrD,MAAM,KAAK,SAAS,eAAe,SAAS,KAAK;AACjD,OAAI,GACF,IAAG,eAAe,0BAA0B"}
@@ -40,7 +40,8 @@ export type { Redirect, RedirectOptions, RedirectOptionsRoute, RedirectFnRoute,
40
40
  export { redirect, isRedirect, isResolvedRedirect, parseRedirect, } from './redirect.js';
41
41
  export type { NotFoundError } from './not-found.js';
42
42
  export { isNotFound, notFound } from './not-found.js';
43
- export { defaultGetScrollRestorationKey, restoreScroll, storageKey, getCssSelector, scrollRestorationCache, setupScrollRestoration, handleHashScroll, } from './scroll-restoration.js';
43
+ export { defaultGetScrollRestorationKey, getElementScrollRestorationEntry, storageKey, scrollRestorationCache, setupScrollRestoration, } from './scroll-restoration.js';
44
+ export { handleHashScroll } from './hash-scroll.js';
44
45
  export type { ScrollRestorationOptions, ScrollRestorationEntry, } from './scroll-restoration.js';
45
46
  export type { ValidateFromPath, ValidateToPath, ValidateSearch, ValidateParams, InferFrom, InferTo, InferMaskTo, InferMaskFrom, ValidateNavigateOptions, ValidateNavigateOptionsArray, ValidateRedirectOptions, ValidateRedirectOptionsArray, ValidateId, InferStrict, InferShouldThrow, InferSelected, ValidateUseSearchResult, ValidateUseParamsResult, } from './typePrimitives.js';
46
47
  export type { AnySerializationAdapter, SerializationAdapter, ValidateSerializableInput, ValidateSerializableInputResult, SerializerExtensions, ValidateSerializable, RegisteredSerializableInput, SerializableExtensions, DefaultSerializable, Serializable, TSR_SERIALIZABLE, TsrSerializable, } from './ssr/serializer/transformer.js';
package/dist/esm/index.js CHANGED
@@ -2,7 +2,7 @@ import { DEFAULT_PROTOCOL_ALLOWLIST, buildDevStylesUrl, createControlledPromise,
2
2
  import { invariant } from "./invariant.js";
3
3
  import { cleanPath, exactPathTest, interpolatePath, joinPaths, removeTrailingSlash, resolvePath, trimPath, trimPathLeft, trimPathRight } from "./path.js";
4
4
  import { isNotFound, notFound } from "./not-found.js";
5
- import { defaultGetScrollRestorationKey, getCssSelector, handleHashScroll, restoreScroll, scrollRestorationCache, setupScrollRestoration, storageKey } from "./scroll-restoration.js";
5
+ import { defaultGetScrollRestorationKey, getElementScrollRestorationEntry, scrollRestorationCache, setupScrollRestoration, storageKey } from "./scroll-restoration.js";
6
6
  import { decode, encode } from "./qss.js";
7
7
  import { defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith } from "./searchParams.js";
8
8
  import { rootRouteId } from "./root.js";
@@ -17,7 +17,8 @@ import { isMatch } from "./Matches.js";
17
17
  import { BaseRootRoute, BaseRoute, BaseRouteApi } from "./route.js";
18
18
  import { createRouterConfig } from "./config.js";
19
19
  import { retainSearchParams, stripSearchParams } from "./searchMiddleware.js";
20
+ import { handleHashScroll } from "./hash-scroll.js";
20
21
  import { createSerializationAdapter, makeSerovalPlugin, makeSsrSerovalPlugin } from "./ssr/serializer/transformer.js";
21
22
  import { RawStream, createRawStreamDeserializePlugin, createRawStreamRPCPlugin } from "./ssr/serializer/RawStream.js";
22
23
  import { defaultSerovalPlugins } from "./ssr/serializer/seroval-plugins.js";
23
- export { BaseRootRoute, BaseRoute, BaseRouteApi, DEFAULT_PROTOCOL_ALLOWLIST, PathParamError, RawStream, RouterCore, SearchParamError, TSR_DEFERRED_PROMISE, buildDevStylesUrl, cleanPath, composeRewrites, createControlledPromise, createNonReactiveMutableStore, createNonReactiveReadonlyStore, createRawStreamDeserializePlugin, createRawStreamRPCPlugin, createRouterConfig, createSerializationAdapter, decode, deepEqual, defaultGetScrollRestorationKey, defaultParseSearch, defaultSerializeError, defaultSerovalPlugins, defaultStringifySearch, defer, encode, escapeHtml, exactPathTest, executeRewriteInput, functionalUpdate, getAssetCrossOrigin, getCssSelector, getInitialRouterState, getLocationChangeInfo, getMatchedRoutes, handleHashScroll, interpolatePath, invariant, isDangerousProtocol, isMatch, isModuleNotFoundError, isNotFound, isPlainArray, isPlainObject, isRedirect, isResolvedRedirect, joinPaths, lazyFn, makeSerovalPlugin, makeSsrSerovalPlugin, notFound, parseRedirect, parseSearchWith, preloadWarning, redirect, removeTrailingSlash, replaceEqualDeep, resolveManifestAssetLink, resolvePath, restoreScroll, retainSearchParams, rootRouteId, scrollRestorationCache, setupScrollRestoration, storageKey, stringifySearchWith, stripSearchParams, trailingSlashOptions, trimPath, trimPathLeft, trimPathRight };
24
+ export { BaseRootRoute, BaseRoute, BaseRouteApi, DEFAULT_PROTOCOL_ALLOWLIST, PathParamError, RawStream, RouterCore, SearchParamError, TSR_DEFERRED_PROMISE, buildDevStylesUrl, cleanPath, composeRewrites, createControlledPromise, createNonReactiveMutableStore, createNonReactiveReadonlyStore, createRawStreamDeserializePlugin, createRawStreamRPCPlugin, createRouterConfig, createSerializationAdapter, decode, deepEqual, defaultGetScrollRestorationKey, defaultParseSearch, defaultSerializeError, defaultSerovalPlugins, defaultStringifySearch, defer, encode, escapeHtml, exactPathTest, executeRewriteInput, functionalUpdate, getAssetCrossOrigin, getElementScrollRestorationEntry, getInitialRouterState, getLocationChangeInfo, getMatchedRoutes, handleHashScroll, interpolatePath, invariant, isDangerousProtocol, isMatch, isModuleNotFoundError, isNotFound, isPlainArray, isPlainObject, isRedirect, isResolvedRedirect, joinPaths, lazyFn, makeSerovalPlugin, makeSsrSerovalPlugin, notFound, parseRedirect, parseSearchWith, preloadWarning, redirect, removeTrailingSlash, replaceEqualDeep, resolveManifestAssetLink, resolvePath, retainSearchParams, rootRouteId, scrollRestorationCache, setupScrollRestoration, storageKey, stringifySearchWith, stripSearchParams, trailingSlashOptions, trimPath, trimPathLeft, trimPathRight };
@@ -0,0 +1,6 @@
1
+ export default function (options: {
2
+ storageKey: string;
3
+ key?: string;
4
+ behavior?: ScrollToOptions['behavior'];
5
+ shouldScrollRestoration?: boolean;
6
+ }): void;
@@ -0,0 +1,6 @@
1
+ //#region src/scroll-restoration-inline.ts?script-string
2
+ var scroll_restoration_inline_default = "function(t){let s;try{s=JSON.parse(sessionStorage.getItem(t.storageKey)||\"{}\")}catch(e){console.error(e);return}const c=t.key||window.history.state?.__TSR_key,r=c?s[c]:void 0;if(t.shouldScrollRestoration&&r&&typeof r==\"object\"&&Object.keys(r).length>0){for(const e in r){const o=r[e];if(!o||typeof o!=\"object\")continue;const l=o.scrollX,i=o.scrollY;if(!(!Number.isFinite(l)||!Number.isFinite(i))){if(e===\"window\")window.scrollTo({top:i,left:l,behavior:t.behavior});else if(e){let n;try{n=document.querySelector(e)}catch{continue}n&&(n.scrollLeft=l,n.scrollTop=i)}}}return}const a=window.location.hash.split(\"#\",2)[1];if(a){const e=window.history.state?.__hashScrollIntoViewOptions??!0;if(e){const o=document.getElementById(a);o&&o.scrollIntoView(e)}return}window.scrollTo({top:0,left:0,behavior:t.behavior})}";
3
+ //#endregion
4
+ export { scroll_restoration_inline_default as default };
5
+
6
+ //# sourceMappingURL=scroll-restoration-inline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-restoration-inline.js","names":[],"sources":["../../src/scroll-restoration-inline.ts?script-string"],"sourcesContent":["export default function (options: {\n storageKey: string\n key?: string\n behavior?: ScrollToOptions['behavior']\n shouldScrollRestoration?: boolean\n}) {\n let byKey\n\n try {\n byKey = JSON.parse(sessionStorage.getItem(options.storageKey) || '{}')\n } catch (error) {\n console.error(error)\n return\n }\n\n const resolvedKey = options.key || window.history.state?.__TSR_key\n const elementEntries = resolvedKey ? byKey[resolvedKey] : undefined\n\n if (\n options.shouldScrollRestoration &&\n elementEntries &&\n typeof elementEntries === 'object' &&\n Object.keys(elementEntries).length > 0\n ) {\n for (const elementSelector in elementEntries) {\n const entry = elementEntries[elementSelector]\n\n if (!entry || typeof entry !== 'object') {\n continue\n }\n\n const scrollX = entry.scrollX\n const scrollY = entry.scrollY\n\n if (!Number.isFinite(scrollX) || !Number.isFinite(scrollY)) {\n continue\n }\n\n if (elementSelector === 'window') {\n window.scrollTo({\n top: scrollY,\n left: scrollX,\n behavior: options.behavior,\n })\n } else if (elementSelector) {\n let element\n\n try {\n element = document.querySelector(elementSelector)\n } catch {\n continue\n }\n\n if (element) {\n element.scrollLeft = scrollX\n element.scrollTop = scrollY\n }\n }\n }\n\n return\n }\n\n const hash = window.location.hash.split('#', 2)[1]\n\n if (hash) {\n const hashScrollIntoViewOptions =\n window.history.state?.__hashScrollIntoViewOptions ?? true\n\n if (hashScrollIntoViewOptions) {\n const el = document.getElementById(hash)\n if (el) {\n el.scrollIntoView(hashScrollIntoViewOptions)\n }\n }\n\n return\n }\n\n window.scrollTo({ top: 0, left: 0, behavior: options.behavior })\n}\n"],"mappings":";AAAA,IAAA,oCAAe"}
@@ -0,0 +1,2 @@
1
+ import { AnyRouter } from '../router.js';
2
+ export declare function getScrollRestorationScriptForRouter(_router: AnyRouter): null;
@@ -0,0 +1,8 @@
1
+ //#region src/scroll-restoration-script/client.ts
2
+ function getScrollRestorationScriptForRouter(_router) {
3
+ return null;
4
+ }
5
+ //#endregion
6
+ export { getScrollRestorationScriptForRouter };
7
+
8
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../../src/scroll-restoration-script/client.ts"],"sourcesContent":["import type { AnyRouter } from '../router'\n\nexport function getScrollRestorationScriptForRouter(_router: AnyRouter) {\n return null\n}\n"],"mappings":";AAEA,SAAgB,oCAAoC,SAAoB;AACtE,QAAO"}
@@ -0,0 +1,2 @@
1
+ import { AnyRouter } from '../router.js';
2
+ export declare function getScrollRestorationScriptForRouter(router: AnyRouter): string | null;
@@ -0,0 +1,29 @@
1
+ import { escapeHtml } from "../utils.js";
2
+ import { defaultGetScrollRestorationKey, storageKey } from "../scroll-restoration.js";
3
+ import scroll_restoration_inline_default from "../scroll-restoration-inline.js";
4
+ //#region src/scroll-restoration-script/server.ts
5
+ var defaultInlineScrollRestorationScript = `(${scroll_restoration_inline_default})(${escapeHtml(JSON.stringify({
6
+ storageKey,
7
+ shouldScrollRestoration: true
8
+ }))})`;
9
+ function getScrollRestorationScript(options) {
10
+ if (options.storageKey === "tsr-scroll-restoration-v1_3" && options.shouldScrollRestoration === true && options.key === void 0 && options.behavior === void 0) return defaultInlineScrollRestorationScript;
11
+ return `(${scroll_restoration_inline_default})(${escapeHtml(JSON.stringify(options))})`;
12
+ }
13
+ function getScrollRestorationScriptForRouter(router) {
14
+ if (typeof router.options.scrollRestoration === "function" && !router.options.scrollRestoration({ location: router.latestLocation })) return null;
15
+ const getKey = router.options.getScrollRestorationKey;
16
+ if (!getKey) return defaultInlineScrollRestorationScript;
17
+ const location = router.latestLocation;
18
+ const userKey = getKey(location);
19
+ if (userKey === defaultGetScrollRestorationKey(location)) return defaultInlineScrollRestorationScript;
20
+ return getScrollRestorationScript({
21
+ storageKey,
22
+ shouldScrollRestoration: true,
23
+ key: userKey
24
+ });
25
+ }
26
+ //#endregion
27
+ export { getScrollRestorationScriptForRouter };
28
+
29
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","names":[],"sources":["../../../src/scroll-restoration-script/server.ts"],"sourcesContent":["import minifiedScrollRestorationScript from '../scroll-restoration-inline?script-string'\nimport {\n defaultGetScrollRestorationKey,\n storageKey,\n} from '../scroll-restoration'\nimport { escapeHtml } from '../utils'\nimport type { AnyRouter } from '../router'\n\ntype InlineScrollRestorationScriptOptions = {\n storageKey: string\n key?: string\n behavior?: ScrollToOptions['behavior']\n shouldScrollRestoration?: boolean\n}\n\nconst defaultInlineScrollRestorationScript = `(${minifiedScrollRestorationScript})(${escapeHtml(\n JSON.stringify({\n storageKey,\n shouldScrollRestoration: true,\n } satisfies InlineScrollRestorationScriptOptions),\n)})`\n\nfunction getScrollRestorationScript(\n options: InlineScrollRestorationScriptOptions,\n) {\n if (\n options.storageKey === storageKey &&\n options.shouldScrollRestoration === true &&\n options.key === undefined &&\n options.behavior === undefined\n ) {\n return defaultInlineScrollRestorationScript\n }\n\n return `(${minifiedScrollRestorationScript})(${escapeHtml(JSON.stringify(options))})`\n}\n\nexport function getScrollRestorationScriptForRouter(router: AnyRouter) {\n if (\n typeof router.options.scrollRestoration === 'function' &&\n !router.options.scrollRestoration({ location: router.latestLocation })\n ) {\n return null\n }\n\n const getKey = router.options.getScrollRestorationKey\n if (!getKey) {\n return defaultInlineScrollRestorationScript\n }\n\n const location = router.latestLocation\n const userKey = getKey(location)\n const defaultKey = defaultGetScrollRestorationKey(location)\n\n if (userKey === defaultKey) {\n return defaultInlineScrollRestorationScript\n }\n\n return getScrollRestorationScript({\n storageKey,\n shouldScrollRestoration: true,\n key: userKey,\n })\n}\n"],"mappings":";;;;AAeA,IAAM,uCAAuC,IAAI,kCAAgC,IAAI,WACnF,KAAK,UAAU;CACb;CACA,yBAAyB;CAC1B,CAAgD,CAClD,CAAC;AAEF,SAAS,2BACP,SACA;AACA,KACE,QAAQ,eAAA,iCACR,QAAQ,4BAA4B,QACpC,QAAQ,QAAQ,KAAA,KAChB,QAAQ,aAAa,KAAA,EAErB,QAAO;AAGT,QAAO,IAAI,kCAAgC,IAAI,WAAW,KAAK,UAAU,QAAQ,CAAC,CAAC;;AAGrF,SAAgB,oCAAoC,QAAmB;AACrE,KACE,OAAO,OAAO,QAAQ,sBAAsB,cAC5C,CAAC,OAAO,QAAQ,kBAAkB,EAAE,UAAU,OAAO,gBAAgB,CAAC,CAEtE,QAAO;CAGT,MAAM,SAAS,OAAO,QAAQ;AAC9B,KAAI,CAAC,OACH,QAAO;CAGT,MAAM,WAAW,OAAO;CACxB,MAAM,UAAU,OAAO,SAAS;AAGhC,KAAI,YAFe,+BAA+B,SAAS,CAGzD,QAAO;AAGT,QAAO,2BAA2B;EAChC;EACA,yBAAyB;EACzB,KAAK;EACN,CAAC"}
@@ -1,26 +1,22 @@
1
1
  import { AnyRouter } from './router.js';
2
2
  import { ParsedLocation } from './location.js';
3
3
  import { NonNullableUpdater } from './utils.js';
4
- import { HistoryLocation } from '@tanstack/history';
5
4
  export type ScrollRestorationEntry = {
6
5
  scrollX: number;
7
6
  scrollY: number;
8
7
  };
9
- export type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>;
10
- export type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>;
11
- export type ScrollRestorationCache = {
12
- state: ScrollRestorationByKey;
8
+ type ScrollRestorationByElement = Record<string, ScrollRestorationEntry>;
9
+ type ScrollRestorationByKey = Record<string, ScrollRestorationByElement>;
10
+ type ScrollRestorationCache = {
11
+ readonly state: ScrollRestorationByKey;
13
12
  set: (updater: NonNullableUpdater<ScrollRestorationByKey>) => void;
13
+ persist: () => void;
14
14
  };
15
15
  export type ScrollRestorationOptions = {
16
16
  getKey?: (location: ParsedLocation) => string;
17
17
  scrollBehavior?: ScrollToOptions['behavior'];
18
18
  };
19
- /** SessionStorage key used to persist scroll restoration state. */
20
- /** SessionStorage key used to store scroll positions across navigations. */
21
- /** SessionStorage key used to store scroll positions across navigations. */
22
19
  export declare const storageKey = "tsr-scroll-restoration-v1_3";
23
- /** In-memory handle to the persisted scroll restoration cache. */
24
20
  export declare const scrollRestorationCache: ScrollRestorationCache | null;
25
21
  /**
26
22
  * The default `getKey` function for `useScrollRestoration`.
@@ -28,34 +24,15 @@ export declare const scrollRestorationCache: ScrollRestorationCache | null;
28
24
  *
29
25
  * The `location.href` is used as a fallback to support the use case where the location state is not available like the initial render.
30
26
  */
31
- /**
32
- * Default scroll restoration cache key: location state key or full href.
33
- */
34
27
  export declare const defaultGetScrollRestorationKey: (location: ParsedLocation) => string;
35
- /** Best-effort nth-child CSS selector for a given element. */
36
- export declare function getCssSelector(el: any): string;
37
- export declare function restoreScroll({ storageKey, key, behavior, shouldScrollRestoration, scrollToTopSelectors, location, }: {
38
- storageKey: string;
39
- key?: string;
40
- behavior?: ScrollToOptions['behavior'];
41
- shouldScrollRestoration?: boolean;
42
- scrollToTopSelectors?: Array<string | (() => Element | null | undefined)>;
43
- location?: HistoryLocation;
44
- }): void;
45
- /** Setup global listeners and hooks to support scroll restoration. */
46
- /** Setup global listeners and hooks to support scroll restoration. */
28
+ export declare function getElementScrollRestorationEntry(router: AnyRouter, options: ({
29
+ id: string;
30
+ getElement?: () => Window | Element | undefined | null;
31
+ } | {
32
+ id?: string;
33
+ getElement: () => Window | Element | undefined | null;
34
+ }) & {
35
+ getKey?: (location: ParsedLocation) => string;
36
+ }): ScrollRestorationEntry | undefined;
47
37
  export declare function setupScrollRestoration(router: AnyRouter, force?: boolean): void;
48
- /**
49
- * @private
50
- * Handles hash-based scrolling after navigation completes.
51
- * To be used in framework-specific <Transitioner> components during the onResolved event.
52
- *
53
- * Provides hash scrolling for programmatic navigation when default browser handling is prevented.
54
- * @param router The router instance containing current location and state
55
- */
56
- /**
57
- * @private
58
- * Handles hash-based scrolling after navigation completes.
59
- * To be used in framework-specific Transitioners.
60
- */
61
- export declare function handleHashScroll(router: AnyRouter): void;
38
+ export {};