1 declare module "postcss" {
3 * @param plugins Can also be included with the Processor#use method.
4 * @returns A processor that will apply plugins as CSS processors.
6 function postcss(plugins?: postcss.AcceptedPlugin[]): postcss.Processor;
7 function postcss(...plugins: postcss.AcceptedPlugin[]): postcss.Processor;
9 type AcceptedPlugin = Plugin<any> | Transformer | {
10 postcss: TransformCallback | Processor;
13 * Creates a PostCSS plugin with a standard API.
14 * @param name Plugin name. Same as in name property in package.json. It will
15 * be saved in plugin.postcssPlugin property.
16 * @param initializer Will receive plugin options and should return functions
17 * to modify nodes in input CSS.
19 function plugin<T>(name: string, initializer: PluginInitializer<T>): Plugin<T>;
20 interface Plugin<T> extends Transformer {
21 (opts?: T): Transformer;
23 process: (css: string | {
25 } | Result, opts?: any) => LazyResult;
27 interface Transformer extends TransformCallback {
28 postcssPlugin?: string;
29 postcssVersion?: string;
31 interface TransformCallback {
33 * @returns Asynchronous plugins should return a promise.
35 (root: Root, result?: Result): void | Function | any;
37 interface PluginInitializer<T> {
38 (pluginOptions?: T): Transformer;
41 * Contains helpers for working with vendor prefixes.
43 export namespace vendor {
45 * @returns The vendor prefix extracted from the input string.
47 function prefix(prop: string): string;
49 * @returns The input string stripped of its vendor prefix.
51 function unprefixed(prop: string): string;
53 export class Stringifier {
54 builder: Stringifier.Builder;
55 constructor(builder?: Stringifier.Builder);
56 stringify(node: Node, semicolon?: boolean): void;
57 root(node: any): void;
58 comment(node: any): void;
59 decl(node: any, semicolon: any): void;
60 rule(node: any): void;
61 atrule(node: any, semicolon: any): void;
62 body(node: any): void;
63 block(node: any, start: any): void;
64 raw(node: Node, own: string, detect?: string): any;
65 rawSemicolon(root: any): any;
66 rawEmptyBody(root: any): any;
67 rawIndent(root: any): any;
68 rawBeforeComment(root: any, node: any): any;
69 rawBeforeDecl(root: any, node: any): any;
70 rawBeforeRule(root: any): any;
71 rawBeforeClose(root: any): any;
72 rawBeforeOpen(root: any): any;
73 rawColon(root: any): any;
74 beforeAfter(node: any, detect: any): any;
75 rawValue(node: any, prop: any): any;
77 export namespace Stringifier {
79 (str: string, node?: Node, str2?: string): void;
83 * Default function to convert a node tree into a CSS string.
85 function stringify(node: Node, builder: Stringifier.Builder): void;
88 * @param css The CSS to parse.
90 * @returns {} A new Root node, which contains the source CSS nodes.
92 function parse(css: string | {
94 } | LazyResult | Result, options?: {
96 map?: postcss.SourceMapOptions;
99 * Contains helpers for safely splitting lists of CSS values, preserving
100 * parentheses and quotes.
102 export namespace list {
104 * Safely splits space-separated values (such as those for background,
105 * border-radius and other shorthand properties).
107 function space(str: string): string[];
109 * Safely splits comma-separated values (such as those for transition-* and
110 * background properties).
112 function comma(str: string): string[];
115 * Creates a new Comment node.
116 * @param defaults Properties for the new Comment node.
117 * @returns The new node.
119 function comment(defaults?: CommentNewProps): Comment;
121 * Creates a new AtRule node.
122 * @param defaults Properties for the new AtRule node.
123 * @returns The new node.
125 function atRule(defaults?: AtRuleNewProps): AtRule;
127 * Creates a new Declaration node.
128 * @param defaults Properties for the new Declaration node.
129 * @returns The new node.
131 function decl(defaults?: DeclarationNewProps): Declaration;
133 * Creates a new Rule node.
134 * @param defaults Properties for the new Rule node.
135 * @returns The new node.
137 function rule(defaults?: RuleNewProps): Rule;
139 * Creates a new Root node.
140 * @param defaults Properties for the new Root node.
141 * @returns The new node.
143 function root(defaults?: Object): Root;
144 interface SourceMapOptions {
146 * Indicates that the source map should be embedded in the output CSS as a
147 * Base64-encoded comment. By default, it is true. But if all previous maps
148 * are external, not inline, PostCSS will not embed the map even if you do
149 * not set this option.
151 * If you have an inline source map, the result.map property will be empty,
152 * as the source map will be contained within the text of result.css.
156 * Source map content from a previous processing step (e.g., Sass compilation).
157 * PostCSS will try to read the previous source map automatically (based on comments
158 * within the source CSS), but you can use this option to identify it manually.
159 * If desired, you can omit the previous map with prev: false.
163 * Indicates that PostCSS should set the origin content (e.g., Sass source)
164 * of the source map. By default, it is true. But if all previous maps do not
165 * contain sources content, PostCSS will also leave it out even if you do not set
168 sourcesContent?: boolean;
170 * Indicates that PostCSS should add annotation comments to the CSS. By default,
171 * PostCSS will always add a comment with a path to the source map. PostCSS will
172 * not add annotations to CSS files that do not contain any comments.
174 * By default, PostCSS presumes that you want to save the source map as
175 * opts.to + '.map' and will use this path in the annotation comment. A different
176 * path can be set by providing a string value for annotation.
178 * If you have set inline: true, annotation cannot be disabled.
180 annotation?: boolean | string;
182 * If true, PostCSS will try to correct any syntax errors that it finds in the CSS.
183 * This is useful for legacy code filled with hacks. Another use-case is interactive
184 * tools with live input — for example, the Autoprefixer demo.
189 * A Processor instance contains plugins to process CSS. Create one
190 * Processor instance, initialize its plugins, and then use that instance
191 * on numerous CSS files.
193 interface Processor {
195 * Adds a plugin to be used as a CSS processor. Plugins can also be
196 * added by passing them as arguments when creating a postcss instance.
198 use(plugin: AcceptedPlugin): Processor;
200 * Parses source CSS. Because some plugins can be asynchronous it doesn't
201 * make any transformations. Transformations will be applied in LazyResult's
203 * @param css Input CSS or any object with toString() method, like a file
204 * stream. If a Result instance is passed the processor will take the
205 * existing Root parser from it.
207 process(css: string | {
209 } | Result, options?: ProcessOptions): LazyResult;
211 * Contains plugins added to this processor.
213 plugins: Plugin<any>[];
215 * Contains the current version of PostCSS (e.g., "4.0.5").
219 interface ProcessOptions extends Syntax {
221 * The path of the CSS source file. You should always set from, because it is
222 * used in source map generation and syntax error messages.
226 * The path where you'll put the output CSS file. You should always set it
227 * to generate correct source maps.
232 * Enable Safe Mode, in which PostCSS will try to fix CSS syntax errors.
235 map?: postcss.SourceMapOptions;
237 * Function to generate AST by string.
239 parser?: Parse | Syntax;
241 * Class to generate string by AST.
243 stringifier?: Stringify | Syntax;
247 * Function to generate AST by string.
251 * Class to generate string by AST.
253 stringify?: Stringify;
256 (css?: string, opts?: postcss.SourceMapOptions): Root;
258 interface Stringify {
259 (node?: postcss.Node, builder?: any): postcss.Result | void;
262 * A promise proxy for the result of PostCSS transformations.
264 interface LazyResult {
266 * Processes input CSS through synchronous and asynchronous plugins.
267 * @param onRejected Called if any plugin throws an error.
269 then(onFulfilled: (result: Result) => void, onRejected?: (error: Error) => void): Function | any;
271 * Processes input CSS through synchronous and asynchronous plugins.
272 * @param onRejected Called if any plugin throws an error.
274 catch(onRejected: (error: Error) => void): Function | any;
276 * Alias for css property.
280 * Processes input CSS through synchronous plugins and converts Root to
281 * CSS string. This property will only work with synchronous plugins. If
282 * the processor contains any asynchronous plugins it will throw an error.
283 * In this case, you should use LazyResult#then() instead.
284 * @returns Result#css.
288 * Alias for css property to use when syntaxes generate non-CSS output.
292 * Processes input CSS through synchronous plugins. This property will
293 * work only with synchronous plugins. If processor contains any
294 * asynchronous plugins it will throw an error. You should use
295 * LazyResult#then() instead.
299 * Processes input CSS through synchronous plugins. This property will work
300 * only with synchronous plugins. If processor contains any asynchronous
301 * plugins it will throw an error. You should use LazyResult#then() instead.
305 * Processes input CSS through synchronous plugins and calls Result#warnings().
306 * This property will only work with synchronous plugins. If the processor
307 * contains any asynchronous plugins it will throw an error. In this case,
308 * you should use LazyResult#then() instead.
310 warnings(): ResultMessage[];
312 * Processes input CSS through synchronous plugins. This property will work
313 * only with synchronous plugins. If processor contains any asynchronous
314 * plugins it will throw an error. You should use LazyResult#then() instead.
316 messages: ResultMessage[];
318 * @returns A processor used for CSS transformations.
320 processor: Processor;
322 * @returns Options from the Processor#process(css, opts) call that produced
323 * this Result instance.
328 * Provides the result of the PostCSS transformations.
332 * Alias for css property.
336 * Creates an instance of Warning and adds it to messages.
337 * @param message Used in the text property of the message object.
338 * @param options Properties for Message object.
340 warn(message: string, options?: WarningOptions): void;
342 * @returns Warnings from plugins, filtered from messages.
344 warnings(): ResultMessage[];
346 * A CSS string representing this Result's Root instance.
350 * Alias for css property to use with syntaxes that generate non-CSS output.
354 * An instance of the SourceMapGenerator class from the source-map library,
355 * representing changes to the Result's Root instance.
356 * This property will have a value only if the user does not want an inline
357 * source map. By default, PostCSS generates inline source maps, written
358 * directly into the processed CSS. The map property will be empty by default.
359 * An external source map will be generated — and assigned to map — only if
360 * the user has set the map.inline option to false, or if PostCSS was passed
361 * an external input source map.
365 * Contains the Root node after all transformations.
369 * Contains messages from plugins (e.g., warnings or custom messages).
370 * Add a warning using Result#warn() and get all warnings
371 * using the Result#warnings() method.
373 messages: ResultMessage[];
375 * The Processor instance used for this transformation.
377 processor?: Processor;
379 * Options from the Processor#process(css, opts) or Root#toResult(opts) call
380 * that produced this Result instance.
382 opts?: ResultOptions;
384 interface ResultOptions extends ProcessOptions {
386 * The CSS node that was the source of the warning.
390 * Name of plugin that created this warning. Result#warn() will fill it
391 * automatically with plugin.postcssPlugin value.
395 interface ResultMap {
397 * Add a single mapping from original source line and column to the generated
398 * source's line and column for this source map being created. The mapping
399 * object should have the following properties:
403 addMapping(mapping: {
413 * The original source file (relative to the sourceRoot).
419 * Set the source content for an original source file.
420 * @param sourceFile The URL of the original source file.
421 * @param sourceContent The content of the source file.
423 setSourceContent(sourceFile: string, sourceContent: string): void;
425 * Applies a SourceMap for a source file to the SourceMap. Each mapping to
426 * the supplied source file is rewritten using the supplied SourceMap.
427 * Note: The resolution for the resulting mappings is the minimium of this
428 * map and the supplied map.
429 * @param sourceMapConsumer The SourceMap to be applied.
430 * @param sourceFile The filename of the source file. If omitted, sourceMapConsumer
431 * file will be used, if it exists. Otherwise an error will be thrown.
432 * @param sourceMapPath The dirname of the path to the SourceMap to be applied.
433 * If relative, it is relative to the SourceMap. This parameter is needed when
434 * the two SourceMaps aren't in the same directory, and the SourceMap to be
435 * applied contains relative source paths. If so, those relative source paths
436 * need to be rewritten relative to the SourceMap.
437 * If omitted, it is assumed that both SourceMaps are in the same directory;
438 * thus, not needing any rewriting (Supplying '.' has the same effect).
440 applySourceMap(sourceMapConsumer: any, sourceFile?: string, sourceMapPath?: string): void;
442 * Renders the source map being generated to JSON.
446 * Renders the source map being generated to a string.
448 toString: () => string;
450 interface ResultMessage {
457 * Represents a plugin warning. It can be created using Result#warn().
461 * @returns Error position, message.
465 * Contains the warning message.
469 * Contains the name of the plugin that created this warning. When you
470 * call Result#warn(), it will fill this property automatically.
474 * The CSS node that caused the warning.
478 * The line in the input file with this warning's source.
482 * Column in the input file with this warning's source.
486 interface WarningOptions extends ResultOptions {
488 * A word inside a node's string that should be highlighted as source
493 * The index inside a node's string that should be highlighted as
499 * The CSS parser throws this error for broken CSS.
501 interface CssSyntaxError extends InputOrigin {
504 * @returns Error position, message and source code of broken part.
508 * @param color Whether arrow should be colored red by terminal color codes.
509 * By default, PostCSS will use process.stdout.isTTY and
510 * process.env.NODE_DISABLE_COLORS.
511 * @returns A few lines of CSS source that caused the error. If CSS has
512 * input source map without sourceContent this method will return an empty
515 showSourceCode(color?: boolean): string;
517 * Contains full error text in the GNU error format.
521 * Contains only the error description.
525 * Contains the PostCSS plugin name if the error didn't come from the
531 interface InputOrigin {
533 * If parser's from option is set, contains the absolute path to the
534 * broken file. PostCSS will use the input source map to detect the
535 * original error location. If you wrote a Sass file, then compiled it
536 * to CSS and parsed it with PostCSS, PostCSS will show the original
537 * position in the Sass file. If you need the position in the PostCSS
538 * input (e.g., to debug the previous compiler), use error.input.file.
542 * Contains the source line of the error. PostCSS will use the input
543 * source map to detect the original error location. If you wrote a Sass
544 * file, then compiled it to CSS and parsed it with PostCSS, PostCSS
545 * will show the original position in the Sass file. If you need the
546 * position in the PostCSS input (e.g., to debug the previous
547 * compiler), use error.input.line.
551 * Contains the source column of the error. PostCSS will use input
552 * source map to detect the original error location. If you wrote a
553 * 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
555 * need the position in the PostCSS input (e.g., to debug the
556 * previous compiler), use error.input.column.
560 * Contains the source code of the broken file. PostCSS will use the
561 * input source map to detect the original error location. If you wrote
562 * a Sass file, then compiled it to CSS and parsed it with PostCSS,
563 * PostCSS will show the original position in the Sass file. If you need
564 * the position in the PostCSS input (e.g., to debug the previous
565 * compiler), use error.input.source.
569 export class PreviousMap {
573 private consumerCache;
576 constructor(css: any, opts: any);
578 withContent(): boolean;
579 startWith(string: any, start: any): boolean;
580 loadAnnotation(css: any): void;
581 decodeInline(text: any): any;
582 loadMap(file: any, prev: any): any;
583 isMap(map: any): boolean;
586 * Represents the source CSS.
590 * The absolute path to the CSS source file defined with the "from" option.
594 * The unique ID of the CSS source. Used if "from" option is not provided
595 * (because PostCSS does not know the file path).
599 * The CSS source identifier. Contains input.file if the user set the
600 * "from" option, or input.id if they did not.
604 * Represents the input source map passed from a compilation step before
605 * PostCSS (e.g., from the Sass compiler).
609 * Reads the input source map.
610 * @returns A symbol position in the input source (e.g., in a Sass file
611 * that was compiled to CSS before being passed to PostCSS):
613 origin(line: number, column: number): InputOrigin;
617 * Returns a string representing the node's type. Possible values are
618 * root, atrule, rule, decl or comment.
622 * Returns the node's parent node.
626 * Returns the input source of the node. The property is used in source
627 * map generation. If you create a node manually
628 * (e.g., with postcss.decl() ), that node will not have a source
629 * property and will be absent from the source map. For this reason, the
630 * plugin developer should consider cloning nodes to create new ones
631 * (in which case the new node's source will reference the original,
632 * cloned node) or setting the source property manually.
636 * Contains information to generate byte-to-byte equal node string as it
637 * was in origin input.
641 * @returns A CSS string representing the node.
645 * This method produces very useful error messages. If present, an input
646 * source map will be used to get the original position of the source, even
647 * from a previous compilation step (e.g., from Sass compilation).
648 * @returns The original position of the node in the source, showing line
649 * and column numbers and also a small excerpt to facilitate debugging.
655 message: string, options?: NodeErrorOptions): CssSyntaxError;
657 * Creates an instance of Warning and adds it to messages. This method is
658 * provided as a convenience wrapper for Result#warn.
659 * Note that `opts.node` is automatically passed to Result#warn for you.
660 * @param result The result that will receive the warning.
661 * @param text Warning message. It will be used in the `text` property of
662 * the message object.
663 * @param opts Properties to assign to the message object.
665 warn(result: Result, text: string, opts?: WarningOptions): void;
667 * @returns The next child of the node's parent; or, returns undefined if
668 * the current node is the last child.
672 * @returns The previous child of the node's parent; or, returns undefined
673 * if the current node is the first child.
677 * @returns The Root instance of the node's tree.
681 * Removes the node from its parent and cleans the parent property in the
682 * node and its children.
683 * @returns This node for chaining.
687 * Inserts node(s) before the current node and removes the current node.
688 * @returns This node for chaining.
690 replaceWith(...nodes: (Node | Object)[]): this;
692 * @param overrides New properties to override in the clone.
693 * @returns A clone of this node. The node and its (cloned) children will
694 * have a clean parent and code style properties.
696 clone(overrides?: Object): this;
698 * Shortcut to clone the node and insert the resulting cloned node before
700 * @param overrides New Properties to override in the clone.
701 * @returns The cloned node.
703 cloneBefore(overrides?: Object): this;
705 * Shortcut to clone the node and insert the resulting cloned node after
707 * @param overrides New Properties to override in the clone.
708 * @returns The cloned node.
710 cloneAfter(overrides?: Object): this;
712 * Removes the node from its current parent and inserts it at the end of
713 * newParent. This will clean the before and after code style properties
714 * from the node and replace them with the indentation style of newParent.
715 * It will also clean the between property if newParent is in another Root.
716 * @param newParent Where the current node will be moved.
717 * @returns This node for chaining.
719 moveTo(newParent: Container): this;
721 * Removes the node from its current parent and inserts it into a new
722 * parent before otherNode. This will also clean the node's code style
723 * properties just as it would in node.moveTo(newParent).
724 * @param otherNode Will be after the current node after moving.
725 * @returns This node for chaining.
727 moveBefore(otherNode: Node): this;
729 * Removes the node from its current parent and inserts it into a new
730 * parent after otherNode. This will also clean the node's code style
731 * properties just as it would in node.moveTo(newParent).
732 * @param otherNode Will be before the current node after moving.
733 * @returns This node for chaining.
735 moveAfter(otherNode: Node): this;
737 * @param prop Name or code style property.
738 * @param defaultType Name of default value. It can be easily missed if the
739 * value is the same as prop.
740 * @returns A code style property value. If the node is missing the code
741 * style property (because the node was manually built or cloned), PostCSS
742 * will try to autodetect the code style property by looking at other nodes
745 raw(prop: string, defaultType?: string): any;
747 interface NodeNewProps {
752 * The space symbols before the node. It also stores `*` and `_`
753 * symbols before the declaration (IE hack).
757 * The space symbols after the last child of the node to the end of
762 * The symbols between the property and value for declarations,
763 * selector and "{" for rules, last parameter and "{" for at-rules.
767 * True if last child has (optional) semicolon.
771 * The space between the at-rule's name and parameters.
775 * The space symbols between "/*" and comment's text.
779 * The space symbols between comment's text and "*\/".
783 * The content of important statement, if it is not just "!important".
787 interface NodeSource {
790 * The starting position of the node's source.
797 * The ending position of the node's source.
804 interface NodeErrorOptions {
806 * Plugin name that created this error. PostCSS will set it automatically.
810 * A word inside a node's string, that should be highlighted as source
815 * An index inside a node's string that should be highlighted as source
822 * Returns a string representing the node's type. Possible values are
823 * root, atrule, rule, decl or comment.
827 * Returns the node's parent node.
829 parent?: JsonContainer;
831 * Returns the input source of the node. The property is used in source
832 * map generation. If you create a node manually (e.g., with
833 * postcss.decl() ), that node will not have a source property and
834 * will be absent from the source map. For this reason, the plugin
835 * developer should consider cloning nodes to create new ones (in which
836 * case the new node's source will reference the original, cloned node)
837 * or setting the source property manually.
841 * Contains information to generate byte-to-byte equal node string as it
842 * was in origin input.
847 * Containers can store any content. If you write a rule inside a rule,
848 * PostCSS will parse it.
850 interface Container extends Node {
852 * Returns the container's parent node.
856 * Contains the container's children.
860 * @returns The container's first child.
864 * @returns The container's last child.
868 * @param overrides New properties to override in the clone.
869 * @returns A clone of this node. The node and its (cloned) children will
870 * have a clean parent and code style properties.
872 clone(overrides?: Object): this;
874 * @param child Child of the current container.
875 * @returns The child's index within the container's "nodes" array.
877 index(child: Node | number): number;
879 * Determines whether all child nodes satisfy the specified test.
880 * @param callback A function that accepts up to three arguments. The
881 * every method calls the callback function for each node until the
882 * callback returns false, or until the end of the array.
883 * @returns True if the callback returns true for all of the container's
886 every(callback: (node: Node, index: number, nodes: Node[]) => any, thisArg?: any): boolean;
888 * Determines whether the specified callback returns true for any child node.
889 * @param callback A function that accepts up to three arguments. The some
890 * method calls the callback for each node until the callback returns true,
891 * or until the end of the array.
892 * @param thisArg An object to which the this keyword can refer in the
893 * callback function. If thisArg is omitted, undefined is used as the
895 * @returns True if callback returns true for (at least) one of the
896 * container's children.
898 some(callback: (node: Node, index: number, nodes: Node[]) => boolean, thisArg?: any): boolean;
900 * Iterates through the container's immediate children, calling the
901 * callback function for each child. If you need to recursively iterate
902 * through all the container's descendant nodes, use container.walk().
903 * Unlike the for {} -cycle or Array#forEach() this iterator is safe if
904 * you are mutating the array of child nodes during iteration.
905 * @param callback Iterator. Returning false will break iteration. Safe
906 * if you are mutating the array of child nodes during iteration. PostCSS
907 * will adjust the current index to match the mutations.
908 * @returns False if the callback returns false during iteration.
910 each(callback: (node: Node, index: number) => any): boolean | void;
912 * Traverses the container's descendant nodes, calling `callback` for each
913 * node. Like container.each(), this method is safe to use if you are
914 * mutating arrays during iteration. If you only need to iterate through
915 * the container's immediate children, use container.each().
916 * @param callback Iterator.
918 walk(callback: (node: Node, index: number) => any): boolean | void;
920 * Traverses the container's descendant nodes, calling `callback` for each
921 * declaration. Like container.each(), this method is safe to use if you
922 * are mutating arrays during iteration.
923 * @param propFilter Filters declarations by property name. Only those
924 * declarations whose property matches propFilter will be iterated over.
925 * @param callback Called for each declaration node within the container.
927 walkDecls(propFilter: string | RegExp, callback?: (decl: Declaration, index: number) => any): boolean | void;
928 walkDecls(callback: (decl: Declaration, index: number) => any): boolean | void;
930 * Traverses the container's descendant nodes, calling `callback` for each
931 * at-rule. Like container.each(), this method is safe to use if you are
932 * mutating arrays during iteration.
933 * @param nameFilter Filters at-rules by name. If provided, iteration
934 * will only happen over at-rules that have matching names.
935 * @param callback Iterator called for each at-rule node within the
938 walkAtRules(nameFilter: string | RegExp, callback: (atRule: AtRule, index: number) => any): boolean | void;
939 walkAtRules(callback: (atRule: AtRule, index: number) => any): boolean | void;
941 * Traverses the container's descendant nodes, calling `callback` for each
942 * rule. Like container.each(), this method is safe to use if you are
943 * mutating arrays during iteration.
944 * @param selectorFilter Filters rules by selector. If provided,
945 * iteration will only happen over rules that have matching names.
946 * @param callback Iterator called for each rule node within the
949 walkRules(selectorFilter: string | RegExp, callback: (atRule: Rule, index: number) => any): boolean | void;
950 walkRules(callback: (atRule: Rule, index: number) => any): boolean | void;
951 walkRules(selectorFilter: any, callback?: (atRule: Rule, index: number) => any): boolean | void;
953 * Traverses the container's descendant nodes, calling `callback` for each
954 * comment. Like container.each(), this method is safe to use if you are
955 * mutating arrays during iteration.
956 * @param callback Iterator called for each comment node within the container.
958 walkComments(callback: (comment: Comment, indexed: number) => any): void | boolean;
960 * Passes all declaration values within the container that match pattern
961 * through the callback, replacing those values with the returned result of
962 * callback. This method is useful if you are using a custom unit or
963 * function and need to iterate through all values.
964 * @param pattern Pattern that we need to replace.
965 * @param options Options to speed up the search.
966 * @param callbackOrReplaceValue String to replace pattern or callback
967 * that will return a new value. The callback will receive the same
968 * arguments as those passed to a function parameter of String#replace.
970 replaceValues(pattern: string | RegExp, options: {
972 * Property names. The method will only search for values that match
973 * regexp within declarations of listed properties.
977 * Used to narrow down values and speed up the regexp search. Searching
978 * every single value with a regexp can be slow. If you pass a fast
979 * string, PostCSS will first check whether the value contains the fast
980 * string; and only if it does will PostCSS check that value against
981 * regexp. For example, instead of just checking for /\d+rem/ on all
982 * values, set fast: 'rem' to first check whether a value has the rem
983 * unit, and only if it does perform the regexp check.
986 }, callbackOrReplaceValue: string | {
987 (substring: string, ...args: any[]): string;
989 replaceValues(pattern: string | RegExp, callbackOrReplaceValue: string | {
990 (substring: string, ...args: any[]): string;
993 * Inserts new nodes to the beginning of the container.
994 * Because each node class is identifiable by unique properties, use the
995 * following shortcuts to create nodes in insert methods:
996 * root.prepend({ name: '@charset', params: '"UTF-8"' }); // at-rule
997 * root.prepend({ selector: 'a' }); // rule
998 * rule.prepend({ prop: 'color', value: 'black' }); // declaration
999 * rule.prepend({ text: 'Comment' }) // comment
1000 * A string containing the CSS of the new element can also be used. This
1001 * approach is slower than the above shortcuts.
1002 * root.prepend('a {}');
1003 * root.first.prepend('color: black; z-index: 1');
1004 * @param nodes New nodes.
1005 * @returns This container for chaining.
1007 prepend(...nodes: (Node | Object | string)[]): this;
1009 * Inserts new nodes to the end of the container.
1010 * Because each node class is identifiable by unique properties, use the
1011 * following shortcuts to create nodes in insert methods:
1012 * root.append({ name: '@charset', params: '"UTF-8"' }); // at-rule
1013 * root.append({ selector: 'a' }); // rule
1014 * rule.append({ prop: 'color', value: 'black' }); // declaration
1015 * rule.append({ text: 'Comment' }) // comment
1016 * A string containing the CSS of the new element can also be used. This
1017 * approach is slower than the above shortcuts.
1018 * root.append('a {}');
1019 * root.first.append('color: black; z-index: 1');
1020 * @param nodes New nodes.
1021 * @returns This container for chaining.
1023 append(...nodes: (Node | Object | string)[]): this;
1025 * Insert newNode before oldNode within the container.
1026 * @param oldNode Child or child's index.
1027 * @returns This container for chaining.
1029 insertBefore(oldNode: Node | number, newNode: Node | Object | string): this;
1031 * Insert newNode after oldNode within the container.
1032 * @param oldNode Child or child's index.
1033 * @returns This container for chaining.
1035 insertAfter(oldNode: Node | number, newNode: Node | Object | string): this;
1037 * Removes the container from its parent and cleans the parent property in the
1038 * container and its children.
1039 * @returns This container for chaining.
1043 * Removes child from the container and cleans the parent properties
1044 * from the node and its children.
1045 * @param child Child or child's index.
1046 * @returns This container for chaining.
1048 removeChild(child: Node | number): this;
1050 * Removes all children from the container and cleans their parent
1052 * @returns This container for chaining.
1056 interface ContainerNewProps extends NodeNewProps {
1058 * Contains the container's children.
1061 raws?: ContainerRaws;
1063 interface ContainerRaws extends NodeRaws {
1066 interface JsonContainer extends JsonNode {
1068 * Contains the container's children.
1072 * @returns The container's first child.
1076 * @returns The container's last child.
1081 * Represents a CSS file and contains all its parsed nodes.
1083 interface Root extends Container {
1085 * Inherited from Container. Should always be undefined for a Root node.
1089 * @param overrides New properties to override in the clone.
1090 * @returns A clone of this node. The node and its (cloned) children will
1091 * have a clean parent and code style properties.
1093 clone(overrides?: Object): this;
1095 * @returns A Result instance representing the root's CSS.
1097 toResult(options?: {
1099 * The path where you'll put the output CSS file. You should always
1100 * set "to" to generate correct source maps.
1103 map?: SourceMapOptions;
1106 * Deprecated. Use Root#removeChild.
1108 remove(child?: Node | number): this;
1110 * Removes child from the root node, and the parent properties of node and
1112 * @param child Child or child's index.
1113 * @returns This root node for chaining.
1115 removeChild(child: Node | number): this;
1117 interface RootNewProps extends ContainerNewProps {
1119 interface JsonRoot extends JsonContainer {
1122 * Represents an at-rule. If it's followed in the CSS by a {} block, this
1123 * node will have a nodes property representing its children.
1125 interface AtRule extends Container {
1127 * The identifier that immediately follows the @.
1131 * These are the values that follow the at-rule's name, but precede any {}
1132 * block. The spec refers to this area as the at-rule's "prelude".
1136 * @param overrides New properties to override in the clone.
1137 * @returns A clone of this node. The node and its (cloned) children will
1138 * have a clean parent and code style properties.
1140 clone(overrides?: Object): this;
1142 interface AtRuleNewProps extends ContainerNewProps {
1144 * The identifier that immediately follows the @.
1148 * These are the values that follow the at-rule's name, but precede any {}
1149 * block. The spec refers to this area as the at-rule's "prelude".
1151 params?: string | number;
1154 interface AtRuleRaws extends NodeRaws {
1157 interface JsonAtRule extends JsonContainer {
1159 * The identifier that immediately follows the @.
1163 * These are the values that follow the at-rule's name, but precede any {}
1164 * block. The spec refers to this area as the at-rule's "prelude".
1169 * Represents a CSS rule: a selector followed by a declaration block.
1171 interface Rule extends Container {
1173 * Returns the rule's parent node.
1177 * The rule's full selector. If there are multiple comma-separated selectors,
1178 * the entire group will be included.
1182 * An array containing the rule's individual selectors.
1183 * Groups of selectors are split at commas.
1185 selectors?: string[];
1187 * @param overrides New properties to override in the clone.
1188 * @returns A clone of this node. The node and its (cloned) children will
1189 * have a clean parent and code style properties.
1191 clone(overrides?: Object): this;
1193 interface RuleNewProps extends ContainerNewProps {
1195 * The rule's full selector. If there are multiple comma-separated selectors,
1196 * the entire group will be included.
1200 * An array containing the rule's individual selectors. Groups of selectors
1201 * are split at commas.
1203 selectors?: string[];
1206 interface RuleRaws extends ContainerRaws {
1208 * The rule's full selector. If there are multiple comma-separated selectors,
1209 * the entire group will be included.
1213 interface JsonRule extends JsonContainer {
1215 * The rule's full selector. If there are multiple comma-separated selectors,
1216 * the entire group will be included.
1220 * An array containing the rule's individual selectors.
1221 * Groups of selectors are split at commas.
1223 selectors?: string[];
1226 * Represents a CSS declaration.
1228 interface Declaration extends Node {
1230 * The declaration's property name.
1234 * The declaration's value. This value will be cleaned of comments. If the
1235 * source value contained comments, those comments will be available in the
1236 * _value.raws property. If you have not changed the value, the result of
1237 * decl.toString() will include the original raws value (comments and all).
1241 * True if the declaration has an !important annotation.
1245 * @param overrides New properties to override in the clone.
1246 * @returns A clone of this node. The node and its (cloned) children will
1247 * have a clean parent and code style properties.
1249 clone(overrides?: Object): this;
1251 interface DeclarationNewProps {
1253 * The declaration's property name.
1257 * The declaration's value. This value will be cleaned of comments. If the
1258 * source value contained comments, those comments will be available in the
1259 * _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).
1263 raws?: DeclarationRaws;
1265 interface DeclarationRaws extends NodeRaws {
1267 * The declaration's value. This value will be cleaned of comments.
1268 * If the source value contained comments, those comments will be
1269 * available in the _value.raws property. If you have not changed the value, the result of
1270 * decl.toString() will include the original raws value (comments and all).
1274 interface JsonDeclaration extends JsonNode {
1276 * True if the declaration has an !important annotation.
1278 important?: boolean;
1281 * Represents a comment between declarations or statements (rule and at-rules).
1282 * Comments inside selectors, at-rule parameters, or declaration values will
1283 * be stored in the Node#raws properties.
1285 interface Comment extends Node {
1287 * The comment's text.
1291 * @param overrides New properties to override in the clone.
1292 * @returns A clone of this node. The node and its (cloned) children will
1293 * have a clean parent and code style properties.
1295 clone(overrides?: Object): this;
1297 interface CommentNewProps {
1299 * The comment's text.
1303 interface JsonComment extends JsonNode {