tangled
alpha
login
or
join now
vielle.dev
/
site
0
fork
atom
Personal Site
0
fork
atom
overview
issues
pulls
pipelines
Random formatting change idk man
vielle.dev
7 months ago
910a30cd
829a42e3
verified
This commit was signed with the committer's
known signature
.
vielle.dev
SSH Key Fingerprint:
SHA256:/4bvxqoEh9iMdjAPgcgAgXKZZQTROL3ULiPt6nH9RSs=
+36
-36
1 changed file
expand all
collapse all
unified
split
src
components
playing
NowPlaying.astro
+36
-36
src/components/playing/NowPlaying.astro
···
348
348
}
349
349
350
350
now-playing {
351
351
-
[slot="art"] {
351
351
+
& img {
352
352
mask-image: var(--small-box-mask-png);
353
353
mask-size: contain;
354
354
}
355
355
-
356
356
-
a {
355
355
+
& a {
357
356
color: black;
358
357
359
358
&:focus,
···
372
371
import { type nowPlaying, isNowPlaying } from "./spotify/client";
373
372
374
373
class HTMLNowPlayingElement extends HTMLElement {
375
375
-
internals = this.attachInternals();
374
374
+
internals = this.attachInternals();
376
375
377
377
-
elements = {
378
378
-
// typecast bc checked in constructor
379
379
-
title: this.querySelector("[slot=title]") as HTMLAnchorElement,
380
380
-
album: this.querySelector("[slot=album]") as HTMLSpanElement,
381
381
-
artists: this.querySelector("[slot=artists]") as HTMLSpanElement,
382
382
-
art: this.querySelector("[slot=art]") as HTMLImageElement,
383
383
-
} as const;
376
376
+
elements = {
377
377
+
// typecast bc checked in constructor
378
378
+
title: this.querySelector("[slot=title]") as HTMLAnchorElement,
379
379
+
album: this.querySelector("[slot=album]") as HTMLSpanElement,
380
380
+
artists: this.querySelector("[slot=artists]") as HTMLSpanElement,
381
381
+
art: this.querySelector("[slot=art]") as HTMLImageElement,
382
382
+
} as const;
384
383
385
385
-
constructor() {
386
386
-
super();
384
384
+
constructor() {
385
385
+
super();
387
386
388
388
-
if (!(this.elements.title instanceof HTMLAnchorElement))
389
389
-
throw new Error("[slot=title] not defined or wrong type");
387
387
+
if (!(this.elements.title instanceof HTMLAnchorElement))
388
388
+
throw new Error("[slot=title] not defined or wrong type");
390
389
391
391
-
if (!(this.elements.album instanceof HTMLSpanElement))
392
392
-
throw new Error("[slot=album] not defined or wrong type");
390
390
+
if (!(this.elements.album instanceof HTMLSpanElement))
391
391
+
throw new Error("[slot=album] not defined or wrong type");
393
392
394
394
-
if (!(this.elements.artists instanceof HTMLSpanElement))
395
395
-
throw new Error("[slot=artists] not defined or wrong type");
393
393
+
if (!(this.elements.artists instanceof HTMLSpanElement))
394
394
+
throw new Error("[slot=artists] not defined or wrong type");
396
395
397
397
-
if (!(this.elements.art instanceof HTMLImageElement))
398
398
-
throw new Error("[slot=art] not defined or wrong type");
399
399
-
}
396
396
+
if (!(this.elements.art instanceof HTMLImageElement))
397
397
+
throw new Error("[slot=art] not defined or wrong type");
398
398
+
}
400
399
401
401
-
updateMetadata(metadata: Exclude<nowPlaying, null>) {
402
402
-
this.elements.title.innerText = metadata.name;
403
403
-
this.elements.title.href = metadata.external_urls.spotify;
400
400
+
updateMetadata(metadata: Exclude<nowPlaying, null>) {
401
401
+
this.elements.title.innerText = metadata.name;
402
402
+
this.elements.title.href = metadata.external_urls.spotify;
404
403
405
405
-
this.elements.album.innerText = metadata.album.name;
404
404
+
this.elements.album.innerText = metadata.album.name;
406
405
407
407
-
this.elements.artists.innerText = "";
408
408
-
this.elements.artists.append(...metadata.artists.flatMap((artist, i) => {
406
406
+
this.elements.artists.innerText = "";
407
407
+
this.elements.artists.append(
408
408
+
...metadata.artists.flatMap((artist, i) => {
409
409
const a = document.createElement("a");
410
410
a.innerText = artist.name;
411
411
a.href = artist.external_urls.spotify;
412
412
return i === 0 ? a : [", ", a];
413
413
-
}));
413
413
+
}),
414
414
+
);
414
415
415
415
-
this.elements.art.src = metadata.album.images[0].url
416
416
-
}
416
416
+
this.elements.art.src = metadata.album.images[0].url;
417
417
}
418
418
+
}
418
419
419
420
const nowPlayingEl = document.getElementById("now-playing");
420
421
if (!nowPlayingEl) throw new Error("Could not find #now-playing");
···
423
424
throw new Error("Could not find #now-playing img.art");
424
425
const nowPlayings = document.querySelectorAll("now-playing");
425
426
426
426
-
customElements.define(
427
427
-
"now-playing",
428
428
-
HTMLNowPlayingElement,
429
429
-
);
427
427
+
customElements.define("now-playing", HTMLNowPlayingElement);
430
428
431
429
const renderNowPlaying = (playing: Exclude<nowPlaying, null>) => {
432
430
art.src = playing.album.images[0].url;
433
433
-
nowPlayings.forEach(el => el instanceof HTMLNowPlayingElement && el.updateMetadata(playing))
431
431
+
nowPlayings.forEach(
432
432
+
(el) => el instanceof HTMLNowPlayingElement && el.updateMetadata(playing),
433
433
+
);
434
434
};
435
435
436
436
const renderSilent = () => {