@@ -332,10 +332,7 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
332332 // https://bokand.github.io/viewport/index.html
333333 let viewportWidth = window . visualViewport ?. width ?? innerWidth
334334 let viewportHeight = window . visualViewport ?. height ?? innerHeight
335-
336- // Newer browsers supports scroll[X|Y], page[X|Y]Offset is
337- let viewportX = window . scrollX ?? pageXOffset
338- let viewportY = window . scrollY ?? pageYOffset
335+ let { scrollX, scrollY } = window
339336
340337 let {
341338 height : targetHeight ,
@@ -436,13 +433,13 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
436433 blockScroll = targetBlock - viewportHeight
437434 } else if ( block === 'nearest' ) {
438435 blockScroll = alignNearest (
439- viewportY ,
440- viewportY + viewportHeight ,
436+ scrollY ,
437+ scrollY + viewportHeight ,
441438 viewportHeight ,
442439 borderTop ,
443440 borderBottom ,
444- viewportY + targetBlock ,
445- viewportY + targetBlock + targetHeight ,
441+ scrollY + targetBlock ,
442+ scrollY + targetBlock + targetHeight ,
446443 targetHeight
447444 )
448445 } else {
@@ -459,24 +456,23 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
459456 } else {
460457 // inline === 'nearest' is the default
461458 inlineScroll = alignNearest (
462- viewportX ,
463- viewportX + viewportWidth ,
459+ scrollX ,
460+ scrollX + viewportWidth ,
464461 viewportWidth ,
465462 borderLeft ,
466463 borderRight ,
467- viewportX + targetInline ,
468- viewportX + targetInline + targetWidth ,
464+ scrollX + targetInline ,
465+ scrollX + targetInline + targetWidth ,
469466 targetWidth
470467 )
471468 }
472469
473470 // Apply scroll position offsets and ensure they are within bounds
474471 // @TODO add more test cases to cover this 100%
475- blockScroll = Math . max ( 0 , blockScroll + viewportY )
476- inlineScroll = Math . max ( 0 , inlineScroll + viewportX )
472+ blockScroll = Math . max ( 0 , blockScroll + scrollY )
473+ inlineScroll = Math . max ( 0 , inlineScroll + scrollX )
477474 } else {
478475 // Handle each scrolling frame that might exist between the target and the viewport
479-
480476 if ( block === 'start' ) {
481477 blockScroll = targetBlock - top - borderTop
482478 } else if ( block === 'end' ) {
0 commit comments