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