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/extensions.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
// Browser extension providers (SVG, animated images, Lottie, OpenEXR, image sequences
|
|
2
|
-
// native host's Rust code in
|
|
1
|
+
// Browser extension providers (SVG, animated images, Lottie, OpenEXR, image sequences, LaTeX,
|
|
2
|
+
// PDF), running the native host's Rust code in lazily loaded wasm modules.
|
|
3
|
+
import { WasmModule } from "./wasm-module.js";
|
|
3
4
|
/**
|
|
4
|
-
* The provider module aborted during this call (a panic or failed allocation)
|
|
5
|
-
*
|
|
5
|
+
* The provider module aborted during this call (a panic or failed allocation), or cannot be used.
|
|
6
|
+
* After an abort the module restarts; {@link Extensions.ready} resolves once later calls work. The
|
|
7
|
+
* source involved stays failed.
|
|
6
8
|
*/
|
|
7
9
|
export class ExtensionModuleError extends Error {
|
|
8
10
|
name = "ExtensionModuleError";
|
|
9
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* The provider module is restarting after an abort. Await {@link Extensions.ready} and call again.
|
|
14
|
+
*/
|
|
15
|
+
export class ExtensionModuleRestartingError extends ExtensionModuleError {
|
|
16
|
+
name = "ExtensionModuleRestartingError";
|
|
17
|
+
constructor() {
|
|
18
|
+
super("the extension module is restarting: await ready() and call again");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
10
21
|
/**
|
|
11
22
|
* The source was opened before the provider module restarted. Re-register its resources and open
|
|
12
23
|
* it again.
|
|
@@ -24,35 +35,64 @@ export class StaleExtensionSourceError extends Error {
|
|
|
24
35
|
function isTrap(error) {
|
|
25
36
|
return (error instanceof WebAssembly.RuntimeError || error instanceof RangeError);
|
|
26
37
|
}
|
|
38
|
+
const PDF_HEADER = [0x25, 0x50, 0x44, 0x46, 0x2d];
|
|
39
|
+
const providerModules = [
|
|
40
|
+
{
|
|
41
|
+
name: "core",
|
|
42
|
+
loader: new WasmModule(() => import("alpha2/extensions-wasm")),
|
|
43
|
+
formats: null,
|
|
44
|
+
claims: () => true,
|
|
45
|
+
readsResources: true,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "pdf",
|
|
49
|
+
loader: new WasmModule(() => import("alpha2/extensions-pdf-wasm")),
|
|
50
|
+
formats: ["pdf"],
|
|
51
|
+
// `%PDF-` within the first 1024 bytes, as PDF readers accept.
|
|
52
|
+
claims: (head) => {
|
|
53
|
+
const end = Math.min(head.length, 1024) - PDF_HEADER.length;
|
|
54
|
+
for (let at = 0; at <= end; at++)
|
|
55
|
+
if (PDF_HEADER.every((byte, index) => head[at + index] === byte))
|
|
56
|
+
return true;
|
|
57
|
+
return false;
|
|
58
|
+
},
|
|
59
|
+
readsResources: false,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
const CORE = providerModules[0];
|
|
63
|
+
function moduleFor(provider) {
|
|
64
|
+
return (providerModules.find((module) => module.formats?.includes(provider.format)) ?? CORE);
|
|
65
|
+
}
|
|
27
66
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* Providers parse untrusted files, and a panic aborts the wasm instance. The call that aborted it
|
|
31
|
-
* throws {@link ExtensionModuleError} and the module restarts with its fonts re-registered, but
|
|
32
|
-
* sources and resources are lost. Older sources throw {@link StaleExtensionSourceError} until
|
|
33
|
-
* reopened.
|
|
67
|
+
* One loaded provider module. A trap in a call restarts it asynchronously; until it is ready again
|
|
68
|
+
* every call throws {@link ExtensionModuleRestartingError}.
|
|
34
69
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
70
|
+
class ModuleSession {
|
|
71
|
+
module;
|
|
72
|
+
#glue;
|
|
37
73
|
#wasm;
|
|
38
74
|
/** Restart count; sources from an earlier generation are stale. */
|
|
39
75
|
#generation = 0;
|
|
76
|
+
/** Settles when the current restart ends; `null` when none is running. */
|
|
77
|
+
#restarting = null;
|
|
40
78
|
/** Set when a restart failed. */
|
|
41
79
|
#broken = null;
|
|
42
80
|
#fonts = [];
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.#
|
|
47
|
-
this.#wasm = new
|
|
48
|
-
this
|
|
49
|
-
call: (call) => this
|
|
81
|
+
calls;
|
|
82
|
+
constructor(module, glue) {
|
|
83
|
+
this.module = module;
|
|
84
|
+
this.#glue = glue;
|
|
85
|
+
this.#wasm = new glue.ExtensionRegistry();
|
|
86
|
+
this.calls = {
|
|
87
|
+
call: (call) => this.call(call),
|
|
50
88
|
generation: () => this.#generation,
|
|
51
89
|
};
|
|
52
90
|
}
|
|
53
|
-
|
|
91
|
+
call(call) {
|
|
54
92
|
if (this.#broken !== null)
|
|
55
|
-
throw
|
|
93
|
+
throw this.#brokenError();
|
|
94
|
+
if (this.#restarting !== null)
|
|
95
|
+
throw new ExtensionModuleRestartingError();
|
|
56
96
|
try {
|
|
57
97
|
return call(this.#wasm);
|
|
58
98
|
}
|
|
@@ -60,60 +100,159 @@ export class Extensions {
|
|
|
60
100
|
if (!isTrap(error))
|
|
61
101
|
throw error;
|
|
62
102
|
this.#restart();
|
|
63
|
-
throw new ExtensionModuleError(`the extension module stopped (${error.message}) and
|
|
103
|
+
throw new ExtensionModuleError(`the ${this.module.name} extension module stopped (${error.message}) and is restarting`, { cause: error });
|
|
64
104
|
}
|
|
65
105
|
}
|
|
106
|
+
#brokenError() {
|
|
107
|
+
const broken = this.#broken;
|
|
108
|
+
return new ExtensionModuleError(`the ${this.module.name} extension module stopped and could not be restarted: ${broken.message}`, { cause: broken });
|
|
109
|
+
}
|
|
66
110
|
#restart() {
|
|
67
111
|
this.#generation += 1;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
112
|
+
// Reuses the compiled module; no fetch or compile.
|
|
113
|
+
this.#restarting = this.module.loader
|
|
114
|
+
.restart()
|
|
115
|
+
.then(() => {
|
|
116
|
+
const wasm = new this.#glue.ExtensionRegistry();
|
|
72
117
|
for (const font of this.#fonts)
|
|
73
118
|
wasm.registerFont(font);
|
|
74
119
|
this.#wasm = wasm;
|
|
120
|
+
})
|
|
121
|
+
.catch((error) => {
|
|
122
|
+
this.#broken =
|
|
123
|
+
error instanceof Error ? error : new Error(String(error));
|
|
124
|
+
})
|
|
125
|
+
.finally(() => {
|
|
126
|
+
this.#restarting = null;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async ready() {
|
|
130
|
+
await this.#restarting;
|
|
131
|
+
if (this.#broken !== null)
|
|
132
|
+
throw this.#brokenError();
|
|
133
|
+
}
|
|
134
|
+
setFonts(fonts) {
|
|
135
|
+
this.call((wasm) => {
|
|
136
|
+
wasm.clearFonts();
|
|
137
|
+
for (const font of fonts)
|
|
138
|
+
wasm.registerFont(font);
|
|
139
|
+
});
|
|
140
|
+
this.#fonts = fonts;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The provider modules, shared by every source on the page. Load it with {@link loadExtensions},
|
|
145
|
+
* which loads the core module; others load when {@link probe} or {@link prepare} needs them.
|
|
146
|
+
*
|
|
147
|
+
* Providers parse untrusted files, and a panic aborts that module's wasm instance. The call that
|
|
148
|
+
* aborted it throws {@link ExtensionModuleError} and the module restarts asynchronously with its
|
|
149
|
+
* fonts re-registered, but its sources and resources are lost. Until {@link ready} resolves, every
|
|
150
|
+
* call to that module throws {@link ExtensionModuleRestartingError}. Older sources throw
|
|
151
|
+
* {@link StaleExtensionSourceError} until reopened.
|
|
152
|
+
*/
|
|
153
|
+
export class Extensions {
|
|
154
|
+
#urls;
|
|
155
|
+
#sessions = new Map();
|
|
156
|
+
#loading = new Map();
|
|
157
|
+
#fonts = [];
|
|
158
|
+
/** Use {@link loadExtensions}. */
|
|
159
|
+
constructor(urls, core) {
|
|
160
|
+
this.#urls = urls;
|
|
161
|
+
this.#sessions.set(core.module.name, core);
|
|
162
|
+
}
|
|
163
|
+
#session(module) {
|
|
164
|
+
const session = this.#sessions.get(module.name);
|
|
165
|
+
if (session === undefined)
|
|
166
|
+
throw new Error(`the ${module.name} extension module is not loaded: await prepare() first`);
|
|
167
|
+
return session;
|
|
168
|
+
}
|
|
169
|
+
#readers() {
|
|
170
|
+
return [...this.#sessions.values()].filter((session) => session.module.readsResources);
|
|
171
|
+
}
|
|
172
|
+
#load(module) {
|
|
173
|
+
const loaded = this.#sessions.get(module.name);
|
|
174
|
+
if (loaded !== undefined)
|
|
175
|
+
return Promise.resolve(loaded);
|
|
176
|
+
let loading = this.#loading.get(module.name);
|
|
177
|
+
if (loading === undefined) {
|
|
178
|
+
loading = loadSession(module, this.#urls[module.name])
|
|
179
|
+
.then((session) => {
|
|
180
|
+
if (module.readsResources && this.#fonts.length > 0)
|
|
181
|
+
session.setFonts(this.#fonts);
|
|
182
|
+
this.#sessions.set(module.name, session);
|
|
183
|
+
return session;
|
|
184
|
+
})
|
|
185
|
+
.finally(() => this.#loading.delete(module.name));
|
|
186
|
+
this.#loading.set(module.name, loading);
|
|
75
187
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
188
|
+
return loading;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Resolves when every loaded module takes calls, at once unless one is restarting.
|
|
192
|
+
*
|
|
193
|
+
* @throws {ExtensionModuleError} When a restart failed; every later call to that module throws.
|
|
194
|
+
*/
|
|
195
|
+
async ready() {
|
|
196
|
+
await Promise.all([...this.#sessions.values()].map((session) => session.ready()));
|
|
79
197
|
}
|
|
80
|
-
/**
|
|
198
|
+
/**
|
|
199
|
+
* Loads the module that opens `provider`, so {@link open} can open it, at once if it is loaded.
|
|
200
|
+
*
|
|
201
|
+
* @throws When the module cannot be fetched or instantiated.
|
|
202
|
+
*/
|
|
203
|
+
async prepare(provider) {
|
|
204
|
+
await this.#load(moduleFor(provider));
|
|
205
|
+
}
|
|
206
|
+
/** Built-in providers of the loaded modules, in priority order. */
|
|
81
207
|
get providers() {
|
|
82
|
-
|
|
208
|
+
const names = [...this.#sessions.values()].flatMap((session) => JSON.parse(session.call((wasm) => wasm.providers())));
|
|
209
|
+
return [...new Set(names)];
|
|
83
210
|
}
|
|
84
|
-
/** Whether the
|
|
211
|
+
/** Whether the package can open this provider source; its module need not be loaded yet. */
|
|
85
212
|
supports(provider) {
|
|
86
|
-
|
|
213
|
+
const session = this.#sessions.get(moduleFor(provider).name);
|
|
214
|
+
return (session === undefined ||
|
|
215
|
+
session.call((wasm) => wasm.supports(JSON.stringify(provider))));
|
|
87
216
|
}
|
|
88
217
|
/**
|
|
89
|
-
* Probes `bytes` with the first provider that claims them, or
|
|
90
|
-
* decoders can read them.
|
|
218
|
+
* Probes `bytes` with the first provider that claims them, or answers `null` so the host's own
|
|
219
|
+
* decoders can read them. Loads a module only when the bytes' start may be one of its formats.
|
|
91
220
|
*
|
|
92
|
-
* @throws When a provider claims the bytes and cannot read them.
|
|
221
|
+
* @throws When a provider claims the bytes and cannot read them, or a module cannot load.
|
|
93
222
|
*/
|
|
94
|
-
probe(bytes) {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
223
|
+
async probe(bytes) {
|
|
224
|
+
for (const module of providerModules) {
|
|
225
|
+
if (!module.claims(bytes))
|
|
226
|
+
continue;
|
|
227
|
+
const session = await this.#load(module);
|
|
228
|
+
const found = session.call((wasm) => wasm.probe(bytes));
|
|
229
|
+
if (found !== undefined)
|
|
230
|
+
return JSON.parse(found);
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
99
233
|
}
|
|
100
234
|
/**
|
|
101
235
|
* Registers bytes under a locator, such as an image sequence frame or an image an SVG references.
|
|
102
236
|
* They stay until released or a module restart; {@link withResources} scopes them to one call.
|
|
103
237
|
*/
|
|
104
238
|
registerResource(locator, bytes) {
|
|
105
|
-
|
|
239
|
+
for (const session of this.#readers())
|
|
240
|
+
session.call((wasm) => wasm.registerResource(locator, bytes));
|
|
106
241
|
}
|
|
107
242
|
releaseResource(locator) {
|
|
108
|
-
|
|
243
|
+
for (const session of this.#readers())
|
|
244
|
+
session.call((wasm) => wasm.releaseResource(locator));
|
|
109
245
|
}
|
|
110
246
|
/** Total registered resource bytes. */
|
|
111
247
|
get resourceBytes() {
|
|
112
|
-
return this.#call((wasm) => wasm.resourceBytes());
|
|
248
|
+
return this.#readers().reduce((total, session) => total + session.call((wasm) => wasm.resourceBytes()), 0);
|
|
113
249
|
}
|
|
114
250
|
/** Locators of resources opening this source reads, such as an image sequence's first frame. */
|
|
115
251
|
openNeeds(provider) {
|
|
116
|
-
|
|
252
|
+
const module = moduleFor(provider);
|
|
253
|
+
if (!module.readsResources)
|
|
254
|
+
return [];
|
|
255
|
+
return JSON.parse(this.#session(module).call((wasm) => wasm.openNeeds(JSON.stringify(provider))));
|
|
117
256
|
}
|
|
118
257
|
/**
|
|
119
258
|
* Runs `call` with the resources `needs` names registered only for its duration. Each is
|
|
@@ -173,23 +312,22 @@ export class Extensions {
|
|
|
173
312
|
if (fonts.length === this.#fonts.length &&
|
|
174
313
|
fonts.every((font, index) => font === this.#fonts[index]))
|
|
175
314
|
return;
|
|
176
|
-
this.#
|
|
177
|
-
|
|
178
|
-
for (const font of fonts)
|
|
179
|
-
wasm.registerFont(font);
|
|
180
|
-
});
|
|
315
|
+
for (const session of this.#readers())
|
|
316
|
+
session.setFonts([...fonts]);
|
|
181
317
|
this.#fonts = [...fonts];
|
|
182
318
|
}
|
|
183
319
|
/**
|
|
184
|
-
* Opens a provider source. Image sequences take
|
|
185
|
-
* (see {@link openNeeds} and {@link withResources}).
|
|
320
|
+
* Opens a provider source. LaTeX takes no bytes. Image sequences take none either; their frames
|
|
321
|
+
* are registered resources (see {@link openNeeds} and {@link withResources}). The source's module
|
|
322
|
+
* must be loaded: {@link probe} loads it for the bytes it claims, {@link prepare} for a source.
|
|
186
323
|
*
|
|
187
324
|
* @throws When the source cannot be opened.
|
|
188
325
|
*/
|
|
189
326
|
open(provider, bytes) {
|
|
190
|
-
|
|
327
|
+
const session = this.#session(moduleFor(provider));
|
|
328
|
+
return session.call((wasm) => {
|
|
191
329
|
const handle = wasm.open(JSON.stringify(provider), bytes);
|
|
192
|
-
return new ExtensionSource(
|
|
330
|
+
return new ExtensionSource(session.calls, handle);
|
|
193
331
|
});
|
|
194
332
|
}
|
|
195
333
|
}
|
|
@@ -321,17 +459,22 @@ export class ExtensionSource {
|
|
|
321
459
|
this.#calls.call((wasm) => wasm.release(handle));
|
|
322
460
|
}
|
|
323
461
|
}
|
|
462
|
+
async function loadSession(module, wasmUrl) {
|
|
463
|
+
return new ModuleSession(module, await module.loader.load(wasmUrl));
|
|
464
|
+
}
|
|
324
465
|
let loading = null;
|
|
325
466
|
/**
|
|
326
|
-
* Loads the provider module once per page
|
|
327
|
-
*
|
|
467
|
+
* Loads the core provider module once per page; the others load when first needed. `wasmUrl`
|
|
468
|
+
* locates the core module's `alpha2_extensions_bg.wasm`, or each module's file by name, when a
|
|
469
|
+
* bundler moved them; it applies to the first call. A failed load is not cached.
|
|
328
470
|
*/
|
|
329
471
|
export function loadExtensions(wasmUrl) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
472
|
+
const urls = typeof wasmUrl === "string" || wasmUrl instanceof URL
|
|
473
|
+
? { core: wasmUrl }
|
|
474
|
+
: (wasmUrl ?? {});
|
|
475
|
+
loading ??= loadSession(CORE, urls.core)
|
|
476
|
+
.then((core) => new Extensions(urls, core))
|
|
477
|
+
.catch((error) => {
|
|
335
478
|
loading = null;
|
|
336
479
|
throw error;
|
|
337
480
|
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type ExtractProgress, type ExtractResult, type ExtractRun, type Extractor } from "./extractor.js";
|
|
2
|
+
export type { ExtractAudio, ExtractContext, ExtractEmitter, ExtractFrame, ExtractProgress, ExtractResult, ExtractRun, Extractor, ExtractorDescriptor, } from "./extractor.js";
|
|
3
|
+
export { collectEmits, schemaProblem } from "./extractor.js";
|
|
4
|
+
import type { Project } from "./generated/project-schema.js";
|
|
5
|
+
import { type AudioResamplerBinding, type MediabunnyInput } from "./mediabunny.js";
|
|
6
|
+
/** The wasm `ExtractSession`, driven push style. */
|
|
7
|
+
export interface WasmExtractSession {
|
|
8
|
+
context(): string;
|
|
9
|
+
next(): string;
|
|
10
|
+
videoBytes(): Uint8Array;
|
|
11
|
+
audioSamples(): Float32Array;
|
|
12
|
+
supplyYuvFrame(ptsTicks: bigint, format: string, codedWidth: number, codedHeight: number, data: Uint8Array, layout: Uint32Array, visibleRect: Uint32Array, displayWidth: number, displayHeight: number, colorJson: string, chromaSiting: string, rotationDegrees: number, mirror: boolean): void;
|
|
13
|
+
supplyRgbaFrame(ptsTicks: bigint, width: number, height: number, rgba: Uint8Array): void;
|
|
14
|
+
supplyEnd(): void;
|
|
15
|
+
supplyAudio(channels: number, samples: Float32Array, speakers?: string): void;
|
|
16
|
+
emit(emits: string): void;
|
|
17
|
+
progress(): string;
|
|
18
|
+
finish(madeFrom?: string): string;
|
|
19
|
+
free(): void;
|
|
20
|
+
}
|
|
21
|
+
/** The part of the `alpha2/wasm` module {@link runExtractor} uses. */
|
|
22
|
+
export interface ExtractBinding {
|
|
23
|
+
readonly ExtractSession: new (project: string, descriptor: string, request: string) => WasmExtractSession;
|
|
24
|
+
}
|
|
25
|
+
/** A rendered timeline frame: straight-alpha sRGB RGBA8 at the size asked for. */
|
|
26
|
+
export interface TimelineFrame {
|
|
27
|
+
readonly width: number;
|
|
28
|
+
readonly height: number;
|
|
29
|
+
readonly rgba: Uint8Array;
|
|
30
|
+
}
|
|
31
|
+
/** What {@link runExtractor} runs over. */
|
|
32
|
+
export interface RunExtractorRequest {
|
|
33
|
+
readonly binding: ExtractBinding;
|
|
34
|
+
readonly project: Project;
|
|
35
|
+
readonly request: ExtractRun;
|
|
36
|
+
/** The media file of each source the request reads. */
|
|
37
|
+
readonly media?: Readonly<Record<string, MediabunnyInput>>;
|
|
38
|
+
/** Resamples source audio to the rate the extractor reads. */
|
|
39
|
+
readonly audioBinding?: AudioResamplerBinding;
|
|
40
|
+
/**
|
|
41
|
+
* Draws the timeline at `time` (ticks), `width` x `height`, for a timeline input; the CPU
|
|
42
|
+
* renderer's `readRgbaAt` does, once the frames it shows are uploaded.
|
|
43
|
+
*/
|
|
44
|
+
readonly timelineFrame?: (time: bigint, width: number, height: number) => Promise<TimelineFrame> | TimelineFrame;
|
|
45
|
+
/** The original source's fingerprint, recorded as `made_from` on source-anchored data. */
|
|
46
|
+
readonly madeFrom?: unknown;
|
|
47
|
+
/** The plugin `extractor` came from (`loadPlugin`), recorded as `made_by.plugin`. */
|
|
48
|
+
readonly plugin?: {
|
|
49
|
+
readonly version: string;
|
|
50
|
+
readonly artifactSha256: string;
|
|
51
|
+
};
|
|
52
|
+
readonly signal?: AbortSignal;
|
|
53
|
+
readonly onProgress?: (progress: ExtractProgress) => void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Runs `extractor` over `request.request` in the page or a worker: source frames are decoded in
|
|
57
|
+
* software and presented by the engine exactly as the native hosts present them, so the data
|
|
58
|
+
* matches theirs byte for byte; timeline frames come from `request.timelineFrame`. Resolves with
|
|
59
|
+
* the data sets the session validated.
|
|
60
|
+
*
|
|
61
|
+
* Rejects with `INVALID_INPUT` for a request the session refuses or params the descriptor's
|
|
62
|
+
* `params_schema` does not take, `INVALID_EMIT` (with `details`) for output the session refuses,
|
|
63
|
+
* `EXTRACTOR_FAILED` when a step throws, and `ABORTED` on `request.signal`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function runExtractor(request: RunExtractorRequest, extractor: Extractor): Promise<ExtractResult>;
|