diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-16 17:19:15 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-16 17:19:15 +0200 |
commit | ef36d50d7858a56cbc08bfb4f272bab9476bb977 (patch) | |
tree | 317e5b46d303ff34d50a8db4c8f3000092450871 | |
parent | b2bcdcc99e42015085b4d0d63e7c94b2d4f84e24 (diff) | |
download | jshelper-ef36d50d7858a56cbc08bfb4f272bab9476bb977.tar jshelper-ef36d50d7858a56cbc08bfb4f272bab9476bb977.tar.bz2 jshelper-ef36d50d7858a56cbc08bfb4f272bab9476bb977.tar.zst |
log bins
-rw-r--r-- | src/log.ts | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -7,6 +7,7 @@ import { e } from "./element.ts" export class Logger<T = HTMLElement> { public element: HTMLElement = e("div", { class: "jsh-log" }) + public bins: Map<string, HTMLElement> = new Map() constructor( private map_fn: (value: T) => HTMLElement = e => { if (e instanceof HTMLElement) return e; @@ -26,23 +27,33 @@ export class Logger<T = HTMLElement> { return el } - log(value: T) { + log(value: T, bin?: string) { const el = this.add(value) + if (bin) { + const oel = this.bins.get(bin) + if (oel && oel.parentElement) this.element.removeChild(oel) + else el.classList.add("jsh-log-line-appear") + this.bins.set(bin, el) + } else { + el.classList.add("jsh-log-line-appear") + } el.classList.add("jsh-log-line", "jsh-log-line-timeout") setTimeout(() => { el.classList.add("jsh-log-line-disappear") setTimeout(() => { - this.element.removeChild(el) + if (el.parentElement) + this.element.removeChild(el) }, this.animation_duration) }, this.timeout + this.animation_duration) } log_persistent(value: T): () => void { const el = this.add(value) - el.classList.add("jsh-log-line", "jsh-log-line-persistent") + el.classList.add("jsh-log-line", "jsh-log-line-persistent", "jsh-log-line-appear") return () => { el.classList.add("jsh-log-line-disappear") setTimeout(() => { - this.element.removeChild(el) + if (el.parentElement) + this.element.removeChild(el) }, this.animation_duration) } } |