@tbela99/css-parser 1.4.3 → 1.4.4
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 +192 -2
- package/README.md +69 -1120
- package/dist/config.json.js +43 -2
- package/dist/index-umd-web.js +17226 -15037
- package/dist/index.cjs +16889 -14705
- package/dist/index.d.ts +1804 -1684
- package/dist/lib/ast/clone.js +4 -3
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/calc.js +59 -54
- package/dist/lib/ast/features/if.js +22 -16
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +343 -6
- package/dist/lib/ast/features/transform.js +7 -4
- package/dist/lib/ast/find.js +5 -5
- package/dist/lib/ast/math/expression.js +12 -8
- package/dist/lib/ast/minify.js +28 -33
- package/dist/lib/ast/transform/minify.js +135 -131
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +69 -8
- package/dist/lib/ast/walk.js +4 -5
- package/dist/lib/fs/resolve.js +71 -57
- package/dist/lib/parser/declaration/list.js +92 -3
- package/dist/lib/parser/declaration/map.js +5 -5
- package/dist/lib/parser/parse.js +528 -466
- package/dist/lib/parser/tokenize.js +110 -4
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +2 -2
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
- package/dist/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/lib/parser/utils/at-rule-support.js +73 -8
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/at-rule.js +2 -8
- package/dist/lib/parser/utils/declaration.js +179 -76
- package/dist/lib/parser/utils/selector.js +53 -11
- package/dist/lib/parser/utils/token.js +13 -11
- package/dist/lib/renderer/render.js +501 -59
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +283 -220
- package/dist/lib/syntax/color/color.js +37 -28
- package/dist/lib/syntax/color/hex.js +2 -2
- package/dist/lib/syntax/color/hsl.js +3 -3
- package/dist/lib/syntax/color/hwb.js +7 -7
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +3 -3
- package/dist/lib/syntax/color/oklch.js +3 -3
- package/dist/lib/syntax/color/relativecolor.js +97 -12
- package/dist/lib/syntax/color/srgb.js +5 -5
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +7 -3
- package/dist/lib/syntax/color/utils/distance.js +21 -4
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/constants.js +29 -1
- package/dist/lib/syntax/syntax.js +307 -39
- package/dist/lib/validation/config.js +2 -2
- package/dist/lib/validation/config.json.js +32 -17
- package/dist/lib/validation/match.js +239 -104
- package/dist/lib/validation/parser/parse.js +0 -1
- package/dist/lib/validation/parser/typedef.js +6 -0
- package/dist/node.js +64 -22
- package/dist/web.js +65 -18
- package/package.json +26 -15
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.repl_history +0 -4
- package/badges/coverage.svg +0 -20
- package/deno.lock +0 -2861
- package/dist/lib/ast/clone.d.ts +0 -10
- package/dist/lib/ast/expand.d.ts +0 -14
- package/dist/lib/ast/features/calc.d.ts +0 -10
- package/dist/lib/ast/features/if.d.ts +0 -10
- package/dist/lib/ast/features/index.d.ts +0 -6
- package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
- package/dist/lib/ast/features/prefix.d.ts +0 -8
- package/dist/lib/ast/features/shorthand.d.ts +0 -12
- package/dist/lib/ast/features/transform.d.ts +0 -10
- package/dist/lib/ast/features/type.d.ts +0 -15
- package/dist/lib/ast/find.d.ts +0 -165
- package/dist/lib/ast/math/expression.d.ts +0 -18
- package/dist/lib/ast/math/math.d.ts +0 -6
- package/dist/lib/ast/minify.d.ts +0 -19
- package/dist/lib/ast/transform/compute.d.ts +0 -8
- package/dist/lib/ast/transform/matrix.d.ts +0 -22
- package/dist/lib/ast/transform/minify.d.ts +0 -5
- package/dist/lib/ast/transform/perspective.d.ts +0 -3
- package/dist/lib/ast/transform/rotate.d.ts +0 -12
- package/dist/lib/ast/transform/scale.d.ts +0 -6
- package/dist/lib/ast/transform/skew.d.ts +0 -4
- package/dist/lib/ast/transform/translate.d.ts +0 -6
- package/dist/lib/ast/transform/utils.d.ts +0 -9
- package/dist/lib/ast/types.d.ts +0 -903
- package/dist/lib/ast/walk.d.ts +0 -162
- package/dist/lib/fs/resolve.d.ts +0 -20
- package/dist/lib/parser/declaration/list.d.ts +0 -16
- package/dist/lib/parser/declaration/map.d.ts +0 -15
- package/dist/lib/parser/declaration/set.d.ts +0 -9
- package/dist/lib/parser/node.d.ts +0 -7
- package/dist/lib/parser/parse.d.ts +0 -107
- package/dist/lib/parser/tokenize.d.ts +0 -57
- package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.js +0 -28
- package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule.d.ts +0 -13
- package/dist/lib/parser/utils/cache.d.ts +0 -6
- package/dist/lib/parser/utils/config.d.ts +0 -2
- package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
- package/dist/lib/parser/utils/declaration.d.ts +0 -18
- package/dist/lib/parser/utils/eq.d.ts +0 -1
- package/dist/lib/parser/utils/hash.d.ts +0 -21
- package/dist/lib/parser/utils/selector.d.ts +0 -5
- package/dist/lib/parser/utils/text.d.ts +0 -3
- package/dist/lib/parser/utils/token.d.ts +0 -14
- package/dist/lib/parser/utils/type.d.ts +0 -2
- package/dist/lib/renderer/render.d.ts +0 -28
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
- package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
- package/dist/lib/syntax/color/cmyk.d.ts +0 -10
- package/dist/lib/syntax/color/color-mix.d.ts +0 -2
- package/dist/lib/syntax/color/color.d.ts +0 -42
- package/dist/lib/syntax/color/hex.d.ts +0 -16
- package/dist/lib/syntax/color/hsl.d.ts +0 -20
- package/dist/lib/syntax/color/hsv.d.ts +0 -2
- package/dist/lib/syntax/color/hwb.d.ts +0 -21
- package/dist/lib/syntax/color/lab.d.ts +0 -25
- package/dist/lib/syntax/color/lch.d.ts +0 -23
- package/dist/lib/syntax/color/oklab.d.ts +0 -22
- package/dist/lib/syntax/color/oklch.d.ts +0 -20
- package/dist/lib/syntax/color/p3.d.ts +0 -6
- package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
- package/dist/lib/syntax/color/rec2020.d.ts +0 -2
- package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
- package/dist/lib/syntax/color/rgb.d.ts +0 -20
- package/dist/lib/syntax/color/srgb.d.ts +0 -23
- package/dist/lib/syntax/color/utils/components.d.ts +0 -2
- package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
- package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
- package/dist/lib/syntax/color/xyz.d.ts +0 -5
- package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
- package/dist/lib/syntax/constants.d.ts +0 -67
- package/dist/lib/syntax/syntax.d.ts +0 -38
- package/dist/lib/validation/config.d.ts +0 -14
- package/dist/lib/validation/json.d.ts +0 -2
- package/dist/lib/validation/match.d.ts +0 -38
- package/dist/lib/validation/parser/parse.d.ts +0 -8
- package/dist/lib/validation/parser/typedef.d.ts +0 -95
- package/dist/lib/validation/utils/list.d.ts +0 -4
- package/dist/lib/validation/utils/whitespace.d.ts +0 -2
- package/dist/node.d.ts +0 -207
- package/dist/web.d.ts +0 -169
- package/playground/index.html +0 -1328
- package/playground/sw.js +0 -55
- package/playground/tree.js +0 -176
package/dist/node.d.ts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import type { AstNode, ParseResult, ParserOptions, RenderOptions, RenderResult, TransformOptions, TransformResult } from "./@types/index.d.ts";
|
|
2
|
-
import { dirname, resolve } from "./lib/fs/resolve.ts";
|
|
3
|
-
import { ResponseType } from "./types.ts";
|
|
4
|
-
export type * from "./@types/index.d.ts";
|
|
5
|
-
export type * from "./@types/ast.d.ts";
|
|
6
|
-
export type * from "./@types/token.d.ts";
|
|
7
|
-
export type * from "./@types/parse.d.ts";
|
|
8
|
-
export type * from "./@types/validation.d.ts";
|
|
9
|
-
export type * from "./@types/walker.d.ts";
|
|
10
|
-
export type { AstNode, ParseResult, ParserOptions, RenderOptions, RenderResult, TransformOptions, TransformResult, } from "./@types/index.d.ts";
|
|
11
|
-
export { minify } from "./lib/ast/minify.ts";
|
|
12
|
-
export { expand } from "./lib/ast/expand.ts";
|
|
13
|
-
export { walk, walkValues, WalkerEvent, WalkerOptionEnum } from "./lib/ast/walk.ts";
|
|
14
|
-
export { parseString } from "./lib/parser/parse.ts";
|
|
15
|
-
export { renderToken } from "./lib/renderer/render.ts";
|
|
16
|
-
export { convertColor } from "./lib/syntax/color/color.ts";
|
|
17
|
-
export { isOkLabClose, okLabDistance } from "./lib/syntax/color/utils/distance.ts";
|
|
18
|
-
export { parseDeclarations } from "./lib/parser/parse.ts";
|
|
19
|
-
export { find, findLast, findByValue, findAll } from "./lib/ast/find.ts";
|
|
20
|
-
export { cloneNode } from "./lib/ast/clone.ts";
|
|
21
|
-
export { EnumToken, ColorType, ValidationLevel, ModuleScopeEnumOptions, ModuleCaseTransformEnum, } from "./lib/ast/types.ts";
|
|
22
|
-
export { SourceMap } from "./lib/renderer/sourcemap/sourcemap.ts";
|
|
23
|
-
export type { ValidationToken } from "./lib/validation/parser/types.d.ts";
|
|
24
|
-
export { FeatureWalkMode } from "./lib/ast/features/type.ts";
|
|
25
|
-
export { dirname, resolve, ResponseType };
|
|
26
|
-
/**
|
|
27
|
-
* load file or url
|
|
28
|
-
* @param url
|
|
29
|
-
* @param currentDirectory
|
|
30
|
-
* @param responseType
|
|
31
|
-
* @throws Error file not found
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* import {load, ResponseType} from '@tbela99/css-parser';
|
|
35
|
-
* const result = await load(file, '.', ResponseType.ArrayBuffer) as ArrayBuffer;
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function load(url: string, currentDirectory?: string, responseType?: boolean | ResponseType): Promise<string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
39
|
-
/**
|
|
40
|
-
* render the ast tree
|
|
41
|
-
* @param data
|
|
42
|
-
* @param options
|
|
43
|
-
* @param mapping
|
|
44
|
-
*
|
|
45
|
-
* Example:
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
*
|
|
49
|
-
* import {render, ColorType} from '@tbela99/css-parser';
|
|
50
|
-
*
|
|
51
|
-
* const css = 'body { color: color(from hsl(0 100% 50%) xyz x y z); }';
|
|
52
|
-
* const parseResult = await parse(css);
|
|
53
|
-
*
|
|
54
|
-
* let renderResult = render(parseResult.ast);
|
|
55
|
-
* console.log(result.code);
|
|
56
|
-
*
|
|
57
|
-
* // body{color:red}
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* renderResult = render(parseResult.ast, {beautify: true, convertColor: ColorType.SRGB});
|
|
61
|
-
* console.log(renderResult.code);
|
|
62
|
-
*
|
|
63
|
-
* // body {
|
|
64
|
-
* // color: color(srgb 1 0 0)
|
|
65
|
-
* // }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
export declare function render(data: AstNode, options?: RenderOptions, mapping?: {
|
|
69
|
-
mapping: Record<string, string>;
|
|
70
|
-
importMapping: Record<string, Record<string, string>> | null;
|
|
71
|
-
} | null): RenderResult;
|
|
72
|
-
/**
|
|
73
|
-
* parse css file
|
|
74
|
-
* @param file url or path
|
|
75
|
-
* @param options
|
|
76
|
-
* @param asStream load file as stream
|
|
77
|
-
*
|
|
78
|
-
* @throws Error file not found
|
|
79
|
-
*
|
|
80
|
-
* Example:
|
|
81
|
-
*
|
|
82
|
-
* ```ts
|
|
83
|
-
*
|
|
84
|
-
* import {parseFile} from '@tbela99/css-parser';
|
|
85
|
-
*
|
|
86
|
-
* // remote file
|
|
87
|
-
* let result = await parseFile('https://docs.deno.com/styles.css');
|
|
88
|
-
* console.log(result.ast);
|
|
89
|
-
*
|
|
90
|
-
* // local file
|
|
91
|
-
* result = await parseFile('./css/styles.css');
|
|
92
|
-
* console.log(result.ast);
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export declare function parseFile(file: string, options?: ParserOptions, asStream?: boolean): Promise<ParseResult>;
|
|
96
|
-
/**
|
|
97
|
-
* parse css
|
|
98
|
-
* @param stream
|
|
99
|
-
* @param options
|
|
100
|
-
*
|
|
101
|
-
* Example:
|
|
102
|
-
*
|
|
103
|
-
* ```ts
|
|
104
|
-
*
|
|
105
|
-
* import {parse} from '@tbela99/css-parser';
|
|
106
|
-
*
|
|
107
|
-
* // css string
|
|
108
|
-
* let result = await parse(css);
|
|
109
|
-
* console.log(result.ast);
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
* Example using stream
|
|
113
|
-
*
|
|
114
|
-
* ```ts
|
|
115
|
-
*
|
|
116
|
-
* import {parse} from '@tbela99/css-parser';
|
|
117
|
-
* import {Readable} from "node:stream";
|
|
118
|
-
*
|
|
119
|
-
* // usage: node index.ts < styles.css or cat styles.css | node index.ts
|
|
120
|
-
*
|
|
121
|
-
* const readableStream = Readable.toWeb(process.stdin);
|
|
122
|
-
* let result = await parse(readableStream, {beautify: true});
|
|
123
|
-
*
|
|
124
|
-
* console.log(result.ast);
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
* Example using fetch and readable stream
|
|
128
|
-
*
|
|
129
|
-
* ```ts
|
|
130
|
-
*
|
|
131
|
-
* import {parse} from '@tbela99/css-parser';
|
|
132
|
-
*
|
|
133
|
-
* const response = await fetch('https://docs.deno.com/styles.css');
|
|
134
|
-
* const result = await parse(response.body, {beautify: true});
|
|
135
|
-
*
|
|
136
|
-
* console.log(result.ast);
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
export declare function parse(stream: string | ReadableStream<Uint8Array>, options?: ParserOptions): Promise<ParseResult>;
|
|
140
|
-
/**
|
|
141
|
-
* transform css file
|
|
142
|
-
* @param file url or path
|
|
143
|
-
* @param options
|
|
144
|
-
* @param asStream load file as stream
|
|
145
|
-
*
|
|
146
|
-
* @throws Error file not found
|
|
147
|
-
*
|
|
148
|
-
* Example:
|
|
149
|
-
*
|
|
150
|
-
* ```ts
|
|
151
|
-
*
|
|
152
|
-
* import {transformFile} from '@tbela99/css-parser';
|
|
153
|
-
*
|
|
154
|
-
* // remote file
|
|
155
|
-
* let result = await transformFile('https://docs.deno.com/styles.css');
|
|
156
|
-
* console.log(result.code);
|
|
157
|
-
*
|
|
158
|
-
* // local file
|
|
159
|
-
* result = await transformFile('./css/styles.css');
|
|
160
|
-
* console.log(result.code);
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
export declare function transformFile(file: string, options?: TransformOptions, asStream?: boolean): Promise<TransformResult>;
|
|
164
|
-
/**
|
|
165
|
-
* transform css
|
|
166
|
-
* @param css
|
|
167
|
-
* @param options
|
|
168
|
-
*
|
|
169
|
-
* Example:
|
|
170
|
-
*
|
|
171
|
-
* ```ts
|
|
172
|
-
*
|
|
173
|
-
* import {transform} from '@tbela99/css-parser';
|
|
174
|
-
*
|
|
175
|
-
* // css string
|
|
176
|
-
* const result = await transform(css);
|
|
177
|
-
* console.log(result.code);
|
|
178
|
-
* ```
|
|
179
|
-
*
|
|
180
|
-
* Example using stream
|
|
181
|
-
*
|
|
182
|
-
* ```ts
|
|
183
|
-
*
|
|
184
|
-
* import {transform} from '@tbela99/css-parser';
|
|
185
|
-
* import {Readable} from "node:stream";
|
|
186
|
-
*
|
|
187
|
-
* // usage: node index.ts < styles.css or cat styles.css | node index.ts
|
|
188
|
-
*
|
|
189
|
-
* const readableStream = Readable.toWeb(process.stdin);
|
|
190
|
-
* const result = await transform(readableStream, {beautify: true});
|
|
191
|
-
*
|
|
192
|
-
* console.log(result.code);
|
|
193
|
-
* ```
|
|
194
|
-
*
|
|
195
|
-
* Example using fetch
|
|
196
|
-
*
|
|
197
|
-
* ```ts
|
|
198
|
-
*
|
|
199
|
-
* import {transform} from '@tbela99/css-parser';
|
|
200
|
-
*
|
|
201
|
-
* const response = await fetch('https://docs.deno.com/styles.css');
|
|
202
|
-
* result = await transform(response.body, {beautify: true});
|
|
203
|
-
*
|
|
204
|
-
* console.log(result.code);
|
|
205
|
-
* ```
|
|
206
|
-
*/
|
|
207
|
-
export declare function transform(css: string | ReadableStream<Uint8Array>, options?: TransformOptions): Promise<TransformResult>;
|
package/dist/web.d.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import type { AstNode, ParseResult, ParserOptions, RenderOptions, RenderResult, TransformOptions, TransformResult } from "./@types/index.d.ts";
|
|
2
|
-
import { dirname, resolve } from "./lib/fs/resolve.ts";
|
|
3
|
-
import { ResponseType } from "./types.ts";
|
|
4
|
-
export type * from "./@types/index.d.ts";
|
|
5
|
-
export type * from "./@types/ast.d.ts";
|
|
6
|
-
export type * from "./@types/token.d.ts";
|
|
7
|
-
export type * from "./@types/parse.d.ts";
|
|
8
|
-
export type * from "./@types/validation.d.ts";
|
|
9
|
-
export type * from "./@types/walker.d.ts";
|
|
10
|
-
export type { AstNode, ParseResult, ParserOptions, RenderOptions, RenderResult, TransformOptions, TransformResult, } from "./@types/index.d.ts";
|
|
11
|
-
export { minify } from "./lib/ast/minify.ts";
|
|
12
|
-
export { expand } from "./lib/ast/expand.ts";
|
|
13
|
-
export { walk, walkValues, WalkerEvent, WalkerOptionEnum } from "./lib/ast/walk.ts";
|
|
14
|
-
export { parseString } from "./lib/parser/parse.ts";
|
|
15
|
-
export { renderToken } from "./lib/renderer/render.ts";
|
|
16
|
-
export { convertColor } from "./lib/syntax/color/color.ts";
|
|
17
|
-
export { isOkLabClose, okLabDistance } from "./lib/syntax/color/utils/distance.ts";
|
|
18
|
-
export { parseDeclarations } from "./lib/parser/parse.ts";
|
|
19
|
-
export { find, findLast, findByValue, findAll } from "./lib/ast/find.ts";
|
|
20
|
-
export { cloneNode } from "./lib/ast/clone.ts";
|
|
21
|
-
export { EnumToken, ColorType, ValidationLevel, ModuleScopeEnumOptions, ModuleCaseTransformEnum, } from "./lib/ast/types.ts";
|
|
22
|
-
export { SourceMap } from "./lib/renderer/sourcemap/sourcemap.ts";
|
|
23
|
-
export type { ValidationToken } from "./lib/validation/parser/types.d.ts";
|
|
24
|
-
export { FeatureWalkMode } from "./lib/ast/features/type.ts";
|
|
25
|
-
export { dirname, resolve, ResponseType };
|
|
26
|
-
/**
|
|
27
|
-
* load file or url
|
|
28
|
-
* @param url
|
|
29
|
-
* @param currentDirectory
|
|
30
|
-
* @param responseType
|
|
31
|
-
* @throws Error file not found
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* import {load, ResponseType} from '@tbela99/css-parser';
|
|
35
|
-
* const result = await load(file, '.', ResponseType.ArrayBuffer) as ArrayBuffer;
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function load(url: string, currentDirectory?: string, responseType?: boolean | ResponseType): Promise<string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
39
|
-
/**
|
|
40
|
-
* render the ast tree
|
|
41
|
-
* @param data
|
|
42
|
-
* @param options
|
|
43
|
-
* @param mapping
|
|
44
|
-
*
|
|
45
|
-
* Example:
|
|
46
|
-
*
|
|
47
|
-
* ```ts
|
|
48
|
-
*
|
|
49
|
-
* import {render, ColorType} from '@tbela99/css-parser';
|
|
50
|
-
*
|
|
51
|
-
* const css = 'body { color: color(from hsl(0 100% 50%) xyz x y z); }';
|
|
52
|
-
* const parseResult = await parse(css);
|
|
53
|
-
*
|
|
54
|
-
* let renderResult = render(parseResult.ast);
|
|
55
|
-
* console.log(result.code);
|
|
56
|
-
*
|
|
57
|
-
* // body{color:red}
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* renderResult = render(parseResult.ast, {beautify: true, convertColor: ColorType.SRGB});
|
|
61
|
-
* console.log(renderResult.code);
|
|
62
|
-
*
|
|
63
|
-
* // body {
|
|
64
|
-
* // color: color(srgb 1 0 0)
|
|
65
|
-
* // }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
export declare function render(data: AstNode, options?: RenderOptions, mapping?: {
|
|
69
|
-
mapping: Record<string, string>;
|
|
70
|
-
importMapping: Record<string, Record<string, string>> | null;
|
|
71
|
-
} | null): RenderResult;
|
|
72
|
-
/**
|
|
73
|
-
* parse css file
|
|
74
|
-
* @param file url or path
|
|
75
|
-
* @param options
|
|
76
|
-
* @param asStream load file as stream
|
|
77
|
-
*
|
|
78
|
-
* @throws Error file not found
|
|
79
|
-
*
|
|
80
|
-
* Example:
|
|
81
|
-
*
|
|
82
|
-
* ```ts
|
|
83
|
-
*
|
|
84
|
-
* import {parseFile} from '@tbela99/css-parser/web';
|
|
85
|
-
*
|
|
86
|
-
* // remote file
|
|
87
|
-
* let result = await parseFile('https://docs.deno.com/styles.css');
|
|
88
|
-
* console.log(result.ast);
|
|
89
|
-
*
|
|
90
|
-
* // local file
|
|
91
|
-
* result = await parseFile('./css/styles.css');
|
|
92
|
-
* console.log(result.ast);
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export declare function parseFile(file: string, options?: ParserOptions, asStream?: boolean): Promise<ParseResult>;
|
|
96
|
-
/**
|
|
97
|
-
* parse css
|
|
98
|
-
* @param stream
|
|
99
|
-
* @param options
|
|
100
|
-
*
|
|
101
|
-
* Example:
|
|
102
|
-
*
|
|
103
|
-
* ```ts
|
|
104
|
-
*
|
|
105
|
-
* import {parse} from '@tbela99/css-parser/web';
|
|
106
|
-
*
|
|
107
|
-
* // css string
|
|
108
|
-
* const result = await parse(css);
|
|
109
|
-
* console.log(result.ast);
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
* Example using fetch and readable stream
|
|
113
|
-
*
|
|
114
|
-
* ```ts
|
|
115
|
-
*
|
|
116
|
-
* import {parse} from '@tbela99/css-parser/web';
|
|
117
|
-
*
|
|
118
|
-
* const response = await fetch('https://docs.deno.com/styles.css');
|
|
119
|
-
* const result = await parse(response.body, {beautify: true});
|
|
120
|
-
*
|
|
121
|
-
* console.log(result.ast);
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
export declare function parse(stream: string | ReadableStream<Uint8Array>, options?: ParserOptions): Promise<ParseResult>;
|
|
125
|
-
/**
|
|
126
|
-
* transform css file
|
|
127
|
-
* @param file url or path
|
|
128
|
-
* @param options
|
|
129
|
-
* @param asStream load file as stream
|
|
130
|
-
*
|
|
131
|
-
* Example:
|
|
132
|
-
*
|
|
133
|
-
* ```ts
|
|
134
|
-
*
|
|
135
|
-
* import {transformFile} from '@tbela99/css-parser/web';
|
|
136
|
-
*
|
|
137
|
-
* // remote file
|
|
138
|
-
* let result = await transformFile('https://docs.deno.com/styles.css');
|
|
139
|
-
* console.log(result.code);
|
|
140
|
-
*
|
|
141
|
-
* // local file
|
|
142
|
-
* result = await transformFile('./css/styles.css');
|
|
143
|
-
* console.log(result.code);
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
export declare function transformFile(file: string, options?: TransformOptions, asStream?: boolean): Promise<TransformResult>;
|
|
147
|
-
/**
|
|
148
|
-
* transform css
|
|
149
|
-
* @param css
|
|
150
|
-
* @param options
|
|
151
|
-
*
|
|
152
|
-
* Example:
|
|
153
|
-
*
|
|
154
|
-
* ```ts
|
|
155
|
-
*
|
|
156
|
-
* import {transform} from '@tbela99/css-parser/web';
|
|
157
|
-
*
|
|
158
|
-
* // css string
|
|
159
|
-
* let result = await transform(css);
|
|
160
|
-
* console.log(result.code);
|
|
161
|
-
*
|
|
162
|
-
* // using readable stream
|
|
163
|
-
* const response = await fetch('https://docs.deno.com/styles.css');
|
|
164
|
-
* result = await transform(response.body, {beautify: true});
|
|
165
|
-
*
|
|
166
|
-
* console.log(result.code);
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
export declare function transform(css: string | ReadableStream<Uint8Array>, options?: TransformOptions): Promise<TransformResult>;
|