postcss 8.4.23 → 8.4.25

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.

@@ -1,20 +1,20 @@
1
- import Node, { ChildNode, NodeProps, ChildProps } from './node.js'
2
- import Declaration from './declaration.js'
3
- import Comment from './comment.js'
4
1
  import AtRule from './at-rule.js'
2
+ import Comment from './comment.js'
3
+ import Declaration from './declaration.js'
4
+ import Node, { ChildNode, ChildProps, NodeProps } from './node.js'
5
5
  import Rule from './rule.js'
6
6
 
7
7
  declare namespace Container {
8
8
  export interface ValueOptions {
9
9
  /**
10
- * An array of property names.
10
+ * String that’s used to narrow down values and speed up the regexp search.
11
11
  */
12
- props?: string[]
12
+ fast?: string
13
13
 
14
14
  /**
15
- * String that’s used to narrow down values and speed up the regexp search.
15
+ * An array of property names.
16
16
  */
17
- fast?: string
17
+ props?: string[]
18
18
  }
19
19
 
20
20
  export interface ContainerProps extends NodeProps {
@@ -48,22 +48,28 @@ declare abstract class Container_<
48
48
  nodes: Child[]
49
49
 
50
50
  /**
51
- * The container’s first child.
51
+ * Inserts new nodes to the end of the container.
52
52
  *
53
53
  * ```js
54
- * rule.first === rules.nodes[0]
55
- * ```
56
- */
57
- get first(): Child | undefined
58
-
59
- /**
60
- * The container’s last child.
54
+ * const decl1 = new Declaration({ prop: 'color', value: 'black' })
55
+ * const decl2 = new Declaration({ prop: 'background-color', value: 'white' })
56
+ * rule.append(decl1, decl2)
61
57
  *
62
- * ```js
63
- * rule.last === rule.nodes[rule.nodes.length - 1]
58
+ * root.append({ name: 'charset', params: '"UTF-8"' }) // at-rule
59
+ * root.append({ selector: 'a' }) // rule
60
+ * rule.append({ prop: 'color', value: 'black' }) // declaration
61
+ * rule.append({ text: 'Comment' }) // comment
62
+ *
63
+ * root.append('a {}')
64
+ * root.first.append('color: black; z-index: 1')
64
65
  * ```
66
+ *
67
+ * @param nodes New nodes.
68
+ * @return This node for methods chain.
65
69
  */
66
- get last(): Child | undefined
70
+ append(
71
+ ...nodes: (ChildProps | ChildProps[] | Node | Node[] | string | string[])[]
72
+ ): this
67
73
 
68
74
  /**
69
75
  * Iterates through the container’s immediate children,
@@ -103,179 +109,75 @@ declare abstract class Container_<
103
109
  ): false | undefined
104
110
 
105
111
  /**
106
- * Traverses the container’s descendant nodes, calling callback
107
- * for each node.
108
- *
109
- * Like container.each(), this method is safe to use
110
- * if you are mutating arrays during iteration.
111
- *
112
- * If you only need to iterate through the container’s immediate children,
113
- * use `Container#each`.
112
+ * Returns `true` if callback returns `true`
113
+ * for all of the container’s children.
114
114
  *
115
115
  * ```js
116
- * root.walk(node => {
117
- * // Traverses all descendant nodes.
118
- * })
116
+ * const noPrefixes = rule.every(i => i.prop[0] !== '-')
119
117
  * ```
120
118
  *
121
- * @param callback Iterator receives each node and index.
122
- * @return Returns `false` if iteration was broke.
119
+ * @param condition Iterator returns true or false.
120
+ * @return Is every child pass condition.
123
121
  */
124
- walk(
125
- callback: (node: ChildNode, index: number) => false | void
126
- ): false | undefined
122
+ every(
123
+ condition: (node: Child, index: number, nodes: Child[]) => boolean
124
+ ): boolean
127
125
 
128
126
  /**
129
- * Traverses the container’s descendant nodes, calling callback
130
- * for each declaration node.
131
- *
132
- * If you pass a filter, iteration will only happen over declarations
133
- * with matching properties.
127
+ * The container’s first child.
134
128
  *
135
129
  * ```js
136
- * root.walkDecls(decl => {
137
- * checkPropertySupport(decl.prop)
138
- * })
139
- *
140
- * root.walkDecls('border-radius', decl => {
141
- * decl.remove()
142
- * })
143
- *
144
- * root.walkDecls(/^background/, decl => {
145
- * decl.value = takeFirstColorFromGradient(decl.value)
146
- * })
130
+ * rule.first === rules.nodes[0]
147
131
  * ```
148
- *
149
- * Like `Container#each`, this method is safe
150
- * to use if you are mutating arrays during iteration.
151
- *
152
- * @param prop String or regular expression to filter declarations
153
- * by property name.
154
- * @param callback Iterator receives each node and index.
155
- * @return Returns `false` if iteration was broke.
156
132
  */
157
- walkDecls(
158
- propFilter: string | RegExp,
159
- callback: (decl: Declaration, index: number) => false | void
160
- ): false | undefined
161
- walkDecls(
162
- callback: (decl: Declaration, index: number) => false | void
163
- ): false | undefined
133
+ get first(): Child | undefined
164
134
 
165
135
  /**
166
- * Traverses the container’s descendant nodes, calling callback
167
- * for each rule node.
168
- *
169
- * If you pass a filter, iteration will only happen over rules
170
- * with matching selectors.
171
- *
172
- * Like `Container#each`, this method is safe
173
- * to use if you are mutating arrays during iteration.
136
+ * Returns a `child`’s index within the `Container#nodes` array.
174
137
  *
175
138
  * ```js
176
- * const selectors = []
177
- * root.walkRules(rule => {
178
- * selectors.push(rule.selector)
179
- * })
180
- * console.log(`Your CSS uses ${ selectors.length } selectors`)
139
+ * rule.index( rule.nodes[2] ) //=> 2
181
140
  * ```
182
141
  *
183
- * @param selector String or regular expression to filter rules by selector.
184
- * @param callback Iterator receives each node and index.
185
- * @return Returns `false` if iteration was broke.
142
+ * @param child Child of the current container.
143
+ * @return Child index.
186
144
  */
187
- walkRules(
188
- selectorFilter: string | RegExp,
189
- callback: (rule: Rule, index: number) => false | void
190
- ): false | undefined
191
- walkRules(
192
- callback: (rule: Rule, index: number) => false | void
193
- ): false | undefined
194
-
145
+ index(child: Child | number): number
195
146
  /**
196
- * Traverses the container’s descendant nodes, calling callback
197
- * for each at-rule node.
198
- *
199
- * If you pass a filter, iteration will only happen over at-rules
200
- * that have matching names.
201
- *
202
- * Like `Container#each`, this method is safe
203
- * to use if you are mutating arrays during iteration.
204
- *
205
- * ```js
206
- * root.walkAtRules(rule => {
207
- * if (isOld(rule.name)) rule.remove()
208
- * })
209
- *
210
- * let first = false
211
- * root.walkAtRules('charset', rule => {
212
- * if (!first) {
213
- * first = true
214
- * } else {
215
- * rule.remove()
216
- * }
217
- * })
218
- * ```
147
+ * Insert new node after old node within the container.
219
148
  *
220
- * @param name String or regular expression to filter at-rules by name.
221
- * @param callback Iterator receives each node and index.
222
- * @return Returns `false` if iteration was broke.
149
+ * @param oldNode Child or child’s index.
150
+ * @param newNode New node.
151
+ * @return This node for methods chain.
223
152
  */
224
- walkAtRules(
225
- nameFilter: string | RegExp,
226
- callback: (atRule: AtRule, index: number) => false | void
227
- ): false | undefined
228
- walkAtRules(
229
- callback: (atRule: AtRule, index: number) => false | void
230
- ): false | undefined
153
+ insertAfter(
154
+ oldNode: Child | number,
155
+ newNode: Child | Child[] | ChildProps | ChildProps[] | string | string[]
156
+ ): this
231
157
 
232
158
  /**
233
- * Traverses the container’s descendant nodes, calling callback
234
- * for each comment node.
235
- *
236
- * Like `Container#each`, this method is safe
237
- * to use if you are mutating arrays during iteration.
159
+ * Insert new node before old node within the container.
238
160
  *
239
161
  * ```js
240
- * root.walkComments(comment => {
241
- * comment.remove()
242
- * })
162
+ * rule.insertBefore(decl, decl.clone({ prop: '-webkit-' + decl.prop }))
243
163
  * ```
244
164
  *
245
- * @param callback Iterator receives each node and index.
246
- * @return Returns `false` if iteration was broke.
165
+ * @param oldNode Child or child’s index.
166
+ * @param newNode New node.
167
+ * @return This node for methods chain.
247
168
  */
248
-
249
- walkComments(
250
- callback: (comment: Comment, indexed: number) => false | void
251
- ): false | undefined
252
- walkComments(
253
- callback: (comment: Comment, indexed: number) => false | void
254
- ): false | undefined
255
-
169
+ insertBefore(
170
+ oldNode: Child | number,
171
+ newNode: Child | Child[] | ChildProps | ChildProps[] | string | string[]
172
+ ): this
256
173
  /**
257
- * Inserts new nodes to the end of the container.
174
+ * The container’s last child.
258
175
  *
259
176
  * ```js
260
- * const decl1 = new Declaration({ prop: 'color', value: 'black' })
261
- * const decl2 = new Declaration({ prop: 'background-color', value: 'white' })
262
- * rule.append(decl1, decl2)
263
- *
264
- * root.append({ name: 'charset', params: '"UTF-8"' }) // at-rule
265
- * root.append({ selector: 'a' }) // rule
266
- * rule.append({ prop: 'color', value: 'black' }) // declaration
267
- * rule.append({ text: 'Comment' }) // comment
268
- *
269
- * root.append('a {}')
270
- * root.first.append('color: black; z-index: 1')
177
+ * rule.last === rule.nodes[rule.nodes.length - 1]
271
178
  * ```
272
- *
273
- * @param nodes New nodes.
274
- * @return This node for methods chain.
275
179
  */
276
- append(
277
- ...nodes: (Node | Node[] | ChildProps | ChildProps[] | string | string[])[]
278
- ): this
180
+ get last(): Child | undefined
279
181
 
280
182
  /**
281
183
  * Inserts new nodes to the start of the container.
@@ -298,9 +200,8 @@ declare abstract class Container_<
298
200
  * @return This node for methods chain.
299
201
  */
300
202
  prepend(
301
- ...nodes: (Node | Node[] | ChildProps | ChildProps[] | string | string[])[]
203
+ ...nodes: (ChildProps | ChildProps[] | Node | Node[] | string | string[])[]
302
204
  ): this
303
-
304
205
  /**
305
206
  * Add child to the end of the node.
306
207
  *
@@ -314,33 +215,34 @@ declare abstract class Container_<
314
215
  push(child: Child): this
315
216
 
316
217
  /**
317
- * Insert new node before old node within the container.
218
+ * Traverses the container’s descendant nodes, calling callback
219
+ * for each comment node.
220
+ *
221
+ * Like `Container#each`, this method is safe
222
+ * to use if you are mutating arrays during iteration.
318
223
  *
319
224
  * ```js
320
- * rule.insertBefore(decl, decl.clone({ prop: '-webkit-' + decl.prop }))
225
+ * root.walkComments(comment => {
226
+ * comment.remove()
227
+ * })
321
228
  * ```
322
229
  *
323
- * @param oldNode Child or child’s index.
324
- * @param newNode New node.
325
- * @return This node for methods chain.
230
+ * @param callback Iterator receives each node and index.
231
+ * @return Returns `false` if iteration was broke.
326
232
  */
327
- insertBefore(
328
- oldNode: Child | number,
329
- newNode: Child | ChildProps | string | Child[] | ChildProps[] | string[]
330
- ): this
331
233
 
332
234
  /**
333
- * Insert new node after old node within the container.
235
+ * Removes all children from the container
236
+ * and cleans their parent properties.
237
+ *
238
+ * ```js
239
+ * rule.removeAll()
240
+ * rule.nodes.length //=> 0
241
+ * ```
334
242
  *
335
- * @param oldNode Child or child’s index.
336
- * @param newNode New node.
337
243
  * @return This node for methods chain.
338
244
  */
339
- insertAfter(
340
- oldNode: Child | number,
341
- newNode: Child | ChildProps | string | Child[] | ChildProps[] | string[]
342
- ): this
343
-
245
+ removeAll(): this
344
246
  /**
345
247
  * Removes node from the container and cleans the parent properties
346
248
  * from the node and its children.
@@ -357,19 +259,6 @@ declare abstract class Container_<
357
259
  */
358
260
  removeChild(child: Child | number): this
359
261
 
360
- /**
361
- * Removes all children from the container
362
- * and cleans their parent properties.
363
- *
364
- * ```js
365
- * rule.removeAll()
366
- * rule.nodes.length //=> 0
367
- * ```
368
- *
369
- * @return This node for methods chain.
370
- */
371
- removeAll(): this
372
-
373
262
  /**
374
263
  * Passes all declaration values within the container that match pattern
375
264
  * through callback, replacing those values with the returned result
@@ -394,56 +283,167 @@ declare abstract class Container_<
394
283
  * @return This node for methods chain.
395
284
  */
396
285
  replaceValues(
397
- pattern: string | RegExp,
286
+ pattern: RegExp | string,
398
287
  options: Container.ValueOptions,
399
- replaced: string | { (substring: string, ...args: any[]): string }
288
+ replaced: { (substring: string, ...args: any[]): string } | string
400
289
  ): this
290
+
401
291
  replaceValues(
402
- pattern: string | RegExp,
403
- replaced: string | { (substring: string, ...args: any[]): string }
292
+ pattern: RegExp | string,
293
+ replaced: { (substring: string, ...args: any[]): string } | string
404
294
  ): this
405
295
 
406
296
  /**
407
- * Returns `true` if callback returns `true`
408
- * for all of the container’s children.
297
+ * Returns `true` if callback returns `true` for (at least) one
298
+ * of the container’s children.
409
299
  *
410
300
  * ```js
411
- * const noPrefixes = rule.every(i => i.prop[0] !== '-')
301
+ * const hasPrefix = rule.some(i => i.prop[0] === '-')
412
302
  * ```
413
303
  *
414
304
  * @param condition Iterator returns true or false.
415
- * @return Is every child pass condition.
305
+ * @return Is some child pass condition.
416
306
  */
417
- every(
307
+ some(
418
308
  condition: (node: Child, index: number, nodes: Child[]) => boolean
419
309
  ): boolean
420
310
 
421
311
  /**
422
- * Returns `true` if callback returns `true` for (at least) one
423
- * of the container’s children.
312
+ * Traverses the container’s descendant nodes, calling callback
313
+ * for each node.
314
+ *
315
+ * Like container.each(), this method is safe to use
316
+ * if you are mutating arrays during iteration.
317
+ *
318
+ * If you only need to iterate through the container’s immediate children,
319
+ * use `Container#each`.
424
320
  *
425
321
  * ```js
426
- * const hasPrefix = rule.some(i => i.prop[0] === '-')
322
+ * root.walk(node => {
323
+ * // Traverses all descendant nodes.
324
+ * })
427
325
  * ```
428
326
  *
429
- * @param condition Iterator returns true or false.
430
- * @return Is some child pass condition.
327
+ * @param callback Iterator receives each node and index.
328
+ * @return Returns `false` if iteration was broke.
431
329
  */
432
- some(
433
- condition: (node: Child, index: number, nodes: Child[]) => boolean
434
- ): boolean
330
+ walk(
331
+ callback: (node: ChildNode, index: number) => false | void
332
+ ): false | undefined
333
+
334
+ walkAtRules(
335
+ callback: (atRule: AtRule, index: number) => false | void
336
+ ): false | undefined
435
337
 
436
338
  /**
437
- * Returns a `child`’s index within the `Container#nodes` array.
339
+ * Traverses the container’s descendant nodes, calling callback
340
+ * for each at-rule node.
341
+ *
342
+ * If you pass a filter, iteration will only happen over at-rules
343
+ * that have matching names.
344
+ *
345
+ * Like `Container#each`, this method is safe
346
+ * to use if you are mutating arrays during iteration.
438
347
  *
439
348
  * ```js
440
- * rule.index( rule.nodes[2] ) //=> 2
349
+ * root.walkAtRules(rule => {
350
+ * if (isOld(rule.name)) rule.remove()
351
+ * })
352
+ *
353
+ * let first = false
354
+ * root.walkAtRules('charset', rule => {
355
+ * if (!first) {
356
+ * first = true
357
+ * } else {
358
+ * rule.remove()
359
+ * }
360
+ * })
441
361
  * ```
442
362
  *
443
- * @param child Child of the current container.
444
- * @return Child index.
363
+ * @param name String or regular expression to filter at-rules by name.
364
+ * @param callback Iterator receives each node and index.
365
+ * @return Returns `false` if iteration was broke.
445
366
  */
446
- index(child: Child | number): number
367
+ walkAtRules(
368
+ nameFilter: RegExp | string,
369
+ callback: (atRule: AtRule, index: number) => false | void
370
+ ): false | undefined
371
+
372
+ walkComments(
373
+ callback: (comment: Comment, indexed: number) => false | void
374
+ ): false | undefined
375
+
376
+ walkComments(
377
+ callback: (comment: Comment, indexed: number) => false | void
378
+ ): false | undefined
379
+ walkDecls(
380
+ callback: (decl: Declaration, index: number) => false | void
381
+ ): false | undefined
382
+
383
+ /**
384
+ * Traverses the container’s descendant nodes, calling callback
385
+ * for each declaration node.
386
+ *
387
+ * If you pass a filter, iteration will only happen over declarations
388
+ * with matching properties.
389
+ *
390
+ * ```js
391
+ * root.walkDecls(decl => {
392
+ * checkPropertySupport(decl.prop)
393
+ * })
394
+ *
395
+ * root.walkDecls('border-radius', decl => {
396
+ * decl.remove()
397
+ * })
398
+ *
399
+ * root.walkDecls(/^background/, decl => {
400
+ * decl.value = takeFirstColorFromGradient(decl.value)
401
+ * })
402
+ * ```
403
+ *
404
+ * Like `Container#each`, this method is safe
405
+ * to use if you are mutating arrays during iteration.
406
+ *
407
+ * @param prop String or regular expression to filter declarations
408
+ * by property name.
409
+ * @param callback Iterator receives each node and index.
410
+ * @return Returns `false` if iteration was broke.
411
+ */
412
+ walkDecls(
413
+ propFilter: RegExp | string,
414
+ callback: (decl: Declaration, index: number) => false | void
415
+ ): false | undefined
416
+
417
+ walkRules(
418
+ callback: (rule: Rule, index: number) => false | void
419
+ ): false | undefined
420
+
421
+ /**
422
+ * Traverses the container’s descendant nodes, calling callback
423
+ * for each rule node.
424
+ *
425
+ * If you pass a filter, iteration will only happen over rules
426
+ * with matching selectors.
427
+ *
428
+ * Like `Container#each`, this method is safe
429
+ * to use if you are mutating arrays during iteration.
430
+ *
431
+ * ```js
432
+ * const selectors = []
433
+ * root.walkRules(rule => {
434
+ * selectors.push(rule.selector)
435
+ * })
436
+ * console.log(`Your CSS uses ${ selectors.length } selectors`)
437
+ * ```
438
+ *
439
+ * @param selector String or regular expression to filter rules by selector.
440
+ * @param callback Iterator receives each node and index.
441
+ * @return Returns `false` if iteration was broke.
442
+ */
443
+ walkRules(
444
+ selectorFilter: RegExp | string,
445
+ callback: (rule: Rule, index: number) => false | void
446
+ ): false | undefined
447
447
  }
448
448
 
449
449
  declare class Container<Child extends Node = ChildNode> extends Container_<Child> {}