@litlab/audx 0.5.5 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -20
- package/dist/bin.js +389 -200
- package/dist/{cc-DgCkkqq8.js → cc-zJdVkWBV.js} +12 -1
- package/dist/index.js +3 -1
- package/dist/react.js +3 -1
- package/package.json +1 -1
- package/schemas/pack.schema.json +1 -1
- package/schemas/{patch.schema.json → theme.schema.json} +4 -4
package/README.md
CHANGED
|
@@ -37,58 +37,58 @@ beep();
|
|
|
37
37
|
click();
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
### Sound
|
|
40
|
+
### Sound themes (React)
|
|
41
41
|
|
|
42
42
|
```tsx
|
|
43
|
-
import {
|
|
43
|
+
import { useTheme } from "@litlab/audx/react";
|
|
44
44
|
|
|
45
45
|
function App() {
|
|
46
|
-
const
|
|
46
|
+
const theme = useTheme("/themes/core.json");
|
|
47
47
|
|
|
48
48
|
return (
|
|
49
|
-
<button onClick={() =>
|
|
49
|
+
<button onClick={() => theme.play("click")} disabled={!theme.ready}>
|
|
50
50
|
Click me
|
|
51
51
|
</button>
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
### Sound
|
|
56
|
+
### Sound themes (vanilla)
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
|
-
import {
|
|
59
|
+
import { loadTheme } from "@litlab/audx";
|
|
60
60
|
|
|
61
|
-
const
|
|
62
|
-
|
|
61
|
+
const theme = await loadTheme("/themes/core.json");
|
|
62
|
+
theme.play("click");
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
## CLI
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
-
# Browse and install
|
|
68
|
+
# Browse and install themes from the registry
|
|
69
69
|
npx @litlab/audx add
|
|
70
70
|
|
|
71
|
-
# Install
|
|
71
|
+
# Install themes from a GitHub repo
|
|
72
72
|
npx @litlab/audx add user/repo
|
|
73
73
|
|
|
74
|
-
# Create a new sound
|
|
74
|
+
# Create a new sound theme
|
|
75
75
|
npx @litlab/audx init
|
|
76
76
|
|
|
77
|
-
# List installed
|
|
77
|
+
# List installed themes
|
|
78
78
|
npx @litlab/audx list
|
|
79
79
|
|
|
80
|
-
# Remove installed
|
|
80
|
+
# Remove installed themes
|
|
81
81
|
npx @litlab/audx remove
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
##
|
|
84
|
+
## Theme authoring
|
|
85
85
|
|
|
86
|
-
Create a
|
|
86
|
+
Create a theme JSON file with `npx @litlab/audx init`, then add sound definitions to the `sounds` object:
|
|
87
87
|
|
|
88
88
|
```json
|
|
89
89
|
{
|
|
90
|
-
"$schema": "node_modules/@litlab/audx/schemas/
|
|
91
|
-
"name": "my-
|
|
90
|
+
"$schema": "node_modules/@litlab/audx/schemas/theme.schema.json",
|
|
91
|
+
"name": "my-theme",
|
|
92
92
|
"sounds": {
|
|
93
93
|
"click": {
|
|
94
94
|
"source": { "type": "noise", "color": "white" },
|
|
@@ -116,9 +116,9 @@ npx @litlab/audx add your-username/your-repo
|
|
|
116
116
|
| `square(freq, decay)` | Shorthand for square oscillator |
|
|
117
117
|
| `sawtooth(freq, decay)` | Shorthand for sawtooth oscillator |
|
|
118
118
|
| `noise(color, decay)` | Shorthand for noise generator |
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
119
|
+
| `loadTheme(url)` | Load a sound theme from a URL |
|
|
120
|
+
| `defineTheme(json)` | Create a theme from a JSON object |
|
|
121
|
+
| `useTheme(url)` | React hook for loading and playing themes |
|
|
122
122
|
|
|
123
123
|
## Documentation
|
|
124
124
|
|
package/dist/bin.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import * as p from '@clack/prompts';
|
|
2
|
+
import { a as _object_without_properties_loose, _ as _extends } from './cc-zJdVkWBV.js';
|
|
3
3
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
4
4
|
import { readdir, readFile, writeFile, unlink } from 'node:fs/promises';
|
|
5
5
|
import __node_cjsPath, { resolve, join, basename, isAbsolute } from 'node:path';
|
|
6
6
|
import pc from 'picocolors';
|
|
7
|
-
import { _ as _object_without_properties_loose } from './cc-DgCkkqq8.js';
|
|
8
7
|
import __node_cjsModule from 'node:module';
|
|
9
8
|
import __node_cjsUrl from 'node:url';
|
|
10
9
|
|
|
@@ -97,7 +96,7 @@ function normalizeConfigOutput(output, context) {
|
|
|
97
96
|
}
|
|
98
97
|
return normalized;
|
|
99
98
|
}
|
|
100
|
-
function
|
|
99
|
+
function getThemesDir() {
|
|
101
100
|
var _ref;
|
|
102
101
|
const config = getConfig();
|
|
103
102
|
const output = (_ref = config == null ? void 0 : config.output) != null ? _ref : "src/audio";
|
|
@@ -132,7 +131,7 @@ function parseGitHubSource(source) {
|
|
|
132
131
|
}
|
|
133
132
|
return null;
|
|
134
133
|
}
|
|
135
|
-
async function
|
|
134
|
+
async function discoverThemesFromGitHub(source) {
|
|
136
135
|
const parsed = parseGitHubSource(source);
|
|
137
136
|
if (!parsed) {
|
|
138
137
|
throw new Error(`Invalid source: ${source}. Use owner/repo or a GitHub URL.`);
|
|
@@ -157,15 +156,15 @@ async function discoverPatchesFromGitHub(source) {
|
|
|
157
156
|
if (item.path.includes(".changeset/")) return false;
|
|
158
157
|
return true;
|
|
159
158
|
});
|
|
160
|
-
const
|
|
159
|
+
const themes = [];
|
|
161
160
|
for (const file of jsonFiles){
|
|
162
161
|
const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/${file.path}`;
|
|
163
162
|
try {
|
|
164
163
|
const r = await fetch(rawUrl);
|
|
165
164
|
if (!r.ok) continue;
|
|
166
165
|
const data = await r.json();
|
|
167
|
-
if (!
|
|
168
|
-
|
|
166
|
+
if (!validateTheme(data)) continue;
|
|
167
|
+
themes.push({
|
|
169
168
|
name: data.name,
|
|
170
169
|
path: file.path,
|
|
171
170
|
downloadUrl: rawUrl,
|
|
@@ -174,7 +173,7 @@ async function discoverPatchesFromGitHub(source) {
|
|
|
174
173
|
});
|
|
175
174
|
} catch (unused) {}
|
|
176
175
|
}
|
|
177
|
-
return
|
|
176
|
+
return themes;
|
|
178
177
|
}
|
|
179
178
|
function isGitHubSource(source) {
|
|
180
179
|
return parseGitHubSource(source) !== null;
|
|
@@ -186,13 +185,13 @@ function isLocalSource(source) {
|
|
|
186
185
|
const abs = isAbsolute(source) ? source : resolve(process.cwd(), source);
|
|
187
186
|
return existsSync(abs);
|
|
188
187
|
}
|
|
189
|
-
async function
|
|
188
|
+
async function discoverThemesFromLocal(source) {
|
|
190
189
|
const abs = isAbsolute(source) ? source : resolve(process.cwd(), source);
|
|
191
190
|
if (abs.endsWith(".json")) {
|
|
192
191
|
const raw = await readFile(abs, "utf-8");
|
|
193
192
|
const data = JSON.parse(raw);
|
|
194
|
-
if (!
|
|
195
|
-
throw new Error(`${source} is not a valid sound
|
|
193
|
+
if (!validateTheme(data)) {
|
|
194
|
+
throw new Error(`${source} is not a valid sound theme.`);
|
|
196
195
|
}
|
|
197
196
|
return [
|
|
198
197
|
{
|
|
@@ -205,15 +204,15 @@ async function discoverPatchesFromLocal(source) {
|
|
|
205
204
|
];
|
|
206
205
|
}
|
|
207
206
|
const files = await readdir(abs);
|
|
208
|
-
const
|
|
207
|
+
const themes = [];
|
|
209
208
|
for (const file of files){
|
|
210
209
|
if (!file.endsWith(".json") || file === "index.json") continue;
|
|
211
210
|
try {
|
|
212
211
|
const filePath = join(abs, file);
|
|
213
212
|
const raw = await readFile(filePath, "utf-8");
|
|
214
213
|
const data = JSON.parse(raw);
|
|
215
|
-
if (!
|
|
216
|
-
|
|
214
|
+
if (!validateTheme(data)) continue;
|
|
215
|
+
themes.push({
|
|
217
216
|
name: data.name,
|
|
218
217
|
path: filePath,
|
|
219
218
|
downloadUrl: filePath,
|
|
@@ -222,26 +221,26 @@ async function discoverPatchesFromLocal(source) {
|
|
|
222
221
|
});
|
|
223
222
|
} catch (unused) {}
|
|
224
223
|
}
|
|
225
|
-
return
|
|
224
|
+
return themes;
|
|
226
225
|
}
|
|
227
|
-
async function
|
|
228
|
-
const res = await fetch(`${REGISTRY_BASE}/
|
|
226
|
+
async function fetchThemeIndex() {
|
|
227
|
+
const res = await fetch(`${REGISTRY_BASE}/audio/themes`);
|
|
229
228
|
if (!res.ok) {
|
|
230
|
-
throw new Error(`Failed to fetch
|
|
229
|
+
throw new Error(`Failed to fetch theme index: ${res.status}`);
|
|
231
230
|
}
|
|
232
231
|
return res.json();
|
|
233
232
|
}
|
|
234
|
-
async function
|
|
235
|
-
const url = nameOrUrl.startsWith("http") ? nameOrUrl : `${REGISTRY_BASE}/
|
|
233
|
+
async function fetchThemeJson(nameOrUrl) {
|
|
234
|
+
const url = nameOrUrl.startsWith("http") ? nameOrUrl : `${REGISTRY_BASE}/audio/theme/${nameOrUrl}`;
|
|
236
235
|
const res = await fetch(url);
|
|
237
236
|
if (!res.ok) {
|
|
238
|
-
throw new Error(`Failed to fetch
|
|
237
|
+
throw new Error(`Failed to fetch theme: ${res.status}`);
|
|
239
238
|
}
|
|
240
239
|
return res.json();
|
|
241
240
|
}
|
|
242
|
-
async function
|
|
241
|
+
async function registerTheme(url) {
|
|
243
242
|
try {
|
|
244
|
-
await fetch(`${REGISTRY_BASE}/
|
|
243
|
+
await fetch(`${REGISTRY_BASE}/audio/themes`, {
|
|
245
244
|
method: "POST",
|
|
246
245
|
headers: {
|
|
247
246
|
"Content-Type": "application/json"
|
|
@@ -252,30 +251,30 @@ async function registerPatch(url) {
|
|
|
252
251
|
});
|
|
253
252
|
} catch (unused) {}
|
|
254
253
|
}
|
|
255
|
-
function
|
|
254
|
+
function validateTheme(data) {
|
|
256
255
|
return typeof data.name === "string" && typeof data.sounds === "object" && data.sounds !== null;
|
|
257
256
|
}
|
|
258
|
-
async function
|
|
259
|
-
const dir =
|
|
257
|
+
async function getInstalledThemes() {
|
|
258
|
+
const dir = getThemesDir();
|
|
260
259
|
if (!existsSync(dir)) return [];
|
|
261
260
|
const files = await readdir(dir);
|
|
262
|
-
const
|
|
261
|
+
const themes = [];
|
|
263
262
|
for (const file of files){
|
|
264
263
|
if (!file.endsWith(".ts") || file === "index.ts") continue;
|
|
265
264
|
try {
|
|
266
265
|
var _raw_match, _ref;
|
|
267
266
|
const raw = await readFile(join(dir, file), "utf-8");
|
|
268
|
-
const nameMatch = raw.match(/^\/\/
|
|
267
|
+
const nameMatch = raw.match(/^\/\/ theme: (.+)$/m);
|
|
269
268
|
const exportCount = ((_raw_match = raw.match(/^export const /gm)) != null ? _raw_match : []).length;
|
|
270
269
|
const name = (_ref = nameMatch == null ? void 0 : nameMatch[1]) != null ? _ref : basename(file, ".ts");
|
|
271
|
-
|
|
270
|
+
themes.push({
|
|
272
271
|
file,
|
|
273
272
|
name,
|
|
274
273
|
soundCount: Math.max(0, exportCount - 1)
|
|
275
274
|
});
|
|
276
275
|
} catch (unused) {}
|
|
277
276
|
}
|
|
278
|
-
return
|
|
277
|
+
return themes;
|
|
279
278
|
}
|
|
280
279
|
const RESERVED = new Set([
|
|
281
280
|
"break",
|
|
@@ -335,7 +334,7 @@ function generateModule(data) {
|
|
|
335
334
|
const ids = entries.map(([key])=>toCamelCase(key));
|
|
336
335
|
const lines = [
|
|
337
336
|
`// ${data.name} — generated by @litlab/audx (do not edit)`,
|
|
338
|
-
`//
|
|
337
|
+
`// theme: ${data.name}`,
|
|
339
338
|
`import type { SoundDefinition, SoundPatch } from "@litlab/audx";`,
|
|
340
339
|
""
|
|
341
340
|
];
|
|
@@ -384,8 +383,12 @@ function parseAddOptions(args) {
|
|
|
384
383
|
options.yes = true;
|
|
385
384
|
} else if (arg === "-l" || arg === "--list") {
|
|
386
385
|
options.list = true;
|
|
387
|
-
} else if (arg === "--
|
|
388
|
-
options.
|
|
386
|
+
} else if (arg === "--theme") {
|
|
387
|
+
options.theme = args[++i];
|
|
388
|
+
} else if (arg === "--data") {
|
|
389
|
+
options.data = args[++i];
|
|
390
|
+
} else if (arg === "--tune") {
|
|
391
|
+
options.tune = args[++i];
|
|
389
392
|
} else if (arg && !arg.startsWith("-")) {
|
|
390
393
|
source = arg;
|
|
391
394
|
}
|
|
@@ -399,9 +402,21 @@ async function add(args) {
|
|
|
399
402
|
const { source, options } = parseAddOptions(args);
|
|
400
403
|
p.intro("@litlab/audx add");
|
|
401
404
|
if (!source) {
|
|
405
|
+
if (options.data || options.tune) {
|
|
406
|
+
p.log.error("--data and --tune require a sound name.");
|
|
407
|
+
process.exit(1);
|
|
408
|
+
}
|
|
402
409
|
await addFromRegistry(options);
|
|
403
410
|
return;
|
|
404
411
|
}
|
|
412
|
+
if (options.data) {
|
|
413
|
+
await addEncodedSound(source, options);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (options.tune) {
|
|
417
|
+
await addTunedSound(source, options);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
405
420
|
if (isLocalSource(source)) {
|
|
406
421
|
await addFromLocal(source, options);
|
|
407
422
|
return;
|
|
@@ -416,108 +431,280 @@ async function add(args) {
|
|
|
416
431
|
}
|
|
417
432
|
await addSoundFromRegistry(source, options);
|
|
418
433
|
}
|
|
434
|
+
const WAVEFORM_CODES = {
|
|
435
|
+
o: "original",
|
|
436
|
+
s: "sine",
|
|
437
|
+
t: "triangle",
|
|
438
|
+
q: "square",
|
|
439
|
+
w: "sawtooth"
|
|
440
|
+
};
|
|
441
|
+
function decodeSoundCustomization(value) {
|
|
442
|
+
const [version, pitch, duration, gain, pan, waveform, ...extra] = value.split(".");
|
|
443
|
+
if (version !== "1" || extra.length > 0 || !pitch || !duration || !gain || !pan || !waveform) {
|
|
444
|
+
throw new Error("unsupported tuning token");
|
|
445
|
+
}
|
|
446
|
+
const settings = {
|
|
447
|
+
pitch: Number.parseInt(pitch, 36) - 12,
|
|
448
|
+
duration: Number.parseInt(duration, 36) / 20,
|
|
449
|
+
gain: Number.parseInt(gain, 36) / 20,
|
|
450
|
+
pan: (Number.parseInt(pan, 36) - 20) / 20,
|
|
451
|
+
waveform: WAVEFORM_CODES[waveform]
|
|
452
|
+
};
|
|
453
|
+
if (!Number.isInteger(settings.pitch) || settings.pitch < -12 || settings.pitch > 12 || !Number.isFinite(settings.duration) || settings.duration < 0.25 || settings.duration > 3 || !Number.isFinite(settings.gain) || settings.gain < 0 || settings.gain > 2 || !Number.isFinite(settings.pan) || settings.pan < -1 || settings.pan > 1 || !settings.waveform) {
|
|
454
|
+
throw new Error("invalid tuning values");
|
|
455
|
+
}
|
|
456
|
+
return settings;
|
|
457
|
+
}
|
|
458
|
+
async function addTunedSound(soundName, options) {
|
|
459
|
+
if (!options.theme) {
|
|
460
|
+
p.log.error("--tune requires --theme <name>.");
|
|
461
|
+
process.exit(1);
|
|
462
|
+
}
|
|
463
|
+
let settings;
|
|
464
|
+
try {
|
|
465
|
+
var _options_tune;
|
|
466
|
+
settings = decodeSoundCustomization((_options_tune = options.tune) != null ? _options_tune : "");
|
|
467
|
+
} catch (err) {
|
|
468
|
+
p.log.error(`Invalid tuning token: ${err instanceof Error ? err.message : String(err)}`);
|
|
469
|
+
process.exit(1);
|
|
470
|
+
}
|
|
471
|
+
const s = p.spinner();
|
|
472
|
+
s.start(`Fetching "${soundName}" from ${options.theme}...`);
|
|
473
|
+
try {
|
|
474
|
+
const theme = await fetchThemeJson(options.theme);
|
|
475
|
+
if (!validateTheme(theme)) throw new Error("invalid theme");
|
|
476
|
+
const match = Object.entries(theme.sounds).find(([name])=>name.toLowerCase() === soundName.toLowerCase());
|
|
477
|
+
if (!match) throw new Error(`sound not found in theme "${options.theme}"`);
|
|
478
|
+
const definition = customizeDefinition(match[1], settings);
|
|
479
|
+
if (!validateSoundDefinition(definition)) {
|
|
480
|
+
throw new Error("theme returned an invalid sound definition");
|
|
481
|
+
}
|
|
482
|
+
s.stop(`Customized "${soundName}" from ${theme.name}`);
|
|
483
|
+
await writeSound(soundName, definition, options);
|
|
484
|
+
p.note(` - ${soundName}`, "Installed customized sound");
|
|
485
|
+
p.outro("Done!");
|
|
486
|
+
} catch (err) {
|
|
487
|
+
s.stop("Failed to install customized sound.");
|
|
488
|
+
p.log.error(err instanceof Error ? err.message : String(err));
|
|
489
|
+
process.exit(1);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function customizeDefinition(value, settings) {
|
|
493
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
494
|
+
const definition = value;
|
|
495
|
+
if (Array.isArray(definition.layers)) {
|
|
496
|
+
return _extends({}, definition, {
|
|
497
|
+
layers: definition.layers.map((layer)=>customizeDefinition(layer, settings)),
|
|
498
|
+
effects: scaleEffects(definition.effects, settings.duration)
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
const source = customizeSource(definition.source, settings);
|
|
502
|
+
const envelope = definition.envelope && typeof definition.envelope === "object" && !Array.isArray(definition.envelope) ? scaleEnvelope(definition.envelope, settings.duration) : undefined;
|
|
503
|
+
const gain = typeof definition.gain === "number" ? definition.gain : 0.5;
|
|
504
|
+
const delay = typeof definition.delay === "number" ? definition.delay : 0;
|
|
505
|
+
return _extends({}, definition, {
|
|
506
|
+
source,
|
|
507
|
+
envelope,
|
|
508
|
+
gain: clamp(gain * settings.gain, 0, 1)
|
|
509
|
+
}, "panner" in definition ? {} : {
|
|
510
|
+
pan: clamp((typeof definition.pan === "number" ? definition.pan : 0) + settings.pan, -1, 1)
|
|
511
|
+
}, {
|
|
512
|
+
delay: delay * settings.duration,
|
|
513
|
+
effects: scaleEffects(definition.effects, settings.duration)
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
function customizeSource(value, settings) {
|
|
517
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
518
|
+
const source = value;
|
|
519
|
+
const frequencyScale = 2 ** (settings.pitch / 12);
|
|
520
|
+
if (source.type === "sine" || source.type === "triangle" || source.type === "square" || source.type === "sawtooth" || source.type === "wavetable") {
|
|
521
|
+
return _extends({}, source, source.type === "wavetable" || settings.waveform === "original" ? {} : {
|
|
522
|
+
type: settings.waveform
|
|
523
|
+
}, {
|
|
524
|
+
frequency: scaleFrequency(source.frequency, frequencyScale)
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
if (source.type === "sample") {
|
|
528
|
+
return _extends({}, source, {
|
|
529
|
+
detune: (typeof source.detune === "number" ? source.detune : 0) + settings.pitch * 100
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
return source;
|
|
533
|
+
}
|
|
534
|
+
function scaleFrequency(value, scale) {
|
|
535
|
+
if (typeof value === "number") return value * scale;
|
|
536
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
537
|
+
const frequency = value;
|
|
538
|
+
if (typeof frequency.start !== "number" || typeof frequency.end !== "number") {
|
|
539
|
+
return value;
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
start: frequency.start * scale,
|
|
543
|
+
end: frequency.end * scale
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
function scaleEnvelope(envelope, duration) {
|
|
547
|
+
return _extends({}, envelope, {
|
|
548
|
+
attack: (typeof envelope.attack === "number" ? envelope.attack : 0) * duration,
|
|
549
|
+
decay: (typeof envelope.decay === "number" ? envelope.decay : 0) * duration,
|
|
550
|
+
release: (typeof envelope.release === "number" ? envelope.release : 0) * duration
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
function scaleEffects(value, duration) {
|
|
554
|
+
if (!Array.isArray(value)) return undefined;
|
|
555
|
+
return value.map((effect)=>{
|
|
556
|
+
if (!effect || typeof effect !== "object" || Array.isArray(effect)) {
|
|
557
|
+
return effect;
|
|
558
|
+
}
|
|
559
|
+
const item = effect;
|
|
560
|
+
if (item.type === "delay") {
|
|
561
|
+
return _extends({}, item, {
|
|
562
|
+
time: (typeof item.time === "number" ? item.time : 0.25) * duration
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
if (item.type === "reverb") {
|
|
566
|
+
return _extends({}, item, {
|
|
567
|
+
decay: (typeof item.decay === "number" ? item.decay : 0.5) * duration,
|
|
568
|
+
preDelay: (typeof item.preDelay === "number" ? item.preDelay : 0) * duration
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
return item;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function clamp(value, min, max) {
|
|
575
|
+
return Math.min(max, Math.max(min, value));
|
|
576
|
+
}
|
|
577
|
+
async function addEncodedSound(soundName, options) {
|
|
578
|
+
let definition;
|
|
579
|
+
try {
|
|
580
|
+
var _options_data;
|
|
581
|
+
definition = decodeSoundDefinition((_options_data = options.data) != null ? _options_data : "");
|
|
582
|
+
} catch (err) {
|
|
583
|
+
p.log.error(`Invalid customized sound data: ${err instanceof Error ? err.message : String(err)}`);
|
|
584
|
+
process.exit(1);
|
|
585
|
+
}
|
|
586
|
+
if (!validateSoundDefinition(definition)) {
|
|
587
|
+
p.log.error("Invalid customized sound definition.");
|
|
588
|
+
process.exit(1);
|
|
589
|
+
}
|
|
590
|
+
await writeSound(soundName, definition, options);
|
|
591
|
+
p.note(` - ${soundName}`, "Installed customized sound");
|
|
592
|
+
p.outro("Done!");
|
|
593
|
+
}
|
|
594
|
+
function decodeSoundDefinition(value) {
|
|
595
|
+
if (!value) throw new Error("missing value");
|
|
596
|
+
return JSON.parse(Buffer.from(value, "base64url").toString("utf-8"));
|
|
597
|
+
}
|
|
598
|
+
function validateSoundDefinition(value) {
|
|
599
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
600
|
+
const definition = value;
|
|
601
|
+
if (Array.isArray(definition.layers)) {
|
|
602
|
+
return definition.layers.length > 0 && definition.layers.every(validateSoundDefinition);
|
|
603
|
+
}
|
|
604
|
+
return !!definition.source && typeof definition.source === "object" && !Array.isArray(definition.source);
|
|
605
|
+
}
|
|
419
606
|
async function addFromLocal(source, options) {
|
|
420
607
|
const s = p.spinner();
|
|
421
|
-
s.start("Scanning local path for
|
|
608
|
+
s.start("Scanning local path for themes...");
|
|
422
609
|
let discovered;
|
|
423
610
|
try {
|
|
424
|
-
discovered = await
|
|
425
|
-
s.stop(`Found ${discovered.length}
|
|
611
|
+
discovered = await discoverThemesFromLocal(source);
|
|
612
|
+
s.stop(`Found ${discovered.length} theme(es)`);
|
|
426
613
|
} catch (err) {
|
|
427
614
|
s.stop("Failed to scan local path.");
|
|
428
615
|
p.log.error(String(err));
|
|
429
616
|
process.exit(1);
|
|
430
617
|
}
|
|
431
618
|
if (discovered.length === 0) {
|
|
432
|
-
p.log.warn("No valid sound
|
|
433
|
-
p.outro("
|
|
619
|
+
p.log.warn("No valid sound themes found at this path.");
|
|
620
|
+
p.outro("Themes must be JSON files with a name and sounds object.");
|
|
434
621
|
return;
|
|
435
622
|
}
|
|
436
623
|
if (options.list) {
|
|
437
|
-
|
|
624
|
+
printThemeList(discovered);
|
|
438
625
|
return;
|
|
439
626
|
}
|
|
440
|
-
const toInstall =
|
|
627
|
+
const toInstall = selectThemes(discovered, options);
|
|
441
628
|
if (!toInstall || toInstall.length === 0) return;
|
|
442
|
-
const installed = await
|
|
629
|
+
const installed = await getInstalledThemes();
|
|
443
630
|
const installedNames = new Set(installed.map((p)=>p.name));
|
|
444
|
-
const final = options.yes ? toInstall : await
|
|
631
|
+
const final = options.yes ? toInstall : await confirmThemeOverwrites(toInstall, installedNames);
|
|
445
632
|
if (!final || final.length === 0) return;
|
|
446
633
|
const dl = p.spinner();
|
|
447
|
-
dl.start(`Installing ${final.length}
|
|
634
|
+
dl.start(`Installing ${final.length} theme(es)...`);
|
|
448
635
|
const results = [];
|
|
449
|
-
for (const
|
|
636
|
+
for (const theme of final){
|
|
450
637
|
try {
|
|
451
|
-
const raw = await readFile(
|
|
638
|
+
const raw = await readFile(theme.downloadUrl, "utf-8");
|
|
452
639
|
const data = JSON.parse(raw);
|
|
453
|
-
if (!
|
|
454
|
-
p.log.warn(`Skipping ${
|
|
640
|
+
if (!validateTheme(data)) {
|
|
641
|
+
p.log.warn(`Skipping ${theme.name}: invalid theme format`);
|
|
455
642
|
continue;
|
|
456
643
|
}
|
|
457
|
-
await
|
|
644
|
+
await writeTheme(theme.name, data);
|
|
458
645
|
results.push(data.name);
|
|
459
646
|
} catch (err) {
|
|
460
|
-
p.log.warn(`Failed to install ${
|
|
647
|
+
p.log.warn(`Failed to install ${theme.name}: ${err}`);
|
|
461
648
|
}
|
|
462
649
|
}
|
|
463
|
-
dl.stop(`Installed ${results.length}
|
|
464
|
-
p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed
|
|
650
|
+
dl.stop(`Installed ${results.length} theme(es)`);
|
|
651
|
+
p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed themes");
|
|
465
652
|
p.outro("Done!");
|
|
466
653
|
}
|
|
467
654
|
async function addFromGitHub(source, options) {
|
|
468
655
|
const s = p.spinner();
|
|
469
|
-
s.start("Scanning repository for
|
|
656
|
+
s.start("Scanning repository for themes...");
|
|
470
657
|
let discovered;
|
|
471
658
|
try {
|
|
472
|
-
discovered = await
|
|
473
|
-
s.stop(`Found ${discovered.length}
|
|
659
|
+
discovered = await discoverThemesFromGitHub(source);
|
|
660
|
+
s.stop(`Found ${discovered.length} theme(es)`);
|
|
474
661
|
} catch (err) {
|
|
475
662
|
s.stop("Failed to scan repository.");
|
|
476
663
|
p.log.error(String(err));
|
|
477
664
|
process.exit(1);
|
|
478
665
|
}
|
|
479
666
|
if (discovered.length === 0) {
|
|
480
|
-
p.log.warn("No valid sound
|
|
481
|
-
p.outro("
|
|
667
|
+
p.log.warn("No valid sound themes found in this repository.");
|
|
668
|
+
p.outro("Themes must be JSON files with a name and sounds object.");
|
|
482
669
|
return;
|
|
483
670
|
}
|
|
484
671
|
if (options.list) {
|
|
485
|
-
|
|
672
|
+
printThemeList(discovered);
|
|
486
673
|
return;
|
|
487
674
|
}
|
|
488
|
-
const installed = await
|
|
675
|
+
const installed = await getInstalledThemes();
|
|
489
676
|
const installedNames = new Set(installed.map((p)=>p.name));
|
|
490
|
-
const toInstall = await
|
|
677
|
+
const toInstall = await resolveThemeSelection(discovered, installedNames, options);
|
|
491
678
|
if (!toInstall || toInstall.length === 0) return;
|
|
492
679
|
const dl = p.spinner();
|
|
493
|
-
dl.start(`Installing ${toInstall.length}
|
|
680
|
+
dl.start(`Installing ${toInstall.length} theme(es)...`);
|
|
494
681
|
const results = [];
|
|
495
|
-
for (const
|
|
682
|
+
for (const theme of toInstall){
|
|
496
683
|
try {
|
|
497
|
-
const data = await
|
|
498
|
-
if (!
|
|
499
|
-
p.log.warn(`Skipping ${
|
|
684
|
+
const data = await fetchThemeJson(theme.downloadUrl);
|
|
685
|
+
if (!validateTheme(data)) {
|
|
686
|
+
p.log.warn(`Skipping ${theme.name}: invalid theme format`);
|
|
500
687
|
continue;
|
|
501
688
|
}
|
|
502
|
-
await
|
|
503
|
-
|
|
689
|
+
await writeTheme(theme.name, data);
|
|
690
|
+
registerTheme(theme.downloadUrl);
|
|
504
691
|
results.push(data.name);
|
|
505
692
|
} catch (err) {
|
|
506
|
-
p.log.warn(`Failed to install ${
|
|
693
|
+
p.log.warn(`Failed to install ${theme.name}: ${err}`);
|
|
507
694
|
}
|
|
508
695
|
}
|
|
509
|
-
dl.stop(`Installed ${results.length}
|
|
510
|
-
p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed
|
|
696
|
+
dl.stop(`Installed ${results.length} theme(es)`);
|
|
697
|
+
p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed themes");
|
|
511
698
|
p.outro("Done!");
|
|
512
699
|
}
|
|
513
700
|
async function addFromUrl(url, options) {
|
|
514
701
|
const s = p.spinner();
|
|
515
|
-
s.start("Fetching
|
|
702
|
+
s.start("Fetching theme...");
|
|
516
703
|
try {
|
|
517
|
-
const data = await
|
|
518
|
-
if (!
|
|
519
|
-
s.stop("Invalid
|
|
520
|
-
p.log.error("The fetched JSON is not a valid sound
|
|
704
|
+
const data = await fetchThemeJson(url);
|
|
705
|
+
if (!validateTheme(data)) {
|
|
706
|
+
s.stop("Invalid theme format.");
|
|
707
|
+
p.log.error("The fetched JSON is not a valid sound theme (missing name or sounds).");
|
|
521
708
|
process.exit(1);
|
|
522
709
|
}
|
|
523
710
|
s.stop(`Fetched "${data.name}"`);
|
|
@@ -526,23 +713,23 @@ async function addFromUrl(url, options) {
|
|
|
526
713
|
console.log();
|
|
527
714
|
return;
|
|
528
715
|
}
|
|
529
|
-
await
|
|
530
|
-
|
|
716
|
+
await writeTheme(data.name, data);
|
|
717
|
+
registerTheme(url);
|
|
531
718
|
} catch (err) {
|
|
532
|
-
s.stop("Failed to fetch
|
|
719
|
+
s.stop("Failed to fetch theme.");
|
|
533
720
|
p.log.error(String(err));
|
|
534
721
|
process.exit(1);
|
|
535
722
|
}
|
|
536
723
|
}
|
|
537
724
|
async function addFromRegistry(options) {
|
|
538
725
|
const s = p.spinner();
|
|
539
|
-
s.start("Fetching available
|
|
726
|
+
s.start("Fetching available themes...");
|
|
540
727
|
let index;
|
|
541
728
|
try {
|
|
542
|
-
index = await
|
|
543
|
-
s.stop(`Found ${index.length}
|
|
729
|
+
index = await fetchThemeIndex();
|
|
730
|
+
s.stop(`Found ${index.length} themes`);
|
|
544
731
|
} catch (err) {
|
|
545
|
-
s.stop("Failed to fetch
|
|
732
|
+
s.stop("Failed to fetch theme index.");
|
|
546
733
|
p.log.error(String(err));
|
|
547
734
|
process.exit(1);
|
|
548
735
|
}
|
|
@@ -554,24 +741,24 @@ async function addFromRegistry(options) {
|
|
|
554
741
|
console.log();
|
|
555
742
|
return;
|
|
556
743
|
}
|
|
557
|
-
const installed = await
|
|
744
|
+
const installed = await getInstalledThemes();
|
|
558
745
|
const installedNames = new Set(installed.map((p)=>p.name));
|
|
559
746
|
let names;
|
|
560
|
-
if (options.
|
|
561
|
-
const
|
|
747
|
+
if (options.theme) {
|
|
748
|
+
const themeName = options.theme;
|
|
562
749
|
names = [
|
|
563
|
-
|
|
750
|
+
themeName
|
|
564
751
|
];
|
|
565
|
-
const match = index.find((e)=>e.name.toLowerCase() ===
|
|
752
|
+
const match = index.find((e)=>e.name.toLowerCase() === themeName.toLowerCase());
|
|
566
753
|
if (!match) {
|
|
567
|
-
p.log.error(`
|
|
754
|
+
p.log.error(`Theme "${themeName}" not found in registry.`);
|
|
568
755
|
process.exit(1);
|
|
569
756
|
}
|
|
570
757
|
} else if (options.yes) {
|
|
571
758
|
names = index.map((e)=>e.name);
|
|
572
759
|
} else {
|
|
573
760
|
const selected = await p.multiselect({
|
|
574
|
-
message: "Select
|
|
761
|
+
message: "Select themes to install",
|
|
575
762
|
options: index.map((entry)=>({
|
|
576
763
|
value: entry.name,
|
|
577
764
|
label: `${entry.name}${installedNames.has(entry.name) ? " (installed)" : ""}`,
|
|
@@ -584,7 +771,7 @@ async function addFromRegistry(options) {
|
|
|
584
771
|
}
|
|
585
772
|
names = selected;
|
|
586
773
|
if (names.length === 0) {
|
|
587
|
-
p.outro("No
|
|
774
|
+
p.outro("No themes selected.");
|
|
588
775
|
return;
|
|
589
776
|
}
|
|
590
777
|
}
|
|
@@ -592,7 +779,7 @@ async function addFromRegistry(options) {
|
|
|
592
779
|
const existing = names.filter((n)=>installedNames.has(n));
|
|
593
780
|
if (existing.length > 0) {
|
|
594
781
|
const overwrite = await p.confirm({
|
|
595
|
-
message: `${existing.length}
|
|
782
|
+
message: `${existing.length} theme(es) already installed. Overwrite?`
|
|
596
783
|
});
|
|
597
784
|
if (p.isCancel(overwrite) || !overwrite) {
|
|
598
785
|
p.cancel("Cancelled.");
|
|
@@ -601,23 +788,23 @@ async function addFromRegistry(options) {
|
|
|
601
788
|
}
|
|
602
789
|
}
|
|
603
790
|
const dl = p.spinner();
|
|
604
|
-
dl.start(`Downloading ${names.length}
|
|
791
|
+
dl.start(`Downloading ${names.length} theme(es)...`);
|
|
605
792
|
const results = [];
|
|
606
793
|
for (const name of names){
|
|
607
794
|
try {
|
|
608
|
-
const data = await
|
|
609
|
-
if (!
|
|
610
|
-
p.log.warn(`Skipping ${name}: invalid
|
|
795
|
+
const data = await fetchThemeJson(name);
|
|
796
|
+
if (!validateTheme(data)) {
|
|
797
|
+
p.log.warn(`Skipping ${name}: invalid theme format`);
|
|
611
798
|
continue;
|
|
612
799
|
}
|
|
613
|
-
await
|
|
800
|
+
await writeTheme(name, data);
|
|
614
801
|
results.push(data.name);
|
|
615
802
|
} catch (err) {
|
|
616
803
|
p.log.warn(`Failed to download ${name}: ${err}`);
|
|
617
804
|
}
|
|
618
805
|
}
|
|
619
|
-
dl.stop(`Downloaded ${results.length}
|
|
620
|
-
p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed
|
|
806
|
+
dl.stop(`Downloaded ${results.length} theme(es)`);
|
|
807
|
+
p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed themes");
|
|
621
808
|
p.outro("Done!");
|
|
622
809
|
}
|
|
623
810
|
async function addSoundFromRegistry(soundName, options) {
|
|
@@ -629,7 +816,7 @@ async function addSoundFromRegistry(soundName, options) {
|
|
|
629
816
|
s.start(`Finding "${soundName}"...`);
|
|
630
817
|
let index;
|
|
631
818
|
try {
|
|
632
|
-
index = await
|
|
819
|
+
index = await fetchThemeIndex();
|
|
633
820
|
} catch (err) {
|
|
634
821
|
s.stop("Failed to fetch theme index.");
|
|
635
822
|
p.log.error(String(err));
|
|
@@ -638,8 +825,8 @@ async function addSoundFromRegistry(soundName, options) {
|
|
|
638
825
|
let found;
|
|
639
826
|
for (const entry of index){
|
|
640
827
|
try {
|
|
641
|
-
const data = await
|
|
642
|
-
if (!
|
|
828
|
+
const data = await fetchThemeJson(entry.name);
|
|
829
|
+
if (!validateTheme(data)) continue;
|
|
643
830
|
const match = Object.entries(data.sounds).find(([name])=>name.toLowerCase() === soundName.toLowerCase());
|
|
644
831
|
if (match) {
|
|
645
832
|
found = {
|
|
@@ -660,20 +847,20 @@ async function addSoundFromRegistry(soundName, options) {
|
|
|
660
847
|
p.note(` - ${soundName}`, "Installed sound");
|
|
661
848
|
p.outro("Done!");
|
|
662
849
|
}
|
|
663
|
-
function
|
|
850
|
+
function printThemeList(themes) {
|
|
664
851
|
console.log();
|
|
665
|
-
for (const
|
|
666
|
-
const desc =
|
|
667
|
-
console.log(` ${pc.bold(
|
|
852
|
+
for (const theme of themes){
|
|
853
|
+
const desc = theme.description ? ` ${pc.dim(theme.description)}` : "";
|
|
854
|
+
console.log(` ${pc.bold(theme.name)} ${pc.dim(`${theme.soundCount} sounds`)}${desc}`);
|
|
668
855
|
}
|
|
669
856
|
console.log();
|
|
670
857
|
}
|
|
671
|
-
function
|
|
672
|
-
if (options.
|
|
673
|
-
const
|
|
674
|
-
const match = discovered.filter((d)=>d.name.toLowerCase() ===
|
|
858
|
+
function selectThemes(discovered, options) {
|
|
859
|
+
if (options.theme) {
|
|
860
|
+
const themeName = options.theme;
|
|
861
|
+
const match = discovered.filter((d)=>d.name.toLowerCase() === themeName.toLowerCase());
|
|
675
862
|
if (match.length === 0) {
|
|
676
|
-
p.log.error(`
|
|
863
|
+
p.log.error(`Theme "${themeName}" not found.`);
|
|
677
864
|
process.exit(1);
|
|
678
865
|
}
|
|
679
866
|
return match;
|
|
@@ -681,27 +868,27 @@ function selectPatches(discovered, options) {
|
|
|
681
868
|
if (options.yes) return discovered;
|
|
682
869
|
return discovered;
|
|
683
870
|
}
|
|
684
|
-
async function
|
|
685
|
-
if (options.
|
|
686
|
-
const
|
|
687
|
-
const match = discovered.filter((d)=>d.name.toLowerCase() ===
|
|
871
|
+
async function resolveThemeSelection(discovered, installedNames, options) {
|
|
872
|
+
if (options.theme) {
|
|
873
|
+
const themeName = options.theme;
|
|
874
|
+
const match = discovered.filter((d)=>d.name.toLowerCase() === themeName.toLowerCase());
|
|
688
875
|
if (match.length === 0) {
|
|
689
|
-
p.log.error(`
|
|
876
|
+
p.log.error(`Theme "${themeName}" not found.`);
|
|
690
877
|
process.exit(1);
|
|
691
878
|
}
|
|
692
879
|
return match;
|
|
693
880
|
}
|
|
694
881
|
if (options.yes) return discovered;
|
|
695
882
|
if (discovered.length === 1) return discovered;
|
|
696
|
-
return await
|
|
883
|
+
return await promptThemeSelection(discovered, installedNames);
|
|
697
884
|
}
|
|
698
|
-
async function
|
|
885
|
+
async function promptThemeSelection(discovered, installedNames) {
|
|
699
886
|
const selected = await p.multiselect({
|
|
700
|
-
message: "Select
|
|
701
|
-
options: discovered.map((
|
|
702
|
-
value:
|
|
703
|
-
label: `${
|
|
704
|
-
hint:
|
|
887
|
+
message: "Select themes to install",
|
|
888
|
+
options: discovered.map((theme)=>({
|
|
889
|
+
value: theme.name,
|
|
890
|
+
label: `${theme.name}${installedNames.has(theme.name) ? " (installed)" : ""}`,
|
|
891
|
+
hint: theme.description ? `${theme.soundCount} sounds — ${theme.description}` : `${theme.soundCount} sounds`
|
|
705
892
|
}))
|
|
706
893
|
});
|
|
707
894
|
if (p.isCancel(selected)) {
|
|
@@ -711,21 +898,21 @@ async function promptPatchSelection(discovered, installedNames) {
|
|
|
711
898
|
const names = new Set(selected);
|
|
712
899
|
return discovered.filter((d)=>names.has(d.name));
|
|
713
900
|
}
|
|
714
|
-
async function
|
|
715
|
-
const existing =
|
|
716
|
-
if (existing.length === 0) return
|
|
901
|
+
async function confirmThemeOverwrites(themes, installedNames) {
|
|
902
|
+
const existing = themes.filter((theme)=>installedNames.has(theme.name));
|
|
903
|
+
if (existing.length === 0) return themes;
|
|
717
904
|
const overwrite = await p.confirm({
|
|
718
|
-
message: `${existing.length}
|
|
905
|
+
message: `${existing.length} theme(es) already installed. Overwrite?`
|
|
719
906
|
});
|
|
720
907
|
if (p.isCancel(overwrite) || !overwrite) {
|
|
721
908
|
p.cancel("Cancelled.");
|
|
722
909
|
process.exit(0);
|
|
723
910
|
}
|
|
724
|
-
return
|
|
911
|
+
return themes;
|
|
725
912
|
}
|
|
726
|
-
async function
|
|
913
|
+
async function writeTheme(filename, data) {
|
|
727
914
|
await ensureConfig("themes");
|
|
728
|
-
const dir =
|
|
915
|
+
const dir = getThemesDir();
|
|
729
916
|
if (!existsSync(dir)) {
|
|
730
917
|
mkdirSync(dir, {
|
|
731
918
|
recursive: true
|
|
@@ -761,18 +948,18 @@ async function writeSound(name, definition, options) {
|
|
|
761
948
|
|
|
762
949
|
async function check(_args) {
|
|
763
950
|
p.intro("@litlab/audx check");
|
|
764
|
-
const installed = await
|
|
951
|
+
const installed = await getInstalledThemes();
|
|
765
952
|
if (installed.length === 0) {
|
|
766
|
-
p.log.warn("No
|
|
767
|
-
p.outro("Install
|
|
953
|
+
p.log.warn("No themes installed.");
|
|
954
|
+
p.outro("Install themes with npx @litlab/audx add");
|
|
768
955
|
return;
|
|
769
956
|
}
|
|
770
957
|
const s = p.spinner();
|
|
771
958
|
s.start("Checking for updates...");
|
|
772
959
|
let registry;
|
|
773
960
|
try {
|
|
774
|
-
registry = await
|
|
775
|
-
s.stop(`Checked ${registry.length} registry
|
|
961
|
+
registry = await fetchThemeIndex();
|
|
962
|
+
s.stop(`Checked ${registry.length} registry theme(es)`);
|
|
776
963
|
} catch (err) {
|
|
777
964
|
s.stop("Failed to fetch registry.");
|
|
778
965
|
p.log.error(String(err));
|
|
@@ -793,14 +980,14 @@ async function check(_args) {
|
|
|
793
980
|
}
|
|
794
981
|
}
|
|
795
982
|
if (available.length === 0) {
|
|
796
|
-
p.log.warn("No installed
|
|
983
|
+
p.log.warn("No installed themes found in the registry.");
|
|
797
984
|
p.outro("");
|
|
798
985
|
return;
|
|
799
986
|
}
|
|
800
|
-
p.note(available.map((name)=>` ↑ ${name}`).join("\n"), `${available.length}
|
|
987
|
+
p.note(available.map((name)=>` ↑ ${name}`).join("\n"), `${available.length} theme(es) available`);
|
|
801
988
|
if (notInRegistry.length > 0) {
|
|
802
989
|
p.log.warn([
|
|
803
|
-
`${notInRegistry.length}
|
|
990
|
+
`${notInRegistry.length} theme(es) not found in registry:`,
|
|
804
991
|
...notInRegistry.map((name)=>` • ${name}`)
|
|
805
992
|
].join("\n"));
|
|
806
993
|
}
|
|
@@ -814,15 +1001,15 @@ async function find(args) {
|
|
|
814
1001
|
s.start("Fetching registry...");
|
|
815
1002
|
let index;
|
|
816
1003
|
try {
|
|
817
|
-
index = await
|
|
818
|
-
s.stop(`Found ${index.length}
|
|
1004
|
+
index = await fetchThemeIndex();
|
|
1005
|
+
s.stop(`Found ${index.length} theme(es) in registry`);
|
|
819
1006
|
} catch (err) {
|
|
820
1007
|
s.stop("Failed to fetch registry.");
|
|
821
1008
|
p.log.error(String(err));
|
|
822
1009
|
process.exit(1);
|
|
823
1010
|
}
|
|
824
1011
|
if (index.length === 0) {
|
|
825
|
-
p.log.warn("No
|
|
1012
|
+
p.log.warn("No themes available in the registry.");
|
|
826
1013
|
p.outro("");
|
|
827
1014
|
return;
|
|
828
1015
|
}
|
|
@@ -832,11 +1019,11 @@ async function find(args) {
|
|
|
832
1019
|
return haystack.includes(query);
|
|
833
1020
|
}) : index;
|
|
834
1021
|
if (matches.length === 0) {
|
|
835
|
-
p.log.warn(`No
|
|
1022
|
+
p.log.warn(`No themes found for "${query}"`);
|
|
836
1023
|
p.outro("");
|
|
837
1024
|
return;
|
|
838
1025
|
}
|
|
839
|
-
p.log.info("Install with npx @litlab/audx add --
|
|
1026
|
+
p.log.info("Install with npx @litlab/audx add --theme <name>");
|
|
840
1027
|
for (const entry of matches){
|
|
841
1028
|
const tags = entry.tags && entry.tags.length > 0 ? ` ${entry.tags.join(", ")}` : "";
|
|
842
1029
|
const desc = entry.description ? `\n ${entry.description}` : "";
|
|
@@ -857,8 +1044,8 @@ async function init(args) {
|
|
|
857
1044
|
async function themeInit(_args) {
|
|
858
1045
|
p.intro("@litlab/audx theme init");
|
|
859
1046
|
const name = await p.text({
|
|
860
|
-
message: "
|
|
861
|
-
placeholder: "my-
|
|
1047
|
+
message: "Theme name",
|
|
1048
|
+
placeholder: "my-theme",
|
|
862
1049
|
validate: (v)=>v.length === 0 ? "Name is required" : undefined
|
|
863
1050
|
});
|
|
864
1051
|
if (p.isCancel(name)) {
|
|
@@ -875,7 +1062,7 @@ async function themeInit(_args) {
|
|
|
875
1062
|
}
|
|
876
1063
|
const description = await p.text({
|
|
877
1064
|
message: "Description",
|
|
878
|
-
placeholder: "What does this
|
|
1065
|
+
placeholder: "What does this theme sound like?"
|
|
879
1066
|
});
|
|
880
1067
|
if (p.isCancel(description)) {
|
|
881
1068
|
p.cancel("Cancelled.");
|
|
@@ -899,8 +1086,8 @@ async function themeInit(_args) {
|
|
|
899
1086
|
process.exit(0);
|
|
900
1087
|
}
|
|
901
1088
|
}
|
|
902
|
-
const
|
|
903
|
-
$schema: "../../node_modules/@litlab/audx/schemas/
|
|
1089
|
+
const theme = {
|
|
1090
|
+
$schema: "../../node_modules/@litlab/audx/schemas/theme.schema.json",
|
|
904
1091
|
name: name,
|
|
905
1092
|
author: author || undefined,
|
|
906
1093
|
version: "1.0.0",
|
|
@@ -908,64 +1095,64 @@ async function themeInit(_args) {
|
|
|
908
1095
|
tags: [],
|
|
909
1096
|
sounds: {}
|
|
910
1097
|
};
|
|
911
|
-
await writeFile(target, `${JSON.stringify(
|
|
1098
|
+
await writeFile(target, `${JSON.stringify(theme, null, 2)}\n`, "utf-8");
|
|
912
1099
|
p.log.success(`Created .audx/themes/${filename}`);
|
|
913
1100
|
p.outro("Add sounds to the `sounds` object to get started.");
|
|
914
1101
|
}
|
|
915
1102
|
|
|
916
1103
|
async function list(_args) {
|
|
917
1104
|
p.intro("@litlab/audx list");
|
|
918
|
-
const
|
|
919
|
-
if (
|
|
920
|
-
p.log.warn(`No
|
|
921
|
-
p.outro("Run `@litlab/audx add` to install
|
|
1105
|
+
const themes = await getInstalledThemes();
|
|
1106
|
+
if (themes.length === 0) {
|
|
1107
|
+
p.log.warn(`No themes found in ${getThemesDir()}`);
|
|
1108
|
+
p.outro("Run `@litlab/audx add` to install themes.");
|
|
922
1109
|
return;
|
|
923
1110
|
}
|
|
924
|
-
const rows =
|
|
925
|
-
var
|
|
926
|
-
return ` ${
|
|
1111
|
+
const rows = themes.map((theme)=>{
|
|
1112
|
+
var _theme_description;
|
|
1113
|
+
return ` ${theme.name.padEnd(16)} ${String(theme.soundCount).padStart(3)} sounds ${(_theme_description = theme.description) != null ? _theme_description : ""}`;
|
|
927
1114
|
});
|
|
928
|
-
p.note(rows.join("\n"), `${
|
|
929
|
-
p.outro(
|
|
1115
|
+
p.note(rows.join("\n"), `${themes.length} theme(es) installed`);
|
|
1116
|
+
p.outro(getThemesDir());
|
|
930
1117
|
}
|
|
931
1118
|
|
|
932
1119
|
function parseRemoveOptions(args) {
|
|
933
1120
|
const options = {};
|
|
934
|
-
const
|
|
1121
|
+
const themes = [];
|
|
935
1122
|
for(let i = 0; i < args.length; i++){
|
|
936
1123
|
const arg = args[i];
|
|
937
1124
|
if (arg === "-y" || arg === "--yes") {
|
|
938
1125
|
options.yes = true;
|
|
939
1126
|
} else if (arg && !arg.startsWith("-")) {
|
|
940
|
-
|
|
1127
|
+
themes.push(arg);
|
|
941
1128
|
}
|
|
942
1129
|
}
|
|
943
1130
|
return {
|
|
944
|
-
|
|
1131
|
+
themes,
|
|
945
1132
|
options
|
|
946
1133
|
};
|
|
947
1134
|
}
|
|
948
1135
|
async function remove(args) {
|
|
949
|
-
const {
|
|
1136
|
+
const { themes: themeNames, options } = parseRemoveOptions(args);
|
|
950
1137
|
p.intro("@litlab/audx remove");
|
|
951
|
-
const
|
|
952
|
-
if (
|
|
953
|
-
p.log.warn("No
|
|
1138
|
+
const themes = await getInstalledThemes();
|
|
1139
|
+
if (themes.length === 0) {
|
|
1140
|
+
p.log.warn("No themes installed.");
|
|
954
1141
|
p.outro("Nothing to remove.");
|
|
955
1142
|
return;
|
|
956
1143
|
}
|
|
957
1144
|
let files;
|
|
958
|
-
if (
|
|
959
|
-
const matched =
|
|
1145
|
+
if (themeNames.length > 0) {
|
|
1146
|
+
const matched = themes.filter((pk)=>themeNames.some((n)=>n.toLowerCase() === pk.name.toLowerCase()));
|
|
960
1147
|
if (matched.length === 0) {
|
|
961
|
-
p.log.error(`No matching
|
|
1148
|
+
p.log.error(`No matching themes found for: ${themeNames.join(", ")}`);
|
|
962
1149
|
return;
|
|
963
1150
|
}
|
|
964
1151
|
files = matched.map((pk)=>pk.file);
|
|
965
1152
|
} else {
|
|
966
1153
|
const selected = await p.multiselect({
|
|
967
|
-
message: "Select
|
|
968
|
-
options:
|
|
1154
|
+
message: "Select themes to remove",
|
|
1155
|
+
options: themes.map((pk)=>({
|
|
969
1156
|
value: pk.file,
|
|
970
1157
|
label: pk.name,
|
|
971
1158
|
hint: `${pk.soundCount} sounds`
|
|
@@ -977,50 +1164,50 @@ async function remove(args) {
|
|
|
977
1164
|
}
|
|
978
1165
|
files = selected;
|
|
979
1166
|
if (files.length === 0) {
|
|
980
|
-
p.outro("No
|
|
1167
|
+
p.outro("No themes selected.");
|
|
981
1168
|
return;
|
|
982
1169
|
}
|
|
983
1170
|
}
|
|
984
1171
|
if (!options.yes) {
|
|
985
1172
|
const confirmed = await p.confirm({
|
|
986
|
-
message: `Remove ${files.length}
|
|
1173
|
+
message: `Remove ${files.length} theme(es)?`
|
|
987
1174
|
});
|
|
988
1175
|
if (p.isCancel(confirmed) || !confirmed) {
|
|
989
1176
|
p.cancel("Cancelled.");
|
|
990
1177
|
process.exit(0);
|
|
991
1178
|
}
|
|
992
1179
|
}
|
|
993
|
-
const dir =
|
|
1180
|
+
const dir = getThemesDir();
|
|
994
1181
|
const removed = [];
|
|
995
1182
|
for (const file of files){
|
|
996
1183
|
try {
|
|
997
1184
|
var _ref;
|
|
998
1185
|
await unlink(join(dir, file));
|
|
999
|
-
const pk =
|
|
1186
|
+
const pk = themes.find((item)=>item.file === file);
|
|
1000
1187
|
removed.push((_ref = pk == null ? void 0 : pk.name) != null ? _ref : file);
|
|
1001
1188
|
} catch (err) {
|
|
1002
1189
|
p.log.warn(`Failed to remove ${file}: ${err}`);
|
|
1003
1190
|
}
|
|
1004
1191
|
}
|
|
1005
1192
|
await regenerateIndex(dir);
|
|
1006
|
-
p.note(removed.map((n)=>` - ${n}`).join("\n"), "Removed
|
|
1193
|
+
p.note(removed.map((n)=>` - ${n}`).join("\n"), "Removed themes");
|
|
1007
1194
|
p.outro("Done!");
|
|
1008
1195
|
}
|
|
1009
1196
|
|
|
1010
1197
|
async function update(_args) {
|
|
1011
1198
|
p.intro("@litlab/audx update");
|
|
1012
|
-
const installed = await
|
|
1199
|
+
const installed = await getInstalledThemes();
|
|
1013
1200
|
if (installed.length === 0) {
|
|
1014
|
-
p.log.warn("No
|
|
1015
|
-
p.outro("Install
|
|
1201
|
+
p.log.warn("No themes installed.");
|
|
1202
|
+
p.outro("Install themes with npx @litlab/audx add");
|
|
1016
1203
|
return;
|
|
1017
1204
|
}
|
|
1018
1205
|
const s = p.spinner();
|
|
1019
1206
|
s.start("Fetching registry...");
|
|
1020
1207
|
let registry;
|
|
1021
1208
|
try {
|
|
1022
|
-
registry = await
|
|
1023
|
-
s.stop(`Found ${registry.length} registry
|
|
1209
|
+
registry = await fetchThemeIndex();
|
|
1210
|
+
s.stop(`Found ${registry.length} registry theme(es)`);
|
|
1024
1211
|
} catch (err) {
|
|
1025
1212
|
s.stop("Failed to fetch registry.");
|
|
1026
1213
|
p.log.error(String(err));
|
|
@@ -1032,15 +1219,15 @@ async function update(_args) {
|
|
|
1032
1219
|
]));
|
|
1033
1220
|
const toUpdate = installed.filter((pk)=>registryMap.has(pk.name.toLowerCase()));
|
|
1034
1221
|
if (toUpdate.length === 0) {
|
|
1035
|
-
p.log.warn("No installed
|
|
1222
|
+
p.log.warn("No installed themes found in the registry.");
|
|
1036
1223
|
p.outro("");
|
|
1037
1224
|
return;
|
|
1038
1225
|
}
|
|
1039
1226
|
const dl = p.spinner();
|
|
1040
|
-
dl.start(`Updating ${toUpdate.length}
|
|
1227
|
+
dl.start(`Updating ${toUpdate.length} theme(es)...`);
|
|
1041
1228
|
let successCount = 0;
|
|
1042
1229
|
let failCount = 0;
|
|
1043
|
-
const dir =
|
|
1230
|
+
const dir = getThemesDir();
|
|
1044
1231
|
if (!existsSync(dir)) {
|
|
1045
1232
|
mkdirSync(dir, {
|
|
1046
1233
|
recursive: true
|
|
@@ -1048,8 +1235,8 @@ async function update(_args) {
|
|
|
1048
1235
|
}
|
|
1049
1236
|
for (const entry of toUpdate){
|
|
1050
1237
|
try {
|
|
1051
|
-
const data = await
|
|
1052
|
-
if (!
|
|
1238
|
+
const data = await fetchThemeJson(entry.name);
|
|
1239
|
+
if (!validateTheme(data)) {
|
|
1053
1240
|
failCount++;
|
|
1054
1241
|
continue;
|
|
1055
1242
|
}
|
|
@@ -1063,9 +1250,9 @@ async function update(_args) {
|
|
|
1063
1250
|
}
|
|
1064
1251
|
}
|
|
1065
1252
|
await regenerateIndex(dir);
|
|
1066
|
-
dl.stop(`Updated ${successCount}
|
|
1253
|
+
dl.stop(`Updated ${successCount} theme(es)`);
|
|
1067
1254
|
if (failCount > 0) {
|
|
1068
|
-
p.log.warn(`Failed to update ${failCount}
|
|
1255
|
+
p.log.warn(`Failed to update ${failCount} theme(es)`);
|
|
1069
1256
|
}
|
|
1070
1257
|
p.outro("Done!");
|
|
1071
1258
|
}
|
|
@@ -1100,19 +1287,19 @@ const COMMANDS = {
|
|
|
1100
1287
|
};
|
|
1101
1288
|
function showBanner() {
|
|
1102
1289
|
p.intro("@litlab/audx");
|
|
1103
|
-
p.log.message("Manage sound
|
|
1290
|
+
p.log.message("Manage sound themes for your project.");
|
|
1104
1291
|
p.log.message([
|
|
1105
|
-
"
|
|
1292
|
+
"Themes",
|
|
1106
1293
|
" add [sound] Install an individual sound",
|
|
1107
1294
|
" add Browse and install themes",
|
|
1108
|
-
" find [query] Search for
|
|
1109
|
-
" list List installed
|
|
1110
|
-
" remove Remove installed
|
|
1295
|
+
" find [query] Search for themes",
|
|
1296
|
+
" list List installed themes",
|
|
1297
|
+
" remove Remove installed themes"
|
|
1111
1298
|
].join("\n"));
|
|
1112
1299
|
p.log.message([
|
|
1113
1300
|
"Updates",
|
|
1114
1301
|
" check Check for updates",
|
|
1115
|
-
" update Update installed
|
|
1302
|
+
" update Update installed themes"
|
|
1116
1303
|
].join("\n"));
|
|
1117
1304
|
p.log.message([
|
|
1118
1305
|
"Project",
|
|
@@ -1126,17 +1313,17 @@ function showHelp() {
|
|
|
1126
1313
|
p.log.message([
|
|
1127
1314
|
"Usage: @litlab/audx <command> [options]",
|
|
1128
1315
|
"",
|
|
1129
|
-
"Manage
|
|
1316
|
+
"Manage Themes:",
|
|
1130
1317
|
" add [sound] Install an individual sound",
|
|
1131
1318
|
" add Browse and install themes",
|
|
1132
1319
|
" add <source> Install themes from a source",
|
|
1133
|
-
" find [query] Search for
|
|
1134
|
-
" list, ls List installed
|
|
1135
|
-
" remove, rm Remove installed
|
|
1320
|
+
" find [query] Search for themes in the registry",
|
|
1321
|
+
" list, ls List installed themes",
|
|
1322
|
+
" remove, rm Remove installed themes",
|
|
1136
1323
|
"",
|
|
1137
1324
|
"Updates:",
|
|
1138
1325
|
" check Check for available updates",
|
|
1139
|
-
" update Update all installed
|
|
1326
|
+
" update Update all installed themes",
|
|
1140
1327
|
"",
|
|
1141
1328
|
"Project:",
|
|
1142
1329
|
" init Set up AudX and install themes",
|
|
@@ -1144,9 +1331,11 @@ function showHelp() {
|
|
|
1144
1331
|
].join("\n"));
|
|
1145
1332
|
p.log.message([
|
|
1146
1333
|
"Add Options:",
|
|
1147
|
-
" -l, --list Preview available
|
|
1334
|
+
" -l, --list Preview available themes without installing",
|
|
1148
1335
|
" -y, --yes Skip confirmation prompts",
|
|
1149
|
-
" --
|
|
1336
|
+
" --theme <name> Install a specific theme by name",
|
|
1337
|
+
" --data <value> Install an encoded customized sound definition",
|
|
1338
|
+
" --tune <token> Apply compact editor settings (requires --theme)",
|
|
1150
1339
|
"",
|
|
1151
1340
|
"Remove Options:",
|
|
1152
1341
|
" -y, --yes Skip confirmation prompts"
|
|
@@ -1156,7 +1345,7 @@ function showHelp() {
|
|
|
1156
1345
|
" ./local/path Local file or directory",
|
|
1157
1346
|
" owner/repo GitHub shorthand",
|
|
1158
1347
|
" https://github.com/user/repo Full GitHub URL",
|
|
1159
|
-
" https://...
|
|
1348
|
+
" https://...theme.json Direct URL to a theme file",
|
|
1160
1349
|
" (no argument) Browse the registry"
|
|
1161
1350
|
].join("\n"));
|
|
1162
1351
|
p.log.message([
|
|
@@ -1168,7 +1357,7 @@ function showHelp() {
|
|
|
1168
1357
|
" @litlab/audx add ommgh/audio",
|
|
1169
1358
|
" @litlab/audx add ./.themes/",
|
|
1170
1359
|
" @litlab/audx add ommgh/audio --list",
|
|
1171
|
-
" @litlab/audx add --
|
|
1360
|
+
" @litlab/audx add --theme core -y",
|
|
1172
1361
|
" @litlab/audx remove core -y",
|
|
1173
1362
|
" @litlab/audx find ambient",
|
|
1174
1363
|
" @litlab/audx check",
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
function _extends() {
|
|
2
|
+
_extends = Object.assign || function assign(target) {
|
|
3
|
+
for(var i = 1; i < arguments.length; i++){
|
|
4
|
+
var source = arguments[i];
|
|
5
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
6
|
+
}
|
|
7
|
+
return target;
|
|
8
|
+
};
|
|
9
|
+
return _extends.apply(this, arguments);
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
function _object_without_properties_loose(source, excluded) {
|
|
2
13
|
if (source == null) return {};
|
|
3
14
|
var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
|
|
@@ -10,4 +21,4 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
10
21
|
return target;
|
|
11
22
|
}
|
|
12
23
|
|
|
13
|
-
export {
|
|
24
|
+
export { _extends as _, _object_without_properties_loose as a };
|
package/dist/index.js
CHANGED
|
@@ -1293,7 +1293,9 @@ function createPatchInstance(data) {
|
|
|
1293
1293
|
* @throws {Error} If the network request fails
|
|
1294
1294
|
*/ async function loadPatch(source) {
|
|
1295
1295
|
if (typeof source === "string") {
|
|
1296
|
-
const response = await fetch(source
|
|
1296
|
+
const response = await fetch(source, {
|
|
1297
|
+
cache: "no-store"
|
|
1298
|
+
});
|
|
1297
1299
|
if (!response.ok) throw new Error(`Failed to load patch from ${source}: ${response.status}`);
|
|
1298
1300
|
const data = await response.json();
|
|
1299
1301
|
return createPatchInstance(data);
|
package/dist/react.js
CHANGED
|
@@ -1149,7 +1149,9 @@ function createPatchInstance(data) {
|
|
|
1149
1149
|
* @throws {Error} If the network request fails
|
|
1150
1150
|
*/ async function loadPatch(source) {
|
|
1151
1151
|
if (typeof source === "string") {
|
|
1152
|
-
const response = await fetch(source
|
|
1152
|
+
const response = await fetch(source, {
|
|
1153
|
+
cache: "no-store"
|
|
1154
|
+
});
|
|
1153
1155
|
if (!response.ok) throw new Error(`Failed to load patch from ${source}: ${response.status}`);
|
|
1154
1156
|
const data = await response.json();
|
|
1155
1157
|
return createPatchInstance(data);
|
package/package.json
CHANGED
package/schemas/pack.schema.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://audx.site/schemas/
|
|
4
|
-
"title": "@litlab/audx Sound
|
|
5
|
-
"description": "Schema for @litlab/audx sound
|
|
3
|
+
"$id": "https://audx.site/schemas/theme.schema.json",
|
|
4
|
+
"title": "@litlab/audx Sound Theme",
|
|
5
|
+
"description": "Schema for @litlab/audx sound theme JSON files",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"required": ["name", "sounds"],
|
|
8
8
|
"properties": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"name": {
|
|
13
13
|
"type": "string",
|
|
14
|
-
"description": "Display name of the
|
|
14
|
+
"description": "Display name of the theme"
|
|
15
15
|
},
|
|
16
16
|
"author": {
|
|
17
17
|
"type": "string"
|