mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-15 17:16:16 -08:00
refactor(core): CORE-17 type input events and own interaction lifetimes
This commit is contained in:
1 parent
88aef830df
commit
a842058136
72 files changed
+31156
-1219
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import type { GlobalEventSource } from '../../packages/artplayer/src/events/global-types'
|
||||
import type { ViewEvents, ViewHost } from '../../packages/artplayer/src/events/scheduling-types'
|
||||
import type { EventsHost } from '../../packages/artplayer/src/events/types'
|
||||
import Events from '../../packages/artplayer/src/events'
|
||||
import { eventSubscriptions } from '../../packages/artplayer/src/events/subscriptions'
|
||||
|
||||
declare const host: EventsHost
|
||||
declare const view: ViewHost
|
||||
declare const source: GlobalEventSource
|
||||
const events = new Events(host)
|
||||
const target = document.createElement('button')
|
||||
const dispose: () => void = events.proxy(target, 'click', event => event.preventDefault(), null)
|
||||
const disposers: (() => void)[] = events.proxy(target, ['click', 'mouseenter'], { handleEvent: event => event.preventDefault() })
|
||||
events.remove(dispose)
|
||||
disposers.forEach(remove => remove())
|
||||
events.bindGlobalEvents(source)
|
||||
// @ts-expect-error Native registration requires a string name or array.
|
||||
events.proxy(target, 123, () => {})
|
||||
// @ts-expect-error Public hover supplies an Event, not a narrower keyboard event.
|
||||
events.hover(target, (event: KeyboardEvent) => event.code)
|
||||
const on = eventSubscriptions<ViewEvents>(view)
|
||||
on('view', (visible) => {
|
||||
const value: boolean = visible
|
||||
return value
|
||||
})
|
||||
// @ts-expect-error View payloads are boolean.
|
||||
on('view', (visible: string) => visible)
|
||||
// @ts-expect-error The subscription factory only accepts its declared event map.
|
||||
on('resize', () => {})
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { GestureHost } from '../../packages/artplayer/src/input/gesture-types'
|
||||
import type Artplayer from '../../packages/artplayer/types/artplayer'
|
||||
import { gestureController } from '../../packages/artplayer/src/input/gesture-controller'
|
||||
|
||||
declare const art: Artplayer
|
||||
declare const host: GestureHost
|
||||
const gesture = gestureController(host)
|
||||
gesture.start(host.template.$video, new TouchEvent('touchstart'))
|
||||
gesture.move(new TouchEvent('touchmove'))
|
||||
gesture.cancel()
|
||||
// @ts-expect-error Gesture input requires touch coordinates and identifiers.
|
||||
gesture.move(new MouseEvent('mousemove'))
|
||||
art.on('document:touchcancel', (event) => {
|
||||
const original: Event = event
|
||||
return original
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { HotkeyHost } from '../../packages/artplayer/src/input/hotkey-types'
|
||||
import Hotkey from '../../packages/artplayer/src/hotkey'
|
||||
|
||||
declare const host: HotkeyHost & { extension: string }
|
||||
const keys = new Hotkey(host)
|
||||
keys.add('KeyK', function (event) {
|
||||
const extension: string = this.extension
|
||||
const code: string = event.code
|
||||
return { extension, code }
|
||||
}).remove('KeyK', () => {})
|
||||
const same: typeof host = keys.art
|
||||
// @ts-expect-error Keyboard callbacks receive a keyboard event.
|
||||
keys.add('KeyK', (event: MouseEvent) => event.clientX)
|
||||
// @ts-expect-error The callback receiver preserves the host extension type.
|
||||
keys.add('KeyK', function (this: { extension: number }) {
|
||||
return this.extension
|
||||
})
|
||||
export { same }
|
||||
Reference in new issue
Block a user