alpha2 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -5
- package/THIRD_PARTY_NOTICES.md +191 -1
- package/dist/apply-edit.d.ts +124 -0
- package/dist/apply-edit.js +15 -0
- package/dist/assets.d.ts +12 -0
- package/dist/audio-layout.js +6 -3
- package/dist/audio-worklet-processor.js +27 -33
- package/dist/audio.d.ts +5 -4
- package/dist/audio.js +8 -6
- package/dist/compose.d.ts +105 -0
- package/dist/compose.js +63 -0
- package/dist/decoder-fallback.d.ts +3 -2
- package/dist/decoder-fallback.js +11 -3
- package/dist/decoder-stall.d.ts +15 -0
- package/dist/decoder-stall.js +52 -0
- package/dist/edit-data.d.ts +24 -0
- package/dist/edit-data.js +224 -0
- package/dist/edit-keys.d.ts +16 -0
- package/dist/edit-keys.js +233 -0
- package/dist/edit.d.ts +41 -8
- package/dist/edit.js +123 -30
- package/dist/export-failure.d.ts +10 -2
- package/dist/export-failure.js +55 -4
- package/dist/export-retry.d.ts +6 -1
- package/dist/export-retry.js +12 -1
- package/dist/exporter.d.ts +11 -7
- package/dist/exporter.js +10 -9
- package/dist/extensions.d.ts +86 -28
- package/dist/extensions.js +204 -61
- package/dist/extract.d.ts +65 -0
- package/dist/extract.js +291 -0
- package/dist/extractor.d.ts +151 -0
- package/dist/extractor.js +141 -0
- package/dist/float32.d.ts +2 -0
- package/dist/float32.js +10 -0
- package/dist/frame-intake.d.ts +5 -0
- package/dist/frame-intake.js +10 -3
- package/dist/generated/builtin-effects.d.ts +3 -0
- package/dist/generated/builtin-effects.js +1804 -0
- package/dist/generated/project-schema.d.ts +696 -41
- package/dist/generated/project-schema.js +67 -0
- package/dist/generated/project-shape.js +986 -383
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json-text.js +14 -2
- package/dist/layout-values.js +7 -1
- package/dist/layout.d.ts +12 -4
- package/dist/media.d.ts +44 -11
- package/dist/media.js +256 -67
- package/dist/mediabunny.d.ts +32 -12
- package/dist/mediabunny.js +276 -90
- package/dist/player.d.ts +9 -3
- package/dist/player.js +114 -18
- package/dist/plugins.d.ts +62 -0
- package/dist/plugins.js +506 -0
- package/dist/project-data.d.ts +56 -0
- package/dist/project-data.js +765 -0
- package/dist/project.d.ts +36 -1
- package/dist/project.js +515 -42
- package/dist/robustness.d.ts +6 -33
- package/dist/robustness.js +2 -63
- package/dist/sha256.d.ts +3 -2
- package/dist/sha256.js +14 -6
- package/dist/wasm-module.d.ts +37 -0
- package/dist/wasm-module.js +47 -0
- package/dist/worker-error.d.ts +3 -2
- package/dist/worker-error.js +3 -1
- package/dist/worker.d.ts +13 -3
- package/dist/worker.js +36 -9
- package/package.json +36 -2
- package/wasm/alpha2_compose.d.ts +92 -0
- package/wasm/alpha2_compose.js +445 -0
- package/wasm/alpha2_compose_bg.wasm +0 -0
- package/wasm/alpha2_compose_bg.wasm.d.ts +17 -0
- package/wasm/alpha2_extensions.d.ts +4 -4
- package/wasm/alpha2_extensions.js +16 -4
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf.d.ts +227 -0
- package/wasm/alpha2_extensions_pdf.js +841 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm +0 -0
- package/wasm/alpha2_extensions_pdf_bg.wasm.d.ts +38 -0
- package/wasm/alpha2_wasm.d.ts +151 -18
- package/wasm/alpha2_wasm.js +403 -59
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +21 -6
- package/wasm/rust-crate-licenses.md +493 -54
- package/wasm/snippets/alpha2-wasm-1b02e9f302d283ba/inline3.js +7 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline1.js → alpha2-wasm-1b02e9f302d283ba/inline0.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline2.js → alpha2-wasm-1b02e9f302d283ba/inline1.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline3.js → alpha2-wasm-1b02e9f302d283ba/inline2.js} +0 -0
- /package/wasm/snippets/{alpha2-wasm-a21734ffde826659/inline0.js → alpha2-wasm-1b02e9f302d283ba/inline4.js} +0 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// Bus automation under timeline edits, mirroring `shift_keys` in `alpha2_eval::edit` and
|
|
2
|
+
// `CubicBezier::between` in `alpha2_model`.
|
|
3
|
+
import { shortestFloat32 } from "./float32.js";
|
|
4
|
+
const NEWTON_STEPS = 8;
|
|
5
|
+
const BISECTION_STEPS = 64;
|
|
6
|
+
const TOLERANCE = 1e-12;
|
|
7
|
+
const MIN_SLOPE = 1e-9;
|
|
8
|
+
const F32_MAX = 3.4028234663852886e38;
|
|
9
|
+
function component(t, p1, p2) {
|
|
10
|
+
const c = 3 * p1;
|
|
11
|
+
const b = 3 * (p2 - p1) - c;
|
|
12
|
+
const a = 1 - c - b;
|
|
13
|
+
return ((a * t + b) * t + c) * t;
|
|
14
|
+
}
|
|
15
|
+
function slope(t, p1, p2) {
|
|
16
|
+
const c = 3 * p1;
|
|
17
|
+
const b = 3 * (p2 - p1) - c;
|
|
18
|
+
const a = 1 - c - b;
|
|
19
|
+
return (3 * a * t + 2 * b) * t + c;
|
|
20
|
+
}
|
|
21
|
+
/** The Bezier parameter whose `x` is `x` in `(0, 1)` (mirrors `CubicBezier::parameter_at`). */
|
|
22
|
+
function parameterAt(x, x1, x2) {
|
|
23
|
+
let parameter = x;
|
|
24
|
+
for (let step = 0; step < NEWTON_STEPS; step += 1) {
|
|
25
|
+
const error = component(parameter, x1, x2) - x;
|
|
26
|
+
if (Math.abs(error) < TOLERANCE) {
|
|
27
|
+
if (parameter >= 0 && parameter <= 1)
|
|
28
|
+
return parameter;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
const steepness = slope(parameter, x1, x2);
|
|
32
|
+
if (Math.abs(steepness) < MIN_SLOPE)
|
|
33
|
+
break;
|
|
34
|
+
parameter -= error / steepness;
|
|
35
|
+
}
|
|
36
|
+
let low = 0;
|
|
37
|
+
let high = 1;
|
|
38
|
+
parameter = x;
|
|
39
|
+
for (let step = 0; step < BISECTION_STEPS; step += 1) {
|
|
40
|
+
const value = component(parameter, x1, x2);
|
|
41
|
+
if (Math.abs(value - x) < TOLERANCE)
|
|
42
|
+
break;
|
|
43
|
+
if (value < x)
|
|
44
|
+
low = parameter;
|
|
45
|
+
else
|
|
46
|
+
high = parameter;
|
|
47
|
+
parameter = low + (high - low) * 0.5;
|
|
48
|
+
}
|
|
49
|
+
return parameter;
|
|
50
|
+
}
|
|
51
|
+
/** Mirrors `CubicBezier::apply`. */
|
|
52
|
+
function apply(curve, progress) {
|
|
53
|
+
const x = Math.min(1, Math.max(0, progress));
|
|
54
|
+
if (x <= 0)
|
|
55
|
+
return 0;
|
|
56
|
+
if (x >= 1)
|
|
57
|
+
return 1;
|
|
58
|
+
const parameter = parameterAt(x, Math.fround(curve.x1), Math.fround(curve.x2));
|
|
59
|
+
return component(parameter, Math.fround(curve.y1), Math.fround(curve.y2));
|
|
60
|
+
}
|
|
61
|
+
function blossom(points, u, v, w) {
|
|
62
|
+
const lerp = (a, b, t) => a + (b - a) * t;
|
|
63
|
+
const first = [
|
|
64
|
+
lerp(points[0], points[1], u),
|
|
65
|
+
lerp(points[1], points[2], u),
|
|
66
|
+
lerp(points[2], points[3], u),
|
|
67
|
+
];
|
|
68
|
+
return lerp(lerp(first[0], first[1], v), lerp(first[1], first[2], v), w);
|
|
69
|
+
}
|
|
70
|
+
/** The part of `curve` between linear progress `from` and `to`, rescaled (mirrors `between`). */
|
|
71
|
+
function between(curve, from, to) {
|
|
72
|
+
const x1 = Math.fround(curve.x1);
|
|
73
|
+
const x2 = Math.fround(curve.x2);
|
|
74
|
+
const at = (progress) => progress <= 0 ? 0 : progress >= 1 ? 1 : parameterAt(progress, x1, x2);
|
|
75
|
+
const [u, v] = [at(from), at(to)];
|
|
76
|
+
const part = (p1, p2) => {
|
|
77
|
+
const points = [0, p1, p2, 1];
|
|
78
|
+
return [
|
|
79
|
+
blossom(points, u, u, u),
|
|
80
|
+
blossom(points, u, u, v),
|
|
81
|
+
blossom(points, u, v, v),
|
|
82
|
+
blossom(points, v, v, v),
|
|
83
|
+
];
|
|
84
|
+
};
|
|
85
|
+
const x = part(x1, x2);
|
|
86
|
+
const y = part(Math.fround(curve.y1), Math.fround(curve.y2));
|
|
87
|
+
const width = x[3] - x[0];
|
|
88
|
+
const height = y[3] - y[0];
|
|
89
|
+
if (!(width > 0) || height === 0)
|
|
90
|
+
return undefined;
|
|
91
|
+
const unit = (value) => Math.min(1, Math.max(0, value));
|
|
92
|
+
const result = {
|
|
93
|
+
type: "cubic_bezier",
|
|
94
|
+
x1: shortestFloat32(unit((x[1] - x[0]) / width)),
|
|
95
|
+
y1: shortestFloat32((y[1] - y[0]) / height),
|
|
96
|
+
x2: shortestFloat32(unit((x[2] - x[0]) / width)),
|
|
97
|
+
y2: shortestFloat32((y[2] - y[0]) / height),
|
|
98
|
+
};
|
|
99
|
+
return [result.x1, result.y1, result.x2, result.y2].every(Number.isFinite)
|
|
100
|
+
? result
|
|
101
|
+
: undefined;
|
|
102
|
+
}
|
|
103
|
+
/** The value of keyframes `keys` at `tick` (mirrors the scalar keyframe sampler). */
|
|
104
|
+
function valueAt(keys, tick) {
|
|
105
|
+
let next = 0;
|
|
106
|
+
for (let high = keys.length; next < high;) {
|
|
107
|
+
const middle = (next + high) >> 1;
|
|
108
|
+
if (keys[middle].time <= tick)
|
|
109
|
+
next = middle + 1;
|
|
110
|
+
else
|
|
111
|
+
high = middle;
|
|
112
|
+
}
|
|
113
|
+
if (next === 0)
|
|
114
|
+
return Math.fround(keys[0].value);
|
|
115
|
+
const left = keys[next - 1];
|
|
116
|
+
const right = keys[next];
|
|
117
|
+
if (!right || tick === left.time)
|
|
118
|
+
return Math.fround(left.value);
|
|
119
|
+
const progress = (tick - left.time) / (right.time - left.time);
|
|
120
|
+
const interpolation = left.interpolation;
|
|
121
|
+
const amount = interpolation.type === "hold"
|
|
122
|
+
? undefined
|
|
123
|
+
: interpolation.type === "linear"
|
|
124
|
+
? Math.min(1, Math.max(0, progress))
|
|
125
|
+
: apply(interpolation, progress);
|
|
126
|
+
if (amount === undefined)
|
|
127
|
+
return Math.fround(left.value);
|
|
128
|
+
const start = Math.fround(left.value);
|
|
129
|
+
const end = Math.fround(right.value);
|
|
130
|
+
return Math.fround(Math.min(F32_MAX, Math.max(-F32_MAX, start + (end - start) * amount)));
|
|
131
|
+
}
|
|
132
|
+
/** The interpolation showing the old curve from `from` to `to` (mirrors `part_of_curve`). */
|
|
133
|
+
function partOfCurve(keys, from, to) {
|
|
134
|
+
let next = 0;
|
|
135
|
+
while (next < keys.length && keys[next].time <= from)
|
|
136
|
+
next += 1;
|
|
137
|
+
const start = keys[next - 1];
|
|
138
|
+
const end = keys[next];
|
|
139
|
+
if (!start || !end)
|
|
140
|
+
return undefined;
|
|
141
|
+
const interpolation = start.interpolation;
|
|
142
|
+
if (interpolation.type !== "cubic_bezier")
|
|
143
|
+
return interpolation;
|
|
144
|
+
if (from === start.time && to === end.time)
|
|
145
|
+
return interpolation;
|
|
146
|
+
const span = end.time - start.time;
|
|
147
|
+
return (between(interpolation, (from - start.time) / span, (to - start.time) / span) ?? {
|
|
148
|
+
type: "linear",
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function shiftOf(tick, removal) {
|
|
152
|
+
let shift = 0;
|
|
153
|
+
for (const [from, to] of removal)
|
|
154
|
+
shift += to <= tick ? to - from : from < tick ? tick - from : 0;
|
|
155
|
+
return shift;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Bus keyframes after `removal` leaves a rippled timeline: keys inside go, the rest move, the
|
|
159
|
+
* value at each cut is keyed on both sides, and every key takes the part of the old curve up to
|
|
160
|
+
* the next key (mirrors `shift_keys`).
|
|
161
|
+
*/
|
|
162
|
+
export function closeKeys(animation, removal) {
|
|
163
|
+
if (animation?.mode !== "keyframes" || !removal.length)
|
|
164
|
+
return animation;
|
|
165
|
+
const old = animation.keyframes;
|
|
166
|
+
const removed = (tick) => removal.some(([from, to]) => from <= tick && tick < to);
|
|
167
|
+
const at = [];
|
|
168
|
+
old.forEach((key, index) => {
|
|
169
|
+
if (!removed(key.time))
|
|
170
|
+
at.push([key.time, index]);
|
|
171
|
+
});
|
|
172
|
+
for (const [from, to] of removal) {
|
|
173
|
+
if (from - 1 - shiftOf(from - 1, removal) >= 0)
|
|
174
|
+
at.push([from - 1, undefined]);
|
|
175
|
+
at.push([to, undefined]);
|
|
176
|
+
}
|
|
177
|
+
at.sort((a, b) => a[0] - b[0] || Number(a[1] === undefined) - Number(b[1] === undefined));
|
|
178
|
+
const unique = at.filter((entry, index) => index === 0 || at[index - 1][0] !== entry[0]);
|
|
179
|
+
const keyframes = unique.map(([tick, kept], position) => {
|
|
180
|
+
const next = unique[position + 1]?.[0];
|
|
181
|
+
const own = kept === undefined ? undefined : old[kept].interpolation;
|
|
182
|
+
const interpolation = next === undefined
|
|
183
|
+
? (own ?? { type: "linear" })
|
|
184
|
+
: removal.some(([from, to]) => tick < from && to <= next)
|
|
185
|
+
? { type: "hold" }
|
|
186
|
+
: (partOfCurve(old, tick, next) ?? own ?? { type: "linear" });
|
|
187
|
+
return {
|
|
188
|
+
time: tick - shiftOf(tick, removal),
|
|
189
|
+
value: kept === undefined
|
|
190
|
+
? shortestFloat32(valueAt(old, tick))
|
|
191
|
+
: old[kept].value,
|
|
192
|
+
interpolation,
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
return { ...animation, keyframes };
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Bus keyframes after `length` ticks open at `pivot`: keys at or after it move right, and when
|
|
199
|
+
* keys lie on both sides the value at `pivot` is held across the opening, so every moment outside
|
|
200
|
+
* it reads as before.
|
|
201
|
+
*/
|
|
202
|
+
export function openKeys(animation, pivot, length) {
|
|
203
|
+
if (animation?.mode !== "keyframes" || !length)
|
|
204
|
+
return animation;
|
|
205
|
+
const old = animation.keyframes;
|
|
206
|
+
const before = old.filter((key) => key.time < pivot);
|
|
207
|
+
const after = old.filter((key) => key.time >= pivot);
|
|
208
|
+
const moved = after.map((key) => ({ ...key, time: key.time + length }));
|
|
209
|
+
if (!before.length || !after.length)
|
|
210
|
+
return { ...animation, keyframes: [...before, ...moved] };
|
|
211
|
+
const held = shortestFloat32(valueAt(old, pivot));
|
|
212
|
+
const last = before[before.length - 1];
|
|
213
|
+
const head = before.slice(0, -1);
|
|
214
|
+
const keyframes = [
|
|
215
|
+
...head,
|
|
216
|
+
{
|
|
217
|
+
...last,
|
|
218
|
+
interpolation: partOfCurve(old, last.time, pivot) ?? last.interpolation,
|
|
219
|
+
},
|
|
220
|
+
{ time: pivot, value: held, interpolation: { type: "hold" } },
|
|
221
|
+
];
|
|
222
|
+
if (after[0].time === pivot)
|
|
223
|
+
keyframes.push(...moved);
|
|
224
|
+
else
|
|
225
|
+
keyframes.push({
|
|
226
|
+
time: pivot + length,
|
|
227
|
+
value: held,
|
|
228
|
+
interpolation: partOfCurve(old, pivot, after[0].time) ?? {
|
|
229
|
+
type: "linear",
|
|
230
|
+
},
|
|
231
|
+
}, ...moved);
|
|
232
|
+
return { ...animation, keyframes };
|
|
233
|
+
}
|
package/dist/edit.d.ts
CHANGED
|
@@ -17,7 +17,12 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Ripple edits move later content on the edited track and on `syncTracks` by the same amount. A
|
|
19
19
|
* sync track with content across the edit point, or where pulled content would land on content
|
|
20
|
-
* that stays, refuses the whole edit (`sync_conflict`).
|
|
20
|
+
* that stays, refuses the whole edit (`sync_conflict`). The track and bus keyframes of every track
|
|
21
|
+
* a ripple reaches move with it; a ripple that reaches every track also edits the master bus keys
|
|
22
|
+
* and timeline-anchored data sets, as the engine's `remove_ranges` with `ripple: "timeline"` does.
|
|
23
|
+
* Time the edit closes is cut out of them and time it opens opens in them. Source-anchored data
|
|
24
|
+
* never changes. A ripple's result reports the change in `timeline`, so a host can move its own
|
|
25
|
+
* timeline items (markers) by the same rule.
|
|
21
26
|
*
|
|
22
27
|
* Use {@link deferValidation} for a batch of edits that is valid only as a whole.
|
|
23
28
|
*/
|
|
@@ -38,6 +43,8 @@ export type EditErrorCode =
|
|
|
38
43
|
| "in_fade"
|
|
39
44
|
/** Another clip uses this one as its matte. */
|
|
40
45
|
| "matte_source"
|
|
46
|
+
/** A data binding of another clip reads through this one (`via`). */
|
|
47
|
+
| "read_through"
|
|
41
48
|
/** A loop cannot start part way through a pass. */
|
|
42
49
|
| "unsupported_time_map"
|
|
43
50
|
/** The clip's source kind does not belong on that track. */
|
|
@@ -59,10 +66,29 @@ export interface EditError {
|
|
|
59
66
|
/** For `invalid_result`, what {@link validateProject} reported. */
|
|
60
67
|
readonly problems?: readonly string[];
|
|
61
68
|
}
|
|
62
|
-
/**
|
|
69
|
+
/** What a ripple did to timeline time. Ticks are the old timeline's. */
|
|
70
|
+
export interface TimelineChange {
|
|
71
|
+
/** The time the ripple closed. */
|
|
72
|
+
readonly removed?: TimeRange;
|
|
73
|
+
/** The time the ripple opened: `length` ticks at `at`. */
|
|
74
|
+
readonly opened?: {
|
|
75
|
+
readonly at: number;
|
|
76
|
+
readonly length: number;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Whether the ripple reached every track, so the master bus keys and timeline data moved and a
|
|
80
|
+
* host's own timeline items should too.
|
|
81
|
+
*/
|
|
82
|
+
readonly everyTrack: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The new project, or why the edit was refused. The input is never modified. A ripple that moved
|
|
86
|
+
* time reports how in `timeline`.
|
|
87
|
+
*/
|
|
63
88
|
export type EditResult = {
|
|
64
89
|
readonly ok: true;
|
|
65
90
|
readonly project: Project;
|
|
91
|
+
readonly timeline?: TimelineChange;
|
|
66
92
|
} | {
|
|
67
93
|
readonly ok: false;
|
|
68
94
|
readonly error: EditError;
|
|
@@ -81,8 +107,8 @@ export interface PlaceOptions extends RippleOptions {
|
|
|
81
107
|
/**
|
|
82
108
|
* Splits a clip at `at`. The left part keeps the id, incoming transitions and fade in; the right
|
|
83
109
|
* part becomes `newId` with outgoing transitions, fade out, and its own copy of the composition
|
|
84
|
-
* ({@link copyComposition}).
|
|
85
|
-
* loop.
|
|
110
|
+
* ({@link copyComposition}). The right part's bindings that read through the clip read through
|
|
111
|
+
* `newId`. Refused inside a transition or fade, for a matte source, and for a loop.
|
|
86
112
|
*/
|
|
87
113
|
export declare function split(project: Project, clipId: string, at: number, newId: string): EditResult;
|
|
88
114
|
/**
|
|
@@ -92,12 +118,14 @@ export declare function split(project: Project, clipId: string, at: number, newI
|
|
|
92
118
|
export declare function trim(project: Project, clipId: string, edge: ClipEdge, to: number): EditResult;
|
|
93
119
|
/**
|
|
94
120
|
* Trims like {@link trim} and shifts later clips on the track by the same amount. A start trim
|
|
95
|
-
* keeps the clip's start in place, so `to` may be before the timeline start.
|
|
121
|
+
* keeps the clip's start in place, so `to` may be before the timeline start. Sync tracks and
|
|
122
|
+
* timeline data close or open time at the trimmed edge, which for a start trim is the clip's start.
|
|
96
123
|
*/
|
|
97
124
|
export declare function rippleTrim(project: Project, clipId: string, edge: ClipEdge, to: number, options?: RippleOptions): EditResult;
|
|
98
125
|
/**
|
|
99
126
|
* Removes a clip and its transitions and closes the gap ({@link rippleDeleteSpan}). Refused for a
|
|
100
|
-
* matte source, and when a sync track has content
|
|
127
|
+
* matte source, for a clip another clip's binding reads through, and when a sync track has content
|
|
128
|
+
* in that span.
|
|
101
129
|
*/
|
|
102
130
|
export declare function rippleDelete(project: Project, clipId: string, options?: RippleOptions): EditResult;
|
|
103
131
|
/**
|
|
@@ -165,8 +193,8 @@ export declare function insert(project: Project, trackId: string, clip: Clip, at
|
|
|
165
193
|
/**
|
|
166
194
|
* Places `clip` at `at`, replacing whatever the track shows there. Clips inside are removed, clips
|
|
167
195
|
* across an edge are trimmed, and a clip across both is split (right part `splitId`). Refused where
|
|
168
|
-
* a transition
|
|
169
|
-
* edges.
|
|
196
|
+
* a transition, matte source or clip a binding reads through would be cut, and (`needs_id`) when
|
|
197
|
+
* more than one clip spans both edges.
|
|
170
198
|
*/
|
|
171
199
|
export declare function overwrite(project: Project, trackId: string, clip: Clip, at: number, options?: PlaceOptions): EditResult;
|
|
172
200
|
/** Places `clip` after the track's last clip, or at 0. */
|
|
@@ -196,6 +224,11 @@ export declare function moveClips(project: Project, moves: readonly ClipMove[]):
|
|
|
196
224
|
* synchronous and may nest.
|
|
197
225
|
*/
|
|
198
226
|
export declare function deferValidation<T>(run: () => T): T;
|
|
227
|
+
/**
|
|
228
|
+
* Gives `clip` the id `id`, for a paste or a duplicate. Its bindings that read through itself
|
|
229
|
+
* read through `id`, and those through other clips stay.
|
|
230
|
+
*/
|
|
231
|
+
export declare function withClipId(clip: Clip, id: string): Clip;
|
|
199
232
|
/**
|
|
200
233
|
* Copies composition `id` and every group definition it draws (recursively) so clip `clipId` can
|
|
201
234
|
* be edited independently. Copies take the first free id of `<root>~<clipId>`, `<root>~<clipId>~2`
|
package/dist/edit.js
CHANGED
|
@@ -17,16 +17,24 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Ripple edits move later content on the edited track and on `syncTracks` by the same amount. A
|
|
19
19
|
* sync track with content across the edit point, or where pulled content would land on content
|
|
20
|
-
* that stays, refuses the whole edit (`sync_conflict`).
|
|
20
|
+
* that stays, refuses the whole edit (`sync_conflict`). The track and bus keyframes of every track
|
|
21
|
+
* a ripple reaches move with it; a ripple that reaches every track also edits the master bus keys
|
|
22
|
+
* and timeline-anchored data sets, as the engine's `remove_ranges` with `ripple: "timeline"` does.
|
|
23
|
+
* Time the edit closes is cut out of them and time it opens opens in them. Source-anchored data
|
|
24
|
+
* never changes. A ripple's result reports the change in `timeline`, so a host can move its own
|
|
25
|
+
* timeline items (markers) by the same rule.
|
|
21
26
|
*
|
|
22
27
|
* Use {@link deferValidation} for a batch of edits that is valid only as a whole.
|
|
23
28
|
*/
|
|
24
29
|
import { validateProject } from "./project.js";
|
|
30
|
+
import { dataReferences } from "./project-data.js";
|
|
31
|
+
import { renameVia, rippleTimelineData } from "./edit-data.js";
|
|
32
|
+
import { closeKeys, openKeys } from "./edit-keys.js";
|
|
25
33
|
/**
|
|
26
34
|
* Splits a clip at `at`. The left part keeps the id, incoming transitions and fade in; the right
|
|
27
35
|
* part becomes `newId` with outgoing transitions, fade out, and its own copy of the composition
|
|
28
|
-
* ({@link copyComposition}).
|
|
29
|
-
* loop.
|
|
36
|
+
* ({@link copyComposition}). The right part's bindings that read through the clip read through
|
|
37
|
+
* `newId`. Refused inside a transition or fade, for a matte source, and for a loop.
|
|
30
38
|
*/
|
|
31
39
|
export function split(project, clipId, at, newId) {
|
|
32
40
|
const time = notTicks(at, "the split time");
|
|
@@ -77,9 +85,8 @@ export function split(project, clipId, at, newId) {
|
|
|
77
85
|
id: copy.id,
|
|
78
86
|
};
|
|
79
87
|
}
|
|
80
|
-
const right = {
|
|
88
|
+
const right = withClipId({
|
|
81
89
|
...clip,
|
|
82
|
-
id: newId,
|
|
83
90
|
timeline_range: { start: at, end: range.end },
|
|
84
91
|
source_range: sources.right,
|
|
85
92
|
...(audio?.fade_in === undefined
|
|
@@ -88,7 +95,7 @@ export function split(project, clipId, at, newId) {
|
|
|
88
95
|
...(rightComposition === undefined
|
|
89
96
|
? {}
|
|
90
97
|
: { composition: rightComposition }),
|
|
91
|
-
};
|
|
98
|
+
}, newId);
|
|
92
99
|
const transitions = (track.transitions ?? []).map((transition) => transition.from_clip === clipId
|
|
93
100
|
? { ...transition, from_clip: newId }
|
|
94
101
|
: transition);
|
|
@@ -113,7 +120,8 @@ export function trim(project, clipId, edge, to) {
|
|
|
113
120
|
}
|
|
114
121
|
/**
|
|
115
122
|
* Trims like {@link trim} and shifts later clips on the track by the same amount. A start trim
|
|
116
|
-
* keeps the clip's start in place, so `to` may be before the timeline start.
|
|
123
|
+
* keeps the clip's start in place, so `to` may be before the timeline start. Sync tracks and
|
|
124
|
+
* timeline data close or open time at the trimmed edge, which for a start trim is the clip's start.
|
|
117
125
|
*/
|
|
118
126
|
export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
119
127
|
const time = notTicks(to, "the trim time");
|
|
@@ -126,6 +134,7 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
|
126
134
|
const before = trimmed.original.timeline_range;
|
|
127
135
|
let edited = clip;
|
|
128
136
|
let delta;
|
|
137
|
+
let pivot = before.end;
|
|
129
138
|
if (edge === "end") {
|
|
130
139
|
delta = to - before.end;
|
|
131
140
|
}
|
|
@@ -133,9 +142,14 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
|
133
142
|
// Trim the head, then slide the clip back to its original start.
|
|
134
143
|
delta = before.start - to;
|
|
135
144
|
edited = shift(clip, delta);
|
|
145
|
+
pivot = before.start;
|
|
136
146
|
}
|
|
137
147
|
if (pullsOnto(track, before.end, delta, clipId))
|
|
138
148
|
return pulledOnto(track);
|
|
149
|
+
if (edge === "start" && delta < 0)
|
|
150
|
+
for (const other of syncTracksOf(project, options.syncTracks, track.id))
|
|
151
|
+
if (occupies(other, { start: before.start, end: to }))
|
|
152
|
+
return failure("sync_conflict", `track ${other.id} has content in the time the trim closes`);
|
|
139
153
|
const shifted = (track.clips ?? []).map((candidate) => {
|
|
140
154
|
if (candidate.id === clipId)
|
|
141
155
|
return edited;
|
|
@@ -143,18 +157,23 @@ export function rippleTrim(project, clipId, edge, to, options = {}) {
|
|
|
143
157
|
? shift(candidate, delta)
|
|
144
158
|
: candidate;
|
|
145
159
|
});
|
|
146
|
-
|
|
147
|
-
if (!synced.ok)
|
|
148
|
-
return synced;
|
|
149
|
-
return finish(replaceTrack(synced.project, {
|
|
160
|
+
return rippled(replaceTrack(project, {
|
|
150
161
|
...track,
|
|
151
162
|
clips: shifted,
|
|
152
163
|
transitions: shiftTransitions(track, before.end, delta),
|
|
153
|
-
})
|
|
164
|
+
}), track.id, options.syncTracks, delta < 0
|
|
165
|
+
? {
|
|
166
|
+
removed: {
|
|
167
|
+
start: pivot + (edge === "start" ? 0 : delta),
|
|
168
|
+
end: edge === "start" ? to : pivot,
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
: { opened: { at: pivot, length: delta } });
|
|
154
172
|
}
|
|
155
173
|
/**
|
|
156
174
|
* Removes a clip and its transitions and closes the gap ({@link rippleDeleteSpan}). Refused for a
|
|
157
|
-
* matte source, and when a sync track has content
|
|
175
|
+
* matte source, for a clip another clip's binding reads through, and when a sync track has content
|
|
176
|
+
* in that span.
|
|
158
177
|
*/
|
|
159
178
|
export function rippleDelete(project, clipId, options = {}) {
|
|
160
179
|
const found = locate(project, clipId);
|
|
@@ -164,6 +183,9 @@ export function rippleDelete(project, clipId, options = {}) {
|
|
|
164
183
|
if (isMatteSource(project, clipId)) {
|
|
165
184
|
return failure("matte_source", `clip ${clipId} is another clip's matte`);
|
|
166
185
|
}
|
|
186
|
+
const reader = readThrough(project, clipId);
|
|
187
|
+
if (reader)
|
|
188
|
+
return reader;
|
|
167
189
|
const range = clip.timeline_range;
|
|
168
190
|
const gap = aloneSpan(track, clip);
|
|
169
191
|
const delta = gap.start - gap.end;
|
|
@@ -180,10 +202,7 @@ export function rippleDelete(project, clipId, options = {}) {
|
|
|
180
202
|
for (const other of syncTracksOf(project, options.syncTracks, track.id))
|
|
181
203
|
if (occupies(other, gap))
|
|
182
204
|
return failure("sync_conflict", `track ${other.id} has content in the time the delete closes`);
|
|
183
|
-
|
|
184
|
-
if (!synced.ok)
|
|
185
|
-
return synced;
|
|
186
|
-
return finish(replaceTrack(synced.project, { ...track, clips, transitions }));
|
|
205
|
+
return rippled(replaceTrack(project, { ...track, clips, transitions }), track.id, options.syncTracks, { removed: gap });
|
|
187
206
|
}
|
|
188
207
|
/**
|
|
189
208
|
* The span {@link rippleDelete} closes: the part of the clip's span no other clip on its track
|
|
@@ -432,14 +451,13 @@ export function retime(project, clipId, duration, options = {}) {
|
|
|
432
451
|
: candidate.timeline_range.start >= range.end
|
|
433
452
|
? shift(candidate, delta)
|
|
434
453
|
: candidate);
|
|
435
|
-
|
|
436
|
-
if (!synced.ok)
|
|
437
|
-
return synced;
|
|
438
|
-
return finish(replaceTrack(synced.project, {
|
|
454
|
+
return rippled(replaceTrack(project, {
|
|
439
455
|
...track,
|
|
440
456
|
clips,
|
|
441
457
|
transitions: shiftTransitions(track, range.end, delta),
|
|
442
|
-
})
|
|
458
|
+
}), track.id, options.syncTracks, delta < 0
|
|
459
|
+
? { removed: { start: range.end + delta, end: range.end } }
|
|
460
|
+
: { opened: { at: range.end, length: delta } });
|
|
443
461
|
}
|
|
444
462
|
/**
|
|
445
463
|
* Inserts `clip` at `at`, pushing later content on the track and `syncTracks` by its length. A clip
|
|
@@ -465,23 +483,20 @@ export function insert(project, trackId, clip, at, options = {}) {
|
|
|
465
483
|
track = edited.timeline.tracks.find((t) => t.id === trackId);
|
|
466
484
|
}
|
|
467
485
|
const length = placed.clip.timeline_range.end - at;
|
|
468
|
-
|
|
469
|
-
if (!synced.ok)
|
|
470
|
-
return synced;
|
|
471
|
-
return finish(replaceTrack(synced.project, {
|
|
486
|
+
return rippled(replaceTrack(edited, {
|
|
472
487
|
...track,
|
|
473
488
|
clips: [
|
|
474
489
|
...(track.clips ?? []).map((c) => c.timeline_range.start >= at ? shift(c, length) : c),
|
|
475
490
|
placed.clip,
|
|
476
491
|
],
|
|
477
492
|
transitions: shiftTransitions(track, at, length),
|
|
478
|
-
}));
|
|
493
|
+
}), trackId, options.syncTracks, { opened: { at, length } });
|
|
479
494
|
}
|
|
480
495
|
/**
|
|
481
496
|
* Places `clip` at `at`, replacing whatever the track shows there. Clips inside are removed, clips
|
|
482
497
|
* across an edge are trimmed, and a clip across both is split (right part `splitId`). Refused where
|
|
483
|
-
* a transition
|
|
484
|
-
* edges.
|
|
498
|
+
* a transition, matte source or clip a binding reads through would be cut, and (`needs_id`) when
|
|
499
|
+
* more than one clip spans both edges.
|
|
485
500
|
*/
|
|
486
501
|
export function overwrite(project, trackId, clip, at, options = {}) {
|
|
487
502
|
const placed = placeAt(project, trackId, clip, at);
|
|
@@ -516,6 +531,9 @@ export function overwrite(project, trackId, clip, at, options = {}) {
|
|
|
516
531
|
if (start >= range.start && end <= range.end) {
|
|
517
532
|
if (isMatteSource(edited, candidate.id))
|
|
518
533
|
return failure("matte_source", `clip ${candidate.id} is another clip's matte`);
|
|
534
|
+
const reader = readThrough(edited, candidate.id);
|
|
535
|
+
if (reader)
|
|
536
|
+
return reader;
|
|
519
537
|
continue;
|
|
520
538
|
}
|
|
521
539
|
const edge = start < range.start ? "end" : "start";
|
|
@@ -596,7 +614,7 @@ function rippleSyncTracks(project, ids, edited, pivot, delta) {
|
|
|
596
614
|
? {
|
|
597
615
|
captions: {
|
|
598
616
|
...track.captions,
|
|
599
|
-
cues: track.captions.cues.map((cue) => cue.timeline_range.start >= pivot
|
|
617
|
+
cues: (track.captions.cues ?? []).map((cue) => cue.timeline_range.start >= pivot
|
|
600
618
|
? {
|
|
601
619
|
...cue,
|
|
602
620
|
timeline_range: offset(cue.timeline_range, delta),
|
|
@@ -901,6 +919,81 @@ function transitionsOf(track, clipId) {
|
|
|
901
919
|
function isMatteSource(project, clipId) {
|
|
902
920
|
return project.timeline.tracks.some((track) => (track.clips ?? []).some((clip) => clip.matte?.source === clipId));
|
|
903
921
|
}
|
|
922
|
+
/** The `read_through` refusal when a binding of another clip reads through `clipId`. */
|
|
923
|
+
function readThrough(project, clipId) {
|
|
924
|
+
if (!project.data?.length)
|
|
925
|
+
return undefined;
|
|
926
|
+
const reader = dataReferences(project).find((reference) => reference.via !== undefined &&
|
|
927
|
+
"clip" in reference.via &&
|
|
928
|
+
reference.via.clip === clipId &&
|
|
929
|
+
!(reference.owner.kind === "clip" && reference.owner.clip === clipId));
|
|
930
|
+
if (!reader)
|
|
931
|
+
return undefined;
|
|
932
|
+
const owner = reader.owner.kind === "clip" ? `clip ${reader.owner.clip} ` : "";
|
|
933
|
+
return failure("read_through", `${owner}${reader.property} reads data through clip ${clipId}`);
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Gives `clip` the id `id`, for a paste or a duplicate. Its bindings that read through itself
|
|
937
|
+
* read through `id`, and those through other clips stay.
|
|
938
|
+
*/
|
|
939
|
+
export function withClipId(clip, id) {
|
|
940
|
+
return { ...renameVia(clip, clip.id, id), id };
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Finishes a ripple whose edited track `trackId` is already in `project`: sync tracks shift (or
|
|
944
|
+
* refuse), the bus keys of every reached track move, and when the ripple reaches every track the
|
|
945
|
+
* master bus keys and timeline data move too. The one place a ripple changes time beyond its track.
|
|
946
|
+
*/
|
|
947
|
+
function rippled(project, trackId, syncTracks, change) {
|
|
948
|
+
const removed = "removed" in change ? change.removed : undefined;
|
|
949
|
+
const opened = "opened" in change ? change.opened : undefined;
|
|
950
|
+
const pivot = removed ? removed.end : opened.at;
|
|
951
|
+
const delta = removed ? removed.start - removed.end : opened.length;
|
|
952
|
+
if (delta === 0)
|
|
953
|
+
return finish(project);
|
|
954
|
+
const synced = rippleSyncTracks(project, syncTracks, trackId, pivot, delta);
|
|
955
|
+
if (!synced.ok)
|
|
956
|
+
return synced;
|
|
957
|
+
const reached = new Set([
|
|
958
|
+
trackId,
|
|
959
|
+
...syncTracksOf(project, syncTracks, trackId).map((track) => track.id),
|
|
960
|
+
]);
|
|
961
|
+
const everyTrack = project.timeline.tracks.every((track) => reached.has(track.id));
|
|
962
|
+
const keys = (value) => (removed
|
|
963
|
+
? closeKeys(value, [[removed.start, removed.end]])
|
|
964
|
+
: openKeys(value, opened.at, opened.length));
|
|
965
|
+
let result = {
|
|
966
|
+
...synced.project,
|
|
967
|
+
timeline: {
|
|
968
|
+
...synced.project.timeline,
|
|
969
|
+
tracks: synced.project.timeline.tracks.map((track) => reached.has(track.id) && track.audio
|
|
970
|
+
? {
|
|
971
|
+
...track,
|
|
972
|
+
audio: {
|
|
973
|
+
...track.audio,
|
|
974
|
+
...(track.audio.gain ? { gain: keys(track.audio.gain) } : {}),
|
|
975
|
+
...(track.audio.pan ? { pan: keys(track.audio.pan) } : {}),
|
|
976
|
+
},
|
|
977
|
+
}
|
|
978
|
+
: track),
|
|
979
|
+
},
|
|
980
|
+
};
|
|
981
|
+
if (everyTrack) {
|
|
982
|
+
if (result.audio?.gain)
|
|
983
|
+
result = {
|
|
984
|
+
...result,
|
|
985
|
+
audio: { ...result.audio, gain: keys(result.audio.gain) },
|
|
986
|
+
};
|
|
987
|
+
result = rippleTimelineData(result, pivot, delta);
|
|
988
|
+
}
|
|
989
|
+
const finished = finish(result);
|
|
990
|
+
return finished.ok
|
|
991
|
+
? {
|
|
992
|
+
...finished,
|
|
993
|
+
timeline: { ...(removed ? { removed } : { opened }), everyTrack },
|
|
994
|
+
}
|
|
995
|
+
: finished;
|
|
996
|
+
}
|
|
904
997
|
function replaceTrack(project, track) {
|
|
905
998
|
return {
|
|
906
999
|
...project,
|
package/dist/export-failure.d.ts
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Failure class. `RESOURCE_LIMIT` means the export was stopped before exceeding a budget.
|
|
9
9
|
* `RESOURCE_BUSY` means a device is held by other work (for example all hardware encoder
|
|
10
|
-
* sessions) and may free up later.
|
|
10
|
+
* sessions) and may free up later. `DEFECT` is an engine fault (a panic or a wasm trap), which a
|
|
11
|
+
* fresh worker or host may not repeat.
|
|
11
12
|
*/
|
|
12
|
-
export type ExportFailureCode = "OUT_OF_MEMORY" | "ALLOCATION_FAILED" | "DEVICE_LOST" | "DEVICE_HUNG" | "READBACK_FAILED" | "GPU_TIMEOUT" | "VALIDATION_FAILED" | "INVALID_INPUT" | "HOST_EXITED" | "OUTPUT_IO_FAILED" | "STORAGE_QUOTA_EXCEEDED" | "RESOURCE_LIMIT" | "RESOURCE_BUSY" | "CANCELLED" | "UNKNOWN";
|
|
13
|
+
export type ExportFailureCode = "OUT_OF_MEMORY" | "ALLOCATION_FAILED" | "DEVICE_LOST" | "DEVICE_HUNG" | "READBACK_FAILED" | "GPU_TIMEOUT" | "VALIDATION_FAILED" | "INVALID_INPUT" | "HOST_EXITED" | "OUTPUT_IO_FAILED" | "STORAGE_QUOTA_EXCEEDED" | "RESOURCE_LIMIT" | "RESOURCE_BUSY" | "CANCELLED" | "DEFECT" | "UNKNOWN";
|
|
13
14
|
/** Export step a failure belongs to. Steps overlap in a pipelined export. */
|
|
14
15
|
export type ExportPhase = "prepare" | "decode" | "upload" | "render" | "readback" | "encode" | "mux" | "publish" | "download" | "cleanup";
|
|
15
16
|
/** Reporting process. `node` is `@alpha2-sh/node` and `python` the `alpha2` Python package. */
|
|
@@ -83,6 +84,13 @@ export interface FailureClass {
|
|
|
83
84
|
readonly code: ExportFailureCode;
|
|
84
85
|
readonly resource: MemoryResource;
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Codes only the browser runtime makes: decode refusals, the frame supply, wasm traps, its
|
|
89
|
+
* workers, and the wasm binding's own `INVALID_STATE`.
|
|
90
|
+
*/
|
|
91
|
+
export declare const BROWSER_ERROR_CODES: readonly ["DECODE_UNAVAILABLE", "PLANAR_DECODE_UNAVAILABLE", "NON_PLANAR_FRAME", "FRAME_SUPPLY_FAILED", "SOFTWARE_DECODE_REQUIRED", "WASM_TRAP", "WASM_TRAPPED", "WASM_COMPILE_ERROR", "WASM_LINK_ERROR", "RENDER_WORKER_ERROR", "RENDER_WORKER_FAILED", "AUDIO_WORKER_ERROR", "INVALID_STATE"];
|
|
92
|
+
/** A code the browser runtime makes; see {@link BROWSER_ERROR_CODES}. */
|
|
93
|
+
export type BrowserErrorCode = (typeof BROWSER_ERROR_CODES)[number];
|
|
86
94
|
/** Failure class of a protocol or `@alpha2-sh/node` error code; `UNKNOWN` for any other. */
|
|
87
95
|
export declare function failureClassOfCode(code: unknown): FailureClass;
|
|
88
96
|
/** Context for {@link failureForCode}. */
|