eligius
    Preparing search index...

    Interface IPositionSource

    Core interface for timeline position sources.

    A position source provides the current position within a timeline and emits position updates. The source of position can vary: elapsed time (RAF), media playback (video), scroll position, mouse position, external data, etc.

    // RAF-based position source
    const source = new RafPositionSource(config);
    await source.init();

    source.onPosition((position) => {
    console.log(`Current position: ${position}`);
    });

    source.onBoundaryReached((boundary) => {
    if (boundary === 'end') console.log('Reached end');
    });

    await source.activate();
    interface IPositionSource {
        loop: boolean;
        state: TSourceState;
        activate(): Promise<void>;
        deactivate(): void;
        destroy(): void;
        getDuration(): number;
        getPosition(): number;
        init(): Promise<void>;
        onActivated(callback: () => void): void;
        onBoundaryReached(callback: (boundary: TBoundary) => void): void;
        onPosition(callback: (position: number) => void): void;
        suspend(): void;
    }

    Implemented by

    Index

    Properties

    loop: boolean

    Whether to loop when reaching the end boundary.

    When true, the source resets to position 0 and continues. When false, the source emits 'end' boundary and deactivates.

    For sources where looping is not applicable (e.g., mouse position), this property has no effect.

    Current state of the position source

    Methods

    • Activate the position source to begin emitting position updates.

      Transitions state from inactive or suspended to active.

      Returns Promise<void>

      If activation fails (e.g., autoplay blocked, permission denied)

    • Deactivate the position source and reset to initial state.

      Transitions state to inactive. Position is reset (typically to 0).

      Returns void

    • Destroy the position source and release all resources.

      After calling destroy, the source cannot be reused. Removes event listeners, closes connections, clears timers.

      Returns void

    • Get the total duration.

      Returns number

      Duration in seconds (or source-specific units), or Infinity for unbounded sources

    • Get the current position.

      Returns number

      Current position in seconds (or source-specific units)

    • Initialize the position source.

      Performs any async setup required before the source can be activated. For example: loading media, binding event listeners, establishing connections.

      Returns Promise<void>

      If initialization fails (e.g., media load error, connection refused)

    • Register a callback for when the source becomes active.

      Called once each time the source transitions to the active state. This is equivalent to "first frame" semantics - for RAF sources it's the first tick, for video sources it's when playback actually starts.

      Parameters

      • callback: () => void

        Function called when source becomes active

      Returns void

    • Register a callback for boundary events.

      Called when position reaches a boundary (start or end). For looping sources, 'end' is emitted before reset.

      Parameters

      • callback: (boundary: TBoundary) => void

        Function receiving the boundary type

      Returns void

    • Register a callback for position updates.

      Called whenever the position changes while the source is active. Frequency depends on the source type (e.g., RAF tick, video timeupdate).

      Parameters

      • callback: (position: number) => void

        Function receiving the current position

      Returns void

    • Suspend the position source, preserving current position.

      Transitions state from active to suspended. Position updates stop but position is preserved for later resumption.

      Returns void