@@ -4,16 +4,21 @@ export class Box {
4
4
width : number
5
5
height : number
6
6
7
- constructor ( { x , y , width , height } : {
7
+ constructor ( args : DOMRect | {
8
8
x : number
9
9
y : number
10
10
width : number
11
11
height : number
12
12
} ) {
13
- this . x = x
14
- this . y = y
15
- this . width = width
16
- this . height = height
13
+ const pageScale = document . body . currentCSSZoom ?? 1
14
+ const factor = args instanceof DOMRect ? 1 + ( 1 - pageScale ) / pageScale : 1
15
+
16
+ const { x, y, width, height } = args
17
+
18
+ this . x = x * factor
19
+ this . y = y * factor
20
+ this . width = width * factor
21
+ this . height = height * factor
17
22
}
18
23
19
24
get top ( ) { return this . y }
@@ -37,14 +42,17 @@ export function getOverflow (a: Box, b: Box) {
37
42
38
43
export function getTargetBox ( target : HTMLElement | [ x : number , y : number ] ) : Box {
39
44
if ( Array . isArray ( target ) ) {
45
+ const pageScale = document . body . currentCSSZoom ?? 1
46
+ const factor = 1 + ( 1 - pageScale ) / pageScale
47
+
40
48
return new Box ( {
41
- x : target [ 0 ] ,
42
- y : target [ 1 ] ,
43
- width : 0 ,
44
- height : 0 ,
49
+ x : target [ 0 ] * factor ,
50
+ y : target [ 1 ] * factor ,
51
+ width : 0 * factor ,
52
+ height : 0 * factor ,
45
53
} )
46
54
} else {
47
- return target . getBoundingClientRect ( )
55
+ return new Box ( target . getBoundingClientRect ( ) )
48
56
}
49
57
}
50
58
@@ -58,11 +66,12 @@ export function getElementBox (el: HTMLElement) {
58
66
height : document . documentElement . clientHeight ,
59
67
} )
60
68
} else {
69
+ const pageScale = document . body . currentCSSZoom ?? 1
61
70
return new Box ( {
62
71
x : visualViewport . scale > 1 ? 0 : visualViewport . offsetLeft ,
63
72
y : visualViewport . scale > 1 ? 0 : visualViewport . offsetTop ,
64
- width : visualViewport . width * visualViewport . scale ,
65
- height : visualViewport . height * visualViewport . scale ,
73
+ width : visualViewport . width * visualViewport . scale / pageScale ,
74
+ height : visualViewport . height * visualViewport . scale / pageScale ,
66
75
} )
67
76
}
68
77
} else {
0 commit comments