|
165 | 165 | }
|
166 | 166 | };
|
167 | 167 |
|
168 |
| - function normalizeKeyframes(effectInput) { |
169 |
| - if (!Array.isArray(effectInput) && effectInput !== null) |
170 |
| - throw new TypeError('Keyframes must be null or an array of keyframes'); |
| 168 | + function convertToArrayForm(effectInput) { |
| 169 | + var normalizedEffectInput = []; |
| 170 | + |
| 171 | + for (var property in effectInput) { |
| 172 | + if (property in ['easing', 'offset', 'composite']) |
| 173 | + continue; |
| 174 | + |
| 175 | + var values = effectInput[property]; |
| 176 | + if (!Array.isArray(values)) |
| 177 | + values = [values]; |
| 178 | + |
| 179 | + var keyframe; |
| 180 | + var numKeyframes = values.length; |
| 181 | + for (var i = 0; i < numKeyframes; i++) { |
| 182 | + keyframe = {}; |
| 183 | + |
| 184 | + if ('offset' in effectInput) |
| 185 | + keyframe['offset'] = effectInput['offset']; |
| 186 | + else if (numKeyframes == 1) |
| 187 | + keyframe['offset'] = 1.0; |
| 188 | + else |
| 189 | + keyframe['offset'] = i / (numKeyframes - 1.0); |
| 190 | + |
| 191 | + if ('easing' in effectInput) |
| 192 | + keyframe['easing'] = effectInput['easing']; |
| 193 | + |
| 194 | + if ('composite' in effectInput) |
| 195 | + keyframe['composite'] = effectInput['composite']; |
| 196 | + |
| 197 | + keyframe[property] = values[i]; |
171 | 198 |
|
| 199 | + normalizedEffectInput.push(keyframe); |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + normalizedEffectInput.sort(function(a, b) { return a['offset'] - b['offset']; }); |
| 204 | + return normalizedEffectInput; |
| 205 | + }; |
| 206 | + |
| 207 | + function normalizeKeyframes(effectInput) { |
172 | 208 | if (effectInput == null)
|
173 | 209 | return [];
|
174 | 210 |
|
| 211 | + if (!Array.isArray(effectInput)) { |
| 212 | + effectInput = convertToArrayForm(effectInput); |
| 213 | + } |
| 214 | + |
175 | 215 | var keyframes = effectInput.map(function(originalKeyframe) {
|
176 | 216 | var keyframe = {};
|
177 | 217 | for (var member in originalKeyframe) {
|
|
250 | 290 | return keyframes;
|
251 | 291 | }
|
252 | 292 |
|
| 293 | + shared.convertToArrayForm = convertToArrayForm; |
253 | 294 | shared.normalizeKeyframes = normalizeKeyframes;
|
254 | 295 |
|
255 | 296 | if (WEB_ANIMATIONS_TESTING) {
|
|
0 commit comments