22import type { DevToolsFrameState , NuxtDevtoolsHostClient , NuxtDevToolsOptions } from ' @nuxt/devtools/types'
33import type { CSSProperties } from ' vue'
44import { toRefs , useElementBounding , useEventListener , useScreenSafeArea } from ' @vueuse/core'
5- import { computed , onMounted , reactive , ref , watchEffect } from ' vue'
5+ import { computed , onMounted , reactive , ref , useTemplateRef , watchEffect } from ' vue'
66import FrameBox from ' ./NuxtDevtoolsFrameBox.vue'
77
88const props = defineProps <{
@@ -38,11 +38,18 @@ const panelMargins = reactive({
3838const safeArea = useScreenSafeArea ()
3939const isSafari = navigator .userAgent .includes (' Safari' ) && ! navigator .userAgent .includes (' Chrome' )
4040
41+ function toNumber(value : string ) {
42+ const num = + value
43+ if (Number .isNaN (num ))
44+ return 0
45+ return num
46+ }
47+
4148watchEffect (() => {
42- panelMargins .left = + safeArea .left .value + 10
43- panelMargins .top = + safeArea .top .value + 10
44- panelMargins .right = + safeArea .right .value + 10
45- panelMargins .bottom = + safeArea .bottom .value + 10
49+ panelMargins .left = toNumber ( safeArea .left .value ) + 10
50+ panelMargins .top = toNumber ( safeArea .top .value ) + 10
51+ panelMargins .right = toNumber ( safeArea .right .value ) + 10
52+ panelMargins .bottom = toNumber ( safeArea .bottom .value ) + 10
4653})
4754
4855const SNAP_THRESHOLD = 2
@@ -57,11 +64,14 @@ const vars = computed(() => {
5764 }
5865})
5966
60- const frameBox = ref <HTMLDivElement >()
61- const panelEl = ref <HTMLDivElement >()
62- const anchorEl = ref <HTMLDivElement >()
67+ const frameBox = useTemplateRef <HTMLDivElement >(' frameBox ' )
68+ const panelEl = useTemplateRef <HTMLDivElement >(' panelEl ' )
69+ const anchorEl = useTemplateRef <HTMLDivElement >(' anchorEl ' )
6370
64- const windowSize = reactive ({ width: 0 , height: 0 })
71+ const windowSize = reactive ({
72+ width: window .innerWidth ,
73+ height: window .innerHeight ,
74+ })
6575const isDragging = ref (false )
6676const draggingOffset = reactive ({ x: 0 , y: 0 })
6777const mousePosition = reactive ({ x: 0 , y: 0 })
@@ -88,22 +98,25 @@ onMounted(() => {
8898 if (! isDragging .value )
8999 return
90100
91- const centerX = windowSize . width / 2
92- const centerY = windowSize . height / 2
101+ const centerX = window . innerWidth / 2
102+ const centerY = window . innerHeight / 2
93103
94104 const x = e .clientX - draggingOffset .x
95105 const y = e .clientY - draggingOffset .y
96106
107+ if (Number .isNaN (x ) || Number .isNaN (y ))
108+ return
109+
97110 mousePosition .x = x
98111 mousePosition .y = y
99112
100113 // Get position
101114 const deg = Math .atan2 (y - centerY , x - centerX )
102115 const HORIZONTAL_MARGIN = 70
103116 const TL = Math .atan2 (0 - centerY + HORIZONTAL_MARGIN , 0 - centerX )
104- const TR = Math .atan2 (0 - centerY + HORIZONTAL_MARGIN , windowSize . width - centerX )
105- const BL = Math .atan2 (windowSize . height - HORIZONTAL_MARGIN - centerY , 0 - centerX )
106- const BR = Math .atan2 (windowSize . height - HORIZONTAL_MARGIN - centerY , windowSize . width - centerX )
117+ const TR = Math .atan2 (0 - centerY + HORIZONTAL_MARGIN , window . innerWidth - centerX )
118+ const BL = Math .atan2 (window . innerHeight - HORIZONTAL_MARGIN - centerY , 0 - centerX )
119+ const BR = Math .atan2 (window . innerHeight - HORIZONTAL_MARGIN - centerY , window . innerWidth - centerX )
107120
108121 state .value .position = deg >= TL && deg <= TR
109122 ? ' top'
@@ -113,8 +126,8 @@ onMounted(() => {
113126 ? ' bottom'
114127 : ' left'
115128
116- state .value .left = snapToPoints (x / windowSize . width * 100 )
117- state .value .top = snapToPoints (y / windowSize . height * 100 )
129+ state .value .left = snapToPoints (x / window . innerWidth * 100 )
130+ state .value .top = snapToPoints (y / window . innerHeight * 100 )
118131 })
119132 useEventListener (window , ' pointerup' , () => {
120133 isDragging .value = false
0 commit comments