-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.cjs
More file actions
71 lines (71 loc) · 2.55 KB
/
Copy pathindex.cjs
File metadata and controls
71 lines (71 loc) · 2.55 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const parser = require("postcss-value-parser");
const springEasing = require("spring-easing");
function toSnake(str) {
return str[0] + str.slice(1).replace(/[A-Z]/g, (letter) => {
return "-" + letter.toLowerCase();
});
}
function toCamel(str) {
return str.replace(/-[a-z]/g, (letter) => {
return letter[1].toUpperCase();
});
}
const easingFns = {};
for (let name of springEasing.EasingFunctionKeys) {
easingFns[name.replace(/-/g, "").toLowerCase()] = springEasing.EasingFunctions[name];
easingFns[toSnake(name)] = springEasing.EasingFunctions[name];
}
springEasing.registerEasingFunctions(easingFns);
const springEasingPlugin = function(opts = {}) {
const { easings, ...easingOpts } = opts;
const locals = Object.assign({}, springEasing.EasingFunctions);
if (opts.easings) {
for (let name in Object.assign({}, opts.easings)) {
locals[name.replace(/-/g, "").toLowerCase()] = opts.easings[name];
locals[toSnake(name)] = opts.easings[name];
}
}
springEasing.registerEasingFunctions(locals);
const localKeys = Array.from(new Set(Object.keys(locals)));
const localKeysStr = localKeys.join("|").trim();
return {
postcssPlugin: "postcss-spring-easing",
Declaration(decl) {
if (!new RegExp(localKeysStr, "i").test(decl.value))
return;
let root = parser(decl.value);
let changed = false;
root.nodes = root.nodes.map((node) => {
let value = node.value.trim();
const isFunction = node.type === "function";
const isWord = node.type === "word";
if ((isWord || isFunction) && value.length > 0 && new RegExp(`^(${localKeysStr})$`, "i").test(value)) {
changed = true;
const contents = isFunction ? parser.stringify(node) : value;
const [easings2, duration] = springEasing.CSSSpringEasing({
easing: contents,
...easingOpts
});
node.type = "function";
node.value = `linear`;
node.nodes = parser(easings2).nodes;
decl.before(`--spring-duration: ${springEasing.toFixed(duration, 2)}ms;`);
}
return node;
});
if (changed) {
decl.value = root.toString();
}
}
};
};
const postcss = true;
springEasingPlugin.postcss = postcss;
exports.default = springEasingPlugin;
exports.postcss = postcss;
exports.springEasingPlugin = springEasingPlugin;
exports.toCamel = toCamel;
exports.toSnake = toSnake;
//# sourceMappingURL=index.cjs.map