{"version":3,"file":"Root.js","names":["UpstreamNavigationContainer"],"sources":["esm/Root.js"],"sourcesContent":["import { DarkTheme, DefaultTheme } from \"./fork/theme\";\nimport { useUserScheme } from \"@vxrn/color-scheme\";\nimport {\n  createContext,\n  StrictMode,\n  useContext,\n  useId,\n  useLayoutEffect,\n  useState\n} from \"react\";\nimport { SERVER_CONTEXT_KEY, isNative } from \"./constants\";\nimport { initScreensFeatureFlags } from \"./screensFeatureFlags\";\nimport { SpaShellContext } from \"./router/SpaShellContext\";\nimport { NavigationContainer as UpstreamNavigationContainer } from \"./fork/NavigationContainer\";\nimport { getURL } from \"./getURL\";\nimport { FlagsContext } from \"./router/FlagsContext\";\nimport { getResolvedLinking } from \"./router/linkingConfig\";\nimport { handleNavigationContainerStateChange } from \"./router/router\";\nimport { ServerLocationContext } from \"./router/serverLocationContext\";\nimport { useInitializeOneRouter } from \"./router/useInitializeOneRouter\";\nimport { useViteRoutes } from \"./router/useViteRoutes\";\nimport { evictOldest } from \"./utils/evictOldest\";\nimport { ServerRenderID } from \"./useServerHeadInsertion\";\nimport { PreloadLinks } from \"./views/PreloadLinks\";\nimport { SafeAreaProvider, initialWindowMetrics } from \"./safe-area-context\";\nimport { RootErrorBoundary } from \"./views/RootErrorBoundary\";\nimport { ScrollBehavior } from \"./views/ScrollBehavior\";\nimport { Fragment, jsx, jsxs } from \"react/jsx-runtime\";\nconst ssrLocationCache = /* @__PURE__ */ new Map();\nfunction getCachedSSRLocation(path) {\n  let url = ssrLocationCache.get(path);\n  if (url) return url;\n  url = new URL(path, getURL());\n  evictOldest(ssrLocationCache, 5e3, 1e3);\n  ssrLocationCache.set(path, url);\n  return url;\n}\nconst ServerAsyncLocalIDContext = createContext(null);\nglobalThis[\"__vxrnGetContextFromReactContext\"] = () => useContext(ServerAsyncLocalIDContext);\nfunction Root(props) {\n  if (isNative) {\n    initScreensFeatureFlags();\n  }\n  const {\n    path,\n    routes,\n    routeOptions,\n    isClient,\n    navigationContainerProps,\n    onRenderId,\n    linking\n  } = props;\n  const context = useViteRoutes(\n    routes,\n    props.routerRoot,\n    routeOptions,\n    globalThis[\"__vxrnVersion\"]\n  );\n  const location = isNative ? void 0 : typeof window !== \"undefined\" && window.location ? new URL(path || window.location.href || \"/\", window.location.href) : getCachedSSRLocation(path || \"/\");\n  const store = useInitializeOneRouter(context, location, linking);\n  const userScheme = useUserScheme();\n  const Component = store.rootComponent;\n  if (!Component) {\n    throw new Error(`No root component found`);\n  }\n  const id = useId();\n  onRenderId?.(id);\n  const value = process.env.VERCEL ? globalThis[\"__oneGlobalContextId\"] : globalThis[\"__vxrnrequestAsyncLocalStore\"]?.getStore() || null;\n  const deferredPreloads = props.deferredPreloads;\n  let contents = /* @__PURE__ */ jsx(ServerAsyncLocalIDContext.Provider, { value, children: /* @__PURE__ */ jsxs(ServerRenderID.Provider, { value: id, children: [\n    typeof window === \"undefined\" && deferredPreloads?.map((src) => /* @__PURE__ */ jsx(\"link\", { rel: \"modulepreload\", fetchPriority: \"low\", href: src }, src)),\n    /* @__PURE__ */ jsx(SafeAreaProvider, { initialMetrics: initialWindowMetrics, children: /* @__PURE__ */ jsx(\n      UpstreamNavigationContainer,\n      {\n        ref: store.navigationRef,\n        initialState: store.initialState,\n        linking: getResolvedLinking(),\n        onUnhandledAction,\n        onStateChange: handleNavigationContainerStateChange,\n        theme: userScheme.value === \"dark\" ? DarkTheme : DefaultTheme,\n        documentTitle: {\n          enabled: false\n        },\n        ...navigationContainerProps,\n        children: /* @__PURE__ */ jsx(ServerLocationContext.Provider, { value: location, children: /* @__PURE__ */ jsxs(Fragment, { children: [\n          /* @__PURE__ */ jsx(ScrollBehavior, {}),\n          /* @__PURE__ */ jsx(RootErrorBoundary, { children: /* @__PURE__ */ jsx(Component, {}) })\n        ] }) })\n      }\n    ) }),\n    typeof window !== \"undefined\" && /* @__PURE__ */ jsx(PreloadLinks, {}, \"preload-links\")\n  ] }) });\n  if (props.flags) {\n    contents = /* @__PURE__ */ jsx(FlagsContext.Provider, { value: props.flags, children: contents });\n  }\n  if (!process.env.ONE_DISABLE_STRICT_MODE) {\n    contents = /* @__PURE__ */ jsx(StrictMode, { children: contents });\n  }\n  if (isClient) {\n    const serverMode = globalThis[SERVER_CONTEXT_KEY]?.mode;\n    if (serverMode === \"spa\") {\n      const [show, setShow] = useState(false);\n      useLayoutEffect(() => {\n        setShow(true);\n      }, []);\n      return show ? contents : null;\n    }\n    if (serverMode === \"spa-shell\") {\n      const [isSpaShell, setIsSpaShell] = useState(true);\n      useLayoutEffect(() => {\n        setIsSpaShell(false);\n      }, []);\n      useLayoutEffect(() => {\n        if (!isSpaShell) {\n          const initialPath = window.location.pathname + window.location.search;\n          requestAnimationFrame(() => {\n            if (window.location.pathname + window.location.search !== initialPath) return;\n            const nav = store.navigationRef?.current;\n            if (!nav) return;\n            const linking2 = getResolvedLinking();\n            if (linking2?.getStateFromPath) {\n              const freshState = linking2.getStateFromPath(initialPath, linking2.config);\n              if (freshState) {\n                nav.resetRoot(freshState);\n              }\n            }\n          });\n        }\n      }, [isSpaShell]);\n      return /* @__PURE__ */ jsx(SpaShellContext.Provider, { value: isSpaShell, children: contents });\n    }\n    return contents;\n  }\n  if (props.mode === \"spa-shell\") {\n    return /* @__PURE__ */ jsx(SpaShellContext.Provider, { value: true, children: contents });\n  }\n  return contents;\n}\nlet onUnhandledAction;\nif (process.env.NODE_ENV !== \"production\") {\n  onUnhandledAction = (action) => {\n    const payload = action.payload;\n    let message = `The action '${action.type}'${payload ? ` with payload ${JSON.stringify(action.payload)}` : \"\"} was not handled by any navigator.`;\n    switch (action.type) {\n      case \"NAVIGATE\":\n      case \"PUSH\":\n      case \"REPLACE\":\n      case \"JUMP_TO\":\n        if (payload?.name) {\n          message += `\n\nDo you have a route named '${payload.name}'?`;\n        } else {\n          message += `\n\nYou need to pass the name of the screen to navigate to. This may be a bug.`;\n        }\n        break;\n      case \"GO_BACK\":\n      case \"POP\":\n      case \"POP_TO_TOP\":\n        message += `\n\nIs there any screen to go back to?`;\n        break;\n      case \"OPEN_DRAWER\":\n      case \"CLOSE_DRAWER\":\n      case \"TOGGLE_DRAWER\":\n        message += `\n\nIs your screen inside a Drawer navigator?`;\n        break;\n    }\n    message += `\n\nThis is a development-only warning and won't be shown in production.`;\n    if (process.env.NODE_ENV === \"test\") {\n      throw new Error(message);\n    }\n    console.error(message);\n  };\n} else {\n  onUnhandledAction = () => {\n  };\n}\nexport {\n  Root\n};\n//# sourceMappingURL=Root.js.map\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,mCAAmC,IAAI,IAAI;AACjD,SAAS,qBAAqB,MAAM;CAClC,IAAI,MAAM,iBAAiB,IAAI,IAAI;CACnC,IAAI,KAAK,OAAO;CAChB,MAAM,IAAI,IAAI,MAAM,OAAO,CAAC;CAC5B,YAAY,kBAAkB,KAAK,GAAG;CACtC,iBAAiB,IAAI,MAAM,GAAG;CAC9B,OAAO;AACT;AACA,MAAM,4BAA4B,cAAc,IAAI;AACpD,WAAW,4CAA4C,WAAW,yBAAyB;AAC3F,SAAS,KAAK,OAAO;CACnB,IAAI,UAAU;EACZ,wBAAwB;CAC1B;CACA,MAAM,EACJ,MACA,QACA,cACA,UACA,0BACA,YACA,YACE;CACJ,MAAM,UAAU,cACd,QACA,MAAM,YACN,cACA,WAAW,gBACb;CACA,MAAM,WAAW,WAAW,KAAK,IAAI,OAAO,WAAW,eAAe,OAAO,WAAW,IAAI,IAAI,QAAQ,OAAO,SAAS,QAAQ,KAAK,OAAO,SAAS,IAAI,IAAI,qBAAqB,QAAQ,GAAG;CAC7L,MAAM,QAAQ,uBAAuB,SAAS,UAAU,OAAO;CAC/D,MAAM,aAAa,cAAc;CACjC,MAAM,YAAY,MAAM;CACxB,IAAI,CAAC,WAAW;EACd,MAAM,IAAI,MAAM,yBAAyB;CAC3C;CACA,MAAM,KAAK,MAAM;CACjB,aAAa,EAAE;CACf,MAAM,QAAQ,QAAQ,IAAI,SAAS,WAAW,0BAA0B,WAAW,+BA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