postcss 8.4.24 → 8.4.26

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,28 +1,28 @@
1
- import { SourceMapGenerator, RawSourceMap } from 'source-map-js'
1
+ import { RawSourceMap, SourceMapGenerator } from 'source-map-js'
2
2
 
3
+ import AtRule, { AtRuleProps } from './at-rule.js'
4
+ import Comment, { CommentProps } from './comment.js'
5
+ import Container, { ContainerProps } from './container.js'
6
+ import CssSyntaxError from './css-syntax-error.js'
7
+ import Declaration, { DeclarationProps } from './declaration.js'
8
+ import Document, { DocumentProps } from './document.js'
9
+ import Input, { FilePosition } from './input.js'
10
+ import LazyResult from './lazy-result.js'
11
+ import list from './list.js'
3
12
  import Node, {
4
- Position,
5
- Source,
13
+ AnyNode,
6
14
  ChildNode,
15
+ ChildProps,
7
16
  NodeErrorOptions,
8
17
  NodeProps,
9
- ChildProps,
10
- AnyNode
18
+ Position,
19
+ Source
11
20
  } from './node.js'
12
- import Declaration, { DeclarationProps } from './declaration.js'
13
- import Container, { ContainerProps } from './container.js'
14
- import Document, { DocumentProps } from './document.js'
15
- import Warning, { WarningOptions } from './warning.js'
16
- import Comment, { CommentProps } from './comment.js'
17
- import AtRule, { AtRuleProps } from './at-rule.js'
18
- import Input, { FilePosition } from './input.js'
21
+ import Processor from './processor.js'
19
22
  import Result, { Message } from './result.js'
20
23
  import Root, { RootProps } from './root.js'
21
24
  import Rule, { RuleProps } from './rule.js'
22
- import CssSyntaxError from './css-syntax-error.js'
23
- import list from './list.js'
24
- import LazyResult from './lazy-result.js'
25
- import Processor from './processor.js'
25
+ import Warning, { WarningOptions } from './warning.js'
26
26
 
27
27
  type DocumentProcessor = (
28
28
  document: Document,
@@ -42,42 +42,33 @@ type CommentProcessor = (
42
42
 
43
43
  interface Processors {
44
44
  /**
45
- * Will be called on `Document` node.
45
+ * Will be called on all`AtRule` nodes.
46
46
  *
47
- * Will be called again on children changes.
47
+ * Will be called again on node or children changes.
48
48
  */
49
- Document?: DocumentProcessor
49
+ AtRule?: { [name: string]: AtRuleProcessor } | AtRuleProcessor
50
50
 
51
51
  /**
52
- * Will be called on `Document` node, when all children will be processed.
52
+ * Will be called on all `AtRule` nodes, when all children will be processed.
53
53
  *
54
- * Will be called again on children changes.
55
- */
56
- DocumentExit?: DocumentProcessor
57
-
58
- /**
59
- * Will be called on `Root` node once.
60
- */
61
- Once?: RootProcessor
62
-
63
- /**
64
- * Will be called on `Root` node once, when all children will be processed.
54
+ * Will be called again on node or children changes.
65
55
  */
66
- OnceExit?: RootProcessor
56
+ AtRuleExit?: { [name: string]: AtRuleProcessor } | AtRuleProcessor
67
57
 
68
58
  /**
69
- * Will be called on `Root` node.
59
+ * Will be called on all `Comment` nodes.
70
60
  *
71
- * Will be called again on children changes.
61
+ * Will be called again on node or children changes.
72
62
  */
73
- Root?: RootProcessor
63
+ Comment?: CommentProcessor
74
64
 
75
65
  /**
76
- * Will be called on `Root` node, when all children will be processed.
66
+ * Will be called on all `Comment` nodes after listeners
67
+ * for `Comment` event.
77
68
  *
78
- * Will be called again on children changes.
69
+ * Will be called again on node or children changes.
79
70
  */
80
- RootExit?: RootProcessor
71
+ CommentExit?: CommentProcessor
81
72
 
82
73
  /**
83
74
  * Will be called on all `Declaration` nodes after listeners
@@ -85,7 +76,7 @@ interface Processors {
85
76
  *
86
77
  * Will be called again on node or children changes.
87
78
  */
88
- Declaration?: DeclarationProcessor | { [prop: string]: DeclarationProcessor }
79
+ Declaration?: { [prop: string]: DeclarationProcessor } | DeclarationProcessor
89
80
 
90
81
  /**
91
82
  * Will be called on all `Declaration` nodes.
@@ -93,94 +84,103 @@ interface Processors {
93
84
  * Will be called again on node or children changes.
94
85
  */
95
86
  DeclarationExit?:
96
- | DeclarationProcessor
97
87
  | { [prop: string]: DeclarationProcessor }
88
+ | DeclarationProcessor
98
89
 
99
90
  /**
100
- * Will be called on all `Rule` nodes.
91
+ * Will be called on `Document` node.
101
92
  *
102
- * Will be called again on node or children changes.
93
+ * Will be called again on children changes.
103
94
  */
104
- Rule?: RuleProcessor
95
+ Document?: DocumentProcessor
105
96
 
106
97
  /**
107
- * Will be called on all `Rule` nodes, when all children will be processed.
98
+ * Will be called on `Document` node, when all children will be processed.
108
99
  *
109
- * Will be called again on node or children changes.
100
+ * Will be called again on children changes.
110
101
  */
111
- RuleExit?: RuleProcessor
102
+ DocumentExit?: DocumentProcessor
112
103
 
113
104
  /**
114
- * Will be called on all`AtRule` nodes.
105
+ * Will be called on `Root` node once.
106
+ */
107
+ Once?: RootProcessor
108
+
109
+ /**
110
+ * Will be called on `Root` node once, when all children will be processed.
111
+ */
112
+ OnceExit?: RootProcessor
113
+
114
+ /**
115
+ * Will be called on `Root` node.
115
116
  *
116
- * Will be called again on node or children changes.
117
+ * Will be called again on children changes.
117
118
  */
118
- AtRule?: AtRuleProcessor | { [name: string]: AtRuleProcessor }
119
+ Root?: RootProcessor
119
120
 
120
121
  /**
121
- * Will be called on all `AtRule` nodes, when all children will be processed.
122
+ * Will be called on `Root` node, when all children will be processed.
122
123
  *
123
- * Will be called again on node or children changes.
124
+ * Will be called again on children changes.
124
125
  */
125
- AtRuleExit?: AtRuleProcessor | { [name: string]: AtRuleProcessor }
126
+ RootExit?: RootProcessor
126
127
 
127
128
  /**
128
- * Will be called on all `Comment` nodes.
129
+ * Will be called on all `Rule` nodes.
129
130
  *
130
131
  * Will be called again on node or children changes.
131
132
  */
132
- Comment?: CommentProcessor
133
+ Rule?: RuleProcessor
133
134
 
134
135
  /**
135
- * Will be called on all `Comment` nodes after listeners
136
- * for `Comment` event.
136
+ * Will be called on all `Rule` nodes, when all children will be processed.
137
137
  *
138
138
  * Will be called again on node or children changes.
139
139
  */
140
- CommentExit?: CommentProcessor
140
+ RuleExit?: RuleProcessor
141
141
  }
142
142
 
143
143
  declare namespace postcss {
144
144
  export {
145
- NodeErrorOptions,
146
- DeclarationProps,
147
- CssSyntaxError,
145
+ AnyNode,
146
+ AtRule,
147
+ AtRuleProps,
148
+ ChildNode,
149
+ ChildProps,
150
+ Comment,
151
+ CommentProps,
152
+ Container,
148
153
  ContainerProps,
149
- WarningOptions,
154
+ CssSyntaxError,
155
+ Declaration,
156
+ DeclarationProps,
157
+ Document,
150
158
  DocumentProps,
151
159
  FilePosition,
152
- CommentProps,
153
- AtRuleProps,
154
- Declaration,
155
- ChildProps,
160
+ Input,
156
161
  LazyResult,
157
- ChildNode,
162
+ list,
163
+ Message,
164
+ Node,
165
+ NodeErrorOptions,
158
166
  NodeProps,
159
- Processor,
160
- RuleProps,
161
- RootProps,
162
- Container,
163
167
  Position,
164
- Document,
165
- AnyNode,
166
- Warning,
167
- Message,
168
- Comment,
169
- Source,
170
- AtRule,
168
+ Processor,
171
169
  Result,
172
- Input,
173
- Node,
174
- list,
170
+ Root,
171
+ RootProps,
175
172
  Rule,
176
- Root
173
+ RuleProps,
174
+ Source,
175
+ Warning,
176
+ WarningOptions
177
177
  }
178
178
 
179
179
  export type SourceMap = SourceMapGenerator & {
180
180
  toJSON(): RawSourceMap
181
181
  }
182
182
 
183
- export type Helpers = { result: Result; postcss: Postcss } & Postcss
183
+ export type Helpers = { postcss: Postcss; result: Result } & Postcss
184
184
 
185
185
  export interface Plugin extends Processors {
186
186
  postcssPlugin: string
@@ -207,24 +207,24 @@ declare namespace postcss {
207
207
  }
208
208
 
209
209
  export type AcceptedPlugin =
210
- | Plugin
211
- | PluginCreator<any>
212
- | OldPlugin<any>
213
- | TransformCallback
214
210
  | {
215
- postcss: TransformCallback | Processor
211
+ postcss: Processor | TransformCallback
216
212
  }
213
+ | OldPlugin<any>
214
+ | Plugin
215
+ | PluginCreator<any>
217
216
  | Processor
217
+ | TransformCallback
218
218
 
219
- export interface Parser<RootNode = Root | Document> {
219
+ export interface Parser<RootNode = Document | Root> {
220
220
  (
221
- css: string | { toString(): string },
222
- opts?: Pick<ProcessOptions, 'map' | 'from'>
221
+ css: { toString(): string } | string,
222
+ opts?: Pick<ProcessOptions, 'from' | 'map'>
223
223
  ): RootNode
224
224
  }
225
225
 
226
226
  export interface Builder {
227
- (part: string, node?: AnyNode, type?: 'start' | 'end'): void
227
+ (part: string, node?: AnyNode, type?: 'end' | 'start'): void
228
228
  }
229
229
 
230
230
  export interface Stringifier {
@@ -232,8 +232,8 @@ declare namespace postcss {
232
232
  }
233
233
 
234
234
  export interface JSONHydrator {
235
- (data: object[]): Node[]
236
235
  (data: object): Node
236
+ (data: object[]): Node[]
237
237
  }
238
238
 
239
239
  export interface Syntax {
@@ -249,6 +249,30 @@ declare namespace postcss {
249
249
  }
250
250
 
251
251
  export interface SourceMapOptions {
252
+ /**
253
+ * Use absolute path in generated source map.
254
+ */
255
+ absolute?: boolean
256
+
257
+ /**
258
+ * Indicates that PostCSS should add annotation comments to the CSS.
259
+ * By default, PostCSS will always add a comment with a path
260
+ * to the source map. PostCSS will not add annotations to CSS files
261
+ * that do not contain any comments.
262
+ *
263
+ * By default, PostCSS presumes that you want to save the source map as
264
+ * `opts.to + '.map'` and will use this path in the annotation comment.
265
+ * A different path can be set by providing a string value for annotation.
266
+ *
267
+ * If you have set `inline: true`, annotation cannot be disabled.
268
+ */
269
+ annotation?: ((file: string, root: Root) => string) | boolean | string
270
+
271
+ /**
272
+ * Override `from` in map’s sources.
273
+ */
274
+ from?: string
275
+
252
276
  /**
253
277
  * Indicates that the source map should be embedded in the output CSS
254
278
  * as a Base64-encoded comment. By default, it is `true`.
@@ -269,7 +293,7 @@ declare namespace postcss {
269
293
  *
270
294
  * If desired, you can omit the previous map with prev: `false`.
271
295
  */
272
- prev?: string | boolean | object | ((file: string) => string)
296
+ prev?: ((file: string) => string) | boolean | object | string
273
297
 
274
298
  /**
275
299
  * Indicates that PostCSS should set the origin content (e.g., Sass source)
@@ -278,30 +302,6 @@ declare namespace postcss {
278
302
  * do not set this option.
279
303
  */
280
304
  sourcesContent?: boolean
281
-
282
- /**
283
- * Indicates that PostCSS should add annotation comments to the CSS.
284
- * By default, PostCSS will always add a comment with a path
285
- * to the source map. PostCSS will not add annotations to CSS files
286
- * that do not contain any comments.
287
- *
288
- * By default, PostCSS presumes that you want to save the source map as
289
- * `opts.to + '.map'` and will use this path in the annotation comment.
290
- * A different path can be set by providing a string value for annotation.
291
- *
292
- * If you have set `inline: true`, annotation cannot be disabled.
293
- */
294
- annotation?: string | boolean | ((file: string, root: Root) => string)
295
-
296
- /**
297
- * Override `from` in map’s sources.
298
- */
299
- from?: string
300
-
301
- /**
302
- * Use absolute path in generated source map.
303
- */
304
- absolute?: boolean
305
305
  }
306
306
 
307
307
  export interface ProcessOptions {
@@ -312,20 +312,19 @@ declare namespace postcss {
312
312
  from?: string
313
313
 
314
314
  /**
315
- * The path where you'll put the output CSS file. You should always set `to`
316
- * to generate correct source maps.
315
+ * Source map options
317
316
  */
318
- to?: string
317
+ map?: boolean | SourceMapOptions
319
318
 
320
319
  /**
321
320
  * Function to generate AST by string.
322
321
  */
323
- parser?: Syntax | Parser
322
+ parser?: Parser | Syntax
324
323
 
325
324
  /**
326
325
  * Class to generate string by AST.
327
326
  */
328
- stringifier?: Syntax | Stringifier
327
+ stringifier?: Stringifier | Syntax
329
328
 
330
329
  /**
331
330
  * Object with parse and stringify.
@@ -333,9 +332,10 @@ declare namespace postcss {
333
332
  syntax?: Syntax
334
333
 
335
334
  /**
336
- * Source map options
335
+ * The path where you'll put the output CSS file. You should always set `to`
336
+ * to generate correct source maps.
337
337
  */
338
- map?: SourceMapOptions | boolean
338
+ to?: string
339
339
  }
340
340
 
341
341
  export type Postcss = typeof postcss
@@ -21,35 +21,35 @@ declare namespace PreviousMap {
21
21
  */
22
22
  declare class PreviousMap_ {
23
23
  /**
24
- * Was source map inlined by data-uri to input CSS.
24
+ * `sourceMappingURL` content.
25
25
  */
26
- inline: boolean
26
+ annotation?: string
27
27
 
28
28
  /**
29
- * `sourceMappingURL` content.
29
+ * The CSS source identifier. Contains `Input#file` if the user
30
+ * set the `from` option, or `Input#id` if they did not.
30
31
  */
31
- annotation?: string
32
+ file?: string
32
33
 
33
34
  /**
34
- * Source map file content.
35
+ * Was source map inlined by data-uri to input CSS.
35
36
  */
36
- text?: string
37
+ inline: boolean
37
38
 
38
39
  /**
39
- * The directory with source map file, if source map is in separated file.
40
+ * Path to source map file.
40
41
  */
41
- root?: string
42
+ mapFile?: string
42
43
 
43
44
  /**
44
- * The CSS source identifier. Contains `Input#file` if the user
45
- * set the `from` option, or `Input#id` if they did not.
45
+ * The directory with source map file, if source map is in separated file.
46
46
  */
47
- file?: string
47
+ root?: string
48
48
 
49
49
  /**
50
- * Path to source map file.
50
+ * Source map file content.
51
51
  */
52
- mapFile?: string
52
+ text?: string
53
53
 
54
54
  /**
55
55
  * @param css Input CSS source.
@@ -35,22 +35,37 @@ class PreviousMap {
35
35
  return this.consumerCache
36
36
  }
37
37
 
38
- withContent() {
39
- return !!(
40
- this.consumer().sourcesContent &&
41
- this.consumer().sourcesContent.length > 0
42
- )
43
- }
38
+ decodeInline(text) {
39
+ let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/
40
+ let baseUri = /^data:application\/json;base64,/
41
+ let charsetUri = /^data:application\/json;charset=utf-?8,/
42
+ let uri = /^data:application\/json,/
44
43
 
45
- startWith(string, start) {
46
- if (!string) return false
47
- return string.substr(0, start.length) === start
44
+ if (charsetUri.test(text) || uri.test(text)) {
45
+ return decodeURIComponent(text.substr(RegExp.lastMatch.length))
46
+ }
47
+
48
+ if (baseCharsetUri.test(text) || baseUri.test(text)) {
49
+ return fromBase64(text.substr(RegExp.lastMatch.length))
50
+ }
51
+
52
+ let encoding = text.match(/data:application\/json;([^,]+),/)[1]
53
+ throw new Error('Unsupported source map encoding ' + encoding)
48
54
  }
49
55
 
50
56
  getAnnotationURL(sourceMapString) {
51
57
  return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
52
58
  }
53
59
 
60
+ isMap(map) {
61
+ if (typeof map !== 'object') return false
62
+ return (
63
+ typeof map.mappings === 'string' ||
64
+ typeof map._mappings === 'string' ||
65
+ Array.isArray(map.sections)
66
+ )
67
+ }
68
+
54
69
  loadAnnotation(css) {
55
70
  let comments = css.match(/\/\*\s*# sourceMappingURL=/gm)
56
71
  if (!comments) return
@@ -65,24 +80,6 @@ class PreviousMap {
65
80
  }
66
81
  }
67
82
 
68
- decodeInline(text) {
69
- let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/
70
- let baseUri = /^data:application\/json;base64,/
71
- let charsetUri = /^data:application\/json;charset=utf-?8,/
72
- let uri = /^data:application\/json,/
73
-
74
- if (charsetUri.test(text) || uri.test(text)) {
75
- return decodeURIComponent(text.substr(RegExp.lastMatch.length))
76
- }
77
-
78
- if (baseCharsetUri.test(text) || baseUri.test(text)) {
79
- return fromBase64(text.substr(RegExp.lastMatch.length))
80
- }
81
-
82
- let encoding = text.match(/data:application\/json;([^,]+),/)[1]
83
- throw new Error('Unsupported source map encoding ' + encoding)
84
- }
85
-
86
83
  loadFile(path) {
87
84
  this.root = dirname(path)
88
85
  if (existsSync(path)) {
@@ -128,12 +125,15 @@ class PreviousMap {
128
125
  }
129
126
  }
130
127
 
131
- isMap(map) {
132
- if (typeof map !== 'object') return false
133
- return (
134
- typeof map.mappings === 'string' ||
135
- typeof map._mappings === 'string' ||
136
- Array.isArray(map.sections)
128
+ startWith(string, start) {
129
+ if (!string) return false
130
+ return string.substr(0, start.length) === start
131
+ }
132
+
133
+ withContent() {
134
+ return !!(
135
+ this.consumer().sourcesContent &&
136
+ this.consumer().sourcesContent.length > 0
137
137
  )
138
138
  }
139
139
  }
@@ -1,14 +1,14 @@
1
+ import LazyResult from './lazy-result.js'
2
+ import NoWorkResult from './no-work-result.js'
1
3
  import {
2
4
  AcceptedPlugin,
3
5
  Plugin,
4
6
  ProcessOptions,
5
- Transformer,
6
- TransformCallback
7
+ TransformCallback,
8
+ Transformer
7
9
  } from './postcss.js'
8
- import LazyResult from './lazy-result.js'
9
10
  import Result from './result.js'
10
11
  import Root from './root.js'
11
- import NoWorkResult from './no-work-result.js'
12
12
 
13
13
  declare namespace Processor {
14
14
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -27,31 +27,55 @@ declare namespace Processor {
27
27
  */
28
28
  declare class Processor_ {
29
29
  /**
30
- * Current PostCSS version.
30
+ * Plugins added to this processor.
31
31
  *
32
32
  * ```js
33
- * if (result.processor.version.split('.')[0] !== '6') {
34
- * throw new Error('This plugin works only with PostCSS 6')
35
- * }
33
+ * const processor = postcss([autoprefixer, postcssNested])
34
+ * processor.plugins.length //=> 2
36
35
  * ```
37
36
  */
38
- version: string
37
+ plugins: (Plugin | TransformCallback | Transformer)[]
39
38
 
40
39
  /**
41
- * Plugins added to this processor.
40
+ * Current PostCSS version.
42
41
  *
43
42
  * ```js
44
- * const processor = postcss([autoprefixer, postcssNested])
45
- * processor.plugins.length //=> 2
43
+ * if (result.processor.version.split('.')[0] !== '6') {
44
+ * throw new Error('This plugin works only with PostCSS 6')
45
+ * }
46
46
  * ```
47
47
  */
48
- plugins: (Plugin | Transformer | TransformCallback)[]
48
+ version: string
49
49
 
50
50
  /**
51
51
  * @param plugins PostCSS plugins
52
52
  */
53
53
  constructor(plugins?: AcceptedPlugin[])
54
54
 
55
+ /**
56
+ * Parses source CSS and returns a `LazyResult` Promise proxy.
57
+ * Because some plugins can be asynchronous it doesn’t make
58
+ * any transformations. Transformations will be applied
59
+ * in the `LazyResult` methods.
60
+ *
61
+ * ```js
62
+ * processor.process(css, { from: 'a.css', to: 'a.out.css' })
63
+ * .then(result => {
64
+ * console.log(result.css)
65
+ * })
66
+ * ```
67
+ *
68
+ * @param css String with input CSS or any object with a `toString()` method,
69
+ * like a Buffer. Optionally, send a `Result` instance
70
+ * and the processor will take the `Root` from it.
71
+ * @param opts Options.
72
+ * @return Promise proxy.
73
+ */
74
+ process(
75
+ css: { toString(): string } | LazyResult | Result | Root | string,
76
+ options?: ProcessOptions
77
+ ): LazyResult | NoWorkResult
78
+
55
79
  /**
56
80
  * Adds a plugin to be used as a CSS processor.
57
81
  *
@@ -80,30 +104,6 @@ declare class Processor_ {
80
104
  * @return Current processor to make methods chain.
81
105
  */
82
106
  use(plugin: AcceptedPlugin): this
83
-
84
- /**
85
- * Parses source CSS and returns a `LazyResult` Promise proxy.
86
- * Because some plugins can be asynchronous it doesn’t make
87
- * any transformations. Transformations will be applied
88
- * in the `LazyResult` methods.
89
- *
90
- * ```js
91
- * processor.process(css, { from: 'a.css', to: 'a.out.css' })
92
- * .then(result => {
93
- * console.log(result.css)
94
- * })
95
- * ```
96
- *
97
- * @param css String with input CSS or any object with a `toString()` method,
98
- * like a Buffer. Optionally, send a `Result` instance
99
- * and the processor will take the `Root` from it.
100
- * @param opts Options.
101
- * @return Promise proxy.
102
- */
103
- process(
104
- css: string | { toString(): string } | Result | LazyResult | Root,
105
- options?: ProcessOptions
106
- ): LazyResult | NoWorkResult
107
107
  }
108
108
 
109
109
  declare class Processor extends Processor_ {}