@alpha2-sh/editor 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/bridge.js +40 -16
- package/dist/browser/runtime/engine.d.ts +7 -2
- package/dist/browser/runtime/engine.js +27 -6
- package/dist/browser/runtime/exporter.d.ts +3 -0
- package/dist/browser/runtime/exporter.js +14 -0
- package/dist/browser/runtime/sources.d.ts +17 -6
- package/dist/browser/runtime/sources.js +114 -9
- package/dist/browser/types.d.ts +25 -1
- package/dist/browser/worker.js +1 -1
- package/dist/core/commands.d.ts +11 -2
- package/dist/core/commands.js +4 -3
- package/dist/core/compositions.d.ts +25 -16
- package/dist/core/compositions.js +5 -2
- package/dist/core/document.d.ts +30 -7
- package/dist/core/document.js +25 -7
- package/dist/core/session.d.ts +10 -1
- package/dist/core/session.js +3 -3
- package/dist/ports/index.d.ts +4 -2
- package/package.json +3 -3
package/dist/browser/bridge.js
CHANGED
|
@@ -215,7 +215,10 @@ export function createBrowserBridge(options) {
|
|
|
215
215
|
};
|
|
216
216
|
/** The engine's asset decisions, from the wasm module, loaded on first use. */
|
|
217
217
|
const decisions = async () => (decisionBinding ??= await loadWasm());
|
|
218
|
-
/**
|
|
218
|
+
/**
|
|
219
|
+
* What `measureText` and `measureLayout` lay text out with, made on first use, and the font
|
|
220
|
+
* stack it holds.
|
|
221
|
+
*/
|
|
219
222
|
let measurer = null, measuredFonts = null;
|
|
220
223
|
const registry = new ResourceRegistry(resourceLimit);
|
|
221
224
|
/**
|
|
@@ -675,6 +678,24 @@ export function createBrowserBridge(options) {
|
|
|
675
678
|
function heldFonts(document) {
|
|
676
679
|
return Object.values(document.assets).filter((a) => a.kind === "font" && !a.missing && ownerOf(document, a));
|
|
677
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Readies `measurer` with the fonts preview draws the draft with, and answers the draft's canvas
|
|
683
|
+
* size, which preview draws it at.
|
|
684
|
+
*/
|
|
685
|
+
async function draftMeasurer() {
|
|
686
|
+
const { WasmTextMeasurer } = await loadWasm();
|
|
687
|
+
if (disposed)
|
|
688
|
+
throw new EditorError("disposed", "Bridge is disposed", "browser");
|
|
689
|
+
const document = editor.draft;
|
|
690
|
+
const fonts = fontStackOf(document);
|
|
691
|
+
measurer ??= new WasmTextMeasurer();
|
|
692
|
+
if (!sameList(measuredFonts, fonts)) {
|
|
693
|
+
// A font the engine refuses is left out here as preview leaves it out, and reported there.
|
|
694
|
+
registerCaptionFonts(measurer, fonts);
|
|
695
|
+
measuredFonts = fonts;
|
|
696
|
+
}
|
|
697
|
+
return document.project.settings;
|
|
698
|
+
}
|
|
678
699
|
const sameList = (a, b) => a !== null &&
|
|
679
700
|
a.length === b.length &&
|
|
680
701
|
a.every((item, index) => item === b[index]);
|
|
@@ -1302,7 +1323,9 @@ export function createBrowserBridge(options) {
|
|
|
1302
1323
|
workerPreview = null;
|
|
1303
1324
|
workerDiagnostics = null;
|
|
1304
1325
|
const useWorker = features.worker.available && typeof canvas.getContext === "function";
|
|
1305
|
-
engine = new Engine(useWorker ? new OffscreenCanvas(canvas.width, canvas.height) : canvas, sources, library, runtimeAssets
|
|
1326
|
+
engine = new Engine(useWorker ? new OffscreenCanvas(canvas.width, canvas.height) : canvas, sources, library, runtimeAssets,
|
|
1327
|
+
// A frame shown at once matters more in a preview than the engine's conversion of it.
|
|
1328
|
+
{ unreadableFrames: "present" });
|
|
1306
1329
|
mixer = new EngineAudioMixer(runtimeAssets, { enabled: audio });
|
|
1307
1330
|
mixer.setMasterVolume(monitorVolume);
|
|
1308
1331
|
stalledAudio = null;
|
|
@@ -1737,6 +1760,9 @@ export function createBrowserBridge(options) {
|
|
|
1737
1760
|
if (jobs.size)
|
|
1738
1761
|
throw new EditorError("export_busy", "Only one export may run per bridge", "export");
|
|
1739
1762
|
requireExportFrameRate(options.frameRate);
|
|
1763
|
+
const videoDecode = options.videoDecode ?? "auto";
|
|
1764
|
+
if (videoDecode !== "auto" && videoDecode !== "software")
|
|
1765
|
+
throw new EditorError("invalid_video_decode", `Export videoDecode must be "auto" or "software"; received ${JSON.stringify(videoDecode)}`, "export");
|
|
1740
1766
|
materializeText(editor.document);
|
|
1741
1767
|
const snapshot = editor.document, revision = editor.revision, effects = keptEffects();
|
|
1742
1768
|
const compiled = compileEditorDocument(snapshot);
|
|
@@ -1782,6 +1808,7 @@ export function createBrowserBridge(options) {
|
|
|
1782
1808
|
const project = compiled.project, lib = { get: (id) => map.get(id) };
|
|
1783
1809
|
const pixels = new SourcePixels(lib, {
|
|
1784
1810
|
extensionsWasmUrl: runtimeAssets.extensionsWasmUrl,
|
|
1811
|
+
videoDecode,
|
|
1785
1812
|
});
|
|
1786
1813
|
const renderer = new Engine(new OffscreenCanvas(project.settings.width, project.settings.height), pixels, lib, runtimeAssets);
|
|
1787
1814
|
const audio = new AudioWindowSupplier(lib);
|
|
@@ -1854,7 +1881,11 @@ export function createBrowserBridge(options) {
|
|
|
1854
1881
|
return {
|
|
1855
1882
|
...artifact,
|
|
1856
1883
|
media: Object.fromEntries(selection),
|
|
1857
|
-
report: {
|
|
1884
|
+
report: {
|
|
1885
|
+
...result,
|
|
1886
|
+
videoDecode,
|
|
1887
|
+
decodeFallbacks: pixels.decodeFallbacks,
|
|
1888
|
+
},
|
|
1858
1889
|
};
|
|
1859
1890
|
}
|
|
1860
1891
|
finally {
|
|
@@ -2024,21 +2055,14 @@ export function createBrowserBridge(options) {
|
|
|
2024
2055
|
return families;
|
|
2025
2056
|
},
|
|
2026
2057
|
async measureText(generator) {
|
|
2027
|
-
const {
|
|
2028
|
-
if (disposed)
|
|
2029
|
-
throw new EditorError("disposed", "Bridge is disposed", "browser");
|
|
2030
|
-
// The fonts and canvas preview draws the draft with.
|
|
2031
|
-
const document = editor.draft;
|
|
2032
|
-
const fonts = fontStackOf(document);
|
|
2033
|
-
measurer ??= new WasmTextMeasurer();
|
|
2034
|
-
if (!sameList(measuredFonts, fonts)) {
|
|
2035
|
-
// A font the engine refuses is left out here as preview leaves it out, and reported there.
|
|
2036
|
-
registerCaptionFonts(measurer, fonts);
|
|
2037
|
-
measuredFonts = fonts;
|
|
2038
|
-
}
|
|
2039
|
-
const { width, height } = document.project.settings;
|
|
2058
|
+
const { width, height } = await draftMeasurer();
|
|
2040
2059
|
return JSON.parse(measurer.measure(JSON.stringify(generator), width, height));
|
|
2041
2060
|
},
|
|
2061
|
+
async measureLayout(generator, time = 0) {
|
|
2062
|
+
const { width, height } = await draftMeasurer();
|
|
2063
|
+
// Measured at the canvas size, which its pixel lengths are pixels of.
|
|
2064
|
+
return JSON.parse(measurer.measureLayout(JSON.stringify(generator), width, height, time, width, height));
|
|
2065
|
+
},
|
|
2042
2066
|
conform,
|
|
2043
2067
|
/**
|
|
2044
2068
|
* Makes a proxy of a source whose original this session holds, keeps it, and previews from it
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* render queue that collapses to the newest request.
|
|
4
4
|
*/
|
|
5
5
|
export class Engine {
|
|
6
|
-
constructor(canvas: any, sources: any, library: any, runtimeAssets?: {});
|
|
6
|
+
constructor(canvas: any, sources: any, library: any, runtimeAssets?: {}, { unreadableFrames }?: {});
|
|
7
7
|
runtimeAssets: {};
|
|
8
|
+
/** What the frame supply does with a frame the browser cannot read back (`FrameSupply`). */
|
|
9
|
+
unreadableFrames: any;
|
|
8
10
|
canvas: any;
|
|
9
11
|
sources: any;
|
|
10
12
|
library: any;
|
|
@@ -42,7 +44,10 @@ export class Engine {
|
|
|
42
44
|
audible(policy: any, rate: any): boolean;
|
|
43
45
|
get ready(): boolean;
|
|
44
46
|
get deviceLost(): any;
|
|
45
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Raw source video the frame supply copied through script memory, and the frames it could not
|
|
49
|
+
* read back and how it recovered them; cumulative.
|
|
50
|
+
*/
|
|
46
51
|
get sourceTransfer(): any;
|
|
47
52
|
/** The wasm object, for callers that drive audio directly. */
|
|
48
53
|
get wasm(): null;
|
|
@@ -34,8 +34,10 @@ export class Engine {
|
|
|
34
34
|
#unchanged = 0;
|
|
35
35
|
/** What `supply` uploaded for the export frame the engine has not rendered yet. */
|
|
36
36
|
#exportUploads = [];
|
|
37
|
-
constructor(canvas, sources, library, runtimeAssets = {}) {
|
|
37
|
+
constructor(canvas, sources, library, runtimeAssets = {}, { unreadableFrames } = {}) {
|
|
38
38
|
this.runtimeAssets = runtimeAssets;
|
|
39
|
+
/** What the frame supply does with a frame the browser cannot read back (`FrameSupply`). */
|
|
40
|
+
this.unreadableFrames = unreadableFrames;
|
|
39
41
|
this.canvas = canvas;
|
|
40
42
|
this.sources = sources;
|
|
41
43
|
this.library = library;
|
|
@@ -58,7 +60,11 @@ export class Engine {
|
|
|
58
60
|
: await WebEffectRegistry.createForHtmlCanvas(this.canvas);
|
|
59
61
|
this.#effectResources = new Map();
|
|
60
62
|
this.#sizeResultCache();
|
|
61
|
-
this.#supply = new FrameSupply(this.#registry
|
|
63
|
+
this.#supply = new FrameSupply(this.#registry, {
|
|
64
|
+
...(this.unreadableFrames === undefined
|
|
65
|
+
? {}
|
|
66
|
+
: { unreadableFrames: this.unreadableFrames }),
|
|
67
|
+
});
|
|
62
68
|
// `engine.traceUploads = true` in the console logs every source upload, to tell a host decode
|
|
63
69
|
// bug from an engine one when a clip shows another clip's picture.
|
|
64
70
|
this.#supply.onUpload = (entry) => {
|
|
@@ -125,11 +131,25 @@ export class Engine {
|
|
|
125
131
|
get deviceLost() {
|
|
126
132
|
return this.#registry?.deviceLost ?? false;
|
|
127
133
|
}
|
|
128
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Raw source video the frame supply copied through script memory, and the frames it could not
|
|
136
|
+
* read back and how it recovered them; cumulative.
|
|
137
|
+
*/
|
|
129
138
|
get sourceTransfer() {
|
|
130
|
-
return
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
return {
|
|
140
|
+
...(this.#supply?.sourceTransfer ?? {
|
|
141
|
+
planarCopyFrames: 0,
|
|
142
|
+
planarCopyBytes: 0,
|
|
143
|
+
}),
|
|
144
|
+
...this.#readbackRecovery(),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
#readbackRecovery() {
|
|
148
|
+
return (this.#supply?.readbackRecovery ?? {
|
|
149
|
+
unreadableFrames: 0,
|
|
150
|
+
readbackRetries: 0,
|
|
151
|
+
redecodedFrames: 0,
|
|
152
|
+
presentedFrames: 0,
|
|
133
153
|
});
|
|
134
154
|
}
|
|
135
155
|
/** The wasm object, for callers that drive audio directly. */
|
|
@@ -411,6 +431,7 @@ export class Engine {
|
|
|
411
431
|
unchanged: this.#unchanged,
|
|
412
432
|
renderSize: [this.canvas.width, this.canvas.height],
|
|
413
433
|
backend: this.backend,
|
|
434
|
+
readbackRecovery: this.#readbackRecovery(),
|
|
414
435
|
};
|
|
415
436
|
this.lastDiagnostics = diagnostics;
|
|
416
437
|
this.onDiagnostics?.(diagnostics);
|
|
@@ -97,6 +97,9 @@ export function exportTimeline({ supplyFrame, renderFrame, sourceTransfer, engin
|
|
|
97
97
|
outputRepackBytes: any;
|
|
98
98
|
sourcePlanarCopyFrames: any;
|
|
99
99
|
sourcePlanarCopyBytes: any;
|
|
100
|
+
sourceUnreadableFrames: any;
|
|
101
|
+
sourceReadbackRetries: any;
|
|
102
|
+
sourceRedecodedFrames: any;
|
|
100
103
|
peakEncodeQueueBytes: any;
|
|
101
104
|
maxPendingMediaEvents: any;
|
|
102
105
|
averagePendingMediaEvents: number;
|
|
@@ -381,6 +381,12 @@ export async function exportTimeline({ supplyFrame, renderFrame, sourceTransfer,
|
|
|
381
381
|
transferAfter.planarCopyFrames - transferBefore.planarCopyFrames;
|
|
382
382
|
metrics.sourcePlanarCopyBytes =
|
|
383
383
|
transferAfter.planarCopyBytes - transferBefore.planarCopyBytes;
|
|
384
|
+
metrics.sourceUnreadableFrames =
|
|
385
|
+
transferAfter.unreadableFrames - transferBefore.unreadableFrames;
|
|
386
|
+
metrics.sourceReadbackRetries =
|
|
387
|
+
transferAfter.readbackRetries - transferBefore.readbackRetries;
|
|
388
|
+
metrics.sourceRedecodedFrames =
|
|
389
|
+
transferAfter.redecodedFrames - transferBefore.redecodedFrames;
|
|
384
390
|
}
|
|
385
391
|
const result = {
|
|
386
392
|
renderMs,
|
|
@@ -577,6 +583,9 @@ function browserExportMetrics() {
|
|
|
577
583
|
outputRepackBytes: 0,
|
|
578
584
|
sourcePlanarCopyFrames: 0,
|
|
579
585
|
sourcePlanarCopyBytes: 0,
|
|
586
|
+
sourceUnreadableFrames: 0,
|
|
587
|
+
sourceReadbackRetries: 0,
|
|
588
|
+
sourceRedecodedFrames: 0,
|
|
580
589
|
peakEncodeQueueBytes: 0,
|
|
581
590
|
maxPendingMediaEvents: 0,
|
|
582
591
|
pendingDepthTotal: 0,
|
|
@@ -615,6 +624,11 @@ function finishBrowserExportMetrics(metrics, before, after) {
|
|
|
615
624
|
outputRepackBytes: metrics.outputRepackBytes,
|
|
616
625
|
sourcePlanarCopyFrames: metrics.sourcePlanarCopyFrames,
|
|
617
626
|
sourcePlanarCopyBytes: metrics.sourcePlanarCopyBytes,
|
|
627
|
+
// Source frames the browser could not read back, the reads repeated, and the frames decoded
|
|
628
|
+
// again in software for it.
|
|
629
|
+
sourceUnreadableFrames: metrics.sourceUnreadableFrames,
|
|
630
|
+
sourceReadbackRetries: metrics.sourceReadbackRetries,
|
|
631
|
+
sourceRedecodedFrames: metrics.sourceRedecodedFrames,
|
|
618
632
|
peakEncodeQueueBytes: metrics.peakEncodeQueueBytes,
|
|
619
633
|
maxPendingMediaEvents: metrics.maxPendingMediaEvents,
|
|
620
634
|
averagePendingMediaEvents: metrics.pendingDepthSamples === 0
|
|
@@ -17,16 +17,24 @@ export const DEFAULT_RASTER_BUDGET_BYTES: number;
|
|
|
17
17
|
export const DEFAULT_PROVIDER_SOURCE_BYTES: number;
|
|
18
18
|
/** The host side of the engine's per-frame source requests for one renderer (preview or export). */
|
|
19
19
|
export class SourcePixels {
|
|
20
|
-
constructor(library: any, { decoderLimit, rasterBudgetBytes, providerSourceBytes, extensionsWasmUrl, }?: {
|
|
20
|
+
constructor(library: any, { decoderLimit, rasterBudgetBytes, providerSourceBytes, extensionsWasmUrl, videoDecode, }?: {
|
|
21
21
|
decoderLimit?: number | undefined;
|
|
22
22
|
rasterBudgetBytes?: number | undefined;
|
|
23
23
|
providerSourceBytes?: number | undefined;
|
|
24
|
+
videoDecode?: string | undefined;
|
|
24
25
|
});
|
|
25
26
|
decoderLimit: number;
|
|
26
27
|
rasterBudgetBytes: number;
|
|
27
28
|
providerSourceBytes: number;
|
|
28
29
|
library: any;
|
|
29
30
|
extensionsWasmUrl: any;
|
|
31
|
+
/**
|
|
32
|
+
* How video decodes: `"auto"` lets the browser pick, a hardware decoder where it has one;
|
|
33
|
+
* `"software"` decodes on the CPU, so no frame needs a GPU readback, except a source the
|
|
34
|
+
* browser has no software decoder for, which decodes as `"auto"` and is reported in
|
|
35
|
+
* `decodeFallbacks`.
|
|
36
|
+
*/
|
|
37
|
+
videoDecode: string;
|
|
30
38
|
get diagnostics(): {
|
|
31
39
|
liveDecoders: number;
|
|
32
40
|
retainedFrameBytes: any;
|
|
@@ -58,16 +66,19 @@ export class SourcePixels {
|
|
|
58
66
|
/**
|
|
59
67
|
* Bound method handed to `FrameSupply` as its `pixelsFor` callback. `sourceId` is the source the
|
|
60
68
|
* engine asked for, which the layer may stand in for (a proxy has an ID of its own): decoders are
|
|
61
|
-
* kept per source, as `release` names them.
|
|
69
|
+
* kept per source, as `release` names them. `decode: "software"` asks for the frame decoded on
|
|
70
|
+
* the CPU (see `#softwareFrame`).
|
|
62
71
|
*/
|
|
63
|
-
pixelsFor: (layer: any, seconds: any, { preferVideoFrame, consumerId, sourceId }?: {
|
|
72
|
+
pixelsFor: (layer: any, seconds: any, { preferVideoFrame, consumerId, sourceId, decode }?: {
|
|
64
73
|
preferVideoFrame?: boolean | undefined;
|
|
65
74
|
consumerId?: any;
|
|
66
75
|
}) => Promise<any>;
|
|
67
76
|
/**
|
|
68
|
-
*
|
|
69
|
-
* how many frames, and whether its decoding stopped for good
|
|
70
|
-
* {@link MAX_DECODE_FAILURES} frames running)
|
|
77
|
+
* What fell back, per source and kind: `"element-seek"`, frames read by element seeks rather
|
|
78
|
+
* than decoded, with the last reason, how many frames, and whether its decoding stopped for good
|
|
79
|
+
* (it could not open, or failed {@link MAX_DECODE_FAILURES} frames running);
|
|
80
|
+
* `"software-unavailable"`, a source `videoDecode: "software"` decoded as `"auto"` because the
|
|
81
|
+
* browser has no software decoder for it (`frames` 0). A browser export reports it.
|
|
71
82
|
*/
|
|
72
83
|
get decodeFallbacks(): any[];
|
|
73
84
|
/** Keeps decoder sessions bounded to consumers needed by the current frame. */
|
|
@@ -53,7 +53,9 @@ export class SourcePixels {
|
|
|
53
53
|
#fonts = [];
|
|
54
54
|
/** What each SVG's pixels are with the fonts it was drawn with, for `contentOf`. */
|
|
55
55
|
#fontContents = new WeakMap();
|
|
56
|
-
constructor(library, { decoderLimit = 32, rasterBudgetBytes = DEFAULT_RASTER_BUDGET_BYTES, providerSourceBytes = DEFAULT_PROVIDER_SOURCE_BYTES, extensionsWasmUrl, } = {}) {
|
|
56
|
+
constructor(library, { decoderLimit = 32, rasterBudgetBytes = DEFAULT_RASTER_BUDGET_BYTES, providerSourceBytes = DEFAULT_PROVIDER_SOURCE_BYTES, extensionsWasmUrl, videoDecode = "auto", } = {}) {
|
|
57
|
+
if (videoDecode !== "auto" && videoDecode !== "software")
|
|
58
|
+
throw new RangeError('videoDecode must be "auto" or "software"');
|
|
57
59
|
if (!Number.isSafeInteger(rasterBudgetBytes) || rasterBudgetBytes <= 0)
|
|
58
60
|
throw new RangeError("rasterBudgetBytes must be a positive integer");
|
|
59
61
|
if (!Number.isSafeInteger(providerSourceBytes) || providerSourceBytes <= 0)
|
|
@@ -63,6 +65,13 @@ export class SourcePixels {
|
|
|
63
65
|
this.providerSourceBytes = providerSourceBytes;
|
|
64
66
|
this.library = library;
|
|
65
67
|
this.extensionsWasmUrl = extensionsWasmUrl;
|
|
68
|
+
/**
|
|
69
|
+
* How video decodes: `"auto"` lets the browser pick, a hardware decoder where it has one;
|
|
70
|
+
* `"software"` decodes on the CPU, so no frame needs a GPU readback, except a source the
|
|
71
|
+
* browser has no software decoder for, which decodes as `"auto"` and is reported in
|
|
72
|
+
* `decodeFallbacks`.
|
|
73
|
+
*/
|
|
74
|
+
this.videoDecode = videoDecode;
|
|
66
75
|
}
|
|
67
76
|
get diagnostics() {
|
|
68
77
|
const decoders = [...this.#decoders.values()]
|
|
@@ -126,10 +135,13 @@ export class SourcePixels {
|
|
|
126
135
|
/**
|
|
127
136
|
* Bound method handed to `FrameSupply` as its `pixelsFor` callback. `sourceId` is the source the
|
|
128
137
|
* engine asked for, which the layer may stand in for (a proxy has an ID of its own): decoders are
|
|
129
|
-
* kept per source, as `release` names them.
|
|
138
|
+
* kept per source, as `release` names them. `decode: "software"` asks for the frame decoded on
|
|
139
|
+
* the CPU (see `#softwareFrame`).
|
|
130
140
|
*/
|
|
131
|
-
pixelsFor = async (layer, seconds, { preferVideoFrame = false, consumerId = layer.id, sourceId } = {}) => {
|
|
141
|
+
pixelsFor = async (layer, seconds, { preferVideoFrame = false, consumerId = layer.id, sourceId, decode } = {}) => {
|
|
132
142
|
const asset = layer.asset ?? layer;
|
|
143
|
+
if (decode === "software")
|
|
144
|
+
return this.#softwareFrame(asset, seconds, consumerId, sourceId ?? asset.id);
|
|
133
145
|
if (asset.provider)
|
|
134
146
|
return this.#providerPixels(asset, providerKey(asset, consumerId), seconds);
|
|
135
147
|
if (asset.kind === "text")
|
|
@@ -480,7 +492,7 @@ export class SourcePixels {
|
|
|
480
492
|
decoder = undefined;
|
|
481
493
|
}
|
|
482
494
|
if (!decoder) {
|
|
483
|
-
if (this.#
|
|
495
|
+
if (this.#cursorCount() >= this.decoderLimit)
|
|
484
496
|
throw Object.assign(new Error("Video decoder budget reached"), {
|
|
485
497
|
code: "resource_budget",
|
|
486
498
|
});
|
|
@@ -501,7 +513,7 @@ export class SourcePixels {
|
|
|
501
513
|
}
|
|
502
514
|
// A decoder that cannot open (a codec the browser cannot decode) is the fallback's for good.
|
|
503
515
|
try {
|
|
504
|
-
decoder.video ??= await (decoder.opening ??=
|
|
516
|
+
decoder.video ??= await (decoder.opening ??= this.#openVideo(decoder));
|
|
505
517
|
}
|
|
506
518
|
catch (error) {
|
|
507
519
|
decoder.opening = null;
|
|
@@ -522,7 +534,7 @@ export class SourcePixels {
|
|
|
522
534
|
// decoder's surfaces do not hold up.
|
|
523
535
|
closeOpened(decoder);
|
|
524
536
|
try {
|
|
525
|
-
decoder.opening =
|
|
537
|
+
decoder.opening = this.#openVideo(decoder);
|
|
526
538
|
decoder.video = await decoder.opening;
|
|
527
539
|
decoded = await decoder.video.refill(request);
|
|
528
540
|
}
|
|
@@ -544,6 +556,96 @@ export class SourcePixels {
|
|
|
544
556
|
chromaSiting: decoded.chromaSiting,
|
|
545
557
|
};
|
|
546
558
|
}
|
|
559
|
+
/** Decoder cursors the budget counts: the software cursors of recovered frames are not. */
|
|
560
|
+
#cursorCount() {
|
|
561
|
+
let count = 0;
|
|
562
|
+
for (const decoder of this.#decoders.values())
|
|
563
|
+
if (!decoder.software)
|
|
564
|
+
count += 1;
|
|
565
|
+
return count;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Opens `decoder`'s source as `videoDecode` says. A source the browser has no software decoder
|
|
569
|
+
* for opens as `"auto"`, for good, and is reported once in `decodeFallbacks`.
|
|
570
|
+
*/
|
|
571
|
+
async #openVideo(decoder) {
|
|
572
|
+
const { asset } = decoder;
|
|
573
|
+
if (this.videoDecode !== "software" || decoder.softwareUnavailable)
|
|
574
|
+
return MediabunnyVideoDecoder.open(asset.id, asset.file);
|
|
575
|
+
try {
|
|
576
|
+
return await MediabunnyVideoDecoder.open(asset.id, asset.file, {
|
|
577
|
+
hardwareAcceleration: "prefer-software",
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
if (error?.code !== "software_decode_unavailable")
|
|
582
|
+
throw error;
|
|
583
|
+
decoder.softwareUnavailable = true;
|
|
584
|
+
const key = `software-unavailable\u0000${decoder.sourceId}`;
|
|
585
|
+
if (!this.#fallbacks.has(key))
|
|
586
|
+
this.#fallbacks.set(key, {
|
|
587
|
+
kind: "software-unavailable",
|
|
588
|
+
sourceId: decoder.sourceId,
|
|
589
|
+
reason: String(error.message),
|
|
590
|
+
frames: 0,
|
|
591
|
+
permanent: false,
|
|
592
|
+
});
|
|
593
|
+
return MediabunnyVideoDecoder.open(asset.id, asset.file);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* The frame at `seconds` decoded on the CPU, on a cursor of its own beside the consumer's: what
|
|
598
|
+
* `FrameSupply` asks for when the browser could not read a hardware frame back. Rejects rather
|
|
599
|
+
* than falling back to an element seek, whose frame would be the browser's again.
|
|
600
|
+
*
|
|
601
|
+
* The cursor shares the consumer's source and consumer IDs, so `retainConsumers` and `release`
|
|
602
|
+
* close it with the consumer's; it stays open between frames, as readback failures come in runs
|
|
603
|
+
* and the next one then decodes on from it.
|
|
604
|
+
*/
|
|
605
|
+
async #softwareFrame(asset, seconds, consumerId, sourceId) {
|
|
606
|
+
if (!asset.file)
|
|
607
|
+
throw new Error(`${asset.id} has no file to decode in software`);
|
|
608
|
+
const cursor = `${decoderCursorKey(sourceId, consumerId)}\u0000software`;
|
|
609
|
+
let decoder = this.#decoders.get(cursor);
|
|
610
|
+
if (decoder && decoder.asset !== asset) {
|
|
611
|
+
await closeDecoder(decoder);
|
|
612
|
+
this.#decoders.delete(cursor);
|
|
613
|
+
decoder = undefined;
|
|
614
|
+
}
|
|
615
|
+
if (!decoder) {
|
|
616
|
+
decoder = {
|
|
617
|
+
sourceId,
|
|
618
|
+
asset,
|
|
619
|
+
consumerId,
|
|
620
|
+
software: true,
|
|
621
|
+
opening: null,
|
|
622
|
+
video: null,
|
|
623
|
+
};
|
|
624
|
+
this.#decoders.set(cursor, decoder);
|
|
625
|
+
}
|
|
626
|
+
try {
|
|
627
|
+
decoder.video ??= await (decoder.opening ??= MediabunnyVideoDecoder.open(asset.id, asset.file, { hardwareAcceleration: "prefer-software" }));
|
|
628
|
+
const decoded = await decoder.video.refill({
|
|
629
|
+
sourceId: asset.id,
|
|
630
|
+
mediaTimeTicks: BigInt(Math.round(seconds * TICKS_PER_SECOND)),
|
|
631
|
+
reason: "prefetch",
|
|
632
|
+
generation: 0,
|
|
633
|
+
});
|
|
634
|
+
return {
|
|
635
|
+
kind: "video-frame",
|
|
636
|
+
frame: decoded.frame,
|
|
637
|
+
rotation: decoded.rotationDegrees ?? 0,
|
|
638
|
+
mirror: decoded.mirror ?? false,
|
|
639
|
+
chromaSiting: decoded.chromaSiting,
|
|
640
|
+
physicalTimeMicroseconds: decoded.frame.timestamp,
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
catch (error) {
|
|
644
|
+
// The next request opens it again.
|
|
645
|
+
closeOpened(decoder);
|
|
646
|
+
throw error;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
547
649
|
/**
|
|
548
650
|
* Records that `decoder`'s frame falls back to an element seek because of `error`; `permanent`
|
|
549
651
|
* applies it to every later frame of the cursor.
|
|
@@ -554,6 +656,7 @@ export class SourcePixels {
|
|
|
554
656
|
const reason = String(error?.message ?? error);
|
|
555
657
|
const known = this.#fallbacks.get(decoder.sourceId);
|
|
556
658
|
this.#fallbacks.set(decoder.sourceId, {
|
|
659
|
+
kind: "element-seek",
|
|
557
660
|
sourceId: decoder.sourceId,
|
|
558
661
|
reason,
|
|
559
662
|
frames: (known?.frames ?? 0) + 1,
|
|
@@ -565,9 +668,11 @@ export class SourcePixels {
|
|
|
565
668
|
return null;
|
|
566
669
|
}
|
|
567
670
|
/**
|
|
568
|
-
*
|
|
569
|
-
* how many frames, and whether its decoding stopped for good
|
|
570
|
-
* {@link MAX_DECODE_FAILURES} frames running)
|
|
671
|
+
* What fell back, per source and kind: `"element-seek"`, frames read by element seeks rather
|
|
672
|
+
* than decoded, with the last reason, how many frames, and whether its decoding stopped for good
|
|
673
|
+
* (it could not open, or failed {@link MAX_DECODE_FAILURES} frames running);
|
|
674
|
+
* `"software-unavailable"`, a source `videoDecode: "software"` decoded as `"auto"` because the
|
|
675
|
+
* browser has no software decoder for it (`frames` 0). A browser export reports it.
|
|
571
676
|
*/
|
|
572
677
|
get decodeFallbacks() {
|
|
573
678
|
return [...this.#fallbacks.values()].map((entry) => ({ ...entry }));
|
package/dist/browser/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Generator, MediaFingerprint, Project } from "alpha2/project";
|
|
2
|
+
import type { LayoutBounds } from "alpha2/layout";
|
|
2
3
|
import type { AssetBinding, ConformReport, MediaPurpose } from "alpha2/assets";
|
|
3
4
|
import type { BuiltinEffectCatalog, EffectDefinition } from "alpha2/effects";
|
|
4
5
|
import type { EditorSession } from "../core/session.js";
|
|
@@ -259,6 +260,16 @@ export interface BrowserExportOptions {
|
|
|
259
260
|
readonly memory?: {
|
|
260
261
|
readonly inFlightBytes?: number;
|
|
261
262
|
};
|
|
263
|
+
/**
|
|
264
|
+
* How source video decodes: `auto` (the default) lets the browser pick, a hardware decoder where
|
|
265
|
+
* it has one; `software` decodes on the CPU, so no frame is read back from the GPU, except a
|
|
266
|
+
* source the browser has no software decoder for, which decodes as `auto` and is reported in the
|
|
267
|
+
* result's `report.decodeFallbacks` (`kind: "software-unavailable"`). Either way the engine
|
|
268
|
+
* converts the same decoded values; a frame the browser cannot read back is decoded again in
|
|
269
|
+
* software. Another value is refused when the export starts, with an `EditorError`
|
|
270
|
+
* `invalid_video_decode`.
|
|
271
|
+
*/
|
|
272
|
+
readonly videoDecode?: "auto" | "software";
|
|
262
273
|
}
|
|
263
274
|
/** Where a browser export writes its file. */
|
|
264
275
|
export type ExportOutputTarget = {
|
|
@@ -532,6 +543,18 @@ export interface BrowserBridge {
|
|
|
532
543
|
measureText(generator: Extract<Generator, {
|
|
533
544
|
type: "text";
|
|
534
545
|
}>): Promise<TextBounds>;
|
|
546
|
+
/**
|
|
547
|
+
* Where every box of a layout generator lies at picture time `time` (whole ticks) and whether
|
|
548
|
+
* anything overflows (see `alpha2/layout`'s `LayoutBounds`): laid out as preview lays it out,
|
|
549
|
+
* with the same fonts, at the draft's canvas size, without rendering. A clip's transform maps
|
|
550
|
+
* these rectangles as it maps the rest of its picture.
|
|
551
|
+
*
|
|
552
|
+
* Rejects a generator that is not a valid layout generator (`INVALID_INPUT`), a layout with text
|
|
553
|
+
* and no fonts to draw it, and once the bridge is disposed (`disposed`).
|
|
554
|
+
*/
|
|
555
|
+
measureLayout(generator: Extract<Generator, {
|
|
556
|
+
type: "layout";
|
|
557
|
+
}>, time?: number): Promise<LayoutBounds>;
|
|
535
558
|
/**
|
|
536
559
|
* The files a native export of `document` (the current one by default) needs, for upload:
|
|
537
560
|
* shown media (or their proxies with `media: "proxies"`), an image sequence's frames, font
|
|
@@ -620,7 +643,8 @@ export interface BrowserBridge {
|
|
|
620
643
|
* decisions must be loaded: call {@link BrowserBridge.conform} first, or pass `assetDecisions`.
|
|
621
644
|
*
|
|
622
645
|
* Throws synchronously when the bridge is disposed (`disposed`), another export runs
|
|
623
|
-
* (`export_busy`), `frameRate` is not one the engine reads (`invalid_frame_rate`),
|
|
646
|
+
* (`export_busy`), `frameRate` is not one the engine reads (`invalid_frame_rate`), `videoDecode`
|
|
647
|
+
* is not `auto` or `software` (`invalid_video_decode`), the asset
|
|
624
648
|
* decisions are not loaded (`conform_pending`), the media is not ready (`ConformError`), or the
|
|
625
649
|
* document does not compile. Everything later is reported through the job's `result`.
|
|
626
650
|
*/
|
package/dist/browser/worker.js
CHANGED
|
@@ -61,7 +61,7 @@ export function installEditorWorker(scope) {
|
|
|
61
61
|
});
|
|
62
62
|
const { Engine } = await import("./runtime/engine.js");
|
|
63
63
|
engine = new Engine(request.canvas ??
|
|
64
|
-
new OffscreenCanvas(request.width ?? 16, request.height ?? 16), pixels, library, request.runtimeAssets);
|
|
64
|
+
new OffscreenCanvas(request.width ?? 16, request.height ?? 16), pixels, library, request.runtimeAssets, { unreadableFrames: "present" });
|
|
65
65
|
audio = new AudioWindowSupplier(library);
|
|
66
66
|
engine.backend = "worker";
|
|
67
67
|
await engine.start();
|
package/dist/core/commands.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { InputKey } from "./compositions.js";
|
|
2
2
|
import type { Project, Clip, Track, ClipEffect, CaptionCue, Composition, CompositionNode, MediaSource, EffectResource } from "alpha2/project";
|
|
3
3
|
import type { EditorDocument, TrackMetadata, ClipMetadata, AssetDescriptor, Marker, Result, GraphLayout, GraphPosition } from "./document.js";
|
|
4
|
+
/**
|
|
5
|
+
* A document while a command is applied to it: its project may hold what the command brought in
|
|
6
|
+
* as written (a CSS hex color, say) until {@link executeCommand} puts the result in the forms the
|
|
7
|
+
* engine writes ({@link canonicalDocument}). An {@link EditorDocument} is one.
|
|
8
|
+
*/
|
|
9
|
+
type DraftDocument = Omit<EditorDocument, "project"> & {
|
|
10
|
+
readonly project: Project;
|
|
11
|
+
};
|
|
4
12
|
/**
|
|
5
13
|
* An edit of an {@link EditorDocument}, run by {@link executeCommand} or
|
|
6
14
|
* `EditorSession.dispatch`. Times are timeline ticks unless a variant says otherwise. Ids that
|
|
@@ -396,9 +404,9 @@ export type Command =
|
|
|
396
404
|
readonly patch: Partial<Pick<EditorDocument["metadata"], "markers" | "exportRange" | "graphLayout" | "graphNames">>;
|
|
397
405
|
};
|
|
398
406
|
/** The names the node editor shows for group compositions, by composition id. */
|
|
399
|
-
export declare function graphNames(document:
|
|
407
|
+
export declare function graphNames(document: DraftDocument): Readonly<Record<string, string>>;
|
|
400
408
|
/** The node editor positions a document stores. */
|
|
401
|
-
export declare function graphLayout(document:
|
|
409
|
+
export declare function graphLayout(document: DraftDocument): GraphLayout;
|
|
402
410
|
/**
|
|
403
411
|
* Applies `command` to `document` and validates the result. `gesture` checks only what a pointer
|
|
404
412
|
* move can change (see `validateDocumentShape`); the gesture validates in full once, when it
|
|
@@ -411,3 +419,4 @@ export declare function graphLayout(document: EditorDocument): GraphLayout;
|
|
|
411
419
|
export declare function executeCommand(document: EditorDocument, command: Command, { gesture }?: {
|
|
412
420
|
gesture?: boolean;
|
|
413
421
|
}): Result<EditorDocument>;
|
|
422
|
+
export {};
|
package/dist/core/commands.js
CHANGED
|
@@ -2,7 +2,7 @@ import { addTransition, resizeTransition, removeTransition, } from "./transition
|
|
|
2
2
|
import * as edit from "alpha2/edit";
|
|
3
3
|
import { drawnEffectResources, effectStack, findComposition, freeCompositionId, freeNodeId, groupNodes, ungroupNode, acceptsInput, correspondingCompositions, ownComposition, withEffectStack, withoutUndrawn, withInput, withoutNodes, shownSources, } from "./compositions.js";
|
|
4
4
|
import { rememberValid, withValidated } from "./validated.js";
|
|
5
|
-
import { EditorError, validateDocument, validateDocumentShape, assertProjection, indexDocument, transitionInstanceId, withInstanceIds, } from "./document.js";
|
|
5
|
+
import { EditorError, validateDocument, validateDocumentShape, canonicalDocument, assertProjection, indexDocument, transitionInstanceId, withInstanceIds, } from "./document.js";
|
|
6
6
|
const NO_NAMES = Object.freeze({});
|
|
7
7
|
/** The names the node editor shows for group compositions, by composition id. */
|
|
8
8
|
export function graphNames(document) {
|
|
@@ -1095,9 +1095,10 @@ export function executeCommand(document, command, { gesture = false } = {}) {
|
|
|
1095
1095
|
const reduced = apply(document, structuredClone(command));
|
|
1096
1096
|
// A clip owns the composition it shows: what the command stopped drawing goes.
|
|
1097
1097
|
const undrawn = withoutUndrawn(document.project, reduced.project);
|
|
1098
|
-
|
|
1098
|
+
// What the command brought in is put in the forms the engine writes, as all of a document is.
|
|
1099
|
+
const next = withInstanceIds(canonicalDocument(withoutGraphs(undrawn.removed.size
|
|
1099
1100
|
? { ...reduced, project: undrawn.project }
|
|
1100
|
-
: reduced, undrawn.removed));
|
|
1101
|
+
: reduced, undrawn.removed)));
|
|
1101
1102
|
if (gesture) {
|
|
1102
1103
|
validateDocumentShape(next);
|
|
1103
1104
|
assertProjection(next);
|
|
@@ -6,12 +6,21 @@ export interface StackEntry {
|
|
|
6
6
|
readonly effect: ClipEffect;
|
|
7
7
|
readonly bypass: boolean;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* A composition of `P`: in the forms the engine writes when `P` is a document's `CanonicalProject`,
|
|
11
|
+
* as written when `P` is a `Project`. The helpers below return parts in the form their input has:
|
|
12
|
+
* they rearrange what they are given, and what they add (ids, inputs, effect and group nodes) holds
|
|
13
|
+
* no color or paint, so a canonical project stays canonical through them.
|
|
14
|
+
*/
|
|
15
|
+
export type CompositionOf<P extends Project> = NonNullable<P["compositions"]>[number];
|
|
16
|
+
/** A clip of `P`, in the form `P` holds it (see {@link CompositionOf}). */
|
|
17
|
+
export type ClipOf<P extends Project> = NonNullable<P["timeline"]["tracks"][number]["clips"]>[number];
|
|
9
18
|
/**
|
|
10
19
|
* The composition `id` names in `project`. Looked up in an index of the project's compositions
|
|
11
20
|
* array, made once per array, so walks that find many compositions stay linear. An index a changed
|
|
12
21
|
* array no longer matches is made again, and an id it lacks is looked for in the array itself.
|
|
13
22
|
*/
|
|
14
|
-
export declare function findComposition(project:
|
|
23
|
+
export declare function findComposition<P extends Project>(project: P, id: string): CompositionOf<P> | undefined;
|
|
15
24
|
/**
|
|
16
25
|
* A clip's effects as a stack: its composition when that is the clip's picture through a chain of
|
|
17
26
|
* effect nodes and nothing else, bottom first. A clip without a composition has an empty stack.
|
|
@@ -27,12 +36,12 @@ export declare function freeCompositionId(project: Project, base: string): strin
|
|
|
27
36
|
* keeps its id and the clip its time mapping; a clip without one gets `<clip id>-fx`.
|
|
28
37
|
* Throws when `clipId` names no clip.
|
|
29
38
|
*/
|
|
30
|
-
export declare function withEffectStack(project:
|
|
39
|
+
export declare function withEffectStack<P extends Project>(project: P, clipId: string, stack: readonly StackEntry[]): P;
|
|
31
40
|
/**
|
|
32
41
|
* The compositions `id` draws: itself and, through group nodes, the group definitions it uses, each
|
|
33
42
|
* once.
|
|
34
43
|
*/
|
|
35
|
-
export declare function compositionTree(project:
|
|
44
|
+
export declare function compositionTree<P extends Project>(project: P, id: string): CompositionOf<P>[];
|
|
36
45
|
/**
|
|
37
46
|
* Ids of the compositions `project` draws: those clips show and composition sources show (Library
|
|
38
47
|
* items), and those these use through group nodes and composition sources, as far as they go.
|
|
@@ -45,8 +54,8 @@ export declare function drawnCompositions(project: Project): Set<string>;
|
|
|
45
54
|
* and the group definitions only it drew with it. A composition `before` did not draw stays, so one
|
|
46
55
|
* added for a later edit (a macro's definition) waits for it. Returns the ids it removed.
|
|
47
56
|
*/
|
|
48
|
-
export declare function withoutUndrawn(before: Project, after:
|
|
49
|
-
readonly project:
|
|
57
|
+
export declare function withoutUndrawn<P extends Project>(before: Project, after: P): {
|
|
58
|
+
readonly project: P;
|
|
50
59
|
readonly removed: ReadonlySet<string>;
|
|
51
60
|
};
|
|
52
61
|
/**
|
|
@@ -57,9 +66,9 @@ export declare function withoutUndrawn(before: Project, after: Project): {
|
|
|
57
66
|
* does. A copy takes free ids based on `<root>~<clip id>` ({@link copyComposition}), so the clip is
|
|
58
67
|
* edited independently of its original. Returns the copies' ids by their originals'.
|
|
59
68
|
*/
|
|
60
|
-
export declare function ownComposition(project:
|
|
61
|
-
readonly project:
|
|
62
|
-
readonly clip:
|
|
69
|
+
export declare function ownComposition<P extends Project>(project: P, clip: ClipOf<P>, compositions?: readonly CompositionOf<P>[]): {
|
|
70
|
+
readonly project: P;
|
|
71
|
+
readonly clip: ClipOf<P>;
|
|
63
72
|
readonly copies: ReadonlyMap<string, string>;
|
|
64
73
|
};
|
|
65
74
|
/**
|
|
@@ -147,12 +156,12 @@ export declare function acceptsInput(op: CompositionNode["op"], key: InputKey):
|
|
|
147
156
|
* An effect's named input is added when it has none of the name. Throws when `op` cannot take
|
|
148
157
|
* input `key`.
|
|
149
158
|
*/
|
|
150
|
-
export declare function withInput
|
|
159
|
+
export declare function withInput<O extends CompositionNode["op"]>(op: O, key: InputKey, node: string | null): O;
|
|
151
160
|
/**
|
|
152
161
|
* `op` without its effect input `name`; an effect left with none has no `inputs`, as the model
|
|
153
162
|
* writes it. Any other operation is returned as it is.
|
|
154
163
|
*/
|
|
155
|
-
export declare function withoutEffectInput
|
|
164
|
+
export declare function withoutEffectInput<O extends CompositionNode["op"]>(op: O, name: string): O;
|
|
156
165
|
/**
|
|
157
166
|
* How a composition is drawn, which decides what its clip nodes and group inputs read, as the
|
|
158
167
|
* engine plans it.
|
|
@@ -217,7 +226,7 @@ export declare function freeNodeId(composition: Composition, base: string): stri
|
|
|
217
226
|
* `composition` without the nodes `ids`, every input that read one of them disconnected, no output
|
|
218
227
|
* if it was one of them, and no control that exposed one of them.
|
|
219
228
|
*/
|
|
220
|
-
export declare function withoutNodes(composition:
|
|
229
|
+
export declare function withoutNodes<C extends Composition>(composition: C, ids: readonly string[]): C;
|
|
221
230
|
/**
|
|
222
231
|
* `composition` with nodes `ids` folded into a group node `groupId` that draws a new composition
|
|
223
232
|
* `definitionId` of them: each node outside the selection that a selected node reads becomes one of
|
|
@@ -229,9 +238,9 @@ export declare function withoutNodes(composition: Composition, ids: readonly str
|
|
|
229
238
|
* @throws When the selection is empty or only group inputs, names an absent node, `groupId` names
|
|
230
239
|
* an unselected node, or other than one selected node's picture leaves the selection.
|
|
231
240
|
*/
|
|
232
|
-
export declare function groupNodes(composition:
|
|
233
|
-
readonly parent:
|
|
234
|
-
readonly definition:
|
|
241
|
+
export declare function groupNodes<C extends Composition>(composition: C, ids: readonly string[], groupId: string, definitionId: string): {
|
|
242
|
+
readonly parent: C;
|
|
243
|
+
readonly definition: C;
|
|
235
244
|
};
|
|
236
245
|
/**
|
|
237
246
|
* `composition` with group node `groupId` replaced by the nodes of the composition it draws, under
|
|
@@ -240,7 +249,7 @@ export declare function groupNodes(composition: Composition, ids: readonly strin
|
|
|
240
249
|
* the new ids by inner id. The picture does not change.
|
|
241
250
|
* Throws when `groupId` is not a group node of `composition`.
|
|
242
251
|
*/
|
|
243
|
-
export declare function ungroupNode(composition:
|
|
244
|
-
readonly parent:
|
|
252
|
+
export declare function ungroupNode<C extends Composition>(composition: C, groupId: string, definition: C): {
|
|
253
|
+
readonly parent: C;
|
|
245
254
|
readonly ids: ReadonlyMap<string, string>;
|
|
246
255
|
};
|
|
@@ -557,6 +557,9 @@ export function acceptsInput(op, key) {
|
|
|
557
557
|
* input `key`.
|
|
558
558
|
*/
|
|
559
559
|
export function withInput(op, key, node) {
|
|
560
|
+
return opWithInput(op, key, node);
|
|
561
|
+
}
|
|
562
|
+
function opWithInput(op, key, node) {
|
|
560
563
|
if (!acceptsInput(op, key))
|
|
561
564
|
throw new Error(`A ${op.type} node has no input ${String(key)}`);
|
|
562
565
|
const name = effectInputName(key);
|
|
@@ -583,7 +586,7 @@ export function withoutEffectInput(op, name) {
|
|
|
583
586
|
return op;
|
|
584
587
|
const { [name]: _removed, ...rest } = op.inputs;
|
|
585
588
|
const { inputs: _inputs, ...without } = op;
|
|
586
|
-
return Object.keys(rest).length > 0 ? { ...without, inputs: rest } : without;
|
|
589
|
+
return (Object.keys(rest).length > 0 ? { ...without, inputs: rest } : without);
|
|
587
590
|
}
|
|
588
591
|
/**
|
|
589
592
|
* What stops `composition`'s output from rendering when it is drawn as `use`: no output, an
|
|
@@ -825,7 +828,7 @@ export function groupNodes(composition, ids, groupId, definitionId) {
|
|
|
825
828
|
],
|
|
826
829
|
output: composition.output === output ? groupId : (composition.output ?? null),
|
|
827
830
|
};
|
|
828
|
-
return { parent, definition };
|
|
831
|
+
return { parent: parent, definition: definition };
|
|
829
832
|
}
|
|
830
833
|
/**
|
|
831
834
|
* `composition` with group node `groupId` replaced by the nodes of the composition it draws, under
|
package/dist/core/document.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExportFailureCode } from "alpha2/export-failure";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Canonical, CanonicalProject } from "alpha2/project";
|
|
3
|
+
import type { ClipTransition, MediaFingerprint, Project, Track, ProjectSettings, TimeRange } from "alpha2/project";
|
|
3
4
|
/** A JSON value: what editor metadata and asset authoring data may hold. */
|
|
4
5
|
export type Json = null | boolean | number | string | readonly Json[] | {
|
|
5
6
|
readonly [key: string]: Json;
|
|
@@ -93,7 +94,13 @@ export interface EditorMetadata {
|
|
|
93
94
|
export interface EditorDocument {
|
|
94
95
|
readonly format: "alpha2-editor-project";
|
|
95
96
|
readonly version: 1;
|
|
96
|
-
|
|
97
|
+
/**
|
|
98
|
+
* The engine project, in the forms the engine writes ({@link CanonicalProject}): every color the
|
|
99
|
+
* components object, every paint tagged, padding and margin the four sides, an offset `{ x, y }`.
|
|
100
|
+
* A document is put in this form wherever it enters the editor (opened, created, or made by a
|
|
101
|
+
* command), so reading it never meets CSS hex or a color standing for a paint.
|
|
102
|
+
*/
|
|
103
|
+
readonly project: CanonicalProject;
|
|
97
104
|
readonly metadata: EditorMetadata;
|
|
98
105
|
readonly assets: Readonly<Record<string, AssetDescriptor>>;
|
|
99
106
|
}
|
|
@@ -189,6 +196,17 @@ export declare function parseDocument(text: string): EditorDocument;
|
|
|
189
196
|
* do (a split hands an outgoing transition to the right part).
|
|
190
197
|
*/
|
|
191
198
|
export declare function transitionInstanceId(trackId: string, transition: Pick<ClipTransition, "from_clip" | "to_clip">): string;
|
|
199
|
+
/**
|
|
200
|
+
* `document` with its project in the forms the engine writes ({@link canonicalProject}): every
|
|
201
|
+
* color the components object, every paint tagged, padding and margin the four sides, an offset
|
|
202
|
+
* `{ x, y }`. Returns `document` itself when its project is already in that form, shares the parts
|
|
203
|
+
* that are, and leaves a document of the wrong shape, or a value it cannot read, for validation to
|
|
204
|
+
* refuse. Each place a document enters the editor puts it in this form, so the editor's own code
|
|
205
|
+
* and its callers read one form.
|
|
206
|
+
*/
|
|
207
|
+
export declare function canonicalDocument(document: Omit<EditorDocument, "project"> & {
|
|
208
|
+
readonly project: Project;
|
|
209
|
+
}): EditorDocument;
|
|
192
210
|
/**
|
|
193
211
|
* `document` with an instance id for every caption cue, transition and clip mask: each track's
|
|
194
212
|
* transitions named by {@link transitionInstanceId}; cues and masks keep the ids they have, and
|
|
@@ -196,16 +214,21 @@ export declare function transitionInstanceId(trackId: string, transition: Pick<C
|
|
|
196
214
|
* changes, and leaves a document of the wrong shape for validation to refuse.
|
|
197
215
|
*/
|
|
198
216
|
export declare function withInstanceIds(document: EditorDocument): EditorDocument;
|
|
199
|
-
/**
|
|
200
|
-
|
|
201
|
-
|
|
217
|
+
/**
|
|
218
|
+
* A document's tracks and clips by id: of an {@link EditorDocument}, in the forms the engine writes
|
|
219
|
+
* (`Canonical<Track>`).
|
|
220
|
+
*/
|
|
221
|
+
export interface EntityIndex<T extends Track = Canonical<Track>> {
|
|
222
|
+
readonly tracks: ReadonlyMap<string, T>;
|
|
202
223
|
readonly clips: ReadonlyMap<string, {
|
|
203
|
-
readonly clip:
|
|
224
|
+
readonly clip: NonNullable<T["clips"]>[number];
|
|
204
225
|
readonly trackId: string;
|
|
205
226
|
}>;
|
|
206
227
|
}
|
|
207
228
|
/** The {@link EntityIndex} of `document`, built once per document object and cached. */
|
|
208
|
-
export declare function indexDocument
|
|
229
|
+
export declare function indexDocument<D extends {
|
|
230
|
+
readonly project: Project;
|
|
231
|
+
}>(document: D): EntityIndex<D["project"]["timeline"]["tracks"][number]>;
|
|
209
232
|
/** What the engine renders of a document. */
|
|
210
233
|
export interface CompiledEditorDocument {
|
|
211
234
|
/**
|
package/dist/core/document.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { frozenValid, knownValid, rememberValid, withValidated, } from "./validated.js";
|
|
2
|
-
import { validateProject, MAX_JSON_DEPTH, MAX_PROJECT_JSON_BYTES, } from "alpha2/project";
|
|
2
|
+
import { canonicalProject, 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 is evidence of (`alpha2/export-failure`): a
|
|
@@ -35,6 +35,7 @@ const EDITOR_FAILURE_CODES = Object.freeze({
|
|
|
35
35
|
invalid_rate: "INVALID_INPUT",
|
|
36
36
|
invalid_time: "INVALID_INPUT",
|
|
37
37
|
invalid_transition: "INVALID_INPUT",
|
|
38
|
+
invalid_video_decode: "INVALID_INPUT",
|
|
38
39
|
locked: "INVALID_INPUT",
|
|
39
40
|
missing_asset: "INVALID_INPUT",
|
|
40
41
|
preview_worker_failed: "UNKNOWN",
|
|
@@ -299,7 +300,7 @@ export function createDocument(project, assets = {}) {
|
|
|
299
300
|
return withValidated(() => {
|
|
300
301
|
assertJson(project, MAX_JSON_DEPTH);
|
|
301
302
|
// Frozen before validation, so validated parts are reused when edits check them.
|
|
302
|
-
const copy = freeze(structuredClone(project));
|
|
303
|
+
const copy = freeze(canonicalProject(structuredClone(project)));
|
|
303
304
|
if (!knownValid(project)) {
|
|
304
305
|
const errors = validateProject(copy);
|
|
305
306
|
if (errors.length)
|
|
@@ -383,7 +384,7 @@ export function parseDocument(text) {
|
|
|
383
384
|
try {
|
|
384
385
|
if (isRecord(data) && "schema_version" in data)
|
|
385
386
|
return createDocument(data);
|
|
386
|
-
const document = freeze(withInstanceIds(data));
|
|
387
|
+
const document = freeze(withInstanceIds(canonicalDocument(data)));
|
|
387
388
|
validateDocument(document);
|
|
388
389
|
return frozenValid(document);
|
|
389
390
|
}
|
|
@@ -402,6 +403,23 @@ export function parseDocument(text) {
|
|
|
402
403
|
export function transitionInstanceId(trackId, transition) {
|
|
403
404
|
return `${trackId}/transitions/${encodeURIComponent(transition.from_clip)}/${encodeURIComponent(transition.to_clip)}`;
|
|
404
405
|
}
|
|
406
|
+
/**
|
|
407
|
+
* `document` with its project in the forms the engine writes ({@link canonicalProject}): every
|
|
408
|
+
* color the components object, every paint tagged, padding and margin the four sides, an offset
|
|
409
|
+
* `{ x, y }`. Returns `document` itself when its project is already in that form, shares the parts
|
|
410
|
+
* that are, and leaves a document of the wrong shape, or a value it cannot read, for validation to
|
|
411
|
+
* refuse. Each place a document enters the editor puts it in this form, so the editor's own code
|
|
412
|
+
* and its callers read one form.
|
|
413
|
+
*/
|
|
414
|
+
export function canonicalDocument(document) {
|
|
415
|
+
const project = document?.project;
|
|
416
|
+
if (!isRecord(project))
|
|
417
|
+
return document;
|
|
418
|
+
const canonical = canonicalProject(project);
|
|
419
|
+
return canonical === project
|
|
420
|
+
? document
|
|
421
|
+
: { ...document, project: canonical };
|
|
422
|
+
}
|
|
405
423
|
/**
|
|
406
424
|
* Frozen tracks and clips {@link withInstanceIds} found named as they are in a frozen `instanceIds`
|
|
407
425
|
* record.
|
|
@@ -512,9 +530,9 @@ export function withInstanceIds(document) {
|
|
|
512
530
|
const indexes = new WeakMap();
|
|
513
531
|
/** The {@link EntityIndex} of `document`, built once per document object and cached. */
|
|
514
532
|
export function indexDocument(document) {
|
|
515
|
-
|
|
516
|
-
if (
|
|
517
|
-
return
|
|
533
|
+
const known = indexes.get(document);
|
|
534
|
+
if (known)
|
|
535
|
+
return known;
|
|
518
536
|
const tracks = new Map();
|
|
519
537
|
const clips = new Map();
|
|
520
538
|
for (const track of document.project.timeline.tracks) {
|
|
@@ -522,7 +540,7 @@ export function indexDocument(document) {
|
|
|
522
540
|
for (const clip of track.clips ?? [])
|
|
523
541
|
clips.set(clip.id, { clip, trackId: track.id });
|
|
524
542
|
}
|
|
525
|
-
index = { tracks, clips };
|
|
543
|
+
const index = { tracks, clips };
|
|
526
544
|
indexes.set(document, index);
|
|
527
545
|
return index;
|
|
528
546
|
}
|
package/dist/core/session.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Clip } from "alpha2/project";
|
|
1
2
|
import type { EditorDocument, Result } from "./document.js";
|
|
2
3
|
import type { Command } from "./commands.js";
|
|
3
4
|
/** An immutable view of an {@link EditorSession}; a new object after every change. */
|
|
@@ -96,7 +97,15 @@ export declare class EditorSession {
|
|
|
96
97
|
*/
|
|
97
98
|
select(ids: readonly string[]): void;
|
|
98
99
|
/** The committed document's tracks and clips by id. */
|
|
99
|
-
query(): import("./document.js").EntityIndex
|
|
100
|
+
query(): import("./document.js").EntityIndex<{
|
|
101
|
+
readonly audio?: import("alpha2/project").Canonical<import("alpha2/project").TrackAudio | undefined>;
|
|
102
|
+
readonly captions?: import("alpha2/project").Canonical<import("alpha2/project").Captions | null | undefined>;
|
|
103
|
+
readonly clips?: import("alpha2/project").Canonical<readonly Clip[] | undefined>;
|
|
104
|
+
readonly id: import("alpha2/project").TrackId;
|
|
105
|
+
readonly kind: import("alpha2/project").Canonical<import("alpha2/project").TrackKind>;
|
|
106
|
+
readonly name: string;
|
|
107
|
+
readonly transitions?: import("alpha2/project").Canonical<readonly import("alpha2/project").ClipTransition[] | undefined>;
|
|
108
|
+
}>;
|
|
100
109
|
/**
|
|
101
110
|
* Copies the clips `ids` names (the selection by default) to the session's clipboard, with their
|
|
102
111
|
* names and the compositions they draw. Unknown ids are skipped.
|
package/dist/core/session.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compositionTree } from "./compositions.js";
|
|
2
|
-
import { createEmptyDocument, validateDocument, withInstanceIds, indexDocument, inheritDocumentIndex, EditorError, } from "./document.js";
|
|
2
|
+
import { createEmptyDocument, validateDocument, withInstanceIds, canonicalDocument, indexDocument, inheritDocumentIndex, EditorError, } from "./document.js";
|
|
3
3
|
import { executeCommand } from "./commands.js";
|
|
4
4
|
import { frozenValid, owned } from "./validated.js";
|
|
5
5
|
/**
|
|
@@ -42,7 +42,7 @@ export class EditorSession {
|
|
|
42
42
|
!Number.isSafeInteger(historyByteLimit) ||
|
|
43
43
|
historyByteLimit < 0)
|
|
44
44
|
throw new RangeError("Invalid history budget");
|
|
45
|
-
document = withInstanceIds(document);
|
|
45
|
+
document = withInstanceIds(canonicalDocument(document));
|
|
46
46
|
validateDocument(document);
|
|
47
47
|
this.#document = frozenValid(owned(document));
|
|
48
48
|
this.#snapshot = this.#read();
|
|
@@ -186,7 +186,7 @@ export class EditorSession {
|
|
|
186
186
|
*/
|
|
187
187
|
open(document) {
|
|
188
188
|
this.#active();
|
|
189
|
-
document = withInstanceIds(document);
|
|
189
|
+
document = withInstanceIds(canonicalDocument(document));
|
|
190
190
|
validateDocument(document);
|
|
191
191
|
const next = frozenValid(owned(document));
|
|
192
192
|
this.#cancelGesture?.();
|
package/dist/ports/index.d.ts
CHANGED
|
@@ -96,8 +96,10 @@ export type ExportArtifact = ({
|
|
|
96
96
|
readonly bytes?: number;
|
|
97
97
|
/**
|
|
98
98
|
* What the exporter reported about the run: timings, `performance` (with `memory` and `output`),
|
|
99
|
-
* rates. A browser export adds `
|
|
100
|
-
*
|
|
99
|
+
* rates. A browser export adds `videoDecode`, the decode mode it ran with, and `decodeFallbacks`:
|
|
100
|
+
* per source, frames read by element seeks rather than decoded (`kind: "element-seek"`), with
|
|
101
|
+
* why, how many frames, and whether for good, and sources `videoDecode: "software"` could not
|
|
102
|
+
* decode in software (`kind: "software-unavailable"`).
|
|
101
103
|
*/
|
|
102
104
|
readonly report?: Readonly<Record<string, unknown>>;
|
|
103
105
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpha2-sh/editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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": "rm -rf dist && tsc -p tsconfig.json"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"alpha2": "0.
|
|
63
|
+
"alpha2": "0.4.0",
|
|
64
64
|
"react": "^19.3.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"alpha2": "0.
|
|
67
|
+
"alpha2": "0.4.0",
|
|
68
68
|
"react": "19.3.0",
|
|
69
69
|
"react-dom": "19.3.0",
|
|
70
70
|
"@types/react": "19.3.0",
|