basecoat-css
Version:
Tailwind CSS for Basecoat components
1 lines • 1.03 kB
JavaScript
(()=>{const e={};let t=null;const o=()=>{Object.entries(e).forEach((([e,{selector:t,init:o}])=>{document.querySelectorAll(t).forEach(o)}))},r=t=>{t.nodeType===Node.ELEMENT_NODE&&Object.entries(e).forEach((([e,{selector:o,init:r}])=>{t.matches(o)&&r(t),t.querySelectorAll(o).forEach(r)}))},n=()=>{t||(t=new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach(r)}))})),t.observe(document.body,{childList:!0,subtree:!0}))};window.basecoat={register:(t,o,r)=>{e[t]={selector:o,init:r}},init:t=>{const o=e[t];if(!o)return void console.warn(`Component '${t}' not found in registry`);const r=`data-${t}-initialized`;document.querySelectorAll(`[${r}]`).forEach((e=>{e.removeAttribute(r)})),document.querySelectorAll(o.selector).forEach(o.init)},initAll:()=>{Object.entries(e).forEach((([e,{selector:t}])=>{const o=`data-${e}-initialized`;document.querySelectorAll(`[${o}]`).forEach((e=>{e.removeAttribute(o)}))})),o()},start:n,stop:()=>{t&&(t.disconnect(),t=null)}},document.addEventListener("DOMContentLoaded",(()=>{o(),n()}))})();