/*!
 * KoliBri - The accessible HTML-Standard
 */
import{g as e,L as t,a as n,s as i,b as s,p as o,c as a,d as c,f as l}from"./index-c3ae175d.js";class r{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(t){if(t instanceof HTMLElement){this.lockedElements.has(t)&&this.unlockElement(this.lockedElements.get(t),t);const e=setTimeout((()=>{clearTimeout(e),t.focus()}),500)}if(this.unlockLockedElements(this.lockedElements),this.modalStack.size>0){const t=Array.from(this.modalStack.keys()),n=t[t.length-1];this.modalStack.forEach(((e,t)=>{t.style.display=n===t?"inline":"none"})),e().body.style.maxHeight="100vh",e().body.style.overflow="hidden",this.lockFocus(e().body,n)}else e().body.style.maxHeight="unset",e().body.style.overflow="unset"}openModal(e,n){e instanceof HTMLElement==!1?t.warn("[KolModalService] Die DOM-Referenz des Modals ist nicht valide."):(this.modalStack.set(e,{activeElement:n}),this.renderModalIfExists())}closeModal(e){var n;if(e instanceof HTMLElement==!1)t.warn("[KolModalService] Die DOM-Referenz des Modals ist nicht valide.");else{const t=null===(n=this.modalStack.get(e))||void 0===n?void 0:n.activeElement;this.modalStack.delete(e),this.renderModalIfExists(t)}}}const f=e=>{e instanceof Window?(i(e),n().document instanceof Document?s(e.document):console.warn("The given Window has no valid Document.")):console.warn("The given Window is not valid.")},d=()=>{const t=e().querySelector('meta[name="kolibri"]');if(t&&t.hasAttribute("content")){const e=t.getAttribute("content");"string"==typeof e&&(a(e.includes("dev-mode=true")),c(e.includes("experimental-mode=true")),l(e.includes("color-contrast-analysis=true")))}},h=()=>{let e=n().KoliBri;return void 0===e&&(e={},Object.defineProperty(n(),"KoliBri",{value:e,writable:!1})),e},u=()=>{if(void 0===h().Modal){const e=new r;Object.defineProperty(h(),"Modal",{get:function(){return e}}),d(),t.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.")},m=()=>{!0!==h().adviceShown&&(Object.defineProperty(h(),"adviceShown",{get:function(){return!0}}),t.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"))};let M=()=>Math.floor(16777215*Math.random()).toString(16);"test"===o&&(M=()=>"nonce");export{f as c,h as g,u as i,M as n,m as r};