{"version":3,"file":"createShadowDomElements.cjs","names":["_createReactRootElements","require","_encapsulateShadowDomFromGlobalStyles","createShadowDomElements","containerElement","nonce","window","cspNonce","shadowRoot","attachShadow","mode","appRootElement","stylesRootElement","createReactRootElements","appendChild","encapsulateShadowDomFromGlobalStyles","emotionRootElement","shadowRootElement","exports","createShadowRootElement","document","createElement","setAttribute"],"sources":["../../../src/web-component/createShadowDomElements.ts"],"sourcesContent":["/*!\n * Copyright (c) 2023-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 { createReactRootElements } from \"./createReactRootElements.js\";\nimport { encapsulateShadowDomFromGlobalStyles } from \"./encapsulateShadowDomFromGlobalStyles.js\";\n\n/**\n * This function is necessary only when using bare Shadow DOM, but with UI Shell rendering in a Web Component, you won't be able to render your Shadow DOM in its Shadow DOM without using a Web Component.\n *\n * In most cases, you'll want to use `renderReactInWebComponent` from `@okta/odyssey-react-mui/web-component` instead.\n */\nexport const createShadowDomElements = (\n  containerElement: HTMLElement,\n  nonce: string = window.cspNonce,\n) => {\n  const shadowRoot = containerElement.attachShadow({ mode: \"open\" });\n\n  // Container for Emotion `<style>` elements.\n  const { appRootElement, stylesRootElement } = createReactRootElements();\n\n  shadowRoot.appendChild(appRootElement);\n  shadowRoot.appendChild(stylesRootElement);\n\n  encapsulateShadowDomFromGlobalStyles({\n    nonce,\n    stylesRootElement,\n  });\n\n  return {\n    emotionRootElement: stylesRootElement,\n    shadowRootElement: appRootElement,\n  };\n};\n\n/**\n * @deprecated Use `createShadowDomElements` instead which returns an object instead of an array. It's otherwise the same.\n * @deprecated Ideally, use `renderReactInWebComponent` from `@okta/odyssey-react-mui/web-component` instead. This function was necessary when using bare Shadow DOM, but with UI Shell rendering in a Web Component, you won't be able to render your Shadow DOM in its Shadow DOM without using a Web Component. */\nexport const createShadowRootElement = (\n  containerElement: HTMLElement,\n): [HTMLStyleElement, HTMLDivElement] => {\n  const shadowRoot = containerElement.attachShadow({ mode: \"open\" });\n\n  // the element that styles will be cached into\n  const emotionRootElement = document.createElement(\"style\");\n  emotionRootElement.setAttribute(\"id\", \"style-root\");\n  emotionRootElement.setAttribute(\"nonce\", window.cspNonce);\n\n  // the element that emotion renders html into\n  const shadowRootElement = document.createElement(\"div\");\n  shadowRootElement.setAttribute(\"id\", \"shadow-root\");\n\n  shadowRoot.appendChild(emotionRootElement);\n  shadowRoot.appendChild(shadowRootElement);\n\n  return [emotionRootElement, shadowRootElement];\n};\n"],"mappings":";;;;;;AAYA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,qCAAA,GAAAD,OAAA;AAbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAUO,MAAME,uBAAuB,GAAGA,CACrCC,gBAA6B,EAC7BC,KAAa,GAAGC,MAAM,CAACC,QAAQ,KAC5B;EACH,MAAMC,UAAU,GAAGJ,gBAAgB,CAACK,YAAY,CAAC;IAAEC,IAAI,EAAE;EAAO,CAAC,CAAC;EAGlE,MAAM;IAAEC,cAAc;IAAEC;EAAkB,CAAC,GAAG,IAAAC,gDAAuB,EAAC,CAAC;EAEvEL,UAAU,CAACM,WAAW,CAACH,cAAc,CAAC;EACtCH,UAAU,CAACM,WAAW,CAACF,iBAAiB,CAAC;EAEzC,IAAAG,0EAAoC,EAAC;IACnCV,KAAK;IACLO;EACF,CAAC,CAAC;EAEF,OAAO;IACLI,kBAAkB,EAAEJ,iBAAiB;IACrCK,iBAAiB,EAAEN;EACrB,CAAC;AACH,CAAC;AAACO,OAAA,CAAAf,uBAAA,GAAAA,uBAAA;AAKK,MAAMgB,uBAAuB,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