@vielzeug/codex 26.11.17 → 26.11.19
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/data/catalog.json +105 -54
- package/data/llms-full.txt +518 -1
- package/data/llms.txt +2 -1
- package/data/manifest.json +1 -1
- package/data/packages/archive.json +12 -1
- package/data/packages/assay.json +12 -1
- package/data/packages/bard.json +38 -0
- package/data/packages/forge.json +5 -0
- package/data/packages/ore.json +12 -1
- package/data/packages/patchwork.json +5 -0
- package/data/packages/prism.json +12 -1
- package/data/packages/refine.json +12 -1
- package/data/packages/tavern.json +7 -1
- package/package.json +2 -2
- package/skills/vielzeug/SKILL.md +1 -0
package/data/llms-full.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Vielzeug: Full Documentation
|
|
2
2
|
|
|
3
|
-
> Complete documentation for
|
|
3
|
+
> Complete documentation for 47 packages. Version: 26.11.18
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -1506,6 +1506,11 @@ export function useRecipes() {
|
|
|
1506
1506
|
- [Client Error Mapping](./examples/client-error-mapping.md)
|
|
1507
1507
|
- [GDPR Erasure and Export](./examples/gdpr-erasure-and-export.md)
|
|
1508
1508
|
|
|
1509
|
+
### REPL Examples
|
|
1510
|
+
|
|
1511
|
+
- Shared Contract Schemas (id: `contract-schemas`)
|
|
1512
|
+
- Define A Collection (id: `define-collection`)
|
|
1513
|
+
|
|
1509
1514
|
---
|
|
1510
1515
|
|
|
1511
1516
|
## @vielzeug/arsenal
|
|
@@ -2772,6 +2777,497 @@ use the flat tree for DOM algorithms; this helper is for test code that needs eq
|
|
|
2772
2777
|
- [Custom Element Interaction](./examples/custom-element-interaction.md)
|
|
2773
2778
|
- [Waiting for Async Updates](./examples/waiting-for-async-updates.md)
|
|
2774
2779
|
|
|
2780
|
+
### REPL Examples
|
|
2781
|
+
|
|
2782
|
+
- Scoped Queries And Events (id: `scoped-queries`)
|
|
2783
|
+
- Cancellable Waiting (id: `waiting`)
|
|
2784
|
+
|
|
2785
|
+
---
|
|
2786
|
+
|
|
2787
|
+
## @vielzeug/bard
|
|
2788
|
+
|
|
2789
|
+
**Category:** utilities
|
|
2790
|
+
|
|
2791
|
+
### Overview
|
|
2792
|
+
|
|
2793
|
+
## Why Bard?
|
|
2794
|
+
|
|
2795
|
+
The Web Audio API gives you nodes and params but no lifecycle: nothing stops voices, removes gesture listeners, or closes the context when your feature unmounts. Bard wraps a lazily created `AudioContext` in one disposable engine with named buses, ducking, voice caps, and a crossfading music deck.
|
|
2796
|
+
|
|
2797
|
+
```ts
|
|
2798
|
+
// Before: hand-rolled graph, listeners, and teardown you must remember
|
|
2799
|
+
const ctx = new AudioContext();
|
|
2800
|
+
const source = ctx.createBufferSource();
|
|
2801
|
+
source.connect(ctx.destination);
|
|
2802
|
+
// ...who disconnects this on unmount?
|
|
2803
|
+
|
|
2804
|
+
// After
|
|
2805
|
+
const bard = createBard({ ducking: [{ source: 'voice', target: 'music', gain: 0.3 }] });
|
|
2806
|
+
await bard.load({ confirm: '/confirm.wav' });
|
|
2807
|
+
bard.play('confirm');
|
|
2808
|
+
bard.dispose(); // stops voices, removes listeners, closes the context
|
|
2809
|
+
```
|
|
2810
|
+
|
|
2811
|
+
| Feature | Native Web Audio | Bard | Howler.js |
|
|
2812
|
+
| ----------------- | -------------------------------------------- | -------------------------------------------- | -------------------------------------------- |
|
|
2813
|
+
| Bundle size | 0 B | | ~30 kB |
|
|
2814
|
+
| Root dependencies | | | |
|
|
2815
|
+
| Lifecycle | Manual node teardown | `dispose()` + `Symbol.dispose` | Per-sound unload |
|
|
2816
|
+
| Mixing | Hand-built gain graph | Named buses, ducking rules, voice caps | Per-sound volume only |
|
|
2817
|
+
| Music transitions | Manual crossfade scheduling | `deck.transition()` with loop points, queue | Not built in |
|
|
2818
|
+
|
|
2819
|
+
**Use Bard when** an interactive app needs owned audio: UI SFX with voice caps, narration that ducks music, or game-state music transitions with crossfades and loop points.
|
|
2820
|
+
|
|
2821
|
+
**Consider a plain `HTMLAudioElement` when** you need one background track with no mixing, sprites, or lifecycle requirements.
|
|
2822
|
+
|
|
2823
|
+
## Installation
|
|
2824
|
+
|
|
2825
|
+
```sh [pnpm]
|
|
2826
|
+
pnpm add @vielzeug/bard
|
|
2827
|
+
```
|
|
2828
|
+
|
|
2829
|
+
```sh [npm]
|
|
2830
|
+
npm install @vielzeug/bard
|
|
2831
|
+
```
|
|
2832
|
+
|
|
2833
|
+
```sh [yarn]
|
|
2834
|
+
yarn add @vielzeug/bard
|
|
2835
|
+
```
|
|
2836
|
+
|
|
2837
|
+
## Quick Start
|
|
2838
|
+
|
|
2839
|
+
Create the engine once per app, load assets, and dispose it when the owning feature unmounts. Nothing touches `AudioContext` or the DOM until the first call that needs audio, so server rendering is safe.
|
|
2840
|
+
|
|
2841
|
+
```ts
|
|
2842
|
+
import { createBard } from '@vielzeug/bard';
|
|
2843
|
+
|
|
2844
|
+
const bard = createBard({
|
|
2845
|
+
ducking: [{ source: 'voice', target: 'music', gain: 0.3 }],
|
|
2846
|
+
});
|
|
2847
|
+
|
|
2848
|
+
await bard.load({
|
|
2849
|
+
music: { src: '/theme.mp3', stream: true },
|
|
2850
|
+
dice: { src: '/sfx.wav', sprites: { roll: [0, 1.2] } },
|
|
2851
|
+
});
|
|
2852
|
+
|
|
2853
|
+
const deck = bard.createDeck();
|
|
2854
|
+
deck.transition('music', { loop: true });
|
|
2855
|
+
bard.play('dice:roll', { detune: [-60, 60] });
|
|
2856
|
+
|
|
2857
|
+
bard.dispose();
|
|
2858
|
+
```
|
|
2859
|
+
|
|
2860
|
+
## Features
|
|
2861
|
+
|
|
2862
|
+
- **`createBard()`**: one disposable owner for the context, buses, voices, and decks.
|
|
2863
|
+
- **`bus()`**: named gain buses (`music`, `sfx`, `voice`) with click-free volume ramps.
|
|
2864
|
+
- **`ducking`**: declarative rules that ramp a target bus while a source bus has active voices.
|
|
2865
|
+
- **`play()`**: buffered playback with sprites, voice caps, oldest-first stealing, and detune/rate variance.
|
|
2866
|
+
- **`synth()`**: zero-asset oscillator and noise voices with ADSR and frequency sweeps.
|
|
2867
|
+
- **`createDeck()`**: two-slot crossfader with loop points, queue with shuffle, and opt-in Media Session.
|
|
2868
|
+
- **`tap()`**: observability events for state changes, steals, ducks, and track changes.
|
|
2869
|
+
|
|
2870
|
+
## Documentation
|
|
2871
|
+
|
|
2872
|
+
- [Usage Guide](./usage.md)
|
|
2873
|
+
- [API Reference](./api.md)
|
|
2874
|
+
- [Examples](./examples.md)
|
|
2875
|
+
- [Migration](./migration.md)
|
|
2876
|
+
|
|
2877
|
+
## See Also
|
|
2878
|
+
|
|
2879
|
+
- [Necromancer](/necromancer/): pair visual transitions with deck music transitions from the same game-state change.
|
|
2880
|
+
- [Arsenal](/arsenal/): general-purpose utilities used across the monorepo.
|
|
2881
|
+
|
|
2882
|
+
### API Reference
|
|
2883
|
+
|
|
2884
|
+
## API Overview
|
|
2885
|
+
|
|
2886
|
+
| Symbol | Purpose | Execution | Common gotcha |
|
|
2887
|
+
| ---------------------- | ------------------------------------------- | --------- | ------------------------------------------------------------------------ |
|
|
2888
|
+
| `createBard` | Creates the disposable audio engine | Sync | Context is still created lazily on first audio use |
|
|
2889
|
+
| `BardError` | Base error for invalid keys, buses, regions | — | Subclasses: `BardLoadError`, `BardDisposedError`, `BardUnsupportedError` |
|
|
2890
|
+
| `BardLoadError` | A manifest entry failed to fetch or decode | — | Original failure is in `cause` |
|
|
2891
|
+
| `BardDisposedError` | A method ran after `dispose()` | — | Thrown by every engine method except `dispose` |
|
|
2892
|
+
| `BardUnsupportedError` | No `AudioContext` in the runtime | — | `unlock()` rejects with it on servers without Web Audio |
|
|
2893
|
+
|
|
2894
|
+
## Package Entry Point
|
|
2895
|
+
|
|
2896
|
+
| Import | Purpose |
|
|
2897
|
+
| ------------------------ | --------------------------------------- |
|
|
2898
|
+
| `@vielzeug/bard` | Complete public Bard API |
|
|
2899
|
+
| `@vielzeug/bard/testing` | Deterministic Web Audio fakes for tests |
|
|
2900
|
+
|
|
2901
|
+
## Engine
|
|
2902
|
+
|
|
2903
|
+
### createBard
|
|
2904
|
+
|
|
2905
|
+
```ts
|
|
2906
|
+
function createBard(options?: BardOptions): Bard;
|
|
2907
|
+
```
|
|
2908
|
+
|
|
2909
|
+
Creates the engine. Touches no browser global until the first method that needs audio.
|
|
2910
|
+
|
|
2911
|
+
| Option | Type | Default | Notes |
|
|
2912
|
+
| --------------------- | ------------------------ | --------------------------- | --------------------------------------------------------------------------- |
|
|
2913
|
+
| `buses` | `readonly string[]` | `['music', 'sfx', 'voice']` | `'master'` is reserved and throws if declared |
|
|
2914
|
+
| `volume` | `number` | `1` | Master volume, linear 0..1 |
|
|
2915
|
+
| `ducking` | `readonly DuckingRule[]` | `[]` | See Ducking |
|
|
2916
|
+
| `maxVoices` | `number` | `32` | Engine-wide concurrent voice cap |
|
|
2917
|
+
| `autoUnlock` | `boolean` | `true` | Gesture listeners resume a suspended context |
|
|
2918
|
+
| `autoSuspendOnHidden` | `boolean` | `false` | Suspend on page hide, resume on show (only resumes its own suspends) |
|
|
2919
|
+
| `context` | `() => AudioContext` | lazy `new AudioContext()` | Injection seam for tests; injected contexts are never closed by `dispose()` |
|
|
2920
|
+
|
|
2921
|
+
Returns the `Bard` engine.
|
|
2922
|
+
|
|
2923
|
+
```ts
|
|
2924
|
+
import { createBard } from '@vielzeug/bard';
|
|
2925
|
+
|
|
2926
|
+
const bard = createBard({ volume: 0.9 });
|
|
2927
|
+
```
|
|
2928
|
+
|
|
2929
|
+
### Bard
|
|
2930
|
+
|
|
2931
|
+
| Member | Signature | Notes |
|
|
2932
|
+
| ----------------------------- | ----------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
|
2933
|
+
| `state` | `'idle' \| 'suspended' \| 'running' \| 'interrupted' \| 'closed'` | `'idle'` until first lazy context creation; `'interrupted'` occurs on iOS calls |
|
|
2934
|
+
| `context` | `AudioContext \| null` | Native context for advanced graph work |
|
|
2935
|
+
| `unlock()` | `() => Promise` | Creates and resumes the context |
|
|
2936
|
+
| `load(manifest, options?)` | `(AssetManifest, { signal? }) => Promise` | Deduplicates concurrent fetches per URL |
|
|
2937
|
+
| `unload(keys?)` | `(string \| readonly string[]) => void` | Stops active voices for the dropped keys |
|
|
2938
|
+
| `has(key)` | `(string) => boolean` | Resolves `'key:sprite'` to its parent asset |
|
|
2939
|
+
| `play(key, options?)` | `(string, PlayOptions?) => SoundHandle` | Throws `BardError` for unknown keys and streamed assets |
|
|
2940
|
+
| `synth(options)` | `(SynthOptions) => SoundHandle` | Procedural voice, self-cleaning |
|
|
2941
|
+
| `bus(name)` | `(string) => BusController` | `'master'` is valid; unknown names throw |
|
|
2942
|
+
| `createDeck(options?)` | `(DeckOptions?) => MusicDeck` | Multiple decks share the engine |
|
|
2943
|
+
| `suspend()` / `resume()` | `() => Promise` | Engine-wide pause for the whole context |
|
|
2944
|
+
| `tap(handler, options?)` | `(BardEvent) => void` → unsubscribe | Handler errors are swallowed; auto-detaches on `signal` |
|
|
2945
|
+
| `dispose()` | `() => void` | Stops voices and decks, aborts loads, removes listeners, closes an owned context; idempotent |
|
|
2946
|
+
| `disposed` / `disposalSignal` | `boolean` / `AbortSignal` | Standard disposal contract |
|
|
2947
|
+
|
|
2948
|
+
---
|
|
2949
|
+
|
|
2950
|
+
## Playback
|
|
2951
|
+
|
|
2952
|
+
### SoundHandle
|
|
2953
|
+
|
|
2954
|
+
Returned by `play()` and `synth()`.
|
|
2955
|
+
|
|
2956
|
+
| Member | Signature | Notes |
|
|
2957
|
+
| --------------------------------------------- | -------------------------------- | ------------------------------------------- |
|
|
2958
|
+
| `stop(options?)` | `(FadeOptions?) => void` | Fades (default 15 ms micro-fade) then stops |
|
|
2959
|
+
| `setVolume(volume, options?)` | `(number, FadeOptions?) => void` | Ramped, never clicks |
|
|
2960
|
+
| `setPan(pan)` | `(-1..1) => void` | Every voice has a panner |
|
|
2961
|
+
| `finished` | `Promise` | Resolves on natural end, stop, or dispose |
|
|
2962
|
+
| `dispose()` / `disposed` / `[Symbol.dispose]` | | Immediate stop and node release |
|
|
2963
|
+
|
|
2964
|
+
### PlayOptions
|
|
2965
|
+
|
|
2966
|
+
| Option | Type | Default | Notes |
|
|
2967
|
+
| ----------------------- | ---------------------- | ------------- | -------------------------------------- |
|
|
2968
|
+
| `bus` | `string` | `'sfx'` | Destination bus |
|
|
2969
|
+
| `volume` | `number` | `1` | Linear 0..1 |
|
|
2970
|
+
| `pan` | `number` | `0` | -1..1; voices always route via a panner |
|
|
2971
|
+
| `loop` | `boolean` | `false` | Loops the buffer or sprite region |
|
|
2972
|
+
| `loopStart` / `loopEnd` | `number` | — | Absolute buffer seconds |
|
|
2973
|
+
| `offset` | `number` | `0` | Start offset in seconds |
|
|
2974
|
+
| `detune` | `number \| [min, max]` | — | Cents; ranges sampled per voice |
|
|
2975
|
+
| `rate` | `number \| [min, max]` | — | Playback rate; shifts pitch on buffers |
|
|
2976
|
+
| `maxVoices` | `number` | — | Per-key cap; oldest copy is stolen |
|
|
2977
|
+
| `fadeIn` | `number` | — | Seconds from 0 to `volume` |
|
|
2978
|
+
| `random` | `() => number` | `Math.random` | Deterministic sampling in tests |
|
|
2979
|
+
|
|
2980
|
+
### SynthOptions
|
|
2981
|
+
|
|
2982
|
+
| Option | Type | Default | Notes |
|
|
2983
|
+
| ---------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------ | --------------------------------------------------------------- |
|
|
2984
|
+
| `type` | `'sine' \| 'square' \| 'sawtooth' \| 'triangle' \| 'noise'` | `'sine'` | `'noise'` uses a cached white-noise buffer |
|
|
2985
|
+
| `freq` | `number \| [from, to]` | `440` | Tuple sweeps exponentially; maps to filter cutoff for `'noise'` |
|
|
2986
|
+
| `duration` | `number` | `0.3` | Total seconds including release; must be positive |
|
|
2987
|
+
| `envelope` | `SynthEnvelope` | `{ attack: 0.005, decay: 0.05, sustain: 0.6, release: 0.1 }` | ADSR; `sustain` is a level |
|
|
2988
|
+
| `filter` | `SynthFilter` | — | Biquad stage before the envelope |
|
|
2989
|
+
| `bus` / `volume` / `pan` / `detune` | as in `PlayOptions` | | |
|
|
2990
|
+
|
|
2991
|
+
---
|
|
2992
|
+
|
|
2993
|
+
## Mixing
|
|
2994
|
+
|
|
2995
|
+
### DuckingRule
|
|
2996
|
+
|
|
2997
|
+
```ts
|
|
2998
|
+
interface DuckingRule {
|
|
2999
|
+
readonly source: string;
|
|
3000
|
+
readonly target: string;
|
|
3001
|
+
readonly gain: number; // duck level, linear 0..1
|
|
3002
|
+
readonly attack?: number; // seconds, default 0.2
|
|
3003
|
+
readonly release?: number; // seconds, default 0.8
|
|
3004
|
+
}
|
|
3005
|
+
```
|
|
3006
|
+
|
|
3007
|
+
While the `source` bus has active voices, `target` ramps to `gain`; when they end it ramps back to 1. Multiple rules on one target take the lowest active gain.
|
|
3008
|
+
|
|
3009
|
+
### BusController
|
|
3010
|
+
|
|
3011
|
+
| Member | Notes |
|
|
3012
|
+
| ----------------------------------- | -------------------------------------- |
|
|
3013
|
+
| `name` | Bus name |
|
|
3014
|
+
| `volume` / `setVolume(v, options?)` | User volume stage, ramped |
|
|
3015
|
+
| `muted` / `mute()` / `unmute()` | Ramped mute |
|
|
3016
|
+
| `duckLevel` | Current duck multiplier (1 = unducked) |
|
|
3017
|
+
|
|
3018
|
+
---
|
|
3019
|
+
|
|
3020
|
+
## Music Deck
|
|
3021
|
+
|
|
3022
|
+
### MusicDeck
|
|
3023
|
+
|
|
3024
|
+
| Member | Signature | Notes |
|
|
3025
|
+
| --------------------------------------------- | --------------------------------------------- | ----------------------------------------------- |
|
|
3026
|
+
| `current` | `string \| null` | Active track key |
|
|
3027
|
+
| `playing` | `boolean` | `false` while paused or stopped |
|
|
3028
|
+
| `transition(key, options?)` | `(string, TransitionOptions?) => void` | Crossfades; transitioning to the live key is a no-op |
|
|
3029
|
+
| `queue(keys, options?)` | `(readonly string[], QueueOptions?) => void` | Replaces the queue and starts its first track |
|
|
3030
|
+
| `next()` / `previous()` | `() => void` | No-op without a queue |
|
|
3031
|
+
| `pause()` / `play()` | `() => void` | `play()` resumes from the paused offset |
|
|
3032
|
+
| `stop(options?)` | `(FadeOptions?) => void` | Stops and clears queue and slot |
|
|
3033
|
+
| `dispose()` / `disposed` / `[Symbol.dispose]` | | Releases a Media Session claim |
|
|
3034
|
+
|
|
3035
|
+
`TransitionOptions`: `fade`, `loop`, `loopStart`, `loopEnd`, `offset`.
|
|
3036
|
+
`QueueOptions`: `shuffle`, `crossfade`, `repeat`, `random`.
|
|
3037
|
+
|
|
3038
|
+
### DeckOptions
|
|
3039
|
+
|
|
3040
|
+
| Option | Type | Default | Notes |
|
|
3041
|
+
| -------------- | --------- | --------- | ------------------------------------------------------ |
|
|
3042
|
+
| `bus` | `string` | `'music'` | Destination bus |
|
|
3043
|
+
| `mediaSession` | `boolean` | `false` | Claims `navigator.mediaSession`; a second claim throws |
|
|
3044
|
+
| `fade` | `number` | `2` | Default crossfade seconds |
|
|
3045
|
+
|
|
3046
|
+
---
|
|
3047
|
+
|
|
3048
|
+
## Assets
|
|
3049
|
+
|
|
3050
|
+
### AssetManifest
|
|
3051
|
+
|
|
3052
|
+
```ts
|
|
3053
|
+
type AssetManifest = Readonly>;
|
|
3054
|
+
|
|
3055
|
+
interface AssetDefinition {
|
|
3056
|
+
readonly src: string;
|
|
3057
|
+
readonly sprites?: Readonly>;
|
|
3058
|
+
readonly stream?: boolean; // deck-only playback via an owned element
|
|
3059
|
+
readonly meta?: AssetMeta; // Media Session metadata
|
|
3060
|
+
}
|
|
3061
|
+
```
|
|
3062
|
+
|
|
3063
|
+
A bare string is shorthand for `{ src }`. Sprite regions are `[startSeconds, durationSeconds]` and play as `'key:sprite'`; out-of-bounds regions throw `BardError`.
|
|
3064
|
+
|
|
3065
|
+
---
|
|
3066
|
+
|
|
3067
|
+
## Observability
|
|
3068
|
+
|
|
3069
|
+
### BardEvent
|
|
3070
|
+
|
|
3071
|
+
| Event | Payload | Fires |
|
|
3072
|
+
| ------------ | ---------------------- | ---------------------------------------- |
|
|
3073
|
+
| `state` | `state` | Context lifecycle changes |
|
|
3074
|
+
| `load` | `key` | A manifest entry finished loading |
|
|
3075
|
+
| `load-error` | `key`, `error` | A load failed |
|
|
3076
|
+
| `steal` | `key` | A voice was stolen past a cap |
|
|
3077
|
+
| `duck` | `bus`, `level`, `ramp` | A bus duck level changed |
|
|
3078
|
+
| `track` | `key \| null` | The deck changed tracks |
|
|
3079
|
+
| `dispose` | — | Emitted once at the start of `dispose()` |
|
|
3080
|
+
|
|
3081
|
+
---
|
|
3082
|
+
|
|
3083
|
+
## Testing
|
|
3084
|
+
|
|
3085
|
+
`@vielzeug/bard/testing` exports `FakeAudioContext` (manual clock via `advance(seconds)`, recorded `FakeAudioParam` automation), `FakeMediaElement`, `FakeMediaSession`, and `flush()`. Inject the fake with `createBard({ context: () => fake })`.
|
|
3086
|
+
|
|
3087
|
+
---
|
|
3088
|
+
|
|
3089
|
+
## Errors
|
|
3090
|
+
|
|
3091
|
+
| Error | Trigger | Notes |
|
|
3092
|
+
| ------------------- | ---------------------------------------------------------------- | --------------------------------------------------------- |
|
|
3093
|
+
| `BardError` | Unknown key/bus/sprite, reserved bus name, streamed-asset misuse | Base class |
|
|
3094
|
+
| `BardLoadError` | Fetch or `decodeAudioData` failure | `cause` carries the original error or `{ status }` |
|
|
3095
|
+
| `BardDisposedError` | Engine use after `dispose()` | Also `BardUnsupportedError` when no `AudioContext` exists |
|
|
3096
|
+
|
|
3097
|
+
### Usage Guide
|
|
3098
|
+
|
|
3099
|
+
## Basic Usage
|
|
3100
|
+
|
|
3101
|
+
Create one engine per app, load a manifest, and play through a bus. Dispose the engine when its owning feature unmounts.
|
|
3102
|
+
|
|
3103
|
+
```ts
|
|
3104
|
+
import { createBard } from '@vielzeug/bard';
|
|
3105
|
+
|
|
3106
|
+
const bard = createBard();
|
|
3107
|
+
await bard.load({ click: '/click.wav', boom: '/boom.wav' });
|
|
3108
|
+
|
|
3109
|
+
const handle = bard.play('boom', { volume: 0.8, pan: -0.3 });
|
|
3110
|
+
await handle.finished;
|
|
3111
|
+
bard.dispose();
|
|
3112
|
+
```
|
|
3113
|
+
|
|
3114
|
+
`play()` returns a `SoundHandle` immediately; audio starts once the browser allows it. `finished` resolves when the voice ends, is stopped, or is disposed.
|
|
3115
|
+
|
|
3116
|
+
## Unlocking Audio
|
|
3117
|
+
|
|
3118
|
+
Browsers start the `AudioContext` suspended until a user gesture. Bard attaches capture-phase listeners for `pointerup`, `touchend`, `keydown`, and `click` and resumes the context inside the first one. All listeners are removed once the context is running.
|
|
3119
|
+
|
|
3120
|
+
```ts
|
|
3121
|
+
const bard = createBard(); // listeners attach on first audio use
|
|
3122
|
+
await bard.unlock(); // or resume programmatically inside your own handler
|
|
3123
|
+
```
|
|
3124
|
+
|
|
3125
|
+
`autoUnlock: false` skips the gesture listeners entirely; call `resume()` from your own gesture handler instead.
|
|
3126
|
+
|
|
3127
|
+
## Buses and Volume
|
|
3128
|
+
|
|
3129
|
+
Voices route to a named bus: `voice -> [pan] -> bus -> master -> destination`. The defaults are `music`, `sfx`, and `voice`; override with `buses`. Volume changes always ramp, so they never click.
|
|
3130
|
+
|
|
3131
|
+
```ts
|
|
3132
|
+
const music = bard.bus('music');
|
|
3133
|
+
music.setVolume(0.6, { fade: 0.5 });
|
|
3134
|
+
music.mute();
|
|
3135
|
+
music.unmute();
|
|
3136
|
+
```
|
|
3137
|
+
|
|
3138
|
+
`bard.bus('master')` controls the output stage for every bus.
|
|
3139
|
+
|
|
3140
|
+
## Ducking
|
|
3141
|
+
|
|
3142
|
+
A ducking rule ramps a target bus down while the source bus has active voices, and back up when they end. Narration over music is the canonical case.
|
|
3143
|
+
|
|
3144
|
+
```ts
|
|
3145
|
+
const bard = createBard({
|
|
3146
|
+
ducking: [{ source: 'voice', target: 'music', gain: 0.3, attack: 0.2, release: 0.8 }],
|
|
3147
|
+
});
|
|
3148
|
+
|
|
3149
|
+
await bard.load({ announce: '/announce.wav' });
|
|
3150
|
+
const voice = bard.play('announce', { bus: 'voice' });
|
|
3151
|
+
// music is now at 30% until the announcement ends
|
|
3152
|
+
await voice.finished; // music ramps back to 100%
|
|
3153
|
+
```
|
|
3154
|
+
|
|
3155
|
+
Ducking uses its own gain stage per bus, so it never fights user volume automation.
|
|
3156
|
+
|
|
3157
|
+
## Sound Sprites
|
|
3158
|
+
|
|
3159
|
+
Bundle many short SFX into one file and address regions with `key:sprite`. The region is `[startSeconds, durationSeconds]`.
|
|
3160
|
+
|
|
3161
|
+
```ts
|
|
3162
|
+
await bard.load({
|
|
3163
|
+
ui: { src: '/ui.wav', sprites: { open: [0, 0.4], close: [0.5, 0.4] } },
|
|
3164
|
+
});
|
|
3165
|
+
|
|
3166
|
+
bard.play('ui:open');
|
|
3167
|
+
bard.play('ui:close', { bus: 'sfx' });
|
|
3168
|
+
```
|
|
3169
|
+
|
|
3170
|
+
## Voice Caps and Variance
|
|
3171
|
+
|
|
3172
|
+
`maxVoices` caps concurrent copies of one key; the oldest copy is stolen with a micro-fade. The engine-wide cap is `maxVoices` in `createBard` (default 32). Ranges for `detune` and `rate` keep repeated hits from sounding identical.
|
|
3173
|
+
|
|
3174
|
+
```ts
|
|
3175
|
+
for (let i = 0; i ` element instead of decoding it into an `AudioBuffer`. Mobile devices never spike RAM on ten-minute ambient tracks. Streamed assets are deck-only; `play()` on them throws.
|
|
3176
|
+
|
|
3177
|
+
```ts
|
|
3178
|
+
await bard.load({
|
|
3179
|
+
ambient: { src: 'https://cdn.example.com/forest.mp3', stream: true },
|
|
3180
|
+
});
|
|
3181
|
+
bard.createDeck().transition('ambient', { loop: true });
|
|
3182
|
+
```
|
|
3183
|
+
|
|
3184
|
+
The element requests CORS (`crossOrigin: 'anonymous'`); a CDN without CORS headers plays silent through Web Audio. Streamed loops cover the whole file: `loopStart`/`loopEnd` throw.
|
|
3185
|
+
|
|
3186
|
+
## Media Session
|
|
3187
|
+
|
|
3188
|
+
`mediaSession: true` claims `navigator.mediaSession` for one deck: metadata from the asset's `meta`, hardware play/pause/next/previous. A second claim throws instead of stealing controls; disposing the deck releases the claim.
|
|
3189
|
+
|
|
3190
|
+
```ts
|
|
3191
|
+
await bard.load({
|
|
3192
|
+
theme: { src: '/theme.mp3', meta: { title: 'Hunt Theme', artist: 'Bard' } },
|
|
3193
|
+
});
|
|
3194
|
+
const deck = bard.createDeck({ mediaSession: true });
|
|
3195
|
+
deck.transition('theme');
|
|
3196
|
+
```
|
|
3197
|
+
|
|
3198
|
+
## Testing
|
|
3199
|
+
|
|
3200
|
+
`@vielzeug/bard/testing` ships deterministic fakes: a context with a manual clock, recorded param automation, and fake media elements. Bard's own suite uses them.
|
|
3201
|
+
|
|
3202
|
+
```ts
|
|
3203
|
+
import { createBard } from '@vielzeug/bard';
|
|
3204
|
+
import { FakeAudioContext } from '@vielzeug/bard/testing';
|
|
3205
|
+
|
|
3206
|
+
const ctx = new FakeAudioContext();
|
|
3207
|
+
const bard = createBard({ context: () => ctx });
|
|
3208
|
+
await bard.load({ ping: '/ping.wav' });
|
|
3209
|
+
bard.play('ping');
|
|
3210
|
+
ctx.advance(2); // clock moves, sources past their stop time fire 'ended'
|
|
3211
|
+
```
|
|
3212
|
+
|
|
3213
|
+
## Framework Integration
|
|
3214
|
+
|
|
3215
|
+
```tsx [React]
|
|
3216
|
+
import { useEffect, useState } from 'react';
|
|
3217
|
+
import { createBard, type Bard } from '@vielzeug/bard';
|
|
3218
|
+
|
|
3219
|
+
export function useBard() {
|
|
3220
|
+
const [bard, setBard] = useState(null);
|
|
3221
|
+
useEffect(() => {
|
|
3222
|
+
const engine = createBard();
|
|
3223
|
+
setBard(engine);
|
|
3224
|
+
return () => engine.dispose();
|
|
3225
|
+
}, []);
|
|
3226
|
+
return bard;
|
|
3227
|
+
}
|
|
3228
|
+
```
|
|
3229
|
+
|
|
3230
|
+
```vue [Vue 3]
|
|
3231
|
+
|
|
3232
|
+
import { onMounted, onUnmounted, shallowRef } from 'vue';
|
|
3233
|
+
import { createBard } from '@vielzeug/bard';
|
|
3234
|
+
|
|
3235
|
+
const bard = shallowRef | null>(null);
|
|
3236
|
+
onMounted(() => (bard.value = createBard()));
|
|
3237
|
+
onUnmounted(() => bard.value?.dispose());
|
|
3238
|
+
|
|
3239
|
+
```
|
|
3240
|
+
|
|
3241
|
+
```svelte [Svelte]
|
|
3242
|
+
|
|
3243
|
+
import { createBard } from '@vielzeug/bard';
|
|
3244
|
+
import { onDestroy } from 'svelte';
|
|
3245
|
+
|
|
3246
|
+
const bard = createBard();
|
|
3247
|
+
onDestroy(() => bard.dispose());
|
|
3248
|
+
|
|
3249
|
+
```
|
|
3250
|
+
|
|
3251
|
+
Create the engine in a mount hook, not at module scope: only mount lifecycle proves a browser runtime exists.
|
|
3252
|
+
|
|
3253
|
+
## Best Practices
|
|
3254
|
+
|
|
3255
|
+
- Create one engine per app and pass it down; contexts are a limited hardware resource.
|
|
3256
|
+
- Dispose the engine with its owning feature; `using` works via `Symbol.dispose`.
|
|
3257
|
+
- Keep streamed assets for tracks longer than a few minutes; buffers are better for SFX.
|
|
3258
|
+
- Give narration its own `voice` bus and duck `music` from it, rather than fading tracks by hand.
|
|
3259
|
+
- Inject `random` in tests so detune, rate, and shuffle are deterministic.
|
|
3260
|
+
- Watch `tap()` events (`steal`, `duck`, `load-error`) in development to catch mixing problems early.
|
|
3261
|
+
- Call `unlock()` from your own first-gesture UI when you want audio live before the next interaction.
|
|
3262
|
+
|
|
3263
|
+
### Examples
|
|
3264
|
+
|
|
3265
|
+
## Examples
|
|
3266
|
+
|
|
3267
|
+
- [Game-State Music Transitions](./examples/game-state-music-transitions.md)
|
|
3268
|
+
- [Duck Music Under Narration](./examples/duck-music-under-narration.md)
|
|
3269
|
+
- [UI SFX Without Assets](./examples/ui-sfx-without-assets.md)
|
|
3270
|
+
|
|
2775
3271
|
---
|
|
2776
3272
|
|
|
2777
3273
|
## @vielzeug/beacon
|
|
@@ -10234,6 +10730,7 @@ The owner that creates the form disposes it. Framework subscriptions own only th
|
|
|
10234
10730
|
- Form Submission (id: `form-submission`)
|
|
10235
10731
|
- Form and Field Subscriptions (id: `form-subscriptions`)
|
|
10236
10732
|
- Whole-Value Validation (id: `form-validation`)
|
|
10733
|
+
- Forge state + Refine elements (id: `refine-elements`)
|
|
10237
10734
|
- Nested Field Handles (id: `scoped-sub-forms`)
|
|
10238
10735
|
|
|
10239
10736
|
---
|
|
@@ -18129,6 +18626,11 @@ define('signup-form', {
|
|
|
18129
18626
|
- [Form Associated Rating Input](./examples/form-associated-rating-input.md)
|
|
18130
18627
|
- [Test Example With @vielzeug/ore/testing](./examples/test-example-at-vielzeug-ore-testing.md)
|
|
18131
18628
|
|
|
18629
|
+
### REPL Examples
|
|
18630
|
+
|
|
18631
|
+
- Counter chip (id: `counter-chip`)
|
|
18632
|
+
- Todo list (id: `todo-list`)
|
|
18633
|
+
|
|
18132
18634
|
---
|
|
18133
18635
|
|
|
18134
18636
|
## @vielzeug/patchwork
|
|
@@ -18455,6 +18957,7 @@ that is the `from` location when the source was missing.
|
|
|
18455
18957
|
- Apply - Immutable patches and guarded test (id: `apply-basic`)
|
|
18456
18958
|
- Diff - Structural patches (id: `diff-basic`)
|
|
18457
18959
|
- Merge - Three-way field-level reconciliation (id: `merge-basic`)
|
|
18960
|
+
- getIn - JSON Pointer Round-Trips (id: `pointers-basic`)
|
|
18458
18961
|
|
|
18459
18962
|
---
|
|
18460
18963
|
|
|
@@ -21372,6 +21875,11 @@ Use Refine components for dashboard controls and keep Prism in a sized host elem
|
|
|
21372
21875
|
- [Render a custom tooltip](./examples/custom-tooltip.md)
|
|
21373
21876
|
- [Match charts to your design system](./examples/theming.md)
|
|
21374
21877
|
|
|
21878
|
+
### REPL Examples
|
|
21879
|
+
|
|
21880
|
+
- Bar chart (id: `bar-chart`)
|
|
21881
|
+
- Line chart (id: `line-chart`)
|
|
21882
|
+
|
|
21375
21883
|
---
|
|
21376
21884
|
|
|
21377
21885
|
## @vielzeug/pulse
|
|
@@ -22991,6 +23499,11 @@ Use Necromancer directly when you need animation handles, groups, or explicit ke
|
|
|
22991
23499
|
- **Working with AI agents?** Install the `vielzeug` skill (`npx -y @vielzeug/codex skills install`) so agents reach for Refine components and tokens instead of custom widgets: see the [Codex usage guide](../codex/usage.md#agent-skill).
|
|
22992
23500
|
- **Rendering model-authored UI?** Validate it through the [on-demand UI document contract](./on-demand-ui) instead of trusting model output; never build DOM from unvalidated JSON.
|
|
22993
23501
|
|
|
23502
|
+
### REPL Examples
|
|
23503
|
+
|
|
23504
|
+
- Themed components (id: `components`)
|
|
23505
|
+
- Form controls (id: `form`)
|
|
23506
|
+
|
|
22994
23507
|
---
|
|
22995
23508
|
|
|
22996
23509
|
## @vielzeug/ripple
|
|
@@ -34149,6 +34662,10 @@ Pair `@vielzeug/ledger` on the host to give the commands tavern applies an undo
|
|
|
34149
34662
|
|
|
34150
34663
|
- [Share State Across Devices](./examples/share-state-across-devices.md)
|
|
34151
34664
|
|
|
34665
|
+
### REPL Examples
|
|
34666
|
+
|
|
34667
|
+
- Host & Guest Session (id: `session-basic`)
|
|
34668
|
+
|
|
34152
34669
|
---
|
|
34153
34670
|
|
|
34154
34671
|
## @vielzeug/tempo
|
package/data/llms.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Vielzeug
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> 47 focused TypeScript packages. Version: 26.11.18
|
|
4
4
|
|
|
5
5
|
Install any package independently: `pnpm add @vielzeug/<name>`
|
|
6
6
|
|
|
@@ -9,6 +9,7 @@ Install any package independently: `pnpm add @vielzeug/<name>`
|
|
|
9
9
|
- [@vielzeug/archive](/archive/): Community content publishing for Cloudflare Workers + D1: a hardened Worker core over per-collection payload schemas
|
|
10
10
|
- [@vielzeug/arsenal](/arsenal/): Tree-shakeable TypeScript utilities with focused category entry points for arrays, async work, caching, objects, strings, math, and guards.
|
|
11
11
|
- [@vielzeug/assay](/assay/): Scoped DOM queries, exact event dispatch, and cancellable async waiting for browser tests.
|
|
12
|
+
- [@vielzeug/bard](/bard/): Lifecycle-owned Web Audio mixing: buses with ducking, buffered SFX and sprites, procedural synth, streamed tracks, and crossfading music decks
|
|
12
13
|
- [@vielzeug/beacon](/beacon/): Guided onboarding and contextual product tours for web applications
|
|
13
14
|
- [@vielzeug/clockwork](/clockwork/): Framework-neutral typed state machines with pure transitions, actor-owned runtime work, timers, invokes, and explicit effects.
|
|
14
15
|
- [@vielzeug/codex](/codex/): Local MCP access to Vielzeug documentation and package metadata.
|
package/data/manifest.json
CHANGED