UNPKG

@ne1410s/cust-elems

Version:

ES Custom Elements base functionality

27 lines (24 loc) 797 B
class CustomElementBase extends HTMLElement { constructor(css, html, mode = 'closed') { super(); this.root = this.attachShadow({ mode }); this.root.innerHTML = html; const style = document.createElement('style'); style.textContent = css; this.root.appendChild(style); } } function decode(b64) { const bIndex = (b64 + '').indexOf('base64,'); return bIndex === -1 ? b64 : window.atob(b64.substring(bIndex + 7)); } function reduceCss(cssIn) { return cssIn .replace(/\s+/g, ' ') .replace(/([,{}:;])\s/g, '$1') .replace(/\s([{])/g, '$1'); } function reduceHtml(htmlIn) { return htmlIn.replace(/\s+/g, ' ').replace(/(^|>)\s+(<|$)/g, '$1$2'); } export { CustomElementBase, decode, reduceCss, reduceHtml };