UNPKG

1.33 kBJavaScriptView Raw
1'use strict';
2
3var _postcss = require('postcss');
4
5var _postcss2 = _interopRequireDefault(_postcss);
6
7var _postcssValueParser = require('postcss-value-parser');
8
9var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
10
11var _hslFunctionalNotation = require('./lib/hsl-functional-notation');
12
13var _hslFunctionalNotation2 = _interopRequireDefault(_hslFunctionalNotation);
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17function transformHsl(value) {
18 return (0, _postcssValueParser2.default)(value).walk(function (node) {
19 /* istanbul ignore if */
20 if (node.type !== 'function' || node.value !== 'hsl' && node.value !== 'hsla') {
21 return;
22 }
23 node.value = _hslFunctionalNotation2.default.legacy(_postcssValueParser2.default.stringify(node));
24 node.type = 'word';
25 }).toString();
26}
27
28module.exports = _postcss2.default.plugin('postcss-color-hsl', function (opts) {
29 opts = opts || {};
30
31 return function (root, result) {
32 root.walkDecls(function (decl) {
33 /* istanbul ignore if */
34 if (!decl.value || decl.value.indexOf('hsl(') === -1 && decl.value.indexOf('hsla(') === -1) {
35 return;
36 }
37 decl.value = transformHsl(decl.value);
38 });
39 };
40});
\No newline at end of file