{"version":3,"file":"FullScreenOverlayContext.cjs","names":["_react","require","_useFullscreen","_createShadowDomElements","_jsxRuntime","FullScreenOverlayContext","exports","createContext","useFullScreenOverlayContext","useContext","OVERLAY_DATA_ATTRIBUTES","dialog","drawer","toastStack","default","FullScreenOverlayProvider","children","hasShadowDom","overlayParentElement","overlayParentElementProp","overlayType","fullScreenOverlayId","overlayEmotionRootElement","overlayShadowRootElement","useMemo","document","createElement","emotionRootElement","shadowRootElement","createShadowDomElements","undefined","useEffect","id","removeAttribute","setAttribute","body","append","remove","hasActiveFullscreen","useHasActiveFullscreen","removeInert","hasAttribute","mutationObserver","MutationObserver","observe","attributeFilter","disconnect","providerValue","jsx","Provider","value","MemoizedFullScreenOverlayProvider","memo","displayName"],"sources":["../../src/FullScreenOverlayContext.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2025-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport {\n  createContext,\n  memo,\n  type ReactNode,\n  useContext,\n  useEffect,\n  useMemo,\n} from \"react\";\n\nimport { useHasActiveFullscreen } from \"./fullscreen/useFullscreen.js\";\nimport { createShadowDomElements } from \"./web-component/createShadowDomElements.js\";\n\nexport type FullScreenOverlayContextType = {\n  /**\n   * If `true`, the component is already rendering inside an overlay's container, so an overlay opened from it renders into that same container.\n   */\n  isWithinOverlay?: boolean;\n  overlayEmotionRootElement?: HTMLDivElement | HTMLElement;\n  overlayShadowRootElement?: HTMLDivElement | HTMLElement;\n};\n\nexport const FullScreenOverlayContext =\n  createContext<FullScreenOverlayContextType>({});\n\nexport const useFullScreenOverlayContext = () =>\n  useContext(FullScreenOverlayContext);\n\nexport const OVERLAY_DATA_ATTRIBUTES = {\n  dialog: \"data-odyssey-react-dialog-overlay-component\",\n  drawer: \"data-odyssey-react-drawer-overlay-component\",\n  toastStack: \"data-odyssey-react-toast-stack-overlay-component\",\n  default: \"data-odyssey-react-overlay-component\",\n} as const;\n\nexport type OverlayType = keyof typeof OVERLAY_DATA_ATTRIBUTES;\n\nexport type FullScreenOverlayProviderProps = {\n  children: ReactNode;\n  /**\n   * An optional HTML `id` attribute to be applied to the overlay's container element.\n   */\n  fullScreenOverlayId?: string;\n  hasShadowDom?: boolean;\n  /**\n   * @experimental This is the element overlays will render into. By default, it's set to `document.body`.\n   *\n   * If you specify this value , it will render overlays into this container, such as the `shadowRootElement` over the document body. Most likely, you don't need to change this value, but you might run into strange issues related iframes and other shadow roots. This is here as a safeguard; not meant to be used.\n   */\n  overlayParentElement?: HTMLDivElement | HTMLElement;\n  /**\n   * Type of overlay being rendered. This controls the data attribute set on the overlay parent element.\n   * @default \"default\"\n   * @deprecated Overlays no longer create containers of their own, so the app's one container only needs `data-odyssey-react-overlay-component`. Select overlays by that attribute and the app's `fullScreenOverlayId`.\n   */\n  overlayType?: OverlayType;\n};\n\nconst FullScreenOverlayProvider = ({\n  children,\n  hasShadowDom,\n  overlayParentElement: overlayParentElementProp,\n  overlayType = \"default\",\n  fullScreenOverlayId,\n}: FullScreenOverlayProviderProps) => {\n  const {\n    overlayEmotionRootElement,\n    overlayParentElement,\n    overlayShadowRootElement,\n  } = useMemo(() => {\n    const overlayParentElement =\n      overlayParentElementProp || document.createElement(\"div\");\n\n    if (hasShadowDom) {\n      const { emotionRootElement, shadowRootElement } =\n        createShadowDomElements(overlayParentElement);\n\n      return {\n        overlayEmotionRootElement: emotionRootElement,\n        overlayParentElement,\n        overlayShadowRootElement: shadowRootElement,\n      };\n    }\n\n    return {\n      overlayEmotionRootElement: undefined,\n      overlayParentElement,\n      overlayShadowRootElement: undefined,\n    };\n  }, [hasShadowDom, overlayParentElementProp]);\n\n  useEffect(() => {\n    if (overlayParentElement) {\n      if (fullScreenOverlayId) {\n        overlayParentElement.id = fullScreenOverlayId;\n      } else {\n        overlayParentElement.removeAttribute(\"id\");\n      }\n      overlayParentElement.setAttribute(\n        OVERLAY_DATA_ATTRIBUTES[overlayType],\n        \"\",\n      );\n      document.body.append(overlayParentElement);\n    }\n\n    return () => {\n      overlayParentElement.remove();\n    };\n  }, [fullScreenOverlayId, overlayParentElement, overlayType]);\n\n  const hasActiveFullscreen = useHasActiveFullscreen();\n\n  // The container sits on `<body>` from the moment the app mounts, so a fullscreen region, possibly from another bundle or an older Odyssey, makes it inert along with the rest of the page. An overlay in an inert container is visible but ignores every click and keypress, so the container refuses `inert` while anything is in fullscreen. Outside fullscreen it leaves `inert` alone, because then a host page's own modal may be isolating it on purpose.\n  useEffect(() => {\n    if (!hasActiveFullscreen) {\n      return;\n    }\n\n    const removeInert = () => {\n      if (overlayParentElement.hasAttribute(\"inert\")) {\n        overlayParentElement.removeAttribute(\"inert\");\n      }\n    };\n\n    removeInert();\n\n    const mutationObserver = new MutationObserver(removeInert);\n    mutationObserver.observe(overlayParentElement, {\n      attributeFilter: [\"inert\"],\n    });\n\n    return () => mutationObserver.disconnect();\n  }, [hasActiveFullscreen, overlayParentElement]);\n\n  const providerValue = useMemo(\n    () => ({\n      overlayEmotionRootElement,\n      overlayShadowRootElement,\n    }),\n    [overlayEmotionRootElement, overlayShadowRootElement],\n  );\n\n  return (\n    <FullScreenOverlayContext.Provider value={providerValue}>\n      {children}\n    </FullScreenOverlayContext.Provider>\n  );\n};\n\nconst MemoizedFullScreenOverlayProvider = memo(FullScreenOverlayProvider);\nMemoizedFullScreenOverlayProvider.displayName = \"FullScreenOverlayProvider\";\n\nexport { MemoizedFullScreenOverlayProvider as FullScreenOverlayProvider };\n"],"mappings":";;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AASA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,wBAAA,GAAAF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