ranui
Version:
A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.
70 lines (69 loc) • 3.22 kB
TypeScript
import type { PlaybackSnapshot } from './playback';
import type { PlayerContextState, PlayerRuntimeState } from './state';
import type { PlayerVisualSignals } from './store';
import { type ThumbnailCue } from './thumbnails';
export interface PlayerSeekRefs {
progress: HTMLDivElement;
progressWrap: HTMLDivElement;
progressWrapValue: HTMLDivElement;
progressDot: HTMLDivElement;
playerBtn: HTMLDivElement;
playerTip: HTMLDivElement;
playerTipThumbnail: HTMLDivElement;
playerTipTime: HTMLDivElement;
playerTipText: HTMLDivElement;
}
export type PlayerSeekRuntimeState = Pick<PlayerRuntimeState<PlaybackSnapshot>, 'moveProgress' | 'isSeeking' | 'wasPlayingBeforeSeek' | 'pendingPlaybackRestore' | 'isSwitchingSource'>;
export interface PlayerSeekDeps {
refs: PlayerSeekRefs;
state: PlayerSeekRuntimeState;
ctx: Pick<PlayerContextState, 'duration' | 'currentTime'>;
visualSignals: PlayerVisualSignals;
getVideo: () => HTMLVideoElement | undefined;
getTotalTime: () => number;
getCurrentTime: () => number;
setCurrentTime: (n: number) => number;
safePlay: (showLoading: boolean) => void;
pause: () => void;
showControllerBar: (e?: MouseEvent) => void;
getThumbnailCue: (time: number) => ThumbnailCue | undefined;
/**
* Self-forwarding entries for this module's own methods — handlers below call
* siblings through the RanPlayer wrapper (`this.seekToPercentage(...)` etc.)
* instead of the local closures, so a `vi.spyOn(player, 'seekToPercentage')`
* set up after construction still intercepts them (a bare local reference
* would forever point at the pre-spy original).
*/
seekToPercentage: (percentage: number) => void;
syncProgressByPercentage: (percentage: number) => void;
updateCurrentProgress: () => void;
updateBufferedProgress: () => void;
requestAnimationFrame: (fn: Function) => void;
cancelAnimationFrame: () => void;
}
export interface PlayerSeekHandlers {
progressClick: (e: MouseEvent) => void;
onProgressKeydown: (e: KeyboardEvent) => void;
progressDotPointerDown: (e: PointerEvent) => void;
progressDotMouseMove: (e: MouseEvent) => void;
progressDotPointerMove: (e: PointerEvent) => void;
progressDotPointerUp: () => void;
progressDotPointerCancel: () => void;
syncProgressByPercentage: (percentage: number) => void;
seekToPercentage: (percentage: number) => void;
updateCurrentProgress: () => void;
requestAnimationFrame: (fn: Function) => void;
cancelAnimationFrame: () => void;
progressMouseEnter: (e: MouseEvent) => void;
progressMouseLeave: (e: MouseEvent) => void;
progressMouseMove: (e: MouseEvent) => void;
updateBufferedProgress: () => void;
}
/**
* Everything about the seek bar: click/drag/keyboard seeking, the hover tip,
* and the rAF loop that keeps the progress display live while playing.
* `requestAnimationFrameId` lives as a closure-local here — it's never read
* outside this module (only the `requestAnimationFrame`/`cancelAnimationFrame`
* methods themselves are test-visible).
*/
export declare function createSeekHandlers(deps: PlayerSeekDeps): PlayerSeekHandlers;