{"version":3,"file":"useFullscreenChromeCollapse.cjs","names":["_react","require","_AnimationContext","_fullscreenTransitionTokens","useFullscreenChromeCollapse","chromeElementRef","collapsedDimension","isCollapsed","hasAnimations","useAnimation","hasFinishedCollapsing","setHasFinishedCollapsing","useState","previousIsCollapsedRef","useRef","interruptedSizeRef","undefined","useLayoutEffect","hasCollapseChanged","current","chromeElement","expandedKeyframe","getBoundingClientRect","overflow","collapsedKeyframe","interruptedSize","restingStartKeyframe","startKeyframe","chromeAnimation","animate","duration","fullscreenTransitionTokens","durationMilliseconds","easing","fill","addEventListener","playState","cancel","isChromeHidden","exports"],"sources":["../../../src/ui-shell/useFullscreenChromeCollapse.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 { type RefObject, useLayoutEffect, useRef, useState } from \"react\";\n\nimport { useAnimation } from \"../AnimationContext.js\";\nimport { fullscreenTransitionTokens } from \"../pendingDesignTokens/fullscreenTransitionTokens.js\";\n\nexport type UseFullscreenChromeCollapseArgs = {\n  /** The part of the shell that shrinks away while fullscreen is active. */\n  chromeElementRef: RefObject<HTMLElement | null>;\n  /** The side that shrinks: `height` for a bar across the shell, `width` for a column beside the app. */\n  collapsedDimension: \"height\" | \"width\";\n  /** If `true`, fullscreen is active and the chrome collapses. */\n  isCollapsed: boolean;\n};\n\n/**\n * Shrinks a part of the shell to nothing when fullscreen starts, and grows it back when fullscreen ends, so the user can see where the navigation went.\n *\n * Returns `isChromeHidden`, which turns `true` only once the collapse has finished.\n */\nexport const useFullscreenChromeCollapse = ({\n  chromeElementRef,\n  collapsedDimension,\n  isCollapsed,\n}: UseFullscreenChromeCollapseArgs) => {\n  const hasAnimations = useAnimation();\n  const [hasFinishedCollapsing, setHasFinishedCollapsing] =\n    useState(isCollapsed);\n  const previousIsCollapsedRef = useRef(isCollapsed);\n  const interruptedSizeRef = useRef<number>(undefined);\n\n  // A layout effect, so the first keyframe applies before the browser paints the new state.\n  useLayoutEffect(() => {\n    const hasCollapseChanged = previousIsCollapsedRef.current !== isCollapsed;\n    previousIsCollapsedRef.current = isCollapsed;\n\n    if (!isCollapsed) {\n      setHasFinishedCollapsing(false);\n    }\n\n    const chromeElement = chromeElementRef.current;\n\n    if (!hasCollapseChanged || !hasAnimations || !chromeElement) {\n      return;\n    }\n\n    const expandedKeyframe = {\n      [collapsedDimension]: `${chromeElement.getBoundingClientRect()[collapsedDimension]}px`,\n      overflow: \"hidden\",\n    };\n    const collapsedKeyframe = {\n      [collapsedDimension]: \"0px\",\n      overflow: \"hidden\",\n    };\n    // Fullscreen can end before the collapse finishes. Starting from the size the chrome had reached keeps it from snapping shut before it grows back.\n    const interruptedSize = interruptedSizeRef.current;\n    interruptedSizeRef.current = undefined;\n    const restingStartKeyframe = isCollapsed\n      ? expandedKeyframe\n      : collapsedKeyframe;\n    const startKeyframe =\n      interruptedSize === undefined\n        ? restingStartKeyframe\n        : { [collapsedDimension]: `${interruptedSize}px`, overflow: \"hidden\" };\n\n    const chromeAnimation = chromeElement.animate(\n      isCollapsed\n        ? [startKeyframe, collapsedKeyframe]\n        : [startKeyframe, expandedKeyframe],\n      {\n        duration: fullscreenTransitionTokens.durationMilliseconds,\n        easing: fullscreenTransitionTokens.easing,\n        // Holds the collapsed size until React hides the element. Without it, the chrome springs back to full size for a frame after the animation ends.\n        fill: isCollapsed ? \"forwards\" : \"none\",\n      },\n    );\n\n    if (isCollapsed) {\n      chromeAnimation.addEventListener(\"finish\", () => {\n        setHasFinishedCollapsing(true);\n      });\n    }\n\n    return () => {\n      // Read before cancelling, while the animation still holds the in-between size.\n      interruptedSizeRef.current =\n        chromeAnimation.playState === \"running\"\n          ? chromeElement.getBoundingClientRect()[collapsedDimension]\n          : undefined;\n      chromeAnimation.cancel();\n    };\n  }, [chromeElementRef, collapsedDimension, hasAnimations, isCollapsed]);\n\n  return {\n    isChromeHidden: isCollapsed && (hasFinishedCollapsing || !hasAnimations),\n  };\n};\n"],"mappings":";;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,2BAAA,GAAAF,OAAA;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAqBO,MAAMG,2BAA2B,GAAGA,CAAC;EAC1CC,gBAAgB;EAChBC,kBAAkB;EAClBC;AAC+B,CAAC,KAAK;EACrC,MAAMC,aAAa,GAAG,IAAAC,8BAAY,EAAC,CAAC;EACpC,MAAM,CAACC,qBAAqB,EAAEC,wBAAwB,CAAC,GACrD,IAAAC,eAAQ,EAACL,WAAW,CAAC;EACvB,MAAMM,sBAAsB,GAAG,IAAAC,aAAM,EAACP,WAAW,CAAC;EAClD,MAAMQ,kBAAkB,GAAG,IAAAD,aAAM,EAASE,SAAS,CAAC;EAGpD,IAAAC,sBAAe,EAAC,MAAM;IACpB,MAAMC,kBAAkB,GAAGL,sBAAsB,CAACM,OAAO,KAAKZ,WAAW;IACzEM,sBAAsB,CAACM,OAAO,GAAGZ,WAAW;IAE5C,IAAI,CAACA,WAAW,EAAE;MAChBI,wBAAwB,CAAC,KAAK,CAAC;IACjC;IAEA,MAAMS,aAAa,GAAGf,gBAAgB,CAACc,OAAO;IAE9C,IAAI,CAACD,kBAAkB,IAAI,CAACV,aAAa,IAAI,CAACY,aAAa,EAAE;MAC3D;IACF;IAEA,MAAMC,gBAAgB,GAAG;MACvB,CAACf,kBAAkB,GAAG,GAAGc,aAAa,CAACE,qBAAqB,CAAC,CAAC,CAAChB,kBAAkB,CAAC,IAAI;MACtFiB,QAAQ,EAAE;I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