postcss 8.4.48 → 8.5.0
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 +42 -7
- 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
@@ -32,6 +32,36 @@ function cloneNode(obj, parent) {
|
|
32
32
|
return cloned
|
33
33
|
}
|
34
34
|
|
35
|
+
function sourceOffset(inputCSS, position) {
|
36
|
+
// Not all custom syntaxes support `offset` in `source.start` and `source.end`
|
37
|
+
if (
|
38
|
+
position &&
|
39
|
+
typeof position.offset !== 'undefined'
|
40
|
+
) {
|
41
|
+
return position.offset;
|
42
|
+
}
|
43
|
+
|
44
|
+
let column = 1
|
45
|
+
let line = 1
|
46
|
+
let offset = 0
|
47
|
+
|
48
|
+
for (let i = 0; i < inputCSS.length; i++) {
|
49
|
+
if (line === position.line && column === position.column) {
|
50
|
+
offset = i
|
51
|
+
break
|
52
|
+
}
|
53
|
+
|
54
|
+
if (inputCSS[i] === '\n') {
|
55
|
+
column = 1
|
56
|
+
line += 1
|
57
|
+
} else {
|
58
|
+
column += 1
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
return offset
|
63
|
+
}
|
64
|
+
|
35
65
|
class Node {
|
36
66
|
constructor(defaults = {}) {
|
37
67
|
this.raws = {}
|
@@ -174,12 +204,15 @@ class Node {
|
|
174
204
|
return this.parent.nodes[index + 1]
|
175
205
|
}
|
176
206
|
|
177
|
-
positionBy(opts
|
207
|
+
positionBy(opts) {
|
178
208
|
let pos = this.source.start
|
179
209
|
if (opts.index) {
|
180
210
|
pos = this.positionInside(opts.index)
|
181
211
|
} else if (opts.word) {
|
182
|
-
stringRepresentation = this.source.input.
|
212
|
+
let stringRepresentation = this.source.input.document.slice(
|
213
|
+
sourceOffset(this.source.input.document, this.source.start),
|
214
|
+
sourceOffset(this.source.input.document, this.source.end)
|
215
|
+
)
|
183
216
|
let index = stringRepresentation.indexOf(opts.word)
|
184
217
|
if (index !== -1) pos = this.positionInside(index)
|
185
218
|
}
|
@@ -189,11 +222,11 @@ class Node {
|
|
189
222
|
positionInside(index) {
|
190
223
|
let column = this.source.start.column
|
191
224
|
let line = this.source.start.line
|
192
|
-
let offset = this.source.start
|
225
|
+
let offset = sourceOffset(this.source.input.document, this.source.start)
|
193
226
|
let end = offset + index
|
194
227
|
|
195
228
|
for (let i = offset; i < end; i++) {
|
196
|
-
if (this.source.input.
|
229
|
+
if (this.source.input.document[i] === '\n') {
|
197
230
|
column = 1
|
198
231
|
line += 1
|
199
232
|
} else {
|
@@ -226,13 +259,15 @@ class Node {
|
|
226
259
|
}
|
227
260
|
|
228
261
|
if (opts.word) {
|
229
|
-
let stringRepresentation = this.source.input.
|
262
|
+
let stringRepresentation = this.source.input.document.slice(
|
263
|
+
sourceOffset(this.source.input.document, this.source.start),
|
264
|
+
sourceOffset(this.source.input.document, this.source.end)
|
265
|
+
)
|
230
266
|
let index = stringRepresentation.indexOf(opts.word)
|
231
267
|
if (index !== -1) {
|
232
|
-
start = this.positionInside(index
|
268
|
+
start = this.positionInside(index)
|
233
269
|
end = this.positionInside(
|
234
270
|
index + opts.word.length,
|
235
|
-
stringRepresentation
|
236
271
|
)
|
237
272
|
}
|
238
273
|
} else {
|
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.0",
|
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
|
},
|