@litlab/audx 0.5.5 → 0.6.0

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 CHANGED
@@ -37,58 +37,58 @@ beep();
37
37
  click();
38
38
  ```
39
39
 
40
- ### Sound patches (React)
40
+ ### Sound themes (React)
41
41
 
42
42
  ```tsx
43
- import { usePatch } from "@litlab/audx/react";
43
+ import { useTheme } from "@litlab/audx/react";
44
44
 
45
45
  function App() {
46
- const patch = usePatch("/patches/core.json");
46
+ const theme = useTheme("/themes/core.json");
47
47
 
48
48
  return (
49
- <button onClick={() => patch.play("click")} disabled={!patch.ready}>
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 patches (vanilla)
56
+ ### Sound themes (vanilla)
57
57
 
58
58
  ```ts
59
- import { loadPatch } from "@litlab/audx";
59
+ import { loadTheme } from "@litlab/audx";
60
60
 
61
- const patch = await loadPatch("/patches/core.json");
62
- patch.play("click");
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 patches from the registry
68
+ # Browse and install themes from the registry
69
69
  npx @litlab/audx add
70
70
 
71
- # Install patches from a GitHub repo
71
+ # Install themes from a GitHub repo
72
72
  npx @litlab/audx add user/repo
73
73
 
74
- # Create a new sound patch
74
+ # Create a new sound theme
75
75
  npx @litlab/audx init
76
76
 
77
- # List installed patches
77
+ # List installed themes
78
78
  npx @litlab/audx list
79
79
 
80
- # Remove installed patches
80
+ # Remove installed themes
81
81
  npx @litlab/audx remove
82
82
  ```
83
83
 
84
- ## Patch authoring
84
+ ## Theme authoring
85
85
 
86
- Create a patch JSON file with `npx @litlab/audx init`, then add sound definitions to the `sounds` object:
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/patch.schema.json",
91
- "name": "my-patch",
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
- | `loadPatch(url)` | Load a sound patch from a URL |
120
- | `definePatch(json)` | Create a patch from a JSON object |
121
- | `usePatch(url)` | React hook for loading and playing patches |
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
@@ -97,7 +97,7 @@ function normalizeConfigOutput(output, context) {
97
97
  }
98
98
  return normalized;
99
99
  }
100
- function getPatchesDir() {
100
+ function getThemesDir() {
101
101
  var _ref;
102
102
  const config = getConfig();
103
103
  const output = (_ref = config == null ? void 0 : config.output) != null ? _ref : "src/audio";
@@ -132,7 +132,7 @@ function parseGitHubSource(source) {
132
132
  }
133
133
  return null;
134
134
  }
135
- async function discoverPatchesFromGitHub(source) {
135
+ async function discoverThemesFromGitHub(source) {
136
136
  const parsed = parseGitHubSource(source);
137
137
  if (!parsed) {
138
138
  throw new Error(`Invalid source: ${source}. Use owner/repo or a GitHub URL.`);
@@ -157,15 +157,15 @@ async function discoverPatchesFromGitHub(source) {
157
157
  if (item.path.includes(".changeset/")) return false;
158
158
  return true;
159
159
  });
160
- const patches = [];
160
+ const themes = [];
161
161
  for (const file of jsonFiles){
162
162
  const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/${file.path}`;
163
163
  try {
164
164
  const r = await fetch(rawUrl);
165
165
  if (!r.ok) continue;
166
166
  const data = await r.json();
167
- if (!validatePatch(data)) continue;
168
- patches.push({
167
+ if (!validateTheme(data)) continue;
168
+ themes.push({
169
169
  name: data.name,
170
170
  path: file.path,
171
171
  downloadUrl: rawUrl,
@@ -174,7 +174,7 @@ async function discoverPatchesFromGitHub(source) {
174
174
  });
175
175
  } catch (unused) {}
176
176
  }
177
- return patches;
177
+ return themes;
178
178
  }
179
179
  function isGitHubSource(source) {
180
180
  return parseGitHubSource(source) !== null;
@@ -186,13 +186,13 @@ function isLocalSource(source) {
186
186
  const abs = isAbsolute(source) ? source : resolve(process.cwd(), source);
187
187
  return existsSync(abs);
188
188
  }
189
- async function discoverPatchesFromLocal(source) {
189
+ async function discoverThemesFromLocal(source) {
190
190
  const abs = isAbsolute(source) ? source : resolve(process.cwd(), source);
191
191
  if (abs.endsWith(".json")) {
192
192
  const raw = await readFile(abs, "utf-8");
193
193
  const data = JSON.parse(raw);
194
- if (!validatePatch(data)) {
195
- throw new Error(`${source} is not a valid sound patch.`);
194
+ if (!validateTheme(data)) {
195
+ throw new Error(`${source} is not a valid sound theme.`);
196
196
  }
197
197
  return [
198
198
  {
@@ -205,15 +205,15 @@ async function discoverPatchesFromLocal(source) {
205
205
  ];
206
206
  }
207
207
  const files = await readdir(abs);
208
- const patches = [];
208
+ const themes = [];
209
209
  for (const file of files){
210
210
  if (!file.endsWith(".json") || file === "index.json") continue;
211
211
  try {
212
212
  const filePath = join(abs, file);
213
213
  const raw = await readFile(filePath, "utf-8");
214
214
  const data = JSON.parse(raw);
215
- if (!validatePatch(data)) continue;
216
- patches.push({
215
+ if (!validateTheme(data)) continue;
216
+ themes.push({
217
217
  name: data.name,
218
218
  path: filePath,
219
219
  downloadUrl: filePath,
@@ -222,26 +222,26 @@ async function discoverPatchesFromLocal(source) {
222
222
  });
223
223
  } catch (unused) {}
224
224
  }
225
- return patches;
225
+ return themes;
226
226
  }
227
- async function fetchPatchIndex() {
228
- const res = await fetch(`${REGISTRY_BASE}/patches`);
227
+ async function fetchThemeIndex() {
228
+ const res = await fetch(`${REGISTRY_BASE}/audio/themes`);
229
229
  if (!res.ok) {
230
- throw new Error(`Failed to fetch patch index: ${res.status}`);
230
+ throw new Error(`Failed to fetch theme index: ${res.status}`);
231
231
  }
232
232
  return res.json();
233
233
  }
234
- async function fetchPatchJson(nameOrUrl) {
235
- const url = nameOrUrl.startsWith("http") ? nameOrUrl : `${REGISTRY_BASE}/patch/${nameOrUrl}`;
234
+ async function fetchThemeJson(nameOrUrl) {
235
+ const url = nameOrUrl.startsWith("http") ? nameOrUrl : `${REGISTRY_BASE}/audio/theme/${nameOrUrl}`;
236
236
  const res = await fetch(url);
237
237
  if (!res.ok) {
238
- throw new Error(`Failed to fetch patch: ${res.status}`);
238
+ throw new Error(`Failed to fetch theme: ${res.status}`);
239
239
  }
240
240
  return res.json();
241
241
  }
242
- async function registerPatch(url) {
242
+ async function registerTheme(url) {
243
243
  try {
244
- await fetch(`${REGISTRY_BASE}/patches`, {
244
+ await fetch(`${REGISTRY_BASE}/audio/themes`, {
245
245
  method: "POST",
246
246
  headers: {
247
247
  "Content-Type": "application/json"
@@ -252,30 +252,30 @@ async function registerPatch(url) {
252
252
  });
253
253
  } catch (unused) {}
254
254
  }
255
- function validatePatch(data) {
255
+ function validateTheme(data) {
256
256
  return typeof data.name === "string" && typeof data.sounds === "object" && data.sounds !== null;
257
257
  }
258
- async function getInstalledPatches() {
259
- const dir = getPatchesDir();
258
+ async function getInstalledThemes() {
259
+ const dir = getThemesDir();
260
260
  if (!existsSync(dir)) return [];
261
261
  const files = await readdir(dir);
262
- const patches = [];
262
+ const themes = [];
263
263
  for (const file of files){
264
264
  if (!file.endsWith(".ts") || file === "index.ts") continue;
265
265
  try {
266
266
  var _raw_match, _ref;
267
267
  const raw = await readFile(join(dir, file), "utf-8");
268
- const nameMatch = raw.match(/^\/\/ patch: (.+)$/m);
268
+ const nameMatch = raw.match(/^\/\/ theme: (.+)$/m);
269
269
  const exportCount = ((_raw_match = raw.match(/^export const /gm)) != null ? _raw_match : []).length;
270
270
  const name = (_ref = nameMatch == null ? void 0 : nameMatch[1]) != null ? _ref : basename(file, ".ts");
271
- patches.push({
271
+ themes.push({
272
272
  file,
273
273
  name,
274
274
  soundCount: Math.max(0, exportCount - 1)
275
275
  });
276
276
  } catch (unused) {}
277
277
  }
278
- return patches;
278
+ return themes;
279
279
  }
280
280
  const RESERVED = new Set([
281
281
  "break",
@@ -335,7 +335,7 @@ function generateModule(data) {
335
335
  const ids = entries.map(([key])=>toCamelCase(key));
336
336
  const lines = [
337
337
  `// ${data.name} — generated by @litlab/audx (do not edit)`,
338
- `// patch: ${data.name}`,
338
+ `// theme: ${data.name}`,
339
339
  `import type { SoundDefinition, SoundPatch } from "@litlab/audx";`,
340
340
  ""
341
341
  ];
@@ -384,8 +384,8 @@ function parseAddOptions(args) {
384
384
  options.yes = true;
385
385
  } else if (arg === "-l" || arg === "--list") {
386
386
  options.list = true;
387
- } else if (arg === "--patch") {
388
- options.patch = args[++i];
387
+ } else if (arg === "--theme") {
388
+ options.theme = args[++i];
389
389
  } else if (arg && !arg.startsWith("-")) {
390
390
  source = arg;
391
391
  }
@@ -418,106 +418,106 @@ async function add(args) {
418
418
  }
419
419
  async function addFromLocal(source, options) {
420
420
  const s = p.spinner();
421
- s.start("Scanning local path for patches...");
421
+ s.start("Scanning local path for themes...");
422
422
  let discovered;
423
423
  try {
424
- discovered = await discoverPatchesFromLocal(source);
425
- s.stop(`Found ${discovered.length} patch(es)`);
424
+ discovered = await discoverThemesFromLocal(source);
425
+ s.stop(`Found ${discovered.length} theme(es)`);
426
426
  } catch (err) {
427
427
  s.stop("Failed to scan local path.");
428
428
  p.log.error(String(err));
429
429
  process.exit(1);
430
430
  }
431
431
  if (discovered.length === 0) {
432
- p.log.warn("No valid sound patches found at this path.");
433
- p.outro("Patches must be JSON files with a name and sounds object.");
432
+ p.log.warn("No valid sound themes found at this path.");
433
+ p.outro("Themes must be JSON files with a name and sounds object.");
434
434
  return;
435
435
  }
436
436
  if (options.list) {
437
- printPatchList(discovered);
437
+ printThemeList(discovered);
438
438
  return;
439
439
  }
440
- const toInstall = selectPatches(discovered, options);
440
+ const toInstall = selectThemes(discovered, options);
441
441
  if (!toInstall || toInstall.length === 0) return;
442
- const installed = await getInstalledPatches();
442
+ const installed = await getInstalledThemes();
443
443
  const installedNames = new Set(installed.map((p)=>p.name));
444
- const final = options.yes ? toInstall : await confirmOverwrites(toInstall, installedNames);
444
+ const final = options.yes ? toInstall : await confirmThemeOverwrites(toInstall, installedNames);
445
445
  if (!final || final.length === 0) return;
446
446
  const dl = p.spinner();
447
- dl.start(`Installing ${final.length} patch(es)...`);
447
+ dl.start(`Installing ${final.length} theme(es)...`);
448
448
  const results = [];
449
- for (const patch of final){
449
+ for (const theme of final){
450
450
  try {
451
- const raw = await readFile(patch.downloadUrl, "utf-8");
451
+ const raw = await readFile(theme.downloadUrl, "utf-8");
452
452
  const data = JSON.parse(raw);
453
- if (!validatePatch(data)) {
454
- p.log.warn(`Skipping ${patch.name}: invalid patch format`);
453
+ if (!validateTheme(data)) {
454
+ p.log.warn(`Skipping ${theme.name}: invalid theme format`);
455
455
  continue;
456
456
  }
457
- await writePatch(patch.name, data);
457
+ await writeTheme(theme.name, data);
458
458
  results.push(data.name);
459
459
  } catch (err) {
460
- p.log.warn(`Failed to install ${patch.name}: ${err}`);
460
+ p.log.warn(`Failed to install ${theme.name}: ${err}`);
461
461
  }
462
462
  }
463
- dl.stop(`Installed ${results.length} patch(es)`);
464
- p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed patches");
463
+ dl.stop(`Installed ${results.length} theme(es)`);
464
+ p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed themes");
465
465
  p.outro("Done!");
466
466
  }
467
467
  async function addFromGitHub(source, options) {
468
468
  const s = p.spinner();
469
- s.start("Scanning repository for patches...");
469
+ s.start("Scanning repository for themes...");
470
470
  let discovered;
471
471
  try {
472
- discovered = await discoverPatchesFromGitHub(source);
473
- s.stop(`Found ${discovered.length} patch(es)`);
472
+ discovered = await discoverThemesFromGitHub(source);
473
+ s.stop(`Found ${discovered.length} theme(es)`);
474
474
  } catch (err) {
475
475
  s.stop("Failed to scan repository.");
476
476
  p.log.error(String(err));
477
477
  process.exit(1);
478
478
  }
479
479
  if (discovered.length === 0) {
480
- p.log.warn("No valid sound patches found in this repository.");
481
- p.outro("Patches must be JSON files with a name and sounds object.");
480
+ p.log.warn("No valid sound themes found in this repository.");
481
+ p.outro("Themes must be JSON files with a name and sounds object.");
482
482
  return;
483
483
  }
484
484
  if (options.list) {
485
- printPatchList(discovered);
485
+ printThemeList(discovered);
486
486
  return;
487
487
  }
488
- const installed = await getInstalledPatches();
488
+ const installed = await getInstalledThemes();
489
489
  const installedNames = new Set(installed.map((p)=>p.name));
490
- const toInstall = await resolvePatchSelection(discovered, installedNames, options);
490
+ const toInstall = await resolveThemeSelection(discovered, installedNames, options);
491
491
  if (!toInstall || toInstall.length === 0) return;
492
492
  const dl = p.spinner();
493
- dl.start(`Installing ${toInstall.length} patch(es)...`);
493
+ dl.start(`Installing ${toInstall.length} theme(es)...`);
494
494
  const results = [];
495
- for (const patch of toInstall){
495
+ for (const theme of toInstall){
496
496
  try {
497
- const data = await fetchPatchJson(patch.downloadUrl);
498
- if (!validatePatch(data)) {
499
- p.log.warn(`Skipping ${patch.name}: invalid patch format`);
497
+ const data = await fetchThemeJson(theme.downloadUrl);
498
+ if (!validateTheme(data)) {
499
+ p.log.warn(`Skipping ${theme.name}: invalid theme format`);
500
500
  continue;
501
501
  }
502
- await writePatch(patch.name, data);
503
- registerPatch(patch.downloadUrl);
502
+ await writeTheme(theme.name, data);
503
+ registerTheme(theme.downloadUrl);
504
504
  results.push(data.name);
505
505
  } catch (err) {
506
- p.log.warn(`Failed to install ${patch.name}: ${err}`);
506
+ p.log.warn(`Failed to install ${theme.name}: ${err}`);
507
507
  }
508
508
  }
509
- dl.stop(`Installed ${results.length} patch(es)`);
510
- p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed patches");
509
+ dl.stop(`Installed ${results.length} theme(es)`);
510
+ p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed themes");
511
511
  p.outro("Done!");
512
512
  }
513
513
  async function addFromUrl(url, options) {
514
514
  const s = p.spinner();
515
- s.start("Fetching patch...");
515
+ s.start("Fetching theme...");
516
516
  try {
517
- const data = await fetchPatchJson(url);
518
- if (!validatePatch(data)) {
519
- s.stop("Invalid patch format.");
520
- p.log.error("The fetched JSON is not a valid sound patch (missing name or sounds).");
517
+ const data = await fetchThemeJson(url);
518
+ if (!validateTheme(data)) {
519
+ s.stop("Invalid theme format.");
520
+ p.log.error("The fetched JSON is not a valid sound theme (missing name or sounds).");
521
521
  process.exit(1);
522
522
  }
523
523
  s.stop(`Fetched "${data.name}"`);
@@ -526,23 +526,23 @@ async function addFromUrl(url, options) {
526
526
  console.log();
527
527
  return;
528
528
  }
529
- await writePatch(data.name, data);
530
- registerPatch(url);
529
+ await writeTheme(data.name, data);
530
+ registerTheme(url);
531
531
  } catch (err) {
532
- s.stop("Failed to fetch patch.");
532
+ s.stop("Failed to fetch theme.");
533
533
  p.log.error(String(err));
534
534
  process.exit(1);
535
535
  }
536
536
  }
537
537
  async function addFromRegistry(options) {
538
538
  const s = p.spinner();
539
- s.start("Fetching available patches...");
539
+ s.start("Fetching available themes...");
540
540
  let index;
541
541
  try {
542
- index = await fetchPatchIndex();
543
- s.stop(`Found ${index.length} patches`);
542
+ index = await fetchThemeIndex();
543
+ s.stop(`Found ${index.length} themes`);
544
544
  } catch (err) {
545
- s.stop("Failed to fetch patch index.");
545
+ s.stop("Failed to fetch theme index.");
546
546
  p.log.error(String(err));
547
547
  process.exit(1);
548
548
  }
@@ -554,24 +554,24 @@ async function addFromRegistry(options) {
554
554
  console.log();
555
555
  return;
556
556
  }
557
- const installed = await getInstalledPatches();
557
+ const installed = await getInstalledThemes();
558
558
  const installedNames = new Set(installed.map((p)=>p.name));
559
559
  let names;
560
- if (options.patch) {
561
- const patchName = options.patch;
560
+ if (options.theme) {
561
+ const themeName = options.theme;
562
562
  names = [
563
- patchName
563
+ themeName
564
564
  ];
565
- const match = index.find((e)=>e.name.toLowerCase() === patchName.toLowerCase());
565
+ const match = index.find((e)=>e.name.toLowerCase() === themeName.toLowerCase());
566
566
  if (!match) {
567
- p.log.error(`Patch "${patchName}" not found in registry.`);
567
+ p.log.error(`Theme "${themeName}" not found in registry.`);
568
568
  process.exit(1);
569
569
  }
570
570
  } else if (options.yes) {
571
571
  names = index.map((e)=>e.name);
572
572
  } else {
573
573
  const selected = await p.multiselect({
574
- message: "Select patches to install",
574
+ message: "Select themes to install",
575
575
  options: index.map((entry)=>({
576
576
  value: entry.name,
577
577
  label: `${entry.name}${installedNames.has(entry.name) ? " (installed)" : ""}`,
@@ -584,7 +584,7 @@ async function addFromRegistry(options) {
584
584
  }
585
585
  names = selected;
586
586
  if (names.length === 0) {
587
- p.outro("No patches selected.");
587
+ p.outro("No themes selected.");
588
588
  return;
589
589
  }
590
590
  }
@@ -592,7 +592,7 @@ async function addFromRegistry(options) {
592
592
  const existing = names.filter((n)=>installedNames.has(n));
593
593
  if (existing.length > 0) {
594
594
  const overwrite = await p.confirm({
595
- message: `${existing.length} patch(es) already installed. Overwrite?`
595
+ message: `${existing.length} theme(es) already installed. Overwrite?`
596
596
  });
597
597
  if (p.isCancel(overwrite) || !overwrite) {
598
598
  p.cancel("Cancelled.");
@@ -601,23 +601,23 @@ async function addFromRegistry(options) {
601
601
  }
602
602
  }
603
603
  const dl = p.spinner();
604
- dl.start(`Downloading ${names.length} patch(es)...`);
604
+ dl.start(`Downloading ${names.length} theme(es)...`);
605
605
  const results = [];
606
606
  for (const name of names){
607
607
  try {
608
- const data = await fetchPatchJson(name);
609
- if (!validatePatch(data)) {
610
- p.log.warn(`Skipping ${name}: invalid patch format`);
608
+ const data = await fetchThemeJson(name);
609
+ if (!validateTheme(data)) {
610
+ p.log.warn(`Skipping ${name}: invalid theme format`);
611
611
  continue;
612
612
  }
613
- await writePatch(name, data);
613
+ await writeTheme(name, data);
614
614
  results.push(data.name);
615
615
  } catch (err) {
616
616
  p.log.warn(`Failed to download ${name}: ${err}`);
617
617
  }
618
618
  }
619
- dl.stop(`Downloaded ${results.length} patch(es)`);
620
- p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed patches");
619
+ dl.stop(`Downloaded ${results.length} theme(es)`);
620
+ p.note(results.map((n)=>` - ${n}`).join("\n"), "Installed themes");
621
621
  p.outro("Done!");
622
622
  }
623
623
  async function addSoundFromRegistry(soundName, options) {
@@ -629,7 +629,7 @@ async function addSoundFromRegistry(soundName, options) {
629
629
  s.start(`Finding "${soundName}"...`);
630
630
  let index;
631
631
  try {
632
- index = await fetchPatchIndex();
632
+ index = await fetchThemeIndex();
633
633
  } catch (err) {
634
634
  s.stop("Failed to fetch theme index.");
635
635
  p.log.error(String(err));
@@ -638,8 +638,8 @@ async function addSoundFromRegistry(soundName, options) {
638
638
  let found;
639
639
  for (const entry of index){
640
640
  try {
641
- const data = await fetchPatchJson(entry.name);
642
- if (!validatePatch(data)) continue;
641
+ const data = await fetchThemeJson(entry.name);
642
+ if (!validateTheme(data)) continue;
643
643
  const match = Object.entries(data.sounds).find(([name])=>name.toLowerCase() === soundName.toLowerCase());
644
644
  if (match) {
645
645
  found = {
@@ -660,20 +660,20 @@ async function addSoundFromRegistry(soundName, options) {
660
660
  p.note(` - ${soundName}`, "Installed sound");
661
661
  p.outro("Done!");
662
662
  }
663
- function printPatchList(patches) {
663
+ function printThemeList(themes) {
664
664
  console.log();
665
- for (const patch of patches){
666
- const desc = patch.description ? ` ${pc.dim(patch.description)}` : "";
667
- console.log(` ${pc.bold(patch.name)} ${pc.dim(`${patch.soundCount} sounds`)}${desc}`);
665
+ for (const theme of themes){
666
+ const desc = theme.description ? ` ${pc.dim(theme.description)}` : "";
667
+ console.log(` ${pc.bold(theme.name)} ${pc.dim(`${theme.soundCount} sounds`)}${desc}`);
668
668
  }
669
669
  console.log();
670
670
  }
671
- function selectPatches(discovered, options) {
672
- if (options.patch) {
673
- const patchName = options.patch;
674
- const match = discovered.filter((d)=>d.name.toLowerCase() === patchName.toLowerCase());
671
+ function selectThemes(discovered, options) {
672
+ if (options.theme) {
673
+ const themeName = options.theme;
674
+ const match = discovered.filter((d)=>d.name.toLowerCase() === themeName.toLowerCase());
675
675
  if (match.length === 0) {
676
- p.log.error(`Patch "${patchName}" not found.`);
676
+ p.log.error(`Theme "${themeName}" not found.`);
677
677
  process.exit(1);
678
678
  }
679
679
  return match;
@@ -681,27 +681,27 @@ function selectPatches(discovered, options) {
681
681
  if (options.yes) return discovered;
682
682
  return discovered;
683
683
  }
684
- async function resolvePatchSelection(discovered, installedNames, options) {
685
- if (options.patch) {
686
- const patchName = options.patch;
687
- const match = discovered.filter((d)=>d.name.toLowerCase() === patchName.toLowerCase());
684
+ async function resolveThemeSelection(discovered, installedNames, options) {
685
+ if (options.theme) {
686
+ const themeName = options.theme;
687
+ const match = discovered.filter((d)=>d.name.toLowerCase() === themeName.toLowerCase());
688
688
  if (match.length === 0) {
689
- p.log.error(`Patch "${patchName}" not found.`);
689
+ p.log.error(`Theme "${themeName}" not found.`);
690
690
  process.exit(1);
691
691
  }
692
692
  return match;
693
693
  }
694
694
  if (options.yes) return discovered;
695
695
  if (discovered.length === 1) return discovered;
696
- return await promptPatchSelection(discovered, installedNames);
696
+ return await promptThemeSelection(discovered, installedNames);
697
697
  }
698
- async function promptPatchSelection(discovered, installedNames) {
698
+ async function promptThemeSelection(discovered, installedNames) {
699
699
  const selected = await p.multiselect({
700
- message: "Select patches to install",
701
- options: discovered.map((patch)=>({
702
- value: patch.name,
703
- label: `${patch.name}${installedNames.has(patch.name) ? " (installed)" : ""}`,
704
- hint: patch.description ? `${patch.soundCount} sounds — ${patch.description}` : `${patch.soundCount} sounds`
700
+ message: "Select themes to install",
701
+ options: discovered.map((theme)=>({
702
+ value: theme.name,
703
+ label: `${theme.name}${installedNames.has(theme.name) ? " (installed)" : ""}`,
704
+ hint: theme.description ? `${theme.soundCount} sounds — ${theme.description}` : `${theme.soundCount} sounds`
705
705
  }))
706
706
  });
707
707
  if (p.isCancel(selected)) {
@@ -711,21 +711,21 @@ async function promptPatchSelection(discovered, installedNames) {
711
711
  const names = new Set(selected);
712
712
  return discovered.filter((d)=>names.has(d.name));
713
713
  }
714
- async function confirmOverwrites(patches, installedNames) {
715
- const existing = patches.filter((patch)=>installedNames.has(patch.name));
716
- if (existing.length === 0) return patches;
714
+ async function confirmThemeOverwrites(themes, installedNames) {
715
+ const existing = themes.filter((theme)=>installedNames.has(theme.name));
716
+ if (existing.length === 0) return themes;
717
717
  const overwrite = await p.confirm({
718
- message: `${existing.length} patch(es) already installed. Overwrite?`
718
+ message: `${existing.length} theme(es) already installed. Overwrite?`
719
719
  });
720
720
  if (p.isCancel(overwrite) || !overwrite) {
721
721
  p.cancel("Cancelled.");
722
722
  process.exit(0);
723
723
  }
724
- return patches;
724
+ return themes;
725
725
  }
726
- async function writePatch(filename, data) {
726
+ async function writeTheme(filename, data) {
727
727
  await ensureConfig("themes");
728
- const dir = getPatchesDir();
728
+ const dir = getThemesDir();
729
729
  if (!existsSync(dir)) {
730
730
  mkdirSync(dir, {
731
731
  recursive: true
@@ -761,18 +761,18 @@ async function writeSound(name, definition, options) {
761
761
 
762
762
  async function check(_args) {
763
763
  p.intro("@litlab/audx check");
764
- const installed = await getInstalledPatches();
764
+ const installed = await getInstalledThemes();
765
765
  if (installed.length === 0) {
766
- p.log.warn("No patches installed.");
767
- p.outro("Install patches with npx @litlab/audx add");
766
+ p.log.warn("No themes installed.");
767
+ p.outro("Install themes with npx @litlab/audx add");
768
768
  return;
769
769
  }
770
770
  const s = p.spinner();
771
771
  s.start("Checking for updates...");
772
772
  let registry;
773
773
  try {
774
- registry = await fetchPatchIndex();
775
- s.stop(`Checked ${registry.length} registry patch(es)`);
774
+ registry = await fetchThemeIndex();
775
+ s.stop(`Checked ${registry.length} registry theme(es)`);
776
776
  } catch (err) {
777
777
  s.stop("Failed to fetch registry.");
778
778
  p.log.error(String(err));
@@ -793,14 +793,14 @@ async function check(_args) {
793
793
  }
794
794
  }
795
795
  if (available.length === 0) {
796
- p.log.warn("No installed patches found in the registry.");
796
+ p.log.warn("No installed themes found in the registry.");
797
797
  p.outro("");
798
798
  return;
799
799
  }
800
- p.note(available.map((name)=>` ↑ ${name}`).join("\n"), `${available.length} patch(es) available`);
800
+ p.note(available.map((name)=>` ↑ ${name}`).join("\n"), `${available.length} theme(es) available`);
801
801
  if (notInRegistry.length > 0) {
802
802
  p.log.warn([
803
- `${notInRegistry.length} patch(es) not found in registry:`,
803
+ `${notInRegistry.length} theme(es) not found in registry:`,
804
804
  ...notInRegistry.map((name)=>` • ${name}`)
805
805
  ].join("\n"));
806
806
  }
@@ -814,15 +814,15 @@ async function find(args) {
814
814
  s.start("Fetching registry...");
815
815
  let index;
816
816
  try {
817
- index = await fetchPatchIndex();
818
- s.stop(`Found ${index.length} patch(es) in registry`);
817
+ index = await fetchThemeIndex();
818
+ s.stop(`Found ${index.length} theme(es) in registry`);
819
819
  } catch (err) {
820
820
  s.stop("Failed to fetch registry.");
821
821
  p.log.error(String(err));
822
822
  process.exit(1);
823
823
  }
824
824
  if (index.length === 0) {
825
- p.log.warn("No patches available in the registry.");
825
+ p.log.warn("No themes available in the registry.");
826
826
  p.outro("");
827
827
  return;
828
828
  }
@@ -832,11 +832,11 @@ async function find(args) {
832
832
  return haystack.includes(query);
833
833
  }) : index;
834
834
  if (matches.length === 0) {
835
- p.log.warn(`No patches found for "${query}"`);
835
+ p.log.warn(`No themes found for "${query}"`);
836
836
  p.outro("");
837
837
  return;
838
838
  }
839
- p.log.info("Install with npx @litlab/audx add --patch <name>");
839
+ p.log.info("Install with npx @litlab/audx add --theme <name>");
840
840
  for (const entry of matches){
841
841
  const tags = entry.tags && entry.tags.length > 0 ? ` ${entry.tags.join(", ")}` : "";
842
842
  const desc = entry.description ? `\n ${entry.description}` : "";
@@ -857,8 +857,8 @@ async function init(args) {
857
857
  async function themeInit(_args) {
858
858
  p.intro("@litlab/audx theme init");
859
859
  const name = await p.text({
860
- message: "Patch name",
861
- placeholder: "my-patch",
860
+ message: "Theme name",
861
+ placeholder: "my-theme",
862
862
  validate: (v)=>v.length === 0 ? "Name is required" : undefined
863
863
  });
864
864
  if (p.isCancel(name)) {
@@ -875,7 +875,7 @@ async function themeInit(_args) {
875
875
  }
876
876
  const description = await p.text({
877
877
  message: "Description",
878
- placeholder: "What does this patch sound like?"
878
+ placeholder: "What does this theme sound like?"
879
879
  });
880
880
  if (p.isCancel(description)) {
881
881
  p.cancel("Cancelled.");
@@ -899,8 +899,8 @@ async function themeInit(_args) {
899
899
  process.exit(0);
900
900
  }
901
901
  }
902
- const patch = {
903
- $schema: "../../node_modules/@litlab/audx/schemas/patch.schema.json",
902
+ const theme = {
903
+ $schema: "../../node_modules/@litlab/audx/schemas/theme.schema.json",
904
904
  name: name,
905
905
  author: author || undefined,
906
906
  version: "1.0.0",
@@ -908,64 +908,64 @@ async function themeInit(_args) {
908
908
  tags: [],
909
909
  sounds: {}
910
910
  };
911
- await writeFile(target, `${JSON.stringify(patch, null, 2)}\n`, "utf-8");
911
+ await writeFile(target, `${JSON.stringify(theme, null, 2)}\n`, "utf-8");
912
912
  p.log.success(`Created .audx/themes/${filename}`);
913
913
  p.outro("Add sounds to the `sounds` object to get started.");
914
914
  }
915
915
 
916
916
  async function list(_args) {
917
917
  p.intro("@litlab/audx list");
918
- const patches = await getInstalledPatches();
919
- if (patches.length === 0) {
920
- p.log.warn(`No patches found in ${getPatchesDir()}`);
921
- p.outro("Run `@litlab/audx add` to install patches.");
918
+ const themes = await getInstalledThemes();
919
+ if (themes.length === 0) {
920
+ p.log.warn(`No themes found in ${getThemesDir()}`);
921
+ p.outro("Run `@litlab/audx add` to install themes.");
922
922
  return;
923
923
  }
924
- const rows = patches.map((patch)=>{
925
- var _patch_description;
926
- return ` ${patch.name.padEnd(16)} ${String(patch.soundCount).padStart(3)} sounds ${(_patch_description = patch.description) != null ? _patch_description : ""}`;
924
+ const rows = themes.map((theme)=>{
925
+ var _theme_description;
926
+ return ` ${theme.name.padEnd(16)} ${String(theme.soundCount).padStart(3)} sounds ${(_theme_description = theme.description) != null ? _theme_description : ""}`;
927
927
  });
928
- p.note(rows.join("\n"), `${patches.length} patch(es) installed`);
929
- p.outro(getPatchesDir());
928
+ p.note(rows.join("\n"), `${themes.length} theme(es) installed`);
929
+ p.outro(getThemesDir());
930
930
  }
931
931
 
932
932
  function parseRemoveOptions(args) {
933
933
  const options = {};
934
- const patches = [];
934
+ const themes = [];
935
935
  for(let i = 0; i < args.length; i++){
936
936
  const arg = args[i];
937
937
  if (arg === "-y" || arg === "--yes") {
938
938
  options.yes = true;
939
939
  } else if (arg && !arg.startsWith("-")) {
940
- patches.push(arg);
940
+ themes.push(arg);
941
941
  }
942
942
  }
943
943
  return {
944
- patches,
944
+ themes,
945
945
  options
946
946
  };
947
947
  }
948
948
  async function remove(args) {
949
- const { patches: patchNames, options } = parseRemoveOptions(args);
949
+ const { themes: themeNames, options } = parseRemoveOptions(args);
950
950
  p.intro("@litlab/audx remove");
951
- const patches = await getInstalledPatches();
952
- if (patches.length === 0) {
953
- p.log.warn("No patches installed.");
951
+ const themes = await getInstalledThemes();
952
+ if (themes.length === 0) {
953
+ p.log.warn("No themes installed.");
954
954
  p.outro("Nothing to remove.");
955
955
  return;
956
956
  }
957
957
  let files;
958
- if (patchNames.length > 0) {
959
- const matched = patches.filter((pk)=>patchNames.some((n)=>n.toLowerCase() === pk.name.toLowerCase()));
958
+ if (themeNames.length > 0) {
959
+ const matched = themes.filter((pk)=>themeNames.some((n)=>n.toLowerCase() === pk.name.toLowerCase()));
960
960
  if (matched.length === 0) {
961
- p.log.error(`No matching patches found for: ${patchNames.join(", ")}`);
961
+ p.log.error(`No matching themes found for: ${themeNames.join(", ")}`);
962
962
  return;
963
963
  }
964
964
  files = matched.map((pk)=>pk.file);
965
965
  } else {
966
966
  const selected = await p.multiselect({
967
- message: "Select patches to remove",
968
- options: patches.map((pk)=>({
967
+ message: "Select themes to remove",
968
+ options: themes.map((pk)=>({
969
969
  value: pk.file,
970
970
  label: pk.name,
971
971
  hint: `${pk.soundCount} sounds`
@@ -977,50 +977,50 @@ async function remove(args) {
977
977
  }
978
978
  files = selected;
979
979
  if (files.length === 0) {
980
- p.outro("No patches selected.");
980
+ p.outro("No themes selected.");
981
981
  return;
982
982
  }
983
983
  }
984
984
  if (!options.yes) {
985
985
  const confirmed = await p.confirm({
986
- message: `Remove ${files.length} patch(es)?`
986
+ message: `Remove ${files.length} theme(es)?`
987
987
  });
988
988
  if (p.isCancel(confirmed) || !confirmed) {
989
989
  p.cancel("Cancelled.");
990
990
  process.exit(0);
991
991
  }
992
992
  }
993
- const dir = getPatchesDir();
993
+ const dir = getThemesDir();
994
994
  const removed = [];
995
995
  for (const file of files){
996
996
  try {
997
997
  var _ref;
998
998
  await unlink(join(dir, file));
999
- const pk = patches.find((item)=>item.file === file);
999
+ const pk = themes.find((item)=>item.file === file);
1000
1000
  removed.push((_ref = pk == null ? void 0 : pk.name) != null ? _ref : file);
1001
1001
  } catch (err) {
1002
1002
  p.log.warn(`Failed to remove ${file}: ${err}`);
1003
1003
  }
1004
1004
  }
1005
1005
  await regenerateIndex(dir);
1006
- p.note(removed.map((n)=>` - ${n}`).join("\n"), "Removed patches");
1006
+ p.note(removed.map((n)=>` - ${n}`).join("\n"), "Removed themes");
1007
1007
  p.outro("Done!");
1008
1008
  }
1009
1009
 
1010
1010
  async function update(_args) {
1011
1011
  p.intro("@litlab/audx update");
1012
- const installed = await getInstalledPatches();
1012
+ const installed = await getInstalledThemes();
1013
1013
  if (installed.length === 0) {
1014
- p.log.warn("No patches installed.");
1015
- p.outro("Install patches with npx @litlab/audx add");
1014
+ p.log.warn("No themes installed.");
1015
+ p.outro("Install themes with npx @litlab/audx add");
1016
1016
  return;
1017
1017
  }
1018
1018
  const s = p.spinner();
1019
1019
  s.start("Fetching registry...");
1020
1020
  let registry;
1021
1021
  try {
1022
- registry = await fetchPatchIndex();
1023
- s.stop(`Found ${registry.length} registry patch(es)`);
1022
+ registry = await fetchThemeIndex();
1023
+ s.stop(`Found ${registry.length} registry theme(es)`);
1024
1024
  } catch (err) {
1025
1025
  s.stop("Failed to fetch registry.");
1026
1026
  p.log.error(String(err));
@@ -1032,15 +1032,15 @@ async function update(_args) {
1032
1032
  ]));
1033
1033
  const toUpdate = installed.filter((pk)=>registryMap.has(pk.name.toLowerCase()));
1034
1034
  if (toUpdate.length === 0) {
1035
- p.log.warn("No installed patches found in the registry.");
1035
+ p.log.warn("No installed themes found in the registry.");
1036
1036
  p.outro("");
1037
1037
  return;
1038
1038
  }
1039
1039
  const dl = p.spinner();
1040
- dl.start(`Updating ${toUpdate.length} patch(es)...`);
1040
+ dl.start(`Updating ${toUpdate.length} theme(es)...`);
1041
1041
  let successCount = 0;
1042
1042
  let failCount = 0;
1043
- const dir = getPatchesDir();
1043
+ const dir = getThemesDir();
1044
1044
  if (!existsSync(dir)) {
1045
1045
  mkdirSync(dir, {
1046
1046
  recursive: true
@@ -1048,8 +1048,8 @@ async function update(_args) {
1048
1048
  }
1049
1049
  for (const entry of toUpdate){
1050
1050
  try {
1051
- const data = await fetchPatchJson(entry.name);
1052
- if (!validatePatch(data)) {
1051
+ const data = await fetchThemeJson(entry.name);
1052
+ if (!validateTheme(data)) {
1053
1053
  failCount++;
1054
1054
  continue;
1055
1055
  }
@@ -1063,9 +1063,9 @@ async function update(_args) {
1063
1063
  }
1064
1064
  }
1065
1065
  await regenerateIndex(dir);
1066
- dl.stop(`Updated ${successCount} patch(es)`);
1066
+ dl.stop(`Updated ${successCount} theme(es)`);
1067
1067
  if (failCount > 0) {
1068
- p.log.warn(`Failed to update ${failCount} patch(es)`);
1068
+ p.log.warn(`Failed to update ${failCount} theme(es)`);
1069
1069
  }
1070
1070
  p.outro("Done!");
1071
1071
  }
@@ -1100,19 +1100,19 @@ const COMMANDS = {
1100
1100
  };
1101
1101
  function showBanner() {
1102
1102
  p.intro("@litlab/audx");
1103
- p.log.message("Manage sound patches for your project.");
1103
+ p.log.message("Manage sound themes for your project.");
1104
1104
  p.log.message([
1105
- "Patches",
1105
+ "Themes",
1106
1106
  " add [sound] Install an individual sound",
1107
1107
  " add Browse and install themes",
1108
- " find [query] Search for patches",
1109
- " list List installed patches",
1110
- " remove Remove installed patches"
1108
+ " find [query] Search for themes",
1109
+ " list List installed themes",
1110
+ " remove Remove installed themes"
1111
1111
  ].join("\n"));
1112
1112
  p.log.message([
1113
1113
  "Updates",
1114
1114
  " check Check for updates",
1115
- " update Update installed patches"
1115
+ " update Update installed themes"
1116
1116
  ].join("\n"));
1117
1117
  p.log.message([
1118
1118
  "Project",
@@ -1126,17 +1126,17 @@ function showHelp() {
1126
1126
  p.log.message([
1127
1127
  "Usage: @litlab/audx <command> [options]",
1128
1128
  "",
1129
- "Manage Patches:",
1129
+ "Manage Themes:",
1130
1130
  " add [sound] Install an individual sound",
1131
1131
  " add Browse and install themes",
1132
1132
  " add <source> Install themes from a source",
1133
- " find [query] Search for patches in the registry",
1134
- " list, ls List installed patches",
1135
- " remove, rm Remove installed patches",
1133
+ " find [query] Search for themes in the registry",
1134
+ " list, ls List installed themes",
1135
+ " remove, rm Remove installed themes",
1136
1136
  "",
1137
1137
  "Updates:",
1138
1138
  " check Check for available updates",
1139
- " update Update all installed patches",
1139
+ " update Update all installed themes",
1140
1140
  "",
1141
1141
  "Project:",
1142
1142
  " init Set up AudX and install themes",
@@ -1144,9 +1144,9 @@ function showHelp() {
1144
1144
  ].join("\n"));
1145
1145
  p.log.message([
1146
1146
  "Add Options:",
1147
- " -l, --list Preview available patches without installing",
1147
+ " -l, --list Preview available themes without installing",
1148
1148
  " -y, --yes Skip confirmation prompts",
1149
- " --patch <name> Install a specific patch by name",
1149
+ " --theme <name> Install a specific theme by name",
1150
1150
  "",
1151
1151
  "Remove Options:",
1152
1152
  " -y, --yes Skip confirmation prompts"
@@ -1156,7 +1156,7 @@ function showHelp() {
1156
1156
  " ./local/path Local file or directory",
1157
1157
  " owner/repo GitHub shorthand",
1158
1158
  " https://github.com/user/repo Full GitHub URL",
1159
- " https://...patch.json Direct URL to a patch file",
1159
+ " https://...theme.json Direct URL to a theme file",
1160
1160
  " (no argument) Browse the registry"
1161
1161
  ].join("\n"));
1162
1162
  p.log.message([
@@ -1168,7 +1168,7 @@ function showHelp() {
1168
1168
  " @litlab/audx add ommgh/audio",
1169
1169
  " @litlab/audx add ./.themes/",
1170
1170
  " @litlab/audx add ommgh/audio --list",
1171
- " @litlab/audx add --patch core -y",
1171
+ " @litlab/audx add --theme core -y",
1172
1172
  " @litlab/audx remove core -y",
1173
1173
  " @litlab/audx find ambient",
1174
1174
  " @litlab/audx check",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litlab/audx",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "description": "Core Engine For Semantic Web Audio",
5
5
  "author": "Om Mishra",
6
6
  "license": "MIT",
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$ref": "./patch.schema.json"
3
+ "$ref": "./theme.schema.json"
4
4
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://audx.site/schemas/patch.schema.json",
4
- "title": "@litlab/audx Sound Patch",
5
- "description": "Schema for @litlab/audx sound patch JSON files",
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 patch"
14
+ "description": "Display name of the theme"
15
15
  },
16
16
  "author": {
17
17
  "type": "string"