@tbela99/css-parser 1.3.0 → 1.3.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/CHANGELOG.md +6 -0
- package/README.md +28 -10
- package/dist/index-umd-web.js +1610 -1170
- package/dist/index.cjs +1699 -1168
- package/dist/index.d.ts +1834 -71
- package/dist/lib/ast/expand.js +4 -65
- package/dist/lib/ast/features/calc.js +2 -2
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +2 -1
- package/dist/lib/ast/features/transform.js +2 -1
- package/dist/lib/ast/features/type.js +9 -0
- package/dist/lib/ast/math/math.js +1 -1
- package/dist/lib/ast/minify.js +82 -171
- package/dist/lib/ast/types.js +369 -4
- package/dist/lib/ast/walk.js +18 -0
- package/dist/lib/fs/resolve.js +11 -3
- package/dist/lib/parser/declaration/map.js +1 -0
- package/dist/lib/parser/parse.js +106 -21
- package/dist/lib/parser/tokenize.js +40 -80
- package/dist/lib/renderer/render.js +25 -3
- package/dist/lib/renderer/sourcemap/sourcemap.js +34 -0
- package/dist/lib/syntax/color/color.js +7 -0
- package/dist/lib/syntax/color/utils/distance.js +5 -1
- package/dist/lib/syntax/syntax.js +10 -0
- package/dist/lib/validation/config.json.js +33 -30
- package/dist/lib/validation/syntax.js +3 -1
- package/dist/node.js +229 -0
- package/dist/web.js +158 -0
- package/package.json +14 -11
- package/dist/node/index.js +0 -57
- package/dist/node/load.js +0 -20
- package/dist/web/index.js +0 -66
- package/dist/web/load.js +0 -31
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[](https://tbela99.github.io/css-parser/playground/) [](https://www.npmjs.com/package/@tbela99/css-parser) [](https://jsr.io/@tbela99/css-parser) [](https://github.com/tbela99/css-parser/actions) [](https://www.npmjs.com/package/@tbela99/css-parser) [](https://www.npmjs.com/package/@tbela99/css-parser)
|
|
3
|
+
)](https://jsr.io/@tbela99/css-parser) [](https://github.com/tbela99/css-parser/actions) [](https://tbela99.github.io/css-parser/docs) [](https://www.npmjs.com/package/@tbela99/css-parser) [](https://www.npmjs.com/package/@tbela99/css-parser)
|
|
4
4
|
|
|
5
5
|
# css-parser
|
|
6
6
|
|
|
@@ -97,7 +97,7 @@ Javascript module from cdn
|
|
|
97
97
|
|
|
98
98
|
<script type="module">
|
|
99
99
|
|
|
100
|
-
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.
|
|
100
|
+
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.1/web';
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
const css = `
|
|
@@ -116,7 +116,7 @@ Javascript module
|
|
|
116
116
|
|
|
117
117
|
```javascript
|
|
118
118
|
|
|
119
|
-
<script src="dist/web
|
|
119
|
+
<script src="dist/web.js" type="module"></script>
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
Single Javascript file
|
|
@@ -134,7 +134,9 @@ Parse and render css in a single pass.
|
|
|
134
134
|
|
|
135
135
|
```typescript
|
|
136
136
|
|
|
137
|
-
transform(css
|
|
137
|
+
transform(css: string | ReadableStream<string>, transformOptions: TransformOptions = {}): TransformResult
|
|
138
|
+
parse(css: string | ReadableStream<string>, parseOptions: ParseOptions = {}): ParseResult;
|
|
139
|
+
render(ast: AstNode, renderOptions: RenderOptions = {}): RenderResult;
|
|
138
140
|
```
|
|
139
141
|
|
|
140
142
|
### Example
|
|
@@ -146,6 +148,21 @@ import {transform} from '@tbela99/css-parser';
|
|
|
146
148
|
const {ast, code, map, errors, stats} = await transform(css, {minify: true, resolveImport: true, cwd: 'files/css'});
|
|
147
149
|
```
|
|
148
150
|
|
|
151
|
+
### Example
|
|
152
|
+
|
|
153
|
+
Read from stdin with node using readable stream
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import {transform} from "../src/node";
|
|
157
|
+
import {Readable} from "node:stream";
|
|
158
|
+
import type {TransformResult} from '../src/@types/index.d.ts';
|
|
159
|
+
|
|
160
|
+
const readableStream: ReadableStream<string> = Readable.toWeb(process.stdin) as ReadableStream<string>;
|
|
161
|
+
const result: TransformResult = await transform(readableStream, {beautify: true});
|
|
162
|
+
|
|
163
|
+
console.log(result.code);
|
|
164
|
+
```
|
|
165
|
+
|
|
149
166
|
### TransformOptions
|
|
150
167
|
|
|
151
168
|
Include ParseOptions and RenderOptions
|
|
@@ -215,17 +232,17 @@ Include ParseOptions and RenderOptions
|
|
|
215
232
|
- true: same as ColorType.HEX
|
|
216
233
|
- false: no color conversion
|
|
217
234
|
- ColorType.HEX
|
|
218
|
-
- ColorType.RGB
|
|
235
|
+
- ColorType.RGB or ColorType.RGBA
|
|
219
236
|
- ColorType.HSL
|
|
220
237
|
- ColorType.HWB
|
|
221
|
-
- ColorType.CMYK
|
|
238
|
+
- ColorType.CMYK or ColorType.DEVICE_CMYK
|
|
222
239
|
- ColorType.SRGB
|
|
223
240
|
- ColorType.SRGB_LINEAR
|
|
224
241
|
- ColorType.DISPLAY_P3
|
|
225
242
|
- ColorType.PROPHOTO_RGB
|
|
226
243
|
- ColorType.A98_RGB
|
|
227
244
|
- ColorType.REC2020
|
|
228
|
-
- ColorType.XYZ
|
|
245
|
+
- ColorType.XYZ or ColorType.XYZ_D65
|
|
229
246
|
- ColorType.XYZ_D50
|
|
230
247
|
- ColorType.LAB
|
|
231
248
|
- ColorType.LCH
|
|
@@ -903,8 +920,8 @@ const options: ParserOptions = {
|
|
|
903
920
|
nam: 'width',
|
|
904
921
|
val: [
|
|
905
922
|
<LengthToken>{
|
|
906
|
-
typ: EnumToken.
|
|
907
|
-
val:
|
|
923
|
+
typ: EnumToken.LengthTokenType,
|
|
924
|
+
val: 3,
|
|
908
925
|
unit: 'px'
|
|
909
926
|
}
|
|
910
927
|
]
|
|
@@ -989,7 +1006,8 @@ const options: ParserOptions = {
|
|
|
989
1006
|
|
|
990
1007
|
media: (node: AstAtRule): AstAtRule => {
|
|
991
1008
|
|
|
992
|
-
|
|
1009
|
+
node.val = 'all';
|
|
1010
|
+
return node
|
|
993
1011
|
}
|
|
994
1012
|
}
|
|
995
1013
|
}
|