refactor(core): CORE-06 type media surfaces and playback hosts

This commit is contained in:
Harvey Zhao committed 2026-09-11 01:18:14 +08:00
1 parent 97d320bd74
commit ee859e4804
27 files changed
+2152 -79

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
import type { ResolvedOption } from '../option/types'
import type { PlaybackMethods } from './types'
export interface MediaHost<Media> {
template: { $video: Media }
}
interface NoticeHost {
i18n: { get: (key: string) => string }
notice: { get show(): unknown, set show(value: string | Error) }
emit: (name: 'play' | 'pause') => unknown
}
export type PauseHost<Media extends Pick<PlaybackMethods, 'pause'>> = MediaHost<Media> & NoticeHost
interface PauseTarget {
pause: () => unknown
}
export type PlayHost<Media extends Pick<PlaybackMethods, 'play'>> = MediaHost<Media> & NoticeHost & Partial<PauseTarget> & {
option: Pick<ResolvedOption, 'mutex'>
constructor: { instances: PauseTarget[] }
}
export interface LayoutHost {
template: { $player: Pick<Element, 'getBoundingClientRect'> }
}
export type RectState = Readonly<Pick<DOMRect, 'bottom' | 'height' | 'left' | 'right' | 'top' | 'width'>> & {
readonly rect: DOMRect
readonly x: number
readonly y: number
}
+40
View File
@@ -0,0 +1,40 @@
export type MediaState = Pick<HTMLMediaElement, 'currentTime' | 'duration' | 'paused' | 'ended' | 'readyState'> & {
readonly playing?: boolean
}
export interface PlaybackMethods<PlayResult = unknown, PauseResult = unknown> {
play: () => PlayResult
pause: () => PauseResult
}
export interface OptionalMediaCapabilities {
readonly textTracks?: ArrayLike<TextTrack>
readonly error?: unknown
requestPictureInPicture?: () => Promise<PictureInPictureWindow>
requestVideoFrameCallback?: (callback: VideoFrameRequestCallback) => number
cancelVideoFrameCallback?: (handle: number) => void
webkitEnterFullscreen?: () => void
webkitExitFullscreen?: () => void
readonly webkitSupportsFullscreen?: boolean
webkitShowPlaybackTargetPicker?: () => void
webkitSupportsPresentationMode?: (mode: string) => boolean
webkitSetPresentationMode?: (mode: string) => void
readonly webkitPresentationMode?: string
readonly webkitDisplayingFullscreen?: boolean
}
export type NativeMedia = Omit<HTMLVideoElement, keyof OptionalMediaCapabilities> & OptionalMediaCapabilities
export type CanvasMedia = HTMLCanvasElement & MediaState & PlaybackMethods & OptionalMediaCapabilities & {
src: string | null
readonly currentSrc: string | null
readonly videoWidth: number
readonly videoHeight: number
readonly buffered: TimeRanges
volume: number
muted: boolean
playbackRate: number
load: () => unknown
}
export type MediaSurface = NativeMedia | CanvasMedia