{"version":3,"file":"scroll-restoration-inline.cjs","names":[],"sources":["../../src/scroll-restoration-inline.ts?script-string"],"sourcesContent":["export default function (storageKey: string, key?: string) {\n  let byKey\n\n  try {\n    byKey = JSON.parse(sessionStorage.getItem(storageKey) || '{}')\n  } catch {\n    return\n  }\n\n  const elementEntries = byKey?.[key || history.state?.__TSR_key]\n  let windowRestored = false\n\n  for (const elementSelector in elementEntries) {\n    const entry = elementEntries[elementSelector]\n    const scrollX = entry?.scrollX\n    const scrollY = entry?.scrollY\n\n    if (Number.isFinite(scrollX) && Number.isFinite(scrollY)) {\n      if (elementSelector === 'window') {\n        scrollTo(scrollX, scrollY)\n        windowRestored = true\n      } else if (elementSelector) {\n        try {\n          const element = document.querySelector(elementSelector)\n          if (element) {\n            element.scrollLeft = scrollX\n            element.scrollTop = scrollY\n          }\n        } catch {}\n      }\n    }\n  }\n\n  if (windowRestored) return\n\n  const hash = location.hash.slice(1)\n\n  if (hash) {\n    const hashScrollIntoViewOptions =\n      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  scrollTo(0, 0)\n}\n"],"mappings":";AAAA,IAAA,oCAAe"}