UNPKG

45.8 kBTypeScriptView Raw
1import * as mozilla from 'source-map';
2
3/**
4 * @param plugins Can also be included with the Processor#use method.
5 * @returns A processor that will apply plugins as CSS processors.
6 */
7declare function postcss(plugins?: postcss.AcceptedPlugin[]): postcss.Processor;
8declare function postcss(...plugins: postcss.AcceptedPlugin[]): postcss.Processor;
9declare namespace postcss {
10 type AcceptedPlugin = Plugin<any> | Transformer | {
11 postcss: TransformCallback | Processor;
12 } | Processor;
13 /**
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.
19 */
20 function plugin<T>(name: string, initializer: PluginInitializer<T>): Plugin<T>;
21 interface Plugin<T> extends Transformer {
22 (opts?: T): Transformer;
23 postcss: Transformer;
24 process: (css: string | {
25 toString(): string;
26 } | Result, opts?: any) => LazyResult;
27 }
28 interface Transformer extends TransformCallback {
29 postcssPlugin?: string;
30 postcssVersion?: string;
31 }
32 interface TransformCallback {
33 /**
34 * @returns A Promise that resolves when all work is complete. May return
35 * synchronously, but that style of plugin is only meant for debugging and
36 * development. In either case, the resolved or returned value is not used -
37 * the "result" is the output.
38 */
39 (root: Root, result: Result): Promise<any> | any;
40 }
41 interface PluginInitializer<T> {
42 (pluginOptions?: T): Transformer;
43 }
44 /**
45 * Contains helpers for working with vendor prefixes.
46 */
47 export namespace vendor {
48 /**
49 * @returns The vendor prefix extracted from the input string.
50 */
51 function prefix(prop: string): string;
52 /**
53 * @returns The input string stripped of its vendor prefix.
54 */
55 function unprefixed(prop: string): string;
56 }
57 type ParserInput = string | { toString(): string };
58 interface Parser {
59 (css: ParserInput, opts?: Pick<ProcessOptions, 'map' | 'from'>): Root;
60 }
61 interface Builder {
62 (part: string, node?: Node, type?: 'start' | 'end'): void;
63 }
64 interface Stringifier {
65 (node: Node, builder: Builder): void;
66 }
67 /**
68 * Default function to convert a node tree into a CSS string.
69 */
70 const stringify: Stringifier;
71 /**
72 * Parses source CSS.
73 * @param css The CSS to parse.
74 * @param options
75 * @returns {} A new Root node, which contains the source CSS nodes.
76 */
77 const parse: Parser;
78 /**
79 * Contains helpers for safely splitting lists of CSS values, preserving
80 * parentheses and quotes.
81 */
82 export namespace list {
83 /**
84 * Safely splits space-separated values (such as those for background,
85 * border-radius and other shorthand properties).
86 */
87 function space(str: string): string[];
88 /**
89 * Safely splits comma-separated values (such as those for transition-* and
90 * background properties).
91 */
92 function comma(str: string): string[];
93 }
94 /**
95 * Creates a new Comment node.
96 * @param defaults Properties for the new Comment node.
97 * @returns The new node.
98 */
99 function comment(defaults?: CommentNewProps): Comment;
100 /**
101 * Creates a new AtRule node.
102 * @param defaults Properties for the new AtRule node.
103 * @returns The new node.
104 */
105 function atRule(defaults?: AtRuleNewProps): AtRule;
106 /**
107 * Creates a new Declaration node.
108 * @param defaults Properties for the new Declaration node.
109 * @returns The new node.
110 */
111 function decl(defaults?: DeclarationNewProps): Declaration;
112 /**
113 * Creates a new Rule node.
114 * @param defaults Properties for the new Rule node.
115 * @returns The new node.
116 */
117 function rule(defaults?: RuleNewProps): Rule;
118 /**
119 * Creates a new Root node.
120 * @param defaults Properties for the new Root node.
121 * @returns The new node.
122 */
123 function root(defaults?: object): Root;
124 interface SourceMapOptions {
125 /**
126 * Indicates that the source map should be embedded in the output CSS as a
127 * Base64-encoded comment. By default, it is true. But if all previous maps
128 * are external, not inline, PostCSS will not embed the map even if you do
129 * not set this option.
130 *
131 * If you have an inline source map, the result.map property will be empty,
132 * as the source map will be contained within the text of result.css.
133 */
134 inline?: boolean;
135 /**
136 * Source map content from a previous processing step (e.g., Sass compilation).
137 * PostCSS will try to read the previous source map automatically (based on comments
138 * within the source CSS), but you can use this option to identify it manually.
139 * If desired, you can omit the previous map with prev: false.
140 */
141 prev?: any;
142 /**
143 * Indicates that PostCSS should set the origin content (e.g., Sass source)
144 * of the source map. By default, it is true. But if all previous maps do not
145 * contain sources content, PostCSS will also leave it out even if you do not set
146 * this option.
147 */
148 sourcesContent?: boolean;
149 /**
150 * Indicates that PostCSS should add annotation comments to the CSS. By default,
151 * PostCSS will always add a comment with a path to the source map. PostCSS will
152 * not add annotations to CSS files that do not contain any comments.
153 *
154 * By default, PostCSS presumes that you want to save the source map as
155 * opts.to + '.map' and will use this path in the annotation comment. A different
156 * path can be set by providing a string value for annotation.
157 *
158 * If you have set inline: true, annotation cannot be disabled.
159 */
160 annotation?: string | boolean;
161 /**
162 * Override "from" in map's sources.
163 */
164 from?: string;
165 }
166 /**
167 * A Processor instance contains plugins to process CSS. Create one
168 * Processor instance, initialize its plugins, and then use that instance
169 * on numerous CSS files.
170 */
171 interface Processor {
172 /**
173 * Adds a plugin to be used as a CSS processor. Plugins can also be
174 * added by passing them as arguments when creating a postcss instance.
175 */
176 use(plugin: AcceptedPlugin): Processor;
177 /**
178 * Parses source CSS. Because some plugins can be asynchronous it doesn't
179 * make any transformations. Transformations will be applied in LazyResult's
180 * methods.
181 * @param css Input CSS or any object with toString() method, like a file
182 * stream. If a Result instance is passed the processor will take the
183 * existing Root parser from it.
184 */
185 process(css: ParserInput | Result | LazyResult | Root, options?: ProcessOptions): LazyResult;
186 /**
187 * Contains plugins added to this processor.
188 */
189 plugins: Plugin<any>[];
190 /**
191 * Contains the current version of PostCSS (e.g., "4.0.5").
192 */
193 version: string;
194 }
195 interface ProcessOptions {
196 /**
197 * The path of the CSS source file. You should always set "from", because it is
198 * used in source map generation and syntax error messages.
199 */
200 from?: string;
201 /**
202 * The path where you'll put the output CSS file. You should always set "to"
203 * to generate correct source maps.
204 */
205 to?: string;
206 /**
207 * Function to generate AST by string.
208 */
209 parser?: Parser;
210 /**
211 * Class to generate string by AST.
212 */
213 stringifier?: Stringifier;
214 /**
215 * Object with parse and stringify.
216 */
217 syntax?: Syntax;
218 /**
219 * Source map options
220 */
221 map?: SourceMapOptions | boolean;
222 }
223 interface Syntax {
224 /**
225 * Function to generate AST by string.
226 */
227 parse?: Parser;
228 /**
229 * Class to generate string by AST.
230 */
231 stringify?: Stringifier;
232 }
233 /**
234 * A promise proxy for the result of PostCSS transformations.
235 */
236 interface LazyResult {
237 /**
238 * Processes input CSS through synchronous and asynchronous plugins.
239 * @param onRejected Called if any plugin throws an error.
240 */
241 then: Promise<Result>["then"];
242 /**
243 * Processes input CSS through synchronous and asynchronous plugins.
244 * @param onRejected Called if any plugin throws an error.
245 */
246 catch: Promise<Result>["catch"];
247 /**
248 * Alias for css property.
249 */
250 toString(): string;
251 /**
252 * Processes input CSS through synchronous plugins and converts Root to
253 * CSS string. This property will only work with synchronous plugins. If
254 * the processor contains any asynchronous plugins it will throw an error.
255 * In this case, you should use LazyResult#then() instead.
256 * @returns Result#css.
257 */
258 css: string;
259 /**
260 * Alias for css property to use when syntaxes generate non-CSS output.
261 */
262 content: string;
263 /**
264 * Processes input CSS through synchronous plugins. This property will
265 * work only with synchronous plugins. If processor contains any
266 * asynchronous plugins it will throw an error. You should use
267 * LazyResult#then() instead.
268 */
269 map: ResultMap;
270 /**
271 * Processes input CSS through synchronous plugins. This property will work
272 * only with synchronous plugins. If processor contains any asynchronous
273 * plugins it will throw an error. You should use LazyResult#then() instead.
274 */
275 root: Root;
276 /**
277 * Processes input CSS through synchronous plugins and calls Result#warnings().
278 * This property will only work with synchronous plugins. If the processor
279 * contains any asynchronous plugins it will throw an error. In this case,
280 * you should use LazyResult#then() instead.
281 */
282 warnings(): Warning[];
283 /**
284 * Processes input CSS through synchronous plugins. This property will work
285 * only with synchronous plugins. If processor contains any asynchronous
286 * plugins it will throw an error. You should use LazyResult#then() instead.
287 */
288 messages: ResultMessage[];
289 /**
290 * @returns A processor used for CSS transformations.
291 */
292 processor: Processor;
293 /**
294 * @returns Options from the Processor#process(css, opts) call that produced
295 * this Result instance.
296 */
297 opts: ResultOptions;
298 }
299 /**
300 * Provides the result of the PostCSS transformations.
301 */
302 interface Result {
303 /**
304 * Alias for css property.
305 */
306 toString(): string;
307 /**
308 * Creates an instance of Warning and adds it to messages.
309 * @param message Used in the text property of the message object.
310 * @param options Properties for Message object.
311 */
312 warn(message: string, options?: WarningOptions): void;
313 /**
314 * @returns Warnings from plugins, filtered from messages.
315 */
316 warnings(): Warning[];
317 /**
318 * A CSS string representing this Result's Root instance.
319 */
320 css: string;
321 /**
322 * Alias for css property to use with syntaxes that generate non-CSS output.
323 */
324 content: string;
325 /**
326 * An instance of the SourceMapGenerator class from the source-map library,
327 * representing changes to the Result's Root instance.
328 * This property will have a value only if the user does not want an inline
329 * source map. By default, PostCSS generates inline source maps, written
330 * directly into the processed CSS. The map property will be empty by default.
331 * An external source map will be generated — and assigned to map — only if
332 * the user has set the map.inline option to false, or if PostCSS was passed
333 * an external input source map.
334 */
335 map: ResultMap;
336 /**
337 * Contains the Root node after all transformations.
338 */
339 root?: Root;
340 /**
341 * Contains messages from plugins (e.g., warnings or custom messages).
342 * Add a warning using Result#warn() and get all warnings
343 * using the Result#warnings() method.
344 */
345 messages: ResultMessage[];
346 /**
347 * The Processor instance used for this transformation.
348 */
349 processor?: Processor;
350 /**
351 * Options from the Processor#process(css, opts) or Root#toResult(opts) call
352 * that produced this Result instance.
353 */
354 opts?: ResultOptions;
355 }
356 interface ResultOptions extends ProcessOptions {
357 /**
358 * The CSS node that was the source of the warning.
359 */
360 node?: postcss.Node;
361 /**
362 * Name of plugin that created this warning. Result#warn() will fill it
363 * automatically with plugin.postcssPlugin value.
364 */
365 plugin?: string;
366 }
367 interface ResultMap {
368 /**
369 * Add a single mapping from original source line and column to the generated
370 * source's line and column for this source map being created. The mapping
371 * object should have the following properties:
372 * @param mapping
373 * @returns {}
374 */
375 addMapping(mapping: mozilla.Mapping): void;
376 /**
377 * Set the source content for an original source file.
378 * @param sourceFile The URL of the original source file.
379 * @param sourceContent The content of the source file.
380 */
381 setSourceContent(sourceFile: string, sourceContent: string): void;
382 /**
383 * Applies a SourceMap for a source file to the SourceMap. Each mapping to
384 * the supplied source file is rewritten using the supplied SourceMap.
385 * Note: The resolution for the resulting mappings is the minimum of this
386 * map and the supplied map.
387 * @param sourceMapConsumer The SourceMap to be applied.
388 * @param sourceFile The filename of the source file. If omitted, sourceMapConsumer
389 * file will be used, if it exists. Otherwise an error will be thrown.
390 * @param sourceMapPath The dirname of the path to the SourceMap to be applied.
391 * If relative, it is relative to the SourceMap. This parameter is needed when
392 * the two SourceMaps aren't in the same directory, and the SourceMap to be
393 * applied contains relative source paths. If so, those relative source paths
394 * need to be rewritten relative to the SourceMap.
395 * If omitted, it is assumed that both SourceMaps are in the same directory;
396 * thus, not needing any rewriting (Supplying '.' has the same effect).
397 */
398 applySourceMap(
399 sourceMapConsumer: mozilla.SourceMapConsumer,
400 sourceFile?: string,
401 sourceMapPath?: string
402 ): void;
403 /**
404 * Renders the source map being generated to JSON.
405 */
406 toJSON: () => mozilla.RawSourceMap;
407 /**
408 * Renders the source map being generated to a string.
409 */
410 toString: () => string;
411 }
412 interface ResultMessage {
413 type: string;
414 plugin: string;
415 [others: string]: any;
416 }
417 /**
418 * Represents a plugin warning. It can be created using Result#warn().
419 */
420 interface Warning {
421 /**
422 * @returns Error position, message.
423 */
424 toString(): string;
425 /**
426 * Contains the warning message.
427 */
428 text: string;
429 /**
430 * Contains the name of the plugin that created this warning. When you
431 * call Result#warn(), it will fill this property automatically.
432 */
433 plugin: string;
434 /**
435 * The CSS node that caused the warning.
436 */
437 node: Node;
438 /**
439 * The line in the input file with this warning's source.
440 */
441 line: number;
442 /**
443 * Column in the input file with this warning's source.
444 */
445 column: number;
446 }
447 interface WarningOptions extends ResultOptions {
448 /**
449 * A word inside a node's string that should be highlighted as source
450 * of warning.
451 */
452 word?: string;
453 /**
454 * The index inside a node's string that should be highlighted as
455 * source of warning.
456 */
457 index?: number;
458 }
459 /**
460 * The CSS parser throws this error for broken CSS.
461 */
462 interface CssSyntaxError extends InputOrigin {
463 name: string;
464 /**
465 * @returns Error position, message and source code of broken part.
466 */
467 toString(): string;
468 /**
469 * @param color Whether arrow should be colored red by terminal color codes.
470 * By default, PostCSS will use process.stdout.isTTY and
471 * process.env.NODE_DISABLE_COLORS.
472 * @returns A few lines of CSS source that caused the error. If CSS has
473 * input source map without sourceContent this method will return an empty
474 * string.
475 */
476 showSourceCode(color?: boolean): string;
477 /**
478 * Contains full error text in the GNU error format.
479 */
480 message: string;
481 /**
482 * Contains only the error description.
483 */
484 reason: string;
485 /**
486 * Contains the PostCSS plugin name if the error didn't come from the
487 * CSS parser.
488 */
489 plugin?: string;
490 input?: InputOrigin;
491 }
492 interface InputOrigin {
493 /**
494 * If parser's from option is set, contains the absolute path to the
495 * broken file. PostCSS will use the input source map to detect the
496 * original error location. If you wrote a Sass file, then compiled it
497 * to CSS and parsed it with PostCSS, PostCSS will show the original
498 * position in the Sass file. If you need the position in the PostCSS
499 * input (e.g., to debug the previous compiler), use error.input.file.
500 */
501 file?: string;
502 /**
503 * Contains the source line of the error. PostCSS will use the input
504 * source map to detect the original error location. If you wrote a Sass
505 * file, then compiled it to CSS and parsed it with PostCSS, PostCSS
506 * will show the original position in the Sass file. If you need the
507 * position in the PostCSS input (e.g., to debug the previous
508 * compiler), use error.input.line.
509 */
510 line?: number;
511 /**
512 * Contains the source column of the error. PostCSS will use input
513 * source map to detect the original error location. If you wrote a
514 * Sass file, then compiled it to CSS and parsed it with PostCSS,
515 * PostCSS will show the original position in the Sass file. If you
516 * need the position in the PostCSS input (e.g., to debug the
517 * previous compiler), use error.input.column.
518 */
519 column?: number;
520 /**
521 * Contains the source code of the broken file. PostCSS will use the
522 * input source map to detect the original error location. If you wrote
523 * a Sass file, then compiled it to CSS and parsed it with PostCSS,
524 * PostCSS will show the original position in the Sass file. If you need
525 * the position in the PostCSS input (e.g., to debug the previous
526 * compiler), use error.input.source.
527 */
528 source?: string;
529 }
530 export class PreviousMap {
531 private inline;
532 annotation: string;
533 root: string;
534 private consumerCache;
535 text: string;
536 file: string;
537 constructor(css: any, opts: any);
538 consumer(): mozilla.SourceMapConsumer;
539 withContent(): boolean;
540 startWith(string: string, start: string): boolean;
541 loadAnnotation(css: string): void;
542 decodeInline(text: string): string;
543 loadMap(
544 file: any,
545 prev: string | Function | mozilla.SourceMapConsumer | mozilla.SourceMapGenerator | mozilla.RawSourceMap
546 ): string;
547 isMap(map: any): boolean;
548 }
549 /**
550 * Represents the source CSS.
551 */
552 interface Input {
553 /**
554 * The absolute path to the CSS source file defined with the "from" option.
555 * Either this property or the "id" property are always defined.
556 */
557 file?: string;
558 /**
559 * The unique ID of the CSS source. Used if "from" option is not provided
560 * (because PostCSS does not know the file path). Either this property
561 * or the "file" property are always defined.
562 */
563 id?: string;
564 /**
565 * The CSS source identifier. Contains input.file if the user set the
566 * "from" option, or input.id if they did not.
567 */
568 from: string;
569 /**
570 * Represents the input source map passed from a compilation step before
571 * PostCSS (e.g., from the Sass compiler).
572 */
573 map: PreviousMap;
574 /**
575 * The flag to indicate whether or not the source code has Unicode BOM.
576 */
577 hasBOM: boolean;
578 /**
579 * Reads the input source map.
580 * @returns A symbol position in the input source (e.g., in a Sass file
581 * that was compiled to CSS before being passed to PostCSS):
582 */
583 origin(line: number, column: number): InputOrigin;
584 }
585 type ChildNode = AtRule | Rule | Declaration | Comment;
586 type Node = Root | ChildNode;
587 interface NodeBase {
588 /**
589 * Returns the input source of the node. The property is used in source
590 * map generation. If you create a node manually
591 * (e.g., with postcss.decl() ), that node will not have a source
592 * property and will be absent from the source map. For this reason, the
593 * plugin developer should consider cloning nodes to create new ones
594 * (in which case the new node's source will reference the original,
595 * cloned node) or setting the source property manually.
596 */
597 source?: NodeSource;
598 /**
599 * Contains information to generate byte-to-byte equal node string as it
600 * was in origin input.
601 */
602 raws: NodeRaws;
603 /**
604 * @returns A CSS string representing the node.
605 */
606 toString(): string;
607 /**
608 * This method produces very useful error messages. If present, an input
609 * source map will be used to get the original position of the source, even
610 * from a previous compilation step (e.g., from Sass compilation).
611 * @returns The original position of the node in the source, showing line
612 * and column numbers and also a small excerpt to facilitate debugging.
613 */
614 error(
615 /**
616 * Error description.
617 */
618 message: string, options?: NodeErrorOptions): CssSyntaxError;
619 /**
620 * Creates an instance of Warning and adds it to messages. This method is
621 * provided as a convenience wrapper for Result#warn.
622 * Note that `opts.node` is automatically passed to Result#warn for you.
623 * @param result The result that will receive the warning.
624 * @param text Warning message. It will be used in the `text` property of
625 * the message object.
626 * @param opts Properties to assign to the message object.
627 */
628 warn(result: Result, text: string, opts?: WarningOptions): void;
629 /**
630 * @returns The next child of the node's parent; or, returns undefined if
631 * the current node is the last child.
632 */
633 next(): ChildNode | void;
634 /**
635 * @returns The previous child of the node's parent; or, returns undefined
636 * if the current node is the first child.
637 */
638 prev(): ChildNode | void;
639 /**
640 * Insert new node before current node to current node’s parent.
641 *
642 * Just an alias for `node.parent.insertBefore(node, newNode)`.
643 *
644 * @returns this node for method chaining.
645 *
646 * @example
647 * decl.before('content: ""');
648 */
649 before(newNode: Node | object | string | Node[]): this;
650 /**
651 * Insert new node after current node to current node’s parent.
652 *
653 * Just an alias for `node.parent.insertAfter(node, newNode)`.
654 *
655 * @returns this node for method chaining.
656 *
657 * @example
658 * decl.after('color: black');
659 */
660 after(newNode: Node | object | string | Node[]): this;
661 /**
662 * @returns The Root instance of the node's tree.
663 */
664 root(): Root;
665 /**
666 * Removes the node from its parent and cleans the parent property in the
667 * node and its children.
668 * @returns This node for chaining.
669 */
670 remove(): this;
671 /**
672 * Inserts node(s) before the current node and removes the current node.
673 * @returns This node for chaining.
674 */
675 replaceWith(...nodes: (Node | object)[]): this;
676 /**
677 * @param overrides New properties to override in the clone.
678 * @returns A clone of this node. The node and its (cloned) children will
679 * have a clean parent and code style properties.
680 */
681 clone(overrides?: object): this;
682 /**
683 * Shortcut to clone the node and insert the resulting cloned node before
684 * the current node.
685 * @param overrides New Properties to override in the clone.
686 * @returns The cloned node.
687 */
688 cloneBefore(overrides?: object): this;
689 /**
690 * Shortcut to clone the node and insert the resulting cloned node after
691 * the current node.
692 * @param overrides New Properties to override in the clone.
693 * @returns The cloned node.
694 */
695 cloneAfter(overrides?: object): this;
696 /**
697 * @param prop Name or code style property.
698 * @param defaultType Name of default value. It can be easily missed if the
699 * value is the same as prop.
700 * @returns A code style property value. If the node is missing the code
701 * style property (because the node was manually built or cloned), PostCSS
702 * will try to autodetect the code style property by looking at other nodes
703 * in the tree.
704 */
705 raw(prop: string, defaultType?: string): any;
706 }
707 interface NodeNewProps {
708 source?: NodeSource;
709 raws?: NodeRaws;
710 }
711 interface NodeRaws {
712 /**
713 * The space symbols before the node. It also stores `*` and `_`
714 * symbols before the declaration (IE hack).
715 */
716 before?: string;
717 /**
718 * The space symbols after the last child of the node to the end of
719 * the node.
720 */
721 after?: string;
722 /**
723 * The symbols between the property and value for declarations,
724 * selector and "{" for rules, last parameter and "{" for at-rules.
725 */
726 between?: string;
727 /**
728 * True if last child has (optional) semicolon.
729 */
730 semicolon?: boolean;
731 /**
732 * The space between the at-rule's name and parameters.
733 */
734 afterName?: string;
735 /**
736 * The space symbols between "/*" and comment's text.
737 */
738 left?: string;
739 /**
740 * The space symbols between comment's text and "*\/".
741 */
742 right?: string;
743 /**
744 * The content of important statement, if it is not just "!important".
745 */
746 important?: string;
747 }
748 interface NodeSource {
749 input: Input;
750 /**
751 * The starting position of the node's source.
752 */
753 start?: {
754 column: number;
755 line: number;
756 };
757 /**
758 * The ending position of the node's source.
759 */
760 end?: {
761 column: number;
762 line: number;
763 };
764 }
765 interface NodeErrorOptions {
766 /**
767 * Plugin name that created this error. PostCSS will set it automatically.
768 */
769 plugin?: string;
770 /**
771 * A word inside a node's string, that should be highlighted as source
772 * of error.
773 */
774 word?: string;
775 /**
776 * An index inside a node's string that should be highlighted as source
777 * of error.
778 */
779 index?: number;
780 }
781 interface JsonNode {
782 /**
783 * Returns a string representing the node's type. Possible values are
784 * root, atrule, rule, decl or comment.
785 */
786 type?: string;
787 /**
788 * Returns the node's parent node.
789 */
790 parent?: JsonContainer;
791 /**
792 * Returns the input source of the node. The property is used in source
793 * map generation. If you create a node manually (e.g., with
794 * postcss.decl() ), that node will not have a source property and
795 * will be absent from the source map. For this reason, the plugin
796 * developer should consider cloning nodes to create new ones (in which
797 * case the new node's source will reference the original, cloned node)
798 * or setting the source property manually.
799 */
800 source?: NodeSource;
801 /**
802 * Contains information to generate byte-to-byte equal node string as it
803 * was in origin input.
804 */
805 raws?: NodeRaws;
806 }
807 type Container = Root | AtRule | Rule;
808 /**
809 * Containers can store any content. If you write a rule inside a rule,
810 * PostCSS will parse it.
811 */
812 interface ContainerBase extends NodeBase {
813 /**
814 * Contains the container's children.
815 */
816 nodes?: ChildNode[];
817 /**
818 * @returns The container's first child.
819 */
820 first?: ChildNode;
821 /**
822 * @returns The container's last child.
823 */
824 last?: ChildNode;
825 /**
826 * @param overrides New properties to override in the clone.
827 * @returns A clone of this node. The node and its (cloned) children will
828 * have a clean parent and code style properties.
829 */
830 clone(overrides?: object): this;
831 /**
832 * @param child Child of the current container.
833 * @returns The child's index within the container's "nodes" array.
834 */
835 index(child: ChildNode | number): number;
836 /**
837 * Determines whether all child nodes satisfy the specified test.
838 * @param callback A function that accepts up to three arguments. The
839 * every method calls the callback function for each node until the
840 * callback returns false, or until the end of the array.
841 * @returns True if the callback returns true for all of the container's
842 * children.
843 */
844 every(callback: (node: ChildNode, index: number, nodes: ChildNode[]) => any, thisArg?: any): boolean;
845 /**
846 * Determines whether the specified callback returns true for any child node.
847 * @param callback A function that accepts up to three arguments. The some
848 * method calls the callback for each node until the callback returns true,
849 * or until the end of the array.
850 * @param thisArg An object to which the this keyword can refer in the
851 * callback function. If thisArg is omitted, undefined is used as the
852 * this value.
853 * @returns True if callback returns true for (at least) one of the
854 * container's children.
855 */
856 some(callback: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean, thisArg?: any): boolean;
857 /**
858 * Iterates through the container's immediate children, calling the
859 * callback function for each child. If you need to recursively iterate
860 * through all the container's descendant nodes, use container.walk().
861 * Unlike the for {} -cycle or Array#forEach() this iterator is safe if
862 * you are mutating the array of child nodes during iteration.
863 * @param callback Iterator. Returning false will break iteration. Safe
864 * if you are mutating the array of child nodes during iteration. PostCSS
865 * will adjust the current index to match the mutations.
866 * @returns False if the callback returns false during iteration.
867 */
868 each(callback: (node: ChildNode, index: number) => any): boolean | void;
869 /**
870 * Traverses the container's descendant nodes, calling `callback` for each
871 * node. Like container.each(), this method is safe to use if you are
872 * mutating arrays during iteration. If you only need to iterate through
873 * the container's immediate children, use container.each().
874 * @param callback Iterator.
875 */
876 walk(callback: (node: ChildNode, index: number) => any): boolean | void;
877 /**
878 * Traverses the container's descendant nodes, calling `callback` for each
879 * declaration. Like container.each(), this method is safe to use if you
880 * are mutating arrays during iteration.
881 * @param propFilter Filters declarations by property name. Only those
882 * declarations whose property matches propFilter will be iterated over.
883 * @param callback Called for each declaration node within the container.
884 */
885 walkDecls(propFilter: string | RegExp, callback?: (decl: Declaration, index: number) => any): boolean | void;
886 walkDecls(callback: (decl: Declaration, index: number) => any): boolean | void;
887 /**
888 * Traverses the container's descendant nodes, calling `callback` for each
889 * at-rule. Like container.each(), this method is safe to use if you are
890 * mutating arrays during iteration.
891 * @param nameFilter Filters at-rules by name. If provided, iteration
892 * will only happen over at-rules that have matching names.
893 * @param callback Iterator called for each at-rule node within the
894 * container.
895 */
896 walkAtRules(nameFilter: string | RegExp, callback: (atRule: AtRule, index: number) => any): boolean | void;
897 walkAtRules(callback: (atRule: AtRule, index: number) => any): boolean | void;
898 /**
899 * Traverses the container's descendant nodes, calling `callback` for each
900 * rule. Like container.each(), this method is safe to use if you are
901 * mutating arrays during iteration.
902 * @param selectorFilter Filters rules by selector. If provided,
903 * iteration will only happen over rules that have matching names.
904 * @param callback Iterator called for each rule node within the
905 * container.
906 */
907 walkRules(selectorFilter: string | RegExp, callback: (atRule: Rule, index: number) => any): boolean | void;
908 walkRules(callback: (atRule: Rule, index: number) => any): boolean | void;
909 walkRules(selectorFilter: any, callback?: (atRule: Rule, index: number) => any): boolean | void;
910 /**
911 * Traverses the container's descendant nodes, calling `callback` for each
912 * comment. Like container.each(), this method is safe to use if you are
913 * mutating arrays during iteration.
914 * @param callback Iterator called for each comment node within the container.
915 */
916 walkComments(callback: (comment: Comment, indexed: number) => any): void | boolean;
917 /**
918 * Passes all declaration values within the container that match pattern
919 * through the callback, replacing those values with the returned result of
920 * callback. This method is useful if you are using a custom unit or
921 * function and need to iterate through all values.
922 * @param pattern Pattern that we need to replace.
923 * @param options Options to speed up the search.
924 * @param callbackOrReplaceValue String to replace pattern or callback
925 * that will return a new value. The callback will receive the same
926 * arguments as those passed to a function parameter of String#replace.
927 */
928 replaceValues(pattern: string | RegExp, options: {
929 /**
930 * Property names. The method will only search for values that match
931 * regexp within declarations of listed properties.
932 */
933 props?: string[];
934 /**
935 * Used to narrow down values and speed up the regexp search. Searching
936 * every single value with a regexp can be slow. If you pass a fast
937 * string, PostCSS will first check whether the value contains the fast
938 * string; and only if it does will PostCSS check that value against
939 * regexp. For example, instead of just checking for /\d+rem/ on all
940 * values, set fast: 'rem' to first check whether a value has the rem
941 * unit, and only if it does perform the regexp check.
942 */
943 fast?: string;
944 }, callbackOrReplaceValue: string | {
945 (substring: string, ...args: any[]): string;
946 }): this;
947 replaceValues(pattern: string | RegExp, callbackOrReplaceValue: string | {
948 (substring: string, ...args: any[]): string;
949 }): this;
950 /**
951 * Inserts new nodes to the beginning of the container.
952 * Because each node class is identifiable by unique properties, use the
953 * following shortcuts to create nodes in insert methods:
954 * root.prepend({ name: '@charset', params: '"UTF-8"' }); // at-rule
955 * root.prepend({ selector: 'a' }); // rule
956 * rule.prepend({ prop: 'color', value: 'black' }); // declaration
957 * rule.prepend({ text: 'Comment' }) // comment
958 * A string containing the CSS of the new element can also be used. This
959 * approach is slower than the above shortcuts.
960 * root.prepend('a {}');
961 * root.first.prepend('color: black; z-index: 1');
962 * @param nodes New nodes.
963 * @returns This container for chaining.
964 */
965 prepend(...nodes: (Node | object | string)[]): this;
966 /**
967 * Inserts new nodes to the end of the container.
968 * Because each node class is identifiable by unique properties, use the
969 * following shortcuts to create nodes in insert methods:
970 * root.append({ name: '@charset', params: '"UTF-8"' }); // at-rule
971 * root.append({ selector: 'a' }); // rule
972 * rule.append({ prop: 'color', value: 'black' }); // declaration
973 * rule.append({ text: 'Comment' }) // comment
974 * A string containing the CSS of the new element can also be used. This
975 * approach is slower than the above shortcuts.
976 * root.append('a {}');
977 * root.first.append('color: black; z-index: 1');
978 * @param nodes New nodes.
979 * @returns This container for chaining.
980 */
981 append(...nodes: (Node | object | string)[]): this;
982 /**
983 * Insert newNode before oldNode within the container.
984 * @param oldNode Child or child's index.
985 * @returns This container for chaining.
986 */
987 insertBefore(oldNode: ChildNode | number, newNode: ChildNode | object | string): this;
988 /**
989 * Insert newNode after oldNode within the container.
990 * @param oldNode Child or child's index.
991 * @returns This container for chaining.
992 */
993 insertAfter(oldNode: ChildNode | number, newNode: ChildNode | object | string): this;
994 /**
995 * Removes the container from its parent and cleans the parent property in the
996 * container and its children.
997 * @returns This container for chaining.
998 */
999 remove(): this;
1000 /**
1001 * Removes child from the container and cleans the parent properties
1002 * from the node and its children.
1003 * @param child Child or child's index.
1004 * @returns This container for chaining.
1005 */
1006 removeChild(child: ChildNode | number): this;
1007 /**
1008 * Removes all children from the container and cleans their parent
1009 * properties.
1010 * @returns This container for chaining.
1011 */
1012 removeAll(): this;
1013 }
1014 interface ContainerNewProps extends NodeNewProps {
1015 /**
1016 * Contains the container's children.
1017 */
1018 nodes?: ChildNode[];
1019 raws?: ContainerRaws;
1020 }
1021 interface ContainerRaws extends NodeRaws {
1022 indent?: string;
1023 }
1024 interface JsonContainer extends JsonNode {
1025 /**
1026 * Contains the container's children.
1027 */
1028 nodes?: ChildNode[];
1029 /**
1030 * @returns The container's first child.
1031 */
1032 first?: ChildNode;
1033 /**
1034 * @returns The container's last child.
1035 */
1036 last?: ChildNode;
1037 }
1038 /**
1039 * Represents a CSS file and contains all its parsed nodes.
1040 */
1041 interface Root extends ContainerBase {
1042 type: 'root';
1043 /**
1044 * Inherited from Container. Should always be undefined for a Root node.
1045 */
1046 parent: void;
1047 /**
1048 * @param overrides New properties to override in the clone.
1049 * @returns A clone of this node. The node and its (cloned) children will
1050 * have a clean parent and code style properties.
1051 */
1052 clone(overrides?: object): this;
1053 /**
1054 * @returns A Result instance representing the root's CSS.
1055 */
1056 toResult(options?: {
1057 /**
1058 * The path where you'll put the output CSS file. You should always
1059 * set "to" to generate correct source maps.
1060 */
1061 to?: string;
1062 map?: SourceMapOptions;
1063 }): Result;
1064 /**
1065 * Removes child from the root node, and the parent properties of node and
1066 * its children.
1067 * @param child Child or child's index.
1068 * @returns This root node for chaining.
1069 */
1070 removeChild(child: ChildNode | number): this;
1071 }
1072 interface RootNewProps extends ContainerNewProps {
1073 }
1074 interface JsonRoot extends JsonContainer {
1075 }
1076 /**
1077 * Represents an at-rule. If it's followed in the CSS by a {} block, this
1078 * node will have a nodes property representing its children.
1079 */
1080 interface AtRule extends ContainerBase {
1081 type: 'atrule';
1082 /**
1083 * Returns the atrule's parent node.
1084 */
1085 parent: Container;
1086 /**
1087 * The identifier that immediately follows the @.
1088 */
1089 name: string;
1090 /**
1091 * These are the values that follow the at-rule's name, but precede any {}
1092 * block. The spec refers to this area as the at-rule's "prelude".
1093 */
1094 params: string;
1095 /**
1096 * @param overrides New properties to override in the clone.
1097 * @returns A clone of this node. The node and its (cloned) children will
1098 * have a clean parent and code style properties.
1099 */
1100 clone(overrides?: object): this;
1101 }
1102 interface AtRuleNewProps extends ContainerNewProps {
1103 /**
1104 * The identifier that immediately follows the @.
1105 */
1106 name?: string;
1107 /**
1108 * These are the values that follow the at-rule's name, but precede any {}
1109 * block. The spec refers to this area as the at-rule's "prelude".
1110 */
1111 params?: string | number;
1112 raws?: AtRuleRaws;
1113 }
1114 interface AtRuleRaws extends NodeRaws {
1115 params?: string;
1116 }
1117 interface JsonAtRule extends JsonContainer {
1118 /**
1119 * The identifier that immediately follows the @.
1120 */
1121 name?: string;
1122 /**
1123 * These are the values that follow the at-rule's name, but precede any {}
1124 * block. The spec refers to this area as the at-rule's "prelude".
1125 */
1126 params?: string;
1127 }
1128 /**
1129 * Represents a CSS rule: a selector followed by a declaration block.
1130 */
1131 interface Rule extends ContainerBase {
1132 type: 'rule';
1133 /**
1134 * Returns the rule's parent node.
1135 */
1136 parent: Container;
1137 /**
1138 * The rule's full selector. If there are multiple comma-separated selectors,
1139 * the entire group will be included.
1140 */
1141 selector: string;
1142 /**
1143 * An array containing the rule's individual selectors.
1144 * Groups of selectors are split at commas.
1145 */
1146 selectors: string[];
1147 /**
1148 * @param overrides New properties to override in the clone.
1149 * @returns A clone of this node. The node and its (cloned) children will
1150 * have a clean parent and code style properties.
1151 */
1152 clone(overrides?: object): this;
1153 }
1154 interface RuleNewProps extends ContainerNewProps {
1155 /**
1156 * The rule's full selector. If there are multiple comma-separated selectors,
1157 * the entire group will be included.
1158 */
1159 selector?: string;
1160 /**
1161 * An array containing the rule's individual selectors. Groups of selectors
1162 * are split at commas.
1163 */
1164 selectors?: string[];
1165 raws?: RuleRaws;
1166 }
1167 interface RuleRaws extends ContainerRaws {
1168 /**
1169 * The rule's full selector. If there are multiple comma-separated selectors,
1170 * the entire group will be included.
1171 */
1172 selector?: string;
1173 }
1174 interface JsonRule extends JsonContainer {
1175 /**
1176 * The rule's full selector. If there are multiple comma-separated selectors,
1177 * the entire group will be included.
1178 */
1179 selector?: string;
1180 /**
1181 * An array containing the rule's individual selectors.
1182 * Groups of selectors are split at commas.
1183 */
1184 selectors?: string[];
1185 }
1186 /**
1187 * Represents a CSS declaration.
1188 */
1189 interface Declaration extends NodeBase {
1190 type: 'decl';
1191 /**
1192 * Returns the declaration's parent node.
1193 */
1194 parent: Container;
1195 /**
1196 * The declaration's property name.
1197 */
1198 prop: string;
1199 /**
1200 * The declaration's value. This value will be cleaned of comments. If the
1201 * source value contained comments, those comments will be available in the
1202 * _value.raws property. If you have not changed the value, the result of
1203 * decl.toString() will include the original raws value (comments and all).
1204 */
1205 value: string;
1206 /**
1207 * True if the declaration has an !important annotation.
1208 */
1209 important: boolean;
1210 /**
1211 * @param overrides New properties to override in the clone.
1212 * @returns A clone of this node. The node and its (cloned) children will
1213 * have a clean parent and code style properties.
1214 */
1215 clone(overrides?: object): this;
1216 }
1217 interface DeclarationNewProps {
1218 /**
1219 * The declaration's property name.
1220 */
1221 prop?: string;
1222 /**
1223 * The declaration's value. This value will be cleaned of comments. If the
1224 * source value contained comments, those comments will be available in the
1225 * _value.raws property. If you have not changed the value, the result of
1226 * decl.toString() will include the original raws value (comments and all).
1227 */
1228 value?: string;
1229 raws?: DeclarationRaws;
1230 }
1231 interface DeclarationRaws extends NodeRaws {
1232 /**
1233 * The declaration's value. This value will be cleaned of comments.
1234 * If the source value contained comments, those comments will be
1235 * available in the _value.raws property. If you have not changed the value, the result of
1236 * decl.toString() will include the original raws value (comments and all).
1237 */
1238 value?: string;
1239 }
1240 interface JsonDeclaration extends JsonNode {
1241 /**
1242 * True if the declaration has an !important annotation.
1243 */
1244 important?: boolean;
1245 }
1246 /**
1247 * Represents a comment between declarations or statements (rule and at-rules).
1248 * Comments inside selectors, at-rule parameters, or declaration values will
1249 * be stored in the Node#raws properties.
1250 */
1251 interface Comment extends NodeBase {
1252 type: 'comment';
1253 /**
1254 * Returns the comment's parent node.
1255 */
1256 parent: Container;
1257 /**
1258 * The comment's text.
1259 */
1260 text: string;
1261 /**
1262 * @param overrides New properties to override in the clone.
1263 * @returns A clone of this node. The node and its (cloned) children will
1264 * have a clean parent and code style properties.
1265 */
1266 clone(overrides?: object): this;
1267 }
1268 interface CommentNewProps {
1269 /**
1270 * The comment's text.
1271 */
1272 text?: string;
1273 }
1274 interface JsonComment extends JsonNode {
1275 }
1276}
1277export = postcss;