@ne1410s/cust-elems
Version:
ES Custom Elements base functionality
32 lines (28 loc) • 887 B
JavaScript
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');
}
exports.CustomElementBase = CustomElementBase;
exports.decode = decode;
exports.reduceCss = reduceCss;
exports.reduceHtml = reduceHtml;
;