···22name: diffuse-facet
33description: Create an interface or feature facet for Diffuse
44user-invocable: true
55-version: 0.1.0
55+version: 0.2.0
66---
7788Create a Diffuse facet and produce the HTML ready to paste into the `create/` page.
···13131414- `docs/architecture.txt` — system overview, facet rules, foundation API
1515- `docs/elements.txt` — all available custom elements with code examples
1616+- `docs/foundation.js` — the foundation code mentioned throughout this document
1617- `example/index.html` — a representative interface facet to use as a reference
1718- Any specific definition you need (e.g. `docs/definitions/output/track.json` for the track schema)
1819- `docs/definitions/index.ts` — TypeScript types for all data structures
···85868687For a centered or full-screen layout (player, dialog, etc.) override `body` and `main` in the facet's `<style>` block directly.
87888888-### Foundation API quick reference
8989-9090-```js
9191-// Engines
9292-const audio = await foundation.engine.audio();
9393-const queue = await foundation.engine.queue();
9494-const repeatShuffle = await foundation.engine.repeatShuffle();
9595-9696-// Configurators
9797-const inputCfg = await foundation.configurator.input();
9898-const metadataCfg = await foundation.configurator.metadata();
9999-100100-// Orchestrators
101101-const output = await foundation.orchestrator.output();
102102-const sources = await foundation.orchestrator.sources();
103103-const controller = await foundation.orchestrator.controller();
104104-const queueAudio = await foundation.orchestrator.queueAudio();
105105-const mediaSession = await foundation.orchestrator.mediaSession();
106106-const processTracks = await foundation.orchestrator.processTracks({ disableWhenReady: false });
107107-const favourites = await foundation.orchestrator.favourites();
108108-const artwork = await foundation.orchestrator.artwork();
109109-const scopedTracks = await foundation.orchestrator.scopedTracks();
110110-const autoQueue = await foundation.orchestrator.autoQueue();
111111-```
112112-113113-Though make sure to check the mentioned foundation js file for the latest code.
114114-115115-Typical playback bootstrap:
8989+### Example foundation usage
1169011791```js
11892await foundation.orchestrator.queueAudio();
···133107134108```js
135109effect(() => {
136136- const track = ctl.currentTrack(); // computed — call like a fn
137137- const isPlaying = ctl.isPlaying();
138138- const audioState = ctl.audio(); // AudioStateReadOnly | undefined
110110+ const track = ctl.currentTrack(); // computed — call like a fn
111111+ const isPlaying = ctl.isPlaying();
112112+ const audioState = ctl.audio(); // AudioStateReadOnly | undefined
139113140114 if (audioState) {
141141- const progress = audioState.progress(); // 0–1
142142- const current = audioState.currentTime();
115115+ const progress = audioState.progress(); // 0–1
116116+ const current = audioState.currentTime();
143117 const duration = audioState.duration();
144118 }
145119146146- const now = queue.now(); // SignalReader — call like a fn
147147- const past = queue.past();
120120+ const now = queue.now(); // SignalReader — call like a fn
121121+ const past = queue.past();
148122 const future = queue.future();
149123});
150124```
···155129audio.play({ audioId: queue.now().id });
156130audio.pause({ audioId: queue.now().id });
157131audio.seek({ audioId: queue.now().id, percentage: 0.5 }); // 0–1
158158-queue.shift(); // next track
159159-queue.unshift(); // previous track
132132+queue.shift(); // next track
133133+queue.unshift(); // previous track
160134```
135135+136136+### Additional requirements and notes
137137+138138+- When working with track lists, realise that there could be a huge number of tracks that you need to work with (eg. 20000 tracks). You can use `~/vendor/@tanstack/virtual-core/index.js` for this.
139139+- Prefer the lit-html library as the templating/rendering engine. It is available from `~/vendor/lit-html/index.js` (among some other libraries such as: `idb-keyval`, `throttle-debounce`, several `@atcute` libraries, and `kmenu-core`). Always make sure to use the `~/vendor/` prefix for libraries, you're not working in an enviroment that bundles code.
140140+- Prefer to fetch the tracks from the `scoped-tracks` orchestrator element.
141141+- Talking about orchestrators, always prefer to use an orchestrator or another component instead of reimplementing logic yourself.
161142162143## Step 4 — Deliver
163144