UNPKG

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