-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
159 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,131 @@ | ||
var e,t="readystatechange";var n=e=>`color: ${e}; font-weight: bold;`,o="#f012be";function s({component:e,e:t,module:s,color:r}){if("boolean"==typeof __DEV__&&!__DEV__)return;const c=t.type;console.groupCollapsed(`${s}> %c${c}%c on %c${e}`,n(r||o),"",n("#1a80cc")),console.log(t),t.target&&console.log(t.target),console.groupEnd()}var r={};function c(e,t){if(!e)throw new Error(t)}function i(n,o){c("string"==typeof o&&!!o,"Component name must be a non-empty string"),c(!r[o],`The component of the given name is already registered: ${o}`);const i=`${o}-💊`,u=e=>{if(!e.classList.contains(i)){e.classList.add(o),e.classList.add(i),e.addEventListener(`__ummount__:${o}`,(()=>{e.classList.remove(i)}),{once:!0});const t=new Proxy((()=>{}),{set:(t,n,s)=>(a(o,e,n,s),!0),get:(t,n)=>"outside"===n?new Proxy({},{set(t,n,r){c("function"==typeof r,`Event handler must be a function, ${typeof r} (${r}) is given`);const i=t=>{e===t.target||e.contains(t.target)||(s({module:"outside",color:"#39cccc",e:t,component:o}),r(t))};return document.addEventListener(n,i),e.addEventListener(`__unmount__:${o}`,(()=>{document.removeEventListener(n,i)}),{once:!0}),!0}}):null,apply(t,n,s){const r=s[0];return c("string"==typeof r,"Delegation selector must be a string. ${typeof selector} is given."),new Proxy({},{set:(t,n,s)=>(a(o,e,n,s,r),!0)})}}),r=t=>e.classList.add(`sub:${t}`),l=n({el:e,on:t,pub:(e,t)=>{document.querySelectorAll(`.sub\\:${e}`).forEach((n=>{n.dispatchEvent(new CustomEvent(e,{bubbles:!1,detail:t}))}))},sub:r,query:t=>e.querySelector(t),queryAll:t=>e.querySelectorAll(t)});"string"==typeof l&&(e.innerHTML=l)}};u.sel=`.${o}:not(.${i})`,r[o]=u,(e=e||new Promise((e=>{const n=document,o=()=>{"complete"===n.readyState&&(e(),n.removeEventListener(t,o))};n.addEventListener(t,o),o()}))).then((()=>{l(o)}))}function a(e,t,n,o,r){c("function"==typeof o,`Event handler must be a function, ${typeof o} (${o}) is given`);const i=n=>{r&&![].some.call(t.querySelectorAll(r),(e=>e===n.target||e.contains(n.target)))||(s({module:"💊",color:"#e0407b",e:n,component:e}),o(n))};t.addEventListener(`__unmount__:${e}`,(()=>{t.removeEventListener(n,i)}),{once:!0}),t.addEventListener(n,i)}function l(e,t){let n;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),n=[e]):n=Object.keys(r),n.map((e=>{[].map.call((t||document).querySelectorAll(r[e].sel),r[e])}))}function u(e,t){c(!!r[e],`The component of the given name is not registered: ${e}`),t.dispatchEvent(new CustomEvent(`__unmount__:${e}`))}export{l as mount,i as register,u as unmount}; | ||
/*! Cell v0.1.0 | Copyright 2024 Yoshiya Hinosawa and Capsule contributors | MIT license */ | ||
var e, t = "readystatechange"; | ||
var n = (e) => `color: ${e}; font-weight: bold;`, o = "#f012be"; | ||
function s({ component: e, e: t, module: s, color: r }) { | ||
if ("boolean" == typeof __DEV__ && !__DEV__) return; | ||
const c = t.type; | ||
console.groupCollapsed( | ||
`${s}> %c${c}%c on %c${e}`, | ||
n(r || o), | ||
"", | ||
n("#1a80cc"), | ||
), | ||
console.log(t), | ||
t.target && console.log(t.target), | ||
console.groupEnd(); | ||
} | ||
var r = {}; | ||
function c(e, t) { | ||
if (!e) throw new Error(t); | ||
} | ||
function i(n, o) { | ||
c("string" == typeof o && !!o, "Component name must be a non-empty string"), | ||
c(!r[o], `The component of the given name is already registered: ${o}`); | ||
const i = `${o}-💊`, | ||
u = (e) => { | ||
if (!e.classList.contains(i)) { | ||
e.classList.add(o), | ||
e.classList.add(i), | ||
e.addEventListener(`__ummount__:${o}`, () => { | ||
e.classList.remove(i); | ||
}, { once: !0 }); | ||
const t = new Proxy(() => {}, { | ||
set: (t, n, s) => (a(o, e, n, s), !0), | ||
get: (t, n) => | ||
"outside" === n | ||
? new Proxy({}, { | ||
set(t, n, r) { | ||
c( | ||
"function" == typeof r, | ||
`Event handler must be a function, ${typeof r} (${r}) is given`, | ||
); | ||
const i = (t) => { | ||
e === t.target || e.contains(t.target) || | ||
(s({ | ||
module: "outside", | ||
color: "#39cccc", | ||
e: t, | ||
component: o, | ||
}), | ||
r(t)); | ||
}; | ||
return document.addEventListener(n, i), | ||
e.addEventListener(`__unmount__:${o}`, () => { | ||
document.removeEventListener(n, i); | ||
}, { once: !0 }), | ||
!0; | ||
}, | ||
}) | ||
: null, | ||
apply(t, n, s) { | ||
const r = s[0]; | ||
return c( | ||
"string" == typeof r, | ||
"Delegation selector must be a string. ${typeof selector} is given.", | ||
), | ||
new Proxy({}, { set: (t, n, s) => (a(o, e, n, s, r), !0) }); | ||
}, | ||
}), | ||
r = (t) => e.classList.add(`sub:${t}`), | ||
l = n({ | ||
el: e, | ||
on: t, | ||
pub: (e, t) => { | ||
document.querySelectorAll(`.sub\\:${e}`).forEach((n) => { | ||
n.dispatchEvent(new CustomEvent(e, { bubbles: !1, detail: t })); | ||
}); | ||
}, | ||
sub: r, | ||
query: (t) => e.querySelector(t), | ||
queryAll: (t) => e.querySelectorAll(t), | ||
}); | ||
"string" == typeof l && (e.innerHTML = l); | ||
} | ||
}; | ||
u.sel = `.${o}:not(.${i})`, | ||
r[o] = u, | ||
(e = e || new Promise((e) => { | ||
const n = document, | ||
o = () => { | ||
"complete" === n.readyState && (e(), n.removeEventListener(t, o)); | ||
}; | ||
n.addEventListener(t, o), o(); | ||
})).then(() => { | ||
l(o); | ||
}); | ||
} | ||
function a(e, t, n, o, r) { | ||
c( | ||
"function" == typeof o, | ||
`Event handler must be a function, ${typeof o} (${o}) is given`, | ||
); | ||
const i = (n) => { | ||
r && | ||
![].some.call( | ||
t.querySelectorAll(r), | ||
(e) => e === n.target || e.contains(n.target), | ||
) || | ||
(s({ module: "💊", color: "#e0407b", e: n, component: e }), o(n)); | ||
}; | ||
t.addEventListener(`__unmount__:${e}`, () => { | ||
t.removeEventListener(n, i); | ||
}, { once: !0 }), t.addEventListener(n, i); | ||
} | ||
function l(e, t) { | ||
let n; | ||
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), | ||
n = [e]) | ||
: n = Object.keys(r), | ||
n.map((e) => { | ||
[].map.call((t || document).querySelectorAll(r[e].sel), r[e]); | ||
}); | ||
} | ||
function u(e, t) { | ||
c(!!r[e], `The component of the given name is not registered: ${e}`), | ||
t.dispatchEvent(new CustomEvent(`__unmount__:${e}`)); | ||
} | ||
export { i as register, l as mount, u as unmount }; | ||
/*! Cell v0.1.0 | Copyright 2024 Yoshiya Hinosawa and Capsule contributors | MIT license */ |