postcss-normalize-repeat-style 5.0.0 → 5.0.4

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/package.json CHANGED
@@ -1,21 +1,15 @@
1
1
  {
2
2
  "name": "postcss-normalize-repeat-style",
3
- "version": "5.0.0",
3
+ "version": "5.0.4",
4
4
  "description": "Convert two value syntax for repeat-style into one value.",
5
- "main": "dist/index.js",
6
- "scripts": {
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"
10
- },
5
+ "main": "src/index.js",
11
6
  "files": [
12
7
  "LICENSE-MIT",
13
- "dist"
8
+ "src"
14
9
  ],
15
10
  "license": "MIT",
16
11
  "dependencies": {
17
- "cssnano-utils": "^2.0.0",
18
- "postcss-value-parser": "^4.1.0"
12
+ "postcss-value-parser": "^4.2.0"
19
13
  },
20
14
  "author": {
21
15
  "name": "Ben Briggs",
@@ -31,10 +25,10 @@
31
25
  "node": "^10 || ^12 || >=14.0"
32
26
  },
33
27
  "devDependencies": {
34
- "postcss": "^8.2.1"
28
+ "postcss": "^8.2.15"
35
29
  },
36
30
  "peerDependencies": {
37
- "postcss": "^8.2.1"
31
+ "postcss": "^8.2.15"
38
32
  },
39
- "gitHead": "0e2c3bf5835bafcdc8783bef66f730a24194c8f3"
40
- }
33
+ "readme": "# [postcss][postcss]-normalize-repeat-style\n\n> Normalize repeat styles with PostCSS.\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-normalize-repeat-style) do:\n\n```\nnpm install postcss-normalize-repeat-style --save\n```\n\n## Example\n\n### Input\n\n```css\nh1 {\n background: url(image.jpg) repeat no-repeat\n}\n```\n\n### Output\n\n```css\nh1 {\n background: url(image.jpg) repeat-x\n}\n```\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[postcss]: https://github.com/postcss/postcss\n"
34
+ }
@@ -1,25 +1,12 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
9
-
10
- var _cssnanoUtils = require("cssnano-utils");
11
-
12
- var _map = _interopRequireDefault(require("./lib/map"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1
+ 'use strict';
2
+ const valueParser = require('postcss-value-parser');
3
+ const mappings = require('./lib/map');
15
4
 
16
5
  function evenValues(list, index) {
17
6
  return index % 2 === 0;
18
7
  }
19
8
 
20
- const repeatKeywords = _map.default.map(mapping => mapping[0]);
21
-
22
- const getMatch = (0, _cssnanoUtils.getMatch)(_map.default);
9
+ const repeatKeywords = new Set(mappings.values());
23
10
 
24
11
  function isCommaNode(node) {
25
12
  return node.type === 'div' && node.value === ',';
@@ -34,7 +21,7 @@ function isVariableFunctionNode(node) {
34
21
  }
35
22
 
36
23
  function transform(value) {
37
- const parsed = (0, _postcssValueParser.default)(value);
24
+ const parsed = valueParser(value);
38
25
 
39
26
  if (parsed.nodes.length === 1) {
40
27
  return value;
@@ -43,45 +30,51 @@ function transform(value) {
43
30
  const ranges = [];
44
31
  let rangeIndex = 0;
45
32
  let shouldContinue = true;
33
+
46
34
  parsed.nodes.forEach((node, index) => {
47
35
  // After comma (`,`) follows next background
48
36
  if (isCommaNode(node)) {
49
37
  rangeIndex += 1;
50
38
  shouldContinue = true;
39
+
51
40
  return;
52
41
  }
53
42
 
54
43
  if (!shouldContinue) {
55
44
  return;
56
- } // After separator (`/`) follows `background-size` values
57
- // Avoid them
58
-
45
+ }
59
46
 
47
+ // After separator (`/`) follows `background-size` values
48
+ // Avoid them
60
49
  if (node.type === 'div' && node.value === '/') {
61
50
  shouldContinue = false;
51
+
62
52
  return;
63
53
  }
64
54
 
65
55
  if (!ranges[rangeIndex]) {
66
56
  ranges[rangeIndex] = {
67
57
  start: null,
68
- end: null
58
+ end: null,
69
59
  };
70
- } // Do not try to be processed `var and `env` function inside background
71
-
60
+ }
72
61
 
62
+ // Do not try to be processed `var and `env` function inside background
73
63
  if (isVariableFunctionNode(node)) {
74
64
  shouldContinue = false;
75
65
  ranges[rangeIndex].start = null;
76
66
  ranges[rangeIndex].end = null;
67
+
77
68
  return;
78
69
  }
79
70
 
80
- const isRepeatKeyword = node.type === 'word' && repeatKeywords.includes(node.value.toLowerCase());
71
+ const isRepeatKeyword =
72
+ node.type === 'word' && repeatKeywords.has(node.value.toLowerCase());
81
73
 
82
74
  if (ranges[rangeIndex].start === null && isRepeatKeyword) {
83
75
  ranges[rangeIndex].start = index;
84
76
  ranges[rangeIndex].end = index;
77
+
85
78
  return;
86
79
  }
87
80
 
@@ -90,13 +83,15 @@ function transform(value) {
90
83
  return;
91
84
  } else if (isRepeatKeyword) {
92
85
  ranges[rangeIndex].end = index;
86
+
93
87
  return;
94
88
  }
95
89
 
96
90
  return;
97
91
  }
98
92
  });
99
- ranges.forEach(range => {
93
+
94
+ ranges.forEach((range) => {
100
95
  if (range.start === null) {
101
96
  return;
102
97
  }
@@ -106,50 +101,55 @@ function transform(value) {
106
101
  if (nodes.length !== 3) {
107
102
  return;
108
103
  }
104
+ const key = nodes
105
+ .filter(evenValues)
106
+ .map((n) => n.value.toLowerCase())
107
+ .toString();
109
108
 
110
- const match = getMatch(nodes.filter(evenValues).map(n => n.value.toLowerCase()));
109
+ const match = mappings.get(key);
111
110
 
112
111
  if (match) {
113
112
  nodes[0].value = match;
114
113
  nodes[1].value = nodes[2].value = '';
115
114
  }
116
115
  });
116
+
117
117
  return parsed.toString();
118
118
  }
119
119
 
120
120
  function pluginCreator() {
121
121
  return {
122
122
  postcssPlugin: 'postcss-normalize-repeat-style',
123
-
124
123
  prepare() {
125
- const cache = {};
124
+ const cache = new Map();
126
125
  return {
127
126
  OnceExit(css) {
128
- css.walkDecls(/^(background(-repeat)?|(-\w+-)?mask-repeat)$/i, decl => {
129
- const value = decl.value;
127
+ css.walkDecls(
128
+ /^(background(-repeat)?|(-\w+-)?mask-repeat)$/i,
129
+ (decl) => {
130
+ const value = decl.value;
130
131
 
131
- if (!value) {
132
- return;
133
- }
132
+ if (!value) {
133
+ return;
134
+ }
134
135
 
135
- if (cache[value]) {
136
- decl.value = cache[value];
137
- return;
138
- }
136
+ if (cache.has(value)) {
137
+ decl.value = cache.get(value);
139
138
 
140
- const result = transform(value);
141
- decl.value = result;
142
- cache[value] = result;
143
- });
144
- }
139
+ return;
140
+ }
145
141
 
146
- };
147
- }
142
+ const result = transform(value);
148
143
 
144
+ decl.value = result;
145
+ cache.set(value, result);
146
+ }
147
+ );
148
+ },
149
+ };
150
+ },
149
151
  };
150
152
  }
151
153
 
152
154
  pluginCreator.postcss = true;
153
- var _default = pluginCreator;
154
- exports.default = _default;
155
- module.exports = exports.default;
155
+ module.exports = pluginCreator;
package/src/lib/map.js ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+ module.exports = new Map([
3
+ [['repeat', 'no-repeat'].toString(), 'repeat-x'],
4
+ [['no-repeat', 'repeat'].toString(), 'repeat-y'],
5
+ [['repeat', 'repeat'].toString(), 'repeat'],
6
+ [['space', 'space'].toString(), 'space'],
7
+ [['round', 'round'].toString(), 'round'],
8
+ [['no-repeat', 'no-repeat'].toString(), 'no-repeat'],
9
+ ]);
package/CHANGELOG.md DELETED
@@ -1,69 +0,0 @@
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/lib/map.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
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;