@@ -14,7 +14,7 @@ export interface SmoothBehaviorOptions extends Options {
1414}
1515
1616// Memoize so we're much more friendly to non-dom envs
17- let memoizedNow
17+ let memoizedNow : ( ) => number
1818const now = ( ) => {
1919 if ( ! memoizedNow ) {
2020 memoizedNow =
@@ -23,7 +23,19 @@ const now = () => {
2323 return memoizedNow ( )
2424}
2525
26- function step ( context ) {
26+ type Context = {
27+ scrollable : Element
28+ method : Function
29+ startTime : number
30+ startX : number
31+ startY : number
32+ x : number
33+ y : number
34+ duration : number
35+ ease : CustomEasing
36+ cb : Function
37+ }
38+ function step ( context : Context ) {
2739 const time = now ( )
2840 const elapsed = Math . min ( ( time - context . startTime ) / context . duration , 1 )
2941
@@ -42,33 +54,26 @@ function step(context) {
4254}
4355
4456function smoothScroll (
45- el ,
46- x ,
47- y ,
48- duration = 450 ,
49- ease = t => 1 + -- t * t * t * t * t ,
50- cb
57+ el : Element ,
58+ x : number ,
59+ y : number ,
60+ duration = 600 ,
61+ ease : CustomEasing = t => 1 + -- t * t * t * t * t ,
62+ cb : Function
5163) {
5264 let scrollable
5365 let startX
5466 let startY
5567 let method
5668
5769 // define scroll context
58- if ( el === document . documentElement ) {
59- scrollable = window
60- startX = window . scrollX || window . pageXOffset
61- startY = window . scrollY || window . pageYOffset
62- method = ( x , y ) => window . scroll ( x , y )
63- } else {
64- scrollable = el
65- startX = el . scrollLeft
66- startY = el . scrollTop
67- method = ( x , y ) => {
68- // @TODO use Element.scroll if it exists, as it is potentially better performing
69- el . scrollLeft = x
70- el . scrollTop = y
71- }
70+ scrollable = el
71+ startX = el . scrollLeft
72+ startY = el . scrollTop
73+ method = ( x : number , y : number ) => {
74+ // @TODO use Element.scroll if it exists, as it is potentially better performing
75+ el . scrollLeft = x
76+ el . scrollTop = y
7277 }
7378
7479 // scroll looping over a frame
@@ -93,7 +98,7 @@ const shouldSmoothScroll = <T>(options: any): options is T => {
9398function scroll ( target : Element , options ?: SmoothBehaviorOptions ) : Promise < any >
9499function scroll < T > ( target : Element , options : CustomBehaviorOptions < T > ) : T
95100function scroll ( target : Element , options : StandardBehaviorOptions ) : void
96- function scroll < T > ( target , options ) {
101+ function scroll < T > ( target : Element , options ?: any ) {
97102 if ( shouldSmoothScroll < SmoothBehaviorOptions > ( options ) ) {
98103 const overrides = options || { }
99104 // @TODO replace <any> in promise signatures with better information
0 commit comments