14
14
15
15
import { parseLength } from './utils' ;
16
16
17
+ const ORIENTATIONS = new Set ( )
18
+
17
19
let scrollTimelineOptions = new WeakMap ( ) ;
18
20
19
21
function scrollEventSource ( scrollSource ) {
@@ -22,8 +24,8 @@ function scrollEventSource(scrollSource) {
22
24
return scrollSource ;
23
25
}
24
26
25
- function calculateTargetEffectEnd ( options ) {
26
- if ( options . iterationCount == Infinity )
27
+ export function calculateTargetEffectEnd ( options ) {
28
+ if ( options . iterationCount === Infinity )
27
29
return Infinity ;
28
30
return Math . max ( ( options . startDelay || 0 ) + ( options . duration || 0 ) * ( options . iterationCount || 1 ) + ( options . endDelay || 0 ) , 0 ) ;
29
31
}
@@ -34,62 +36,62 @@ export function installScrollOffsetExtension(parseFunction, evaluateFunction) {
34
36
extensionScrollOffsetFunctions . push ( [ parseFunction , evaluateFunction ] ) ;
35
37
}
36
38
37
- function calculateMaxScrollOffset ( scrollSource , orientation ) {
39
+ export function calculateMaxScrollOffset ( scrollSource , orientation ) {
38
40
// TODO: Support other writing directions.
39
- if ( orientation == 'block' )
41
+ if ( orientation === 'block' )
40
42
orientation = 'vertical' ;
41
- else if ( orientation == 'inline' )
43
+ else if ( orientation === 'inline' )
42
44
orientation = 'horizontal' ;
43
- if ( orientation == 'vertical' )
45
+ if ( orientation === 'vertical' )
44
46
return scrollSource . scrollHeight - scrollSource . clientHeight ;
45
- else if ( orientation == 'horizontal' )
47
+ else if ( orientation === 'horizontal' )
46
48
return scrollSource . scrollWidth - scrollSource . clientWidth ;
47
49
48
50
}
49
51
50
52
function calculateScrollOffset ( autoValue , scrollSource , orientation , offset , fn ) {
51
53
if ( fn )
52
- return fn ( scrollSource , orientation , offset , autoValue == '0%' ? 'start' : 'end' ) ;
54
+ return fn ( scrollSource , orientation , offset , autoValue === '0%' ? 'start' : 'end' ) ;
53
55
// TODO: Support other writing directions.
54
- if ( orientation == 'block' )
56
+ if ( orientation === 'block' )
55
57
orientation = 'vertical' ;
56
- else if ( orientation == 'inline' )
58
+ else if ( orientation === 'inline' )
57
59
orientation = 'horizontal' ;
58
60
59
- let maxValue = orientation == 'vertical' ?
61
+ let maxValue = orientation === 'vertical' ?
60
62
scrollSource . scrollHeight - scrollSource . clientHeight :
61
63
scrollSource . scrollWidth - scrollSource . clientWidth ;
62
- let parsed = parseLength ( offset == 'auto' ? autoValue : offset ) ;
63
- if ( parsed [ 2 ] == '%' )
64
+ let parsed = parseLength ( offset === 'auto' ? autoValue : offset ) ;
65
+ if ( parsed [ 2 ] === '%' )
64
66
return parseFloat ( parsed [ 1 ] ) * maxValue / 100 ;
65
67
return parseFloat ( parsed [ 1 ] ) ;
66
68
}
67
69
68
70
function calculateTimeRange ( scrollTimeline ) {
69
71
let timeRange = scrollTimeline . timeRange ;
70
- if ( timeRange == 'auto' ) {
72
+ if ( timeRange === 'auto' ) {
71
73
timeRange = 0 ;
72
74
let options = scrollTimelineOptions . get ( scrollTimeline ) . animationOptions ;
73
75
for ( let i = 0 ; i < options . length ; i ++ ) {
74
76
timeRange = Math . max ( timeRange , calculateTargetEffectEnd ( options [ i ] ) ) ;
75
77
}
76
- if ( timeRange == Infinity )
78
+ if ( timeRange === Infinity )
77
79
timeRange = 0 ;
78
80
}
79
81
return timeRange ;
80
82
}
81
83
82
84
function updateInternal ( ) {
83
85
let animations = scrollTimelineOptions . get ( this ) . animations ;
84
- if ( animations . length == 0 )
86
+ if ( animations . length === 0 )
85
87
return ;
86
88
let currentTime = this . currentTime ;
87
89
for ( let i = 0 ; i < animations . length ; i ++ ) {
88
90
// The web-animations spec says to throw a TypeError if you try to seek to
89
91
// an unresolved time value from a resolved time value, so to polyfill the
90
92
// expected behavior we cancel the underlying animation.
91
93
if ( currentTime == null ) {
92
- if ( animations [ i ] . playState == 'paused' )
94
+ if ( animations [ i ] . playState === 'paused' )
93
95
animations [ i ] . cancel ( ) ;
94
96
} else {
95
97
animations [ i ] . currentTime = currentTime ;
@@ -108,7 +110,7 @@ function addAnimation(scrollTimeline, animation, options) {
108
110
function removeAnimation ( scrollTimeline , animation ) {
109
111
let animations = scrollTimelineOptions . get ( scrollTimeline ) . animations ;
110
112
let index = animations . indexOf ( animation ) ;
111
- if ( index == - 1 )
113
+ if ( index === - 1 )
112
114
return ;
113
115
animations . splice ( index , 1 ) ;
114
116
scrollTimelineOptions . get ( scrollTimeline ) . animationOptions . splice ( index , 1 ) ;
0 commit comments