Line data Source code
1 16 : <template>
2 29 : <div
3 : ref="pointerZoneRef"
4 : data-testid="pointer-zone"
5 : class="h-full w-[calc(100%-4rem-220px)]"
6 : @pointerdown="handlePointerDown"
7 : @pointermove="handlePointerMove"
8 : @pointerup="handlePointerUp"
9 : @pointerleave="handlePointerLeave"
10 : @pointerenter="handlePointerEnter"
11 : @touchstart="handleTouchStart"
12 : @touchmove="handleTouchMove"
13 : @touchend="handleTouchEnd"
14 : @wheel.prevent="handleWheel"
15 : @contextmenu.prevent
16 : />
17 : </template>
18 :
19 : <script setup lang="ts">
20 : import { onMounted, ref, watch } from 'vue'
21 :
22 : import type { usePanAndZoom } from '#/usePanAndZoom'
23 : import type { useToolManager } from '#/useToolManager'
24 : import { useMaskEditorStore } from '#/maskEditorStore'
25 :
26 : const { toolManager, panZoom } = defineProps<{
27 : toolManager: ReturnType<typeof useToolManager>
28 : panZoom: ReturnType<typeof usePanAndZoom>
29 : }>()
30 :
31 29 : const store = useMaskEditorStore()
32 29 : const pointerZoneRef = ref<HTMLDivElement>()
33 :
34 29 : onMounted(() => {
35 29 : if (!pointerZoneRef.value) {
36 0 : console.error('[PointerZone] Pointer zone ref not initialized')
37 0 : return
38 : }
39 :
40 29 : store.pointerZone = pointerZoneRef.value
41 : })
42 :
43 29 : watch(
44 : () => store.isPanning,
45 : (isPanning) => {
46 2 : if (!pointerZoneRef.value) return
47 :
48 2 : if (isPanning) {
49 1 : pointerZoneRef.value.style.cursor = 'grabbing'
50 : } else {
51 1 : toolManager.updateCursor()
52 : }
53 : }
54 : )
55 :
56 29 : const handlePointerDown = async (event: PointerEvent) => {
57 20 : await toolManager.handlePointerDown(event)
58 : }
59 :
60 29 : const handlePointerMove = async (event: PointerEvent) => {
61 230 : await toolManager.handlePointerMove(event)
62 : }
63 :
64 29 : const handlePointerUp = (event: PointerEvent) => {
65 20 : void toolManager.handlePointerUp(event)
66 : }
67 :
68 29 : const handlePointerLeave = () => {
69 20 : store.brushVisible = false
70 20 : if (pointerZoneRef.value) {
71 20 : pointerZoneRef.value.style.cursor = ''
72 : }
73 : }
74 :
75 29 : const handlePointerEnter = () => {
76 29 : toolManager.updateCursor()
77 : }
78 :
79 29 : const handleTouchStart = (event: TouchEvent) => {
80 0 : panZoom.handleTouchStart(event)
81 : }
82 :
83 29 : const handleTouchMove = async (event: TouchEvent) => {
84 0 : await panZoom.handleTouchMove(event)
85 : }
86 :
87 29 : const handleTouchEnd = (event: TouchEvent) => {
88 0 : panZoom.handleTouchEnd(event)
89 : }
90 :
91 29 : const handleWheel = async (event: WheelEvent) => {
92 0 : await panZoom.zoom(event)
93 0 : const newCursorPoint = { x: event.clientX, y: event.clientY }
94 0 : panZoom.updateCursorPosition(newCursorPoint)
95 : }
96 : </script>
|