@@ -10,13 +10,85 @@ window.__svelte_devtools_select_element = function(element) {
10
10
if ( node ) window . postMessage ( { type : 'inspect' , node : serializeNode ( node ) } )
11
11
}
12
12
13
+ const hoverArea = document . createElement ( 'div' )
14
+ hoverArea . style . position = 'fixed'
15
+ hoverArea . style . backgroundColor = 'rgba(0, 136, 204, 0.2)'
16
+ hoverArea . style . zIndex = '2147483647'
17
+
18
+ const hoverX = document . createElement ( 'div' )
19
+ hoverX . style . position = 'fixed'
20
+ hoverX . style . borderStyle = 'dashed'
21
+ hoverX . style . borderColor = 'rgb(0, 136, 204)'
22
+ hoverX . style . borderWidth = '1px 0'
23
+ hoverX . style . zIndex = '2147483647'
24
+ hoverX . style . left = '0'
25
+ hoverX . style . width = '100vw'
26
+
27
+ const hoverY = document . createElement ( 'div' )
28
+ hoverY . style . position = 'fixed'
29
+ hoverY . style . borderStyle = 'dashed'
30
+ hoverY . style . borderColor = 'rgb(0, 136, 204)'
31
+ hoverY . style . borderWidth = '0 1px'
32
+ hoverY . style . zIndex = '2147483647'
33
+ hoverY . style . top = '0'
34
+ hoverY . style . height = '100vh'
35
+
36
+ function getBoundingRect ( node ) {
37
+ if ( node . type == 'element' ) return node . detail . getBoundingClientRect ( )
38
+
39
+ const maxRect = {
40
+ top : Infinity ,
41
+ left : Infinity ,
42
+ bottom : - Infinity ,
43
+ right : - Infinity
44
+ }
45
+
46
+ for ( const child of node . children ) {
47
+ const rect = getBoundingRect ( child )
48
+ if ( rect . top < maxRect . top ) maxRect . top = rect . top
49
+ if ( rect . left < maxRect . left ) maxRect . left = rect . left
50
+ if ( rect . bottom > maxRect . bottom ) maxRect . bottom = rect . bottom
51
+ if ( rect . right > maxRect . right ) maxRect . right = rect . right
52
+ }
53
+
54
+ maxRect . width = maxRect . right - maxRect . left
55
+ maxRect . height = maxRect . bottom - maxRect . top
56
+
57
+ return maxRect
58
+ }
59
+
13
60
window . addEventListener ( 'message' , e => handleMessage ( e . data ) , false )
14
61
15
62
function handleMessage ( msg ) {
63
+ const node = getNode ( msg . nodeId )
64
+
16
65
switch ( msg . type ) {
17
66
case 'setSelected' :
18
- const node = getNode ( msg . nodeId )
19
67
if ( node ) window . $s = node . detail
68
+ break
69
+
70
+ case 'setHover' :
71
+ if ( ! node ) {
72
+ hoverArea . remove ( )
73
+ hoverX . remove ( )
74
+ hoverY . remove ( )
75
+ break
76
+ }
77
+
78
+ const box = getBoundingRect ( node )
79
+ hoverArea . style . top = box . top + 'px'
80
+ hoverArea . style . left = box . left + 'px'
81
+ hoverArea . style . width = box . width + 'px'
82
+ hoverArea . style . height = box . height + 'px'
83
+ document . body . append ( hoverArea )
84
+
85
+ hoverX . style . top = box . top + 'px'
86
+ hoverX . style . height = box . height - 2 + 'px'
87
+ document . body . append ( hoverX )
88
+
89
+ hoverY . style . left = box . left + 'px'
90
+ hoverY . style . width = box . width - 2 + 'px'
91
+ document . body . append ( hoverY )
20
92
21
93
break
22
94
}
0 commit comments