simplify animation tests and improve stability (#4250)
This will make sure that we tackle a few additional edge cases: - When the `name` is the same as a reserved keyword, then it will be used as a `name` as well. E.g.: 1s ease ease infinite; Will result in a name of `ease` as well. - We take care of trimming and multiple spaces. - We don't generate 8k tests anymore, which means that these specific tests only take a second instead of 10 seconds.
This commit is contained in:
parent
0c5c5409d7
commit
c7bcfe52cd
2 changed files with 69 additions and 113 deletions
|
|
@ -6,26 +6,46 @@ const TIMINGS = new Set(['linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out']
|
|||
const TIMING_FNS = ['cubic-bezier', 'steps']
|
||||
|
||||
const COMMA = /\,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
|
||||
const SPACE = /\ (?![^(]*\))/g // Similar to the one above, but with spaces instead.
|
||||
const SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.
|
||||
const TIME = /^(-?[\d.]+m?s)$/
|
||||
const DIGIT = /^(\d+)$/
|
||||
|
||||
export default function parseAnimationValue(input) {
|
||||
const animations = input.split(COMMA)
|
||||
const result = animations.map((animation) => {
|
||||
const result = {}
|
||||
const parts = animation.split(SPACE)
|
||||
let animations = input.split(COMMA)
|
||||
let result = animations.map((animation) => {
|
||||
let result = {}
|
||||
let parts = animation.trim().split(SPACE)
|
||||
let seen = new Set()
|
||||
|
||||
for (let part of parts) {
|
||||
if (DIRECTIONS.has(part)) result.direction = part
|
||||
else if (PLAY_STATES.has(part)) result.playState = part
|
||||
else if (FILL_MODES.has(part)) result.fillMode = part
|
||||
else if (ITERATION_COUNTS.has(part)) result.iterationCount = part
|
||||
else if (TIMINGS.has(part)) result.timingFunction = part
|
||||
else if (TIMING_FNS.some((f) => part.startsWith(`${f}(`))) result.timingFunction = part
|
||||
else if (TIME.test(part)) result[result.duration === undefined ? 'duration' : 'delay'] = part
|
||||
else if (DIGIT.test(part)) result.iterationCount = part
|
||||
else result.name = part
|
||||
if (!seen.has('DIRECTIONS') && DIRECTIONS.has(part)) {
|
||||
result.direction = part
|
||||
seen.add('DIRECTIONS')
|
||||
} else if (!seen.has('PLAY_STATES') && PLAY_STATES.has(part)) {
|
||||
result.playState = part
|
||||
seen.add('PLAY_STATES')
|
||||
} else if (!seen.has('FILL_MODES') && FILL_MODES.has(part)) {
|
||||
result.fillMode = part
|
||||
seen.add('FILL_MODES')
|
||||
} else if (
|
||||
!seen.has('ITERATION_COUNTS') &&
|
||||
(ITERATION_COUNTS.has(part) || DIGIT.test(part))
|
||||
) {
|
||||
result.iterationCount = part
|
||||
seen.add('ITERATION_COUNTS')
|
||||
} else if (!seen.has('TIMING_FUNCTION') && TIMINGS.has(part)) {
|
||||
result.timingFunction = part
|
||||
seen.add('TIMING_FUNCTION')
|
||||
} else if (!seen.has('TIMING_FUNCTION') && TIMING_FNS.some((f) => part.startsWith(`${f}(`))) {
|
||||
result.timingFunction = part
|
||||
seen.add('TIMING_FUNCTION')
|
||||
} else if (!seen.has('DURATION') && TIME.test(part)) {
|
||||
result.duration = part
|
||||
seen.add('DURATION')
|
||||
} else if (!seen.has('DELAY') && TIME.test(part)) {
|
||||
result.delay = part
|
||||
seen.add('DELAY')
|
||||
} else result.name = part
|
||||
}
|
||||
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue