refactor(core): CORE-10 type playback properties and add compatible controls view

This commit is contained in:
Harvey Zhao committed 2026-09-11 02:51:55 +08:00
1 parent 44f4e083a9
commit 5e31274f1d
48 files changed
+3846 -248

No files matched your search

+6 -1
View File
@@ -13,8 +13,13 @@ const throttled: number = Artplayer.utils.throttle(() => 1, 10)()
const descriptor: void = Artplayer.utils.def({}, 'value', { value: 1 })
const updated: Artplayer['setting'] = art.setting.update({ name: 'entry', html: 'Entry' })
const removed: Artplayer['setting'] = art.setting.remove('entry')
const seekRead: number = art.seek
const forwardRead: number = art.forward
const backwardRead: number = art.backward
const switchRead: string = art.switch
const qualityRead: Artplayer['quality'] = art.quality
art.on('subtitleBeforeUpdate', (cue) => {
const historicalCue: VTTCue = cue
void historicalCue
})
void [requiredUrl, registration, toggle, debounced, throttled, descriptor, updated, removed]
void [requiredUrl, registration, toggle, debounced, throttled, descriptor, updated, removed, seekRead, forwardRead, backwardRead, switchRead, qualityRead]
+33
View File
@@ -0,0 +1,33 @@
import currentTimeMix from '../../packages/artplayer/src/player/currentTimeMix'
import loadedMix from '../../packages/artplayer/src/player/loadedMix'
import seekMix from '../../packages/artplayer/src/player/seekMix'
import toggleMix from '../../packages/artplayer/src/player/toggleMix'
declare const timing: {
template: { $video: Pick<HTMLMediaElement, 'currentTime' | 'duration' | 'buffered'> }
duration: number
notice: { show: string }
emit: (name: 'seek', actual: number, requested: number | string) => void
}
currentTimeMix(timing)
timing.currentTime = '12.5 seconds'
const time: number = timing.currentTime
seekMix(timing)
timing.seek = 12
const noSeekGetter: undefined = timing.seek
const noForwardGetter: undefined = timing.forward
loadedMix(timing)
const loaded: number = timing.loadedTime
void [time, loaded, noSeekGetter, noForwardGetter]
// @ts-expect-error Buffered state is computed, not writable.
timing.loaded = 0.5
// @ts-expect-error Time inputs do not advertise booleans.
timing.currentTime = true
declare const playback: { playing: boolean, play: () => Promise<42>, pause: () => 'paused' }
toggleMix(playback)
const result: Promise<42> | 'paused' = playback.toggle()
void result
// @ts-expect-error A toggle preserves either branch, not only the play branch.
const invalid: Promise<42> = playback.toggle()
void invalid
+19
View File
@@ -0,0 +1,19 @@
import type Artplayer from 'artplayer'
import type { PlaybackControls } from 'artplayer'
import type { PlaybackControls as SharedControls } from 'artplayer/types'
declare const art: Artplayer
const controls: PlaybackControls = art
const shared: SharedControls = controls
const toggled: Promise<void> | void = shared.toggle()
if (toggled)
toggled.catch(() => {})
const played: Promise<void> = controls.play()
const paused: void = controls.pause()
const historical: void = art.toggle()
void [played, paused, historical]
// @ts-expect-error A paused toggle does not return a Promise.
const alwaysAsync: Promise<void> = controls.toggle()
// @ts-expect-error Toggle does not report playback as a boolean.
const boolean: boolean = controls.toggle()
void [alwaysAsync, boolean]