@alpha2-sh/editor 0.3.1 → 0.4.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.js +28 -14
- package/dist/browser/types.d.ts +13 -0
- 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 +24 -7
- package/dist/core/session.d.ts +10 -1
- package/dist/core/session.js +3 -3
- 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]);
|
|
@@ -2034,21 +2055,14 @@ export function createBrowserBridge(options) {
|
|
|
2034
2055
|
return families;
|
|
2035
2056
|
},
|
|
2036
2057
|
async measureText(generator) {
|
|
2037
|
-
const {
|
|
2038
|
-
if (disposed)
|
|
2039
|
-
throw new EditorError("disposed", "Bridge is disposed", "browser");
|
|
2040
|
-
// The fonts and canvas preview draws the draft with.
|
|
2041
|
-
const document = editor.draft;
|
|
2042
|
-
const fonts = fontStackOf(document);
|
|
2043
|
-
measurer ??= new WasmTextMeasurer();
|
|
2044
|
-
if (!sameList(measuredFonts, fonts)) {
|
|
2045
|
-
// A font the engine refuses is left out here as preview leaves it out, and reported there.
|
|
2046
|
-
registerCaptionFonts(measurer, fonts);
|
|
2047
|
-
measuredFonts = fonts;
|
|
2048
|
-
}
|
|
2049
|
-
const { width, height } = document.project.settings;
|
|
2058
|
+
const { width, height } = await draftMeasurer();
|
|
2050
2059
|
return JSON.parse(measurer.measure(JSON.stringify(generator), width, height));
|
|
2051
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
|
+
},
|
|
2052
2066
|
conform,
|
|
2053
2067
|
/**
|
|
2054
2068
|
* Makes a proxy of a source whose original this session holds, keeps it, and previews from it
|
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";
|
|
@@ -542,6 +543,18 @@ export interface BrowserBridge {
|
|
|
542
543
|
measureText(generator: Extract<Generator, {
|
|
543
544
|
type: "text";
|
|
544
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>;
|
|
545
558
|
/**
|
|
546
559
|
* The files a native export of `document` (the current one by default) needs, for upload:
|
|
547
560
|
* shown media (or their proxies with `media: "proxies"`), an image sequence's frames, font
|
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
|
|
@@ -300,7 +300,7 @@ export function createDocument(project, assets = {}) {
|
|
|
300
300
|
return withValidated(() => {
|
|
301
301
|
assertJson(project, MAX_JSON_DEPTH);
|
|
302
302
|
// Frozen before validation, so validated parts are reused when edits check them.
|
|
303
|
-
const copy = freeze(structuredClone(project));
|
|
303
|
+
const copy = freeze(canonicalProject(structuredClone(project)));
|
|
304
304
|
if (!knownValid(project)) {
|
|
305
305
|
const errors = validateProject(copy);
|
|
306
306
|
if (errors.length)
|
|
@@ -384,7 +384,7 @@ export function parseDocument(text) {
|
|
|
384
384
|
try {
|
|
385
385
|
if (isRecord(data) && "schema_version" in data)
|
|
386
386
|
return createDocument(data);
|
|
387
|
-
const document = freeze(withInstanceIds(data));
|
|
387
|
+
const document = freeze(withInstanceIds(canonicalDocument(data)));
|
|
388
388
|
validateDocument(document);
|
|
389
389
|
return frozenValid(document);
|
|
390
390
|
}
|
|
@@ -403,6 +403,23 @@ export function parseDocument(text) {
|
|
|
403
403
|
export function transitionInstanceId(trackId, transition) {
|
|
404
404
|
return `${trackId}/transitions/${encodeURIComponent(transition.from_clip)}/${encodeURIComponent(transition.to_clip)}`;
|
|
405
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
|
+
}
|
|
406
423
|
/**
|
|
407
424
|
* Frozen tracks and clips {@link withInstanceIds} found named as they are in a frozen `instanceIds`
|
|
408
425
|
* record.
|
|
@@ -513,9 +530,9 @@ export function withInstanceIds(document) {
|
|
|
513
530
|
const indexes = new WeakMap();
|
|
514
531
|
/** The {@link EntityIndex} of `document`, built once per document object and cached. */
|
|
515
532
|
export function indexDocument(document) {
|
|
516
|
-
|
|
517
|
-
if (
|
|
518
|
-
return
|
|
533
|
+
const known = indexes.get(document);
|
|
534
|
+
if (known)
|
|
535
|
+
return known;
|
|
519
536
|
const tracks = new Map();
|
|
520
537
|
const clips = new Map();
|
|
521
538
|
for (const track of document.project.timeline.tracks) {
|
|
@@ -523,7 +540,7 @@ export function indexDocument(document) {
|
|
|
523
540
|
for (const clip of track.clips ?? [])
|
|
524
541
|
clips.set(clip.id, { clip, trackId: track.id });
|
|
525
542
|
}
|
|
526
|
-
index = { tracks, clips };
|
|
543
|
+
const index = { tracks, clips };
|
|
527
544
|
indexes.set(document, index);
|
|
528
545
|
return index;
|
|
529
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpha2-sh/editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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.1",
|
|
64
64
|
"react": "^19.3.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"alpha2": "0.
|
|
67
|
+
"alpha2": "0.4.1",
|
|
68
68
|
"react": "19.3.0",
|
|
69
69
|
"react-dom": "19.3.0",
|
|
70
70
|
"@types/react": "19.3.0",
|