1 import * as mozilla from 'source-map';
4 * @param plugins Can also be included with the Processor#use method.
5 * @returns A processor that will apply plugins as CSS processors.
7 declare function postcss(plugins?: postcss.AcceptedPlugin[]): postcss.Processor;
8 declare function postcss(...plugins: postcss.AcceptedPlugin[]): postcss.Processor;
9 declare namespace postcss {
10 type AcceptedPlugin = Plugin<any> | Transformer | {
11 postcss: TransformCallback | Processor;
14 * Creates a PostCSS plugin with a standard API.
15 * @param name Plugin name. Same as in name property in package.json. It will
16 * be saved in plugin.postcssPlugin property.
17 * @param initializer Will receive plugin options and should return functions
18 * to modify nodes in input CSS.
20 function plugin<T>(name: string, initializer: PluginInitializer<T>): Plugin<T>;
21 interface Plugin<T> extends Transformer {
22 (opts?: T): Transformer;
24 process: (css: string | {
26 } | Result, opts?: any) => LazyResult;
28 interface Transformer extends TransformCallback {
29 postcssPlugin?: string;
30 postcssVersion?: string;
32 interface TransformCallback {
34 * @returns Asynchronous plugins should return a promise.
36 (root: Root, result?: Result): void | Function | any;
38 interface PluginInitializer<T> {
39 (pluginOptions?: T): Transformer;
42 * Contains helpers for working with vendor prefixes.
44 export namespace vendor {
46 * @returns The vendor prefix extracted from the input string.
48 function prefix(prop: string): string;
50 * @returns The input string stripped of its vendor prefix.
52 function unprefixed(prop: string): string;
54 export class Stringifier {
55 builder: Stringifier.Builder;
56 constructor(builder?: Stringifier.Builder);
57 stringify(node: Node, semicolon?: boolean): void;
58 root(node: any): void;
59 comment(node: any): void;
60 decl(node: any, semicolon: any): void;
61 rule(node: any): void;
62 atrule(node: any, semicolon: any): void;
63 body(node: any): void;
64 block(node: any, start: any): void;
65 raw(node: Node, own: string, detect?: string): any;
66 rawSemicolon(root: any): any;
67 rawEmptyBody(root: any): any;
68 rawIndent(root: any): any;
69 rawBeforeComment(root: any, node: any): any;
70 rawBeforeDecl(root: any, node: any): any;
71 rawBeforeRule(root: any): any;
72 rawBeforeClose(root: any): any;
73 rawBeforeOpen(root: any): any;
74 rawColon(root: any): any;
75 beforeAfter(node: any, detect: any): any;
76 rawValue(node: any, prop: any): any;
78 export namespace Stringifier {
80 (str: string, node?: Node, str2?: string): void;
84 * Default function to convert a node tree into a CSS string.
86 function stringify(node: Node, builder: Stringifier.Builder): void;
89 * @param css The CSS to parse.
91 * @returns {} A new Root node, which contains the source CSS nodes.
93 function parse(css: string | {
95 } | LazyResult | Result, options?: {
97 map?: postcss.SourceMapOptions;
100 * Contains helpers for safely splitting lists of CSS values, preserving
101 * parentheses and quotes.
103 export namespace list {
105 * Safely splits space-separated values (such as those for background,
106 * border-radius and other shorthand properties).
108 function space(str: string): string[];
110 * Safely splits comma-separated values (such as those for transition-* and
111 * background properties).
113 function comma(str: string): string[];
116 * Creates a new Comment node.
117 * @param defaults Properties for the new Comment node.
118 * @returns The new node.
120 function comment(defaults?: CommentNewProps): Comment;
122 * Creates a new AtRule node.
123 * @param defaults Properties for the new AtRule node.
124 * @returns The new node.
126 function atRule(defaults?: AtRuleNewProps): AtRule;
128 * Creates a new Declaration node.
129 * @param defaults Properties for the new Declaration node.
130 * @returns The new node.
132 function decl(defaults?: DeclarationNewProps): Declaration;
134 * Creates a new Rule node.
135 * @param defaults Properties for the new Rule node.
136 * @returns The new node.
138 function rule(defaults?: RuleNewProps): Rule;
140 * Creates a new Root node.
141 * @param defaults Properties for the new Root node.
142 * @returns The new node.
144 function root(defaults?: object): Root;
145 interface SourceMapOptions {
147 * Indicates that the source map should be embedded in the output CSS as a
148 * Base64-encoded comment. By default, it is true. But if all previous maps
149 * are external, not inline, PostCSS will not embed the map even if you do
150 * not set this option.
152 * If you have an inline source map, the result.map property will be empty,
153 * as the source map will be contained within the text of result.css.
157 * Source map content from a previous processing step (e.g., Sass compilation).
158 * PostCSS will try to read the previous source map automatically (based on comments
159 * within the source CSS), but you can use this option to identify it manually.
160 * If desired, you can omit the previous map with prev: false.
164 * Indicates that PostCSS should set the origin content (e.g., Sass source)
165 * of the source map. By default, it is true. But if all previous maps do not
166 * contain sources content, PostCSS will also leave it out even if you do not set
169 sourcesContent?: boolean;
171 * Indicates that PostCSS should add annotation comments to the CSS. By default,
172 * PostCSS will always add a comment with a path to the source map. PostCSS will
173 * not add annotations to CSS files that do not contain any comments.
175 * By default, PostCSS presumes that you want to save the source map as
176 * opts.to + '.map' and will use this path in the annotation comment. A different
177 * path can be set by providing a string value for annotation.
179 * If you have set inline: true, annotation cannot be disabled.
181 annotation?: boolean | string;
183 * If true, PostCSS will try to correct any syntax errors that it finds in the CSS.
184 * This is useful for legacy code filled with hacks. Another use-case is interactive
185 * tools with live input — for example, the Autoprefixer demo.
190 * A Processor instance contains plugins to process CSS. Create one
191 * Processor instance, initialize its plugins, and then use that instance
192 * on numerous CSS files.
194 interface Processor {
196 * Adds a plugin to be used as a CSS processor. Plugins can also be
197 * added by passing them as arguments when creating a postcss instance.
199 use(plugin: AcceptedPlugin): Processor;
201 * Parses source CSS. Because some plugins can be asynchronous it doesn't
202 * make any transformations. Transformations will be applied in LazyResult's
204 * @param css Input CSS or any object with toString() method, like a file
205 * stream. If a Result instance is passed the processor will take the
206 * existing Root parser from it.
208 process(css: string | {
210 } | Result, options?: ProcessOptions): LazyResult;
212 * Contains plugins added to this processor.
214 plugins: Plugin<any>[];
216 * Contains the current version of PostCSS (e.g., "4.0.5").
220 interface ProcessOptions extends Syntax {
222 * The path of the CSS source file. You should always set from, because it is
223 * used in source map generation and syntax error messages.
227 * The path where you'll put the output CSS file. You should always set it
228 * to generate correct source maps.
233 * Enable Safe Mode, in which PostCSS will try to fix CSS syntax errors.
236 map?: postcss.SourceMapOptions;
238 * Function to generate AST by string.
240 parser?: Parse | Syntax;
242 * Class to generate string by AST.
244 stringifier?: Stringify | Syntax;
248 * Function to generate AST by string.
252 * Class to generate string by AST.
254 stringify?: Stringify;
257 (css?: string, opts?: postcss.SourceMapOptions): Root;
259 interface Stringify {
260 (node?: postcss.Node, builder?: any): postcss.Result | void;
263 * A promise proxy for the result of PostCSS transformations.
265 interface LazyResult {
267 * Processes input CSS through synchronous and asynchronous plugins.
268 * @param onRejected Called if any plugin throws an error.
270 then(onFulfilled: (result: Result) => void, onRejected?: (error: Error) => void): Function | any;
272 * Processes input CSS through synchronous and asynchronous plugins.
273 * @param onRejected Called if any plugin throws an error.
275 catch(onRejected: (error: Error) => void): Function | any;
277 * Alias for css property.
281 * Processes input CSS through synchronous plugins and converts Root to
282 * CSS string. This property will only work with synchronous plugins. If
283 * the processor contains any asynchronous plugins it will throw an error.
284 * In this case, you should use LazyResult#then() instead.
285 * @returns Result#css.
289 * Alias for css property to use when syntaxes generate non-CSS output.
293 * Processes input CSS through synchronous plugins. This property will
294 * work only with synchronous plugins. If processor contains any
295 * asynchronous plugins it will throw an error. You should use
296 * LazyResult#then() instead.
300 * Processes input CSS through synchronous plugins. This property will work
301 * only with synchronous plugins. If processor contains any asynchronous
302 * plugins it will throw an error. You should use LazyResult#then() instead.
306 * Processes input CSS through synchronous plugins and calls Result#warnings().
307 * This property will only work with synchronous plugins. If the processor
308 * contains any asynchronous plugins it will throw an error. In this case,
309 * you should use LazyResult#then() instead.
311 warnings(): ResultMessage[];
313 * Processes input CSS through synchronous plugins. This property will work
314 * only with synchronous plugins. If processor contains any asynchronous
315 * plugins it will throw an error. You should use LazyResult#then() instead.
317 messages: ResultMessage[];
319 * @returns A processor used for CSS transformations.
321 processor: Processor;
323 * @returns Options from the Processor#process(css, opts) call that produced
324 * this Result instance.
329 * Provides the result of the PostCSS transformations.
333 * Alias for css property.
337 * Creates an instance of Warning and adds it to messages.
338 * @param message Used in the text property of the message object.
339 * @param options Properties for Message object.
341 warn(message: string, options?: WarningOptions): void;
343 * @returns Warnings from plugins, filtered from messages.
345 warnings(): ResultMessage[];
347 * A CSS string representing this Result's Root instance.
351 * Alias for css property to use with syntaxes that generate non-CSS output.
355 * An instance of the SourceMapGenerator class from the source-map library,
356 * representing changes to the Result's Root instance.
357 * This property will have a value only if the user does not want an inline
358 * source map. By default, PostCSS generates inline source maps, written
359 * directly into the processed CSS. The map property will be empty by default.
360 * An external source map will be generated — and assigned to map — only if
361 * the user has set the map.inline option to false, or if PostCSS was passed
362 * an external input source map.
366 * Contains the Root node after all transformations.
370 * Contains messages from plugins (e.g., warnings or custom messages).
371 * Add a warning using Result#warn() and get all warnings
372 * using the Result#warnings() method.
374 messages: ResultMessage[];
376 * The Processor instance used for this transformation.
378 processor?: Processor;
380 * Options from the Processor#process(css, opts) or Root#toResult(opts) call
381 * that produced this Result instance.
383 opts?: ResultOptions;
385 interface ResultOptions extends ProcessOptions {
387 * The CSS node that was the source of the warning.
391 * Name of plugin that created this warning. Result#warn() will fill it
392 * automatically with plugin.postcssPlugin value.
396 interface ResultMap {
398 * Add a single mapping from original source line and column to the generated
399 * source's line and column for this source map being created. The mapping
400 * object should have the following properties:
404 addMapping(mapping: mozilla.Mapping): void;
406 * Set the source content for an original source file.
407 * @param sourceFile The URL of the original source file.
408 * @param sourceContent The content of the source file.
410 setSourceContent(sourceFile: string, sourceContent: string): void;
412 * Applies a SourceMap for a source file to the SourceMap. Each mapping to
413 * the supplied source file is rewritten using the supplied SourceMap.
414 * Note: The resolution for the resulting mappings is the minimium of this
415 * map and the supplied map.
416 * @param sourceMapConsumer The SourceMap to be applied.
417 * @param sourceFile The filename of the source file. If omitted, sourceMapConsumer
418 * file will be used, if it exists. Otherwise an error will be thrown.
419 * @param sourceMapPath The dirname of the path to the SourceMap to be applied.
420 * If relative, it is relative to the SourceMap. This parameter is needed when
421 * the two SourceMaps aren't in the same directory, and the SourceMap to be
422 * applied contains relative source paths. If so, those relative source paths
423 * need to be rewritten relative to the SourceMap.
424 * If omitted, it is assumed that both SourceMaps are in the same directory;
425 * thus, not needing any rewriting (Supplying '.' has the same effect).
428 sourceMapConsumer: mozilla.SourceMapConsumer,
430 sourceMapPath?: string
433 * Renders the source map being generated to JSON.
435 toJSON: () => mozilla.RawSourceMap;
437 * Renders the source map being generated to a string.
439 toString: () => string;
441 interface ResultMessage {
448 * Represents a plugin warning. It can be created using Result#warn().
452 * @returns Error position, message.
456 * Contains the warning message.
460 * Contains the name of the plugin that created this warning. When you
461 * call Result#warn(), it will fill this property automatically.
465 * The CSS node that caused the warning.
469 * The line in the input file with this warning's source.
473 * Column in the input file with this warning's source.
477 interface WarningOptions extends ResultOptions {
479 * A word inside a node's string that should be highlighted as source
484 * The index inside a node's string that should be highlighted as
490 * The CSS parser throws this error for broken CSS.
492 interface CssSyntaxError extends InputOrigin {
495 * @returns Error position, message and source code of broken part.
499 * @param color Whether arrow should be colored red by terminal color codes.
500 * By default, PostCSS will use process.stdout.isTTY and
501 * process.env.NODE_DISABLE_COLORS.
502 * @returns A few lines of CSS source that caused the error. If CSS has
503 * input source map without sourceContent this method will return an empty
506 showSourceCode(color?: boolean): string;
508 * Contains full error text in the GNU error format.
512 * Contains only the error description.
516 * Contains the PostCSS plugin name if the error didn't come from the
522 interface InputOrigin {
524 * If parser's from option is set, contains the absolute path to the
525 * broken file. PostCSS will use the input source map to detect the
526 * original error location. If you wrote a Sass file, then compiled it
527 * to CSS and parsed it with PostCSS, PostCSS will show the original
528 * position in the Sass file. If you need the position in the PostCSS
529 * input (e.g., to debug the previous compiler), use error.input.file.
533 * Contains the source line of the error. PostCSS will use the input
534 * source map to detect the original error location. If you wrote a Sass
535 * file, then compiled it to CSS and parsed it with PostCSS, PostCSS
536 * will show the original position in the Sass file. If you need the
537 * position in the PostCSS input (e.g., to debug the previous
538 * compiler), use error.input.line.
542 * Contains the source column of the error. PostCSS will use input
543 * source map to detect the original error location. If you wrote a
544 * Sass file, then compiled it to CSS and parsed it with PostCSS,
545 * PostCSS will show the original position in the Sass file. If you
546 * need the position in the PostCSS input (e.g., to debug the
547 * previous compiler), use error.input.column.
551 * Contains the source code of the broken file. PostCSS will use the
552 * input source map to detect the original error location. If you wrote
553 * a Sass file, then compiled it to CSS and parsed it with PostCSS,
554 * PostCSS will show the original position in the Sass file. If you need
555 * the position in the PostCSS input (e.g., to debug the previous
556 * compiler), use error.input.source.
560 export class PreviousMap {
564 private consumerCache;
567 constructor(css: any, opts: any);
568 consumer(): mozilla.SourceMapConsumer;
569 withContent(): boolean;
570 startWith(string: string, start: string): boolean;
571 loadAnnotation(css: string): void;
572 decodeInline(text: string): string;
575 prev: string | Function | mozilla.SourceMapConsumer | mozilla.SourceMapGenerator | mozilla.RawSourceMap
577 isMap(map: any): boolean;
580 * Represents the source CSS.
584 * The absolute path to the CSS source file defined with the "from" option.
588 * The unique ID of the CSS source. Used if "from" option is not provided
589 * (because PostCSS does not know the file path).
593 * The CSS source identifier. Contains input.file if the user set the
594 * "from" option, or input.id if they did not.
598 * Represents the input source map passed from a compilation step before
599 * PostCSS (e.g., from the Sass compiler).
603 * Reads the input source map.
604 * @returns A symbol position in the input source (e.g., in a Sass file
605 * that was compiled to CSS before being passed to PostCSS):
607 origin(line: number, column: number): InputOrigin;
609 type ChildNode = AtRule | Rule | Declaration | Comment;
610 type Node = Root | ChildNode;
613 * Returns the input source of the node. The property is used in source
614 * map generation. If you create a node manually
615 * (e.g., with postcss.decl() ), that node will not have a source
616 * property and will be absent from the source map. For this reason, the
617 * plugin developer should consider cloning nodes to create new ones
618 * (in which case the new node's source will reference the original,
619 * cloned node) or setting the source property manually.
623 * Contains information to generate byte-to-byte equal node string as it
624 * was in origin input.
628 * @returns A CSS string representing the node.
632 * This method produces very useful error messages. If present, an input
633 * source map will be used to get the original position of the source, even
634 * from a previous compilation step (e.g., from Sass compilation).
635 * @returns The original position of the node in the source, showing line
636 * and column numbers and also a small excerpt to facilitate debugging.
642 message: string, options?: NodeErrorOptions): CssSyntaxError;
644 * Creates an instance of Warning and adds it to messages. This method is
645 * provided as a convenience wrapper for Result#warn.
646 * Note that `opts.node` is automatically passed to Result#warn for you.
647 * @param result The result that will receive the warning.
648 * @param text Warning message. It will be used in the `text` property of
649 * the message object.
650 * @param opts Properties to assign to the message object.
652 warn(result: Result, text: string, opts?: WarningOptions): void;
654 * @returns The next child of the node's parent; or, returns undefined if
655 * the current node is the last child.
657 next(): ChildNode | void;
659 * @returns The previous child of the node's parent; or, returns undefined
660 * if the current node is the first child.
662 prev(): ChildNode | void;
664 * Insert new node before current node to current node’s parent.
666 * Just an alias for `node.parent.insertBefore(node, newNode)`.
668 * @returns this node for method chaining.
671 * decl.before('content: ""');
673 before(newNode: Node | object | string | Node[]): this;
675 * Insert new node after current node to current node’s parent.
677 * Just an alias for `node.parent.insertAfter(node, newNode)`.
679 * @returns this node for method chaining.
682 * decl.after('color: black');
684 after(newNode: Node | object | string | Node[]): this;
686 * @returns The Root instance of the node's tree.
690 * Removes the node from its parent and cleans the parent property in the
691 * node and its children.
692 * @returns This node for chaining.
696 * Inserts node(s) before the current node and removes the current node.
697 * @returns This node for chaining.
699 replaceWith(...nodes: (Node | object)[]): this;
701 * @param overrides New properties to override in the clone.
702 * @returns A clone of this node. The node and its (cloned) children will
703 * have a clean parent and code style properties.
705 clone(overrides?: object): this;
707 * Shortcut to clone the node and insert the resulting cloned node before
709 * @param overrides New Properties to override in the clone.
710 * @returns The cloned node.
712 cloneBefore(overrides?: object): this;
714 * Shortcut to clone the node and insert the resulting cloned node after
716 * @param overrides New Properties to override in the clone.
717 * @returns The cloned node.
719 cloneAfter(overrides?: object): this;
721 * @param prop Name or code style property.
722 * @param defaultType Name of default value. It can be easily missed if the
723 * value is the same as prop.
724 * @returns A code style property value. If the node is missing the code
725 * style property (because the node was manually built or cloned), PostCSS
726 * will try to autodetect the code style property by looking at other nodes
729 raw(prop: string, defaultType?: string): any;
731 interface NodeNewProps {
737 * The space symbols before the node. It also stores `*` and `_`
738 * symbols before the declaration (IE hack).
742 * The space symbols after the last child of the node to the end of
747 * The symbols between the property and value for declarations,
748 * selector and "{" for rules, last parameter and "{" for at-rules.
752 * True if last child has (optional) semicolon.
756 * The space between the at-rule's name and parameters.
760 * The space symbols between "/*" and comment's text.
764 * The space symbols between comment's text and "*\/".
768 * The content of important statement, if it is not just "!important".
772 interface NodeSource {
775 * The starting position of the node's source.
782 * The ending position of the node's source.
789 interface NodeErrorOptions {
791 * Plugin name that created this error. PostCSS will set it automatically.
795 * A word inside a node's string, that should be highlighted as source
800 * An index inside a node's string that should be highlighted as source
807 * Returns a string representing the node's type. Possible values are
808 * root, atrule, rule, decl or comment.
812 * Returns the node's parent node.
814 parent?: JsonContainer;
816 * Returns the input source of the node. The property is used in source
817 * map generation. If you create a node manually (e.g., with
818 * postcss.decl() ), that node will not have a source property and
819 * will be absent from the source map. For this reason, the plugin
820 * developer should consider cloning nodes to create new ones (in which
821 * case the new node's source will reference the original, cloned node)
822 * or setting the source property manually.
826 * Contains information to generate byte-to-byte equal node string as it
827 * was in origin input.
831 type Container = Root | AtRule | Rule;
833 * Containers can store any content. If you write a rule inside a rule,
834 * PostCSS will parse it.
836 interface ContainerBase extends NodeBase {
838 * Contains the container's children.
842 * @returns The container's first child.
846 * @returns The container's last child.
850 * @param overrides New properties to override in the clone.
851 * @returns A clone of this node. The node and its (cloned) children will
852 * have a clean parent and code style properties.
854 clone(overrides?: object): this;
856 * @param child Child of the current container.
857 * @returns The child's index within the container's "nodes" array.
859 index(child: ChildNode | number): number;
861 * Determines whether all child nodes satisfy the specified test.
862 * @param callback A function that accepts up to three arguments. The
863 * every method calls the callback function for each node until the
864 * callback returns false, or until the end of the array.
865 * @returns True if the callback returns true for all of the container's
868 every(callback: (node: ChildNode, index: number, nodes: ChildNode[]) => any, thisArg?: any): boolean;
870 * Determines whether the specified callback returns true for any child node.
871 * @param callback A function that accepts up to three arguments. The some
872 * method calls the callback for each node until the callback returns true,
873 * or until the end of the array.
874 * @param thisArg An object to which the this keyword can refer in the
875 * callback function. If thisArg is omitted, undefined is used as the
877 * @returns True if callback returns true for (at least) one of the
878 * container's children.
880 some(callback: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean, thisArg?: any): boolean;
882 * Iterates through the container's immediate children, calling the
883 * callback function for each child. If you need to recursively iterate
884 * through all the container's descendant nodes, use container.walk().
885 * Unlike the for {} -cycle or Array#forEach() this iterator is safe if
886 * you are mutating the array of child nodes during iteration.
887 * @param callback Iterator. Returning false will break iteration. Safe
888 * if you are mutating the array of child nodes during iteration. PostCSS
889 * will adjust the current index to match the mutations.
890 * @returns False if the callback returns false during iteration.
892 each(callback: (node: ChildNode, index: number) => any): boolean | void;
894 * Traverses the container's descendant nodes, calling `callback` for each
895 * node. Like container.each(), this method is safe to use if you are
896 * mutating arrays during iteration. If you only need to iterate through
897 * the container's immediate children, use container.each().
898 * @param callback Iterator.
900 walk(callback: (node: ChildNode, index: number) => any): boolean | void;
902 * Traverses the container's descendant nodes, calling `callback` for each
903 * declaration. Like container.each(), this method is safe to use if you
904 * are mutating arrays during iteration.
905 * @param propFilter Filters declarations by property name. Only those
906 * declarations whose property matches propFilter will be iterated over.
907 * @param callback Called for each declaration node within the container.
909 walkDecls(propFilter: string | RegExp, callback?: (decl: Declaration, index: number) => any): boolean | void;
910 walkDecls(callback: (decl: Declaration, index: number) => any): boolean | void;
912 * Traverses the container's descendant nodes, calling `callback` for each
913 * at-rule. Like container.each(), this method is safe to use if you are
914 * mutating arrays during iteration.
915 * @param nameFilter Filters at-rules by name. If provided, iteration
916 * will only happen over at-rules that have matching names.
917 * @param callback Iterator called for each at-rule node within the
920 walkAtRules(nameFilter: string | RegExp, callback: (atRule: AtRule, index: number) => any): boolean | void;
921 walkAtRules(callback: (atRule: AtRule, index: number) => any): boolean | void;
923 * Traverses the container's descendant nodes, calling `callback` for each
924 * rule. Like container.each(), this method is safe to use if you are
925 * mutating arrays during iteration.
926 * @param selectorFilter Filters rules by selector. If provided,
927 * iteration will only happen over rules that have matching names.
928 * @param callback Iterator called for each rule node within the
931 walkRules(selectorFilter: string | RegExp, callback: (atRule: Rule, index: number) => any): boolean | void;
932 walkRules(callback: (atRule: Rule, index: number) => any): boolean | void;
933 walkRules(selectorFilter: any, callback?: (atRule: Rule, index: number) => any): boolean | void;
935 * Traverses the container's descendant nodes, calling `callback` for each
936 * comment. Like container.each(), this method is safe to use if you are
937 * mutating arrays during iteration.
938 * @param callback Iterator called for each comment node within the container.
940 walkComments(callback: (comment: Comment, indexed: number) => any): void | boolean;
942 * Passes all declaration values within the container that match pattern
943 * through the callback, replacing those values with the returned result of
944 * callback. This method is useful if you are using a custom unit or
945 * function and need to iterate through all values.
946 * @param pattern Pattern that we need to replace.
947 * @param options Options to speed up the search.
948 * @param callbackOrReplaceValue String to replace pattern or callback
949 * that will return a new value. The callback will receive the same
950 * arguments as those passed to a function parameter of String#replace.
952 replaceValues(pattern: string | RegExp, options: {
954 * Property names. The method will only search for values that match
955 * regexp within declarations of listed properties.
959 * Used to narrow down values and speed up the regexp search. Searching
960 * every single value with a regexp can be slow. If you pass a fast
961 * string, PostCSS will first check whether the value contains the fast
962 * string; and only if it does will PostCSS check that value against
963 * regexp. For example, instead of just checking for /\d+rem/ on all
964 * values, set fast: 'rem' to first check whether a value has the rem
965 * unit, and only if it does perform the regexp check.
968 }, callbackOrReplaceValue: string | {
969 (substring: string, ...args: any[]): string;
971 replaceValues(pattern: string | RegExp, callbackOrReplaceValue: string | {
972 (substring: string, ...args: any[]): string;
975 * Inserts new nodes to the beginning of the container.
976 * Because each node class is identifiable by unique properties, use the
977 * following shortcuts to create nodes in insert methods:
978 * root.prepend({ name: '@charset', params: '"UTF-8"' }); // at-rule
979 * root.prepend({ selector: 'a' }); // rule
980 * rule.prepend({ prop: 'color', value: 'black' }); // declaration
981 * rule.prepend({ text: 'Comment' }) // comment
982 * A string containing the CSS of the new element can also be used. This
983 * approach is slower than the above shortcuts.
984 * root.prepend('a {}');
985 * root.first.prepend('color: black; z-index: 1');
986 * @param nodes New nodes.
987 * @returns This container for chaining.
989 prepend(...nodes: (Node | object | string)[]): this;
991 * Inserts new nodes to the end of the container.
992 * Because each node class is identifiable by unique properties, use the
993 * following shortcuts to create nodes in insert methods:
994 * root.append({ name: '@charset', params: '"UTF-8"' }); // at-rule
995 * root.append({ selector: 'a' }); // rule
996 * rule.append({ prop: 'color', value: 'black' }); // declaration
997 * rule.append({ text: 'Comment' }) // comment
998 * A string containing the CSS of the new element can also be used. This
999 * approach is slower than the above shortcuts.
1000 * root.append('a {}');
1001 * root.first.append('color: black; z-index: 1');
1002 * @param nodes New nodes.
1003 * @returns This container for chaining.
1005 append(...nodes: (Node | object | string)[]): this;
1007 * Insert newNode before oldNode within the container.
1008 * @param oldNode Child or child's index.
1009 * @returns This container for chaining.
1011 insertBefore(oldNode: ChildNode | number, newNode: ChildNode | object | string): this;
1013 * Insert newNode after oldNode within the container.
1014 * @param oldNode Child or child's index.
1015 * @returns This container for chaining.
1017 insertAfter(oldNode: ChildNode | number, newNode: ChildNode | object | string): this;
1019 * Removes the container from its parent and cleans the parent property in the
1020 * container and its children.
1021 * @returns This container for chaining.
1025 * Removes child from the container and cleans the parent properties
1026 * from the node and its children.
1027 * @param child Child or child's index.
1028 * @returns This container for chaining.
1030 removeChild(child: ChildNode | number): this;
1032 * Removes all children from the container and cleans their parent
1034 * @returns This container for chaining.
1038 interface ContainerNewProps extends NodeNewProps {
1040 * Contains the container's children.
1042 nodes?: ChildNode[];
1043 raws?: ContainerRaws;
1045 interface ContainerRaws extends NodeRaws {
1048 interface JsonContainer extends JsonNode {
1050 * Contains the container's children.
1052 nodes?: ChildNode[];
1054 * @returns The container's first child.
1058 * @returns The container's last child.
1063 * Represents a CSS file and contains all its parsed nodes.
1065 interface Root extends ContainerBase {
1068 * Inherited from Container. Should always be undefined for a Root node.
1072 * @param overrides New properties to override in the clone.
1073 * @returns A clone of this node. The node and its (cloned) children will
1074 * have a clean parent and code style properties.
1076 clone(overrides?: object): this;
1078 * @returns A Result instance representing the root's CSS.
1080 toResult(options?: {
1082 * The path where you'll put the output CSS file. You should always
1083 * set "to" to generate correct source maps.
1086 map?: SourceMapOptions;
1089 * Removes child from the root node, and the parent properties of node and
1091 * @param child Child or child's index.
1092 * @returns This root node for chaining.
1094 removeChild(child: ChildNode | number): this;
1096 interface RootNewProps extends ContainerNewProps {
1098 interface JsonRoot extends JsonContainer {
1101 * Represents an at-rule. If it's followed in the CSS by a {} block, this
1102 * node will have a nodes property representing its children.
1104 interface AtRule extends ContainerBase {
1107 * Returns the atrule's parent node.
1111 * The identifier that immediately follows the @.
1115 * These are the values that follow the at-rule's name, but precede any {}
1116 * block. The spec refers to this area as the at-rule's "prelude".
1120 * @param overrides New properties to override in the clone.
1121 * @returns A clone of this node. The node and its (cloned) children will
1122 * have a clean parent and code style properties.
1124 clone(overrides?: object): this;
1126 interface AtRuleNewProps extends ContainerNewProps {
1128 * The identifier that immediately follows the @.
1132 * These are the values that follow the at-rule's name, but precede any {}
1133 * block. The spec refers to this area as the at-rule's "prelude".
1135 params?: string | number;
1138 interface AtRuleRaws extends NodeRaws {
1141 interface JsonAtRule extends JsonContainer {
1143 * The identifier that immediately follows the @.
1147 * These are the values that follow the at-rule's name, but precede any {}
1148 * block. The spec refers to this area as the at-rule's "prelude".
1153 * Represents a CSS rule: a selector followed by a declaration block.
1155 interface Rule extends ContainerBase {
1158 * Returns the rule's parent node.
1162 * The rule's full selector. If there are multiple comma-separated selectors,
1163 * the entire group will be included.
1167 * An array containing the rule's individual selectors.
1168 * Groups of selectors are split at commas.
1170 selectors?: string[];
1172 * @param overrides New properties to override in the clone.
1173 * @returns A clone of this node. The node and its (cloned) children will
1174 * have a clean parent and code style properties.
1176 clone(overrides?: object): this;
1178 interface RuleNewProps extends ContainerNewProps {
1180 * The rule's full selector. If there are multiple comma-separated selectors,
1181 * the entire group will be included.
1185 * An array containing the rule's individual selectors. Groups of selectors
1186 * are split at commas.
1188 selectors?: string[];
1191 interface RuleRaws extends ContainerRaws {
1193 * The rule's full selector. If there are multiple comma-separated selectors,
1194 * the entire group will be included.
1198 interface JsonRule extends JsonContainer {
1200 * The rule's full selector. If there are multiple comma-separated selectors,
1201 * the entire group will be included.
1205 * An array containing the rule's individual selectors.
1206 * Groups of selectors are split at commas.
1208 selectors?: string[];
1211 * Represents a CSS declaration.
1213 interface Declaration extends NodeBase {
1216 * Returns the declaration's parent node.
1220 * The declaration's property name.
1224 * The declaration's value. This value will be cleaned of comments. If the
1225 * source value contained comments, those comments will be available in the
1226 * _value.raws property. If you have not changed the value, the result of
1227 * decl.toString() will include the original raws value (comments and all).
1231 * True if the declaration has an !important annotation.
1235 * @param overrides New properties to override in the clone.
1236 * @returns A clone of this node. The node and its (cloned) children will
1237 * have a clean parent and code style properties.
1239 clone(overrides?: object): this;
1241 interface DeclarationNewProps {
1243 * The declaration's property name.
1247 * The declaration's value. This value will be cleaned of comments. If the
1248 * source value contained comments, those comments will be available in the
1249 * _value.raws property. If you have not changed the value, the result of
1250 * decl.toString() will include the original raws value (comments and all).
1253 raws?: DeclarationRaws;
1255 interface DeclarationRaws extends NodeRaws {
1257 * The declaration's value. This value will be cleaned of comments.
1258 * If the source value contained comments, those comments will be
1259 * available in the _value.raws property. If you have not changed the value, the result of
1260 * decl.toString() will include the original raws value (comments and all).
1264 interface JsonDeclaration extends JsonNode {
1266 * True if the declaration has an !important annotation.
1268 important?: boolean;
1271 * Represents a comment between declarations or statements (rule and at-rules).
1272 * Comments inside selectors, at-rule parameters, or declaration values will
1273 * be stored in the Node#raws properties.
1275 interface Comment extends NodeBase {
1278 * Returns the comment's parent node.
1282 * The comment's text.
1286 * @param overrides New properties to override in the clone.
1287 * @returns A clone of this node. The node and its (cloned) children will
1288 * have a clean parent and code style properties.
1290 clone(overrides?: object): this;
1292 interface CommentNewProps {
1294 * The comment's text.
1298 interface JsonComment extends JsonNode {