Overview
The utility package contains rational-time helpers and small shared math functions. It is intentionally light so apps, tests, server export code, and package internals can agree on timeline time math without importing React or the engine.
Use these helpers at the edges of your app when converting from seconds, frame counts, timecode strings, or UI input into the rational time values expected by Canvas Timeline.
Install
pnpm add @techsquidtv/canvas-timeline-utilsnpm install @techsquidtv/canvas-timeline-utilsyarn add @techsquidtv/canvas-timeline-utilsbun add @techsquidtv/canvas-timeline-utilsUse the utilities for
- You need exact
RationalTimevalues instead of floating-point seconds. - You are formatting or parsing timeline time outside the React components.
- You want shared clamp, rounding, and arithmetic helpers without editor dependencies.
Usage
Convert at the app boundary
Keep timeline state in rational time. Convert from seconds or timecode when data enters the timeline, then convert back only for display, media APIs, or export code that requires decimal seconds.
- 1Use
fromSecondswhen creating timeline state from ordinary media durations or UI values. - 2Use
toSecondswhen passing playhead or clip times to browser media APIs. - 3Use formatting helpers for readouts and editable timecode fields.
Example
import { addRational, formatTime, fromSeconds, toSeconds,} from '@techsquidtv/canvas-timeline-utils';
const start = fromSeconds(12);const duration = fromSeconds(3.5);const end = addRational(start, duration);
console.log(formatTime(end));console.log(toSeconds(end));