"use strict";const a=require("loglevel");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const a__default=_interopDefaultCompat(a),createTranslation=(e,t)=>s=>s(e,t),createTheme=(e,t)=>s=>s(e,t,{append:!1}),STORE={};let l=!0,h$1=!1;const w$1=/^[a-z][a-z0-9]{1,}(-[a-z0-9]+)?$/,R$1=e=>typeof e=="string"&&w$1.test(e),u=e=>{if(R$1(e)===!1)throw new Error(`[Theming] The theme identifier "${typeof e=="string"?e:""}" (Type: ${typeof e}) is not valid. Please use only follow this pattern: /^[a-z][a-z0-9]{1,}(-[a-z0-9]+)?$/`)},patchThemeTag=(e,t,s,o)=>setThemeTag(e,t,s,o),setThemeTag=(e,t,s,o)=>{o=o??{},o.append=o.append??!1,u(e),l===!0&&h$1===!1&&(h$1=!0,a__default.warn(`[Theming] The theme process is locked. This means that the theme "${e}" should not be patched. import { register } from 'adopted-style-sheets'; import { defineCustomElements } from '...'; import { THEME } from '...'; register(THEME, defineCustomElements) .then(() => { // run your app or website }) .catch(console.warn);`)),(typeof STORE.A11yUi!="object"||STORE.A11yUi===null)&&(STORE.A11yUi={}),typeof STORE.A11yUi=="object"&&STORE.A11yUi!==null&&(typeof STORE.A11yUi.Themes!="object"||STORE.A11yUi.Themes===null)&&(STORE.A11yUi.Themes={}),typeof STORE.A11yUi=="object"&&STORE.A11yUi!==null&&typeof STORE.A11yUi.Themes=="object"&&STORE.A11yUi.Themes!==null&&(typeof STORE.A11yUi.Themes[e]!="object"||STORE.A11yUi.Themes[e]===null)&&(STORE.A11yUi.Themes[e]={}),typeof STORE.A11yUi=="object"&&STORE.A11yUi!==null&&typeof STORE.A11yUi.Themes=="object"&&STORE.A11yUi.Themes!==null&&typeof STORE.A11yUi.Themes[e]=="object"&&STORE.A11yUi.Themes[e]!==null&&(o.append&&typeof STORE.A11yUi.Themes[e][t]=="string"?STORE.A11yUi.Themes[e][t]+=s:STORE.A11yUi.Themes[e][t]=s)},patchTheme=(e,t,s,o)=>setTheme(e,t,s,o),setTheme=(e,t,s,o)=>(u(e),typeof t=="object"&&t!==null&&Object.getOwnPropertyNames(t).forEach(n=>{const U=t[n],j=n.toLowerCase(),v=typeof o?.transformTagName=="function"&&!["GLOBAL","PROPERTIES"].includes(n)?o.transformTagName(j):n;typeof U=="string"&&U.length>0&&setThemeTag(e,v.toUpperCase(),U,s)}),e),f$1=e=>{if(e instanceof HTMLElement){if(typeof e.dataset.theme=="string")return e;{let t=e.parentNode;for(;t instanceof ShadowRoot;)t=t.host;return f$1(t)}}else return null},d$1=(e={})=>e.themeEncroachCss==="false"||e.themeReset==="true"?!1:{mode:e.themeEncroachCssMode==="after"||e.themeEncroachCssMode==="before"?e.themeEncroachCssMode:"before"},m$1=()=>typeof STORE.A11yUi=="object"&&STORE.A11yUi!==null&&typeof STORE.A11yUi.Theme=="object"&&STORE.A11yUi.Theme!==null&&typeof STORE.A11yUi.Theme.cache=="boolean"&&typeof STORE.A11yUi.Theme.encroachCss=="object"&&STORE.A11yUi.Theme.encroachCss!==null&&typeof STORE.A11yUi.Theme.encroachCss.mode=="string"&&typeof STORE.A11yUi.Theme.name=="string",p$1=()=>!(typeof STORE.A11yUi=="object"&&STORE.A11yUi!==null)||!(typeof STORE.A11yUi.Theme=="object"&&STORE.A11yUi.Theme!==null)||STORE.A11yUi.Theme.name!=="default",getThemeDetails=e=>{if(m$1())return STORE.A11yUi.Theme;{const t={cache:!0,encroachCss:d$1(),loglevel:"silent",name:null},s=f$1(e);return s instanceof HTMLElement&&(t.cache=s.dataset.themeCache!=="false",t.encroachCss=d$1(s.dataset),t.loglevel=s.dataset.themeLoglevel==="debug"?s.dataset.themeLoglevel:"silent",t.name=s.dataset.theme||null),t}},getTheme=e=>getThemeDetails(e).name,k$1=(e,t)=>({cache:t.cache!==!1,detect:t.detect==="auto"?"auto":"fixed",encroachCss:t.encroachCss===!1?!1:typeof t.encroachCss=="object"&&t.encroachCss!=null&&(t.encroachCss.mode==="after"||t.encroachCss.mode==="before")?t.encroachCss:{mode:"before"},loglevel:t.loglevel==="debug"?t.loglevel:"silent",name:typeof t.name=="string"?t.name:e}),A$1=(e,t)=>{m$1()===!1&&p$1()&&typeof t=="object"&&t!==null&&(t=k$1(e,t),t.detect==="fixed"?(t.name===null&&typeof e=="string"&&(t.name=e),e===t.name&&((typeof STORE.A11yUi!="object"||STORE.A11yUi===null)&&(STORE.A11yUi={}),STORE.A11yUi.Theme=t,a__default.info(`[Theming] Theme "${e}" was set as default theme.`))):a__default.warn("[Theming] The presetting of theme options is only relevant by using 'fixed' detection mode."))};let T=!1;const register=(e,t,s={})=>{T===!1&&(T=!0,l=!1),typeof e=="function"?e=new Set([e]):Array.isArray(e)&&(e=new Set(e)),e instanceof Set&&e.forEach(n=>{typeof n=="function"&&n.length===1?A$1(n((U,j,v)=>setTheme(U,j,v,s)),{cache:s.theme?.cache,detect:s.theme?.detect,encroachCss:s.theme?.encroachCss,name:s.theme?.name}):a__default.error("[Theming] Es wurde versucht eine nicht kompatibles Theme zu laden.")}),l=!0,typeof t=="function"?t=new Set([t]):Array.isArray(t)&&(t=new Set(t));const o=[];return t.forEach(n=>{const U=n();U instanceof Promise&&o.push(U)}),Promise.all(o)},r=class{constructor(e,t){this.store=this.createStore(e,t)}static getInstance(e,t){let s=r.instances.get(e);return s===void 0&&(s=new r(t,e),r.instances.set(e,s)),s}createStore(e,t){return Object.defineProperty(e,t,{enumerable:!1,value:{},writable:!1}),e[t]}recursiveSetItem(e,t,s,o=r.options){let n=typeof s=="object"&&s!==null?{}:s;if(Object.defineProperty(e,t,{enumerable:o.enumerable===!0,get:()=>n,set:o.immutable===!0?void 0:U=>n=U}),typeof s=="object"&&s!==null)for(const[U,j]of Object.entries(s))this.recursiveSetItem(e[t],U,j,o)}setItem(e,t,s=r.options){return this.recursiveSetItem(this.store,e,t,s),this}getItem(e){return Array.isArray(e)?e.map(t=>this.getItem(t)):this.store[e]}};let RobustStore=r;RobustStore.options={enumerable:!1,immutable:!1},RobustStore.instances=new Map;const i=new Map,S=[],h=new Set,c=new Map,p=/--[^;]+/g,L=/:/;(typeof STORE.A11yUi!="object"||STORE.A11yUi===null)&&(STORE.A11yUi={CSS_STYLE_CACHE:c,HYDRATED_HISTORY:S,STYLING_TASK_QUEUE:i});const R=(e,t)=>{let s=t.match(p);if(Array.isArray(s)){s=s.filter(n=>L.test(n));const o=document.createElement("style");o.innerHTML=`.${e} {${s.join(";")}}`,document.querySelector("head")?.appendChild(o)}h.add(e)},getCssStyle=(e,t)=>typeof STORE.A11yUi=="object"&&STORE.A11yUi!==null&&typeof STORE.A11yUi.Themes=="object"&&STORE.A11yUi.Themes!==null&&typeof STORE.A11yUi.Themes[e]=="object"&&STORE.A11yUi.Themes[e]!==null&&typeof STORE.A11yUi.Themes[e][t]=="string"?STORE.A11yUi.Themes[e][t].replace(/\r?\n/g,""):"",M=e=>{for(const t of Array.from(e.childNodes))if(t instanceof HTMLStyleElement&&t.tagName==="STYLE")e.removeChild(t);else break},H=(e,t)=>{try{const s=[];t.forEach(o=>{const n=new CSSStyleSheet;n.replaceSync(o),s.push(n)}),e.adoptedStyleSheets=s}catch{t.reverse().forEach(s=>{const o=document.createElement("style");o.innerHTML=s,e.insertBefore(o,e.firstChild)})}},w=(e,t,s)=>{if(s!==!1){const o=[...Array.from(e.childNodes).filter(U=>U instanceof HTMLStyleElement&&U.tagName==="STYLE")];let n;try{n=[...Array.from(e.adoptedStyleSheets)]}catch{n=[]}s?.mode==="before"?(o.reverse().forEach(U=>t.unshift(U.innerHTML)),n.reverse().forEach(U=>t.unshift(Array.from(U.cssRules).map(j=>j.cssText).join("")))):s?.mode==="after"&&(o.forEach(U=>t.push(U.innerHTML)),n.forEach(U=>t.push(Array.from(U.cssRules).map(j=>j.cssText).join(""))))}},g=(e,t,s)=>{const o=t.name||"default";let n;try{if(e.shadowRoot===null)throw new Error("ShadowRoot is null");n=e.shadowRoot}catch{n=e}if(c.get(o)?.has(e.tagName))d(e,n,c.get(o)?.get(e.tagName),s);else{const U=getCssStyle(o,"PROPERTIES"),j=getCssStyle(o,"GLOBAL"),v=getCssStyle(o,e.tagName);h.has(o)===!1&&R(o,j);const x=[U,j,v];w(n,x,t.encroachCss),t.loglevel==="debug"&&console.log(e.tagName,x),t.cache===!0&&(c.has(o)===!1&&c.set(o,new Map),c.get(o)?.set(e.tagName,x)),d(e,n,x,s)}},d=(e,t,s,o)=>{M(t),H(t,s),e.style.display=o},E=e=>{e.loglevel==="debug"&&S.push({timestamp:Date.now(),numberOfTasks:i.size})},A=(e,t)=>{i.set(e,{styleDisplay:e.style.display?`${e.style.display}`:null,themeDetails:t})},k=(e,t)=>{A(e,t),E(t)},b=e=>{i.delete(e)},f=(e,t)=>{b(e),E(t)},m=e=>{const t=setTimeout(()=>{if(clearTimeout(t),i.has(e)&&e.classList.contains("hydrated")){const{styleDisplay:s,themeDetails:o}=i.get(e);g(e,o,s),f(e,o)}else m(e)},25)},D=e=>{for(const t of e)if(i.has(t.target)&&t.target.classList.contains("hydrated")){const{styleDisplay:s,themeDetails:o}=i.get(t.target);g(t.target,o,s),f(t.target,o)}},C={attributes:!0,attributeFilter:["class"],childList:!1,subtree:!1};let y;try{y=new MutationObserver(D)}catch{y=null}const setThemeStyle=(e,t)=>{k(e,t),y?y.observe(e,C):m(e),e.style.display="none"};class Theme{constructor(t,s,o){this.createTheme=(n,U)=>createTheme(n,U),this.createTranslation=(n,U)=>createTranslation(n,U),this.Prefix=t,this.Key=Object.getOwnPropertyNames(s),this.Tag=Object.getOwnPropertyNames(o)}}exports.RobustStore=RobustStore,exports.STORE=STORE,exports.Theme=Theme,exports.getCssStyle=getCssStyle,exports.getTheme=getTheme,exports.getThemeDetails=getThemeDetails,exports.patchTheme=patchTheme,exports.patchThemeTag=patchThemeTag,exports.register=register,exports.setTheme=setTheme,exports.setThemeStyle=setThemeStyle,exports.setThemeTag=setThemeTag;