@molecule/app-feature-video-scrubber-angular
v1.2.0
Published
Frame-accurate video scrubber for video-editor — timeline strip with thumbnail filmstrip, playhead, and frame-by-frame stepping; composes with @molecule/app-feature-video-timeline-react
Maintainers
Readme
@molecule/app-feature-video-scrubber-angular
Angular frame-accurate video scrubber — the counterpart of
@molecule/app-feature-video-scrubber-react: the same props and the same
DOM for the same input.
Exports <VideoScrubber> (attribute selector div[mol-video-scrubber], so
the host IS React's root element), the Thumbnail and VideoScrubberProps
types, the default constants, and the pure helpers timeToFrame,
frameToTime, snapTimeToFrame, computeFilmstripTicks,
selectClosestThumbnail, and formatFrameNumber.
Timeline strip with thumbnail filmstrip, vertical playhead, frame-by-frame keyboard stepping (Shift = ±1 second), and an optional frame-number readout.
Composes well with <VideoTimeline> from
@molecule/app-feature-video-timeline-angular — the scrubber shows
preview thumbnails and frame-precision controls; the timeline shows
multi-track structure.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { Component } from '@angular/core'
import { VideoScrubber } from '@molecule/app-feature-video-scrubber-angular'
@Component({
selector: 'app-editor',
standalone: true,
imports: [VideoScrubber],
template: `
<div
mol-video-scrubber
[duration]="60"
[currentTime]="currentTime"
[fps]="24"
[thumbnails]="thumbnails"
(onSeek)="currentTime = $event"
></div>
`,
})
export class Editor {
currentTime = 3.2
thumbnails = [
{ time: 0, src: 'data:image/png;base64,...' },
{ time: 5, src: 'data:image/png;base64,...' },
{ time: 10, src: 'data:image/png;base64,...' },
]
}Type
feature
Installation
npm install @molecule/app-feature-video-scrubber-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angularAPI
Interfaces
Thumbnail
One pre-computed thumbnail at a given time. The scrubber renders a
filmstrip row of thumbnails by picking, for each visible tick, the
provided thumbnail whose time is closest. Hosts can supply as few
or as many thumbnails as they like; gaps are filled by repeating the
nearest neighbour.
interface Thumbnail {
/** Time of this thumbnail in seconds. */
time: number
/** Image source URL (data: URL or fetched blob URL). */
src: string
}VideoScrubberProps
Props for <VideoScrubber> (React's prop names). Frame-accurate scrubber
widget pairing a thumbnail filmstrip with a click-to-seek playhead,
frame-step keyboard controls, and an optional frame-number readout.
interface VideoScrubberProps {
/** Total media duration in seconds. */
duration: number
/** Current playhead time in seconds. */
currentTime: number
/** Frames-per-second used for snapping + frame-step keyboard. Defaults to 24. */
fps?: number
/** Pre-computed thumbnails. The scrubber picks the closest one per filmstrip tick. */
thumbnails?: Thumbnail[]
/** Called with the seek time (snapped to the nearest frame). */
onSeek?: (time: number) => void
/** Whether to show the frame-number readout. Defaults to `true`. */
showFrameNumber?: boolean
/** Number of filmstrip cells to render. Defaults to 12. */
thumbnailCount?: number
/** Filmstrip cell height in px. Defaults to 48. */
thumbnailHeight?: number
/** Optional id for the root element (useful for label associations). */
id?: string
/** Extra classes merged onto the root element. */
className?: string
}Classes
VideoScrubber
Frame-accurate video scrubber. Renders an evenly-spaced filmstrip of
thumbnail images, a vertical playhead, and an optional frame-number
readout. Click anywhere on the strip to seek (snapped to the nearest
frame); use ←/→ arrows to step ±1 frame, or Shift+←/→ to step
±1 second. All onSeek calls receive frame-snapped times.
The host IS the root <div> (div[mol-video-scrubber]), matching React's
root exactly, so the root's ClassMap classes and inline style are the
host's.
@Component({
selector: 'div[mol-video-scrubber]',
standalone: true,
imports: [WebDragDirective],
inputs: [
'duration',
'currentTime',
'fps',
'thumbnails',
'onSeek',
'showFrameNumber',
'thumbnailCount',
'thumbnailHeight',
'id',
'className',
],
host: {
role: 'group',
'data-mol-id': 'video-scrubber',
'[attr.id]': 'id ?? null',
'[attr.aria-label]': 'rootLabel()',
'[attr.data-fps]': 'safeFps()',
'[attr.data-frame]': 'currentFrame()',
'[class]': 'classes()',
'[style]': 'rootStyle',
},
// prettier-ignore
template: `<div role="slider" tabindex="0" [attr.aria-label]="stripLabel()" aria-valuemin="0" [attr.aria-valuemax]="safeDuration()" [attr.aria-valuenow]="clampedTime()" data-mol-id="video-scrubber-strip" [style]="stripBodyStyle()" [molDrag]="stripDrag" (keydown)="onKeyDown($event)">@for (tk of ticks(); track $index) {<div data-mol-id="video-scrubber-cell" [attr.data-time]="tk.time" [attr.data-index]="$index" role="img" [attr.aria-label]="cellLabel(tk.time)" [style]="cellStyle(tk.time)"></div>}<div data-mol-id="video-scrubber-playhead" [attr.aria-label]="playheadLabel()" [style]="playheadStyle()"></div></div>@if (showFrameReadout()) {<div data-mol-id="video-scrubber-frame-readout" [attr.aria-label]="frameReadoutLabel()" [class]="readoutClasses()" style="font-variant-numeric: tabular-nums"><span data-mol-id="video-scrubber-frame-current">{{ frameNumber() }}</span><span data-mol-id="video-scrubber-frame-total">{{ totalLabel() }}</span></div>}`,
})
export class VideoScrubber {
/** Total media duration in seconds. */
duration = 0
/** Current playhead time in seconds. */
currentTime = 0
fps?: number
/** Pre-computed thumbnails. */
thumbnails?: Thumbnail[]
onSeek?: (time: number) => void
showFrameNumber?: boolean
thumbnailCount?: number
thumbnailHeight?: number
id?: string
/** Extra classes merged onto the root element. */
className?: string
/** React's root inline style. */
readonly rootStyle = ROOT_STYLE
private readonly i18n = useTranslation()
private readonly seekDrag: ElementDrag = {
axis: 'horizontal',
onStart: (point) => this.seekAt(point),
onMove: (point) => this.seekAt(point),
}
get stripDrag(): ElementDrag | undefined {
return typeof this.onSeek === 'function' ? this.seekDrag : undefined
}
/** The current class map. */
cm(): UIClassMap {
return getClassMap()
}
classes(): string {
return this.cm().cn(this.className)
}
readoutClasses(): string {
return this.cm().cn(
this.cm().flex({ align: 'center', justify: 'between' }),
this.cm().sp('p', 1),
)
}
safeFps(): number {
const fps = this.fps === undefined ? DEFAULT_FPS : this.fps
return Number.isFinite(fps) && fps > 0 ? fps : DEFAULT_FPS
}
/** React's `duration <= 0` guard. */
safeDuration(): number {
return Number.isFinite(this.duration) && this.duration > 0 ? this.duration : 0
}
clampedTime(): number {
const time = Number.isFinite(this.currentTime) && this.currentTime > 0 ? this.currentTime : 0
const duration = this.safeDuration()
return time > duration ? duration : time
}
currentFrame(): number {
return timeToFrame(this.clampedTime(), this.safeFps())
}
totalFrames(): number {
return timeToFrame(this.safeDuration(), this.safeFps())
}
showFrameReadout(): boolean {
return this.showFrameNumber === undefined ? true : Boolean(this.showFrameNumber)
}
/** The playhead position across the strip, 0..1. */
playheadPosition(): number {
const duration = this.safeDuration()
return duration > 0 ? this.clampedTime() / duration : 0
}
ticks(): Tick[] {
const count = this.thumbnailCount === undefined ? DEFAULT_THUMBNAIL_COUNT : this.thumbnailCount
return computeFilmstripTicks(this.safeDuration(), count)
}
/** The filmstrip cell height in px. */
cellHeight(): number {
return this.thumbnailHeight === undefined ? DEFAULT_THUMBNAIL_HEIGHT : this.thumbnailHeight
}
stripBodyStyle(): string {
return [
'position: relative',
'display: flex',
'width: 100%',
`height: ${this.cellHeight()}px`,
'overflow: hidden',
`cursor: ${typeof this.onSeek === 'function' ? 'pointer' : 'default'}`,
'touch-action: none',
'user-select: none',
].join('; ')
}
playheadStyle(): string {
return [
'position: absolute',
'top: 0px',
'bottom: 0px',
'width: 2px',
`left: ${this.playheadPosition() * 100}%`,
'transform: translateX(-1px)',
'background: var(--mol-video-scrubber-playhead, #ff3b30)',
'pointer-events: none',
'z-index: 2',
].join('; ')
}
cellThumbnail(time: number): string {
const list = this.thumbnails
if (!list || list.length === 0) return ''
return selectClosestThumbnail(list, time)?.src ?? ''
}
cellStyle(time: number): string {
const src = this.cellThumbnail(time)
return [
'flex: 1 1 0px',
'min-width: 0px',
'height: 100%',
...(src ? [`background-image: url("${src}")`] : []),
'background-size: cover',
'background-position: center center',
'background-color: var(--mol-video-scrubber-cell-bg, rgba(127, 127, 127, 0.15))',
'border-right: var(--mol-video-scrubber-cell-divider, 1px solid rgba(0, 0, 0, 0.08))',
].join('; ')
}
cellLabel(time: number): string {
return this.cellThumbnail(time)
? this.i18n.t('videoScrubber.aria.thumbnail', {}, { defaultValue: 'Frame preview' })
: this.i18n.t('videoScrubber.thumbnails.empty', {}, { defaultValue: 'No preview' })
}
rootLabel(): string {
return this.i18n.t('videoScrubber.aria.root', {}, { defaultValue: 'Video scrubber' })
}
stripLabel(): string {
return this.i18n.t(
'videoScrubber.aria.strip',
{ time: this.clampedTime().toFixed(2), frame: this.currentFrame() },
{ defaultValue: 'Filmstrip — playhead at {{time}}s (frame {{frame}})' },
)
}
playheadLabel(): string {
return this.i18n.t(
'videoScrubber.aria.playhead',
{ time: this.clampedTime().toFixed(2) },
{ defaultValue: 'Playhead at {{time}}s' },
)
}
frameReadoutLabel(): string {
return this.i18n.t(
'videoScrubber.aria.frameReadout',
{ frame: this.currentFrame(), total: this.totalFrames() },
{ defaultValue: 'Frame {{frame}} of {{total}}' },
)
}
totalLabel(): string {
return this.i18n.t(
'videoScrubber.frameReadout.total',
{ total: this.totalFrames() },
{ defaultValue: '/ {{total}} frames' },
)
}
frameNumber(): string {
return formatFrameNumber(this.currentFrame())
}
private seekAt({ x, bounds }: ElementDragPoint): void {
const duration = this.safeDuration()
const ratio = bounds.width > 0 ? Math.max(0, Math.min(1, x / bounds.width)) : 0
this.onSeek?.(snapTimeToFrame(ratio * duration, this.safeFps(), duration))
}
onKeyDown(event: KeyboardEvent): void {
if (typeof this.onSeek !== 'function') return
const duration = this.safeDuration()
const fps = this.safeFps()
const clampedTime = this.clampedTime()
const currentFrame = timeToFrame(clampedTime, fps)
const { key, shiftKey } = event
let next: number | null = null
if (key === 'ArrowLeft') {
next = shiftKey ? clampedTime - 1 : frameToTime(currentFrame - 1, fps)
} else if (key === 'ArrowRight') {
next = shiftKey ? clampedTime + 1 : frameToTime(currentFrame + 1, fps)
} else if (key === 'PageUp') {
next = frameToTime(currentFrame - 10, fps)
} else if (key === 'PageDown') {
next = frameToTime(currentFrame + 10, fps)
} else if (key === 'Home') {
next = 0
} else if (key === 'End') {
next = duration
}
if (next === null) return
event.preventDefault()
this.onSeek(snapTimeToFrame(next, fps, duration))
}
}(Member comments are shortened to their first sentence, and the 30 longest are left out to fit; the full declaration is in node_modules/@molecule/app-feature-video-scrubber-angular/dist/video-scrubber.component.d.ts.)
Functions
timeToFrame(time, fps)
Convert a continuous time in seconds to a frame index, given a frame rate. The result is rounded to the nearest integer (i.e. snapped to the closest frame boundary).
function timeToFrame(time: number, fps: number): numbertime— Time in seconds.fps— Frame rate. Must be > 0.
Returns: Integer frame index (>= 0).
frameToTime(frame, fps)
Convert a frame index back to a time in seconds.
function frameToTime(frame: number, fps: number): numberframe— Frame index (any integer >= 0).fps— Frame rate. Must be > 0.
Returns: Time in seconds.
snapTimeToFrame(time, fps, duration)
Snap a continuous time value to the nearest frame boundary, then
clamp into [0, duration]. This is what the scrubber emits via
onSeek for click-anywhere scrubbing.
function snapTimeToFrame(time: number, fps: number, duration: number): numbertime— Candidate time in seconds.fps— Frame rate. Must be > 0.duration— Maximum time in seconds (clamp upper bound).
Returns: Frame-snapped, clamped time in seconds.
computeFilmstripTicks(duration, count)
Compute evenly-spaced filmstrip ticks across [0, duration]. Each
tick has a time (in seconds) and a position (0..1) for layout
via left: position * 100%. The first tick is at time 0; the last
tick is at time duration (or 0 if duration <= 0).
function computeFilmstripTicks(duration: number, count: number): Tick[]duration— Total duration in seconds.count— Number of ticks. Coerced into[1, 1000].
Returns: Array of { time, position } ticks (length === clamped count).
selectClosestThumbnail(thumbnails, targetTime)
Pick the thumbnail whose time is closest to a target time. Ties
break toward the earlier thumbnail. Returns undefined only when
the input list is empty.
function selectClosestThumbnail(thumbnails: Thumbnail[], targetTime: number): Thumbnail | undefinedthumbnails— Available thumbnails (any order).targetTime— The target time in seconds.
Returns: The closest thumbnail, or undefined if thumbnails is empty.
formatFrameNumber(frame)
Format a frame index for the readout display — fixed-width-friendly with a leading hash for clarity.
function formatFrameNumber(frame: number): stringframe— Frame index.
Returns: The display string (e.g. #42).
Constants
DEFAULT_FPS
Default frame rate (24fps — feature-film standard).
const DEFAULT_FPS: 24DEFAULT_THUMBNAIL_COUNT
Default number of filmstrip cells.
const DEFAULT_THUMBNAIL_COUNT: 12DEFAULT_THUMBNAIL_HEIGHT
Default filmstrip cell height in px.
const DEFAULT_THUMBNAIL_HEIGHT: 48Injection Notes
Requirements
Peer dependencies:
@angular/common^22.0.0@angular/core^22.0.0@angular/platform-browser^22.0.0@molecule/app-angular^3.5.0@molecule/app-ui^1.9.0@molecule/app-ui-angular^1.6.0
Runtime Dependencies
@angular/common@angular/core@angular/platform-browser@molecule/app-angular@molecule/app-ui@molecule/app-ui-angular
onSeek is always called with frame-snapped times. Click anywhere on
the filmstrip to seek; press the strip with keyboard focus and use
arrows for ±1 frame, Shift+arrows for ±1 second, PageUp/PageDown for
±10 frames, Home/End to jump to start/end.
Translations
Translation strings are provided by @molecule/app-locales-feature-video-scrubber.
