@litlab/audx 0.0.2 → 0.5.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.
Files changed (81) hide show
  1. package/README.md +96 -53
  2. package/dist/bin.js +1212 -0
  3. package/dist/cc-DgCkkqq8.js +13 -0
  4. package/dist/cc-he3fHS3P.js +12 -0
  5. package/dist/index.d.ts +723 -3
  6. package/dist/index.js +1534 -126
  7. package/dist/react.d.ts +583 -0
  8. package/dist/react.js +1556 -0
  9. package/package.json +64 -39
  10. package/schemas/pack.schema.json +4 -0
  11. package/schemas/patch.schema.json +857 -0
  12. package/dist/codegen/theme-codegen.d.ts +0 -12
  13. package/dist/codegen/theme-codegen.d.ts.map +0 -1
  14. package/dist/codegen/theme-codegen.js +0 -153
  15. package/dist/codegen/theme-codegen.js.map +0 -1
  16. package/dist/commands/add.d.ts +0 -2
  17. package/dist/commands/add.d.ts.map +0 -1
  18. package/dist/commands/add.js +0 -120
  19. package/dist/commands/add.js.map +0 -1
  20. package/dist/commands/diff.d.ts +0 -2
  21. package/dist/commands/diff.d.ts.map +0 -1
  22. package/dist/commands/diff.js +0 -103
  23. package/dist/commands/diff.js.map +0 -1
  24. package/dist/commands/generate.d.ts +0 -12
  25. package/dist/commands/generate.d.ts.map +0 -1
  26. package/dist/commands/generate.js +0 -96
  27. package/dist/commands/generate.js.map +0 -1
  28. package/dist/commands/init.d.ts +0 -2
  29. package/dist/commands/init.d.ts.map +0 -1
  30. package/dist/commands/init.js +0 -79
  31. package/dist/commands/init.js.map +0 -1
  32. package/dist/commands/list.d.ts +0 -14
  33. package/dist/commands/list.d.ts.map +0 -1
  34. package/dist/commands/list.js +0 -93
  35. package/dist/commands/list.js.map +0 -1
  36. package/dist/commands/remove.d.ts +0 -2
  37. package/dist/commands/remove.d.ts.map +0 -1
  38. package/dist/commands/remove.js +0 -71
  39. package/dist/commands/remove.js.map +0 -1
  40. package/dist/commands/theme.d.ts +0 -31
  41. package/dist/commands/theme.d.ts.map +0 -1
  42. package/dist/commands/theme.js +0 -142
  43. package/dist/commands/theme.js.map +0 -1
  44. package/dist/commands/update.d.ts +0 -2
  45. package/dist/commands/update.d.ts.map +0 -1
  46. package/dist/commands/update.js +0 -123
  47. package/dist/commands/update.js.map +0 -1
  48. package/dist/core/alias-resolver.d.ts +0 -24
  49. package/dist/core/alias-resolver.d.ts.map +0 -1
  50. package/dist/core/alias-resolver.js +0 -87
  51. package/dist/core/alias-resolver.js.map +0 -1
  52. package/dist/core/config.d.ts +0 -21
  53. package/dist/core/config.d.ts.map +0 -1
  54. package/dist/core/config.js +0 -43
  55. package/dist/core/config.js.map +0 -1
  56. package/dist/core/file-writer.d.ts +0 -14
  57. package/dist/core/file-writer.d.ts.map +0 -1
  58. package/dist/core/file-writer.js +0 -90
  59. package/dist/core/file-writer.js.map +0 -1
  60. package/dist/core/package-manager.d.ts +0 -3
  61. package/dist/core/package-manager.d.ts.map +0 -1
  62. package/dist/core/package-manager.js +0 -17
  63. package/dist/core/package-manager.js.map +0 -1
  64. package/dist/core/registry.d.ts +0 -18
  65. package/dist/core/registry.d.ts.map +0 -1
  66. package/dist/core/registry.js +0 -69
  67. package/dist/core/registry.js.map +0 -1
  68. package/dist/core/theme-manager.d.ts +0 -35
  69. package/dist/core/theme-manager.d.ts.map +0 -1
  70. package/dist/core/theme-manager.js +0 -94
  71. package/dist/core/theme-manager.js.map +0 -1
  72. package/dist/core/utils.d.ts +0 -22
  73. package/dist/core/utils.d.ts.map +0 -1
  74. package/dist/core/utils.js +0 -44
  75. package/dist/core/utils.js.map +0 -1
  76. package/dist/index.d.ts.map +0 -1
  77. package/dist/index.js.map +0 -1
  78. package/dist/types.d.ts +0 -121
  79. package/dist/types.d.ts.map +0 -1
  80. package/dist/types.js +0 -198
  81. package/dist/types.js.map +0 -1
package/README.md CHANGED
@@ -1,86 +1,129 @@
1
- # audx
1
+ # @litlab/audx
2
2
 
3
- CLI tool for distributing and managing UI sounds from the [audx](https://audx.dev) registry.
3
+ Declarative audio synthesis for the web. Describe sounds as plain objects, play them with one function call.
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install -g @litlab/audx
8
+ npm install @litlab/audx
9
9
  ```
10
10
 
11
- Or use directly with `npx`:
11
+ ## Usage
12
12
 
13
- ```bash
14
- npx @litlab/audx <command>
13
+ ### Define and play a sound
14
+
15
+ ```ts
16
+ import { defineSound, ensureReady } from "@litlab/audx";
17
+
18
+ const pop = defineSound({
19
+ source: { type: "sine", frequency: { start: 1200, end: 300 } },
20
+ envelope: { attack: 0.001, decay: 0.06, sustain: 0, release: 0.03 },
21
+ gain: 0.3,
22
+ });
23
+
24
+ await ensureReady();
25
+ pop();
15
26
  ```
16
27
 
17
- ## Quick Start
28
+ ### Shorthand helpers
18
29
 
19
- ```bash
20
- # Initialize audx in your project
21
- audx init
30
+ ```ts
31
+ import { sine, noise } from "@litlab/audx";
32
+
33
+ const beep = sine(440, 0.1);
34
+ const click = noise("white", 0.02);
35
+
36
+ beep();
37
+ click();
38
+ ```
39
+
40
+ ### Sound patches (React)
41
+
42
+ ```tsx
43
+ import { usePatch } from "@litlab/audx/react";
44
+
45
+ function App() {
46
+ const patch = usePatch("/patches/core.json");
22
47
 
23
- # Browse available sounds
24
- audx list
48
+ return (
49
+ <button onClick={() => patch.play("click")} disabled={!patch.ready}>
50
+ Click me
51
+ </button>
52
+ );
53
+ }
54
+ ```
55
+
56
+ ### Sound patches (vanilla)
25
57
 
26
- # Add a sound
27
- audx add click-001
58
+ ```ts
59
+ import { loadPatch } from "@litlab/audx";
28
60
 
29
- # Set up themes
30
- audx theme init
31
- audx theme map click click-001
32
- audx theme generate
61
+ const patch = await loadPatch("/patches/core.json");
62
+ patch.play("click");
33
63
  ```
34
64
 
35
- ## Commands
65
+ ## CLI
36
66
 
37
- | Command | Description |
38
- |---|---|
39
- | `audx init` | Initialize audx config in your project |
40
- | `audx add <sounds...>` | Add sounds from the registry |
41
- | `audx remove <sounds...>` | Remove installed sounds |
42
- | `audx list` | List available sounds (`--tag`, `--search`) |
43
- | `audx diff` | Check for updates to installed sounds |
44
- | `audx update [sound]` | Update installed sounds from registry |
45
- | `audx generate "<prompt>"` | Generate a sound from a text prompt (`--name`, `--duration`) |
46
- | `audx theme init` | Create theme configuration |
47
- | `audx theme set <name>` | Switch active theme |
48
- | `audx theme map <semantic> <sound>` | Map a semantic name to a sound |
49
- | `audx theme create <name>` | Create a new theme |
50
- | `audx theme list` | List all themes |
51
- | `audx theme generate` | Generate `sound-theme.ts` |
67
+ ```bash
68
+ # Browse and install patches from the registry
69
+ npx @litlab/audx add
70
+
71
+ # Install patches from a GitHub repo
72
+ npx @litlab/audx add user/repo
52
73
 
53
- ## How It Works
74
+ # Create a new sound patch
75
+ npx @litlab/audx init
54
76
 
55
- audx manages UI sounds as TypeScript modules with base64-encoded audio data — no external files to serve. Sounds are fetched from the audx registry and written directly into your project.
77
+ # List installed patches
78
+ npx @litlab/audx list
56
79
 
57
- The theme system lets you reference sounds by semantic purpose (`play("success")`) instead of file names, and swap entire sound palettes by switching themes.
80
+ # Remove installed patches
81
+ npx @litlab/audx remove
82
+ ```
58
83
 
59
- ## Configuration
84
+ ## Patch authoring
60
85
 
61
- Running `audx init` creates `audx.config.json`:
86
+ Create a patch JSON file with `npx @litlab/audx init`, then add sound definitions to the `sounds` object:
62
87
 
63
88
  ```json
64
89
  {
65
- "soundDir": "src/sounds",
66
- "libDir": "src/lib",
67
- "registryUrl": "https://audx.dev",
68
- "packageManager": "pnpm",
69
- "aliases": {
70
- "lib": "@/lib",
71
- "hooks": "@/hooks",
72
- "sounds": "@/sounds"
73
- },
74
- "installedSounds": {}
90
+ "$schema": "node_modules/@litlab/audx/schemas/patch.schema.json",
91
+ "name": "my-patch",
92
+ "sounds": {
93
+ "click": {
94
+ "source": { "type": "noise", "color": "white" },
95
+ "filter": { "type": "bandpass", "frequency": 2000 },
96
+ "envelope": { "decay": 0.05 }
97
+ }
98
+ }
75
99
  }
76
100
  ```
77
101
 
78
- Path aliases are auto-detected from your `tsconfig.json`.
102
+ Push it to a GitHub repo. Others can install it with:
103
+
104
+ ```bash
105
+ npx @litlab/audx add your-username/your-repo
106
+ ```
107
+
108
+ ## API
109
+
110
+ | Export | Description |
111
+ |--------|-------------|
112
+ | `defineSound(def)` | Create a reusable play function from a sound definition |
113
+ | `ensureReady()` | Initialize the audio context (call before first play) |
114
+ | `sine(freq, decay)` | Shorthand for sine oscillator |
115
+ | `triangle(freq, decay)` | Shorthand for triangle oscillator |
116
+ | `square(freq, decay)` | Shorthand for square oscillator |
117
+ | `sawtooth(freq, decay)` | Shorthand for sawtooth oscillator |
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 |
79
122
 
80
- ## Requirements
123
+ ## Documentation
81
124
 
82
- - Node.js 18+
125
+ Full docs at [audx.site](https://audx.site).
83
126
 
84
127
  ## License
85
128
 
86
- MIT
129
+ [MIT](https://github.com/ommgh/audio/blob/main/LICENSE)