alpha2 0.5.3 → 0.6.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/README.md +68 -3
- package/THIRD_PARTY_NOTICES.md +7 -3
- package/dist/apply-edit.d.ts +124 -0
- package/dist/apply-edit.js +15 -0
- package/dist/assets.d.ts +12 -0
- package/dist/audio-layout.js +6 -3
- package/dist/audio-worklet-processor.js +27 -33
- package/dist/audio.d.ts +5 -4
- package/dist/audio.js +8 -6
- package/dist/compose.d.ts +105 -0
- package/dist/compose.js +63 -0
- package/dist/decoder-fallback.d.ts +3 -2
- package/dist/decoder-fallback.js +11 -3
- package/dist/decoder-stall.d.ts +15 -0
- package/dist/decoder-stall.js +52 -0
- package/dist/edit-data.d.ts +24 -0
- package/dist/edit-data.js +224 -0
- package/dist/edit-keys.d.ts +16 -0
- package/dist/edit-keys.js +233 -0
- package/dist/edit.d.ts +41 -8
- package/dist/edit.js +123 -30
- package/dist/export-failure.d.ts +10 -2
- package/dist/export-failure.js +55 -4
- package/dist/export-retry.d.ts +6 -1
- package/dist/export-retry.js +12 -1
- package/dist/exporter.d.ts +11 -7
- package/dist/exporter.js +10 -9
- package/dist/extract.d.ts +65 -0
- package/dist/extract.js +291 -0
- package/dist/extractor.d.ts +151 -0
- package/dist/extractor.js +141 -0
- package/dist/float32.d.ts +2 -0
- package/dist/float32.js +10 -0
- package/dist/frame-intake.d.ts +5 -0
- package/dist/frame-intake.js +10 -3
- package/dist/generated/builtin-effects.d.ts +3 -0
- package/dist/generated/builtin-effects.js +1804 -0
- package/dist/generated/project-schema.d.ts +636 -37
- package/dist/generated/project-schema.js +55 -0
- package/dist/generated/project-shape.js +950 -381
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json-text.js +14 -2
- package/dist/layout-values.js +7 -1
- package/dist/layout.d.ts +12 -4
- package/dist/media.d.ts +43 -10
- package/dist/media.js +255 -66
- package/dist/mediabunny.d.ts +32 -12
- package/dist/mediabunny.js +276 -90
- package/dist/player.d.ts +9 -3
- package/dist/player.js +114 -18
- package/dist/plugins.d.ts +62 -0
- package/dist/plugins.js +506 -0
- package/dist/project-data.d.ts +56 -0
- package/dist/project-data.js +765 -0
- package/dist/project.d.ts +24 -1
- package/dist/project.js +456 -38
- package/dist/robustness.d.ts +6 -33
- package/dist/robustness.js +2 -63
- package/dist/sha256.d.ts +3 -2
- package/dist/sha256.js +14 -6
- package/dist/worker-error.d.ts +3 -2
- package/dist/worker-error.js +3 -1
- package/dist/worker.d.ts +13 -3
- package/dist/worker.js +36 -9
- package/package.json +26 -1
- package/wasm/alpha2_compose.d.ts +92 -0
- package/wasm/alpha2_compose.js +445 -0
- package/wasm/alpha2_compose_bg.wasm +0 -0
- package/wasm/alpha2_compose_bg.wasm.d.ts +17 -0
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +151 -18
- package/wasm/alpha2_wasm.js +403 -59
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +21 -6
- package/wasm/rust-crate-licenses.md +5 -61
- package/wasm/snippets/alpha2-wasm-1b02e9f302d283ba/inline3.js +7 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline1.js → alpha2-wasm-1b02e9f302d283ba/inline0.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline2.js → alpha2-wasm-1b02e9f302d283ba/inline1.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline3.js → alpha2-wasm-1b02e9f302d283ba/inline2.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a6265983c9769e80/inline0.js → alpha2-wasm-1b02e9f302d283ba/inline4.js} +0 -0
package/dist/robustness.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export type BrowserCapabilityDiagnostic = "webgpu-unavailable" | "webgl2-unavailable" | "webcodecs-unavailable" | "offscreen-canvas-unavailable" | "wasm-simd-unavailable" | "wasm-reference-types-unavailable"
|
|
3
|
-
/** Caller-configured browser resource limits; both must be positive integers. */
|
|
4
|
-
export interface BrowserResourceBudget {
|
|
5
|
-
readonly textureBytes: number;
|
|
6
|
-
/** Video decoders allowed open at once. */
|
|
7
|
-
readonly decoderSessions: number;
|
|
8
|
-
}
|
|
1
|
+
/** A capability a probe found missing. */
|
|
2
|
+
export type BrowserCapabilityDiagnostic = "webgpu-unavailable" | "webgl2-unavailable" | "webcodecs-unavailable" | "offscreen-canvas-unavailable" | "wasm-simd-unavailable" | "wasm-reference-types-unavailable";
|
|
9
3
|
/**
|
|
10
4
|
* Facts hosts use to select WebGPU, WebGL2 and media fallbacks. They hold only for the probing
|
|
11
5
|
* thread: a worker can get different answers than the page, so worker hosts should use
|
|
@@ -25,6 +19,10 @@ export interface BrowserCapabilities {
|
|
|
25
19
|
*/
|
|
26
20
|
readonly renderer: "gpu" | "cpu";
|
|
27
21
|
readonly webcodecs: boolean;
|
|
22
|
+
/** WebCodecs `AudioDecoder` exists. */
|
|
23
|
+
readonly audioDecoder: boolean;
|
|
24
|
+
/** WebCodecs `AudioEncoder` exists. */
|
|
25
|
+
readonly audioEncoder: boolean;
|
|
28
26
|
readonly offscreenCanvas: boolean;
|
|
29
27
|
/**
|
|
30
28
|
* WebAssembly SIMD and reference types are supported. Without them neither the engine, the audio
|
|
@@ -41,28 +39,3 @@ export interface BrowserCapabilities {
|
|
|
41
39
|
* modules, so it is cheap to check before fetching the engine.
|
|
42
40
|
*/
|
|
43
41
|
export declare function detectBrowserCapabilities(): Promise<BrowserCapabilities>;
|
|
44
|
-
/**
|
|
45
|
-
* Tracks browser lifecycle events against a {@link BrowserResourceBudget} and reports each
|
|
46
|
-
* degradation through `notify`. The host acts on what it reports.
|
|
47
|
-
*
|
|
48
|
-
* @throws RangeError From the constructor when either budget is not a positive safe integer.
|
|
49
|
-
*/
|
|
50
|
-
export declare class BrowserRobustnessCoordinator {
|
|
51
|
-
#private;
|
|
52
|
-
constructor(budget: BrowserResourceBudget, notify: (diagnostic: BrowserCapabilityDiagnostic) => void);
|
|
53
|
-
/**
|
|
54
|
-
* Sizes `canvas`'s backing store to its CSS size times `scale` (device pixel ratio), min 1x1.
|
|
55
|
-
*
|
|
56
|
-
* @throws RangeError When the scaled size is not a safe integer.
|
|
57
|
-
*/
|
|
58
|
-
resize(canvas: HTMLCanvasElement | OffscreenCanvas, cssWidth: number, cssHeight: number, scale?: number): void;
|
|
59
|
-
/** Records page visibility; hiding a visible page reports `visibility-suspended`. */
|
|
60
|
-
setVisible(visible: boolean): void;
|
|
61
|
-
/** Reports `memory-pressure` and returns the reduced texture budget (half, at least 1 byte). */
|
|
62
|
-
memoryPressure(): number;
|
|
63
|
-
contextLost(): void;
|
|
64
|
-
/** Takes one decoder session, or reports `decoder-session-limit` and returns `false`. */
|
|
65
|
-
acquireDecoder(): boolean;
|
|
66
|
-
/** Returns a session taken by {@link acquireDecoder}; extra calls are ignored. */
|
|
67
|
-
releaseDecoder(): void;
|
|
68
|
-
}
|
package/dist/robustness.js
CHANGED
|
@@ -36,6 +36,8 @@ export async function detectBrowserCapabilities() {
|
|
|
36
36
|
webgl2Renderer,
|
|
37
37
|
renderer: webgpu || hardwareWebgl2 ? "gpu" : "cpu",
|
|
38
38
|
webcodecs,
|
|
39
|
+
audioDecoder: globalThis.AudioDecoder !== undefined,
|
|
40
|
+
audioEncoder: globalThis.AudioEncoder !== undefined,
|
|
39
41
|
offscreenCanvas,
|
|
40
42
|
wasm: simd && referenceTypes,
|
|
41
43
|
diagnostics,
|
|
@@ -122,66 +124,3 @@ function detectWebgl2() {
|
|
|
122
124
|
}
|
|
123
125
|
return renderer;
|
|
124
126
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Tracks browser lifecycle events against a {@link BrowserResourceBudget} and reports each
|
|
127
|
-
* degradation through `notify`. The host acts on what it reports.
|
|
128
|
-
*
|
|
129
|
-
* @throws RangeError From the constructor when either budget is not a positive safe integer.
|
|
130
|
-
*/
|
|
131
|
-
export class BrowserRobustnessCoordinator {
|
|
132
|
-
#budget;
|
|
133
|
-
#notify;
|
|
134
|
-
#decoders = 0;
|
|
135
|
-
#visible = true;
|
|
136
|
-
constructor(budget, notify) {
|
|
137
|
-
if (!Number.isSafeInteger(budget.textureBytes) ||
|
|
138
|
-
budget.textureBytes <= 0 ||
|
|
139
|
-
!Number.isSafeInteger(budget.decoderSessions) ||
|
|
140
|
-
budget.decoderSessions <= 0) {
|
|
141
|
-
throw new RangeError("browser resource budget must be positive integers");
|
|
142
|
-
}
|
|
143
|
-
this.#budget = budget;
|
|
144
|
-
this.#notify = notify;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Sizes `canvas`'s backing store to its CSS size times `scale` (device pixel ratio), min 1x1.
|
|
148
|
-
*
|
|
149
|
-
* @throws RangeError When the scaled size is not a safe integer.
|
|
150
|
-
*/
|
|
151
|
-
resize(canvas, cssWidth, cssHeight, scale = 1) {
|
|
152
|
-
const width = Math.max(1, Math.round(cssWidth * scale));
|
|
153
|
-
const height = Math.max(1, Math.round(cssHeight * scale));
|
|
154
|
-
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height)) {
|
|
155
|
-
throw new RangeError("canvas size is unsupported");
|
|
156
|
-
}
|
|
157
|
-
canvas.width = width;
|
|
158
|
-
canvas.height = height;
|
|
159
|
-
}
|
|
160
|
-
/** Records page visibility; hiding a visible page reports `visibility-suspended`. */
|
|
161
|
-
setVisible(visible) {
|
|
162
|
-
if (this.#visible && !visible)
|
|
163
|
-
this.#notify("visibility-suspended");
|
|
164
|
-
this.#visible = visible;
|
|
165
|
-
}
|
|
166
|
-
/** Reports `memory-pressure` and returns the reduced texture budget (half, at least 1 byte). */
|
|
167
|
-
memoryPressure() {
|
|
168
|
-
this.#notify("memory-pressure");
|
|
169
|
-
return Math.max(1, Math.floor(this.#budget.textureBytes / 2));
|
|
170
|
-
}
|
|
171
|
-
contextLost() {
|
|
172
|
-
this.#notify("context-lost");
|
|
173
|
-
}
|
|
174
|
-
/** Takes one decoder session, or reports `decoder-session-limit` and returns `false`. */
|
|
175
|
-
acquireDecoder() {
|
|
176
|
-
if (this.#decoders >= this.#budget.decoderSessions) {
|
|
177
|
-
this.#notify("decoder-session-limit");
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
this.#decoders += 1;
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
/** Returns a session taken by {@link acquireDecoder}; extra calls are ignored. */
|
|
184
|
-
releaseDecoder() {
|
|
185
|
-
this.#decoders = Math.max(0, this.#decoders - 1);
|
|
186
|
-
}
|
|
187
|
-
}
|
package/dist/sha256.d.ts
CHANGED
|
@@ -9,8 +9,9 @@ export declare class Sha256 {
|
|
|
9
9
|
/**
|
|
10
10
|
* Streams a blob through SHA-256 and returns 64 lowercase hex digits.
|
|
11
11
|
*
|
|
12
|
-
* `onProgress` receives the bytes hashed so far after each piece of at most 1 MiB
|
|
13
|
-
* to the event loop about every 8 ms so the page stays responsive and
|
|
12
|
+
* `onProgress` receives the bytes hashed so far after each piece of at most 1 MiB, sized to take
|
|
13
|
+
* about 2 ms. Hashing yields to the event loop about every 8 ms so the page stays responsive and
|
|
14
|
+
* `signal` can abort it.
|
|
14
15
|
*
|
|
15
16
|
* Rejects with `signal.reason` on abort, or with the stream's error when the blob cannot be read.
|
|
16
17
|
*/
|
package/dist/sha256.js
CHANGED
|
@@ -121,8 +121,9 @@ export class Sha256 {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
const HASH_SLICE_MS = 8;
|
|
124
|
-
|
|
125
|
-
const
|
|
124
|
+
const HASH_PIECE_MS = HASH_SLICE_MS / 4;
|
|
125
|
+
const LEAST_PIECE_BYTES = 16 << 10;
|
|
126
|
+
const MOST_PIECE_BYTES = 1 << 20;
|
|
126
127
|
// A channel message avoids the timer minimum delay. `scheduler.yield()` is not used because Chrome
|
|
127
128
|
// runs its continuation ahead of timers and the next frame, which starves rendering.
|
|
128
129
|
function yieldToEventLoop() {
|
|
@@ -141,8 +142,9 @@ function yieldToEventLoop() {
|
|
|
141
142
|
/**
|
|
142
143
|
* Streams a blob through SHA-256 and returns 64 lowercase hex digits.
|
|
143
144
|
*
|
|
144
|
-
* `onProgress` receives the bytes hashed so far after each piece of at most 1 MiB
|
|
145
|
-
* to the event loop about every 8 ms so the page stays responsive and
|
|
145
|
+
* `onProgress` receives the bytes hashed so far after each piece of at most 1 MiB, sized to take
|
|
146
|
+
* about 2 ms. Hashing yields to the event loop about every 8 ms so the page stays responsive and
|
|
147
|
+
* `signal` can abort it.
|
|
146
148
|
*
|
|
147
149
|
* Rejects with `signal.reason` on abort, or with the stream's error when the blob cannot be read.
|
|
148
150
|
*/
|
|
@@ -150,6 +152,7 @@ export async function sha256Blob(blob, options = {}) {
|
|
|
150
152
|
const hash = new Sha256();
|
|
151
153
|
const reader = blob.stream().getReader();
|
|
152
154
|
let read = 0;
|
|
155
|
+
let pieceBytes = LEAST_PIECE_BYTES;
|
|
153
156
|
let sliceStart = performance.now();
|
|
154
157
|
try {
|
|
155
158
|
for (;;) {
|
|
@@ -157,16 +160,21 @@ export async function sha256Blob(blob, options = {}) {
|
|
|
157
160
|
const { done, value } = await reader.read();
|
|
158
161
|
if (done)
|
|
159
162
|
break;
|
|
160
|
-
for (let at = 0; at < value.length;
|
|
163
|
+
for (let at = 0; at < value.length;) {
|
|
161
164
|
if (performance.now() - sliceStart >= HASH_SLICE_MS) {
|
|
162
165
|
await yieldToEventLoop();
|
|
163
166
|
options.signal?.throwIfAborted();
|
|
164
167
|
sliceStart = performance.now();
|
|
165
168
|
}
|
|
166
|
-
const piece = value.subarray(at, at +
|
|
169
|
+
const piece = value.subarray(at, at + pieceBytes);
|
|
170
|
+
const begun = performance.now();
|
|
167
171
|
hash.update(piece);
|
|
172
|
+
const took = performance.now() - begun;
|
|
173
|
+
at += piece.length;
|
|
168
174
|
read += piece.length;
|
|
169
175
|
options.onProgress?.(read);
|
|
176
|
+
if (piece.length === pieceBytes)
|
|
177
|
+
pieceBytes = Math.round(Math.min(MOST_PIECE_BYTES, 2 * pieceBytes, Math.max(LEAST_PIECE_BYTES, took > 0 ? (pieceBytes * HASH_PIECE_MS) / took : Infinity)));
|
|
170
178
|
}
|
|
171
179
|
}
|
|
172
180
|
}
|
package/dist/worker-error.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BrowserErrorCode } from "./export-failure.js";
|
|
1
2
|
/** An error as plain data that survives `postMessage`. */
|
|
2
3
|
export interface SerializedAlpha2Error {
|
|
3
4
|
/** The error's own `code`, else a wasm trap code or the worker's default. */
|
|
@@ -22,6 +23,6 @@ export declare class Alpha2WasmError extends Error {
|
|
|
22
23
|
* Pass `trapped` once the worker has seen a wasm trap: borrows are still held, so every later error
|
|
23
24
|
* is fatal. `uncoded` is the code for an error without one.
|
|
24
25
|
*/
|
|
25
|
-
export declare function serializeError(error: unknown, trapped?: boolean, uncoded?:
|
|
26
|
+
export declare function serializeError(error: unknown, trapped?: boolean, uncoded?: BrowserErrorCode): SerializedAlpha2Error;
|
|
26
27
|
/** Classifies the unrecoverable `WebAssembly` failures, or `undefined`. */
|
|
27
|
-
export declare function wasmTrapCode(error: unknown):
|
|
28
|
+
export declare function wasmTrapCode(error: unknown): BrowserErrorCode | undefined;
|
package/dist/worker-error.js
CHANGED
|
@@ -42,7 +42,9 @@ export function serializeError(error, trapped = false, uncoded = "RENDER_WORKER_
|
|
|
42
42
|
};
|
|
43
43
|
if (trapped) {
|
|
44
44
|
return {
|
|
45
|
-
code: typeof value?.code === "string"
|
|
45
|
+
code: typeof value?.code === "string"
|
|
46
|
+
? value.code
|
|
47
|
+
: "WASM_TRAPPED",
|
|
46
48
|
message: `${message} (after an earlier wasm trap; the worker must be replaced)`,
|
|
47
49
|
fatal: true,
|
|
48
50
|
...carried,
|
package/dist/worker.d.ts
CHANGED
|
@@ -170,16 +170,26 @@ export declare function installRenderWorker(scope: RenderWorkerScope, createHost
|
|
|
170
170
|
* renderer, compiling an effect or loading the project fails.
|
|
171
171
|
*/
|
|
172
172
|
export declare function createWasmRenderWorkerHost(binding: WasmEffectRegistryBinding, projectJson: string, options?: WasmRenderWorkerHostOptions): (canvas: OffscreenCanvas) => Promise<RenderWorkerHost>;
|
|
173
|
+
/** Options of {@link WorkerRenderBackend}. */
|
|
174
|
+
export interface WorkerRenderBackendOptions {
|
|
175
|
+
/**
|
|
176
|
+
* Milliseconds of active time (a hidden or frozen page does not count) any request waits for
|
|
177
|
+
* its reply. Default 60000 for `initialize` and `recover`, 30000 for every other request. An
|
|
178
|
+
* export frame's readback is bounded by the engine instead.
|
|
179
|
+
*/
|
|
180
|
+
readonly requestTimeoutMs?: number;
|
|
181
|
+
}
|
|
173
182
|
/**
|
|
174
183
|
* A `RenderBackend` that forwards every call to a worker running {@link installRenderWorker}.
|
|
175
184
|
*
|
|
176
185
|
* Calls reject with `Alpha2WasmError` for worker errors, and with a plain `Error` after
|
|
177
|
-
* {@link WorkerRenderBackend.dispose}. After an uncaught worker error,
|
|
178
|
-
*
|
|
186
|
+
* {@link WorkerRenderBackend.dispose}. After an uncaught worker error, a message that cannot be
|
|
187
|
+
* read, or a request unanswered past its deadline, every pending and later call rejects with a
|
|
188
|
+
* fatal `RENDER_WORKER_FAILED` and the worker must be replaced.
|
|
179
189
|
*/
|
|
180
190
|
export declare class WorkerRenderBackend implements RenderBackend {
|
|
181
191
|
#private;
|
|
182
|
-
constructor(worker: Worker);
|
|
192
|
+
constructor(worker: Worker, options?: WorkerRenderBackendOptions);
|
|
183
193
|
/** Set by {@link WorkerRenderBackend.initialize} and each recovery; `undefined` before. */
|
|
184
194
|
get rendererChoice(): RendererChoice | undefined;
|
|
185
195
|
/** Transfers `canvas` to the worker and creates its host there. */
|
package/dist/worker.js
CHANGED
|
@@ -9,6 +9,7 @@ import { decodeRefusalMessage, NonPlanarVideoFrameError, PlanarCopyPool, PlanarD
|
|
|
9
9
|
import { Alpha2WasmError, serializeError, wasmTrapCode, } from "./worker-error.js";
|
|
10
10
|
import { PhysicalFrameAliases, } from "./physical-frames.js";
|
|
11
11
|
import { sendsBitmaps, uploadPresentedFrame } from "./presented-frames.js";
|
|
12
|
+
import { withinActiveTime } from "./active-clock.js";
|
|
12
13
|
export { Alpha2WasmError } from "./worker-error.js";
|
|
13
14
|
/**
|
|
14
15
|
* Installs a serial request loop in the worker that owns the GPU device, replacing
|
|
@@ -552,12 +553,19 @@ function requiredHost(host) {
|
|
|
552
553
|
throw new Error("render worker is not initialized");
|
|
553
554
|
return host;
|
|
554
555
|
}
|
|
556
|
+
/** Active milliseconds a request may wait for its reply, by type; others take the default. */
|
|
557
|
+
const REQUEST_TIMEOUT_MS = {
|
|
558
|
+
initialize: 60_000,
|
|
559
|
+
recover: 60_000,
|
|
560
|
+
};
|
|
561
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
|
|
555
562
|
/**
|
|
556
563
|
* A `RenderBackend` that forwards every call to a worker running {@link installRenderWorker}.
|
|
557
564
|
*
|
|
558
565
|
* Calls reject with `Alpha2WasmError` for worker errors, and with a plain `Error` after
|
|
559
|
-
* {@link WorkerRenderBackend.dispose}. After an uncaught worker error,
|
|
560
|
-
*
|
|
566
|
+
* {@link WorkerRenderBackend.dispose}. After an uncaught worker error, a message that cannot be
|
|
567
|
+
* read, or a request unanswered past its deadline, every pending and later call rejects with a
|
|
568
|
+
* fatal `RENDER_WORKER_FAILED` and the worker must be replaced.
|
|
561
569
|
*/
|
|
562
570
|
export class WorkerRenderBackend {
|
|
563
571
|
#worker;
|
|
@@ -569,10 +577,13 @@ export class WorkerRenderBackend {
|
|
|
569
577
|
#lossReport;
|
|
570
578
|
#disposed = false;
|
|
571
579
|
#failure;
|
|
572
|
-
|
|
580
|
+
#requestTimeoutMs;
|
|
581
|
+
constructor(worker, options = {}) {
|
|
573
582
|
this.#worker = worker;
|
|
583
|
+
this.#requestTimeoutMs = options.requestTimeoutMs;
|
|
574
584
|
worker.addEventListener("message", this.#onMessage);
|
|
575
585
|
worker.addEventListener("error", this.#onWorkerError);
|
|
586
|
+
worker.addEventListener("messageerror", this.#onMessageError);
|
|
576
587
|
}
|
|
577
588
|
/** Set by {@link WorkerRenderBackend.initialize} and each recovery; `undefined` before. */
|
|
578
589
|
get rendererChoice() {
|
|
@@ -651,7 +662,7 @@ export class WorkerRenderBackend {
|
|
|
651
662
|
reject(failure);
|
|
652
663
|
}
|
|
653
664
|
});
|
|
654
|
-
return started.then((value) => {
|
|
665
|
+
return this.#withinDeadline(started, "begin-export-frame").then((value) => {
|
|
655
666
|
const result = value;
|
|
656
667
|
if (result.kind === "waiting") {
|
|
657
668
|
this.#pendingExportReadbacks.delete(id);
|
|
@@ -702,6 +713,7 @@ export class WorkerRenderBackend {
|
|
|
702
713
|
this.#postWithoutReply({ type: "dispose" });
|
|
703
714
|
this.#worker.removeEventListener("message", this.#onMessage);
|
|
704
715
|
this.#worker.removeEventListener("error", this.#onWorkerError);
|
|
716
|
+
this.#worker.removeEventListener("messageerror", this.#onMessageError);
|
|
705
717
|
this.#worker.terminate();
|
|
706
718
|
const error = new Error("alpha2 render worker disposed");
|
|
707
719
|
for (const request of this.#pending.values())
|
|
@@ -748,12 +760,19 @@ export class WorkerRenderBackend {
|
|
|
748
760
|
// An uncaught worker error (such as a trap in a wasm-driven future) can leave the serial queue
|
|
749
761
|
// waiting forever, so the backend fails every pending and later call.
|
|
750
762
|
#onWorkerError = (event) => {
|
|
751
|
-
|
|
763
|
+
this.#fail(event.message || "alpha2 render worker failed");
|
|
764
|
+
};
|
|
765
|
+
#onMessageError = () => {
|
|
766
|
+
this.#fail("a render worker message could not be read");
|
|
767
|
+
};
|
|
768
|
+
/** Fails every pending and later call with one fatal `RENDER_WORKER_FAILED`. */
|
|
769
|
+
#fail(reason) {
|
|
770
|
+
this.#failure ??= new Alpha2WasmError({
|
|
752
771
|
code: "RENDER_WORKER_FAILED",
|
|
753
|
-
message: `${
|
|
772
|
+
message: `${reason}; the render worker must be replaced`,
|
|
754
773
|
fatal: true,
|
|
755
774
|
});
|
|
756
|
-
this.#failure
|
|
775
|
+
const error = this.#failure;
|
|
757
776
|
for (const request of this.#pending.values())
|
|
758
777
|
request.reject(error);
|
|
759
778
|
this.#pending.clear();
|
|
@@ -761,7 +780,14 @@ export class WorkerRenderBackend {
|
|
|
761
780
|
readback.reject(error);
|
|
762
781
|
}
|
|
763
782
|
this.#pendingExportReadbacks.clear();
|
|
764
|
-
|
|
783
|
+
return error;
|
|
784
|
+
}
|
|
785
|
+
#withinDeadline(reply, type) {
|
|
786
|
+
const limit = this.#requestTimeoutMs ??
|
|
787
|
+
REQUEST_TIMEOUT_MS[type] ??
|
|
788
|
+
DEFAULT_REQUEST_TIMEOUT_MS;
|
|
789
|
+
return withinActiveTime(reply, limit, () => this.#fail(`the render worker did not answer ${type} within ${limit / 1000} s of active time`));
|
|
790
|
+
}
|
|
765
791
|
#request(request, transfer = [], onPostFailure) {
|
|
766
792
|
if (this.#disposed) {
|
|
767
793
|
onPostFailure?.();
|
|
@@ -772,7 +798,7 @@ export class WorkerRenderBackend {
|
|
|
772
798
|
return Promise.reject(this.#failure);
|
|
773
799
|
}
|
|
774
800
|
const id = this.#nextId++;
|
|
775
|
-
|
|
801
|
+
const reply = new Promise((resolve, reject) => {
|
|
776
802
|
this.#pending.set(id, { resolve, reject });
|
|
777
803
|
try {
|
|
778
804
|
this.#worker.postMessage({ ...request, id }, transfer);
|
|
@@ -783,6 +809,7 @@ export class WorkerRenderBackend {
|
|
|
783
809
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
784
810
|
}
|
|
785
811
|
});
|
|
812
|
+
return this.#withinDeadline(reply, request.type);
|
|
786
813
|
}
|
|
787
814
|
#postWithoutReply(request) {
|
|
788
815
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alpha2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "JavaScript bindings for the standalone alpha2 media engine.",
|
|
6
6
|
"repository": {
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
"types": "./dist/project.d.ts",
|
|
38
38
|
"import": "./dist/project.js"
|
|
39
39
|
},
|
|
40
|
+
"./compose": {
|
|
41
|
+
"types": "./dist/compose.d.ts",
|
|
42
|
+
"import": "./dist/compose.js"
|
|
43
|
+
},
|
|
40
44
|
"./exporter": {
|
|
41
45
|
"types": "./dist/exporter.d.ts",
|
|
42
46
|
"import": "./dist/exporter.js"
|
|
@@ -81,6 +85,10 @@
|
|
|
81
85
|
"types": "./dist/active-clock.d.ts",
|
|
82
86
|
"import": "./dist/active-clock.js"
|
|
83
87
|
},
|
|
88
|
+
"./apply-edit": {
|
|
89
|
+
"types": "./dist/apply-edit.d.ts",
|
|
90
|
+
"import": "./dist/apply-edit.js"
|
|
91
|
+
},
|
|
84
92
|
"./assets": {
|
|
85
93
|
"types": "./dist/assets.d.ts",
|
|
86
94
|
"import": "./dist/assets.js"
|
|
@@ -165,6 +173,18 @@
|
|
|
165
173
|
"types": "./dist/edit.d.ts",
|
|
166
174
|
"import": "./dist/edit.js"
|
|
167
175
|
},
|
|
176
|
+
"./extract": {
|
|
177
|
+
"types": "./dist/extract.d.ts",
|
|
178
|
+
"import": "./dist/extract.js"
|
|
179
|
+
},
|
|
180
|
+
"./extractor": {
|
|
181
|
+
"types": "./dist/extractor.d.ts",
|
|
182
|
+
"import": "./dist/extractor.js"
|
|
183
|
+
},
|
|
184
|
+
"./plugins": {
|
|
185
|
+
"types": "./dist/plugins.d.ts",
|
|
186
|
+
"import": "./dist/plugins.js"
|
|
187
|
+
},
|
|
168
188
|
"./effects": {
|
|
169
189
|
"types": "./dist/effects.d.ts",
|
|
170
190
|
"import": "./dist/effects.js"
|
|
@@ -187,6 +207,11 @@
|
|
|
187
207
|
},
|
|
188
208
|
"./wasm/alpha2_wasm_bg.wasm": "./wasm/alpha2_wasm_bg.wasm",
|
|
189
209
|
"./wasm/alpha2_audio_worklet.wasm": "./wasm/alpha2_audio_worklet.wasm",
|
|
210
|
+
"./compose-wasm": {
|
|
211
|
+
"types": "./wasm/alpha2_compose.d.ts",
|
|
212
|
+
"import": "./wasm/alpha2_compose.js"
|
|
213
|
+
},
|
|
214
|
+
"./wasm/alpha2_compose_bg.wasm": "./wasm/alpha2_compose_bg.wasm",
|
|
190
215
|
"./extensions-wasm": {
|
|
191
216
|
"types": "./wasm/alpha2_extensions.d.ts",
|
|
192
217
|
"import": "./wasm/alpha2_extensions.js"
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A template bound to its data, or a spec with its template nodes expanded, as JSON.
|
|
6
|
+
* `options` is `{"theme"?, "templates"?}`.
|
|
7
|
+
*
|
|
8
|
+
* # Errors
|
|
9
|
+
* Rejects a template, data or options that do not bind, naming where.
|
|
10
|
+
*/
|
|
11
|
+
export function composeBind(document: string, data: string, options: string): string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A compose spec compiled with facts about its files and font files, as JSON
|
|
15
|
+
* `{"project", "assets", "loudness", "warnings"}`.
|
|
16
|
+
*
|
|
17
|
+
* # Errors
|
|
18
|
+
* Rejects a spec or facts that do not compile, naming where.
|
|
19
|
+
*/
|
|
20
|
+
export function composeCompile(spec: string, facts: string, fonts: Uint8Array[]): string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A template's data as a JSON Schema.
|
|
24
|
+
*
|
|
25
|
+
* # Errors
|
|
26
|
+
* Rejects a template that does not parse.
|
|
27
|
+
*/
|
|
28
|
+
export function composeDataSchema(template: string): string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A template's problems as a JSON list of `{path, code, message, severity}`; `data` may be
|
|
32
|
+
* empty for none.
|
|
33
|
+
*
|
|
34
|
+
* # Errors
|
|
35
|
+
* Rejects text that is not JSON.
|
|
36
|
+
*/
|
|
37
|
+
export function composeLint(template: string, data: string, options: string): string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The files a compose spec names, as JSON `{"media": [{path, kind}], "texts": [path]}`.
|
|
41
|
+
*
|
|
42
|
+
* # Errors
|
|
43
|
+
* Rejects a spec that does not parse, naming where.
|
|
44
|
+
*/
|
|
45
|
+
export function composeRequirements(spec: string): string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The 1st-party `alpha2/` templates, as a JSON list.
|
|
49
|
+
*/
|
|
50
|
+
export function composeTemplates(): string;
|
|
51
|
+
|
|
52
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
53
|
+
|
|
54
|
+
export interface InitOutput {
|
|
55
|
+
readonly memory: WebAssembly.Memory;
|
|
56
|
+
readonly composeBind: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
57
|
+
readonly composeCompile: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
58
|
+
readonly composeDataSchema: (a: number, b: number) => [number, number, number, number];
|
|
59
|
+
readonly composeLint: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
60
|
+
readonly composeRequirements: (a: number, b: number) => [number, number, number, number];
|
|
61
|
+
readonly composeTemplates: () => [number, number];
|
|
62
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
63
|
+
readonly __externref_table_alloc: () => number;
|
|
64
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
65
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
66
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
67
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
68
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
69
|
+
readonly __wbindgen_start: () => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
76
|
+
* a precompiled `WebAssembly.Module`.
|
|
77
|
+
*
|
|
78
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
79
|
+
*
|
|
80
|
+
* @returns {InitOutput}
|
|
81
|
+
*/
|
|
82
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
86
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
87
|
+
*
|
|
88
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
89
|
+
*
|
|
90
|
+
* @returns {Promise<InitOutput>}
|
|
91
|
+
*/
|
|
92
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|