UNPKG

@ne1410s/cust-elems

Version:

ES Custom Elements base functionality

38 lines (33 loc) 1.28 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ne_cust_elems = {})); })(this, (function (exports) { 'use strict'; 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; }));