@@ -127,7 +127,7 @@ function getContainerDimensions(containerNode: Element): Dimensions {
127
127
left = visualViewport . offsetLeft ;
128
128
}
129
129
} else {
130
- ( { width, height, top, left} = getOffset ( containerNode ) ) ;
130
+ ( { width, height, top, left} = getOffset ( containerNode , false ) ) ;
131
131
scroll . top = containerNode . scrollTop ;
132
132
scroll . left = containerNode . scrollLeft ;
133
133
totalWidth = width ;
@@ -488,15 +488,15 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
488
488
let isViewportContainer = container === document . documentElement ;
489
489
const containerPositionStyle = window . getComputedStyle ( container ) . position ;
490
490
let isContainerPositioned = ! ! containerPositionStyle && containerPositionStyle !== 'static' ;
491
- let childOffset : Offset = isViewportContainer ? getOffset ( targetNode ) : getPosition ( targetNode , container ) ;
491
+ let childOffset : Offset = isViewportContainer ? getOffset ( targetNode , false ) : getPosition ( targetNode , container , false ) ;
492
492
493
493
if ( ! isViewportContainer ) {
494
494
let { marginTop, marginLeft} = window . getComputedStyle ( targetNode ) ;
495
495
childOffset . top += parseInt ( marginTop , 10 ) || 0 ;
496
496
childOffset . left += parseInt ( marginLeft , 10 ) || 0 ;
497
497
}
498
498
499
- let overlaySize : Offset = getOffset ( overlayNode ) ;
499
+ let overlaySize : Offset = getOffset ( overlayNode , true ) ;
500
500
let margins = getMargins ( overlayNode ) ;
501
501
overlaySize . width += ( margins . left ?? 0 ) + ( margins . right ?? 0 ) ;
502
502
overlaySize . height += ( margins . top ?? 0 ) + ( margins . bottom ?? 0 ) ;
@@ -507,7 +507,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
507
507
// If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
508
508
// body element's scroll. Set the container's scroll values to 0 since the overlay's edge position value in getDelta don't then need to be further offset
509
509
// by the container scroll since they are essentially the same containing element and thus in the same coordinate system
510
- let containerOffsetWithBoundary : Offset = boundaryElement . tagName === 'BODY' ? getOffset ( container ) : getPosition ( container , boundaryElement ) ;
510
+ let containerOffsetWithBoundary : Offset = boundaryElement . tagName === 'BODY' ? getOffset ( container , false ) : getPosition ( container , boundaryElement , false ) ;
511
511
if ( container . tagName === 'HTML' && boundaryElement . tagName === 'BODY' ) {
512
512
containerDimensions . scroll . top = 0 ;
513
513
containerDimensions . scroll . left = 0 ;
@@ -533,8 +533,21 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
533
533
) ;
534
534
}
535
535
536
- function getOffset ( node : Element ) : Offset {
536
+ export function getRect ( node : Element , ignoreScale : boolean ) {
537
537
let { top, left, width, height} = node . getBoundingClientRect ( ) ;
538
+
539
+ // Use offsetWidth and offsetHeight if this is an HTML element, so that
540
+ // the size is not affected by scale transforms.
541
+ if ( ignoreScale && node instanceof node . ownerDocument . defaultView ! . HTMLElement ) {
542
+ width = node . offsetWidth ;
543
+ height = node . offsetHeight ;
544
+ }
545
+
546
+ return { top, left, width, height} ;
547
+ }
548
+
549
+ function getOffset ( node : Element , ignoreScale : boolean ) : Offset {
550
+ let { top, left, width, height} = getRect ( node , ignoreScale ) ;
538
551
let { scrollTop, scrollLeft, clientTop, clientLeft} = document . documentElement ;
539
552
return {
540
553
top : top + scrollTop - clientTop ,
@@ -544,15 +557,14 @@ function getOffset(node: Element): Offset {
544
557
} ;
545
558
}
546
559
547
- function getPosition ( node : Element , parent : Element ) : Offset {
560
+ function getPosition ( node : Element , parent : Element , ignoreScale : boolean ) : Offset {
548
561
let style = window . getComputedStyle ( node ) ;
549
562
let offset : Offset ;
550
563
if ( style . position === 'fixed' ) {
551
- let { top, left, width, height} = node . getBoundingClientRect ( ) ;
552
- offset = { top, left, width, height} ;
564
+ offset = getRect ( node , ignoreScale ) ;
553
565
} else {
554
- offset = getOffset ( node ) ;
555
- let parentOffset = getOffset ( parent ) ;
566
+ offset = getOffset ( node , ignoreScale ) ;
567
+ let parentOffset = getOffset ( parent , ignoreScale ) ;
556
568
let parentStyle = window . getComputedStyle ( parent ) ;
557
569
parentOffset . top += ( parseInt ( parentStyle . borderTopWidth , 10 ) || 0 ) - parent . scrollTop ;
558
570
parentOffset . left += ( parseInt ( parentStyle . borderLeftWidth , 10 ) || 0 ) - parent . scrollLeft ;
0 commit comments