{"version":3,"file":"getBackgroundColorBehindElement.cjs","names":["_useContrastMode","require","getVisibleCenter","element","bottom","left","right","top","getBoundingClientRect","visibleBottom","Math","min","document","documentElement","clientHeight","visibleLeft","max","visibleRight","clientWidth","visibleTop","x","y","undefined","getElementsAtPoint","root","viewportPoint","elementsFromPoint","filter","elementAtPoint","Document","getRootNode","flatMap","shadowRoot","concat","getBackgroundColorBehindElement","elementsAtPoint","elementIndex","indexOf","backgroundColorBehind","slice","elementBehind","HTMLElement","map","getElementComputedBackgroundColor","find","backgroundColor","isTransparentColor","normalizeBackgroundColor","getBackgroundColor","exports"],"sources":["../../../src/fullscreen/getBackgroundColorBehindElement.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  getBackgroundColor,\n  getElementComputedBackgroundColor,\n  isTransparentColor,\n  normalizeBackgroundColor,\n} from \"../useContrastMode.js\";\n\ntype ViewportPoint = {\n  x: number;\n  y: number;\n};\n\nconst getVisibleCenter = ({\n  element,\n}: {\n  element: Element;\n}): ViewportPoint | undefined => {\n  const { bottom, left, right, top } = element.getBoundingClientRect();\n\n  const visibleBottom = Math.min(bottom, document.documentElement.clientHeight);\n  const visibleLeft = Math.max(left, 0);\n  const visibleRight = Math.min(right, document.documentElement.clientWidth);\n  const visibleTop = Math.max(top, 0);\n\n  return visibleLeft < visibleRight && visibleTop < visibleBottom\n    ? {\n        x: (visibleLeft + visibleRight) / 2,\n        y: (visibleTop + visibleBottom) / 2,\n      }\n    : undefined;\n};\n\n/**\n * Every element under a point, front to back, including elements inside open shadow roots. `elementsFromPoint` stops at a shadow host, and UI Shell draws its app area inside one.\n */\nconst getElementsAtPoint = ({\n  root,\n  viewportPoint,\n}: {\n  root: Document | ShadowRoot;\n  viewportPoint: ViewportPoint;\n}): Element[] =>\n  root\n    .elementsFromPoint(viewportPoint.x, viewportPoint.y)\n    // A shadow root also returns the elements outside it. Those are already in the outer list.\n    .filter(\n      (elementAtPoint) =>\n        root instanceof Document || elementAtPoint.getRootNode() === root,\n    )\n    .flatMap((elementAtPoint) =>\n      elementAtPoint.shadowRoot\n        ? getElementsAtPoint({\n            root: elementAtPoint.shadowRoot,\n            viewportPoint,\n          }).concat(elementAtPoint)\n        : [elementAtPoint],\n    );\n\n/**\n * The background color seen behind an element: the first opaque background under its center that sits behind it.\n *\n * Reading the element's ancestors isn't enough. UI Shell lays the app over its app area rather than inside it, so the gray behind an app is on none of the app's ancestors.\n *\n * Falls back to the element's ancestors when it isn't on screen.\n */\nexport const getBackgroundColorBehindElement = ({\n  element,\n}: {\n  element: HTMLElement;\n}): string => {\n  const viewportPoint = getVisibleCenter({ element });\n\n  const elementsAtPoint = viewportPoint\n    ? getElementsAtPoint({ root: document, viewportPoint })\n    : [];\n\n  const elementIndex = elementsAtPoint.indexOf(element);\n\n  const backgroundColorBehind =\n    elementIndex === -1\n      ? undefined\n      : elementsAtPoint\n          .slice(elementIndex + 1)\n          .filter(\n            (elementBehind): elementBehind is HTMLElement =>\n              elementBehind instanceof HTMLElement,\n          )\n          .map(getElementComputedBackgroundColor)\n          .find((backgroundColor) => !isTransparentColor(backgroundColor));\n\n  return backgroundColorBehind\n    ? normalizeBackgroundColor(backgroundColorBehind)\n    : getBackgroundColor(element);\n};\n"],"mappings":";;;;;;AAYA,IAAAA,gBAAA,GAAAC,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,MAAMC,gBAAgB,GAAGA,CAAC;EACxBC;AAGF,CAAC,KAAgC;EAC/B,MAAM;IAAEC,MA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