Class

TimelineEngine

The central orchestrator and coordinator for the high-performance timeline editor. Maintains state (tracks, clips, markers, playhead position, zoom scale, scrolls, snaps), builds dynamic snap indexes for magnetic snap guidance, handles split and edit actions, and publishes state events to trigger low-latency canvas renderings and lightweight React layouts.

Signature

Type Definition
Class TimelineEngine

Properties

NameSignatureDescription
canPasteSelectioncanPasteSelection: booleanWhether copied clips are available to paste.
canRedocanRedo: booleanWhether a redo snapshot is available.
canUndocanUndo: booleanWhether an undo snapshot is available.
clipboardCountclipboardCount: numberNumber of clips currently stored in the engine clipboard.
contentRevisioncontentRevision: numberMonotonic revision for changes that can affect active layer lookup.
isSnappingEnabledisSnappingEnabled: booleanWhether magnetic snapping is enabled.
markersmarkers: Marker[]Current marker list.
maxContentTimemaxContentTime: RationalTimeMaximum timeline time used for playback and scroll clamping.
maxScrollLeftmaxScrollLeft: numberMaximum horizontal scroll offset for the current viewport and content duration.
maxScrollTopmaxScrollTop: numberMaximum vertical scroll offset for the current viewport and track stack.
maxZoomScalemaxZoomScale: numberCurrent maximum zoom scale in pixels per second. When a frame-rate cap is lower than the content-fit floor, the content-fit floor wins so zoom never violates viewport bounds.
minZoomScaleminZoomScale: numberCurrent minimum zoom scale in pixels per second. This preserves the content-fit floor so users cannot zoom out past the current duration/content bounds.
playheadTimeplayheadTime: RationalTimeCurrent playhead position.
scrollLeftscrollLeft: numberCurrent horizontal scroll offset in pixels.
scrollTopscrollTop: numberCurrent vertical scroll offset in pixels.
snapThresholdPixelssnapThresholdPixels: numberMagnetic snap radius in screen pixels.
trackstracks: Track<string>[]Current mutable track list owned by the engine.
zoomScalezoomScale: numberCurrent horizontal zoom scale in pixels per second.

Constructors

NameSignatureDescription
constructorconstructor(initialState: object): TimelineEngineCreates an instance of the TimelineEngine.

Methods

NameSignatureDescription
addMarkeraddMarker(time: RationalTime, label?: string, color?: string, description?: string): objectAdds a marker at a timeline time.
addTrackaddTrack(track: Track): voidAppends a track to the timeline.
applyOverwritesapplyOverwrites(winningClipId: string): voidApplies overwrite-edit rules for a clip against overlapping clips on its track. Fully covered clips are removed, partially covered clips are trimmed, and clips split by the winner are divided into two segments.
cancelEditcancelEdit(): voidClears the active command-layer edit preview and snap guides.
clearClipDropFeedbackclearClipDropFeedback(): voidClears transient drop feedback for the active clip body drag interaction.
clearInOutPointsclearInOutPoints(): voidClears both in-point and out-point boundaries.
clearKeyframeSelectionclearKeyframeSelection(): voidClears keyframe selection.
commitEditcommitEdit(command: TimelineEditCommand): TimelineEditCommitResultResolves, validates, and commits an edit command as one history entry.
copySelectioncopySelection(): voidCopies selected clips into the engine clipboard.
cutSelectioncutSelection(): voidCopies selected clips into the clipboard, then removes them from their tracks.
deleteClipdeleteClip(clipId: string): booleanRemoves a clip from its containing track.
emitemit(event: K, args: undefined): voidEmits a typed event to all active subscribers. Supports type-safety by enforcing key-value mapping and allows omitting the payload argument entirely if the map type is void.
endDragendDrag(): voidEnds live drag preview and clears temporary cut flags.
getActiveClipgetActiveClip(query: ActiveClipQuery = {}): ActiveClip<string> | undefinedReturns the first active clip matching an active layer query.
getActiveClipsgetActiveClips(time: RationalTime = ...): ActiveClip<string>[]Returns enabled clips under a timeline time, ordered by track and clip order. Hidden or muted tracks and disabled clips are excluded so preview and playback integrations can pick sources using the same visibility rules. Clip intervals are half-open: active at `timelineStart` and inactive at `timelineEnd`.
getActiveClipsByTrackgetActiveClipsByTrack(time: RationalTime = ...): Map<string, ActiveClip<string>[]>Groups active clips by containing track id.
getActiveLayersgetActiveLayers(options: ActiveLayerOptions<LayerName>): ActiveLayerResult<LayerName>Finds the clips active at a timeline time and groups them by named layer selectors. Use this for preview, playback, subtitle, and effect integrations that need to know which layer clips should be rendered or synced at the playhead. Hidden or muted tracks and disabled clips are excluded. The result preserves every match in `layers`, deduplicates matches in `all`, and exposes `primary` as a first-match convenience for each requested layer.
getClipgetClip(clipId: string): { clip: Clip; clipIndex: number; track: Track; trackIndex: number } | undefinedLocates a clip and returns its containing track and indexes.
getClipAtPointgetClipAtPoint(input: ClipHitTestInput): ClipHitTestResult | nullHit-tests timeline clips in viewport coordinates, matching canvas track layout. Clip bodies remain selectable even when their track is locked or the clip is non-editable; edge/body edit regions are only reported when the clip can be edited.
getClipDropFeedbackgetClipDropFeedback(): TimelineClipDropFeedbackCurrent transient drop feedback for the active clip body drag interaction.
getClipKeyframesgetClipKeyframes(clipId: string, property?: "opacity"): TimelineKeyframe[]Returns keyframes owned by one clip, optionally filtered by property.
getClipPropertyValueAtTimegetClipPropertyValueAtTime(clipIdOrClip: string | Clip, property: "opacity", timelineTime: RationalTime = ...): number | undefinedEvaluates a keyframed clip property at a timeline time.
getClipRectgetClipRect(clipId: string, geometry: TimelineInteractionGeometry = {}): ClipViewportRect | nullReturns the current viewport rectangle for a clip, matching canvas track layout.
getClipRectsgetClipRects(options: TimelineInteractionGeometry = {}): TimelineClipRect<TrackKind>[]Returns viewport rectangles for every clip in track order. This is the canonical geometry source for DOM clip rendering and custom canvas layers. Pointer hit testing keeps a direct low-allocation path.
getClipSourceRangegetClipSourceRange(clipIdOrClip: string | Clip): ClipSourceRange | undefinedComputes the source-media range covered by a clip.
getClipSyncKeygetClipSyncKey(clipIdOrClip: string | Clip): string | undefinedReturns a stable media sync signature for timing-affecting clip fields.
getEditImpactsgetEditImpacts(): TimelineEditImpacts | nullCurrent transient impacts for the active live edit interaction. Returns null when no live edit is currently affecting other clips.
getEditPreviewgetEditPreview(): TimelineEditPreview | nullCurrent transient preview for the active command-layer edit. Returns null when no command preview is active.
getFirstContentTimegetFirstContentTime(options: Pick<ActiveLayerOptions<LayerName>, "layers">): RationalTime | undefinedFinds the earliest clip start matching any requested layer.
getKeyframeAtPointgetKeyframeAtPoint(input: TimelineKeyframeHitTestInput): TimelineKeyframeHitTestResult<TrackKind> | nullHit-tests timeline keyframes in viewport coordinates.
getKeyframeCurveHandleAtPointgetKeyframeCurveHandleAtPoint(input: TimelineKeyframeCurveHitTestInput): TimelineKeyframeCurveHandleHitTestResult<TrackKind> | nullHit-tests Bezier curve handles in viewport coordinates.
getKeyframeCurveSegmentsgetKeyframeCurveSegments(options: TimelineKeyframeCurveGeometryOptions = {}): TimelineKeyframeCurveSegment<TrackKind>[]Returns keyframe curve segments in track order.
getKeyframeRectsgetKeyframeRects(options: TimelineKeyframeGeometryOptions = {}): TimelineKeyframeRect<TrackKind>[]Returns viewport rectangles for keyframes in track order.
getPlaybackRategetPlaybackRate(): numberReturns the current playback speed multiplier.
getStategetState(): TimelineStateReturns the current engine state object.
getTimegetTime(): RationalTimeReturns the current playhead time.
getTrackAtPointgetTrackAtPoint(input: TrackHitTestInput): TimelineTrackHitTestResult<TrackKind> | nullHit-tests timeline tracks in viewport coordinates, matching canvas layout.
getTrackRectsgetTrackRects(options: TimelineTrackGeometryOptions = {}): TimelineTrackRect[]Returns viewport rectangles for every track row in track order.
getVisibleKeyframeCurveSegmentsgetVisibleKeyframeCurveSegments(options: TimelineKeyframeCurveGeometryOptions = {}): VisibleTimelineKeyframeCurveSegment<TrackKind>[]Returns keyframe curve segments intersecting the current viewport.
getVisibleKeyframesgetVisibleKeyframes(options: TimelineKeyframeGeometryOptions = {}): VisibleTimelineKeyframe<TrackKind>[]Returns keyframes intersecting the current viewport, plus optional overscan.
getVisibleTimelineClipsgetVisibleTimelineClips(options: VisibleTimelineClipOptions = {}): VisibleTimelineClip<TrackKind>[]Returns clips intersecting the current horizontal viewport, plus optional overscan. The returned visible ranges map clipped viewport pixels back to timeline and source-media times so custom renderers can draw cached thumbnails, waveforms, annotations, or heatmaps without duplicating timeline math.
invalidateContentinvalidateContent(): voidNo method summary yet.
moveClipmoveClip(options: TimelineClipMoveOptions): booleanMoves a clip to a new timeline start time and optionally into another track. Honors track and clip movement locks, track-kind compatibility, min/max bounds, snapping, and overwrite preview state when a drag is active.
onon(event: K, callback: (payload: indexedAccess) => void): () => voidSubscribes to a typed event.
pasteSelectionpasteSelection(time: RationalTime, targetTrackId?: string): voidPastes clipboard clips at a timeline time. Relative offsets between copied clips are preserved. When no target track is supplied, the first targeted track is used, then the first track as fallback.
pausepause(): voidStops playhead playback and clears the active animation frame.
pixelToTimepixelToTime(pixel: number, rate: number = 24000): RationalTimeConverts a horizontal pixel coordinate to timeline time.
playplay(options: PlaybackOptions = {}): booleanStarts playhead playback.
prepareSnappingprepareSnapping(ignoreClipIdOrOptions?: string | SnapPreparationOptions): voidRebuilds snap targets for an upcoming drag, trim, or range-boundary gesture.
previewEditpreviewEdit(command: TimelineEditCommand): TimelineEditPreviewResolves and publishes a non-mutating preview for an edit command.
redoredo(): voidRestores the next redo-history snapshot when available.
registerSnapProviderregisterSnapProvider(provider: TimelineSnapProvider): () => voidRegisters a runtime snap target provider.
removeClipKeyframeremoveClipKeyframe(clipId: string, keyframeId: string, options: TimelineKeyframeMutationOptions = {}): booleanRemoves a keyframe from one clip.
removeMarkerremoveMarker(id: string): booleanRemoves a marker by id.
removeTrackremoveTrack(trackId: string): booleanRemoves a track by id.
resolveSnapresolveSnap(time: RationalTime, publishFeedback: boolean = true): TimelineSnapResult | nullResolves a candidate timeline time against the prepared snap index.
selectClipselectClip(clipId: string | null): voidSelects one clip and clears selection from all others.
selectClipKeyframeselectClipKeyframe(clipId: string | null, keyframeId: string | null): voidSelects one keyframe and clears all other keyframe selections.
selectTrackselectTrack(trackId: string | null): voidSelects one track and clears selection from all others.
setClipDropFeedbacksetClipDropFeedback(feedback: TimelineClipDropFeedback): voidPublishes transient drop feedback for renderer and headless UI consumers.
setClipKeyframesetClipKeyframe(input: TimelineSetClipKeyframeOptions, options: TimelineKeyframeMutationOptions = {}): TimelineKeyframe | nullAdds or updates one keyframe by clip, property, and exact timeline time. New keyframes created without an explicit `interpolation` inherit the interpolation mode and Bezier easing of the previous keyframe in the same property lane, so splitting a segment keeps its easing character. Linear is used when no previous keyframe exists.
setDurationsetDuration(duration: RationalTime | undefined): voidSets or clears an explicit timeline duration. When a duration is set, zoom, scroll, and playhead are clamped to that duration instead of the dynamic maximum clip end.
setEditPolicysetEditPolicy(policy: TimelineEditPolicy | undefined): voidReplaces the app-defined edit policy used by command validation.
setInPointsetInPoint(time: RationalTime | undefined, snap?: boolean): voidSets or clears the in-point boundary.
setOutPointsetOutPoint(time: RationalTime | undefined, snap?: boolean): voidSets or clears the out-point boundary.
setPlaybackRatesetPlaybackRate(rate: number): voidUpdates the playback speed multiplier.
setScrollLeftsetScrollLeft(scroll: number): voidSets horizontal scroll offset, clamped to the valid scroll range.
setScrollTopsetScrollTop(scroll: number): voidSets vertical scroll offset, clamped to the valid track stack scroll range.
setSnappingEnabledsetSnappingEnabled(enabled: boolean): voidEnables or disables magnetic snapping.
setSnapThresholdPixelssetSnapThresholdPixels(thresholdPixels: number): voidSets the magnetic snap radius in screen pixels.
setTimesetTime(time: RationalTime): voidMoves the playhead to an absolute timeline time. Alias for `updatePlayhead` that reads naturally in external media sync code.
settlesettle(): voidFinalizes an interaction, clears snap guides, snapshots history, and emits settled state.
setTrackGroupsetTrackGroup(trackId: string, groupId: string | undefined): voidAssigns a track to a group or removes it from grouping.
setTrackHeightsetTrackHeight(trackId: string, height: number): voidUpdates a track's expanded display height.
setTrackHeightssetTrackHeights(updates: typeOperator, options: TimelineTrackHeightBatchOptions = {}): voidSets multiple expanded track heights and publishes a single settled/render cycle.
setViewportHeightsetViewportHeight(height: number): voidStores the visible timeline viewport height.
setViewportWidthsetViewportWidth(width: number): voidStores the visible timeline viewport width.
setZoomConstraintssetZoomConstraints(constraints: TimelineZoomConstraints = {}): voidUpdates engine-owned zoom constraints and re-clamps the current viewport.
setZoomScalesetZoomScale(scale: number): voidSets the zoom scale while keeping the viewport within content bounds.
slideClipslideClip(clipId: string, deltaTime: RationalTime): voidMoves a clip by a relative timeline offset.
slipClipslipClip(clipId: string, deltaTime: RationalTime): voidShifts a clip's source start without moving it on the timeline.
snapshotsnapshot(): voidStores the current track and marker state in undo history.
sourceTimeToTimelineTimesourceTimeToTimelineTime(clipIdOrClip: string | Clip, sourceTime: RationalTime): RationalTime | undefinedMaps a source-media timestamp within a clip back to timeline time.
splitClipsplitClip(clipId: string, splitTime: RationalTime): booleanSplits a clip into two clips at a timeline time.
startDragstartDrag(): voidCaptures the current track state for live drag preview.
timelineTimeToSourceTimetimelineTimeToSourceTime(clipIdOrClip: string | Clip, timelineTime: RationalTime = ...): RationalTime | undefinedMaps a timeline timestamp within a clip to the matching source-media time.
timeToPixeltimeToPixel(time: RationalTime): numberConverts a timeline time to a horizontal pixel coordinate.
toggleLockTracktoggleLockTrack(trackId: string, locked?: boolean): voidEnables, disables, or toggles a track's locked state.
toggleMuteTracktoggleMuteTrack(trackId: string, muted?: boolean): voidEnables, disables, or toggles a track's muted state.
toggleTrackTargettoggleTrackTarget(trackId: string, targeted?: boolean): voidEnables, disables, or toggles track targeting.
toggleTrackVisibilitytoggleTrackVisibility(trackId: string, visible?: boolean): voidEnables, disables, or toggles a track's output visibility.
trimCliptrimClip(clipId: string, edge: "start" | "end", newTime: RationalTime): voidTrims one edge of a clip to a new timeline time. Start trims also shift `sourceStart` so the visible source frame remains aligned with the new timeline boundary.
undoundo(): voidRestores the previous undo-history snapshot when available.
updateClipKeyframeupdateClipKeyframe(input: TimelineUpdateClipKeyframeOptions, options: TimelineKeyframeMutationOptions = {}): TimelineKeyframe | nullUpdates an existing keyframe. Committed updates merge keyframes that land on the same property and time. Preview updates (`{ commit: false }`) never delete a colliding neighbor; the keyframe keeps its current time instead, so drag previews stay non-destructive.
updateClipPropertiesupdateClipProperties(clipId: string, properties: Partial<Pick<Clip, "label" | "opacity" | "color">>): booleanUpdates user-facing clip display properties.
updateMarkerupdateMarker(id: string, updates: Partial<Marker>): Marker | nullUpdates an existing marker.
updatePlayheadupdatePlayhead(time: RationalTime): voidMoves the playhead, clamped to the timeline content range.
validateEditvalidateEdit(command: TimelineEditCommand): TimelineEditValidationResultValidates an edit command without mutating timeline state.