@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.
Files changed (51) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +258 -4
  3. package/dist/_race-abort.d.ts +2 -0
  4. package/dist/_race-abort.d.ts.map +1 -0
  5. package/dist/_race-abort.js +20 -0
  6. package/dist/_race-abort.js.map +1 -0
  7. package/dist/canvas/image-data-pixels.d.ts +61 -0
  8. package/dist/canvas/image-data-pixels.d.ts.map +1 -0
  9. package/dist/canvas/image-data-pixels.js +74 -0
  10. package/dist/canvas/image-data-pixels.js.map +1 -0
  11. package/dist/canvas/read-image-data.d.ts +120 -0
  12. package/dist/canvas/read-image-data.d.ts.map +1 -0
  13. package/dist/canvas/read-image-data.js +147 -0
  14. package/dist/canvas/read-image-data.js.map +1 -0
  15. package/dist/dom/index.d.ts +2 -0
  16. package/dist/dom/index.d.ts.map +1 -0
  17. package/dist/dom/index.js +2 -0
  18. package/dist/dom/index.js.map +1 -0
  19. package/dist/dom/web-animations/wait-for-transitions.d.ts +59 -0
  20. package/dist/dom/web-animations/wait-for-transitions.d.ts.map +1 -0
  21. package/dist/dom/web-animations/wait-for-transitions.js +44 -0
  22. package/dist/dom/web-animations/wait-for-transitions.js.map +1 -0
  23. package/dist/index.d.ts +4 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +4 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/media-capture/microphone-access.d.ts +116 -0
  28. package/dist/media-capture/microphone-access.d.ts.map +1 -0
  29. package/dist/media-capture/microphone-access.js +224 -0
  30. package/dist/media-capture/microphone-access.js.map +1 -0
  31. package/dist/testing/fake-audio-context.d.ts +174 -0
  32. package/dist/testing/fake-audio-context.d.ts.map +1 -0
  33. package/dist/testing/fake-audio-context.js +314 -0
  34. package/dist/testing/fake-audio-context.js.map +1 -0
  35. package/dist/testing/fake-media-devices.d.ts +90 -0
  36. package/dist/testing/fake-media-devices.d.ts.map +1 -0
  37. package/dist/testing/fake-media-devices.js +147 -0
  38. package/dist/testing/fake-media-devices.js.map +1 -0
  39. package/dist/testing/fake-web-midi.d.ts +25 -0
  40. package/dist/testing/fake-web-midi.d.ts.map +1 -0
  41. package/dist/testing/fake-web-midi.js +52 -0
  42. package/dist/testing/fake-web-midi.js.map +1 -0
  43. package/dist/testing/index.d.ts +4 -0
  44. package/dist/testing/index.d.ts.map +1 -0
  45. package/dist/testing/index.js +4 -0
  46. package/dist/testing/index.js.map +1 -0
  47. package/dist/web-audio/audio-clock-mapping.d.ts +124 -0
  48. package/dist/web-audio/audio-clock-mapping.d.ts.map +1 -0
  49. package/dist/web-audio/audio-clock-mapping.js +245 -0
  50. package/dist/web-audio/audio-clock-mapping.js.map +1 -0
  51. package/package.json +20 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-image-data.d.ts","sourceRoot":"","sources":["../../src/canvas/read-image-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAoB,MAAM,cAAc,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACxB,gBAAgB,GAChB,gBAAgB,GAChB,iBAAiB,GACjB,eAAe,GACf,WAAW,GACX,UAAU,CAAC;AAEd,iFAAiF;AACjF,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAClC,wBAAwB,EACtB,WAAW,GACX,cAAc,GACd,uBAAuB,GACvB,uBAAuB,CACzB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,UAAU,CACT,SAAS,EAAE,IAAI,EACf,QAAQ,CAAC,EAAE,gCAAgC,GACzC,gBAAgB,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,oBAAoB,GAAG;IAClC;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,qBAAqB,CAAC;IACnD;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,gCAAgC,CAAC;CAC5D,CAAC;AAEF;;;;GAIG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IACrD,YAAY,OAAO,CAAC,EAAE,YAAY,EAGjC;CACD;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,aAAa,CAC5B,YAAY,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,eAAe,CAAC,EACxE,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE,oBAAoB,GAC5B,SAAS,CAwDX"}
@@ -0,0 +1,147 @@
1
+ import { UnsupportedError } from "@ac-kit/core";
2
+ /**
3
+ * The source has no pixels to draw yet: an image still loading, or broken; a
4
+ * video without its current frame; a closed `ImageBitmap` or `VideoFrame`; an
5
+ * empty canvas.
6
+ */
7
+ export class ImageSourceUnavailableError extends Error {
8
+ constructor(options) {
9
+ super("The image source has no pixels to draw", options);
10
+ this.name = "ImageSourceUnavailableError";
11
+ }
12
+ }
13
+ // A side the major browsers all draw: a policy, not any browser's limit.
14
+ const DEFAULT_MAX_SIDE_ = 32767;
15
+ // The smallest canvas area current browsers allow: Safari on iOS.
16
+ const DEFAULT_MAX_PIXELS_ = 4096 * 4096;
17
+ /**
18
+ * Reads the pixels of an image as `ImageData`, scaled down to fit `maxSize`
19
+ * when it is larger: for analysing an image's colours in a page or a worker
20
+ * without walking all of its pixels. The image is drawn once with `drawImage`
21
+ * on the canvas `createCanvas` returns, which is then read back whole.
22
+ *
23
+ * The pixels are the browser's resampling of the source, converted to the
24
+ * canvas's colour space (the result's `colorSpace`): 8-bit, not premultiplied
25
+ * by alpha. A canvas holds its colours premultiplied, so a translucent pixel's
26
+ * colour comes back quantized; the read is not lossless, even at full size.
27
+ *
28
+ * The source must be ready to draw: await `image.decode()` on an image,
29
+ * `"loadeddata"` on a video. What can be told synchronously is checked — an
30
+ * image not complete or broken, a video without a current frame, a source of no
31
+ * size — and throws; a source the browser cannot draw for another reason reads
32
+ * back transparent.
33
+ *
34
+ * Time and memory are linear in the pixels read, plus the browser's resampling
35
+ * of the source.
36
+ *
37
+ * @example
38
+ * const image = new Image();
39
+ * image.src = url;
40
+ * await image.decode();
41
+ * const imageData = readImageData(
42
+ * (width, height) => new OffscreenCanvas(width, height),
43
+ * image,
44
+ * { maxSize: 80, contextSettings: { colorSpace: "display-p3" } },
45
+ * );
46
+ *
47
+ * @param createCanvas Returns a fresh canvas `width` × `height` pixels large,
48
+ * as `(width, height) => new OffscreenCanvas(width, height)` does. A canvas
49
+ * drawn on before is cleared, and its context's state (transform, clip,
50
+ * compositing) reset, only by assigning its `width` and `height`; and it
51
+ * keeps the colour space of its first context whatever `contextSettings`
52
+ * say.
53
+ * @param source Its own size is read from `naturalWidth` and `naturalHeight`
54
+ * for an image, `videoWidth` and `videoHeight` for a video, `displayWidth`
55
+ * and `displayHeight` for a `VideoFrame`, and `width` and `height`
56
+ * otherwise.
57
+ * @returns `ImageData` of the size `source` was drawn at, in the canvas's
58
+ * colour space.
59
+ * @throws {ImageSourceUnavailableError} When `source` has no pixels to draw
60
+ * yet, before any canvas is created.
61
+ * @throws {RangeError} When `maxSize`, `maxPixels` or `maxSide` is not a
62
+ * positive integer, or the size to draw at exceeds `maxPixels` or `maxSide`;
63
+ * pass a `maxSize`, or raise them, then.
64
+ * @throws {UnsupportedError} When the canvas gives no 2D context.
65
+ * @throws A `DOMException` named `"SecurityError"` when `source` is a
66
+ * cross-origin image loaded without CORS, which the browser does not let a
67
+ * page read.
68
+ */
69
+ export function readImageData(createCanvas, source, options) {
70
+ const maxSize = options?.maxSize;
71
+ if (maxSize !== undefined) {
72
+ assertPositiveInteger_("maxSize", maxSize);
73
+ }
74
+ const maxPixels = options?.maxPixels ?? DEFAULT_MAX_PIXELS_;
75
+ assertPositiveInteger_("maxPixels", maxPixels);
76
+ const maxSide = options?.maxSide ?? DEFAULT_MAX_SIDE_;
77
+ assertPositiveInteger_("maxSide", maxSide);
78
+ const [sourceWidth, sourceHeight] = drawableSize_(source);
79
+ if (!(sourceWidth > 0 && sourceHeight > 0)) {
80
+ throw new ImageSourceUnavailableError();
81
+ }
82
+ let width = sourceWidth;
83
+ let height = sourceHeight;
84
+ if (maxSize !== undefined && Math.max(width, height) > maxSize) {
85
+ // `maxSize / aspect`, not `sourceHeight * maxSize / sourceWidth`: the two
86
+ // can round apart, and data derived from an earlier read of the same
87
+ // image must find the same size.
88
+ const aspect = sourceWidth / sourceHeight;
89
+ if (aspect >= 1) {
90
+ width = maxSize;
91
+ height = Math.max(1, Math.round(maxSize / aspect));
92
+ }
93
+ else {
94
+ height = maxSize;
95
+ width = Math.max(1, Math.round(maxSize * aspect));
96
+ }
97
+ }
98
+ // A canvas too large to allocate reads back blank rather than failing.
99
+ if (Math.max(width, height) > maxSide || width * height > maxPixels) {
100
+ throw new RangeError(`Reading ${width} × ${height} pixels exceeds maxPixels or maxSide; pass a maxSize, or raise them`);
101
+ }
102
+ const context = createCanvas(width, height).getContext("2d", options?.contextSettings);
103
+ if (context === null) {
104
+ throw new UnsupportedError("The canvas gives no 2D context");
105
+ }
106
+ const smoothing = options?.smoothing;
107
+ if (smoothing === false) {
108
+ context.imageSmoothingEnabled = false;
109
+ }
110
+ else if (smoothing !== undefined) {
111
+ context.imageSmoothingEnabled = true;
112
+ context.imageSmoothingQuality = smoothing;
113
+ }
114
+ // `drawImage` onto the canvas rather than `createImageBitmap`'s resize
115
+ // options: those resample differently (and per browser), are asynchronous,
116
+ // and a canvas is needed to read the pixels anyway.
117
+ context.drawImage(source, 0, 0, width, height);
118
+ return context.getImageData(0, 0, width, height);
119
+ }
120
+ function assertPositiveInteger_(name, value) {
121
+ if (!(Number.isInteger(value) && value >= 1)) {
122
+ throw new RangeError(`${name} must be a positive integer, not ${value}`);
123
+ }
124
+ }
125
+ // What `drawImage` would draw `source` at, or [0, 0] when it would draw
126
+ // nothing. Sources are told apart by their members: `instanceof` would need
127
+ // the page's classes.
128
+ function drawableSize_(source) {
129
+ if ("naturalWidth" in source) {
130
+ // A loading image may know its size from its header already, and draws
131
+ // transparent until complete.
132
+ return source.complete
133
+ ? [source.naturalWidth, source.naturalHeight]
134
+ : [0, 0];
135
+ }
136
+ if ("videoWidth" in source) {
137
+ // Below HAVE_CURRENT_DATA, a video draws nothing.
138
+ return source.readyState >= 2
139
+ ? [source.videoWidth, source.videoHeight]
140
+ : [0, 0];
141
+ }
142
+ if ("displayWidth" in source) {
143
+ return [source.displayWidth, source.displayHeight];
144
+ }
145
+ return [source.width, source.height];
146
+ }
147
+ //# sourceMappingURL=read-image-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-image-data.js","sourceRoot":"","sources":["../../src/canvas/read-image-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AA8E/D;;;;GAIG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACrD,YAAY,OAAsB;QACjC,KAAK,CAAC,wCAAwC,EAAE,OAAO,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC3C,CAAC;CACD;AAED,yEAAyE;AACzE,MAAM,iBAAiB,GAAG,KAAM,CAAC;AACjC,kEAAkE;AAClE,MAAM,mBAAmB,GAAG,IAAI,GAAG,IAAI,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,UAAU,aAAa,CAC5B,YAAwE,EACxE,MAAuB,EACvB,OAA8B;IAE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F,CAAC;AAED,wEAAwE;AACxE,4EAA4E;AAC5E,sBAAsB;AACtB,SAAS,aAAa,CAAC,MAAuB;IAC7C,IAAI,cAAc,IAAI,MAAM,EAAE,CAAC;QAC9B,uEAAuE;QACvE,8BAA8B;QAC9B,OAAO,MAAM,CAAC,QAAQ;YACrB,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,aAAa,CAAC;YAC7C,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACX,CAAC;IACD,IAAI,YAAY,IAAI,MAAM,EAAE,CAAC;QAC5B,kDAAkD;QAClD,OAAO,MAAM,CAAC,UAAU,IAAI,CAAC;YAC5B,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC;YACzC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACX,CAAC;IACD,IAAI,cAAc,IAAI,MAAM,EAAE,CAAC;QAC9B,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./web-animations/wait-for-transitions.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":"AAAA,cAAc,0CAA0C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./web-animations/wait-for-transitions.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":"AAAA,cAAc,0CAA0C,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A CSS transition as {@link waitForTransitions} reads it: a `CSSTransition`'s
3
+ * members, or a stand-in's. An animation that is not a transition has no
4
+ * `transitionProperty`.
5
+ */
6
+ export type TransitionLike = {
7
+ /** The CSS property it changes, a longhand such as `"opacity"`. */
8
+ readonly transitionProperty?: string;
9
+ readonly finished: Promise<unknown>;
10
+ };
11
+ /** An element whose transitions {@link waitForTransitions} waits for. */
12
+ export type TransitionsElement = {
13
+ getAnimations(options?: GetAnimationsOptions): readonly TransitionLike[];
14
+ };
15
+ /** Which transitions {@link waitForTransitions} waits for. */
16
+ export type WaitForTransitionsOptions = {
17
+ /**
18
+ * Those of the element's descendants too, and of its and their
19
+ * pseudo-elements (`::before`, `::after`, `::marker`), as `getAnimations({
20
+ * subtree: true })` lists them. Default: `false`, the element's own only.
21
+ */
22
+ readonly subtree?: boolean;
23
+ /**
24
+ * Only those changing one of these CSS properties, longhands as
25
+ * `transitionProperty` names them (`"opacity"`, `"margin-top"`). Default: all
26
+ * of them.
27
+ */
28
+ readonly properties?: readonly string[];
29
+ /** Aborting it stops the wait, which rejects with its reason. */
30
+ readonly signal?: AbortSignal;
31
+ };
32
+ /**
33
+ * Waits for the CSS transitions an element runs to end: the step after a class
34
+ * change has faded it out, before its content is swapped.
35
+ *
36
+ * It waits for a snapshot: the transitions `element.getAnimations()` lists at
37
+ * the call, after the style changes made before it, which the call applies. One
38
+ * that just started counts, a delayed one too, even of zero duration; one that
39
+ * never starts (no change, no duration nor delay) is not waited for, and one
40
+ * cancelled meanwhile counts as ended. A transition started after the call, by
41
+ * a later style change, is not waited for.
42
+ *
43
+ * Prefer it to listening for `transitionend`, which a cancelled or never
44
+ * started transition never fires, and which bubbles from descendants. A browser
45
+ * pausing a hidden page's rendering pauses its transitions too: bound the wait
46
+ * with `signal` where that matters, such as `AbortSignal.timeout(ms)`.
47
+ *
48
+ * @example
49
+ * panel.classList.add("is-hidden");
50
+ * await waitForTransitions(panel, { signal });
51
+ * panel.replaceChildren(next);
52
+ * panel.classList.remove("is-hidden");
53
+ *
54
+ * @param element The element, or a stand-in.
55
+ * @throws When `options.signal` is aborted, before or during the wait, its
56
+ * reason.
57
+ */
58
+ export declare function waitForTransitions(element: TransitionsElement, options?: WaitForTransitionsOptions): Promise<void>;
59
+ //# sourceMappingURL=wait-for-transitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait-for-transitions.d.ts","sourceRoot":"","sources":["../../../src/dom/web-animations/wait-for-transitions.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CACpC,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG;IAChC,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,SAAS,cAAc,EAAE,CAAC;CACzE,CAAC;AAEF,8DAA8D;AAC9D,MAAM,MAAM,yBAAyB,GAAG;IACvC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,iEAAiE;IACjE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,kBAAkB,CACvC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,CAAC,EAAE,yBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -0,0 +1,44 @@
1
+ import { raceAbort_ } from "../../_race-abort.js";
2
+ /**
3
+ * Waits for the CSS transitions an element runs to end: the step after a class
4
+ * change has faded it out, before its content is swapped.
5
+ *
6
+ * It waits for a snapshot: the transitions `element.getAnimations()` lists at
7
+ * the call, after the style changes made before it, which the call applies. One
8
+ * that just started counts, a delayed one too, even of zero duration; one that
9
+ * never starts (no change, no duration nor delay) is not waited for, and one
10
+ * cancelled meanwhile counts as ended. A transition started after the call, by
11
+ * a later style change, is not waited for.
12
+ *
13
+ * Prefer it to listening for `transitionend`, which a cancelled or never
14
+ * started transition never fires, and which bubbles from descendants. A browser
15
+ * pausing a hidden page's rendering pauses its transitions too: bound the wait
16
+ * with `signal` where that matters, such as `AbortSignal.timeout(ms)`.
17
+ *
18
+ * @example
19
+ * panel.classList.add("is-hidden");
20
+ * await waitForTransitions(panel, { signal });
21
+ * panel.replaceChildren(next);
22
+ * panel.classList.remove("is-hidden");
23
+ *
24
+ * @param element The element, or a stand-in.
25
+ * @throws When `options.signal` is aborted, before or during the wait, its
26
+ * reason.
27
+ */
28
+ export async function waitForTransitions(element, options) {
29
+ const signal = options?.signal;
30
+ signal?.throwIfAborted();
31
+ const properties = options?.properties;
32
+ const transitions = element
33
+ .getAnimations({ subtree: options?.subtree ?? false })
34
+ .filter(({ transitionProperty }) => transitionProperty !== undefined &&
35
+ (properties === undefined || properties.includes(transitionProperty)));
36
+ // A cancelled transition's `finished` rejects; it has ended all the same.
37
+ const ended = Promise.allSettled(transitions.map((transition) => transition.finished));
38
+ if (signal === undefined) {
39
+ await ended;
40
+ return;
41
+ }
42
+ await raceAbort_(ended, signal);
43
+ }
44
+ //# sourceMappingURL=wait-for-transitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait-for-transitions.js","sourceRoot":"","sources":["../../../src/dom/web-animations/wait-for-transitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAoClD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,OAA2B,EAC3B,OAAmC;IAEnC,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;IAC/B,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,CAAC;IACvC,MAAM,WAAW,GAAG,OAAO;SACzB,aAAa,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,CAAC;SACrD,MAAM,CACN,CAAC,EAAE,kBAAkB,EAAE,EAAE,EAAE,CAC1B,kBAAkB,KAAK,SAAS;QAChC,CAAC,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CACtE,CAAC;IACH,0EAA0E;IAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,CAC/B,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CACpD,CAAC;IACF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,KAAK,CAAC;QACZ,OAAO;IACR,CAAC;IAED,MAAM,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
+ export * from "./canvas/image-data-pixels.js";
2
+ export * from "./canvas/read-image-data.js";
1
3
  export * from "./indexeddb/indexed-db-error.js";
2
4
  export * from "./indexeddb/indexed-db-records.js";
3
5
  export * from "./indexeddb/open-indexed-db.js";
6
+ export * from "./media-capture/microphone-access.js";
7
+ export * from "./web-audio/audio-clock-mapping.js";
4
8
  export * from "./web-midi/web-midi-access.js";
5
9
  export * from "./web-midi/web-midi-inputs.js";
6
10
  export * from "./xhr/send-with-progress.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,10 @@
1
+ export * from "./canvas/image-data-pixels.js";
2
+ export * from "./canvas/read-image-data.js";
1
3
  export * from "./indexeddb/indexed-db-error.js";
2
4
  export * from "./indexeddb/indexed-db-records.js";
3
5
  export * from "./indexeddb/open-indexed-db.js";
6
+ export * from "./media-capture/microphone-access.js";
7
+ export * from "./web-audio/audio-clock-mapping.js";
4
8
  export * from "./web-midi/web-midi-access.js";
5
9
  export * from "./web-midi/web-midi-inputs.js";
6
10
  export * from "./xhr/send-with-progress.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * What a browser offers of audio capture: its `navigator`, or a stand-in. Every
3
+ * member is optional, as a browser may lack it, as `mediaDevices` outside a
4
+ * secure context.
5
+ */
6
+ export type MicrophoneNavigator = {
7
+ readonly mediaDevices?: Partial<Pick<MediaDevices, "getUserMedia" | "enumerateDevices">>;
8
+ readonly permissions?: Pick<Permissions, "query">;
9
+ };
10
+ /** A microphone the browser lists. */
11
+ export type MicrophoneDevice = {
12
+ readonly deviceId: string;
13
+ /** Empty until the page has been given a microphone. */
14
+ readonly label: string;
15
+ };
16
+ /** What to ask the microphone for, beyond audio with its processing off. */
17
+ export type MicrophoneStreamOptions = {
18
+ /**
19
+ * The microphone to use, which {@link requestMicrophoneStream} insists on
20
+ * (`exact`) but for a device the browser cannot open by that id, when it asks
21
+ * again without it; the browser's choice when omitted.
22
+ */
23
+ readonly deviceId?: string | undefined;
24
+ /**
25
+ * The sampling rate to ask for, Hz; an ideal one, which the browser may not
26
+ * match. No preference when omitted.
27
+ */
28
+ readonly sampleRate?: number | undefined;
29
+ /**
30
+ * Gives up waiting, as for a permission prompt the user leaves open: the call
31
+ * rejects with the signal's reason, and a microphone the browser opens
32
+ * afterwards is stopped at once.
33
+ */
34
+ readonly signal?: AbortSignal | undefined;
35
+ };
36
+ /** A microphone opened. */
37
+ export type MicrophoneStream = {
38
+ readonly stream: MediaStream;
39
+ /**
40
+ * Whether the `deviceId` asked for could not be opened and the stream is the
41
+ * one a second request, without it, opened: the browser's choice, its default
42
+ * microphone in practice but not necessarily. `false` without a `deviceId`.
43
+ */
44
+ readonly isDefaultInstead: boolean;
45
+ };
46
+ /** What waiting for the browser may be given up by. */
47
+ export type MicrophoneQueryOptions = {
48
+ /** Rejects the call with its reason once aborted. */
49
+ readonly signal?: AbortSignal | undefined;
50
+ };
51
+ /** The browser cannot capture audio, as outside a secure context. */
52
+ export declare class MicrophoneUnsupportedError extends Error {
53
+ constructor(options?: ErrorOptions);
54
+ }
55
+ /** The user, or the browser's settings, refused the microphone. */
56
+ export declare class MicrophoneDeniedError extends Error {
57
+ constructor(options?: ErrorOptions);
58
+ }
59
+ /** There is no microphone to open. */
60
+ export declare class MicrophoneNotFoundError extends Error {
61
+ constructor(options?: ErrorOptions);
62
+ }
63
+ /** Another application, or tab, holds the microphone, or it failed to start. */
64
+ export declare class MicrophoneInUseError extends Error {
65
+ constructor(options?: ErrorOptions);
66
+ }
67
+ /**
68
+ * Whether the page may reach the microphone without asking: `"granted"`;
69
+ * `"prompt"` when the browser would ask, or cannot say; `"denied"` when it
70
+ * refused; `"unsupported"` without audio capture. Never opens the microphone.
71
+ *
72
+ * @param navigator The page's `navigator`, or a stand-in.
73
+ * @throws When `signal` aborts, its reason.
74
+ */
75
+ export declare function queryMicrophonePermission(navigator: MicrophoneNavigator, options?: MicrophoneQueryOptions): Promise<PermissionState | "unsupported">;
76
+ /**
77
+ * The microphones the browser lists, without a device whose id it withholds:
78
+ * before the page was given a microphone it lists them without ids. Empty when
79
+ * the browser cannot list them.
80
+ *
81
+ * @param navigator The page's `navigator`, or a stand-in.
82
+ * @throws When `signal` aborts, its reason.
83
+ */
84
+ export declare function listMicrophones(navigator: MicrophoneNavigator, options?: MicrophoneQueryOptions): Promise<MicrophoneDevice[]>;
85
+ /**
86
+ * Opens a microphone for analysis: echo cancellation, noise suppression, auto
87
+ * gain and voice isolation off, one channel preferred. It may ask the user
88
+ * first, and answers once they did, so call it from a user gesture.
89
+ *
90
+ * A microphone chosen by `deviceId` that the browser cannot open by it is asked
91
+ * for once more without it, and `isDefaultInstead` says so: on an
92
+ * `OverconstrainedError` whose `constraint` is `"deviceId"`, or is empty or
93
+ * absent (a browser withholds it before the page was given a microphone, and
94
+ * `deviceId` is the only constraint asked for as `exact`, so it is the only one
95
+ * that can fail). One naming another constraint is not retried. The caller owns
96
+ * the stream: stop its tracks to release the microphone.
97
+ *
98
+ * @example
99
+ * const { stream } = await requestMicrophoneStream(navigator, {
100
+ * sampleRate: 48_000,
101
+ * });
102
+ *
103
+ * @param navigator The page's `navigator`, or a stand-in.
104
+ * @throws {MicrophoneUnsupportedError} Without audio capture.
105
+ * @throws {MicrophoneDeniedError} On `NotAllowedError` or `SecurityError`, or
106
+ * `PermissionDeniedError` as old Chrome has it.
107
+ * @throws {MicrophoneNotFoundError} On `NotFoundError`, or
108
+ * `DevicesNotFoundError` as old Chrome has it.
109
+ * @throws {MicrophoneInUseError} On `NotReadableError`, or `AbortError`, as
110
+ * Firefox reports a microphone another application holds, or
111
+ * `TrackStartError` as old Chrome has it.
112
+ * @throws When `signal` aborts, its reason. Any other rejection goes through
113
+ * unchanged, a `TypeError` for constraints the browser refuses included.
114
+ */
115
+ export declare function requestMicrophoneStream(navigator: MicrophoneNavigator, options?: MicrophoneStreamOptions): Promise<MicrophoneStream>;
116
+ //# sourceMappingURL=microphone-access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"microphone-access.d.ts","sourceRoot":"","sources":["../../src/media-capture/microphone-access.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IACjC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAC9B,IAAI,CAAC,YAAY,EAAE,cAAc,GAAG,kBAAkB,CAAC,CACvD,CAAC;IACF,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;CAClD,CAAC;AAEF,sCAAsC;AACtC,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,wDAAwD;IACxD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,4EAA4E;AAC5E,MAAM,MAAM,uBAAuB,GAAG;IACrC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAA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