···77import * as TID from "@atcute/tid";
8899import * as CID from "~/common/cid.js";
1010+import * as Output from "~/common/output.js";
1011import foundation from "~/common/facets/foundation.js";
1111-import { signal } from "~/common/signal.js";
1212+import { facetFromURI } from "~/common/facets/utils.js";
1213import { loadURI } from "~/common/loader.js";
1414+import { signal } from "~/common/signal.js";
13151416/**
1517 * @import {Facet} from "~/definitions/types.d.ts"
···4143</style>
42444345<script type="module">
4444- import foundation from "@diffuse/foundation";
4545- import { effect } from "./common/signal.js";
4646+ import foundation from "~/common/facets/foundation.js";
4747+ import { effect } from "~/common/signal.js";
46484749 const components = foundation.features.fillQueueAutomatically();
4850 const myHtmlElement = document.querySelector("#now-playing");
···161163/**
162164 * @param {Facet} facet
163165 */
166166+164167async function saveFacet(facet) {
168168+ await Output.waitUntilLoaded(output.facets);
169169+165170 const col = output.facets.collection();
166171 const colWithoutId = col.filter((c) => c.id !== facet.id);
167172 await output.facets.save([...colWithoutId, {
···169174 updatedAt: new Date().toISOString(),
170175 }]);
171176}
177177+178178+////////////////////////////////////////////
179179+// SAVE & FORK
180180+////////////////////////////////////////////
181181+182182+document.body.addEventListener(
183183+ "click",
184184+ /**
185185+ * @param {MouseEvent} event
186186+ */
187187+ async (event) => {
188188+ const target = /** @type {HTMLElement} */ (event.target);
189189+ const rel = target.getAttribute("rel");
190190+ if (!rel) return;
191191+192192+ const uri = target.closest("li")?.getAttribute("data-uri");
193193+ if (!uri) return;
194194+195195+ const name = target.closest("li")?.getAttribute("data-name");
196196+ if (!name) return;
197197+198198+ switch (rel) {
199199+ case "edit": {
200200+ const facet = await facetFromURI({ name, uri }, { fetchHTML: true });
201201+ editFacet(facet);
202202+ document.querySelector("#build")?.scrollIntoView();
203203+ break;
204204+ }
205205+ }
206206+ },
207207+);
208208+209209+////////////////////////////////////////////
210210+// 🚀
211211+////////////////////////////////////////////
212212+213213+await Output.waitUntilLoaded(output.facets);
214214+215215+// Load facet from url
216216+const idParam = new URLSearchParams(location.search).get("id");
217217+218218+if (idParam) {
219219+ const facet = output.facets.collection().find((f) => f.id === idParam);
220220+ if (facet) await editFacet(facet);
221221+}
-253
src/facets/_index.vto
···11----
22-layout: layouts/diffuse.vto
33-base: ../
44-55-styles:
66- - styles/base.css
77- - styles/diffuse/page.css
88- - vendor/@phosphor-icons/bold/style.css
99- - vendor/@phosphor-icons/fill/style.css
1010-1111-scripts:
1212- - facets/index.js
1313-1414-examples:
1515- - url: "facets/examples/now-playing/index.html"
1616- title: "Now playing"
1717- desc: >
1818- Shows what's currently set to "now playing" in the queue, along with a button to shift the queue to the next track.
1919- - url: "facets/examples/generate-playlist/index.html"
2020- title: "Generate playlist"
2121- desc: >
2222- Make a list of what previously played in the queue.
2323----
2424-2525-<header>
2626- <div>
2727- <div>
2828- <a class="diffuse-logo" href="./" style="display: inline-block;">
2929- {{ await comp.diffuse.logo() }}
3030- </a>
3131- </div>
3232- <p class="construct dither-mask" style="margin-top: 0; max-width: none;">
3333- Facets
3434- </p>
3535- <p>
3636- Facets are various interface components each loaded in their own web page. Every used component is configured so that it operates in broadcast mode, making all the pages communicate with each other.
3737- </p>
3838-3939- <ul class="table-of-contents">
4040- <li><a href="facets/#collection">Your collection</a></li>
4141- <li><a href="facets/#featured">Featured</a></li>
4242- <li><a href="facets/#usage">Usage</a></li>
4343- <li><a href="facets/#built-in">Built-in</a></li>
4444- <li><a href="facets/#community">Community</a></li>
4545- <li><a href="facets/#build">Build</a></li>
4646- <li><a href="facets/#foundation">Foundation</a></li>
4747- <li><a href="facets/#examples">Examples</a></li>
4848- <li><a href="facets/#notes">Notes</a></li>
4949- </ul>
5050- </div>
5151- <div class="dither-mask filler"></div>
5252-</header>
5353-<main>
5454- <!-- FEATURED + USAGE -->
5555- <div class="columns">
5656- <section class="flex">
5757- <h2 id="featured">Featured</h2>
5858-5959- <ol style="list-style: none; padding-left: 0;">
6060- <li>
6161- <p>
6262- <i class="ph-fill ph-plus"></i>
6363- <strong><a href="{{ ('themes/webamp/configurators/input/facet/index.html') |> facetLoaderURL }}">Add</a></strong> audio from various places on the web and your device.
6464- </p>
6565- </li>
6666- <li>
6767- <p>
6868- <i class="ph-fill ph-queue"></i>
6969- <strong><a href="{{ ('themes/webamp/browser/facet/index.html') |> facetLoaderURL }}">Browse</a></strong> your collection to put something into the queue.
7070- </p>
7171- </li>
7272- <li>
7373- <p>
7474- <i class="ph-fill ph-queue"></i>
7575- <strong><a href="{{ ('facets/tools/auto-queue/index.html') |> facetLoaderURL }}">Automate</a></strong> adding items to the queue, for infinite playback or listening to a playlist.
7676- </p>
7777- </li>
7878- <li>
7979- <p>
8080- <i class="ph-fill ph-music-note"></i>
8181- <strong><a href="{{ ('themes/blur/artwork-controller/facet/index.html') |> facetLoaderURL }}">Play</a></strong> queued songs.
8282- </p>
8383- </li>
8484- <li>
8585- <p>
8686- <i class="ph-fill ph-person"></i>
8787- <strong><a href="{{ ('themes/webamp/configurators/output/facet/index.html') |> facetLoaderURL }}">Manage</a></strong> your user data, sync with your other devices or other people.
8888- </p>
8989- </li>
9090- </ol>
9191- </section>
9292-9393- <section class="flex">
9494- <h2 id="usage">Usage</h2>
9595- <p>
9696- To use these facets, simply open whichever ones provide the functionality that you're looking for at a given moment. You can browse existing ones here and create one below.
9797- </p>
9898- <p>
9999- For example, say you want to play music; two options would be: (1) <a href="{{ ('themes/webamp/browser/facet/index.html') |> facetLoaderURL }}">browse</a> for a specific song and add it to the queue, or (2) <a href="{{ ('facets/tools/auto-queue/index.html') |> facetLoaderURL }}">automatically</a> add a bunch of shuffled songs to the queue. Next, you need a way to play the items you added to the queue. That's where a <a href="{{ ('themes/blur/artwork-controller/facet/index.html') |> facetLoaderURL }}">controller</a> could be used.
100100- </p>
101101- <p>
102102- <em>You might ask, why can't I do all of this in just one window? That's what <a href="themes/">themes</a> are for, if you need something more streamlined. If you however want a customised experience, or prefer certain interfaces for certain things, that's what facets are for.</em>
103103- </p>
104104- <p>
105105- <small><i class="ph-fill ph-info"></i> Every facet has access to your audio collection and your user data, along with any other shared state.</small>
106106- </p>
107107- </section>
108108- </div>
109109-110110- <!-- BUILT-IN + COMMUNITY -->
111111- <div class="columns">
112112- <section class="flex">
113113- <h2 id="built-in">Built-in</h2>
114114-115115- {{ await comp.facets.list({ id: "builtin", items: facets }) }}
116116- </section>
117117-118118- <section class="flex">
119119- <h2 id="community">Community</h2>
120120- <p>
121121- Check out some facets from the community and load them here.
122122- </p>
123123- <p>
124124- <small><i class="ph-fill ph-info"></i> Nothing here yet, too early.</small>
125125- </p>
126126- </section>
127127- </div>
128128-129129- <!-- / -->
130130- <div class="dither-mask filler" style="height: var(--space-2xl); margin-top: var(--space-2xl);"></div>
131131-132132- <!-- BUILD -->
133133- <section>
134134- <h2 id="build">Build</h2>
135135-136136- <form id="build-form" class="columns">
137137- <div class="flex">
138138- <p style="margin-top: 0">
139139- If you know a bit of HTML & Javascript, you can write your own or plug in some code you found elsewhere:
140140- </p>
141141-142142- <div id="html-input-container" class="code-editor monospace-font">
143143- </div>
144144- </div>
145145-146146- <div class="flex">
147147- <p style="margin-top: 0">
148148- Your code here builds on the <a href="facets/#foundation">foundation</a> listed below, it'll be injected into a <code><div id="container"></code> element in the body.
149149- </p>
150150- <p>
151151- <input id="name-input" type="text" placeholder="Name" name="name" required />
152152- </p>
153153- <p>
154154- <textarea id="description-input" placeholder="Description" name="description" rows="2"></textarea>
155155- </p>
156156- <p>
157157- <span class="button-row">
158158- <button name="save">Save</button>
159159- <button name="save+open">Save & Open</button>
160160- </span>
161161- </p>
162162- </div>
163163- </form>
164164- </section>
165165-166166- <!-- FOUNDATION -->
167167- <div class="columns">
168168- <section class="flex">
169169- <h2 id="foundation">Foundation</h2>
170170-171171- <p>
172172- Diffuse comes with a foundation that preconfigures all elements so you don't have to set them up yourself, along with a combination of elements for certain features. It internally tracks the DOM addition of the custom elements, so no need to worry about setting up an element multiple times.
173173- </p>
174174- <p>
175175- <small><i class="ph-fill ph-info"></i> Refer to the <a href="#elements">elements index</a> to find out what each element does.</small>
176176- </p>
177177- <div class="code-block">
178178- <code>
179179- {{- echo -}}
180180- import foundation from "common/facets/foundation.js"
181181- {{ /echo }}
182182-{{ echo -}}foundation.engine.audio(){{- /echo }}
183183-{{ echo -}}foundation.engine.queue(){{- /echo }}
184184-{{ echo -}}foundation.engine.repeatShuffle(){{- /echo }}
185185-{{ echo -}}foundation.engine.scope(){{- /echo }}
186186-187187-{{ echo -}}foundation.orchestrator.autoQueue(){{- /echo }}
188188-{{ echo -}}foundation.orchestrator.favourites(){{- /echo }}
189189-{{ echo -}}foundation.orchestrator.input(){{- /echo }}
190190-{{ echo -}}foundation.orchestrator.output(){{- /echo }}
191191-{{ echo -}}foundation.orchestrator.queueAudio(){{- /echo }}
192192-{{ echo -}}foundation.orchestrator.processTracks(){{- /echo }}
193193-{{ echo -}}foundation.orchestrator.scopedTracks(){{- /echo }}
194194-{{ echo -}}foundation.orchestrator.sources(){{- /echo }}
195195-196196-{{ echo -}}foundation.processor.artwork(){{- /echo }}
197197-{{ echo -}}foundation.processor.metadata(){{- /echo }}
198198-{{ echo -}}foundation.processor.search(){{- /echo -}}
199199- </code>
200200- </div>
201201-202202- <p>
203203- <small>Features:</small>
204204- </p>
205205- <ul style="margin-bottom: 0;">
206206- <li>
207207- <span>Fill the queue automatically <small>(infinite play)</small></span>
208208- <div class="list-description">
209209- <code>foundation.features.fillQueueAutomatically()</code>
210210- </div>
211211- </li>
212212- <li>
213213- <span>Play audio from the queue</span>
214214- <div class="list-description">
215215- <code>foundation.features.playAudioFromQueue()</code>
216216- </div>
217217- </li>
218218- <li>
219219- <span>Process inputs <small>(into tracks, etc)</small></span>
220220- <div class="list-description">
221221- <code>foundation.features.processInputs()</code>
222222- </div>
223223- </li>
224224- <li>
225225- <span>Search through your collection</span>
226226- <div class="list-description" style="margin-bottom: 0;">
227227- <code>foundation.features.searchThroughCollection()</code>
228228- </div>
229229- </li>
230230- </ul>
231231- </section>
232232-233233- <section class="flex">
234234- <h2 id="examples">Examples</h2>
235235-236236- <p>
237237- Some simple examples to help you understand how to build your own facet. Fork them to load them into the code editor below (or save → edit).
238238- </p>
239239-240240- {{ await comp.facets.list({ id: "examples", items: examples }) }}
241241-242242- <h2 id="notes">Notes</h2>
243243- <p>
244244- While you have the ability to do whatever you want in a custom facet, the existing facets are designed to work a certain way; so here's some things to keep in mind:
245245- </p>
246246- <ul>
247247- <li><span>In most cases you'll want to call <code>foundation.features.processInputs()</code> so that your audio files and streams actually show up.</span></li>
248248- <li><span>Most elements are configured in broadcast mode so they communicate across tabs. There are a few exceptions such as inputs, where we prefer parallelisation.</span></li>
249249- <li><span>You can use facets in combination with themes by adding the elements used in the theme to a group and then passing in the group name as a URL query parameter (eg. <code>group=facets</code>)</span></li>
250250- </ul>
251251- </section>
252252- </div>
253253-</main>
+137-2
src/facets/build.vto
···22layout: layouts/facets.vto
33base: ../../
44title: Build | Facets | Diffuse
55+66+styles:
77+ - styles/base.css
88+ - styles/diffuse/page.css
99+ - styles/diffuse/code-editor.css
1010+ - vendor/@phosphor-icons/bold/style.css
1111+ - vendor/@phosphor-icons/fill/style.css
1212+1313+scripts:
1414+ - facets/build.js
1515+1616+examples:
1717+ - url: "facets/examples/now-playing/index.html"
1818+ title: "Now playing"
1919+ desc: >
2020+ Shows what's currently set to "now playing" in the queue, along with a button to shift the queue to the next track.
2121+ - url: "facets/examples/generate-playlist/index.html"
2222+ title: "Generate playlist"
2323+ desc: >
2424+ Make a list of what previously played in the queue.
525---
62677-<section>
88- <h1 hidden>Build</h1>
2727+<h1 id="build" hidden>Build</h1>
2828+2929+3030+<!-- BUILD -->
3131+<section style="margin-top: var(--space-lg);">
3232+ <form id="build-form" class="columns">
3333+ <div class="flex">
3434+ <div id="html-input-container" class="code-editor monospace-font">
3535+ </div>
3636+ </div>
3737+3838+ <div style="flex: 1; max-width: var(--container-sm)">
3939+ <p style="margin-top: 0">
4040+ Your code here builds on the <a href="#foundation">foundation</a> listed below, and will be injected into a <span style="white-space: nowrap"><code><div id="container"></code></span> element in the body.
4141+ </p>
4242+ <p>
4343+ <input id="name-input" type="text" placeholder="Name" name="name" required />
4444+ </p>
4545+ <p>
4646+ <textarea id="description-input" placeholder="Description" name="description" rows="5"></textarea>
4747+ </p>
4848+ <p>
4949+ <span class="button-row">
5050+ <button class="button--bg-twist-2" name="save">Save</button>
5151+ <button class="button--bg-twist-2" name="save+open">Save & Open</button>
5252+ </span>
5353+ </p>
5454+ </div>
5555+ </form>
956</section>
5757+5858+<!-- FOUNDATION -->
5959+<div class="columns">
6060+ <section class="flex">
6161+ <h2 id="foundation">Foundation</h2>
6262+6363+ <p>
6464+ Diffuse comes with a foundation that preconfigures all elements so you don't have to set them up yourself, along with a combination of elements for certain features. It internally tracks the DOM addition of the custom elements, so no need to worry about setting up an element multiple times.
6565+ </p>
6666+ <p>
6767+ <small><i class="ph-fill ph-info"></i> Refer to the <a href="#elements">elements index</a> to find out what each element does.</small>
6868+ </p>
6969+ <div class="code-block">
7070+ <code>
7171+ {{- echo -}}
7272+ import foundation from "common/facets/foundation.js"
7373+ {{ /echo }}
7474+{{ echo -}}foundation.engine.audio(){{- /echo }}
7575+{{ echo -}}foundation.engine.queue(){{- /echo }}
7676+{{ echo -}}foundation.engine.repeatShuffle(){{- /echo }}
7777+{{ echo -}}foundation.engine.scope(){{- /echo }}
7878+7979+{{ echo -}}foundation.orchestrator.autoQueue(){{- /echo }}
8080+{{ echo -}}foundation.orchestrator.favourites(){{- /echo }}
8181+{{ echo -}}foundation.orchestrator.input(){{- /echo }}
8282+{{ echo -}}foundation.orchestrator.output(){{- /echo }}
8383+{{ echo -}}foundation.orchestrator.queueAudio(){{- /echo }}
8484+{{ echo -}}foundation.orchestrator.processTracks(){{- /echo }}
8585+{{ echo -}}foundation.orchestrator.scopedTracks(){{- /echo }}
8686+{{ echo -}}foundation.orchestrator.sources(){{- /echo }}
8787+8888+{{ echo -}}foundation.processor.artwork(){{- /echo }}
8989+{{ echo -}}foundation.processor.metadata(){{- /echo }}
9090+{{ echo -}}foundation.processor.search(){{- /echo -}}
9191+ </code>
9292+ </div>
9393+9494+ <p>
9595+ <small>Features:</small>
9696+ </p>
9797+ <ul style="margin-bottom: 0;">
9898+ <li>
9999+ <span>Fill the queue automatically <small>(infinite play)</small></span>
100100+ <div class="list-description">
101101+ <code>foundation.features.fillQueueAutomatically()</code>
102102+ </div>
103103+ </li>
104104+ <li>
105105+ <span>Play audio from the queue</span>
106106+ <div class="list-description">
107107+ <code>foundation.features.playAudioFromQueue()</code>
108108+ </div>
109109+ </li>
110110+ <li>
111111+ <span>Process inputs <small>(into tracks, etc)</small></span>
112112+ <div class="list-description">
113113+ <code>foundation.features.processInputs()</code>
114114+ </div>
115115+ </li>
116116+ <li>
117117+ <span>Search through your collection</span>
118118+ <div class="list-description" style="margin-bottom: 0;">
119119+ <code>foundation.features.searchThroughCollection()</code>
120120+ </div>
121121+ </li>
122122+ </ul>
123123+ </section>
124124+125125+ <section class="flex">
126126+ <h2 id="examples">Examples</h2>
127127+128128+ <p>
129129+ Some simple examples to help you understand how to build your own facet. Click the edit button to load them into the code editor above.
130130+ </p>
131131+132132+ {{ await comp.facets.examples({ id: "examples", items: examples }) }}
133133+134134+ <h2 id="notes">Notes</h2>
135135+ <p>
136136+ While you have the ability to do whatever you want in a custom facet, the existing facets are designed to work a certain way; so here's some things to keep in mind:
137137+ </p>
138138+ <ul>
139139+ <li><span>In most cases you'll want to call <code>foundation.features.processInputs()</code> so that your audio files and streams actually show up.</span></li>
140140+ <li><span>Most elements are configured in broadcast mode so they communicate across tabs. There are a few exceptions such as inputs, where we prefer parallelisation.</span></li>
141141+ <li><span>You can use facets in combination with themes by adding the elements used in the theme to a group and then passing in the group name as a URL query parameter (eg. <code>group=facets</code>)</span></li>
142142+ </ul>
143143+ </section>
144144+</div>