forked from
tokono.ma/diffuse
A music player that connects to your cloud/distributed storage.
1import { defineElement, DiffuseElement } from "~/common/element.js";
2
3/**
4 * @import {ProxiedActions, Tunnel} from "~/common/worker.d.ts"
5 * @import {InputElement} from "~/components/input/types.d.ts"
6 * @import {Actions} from "./types.d.ts"
7 */
8
9/**
10 * @typedef {{ element: InputElement, tunnel: Tunnel, worker: Worker | SharedWorker }} Input
11 */
12
13////////////////////////////////////////////
14// ELEMENT
15////////////////////////////////////////////
16
17/**
18 * @implements {ProxiedActions<Actions>}
19 */
20class InputConfigurator extends DiffuseElement {
21 static NAME = "diffuse/configurator/input";
22 static WORKER_URL = "components/configurator/input/worker.js";
23
24 constructor() {
25 super();
26
27 /** @type {ProxiedActions<Actions>} */
28 const proxy = this.workerProxy();
29
30 this.artwork = proxy.artwork;
31 this.consult = proxy.consult;
32 this.detach = proxy.detach;
33 this.groupConsult = proxy.groupConsult;
34 this.list = proxy.list;
35 this.resolve = proxy.resolve;
36
37 this.cache = proxy.cache;
38 this.cacheBlob = proxy.cacheBlob;
39 this.listCached = proxy.listCached;
40 this.removeFromCache = proxy.removeFromCache;
41 }
42
43 // WORKERS
44
45 /**
46 * @override
47 */
48 dependencies() {
49 return this.inputs();
50 }
51
52 inputs() {
53 return Object.fromEntries(
54 Array.from(this.children).map((element) => {
55 const input = /** @type {InputElement} */ (element);
56 return [input.SCHEME, input];
57 }),
58 );
59 }
60}
61
62export default InputConfigurator;
63
64////////////////////////////////////////////
65// REGISTER
66////////////////////////////////////////////
67
68export const CLASS = InputConfigurator;
69export const NAME = "dc-input";
70
71defineElement(NAME, CLASS);