| 1 | import { useMouse } from '@vueuse/core' |
| 2 | import { computed } from 'vue' |
| 3 | import { mainSlideElement } from '../internals/SlideContainer.vue' |
| 4 | |
| 5 | export function useMousePosInSlide() { |
| 6 | const mouse = useMouse() |
| 7 | |
| 8 | return computed(() => { |
| 9 | const rect = mainSlideElement.value?.getBoundingClientRect() |
| 10 | if (!rect) |
| 11 | return undefined |
| 12 | |
| 13 | const x = (mouse.x.value - rect.left) / rect.width * 100 |
| 14 | const y = (mouse.y.value - rect.top) / rect.height * 100 |
| 15 | |
| 16 | if (x < 0 || x > 100 || y < 0 || y > 100) |
| 17 | return undefined |
| 18 | |
| 19 | return { x, y } |
| 20 | }) |
| 21 | } |
| 22 |