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