@@ -127,7 +127,7 @@ function getContainerDimensions(containerNode: Element): Dimensions {
127127 left = visualViewport . offsetLeft ;
128128 }
129129 } else {
130- ( { width, height, top, left} = getOffset ( containerNode ) ) ;
130+ ( { width, height, top, left} = getOffset ( containerNode , false ) ) ;
131131 scroll . top = containerNode . scrollTop ;
132132 scroll . left = containerNode . scrollLeft ;
133133 totalWidth = width ;
@@ -488,15 +488,15 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
488488 let isViewportContainer = container === document . documentElement ;
489489 const containerPositionStyle = window . getComputedStyle ( container ) . position ;
490490 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 ) ;
492492
493493 if ( ! isViewportContainer ) {
494494 let { marginTop, marginLeft} = window . getComputedStyle ( targetNode ) ;
495495 childOffset . top += parseInt ( marginTop , 10 ) || 0 ;
496496 childOffset . left += parseInt ( marginLeft , 10 ) || 0 ;
497497 }
498498
499- let overlaySize : Offset = getOffset ( overlayNode ) ;
499+ let overlaySize : Offset = getOffset ( overlayNode , true ) ;
500500 let margins = getMargins ( overlayNode ) ;
501501 overlaySize . width += ( margins . left ?? 0 ) + ( margins . right ?? 0 ) ;
502502 overlaySize . height += ( margins . top ?? 0 ) + ( margins . bottom ?? 0 ) ;
@@ -507,7 +507,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
507507 // If the container is the HTML element wrapping the body element, the retrieved scrollTop/scrollLeft will be equal to the
508508 // 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
509509 // 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 ) ;
511511 if ( container . tagName === 'HTML' && boundaryElement . tagName === 'BODY' ) {
512512 containerDimensions . scroll . top = 0 ;
513513 containerDimensions . scroll . left = 0 ;
@@ -533,8 +533,21 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
533533 ) ;
534534}
535535
536- function getOffset ( node : Element ) : Offset {
536+ export function getRect ( node : Element , ignoreScale : boolean ) {
537537 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 ) ;
538551 let { scrollTop, scrollLeft, clientTop, clientLeft} = document . documentElement ;
539552 return {
540553 top : top + scrollTop - clientTop ,
@@ -544,15 +557,14 @@ function getOffset(node: Element): Offset {
544557 } ;
545558}
546559
547- function getPosition ( node : Element , parent : Element ) : Offset {
560+ function getPosition ( node : Element , parent : Element , ignoreScale : boolean ) : Offset {
548561 let style = window . getComputedStyle ( node ) ;
549562 let offset : Offset ;
550563 if ( style . position === 'fixed' ) {
551- let { top, left, width, height} = node . getBoundingClientRect ( ) ;
552- offset = { top, left, width, height} ;
564+ offset = getRect ( node , ignoreScale ) ;
553565 } else {
554- offset = getOffset ( node ) ;
555- let parentOffset = getOffset ( parent ) ;
566+ offset = getOffset ( node , ignoreScale ) ;
567+ let parentOffset = getOffset ( parent , ignoreScale ) ;
556568 let parentStyle = window . getComputedStyle ( parent ) ;
557569 parentOffset . top += ( parseInt ( parentStyle . borderTopWidth , 10 ) || 0 ) - parent . scrollTop ;
558570 parentOffset . left += ( parseInt ( parentStyle . borderLeftWidth , 10 ) || 0 ) - parent . scrollLeft ;
0 commit comments