{"ast":null,"code":"\"use strict\";\n\nimport { nanoid } from 'nanoid/non-secure';\nexport function createMemoryHistory() {\n  let index = 0;\n  let items = [];\n  const pending = [];\n  const interrupt = () => {\n    pending.forEach(it => {\n      const cb = it.cb;\n      it.cb = () => cb(true);\n    });\n  };\n  const history = {\n    get index() {\n      const id = window.history.state?.id;\n      if (id) {\n        const index = items.findIndex(item => item.id === id);\n        return index > -1 ? index : 0;\n      }\n      return 0;\n    },\n    get(index) {\n      return items[index];\n    },\n    backIndex({\n      path\n    }) {\n      for (let i = index - 1; i >= 0; i--) {\n        const item = items[i];\n        if (item.path === path) {\n          return i;\n        }\n      }\n      return -1;\n    },\n    push({\n      path,\n      state\n    }) {\n      interrupt();\n      const id = nanoid();\n      items = items.slice(0, index + 1);\n      items.push({\n        path,\n        state,\n        id\n      });\n      index = items.length - 1;\n      window.history.pushState({\n        id\n      }, '', path);\n    },\n    replace({\n      path,\n      state\n    }) {\n      interrupt();\n      const id = window.history.state?.id ?? nanoid();\n      let pathWithHash = path;\n      const hash = pathWithHash.includes('#') ? '' : location.hash;\n      if (!items.length || items.findIndex(item => item.id === id) < 0) {\n        pathWithHash = pathWithHash + hash;\n        items = [{\n          path: pathWithHash,\n          state,\n          id\n        }];\n        index = 0;\n      } else {\n        if (items[index].path === path) {\n          pathWithHash = pathWithHash + hash;\n        }\n        items[index] = {\n          path,\n          state,\n          id\n        };\n      }\n      window.history.replaceState({\n        id\n      }, '', pathWithHash);\n    },\n    go(n) {\n      interrupt();\n      const nextIndex = index + n;\n      const lastItemIndex = items.length - 1;\n      if (n < 0 && !items[nextIndex]) {\n        n = -index;\n        index = 0;\n      } else if (n > 0 && nextIndex > lastItemIndex) {\n        n = lastItemIndex - index;\n        index = lastItemIndex;\n      } else {\n        index = nextIndex;\n      }\n      if (n === 0) {\n        return;\n      }\n      return new Promise((resolve, reject) => {\n        const done = interrupted => {\n          clearTimeout(timer);\n          if (interrupted) {\n            reject(new Error('History was changed during navigation.'));\n            return;\n          }\n          const {\n            title\n          } = window.document;\n          window.document.title = '';\n          window.document.title = title;\n          resolve();\n        };\n        pending.push({\n          ref: done,\n          cb: done\n        });\n        const timer = setTimeout(() => {\n          const foundIndex = pending.findIndex(it => it.ref === done);\n          if (foundIndex > -1) {\n            pending[foundIndex].cb();\n            pending.splice(foundIndex, 1);\n          }\n          index = this.index;\n        }, 100);\n        const onPopState = () => {\n          index = this.index;\n          const last = pending.pop();\n          window.removeEventListener('popstate', onPopState);\n          last?.cb();\n        };\n        window.addEventListener('popstate', onPopState);\n        window.history.go(n);\n      });\n    },\n    listen(listener) {\n      const onPopState = () => {\n        index = this.index;\n        if (pending.length) {\n          return;\n        }\n        listener();\n      };\n      window.addEventListener('popstate', onPopState);\n      return () => window.removeEventListener('popstate', onPopState);\n    }\n  };\n  return history;\n}","map":{"version":3,"names":["nanoid","createMemoryHistory","index","items","pending","interrupt","forEach","it","cb","history","id","window","state","findIndex","item","get","backIndex","path","i","push","slice","length","pushState","replace","pathWithHash","hash","includes","location","replaceState","go","n","nextIndex","lastItemIndex","Promise","resolve","reject","done","interrupted","clearTimeout","timer","Error","title","document","ref","setTimeout","foundIndex","splice","onPopState","last","pop","removeEventListener","addEventListener","listen","listener"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/@react-navigation/native/src/createMemoryHistory.tsx"],"sourcesContent":["import type { NavigationState } from '@react-navigation/core';\nimport { nanoid } from 'nanoid/non-secure';\n\ntype HistoryRecord = {\n  // Unique identifier for this record to match it with window.history.state\n  id: string;\n  // Navigation state object for the history entry\n  state: NavigationState;\n  // Path of the history entry\n  path: string;\n};\n\nexport function createMemoryHistory() {\n  let index = 0;\n  let items: HistoryRecord[] = [];\n\n  // Pending callbacks for `history.go(n)`\n  // We might modify the callback stored if it was interrupted, so we have a ref to identify it\n  const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = [];\n\n  const interrupt = () => {\n    // If another history operation was performed we need to interrupt existing ones\n    // This makes sure that calls such as `history.replace` after `history.go` don't happen\n    // Since otherwise it won't be correct if something else has changed\n    pending.forEach((it) => {\n      const cb = it.cb;\n      it.cb = () => cb(true);\n    });\n  };\n\n  const history = {\n    get index(): number {\n      // We store an id in the state instead of an index\n      // Index could get out of sync with in-memory values if page reloads\n      const id = window.history.state?.id;\n\n      if (id) {\n        const index = items.findIndex((item) => item.id === id);\n\n        return index > -1 ? index : 0;\n      }\n\n      return 0;\n    },\n\n    get(index: number) {\n      return items[index];\n    },\n\n    backIndex({ path }: { path: string }) {\n      // We need to find the index from the element before current to get closest path to go back to\n      for (let i = index - 1; i >= 0; i--) {\n        const item = items[i];\n\n        if (item.path === path) {\n          return i;\n        }\n      }\n\n      return -1;\n    },\n\n    push({ path, state }: { path: string; state: NavigationState }) {\n      interrupt();\n\n      const id = nanoid();\n\n      // When a new entry is pushed, all the existing entries after index will be inaccessible\n      // So we remove any existing entries after the current index to clean them up\n      items = items.slice(0, index + 1);\n\n      items.push({ path, state, id });\n      index = items.length - 1;\n\n      // We pass empty string for title because it's ignored in all browsers except safari\n      // We don't store state object in history.state because:\n      // - browsers have limits on how big it can be, and we don't control the size\n      // - while not recommended, there could be non-serializable data in state\n      window.history.pushState({ id }, '', path);\n    },\n\n    replace({ path, state }: { path: string; state: NavigationState }) {\n      interrupt();\n\n      const id = window.history.state?.id ?? nanoid();\n\n      // Need to keep the hash part of the path if there was no previous history entry\n      // or the previous history entry had the same path\n      let pathWithHash = path;\n      const hash = pathWithHash.includes('#') ? '' : location.hash;\n\n      if (!items.length || items.findIndex((item) => item.id === id) < 0) {\n        // There are two scenarios for creating an array with only one history record:\n        // - When loaded id not found in the items array, this function by default will replace\n        //   the first item. We need to keep only the new updated object, otherwise it will break\n        //   the page when navigating forward in history.\n        // - This is the first time any state modifications are done\n        //   So we need to push the entry as there's nothing to replace\n\n        pathWithHash = pathWithHash + hash;\n        items = [{ path: pathWithHash, state, id }];\n        index = 0;\n      } else {\n        if (items[index].path === path) {\n          pathWithHash = pathWithHash + hash;\n        }\n        items[index] = { path, state, id };\n      }\n\n      window.history.replaceState({ id }, '', pathWithHash);\n    },\n\n    // `history.go(n)` is asynchronous, there are couple of things to keep in mind:\n    // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.\n    // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.\n    // - the `popstate` event fires before the next frame after calling `history.go(n)`.\n    // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.\n    go(n: number) {\n      interrupt();\n\n      // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory\n      // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app.\n      const nextIndex = index + n;\n      const lastItemIndex = items.length - 1;\n      if (n < 0 && !items[nextIndex]) {\n        // Attempted to navigate beyond the first index. Negating the current index will align the browser history with the first item.\n        n = -index;\n        index = 0;\n      } else if (n > 0 && nextIndex > lastItemIndex) {\n        // Attempted to navigate past the last index. Calculate how many indices away from the last index and go there.\n        n = lastItemIndex - index;\n        index = lastItemIndex;\n      } else {\n        index = nextIndex;\n      }\n\n      if (n === 0) {\n        return;\n      }\n\n      // When we call `history.go`, `popstate` will fire when there's history to go back to\n      // So we need to somehow handle following cases:\n      // - There's history to go back, `history.go` is called, and `popstate` fires\n      // - `history.go` is called multiple times, we need to resolve on respective `popstate`\n      // - No history to go back, but `history.go` was called, browser has no API to detect it\n      return new Promise<void>((resolve, reject) => {\n        const done = (interrupted?: boolean) => {\n          clearTimeout(timer);\n\n          if (interrupted) {\n            reject(new Error('History was changed during navigation.'));\n            return;\n          }\n\n          // There seems to be a bug in Chrome regarding updating the title\n          // If we set a title just before calling `history.go`, the title gets lost\n          // However the value of `document.title` is still what we set it to\n          // It's just not displayed in the tab bar\n          // To update the tab bar, we need to reset the title to something else first (e.g. '')\n          // And set the title to what it was before so it gets applied\n          // It won't work without setting it to empty string coz otherwise title isn't changing\n          // Which means that the browser won't do anything after setting the title\n          const { title } = window.document;\n\n          window.document.title = '';\n          window.document.title = title;\n\n          resolve();\n        };\n\n        pending.push({ ref: done, cb: done });\n\n        // If navigation didn't happen within 100ms, assume that it won't happen\n        // This may not be accurate, but hopefully it won't take so much time\n        // In Chrome, navigation seems to happen instantly in next microtask\n        // But on Firefox, it seems to take much longer, around 50ms from our testing\n        // We're using a hacky timeout since there doesn't seem to be way to know for sure\n        const timer = setTimeout(() => {\n          const foundIndex = pending.findIndex((it) => it.ref === done);\n\n          if (foundIndex > -1) {\n            pending[foundIndex].cb();\n            pending.splice(foundIndex, 1);\n          }\n\n          index = this.index;\n        }, 100);\n\n        const onPopState = () => {\n          // Fix createMemoryHistory.index variable's value\n          // as it may go out of sync when navigating in the browser.\n          index = this.index;\n\n          const last = pending.pop();\n\n          window.removeEventListener('popstate', onPopState);\n          last?.cb();\n        };\n\n        window.addEventListener('popstate', onPopState);\n        window.history.go(n);\n      });\n    },\n\n    // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`\n    // If we call `history.go(n)` ourselves, we don't want it to trigger the listener\n    // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener\n    listen(listener: () => void) {\n      const onPopState = () => {\n        // Fix createMemoryHistory.index variable's value\n        // as it may go out of sync when navigating in the browser.\n        index = this.index;\n\n        if (pending.length) {\n          // This was triggered by `history.go(n)`, we shouldn't call the listener\n          return;\n        }\n\n        listener();\n      };\n\n      window.addEventListener('popstate', onPopState);\n\n      return () => window.removeEventListener('popstate', onPopState);\n    },\n  };\n\n  return history;\n}\n"],"mappings":";;AACA,SAASA,MAAM,QAAQ,mBAAmB;AAW1C,OAAO,SAASC,mBAAmBA,CAAA,EAAG;EACpC,IAAIC,KAAK,GAAG,CAAC;EACb,IAAIC,KAAsB,GAAG,EAAE;EAI/B,MAAMC,OAAgE,GAAG,EAAE;EAE3E,MAAMC,SAAS,GAAGA,CAAA,KAAM;IAItBD,OAAO,CAACE,OAAO,CAAEC,EAAE,IAAK;MACtB,MAAMC,EAAE,GAAGD,EAAE,CAACC,EAAE;MAChBD,EAAE,CAACC,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