source: trip-planner-front/node_modules/css-has-pseudo/node_modules/postcss/lib/postcss.d.ts@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 45.2 KB
Line 
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, processOpts?: ProcessOptions, pluginOpts?: T) => 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 getAnnotationURL(sourceMapString: string): string;
542 loadAnnotation(css: string): void;
543 decodeInline(text: string): string;
544 loadMap(
545 file: any,
546 prev: string | Function | mozilla.SourceMapConsumer | mozilla.SourceMapGenerator | mozilla.RawSourceMap
547 ): string;
548 isMap(map: any): boolean;
549 }
550 /**
551 * Represents the source CSS.
552 */
553 interface Input {
554 /**
555 * The absolute path to the CSS source file defined with the "from" option.
556 * Either this property or the "id" property are always defined.
557 */
558 file?: string;
559 /**
560 * The unique ID of the CSS source. Used if "from" option is not provided
561 * (because PostCSS does not know the file path). Either this property
562 * or the "file" property are always defined.
563 */
564 id?: string;
565 /**
566 * The CSS source identifier. Contains input.file if the user set the
567 * "from" option, or input.id if they did not.
568 */
569 from: string;
570 /**
571 * Represents the input source map passed from a compilation step before
572 * PostCSS (e.g., from the Sass compiler).
573 */
574 map: PreviousMap;
575 /**
576 * The flag to indicate whether or not the source code has Unicode BOM.
577 */
578 hasBOM: boolean;
579 /**
580 * Reads the input source map.
581 * @returns A symbol position in the input source (e.g., in a Sass file
582 * that was compiled to CSS before being passed to PostCSS):
583 */
584 origin(line: number, column: number): InputOrigin | false;
585 }
586 type ChildNode = AtRule | Rule | Declaration | Comment;
587 type Node = Root | ChildNode;
588 interface NodeBase {
589 /**
590 * Returns the input source of the node. The property is used in source
591 * map generation. If you create a node manually
592 * (e.g., with postcss.decl() ), that node will not have a source
593 * property and will be absent from the source map. For this reason, the
594 * plugin developer should consider cloning nodes to create new ones
595 * (in which case the new node's source will reference the original,
596 * cloned node) or setting the source property manually.
597 */
598 source?: NodeSource;
599 /**
600 * Contains information to generate byte-to-byte equal node string as it
601 * was in origin input.
602 */
603 raws: NodeRaws;
604 /**
605 * @returns A CSS string representing the node.
606 */
607 toString(stringifier?: Stringifier | Syntax): string;
608 /**
609 * This method produces very useful error messages. If present, an input
610 * source map will be used to get the original position of the source, even
611 * from a previous compilation step (e.g., from Sass compilation).
612 * @returns The original position of the node in the source, showing line
613 * and column numbers and also a small excerpt to facilitate debugging.
614 */
615 error(
616 /**
617 * Error description.
618 */
619 message: string, options?: NodeErrorOptions): CssSyntaxError;
620 /**
621 * Creates an instance of Warning and adds it to messages. This method is
622 * provided as a convenience wrapper for Result#warn.
623 * Note that `opts.node` is automatically passed to Result#warn for you.
624 * @param result The result that will receive the warning.
625 * @param text Warning message. It will be used in the `text` property of
626 * the message object.
627 * @param opts Properties to assign to the message object.
628 */
629 warn(result: Result, text: string, opts?: WarningOptions): void;
630 /**
631 * @returns The next child of the node's parent; or, returns undefined if
632 * the current node is the last child.
633 */
634 next(): ChildNode | undefined;
635 /**
636 * @returns The previous child of the node's parent; or, returns undefined
637 * if the current node is the first child.
638 */
639 prev(): ChildNode | undefined;
640 /**
641 * Insert new node before current node to current node’s parent.
642 *
643 * Just an alias for `node.parent.insertBefore(node, newNode)`.
644 *
645 * @returns this node for method chaining.
646 *
647 * @example
648 * decl.before('content: ""');
649 */
650 before(newNode: Node | object | string | Node[]): this;
651 /**
652 * Insert new node after current node to current node’s parent.
653 *
654 * Just an alias for `node.parent.insertAfter(node, newNode)`.
655 *
656 * @returns this node for method chaining.
657 *
658 * @example
659 * decl.after('color: black');
660 */
661 after(newNode: Node | object | string | Node[]): this;
662 /**
663 * @returns The Root instance of the node's tree.
664 */
665 root(): Root;
666 /**
667 * Removes the node from its parent and cleans the parent property in the
668 * node and its children.
669 * @returns This node for chaining.
670 */
671 remove(): this;
672 /**
673 * Inserts node(s) before the current node and removes the current node.
674 * @returns This node for chaining.
675 */
676 replaceWith(...nodes: (Node | object)[]): this;
677 /**
678 * @param overrides New properties to override in the clone.
679 * @returns A clone of this node. The node and its (cloned) children will
680 * have a clean parent and code style properties.
681 */
682 clone(overrides?: object): this;
683 /**
684 * Shortcut to clone the node and insert the resulting cloned node before
685 * the current node.
686 * @param overrides New Properties to override in the clone.
687 * @returns The cloned node.
688 */
689 cloneBefore(overrides?: object): this;
690 /**
691 * Shortcut to clone the node and insert the resulting cloned node after
692 * the current node.
693 * @param overrides New Properties to override in the clone.
694 * @returns The cloned node.
695 */
696 cloneAfter(overrides?: object): this;
697 /**
698 * @param prop Name or code style property.
699 * @param defaultType Name of default value. It can be easily missed if the
700 * value is the same as prop.
701 * @returns A code style property value. If the node is missing the code
702 * style property (because the node was manually built or cloned), PostCSS
703 * will try to autodetect the code style property by looking at other nodes
704 * in the tree.
705 */
706 raw(prop: string, defaultType?: string): string;
707 }
708 interface NodeNewProps {
709 source?: NodeSource;
710 raws?: NodeRaws;
711 }
712 interface NodeRaws {
713 /**
714 * The space symbols before the node. It also stores `*` and `_`
715 * symbols before the declaration (IE hack).
716 */
717 before?: string;
718 /**
719 * The space symbols after the last child of the node to the end of
720 * the node.
721 */
722 after?: string;
723 /**
724 * The symbols between the property and value for declarations,
725 * selector and "{" for rules, last parameter and "{" for at-rules.
726 */
727 between?: string;
728 /**
729 * True if last child has (optional) semicolon.
730 */
731 semicolon?: boolean;
732 /**
733 * The space between the at-rule's name and parameters.
734 */
735 afterName?: string;
736 /**
737 * The space symbols between "/*" and comment's text.
738 */
739 left?: string;
740 /**
741 * The space symbols between comment's text and "*\/".
742 */
743 right?: string;
744 /**
745 * The content of important statement, if it is not just "!important".
746 */
747 important?: string;
748 }
749 interface NodeSource {
750 input: Input;
751 /**
752 * The starting position of the node's source.
753 */
754 start?: {
755 column: number;
756 line: number;
757 };
758 /**
759 * The ending position of the node's source.
760 */
761 end?: {
762 column: number;
763 line: number;
764 };
765 }
766 interface NodeErrorOptions {
767 /**
768 * Plugin name that created this error. PostCSS will set it automatically.
769 */
770 plugin?: string;
771 /**
772 * A word inside a node's string, that should be highlighted as source
773 * of error.
774 */
775 word?: string;
776 /**
777 * An index inside a node's string that should be highlighted as source
778 * of error.
779 */
780 index?: number;
781 }
782 interface JsonNode {
783 /**
784 * Returns a string representing the node's type. Possible values are
785 * root, atrule, rule, decl or comment.
786 */
787 type?: string;
788 /**
789 * Returns the node's parent node.
790 */
791 parent?: JsonContainer;
792 /**
793 * Returns the input source of the node. The property is used in source
794 * map generation. If you create a node manually (e.g., with
795 * postcss.decl() ), that node will not have a source property and
796 * will be absent from the source map. For this reason, the plugin
797 * developer should consider cloning nodes to create new ones (in which
798 * case the new node's source will reference the original, cloned node)
799 * or setting the source property manually.
800 */
801 source?: NodeSource;
802 /**
803 * Contains information to generate byte-to-byte equal node string as it
804 * was in origin input.
805 */
806 raws?: NodeRaws;
807 }
808 type Container = Root | AtRule | Rule;
809 /**
810 * Containers can store any content. If you write a rule inside a rule,
811 * PostCSS will parse it.
812 */
813 interface ContainerBase extends NodeBase {
814 /**
815 * Contains the container's children.
816 */
817 nodes?: ChildNode[];
818 /**
819 * @returns The container's first child.
820 */
821 first?: ChildNode;
822 /**
823 * @returns The container's last child.
824 */
825 last?: ChildNode;
826 /**
827 * @param overrides New properties to override in the clone.
828 * @returns A clone of this node. The node and its (cloned) children will
829 * have a clean parent and code style properties.
830 */
831 clone(overrides?: object): this;
832 /**
833 * @param child Child of the current container.
834 * @returns The child's index within the container's "nodes" array.
835 */
836 index(child: ChildNode | number): number;
837 /**
838 * Determines whether all child nodes satisfy the specified test.
839 * @param callback A function that accepts up to three arguments. The
840 * every method calls the callback function for each node until the
841 * callback returns false, or until the end of the array.
842 * @returns True if the callback returns true for all of the container's
843 * children.
844 */
845 every(callback: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean): boolean;
846 /**
847 * Determines whether the specified callback returns true for any child node.
848 * @param callback A function that accepts up to three arguments. The some
849 * method calls the callback for each node until the callback returns true,
850 * or until the end of the array.
851 * @returns True if callback returns true for (at least) one of the
852 * container's children.
853 */
854 some(callback: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean): boolean;
855 /**
856 * Iterates through the container's immediate children, calling the
857 * callback function for each child. If you need to recursively iterate
858 * through all the container's descendant nodes, use container.walk().
859 * Unlike the for {} -cycle or Array#forEach() this iterator is safe if
860 * you are mutating the array of child nodes during iteration.
861 * @param callback Iterator. Returning false will break iteration. Safe
862 * if you are mutating the array of child nodes during iteration. PostCSS
863 * will adjust the current index to match the mutations.
864 * @returns False if the callback returns false during iteration.
865 */
866 each(callback: (node: ChildNode, index: number) => void): void;
867 each(callback: (node: ChildNode, index: number) => boolean): boolean;
868 /**
869 * Traverses the container's descendant nodes, calling `callback` for each
870 * node. Like container.each(), this method is safe to use if you are
871 * mutating arrays during iteration. If you only need to iterate through
872 * the container's immediate children, use container.each().
873 * @param callback Iterator.
874 */
875 walk(callback: (node: ChildNode, index: number) => void): void;
876 walk(callback: (node: ChildNode, index: number) => boolean): boolean;
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) => void): void;
886 walkDecls(callback: (decl: Declaration, index: number) => void): void;
887 walkDecls(propFilter: string | RegExp, callback: (decl: Declaration, index: number) => boolean): boolean;
888 walkDecls(callback: (decl: Declaration, index: number) => boolean): boolean;
889 /**
890 * Traverses the container's descendant nodes, calling `callback` for each
891 * at-rule. Like container.each(), this method is safe to use if you are
892 * mutating arrays during iteration.
893 * @param nameFilter Filters at-rules by name. If provided, iteration
894 * will only happen over at-rules that have matching names.
895 * @param callback Iterator called for each at-rule node within the
896 * container.
897 */
898 walkAtRules(nameFilter: string | RegExp, callback: (atRule: AtRule, index: number) => void): void;
899 walkAtRules(callback: (atRule: AtRule, index: number) => void): void;
900 walkAtRules(nameFilter: string | RegExp, callback: (atRule: AtRule, index: number) => boolean): boolean;
901 walkAtRules(callback: (atRule: AtRule, index: number) => boolean): boolean;
902 /**
903 * Traverses the container's descendant nodes, calling `callback` for each
904 * rule. Like container.each(), this method is safe to use if you are
905 * mutating arrays during iteration.
906 * @param selectorFilter Filters rules by selector. If provided,
907 * iteration will only happen over rules that have matching names.
908 * @param callback Iterator called for each rule node within the
909 * container.
910 */
911 walkRules(selectorFilter: string | RegExp, callback: (atRule: Rule, index: number) => void): void;
912 walkRules(callback: (atRule: Rule, index: number) => void): void;
913 walkRules(selectorFilter: string | RegExp, callback: (atRule: Rule, index: number) => boolean): boolean;
914 walkRules(callback: (atRule: Rule, index: number) => boolean): boolean;
915 /**
916 * Traverses the container's descendant nodes, calling `callback` for each
917 * comment. Like container.each(), this method is safe to use if you are
918 * mutating arrays during iteration.
919 * @param callback Iterator called for each comment node within the container.
920 */
921 walkComments(callback: (comment: Comment, indexed: number) => void): void;
922 walkComments(callback: (comment: Comment, indexed: number) => boolean): boolean;
923 /**
924 * Passes all declaration values within the container that match pattern
925 * through the callback, replacing those values with the returned result of
926 * callback. This method is useful if you are using a custom unit or
927 * function and need to iterate through all values.
928 * @param pattern Pattern that we need to replace.
929 * @param options Options to speed up the search.
930 * @param callbackOrReplaceValue String to replace pattern or callback
931 * that will return a new value. The callback will receive the same
932 * arguments as those passed to a function parameter of String#replace.
933 */
934 replaceValues(pattern: string | RegExp, options: {
935 /**
936 * Property names. The method will only search for values that match
937 * regexp within declarations of listed properties.
938 */
939 props?: string[];
940 /**
941 * Used to narrow down values and speed up the regexp search. Searching
942 * every single value with a regexp can be slow. If you pass a fast
943 * string, PostCSS will first check whether the value contains the fast
944 * string; and only if it does will PostCSS check that value against
945 * regexp. For example, instead of just checking for /\d+rem/ on all
946 * values, set fast: 'rem' to first check whether a value has the rem
947 * unit, and only if it does perform the regexp check.
948 */
949 fast?: string;
950 }, callbackOrReplaceValue: string | {
951 (substring: string, ...args: any[]): string;
952 }): this;
953 replaceValues(pattern: string | RegExp, callbackOrReplaceValue: string | {
954 (substring: string, ...args: any[]): string;
955 }): this;
956 /**
957 * Inserts new nodes to the beginning of the container.
958 * Because each node class is identifiable by unique properties, use the
959 * following shortcuts to create nodes in insert methods:
960 * root.prepend({ name: '@charset', params: '"UTF-8"' }); // at-rule
961 * root.prepend({ selector: 'a' }); // rule
962 * rule.prepend({ prop: 'color', value: 'black' }); // declaration
963 * rule.prepend({ text: 'Comment' }) // comment
964 * A string containing the CSS of the new element can also be used. This
965 * approach is slower than the above shortcuts.
966 * root.prepend('a {}');
967 * root.first.prepend('color: black; z-index: 1');
968 * @param nodes New nodes.
969 * @returns This container for chaining.
970 */
971 prepend(...nodes: (Node | object | string)[]): this;
972 /**
973 * Inserts new nodes to the end of the container.
974 * Because each node class is identifiable by unique properties, use the
975 * following shortcuts to create nodes in insert methods:
976 * root.append({ name: '@charset', params: '"UTF-8"' }); // at-rule
977 * root.append({ selector: 'a' }); // rule
978 * rule.append({ prop: 'color', value: 'black' }); // declaration
979 * rule.append({ text: 'Comment' }) // comment
980 * A string containing the CSS of the new element can also be used. This
981 * approach is slower than the above shortcuts.
982 * root.append('a {}');
983 * root.first.append('color: black; z-index: 1');
984 * @param nodes New nodes.
985 * @returns This container for chaining.
986 */
987 append(...nodes: (Node | object | string)[]): this;
988 /**
989 * Insert newNode before oldNode within the container.
990 * @param oldNode Child or child's index.
991 * @returns This container for chaining.
992 */
993 insertBefore(oldNode: ChildNode | number, newNode: ChildNode | object | string): this;
994 /**
995 * Insert newNode after oldNode within the container.
996 * @param oldNode Child or child's index.
997 * @returns This container for chaining.
998 */
999 insertAfter(oldNode: ChildNode | number, newNode: ChildNode | object | string): this;
1000 /**
1001 * Removes the container from its parent and cleans the parent property in the
1002 * container and its children.
1003 * @returns This container for chaining.
1004 */
1005 remove(): this;
1006 /**
1007 * Removes child from the container and cleans the parent properties
1008 * from the node and its children.
1009 * @param child Child or child's index.
1010 * @returns This container for chaining.
1011 */
1012 removeChild(child: ChildNode | number): this;
1013 /**
1014 * Removes all children from the container and cleans their parent
1015 * properties.
1016 * @returns This container for chaining.
1017 */
1018 removeAll(): this;
1019 }
1020 interface ContainerNewProps extends NodeNewProps {
1021 /**
1022 * Contains the container's children.
1023 */
1024 nodes?: ChildNode[];
1025 raws?: ContainerRaws;
1026 }
1027 interface ContainerRaws extends NodeRaws {
1028 indent?: string;
1029 }
1030 interface JsonContainer extends JsonNode {
1031 /**
1032 * Contains the container's children.
1033 */
1034 nodes?: ChildNode[];
1035 /**
1036 * @returns The container's first child.
1037 */
1038 first?: ChildNode;
1039 /**
1040 * @returns The container's last child.
1041 */
1042 last?: ChildNode;
1043 }
1044 /**
1045 * Represents a CSS file and contains all its parsed nodes.
1046 */
1047 interface Root extends ContainerBase {
1048 type: 'root';
1049 /**
1050 * Inherited from Container. Should always be undefined for a Root node.
1051 */
1052 parent: void;
1053 /**
1054 * @param overrides New properties to override in the clone.
1055 * @returns A clone of this node. The node and its (cloned) children will
1056 * have a clean parent and code style properties.
1057 */
1058 clone(overrides?: object): this;
1059 /**
1060 * @returns A Result instance representing the root's CSS.
1061 */
1062 toResult(options?: {
1063 /**
1064 * The path where you'll put the output CSS file. You should always
1065 * set "to" to generate correct source maps.
1066 */
1067 to?: string;
1068 map?: SourceMapOptions;
1069 }): Result;
1070 /**
1071 * Removes child from the root node, and the parent properties of node and
1072 * its children.
1073 * @param child Child or child's index.
1074 * @returns This root node for chaining.
1075 */
1076 removeChild(child: ChildNode | number): this;
1077 }
1078 interface RootNewProps extends ContainerNewProps {
1079 }
1080 interface JsonRoot extends JsonContainer {
1081 }
1082 /**
1083 * Represents an at-rule. If it's followed in the CSS by a {} block, this
1084 * node will have a nodes property representing its children.
1085 */
1086 interface AtRule extends ContainerBase {
1087 type: 'atrule';
1088 /**
1089 * Returns the atrule's parent node.
1090 */
1091 parent: Container;
1092 /**
1093 * The identifier that immediately follows the @.
1094 */
1095 name: string;
1096 /**
1097 * These are the values that follow the at-rule's name, but precede any {}
1098 * block. The spec refers to this area as the at-rule's "prelude".
1099 */
1100 params: string;
1101 /**
1102 * @param overrides New properties to override in the clone.
1103 * @returns A clone of this node. The node and its (cloned) children will
1104 * have a clean parent and code style properties.
1105 */
1106 clone(overrides?: object): this;
1107 }
1108 interface AtRuleNewProps extends ContainerNewProps {
1109 /**
1110 * The identifier that immediately follows the @.
1111 */
1112 name?: string;
1113 /**
1114 * These are the values that follow the at-rule's name, but precede any {}
1115 * block. The spec refers to this area as the at-rule's "prelude".
1116 */
1117 params?: string | number;
1118 raws?: AtRuleRaws;
1119 }
1120 interface AtRuleRaws extends NodeRaws {
1121 params?: string;
1122 }
1123 interface JsonAtRule extends JsonContainer {
1124 /**
1125 * The identifier that immediately follows the @.
1126 */
1127 name?: string;
1128 /**
1129 * These are the values that follow the at-rule's name, but precede any {}
1130 * block. The spec refers to this area as the at-rule's "prelude".
1131 */
1132 params?: string;
1133 }
1134 /**
1135 * Represents a CSS rule: a selector followed by a declaration block.
1136 */
1137 interface Rule extends ContainerBase {
1138 type: 'rule';
1139 /**
1140 * Returns the rule's parent node.
1141 */
1142 parent: Container;
1143 /**
1144 * The rule's full selector. If there are multiple comma-separated selectors,
1145 * the entire group will be included.
1146 */
1147 selector: string;
1148 /**
1149 * An array containing the rule's individual selectors.
1150 * Groups of selectors are split at commas.
1151 */
1152 selectors: string[];
1153 /**
1154 * @param overrides New properties to override in the clone.
1155 * @returns A clone of this node. The node and its (cloned) children will
1156 * have a clean parent and code style properties.
1157 */
1158 clone(overrides?: object): this;
1159 }
1160 interface RuleNewProps extends ContainerNewProps {
1161 /**
1162 * The rule's full selector. If there are multiple comma-separated selectors,
1163 * the entire group will be included.
1164 */
1165 selector?: string;
1166 /**
1167 * An array containing the rule's individual selectors. Groups of selectors
1168 * are split at commas.
1169 */
1170 selectors?: string[];
1171 raws?: RuleRaws;
1172 }
1173 interface RuleRaws extends ContainerRaws {
1174 /**
1175 * The rule's full selector. If there are multiple comma-separated selectors,
1176 * the entire group will be included.
1177 */
1178 selector?: string;
1179 }
1180 interface JsonRule extends JsonContainer {
1181 /**
1182 * The rule's full selector. If there are multiple comma-separated selectors,
1183 * the entire group will be included.
1184 */
1185 selector?: string;
1186 /**
1187 * An array containing the rule's individual selectors.
1188 * Groups of selectors are split at commas.
1189 */
1190 selectors?: string[];
1191 }
1192 /**
1193 * Represents a CSS declaration.
1194 */
1195 interface Declaration extends NodeBase {
1196 type: 'decl';
1197 /**
1198 * Returns the declaration's parent node.
1199 */
1200 parent: Container;
1201 /**
1202 * The declaration's property name.
1203 */
1204 prop: string;
1205 /**
1206 * The declaration's value. This value will be cleaned of comments. If the
1207 * source value contained comments, those comments will be available in the
1208 * _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).
1210 */
1211 value: string;
1212 /**
1213 * True if the declaration has an !important annotation.
1214 */
1215 important: boolean;
1216 /**
1217 * @param overrides New properties to override in the clone.
1218 * @returns A clone of this node. The node and its (cloned) children will
1219 * have a clean parent and code style properties.
1220 */
1221 clone(overrides?: object): this;
1222 }
1223 interface DeclarationNewProps {
1224 /**
1225 * The declaration's property name.
1226 */
1227 prop?: string;
1228 /**
1229 * The declaration's value. This value will be cleaned of comments. If the
1230 * source value contained comments, those comments will be available in the
1231 * _value.raws property. If you have not changed the value, the result of
1232 * decl.toString() will include the original raws value (comments and all).
1233 */
1234 value?: string;
1235 raws?: DeclarationRaws;
1236 }
1237 interface DeclarationRaws extends NodeRaws {
1238 /**
1239 * The declaration's value. This value will be cleaned of comments.
1240 * If the source value contained comments, those comments will be
1241 * available in the _value.raws property. If you have not changed the value, the result of
1242 * decl.toString() will include the original raws value (comments and all).
1243 */
1244 value?: string;
1245 }
1246 interface JsonDeclaration extends JsonNode {
1247 /**
1248 * True if the declaration has an !important annotation.
1249 */
1250 important?: boolean;
1251 }
1252 /**
1253 * Represents a comment between declarations or statements (rule and at-rules).
1254 * Comments inside selectors, at-rule parameters, or declaration values will
1255 * be stored in the Node#raws properties.
1256 */
1257 interface Comment extends NodeBase {
1258 type: 'comment';
1259 /**
1260 * Returns the comment's parent node.
1261 */
1262 parent: Container;
1263 /**
1264 * The comment's text.
1265 */
1266 text: string;
1267 /**
1268 * @param overrides New properties to override in the clone.
1269 * @returns A clone of this node. The node and its (cloned) children will
1270 * have a clean parent and code style properties.
1271 */
1272 clone(overrides?: object): this;
1273 }
1274 interface CommentNewProps {
1275 /**
1276 * The comment's text.
1277 */
1278 text?: string;
1279 }
1280 interface JsonComment extends JsonNode {
1281 }
1282}
1283export = postcss;
Note: See TracBrowser for help on using the repository browser.