{"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface NavigateOptions {\n  ignoreBlocker?: boolean\n}\n\ntype SubscriberHistoryAction =\n  | {\n      type: Exclude<HistoryAction, 'GO'>\n    }\n  | {\n      type: 'GO'\n      index: number\n    }\n\ntype SubscriberArgs = {\n  location: HistoryLocation\n  action: SubscriberHistoryAction\n}\n\nexport interface RouterHistory {\n  location: HistoryLocation\n  length: number\n  subscribers: Set<(opts: SubscriberArgs) => void>\n  subscribe: (cb: (opts: SubscriberArgs) => void) => () => void\n  push: (path: string, state?: any, navigateOpts?: NavigateOptions) => void\n  replace: (path: string, state?: any, navigateOpts?: NavigateOptions) => void\n  go: (index: number, navigateOpts?: NavigateOptions) => void\n  back: (navigateOpts?: NavigateOptions) => void\n  forward: (navigateOpts?: NavigateOptions) => void\n  canGoBack: () => boolean\n  createHref: (href: string) => string\n  block: (blocker: NavigationBlocker) => () => void\n  flush: () => void\n  destroy: () => void\n  notify: (action: SubscriberHistoryAction) => void\n  _getBlockers: () => Array<NavigationBlocker>\n  _ignoreSubscribers?: boolean\n  _ignoreNextBeforeUnload?: (href: string) => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n  state: ParsedHistoryState\n}\n\nexport interface ParsedPath {\n  href: string\n  pathname: string\n  search: string\n  hash: string\n}\n\nexport interface HistoryState {}\n\nexport type ParsedHistoryState = HistoryState & {\n  key?: string // TODO: Remove in v2 - use __TSR_key instead\n  __TSR_key?: string\n  __TSR_index: number\n}\n\ntype ShouldAllowNavigation = any\n\nexport type HistoryAction = 'PUSH' | 'REPLACE' | 'FORWARD' | 'BACK' | 'GO'\n\nexport type BlockerFnArgs = {\n  currentLocation: HistoryLocation\n  nextLocation: HistoryLocation\n  action: HistoryAction\n}\n\nexport type BlockerFn = (\n  args: BlockerFnArgs,\n) => Promise<ShouldAllowNavigation> | ShouldAllowNavigation\n\nexport type NavigationBlocker = {\n  blockerFn: BlockerFn\n  enableBeforeUnload?: (() => boolean) | boolean\n}\n\ntype TryNavigateArgs = {\n  task: () => void\n  type: 'PUSH' | 'REPLACE' | 'BACK' | 'FORWARD' | 'GO'\n  navigateOpts?: NavigateOptions\n} & (\n  | {\n      type: 'PUSH' | 'REPLACE'\n      path: string\n      state: any\n    }\n  | {\n      type: 'BACK' | 'FORWARD' | 'GO'\n    }\n)\n\nconst stateIndexKey = '__TSR_index'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\n/**\n * Turn protocol-relative inputs such as \"//evil.example\" into paths\n * such as \"/evil.example\", keeping navigation on the current origin.\n *\n * For HTTP(S) URLs, WHATWG parsing ignores leading C0 controls and spaces,\n * removes tabs/newlines, and treats backslashes as slashes, so inputs like\n * \"/\\evil.example\" also need normalization. This only allocates when those\n * rules would make the input protocol-relative.\n */\n// eslint-disable-next-line no-control-regex\nconst protocolRelativePrefix = /^[\\x00-\\x20]*(?:[\\\\/][\\t\\n\\r]*){2,}/\n\nexport function normalizeProtocolRelative(url: string): string {\n  const match = protocolRelativePrefix.exec(url)\n  return match ? '/' + url.slice(match[0].length) : url\n}\n\nfunction normalizeHref(href: string): string {\n  // eslint-disable-next-line no-control-regex\n  if (/[\\x00-\\x1f\\x7f]/.test(href)) {\n    // eslint-disable-next-line no-control-regex\n    href = href.replace(/[\\x00-\\x1f\\x7f]/g, (character) =>\n      '\\t\\n\\r'.includes(character) ? '' : encodeURIComponent(character),\n    )\n  }\n  return normalizeProtocolRelative(href)\n}\n\nexport function createHistory(opts: {\n  getLocation: () => HistoryLocation\n  getLength: () => number\n  pushState: (path: string, state: any) => void\n  replaceState: (path: string, state: any) => void\n  go: (n: number, ignoreBlocker: boolean) => void\n  back: (ignoreBlocker: boolean) => void\n  forward: (ignoreBlocker: boolean) => void\n  createHref: (path: string) => string\n  flush?: () => void\n  destroy?: () => void\n  onBlocked?: () => void\n  getBlockers?: () => Array<NavigationBlocker>\n  setBlockers?: (blockers: Array<NavigationBlocker>) => void\n  // Avoid notifying on forward/back/go, used for browser history as we already get notified by the popstate event\n  notifyOnIndexChange?: boolean\n}): RouterHistory {\n  let location = opts.getLocation()\n  const subscribers = new Set<(opts: SubscriberArgs) => void>()\n\n  const notify = (action: SubscriberHistoryAction) => {\n    location = opts.getLocation()\n    subscribers.forEach((subscriber) => subscriber({ location, action }))\n  }\n\n  const handleIndexChange = (action: SubscriberHistoryAction) => {\n    if (opts.notifyOnIndexChange ?? true) notify(action)\n    else location = opts.getLocation()\n  }\n\n  const tryNavigation = async (args: TryNavigateArgs) => {\n    const blockers = args.navigateOpts?.ignoreBlocker\n      ? undefined\n      : opts.getBlockers?.()\n    if (\n      typeof document !== 'undefined' &&\n      blockers?.length &&\n      (args.type === 'PUSH' || args.type === 'REPLACE')\n    ) {\n      for (const blocker of blockers) {\n        const nextLocation = parseHref(args.path, args.state)\n        const isBlocked = await blocker.blockerFn({\n          currentLocation: location,\n          nextLocation,\n          action: args.type,\n        })\n        if (isBlocked) {\n          opts.onBlocked?.()\n          return\n        }\n      }\n    }\n\n    args.task()\n  }\n\n  return {\n    get location() {\n      return location\n    },\n    get length() {\n      return opts.getLength()\n    },\n    subscribers,\n    subscribe: (cb: (opts: SubscriberArgs) => void) => {\n      subscribers.add(cb)\n\n      return () => {\n        subscribers.delete(cb)\n      }\n    },\n    push: (path, state, navigateOpts) => {\n      const currentIndex = location.state[stateIndexKey]\n      state = assignKeyAndIndex(currentIndex + 1, state)\n      tryNavigation({\n        task: () => {\n          opts.pushState(path, state)\n          notify({ type: 'PUSH' })\n        },\n        navigateOpts,\n        type: 'PUSH',\n        path,\n        state,\n      })\n    },\n    replace: (path, state, navigateOpts) => {\n      const currentIndex = location.state[stateIndexKey]\n      state = assignKeyAndIndex(currentIndex, state)\n      tryNavigation({\n        task: () => {\n          opts.replaceState(path, state)\n          notify({ type: 'REPLACE' })\n        },\n        navigateOpts,\n        type: 'REPLACE',\n        path,\n        state,\n      })\n    },\n    go: (index, navigateOpts) => {\n      tryNavigation({\n        task: () => {\n          opts.go(index, navigateOpts?.ignoreBlocker ?? false)\n          handleIndexChange({ type: 'GO', index })\n        },\n        navigateOpts,\n        type: 'GO',\n      })\n    },\n    back: (navigateOpts) => {\n      tryNavigation({\n        task: () => {\n          opts.back(navigateOpts?.ignoreBlocker ?? false)\n          handleIndexChange({ type: 'BACK' })\n        },\n        navigateOpts,\n        type: 'BACK',\n      })\n    },\n    forward: (navigateOpts) => {\n      tryNavigation({\n        task: () => {\n          opts.forward(navigateOpts?.ignoreBlocker ?? false)\n          handleIndexChange({ type: 'FORWARD' })\n        },\n        navigateOpts,\n        type: 'FORWARD',\n      })\n    },\n    canGoBack: () => location.state[stateIndexKey] !== 0,\n    createHref: (str) => opts.createHref(str),\n    block: (blocker) => {\n      if (!opts.setBlockers) return () => {}\n      const blockers = opts.getBlockers?.() ?? []\n      opts.setBlockers([...blockers, blocker])\n\n      return () => {\n        const blockers = opts.getBlockers?.() ?? []\n        opts.setBlockers?.(blockers.filter((b) => b !== blocker))\n      }\n    },\n    flush: () => opts.flush?.(),\n    destroy: () => opts.destroy?.(),\n    notify,\n    _getBlockers: () => opts.getBlockers?.() ?? [],\n  }\n}\n\nfunction assignKeyAndIndex(index: number, state: HistoryState | undefined) {\n  const key = createRandomKey()\n  return {\n    ...state,\n    key, // TODO: Remove in v2 - use __TSR_key instead\n    __TSR_key: key,\n    [stateIndexKey]: index,\n  } as ParsedHistoryState\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n  parseLocation?: () => HistoryLocation\n  createHref?: (path: string) => string\n  window?: any\n}): RouterHistory {\n  const win =\n    opts?.window ??\n    (typeof document !== 'undefined' ? window : (undefined as any))\n\n  const originalPushState = win.history.pushState\n  const originalReplaceState = win.history.replaceState\n\n  let blockers: Array<NavigationBlocker> = []\n  const _getBlockers = () => blockers\n  const _setBlockers = (newBlockers: Array<NavigationBlocker>) =>\n    (blockers = newBlockers)\n\n  const createHref = (path: string) =>\n    normalizeHref(opts?.createHref ? opts.createHref(path) : path)\n  const parseLocation =\n    opts?.parseLocation ??\n    (() =>\n      parseHref(\n        `${win.location.pathname}${win.location.search}${win.location.hash}`,\n        win.history.state,\n      ))\n\n  // Ensure there is always a key to start\n  if (!win.history.state?.__TSR_key && !win.history.state?.key) {\n    const addedKey = createRandomKey()\n    win.history.replaceState(\n      {\n        [stateIndexKey]: 0,\n        key: addedKey, // TODO: Remove in v2 - use __TSR_key instead\n        __TSR_key: addedKey,\n      },\n      '',\n    )\n  }\n\n  let currentLocation = parseLocation()\n  let rollbackLocation: HistoryLocation | undefined\n\n  let nextPopIsGo = false\n  let ignoreNextPop = false\n  // TODO: An ignored traversal past a history boundary emits neither popstate\n  // nor beforeunload, leaving these bypasses active for a later navigation.\n  // The History API provides no completion signal for such no-op traversals.\n  let skipBlockerNextPop = false\n  let ignoreNextBeforeUnload = false\n\n  const getLocation = () => currentLocation\n\n  let next:\n    | undefined\n    | [\n        // The latest location that we were attempting to push/replace\n        href: string,\n        // The latest state that we were attempting to push/replace\n        state: any,\n        // Whether any queued update needs to push rather than replace\n        isPush: boolean,\n      ]\n\n  // This function flushes the next update to the browser history\n  const flush = () => {\n    if (!next) {\n      return\n    }\n\n    // We need to ignore any updates to the subscribers while we update the browser history\n    history._ignoreSubscribers = true\n\n    // Update the browser history\n    ;(next[2 /* is push */] ? win.history.pushState : win.history.replaceState)(\n      next[1 /* state */],\n      '',\n      next[0 /* href */],\n    )\n\n    // Stop ignoring subscriber updates\n    history._ignoreSubscribers = false\n\n    // Clear the queued action after it reaches browser history.\n    next = undefined\n    rollbackLocation = undefined\n  }\n\n  // This function queues up a call to update the browser history\n  const queueHistoryAction = (\n    isPush: boolean,\n    destHref: string,\n    state: any,\n  ) => {\n    // A formatter changes the URL space and must receive the original input.\n    // Otherwise parseHref below already produces the browser destination.\n    const href = opts?.createHref ? createHref(destHref) : undefined\n    const hasPendingAction = !!next\n\n    if (!hasPendingAction) {\n      rollbackLocation = currentLocation\n    }\n\n    // Keep the optimistic location in the router's logical URL space.\n    currentLocation = parseHref(destHref, state)\n\n    // Keep track of the next location we need to flush to the URL\n    next = [\n      href ?? currentLocation.href,\n      state,\n      next?.[2 /* is push */] || isPush,\n    ]\n\n    if (!hasPendingAction) {\n      // Schedule an update to the browser history\n      queueMicrotask(() => flush())\n    }\n  }\n\n  // NOTE: this function can probably be removed\n  const onPushPop = (type: 'PUSH' | 'REPLACE') => {\n    currentLocation = parseLocation()\n    history.notify({ type })\n  }\n\n  const onPushPopEvent = async () => {\n    // Same-document traversals do not fire beforeunload, so consume their\n    // exemption here instead of carrying it into a later document navigation.\n    ignoreNextBeforeUnload = false\n\n    if (ignoreNextPop) {\n      ignoreNextPop = false\n      return\n    }\n\n    const nextLocation = parseLocation()\n    const delta =\n      nextLocation.state[stateIndexKey] - currentLocation.state[stateIndexKey]\n    const isForward = delta === 1\n    const isBack = delta === -1\n    const isGo = (!isForward && !isBack) || nextPopIsGo\n    nextPopIsGo = false\n\n    const action = isGo ? 'GO' : isBack ? 'BACK' : 'FORWARD'\n    const notify: SubscriberHistoryAction = isGo\n      ? {\n          type: 'GO',\n          index: delta,\n        }\n      : {\n          type: isBack ? 'BACK' : 'FORWARD',\n        }\n\n    if (skipBlockerNextPop) {\n      skipBlockerNextPop = false\n    } else {\n      const blockers = _getBlockers()\n      if (typeof document !== 'undefined' && blockers.length) {\n        for (const blocker of blockers) {\n          const isBlocked = await blocker.blockerFn({\n            currentLocation,\n            nextLocation,\n            action,\n          })\n          if (isBlocked) {\n            ignoreNextPop = true\n            win.history.go(-delta)\n            history.notify(notify)\n            return\n          }\n        }\n      }\n    }\n\n    currentLocation = parseLocation()\n    history.notify(notify)\n  }\n\n  const onBeforeUnload = (e: BeforeUnloadEvent) => {\n    if (ignoreNextBeforeUnload) {\n      ignoreNextBeforeUnload = false\n      return\n    }\n\n    let shouldBlock = false\n\n    // If one blocker has a non-disabled beforeUnload, we should block\n    const blockers = _getBlockers()\n    if (typeof document !== 'undefined' && blockers.length) {\n      for (const blocker of blockers) {\n        const shouldHaveBeforeUnload = blocker.enableBeforeUnload ?? true\n        if (shouldHaveBeforeUnload === true) {\n          shouldBlock = true\n          break\n        }\n\n        if (\n          typeof shouldHaveBeforeUnload === 'function' &&\n          shouldHaveBeforeUnload() === true\n        ) {\n          shouldBlock = true\n          break\n        }\n      }\n    }\n\n    if (shouldBlock) {\n      e.preventDefault()\n      return (e.returnValue = '')\n    }\n    return\n  }\n\n  const history = createHistory({\n    getLocation,\n    getLength: () => win.history.length,\n    pushState: (href, state) => queueHistoryAction(true, href, state),\n    replaceState: (href, state) => queueHistoryAction(false, href, state),\n    back: (ignoreBlocker) => {\n      if (ignoreBlocker) {\n        skipBlockerNextPop = true\n        ignoreNextBeforeUnload = true\n      }\n      return win.history.back()\n    },\n    forward: (ignoreBlocker) => {\n      if (ignoreBlocker) {\n        skipBlockerNextPop = true\n        ignoreNextBeforeUnload = true\n      }\n      win.history.forward()\n    },\n    go: (n, ignoreBlocker) => {\n      nextPopIsGo = true\n      if (ignoreBlocker) {\n        skipBlockerNextPop = true\n        ignoreNextBeforeUnload = true\n      }\n      win.history.go(n)\n    },\n    createHref,\n    flush,\n    destroy: () => {\n      win.history.pushState = originalPushState\n      win.history.replaceState = originalReplaceState\n      win.removeEventListener(beforeUnloadEvent, onBeforeUnload, {\n        capture: true,\n      })\n      win.removeEventListener(popStateEvent, onPushPopEvent)\n    },\n    onBlocked: () => {\n      // If a navigation is blocked, we need to rollback the location\n      // that we optimistically updated in memory.\n      if (rollbackLocation && currentLocation !== rollbackLocation) {\n        currentLocation = rollbackLocation\n      }\n    },\n    getBlockers: _getBlockers,\n    setBlockers: _setBlockers,\n    notifyOnIndexChange: false,\n  })\n\n  history._ignoreNextBeforeUnload = (href) => {\n    ignoreNextBeforeUnload = false\n    try {\n      href = new URL(href, win.document.baseURI).href\n      // External handlers and same-document fragments may emit neither\n      // beforeunload nor popstate, leaving an exemption for a later departure.\n      ignoreNextBeforeUnload =\n        /^https?:/.test(href) &&\n        (!href.includes('#') ||\n          href.split('#')[0] !== win.location.href.split('#')[0])\n    } catch {\n      // Invalid URLs cannot unload the document.\n    }\n  }\n\n  win.addEventListener(beforeUnloadEvent, onBeforeUnload, { capture: true })\n  win.addEventListener(popStateEvent, onPushPopEvent)\n\n  win.history.pushState = function (...args: Array<any>) {\n    const res = originalPushState.apply(win.history, args as any)\n    if (!history._ignoreSubscribers) onPushPop('PUSH')\n    return res\n  }\n\n  win.history.replaceState = function (...args: Array<any>) {\n    const res = originalReplaceState.apply(win.history, args as any)\n    if (!history._ignoreSubscribers) onPushPop('REPLACE')\n    return res\n  }\n\n  return history\n}\n\n/**\n * Create a hash-based history implementation.\n * Useful for static hosts or environments without server URL rewriting.\n * @link https://tanstack.com/router/latest/docs/framework/react/guide/history-types\n */\nexport function createHashHistory(opts?: { window?: any }): RouterHistory {\n  const win =\n    opts?.window ??\n    (typeof document !== 'undefined' ? window : (undefined as any))\n  return createBrowserHistory({\n    window: win,\n    parseLocation: () => {\n      // `#/path?query#fragment`: the router's own fragment starts at the\n      // second '#'. A non-empty `location.hash` always starts with '#'.\n      const hash = win.location.hash\n      let hashIndex = hash.indexOf('#', 1)\n      if (hashIndex < 0) {\n        hashIndex = hash.length\n      }\n      return parseHref(\n        `${hash ? hash.slice(1, hashIndex) : '/'}${win.location.search}${hash.slice(hashIndex)}`,\n        win.history.state,\n      )\n    },\n    createHref: (href) =>\n      `${win.location.pathname}${win.location.search}#${href}`,\n  })\n}\n\n/**\n * Create an in-memory history implementation.\n * Ideal for server rendering, tests, and non-DOM environments.\n * @link https://tanstack.com/router/latest/docs/framework/react/guide/history-types\n */\nexport function createMemoryHistory(\n  opts: {\n    initialEntries: Array<string>\n    initialIndex?: number\n  } = {\n    initialEntries: ['/'],\n  },\n): RouterHistory {\n  const entries = opts.initialEntries\n  let index = opts.initialIndex\n    ? Math.min(Math.max(opts.initialIndex, 0), entries.length - 1)\n    : entries.length - 1\n  const states = entries.map((_entry, index) =>\n    assignKeyAndIndex(index, undefined),\n  )\n\n  const getLocation = () => parseHref(entries[index]!, states[index])\n\n  let blockers: Array<NavigationBlocker> = []\n  const _getBlockers = () => blockers\n  const _setBlockers = (newBlockers: Array<NavigationBlocker>) =>\n    (blockers = newBlockers)\n\n  return createHistory({\n    getLocation,\n    getLength: () => entries.length,\n    pushState: (path, state) => {\n      // Removes all subsequent entries after the current index to start a new branch\n      index = index < entries.length - 1 ? index + 1 : entries.length\n      states[index] = state\n      entries[index] = path\n      if (index < entries.length - 1) {\n        entries.length = index + 1\n        states.length = index + 1\n      }\n    },\n    replaceState: (path, state) => {\n      states[index] = state\n      entries[index] = path\n    },\n    back: () => {\n      index = Math.max(index - 1, 0)\n    },\n    forward: () => {\n      index = Math.min(index + 1, entries.length - 1)\n    },\n    go: (n) => {\n      index = Math.min(Math.max(index + n, 0), entries.length - 1)\n    },\n    createHref: normalizeHref,\n    getBlockers: _getBlockers,\n    setBlockers: _setBlockers,\n  })\n}\n\nconst noop = () => {}\n\nclass ServerHistory implements RouterHistory {\n  declare private _subscribers?: RouterHistory['subscribers']\n\n  constructor(public location: HistoryLocation) {}\n\n  get length() {\n    return 1\n  }\n\n  // Preserve the history interface without allocating a Set for each request.\n  get subscribers() {\n    return (this._subscribers ??= new Set())\n  }\n\n  subscribe() {\n    return noop\n  }\n\n  push() {}\n  replace() {}\n  go() {}\n  back() {}\n  forward() {}\n\n  canGoBack() {\n    return false\n  }\n\n  createHref(href: string) {\n    return normalizeHref(href)\n  }\n\n  block() {\n    return noop\n  }\n\n  flush() {}\n  destroy() {}\n  notify() {}\n\n  _getBlockers(): Array<NavigationBlocker> {\n    return []\n  }\n}\n\n/** A fixed request location; server navigation is a no-op. */\nexport function createServerHistory(href: string): RouterHistory {\n  return new ServerHistory(parseHref(href, undefined))\n}\n\nexport function parseHref(\n  href: string,\n  state: ParsedHistoryState | undefined,\n): HistoryLocation {\n  const sanitizedHref = normalizeHref(href)\n  const hashIndex = sanitizedHref.indexOf('#')\n  const searchIndex = sanitizedHref.indexOf('?')\n  if (!state) {\n    const key = createRandomKey()\n    state = { [stateIndexKey]: 0, key, __TSR_key: key }\n  }\n\n  return {\n    href: sanitizedHref,\n    pathname: sanitizedHref.slice(\n      0,\n      hashIndex > -1\n        ? searchIndex > -1\n          ? Math.min(hashIndex, searchIndex)\n          : hashIndex\n        : searchIndex > -1\n          ? searchIndex\n          : sanitizedHref.length,\n    ),\n    hash: hashIndex > -1 ? sanitizedHref.slice(hashIndex) : '',\n    search:\n      searchIndex > -1\n        ? sanitizedHref.slice(\n            searchIndex,\n            hashIndex === -1 ? undefined : hashIndex,\n          )\n        : '',\n    state,\n  }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n  return (Math.random() + 1).toString(36).slice(7)\n}\n"],"mappings":";;AAgGA,IAAM,gBAAgB;AACtB,IAAM,gBAAgB;AACtB,IAAM,oBAAoB;;;;;;;;;;AAY1B,IAAM,yBAAyB;AAE/B,SAAgB,0BAA0B,KAAqB;CAC7D,MAAM,QAAQ,uBAAuB,KAAK,GAAG;CAC7C,OAAO,QAAQ,MAAM,IAAI,MAAM,MAAM,EAAE,CAAC,MAAM,IAAI;AACpD;AAEA,SAAS,cAAc,MAAsB;CAE3C,IAAI,kBAAk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