@alpha2-sh/editor 0.5.2 → 0.5.3
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 +2 -2
- package/dist/browser/bridge.d.ts +5 -4
- package/dist/browser/bridge.js +118 -18
- package/dist/browser/extensions-worker.d.ts +4 -3
- package/dist/browser/extensions-worker.js +13 -6
- package/dist/browser/runtime/extension-import.d.ts +30 -10
- package/dist/browser/runtime/extension-import.js +52 -9
- package/dist/browser/runtime/sources.d.ts +2 -2
- package/dist/browser/runtime/sources.js +12 -6
- package/dist/browser/runtime/wasm.d.ts +5 -5
- package/dist/browser/runtime/wasm.js +6 -13
- package/dist/browser/types.d.ts +33 -7
- package/dist/browser/worker.js +2 -1
- package/dist/core/document.d.ts +10 -0
- package/dist/core/document.js +11 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -83,8 +83,8 @@ await bridge.dispose();
|
|
|
83
83
|
await editor.dispose();
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
- Import checks each file with the engine (media, fonts, `.cube` LUTs, SRT and WebVTT captions through `importCaptions`) and adds it to the document in one undoable step. `importSequence` imports numbered PNG or OpenEXR files as one image sequence.
|
|
87
|
-
- `bindPreview` draws on a canvas. With `runtimeAssets.workerFactory`, a worker running the `@alpha2-sh/editor/preview-worker` entry renders the preview off the main thread; without one, or when the worker fails, the main thread does. `hashWorkerFactory` (`@alpha2-sh/editor/hash-worker`) and `extensionsWorkerFactory` (`@alpha2-sh/editor/extensions-worker`, with `extensionsWasmUrl`) move file hashing and SVG, animated image, Lottie and
|
|
86
|
+
- Import checks each file with the engine (media, fonts, `.cube` LUTs, SRT and WebVTT captions through `importCaptions`) and adds it to the document in one undoable step. `importSequence` imports numbered PNG or OpenEXR files as one image sequence. A source whose provider reads no file, such as a LaTeX formula (`{ format: "latex", latex, font_size }`), is kept in the project itself: `putProviderSource` adds or edits one in one undoable step, and it draws in preview and both exports with no file to relink.
|
|
87
|
+
- `bindPreview` draws on a canvas. With `runtimeAssets.workerFactory`, a worker running the `@alpha2-sh/editor/preview-worker` entry renders the preview off the main thread; without one, or when the worker fails, the main thread does. `hashWorkerFactory` (`@alpha2-sh/editor/hash-worker`) and `extensionsWorkerFactory` (`@alpha2-sh/editor/extensions-worker`, with `extensionsWasmUrl` and `extensionModuleUrls` such as `{ pdf }`) move file hashing and SVG, animated image, Lottie, OpenEXR and PDF reading into workers too.
|
|
88
88
|
- `seek`, `play` and `pause` move the playhead; with audio, playback follows the audio clock. Audio preview needs a cross-origin isolated page; editing and video preview do not.
|
|
89
89
|
- `startExport` returns a job with `result`, progress (`subscribe`) and `cancel`. `container` (`mp4` by default, `mov`, `mkv` or `webm`) names the file and decides the codecs: an absent `videoCodec` or `audioCodec` is the container's default (H.264 and AAC, or VP9 and Opus for WebM, with Opus where a browser cannot encode AAC in MP4 or MKV), and one the container does not offer is refused. The output goes to a temporary file in the origin's private storage by default (`release()` deletes it), to a file the user picked (`output: { kind: "file", handle }`), or to memory (`output: { kind: "memory", maxBytes }`). Whether the browser encodes a codec is the browser's to say: `bridge.videoEncoders()` asks ahead, and an export with a codec the browser does not encode is refused before it renders.
|
|
90
90
|
|
package/dist/browser/bridge.d.ts
CHANGED
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
* per file from `extensionsWorkerFactory` (terminated on cancel or past
|
|
6
6
|
* `EXTENSIONS_CALL_TIMEOUT_MS`), or on this thread without one. Fonts are checked with the engine's
|
|
7
7
|
* parser and also registered with the page's `FontFace` set. Content hashes run in a
|
|
8
|
-
* `hashWorkerFactory` worker when given. HDR video without planes
|
|
9
|
-
*
|
|
10
|
-
* @param {{ extensionsWasmUrl?: string | URL, wasmUrl?: string | URL, hashWorkerFactory?: () => Worker, extensionsWorkerFactory?: () => Worker, hdrWithoutPlanes?: "refuse" | "preview-degraded" }} [options]
|
|
8
|
+
* `hashWorkerFactory` worker when given. `hdrWithoutPlanes` says whether HDR video without planes
|
|
9
|
+
* imports degraded or is refused.
|
|
10
|
+
* @param {{ extensionsWasmUrl?: string | URL, extensionModuleUrls?: import("alpha2/extensions").ExtensionWasmUrls, wasmUrl?: string | URL, hashWorkerFactory?: () => Worker, extensionsWorkerFactory?: () => Worker, hdrWithoutPlanes?: "refuse" | "preview-degraded" }} [options]
|
|
11
11
|
* @returns {import("./types.js").BrowserMediaAdapter}
|
|
12
12
|
*/
|
|
13
|
-
export function createMediaAdapter({ extensionsWasmUrl, wasmUrl, hashWorkerFactory, extensionsWorkerFactory, hdrWithoutPlanes, }?: {
|
|
13
|
+
export function createMediaAdapter({ extensionsWasmUrl, extensionModuleUrls, wasmUrl, hashWorkerFactory, extensionsWorkerFactory, hdrWithoutPlanes, }?: {
|
|
14
14
|
extensionsWasmUrl?: string | URL;
|
|
15
|
+
extensionModuleUrls?: import("alpha2/extensions").ExtensionWasmUrls;
|
|
15
16
|
wasmUrl?: string | URL;
|
|
16
17
|
hashWorkerFactory?: () => Worker;
|
|
17
18
|
extensionsWorkerFactory?: () => Worker;
|
package/dist/browser/bridge.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { frameAt, frameStart } from "../core/time.js";
|
|
2
|
-
import { compileEditorDocument, EditorError, sequenceEnd, } from "../core/document.js";
|
|
2
|
+
import { compileEditorDocument, EditorError, readsMediaFile, sequenceEnd, } from "../core/document.js";
|
|
3
3
|
import { captionsAsset } from "../core/captions.js";
|
|
4
|
-
import { MAX_CAPTION_FILE_BYTES } from "alpha2/project";
|
|
4
|
+
import { MAX_CAPTION_FILE_BYTES, providerKind, providerReadsFile, } from "alpha2/project";
|
|
5
5
|
import { containerPolicy } from "alpha2/containers";
|
|
6
6
|
import { PlanarDecodeUnavailableError } from "alpha2/hdr-frames";
|
|
7
7
|
import { drawnEffectResources, shownSources } from "../core/compositions.js";
|
|
@@ -17,7 +17,7 @@ import { SourcePixels, providerSettings, sameProviderSettings, } from "./runtime
|
|
|
17
17
|
import { fingerprintFile } from "./runtime/fingerprint.js";
|
|
18
18
|
import { hashInWorker } from "./hash-worker.js";
|
|
19
19
|
import { callExtensions } from "./extensions-worker.js";
|
|
20
|
-
import { keepProviderChoices, mayBeExtension, providerDocumentLimit, stageProviderFile, stageSequence, } from "./runtime/extension-import.js";
|
|
20
|
+
import { keepProviderChoices, mayBeExtension, providerDocumentLimit, stageProviderFile, stageSequence, extensionWasmUrls, } from "./runtime/extension-import.js";
|
|
21
21
|
import { ProxyStore } from "./runtime/proxies.js";
|
|
22
22
|
import { blockingIssues, compareFingerprints, conformProject, sha256Blob, } from "alpha2/assets";
|
|
23
23
|
/**
|
|
@@ -64,18 +64,18 @@ const AUDIO_START_TIMEOUT_MS = 3000;
|
|
|
64
64
|
* per file from `extensionsWorkerFactory` (terminated on cancel or past
|
|
65
65
|
* `EXTENSIONS_CALL_TIMEOUT_MS`), or on this thread without one. Fonts are checked with the engine's
|
|
66
66
|
* parser and also registered with the page's `FontFace` set. Content hashes run in a
|
|
67
|
-
* `hashWorkerFactory` worker when given. HDR video without planes
|
|
68
|
-
*
|
|
69
|
-
* @param {{ extensionsWasmUrl?: string | URL, wasmUrl?: string | URL, hashWorkerFactory?: () => Worker, extensionsWorkerFactory?: () => Worker, hdrWithoutPlanes?: "refuse" | "preview-degraded" }} [options]
|
|
67
|
+
* `hashWorkerFactory` worker when given. `hdrWithoutPlanes` says whether HDR video without planes
|
|
68
|
+
* imports degraded or is refused.
|
|
69
|
+
* @param {{ extensionsWasmUrl?: string | URL, extensionModuleUrls?: import("alpha2/extensions").ExtensionWasmUrls, wasmUrl?: string | URL, hashWorkerFactory?: () => Worker, extensionsWorkerFactory?: () => Worker, hdrWithoutPlanes?: "refuse" | "preview-degraded" }} [options]
|
|
70
70
|
* @returns {import("./types.js").BrowserMediaAdapter}
|
|
71
71
|
*/
|
|
72
|
-
export function createMediaAdapter({ extensionsWasmUrl, wasmUrl, hashWorkerFactory, extensionsWorkerFactory, hdrWithoutPlanes = "preview-degraded", } = {}) {
|
|
72
|
+
export function createMediaAdapter({ extensionsWasmUrl, extensionModuleUrls, wasmUrl, hashWorkerFactory, extensionsWorkerFactory, hdrWithoutPlanes = "preview-degraded", } = {}) {
|
|
73
73
|
const hash = hashWorkerFactory
|
|
74
74
|
? (file, options) => hashInWorker(hashWorkerFactory, file, options)
|
|
75
75
|
: sha256Blob;
|
|
76
76
|
const module = {
|
|
77
77
|
factory: extensionsWorkerFactory,
|
|
78
|
-
wasmUrl: extensionsWasmUrl,
|
|
78
|
+
wasmUrl: extensionWasmUrls({ extensionsWasmUrl, extensionModuleUrls }),
|
|
79
79
|
};
|
|
80
80
|
/**
|
|
81
81
|
* Runs provider `call` on `file`. A refusal becomes `unreadable_media` with its reason;
|
|
@@ -280,7 +280,57 @@ export function createBrowserBridge(options) {
|
|
|
280
280
|
/** What preview prefers where a source has a fresh proxy (see `setPreviewMedia`). */
|
|
281
281
|
let preferredPreviewMedia = "original";
|
|
282
282
|
const hashOf = (asset) => asset?.fingerprint?.content_sha256;
|
|
283
|
+
/** Runtime views of sources that read no file, by ID, so each keeps one identity. */
|
|
284
|
+
const fileless = new Map();
|
|
285
|
+
/**
|
|
286
|
+
* The runtime a source that reads no file draws from: its own provider settings, which
|
|
287
|
+
* `sourceView` keeps current. `null` for a source whose media is a file. Its report and
|
|
288
|
+
* thumbnail follow the settings, described again whenever they change.
|
|
289
|
+
*/
|
|
290
|
+
function filelessRuntime(document, id) {
|
|
291
|
+
const source = document.project.sources.find((each) => each.id === id);
|
|
292
|
+
if (!source || readsMediaFile(source))
|
|
293
|
+
return null;
|
|
294
|
+
let runtime = fileless.get(id);
|
|
295
|
+
if (!runtime)
|
|
296
|
+
fileless.set(id, (runtime = { id, kind: source.kind, provider: source.provider }));
|
|
297
|
+
if (!sameProviderSettings(runtime.described ?? null, source.provider))
|
|
298
|
+
describeInBackground(runtime, source.provider);
|
|
299
|
+
return runtime;
|
|
300
|
+
}
|
|
301
|
+
/** Opens `provider` in the extensions worker for its report and thumbnail. */
|
|
302
|
+
function describeProvider(provider, signal) {
|
|
303
|
+
return callExtensions({
|
|
304
|
+
factory: runtimeAssets.extensionsWorkerFactory,
|
|
305
|
+
wasmUrl: extensionWasmUrls(runtimeAssets),
|
|
306
|
+
}, { call: "describe", provider }, { signal, operation: "describe" });
|
|
307
|
+
}
|
|
308
|
+
function describe(runtime, provider, { report, thumbnail }) {
|
|
309
|
+
Object.assign(runtime, {
|
|
310
|
+
described: provider,
|
|
311
|
+
report,
|
|
312
|
+
thumbnail,
|
|
313
|
+
width: report.width,
|
|
314
|
+
height: report.height,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function describeInBackground(runtime, provider) {
|
|
318
|
+
if (runtime.describing === provider)
|
|
319
|
+
return;
|
|
320
|
+
runtime.describing = provider;
|
|
321
|
+
describeProvider(provider, lifetime.signal).then((read) => {
|
|
322
|
+
if (disposed || runtime.describing !== provider)
|
|
323
|
+
return;
|
|
324
|
+
describe(runtime, provider, read);
|
|
325
|
+
notifyAssets();
|
|
326
|
+
},
|
|
327
|
+
// A source that does not open reports it when drawn; the next change tries again.
|
|
328
|
+
() => { });
|
|
329
|
+
}
|
|
283
330
|
const originalOf = (document, id) => {
|
|
331
|
+
const contained = filelessRuntime(document, id);
|
|
332
|
+
if (contained)
|
|
333
|
+
return contained;
|
|
284
334
|
const descriptor = document.assets[id];
|
|
285
335
|
if (!descriptor || descriptor.missing)
|
|
286
336
|
return null;
|
|
@@ -467,6 +517,9 @@ export function createBrowserBridge(options) {
|
|
|
467
517
|
* with the document's provider settings.
|
|
468
518
|
*/
|
|
469
519
|
function previewMedia(document, id) {
|
|
520
|
+
const contained = filelessRuntime(document, id);
|
|
521
|
+
if (contained)
|
|
522
|
+
return sourceView(document, id, contained);
|
|
470
523
|
const descriptor = document.assets[id];
|
|
471
524
|
const original = descriptor
|
|
472
525
|
? sourceView(document, id, ownerOf(document, descriptor)?.lease.value)
|
|
@@ -502,6 +555,9 @@ export function createBrowserBridge(options) {
|
|
|
502
555
|
}
|
|
503
556
|
/** A lease on the runtime `asset` reads, for work that outlives the owner's hold. */
|
|
504
557
|
function acquireOwned(document, asset) {
|
|
558
|
+
const contained = asset && filelessRuntime(document, asset.id);
|
|
559
|
+
if (contained)
|
|
560
|
+
return { value: contained, release() { } };
|
|
505
561
|
const owner = asset && ownerOf(document, asset);
|
|
506
562
|
if (!owner && asset?.kind === "text")
|
|
507
563
|
throw undrawnText(document, asset);
|
|
@@ -910,7 +966,7 @@ export function createBrowserBridge(options) {
|
|
|
910
966
|
try {
|
|
911
967
|
diagnostics = await callExtensions({
|
|
912
968
|
factory: runtimeAssets.extensionsWorkerFactory,
|
|
913
|
-
wasmUrl: runtimeAssets
|
|
969
|
+
wasmUrl: extensionWasmUrls(runtimeAssets),
|
|
914
970
|
}, {
|
|
915
971
|
call: "svg-diagnostics",
|
|
916
972
|
file: runtime.file,
|
|
@@ -1372,7 +1428,7 @@ export function createBrowserBridge(options) {
|
|
|
1372
1428
|
await engine?.dispose();
|
|
1373
1429
|
await sources?.dispose();
|
|
1374
1430
|
sources = new SourcePixels(library, {
|
|
1375
|
-
|
|
1431
|
+
extensionWasmUrls: extensionWasmUrls(runtimeAssets),
|
|
1376
1432
|
});
|
|
1377
1433
|
const { Engine } = await import("./runtime/engine.js");
|
|
1378
1434
|
// Until a project loads and sets the render size (see `loaded`).
|
|
@@ -1419,9 +1475,7 @@ export function createBrowserBridge(options) {
|
|
|
1419
1475
|
...(runtimeAssets.wasmUrl
|
|
1420
1476
|
? { wasmUrl: String(runtimeAssets.wasmUrl) }
|
|
1421
1477
|
: {}),
|
|
1422
|
-
|
|
1423
|
-
? { extensionsWasmUrl: String(runtimeAssets.extensionsWasmUrl) }
|
|
1424
|
-
: {}),
|
|
1478
|
+
extensionModuleUrls: extensionWasmUrls(runtimeAssets),
|
|
1425
1479
|
};
|
|
1426
1480
|
workerPreview = createWorkerPreview(runtimeAssets.workerFactory(), {
|
|
1427
1481
|
runtimeAssets: workerRuntime,
|
|
@@ -1755,8 +1809,8 @@ export function createBrowserBridge(options) {
|
|
|
1755
1809
|
const old = relinkId ? editor.document.assets[relinkId] : null;
|
|
1756
1810
|
if (relinkId && !old)
|
|
1757
1811
|
throw new EditorError("missing_asset", "Unknown relink target", "relink", relinkId);
|
|
1758
|
-
// Equal hashes match whatever else differs
|
|
1759
|
-
// other media.
|
|
1812
|
+
// Equal hashes match whatever else differs. Without hashes, any recorded part that differs
|
|
1813
|
+
// means other media.
|
|
1760
1814
|
if (old?.fingerprint && item.fingerprint) {
|
|
1761
1815
|
const match = compareFingerprints(await decisions(), old.fingerprint, item.fingerprint);
|
|
1762
1816
|
if (match.kind === "mismatch")
|
|
@@ -1954,7 +2008,7 @@ export function createBrowserBridge(options) {
|
|
|
1954
2008
|
const { openExportOutput } = await import("./runtime/output.js");
|
|
1955
2009
|
const project = compiled.project, lib = { get: (id) => map.get(id) };
|
|
1956
2010
|
const pixels = new SourcePixels(lib, {
|
|
1957
|
-
|
|
2011
|
+
extensionWasmUrls: extensionWasmUrls(runtimeAssets),
|
|
1958
2012
|
videoDecode,
|
|
1959
2013
|
});
|
|
1960
2014
|
// The retry policy picks the renderer: CPU after a self-caused loss or a second page loss.
|
|
@@ -2136,6 +2190,50 @@ export function createBrowserBridge(options) {
|
|
|
2136
2190
|
relink: (id, file, options) => importFiles([file], { ...options, relinkId: id }),
|
|
2137
2191
|
importSequence,
|
|
2138
2192
|
relinkSequence,
|
|
2193
|
+
async putProviderSource({ id, name, provider }, { signal } = {}) {
|
|
2194
|
+
if (providerReadsFile(provider))
|
|
2195
|
+
throw new EditorError("unsupported_media", "A provider source that reads a file is imported with importFiles", "provider", id);
|
|
2196
|
+
const generation = editor.generation;
|
|
2197
|
+
let read;
|
|
2198
|
+
try {
|
|
2199
|
+
read = await describeProvider(provider, signal);
|
|
2200
|
+
}
|
|
2201
|
+
catch (error) {
|
|
2202
|
+
if (error?.name === "AbortError")
|
|
2203
|
+
throw error;
|
|
2204
|
+
throw new EditorError("unreadable_media", String(error?.message ?? error), "provider", id);
|
|
2205
|
+
}
|
|
2206
|
+
if (disposed || editor.disposed || editor.generation !== generation)
|
|
2207
|
+
throw new EditorError("stale_import", "Project changed while the source opened", "provider", id);
|
|
2208
|
+
const assetId = id ?? crypto.randomUUID();
|
|
2209
|
+
const descriptor = editor.document.assets[assetId];
|
|
2210
|
+
const previous = editor.document.project.sources.find((candidate) => candidate.id === assetId);
|
|
2211
|
+
const kind = providerKind(provider);
|
|
2212
|
+
const result = editor.dispatch({
|
|
2213
|
+
type: "asset.put",
|
|
2214
|
+
asset: {
|
|
2215
|
+
...(descriptor ?? { contentRevision: 0 }),
|
|
2216
|
+
id: assetId,
|
|
2217
|
+
kind,
|
|
2218
|
+
name: name ?? descriptor?.name ?? provider.format,
|
|
2219
|
+
missing: false,
|
|
2220
|
+
},
|
|
2221
|
+
source: {
|
|
2222
|
+
...previous,
|
|
2223
|
+
id: assetId,
|
|
2224
|
+
kind,
|
|
2225
|
+
locator: "",
|
|
2226
|
+
provider,
|
|
2227
|
+
},
|
|
2228
|
+
});
|
|
2229
|
+
if (!result.ok)
|
|
2230
|
+
throw result.error;
|
|
2231
|
+
const runtime = filelessRuntime(editor.document, assetId);
|
|
2232
|
+
if (runtime)
|
|
2233
|
+
describe(runtime, provider, read);
|
|
2234
|
+
notifyAssets();
|
|
2235
|
+
return { assetId };
|
|
2236
|
+
},
|
|
2139
2237
|
selectAnimation(id, animation) {
|
|
2140
2238
|
const descriptor = editor.document.assets[id];
|
|
2141
2239
|
const source = editor.document.project.sources.find((candidate) => candidate.id === id);
|
|
@@ -2375,7 +2473,9 @@ export function createBrowserBridge(options) {
|
|
|
2375
2473
|
const result = [];
|
|
2376
2474
|
const fonts = new Set(heldFonts(snapshot));
|
|
2377
2475
|
for (const asset of Object.values(snapshot.assets)) {
|
|
2476
|
+
// A source that reads no file goes to the host in the project alone.
|
|
2378
2477
|
if (drawnByEngine(asset) ||
|
|
2478
|
+
filelessRuntime(snapshot, asset.id) ||
|
|
2379
2479
|
(asset.kind === "font" ? !fonts.has(asset) : !used.has(asset.id)))
|
|
2380
2480
|
continue;
|
|
2381
2481
|
const proxied = selection.get(asset.id)?.media === "proxy";
|
|
@@ -2532,8 +2632,8 @@ export function createBrowserBridge(options) {
|
|
|
2532
2632
|
return engine?.catalog ?? null;
|
|
2533
2633
|
},
|
|
2534
2634
|
registerEffects,
|
|
2535
|
-
// A source's own media while online, whichever preview reads, so size, file and peaks
|
|
2536
|
-
// original
|
|
2635
|
+
// A source's own media while online, whichever one preview reads, so the size, file and peaks
|
|
2636
|
+
// come from the original.
|
|
2537
2637
|
getAsset: (id) => (preferredPreviewMedia === "proxies" &&
|
|
2538
2638
|
sourceView(editor.draft, id, originalOf(editor.draft, id))) ||
|
|
2539
2639
|
library.get(id),
|
|
@@ -9,19 +9,20 @@ export function installExtensionsWorker(scope: {
|
|
|
9
9
|
postMessage(message: unknown): void;
|
|
10
10
|
}): void;
|
|
11
11
|
/**
|
|
12
|
-
* Runs an extensions call (`read`, `svg-diagnostics
|
|
12
|
+
* Runs an extensions call (`read`, `svg-diagnostics`, `exr-first-frame` or `describe`) on
|
|
13
|
+
* `request.file`, which `describe` omits for a provider that reads no file.
|
|
13
14
|
* With `factory`, the call runs in a new worker running {@link installExtensionsWorker}, terminated
|
|
14
15
|
* once it answers, when `signal` aborts (rejecting with its reason), or after `timeoutMs`
|
|
15
16
|
* (rejecting as `provider_stalled`). Without a factory, or if the worker script fails to load, the
|
|
16
17
|
* call runs on this thread, where it cannot be stopped and `signal` is checked between steps.
|
|
17
18
|
*
|
|
18
|
-
* @param {{ factory?: () => Worker, wasmUrl?: string | URL }} module
|
|
19
|
+
* @param {{ factory?: () => Worker, wasmUrl?: string | URL | import("alpha2/extensions").ExtensionWasmUrls }} module
|
|
19
20
|
* @param {{ call: string, file: Blob & { name?: string }, [key: string]: unknown }} request
|
|
20
21
|
* @param {{ signal?: AbortSignal, timeoutMs?: number, operation?: string }} [options]
|
|
21
22
|
*/
|
|
22
23
|
export function callExtensions({ factory, wasmUrl }: {
|
|
23
24
|
factory?: () => Worker;
|
|
24
|
-
wasmUrl?: string | URL;
|
|
25
|
+
wasmUrl?: string | URL | import("alpha2/extensions").ExtensionWasmUrls;
|
|
25
26
|
}, request: {
|
|
26
27
|
call: string;
|
|
27
28
|
file: Blob & {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// `@alpha2-sh/editor/extensions-worker` entry pass `runtimeAssets.extensionsWorkerFactory`; each
|
|
4
4
|
// call gets its own worker, terminated on cancel or past `EXTENSIONS_CALL_TIMEOUT_MS`.
|
|
5
5
|
import { EditorError } from "../core/document.js";
|
|
6
|
-
import { exrFirstFrame, readProviderFile, svgDiagnostics, } from "./runtime/extension-import.js";
|
|
6
|
+
import { exrFirstFrame, readProviderFile, readProviderSource, svgDiagnostics, } from "./runtime/extension-import.js";
|
|
7
7
|
/**
|
|
8
8
|
* How long one extensions worker call may run before the worker is terminated and the call fails as
|
|
9
9
|
* `provider_stalled`. Matches the 40 s a native decode shard may spend in one provider or decoder
|
|
@@ -22,6 +22,8 @@ const CALLS = {
|
|
|
22
22
|
"svg-diagnostics": (extensions, bytes, { provider, fonts }) => svgDiagnostics(extensions, provider, bytes, fonts),
|
|
23
23
|
/** An OpenEXR sequence's first frame: its thumbnail and report. */
|
|
24
24
|
"exr-first-frame": (extensions, bytes) => exrFirstFrame(extensions, bytes),
|
|
25
|
+
/** A provider source's report and thumbnail; no file for one that reads none. */
|
|
26
|
+
describe: (extensions, bytes, { provider }) => readProviderSource(extensions, provider, bytes),
|
|
25
27
|
};
|
|
26
28
|
async function run(request, wasmUrl, load, signal) {
|
|
27
29
|
const call = CALLS[request.call];
|
|
@@ -29,7 +31,9 @@ async function run(request, wasmUrl, load, signal) {
|
|
|
29
31
|
throw new Error(`unknown extensions call ${request.call}`);
|
|
30
32
|
const extensions = await load(wasmUrl);
|
|
31
33
|
signal?.throwIfAborted();
|
|
32
|
-
const bytes =
|
|
34
|
+
const bytes = request.file
|
|
35
|
+
? new Uint8Array(await request.file.arrayBuffer())
|
|
36
|
+
: undefined;
|
|
33
37
|
signal?.throwIfAborted();
|
|
34
38
|
return call(extensions, bytes, request);
|
|
35
39
|
}
|
|
@@ -58,21 +62,24 @@ export function installExtensionsWorker(scope) {
|
|
|
58
62
|
};
|
|
59
63
|
scope.postMessage({ type: "started" });
|
|
60
64
|
}
|
|
61
|
-
/** `url
|
|
65
|
+
/** Makes `url`, or each URL in a map of them, absolute, so a worker resolves it like the page. */
|
|
62
66
|
function absolute(url) {
|
|
63
67
|
if (url === undefined)
|
|
64
68
|
return undefined;
|
|
69
|
+
if (typeof url === "object" && !(url instanceof URL))
|
|
70
|
+
return Object.fromEntries(Object.entries(url).map(([name, each]) => [name, absolute(each)]));
|
|
65
71
|
const base = globalThis.location?.href;
|
|
66
72
|
return base ? new URL(String(url), base).href : String(url);
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
69
|
-
* Runs an extensions call (`read`, `svg-diagnostics
|
|
75
|
+
* Runs an extensions call (`read`, `svg-diagnostics`, `exr-first-frame` or `describe`) on
|
|
76
|
+
* `request.file`, which `describe` omits for a provider that reads no file.
|
|
70
77
|
* With `factory`, the call runs in a new worker running {@link installExtensionsWorker}, terminated
|
|
71
78
|
* once it answers, when `signal` aborts (rejecting with its reason), or after `timeoutMs`
|
|
72
79
|
* (rejecting as `provider_stalled`). Without a factory, or if the worker script fails to load, the
|
|
73
80
|
* call runs on this thread, where it cannot be stopped and `signal` is checked between steps.
|
|
74
81
|
*
|
|
75
|
-
* @param {{ factory?: () => Worker, wasmUrl?: string | URL }} module
|
|
82
|
+
* @param {{ factory?: () => Worker, wasmUrl?: string | URL | import("alpha2/extensions").ExtensionWasmUrls }} module
|
|
76
83
|
* @param {{ call: string, file: Blob & { name?: string }, [key: string]: unknown }} request
|
|
77
84
|
* @param {{ signal?: AbortSignal, timeoutMs?: number, operation?: string }} [options]
|
|
78
85
|
*/
|
|
@@ -103,7 +110,7 @@ export function callExtensions({ factory, wasmUrl }, request, { signal, timeoutM
|
|
|
103
110
|
};
|
|
104
111
|
const timer = setTimeout(() => {
|
|
105
112
|
end();
|
|
106
|
-
reject(new EditorError("provider_stalled", `${request.file
|
|
113
|
+
reject(new EditorError("provider_stalled", `${request.file?.name ?? "The source"} took the extension provider more than ${timeoutMs / 1000} s to read; it was stopped`, operation));
|
|
107
114
|
}, timeoutMs);
|
|
108
115
|
signal?.addEventListener("abort", abort, { once: true });
|
|
109
116
|
worker.onmessage = ({ data }) => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/** Whether a file's start could be SVG, GIF,
|
|
1
|
+
/** Whether a file's start could be SVG, GIF, WebP, APNG, Lottie, dotLottie, OpenEXR or PDF. */
|
|
2
2
|
export function mayBeExtension(head: any): boolean;
|
|
3
3
|
/**
|
|
4
4
|
* The byte limit for a file that could be a document format a provider parses whole, by its start:
|
|
5
|
-
* dotLottie (ZIP, `MAX_PROVIDER_DOCUMENT_BYTES`), Lottie (JSON, `MAX_LOTTIE_DOCUMENT_BYTES`)
|
|
6
|
-
*
|
|
7
|
-
* files are refused unread.
|
|
5
|
+
* dotLottie (ZIP, `MAX_PROVIDER_DOCUMENT_BYTES`), Lottie (JSON, `MAX_LOTTIE_DOCUMENT_BYTES`), SVG
|
|
6
|
+
* (XML, `MAX_SVG_DOCUMENT_BYTES`) or PDF (`MAX_PDF_DOCUMENT_BYTES`), with the format's name;
|
|
7
|
+
* `null` for other files. Larger files are refused unread.
|
|
8
8
|
*/
|
|
9
9
|
export function providerDocumentLimit(head: any): {
|
|
10
10
|
limit: number;
|
|
@@ -36,18 +36,28 @@ export function keepProviderChoices(recorded: any, staged: any, report: any): an
|
|
|
36
36
|
*/
|
|
37
37
|
export function readProviderFile(extensions: any, bytes: any): Promise<{
|
|
38
38
|
report: any;
|
|
39
|
-
provider:
|
|
40
|
-
format: any;
|
|
41
|
-
} | {
|
|
42
|
-
animation?: any;
|
|
43
|
-
format: string;
|
|
44
|
-
};
|
|
39
|
+
provider: any;
|
|
45
40
|
thumbnail: {
|
|
46
41
|
dataUrl: any;
|
|
47
42
|
width: number;
|
|
48
43
|
height: number;
|
|
49
44
|
};
|
|
50
45
|
} | null>;
|
|
46
|
+
/**
|
|
47
|
+
* What a provider source shows: its report and a first-frame thumbnail. `bytes` are its file,
|
|
48
|
+
* absent for a provider that reads none.
|
|
49
|
+
*
|
|
50
|
+
* @throws When the source does not open.
|
|
51
|
+
*/
|
|
52
|
+
export function readProviderSource(extensions: any, provider: any, bytes: any): Promise<{
|
|
53
|
+
report: any;
|
|
54
|
+
provider: any;
|
|
55
|
+
thumbnail: {
|
|
56
|
+
dataUrl: any;
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
};
|
|
60
|
+
}>;
|
|
51
61
|
/**
|
|
52
62
|
* An SVG's diagnostics when opened with font stack `fonts`, listing text no font draws
|
|
53
63
|
* (`missing_font`).
|
|
@@ -187,3 +197,13 @@ export function exrFirstFrame(extensions: any, bytes: any): Promise<{
|
|
|
187
197
|
};
|
|
188
198
|
report: any;
|
|
189
199
|
}>;
|
|
200
|
+
/**
|
|
201
|
+
* The provider modules' `.wasm` URLs by module name, as strings a worker can be sent. The core
|
|
202
|
+
* module's comes from `extensionsWasmUrl`, any other's from `extensionModuleUrls`.
|
|
203
|
+
* @param {{ extensionsWasmUrl?: string | URL, extensionModuleUrls?: import("alpha2/extensions").ExtensionWasmUrls } | undefined} assets
|
|
204
|
+
* @returns {Record<string, string>}
|
|
205
|
+
*/
|
|
206
|
+
export function extensionWasmUrls(assets: {
|
|
207
|
+
extensionsWasmUrl?: string | URL;
|
|
208
|
+
extensionModuleUrls?: import("alpha2/extensions").ExtensionWasmUrls;
|
|
209
|
+
} | undefined): Record<string, string>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Importing media an extension provider reads. The provider is chosen by probing bytes, never by
|
|
2
2
|
// file name; the extensions wasm module loads only when the bytes could match one of its formats.
|
|
3
|
-
import { MAX_LOTTIE_DOCUMENT_BYTES, MAX_PROVIDER_DOCUMENT_BYTES, MAX_SEQUENCE_FRAMES, MAX_SVG_DOCUMENT_BYTES, } from "alpha2/project";
|
|
3
|
+
import { MAX_LOTTIE_DOCUMENT_BYTES, MAX_PDF_DOCUMENT_BYTES, MAX_PROVIDER_DOCUMENT_BYTES, MAX_SEQUENCE_FRAMES, MAX_SVG_DOCUMENT_BYTES, } from "alpha2/project";
|
|
4
4
|
import { EditorError } from "../../core/document.js";
|
|
5
5
|
const TICKS_PER_SECOND = 120_000;
|
|
6
|
-
/** Whether a file's start could be SVG, GIF,
|
|
6
|
+
/** Whether a file's start could be SVG, GIF, WebP, APNG, Lottie, dotLottie, OpenEXR or PDF. */
|
|
7
7
|
export function mayBeExtension(head) {
|
|
8
8
|
const ascii = (at, text) => [...text].every((char, index) => head[at + index] === char.charCodeAt(0));
|
|
9
|
-
if (ascii(0, "GIF8") || isExr(head))
|
|
9
|
+
if (ascii(0, "GIF8") || isExr(head) || isPdf(head))
|
|
10
10
|
return true;
|
|
11
11
|
if (ascii(0, "RIFF") && ascii(8, "WEBP"))
|
|
12
12
|
return ascii(12, "VP8X") && (head[20] & 0x02) !== 0;
|
|
@@ -22,11 +22,13 @@ export function mayBeExtension(head) {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* The byte limit for a file that could be a document format a provider parses whole, by its start:
|
|
25
|
-
* dotLottie (ZIP, `MAX_PROVIDER_DOCUMENT_BYTES`), Lottie (JSON, `MAX_LOTTIE_DOCUMENT_BYTES`)
|
|
26
|
-
*
|
|
27
|
-
* files are refused unread.
|
|
25
|
+
* dotLottie (ZIP, `MAX_PROVIDER_DOCUMENT_BYTES`), Lottie (JSON, `MAX_LOTTIE_DOCUMENT_BYTES`), SVG
|
|
26
|
+
* (XML, `MAX_SVG_DOCUMENT_BYTES`) or PDF (`MAX_PDF_DOCUMENT_BYTES`), with the format's name;
|
|
27
|
+
* `null` for other files. Larger files are refused unread.
|
|
28
28
|
*/
|
|
29
29
|
export function providerDocumentLimit(head) {
|
|
30
|
+
if (isPdf(head))
|
|
31
|
+
return { limit: MAX_PDF_DOCUMENT_BYTES, what: "PDF document" };
|
|
30
32
|
if (head[0] === 0x50 &&
|
|
31
33
|
head[1] === 0x4b &&
|
|
32
34
|
head[2] === 0x03 &&
|
|
@@ -39,6 +41,16 @@ export function providerDocumentLimit(head) {
|
|
|
39
41
|
return { limit: MAX_SVG_DOCUMENT_BYTES, what: "SVG document" };
|
|
40
42
|
return null;
|
|
41
43
|
}
|
|
44
|
+
/** Whether `%PDF-` starts within the first 1024 bytes, as PDF readers accept. */
|
|
45
|
+
function isPdf(head) {
|
|
46
|
+
const signature = [0x25, 0x50, 0x44, 0x46, 0x2d];
|
|
47
|
+
const end = Math.min(head.length, 1024) - signature.length;
|
|
48
|
+
for (let at = 0; at <= end; at++) {
|
|
49
|
+
if (signature.every((byte, index) => head[at + index] === byte))
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
42
54
|
function isExr(head) {
|
|
43
55
|
return (head[0] === 0x76 && head[1] === 0x2f && head[2] === 0x31 && head[3] === 0x01);
|
|
44
56
|
}
|
|
@@ -141,12 +153,19 @@ export function keepProviderChoices(recorded, staged, report) {
|
|
|
141
153
|
recorded.primaries !== undefined &&
|
|
142
154
|
report?.color)
|
|
143
155
|
return { ...staged, primaries: recorded.primaries };
|
|
156
|
+
if (staged.format === "pdf" &&
|
|
157
|
+
recorded.page !== undefined &&
|
|
158
|
+
report?.items?.includes(String(recorded.page)))
|
|
159
|
+
return { ...staged, page: recorded.page };
|
|
144
160
|
return staged;
|
|
145
161
|
}
|
|
146
162
|
/** The provider source import records for a probed file. */
|
|
147
163
|
function providerOf(report) {
|
|
148
164
|
if (report.format === "svg" || report.format === "exr")
|
|
149
165
|
return { format: report.format };
|
|
166
|
+
// The first page, until the user picks another.
|
|
167
|
+
if (report.format === "pdf")
|
|
168
|
+
return { format: "pdf", page: 1 };
|
|
150
169
|
if (report.format === "lottie" || report.format === "dot_lottie")
|
|
151
170
|
return {
|
|
152
171
|
format: "lottie",
|
|
@@ -165,14 +184,24 @@ function providerOf(report) {
|
|
|
165
184
|
* @throws When a provider claims the bytes and cannot read them.
|
|
166
185
|
*/
|
|
167
186
|
export async function readProviderFile(extensions, bytes) {
|
|
168
|
-
const found = extensions.probe(bytes);
|
|
187
|
+
const found = await extensions.probe(bytes);
|
|
169
188
|
if (!found)
|
|
170
189
|
return null;
|
|
171
|
-
const
|
|
190
|
+
const read = await readProviderSource(extensions, providerOf(found.report), bytes);
|
|
191
|
+
return { ...read, report: found.report };
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* What a provider source shows: its report and a first-frame thumbnail. `bytes` are its file,
|
|
195
|
+
* absent for a provider that reads none.
|
|
196
|
+
*
|
|
197
|
+
* @throws When the source does not open.
|
|
198
|
+
*/
|
|
199
|
+
export async function readProviderSource(extensions, provider, bytes) {
|
|
200
|
+
await extensions.prepare(provider);
|
|
172
201
|
const source = extensions.open(provider, bytes);
|
|
173
202
|
try {
|
|
174
203
|
return {
|
|
175
|
-
report:
|
|
204
|
+
report: source.report,
|
|
176
205
|
provider,
|
|
177
206
|
thumbnail: await thumbnailOf(source.render(0n, { width: 160, height: 90 })),
|
|
178
207
|
};
|
|
@@ -509,3 +538,17 @@ export async function exrFirstFrame(extensions, bytes) {
|
|
|
509
538
|
source.release();
|
|
510
539
|
}
|
|
511
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* The provider modules' `.wasm` URLs by module name, as strings a worker can be sent. The core
|
|
543
|
+
* module's comes from `extensionsWasmUrl`, any other's from `extensionModuleUrls`.
|
|
544
|
+
* @param {{ extensionsWasmUrl?: string | URL, extensionModuleUrls?: import("alpha2/extensions").ExtensionWasmUrls } | undefined} assets
|
|
545
|
+
* @returns {Record<string, string>}
|
|
546
|
+
*/
|
|
547
|
+
export function extensionWasmUrls(assets) {
|
|
548
|
+
const urls = { ...assets?.extensionModuleUrls };
|
|
549
|
+
if (assets?.extensionsWasmUrl)
|
|
550
|
+
urls.core = assets.extensionsWasmUrl;
|
|
551
|
+
return Object.fromEntries(Object.entries(urls)
|
|
552
|
+
.filter(([, url]) => url)
|
|
553
|
+
.map(([name, url]) => [name, String(url)]));
|
|
554
|
+
}
|
|
@@ -14,7 +14,7 @@ export const DEFAULT_RASTER_BUDGET_BYTES: number;
|
|
|
14
14
|
export const DEFAULT_PROVIDER_SOURCE_BYTES: number;
|
|
15
15
|
/** The host side of the engine's per-frame source requests for one renderer (preview or export). */
|
|
16
16
|
export class SourcePixels {
|
|
17
|
-
constructor(library: any, { decoderLimit, rasterBudgetBytes, providerSourceBytes,
|
|
17
|
+
constructor(library: any, { decoderLimit, rasterBudgetBytes, providerSourceBytes, extensionWasmUrls, videoDecode, }?: {
|
|
18
18
|
decoderLimit?: number | undefined;
|
|
19
19
|
rasterBudgetBytes?: number | undefined;
|
|
20
20
|
providerSourceBytes?: number | undefined;
|
|
@@ -24,7 +24,7 @@ export class SourcePixels {
|
|
|
24
24
|
rasterBudgetBytes: number;
|
|
25
25
|
providerSourceBytes: number;
|
|
26
26
|
library: any;
|
|
27
|
-
|
|
27
|
+
extensionWasmUrls: any;
|
|
28
28
|
/**
|
|
29
29
|
* `"auto"` lets the browser pick, hardware where available; `"software"` decodes on the CPU so
|
|
30
30
|
* no frame needs a GPU readback. Sources without a software decoder decode as `"auto"` and are
|
|
@@ -50,7 +50,7 @@ export class SourcePixels {
|
|
|
50
50
|
#fonts = [];
|
|
51
51
|
/** Each SVG's content identity with the fonts it was drawn with, for `contentOf`. */
|
|
52
52
|
#fontContents = new WeakMap();
|
|
53
|
-
constructor(library, { decoderLimit = 32, rasterBudgetBytes = DEFAULT_RASTER_BUDGET_BYTES, providerSourceBytes = DEFAULT_PROVIDER_SOURCE_BYTES,
|
|
53
|
+
constructor(library, { decoderLimit = 32, rasterBudgetBytes = DEFAULT_RASTER_BUDGET_BYTES, providerSourceBytes = DEFAULT_PROVIDER_SOURCE_BYTES, extensionWasmUrls, videoDecode = "auto", } = {}) {
|
|
54
54
|
if (videoDecode !== "auto" && videoDecode !== "software")
|
|
55
55
|
throw new RangeError('videoDecode must be "auto" or "software"');
|
|
56
56
|
if (!Number.isSafeInteger(rasterBudgetBytes) || rasterBudgetBytes <= 0)
|
|
@@ -61,7 +61,7 @@ export class SourcePixels {
|
|
|
61
61
|
this.rasterBudgetBytes = rasterBudgetBytes;
|
|
62
62
|
this.providerSourceBytes = providerSourceBytes;
|
|
63
63
|
this.library = library;
|
|
64
|
-
this.
|
|
64
|
+
this.extensionWasmUrls = extensionWasmUrls;
|
|
65
65
|
/**
|
|
66
66
|
* `"auto"` lets the browser pick, hardware where available; `"software"` decodes on the CPU so
|
|
67
67
|
* no frame needs a GPU readback. Sources without a software decoder decode as `"auto"` and are
|
|
@@ -160,7 +160,7 @@ export class SourcePixels {
|
|
|
160
160
|
fonts,
|
|
161
161
|
source: provider.format === "animated_image"
|
|
162
162
|
? this.#openReader(asset)
|
|
163
|
-
: openProvider(asset, this.
|
|
163
|
+
: openProvider(asset, this.extensionWasmUrls, fonts),
|
|
164
164
|
};
|
|
165
165
|
// Keep provider reports, but retry load or read failures next frame.
|
|
166
166
|
opening.source.catch((error) => {
|
|
@@ -195,9 +195,13 @@ export class SourcePixels {
|
|
|
195
195
|
frame = await extensions.withResources(read, () => source.needs(ticks), () => source.render(ticks, fit));
|
|
196
196
|
}
|
|
197
197
|
catch (error) {
|
|
198
|
-
// The provider module restarted after another source stopped it, so
|
|
199
|
-
|
|
198
|
+
// The provider module restarted, or is restarting, after another source stopped it, so
|
|
199
|
+
// reopen this one once it is ready.
|
|
200
|
+
if ((error?.name !== "ExtensionModuleRestartingError" &&
|
|
201
|
+
error?.name !== "StaleExtensionSourceError") ||
|
|
202
|
+
reopened)
|
|
200
203
|
throw error;
|
|
204
|
+
await extensions.ready();
|
|
201
205
|
if (this.#providers.get(key) === opened)
|
|
202
206
|
this.#providers.delete(key);
|
|
203
207
|
return this.#providerPixels(asset, key, seconds, true);
|
|
@@ -248,7 +252,7 @@ export class SourcePixels {
|
|
|
248
252
|
}
|
|
249
253
|
else if (made)
|
|
250
254
|
this.#dropReaderMaker(asset.id);
|
|
251
|
-
const opening = openProvider(asset, this.
|
|
255
|
+
const opening = openProvider(asset, this.extensionWasmUrls, null);
|
|
252
256
|
const entry = {
|
|
253
257
|
asset,
|
|
254
258
|
provider,
|
|
@@ -899,6 +903,8 @@ async function openProvider(asset, wasmUrl, fonts) {
|
|
|
899
903
|
try {
|
|
900
904
|
const { loadExtensions } = await import("alpha2/extensions");
|
|
901
905
|
extensions = await loadExtensions(wasmUrl);
|
|
906
|
+
await extensions.ready();
|
|
907
|
+
await extensions.prepare(asset.provider);
|
|
902
908
|
own = asset.file
|
|
903
909
|
? new Uint8Array(await asset.file.arrayBuffer())
|
|
904
910
|
: undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Instantiates `alpha2/wasm` once per realm and resolves to its exports.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* failed load is retried by the next call.
|
|
2
|
+
* Instantiates `alpha2/wasm` once per realm and resolves to its exports. Every caller goes through
|
|
3
|
+
* here, since two concurrent wasm-bindgen inits would replace the module's memory under objects
|
|
4
|
+
* made from the first; a failed load is retried by the next call.
|
|
6
5
|
* @param {string | URL | undefined} wasmUrl
|
|
7
6
|
*/
|
|
8
|
-
export function loadEngineWasm(wasmUrl: string | URL | undefined):
|
|
7
|
+
export function loadEngineWasm(wasmUrl: string | URL | undefined): Promise<typeof binding>;
|
|
8
|
+
import * as binding from "alpha2/wasm";
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import init from "alpha2/wasm";
|
|
2
1
|
import * as binding from "alpha2/wasm";
|
|
3
|
-
|
|
2
|
+
import { WasmModule } from "alpha2/wasm-module";
|
|
3
|
+
const engine = new WasmModule(() => import("alpha2/wasm"));
|
|
4
4
|
/**
|
|
5
|
-
* Instantiates `alpha2/wasm` once per realm and resolves to its exports.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* failed load is retried by the next call.
|
|
5
|
+
* Instantiates `alpha2/wasm` once per realm and resolves to its exports. Every caller goes through
|
|
6
|
+
* here, since two concurrent wasm-bindgen inits would replace the module's memory under objects
|
|
7
|
+
* made from the first; a failed load is retried by the next call.
|
|
9
8
|
* @param {string | URL | undefined} wasmUrl
|
|
10
9
|
*/
|
|
11
10
|
export function loadEngineWasm(wasmUrl) {
|
|
12
|
-
|
|
13
|
-
.then(() => binding)
|
|
14
|
-
.catch((error) => {
|
|
15
|
-
loading = null;
|
|
16
|
-
throw error;
|
|
17
|
-
});
|
|
18
|
-
return loading;
|
|
11
|
+
return engine.load(wasmUrl).then(() => binding);
|
|
19
12
|
}
|
package/dist/browser/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { EditorSession } from "../core/session.js";
|
|
|
7
7
|
import type { CapabilityReport, PlaybackPolicy } from "alpha2";
|
|
8
8
|
import type { Capability } from "../ports/index.js";
|
|
9
9
|
import type { Json } from "../core/document.js";
|
|
10
|
+
import type { ExtensionWasmUrls } from "alpha2/extensions";
|
|
10
11
|
import type { ExportJob } from "./jobs.js";
|
|
11
12
|
/** Bundled locations of the runtime's code and data. Each URL defaults to the packaged one. */
|
|
12
13
|
export interface RuntimeAssets {
|
|
@@ -30,8 +31,16 @@ export interface RuntimeAssets {
|
|
|
30
31
|
readonly extensionsWorkerFactory?: () => Worker;
|
|
31
32
|
/** The engine's wasm binary (`alpha2/wasm`). */
|
|
32
33
|
readonly wasmUrl?: string | URL;
|
|
33
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* `alpha2_extensions_bg.wasm`, the core provider module, loaded when an SVG, animated image,
|
|
36
|
+
* Lottie, OpenEXR, image sequence or LaTeX source opens.
|
|
37
|
+
*/
|
|
34
38
|
readonly extensionsWasmUrl?: string | URL;
|
|
39
|
+
/**
|
|
40
|
+
* Other provider modules' `.wasm` files by module name, such as `pdf` for
|
|
41
|
+
* `alpha2_extensions_pdf_bg.wasm`, each loaded when a file it reads is probed or opened.
|
|
42
|
+
*/
|
|
43
|
+
readonly extensionModuleUrls?: ExtensionWasmUrls;
|
|
35
44
|
/** The audio worklet's wasm binary, loaded on the first Play. */
|
|
36
45
|
readonly audioWasmUrl?: string | URL;
|
|
37
46
|
/** The audio worklet processor module. */
|
|
@@ -427,9 +436,8 @@ export interface BrowserBridge {
|
|
|
427
436
|
readonly catalog: BuiltinEffectCatalog | null;
|
|
428
437
|
/**
|
|
429
438
|
* Adds runtime effects and transitions beyond the built-in catalog, addressable by `id@version`.
|
|
430
|
-
* They belong to the bridge, not the document
|
|
431
|
-
*
|
|
432
|
-
* keeps them.
|
|
439
|
+
* They belong to the bridge, not the document, so they outlast loading another project. Each
|
|
440
|
+
* renderer the bridge makes registers them, including a preview remade after GPU loss.
|
|
433
441
|
*
|
|
434
442
|
* With a preview bound, the definitions compile on its device all or none, and the call rejects
|
|
435
443
|
* with `invalid_effect` naming the first one the engine refuses. Without one they are kept
|
|
@@ -537,9 +545,9 @@ export interface BrowserBridge {
|
|
|
537
545
|
/** Stops playback and audio; the playhead stays where it was. */
|
|
538
546
|
pause(): void;
|
|
539
547
|
/**
|
|
540
|
-
* Reads a subtitle file (`.srt`, or `.vtt` for WebVTT) into a captions asset in the bin
|
|
541
|
-
* `skipped` counts blocks that were not cues. Nothing reaches the timeline until
|
|
542
|
-
*
|
|
548
|
+
* Reads a subtitle file (`.srt`, or `.vtt` for WebVTT) into a captions asset in the bin, and
|
|
549
|
+
* `skipped` counts blocks that were not cues. Nothing reaches the timeline until
|
|
550
|
+
* `captionTrackCommands` inserts the asset.
|
|
543
551
|
*
|
|
544
552
|
* Rejects with an `EditorError` `invalid_captions` for a file larger than
|
|
545
553
|
* `MAX_CAPTION_FILE_BYTES` (not read), a WebVTT file without its header, more than
|
|
@@ -646,6 +654,24 @@ export interface BrowserBridge {
|
|
|
646
654
|
setPreviewMedia(media: "original" | "proxies"): void;
|
|
647
655
|
/** What {@link BrowserBridge.setPreviewMedia} last set. */
|
|
648
656
|
readonly previewMedia: "original" | "proxies";
|
|
657
|
+
/**
|
|
658
|
+
* Adds or replaces a source whose provider reads no file, such as `{ format: "latex", ... }`,
|
|
659
|
+
* in one undoable `asset.put`. With an existing `id` its clips keep showing it with the new
|
|
660
|
+
* settings. The source is opened first, so its bin thumbnail and size are known.
|
|
661
|
+
*
|
|
662
|
+
* Rejects with `EditorError` `unsupported_media` for a provider that reads a file (use
|
|
663
|
+
* {@link BrowserBridge.importFiles}), `unreadable_media` when the source does not open, and
|
|
664
|
+
* `stale_import` when the session loads another project meanwhile.
|
|
665
|
+
*/
|
|
666
|
+
putProviderSource(source: {
|
|
667
|
+
readonly id?: string;
|
|
668
|
+
readonly name?: string;
|
|
669
|
+
readonly provider: import("alpha2/project").ProviderSource;
|
|
670
|
+
}, options?: {
|
|
671
|
+
signal?: AbortSignal;
|
|
672
|
+
}): Promise<{
|
|
673
|
+
assetId: string;
|
|
674
|
+
}>;
|
|
649
675
|
/**
|
|
650
676
|
* Shows another animation of a dotLottie source, keeping its clips. Throws `EditorError`
|
|
651
677
|
* `unsupported_media` for another kind of source or an animation the package lacks.
|
package/dist/browser/worker.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Alpha2WasmError, serializeError } from "alpha2/worker-error";
|
|
2
2
|
import { SourcePixels } from "./runtime/sources.js";
|
|
3
|
+
import { extensionWasmUrls } from "./runtime/extension-import.js";
|
|
3
4
|
import { AudioWindowSupplier, mixBlock } from "./runtime/audio.js";
|
|
4
5
|
const INSTALLED = Symbol.for("alpha2.editorWorker");
|
|
5
6
|
/**
|
|
@@ -69,7 +70,7 @@ function serveEditorWorker(scope) {
|
|
|
69
70
|
sessionId = request.sessionId;
|
|
70
71
|
bitmapOutput = request.bitmapOutput === true;
|
|
71
72
|
pixels = new SourcePixels(library, {
|
|
72
|
-
|
|
73
|
+
extensionWasmUrls: extensionWasmUrls(request.runtimeAssets),
|
|
73
74
|
});
|
|
74
75
|
const { Engine } = await import("./runtime/engine.js");
|
|
75
76
|
engine = new Engine(request.canvas ??
|
package/dist/core/document.d.ts
CHANGED
|
@@ -120,6 +120,16 @@ export type Result<T> = {
|
|
|
120
120
|
readonly error: EditorError;
|
|
121
121
|
};
|
|
122
122
|
/** Deep-freezes `value` in place and returns it. Already frozen objects are not descended into. */
|
|
123
|
+
/**
|
|
124
|
+
* Whether a source's media is a file the session must hold. The engine draws generated and
|
|
125
|
+
* composition sources, and a provider that reads no file (such as LaTeX) draws from its settings.
|
|
126
|
+
*/
|
|
127
|
+
export declare function readsMediaFile(source: {
|
|
128
|
+
readonly kind: string;
|
|
129
|
+
readonly provider?: {
|
|
130
|
+
readonly format: string;
|
|
131
|
+
} | null;
|
|
132
|
+
}): boolean;
|
|
123
133
|
export declare function freeze<T>(value: T): T;
|
|
124
134
|
/**
|
|
125
135
|
* The deepest array and object nesting an editor document may have: the engine's project limit
|
package/dist/core/document.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { frozenValid, knownValid, rememberValid, withValidated, } from "./validated.js";
|
|
2
|
-
import { canonicalProject, validateProject, MAX_JSON_DEPTH, MAX_PROJECT_JSON_BYTES, } from "alpha2/project";
|
|
2
|
+
import { canonicalProject, providerReadsFile, validateProject, MAX_JSON_DEPTH, MAX_PROJECT_JSON_BYTES, } from "alpha2/project";
|
|
3
3
|
import { CAPTIONS_ASSET_KIND, validCaptionsAuthoring } from "./captions.js";
|
|
4
4
|
/**
|
|
5
5
|
* The export failure class each editor error code implies (`alpha2/export-failure`). Refusals of
|
|
@@ -92,6 +92,15 @@ export class EditorError extends Error {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
/** Deep-freezes `value` in place and returns it. Already frozen objects are not descended into. */
|
|
95
|
+
/**
|
|
96
|
+
* Whether a source's media is a file the session must hold. The engine draws generated and
|
|
97
|
+
* composition sources, and a provider that reads no file (such as LaTeX) draws from its settings.
|
|
98
|
+
*/
|
|
99
|
+
export function readsMediaFile(source) {
|
|
100
|
+
if (source.kind === "generated" || source.kind === "composition")
|
|
101
|
+
return false;
|
|
102
|
+
return source.provider == null || providerReadsFile(source.provider);
|
|
103
|
+
}
|
|
95
104
|
export function freeze(value) {
|
|
96
105
|
// Iterative, so values nested deeper than the stack are frozen too.
|
|
97
106
|
const pending = [value];
|
|
@@ -319,7 +328,7 @@ function documentOf(project, assets) {
|
|
|
319
328
|
kind: source.kind,
|
|
320
329
|
name: source.id,
|
|
321
330
|
contentRevision: 0,
|
|
322
|
-
missing: source
|
|
331
|
+
missing: readsMediaFile(source),
|
|
323
332
|
},
|
|
324
333
|
])),
|
|
325
334
|
...structuredClone(assets),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpha2-sh/editor",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Headless Project-based editing sessions and browser adapters for alpha2.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"alpha2": "0.5.
|
|
63
|
+
"alpha2": "0.5.3",
|
|
64
64
|
"react": "^19.3.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"alpha2": "0.5.
|
|
67
|
+
"alpha2": "0.5.3",
|
|
68
68
|
"react": "19.3.0",
|
|
69
69
|
"react-dom": "19.3.0",
|
|
70
70
|
"@types/react": "19.3.0",
|