{"version":3,"file":"useStackedBackdropProps.cjs","names":["_react","require","_shim","_backdropStack","_useUniqueId","useStackedBackdropProps","backdropStack","defaultBackdropStack","isOpen","layer","backdropId","useUniqueId","openBackdropIds","useSyncExternalStore","subscribeToOpenBackdropIds","getOpenBackdropIds","useLayoutEffect","openBackdrop","undefined","useMemo","invisible","length","at","some","openBackdropId","transitionDuration","exports"],"sources":["../../src/useStackedBackdropProps.ts"],"sourcesContent":["/*!\n * Copyright (c) 2026-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 { useLayoutEffect, useMemo } from \"react\";\n// React's `useSyncExternalStore` does not exist before React 18. The shim delegates to the native hook on React 18.\nimport { useSyncExternalStore } from \"use-sync-external-store/shim\";\n\nimport { type BackdropStack, defaultBackdropStack } from \"./backdropStack.js\";\nimport { useUniqueId } from \"./useUniqueId.js\";\n\nexport type UseStackedBackdropPropsArgs = {\n  /**\n   * The stack this backdrop joins.\n   * @default defaultBackdropStack\n   */\n  backdropStack?: BackdropStack;\n  /**\n   * If `true`, the overlay is open and its backdrop joins the stack.\n   */\n  isOpen: boolean;\n  /**\n   * The z-index the overlay renders at, such as `theme.zIndex.modal`.\n   */\n  layer: number;\n};\n\nexport type StackedBackdropProps = {\n  invisible: boolean;\n  transitionDuration?: number;\n};\n\n/**\n * Get the backdrop props that keep stacked overlays from darkening the page more than once. Only the top-most open backdrop paints.\n */\nexport const useStackedBackdropProps = ({\n  backdropStack = defaultBackdropStack,\n  isOpen,\n  layer,\n}: UseStackedBackdropPropsArgs): StackedBackdropProps => {\n  const backdropId = useUniqueId();\n\n  const openBackdropIds = useSyncExternalStore(\n    backdropStack.subscribeToOpenBackdropIds,\n    backdropStack.getOpenBackdropIds,\n    backdropStack.getOpenBackdropIds,\n  );\n\n  // A layout effect, so the backdrop underneath hides in the same frame the new one appears, not one paint later.\n  useLayoutEffect(\n    () =>\n      isOpen ? backdropStack.openBackdrop({ backdropId, layer }) : undefined,\n    [backdropId, backdropStack, isOpen, layer],\n  );\n\n  return useMemo(\n    () => ({\n      // A closing backdrop has already left the stack but stays mounted while it fades out, so membership alone would leave it painted under an overlay that opens during that fade.\n      invisible:\n        openBackdropIds.length > 0 && openBackdropIds.at(-1) !== backdropId,\n      // A backdrop fading in or out over another one would briefly show both, so the gray changes in one step. The last backdrop to close still fades out.\n      ...(openBackdropIds.some(\n        (openBackdropId) => openBackdropId !== backdropId,\n      ) && { transitionDuration: 0 }),\n    }),\n    [backdropId, openBackdropIds],\n  );\n};\n"],"mappings":";;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAjBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAiCO,MAAMI,uBAAuB,GAAGA,CAAC;EACtCC,aAAa,GAAGC,mCAAoB;EACpCC,MAAM;EACNC;AAC2B,CAAC,KAA2B;EACvD,MAAMC,UAAU,GAAG,IAAAC,wBAAW,EAAC,CAAC;EAEhC,MAAMC,eAAe,GAAG,IAAAC,0BAAoB,EAC1CP,aAAa,CAACQ,0BAA0B,EACxCR,aAAa,CAACS,kBAAkB,EAChCT,aAAa,CAACS,kBAChB,CAAC;EAGD,IAAAC,sBAAe,EACb,MACER,MAAM,GAAGF,aAAa,CAACW,YAAY,CAAC;IAAEP,UAAU;IAAED;EAAM,CAAC,CAAC,GAAGS,SAAS,EACxE,CAACR,UAAU,EAAEJ,aAAa,EAAEE,MAAM,EAAEC,KAAK,CAC3C,CAAC;EAED,OAAO,IAAAU,cAAO,EACZ,OAAO;IAELC,SAAS,EACPR,eAAe,CAACS,MAAM,GAAG,CAAC,IAAIT,eAAe,CAACU,EAAE,CAAC,CAAC,CAAC,CAAC,KAAKZ,UAAU;IAErE,IAAIE,eAAe,CAACW,IAAI,CACrBC,cAAc,IAAKA,cAAc,KAAKd,UACzC,CAAC,IAAI;MAAEe,kBAAkB,EAAE;IAAE,CAAC;EAChC,CAAC,CAAC,EACF,CAACf,UAAU,EAAEE,eAAe,CAC9B,CAAC;AACH,CAAC;AAACc,OAAA,CAAArB,uBAAA,GAAAA,uBAAA","ignoreList":[]}