@alpha2-sh/editor 0.4.6 → 0.5.1
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.d.ts +15 -16
- package/dist/browser/bridge.js +393 -312
- package/dist/browser/extensions-worker.d.ts +12 -16
- package/dist/browser/extensions-worker.js +17 -24
- package/dist/browser/hash-worker.d.ts +4 -5
- package/dist/browser/hash-worker.js +7 -8
- package/dist/browser/jobs.d.ts +17 -19
- package/dist/browser/jobs.js +41 -28
- package/dist/browser/resources.d.ts +6 -11
- package/dist/browser/resources.js +5 -9
- package/dist/browser/runtime/assets.d.ts +52 -28
- package/dist/browser/runtime/assets.js +136 -45
- package/dist/browser/runtime/audio.d.ts +16 -11
- package/dist/browser/runtime/audio.js +102 -59
- package/dist/browser/runtime/budget.d.ts +4 -5
- package/dist/browser/runtime/budget.js +4 -5
- package/dist/browser/runtime/caption-fonts.d.ts +3 -7
- package/dist/browser/runtime/caption-fonts.js +4 -8
- package/dist/browser/runtime/engine.d.ts +44 -44
- package/dist/browser/runtime/engine.js +87 -64
- package/dist/browser/runtime/export-audio.d.ts +6 -6
- package/dist/browser/runtime/export-audio.js +8 -9
- package/dist/browser/runtime/exporter.d.ts +33 -66
- package/dist/browser/runtime/exporter.js +111 -137
- package/dist/browser/runtime/extension-import.d.ts +28 -35
- package/dist/browser/runtime/extension-import.js +36 -46
- package/dist/browser/runtime/fingerprint.d.ts +11 -14
- package/dist/browser/runtime/fingerprint.js +20 -24
- package/dist/browser/runtime/generators.d.ts +2 -3
- package/dist/browser/runtime/generators.js +5 -7
- package/dist/browser/runtime/locks.d.ts +5 -7
- package/dist/browser/runtime/locks.js +5 -7
- package/dist/browser/runtime/output.d.ts +7 -9
- package/dist/browser/runtime/output.js +17 -21
- package/dist/browser/runtime/preview-utils.js +10 -6
- package/dist/browser/runtime/proxies.d.ts +19 -19
- package/dist/browser/runtime/proxies.js +72 -51
- package/dist/browser/runtime/proxy-storage.d.ts +15 -19
- package/dist/browser/runtime/proxy-storage.js +20 -24
- package/dist/browser/runtime/sources.d.ts +23 -31
- package/dist/browser/runtime/sources.js +85 -103
- package/dist/browser/runtime/staging.d.ts +2 -6
- package/dist/browser/runtime/staging.js +7 -11
- package/dist/browser/runtime/still.d.ts +2 -6
- package/dist/browser/runtime/still.js +6 -12
- package/dist/browser/runtime/text.d.ts +14 -0
- package/dist/browser/runtime/text.js +27 -0
- package/dist/browser/runtime/wasm.d.ts +4 -5
- package/dist/browser/runtime/wasm.js +4 -5
- package/dist/browser/types.d.ts +244 -239
- package/dist/browser/worker.d.ts +10 -10
- package/dist/browser/worker.js +64 -22
- package/dist/core/captions.d.ts +8 -10
- package/dist/core/captions.js +10 -18
- package/dist/core/clip-time.d.ts +8 -10
- package/dist/core/clip-time.js +12 -15
- package/dist/core/commands.d.ts +46 -46
- package/dist/core/commands.js +38 -36
- package/dist/core/compositions.d.ts +78 -112
- package/dist/core/compositions.js +66 -94
- package/dist/core/document.d.ts +59 -92
- package/dist/core/document.js +65 -90
- package/dist/core/keyframes.d.ts +11 -12
- package/dist/core/keyframes.js +11 -13
- package/dist/core/presets.d.ts +14 -20
- package/dist/core/presets.js +12 -18
- package/dist/core/session.d.ts +26 -38
- package/dist/core/session.js +38 -53
- package/dist/core/text.d.ts +2 -3
- package/dist/core/text.js +2 -3
- package/dist/core/timeline-index.d.ts +2 -3
- package/dist/core/timeline-index.js +11 -7
- package/dist/core/transitions.js +4 -5
- package/dist/core/validated.d.ts +6 -7
- package/dist/core/validated.js +8 -11
- package/dist/native-client/index.d.ts +31 -32
- package/dist/native-client/index.js +40 -41
- package/dist/ports/index.d.ts +19 -20
- package/dist/react/index.d.ts +5 -6
- package/dist/react/index.js +5 -6
- package/package.json +4 -4
package/dist/browser/worker.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Serves the editor's preview protocol (`createWorkerPreview`) on `scope`, a dedicated worker's
|
|
3
|
-
* global.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* global. Requests run one at a time in arrival order. A `cancel` or `replace-project` stops the
|
|
4
|
+
* render in flight and drops seeks that arrived before it. Requests from another session or an
|
|
5
|
+
* older revision are answered with an error. A second call on the same scope returns the first
|
|
6
|
+
* call's handle and leaves its handler in place.
|
|
7
7
|
* @param {import("./types.js").EditorWorkerScope} scope
|
|
8
8
|
* @returns {{ dispose(): Promise<void> }} Waits for queued requests, releases the engine and
|
|
9
9
|
* decoders, and detaches the message handler.
|
|
@@ -12,13 +12,13 @@ export function installEditorWorker(scope: import("./types.js").EditorWorkerScop
|
|
|
12
12
|
dispose(): Promise<void>;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
* Drives a preview renderer in `worker`, which must run `installEditorWorker`. The caller owns
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* Drives a preview renderer in `worker`, which must run `installEditorWorker`. The caller owns the
|
|
16
|
+
* worker; `dispose()` terminates it. This port renders picture and mixes audio blocks only, apart
|
|
17
|
+
* from a bridge's main-thread audio output. Every call waits for `ready`, which rejects if the
|
|
18
|
+
* worker cannot start its engine; a disposed preview rejects new calls, and a worker error rejects
|
|
19
|
+
* every pending one.
|
|
20
20
|
* @param {Worker} worker
|
|
21
21
|
* @param {import("./types.js").WorkerPreviewOptions} [options]
|
|
22
22
|
* @returns {import("./types.js").WorkerPreview}
|
|
23
23
|
*/
|
|
24
|
-
export function createWorkerPreview(worker: Worker, { sessionId, runtimeAssets, canvas, bitmapOutput, width, height, videoConversion, }?: import("./types.js").WorkerPreviewOptions): import("./types.js").WorkerPreview;
|
|
24
|
+
export function createWorkerPreview(worker: Worker, { sessionId, runtimeAssets, canvas, bitmapOutput, width, height, videoConversion, opaqueEngineFrames, renderer, }?: import("./types.js").WorkerPreviewOptions): import("./types.js").WorkerPreview;
|
package/dist/browser/worker.js
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
|
+
import { Alpha2WasmError, serializeError } from "alpha2/worker-error";
|
|
1
2
|
import { SourcePixels } from "./runtime/sources.js";
|
|
2
3
|
import { AudioWindowSupplier, mixBlock } from "./runtime/audio.js";
|
|
4
|
+
const INSTALLED = Symbol.for("alpha2.editorWorker");
|
|
3
5
|
/**
|
|
4
6
|
* Serves the editor's preview protocol (`createWorkerPreview`) on `scope`, a dedicated worker's
|
|
5
|
-
* global.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* global. Requests run one at a time in arrival order. A `cancel` or `replace-project` stops the
|
|
8
|
+
* render in flight and drops seeks that arrived before it. Requests from another session or an
|
|
9
|
+
* older revision are answered with an error. A second call on the same scope returns the first
|
|
10
|
+
* call's handle and leaves its handler in place.
|
|
9
11
|
* @param {import("./types.js").EditorWorkerScope} scope
|
|
10
12
|
* @returns {{ dispose(): Promise<void> }} Waits for queued requests, releases the engine and
|
|
11
13
|
* decoders, and detaches the message handler.
|
|
12
14
|
*/
|
|
13
15
|
export function installEditorWorker(scope) {
|
|
16
|
+
// Bundles whose lazy engine chunk imports the worker's entry chunk evaluate the entry again in
|
|
17
|
+
// some browsers; a fresh handler there would answer every request after `init` as stale.
|
|
18
|
+
const installed = scope[INSTALLED];
|
|
19
|
+
if (installed)
|
|
20
|
+
return installed;
|
|
21
|
+
const handle = serveEditorWorker(scope);
|
|
22
|
+
scope[INSTALLED] = handle;
|
|
23
|
+
return handle;
|
|
24
|
+
}
|
|
25
|
+
function serveEditorWorker(scope) {
|
|
14
26
|
let engine = null, pixels = null, audio = null, sessionId = null, bitmapOutput = false, currentProject = null, revision = -1,
|
|
15
|
-
// The renderer
|
|
27
|
+
// The last posted renderer diagnostics; a seek reply carries only newer ones.
|
|
16
28
|
sentDiagnostics = null, tail = Promise.resolve();
|
|
17
29
|
const assets = new Map(), library = { get: (id) => assets.get(id) };
|
|
18
30
|
const hasContent = (project) => project?.timeline.tracks.some((track) => (track.clips?.length ?? 0) + (track.captions?.cues.length ?? 0)) ?? false;
|
|
19
|
-
// The canvas
|
|
20
|
-
//
|
|
31
|
+
// The canvas takes the render size (document size times preview scale); unchanged with nothing
|
|
32
|
+
// loaded.
|
|
21
33
|
const sizeCanvas = () => {
|
|
22
34
|
const size = hasContent(currentProject) ? engine.previewSize : null;
|
|
23
35
|
if (size)
|
|
@@ -33,13 +45,13 @@ export function installEditorWorker(scope) {
|
|
|
33
45
|
return asset?.kind === "text" ? { id, kind: "image", asset } : asset;
|
|
34
46
|
},
|
|
35
47
|
});
|
|
36
|
-
// Counts cancels and project replacements.
|
|
37
|
-
//
|
|
48
|
+
// Counts cancels and project replacements. Requests remember the count on arrival, so work queued
|
|
49
|
+
// before a cancel or replacement is dropped however long it waited.
|
|
38
50
|
let epoch = 0;
|
|
39
51
|
scope.onmessage = ({ data: request }) => {
|
|
40
52
|
if (request.type === "cancel" || request.type === "replace-project") {
|
|
41
53
|
epoch += 1;
|
|
42
|
-
// The render in flight is for what this replaces
|
|
54
|
+
// The render in flight is for what this replaces, so stop it.
|
|
43
55
|
engine?.invalidate();
|
|
44
56
|
}
|
|
45
57
|
const arrived = epoch;
|
|
@@ -64,6 +76,8 @@ export function installEditorWorker(scope) {
|
|
|
64
76
|
new OffscreenCanvas(request.width ?? 16, request.height ?? 16), pixels, library, request.runtimeAssets, {
|
|
65
77
|
unreadableFrames: "present",
|
|
66
78
|
videoConversion: request.videoConversion,
|
|
79
|
+
opaqueEngineFrames: request.opaqueEngineFrames,
|
|
80
|
+
renderer: request.renderer ?? "auto",
|
|
67
81
|
});
|
|
68
82
|
audio = new AudioWindowSupplier(library);
|
|
69
83
|
engine.backend = "worker";
|
|
@@ -98,13 +112,13 @@ export function installEditorWorker(scope) {
|
|
|
98
112
|
}
|
|
99
113
|
else if (type === "seek") {
|
|
100
114
|
const generation = engine.generation;
|
|
101
|
-
const { rendered, unchanged } = arrived !== epoch || !hasContent(currentProject)
|
|
115
|
+
const { rendered, unchanged, degradedSources = [], } = arrived !== epoch || !hasContent(currentProject)
|
|
102
116
|
? { rendered: false, unchanged: false }
|
|
103
117
|
: await engine.render(request.tick / 120000, {
|
|
104
118
|
generation,
|
|
105
119
|
context: context(),
|
|
106
120
|
});
|
|
107
|
-
// An unchanged frame was not presented
|
|
121
|
+
// An unchanged frame was not presented; the surface it was copied to still shows it.
|
|
108
122
|
const bitmap = rendered && !unchanged && bitmapOutput
|
|
109
123
|
? engine.canvas.transferToImageBitmap()
|
|
110
124
|
: null;
|
|
@@ -118,6 +132,7 @@ export function installEditorWorker(scope) {
|
|
|
118
132
|
value: {
|
|
119
133
|
rendered,
|
|
120
134
|
unchanged,
|
|
135
|
+
degradedSources,
|
|
121
136
|
diagnostics: pixels.diagnostics,
|
|
122
137
|
...(engineDiagnostics ? { engineDiagnostics } : {}),
|
|
123
138
|
...(bitmap ? { bitmap } : {}),
|
|
@@ -163,12 +178,24 @@ export function installEditorWorker(scope) {
|
|
|
163
178
|
scope.postMessage({ ...response, ok: true });
|
|
164
179
|
}
|
|
165
180
|
catch (error) {
|
|
181
|
+
// What the bridge decides by: code, fatality, name and failure, plus the cause's code,
|
|
182
|
+
// since a source the browser cannot hand over arrives wrapped in the frame that needed it.
|
|
183
|
+
const causeCode = error?.cause?.code;
|
|
184
|
+
// Read the GPU loss report before the engine is freed; the page's recovery ladder uses it.
|
|
185
|
+
let lossReport;
|
|
186
|
+
try {
|
|
187
|
+
lossReport = engine?.lossReport();
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
lossReport = undefined;
|
|
191
|
+
}
|
|
166
192
|
scope.postMessage({
|
|
167
193
|
...response,
|
|
168
194
|
ok: false,
|
|
169
195
|
error: {
|
|
170
|
-
|
|
171
|
-
|
|
196
|
+
...serializeError(error, false, "worker_error"),
|
|
197
|
+
...(typeof causeCode === "string" ? { causeCode } : {}),
|
|
198
|
+
...(lossReport === undefined ? {} : { lossReport }),
|
|
172
199
|
},
|
|
173
200
|
});
|
|
174
201
|
}
|
|
@@ -182,20 +209,21 @@ export function installEditorWorker(scope) {
|
|
|
182
209
|
await pixels?.dispose();
|
|
183
210
|
assets.clear();
|
|
184
211
|
scope.onmessage = null;
|
|
212
|
+
delete scope[INSTALLED];
|
|
185
213
|
},
|
|
186
214
|
};
|
|
187
215
|
}
|
|
188
216
|
/**
|
|
189
|
-
* Drives a preview renderer in `worker`, which must run `installEditorWorker`. The caller owns
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
217
|
+
* Drives a preview renderer in `worker`, which must run `installEditorWorker`. The caller owns the
|
|
218
|
+
* worker; `dispose()` terminates it. This port renders picture and mixes audio blocks only, apart
|
|
219
|
+
* from a bridge's main-thread audio output. Every call waits for `ready`, which rejects if the
|
|
220
|
+
* worker cannot start its engine; a disposed preview rejects new calls, and a worker error rejects
|
|
221
|
+
* every pending one.
|
|
194
222
|
* @param {Worker} worker
|
|
195
223
|
* @param {import("./types.js").WorkerPreviewOptions} [options]
|
|
196
224
|
* @returns {import("./types.js").WorkerPreview}
|
|
197
225
|
*/
|
|
198
|
-
export function createWorkerPreview(worker, { sessionId = crypto.randomUUID(), runtimeAssets = {}, canvas, bitmapOutput = false, width = 16, height = 16, videoConversion, } = {}) {
|
|
226
|
+
export function createWorkerPreview(worker, { sessionId = crypto.randomUUID(), runtimeAssets = {}, canvas, bitmapOutput = false, width = 16, height = 16, videoConversion, opaqueEngineFrames, renderer, } = {}) {
|
|
199
227
|
let nextId = 0, revision = 0, disposed = false;
|
|
200
228
|
const pending = new Map();
|
|
201
229
|
const rejectAll = (error) => {
|
|
@@ -216,8 +244,20 @@ export function createWorkerPreview(worker, { sessionId = crypto.randomUUID(), r
|
|
|
216
244
|
pending.delete(data.requestId);
|
|
217
245
|
if (data.ok)
|
|
218
246
|
waiter.resolve(data.value);
|
|
219
|
-
else
|
|
220
|
-
|
|
247
|
+
else {
|
|
248
|
+
const error = new Alpha2WasmError(data.error);
|
|
249
|
+
if (typeof data.error.causeCode === "string")
|
|
250
|
+
Object.defineProperty(error, "cause", {
|
|
251
|
+
value: { code: data.error.causeCode },
|
|
252
|
+
configurable: true,
|
|
253
|
+
});
|
|
254
|
+
if (data.error.lossReport !== undefined)
|
|
255
|
+
Object.defineProperty(error, "lossReport", {
|
|
256
|
+
value: data.error.lossReport,
|
|
257
|
+
configurable: true,
|
|
258
|
+
});
|
|
259
|
+
waiter.reject(error);
|
|
260
|
+
}
|
|
221
261
|
};
|
|
222
262
|
worker.onerror = (event) => rejectAll(new Error(event.message));
|
|
223
263
|
const call = (type, body = {}, transfer = []) => {
|
|
@@ -241,6 +281,8 @@ export function createWorkerPreview(worker, { sessionId = crypto.randomUUID(), r
|
|
|
241
281
|
width,
|
|
242
282
|
height,
|
|
243
283
|
...(videoConversion === undefined ? {} : { videoConversion }),
|
|
284
|
+
...(opaqueEngineFrames === undefined ? {} : { opaqueEngineFrames }),
|
|
285
|
+
...(renderer === undefined ? {} : { renderer }),
|
|
244
286
|
...(canvas ? { canvas } : {}),
|
|
245
287
|
}, canvas ? [canvas] : []);
|
|
246
288
|
return {
|
package/dist/core/captions.d.ts
CHANGED
|
@@ -4,14 +4,14 @@ import type { Command } from "./commands.js";
|
|
|
4
4
|
/** The bin asset kind a subtitle file (SRT or WebVTT) imports as. */
|
|
5
5
|
export declare const CAPTIONS_ASSET_KIND = "captions";
|
|
6
6
|
/**
|
|
7
|
-
* A subtitle file in the bin: its cues split into rows,
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* A subtitle file in the bin: its cues split into non-overlapping rows, as `parseCaptions` reads
|
|
8
|
+
* them. The cues live in the asset's authoring data, so the asset needs no file to stay online.
|
|
9
|
+
* Inserting it adds one caption track per row.
|
|
10
10
|
*/
|
|
11
11
|
export declare function captionsAsset(id: string, name: string, rows: readonly (readonly CaptionCue[])[]): AssetDescriptor;
|
|
12
12
|
/**
|
|
13
|
-
* Whether
|
|
14
|
-
*
|
|
13
|
+
* Whether authoring data is the cue rows {@link captionsAsset} writes; `validateDocument` refuses
|
|
14
|
+
* a captions asset with anything else.
|
|
15
15
|
*/
|
|
16
16
|
export declare function validCaptionsAuthoring(authoring: Json | undefined): boolean;
|
|
17
17
|
/** A captions asset's cue rows; empty for any other asset or malformed authoring data. */
|
|
@@ -19,11 +19,9 @@ export declare function captionRows(asset: AssetDescriptor | undefined): readonl
|
|
|
19
19
|
/** Where a captions asset's last cue ends, in ticks from its start. */
|
|
20
20
|
export declare function captionsDuration(asset: AssetDescriptor | undefined): number;
|
|
21
21
|
/**
|
|
22
|
-
* The commands that put a captions asset on the timeline:
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* Throws when the asset has no cues.
|
|
22
|
+
* The commands that put a captions asset on the timeline: one new caption track per row, every cue
|
|
23
|
+
* moved `at` ticks later, in `style` when given. Track IDs come from `newId` (`crypto.randomUUID`
|
|
24
|
+
* by default). Throws when the asset has no cues.
|
|
27
25
|
*/
|
|
28
26
|
export declare function captionTrackCommands(asset: AssetDescriptor, at: number, options?: {
|
|
29
27
|
newId?: () => string;
|
package/dist/core/captions.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** The bin asset kind a subtitle file (SRT or WebVTT) imports as. */
|
|
2
2
|
export const CAPTIONS_ASSET_KIND = "captions";
|
|
3
3
|
/**
|
|
4
|
-
* A subtitle file in the bin: its cues split into rows,
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* A subtitle file in the bin: its cues split into non-overlapping rows, as `parseCaptions` reads
|
|
5
|
+
* them. The cues live in the asset's authoring data, so the asset needs no file to stay online.
|
|
6
|
+
* Inserting it adds one caption track per row.
|
|
7
7
|
*/
|
|
8
8
|
export function captionsAsset(id, name, rows) {
|
|
9
9
|
return {
|
|
@@ -14,10 +14,7 @@ export function captionsAsset(id, name, rows) {
|
|
|
14
14
|
authoring: { captions: { rows } },
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Whether `value` is a cue as a captions asset keeps it: text, and a non-empty range of safe
|
|
19
|
-
* integer ticks from the asset's start.
|
|
20
|
-
*/
|
|
17
|
+
/** Whether `value` is a stored cue: text and a non-empty range of safe-integer ticks. */
|
|
21
18
|
function isCaptionCue(value) {
|
|
22
19
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
23
20
|
return false;
|
|
@@ -31,10 +28,7 @@ function isCaptionCue(value) {
|
|
|
31
28
|
start >= 0 &&
|
|
32
29
|
start < end);
|
|
33
30
|
}
|
|
34
|
-
/**
|
|
35
|
-
* The cue rows a captions asset's authoring data holds, or `undefined` when it holds anything else:
|
|
36
|
-
* `{ captions: { rows } }`, each row a list of cues.
|
|
37
|
-
*/
|
|
31
|
+
/** A captions asset's `{ captions: { rows } }` cue rows, or `undefined` for anything else. */
|
|
38
32
|
function rowsOf(authoring) {
|
|
39
33
|
const captions = typeof authoring === "object" &&
|
|
40
34
|
authoring !== null &&
|
|
@@ -50,8 +44,8 @@ function rowsOf(authoring) {
|
|
|
50
44
|
return rows;
|
|
51
45
|
}
|
|
52
46
|
/**
|
|
53
|
-
* Whether
|
|
54
|
-
*
|
|
47
|
+
* Whether authoring data is the cue rows {@link captionsAsset} writes; `validateDocument` refuses
|
|
48
|
+
* a captions asset with anything else.
|
|
55
49
|
*/
|
|
56
50
|
export function validCaptionsAuthoring(authoring) {
|
|
57
51
|
return rowsOf(authoring) !== undefined;
|
|
@@ -71,11 +65,9 @@ export function captionsDuration(asset) {
|
|
|
71
65
|
return end;
|
|
72
66
|
}
|
|
73
67
|
/**
|
|
74
|
-
* The commands that put a captions asset on the timeline:
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* Throws when the asset has no cues.
|
|
68
|
+
* The commands that put a captions asset on the timeline: one new caption track per row, every cue
|
|
69
|
+
* moved `at` ticks later, in `style` when given. Track IDs come from `newId` (`crypto.randomUUID`
|
|
70
|
+
* by default). Throws when the asset has no cues.
|
|
79
71
|
*/
|
|
80
72
|
export function captionTrackCommands(asset, at, options = {}) {
|
|
81
73
|
const rows = captionRows(asset).filter((row) => row.length > 0);
|
package/dist/core/clip-time.d.ts
CHANGED
|
@@ -10,22 +10,20 @@ export interface FrameRateValue {
|
|
|
10
10
|
* timeline length, `S` its source length, and `F` one frame at `frameRate`:
|
|
11
11
|
*
|
|
12
12
|
* - forward: `floor(e*S/T)` past the source start;
|
|
13
|
-
* - reverse: the forward instant at the start of the mirrored project frame, less the time into
|
|
14
|
-
* frame, so a reversed clip shows the forward clip's frames in
|
|
15
|
-
*
|
|
16
|
-
* source start where that falls before it);
|
|
13
|
+
* - reverse: the forward instant at the start of the mirrored project frame, less the time into
|
|
14
|
+
* the frame, so a reversed clip shows the forward clip's frames in opposite order at the same
|
|
15
|
+
* instants (clamped to the source start);
|
|
17
16
|
* - freeze: its instant;
|
|
18
17
|
* - a repeating loop: `e mod S` past the source start;
|
|
19
|
-
* - a ping-pong loop: the same on even passes,
|
|
20
|
-
* same way.
|
|
18
|
+
* - a ping-pong loop: the same on even passes, mirrored by frame on odd ones.
|
|
21
19
|
*
|
|
22
20
|
* A clip with an empty range reads its source start.
|
|
23
21
|
*/
|
|
24
22
|
export declare function clipSourceTime(clip: Clip, tick: number, frameRate: FrameRateValue): number;
|
|
25
23
|
/**
|
|
26
|
-
* The first timeline tick at which `clip`'s picture shows source time `time` (rounded up
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
24
|
+
* The first timeline tick at which `clip`'s picture shows source time `time` (rounded up), or
|
|
25
|
+
* where it never shows exactly that, the first that passes it in the direction of play. The
|
|
26
|
+
* inverse of {@link clipSourceTime} on a clip's first pass. A freeze shows its instant from its
|
|
27
|
+
* start.
|
|
30
28
|
*/
|
|
31
29
|
export declare function clipTimelineTime(clip: Clip, time: number, frameRate: FrameRateValue): number;
|
package/dist/core/clip-time.js
CHANGED
|
@@ -5,14 +5,12 @@ import { TICKS_PER_SECOND } from "alpha2/project";
|
|
|
5
5
|
* timeline length, `S` its source length, and `F` one frame at `frameRate`:
|
|
6
6
|
*
|
|
7
7
|
* - forward: `floor(e*S/T)` past the source start;
|
|
8
|
-
* - reverse: the forward instant at the start of the mirrored project frame, less the time into
|
|
9
|
-
* frame, so a reversed clip shows the forward clip's frames in
|
|
10
|
-
*
|
|
11
|
-
* source start where that falls before it);
|
|
8
|
+
* - reverse: the forward instant at the start of the mirrored project frame, less the time into
|
|
9
|
+
* the frame, so a reversed clip shows the forward clip's frames in opposite order at the same
|
|
10
|
+
* instants (clamped to the source start);
|
|
12
11
|
* - freeze: its instant;
|
|
13
12
|
* - a repeating loop: `e mod S` past the source start;
|
|
14
|
-
* - a ping-pong loop: the same on even passes,
|
|
15
|
-
* same way.
|
|
13
|
+
* - a ping-pong loop: the same on even passes, mirrored by frame on odd ones.
|
|
16
14
|
*
|
|
17
15
|
* A clip with an empty range reads its source start.
|
|
18
16
|
*/
|
|
@@ -40,10 +38,10 @@ export function clipSourceTime(clip, tick, frameRate) {
|
|
|
40
38
|
return Number(source + offset);
|
|
41
39
|
}
|
|
42
40
|
/**
|
|
43
|
-
* The first timeline tick at which `clip`'s picture shows source time `time` (rounded up
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
41
|
+
* The first timeline tick at which `clip`'s picture shows source time `time` (rounded up), or
|
|
42
|
+
* where it never shows exactly that, the first that passes it in the direction of play. The
|
|
43
|
+
* inverse of {@link clipSourceTime} on a clip's first pass. A freeze shows its instant from its
|
|
44
|
+
* start.
|
|
47
45
|
*/
|
|
48
46
|
export function clipTimelineTime(clip, time, frameRate) {
|
|
49
47
|
const { timeline, source, span, length, per, frame } = parts(clip, frameRate);
|
|
@@ -55,7 +53,7 @@ export function clipTimelineTime(clip, time, frameRate) {
|
|
|
55
53
|
if (map.type === "loop")
|
|
56
54
|
elapsed = k;
|
|
57
55
|
else if (map.type === "reverse") {
|
|
58
|
-
// The mirrored instant never rises with `e
|
|
56
|
+
// The mirrored instant never rises with `e`; binary-search the first `e` showing `k` or before.
|
|
59
57
|
let low = 0n;
|
|
60
58
|
let high = length;
|
|
61
59
|
while (low < high) {
|
|
@@ -86,10 +84,9 @@ function parts(clip, frameRate) {
|
|
|
86
84
|
/**
|
|
87
85
|
* The forward offset `floor(e' * scale / length)` the mirror of `elapsed` shows within `length`
|
|
88
86
|
* ticks from timeline tick `start`, by project frames of `frame / per` ticks (alpha2-eval's
|
|
89
|
-
* `Mirror::offset`)
|
|
90
|
-
* containing the instant (`k0` before it
|
|
91
|
-
*
|
|
92
|
-
* starts in shows its start.
|
|
87
|
+
* `Mirror::offset`). With `k0` and `k1` the first and last frames starting inside and `k` the one
|
|
88
|
+
* containing the instant (`k0` before it), `e'` is the start of `k0 + k1 - k` less the time into
|
|
89
|
+
* `k`, from `start`, clamped at zero. A window no frame starts in shows its start.
|
|
93
90
|
*/
|
|
94
91
|
function mirrored(start, length, elapsed, scale, frame, per) {
|
|
95
92
|
const startOf = (k) => floorDiv(k * frame, per);
|
package/dist/core/commands.d.ts
CHANGED
|
@@ -2,9 +2,8 @@ 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
4
|
/**
|
|
5
|
-
* A document while a command
|
|
6
|
-
*
|
|
7
|
-
* engine writes ({@link canonicalDocument}). An {@link EditorDocument} is one.
|
|
5
|
+
* A document while a command applies: its project may hold input as written (a CSS hex color, say)
|
|
6
|
+
* until {@link executeCommand} canonicalizes the result ({@link canonicalDocument}).
|
|
8
7
|
*/
|
|
9
8
|
type DraftDocument = Omit<EditorDocument, "project"> & {
|
|
10
9
|
readonly project: Project;
|
|
@@ -27,19 +26,14 @@ export type Command =
|
|
|
27
26
|
readonly duration: number;
|
|
28
27
|
readonly effect: ClipEffect;
|
|
29
28
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Gives a transition, named by its instance id, a new duration; the incoming clips move to match.
|
|
32
|
-
*/
|
|
29
|
+
/** Gives a transition, by instance id, a new duration; the incoming clips move to match. */
|
|
33
30
|
| {
|
|
34
31
|
readonly type: "transition.resize";
|
|
35
32
|
readonly trackId: string;
|
|
36
33
|
readonly instanceId: string;
|
|
37
34
|
readonly duration: number;
|
|
38
35
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Removes a transition; the incoming clip and its chain move later to where the outgoing clip
|
|
41
|
-
* ends.
|
|
42
|
-
*/
|
|
36
|
+
/** Removes a transition; the incoming clip and its chain move to the outgoing clip's end. */
|
|
43
37
|
| {
|
|
44
38
|
readonly type: "transition.remove";
|
|
45
39
|
readonly trackId: string;
|
|
@@ -55,10 +49,7 @@ export type Command =
|
|
|
55
49
|
readonly type: "project.update";
|
|
56
50
|
readonly patch: Partial<Pick<Project, "name" | "settings" | "audio">>;
|
|
57
51
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Adds a track on top of the others. Like `clip.insert`, each of its clips whose composition
|
|
60
|
-
* something else draws shows its own copy of it.
|
|
61
|
-
*/
|
|
52
|
+
/** Adds a track on top. As in `clip.insert`, shared compositions are copied per clip. */
|
|
62
53
|
| {
|
|
63
54
|
readonly type: "track.add";
|
|
64
55
|
readonly track: Track;
|
|
@@ -90,10 +81,10 @@ export type Command =
|
|
|
90
81
|
readonly patch: ClipMetadata;
|
|
91
82
|
}
|
|
92
83
|
/**
|
|
93
|
-
* Adds a clip to a track as
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
84
|
+
* Adds a clip to a track as is, without making room. A clip whose composition something else
|
|
85
|
+
* draws gets its own copy of it (and its group definitions), so a duplicate edits independently.
|
|
86
|
+
* `compositions` are those the clip drew when copied; it shows copies of them even if the
|
|
87
|
+
* document no longer has them.
|
|
97
88
|
*/
|
|
98
89
|
| {
|
|
99
90
|
readonly type: "clip.insert";
|
|
@@ -103,11 +94,10 @@ export type Command =
|
|
|
103
94
|
readonly compositions?: readonly Composition[];
|
|
104
95
|
}
|
|
105
96
|
/**
|
|
106
|
-
* Puts a clip down at `at
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* of it.
|
|
97
|
+
* Puts a clip down at `at`: `insert` makes room by moving later content (on sync-locked tracks
|
|
98
|
+
* too), `overwrite` replaces what is there, `append` goes after the track's last clip. A clip the
|
|
99
|
+
* new one cuts in two keeps its id on the left; the right part is `splitId`. Shared compositions
|
|
100
|
+
* are copied as in `clip.insert`.
|
|
111
101
|
*/
|
|
112
102
|
| {
|
|
113
103
|
readonly type: "clip.place";
|
|
@@ -131,9 +121,9 @@ export type Command =
|
|
|
131
121
|
readonly delta: number;
|
|
132
122
|
}
|
|
133
123
|
/**
|
|
134
|
-
* Gives a clip a new length from
|
|
135
|
-
*
|
|
136
|
-
*
|
|
124
|
+
* Gives a clip a new length from its start by changing its speed (forward or reversed). `ripple`
|
|
125
|
+
* moves what follows (on sync-locked tracks too); `keyframes` keeps or stretches its keyframes,
|
|
126
|
+
* fades and composition time.
|
|
137
127
|
*/
|
|
138
128
|
| {
|
|
139
129
|
readonly type: "clip.retime";
|
|
@@ -171,10 +161,7 @@ export type Command =
|
|
|
171
161
|
readonly at: number;
|
|
172
162
|
readonly trackId?: string;
|
|
173
163
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Moves several clips as one: only where they all land must be valid, whatever order `moves`
|
|
176
|
-
* lists them in.
|
|
177
|
-
*/
|
|
164
|
+
/** Moves several clips as one; only the final positions must be valid, whatever the order. */
|
|
178
165
|
| {
|
|
179
166
|
readonly type: "clips.move";
|
|
180
167
|
readonly moves: readonly {
|
|
@@ -218,7 +205,7 @@ export type Command =
|
|
|
218
205
|
}
|
|
219
206
|
/**
|
|
220
207
|
* Adds an effect on top of clip `id`'s effect stack as `instanceId`. The `effect.*` commands are
|
|
221
|
-
* refused
|
|
208
|
+
* refused when the clip's composition is a graph rather than a stack (see `effectStack`).
|
|
222
209
|
*/
|
|
223
210
|
| {
|
|
224
211
|
readonly type: "effect.add";
|
|
@@ -241,9 +228,7 @@ export type Command =
|
|
|
241
228
|
readonly id: string;
|
|
242
229
|
readonly instanceId: string;
|
|
243
230
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Puts clip `id`'s effects in the order `ids` lists them, bottom first; `ids` names each once.
|
|
246
|
-
*/
|
|
231
|
+
/** Orders clip `id`'s effects as `ids` lists them, bottom first; `ids` names each once. */
|
|
247
232
|
| {
|
|
248
233
|
readonly type: "effect.reorder";
|
|
249
234
|
readonly id: string;
|
|
@@ -276,10 +261,7 @@ export type Command =
|
|
|
276
261
|
readonly compositionId: string;
|
|
277
262
|
readonly ids: readonly string[];
|
|
278
263
|
}
|
|
279
|
-
/**
|
|
280
|
-
* Connects node `from`'s picture to input `input` of node `to`; `"layer"` adds a merge layer on
|
|
281
|
-
* top.
|
|
282
|
-
*/
|
|
264
|
+
/** Connects node `from`'s picture to input `input` of node `to`; `"layer"` adds a merge layer. */
|
|
283
265
|
| {
|
|
284
266
|
readonly type: "graph.connect";
|
|
285
267
|
readonly compositionId: string;
|
|
@@ -347,8 +329,8 @@ export type Command =
|
|
|
347
329
|
readonly name: string;
|
|
348
330
|
}
|
|
349
331
|
/**
|
|
350
|
-
* Makes a composition a Library item
|
|
351
|
-
*
|
|
332
|
+
* Makes a composition a Library item (a composition source clips place like media), starting with
|
|
333
|
+
* a background to build on.
|
|
352
334
|
*/
|
|
353
335
|
| {
|
|
354
336
|
readonly type: "composition.create";
|
|
@@ -380,6 +362,28 @@ export type Command =
|
|
|
380
362
|
readonly trackId: string;
|
|
381
363
|
readonly instanceId: string;
|
|
382
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Cuts cue `instanceId` in two at timeline tick `at`, the second half as `newInstanceId`. Timed
|
|
367
|
+
* runs are rebased to each half's start, and a run spanning the cut is kept in both (`splitCue`).
|
|
368
|
+
*/
|
|
369
|
+
| {
|
|
370
|
+
readonly type: "cue.split";
|
|
371
|
+
readonly trackId: string;
|
|
372
|
+
readonly instanceId: string;
|
|
373
|
+
readonly newInstanceId: string;
|
|
374
|
+
readonly at: number;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Shows cue `instanceId` from `start` to `end` within its range; runs outside are dropped and the
|
|
378
|
+
* rest rebased (`trimCue`).
|
|
379
|
+
*/
|
|
380
|
+
| {
|
|
381
|
+
readonly type: "cue.trim";
|
|
382
|
+
readonly trackId: string;
|
|
383
|
+
readonly instanceId: string;
|
|
384
|
+
readonly start: number;
|
|
385
|
+
readonly end: number;
|
|
386
|
+
}
|
|
383
387
|
/**
|
|
384
388
|
* Adds or replaces a bin asset, with the project source or effect resource of the same id when
|
|
385
389
|
* given. `contentRevision` may not go below the replaced asset's.
|
|
@@ -390,10 +394,7 @@ export type Command =
|
|
|
390
394
|
readonly source?: MediaSource;
|
|
391
395
|
readonly resource?: EffectResource;
|
|
392
396
|
}
|
|
393
|
-
/**
|
|
394
|
-
* Removes a bin asset and its project source or effect resource; a clip still reading it is
|
|
395
|
-
* refused.
|
|
396
|
-
*/
|
|
397
|
+
/** Removes a bin asset and its source or effect resource; refused while a clip reads it. */
|
|
397
398
|
| {
|
|
398
399
|
readonly type: "asset.remove";
|
|
399
400
|
readonly id: string;
|
|
@@ -409,8 +410,7 @@ export declare function graphNames(document: DraftDocument): Readonly<Record<str
|
|
|
409
410
|
export declare function graphLayout(document: DraftDocument): GraphLayout;
|
|
410
411
|
/**
|
|
411
412
|
* Applies `command` to `document` and validates the result. `gesture` checks only what a pointer
|
|
412
|
-
* move can change (see `validateDocumentShape`); the gesture validates in full
|
|
413
|
-
* commits.
|
|
413
|
+
* move can change (see `validateDocumentShape`); the gesture validates in full when it commits.
|
|
414
414
|
*
|
|
415
415
|
* Never throws: a refusal is `{ ok: false }` with an `EditorError` (`invalid_command`, `locked`, a
|
|
416
416
|
* validation code, or an edit code from `alpha2/edit`). `document` and `command` are not modified;
|