let e;const t=e=>`color: ${e}; font-weight: bold;`;function n({component:e,e:n,module:o,color:s}){if("boolean"==typeof __DEV__&&!__DEV__)return;const r=n.type;console.groupCollapsed(`${o}> %c${r}%c on %c${e}`,t(s||"#f012be"),"",t("#1a80cc")),console.log(n),n.target&&console.log(n.target),console.groupEnd()}const o={};function s(e,t){if(!e)throw new Error(t)}function r(t){s("string"==typeof t&&!!t,"Component name must be a non-empty string"),s(!o[t],`The component of the given name is already registered: ${t}`);const r=`${t}-💊`,l=[({el:e})=>{e.classList.add(t),e.classList.add(r),e.addEventListener(`__ummount__:${t}`,(()=>{e.classList.remove(r)}),{once:!0})}],a=[],m=e=>{if(!e.classList.contains(r)){const t=c(new CustomEvent("__mount__",{bubbles:!1}),e);l.map((e=>{e(t)})),a.map((e=>{e(t)}))}};m.sel=`.${t}:not(.${r})`,o[t]=m,(e=e||new Promise((e=>{const t=document,n=()=>{"complete"===t.readyState&&(e(),t.removeEventListener("readystatechange",n))};t.addEventListener("readystatechange",n),n()}))).then((()=>{i(t)}));const d=new Proxy((()=>{}),{set:(e,n,o)=>u(t,l,a,n,o),get:(e,o)=>"outside"===o?new Proxy({},{set:(e,o,r)=>(s("function"==typeof r,`Event handler must be a function, ${typeof r} (${r}) is given`),l.push((({el:e})=>{const s=o=>{e===o.target||e.contains(o.target)||(n({module:"outside",color:"#39cccc",e:o,component:t}),r(c(o,e)))};document.addEventListener(o,s),e.addEventListener(`__unmount__:${t}`,(()=>{document.removeEventListener(o,s)}),{once:!0})})),!0)}):null,apply(e,n,o){const r=o[0];return s("string"==typeof r,"Delegation selector must be a string. ${typeof selector} is given."),new Proxy({},{set:(e,n,o)=>u(t,l,a,n,o,r)})}}),_=e=>{l.push((({el:t})=>{t.classList.add(e)}))};return{on:d,is:_,sub:e=>_(`sub:${e}`),innerHTML:e=>{l.push((({el:t})=>{t.innerHTML=e}))}}}function c(e,t){return{e:e,el:t,query:e=>t.querySelector(e),queryAll:e=>t.querySelectorAll(e),pub:(e,t)=>{document.querySelectorAll(`.sub\\:${e}`).forEach((n=>{n.dispatchEvent(new CustomEvent(e,{bubbles:!1,detail:t}))}))},emit:(e,n)=>{t.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:n}))}}}function u(e,t,o,r,u,i){return s("function"==typeof u,`Event handler must be a function, ${typeof u} (${u}) is given`),"__mount__"===r?(o.push(u),!0):"__unmount__"===r?(t.push((({el:t})=>{t.addEventListener(`__unmount__:${e}`,(()=>{u(c(new CustomEvent("__unmount__"),t))}),{once:!0})})),!0):(t.push((({el:t})=>{const o=o=>{i&&![].some.call(t.querySelectorAll(i),(e=>e===o.target||e.contains(o.target)))||(n({module:"💊",color:"#e0407b",e:o,component:e}),u(c(o,t)))};t.addEventListener(`__unmount__:${e}`,(()=>{t.removeEventListener(r,o)}),{once:!0}),t.addEventListener(r,o)})),!0)}function i(e,t){let n;e?(!function(e){s("string"==typeof e,"The name should be a string"),s(!!o[e],`The component of the given name is not registered: ${e}`)}(e),n=[e]):n=Object.keys(o),n.map((e=>{[].map.call((t||document).querySelectorAll(o[e].sel),o[e])}))}function l(e,t){s(!!o[e],`The component of the given name is not registered: ${e}`),t.dispatchEvent(new CustomEvent(`__unmount__:${e}`))}export{r as component};export{i as mount};export{l as unmount};