From ef36d50d7858a56cbc08bfb4f272bab9476bb977 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 16 Apr 2025 17:19:15 +0200 Subject: log bins --- src/log.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/log.ts b/src/log.ts index 6f8c538..3fd65fc 100644 --- a/src/log.ts +++ b/src/log.ts @@ -7,6 +7,7 @@ import { e } from "./element.ts" export class Logger { public element: HTMLElement = e("div", { class: "jsh-log" }) + public bins: Map = new Map() constructor( private map_fn: (value: T) => HTMLElement = e => { if (e instanceof HTMLElement) return e; @@ -26,23 +27,33 @@ export class Logger { 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) } } -- cgit v1.2.3-70-g09d2