postcss 6.0.9 → 6.0.13

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