mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-10 21:06:15 -08:00
refactor(core): [CORE-20] type entry and converge initialization
This commit is contained in:
1 parent
ccf77c4ed2
commit
ee895a558f
100 files changed
+33854
-839
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import type { PipProperty } from '../../packages/artplayer/src/display/types'
|
||||
import type { DisplayStates } from '../../packages/artplayer/src/media/playback'
|
||||
import type { AirplayHost } from '../../packages/artplayer/src/player/airplayMix'
|
||||
import type { AttributeMethods } from '../../packages/artplayer/src/player/attrMix'
|
||||
import type { CssVariableMethods } from '../../packages/artplayer/src/player/cssVarMix'
|
||||
import type { InitialOptionHost } from '../../packages/artplayer/src/player/optionInit'
|
||||
import type { PlaybackStorage } from '../../packages/artplayer/src/plugins/auto-playback/records'
|
||||
import config from '../../packages/artplayer/src/config'
|
||||
import airplayMix from '../../packages/artplayer/src/player/airplayMix'
|
||||
import optionInit from '../../packages/artplayer/src/player/optionInit'
|
||||
import stateMix from '../../packages/artplayer/src/player/stateMix'
|
||||
import Storage from '../../packages/artplayer/src/storage'
|
||||
import { append, getStyle } from '../../packages/artplayer/src/utils/dom'
|
||||
|
||||
declare const element: HTMLElement
|
||||
declare const attrs: AttributeMethods
|
||||
declare const css: CssVariableMethods
|
||||
declare const initial: InitialOptionHost
|
||||
declare const airplay: AirplayHost
|
||||
const raw: unknown = attrs.attr(Symbol('extension'))
|
||||
const text: string = css.cssVar('--custom')
|
||||
const numeric: number = getStyle(element, 'width')
|
||||
const authored: string = getStyle(element, 'width', false)
|
||||
const node: Element | ChildNode | null = append(element, '')
|
||||
const storage = new Storage()
|
||||
const records: PlaybackStorage = storage
|
||||
declare const pip: PipProperty
|
||||
const display: DisplayStates = {
|
||||
mini: false,
|
||||
fullscreen: false,
|
||||
fullscreenWeb: false,
|
||||
get pip(): HTMLElement | null | boolean { return pip.pip },
|
||||
set pip(value: boolean) { pip.pip = value },
|
||||
}
|
||||
stateMix(display)
|
||||
const stored: unknown = storage.get('extension')
|
||||
config.events.push('custom-event')
|
||||
config.methods = ['customMethod']
|
||||
optionInit(initial)
|
||||
airplayMix(airplay)
|
||||
// @ts-expect-error DOM append can return a text node or null.
|
||||
const guaranteedElement: HTMLElement = append(element, '')
|
||||
// @ts-expect-error Raw storage reads are not validated records.
|
||||
const validated: Record<string, unknown> = storage.get()
|
||||
// @ts-expect-error String style reads are distinct from numeric reads.
|
||||
const wrong: number = getStyle(element, 'width', false)
|
||||
export { authored, display, guaranteedElement, node, numeric, raw, records, stored, text, validated, wrong }
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { PlayerHost } from '../../packages/artplayer/src/player'
|
||||
import type { BuiltinHost } from '../../packages/artplayer/src/plugins/builtins'
|
||||
import Artplayer from '../../packages/artplayer/src'
|
||||
|
||||
const art = new Artplayer({ container: '#player', url: '' }, function (player) {
|
||||
const same: Artplayer = player
|
||||
this.option.plugins.push((core) => {
|
||||
core.currentTime = '1.5'
|
||||
return { name: 'source-extension', player: same }
|
||||
})
|
||||
})
|
||||
const playerHost: PlayerHost<Artplayer> = art
|
||||
const builtinHost: BuiltinHost = art
|
||||
const seeking: undefined = art.seek
|
||||
const quality: undefined = art.quality
|
||||
const fullscreen: boolean | undefined = art.fullscreen
|
||||
const noticeVisible: boolean = art.notice.show
|
||||
art.notice.show = new Error('test')
|
||||
art.seek = '1.5'
|
||||
art.quality = [{ html: document.createElement('span'), url: '/video.mp4' }]
|
||||
art.on('document:keydown', (event) => {
|
||||
const key: string = event.key
|
||||
return key
|
||||
})
|
||||
art.on('extension:event', (...values) => values)
|
||||
art.emit('video:timeupdate', new Event('timeupdate'))
|
||||
art.emit('extension:event', { custom: true })
|
||||
// @ts-expect-error The native media event payload must be an Event.
|
||||
art.emit('video:timeupdate', 'not an event')
|
||||
// @ts-expect-error Reconnect errors include the attempt count.
|
||||
art.emit('error', new Error('test'))
|
||||
// @ts-expect-error A setter-only seek is not a readable numeric value.
|
||||
const position: number = art.seek
|
||||
// @ts-expect-error Notice visibility is not the last notice message.
|
||||
const message: string = art.notice.show
|
||||
export { builtinHost, fullscreen, message, noticeVisible, playerHost, position, quality, seeking }
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { PluginFactory, PluginHost } from '../../packages/artplayer/src/plugins/types'
|
||||
import type Artplayer from '../../packages/artplayer/src'
|
||||
import type { PluginFactory } from '../../packages/artplayer/src/plugins/types'
|
||||
import Plugins from '../../packages/artplayer/src/plugins'
|
||||
|
||||
interface Host extends PluginHost<Host> {
|
||||
id: number
|
||||
}
|
||||
declare const host: Host
|
||||
declare const host: Artplayer
|
||||
const registry = new Plugins(host)
|
||||
const sync: typeof registry = registry.add(function (art) {
|
||||
const id: number = this.id + art.id
|
||||
@@ -12,7 +10,7 @@ const sync: typeof registry = registry.add(function (art) {
|
||||
})
|
||||
const asyncResult: Promise<typeof registry> = registry.add(async () => ({ name: 'async' }))
|
||||
const mixed: typeof registry | Promise<typeof registry> = registry.add(() => Math.random() ? Promise.resolve(1) : 1)
|
||||
const untyped: PluginFactory<Host> = () => null
|
||||
const untyped: PluginFactory<Artplayer> = () => null
|
||||
const unknown: typeof registry | Promise<typeof registry> = registry.add(untyped)
|
||||
// @ts-expect-error Synchronous plugins do not always return a Promise.
|
||||
const bad: Promise<typeof registry> = registry.add(() => ({ name: 'sync' }))
|
||||
|
||||
Reference in new issue
Block a user