@@ -75,10 +75,10 @@ export interface ScrollAction {
75
75
}
76
76
77
77
// @TODO better shadowdom test, 11 = document fragment
78
- let isElement = ( el : any ) : el is Element =>
78
+ const isElement = ( el : any ) : el is Element =>
79
79
typeof el === 'object' && el != null && el . nodeType === 1
80
80
81
- let canOverflow = (
81
+ const canOverflow = (
82
82
overflow : string | null ,
83
83
skipOverflowHiddenElements ?: boolean
84
84
) => {
@@ -89,7 +89,7 @@ let canOverflow = (
89
89
return overflow !== 'visible' && overflow !== 'clip'
90
90
}
91
91
92
- let getFrameElement = ( el : Element ) => {
92
+ const getFrameElement = ( el : Element ) => {
93
93
if ( ! el . ownerDocument || ! el . ownerDocument . defaultView ) {
94
94
return null
95
95
}
@@ -101,8 +101,8 @@ let getFrameElement = (el: Element) => {
101
101
}
102
102
}
103
103
104
- let isHiddenByFrame = ( el : Element ) : boolean => {
105
- let frame = getFrameElement ( el )
104
+ const isHiddenByFrame = ( el : Element ) : boolean => {
105
+ const frame = getFrameElement ( el )
106
106
if ( ! frame ) {
107
107
return false
108
108
}
@@ -112,9 +112,9 @@ let isHiddenByFrame = (el: Element): boolean => {
112
112
)
113
113
}
114
114
115
- let isScrollable = ( el : Element , skipOverflowHiddenElements ?: boolean ) => {
115
+ const isScrollable = ( el : Element , skipOverflowHiddenElements ?: boolean ) => {
116
116
if ( el . clientHeight < el . scrollHeight || el . clientWidth < el . scrollWidth ) {
117
- let style = getComputedStyle ( el , null )
117
+ const style = getComputedStyle ( el , null )
118
118
return (
119
119
canOverflow ( style . overflowY , skipOverflowHiddenElements ) ||
120
120
canOverflow ( style . overflowX , skipOverflowHiddenElements ) ||
@@ -133,7 +133,7 @@ let isScrollable = (el: Element, skipOverflowHiddenElements?: boolean) => {
133
133
* │ target │ frame
134
134
* └────────┘ ┗ ━ ━ ━ ┛
135
135
*/
136
- let alignNearest = (
136
+ const alignNearest = (
137
137
scrollingEdgeStart : number ,
138
138
scrollingEdgeEnd : number ,
139
139
scrollingSize : number ,
@@ -266,38 +266,38 @@ let alignNearest = (
266
266
return 0
267
267
}
268
268
269
- let getParentElement = ( element : Node ) : Element | null => {
270
- let parent = element . parentElement
269
+ const getParentElement = ( element : Node ) : Element | null => {
270
+ const parent = element . parentElement
271
271
if ( parent == null ) {
272
272
return ( element . getRootNode ( ) as ShadowRoot ) . host || null
273
273
}
274
274
return parent
275
275
}
276
276
277
277
/** @public */
278
- export let compute = ( target : Element , options : Options ) : ScrollAction [ ] => {
278
+ export const compute = ( target : Element , options : Options ) : ScrollAction [ ] => {
279
279
if ( typeof document === 'undefined' ) {
280
280
// If there's no DOM we assume it's not in a browser environment
281
281
return [ ]
282
282
}
283
283
284
- let { scrollMode, block, inline, boundary, skipOverflowHiddenElements } =
284
+ const { scrollMode, block, inline, boundary, skipOverflowHiddenElements } =
285
285
options
286
286
// Allow using a callback to check the boundary
287
287
// The default behavior is to check if the current target matches the boundary element or not
288
288
// If undefined it'll check that target is never undefined (can happen as we recurse up the tree)
289
- let checkBoundary =
289
+ const checkBoundary =
290
290
typeof boundary === 'function' ? boundary : ( node : any ) => node !== boundary
291
291
292
292
if ( ! isElement ( target ) ) {
293
293
throw new TypeError ( 'Invalid target' )
294
294
}
295
295
296
296
// Used to handle the top most element that can be scrolled
297
- let scrollingElement = document . scrollingElement || document . documentElement
297
+ const scrollingElement = document . scrollingElement || document . documentElement
298
298
299
299
// Collect all the scrolling boxes, as defined in the spec: https://drafts.csswg.org/cssom-view/#scrolling-box
300
- let frames : Element [ ] = [ ]
300
+ const frames : Element [ ] = [ ]
301
301
let cursor : Element | null = target
302
302
while ( isElement ( cursor ) && checkBoundary ( cursor ) ) {
303
303
// Move cursor to parent
@@ -330,11 +330,11 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
330
330
// and viewport dimensions on window.innerWidth/Height
331
331
// https://www.quirksmode.org/mobile/viewports2.html
332
332
// https://bokand.github.io/viewport/index.html
333
- let viewportWidth = window . visualViewport ?. width ?? innerWidth
334
- let viewportHeight = window . visualViewport ?. height ?? innerHeight
335
- let { scrollX, scrollY } = window
333
+ const viewportWidth = window . visualViewport ?. width ?? innerWidth
334
+ const viewportHeight = window . visualViewport ?. height ?? innerHeight
335
+ const { scrollX, scrollY } = window
336
336
337
- let {
337
+ const {
338
338
height : targetHeight ,
339
339
width : targetWidth ,
340
340
top : targetTop ,
@@ -358,14 +358,14 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
358
358
: targetLeft // inline === 'start || inline === 'nearest
359
359
360
360
// Collect new scroll positions
361
- let computations : ScrollAction [ ] = [ ]
361
+ const computations : ScrollAction [ ] = [ ]
362
362
// In chrome there's no longer a difference between caching the `frames.length` to a var or not, so we don't in this case (size > speed anyways)
363
363
for ( let index = 0 ; index < frames . length ; index ++ ) {
364
- let frame = frames [ index ]
364
+ const frame = frames [ index ]
365
365
366
366
// @TODO add a shouldScroll hook here that allows userland code to take control
367
367
368
- let { height, width, top, right, bottom, left } =
368
+ const { height, width, top, right, bottom, left } =
369
369
frame . getBoundingClientRect ( )
370
370
371
371
// If the element is already visible we can end it here
@@ -385,39 +385,39 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
385
385
return computations
386
386
}
387
387
388
- let frameStyle = getComputedStyle ( frame )
389
- let borderLeft = parseInt ( frameStyle . borderLeftWidth as string , 10 )
390
- let borderTop = parseInt ( frameStyle . borderTopWidth as string , 10 )
391
- let borderRight = parseInt ( frameStyle . borderRightWidth as string , 10 )
392
- let borderBottom = parseInt ( frameStyle . borderBottomWidth as string , 10 )
388
+ const frameStyle = getComputedStyle ( frame )
389
+ const borderLeft = parseInt ( frameStyle . borderLeftWidth as string , 10 )
390
+ const borderTop = parseInt ( frameStyle . borderTopWidth as string , 10 )
391
+ const borderRight = parseInt ( frameStyle . borderRightWidth as string , 10 )
392
+ const borderBottom = parseInt ( frameStyle . borderBottomWidth as string , 10 )
393
393
394
394
let blockScroll : number = 0
395
395
let inlineScroll : number = 0
396
396
397
397
// The property existance checks for offfset[Width|Height] is because only HTMLElement objects have them, but any Element might pass by here
398
398
// @TODO find out if the "as HTMLElement" overrides can be dropped
399
- let scrollbarWidth =
399
+ const scrollbarWidth =
400
400
'offsetWidth' in frame
401
401
? ( frame as HTMLElement ) . offsetWidth -
402
402
( frame as HTMLElement ) . clientWidth -
403
403
borderLeft -
404
404
borderRight
405
405
: 0
406
- let scrollbarHeight =
406
+ const scrollbarHeight =
407
407
'offsetHeight' in frame
408
408
? ( frame as HTMLElement ) . offsetHeight -
409
409
( frame as HTMLElement ) . clientHeight -
410
410
borderTop -
411
411
borderBottom
412
412
: 0
413
413
414
- let scaleX =
414
+ const scaleX =
415
415
'offsetWidth' in frame
416
416
? ( frame as HTMLElement ) . offsetWidth === 0
417
417
? 0
418
418
: width / ( frame as HTMLElement ) . offsetWidth
419
419
: 0
420
- let scaleY =
420
+ const scaleY =
421
421
'offsetHeight' in frame
422
422
? ( frame as HTMLElement ) . offsetHeight === 0
423
423
? 0
@@ -513,7 +513,7 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
513
513
)
514
514
}
515
515
516
- let { scrollLeft, scrollTop } = frame
516
+ const { scrollLeft, scrollTop } = frame
517
517
// Ensure scroll coordinates are not out of bounds while applying scroll offsets
518
518
blockScroll = Math . max (
519
519
0 ,
0 commit comments