@vielzeug/bard 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +53 -2
- package/dist/_bus.cjs +2 -0
- package/dist/_bus.cjs.map +1 -0
- package/dist/_bus.d.ts +28 -0
- package/dist/_bus.d.ts.map +1 -0
- package/dist/_bus.js +108 -0
- package/dist/_bus.js.map +1 -0
- package/dist/_context.cjs +2 -0
- package/dist/_context.cjs.map +1 -0
- package/dist/_context.d.ts +22 -0
- package/dist/_context.d.ts.map +1 -0
- package/dist/_context.js +73 -0
- package/dist/_context.js.map +1 -0
- package/dist/_deck.cjs +2 -0
- package/dist/_deck.cjs.map +1 -0
- package/dist/_deck.d.ts +24 -0
- package/dist/_deck.d.ts.map +1 -0
- package/dist/_deck.js +166 -0
- package/dist/_deck.js.map +1 -0
- package/dist/_loader.cjs +2 -0
- package/dist/_loader.cjs.map +1 -0
- package/dist/_loader.d.ts +37 -0
- package/dist/_loader.d.ts.map +1 -0
- package/dist/_loader.js +88 -0
- package/dist/_loader.js.map +1 -0
- package/dist/_media-session.cjs +2 -0
- package/dist/_media-session.cjs.map +1 -0
- package/dist/_media-session.d.ts +23 -0
- package/dist/_media-session.d.ts.map +1 -0
- package/dist/_media-session.js +49 -0
- package/dist/_media-session.js.map +1 -0
- package/dist/_ramp.cjs +2 -0
- package/dist/_ramp.cjs.map +1 -0
- package/dist/_ramp.d.ts +20 -0
- package/dist/_ramp.d.ts.map +1 -0
- package/dist/_ramp.js +19 -0
- package/dist/_ramp.js.map +1 -0
- package/dist/_stream.cjs +2 -0
- package/dist/_stream.cjs.map +1 -0
- package/dist/_stream.d.ts +25 -0
- package/dist/_stream.d.ts.map +1 -0
- package/dist/_stream.js +46 -0
- package/dist/_stream.js.map +1 -0
- package/dist/_synth.cjs +2 -0
- package/dist/_synth.cjs.map +1 -0
- package/dist/_synth.d.ts +14 -0
- package/dist/_synth.d.ts.map +1 -0
- package/dist/_synth.js +101 -0
- package/dist/_synth.js.map +1 -0
- package/dist/_tappers.cjs +2 -0
- package/dist/_tappers.cjs.map +1 -0
- package/dist/_tappers.d.ts +23 -0
- package/dist/_tappers.d.ts.map +1 -0
- package/dist/_tappers.js +24 -0
- package/dist/_tappers.js.map +1 -0
- package/dist/_voices.cjs +2 -0
- package/dist/_voices.cjs.map +1 -0
- package/dist/_voices.d.ts +23 -0
- package/dist/_voices.d.ts.map +1 -0
- package/dist/_voices.js +110 -0
- package/dist/_voices.js.map +1 -0
- package/dist/bard.cjs +2 -0
- package/dist/bard.cjs.map +1 -0
- package/dist/bard.d.ts +8 -0
- package/dist/bard.d.ts.map +1 -0
- package/dist/bard.iife.js +2 -0
- package/dist/bard.iife.js.map +1 -0
- package/dist/bard.js +901 -0
- package/dist/bard.js.map +1 -0
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/testing/index.d.ts +146 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing.cjs +2 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.js +221 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +269 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +58 -4
package/dist/testing.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// src/testing/index.ts
|
|
2
|
+
var FakeEventTarget = class {
|
|
3
|
+
listeners = /* @__PURE__ */ new Map();
|
|
4
|
+
addEventListener(e, t) {
|
|
5
|
+
let n = this.listeners.get(e) ?? /* @__PURE__ */ new Set();
|
|
6
|
+
n.add(t), this.listeners.set(e, n);
|
|
7
|
+
}
|
|
8
|
+
removeEventListener(e, t) {
|
|
9
|
+
this.listeners.get(e)?.delete(t);
|
|
10
|
+
}
|
|
11
|
+
dispatchEvent(e) {
|
|
12
|
+
for (let t of [...this.listeners.get(e) ?? []]) t();
|
|
13
|
+
}
|
|
14
|
+
}, FakeAudioParam = class {
|
|
15
|
+
value;
|
|
16
|
+
constructor(e = 0) {
|
|
17
|
+
this.value = e;
|
|
18
|
+
}
|
|
19
|
+
calls = [];
|
|
20
|
+
setValueAtTime(e, t) {
|
|
21
|
+
return this.calls.push({
|
|
22
|
+
method: "setValueAtTime",
|
|
23
|
+
time: t,
|
|
24
|
+
value: e
|
|
25
|
+
}), this.value = e, this;
|
|
26
|
+
}
|
|
27
|
+
linearRampToValueAtTime(e, t) {
|
|
28
|
+
return this.calls.push({
|
|
29
|
+
method: "linearRampToValueAtTime",
|
|
30
|
+
time: t,
|
|
31
|
+
value: e
|
|
32
|
+
}), this.value = e, this;
|
|
33
|
+
}
|
|
34
|
+
exponentialRampToValueAtTime(e, t) {
|
|
35
|
+
if (e === 0) throw RangeError("exponentialRampToValueAtTime target must not be 0.");
|
|
36
|
+
return this.calls.push({
|
|
37
|
+
method: "exponentialRampToValueAtTime",
|
|
38
|
+
time: t,
|
|
39
|
+
value: e
|
|
40
|
+
}), this.value = e, this;
|
|
41
|
+
}
|
|
42
|
+
cancelScheduledValues(e) {
|
|
43
|
+
return this.calls.push({
|
|
44
|
+
method: "cancelScheduledValues",
|
|
45
|
+
time: e,
|
|
46
|
+
value: this.value
|
|
47
|
+
}), this;
|
|
48
|
+
}
|
|
49
|
+
used(e) {
|
|
50
|
+
return this.calls.some((t) => t.method === e);
|
|
51
|
+
}
|
|
52
|
+
}, FakeAudioNode = class extends FakeEventTarget {
|
|
53
|
+
connections = [];
|
|
54
|
+
disconnected = 0;
|
|
55
|
+
context;
|
|
56
|
+
constructor(e) {
|
|
57
|
+
super(), this.context = e ?? this;
|
|
58
|
+
}
|
|
59
|
+
connect(e) {
|
|
60
|
+
return this.connections.push(e), e;
|
|
61
|
+
}
|
|
62
|
+
disconnect() {
|
|
63
|
+
this.disconnected += 1, this.connections.length = 0;
|
|
64
|
+
}
|
|
65
|
+
}, FakeGainNode = class extends FakeAudioNode {
|
|
66
|
+
gain = new FakeAudioParam(1);
|
|
67
|
+
}, FakeStereoPannerNode = class extends FakeAudioNode {
|
|
68
|
+
pan = new FakeAudioParam();
|
|
69
|
+
}, FakeBiquadFilterNode = class extends FakeAudioNode {
|
|
70
|
+
frequency = new FakeAudioParam();
|
|
71
|
+
Q = new FakeAudioParam();
|
|
72
|
+
type = "lowpass";
|
|
73
|
+
}, FakeScheduledSourceNode = class extends FakeAudioNode {
|
|
74
|
+
started = [];
|
|
75
|
+
stops = [];
|
|
76
|
+
onended = null;
|
|
77
|
+
startedAt = null;
|
|
78
|
+
stopAt = null;
|
|
79
|
+
start(e = 0, t, n) {
|
|
80
|
+
if (this.startedAt !== null) throw Error("start() called twice on the same source.");
|
|
81
|
+
this.startedAt = e, this.started.push({
|
|
82
|
+
duration: n,
|
|
83
|
+
offset: t,
|
|
84
|
+
when: e
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
stop(e = 0) {
|
|
88
|
+
if (this.startedAt === null) throw Error("stop() called before start().");
|
|
89
|
+
this.stops.push(e), this.stopAt = this.stopAt === null ? e : Math.min(this.stopAt, e);
|
|
90
|
+
}
|
|
91
|
+
emitEnded() {
|
|
92
|
+
this.onended?.(), this.dispatchEvent("ended");
|
|
93
|
+
}
|
|
94
|
+
}, FakeAudioBufferSourceNode = class extends FakeScheduledSourceNode {
|
|
95
|
+
buffer = null;
|
|
96
|
+
loop = !1;
|
|
97
|
+
loopStart = 0;
|
|
98
|
+
loopEnd = 0;
|
|
99
|
+
playbackRate = new FakeAudioParam();
|
|
100
|
+
detune = new FakeAudioParam();
|
|
101
|
+
}, FakeOscillatorNode = class extends FakeScheduledSourceNode {
|
|
102
|
+
type = "sine";
|
|
103
|
+
frequency = new FakeAudioParam();
|
|
104
|
+
detune = new FakeAudioParam();
|
|
105
|
+
}, FakeMediaElementSourceNode = class extends FakeAudioNode {
|
|
106
|
+
element;
|
|
107
|
+
constructor(e, t) {
|
|
108
|
+
super(e), this.element = t;
|
|
109
|
+
}
|
|
110
|
+
}, FakeAudioBuffer = class {
|
|
111
|
+
duration;
|
|
112
|
+
length;
|
|
113
|
+
sampleRate;
|
|
114
|
+
numberOfChannels;
|
|
115
|
+
constructor(e, t, n) {
|
|
116
|
+
this.length = e, this.sampleRate = t, this.numberOfChannels = n, this.duration = e / t;
|
|
117
|
+
}
|
|
118
|
+
getChannelData() {
|
|
119
|
+
return new Float32Array(this.length);
|
|
120
|
+
}
|
|
121
|
+
}, FakeAudioContext = class extends FakeAudioNode {
|
|
122
|
+
destination = new FakeAudioNode(this);
|
|
123
|
+
sampleRate = 44100;
|
|
124
|
+
currentTime = 0;
|
|
125
|
+
state = "suspended";
|
|
126
|
+
closed = !1;
|
|
127
|
+
nodes = [];
|
|
128
|
+
sources = [];
|
|
129
|
+
decodeCalls = 0;
|
|
130
|
+
createGain() {
|
|
131
|
+
return this.track(new FakeGainNode(this));
|
|
132
|
+
}
|
|
133
|
+
createStereoPanner() {
|
|
134
|
+
return this.track(new FakeStereoPannerNode(this));
|
|
135
|
+
}
|
|
136
|
+
createBiquadFilter() {
|
|
137
|
+
return this.track(new FakeBiquadFilterNode(this));
|
|
138
|
+
}
|
|
139
|
+
createBufferSource() {
|
|
140
|
+
return this.trackSource(new FakeAudioBufferSourceNode(this));
|
|
141
|
+
}
|
|
142
|
+
createOscillator() {
|
|
143
|
+
return this.trackSource(new FakeOscillatorNode(this));
|
|
144
|
+
}
|
|
145
|
+
createBuffer(e, t, n) {
|
|
146
|
+
return new FakeAudioBuffer(t, n, e);
|
|
147
|
+
}
|
|
148
|
+
createMediaElementSource(e) {
|
|
149
|
+
return this.track(new FakeMediaElementSourceNode(this, e));
|
|
150
|
+
}
|
|
151
|
+
async decodeAudioData(e) {
|
|
152
|
+
return this.decodeCalls += 1, new FakeAudioBuffer(44100, this.sampleRate, 1);
|
|
153
|
+
}
|
|
154
|
+
async resume() {
|
|
155
|
+
this.setState("running");
|
|
156
|
+
}
|
|
157
|
+
async suspend() {
|
|
158
|
+
this.setState("suspended");
|
|
159
|
+
}
|
|
160
|
+
async close() {
|
|
161
|
+
this.closed = !0, this.setState("closed");
|
|
162
|
+
}
|
|
163
|
+
setState(e) {
|
|
164
|
+
this.state = e, this.dispatchEvent("statechange");
|
|
165
|
+
}
|
|
166
|
+
advance(e) {
|
|
167
|
+
this.currentTime += e;
|
|
168
|
+
for (let e of [...this.sources]) e.stopAt !== null && e.stopAt <= this.currentTime && (e.stopAt = null, e.emitEnded());
|
|
169
|
+
}
|
|
170
|
+
track(e) {
|
|
171
|
+
return this.nodes.push(e), e;
|
|
172
|
+
}
|
|
173
|
+
trackSource(e) {
|
|
174
|
+
return this.nodes.push(e), this.sources.push(e), e;
|
|
175
|
+
}
|
|
176
|
+
}, FakeMediaElement = class extends FakeAudioNode {
|
|
177
|
+
src = "";
|
|
178
|
+
crossOrigin = "";
|
|
179
|
+
preload = "";
|
|
180
|
+
loop = !1;
|
|
181
|
+
playing = !1;
|
|
182
|
+
currentTime = 0;
|
|
183
|
+
duration = 10;
|
|
184
|
+
constructor(e) {
|
|
185
|
+
super(e);
|
|
186
|
+
}
|
|
187
|
+
play() {
|
|
188
|
+
return this.playing = !0, Promise.resolve();
|
|
189
|
+
}
|
|
190
|
+
pause() {
|
|
191
|
+
this.playing = !1;
|
|
192
|
+
}
|
|
193
|
+
removeAttribute(e) {
|
|
194
|
+
e === "src" && (this.src = "");
|
|
195
|
+
}
|
|
196
|
+
emitCanPlay() {
|
|
197
|
+
this.dispatchEvent("canplay");
|
|
198
|
+
}
|
|
199
|
+
emitError() {
|
|
200
|
+
this.dispatchEvent("error");
|
|
201
|
+
}
|
|
202
|
+
emitEnded() {
|
|
203
|
+
this.playing = !1, this.dispatchEvent("ended");
|
|
204
|
+
}
|
|
205
|
+
tick(e) {
|
|
206
|
+
this.currentTime += e, this.dispatchEvent("timeupdate");
|
|
207
|
+
}
|
|
208
|
+
}, FakeMediaSession = class {
|
|
209
|
+
metadata = null;
|
|
210
|
+
playbackState = "none";
|
|
211
|
+
handlers = /* @__PURE__ */ new Map();
|
|
212
|
+
setActionHandler(e, t) {
|
|
213
|
+
this.handlers.set(e, t);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
function flush() {
|
|
217
|
+
return new Promise((e) => setTimeout(e, 0));
|
|
218
|
+
}
|
|
219
|
+
export { FakeAudioBuffer, FakeAudioBufferSourceNode, FakeAudioContext, FakeAudioNode, FakeAudioParam, FakeBiquadFilterNode, FakeEventTarget, FakeGainNode, FakeMediaElement, FakeMediaElementSourceNode, FakeMediaSession, FakeOscillatorNode, FakeScheduledSourceNode, FakeStereoPannerNode, flush };
|
|
220
|
+
|
|
221
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","names":["set","type","listener","initial","value","call","method","context","destination","when","element","length","sampleRate","numberOfChannels","channels","state","seconds","source","node","name","action","handler","resolve"],"sources":["../src/testing/index.ts"],"sourcesContent":["/**\n * Deterministic Web Audio fakes for testing code that consumes `@vielzeug/bard`\n * (and bard's own suite). No audio is produced; the fake context exposes a\n * manual clock (`advance`) and records every graph mutation and param\n * automation so tests can assert on behavior instead of sound.\n */\n\n/** Tiny listener registry so fakes avoid DOM event plumbing. */\nexport class FakeEventTarget {\n private readonly listeners = new Map<string, Set<() => void>>();\n\n addEventListener(type: string, listener: () => void): void {\n const set = this.listeners.get(type) ?? new Set();\n set.add(listener);\n this.listeners.set(type, set);\n }\n removeEventListener(type: string, listener: () => void): void {\n this.listeners.get(type)?.delete(listener);\n }\n dispatchEvent(type: string): void {\n for (const listener of [...(this.listeners.get(type) ?? [])]) listener();\n }\n}\n\nexport interface AutomationCall {\n readonly method:\n | 'setValueAtTime'\n | 'linearRampToValueAtTime'\n | 'exponentialRampToValueAtTime'\n | 'cancelScheduledValues';\n readonly time: number;\n readonly value: number;\n}\n\nexport class FakeAudioParam {\n value: number;\n\n constructor(initial = 0) {\n this.value = initial;\n }\n readonly calls: AutomationCall[] = [];\n\n setValueAtTime(value: number, time: number): this {\n this.calls.push({ method: 'setValueAtTime', time, value });\n this.value = value;\n return this;\n }\n linearRampToValueAtTime(value: number, time: number): this {\n this.calls.push({ method: 'linearRampToValueAtTime', time, value });\n this.value = value;\n return this;\n }\n exponentialRampToValueAtTime(value: number, time: number): this {\n if (value === 0) throw new RangeError('exponentialRampToValueAtTime target must not be 0.');\n this.calls.push({ method: 'exponentialRampToValueAtTime', time, value });\n this.value = value;\n return this;\n }\n cancelScheduledValues(time: number): this {\n this.calls.push({ method: 'cancelScheduledValues', time, value: this.value });\n return this;\n }\n /** True when any recorded call used `method`. */\n used(method: AutomationCall['method']): boolean {\n return this.calls.some((call) => call.method === method);\n }\n}\n\nexport class FakeAudioNode extends FakeEventTarget {\n readonly connections: FakeAudioNode[] = [];\n disconnected = 0;\n readonly context: FakeAudioContext;\n\n constructor(context?: FakeAudioContext) {\n super();\n // A FakeAudioContext *is* the context for its own nodes.\n this.context = context ?? (this as unknown as FakeAudioContext);\n }\n\n connect(destination: FakeAudioNode): FakeAudioNode {\n this.connections.push(destination);\n return destination;\n }\n\n disconnect(): void {\n this.disconnected += 1;\n this.connections.length = 0;\n }\n}\n\nexport class FakeGainNode extends FakeAudioNode {\n /** Real GainNodes default to unity gain. */\n readonly gain = new FakeAudioParam(1);\n}\n\nexport class FakeStereoPannerNode extends FakeAudioNode {\n readonly pan = new FakeAudioParam();\n}\n\nexport class FakeBiquadFilterNode extends FakeAudioNode {\n readonly frequency = new FakeAudioParam();\n readonly Q = new FakeAudioParam();\n type: BiquadFilterType = 'lowpass';\n}\n\nexport interface StartCall {\n readonly duration?: number;\n readonly offset?: number;\n readonly when: number;\n}\n\nexport class FakeScheduledSourceNode extends FakeAudioNode {\n readonly started: StartCall[] = [];\n readonly stops: number[] = [];\n onended: (() => void) | null = null;\n startedAt: number | null = null;\n stopAt: number | null = null;\n\n start(when = 0, offset?: number, duration?: number): void {\n if (this.startedAt !== null) throw new Error('start() called twice on the same source.');\n this.startedAt = when;\n this.started.push({ duration, offset, when });\n }\n\n stop(when = 0): void {\n if (this.startedAt === null) throw new Error('stop() called before start().');\n this.stops.push(when);\n this.stopAt = this.stopAt === null ? when : Math.min(this.stopAt, when);\n }\n\n /** Fires the `ended` path (listener and `onended`) once. */\n emitEnded(): void {\n this.onended?.();\n this.dispatchEvent('ended');\n }\n}\n\nexport class FakeAudioBufferSourceNode extends FakeScheduledSourceNode {\n buffer: FakeAudioBuffer | null = null;\n loop = false;\n loopStart = 0;\n loopEnd = 0;\n readonly playbackRate = new FakeAudioParam();\n readonly detune = new FakeAudioParam();\n}\n\nexport class FakeOscillatorNode extends FakeScheduledSourceNode {\n type: OscillatorType = 'sine';\n readonly frequency = new FakeAudioParam();\n readonly detune = new FakeAudioParam();\n}\n\nexport class FakeMediaElementSourceNode extends FakeAudioNode {\n readonly element: FakeMediaElement;\n\n constructor(context: FakeAudioContext, element: FakeMediaElement) {\n super(context);\n this.element = element;\n }\n}\n\nexport class FakeAudioBuffer {\n readonly duration: number;\n readonly length: number;\n readonly sampleRate: number;\n readonly numberOfChannels: number;\n\n constructor(length: number, sampleRate: number, numberOfChannels: number) {\n this.length = length;\n this.sampleRate = sampleRate;\n this.numberOfChannels = numberOfChannels;\n this.duration = length / sampleRate;\n }\n\n getChannelData(): Float32Array {\n return new Float32Array(this.length);\n }\n}\n\nexport class FakeAudioContext extends FakeAudioNode {\n readonly destination = new FakeAudioNode(this);\n readonly sampleRate = 44100;\n currentTime = 0;\n state: AudioContextState = 'suspended';\n closed = false;\n readonly nodes: FakeAudioNode[] = [];\n /** Every source created here, for clock-driven `ended` dispatch. */\n readonly sources: FakeScheduledSourceNode[] = [];\n decodeCalls = 0;\n\n createGain(): FakeGainNode {\n return this.track(new FakeGainNode(this));\n }\n createStereoPanner(): FakeStereoPannerNode {\n return this.track(new FakeStereoPannerNode(this));\n }\n createBiquadFilter(): FakeBiquadFilterNode {\n return this.track(new FakeBiquadFilterNode(this));\n }\n createBufferSource(): FakeAudioBufferSourceNode {\n return this.trackSource(new FakeAudioBufferSourceNode(this));\n }\n createOscillator(): FakeOscillatorNode {\n return this.trackSource(new FakeOscillatorNode(this));\n }\n createBuffer(channels: number, length: number, sampleRate: number): FakeAudioBuffer {\n return new FakeAudioBuffer(length, sampleRate, channels);\n }\n createMediaElementSource(element: FakeMediaElement): FakeMediaElementSourceNode {\n return this.track(new FakeMediaElementSourceNode(this, element));\n }\n\n async decodeAudioData(_data: ArrayBuffer): Promise<FakeAudioBuffer> {\n this.decodeCalls += 1;\n return new FakeAudioBuffer(44100, this.sampleRate, 1);\n }\n\n async resume(): Promise<void> {\n this.setState('running');\n }\n async suspend(): Promise<void> {\n this.setState('suspended');\n }\n async close(): Promise<void> {\n this.closed = true;\n this.setState('closed');\n }\n\n setState(state: AudioContextState): void {\n this.state = state;\n this.dispatchEvent('statechange');\n }\n\n /** Moves the clock and fires `ended` for sources whose stop time passed. */\n advance(seconds: number): void {\n this.currentTime += seconds;\n for (const source of [...this.sources]) {\n if (source.stopAt !== null && source.stopAt <= this.currentTime) {\n source.stopAt = null;\n source.emitEnded();\n }\n }\n }\n\n private track<T extends FakeAudioNode>(node: T): T {\n this.nodes.push(node);\n return node;\n }\n private trackSource<T extends FakeScheduledSourceNode>(node: T): T {\n this.nodes.push(node);\n this.sources.push(node);\n return node;\n }\n}\n\n/** Minimal `HTMLAudioElement` stand-in: playback flags, clock, and events. */\nexport class FakeMediaElement extends FakeAudioNode {\n src = '';\n crossOrigin = '';\n preload = '';\n loop = false;\n playing = false;\n currentTime = 0;\n duration = 10;\n\n constructor(context?: FakeAudioContext) {\n super(context as FakeAudioContext);\n }\n\n play(): Promise<void> {\n this.playing = true;\n return Promise.resolve();\n }\n pause(): void {\n this.playing = false;\n }\n removeAttribute(name: string): void {\n if (name === 'src') this.src = '';\n }\n\n /** Fires `canplay` so pending stream-ready promises settle. */\n emitCanPlay(): void {\n this.dispatchEvent('canplay');\n }\n emitError(): void {\n this.dispatchEvent('error');\n }\n emitEnded(): void {\n this.playing = false;\n this.dispatchEvent('ended');\n }\n tick(seconds: number): void {\n this.currentTime += seconds;\n this.dispatchEvent('timeupdate');\n }\n}\n\n/** Records Media Session claims so tests can assert single ownership. */\nexport class FakeMediaSession {\n metadata: unknown = null;\n playbackState: MediaSessionPlaybackState = 'none';\n readonly handlers = new Map<string, (() => void) | null>();\n\n setActionHandler(action: string, handler: (() => void) | null): void {\n this.handlers.set(action, handler);\n }\n}\n\n/** Lets queued microtasks and zero-delay timers settle. */\nexport function flush(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, 0));\n}\n"],"mappings":";AAQA,IAAa,kBAAb,MAA6B;CAC3B,4BAA6B,IAAI,IAA6B;CAE9D,iBAAiB,GAAc,GAA4B;EACzD,IAAMA,IAAM,KAAK,UAAU,IAAIC,CAAI,qBAAK,IAAI,IAAI;EAEhD,AADAD,EAAI,IAAIE,CAAQ,GAChB,KAAK,UAAU,IAAID,GAAMD,CAAG;CAC9B;CACA,oBAAoB,GAAc,GAA4B;EAC5D,KAAK,UAAU,IAAIC,CAAI,CAAC,EAAE,OAAOC,CAAQ;CAC3C;CACA,cAAc,GAAoB;EAChC,KAAK,IAAMA,KAAY,CAAC,GAAI,KAAK,UAAU,IAAID,CAAI,KAAK,CAAC,CAAE,GAAG,EAAS;CACzE;AACF,GAYa,iBAAb,MAA4B;CAC1B;CAEA,YAAY,IAAU,GAAG;EACvB,KAAK,QAAQE;CACf;CACA,QAAmC,CAAC;CAEpC,eAAe,GAAe,GAAoB;EAGhD,OAFA,KAAK,MAAM,KAAK;GAAE,QAAQ;GAAkB;GAAM;EAAM,CAAC,GACzD,KAAK,QAAQC,GACN;CACT;CACA,wBAAwB,GAAe,GAAoB;EAGzD,OAFA,KAAK,MAAM,KAAK;GAAE,QA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jB;CACA,gBAAgB,GAAoB;EAClC,AAAIY,MAAS,UAAO,KAAK,MAAM;CACjC;CAGA,cAAoB;EAClB,KAAK,cAAc,SAAS;CAC9B;CACA,YAAkB;EAChB,KAAK,cAAc,OAAO;CAC5B;CACA,YAAkB;EAEhB,AADA,KAAK,UAAU,IACf,KAAK,cAAc,OAAO;CAC5B;CACA,KAAK,GAAuB;EAE1B,AADA,KAAK,eAAeH,GACpB,KAAK,cAAc,YAAY;CACjC;AACF,GAGa,mBAAb,MAA8B;CAC5B,WAAoB;CACpB,gBAA2C;CAC3C,2BAAoB,IAAI,IAAiC;CAEzD,iBAAiB,GAAgB,GAAoC;EACnE,KAAK,SAAS,IAAII,GAAQC,CAAO;CACnC;AACF;AAGA,SAAgB,QAAuB;CACrC,OAAO,IAAI,SAAS,MAAY,WAAWC,GAAS,CAAC,CAAC;AACxD"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for `@vielzeug/bard`.
|
|
3
|
+
*/
|
|
4
|
+
/** Lifecycle state of the engine's audio context. */
|
|
5
|
+
export type BardState = 'idle' | 'suspended' | 'running' | 'interrupted' | 'closed';
|
|
6
|
+
/** One artwork entry for Media Session metadata. */
|
|
7
|
+
export interface MediaImage {
|
|
8
|
+
readonly sizes?: string;
|
|
9
|
+
readonly src: string;
|
|
10
|
+
readonly type?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Descriptive metadata for an asset, used by Media Session integration. */
|
|
13
|
+
export interface AssetMeta {
|
|
14
|
+
readonly album?: string;
|
|
15
|
+
readonly artist?: string;
|
|
16
|
+
readonly artwork?: readonly MediaImage[];
|
|
17
|
+
readonly title?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Full form of a manifest entry. */
|
|
20
|
+
export interface AssetDefinition {
|
|
21
|
+
readonly meta?: AssetMeta;
|
|
22
|
+
/** Named regions `[startSec, durationSec]` inside the file, played as `"key:name"`. */
|
|
23
|
+
readonly sprites?: Readonly<Record<string, readonly [start: number, duration: number]>>;
|
|
24
|
+
readonly src: string;
|
|
25
|
+
/**
|
|
26
|
+
* Stream through an owned `HTMLAudioElement` instead of decoding into an
|
|
27
|
+
* `AudioBuffer`. Deck-only: `play()` on a streamed key throws.
|
|
28
|
+
*/
|
|
29
|
+
readonly stream?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** A manifest maps sound keys to a URL or a full definition. */
|
|
32
|
+
export type AssetManifest = Readonly<Record<string, string | AssetDefinition>>;
|
|
33
|
+
/** Options for {@link SoundHandle.stop} and volume ramps. */
|
|
34
|
+
export interface FadeOptions {
|
|
35
|
+
/** Crossfade seconds; defaults to a 15 ms micro-fade that avoids clicks. */
|
|
36
|
+
readonly fade?: number;
|
|
37
|
+
}
|
|
38
|
+
/** A lightweight control over one started sound. */
|
|
39
|
+
export interface SoundHandle {
|
|
40
|
+
/** Stops immediately and releases the owned nodes. */
|
|
41
|
+
dispose(): void;
|
|
42
|
+
readonly disposed: boolean;
|
|
43
|
+
/** Resolves once the sound has ended, been stopped, or been disposed. */
|
|
44
|
+
readonly finished: Promise<void>;
|
|
45
|
+
/** Sets the stereo pan (-1..1). */
|
|
46
|
+
setPan(pan: number): void;
|
|
47
|
+
/** Ramps the voice volume (linear 0..1). */
|
|
48
|
+
setVolume(volume: number, options?: FadeOptions): void;
|
|
49
|
+
/** Fades out and stops the sound; the fade defaults to a click-free micro-fade. */
|
|
50
|
+
stop(options?: FadeOptions): void;
|
|
51
|
+
/** Calls {@link SoundHandle.dispose}. */
|
|
52
|
+
[Symbol.dispose](): void;
|
|
53
|
+
}
|
|
54
|
+
/** Options for {@link Bard.play}. */
|
|
55
|
+
export interface PlayOptions {
|
|
56
|
+
/** Destination bus; defaults to `'sfx'`. */
|
|
57
|
+
readonly bus?: string;
|
|
58
|
+
/** Detune in cents, or a `[min, max]` range sampled per voice. */
|
|
59
|
+
readonly detune?: number | readonly [min: number, max: number];
|
|
60
|
+
/** Fade-in seconds from 0 to `volume`. */
|
|
61
|
+
readonly fadeIn?: number;
|
|
62
|
+
/** Loop the buffer (or the sprite region when combined with `loopStart`/`loopEnd`). */
|
|
63
|
+
readonly loop?: boolean;
|
|
64
|
+
/** Loop end in buffer seconds (absolute, not sprite-relative). */
|
|
65
|
+
readonly loopEnd?: number;
|
|
66
|
+
/** Loop start in buffer seconds (absolute, not sprite-relative). */
|
|
67
|
+
readonly loopStart?: number;
|
|
68
|
+
/** Concurrent voice cap for this key; unlimited when omitted (the global cap still applies). */
|
|
69
|
+
readonly maxVoices?: number;
|
|
70
|
+
/** Start offset in seconds. */
|
|
71
|
+
readonly offset?: number;
|
|
72
|
+
/** Initial stereo pan (-1..1). */
|
|
73
|
+
readonly pan?: number;
|
|
74
|
+
/** Random source for range sampling; inject a deterministic one in tests. */
|
|
75
|
+
readonly random?: () => number;
|
|
76
|
+
/**
|
|
77
|
+
* Playback rate, or a `[min, max]` range sampled per voice. Note: rate
|
|
78
|
+
* shifts pitch on buffer sources; pitch-preserving playback belongs on an
|
|
79
|
+
* `HTMLAudioElement`.
|
|
80
|
+
*/
|
|
81
|
+
readonly rate?: number | readonly [min: number, max: number];
|
|
82
|
+
/** Linear volume 0..1; defaults to 1. */
|
|
83
|
+
readonly volume?: number;
|
|
84
|
+
}
|
|
85
|
+
/** A cross-bus ducking rule: while `source` has active voices, `target` ducks to `gain`. */
|
|
86
|
+
export interface DuckingRule {
|
|
87
|
+
/** Seconds to reach the duck level; defaults to 0.2. */
|
|
88
|
+
readonly attack?: number;
|
|
89
|
+
/** Duck level as linear gain 0..1. */
|
|
90
|
+
readonly gain: number;
|
|
91
|
+
/** Seconds to return to 1; defaults to 0.8. */
|
|
92
|
+
readonly release?: number;
|
|
93
|
+
readonly source: string;
|
|
94
|
+
readonly target: string;
|
|
95
|
+
}
|
|
96
|
+
/** Control over one mixing bus. */
|
|
97
|
+
export interface BusController {
|
|
98
|
+
/** Current duck level (linear gain; 1 means unducked). */
|
|
99
|
+
readonly duckLevel: number;
|
|
100
|
+
mute(): void;
|
|
101
|
+
readonly muted: boolean;
|
|
102
|
+
readonly name: string;
|
|
103
|
+
setVolume(volume: number, options?: FadeOptions): void;
|
|
104
|
+
unmute(): void;
|
|
105
|
+
/** Current user volume (linear 0..1). */
|
|
106
|
+
readonly volume: number;
|
|
107
|
+
}
|
|
108
|
+
/** Waveform for {@link SynthOptions}; `'noise'` plays a cached white-noise buffer. */
|
|
109
|
+
export type SynthWaveform = 'sine' | 'square' | 'sawtooth' | 'triangle' | 'noise';
|
|
110
|
+
/** ADSR envelope in seconds; `sustain` is a 0..1 level. */
|
|
111
|
+
export interface SynthEnvelope {
|
|
112
|
+
readonly attack?: number;
|
|
113
|
+
readonly decay?: number;
|
|
114
|
+
readonly release?: number;
|
|
115
|
+
readonly sustain?: number;
|
|
116
|
+
}
|
|
117
|
+
/** Biquad filter stage for {@link SynthOptions}. A tuple sweeps the cutoff. */
|
|
118
|
+
export interface SynthFilter {
|
|
119
|
+
readonly frequency: number | readonly [from: number, to: number];
|
|
120
|
+
readonly q?: number;
|
|
121
|
+
readonly type: BiquadFilterType;
|
|
122
|
+
}
|
|
123
|
+
/** Options for {@link Bard.synth}. */
|
|
124
|
+
export interface SynthOptions {
|
|
125
|
+
/** Destination bus; defaults to `'sfx'`. */
|
|
126
|
+
readonly bus?: string;
|
|
127
|
+
/** Detune in cents (oscillator only). */
|
|
128
|
+
readonly detune?: number;
|
|
129
|
+
/** Total audible length in seconds including the release; defaults to 0.3. */
|
|
130
|
+
readonly duration?: number;
|
|
131
|
+
readonly envelope?: SynthEnvelope;
|
|
132
|
+
readonly filter?: SynthFilter;
|
|
133
|
+
/** Frequency in Hz, or a `[from, to]` exponential sweep. For `'noise'` it maps to the filter cutoff. */
|
|
134
|
+
readonly freq?: number | readonly [from: number, to: number];
|
|
135
|
+
readonly pan?: number;
|
|
136
|
+
readonly type?: SynthWaveform;
|
|
137
|
+
readonly volume?: number;
|
|
138
|
+
}
|
|
139
|
+
/** Options for {@link MusicDeck.transition}. */
|
|
140
|
+
export interface TransitionOptions {
|
|
141
|
+
/** Crossfade seconds; defaults to the deck's `fade`. */
|
|
142
|
+
readonly fade?: number;
|
|
143
|
+
readonly loop?: boolean;
|
|
144
|
+
readonly loopEnd?: number;
|
|
145
|
+
readonly loopStart?: number;
|
|
146
|
+
/** Start offset in seconds (buffered assets; streamed assets seek too). */
|
|
147
|
+
readonly offset?: number;
|
|
148
|
+
}
|
|
149
|
+
/** Options for {@link MusicDeck.queue}. */
|
|
150
|
+
export interface QueueOptions {
|
|
151
|
+
/** Seconds of overlap before each track end; defaults to the deck's `fade`. */
|
|
152
|
+
readonly crossfade?: number;
|
|
153
|
+
/** Random source for the shuffle; inject a deterministic one in tests. */
|
|
154
|
+
readonly random?: () => number;
|
|
155
|
+
readonly repeat?: boolean;
|
|
156
|
+
readonly shuffle?: boolean;
|
|
157
|
+
}
|
|
158
|
+
/** A two-slot crossfading music deck. */
|
|
159
|
+
export interface MusicDeck {
|
|
160
|
+
/** The key currently playing, or `null`. */
|
|
161
|
+
readonly current: string | null;
|
|
162
|
+
dispose(): void;
|
|
163
|
+
readonly disposed: boolean;
|
|
164
|
+
/** Crossfades to the next queued track; a no-op without a queue. */
|
|
165
|
+
next(): void;
|
|
166
|
+
pause(): void;
|
|
167
|
+
play(): void;
|
|
168
|
+
readonly playing: boolean;
|
|
169
|
+
/** Crossfades to the previous queued track; a no-op without a queue. */
|
|
170
|
+
previous(): void;
|
|
171
|
+
/** Replaces the queue and starts its first track with a crossfade. */
|
|
172
|
+
queue(keys: readonly string[], options?: QueueOptions): void;
|
|
173
|
+
stop(options?: FadeOptions): void;
|
|
174
|
+
/**
|
|
175
|
+
* Crossfades to `key`. Transitioning to the key that is already live is a
|
|
176
|
+
* no-op; the deck's own `pause`/`play`/`stop` control playback, so this
|
|
177
|
+
* returns nothing.
|
|
178
|
+
*/
|
|
179
|
+
transition(key: string, options?: TransitionOptions): void;
|
|
180
|
+
/** Calls {@link MusicDeck.dispose}. */
|
|
181
|
+
[Symbol.dispose](): void;
|
|
182
|
+
}
|
|
183
|
+
/** Options for {@link Bard.createDeck}. */
|
|
184
|
+
export interface DeckOptions {
|
|
185
|
+
/** Destination bus; defaults to `'music'`. */
|
|
186
|
+
readonly bus?: string;
|
|
187
|
+
/** Default crossfade seconds; defaults to 2. */
|
|
188
|
+
readonly fade?: number;
|
|
189
|
+
/** Claim `navigator.mediaSession` for this deck; at most one deck may own it. */
|
|
190
|
+
readonly mediaSession?: boolean;
|
|
191
|
+
}
|
|
192
|
+
/** Options for {@link createBard}. */
|
|
193
|
+
export interface BardOptions {
|
|
194
|
+
/** Suspend when the page hides and resume when it shows again; defaults to false. */
|
|
195
|
+
readonly autoSuspendOnHidden?: boolean;
|
|
196
|
+
/** Attach gesture listeners that resume a suspended context on first interaction; defaults to true. */
|
|
197
|
+
readonly autoUnlock?: boolean;
|
|
198
|
+
/** User bus names; defaults to `['music', 'sfx', 'voice']`. `'master'` is implicit and reserved. */
|
|
199
|
+
readonly buses?: readonly string[];
|
|
200
|
+
/** Context factory; defaults to a lazily constructed `AudioContext`. Injection seam for tests. */
|
|
201
|
+
readonly context?: () => AudioContext;
|
|
202
|
+
readonly ducking?: readonly DuckingRule[];
|
|
203
|
+
/** Global concurrent voice cap; defaults to 32. */
|
|
204
|
+
readonly maxVoices?: number;
|
|
205
|
+
/** Master volume (linear 0..1); defaults to 1. */
|
|
206
|
+
readonly volume?: number;
|
|
207
|
+
}
|
|
208
|
+
/** Observability events emitted through {@link Bard.tap}. */
|
|
209
|
+
export type BardEvent = {
|
|
210
|
+
readonly type: 'state';
|
|
211
|
+
readonly state: BardState;
|
|
212
|
+
} | {
|
|
213
|
+
readonly type: 'load';
|
|
214
|
+
readonly key: string;
|
|
215
|
+
} | {
|
|
216
|
+
readonly type: 'load-error';
|
|
217
|
+
readonly key: string;
|
|
218
|
+
readonly error: unknown;
|
|
219
|
+
} | {
|
|
220
|
+
readonly type: 'steal';
|
|
221
|
+
readonly key: string | null;
|
|
222
|
+
} | {
|
|
223
|
+
readonly type: 'duck';
|
|
224
|
+
readonly bus: string;
|
|
225
|
+
readonly level: number;
|
|
226
|
+
readonly ramp: number;
|
|
227
|
+
} | {
|
|
228
|
+
readonly type: 'track';
|
|
229
|
+
readonly key: string | null;
|
|
230
|
+
} | {
|
|
231
|
+
readonly type: 'dispose';
|
|
232
|
+
};
|
|
233
|
+
/** The engine returned by `createBard()`. */
|
|
234
|
+
export interface Bard {
|
|
235
|
+
/** The controller for a bus; throws `BardError` for unknown names. */
|
|
236
|
+
bus(name: string): BusController;
|
|
237
|
+
/** The native context for advanced graph work; `null` until first use. */
|
|
238
|
+
readonly context: AudioContext | null;
|
|
239
|
+
createDeck(options?: DeckOptions): MusicDeck;
|
|
240
|
+
readonly disposalSignal: AbortSignal;
|
|
241
|
+
/** Tear down every node, listener, and owned context. Idempotent. */
|
|
242
|
+
dispose(): void;
|
|
243
|
+
readonly disposed: boolean;
|
|
244
|
+
/** Whether `key` (or its parent asset for `'key:sprite'`) is loaded. */
|
|
245
|
+
has(key: string): boolean;
|
|
246
|
+
/** Fetch and decode every manifest entry, deduplicating concurrent loads of the same URL. */
|
|
247
|
+
load(manifest: AssetManifest, options?: {
|
|
248
|
+
readonly signal?: AbortSignal;
|
|
249
|
+
}): Promise<void>;
|
|
250
|
+
/** Start a loaded sound; throws `BardError` for unknown keys and streamed assets. */
|
|
251
|
+
play(key: string, options?: PlayOptions): SoundHandle;
|
|
252
|
+
resume(): Promise<void>;
|
|
253
|
+
/** Context lifecycle state; `'idle'` until the first lazy creation. */
|
|
254
|
+
readonly state: BardState;
|
|
255
|
+
suspend(): Promise<void>;
|
|
256
|
+
/** Start a procedurally generated sound. */
|
|
257
|
+
synth(options: SynthOptions): SoundHandle;
|
|
258
|
+
/** Observe runtime behavior; see `BardEvent`. */
|
|
259
|
+
tap(handler: (event: BardEvent) => void, options?: {
|
|
260
|
+
readonly signal?: AbortSignal;
|
|
261
|
+
}): () => void;
|
|
262
|
+
/** Drop loaded assets (all when omitted), stopping their active voices. */
|
|
263
|
+
unload(keys?: string | readonly string[]): void;
|
|
264
|
+
/** Create the context (when needed) and resume it; rejects with `BardUnsupportedError` without Web Audio. */
|
|
265
|
+
unlock(): Promise<void>;
|
|
266
|
+
/** Calls {@link Bard.dispose}. */
|
|
267
|
+
[Symbol.dispose](): void;
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qDAAqD;AACrD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,aAAa,GAAG,QAAQ,CAAC;AAEpF,oDAAoD;AACpD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,4EAA4E;AAC5E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qCAAqC;AACrC,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B,uFAAuF;IACvF,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACxF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;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OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,uEAAuE;IACvE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAE1B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,4CAA4C;IAC5C,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,CAAC;IAE1C,iDAAiD;IACjD,GAAG,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,MAAM,IAAI,CAAC;IAClG,2EAA2E;IAC3E,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAEhD,6GAA6G;IAC7G,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,kCAAkC;IAClC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;CAC1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/bard",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "26.11.19",
|
|
4
|
+
"description": "Lifecycle-owned Web Audio mixing: buses with ducking, buffered SFX and sprites, procedural synth, streamed tracks, and crossfading music decks",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/helmuthdu/vielzeug",
|
|
8
|
+
"directory": "packages/bard"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=22"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs",
|
|
25
|
+
"types": "./dist/index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./testing": {
|
|
28
|
+
"import": "./dist/testing.js",
|
|
29
|
+
"require": "./dist/testing.cjs",
|
|
30
|
+
"types": "./dist/testing/index.d.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"typesVersions": {
|
|
34
|
+
"*": {
|
|
35
|
+
"testing": [
|
|
36
|
+
"dist/testing/index.d.ts"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"registry": "https://registry.npmjs.org/"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "vite build && bun run --silent build:bundle && bun run --silent build:types",
|
|
47
|
+
"build:bundle": "vite build --config vite.bundle.config.ts",
|
|
48
|
+
"build:types": "tsc -p tsconfig.declarations.json",
|
|
49
|
+
"fix": "biome check --write src",
|
|
50
|
+
"lint": "biome ci src",
|
|
51
|
+
"prepublishOnly": "bun run --silent build",
|
|
52
|
+
"test": "vitest"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^26.6.6",
|
|
56
|
+
"typescript": "^6.0.3",
|
|
57
|
+
"vite": "^8.3.6",
|
|
58
|
+
"vitest": "^5.1.0"
|
|
59
|
+
}
|
|
60
|
+
}
|