@ac-kit/browser 0.1.0 → 0.2.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/CHANGELOG.md +58 -0
- package/README.md +258 -4
- package/dist/_race-abort.d.ts +2 -0
- package/dist/_race-abort.d.ts.map +1 -0
- package/dist/_race-abort.js +20 -0
- package/dist/_race-abort.js.map +1 -0
- package/dist/canvas/image-data-pixels.d.ts +61 -0
- package/dist/canvas/image-data-pixels.d.ts.map +1 -0
- package/dist/canvas/image-data-pixels.js +74 -0
- package/dist/canvas/image-data-pixels.js.map +1 -0
- package/dist/canvas/read-image-data.d.ts +120 -0
- package/dist/canvas/read-image-data.d.ts.map +1 -0
- package/dist/canvas/read-image-data.js +147 -0
- package/dist/canvas/read-image-data.js.map +1 -0
- package/dist/dom/index.d.ts +2 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +2 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/dom/web-animations/wait-for-transitions.d.ts +59 -0
- package/dist/dom/web-animations/wait-for-transitions.d.ts.map +1 -0
- package/dist/dom/web-animations/wait-for-transitions.js +44 -0
- package/dist/dom/web-animations/wait-for-transitions.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/media-capture/microphone-access.d.ts +116 -0
- package/dist/media-capture/microphone-access.d.ts.map +1 -0
- package/dist/media-capture/microphone-access.js +224 -0
- package/dist/media-capture/microphone-access.js.map +1 -0
- package/dist/testing/fake-audio-context.d.ts +174 -0
- package/dist/testing/fake-audio-context.d.ts.map +1 -0
- package/dist/testing/fake-audio-context.js +314 -0
- package/dist/testing/fake-audio-context.js.map +1 -0
- package/dist/testing/fake-media-devices.d.ts +90 -0
- package/dist/testing/fake-media-devices.d.ts.map +1 -0
- package/dist/testing/fake-media-devices.js +147 -0
- package/dist/testing/fake-media-devices.js.map +1 -0
- package/dist/testing/fake-web-midi.d.ts +25 -0
- package/dist/testing/fake-web-midi.d.ts.map +1 -0
- package/dist/testing/fake-web-midi.js +52 -0
- package/dist/testing/fake-web-midi.js.map +1 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/web-audio/audio-clock-mapping.d.ts +124 -0
- package/dist/web-audio/audio-clock-mapping.d.ts.map +1 -0
- package/dist/web-audio/audio-clock-mapping.js +245 -0
- package/dist/web-audio/audio-clock-mapping.js.map +1 -0
- package/package.json +20 -6
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/** An audio node that records what it was connected to, and its disconnections. */
|
|
2
|
+
export class FakeAudioNode {
|
|
3
|
+
/** The nodes it was connected to, in order. */
|
|
4
|
+
connections = [];
|
|
5
|
+
/** How many times the page called {@link disconnect}. */
|
|
6
|
+
disconnectCount = 0;
|
|
7
|
+
connect(destination) {
|
|
8
|
+
this.connections.push(destination);
|
|
9
|
+
}
|
|
10
|
+
disconnect() {
|
|
11
|
+
this.disconnectCount += 1;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** The node a microphone stream enters the graph by. */
|
|
15
|
+
export class FakeMediaStreamSource extends FakeAudioNode {
|
|
16
|
+
stream;
|
|
17
|
+
constructor(stream) {
|
|
18
|
+
super();
|
|
19
|
+
this.stream = stream;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A message port the page posts to and listens on. What arrives before there is
|
|
24
|
+
* a listener waits for it, and is handed over after the current task, as a real
|
|
25
|
+
* port does.
|
|
26
|
+
*/
|
|
27
|
+
export class FakeMessagePort {
|
|
28
|
+
/** What the page posted, in order. */
|
|
29
|
+
posted = [];
|
|
30
|
+
/**
|
|
31
|
+
* The other end, given each message the page posts once it is recorded: set
|
|
32
|
+
* it to feed a real processor's logic, rather than replacing
|
|
33
|
+
* {@link postMessage}, whose replacement would leave {@link posted} empty.
|
|
34
|
+
*/
|
|
35
|
+
onPostMessage;
|
|
36
|
+
handler = null;
|
|
37
|
+
pending = [];
|
|
38
|
+
postMessage(message) {
|
|
39
|
+
this.posted.push(message);
|
|
40
|
+
this.onPostMessage?.(message);
|
|
41
|
+
}
|
|
42
|
+
get onmessage() {
|
|
43
|
+
return this.handler;
|
|
44
|
+
}
|
|
45
|
+
set onmessage(handler) {
|
|
46
|
+
this.handler = handler;
|
|
47
|
+
if (handler !== null && this.pending.length > 0) {
|
|
48
|
+
queueMicrotask(() => this.flush());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** `data` arrives from the other end. */
|
|
52
|
+
receive(data) {
|
|
53
|
+
if (this.handler === null) {
|
|
54
|
+
this.pending.push(data);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.handler(new MessageEvent("message", { data }));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
flush() {
|
|
61
|
+
for (const data of this.pending.splice(0)) {
|
|
62
|
+
this.handler?.(new MessageEvent("message", { data }));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* An `AudioWorkletNode` whose processor is the test: what the page posts is in
|
|
68
|
+
* {@link posted}, and {@link emit} posts to the page. The processor options it
|
|
69
|
+
* was made with are in {@link configuration}.
|
|
70
|
+
*/
|
|
71
|
+
export class FakeAudioWorkletNode extends FakeAudioNode {
|
|
72
|
+
configuration;
|
|
73
|
+
onprocessorerror = null;
|
|
74
|
+
port = new FakeMessagePort();
|
|
75
|
+
constructor(configuration) {
|
|
76
|
+
super();
|
|
77
|
+
this.configuration = configuration;
|
|
78
|
+
}
|
|
79
|
+
/** What the page posted to the processor, in order. */
|
|
80
|
+
get posted() {
|
|
81
|
+
return this.port.posted;
|
|
82
|
+
}
|
|
83
|
+
/** The messages of `type` the page posted. */
|
|
84
|
+
postedOf(type) {
|
|
85
|
+
return this.posted.filter((message) => typeof message === "object" &&
|
|
86
|
+
message !== null &&
|
|
87
|
+
"type" in message &&
|
|
88
|
+
message.type === type);
|
|
89
|
+
}
|
|
90
|
+
/** The processor posts `data` to the page. */
|
|
91
|
+
emit(data) {
|
|
92
|
+
this.port.receive(data);
|
|
93
|
+
}
|
|
94
|
+
/** The processor threw. */
|
|
95
|
+
fail() {
|
|
96
|
+
this.onprocessorerror?.(new Event("processorerror"));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** An audio buffer holding the samples copied into it. */
|
|
100
|
+
export class FakeAudioBuffer {
|
|
101
|
+
length;
|
|
102
|
+
sampleRate;
|
|
103
|
+
data;
|
|
104
|
+
constructor(length, sampleRate) {
|
|
105
|
+
this.length = length;
|
|
106
|
+
this.sampleRate = sampleRate;
|
|
107
|
+
this.data = new Float32Array(length);
|
|
108
|
+
}
|
|
109
|
+
copyToChannel(samples, _channel) {
|
|
110
|
+
this.data.set(samples);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** A gain node: its value is what a test reads. */
|
|
114
|
+
export class FakeGainNode extends FakeAudioNode {
|
|
115
|
+
gain = { value: 1 };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A buffer source: {@link start} records when it was asked to start, and
|
|
119
|
+
* {@link stop} ends it, as a real one does.
|
|
120
|
+
*/
|
|
121
|
+
export class FakeBufferSource extends FakeAudioNode {
|
|
122
|
+
buffer = null;
|
|
123
|
+
onended = null;
|
|
124
|
+
/** The node it was connected to. */
|
|
125
|
+
output;
|
|
126
|
+
/** The times it was asked to start at, in order; `undefined` for now. */
|
|
127
|
+
starts = [];
|
|
128
|
+
/** How many times the page called {@link stop}. */
|
|
129
|
+
stopCount = 0;
|
|
130
|
+
connect(node) {
|
|
131
|
+
super.connect(node);
|
|
132
|
+
this.output = node;
|
|
133
|
+
}
|
|
134
|
+
start(when) {
|
|
135
|
+
this.starts.push(when);
|
|
136
|
+
}
|
|
137
|
+
stop() {
|
|
138
|
+
this.stopCount += 1;
|
|
139
|
+
this.onended?.();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* An `AudioContext` that starts suspended, as before a gesture, and answers
|
|
144
|
+
* `resume`, `suspend` and `close` by its state and a `statechange` event.
|
|
145
|
+
*/
|
|
146
|
+
export class FakeAudioContext extends EventTarget {
|
|
147
|
+
sampleRate;
|
|
148
|
+
state = "suspended";
|
|
149
|
+
/** Whether the page's `resume()` is allowed: false before a gesture. */
|
|
150
|
+
isResumeAllowed = true;
|
|
151
|
+
/** What the next `addModule` and `resume` calls wait for, in turn. */
|
|
152
|
+
moduleGates = [];
|
|
153
|
+
resumeGates = [];
|
|
154
|
+
/** The URLs of every `addModule` call, in order. */
|
|
155
|
+
modules = [];
|
|
156
|
+
audioWorklet = {
|
|
157
|
+
addModule: async (url) => {
|
|
158
|
+
this.modules.push(url);
|
|
159
|
+
await this.moduleGates.shift();
|
|
160
|
+
if (this.isModuleFailing) {
|
|
161
|
+
throw new DOMException("fake module failure", "AbortError");
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
isModuleFailing = false;
|
|
166
|
+
/** Whether a stream whose rate is not the context's is refused, as Firefox. */
|
|
167
|
+
isRateMatchRequired = false;
|
|
168
|
+
/** The name of the exception `createMediaStreamSource` throws, if any. */
|
|
169
|
+
sourceErrorName;
|
|
170
|
+
sources = [];
|
|
171
|
+
/** The context's clock, seconds: tests set it. */
|
|
172
|
+
currentTime = 0;
|
|
173
|
+
baseLatency = 0.01;
|
|
174
|
+
/** What the browser reports of the output; `undefined` when it does not. */
|
|
175
|
+
outputLatency = 0.02;
|
|
176
|
+
destination = {};
|
|
177
|
+
/** The sounds played, in order. */
|
|
178
|
+
bufferSources = [];
|
|
179
|
+
/** How many times the page called {@link resume}. */
|
|
180
|
+
resumeCount = 0;
|
|
181
|
+
/** How many times the page called {@link suspend}. */
|
|
182
|
+
suspendCount = 0;
|
|
183
|
+
/** How many times the page called {@link close}. */
|
|
184
|
+
closeCount = 0;
|
|
185
|
+
constructor(sampleRate) {
|
|
186
|
+
super();
|
|
187
|
+
this.sampleRate = sampleRate;
|
|
188
|
+
}
|
|
189
|
+
createBuffer(_channels, length, sampleRate) {
|
|
190
|
+
return new FakeAudioBuffer(length, sampleRate);
|
|
191
|
+
}
|
|
192
|
+
createBufferSource() {
|
|
193
|
+
const source = new FakeBufferSource();
|
|
194
|
+
this.bufferSources.push(source);
|
|
195
|
+
return source;
|
|
196
|
+
}
|
|
197
|
+
createGain() {
|
|
198
|
+
return new FakeGainNode();
|
|
199
|
+
}
|
|
200
|
+
createMediaStreamSource(stream) {
|
|
201
|
+
if (this.sourceErrorName !== undefined) {
|
|
202
|
+
throw new DOMException("fake source failure", this.sourceErrorName);
|
|
203
|
+
}
|
|
204
|
+
const [track] = stream.getAudioTracks();
|
|
205
|
+
const rate = track?.getSettings().sampleRate;
|
|
206
|
+
if (this.isRateMatchRequired &&
|
|
207
|
+
rate !== undefined &&
|
|
208
|
+
rate !== this.sampleRate) {
|
|
209
|
+
throw new DOMException("sample rates differ", "NotSupportedError");
|
|
210
|
+
}
|
|
211
|
+
const source = new FakeMediaStreamSource(stream);
|
|
212
|
+
this.sources.push(source);
|
|
213
|
+
return source;
|
|
214
|
+
}
|
|
215
|
+
async resume() {
|
|
216
|
+
this.resumeCount += 1;
|
|
217
|
+
await this.resumeGates.shift();
|
|
218
|
+
if (this.isResumeAllowed) {
|
|
219
|
+
this.setState("running");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async suspend() {
|
|
223
|
+
this.suspendCount += 1;
|
|
224
|
+
this.setState("suspended");
|
|
225
|
+
}
|
|
226
|
+
async close() {
|
|
227
|
+
this.closeCount += 1;
|
|
228
|
+
this.setState("closed");
|
|
229
|
+
}
|
|
230
|
+
/** The browser changes the context's state: another tab, a phone call. */
|
|
231
|
+
setState(state) {
|
|
232
|
+
if (state !== this.state) {
|
|
233
|
+
this.state = state;
|
|
234
|
+
this.dispatchEvent(new Event("statechange"));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* What a browser makes audio contexts and worklet nodes of: records every one,
|
|
240
|
+
* and refuses the sampling rates it is told to, as Firefox does.
|
|
241
|
+
*/
|
|
242
|
+
export class FakeAudioEnvironment {
|
|
243
|
+
contexts = [];
|
|
244
|
+
nodes = [];
|
|
245
|
+
/** The rates `createContext` refuses with a `NotSupportedError`. */
|
|
246
|
+
unsupportedRates = new Set();
|
|
247
|
+
/** The rate of a context made with none. */
|
|
248
|
+
defaultRate = 48000;
|
|
249
|
+
/** Whether the contexts made from now on are Firefox's about rates. */
|
|
250
|
+
isRateMatchRequired = false;
|
|
251
|
+
/** Whether the contexts made from now on fail to load the module. */
|
|
252
|
+
isModuleFailing = false;
|
|
253
|
+
/** The exception the contexts made from now on throw making a source. */
|
|
254
|
+
sourceErrorName;
|
|
255
|
+
/** Whether the contexts made from now on may run: false before a gesture. */
|
|
256
|
+
isResumeAllowed = true;
|
|
257
|
+
moduleGates = [];
|
|
258
|
+
resumeGates = [];
|
|
259
|
+
/**
|
|
260
|
+
* Makes the next `addModule` of any context wait.
|
|
261
|
+
*
|
|
262
|
+
* @returns What lets it go on.
|
|
263
|
+
*/
|
|
264
|
+
holdNextModule() {
|
|
265
|
+
const gate = Promise.withResolvers();
|
|
266
|
+
this.moduleGates.push(gate.promise);
|
|
267
|
+
return gate.resolve;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Makes the next `resume` of any context wait, as before a gesture.
|
|
271
|
+
*
|
|
272
|
+
* @returns What lets it go on.
|
|
273
|
+
*/
|
|
274
|
+
holdNextResume() {
|
|
275
|
+
const gate = Promise.withResolvers();
|
|
276
|
+
this.resumeGates.push(gate.promise);
|
|
277
|
+
return gate.resolve;
|
|
278
|
+
}
|
|
279
|
+
createContext = (sampleRate) => {
|
|
280
|
+
const rate = sampleRate ?? this.defaultRate;
|
|
281
|
+
if (this.unsupportedRates.has(rate)) {
|
|
282
|
+
throw new DOMException(`rate ${rate} refused`, "NotSupportedError");
|
|
283
|
+
}
|
|
284
|
+
const context = new FakeAudioContext(rate);
|
|
285
|
+
context.isRateMatchRequired = this.isRateMatchRequired;
|
|
286
|
+
context.isModuleFailing = this.isModuleFailing;
|
|
287
|
+
context.sourceErrorName = this.sourceErrorName;
|
|
288
|
+
context.isResumeAllowed = this.isResumeAllowed;
|
|
289
|
+
context.moduleGates = this.moduleGates;
|
|
290
|
+
context.resumeGates = this.resumeGates;
|
|
291
|
+
this.contexts.push(context);
|
|
292
|
+
return context;
|
|
293
|
+
};
|
|
294
|
+
createWorkletNode = (_context, configuration) => {
|
|
295
|
+
const node = new FakeAudioWorkletNode(configuration);
|
|
296
|
+
this.nodes.push(node);
|
|
297
|
+
return node;
|
|
298
|
+
};
|
|
299
|
+
get context() {
|
|
300
|
+
const context = this.contexts.at(-1);
|
|
301
|
+
if (context === undefined) {
|
|
302
|
+
throw new Error("no context was made");
|
|
303
|
+
}
|
|
304
|
+
return context;
|
|
305
|
+
}
|
|
306
|
+
get node() {
|
|
307
|
+
const node = this.nodes.at(-1);
|
|
308
|
+
if (node === undefined) {
|
|
309
|
+
throw new Error("no worklet node was made");
|
|
310
|
+
}
|
|
311
|
+
return node;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=fake-audio-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-audio-context.js","sourceRoot":"","sources":["../../src/testing/fake-audio-context.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,OAAO,aAAa;IACzB,+CAA+C;IACtC,WAAW,GAAc,EAAE,CAAC;IACrC,yDAAyD;IACzD,eAAe,GAAG,CAAC,CAAC;IAEpB,OAAO,CAAC,WAAoB;QAC3B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;IAED,UAAU;QACT,IAAI,C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OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC/C,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACvC,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE5B,OAAO,OAAkC,CAAC;IAC3C,CAAC,CAAC;IAEO,iBAAiB,GAAG,CAC5B,QAAsB,EACtB,aAAuB,EACJ,EAAE;QACrB,MAAM,IAAI,GAAG,IAAI,oBAAoB,CAAC,aAAa,CAAC,CAAC;QACrD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEtB,OAAO,IAAmC,CAAC;IAC5C,CAAC,CAAC;IAEF,IAAI,OAAO;QACV,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,IAAI,IAAI;QACP,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** What a fake track reports of itself, as `getSettings()` does. */
|
|
2
|
+
export type FakeTrackSettings = {
|
|
3
|
+
sampleRate?: number;
|
|
4
|
+
echoCancellation?: boolean;
|
|
5
|
+
noiseSuppression?: boolean;
|
|
6
|
+
autoGainControl?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A microphone's audio track: live until stopped or until its device is lost
|
|
10
|
+
* ({@link end}), which a real track reports by an `ended` event, and not by
|
|
11
|
+
* `stop()`.
|
|
12
|
+
*/
|
|
13
|
+
export declare class FakeMediaStreamTrack extends EventTarget {
|
|
14
|
+
readonly label: string;
|
|
15
|
+
private readonly settings_;
|
|
16
|
+
readyState: MediaStreamTrackState;
|
|
17
|
+
muted: boolean;
|
|
18
|
+
/** How many times the page called {@link stop}. */
|
|
19
|
+
stopCount: number;
|
|
20
|
+
private readonly listeners_;
|
|
21
|
+
constructor(label?: string, settings_?: FakeTrackSettings);
|
|
22
|
+
/** How many listeners of `type` are registered, those removed by a signal not. */
|
|
23
|
+
listenerCount(type: string): number;
|
|
24
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
|
|
25
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
|
26
|
+
getSettings(): FakeTrackSettings;
|
|
27
|
+
stop(): void;
|
|
28
|
+
/** The device went away. */
|
|
29
|
+
end(): void;
|
|
30
|
+
/** Another application took the microphone. */
|
|
31
|
+
mute(): void;
|
|
32
|
+
unmute(): void;
|
|
33
|
+
}
|
|
34
|
+
/** A media stream that stands for the microphone's: one live track by default. */
|
|
35
|
+
export declare class FakeMediaStream {
|
|
36
|
+
private readonly tracks_;
|
|
37
|
+
constructor(tracks_?: FakeMediaStreamTrack[]);
|
|
38
|
+
getTracks(): MediaStreamTrack[];
|
|
39
|
+
getAudioTracks(): MediaStreamTrack[];
|
|
40
|
+
}
|
|
41
|
+
/** One device `enumerateDevices` lists. */
|
|
42
|
+
export type FakeMediaDeviceInfo = {
|
|
43
|
+
kind: MediaDeviceKind;
|
|
44
|
+
deviceId: string;
|
|
45
|
+
label: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* What a `getUserMedia` call answers: `"ok"` opens a stream, another string
|
|
49
|
+
* rejects with a `DOMException` of that name, and any other value is thrown as
|
|
50
|
+
* it is (an `OverconstrainedError` carrying its `constraint`, say).
|
|
51
|
+
*/
|
|
52
|
+
export type FakeUserMediaOutcome = string | {
|
|
53
|
+
readonly thrown: unknown;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* A `MediaDevices` whose `getUserMedia` answers with the given outcomes in
|
|
57
|
+
* turn, then opens streams, and which lists the given devices. It opens a
|
|
58
|
+
* stream of one track with {@link trackSettings}, keeps every request and every
|
|
59
|
+
* track it opened, and tells when the devices change.
|
|
60
|
+
*
|
|
61
|
+
* Its methods are plain: spy on them with the test runner's own spies
|
|
62
|
+
* (`vi.spyOn(mediaDevices, "getUserMedia")`) to assert on the calls.
|
|
63
|
+
*/
|
|
64
|
+
export declare class FakeMediaDevices extends EventTarget {
|
|
65
|
+
private readonly outcomes_;
|
|
66
|
+
devices: FakeMediaDeviceInfo[];
|
|
67
|
+
/** What the tracks opened from now on report of themselves. */
|
|
68
|
+
trackSettings: FakeTrackSettings;
|
|
69
|
+
/** The label of the tracks opened from now on. */
|
|
70
|
+
trackLabel: string;
|
|
71
|
+
/** The constraints of every `getUserMedia` call, in order. */
|
|
72
|
+
readonly requests: (MediaStreamConstraints | undefined)[];
|
|
73
|
+
/** Every track opened, in order. */
|
|
74
|
+
readonly tracks: FakeMediaStreamTrack[];
|
|
75
|
+
private readonly gates_;
|
|
76
|
+
constructor(outcomes_?: FakeUserMediaOutcome[], devices?: FakeMediaDeviceInfo[]);
|
|
77
|
+
/** The tracks opened and neither stopped nor ended. */
|
|
78
|
+
get liveTracks(): FakeMediaStreamTrack[];
|
|
79
|
+
getUserMedia(constraints?: MediaStreamConstraints): Promise<MediaStream>;
|
|
80
|
+
enumerateDevices(): Promise<MediaDeviceInfo[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Makes the next `getUserMedia` wait, as for a permission prompt.
|
|
83
|
+
*
|
|
84
|
+
* @returns What lets it go on.
|
|
85
|
+
*/
|
|
86
|
+
holdNext(): () => void;
|
|
87
|
+
/** Plugs `devices` in and out: the browser tells so. */
|
|
88
|
+
changeDevices(devices: FakeMediaDeviceInfo[]): void;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=fake-media-devices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-media-devices.d.ts","sourceRoot":"","sources":["../../src/testing/fake-media-devices.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,MAAM,MAAM,iBAAiB,GAAG;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,WAAW;IASnD,QAAQ,CAAC,KAAK;IACd,OAAO,CAAC,QAAQ,CAAC,SAAS;IAT3B,UAAU,EAAE,qBAAqB,CAAU;IAC3C,KAAK,UAAS;IACd,mDAAmD;IACnD,SAAS,SAAK;IAEd,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAE9D,YACU,KAAK,SAAoB,EACjB,SAAS,GAAE,iBAAsB,EAGlD;IAED,kFAAkF;IAClF,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElC;IAEQ,gBAAgB,CACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,GAAG,IAAI,EACnD,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,GACzC,IAAI,CAUN;IAEQ,mBAAmB,CAC3B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,GAAG,IAAI,EACnD,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,GACtC,IAAI,CAGN;IAED,WAAW,IAAI,iBAAiB,CAE/B;IAED,IAAI,IAAI,IAAI,CAGX;IAED,4BAA4B;IAC5B,GAAG,IAAI,IAAI,CAGV;I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AMnD;IAED;;;;OAIG;IACH,QAAQ,IAAI,MAAM,IAAI,CAKrB;IAED,wDAAwD;IACxD,aAAa,CAAC,OAAO,EAAE,mBAAmB,EAAE,GAAG,IAAI,CAGlD;CACD"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A microphone's audio track: live until stopped or until its device is lost
|
|
3
|
+
* ({@link end}), which a real track reports by an `ended` event, and not by
|
|
4
|
+
* `stop()`.
|
|
5
|
+
*/
|
|
6
|
+
export class FakeMediaStreamTrack extends EventTarget {
|
|
7
|
+
label;
|
|
8
|
+
settings_;
|
|
9
|
+
readyState = "live";
|
|
10
|
+
muted = false;
|
|
11
|
+
/** How many times the page called {@link stop}. */
|
|
12
|
+
stopCount = 0;
|
|
13
|
+
listeners_ = new Map();
|
|
14
|
+
constructor(label = "Fake microphone", settings_ = {}) {
|
|
15
|
+
super();
|
|
16
|
+
this.label = label;
|
|
17
|
+
this.settings_ = settings_;
|
|
18
|
+
}
|
|
19
|
+
/** How many listeners of `type` are registered, those removed by a signal not. */
|
|
20
|
+
listenerCount(type) {
|
|
21
|
+
return this.listeners_.get(type)?.size ?? 0;
|
|
22
|
+
}
|
|
23
|
+
addEventListener(type, listener, options) {
|
|
24
|
+
super.addEventListener(type, listener, options);
|
|
25
|
+
const registered = this.listeners_.get(type) ?? new Set();
|
|
26
|
+
this.listeners_.set(type, registered);
|
|
27
|
+
registered.add(listener);
|
|
28
|
+
if (typeof options === "object") {
|
|
29
|
+
options.signal?.addEventListener("abort", () => registered.delete(listener));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
removeEventListener(type, listener, options) {
|
|
33
|
+
super.removeEventListener(type, listener, options);
|
|
34
|
+
this.listeners_.get(type)?.delete(listener);
|
|
35
|
+
}
|
|
36
|
+
getSettings() {
|
|
37
|
+
return this.settings_;
|
|
38
|
+
}
|
|
39
|
+
stop() {
|
|
40
|
+
this.stopCount += 1;
|
|
41
|
+
this.readyState = "ended";
|
|
42
|
+
}
|
|
43
|
+
/** The device went away. */
|
|
44
|
+
end() {
|
|
45
|
+
this.readyState = "ended";
|
|
46
|
+
this.dispatchEvent(new Event("ended"));
|
|
47
|
+
}
|
|
48
|
+
/** Another application took the microphone. */
|
|
49
|
+
mute() {
|
|
50
|
+
this.muted = true;
|
|
51
|
+
this.dispatchEvent(new Event("mute"));
|
|
52
|
+
}
|
|
53
|
+
unmute() {
|
|
54
|
+
this.muted = false;
|
|
55
|
+
this.dispatchEvent(new Event("unmute"));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** A media stream that stands for the microphone's: one live track by default. */
|
|
59
|
+
export class FakeMediaStream {
|
|
60
|
+
tracks_;
|
|
61
|
+
constructor(tracks_ = [
|
|
62
|
+
new FakeMediaStreamTrack(),
|
|
63
|
+
]) {
|
|
64
|
+
this.tracks_ = tracks_;
|
|
65
|
+
}
|
|
66
|
+
getTracks() {
|
|
67
|
+
return this.tracks_;
|
|
68
|
+
}
|
|
69
|
+
getAudioTracks() {
|
|
70
|
+
return this.getTracks();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A `MediaDevices` whose `getUserMedia` answers with the given outcomes in
|
|
75
|
+
* turn, then opens streams, and which lists the given devices. It opens a
|
|
76
|
+
* stream of one track with {@link trackSettings}, keeps every request and every
|
|
77
|
+
* track it opened, and tells when the devices change.
|
|
78
|
+
*
|
|
79
|
+
* Its methods are plain: spy on them with the test runner's own spies
|
|
80
|
+
* (`vi.spyOn(mediaDevices, "getUserMedia")`) to assert on the calls.
|
|
81
|
+
*/
|
|
82
|
+
export class FakeMediaDevices extends EventTarget {
|
|
83
|
+
outcomes_;
|
|
84
|
+
devices;
|
|
85
|
+
/** What the tracks opened from now on report of themselves. */
|
|
86
|
+
trackSettings = {
|
|
87
|
+
sampleRate: 48000,
|
|
88
|
+
echoCancellation: false,
|
|
89
|
+
noiseSuppression: false,
|
|
90
|
+
autoGainControl: false,
|
|
91
|
+
};
|
|
92
|
+
/** The label of the tracks opened from now on. */
|
|
93
|
+
trackLabel = "Fake microphone";
|
|
94
|
+
/** The constraints of every `getUserMedia` call, in order. */
|
|
95
|
+
requests = [];
|
|
96
|
+
/** Every track opened, in order. */
|
|
97
|
+
tracks = [];
|
|
98
|
+
gates_ = [];
|
|
99
|
+
constructor(outcomes_ = [], devices = []) {
|
|
100
|
+
super();
|
|
101
|
+
this.outcomes_ = outcomes_;
|
|
102
|
+
this.devices = devices;
|
|
103
|
+
}
|
|
104
|
+
/** The tracks opened and neither stopped nor ended. */
|
|
105
|
+
get liveTracks() {
|
|
106
|
+
return this.tracks.filter(({ readyState }) => readyState === "live");
|
|
107
|
+
}
|
|
108
|
+
async getUserMedia(constraints) {
|
|
109
|
+
this.requests.push(constraints);
|
|
110
|
+
const outcome = this.outcomes_.shift() ?? "ok";
|
|
111
|
+
await this.gates_.shift();
|
|
112
|
+
if (typeof outcome !== "string") {
|
|
113
|
+
throw outcome.thrown;
|
|
114
|
+
}
|
|
115
|
+
if (outcome !== "ok") {
|
|
116
|
+
throw new DOMException(`fake ${outcome}`, outcome);
|
|
117
|
+
}
|
|
118
|
+
const track = new FakeMediaStreamTrack(this.trackLabel, {
|
|
119
|
+
...this.trackSettings,
|
|
120
|
+
});
|
|
121
|
+
this.tracks.push(track);
|
|
122
|
+
return new FakeMediaStream([track]);
|
|
123
|
+
}
|
|
124
|
+
async enumerateDevices() {
|
|
125
|
+
return this.devices.map((device) => ({
|
|
126
|
+
...device,
|
|
127
|
+
groupId: "",
|
|
128
|
+
toJSON: () => ({}),
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Makes the next `getUserMedia` wait, as for a permission prompt.
|
|
133
|
+
*
|
|
134
|
+
* @returns What lets it go on.
|
|
135
|
+
*/
|
|
136
|
+
holdNext() {
|
|
137
|
+
const gate = Promise.withResolvers();
|
|
138
|
+
this.gates_.push(gate.promise);
|
|
139
|
+
return gate.resolve;
|
|
140
|
+
}
|
|
141
|
+
/** Plugs `devices` in and out: the browser tells so. */
|
|
142
|
+
changeDevices(devices) {
|
|
143
|
+
this.devices = devices;
|
|
144
|
+
this.dispatchEvent(new Event("devicechange"));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=fake-media-devices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-media-devices.js","sourceRoot":"","sources":["../../src/testing/fake-media-devices.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IAS1C,KAAK;IACG,SAAS;IAT3B,UAAU,GAA0B,MAAM,CAAC;IAC3C,KAAK,GAAG,KAAK,CAAC;IACd,mDAAmD;IACnD,SAAS,GAAG,CAAC,CAAC;IAEG,UAAU,GAAG,IAAI,GAAG,EAAwB,CAAC;IAE9D,YACU,KAAK,GAAG,iBAAiB,EACjB,SAAS,GAAsB,EAAE;QAElD,KAAK,EAAE,CAAC;qBAHC,KAAK;yBACG,SAAS;IAG3B,CAAC;IAED,kFAAkF;IAClF,aAAa,CAAC,IAAY;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEQ,gBAAgB,CACxB,IAAY,EACZ,QAAmD,EACnD,OAA2C;QAE3C,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAChD,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;QAC1D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACtC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,CAAC,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D,GAAG,IAAI,CAAC,aAAa;SACrB,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAExB,OAAO,IAAI,eAAe,CAAC,CAAC,KAAK,CAAC,CAA2B,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,gBAAgB;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACpC,GAAG,MAAM;YACT,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;SAClB,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACP,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,EAAQ,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE/B,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,wDAAwD;IACxD,aAAa,CAAC,OAA8B;QAC3C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;IAC/C,CAAC;CACD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** A Web MIDI input port that sends the messages it is told to. */
|
|
2
|
+
export declare class FakeMidiInput extends EventTarget {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly name: string | null;
|
|
5
|
+
readonly manufacturer: string | null;
|
|
6
|
+
state: MIDIPortDeviceState;
|
|
7
|
+
/** How many times the page called {@link close}. */
|
|
8
|
+
closeCount: number;
|
|
9
|
+
constructor(id: string, name: string | null, manufacturer: string | null);
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
/** Sends `bytes` as one event that arrived at `timeStamp`. */
|
|
12
|
+
send(bytes: readonly number[], timeStamp: number): void;
|
|
13
|
+
}
|
|
14
|
+
/** A Web MIDI access whose ports are plugged in and out by the test. */
|
|
15
|
+
export declare class FakeMidiAccess extends EventTarget {
|
|
16
|
+
readonly inputs: Map<string, FakeMidiInput>;
|
|
17
|
+
constructor(...inputs: FakeMidiInput[]);
|
|
18
|
+
plug(input: FakeMidiInput): void;
|
|
19
|
+
/**
|
|
20
|
+
* Unplugs `input`: kept in the list as disconnected, as Chrome does, or
|
|
21
|
+
* dropped from it.
|
|
22
|
+
*/
|
|
23
|
+
unplug(input: FakeMidiInput, isKept?: boolean): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=fake-web-midi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-web-midi.d.ts","sourceRoot":"","sources":["../../src/testing/fake-web-midi.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,qBAAa,aAAc,SAAQ,WAAW;IAM5C,QAAQ,CAAC,EAAE,EAAE,MAAM;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAPrC,KAAK,EAAE,mBAAmB,CAAe;IACzC,oDAAoD;IACpD,UAAU,SAAK;IAEf,YACU,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,YAAY,EAAE,MAAM,GAAG,IAAI,EAGpC;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAED,8DAA8D;IAC9D,IAAI,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAKtD;CACD;AAED,wEAAwE;AACxE,qBAAa,cAAe,SAAQ,WAAW;IAC9C,QAAQ,CAAC,MAAM,6BAAoC;IAEnD,YAAY,GAAG,MAAM,EAAE,aAAa,EAAE,EAKrC;IAED,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAI/B;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,UAAQ,GAAG,IAAI,CAMjD;CACD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** A Web MIDI input port that sends the messages it is told to. */
|
|
2
|
+
export class FakeMidiInput extends EventTarget {
|
|
3
|
+
id;
|
|
4
|
+
name;
|
|
5
|
+
manufacturer;
|
|
6
|
+
state = "connected";
|
|
7
|
+
/** How many times the page called {@link close}. */
|
|
8
|
+
closeCount = 0;
|
|
9
|
+
constructor(id, name, manufacturer) {
|
|
10
|
+
super();
|
|
11
|
+
this.id = id;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.manufacturer = manufacturer;
|
|
14
|
+
}
|
|
15
|
+
async close() {
|
|
16
|
+
this.closeCount += 1;
|
|
17
|
+
}
|
|
18
|
+
/** Sends `bytes` as one event that arrived at `timeStamp`. */
|
|
19
|
+
send(bytes, timeStamp) {
|
|
20
|
+
const event = new Event("midimessage");
|
|
21
|
+
Object.defineProperty(event, "data", { value: new Uint8Array(bytes) });
|
|
22
|
+
Object.defineProperty(event, "timeStamp", { value: timeStamp });
|
|
23
|
+
this.dispatchEvent(event);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** A Web MIDI access whose ports are plugged in and out by the test. */
|
|
27
|
+
export class FakeMidiAccess extends EventTarget {
|
|
28
|
+
inputs = new Map();
|
|
29
|
+
constructor(...inputs) {
|
|
30
|
+
super();
|
|
31
|
+
for (const input of inputs) {
|
|
32
|
+
this.inputs.set(input.id, input);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
plug(input) {
|
|
36
|
+
input.state = "connected";
|
|
37
|
+
this.inputs.set(input.id, input);
|
|
38
|
+
this.dispatchEvent(new Event("statechange"));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Unplugs `input`: kept in the list as disconnected, as Chrome does, or
|
|
42
|
+
* dropped from it.
|
|
43
|
+
*/
|
|
44
|
+
unplug(input, isKept = false) {
|
|
45
|
+
input.state = "disconnected";
|
|
46
|
+
if (!isKept) {
|
|
47
|
+
this.inputs.delete(input.id);
|
|
48
|
+
}
|
|
49
|
+
this.dispatchEvent(new Event("statechange"));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=fake-web-midi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-web-midi.js","sourceRoot":"","sources":["../../src/testing/fake-web-midi.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,OAAO,aAAc,SAAQ,WAAW;IAMnC,EAAE;IACF,IAAI;IACJ,YAAY;IAPtB,KAAK,GAAwB,WAAW,CAAC;IACzC,oDAAoD;IACpD,UAAU,GAAG,CAAC,CAAC;IAEf,YACU,EAAU,EACV,IAAmB,EACnB,YAA2B;QAEpC,KAAK,EAAE,CAAC;kBAJC,EAAE;oBACF,IAAI;4BACJ,YAAY;IAGtB,CAAC;IAED,KAAK,CAAC,KAAK;QACV,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,8DAA8D;IAC9D,IAAI,CAAC,KAAwB,EAAE,SAAiB;QAC/C,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QACvC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvE,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;CACD;AAED,wEAAwE;AACxE,MAAM,OAAO,cAAe,SAAQ,WAAW;IACrC,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;IAEnD,YAAY,GAAG,MAAuB;QACrC,KAAK,EAAE,CAAC;QACR,KAAK,MAAM,KAAK,IAAI,MA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