1 import PreviousMap from './previous-map';
2 import Stringifier from './stringifier';
3 import _vendor from './vendor';
4 import _list from './list';
6 * @param plugins Can also be included with the Processor#use method.
7 * @returns A processor that will apply plugins as CSS processors.
9 declare function postcss(plugins?: (typeof postcss.acceptedPlugin)[]): postcss.Processor;
10 declare function postcss(...plugins: (typeof postcss.acceptedPlugin)[]): postcss.Processor;
11 declare module postcss {
12 var acceptedPlugin: Plugin<any> | Transformer | {
13 postcss: TransformCallback | Processor;
16 * Creates a PostCSS plugin with a standard API.
17 * @param name Plugin name. Same as in name property in package.json. It will
18 * be saved in plugin.postcssPlugin property.
19 * @param initializer Will receive plugin options and should return functions
20 * to modify nodes in input CSS.
22 function plugin<T>(name: string, initializer: PluginInitializer<T>): Plugin<T>;
23 interface Plugin<T> extends Transformer {
24 (opts?: T): Transformer;
26 process: (css: string | {
28 } | Result, opts?: any) => LazyResult;
30 interface Transformer extends TransformCallback {
31 postcssPlugin?: string;
32 postcssVersion?: string;
34 interface TransformCallback {
36 * @returns Asynchronous plugins should return a promise.
38 (root: Root, result?: Result): void | Function | any;
40 interface PluginInitializer<T> {
41 (pluginOptions?: T): Transformer;
44 * Contains the Vendor module, which contains helpers for working with
47 var vendor: typeof _vendor;
49 * Default function to convert a node tree into a CSS string.
51 function stringify(node: Node, builder: Stringifier.Builder): void;
54 * @param css The CSS to parse.
56 * @returns {} A new Root node, which contains the source CSS nodes.
58 function parse(css: string | {
60 } | LazyResult | Result, options?: {
62 map?: postcss.SourceMapOptions;
65 * Contains the List module, which contains helpers for safely splitting
66 * lists of CSS values, preserving parentheses and quotes.
68 var list: typeof _list;
70 * Creates a new Comment node.
71 * @param defaults Properties for the new Comment node.
72 * @returns The new node.
74 function comment(defaults?: CommentNewProps): Comment;
76 * Creates a new AtRule node.
77 * @param defaults Properties for the new AtRule node.
78 * @returns The new node.
80 function atRule(defaults?: AtRuleNewProps): AtRule;
82 * Creates a new Declaration node.
83 * @param defaults Properties for the new Declaration node.
84 * @returns The new node.
86 function decl(defaults?: DeclarationNewProps): Declaration;
88 * Creates a new Rule node.
89 * @param defaults Properties for the new Rule node.
90 * @returns The new node.
92 function rule(defaults?: RuleNewProps): Rule;
94 * Creates a new Root node.
95 * @param defaults Properties for the new Root node.
96 * @returns The new node.
98 function root(defaults?: Object): Root;
99 interface SourceMapOptions {
101 * Indicates that the source map should be embedded in the output CSS as a
102 * Base64-encoded comment. By default, it is true. But if all previous maps
103 * are external, not inline, PostCSS will not embed the map even if you do
104 * not set this option.
106 * If you have an inline source map, the result.map property will be empty,
107 * as the source map will be contained within the text of result.css.
111 * Source map content from a previous processing step (e.g., Sass compilation).
112 * PostCSS will try to read the previous source map automatically (based on comments
113 * within the source CSS), but you can use this option to identify it manually.
114 * If desired, you can omit the previous map with prev: false.
118 * Indicates that PostCSS should set the origin content (e.g., Sass source)
119 * of the source map. By default, it is true. But if all previous maps do not
120 * contain sources content, PostCSS will also leave it out even if you do not set
123 sourcesContent?: boolean;
125 * Indicates that PostCSS should add annotation comments to the CSS. By default,
126 * PostCSS will always add a comment with a path to the source map. PostCSS will
127 * not add annotations to CSS files that do not contain any comments.
129 * By default, PostCSS presumes that you want to save the source map as
130 * opts.to + '.map' and will use this path in the annotation comment. A different
131 * path can be set by providing a string value for annotation.
133 * If you have set inline: true, annotation cannot be disabled.
135 annotation?: boolean | string;
137 * If true, PostCSS will try to correct any syntax errors that it finds in the CSS.
138 * This is useful for legacy code filled with hacks. Another use-case is interactive
139 * tools with live input — for example, the Autoprefixer demo.
144 * A Processor instance contains plugins to process CSS. Create one
145 * Processor instance, initialize its plugins, and then use that instance
146 * on numerous CSS files.
148 interface Processor {
150 * Adds a plugin to be used as a CSS processor. Plugins can also be
151 * added by passing them as arguments when creating a postcss instance.
153 use(plugin: typeof acceptedPlugin): Processor;
155 * Parses source CSS. Because some plugins can be asynchronous it doesn't
156 * make any transformations. Transformations will be applied in LazyResult's
158 * @param css Input CSS or any object with toString() method, like a file
159 * stream. If a Result instance is passed the processor will take the
160 * existing Root parser from it.
162 process(css: string | {
164 } | Result, options?: ProcessOptions): LazyResult;
166 * Contains plugins added to this processor.
168 plugins: Plugin<any>[];
170 * Contains the current version of PostCSS (e.g., "4.0.5").
174 interface ProcessOptions extends Syntax {
176 * The path of the CSS source file. You should always set from, because it is
177 * used in source map generation and syntax error messages.
181 * The path where you'll put the output CSS file. You should always set it
182 * to generate correct source maps.
187 * Enable Safe Mode, in which PostCSS will try to fix CSS syntax errors.
190 map?: postcss.SourceMapOptions;
192 * Function to generate AST by string.
194 parser?: Parse | Syntax;
196 * Class to generate string by AST.
198 stringifier?: Stringify | Syntax;
202 * Function to generate AST by string.
206 * Class to generate string by AST.
208 stringify?: Stringify;
211 (css?: string, opts?: postcss.SourceMapOptions): Root;
213 interface Stringify {
214 (node?: postcss.Node, builder?: any): postcss.Result | void;
217 * A promise proxy for the result of PostCSS transformations.
219 interface LazyResult {
221 * Processes input CSS through synchronous and asynchronous plugins.
222 * @param onRejected Called if any plugin throws an error.
224 then(onFulfilled: (result: Result) => void, onRejected?: (error: Error) => void): Function | any;
226 * Processes input CSS through synchronous and asynchronous plugins.
227 * @param onRejected Called if any plugin throws an error.
229 catch(onRejected: (error: Error) => void): Function | any;
231 * Alias for css property.
235 * Processes input CSS through synchronous plugins and converts Root to
236 * CSS string. This property will only work with synchronous plugins. If
237 * the processor contains any asynchronous plugins it will throw an error.
238 * In this case, you should use LazyResult#then() instead.
239 * @returns Result#css.
243 * Alias for css property to use when syntaxes generate non-CSS output.
247 * Processes input CSS through synchronous plugins. This property will
248 * work only with synchronous plugins. If processor contains any
249 * asynchronous plugins it will throw an error. You should use
250 * LazyResult#then() instead.
254 * Processes input CSS through synchronous plugins. This property will work
255 * only with synchronous plugins. If processor contains any asynchronous
256 * plugins it will throw an error. You should use LazyResult#then() instead.
260 * Processes input CSS through synchronous plugins and calls Result#warnings().
261 * This property will only work with synchronous plugins. If the processor
262 * contains any asynchronous plugins it will throw an error. In this case,
263 * you should use LazyResult#then() instead.
265 warnings(): ResultMessage[];
267 * Processes input CSS through synchronous plugins. This property will work
268 * only with synchronous plugins. If processor contains any asynchronous
269 * plugins it will throw an error. You should use LazyResult#then() instead.
271 messages: ResultMessage[];
273 * @returns A processor used for CSS transformations.
275 processor: Processor;
277 * @returns Options from the Processor#process(css, opts) call that produced
278 * this Result instance.
283 * Provides the result of the PostCSS transformations.
287 * Alias for css property.
291 * Creates an instance of Warning and adds it to messages.
292 * @param message Used in the text property of the message object.
293 * @param options Properties for Message object.
295 warn(message: string, options?: WarningOptions): void;
297 * @returns Warnings from plugins, filtered from messages.
299 warnings(): ResultMessage[];
301 * A CSS string representing this Result's Root instance.
305 * Alias for css property to use with syntaxes that generate non-CSS output.
309 * An instance of the SourceMapGenerator class from the source-map library,
310 * representing changes to the Result's Root instance.
311 * This property will have a value only if the user does not want an inline
312 * source map. By default, PostCSS generates inline source maps, written
313 * directly into the processed CSS. The map property will be empty by default.
314 * An external source map will be generated — and assigned to map — only if
315 * the user has set the map.inline option to false, or if PostCSS was passed
316 * an external input source map.
320 * Contains the Root node after all transformations.
324 * Contains messages from plugins (e.g., warnings or custom messages).
325 * Add a warning using Result#warn() and get all warnings
326 * using the Result#warnings() method.
328 messages: ResultMessage[];
330 * The Processor instance used for this transformation.
332 processor: Processor;
334 * Options from the Processor#process(css, opts) or Root#toResult(opts) call
335 * that produced this Result instance.
339 interface ResultOptions extends ProcessOptions {
341 * The CSS node that was the source of the warning.
345 * Name of plugin that created this warning. Result#warn() will fill it
346 * automatically with plugin.postcssPlugin value.
350 interface ResultMap {
352 * Add a single mapping from original source line and column to the generated
353 * source's line and column for this source map being created. The mapping
354 * object should have the following properties:
358 addMapping(mapping: {
368 * The original source file (relative to the sourceRoot).
374 * Set the source content for an original source file.
375 * @param sourceFile The URL of the original source file.
376 * @param sourceContent The content of the source file.
378 setSourceContent(sourceFile: string, sourceContent: string): void;
380 * Applies a SourceMap for a source file to the SourceMap. Each mapping to
381 * the supplied source file is rewritten using the supplied SourceMap.
382 * Note: The resolution for the resulting mappings is the minimium of this
383 * map and the supplied map.
384 * @param sourceMapConsumer The SourceMap to be applied.
385 * @param sourceFile The filename of the source file. If omitted, sourceMapConsumer
386 * file will be used, if it exists. Otherwise an error will be thrown.
387 * @param sourceMapPath The dirname of the path to the SourceMap to be applied.
388 * If relative, it is relative to the SourceMap. This parameter is needed when
389 * the two SourceMaps aren't in the same directory, and the SourceMap to be
390 * applied contains relative source paths. If so, those relative source paths
391 * need to be rewritten relative to the SourceMap.
392 * If omitted, it is assumed that both SourceMaps are in the same directory;
393 * thus, not needing any rewriting (Supplying '.' has the same effect).
395 applySourceMap(sourceMapConsumer: any, sourceFile?: string, sourceMapPath?: string): void;
397 * Renders the source map being generated to JSON.
401 * Renders the source map being generated to a string.
403 toString: () => string;
405 interface ResultMessage {
412 * Represents a plugin warning. It can be created using Result#warn().
416 * @returns Error position, message.
420 * Contains the warning message.
424 * Contains the name of the plugin that created this warning. When you
425 * call Result#warn(), it will fill this property automatically.
429 * The CSS node that caused the warning.
433 * The line in the input file with this warning's source.
437 * Column in the input file with this warning's source.
441 interface WarningOptions extends ResultOptions {
443 * A word inside a node's string that should be highlighted as source
448 * The index inside a node's string that should be highlighted as
454 * The CSS parser throws this error for broken CSS.
456 interface CssSyntaxError extends InputOrigin {
459 * @returns Error position, message and source code of broken part.
463 * @param color Whether arrow should be colored red by terminal color codes.
464 * By default, PostCSS will use process.stdout.isTTY and
465 * process.env.NODE_DISABLE_COLORS.
466 * @returns A few lines of CSS source that caused the error. If CSS has
467 * input source map without sourceContent this method will return an empty
470 showSourceCode(color?: boolean): string;
472 * Contains full error text in the GNU error format.
476 * Contains only the error description.
480 * Contains the PostCSS plugin name if the error didn't come from the
486 interface InputOrigin {
488 * If parser's from option is set, contains the absolute path to the
489 * broken file. PostCSS will use the input source map to detect the
490 * original error location. If you wrote a Sass file, then compiled it
491 * to CSS and parsed it with PostCSS, PostCSS will show the original
492 * position in the Sass file. If you need the position in the PostCSS
493 * input (e.g., to debug the previous compiler), use error.input.file.
497 * Contains the source line of the error. PostCSS will use the input
498 * source map to detect the original error location. If you wrote a Sass
499 * file, then compiled it to CSS and parsed it with PostCSS, PostCSS
500 * will show the original position in the Sass file. If you need the
501 * position in the PostCSS input (e.g., to debug the previous
502 * compiler), use error.input.line.
506 * Contains the source column of the error. PostCSS will use input
507 * source map to detect the original error location. If you wrote a
508 * Sass file, then compiled it to CSS and parsed it with PostCSS,
509 * PostCSS will show the original position in the Sass file. If you
510 * need the position in the PostCSS input (e.g., to debug the
511 * previous compiler), use error.input.column.
515 * Contains the source code of the broken file. PostCSS will use the
516 * input source map to detect the original error location. If you wrote
517 * a Sass file, then compiled it to CSS and parsed it with PostCSS,
518 * PostCSS will show the original position in the Sass file. If you need
519 * the position in the PostCSS input (e.g., to debug the previous
520 * compiler), use error.input.source.
525 * Represents the source CSS.
529 * The absolute path to the CSS source file defined with the "from" option.
533 * The unique ID of the CSS source. Used if "from" option is not provided
534 * (because PostCSS does not know the file path).
538 * The CSS source identifier. Contains input.file if the user set the
539 * "from" option, or input.id if they did not.
543 * Represents the input source map passed from a compilation step before
544 * PostCSS (e.g., from the Sass compiler).
548 * Reads the input source map.
549 * @returns A symbol position in the input source (e.g., in a Sass file
550 * that was compiled to CSS before being passed to PostCSS):
552 origin(line: number, column: number): InputOrigin;
556 * Returns a string representing the node's type. Possible values are
557 * root, atrule, rule, decl or comment.
561 * Returns the node's parent node.
565 * Returns the input source of the node. The property is used in source
566 * map generation. If you create a node manually
567 * (e.g., with postcss.decl() ), that node will not have a source
568 * property and will be absent from the source map. For this reason, the
569 * plugin developer should consider cloning nodes to create new ones
570 * (in which case the new node's source will reference the original,
571 * cloned node) or setting the source property manually.
575 * Contains information to generate byte-to-byte equal node string as it
576 * was in origin input.
580 * @returns A CSS string representing the node.
584 * This method produces very useful error messages. If present, an input
585 * source map will be used to get the original position of the source, even
586 * from a previous compilation step (e.g., from Sass compilation).
587 * @returns The original position of the node in the source, showing line
588 * and column numbers and also a small excerpt to facilitate debugging.
594 message: string, options?: NodeErrorOptions): CssSyntaxError;
596 * Creates an instance of Warning and adds it to messages. This method is
597 * provided as a convenience wrapper for Result#warn.
598 * Note that `opts.node` is automatically passed to Result#warn for you.
599 * @param result The result that will receive the warning.
600 * @param text Warning message. It will be used in the `text` property of
601 * the message object.
602 * @param opts Properties to assign to the message object.
604 warn(result: Result, text: string, opts?: WarningOptions): void;
606 * @returns The next child of the node's parent; or, returns undefined if
607 * the current node is the last child.
611 * @returns The previous child of the node's parent; or, returns undefined
612 * if the current node is the first child.
616 * @returns The Root instance of the node's tree.
620 * Removes the node from its parent and cleans the parent property in the
621 * node and its children.
622 * @returns This node for chaining.
626 * Inserts node(s) before the current node and removes the current node.
627 * @returns This node for chaining.
629 replaceWith(...nodes: (Node | Object)[]): Node;
631 * @param overrides New properties to override in the clone.
632 * @returns A clone of this node. The node and its (cloned) children will
633 * have a clean parent and code style properties.
635 clone(overrides?: Object): Node;
637 * Shortcut to clone the node and insert the resulting cloned node before
639 * @param overrides New Properties to override in the clone.
640 * @returns The cloned node.
642 cloneBefore(overrides?: Object): Node;
644 * Shortcut to clone the node and insert the resulting cloned node after
646 * @param overrides New Properties to override in the clone.
647 * @returns The cloned node.
649 cloneAfter(overrides?: Object): Node;
651 * Removes the node from its current parent and inserts it at the end of
652 * newParent. This will clean the before and after code style properties
653 * from the node and replace them with the indentation style of newParent.
654 * It will also clean the between property if newParent is in another Root.
655 * @param newParent Where the current node will be moved.
656 * @returns This node for chaining.
658 moveTo(newParent: Container): Node;
660 * Removes the node from its current parent and inserts it into a new
661 * parent before otherNode. This will also clean the node's code style
662 * properties just as it would in node.moveTo(newParent).
663 * @param otherNode Will be after the current node after moving.
664 * @returns This node for chaining.
666 moveBefore(otherNode: Node): Node;
668 * Removes the node from its current parent and inserts it into a new
669 * parent after otherNode. This will also clean the node's code style
670 * properties just as it would in node.moveTo(newParent).
671 * @param otherNode Will be before the current node after moving.
672 * @returns This node for chaining.
674 moveAfter(otherNode: Node): Node;
676 * @param prop Name or code style property.
677 * @param defaultType Name of default value. It can be easily missed if the
678 * value is the same as prop.
679 * @returns A code style property value. If the node is missing the code
680 * style property (because the node was manually built or cloned), PostCSS
681 * will try to autodetect the code style property by looking at other nodes
684 raw(prop: string, defaultType?: string): any;
686 interface NodeNewProps {
691 * The space symbols before the node. It also stores `*` and `_`
692 * symbols before the declaration (IE hack).
696 * The space symbols after the last child of the node to the end of
701 * The symbols between the property and value for declarations,
702 * selector and "{" for rules, last parameter and "{" for at-rules.
706 * True if last child has (optional) semicolon.
710 * The space between the at-rule's name and parameters.
714 * The space symbols between "/*" and comment's text.
718 * The space symbols between comment's text and "*\/".
722 * The content of important statement, if it is not just "!important".
726 interface NodeSource {
729 * The starting position of the node's source.
736 * The ending position of the node's source.
743 interface NodeErrorOptions {
745 * Plugin name that created this error. PostCSS will set it automatically.
749 * A word inside a node's string, that should be highlighted as source
754 * An index inside a node's string that should be highlighted as source
761 * Returns a string representing the node's type. Possible values are
762 * root, atrule, rule, decl or comment.
766 * Returns the node's parent node.
768 parent?: JsonContainer;
770 * Returns the input source of the node. The property is used in source
771 * map generation. If you create a node manually (e.g., with
772 * postcss.decl() ), that node will not have a source property and
773 * will be absent from the source map. For this reason, the plugin
774 * developer should consider cloning nodes to create new ones (in which
775 * case the new node's source will reference the original, cloned node)
776 * or setting the source property manually.
780 * Contains information to generate byte-to-byte equal node string as it
781 * was in origin input.
786 * Containers can store any content. If you write a rule inside a rule,
787 * PostCSS will parse it.
789 interface Container extends Node {
791 * Returns the container's parent node.
795 * Contains the container's children.
799 * @returns The container's first child.
803 * @returns The container's last child.
807 * @param overrides New properties to override in the clone.
808 * @returns A clone of this node. The node and its (cloned) children will
809 * have a clean parent and code style properties.
811 clone(overrides?: Object): Container;
813 * @param child Child of the current container.
814 * @returns The child's index within the container's "nodes" array.
816 index(child: Node | number): number;
818 * Determines whether all child nodes satisfy the specified test.
819 * @param callback A function that accepts up to three arguments. The
820 * every method calls the callback function for each node until the
821 * callback returns false, or until the end of the array.
822 * @returns True if the callback returns true for all of the container's
825 every(callback: (node: Node, index: number, nodes: Node[]) => any, thisArg?: any): boolean;
827 * Determines whether the specified callback returns true for any child node.
828 * @param callback A function that accepts up to three arguments. The some
829 * method calls the callback for each node until the callback returns true,
830 * or until the end of the array.
831 * @param thisArg An object to which the this keyword can refer in the
832 * callback function. If thisArg is omitted, undefined is used as the
834 * @returns True if callback returns true for (at least) one of the
835 * container's children.
837 some(callback: (node: Node, index: number, nodes: Node[]) => boolean, thisArg?: any): boolean;
839 * Iterates through the container's immediate children, calling the
840 * callback function for each child. If you need to recursively iterate
841 * through all the container's descendant nodes, use container.walk().
842 * Unlike the for {} -cycle or Array#forEach() this iterator is safe if
843 * you are mutating the array of child nodes during iteration.
844 * @param callback Iterator. Returning false will break iteration. Safe
845 * if you are mutating the array of child nodes during iteration. PostCSS
846 * will adjust the current index to match the mutations.
847 * @returns False if the callback returns false during iteration.
849 each(callback: (node: Node, index: number) => any): boolean | void;
851 * Traverses the container's descendant nodes, calling `callback` for each
852 * node. Like container.each(), this method is safe to use if you are
853 * mutating arrays during iteration. If you only need to iterate through
854 * the container's immediate children, use container.each().
855 * @param callback Iterator.
857 walk(callback: (node: Node, index: number) => any): boolean | void;
859 * Traverses the container's descendant nodes, calling `callback` for each
860 * declaration. Like container.each(), this method is safe to use if you
861 * are mutating arrays during iteration.
862 * @param propFilter Filters declarations by property name. Only those
863 * declarations whose property matches propFilter will be iterated over.
864 * @param callback Called for each declaration node within the container.
866 walkDecls(propFilter: string | RegExp, callback?: (decl: Declaration, index: number) => any): boolean | void;
867 walkDecls(callback: (decl: Declaration, index: number) => any): boolean | void;
869 * Traverses the container's descendant nodes, calling `callback` for each
870 * at-rule. Like container.each(), this method is safe to use if you are
871 * mutating arrays during iteration.
872 * @param nameFilter Filters at-rules by name. If provided, iteration
873 * will only happen over at-rules that have matching names.
874 * @param callback Iterator called for each at-rule node within the
877 walkAtRules(nameFilter: string | RegExp, callback: (atRule: AtRule, index: number) => any): boolean | void;
878 walkAtRules(callback: (atRule: AtRule, index: number) => any): boolean | void;
880 * Traverses the container's descendant nodes, calling `callback` for each
881 * rule. Like container.each(), this method is safe to use if you are
882 * mutating arrays during iteration.
883 * @param selectorFilter Filters rules by selector. If provided,
884 * iteration will only happen over rules that have matching names.
885 * @param callback Iterator called for each rule node within the
888 walkRules(selectorFilter: string | RegExp, callback: (atRule: Rule, index: number) => any): boolean | void;
889 walkRules(callback: (atRule: Rule, index: number) => any): boolean | void;
890 walkRules(selectorFilter: any, callback?: (atRule: Rule, index: number) => any): boolean | void;
892 * Traverses the container's descendant nodes, calling `callback` for each
893 * comment. Like container.each(), this method is safe to use if you are
894 * mutating arrays during iteration.
895 * @param callback Iterator called for each comment node within the container.
897 walkComments(callback: (comment: Comment, indexed: number) => any): void | boolean;
899 * Passes all declaration values within the container that match pattern
900 * through the callback, replacing those values with the returned result of
901 * callback. This method is useful if you are using a custom unit or
902 * function and need to iterate through all values.
903 * @param pattern Pattern that we need to replace.
904 * @param options Options to speed up the search.
905 * @param callbackOrReplaceValue String to replace pattern or callback
906 * that will return a new value. The callback will receive the same
907 * arguments as those passed to a function parameter of String#replace.
909 replaceValues(pattern: string | RegExp, options: {
911 * Property names. The method will only search for values that match
912 * regexp within declarations of listed properties.
916 * Used to narrow down values and speed up the regexp search. Searching
917 * every single value with a regexp can be slow. If you pass a fast
918 * string, PostCSS will first check whether the value contains the fast
919 * string; and only if it does will PostCSS check that value against
920 * regexp. For example, instead of just checking for /\d+rem/ on all
921 * values, set fast: 'rem' to first check whether a value has the rem
922 * unit, and only if it does perform the regexp check.
925 }, callbackOrReplaceValue: string | {
926 (substring: string, ...args: any[]): string;
928 replaceValues(pattern: string | RegExp, callbackOrReplaceValue: string | {
929 (substring: string, ...args: any[]): string;
932 * Inserts new nodes to the beginning of the container.
933 * Because each node class is identifiable by unique properties, use the
934 * following shortcuts to create nodes in insert methods:
935 * root.prepend({ name: '@charset', params: '"UTF-8"' }); // at-rule
936 * root.prepend({ selector: 'a' }); // rule
937 * rule.prepend({ prop: 'color', value: 'black' }); // declaration
938 * rule.prepend({ text: 'Comment' }) // comment
939 * A string containing the CSS of the new element can also be used. This
940 * approach is slower than the above shortcuts.
941 * root.prepend('a {}');
942 * root.first.prepend('color: black; z-index: 1');
943 * @param nodes New nodes.
944 * @returns This container for chaining.
946 prepend(...nodes: (Node | Object | string)[]): Container;
948 * Inserts new nodes to the end of the container.
949 * Because each node class is identifiable by unique properties, use the
950 * following shortcuts to create nodes in insert methods:
951 * root.append({ name: '@charset', params: '"UTF-8"' }); // at-rule
952 * root.append({ selector: 'a' }); // rule
953 * rule.append({ prop: 'color', value: 'black' }); // declaration
954 * rule.append({ text: 'Comment' }) // comment
955 * A string containing the CSS of the new element can also be used. This
956 * approach is slower than the above shortcuts.
957 * root.append('a {}');
958 * root.first.append('color: black; z-index: 1');
959 * @param nodes New nodes.
960 * @returns This container for chaining.
962 append(...nodes: (Node | Object | string)[]): Container;
964 * Insert newNode before oldNode within the container.
965 * @param oldNode Child or child's index.
966 * @returns This container for chaining.
968 insertBefore(oldNode: Node | number, newNode: Node | Object | string): Container;
970 * Insert newNode after oldNode within the container.
971 * @param oldNode Child or child's index.
972 * @returns This container for chaining.
974 insertAfter(oldNode: Node | number, newNode: Node | Object | string): Container;
976 * Removes the container from its parent and cleans the parent property in the
977 * container and its children.
978 * @returns This container for chaining.
982 * Removes child from the container and cleans the parent properties
983 * from the node and its children.
984 * @param child Child or child's index.
985 * @returns This container for chaining.
987 removeChild(child: Node | number): Container;
989 * Removes all children from the container and cleans their parent
991 * @returns This container for chaining.
993 removeAll(): Container;
995 interface ContainerNewProps extends NodeNewProps {
997 * Contains the container's children.
1000 raws?: ContainerRaws;
1002 interface ContainerRaws extends NodeRaws {
1005 interface JsonContainer extends JsonNode {
1007 * Contains the container's children.
1011 * @returns The container's first child.
1015 * @returns The container's last child.
1020 * Represents a CSS file and contains all its parsed nodes.
1022 interface Root extends Container {
1024 * Inherited from Container. Should always be undefined for a Root node.
1028 * @param overrides New properties to override in the clone.
1029 * @returns A clone of this node. The node and its (cloned) children will
1030 * have a clean parent and code style properties.
1032 clone(overrides?: Object): Root;
1034 * @returns A Result instance representing the root's CSS.
1036 toResult(options?: {
1038 * The path where you'll put the output CSS file. You should always
1039 * set "to" to generate correct source maps.
1042 map?: SourceMapOptions;
1045 * Deprecated. Use Root#removeChild.
1047 remove(child?: Node | number): Root;
1049 * Removes child from the root node, and the parent properties of node and
1051 * @param child Child or child's index.
1052 * @returns This root node for chaining.
1054 removeChild(child: Node | number): Root;
1056 interface RootNewProps extends ContainerNewProps {
1058 interface JsonRoot extends JsonContainer {
1061 * Represents an at-rule. If it's followed in the CSS by a {} block, this
1062 * node will have a nodes property representing its children.
1064 interface AtRule extends Container {
1066 * The identifier that immediately follows the @.
1070 * These are the values that follow the at-rule's name, but precede any {}
1071 * block. The spec refers to this area as the at-rule's "prelude".
1075 * @param overrides New properties to override in the clone.
1076 * @returns A clone of this node. The node and its (cloned) children will
1077 * have a clean parent and code style properties.
1079 clone(overrides?: Object): AtRule;
1081 interface AtRuleNewProps extends ContainerNewProps {
1083 * The identifier that immediately follows the @.
1087 * These are the values that follow the at-rule's name, but precede any {}
1088 * block. The spec refers to this area as the at-rule's "prelude".
1090 params?: string | number;
1093 interface AtRuleRaws extends NodeRaws {
1096 interface JsonAtRule extends JsonContainer {
1098 * The identifier that immediately follows the @.
1102 * These are the values that follow the at-rule's name, but precede any {}
1103 * block. The spec refers to this area as the at-rule's "prelude".
1108 * Represents a CSS rule: a selector followed by a declaration block.
1110 interface Rule extends Container {
1112 * Returns the rule's parent node.
1116 * The rule's full selector. If there are multiple comma-separated selectors,
1117 * the entire group will be included.
1121 * An array containing the rule's individual selectors.
1122 * Groups of selectors are split at commas.
1124 selectors?: string[];
1126 * @param overrides New properties to override in the clone.
1127 * @returns A clone of this node. The node and its (cloned) children will
1128 * have a clean parent and code style properties.
1130 clone(overrides?: Object): Rule;
1132 interface RuleNewProps extends ContainerNewProps {
1134 * The rule's full selector. If there are multiple comma-separated selectors,
1135 * the entire group will be included.
1139 * An array containing the rule's individual selectors. Groups of selectors
1140 * are split at commas.
1142 selectors?: string[];
1145 interface RuleRaws extends ContainerRaws {
1147 * The rule's full selector. If there are multiple comma-separated selectors,
1148 * the entire group will be included.
1152 interface JsonRule extends JsonContainer {
1154 * The rule's full selector. If there are multiple comma-separated selectors,
1155 * the entire group will be included.
1159 * An array containing the rule's individual selectors.
1160 * Groups of selectors are split at commas.
1162 selectors?: string[];
1165 * Represents a CSS declaration.
1167 interface Declaration extends Node {
1169 * The declaration's property name.
1173 * The declaration's value. This value will be cleaned of comments. If the
1174 * source value contained comments, those comments will be available in the
1175 * _value.raws property. If you have not changed the value, the result of
1176 * decl.toString() will include the original raws value (comments and all).
1180 * True if the declaration has an !important annotation.
1184 * @param overrides New properties to override in the clone.
1185 * @returns A clone of this node. The node and its (cloned) children will
1186 * have a clean parent and code style properties.
1188 clone(overrides?: Object): Declaration;
1190 interface DeclarationNewProps {
1192 * The declaration's property name.
1196 * The declaration's value. This value will be cleaned of comments. If the
1197 * source value contained comments, those comments will be available in the
1198 * _value.raws property. If you have not changed the value, the result of
1199 * decl.toString() will include the original raws value (comments and all).
1202 raws?: DeclarationRaws;
1204 interface DeclarationRaws extends NodeRaws {
1206 * The declaration's value. This value will be cleaned of comments.
1207 * If the source value contained comments, those comments will be
1208 * available in the _value.raws property. If you have not changed the value, the result of
1209 * decl.toString() will include the original raws value (comments and all).
1213 interface JsonDeclaration extends JsonNode {
1215 * True if the declaration has an !important annotation.
1217 important?: boolean;
1220 * Represents a comment between declarations or statements (rule and at-rules).
1221 * Comments inside selectors, at-rule parameters, or declaration values will
1222 * be stored in the Node#raws properties.
1224 interface Comment extends Node {
1226 * The comment's text.
1230 * @param overrides New properties to override in the clone.
1231 * @returns A clone of this node. The node and its (cloned) children will
1232 * have a clean parent and code style properties.
1234 clone(overrides?: Object): Comment;
1236 interface CommentNewProps {
1238 * The comment's text.
1242 interface JsonComment extends JsonNode {
1245 export default postcss;