Skip to content

Commit 32242a3

Browse files
authored
feat(locationStrategies): support CSS zoom (#21878)
fixes #20719
1 parent ffe0501 commit 32242a3

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

packages/vuetify/src/util/animation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Box } from '@/util/box'
33

44
/** @see https://stackoverflow.com/a/57876601/2074736 */
55
export function nullifyTransforms (el: HTMLElement): Box {
6-
const rect = el.getBoundingClientRect()
6+
const rect = new Box(el.getBoundingClientRect())
77
const style = getComputedStyle(el)
88
const tx = style.transform
99

packages/vuetify/src/util/box.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@ export class Box {
44
width: number
55
height: number
66

7-
constructor ({ x, y, width, height }: {
7+
constructor (args: DOMRect | {
88
x: number
99
y: number
1010
width: number
1111
height: number
1212
}) {
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
1722
}
1823

1924
get top () { return this.y }
@@ -37,14 +42,17 @@ export function getOverflow (a: Box, b: Box) {
3742

3843
export function getTargetBox (target: HTMLElement | [x: number, y: number]): Box {
3944
if (Array.isArray(target)) {
45+
const pageScale = document.body.currentCSSZoom ?? 1
46+
const factor = 1 + (1 - pageScale) / pageScale
47+
4048
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,
4553
})
4654
} else {
47-
return target.getBoundingClientRect()
55+
return new Box(target.getBoundingClientRect())
4856
}
4957
}
5058

@@ -58,11 +66,12 @@ export function getElementBox (el: HTMLElement) {
5866
height: document.documentElement.clientHeight,
5967
})
6068
} else {
69+
const pageScale = document.body.currentCSSZoom ?? 1
6170
return new Box({
6271
x: visualViewport.scale > 1 ? 0 : visualViewport.offsetLeft,
6372
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,
6675
})
6776
}
6877
} else {

0 commit comments

Comments
 (0)