Skip to content

Commit

Permalink
chore: exclude dist from formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Jun 18, 2024
1 parent d0d1c3d commit dd716b0
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 31 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"compilerOptions": {
"lib": ["deno.ns", "deno.unstable", "dom", "esnext"]
},
"exclude": ["node", "dist.js", "dist.min.js"],
"exclude": ["docs/dist.js", "docs/dist.min.js"],
"tasks": {
"test": "deno test -A",
"cov": "deno test --coverage -A",
Expand Down
55 changes: 27 additions & 28 deletions docs/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ function logEvent({
component,
e,
module,
color
color,
}) {
if (typeof __DEV__ === "boolean" && !__DEV__)
if (typeof __DEV__ === "boolean" && !__DEV__) {
return;
}
const event = e.type;
console.groupCollapsed(
`${module}> %c${event}%c on %c${component}`,
boldColor(color || defaultEventColor),
"",
boldColor("#1a80cc")
boldColor("#1a80cc"),
);
console.log(e);
if (e.target) {
Expand All @@ -49,17 +50,17 @@ function assertComponentNameIsValid(name) {
assert(typeof name === "string", "The name should be a string");
assert(
!!registry[name],
`The component of the given name is not registered: ${name}`
`The component of the given name is not registered: ${name}`,
);
}
function register(component, name) {
assert(
typeof name === "string" && !!name,
"Component name must be a non-empty string"
"Component name must be a non-empty string",
);
assert(
!registry[name],
`The component of the given name is already registered: ${name}`
`The component of the given name is already registered: ${name}`,
);
const initClass = `${name}-\u{1F48A}`;
const initializer = (el) => {
Expand All @@ -82,15 +83,15 @@ function register(component, name) {
set(_2, type, value) {
assert(
typeof value === "function",
`Event handler must be a function, ${typeof value} (${value}) is given`
`Event handler must be a function, ${typeof value} (${value}) is given`,
);
const listener = (e) => {
if (el !== e.target && !el.contains(e.target)) {
logEvent({
module: "outside",
color: "#39cccc",
e,
component: name
component: name,
});
value(e);
}
Expand All @@ -100,7 +101,7 @@ function register(component, name) {
document.removeEventListener(type, listener);
}, { once: true });
return true;
}
},
});
}
return null;
Expand All @@ -110,7 +111,7 @@ function register(component, name) {
const selector = args[0];
assert(
typeof selector === "string",
"Delegation selector must be a string. ${typeof selector} is given."
"Delegation selector must be a string. ${typeof selector} is given.",
);
return new Proxy({}, {
set(_, type, value) {
Expand All @@ -120,17 +121,17 @@ function register(component, name) {
type,
// deno-lint-ignore no-explicit-any
value,
selector
selector,
);
return true;
}
},
});
}
},
});
const pub = (type, data) => {
document.querySelectorAll(`.sub\\:${type}`).forEach((el2) => {
el2.dispatchEvent(
new CustomEvent(type, { bubbles: false, detail: data })
new CustomEvent(type, { bubbles: false, detail: data }),
);
});
};
Expand All @@ -141,7 +142,7 @@ function register(component, name) {
pub,
sub,
query: (s) => el.querySelector(s),
queryAll: (s) => el.querySelectorAll(s)
queryAll: (s) => el.querySelectorAll(s),
};
const html = component(context);
if (typeof html === "string") {
Expand All @@ -158,18 +159,20 @@ function register(component, name) {
function addEventListener(name, el, type, handler, selector) {
assert(
typeof handler === "function",
`Event handler must be a function, ${typeof handler} (${handler}) is given`
`Event handler must be a function, ${typeof handler} (${handler}) is given`,
);
const listener = (e) => {
if (!selector || [].some.call(
el.querySelectorAll(selector),
(node) => node === e.target || node.contains(e.target)
)) {
if (
!selector || [].some.call(
el.querySelectorAll(selector),
(node) => node === e.target || node.contains(e.target),
)
) {
logEvent({
module: "\u{1F48A}",
color: "#e0407b",
e,
component: name
component: name,
});
handler(e);
}
Expand All @@ -190,20 +193,16 @@ function mount(name, el) {
classNames.map((className) => {
[].map.call(
(el || document).querySelectorAll(registry[className].sel),
registry[className]
registry[className],
);
});
}
function unmount(name, el) {
assert(
!!registry[name],
`The component of the given name is not registered: ${name}`
`The component of the given name is not registered: ${name}`,
);
el.dispatchEvent(new CustomEvent(`__unmount__:${name}`));
}
export {
mount,
register,
unmount
};
export { mount, register, unmount };
/*! Cell v0.1.0 | Copyright 2024 Yoshiya Hinosawa and Capsule contributors | MIT license */
133 changes: 131 additions & 2 deletions docs/dist.min.js
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 */

0 comments on commit dd716b0

Please sign in to comment.