Skip to content

Commit d6f778d

Browse files
authored
fix: use const replace let (#889)
1 parent 0c45c0a commit d6f778d

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/index.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ export interface ScrollAction {
7575
}
7676

7777
// @TODO better shadowdom test, 11 = document fragment
78-
let isElement = (el: any): el is Element =>
78+
const isElement = (el: any): el is Element =>
7979
typeof el === 'object' && el != null && el.nodeType === 1
8080

81-
let canOverflow = (
81+
const canOverflow = (
8282
overflow: string | null,
8383
skipOverflowHiddenElements?: boolean
8484
) => {
@@ -89,7 +89,7 @@ let canOverflow = (
8989
return overflow !== 'visible' && overflow !== 'clip'
9090
}
9191

92-
let getFrameElement = (el: Element) => {
92+
const getFrameElement = (el: Element) => {
9393
if (!el.ownerDocument || !el.ownerDocument.defaultView) {
9494
return null
9595
}
@@ -101,8 +101,8 @@ let getFrameElement = (el: Element) => {
101101
}
102102
}
103103

104-
let isHiddenByFrame = (el: Element): boolean => {
105-
let frame = getFrameElement(el)
104+
const isHiddenByFrame = (el: Element): boolean => {
105+
const frame = getFrameElement(el)
106106
if (!frame) {
107107
return false
108108
}
@@ -112,9 +112,9 @@ let isHiddenByFrame = (el: Element): boolean => {
112112
)
113113
}
114114

115-
let isScrollable = (el: Element, skipOverflowHiddenElements?: boolean) => {
115+
const isScrollable = (el: Element, skipOverflowHiddenElements?: boolean) => {
116116
if (el.clientHeight < el.scrollHeight || el.clientWidth < el.scrollWidth) {
117-
let style = getComputedStyle(el, null)
117+
const style = getComputedStyle(el, null)
118118
return (
119119
canOverflow(style.overflowY, skipOverflowHiddenElements) ||
120120
canOverflow(style.overflowX, skipOverflowHiddenElements) ||
@@ -133,7 +133,7 @@ let isScrollable = (el: Element, skipOverflowHiddenElements?: boolean) => {
133133
* │ target │ frame
134134
* └────────┘ ┗ ━ ━ ━ ┛
135135
*/
136-
let alignNearest = (
136+
const alignNearest = (
137137
scrollingEdgeStart: number,
138138
scrollingEdgeEnd: number,
139139
scrollingSize: number,
@@ -266,38 +266,38 @@ let alignNearest = (
266266
return 0
267267
}
268268

269-
let getParentElement = (element: Node): Element | null => {
270-
let parent = element.parentElement
269+
const getParentElement = (element: Node): Element | null => {
270+
const parent = element.parentElement
271271
if (parent == null) {
272272
return (element.getRootNode() as ShadowRoot).host || null
273273
}
274274
return parent
275275
}
276276

277277
/** @public */
278-
export let compute = (target: Element, options: Options): ScrollAction[] => {
278+
export const compute = (target: Element, options: Options): ScrollAction[] => {
279279
if (typeof document === 'undefined') {
280280
// If there's no DOM we assume it's not in a browser environment
281281
return []
282282
}
283283

284-
let { scrollMode, block, inline, boundary, skipOverflowHiddenElements } =
284+
const { scrollMode, block, inline, boundary, skipOverflowHiddenElements } =
285285
options
286286
// Allow using a callback to check the boundary
287287
// The default behavior is to check if the current target matches the boundary element or not
288288
// If undefined it'll check that target is never undefined (can happen as we recurse up the tree)
289-
let checkBoundary =
289+
const checkBoundary =
290290
typeof boundary === 'function' ? boundary : (node: any) => node !== boundary
291291

292292
if (!isElement(target)) {
293293
throw new TypeError('Invalid target')
294294
}
295295

296296
// 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
298298

299299
// 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[] = []
301301
let cursor: Element | null = target
302302
while (isElement(cursor) && checkBoundary(cursor)) {
303303
// Move cursor to parent
@@ -330,11 +330,11 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
330330
// and viewport dimensions on window.innerWidth/Height
331331
// https://www.quirksmode.org/mobile/viewports2.html
332332
// 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
336336

337-
let {
337+
const {
338338
height: targetHeight,
339339
width: targetWidth,
340340
top: targetTop,
@@ -358,14 +358,14 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
358358
: targetLeft // inline === 'start || inline === 'nearest
359359

360360
// Collect new scroll positions
361-
let computations: ScrollAction[] = []
361+
const computations: ScrollAction[] = []
362362
// 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)
363363
for (let index = 0; index < frames.length; index++) {
364-
let frame = frames[index]
364+
const frame = frames[index]
365365

366366
// @TODO add a shouldScroll hook here that allows userland code to take control
367367

368-
let { height, width, top, right, bottom, left } =
368+
const { height, width, top, right, bottom, left } =
369369
frame.getBoundingClientRect()
370370

371371
// If the element is already visible we can end it here
@@ -385,39 +385,39 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
385385
return computations
386386
}
387387

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)
393393

394394
let blockScroll: number = 0
395395
let inlineScroll: number = 0
396396

397397
// The property existance checks for offfset[Width|Height] is because only HTMLElement objects have them, but any Element might pass by here
398398
// @TODO find out if the "as HTMLElement" overrides can be dropped
399-
let scrollbarWidth =
399+
const scrollbarWidth =
400400
'offsetWidth' in frame
401401
? (frame as HTMLElement).offsetWidth -
402402
(frame as HTMLElement).clientWidth -
403403
borderLeft -
404404
borderRight
405405
: 0
406-
let scrollbarHeight =
406+
const scrollbarHeight =
407407
'offsetHeight' in frame
408408
? (frame as HTMLElement).offsetHeight -
409409
(frame as HTMLElement).clientHeight -
410410
borderTop -
411411
borderBottom
412412
: 0
413413

414-
let scaleX =
414+
const scaleX =
415415
'offsetWidth' in frame
416416
? (frame as HTMLElement).offsetWidth === 0
417417
? 0
418418
: width / (frame as HTMLElement).offsetWidth
419419
: 0
420-
let scaleY =
420+
const scaleY =
421421
'offsetHeight' in frame
422422
? (frame as HTMLElement).offsetHeight === 0
423423
? 0
@@ -513,7 +513,7 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
513513
)
514514
}
515515

516-
let { scrollLeft, scrollTop } = frame
516+
const { scrollLeft, scrollTop } = frame
517517
// Ensure scroll coordinates are not out of bounds while applying scroll offsets
518518
blockScroll = Math.max(
519519
0,

0 commit comments

Comments
 (0)