alpha2 0.5.2 → 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 +71 -5
- package/THIRD_PARTY_NOTICES.md +191 -1
- 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/extensions.d.ts +86 -28
- package/dist/extensions.js +204 -61
- 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 +696 -41
- package/dist/generated/project-schema.js +67 -0
- package/dist/generated/project-shape.js +986 -383
- 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 +44 -11
- package/dist/media.js +256 -67
- 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 +36 -1
- package/dist/project.js +515 -42
- 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/wasm-module.d.ts +37 -0
- package/dist/wasm-module.js +47 -0
- 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 +36 -2
- 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.d.ts +4 -4
- package/wasm/alpha2_extensions.js +16 -4
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf.d.ts +227 -0
- package/wasm/alpha2_extensions_pdf.js +841 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm.d.ts +38 -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 +493 -54
- package/wasm/snippets/alpha2-wasm-1b02e9f302d283ba/inline3.js +7 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline1.js → alpha2-wasm-1b02e9f302d283ba/inline0.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline2.js → alpha2-wasm-1b02e9f302d283ba/inline1.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline3.js → alpha2-wasm-1b02e9f302d283ba/inline2.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline0.js → alpha2-wasm-1b02e9f302d283ba/inline4.js} +0 -0
package/dist/export-failure.js
CHANGED
|
@@ -43,6 +43,7 @@ const CODES = new Set([
|
|
|
43
43
|
"RESOURCE_LIMIT",
|
|
44
44
|
"RESOURCE_BUSY",
|
|
45
45
|
"CANCELLED",
|
|
46
|
+
"DEFECT",
|
|
46
47
|
"UNKNOWN",
|
|
47
48
|
]);
|
|
48
49
|
/** The well-formed failure `error` carries, if any. */
|
|
@@ -104,10 +105,29 @@ export function classifyBrowserFailure(error, context) {
|
|
|
104
105
|
}
|
|
105
106
|
const permanent = { code: "INVALID_INPUT", resource: "unknown" };
|
|
106
107
|
const unknown = { code: "UNKNOWN", resource: "unknown" };
|
|
108
|
+
const defect = { code: "DEFECT", resource: "unknown" };
|
|
107
109
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
|
|
110
|
+
* Codes only the browser runtime makes: decode refusals, the frame supply, wasm traps, its
|
|
111
|
+
* workers, and the wasm binding's own `INVALID_STATE`.
|
|
112
|
+
*/
|
|
113
|
+
export const BROWSER_ERROR_CODES = [
|
|
114
|
+
"DECODE_UNAVAILABLE",
|
|
115
|
+
"PLANAR_DECODE_UNAVAILABLE",
|
|
116
|
+
"NON_PLANAR_FRAME",
|
|
117
|
+
"FRAME_SUPPLY_FAILED",
|
|
118
|
+
"SOFTWARE_DECODE_REQUIRED",
|
|
119
|
+
"WASM_TRAP",
|
|
120
|
+
"WASM_TRAPPED",
|
|
121
|
+
"WASM_COMPILE_ERROR",
|
|
122
|
+
"WASM_LINK_ERROR",
|
|
123
|
+
"RENDER_WORKER_ERROR",
|
|
124
|
+
"RENDER_WORKER_FAILED",
|
|
125
|
+
"AUDIO_WORKER_ERROR",
|
|
126
|
+
"INVALID_STATE",
|
|
127
|
+
];
|
|
128
|
+
/**
|
|
129
|
+
* Failure class of each error code. Must match the host's `classify_failure`;
|
|
130
|
+
* `tests/cases/failure-classes.json` checks both.
|
|
111
131
|
*/
|
|
112
132
|
const CODE_CLASSES = Object.freeze({
|
|
113
133
|
UNSUPPORTED_PROTOCOL: permanent,
|
|
@@ -130,13 +150,33 @@ const CODE_CLASSES = Object.freeze({
|
|
|
130
150
|
OUTPUT_PUBLISH_FAILED: { code: "OUTPUT_IO_FAILED", resource: "unknown" },
|
|
131
151
|
CANCELLED: { code: "CANCELLED", resource: "unknown" },
|
|
132
152
|
RESOURCE_LIMIT: { code: "RESOURCE_LIMIT", resource: "unknown" },
|
|
153
|
+
// Never started: the host was retiring, and another host runs it.
|
|
154
|
+
HOST_RETIRING: { code: "HOST_EXITED", resource: "unknown" },
|
|
155
|
+
// An extractor's own output or failure repeats on a retry; a slow client may not.
|
|
156
|
+
INVALID_EMIT: permanent,
|
|
157
|
+
EXTRACTOR_FAILED: permanent,
|
|
158
|
+
EXTRACTOR_TIMEOUT: unknown,
|
|
159
|
+
// A plugin that is refused, does not load or traps does so again; a server may answer later.
|
|
160
|
+
PLUGIN_FETCH_FAILED: unknown,
|
|
161
|
+
PLUGIN_HASH_MISMATCH: permanent,
|
|
162
|
+
PLUGIN_ABI_UNSUPPORTED: permanent,
|
|
163
|
+
PLUGIN_NO_ARTIFACT: permanent,
|
|
164
|
+
PLUGIN_NATIVE_REFUSED: permanent,
|
|
165
|
+
PLUGIN_REFUSED: permanent,
|
|
166
|
+
PLUGIN_DESCRIPTOR_MISMATCH: permanent,
|
|
167
|
+
PLUGIN_UNSUPPORTED_FEATURE: permanent,
|
|
168
|
+
PLUGIN_LOAD_FAILED: permanent,
|
|
169
|
+
PLUGIN_TRAPPED: permanent,
|
|
170
|
+
PLUGIN_LIMIT: { code: "RESOURCE_LIMIT", resource: "unknown" },
|
|
133
171
|
GPU_INIT_FAILED: unknown,
|
|
134
172
|
ENCODE_ERROR: unknown,
|
|
135
173
|
ENCODER_BUSY: { code: "RESOURCE_BUSY", resource: "gpu" },
|
|
136
|
-
|
|
174
|
+
// A caught panic of the host.
|
|
175
|
+
INTERNAL: defect,
|
|
137
176
|
ALPHA2_ERROR: unknown,
|
|
138
177
|
// `@alpha2-sh/node` setup errors that a retry does not fix.
|
|
139
178
|
HOST_NOT_FOUND: permanent,
|
|
179
|
+
HOST_VERSION_MISMATCH: permanent,
|
|
140
180
|
HOST_NOT_EXECUTABLE: permanent,
|
|
141
181
|
HOST_LOAD_FAILED: permanent,
|
|
142
182
|
HOST_START_FAILED: unknown,
|
|
@@ -157,6 +197,17 @@ const CODE_CLASSES = Object.freeze({
|
|
|
157
197
|
NON_PLANAR_FRAME: permanent,
|
|
158
198
|
FRAME_SUPPLY_FAILED: unknown,
|
|
159
199
|
SOFTWARE_DECODE_REQUIRED: unknown,
|
|
200
|
+
// A module that does not compile or link, and a call the binding's state refuses, repeat.
|
|
201
|
+
WASM_COMPILE_ERROR: permanent,
|
|
202
|
+
WASM_LINK_ERROR: permanent,
|
|
203
|
+
INVALID_STATE: permanent,
|
|
204
|
+
// A trap is an engine fault; a fresh worker may not meet it again.
|
|
205
|
+
WASM_TRAP: defect,
|
|
206
|
+
WASM_TRAPPED: defect,
|
|
207
|
+
// A worker's error without a code of its own says nothing about a retry.
|
|
208
|
+
RENDER_WORKER_ERROR: unknown,
|
|
209
|
+
RENDER_WORKER_FAILED: unknown,
|
|
210
|
+
AUDIO_WORKER_ERROR: unknown,
|
|
160
211
|
});
|
|
161
212
|
/** Failure class of a protocol or `@alpha2-sh/node` error code; `UNKNOWN` for any other. */
|
|
162
213
|
export function failureClassOfCode(code) {
|
package/dist/export-retry.d.ts
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* - Memory exhaustion steps down to a smaller profile.
|
|
11
11
|
* - An encode failure retries once with the software video encoder when available.
|
|
12
12
|
* - `RESOURCE_BUSY` retries unchanged after the longer of its `retryAfterMs` and the backoff.
|
|
13
|
+
* - `DEFECT` (an engine panic or wasm trap) retries once, unchanged and at once, on a fresh worker
|
|
14
|
+
* or host; a second one stops.
|
|
13
15
|
* - Other transient failures retry unchanged and step down only if they recur at the same point.
|
|
14
16
|
* A browser that has already lost the GPU twice moves to the CPU or stops, since the browser
|
|
15
17
|
* withdraws GPU access at the next reset.
|
|
@@ -41,7 +43,10 @@ export interface AttemptOutcome {
|
|
|
41
43
|
export interface RetryPolicyOptions {
|
|
42
44
|
/** Total attempts, including the first. Default 3. */
|
|
43
45
|
readonly maxAttempts?: number;
|
|
44
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Delay before attempt `n + 1`, given `n` failed attempts. Default `1000 * 2^(n-1)` ms, the
|
|
48
|
+
* exponent capped at 16.
|
|
49
|
+
*/
|
|
45
50
|
readonly backoffMs?: (failedAttempts: number) => number;
|
|
46
51
|
/** Profiles to step down through, largest first. Default {@link RETRY_PROFILES}. */
|
|
47
52
|
readonly profiles?: readonly RetryProfile[];
|
package/dist/export-retry.js
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* - Memory exhaustion steps down to a smaller profile.
|
|
11
11
|
* - An encode failure retries once with the software video encoder when available.
|
|
12
12
|
* - `RESOURCE_BUSY` retries unchanged after the longer of its `retryAfterMs` and the backoff.
|
|
13
|
+
* - `DEFECT` (an engine panic or wasm trap) retries once, unchanged and at once, on a fresh worker
|
|
14
|
+
* or host; a second one stops.
|
|
13
15
|
* - Other transient failures retry unchanged and step down only if they recur at the same point.
|
|
14
16
|
* A browser that has already lost the GPU twice moves to the CPU or stops, since the browser
|
|
15
17
|
* withdraws GPU access at the next reset.
|
|
@@ -56,7 +58,8 @@ export function isRetryableFailure(failure) {
|
|
|
56
58
|
export function decideRetry(history, options = {}) {
|
|
57
59
|
const maxAttempts = options.maxAttempts ?? 3;
|
|
58
60
|
const profiles = options.profiles ?? RETRY_PROFILES;
|
|
59
|
-
const backoff = options.backoffMs ??
|
|
61
|
+
const backoff = options.backoffMs ??
|
|
62
|
+
((failed) => 1_000 * 2 ** Math.min(failed - 1, 16));
|
|
60
63
|
const last = history.at(-1);
|
|
61
64
|
if (last === undefined)
|
|
62
65
|
return { retry: false, reason: "nothing failed", failure: undefined };
|
|
@@ -97,6 +100,14 @@ export function decideRetry(history, options = {}) {
|
|
|
97
100
|
? "it failed on the CPU renderer too"
|
|
98
101
|
: "there is no CPU renderer to retry on"}`, hung);
|
|
99
102
|
}
|
|
103
|
+
if (failure.code === "DEFECT") {
|
|
104
|
+
const defects = history.filter((attempt) => attempt.failure.code === "DEFECT").length;
|
|
105
|
+
if (defects > 1)
|
|
106
|
+
return stop("DEFECT again on a fresh attempt: the engine fails this export the same way");
|
|
107
|
+
if (!attemptsLeft)
|
|
108
|
+
return stop(`all ${maxAttempts} attempts failed`);
|
|
109
|
+
return retry(`DEFECT: an engine fault; retrying once on a fresh ${failure.origin === "browser" ? "worker" : "host"}`, { delayMs: 0 });
|
|
110
|
+
}
|
|
100
111
|
if (!isRetryableFailure(failure))
|
|
101
112
|
return stop(`${failure.code} at ${failure.phase} is not helped by a retry`);
|
|
102
113
|
if (!attemptsLeft)
|
package/dist/exporter.d.ts
CHANGED
|
@@ -93,7 +93,10 @@ export interface BrowserEncodeSink {
|
|
|
93
93
|
writeVideo(frame: ExportedFrame): Promise<void>;
|
|
94
94
|
/** Flushes the encoder and finalizes the container after the last frame. */
|
|
95
95
|
finish(): Promise<void>;
|
|
96
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Discards partial output; called once when the export fails, also while `finish` is pending. A
|
|
98
|
+
* `finish` that settles after `abort` must not commit the output.
|
|
99
|
+
*/
|
|
97
100
|
abort(reason: Error): Promise<void> | void;
|
|
98
101
|
/** Copied into the result when present. */
|
|
99
102
|
readonly videoLatencyProbe?: VideoLatencyProbe;
|
|
@@ -172,11 +175,12 @@ export declare class Alpha2Exporter {
|
|
|
172
175
|
* 0), not the preview's. The preview's coordinator moves past generation 0 after its first seek
|
|
173
176
|
* and would silently drop the export's requests.
|
|
174
177
|
*
|
|
175
|
-
* Resolves after `sink.finish()` with timing and memory metrics. Aborting `signal
|
|
176
|
-
* `finish()
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
178
|
+
* Resolves after `sink.finish()` with timing and memory metrics. Aborting `signal` before
|
|
179
|
+
* `finish()` resolves, even while it is pending, rejects immediately; late results are closed. An
|
|
180
|
+
* abort after `finish()` resolved is ignored. On other failures, held frames are closed and pending
|
|
181
|
+
* writes awaited. In both cases `sink.abort` is called once and the promise rejects with an
|
|
182
|
+
* {@link ExportAbortedError}, a `RESOURCE_LIMIT` `ExportFailureError`, a `RangeError` for an
|
|
183
|
+
* invalid option, or the error from the backend, `refill` or sink. An error thrown by
|
|
184
|
+
* `sink.abort` does not replace it.
|
|
181
185
|
*/
|
|
182
186
|
export declare function exportToSink(exporter: Alpha2Exporter, sink: BrowserEncodeSink, refill: (waiting: ExportWaiting) => Promise<void>, options?: BrowserExportOptions): Promise<BrowserExportResult>;
|
package/dist/exporter.js
CHANGED
|
@@ -157,12 +157,13 @@ export class Alpha2Exporter {
|
|
|
157
157
|
* 0), not the preview's. The preview's coordinator moves past generation 0 after its first seek
|
|
158
158
|
* and would silently drop the export's requests.
|
|
159
159
|
*
|
|
160
|
-
* Resolves after `sink.finish()` with timing and memory metrics. Aborting `signal
|
|
161
|
-
* `finish()
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
160
|
+
* Resolves after `sink.finish()` with timing and memory metrics. Aborting `signal` before
|
|
161
|
+
* `finish()` resolves, even while it is pending, rejects immediately; late results are closed. An
|
|
162
|
+
* abort after `finish()` resolved is ignored. On other failures, held frames are closed and pending
|
|
163
|
+
* writes awaited. In both cases `sink.abort` is called once and the promise rejects with an
|
|
164
|
+
* {@link ExportAbortedError}, a `RESOURCE_LIMIT` `ExportFailureError`, a `RangeError` for an
|
|
165
|
+
* invalid option, or the error from the backend, `refill` or sink. An error thrown by
|
|
166
|
+
* `sink.abort` does not replace it.
|
|
166
167
|
*/
|
|
167
168
|
export async function exportToSink(exporter, sink, refill, options = {}) {
|
|
168
169
|
const started = performance.now();
|
|
@@ -206,7 +207,7 @@ export async function exportToSink(exporter, sink, refill, options = {}) {
|
|
|
206
207
|
encodeQueueBytes -= write.retainedBytes;
|
|
207
208
|
}
|
|
208
209
|
};
|
|
209
|
-
// Also checked
|
|
210
|
+
// Also checked before finish(), so a cancel after the last submission still wins.
|
|
210
211
|
const cancelledError = (signal) => new ExportAbortedError("cancelled", "browser export cancelled", {
|
|
211
212
|
cause: signal.reason,
|
|
212
213
|
});
|
|
@@ -364,9 +365,9 @@ export async function exportToSink(exporter, sink, refill, options = {}) {
|
|
|
364
365
|
pendingWrites.length = 0;
|
|
365
366
|
throwIfCancelled();
|
|
366
367
|
const finishStarted = performance.now();
|
|
367
|
-
|
|
368
|
+
// Once `finish` has resolved the output is committed, so the signal is not read again.
|
|
369
|
+
await cancellable(sink.finish());
|
|
368
370
|
metrics.finishMs = performance.now() - finishStarted;
|
|
369
|
-
throwIfCancelled();
|
|
370
371
|
const renderMs = performance.now() - started;
|
|
371
372
|
const completed = exporter.progress.completed;
|
|
372
373
|
const frames = Number(completed);
|
package/dist/extensions.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { WasmModule, type WasmBindgenGlue } from "./wasm-module.js";
|
|
1
2
|
import type { LinearPrimaries, ProviderSource } from "./generated/project-schema.js";
|
|
2
|
-
export type ExtensionFormat = "svg" | "gif" | "apng" | "webp" | "png_sequence" | "lottie" | "dot_lottie" | "exr" | "exr_sequence";
|
|
3
|
+
export type ExtensionFormat = "svg" | "gif" | "apng" | "webp" | "png_sequence" | "lottie" | "dot_lottie" | "exr" | "exr_sequence" | "latex" | "pdf";
|
|
3
4
|
/** Frame timing in source ticks. */
|
|
4
5
|
export type ExtensionTiming = {
|
|
5
6
|
readonly kind: "static";
|
|
@@ -23,6 +24,11 @@ export type ExtensionDiagnostic = {
|
|
|
23
24
|
readonly kind: "missing_font";
|
|
24
25
|
readonly families: string;
|
|
25
26
|
}
|
|
27
|
+
/** Fonts a document does not embed, drawn with the nearest standard font. */
|
|
28
|
+
| {
|
|
29
|
+
readonly kind: "substituted_font";
|
|
30
|
+
readonly families: string;
|
|
31
|
+
}
|
|
26
32
|
/** A referenced image is not registered or is too large; it is not drawn. */
|
|
27
33
|
| {
|
|
28
34
|
readonly kind: "missing_image";
|
|
@@ -108,13 +114,11 @@ export type ExtensionFrame = {
|
|
|
108
114
|
*/
|
|
109
115
|
readonly pixels: Uint16Array;
|
|
110
116
|
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
module_or_path: string | URL;
|
|
114
|
-
}): Promise<unknown>;
|
|
117
|
+
/** The wasm-bindgen glue every provider module's build writes. */
|
|
118
|
+
export interface ExtensionModule extends WasmBindgenGlue {
|
|
115
119
|
ExtensionRegistry: new () => WasmExtensionRegistry;
|
|
116
|
-
/**
|
|
117
|
-
|
|
120
|
+
/** Added by the package build after `--experimental-reset-state-function`. */
|
|
121
|
+
__wbg_reset_state_async(): Promise<void>;
|
|
118
122
|
}
|
|
119
123
|
interface WasmRenderedFrame {
|
|
120
124
|
readonly width: number;
|
|
@@ -149,11 +153,19 @@ interface WasmExtensionRegistry {
|
|
|
149
153
|
free(): void;
|
|
150
154
|
}
|
|
151
155
|
/**
|
|
152
|
-
* The provider module aborted during this call (a panic or failed allocation)
|
|
153
|
-
*
|
|
156
|
+
* The provider module aborted during this call (a panic or failed allocation), or cannot be used.
|
|
157
|
+
* After an abort the module restarts; {@link Extensions.ready} resolves once later calls work. The
|
|
158
|
+
* source involved stays failed.
|
|
154
159
|
*/
|
|
155
160
|
export declare class ExtensionModuleError extends Error {
|
|
156
|
-
readonly name
|
|
161
|
+
readonly name: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The provider module is restarting after an abort. Await {@link Extensions.ready} and call again.
|
|
165
|
+
*/
|
|
166
|
+
export declare class ExtensionModuleRestartingError extends ExtensionModuleError {
|
|
167
|
+
readonly name = "ExtensionModuleRestartingError";
|
|
168
|
+
constructor();
|
|
157
169
|
}
|
|
158
170
|
/**
|
|
159
171
|
* The source was opened before the provider module restarted. Re-register its resources and open
|
|
@@ -169,32 +181,76 @@ interface ExtensionCalls {
|
|
|
169
181
|
call<T>(call: (wasm: WasmExtensionRegistry) => T): T;
|
|
170
182
|
generation(): number;
|
|
171
183
|
}
|
|
184
|
+
/** A provider wasm module, with the formats it opens and the file starts it reads. */
|
|
185
|
+
interface ProviderModule {
|
|
186
|
+
readonly name: ExtensionModuleName;
|
|
187
|
+
readonly loader: WasmModule<ExtensionModule>;
|
|
188
|
+
/** Provider source formats it opens; `null` for every format no other module lists. */
|
|
189
|
+
readonly formats: readonly string[] | null;
|
|
190
|
+
/** Whether a file's first bytes may be one this module reads, so probing should load it. */
|
|
191
|
+
claims(head: Uint8Array): boolean;
|
|
192
|
+
/** Whether its formats read registered resources and fonts (SVG, Lottie, image sequences). */
|
|
193
|
+
readonly readsResources: boolean;
|
|
194
|
+
}
|
|
195
|
+
/** The provider wasm modules of the package, probed in this order. */
|
|
196
|
+
export type ExtensionModuleName = "core" | "pdf";
|
|
197
|
+
/** Where each provider module's `.wasm` file is when a bundler moved it. */
|
|
198
|
+
export type ExtensionWasmUrls = {
|
|
199
|
+
readonly [name in ExtensionModuleName]?: string | URL;
|
|
200
|
+
};
|
|
172
201
|
/**
|
|
173
|
-
*
|
|
202
|
+
* One loaded provider module. A trap in a call restarts it asynchronously; until it is ready again
|
|
203
|
+
* every call throws {@link ExtensionModuleRestartingError}.
|
|
204
|
+
*/
|
|
205
|
+
declare class ModuleSession {
|
|
206
|
+
#private;
|
|
207
|
+
readonly module: ProviderModule;
|
|
208
|
+
readonly calls: ExtensionCalls;
|
|
209
|
+
constructor(module: ProviderModule, glue: ExtensionModule);
|
|
210
|
+
call<T>(call: (wasm: WasmExtensionRegistry) => T): T;
|
|
211
|
+
ready(): Promise<void>;
|
|
212
|
+
setFonts(fonts: readonly Uint8Array[]): void;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The provider modules, shared by every source on the page. Load it with {@link loadExtensions},
|
|
216
|
+
* which loads the core module; others load when {@link probe} or {@link prepare} needs them.
|
|
174
217
|
*
|
|
175
|
-
* Providers parse untrusted files, and a panic aborts
|
|
176
|
-
* throws {@link ExtensionModuleError} and the module restarts with its
|
|
177
|
-
* sources and resources are lost.
|
|
178
|
-
*
|
|
218
|
+
* Providers parse untrusted files, and a panic aborts that module's wasm instance. The call that
|
|
219
|
+
* aborted it throws {@link ExtensionModuleError} and the module restarts asynchronously with its
|
|
220
|
+
* fonts re-registered, but its sources and resources are lost. Until {@link ready} resolves, every
|
|
221
|
+
* call to that module throws {@link ExtensionModuleRestartingError}. Older sources throw
|
|
222
|
+
* {@link StaleExtensionSourceError} until reopened.
|
|
179
223
|
*/
|
|
180
224
|
export declare class Extensions {
|
|
181
225
|
#private;
|
|
182
226
|
/** Use {@link loadExtensions}. */
|
|
183
|
-
constructor(
|
|
184
|
-
/**
|
|
227
|
+
constructor(urls: ExtensionWasmUrls, core: ModuleSession);
|
|
228
|
+
/**
|
|
229
|
+
* Resolves when every loaded module takes calls, at once unless one is restarting.
|
|
230
|
+
*
|
|
231
|
+
* @throws {ExtensionModuleError} When a restart failed; every later call to that module throws.
|
|
232
|
+
*/
|
|
233
|
+
ready(): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Loads the module that opens `provider`, so {@link open} can open it, at once if it is loaded.
|
|
236
|
+
*
|
|
237
|
+
* @throws When the module cannot be fetched or instantiated.
|
|
238
|
+
*/
|
|
239
|
+
prepare(provider: ProviderSource): Promise<void>;
|
|
240
|
+
/** Built-in providers of the loaded modules, in priority order. */
|
|
185
241
|
get providers(): readonly string[];
|
|
186
|
-
/** Whether the
|
|
242
|
+
/** Whether the package can open this provider source; its module need not be loaded yet. */
|
|
187
243
|
supports(provider: ProviderSource): boolean;
|
|
188
244
|
/**
|
|
189
|
-
* Probes `bytes` with the first provider that claims them, or
|
|
190
|
-
* decoders can read them.
|
|
245
|
+
* Probes `bytes` with the first provider that claims them, or answers `null` so the host's own
|
|
246
|
+
* decoders can read them. Loads a module only when the bytes' start may be one of its formats.
|
|
191
247
|
*
|
|
192
|
-
* @throws When a provider claims the bytes and cannot read them.
|
|
248
|
+
* @throws When a provider claims the bytes and cannot read them, or a module cannot load.
|
|
193
249
|
*/
|
|
194
|
-
probe(bytes: Uint8Array): {
|
|
250
|
+
probe(bytes: Uint8Array): Promise<{
|
|
195
251
|
readonly provider: string;
|
|
196
252
|
readonly report: ExtensionReport;
|
|
197
|
-
} | null
|
|
253
|
+
} | null>;
|
|
198
254
|
/**
|
|
199
255
|
* Registers bytes under a locator, such as an image sequence frame or an image an SVG references.
|
|
200
256
|
* They stay until released or a module restart; {@link withResources} scopes them to one call.
|
|
@@ -235,8 +291,9 @@ export declare class Extensions {
|
|
|
235
291
|
*/
|
|
236
292
|
setFonts(fonts: readonly Uint8Array[]): void;
|
|
237
293
|
/**
|
|
238
|
-
* Opens a provider source. Image sequences take
|
|
239
|
-
* (see {@link openNeeds} and {@link withResources}).
|
|
294
|
+
* Opens a provider source. LaTeX takes no bytes. Image sequences take none either; their frames
|
|
295
|
+
* are registered resources (see {@link openNeeds} and {@link withResources}). The source's module
|
|
296
|
+
* must be loaded: {@link probe} loads it for the bytes it claims, {@link prepare} for a source.
|
|
240
297
|
*
|
|
241
298
|
* @throws When the source cannot be opened.
|
|
242
299
|
*/
|
|
@@ -290,8 +347,9 @@ export declare class ExtensionSource {
|
|
|
290
347
|
release(): void;
|
|
291
348
|
}
|
|
292
349
|
/**
|
|
293
|
-
* Loads the provider module once per page
|
|
294
|
-
*
|
|
350
|
+
* Loads the core provider module once per page; the others load when first needed. `wasmUrl`
|
|
351
|
+
* locates the core module's `alpha2_extensions_bg.wasm`, or each module's file by name, when a
|
|
352
|
+
* bundler moved them; it applies to the first call. A failed load is not cached.
|
|
295
353
|
*/
|
|
296
|
-
export declare function loadExtensions(wasmUrl?: string | URL): Promise<Extensions>;
|
|
354
|
+
export declare function loadExtensions(wasmUrl?: string | URL | ExtensionWasmUrls): Promise<Extensions>;
|
|
297
355
|
export {};
|