mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 05:41:20 -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,22 @@
|
||||
interface EventPathSource {
|
||||
target: EventTarget | null
|
||||
composedPath?: () => EventTarget[]
|
||||
}
|
||||
|
||||
export function getComposedPath(event: EventPathSource): EventTarget[] {
|
||||
if (event.composedPath)
|
||||
return event.composedPath()
|
||||
const path: EventTarget[] = []
|
||||
let node = event.target
|
||||
while (node) {
|
||||
path.push(node)
|
||||
node = (node as EventTarget & { parentNode?: EventTarget | null }).parentNode ?? null
|
||||
}
|
||||
if (typeof window !== 'undefined' && !path.includes(window))
|
||||
path.push(window)
|
||||
return path
|
||||
}
|
||||
|
||||
export function includeFromEvent(event: EventPathSource, target: EventTarget | null | undefined): boolean {
|
||||
return getComposedPath(event).includes(target as EventTarget)
|
||||
}
|
||||
Reference in new issue
Block a user