postcss 2.2.2 → 2.2.6

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.

Potentially problematic release.


This version of postcss might be problematic. Click here for more details.

package/README.md CHANGED
@@ -1,24 +1,24 @@
1
1
  # PostCSS [![Build Status](https://travis-ci.org/postcss/postcss.png)](https://travis-ci.org/postcss/postcss)
2
2
 
3
- <img align="right" width="95" height="95" src="http://postcss.github.io/postcss/logo.png" title="Philosopher's stone, logo of PostCSS">
3
+ <img align="right" width="95" height="95" src="http://postcss.github.io/postcss/logo.png" title="Philosophers stone, logo of PostCSS">
4
4
 
5
5
  PostCSS is a framework for CSS postprocessors,
6
6
  to modify CSS with JavaScript with full source map support.
7
7
 
8
- It takes care of most common CSS tool tasks:
8
+ It takes care of the most common CSS tool tasks:
9
9
 
10
10
  1. parses CSS;
11
- 2. gives you usable JS API to edit CSS node tree;
12
- 3. dumps modified node tree into CSS string;
13
- 4. generates (or modifies existent) source map for your changes;
11
+ 2. provides a usable JS API to edit CSS node trees;
12
+ 3. dumps the modified node tree into a CSS string;
13
+ 4. generates a source map (or modifies an pre-existing source map) containing your changes;
14
14
 
15
- You can use this framework to write you own:
15
+ You can use this framework to write your own:
16
16
 
17
17
  * CSS minifier or beautifier.
18
18
  * CSS polyfills.
19
19
  * Grunt plugin to generate sprites, include `data-uri` images
20
- or any other works.
21
- * Text editor plugin to automate CSS routine.
20
+ or any other work.
21
+ * Text editor plugin to automate CSS routines.
22
22
  * Command-line CSS tool.
23
23
 
24
24
  Sponsored by [Evil Martians](http://evilmartians.com/).
@@ -28,54 +28,65 @@ Sponsored by [Evil Martians](http://evilmartians.com/).
28
28
  ### Tools
29
29
 
30
30
  * [Autoprefixer] adds vendor prefixes by Can I Use data.
31
+ * [BEM linter] lints CSS for SUIT CSS methodology.
31
32
  * [CSS MQPacker] joins same media queries.
32
33
  * [css2modernizr] analyzes your CSS and output only used Modernizr’s settings.
33
- * [cssnext] is a transpiler (CSS4+ to CSS3) that allow you to use tomorrow's CSS syntax today.
34
- * [CSSWring] and [grunt-csswring] CSS minifier with full source map support.
34
+ * [cssnext] is a transpiler (CSS4+ to CSS3) that allow you to use tomorrows
35
+ CSS syntax today.
36
+ * [CSSWring] is a CSS minifier with full source map support.
35
37
  * [data-separator] splits data-uri into a separate CSS file.
36
- * [grunt-pixrem], `rem` unit polyfill.
37
- * [grunt-webpcss] to duplicate images in CSS to WebP for supported browsers.
38
+ * [pixrem] is a `rem` unit polyfill.
39
+ * [webpcss] to duplicate images in CSS to WebP for supported browsers.
38
40
  * [Pleeease] is a pack of various postprocessors.
39
41
  * [Pleeease Filters] converts WebKit filters to SVG filter for other browsers.
40
42
  * [RTLCSS] mirrors styles for right-to-left locales.
41
-
42
- [Autoprefixer]: https://github.com/postcss/autoprefixer
43
- [CSS MQPacker]: https://github.com/hail2u/node-css-mqpacker
44
- [css2modernizr]: https://github.com/vovanbo/css2modernizr
45
- [cssnext]: https://github.com/putaindecode/cssnext
46
- [CSSWring]: https://github.com/hail2u/node-csswring
47
- [data-separator]: https://github.com/Sebastian-Fitzner/grunt-data-separator
48
- [grunt-csswring]: https://github.com/princed/grunt-csswring
49
- [grunt-pixrem]: https://github.com/robwierzbowski/grunt-pixrem
50
- [grunt-webpcss]: https://github.com/lexich/grunt-webpcss
51
- [Pleeease]: http://pleeease.io/
52
- [Pleeease Filters]: https://github.com/iamvdo/pleeease-filters
53
- [RTLCSS]: https://github.com/MohammadYounes/rtlcss
43
+ * [CSS Byebye] explicitly removes the CSS rules that you don't want.
44
+
45
+ [Autoprefixer]: https://github.com/postcss/autoprefixer
46
+ [BEM linter]: https://github.com/necolas/postcss-bem-linter
47
+ [CSS MQPacker]: https://github.com/hail2u/node-css-mqpacker
48
+ [css2modernizr]: https://github.com/vovanbo/css2modernizr
49
+ [cssnext]: https://github.com/putaindecode/cssnext
50
+ [CSSWring]: https://github.com/hail2u/node-csswring
51
+ [data-separator]: https://github.com/Sebastian-Fitzner/grunt-data-separator
52
+ [pixrem]: https://github.com/robwierzbowski/node-pixrem
53
+ [webpcss]: https://github.com/lexich/webpcss
54
+ [Pleeease]: http://pleeease.io/
55
+ [Pleeease Filters]: https://github.com/iamvdo/pleeease-filters
56
+ [RTLCSS]: https://github.com/MohammadYounes/rtlcss
57
+ [CSS Byebye]: https://github.com/AoDev/css-byebye
54
58
 
55
59
  ### Plugins
56
60
 
57
61
  * [postcss-calc] to reduce `calc()` usage
58
62
  (recommanded with `postcss-custom-properties`).
59
- * [postcss-color] to transform latest W3C CSS color module syntax
60
- to more compatible CSS.
61
- * [postcss-import] to transform @import rules by inlining content.
62
- * [postcss-custom-media] to transform W3C CSS Custom Media Queries
63
- to more compatible CSS.
64
- * [postcss-custom-properties] to transform W3C CSS Custom Properties
65
- for cascading variables to more compatible CSS.
63
+ * [postcss-color-function] to transform `color()` function.
64
+ * [postcss-color-gray] to transform `gray()` function.
65
+ * [postcss-color-hex-alpha] to transform hexadecimal notations with alpha
66
+ (`#rrggbbaa` or `#rgba`).
67
+ * [postcss-color-hwb] to transform `hwb()` function.
68
+ * [postcss-color-rebeccapurple] to transform `rebeccapurple` color.
69
+ * [postcss-import] to transform `@import` rules by inlining content.
70
+ * [postcss-custom-media] to add names for Media Queries.
71
+ * [postcss-custom-properties] to transform Custom Properties
72
+ for cascading variables.
66
73
  * [postcss-url] to rebase or inline on `url()`.
67
74
 
68
- [postcss-calc]: https://github.com/postcss/postcss-calc
69
- [postcss-color]: https://github.com/postcss/postcss-color
70
- [postcss-import]: https://github.com/postcss/postcss-import
71
- [postcss-custom-media]: https://github.com/postcss/postcss-custom-media
72
- [postcss-custom-properties]: https://github.com/postcss/postcss-custom-properties
73
- [postcss-url]: https://github.com/postcss/postcss-url
75
+ [postcss-calc]: https://github.com/postcss/postcss-calc
76
+ [postcss-color-function]: https://github.com/postcss/postcss-color-function
77
+ [postcss-color-gray]: https://github.com/postcss/postcss-color-gray
78
+ [postcss-color-hex-alpha]: https://github.com/postcss/postcss-color-hex-alpha
79
+ [postcss-color-hwb]: https://github.com/postcss/postcss-color-hwb
80
+ [postcss-color-rebeccapurple]: https://github.com/postcss/postcss-color-rebeccapurple
81
+ [postcss-import]: https://github.com/postcss/postcss-import
82
+ [postcss-custom-media]: https://github.com/postcss/postcss-custom-media
83
+ [postcss-custom-properties]: https://github.com/postcss/postcss-custom-properties
84
+ [postcss-url]: https://github.com/postcss/postcss-url
74
85
 
75
86
 
76
87
  ## Quick Example
77
88
 
78
- Let’s fix forgotten `content` property in `::before` and `::after`:
89
+ Let’s fix a forgotten `content` property in `::before` and `::after`:
79
90
 
80
91
  ```js
81
92
  var postcss = require('postcss');
@@ -83,9 +94,9 @@ var postcss = require('postcss');
83
94
  var contenter = postcss(function (css) {
84
95
  css.eachRule(function (rule) {
85
96
  if ( rule.selector.match(/::(before|after)/) ) {
86
- // In every ::before/::after rule
97
+ // In each ::before/::after rule
87
98
 
88
- // Did we forget content property?
99
+ // Did we forget the content property?
89
100
  var good = rule.some(function (i) { return i.prop == 'content'; });
90
101
 
91
102
  if ( !good ) {
@@ -98,7 +109,7 @@ var contenter = postcss(function (css) {
98
109
  });
99
110
  ```
100
111
 
101
- And then CSS with forgotten `content`:
112
+ And the CSS with a forgotten `content` property:
102
113
 
103
114
  ```css
104
115
  a::before {
@@ -127,7 +138,7 @@ a::before {
127
138
 
128
139
  ### Source Map
129
140
 
130
- PostCSS generates source map for its changes:
141
+ PostCSS generates a source map of its changes:
131
142
 
132
143
  ```js
133
144
  result = processor.process(css, { map: true, from: 'from.css', to: 'to.css' });
@@ -135,7 +146,7 @@ result.css // String with processed CSS
135
146
  result.map // Source map
136
147
  ```
137
148
 
138
- And modifies source map from previous step (like Sass preprocessor):
149
+ And modifies a source map from previous steps (for example, a Sass preprocessor):
139
150
 
140
151
  ```js
141
152
  var sass = compiler.compile(sass);
@@ -149,13 +160,13 @@ processor.process(sass.css, {
149
160
 
150
161
  ### Preserves code formatting and indentations
151
162
 
152
- PostCSS will not change any byte of a rule if you don’t modify its node:
163
+ PostCSS will not change any byte of a rule, if you do not modify its node:
153
164
 
154
165
  ```js
155
166
  postcss(function (css) { }).process(css).css == css;
156
167
  ```
157
168
 
158
- And when you modify CSS nodes, PostCSS will try to copy coding style:
169
+ And when you modify CSS nodes, PostCSS will try to copy the coding style:
159
170
 
160
171
  ```js
161
172
  contenter.process("a::before{color:black}")
@@ -168,90 +179,112 @@ contenter.process("a::before {\n color: black;\n }")
168
179
  // }
169
180
  ```
170
181
 
171
- It allows to use PostCSS in text editor plugin and preserve user code style.
182
+ Which allows you to use PostCSS in text editor plugins while preserving
183
+ the user’s code style.
172
184
 
173
185
  ## Why PostCSS Better Than …
174
186
 
175
187
  ### Preprocessors
176
188
 
177
- Preprocessors (like Sass or Stylus) give us special language with variables,
178
- mixins, statements and compile it to CSS. Compass, nib and other mixins
189
+ Preprocessors (like Sass or Stylus) give us special languages with variables,
190
+ mixins, and statements, which are compiled to CSS. Compass, nib and other mixins
179
191
  libraries use these languages to work with prefixes, sprites and inline images.
180
192
 
181
- But Sass and Stylus languages were created to be syntax-sugar for CSS.
182
- Writing really complicated programs using preporcessor languages
183
- is very difficult. [Autoprefixer] is absolutely impossible to implement
184
- on top of Sass.
193
+ But the Sass and Stylus languages were created to be syntax-sugar for CSS.
194
+ Writing complicated programs using preprocessor languages can be very difficult.
195
+ For example, it would be impossible to implement [Autoprefixer] on top of Sass.
185
196
 
186
- PostCSS gives you comfort and power of JS or CoffeeScript to working with CSS.
187
- You can do really magic things with wide range of [npm] libraries.
197
+ PostCSS gives you the comfort and power of JS or CoffeeScript while you are working
198
+ with CSS. Applying the depth and variety of [npm]’s libraries allows you to perform
199
+ quite magical things using PostCSS.
188
200
 
189
- But postprocessors are not enemies for preprocessors. Sass and Stylus are still
190
- the best way to improve readability and add some syntax sugar to CSS.
191
- You can easily combine preprocessors and postprocessors
192
- (and PostCSS will also update source map from Sass or Stylus).
201
+ An important point is that postprocessors are not the enemies of preprocessors.
202
+ Preprocessors and postprocessors can be easily combined, so that you can take
203
+ advantage of the readability and syntactical sugar offered by Sass and Stylus;
204
+ and PostCSS will preserve their source maps.
193
205
 
194
206
  [Autoprefixer]: https://github.com/postcss/autoprefixer
195
207
  [npm]: https://npmjs.org/
196
208
 
197
- ### RegExp
209
+ ### Regular Expressions
198
210
 
199
- Some Grunt plugins modify CSS with regular expressions but using a CSS parser
200
- and a node tree is a much safer way to edit CSS. Also, regexps will break
201
- source maps generated by preprocessors.
211
+ Some Grunt plugins modify CSS with regular expressions, however a parser
212
+ and its node tree provide a much safer interface to edit CSS. Furthermore,
213
+ regular expressions typically break the source maps generated by preprocessors.
202
214
 
203
215
  ### CSS Parsers
204
216
 
205
- There are a lot of good CSS parsers, like [Gonzales]. But they help you only
206
- with first step.
207
-
208
- Unlike them PostCSS gives you full source map support and useful high level API
209
- (for example, safe iterators).
217
+ There are a lot of good CSS parsers, such as [Gonzales], but they only help you
218
+ to read in the CSS. PostCSS provides you with full source map support and a
219
+ high level API. Safe iterators, and other features, are unique to PostCSS.
210
220
 
211
221
  [Gonzales]: https://github.com/css/gonzales
212
222
 
213
223
  ### Rework
214
224
 
215
- [Rework] and PostCSS are very similar, but they has different targets.
225
+ [Rework] and PostCSS are very similar, but they have different targets.
216
226
 
217
- Rework was created to build new CSS sublanguage to replace Stylus (like [Myth]).
218
- PostCSS was created for CSS tools, which works in chain with legacy CSS code
219
- (like Autoprefixer).
227
+ Rework was created to build a new CSS sublanguage that replaced Stylus (like [Myth]).
228
+ PostCSS was created for CSS tools which work with legacy CSS code (one such
229
+ tool is Autoprefixer).
220
230
 
221
- Because of this background difference, PostCSS:
231
+ Because of this fundamental difference, PostCSS:
222
232
 
223
- * Better works with source map, because it should update map from previous step
224
- (like Sass compiling).
225
- * Saves all your spaces and code style, because it can be worked in text editor
233
+ * Handles source map better, because it updates the map from the previous step
234
+ (for example, Sass compilation).
235
+ * Preserves all your spaces and code style, so that it can function in text editor
226
236
  plugins.
227
- * Has safer parser, because it can be used for legacy code. Only PostCSS can
228
- parse all hacks from [Browserhacks.com](http://browserhacks.com/).
229
- * Has high level API to clean your processor from common tasks.
237
+ * Has a safer parser, so that it can be used for legacy code. Only PostCSS can
238
+ parse all of the hacks from [Browserhacks.com](http://browserhacks.com/).
239
+ * Has a high level API to provide an simple interface for your processor to
240
+ perform typical tasks.
230
241
 
231
242
  [Myth]: http://www.myth.io/
232
243
  [Rework]: https://github.com/visionmedia/rework
233
244
 
234
245
  ## Usage
235
246
 
247
+ ### Grunt
248
+
249
+ Grunt plugin [grunt-postcss] allows you to pipe your CSS files through
250
+ an array of PostCSS processors.
251
+
252
+ ```js
253
+ grunt.initConfig({
254
+ postcss: {
255
+ options: {
256
+ map: true,
257
+ processors: [
258
+ require('autoprefixer-core').postcss,
259
+ require('csswring').postcss
260
+ ]
261
+ },
262
+ dist: {
263
+ src: 'css/*.css'
264
+ }
265
+ }
266
+ });
267
+
268
+ grunt.loadNpmTasks('grunt-postcss');
269
+ ```
270
+
271
+ [grunt-postcss]: https://github.com/nDmitry/grunt-postcss
272
+
236
273
  ### Gulp
237
274
 
238
- There is a gulp plugin for postcss called
239
- [gulp-postcss](https://github.com/w0rm/gulp-postcss)
240
- that allows to pipe your CSS files through array of PostCSS processors.
275
+ There is a Gulp plugin for PostCSS called [gulp-postcss] that allows you
276
+ to pipe your CSS files through an array of PostCSS processors.
241
277
 
242
- External source map is supported
243
- by [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps).
278
+ Support for external source maps is provided by [gulp-sourcemaps].
244
279
 
245
280
  ```js
246
- var gulp = require('gulp');
247
281
  var postcss = require('gulp-postcss');
248
282
  var sourcemaps = require('gulp-sourcemaps');
249
283
 
250
284
  gulp.task('css', function () {
251
285
  var processors = [
252
- require('autoprefixer')('last 1 version').postcss,
253
- require('css-mqpacker').processor,
254
- require('csswring').postcss
286
+ require('autoprefixer-core'),
287
+ require('csswring')
255
288
  ];
256
289
  return gulp.src('./src/style.css')
257
290
  .pipe(sourcemaps.init())
@@ -261,9 +294,34 @@ gulp.task('css', function () {
261
294
  });
262
295
  ```
263
296
 
297
+ [gulp-postcss]: https://github.com/w0rm/gulp-postcss
298
+ [gulp-sourcemaps]: https://github.com/floridoo/gulp-sourcemaps
299
+
300
+ ### Webpack
301
+
302
+ In [webpack] you can use [postcss-loader] to process CSS files through
303
+ an array of PostCSS processors.
304
+
305
+ ```js
306
+ module.exports = {
307
+ module: {
308
+ loaders: [
309
+ {
310
+ test: /\.css$/,
311
+ loader: "style-loader!css-loader!postcss-loader"
312
+ }
313
+ ]
314
+ },
315
+ postcss: [require('autoprefixer-core'), require('csswring')]
316
+ }
317
+ ```
318
+
319
+ [postcss-loader]: https://github.com/postcss/postcss-loader
320
+ [webpack]: http://webpack.github.io/
321
+
264
322
  ## Write Own Processor
265
323
 
266
- You can parse CSS by `postcss.parse()` method, which returns CSS AST:
324
+ You can parse CSS with the `postcss.parse()` method, which returns a CSS AST:
267
325
 
268
326
  ```js
269
327
  var postcss = require('postcss');
@@ -271,20 +329,21 @@ var postcss = require('postcss');
271
329
  var css = postcss.parse('a { color: black }');
272
330
  ```
273
331
 
274
- Then you can change this AST. Use `css.list` to get childs.
332
+ You can easily make changes to this AST. Use `css.list` to get children.
275
333
  Properties `rule.selector`, `decl.prop`, `decl.value`, `atrule.name`
276
334
  and `atrule.params` contain data.
277
335
 
278
- Don’t use underscore properties (like `_selector`, `_params` and `_value`),
279
- because they are only for comments save magic
280
- (See [Raw Properties](#raw-properties) below). Use getters and setters instead
281
- (like `selector`, `selectors`, `params` and `value`).
336
+ Try to avoid using underscore-prefixed properties (such as `_selector`, `_params` and `_value`),
337
+ as they are used for comment-preserving magic
338
+ (See [Raw Properties](#raw-properties) below). Use the getters and setters instead
339
+ (for example, `selector`, `selectors`, `params` and `value`).
282
340
 
283
341
  ```js
284
342
  css.list[0].value = 'white';
285
343
  ```
286
344
 
287
- After changes you can get new CSS and modification’s source map:
345
+ After changes have been made you can get the new CSS and a source map reflecting
346
+ the modifications:
288
347
 
289
348
  ```js
290
349
  var result = css.toResult(options);
@@ -293,8 +352,8 @@ result.css //=> 'a { color: white }'
293
352
  result.map //=> '{"version":3, … }'
294
353
  ```
295
354
 
296
- Methods `postcss.parse()` and `CSS#toResult()` are low level API, for most cases
297
- it will be better to create processors with simplier API and chaining.
355
+ The methods `postcss.parse()` and `CSS#toResult()` are part of a low level API, and -
356
+ in most cases - it will be better to create processors with a simpler API and chaining.
298
357
 
299
358
  ### Processor
300
359
 
@@ -308,7 +367,7 @@ var processor = postcss(function (css, opts) {
308
367
  });
309
368
  ```
310
369
 
311
- If you want to combine multiple processors (and parse CSS only once),
370
+ If you want to combine multiple processors (and parse the CSS only once),
312
371
  you can add several functions using the `use(fn)` method:
313
372
 
314
373
  ```js
@@ -317,14 +376,14 @@ var all = postcss().
317
376
  use(minifing);
318
377
  ```
319
378
 
320
- Also you can add processor object with `postcss` function:
379
+ You can also add processor objects with the `postcss` function:
321
380
 
322
381
  ```js
323
382
  postcss().use( autoprefixer.postcss ); // via function
324
383
  postcss().use( autoprefixer ); // via object
325
384
  ```
326
385
 
327
- Processor function can change the current CSS node tree:
386
+ A processor function can change the current CSS node tree:
328
387
 
329
388
  ```js
330
389
  postcss(function (css) {
@@ -342,7 +401,7 @@ postcss(function (css) {
342
401
  });
343
402
  ```
344
403
 
345
- This generated processor transforms some CSS using `process(css, opts)` method:
404
+ This generated processor transforms some CSS using the `process(css, opts)` method:
346
405
 
347
406
  ```js
348
407
  var doubler = postcss(function (css) {
@@ -358,8 +417,8 @@ var result = doubler.process(css);
358
417
  result.css //=> "a { color: black; color: black; }"
359
418
  ```
360
419
 
361
- You can set the original CSS filename via `from` option and make syntax error
362
- messages much more helpful:
420
+ You can change the original CSS filename via the `from` option, which
421
+ can make syntax error more helpful:
363
422
 
364
423
  ```js
365
424
  var wrong = "a {";
@@ -368,10 +427,10 @@ processor.process(wrong, { from: 'main.css' });
368
427
  ```
369
428
 
370
429
  Options from `process(css, opts)` will be sent to processors
371
- as seconds argument.
430
+ as the second argument.
372
431
 
373
- You can also use result from previous postprocessor or already parsed `Root`
374
- as argument in next one:
432
+ You can also use the result from a previous postprocessor, or
433
+ an already-parsed `Root`, as an argument to the next one:
375
434
 
376
435
  ```js
377
436
  result = processor1.process(css)
@@ -380,11 +439,11 @@ processor2.process(result)
380
439
 
381
440
  ### Multiple Inputs
382
441
 
383
- The function `postcss()` generates processor only for one input.
384
- If you need to process several inputs (like in files concatenation) you can use
385
- `postcss.parse()`.
442
+ The function `postcss()` generates a processor for only one input.
443
+ If you need to process several inputs (for example, when concatenating files)
444
+ you can use `postcss.parse()`.
386
445
 
387
- Let’s join two CSS with source map support in 5 lines of code:
446
+ Let’s join two CSS strings with full source map support in only 5 lines of code:
388
447
 
389
448
  ```js
390
449
  var file1 = postcss.parse(css1, { from: 'a.css' });
@@ -397,36 +456,38 @@ var result = file1.toResult({ to: 'app.css', map: true });
397
456
 
398
457
  ### Source Map
399
458
 
400
- With [source maps], browser’s development tools will show you origin position
401
- of your styles. For example, inspector will show position in Sass file,
402
- even if you compile it to CSS, concatenate and minify it.
459
+ By using [source maps], a browser’s development tools can indicate the
460
+ original position of your styles before the css file was transformed.
461
+ For example, an inspector will show the position in a Sass file, even if
462
+ the file has been compiled to CSS, concatenated, and minified.
403
463
 
404
- To generate correct source map every CSS processing step should update map from
405
- previous step. Sass compiler should generate first map, concatenation tool
406
- should update map from Sass step and minifier should update map from concat.
464
+ To ensure a correct source map is generated, every CSS processing step should update
465
+ the map generated by the previous step. For example, a Sass compiler will generate
466
+ the first map, a concatenation tool should update the Sass step’s map, and a minifier
467
+ should update the map generated by the concatenation tool.
407
468
 
408
- There is 2 way to store map:
469
+ There are two ways to store a source map:
409
470
 
410
- * You can put it to separated file and add special annotation comment
411
- with map path to CSS:
471
+ * You can place it in a separate file which contains a special annotation comment
472
+ pointing to another file:
412
473
 
413
474
  ```css
414
475
  a { }
415
476
  /*# sourceMappingURL=main.out.css.map */
416
477
  ```
417
- * Or you can inline map to CSS annotation comment by base64:
478
+ * Or you can inline a base64-encoded source map within a CSS comment:
418
479
 
419
480
  ```css
420
481
  a { }
421
482
  /*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5taW4uY3NzIiwic291cmNlcyI6WyJtYWluLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFLIn0= */
422
483
  ```
423
484
 
424
- PostCSS has great source map support. You must set input and output CSS files
425
- paths (using `from` and `to` options respectively) to generate correct source
426
- map.
485
+ PostCSS has great source map support. To ensure that you generate the correct
486
+ source map, you must indicate the input and output CSS files
487
+ paths (using the options `from` and `to` respectively).
427
488
 
428
- To generate new source map with default options just set `map: true` option in
429
- `processor.process(css, opts)`.
489
+ To generate a new source map with the default options, provide `map: true` in the
490
+ options passed to `processor.process(css, opts)`.
430
491
 
431
492
  ```js
432
493
  var result = processor.process(css, {
@@ -445,63 +506,63 @@ Or set `from` in `postcss.parse(css, opts)` and `to` in `root.toResult(opts)`:
445
506
 
446
507
  ```js
447
508
  var root = postcss.parse(css, { from: 'main.css' });
448
- root.last.removeSelf();
509
+ root.last.removeSelf(); // Example transformation
449
510
 
450
511
  var result = root.toResult({ to: 'main.out.css' });
451
512
  fs.writeFileSync('main.out.css', result.css);
452
513
  fs.writeFileSync('main.out.css.map', result.map);
453
514
  ```
454
515
 
455
- If PostCSS will find source map in previous CSS, it will automatically update
456
- it with same options.
516
+ If PostCSS is handling CSS and finds source maps from previous transformations, it will
517
+ automatically update the CSS with the same options.
457
518
 
458
519
  ```js
459
- // main.sass.css has annotation comment with link to main.sass.css.map
520
+ // main.sass.css has an annotation comment with a link to main.sass.css.map
460
521
  var result = minifier.process(css, { from: 'main.sass.css', to: 'main.min.css' });
461
522
  result.map //=> Source map from main.sass to main.min.css
462
523
  ```
463
524
 
464
- If you want to control map generation you can set object with parameters
465
- to `map` option:
525
+ If you want more control over source map generation, you can define the `map` option
526
+ as an object with the following parameters:
466
527
 
467
- * `inline` (boolean): should we inline map to CSS annotation comment.
468
- By default, PostCSS will inline new maps only if map was inlined
469
- in previous CSS.
528
+ * `inline` (boolean): indicates the source map should be inserted into the CSS string as
529
+ a comment. By default, PostCSS will inline new source maps only if the source map from
530
+ a previous step inserted an inline source map.
470
531
 
471
- If you inline map, `result.map` will be empty, because map will be
472
- in `result.css` text.
532
+ If you inline a source map, `result.map` will be empty, as the source map will be
533
+ contained within the text of `result.css`.
473
534
 
474
- You can shortcut `map { inline: true }` to `map: 'inline'`.
535
+ As a shortcut, `map { inline: true }` is equivalent to `map: 'inline'`.
475
536
 
476
- * `prev` (strong or object): map content from previous processing step
477
- (like Sass compilation). PostCSS will try to read previous map automatically
478
- by annotation comment in origin CSS, but you can set it manually. Also you can
479
- remove previous map by `prev: false`.
537
+ * `prev` (string, object, or boolean): map content from a previous processing step
538
+ (for example, Sass compilation). PostCSS will try to read the previous source map
539
+ automatically from the comment within origin CSS, but you can also set manually.
540
+ If desired, you can omit the previous map with `prev: false`.
480
541
 
481
- This option is only one map option, which can be passed
482
- to `postcss.parse(css, opts)`. Other options is for `toResult(opts)`
483
- or `process(css, opts)` method.
542
+ This is a source map option which can be passed to `postcss.parse(css, opts)`.
543
+ Other options can be passed to the `toResult(opts)` or `process(css, opts)` methods.
484
544
 
485
- * `sourcesContent` (boolean): should we set origin content (for example,
486
- Sass source) to map. By default, PostCSS will add content only if previous map
487
- contains it.
545
+ * `sourcesContent` (boolean): indicates that we should set the origin content
546
+ (for example, Sass source) of the source map. By default, PostCSS will add
547
+ content only if previous map contains it.
488
548
 
489
- * `annotation` (boolean or string): should we add annotation comment to CSS.
490
- By default, PostCSS always adds annotation with path to map. But if all
491
- previous CSS have not annotation, PostCSS will miss it too.
549
+ * `annotation` (boolean or string): indicates if we should add annotation comments
550
+ to the CSS. By default, PostCSS will always add a comment with a path to the source
551
+ map. But if the previous CSS does not have an annotation comment, PostCSS will
552
+ omit it too.
492
553
 
493
- By default, PostCSS thinks, that you will save map to `opts.to + '.map'`,
494
- and uses this path in annotation. But you can set another path as string value
495
- in `annotation` option.
554
+ By default, PostCSS presumes that you want to save the source map as
555
+ `opts.to + '.map'` and will use this path in the annotation comment. But you can
556
+ set another path by providing a string value as the `annotation` option.
496
557
 
497
- If you set `inline: true`, of cource, you will not be able disable annotation.
558
+ If you set `inline: true`, annotation cannot be disabled.
498
559
 
499
560
  [source maps]: http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/
500
561
 
501
562
  ### Safe Mode
502
563
 
503
- If you will set `safe: true` option to `process` or `parse` methods,
504
- PostCSS will try to fix any syntax error, that it founds in CSS.
564
+ If you provide a `safe: true` option to the `process` or `parse` methods,
565
+ PostCSS will try to correct any syntax error that it finds in the CSS.
505
566
  For example, it will parse `a {` as `a {}`.
506
567
 
507
568
  ```js
@@ -509,15 +570,15 @@ postcss.parse('a {'); // will throw "Unclosed block"
509
570
  postcss.parse('a {', { safe: true }); // will return CSS root for a {}
510
571
  ```
511
572
 
512
- It is useful for legacy code with a lot of hack. Other use case is a interactive
513
- tools with live input, like
514
- [Autoprefixer demo](http://jsfiddle.net/simevidas/udyTs/show/light/).
573
+ This is useful for legacy code filled with plenty of hacks. Another use case
574
+ is interactive tools with live input, for example,
575
+ the [Autoprefixer demo](http://jsfiddle.net/simevidas/udyTs/show/light/).
515
576
 
516
577
  ### Helpers
517
578
 
518
579
  #### Vendor
519
580
 
520
- PostCSS contains heigh optimized code to split vendor prefix:
581
+ PostCSS contains height optimized code to split vendor prefix:
521
582
 
522
583
  ```js
523
584
  var vendor = require('postcss/lib/vendor');
@@ -528,8 +589,8 @@ vendor.unprefixed('-moz-tab-size') //=> 'tab-size'
528
589
 
529
590
  #### List
530
591
 
531
- To safely split comma- or space-separated values (like in `background-image`
532
- or `transform` ) with brackets and quotes support you can use `list` helper:
592
+ To safely split comma- or space-separated values (such as those in `background-image`
593
+ or `transform`) with brackets and quotes support, you can use the `list` helper:
533
594
 
534
595
  ```js
535
596
  var list = require('postcss/lib/list');
@@ -540,7 +601,7 @@ list.comma(transform.value) //=> ['color 200ms', 'background 200ms']
540
601
 
541
602
  ### Nodes
542
603
 
543
- Processor function receives `Root` node with CSS node tree inside.
604
+ Processor functions receive a `Root` node which contains the CSS node tree.
544
605
 
545
606
  ```js
546
607
  var processor = postcss(function (cssRoot) {
@@ -548,15 +609,16 @@ var processor = postcss(function (cssRoot) {
548
609
  ```
549
610
 
550
611
  There are 4 types of child nodes: `Comment`, `AtRule`, `Rule` and `Declaration`.
551
- All nodes have `toString()` and `clone()` methods.
612
+ All nodes possess `toString()` and `clone()` methods.
552
613
 
553
- You can parse CSS and get a `Root` node by `postcss.parse(css, opts)` method:
614
+ You can parse CSS and get a `Root` node by calling the `postcss.parse(css, opts)` method:
554
615
 
555
616
  ```js
556
617
  var cssRoot = postcss.parse('a { }');
557
618
  ```
558
619
 
559
- All node‘s methods return current node, so you can build nice method chains:
620
+ Many of the methods on a node will return the current node, which enables
621
+ you to build method chains:
560
622
 
561
623
  ```js
562
624
  root.append( rule1 ).append( rule2 ).toString();
@@ -564,8 +626,8 @@ root.append( rule1 ).append( rule2 ).toString();
564
626
 
565
627
  ### Node Source
566
628
 
567
- Every node stores its origin file (if you set `from` option to `process`
568
- or `parse` method) and position:
629
+ Every node stores its origin file (if you provide the `from` option to the `process`
630
+ or `parse` methods) and position:
569
631
 
570
632
  ```js
571
633
  var root = postcss.parse(css, { from: 'main.css' });
@@ -576,18 +638,20 @@ rule.source.start //=> { line: 5, position: 1 }
576
638
  rule.source.end //=> { line: 10, position: 5 }
577
639
  ```
578
640
 
579
- ### Whitespaces
641
+ ### Whitespace
580
642
 
581
- All nodes (exclude `Root`) have `before` property with indentation
582
- and all earlier spaces.
643
+ All nodes (excluding the `Root`) have a `before` property which contains
644
+ the indentation and any previous whitespace.
583
645
 
584
- Nodes with children (`Root`, `AtRule` and `Rule`) contain also `after` property
585
- with spaces after last child and before `}` or end of file.
646
+ Nodes with children (`Root`, `AtRule` and `Rule`) also contain an `after`
647
+ property which indicates the spaces after the last child and before a `}`
648
+ character or the end of the file.
586
649
 
587
- Every `Declaration` has `between` property with colon, spaces and comments
588
- between property name and value. `Rule` stores spaces and comments between
589
- selector and `{` in `between` property. `AtRule` uses `between` also to store
590
- spaces and comments before `{` or `;` for bodiless at-rule.
650
+ Every `Declaration` has a `between` property with colon, spaces and comments
651
+ between the property name and value. `Rule` stores the spaces and comments between
652
+ the selector and `{` in the `between` property. `AtRule` uses `between` to
653
+ indicate the spaces and comments before either a `{` or `;`, if the at-rule
654
+ is bodiless.
591
655
 
592
656
  ```js
593
657
  var root = postcss.parse("a {\n color: black;\n}\n");
@@ -627,15 +691,15 @@ var css = "a {\n color:black\n}\n";
627
691
  minifier.process(css).css //=> "a{color:black}"
628
692
  ```
629
693
 
630
- Note, that nodes may have not properties like `before` or `between`:
694
+ Note that nodes may have not `before` or `between` properties:
631
695
 
632
696
  * If node was created by hand via `postcss.rule()`.
633
- * `node.clone()` will clean all style properties to use style from new CSS root.
697
+ * `node.clone()` will clean all style properties to use the style for a new CSS root.
634
698
 
635
699
  ### Raw Properties
636
700
 
637
701
  Some CSS values (selectors, comment text, at-rule params and declaration values)
638
- can contain comments. PostCSS will clean them from trailing spaces for you:
702
+ can contain comments. PostCSS will clean them to remove trailing spaces:
639
703
 
640
704
  ```js
641
705
  var root = postcss.parse("a /**/ b {}");
@@ -645,9 +709,9 @@ rule.selector //=> 'a b' trimmed and cleaned from comments
645
709
  rule._selector.raw //=> 'a /**/ b' original raw value
646
710
  ```
647
711
 
648
- But PostCSS saves raw content to be able to stringify it to CSS, if you don’t
649
- change origin value. As you can remember, PostCSS tries to save origin CSS
650
- byte-to-byte, when it’s possible:
712
+ But PostCSS preservers the raw content in order to stringify it back to CSS,
713
+ in case you don’t change the original value. In general, PostCSS tries to preserve
714
+ the original CSS byte-to-byte whenever possible:
651
715
 
652
716
  ```js
653
717
  rule.toString() //=> 'a /**/ b {}' with comment
@@ -659,29 +723,29 @@ rule.toString() //=> '.link b {}' you change value and origin comment was gone
659
723
  ### Containers
660
724
 
661
725
  `Root`, `AtRule` and `Rule` nodes can contain children in `rules` or `decls`
662
- property.
726
+ properties.
663
727
 
664
- There are common method to work with children:
728
+ There are some common methods to perform work on children:
665
729
 
666
- * `append(newChild)` to add child at the end of children list.
667
- * `prepend(newChild)` to add child at the beginning of children list.
668
- * `insertBefore(existsChild, newChild)` to insert new child before some
669
- existent child.
670
- * `insertAfter(existsChild, newChild)` to insert new child after some
671
- existent child.
672
- * `remove(existsChild)` to remove child.
673
- * `index(existsChild)` to return child index.
674
- * `some(fn)` to return true if `fn` returns true on any child.
675
- * `every(fn)` to return true if `fn` returns true on all children.
730
+ * `append(newChild)` adds a child at the end of the children list.
731
+ * `prepend(newChild)` adds a child at the beginning of the children list.
732
+ * `insertBefore(existsChild, newChild)` inserts a new child before a
733
+ pre-existing child.
734
+ * `insertAfter(existsChild, newChild)` inserts a new child after some
735
+ pre-existing child.
736
+ * `remove(existsChild)` removes a child.
737
+ * `index(existsChild)` returns a child’s index.
738
+ * `some(fn)` returns true if `fn` returns true for any child.
739
+ * `every(fn)` returns true if `fn` returns true for all children.
676
740
 
677
- Methods `append`, `prepend`, `insertBefore` and `insertAfter` can receive
678
- arrays and `Root` as new child argument.
741
+ Methods `append`, `prepend`, `insertBefore` and `insertAfter` will also accept
742
+ arrays and `Root` nodes as an argument.
679
743
 
680
- Methods `insertBefore`, `insertAfter` and `remove` can receive child node
681
- or child index as an `existsChild` argument. Have in mind that child index works
682
- much faster.
744
+ Methods `insertBefore`, `insertAfter` and `remove` will accept child nodes
745
+ or indexes as the `existsChild` argument. Note that providing a child index will
746
+ result in the method completing much faster.
683
747
 
684
- There are two shorcuts to get first and last child:
748
+ There are two shortcuts to provide the first and last child of a node:
685
749
 
686
750
  ```js
687
751
  rule.first //=> First declaration in rule
@@ -693,19 +757,19 @@ rule.last //=> Last declaration in rule
693
757
  `Comment`, `AtRule`, `Rule` and `Declaration` nodes should be wrapped
694
758
  in other nodes.
695
759
 
696
- All children contain `parent` property with parent node:
760
+ All children contain a `parent` property which indicates the parent node:
697
761
 
698
762
  ```js
699
763
  rule.decls[0].parent == rule;
700
764
  ```
701
765
 
702
- All children has `removeSelf()` method:
766
+ All children have a `removeSelf()` method:
703
767
 
704
768
  ```js
705
769
  rule.decls[0].removeSelf();
706
770
  ```
707
771
 
708
- But `remove(index)` in parent with child index is much faster:
772
+ But invoking the `remove(index)` method on the parent is much faster:
709
773
 
710
774
  ```js
711
775
  rule.each(function (decl, i) {
@@ -715,7 +779,8 @@ rule.each(function (decl, i) {
715
779
 
716
780
  ### Iterators
717
781
 
718
- All parent nodes have `each` method to iterate over children nodes:
782
+ All parent nodes have an `each` method which allows you to iterate over
783
+ its child nodes:
719
784
 
720
785
  ```js
721
786
  root = postcss.parse('a { color: black; display: none }');
@@ -734,23 +799,24 @@ root.rules[0].each(function (decl, i) {
734
799
  ```
735
800
 
736
801
  Unlike `for {}`-cycle construct or `Array#forEach()` this iterator is safe.
737
- You can mutate children while iteration and it will fix current index:
802
+ So you can mutate the children during iteration and PostCSS will fix the current index:
738
803
 
739
804
  ```js
740
805
  rule.rules.forEach(function (decl, i) {
741
806
  rule.prepend( decl.clone() );
742
- // Will be infinity cycle, because on prepend current declaration become
743
- // second and next index will go to current declaration again
807
+ // Will infinitely cycle as prepending the current declaration will
808
+ // cause the second and successive indexes to interact with the
809
+ // current declaration endlessly
744
810
  });
745
811
 
746
812
  rule.each(function (decl, i) {
747
813
  rule.prepend( decl.clone() );
748
- // Will work correct (once clone each declaration), because after prepend
749
- // iterator index will be recalculated
814
+ // Will work correctly (each declaration will be cloned only once),
815
+ // because the iterator index will be recalculated only after the prepend
750
816
  });
751
817
  ```
752
818
 
753
- Because CSS have nested structure, PostCSS also contains recursive iterator
819
+ Because CSS has a nested structure, PostCSS also features a recursive iterator
754
820
  `eachInside`:
755
821
 
756
822
  ```js
@@ -759,7 +825,8 @@ root.eachInside(function (node, i) {
759
825
  });
760
826
  ```
761
827
 
762
- There are also shortcuts to recursive iterate all nodes of specific type:
828
+ There are also shortcuts so that you can recursively iterate over nodes of
829
+ a specific type:
763
830
 
764
831
  ```js
765
832
  root.eachDecl(function (decl, i) {
@@ -779,28 +846,28 @@ root.eachComment(function (comment, i) {
779
846
  })
780
847
  ```
781
848
 
782
- You can break iteration by `return false`.
849
+ You can break out from the iteration by returning `false`.
783
850
 
784
851
  ### Root Node
785
852
 
786
- `Root` node contains entire CSS tree. Its children can be only `Comment`,
787
- `AtRule` or `Rule` nodes in `rules` property.
853
+ `Root` node contains the entire CSS tree. Its children can only be `Comment`,
854
+ `AtRule`, or `Rule` nodes in the `rules` property.
788
855
 
789
- You can create a new root using shortcut:
856
+ You can create a new root using the shortcut:
790
857
 
791
858
  ```js
792
859
  var root = postcss.root();
793
860
  ```
794
861
 
795
- Method `toString()` stringifies entire node tree to CSS string:
862
+ Method `toString()` stringifies the entire node tree and returns a CSS string:
796
863
 
797
864
  ```js
798
865
  root = postcss.parse(css);
799
866
  root.toString() == css;
800
867
  ```
801
868
 
802
- If PostCSS found previous source map, it will save all information
803
- in `Root#prevMap`:
869
+ If PostCSS found previous source map, it will save all the relevant information
870
+ within `Root#prevMap`:
804
871
 
805
872
  ```
806
873
  root = postcss.parse(css);
@@ -815,17 +882,17 @@ if (root.prevMap && root.prevMap.inline) {
815
882
  /* Block comment */
816
883
  ```
817
884
 
818
- PostCSS creates `Comment` nodes only for comments between rules or declarations.
819
- Comments inside selectors, at-rules params, declaration values will be stored
820
- in Raw property.
885
+ PostCSS creates `Comment` nodes only for comments found between rules or declarations.
886
+ Comments found within selectors, at-rules params, or declaration values will be stored
887
+ in the Raw property.
821
888
 
822
- `Comment` has only one property: `text` with trimmed text inside comment.
889
+ `Comment` has only one property: `text` which contains the trimmed text inside the comment.
823
890
 
824
891
  ```js
825
892
  comment.text //=> "Block comment"
826
893
  ```
827
894
 
828
- You can create a new comment using shortcut:
895
+ You can create a new comment using a shortcut:
829
896
 
830
897
  ```js
831
898
  var comment = postcss.comment({ text: 'New comment' });
@@ -847,14 +914,15 @@ var comment = postcss.comment({ text: 'New comment' });
847
914
 
848
915
  `AtRule` has two own properties: `name` and `params`.
849
916
 
850
- As you see, some at-rules don’t contain any children (like `@charset`
851
- or `@import`), some of at-rules can contain only declarations
852
- (like `@font-face` or `@page`), but most of them can contain rules
853
- and nested at-rules (like `@media`, `@keyframes` and others).
917
+ As illustrated above, some at-rules do not contain any children
918
+ (for example, `@charset` or `@import`), some at-rules can only contain
919
+ declarations (for example, `@font-face` or `@page`), but most of them
920
+ can contain rules and nested at-rules (for example, `@media`, `@keyframes`
921
+ and others).
854
922
 
855
- Parser selects `AtRule` content type by its name. If you create `AtRule`
856
- node manually, it will detect own content type with new child type on first
857
- `append` or other add method call:
923
+ The parser selects `AtRule` content type by its name. If you create an `AtRule`
924
+ node manually, it will infer its content type by the first child added via
925
+ the `append` or other methods:
858
926
 
859
927
  ```js
860
928
  var atRule = postcss.atRule({ name: '-x-animations' });
@@ -866,7 +934,7 @@ atRule.rules.length //=> 1
866
934
  atRule.decls //=> undefined
867
935
  ```
868
936
 
869
- You can create a new at-rule using shortcut:
937
+ You can create a new at-rule using a shortcut:
870
938
 
871
939
  ```js
872
940
  var atRule = postcss.atRule({ name: 'charset', params: 'utf-8' });
@@ -880,23 +948,23 @@ a {
880
948
  }
881
949
  ```
882
950
 
883
- `Rule` node has `selector` property and contains `Declaration` and `Comment`
884
- children in `decls` property.
951
+ `Rule` nodes have a `selector` property and contain their `Declaration`
952
+ and `Comment` children within the `decls` property.
885
953
 
886
- There is `selectors` shortcut, which return array:
954
+ They also possess a `selectors` shortcut, which returns an array:
887
955
 
888
956
  ```js
889
957
  rule.selector //=> "a, b"
890
958
  rule.selectors //=> ['a', 'b']
891
959
  ```
892
960
 
893
- You can miss `Declaration` constructor in `append` and other insert methods:
961
+ You can avoid using the `Declaration` constructor for `append` and other insert methods, by:
894
962
 
895
963
  ```js
896
964
  rule.append({ prop: 'color', value: 'black' });
897
965
  ```
898
966
 
899
- Property `semicolon` indicates if last declaration in rule has semicolon or not:
967
+ The property `semicolon` indicates if the last declaration within the rule has a semicolon or not:
900
968
 
901
969
  ```js
902
970
  var root = postcss.parse('a { color: black }');
@@ -906,7 +974,7 @@ var root = postcss.parse('a { color: black; }');
906
974
  root.rules[0].semicolon //=> true
907
975
  ```
908
976
 
909
- You can create a new rule using shortcut:
977
+ You can create a new rule using a shortcut:
910
978
 
911
979
  ```js
912
980
  var rule = postcss.rule({ selector: 'a' });
@@ -918,15 +986,15 @@ var rule = postcss.rule({ selector: 'a' });
918
986
  color: black
919
987
  ```
920
988
 
921
- `Declaration` node has `prop`, `value` and `important` properties.
989
+ `Declaration` nodes have `prop`, `value` and `important` properties.
922
990
 
923
- You can create a new declaration using this shortcut:
991
+ You can create a new declaration using a shortcut:
924
992
 
925
993
  ```js
926
994
  var decl = postcss.decl({ prop: 'color', value: 'black' });
927
995
  ```
928
996
 
929
- Or use short form in rule’s `append()` and other add methods:
997
+ Or you can use the short form available via a rule’s `append()` and other add methods:
930
998
 
931
999
  ```js
932
1000
  rule.append({ prop: 'color', value: 'black' });