| 1 | "use strict";
|
|---|
| 2 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 3 | value: true
|
|---|
| 4 | });
|
|---|
| 5 | Object.defineProperty(exports, "default", {
|
|---|
| 6 | enumerable: true,
|
|---|
| 7 | get: function() {
|
|---|
| 8 | return parseAnimationValue;
|
|---|
| 9 | }
|
|---|
| 10 | });
|
|---|
| 11 | const DIRECTIONS = new Set([
|
|---|
| 12 | "normal",
|
|---|
| 13 | "reverse",
|
|---|
| 14 | "alternate",
|
|---|
| 15 | "alternate-reverse"
|
|---|
| 16 | ]);
|
|---|
| 17 | const PLAY_STATES = new Set([
|
|---|
| 18 | "running",
|
|---|
| 19 | "paused"
|
|---|
| 20 | ]);
|
|---|
| 21 | const FILL_MODES = new Set([
|
|---|
| 22 | "none",
|
|---|
| 23 | "forwards",
|
|---|
| 24 | "backwards",
|
|---|
| 25 | "both"
|
|---|
| 26 | ]);
|
|---|
| 27 | const ITERATION_COUNTS = new Set([
|
|---|
| 28 | "infinite"
|
|---|
| 29 | ]);
|
|---|
| 30 | const TIMINGS = new Set([
|
|---|
| 31 | "linear",
|
|---|
| 32 | "ease",
|
|---|
| 33 | "ease-in",
|
|---|
| 34 | "ease-out",
|
|---|
| 35 | "ease-in-out",
|
|---|
| 36 | "step-start",
|
|---|
| 37 | "step-end"
|
|---|
| 38 | ]);
|
|---|
| 39 | const TIMING_FNS = [
|
|---|
| 40 | "cubic-bezier",
|
|---|
| 41 | "steps"
|
|---|
| 42 | ];
|
|---|
| 43 | const COMMA = /\,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubic-bezier(a, b, c)` these don't count.
|
|---|
| 44 | ;
|
|---|
| 45 | const SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.
|
|---|
| 46 | ;
|
|---|
| 47 | const TIME = /^(-?[\d.]+m?s)$/;
|
|---|
| 48 | const DIGIT = /^(\d+)$/;
|
|---|
| 49 | function parseAnimationValue(input) {
|
|---|
| 50 | let animations = input.split(COMMA);
|
|---|
| 51 | return animations.map((animation)=>{
|
|---|
| 52 | let value = animation.trim();
|
|---|
| 53 | let result = {
|
|---|
| 54 | value
|
|---|
| 55 | };
|
|---|
| 56 | let parts = value.split(SPACE);
|
|---|
| 57 | let seen = new Set();
|
|---|
| 58 | for (let part of parts){
|
|---|
| 59 | if (!seen.has("DIRECTIONS") && DIRECTIONS.has(part)) {
|
|---|
| 60 | result.direction = part;
|
|---|
| 61 | seen.add("DIRECTIONS");
|
|---|
| 62 | } else if (!seen.has("PLAY_STATES") && PLAY_STATES.has(part)) {
|
|---|
| 63 | result.playState = part;
|
|---|
| 64 | seen.add("PLAY_STATES");
|
|---|
| 65 | } else if (!seen.has("FILL_MODES") && FILL_MODES.has(part)) {
|
|---|
| 66 | result.fillMode = part;
|
|---|
| 67 | seen.add("FILL_MODES");
|
|---|
| 68 | } else if (!seen.has("ITERATION_COUNTS") && (ITERATION_COUNTS.has(part) || DIGIT.test(part))) {
|
|---|
| 69 | result.iterationCount = part;
|
|---|
| 70 | seen.add("ITERATION_COUNTS");
|
|---|
| 71 | } else if (!seen.has("TIMING_FUNCTION") && TIMINGS.has(part)) {
|
|---|
| 72 | result.timingFunction = part;
|
|---|
| 73 | seen.add("TIMING_FUNCTION");
|
|---|
| 74 | } else if (!seen.has("TIMING_FUNCTION") && TIMING_FNS.some((f)=>part.startsWith(`${f}(`))) {
|
|---|
| 75 | result.timingFunction = part;
|
|---|
| 76 | seen.add("TIMING_FUNCTION");
|
|---|
| 77 | } else if (!seen.has("DURATION") && TIME.test(part)) {
|
|---|
| 78 | result.duration = part;
|
|---|
| 79 | seen.add("DURATION");
|
|---|
| 80 | } else if (!seen.has("DELAY") && TIME.test(part)) {
|
|---|
| 81 | result.delay = part;
|
|---|
| 82 | seen.add("DELAY");
|
|---|
| 83 | } else if (!seen.has("NAME")) {
|
|---|
| 84 | result.name = part;
|
|---|
| 85 | seen.add("NAME");
|
|---|
| 86 | } else {
|
|---|
| 87 | if (!result.unknown) result.unknown = [];
|
|---|
| 88 | result.unknown.push(part);
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 | return result;
|
|---|
| 92 | });
|
|---|
| 93 | }
|
|---|