@@ -11,8 +11,6 @@ const borderColor = "#ccc";
11
11
const Wrapper = styled ( Box , {
12
12
position : "relative" ,
13
13
alignSelf : "stretch" ,
14
- // borderRight: `1px solid ${borderColor}`,
15
- // borderLeft: `1px solid ${borderColor}`,
16
14
} ) ;
17
15
18
16
const InsetLine = styled ( Box , {
@@ -34,8 +32,8 @@ const Scrollable = styled(Box, {
34
32
} ) ;
35
33
36
34
const bgKeyframes = keyframes ( {
37
- "0%" : { backgroundColor : "oklch(54.6% 0.245 262.881) " } ,
38
- "100%" : { backgroundColor : "oklch(58.6% 0.253 17.585) " } ,
35
+ "0%" : { "--progress" : "0 " } ,
36
+ "100%" : { "--progress" : "360 " } ,
39
37
} ) ;
40
38
41
39
const rafInterval = ( callback : ( ) => void ) : ( ( ) => void ) => {
@@ -58,6 +56,17 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
58
56
const subjectRef = useRef < HTMLDivElement > ( null ) ;
59
57
60
58
useEffect ( ( ) => {
59
+ try {
60
+ CSS . registerProperty ( {
61
+ name : "--progress" ,
62
+ syntax : "<number>" ,
63
+ inherits : true ,
64
+ initialValue : "0" ,
65
+ } ) ;
66
+ } catch {
67
+ /* */
68
+ }
69
+
61
70
const scrollable = scrollableRef . current ;
62
71
const subject = subjectRef . current ;
63
72
@@ -78,12 +87,12 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
78
87
const timeDelta = Date . now ( ) - startTime ;
79
88
80
89
scrollable . scrollTop =
81
- ( Math . sin ( timeDelta / 500 ) * ( scrollHeight - clientHeight ) ) / 2 +
90
+ ( Math . sin ( timeDelta / 1000 ) * ( scrollHeight - clientHeight ) ) / 2 +
82
91
( scrollHeight - clientHeight ) / 2 ;
83
92
84
93
const progress =
85
- subject . getAnimations ( ) ?. [ 0 ] ?. effect ?. getComputedTiming ( ) ?. progress ??
86
- 0 ;
94
+ subject . parentElement ?. getAnimations ( ) ?. [ 0 ] ?. effect ?. getComputedTiming ( )
95
+ ?. progress ?? 0 ;
87
96
88
97
const content = `${ ( progress * 100 ) . toFixed ( 0 ) } %` ;
89
98
@@ -110,6 +119,8 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
110
119
} ,
111
120
] ;
112
121
122
+ const progressRadius = "6px" ;
123
+
113
124
return (
114
125
< Wrapper >
115
126
< Scrollable ref = { scrollableRef } >
@@ -119,21 +130,10 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
119
130
} }
120
131
/>
121
132
< Box
122
- ref = { subjectRef }
123
133
css = { {
124
134
height : insetSize ,
125
135
marginLeft : 4 ,
126
136
marginRight : 4 ,
127
- // border: `1px solid ${borderColor}`,
128
-
129
- color : "white" ,
130
- fontSize : "12px" ,
131
- display : "flex" ,
132
- alignItems : "center" ,
133
- justifyContent : "center" ,
134
- whiteSpace : "pre" ,
135
- textAlign : "center" ,
136
- fontFamily : theme . fonts . robotoMono ,
137
137
138
138
animationName : `${ bgKeyframes } ` ,
139
139
animationTimingFunction : "linear" ,
@@ -142,8 +142,40 @@ export const AnimationRanges = (props: AnimationRangesProps) => {
142
142
animationRangeStart : `${ rangeStart [ 0 ] } ${ toValue ( rangeStart [ 1 ] ) } ` ,
143
143
animationRangeEnd : `${ rangeEnd [ 0 ] } ${ toValue ( rangeEnd [ 1 ] ) } ` ,
144
144
animationTimeline : `view(y ${ insetSize } )` ,
145
+
146
+ position : "relative" ,
147
+ borderRadius : progressRadius ,
145
148
} }
146
- />
149
+ >
150
+ < Box
151
+ css = { {
152
+ position : "absolute" ,
153
+ inset : 0 ,
154
+ borderRadius : progressRadius ,
155
+
156
+ background : `conic-gradient(oklch(54.6% 0.245 262.881) calc(var(--progress, 0) * 1deg), oklch(92.9% 0.013 255.508) 0)` ,
157
+ mask : `linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)` ,
158
+
159
+ maskComposite : `exclude` ,
160
+ padding : `4px` ,
161
+ } }
162
+ />
163
+
164
+ < Box
165
+ ref = { subjectRef }
166
+ css = { {
167
+ position : "absolute" ,
168
+ inset : 0 ,
169
+ fontSize : "12px" ,
170
+ display : "flex" ,
171
+ alignItems : "center" ,
172
+ justifyContent : "center" ,
173
+ whiteSpace : "pre" ,
174
+ textAlign : "center" ,
175
+ fontFamily : theme . fonts . robotoMono ,
176
+ } }
177
+ > </ Box >
178
+ </ Box >
147
179
< Box
148
180
css = { {
149
181
height : `calc(100% - ${ insetSize } )` ,
0 commit comments