@ac-kit/browser 0.1.1 → 0.3.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 (79) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +325 -4
  3. package/dist/animation-frame/frame-scheduler.d.ts +91 -0
  4. package/dist/animation-frame/frame-scheduler.d.ts.map +1 -0
  5. package/dist/animation-frame/frame-scheduler.js +181 -0
  6. package/dist/animation-frame/frame-scheduler.js.map +1 -0
  7. package/dist/canvas/canvas-backing-size.d.ts +58 -0
  8. package/dist/canvas/canvas-backing-size.d.ts.map +1 -0
  9. package/dist/canvas/canvas-backing-size.js +141 -0
  10. package/dist/canvas/canvas-backing-size.js.map +1 -0
  11. package/dist/canvas/image-data-pixels.d.ts +61 -0
  12. package/dist/canvas/image-data-pixels.d.ts.map +1 -0
  13. package/dist/canvas/image-data-pixels.js +71 -0
  14. package/dist/canvas/image-data-pixels.js.map +1 -0
  15. package/dist/canvas/read-image-data.d.ts +120 -0
  16. package/dist/canvas/read-image-data.d.ts.map +1 -0
  17. package/dist/canvas/read-image-data.js +147 -0
  18. package/dist/canvas/read-image-data.js.map +1 -0
  19. package/dist/dom/index.d.ts +4 -0
  20. package/dist/dom/index.d.ts.map +1 -0
  21. package/dist/dom/index.js +4 -0
  22. package/dist/dom/index.js.map +1 -0
  23. package/dist/dom/media-query/watch-media-query.d.ts +26 -0
  24. package/dist/dom/media-query/watch-media-query.d.ts.map +1 -0
  25. package/dist/dom/media-query/watch-media-query.js +42 -0
  26. package/dist/dom/media-query/watch-media-query.js.map +1 -0
  27. package/dist/dom/resize-observer/observe-canvas-size.d.ts +54 -0
  28. package/dist/dom/resize-observer/observe-canvas-size.d.ts.map +1 -0
  29. package/dist/dom/resize-observer/observe-canvas-size.js +189 -0
  30. package/dist/dom/resize-observer/observe-canvas-size.js.map +1 -0
  31. package/dist/dom/web-animations/wait-for-transitions.d.ts +59 -0
  32. package/dist/dom/web-animations/wait-for-transitions.d.ts.map +1 -0
  33. package/dist/dom/web-animations/wait-for-transitions.js +40 -0
  34. package/dist/dom/web-animations/wait-for-transitions.js.map +1 -0
  35. package/dist/index.d.ts +6 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +6 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/indexeddb/open-indexed-db.d.ts +1 -1
  40. package/dist/indexeddb/open-indexed-db.d.ts.map +1 -1
  41. package/dist/indexeddb/open-indexed-db.js +2 -1
  42. package/dist/indexeddb/open-indexed-db.js.map +1 -1
  43. package/dist/media-capture/microphone-access.d.ts +116 -0
  44. package/dist/media-capture/microphone-access.d.ts.map +1 -0
  45. package/dist/media-capture/microphone-access.js +222 -0
  46. package/dist/media-capture/microphone-access.js.map +1 -0
  47. package/dist/testing/fake-animation-frames.d.ts +31 -0
  48. package/dist/testing/fake-animation-frames.d.ts.map +1 -0
  49. package/dist/testing/fake-animation-frames.js +75 -0
  50. package/dist/testing/fake-animation-frames.js.map +1 -0
  51. package/dist/testing/fake-audio-context.d.ts +174 -0
  52. package/dist/testing/fake-audio-context.d.ts.map +1 -0
  53. package/dist/testing/fake-audio-context.js +314 -0
  54. package/dist/testing/fake-audio-context.js.map +1 -0
  55. package/dist/testing/fake-match-media.d.ts +19 -0
  56. package/dist/testing/fake-match-media.d.ts.map +1 -0
  57. package/dist/testing/fake-match-media.js +135 -0
  58. package/dist/testing/fake-match-media.js.map +1 -0
  59. package/dist/testing/fake-media-devices.d.ts +90 -0
  60. package/dist/testing/fake-media-devices.d.ts.map +1 -0
  61. package/dist/testing/fake-media-devices.js +147 -0
  62. package/dist/testing/fake-media-devices.js.map +1 -0
  63. package/dist/testing/fake-resize-observer.d.ts +58 -0
  64. package/dist/testing/fake-resize-observer.d.ts.map +1 -0
  65. package/dist/testing/fake-resize-observer.js +118 -0
  66. package/dist/testing/fake-resize-observer.js.map +1 -0
  67. package/dist/testing/fake-web-midi.d.ts +25 -0
  68. package/dist/testing/fake-web-midi.d.ts.map +1 -0
  69. package/dist/testing/fake-web-midi.js +52 -0
  70. package/dist/testing/fake-web-midi.js.map +1 -0
  71. package/dist/testing/index.d.ts +7 -0
  72. package/dist/testing/index.d.ts.map +1 -0
  73. package/dist/testing/index.js +7 -0
  74. package/dist/testing/index.js.map +1 -0
  75. package/dist/web-audio/audio-clock-mapping.d.ts +124 -0
  76. package/dist/web-audio/audio-clock-mapping.d.ts.map +1 -0
  77. package/dist/web-audio/audio-clock-mapping.js +245 -0
  78. package/dist/web-audio/audio-clock-mapping.js.map +1 -0
  79. package/package.json +23 -7
@@ -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,EAAmC,MAAM,cAAc,CAAC;AAE9E;;;;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 { describeValue, 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 ${describeValue(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,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AA8E9E;;;;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;IAE9B,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;IACjC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAA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AAE,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,4 @@
1
+ export * from "./media-query/watch-media-query.js";
2
+ export * from "./resize-observer/observe-canvas-size.js";
3
+ export * from "./web-animations/wait-for-transitions.js";
4
+ //# 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,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,0CAA0C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./media-query/watch-media-query.js";
2
+ export * from "./resize-observer/observe-canvas-size.js";
3
+ export * from "./web-animations/wait-for-transitions.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,0CAA0C,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { Callable } from "@ac-kit/core";
2
+ export type WatchMediaQueryOptions = {
3
+ /** Called with the new value each time the query starts or stops matching. */
4
+ readonly onChange?: Callable<[matches: boolean]>;
5
+ readonly signal?: AbortSignal;
6
+ };
7
+ /** A media query followed until disposed. */
8
+ export type MediaQueryWatch = Disposable & {
9
+ /** Whether the query matches now (the last value known once disposed). */
10
+ readonly matches: boolean;
11
+ };
12
+ /**
13
+ * Follows a media query of a window, such as `(prefers-reduced-motion:
14
+ * reduce)`, so a binding reads the person's current setting rather than the one
15
+ * at bind time.
16
+ *
17
+ * @example
18
+ * using motion = watchMediaQuery(window, "(prefers-reduced-motion: reduce)");
19
+ * if (!motion.matches) {
20
+ * animate();
21
+ * }
22
+ *
23
+ * @throws {TypeError} When the window has no `matchMedia`.
24
+ */
25
+ export declare function watchMediaQuery(view: Pick<Window, "matchMedia">, query: string, options?: WatchMediaQueryOptions): MediaQueryWatch;
26
+ //# sourceMappingURL=watch-media-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch-media-query.d.ts","sourceRoot":"","sources":["../../../src/dom/media-query/watch-media-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,MAAM,sBAAsB,GAAG;IACpC,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B,CAAC;AAEF,6CAA6C;AAC7C,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG;IAC1C,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,EAChC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,sBAA2B,GAClC,eAAe,CAiCjB"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Follows a media query of a window, such as `(prefers-reduced-motion:
3
+ * reduce)`, so a binding reads the person's current setting rather than the one
4
+ * at bind time.
5
+ *
6
+ * @example
7
+ * using motion = watchMediaQuery(window, "(prefers-reduced-motion: reduce)");
8
+ * if (!motion.matches) {
9
+ * animate();
10
+ * }
11
+ *
12
+ * @throws {TypeError} When the window has no `matchMedia`.
13
+ */
14
+ export function watchMediaQuery(view, query, options = {}) {
15
+ const { onChange, signal } = options;
16
+ if (typeof view.matchMedia !== "function") {
17
+ throw new TypeError("watchMediaQuery: the window has no matchMedia");
18
+ }
19
+ const list = view.matchMedia(query);
20
+ const lifetime = new AbortController();
21
+ const stop = signal === undefined
22
+ ? lifetime.signal
23
+ : AbortSignal.any([signal, lifetime.signal]);
24
+ let matches = list.matches;
25
+ if (!stop.aborted) {
26
+ list.addEventListener("change", (event) => {
27
+ matches = event.matches;
28
+ onChange?.(matches);
29
+ }, { signal: stop });
30
+ // Keeps what was read last, whatever the list says afterwards.
31
+ stop.addEventListener("abort", () => {
32
+ matches = list.matches;
33
+ });
34
+ }
35
+ return {
36
+ get matches() {
37
+ return stop.aborted ? matches : list.matches;
38
+ },
39
+ [Symbol.dispose]: () => lifetime.abort(),
40
+ };
41
+ }
42
+ //# sourceMappingURL=watch-media-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch-media-query.js","sourceRoot":"","sources":["../../../src/dom/media-query/watch-media-query.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAgC,EAChC,KAAa,EACb,OAAO,GAA2B,EAAE;IAEpC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACrC,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC3C,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;IACvC,MAAM,IAAI,GACT,MAAM,KAAK,SAAS;QACnB,CAAC,CAAC,QAAQ,CAAC,MAAM;QACjB,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACnB,IAAI,CAAC,gBAAgB,CACpB,QAAQ,EACR,CAAC,KAAK,EAAE,EAAE;YACT,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;YACxB,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC;QACrB,CAAC,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CAChB,CAAC;QACF,+DAA+D;QAC/D,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YACnC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QACxB,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,OAAO;QACN,IAAI,OAAO;YACV,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QAC9C,CAAC;QACD,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE;KACxC,CAAC;AACH,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { Callable } from "@ac-kit/core";
2
+ import { type CanvasBackingSize, type CanvasBackingSizeOptions } from "../../canvas/canvas-backing-size.js";
3
+ export type ObserveCanvasSizeOptions = CanvasBackingSizeOptions & {
4
+ /**
5
+ * Called after layout and before paint whenever the backing size changes, and
6
+ * once at the first layout. Render here (synchronously) to avoid one
7
+ * stretched frame: animation-frame callbacks of this frame have run already.
8
+ */
9
+ readonly onResize: Callable<[size: CanvasBackingSize]>;
10
+ /**
11
+ * Assign `canvas.width` and `canvas.height` when they differ (never when
12
+ * equal: assigning resets the canvas). Default true; false for a canvas
13
+ * handed to a worker with `transferControlToOffscreen`, whose size goes to
14
+ * the worker in `onResize`.
15
+ */
16
+ readonly resizeCanvas?: boolean;
17
+ readonly signal?: AbortSignal;
18
+ };
19
+ /**
20
+ * Keeps a canvas's backing store at its displayed size in device pixels. Uses
21
+ * the `ResizeObserver` and `devicePixelRatio` of the canvas's own window
22
+ * (`ownerDocument.defaultView`), observing `device-pixel-content-box` where
23
+ * supported (it also fires when the ratio changes, e.g. on another screen) and
24
+ * `content-box` (the caps depend on the CSS size, which can change while the
25
+ * device box does not), else `content-box` plus a `resolution` media query for
26
+ * ratio changes; the query also follows the ratio where an entry gives no
27
+ * device-pixel size. A ratio change is measured again after the next layout,
28
+ * never from the size known before it. An empty box (hidden canvas) changes
29
+ * nothing and calls nothing. Only a change of the size is reported.
30
+ *
31
+ * The canvas's CSS size must not depend on its `width` and `height` attributes
32
+ * (a canvas with none of its own is as large as them): the backing size would
33
+ * feed back into the layout. Give it a CSS size (`width: 100%`, a grid or flex
34
+ * track, a fixed size).
35
+ *
36
+ * If `onResize` throws, the canvas is already resized and the error is reported
37
+ * by the host like any `ResizeObserver` callback's.
38
+ *
39
+ * @example
40
+ * using observation = observeCanvasSize(canvas, {
41
+ * maxPixelRatio: 2,
42
+ * onResize: (size) => {
43
+ * aspect = size.cssWidth / size.cssHeight;
44
+ * scheduler.renderNow();
45
+ * },
46
+ * signal,
47
+ * });
48
+ *
49
+ * @returns Stops observing; disposing it again does nothing.
50
+ * @throws {TypeError} When the canvas has no window or its window has no
51
+ * `ResizeObserver`.
52
+ */
53
+ export declare function observeCanvasSize(canvas: HTMLCanvasElement, options: ObserveCanvasSizeOptions): Disposable;
54
+ //# sourceMappingURL=observe-canvas-size.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observe-canvas-size.d.ts","sourceRoot":"","sources":["../../../src/dom/resize-observer/observe-canvas-size.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAE7B,MAAM,qCAAqC,CAAC;AAE7C,MAAM,MAAM,wBAAwB,GAAG,wBAAwB,GAAG;IACjE;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC;IACvD;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B,CAAC;AAUF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,wBAAwB,GAC/B,UAAU,CAiKZ"}
@@ -0,0 +1,189 @@
1
+ import { canvasBackingSize, } from "../../canvas/canvas-backing-size.js";
2
+ /**
3
+ * Keeps a canvas's backing store at its displayed size in device pixels. Uses
4
+ * the `ResizeObserver` and `devicePixelRatio` of the canvas's own window
5
+ * (`ownerDocument.defaultView`), observing `device-pixel-content-box` where
6
+ * supported (it also fires when the ratio changes, e.g. on another screen) and
7
+ * `content-box` (the caps depend on the CSS size, which can change while the
8
+ * device box does not), else `content-box` plus a `resolution` media query for
9
+ * ratio changes; the query also follows the ratio where an entry gives no
10
+ * device-pixel size. A ratio change is measured again after the next layout,
11
+ * never from the size known before it. An empty box (hidden canvas) changes
12
+ * nothing and calls nothing. Only a change of the size is reported.
13
+ *
14
+ * The canvas's CSS size must not depend on its `width` and `height` attributes
15
+ * (a canvas with none of its own is as large as them): the backing size would
16
+ * feed back into the layout. Give it a CSS size (`width: 100%`, a grid or flex
17
+ * track, a fixed size).
18
+ *
19
+ * If `onResize` throws, the canvas is already resized and the error is reported
20
+ * by the host like any `ResizeObserver` callback's.
21
+ *
22
+ * @example
23
+ * using observation = observeCanvasSize(canvas, {
24
+ * maxPixelRatio: 2,
25
+ * onResize: (size) => {
26
+ * aspect = size.cssWidth / size.cssHeight;
27
+ * scheduler.renderNow();
28
+ * },
29
+ * signal,
30
+ * });
31
+ *
32
+ * @returns Stops observing; disposing it again does nothing.
33
+ * @throws {TypeError} When the canvas has no window or its window has no
34
+ * `ResizeObserver`.
35
+ */
36
+ export function observeCanvasSize(canvas, options) {
37
+ const { onResize, resizeCanvas = true, signal } = options;
38
+ const view = canvas.ownerDocument.defaultView;
39
+ if (view === null || typeof view.ResizeObserver !== "function") {
40
+ throw new TypeError("observeCanvasSize: the canvas has no window with a ResizeObserver");
41
+ }
42
+ const lifetime = new AbortController();
43
+ const disposable = { [Symbol.dispose]: () => lifetime.abort() };
44
+ // A derived signal aborts whatever a listener on `signal` does to the event.
45
+ const stopSignal = signal === undefined
46
+ ? lifetime.signal
47
+ : AbortSignal.any([signal, lifetime.signal]);
48
+ if (stopSignal.aborted) {
49
+ return disposable;
50
+ }
51
+ let last;
52
+ let devicePixels = true;
53
+ let isWatchingRatio = false;
54
+ const observations = [];
55
+ const apply = (box) => {
56
+ if (stopSignal.aborted || box.cssWidth === 0 || box.cssHeight === 0) {
57
+ return;
58
+ }
59
+ const size = canvasBackingSize(box, options);
60
+ if (last !== undefined &&
61
+ last.width === size.width &&
62
+ last.height === size.height &&
63
+ last.cssWidth === size.cssWidth &&
64
+ last.cssHeight === size.cssHeight) {
65
+ return;
66
+ }
67
+ last = size;
68
+ // Assigning resets a canvas, even to the value it has.
69
+ if (resizeCanvas && canvas.width !== size.width) {
70
+ canvas.width = size.width;
71
+ }
72
+ if (resizeCanvas && canvas.height !== size.height) {
73
+ canvas.height = size.height;
74
+ }
75
+ onResize(size);
76
+ };
77
+ // Observing a target again reports it afresh, after the next layout: a ratio
78
+ // change is measured with the layout it comes with, never before.
79
+ const measureAgain = () => {
80
+ for (const { observer, options: observed } of observations) {
81
+ observer.observe(canvas, observed);
82
+ }
83
+ };
84
+ const watchRatio = () => {
85
+ if (typeof view.matchMedia !== "function") {
86
+ return;
87
+ }
88
+ const query = view.matchMedia(`(resolution: ${view.devicePixelRatio}dppx)`);
89
+ query.addEventListener("change", () => {
90
+ watchRatio();
91
+ measureAgain();
92
+ }, { once: true, signal: stopSignal });
93
+ };
94
+ const onEntries = (entries) => {
95
+ let entry;
96
+ for (const candidate of entries) {
97
+ if (candidate.target === canvas) {
98
+ entry = candidate;
99
+ }
100
+ }
101
+ if (entry === undefined) {
102
+ return;
103
+ }
104
+ const { width, height } = entry.contentRect;
105
+ const box = {
106
+ cssWidth: width,
107
+ cssHeight: height,
108
+ devicePixelRatio: view.devicePixelRatio,
109
+ };
110
+ const devicePixelSize = devicePixels
111
+ ? entry.devicePixelContentBoxSize?.[0]
112
+ : undefined;
113
+ if (devicePixelSize !== undefined &&
114
+ devicePixelSize.inlineSize > 0 &&
115
+ devicePixelSize.blockSize > 0) {
116
+ const isVertical = isVerticalWritingMode_(view, canvas) ??
117
+ // Without a computed style: the content box's axes against the rect's.
118
+ isSwapped_(entry.contentBoxSize?.[0], width, height);
119
+ box.devicePixelWidth = isVertical
120
+ ? devicePixelSize.blockSize
121
+ : devicePixelSize.inlineSize;
122
+ box.devicePixelHeight = isVertical
123
+ ? devicePixelSize.inlineSize
124
+ : devicePixelSize.blockSize;
125
+ }
126
+ else if (devicePixels && width > 0 && height > 0 && !isWatchingRatio) {
127
+ // An entry without a device-pixel size does not follow the ratio.
128
+ isWatchingRatio = true;
129
+ watchRatio();
130
+ }
131
+ apply(box);
132
+ };
133
+ const observe = (observer, observed) => {
134
+ observer.observe(canvas, observed);
135
+ observations.push({ observer, options: observed });
136
+ };
137
+ const primaryObserver = new view.ResizeObserver(onEntries);
138
+ try {
139
+ observe(primaryObserver, { box: "device-pixel-content-box" });
140
+ // The device box alone does not report a change of the CSS size that
141
+ // leaves it as it is (the ratio caps depend on that size).
142
+ observe(new view.ResizeObserver(onEntries), { box: "content-box" });
143
+ }
144
+ catch (error) {
145
+ const isUnsupported = isTypeError_(error);
146
+ // Another realm's TypeError is not this realm's `TypeError`.
147
+ for (const { observer } of observations) {
148
+ observer.disconnect();
149
+ }
150
+ observations.length = 0;
151
+ if (!isUnsupported) {
152
+ throw error;
153
+ }
154
+ // Safari: no device-pixel box.
155
+ devicePixels = false;
156
+ observe(primaryObserver, { box: "content-box" });
157
+ isWatchingRatio = true;
158
+ watchRatio();
159
+ }
160
+ stopSignal.addEventListener("abort", () => {
161
+ for (const { observer } of observations) {
162
+ observer.disconnect();
163
+ }
164
+ }, { once: true });
165
+ return disposable;
166
+ }
167
+ function isTypeError_(error) {
168
+ return (typeof error === "object" &&
169
+ error !== null &&
170
+ "name" in error &&
171
+ error.name === "TypeError");
172
+ }
173
+ // A vertical writing mode makes the inline size the height.
174
+ function isVerticalWritingMode_(view, canvas) {
175
+ if (typeof view.getComputedStyle !== "function") {
176
+ return undefined;
177
+ }
178
+ const { writingMode } = view.getComputedStyle(canvas);
179
+ return typeof writingMode === "string" && writingMode !== ""
180
+ ? !writingMode.startsWith("horizontal")
181
+ : undefined;
182
+ }
183
+ function isSwapped_(contentSize, width, height) {
184
+ return (contentSize !== undefined &&
185
+ width !== height &&
186
+ contentSize.inlineSize === height &&
187
+ contentSize.blockSize === width);
188
+ }
189
+ //# sourceMappingURL=observe-canvas-size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observe-canvas-size.js","sourceRoot":"","sources":["../../../src/dom/resize-observer/observe-canvas-size.ts"],"names":[],"mappings":"AAEA,OAAO,EAGN,iBAAiB,GACjB,MAAM,qCAAqC,CAAC;AA2B7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM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UAAU,CAAC,gBAAgB,CAC1B,OAAO,EACP,GAAG,EAAE;QACJ,KAAK,MAAM,EAAE,QAAQ,EAAE,IAAI,YAAY,EAAE,CAAC;YACzC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;IACF,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACd,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IACnC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,IAAI,KAAK,WAAW,CAC1B,CAAC;AACH,CAAC;AAED,4DAA4D;AAC5D,SAAS,sBAAsB,CAC9B,IAAY,EACZ,MAAyB;IAEzB,IAAI,OAAO,IAAI,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAEtD,OAAO,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,EAAE;QAC3D,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC;QACvC,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AAED,SAAS,UAAU,CAClB,WAA2C,EAC3C,KAAa,EACb,MAAc;IAEd,OAAO,CACN,WAAW,KAAK,SAAS;QACzB,KAAK,KAAK,MAAM;QAChB,WAAW,CAAC,UAAU,KAAK,MAAM;QACjC,WAAW,CAAC,SAAS,KAAK,KAAK,CAC/B,CAAC;AACH,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,CAgBf"}
@@ -0,0 +1,40 @@
1
+ import { raceAbortSignal } from "@ac-kit/core";
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
+ await raceAbortSignal(ended, signal);
39
+ }
40
+ //# 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,eAAe,EAAE,MAAM,cAAc,CAAC;AAoC/C;;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,12 @@
1
+ export * from "./animation-frame/frame-scheduler.js";
2
+ export * from "./canvas/canvas-backing-size.js";
3
+ export * from "./canvas/image-data-pixels.js";
4
+ export * from "./canvas/read-image-data.js";
1
5
  export * from "./indexeddb/indexed-db-error.js";
2
6
  export * from "./indexeddb/indexed-db-records.js";
3
7
  export * from "./indexeddb/open-indexed-db.js";
8
+ export * from "./media-capture/microphone-access.js";
9
+ export * from "./web-audio/audio-clock-mapping.js";
4
10
  export * from "./web-midi/web-midi-access.js";
5
11
  export * from "./web-midi/web-midi-inputs.js";
6
12
  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,sCAAsC,CAAC;AACrD,cAAc,iCAAiC,CAAC;AAChD,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"}