postcss
Advanced tools
Comparing version 4.0.6 to 4.1.0
971
API.md
# PostCSS API | ||
* [postcss function](#postcss-function) | ||
* [PostCSS class](#postcss-class) | ||
* [Result class](#result-class) | ||
* [`postcss` function](#postcss-function) | ||
* [`Processor` class](#processor-class) | ||
* [`LazyResult` class](#lazy-result-class) | ||
* [`Result` class](#result-class) | ||
* [`Warning` class](#warning-class) | ||
* [`CssSyntaxError` class](#csssyntaxerror-class) | ||
* [Vendor module](#vendor-module) | ||
* [List module](#list-module) | ||
* [Input class](#input-class) | ||
* [`Input` class](#input-class) | ||
* [Nodes common methods](#nodes-common-methods) | ||
* [Containers common methods](#containers-common-methods) | ||
* [Root node](#root-node) | ||
* [AtRule node](#atrule-node) | ||
* [Rule node](#rule-node) | ||
* [Declaration node](#declaration-node) | ||
* [Comment node](#comment-node) | ||
* [`Root` node](#root-node) | ||
* [`AtRule` node](#atrule-node) | ||
* [`Rule` node](#rule-node) | ||
* [`Declaration` node](#declaration-node) | ||
* [`Comment` node](#comment-node) | ||
@@ -27,3 +30,3 @@ ## `postcss` function | ||
Returns a new `PostCSS` instance that will apply `plugins` | ||
Returns a new [`Processor`] instance that will apply `plugins` | ||
as CSS processors. | ||
@@ -35,6 +38,9 @@ | ||
You can also set plugins with the [`PostCSS#use`] method. | ||
Arguments: | ||
See [`PostCSS#use`] below for details about plugin formats. | ||
* `plugins (array)`: PostCSS plugins list to set them to new processor. | ||
You can also set plugins with the [`Processor#use`] method. | ||
See its description below for details about plugin formats. | ||
### `postcss.parse(css, opts)` | ||
@@ -52,11 +58,92 @@ | ||
Options: | ||
Arguments: | ||
* `from`: the path to the source CSS file. You should always set `from`, | ||
because it is used in map generation and in syntax error messages. | ||
* `safe`: enable [Safe Mode], in which PostCSS will try | ||
to fix CSS syntax errors. | ||
* `map`: an object of [source map options]. | ||
Only `map.prev` is used in `parse`. | ||
* `css (string|#toString)`: String with input CSS or any object | ||
with `toString()` method, like file stream. | ||
* `opts (object) optional`: options: | ||
* `from`: the path to the source CSS file. You should always set `from`, | ||
because it is used in map generation and in syntax error messages. | ||
* `safe`: enable [Safe Mode], in which PostCSS will try | ||
to fix CSS syntax errors. | ||
* `map`: an object of [source map options]. | ||
Only `map.prev` is used in `parse`. | ||
### `postcss.plugin(name, initializer)` | ||
Creates PostCSS plugin with standard API. | ||
```js | ||
var remove = postcss.plugin('postcss-remove', function (opts) { | ||
var filter = opts.prop || 'z-index'; | ||
return function (css, processor) { | ||
css.eachDecl(filter, function (decl) { | ||
decl.removeSelf(); | ||
}); | ||
}; | ||
}); | ||
postcss().use(remove) // with default options | ||
postcss().use(remove({ prop: 'color' })) // with options | ||
``` | ||
Arguments: | ||
* `name (string)`: PostCSS plugin name. Same as in `name` property | ||
in `package.json`. It will be saved in `plugin.postcssPlugin` property. | ||
* `initializer (function)`: will receive plugin options and should return | ||
functions to modify nodes in input CSS. | ||
Also wrap will save plugin name and plugin PostCSS version: | ||
```js | ||
var processor = postcss([replace]); | ||
processor.plugins[0].postcssPlugin //=> 'postcss-replace' | ||
processor.plugins[0].postcssVersion //=> '4.1.0' | ||
``` | ||
Plugin function receive 2 arguments: [`Root` node] and [`Result`] instance. | ||
Then it should mutate the passed `Root` node, or you can create new `Root` node | ||
and put it to `result.root` property. | ||
```js | ||
postcss.plugin('postcss-cleaner', function () { | ||
return function (css, result) { | ||
result.root = postcss.root(); | ||
}; | ||
}); | ||
``` | ||
Asynchronous plugin should return `Promise` instance. | ||
```js | ||
postcss.plugin('postcss-import', function () { | ||
return function (css, result) { | ||
return new Promise(function (resolve, reject) { | ||
fs.readFile('base.css', function (base) { | ||
css.prepend(base); | ||
resolve(); | ||
}) | ||
}); | ||
}; | ||
}); | ||
``` | ||
You can add warnings by [`Result#warn()`] method. | ||
```js | ||
postcss.plugin('postcss-caniuse-test', function () { | ||
return function (css, result) { | ||
css.eachDecl(function (decl) { | ||
if ( !caniuse.support(decl.prop) ) { | ||
result.warn( | ||
'Some of browsers does not support ' + decl.prop, | ||
{ node: decl }); | ||
} | ||
}); | ||
}; | ||
}); | ||
``` | ||
You can send some data to next plugins by [`Result#messages`] array. | ||
### `postcss.root(props)` | ||
@@ -70,2 +157,6 @@ | ||
Arguments: | ||
* `props (object) optional`: properties for new node. | ||
### `postcss.atRule(props)` | ||
@@ -79,2 +170,6 @@ | ||
Arguments: | ||
* `props (object) optional`: properties for new node. | ||
### `postcss.rule(props)` | ||
@@ -88,2 +183,6 @@ | ||
Arguments: | ||
* `props (object) optional`: properties for new node. | ||
### `postcss.decl(props)` | ||
@@ -97,2 +196,6 @@ | ||
Arguments: | ||
* `props (object) optional`: properties for new node. | ||
### `postcss.comment(props)` | ||
@@ -106,6 +209,26 @@ | ||
## `PostCSS` class | ||
Arguments: | ||
A `PostCSS` instance contains plugins to process CSS. You can create | ||
one `PostCSS` instance, initialize its plugins, and then use that instance | ||
* `props (object) optional`: properties for new node. | ||
### `postcss.vendor` | ||
Contains [Vendor module](#vendor-module) module. | ||
```js | ||
postcss.vendor.unprefixed('-moz-tab') //=> ['tab'] | ||
``` | ||
### `postcss.list` | ||
Contains [List module](#list-module) module. | ||
```js | ||
postcss.list.space('5px calc(10% + 5px)') //=> ['5px', 'calc(10% + 5px)'] | ||
``` | ||
## `Processor` class | ||
A `Processor` instance contains plugins to process CSS. You can create | ||
one `Processor` instance, initialize its plugins, and then use that instance | ||
on many CSS files. | ||
@@ -119,3 +242,3 @@ | ||
### `p.use(plugin)` | ||
### `processor.use(plugin)` | ||
@@ -129,54 +252,209 @@ Adds a plugin to be used as a CSS processor. | ||
Arguments: | ||
* `plugin (function|#postcss|Processor)`: PostCSS plugin. I can be in three | ||
formats: | ||
* A plugin created by [`postcss.plugin()`] method. | ||
* A function. PostCSS will pass the function a [`Root` node] | ||
as the first argument and current [`Result`] instance as second. | ||
* An object with a `postcss` method. PostCSS will use that method | ||
as described in #2. | ||
* Another `Processor` instance. PostCSS will copy plugins | ||
from that instance to this one. | ||
Plugins can also be added by passing them as arguments when creating | ||
a `postcss` instance (cf. [`postcss(plugins)`]). | ||
a `postcss` instance (see [`postcss(plugins)`]). | ||
Plugins can come in three formats: | ||
Asynchronous plugin should return `Promise` instance. | ||
1. A function. PostCSS will pass the function a [`Root` node] | ||
as the first argument. | ||
2. An object with a `postcss` method. PostCSS will use that method | ||
as described in #1. | ||
3. Another `PostCSS` instance. PostCSS will copy plugins | ||
from that instance to this one. | ||
### `processor.process(css, opts)` | ||
Plugin functions should mutate the passed `Root` node and return nothing, | ||
or return a new `Root` node. | ||
Parses source CSS and returns [`LazyResult`] instance. Because some plugins can | ||
be asynchronous it doesn’t make any transformations. Transformations will | ||
be apply in `LazyResult`’s methods. | ||
```js | ||
processor.use(function (css) { | ||
css.prepend({ name: 'charset', params: '"UTF-8"' }); | ||
processor.process(css, { from: 'a.css', to: 'a.out.css' }).then(function (result) { | ||
console.log(result.css); | ||
}); | ||
processor.use(function (css) { | ||
return postcss.root(); | ||
``` | ||
Arguments: | ||
* `css (string|#toString|Result)`: String with input CSS or any object | ||
with `toString()` method, like file stream. Also you can send [`Result`] | ||
instance and processor will take already parser [`Root`] from it. | ||
* `ops (object) optional`: options: | ||
* `from`: the path of the CSS source file. You should always set `from`, | ||
because it is used in source map generation and syntax error messages. | ||
* `to`: the path where you’ll put the output CSS file. You should always set | ||
`to` to generate correct source maps. | ||
* `safe`: enable [Safe Mode], in which PostCSS will try | ||
to fix CSS syntax errors. | ||
* `map`: an object of [source map options]. | ||
### `processor.plugins` | ||
Contains plugins added to this processor. | ||
```js | ||
var processor = postcss([cssnext, cssgrace]); | ||
processor.plugins.length //=> 2 | ||
``` | ||
### `processor.version` | ||
Contains current version of PostCSS. | ||
```js | ||
postcss().version //=> '4.0.5' | ||
``` | ||
## `LazyResult` class | ||
Promise proxy for result of PostCSS transformations. | ||
A `LazyResult` instance is returned by [`Processor#process(css, opts)`]. | ||
```js | ||
var lazy = postcss([cssnext]).process(css); | ||
``` | ||
### `lazy.then(onFulfilled, onRejected)` | ||
Processes input CSS through synchronous and asynchronous plugins | ||
and call `onFulfilled` with [`Result`] instance. If some plugin will throw | ||
a error, `onRejected` callback will be executed. | ||
```js | ||
postcss([cssnext]).process(css).then(function(result) { | ||
console.log(result.css); | ||
}); | ||
``` | ||
### `p.process(css, opts)` | ||
This method is a standard [Promise] method. | ||
This is the main method of PostCSS. It will parse the source CSS | ||
and create a [`Root` node]; send this `Root` to each plugin successively, | ||
for transformations; and then return a `Result` instance created | ||
from the transformed `Root`. | ||
### `lazy.catch(onRejected)` | ||
Processes input CSS through synchronous and asynchronous plugins | ||
and call `onRejected` on errors from any plugin. | ||
```js | ||
var result = processor.process(css, { from: 'a.css', to: 'a.out.css' }); | ||
postcss([cssnext]).process(css).then(function(result) { | ||
console.log(result.css); | ||
}).catch(function (error) { | ||
console.error(error); | ||
}); | ||
``` | ||
Input CSS formats are: | ||
This method is a standard [Promise] method. | ||
* A string of CSS. | ||
* A `Result` instance from another PostCSS processor. PostCSS will accept | ||
the already parsed `Root` from it. | ||
* Any object with a `toString()` method — for example, a file stream. | ||
### `lazy.toString()` | ||
Options: | ||
Alias for `LazyResult#css` property. | ||
* `from`: the path of the CSS source file. You should always set `from`, | ||
because it is used in source map generation and syntax error messages. | ||
* `to`: the path where you’ll put the output CSS file. You should always set | ||
`to` to generate correct source maps. | ||
* `safe`: enable [Safe Mode], in which PostCSS will try | ||
to fix CSS syntax errors. | ||
* `map`: an object of [source map options]. | ||
### `lazy.css` | ||
Processes input CSS through synchronous plugins, convert `Root` to CSS string | ||
and returns [`Result#css`]. | ||
```js | ||
processor.process(css).css; | ||
``` | ||
This property will work only with synchronous plugins. If processor contains | ||
any asynchronous plugin it will throw a error. You should use | ||
[`LazyResult#then()`] instead. | ||
```js | ||
postcss([cssnext]).then(function (result) { | ||
console.log(result.css); | ||
}); | ||
``` | ||
### `lazy.map` | ||
Processes input CSS through synchronous plugins and returns [`Result#map`]. | ||
```js | ||
if ( result.map ) { | ||
fs.writeFileSync(result.opts.to + '.map', result.map.toString()); | ||
} | ||
``` | ||
This property will work only with synchronous plugins. If processor contains | ||
any asynchronous plugin it will throw a error. You should use | ||
[`LazyResult#then()`] instead. | ||
```js | ||
postcss([cssnext]).then(function (result) { | ||
if ( result.map ) { | ||
fs.writeFileSync(result.opts.to + '.map', result.map.toString()); | ||
} | ||
}); | ||
``` | ||
### `lazy.root` | ||
Processes input CSS through synchronous plugins and returns | ||
[`Result#root`](#resultroot). | ||
This property will work only with synchronous plugins. If processor contains | ||
any asynchronous plugin it will throw a error. You should use | ||
[`LazyResult#then()`] instead. | ||
```js | ||
postcss([cssnext]).then(function (result) { | ||
console.log(result.root); | ||
}); | ||
``` | ||
### `lazy.warnings()` | ||
Processes input CSS through synchronous plugins and call [`Result#warnings()`]. | ||
```js | ||
postcss([cssnext]).warnings().forEach(function (message) { | ||
console.warn(message.text); | ||
}); | ||
``` | ||
This property will work only with synchronous plugins. If processor contains | ||
any asynchronous plugin it will throw a error. You should use | ||
[`LazyResult#then()`] instead. | ||
```js | ||
postcss([cssnext]).then(function (result) { | ||
result.warnings().forEach(function (message) { | ||
console.warn(message.text); | ||
}); | ||
}); | ||
``` | ||
### `lazy.messages` | ||
Processes input CSS through synchronous plugins and returns [`Result#messages`]. | ||
This property will work only with synchronous plugins. If processor contains | ||
any asynchronous plugin it will throw a error. You should use | ||
[`LazyResult#then()`] instead. | ||
### `lazy.processor` | ||
Returns a [`Processor`] instance, that will be used for CSS transformations. | ||
```js | ||
var lazy = postcss([cssnext, cssgrace]).process(css); | ||
lazy.processor.plugins.length //=> 2 | ||
``` | ||
### `lazy.opts` | ||
Options from the [`Processor#process(css, opts)`] call that produced | ||
this `Result` instance. | ||
```js | ||
postcss().process(css, opts).opts == opts; | ||
``` | ||
## `Result` class | ||
@@ -186,26 +464,58 @@ | ||
A `Result` instance is returned | ||
by [`PostCSS#process(css, opts)`] and [`Root#toResult(opts)`]. | ||
A `Result` instance is returned by [`Root#toResult(opts)`] | ||
or [`LazyResult#then()`] methods. | ||
```js | ||
var result1 = postcss().process(css); | ||
postcss([cssnext]).process(css).then(function (result1) { | ||
console.log(result1.css); | ||
}); | ||
var result2 = postcss.parse(css).toResult(); | ||
``` | ||
### `result.root` | ||
### `result.toString()` | ||
The source `Root` instance. | ||
Alias for [`Result#css`] property. | ||
### `result.warn(text, opts)` | ||
Creates [`Warning`] and adds it to [`Result#messages`]. | ||
```js | ||
root.toResult().root == root; | ||
var plugin = postcss.plugin('postcss-important', function () { | ||
return function (css, result) { | ||
css.eachDecl(function (decl) { | ||
if ( decl.important ) { | ||
result.warn('Try to avoid !important', { node: decl }); | ||
} | ||
}); | ||
} | ||
}); | ||
postcss([plugin]).process(css).then(function (result) { | ||
result.warnings() //=> [{ | ||
// plugin: 'postcss-important-warning', | ||
// text: 'Try to avoid !important' | ||
// node: { type: 'decl', … } | ||
// }] | ||
}) | ||
``` | ||
### `result.opts` | ||
Arguments: | ||
Options from the [`PostCSS#process(css, opts)`] or | ||
[`Root#toResult(opts)`] call that produced | ||
this `Result` instance. | ||
* `text (string)`: warning message. It will be used in `text` property of | ||
message object. | ||
* `opts (object) optional`: properties to message object. | ||
* `node`: CSS node, that was a source of warning. | ||
* `plugin`: name of plugin created this warning. `Result#warn()` will fill it | ||
automatically by `plugin.postcssPlugin` value. | ||
### `result.warnings()` | ||
Returns warnings from plugins. It just a filters [`Warning`] instances | ||
from [Result#messages]. | ||
```js | ||
postcss().process(css, opts).opts == opts; | ||
result.warnings().forEach(function (message) { | ||
console.log(message.toString()); | ||
}); | ||
``` | ||
@@ -218,15 +528,9 @@ | ||
```js | ||
postcss().process('a{}').css //=> "a{}" | ||
postcss.parse('a{}').toResult().css //=> "a{}" | ||
``` | ||
This property is generated *lazily*: `Root` is not stringified until | ||
the first request for the `css` property (or the [`result.map`] property). | ||
That initial request for `css` will also generate a source map. | ||
Source map will inlined into CSS or assigned to the [`result.map`] property, | ||
if user ask to save map to separated file. | ||
### `result.map` | ||
An instance of the `SourceMapGenerator` class from the [`source-map`] library, | ||
representing changes to the `Result`’s `Root` instance. | ||
representing changes to the `Result`’s `Root` instance. | ||
@@ -237,22 +541,261 @@ ```js | ||
This property is generated *lazily*: the source map for `Root` is not generated | ||
until the first request for the `map` property (or the [`result.css`] property). | ||
That initial request will also stringify `Root` and assign the generated | ||
CSS string to the [`result.css`] property. | ||
This property will has a value *only if the user does not want an inline source | ||
map*. By default, PostCSS generates inline source maps, written directly into | ||
the processed CSS; so by default the `map` property will be empty. | ||
Additionally, *this property will receive a value only if the user does not wan | ||
an inline source map*. By default, PostCSS generates inline source maps, | ||
written directly into the processed CSS; so by default the `map` property | ||
will be empty. | ||
An external source map will be generated — and assigned to `map` — | ||
only if the user has set the `map.inline` option to `false`, or if PostCSS | ||
was passed an external input source map. | ||
An external source map will be generated — and assigned to `map` — only if the | ||
user has set the `map.inline` option to `false`, or if PostCSS was passed | ||
an external input source map. | ||
```js | ||
if ( result.map ) { | ||
fs.writeFileSync(to + '.map', result.map.toString()); | ||
fs.writeFileSync(result.opts.to + '.map', result.map.toString()); | ||
} | ||
``` | ||
### `result.root` | ||
Contains [`Root` node] after all transformations. | ||
```js | ||
root.toResult().root == root; | ||
``` | ||
### `result.messages` | ||
Contains messages from plugins. For example, warnings or custom messages | ||
to plugins communication. | ||
Each message should has `type` and `plugin` properties. | ||
```js | ||
postcss.plugin('postcss-min-browser', function () { | ||
return function (css, result) { | ||
var browsers = detectMinBrowsersByCanIUse(css); | ||
result.messages.push({ | ||
type: 'min-browser', | ||
plugin: 'postcss-min-browser', | ||
browsers: browsers | ||
}); | ||
} | ||
}) | ||
``` | ||
You can add warning by [`Result#warn()`] and get all warnings | ||
by [`Result#warnings()`](#resultwarnings) method. | ||
### `result.processor` | ||
Returns a [`Processor`] instance, that was used for this transformations. | ||
```js | ||
result.processor.plugins.forEach(function (plugin) { | ||
if ( plugin.postcssPlugin == 'postcss-bad' ) { | ||
throw 'postcss-good is incompatible with postcss-bad'; | ||
} | ||
}) | ||
``` | ||
### `result.opts` | ||
Options from the [`Processor#process(css, opts)`] or [`Root#toResult(opts)`] | ||
call that produced this `Result` instance. | ||
```js | ||
root.toResult(opts).opts == opts; | ||
``` | ||
## `Warning` class | ||
Warning from plugins. It can be created by [`Result#warn()`]. | ||
```js | ||
if ( decl.important ) { | ||
result.warn('Try to avoid !important', { node: decl }); | ||
} | ||
``` | ||
### `warning.toString()` | ||
Returns string with error position, message. | ||
```js | ||
warning.toString() //=> 'postcss-important:a.css:10:4: Try to avoid !important' | ||
``` | ||
### `warning.text` | ||
Contains warning message. | ||
```js | ||
warning.text //=> 'Try to avoid !important' | ||
``` | ||
### `warning.plugin` | ||
Contains plugin name created this warning. When you call [`Result#warn()`], | ||
it will fill this property automatically. | ||
```js | ||
warning.plugin //=> 'postcss-important' | ||
``` | ||
### `warning.node` | ||
Contains CSS node, that was a source of warning. | ||
```js | ||
warning.node.toString() //=> 'color: white !important' | ||
``` | ||
## `CssSyntaxError` class | ||
CSS parser throw this error on broken CSS. | ||
```js | ||
postcss.parse('a{') //=> CssSyntaxError | ||
``` | ||
Custom parsers can throw this error on broken own custom syntax | ||
by [`Node#error()`](#nodeerrormessage) method. | ||
```js | ||
throw node.error('Unknown variable', { plugin: 'postcss-vars' }); | ||
``` | ||
### `error.toString()` | ||
Returns string with error position, message and source code of broken part. | ||
```js | ||
error.toString() //=> CssSyntaxError: app.css:1:1: Unclosed block | ||
// a { | ||
// ^ | ||
``` | ||
### `error.showSourceCode(color)` | ||
Returns a few lines of CSS source, which generates this error. | ||
```js | ||
error.showSourceCode() //=> | ||
// a { | ||
// bad | ||
// ^ | ||
// } | ||
``` | ||
Arguments: | ||
* `color (boolean) optional`: should arrow will be colored to red by terminal | ||
color codes. By default, PostCSS will use `process.stdout.isTTY` and | ||
`process.env.NODE_DISABLE_COLORS`. | ||
If CSS has input source map without `sourceContent`, this method will return | ||
empty string. | ||
### `error.message` | ||
Contains full error text by GNU error format. | ||
```js | ||
error.message //=> 'a.css:1:1: Unclosed block' | ||
``` | ||
### `error.reason` | ||
Contains only error description. | ||
```js | ||
error.reason //=> 'Unclosed block' | ||
``` | ||
### `error.plugin` | ||
Contains PostCSS plugin name if error came not from CSS parser. | ||
```js | ||
error.plugin //=> 'postcss-vars' | ||
``` | ||
### `error.file` | ||
Contains absolute path to broken file, if use set `from` option to parser. | ||
```js | ||
error.file //=> 'a.sass' | ||
``` | ||
PostCSS will use input source map to detect origin place of error. If you wrote | ||
Sass file, then compile it to CSS and put to PostCSS, PostCSS will show | ||
position in origin Sass file. | ||
If you need position in PostCSS input (for example, to debug previous compiler), | ||
you can use `error.generated.file`. | ||
```js | ||
error.file //=> 'a.sass' | ||
error.generated.file //=> 'a.css' | ||
``` | ||
### `error.line` | ||
Contains source line of error. | ||
```js | ||
error.line //=> 2 | ||
``` | ||
PostCSS will use input source map to detect origin place of error. If you wrote | ||
Sass file, then compile it to CSS and put to PostCSS, PostCSS will show | ||
position in origin Sass file. | ||
If you need position in PostCSS input (for example, to debug previous compiler), | ||
you can use `error.generated.line`. | ||
```js | ||
error.line //=> 2 | ||
error.generated.line //=> 4 | ||
``` | ||
### `error.column` | ||
Contains source column of error. | ||
```js | ||
error.column //=> 1 | ||
``` | ||
PostCSS will use input source map to detect origin place of error. If you wrote | ||
Sass file, then compile it to CSS and put to PostCSS, PostCSS will show | ||
position in origin Sass file. | ||
If you need position in PostCSS input (for example, to debug previous compiler), | ||
you can use `error.generated.column`. | ||
```js | ||
error.column //=> 1 | ||
error.generated.column //=> 4 | ||
``` | ||
### `error.source` | ||
Contains source code of broken file. | ||
```js | ||
error.source //=> 'a {} b {' | ||
``` | ||
PostCSS will use input source map to detect origin place of error. If you wrote | ||
Sass file, then compile it to CSS and put to PostCSS, PostCSS will show | ||
position in origin Sass file. | ||
If you need position in PostCSS input (for example, to debug previous compiler), | ||
you can use `error.generated.source`. | ||
```js | ||
error.source //=> 'a { b {} }' | ||
error.generated.column //=> 'a b { }' | ||
``` | ||
## Vendor module | ||
@@ -262,2 +805,6 @@ | ||
```js | ||
var vendor = postcss.vendor; | ||
``` | ||
### `vendor.prefix(string)` | ||
@@ -268,3 +815,3 @@ | ||
```js | ||
vendor.prefix('-moz-tab-size') //=> '-moz-' | ||
postcss.vendor.prefix('-moz-tab-size') //=> '-moz-' | ||
``` | ||
@@ -277,3 +824,3 @@ | ||
```js | ||
vendor.unprefixed('-moz-tab-size') //=> 'tab-size' | ||
postcss.vendor.unprefixed('-moz-tab-size') //=> 'tab-size' | ||
``` | ||
@@ -287,3 +834,3 @@ | ||
```js | ||
var list = require('postcss/lib/list'); | ||
var list = postcss.list; | ||
``` | ||
@@ -297,4 +844,3 @@ | ||
```js | ||
list.space('1px calc(10% + 1px)') | ||
//=> ['1px', 'calc(10% + 1px)'] | ||
postcss.list.space('1px calc(10% + 1px)') //=> ['1px', 'calc(10% + 1px)'] | ||
``` | ||
@@ -308,3 +854,3 @@ | ||
```js | ||
list.comma('black, linear-gradient(white, black)') | ||
postcss.list.comma('black, linear-gradient(white, black)') | ||
//=> ['black', 'linear-gradient(white, black)'] | ||
@@ -324,4 +870,3 @@ ``` | ||
The absolute path to the CSS source file defined with | ||
the [`from` option](#pprocesscss-opts). | ||
The absolute path to the CSS source file defined with the [`from` option]. | ||
@@ -347,3 +892,3 @@ ```js | ||
The CSS source identifier. Contains [`input.file`](#inputfile) if the user set the | ||
[`from` option](#pprocesscss-opts), or [`input.id`](#inputid) if she did not. | ||
[`from` option], or [`input.id`](#inputid) if she did not. | ||
@@ -450,5 +995,5 @@ ```js | ||
### `node.error(message)` | ||
### `node.error(message, opts)` | ||
Returns a `CssSyntaxError` instance that presents the original position | ||
Returns a [`CssSyntaxError`] instance that presents the original position | ||
of the node in the source, showing line and column numbers and also | ||
@@ -465,4 +1010,4 @@ a small excerpt to facilitate debugging. | ||
if ( !variables[name] ) { | ||
throw decl.error('Unknown variable ' + name); | ||
// CssSyntaxError: a.sass:4:3: Unknown variable $black | ||
throw decl.error('Unknown variable ' + name, { plugin: 'postcss-vars' }); | ||
// CssSyntaxError: postcss-vars:a.sass:4:3: Unknown variable $black | ||
// a | ||
@@ -473,9 +1018,12 @@ // color: $black | ||
} | ||
if ( oldSyntax.check(decl) ) { | ||
console.warn( decl.error('Old syntax for variables').message ); | ||
// a.sass:4:3: Old syntax for variables | ||
} | ||
``` | ||
Arguments: | ||
* `message (string)`: error description. | ||
* `opts (object) optional`: options. | ||
* `plugin (string)`: plugin name, that created this error. | ||
See also [`Result#warn()`] for warnings. | ||
### `node.next()` and `node.prev()` | ||
@@ -522,2 +1070,6 @@ | ||
Arguments: | ||
* `otherNode: (Node)`: other node to replace current one. | ||
### `node.clone(props)` | ||
@@ -528,4 +1080,3 @@ | ||
The resultant clone node and its (clone) children will have clean `parent` | ||
and code style properties. You can override properties in the clone node | ||
by passing a `props` argument. | ||
and code style properties. | ||
@@ -539,2 +1090,6 @@ ```js | ||
Arguments: | ||
* `props (object) optional`: new properties to override them in clone. | ||
### `node.cloneBefore(props)` and `node.cloneAfter(props)` | ||
@@ -549,2 +1104,6 @@ | ||
Arguments: | ||
* `props (object) optional`: new properties to override them in clone. | ||
### `node.moveTo(newParent)` | ||
@@ -563,2 +1122,6 @@ | ||
Arguments: | ||
* `newParent: (Container)`: container node where current node will be moved. | ||
### `node.moveBefore(otherNode)` and `node.moveAfter(otherNode)` | ||
@@ -572,2 +1135,6 @@ | ||
Arguments: | ||
* `otherNode (Node)`: node which will be after/before current node after moving. | ||
### `node.style(prop, defaultType)` | ||
@@ -585,2 +1152,8 @@ | ||
Arguments: | ||
* `prop (string)`: name or code style property. | ||
* `defaultType (string)`: name of default value. You can miss it | ||
if it is same with `prop`. | ||
## Containers: common methods | ||
@@ -629,6 +1202,9 @@ | ||
Arguments: | ||
* `child (Node)`: child of current container. | ||
### `container.every(callback)` | ||
Returns `true` if `callback` returns a truthy value for all | ||
of the container’s children. | ||
Returns `true` if `callback` returns a true for all of the container’s children. | ||
@@ -641,6 +1217,10 @@ ```js | ||
Arguments: | ||
* `callback (function)`: iterator, that returns true of false. | ||
### `container.some(callback)` | ||
Return `true` if `callback` returns a truthy value | ||
for (at least) one of the container’s children. | ||
Return `true` if `callback` returns a true value for (at least) one | ||
of the container’s children. | ||
@@ -653,2 +1233,6 @@ ```js | ||
Arguments: | ||
* `callback (function)`: iterator, that returns true of false. | ||
### `container.each(callback)` | ||
@@ -659,4 +1243,2 @@ | ||
`callback` receives 2 arguments: the node itself and an index. | ||
Returning `false` within `callback` will break iteration. | ||
@@ -674,2 +1256,6 @@ | ||
Arguments: | ||
* `callback (function)`: iterator, that will receive node itself and an index. | ||
Unlike the `for {}`-cycle or `Array#forEach()` this iterator is safe | ||
@@ -697,3 +1283,3 @@ if you are mutating the array of child nodes during iteration. | ||
`container.each()` only iterates through the container’s immediate children. | ||
If you need to recursively iterate through all the container’s descendents, | ||
If you need to recursively iterate through all the container’s nodes, | ||
use `container.eachInside()`. | ||
@@ -706,4 +1292,2 @@ | ||
`callback` receives 2 arguments: the node itself and an index. | ||
```js | ||
@@ -715,2 +1299,6 @@ root.eachInside(function (node) { | ||
Arguments: | ||
* `callback (function)`: iterator, that will receive node itself and an index. | ||
Like `container.each()`, this method is safe to use | ||
@@ -727,4 +1315,2 @@ if you are mutating arrays during iteration. | ||
`callback` receives 2 arguments: the node itself and an index. | ||
```js | ||
@@ -738,5 +1324,11 @@ root.eachDecl(function (decl) { | ||
If you pass a string or regular expression as `filter`, only those declarations whose | ||
property matches`filter` will be iterated over. | ||
Arguments: | ||
* `propFilter: (string|RegExp) optional`: string or regular expression | ||
to filter declarations by property name. | ||
* `callback (function)`: iterator, that will receive node itself and an index. | ||
If you pass a `propFilter`, only those declarations whose property matches | ||
`propFilter` will be iterated over. | ||
```js | ||
@@ -760,5 +1352,3 @@ // Make flat design | ||
`callback` receives 2 arguments: the node itself and an index. | ||
```js | ||
@@ -770,5 +1360,11 @@ root.eachAtRule(function (rule) { | ||
If you pass a string or regular expression as `filter`, only those at-rules whose name | ||
matches `filter` will be iterated over. | ||
Arguments: | ||
* `nameFilter: (string|RegExp) optional`: string or regular expression to filter | ||
at-rules by name. | ||
* `callback (function)`: iterator, that will receive node itself and an index. | ||
If you pass a `filter`, only those at-rules whose name matches `filter` | ||
will be iterated over. | ||
```js | ||
@@ -793,4 +1389,2 @@ var first = false; | ||
`callback` receives 2 arguments: the node itself and an index. | ||
```js | ||
@@ -804,2 +1398,6 @@ var selectors = []; | ||
Arguments: | ||
* `callback (function)`: iterator, that will receive node itself and an index. | ||
Like `container.each()`, this method is safe to use if you are mutating arrays | ||
@@ -819,25 +1417,14 @@ during iteration. | ||
Arguments: | ||
* `callback (function)`: iterator, that will receive node itself and an index. | ||
Like `container.each()`, this method is safe to use if you are mutating arrays | ||
during iteration. | ||
### `container.replaceValues(regexp, opts, callback)` | ||
### `container.replaceValues(pattern, opts, callback)` | ||
Passes all declaration values within the container that match `regexp` through | ||
Passes all declaration values within the container that match `pattern` through | ||
`callback`, replacing those values with the returned result of `callback`. | ||
`callback` will receive the same arguments as those passed to a function | ||
parameter of [`String#replace`]. | ||
You can speed up the search by passing `opts`: | ||
- `props`: An array of property names. The method will only search for values | ||
that match `regexp` within declarations of listed properties. | ||
- `fast`: A string that will be used to narrow down values and speed up | ||
the regexp search. Searching every single value with a regexp can be slow; | ||
so if you pass a `fast` string, PostCSS will first check whether the value | ||
contains the `fast` string; and only if it does will PostCSS check that value | ||
against `regexp`. For example, instead of just checking for `/\d+rem/` on | ||
all values, you can set `fast: 'rem'` to first check whether a value has | ||
the `rem` unit, and only if it does perform the regexp check. | ||
This method is useful if you are using a custom unit or function, | ||
@@ -852,2 +1439,19 @@ so need to iterate through all values. | ||
Arguments: | ||
* `pattern (string|RegExp)`: pattern, that we need to replace. | ||
* `opts (object) optional`: options to speed up th search: | ||
* `props`: An array of property names. The method will only search for values | ||
that match `regexp` within declarations of listed properties. | ||
* `fast`: A string that will be used to narrow down values and speed up | ||
the regexp search. Searching every single value with a regexp can be slow; | ||
so if you pass a `fast` string, PostCSS will first check whether the value | ||
contains the `fast` string; and only if it does will PostCSS check that | ||
value against `regexp`. For example, instead of just checking for `/\d+rem/` | ||
on all values, you can set `fast: 'rem'` to first check whether a value has | ||
the `rem` unit, and only if it does perform the regexp check. | ||
* `callback (function|string)`: string to replace `pattern` or callback, that | ||
will return new value. Callback will receive the same arguments as those | ||
passed to a function parameter of [`String#replace`]. | ||
[`String#replace`]: (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter) | ||
@@ -864,4 +1468,8 @@ | ||
Arguments: | ||
* `node (Node|object|string)`: new node. | ||
Because each node class is identifiable by unique properties, you can use | ||
the following shortcuts to create nodes to prepend/append: | ||
the following shortcuts to create nodes in insert methods: | ||
@@ -874,9 +1482,14 @@ ```js | ||
``` | ||
Also you can use string with CSS of new element. But it will be a little bit | ||
slower, that shortcuts above. | ||
### `container.insertBefore(oldNode, newNew)` and `container.insertAftr(oldNode, newNew)` | ||
```js | ||
root.append('a {}'); | ||
root.first.append('color: black; z-index: 1'); | ||
``` | ||
### `container.insertBefore(oldNode, newNew)` and `container.insertAfter(oldNode, newNew)` | ||
Insert `newNode` before/after `oldNode` within the container. | ||
`oldNode` can be a node or a node’s index. | ||
```js | ||
@@ -886,7 +1499,6 @@ rule.insertBefore(decl, decl.clone({ prop: '-webkit-' + decl.prop })); | ||
You can also use the same shorcuts available to `container.append()`. | ||
Arguments: | ||
```js | ||
rule.insertBefore(decl, { prop: 'color', value: 'black' }); | ||
``` | ||
* `oldNode (Node|number)`: child or child’s index. | ||
* `node (Node|object|string)`: new node. | ||
@@ -898,4 +1510,2 @@ ### `container.remove(node)` | ||
`node` can be a node or a node’s index. | ||
```js | ||
@@ -908,2 +1518,6 @@ rule.nodes.length //=> 5 | ||
Arguments: | ||
* `node (Node|number)`: child or child’s index. | ||
### `container.removeAll()` | ||
@@ -930,3 +1544,3 @@ | ||
Returns a [`Result`] instance representing the root's CSS. | ||
Returns a [`Result`] instance representing the root’s CSS. | ||
@@ -941,7 +1555,8 @@ ```js | ||
Options: | ||
Arguments: | ||
* `to`: the path where you’ll put the output CSS file. You should always set | ||
`to` to generate correct source maps. | ||
* `map`: an object of [source map options]. | ||
* `opts (object) optional`: options: | ||
* `to`: the path where you’ll put the output CSS file. You should always set | ||
`to` to generate correct source maps. | ||
* `map`: an object of [source map options]. | ||
@@ -1006,3 +1621,3 @@ ### `root.after` | ||
If you have not changed the parameters, calling `atrule.toString()` | ||
will stringify the original raw value (comments and all). | ||
will use the original raw value (comments and all). | ||
@@ -1335,2 +1950,3 @@ ```js | ||
[`source-map`]: https://github.com/mozilla/source-map | ||
[Promise]: http://www.html5rocks.com/en/tutorials/es6/promises/ | ||
@@ -1340,14 +1956,23 @@ [source map options]: https://github.com/postcss/postcss#source-map | ||
[`PostCSS#process(css, opts)`]: #pprocesscss-opts | ||
[`Root#toResult(opts)`]: #roottoresult-opts | ||
[`postcss(plugins)`]: #postcssplugins | ||
[`Declaration` node]: #declaration-node | ||
[`Comment` node]: #comment-node | ||
[`PostCSS#use`]: #puseplugin | ||
[`AtRule` node]: #atrule-node | ||
[`result.map`]: #resultmap | ||
[`result.css`]: #resultcss | ||
[`Root` node]: #root-node | ||
[`Rule` node]: #rule-node | ||
[`Input`]: #inputclass | ||
[`Result`]: #result-class | ||
[`Processor#process(css, opts)`]: #processorprocesscss-opts | ||
[`Root#toResult(opts)`]: #roottoresult-opts | ||
[`LazyResult#then()`]: #lazythenonfulfilled-onrejected | ||
[`postcss(plugins)`]: #postcssplugins | ||
[`postcss.plugin()`]: #postcsspluginname-initializer | ||
[`Declaration` node]: #declaration-node | ||
[`Result#messages`]: #resultmessages | ||
[`CssSyntaxError`]: #csssyntaxerror-class | ||
[`Processor#use`]: #processoruseplugin | ||
[`Result#warn()`]: #resultwarn | ||
[`Comment` node]: #comment-node | ||
[`AtRule` node]: #atrule-node | ||
[`from` option]: #processorprocesscss-opts | ||
[`LazyResult`]: #lazy-result-class | ||
[`Result#map`]: #resultmap | ||
[`Result#css`]: #resultcss | ||
[`Root` node]: #root-node | ||
[`Rule` node]: #rule-node | ||
[`Processor`]: #processor-class | ||
[`Warning`]: #warning-class | ||
[`Result`]: #result-class | ||
[`Input`]: #inputclass |
@@ -0,1 +1,20 @@ | ||
## 4.1 “Marquis Andras” | ||
* Asynchronous plugin support. | ||
* Add warnings from plugins and `Result#messages`. | ||
* Add `postcss.plugin()` to create plugins with a standard API. | ||
* Insert nodes by CSS string. | ||
* Show version warning message on error from an outdated plugin. | ||
* Send `Result` instance to plugins as the second argument. | ||
* Add `CssSyntaxError#plugin`. | ||
* Add `CssSyntaxError#showSourceCode()`. | ||
* Add `postcss.list` and `postcss.vendor` aliases. | ||
* Add `Processor#version`. | ||
* Parse wrong closing bracket. | ||
* Parse `!important` statement with spaces and comments inside (by Ben Briggs). | ||
* Throw an error on declaration without `prop` or `value` (by Philip Peterson). | ||
* Fix source map mappings position. | ||
* Add indexed source map support. | ||
* Always set `error.generated`. | ||
* Clean all source map annotation comments. | ||
## 4.0.6 | ||
@@ -26,3 +45,3 @@ * Remove `babel` from released package dependencies (by Andres Suarez). | ||
* Add `Node#cloneBefore()` and `cloneAfter()` shortcuts. | ||
* Add `Node#next()`, `prev()` and `root()` shorcuts. | ||
* Add `Node#next()`, `prev()` and `root()` shortcuts. | ||
* Add `Node#replaceWith()` method. | ||
@@ -130,3 +149,3 @@ * Add `Node#error()` method. | ||
* More safer parser to pass all hacks from Browserhacks.com. | ||
* Use real properties instead of magic getter/setter for raw propeties. | ||
* Use real properties instead of magic getter/setter for raw properties. | ||
@@ -142,4 +161,4 @@ ## 1.0 “Marquis Decarabia” | ||
* Allow to use latest PostCSS from GitHub by npm. | ||
* `Result` now is lazy and it will stringify output CSS only if you use `css` or | ||
`map` property. | ||
* `Result` now is lazy and it will generate output CSS only if you use `css` | ||
or `map` property. | ||
* Use separated `map.prev` option to set previous map. | ||
@@ -176,3 +195,3 @@ * Rename `inlineMap` option to `map.inline`. | ||
* Fix source maps on Windows. | ||
* Fix source maps for styles in subdirectory (by @nDmitry and @lydell). | ||
* Fix source maps for subdirectory (by Dmitry Nikitenko and Simon Lydell). | ||
* Autodetect previous source map. | ||
@@ -183,3 +202,3 @@ * Add `first` and `last` shortcuts to container nodes. | ||
* Copy code style to new nodes. | ||
* Add `eachInside` method to recursivelly iterate all nodes. | ||
* Add `eachInside` method to recursively iterate all nodes. | ||
* Add `selectors` shortcut to get selectors array. | ||
@@ -198,5 +217,5 @@ * Add `toResult` method to `Rule` to simplify work with several input files. | ||
and node end position. | ||
* You can set own stringify function. | ||
* You can set own CSS generate function. | ||
## 0.1 “Count Andromalius” | ||
* Initial release. |
@@ -11,7 +11,3 @@ "use strict"; | ||
// CSS at-rule like “this.keyframes name { }”. | ||
// | ||
// Can contain declarations (like this.font-face or this.page) ot another rules. | ||
var AtRule = (function (Container) { | ||
var AtRule = (function (_Container) { | ||
function AtRule(defaults) { | ||
@@ -21,9 +17,7 @@ _classCallCheck(this, AtRule); | ||
this.type = "atrule"; | ||
Container.call(this, defaults); | ||
_Container.call(this, defaults); | ||
} | ||
_inherits(AtRule, Container); | ||
_inherits(AtRule, _Container); | ||
// Stringify at-rule | ||
AtRule.prototype.stringify = function stringify(builder, semicolon) { | ||
@@ -33,3 +27,3 @@ var name = "@" + this.name; | ||
if (typeof this.afterName != "undefined") { | ||
if (typeof this.afterName !== "undefined") { | ||
name += this.afterName; | ||
@@ -50,28 +44,20 @@ } else if (params) { | ||
// Hack to mark, that at-rule contains children | ||
AtRule.prototype.append = function append(child) { | ||
if (!this.nodes) this.nodes = []; | ||
return Container.prototype.append.call(this, child); | ||
return _Container.prototype.append.call(this, child); | ||
}; | ||
// Hack to mark, that at-rule contains children | ||
AtRule.prototype.prepend = function prepend(child) { | ||
if (!this.nodes) this.nodes = []; | ||
return Container.prototype.prepend.call(this, child); | ||
return _Container.prototype.prepend.call(this, child); | ||
}; | ||
// Hack to mark, that at-rule contains children | ||
AtRule.prototype.insertBefore = function insertBefore(exist, add) { | ||
if (!this.nodes) this.nodes = []; | ||
return Container.prototype.insertBefore.call(this, exist, add); | ||
return _Container.prototype.insertBefore.call(this, exist, add); | ||
}; | ||
// Hack to mark, that at-rule contains children | ||
AtRule.prototype.insertAfter = function insertAfter(exist, add) { | ||
if (!this.nodes) this.nodes = []; | ||
return Container.prototype.insertAfter.call(this, exist, add); | ||
return _Container.prototype.insertAfter.call(this, exist, add); | ||
}; | ||
@@ -78,0 +64,0 @@ |
@@ -11,5 +11,3 @@ "use strict"; | ||
// CSS comment between declarations or rules | ||
var Comment = (function (Node) { | ||
var Comment = (function (_Node) { | ||
function Comment(defaults) { | ||
@@ -19,9 +17,7 @@ _classCallCheck(this, Comment); | ||
this.type = "comment"; | ||
Node.call(this, defaults); | ||
_Node.call(this, defaults); | ||
} | ||
_inherits(Comment, Node); | ||
_inherits(Comment, _Node); | ||
// Stringify declaration | ||
Comment.prototype.stringify = function stringify(builder) { | ||
@@ -28,0 +24,0 @@ var before = this.style("before"); |
@@ -5,3 +5,3 @@ "use strict"; | ||
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
@@ -18,24 +18,20 @@ var _inherits = function (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) subClass.__proto__ = superClass; }; | ||
// CSS node, that contain another nodes (like at-rules or rules with selectors) | ||
var Container = (function (Node) { | ||
var Container = (function (_Node) { | ||
function Container() { | ||
_classCallCheck(this, Container); | ||
if (Node != null) { | ||
Node.apply(this, arguments); | ||
if (_Node != null) { | ||
_Node.apply(this, arguments); | ||
} | ||
} | ||
_inherits(Container, Node); | ||
_inherits(Container, _Node); | ||
// Stringify container children | ||
Container.prototype.stringifyContent = function stringifyContent(builder) { | ||
if (!this.nodes) { | ||
return; | ||
}var i, | ||
}var i = undefined, | ||
last = this.nodes.length - 1; | ||
while (last > 0) { | ||
if (this.nodes[last].type != "comment") break; | ||
if (this.nodes[last].type !== "comment") break; | ||
last -= 1; | ||
@@ -46,9 +42,6 @@ } | ||
for (i = 0; i < this.nodes.length; i++) { | ||
this.nodes[i].stringify(builder, last != i || semicolon); | ||
this.nodes[i].stringify(builder, last !== i || semicolon); | ||
} | ||
}; | ||
// Stringify node with start (for example, selector) and brackets block | ||
// with child inside | ||
Container.prototype.stringifyBlock = function stringifyBlock(builder, start) { | ||
@@ -61,3 +54,3 @@ var before = this.style("before"); | ||
var after; | ||
var after = undefined; | ||
if (this.nodes && this.nodes.length) { | ||
@@ -74,5 +67,2 @@ this.stringifyContent(builder); | ||
// Add child to end of list without any checks. | ||
// Please, use `append()` method, `push()` is mostly for parser. | ||
Container.prototype.push = function push(child) { | ||
@@ -84,17 +74,2 @@ child.parent = this; | ||
// Execute `callback` on every child element. First arguments will be child | ||
// node, second will be index. | ||
// | ||
// css.each( (rule, i) => { | ||
// console.log(rule.type + ' at ' + i); | ||
// }); | ||
// | ||
// It is safe for add and remove elements to list while iterating: | ||
// | ||
// css.each( (rule) => { | ||
// css.insertBefore( rule, addPrefix(rule) ); | ||
// # On next iteration will be next rule, regardless of that | ||
// # list size was increased | ||
// }); | ||
Container.prototype.each = function each(callback) { | ||
@@ -109,4 +84,5 @@ if (!this.lastEach) this.lastEach = 0; | ||
if (!this.nodes) { | ||
return; | ||
}var index, result; | ||
return undefined; | ||
}var index = undefined, | ||
result = undefined; | ||
while (this.indexes[id] < this.nodes.length) { | ||
@@ -127,12 +103,2 @@ index = this.indexes[id]; | ||
// Execute callback on every child in all rules inside. | ||
// | ||
// First argument will be child node, second will be index inside parent. | ||
// | ||
// css.eachInside( (node, i) => { | ||
// console.log(node.type + ' at ' + i); | ||
// }); | ||
// | ||
// Also as `each` it is safe of insert/remove nodes inside iterating. | ||
Container.prototype.eachInside = function eachInside(callback) { | ||
@@ -150,18 +116,2 @@ return this.each(function (child, i) { | ||
// Execute callback on every declaration in all rules inside. | ||
// It will goes inside at-rules recursivelly. | ||
// | ||
// First argument will be declaration node, second will be index inside | ||
// parent rule. | ||
// | ||
// css.eachDecl( (decl, i) => { | ||
// console.log(decl.prop + ' in ' + decl.parent.selector + ':' + i); | ||
// }); | ||
// | ||
// Also as `each` it is safe of insert/remove nodes inside iterating. | ||
// | ||
// You can filter declrataion by property name: | ||
// | ||
// css.eachDecl('background', (decl) => { }); | ||
Container.prototype.eachDecl = function eachDecl(prop, callback) { | ||
@@ -171,3 +121,3 @@ if (!callback) { | ||
return this.eachInside(function (child, i) { | ||
if (child.type == "decl") { | ||
if (child.type === "decl") { | ||
var result = callback(child, i); | ||
@@ -179,3 +129,3 @@ if (result === false) return result; | ||
return this.eachInside(function (child, i) { | ||
if (child.type == "decl" && prop.test(child.prop)) { | ||
if (child.type === "decl" && prop.test(child.prop)) { | ||
var result = callback(child, i); | ||
@@ -187,3 +137,3 @@ if (result === false) return result; | ||
return this.eachInside(function (child, i) { | ||
if (child.type == "decl" && child.prop == prop) { | ||
if (child.type === "decl" && child.prop === prop) { | ||
var result = callback(child, i); | ||
@@ -196,17 +146,5 @@ if (result === false) return result; | ||
// Execute `callback` on every rule in conatiner and inside child at-rules. | ||
// | ||
// First argument will be rule node, second will be index inside parent. | ||
// | ||
// css.eachRule( (rule, i) => { | ||
// if ( parent.type == 'atrule' ) { | ||
// console.log(rule.selector + ' in ' + rule.parent.name); | ||
// } else { | ||
// console.log(rule.selector + ' at ' + i); | ||
// } | ||
// }); | ||
Container.prototype.eachRule = function eachRule(callback) { | ||
return this.eachInside(function (child, i) { | ||
if (child.type == "rule") { | ||
if (child.type === "rule") { | ||
var result = callback(child, i); | ||
@@ -218,18 +156,2 @@ if (result === false) return result; | ||
// Execute `callback` on every at-rule in conatiner and inside at-rules. | ||
// | ||
// First argument will be at-rule node, second will be index inside parent. | ||
// | ||
// css.eachAtRule( (atrule, parent, i) => { | ||
// if ( parent.type == 'atrule' ) { | ||
// console.log(atrule.name + ' in ' + atrule.parent.name); | ||
// } else { | ||
// console.log(atrule.name + ' at ' + i); | ||
// } | ||
// }); | ||
// | ||
// You can filter at-rules by name: | ||
// | ||
// css.eachAtRule('keyframes', (atrule) => { }); | ||
Container.prototype.eachAtRule = function eachAtRule(name, callback) { | ||
@@ -239,3 +161,3 @@ if (!callback) { | ||
return this.eachInside(function (child, i) { | ||
if (child.type == "atrule") { | ||
if (child.type === "atrule") { | ||
var result = callback(child, i); | ||
@@ -247,3 +169,3 @@ if (result === false) return result; | ||
return this.eachInside(function (child, i) { | ||
if (child.type == "atrule" && name.test(child.name)) { | ||
if (child.type === "atrule" && name.test(child.name)) { | ||
var result = callback(child, i); | ||
@@ -255,3 +177,3 @@ if (result === false) return result; | ||
return this.eachInside(function (child, i) { | ||
if (child.type == "atrule" && child.name == name) { | ||
if (child.type === "atrule" && child.name === name) { | ||
var result = callback(child, i); | ||
@@ -264,17 +186,5 @@ if (result === false) return result; | ||
// Execute callback on every block comment (only between rules | ||
// and declarations, not inside selectors and values) in all rules inside. | ||
// | ||
// First argument will be comment node, second will be index inside | ||
// parent rule. | ||
// | ||
// css.eachComment( (comment, i) => { | ||
// console.log(comment.content + ' at ' + i); | ||
// }); | ||
// | ||
// Also as `each` it is safe of insert/remove nodes inside iterating. | ||
Container.prototype.eachComment = function eachComment(callback) { | ||
return this.eachInside(function (child, i) { | ||
if (child.type == "comment") { | ||
if (child.type === "comment") { | ||
var result = callback(child, i); | ||
@@ -286,10 +196,2 @@ if (result === false) return result; | ||
// Add child to container. | ||
// | ||
// css.append(rule); | ||
// | ||
// You can add declaration by hash: | ||
// | ||
// rule.append({ prop: 'color', value: 'black' }); | ||
Container.prototype.append = function append(child) { | ||
@@ -314,10 +216,2 @@ var nodes = this.normalize(child, this.last); | ||
// Add child to beginning of container | ||
// | ||
// css.prepend(rule); | ||
// | ||
// You can add declaration by hash: | ||
// | ||
// rule.prepend({ prop: 'color', value: 'black' }); | ||
Container.prototype.prepend = function prepend(child) { | ||
@@ -346,11 +240,2 @@ var nodes = this.normalize(child, this.first, "prepend").reverse(); | ||
// Insert new `added` child before `exist`. | ||
// You can set node object or node index (it will be faster) in `exist`. | ||
// | ||
// css.insertAfter(1, rule); | ||
// | ||
// You can add declaration by hash: | ||
// | ||
// rule.insertBefore(1, { prop: 'color', value: 'black' }); | ||
Container.prototype.insertBefore = function insertBefore(exist, add) { | ||
@@ -375,3 +260,3 @@ exist = this.index(exist); | ||
this.nodes.splice(exist, 0, node); | ||
}var index; | ||
}var index = undefined; | ||
for (var id in this.indexes) { | ||
@@ -387,11 +272,2 @@ index = this.indexes[id]; | ||
// Insert new `added` child after `exist`. | ||
// You can set node object or node index (it will be faster) in `exist`. | ||
// | ||
// css.insertAfter(1, rule); | ||
// | ||
// You can add declaration by hash: | ||
// | ||
// rule.insertAfter(1, { prop: 'color', value: 'black' }); | ||
Container.prototype.insertAfter = function insertAfter(exist, add) { | ||
@@ -415,3 +291,3 @@ exist = this.index(exist); | ||
this.nodes.splice(exist + 1, 0, node); | ||
}var index; | ||
}var index = undefined; | ||
for (var id in this.indexes) { | ||
@@ -427,6 +303,2 @@ index = this.indexes[id]; | ||
// Remove `child` by index or node. | ||
// | ||
// css.remove(2); | ||
Container.prototype.remove = function remove(child) { | ||
@@ -437,3 +309,3 @@ child = this.index(child); | ||
var index; | ||
var index = undefined; | ||
for (var id in this.indexes) { | ||
@@ -449,6 +321,2 @@ index = this.indexes[id]; | ||
// Remove all children in node. | ||
// | ||
// css.removeAll(); | ||
Container.prototype.removeAll = function removeAll() { | ||
@@ -473,16 +341,2 @@ for (var _iterator = this.nodes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
// Recursivelly check all declarations inside node and replace | ||
// `regexp` by `callback`. | ||
// | ||
// css.replaceValues('black', '#000'); | ||
// | ||
// Argumets `regexp` and `callback` is same as in `String#replace()`. | ||
// | ||
// You can speed up checks by `props` and `fast` options: | ||
// | ||
// css.replaceValues(/\d+rem/, { fast: 'rem', props: ['width'] }, | ||
// function (str) { | ||
// return (14 * parseInt(str)) + 'px'; | ||
// }) | ||
Container.prototype.replaceValues = function replaceValues(regexp, opts, callback) { | ||
@@ -495,4 +349,4 @@ if (!callback) { | ||
this.eachDecl(function (decl) { | ||
if (opts.props && opts.props.indexOf(decl.prop) == -1) return; | ||
if (opts.fast && decl.value.indexOf(opts.fast) == -1) return; | ||
if (opts.props && opts.props.indexOf(decl.prop) === -1) return; | ||
if (opts.fast && decl.value.indexOf(opts.fast) === -1) return; | ||
@@ -505,5 +359,2 @@ decl.value = decl.value.replace(regexp, callback); | ||
// Return true if all nodes return true in `condition`. | ||
// Just shorcut for `nodes.every`. | ||
Container.prototype.every = function every(condition) { | ||
@@ -513,5 +364,2 @@ return this.nodes.every(condition); | ||
// Return true if one or more nodes return true in `condition`. | ||
// Just shorcut for `nodes.some`. | ||
Container.prototype.some = function some(condition) { | ||
@@ -521,6 +369,4 @@ return this.nodes.some(condition); | ||
// Return index of child | ||
Container.prototype.index = function index(child) { | ||
if (typeof child == "number") { | ||
if (typeof child === "number") { | ||
return child; | ||
@@ -532,9 +378,10 @@ } else { | ||
// Normalize child before insert. Copy before from `sample`. | ||
Container.prototype.normalize = function normalize(nodes, sample) { | ||
var _this = this; | ||
if (!Array.isArray(nodes)) { | ||
if (nodes.type == "root") { | ||
if (typeof nodes === "string") { | ||
var parse = require("./parse"); | ||
nodes = parse(nodes).nodes; | ||
} else if (!Array.isArray(nodes)) { | ||
if (nodes.type === "root") { | ||
nodes = nodes.nodes; | ||
@@ -544,13 +391,16 @@ } else if (nodes.type) { | ||
} else if (nodes.prop) { | ||
if (typeof nodes.value === "undefined") { | ||
throw "value field is missed in node creation"; | ||
} | ||
nodes = [new Declaration(nodes)]; | ||
} else if (nodes.selector) { | ||
var Rule = _interopRequire(require("./rule")); | ||
var Rule = require("./rule"); | ||
nodes = [new Rule(nodes)]; | ||
} else if (nodes.name) { | ||
var AtRule = _interopRequire(require("./at-rule")); | ||
var AtRule = require("./at-rule"); | ||
nodes = [new AtRule(nodes)]; | ||
} else if (nodes.text) { | ||
nodes = [new Comment(nodes)]; | ||
} else { | ||
throw "Unknown node type in node creation"; | ||
} | ||
@@ -561,4 +411,4 @@ } | ||
if (child.parent) child = child.clone(); | ||
if (typeof child.before == "undefined") { | ||
if (sample && typeof sample.before != "undefined") { | ||
if (typeof child.before === "undefined") { | ||
if (sample && typeof sample.before !== "undefined") { | ||
child.before = sample.before.replace(/[^\s]/g, ""); | ||
@@ -574,22 +424,14 @@ } | ||
_prototypeProperties(Container, null, { | ||
_createClass(Container, { | ||
first: { | ||
// Shortcut to get first child | ||
get: function () { | ||
if (!this.nodes) return undefined; | ||
return this.nodes[0]; | ||
}, | ||
configurable: true | ||
} | ||
}, | ||
last: { | ||
// Shortcut to get first child | ||
get: function () { | ||
if (!this.nodes) return undefined; | ||
return this.nodes[this.nodes.length - 1]; | ||
}, | ||
configurable: true | ||
} | ||
} | ||
@@ -596,0 +438,0 @@ }); |
@@ -9,10 +9,6 @@ "use strict"; | ||
var PreviousMap = _interopRequire(require("./previous-map")); | ||
var warn = _interopRequire(require("./warn")); | ||
var path = _interopRequire(require("path")); | ||
// Error while CSS parsing | ||
var CssSyntaxError = (function (SyntaxError) { | ||
function CssSyntaxError(message, line, column, source, file) { | ||
var CssSyntaxError = (function (_SyntaxError) { | ||
function CssSyntaxError(message, line, column, source, file, plugin) { | ||
_classCallCheck(this, CssSyntaxError); | ||
@@ -22,4 +18,5 @@ | ||
this.message = file ? file : "<css input>"; | ||
if (typeof line != "undefined" && typeof column != "undefined") { | ||
this.message = plugin ? plugin + ": " : ""; | ||
this.message += file ? file : "<css input>"; | ||
if (typeof line !== "undefined" && typeof column !== "undefined") { | ||
this.line = line; | ||
@@ -34,2 +31,3 @@ this.column = column; | ||
if (source) this.source = source; | ||
if (plugin) this.plugin = plugin; | ||
@@ -41,8 +39,8 @@ if (Error.captureStackTrace) { | ||
_inherits(CssSyntaxError, SyntaxError); | ||
_inherits(CssSyntaxError, _SyntaxError); | ||
// Return source of broken lines | ||
CssSyntaxError.prototype.highlight = function highlight(color) { | ||
var num = this.line - 1; | ||
CssSyntaxError.prototype.showSourceCode = function showSourceCode(color) { | ||
if (!this.source) { | ||
return ""; | ||
}var num = this.line - 1; | ||
var lines = this.source.split("\n"); | ||
@@ -59,3 +57,3 @@ | ||
if (typeof color == "undefined" && typeof process != "undefined") { | ||
if (typeof color === "undefined" && typeof process !== "undefined") { | ||
if (process.stdout && process.env) { | ||
@@ -72,7 +70,12 @@ color = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS; | ||
return prev + broken + mark + next; | ||
return "\n" + prev + broken + mark + next; | ||
}; | ||
CssSyntaxError.prototype.highlight = function highlight(color) { | ||
warn("CssSyntaxError#highlight is deprecated and will be removed " + "in 5.0. Use error.showSourceCode instead."); | ||
return this.showSourceCode(color).replace(/^\n/, ""); | ||
}; | ||
CssSyntaxError.prototype.setMozillaProps = function setMozillaProps() { | ||
var sample = Error.call(this, message); | ||
var sample = Error.call(this, this.message); | ||
if (sample.columnNumber) this.columnNumber = this.column; | ||
@@ -85,5 +88,3 @@ if (sample.description) this.description = this.message; | ||
CssSyntaxError.prototype.toString = function toString() { | ||
var text = this.message; | ||
if (this.source) text += "\n" + this.highlight(); | ||
return this.name + ": " + text; | ||
return this.name + ": " + this.message + this.showSourceCode(); | ||
}; | ||
@@ -90,0 +91,0 @@ |
@@ -9,9 +9,5 @@ "use strict"; | ||
var vendor = _interopRequire(require("./vendor")); | ||
var Node = _interopRequire(require("./node")); | ||
// CSS declaration like “color: black” in rules | ||
var Declaration = (function (Node) { | ||
var Declaration = (function (_Node) { | ||
function Declaration(defaults) { | ||
@@ -21,9 +17,7 @@ _classCallCheck(this, Declaration); | ||
this.type = "decl"; | ||
Node.call(this, defaults); | ||
_Node.call(this, defaults); | ||
} | ||
_inherits(Declaration, Node); | ||
_inherits(Declaration, _Node); | ||
// Stringify declaration | ||
Declaration.prototype.stringify = function stringify(builder, semicolon) { | ||
@@ -30,0 +24,0 @@ var before = this.style("before"); |
@@ -11,4 +11,2 @@ "use strict"; | ||
var Parser = _interopRequire(require("./parser")); | ||
var path = _interopRequire(require("path")); | ||
@@ -26,3 +24,3 @@ | ||
if (this.css[0] == "" || this.css[0] == "") { | ||
if (this.css[0] === "" || this.css[0] === "") { | ||
this.css = this.css.slice(1); | ||
@@ -52,15 +50,5 @@ } | ||
// Throw syntax error from this input | ||
Input.prototype.error = function error(message, line, column) { | ||
var opts = arguments[3] === undefined ? {} : arguments[3]; | ||
Input.prototype.error = (function (_error) { | ||
var _errorWrapper = function error() { | ||
return _error.apply(this, arguments); | ||
}; | ||
_errorWrapper.toString = function () { | ||
return _error.toString(); | ||
}; | ||
return _errorWrapper; | ||
})(function (message, line, column) { | ||
var error = new CssSyntaxError(message); | ||
@@ -70,19 +58,17 @@ | ||
if (origin) { | ||
error = new CssSyntaxError(message, origin.line, origin.column, origin.source, origin.file); | ||
error.generated = { | ||
line: line, | ||
column: column, | ||
source: this.css | ||
}; | ||
if (this.file) error.generated.file = this.file; | ||
error = new CssSyntaxError(message, origin.line, origin.column, origin.source, origin.file, opts.plugin); | ||
} else { | ||
error = new CssSyntaxError(message, line, column, this.css, this.file); | ||
error = new CssSyntaxError(message, line, column, this.css, this.file, opts.plugin); | ||
} | ||
error.generated = { | ||
line: line, | ||
column: column, | ||
source: this.css | ||
}; | ||
if (this.file) error.generated.file = this.file; | ||
return error; | ||
}); | ||
}; | ||
// Get origin position of code if source map was given | ||
Input.prototype.origin = function origin(line, column) { | ||
@@ -108,4 +94,2 @@ if (!this.map) { | ||
// Return path relative from source map root | ||
Input.prototype.mapResolve = function mapResolve(file) { | ||
@@ -112,0 +96,0 @@ return path.resolve(this.map.consumer().sourceRoot || ".", file); |
"use strict"; | ||
// Methods to parse list and split it to array | ||
module.exports = { | ||
// Split string to array by separator symbols with function and inside strings | ||
// cheching | ||
split: function split(string, separators, last) { | ||
split: (function (_split) { | ||
var _splitWrapper = function split(_x, _x2, _x3) { | ||
return _split.apply(this, arguments); | ||
}; | ||
_splitWrapper.toString = function () { | ||
return _split.toString(); | ||
}; | ||
return _splitWrapper; | ||
})(function (string, separators, last) { | ||
var array = []; | ||
@@ -23,16 +30,16 @@ var current = ""; | ||
escape = false; | ||
} else if (letter == "\\") { | ||
} else if (letter === "\\") { | ||
escape = true; | ||
} else if (letter == quote) { | ||
} else if (letter === quote) { | ||
quote = false; | ||
} | ||
} else if (letter == "\"" || letter == "'") { | ||
} else if (letter === "\"" || letter === "'") { | ||
quote = letter; | ||
} else if (letter == "(") { | ||
} else if (letter === "(") { | ||
func += 1; | ||
} else if (letter == ")") { | ||
} else if (letter === ")") { | ||
if (func > 0) func -= 1; | ||
} else if (func === 0) { | ||
for (var j = 0; j < separators.length; j++) { | ||
if (letter == separators[j]) split = true; | ||
if (letter === separators[j]) split = true; | ||
} | ||
@@ -52,26 +59,24 @@ } | ||
return array; | ||
}, | ||
}), | ||
// Split list devided by space: | ||
// | ||
// list.space('a b') #=> ['a', 'b'] | ||
// | ||
// It check for fuction and strings: | ||
// | ||
// list.space('calc(1px + 1em) "b c"') #=> ['calc(1px + 1em)', '"b c"'] | ||
space: function space(string) { | ||
return this.split(string, [" ", "\n", "\t"]); | ||
var spaces = [" ", "\n", "\t"]; | ||
return this.split(string, spaces); | ||
}, | ||
// Split list devided by comma | ||
// | ||
// list.comma('a, b') #=> ['a', 'b'] | ||
// | ||
// It check for fuction and strings: | ||
// | ||
// list.comma('rgba(0, 0, 0, 0) white') #=> ['rgba(0, 0, 0, 0)', '"white"'] | ||
comma: function comma(string) { | ||
return this.split(string, [","], true); | ||
} | ||
comma: (function (_comma) { | ||
var _commaWrapper = function comma(_x) { | ||
return _comma.apply(this, arguments); | ||
}; | ||
_commaWrapper.toString = function () { | ||
return _comma.toString(); | ||
}; | ||
return _commaWrapper; | ||
})(function (string) { | ||
var comma = ","; | ||
return this.split(string, [comma], true); | ||
}) | ||
}; |
@@ -7,4 +7,2 @@ "use strict"; | ||
var Result = _interopRequire(require("./result")); | ||
var Base64 = require("js-base64").Base64; | ||
@@ -16,17 +14,13 @@ | ||
// All tools to generate source maps | ||
var _default = (function () { | ||
var _class = function _default(root, opts) { | ||
_classCallCheck(this, _class); | ||
var MapGenerator = (function () { | ||
function MapGenerator(root, opts) { | ||
_classCallCheck(this, MapGenerator); | ||
this.root = root; | ||
this.opts = opts; | ||
this.mapOpts = opts.map || {}; | ||
} | ||
}; | ||
// Should map be generated | ||
MapGenerator.prototype.isMap = function isMap() { | ||
if (typeof this.opts.map != "undefined") { | ||
_class.prototype.isMap = function isMap() { | ||
if (typeof this.opts.map !== "undefined") { | ||
return !!this.opts.map; | ||
@@ -38,5 +32,3 @@ } else { | ||
// Return source map arrays from previous compilation step (like Sass) | ||
MapGenerator.prototype.previous = function previous() { | ||
_class.prototype.previous = function previous() { | ||
var _this = this; | ||
@@ -49,3 +41,3 @@ | ||
var map = node.source.input.map; | ||
if (_this.previousMaps.indexOf(map) == -1) { | ||
if (_this.previousMaps.indexOf(map) === -1) { | ||
_this.previousMaps.push(map); | ||
@@ -60,6 +52,4 @@ } | ||
// Should we inline source map to annotation comment | ||
MapGenerator.prototype.isInline = function isInline() { | ||
if (typeof this.mapOpts.inline != "undefined") { | ||
_class.prototype.isInline = function isInline() { | ||
if (typeof this.mapOpts.inline !== "undefined") { | ||
return this.mapOpts.inline; | ||
@@ -69,3 +59,3 @@ } | ||
var annotation = this.mapOpts.annotation; | ||
if (typeof annotation != "undefined" && annotation !== true) { | ||
if (typeof annotation !== "undefined" && annotation !== true) { | ||
return false; | ||
@@ -83,6 +73,4 @@ } | ||
// Should we set sourcesContent | ||
MapGenerator.prototype.isSourcesContent = function isSourcesContent() { | ||
if (typeof this.mapOpts.sourcesContent != "undefined") { | ||
_class.prototype.isSourcesContent = function isSourcesContent() { | ||
if (typeof this.mapOpts.sourcesContent !== "undefined") { | ||
return this.mapOpts.sourcesContent; | ||
@@ -99,14 +87,11 @@ } | ||
// Clear source map annotation comment | ||
MapGenerator.prototype.clearAnnotation = function clearAnnotation() { | ||
_class.prototype.clearAnnotation = function clearAnnotation() { | ||
if (this.mapOpts.annotation === false) { | ||
return; | ||
}var node; | ||
}var node = undefined; | ||
for (var i = this.root.nodes.length - 1; i >= 0; i--) { | ||
node = this.root.nodes[i]; | ||
if (node.type != "comment") continue; | ||
if (node.text.match(/^# sourceMappingURL=/)) { | ||
if (node.type !== "comment") continue; | ||
if (node.text.indexOf("# sourceMappingURL=") === 0) { | ||
this.root.remove(i); | ||
return; | ||
} | ||
@@ -116,5 +101,3 @@ } | ||
// Set origin CSS content | ||
MapGenerator.prototype.setSourcesContent = function setSourcesContent() { | ||
_class.prototype.setSourcesContent = function setSourcesContent() { | ||
var _this = this; | ||
@@ -135,5 +118,3 @@ | ||
// Apply source map from previous compilation step (like Sass) | ||
MapGenerator.prototype.applyPrevMaps = function applyPrevMaps() { | ||
_class.prototype.applyPrevMaps = function applyPrevMaps() { | ||
for (var _iterator = this.previous(), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
@@ -155,9 +136,11 @@ var _ref; | ||
var root = prev.root || path.dirname(prev.file); | ||
var map; | ||
var map = undefined; | ||
if (this.mapOpts.sourcesContent === false) { | ||
map = new mozilla.SourceMapConsumer(prev.text); | ||
map.sourcesContent = map.sourcesContent.map(function (i) { | ||
return null; | ||
}); | ||
if (map.sourcesContent) { | ||
map.sourcesContent = map.sourcesContent.map(function () { | ||
return null; | ||
}); | ||
} | ||
} else { | ||
@@ -171,8 +154,6 @@ map = prev.consumer(); | ||
// Should we add annotation comment | ||
MapGenerator.prototype.isAnnotation = function isAnnotation() { | ||
_class.prototype.isAnnotation = function isAnnotation() { | ||
if (this.isInline()) { | ||
return true; | ||
} else if (typeof this.mapOpts.annotation != "undefined") { | ||
} else if (typeof this.mapOpts.annotation !== "undefined") { | ||
return this.mapOpts.annotation; | ||
@@ -188,10 +169,8 @@ } else if (this.previous().length) { | ||
// Add source map annotation comment if it is needed | ||
_class.prototype.addAnnotation = function addAnnotation() { | ||
var content = undefined; | ||
MapGenerator.prototype.addAnnotation = function addAnnotation() { | ||
var content; | ||
if (this.isInline()) { | ||
content = "data:application/json;base64," + Base64.encode(this.map.toString()); | ||
} else if (typeof this.mapOpts.annotation == "string") { | ||
} else if (typeof this.mapOpts.annotation === "string") { | ||
content = this.mapOpts.annotation; | ||
@@ -205,5 +184,3 @@ } else { | ||
// Return output CSS file path | ||
MapGenerator.prototype.outputFile = function outputFile() { | ||
_class.prototype.outputFile = function outputFile() { | ||
if (this.opts.to) { | ||
@@ -218,5 +195,3 @@ return this.relative(this.opts.to); | ||
// Return Result object with map | ||
MapGenerator.prototype.generateMap = function generateMap() { | ||
_class.prototype.generateMap = function generateMap() { | ||
this.stringify(); | ||
@@ -234,8 +209,6 @@ if (this.isSourcesContent()) this.setSourcesContent(); | ||
// Return path relative from output CSS file | ||
MapGenerator.prototype.relative = function relative(file) { | ||
_class.prototype.relative = function relative(file) { | ||
var from = this.opts.to ? path.dirname(this.opts.to) : "."; | ||
if (typeof this.mapOpts.annotation == "string") { | ||
if (typeof this.mapOpts.annotation === "string") { | ||
from = path.dirname(path.resolve(from, this.mapOpts.annotation)); | ||
@@ -245,3 +218,3 @@ } | ||
file = path.relative(from, file); | ||
if (path.sep == "\\") { | ||
if (path.sep === "\\") { | ||
return file.replace(/\\/g, "/"); | ||
@@ -253,11 +226,7 @@ } else { | ||
// Return path of node source for map | ||
MapGenerator.prototype.sourcePath = function sourcePath(node) { | ||
_class.prototype.sourcePath = function sourcePath(node) { | ||
return this.relative(node.source.input.from); | ||
}; | ||
// Return CSS string and source map | ||
MapGenerator.prototype.stringify = function stringify() { | ||
_class.prototype.stringify = function stringify() { | ||
var _this = this; | ||
@@ -271,7 +240,8 @@ | ||
var lines, last; | ||
var lines = undefined, | ||
last = undefined; | ||
var builder = function (str, node, type) { | ||
_this.css += str; | ||
if (node && node.source && node.source.start && type != "end") { | ||
if (node && node.source && node.source.start && type !== "end") { | ||
_this.map.addMapping({ | ||
@@ -299,3 +269,3 @@ source: _this.sourcePath(node), | ||
if (node && node.source && node.source.end && type != "start") { | ||
if (node && node.source && node.source.end && type !== "start") { | ||
_this.map.addMapping({ | ||
@@ -309,3 +279,3 @@ source: _this.sourcePath(node), | ||
line: line, | ||
column: column | ||
column: column - 1 | ||
} | ||
@@ -319,5 +289,3 @@ }); | ||
// Return Result object with or without map | ||
MapGenerator.prototype.generate = function generate() { | ||
_class.prototype.generate = function generate() { | ||
this.clearAnnotation(); | ||
@@ -332,5 +300,5 @@ | ||
return MapGenerator; | ||
return _class; | ||
})(); | ||
module.exports = MapGenerator; | ||
module.exports = _default; |
285
lib/node.js
@@ -9,3 +9,2 @@ "use strict"; | ||
// Default code style | ||
var defaultStyle = { | ||
@@ -25,5 +24,4 @@ colon: ": ", | ||
// Recursivly clone objects | ||
var cloneNode = (function (_cloneNode) { | ||
var _cloneNodeWrapper = function cloneNode() { | ||
var _cloneNodeWrapper = function cloneNode(_x, _x2) { | ||
return _cloneNode.apply(this, arguments); | ||
@@ -38,3 +36,3 @@ }; | ||
})(function (obj, parent) { | ||
if (typeof obj != "object") return obj; | ||
if (typeof obj !== "object") return obj; | ||
var cloned = new obj.constructor(); | ||
@@ -46,11 +44,11 @@ | ||
if (i == "parent" && typeof value == "object") { | ||
if (i === "parent" && typeof value === "object") { | ||
if (parent) cloned[i] = parent; | ||
} else if (i == "source") { | ||
} else if (i === "source") { | ||
cloned[i] = value; | ||
} else if (value instanceof Array) { | ||
cloned[i] = value.map(function (i) { | ||
return cloneNode(i, cloned); | ||
cloned[i] = value.map(function (j) { | ||
return cloneNode(j, cloned); | ||
}); | ||
} else if (i != "before" && i != "after" && i != "between" && i != "semicolon") { | ||
} else if (i !== "before" && i !== "after" && i !== "between" && i !== "semicolon") { | ||
cloned[i] = cloneNode(value, cloned); | ||
@@ -63,32 +61,19 @@ } | ||
// Some common methods for all CSS nodes | ||
var Node = (function () { | ||
function Node() { | ||
var _default = (function () { | ||
var _class = function _default() { | ||
var defaults = arguments[0] === undefined ? {} : arguments[0]; | ||
_classCallCheck(this, Node); | ||
_classCallCheck(this, _class); | ||
for (var name in defaults) { | ||
this[name] = defaults[name]; | ||
for (var _name in defaults) { | ||
this[_name] = defaults[_name]; | ||
} | ||
} | ||
}; | ||
// Return error to mark error in your plugin syntax: | ||
// | ||
// if ( wrongVariable ) { | ||
// throw decl.error('Wrong variable'); | ||
// } | ||
// | ||
// You can also get origin line and column from previous source map: | ||
// | ||
// if ( deprecatedSyntax ) { | ||
// var error = decl.error('Deprecated syntax'); | ||
// console.warn(error.toString()); | ||
// } | ||
_class.prototype.error = function error(message) { | ||
var opts = arguments[1] === undefined ? {} : arguments[1]; | ||
Node.prototype.error = function error(message) { | ||
if (this.source) { | ||
var pos = this.source.start; | ||
return this.source.input.error(message, pos.line, pos.column); | ||
return this.source.input.error(message, pos.line, pos.column, opts); | ||
} else { | ||
@@ -99,11 +84,3 @@ return new CssSyntaxError(message); | ||
// Remove this node from parent | ||
// | ||
// decl.removeSelf(); | ||
// | ||
// Note, that removing by index is faster: | ||
// | ||
// rule.each( (decl, i) => rule.remove(i) ); | ||
Node.prototype.removeSelf = function removeSelf() { | ||
_class.prototype.removeSelf = function removeSelf() { | ||
if (this.parent) { | ||
@@ -116,7 +93,3 @@ this.parent.remove(this); | ||
// Shortcut to insert nodes before and remove self. | ||
// | ||
// importNode.replace( loadedRoot ); | ||
Node.prototype.replace = function replace(nodes) { | ||
_class.prototype.replace = function replace(nodes) { | ||
this.parent.insertBefore(this, nodes); | ||
@@ -127,7 +100,3 @@ this.parent.remove(this); | ||
// Return CSS string of current node | ||
// | ||
// decl.toString(); //=> " color: black" | ||
Node.prototype.toString = function toString() { | ||
_class.prototype.toString = function toString() { | ||
var result = ""; | ||
@@ -141,16 +110,8 @@ var builder = function (str) { | ||
// Clone current node | ||
// | ||
// rule.append( decl.clone() ); | ||
// | ||
// You can override properties while cloning: | ||
// | ||
// rule.append( decl.clone({ value: '0' }) ); | ||
Node.prototype.clone = function clone() { | ||
_class.prototype.clone = function clone() { | ||
var overrides = arguments[0] === undefined ? {} : arguments[0]; | ||
var cloned = cloneNode(this); | ||
for (var name in overrides) { | ||
cloned[name] = overrides[name]; | ||
for (var _name in overrides) { | ||
cloned[_name] = overrides[_name]; | ||
} | ||
@@ -160,8 +121,3 @@ return cloned; | ||
// Clone node and insert clone before current one. | ||
// It accept properties to change in clone and return new node. | ||
// | ||
// decl.cloneBefore({ prop: '-webkit-' + del.prop }); | ||
Node.prototype.cloneBefore = function cloneBefore() { | ||
_class.prototype.cloneBefore = function cloneBefore() { | ||
var overrides = arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -174,8 +130,3 @@ | ||
// Clone node and insert clone after current one. | ||
// It accept properties to change in clone and return new node. | ||
// | ||
// decl.cloneAfter({ value: convertToRem(decl.value) }); | ||
Node.prototype.cloneAfter = function cloneAfter() { | ||
_class.prototype.cloneAfter = function cloneAfter() { | ||
var overrides = arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -188,7 +139,3 @@ | ||
// Replace with node by another one. | ||
// | ||
// decl.replaceWith(fixedDecl); | ||
Node.prototype.replaceWith = function replaceWith(node) { | ||
_class.prototype.replaceWith = function replaceWith(node) { | ||
this.parent.insertBefore(this, node); | ||
@@ -199,10 +146,4 @@ this.removeSelf(); | ||
// Remove node from current place and put to end of new one. | ||
// It will also clean node code styles, but will keep `between` if old | ||
// parent and new parent has same root. | ||
// | ||
// rule.moveTo(atRule); | ||
Node.prototype.moveTo = function moveTo(container) { | ||
this.cleanStyles(this.root() == container.root()); | ||
_class.prototype.moveTo = function moveTo(container) { | ||
this.cleanStyles(this.root() === container.root()); | ||
this.removeSelf(); | ||
@@ -213,10 +154,4 @@ container.append(this); | ||
// Remove node from current place and put to before other node. | ||
// It will also clean node code styles, but will keep `between` if old | ||
// parent and new parent has same root. | ||
// | ||
// rule.moveBefore(rule.parent); | ||
Node.prototype.moveBefore = function moveBefore(node) { | ||
this.cleanStyles(this.root() == node.root()); | ||
_class.prototype.moveBefore = function moveBefore(node) { | ||
this.cleanStyles(this.root() === node.root()); | ||
this.removeSelf(); | ||
@@ -227,10 +162,4 @@ node.parent.insertBefore(node, this); | ||
// Remove node from current place and put to after other node. | ||
// It will also clean node code styles, but will keep `between` if old | ||
// parent and new parent has same root. | ||
// | ||
// rule.moveAfter(rule.parent); | ||
Node.prototype.moveAfter = function moveAfter(node) { | ||
this.cleanStyles(this.root() == node.root()); | ||
_class.prototype.moveAfter = function moveAfter(node) { | ||
this.cleanStyles(this.root() === node.root()); | ||
this.removeSelf(); | ||
@@ -241,11 +170,3 @@ node.parent.insertAfter(node, this); | ||
// Return next node in parent. If current node is last one, | ||
// method will return `undefined`. | ||
// | ||
// var next = decl.next(); | ||
// if ( next && next.prop == removePrefix(decl.prop) ) { | ||
// decl.removeSelf(); | ||
// } | ||
Node.prototype.next = function next() { | ||
_class.prototype.next = function next() { | ||
var index = this.parent.index(this); | ||
@@ -255,11 +176,3 @@ return this.parent.nodes[index + 1]; | ||
// Return previous node in parent. If current node is first one, | ||
// method will return `undefined`. | ||
// | ||
// var prev = decl.prev(); | ||
// if ( prev && removePrefix(prev.prop) == decl.prop) ) { | ||
// prev.removeSelf(); | ||
// } | ||
Node.prototype.prev = function prev() { | ||
_class.prototype.prev = function prev() { | ||
var index = this.parent.index(this); | ||
@@ -269,20 +182,22 @@ return this.parent.nodes[index - 1]; | ||
// Remove `parent` node on cloning to fix circular structures | ||
Node.prototype.toJSON = function toJSON() { | ||
_class.prototype.toJSON = function toJSON() { | ||
var fixed = {}; | ||
for (var name in this) { | ||
if (!this.hasOwnProperty(name)) continue; | ||
if (name == "parent") continue; | ||
var value = this[name]; | ||
for (var _name in this) { | ||
if (!this.hasOwnProperty(_name)) continue; | ||
if (_name === "parent") continue; | ||
var value = this[_name]; | ||
if (value instanceof Array) { | ||
fixed[name] = value.map(function (i) { | ||
return typeof i == "object" && i.toJSON ? i.toJSON() : i; | ||
fixed[_name] = value.map(function (i) { | ||
if (typeof i === "object" && i.toJSON) { | ||
return i.toJSON(); | ||
} else { | ||
return i; | ||
} | ||
}); | ||
} else if (typeof value == "object" && value.toJSON) { | ||
fixed[name] = value.toJSON(); | ||
} else if (typeof value === "object" && value.toJSON) { | ||
fixed[_name] = value.toJSON(); | ||
} else { | ||
fixed[name] = value; | ||
fixed[_name] = value; | ||
} | ||
@@ -294,6 +209,4 @@ } | ||
// Copy code style from first node with same type | ||
Node.prototype.style = function style(own, detect) { | ||
var value; | ||
_class.prototype.style = function style(own, detect) { | ||
var value = undefined; | ||
if (!detect) detect = own; | ||
@@ -304,3 +217,3 @@ | ||
value = this[own]; | ||
if (typeof value != "undefined") { | ||
if (typeof value !== "undefined") { | ||
return value; | ||
@@ -313,4 +226,4 @@ } | ||
// Hack for first rule in CSS | ||
if (detect == "before") { | ||
if (!parent || parent.type == "root" && parent.first == this) { | ||
if (detect === "before") { | ||
if (!parent || parent.type === "root" && parent.first === this) { | ||
return ""; | ||
@@ -326,25 +239,25 @@ } | ||
if (!root.styleCache) root.styleCache = {}; | ||
if (typeof root.styleCache[detect] != "undefined") { | ||
if (typeof root.styleCache[detect] !== "undefined") { | ||
return root.styleCache[detect]; | ||
} | ||
if (detect == "semicolon") { | ||
if (detect === "semicolon") { | ||
root.eachInside(function (i) { | ||
if (i.nodes && i.nodes.length && i.last.type == "decl") { | ||
if (i.nodes && i.nodes.length && i.last.type === "decl") { | ||
value = i.semicolon; | ||
if (typeof value != "undefined") return false; | ||
if (typeof value !== "undefined") return false; | ||
} | ||
}); | ||
} else if (detect == "emptyBody") { | ||
} else if (detect === "emptyBody") { | ||
root.eachInside(function (i) { | ||
if (i.nodes && i.nodes.length === 0) { | ||
value = i.after; | ||
if (typeof value != "undefined") return false; | ||
if (typeof value !== "undefined") return false; | ||
} | ||
}); | ||
} else if (detect == "indent") { | ||
} else if (detect === "indent") { | ||
root.eachInside(function (i) { | ||
var p = i.parent; | ||
if (p && p != root && p.parent && p.parent == root) { | ||
if (typeof i.before != "undefined") { | ||
if (p && p !== root && p.parent && p.parent === root) { | ||
if (typeof i.before !== "undefined") { | ||
var parts = i.before.split("\n"); | ||
@@ -357,7 +270,7 @@ value = parts[parts.length - 1]; | ||
}); | ||
} else if (detect == "beforeComment") { | ||
} else if (detect === "beforeComment") { | ||
root.eachComment(function (i) { | ||
if (typeof i.before != "undefined") { | ||
if (typeof i.before !== "undefined") { | ||
value = i.before; | ||
if (value.indexOf("\n") != -1) { | ||
if (value.indexOf("\n") !== -1) { | ||
value = value.replace(/[^\n]+$/, ""); | ||
@@ -368,10 +281,10 @@ } | ||
}); | ||
if (typeof value == "undefined") { | ||
if (typeof value === "undefined") { | ||
value = this.style(null, "beforeDecl"); | ||
} | ||
} else if (detect == "beforeDecl") { | ||
} else if (detect === "beforeDecl") { | ||
root.eachDecl(function (i) { | ||
if (typeof i.before != "undefined") { | ||
if (typeof i.before !== "undefined") { | ||
value = i.before; | ||
if (value.indexOf("\n") != -1) { | ||
if (value.indexOf("\n") !== -1) { | ||
value = value.replace(/[^\n]+$/, ""); | ||
@@ -382,11 +295,11 @@ } | ||
}); | ||
if (typeof value == "undefined") { | ||
if (typeof value === "undefined") { | ||
value = this.style(null, "beforeRule"); | ||
} | ||
} else if (detect == "beforeRule") { | ||
} else if (detect === "beforeRule") { | ||
root.eachInside(function (i) { | ||
if (i.nodes && (i.parent != root || root.first != i)) { | ||
if (typeof i.before != "undefined") { | ||
if (i.nodes && (i.parent !== root || root.first !== i)) { | ||
if (typeof i.before !== "undefined") { | ||
value = i.before; | ||
if (value.indexOf("\n") != -1) { | ||
if (value.indexOf("\n") !== -1) { | ||
value = value.replace(/[^\n]+$/, ""); | ||
@@ -398,8 +311,8 @@ } | ||
}); | ||
} else if (detect == "beforeClose") { | ||
} else if (detect === "beforeClose") { | ||
root.eachInside(function (i) { | ||
if (i.nodes && i.nodes.length > 0) { | ||
if (typeof i.after != "undefined") { | ||
if (typeof i.after !== "undefined") { | ||
value = i.after; | ||
if (value.indexOf("\n") != -1) { | ||
if (value.indexOf("\n") !== -1) { | ||
value = value.replace(/[^\n]+$/, ""); | ||
@@ -411,8 +324,8 @@ } | ||
}); | ||
} else if (detect == "before" || detect == "after") { | ||
if (this.type == "decl") { | ||
} else if (detect === "before" || detect === "after") { | ||
if (this.type === "decl") { | ||
value = this.style(null, "beforeDecl"); | ||
} else if (this.type == "comment") { | ||
} else if (this.type === "comment") { | ||
value = this.style(null, "beforeComment"); | ||
} else if (detect == "before") { | ||
} else if (detect === "before") { | ||
value = this.style(null, "beforeRule"); | ||
@@ -425,3 +338,3 @@ } else { | ||
var depth = 0; | ||
while (node && node.type != "root") { | ||
while (node && node.type !== "root") { | ||
depth += 1; | ||
@@ -431,6 +344,8 @@ node = node.parent; | ||
if (value.indexOf("\n") != -1) { | ||
if (value.indexOf("\n") !== -1) { | ||
var indent = this.style(null, "indent"); | ||
if (indent.length) { | ||
for (var step = 0; step < depth; step++) value += indent; | ||
for (var step = 0; step < depth; step++) { | ||
value += indent; | ||
} | ||
} | ||
@@ -440,5 +355,5 @@ } | ||
return value; | ||
} else if (detect == "colon") { | ||
} else if (detect === "colon") { | ||
root.eachDecl(function (i) { | ||
if (typeof i.between != "undefined") { | ||
if (typeof i.between !== "undefined") { | ||
value = i.between.replace(/[^\s:]/g, ""); | ||
@@ -448,7 +363,7 @@ return false; | ||
}); | ||
} else if (detect == "beforeOpen") { | ||
} else if (detect === "beforeOpen") { | ||
root.eachInside(function (i) { | ||
if (i.type != "decl") { | ||
if (i.type !== "decl") { | ||
value = i.between; | ||
if (typeof value != "undefined") return false; | ||
if (typeof value !== "undefined") return false; | ||
} | ||
@@ -459,7 +374,7 @@ }); | ||
value = i[own]; | ||
if (typeof value != "undefined") return false; | ||
if (typeof value !== "undefined") return false; | ||
}); | ||
} | ||
if (typeof value == "undefined") value = defaultStyle[detect]; | ||
if (typeof value === "undefined") value = defaultStyle[detect]; | ||
@@ -470,5 +385,3 @@ root.styleCache[detect] = value; | ||
// Return top parent , parent of parents. | ||
Node.prototype.root = function root() { | ||
_class.prototype.root = function root() { | ||
var result = this; | ||
@@ -479,5 +392,3 @@ while (result.parent) result = result.parent; | ||
// Recursivelly remove all code style properties (`before` and `between`). | ||
Node.prototype.cleanStyles = function cleanStyles(keepBetween) { | ||
_class.prototype.cleanStyles = function cleanStyles(keepBetween) { | ||
delete this.before; | ||
@@ -506,5 +417,3 @@ delete this.after; | ||
// Use raw value if origin was not changed | ||
Node.prototype.stringifyRaw = function stringifyRaw(prop) { | ||
_class.prototype.stringifyRaw = function stringifyRaw(prop) { | ||
var value = this[prop]; | ||
@@ -519,5 +428,5 @@ var raw = this["_" + prop]; | ||
return Node; | ||
return _class; | ||
})(); | ||
module.exports = Node; | ||
module.exports = _default; |
@@ -5,2 +5,4 @@ "use strict"; | ||
module.exports = parse; | ||
var Parser = _interopRequire(require("./parser")); | ||
@@ -10,3 +12,3 @@ | ||
module.exports = function (css, opts) { | ||
function parse(css, opts) { | ||
var input = new Input(css, opts); | ||
@@ -19,2 +21,2 @@ | ||
return parser.root; | ||
}; | ||
} |
@@ -19,4 +19,2 @@ "use strict"; | ||
// CSS parser | ||
var Parser = (function () { | ||
@@ -43,3 +41,3 @@ function Parser(input) { | ||
Parser.prototype.loop = function loop() { | ||
var token; | ||
var token = undefined; | ||
while (this.pos < this.tokens.length) { | ||
@@ -107,3 +105,3 @@ token = this.tokens[this.pos]; | ||
Parser.prototype.word = function word() { | ||
var token; | ||
var token = undefined; | ||
var end = false; | ||
@@ -117,19 +115,11 @@ var type = null; | ||
this.pos += 1; | ||
while (true) { | ||
while (this.pos < this.tokens.length) { | ||
token = this.tokens[this.pos]; | ||
if (!token) { | ||
this.pos -= 1; | ||
end = true; | ||
break; | ||
} | ||
type = token[0]; | ||
type = token[0]; | ||
if (type == "(") { | ||
if (type === "(") { | ||
if (!bracket) bracket = token; | ||
brackets += 1; | ||
} else if (type == ")") { | ||
brackets -= 1; | ||
if (brackets === 0) bracket = null; | ||
} else if (brackets === 0) { | ||
if (type == ";") { | ||
if (type === ";") { | ||
if (colon) { | ||
@@ -141,15 +131,18 @@ this.decl(this.tokens.slice(start, this.pos + 1)); | ||
} | ||
} else if (type == "{") { | ||
} else if (type === "{") { | ||
this.rule(this.tokens.slice(start, this.pos + 1)); | ||
return; | ||
} else if (type == "}") { | ||
} else if (type === "}") { | ||
this.pos -= 1; | ||
end = true; | ||
break; | ||
} else if (type == "at-word") { | ||
} else if (type === "at-word") { | ||
this.pos -= 1; | ||
break; | ||
} else { | ||
if (type == ":") colon = true; | ||
if (type === ":") colon = true; | ||
} | ||
} else if (type === ")") { | ||
brackets -= 1; | ||
if (brackets === 0) bracket = null; | ||
} | ||
@@ -159,2 +152,6 @@ | ||
} | ||
if (this.pos === this.tokens.length) { | ||
this.pos -= 1; | ||
end = true; | ||
} | ||
@@ -168,3 +165,3 @@ if (brackets > 0 && !this.input.safe) { | ||
token = this.tokens[this.pos][0]; | ||
if (token != "space" && token != "comment") break; | ||
if (token !== "space" && token !== "comment") break; | ||
this.pos -= 1; | ||
@@ -203,3 +200,3 @@ } | ||
var last = tokens[tokens.length - 1]; | ||
if (last[0] == ";") { | ||
if (last[0] === ";") { | ||
this.semicolon = true; | ||
@@ -214,3 +211,3 @@ tokens.pop(); | ||
while (tokens[0][0] != "word") { | ||
while (tokens[0][0] !== "word") { | ||
node.before += tokens.shift()[1]; | ||
@@ -223,10 +220,10 @@ } | ||
var token; | ||
var token = undefined; | ||
while (tokens.length) { | ||
token = tokens.shift(); | ||
if (token[0] == ":") { | ||
if (token[0] === ":") { | ||
node.between += token[1]; | ||
break; | ||
} else if (token[0] != "space" && token[0] != "comment") { | ||
} else if (token[0] !== "space" && token[0] !== "comment") { | ||
this.unknownWord(node, token, tokens); | ||
@@ -238,3 +235,3 @@ } else { | ||
if (node.prop[0] == "_" || node.prop[0] == "*") { | ||
if (node.prop[0] === "_" || node.prop[0] === "*") { | ||
node.before += node.prop[0]; | ||
@@ -249,9 +246,26 @@ node.prop = node.prop.slice(1); | ||
token = tokens[i]; | ||
if (token[1] == "!important") { | ||
if (token[1] === "!important") { | ||
node.important = true; | ||
var string = this.stringFrom(tokens, i); | ||
string = this.spacesFromEnd(tokens) + string; | ||
if (string != " !important") node._important = string; | ||
if (string !== " !important") node._important = string; | ||
break; | ||
} else if (token[0] != "space" && token[0] != "comment") { | ||
} else if (token[1] === "important") { | ||
var cache = tokens.slice(0); | ||
var str = ""; | ||
for (var j = i; j > 0; j--) { | ||
var type = cache[j][0]; | ||
if (str.trim().indexOf("!") === 0 && type !== "space") { | ||
break; | ||
} | ||
str = cache.pop()[1] + str; | ||
} | ||
if (str.trim().indexOf("!") === 0) { | ||
node.important = true; | ||
node._important = str; | ||
tokens = cache; | ||
} | ||
} | ||
if (token[0] !== "space" && token[0] !== "comment") { | ||
break; | ||
@@ -263,3 +277,3 @@ } | ||
if (node.value.indexOf(":") != -1 && !this.input.safe) { | ||
if (node.value.indexOf(":") !== -1 && !this.input.safe) { | ||
this.checkMissedSemicolon(tokens); | ||
@@ -281,18 +295,15 @@ } | ||
var next; | ||
var last = false; | ||
var open = false; | ||
var params = []; | ||
while (true) { | ||
this.pos += 1; | ||
this.pos += 1; | ||
while (this.pos < this.tokens.length) { | ||
token = this.tokens[this.pos]; | ||
if (!token) { | ||
last = true; | ||
break; | ||
} else if (token[0] == ";") { | ||
if (token[0] === ";") { | ||
node.source.end = { line: token[2], column: token[3] }; | ||
this.semicolon = true; | ||
break; | ||
} else if (token[0] == "{") { | ||
} else if (token[0] === "{") { | ||
open = true; | ||
@@ -303,3 +314,8 @@ break; | ||
} | ||
this.pos += 1; | ||
} | ||
if (this.pos === this.tokens.length) { | ||
last = true; | ||
} | ||
@@ -378,3 +394,4 @@ node.between = this.spacesFromEnd(params); | ||
var brackets = 0; | ||
var type, token; | ||
var type = undefined, | ||
token = undefined; | ||
for (var i = 0; i < tokens.length; i++) { | ||
@@ -384,7 +401,7 @@ token = tokens[i]; | ||
if (type == "(") { | ||
if (type === "(") { | ||
brackets += 1; | ||
} else if (type == ")") { | ||
} else if (type === ")") { | ||
brackets -= 0; | ||
} else if (brackets === 0 && type == ":") { | ||
} else if (brackets === 0 && type === ":") { | ||
if (!prev && this.input.safe) { | ||
@@ -394,3 +411,3 @@ continue; | ||
throw this.input.error("Double colon", token[2], token[3]); | ||
} else if (prev[0] == "word" && prev[1] == "progid") { | ||
} else if (prev[0] === "word" && prev[1] === "progid") { | ||
continue; | ||
@@ -409,8 +426,8 @@ } else { | ||
}if (this.input.safe) { | ||
var split; | ||
var split = undefined; | ||
for (split = colon - 1; split >= 0; split--) { | ||
if (tokens[split][0] == "word") break; | ||
if (tokens[split][0] === "word") break; | ||
} | ||
for (split -= 1; split >= 0; split--) { | ||
if (tokens[split][0] != "space") { | ||
if (tokens[split][0] !== "space") { | ||
split += 1; | ||
@@ -426,8 +443,8 @@ break; | ||
token = tokens[j]; | ||
if (token[0] != "space") { | ||
if (token[0] !== "space") { | ||
founded += 1; | ||
if (founded == 2) break; | ||
if (founded === 2) break; | ||
} | ||
} | ||
throw this.input.error("Missed semicolon", token[4], token[5]); | ||
throw this.input.error("Missed semicolon", token[2], token[3]); | ||
} | ||
@@ -444,7 +461,7 @@ }; | ||
this.spaces = ""; | ||
if (node.type != "comment") this.semicolon = false; | ||
if (node.type !== "comment") this.semicolon = false; | ||
}; | ||
Parser.prototype.raw = function raw(node, prop, tokens) { | ||
var token; | ||
var token = undefined; | ||
var value = ""; | ||
@@ -462,3 +479,3 @@ var clean = true; | ||
if (token[0] == "comment") { | ||
if (token[0] === "comment") { | ||
clean = false; | ||
@@ -488,7 +505,7 @@ } else { | ||
Parser.prototype.spacesFromEnd = function spacesFromEnd(tokens) { | ||
var next; | ||
var next = undefined; | ||
var spaces = ""; | ||
while (tokens.length) { | ||
next = tokens[tokens.length - 1][0]; | ||
if (next != "space" && next != "comment") break; | ||
if (next !== "space" && next !== "comment") break; | ||
spaces += tokens.pop()[1]; | ||
@@ -500,7 +517,7 @@ } | ||
Parser.prototype.spacesFromStart = function spacesFromStart(tokens) { | ||
var next; | ||
var next = undefined; | ||
var spaces = ""; | ||
while (tokens.length) { | ||
next = tokens[0][0]; | ||
if (next != "space" && next != "comment") break; | ||
if (next !== "space" && next !== "comment") break; | ||
spaces += tokens.shift()[1]; | ||
@@ -507,0 +524,0 @@ } |
@@ -5,6 +5,6 @@ "use strict"; | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
var Declaration = _interopRequire(require("./declaration")); | ||
var Processor = _interopRequire(require("./processor")); | ||
var Comment = _interopRequire(require("./comment")); | ||
@@ -14,6 +14,8 @@ | ||
var Result = _interopRequire(require("./result")); | ||
var vendor = _interopRequire(require("./vendor")); | ||
var parse = _interopRequire(require("./parse")); | ||
var list = _interopRequire(require("./list")); | ||
var Rule = _interopRequire(require("./rule")); | ||
@@ -23,87 +25,2 @@ | ||
// List of functions to process CSS | ||
var PostCSS = (function () { | ||
function PostCSS() { | ||
var _this = this; | ||
var plugins = arguments[0] === undefined ? [] : arguments[0]; | ||
_classCallCheck(this, PostCSS); | ||
this.plugins = plugins.map(function (i) { | ||
return _this.normalize(i); | ||
}); | ||
} | ||
// Add function as PostCSS plugins | ||
PostCSS.prototype.use = function use(plugin) { | ||
plugin = this.normalize(plugin); | ||
if (typeof plugin == "object" && Array.isArray(plugin.plugins)) { | ||
this.plugins = this.plugins.concat(plugin.plugins); | ||
} else { | ||
this.plugins.push(plugin); | ||
} | ||
return this; | ||
}; | ||
// Process CSS throw installed plugins | ||
PostCSS.prototype.process = function process(css) { | ||
var opts = arguments[1] === undefined ? {} : arguments[1]; | ||
var parsed; | ||
if (css instanceof Root) { | ||
parsed = css; | ||
} else if (css instanceof Result) { | ||
parsed = css.root; | ||
if (css.map && typeof opts.map == "undefined") { | ||
opts.map = { prev: css.map }; | ||
} | ||
} else { | ||
parsed = postcss.parse(css, opts); | ||
} | ||
for (var _iterator = this.plugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var plugin = _ref; | ||
var returned = plugin(parsed, opts); | ||
if (returned instanceof Root) parsed = returned; | ||
} | ||
return parsed.toResult(opts); | ||
}; | ||
// Return plugin function | ||
PostCSS.prototype.normalize = function normalize(plugin) { | ||
var type = typeof plugin; | ||
if ((type == "object" || type == "function") && plugin.postcss) { | ||
return plugin.postcss; | ||
} else { | ||
return plugin; | ||
} | ||
}; | ||
return PostCSS; | ||
})(); | ||
// Framework for CSS postprocessors | ||
// | ||
// var processor = postcss(function (css) { | ||
// // Change nodes in css | ||
// }); | ||
// processor.process(css) | ||
var postcss = function postcss() { | ||
@@ -114,12 +31,26 @@ for (var _len = arguments.length, plugins = Array(_len), _key = 0; _key < _len; _key++) { | ||
if (plugins.length == 1 && Array.isArray(plugins[0])) { | ||
if (plugins.length === 1 && Array.isArray(plugins[0])) { | ||
plugins = plugins[0]; | ||
} | ||
return new PostCSS(plugins); | ||
return new Processor(plugins); | ||
}; | ||
// Compile CSS to nodes | ||
postcss.plugin = function (name, initializer) { | ||
var creator = function creator() { | ||
var transformer = initializer.apply(this, arguments); | ||
transformer.postcssPlugin = name; | ||
transformer.postcssVersion = Processor.prototype.version; | ||
return transformer; | ||
}; | ||
creator.postcss = creator(); | ||
return creator; | ||
}; | ||
postcss.vendor = vendor; | ||
postcss.parse = parse; | ||
// Nodes shortcuts | ||
postcss.list = list; | ||
postcss.comment = function (defaults) { | ||
@@ -126,0 +57,0 @@ return new Comment(defaults); |
@@ -15,4 +15,2 @@ "use strict"; | ||
// Detect previous map | ||
var PreviousMap = (function () { | ||
@@ -30,4 +28,2 @@ function PreviousMap(css, opts) { | ||
// Return SourceMapConsumer object to read map | ||
PreviousMap.prototype.consumer = function consumer() { | ||
@@ -40,4 +36,2 @@ if (!this.consumerCache) { | ||
// Is map has sources content | ||
PreviousMap.prototype.withContent = function withContent() { | ||
@@ -47,12 +41,8 @@ return !!(this.consumer().sourcesContent && this.consumer().sourcesContent.length > 0); | ||
// Is `string` is starting with `start` | ||
PreviousMap.prototype.startWith = function startWith(string, start) { | ||
if (!string) { | ||
return false; | ||
}return string.substr(0, start.length) == start; | ||
}return string.substr(0, start.length) === start; | ||
}; | ||
// Load for annotation comment from previous compilation step | ||
PreviousMap.prototype.loadAnnotation = function loadAnnotation(css) { | ||
@@ -63,4 +53,2 @@ var match = css.match(/\/\*\s*# sourceMappingURL=(.*)\s*\*\//); | ||
// Encode different type of inline | ||
PreviousMap.prototype.decodeInline = function decodeInline(text) { | ||
@@ -80,9 +68,7 @@ var uri = "data:application/json,"; | ||
// Load previous map | ||
PreviousMap.prototype.loadMap = function loadMap(file, prev) { | ||
if (prev === false) { | ||
return; | ||
return false; | ||
}if (prev) { | ||
if (typeof prev == "string") { | ||
if (typeof prev === "string") { | ||
return prev; | ||
@@ -93,3 +79,3 @@ } else if (prev instanceof mozilla.SourceMapConsumer) { | ||
return prev.toString(); | ||
} else if (typeof prev == "object" && prev.mappings) { | ||
} else if (typeof prev === "object" && prev.mappings) { | ||
return JSON.stringify(prev); | ||
@@ -108,2 +94,4 @@ } else { | ||
return fs.readFileSync(map, "utf-8").toString().trim(); | ||
} else { | ||
return false; | ||
} | ||
@@ -110,0 +98,0 @@ } |
@@ -5,22 +5,22 @@ "use strict"; | ||
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
var MapGenerator = _interopRequire(require("./map-generator")); | ||
var Warning = _interopRequire(require("./warning")); | ||
// Object with processed CSS | ||
var warn = _interopRequire(require("./warn")); | ||
var Result = (function () { | ||
function Result(root) { | ||
var opts = arguments[1] === undefined ? {} : arguments[1]; | ||
function Result(processor, root, opts) { | ||
_classCallCheck(this, Result); | ||
this.processor = processor; | ||
this.messages = []; | ||
this.root = root; | ||
this.opts = opts; | ||
this.css = undefined; | ||
this.map = undefined; | ||
} | ||
// Return CSS string on any try to print | ||
Result.prototype.toString = function toString() { | ||
@@ -30,31 +30,32 @@ return this.css; | ||
// Generate CSS and map | ||
Result.prototype.warn = function warn(text) { | ||
var opts = arguments[1] === undefined ? {} : arguments[1]; | ||
Result.prototype.stringify = function stringify() { | ||
var map = new MapGenerator(this.root, this.opts); | ||
var generated = map.generate(); | ||
this.cssCached = generated[0]; | ||
this.mapCached = generated[1]; | ||
if (!opts.plugin) { | ||
if (this.lastPlugin && this.lastPlugin.postcssPlugin) { | ||
opts.plugin = this.lastPlugin.postcssPlugin; | ||
} | ||
} | ||
this.messages.push(new Warning(text, opts)); | ||
}; | ||
_prototypeProperties(Result, null, { | ||
map: { | ||
Result.prototype.warnings = function warnings() { | ||
return this.messages.filter(function (i) { | ||
return i.type === "warning"; | ||
}); | ||
}; | ||
// Lazy method to return source map | ||
_createClass(Result, { | ||
from: { | ||
get: function () { | ||
if (!this.cssCached) this.stringify(); | ||
return this.mapCached; | ||
}, | ||
configurable: true | ||
warn("result.from is deprecated and will be removed in 5.0. " + "Use result.opts.from instead."); | ||
return this.opts.from; | ||
} | ||
}, | ||
css: { | ||
// Lazy method to return CSS string | ||
to: { | ||
get: function () { | ||
if (!this.cssCached) this.stringify(); | ||
return this.cssCached; | ||
}, | ||
configurable: true | ||
warn("result.to is deprecated and will be removed in 5.0. " + "Use result.opts.to instead."); | ||
return this.opts.to; | ||
} | ||
} | ||
@@ -61,0 +62,0 @@ }); |
@@ -9,17 +9,5 @@ "use strict"; | ||
var Declaration = _interopRequire(require("./declaration")); | ||
var Container = _interopRequire(require("./container")); | ||
var Comment = _interopRequire(require("./comment")); | ||
var AtRule = _interopRequire(require("./at-rule")); | ||
var Result = _interopRequire(require("./result")); | ||
var Rule = _interopRequire(require("./rule")); | ||
// Root of CSS | ||
var Root = (function (Container) { | ||
var Root = (function (_Container) { | ||
function Root(defaults) { | ||
@@ -30,9 +18,7 @@ _classCallCheck(this, Root); | ||
this.nodes = []; | ||
Container.call(this, defaults); | ||
_Container.call(this, defaults); | ||
} | ||
_inherits(Root, Container); | ||
_inherits(Root, _Container); | ||
// Fix space when we remove first child | ||
Root.prototype.remove = function remove(child) { | ||
@@ -45,12 +31,10 @@ child = this.index(child); | ||
return Container.prototype.remove.call(this, child); | ||
return _Container.prototype.remove.call(this, child); | ||
}; | ||
// Fix spaces on insert before first rule | ||
Root.prototype.normalize = function normalize(child, sample, type) { | ||
var nodes = Container.prototype.normalize.call(this, child); | ||
var nodes = _Container.prototype.normalize.call(this, child); | ||
if (sample) { | ||
if (type == "prepend") { | ||
if (type === "prepend") { | ||
if (this.nodes.length > 1) { | ||
@@ -76,3 +60,3 @@ sample.before = this.nodes[1].before; | ||
if (this.first != sample) node.before = sample.before; | ||
if (this.first !== sample) node.before = sample.before; | ||
} | ||
@@ -85,4 +69,2 @@ } | ||
// Stringify styles | ||
Root.prototype.stringify = function stringify(builder) { | ||
@@ -93,8 +75,10 @@ this.stringifyContent(builder); | ||
// Generate processing result with optional source map | ||
Root.prototype.toResult = function toResult() { | ||
var opts = arguments[0] === undefined ? {} : arguments[0]; | ||
return new Result(this, opts); | ||
var LazyResult = require("./lazy-result"); | ||
var Processor = require("./processor"); | ||
var lazy = new LazyResult(new Processor(), this, opts); | ||
return lazy.stringify(); | ||
}; | ||
@@ -101,0 +85,0 @@ |
@@ -5,3 +5,3 @@ "use strict"; | ||
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
@@ -12,4 +12,2 @@ var _inherits = function (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) subClass.__proto__ = superClass; }; | ||
var Declaration = _interopRequire(require("./declaration")); | ||
var Container = _interopRequire(require("./container")); | ||
@@ -19,5 +17,3 @@ | ||
// CSS rule like “a { }” | ||
var Rule = (function (Container) { | ||
var Rule = (function (_Container) { | ||
function Rule(defaults) { | ||
@@ -28,9 +24,7 @@ _classCallCheck(this, Rule); | ||
this.nodes = []; | ||
Container.call(this, defaults); | ||
_Container.call(this, defaults); | ||
} | ||
_inherits(Rule, Container); | ||
_inherits(Rule, _Container); | ||
// Stringify rule | ||
Rule.prototype.stringify = function stringify(builder) { | ||
@@ -40,7 +34,4 @@ this.stringifyBlock(builder, this.stringifyRaw("selector")); | ||
_prototypeProperties(Rule, null, { | ||
_createClass(Rule, { | ||
selectors: { | ||
// Shortcut to get selectors as array | ||
get: function () { | ||
@@ -51,4 +42,3 @@ return list.comma(this.selector); | ||
this.selector = values.join(", "); | ||
}, | ||
configurable: true | ||
} | ||
} | ||
@@ -55,0 +45,0 @@ }); |
"use strict"; | ||
module.exports = tokenize; | ||
var singleQuote = "'".charCodeAt(0), | ||
@@ -24,7 +25,17 @@ doubleQuote = "\"".charCodeAt(0), | ||
module.exports = function (input) { | ||
function tokenize(input) { | ||
var tokens = []; | ||
var css = input.css.valueOf(); | ||
var code, next, quote, lines, last, content, escape, nextLine, nextOffset, escaped, escapePos, bad; | ||
var code = undefined, | ||
next = undefined, | ||
quote = undefined, | ||
lines = undefined, | ||
last = undefined, | ||
content = undefined, | ||
escape = undefined, | ||
nextLine = undefined, | ||
nextOffset = undefined, | ||
escaped = undefined, | ||
escapePos = undefined; | ||
@@ -48,3 +59,3 @@ var length = css.length; | ||
if (code == newline) { | ||
if (code === newline) { | ||
offset = pos; | ||
@@ -64,7 +75,7 @@ line += 1; | ||
code = css.charCodeAt(next); | ||
if (code == newline) { | ||
if (code === newline) { | ||
offset = next; | ||
line += 1; | ||
} | ||
} while (code == space || code == newline || code == tab || code == cr || code == feed); | ||
} while (code === space || code === newline || code === tab || code === cr || code === feed); | ||
@@ -95,3 +106,3 @@ tokens.push(["space", css.slice(pos, next)]); | ||
if (next == -1 || badBracket.test(content)) { | ||
if (next === -1 || badBracket.test(content)) { | ||
tokens.push(["(", "(", line, pos - offset]); | ||
@@ -111,3 +122,3 @@ } else { | ||
case doubleQuote: | ||
quote = code == singleQuote ? "'" : "\""; | ||
quote = code === singleQuote ? "'" : "\""; | ||
next = pos; | ||
@@ -117,5 +128,5 @@ do { | ||
next = css.indexOf(quote, next + 1); | ||
if (next == -1) unclosed("quote", quote); | ||
if (next === -1) unclosed("quote", quote); | ||
escapePos = next; | ||
while (css.charCodeAt(escapePos - 1) == backslash) { | ||
while (css.charCodeAt(escapePos - 1) === backslash) { | ||
escapePos -= 1; | ||
@@ -145,3 +156,3 @@ escaped = !escaped; | ||
escape = true; | ||
while (css.charCodeAt(next + 1) == backslash) { | ||
while (css.charCodeAt(next + 1) === backslash) { | ||
next += 1; | ||
@@ -151,3 +162,3 @@ escape = !escape; | ||
code = css.charCodeAt(next + 1); | ||
if (escape && (code != slash && code != space && code != newline && code != tab && code != cr && code != feed)) { | ||
if (escape && (code !== slash && code !== space && code !== newline && code !== tab && code !== cr && code !== feed)) { | ||
next += 1; | ||
@@ -160,3 +171,3 @@ } | ||
default: | ||
if (code == slash && css.charCodeAt(pos + 1) == asterisk) { | ||
if (code === slash && css.charCodeAt(pos + 1) === asterisk) { | ||
next = css.indexOf("*/", pos + 2) + 1; | ||
@@ -202,2 +213,2 @@ if (next === 0) unclosed("comment", "*/"); | ||
return tokens; | ||
}; | ||
} |
"use strict"; | ||
// Methods to work with vendor prefixes | ||
module.exports = { | ||
// Return vendor prefix from property name, if it exists | ||
// | ||
// vendor.prefix('-moz-box-sizing') #=> '-moz-' | ||
// vendor.prefix('box-sizing') #=> '' | ||
prefix: function prefix(prop) { | ||
if (prop[0] == "-") { | ||
if (prop[0] === "-") { | ||
var sep = prop.indexOf("-", 1); | ||
@@ -19,8 +14,4 @@ return prop.substr(0, sep + 1); | ||
// Remove prefix from property name | ||
// | ||
// vendor.prefix('-moz-box-sizing') #=> 'box-sizing' | ||
// vendor.prefix('box-sizing') #=> 'box-sizing' | ||
unprefixed: function unprefixed(prop) { | ||
if (prop[0] == "-") { | ||
if (prop[0] === "-") { | ||
var sep = prop.indexOf("-", 1); | ||
@@ -27,0 +18,0 @@ return prop.substr(sep + 1); |
{ | ||
"name": "postcss", | ||
"version": "4.0.6", | ||
"version": "4.1.0", | ||
"description": "Tool for transforming CSS with JS plugins", | ||
@@ -22,39 +22,40 @@ "keywords": [ | ||
"dependencies": { | ||
"source-map": "~0.2.0", | ||
"source-map": "~0.4.2", | ||
"js-base64": "~2.1.7" | ||
}, | ||
"devDependencies": { | ||
"concat-with-sourcemaps": "1.0.0", | ||
"concat-with-sourcemaps": "1.0.2", | ||
"gulp-bench-summary": "0.1.0", | ||
"gulp-json-editor": "2.2.1", | ||
"jshint-stylish": "1.0.0", | ||
"gulp-jshint": "1.9.2", | ||
"gonzales-pe": "3.0.0-26", | ||
"browserify": "9.0.3", | ||
"gulp-babel": "4.0.0", | ||
"gulp-eslint": "0.6.0", | ||
"browserify": "9.0.4", | ||
"gulp-babel": "4.0.1", | ||
"gulp-bench": "1.1.0", | ||
"gulp-mocha": "2.0.0", | ||
"node-sass": "2.0.1", | ||
"gulp-util": "3.0.3", | ||
"execSync": "1.0.2", | ||
"fs-extra": "0.16.3", | ||
"gulp-mocha": "2.0.1", | ||
"node-sass": "2.1.1", | ||
"yaspeller": "1.1.0", | ||
"gulp-util": "3.0.4", | ||
"fs-extra": "0.18.0", | ||
"gonzales": "1.0.7", | ||
"through2": "0.6.3", | ||
"stylecow": "4.2.4", | ||
"request": "2.53.0", | ||
"cssnext": "1.0.1", | ||
"stylecow": "5.0.0", | ||
"request": "2.54.0", | ||
"cssnext": "1.1.0", | ||
"rework": "1.0.1", | ||
"mensch": "0.3.1", | ||
"stylus": "0.50.0", | ||
"mocha": "2.1.0", | ||
"eslint": "0.16.1", | ||
"sinon": "1.14.1", | ||
"mocha": "2.2.1", | ||
"cssom": "0.3.0", | ||
"gulp": "3.8.11", | ||
"less": "2.4.0", | ||
"chai": "2.1.0", | ||
"babel": "4.4.6" | ||
"chai": "2.2.0", | ||
"babel": "4.7.16" | ||
}, | ||
"scripts": { | ||
"test": "gulp" | ||
"test": "gulp && yaspeller ." | ||
}, | ||
"main": "lib/postcss" | ||
} |
295
README.md
@@ -14,3 +14,3 @@ # PostCSS [![Build Status](https://travis-ci.org/postcss/postcss.svg)](https://travis-ci.org/postcss/postcss) [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/postcss/postcss?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
PostCSS can do the same work as preprocessors like Sass, Less, and Stylus. | ||
But PostCSS is modular, 4-40x faster, and much more powerful. | ||
But PostCSS is modular, 4-40 times faster, and much more powerful. | ||
@@ -48,4 +48,4 @@ PostCSS itself is very small. It includes only a CSS parser, | ||
Or if you like the power provided by preprocessors like Sass, | ||
you could combine [postcss-nested], [postcss-mixins], [postcss-easings] | ||
and [postcss-media-minmax]: | ||
you could combine [`postcss-nested`], [`postcss-mixins`], [`postcss-easings`] | ||
and [`postcss-media-minmax`]: | ||
@@ -87,4 +87,6 @@ ```css | ||
[Autoprefixer]: https://github.com/postcss/autoprefixer | ||
[@postcss]: https://twitter.com/postcss | ||
[postcss]: http://weibo.com/postcss | ||
[cssnext]: https://github.com/cssnext/cssnext | ||
@@ -109,6 +111,6 @@ ## How PostCSS differs from Preprocessors | ||
Without any plugins, PostCSS will parse your CSS and stringify it back | ||
to you without changing a single byte. All of the processing that enables | ||
special features and syntax in your stylesheets is made possible | ||
by PostCSS plugins, which are nothing more than JS functions. | ||
Without any plugins, PostCSS will parse your CSS and convert it back | ||
to the string without changing a single byte. All of the processing that enables | ||
special features and syntax in your stylesheets is made possible by PostCSS | ||
plugins, which are nothing more than JS functions. | ||
@@ -120,6 +122,6 @@ Because each PostCSS plugin is an independent module, different plugins can take | ||
Some plugins, like [postcss-custom-properties], [postcss-media-minmax], | ||
and [postcss-calc], implement syntax from present and future W3C specs, | ||
Some plugins, like [`postcss-custom-properties`], [`postcss-media-minmax`], | ||
and [`postcss-calc`], implement syntax from present and future W3C specs, | ||
transpiling it to cross-browser-compatible output. Other plugins, | ||
like [postcss-mixins] and [postcss-simple-extend], add new powers | ||
like [`postcss-mixins`] and [`postcss-simple-extend`], add new powers | ||
to your stylesheets that are not yet part of any spec. With PostCSS, | ||
@@ -133,3 +135,3 @@ you can decide for yourself which plugins match your own needs and preferences. | ||
### Perfomance | ||
### Performance | ||
@@ -156,13 +158,13 @@ PostCSS is one of the fastest CSS parsers written in JS. (Only [CSSOM] is | ||
browser-friendly CSS. PostCSS plugin authors have built linters | ||
(like [doiuse] and [postcss-bem-linter]), code review tools | ||
(like [list-selectors]), and minifiers (like [csswring]). | ||
With [postcss-data-packer], you can create a cacheable “sprite” | ||
by moving all `data:uri` values to separate file. | ||
(like [`doiuse`] and [`postcss-bem-linter`]), code review tools | ||
(like [`list-selectors`]), and minifiers (like [`csswring`]). | ||
With [`postcss-data-packer`], you can create a CSS-sprite by moving all | ||
`data:uri` values to separate file. | ||
One unique example of PostCSS’s power is [RTLCSS]. As you know, | ||
in Arabic and Hebrew, writing moves from right-to-left (RTL), instead | ||
of the more widespread left-to-right convention. Because a language’s | ||
directionality affects its readers’ perspective, an international site’s layout | ||
needs to change for RTL users, not just its text. (Check out [Arabic Wikipedia] | ||
as an example.) The [RTLCSS] plugin effectively “mirrors” your stylesheet | ||
One unique example of PostCSS’s power is [`rtlcss`]. As you know, | ||
in Arabic and Hebrew, writing moves from right-to-left, instead of the more | ||
widespread left-to-right convention. Because a language’s directionality affects | ||
its readers’ perspective, an international site’s layout needs to change | ||
for Jews and Arabs, not just its text. (Check out [Arabic Wikipedia] | ||
as an example.) The [`rtlcss`] plugin effectively “mirrors” your stylesheet | ||
by swapping `left` and `right`, changing the value order in `margin` shorthands, | ||
@@ -175,3 +177,3 @@ and more. | ||
CSS3 added valuable features, but some of them are not yet available in all | ||
CSS 3 added valuable features, but some of them are not yet available in all | ||
of the browsers that developers need to support. And exciting future CSS modules | ||
@@ -196,9 +198,10 @@ are being drafted now — some even implemented in cutting-edge browsers — | ||
1. Implement PostCSS with your build tool of choice. See the PostCSS [Grunt], | ||
[Gulp], and [webpack] plugins more detailed instructions. | ||
[Gulp], and [webpack] plugins or [CLI tool] more detailed instructions. | ||
2. Select plugins from the list below and add them to your PostCSS process. | ||
3. Make awesome products. | ||
[webpack]: https://github.com/postcss/postcss-loader | ||
[Grunt]: https://github.com/nDmitry/grunt-postcss | ||
[Gulp]: https://github.com/w0rm/gulp-postcss | ||
[CLI tool]: https://github.com/code42day/postcss-cli | ||
[webpack]: https://github.com/postcss/postcss-loader | ||
[Grunt]: https://github.com/nDmitry/grunt-postcss | ||
[Gulp]: https://github.com/w0rm/gulp-postcss | ||
@@ -208,7 +211,7 @@ ## Plugins Packs | ||
* [cssnext] contains plugins that allow you to use future CSS features today. | ||
* [ACSS] contains plugins that transform your CSS according | ||
* [AtCSS] contains plugins that transform your CSS according | ||
to special annotation comments. | ||
[cssnext]: https://github.com/putaindecode/cssnext | ||
[ACSS]: https://github.com/morishitter/acss | ||
[AtCSS]: https://github.com/morishitter/atcss | ||
@@ -219,56 +222,70 @@ ## Plugins | ||
* [postcss-color-function] supports functions to transform colors. | ||
* [postcss-color-gray] supports the `gray()` function. | ||
* [postcss-color-hex] transforms `rgb()` and `rgba()` to hex. | ||
* [postcss-color-hex-alpha] supports `#rrggbbaa` and `#rgba` notation. | ||
* [postcss-color-hwb] transforms `hwb()` to widely compatible `rgb()`. | ||
* [postcss-color-rebeccapurple] supports the `rebeccapurple` color. | ||
* [postcss-custom-media] supports custom aliases for media queries. | ||
* [postcss-custom-properties] supports variables, using syntax from | ||
* [`postcss-color-function`] supports functions to transform colors. | ||
* [`postcss-color-gray`] supports the `gray()` function. | ||
* [`postcss-color-hex-alpha`] supports `#rrggbbaa` and `#rgba` notation. | ||
* [`postcss-color-hwb`] transforms `hwb()` to widely compatible `rgb()`. | ||
* [`postcss-color-rebeccapurple`] supports the `rebeccapurple` color. | ||
* [`postcss-custom-media`] supports custom aliases for media queries. | ||
* [`postcss-custom-properties`] supports variables, using syntax from | ||
the W3C Custom Properties. | ||
* [postcss-custom-selectors] adds custom aliases for selectors. | ||
* [postcss-font-variant] transpiles human-readable `font-variant` to more widely | ||
supported CSS. | ||
* [postcss-host] makes the Shadow DOM’s `:host` selector work properly | ||
* [`postcss-custom-selectors`] adds custom aliases for selectors. | ||
* [`postcss-font-variant`] transpiles human-readable `font-variant` to more | ||
widely supported CSS. | ||
* [`postcss-host`] makes the Shadow DOM’s `:host` selector work properly | ||
with pseudo-classes. | ||
* [postcss-media-minmax] adds `<=` and `=>` statements to media queries. | ||
* [mq4-hover-shim] supports the `@media (hover)` feature. | ||
* [`postcss-media-minmax`] adds `<=` and `=>` statements to media queries. | ||
* [`mq4-hover-shim`] supports the `@media (hover)` feature. | ||
### Fallbacks | ||
* [postcss-epub] adds the `-epub-` prefix to relevant properties. | ||
* [postcss-opacity] adds opacity filter for IE8. | ||
* [postcss-vmin] generates `vm` fallback for `vmin` unit in IE9. | ||
* [postcss-will-change] inserts 3D hack before `will-change` property. | ||
* [Autoprefixer] adds vendor prefixes for you, using data from Can I Use. | ||
* [cssgrace] provides various helpers and transpiles CSS3 for IE | ||
* [`postcss-color-hex`] transforms `rgb()` and `rgba()` to hex. | ||
* [`postcss-epub`] adds the `-epub-` prefix to relevant properties. | ||
* [`postcss-opacity`] adds opacity filter for IE8. | ||
* [`postcss-pseudoelements`] Convert `::` selectors into `:` selectors | ||
for IE 8 compatibility. | ||
* [`postcss-vmin`] generates `vm` fallback for `vmin` unit in IE9. | ||
* [`postcss-will-change`] inserts 3D hack before `will-change` property. | ||
* [`autoprefixer`] adds vendor prefixes for you, using data from Can I Use. | ||
* [`cssgrace`] provides various helpers and transpiles CSS 3 for IE | ||
and other old browsers. | ||
* [pixrem] generates pixel fallbacks for `rem` units. | ||
* [pleeease-filters] converts WebKit filters to SVG filters, | ||
for cross-browser compatibility. | ||
* [`pixrem`] generates pixel fallbacks for `rem` units. | ||
### Language Extensions | ||
* [postcss-mixins] enables mixins more powerful than Sass’s, | ||
* [`postcss-color-alpha`] transforms `#hex.a`, `black(alpha)` and `white(alpha)` | ||
to `rgba()`. | ||
* [`postcss-mixins`] enables mixins more powerful than Sass’s, | ||
defined within stylesheets or in JS. | ||
* [postcss-nested] unwraps nested rules, as Sass does. | ||
* [postcss-simple-extend] supports extending of silent classes, | ||
* [`postcss-map`] enables configuration maps. | ||
* [`postcss-nested`] unwraps nested rules. | ||
* [`postcss-quantity-queries`] enables quantity queries. | ||
* [`postcss-simple-extend`] supports extending of silent classes, | ||
like Sass’s `@extend`. | ||
* [postcss-simple-vars] supports for Sass-style variables. | ||
* [csstyle] adds components workflow to your styles. | ||
* [`postcss-simple-vars`] supports for Sass-style variables. | ||
* [`csstyle`] adds components workflow to your styles. | ||
### Optimizations | ||
* [postcss-assets] allows you to simplify URLs, insert image dimensions, | ||
* [`postcss-assets`] allows you to simplify URLs, insert image dimensions, | ||
and inline files. | ||
* [postcss-calc] reduces `calc()` to values | ||
* [`postcss-at2x`] handles retina background images via use of `at-2x` keyword. | ||
* [`postcss-calc`] reduces `calc()` to values | ||
(when expressions involve the same units). | ||
* [postcss-data-packer] moves embedded Base64 data out of the stylesheet | ||
* [`postcss-data-packer`] moves embedded Base64 data out of the stylesheet | ||
and into a separate file. | ||
* [postcss-import] inlines the stylesheets referred to by `@import` rules. | ||
* [postcss-url] rebases or inlines `url()`s. | ||
* [csswring] is a CSS minifier. | ||
* [css-byebye] removes the CSS rules that you don’t want. | ||
* [css-mqpacker] joins matching CSS media queries into a single statement. | ||
* [webpcss] adds URLs for WebP images, so they can be used by browsers | ||
* [`postcss-discard-duplicates`] removes duplicate declarations and rules. | ||
* [`postcss-discard-empty`] removes empty rules and declarations. | ||
* [`postcss-font-family`] optimises `font` and `font-family` declarations. | ||
* [`postcss-import`] inlines the stylesheets referred to by `@import` rules. | ||
* [`postcss-merge-rules`] merges adjacent rules when | ||
selectors/properties overlap. | ||
* [`postcss-minify-selectors`] normalizes selectors for better compression. | ||
* [`postcss-normalize-url`] normalizes `url()`s and trims quotes | ||
where they are unnecessary. | ||
* [`postcss-url`] rebases or inlines `url()`s. | ||
* [`postcss-zindex`] rebases positive `z-index` values. | ||
* [`csswring`] is a CSS minifier. | ||
* [`css-byebye`] removes the CSS rules that you don’t want. | ||
* [`css-mqpacker`] joins matching CSS media queries into a single statement. | ||
* [`webpcss`] adds URLs for WebP images, so they can be used by browsers | ||
that support WebP. | ||
@@ -278,5 +295,5 @@ | ||
* [postcss-easings] replaces easing names from easings.net | ||
* [`postcss-easings`] replaces easing names from easings.net | ||
with `cubic-bezier()` functions. | ||
* [postcss-size] adds a `size` shortcut that sets width and height | ||
* [`postcss-size`] adds a `size` shortcut that sets width and height | ||
with one declaration. | ||
@@ -286,64 +303,77 @@ | ||
* [postcss-brand-colors] inserts company brand colors | ||
* [`postcss-brand-colors`] inserts company brand colors | ||
in the `brand-colors` module. | ||
* [postcss-color-palette] transforms CSS2 color keywords to a custom palette. | ||
* [postcss-single-charset] ensures that there is one | ||
* [`postcss-color-palette`] transforms CSS 2 color keywords to a custom palette. | ||
* [`postcss-discard-comments`] removes comments based on rules you specify. | ||
* [`postcss-single-charset`] ensures that there is one | ||
and only one `@charset` rule at the top of file. | ||
* [rtlcss] mirrors styles for right-to-left locales. | ||
* [`rtlcss`] mirrors styles for right-to-left locales. | ||
### Analysis | ||
* [postcss-bem-linter] lints CSS for conformance to SUIT CSS methodology. | ||
* [css2modernizr] creates a Modernizr config file | ||
* [`postcss-bem-linter`] lints CSS for conformance to SUIT CSS methodology. | ||
* [`css2modernizr`] creates a Modernizr config file | ||
that requires only the tests that your CSS uses. | ||
* [doiuse] lints CSS for browser support, using data from Can I Use. | ||
* [list-selectors] lists and categorizes the selectors used in your CSS, | ||
* [`doiuse`] lints CSS for browser support, using data from Can I Use. | ||
* [`list-selectors`] lists and categorizes the selectors used in your CSS, | ||
for code review and analysis. | ||
[postcss-color-rebeccapurple]: https://github.com/postcss/postcss-color-rebeccapurple | ||
[postcss-custom-properties]: https://github.com/postcss/postcss-custom-properties | ||
[postcss-custom-selectors]: https://github.com/postcss/postcss-custom-selectors | ||
[postcss-color-hex-alpha]: https://github.com/postcss/postcss-color-hex-alpha | ||
[postcss-color-function]: https://github.com/postcss/postcss-color-function | ||
[postcss-single-charset]: https://github.com/hail2u/postcss-single-charset | ||
[postcss-color-palette]: https://github.com/zaim/postcss-color-palette | ||
[postcss-simple-extend]: https://github.com/davidtheclark/postcss-simple-extend | ||
[postcss-media-minmax]: https://github.com/postcss/postcss-media-minmax | ||
[postcss-custom-media]: https://github.com/postcss/postcss-custom-media | ||
[postcss-brand-colors]: https://github.com/postcss/postcss-brand-colors | ||
[postcss-font-variant]: https://github.com/postcss/postcss-font-variant | ||
[postcss-will-change]: https://github.com/postcss/postcss-will-change | ||
[postcss-simple-vars]: https://github.com/postcss/postcss-simple-vars | ||
[postcss-data-packer]: https://github.com/Ser-Gen/postcss-data-packer | ||
[postcss-bem-linter]: https://github.com/necolas/postcss-bem-linter | ||
[postcss-color-gray]: https://github.com/postcss/postcss-color-gray | ||
[postcss-color-hex]: https://github.com/TrySound/postcss-color-hex | ||
[postcss-color-hwb]: https://github.com/postcss/postcss-color-hwb | ||
[pleeease-filters]: https://github.com/iamvdo/pleeease-filters | ||
[postcss-easings]: https://github.com/postcss/postcss-easings | ||
[postcss-opacity]: https://github.com/iamvdo/postcss-opacity | ||
[postcss-assets]: https://github.com/borodean/postcss-assets | ||
[postcss-import]: https://github.com/postcss/postcss-import | ||
[postcss-nested]: https://github.com/postcss/postcss-nested | ||
[postcss-mixins]: https://github.com/postcss/postcss-mixins | ||
[mq4-hover-shim]: https://github.com/twbs/mq4-hover-shim | ||
[list-selectors]: https://github.com/davidtheclark/list-selectors | ||
[css2modernizr]: https://github.com/vovanbo/css2modernizr | ||
[Autoprefixer]: https://github.com/postcss/autoprefixer | ||
[css-mqpacker]: https://github.com/hail2u/node-css-mqpacker | ||
[postcss-epub]: https://github.com/Rycochet/postcss-epub | ||
[postcss-calc]: https://github.com/postcss/postcss-calc | ||
[postcss-size]: https://github.com/postcss/postcss-size | ||
[postcss-host]: https://github.com/vitkarpov/postcss-host | ||
[postcss-vmin]: https://github.com/iamvdo/postcss-vmin | ||
[postcss-url]: https://github.com/postcss/postcss-url | ||
[css-byebye]: https://github.com/AoDev/css-byebye | ||
[cssgrace]: https://github.com/cssdream/cssgrace | ||
[csswring]: https://github.com/hail2u/node-csswring | ||
[csstyle]: https://github.com/geddski/csstyle | ||
[webpcss]: https://github.com/lexich/webpcss | ||
[rtlcss]: https://github.com/MohammadYounes/rtlcss | ||
[RTLCSS]: https://github.com/MohammadYounes/rtlcss | ||
[pixrem]: https://github.com/robwierzbowski/node-pixrem | ||
[doiuse]: https://github.com/anandthakker/doiuse | ||
[`postcss-color-rebeccapurple`]: https://github.com/postcss/postcss-color-rebeccapurple | ||
[`postcss-discard-duplicates`]: https://github.com/ben-eb/postcss-discard-duplicates | ||
[`postcss-custom-properties`]: https://github.com/postcss/postcss-custom-properties | ||
[`postcss-custom-selectors`]: https://github.com/postcss/postcss-custom-selectors | ||
[`postcss-discard-comments`]: https://github.com/ben-eb/postcss-discard-comments | ||
[`postcss-minify-selectors`]: https://github.com/ben-eb/postcss-minify-selectors | ||
[`postcss-quantity-queries`]: https://github.com/pascalduez/postcss-quantity-queries | ||
[`postcss-color-hex-alpha`]: https://github.com/postcss/postcss-color-hex-alpha | ||
[`postcss-color-function`]: https://github.com/postcss/postcss-color-function | ||
[`postcss-pseudoelements`]: https://github.com/axa-ch/postcss-pseudoelements | ||
[`postcss-single-charset`]: https://github.com/hail2u/postcss-single-charset | ||
[`postcss-normalize-url`]: https://github.com/ben-eb/postcss-normalize-url | ||
[`postcss-color-palette`]: https://github.com/zaim/postcss-color-palette | ||
[`postcss-discard-empty`]: https://github.com/ben-eb/postcss-discard-empty | ||
[`postcss-simple-extend`]: https://github.com/davidtheclark/postcss-simple-extend | ||
[`postcss-media-minmax`]: https://github.com/postcss/postcss-media-minmax | ||
[`postcss-custom-media`]: https://github.com/postcss/postcss-custom-media | ||
[`postcss-brand-colors`]: https://github.com/postcss/postcss-brand-colors | ||
[`postcss-font-variant`]: https://github.com/postcss/postcss-font-variant | ||
[`postcss-will-change`]: https://github.com/postcss/postcss-will-change | ||
[`postcss-merge-rules`]: https://github.com/ben-eb/postcss-merge-rules | ||
[`postcss-simple-vars`]: https://github.com/postcss/postcss-simple-vars | ||
[`postcss-data-packer`]: https://github.com/Ser-Gen/postcss-data-packer | ||
[`postcss-font-family`]: https://github.com/ben-eb/postcss-font-family | ||
[`postcss-color-alpha`]: https://github.com/avanes/postcss-color-alpha | ||
[`postcss-bem-linter`]: https://github.com/necolas/postcss-bem-linter | ||
[`postcss-color-gray`]: https://github.com/postcss/postcss-color-gray | ||
[`postcss-color-hex`]: https://github.com/TrySound/postcss-color-hex | ||
[`postcss-color-hwb`]: https://github.com/postcss/postcss-color-hwb | ||
[`pleeease-filters`]: https://github.com/iamvdo/pleeease-filters | ||
[`postcss-easings`]: https://github.com/postcss/postcss-easings | ||
[`postcss-opacity`]: https://github.com/iamvdo/postcss-opacity | ||
[`postcss-assets`]: https://github.com/borodean/postcss-assets | ||
[`postcss-import`]: https://github.com/postcss/postcss-import | ||
[`postcss-nested`]: https://github.com/postcss/postcss-nested | ||
[`postcss-zindex`]: https://github.com/ben-eb/postcss-zindex | ||
[`postcss-mixins`]: https://github.com/postcss/postcss-mixins | ||
[`mq4-hover-shim`]: https://github.com/twbs/mq4-hover-shim | ||
[`list-selectors`]: https://github.com/davidtheclark/list-selectors | ||
[`css2modernizr`]: https://github.com/vovanbo/css2modernizr | ||
[`postcss-at2x`]: https://github.com/simonsmith/postcss-at2x | ||
[`autoprefixer`]: https://github.com/postcss/autoprefixer | ||
[`css-mqpacker`]: https://github.com/hail2u/node-css-mqpacker | ||
[`postcss-epub`]: https://github.com/Rycochet/postcss-epub | ||
[`postcss-calc`]: https://github.com/postcss/postcss-calc | ||
[`postcss-size`]: https://github.com/postcss/postcss-size | ||
[`postcss-host`]: https://github.com/vitkarpov/postcss-host | ||
[`postcss-vmin`]: https://github.com/iamvdo/postcss-vmin | ||
[`postcss-url`]: https://github.com/postcss/postcss-url | ||
[`postcss-map`]: https://github.com/pascalduez/postcss-map | ||
[`css-byebye`]: https://github.com/AoDev/css-byebye | ||
[`cssgrace`]: https://github.com/cssdream/cssgrace | ||
[`csswring`]: https://github.com/hail2u/node-csswring | ||
[`csstyle`]: https://github.com/geddski/csstyle | ||
[`webpcss`]: https://github.com/lexich/webpcss | ||
[`rtlcss`]: https://github.com/MohammadYounes/rtlcss | ||
[`pixrem`]: https://github.com/robwierzbowski/node-pixrem | ||
[`doiuse`]: https://github.com/anandthakker/doiuse | ||
@@ -358,11 +388,15 @@ ## Usage | ||
var result = processor.process(css, { from: 'app.css', to: 'app.out.css' }); | ||
console.log(result.css); | ||
processor | ||
.process(css, { from: 'app.css', to: 'app.out.css' }) | ||
.then(function (result) { | ||
fs.fileWriteSync('app.out.css', result.css); | ||
if ( result.map ) { | ||
fs.fileWriteSync('app.out.css.map', result.map); | ||
} | ||
}); | ||
``` | ||
Read the [postcss function], [processor], and [Result] API docs for more details. | ||
Read the [PostCSS API] for more details. | ||
[postcss function]: https://github.com/postcss/postcss/blob/master/API.md#postcss-function | ||
[processor]: https://github.com/postcss/postcss/blob/master/API.md#postcss-class | ||
[Result]: https://github.com/postcss/postcss/blob/master/API.md#result-class | ||
[PostCSS API]: https://github.com/postcss/postcss/blob/master/API.md | ||
@@ -384,4 +418,4 @@ ### Source Maps | ||
var result = processor.process(css, { | ||
from: 'main.css', | ||
to: 'main.out.css', | ||
from: 'app.css', | ||
to: 'app.out.css', | ||
map: { inline: false }, | ||
@@ -398,3 +432,3 @@ }); | ||
// main.sass.css has an annotation comment with a link to main.sass.css.map | ||
var result = minifier.process(css, { from: 'main.sass.css', to: 'main.min.css' }); | ||
var result = minifier.process(css, { from: 'app.sass.css', to: 'app.min.css' }); | ||
result.map //=> Source map from main.sass to main.min.css | ||
@@ -457,1 +491,2 @@ ``` | ||
* [Plugin Boilerplate](https://github.com/postcss/postcss-plugin-boilerplate) | ||
* [Ask questions](https://gitter.im/postcss/postcss) |
178042
28
476
29
2362
+ Addedsource-map@0.4.4(transitive)
- Removedsource-map@0.2.0(transitive)
Updatedsource-map@~0.4.2