/*!
 * KoliBri - The accessible HTML-Standard
 */
"use strict";const index=require("./index-7215e5f8.js");class ModalService{constructor(){this.lockedElements=new Map,this.modalStack=new Map}lockElement(e){const t=e.getAttribute("tabindex");(e instanceof HTMLAnchorElement||e instanceof HTMLButtonElement||e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement||"string"==typeof t||void 0!==e.dataset.kolModal)&&("string"==typeof t?this.lockedElements.set(e,{tabIndex:t}):this.lockedElements.set(e,{}),e.setAttribute("tabindex","-1"),e.setAttribute("aria-hidden","true"),e.style.userSelect="none")}unlockElement(e,t){"string"==typeof e.tabIndex?t.setAttribute("tabindex",e.tabIndex):t.removeAttribute("tabindex"),t.removeAttribute("aria-hidden"),t.style.userSelect="unset",this.lockedElements.delete(t)}unlockLockedElements(e){e.forEach(this.unlockElement.bind(this))}lockFocus(e,t){try{if(e!==t&&(e instanceof HTMLElement||e instanceof ShadowRoot)){e instanceof HTMLElement&&(this.lockElement(e),this.lockFocus(e.shadowRoot,t));for(let n=0;n<e.children.length;n++)this.lockFocus(e.children[n],t)}}catch(e){}}renderModalIfExists(e){if(e instanceof HTMLElement){this.lockedElements.has(e)&&this.unlockElement(this.lockedElements.get(e),e);const t=setTimeout((()=>{clearTimeout(t),e.focus()}),500)}if(this.unlockLockedElements(this.lockedElements),this.modalStack.size>0){const e=Array.from(this.modalStack.keys()),t=e[e.length-1];this.modalStack.forEach(((e,n)=>{n.style.display=t===n?"inline":"none"})),index.getDocument().body.style.maxHeight="100vh",index.getDocument().body.style.overflow="hidden",this.lockFocus(index.getDocument().body,t)}else index.getDocument().body.style.maxHeight="unset",index.getDocument().body.style.overflow="unset"}openModal(e,t){e instanceof HTMLElement==!1?index.Log.warn("[KolModalService] Die DOM-Referenz des Modals ist nicht valide."):(this.modalStack.set(e,{activeElement:t}),this.renderModalIfExists())}closeModal(e){var t;if(e instanceof HTMLElement==!1)index.Log.warn("[KolModalService] Die DOM-Referenz des Modals ist nicht valide.");else{const n=null===(t=this.modalStack.get(e))||void 0===t?void 0:t.activeElement;this.modalStack.delete(e),this.renderModalIfExists(n)}}}const configKoliBri=e=>{e instanceof Window?(index.setWindow(e),index.getWindow().document instanceof Document?index.setDocument(e.document):console.warn("The given Window has no valid Document.")):console.warn("The given Window is not valid.")},initMeta=()=>{const e=index.getDocument().querySelector('meta[name="kolibri"]');if(e&&e.hasAttribute("content")){const t=e.getAttribute("content");"string"==typeof t&&(index.setDevMode(t.includes("dev-mode=true")),index.setExperimentalMode(t.includes("experimental-mode=true")),index.setColorContrastAnalysis(t.includes("color-contrast-analysis=true")))}},getKoliBri=()=>{let e=index.getWindow().KoliBri;return void 0===e&&(e={},Object.defineProperty(index.getWindow(),"KoliBri",{value:e,writable:!1})),e},initKoliBri=()=>{if(void 0===getKoliBri().Modal){const e=new ModalService;Object.defineProperty(getKoliBri(),"Modal",{get:function(){return e}}),initMeta(),index.Log.debug("\n\t,--. ,--.         ,--. ,--. ,-----.           ,--.\n\t|  .'   /  ,---.  |  | `--' |  |) /_  ,--.--. `--'\n\t|  .   '  | .-. | |  | ,--. |  .-.  \\ |  .--' ,--.\n\t|  |\\   \\ | '-' | |  | |  | |  '--' / |  |    |  |\n\t`--' `--´  `---´  `--' `--' `------´  `--'    `--'\n\t🚹 The accessible HTML-Standard | 👉 https://public-ui.github.io | 2.0.6\n\t\t",{forceLog:!0})}else console.warn("You can only initialize KoliBri once.")},renderDevAdvice=()=>{!0!==getKoliBri().adviceShown&&(Object.defineProperty(getKoliBri(),"adviceShown",{get:function(){return!0}}),index.Log.debug("\nYou are using the KoliBri component library. If you have any suggestions for improvement or find a problem, please contact us:\n\nTicket: https://github.com/public-ui/kolibri/issues/new/choose (for privacy reasons, please use email)\nEmail: kolibri@itzbund.de\n"))};exports.nonce=()=>Math.floor(16777215*Math.random()).toString(16),"test"===index.processEnv&&(exports.nonce=()=>"nonce"),exports.configKoliBri=configKoliBri,exports.getKoliBri=getKoliBri,exports.initKoliBri=initKoliBri,exports.renderDevAdvice=renderDevAdvice;