postcss-normalize-repeat-style 4.0.0-nightly.2020.9.3 → 4.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,4 @@
1
+ # 4.0.0-rc.0
2
+
3
+ * Initial commit. This module was previously part of other cssnano modules and
4
+ has been extracted out.
package/dist/index.js CHANGED
@@ -1,145 +1,89 @@
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;
7
6
 
8
- var _postcss = _interopRequireDefault(require("postcss"));
7
+ var _postcss = require('postcss');
9
8
 
10
- var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
9
+ var _postcss2 = _interopRequireDefault(_postcss);
11
10
 
12
- var _cssnanoUtils = require("cssnano-utils");
11
+ var _postcssValueParser = require('postcss-value-parser');
13
12
 
14
- var _map = _interopRequireDefault(require("./lib/map"));
13
+ var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
15
14
 
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function evenValues(list, index) {
19
- return index % 2 === 0;
20
- }
21
-
22
- const repeatKeywords = _map.default.map(mapping => mapping[0]);
23
-
24
- const getMatch = (0, _cssnanoUtils.getMatch)(_map.default);
25
-
26
- function isCommaNode(node) {
27
- return node.type === 'div' && node.value === ',';
28
- }
29
-
30
- function isVariableFunctionNode(node) {
31
- if (node.type !== 'function') {
32
- return false;
33
- }
15
+ var _cssnanoUtilGetArguments = require('cssnano-util-get-arguments');
34
16
 
35
- return ['var', 'env'].includes(node.value.toLowerCase());
36
- }
17
+ var _cssnanoUtilGetArguments2 = _interopRequireDefault(_cssnanoUtilGetArguments);
37
18
 
38
- function transform(value) {
39
- const parsed = (0, _postcssValueParser.default)(value);
40
-
41
- if (parsed.nodes.length === 1) {
42
- return value;
43
- }
44
-
45
- const ranges = [];
46
- let rangeIndex = 0;
47
- let shouldContinue = true;
48
- parsed.nodes.forEach((node, index) => {
49
- // After comma (`,`) follows next background
50
- if (isCommaNode(node)) {
51
- rangeIndex += 1;
52
- shouldContinue = true;
53
- return;
54
- }
19
+ var _cssnanoUtilGetMatch = require('cssnano-util-get-match');
55
20
 
56
- if (!shouldContinue) {
57
- return;
58
- } // After separator (`/`) follows `background-size` values
59
- // Avoid them
21
+ var _cssnanoUtilGetMatch2 = _interopRequireDefault(_cssnanoUtilGetMatch);
60
22
 
23
+ var _map = require('./lib/map');
61
24
 
62
- if (node.type === 'div' && node.value === '/') {
63
- shouldContinue = false;
64
- return;
65
- }
66
-
67
- if (!ranges[rangeIndex]) {
68
- ranges[rangeIndex] = {
69
- start: null,
70
- end: null
71
- };
72
- } // Do not try to be processed `var and `env` function inside background
25
+ var _map2 = _interopRequireDefault(_map);
73
26
 
27
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
74
28
 
75
- if (isVariableFunctionNode(node)) {
76
- shouldContinue = false;
77
- ranges[rangeIndex].start = null;
78
- ranges[rangeIndex].end = null;
79
- return;
80
- }
29
+ function evenValues(list, index) {
30
+ return index % 2 === 0;
31
+ }
81
32
 
82
- const isRepeatKeyword = node.type === 'word' && repeatKeywords.includes(node.value.toLowerCase());
33
+ const repeatKeywords = _map2.default.map(mapping => mapping[0]);
83
34
 
84
- if (ranges[rangeIndex].start === null && isRepeatKeyword) {
85
- ranges[rangeIndex].start = index;
86
- ranges[rangeIndex].end = index;
87
- return;
88
- }
35
+ const getMatch = (0, _cssnanoUtilGetMatch2.default)(_map2.default);
89
36
 
90
- if (ranges[rangeIndex].start !== null) {
91
- if (node.type === 'space') {
37
+ function transform(decl) {
38
+ const values = (0, _postcssValueParser2.default)(decl.value);
39
+ if (values.nodes.length === 1) {
92
40
  return;
93
- } else if (isRepeatKeyword) {
94
- ranges[rangeIndex].end = index;
95
- return;
96
- }
97
-
98
- return;
99
- }
100
- });
101
- ranges.forEach(range => {
102
- if (range.start === null) {
103
- return;
104
- }
105
-
106
- const nodes = parsed.nodes.slice(range.start, range.end + 1);
107
-
108
- if (nodes.length !== 3) {
109
- return;
110
- }
111
-
112
- const match = getMatch(nodes.filter(evenValues).map(n => n.value.toLowerCase()));
113
-
114
- if (match) {
115
- nodes[0].value = match;
116
- nodes[1].value = nodes[2].value = '';
117
41
  }
118
- });
119
- return parsed.toString();
42
+ const args = (0, _cssnanoUtilGetArguments2.default)(values);
43
+ const relevant = [];
44
+ args.forEach(arg => {
45
+ relevant.push({
46
+ start: null,
47
+ end: null
48
+ });
49
+ arg.forEach((part, index) => {
50
+ const isRepeat = ~repeatKeywords.indexOf(part.value.toLowerCase());
51
+ const len = relevant.length - 1;
52
+ if (relevant[len].start === null && isRepeat) {
53
+ relevant[len].start = index;
54
+ relevant[len].end = index;
55
+ return;
56
+ }
57
+ if (relevant[len].start !== null) {
58
+ if (part.type === 'space') {
59
+ return;
60
+ } else if (isRepeat) {
61
+ relevant[len].end = index;
62
+ return;
63
+ }
64
+ return;
65
+ }
66
+ });
67
+ });
68
+ relevant.forEach((range, index) => {
69
+ if (range.start === null) {
70
+ return;
71
+ }
72
+ const val = args[index].slice(range.start, range.end + 1);
73
+ if (val.length !== 3) {
74
+ return;
75
+ }
76
+ const match = getMatch(val.filter(evenValues).map(n => n.value.toLowerCase()));
77
+ if (match) {
78
+ args[index][range.start].value = match;
79
+ args[index][range.start + 1].value = '';
80
+ args[index][range.end].value = '';
81
+ }
82
+ });
83
+ decl.value = values.toString();
120
84
  }
121
85
 
122
- var _default = _postcss.default.plugin('postcss-normalize-repeat-style', () => {
123
- return css => {
124
- const cache = {};
125
- css.walkDecls(/^(background(-repeat)?|(-\w+-)?mask-repeat)$/i, decl => {
126
- const value = decl.value;
127
-
128
- if (!value) {
129
- return;
130
- }
131
-
132
- if (cache[value]) {
133
- decl.value = cache[value];
134
- return;
135
- }
136
-
137
- const result = transform(value);
138
- decl.value = result;
139
- cache[value] = result;
140
- });
141
- };
86
+ exports.default = _postcss2.default.plugin('postcss-normalize-repeat-style', () => {
87
+ return css => css.walkDecls(/background(-repeat)?|(-webkit-)?mask-repeat/i, transform);
142
88
  });
143
-
144
- exports.default = _default;
145
- module.exports = exports.default;
89
+ module.exports = exports['default'];
package/dist/lib/map.js CHANGED
@@ -1,9 +1,7 @@
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;
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;
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'];
package/package.json CHANGED
@@ -1,12 +1,10 @@
1
1
  {
2
2
  "name": "postcss-normalize-repeat-style",
3
- "version": "4.0.0-nightly.2020.9.3",
3
+ "version": "4.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
- "prebuild": "",
8
- "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
9
- "prepublish": ""
7
+ "prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
10
8
  },
11
9
  "files": [
12
10
  "LICENSE-MIT",
@@ -14,9 +12,14 @@
14
12
  ],
15
13
  "license": "MIT",
16
14
  "dependencies": {
17
- "cssnano-utils": "nightly",
18
- "postcss": "^7.0.16",
19
- "postcss-value-parser": "^3.3.1"
15
+ "cssnano-util-get-arguments": "^4.0.0",
16
+ "cssnano-util-get-match": "^4.0.0",
17
+ "postcss": "^6.0.0",
18
+ "postcss-value-parser": "^3.0.0"
19
+ },
20
+ "devDependencies": {
21
+ "babel-cli": "^6.0.0",
22
+ "cross-env": "^5.0.0"
20
23
  },
21
24
  "author": {
22
25
  "name": "Ben Briggs",
@@ -29,6 +32,6 @@
29
32
  },
30
33
  "homepage": "https://github.com/cssnano/cssnano",
31
34
  "engines": {
32
- "node": ">=10.13.0"
35
+ "node": ">=6.9.0"
33
36
  }
34
- }
37
+ }