@ac-kit/browser 0.2.0 → 0.4.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 +193 -0
- package/README.md +239 -11
- package/dist/animation-frame/frame-scheduler.d.ts +91 -0
- package/dist/animation-frame/frame-scheduler.d.ts.map +1 -0
- package/dist/animation-frame/frame-scheduler.js +181 -0
- package/dist/animation-frame/frame-scheduler.js.map +1 -0
- package/dist/canvas/canvas-backing-size.d.ts +58 -0
- package/dist/canvas/canvas-backing-size.d.ts.map +1 -0
- package/dist/canvas/canvas-backing-size.js +141 -0
- package/dist/canvas/canvas-backing-size.js.map +1 -0
- package/dist/canvas/image-data-pixels.d.ts +1 -1
- package/dist/canvas/image-data-pixels.d.ts.map +1 -1
- package/dist/canvas/image-data-pixels.js +2 -5
- package/dist/canvas/image-data-pixels.js.map +1 -1
- package/dist/canvas/read-image-data.d.ts.map +1 -1
- package/dist/canvas/read-image-data.js +2 -2
- package/dist/canvas/read-image-data.js.map +1 -1
- package/dist/dom/drag-and-drop/file-drop-zone.d.ts +71 -0
- package/dist/dom/drag-and-drop/file-drop-zone.d.ts.map +1 -0
- package/dist/dom/drag-and-drop/file-drop-zone.js +145 -0
- package/dist/dom/drag-and-drop/file-drop-zone.js.map +1 -0
- package/dist/dom/forms/get-form-input.d.ts +17 -0
- package/dist/dom/forms/get-form-input.d.ts.map +1 -0
- package/dist/dom/forms/get-form-input.js +35 -0
- package/dist/dom/forms/get-form-input.js.map +1 -0
- package/dist/dom/index.d.ts +5 -0
- package/dist/dom/index.d.ts.map +1 -1
- package/dist/dom/index.js +5 -0
- package/dist/dom/index.js.map +1 -1
- package/dist/dom/media-query/watch-media-query.d.ts +26 -0
- package/dist/dom/media-query/watch-media-query.d.ts.map +1 -0
- package/dist/dom/media-query/watch-media-query.js +42 -0
- package/dist/dom/media-query/watch-media-query.js.map +1 -0
- package/dist/dom/resize-observer/observe-canvas-size.d.ts +54 -0
- package/dist/dom/resize-observer/observe-canvas-size.d.ts.map +1 -0
- package/dist/dom/resize-observer/observe-canvas-size.js +189 -0
- package/dist/dom/resize-observer/observe-canvas-size.js.map +1 -0
- package/dist/dom/user-activation/user-activation.d.ts +54 -0
- package/dist/dom/user-activation/user-activation.d.ts.map +1 -0
- package/dist/dom/user-activation/user-activation.js +93 -0
- package/dist/dom/user-activation/user-activation.js.map +1 -0
- package/dist/dom/web-animations/wait-for-transitions.d.ts.map +1 -1
- package/dist/dom/web-animations/wait-for-transitions.js +2 -6
- package/dist/dom/web-animations/wait-for-transitions.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/indexeddb/open-indexed-db.d.ts +1 -1
- package/dist/indexeddb/open-indexed-db.d.ts.map +1 -1
- package/dist/indexeddb/open-indexed-db.js +3 -1
- package/dist/indexeddb/open-indexed-db.js.map +1 -1
- package/dist/media-capture/microphone-access.d.ts.map +1 -1
- package/dist/media-capture/microphone-access.js +4 -6
- package/dist/media-capture/microphone-access.js.map +1 -1
- package/dist/permissions/_untracked-permission-watch.d.ts +4 -0
- package/dist/permissions/_untracked-permission-watch.d.ts.map +1 -0
- package/dist/permissions/_untracked-permission-watch.js +5 -0
- package/dist/permissions/_untracked-permission-watch.js.map +1 -0
- package/dist/permissions/watch-permission.d.ts +38 -0
- package/dist/permissions/watch-permission.d.ts.map +1 -0
- package/dist/permissions/watch-permission.js +58 -0
- package/dist/permissions/watch-permission.js.map +1 -0
- package/dist/temporal/enable-temporal.d.ts +44 -0
- package/dist/temporal/enable-temporal.d.ts.map +1 -0
- package/dist/temporal/enable-temporal.js +70 -0
- package/dist/temporal/enable-temporal.js.map +1 -0
- package/dist/testing/fake-animation-frames.d.ts +31 -0
- package/dist/testing/fake-animation-frames.d.ts.map +1 -0
- package/dist/testing/fake-animation-frames.js +75 -0
- package/dist/testing/fake-animation-frames.js.map +1 -0
- package/dist/testing/fake-audio-context.js +2 -2
- package/dist/testing/fake-audio-context.js.map +1 -1
- package/dist/testing/fake-match-media.d.ts +19 -0
- package/dist/testing/fake-match-media.d.ts.map +1 -0
- package/dist/testing/fake-match-media.js +135 -0
- package/dist/testing/fake-match-media.js.map +1 -0
- package/dist/testing/fake-media-devices.js +2 -2
- package/dist/testing/fake-media-devices.js.map +1 -1
- package/dist/testing/fake-permissions.d.ts +48 -0
- package/dist/testing/fake-permissions.d.ts.map +1 -0
- package/dist/testing/fake-permissions.js +90 -0
- package/dist/testing/fake-permissions.js.map +1 -0
- package/dist/testing/fake-resize-observer.d.ts +58 -0
- package/dist/testing/fake-resize-observer.d.ts.map +1 -0
- package/dist/testing/fake-resize-observer.js +118 -0
- package/dist/testing/fake-resize-observer.js.map +1 -0
- package/dist/testing/fake-web-midi.d.ts +26 -3
- package/dist/testing/fake-web-midi.d.ts.map +1 -1
- package/dist/testing/fake-web-midi.js +62 -2
- package/dist/testing/fake-web-midi.js.map +1 -1
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/web-audio/audio-clock-mapping.d.ts +36 -14
- package/dist/web-audio/audio-clock-mapping.d.ts.map +1 -1
- package/dist/web-audio/audio-clock-mapping.js +147 -35
- package/dist/web-audio/audio-clock-mapping.js.map +1 -1
- package/dist/web-midi/_midi-port.d.ts +4 -0
- package/dist/web-midi/_midi-port.d.ts.map +1 -0
- package/dist/web-midi/_midi-port.js +12 -0
- package/dist/web-midi/_midi-port.js.map +1 -0
- package/dist/web-midi/web-midi-access.d.ts +20 -0
- package/dist/web-midi/web-midi-access.d.ts.map +1 -1
- package/dist/web-midi/web-midi-access.js +31 -0
- package/dist/web-midi/web-midi-access.js.map +1 -1
- package/dist/web-midi/web-midi-inputs.d.ts.map +1 -1
- package/dist/web-midi/web-midi-inputs.js +1 -11
- package/dist/web-midi/web-midi-inputs.js.map +1 -1
- package/dist/web-midi/web-midi-pinned-input.d.ts +124 -0
- package/dist/web-midi/web-midi-pinned-input.d.ts.map +1 -0
- package/dist/web-midi/web-midi-pinned-input.js +177 -0
- package/dist/web-midi/web-midi-pinned-input.js.map +1 -0
- package/dist/xhr/send-with-progress.d.ts.map +1 -1
- package/dist/xhr/send-with-progress.js +3 -0
- package/dist/xhr/send-with-progress.js.map +1 -1
- package/package.json +20 -7
- package/dist/_race-abort.d.ts +0 -2
- package/dist/_race-abort.d.ts.map +0 -1
- package/dist/_race-abort.js +0 -20
- package/dist/_race-abort.js.map +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `ResizeObserver` stand-in for tests under Node: it records what is observed
|
|
3
|
+
* and delivers the entries the test gives it, as a browser does: an entry for a
|
|
4
|
+
* target only when the box it observes changed since the last one (the first
|
|
5
|
+
* always), carrying every box the size gives; observing a target again replaces
|
|
6
|
+
* the earlier observation and reports it afresh.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const ResizeObserver = FakeResizeObserver.create();
|
|
10
|
+
* const window = { ResizeObserver, devicePixelRatio: 2, … };
|
|
11
|
+
* ResizeObserver.resize({ cssWidth: 300, cssHeight: 150, devicePixelRatio: 2, devicePixelWidth: 600, devicePixelHeight: 300 });
|
|
12
|
+
*/
|
|
13
|
+
export class FakeResizeObserver {
|
|
14
|
+
callback_;
|
|
15
|
+
/** The targets observed, with the options each was given. */
|
|
16
|
+
observed = [];
|
|
17
|
+
isConnected = true;
|
|
18
|
+
refuseDevicePixelBox_;
|
|
19
|
+
reported_ = new Map();
|
|
20
|
+
constructor(callback_, options) {
|
|
21
|
+
this.callback_ = callback_;
|
|
22
|
+
this.refuseDevicePixelBox_ = options.refuseDevicePixelBox ?? false;
|
|
23
|
+
}
|
|
24
|
+
/** A constructor to hand to code that makes its own `ResizeObserver`. */
|
|
25
|
+
static create(options = {}) {
|
|
26
|
+
const instances = [];
|
|
27
|
+
return class extends FakeResizeObserver {
|
|
28
|
+
static instances = instances;
|
|
29
|
+
static resize(size, resizeOptions) {
|
|
30
|
+
for (const instance of instances) {
|
|
31
|
+
instance.resize(size, resizeOptions);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
constructor(callback) {
|
|
35
|
+
super(callback, options);
|
|
36
|
+
instances.push(this);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
observe(target, options) {
|
|
41
|
+
if (this.refuseDevicePixelBox_ &&
|
|
42
|
+
options?.box === "device-pixel-content-box") {
|
|
43
|
+
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': The provided value 'device-pixel-content-box' is not a valid enum value.");
|
|
44
|
+
}
|
|
45
|
+
this.unobserve(target);
|
|
46
|
+
this.observed.push(options === undefined ? { target } : { target, options });
|
|
47
|
+
this.isConnected = true;
|
|
48
|
+
}
|
|
49
|
+
unobserve(target) {
|
|
50
|
+
const index = this.observed.findIndex((item) => item.target === target);
|
|
51
|
+
if (index !== -1) {
|
|
52
|
+
this.observed.splice(index, 1);
|
|
53
|
+
}
|
|
54
|
+
this.reported_.delete(target);
|
|
55
|
+
}
|
|
56
|
+
disconnect() {
|
|
57
|
+
this.observed.length = 0;
|
|
58
|
+
this.reported_.clear();
|
|
59
|
+
this.isConnected = false;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Delivers, after layout, an entry for each observed target whose observed
|
|
63
|
+
* box changed. Nothing happens once disconnected.
|
|
64
|
+
*/
|
|
65
|
+
resize(size, options = {}) {
|
|
66
|
+
const entries = [];
|
|
67
|
+
for (const { target, options: observed } of this.observed) {
|
|
68
|
+
const isDeviceBox = observed?.box === "device-pixel-content-box";
|
|
69
|
+
const key = isDeviceBox
|
|
70
|
+
? `device ${size.devicePixelWidth} ${size.devicePixelHeight}`
|
|
71
|
+
: `content ${size.cssWidth} ${size.cssHeight}`;
|
|
72
|
+
if (this.reported_.get(target) === key) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
this.reported_.set(target, key);
|
|
76
|
+
entries.push(entryOf_(target, size, !this.refuseDevicePixelBox_, options.vertical === true));
|
|
77
|
+
}
|
|
78
|
+
if (entries.length > 0) {
|
|
79
|
+
this.callback_(entries, this);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function sizeOf_(inlineSize, blockSize) {
|
|
84
|
+
return { inlineSize, blockSize };
|
|
85
|
+
}
|
|
86
|
+
function entryOf_(target, size, hasDevicePixelBox, vertical) {
|
|
87
|
+
const { cssWidth, cssHeight, devicePixelWidth, devicePixelHeight } = size;
|
|
88
|
+
const contentBox = vertical
|
|
89
|
+
? sizeOf_(cssHeight, cssWidth)
|
|
90
|
+
: sizeOf_(cssWidth, cssHeight);
|
|
91
|
+
const devicePixelBox = hasDevicePixelBox &&
|
|
92
|
+
devicePixelWidth !== undefined &&
|
|
93
|
+
devicePixelHeight !== undefined
|
|
94
|
+
? [
|
|
95
|
+
vertical
|
|
96
|
+
? sizeOf_(devicePixelHeight, devicePixelWidth)
|
|
97
|
+
: sizeOf_(devicePixelWidth, devicePixelHeight),
|
|
98
|
+
]
|
|
99
|
+
: [];
|
|
100
|
+
return {
|
|
101
|
+
target,
|
|
102
|
+
contentRect: {
|
|
103
|
+
x: 0,
|
|
104
|
+
y: 0,
|
|
105
|
+
width: cssWidth,
|
|
106
|
+
height: cssHeight,
|
|
107
|
+
top: 0,
|
|
108
|
+
left: 0,
|
|
109
|
+
right: cssWidth,
|
|
110
|
+
bottom: cssHeight,
|
|
111
|
+
toJSON: () => ({}),
|
|
112
|
+
},
|
|
113
|
+
contentBoxSize: [contentBox],
|
|
114
|
+
borderBoxSize: [contentBox],
|
|
115
|
+
devicePixelContentBoxSize: devicePixelBox,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=fake-resize-observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-resize-observer.js","sourceRo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QAAQ;YACf,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;SAClB;QACD,cAAc,EAAE,CAAC,UAAU,CAAC;QAC5B,aAAa,EAAE,CAAC,UAAU,CAAC;QAC3B,yBAAyB,EAAE,cAAc;KACzC,CAAC;AACH,CAAC"}
|
|
@@ -1,15 +1,38 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* A Web MIDI input port that sends the messages it is told to. Its `connection`
|
|
3
|
+
* follows `open()` and `close()` as a browser's does: `"open"`, or `"pending"`
|
|
4
|
+
* while the device is disconnected, and `"closed"`; each change fires
|
|
5
|
+
* `statechange` on the access listing it.
|
|
6
|
+
*/
|
|
2
7
|
export declare class FakeMidiInput extends EventTarget {
|
|
3
8
|
readonly id: string;
|
|
4
9
|
readonly name: string | null;
|
|
5
10
|
readonly manufacturer: string | null;
|
|
6
11
|
state: MIDIPortDeviceState;
|
|
12
|
+
connection: MIDIPortConnectionState;
|
|
13
|
+
readonly type = "input";
|
|
14
|
+
/** How many times the page called {@link open}. */
|
|
15
|
+
openCount: number;
|
|
7
16
|
/** How many times the page called {@link close}. */
|
|
8
17
|
closeCount: number;
|
|
18
|
+
/**
|
|
19
|
+
* What the next {@link open} rejects with, as an `InvalidAccessError` when
|
|
20
|
+
* another application holds the device; once.
|
|
21
|
+
*/
|
|
22
|
+
openFailure: Error | undefined;
|
|
23
|
+
private readonly gates_;
|
|
9
24
|
constructor(id: string, name: string | null, manufacturer: string | null);
|
|
10
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Makes the next {@link open} wait, as a browser opening the device does.
|
|
27
|
+
*
|
|
28
|
+
* @returns What lets it go on.
|
|
29
|
+
*/
|
|
30
|
+
holdOpen(): () => void;
|
|
31
|
+
open(): Promise<this>;
|
|
32
|
+
close(): Promise<this>;
|
|
11
33
|
/** Sends `bytes` as one event that arrived at `timeStamp`. */
|
|
12
34
|
send(bytes: readonly number[], timeStamp: number): void;
|
|
35
|
+
private setConnection_;
|
|
13
36
|
}
|
|
14
37
|
/** A Web MIDI access whose ports are plugged in and out by the test. */
|
|
15
38
|
export declare class FakeMidiAccess extends EventTarget {
|
|
@@ -18,7 +41,7 @@ export declare class FakeMidiAccess extends EventTarget {
|
|
|
18
41
|
plug(input: FakeMidiInput): void;
|
|
19
42
|
/**
|
|
20
43
|
* Unplugs `input`: kept in the list as disconnected, as Chrome does, or
|
|
21
|
-
* dropped from it.
|
|
44
|
+
* dropped from it. An open port waits as `"pending"`.
|
|
22
45
|
*/
|
|
23
46
|
unplug(input: FakeMidiInput, isKept?: boolean): void;
|
|
24
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-web-midi.d.ts","sourceRoot":"","sources":["../../src/testing/fake-web-midi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fake-web-midi.d.ts","sourceRoot":"","sources":["../../src/testing/fake-web-midi.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAgB5C,QAAQ,CAAC,EAAE,EAAE,MAAM;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAjBrC,KAAK,EAAE,mBAAmB,CAAe;IACzC,UAAU,EAAE,uBAAuB,CAAY;IAC/C,QAAQ,CAAC,IAAI,WAAW;IACxB,mDAAmD;IACnD,SAAS,SAAK;IACd,oDAAoD;IACpD,UAAU,SAAK;IACf;;;OAGG;IACH,WAAW,EAAE,KAAK,GAAG,SAAS,CAAa;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAE9C,YACU,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,YAAY,EAAE,MAAM,GAAG,IAAI,EAGpC;IAED;;;;OAIG;IACH,QAAQ,IAAI,MAAM,IAAI,CAKrB;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAc1B;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAK3B;IAED,8DAA8D;IAC9D,IAAI,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAKtD;IAED,OAAO,CAAC,cAAc;CAQtB;AAED,wEAAwE;AACxE,qBAAa,cAAe,SAAQ,WAAW;IAC9C,QAAQ,CAAC,MAAM,6BAAoC;IAEnD,YAAY,GAAG,MAAM,EAAE,aAAa,EAAE,EAMrC;IAED,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAS/B;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,UAAQ,GAAG,IAAI,CASjD;CACD"}
|
|
@@ -1,19 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
// The access each input is listed in, told of its ports' connection changes.
|
|
2
|
+
const accessOf_ = new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* A Web MIDI input port that sends the messages it is told to. Its `connection`
|
|
5
|
+
* follows `open()` and `close()` as a browser's does: `"open"`, or `"pending"`
|
|
6
|
+
* while the device is disconnected, and `"closed"`; each change fires
|
|
7
|
+
* `statechange` on the access listing it.
|
|
8
|
+
*/
|
|
2
9
|
export class FakeMidiInput extends EventTarget {
|
|
3
10
|
id;
|
|
4
11
|
name;
|
|
5
12
|
manufacturer;
|
|
6
13
|
state = "connected";
|
|
14
|
+
connection = "closed";
|
|
15
|
+
type = "input";
|
|
16
|
+
/** How many times the page called {@link open}. */
|
|
17
|
+
openCount = 0;
|
|
7
18
|
/** How many times the page called {@link close}. */
|
|
8
19
|
closeCount = 0;
|
|
20
|
+
/**
|
|
21
|
+
* What the next {@link open} rejects with, as an `InvalidAccessError` when
|
|
22
|
+
* another application holds the device; once.
|
|
23
|
+
*/
|
|
24
|
+
openFailure = undefined;
|
|
25
|
+
gates_ = [];
|
|
9
26
|
constructor(id, name, manufacturer) {
|
|
10
27
|
super();
|
|
11
28
|
this.id = id;
|
|
12
29
|
this.name = name;
|
|
13
30
|
this.manufacturer = manufacturer;
|
|
14
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Makes the next {@link open} wait, as a browser opening the device does.
|
|
34
|
+
*
|
|
35
|
+
* @returns What lets it go on.
|
|
36
|
+
*/
|
|
37
|
+
holdOpen() {
|
|
38
|
+
const gate = Promise.withResolvers();
|
|
39
|
+
this.gates_.push(gate.promise);
|
|
40
|
+
return gate.resolve;
|
|
41
|
+
}
|
|
42
|
+
async open() {
|
|
43
|
+
this.openCount += 1;
|
|
44
|
+
const gate = this.gates_.shift();
|
|
45
|
+
if (gate !== undefined) {
|
|
46
|
+
await gate;
|
|
47
|
+
}
|
|
48
|
+
const failure = this.openFailure;
|
|
49
|
+
if (failure !== undefined) {
|
|
50
|
+
this.openFailure = undefined;
|
|
51
|
+
throw failure;
|
|
52
|
+
}
|
|
53
|
+
this.setConnection_(this.state === "connected" ? "open" : "pending");
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
15
56
|
async close() {
|
|
16
57
|
this.closeCount += 1;
|
|
58
|
+
this.setConnection_("closed");
|
|
59
|
+
return this;
|
|
17
60
|
}
|
|
18
61
|
/** Sends `bytes` as one event that arrived at `timeStamp`. */
|
|
19
62
|
send(bytes, timeStamp) {
|
|
@@ -22,6 +65,14 @@ export class FakeMidiInput extends EventTarget {
|
|
|
22
65
|
Object.defineProperty(event, "timeStamp", { value: timeStamp });
|
|
23
66
|
this.dispatchEvent(event);
|
|
24
67
|
}
|
|
68
|
+
setConnection_(connection) {
|
|
69
|
+
if (this.connection === connection) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.connection = connection;
|
|
73
|
+
this.dispatchEvent(new Event("statechange"));
|
|
74
|
+
accessOf_.get(this)?.dispatchEvent(new Event("statechange"));
|
|
75
|
+
}
|
|
25
76
|
}
|
|
26
77
|
/** A Web MIDI access whose ports are plugged in and out by the test. */
|
|
27
78
|
export class FakeMidiAccess extends EventTarget {
|
|
@@ -30,19 +81,28 @@ export class FakeMidiAccess extends EventTarget {
|
|
|
30
81
|
super();
|
|
31
82
|
for (const input of inputs) {
|
|
32
83
|
this.inputs.set(input.id, input);
|
|
84
|
+
accessOf_.set(input, this);
|
|
33
85
|
}
|
|
34
86
|
}
|
|
35
87
|
plug(input) {
|
|
36
88
|
input.state = "connected";
|
|
89
|
+
if (input.connection === "pending") {
|
|
90
|
+
// A browser opens a port again once its device is back.
|
|
91
|
+
input.connection = "open";
|
|
92
|
+
}
|
|
37
93
|
this.inputs.set(input.id, input);
|
|
94
|
+
accessOf_.set(input, this);
|
|
38
95
|
this.dispatchEvent(new Event("statechange"));
|
|
39
96
|
}
|
|
40
97
|
/**
|
|
41
98
|
* Unplugs `input`: kept in the list as disconnected, as Chrome does, or
|
|
42
|
-
* dropped from it.
|
|
99
|
+
* dropped from it. An open port waits as `"pending"`.
|
|
43
100
|
*/
|
|
44
101
|
unplug(input, isKept = false) {
|
|
45
102
|
input.state = "disconnected";
|
|
103
|
+
if (input.connection === "open") {
|
|
104
|
+
input.connection = "pending";
|
|
105
|
+
}
|
|
46
106
|
if (!isKept) {
|
|
47
107
|
this.inputs.delete(input.id);
|
|
48
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-web-midi.js","sourceRoot":"","sources":["../../src/testing/fake-web-midi.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"fake-web-midi.js","sourceRoot":"","sources":["../../src/testing/fake-web-midi.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,SAAS,GAAG,IAAI,OAAO,EAAiC,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,OAAO,aAAc,SAAQ,WAAW;IAgBnC,EAAE;IACF,IAAI;IACJ,YAAY;IAjBtB,KAAK,GAAwB,WAAW,CAAC;IACzC,UAAU,GAA4B,QAAQ,CAAC;IACtC,IA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,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACjC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAoB,EAAE,MAAM,GAAG,KAAK;QAC1C,KAAK,CAAC,KAAK,GAAG,cAAc,CAAC;QAC7B,IAAI,KAAK,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;YACjC,KAAK,CAAC,UAAU,GAAG,SAAS,CAAC;QAC9B,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC;IAC9C,CAAC;CACD"}
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export * from "./fake-animation-frames.js";
|
|
1
2
|
export * from "./fake-audio-context.js";
|
|
3
|
+
export * from "./fake-match-media.js";
|
|
2
4
|
export * from "./fake-media-devices.js";
|
|
5
|
+
export * from "./fake-permissions.js";
|
|
6
|
+
export * from "./fake-resize-observer.js";
|
|
3
7
|
export * from "./fake-web-midi.js";
|
|
4
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC"}
|
package/dist/testing/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export * from "./fake-animation-frames.js";
|
|
1
2
|
export * from "./fake-audio-context.js";
|
|
3
|
+
export * from "./fake-match-media.js";
|
|
2
4
|
export * from "./fake-media-devices.js";
|
|
5
|
+
export * from "./fake-permissions.js";
|
|
6
|
+
export * from "./fake-resize-observer.js";
|
|
3
7
|
export * from "./fake-web-midi.js";
|
|
4
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC"}
|
|
@@ -4,14 +4,17 @@ export type AudioClockMappingOptions = {
|
|
|
4
4
|
readonly windowMs: number;
|
|
5
5
|
/**
|
|
6
6
|
* The step, in milliseconds, that tells the audio clock was re-anchored: a
|
|
7
|
-
* tick that far below the offset, or
|
|
8
|
-
*
|
|
7
|
+
* tick that far below the offset, or a steady run of ticks, all within the
|
|
8
|
+
* window, that far above it.
|
|
9
9
|
*/
|
|
10
10
|
readonly jumpMs: number;
|
|
11
11
|
/**
|
|
12
|
-
* How
|
|
13
|
-
* still be one step in the audio clock, not jank or a backlog
|
|
14
|
-
*
|
|
12
|
+
* How far, in milliseconds, the floor of a run of ticks above the offset may
|
|
13
|
+
* move and still be one step in the audio clock, not jank or a backlog
|
|
14
|
+
* draining (whose floor keeps falling): its later half may rise by
|
|
15
|
+
* `steadyMs`, and the floor fall by at most `steadyMs / 4` over `readyTicks −
|
|
16
|
+
* 1` ticks. The jitter above the floor is not bounded by it: it lengthens the
|
|
17
|
+
* run needed.
|
|
15
18
|
*/
|
|
16
19
|
readonly steadyMs: number;
|
|
17
20
|
/** How many ticks since a reset make the mapping ready; a positive integer. */
|
|
@@ -33,20 +36,34 @@ export type AudioClockMappingOptions = {
|
|
|
33
36
|
* and what is left is the posting delay, within one render quantum of the true
|
|
34
37
|
* one (`biasMs` takes off a steady remainder). The mapping starts again when
|
|
35
38
|
* the clock is re-anchored: a context suspended and resumed, a worklet
|
|
36
|
-
* restarted ({@link AudioClockMapping.reset}), or a step the ticks show.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* ticks
|
|
39
|
+
* restarted ({@link AudioClockMapping.reset}), or a step the ticks show.
|
|
40
|
+
*
|
|
41
|
+
* A step up is taken from a steady run: the latest ticks, at least `readyTicks`
|
|
42
|
+
* of them, each more than `jumpMs` above the least offset of the ticks before
|
|
43
|
+
* it, whose floor is flat. The floor is the lower convex hull of the run's
|
|
44
|
+
* offsets: over the middle half of the run it may fall by at most `steadyMs /
|
|
45
|
+
* 4` per `readyTicks − 1` ticks, and the least offset of the run's later half
|
|
46
|
+
* may not rise more than `steadyMs` above its earlier half's. The ticks may
|
|
47
|
+
* jitter above that floor: the run must then be long enough that the least of
|
|
48
|
+
* half its ticks, for a jitter of the width the run and the ticks before it
|
|
49
|
+
* show (twice their mean delay above their least, each delay counted up to
|
|
50
|
+
* `jumpMs`), lies on average within half the fall allowed between the halves.
|
|
51
|
+
* Clean ticks give a step in `readyTicks`; ticks jittering by 8 ms, at a tick
|
|
52
|
+
* every 50 ms and `steadyMs` 5, in about 15. Jank, whose ticks spread over far
|
|
53
|
+
* more than their jitter, needs a run longer than any window holds; a backlog
|
|
54
|
+
* draining after a freeze falls. A step whose run never gets steady is still
|
|
55
|
+
* taken once the older ticks leave the window.
|
|
40
56
|
*
|
|
41
57
|
* It reads no clock and no global: the caller passes both times, so it runs in
|
|
42
58
|
* a worker or under Node as well.
|
|
43
59
|
*
|
|
44
60
|
* Time complexity: O(n) per {@link AudioClockMapping.observe}, n the ticks in
|
|
45
|
-
* the window (
|
|
46
|
-
* is checked); O(n) for
|
|
47
|
-
* {@link AudioClockMapping.
|
|
48
|
-
* Memory: O(n), the most ticks the window
|
|
49
|
-
* by doubling and never shrinks: a tick
|
|
61
|
+
* the window (scans for their minimum, and for the run's floors, hull and
|
|
62
|
+
* jitter when a step up is checked); O(n) for
|
|
63
|
+
* {@link AudioClockMapping.offsetMs}, {@link AudioClockMapping.toPageMs} and
|
|
64
|
+
* {@link AudioClockMapping.toAudioMs}. Memory: O(n), the most ticks the window
|
|
65
|
+
* has held, in a ring buffer that grows by doubling and never shrinks: a tick
|
|
66
|
+
* allocates nothing otherwise.
|
|
50
67
|
*
|
|
51
68
|
* @example
|
|
52
69
|
* const mapping = new AudioClockMapping({
|
|
@@ -69,6 +86,7 @@ export declare class AudioClockMapping {
|
|
|
69
86
|
private readonly biasMs_;
|
|
70
87
|
private pages_;
|
|
71
88
|
private offsets_;
|
|
89
|
+
private hull_;
|
|
72
90
|
private head_;
|
|
73
91
|
private size_;
|
|
74
92
|
private runLength_;
|
|
@@ -120,5 +138,9 @@ export declare class AudioClockMapping {
|
|
|
120
138
|
private add_;
|
|
121
139
|
private grow_;
|
|
122
140
|
private trackStepUp_;
|
|
141
|
+
private isSteadyRun_;
|
|
142
|
+
private floorSlope_;
|
|
143
|
+
private hullHeightAt_;
|
|
144
|
+
private jitterOf_;
|
|
123
145
|
}
|
|
124
146
|
//# sourceMappingURL=audio-clock-mapping.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-clock-mapping.d.ts","sourceRoot":"","sources":["../../src/web-audio/audio-clock-mapping.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,MAAM,wBAAwB,GAAG;IACtC,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB
|
|
1
|
+
{"version":3,"file":"audio-clock-mapping.d.ts","sourceRoot":"","sources":["../../src/web-audio/audio-clock-mapping.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,MAAM,wBAAwB,GAAG;IACtC,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,+EAA+E;IAC/E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAGjC,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,QAAQ,CAAuC;IAEvD,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,KAAK,CAAK;IAGlB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,WAAW,CAAa;IAEhC,2DAA2D;IAC3D,YAAY,OAAO,EAAE,wBAAwB,EAsB5C;IAED,iEAAiE;IACjE,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,+EAA+E;IAC/E,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAMjC;IAED;;;;;OAKG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAe7C;IAED;;;OAGG;IACH,KAAK,IAAI,IAAI,CAGZ;IAED;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhC;IAED;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhC;IAED,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,IAAI;IAgBZ,OAAO,CAAC,KAAK;IAeb,OAAO,CAAC,YAAY;IA8BpB,OAAO,CAAC,YAAY;IAgDpB,OAAO,CAAC,WAAW;IAsCnB,OAAO,CAAC,aAAa;IAuBrB,OAAO,CAAC,SAAS;CAgBjB"}
|
|
@@ -10,20 +10,34 @@ const INITIAL_CAPACITY_ = 16;
|
|
|
10
10
|
* and what is left is the posting delay, within one render quantum of the true
|
|
11
11
|
* one (`biasMs` takes off a steady remainder). The mapping starts again when
|
|
12
12
|
* the clock is re-anchored: a context suspended and resumed, a worklet
|
|
13
|
-
* restarted ({@link AudioClockMapping.reset}), or a step the ticks show.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* ticks
|
|
13
|
+
* restarted ({@link AudioClockMapping.reset}), or a step the ticks show.
|
|
14
|
+
*
|
|
15
|
+
* A step up is taken from a steady run: the latest ticks, at least `readyTicks`
|
|
16
|
+
* of them, each more than `jumpMs` above the least offset of the ticks before
|
|
17
|
+
* it, whose floor is flat. The floor is the lower convex hull of the run's
|
|
18
|
+
* offsets: over the middle half of the run it may fall by at most `steadyMs /
|
|
19
|
+
* 4` per `readyTicks − 1` ticks, and the least offset of the run's later half
|
|
20
|
+
* may not rise more than `steadyMs` above its earlier half's. The ticks may
|
|
21
|
+
* jitter above that floor: the run must then be long enough that the least of
|
|
22
|
+
* half its ticks, for a jitter of the width the run and the ticks before it
|
|
23
|
+
* show (twice their mean delay above their least, each delay counted up to
|
|
24
|
+
* `jumpMs`), lies on average within half the fall allowed between the halves.
|
|
25
|
+
* Clean ticks give a step in `readyTicks`; ticks jittering by 8 ms, at a tick
|
|
26
|
+
* every 50 ms and `steadyMs` 5, in about 15. Jank, whose ticks spread over far
|
|
27
|
+
* more than their jitter, needs a run longer than any window holds; a backlog
|
|
28
|
+
* draining after a freeze falls. A step whose run never gets steady is still
|
|
29
|
+
* taken once the older ticks leave the window.
|
|
17
30
|
*
|
|
18
31
|
* It reads no clock and no global: the caller passes both times, so it runs in
|
|
19
32
|
* a worker or under Node as well.
|
|
20
33
|
*
|
|
21
34
|
* Time complexity: O(n) per {@link AudioClockMapping.observe}, n the ticks in
|
|
22
|
-
* the window (
|
|
23
|
-
* is checked); O(n) for
|
|
24
|
-
* {@link AudioClockMapping.
|
|
25
|
-
* Memory: O(n), the most ticks the window
|
|
26
|
-
* by doubling and never shrinks: a tick
|
|
35
|
+
* the window (scans for their minimum, and for the run's floors, hull and
|
|
36
|
+
* jitter when a step up is checked); O(n) for
|
|
37
|
+
* {@link AudioClockMapping.offsetMs}, {@link AudioClockMapping.toPageMs} and
|
|
38
|
+
* {@link AudioClockMapping.toAudioMs}. Memory: O(n), the most ticks the window
|
|
39
|
+
* has held, in a ring buffer that grows by doubling and never shrinks: a tick
|
|
40
|
+
* allocates nothing otherwise.
|
|
27
41
|
*
|
|
28
42
|
* @example
|
|
29
43
|
* const mapping = new AudioClockMapping({
|
|
@@ -48,6 +62,8 @@ export class AudioClockMapping {
|
|
|
48
62
|
// arrived at and its offset.
|
|
49
63
|
pages_ = new Float64Array(INITIAL_CAPACITY_);
|
|
50
64
|
offsets_ = new Float64Array(INITIAL_CAPACITY_);
|
|
65
|
+
// Scratch for the lower hull of a run: positions in it, as long as the ring.
|
|
66
|
+
hull_ = new Int32Array(INITIAL_CAPACITY_);
|
|
51
67
|
head_ = 0;
|
|
52
68
|
size_ = 0;
|
|
53
69
|
// How many of the latest ticks of the window sit each more than `jumpMs`
|
|
@@ -202,6 +218,7 @@ export class AudioClockMapping {
|
|
|
202
218
|
}
|
|
203
219
|
this.pages_ = pages;
|
|
204
220
|
this.offsets_ = offsets;
|
|
221
|
+
this.hull_ = new Int32Array(capacity);
|
|
205
222
|
this.head_ = 0;
|
|
206
223
|
}
|
|
207
224
|
trackStepUp_(offsetMs) {
|
|
@@ -212,34 +229,129 @@ export class AudioClockMapping {
|
|
|
212
229
|
return;
|
|
213
230
|
}
|
|
214
231
|
// The run is the latest ticks of the window: those that left it are no
|
|
215
|
-
// longer part of it.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (this.
|
|
219
|
-
|
|
232
|
+
// longer part of it. It grows for as long as its ticks stay above, so a
|
|
233
|
+
// jittery one is weighed again on every tick.
|
|
234
|
+
this.runLength_ = Math.min(this.runLength_, earlierCount) + 1;
|
|
235
|
+
if (this.isSteadyRun_()) {
|
|
236
|
+
// Start again from the run alone.
|
|
237
|
+
this.head_ = this.slot_(this.size_ - this.runLength_);
|
|
238
|
+
this.size_ = this.runLength_;
|
|
239
|
+
this.tickCount_ = this.runLength_;
|
|
240
|
+
this.runLength_ = 0;
|
|
241
|
+
this.resetCount_ += 1;
|
|
220
242
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
const fall = this.offsets_[this.slot_(first)] - offsetMs;
|
|
234
|
-
if (highest - lowest > this.steadyMs_ || fall > this.steadyMs_ / 2) {
|
|
235
|
-
return;
|
|
243
|
+
}
|
|
244
|
+
// Whether the run is a step in the audio clock: that leaves the floor of the
|
|
245
|
+
// offsets flat from then on, with the ticks jittering above it as they did
|
|
246
|
+
// before. Jank leaves no floor, its ticks spread far above their least
|
|
247
|
+
// offset; a backlog draining after a freeze is ticks each handled in a task
|
|
248
|
+
// shorter than their interval, so their floor keeps falling; a climb keeps
|
|
249
|
+
// rising.
|
|
250
|
+
isSteadyRun_() {
|
|
251
|
+
const runLength = this.runLength_;
|
|
252
|
+
if (runLength < this.readyTicks_) {
|
|
253
|
+
return false;
|
|
236
254
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
255
|
+
const runStart = this.size_ - runLength;
|
|
256
|
+
let earlierFloor = Infinity;
|
|
257
|
+
let laterFloor = Infinity;
|
|
258
|
+
const halfLength = Math.floor(runLength / 2);
|
|
259
|
+
for (let position = 0; position < runLength; position += 1) {
|
|
260
|
+
const offset = this.offsets_[this.slot_(runStart + position)];
|
|
261
|
+
if (position < halfLength) {
|
|
262
|
+
earlierFloor = Math.min(earlierFloor, offset);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
laterFloor = Math.min(laterFloor, offset);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (halfLength === 0) {
|
|
269
|
+
// One tick, under `readyTicks: 1`, shows no trend.
|
|
270
|
+
earlierFloor = laterFloor;
|
|
271
|
+
}
|
|
272
|
+
const runJitterMs = this.jitterOf_(runStart, runLength);
|
|
273
|
+
const jitterBeforeMs = this.jitterOf_(0, runStart);
|
|
274
|
+
const jitterMs = Math.max(runJitterMs, jitterBeforeMs);
|
|
275
|
+
// The floor may fall by `fallPerTick` from one tick to the next, half the
|
|
276
|
+
// fall of `steadyMs / 2` over `readyTicks − 1` ticks that tells a backlog,
|
|
277
|
+
// so that neither a step nor a backlog sits at the bound. The least of
|
|
278
|
+
// `halfLength` delays spread evenly over the jitter lies
|
|
279
|
+
// `jitter / (halfLength + 1)` above the floor on average: the run is long
|
|
280
|
+
// enough once that is at most half the fall allowed from one half of the
|
|
281
|
+
// run to the other.
|
|
282
|
+
const fallPerTick = this.steadyMs_ / (4 * Math.max(1, this.readyTicks_ - 1));
|
|
283
|
+
const span = runLength - halfLength;
|
|
284
|
+
if (jitterMs / (halfLength + 1) > (fallPerTick * span) / 2) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
return (-this.floorSlope_(runStart, runLength) <= fallPerTick &&
|
|
288
|
+
laterFloor - earlierFloor <= this.steadyMs_);
|
|
289
|
+
}
|
|
290
|
+
// The mean slope, per tick, of the lower convex hull of `count` ticks from
|
|
291
|
+
// `start` over their middle half: the floor of the offsets, drawn through
|
|
292
|
+
// the lowest ticks, which the jitter above it moves least. A falling floor's
|
|
293
|
+
// least offset is its last few ticks; the hull uses them all.
|
|
294
|
+
floorSlope_(start, count) {
|
|
295
|
+
const hull = this.hull_;
|
|
296
|
+
let hullSize = 0;
|
|
297
|
+
for (let position = 0; position < count; position += 1) {
|
|
298
|
+
const offset = this.offsets_[this.slot_(start + position)];
|
|
299
|
+
while (hullSize >= 2) {
|
|
300
|
+
const a = hull[hullSize - 2];
|
|
301
|
+
const b = hull[hullSize - 1];
|
|
302
|
+
const offsetA = this.offsets_[this.slot_(start + a)];
|
|
303
|
+
const offsetB = this.offsets_[this.slot_(start + b)];
|
|
304
|
+
// Keep b only where the hull turns up there.
|
|
305
|
+
if ((offsetB - offsetA) * (position - a) <
|
|
306
|
+
(offset - offsetA) * (b - a)) {
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
hullSize -= 1;
|
|
310
|
+
}
|
|
311
|
+
hull[hullSize] = position;
|
|
312
|
+
hullSize += 1;
|
|
313
|
+
}
|
|
314
|
+
if (hullSize < 2) {
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
// The hull's mean slope over the middle half of the run.
|
|
318
|
+
const from = (count - 1) / 4;
|
|
319
|
+
const to = (3 * (count - 1)) / 4;
|
|
320
|
+
return ((this.hullHeightAt_(start, hullSize, to) -
|
|
321
|
+
this.hullHeightAt_(start, hullSize, from)) /
|
|
322
|
+
(to - from));
|
|
323
|
+
}
|
|
324
|
+
// The height of the lower hull in `hull_`, of ticks from `start`, at the
|
|
325
|
+
// fractional tick `position` within its range.
|
|
326
|
+
hullHeightAt_(start, hullSize, position) {
|
|
327
|
+
const hull = this.hull_;
|
|
328
|
+
let edge = 1;
|
|
329
|
+
while (edge < hullSize - 1 && hull[edge] < position) {
|
|
330
|
+
edge += 1;
|
|
331
|
+
}
|
|
332
|
+
const from = hull[edge - 1];
|
|
333
|
+
const to = hull[edge];
|
|
334
|
+
const offsetFrom = this.offsets_[this.slot_(start + from)];
|
|
335
|
+
const offsetTo = this.offsets_[this.slot_(start + to)];
|
|
336
|
+
return (offsetFrom + ((offsetTo - offsetFrom) * (position - from)) / (to - from));
|
|
337
|
+
}
|
|
338
|
+
// The width of the jitter of `count` ticks of the window from `start`: twice
|
|
339
|
+
// their mean delay above their least offset, as for a jitter spread evenly.
|
|
340
|
+
// A delay of more than `jumpMs` is jank, not jitter, and counts as `jumpMs`.
|
|
341
|
+
jitterOf_(start, count) {
|
|
342
|
+
if (count === 0) {
|
|
343
|
+
return 0;
|
|
344
|
+
}
|
|
345
|
+
let floor = Infinity;
|
|
346
|
+
for (let position = start; position < start + count; position += 1) {
|
|
347
|
+
floor = Math.min(floor, this.offsets_[this.slot_(position)]);
|
|
348
|
+
}
|
|
349
|
+
let delays = 0;
|
|
350
|
+
for (let position = start; position < start + count; position += 1) {
|
|
351
|
+
const delay = this.offsets_[this.slot_(position)] - floor;
|
|
352
|
+
delays += Math.min(delay, this.jumpMs_);
|
|
353
|
+
}
|
|
354
|
+
return (2 * delays) / count;
|
|
243
355
|
}
|
|
244
356
|
}
|
|
245
357
|
//# sourceMappingURL=audio-clock-mapping.js.map
|