postcss 8.4.49 → 8.5.1

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.
package/lib/input.d.ts CHANGED
@@ -62,6 +62,17 @@ declare class Input_ {
62
62
  */
63
63
  css: string
64
64
 
65
+ /**
66
+ * Input source with support for non-CSS documents.
67
+ *
68
+ * ```js
69
+ * const input = postcss.parse('a{}', { from: file, document: '<style>a {}</style>' }).input
70
+ * input.document //=> "<style>a {}</style>"
71
+ * input.css //=> "a{}"
72
+ * ```
73
+ */
74
+ document: string
75
+
65
76
  /**
66
77
  * The absolute path to the CSS source file defined
67
78
  * with the `from` option.
package/lib/input.js CHANGED
@@ -33,6 +33,9 @@ class Input {
33
33
  this.hasBOM = false
34
34
  }
35
35
 
36
+ this.document = this.css
37
+ if (opts.document) this.document = opts.document.toString()
38
+
36
39
  if (opts.from) {
37
40
  if (
38
41
  !pathAvailable ||
package/lib/node.js CHANGED
@@ -209,9 +209,12 @@ class Node {
209
209
  if (opts.index) {
210
210
  pos = this.positionInside(opts.index)
211
211
  } else if (opts.word) {
212
- let stringRepresentation = this.source.input.css.slice(
213
- sourceOffset(this.source.input.css, this.source.start),
214
- sourceOffset(this.source.input.css, this.source.end)
212
+ let inputString = ('document' in this.source.input)
213
+ ? this.source.input.document
214
+ : this.source.input.css
215
+ let stringRepresentation = inputString.slice(
216
+ sourceOffset(inputString, this.source.start),
217
+ sourceOffset(inputString, this.source.end)
215
218
  )
216
219
  let index = stringRepresentation.indexOf(opts.word)
217
220
  if (index !== -1) pos = this.positionInside(index)
@@ -222,11 +225,14 @@ class Node {
222
225
  positionInside(index) {
223
226
  let column = this.source.start.column
224
227
  let line = this.source.start.line
225
- let offset = sourceOffset(this.source.input.css, this.source.start)
228
+ let inputString = ('document' in this.source.input)
229
+ ? this.source.input.document
230
+ : this.source.input.css
231
+ let offset = sourceOffset(inputString, this.source.start)
226
232
  let end = offset + index
227
233
 
228
234
  for (let i = offset; i < end; i++) {
229
- if (this.source.input.css[i] === '\n') {
235
+ if (inputString[i] === '\n') {
230
236
  column = 1
231
237
  line += 1
232
238
  } else {
@@ -259,9 +265,12 @@ class Node {
259
265
  }
260
266
 
261
267
  if (opts.word) {
262
- let stringRepresentation = this.source.input.css.slice(
263
- sourceOffset(this.source.input.css, this.source.start),
264
- sourceOffset(this.source.input.css, this.source.end)
268
+ let inputString = ('document' in this.source.input)
269
+ ? this.source.input.document
270
+ : this.source.input.css
271
+ let stringRepresentation = inputString.slice(
272
+ sourceOffset(inputString, this.source.start),
273
+ sourceOffset(inputString, this.source.end)
265
274
  )
266
275
  let index = stringRepresentation.indexOf(opts.word)
267
276
  if (index !== -1) {
package/lib/postcss.d.ts CHANGED
@@ -229,7 +229,7 @@ declare namespace postcss {
229
229
  export interface Parser<RootNode = Document | Root> {
230
230
  (
231
231
  css: { toString(): string } | string,
232
- opts?: Pick<ProcessOptions, 'from' | 'map'>
232
+ opts?: Pick<ProcessOptions, 'document' | 'from' | 'map'>
233
233
  ): RootNode
234
234
  }
235
235
 
@@ -315,6 +315,11 @@ declare namespace postcss {
315
315
  }
316
316
 
317
317
  export interface ProcessOptions<RootNode = Document | Root> {
318
+ /**
319
+ * Input file if it is not simple CSS file, but HTML with <style> or JS with CSS-in-JS blocks.
320
+ */
321
+ document?: string
322
+
318
323
  /**
319
324
  * The path of the CSS source file. You should always set `from`,
320
325
  * because it is used in source map generation and syntax error messages.
package/lib/processor.js CHANGED
@@ -7,7 +7,7 @@ let Root = require('./root')
7
7
 
8
8
  class Processor {
9
9
  constructor(plugins = []) {
10
- this.version = '8.4.49'
10
+ this.version = '8.5.1'
11
11
  this.plugins = this.normalize(plugins)
12
12
  }
13
13
 
package/lib/rule.d.ts CHANGED
@@ -22,7 +22,7 @@ declare namespace Rule {
22
22
  between?: string
23
23
 
24
24
  /**
25
- * Contains `true` if there is semicolon after rule.
25
+ * Contains the text of the semicolon after this rule.
26
26
  */
27
27
  ownSemicolon?: string
28
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss",
3
- "version": "8.4.49",
3
+ "version": "8.5.1",
4
4
  "description": "Tool for transforming styles with JS plugins",
5
5
  "engines": {
6
6
  "node": "^10 || ^12 || >=14"
@@ -74,7 +74,7 @@
74
74
  "url": "https://github.com/postcss/postcss/issues"
75
75
  },
76
76
  "dependencies": {
77
- "nanoid": "^3.3.7",
77
+ "nanoid": "^3.3.8",
78
78
  "picocolors": "^1.1.1",
79
79
  "source-map-js": "^1.2.1"
80
80
  },