{"version":3,"file":"createUiShellFullscreenState.cjs","names":["_index","require","_createMessageBus","_createStore","createUiShellFullscreenState","createFullscreenModeMessageBus","defaultCreateFullscreenModeMessageBus","appFullscreenId","createFullscreenId","store","createStore","connection","fullscreenStateBus","createMessageBus","getFullscreenModeMessageBus","getState","fullscreenModeMessageBus","getFullscreenState","emptyFullscreenState","exitAppFullscreen","exitFullscreen","fullscreenId","connect","unsubscribeFromFullscreenState","subscribeToFullscreenState","publish","setState","requestFullscreenState","hasUnreportedFullscreen","getHasActiveFullscreen","destroy","enterAppFullscreen","enterFullscreen","subscribe","exports"],"sources":["../../../src/ui-shell/createUiShellFullscreenState.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 {\n  createFullscreenId,\n  createFullscreenModeMessageBus as defaultCreateFullscreenModeMessageBus,\n  emptyFullscreenState,\n  type FullscreenModeMessageBus,\n  type FullscreenState,\n  getHasActiveFullscreen,\n} from \"../message-bus/index.js\";\nimport { createMessageBus } from \"../tools/createMessageBus.js\";\nimport { createStore } from \"../tools/createStore.js\";\n\nexport type DisconnectUiShellFullscreenState = () => void;\n\nexport type UiShellFullscreenState = {\n  /**\n   * Start listening for the page's fullscreen stack. UI Shell calls this when it mounts, and the function it returns when it unmounts, so the shell never leaves a listener on the page after it's gone.\n   *\n   * Disconnecting takes the app area out of fullscreen and reports an empty stack, since nothing is listening anymore.\n   */\n  connect: () => DisconnectUiShellFullscreenState;\n  /**\n   * Put the whole app area in fullscreen. UI Shell hides its top nav, side nav, and banners so the app fills the page. Does nothing while disconnected.\n   */\n  enterAppFullscreen: () => void;\n  /**\n   * Take the app area out of fullscreen. A `FullscreenRegion` that entered on top of it stays in fullscreen.\n   */\n  exitAppFullscreen: () => void;\n  getFullscreenState: FullscreenModeMessageBus[\"getFullscreenState\"];\n  /**\n   * Listen for fullscreen changes. Listeners stay subscribed while UI Shell is removed and added back.\n   */\n  subscribeToFullscreenState: FullscreenModeMessageBus[\"subscribeToFullscreenState\"];\n};\n\nexport type CreateUiShellFullscreenStateArgs = {\n  /**\n   * Creates the message bus that reads and changes the page's fullscreen stack.\n   * @default createFullscreenModeMessageBus\n   */\n  createFullscreenModeMessageBus?: () => FullscreenModeMessageBus;\n};\n\n/**\n * Create the fullscreen mode instance `renderUiShell` hands to apps not built with Odyssey's React components, so a non-React app can put its whole app area in fullscreen.\n *\n * The app area is one more id in the page's fullscreen stack, so a `FullscreenRegion` can still enter on top of it and Escape goes back one step at a time.\n *\n * It only listens to the page while connected. `renderUiShell` has no dispose call, so the shell's own mount and unmount are the only reliable signal that it's gone.\n */\nexport const createUiShellFullscreenState = ({\n  createFullscreenModeMessageBus = defaultCreateFullscreenModeMessageBus,\n}: CreateUiShellFullscreenStateArgs = {}): UiShellFullscreenState => {\n  const appFullscreenId = createFullscreenId();\n\n  const store = createStore<{\n    connection: { fullscreenModeMessageBus?: FullscreenModeMessageBus };\n  }>({ connection: {} });\n\n  // Listeners subscribe here rather than on the connection, so they outlive a shell removed and added back.\n  const fullscreenStateBus = createMessageBus<FullscreenState>();\n\n  const getFullscreenModeMessageBus = () =>\n    store.getState(\"connection\")?.fullscreenModeMessageBus;\n\n  const getFullscreenState = (): FullscreenState =>\n    getFullscreenModeMessageBus()?.getFullscreenState() ?? emptyFullscreenState;\n\n  const exitAppFullscreen = () => {\n    getFullscreenModeMessageBus()?.exitFullscreen({\n      fullscreenId: appFullscreenId,\n    });\n  };\n\n  const connect = () => {\n    const fullscreenModeMessageBus = createFullscreenModeMessageBus();\n\n    const unsubscribeFromFullscreenState =\n      fullscreenModeMessageBus.subscribeToFullscreenState(\n        fullscreenStateBus.publish,\n      );\n\n    store.setState(\"connection\", { fullscreenModeMessageBus });\n    fullscreenModeMessageBus.requestFullscreenState();\n\n    return () => {\n      exitAppFullscreen();\n      unsubscribeFromFullscreenState();\n\n      const hasUnreportedFullscreen = getHasActiveFullscreen(\n        fullscreenModeMessageBus.getFullscreenState(),\n      );\n\n      fullscreenModeMessageBus.destroy();\n      store.setState(\"connection\", {});\n\n      // The host's next snapshot can't reach a bus that's already closed, so listeners hear the empty stack from here.\n      if (hasUnreportedFullscreen) {\n        fullscreenStateBus.publish(emptyFullscreenState);\n      }\n    };\n  };\n\n  return {\n    connect,\n    enterAppFullscreen: () => {\n      getFullscreenModeMessageBus()?.enterFullscreen({\n        fullscreenId: appFullscreenId,\n      });\n    },\n    exitAppFullscreen,\n    getFullscreenState,\n    subscribeToFullscreenState: fullscreenStateBus.subscribe,\n  };\n};\n"],"mappings":";;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AAQA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AArBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAoDO,MAAMG,4BAA4B,GAAGA,CAAC;EAC3CC,8BAA8B,GAAGC;AACD,CAAC,GAAG,CAAC,CAAC,KAA6B;EACnE,MAAMC,eAAe,GAAG,IAAAC,yBAAkB,EAAC,CAAC;EAE5C,MAAMC,KAAK,GAAG,IAAAC,wBAAW,EAEtB;IAAEC,UAAU,EAAE,CAAC;EAAE,CAAC,CAAC;EAGtB,MAAMC,kBAAkB,GAAG,IAAAC,kCAAgB,EAAkB,CAAC;EAE9D,MAAMC,2BAA2B,GAAGA,CAAA,KAClCL,KAAK,CAACM,QAAQ,CAAC,YAAY,CAAC,EAAEC,wBAAwB;EAExD,MAAMC,kBAAkB,GAAGA,CAAA,KACzBH,2BAA2B,CAAC,CAAC,EAAEG,kBAAkB,CAAC,CAAC,I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