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"],s={},a=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 i(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function l(){for(var o=this.getLevel(),s=0;s<n.length;s++){var a=n[s];this[a]=s<o?e:this.methodFactory(a,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&&(l.call(this),this[e].apply(this,arguments))}}function h(n,s,a){return function(n){return"debug"===n&&(n="log"),typeof console!==t&&("trace"===n&&o?i: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,i,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),s=o.indexOf(n+"=");-1!==s&&(e=/^([^;]+)/.exec(o.slice(s+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!=i?i: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),l.call(f)},f.setDefaultLevel=function(e){i=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){}}}(),l.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(a!==f&&(r=d(a.getLevel())),l.call(f),a===f)for(var e in s)s[e].rebuild()},r=d(a?a.getLevel():"WARN");var u=m();null!=u&&(c=d(u)),l.call(f)}(a=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=s[e];return t||(t=s[e]=new f(e,a.methodFactory)),t};var y=typeof window!==t?window.log:void 0;return a.noConflict=function(){return typeof window!==t&&window.log===a&&(window.log=y),a},a.getLoggers=function(){return s},a.default=a,a},e.exports?e.exports=o():t.log=o()}(loglevel);const h=loglevel.exports,j=(e,t)=>o=>o(e,t),H=(e,t)=>o=>o(e,t,{append:!1}),M=new Map,Y=[],$=new Map,o={A11yUi:{CSS_STYLE_CACHE:M,HYDRATED_HISTORY:Y,STYLING_TASK_QUEUE:$,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),p=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]+)?$/`)},R=(e,t,o,n)=>u(e,t,o,n),u=(e,t,n,s)=>{(s=s??{}).append=s.append??!1,p(e),!0===T&&!1===y&&(y=!0,h.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 o.A11yUi.Themes[e]||null===o.A11yUi.Themes[e])&&(o.A11yUi.Themes[e]={}),s.append&&"string"==typeof o.A11yUi.Themes[e][t]?o.A11yUi.Themes[e][t]+=n:o.A11yUi.Themes[e][t]=n},P=(e,t,o,n)=>g(e,t,o,n),g=(e,t,o,n)=>(p(e),"object"==typeof t&&null!==t&&Object.getOwnPropertyNames(t).forEach((s=>{const a=t[s],r=s.toLowerCase(),i="function"!=typeof n?.transformTagName||["GLOBAL","PROPERTIES"].includes(s)?s:n.transformTagName(r);"string"==typeof a&&a.length>0&&u(e,i.toUpperCase(),a,o)})),e),A=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 A(t)}}return null},U=(e={})=>"false"!==e.themeEncroachCss&&"true"!==e.themeReset&&{mode:"after"===e.themeEncroachCssMode||"before"===e.themeEncroachCssMode?e.themeEncroachCssMode:"before"},E=()=>"object"==typeof o.A11yUi&&null!==o.A11yUi&&"object"==typeof o.A11yUi.Theme&&null!==o.A11yUi.Theme&&"boolean"==typeof o.A11yUi.Theme.cache&&"object"==typeof o.A11yUi.Theme.encroachCss&&null!==o.A11yUi.Theme.encroachCss&&"string"==typeof o.A11yUi.Theme.encroachCss.mode&&"string"==typeof o.A11yUi.Theme.name,k=()=>!("object"==typeof o.A11yUi&&null!==o.A11yUi&&"object"==typeof o.A11yUi.Theme&&null!==o.A11yUi.Theme&&"default"===o.A11yUi.Theme.name),S=e=>{if(E())return o.A11yUi.Theme;{const t={cache:!0,encroachCss:U(),loglevel:"silent",mode:"csr",name:null},o=A(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}),D=(e,t)=>{!1===E()&&k()&&"object"==typeof t&&null!==t&&("fixed"===(t=K(e,t)).detect?(null===t.name&&"string"==typeof e&&(t.name=e),e===t.name&&(o.A11yUi.Theme=t,h.info(`[Theming] Theme "${e}" was set as default theme.`))):y||(y=!0,h.warn("[Theming] The presetting of theme options is only relevant by using 'fixed' detection mode.")))};let b=!1;const B=(e,t,o={})=>{!1===b&&(b=!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?D(e(((e,t,n)=>g(e,t,n,o))),{cache:o.theme?.cache,detect:o.theme?.detect,encroachCss:o.theme?.encroachCss,mode:o.theme?.mode,name:o.theme?.name}):h.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)},C=new Set,F=/--[^;]+/g,V=/:/,q=(e,t)=>{let o=t.match(F);if(Array.isArray(o)){o=o.filter((e=>V.test(e)));const t=document.createElement("style");t.innerHTML=`.${e} {${o.join(";")}}`,document.querySelector("head")?.appendChild(t)}C.add(e)},f=(e,t)=>"object"==typeof o.A11yUi&&null!==o.A11yUi&&"object"==typeof o.A11yUi.Themes&&null!==o.A11yUi.Themes&&"object"==typeof o.A11yUi.Themes[e]&&null!==o.A11yUi.Themes[e]&&"string"==typeof o.A11yUi.Themes[e][t]?o.A11yUi.Themes[e][t].replace(/\r?\n/g,""):"",J=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)}},W=(e,t)=>{try{if("ssr"===o.A11yUi.Theme?.mode)throw new Error("SSR");const n=[];t.forEach((e=>{const t=new CSSStyleSheet;t.replaceSync(e),n.push(t)})),e.adoptedStyleSheets=n}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)}))}},X=(e,t,o)=>{if(!1!==o){const n=[...Array.from(e.childNodes).filter((e=>e instanceof HTMLStyleElement&&"STYLE"===e.tagName))];let s;try{s=[...Array.from(e.adoptedStyleSheets)]}catch{s=[]}"before"===o?.mode?(n.reverse().forEach((e=>t.unshift(e.innerHTML))),s.reverse().forEach((e=>t.unshift(Array.from(e.cssRules).map((e=>e.cssText)).join(""))))):"after"===o?.mode&&(n.forEach((e=>t.push(e.innerHTML))),s.forEach((e=>t.push(Array.from(e.cssRules).map((e=>e.cssText)).join("")))))}},w=(e,t,n)=>{const s=t.name||"default";let a;try{if(null===e.shadowRoot)throw new Error("ShadowRoot is null");a=e.shadowRoot}catch{a=e}if(o.A11yUi.CSS_STYLE_CACHE.get(s)?.has(e.tagName))L(e,a,o.A11yUi.CSS_STYLE_CACHE.get(s)?.get(e.tagName),n);else{const r=f(s,"PROPERTIES"),i=f(s,"GLOBAL"),l=f(s,e.tagName);!1===C.has(s)&&q(s,i);const c=[r,i,l];X(a,c,t.encroachCss),"debug"===t.loglevel&&console.log(e.tagName,c),!0===t.cache&&(!1===o.A11yUi.CSS_STYLE_CACHE.has(s)&&o.A11yUi.CSS_STYLE_CACHE.set(s,new Map),o.A11yUi.CSS_STYLE_CACHE.get(s)?.set(e.tagName,c)),L(e,a,c,n)}},L=(e,t,o,n)=>{J(t),W(t,o),e.style.visibility=n},v=e=>{"debug"===e.loglevel&&o.A11yUi.HYDRATED_HISTORY.push({timestamp:Date.now(),numberOfTasks:o.A11yUi.STYLING_TASK_QUEUE.size})},Z=(e,t)=>{o.A11yUi.STYLING_TASK_QUEUE.set(e,{styleVisibility:e.style.visibility?`${e.style.visibility}`:null,themeDetails:t})},ee=(e,t)=>{Z(e,t),v(t)},te=e=>{o.A11yUi.STYLING_TASK_QUEUE.delete(e)},_=(e,t)=>{te(e),v(t)},N=e=>{const t=setTimeout((()=>{if(clearTimeout(t),o.A11yUi.STYLING_TASK_QUEUE.has(e)&&e.classList.contains("hydrated")){const{styleVisibility:t,themeDetails:n}=o.A11yUi.STYLING_TASK_QUEUE.get(e);w(e,n,t),_(e,n)}else N(e)}),25)},se=e=>{for(const t of e)if(o.A11yUi.STYLING_TASK_QUEUE.has(t.target)&&t.target.classList.contains("hydrated")){const{styleVisibility:e,themeDetails:n}=o.A11yUi.STYLING_TASK_QUEUE.get(t.target);w(t.target,n,e),_(t.target,n)}},ae={attributes:!0,attributeFilter:["class"],childList:!1,subtree:!1};let d;try{d=new MutationObserver(se)}catch{d=null}const oe=(e,t)=>{t={...o.A11yUi.Theme,...t},ee(e,t),d?d.observe(e,ae):N(e),e.style.visibility="hidden"};class ne{Prefix;Key;Tag;createTheme=(e,t)=>H(e,t);createTranslation=(e,t)=>j(e,t);constructor(e,t,o){this.Prefix=e,this.Key=Object.getOwnPropertyNames(t),this.Tag=Object.getOwnPropertyNames(o)}}exports.B=B,exports.P=P,exports.R=R,exports.S=S,exports.f=f,exports.ne=ne,exports.oe=oe;