{"version":3,"file":"useStack.js","names":[],"sources":["esm/headless/useStack.js"],"sourcesContent":["\"use client\";\nimport {\n  createContext,\n  createElement,\n  useContext,\n  useMemo\n} from \"react\";\nimport { getPathFromState } from \"../fork/getPathFromState\";\nimport { getResolvedLinking } from \"../router/linkingConfig\";\nconst StackContext = createContext(null);\nfunction StackStateProvider({\n  state,\n  descriptors,\n  children\n}) {\n  const linking = getResolvedLinking();\n  const value = useMemo(() => {\n    const screens = state.routes.map((route, index) => {\n      const descriptor = descriptors[route.key];\n      const options = descriptor.options;\n      const href = (linking?.getPathFromState ?? getPathFromState)(\n        { ...state, index },\n        linking?.config\n      );\n      return {\n        key: route.key,\n        name: route.name,\n        params: route.params ?? {},\n        href,\n        isFocused: index === state.index,\n        keepMounted: options.keepMounted === true,\n        options,\n        element: descriptor.render()\n      };\n    });\n    return { screens, focused: screens[state.index] };\n  }, [descriptors, linking, state]);\n  return createElement(StackContext.Provider, { value }, children);\n}\nfunction useStack() {\n  const value = useContext(StackContext);\n  if (!value) {\n    throw new Error(\n      \"useStack() must be called inside a <Stack>. it is web-only: on native the stack is rendered by react-navigation.\"\n    );\n  }\n  return value;\n}\nexport {\n  StackStateProvider,\n  useStack\n};\n//# sourceMappingURL=useStack.js.map\n"],"mappings":";;;;;;;AASA,MAAM,eAAe,cAAc,IAAI;AACvC,SAAS,mBAAmB,EAC1B,OACA,aACA,YACC;CACD,MAAM,UAAU,mBAAmB;CACnC,MAAM,QAAQ,cAAc;EAC1B,MAAM,UAAU,MAAM,OAAO,KAAK,OAAO,UAAU;GACjD,MAAM,aAAa,YAAY,MAAM;GACrC,MAAM,UAAU,WAAW;GAC3B,MAAM,QAAQ,SAAS,oBAAoB,iBAAgB,CACzD;IAAE,GAAG;IAAO;GAAM,GAClB,SAAS,MACX;GACA,OAAO;IACL,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,QAAQ,MAAM,UAAU,CAAC;IACzB;IACA,WAAW,UAAU,MAAM;IAC3B,aAAa,QAAQ,gBAAgB;IACrC;IACA,SAAS,WAAW,OAAO;GAC7B;EACF,CAAC;EACD,OAAO;GAAE;GAAS,SAAS,QAAQ,MAAM;EAAO;CAClD,GAAG;EAAC;EAAa;EAAS;CAAK,CAAC;CAChC,OAAO,cAAc,aAAa,UAAU,EAAE,MAAM,GAAG,QAAQ;AACjE;AACA,SAAS,WAAW;CAClB,MAAM,QAAQ,WAAW,YAAY;CACrC,IAAI,CAAC,OAAO;EACV,MAAM,IAAI,MACR,kHACF;CACF;CACA,OAAO;AACT"}