postcss 6.0.22 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of postcss might be problematic. Click here for more details.

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