/
eb
/
Surf
Обзор
Документация
Войти
/
eb
/
Surf
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
node_modules/postcss/lib/postcss.js
285 строк
19 KB
EvgeniyBudaev
Initial commit
17 фев 2020, 09:02
17 фев 2020, 09:02
bb6f06f
Код
Авторство
О чём код?
"use strict"; exports.__esModule = true; exports.default = void 0; var _declaration = _interopRequireDefault(require("./declaration")); var _processor = _interopRequireDefault(require("./processor")); var _stringify = _interopRequireDefault(require("./stringify")); var _comment = _interopRequireDefault(require("./comment")); var _atRule = _interopRequireDefault(require("./at-rule")); var _vendor = _interopRequireDefault(require("./vendor")); var _parse = _interopRequireDefault(require("./parse")); var _list = _interopRequireDefault(require("./list")); var _rule = _interopRequireDefault(require("./rule")); var _root = _interopRequireDefault(require("./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 = new Array(_len), _key = 0; _key < _len; _key++) { plugins[_key] = arguments[_key]; } if (plugins.length === 1 && Array.isArray(plugins[0])) { plugins = plugins[0]; } return new _processor.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 //=> '6.0.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) { function creator() { var transformer = initializer.apply(void 0, arguments); transformer.postcssPlugin = name; transformer.postcssVersion = new _processor.default().version; return transformer; } var cache; 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 = _stringify.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 = _parse.default; /** * Contains the {@link vendor} module. * * @type {vendor} * * @example * postcss.vendor.unprefixed('-moz-tab') //=> ['tab'] */ postcss.vendor = _vendor.default; /** * Contains the {@link list} module. * * @member {list} * * @example * postcss.list.space('5px calc(10% + 5px)') //=> ['5px', 'calc(10% + 5px)'] */ postcss.list = _list.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 _comment.default(defaults); }; /** * Creates a new {@link AtRule} node. * * @param {object} [defaults] Properties for the new node. * * @return {AtRule} new at-rule node * * @example * postcss.atRule({ name: 'charset' }).toString() //=> "@charset" */ postcss.atRule = function (defaults) { return new _atRule.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 _declaration.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 _rule.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 _root.default(defaults); }; var _default = postcss; exports.default = _default; module.exports = exports.default; //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInBvc3Rjc3MuZXM2Il0sIm5hbWVzIjpbInBvc3Rjc3MiLCJwbHVnaW5zIiwibGVuZ3RoIiwiQXJyYXkiLCJpc0FycmF5IiwiUHJvY2Vzc … [Строка слишком длинная. Вы можете скачать файл]