autoprefixer 7.1.6 → 7.2.3

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.
@@ -0,0 +1,160 @@
1
+ 'use strict';
2
+
3
+ var parser = require('postcss-value-parser');
4
+
5
+ function convert(value) {
6
+ if (value && value.length === 2 && value[0] === 'span' && parseInt(value[1], 10) > 0) {
7
+ return [false, parseInt(value[1], 10)];
8
+ }
9
+
10
+ if (value && value.length === 1 && parseInt(value[0], 10) > 0) {
11
+ return [parseInt(value[0], 10), false];
12
+ }
13
+
14
+ return [false, false];
15
+ }
16
+
17
+ function translate(values, startIndex, endIndex) {
18
+ var startValue = values[startIndex];
19
+ var endValue = values[endIndex];
20
+
21
+ if (!startValue) {
22
+ return [false, false];
23
+ }
24
+
25
+ var _convert = convert(startValue),
26
+ start = _convert[0],
27
+ spanStart = _convert[1];
28
+
29
+ var _convert2 = convert(endValue),
30
+ end = _convert2[0],
31
+ spanEnd = _convert2[1];
32
+
33
+ if (start && !endValue) {
34
+ return [start, false];
35
+ }
36
+
37
+ if (spanStart && end) {
38
+ return [end - spanStart, spanStart];
39
+ }
40
+
41
+ if (start && spanEnd) {
42
+ return [start, spanEnd];
43
+ }
44
+
45
+ if (start && end) {
46
+ return [start, end - start];
47
+ }
48
+
49
+ return [false, false];
50
+ }
51
+
52
+ function parse(decl) {
53
+ var node = parser(decl.value);
54
+
55
+ var values = [];
56
+ var current = 0;
57
+ values[current] = [];
58
+
59
+ for (var _iterator = node.nodes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
60
+ var _ref;
61
+
62
+ if (_isArray) {
63
+ if (_i >= _iterator.length) break;
64
+ _ref = _iterator[_i++];
65
+ } else {
66
+ _i = _iterator.next();
67
+ if (_i.done) break;
68
+ _ref = _i.value;
69
+ }
70
+
71
+ var i = _ref;
72
+
73
+ if (i.type === 'div') {
74
+ current += 1;
75
+ values[current] = [];
76
+ } else if (i.type === 'word') {
77
+ values[current].push(i.value);
78
+ }
79
+ }
80
+
81
+ return values;
82
+ }
83
+
84
+ function parseTemplateShortcut(decl) {
85
+ var node = parser(decl.value, { loose: true });
86
+
87
+ var values = [];
88
+ var current = 0;
89
+ values[current] = [];
90
+
91
+ for (var _iterator2 = node.nodes, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
92
+ var _ref2;
93
+
94
+ if (_isArray2) {
95
+ if (_i2 >= _iterator2.length) break;
96
+ _ref2 = _iterator2[_i2++];
97
+ } else {
98
+ _i2 = _iterator2.next();
99
+ if (_i2.done) break;
100
+ _ref2 = _i2.value;
101
+ }
102
+
103
+ var i = _ref2;
104
+
105
+ if (i.type === 'div') {
106
+ current += 1;
107
+ values[current] = [];
108
+ } else {
109
+ values[current].push(parser.stringify(i));
110
+ }
111
+ }
112
+
113
+ return values;
114
+ }
115
+
116
+ function walkRepeat(node) {
117
+ var fixed = [];
118
+ for (var _iterator3 = node.nodes, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
119
+ var _ref3;
120
+
121
+ if (_isArray3) {
122
+ if (_i3 >= _iterator3.length) break;
123
+ _ref3 = _iterator3[_i3++];
124
+ } else {
125
+ _i3 = _iterator3.next();
126
+ if (_i3.done) break;
127
+ _ref3 = _i3.value;
128
+ }
129
+
130
+ var i = _ref3;
131
+
132
+ if (i.nodes) {
133
+ walkRepeat(i);
134
+ }
135
+ fixed.push(i);
136
+ if (i.type === 'function' && i.value === 'repeat') {
137
+ var first = i.nodes.shift();
138
+ if (first) {
139
+ var count = first.value;
140
+ i.nodes.shift();
141
+ i.value = '';
142
+ fixed.push({ type: 'word', value: '[' + count + ']' });
143
+ }
144
+ }
145
+ }
146
+ node.nodes = fixed;
147
+ }
148
+
149
+ function changeRepeat(value) {
150
+ var ast = parser(value);
151
+ walkRepeat(ast);
152
+ return ast.toString();
153
+ }
154
+
155
+ module.exports = {
156
+ parse: parse,
157
+ translate: translate,
158
+ changeRepeat: changeRepeat,
159
+ parseTemplateShortcut: parseTemplateShortcut
160
+ };
@@ -21,7 +21,8 @@ var GridStart = function (_Declaration) {
21
21
  * Do not add prefix for unsupported value in IE
22
22
  */
23
23
  GridStart.prototype.check = function check(decl) {
24
- return decl.value.indexOf('/') === -1 || decl.value.indexOf('span') !== -1;
24
+ var value = decl.value;
25
+ return value.indexOf('/') === -1 || value.indexOf('span') !== -1;
25
26
  };
26
27
 
27
28
  /**
@@ -39,55 +40,11 @@ var GridStart = function (_Declaration) {
39
40
 
40
41
 
41
42
  GridStart.prototype.prefixed = function prefixed(prop, prefix) {
43
+ var result = _Declaration.prototype.prefixed.call(this, prop, prefix);
42
44
  if (prefix === '-ms-') {
43
- return prefix + prop.replace('-start', '');
44
- } else {
45
- return _Declaration.prototype.prefixed.call(this, prop, prefix);
45
+ result = result.replace('-start', '');
46
46
  }
47
- };
48
-
49
- /**
50
- * Split one value to two
51
- */
52
-
53
-
54
- GridStart.prototype.insert = function insert(decl, prefix, prefixes) {
55
- var parts = this.splitValue(decl, prefix);
56
- if (parts.length === 2) {
57
- decl.cloneBefore({
58
- prop: '-ms-' + decl.prop + '-span',
59
- value: parts[1]
60
- });
61
- }
62
- return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
63
- };
64
-
65
- /**
66
- * Change value for combine property
67
- */
68
-
69
-
70
- GridStart.prototype.set = function set(decl, prefix) {
71
- var parts = this.splitValue(decl, prefix);
72
- if (parts.length === 2) {
73
- decl.value = parts[0];
74
- }
75
- return _Declaration.prototype.set.call(this, decl, prefix);
76
- };
77
-
78
- /**
79
- * If property contains start and end
80
- */
81
-
82
-
83
- GridStart.prototype.splitValue = function splitValue(decl, prefix) {
84
- if (prefix === '-ms-' && decl.prop.indexOf('-start') === -1) {
85
- var parts = decl.value.split(/\s*\/\s*span\s+/);
86
- if (parts.length === 2) {
87
- return parts;
88
- }
89
- }
90
- return false;
47
+ return result;
91
48
  };
92
49
 
93
50
  return GridStart;
@@ -96,7 +53,7 @@ var GridStart = function (_Declaration) {
96
53
  Object.defineProperty(GridStart, 'names', {
97
54
  enumerable: true,
98
55
  writable: true,
99
- value: ['grid-row-start', 'grid-column-start', 'grid-row', 'grid-column']
56
+ value: ['grid-row-start', 'grid-column-start']
100
57
  });
101
58
 
102
59
 
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+
5
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
6
+
7
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
8
+
9
+ var Declaration = require('../declaration');
10
+
11
+ var DOTS = /^\.+$/;
12
+
13
+ function track(start, end) {
14
+ return { start: start, end: end, span: end - start };
15
+ }
16
+
17
+ function getRows(tpl) {
18
+ return tpl.trim().slice(1, -1).split(/['"]\s*['"]?/g);
19
+ }
20
+
21
+ function getColumns(line) {
22
+ return line.trim().split(/\s+/g);
23
+ }
24
+
25
+ function parseGridAreas(tpl) {
26
+ return getRows(tpl).reduce(function (areas, line, rowIndex) {
27
+ if (line.trim() === '') return areas;
28
+ getColumns(line).forEach(function (area, columnIndex) {
29
+ if (DOTS.test(area)) return;
30
+ if (typeof areas[area] === 'undefined') {
31
+ areas[area] = {
32
+ column: track(columnIndex + 1, columnIndex + 2),
33
+ row: track(rowIndex + 1, rowIndex + 2)
34
+ };
35
+ } else {
36
+ var _areas$area = areas[area],
37
+ column = _areas$area.column,
38
+ row = _areas$area.row;
39
+
40
+
41
+ column.start = Math.min(column.start, columnIndex + 1);
42
+ column.end = Math.max(column.end, columnIndex + 2);
43
+ column.span = column.end - column.start;
44
+
45
+ row.start = Math.min(row.start, rowIndex + 1);
46
+ row.end = Math.max(row.end, rowIndex + 2);
47
+ row.span = row.end - row.start;
48
+ }
49
+ });
50
+ return areas;
51
+ }, {});
52
+ }
53
+
54
+ var GridTemplateAreas = function (_Declaration) {
55
+ _inherits(GridTemplateAreas, _Declaration);
56
+
57
+ function GridTemplateAreas() {
58
+ _classCallCheck(this, GridTemplateAreas);
59
+
60
+ return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
61
+ }
62
+
63
+ GridTemplateAreas.prototype.getRoot = function getRoot(parent) {
64
+ if (parent.type === 'atrule' || !parent.parent) {
65
+ return parent;
66
+ }
67
+ return this.getRoot(parent.parent);
68
+ };
69
+
70
+ /**
71
+ * Translate grid-template-areas to separate -ms- prefixed properties
72
+ */
73
+
74
+
75
+ GridTemplateAreas.prototype.insert = function insert(decl, prefix, prefixes, result) {
76
+ if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
77
+
78
+ var areas = parseGridAreas(decl.value);
79
+ this.getRoot(decl.parent).walkDecls('grid-area', function (gridArea) {
80
+ var value = gridArea.value;
81
+ var area = areas[value];
82
+ delete areas[value];
83
+
84
+ if (gridArea.parent.some(function (i) {
85
+ return i.prop === '-ms-grid-row';
86
+ })) {
87
+ return undefined;
88
+ }
89
+
90
+ if (area) {
91
+ gridArea.cloneBefore({
92
+ prop: '-ms-grid-row',
93
+ value: String(area.row.start)
94
+ });
95
+ if (area.row.span > 1) {
96
+ gridArea.cloneBefore({
97
+ prop: '-ms-grid-row-span',
98
+ value: String(area.row.span)
99
+ });
100
+ }
101
+ gridArea.cloneBefore({
102
+ prop: '-ms-grid-column',
103
+ value: String(area.column.start)
104
+ });
105
+ if (area.column.span > 1) {
106
+ gridArea.cloneBefore({
107
+ prop: '-ms-grid-column-span',
108
+ value: String(area.column.span)
109
+ });
110
+ }
111
+ }
112
+ return undefined;
113
+ });
114
+
115
+ var missed = Object.keys(areas);
116
+ if (missed.length > 0) {
117
+ decl.warn(result, 'Can not find grid areas: ' + missed.join(', '));
118
+ }
119
+
120
+ return decl;
121
+ };
122
+
123
+ return GridTemplateAreas;
124
+ }(Declaration);
125
+
126
+ Object.defineProperty(GridTemplateAreas, 'names', {
127
+ enumerable: true,
128
+ writable: true,
129
+ value: ['grid-template-areas']
130
+ });
131
+
132
+
133
+ module.exports = GridTemplateAreas;
@@ -6,9 +6,8 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
6
6
 
7
7
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
8
8
 
9
- var parser = require('postcss-value-parser');
10
-
11
9
  var Declaration = require('../declaration');
10
+ var shorthand = require('./grid-shorthand');
12
11
 
13
12
  var GridTemplate = function (_Declaration) {
14
13
  _inherits(GridTemplate, _Declaration);
@@ -20,84 +19,45 @@ var GridTemplate = function (_Declaration) {
20
19
  }
21
20
 
22
21
  /**
23
- * Change property name for IE
22
+ * Do not add prefix for unsupported value in IE
24
23
  */
25
- GridTemplate.prototype.prefixed = function prefixed(prop, prefix) {
26
- if (prefix === '-ms-') {
27
- return prefix + prop.replace('template-', '');
28
- } else {
29
- return _Declaration.prototype.prefixed.call(this, prop, prefix);
30
- }
24
+ GridTemplate.prototype.check = function check(decl) {
25
+ return decl.value.includes('/') && !decl.value.includes('[') && !decl.value.includes('"') && !decl.value.includes('\'');
31
26
  };
32
27
 
33
28
  /**
34
- * Change IE property back
29
+ * Translate grid-template to separate -ms- prefixed properties
35
30
  */
36
31
 
37
32
 
38
- GridTemplate.prototype.normalize = function normalize(prop) {
39
- return prop.replace(/^grid-(rows|columns)/, 'grid-template-$1');
40
- };
33
+ GridTemplate.prototype.insert = function insert(decl, prefix, prefixes) {
34
+ if (prefix !== '-ms-') return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
41
35
 
42
- /**
43
- * Recursive part of changeRepeat
44
- */
45
-
46
-
47
- GridTemplate.prototype.walkRepeat = function walkRepeat(node) {
48
- var fixed = [];
49
- for (var _iterator = node.nodes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
50
- var _ref;
51
-
52
- if (_isArray) {
53
- if (_i >= _iterator.length) break;
54
- _ref = _iterator[_i++];
55
- } else {
56
- _i = _iterator.next();
57
- if (_i.done) break;
58
- _ref = _i.value;
59
- }
60
-
61
- var i = _ref;
62
-
63
- if (i.nodes) {
64
- this.walkRepeat(i);
65
- }
66
- fixed.push(i);
67
- if (i.type === 'function' && i.value === 'repeat') {
68
- var first = i.nodes.shift();
69
- if (first) {
70
- var count = first.value;
71
- i.nodes.shift();
72
- i.value = '';
73
- fixed.push({ type: 'word', value: '[' + count + ']' });
74
- }
75
- }
36
+ if (decl.parent.some(function (i) {
37
+ return i.prop === '-ms-grid-rows';
38
+ })) {
39
+ return undefined;
76
40
  }
77
- node.nodes = fixed;
78
- };
79
-
80
- /**
81
- * IE repeating syntax
82
- */
83
41
 
42
+ var _shorthand$parseTempl = shorthand.parseTemplateShortcut(decl),
43
+ templateRows = _shorthand$parseTempl[0],
44
+ templateColumns = _shorthand$parseTempl[1];
84
45
 
85
- GridTemplate.prototype.changeRepeat = function changeRepeat(value) {
86
- var ast = parser(value);
87
- this.walkRepeat(ast);
88
- return ast.toString();
89
- };
90
-
91
- /**
92
- * Change repeating syntax for IE
93
- */
94
-
46
+ if (templateRows) {
47
+ decl.cloneBefore({
48
+ prop: '-ms-grid-rows',
49
+ value: shorthand.changeRepeat(templateRows.join(''))
50
+ });
51
+ }
95
52
 
96
- GridTemplate.prototype.set = function set(decl, prefix) {
97
- if (prefix === '-ms-' && decl.value.indexOf('repeat(') !== -1) {
98
- decl.value = this.changeRepeat(decl.value);
53
+ if (templateColumns) {
54
+ decl.cloneBefore({
55
+ prop: '-ms-grid-columns',
56
+ value: shorthand.changeRepeat(templateColumns.join(''))
57
+ });
99
58
  }
100
- return _Declaration.prototype.set.call(this, decl, prefix);
59
+
60
+ return decl;
101
61
  };
102
62
 
103
63
  return GridTemplate;
@@ -106,7 +66,7 @@ var GridTemplate = function (_Declaration) {
106
66
  Object.defineProperty(GridTemplate, 'names', {
107
67
  enumerable: true,
108
68
  writable: true,
109
- value: ['grid-template-rows', 'grid-template-columns', 'grid-rows', 'grid-columns']
69
+ value: ['grid-template']
110
70
  });
111
71
 
112
72
 
@@ -43,13 +43,10 @@ var ImageRendering = function (_Declaration) {
43
43
 
44
44
 
45
45
  ImageRendering.prototype.set = function set(decl, prefix) {
46
- if (prefix === '-ms-') {
47
- decl.prop = '-ms-interpolation-mode';
48
- decl.value = 'nearest-neighbor';
49
- return decl;
50
- } else {
51
- return _Declaration.prototype.set.call(this, decl, prefix);
52
- }
46
+ if (prefix !== '-ms-') return _Declaration.prototype.set.call(this, decl, prefix);
47
+ decl.prop = '-ms-interpolation-mode';
48
+ decl.value = 'nearest-neighbor';
49
+ return decl;
53
50
  };
54
51
 
55
52
  /**
@@ -21,11 +21,11 @@ var ImageSet = function (_Value) {
21
21
  * Use non-standard name for WebKit and Firefox
22
22
  */
23
23
  ImageSet.prototype.replace = function replace(string, prefix) {
24
+ var fixed = _Value.prototype.replace.call(this, string, prefix);
24
25
  if (prefix === '-webkit-') {
25
- return _Value.prototype.replace.call(this, string, prefix).replace(/("[^"]+"|'[^']+')(\s+\d+\w)/gi, 'url($1)$2');
26
- } else {
27
- return _Value.prototype.replace.call(this, string, prefix);
26
+ fixed = fixed.replace(/("[^"]+"|'[^']+')(\s+\d+\w)/gi, 'url($1)$2');
28
27
  }
28
+ return fixed;
29
29
  };
30
30
 
31
31
  return ImageSet;
@@ -30,11 +30,11 @@ var MaskBorder = function (_Declaration) {
30
30
 
31
31
 
32
32
  MaskBorder.prototype.prefixed = function prefixed(prop, prefix) {
33
+ var result = _Declaration.prototype.prefixed.call(this, prop, prefix);
33
34
  if (prefix === '-webkit-') {
34
- return _Declaration.prototype.prefixed.call(this, prop, prefix).replace('border', 'box-image');
35
- } else {
36
- return _Declaration.prototype.prefixed.call(this, prop, prefix);
35
+ result = result.replace('border', 'box-image');
37
36
  }
37
+ return result;
38
38
  };
39
39
 
40
40
  return MaskBorder;
@@ -20,10 +20,8 @@ var TextEmphasisPosition = function (_Declaration) {
20
20
  TextEmphasisPosition.prototype.set = function set(decl, prefix) {
21
21
  if (prefix === '-webkit-') {
22
22
  decl.value = decl.value.replace(/\s*(right|left)\s*/i, '');
23
- return _Declaration.prototype.set.call(this, decl, prefix);
24
- } else {
25
- return _Declaration.prototype.set.call(this, decl, prefix);
26
23
  }
24
+ return _Declaration.prototype.set.call(this, decl, prefix);
27
25
  };
28
26
 
29
27
  return TextEmphasisPosition;
@@ -34,7 +34,7 @@ var TransformDecl = function (_Declaration) {
34
34
  };
35
35
 
36
36
  /**
37
- * Is transform caontain 3D commands
37
+ * Is transform contain 3D commands
38
38
  */
39
39
 
40
40
 
package/lib/prefixer.js CHANGED
@@ -34,9 +34,7 @@ function _clone(obj, parent) {
34
34
  if (parent) {
35
35
  cloned[i] = parent;
36
36
  }
37
- } else if (i === 'source') {
38
- cloned[i] = value;
39
- } else if (i === null) {
37
+ } else if (i === 'source' || i === null) {
40
38
  cloned[i] = value;
41
39
  } else if (value instanceof Array) {
42
40
  cloned[i] = value.map(function (x) {
@@ -141,7 +139,7 @@ var Prefixer = function () {
141
139
  */
142
140
 
143
141
 
144
- Prefixer.prototype.process = function process(node) {
142
+ Prefixer.prototype.process = function process(node, result) {
145
143
  if (!this.check(node)) {
146
144
  return undefined;
147
145
  }
@@ -167,7 +165,7 @@ var Prefixer = function () {
167
165
 
168
166
  var prefix = _ref2;
169
167
 
170
- if (this.add(node, prefix, added.concat([prefix]))) {
168
+ if (this.add(node, prefix, added.concat([prefix]), result)) {
171
169
  added.push(prefix);
172
170
  }
173
171
  }
package/lib/prefixes.js CHANGED
@@ -22,9 +22,11 @@ Declaration.hack(require('./hacks/flex'));
22
22
  Declaration.hack(require('./hacks/order'));
23
23
  Declaration.hack(require('./hacks/filter'));
24
24
  Declaration.hack(require('./hacks/grid-end'));
25
+ Declaration.hack(require('./hacks/animation'));
25
26
  Declaration.hack(require('./hacks/flex-flow'));
26
27
  Declaration.hack(require('./hacks/flex-grow'));
27
28
  Declaration.hack(require('./hacks/flex-wrap'));
29
+ Declaration.hack(require('./hacks/grid-area'));
28
30
  Declaration.hack(require('./hacks/grid-start'));
29
31
  Declaration.hack(require('./hacks/align-self'));
30
32
  Declaration.hack(require('./hacks/appearance'));
@@ -47,7 +49,10 @@ Declaration.hack(require('./hacks/image-rendering'));
47
49
  Declaration.hack(require('./hacks/text-decoration'));
48
50
  Declaration.hack(require('./hacks/justify-content'));
49
51
  Declaration.hack(require('./hacks/background-size'));
52
+ Declaration.hack(require('./hacks/grid-row-column'));
53
+ Declaration.hack(require('./hacks/grid-rows-columns'));
50
54
  Declaration.hack(require('./hacks/grid-column-align'));
55
+ Declaration.hack(require('./hacks/grid-template-areas'));
51
56
  Declaration.hack(require('./hacks/text-emphasis-position'));
52
57
 
53
58
  Value.hack(require('./hacks/gradient'));
@@ -55,7 +60,6 @@ Value.hack(require('./hacks/intrinsic'));
55
60
  Value.hack(require('./hacks/pixelated'));
56
61
  Value.hack(require('./hacks/image-set'));
57
62
  Value.hack(require('./hacks/cross-fade'));
58
- Value.hack(require('./hacks/flex-values'));
59
63
  Value.hack(require('./hacks/display-flex'));
60
64
  Value.hack(require('./hacks/display-grid'));
61
65
  Value.hack(require('./hacks/filter-value'));