-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
index.ts
34 lines (28 loc) · 990 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { ref } from 'vue-demi'
import type { MaybeRefOrGetter } from '@vueuse/shared'
import { toValue } from '@vueuse/shared'
import { useRafFn } from '../useRafFn'
import type { ConfigurableDocument } from '../_configurable'
import { defaultDocument } from '../_configurable'
export interface UseElementByPointOptions extends ConfigurableDocument {
x: MaybeRefOrGetter<number>
y: MaybeRefOrGetter<number>
}
/**
* Reactive element by point.
*
* @see https://vueuse.org/useElementByPoint
* @param options - UseElementByPointOptions
*/
export function useElementByPoint(options: UseElementByPointOptions) {
const element = ref<HTMLElement | null>(null)
const { x, y, document = defaultDocument } = options
const controls = useRafFn(() => {
element.value = (document?.elementFromPoint(toValue(x), toValue(y)) || null) as HTMLElement | null
})
return {
element,
...controls,
}
}
export type UseElementByPointReturn = ReturnType<typeof useElementByPoint>