Class: TimelineEditor
TimelineEditor
This class provides an interface to execute all timeline operations using a direct, class-based approach with track-based management. It also handles undo/redo operations internally.
Table of contents
Constructors
Methods
- registerElementType
- unregisterElementType
- on
- off
- getContext
- pauseVideo
- getTimelineData
- getLatestVersion
- addTrack
- getTrackById
- getTrackByName
- getCaptionsTrack
- removeTrackById
- removeTrack
- refresh
- addElementToTrack
- removeElement
- updateElement
- splitElement
- cloneElement
- reorderTracks
- moveElementToNewTrackAt
- updateHistory
- undo
- redo
- resetHistory
- loadProject
- getWatermark
- setWatermark
- removeWatermark
- getVideoAudio
- addTransition
- removeTransition
- getProject
- getBackgroundColor
- setBackgroundColor
- getMetadata
- setMetadata
- rippleDelete
- trimElement
- updateElements
- removeElements
- replaceElementsBySource
- centerElementInScene
- scaleElementToFit
- duplicateElements
Constructors
constructor
• new TimelineEditor(context): TimelineEditor
Parameters
| Name | Type |
|---|---|
context | TimelineOperationContext |
Returns
Defined in
core/editor/timeline.editor.ts:71
Methods
registerElementType
▸ registerElementType(type, deserializer): void
Parameters
| Name | Type |
|---|---|
type | string |
deserializer | (json: ElementJSON) => null | TrackElement |
Returns
void
Defined in
core/editor/timeline.editor.ts:77
unregisterElementType
▸ unregisterElementType(type): void
Parameters
| Name | Type |
|---|---|
type | string |
Returns
void
Defined in
core/editor/timeline.editor.ts:84
on
▸ on(event, handler): void
Subscribe to timeline mutation events.
Parameters
| Name | Type |
|---|---|
event | TimelineEditorEvent |
handler | (payload: unknown) => void |
Returns
void
Defined in
core/editor/timeline.editor.ts:91
off
▸ off(event, handler): void
Unsubscribe from timeline mutation events.
Parameters
| Name | Type |
|---|---|
event | TimelineEditorEvent |
handler | (payload: unknown) => void |
Returns
void
Defined in
core/editor/timeline.editor.ts:103
getContext
▸ getContext(): TimelineOperationContext
Returns
TimelineOperationContext
Defined in
core/editor/timeline.editor.ts:111
pauseVideo
▸ pauseVideo(): void
Returns
void
Defined in
core/editor/timeline.editor.ts:115
getTimelineData
▸ getTimelineData(): null | TimelineTrackData
Returns
null | TimelineTrackData
Defined in
core/editor/timeline.editor.ts:124
getLatestVersion
▸ getLatestVersion(): number
Returns
number
Defined in
core/editor/timeline.editor.ts:129
addTrack
▸ addTrack(name, type?): Track
Parameters
| Name | Type | Default value |
|---|---|---|
name | string | undefined |
type | string | TRACK_TYPES.ELEMENT |
Returns
Defined in
core/editor/timeline.editor.ts:183
getTrackById
▸ getTrackById(id): null | Track
Parameters
| Name | Type |
|---|---|
id | string |
Returns
null | Track
Defined in
core/editor/timeline.editor.ts:193
getTrackByName
▸ getTrackByName(name): null | Track
Parameters
| Name | Type |
|---|---|
name | string |
Returns
null | Track
Defined in
core/editor/timeline.editor.ts:199
getCaptionsTrack
▸ getCaptionsTrack(): null | Track
Returns
null | Track
Defined in
core/editor/timeline.editor.ts:205
removeTrackById
▸ removeTrackById(id): void
Parameters
| Name | Type |
|---|---|
id | string |
Returns
void
Defined in
core/editor/timeline.editor.ts:211
removeTrack
▸ removeTrack(track): void
Parameters
| Name | Type |
|---|---|
track | Track |
Returns
void
Defined in
core/editor/timeline.editor.ts:218
refresh
▸ refresh(): void
Refresh the timeline data
Returns
void
Defined in
core/editor/timeline.editor.ts:228
addElementToTrack
▸ addElementToTrack(track, element): Promise<boolean>
Add an element to a specific track using the visitor pattern.
Parameters
| Name | Type | Description |
|---|---|---|
track | Track | The track to add the element to. |
element | TrackElement | The element to add. |
Returns
Promise<boolean>
A promise that resolves to true if the element was added successfully, otherwise false.
Defined in
core/editor/timeline.editor.ts:241
removeElement
▸ removeElement(element): boolean
Remove an element from a specific track using the visitor pattern.
Parameters
| Name | Type | Description |
|---|---|---|
element | TrackElement | The element to remove. |
Returns
boolean
true if the element was removed successfully, otherwise false.
Defined in
core/editor/timeline.editor.ts:278
updateElement
▸ updateElement(element): TrackElement
Update an element in a specific track using the visitor pattern.
Parameters
| Name | Type | Description |
|---|---|---|
element | TrackElement | The updated element. |
Returns
The updated TrackElement.
Defined in
core/editor/timeline.editor.ts:309
splitElement
▸ splitElement(element, splitTime): Promise<SplitResult>
Split an element at a specific time point using the visitor pattern
Parameters
| Name | Type | Description |
|---|---|---|
element | TrackElement | The element to split |
splitTime | number | The time point to split at |
Returns
Promise<SplitResult>
SplitResult with first element, second element, and success status
Defined in
core/editor/timeline.editor.ts:341
cloneElement
▸ cloneElement(element): null | TrackElement
Clone an element using the visitor pattern
Parameters
| Name | Type | Description |
|---|---|---|
element | TrackElement | The element to clone |
Returns
null | TrackElement
TrackElement | null - the cloned element or null if cloning failed
Defined in
core/editor/timeline.editor.ts:382
reorderTracks
▸ reorderTracks(tracks): void
Parameters
| Name | Type |
|---|---|
tracks | Track[] |
Returns
void
Defined in
core/editor/timeline.editor.ts:391
moveElementToNewTrackAt
▸ moveElementToNewTrackAt(element, targetTrackIndex, startSec): Promise<boolean>
Move an element to a new track inserted at the given index (OpenVideo-style separator drop). Removes the element from its current track, creates a new track at targetTrackIndex, sets element start/end, and adds the element to the new track.
Parameters
| Name | Type |
|---|---|
element | TrackElement |
targetTrackIndex | number |
startSec | number |
Returns
Promise<boolean>
Defined in
core/editor/timeline.editor.ts:401
updateHistory
▸ updateHistory(timelineTrackData): void
Parameters
| Name | Type |
|---|---|
timelineTrackData | TimelineTrackData |
Returns
void
Defined in
core/editor/timeline.editor.ts:442
undo
▸ undo(): void
Trigger undo operation and update timeline data
Returns
void
Defined in
core/editor/timeline.editor.ts:462
redo
▸ redo(): void
Trigger redo operation and update timeline data
Returns
void
Defined in
core/editor/timeline.editor.ts:502
resetHistory
▸ resetHistory(): void
Reset history and clear timeline data
Returns
void
Defined in
core/editor/timeline.editor.ts:542
loadProject
▸ loadProject(«destructured»): void
Parameters
| Name | Type |
|---|---|
«destructured» | Object |
› tracks | TrackJSON[] |
› version | number |
› backgroundColor? | string |
› metadata? | ProjectMetadata |
Returns
void
Defined in
core/editor/timeline.editor.ts:566
getWatermark
▸ getWatermark(): null | Watermark
Returns
null | Watermark
Defined in
core/editor/timeline.editor.ts:612
setWatermark
▸ setWatermark(watermark): void
Parameters
| Name | Type |
|---|---|
watermark | Watermark |
Returns
void
Defined in
core/editor/timeline.editor.ts:617
removeWatermark
▸ removeWatermark(): void
Returns
void
Defined in
core/editor/timeline.editor.ts:628
getVideoAudio
▸ getVideoAudio(): Promise<string>
Returns
Promise<string>
Defined in
core/editor/timeline.editor.ts:638
addTransition
▸ addTransition(fromElementId, toElementId, kind, duration): boolean
Add transition metadata from one element to the next (e.g. crossfade). Sets optional transition on the "from" element; visualizer can interpret it when implemented.
Parameters
| Name | Type |
|---|---|
fromElementId | string |
toElementId | string |
kind | string |
duration | number |
Returns
boolean
Defined in
core/editor/timeline.editor.ts:648
removeTransition
▸ removeTransition(elementId): boolean
Remove transition metadata from an element.
Parameters
| Name | Type |
|---|---|
elementId | string |
Returns
boolean
Defined in
core/editor/timeline.editor.ts:669
getProject
▸ getProject(): ProjectJSON
Get the current project as ProjectJSON (same shape consumed by visualizer).
Returns
Defined in
core/editor/timeline.editor.ts:689
getBackgroundColor
▸ getBackgroundColor(): undefined | string
Returns
undefined | string
Defined in
core/editor/timeline.editor.ts:710
setBackgroundColor
▸ setBackgroundColor(backgroundColor): void
Parameters
| Name | Type |
|---|---|
backgroundColor | string |
Returns
void
Defined in
core/editor/timeline.editor.ts:714
getMetadata
▸ getMetadata(): undefined | ProjectMetadata
Returns
undefined | ProjectMetadata
Defined in
core/editor/timeline.editor.ts:726
setMetadata
▸ setMetadata(metadata): void
Parameters
| Name | Type |
|---|---|
metadata | ProjectMetadata |
Returns
void
Defined in
core/editor/timeline.editor.ts:730
rippleDelete
▸ rippleDelete(fromTime, toTime): Promise<void>
Ripple delete: remove content in [fromTime, toTime] and shift later content left. Single undo step.
Parameters
| Name | Type |
|---|---|
fromTime | number |
toTime | number |
Returns
Promise<void>
Defined in
core/editor/timeline.editor.ts:746
trimElement
▸ trimElement(element, newStart, newEnd): boolean
Trim an element to new start and end times. Validates bounds and updates via updateElement.
Parameters
| Name | Type |
|---|---|
element | TrackElement |
newStart | number |
newEnd | number |
Returns
boolean
Defined in
core/editor/timeline.editor.ts:802
updateElements
▸ updateElements(updates): void
Apply multiple element updates in one batch; single setTimelineData and undo step.
Parameters
| Name | Type |
|---|---|
updates | { elementId: string ; updates: Partial<ElementJSON> }[] |
Returns
void
Defined in
core/editor/timeline.editor.ts:820
removeElements
▸ removeElements(elementIds): void
Remove multiple elements by id in one batch; single setTimelineData and undo step.
Parameters
| Name | Type |
|---|---|
elementIds | string[] |
Returns
void
Defined in
core/editor/timeline.editor.ts:863
replaceElementsBySource
▸ replaceElementsBySource(src, newElementJson): number
Replace all elements with the given src (e.g. placeholder or same URL) with a new element definition. Preserves id, s, e, and track for each replaced element. Single setTimelineData at end.
Parameters
| Name | Type |
|---|---|
src | string |
newElementJson | ElementJSON |
Returns
number
Defined in
core/editor/timeline.editor.ts:890
centerElementInScene
▸ centerElementInScene(elementId, sceneWidth, sceneHeight): boolean
Center an element in the scene by setting its position to the center of scene dimensions.
Parameters
| Name | Type |
|---|---|
elementId | string |
sceneWidth | number |
sceneHeight | number |
Returns
boolean
Defined in
core/editor/timeline.editor.ts:929
scaleElementToFit
▸ scaleElementToFit(elementId, sceneWidth, sceneHeight): boolean
Scale an element to fit within scene dimensions while preserving aspect ratio. Updates width/height in props or frame when present.
Parameters
| Name | Type |
|---|---|
elementId | string |
sceneWidth | number |
sceneHeight | number |
Returns
boolean
Defined in
core/editor/timeline.editor.ts:950
duplicateElements
▸ duplicateElements(elementIds): Promise<TrackElement[]>
Duplicate multiple elements by id; adds clones to the same track. Single setTimelineData at end.
Parameters
| Name | Type |
|---|---|
elementIds | string[] |
Returns
Promise<TrackElement[]>