scancss
Version:
A robust CSS stylesheet statistics collector and analyzer
62 lines (46 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.handleKeyframes = handleKeyframes;
var _rePercentage = require('../../../constants/rePercentage');
var _countUsage = require('../../../calculators/countUsage');
var _trimSpacesNearCommas = require('../../../converters/trimSpacesNearCommas');
var _unique = require('../../../converters/unique');
function handleKeyframes(atRule, report) {
const steps = [];
atRule.walkRules(rule => {
(0, _trimSpacesNearCommas.trimSpacesNearCommas)(rule.selector).split(',').map(selector => selector.trim()).forEach(selector => {
if (selector === 'from') {
steps.push(0);
}
if (_rePercentage.rePercentage.test(selector)) {
steps.push(Number(selector.slice(0, -1)));
}
if (selector === 'to') {
steps.push(100);
}
});
rule.walkDecls(decl => {
if (report.keyframes.animatableProperties.includes(decl.prop) === false) {
report.keyframes.animatableProperties.push(decl.prop);
}
});
});
const stepsUnique = (0, _unique.unique)(steps);
const stepsChain = stepsUnique.sort((a, b) => a - b).map(step => step + '%').join(' -> ');
(0, _countUsage.countUsage)(stepsChain, report.keyframes.stepsChains);
if (report.keyframes.longestStepsChainLength < stepsUnique.length) {
report.keyframes.longestStepsChainLength = stepsUnique.length;
report.keyframes.longestStepsChain = stepsChain;
report.keyframes.longestStepsChainAnimation = atRule.params;
}
if (report.keyframes.shortestStepsChainLength > stepsUnique.length) {
report.keyframes.shortestStepsChainLength = stepsUnique.length;
report.keyframes.shortestStepsChain = stepsChain;
report.keyframes.shortestStepsChainAnimation = atRule.params;
}
if (report.keyframes.definedAnimations.includes(atRule.params) === false) {
report.keyframes.definedAnimations.push(atRule.params);
}
}