diff --git a/src/common/element.js b/src/common/element.js index f0c1b823..e5c44087 100644 --- a/src/common/element.js +++ b/src/common/element.js @@ -6,14 +6,14 @@ import { effect, signal } from "@common/signal.js"; import { rpc, workerLink, workerProxy, workerTunnel } from "./worker.js"; import { BrowserPostMessageIo } from "./worker/rpc.js"; -export { keyed } from "lit-html/directives/keyed.js"; - /** * @import {BroadcastingStatus, ProvisionedWorker, ProvisionedWorkers, WorkerOpts} from "./element.d.ts" * @import {ProxiedActions, Tunnel} from "./worker.d.ts"; * @import {Signal} from "./signal.d.ts" */ +export const DEFAULT_GROUP = "default"; + /** * Base for custom elements, provides some utility functionality * around rendering and managing signals. @@ -25,7 +25,7 @@ export class DiffuseElement extends HTMLElement { constructor() { super(); - this.group = this.getAttribute("group") ?? "default"; + this.group = this.getAttribute("group") ?? DEFAULT_GROUP; this.worker = this.worker.bind(this); this.workerLink = this.workerLink.bind(this); diff --git a/src/components/engine/audio/element.js b/src/components/engine/audio/element.js index 2780b992..642f63e2 100644 --- a/src/components/engine/audio/element.js +++ b/src/components/engine/audio/element.js @@ -1,4 +1,6 @@ -import { BroadcastableDiffuseElement, keyed } from "@common/element.js"; +import { keyed } from "lit-html/directives/keyed.js"; + +import { BroadcastableDiffuseElement } from "@common/element.js"; import { computed, signal } from "@common/signal.js"; /** diff --git a/src/components/orchestrator/queue-tracks/element.js b/src/components/orchestrator/queue-tracks/element.js index b15edfe1..428f7196 100644 --- a/src/components/orchestrator/queue-tracks/element.js +++ b/src/components/orchestrator/queue-tracks/element.js @@ -28,7 +28,13 @@ class QueueTracksOrchestrator extends BroadcastableDiffuseElement { constructor() { super(); - this.#proxy = this.workerProxy(); + this.#proxy = this.workerProxy({ + forceNew: { + dependencies: { + input: true, + }, + }, + }); } // LIFECYCLE diff --git a/src/themes/blur/artwork-controller/element.css b/src/themes/blur/artwork-controller/element.css index 86406b27..018c00d2 100644 --- a/src/themes/blur/artwork-controller/element.css +++ b/src/themes/blur/artwork-controller/element.css @@ -1,5 +1,5 @@ :host { - --transition-durition: 500ms; + --transition-durition: 750ms; } main { @@ -47,8 +47,9 @@ main { left: var(--space-xs); letter-spacing: var(--tracking-wide); line-height: 1; - padding: 7px 6px 6px; + padding: 8px 6px; position: absolute; + text-box: trim-both cap alphabetic; text-transform: uppercase; top: var(--space-xs); transition: diff --git a/src/themes/blur/artwork-controller/element.js b/src/themes/blur/artwork-controller/element.js index ee58b460..84195102 100644 --- a/src/themes/blur/artwork-controller/element.js +++ b/src/themes/blur/artwork-controller/element.js @@ -3,18 +3,22 @@ import { Temporal } from "@js-temporal/polyfill"; import { xxh32r } from "xxh32/dist/raw.js"; import { debounce } from "throttle-debounce"; +import { cache } from "lit-html/directives/cache.js"; +import { guard } from "lit-html/directives/guard.js"; +import { keyed } from "lit-html/directives/keyed.js"; + import { + DEFAULT_GROUP, DiffuseElement, - keyed, query, whenElementsDefined, } from "@common/element.js"; + import { trackArtworkCacheId } from "@common/index.js"; -import { computed, signal } from "@common/signal.js"; +import { computed, signal, untracked } from "@common/signal.js"; /** * @import {RenderArg} from "@common/element.d.ts" - * @import {Track} from "@definitions/types.d.ts" * * @import {InputElement} from "@components/input/types.d.ts" * @import {Artwork} from "@components/processor/artwork/types.d.ts" @@ -46,7 +50,14 @@ class ArtworkController extends DiffuseElement { // SIGNALS - #artwork = signal(/** @type {Artwork[]} */ ([]), { eager: true }); + #artwork = signal( + /** @type {{ current: Artwork | null; previous: Artwork | null }} */ ({ + current: null, + previous: null, + }), + { eager: true }, + ); + #artworkColor = signal(/** @type {string | undefined} */ (undefined)); #artworkLightMode = signal(false); #duration = signal("0:00"); @@ -105,7 +116,8 @@ class ArtworkController extends DiffuseElement { ); this.effect(() => { - debouncedChangeArtwork(queue.now()); + const _trigger = queue.now(); + debouncedChangeArtwork(); }); this.effect(() => this.#formatTimestamps()); @@ -146,12 +158,15 @@ class ArtworkController extends DiffuseElement { } else controller.classList.remove("controller__inner--light-mode"); } - /** - * @param {Track | null} track - */ - async #setArtwork(track) { + /** */ + async #setArtwork() { + const track = this.$queue.value?.now(); + const currArtwork = untracked(this.#artwork.get); + if (!track) { - this.#artwork.value = []; + if (currArtwork.current) { + this.#artwork.value = { current: null, previous: currArtwork.current }; + } return; } @@ -184,9 +199,23 @@ class ArtworkController extends DiffuseElement { }, }; + if (this.$queue.value?.now()?.id !== track.id) { + return; + } + const art = await this.$artwork.value?.artwork(request) ?? []; - const currCacheId = track ? await trackArtworkCacheId(track) : undefined; - if (cacheId === currCacheId) this.#artwork.set(art); + + const currTrack = this.$queue.value?.now(); + const currCacheId = currTrack + ? await trackArtworkCacheId(currTrack) + : undefined; + + if (cacheId === currCacheId) { + this.#artwork.set({ + previous: currArtwork.current, + current: art[0] ?? null, + }); + } } //////////////////////////////////////////// @@ -317,7 +346,20 @@ class ArtworkController extends DiffuseElement { const activeQueueItem = this.$queue.value?.now(); // Artwork - const artwork = this.#artwork.value.map((art) => { + const artworkArr = [ + { key: "previous", value: this.#artwork.value.previous }, + { key: "current", value: this.#artwork.value.current }, + ]; + + const artwork = artworkArr.map(({ key, value }) => { + const art = value; + + if (art === null) { + return html` + + `; + } + const hash = xxh32r(art.bytes).toString(); const blob = new Blob( [/** @type {ArrayBuffer} */ (art.bytes.buffer)], @@ -326,12 +368,18 @@ class ArtworkController extends DiffuseElement { const url = URL.createObjectURL(blob); - return keyed( - hash, - html` - - `, - ); + return guard([hash], () => + keyed( + hash, + html` + + `, + )); }); return html` @@ -343,8 +391,9 @@ class ArtworkController extends DiffuseElement {
-