postcss-normalize-repeat-style 5.0.3 → 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,11 +1,11 @@
1
1
  {
2
2
  "name": "postcss-normalize-repeat-style",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
4
4
  "description": "Convert two value syntax for repeat-style into one value.",
5
- "main": "dist/index.js",
5
+ "main": "src/index.js",
6
6
  "files": [
7
7
  "LICENSE-MIT",
8
- "dist"
8
+ "src"
9
9
  ],
10
10
  "license": "MIT",
11
11
  "dependencies": {
@@ -30,9 +30,5 @@
30
30
  "peerDependencies": {
31
31
  "postcss": "^8.2.15"
32
32
  },
33
- "scripts": {
34
- "prebuild": "rimraf dist",
35
- "build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
36
- },
37
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"
38
34
  }
@@ -1,21 +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 _map = _interopRequireDefault(require("./lib/map"));
11
-
12
- 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');
13
4
 
14
5
  function evenValues(list, index) {
15
6
  return index % 2 === 0;
16
7
  }
17
8
 
18
- const repeatKeywords = new Set(_map.default.values());
9
+ const repeatKeywords = new Set(mappings.values());
19
10
 
20
11
  function isCommaNode(node) {
21
12
  return node.type === 'div' && node.value === ',';
@@ -30,7 +21,7 @@ function isVariableFunctionNode(node) {
30
21
  }
31
22
 
32
23
  function transform(value) {
33
- const parsed = (0, _postcssValueParser.default)(value);
24
+ const parsed = valueParser(value);
34
25
 
35
26
  if (parsed.nodes.length === 1) {
36
27
  return value;
@@ -39,45 +30,51 @@ function transform(value) {
39
30
  const ranges = [];
40
31
  let rangeIndex = 0;
41
32
  let shouldContinue = true;
33
+
42
34
  parsed.nodes.forEach((node, index) => {
43
35
  // After comma (`,`) follows next background
44
36
  if (isCommaNode(node)) {
45
37
  rangeIndex += 1;
46
38
  shouldContinue = true;
39
+
47
40
  return;
48
41
  }
49
42
 
50
43
  if (!shouldContinue) {
51
44
  return;
52
- } // After separator (`/`) follows `background-size` values
53
- // Avoid them
54
-
45
+ }
55
46
 
47
+ // After separator (`/`) follows `background-size` values
48
+ // Avoid them
56
49
  if (node.type === 'div' && node.value === '/') {
57
50
  shouldContinue = false;
51
+
58
52
  return;
59
53
  }
60
54
 
61
55
  if (!ranges[rangeIndex]) {
62
56
  ranges[rangeIndex] = {
63
57
  start: null,
64
- end: null
58
+ end: null,
65
59
  };
66
- } // Do not try to be processed `var and `env` function inside background
67
-
60
+ }
68
61
 
62
+ // Do not try to be processed `var and `env` function inside background
69
63
  if (isVariableFunctionNode(node)) {
70
64
  shouldContinue = false;
71
65
  ranges[rangeIndex].start = null;
72
66
  ranges[rangeIndex].end = null;
67
+
73
68
  return;
74
69
  }
75
70
 
76
- const isRepeatKeyword = node.type === 'word' && repeatKeywords.has(node.value.toLowerCase());
71
+ const isRepeatKeyword =
72
+ node.type === 'word' && repeatKeywords.has(node.value.toLowerCase());
77
73
 
78
74
  if (ranges[rangeIndex].start === null && isRepeatKeyword) {
79
75
  ranges[rangeIndex].start = index;
80
76
  ranges[rangeIndex].end = index;
77
+
81
78
  return;
82
79
  }
83
80
 
@@ -86,13 +83,15 @@ function transform(value) {
86
83
  return;
87
84
  } else if (isRepeatKeyword) {
88
85
  ranges[rangeIndex].end = index;
86
+
89
87
  return;
90
88
  }
91
89
 
92
90
  return;
93
91
  }
94
92
  });
95
- ranges.forEach(range => {
93
+
94
+ ranges.forEach((range) => {
96
95
  if (range.start === null) {
97
96
  return;
98
97
  }
@@ -102,52 +101,55 @@ function transform(value) {
102
101
  if (nodes.length !== 3) {
103
102
  return;
104
103
  }
104
+ const key = nodes
105
+ .filter(evenValues)
106
+ .map((n) => n.value.toLowerCase())
107
+ .toString();
105
108
 
106
- const key = nodes.filter(evenValues).map(n => n.value.toLowerCase()).toString();
107
-
108
- const match = _map.default.get(key);
109
+ const match = mappings.get(key);
109
110
 
110
111
  if (match) {
111
112
  nodes[0].value = match;
112
113
  nodes[1].value = nodes[2].value = '';
113
114
  }
114
115
  });
116
+
115
117
  return parsed.toString();
116
118
  }
117
119
 
118
120
  function pluginCreator() {
119
121
  return {
120
122
  postcssPlugin: 'postcss-normalize-repeat-style',
121
-
122
123
  prepare() {
123
124
  const cache = new Map();
124
125
  return {
125
126
  OnceExit(css) {
126
- css.walkDecls(/^(background(-repeat)?|(-\w+-)?mask-repeat)$/i, decl => {
127
- const value = decl.value;
127
+ css.walkDecls(
128
+ /^(background(-repeat)?|(-\w+-)?mask-repeat)$/i,
129
+ (decl) => {
130
+ const value = decl.value;
128
131
 
129
- if (!value) {
130
- return;
131
- }
132
+ if (!value) {
133
+ return;
134
+ }
132
135
 
133
- if (cache.has(value)) {
134
- decl.value = cache.get(value);
135
- return;
136
- }
136
+ if (cache.has(value)) {
137
+ decl.value = cache.get(value);
137
138
 
138
- const result = transform(value);
139
- decl.value = result;
140
- cache.set(value, result);
141
- });
142
- }
139
+ return;
140
+ }
143
141
 
144
- };
145
- }
142
+ const result = transform(value);
146
143
 
144
+ decl.value = result;
145
+ cache.set(value, result);
146
+ }
147
+ );
148
+ },
149
+ };
150
+ },
147
151
  };
148
152
  }
149
153
 
150
154
  pluginCreator.postcss = true;
151
- var _default = pluginCreator;
152
- exports.default = _default;
153
- 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/dist/lib/map.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _default = new Map([[['repeat', 'no-repeat'].toString(), 'repeat-x'], [['no-repeat', 'repeat'].toString(), 'repeat-y'], [['repeat', 'repeat'].toString(), 'repeat'], [['space', 'space'].toString(), 'space'], [['round', 'round'].toString(), 'round'], [['no-repeat', 'no-repeat'].toString(), 'no-repeat']]);
9
-
10
- exports.default = _default;
11
- module.exports = exports.default;