@webpacked-timeline/core 1.0.0-beta.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/CHANGELOG.md +36 -0
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/chunk-27XCNVPR.js +5969 -0
- package/dist/chunk-6PDBJDHM.js +2263 -0
- package/dist/chunk-BWPS6NQT.js +7465 -0
- package/dist/chunk-FBOYSUYV.js +1280 -0
- package/dist/chunk-FR632TZX.js +1870 -0
- package/dist/chunk-HW4Z7YLJ.js +1242 -0
- package/dist/chunk-HWW62IFH.js +5424 -0
- package/dist/chunk-I2GZXRH4.js +4790 -0
- package/dist/chunk-JQZE3OK4.js +1255 -0
- package/dist/chunk-KF7JNK2F.js +1864 -0
- package/dist/chunk-KR3P2DYK.js +5655 -0
- package/dist/chunk-MO5DSFSW.js +2214 -0
- package/dist/chunk-MQAW33RJ.js +5530 -0
- package/dist/chunk-N4WUWZZX.js +2833 -0
- package/dist/chunk-NRJV7I4C.js +1331 -0
- package/dist/chunk-NXG52532.js +2230 -0
- package/dist/chunk-PVXF67CN.js +1278 -0
- package/dist/chunk-QSB6DHIF.js +5429 -0
- package/dist/chunk-QYWJT7HR.js +5837 -0
- package/dist/chunk-SWBRCMW7.js +7466 -0
- package/dist/chunk-TAT3ULSV.js +2214 -0
- package/dist/chunk-TTDP5JUM.js +2228 -0
- package/dist/chunk-UAGP4VPG.js +1739 -0
- package/dist/chunk-WIG6SY7A.js +1183 -0
- package/dist/chunk-YJ2K5N2R.js +6187 -0
- package/dist/index-3Lr_vKBd.d.cts +2810 -0
- package/dist/index-3Lr_vKBd.d.ts +2810 -0
- package/dist/index-7IPJn1yM.d.cts +1146 -0
- package/dist/index-7IPJn1yM.d.ts +1146 -0
- package/dist/index-B0xOv0V0.d.cts +3259 -0
- package/dist/index-B0xOv0V0.d.ts +3259 -0
- package/dist/index-B2m3zwg7.d.cts +1381 -0
- package/dist/index-B2m3zwg7.d.ts +1381 -0
- package/dist/index-B3sUrU_X.d.cts +1249 -0
- package/dist/index-B3sUrU_X.d.ts +1249 -0
- package/dist/index-B6wla7ZJ.d.cts +2751 -0
- package/dist/index-B6wla7ZJ.d.ts +2751 -0
- package/dist/index-BIv8RWWT.d.cts +1574 -0
- package/dist/index-BIv8RWWT.d.ts +1574 -0
- package/dist/index-BJv6hDHL.d.cts +3255 -0
- package/dist/index-BJv6hDHL.d.ts +3255 -0
- package/dist/index-BUCimS2e.d.cts +1393 -0
- package/dist/index-BUCimS2e.d.ts +1393 -0
- package/dist/index-Bw_nvNcG.d.cts +1275 -0
- package/dist/index-Bw_nvNcG.d.ts +1275 -0
- package/dist/index-ByG0gOtd.d.cts +1167 -0
- package/dist/index-ByG0gOtd.d.ts +1167 -0
- package/dist/index-CDGd2XXv.d.cts +2492 -0
- package/dist/index-CDGd2XXv.d.ts +2492 -0
- package/dist/index-CznAVeJ6.d.cts +1145 -0
- package/dist/index-CznAVeJ6.d.ts +1145 -0
- package/dist/index-DQD9IMh7.d.cts +2534 -0
- package/dist/index-DQD9IMh7.d.ts +2534 -0
- package/dist/index-Dl3qtJEI.d.cts +2178 -0
- package/dist/index-Dl3qtJEI.d.ts +2178 -0
- package/dist/index-DnE2A-Nz.d.cts +2603 -0
- package/dist/index-DnE2A-Nz.d.ts +2603 -0
- package/dist/index-DrOA6QmW.d.cts +2492 -0
- package/dist/index-DrOA6QmW.d.ts +2492 -0
- package/dist/index-Vpa3rPEM.d.cts +1402 -0
- package/dist/index-Vpa3rPEM.d.ts +1402 -0
- package/dist/index-jP6BomSd.d.cts +2640 -0
- package/dist/index-jP6BomSd.d.ts +2640 -0
- package/dist/index-wiGRwVyY.d.cts +3259 -0
- package/dist/index-wiGRwVyY.d.ts +3259 -0
- package/dist/index.cjs +7386 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +263 -0
- package/dist/internal.cjs +7721 -0
- package/dist/internal.d.cts +704 -0
- package/dist/internal.d.ts +704 -0
- package/dist/internal.js +405 -0
- package/package.json +58 -0
|
@@ -0,0 +1,2751 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FRAME-BASED TIME REPRESENTATION
|
|
3
|
+
*
|
|
4
|
+
* Phase 0 compliant. All time values in state are TimelineFrame branded integers.
|
|
5
|
+
* FrameRate is a discriminated literal union — never a raw float.
|
|
6
|
+
*
|
|
7
|
+
* THREE INVIOLABLE RULES:
|
|
8
|
+
* 1. Core has ZERO UI framework imports.
|
|
9
|
+
* 2. Every function that changes state returns a NEW object.
|
|
10
|
+
* 3. Every frame value is a branded TimelineFrame integer — never a raw number.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* TimelineFrame — A discrete, non-negative integer point in time measured in frames.
|
|
14
|
+
*
|
|
15
|
+
* Branded so TypeScript prevents raw numbers from sneaking into frame positions.
|
|
16
|
+
* The ONLY way to create one is via toFrame().
|
|
17
|
+
*/
|
|
18
|
+
type TimelineFrame = number & {
|
|
19
|
+
readonly __brand: "TimelineFrame";
|
|
20
|
+
};
|
|
21
|
+
/** The canonical factory. Use this everywhere instead of casting. */
|
|
22
|
+
declare const toFrame: (n: number) => TimelineFrame;
|
|
23
|
+
/**
|
|
24
|
+
* Legacy alias kept for backward-compat during transition.
|
|
25
|
+
* Prefer toFrame() for new code.
|
|
26
|
+
*/
|
|
27
|
+
declare function frame(value: number): TimelineFrame;
|
|
28
|
+
/**
|
|
29
|
+
* FrameRate — The exact set of supported frame rates.
|
|
30
|
+
*
|
|
31
|
+
* RULE: Never pass 29.97 as a plain number. Use the literal type.
|
|
32
|
+
* This is a discriminated union — TypeScript enforces membership at compile time.
|
|
33
|
+
*/
|
|
34
|
+
type FrameRate = 23.976 | 24 | 25 | 29.97 | 30 | 50 | 59.94 | 60;
|
|
35
|
+
/**
|
|
36
|
+
* Named constants for the most common rates.
|
|
37
|
+
* Prefer these over raw literals where possible.
|
|
38
|
+
*/
|
|
39
|
+
declare const FrameRates: {
|
|
40
|
+
readonly CINEMA: FrameRate;
|
|
41
|
+
readonly PAL: FrameRate;
|
|
42
|
+
readonly NTSC_DF: FrameRate;
|
|
43
|
+
readonly NTSC: FrameRate;
|
|
44
|
+
readonly PAL_HFR: FrameRate;
|
|
45
|
+
readonly NTSC_HFR: FrameRate;
|
|
46
|
+
readonly HFR: FrameRate;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Legacy factory — kept for backward-compat with existing tests.
|
|
50
|
+
* This now validates that the value is a member of the FrameRate union.
|
|
51
|
+
* @throws if the value is not a recognised frame rate.
|
|
52
|
+
*/
|
|
53
|
+
declare function frameRate(value: number): FrameRate;
|
|
54
|
+
/**
|
|
55
|
+
* RationalTime — a frame count at a specific rate. Used only at
|
|
56
|
+
* ingest/export boundaries. Never stored in TimelineState.
|
|
57
|
+
*/
|
|
58
|
+
type RationalTime = {
|
|
59
|
+
readonly value: number;
|
|
60
|
+
readonly rate: FrameRate;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Timecode — SMPTE timecode string, display-only. Never use for arithmetic.
|
|
64
|
+
*/
|
|
65
|
+
type Timecode = string & {
|
|
66
|
+
readonly __brand: "Timecode";
|
|
67
|
+
};
|
|
68
|
+
declare const toTimecode: (s: string) => Timecode;
|
|
69
|
+
/**
|
|
70
|
+
* TimeRange — a start + duration pair, both in TimelineFrame units.
|
|
71
|
+
*/
|
|
72
|
+
type TimeRange = {
|
|
73
|
+
readonly startFrame: TimelineFrame;
|
|
74
|
+
readonly duration: TimelineFrame;
|
|
75
|
+
};
|
|
76
|
+
declare function isValidFrame(value: number): boolean;
|
|
77
|
+
declare function isDropFrame(fps: FrameRate): boolean;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* GENERATOR MODEL — Phase 3
|
|
81
|
+
*
|
|
82
|
+
* Generators are synthetic "assets" (solid, bars, countdown, etc.)
|
|
83
|
+
* registered in AssetRegistry as GeneratorAsset. No filePath.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
type GeneratorId = string & {
|
|
87
|
+
readonly __brand: 'GeneratorId';
|
|
88
|
+
};
|
|
89
|
+
type GeneratorType = 'solid' | 'bars' | 'countdown' | 'noise' | 'text';
|
|
90
|
+
type Generator = {
|
|
91
|
+
readonly id: GeneratorId;
|
|
92
|
+
readonly type: GeneratorType;
|
|
93
|
+
readonly params: Record<string, unknown>;
|
|
94
|
+
readonly duration: TimelineFrame;
|
|
95
|
+
readonly name: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* ASSET MODEL — Phase 0 + Phase 3
|
|
100
|
+
*
|
|
101
|
+
* Asset is FileAsset | GeneratorAsset. Multiple Clips can reference the same Asset.
|
|
102
|
+
* Assets never change their intrinsicDuration after registration.
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
type AssetId = string & {
|
|
106
|
+
readonly __brand: 'AssetId';
|
|
107
|
+
};
|
|
108
|
+
declare const toAssetId: (s: string) => AssetId;
|
|
109
|
+
type AssetStatus = 'online' | 'offline' | 'proxy-only' | 'missing';
|
|
110
|
+
type FileAsset = {
|
|
111
|
+
readonly kind: 'file';
|
|
112
|
+
readonly id: AssetId;
|
|
113
|
+
readonly name: string;
|
|
114
|
+
readonly mediaType: TrackType;
|
|
115
|
+
readonly filePath: string;
|
|
116
|
+
readonly intrinsicDuration: TimelineFrame;
|
|
117
|
+
readonly nativeFps: FrameRate;
|
|
118
|
+
readonly sourceTimecodeOffset: TimelineFrame;
|
|
119
|
+
readonly status: AssetStatus;
|
|
120
|
+
};
|
|
121
|
+
type GeneratorAsset = {
|
|
122
|
+
readonly kind: 'generator';
|
|
123
|
+
readonly id: AssetId;
|
|
124
|
+
readonly name: string;
|
|
125
|
+
readonly mediaType: TrackType;
|
|
126
|
+
readonly intrinsicDuration: TimelineFrame;
|
|
127
|
+
readonly nativeFps: FrameRate;
|
|
128
|
+
readonly sourceTimecodeOffset: TimelineFrame;
|
|
129
|
+
readonly status: AssetStatus;
|
|
130
|
+
readonly generatorDef: Generator;
|
|
131
|
+
};
|
|
132
|
+
type Asset = FileAsset | GeneratorAsset;
|
|
133
|
+
declare function createAsset(params: {
|
|
134
|
+
id: string;
|
|
135
|
+
name: string;
|
|
136
|
+
mediaType: TrackType;
|
|
137
|
+
filePath: string;
|
|
138
|
+
intrinsicDuration: TimelineFrame;
|
|
139
|
+
nativeFps: FrameRate;
|
|
140
|
+
sourceTimecodeOffset: TimelineFrame;
|
|
141
|
+
status?: AssetStatus;
|
|
142
|
+
}): FileAsset;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* EASING CURVES — Phase 4
|
|
146
|
+
*
|
|
147
|
+
* Discriminated union for keyframe/interpolation easing.
|
|
148
|
+
*/
|
|
149
|
+
type EasingCurve = {
|
|
150
|
+
readonly kind: 'Linear';
|
|
151
|
+
} | {
|
|
152
|
+
readonly kind: 'Hold';
|
|
153
|
+
} | {
|
|
154
|
+
readonly kind: 'EaseIn';
|
|
155
|
+
readonly power: number;
|
|
156
|
+
} | {
|
|
157
|
+
readonly kind: 'EaseOut';
|
|
158
|
+
readonly power: number;
|
|
159
|
+
} | {
|
|
160
|
+
readonly kind: 'EaseBoth';
|
|
161
|
+
readonly power: number;
|
|
162
|
+
} | {
|
|
163
|
+
readonly kind: 'BezierCurve';
|
|
164
|
+
readonly p1x: number;
|
|
165
|
+
readonly p1y: number;
|
|
166
|
+
readonly p2x: number;
|
|
167
|
+
readonly p2y: number;
|
|
168
|
+
};
|
|
169
|
+
declare const LINEAR_EASING: EasingCurve;
|
|
170
|
+
declare const HOLD_EASING: EasingCurve;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* KEYFRAME MODEL — Phase 4
|
|
174
|
+
*
|
|
175
|
+
* Single keyframe for animatable values (effect params, transform, audio).
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
type KeyframeId = string & {
|
|
179
|
+
readonly __brand: 'KeyframeId';
|
|
180
|
+
};
|
|
181
|
+
declare function toKeyframeId(s: string): KeyframeId;
|
|
182
|
+
/** Value is a plain number (opacity, scale, rotation, gain, etc.). */
|
|
183
|
+
type Keyframe = {
|
|
184
|
+
readonly id: KeyframeId;
|
|
185
|
+
readonly frame: TimelineFrame;
|
|
186
|
+
readonly value: number;
|
|
187
|
+
/** Easing out of this keyframe. */
|
|
188
|
+
readonly easing: EasingCurve;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* EFFECT MODEL — Phase 4
|
|
193
|
+
*
|
|
194
|
+
* Effect applied to a clip (blur, LUT, color correct, host-defined).
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
type EffectId = string & {
|
|
198
|
+
readonly __brand: 'EffectId';
|
|
199
|
+
};
|
|
200
|
+
declare function toEffectId(s: string): EffectId;
|
|
201
|
+
/** Open string: 'blur', 'lut', 'colorCorrect', host-defined. */
|
|
202
|
+
type EffectType = string;
|
|
203
|
+
type RenderStage = 'preComposite' | 'postComposite' | 'output';
|
|
204
|
+
type EffectParam = {
|
|
205
|
+
readonly key: string;
|
|
206
|
+
readonly value: number | string | boolean;
|
|
207
|
+
};
|
|
208
|
+
type Effect = {
|
|
209
|
+
readonly id: EffectId;
|
|
210
|
+
readonly effectType: EffectType;
|
|
211
|
+
readonly enabled: boolean;
|
|
212
|
+
readonly renderStage: RenderStage;
|
|
213
|
+
readonly params: readonly EffectParam[];
|
|
214
|
+
readonly keyframes: readonly Keyframe[];
|
|
215
|
+
};
|
|
216
|
+
declare function createEffect(id: EffectId, effectType: EffectType, renderStage?: RenderStage, params?: readonly EffectParam[]): Effect;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* CLIP TRANSFORM — Phase 4
|
|
220
|
+
*
|
|
221
|
+
* Animatable position, scale, rotation, opacity, anchor.
|
|
222
|
+
* Each property: base value + optional keyframes.
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
type AnimatableProperty = {
|
|
226
|
+
readonly value: number;
|
|
227
|
+
readonly keyframes: readonly Keyframe[];
|
|
228
|
+
};
|
|
229
|
+
declare function createAnimatableProperty(value: number): AnimatableProperty;
|
|
230
|
+
type ClipTransform = {
|
|
231
|
+
readonly positionX: AnimatableProperty;
|
|
232
|
+
readonly positionY: AnimatableProperty;
|
|
233
|
+
readonly scaleX: AnimatableProperty;
|
|
234
|
+
readonly scaleY: AnimatableProperty;
|
|
235
|
+
readonly rotation: AnimatableProperty;
|
|
236
|
+
readonly opacity: AnimatableProperty;
|
|
237
|
+
readonly anchorX: AnimatableProperty;
|
|
238
|
+
readonly anchorY: AnimatableProperty;
|
|
239
|
+
};
|
|
240
|
+
declare const DEFAULT_CLIP_TRANSFORM: ClipTransform;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* AUDIO PROPERTIES — Phase 4
|
|
244
|
+
*
|
|
245
|
+
* Per-clip audio: gain, pan, mute, channel routing.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
type ChannelRouting = 'stereo' | 'mono' | 'left' | 'right';
|
|
249
|
+
type AudioProperties = {
|
|
250
|
+
readonly gain: AnimatableProperty;
|
|
251
|
+
readonly pan: AnimatableProperty;
|
|
252
|
+
readonly mute: boolean;
|
|
253
|
+
readonly channelRouting: ChannelRouting;
|
|
254
|
+
readonly normalizationGain: number;
|
|
255
|
+
};
|
|
256
|
+
declare const DEFAULT_AUDIO_PROPERTIES: AudioProperties;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* TRANSITION MODEL — Phase 4
|
|
260
|
+
*
|
|
261
|
+
* Outgoing transition between clips (dissolve, wipe, etc.).
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
type TransitionId = string & {
|
|
265
|
+
readonly __brand: 'TransitionId';
|
|
266
|
+
};
|
|
267
|
+
declare function toTransitionId(s: string): TransitionId;
|
|
268
|
+
/** 'dissolve' | 'wipe' | 'dip' | host-defined. */
|
|
269
|
+
type TransitionType = string;
|
|
270
|
+
type TransitionAlignment = 'centerOnCut' | 'endAtCut' | 'startAtCut';
|
|
271
|
+
type TransitionParam = {
|
|
272
|
+
readonly key: string;
|
|
273
|
+
readonly value: number | string | boolean;
|
|
274
|
+
};
|
|
275
|
+
type Transition = {
|
|
276
|
+
readonly id: TransitionId;
|
|
277
|
+
readonly type: TransitionType;
|
|
278
|
+
readonly durationFrames: number;
|
|
279
|
+
readonly alignment: TransitionAlignment;
|
|
280
|
+
readonly easing: EasingCurve;
|
|
281
|
+
readonly params: readonly TransitionParam[];
|
|
282
|
+
};
|
|
283
|
+
declare function createTransition(id: TransitionId, type: TransitionType, durationFrames: number, alignment?: TransitionAlignment, easing?: EasingCurve, params?: readonly TransitionParam[]): Transition;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* CLIP MODEL — Phase 0 compliant
|
|
287
|
+
*
|
|
288
|
+
* A Clip is a time-bound reference to an Asset placed on a Track.
|
|
289
|
+
* All fields are readonly. Never mutate — always return a new object.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
type ClipId = string & {
|
|
293
|
+
readonly __brand: 'ClipId';
|
|
294
|
+
};
|
|
295
|
+
declare const toClipId: (s: string) => ClipId;
|
|
296
|
+
/**
|
|
297
|
+
* Clip — a time-bound viewport into an Asset on a Track.
|
|
298
|
+
*
|
|
299
|
+
* TIMELINE BOUNDS: timelineStart / timelineEnd — where it sits on the track.
|
|
300
|
+
* MEDIA BOUNDS: mediaIn / mediaOut — which portion of the asset plays.
|
|
301
|
+
*
|
|
302
|
+
* INVARIANTS (Phase 0, speed=1.0):
|
|
303
|
+
* timelineEnd > timelineStart
|
|
304
|
+
* mediaOut > mediaIn
|
|
305
|
+
* (mediaOut - mediaIn) === (timelineEnd - timelineStart)
|
|
306
|
+
* mediaIn >= 0
|
|
307
|
+
* mediaOut <= asset.intrinsicDuration
|
|
308
|
+
* timelineEnd <= timeline.duration
|
|
309
|
+
* speed > 0
|
|
310
|
+
*/
|
|
311
|
+
type Clip = {
|
|
312
|
+
readonly id: ClipId;
|
|
313
|
+
readonly assetId: AssetId;
|
|
314
|
+
readonly trackId: TrackId;
|
|
315
|
+
readonly timelineStart: TimelineFrame;
|
|
316
|
+
readonly timelineEnd: TimelineFrame;
|
|
317
|
+
readonly mediaIn: TimelineFrame;
|
|
318
|
+
readonly mediaOut: TimelineFrame;
|
|
319
|
+
readonly speed: number;
|
|
320
|
+
readonly enabled: boolean;
|
|
321
|
+
readonly reversed: boolean;
|
|
322
|
+
readonly name: string | null;
|
|
323
|
+
readonly color: string | null;
|
|
324
|
+
readonly metadata: Record<string, string>;
|
|
325
|
+
readonly effects?: readonly Effect[];
|
|
326
|
+
readonly transform?: ClipTransform;
|
|
327
|
+
readonly audio?: AudioProperties;
|
|
328
|
+
readonly transition?: Transition;
|
|
329
|
+
};
|
|
330
|
+
declare function createClip(params: {
|
|
331
|
+
id: string;
|
|
332
|
+
assetId: string;
|
|
333
|
+
trackId: string;
|
|
334
|
+
timelineStart: TimelineFrame;
|
|
335
|
+
timelineEnd: TimelineFrame;
|
|
336
|
+
mediaIn: TimelineFrame;
|
|
337
|
+
mediaOut: TimelineFrame;
|
|
338
|
+
speed?: number;
|
|
339
|
+
enabled?: boolean;
|
|
340
|
+
reversed?: boolean;
|
|
341
|
+
name?: string | null;
|
|
342
|
+
color?: string | null;
|
|
343
|
+
metadata?: Record<string, string>;
|
|
344
|
+
effects?: readonly Effect[];
|
|
345
|
+
transform?: ClipTransform;
|
|
346
|
+
audio?: AudioProperties;
|
|
347
|
+
transition?: Transition;
|
|
348
|
+
}): Clip;
|
|
349
|
+
declare function getClipDuration(clip: Clip): TimelineFrame;
|
|
350
|
+
declare function getClipMediaDuration(clip: Clip): TimelineFrame;
|
|
351
|
+
declare function clipContainsFrame(clip: Clip, f: TimelineFrame): boolean;
|
|
352
|
+
declare function clipsOverlap(a: Clip, b: Clip): boolean;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* CAPTION MODEL — Phase 3
|
|
356
|
+
*
|
|
357
|
+
* Captions live on Track.captions[]. Used for SRT/VTT and burn-in.
|
|
358
|
+
*/
|
|
359
|
+
|
|
360
|
+
type CaptionId = string & {
|
|
361
|
+
readonly __brand: 'CaptionId';
|
|
362
|
+
};
|
|
363
|
+
type CaptionStyle = {
|
|
364
|
+
readonly fontFamily: string;
|
|
365
|
+
readonly fontSize: number;
|
|
366
|
+
readonly color: string;
|
|
367
|
+
readonly backgroundColor: string;
|
|
368
|
+
readonly hAlign: 'left' | 'center' | 'right';
|
|
369
|
+
readonly vAlign: 'top' | 'center' | 'bottom';
|
|
370
|
+
};
|
|
371
|
+
type Caption = {
|
|
372
|
+
readonly id: CaptionId;
|
|
373
|
+
readonly text: string;
|
|
374
|
+
readonly startFrame: TimelineFrame;
|
|
375
|
+
readonly endFrame: TimelineFrame;
|
|
376
|
+
readonly language: string;
|
|
377
|
+
readonly style: CaptionStyle;
|
|
378
|
+
readonly burnIn: boolean;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* TRACK GROUP — Phase 4
|
|
383
|
+
*
|
|
384
|
+
* Logical grouping of tracks (e.g. for nesting or UI collapse).
|
|
385
|
+
*/
|
|
386
|
+
|
|
387
|
+
type TrackGroupId = string & {
|
|
388
|
+
readonly __brand: 'TrackGroupId';
|
|
389
|
+
};
|
|
390
|
+
declare function toTrackGroupId(s: string): TrackGroupId;
|
|
391
|
+
type TrackGroup = {
|
|
392
|
+
readonly id: TrackGroupId;
|
|
393
|
+
readonly label: string;
|
|
394
|
+
readonly trackIds: readonly TrackId[];
|
|
395
|
+
readonly collapsed: boolean;
|
|
396
|
+
};
|
|
397
|
+
declare function createTrackGroup(id: TrackGroupId, label: string, trackIds?: readonly TrackId[]): TrackGroup;
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* TRACK MODEL — Phase 0 + Phase 3
|
|
401
|
+
*
|
|
402
|
+
* A Track is a horizontal container for Clips, always sorted by timelineStart.
|
|
403
|
+
* Phase 3: captions[] for subtitle/caption items.
|
|
404
|
+
*/
|
|
405
|
+
|
|
406
|
+
type TrackId = string & {
|
|
407
|
+
readonly __brand: 'TrackId';
|
|
408
|
+
};
|
|
409
|
+
declare const toTrackId: (s: string) => TrackId;
|
|
410
|
+
type TrackType = 'video' | 'audio' | 'subtitle' | 'title';
|
|
411
|
+
type Track = {
|
|
412
|
+
readonly id: TrackId;
|
|
413
|
+
readonly name: string;
|
|
414
|
+
readonly type: TrackType;
|
|
415
|
+
readonly locked: boolean;
|
|
416
|
+
readonly muted: boolean;
|
|
417
|
+
readonly solo: boolean;
|
|
418
|
+
readonly height: number;
|
|
419
|
+
/** Always sorted ascending by timelineStart — invariant enforced by checkInvariants. */
|
|
420
|
+
readonly clips: readonly Clip[];
|
|
421
|
+
/** Phase 3: captions on this track (e.g. subtitle/title). */
|
|
422
|
+
readonly captions: readonly Caption[];
|
|
423
|
+
readonly blendMode?: string;
|
|
424
|
+
readonly opacity?: number;
|
|
425
|
+
readonly groupId?: TrackGroupId;
|
|
426
|
+
};
|
|
427
|
+
declare function createTrack(params: {
|
|
428
|
+
id: string;
|
|
429
|
+
name: string;
|
|
430
|
+
type: TrackType;
|
|
431
|
+
clips?: readonly Clip[];
|
|
432
|
+
captions?: readonly Caption[];
|
|
433
|
+
locked?: boolean;
|
|
434
|
+
muted?: boolean;
|
|
435
|
+
solo?: boolean;
|
|
436
|
+
height?: number;
|
|
437
|
+
blendMode?: string;
|
|
438
|
+
opacity?: number;
|
|
439
|
+
groupId?: TrackGroupId;
|
|
440
|
+
}): Track;
|
|
441
|
+
/** Returns a new track with clips sorted ascending by timelineStart. */
|
|
442
|
+
declare function sortTrackClips(track: Track): Track;
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* MARKER TYPES — Phase 3
|
|
446
|
+
*
|
|
447
|
+
* Discriminated union: point (single frame) or range (frameStart..frameEnd).
|
|
448
|
+
* Markers live on Timeline.markers[]. linkedClipId moves with clip on ripple.
|
|
449
|
+
*/
|
|
450
|
+
|
|
451
|
+
type MarkerId = string & {
|
|
452
|
+
readonly __brand: 'MarkerId';
|
|
453
|
+
};
|
|
454
|
+
type MarkerScope = 'global' | 'personal' | 'export';
|
|
455
|
+
type Marker = {
|
|
456
|
+
readonly type: 'point';
|
|
457
|
+
readonly id: MarkerId;
|
|
458
|
+
readonly frame: TimelineFrame;
|
|
459
|
+
readonly label: string;
|
|
460
|
+
readonly color: string;
|
|
461
|
+
readonly scope: MarkerScope;
|
|
462
|
+
readonly linkedClipId: ClipId | null;
|
|
463
|
+
readonly clipId?: ClipId;
|
|
464
|
+
} | {
|
|
465
|
+
readonly type: 'range';
|
|
466
|
+
readonly id: MarkerId;
|
|
467
|
+
readonly frameStart: TimelineFrame;
|
|
468
|
+
readonly frameEnd: TimelineFrame;
|
|
469
|
+
readonly label: string;
|
|
470
|
+
readonly color: string;
|
|
471
|
+
readonly scope: MarkerScope;
|
|
472
|
+
readonly linkedClipId: ClipId | null;
|
|
473
|
+
readonly clipId?: ClipId;
|
|
474
|
+
};
|
|
475
|
+
type BeatGrid = {
|
|
476
|
+
readonly bpm: number;
|
|
477
|
+
readonly timeSignature: readonly [number, number];
|
|
478
|
+
readonly offset: TimelineFrame;
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* LINK GROUP — Phase 4
|
|
483
|
+
*
|
|
484
|
+
* Locks A/V clips in sync; when one moves, all move together.
|
|
485
|
+
*/
|
|
486
|
+
|
|
487
|
+
type LinkGroupId = string & {
|
|
488
|
+
readonly __brand: 'LinkGroupId';
|
|
489
|
+
};
|
|
490
|
+
declare function toLinkGroupId(s: string): LinkGroupId;
|
|
491
|
+
type LinkGroup = {
|
|
492
|
+
readonly id: LinkGroupId;
|
|
493
|
+
/** Min 2 clips. */
|
|
494
|
+
readonly clipIds: readonly ClipId[];
|
|
495
|
+
};
|
|
496
|
+
declare function createLinkGroup(id: LinkGroupId, clipIds: readonly ClipId[]): LinkGroup;
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* TIMELINE MODEL — Phase 0 + Phase 3
|
|
500
|
+
*/
|
|
501
|
+
|
|
502
|
+
type SequenceSettings = {
|
|
503
|
+
readonly pixelAspectRatio: number;
|
|
504
|
+
readonly fieldOrder: 'progressive' | 'upper' | 'lower';
|
|
505
|
+
readonly colorSpace: string;
|
|
506
|
+
readonly audioSampleRate: number;
|
|
507
|
+
readonly audioChannelCount: number;
|
|
508
|
+
};
|
|
509
|
+
type Timeline = {
|
|
510
|
+
readonly id: string;
|
|
511
|
+
readonly name: string;
|
|
512
|
+
readonly fps: FrameRate;
|
|
513
|
+
readonly duration: TimelineFrame;
|
|
514
|
+
readonly startTimecode: Timecode;
|
|
515
|
+
readonly tracks: readonly Track[];
|
|
516
|
+
readonly sequenceSettings: SequenceSettings;
|
|
517
|
+
/**
|
|
518
|
+
* Increments by 1 on every successfully committed Transaction.
|
|
519
|
+
* Use this to detect stale references without deep equality checks.
|
|
520
|
+
*/
|
|
521
|
+
readonly version: number;
|
|
522
|
+
readonly markers: readonly Marker[];
|
|
523
|
+
readonly beatGrid: BeatGrid | null;
|
|
524
|
+
readonly inPoint: TimelineFrame | null;
|
|
525
|
+
readonly outPoint: TimelineFrame | null;
|
|
526
|
+
readonly trackGroups?: readonly TrackGroup[];
|
|
527
|
+
readonly linkGroups?: readonly LinkGroup[];
|
|
528
|
+
};
|
|
529
|
+
declare function createTimeline(params: {
|
|
530
|
+
id: string;
|
|
531
|
+
name: string;
|
|
532
|
+
fps: FrameRate;
|
|
533
|
+
duration: TimelineFrame;
|
|
534
|
+
startTimecode?: Timecode;
|
|
535
|
+
tracks?: readonly Track[];
|
|
536
|
+
sequenceSettings?: Partial<SequenceSettings>;
|
|
537
|
+
markers?: readonly Marker[];
|
|
538
|
+
beatGrid?: BeatGrid | null;
|
|
539
|
+
inPoint?: TimelineFrame | null;
|
|
540
|
+
outPoint?: TimelineFrame | null;
|
|
541
|
+
trackGroups?: readonly TrackGroup[];
|
|
542
|
+
linkGroups?: readonly LinkGroup[];
|
|
543
|
+
}): Timeline;
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* TIMELINE STATE — Phase 0 compliant
|
|
547
|
+
*
|
|
548
|
+
* TimelineState is the single source of truth for the engine.
|
|
549
|
+
* Phase 0 only: timeline + assetRegistry. No Phase 2 fields.
|
|
550
|
+
*
|
|
551
|
+
* RULE: Every function that changes state returns a NEW TimelineState.
|
|
552
|
+
* Never mutate the existing state.
|
|
553
|
+
*/
|
|
554
|
+
|
|
555
|
+
type AssetRegistry = ReadonlyMap<AssetId, Asset>;
|
|
556
|
+
/**
|
|
557
|
+
* Increment this whenever TimelineState gains a new required field or
|
|
558
|
+
* a field's semantics change in a breaking way.
|
|
559
|
+
*
|
|
560
|
+
* The schemaVersion invariant check rejects loading a future schema
|
|
561
|
+
* into an older engine (prevents silent data corruption on downgrade).
|
|
562
|
+
*/
|
|
563
|
+
declare const CURRENT_SCHEMA_VERSION: 2;
|
|
564
|
+
type TimelineState = {
|
|
565
|
+
readonly schemaVersion: number;
|
|
566
|
+
readonly timeline: Timeline;
|
|
567
|
+
readonly assetRegistry: AssetRegistry;
|
|
568
|
+
};
|
|
569
|
+
declare function createTimelineState(params: {
|
|
570
|
+
timeline: Timeline;
|
|
571
|
+
assetRegistry?: AssetRegistry;
|
|
572
|
+
/** @deprecated use assetRegistry. Kept for test backward-compat only. */
|
|
573
|
+
assets?: Map<string, Asset>;
|
|
574
|
+
}): TimelineState;
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* FRAME UTILITIES
|
|
578
|
+
*
|
|
579
|
+
* Pure functions for working with frame-based time values.
|
|
580
|
+
*
|
|
581
|
+
* These utilities handle:
|
|
582
|
+
* - Converting between frames and seconds
|
|
583
|
+
* - Formatting frames as timecode (HH:MM:SS:FF)
|
|
584
|
+
* - Frame arithmetic (clamping, rounding)
|
|
585
|
+
*
|
|
586
|
+
* CRITICAL RULES:
|
|
587
|
+
* - All conversions must quantize to whole frames
|
|
588
|
+
* - No floating-point frame values allowed
|
|
589
|
+
* - Always round/floor/ceil explicitly
|
|
590
|
+
*
|
|
591
|
+
* USAGE:
|
|
592
|
+
* ```typescript
|
|
593
|
+
* const fps = frameRate(30);
|
|
594
|
+
* const frames = secondsToFrames(5.5, fps); // 165 frames
|
|
595
|
+
* const seconds = framesToSeconds(frames, fps); // 5.5 seconds
|
|
596
|
+
* const timecode = framesToTimecode(frames, fps); // "00:00:05:15"
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Convert frames to seconds
|
|
602
|
+
*
|
|
603
|
+
* @param frames - Frame number
|
|
604
|
+
* @param fps - Frames per second
|
|
605
|
+
* @returns Time in seconds (may be fractional)
|
|
606
|
+
*/
|
|
607
|
+
declare function framesToSeconds(frames: TimelineFrame, fps: FrameRate): number;
|
|
608
|
+
/**
|
|
609
|
+
* Convert seconds to frames
|
|
610
|
+
*
|
|
611
|
+
* IMPORTANT: This rounds to the nearest frame.
|
|
612
|
+
* If you need different rounding behavior, use Math.floor or Math.ceil explicitly.
|
|
613
|
+
*
|
|
614
|
+
* @param seconds - Time in seconds
|
|
615
|
+
* @param fps - Frames per second
|
|
616
|
+
* @returns Frame number (rounded to nearest frame)
|
|
617
|
+
*/
|
|
618
|
+
declare function secondsToFrames(seconds: number, fps: FrameRate): TimelineFrame;
|
|
619
|
+
/**
|
|
620
|
+
* Convert frames to timecode format (HH:MM:SS:FF)
|
|
621
|
+
*
|
|
622
|
+
* Example: 3825 frames at 30fps = "00:02:07:15"
|
|
623
|
+
*
|
|
624
|
+
* @param frames - Frame number
|
|
625
|
+
* @param fps - Frames per second
|
|
626
|
+
* @returns Timecode string
|
|
627
|
+
*/
|
|
628
|
+
declare function framesToTimecode(frames: TimelineFrame, fps: FrameRate): string;
|
|
629
|
+
/**
|
|
630
|
+
* Convert frames to simple MM:SS format
|
|
631
|
+
*
|
|
632
|
+
* Example: 3825 frames at 30fps = "02:07"
|
|
633
|
+
*
|
|
634
|
+
* @param frames - Frame number
|
|
635
|
+
* @param fps - Frames per second
|
|
636
|
+
* @returns Time string in MM:SS format
|
|
637
|
+
*/
|
|
638
|
+
declare function framesToMinutesSeconds(frames: TimelineFrame, fps: FrameRate): string;
|
|
639
|
+
/**
|
|
640
|
+
* Clamp a frame value between min and max
|
|
641
|
+
*
|
|
642
|
+
* @param value - Frame to clamp
|
|
643
|
+
* @param min - Minimum frame (inclusive)
|
|
644
|
+
* @param max - Maximum frame (inclusive)
|
|
645
|
+
* @returns Clamped frame value
|
|
646
|
+
*/
|
|
647
|
+
declare function clampFrame(value: TimelineFrame, min: TimelineFrame, max: TimelineFrame): TimelineFrame;
|
|
648
|
+
/**
|
|
649
|
+
* Add two frame values
|
|
650
|
+
*
|
|
651
|
+
* @param a - First frame
|
|
652
|
+
* @param b - Second frame
|
|
653
|
+
* @returns Sum of frames
|
|
654
|
+
*/
|
|
655
|
+
declare function addFrames(a: TimelineFrame, b: TimelineFrame): TimelineFrame;
|
|
656
|
+
/**
|
|
657
|
+
* Subtract two frame values
|
|
658
|
+
*
|
|
659
|
+
* @param a - First frame
|
|
660
|
+
* @param b - Second frame (subtracted from a)
|
|
661
|
+
* @returns Difference of frames (clamped to 0 if negative)
|
|
662
|
+
*/
|
|
663
|
+
declare function subtractFrames(a: TimelineFrame, b: TimelineFrame): TimelineFrame;
|
|
664
|
+
/**
|
|
665
|
+
* Calculate duration between two frames
|
|
666
|
+
*
|
|
667
|
+
* @param start - Start frame
|
|
668
|
+
* @param end - End frame
|
|
669
|
+
* @returns Duration in frames (end - start)
|
|
670
|
+
*/
|
|
671
|
+
declare function frameDuration(start: TimelineFrame, end: TimelineFrame): TimelineFrame;
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* TIMELINE ENGINE
|
|
675
|
+
*
|
|
676
|
+
* The main public API for the timeline editing kernel.
|
|
677
|
+
*
|
|
678
|
+
* WHAT IS THE TIMELINE ENGINE?
|
|
679
|
+
* - A thin wrapper around the history and dispatch systems
|
|
680
|
+
* - Provides a convenient, object-oriented API
|
|
681
|
+
* - Manages internal state
|
|
682
|
+
* - Coordinates operations, validation, and history
|
|
683
|
+
*
|
|
684
|
+
* WHY A CLASS?
|
|
685
|
+
* - Encapsulates state management
|
|
686
|
+
* - Provides a clean API for users
|
|
687
|
+
* - Hides complexity of history and dispatch
|
|
688
|
+
* - Familiar OOP interface for most developers
|
|
689
|
+
*
|
|
690
|
+
* USAGE:
|
|
691
|
+
* ```typescript
|
|
692
|
+
* const engine = new TimelineEngine(initialState);
|
|
693
|
+
*
|
|
694
|
+
* // Add a clip
|
|
695
|
+
* const result = engine.addClip(trackId, clip);
|
|
696
|
+
* if (!result.success) {
|
|
697
|
+
* console.error('Failed to add clip:', result.errors);
|
|
698
|
+
* }
|
|
699
|
+
*
|
|
700
|
+
* // Undo/redo
|
|
701
|
+
* engine.undo();
|
|
702
|
+
* engine.redo();
|
|
703
|
+
*
|
|
704
|
+
* // Query state
|
|
705
|
+
* const clip = engine.findClipById('clip_1');
|
|
706
|
+
* const state = engine.getState();
|
|
707
|
+
* ```
|
|
708
|
+
*
|
|
709
|
+
* DESIGN PHILOSOPHY:
|
|
710
|
+
* - Business logic lives in pure modules (operations, validation, etc.)
|
|
711
|
+
* - Engine is just a thin orchestration layer
|
|
712
|
+
* - Easy to test (can test pure functions independently)
|
|
713
|
+
*/
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* TimelineEngine - The main timeline editing engine
|
|
717
|
+
*
|
|
718
|
+
* Provides a high-level API for timeline editing with built-in
|
|
719
|
+
* undo/redo, validation, and state management.
|
|
720
|
+
*/
|
|
721
|
+
declare class TimelineEngine {
|
|
722
|
+
private history;
|
|
723
|
+
private listeners;
|
|
724
|
+
/**
|
|
725
|
+
* Create a new timeline engine
|
|
726
|
+
*
|
|
727
|
+
* @param initialState - Initial timeline state
|
|
728
|
+
* @param historyLimit - Maximum number of undo steps (default: 50)
|
|
729
|
+
*/
|
|
730
|
+
constructor(initialState: TimelineState, historyLimit?: number);
|
|
731
|
+
/**
|
|
732
|
+
* Subscribe to state changes
|
|
733
|
+
*
|
|
734
|
+
* The listener will be called whenever the timeline state changes,
|
|
735
|
+
* with the new state passed as an argument.
|
|
736
|
+
* This is used by framework adapters (e.g., React) to trigger re-renders.
|
|
737
|
+
*
|
|
738
|
+
* @param listener - Function to call on state changes, receives new state
|
|
739
|
+
* @returns Unsubscribe function
|
|
740
|
+
*
|
|
741
|
+
* @example
|
|
742
|
+
* ```typescript
|
|
743
|
+
* const unsubscribe = engine.subscribe((state) => {
|
|
744
|
+
* console.log('State changed:', state);
|
|
745
|
+
* });
|
|
746
|
+
*
|
|
747
|
+
* // Later...
|
|
748
|
+
* unsubscribe();
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
751
|
+
subscribe(listener: (state: TimelineState) => void): () => void;
|
|
752
|
+
/**
|
|
753
|
+
* Notify all subscribers of a state change
|
|
754
|
+
*
|
|
755
|
+
* This is called internally after any operation that modifies state.
|
|
756
|
+
* Framework adapters use this to trigger re-renders.
|
|
757
|
+
*/
|
|
758
|
+
private notify;
|
|
759
|
+
/**
|
|
760
|
+
* Get the current timeline state
|
|
761
|
+
*
|
|
762
|
+
* @returns Current timeline state
|
|
763
|
+
*/
|
|
764
|
+
getState(): TimelineState;
|
|
765
|
+
/**
|
|
766
|
+
* Register an asset
|
|
767
|
+
*
|
|
768
|
+
* @param asset - Asset to register
|
|
769
|
+
* @returns Dispatch result
|
|
770
|
+
*/
|
|
771
|
+
registerAsset(asset: Asset): {
|
|
772
|
+
accepted: boolean;
|
|
773
|
+
errors?: {
|
|
774
|
+
code: string;
|
|
775
|
+
message: string;
|
|
776
|
+
}[];
|
|
777
|
+
};
|
|
778
|
+
/**
|
|
779
|
+
* Get an asset by ID
|
|
780
|
+
*
|
|
781
|
+
* @param assetId - Asset ID
|
|
782
|
+
* @returns The asset, or undefined if not found
|
|
783
|
+
*/
|
|
784
|
+
getAsset(assetId: string): Asset | undefined;
|
|
785
|
+
/**
|
|
786
|
+
* Add a clip to a track
|
|
787
|
+
*
|
|
788
|
+
* @param trackId - ID of the track to add to
|
|
789
|
+
* @param clip - Clip to add
|
|
790
|
+
* @returns Dispatch result
|
|
791
|
+
*/
|
|
792
|
+
addClip(trackId: string, clip: Clip): {
|
|
793
|
+
accepted: boolean;
|
|
794
|
+
errors?: {
|
|
795
|
+
code: string;
|
|
796
|
+
message: string;
|
|
797
|
+
}[];
|
|
798
|
+
};
|
|
799
|
+
/**
|
|
800
|
+
* Remove a clip
|
|
801
|
+
*
|
|
802
|
+
* @param clipId - ID of the clip to remove
|
|
803
|
+
* @returns Dispatch result
|
|
804
|
+
*/
|
|
805
|
+
removeClip(clipId: string): {
|
|
806
|
+
accepted: boolean;
|
|
807
|
+
errors?: {
|
|
808
|
+
code: string;
|
|
809
|
+
message: string;
|
|
810
|
+
}[];
|
|
811
|
+
};
|
|
812
|
+
/**
|
|
813
|
+
* Move a clip to a new timeline position
|
|
814
|
+
*
|
|
815
|
+
* @param clipId - ID of the clip to move
|
|
816
|
+
* @param newStart - New timeline start frame
|
|
817
|
+
* @returns Dispatch result
|
|
818
|
+
*/
|
|
819
|
+
moveClip(clipId: string, newStart: TimelineFrame): {
|
|
820
|
+
accepted: boolean;
|
|
821
|
+
errors?: {
|
|
822
|
+
code: string;
|
|
823
|
+
message: string;
|
|
824
|
+
}[];
|
|
825
|
+
};
|
|
826
|
+
/**
|
|
827
|
+
* Resize a clip
|
|
828
|
+
*
|
|
829
|
+
* @param clipId - ID of the clip to resize
|
|
830
|
+
* @param newStart - New timeline start frame
|
|
831
|
+
* @param newEnd - New timeline end frame
|
|
832
|
+
* @returns Dispatch result
|
|
833
|
+
*/
|
|
834
|
+
resizeClip(clipId: string, newStart: TimelineFrame, newEnd: TimelineFrame): {
|
|
835
|
+
accepted: boolean;
|
|
836
|
+
errors?: {
|
|
837
|
+
code: string;
|
|
838
|
+
message: string;
|
|
839
|
+
}[];
|
|
840
|
+
};
|
|
841
|
+
/**
|
|
842
|
+
* Trim a clip (change media bounds)
|
|
843
|
+
*
|
|
844
|
+
* @param clipId - ID of the clip to trim
|
|
845
|
+
* @param newMediaIn - New media in frame
|
|
846
|
+
* @param newMediaOut - New media out frame
|
|
847
|
+
* @returns Dispatch result
|
|
848
|
+
*/
|
|
849
|
+
trimClip(clipId: string, newMediaIn: TimelineFrame, newMediaOut: TimelineFrame): {
|
|
850
|
+
accepted: boolean;
|
|
851
|
+
errors?: {
|
|
852
|
+
code: string;
|
|
853
|
+
message: string;
|
|
854
|
+
}[];
|
|
855
|
+
};
|
|
856
|
+
/**
|
|
857
|
+
* Move a clip to a different track
|
|
858
|
+
*
|
|
859
|
+
* @param clipId - ID of the clip to move
|
|
860
|
+
* @param targetTrackId - ID of the target track
|
|
861
|
+
* @returns Dispatch result
|
|
862
|
+
*/
|
|
863
|
+
moveClipToTrack(clipId: string, targetTrackId: string): {
|
|
864
|
+
accepted: boolean;
|
|
865
|
+
errors?: {
|
|
866
|
+
code: string;
|
|
867
|
+
message: string;
|
|
868
|
+
}[];
|
|
869
|
+
};
|
|
870
|
+
/**
|
|
871
|
+
* Add a track
|
|
872
|
+
*
|
|
873
|
+
* @param track - Track to add
|
|
874
|
+
* @returns Dispatch result
|
|
875
|
+
*/
|
|
876
|
+
addTrack(track: Track): {
|
|
877
|
+
accepted: boolean;
|
|
878
|
+
errors?: {
|
|
879
|
+
code: string;
|
|
880
|
+
message: string;
|
|
881
|
+
}[];
|
|
882
|
+
};
|
|
883
|
+
/**
|
|
884
|
+
* Remove a track
|
|
885
|
+
*
|
|
886
|
+
* @param trackId - ID of the track to remove
|
|
887
|
+
* @returns Dispatch result
|
|
888
|
+
*/
|
|
889
|
+
removeTrack(trackId: string): {
|
|
890
|
+
accepted: boolean;
|
|
891
|
+
errors?: {
|
|
892
|
+
code: string;
|
|
893
|
+
message: string;
|
|
894
|
+
}[];
|
|
895
|
+
};
|
|
896
|
+
/**
|
|
897
|
+
* Move a track to a new position
|
|
898
|
+
*
|
|
899
|
+
* @param trackId - ID of the track to move
|
|
900
|
+
* @param newIndex - New index position
|
|
901
|
+
* @returns Dispatch result
|
|
902
|
+
*/
|
|
903
|
+
moveTrack(trackId: string, newIndex: number): {
|
|
904
|
+
accepted: boolean;
|
|
905
|
+
errors?: {
|
|
906
|
+
code: string;
|
|
907
|
+
message: string;
|
|
908
|
+
}[];
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* Toggle track mute
|
|
912
|
+
*
|
|
913
|
+
* @param trackId - ID of the track
|
|
914
|
+
* @returns Dispatch result
|
|
915
|
+
*/
|
|
916
|
+
toggleTrackMute(trackId: string): {
|
|
917
|
+
accepted: boolean;
|
|
918
|
+
errors?: {
|
|
919
|
+
code: string;
|
|
920
|
+
message: string;
|
|
921
|
+
}[];
|
|
922
|
+
};
|
|
923
|
+
/**
|
|
924
|
+
* Toggle track lock
|
|
925
|
+
*
|
|
926
|
+
* @param trackId - ID of the track
|
|
927
|
+
* @returns Dispatch result
|
|
928
|
+
*/
|
|
929
|
+
toggleTrackLock(trackId: string): {
|
|
930
|
+
accepted: boolean;
|
|
931
|
+
errors?: {
|
|
932
|
+
code: string;
|
|
933
|
+
message: string;
|
|
934
|
+
}[];
|
|
935
|
+
};
|
|
936
|
+
/**
|
|
937
|
+
* Toggle track solo
|
|
938
|
+
*
|
|
939
|
+
* @param trackId - ID of the track
|
|
940
|
+
* @returns Dispatch result
|
|
941
|
+
*/
|
|
942
|
+
toggleTrackSolo(trackId: string): {
|
|
943
|
+
accepted: boolean;
|
|
944
|
+
errors?: {
|
|
945
|
+
code: string;
|
|
946
|
+
message: string;
|
|
947
|
+
}[];
|
|
948
|
+
};
|
|
949
|
+
/**
|
|
950
|
+
* Set track height
|
|
951
|
+
*
|
|
952
|
+
* @param trackId - ID of the track
|
|
953
|
+
* @param height - New height in pixels
|
|
954
|
+
* @returns Dispatch result
|
|
955
|
+
*/
|
|
956
|
+
setTrackHeight(trackId: string, height: number): {
|
|
957
|
+
accepted: boolean;
|
|
958
|
+
errors?: {
|
|
959
|
+
code: string;
|
|
960
|
+
message: string;
|
|
961
|
+
}[];
|
|
962
|
+
};
|
|
963
|
+
/**
|
|
964
|
+
* Set timeline duration
|
|
965
|
+
*
|
|
966
|
+
* @param duration - New duration in frames
|
|
967
|
+
* @returns Dispatch result
|
|
968
|
+
*/
|
|
969
|
+
setTimelineDuration(duration: TimelineFrame): {
|
|
970
|
+
accepted: boolean;
|
|
971
|
+
errors?: {
|
|
972
|
+
code: string;
|
|
973
|
+
message: string;
|
|
974
|
+
}[];
|
|
975
|
+
};
|
|
976
|
+
/**
|
|
977
|
+
* Set timeline name
|
|
978
|
+
*
|
|
979
|
+
* @param name - New timeline name
|
|
980
|
+
* @returns Dispatch result
|
|
981
|
+
*/
|
|
982
|
+
setTimelineName(name: string): {
|
|
983
|
+
accepted: boolean;
|
|
984
|
+
errors?: {
|
|
985
|
+
code: string;
|
|
986
|
+
message: string;
|
|
987
|
+
}[];
|
|
988
|
+
};
|
|
989
|
+
/**
|
|
990
|
+
* Undo the last action
|
|
991
|
+
*
|
|
992
|
+
* @returns true if undo was performed
|
|
993
|
+
*/
|
|
994
|
+
undo(): boolean;
|
|
995
|
+
/**
|
|
996
|
+
* Redo the last undone action
|
|
997
|
+
*
|
|
998
|
+
* @returns true if redo was performed
|
|
999
|
+
*/
|
|
1000
|
+
redo(): boolean;
|
|
1001
|
+
/**
|
|
1002
|
+
* Check if undo is available
|
|
1003
|
+
*
|
|
1004
|
+
* @returns true if undo is available
|
|
1005
|
+
*/
|
|
1006
|
+
canUndo(): boolean;
|
|
1007
|
+
/**
|
|
1008
|
+
* Check if redo is available
|
|
1009
|
+
*
|
|
1010
|
+
* @returns true if redo is available
|
|
1011
|
+
*/
|
|
1012
|
+
canRedo(): boolean;
|
|
1013
|
+
/**
|
|
1014
|
+
* Find a clip by ID
|
|
1015
|
+
*
|
|
1016
|
+
* @param clipId - Clip ID
|
|
1017
|
+
* @returns The clip, or undefined if not found
|
|
1018
|
+
*/
|
|
1019
|
+
findClipById(clipId: string): Clip | undefined;
|
|
1020
|
+
/**
|
|
1021
|
+
* Find a track by ID
|
|
1022
|
+
*
|
|
1023
|
+
* @param trackId - Track ID
|
|
1024
|
+
* @returns The track, or undefined if not found
|
|
1025
|
+
*/
|
|
1026
|
+
findTrackById(trackId: string): Track | undefined;
|
|
1027
|
+
/**
|
|
1028
|
+
* Get all clips on a track
|
|
1029
|
+
*
|
|
1030
|
+
* @param trackId - Track ID
|
|
1031
|
+
* @returns Array of clips on the track
|
|
1032
|
+
*/
|
|
1033
|
+
getClipsOnTrack(trackId: string): Clip[];
|
|
1034
|
+
/**
|
|
1035
|
+
* Get all clips at a specific frame
|
|
1036
|
+
*
|
|
1037
|
+
* @param frame - Frame to check
|
|
1038
|
+
* @returns Array of clips at that frame
|
|
1039
|
+
*/
|
|
1040
|
+
getClipsAtFrame(f: TimelineFrame): Clip[];
|
|
1041
|
+
/**
|
|
1042
|
+
* Get all clips in a frame range
|
|
1043
|
+
*
|
|
1044
|
+
* @param start - Start frame
|
|
1045
|
+
* @param end - End frame
|
|
1046
|
+
* @returns Array of clips in the range
|
|
1047
|
+
*/
|
|
1048
|
+
getClipsInRange(start: TimelineFrame, end: TimelineFrame): Clip[];
|
|
1049
|
+
/**
|
|
1050
|
+
* Get all clips in the timeline
|
|
1051
|
+
*
|
|
1052
|
+
* @returns Array of all clips
|
|
1053
|
+
*/
|
|
1054
|
+
getAllClips(): Clip[];
|
|
1055
|
+
/**
|
|
1056
|
+
* Get all tracks in the timeline
|
|
1057
|
+
*
|
|
1058
|
+
* @returns Array of all tracks
|
|
1059
|
+
*/
|
|
1060
|
+
getAllTracks(): readonly Track[];
|
|
1061
|
+
/**
|
|
1062
|
+
* Ripple delete - delete clip and shift subsequent clips left
|
|
1063
|
+
*
|
|
1064
|
+
* @param clipId - ID of the clip to delete
|
|
1065
|
+
* @returns Dispatch result
|
|
1066
|
+
*/
|
|
1067
|
+
rippleDelete(clipId: string): {
|
|
1068
|
+
accepted: boolean;
|
|
1069
|
+
errors?: {
|
|
1070
|
+
code: string;
|
|
1071
|
+
message: string;
|
|
1072
|
+
}[];
|
|
1073
|
+
};
|
|
1074
|
+
/**
|
|
1075
|
+
* Ripple trim - trim clip end and shift subsequent clips
|
|
1076
|
+
*
|
|
1077
|
+
* @param clipId - ID of the clip to trim
|
|
1078
|
+
* @param newEnd - New end frame for the clip
|
|
1079
|
+
* @returns Dispatch result
|
|
1080
|
+
*/
|
|
1081
|
+
rippleTrim(clipId: string, newEnd: TimelineFrame): {
|
|
1082
|
+
accepted: boolean;
|
|
1083
|
+
errors?: {
|
|
1084
|
+
code: string;
|
|
1085
|
+
message: string;
|
|
1086
|
+
}[];
|
|
1087
|
+
};
|
|
1088
|
+
/**
|
|
1089
|
+
* Insert edit - insert clip and shift subsequent clips right
|
|
1090
|
+
*
|
|
1091
|
+
* @param trackId - ID of the track to insert into
|
|
1092
|
+
* @param clip - Clip to insert
|
|
1093
|
+
* @param atFrame - Frame to insert at
|
|
1094
|
+
* @returns Dispatch result
|
|
1095
|
+
*/
|
|
1096
|
+
insertEdit(trackId: string, clip: Clip, atFrame: TimelineFrame): {
|
|
1097
|
+
accepted: boolean;
|
|
1098
|
+
errors?: {
|
|
1099
|
+
code: string;
|
|
1100
|
+
message: string;
|
|
1101
|
+
}[];
|
|
1102
|
+
};
|
|
1103
|
+
/**
|
|
1104
|
+
* Ripple move - move clip and shift surrounding clips to accommodate
|
|
1105
|
+
*
|
|
1106
|
+
* This moves a clip to a new position while maintaining timeline continuity:
|
|
1107
|
+
* - Closes the gap at the source position
|
|
1108
|
+
* - Makes space at the destination position
|
|
1109
|
+
* - All operations are atomic (single undo entry)
|
|
1110
|
+
*
|
|
1111
|
+
* @param clipId - ID of the clip to move
|
|
1112
|
+
* @param newStart - New start frame for the clip
|
|
1113
|
+
* @returns Dispatch result
|
|
1114
|
+
*/
|
|
1115
|
+
rippleMove(clipId: string, newStart: TimelineFrame): {
|
|
1116
|
+
accepted: boolean;
|
|
1117
|
+
errors?: {
|
|
1118
|
+
code: string;
|
|
1119
|
+
message: string;
|
|
1120
|
+
}[];
|
|
1121
|
+
};
|
|
1122
|
+
/**
|
|
1123
|
+
* Insert move - move clip and shift destination clips right
|
|
1124
|
+
*
|
|
1125
|
+
* This moves a clip to a new position without closing the gap at source:
|
|
1126
|
+
* - Leaves gap at the source position
|
|
1127
|
+
* - Pushes all clips at destination right to make space
|
|
1128
|
+
* - All operations are atomic (single undo entry)
|
|
1129
|
+
*
|
|
1130
|
+
* @param clipId - ID of the clip to move
|
|
1131
|
+
* @param newStart - New start frame for the clip
|
|
1132
|
+
* @returns Dispatch result
|
|
1133
|
+
*/
|
|
1134
|
+
insertMove(clipId: string, newStart: TimelineFrame): {
|
|
1135
|
+
accepted: boolean;
|
|
1136
|
+
errors?: {
|
|
1137
|
+
code: string;
|
|
1138
|
+
message: string;
|
|
1139
|
+
}[];
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* OPERATION PRIMITIVES — Phase 0 compliant
|
|
1145
|
+
*
|
|
1146
|
+
* The ONLY way to express a mutation in the engine.
|
|
1147
|
+
* All mutations flow through: OperationPrimitive[] → Transaction → Dispatcher.
|
|
1148
|
+
*
|
|
1149
|
+
* RULE: Never add a new mutation function.
|
|
1150
|
+
* Add a new type to OperationPrimitive, handle it in the Dispatcher switch,
|
|
1151
|
+
* update the InvariantChecker, and update OPERATIONS.md.
|
|
1152
|
+
*
|
|
1153
|
+
* RULE: Transactions are all-or-nothing.
|
|
1154
|
+
* If any primitive fails validation, the entire Transaction is rejected.
|
|
1155
|
+
*/
|
|
1156
|
+
|
|
1157
|
+
type OperationPrimitive = {
|
|
1158
|
+
type: 'MOVE_CLIP';
|
|
1159
|
+
clipId: ClipId;
|
|
1160
|
+
newTimelineStart: TimelineFrame;
|
|
1161
|
+
targetTrackId?: TrackId;
|
|
1162
|
+
} | {
|
|
1163
|
+
type: 'RESIZE_CLIP';
|
|
1164
|
+
clipId: ClipId;
|
|
1165
|
+
edge: 'start' | 'end';
|
|
1166
|
+
newFrame: TimelineFrame;
|
|
1167
|
+
} | {
|
|
1168
|
+
type: 'SLICE_CLIP';
|
|
1169
|
+
clipId: ClipId;
|
|
1170
|
+
atFrame: TimelineFrame;
|
|
1171
|
+
} | {
|
|
1172
|
+
type: 'DELETE_CLIP';
|
|
1173
|
+
clipId: ClipId;
|
|
1174
|
+
} | {
|
|
1175
|
+
type: 'INSERT_CLIP';
|
|
1176
|
+
clip: Clip;
|
|
1177
|
+
trackId: TrackId;
|
|
1178
|
+
} | {
|
|
1179
|
+
type: 'SET_MEDIA_BOUNDS';
|
|
1180
|
+
clipId: ClipId;
|
|
1181
|
+
mediaIn: TimelineFrame;
|
|
1182
|
+
mediaOut: TimelineFrame;
|
|
1183
|
+
} | {
|
|
1184
|
+
type: 'SET_CLIP_ENABLED';
|
|
1185
|
+
clipId: ClipId;
|
|
1186
|
+
enabled: boolean;
|
|
1187
|
+
} | {
|
|
1188
|
+
type: 'SET_CLIP_REVERSED';
|
|
1189
|
+
clipId: ClipId;
|
|
1190
|
+
reversed: boolean;
|
|
1191
|
+
} | {
|
|
1192
|
+
type: 'SET_CLIP_SPEED';
|
|
1193
|
+
clipId: ClipId;
|
|
1194
|
+
speed: number;
|
|
1195
|
+
} | {
|
|
1196
|
+
type: 'SET_CLIP_COLOR';
|
|
1197
|
+
clipId: ClipId;
|
|
1198
|
+
color: string | null;
|
|
1199
|
+
} | {
|
|
1200
|
+
type: 'SET_CLIP_NAME';
|
|
1201
|
+
clipId: ClipId;
|
|
1202
|
+
name: string | null;
|
|
1203
|
+
} | {
|
|
1204
|
+
type: 'ADD_TRACK';
|
|
1205
|
+
track: Track;
|
|
1206
|
+
} | {
|
|
1207
|
+
type: 'DELETE_TRACK';
|
|
1208
|
+
trackId: TrackId;
|
|
1209
|
+
} | {
|
|
1210
|
+
type: 'REORDER_TRACK';
|
|
1211
|
+
trackId: TrackId;
|
|
1212
|
+
newIndex: number;
|
|
1213
|
+
} | {
|
|
1214
|
+
type: 'SET_TRACK_HEIGHT';
|
|
1215
|
+
trackId: TrackId;
|
|
1216
|
+
height: number;
|
|
1217
|
+
} | {
|
|
1218
|
+
type: 'SET_TRACK_NAME';
|
|
1219
|
+
trackId: TrackId;
|
|
1220
|
+
name: string;
|
|
1221
|
+
} | {
|
|
1222
|
+
type: 'REGISTER_ASSET';
|
|
1223
|
+
asset: Asset;
|
|
1224
|
+
} | {
|
|
1225
|
+
type: 'UNREGISTER_ASSET';
|
|
1226
|
+
assetId: AssetId;
|
|
1227
|
+
} | {
|
|
1228
|
+
type: 'SET_ASSET_STATUS';
|
|
1229
|
+
assetId: AssetId;
|
|
1230
|
+
status: AssetStatus;
|
|
1231
|
+
} | {
|
|
1232
|
+
type: 'RENAME_TIMELINE';
|
|
1233
|
+
name: string;
|
|
1234
|
+
} | {
|
|
1235
|
+
type: 'SET_TIMELINE_DURATION';
|
|
1236
|
+
duration: TimelineFrame;
|
|
1237
|
+
} | {
|
|
1238
|
+
type: 'SET_TIMELINE_START_TC';
|
|
1239
|
+
startTimecode: Timecode;
|
|
1240
|
+
} | {
|
|
1241
|
+
type: 'SET_SEQUENCE_SETTINGS';
|
|
1242
|
+
settings: Partial<SequenceSettings>;
|
|
1243
|
+
} | {
|
|
1244
|
+
type: 'ADD_MARKER';
|
|
1245
|
+
marker: Marker;
|
|
1246
|
+
} | {
|
|
1247
|
+
type: 'MOVE_MARKER';
|
|
1248
|
+
markerId: MarkerId;
|
|
1249
|
+
newFrame: TimelineFrame;
|
|
1250
|
+
} | {
|
|
1251
|
+
type: 'DELETE_MARKER';
|
|
1252
|
+
markerId: MarkerId;
|
|
1253
|
+
} | {
|
|
1254
|
+
type: 'SET_IN_POINT';
|
|
1255
|
+
frame: TimelineFrame | null;
|
|
1256
|
+
} | {
|
|
1257
|
+
type: 'SET_OUT_POINT';
|
|
1258
|
+
frame: TimelineFrame | null;
|
|
1259
|
+
} | {
|
|
1260
|
+
type: 'ADD_BEAT_GRID';
|
|
1261
|
+
beatGrid: BeatGrid;
|
|
1262
|
+
} | {
|
|
1263
|
+
type: 'REMOVE_BEAT_GRID';
|
|
1264
|
+
} | {
|
|
1265
|
+
type: 'INSERT_GENERATOR';
|
|
1266
|
+
generator: Generator;
|
|
1267
|
+
trackId: TrackId;
|
|
1268
|
+
atFrame: TimelineFrame;
|
|
1269
|
+
} | {
|
|
1270
|
+
type: 'ADD_CAPTION';
|
|
1271
|
+
caption: Omit<Caption, 'style'> & {
|
|
1272
|
+
style?: CaptionStyle;
|
|
1273
|
+
};
|
|
1274
|
+
trackId: TrackId;
|
|
1275
|
+
} | {
|
|
1276
|
+
type: 'EDIT_CAPTION';
|
|
1277
|
+
captionId: CaptionId;
|
|
1278
|
+
trackId: TrackId;
|
|
1279
|
+
text?: string;
|
|
1280
|
+
language?: string;
|
|
1281
|
+
style?: Partial<CaptionStyle>;
|
|
1282
|
+
burnIn?: boolean;
|
|
1283
|
+
startFrame?: TimelineFrame;
|
|
1284
|
+
endFrame?: TimelineFrame;
|
|
1285
|
+
} | {
|
|
1286
|
+
type: 'DELETE_CAPTION';
|
|
1287
|
+
captionId: CaptionId;
|
|
1288
|
+
trackId: TrackId;
|
|
1289
|
+
} | {
|
|
1290
|
+
type: 'ADD_EFFECT';
|
|
1291
|
+
clipId: ClipId;
|
|
1292
|
+
effect: Effect;
|
|
1293
|
+
} | {
|
|
1294
|
+
type: 'REMOVE_EFFECT';
|
|
1295
|
+
clipId: ClipId;
|
|
1296
|
+
effectId: EffectId;
|
|
1297
|
+
} | {
|
|
1298
|
+
type: 'REORDER_EFFECT';
|
|
1299
|
+
clipId: ClipId;
|
|
1300
|
+
effectId: EffectId;
|
|
1301
|
+
newIndex: number;
|
|
1302
|
+
} | {
|
|
1303
|
+
type: 'SET_EFFECT_ENABLED';
|
|
1304
|
+
clipId: ClipId;
|
|
1305
|
+
effectId: EffectId;
|
|
1306
|
+
enabled: boolean;
|
|
1307
|
+
} | {
|
|
1308
|
+
type: 'SET_EFFECT_PARAM';
|
|
1309
|
+
clipId: ClipId;
|
|
1310
|
+
effectId: EffectId;
|
|
1311
|
+
key: string;
|
|
1312
|
+
value: number | string | boolean;
|
|
1313
|
+
} | {
|
|
1314
|
+
type: 'ADD_KEYFRAME';
|
|
1315
|
+
clipId: ClipId;
|
|
1316
|
+
effectId: EffectId;
|
|
1317
|
+
keyframe: Keyframe;
|
|
1318
|
+
} | {
|
|
1319
|
+
type: 'MOVE_KEYFRAME';
|
|
1320
|
+
clipId: ClipId;
|
|
1321
|
+
effectId: EffectId;
|
|
1322
|
+
keyframeId: KeyframeId;
|
|
1323
|
+
newFrame: TimelineFrame;
|
|
1324
|
+
} | {
|
|
1325
|
+
type: 'DELETE_KEYFRAME';
|
|
1326
|
+
clipId: ClipId;
|
|
1327
|
+
effectId: EffectId;
|
|
1328
|
+
keyframeId: KeyframeId;
|
|
1329
|
+
} | {
|
|
1330
|
+
type: 'SET_KEYFRAME_EASING';
|
|
1331
|
+
clipId: ClipId;
|
|
1332
|
+
effectId: EffectId;
|
|
1333
|
+
keyframeId: KeyframeId;
|
|
1334
|
+
easing: EasingCurve;
|
|
1335
|
+
} | {
|
|
1336
|
+
type: 'SET_CLIP_TRANSFORM';
|
|
1337
|
+
clipId: ClipId;
|
|
1338
|
+
transform: Partial<ClipTransform>;
|
|
1339
|
+
} | {
|
|
1340
|
+
type: 'SET_AUDIO_PROPERTIES';
|
|
1341
|
+
clipId: ClipId;
|
|
1342
|
+
properties: Partial<AudioProperties>;
|
|
1343
|
+
} | {
|
|
1344
|
+
type: 'ADD_TRANSITION';
|
|
1345
|
+
clipId: ClipId;
|
|
1346
|
+
transition: Transition;
|
|
1347
|
+
} | {
|
|
1348
|
+
type: 'DELETE_TRANSITION';
|
|
1349
|
+
clipId: ClipId;
|
|
1350
|
+
} | {
|
|
1351
|
+
type: 'SET_TRANSITION_DURATION';
|
|
1352
|
+
clipId: ClipId;
|
|
1353
|
+
durationFrames: number;
|
|
1354
|
+
} | {
|
|
1355
|
+
type: 'SET_TRANSITION_ALIGNMENT';
|
|
1356
|
+
clipId: ClipId;
|
|
1357
|
+
alignment: TransitionAlignment;
|
|
1358
|
+
} | {
|
|
1359
|
+
type: 'LINK_CLIPS';
|
|
1360
|
+
linkGroup: LinkGroup;
|
|
1361
|
+
} | {
|
|
1362
|
+
type: 'UNLINK_CLIPS';
|
|
1363
|
+
linkGroupId: LinkGroupId;
|
|
1364
|
+
} | {
|
|
1365
|
+
type: 'ADD_TRACK_GROUP';
|
|
1366
|
+
trackGroup: TrackGroup;
|
|
1367
|
+
} | {
|
|
1368
|
+
type: 'DELETE_TRACK_GROUP';
|
|
1369
|
+
trackGroupId: TrackGroupId;
|
|
1370
|
+
} | {
|
|
1371
|
+
type: 'SET_TRACK_BLEND_MODE';
|
|
1372
|
+
trackId: TrackId;
|
|
1373
|
+
blendMode: string;
|
|
1374
|
+
} | {
|
|
1375
|
+
type: 'SET_TRACK_OPACITY';
|
|
1376
|
+
trackId: TrackId;
|
|
1377
|
+
opacity: number;
|
|
1378
|
+
};
|
|
1379
|
+
/**
|
|
1380
|
+
* Transaction — an atomic, labeled batch of OperationPrimitives.
|
|
1381
|
+
*
|
|
1382
|
+
* All primitives in a Transaction are validated before any are applied.
|
|
1383
|
+
* If one fails, none are applied. This is the all-or-nothing rule.
|
|
1384
|
+
*/
|
|
1385
|
+
type Transaction = {
|
|
1386
|
+
readonly id: string;
|
|
1387
|
+
readonly label: string;
|
|
1388
|
+
readonly timestamp: number;
|
|
1389
|
+
readonly operations: readonly OperationPrimitive[];
|
|
1390
|
+
};
|
|
1391
|
+
type RejectionReason = 'OVERLAP' | 'LOCKED_TRACK' | 'ASSET_MISSING' | 'TYPE_MISMATCH' | 'OUT_OF_BOUNDS' | 'MEDIA_BOUNDS_INVALID' | 'ASSET_IN_USE' | 'TRACK_NOT_EMPTY' | 'SPEED_INVALID' | 'INVARIANT_VIOLATED' | 'NOT_FOUND' | 'BEAT_GRID_EXISTS' | 'CLIP_NOT_FOUND' | 'DUPLICATE_EFFECT_ID' | 'EFFECT_NOT_FOUND' | 'EFFECT_INDEX_OUT_OF_RANGE' | 'KEYFRAME_NOT_FOUND' | 'DUPLICATE_KEYFRAME_ID' | 'INVALID_RANGE' | 'TRANSITION_NOT_FOUND' | 'LINK_GROUP_NOT_FOUND' | 'TRACK_GROUP_NOT_FOUND' | 'DUPLICATE_LINK_GROUP_ID' | 'DUPLICATE_TRACK_GROUP_ID' | 'INVALID_OPACITY' | 'TRACK_NOT_FOUND';
|
|
1392
|
+
type DispatchResult = {
|
|
1393
|
+
accepted: true;
|
|
1394
|
+
nextState: TimelineState;
|
|
1395
|
+
} | {
|
|
1396
|
+
accepted: false;
|
|
1397
|
+
reason: RejectionReason;
|
|
1398
|
+
message: string;
|
|
1399
|
+
};
|
|
1400
|
+
type ViolationType = 'OVERLAP' | 'MEDIA_BOUNDS_INVALID' | 'ASSET_MISSING' | 'TRACK_TYPE_MISMATCH' | 'CLIP_BEYOND_TIMELINE' | 'TRACK_NOT_SORTED' | 'DURATION_MISMATCH' | 'SPEED_INVALID' | 'SCHEMA_VERSION_MISMATCH' | 'MARKER_OUT_OF_BOUNDS' | 'IN_OUT_INVALID' | 'BEAT_GRID_INVALID' | 'CAPTION_OUT_OF_BOUNDS' | 'CAPTION_OVERLAP' | 'EFFECT_NOT_FOUND' | 'KEYFRAME_NOT_FOUND' | 'KEYFRAME_ORDER_VIOLATION' | 'EFFECT_INDEX_OUT_OF_RANGE' | 'INVALID_RENDER_STAGE' | 'TRACK_GROUP_NOT_FOUND' | 'INVALID_OPACITY' | 'INVALID_RANGE' | 'LINK_GROUP_NOT_FOUND';
|
|
1401
|
+
type InvariantViolation = {
|
|
1402
|
+
readonly type: ViolationType;
|
|
1403
|
+
readonly entityId: string;
|
|
1404
|
+
readonly message: string;
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
/**
|
|
1408
|
+
* DISPATCHER — Phase 0 compliant
|
|
1409
|
+
*
|
|
1410
|
+
* The ONLY entry point for mutating TimelineState.
|
|
1411
|
+
* Validates first, applies atomically, checks invariants.
|
|
1412
|
+
*
|
|
1413
|
+
* Algorithm:
|
|
1414
|
+
* 1. For each operation: run per-primitive validator → reject immediately on failure
|
|
1415
|
+
* 2. Apply all operations sequentially to get proposedState
|
|
1416
|
+
* 3. Run checkInvariants(proposedState) → reject on any violation
|
|
1417
|
+
* 4. Bump timeline.version by 1 and return accepted
|
|
1418
|
+
*
|
|
1419
|
+
* RULE: If one primitive fails, zero primitives are applied.
|
|
1420
|
+
*/
|
|
1421
|
+
|
|
1422
|
+
declare function dispatch(state: TimelineState, transaction: Transaction): DispatchResult;
|
|
1423
|
+
|
|
1424
|
+
/**
|
|
1425
|
+
* INVARIANT CHECKER — Phase 0 compliant
|
|
1426
|
+
*
|
|
1427
|
+
* The most critical file in the engine.
|
|
1428
|
+
* checkInvariants() runs after every proposed state change inside the Dispatcher.
|
|
1429
|
+
* Zero violations is the only acceptable result in tests and at commit time.
|
|
1430
|
+
*
|
|
1431
|
+
* RULE: Run checkInvariants in EVERY test after every state mutation.
|
|
1432
|
+
*/
|
|
1433
|
+
|
|
1434
|
+
declare function checkInvariants(state: TimelineState): InvariantViolation[];
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Transaction compression policy — Phase 7 Step 3
|
|
1438
|
+
*
|
|
1439
|
+
* Rapid same-type ops within a time window can be merged
|
|
1440
|
+
* into a single history entry (last-write-wins).
|
|
1441
|
+
*/
|
|
1442
|
+
type CompressionPolicy = {
|
|
1443
|
+
readonly kind: 'none';
|
|
1444
|
+
} | {
|
|
1445
|
+
readonly kind: 'last-write-wins';
|
|
1446
|
+
readonly windowMs: number;
|
|
1447
|
+
};
|
|
1448
|
+
type CompressibleOpType = 'MOVE_CLIP' | 'SET_CLIP_TRANSFORM' | 'SET_AUDIO_PROPERTIES' | 'SET_EFFECT_PARAM' | 'MOVE_KEYFRAME' | 'SET_TRANSITION_DURATION' | 'MOVE_MARKER' | 'SET_IN_POINT' | 'SET_OUT_POINT' | 'SET_TRACK_OPACITY';
|
|
1449
|
+
declare const DEFAULT_COMPRESSION_POLICY: CompressionPolicy;
|
|
1450
|
+
declare const NO_COMPRESSION: CompressionPolicy;
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* HISTORY ENGINE
|
|
1454
|
+
*
|
|
1455
|
+
* Snapshot-based undo/redo system for timeline state.
|
|
1456
|
+
*
|
|
1457
|
+
* Two APIs:
|
|
1458
|
+
* - HistoryState + pure functions (createHistory, pushHistory, undo, redo)
|
|
1459
|
+
* - HistoryStack class with compression, checkpoints, and persistence
|
|
1460
|
+
*/
|
|
1461
|
+
|
|
1462
|
+
/**
|
|
1463
|
+
* HistoryState - The history container
|
|
1464
|
+
*
|
|
1465
|
+
* Contains:
|
|
1466
|
+
* - past: Array of previous states (oldest first)
|
|
1467
|
+
* - present: Current state
|
|
1468
|
+
* - future: Array of states that can be redone (newest first)
|
|
1469
|
+
* - limit: Maximum number of past states to keep
|
|
1470
|
+
*/
|
|
1471
|
+
interface HistoryState {
|
|
1472
|
+
past: TimelineState[];
|
|
1473
|
+
present: TimelineState;
|
|
1474
|
+
future: TimelineState[];
|
|
1475
|
+
limit: number;
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Create a new history state
|
|
1479
|
+
*
|
|
1480
|
+
* @param initialState - Initial timeline state
|
|
1481
|
+
* @param limit - Maximum number of past states to keep (default: 50)
|
|
1482
|
+
* @returns A new HistoryState
|
|
1483
|
+
*/
|
|
1484
|
+
declare function createHistory(initialState: TimelineState, limit?: number): HistoryState;
|
|
1485
|
+
/**
|
|
1486
|
+
* Push a new state to history
|
|
1487
|
+
*
|
|
1488
|
+
* Moves current state to past, sets new state as present,
|
|
1489
|
+
* and clears future (can't redo after new action).
|
|
1490
|
+
*
|
|
1491
|
+
* @param history - Current history state
|
|
1492
|
+
* @param newState - New timeline state to push
|
|
1493
|
+
* @returns New history state with new state pushed
|
|
1494
|
+
*/
|
|
1495
|
+
declare function pushHistory(history: HistoryState, newState: TimelineState): HistoryState;
|
|
1496
|
+
/**
|
|
1497
|
+
* Undo the last action
|
|
1498
|
+
*
|
|
1499
|
+
* Moves current state to future, pops last state from past
|
|
1500
|
+
* and sets it as present.
|
|
1501
|
+
*
|
|
1502
|
+
* @param history - Current history state
|
|
1503
|
+
* @returns New history state with undo applied
|
|
1504
|
+
*/
|
|
1505
|
+
declare function undo(history: HistoryState): HistoryState;
|
|
1506
|
+
/**
|
|
1507
|
+
* Redo the last undone action
|
|
1508
|
+
*
|
|
1509
|
+
* Moves current state to past, pops first state from future
|
|
1510
|
+
* and sets it as present.
|
|
1511
|
+
*
|
|
1512
|
+
* @param history - Current history state
|
|
1513
|
+
* @returns New history state with redo applied
|
|
1514
|
+
*/
|
|
1515
|
+
declare function redo(history: HistoryState): HistoryState;
|
|
1516
|
+
/**
|
|
1517
|
+
* Check if undo is available
|
|
1518
|
+
*
|
|
1519
|
+
* @param history - Current history state
|
|
1520
|
+
* @returns true if undo is available
|
|
1521
|
+
*/
|
|
1522
|
+
declare function canUndo(history: HistoryState): boolean;
|
|
1523
|
+
/**
|
|
1524
|
+
* Check if redo is available
|
|
1525
|
+
*
|
|
1526
|
+
* @param history - Current history state
|
|
1527
|
+
* @returns true if redo is available
|
|
1528
|
+
*/
|
|
1529
|
+
declare function canRedo(history: HistoryState): boolean;
|
|
1530
|
+
/**
|
|
1531
|
+
* Get the current state from history
|
|
1532
|
+
*
|
|
1533
|
+
* @param history - Current history state
|
|
1534
|
+
* @returns The current timeline state
|
|
1535
|
+
*/
|
|
1536
|
+
declare function getCurrentState(history: HistoryState): TimelineState;
|
|
1537
|
+
type HistoryEntry = {
|
|
1538
|
+
readonly state: TimelineState;
|
|
1539
|
+
readonly transaction: Transaction;
|
|
1540
|
+
};
|
|
1541
|
+
declare class HistoryStack {
|
|
1542
|
+
private entries;
|
|
1543
|
+
private undoIndex;
|
|
1544
|
+
private limit;
|
|
1545
|
+
private compressor;
|
|
1546
|
+
private clock;
|
|
1547
|
+
private checkpoints;
|
|
1548
|
+
constructor(limit?: number, policy?: CompressionPolicy, clock?: () => number);
|
|
1549
|
+
push(entry: HistoryEntry): void;
|
|
1550
|
+
pushWithCompression(entry: HistoryEntry, transaction: Transaction): void;
|
|
1551
|
+
resetCompression(): void;
|
|
1552
|
+
undo(): TimelineState | null;
|
|
1553
|
+
redo(): TimelineState | null;
|
|
1554
|
+
getCurrentState(): TimelineState | null;
|
|
1555
|
+
canUndo(): boolean;
|
|
1556
|
+
canRedo(): boolean;
|
|
1557
|
+
saveCheckpoint(name: string): void;
|
|
1558
|
+
restoreCheckpoint(name: string): HistoryEntry | null;
|
|
1559
|
+
listCheckpoints(): string[];
|
|
1560
|
+
clearCheckpoint(name: string): void;
|
|
1561
|
+
serialize(): string;
|
|
1562
|
+
static deserialize(raw: string, limit?: number, policy?: CompressionPolicy, clock?: () => number): HistoryStack;
|
|
1563
|
+
softLimitWarning(): boolean;
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
/**
|
|
1567
|
+
* TransactionCompressor — Phase 7 Step 3
|
|
1568
|
+
*
|
|
1569
|
+
* Decides whether a transaction should be merged into the previous
|
|
1570
|
+
* history entry (same op type within window).
|
|
1571
|
+
*/
|
|
1572
|
+
|
|
1573
|
+
declare class TransactionCompressor {
|
|
1574
|
+
private lastOpType;
|
|
1575
|
+
private lastTime;
|
|
1576
|
+
private policy;
|
|
1577
|
+
private clock;
|
|
1578
|
+
constructor(policy?: CompressionPolicy, clock?: () => number);
|
|
1579
|
+
shouldCompress(transaction: Transaction, now: number): boolean;
|
|
1580
|
+
record(transaction: Transaction, now: number): void;
|
|
1581
|
+
reset(): void;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
/**
|
|
1585
|
+
* SNAP INDEX — Phase 1
|
|
1586
|
+
*
|
|
1587
|
+
* Pure functions. Zero React/DOM imports. Zero mutation.
|
|
1588
|
+
*
|
|
1589
|
+
* Phase 1 snap sources: ClipStart, ClipEnd, Playhead.
|
|
1590
|
+
* Phase 2 will add: Marker, InPoint, OutPoint.
|
|
1591
|
+
* Phase 3 will add: BeatGrid.
|
|
1592
|
+
*
|
|
1593
|
+
* Priority table (do not change values):
|
|
1594
|
+
* Marker: 100
|
|
1595
|
+
* InPoint: 90
|
|
1596
|
+
* OutPoint: 90
|
|
1597
|
+
* ClipStart: 80
|
|
1598
|
+
* ClipEnd: 80
|
|
1599
|
+
* Playhead: 70
|
|
1600
|
+
* BeatGrid: 50
|
|
1601
|
+
*/
|
|
1602
|
+
|
|
1603
|
+
/**
|
|
1604
|
+
* All snap point sources across phases.
|
|
1605
|
+
* Defined in full now so SnapPoint & allowedTypes filters are stable.
|
|
1606
|
+
*/
|
|
1607
|
+
type SnapPointType = 'ClipStart' | 'ClipEnd' | 'Playhead' | 'Marker' | 'InPoint' | 'OutPoint' | 'BeatGrid';
|
|
1608
|
+
type SnapPoint = {
|
|
1609
|
+
readonly frame: TimelineFrame;
|
|
1610
|
+
readonly type: SnapPointType;
|
|
1611
|
+
readonly priority: number;
|
|
1612
|
+
readonly trackId: TrackId | null;
|
|
1613
|
+
readonly sourceId: string;
|
|
1614
|
+
};
|
|
1615
|
+
type SnapIndex = {
|
|
1616
|
+
readonly points: readonly SnapPoint[];
|
|
1617
|
+
readonly builtAt: number;
|
|
1618
|
+
readonly enabled: boolean;
|
|
1619
|
+
};
|
|
1620
|
+
/**
|
|
1621
|
+
* Build a SnapIndex from committed state + playhead position.
|
|
1622
|
+
*
|
|
1623
|
+
* RULE: Call via queueMicrotask after accepted dispatch.
|
|
1624
|
+
* Never call during a drag (pointer move).
|
|
1625
|
+
*
|
|
1626
|
+
* Phase 1 sources pulled (in order):
|
|
1627
|
+
* 1. ClipStart + ClipEnd from every clip on every track
|
|
1628
|
+
* 2. Playhead position (trackId = null)
|
|
1629
|
+
*/
|
|
1630
|
+
declare function buildSnapIndex(state: TimelineState, playheadFrame: TimelineFrame, enabled?: boolean): SnapIndex;
|
|
1631
|
+
/**
|
|
1632
|
+
* Find the highest-priority snap candidate within radiusFrames.
|
|
1633
|
+
*
|
|
1634
|
+
* Returns null when:
|
|
1635
|
+
* - index.enabled is false
|
|
1636
|
+
* - no point is within radiusFrames of frame
|
|
1637
|
+
*
|
|
1638
|
+
* Tiebreak (equidistant candidates): highest priority wins.
|
|
1639
|
+
* Second tiebreak (equal priority): first in sorted order.
|
|
1640
|
+
*
|
|
1641
|
+
* @param exclude sourceIds to skip (e.g. the clip being dragged)
|
|
1642
|
+
* @param allowedTypes if provided, only consider points of these types
|
|
1643
|
+
*/
|
|
1644
|
+
declare function nearest(index: SnapIndex, frame: TimelineFrame, radiusFrames: number, exclude?: readonly string[], allowedTypes?: readonly SnapPointType[]): SnapPoint | null;
|
|
1645
|
+
/**
|
|
1646
|
+
* Return a new SnapIndex with enabled toggled.
|
|
1647
|
+
* Does NOT rebuild points — pure field update.
|
|
1648
|
+
*/
|
|
1649
|
+
declare function toggleSnap(index: SnapIndex, enabled: boolean): SnapIndex;
|
|
1650
|
+
|
|
1651
|
+
/**
|
|
1652
|
+
* SnapIndexManager — Phase 7 Step 2
|
|
1653
|
+
*
|
|
1654
|
+
* Debounces SnapIndex rebuilds using queueMicrotask.
|
|
1655
|
+
* Multiple scheduleRebuild() calls in one turn → single rebuild.
|
|
1656
|
+
*/
|
|
1657
|
+
|
|
1658
|
+
declare class SnapIndexManager {
|
|
1659
|
+
private index;
|
|
1660
|
+
private state;
|
|
1661
|
+
private pending;
|
|
1662
|
+
getIndex(): SnapIndex | null;
|
|
1663
|
+
scheduleRebuild(state: TimelineState): void;
|
|
1664
|
+
rebuildSync(state: TimelineState): void;
|
|
1665
|
+
get isPending(): boolean;
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
/**
|
|
1669
|
+
* TOOL CONTRACT TYPES — Phase 1
|
|
1670
|
+
*
|
|
1671
|
+
* Zero implementation. Zero imports from React or DOM.
|
|
1672
|
+
* Every ITool must satisfy this interface exactly.
|
|
1673
|
+
*
|
|
1674
|
+
* RULES (from ITOOL_CONTRACT.md):
|
|
1675
|
+
* - onPointerMove NEVER calls dispatch
|
|
1676
|
+
* - onPointerUp NEVER mutates instance state
|
|
1677
|
+
* - onKeyDown, onKeyUp, onCancel are REQUIRED — implement as no-ops if unused
|
|
1678
|
+
*/
|
|
1679
|
+
|
|
1680
|
+
type ToolId = string & {
|
|
1681
|
+
readonly __brand: 'ToolId';
|
|
1682
|
+
};
|
|
1683
|
+
declare function toToolId(s: string): ToolId;
|
|
1684
|
+
/** Keyboard modifier state — available on ToolContext so getCursor() can
|
|
1685
|
+
* react to held keys even when no pointer event is firing. */
|
|
1686
|
+
type Modifiers = {
|
|
1687
|
+
readonly shift: boolean;
|
|
1688
|
+
readonly alt: boolean;
|
|
1689
|
+
readonly ctrl: boolean;
|
|
1690
|
+
readonly meta: boolean;
|
|
1691
|
+
};
|
|
1692
|
+
/** Normalised pointer event in frame-space.
|
|
1693
|
+
* ToolRouter populates clipId via hit-test — tools never recompute it. */
|
|
1694
|
+
type TimelinePointerEvent = {
|
|
1695
|
+
readonly frame: TimelineFrame;
|
|
1696
|
+
readonly trackId: TrackId | null;
|
|
1697
|
+
readonly clipId: ClipId | null;
|
|
1698
|
+
readonly x: number;
|
|
1699
|
+
readonly y: number;
|
|
1700
|
+
readonly buttons: number;
|
|
1701
|
+
readonly shiftKey: boolean;
|
|
1702
|
+
readonly altKey: boolean;
|
|
1703
|
+
readonly metaKey: boolean;
|
|
1704
|
+
};
|
|
1705
|
+
type TimelineKeyEvent = {
|
|
1706
|
+
readonly key: string;
|
|
1707
|
+
readonly code: string;
|
|
1708
|
+
readonly shiftKey: boolean;
|
|
1709
|
+
readonly altKey: boolean;
|
|
1710
|
+
readonly metaKey: boolean;
|
|
1711
|
+
readonly ctrlKey: boolean;
|
|
1712
|
+
/** True when key is held and OS is firing repeated keydowns. */
|
|
1713
|
+
readonly repeat?: boolean;
|
|
1714
|
+
};
|
|
1715
|
+
/** Pixel + frame region swept by a rubber-band (marquee) selection drag.
|
|
1716
|
+
* Populated by SelectionTool during rubber-band drags. */
|
|
1717
|
+
type RubberBandRegion = {
|
|
1718
|
+
readonly startFrame: TimelineFrame;
|
|
1719
|
+
readonly endFrame: TimelineFrame;
|
|
1720
|
+
readonly startY: number;
|
|
1721
|
+
readonly endY: number;
|
|
1722
|
+
};
|
|
1723
|
+
/** Ghost state produced by onPointerMove.
|
|
1724
|
+
* isProvisional: true is a compile-time discriminant so resolveClip()
|
|
1725
|
+
* can distinguish provisional from committed Clip[] arrays. */
|
|
1726
|
+
type ProvisionalState = {
|
|
1727
|
+
readonly clips: readonly Clip[];
|
|
1728
|
+
readonly rubberBand?: RubberBandRegion;
|
|
1729
|
+
readonly isProvisional: true;
|
|
1730
|
+
};
|
|
1731
|
+
/** Injected by TimelineEngine on every event call.
|
|
1732
|
+
* Tools never import TimelineEngine. They never call dispatch() directly. */
|
|
1733
|
+
type ToolContext = {
|
|
1734
|
+
readonly state: TimelineState;
|
|
1735
|
+
readonly snapIndex: SnapIndex;
|
|
1736
|
+
readonly pixelsPerFrame: number;
|
|
1737
|
+
/** Current modifier key state — updates on every pointer/key event. */
|
|
1738
|
+
readonly modifiers: Modifiers;
|
|
1739
|
+
/** Convert a client-pixel x-position to a TimelineFrame. */
|
|
1740
|
+
readonly frameAtX: (x: number) => TimelineFrame;
|
|
1741
|
+
/** Return the TrackId whose row contains client-pixel y, or null. */
|
|
1742
|
+
readonly trackAtY: (y: number) => TrackId | null;
|
|
1743
|
+
/** Query snap and return the snapped frame (or original if no hit).
|
|
1744
|
+
* Handles enabled/disabled, radius, exclusion, and type filter internally.
|
|
1745
|
+
* Tools never see radiusFrames or the enabled flag. */
|
|
1746
|
+
readonly snap: (frame: TimelineFrame, exclude?: readonly string[], allowedTypes?: readonly SnapPointType[]) => TimelineFrame;
|
|
1747
|
+
};
|
|
1748
|
+
interface ITool {
|
|
1749
|
+
readonly id: ToolId;
|
|
1750
|
+
/** Single-character keyboard shortcut, e.g. 'v', 'b', 'r'. Empty string = no shortcut. */
|
|
1751
|
+
readonly shortcutKey: string;
|
|
1752
|
+
/** Return the CSS cursor string for the current tool + modifier state.
|
|
1753
|
+
* Called on every pointermove — must be cheap. */
|
|
1754
|
+
getCursor(ctx: ToolContext): string;
|
|
1755
|
+
/** Return the SnapPointType categories this tool snaps to.
|
|
1756
|
+
* Used by ctx.snap() to filter the snap index automatically. */
|
|
1757
|
+
getSnapCandidateTypes(): readonly SnapPointType[];
|
|
1758
|
+
onPointerDown(event: TimelinePointerEvent, ctx: ToolContext): void;
|
|
1759
|
+
/** Return ProvisionalState for ghost rendering.
|
|
1760
|
+
* MUST NOT call dispatch. MUST NOT call engine methods. */
|
|
1761
|
+
onPointerMove(event: TimelinePointerEvent, ctx: ToolContext): ProvisionalState | null;
|
|
1762
|
+
/** Return a Transaction to commit, or null if this gesture produces no edit.
|
|
1763
|
+
* MUST NOT mutate any instance state. */
|
|
1764
|
+
onPointerUp(event: TimelinePointerEvent, ctx: ToolContext): Transaction | null;
|
|
1765
|
+
/** Handle a keydown — return a Transaction or null.
|
|
1766
|
+
* Required — implement as `return null` if unused. */
|
|
1767
|
+
onKeyDown(event: TimelineKeyEvent, ctx: ToolContext): Transaction | null;
|
|
1768
|
+
/** Handle a keyup — no return value.
|
|
1769
|
+
* Required — implement as no-op if unused. */
|
|
1770
|
+
onKeyUp(event: TimelineKeyEvent, ctx: ToolContext): void;
|
|
1771
|
+
/** Called when a gesture is interrupted (Escape, tool switch mid-drag).
|
|
1772
|
+
* Required — implement as no-op if unused. */
|
|
1773
|
+
onCancel(): void;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
/**
|
|
1777
|
+
* TOOL REGISTRY — Phase 1
|
|
1778
|
+
*
|
|
1779
|
+
* Pure functions. No classes. No React. No state mutation.
|
|
1780
|
+
*
|
|
1781
|
+
* ToolRegistry is immutable data — activateTool returns a NEW registry.
|
|
1782
|
+
* The active tool lives here, not on TimelineEngine, keeping the engine thin.
|
|
1783
|
+
*
|
|
1784
|
+
* RULES:
|
|
1785
|
+
* - activateTool calls outgoing.onCancel() before switching
|
|
1786
|
+
* - activateTool throws on unknown id (programmer error, never user error)
|
|
1787
|
+
* - NoOpTool is the canonical do-nothing ITool (test double + startup default)
|
|
1788
|
+
*/
|
|
1789
|
+
|
|
1790
|
+
type ToolRegistry = {
|
|
1791
|
+
readonly tools: ReadonlyMap<ToolId, ITool>;
|
|
1792
|
+
readonly activeToolId: ToolId;
|
|
1793
|
+
};
|
|
1794
|
+
/**
|
|
1795
|
+
* Create an initial registry from an array of tools.
|
|
1796
|
+
*
|
|
1797
|
+
* @throws if defaultId is not present in the tools array
|
|
1798
|
+
*/
|
|
1799
|
+
declare function createRegistry(tools: readonly ITool[], defaultId: ToolId): ToolRegistry;
|
|
1800
|
+
/**
|
|
1801
|
+
* Activate a new tool.
|
|
1802
|
+
*
|
|
1803
|
+
* Steps (must run in order):
|
|
1804
|
+
* 1. Call outgoing tool's onCancel() — cleans up any in-progress drag state
|
|
1805
|
+
* 2. Validate that the new id exists in the registry
|
|
1806
|
+
* 3. Return a new ToolRegistry with activeToolId updated
|
|
1807
|
+
*
|
|
1808
|
+
* @throws if id is not registered
|
|
1809
|
+
*/
|
|
1810
|
+
declare function activateTool(registry: ToolRegistry, id: ToolId): ToolRegistry;
|
|
1811
|
+
/**
|
|
1812
|
+
* Return the currently active ITool.
|
|
1813
|
+
* Never returns undefined — registry invariant guarantees activeToolId is registered.
|
|
1814
|
+
*/
|
|
1815
|
+
declare function getActiveTool(registry: ToolRegistry): ITool;
|
|
1816
|
+
/**
|
|
1817
|
+
* Return a new registry with the tool added.
|
|
1818
|
+
* If a tool with the same id already exists, it is replaced.
|
|
1819
|
+
* activeToolId is unchanged.
|
|
1820
|
+
*/
|
|
1821
|
+
declare function registerTool(registry: ToolRegistry, tool: ITool): ToolRegistry;
|
|
1822
|
+
/**
|
|
1823
|
+
* Satisfies ITool with no side effects.
|
|
1824
|
+
*
|
|
1825
|
+
* Use for:
|
|
1826
|
+
* - Test doubles (spread and override only the methods you need)
|
|
1827
|
+
* - Default active tool on engine startup
|
|
1828
|
+
* - ToolRouter smoke tests
|
|
1829
|
+
*
|
|
1830
|
+
* onCancel() is a deliberate no-op: NoOpTool has no drag state to clean up.
|
|
1831
|
+
* Real tools will clear instance variables there.
|
|
1832
|
+
*/
|
|
1833
|
+
declare const NoOpTool: ITool;
|
|
1834
|
+
|
|
1835
|
+
/**
|
|
1836
|
+
* PROVISIONAL MANAGER — Phase 1
|
|
1837
|
+
*
|
|
1838
|
+
* Manages ghost state during pointer drags.
|
|
1839
|
+
*
|
|
1840
|
+
* RULES (from ITOOL_CONTRACT.md):
|
|
1841
|
+
* - setProvisional / clearProvisional return NEW objects — never mutate
|
|
1842
|
+
* - resolveClip checks provisional first, then committed state
|
|
1843
|
+
* - The engine calls clearProvisional() BEFORE dispatching onPointerUp's tx
|
|
1844
|
+
* - Provisional updates trigger notify() so ghosts render immediately
|
|
1845
|
+
*
|
|
1846
|
+
* resolveClip priority:
|
|
1847
|
+
* 1. provisional.clips has a clip with this id → return ghost version
|
|
1848
|
+
* 2. clip exists in committed state → return committed
|
|
1849
|
+
* 3. clip absent from both (deleted mid-drag) → return undefined
|
|
1850
|
+
*/
|
|
1851
|
+
|
|
1852
|
+
type ProvisionalManager = {
|
|
1853
|
+
readonly current: ProvisionalState | null;
|
|
1854
|
+
};
|
|
1855
|
+
/** Create an empty provisional manager (current = null). */
|
|
1856
|
+
declare function createProvisionalManager(): ProvisionalManager;
|
|
1857
|
+
/** Return a new manager with current set to state.
|
|
1858
|
+
* Pure — never mutates the original manager. */
|
|
1859
|
+
declare function setProvisional(_manager: ProvisionalManager, state: ProvisionalState): ProvisionalManager;
|
|
1860
|
+
/** Return a new manager with current set to null.
|
|
1861
|
+
* Pure — never mutates the original manager. */
|
|
1862
|
+
declare function clearProvisional(_manager: ProvisionalManager): ProvisionalManager;
|
|
1863
|
+
/**
|
|
1864
|
+
* Resolve which version of a clip to render.
|
|
1865
|
+
*
|
|
1866
|
+
* Priority:
|
|
1867
|
+
* 1. If manager.current has a clip with this id → return provisional (ghost)
|
|
1868
|
+
* 2. Otherwise → search committed state
|
|
1869
|
+
* 3. If absent from both (clip deleted mid-drag) → return undefined
|
|
1870
|
+
*
|
|
1871
|
+
* Returns undefined if the clip has been deleted from committed state
|
|
1872
|
+
* and is not in provisional. Components must handle this:
|
|
1873
|
+
* const clip = useClip(id)
|
|
1874
|
+
* if (!clip) return null ← required, not optional
|
|
1875
|
+
*
|
|
1876
|
+
* Call site in useClip selector:
|
|
1877
|
+
* () => resolveClip(id, engine.getSnapshot(), engine.getProvisionalManager())
|
|
1878
|
+
*/
|
|
1879
|
+
declare function resolveClip(clipId: ClipId, state: TimelineState, manager: ProvisionalManager): Clip | undefined;
|
|
1880
|
+
|
|
1881
|
+
/**
|
|
1882
|
+
* MARKER SEARCH API — Phase 3 Step 2
|
|
1883
|
+
*
|
|
1884
|
+
* Pure functions. Search state.timeline.markers only.
|
|
1885
|
+
*/
|
|
1886
|
+
|
|
1887
|
+
/**
|
|
1888
|
+
* Returns markers whose color exactly matches the given string.
|
|
1889
|
+
*/
|
|
1890
|
+
declare function findMarkersByColor(state: TimelineState, color: string): Marker[];
|
|
1891
|
+
/**
|
|
1892
|
+
* Returns markers whose label contains the given string (case-insensitive).
|
|
1893
|
+
*/
|
|
1894
|
+
declare function findMarkersByLabel(state: TimelineState, label: string): Marker[];
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* SUBTITLE IMPORT — Phase 3 Step 3
|
|
1898
|
+
*
|
|
1899
|
+
* Pure functions for parsing SRT/VTT into Caption[].
|
|
1900
|
+
* No file IO. No DOM. No external deps.
|
|
1901
|
+
*/
|
|
1902
|
+
|
|
1903
|
+
declare const defaultCaptionStyle: CaptionStyle;
|
|
1904
|
+
type SRTParseOptions = {
|
|
1905
|
+
language?: string;
|
|
1906
|
+
burnIn?: boolean;
|
|
1907
|
+
defaultStyle?: Partial<CaptionStyle>;
|
|
1908
|
+
};
|
|
1909
|
+
type VTTParseOptions = SRTParseOptions;
|
|
1910
|
+
declare function parseSRT(raw: string, fps: number, options?: SRTParseOptions): Caption[];
|
|
1911
|
+
declare function parseVTT(raw: string, fps: number, options?: VTTParseOptions): Caption[];
|
|
1912
|
+
declare function subtitleImportToOps(captions: Caption[], trackId: TrackId): OperationPrimitive[];
|
|
1913
|
+
|
|
1914
|
+
/**
|
|
1915
|
+
* TransitionTool — Phase 4 Step 4
|
|
1916
|
+
*
|
|
1917
|
+
* Drag from a clip's right edge to create or resize a transition.
|
|
1918
|
+
* Click on an existing transition area to delete it.
|
|
1919
|
+
*
|
|
1920
|
+
* RULES:
|
|
1921
|
+
* - onPointerMove never dispatches; returns ProvisionalState for preview
|
|
1922
|
+
* - onPointerUp never mutates instance state (capture-before-reset)
|
|
1923
|
+
* - Every instance variable reset in onCancel()
|
|
1924
|
+
*/
|
|
1925
|
+
|
|
1926
|
+
declare class TransitionTool implements ITool {
|
|
1927
|
+
readonly id: ToolId;
|
|
1928
|
+
readonly shortcutKey: string;
|
|
1929
|
+
private pendingClipId;
|
|
1930
|
+
private dragStartX;
|
|
1931
|
+
private pendingDeleteTransitionClipId;
|
|
1932
|
+
getCursor(_ctx: ToolContext): string;
|
|
1933
|
+
getSnapCandidateTypes(): readonly SnapPointType[];
|
|
1934
|
+
onPointerDown(event: TimelinePointerEvent, ctx: ToolContext): void;
|
|
1935
|
+
onPointerMove(event: TimelinePointerEvent, ctx: ToolContext): ProvisionalState | null;
|
|
1936
|
+
onPointerUp(event: TimelinePointerEvent, ctx: ToolContext): Transaction | null;
|
|
1937
|
+
onKeyDown(_event: TimelineKeyEvent, _ctx: ToolContext): Transaction | null;
|
|
1938
|
+
onKeyUp(_event: TimelineKeyEvent, _ctx: ToolContext): void;
|
|
1939
|
+
onCancel(): void;
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
/**
|
|
1943
|
+
* KeyframeTool (Pen tool) — Phase 4 Step 4
|
|
1944
|
+
*
|
|
1945
|
+
* Click on a clip's effect lane to add a keyframe.
|
|
1946
|
+
* Click an existing keyframe to delete (via Delete key). Drag keyframe to move.
|
|
1947
|
+
*
|
|
1948
|
+
* RULES:
|
|
1949
|
+
* - onPointerMove never dispatches; returns ProvisionalState for preview
|
|
1950
|
+
* - onPointerUp never mutates instance state (capture-before-reset)
|
|
1951
|
+
* - Every instance variable reset in onCancel()
|
|
1952
|
+
*/
|
|
1953
|
+
|
|
1954
|
+
declare class KeyframeTool implements ITool {
|
|
1955
|
+
readonly id: ToolId;
|
|
1956
|
+
readonly shortcutKey: string;
|
|
1957
|
+
private draggingKeyframe;
|
|
1958
|
+
private activeClipId;
|
|
1959
|
+
private activeEffectId;
|
|
1960
|
+
private pendingAddKeyframe;
|
|
1961
|
+
getCursor(_ctx: ToolContext): string;
|
|
1962
|
+
getSnapCandidateTypes(): readonly SnapPointType[];
|
|
1963
|
+
onPointerDown(event: TimelinePointerEvent, ctx: ToolContext): void;
|
|
1964
|
+
onPointerMove(event: TimelinePointerEvent, ctx: ToolContext): ProvisionalState | null;
|
|
1965
|
+
onPointerUp(event: TimelinePointerEvent, ctx: ToolContext): Transaction | null;
|
|
1966
|
+
onKeyDown(event: TimelineKeyEvent, ctx: ToolContext): Transaction | null;
|
|
1967
|
+
onKeyUp(_event: TimelineKeyEvent, _ctx: ToolContext): void;
|
|
1968
|
+
onCancel(): void;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
/**
|
|
1972
|
+
* SerializationError — Phase 5 Step 1
|
|
1973
|
+
*
|
|
1974
|
+
* Thrown when deserialization or migration fails.
|
|
1975
|
+
*/
|
|
1976
|
+
|
|
1977
|
+
declare class SerializationError extends Error {
|
|
1978
|
+
readonly violations?: InvariantViolation[] | undefined;
|
|
1979
|
+
constructor(message: string, violations?: InvariantViolation[] | undefined);
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
/**
|
|
1983
|
+
* Timeline serialization — Phase 5 Step 1
|
|
1984
|
+
*
|
|
1985
|
+
* Pure functions. No IO. No DOM. No external deps.
|
|
1986
|
+
* serializeTimeline / deserializeTimeline round-trip TimelineState.
|
|
1987
|
+
*/
|
|
1988
|
+
|
|
1989
|
+
/**
|
|
1990
|
+
* Serialize state to JSON string.
|
|
1991
|
+
* Converts assetRegistry Map to plain object for JSON compatibility.
|
|
1992
|
+
*/
|
|
1993
|
+
declare function serializeTimeline(state: TimelineState): string;
|
|
1994
|
+
/**
|
|
1995
|
+
* Parse JSON string, migrate to current schema, validate invariants.
|
|
1996
|
+
* Throws SerializationError on invalid JSON, missing schemaVersion,
|
|
1997
|
+
* unknown version, or invariant violations.
|
|
1998
|
+
*/
|
|
1999
|
+
declare function deserializeTimeline(raw: string): TimelineState;
|
|
2000
|
+
type AssetRemapCallback = (asset: FileAsset) => FileAsset;
|
|
2001
|
+
/**
|
|
2002
|
+
* Walk assetRegistry; for each FileAsset replace with remap(asset).
|
|
2003
|
+
* GeneratorAssets unchanged. Returns new state (immutable).
|
|
2004
|
+
*/
|
|
2005
|
+
declare function remapAssetPaths(state: TimelineState, remap: AssetRemapCallback): TimelineState;
|
|
2006
|
+
type OfflineAsset = {
|
|
2007
|
+
readonly assetId: AssetId;
|
|
2008
|
+
readonly path: string;
|
|
2009
|
+
readonly clipIds: readonly ClipId[];
|
|
2010
|
+
};
|
|
2011
|
+
/**
|
|
2012
|
+
* For each FileAsset where isOnline(asset) === false, collect clip IDs
|
|
2013
|
+
* that reference it. Host provides isOnline; core does not do filesystem checks.
|
|
2014
|
+
*/
|
|
2015
|
+
declare function findOfflineAssets(state: TimelineState, isOnline: (asset: FileAsset) => boolean): OfflineAsset[];
|
|
2016
|
+
|
|
2017
|
+
/**
|
|
2018
|
+
* OTIO export — Phase 5 Step 2
|
|
2019
|
+
*
|
|
2020
|
+
* Pure function. Produces OTIO JSON-serializable document from TimelineState.
|
|
2021
|
+
* No external OTIO library. Hand-rolled mapping.
|
|
2022
|
+
*/
|
|
2023
|
+
|
|
2024
|
+
type OTIORationalTime = {
|
|
2025
|
+
value: number;
|
|
2026
|
+
rate: number;
|
|
2027
|
+
};
|
|
2028
|
+
type OTIOTimeRange = {
|
|
2029
|
+
OTIO_SCHEMA: string;
|
|
2030
|
+
start_time: OTIORationalTime;
|
|
2031
|
+
duration: OTIORationalTime;
|
|
2032
|
+
};
|
|
2033
|
+
type OTIOExternalReference = {
|
|
2034
|
+
OTIO_SCHEMA: string;
|
|
2035
|
+
target_url: string;
|
|
2036
|
+
available_range: OTIOTimeRange;
|
|
2037
|
+
};
|
|
2038
|
+
type OTIOGeneratorReference = {
|
|
2039
|
+
OTIO_SCHEMA: string;
|
|
2040
|
+
generator_kind: string;
|
|
2041
|
+
};
|
|
2042
|
+
type OTIOMissingReference = {
|
|
2043
|
+
OTIO_SCHEMA: string;
|
|
2044
|
+
};
|
|
2045
|
+
type OTIOClip = {
|
|
2046
|
+
OTIO_SCHEMA: string;
|
|
2047
|
+
name: string;
|
|
2048
|
+
source_range: OTIOTimeRange;
|
|
2049
|
+
media_reference: OTIOExternalReference | OTIOGeneratorReference | OTIOMissingReference;
|
|
2050
|
+
effects?: OTIOEffect[];
|
|
2051
|
+
};
|
|
2052
|
+
type OTIOGap = {
|
|
2053
|
+
OTIO_SCHEMA: string;
|
|
2054
|
+
source_range: OTIOTimeRange;
|
|
2055
|
+
};
|
|
2056
|
+
type OTIOEffect = {
|
|
2057
|
+
OTIO_SCHEMA: string;
|
|
2058
|
+
name: string;
|
|
2059
|
+
effect_name: string;
|
|
2060
|
+
enabled: boolean;
|
|
2061
|
+
metadata: {
|
|
2062
|
+
params: readonly {
|
|
2063
|
+
key: string;
|
|
2064
|
+
value: number | string | boolean;
|
|
2065
|
+
}[];
|
|
2066
|
+
};
|
|
2067
|
+
};
|
|
2068
|
+
type OTIOTrack = {
|
|
2069
|
+
OTIO_SCHEMA: string;
|
|
2070
|
+
kind: string;
|
|
2071
|
+
children: (OTIOClip | OTIOGap)[];
|
|
2072
|
+
};
|
|
2073
|
+
type OTIOStack = {
|
|
2074
|
+
OTIO_SCHEMA: string;
|
|
2075
|
+
children: OTIOTrack[];
|
|
2076
|
+
};
|
|
2077
|
+
type OTIOMarker = {
|
|
2078
|
+
OTIO_SCHEMA: string;
|
|
2079
|
+
name: string;
|
|
2080
|
+
color: string;
|
|
2081
|
+
marked_range: OTIOTimeRange;
|
|
2082
|
+
};
|
|
2083
|
+
type OTIODocument = {
|
|
2084
|
+
OTIO_SCHEMA: string;
|
|
2085
|
+
name: string;
|
|
2086
|
+
global_start_time: OTIORationalTime;
|
|
2087
|
+
tracks: OTIOStack;
|
|
2088
|
+
markers: OTIOMarker[];
|
|
2089
|
+
};
|
|
2090
|
+
/**
|
|
2091
|
+
* Export TimelineState to an OTIO document (plain object).
|
|
2092
|
+
* Caller can JSON.stringify the result.
|
|
2093
|
+
*/
|
|
2094
|
+
declare function exportToOTIO(state: TimelineState): OTIODocument;
|
|
2095
|
+
|
|
2096
|
+
/**
|
|
2097
|
+
* OTIO import — Phase 5 Step 2
|
|
2098
|
+
*
|
|
2099
|
+
* Pure function. Builds TimelineState from OTIO document.
|
|
2100
|
+
* Throws SerializationError on invalid doc or invariant violations.
|
|
2101
|
+
*/
|
|
2102
|
+
|
|
2103
|
+
type OTIOImportOptions = {
|
|
2104
|
+
/** Override fps; default: from doc global_start_time.rate or first clip rate, fallback 30 */
|
|
2105
|
+
fps?: number;
|
|
2106
|
+
/** Override timeline name */
|
|
2107
|
+
name?: string;
|
|
2108
|
+
};
|
|
2109
|
+
declare function importFromOTIO(doc: unknown, options?: OTIOImportOptions): TimelineState;
|
|
2110
|
+
|
|
2111
|
+
/**
|
|
2112
|
+
* CMX3600 EDL export — Phase 5 Step 3
|
|
2113
|
+
*
|
|
2114
|
+
* Single video track only. Pure function, returns string.
|
|
2115
|
+
* No IO.
|
|
2116
|
+
*/
|
|
2117
|
+
|
|
2118
|
+
type EDLExportOptions = {
|
|
2119
|
+
/** Default: state.timeline.name */
|
|
2120
|
+
title?: string;
|
|
2121
|
+
/** Default: false (non-drop). True = 29.97 drop frame only. */
|
|
2122
|
+
dropFrame?: boolean;
|
|
2123
|
+
/** Which video track to export. Default: 0 (first video track). */
|
|
2124
|
+
trackIndex?: number;
|
|
2125
|
+
};
|
|
2126
|
+
/**
|
|
2127
|
+
* Convert frame count to timecode string.
|
|
2128
|
+
* dropFrame true: only 29.97fps uses real drop-frame; others fall back to non-drop.
|
|
2129
|
+
*/
|
|
2130
|
+
declare function frameToTimecode(frame: number, fps: number, dropFrame: boolean): string;
|
|
2131
|
+
/**
|
|
2132
|
+
* FileAsset: filename without extension, truncate 8 chars, uppercase.
|
|
2133
|
+
* GeneratorAsset or undefined: "AX".
|
|
2134
|
+
*/
|
|
2135
|
+
declare function reelName(asset: Asset | undefined): string;
|
|
2136
|
+
/**
|
|
2137
|
+
* Export a single video track to CMX3600 EDL string.
|
|
2138
|
+
* trackIndex selects which video track (default 0).
|
|
2139
|
+
*/
|
|
2140
|
+
declare function exportToEDL(state: TimelineState, options?: EDLExportOptions): string;
|
|
2141
|
+
|
|
2142
|
+
/**
|
|
2143
|
+
* AAF XML export — Phase 5 Step 4
|
|
2144
|
+
*
|
|
2145
|
+
* Simplified AAF XML representation for Avid interchange.
|
|
2146
|
+
* Pure function, returns string. No IO.
|
|
2147
|
+
*/
|
|
2148
|
+
|
|
2149
|
+
type AAFExportOptions = {
|
|
2150
|
+
/** Default: timeline name */
|
|
2151
|
+
projectName?: string;
|
|
2152
|
+
/** Default: derived from state (e.g. 30 → "30/1") */
|
|
2153
|
+
frameRate?: string;
|
|
2154
|
+
};
|
|
2155
|
+
declare function exportToAAF(state: TimelineState, options?: AAFExportOptions): string;
|
|
2156
|
+
|
|
2157
|
+
/**
|
|
2158
|
+
* FCP XML (FCPX) export — Phase 5 Step 4
|
|
2159
|
+
*
|
|
2160
|
+
* Final Cut Pro XML 1.10 interchange. Pure function, returns string. No IO.
|
|
2161
|
+
*/
|
|
2162
|
+
|
|
2163
|
+
type FCPXMLExportOptions = {
|
|
2164
|
+
libraryName?: string;
|
|
2165
|
+
eventName?: string;
|
|
2166
|
+
};
|
|
2167
|
+
/**
|
|
2168
|
+
* FCPXML rational time: "0s" or "{frames}/{fps}s".
|
|
2169
|
+
*/
|
|
2170
|
+
declare function toFCPTime(frames: number, fps: number): string;
|
|
2171
|
+
declare function exportToFCPXML(state: TimelineState, options?: FCPXMLExportOptions): string;
|
|
2172
|
+
|
|
2173
|
+
/**
|
|
2174
|
+
* PROJECT MODEL — Phase 5 Step 5
|
|
2175
|
+
*
|
|
2176
|
+
* A Project is a multi-timeline container with a shared bin hierarchy.
|
|
2177
|
+
* Pure types + factories only. No IO.
|
|
2178
|
+
*/
|
|
2179
|
+
|
|
2180
|
+
type ProjectId = string & {
|
|
2181
|
+
readonly __brand: 'ProjectId';
|
|
2182
|
+
};
|
|
2183
|
+
declare function toProjectId(s: string): ProjectId;
|
|
2184
|
+
type BinId = string & {
|
|
2185
|
+
readonly __brand: 'BinId';
|
|
2186
|
+
};
|
|
2187
|
+
declare function toBinId(s: string): BinId;
|
|
2188
|
+
type BinItem = {
|
|
2189
|
+
readonly kind: 'asset';
|
|
2190
|
+
readonly assetId: AssetId;
|
|
2191
|
+
} | {
|
|
2192
|
+
readonly kind: 'sequence';
|
|
2193
|
+
readonly timelineId: string;
|
|
2194
|
+
} | {
|
|
2195
|
+
readonly kind: 'bin';
|
|
2196
|
+
readonly binId: BinId;
|
|
2197
|
+
};
|
|
2198
|
+
type Bin = {
|
|
2199
|
+
readonly id: BinId;
|
|
2200
|
+
readonly label: string;
|
|
2201
|
+
readonly parentId: BinId | null;
|
|
2202
|
+
readonly items: readonly BinItem[];
|
|
2203
|
+
readonly color?: string;
|
|
2204
|
+
};
|
|
2205
|
+
declare function createBin(id: BinId, label: string, parentId?: BinId | null): Bin;
|
|
2206
|
+
type Project = {
|
|
2207
|
+
readonly id: ProjectId;
|
|
2208
|
+
readonly name: string;
|
|
2209
|
+
readonly timelines: readonly TimelineState[];
|
|
2210
|
+
readonly bins: readonly Bin[];
|
|
2211
|
+
readonly rootBinIds: readonly BinId[];
|
|
2212
|
+
readonly createdAt: number;
|
|
2213
|
+
readonly updatedAt: number;
|
|
2214
|
+
readonly schemaVersion: number;
|
|
2215
|
+
};
|
|
2216
|
+
declare function createProject(id: ProjectId, name: string, timelines?: readonly TimelineState[]): Project;
|
|
2217
|
+
|
|
2218
|
+
declare function addTimeline(project: Project, state: TimelineState): Project;
|
|
2219
|
+
declare function removeTimeline(project: Project, timelineId: string): Project;
|
|
2220
|
+
declare function addBin(project: Project, bin: Bin): Project;
|
|
2221
|
+
declare function removeBin(project: Project, binId: BinId): Project;
|
|
2222
|
+
declare function addItemToBin(project: Project, binId: BinId, item: BinItem): Project;
|
|
2223
|
+
declare function removeItemFromBin(project: Project, binId: BinId, item: BinItem): Project;
|
|
2224
|
+
declare function moveItemBetweenBins(project: Project, fromBinId: BinId, toBinId: BinId, item: BinItem): Project;
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* Project serialization — Phase 5 Step 5
|
|
2228
|
+
*
|
|
2229
|
+
* Pure functions. No IO. Uses timeline migrate() + checkInvariants().
|
|
2230
|
+
*/
|
|
2231
|
+
|
|
2232
|
+
declare function serializeProject(project: Project): string;
|
|
2233
|
+
declare function deserializeProject(raw: string): Project;
|
|
2234
|
+
|
|
2235
|
+
/**
|
|
2236
|
+
* Playhead types — Phase 6 Step 1 + Step 5
|
|
2237
|
+
*
|
|
2238
|
+
* Playback position and quality. No DOM deps.
|
|
2239
|
+
*/
|
|
2240
|
+
|
|
2241
|
+
type PlaybackRate = number;
|
|
2242
|
+
type PlaybackQuality = 'full' | 'half' | 'quarter' | 'proxy';
|
|
2243
|
+
type LoopRegion = {
|
|
2244
|
+
readonly startFrame: TimelineFrame;
|
|
2245
|
+
readonly endFrame: TimelineFrame;
|
|
2246
|
+
};
|
|
2247
|
+
type PlayheadState = {
|
|
2248
|
+
readonly currentFrame: TimelineFrame;
|
|
2249
|
+
readonly isPlaying: boolean;
|
|
2250
|
+
readonly playbackRate: PlaybackRate;
|
|
2251
|
+
readonly quality: PlaybackQuality;
|
|
2252
|
+
readonly durationFrames: number;
|
|
2253
|
+
readonly fps: number;
|
|
2254
|
+
readonly loopRegion: LoopRegion | null;
|
|
2255
|
+
readonly prerollFrames: number;
|
|
2256
|
+
readonly postrollFrames: number;
|
|
2257
|
+
};
|
|
2258
|
+
type PlayheadEventType = 'play' | 'pause' | 'seek' | 'loop' | 'frame-dropped' | 'ended' | 'loop-point' | 'state';
|
|
2259
|
+
type PlayheadEvent = {
|
|
2260
|
+
readonly type: PlayheadEventType;
|
|
2261
|
+
readonly frame: TimelineFrame;
|
|
2262
|
+
readonly data?: unknown;
|
|
2263
|
+
};
|
|
2264
|
+
type PlayheadListener = (event: PlayheadEvent) => void;
|
|
2265
|
+
/** Return type of PlayheadController.on() — call to unsubscribe. */
|
|
2266
|
+
type PlayheadUnsubscribe = () => void;
|
|
2267
|
+
|
|
2268
|
+
/**
|
|
2269
|
+
* Clock abstraction — Phase 6 Step 1
|
|
2270
|
+
*
|
|
2271
|
+
* Allows PlayheadController to run without real rAF (swapped for mock in tests).
|
|
2272
|
+
*/
|
|
2273
|
+
type ClockCallback = (timestamp: number) => void;
|
|
2274
|
+
type Clock = {
|
|
2275
|
+
requestFrame: (cb: ClockCallback) => number;
|
|
2276
|
+
cancelFrame: (id: number) => void;
|
|
2277
|
+
now: () => number;
|
|
2278
|
+
};
|
|
2279
|
+
declare const browserClock: Clock;
|
|
2280
|
+
declare const nodeClock: Clock;
|
|
2281
|
+
declare function createTestClock(): {
|
|
2282
|
+
clock: Clock;
|
|
2283
|
+
tick: (ms: number) => void;
|
|
2284
|
+
getCallbacks: () => ClockCallback[];
|
|
2285
|
+
};
|
|
2286
|
+
|
|
2287
|
+
/**
|
|
2288
|
+
* PlayheadController — Phase 6 Step 1
|
|
2289
|
+
*
|
|
2290
|
+
* Manages playback position only. Decoupled from Dispatcher and TimelineState.
|
|
2291
|
+
* Never calls dispatch(). Uses clock abstraction for testability.
|
|
2292
|
+
*/
|
|
2293
|
+
|
|
2294
|
+
declare class PlayheadController {
|
|
2295
|
+
private state;
|
|
2296
|
+
private listeners;
|
|
2297
|
+
private rafId;
|
|
2298
|
+
private lastTimestamp;
|
|
2299
|
+
private frameAccum;
|
|
2300
|
+
private clock;
|
|
2301
|
+
constructor(initialState: Pick<PlayheadState, 'durationFrames' | 'fps'>, clock?: Clock);
|
|
2302
|
+
getState(): PlayheadState;
|
|
2303
|
+
play(): void;
|
|
2304
|
+
pause(): void;
|
|
2305
|
+
seekTo(frame: TimelineFrame): void;
|
|
2306
|
+
setPlaybackRate(rate: PlaybackRate): void;
|
|
2307
|
+
setQuality(quality: PlaybackQuality): void;
|
|
2308
|
+
setDuration(durationFrames: number): void;
|
|
2309
|
+
setLoopRegion(region: LoopRegion | null): void;
|
|
2310
|
+
setPreroll(frames: number): void;
|
|
2311
|
+
setPostroll(frames: number): void;
|
|
2312
|
+
private scheduleFrame;
|
|
2313
|
+
private onFrame;
|
|
2314
|
+
on(listener: PlayheadListener): PlayheadUnsubscribe;
|
|
2315
|
+
private emit;
|
|
2316
|
+
destroy(): void;
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
/**
|
|
2320
|
+
* Pipeline contracts — Phase 6 Step 2
|
|
2321
|
+
*
|
|
2322
|
+
* Core defines the CONTRACT (types + interfaces).
|
|
2323
|
+
* Host app provides the IMPLEMENTATION.
|
|
2324
|
+
* Core never does actual decoding or compositing.
|
|
2325
|
+
*/
|
|
2326
|
+
|
|
2327
|
+
type VideoFrameRequest = {
|
|
2328
|
+
readonly clipId: ClipId;
|
|
2329
|
+
readonly mediaFrame: TimelineFrame;
|
|
2330
|
+
readonly quality: PlaybackQuality;
|
|
2331
|
+
};
|
|
2332
|
+
type AudioChunkRequest = {
|
|
2333
|
+
readonly clipId: ClipId;
|
|
2334
|
+
readonly mediaFrame: TimelineFrame;
|
|
2335
|
+
readonly durationFrames: number;
|
|
2336
|
+
readonly sampleRate: number;
|
|
2337
|
+
};
|
|
2338
|
+
type VideoFrameResult = {
|
|
2339
|
+
readonly clipId: ClipId;
|
|
2340
|
+
readonly mediaFrame: TimelineFrame;
|
|
2341
|
+
readonly width: number;
|
|
2342
|
+
readonly height: number;
|
|
2343
|
+
readonly bitmap: unknown;
|
|
2344
|
+
};
|
|
2345
|
+
type AudioChunkResult = {
|
|
2346
|
+
readonly clipId: ClipId;
|
|
2347
|
+
readonly mediaFrame: TimelineFrame;
|
|
2348
|
+
readonly samples: unknown;
|
|
2349
|
+
readonly sampleRate: number;
|
|
2350
|
+
};
|
|
2351
|
+
type VideoDecoder = (request: VideoFrameRequest) => Promise<VideoFrameResult>;
|
|
2352
|
+
type AudioDecoder = (request: AudioChunkRequest) => Promise<AudioChunkResult>;
|
|
2353
|
+
type CompositeLayer = {
|
|
2354
|
+
readonly clipId: ClipId;
|
|
2355
|
+
readonly trackId: TrackId;
|
|
2356
|
+
readonly trackIndex: number;
|
|
2357
|
+
readonly frame: VideoFrameResult;
|
|
2358
|
+
readonly transform: ClipTransform;
|
|
2359
|
+
readonly opacity: number;
|
|
2360
|
+
readonly blendMode: string;
|
|
2361
|
+
readonly effects: readonly Effect[];
|
|
2362
|
+
};
|
|
2363
|
+
/** Layer spec from resolveFrame (no decoded frame yet). */
|
|
2364
|
+
type ResolvedLayer = {
|
|
2365
|
+
readonly clipId: ClipId;
|
|
2366
|
+
readonly trackId: TrackId;
|
|
2367
|
+
readonly trackIndex: number;
|
|
2368
|
+
readonly mediaFrame: TimelineFrame;
|
|
2369
|
+
readonly transform: ClipTransform;
|
|
2370
|
+
readonly opacity: number;
|
|
2371
|
+
readonly blendMode: string;
|
|
2372
|
+
readonly effects: readonly Effect[];
|
|
2373
|
+
};
|
|
2374
|
+
type CompositeRequest = {
|
|
2375
|
+
readonly timelineFrame: TimelineFrame;
|
|
2376
|
+
readonly layers: readonly CompositeLayer[];
|
|
2377
|
+
readonly width: number;
|
|
2378
|
+
readonly height: number;
|
|
2379
|
+
readonly quality: PlaybackQuality;
|
|
2380
|
+
};
|
|
2381
|
+
type CompositeResult = {
|
|
2382
|
+
readonly timelineFrame: TimelineFrame;
|
|
2383
|
+
readonly bitmap: unknown;
|
|
2384
|
+
};
|
|
2385
|
+
/** Result of resolveFrame (layers have mediaFrame, not decoded frame). */
|
|
2386
|
+
type ResolvedCompositeRequest = {
|
|
2387
|
+
readonly timelineFrame: TimelineFrame;
|
|
2388
|
+
readonly layers: readonly ResolvedLayer[];
|
|
2389
|
+
readonly width: number;
|
|
2390
|
+
readonly height: number;
|
|
2391
|
+
readonly quality: PlaybackQuality;
|
|
2392
|
+
};
|
|
2393
|
+
type Compositor = (request: CompositeRequest) => Promise<CompositeResult>;
|
|
2394
|
+
type ThumbnailRequest = {
|
|
2395
|
+
readonly clipId: ClipId;
|
|
2396
|
+
readonly mediaFrame: TimelineFrame;
|
|
2397
|
+
readonly width: number;
|
|
2398
|
+
readonly height: number;
|
|
2399
|
+
};
|
|
2400
|
+
type ThumbnailResult = {
|
|
2401
|
+
readonly clipId: ClipId;
|
|
2402
|
+
readonly mediaFrame: TimelineFrame;
|
|
2403
|
+
readonly bitmap: unknown;
|
|
2404
|
+
};
|
|
2405
|
+
type ThumbnailProvider = (request: ThumbnailRequest) => Promise<ThumbnailResult>;
|
|
2406
|
+
type PipelineConfig = {
|
|
2407
|
+
readonly videoDecoder: VideoDecoder;
|
|
2408
|
+
readonly audioDecoder?: AudioDecoder;
|
|
2409
|
+
readonly compositor: Compositor;
|
|
2410
|
+
readonly thumbnailProvider?: ThumbnailProvider;
|
|
2411
|
+
};
|
|
2412
|
+
|
|
2413
|
+
/**
|
|
2414
|
+
* TrackIndex — Phase 7 Step 1
|
|
2415
|
+
*
|
|
2416
|
+
* Wraps IntervalTree per track for O(log n + k) getClipsAtFrame.
|
|
2417
|
+
*/
|
|
2418
|
+
|
|
2419
|
+
type ClipEntry = {
|
|
2420
|
+
clip: Clip;
|
|
2421
|
+
track: Track;
|
|
2422
|
+
trackIndex: number;
|
|
2423
|
+
};
|
|
2424
|
+
declare class TrackIndex {
|
|
2425
|
+
private tree;
|
|
2426
|
+
private built;
|
|
2427
|
+
build(state: TimelineState): void;
|
|
2428
|
+
query(frame: number): ClipEntry[];
|
|
2429
|
+
get isBuilt(): boolean;
|
|
2430
|
+
invalidate(): void;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
/**
|
|
2434
|
+
* Frame resolver — Phase 6 Step 2 + Step 3
|
|
2435
|
+
*
|
|
2436
|
+
* Given a TimelineFrame, resolves which clips are visible and builds
|
|
2437
|
+
* the composite request. Pure function — no async, no decoding.
|
|
2438
|
+
*/
|
|
2439
|
+
|
|
2440
|
+
/**
|
|
2441
|
+
* Returns the media-space frame for a clip at the given timeline frame.
|
|
2442
|
+
* mediaFrame = timelineFrame - clip.timelineStart + clip.mediaIn
|
|
2443
|
+
*/
|
|
2444
|
+
declare function mediaFrameForClip(clip: Clip, timelineFrame: TimelineFrame): TimelineFrame;
|
|
2445
|
+
/**
|
|
2446
|
+
* Returns all clips visible at the given timeline frame, with their
|
|
2447
|
+
* parent track and track index (z-order).
|
|
2448
|
+
* If index is provided and built, uses O(log n + k) lookup; else linear scan.
|
|
2449
|
+
*/
|
|
2450
|
+
declare function getClipsAtFrame(state: TimelineState, timelineFrame: TimelineFrame, index?: TrackIndex): Array<{
|
|
2451
|
+
clip: Clip;
|
|
2452
|
+
track: Track;
|
|
2453
|
+
trackIndex: number;
|
|
2454
|
+
}>;
|
|
2455
|
+
/**
|
|
2456
|
+
* Resolves the composite request for a timeline frame: which layers are
|
|
2457
|
+
* visible and their transform/opacity/blend/effects. Does not decode.
|
|
2458
|
+
* Pass optional index for O(log n + k) clip lookup.
|
|
2459
|
+
*/
|
|
2460
|
+
declare function resolveFrame(state: TimelineState, timelineFrame: TimelineFrame, quality: PlaybackQuality, dimensions: {
|
|
2461
|
+
width: number;
|
|
2462
|
+
height: number;
|
|
2463
|
+
}, index?: TrackIndex): ResolvedCompositeRequest;
|
|
2464
|
+
/**
|
|
2465
|
+
* Returns the nearest frame strictly after fromFrame where any clip
|
|
2466
|
+
* starts or ends on any track. Returns null if none.
|
|
2467
|
+
*/
|
|
2468
|
+
declare function findNextClipBoundary(state: TimelineState, fromFrame: TimelineFrame): TimelineFrame | null;
|
|
2469
|
+
/**
|
|
2470
|
+
* Returns the nearest frame strictly before fromFrame where any clip
|
|
2471
|
+
* starts or ends on any track. Returns null if none.
|
|
2472
|
+
*/
|
|
2473
|
+
declare function findPrevClipBoundary(state: TimelineState, fromFrame: TimelineFrame): TimelineFrame | null;
|
|
2474
|
+
/**
|
|
2475
|
+
* Returns the marker with the smallest anchor strictly after fromFrame.
|
|
2476
|
+
* Point markers use .frame; range markers use .frameStart as anchor.
|
|
2477
|
+
*/
|
|
2478
|
+
declare function findNextMarker(state: TimelineState, fromFrame: TimelineFrame): Marker | null;
|
|
2479
|
+
/**
|
|
2480
|
+
* Returns the marker with the largest anchor strictly before fromFrame.
|
|
2481
|
+
*/
|
|
2482
|
+
declare function findPrevMarker(state: TimelineState, fromFrame: TimelineFrame): Marker | null;
|
|
2483
|
+
/**
|
|
2484
|
+
* Searches all tracks for a clip with the given id.
|
|
2485
|
+
* Returns clip + parent track + trackIndex, or null if not found.
|
|
2486
|
+
*/
|
|
2487
|
+
declare function findClipById(state: TimelineState, clipId: ClipId): {
|
|
2488
|
+
clip: Clip;
|
|
2489
|
+
track: Track;
|
|
2490
|
+
trackIndex: number;
|
|
2491
|
+
} | null;
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* Centered interval tree — Phase 7 Step 1
|
|
2495
|
+
*
|
|
2496
|
+
* Stores intervals [start, end) and answers query(point):
|
|
2497
|
+
* all intervals containing point. O(log n + k).
|
|
2498
|
+
*/
|
|
2499
|
+
type Interval<T> = {
|
|
2500
|
+
readonly start: number;
|
|
2501
|
+
readonly end: number;
|
|
2502
|
+
readonly data: T;
|
|
2503
|
+
};
|
|
2504
|
+
declare class IntervalTree<T> {
|
|
2505
|
+
private root;
|
|
2506
|
+
private _size;
|
|
2507
|
+
build(intervals: Interval<T>[]): void;
|
|
2508
|
+
query(point: number): T[];
|
|
2509
|
+
size(): number;
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
declare class PlaybackEngine {
|
|
2513
|
+
private controller;
|
|
2514
|
+
private pipeline;
|
|
2515
|
+
private state;
|
|
2516
|
+
private dimensions;
|
|
2517
|
+
private trackIndex;
|
|
2518
|
+
private snapManager;
|
|
2519
|
+
private unsubscribe;
|
|
2520
|
+
constructor(state: TimelineState, pipeline: PipelineConfig, dimensions: {
|
|
2521
|
+
width: number;
|
|
2522
|
+
height: number;
|
|
2523
|
+
}, clock?: Clock);
|
|
2524
|
+
updateState(state: TimelineState): void;
|
|
2525
|
+
play(): void;
|
|
2526
|
+
pause(): void;
|
|
2527
|
+
seekTo(frame: TimelineFrame): void;
|
|
2528
|
+
seekToNextClipBoundary(): void;
|
|
2529
|
+
seekToPrevClipBoundary(): void;
|
|
2530
|
+
seekToNextMarker(): void;
|
|
2531
|
+
seekToPrevMarker(): void;
|
|
2532
|
+
seekToStart(): void;
|
|
2533
|
+
seekToEnd(): void;
|
|
2534
|
+
setPlaybackRate(rate: PlaybackRate): void;
|
|
2535
|
+
setQuality(quality: PlaybackQuality): void;
|
|
2536
|
+
setLoopRegion(region: LoopRegion | null): void;
|
|
2537
|
+
setPreroll(frames: number): void;
|
|
2538
|
+
setPostroll(frames: number): void;
|
|
2539
|
+
getState(): PlayheadState;
|
|
2540
|
+
getCurrentTimelineState(): TimelineState;
|
|
2541
|
+
on(listener: PlayheadListener): () => void;
|
|
2542
|
+
renderFrame(timelineFrame: TimelineFrame): Promise<CompositeResult>;
|
|
2543
|
+
destroy(): void;
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
/**
|
|
2547
|
+
* Virtual rendering contract — Phase 7 Step 2
|
|
2548
|
+
*
|
|
2549
|
+
* Defines what is "visible" so the React layer can mount
|
|
2550
|
+
* only visible clip components.
|
|
2551
|
+
*/
|
|
2552
|
+
|
|
2553
|
+
type VirtualWindow = {
|
|
2554
|
+
readonly startFrame: TimelineFrame;
|
|
2555
|
+
readonly endFrame: TimelineFrame;
|
|
2556
|
+
readonly pixelsPerFrame: number;
|
|
2557
|
+
};
|
|
2558
|
+
type VirtualClipEntry = {
|
|
2559
|
+
readonly clip: Clip;
|
|
2560
|
+
readonly track: Track;
|
|
2561
|
+
readonly trackIndex: number;
|
|
2562
|
+
readonly isVisible: boolean;
|
|
2563
|
+
readonly left: number;
|
|
2564
|
+
readonly width: number;
|
|
2565
|
+
};
|
|
2566
|
+
/**
|
|
2567
|
+
* Returns all clips with visibility and layout (left, width).
|
|
2568
|
+
* Sorted by trackIndex ascending, then by clip timelineStart ascending.
|
|
2569
|
+
*/
|
|
2570
|
+
declare function getVisibleClips(state: TimelineState, window: VirtualWindow): VirtualClipEntry[];
|
|
2571
|
+
/**
|
|
2572
|
+
* Builds a VirtualWindow from viewport dimensions and scroll.
|
|
2573
|
+
*/
|
|
2574
|
+
declare function getVisibleFrameRange(viewportWidth: number, scrollLeft: number, pixelsPerFrame: number): VirtualWindow;
|
|
2575
|
+
|
|
2576
|
+
/**
|
|
2577
|
+
* StateChange diff — Phase 7 Step 2
|
|
2578
|
+
*
|
|
2579
|
+
* Lightweight diff for hook optimization: compare prev vs next
|
|
2580
|
+
* by reference so hooks can skip re-render when nothing relevant changed.
|
|
2581
|
+
*/
|
|
2582
|
+
|
|
2583
|
+
type StateChange = {
|
|
2584
|
+
readonly trackIds: boolean;
|
|
2585
|
+
readonly clipIds: ReadonlySet<ClipId>;
|
|
2586
|
+
readonly markers: boolean;
|
|
2587
|
+
readonly timeline: boolean;
|
|
2588
|
+
readonly playhead: boolean;
|
|
2589
|
+
};
|
|
2590
|
+
declare const EMPTY_STATE_CHANGE: StateChange;
|
|
2591
|
+
/**
|
|
2592
|
+
* Diffs prev and next state by reference.
|
|
2593
|
+
* clipIds: set of clip ids whose clip reference changed or were added/removed.
|
|
2594
|
+
*/
|
|
2595
|
+
declare function diffStates(prev: TimelineState, next: TimelineState): StateChange;
|
|
2596
|
+
|
|
2597
|
+
/**
|
|
2598
|
+
* Worker contracts — Phase 7 Step 4
|
|
2599
|
+
*
|
|
2600
|
+
* Core defines message/response types only.
|
|
2601
|
+
* No Worker instantiation — host responsibility.
|
|
2602
|
+
*/
|
|
2603
|
+
|
|
2604
|
+
type WaveformRequest = {
|
|
2605
|
+
readonly requestId: string;
|
|
2606
|
+
readonly assetId: AssetId;
|
|
2607
|
+
readonly channel: number;
|
|
2608
|
+
readonly startFrame: TimelineFrame;
|
|
2609
|
+
readonly endFrame: TimelineFrame;
|
|
2610
|
+
readonly buckets: number;
|
|
2611
|
+
readonly sampleRate: number;
|
|
2612
|
+
};
|
|
2613
|
+
type WaveformPeak = {
|
|
2614
|
+
readonly min: number;
|
|
2615
|
+
readonly max: number;
|
|
2616
|
+
readonly rms: number;
|
|
2617
|
+
};
|
|
2618
|
+
type WaveformResult = {
|
|
2619
|
+
readonly requestId: string;
|
|
2620
|
+
readonly assetId: AssetId;
|
|
2621
|
+
readonly peaks: readonly WaveformPeak[];
|
|
2622
|
+
readonly error?: string;
|
|
2623
|
+
};
|
|
2624
|
+
type WaveformWorkerMessage = {
|
|
2625
|
+
type: 'request';
|
|
2626
|
+
payload: WaveformRequest;
|
|
2627
|
+
} | {
|
|
2628
|
+
type: 'cancel';
|
|
2629
|
+
requestId: string;
|
|
2630
|
+
};
|
|
2631
|
+
type WaveformWorkerResponse = {
|
|
2632
|
+
type: 'result';
|
|
2633
|
+
payload: WaveformResult;
|
|
2634
|
+
} | {
|
|
2635
|
+
type: 'progress';
|
|
2636
|
+
requestId: string;
|
|
2637
|
+
progress: number;
|
|
2638
|
+
} | {
|
|
2639
|
+
type: 'error';
|
|
2640
|
+
requestId: string;
|
|
2641
|
+
message: string;
|
|
2642
|
+
};
|
|
2643
|
+
type ThumbnailPriority = 'high' | 'normal' | 'low';
|
|
2644
|
+
type ThumbnailQueueEntry = {
|
|
2645
|
+
readonly request: ThumbnailRequest;
|
|
2646
|
+
readonly priority: ThumbnailPriority;
|
|
2647
|
+
readonly addedAt: number;
|
|
2648
|
+
};
|
|
2649
|
+
type ThumbnailWorkerMessage = {
|
|
2650
|
+
type: 'request';
|
|
2651
|
+
payload: ThumbnailQueueEntry;
|
|
2652
|
+
} | {
|
|
2653
|
+
type: 'cancel';
|
|
2654
|
+
requestId: string;
|
|
2655
|
+
} | {
|
|
2656
|
+
type: 'set-priority';
|
|
2657
|
+
requestId: string;
|
|
2658
|
+
priority: ThumbnailPriority;
|
|
2659
|
+
};
|
|
2660
|
+
type ThumbnailWorkerResponse = {
|
|
2661
|
+
type: 'result';
|
|
2662
|
+
payload: ThumbnailResult;
|
|
2663
|
+
} | {
|
|
2664
|
+
type: 'error';
|
|
2665
|
+
requestId: string;
|
|
2666
|
+
message: string;
|
|
2667
|
+
};
|
|
2668
|
+
|
|
2669
|
+
/**
|
|
2670
|
+
* ThumbnailCache — Phase 7 Step 4
|
|
2671
|
+
*
|
|
2672
|
+
* In-memory LRU cache for thumbnail results.
|
|
2673
|
+
* No Worker — sits between pipeline and host's thumbnail provider.
|
|
2674
|
+
*/
|
|
2675
|
+
|
|
2676
|
+
declare class ThumbnailCache {
|
|
2677
|
+
private cache;
|
|
2678
|
+
private order;
|
|
2679
|
+
private maxSize;
|
|
2680
|
+
constructor(maxSize?: number);
|
|
2681
|
+
private key;
|
|
2682
|
+
get(request: ThumbnailRequest): ThumbnailResult | null;
|
|
2683
|
+
set(request: ThumbnailRequest, result: ThumbnailResult): void;
|
|
2684
|
+
has(request: ThumbnailRequest): boolean;
|
|
2685
|
+
invalidateClip(clipId: ClipId): void;
|
|
2686
|
+
clear(): void;
|
|
2687
|
+
get size(): number;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
/**
|
|
2691
|
+
* ThumbnailQueue — Phase 7 Step 4
|
|
2692
|
+
*
|
|
2693
|
+
* Priority queue for thumbnail requests.
|
|
2694
|
+
* Visible clips get 'high', off-screen get 'low'.
|
|
2695
|
+
*/
|
|
2696
|
+
|
|
2697
|
+
declare class ThumbnailQueue {
|
|
2698
|
+
private entries;
|
|
2699
|
+
enqueue(request: ThumbnailRequest, priority?: ThumbnailPriority): void;
|
|
2700
|
+
dequeue(): ThumbnailQueueEntry | null;
|
|
2701
|
+
cancel(clipId: ClipId): void;
|
|
2702
|
+
setPriority(clipId: ClipId, mediaFrame: TimelineFrame, priority: ThumbnailPriority): void;
|
|
2703
|
+
get length(): number;
|
|
2704
|
+
peek(): ThumbnailQueueEntry | null;
|
|
2705
|
+
clear(): void;
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
/**
|
|
2709
|
+
* Keyboard contract — Phase 6 Step 4 + Step 5
|
|
2710
|
+
*
|
|
2711
|
+
* Key bindings and actions for J/K/L jog-shuttle and timeline navigation.
|
|
2712
|
+
*/
|
|
2713
|
+
|
|
2714
|
+
type TimelineKeyAction = 'play-pause' | 'stop' | 'jog-forward' | 'jog-backward' | 'jog-stop' | 'step-forward' | 'step-backward' | 'seek-start' | 'seek-end' | 'next-clip' | 'prev-clip' | 'next-marker' | 'prev-marker' | 'mark-in' | 'mark-out' | 'toggle-loop';
|
|
2715
|
+
type KeyBinding = {
|
|
2716
|
+
readonly code: string;
|
|
2717
|
+
readonly shift?: boolean;
|
|
2718
|
+
readonly alt?: boolean;
|
|
2719
|
+
readonly meta?: boolean;
|
|
2720
|
+
readonly ctrl?: boolean;
|
|
2721
|
+
readonly action: TimelineKeyAction;
|
|
2722
|
+
readonly repeat?: boolean;
|
|
2723
|
+
};
|
|
2724
|
+
declare const DEFAULT_KEY_BINDINGS: KeyBinding[];
|
|
2725
|
+
type KeyboardHandlerOptions = {
|
|
2726
|
+
bindings?: KeyBinding[];
|
|
2727
|
+
onMarkIn?: (frame: TimelineFrame) => void;
|
|
2728
|
+
onMarkOut?: (frame: TimelineFrame) => void;
|
|
2729
|
+
getTimelineState?: () => TimelineState;
|
|
2730
|
+
};
|
|
2731
|
+
|
|
2732
|
+
/**
|
|
2733
|
+
* KeyboardHandler — Phase 6 Step 4
|
|
2734
|
+
*
|
|
2735
|
+
* J/K/L jog-shuttle and keyboard contract. Zero DOM deps;
|
|
2736
|
+
* accepts TimelineKeyEvent (host maps from KeyboardEvent).
|
|
2737
|
+
*/
|
|
2738
|
+
|
|
2739
|
+
declare class KeyboardHandler {
|
|
2740
|
+
private bindings;
|
|
2741
|
+
private engine;
|
|
2742
|
+
private jogLevel;
|
|
2743
|
+
private onMarkIn;
|
|
2744
|
+
private onMarkOut;
|
|
2745
|
+
private getTimelineState;
|
|
2746
|
+
constructor(engine: PlaybackEngine, options?: KeyboardHandlerOptions);
|
|
2747
|
+
handleKeyDown(event: TimelineKeyEvent): boolean;
|
|
2748
|
+
private dispatchAction;
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
export { type KeyBinding as $, type Asset as A, type Bin as B, type Clip as C, DEFAULT_AUDIO_PROPERTIES as D, DEFAULT_CLIP_TRANSFORM as E, DEFAULT_COMPRESSION_POLICY as F, DEFAULT_KEY_BINDINGS as G, type DispatchResult as H, type EDLExportOptions as I, EMPTY_STATE_CHANGE as J, type EasingCurve as K, type Effect as L, type EffectId as M, type EffectParam as N, type EffectType as O, type FCPXMLExportOptions as P, type FrameRate as Q, FrameRates as R, HOLD_EASING as S, type TimelineState as T, type HistoryEntry as U, HistoryStack as V, type HistoryState as W, type ITool as X, type Interval as Y, IntervalTree as Z, type InvariantViolation as _, type Track as a, type TrackId as a$, KeyboardHandler as a0, type KeyboardHandlerOptions as a1, type Keyframe as a2, type KeyframeId as a3, KeyframeTool as a4, LINEAR_EASING as a5, type LinkGroup as a6, type LinkGroupId as a7, type LoopRegion as a8, type Modifiers as a9, SerializationError as aA, type SnapIndex as aB, SnapIndexManager as aC, type SnapPoint as aD, type SnapPointType as aE, type StateChange as aF, ThumbnailCache as aG, type ThumbnailPriority as aH, type ThumbnailProvider as aI, ThumbnailQueue as aJ, type ThumbnailQueueEntry as aK, type ThumbnailRequest as aL, type ThumbnailResult as aM, type ThumbnailWorkerMessage as aN, type ThumbnailWorkerResponse as aO, type TimeRange as aP, type Timecode as aQ, type Timeline as aR, TimelineEngine as aS, type TimelineKeyAction as aT, type TimelineKeyEvent as aU, type TimelinePointerEvent as aV, type ToolContext as aW, type ToolId as aX, type ToolRegistry as aY, type TrackGroup as aZ, type TrackGroupId as a_, NO_COMPRESSION as aa, NoOpTool as ab, type OTIODocument as ac, type OTIOImportOptions as ad, type OfflineAsset as ae, type OperationPrimitive as af, type PipelineConfig as ag, PlaybackEngine as ah, type PlaybackQuality as ai, type PlaybackRate as aj, PlayheadController as ak, type PlayheadEvent as al, type PlayheadEventType as am, type PlayheadListener as an, type PlayheadState as ao, type PlayheadUnsubscribe as ap, type Project as aq, type ProjectId as ar, type ProvisionalManager as as, type ProvisionalState as at, type RationalTime as au, type RejectionReason as av, type RenderStage as aw, type RubberBandRegion as ax, type SRTParseOptions as ay, type SequenceSettings as az, type TimelineFrame as b, findNextClipBoundary as b$, TrackIndex as b0, type TrackType as b1, type Transaction as b2, TransactionCompressor as b3, type Transition as b4, type TransitionAlignment as b5, type TransitionId as b6, type TransitionParam as b7, TransitionTool as b8, type TransitionType as b9, createAnimatableProperty as bA, createAsset as bB, createBin as bC, createClip as bD, createEffect as bE, createHistory as bF, createLinkGroup as bG, createProject as bH, createProvisionalManager as bI, createRegistry as bJ, createTestClock as bK, createTimeline as bL, createTimelineState as bM, createTrack as bN, createTrackGroup as bO, createTransition as bP, defaultCaptionStyle as bQ, deserializeProject as bR, deserializeTimeline as bS, diffStates as bT, dispatch as bU, exportToAAF as bV, exportToEDL as bW, exportToFCPXML as bX, exportToOTIO as bY, findMarkersByColor as bZ, findMarkersByLabel as b_, type VTTParseOptions as ba, type VideoDecoder as bb, type VideoFrameRequest as bc, type VideoFrameResult as bd, type ViolationType as be, type VirtualClipEntry as bf, type VirtualWindow as bg, type WaveformPeak as bh, type WaveformRequest as bi, type WaveformResult as bj, type WaveformWorkerMessage as bk, type WaveformWorkerResponse as bl, activateTool as bm, addBin as bn, addFrames as bo, addItemToBin as bp, addTimeline as bq, browserClock as br, buildSnapIndex as bs, canRedo as bt, canUndo as bu, checkInvariants as bv, clampFrame as bw, clearProvisional as bx, clipContainsFrame as by, clipsOverlap as bz, type AAFExportOptions as c, findNextMarker as c0, findOfflineAssets as c1, findPrevClipBoundary as c2, findPrevMarker as c3, frame as c4, frameDuration as c5, frameRate as c6, frameToTimecode as c7, framesToMinutesSeconds as c8, framesToSeconds as c9, secondsToFrames as cA, serializeProject as cB, serializeTimeline as cC, setProvisional as cD, sortTrackClips as cE, subtitleImportToOps as cF, subtractFrames as cG, toAssetId as cH, toBinId as cI, toClipId as cJ, toEffectId as cK, toFCPTime as cL, toFrame as cM, toKeyframeId as cN, toLinkGroupId as cO, toProjectId as cP, toTimecode as cQ, toToolId as cR, toTrackGroupId as cS, toTrackId as cT, toTransitionId as cU, toggleSnap as cV, undo as cW, findClipById as cX, getClipsAtFrame as cY, framesToTimecode as ca, getActiveTool as cb, getClipDuration as cc, getClipMediaDuration as cd, getCurrentState as ce, getVisibleClips as cf, getVisibleFrameRange as cg, importFromOTIO as ch, isDropFrame as ci, isValidFrame as cj, mediaFrameForClip as ck, moveItemBetweenBins as cl, nearest as cm, nodeClock as cn, parseSRT as co, parseVTT as cp, pushHistory as cq, redo as cr, reelName as cs, registerTool as ct, remapAssetPaths as cu, removeBin as cv, removeItemFromBin as cw, removeTimeline as cx, resolveClip as cy, resolveFrame as cz, type AnimatableProperty as d, type AssetId as e, type AssetRegistry as f, type AssetRemapCallback as g, type AssetStatus as h, type AudioChunkRequest as i, type AudioChunkResult as j, type AudioDecoder as k, type AudioProperties as l, type BinId as m, type BinItem as n, CURRENT_SCHEMA_VERSION as o, type ChannelRouting as p, type ClipEntry as q, type ClipId as r, type ClipTransform as s, type Clock as t, type CompositeLayer as u, type CompositeRequest as v, type CompositeResult as w, type Compositor as x, type CompressibleOpType as y, type CompressionPolicy as z };
|