@coderundebug/ui-web
Version:
A collection of UI web components that can be used in any web project.
2 lines • 1.21 kB
JavaScript
/* By Stephen Paul Hassall (web: https://coderundebug.com) */
import{UiTools as t}from"./ui-tools.js";export default class e extends HTMLElement{static t=new Map;static get CSS(){return" :host{display:block;padding:0;margin:0;font-size:var(--ui-font-size-normal);color:var(--ui-foreground);background-color:var(--ui-background);--ui-icon-primary-color:var(--ui-foreground);}"}constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML="<slot></slot>"}attributeChangedCallback(t,e,i){"src"===t&&this.i(i)}static get observedAttributes(){return["src"]}async i(t){if(!1===e.t.has(t)){const i=await fetch(t),o=await i.text(),s=new CSSStyleSheet;await s.replace(o),e.t.set(t,s)}e.o||(e.o=new CSSStyleSheet,await e.o.replace(e.CSS));const i=e.t.get(t);this.shadowRoot.adoptedStyleSheets=[e.o,i]}static switchPageTheme(t){const e=document.head.querySelector("link[ui-theme]");if(t||(window.localStorage.removeItem("ui-theme"),e&&e.remove()),t){window.localStorage.setItem("ui-theme",t);let i=document.createElement("link");i.setAttribute("ui-theme",""),i.rel="stylesheet",i.type="text/css",i.href=t,document.head.appendChild(i),i.onload=()=>{e&&e.remove()}}}}customElements.define("ui-theme",e);