postcss-normalize-repeat-style 4.0.0-rc.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +77 -53
- package/package.json +9 -9
- package/CHANGELOG.md +0 -4
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -30,66 +30,90 @@ function evenValues(list, index) {
|
|
|
30
30
|
return index % 2 === 0;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const repeatKeywords = _map2.default.map(mapping => mapping[0]);
|
|
34
|
+
|
|
35
|
+
const getMatch = (0, _cssnanoUtilGetMatch2.default)(_map2.default);
|
|
36
|
+
|
|
37
|
+
exports.default = _postcss2.default.plugin('postcss-normalize-repeat-style', () => {
|
|
38
|
+
return css => {
|
|
39
|
+
const cache = {};
|
|
40
|
+
|
|
41
|
+
css.walkDecls(/background(-repeat)?|(-webkit-)?mask-repeat/i, decl => {
|
|
42
|
+
const value = decl.value;
|
|
43
|
+
|
|
44
|
+
if (cache[value]) {
|
|
45
|
+
decl.value = cache[value];
|
|
46
|
+
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const parsed = (0, _postcssValueParser2.default)(value);
|
|
51
|
+
|
|
52
|
+
if (parsed.nodes.length === 1) {
|
|
53
|
+
cache[value] = value;
|
|
36
54
|
|
|
37
|
-
var getMatch = (0, _cssnanoUtilGetMatch2.default)(_map2.default);
|
|
38
|
-
|
|
39
|
-
function transform(decl) {
|
|
40
|
-
var values = (0, _postcssValueParser2.default)(decl.value);
|
|
41
|
-
if (values.nodes.length === 1) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
var args = (0, _cssnanoUtilGetArguments2.default)(values);
|
|
45
|
-
var relevant = [];
|
|
46
|
-
args.forEach(function (arg) {
|
|
47
|
-
relevant.push({
|
|
48
|
-
start: null,
|
|
49
|
-
end: null
|
|
50
|
-
});
|
|
51
|
-
arg.forEach(function (part, index) {
|
|
52
|
-
var isRepeat = ~repeatKeywords.indexOf(part.value);
|
|
53
|
-
var len = relevant.length - 1;
|
|
54
|
-
if (relevant[len].start === null && isRepeat) {
|
|
55
|
-
relevant[len].start = index;
|
|
56
|
-
relevant[len].end = index;
|
|
57
55
|
return;
|
|
58
56
|
}
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
|
|
58
|
+
const args = (0, _cssnanoUtilGetArguments2.default)(parsed);
|
|
59
|
+
const relevant = [];
|
|
60
|
+
|
|
61
|
+
args.forEach(arg => {
|
|
62
|
+
relevant.push({
|
|
63
|
+
start: null,
|
|
64
|
+
end: null
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
arg.forEach((part, index) => {
|
|
68
|
+
const isRepeat = ~repeatKeywords.indexOf(part.value.toLowerCase());
|
|
69
|
+
const len = relevant.length - 1;
|
|
70
|
+
|
|
71
|
+
if (relevant[len].start === null && isRepeat) {
|
|
72
|
+
relevant[len].start = index;
|
|
73
|
+
relevant[len].end = index;
|
|
74
|
+
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (relevant[len].start !== null) {
|
|
79
|
+
if (part.type === 'space') {
|
|
80
|
+
return;
|
|
81
|
+
} else if (isRepeat) {
|
|
82
|
+
relevant[len].end = index;
|
|
83
|
+
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
relevant.forEach((range, index) => {
|
|
93
|
+
if (range.start === null) {
|
|
61
94
|
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const val = args[index].slice(range.start, range.end + 1);
|
|
98
|
+
|
|
99
|
+
if (val.length !== 3) {
|
|
64
100
|
return;
|
|
65
101
|
}
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
relevant.forEach(function (range, index) {
|
|
71
|
-
if (range.start === null) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
var val = args[index].slice(range.start, range.end + 1);
|
|
75
|
-
if (val.length !== 3) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
var match = getMatch(val.filter(evenValues).map(function (n) {
|
|
79
|
-
return n.value;
|
|
80
|
-
}));
|
|
81
|
-
if (match) {
|
|
82
|
-
args[index][range.start].value = match;
|
|
83
|
-
args[index][range.start + 1].value = '';
|
|
84
|
-
args[index][range.end].value = '';
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
decl.value = values.toString();
|
|
88
|
-
}
|
|
89
102
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
103
|
+
const match = getMatch(val.filter(evenValues).map(n => n.value.toLowerCase()));
|
|
104
|
+
|
|
105
|
+
if (match) {
|
|
106
|
+
args[index][range.start].value = match;
|
|
107
|
+
args[index][range.start + 1].value = '';
|
|
108
|
+
args[index][range.end].value = '';
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const result = parsed.toString();
|
|
113
|
+
|
|
114
|
+
decl.value = result;
|
|
115
|
+
cache[value] = result;
|
|
116
|
+
});
|
|
93
117
|
};
|
|
94
118
|
});
|
|
95
119
|
module.exports = exports['default'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-normalize-repeat-style",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Convert two value syntax for repeat-style into one value.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,26 +12,26 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"cssnano-util-get-arguments": "^4.0.0
|
|
16
|
-
"cssnano-util-get-match": "^4.0.0
|
|
17
|
-
"postcss": "^
|
|
15
|
+
"cssnano-util-get-arguments": "^4.0.0",
|
|
16
|
+
"cssnano-util-get-match": "^4.0.0",
|
|
17
|
+
"postcss": "^7.0.0",
|
|
18
18
|
"postcss-value-parser": "^3.0.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"babel-cli": "^6.0.0",
|
|
22
|
-
"cross-env": "^
|
|
22
|
+
"cross-env": "^5.0.0"
|
|
23
23
|
},
|
|
24
24
|
"author": {
|
|
25
25
|
"name": "Ben Briggs",
|
|
26
26
|
"email": "beneb.info@gmail.com",
|
|
27
27
|
"url": "http://beneb.info"
|
|
28
28
|
},
|
|
29
|
-
"repository": "
|
|
29
|
+
"repository": "cssnano/cssnano",
|
|
30
30
|
"bugs": {
|
|
31
|
-
"url": "https://github.com/
|
|
31
|
+
"url": "https://github.com/cssnano/cssnano/issues"
|
|
32
32
|
},
|
|
33
|
-
"homepage": "https://github.com/
|
|
33
|
+
"homepage": "https://github.com/cssnano/cssnano",
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
35
|
+
"node": ">=6.9.0"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/CHANGELOG.md
DELETED