@techsquidtv/canvas-timeline-utils
packages/utils/src/index.ts
Common Entry Points
Start with these essential APIs, then check the full reference index below.
fromSeconds
Converts seconds to rational timeline time at the requested tick rate.
FunctiontoSeconds
Converts a rational timeline time to seconds.
FunctionformatTime
Formats a rational timeline time as mm:ss.
FunctionformatTimecode
Formats seconds for flexible editable timecode text. Decimal formats are rounded to centiseconds and clamped at zero. Non-finite values are treated as zero. Frame formats round to the nearest frame for the supplied frame rate.
FunctionaddRational
Adds two rational timeline times.
API Index
Exhaustive list of all public exports grouped by category.
Interface
4Options for parsing editable timecode text into `RationalTime`.
RationalTimeStores a timeline time as integer ticks at a fixed rate.
TimecodeFormatOptionsOptions for formatting a seconds value into editable timecode text.
TimecodeParseOptionsOptions for parsing editable timecode text into seconds.
Type Alias
3Display shape used when formatting seconds for editable timecode text. `auto` keeps common decimal clock text unless a frame rate is provided. With a frame rate, `auto` formats frame timecode. `seconds`, `minutes`, and `hours` keep decimal centiseconds. `frames` formats `HH:MM:SS:FF`, and `drop-frame` formats `HH:MM:SS;FF`.
TimecodeFrameRateFrame rate accepted by frame-based timecode helpers. Pass a number for simple rates such as `24`, `25`, `30`, or `60`. Pass a rational object for exact fractional media rates such as `{ numerator: 30000, denominator: 1001 }`.
TimecodeParseRoundingRounding policy used when parsing editable timecode text. `none` preserves the decimal precision entered by the user, within normal JavaScript number limits. `centisecond` rounds the parsed seconds to two decimal places for legacy or display-like workflows.
Function
20Adds two rational timeline times.
assertValidRationalTimeAsserts that a value is a finite rational timeline time.
clampRestricts a number to an inclusive minimum and maximum range.
compareRationalCompares two rational timeline times.
formatRationalTimecodeFormats a `RationalTime` as editable timecode text.
formatSecondsFormats a rational timeline time as decimal seconds.
formatTimeFormats a rational timeline time as mm:ss.
formatTimecodeFormats seconds for flexible editable timecode text. Decimal formats are rounded to centiseconds and clamped at zero. Non-finite values are treated as zero. Frame formats round to the nearest frame for the supplied frame rate.
fromSecondsConverts seconds to rational timeline time at the requested tick rate.
fromTimecodeFrameNumberConverts a zero-based frame number to rational timeline time.
maxRationalReturns the later of two rational timeline times.
minRationalReturns the earlier of two rational timeline times.
parseTimecodeParses flexible editable timecode text into seconds. Accepts plain seconds, decimal seconds, `m:ss`, `m:ss.cc`, `h:mm:ss`, `h:mm:ss.cc`, flexible single-digit colon segments such as `1:2`, and unit suffixes like `s` (seconds), `ms` (milliseconds), `m` (minutes), or `f` (frames, which requires a `frameRate` option). Invalid, negative, missing, or out-of-range user text returns `null`. Invalid developer options such as unsupported drop-frame rates throw `RangeError`.
parseTimecodeToRationalTimeParses editable timecode text into `RationalTime`.
rationalEqualsChecks whether two rational timeline times represent the same moment.
resolveTimecodeFrameRateResolves a frame-rate option to frames per second. This uses the same validation and normalization path as the timecode formatter/parser helpers, so invalid rates throw the same `RangeError`.
roundRounds a number to the requested number of decimal places.
subRationalSubtracts one rational timeline time from another.
toSecondsConverts a rational timeline time to seconds.
toTimecodeFrameNumberConverts a rational time to the nearest source frame number.