You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
293 lines
19 KiB
293 lines
19 KiB
2 years ago
|
'use strict';
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
|
||
|
var _declaration = require('./declaration');
|
||
|
|
||
|
var _declaration2 = _interopRequireDefault(_declaration);
|
||
|
|
||
|
var _processor = require('./processor');
|
||
|
|
||
|
var _processor2 = _interopRequireDefault(_processor);
|
||
|
|
||
|
var _stringify = require('./stringify');
|
||
|
|
||
|
var _stringify2 = _interopRequireDefault(_stringify);
|
||
|
|
||
|
var _comment = require('./comment');
|
||
|
|
||
|
var _comment2 = _interopRequireDefault(_comment);
|
||
|
|
||
|
var _atRule = require('./at-rule');
|
||
|
|
||
|
var _atRule2 = _interopRequireDefault(_atRule);
|
||
|
|
||
|
var _vendor = require('./vendor');
|
||
|
|
||
|
var _vendor2 = _interopRequireDefault(_vendor);
|
||
|
|
||
|
var _parse = require('./parse');
|
||
|
|
||
|
var _parse2 = _interopRequireDefault(_parse);
|
||
|
|
||
|
var _list = require('./list');
|
||
|
|
||
|
var _list2 = _interopRequireDefault(_list);
|
||
|
|
||
|
var _rule = require('./rule');
|
||
|
|
||
|
var _rule2 = _interopRequireDefault(_rule);
|
||
|
|
||
|
var _root = require('./root');
|
||
|
|
||
|
var _root2 = _interopRequireDefault(_root);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
/**
|
||
|
* Create a new {@link Processor} instance that will apply `plugins`
|
||
|
* as CSS processors.
|
||
|
*
|
||
|
* @param {Array.<Plugin|pluginFunction>|Processor} plugins - PostCSS
|
||
|
* plugins. See {@link Processor#use} for plugin format.
|
||
|
*
|
||
|
* @return {Processor} Processor to process multiple CSS
|
||
|
*
|
||
|
* @example
|
||
|
* import postcss from 'postcss';
|
||
|
*
|
||
|
* postcss(plugins).process(css, { from, to }).then(result => {
|
||
|
* console.log(result.css);
|
||
|
* });
|
||
|
*
|
||
|
* @namespace postcss
|
||
|
*/
|
||
|
function postcss() {
|
||
|
for (var _len = arguments.length, plugins = Array(_len), _key = 0; _key < _len; _key++) {
|
||
|
plugins[_key] = arguments[_key];
|
||
|
}
|
||
|
|
||
|
if (plugins.length === 1 && Array.isArray(plugins[0])) {
|
||
|
plugins = plugins[0];
|
||
|
}
|
||
|
return new _processor2.default(plugins);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Creates a PostCSS plugin with a standard API.
|
||
|
*
|
||
|
* The newly-wrapped function will provide both the name and PostCSS
|
||
|
* version of the plugin.
|
||
|
*
|
||
|
* ```js
|
||
|
* const processor = postcss([replace]);
|
||
|
* processor.plugins[0].postcssPlugin //=> 'postcss-replace'
|
||
|
* processor.plugins[0].postcssVersion //=> '5.1.0'
|
||
|
* ```
|
||
|
*
|
||
|
* The plugin function receives 2 arguments: {@link Root}
|
||
|
* and {@link Result} instance. The function should mutate the provided
|
||
|
* `Root` node. Alternatively, you can create a new `Root` node
|
||
|
* and override the `result.root` property.
|
||
|
*
|
||
|
* ```js
|
||
|
* const cleaner = postcss.plugin('postcss-cleaner', () => {
|
||
|
* return (root, result) => {
|
||
|
* result.root = postcss.root();
|
||
|
* };
|
||
|
* });
|
||
|
* ```
|
||
|
*
|
||
|
* As a convenience, plugins also expose a `process` method so that you can use
|
||
|
* them as standalone tools.
|
||
|
*
|
||
|
* ```js
|
||
|
* cleaner.process(css, processOpts, pluginOpts);
|
||
|
* // This is equivalent to:
|
||
|
* postcss([ cleaner(pluginOpts) ]).process(css, processOpts);
|
||
|
* ```
|
||
|
*
|
||
|
* Asynchronous plugins should return a `Promise` instance.
|
||
|
*
|
||
|
* ```js
|
||
|
* postcss.plugin('postcss-import', () => {
|
||
|
* return (root, result) => {
|
||
|
* return new Promise( (resolve, reject) => {
|
||
|
* fs.readFile('base.css', (base) => {
|
||
|
* root.prepend(base);
|
||
|
* resolve();
|
||
|
* });
|
||
|
* });
|
||
|
* };
|
||
|
* });
|
||
|
* ```
|
||
|
*
|
||
|
* Add warnings using the {@link Node#warn} method.
|
||
|
* Send data to other plugins using the {@link Result#messages} array.
|
||
|
*
|
||
|
* ```js
|
||
|
* postcss.plugin('postcss-caniuse-test', () => {
|
||
|
* return (root, result) => {
|
||
|
* root.walkDecls(decl => {
|
||
|
* if ( !caniuse.support(decl.prop) ) {
|
||
|
* decl.warn(result, 'Some browsers do not support ' + decl.prop);
|
||
|
* }
|
||
|
* });
|
||
|
* };
|
||
|
* });
|
||
|
* ```
|
||
|
*
|
||
|
* @param {string} name - PostCSS plugin name. Same as in `name`
|
||
|
* property in `package.json`. It will be saved
|
||
|
* in `plugin.postcssPlugin` property.
|
||
|
* @param {function} initializer - will receive plugin options
|
||
|
* and should return {@link pluginFunction}
|
||
|
*
|
||
|
* @return {Plugin} PostCSS plugin
|
||
|
*/
|
||
|
postcss.plugin = function plugin(name, initializer) {
|
||
|
var creator = function creator() {
|
||
|
var transformer = initializer.apply(undefined, arguments);
|
||
|
transformer.postcssPlugin = name;
|
||
|
transformer.postcssVersion = new _processor2.default().version;
|
||
|
return transformer;
|
||
|
};
|
||
|
|
||
|
var cache = void 0;
|
||
|
Object.defineProperty(creator, 'postcss', {
|
||
|
get: function get() {
|
||
|
if (!cache) cache = creator();
|
||
|
return cache;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
creator.process = function (css, processOpts, pluginOpts) {
|
||
|
return postcss([creator(pluginOpts)]).process(css, processOpts);
|
||
|
};
|
||
|
|
||
|
return creator;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Default function to convert a node tree into a CSS string.
|
||
|
*
|
||
|
* @param {Node} node - start node for stringifing. Usually {@link Root}.
|
||
|
* @param {builder} builder - function to concatenate CSS from node’s parts
|
||
|
* or generate string and source map
|
||
|
*
|
||
|
* @return {void}
|
||
|
*
|
||
|
* @function
|
||
|
*/
|
||
|
postcss.stringify = _stringify2.default;
|
||
|
|
||
|
/**
|
||
|
* Parses source css and returns a new {@link Root} node,
|
||
|
* which contains the source CSS nodes.
|
||
|
*
|
||
|
* @param {string|toString} css - string with input CSS or any object
|
||
|
* with toString() method, like a Buffer
|
||
|
* @param {processOptions} [opts] - options with only `from` and `map` keys
|
||
|
*
|
||
|
* @return {Root} PostCSS AST
|
||
|
*
|
||
|
* @example
|
||
|
* // Simple CSS concatenation with source map support
|
||
|
* const root1 = postcss.parse(css1, { from: file1 });
|
||
|
* const root2 = postcss.parse(css2, { from: file2 });
|
||
|
* root1.append(root2).toResult().css;
|
||
|
*
|
||
|
* @function
|
||
|
*/
|
||
|
postcss.parse = _parse2.default;
|
||
|
|
||
|
/**
|
||
|
* @member {vendor} - Contains the {@link vendor} module.
|
||
|
*
|
||
|
* @example
|
||
|
* postcss.vendor.unprefixed('-moz-tab') //=> ['tab']
|
||
|
*/
|
||
|
postcss.vendor = _vendor2.default;
|
||
|
|
||
|
/**
|
||
|
* @member {list} - Contains the {@link list} module.
|
||
|
*
|
||
|
* @example
|
||
|
* postcss.list.space('5px calc(10% + 5px)') //=> ['5px', 'calc(10% + 5px)']
|
||
|
*/
|
||
|
postcss.list = _list2.default;
|
||
|
|
||
|
/**
|
||
|
* Creates a new {@link Comment} node.
|
||
|
*
|
||
|
* @param {object} [defaults] - properties for the new node.
|
||
|
*
|
||
|
* @return {Comment} new Comment node
|
||
|
*
|
||
|
* @example
|
||
|
* postcss.comment({ text: 'test' })
|
||
|
*/
|
||
|
postcss.comment = function (defaults) {
|
||
|
return new _comment2.default(defaults);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Creates a new {@link AtRule} node.
|
||
|
*
|
||
|
* @param {object} [defaults] - properties for the new node.
|
||
|
*
|
||
|
* @return {AtRule} new AtRule node
|
||
|
*
|
||
|
* @example
|
||
|
* postcss.atRule({ name: 'charset' }).toString() //=> "@charset"
|
||
|
*/
|
||
|
postcss.atRule = function (defaults) {
|
||
|
return new _atRule2.default(defaults);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Creates a new {@link Declaration} node.
|
||
|
*
|
||
|
* @param {object} [defaults] - properties for the new node.
|
||
|
*
|
||
|
* @return {Declaration} new Declaration node
|
||
|
*
|
||
|
* @example
|
||
|
* postcss.decl({ prop: 'color', value: 'red' }).toString() //=> "color: red"
|
||
|
*/
|
||
|
postcss.decl = function (defaults) {
|
||
|
return new _declaration2.default(defaults);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Creates a new {@link Rule} node.
|
||
|
*
|
||
|
* @param {object} [defaults] - properties for the new node.
|
||
|
*
|
||
|
* @return {Rule} new Rule node
|
||
|
*
|
||
|
* @example
|
||
|
* postcss.rule({ selector: 'a' }).toString() //=> "a {\n}"
|
||
|
*/
|
||
|
postcss.rule = function (defaults) {
|
||
|
return new _rule2.default(defaults);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Creates a new {@link Root} node.
|
||
|
*
|
||
|
* @param {object} [defaults] - properties for the new node.
|
||
|
*
|
||
|
* @return {Root} new Root node
|
||
|
*
|
||
|
* @example
|
||
|
* postcss.root({ after: '\n' }).toString() //=> "\n"
|
||
|
*/
|
||
|
postcss.root = function (defaults) {
|
||
|
return new _root2.default(defaults);
|
||
|
};
|
||
|
|
||
|
exports.default = postcss;
|
||
|
module.exports = exports['default'];
|
||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInBvc3Rjc3MuZXM2Il0sIm5hbWVzIjpbInBvc3Rjc3MiLCJwbHVnaW5zIiwibGVuZ3RoIiwiQXJyYXkiLCJpc0FycmF5IiwiUHJvY2Vzc29yIiwicGx1Z2luIiwibmFtZSIsImluaXRpYWxpemVyIiwiY3JlYXRvciIsInRyYW5zZm9ybWVyIiwicG9zdGNzc1BsdWdpbiIsInBvc3Rjc3NWZXJzaW9uIiwidmVyc2lvbiIsImNhY2hlIiwiT2JqZWN0IiwiZGVmaW5lUHJvcGVydHkiLCJnZXQiLCJwcm9jZXNzIiwiY3NzIiwicHJvY2Vzc09wdHMi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