{"version":3,"file":"scroll-restoration-inline.cjs","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"}