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 +11 -0
- package/lib/input.js +3 -0
- package/lib/node.js +17 -8
- package/lib/postcss.d.ts +6 -1
- package/lib/processor.js +1 -1
- package/lib/rule.d.ts +1 -1
- package/package.json +2 -2
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
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
|
213
|
-
|
214
|
-
|
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
|
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 (
|
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
|
263
|
-
|
264
|
-
|
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
package/lib/rule.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "postcss",
|
3
|
-
"version": "8.
|
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.
|
77
|
+
"nanoid": "^3.3.8",
|
78
78
|
"picocolors": "^1.1.1",
|
79
79
|
"source-map-js": "^1.2.1"
|
80
80
|
},
|