postcss-normalize-repeat-style 4.0.2 → 5.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,69 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-normalize-repeat-style@5.0.0-rc.2...postcss-normalize-repeat-style@5.0.0) (2021-04-06)
7
+
8
+ **Note:** Version bump only for package postcss-normalize-repeat-style
9
+
10
+
11
+
12
+
13
+
14
+ # [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-normalize-repeat-style@5.0.0-rc.1...postcss-normalize-repeat-style@5.0.0-rc.2) (2021-03-15)
15
+
16
+ **Note:** Version bump only for package postcss-normalize-repeat-style
17
+
18
+
19
+
20
+
21
+
22
+ # [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-normalize-repeat-style@5.0.0-rc.0...postcss-normalize-repeat-style@5.0.0-rc.1) (2021-03-04)
23
+
24
+ **Note:** Version bump only for package postcss-normalize-repeat-style
25
+
26
+
27
+
28
+
29
+
30
+ # 5.0.0-rc.0 (2021-02-19)
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * **postcss-normalize-repeat-style:** better handle css variables ([#753](https://github.com/cssnano/cssnano/issues/753)) ([7e18b0c](https://github.com/cssnano/cssnano/commit/7e18b0cbcd7cb5de58e60ab4ef1900a4d8eeefec))
36
+
37
+
38
+ ### chore
39
+
40
+ * minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
41
+
42
+
43
+ ### Features
44
+
45
+ * migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
46
+
47
+
48
+ ### BREAKING CHANGES
49
+
50
+ * minimum supported `postcss` version is `8.2.1`
51
+ * minimum require version of node is 10.13
52
+
53
+
54
+
55
+ ## 4.1.9 (2019-02-12)
56
+
57
+
58
+ ### Performance Improvements
59
+
60
+ * **postcss-normalize-repeat-style:** increase perf ([#690](https://github.com/cssnano/cssnano/issues/690)) ([2c900e4](https://github.com/cssnano/cssnano/commit/2c900e4176e4aabd484e468b32b1ed1011c00ef4))
61
+
62
+
63
+
64
+ ## 4.1.1 (2018-09-24)
65
+
66
+
67
+ ### Bug Fixes
68
+
69
+ * **postcss-merge-longhand:** not mangle border output ([#555](https://github.com/cssnano/cssnano/issues/555)) ([9a70605](https://github.com/cssnano/cssnano/commit/9a706050b621e7795a9bf74eb7110b5c81804ffe)), closes [#553](https://github.com/cssnano/cssnano/issues/553) [#554](https://github.com/cssnano/cssnano/issues/554)
package/dist/index.js CHANGED
@@ -1,119 +1,155 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _postcss = require('postcss');
8
+ var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
8
9
 
9
- var _postcss2 = _interopRequireDefault(_postcss);
10
+ var _cssnanoUtils = require("cssnano-utils");
10
11
 
11
- var _postcssValueParser = require('postcss-value-parser');
12
-
13
- var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
14
-
15
- var _cssnanoUtilGetArguments = require('cssnano-util-get-arguments');
16
-
17
- var _cssnanoUtilGetArguments2 = _interopRequireDefault(_cssnanoUtilGetArguments);
18
-
19
- var _cssnanoUtilGetMatch = require('cssnano-util-get-match');
20
-
21
- var _cssnanoUtilGetMatch2 = _interopRequireDefault(_cssnanoUtilGetMatch);
22
-
23
- var _map = require('./lib/map');
24
-
25
- var _map2 = _interopRequireDefault(_map);
12
+ var _map = _interopRequireDefault(require("./lib/map"));
26
13
 
27
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
15
 
29
16
  function evenValues(list, index) {
30
- return index % 2 === 0;
17
+ return index % 2 === 0;
31
18
  }
32
19
 
33
- const repeatKeywords = _map2.default.map(mapping => mapping[0]);
20
+ const repeatKeywords = _map.default.map(mapping => mapping[0]);
34
21
 
35
- const getMatch = (0, _cssnanoUtilGetMatch2.default)(_map2.default);
22
+ const getMatch = (0, _cssnanoUtils.getMatch)(_map.default);
36
23
 
37
- exports.default = _postcss2.default.plugin('postcss-normalize-repeat-style', () => {
38
- return css => {
39
- const cache = {};
24
+ function isCommaNode(node) {
25
+ return node.type === 'div' && node.value === ',';
26
+ }
40
27
 
41
- css.walkDecls(/background(-repeat)?|(-webkit-)?mask-repeat/i, decl => {
42
- const value = decl.value;
28
+ function isVariableFunctionNode(node) {
29
+ if (node.type !== 'function') {
30
+ return false;
31
+ }
43
32
 
44
- if (cache[value]) {
45
- decl.value = cache[value];
33
+ return ['var', 'env'].includes(node.value.toLowerCase());
34
+ }
46
35
 
47
- return;
48
- }
36
+ function transform(value) {
37
+ const parsed = (0, _postcssValueParser.default)(value);
38
+
39
+ if (parsed.nodes.length === 1) {
40
+ return value;
41
+ }
42
+
43
+ const ranges = [];
44
+ let rangeIndex = 0;
45
+ let shouldContinue = true;
46
+ parsed.nodes.forEach((node, index) => {
47
+ // After comma (`,`) follows next background
48
+ if (isCommaNode(node)) {
49
+ rangeIndex += 1;
50
+ shouldContinue = true;
51
+ return;
52
+ }
53
+
54
+ if (!shouldContinue) {
55
+ return;
56
+ } // After separator (`/`) follows `background-size` values
57
+ // Avoid them
58
+
59
+
60
+ if (node.type === 'div' && node.value === '/') {
61
+ shouldContinue = false;
62
+ return;
63
+ }
64
+
65
+ if (!ranges[rangeIndex]) {
66
+ ranges[rangeIndex] = {
67
+ start: null,
68
+ end: null
69
+ };
70
+ } // Do not try to be processed `var and `env` function inside background
71
+
72
+
73
+ if (isVariableFunctionNode(node)) {
74
+ shouldContinue = false;
75
+ ranges[rangeIndex].start = null;
76
+ ranges[rangeIndex].end = null;
77
+ return;
78
+ }
79
+
80
+ const isRepeatKeyword = node.type === 'word' && repeatKeywords.includes(node.value.toLowerCase());
81
+
82
+ if (ranges[rangeIndex].start === null && isRepeatKeyword) {
83
+ ranges[rangeIndex].start = index;
84
+ ranges[rangeIndex].end = index;
85
+ return;
86
+ }
87
+
88
+ if (ranges[rangeIndex].start !== null) {
89
+ if (node.type === 'space') {
90
+ return;
91
+ } else if (isRepeatKeyword) {
92
+ ranges[rangeIndex].end = index;
93
+ return;
94
+ }
95
+
96
+ return;
97
+ }
98
+ });
99
+ ranges.forEach(range => {
100
+ if (range.start === null) {
101
+ return;
102
+ }
103
+
104
+ const nodes = parsed.nodes.slice(range.start, range.end + 1);
105
+
106
+ if (nodes.length !== 3) {
107
+ return;
108
+ }
109
+
110
+ const match = getMatch(nodes.filter(evenValues).map(n => n.value.toLowerCase()));
111
+
112
+ if (match) {
113
+ nodes[0].value = match;
114
+ nodes[1].value = nodes[2].value = '';
115
+ }
116
+ });
117
+ return parsed.toString();
118
+ }
49
119
 
50
- const parsed = (0, _postcssValueParser2.default)(value);
120
+ function pluginCreator() {
121
+ return {
122
+ postcssPlugin: 'postcss-normalize-repeat-style',
51
123
 
52
- if (parsed.nodes.length === 1) {
53
- cache[value] = value;
124
+ prepare() {
125
+ const cache = {};
126
+ return {
127
+ OnceExit(css) {
128
+ css.walkDecls(/^(background(-repeat)?|(-\w+-)?mask-repeat)$/i, decl => {
129
+ const value = decl.value;
54
130
 
55
- return;
131
+ if (!value) {
132
+ return;
56
133
  }
57
134
 
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) {
94
- return;
95
- }
96
-
97
- const val = args[index].slice(range.start, range.end + 1);
98
-
99
- if (val.length !== 3) {
100
- return;
101
- }
135
+ if (cache[value]) {
136
+ decl.value = cache[value];
137
+ return;
138
+ }
102
139
 
103
- const match = getMatch(val.filter(evenValues).map(n => n.value.toLowerCase()));
140
+ const result = transform(value);
141
+ decl.value = result;
142
+ cache[value] = result;
143
+ });
144
+ }
104
145
 
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
- });
146
+ };
147
+ }
111
148
 
112
- const result = parsed.toString();
149
+ };
150
+ }
113
151
 
114
- decl.value = result;
115
- cache[value] = result;
116
- });
117
- };
118
- });
119
- module.exports = exports['default'];
152
+ pluginCreator.postcss = true;
153
+ var _default = pluginCreator;
154
+ exports.default = _default;
155
+ module.exports = exports.default;
package/dist/lib/map.js CHANGED
@@ -1,7 +1,9 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
- exports.default = [['repeat-x', ['repeat', 'no-repeat']], ['repeat-y', ['no-repeat', 'repeat']], ['repeat', ['repeat', 'repeat']], ['space', ['space', 'space']], ['round', ['round', 'round']], ['no-repeat', ['no-repeat', 'no-repeat']]];
7
- module.exports = exports['default'];
6
+ exports.default = void 0;
7
+ var _default = [['repeat-x', ['repeat', 'no-repeat']], ['repeat-y', ['no-repeat', 'repeat']], ['repeat', ['repeat', 'repeat']], ['space', ['space', 'space']], ['round', ['round', 'round']], ['no-repeat', ['no-repeat', 'no-repeat']]];
8
+ exports.default = _default;
9
+ module.exports = exports.default;
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "postcss-normalize-repeat-style",
3
- "version": "4.0.2",
3
+ "version": "5.0.0",
4
4
  "description": "Convert two value syntax for repeat-style into one value.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
7
+ "prebuild": "del-cli dist",
8
+ "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
9
+ "prepublish": "yarn build"
8
10
  },
9
11
  "files": [
10
12
  "LICENSE-MIT",
@@ -12,14 +14,8 @@
12
14
  ],
13
15
  "license": "MIT",
14
16
  "dependencies": {
15
- "cssnano-util-get-arguments": "^4.0.0",
16
- "cssnano-util-get-match": "^4.0.0",
17
- "postcss": "^7.0.0",
18
- "postcss-value-parser": "^3.0.0"
19
- },
20
- "devDependencies": {
21
- "babel-cli": "^6.0.0",
22
- "cross-env": "^5.0.0"
17
+ "cssnano-utils": "^2.0.0",
18
+ "postcss-value-parser": "^4.1.0"
23
19
  },
24
20
  "author": {
25
21
  "name": "Ben Briggs",
@@ -32,6 +28,13 @@
32
28
  },
33
29
  "homepage": "https://github.com/cssnano/cssnano",
34
30
  "engines": {
35
- "node": ">=6.9.0"
36
- }
31
+ "node": "^10 || ^12 || >=14.0"
32
+ },
33
+ "devDependencies": {
34
+ "postcss": "^8.2.1"
35
+ },
36
+ "peerDependencies": {
37
+ "postcss": "^8.2.1"
38
+ },
39
+ "gitHead": "0e2c3bf5835bafcdc8783bef66f730a24194c8f3"
37
40
  }