-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathkeyframes.js
38 lines (28 loc) · 973 Bytes
/
keyframes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function unprefixed(prop) {
return prop.replace(/^-\w+-/, '');
}
const {rtlifyDecl} = require('./decls');
const {rtlifyRule} = require('./rules');
const isKeyframeRule = (rule) => rule.type === 'atrule' && unprefixed(rule.name) === 'keyframes';
const isKeyframeAlreadyProcessed = (rule) => !!rule.params.match(/-ltr$|-rtl$/);
const isKeyframeSymmetric = (rule) => !rtlifyRule(rule);
const rtlifyKeyframe = (rule, options) => {
const ruleName = rule.params;
rule.params = `${ruleName}-ltr`;
if (!options.onlyDirection || options.onlyDirection === 'rtl') {
const rtlRule = rule.cloneAfter({params: `${ruleName}-rtl`});
rtlRule.walkDecls((decl) => {
const rtl = rtlifyDecl(decl);
decl.value = rtl ? rtl.value : decl.value;
});
}
if (options.onlyDirection && options.onlyDirection === 'rtl') {
rule.remove();
}
};
module.exports = {
isKeyframeRule,
isKeyframeAlreadyProcessed,
isKeyframeSymmetric,
rtlifyKeyframe,
};