@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 10.9 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t={exports:{}};!function(t){!function(e,o){t.exports?t.exports=o():e.log=o()}(e,(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"],l={},s=null;function a(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 r(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function i(n){return"debug"===n&&(n="log"),typeof console!==t&&("trace"===n&&o?r:void 0!==console[n]?a(console,n):void 0!==console.log?a(console,"log"):e)}function c(){for(var o=this.getLevel(),l=0;l<n.length;l++){var s=n[l];this[s]=l<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 h(e){return function(){typeof console!==t&&(c.call(this),this[e].apply(this,arguments))}}function f(e,t,o){return i(e)||h.apply(this,arguments)}function y(e,o){var a,r,i,h=this,y="loglevel";function m(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){}}}function d(){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),l=o.indexOf(n+"=");-1!==l&&(e=/^([^;]+)/.exec(o.slice(l+n.length+1))[1])}catch(e){}return void 0===h.levels[e]&&(e=void 0),e}}function u(e){var t=e;if("string"==typeof t&&void 0!==h.levels[t.toUpperCase()]&&(t=h.levels[t.toUpperCase()]),"number"==typeof t&&t>=0&&t<=h.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),h.name=e,h.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},h.methodFactory=o||f,h.getLevel=function(){return null!=i?i:null!=r?r:a},h.setLevel=function(e,t){return i=u(e),!1!==t&&m(i),c.call(h)},h.setDefaultLevel=function(e){r=u(e),d()||h.setLevel(e,!1)},h.resetLevel=function(){i=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){}}}(),c.call(h)},h.enableAll=function(e){h.setLevel(h.levels.TRACE,e)},h.disableAll=function(e){h.setLevel(h.levels.SILENT,e)},h.rebuild=function(){if(s!==h&&(a=u(s.getLevel())),c.call(h),s===h)for(var e in l)l[e].rebuild()},a=u(s?s.getLevel():"WARN");var p=d();null!=p&&(i=u(p)),c.call(h)}(s=new y).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=l[e];return t||(t=l[e]=new y(e,s.methodFactory)),t};var m=typeof window!==t?window.log:void 0;return s.noConflict=function(){return typeof window!==t&&window.log===s&&(window.log=m),s},s.getLoggers=function(){return l},s.default=s,s}))}(t);const n=t.exports,o=(e,t)=>o=>o(e,t),r=(e,t)=>o=>o(e,t,{append:!1}),i=new Map,s=[],f=new Map,l={A11yUi:{CSS_STYLE_CACHE:i,HYDRATED_HISTORY:s,STYLING_TASK_QUEUE:f,Themes:{}}};let c=!0,a=!1;const u=/^[a-z][a-z0-9]{1,}(-[a-z0-9]+)?$/,d=e=>"string"==typeof e&&u.test(e),y=e=>{if(!1===d(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]+)?$/`)},p=(e,t,o,n)=>h(e,t,o,n),h=(e,t,o,s)=>{(s=s??{}).append=s.append??!1,y(e),!0===c&&!1===a&&(a=!0,n.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 l.A11yUi.Themes[e]||null===l.A11yUi.Themes[e])&&(l.A11yUi.Themes[e]={}),s.append&&"string"==typeof l.A11yUi.Themes[e][t]?l.A11yUi.Themes[e][t]+=o:l.A11yUi.Themes[e][t]=o},w=(e,t,o,n)=>m(e,t,o,n),m=(e,t,o,n)=>(y(e),"object"==typeof t&&null!==t&&Object.getOwnPropertyNames(t).forEach((l=>{const s=t[l],a=l.toLowerCase(),r="function"!=typeof n?.transformTagName||["GLOBAL","PROPERTIES"].includes(l)?l:n.transformTagName(a);"string"==typeof s&&s.length>0&&h(e,r.toUpperCase(),s,o)})),e),b=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 b(t)}}return null},g=(e={})=>"false"!==e.themeEncroachCss&&"true"!==e.themeReset&&{mode:"after"===e.themeEncroachCssMode||"before"===e.themeEncroachCssMode?e.themeEncroachCssMode:"before"},T=()=>"object"==typeof l.A11yUi&&null!==l.A11yUi&&"object"==typeof l.A11yUi.Theme&&null!==l.A11yUi.Theme&&"boolean"==typeof l.A11yUi.Theme.cache&&"object"==typeof l.A11yUi.Theme.encroachCss&&null!==l.A11yUi.Theme.encroachCss&&"string"==typeof l.A11yUi.Theme.encroachCss.mode&&"string"==typeof l.A11yUi.Theme.name,v=()=>!("object"==typeof l.A11yUi&&null!==l.A11yUi&&"object"==typeof l.A11yUi.Theme&&null!==l.A11yUi.Theme&&"default"===l.A11yUi.Theme.name),E=e=>{if(T())return l.A11yUi.Theme;{const t={cache:!0,encroachCss:g(),loglevel:"silent",mode:"csr",name:null},o=b(e);return o instanceof HTMLElement&&(t.cache="false"!==o.dataset.themeCache,t.encroachCss=g(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}},S=(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}),A=(e,t)=>{!1===T()&&v()&&"object"==typeof t&&null!==t&&("fixed"===(t=S(e,t)).detect?(null===t.name&&"string"==typeof e&&(t.name=e),e===t.name&&(l.A11yUi.Theme=t,n.info(`[Theming] Theme "${e}" was set as default theme.`))):a||(a=!0,n.warn("[Theming] The presetting of theme options is only relevant by using 'fixed' detection mode.")))};let R=!1;const j=(e,t,o={})=>{!1===R&&(R=!0,c=!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?A(e(((e,t,n)=>m(e,t,n,o))),{cache:o.theme?.cache,detect:o.theme?.detect,encroachCss:o.theme?.encroachCss,mode:o.theme?.mode,name:o.theme?.name}):n.error("[Theming] An attempt was made to load an incompatible theme.")})),c=!0,"function"==typeof t?t=new Set([t]):Array.isArray(t)&&(t=new Set(t));const l=[];return t.forEach((e=>{const t=e();t instanceof Promise&&l.push(t)})),Promise.all(l)},L=new Set,C=/--[^;]+/g,O=/:/,M=(e,t)=>{let o=t.match(C);if(Array.isArray(o)){o=o.filter((e=>O.test(e)));const t=document.createElement("style");t.innerHTML=`.${e} {${o.join(";")}}`,document.querySelector("head")?.appendChild(t)}L.add(e)},D=(e,t)=>"object"==typeof l.A11yUi&&null!==l.A11yUi&&"object"==typeof l.A11yUi.Themes&&null!==l.A11yUi.Themes&&"object"==typeof l.A11yUi.Themes[e]&&null!==l.A11yUi.Themes[e]&&"string"==typeof l.A11yUi.Themes[e][t]?l.A11yUi.Themes[e][t].replace(/\r?\n/g,""):"",I=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)}},k=(e,t)=>{try{if("ssr"===l.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)}))}},H=(e,t,o)=>{if(!1!==o){const n=[...Array.from(e.childNodes).filter((e=>e instanceof HTMLStyleElement&&"STYLE"===e.tagName))];let l;try{l=[...Array.from(e.adoptedStyleSheets)]}catch{l=[]}"before"===o?.mode?(n.reverse().forEach((e=>t.unshift(e.innerHTML))),l.reverse().forEach((e=>t.unshift(Array.from(e.cssRules).map((e=>e.cssText)).join(""))))):"after"===o?.mode&&(n.forEach((e=>t.push(e.innerHTML))),l.forEach((e=>t.push(Array.from(e.cssRules).map((e=>e.cssText)).join("")))))}},$=(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(l.A11yUi.CSS_STYLE_CACHE.get(n)?.has(e.tagName))U(e,s,l.A11yUi.CSS_STYLE_CACHE.get(n)?.get(e.tagName),o);else{const a=D(n,"PROPERTIES"),r=D(n,"GLOBAL"),i=D(n,e.tagName);!1===L.has(n)&&M(n,r);const c=[a,r,i];H(s,c,t.encroachCss),"debug"===t.loglevel&&console.log(e.tagName,c),!0===t.cache&&(!1===l.A11yUi.CSS_STYLE_CACHE.has(n)&&l.A11yUi.CSS_STYLE_CACHE.set(n,new Map),l.A11yUi.CSS_STYLE_CACHE.get(n)?.set(e.tagName,c)),U(e,s,c,o)}},U=(e,t,o,n)=>{I(t),k(t,o),e.style.display=n},P=e=>{"debug"===e.loglevel&&l.A11yUi.HYDRATED_HISTORY.push({timestamp:Date.now(),numberOfTasks:l.A11yUi.STYLING_TASK_QUEUE.size})},Y=(e,t)=>{l.A11yUi.STYLING_TASK_QUEUE.set(e,{styleDisplay:e.style.display?`${e.style.display}`:null,themeDetails:t})},x=(e,t)=>{Y(e,t),P(t)},z=e=>{l.A11yUi.STYLING_TASK_QUEUE.delete(e)},N=(e,t)=>{z(e),P(t)},F=e=>{const t=setTimeout((()=>{if(clearTimeout(t),l.A11yUi.STYLING_TASK_QUEUE.has(e)&&e.classList.contains("hydrated")){const{styleDisplay:t,themeDetails:o}=l.A11yUi.STYLING_TASK_QUEUE.get(e);$(e,o,t),N(e,o)}else F(e)}),25)},_=e=>{for(const t of e)if(l.A11yUi.STYLING_TASK_QUEUE.has(t.target)&&t.target.classList.contains("hydrated")){const{styleDisplay:e,themeDetails:o}=l.A11yUi.STYLING_TASK_QUEUE.get(t.target);$(t.target,o,e),N(t.target,o)}},G={attributes:!0,attributeFilter:["class"],childList:!1,subtree:!1};let B;try{B=new MutationObserver(_)}catch{B=null}const W=(e,t)=>{t={...l.A11yUi.Theme,...t},x(e,t),B?B.observe(e,G):F(e),e.style.display="none"};class J{constructor(e,t,n){this.createTheme=(e,t)=>r(e,t),this.createTranslation=(e,t)=>o(e,t),this.Prefix=e,this.Key=Object.getOwnPropertyNames(t),this.Tag=Object.getOwnPropertyNames(n)}}export{j as F,w as P,E as b,D as f,p as k,W as n,J as r};