UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

4 lines 11 kB
/*! * KoliBri - The accessible HTML-Standard */ "use strict";var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},loglevel={exports:{}};!function(e){var t,o;t=commonjsGlobal,o=function(){var e=function(){},t="undefined",o=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),n=["trace","debug","info","warn","error"],a={},s=null;function r(e,t){var o=e[t];if("function"==typeof o.bind)return o.bind(e);try{return Function.prototype.bind.call(o,e)}catch(t){return function(){return Function.prototype.apply.apply(o,[e,arguments])}}}function l(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function i(){for(var o=this.getLevel(),a=0;a<n.length;a++){var s=n[a];this[s]=a<o?e:this.methodFactory(s,o,this.name)}if(this.log=this.debug,typeof console===t&&o<this.levels.SILENT)return"No console available for logging"}function c(e){return function(){typeof console!==t&&(i.call(this),this[e].apply(this,arguments))}}function h(n,a,s){return function(n){return"debug"===n&&(n="log"),typeof console!==t&&("trace"===n&&o?l:void 0!==console[n]?r(console,n):void 0!==console.log?r(console,"log"):e)}(n)||c.apply(this,arguments)}function f(e,o){var r,l,c,f=this,y="loglevel";function m(){var e;if(typeof window!==t&&y){try{e=window.localStorage[y]}catch(e){}if(typeof e===t)try{var o=window.document.cookie,n=encodeURIComponent(y),a=o.indexOf(n+"=");-1!==a&&(e=/^([^;]+)/.exec(o.slice(a+n.length+1))[1])}catch(e){}return void 0===f.levels[e]&&(e=void 0),e}}function d(e){var t=e;if("string"==typeof t&&void 0!==f.levels[t.toUpperCase()]&&(t=f.levels[t.toUpperCase()]),"number"==typeof t&&t>=0&&t<=f.levels.SILENT)return t;throw new TypeError("log.setLevel() called with invalid level: "+e)}"string"==typeof e?y+=":"+e:"symbol"==typeof e&&(y=void 0),f.name=e,f.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},f.methodFactory=o||h,f.getLevel=function(){return null!=c?c:null!=l?l:r},f.setLevel=function(e,o){return c=d(e),!1!==o&&function(e){var o=(n[e]||"silent").toUpperCase();if(typeof window!==t&&y){try{return void(window.localStorage[y]=o)}catch(e){}try{window.document.cookie=encodeURIComponent(y)+"="+o+";"}catch(e){}}}(c),i.call(f)},f.setDefaultLevel=function(e){l=d(e),m()||f.setLevel(e,!1)},f.resetLevel=function(){c=null,function(){if(typeof window!==t&&y){try{window.localStorage.removeItem(y)}catch(e){}try{window.document.cookie=encodeURIComponent(y)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}(),i.call(f)},f.enableAll=function(e){f.setLevel(f.levels.TRACE,e)},f.disableAll=function(e){f.setLevel(f.levels.SILENT,e)},f.rebuild=function(){if(s!==f&&(r=d(s.getLevel())),i.call(f),s===f)for(var e in a)a[e].rebuild()},r=d(s?s.getLevel():"WARN");var p=m();null!=p&&(c=d(p)),i.call(f)}(s=new f).getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=a[e];return t||(t=a[e]=new f(e,s.methodFactory)),t};var y=typeof window!==t?window.log:void 0;return s.noConflict=function(){return typeof window!==t&&window.log===s&&(window.log=y),s},s.getLoggers=function(){return a},s.default=s,s},e.exports?e.exports=o():t.log=o()}(loglevel);const l=loglevel.exports,R=(e,t)=>o=>o(e,t),H=(e,t)=>o=>o(e,t,{append:!1}),$=new Map,M=[],Y=new Map,a={A11yUi:{CSS_STYLE_CACHE:$,HYDRATED_HISTORY:M,STYLING_TASK_QUEUE:Y,Themes:{}}};let T=!0,y=!1;const I=/^[a-z][a-z0-9]{1,}(-[a-z0-9]+)?$/,O=e=>"string"==typeof e&&I.test(e),A=e=>{if(!1===O(e))throw new Error(`[Theming] The theme identifier "${"string"==typeof e?e:""}" (Type: ${typeof e}) is not valid. Please use only follow this pattern: /^[a-z][a-z0-9]{1,}(-[a-z0-9]+)?$/`)},k=(e,t,o,n)=>p(e,t,o,n),p=(e,t,o,n)=>{(n=n??{}).append=n.append??!1,A(e),!0===T&&!1===y&&(y=!0,l.warn(`[Theming] The theme process is locked. This means that the theme "${e}" should not be patched.\n\n\timport { register } from 'adopted-style-sheets';\n\timport { defineCustomElements } from '...';\n\timport { THEME } from '...';\n\n\tregister(THEME, defineCustomElements)\n\t.then(() => {\n\t\t// run your app or website\n\t})\n\t.catch(console.warn);`)),("object"!=typeof a.A11yUi.Themes[e]||null===a.A11yUi.Themes[e])&&(a.A11yUi.Themes[e]={}),n.append&&"string"==typeof a.A11yUi.Themes[e][t]?a.A11yUi.Themes[e][t]+=o:a.A11yUi.Themes[e][t]=o},P=(e,t,o,n)=>u(e,t,o,n),u=(e,t,o,n)=>(A(e),"object"==typeof t&&null!==t&&Object.getOwnPropertyNames(t).forEach((a=>{const s=t[a],r=a.toLowerCase(),l="function"!=typeof n?.transformTagName||["GLOBAL","PROPERTIES"].includes(a)?a:n.transformTagName(r);"string"==typeof s&&s.length>0&&p(e,l.toUpperCase(),s,o)})),e),S=e=>{if(e instanceof HTMLElement){if("string"==typeof e.dataset.theme)return e;{let t=e.parentNode;for(;t instanceof ShadowRoot;)t=t.host;return S(t)}}return null},U=(e={})=>"false"!==e.themeEncroachCss&&"true"!==e.themeReset&&{mode:"after"===e.themeEncroachCssMode||"before"===e.themeEncroachCssMode?e.themeEncroachCssMode:"before"},E=()=>"object"==typeof a.A11yUi&&null!==a.A11yUi&&"object"==typeof a.A11yUi.Theme&&null!==a.A11yUi.Theme&&"boolean"==typeof a.A11yUi.Theme.cache&&"object"==typeof a.A11yUi.Theme.encroachCss&&null!==a.A11yUi.Theme.encroachCss&&"string"==typeof a.A11yUi.Theme.encroachCss.mode&&"string"==typeof a.A11yUi.Theme.name,D=()=>!("object"==typeof a.A11yUi&&null!==a.A11yUi&&"object"==typeof a.A11yUi.Theme&&null!==a.A11yUi.Theme&&"default"===a.A11yUi.Theme.name),b=e=>{if(E())return a.A11yUi.Theme;{const t={cache:!0,encroachCss:U(),loglevel:"silent",mode:"csr",name:null},o=S(e);return o instanceof HTMLElement&&(t.cache="false"!==o.dataset.themeCache,t.encroachCss=U(o.dataset),t.loglevel="debug"===o.dataset.themeLoglevel?o.dataset.themeLoglevel:"silent",t.mode="ssr"===o.dataset.themeMode?o.dataset.themeMode:"csr",t.name=o.dataset.theme||null),t}},K=(e,t)=>({cache:!1!==t.cache,detect:"auto"===t.detect?"auto":"fixed",encroachCss:!1!==t.encroachCss&&("object"!=typeof t.encroachCss||null==t.encroachCss||"after"!==t.encroachCss.mode&&"before"!==t.encroachCss.mode?{mode:"before"}:t.encroachCss),loglevel:"debug"===t.loglevel?t.loglevel:"silent",mode:"ssr"===t.mode?t.mode:"csr",name:"string"==typeof t.name?t.name:e}),Q=(e,t)=>{!1===E()&&D()&&"object"==typeof t&&null!==t&&("fixed"===(t=K(e,t)).detect?(null===t.name&&"string"==typeof e&&(t.name=e),e===t.name&&(a.A11yUi.Theme=t,l.info(`[Theming] Theme "${e}" was set as default theme.`))):y||(y=!0,l.warn("[Theming] The presetting of theme options is only relevant by using 'fixed' detection mode.")))};let C=!1;const F=(e,t,o={})=>{!1===C&&(C=!0,T=!1),"function"==typeof e?e=new Set([e]):Array.isArray(e)&&(e=new Set(e)),e instanceof Set&&e.forEach((e=>{"function"==typeof e&&1===e.length?Q(e(((e,t,n)=>u(e,t,n,o))),{cache:o.theme?.cache,detect:o.theme?.detect,encroachCss:o.theme?.encroachCss,mode:o.theme?.mode,name:o.theme?.name}):l.error("[Theming] An attempt was made to load an incompatible theme.")})),T=!0,"function"==typeof t?t=new Set([t]):Array.isArray(t)&&(t=new Set(t));const n=[];return t.forEach((e=>{const t=e();t instanceof Promise&&n.push(t)})),Promise.all(n)},w=new Set,q=/--[^;]+/g,J=/:/,V=(e,t)=>{let o=t.match(q);if(Array.isArray(o)){o=o.filter((e=>J.test(e)));const t=document.createElement("style");t.innerHTML=`.${e} {${o.join(";")}}`,document.querySelector("head")?.appendChild(t)}w.add(e)},f=(e,t)=>"object"==typeof a.A11yUi&&null!==a.A11yUi&&"object"==typeof a.A11yUi.Themes&&null!==a.A11yUi.Themes&&"object"==typeof a.A11yUi.Themes[e]&&null!==a.A11yUi.Themes[e]&&"string"==typeof a.A11yUi.Themes[e][t]?a.A11yUi.Themes[e][t].replace(/\r?\n/g,""):"",W=e=>{for(const t of Array.from(e.childNodes)){if(!(t instanceof HTMLStyleElement&&"STYLE"===t.tagName&&void 0===t.dataset.themingFallback))break;e.removeChild(t)}},X=(e,t)=>{try{if("ssr"===a.A11yUi.Theme?.mode)throw new Error("SSR");const o=[];t.forEach((e=>{const t=new CSSStyleSheet;t.replaceSync(e),o.push(t)})),e.adoptedStyleSheets=o}catch{[...t].reverse().forEach(((t,o)=>{if("string"!=typeof t||0===t.length)return;const n=document.createElement("style");switch(n.dataset.themingFallback="",o){case 4:n.dataset.themingBaseA11y="";break;case 3:n.dataset.themingBaseGlobal="";break;case 2:n.dataset.themingBaseComponent="";break;case 1:n.dataset.themingCustomGlobal="";break;case 0:n.dataset.themingCustomComponent="";break;default:n.dataset.themingUnknown=""}n.innerHTML=t,e.insertBefore(n,e.firstChild)}))}},Z=(e,t,o)=>{if(!1!==o){const n=[...Array.from(e.childNodes).filter((e=>e instanceof HTMLStyleElement&&"STYLE"===e.tagName))];let a;try{a=[...Array.from(e.adoptedStyleSheets)]}catch{a=[]}"before"===o?.mode?(n.reverse().forEach((e=>t.unshift(e.innerHTML))),a.reverse().forEach((e=>t.unshift(Array.from(e.cssRules).map((e=>e.cssText)).join(""))))):"after"===o?.mode&&(n.forEach((e=>t.push(e.innerHTML))),a.forEach((e=>t.push(Array.from(e.cssRules).map((e=>e.cssText)).join("")))))}},L=(e,t,o)=>{const n=t.name||"default";let s;try{if(null===e.shadowRoot)throw new Error("ShadowRoot is null");s=e.shadowRoot}catch{s=e}if(a.A11yUi.CSS_STYLE_CACHE.get(n)?.has(e.tagName))_(e,s,a.A11yUi.CSS_STYLE_CACHE.get(n)?.get(e.tagName),o);else{const r=f(n,"PROPERTIES"),l=f(n,"GLOBAL"),i=f(n,e.tagName);!1===w.has(n)&&V(n,l);const c=[r,l,i];Z(s,c,t.encroachCss),"debug"===t.loglevel&&console.log(e.tagName,c),!0===t.cache&&(!1===a.A11yUi.CSS_STYLE_CACHE.has(n)&&a.A11yUi.CSS_STYLE_CACHE.set(n,new Map),a.A11yUi.CSS_STYLE_CACHE.get(n)?.set(e.tagName,c)),_(e,s,c,o)}},_=(e,t,o,n)=>{W(t),X(t,o),e.style.display=n},N=e=>{"debug"===e.loglevel&&a.A11yUi.HYDRATED_HISTORY.push({timestamp:Date.now(),numberOfTasks:a.A11yUi.STYLING_TASK_QUEUE.size})},ee=(e,t)=>{a.A11yUi.STYLING_TASK_QUEUE.set(e,{styleDisplay:e.style.display?`${e.style.display}`:null,themeDetails:t})},te=(e,t)=>{ee(e,t),N(t)},se=e=>{a.A11yUi.STYLING_TASK_QUEUE.delete(e)},j=(e,t)=>{se(e),N(t)},v=e=>{const t=setTimeout((()=>{if(clearTimeout(t),a.A11yUi.STYLING_TASK_QUEUE.has(e)&&e.classList.contains("hydrated")){const{styleDisplay:t,themeDetails:o}=a.A11yUi.STYLING_TASK_QUEUE.get(e);L(e,o,t),j(e,o)}else v(e)}),25)},oe=e=>{for(const t of e)if(a.A11yUi.STYLING_TASK_QUEUE.has(t.target)&&t.target.classList.contains("hydrated")){const{styleDisplay:e,themeDetails:o}=a.A11yUi.STYLING_TASK_QUEUE.get(t.target);L(t.target,o,e),j(t.target,o)}},ae={attributes:!0,attributeFilter:["class"],childList:!1,subtree:!1};let d;try{d=new MutationObserver(oe)}catch{d=null}const ne=(e,t)=>{t={...a.A11yUi.Theme,...t},te(e,t),d?d.observe(e,ae):v(e),e.style.display="none"};class re{constructor(e,t,o){this.createTheme=(e,t)=>H(e,t),this.createTranslation=(e,t)=>R(e,t),this.Prefix=e,this.Key=Object.getOwnPropertyNames(t),this.Tag=Object.getOwnPropertyNames(o)}}exports.F=F,exports.P=P,exports.b=b,exports.f=f,exports.k=k,exports.ne=ne,exports.re=re;