iobroker.mywebui 1.37.21 → 1.37.22
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/io-package.json +1 -1
- package/package.json +1 -1
- package/www/node_modules/@node-projects/css-parser/LICENSE +11 -0
- package/www/node_modules/@node-projects/css-parser/README.md +161 -0
- package/www/node_modules/@node-projects/css-parser/dist/CssParseError.d.ts +8 -0
- package/www/node_modules/@node-projects/css-parser/dist/CssParseError.js +15 -0
- package/www/node_modules/@node-projects/css-parser/dist/CssPosition.d.ts +25 -0
- package/www/node_modules/@node-projects/css-parser/dist/CssPosition.js +13 -0
- package/www/node_modules/@node-projects/css-parser/dist/index-min.js +56 -0
- package/www/node_modules/@node-projects/css-parser/dist/index-min.js.map +7 -0
- package/www/node_modules/@node-projects/css-parser/dist/index.d.ts +12 -0
- package/www/node_modules/@node-projects/css-parser/dist/index.js +8 -0
- package/www/node_modules/@node-projects/css-parser/dist/parse/index.d.ts +8 -0
- package/www/node_modules/@node-projects/css-parser/dist/parse/index.js +1293 -0
- package/www/node_modules/@node-projects/css-parser/dist/parse/lexer.d.ts +118 -0
- package/www/node_modules/@node-projects/css-parser/dist/parse/lexer.js +248 -0
- package/www/node_modules/@node-projects/css-parser/dist/stringify/compiler.d.ts +172 -0
- package/www/node_modules/@node-projects/css-parser/dist/stringify/compiler.js +732 -0
- package/www/node_modules/@node-projects/css-parser/dist/stringify/index.d.ts +5 -0
- package/www/node_modules/@node-projects/css-parser/dist/stringify/index.js +5 -0
- package/www/node_modules/@node-projects/css-parser/dist/type.d.ts +205 -0
- package/www/node_modules/@node-projects/css-parser/dist/type.js +31 -0
- package/www/node_modules/@node-projects/css-parser/dist/utils/stringSearch.d.ts +53 -0
- package/www/node_modules/@node-projects/css-parser/dist/utils/stringSearch.js +166 -0
- package/www/node_modules/@node-projects/css-parser/docs/API.md +362 -0
- package/www/node_modules/@node-projects/css-parser/docs/AST.md +417 -0
- package/www/node_modules/@node-projects/css-parser/docs/CHANGELOG.md +205 -0
- package/www/node_modules/@node-projects/css-parser/docs/EXAMPLES.md +497 -0
- package/www/node_modules/@node-projects/css-parser/package.json +66 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`@adobe/css-tools` provides a modern CSS parser and stringifier with comprehensive TypeScript support. It can parse CSS into an Abstract Syntax Tree (AST) and convert the AST back to CSS with various formatting options.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @adobe/css-tools
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Core Functions
|
|
14
|
+
|
|
15
|
+
### `parse(code, options?)`
|
|
16
|
+
|
|
17
|
+
Parses CSS code and returns an Abstract Syntax Tree (AST).
|
|
18
|
+
|
|
19
|
+
#### Parameters
|
|
20
|
+
|
|
21
|
+
- `code` (string) - The CSS code to parse
|
|
22
|
+
- `options` (object, optional) - Parsing options
|
|
23
|
+
- `silent` (boolean) - Silently fail on parse errors instead of throwing. When `true`, errors are collected in `ast.stylesheet.parsingErrors`
|
|
24
|
+
- `source` (string) - File path for better error reporting
|
|
25
|
+
- `preserveFormatting` (boolean) - Insert whitespace AST nodes and store raw formatting properties on nodes for identity round-trip. When `true`, whitespace between siblings is preserved as `CssWhitespaceAST` nodes, and raw formatting properties (`rawPrelude`, `rawBetween`, `rawValue`, `rawSource`) are stored on relevant nodes. Default: `false`
|
|
26
|
+
|
|
27
|
+
#### Returns
|
|
28
|
+
|
|
29
|
+
- `CssStylesheetAST` - The parsed CSS as an AST
|
|
30
|
+
|
|
31
|
+
#### Example
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
import { parse } from '@adobe/css-tools';
|
|
35
|
+
|
|
36
|
+
const css = `
|
|
37
|
+
.example {
|
|
38
|
+
color: red;
|
|
39
|
+
font-size: 16px;
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
const ast = parse(css);
|
|
44
|
+
console.log(ast.stylesheet.rules);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `stringify(ast, options?)`
|
|
48
|
+
|
|
49
|
+
Converts a CSS AST back to CSS string with configurable formatting.
|
|
50
|
+
|
|
51
|
+
#### Parameters
|
|
52
|
+
|
|
53
|
+
- `ast` (CssStylesheetAST) - The CSS AST to stringify
|
|
54
|
+
- `options` (CompilerOptions, optional) - Stringification options
|
|
55
|
+
- `indent` (string) - Indentation string (default: `' '`)
|
|
56
|
+
- `compress` (boolean) - Whether to compress/minify the output (default: `false`)
|
|
57
|
+
- `identity` (boolean) - Reproduce the original CSS exactly as parsed. Requires `preserveFormatting: true` during parsing. Walks the AST including whitespace nodes and uses raw formatting properties to reconstruct the original output. Inserted or modified nodes without raw properties are emitted in beautified format. Falls back to beautified output when `preserveFormatting` was not used. Default: `false`
|
|
58
|
+
- `removeEmptyRules` (boolean) - Remove rules with empty declaration blocks from the output. Works in all modes (beautified, compressed, identity). Default: `false`
|
|
59
|
+
|
|
60
|
+
#### Returns
|
|
61
|
+
|
|
62
|
+
- `string` - The formatted CSS string
|
|
63
|
+
|
|
64
|
+
#### Example
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
import { parse, stringify } from '@adobe/css-tools';
|
|
68
|
+
|
|
69
|
+
const css = '.example { color: red; }';
|
|
70
|
+
const ast = parse(css);
|
|
71
|
+
|
|
72
|
+
// Pretty print
|
|
73
|
+
const formatted = stringify(ast, { indent: ' ' });
|
|
74
|
+
console.log(formatted);
|
|
75
|
+
// Output:
|
|
76
|
+
// .example {
|
|
77
|
+
// color: red;
|
|
78
|
+
// }
|
|
79
|
+
|
|
80
|
+
// Compressed
|
|
81
|
+
const minified = stringify(ast, { compress: true });
|
|
82
|
+
console.log(minified);
|
|
83
|
+
// Output: .example{color:red}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Type Definitions
|
|
87
|
+
|
|
88
|
+
### Core Types
|
|
89
|
+
|
|
90
|
+
#### `CssStylesheetAST`
|
|
91
|
+
The root AST node representing a complete CSS stylesheet.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
type CssStylesheetAST = {
|
|
95
|
+
type: CssTypes.stylesheet;
|
|
96
|
+
stylesheet: {
|
|
97
|
+
source?: string;
|
|
98
|
+
rules: Array<CssAtRuleAST | CssWhitespaceAST>;
|
|
99
|
+
parsingErrors?: CssParseError[];
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### `CssRuleAST`
|
|
105
|
+
Represents a CSS rule (selector + declarations).
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
type CssRuleAST = {
|
|
109
|
+
type: CssTypes.rule;
|
|
110
|
+
selectors: string[];
|
|
111
|
+
declarations: CssDeclarationAST[];
|
|
112
|
+
position?: CssPosition;
|
|
113
|
+
parent?: CssStylesheetAST;
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### `CssDeclarationAST`
|
|
118
|
+
Represents a CSS property declaration.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
type CssDeclarationAST = {
|
|
122
|
+
type: CssTypes.declaration;
|
|
123
|
+
property: string;
|
|
124
|
+
value: string;
|
|
125
|
+
position?: CssPosition;
|
|
126
|
+
parent?: CssRuleAST;
|
|
127
|
+
};
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### `CssMediaAST`
|
|
131
|
+
Represents a CSS @media rule.
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
type CssMediaAST = {
|
|
135
|
+
type: CssTypes.media;
|
|
136
|
+
media: string;
|
|
137
|
+
rules: CssRuleAST[];
|
|
138
|
+
position?: CssPosition;
|
|
139
|
+
parent?: CssStylesheetAST;
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### `CssKeyframesAST`
|
|
144
|
+
Represents a CSS @keyframes rule.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
type CssKeyframesAST = {
|
|
148
|
+
type: CssTypes.keyframes;
|
|
149
|
+
name: string;
|
|
150
|
+
keyframes: CssKeyframeAST[];
|
|
151
|
+
position?: CssPosition;
|
|
152
|
+
parent?: CssStylesheetAST;
|
|
153
|
+
};
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### `CssPosition`
|
|
157
|
+
Represents source position information.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
type CssPosition = {
|
|
161
|
+
source?: string;
|
|
162
|
+
start: {
|
|
163
|
+
line: number;
|
|
164
|
+
column: number;
|
|
165
|
+
};
|
|
166
|
+
end: {
|
|
167
|
+
line: number;
|
|
168
|
+
column: number;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### `CssParseError`
|
|
174
|
+
Represents a parsing error.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
type CssParseError = {
|
|
178
|
+
message: string;
|
|
179
|
+
reason: string;
|
|
180
|
+
filename?: string;
|
|
181
|
+
line: number;
|
|
182
|
+
column: number;
|
|
183
|
+
source?: string;
|
|
184
|
+
};
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Compiler Options
|
|
188
|
+
|
|
189
|
+
#### `CompilerOptions`
|
|
190
|
+
Options for the stringifier.
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
type CompilerOptions = {
|
|
194
|
+
indent?: string; // Default: ' '
|
|
195
|
+
compress?: boolean; // Default: false
|
|
196
|
+
identity?: boolean; // Default: false
|
|
197
|
+
removeEmptyRules?: boolean; // Default: false
|
|
198
|
+
};
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Error Handling
|
|
202
|
+
|
|
203
|
+
### Silent Parsing
|
|
204
|
+
|
|
205
|
+
When parsing malformed CSS, you can use the `silent` option to collect errors instead of throwing:
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
import { parse } from '@adobe/css-tools';
|
|
209
|
+
|
|
210
|
+
const malformedCss = `
|
|
211
|
+
body { color: red; }
|
|
212
|
+
{ color: blue; } /* Missing selector */
|
|
213
|
+
.valid { background: green; }
|
|
214
|
+
`;
|
|
215
|
+
|
|
216
|
+
const result = parse(malformedCss, { silent: true });
|
|
217
|
+
|
|
218
|
+
if (result.stylesheet.parsingErrors) {
|
|
219
|
+
result.stylesheet.parsingErrors.forEach(error => {
|
|
220
|
+
console.log(`Error at line ${error.line}: ${error.message}`);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Valid rules are still parsed
|
|
225
|
+
console.log('Valid rules:', result.stylesheet.rules.length);
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Source Tracking
|
|
229
|
+
|
|
230
|
+
Enable source tracking for better error reporting:
|
|
231
|
+
|
|
232
|
+
```javascript
|
|
233
|
+
import { parse } from '@adobe/css-tools';
|
|
234
|
+
|
|
235
|
+
const css = 'body { color: red; }';
|
|
236
|
+
const ast = parse(css, { source: 'styles.css' });
|
|
237
|
+
|
|
238
|
+
const rule = ast.stylesheet.rules[0];
|
|
239
|
+
console.log(rule.position?.source); // "styles.css"
|
|
240
|
+
console.log(rule.position?.start); // { line: 1, column: 1 }
|
|
241
|
+
console.log(rule.position?.end); // { line: 1, column: 20 }
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Advanced Usage
|
|
245
|
+
|
|
246
|
+
### Working with At-Rules
|
|
247
|
+
|
|
248
|
+
```javascript
|
|
249
|
+
import { parse, stringify } from '@adobe/css-tools';
|
|
250
|
+
|
|
251
|
+
const css = `
|
|
252
|
+
@media (max-width: 768px) {
|
|
253
|
+
.container {
|
|
254
|
+
padding: 10px;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@keyframes fadeIn {
|
|
259
|
+
from { opacity: 0; }
|
|
260
|
+
to { opacity: 1; }
|
|
261
|
+
}
|
|
262
|
+
`;
|
|
263
|
+
|
|
264
|
+
const ast = parse(css);
|
|
265
|
+
|
|
266
|
+
// Access media rules
|
|
267
|
+
const mediaRule = ast.stylesheet.rules.find(rule => rule.type === 'media');
|
|
268
|
+
console.log(mediaRule.media); // "(max-width: 768px)"
|
|
269
|
+
|
|
270
|
+
// Access keyframes
|
|
271
|
+
const keyframesRule = ast.stylesheet.rules.find(rule => rule.type === 'keyframes');
|
|
272
|
+
console.log(keyframesRule.name); // "fadeIn"
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Custom Formatting
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
import { parse, stringify } from '@adobe/css-tools';
|
|
279
|
+
|
|
280
|
+
const css = '.example{color:red;font-size:16px}';
|
|
281
|
+
const ast = parse(css);
|
|
282
|
+
|
|
283
|
+
// Custom indentation
|
|
284
|
+
const formatted = stringify(ast, { indent: ' ' });
|
|
285
|
+
console.log(formatted);
|
|
286
|
+
// Output:
|
|
287
|
+
// .example {
|
|
288
|
+
// color: red;
|
|
289
|
+
// font-size: 16px;
|
|
290
|
+
// }
|
|
291
|
+
|
|
292
|
+
// Compressed with no spaces
|
|
293
|
+
const compressed = stringify(ast, { compress: true });
|
|
294
|
+
console.log(compressed);
|
|
295
|
+
// Output: .example{color:red;font-size:16px}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Identity Round-Trip
|
|
299
|
+
|
|
300
|
+
Reproduce the original CSS exactly as it was written, preserving all whitespace, comments, and formatting:
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
import { parse, stringify } from '@adobe/css-tools';
|
|
304
|
+
|
|
305
|
+
const css = '.example { color: red; font-size:16px }';
|
|
306
|
+
|
|
307
|
+
// Parse with preserveFormatting to store original source
|
|
308
|
+
const ast = parse(css, { preserveFormatting: true });
|
|
309
|
+
|
|
310
|
+
// Stringify with identity mode to reproduce the original CSS
|
|
311
|
+
const output = stringify(ast, { identity: true });
|
|
312
|
+
console.log(output === css); // true
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
When `preserveFormatting` was not used during parsing, identity mode falls back to beautified output.
|
|
316
|
+
|
|
317
|
+
### Removing Empty Rules
|
|
318
|
+
|
|
319
|
+
Strip rules with empty declaration blocks from the output:
|
|
320
|
+
|
|
321
|
+
```javascript
|
|
322
|
+
import { parse, stringify } from '@adobe/css-tools';
|
|
323
|
+
|
|
324
|
+
const css = '.empty {} .keep { color: red; }';
|
|
325
|
+
const ast = parse(css);
|
|
326
|
+
|
|
327
|
+
// Beautified without empty rules
|
|
328
|
+
const output = stringify(ast, { removeEmptyRules: true });
|
|
329
|
+
console.log(output);
|
|
330
|
+
// Output:
|
|
331
|
+
// .keep {
|
|
332
|
+
// color: red;
|
|
333
|
+
// }
|
|
334
|
+
|
|
335
|
+
// Also works with compressed mode
|
|
336
|
+
const compressed = stringify(ast, { compress: true, removeEmptyRules: true });
|
|
337
|
+
console.log(compressed);
|
|
338
|
+
// Output: .keep{color:red;}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## TypeScript Integration
|
|
342
|
+
|
|
343
|
+
The library provides comprehensive TypeScript support with full type definitions for all AST nodes and functions:
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
import { parse, stringify, type CssStylesheetAST } from '@adobe/css-tools';
|
|
347
|
+
|
|
348
|
+
const css: string = '.example { color: red; }';
|
|
349
|
+
const ast: CssStylesheetAST = parse(css);
|
|
350
|
+
const output: string = stringify(ast);
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
## Performance Considerations
|
|
354
|
+
|
|
355
|
+
- The parser is optimized for large CSS files
|
|
356
|
+
- AST nodes are lightweight and memory-efficient
|
|
357
|
+
- Stringification is fast and supports streaming for large outputs
|
|
358
|
+
- Consider using `compress: true` for production builds to reduce file size
|
|
359
|
+
|
|
360
|
+
## Browser Support
|
|
361
|
+
|
|
362
|
+
The library works in all modern browsers and Node.js environments. For older environments, you may need to use a bundler with appropriate polyfills.
|