31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
import { analyseComplexValue } from '../../../value/types/complex/index.mjs';
|
|
import { getAnimatableNone } from '../../../value/types/utils/animatable-none.mjs';
|
|
|
|
/**
|
|
* If we encounter keyframes like "none" or "0" and we also have keyframes like
|
|
* "#fff" or "200px 200px" we want to find a keyframe to serve as a template for
|
|
* the "none" keyframes. In this case "#fff" or "200px 200px" - then these get turned into
|
|
* zero equivalents, i.e. "#fff0" or "0px 0px".
|
|
*/
|
|
const invalidTemplates = new Set(["auto", "none", "0"]);
|
|
function makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, name) {
|
|
let i = 0;
|
|
let animatableTemplate = undefined;
|
|
while (i < unresolvedKeyframes.length && !animatableTemplate) {
|
|
const keyframe = unresolvedKeyframes[i];
|
|
if (typeof keyframe === "string" &&
|
|
!invalidTemplates.has(keyframe) &&
|
|
analyseComplexValue(keyframe).values.length) {
|
|
animatableTemplate = unresolvedKeyframes[i];
|
|
}
|
|
i++;
|
|
}
|
|
if (animatableTemplate && name) {
|
|
for (const noneIndex of noneKeyframeIndexes) {
|
|
unresolvedKeyframes[noneIndex] = getAnimatableNone(name, animatableTemplate);
|
|
}
|
|
}
|
|
}
|
|
|
|
export { makeNoneKeyframesAnimatable };
|