@tbela99/css-parser 2.1.0 → 2.3.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/CHANGELOG.md +66 -1
- package/README.md +14 -7
- package/architecture.png +0 -0
- package/dist/{src/lib/ast → ast}/arena-node.js +10 -10
- package/dist/{src/lib/ast → ast}/arena.js +304 -139
- package/dist/{src/lib/ast → ast}/cache.js +40 -24
- package/dist/{src/lib/ast → ast}/features/calc.js +11 -9
- package/dist/{src/lib/ast → ast}/features/if.js +6 -6
- package/dist/ast/features/index.d.ts +7 -0
- package/dist/{src/lib/ast → ast}/features/index.js +3 -2
- package/dist/{src/lib/ast → ast}/features/inlinecssvariables.js +12 -10
- package/dist/ast/features/mixin.js +953 -0
- package/dist/{src/lib/ast → ast}/features/prefix.js +39 -39
- package/dist/ast/features/shorthand.js +129 -0
- package/dist/ast/features/transform.js +188 -0
- package/dist/{src/lib/ast → ast}/features/type.js +2 -2
- package/dist/{src/lib/ast → ast}/math/expression.js +24 -24
- package/dist/{src/lib/ast → ast}/math/math.js +2 -2
- package/dist/{src/lib/ast → ast}/minify.js +745 -201
- package/dist/ast/mixins/custom-function.js +393 -0
- package/dist/ast/mixins/utils.js +53 -0
- package/dist/ast/mixins/variables.js +678 -0
- package/dist/ast/strings.js +910 -0
- package/dist/ast/transform/compute.js +560 -0
- package/dist/ast/transform/matrix.js +67 -0
- package/dist/ast/transform/minify.js +325 -0
- package/dist/ast/transform/perspective.js +24 -0
- package/dist/{src/lib/ast → ast}/transform/rotate.js +16 -7
- package/dist/ast/transform/scale.js +43 -0
- package/dist/ast/transform/skew.js +38 -0
- package/dist/ast/transform/translate.js +56 -0
- package/dist/ast/transform/utils.js +390 -0
- package/dist/{src/lib/ast → ast}/types.js +2 -2
- package/dist/{src/lib/ast → ast}/walk.js +2 -2
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +30 -21
- package/dist/{src/lib/fs → fs}/resolve.js +2 -2
- package/dist/index-umd-web.js +19727 -10719
- package/dist/index.d.ts +738 -100
- package/dist/{src/node.js → node.js} +70 -52
- package/dist/{src/lib/parser → parser}/declaration/list.js +25 -8
- package/dist/{src/lib/parser → parser}/declaration/map.js +15 -15
- package/dist/{src/lib/parser → parser}/declaration/set.js +5 -5
- package/dist/{src/lib/parser → parser}/input.js +18 -3
- package/dist/{src/lib/parser → parser}/linesmap.js +2 -2
- package/dist/{src/lib/parser → parser}/parse.js +444 -278
- package/dist/{src/lib/parser → parser}/source.js +3 -3
- package/dist/{src/lib/parser → parser}/tokenize.js +480 -312
- package/dist/{src/lib/parser → parser}/utils/angle.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/at-rule-container.js +12 -12
- package/dist/{src/lib/parser → parser}/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/at-rule-generic.js +7 -7
- package/dist/{src/lib/parser → parser}/utils/at-rule-import.js +10 -10
- package/dist/{src/lib/parser → parser}/utils/at-rule-media.js +14 -14
- package/dist/{src/lib/parser → parser}/utils/at-rule-support.js +9 -14
- package/dist/{src/lib/parser → parser}/utils/at-rule-when-else.js +6 -6
- package/dist/{src/lib/parser → parser}/utils/at-rule.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/base64.js +2 -2
- package/dist/parser/utils/cache.js +53 -0
- package/dist/parser/utils/canonical.js +78 -0
- package/dist/parser/utils/codes.js +93 -0
- package/dist/{src/lib/parser → parser}/utils/config.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/declaration.js +31 -26
- package/dist/{src/lib/parser → parser}/utils/eq.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/hash.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/selector.js +339 -87
- package/dist/{src/lib/parser → parser}/utils/text.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/token.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/type.js +9 -7
- package/dist/{src/lib/printer/sourcemap → printer}/lib/codec.js +2 -2
- package/dist/{src/lib/printer → printer}/render.js +582 -153
- package/dist/printer/result.js +148 -0
- package/dist/{src/lib/printer/sourcemap → printer}/sourcemap.js +4 -3
- package/dist/printer/writer.js +252 -0
- package/dist/{src/lib/syntax → syntax}/color/a98rgb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/alpha.js +10 -10
- package/dist/{src/lib/syntax → syntax}/color/cmyk.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/color-mix.js +18 -18
- package/dist/{src/lib/syntax → syntax}/color/color.js +18 -18
- package/dist/{src/lib/syntax → syntax}/color/hex.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/hsl.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/hwb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/lab.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/lch.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/oklab.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/oklch.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/p3.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/prophotorgb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/rec2020.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/relative-color.js +14 -14
- package/dist/{src/lib/syntax → syntax}/color/rgb.js +4 -4
- package/dist/{src/lib/syntax → syntax}/color/srgb.js +5 -5
- package/dist/{src/lib/syntax → syntax}/color/utils/color-type.js +4 -4
- package/dist/{src/lib/syntax → syntax}/color/utils/colorspace.js +10 -10
- package/dist/{src/lib/syntax → syntax}/color/utils/components.js +5 -5
- package/dist/{src/lib/syntax → syntax}/color/utils/distance.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/utils/make-color.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/utils/matrix.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/xyz.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/xyzd50.js +2 -2
- package/dist/{src/lib/syntax → syntax}/constants.js +27 -4
- package/dist/{src/lib/syntax → syntax}/syntax.js +37 -29
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +12 -7
- package/dist/validation/compiled/builtins.js +32 -0
- package/dist/validation/compiled/runtime.js +705 -0
- package/dist/validation/compiled/syntaxes.js +1620 -0
- package/dist/{src/lib/validation → validation}/config.js +63 -16
- package/dist/validation/first.js +574 -0
- package/dist/{src/lib/validation → validation}/match.js +376 -161
- package/dist/{src/lib/validation → validation}/parser/parse.js +2 -2
- package/dist/{src/lib/validation → validation}/parser/typedef.js +2 -2
- package/dist/{src/lib/validation → validation}/utils/list.js +3 -19
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +68 -55
- package/package.json +15 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -95
- package/dist/src/lib/ast/features/transform.js +0 -90
- package/dist/src/lib/ast/transform/compute.js +0 -362
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/types.d.ts +0 -21
- package/dist/utils/sync.d.ts +0 -16
package/dist/index.d.ts
CHANGED
|
@@ -1242,6 +1242,410 @@ declare class AstArenaNode {
|
|
|
1242
1242
|
toJSON(): PlainAstNode | PlainToken;
|
|
1243
1243
|
}
|
|
1244
1244
|
|
|
1245
|
+
/**
|
|
1246
|
+
* Hashing and comparison of strings and of ranges of code units, without creating strings.
|
|
1247
|
+
*
|
|
1248
|
+
* The tokenizer reads the code units of the css source (see `toCodeUnits()`): the values of the tokens are ranges of
|
|
1249
|
+
* the code units. The tables of the tokenizer and the string table of the arena are keyed by the hash of the code units:
|
|
1250
|
+
* a string and a range of code units with the same content have the same hash. When the hashes are equal, the code
|
|
1251
|
+
* units are compared: the hash is 30 bits, different strings may have the same hash.
|
|
1252
|
+
*
|
|
1253
|
+
* @module
|
|
1254
|
+
* @internal
|
|
1255
|
+
*/
|
|
1256
|
+
/**
|
|
1257
|
+
* code units of the css source: the bytes of an ascii input, the utf-16 code units otherwise
|
|
1258
|
+
*/
|
|
1259
|
+
type CodeUnits = Uint8Array | Uint16Array;
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* String table of an arena.
|
|
1263
|
+
*
|
|
1264
|
+
* The strings of the nodes (selectors, names, identifiers, strings, units, ...) are interned: a node stores a string id.
|
|
1265
|
+
* An interned string is not necessarily a string object, it is a range of a text:
|
|
1266
|
+
*
|
|
1267
|
+
* - a range of the content of a source file (`source.content`): the values of the tokens read by the tokenizer. the
|
|
1268
|
+
* table stores the source index and the start and end offsets, no string is created
|
|
1269
|
+
* - a range of the canonical text (see {@link canonicalText}): the spelling of the known units and function names
|
|
1270
|
+
* - a range of the pool: the code units of the strings that are not a range of a source (decoded escape sequences,
|
|
1271
|
+
* the values parsed from a string by `parseString()`) are copied to the pool
|
|
1272
|
+
* - a string: the strings interned by {@link StringTable.intern} (generated by the minifier, the visitors, ...) are
|
|
1273
|
+
* kept as they are
|
|
1274
|
+
*
|
|
1275
|
+
* The table is keyed by the hash of the code units: a string and a range with the same content have the same id.
|
|
1276
|
+
* When the hashes are equal, the code units are compared. The strings are created when they are read
|
|
1277
|
+
* ({@link StringTable.get}), once per id.
|
|
1278
|
+
*
|
|
1279
|
+
* @module
|
|
1280
|
+
* @internal
|
|
1281
|
+
*/
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
* boolean properties of the strings computed once per string id, see {@link StringTable.flag}. 4 flags at most
|
|
1285
|
+
*/
|
|
1286
|
+
declare const enum StringFlag {
|
|
1287
|
+
/**
|
|
1288
|
+
* the string is a named color, a system color or `currentcolor` / `transparent`, ignoring the case
|
|
1289
|
+
*/
|
|
1290
|
+
Color = 0,
|
|
1291
|
+
/**
|
|
1292
|
+
* a rule selector that is not modified by the minifier (see `isSimpleSelector()`)
|
|
1293
|
+
*/
|
|
1294
|
+
SimpleSelector = 1,
|
|
1295
|
+
/**
|
|
1296
|
+
* a rule selector that contains a vendor prefixed pseudo class (see `selectorPrefixes()`)
|
|
1297
|
+
*/
|
|
1298
|
+
VendorPrefix = 2
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* values derived from the strings computed once per string id, see {@link StringTable.derived}
|
|
1302
|
+
*/
|
|
1303
|
+
declare const enum StringDerived {
|
|
1304
|
+
/**
|
|
1305
|
+
* the validation syntax of a function (`name()`)
|
|
1306
|
+
*/
|
|
1307
|
+
FunctionSyntax = 0,
|
|
1308
|
+
/**
|
|
1309
|
+
* the validation syntax of a selector function (`:name()`)
|
|
1310
|
+
*/
|
|
1311
|
+
SelectorFunctionSyntax = 1,
|
|
1312
|
+
/**
|
|
1313
|
+
* the kind of a transform function name or of a transform property name (see `transformKind()`)
|
|
1314
|
+
*/
|
|
1315
|
+
TransformKind = 2,
|
|
1316
|
+
/**
|
|
1317
|
+
* true if the rules are allowed in the block of an at-rule (by name, without `@`), see `parseSelector()`
|
|
1318
|
+
*/
|
|
1319
|
+
AtRuleAcceptsRules = 3
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* structured-cloneable copy of a string table, see {@link StringTable.export}
|
|
1323
|
+
*/
|
|
1324
|
+
interface StringTableData {
|
|
1325
|
+
/**
|
|
1326
|
+
* number of strings
|
|
1327
|
+
*/
|
|
1328
|
+
count: number;
|
|
1329
|
+
/**
|
|
1330
|
+
* hash, source, start and end of each string
|
|
1331
|
+
*/
|
|
1332
|
+
hashes: Int32Array;
|
|
1333
|
+
sources: Int32Array;
|
|
1334
|
+
starts: Int32Array;
|
|
1335
|
+
ends: Int32Array;
|
|
1336
|
+
/**
|
|
1337
|
+
* text of each source, by source index
|
|
1338
|
+
*/
|
|
1339
|
+
texts: string[];
|
|
1340
|
+
/**
|
|
1341
|
+
* code units of the pool
|
|
1342
|
+
*/
|
|
1343
|
+
pool: Uint16Array;
|
|
1344
|
+
/**
|
|
1345
|
+
* the strings of the `StringSource.Value` entries, by id
|
|
1346
|
+
*/
|
|
1347
|
+
values: Array<string | undefined>;
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* builds a string from code units, strings and interned strings, then interns it: no string is created
|
|
1351
|
+
*
|
|
1352
|
+
* @internal
|
|
1353
|
+
*/
|
|
1354
|
+
declare class StringBuilder {
|
|
1355
|
+
/**
|
|
1356
|
+
* code units
|
|
1357
|
+
*/
|
|
1358
|
+
codes: Uint16Array;
|
|
1359
|
+
/**
|
|
1360
|
+
* number of code units
|
|
1361
|
+
*/
|
|
1362
|
+
length: number;
|
|
1363
|
+
/**
|
|
1364
|
+
* drop the code units
|
|
1365
|
+
*/
|
|
1366
|
+
reset(): this;
|
|
1367
|
+
/**
|
|
1368
|
+
* append the code units of an interned string
|
|
1369
|
+
* @param table
|
|
1370
|
+
* @param id
|
|
1371
|
+
*/
|
|
1372
|
+
appendId(table: StringTable, id: number): this;
|
|
1373
|
+
/**
|
|
1374
|
+
* append a string
|
|
1375
|
+
* @param str
|
|
1376
|
+
*/
|
|
1377
|
+
appendString(str: string): this;
|
|
1378
|
+
/**
|
|
1379
|
+
* append a code unit
|
|
1380
|
+
* @param code
|
|
1381
|
+
*/
|
|
1382
|
+
appendCode(code: number): this;
|
|
1383
|
+
/**
|
|
1384
|
+
* intern the string
|
|
1385
|
+
* @param table
|
|
1386
|
+
*/
|
|
1387
|
+
intern(table: StringTable): number;
|
|
1388
|
+
/**
|
|
1389
|
+
* make room for more code units
|
|
1390
|
+
* @param size
|
|
1391
|
+
*/
|
|
1392
|
+
private reserve;
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* interned strings of an arena
|
|
1396
|
+
*
|
|
1397
|
+
* @internal
|
|
1398
|
+
*/
|
|
1399
|
+
declare class StringTable {
|
|
1400
|
+
/**
|
|
1401
|
+
* An instance is kept alive: the hidden class of the instances would otherwise be collected by a full garbage
|
|
1402
|
+
* collection when no instance is alive, and the optimized code that depends on it discarded (deoptimized)
|
|
1403
|
+
*/
|
|
1404
|
+
static readonly shape: StringTable;
|
|
1405
|
+
/**
|
|
1406
|
+
* number of strings
|
|
1407
|
+
*/
|
|
1408
|
+
count: number;
|
|
1409
|
+
/**
|
|
1410
|
+
* strings by id: the strings that have been read (see {@link get}) and the `StringSource.Value` strings
|
|
1411
|
+
*/
|
|
1412
|
+
cache: Array<string | undefined>;
|
|
1413
|
+
/**
|
|
1414
|
+
* identity of the ids: replaced when the ids change (see {@link compact}). the caches keyed by string ids use it
|
|
1415
|
+
* as a key
|
|
1416
|
+
*/
|
|
1417
|
+
epoch: object;
|
|
1418
|
+
/**
|
|
1419
|
+
* hash of each string
|
|
1420
|
+
*/
|
|
1421
|
+
private hashes;
|
|
1422
|
+
/**
|
|
1423
|
+
* source of each string, see {@link StringSource}
|
|
1424
|
+
*/
|
|
1425
|
+
private sources;
|
|
1426
|
+
/**
|
|
1427
|
+
* start of each string in its source
|
|
1428
|
+
*/
|
|
1429
|
+
private starts;
|
|
1430
|
+
/**
|
|
1431
|
+
* end of each string in its source
|
|
1432
|
+
*/
|
|
1433
|
+
private ends;
|
|
1434
|
+
/**
|
|
1435
|
+
* hash table: string id + 1 by slot, 0 when the slot is empty (open addressing, linear probing). the load factor
|
|
1436
|
+
* is at most 0.5
|
|
1437
|
+
*/
|
|
1438
|
+
private slots;
|
|
1439
|
+
/**
|
|
1440
|
+
* text of the sources, by source index
|
|
1441
|
+
*/
|
|
1442
|
+
private texts;
|
|
1443
|
+
/**
|
|
1444
|
+
* code units of the sources being tokenized, by source index
|
|
1445
|
+
*/
|
|
1446
|
+
private codes;
|
|
1447
|
+
/**
|
|
1448
|
+
* values derived from the strings, by slot and by id (see {@link derived})
|
|
1449
|
+
*/
|
|
1450
|
+
private derivedValues;
|
|
1451
|
+
/**
|
|
1452
|
+
* properties of the strings, by id (see {@link flag})
|
|
1453
|
+
*/
|
|
1454
|
+
private flags;
|
|
1455
|
+
/**
|
|
1456
|
+
* id of the lowercase string + 1, by id. 0 when it is not computed (see {@link lower})
|
|
1457
|
+
*/
|
|
1458
|
+
private lowers;
|
|
1459
|
+
/**
|
|
1460
|
+
* builder of the lowercase strings
|
|
1461
|
+
*/
|
|
1462
|
+
private readonly builder;
|
|
1463
|
+
/**
|
|
1464
|
+
* code units of the strings that are not a range of a source
|
|
1465
|
+
*/
|
|
1466
|
+
private pool;
|
|
1467
|
+
/**
|
|
1468
|
+
* used length of the pool
|
|
1469
|
+
*/
|
|
1470
|
+
private poolLength;
|
|
1471
|
+
/**
|
|
1472
|
+
* set the text of a source: the strings of the source are ranges of the text
|
|
1473
|
+
* @param source source index
|
|
1474
|
+
* @param text content of the source
|
|
1475
|
+
* @param codes code units of the text, while the source is tokenized: the ranges are compared with the code units
|
|
1476
|
+
* (faster than the text). see {@link releaseCodes}
|
|
1477
|
+
*/
|
|
1478
|
+
setText(source: number, text: string, codes?: CodeUnits | null): void;
|
|
1479
|
+
/**
|
|
1480
|
+
* drop the code units of a source: the source is no longer tokenized, see {@link setText}
|
|
1481
|
+
* @param source
|
|
1482
|
+
*/
|
|
1483
|
+
releaseCodes(source: number): void;
|
|
1484
|
+
/**
|
|
1485
|
+
* intern a string
|
|
1486
|
+
* @param str
|
|
1487
|
+
* @returns the string id
|
|
1488
|
+
*/
|
|
1489
|
+
intern(str: string): number;
|
|
1490
|
+
/**
|
|
1491
|
+
* intern a range of code units
|
|
1492
|
+
* @param codes code units
|
|
1493
|
+
* @param start
|
|
1494
|
+
* @param end
|
|
1495
|
+
* @param source where the range is stored when it is interned: the index of the source the code units are read
|
|
1496
|
+
* from (the range is kept), `StringSource.Canonical` (the code units are the canonical text) or `StringSource.Pool`
|
|
1497
|
+
* (the code units are copied)
|
|
1498
|
+
* @returns the string id
|
|
1499
|
+
*/
|
|
1500
|
+
internRange(codes: CodeUnits, start: number, end: number, source: number): number;
|
|
1501
|
+
/**
|
|
1502
|
+
* id of a string, -1 when the string is not interned
|
|
1503
|
+
* @param str
|
|
1504
|
+
*/
|
|
1505
|
+
lookup(str: string): number;
|
|
1506
|
+
/**
|
|
1507
|
+
* the string of an id. the string is created the first time it is read
|
|
1508
|
+
* @param id
|
|
1509
|
+
*/
|
|
1510
|
+
get(id: number): string;
|
|
1511
|
+
/**
|
|
1512
|
+
* length of a string
|
|
1513
|
+
* @param id
|
|
1514
|
+
*/
|
|
1515
|
+
length(id: number): number;
|
|
1516
|
+
/**
|
|
1517
|
+
* code unit of a string
|
|
1518
|
+
* @param id
|
|
1519
|
+
* @param index
|
|
1520
|
+
*/
|
|
1521
|
+
codeAt(id: number, index: number): number;
|
|
1522
|
+
/**
|
|
1523
|
+
* copy the code units of a string to a buffer. the string is not created
|
|
1524
|
+
* @param id
|
|
1525
|
+
* @param target
|
|
1526
|
+
* @param offset offset in the target
|
|
1527
|
+
* @returns the number of code units
|
|
1528
|
+
*/
|
|
1529
|
+
copy(id: number, target: Uint16Array, offset: number): number;
|
|
1530
|
+
/**
|
|
1531
|
+
* a boolean property of a string, computed once per id: the string is read once (see {@link StringFlag})
|
|
1532
|
+
* @param id
|
|
1533
|
+
* @param flag
|
|
1534
|
+
* @param compute computes the property from the string
|
|
1535
|
+
*/
|
|
1536
|
+
flag(id: number, flag: StringFlag, compute: (str: string) => boolean): boolean;
|
|
1537
|
+
/**
|
|
1538
|
+
* a boolean property of a string, computed once per id from the string id (the string is not necessarily read),
|
|
1539
|
+
* see {@link flag}
|
|
1540
|
+
* @param id
|
|
1541
|
+
* @param flag
|
|
1542
|
+
* @param compute computes the property from the string id
|
|
1543
|
+
*/
|
|
1544
|
+
flagId(id: number, flag: StringFlag, compute: (id: number) => boolean): boolean;
|
|
1545
|
+
/**
|
|
1546
|
+
* a value derived from a string, computed once per id (see {@link StringDerived})
|
|
1547
|
+
* @param id
|
|
1548
|
+
* @param slot
|
|
1549
|
+
* @param compute computes the value from the string id
|
|
1550
|
+
*/
|
|
1551
|
+
derived<T>(id: number, slot: StringDerived, compute: (id: number) => T): T;
|
|
1552
|
+
/**
|
|
1553
|
+
* copy the code units of a string to a byte buffer when they are all ascii (UTF-8 encoding). the string is not
|
|
1554
|
+
* created
|
|
1555
|
+
* @param id
|
|
1556
|
+
* @param target
|
|
1557
|
+
* @param offset offset in the target. the target has room for the string
|
|
1558
|
+
* @returns the number of bytes, -1 when the string is not ascii
|
|
1559
|
+
*/
|
|
1560
|
+
copyAscii(id: number, target: Uint8Array, offset: number): number;
|
|
1561
|
+
/**
|
|
1562
|
+
* index of the first occurrence of a code unit in a string, -1 when it is not found. the string is not created
|
|
1563
|
+
* @param id
|
|
1564
|
+
* @param code
|
|
1565
|
+
*/
|
|
1566
|
+
indexOfCode(id: number, code: number): number;
|
|
1567
|
+
/**
|
|
1568
|
+
* true if the string of an id equals a string. the string is not created
|
|
1569
|
+
* @param id
|
|
1570
|
+
* @param str
|
|
1571
|
+
*/
|
|
1572
|
+
equals(id: number, str: string): boolean;
|
|
1573
|
+
/**
|
|
1574
|
+
* id of the lowercase string (like `toLowerCase()`): the id itself when the string has no uppercase letter. the
|
|
1575
|
+
* string is not created when it is ascii
|
|
1576
|
+
* @param id
|
|
1577
|
+
*/
|
|
1578
|
+
lower(id: number): number;
|
|
1579
|
+
/**
|
|
1580
|
+
* true if the string of an id starts with a string. the string is not created
|
|
1581
|
+
* @param id
|
|
1582
|
+
* @param str
|
|
1583
|
+
*/
|
|
1584
|
+
startsWith(id: number, str: string): boolean;
|
|
1585
|
+
/**
|
|
1586
|
+
* true if the string of an id equals a string, ignoring the case of the ascii letters. the string is not created
|
|
1587
|
+
* @param id
|
|
1588
|
+
* @param str
|
|
1589
|
+
*/
|
|
1590
|
+
equalsIgnoreCase(id: number, str: string): boolean;
|
|
1591
|
+
/**
|
|
1592
|
+
* drop the strings that are not used and renumber the others
|
|
1593
|
+
* @param used used strings, by id
|
|
1594
|
+
* @returns the new id of each string
|
|
1595
|
+
*/
|
|
1596
|
+
compact(used: Uint8Array): Uint32Array;
|
|
1597
|
+
/**
|
|
1598
|
+
* structured-cloneable copy of the table
|
|
1599
|
+
*/
|
|
1600
|
+
export(): StringTableData;
|
|
1601
|
+
/**
|
|
1602
|
+
* initialize the table from an exported copy
|
|
1603
|
+
* @param data
|
|
1604
|
+
*/
|
|
1605
|
+
import(data: StringTableData): void;
|
|
1606
|
+
/**
|
|
1607
|
+
* add a string
|
|
1608
|
+
* @param hash
|
|
1609
|
+
* @param slot empty slot of the hash table
|
|
1610
|
+
* @param source
|
|
1611
|
+
* @param start
|
|
1612
|
+
* @param end
|
|
1613
|
+
*/
|
|
1614
|
+
private add;
|
|
1615
|
+
/**
|
|
1616
|
+
* true if a string has the code units of a range
|
|
1617
|
+
* @param id
|
|
1618
|
+
* @param codes
|
|
1619
|
+
* @param start
|
|
1620
|
+
* @param end
|
|
1621
|
+
*/
|
|
1622
|
+
private equalsRange;
|
|
1623
|
+
/**
|
|
1624
|
+
* true if a string equals a string
|
|
1625
|
+
* @param id
|
|
1626
|
+
* @param str
|
|
1627
|
+
*/
|
|
1628
|
+
private equalsString;
|
|
1629
|
+
/**
|
|
1630
|
+
* grow the columns of the strings
|
|
1631
|
+
* @param size
|
|
1632
|
+
*/
|
|
1633
|
+
private grow;
|
|
1634
|
+
/**
|
|
1635
|
+
* drop the strings, allocate the columns for `count` strings. the ids change
|
|
1636
|
+
* @param count
|
|
1637
|
+
*/
|
|
1638
|
+
private reset;
|
|
1639
|
+
/**
|
|
1640
|
+
* rebuild the hash table
|
|
1641
|
+
*/
|
|
1642
|
+
private rehash;
|
|
1643
|
+
/**
|
|
1644
|
+
* shallow copy of the table
|
|
1645
|
+
*/
|
|
1646
|
+
private clone;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1245
1649
|
/**
|
|
1246
1650
|
* Arena memory manager: ast nodes and value tokens are integer ids, their data is stored column-wise
|
|
1247
1651
|
* in typed arrays (structure of arrays), lists are doubly linked lists stored in the `firstChild` /
|
|
@@ -1311,7 +1715,7 @@ interface ArenaProperties {
|
|
|
1311
1715
|
/**
|
|
1312
1716
|
* interned strings
|
|
1313
1717
|
*/
|
|
1314
|
-
strings:
|
|
1718
|
+
strings: StringTableData;
|
|
1315
1719
|
/**
|
|
1316
1720
|
* validation errors by node id
|
|
1317
1721
|
*/
|
|
@@ -1323,11 +1727,15 @@ interface ArenaProperties {
|
|
|
1323
1727
|
/**
|
|
1324
1728
|
* raw selectors cache ({@link AstArena})
|
|
1325
1729
|
*/
|
|
1326
|
-
raw?: Array<RawSelectorTokens | null | undefined>;
|
|
1730
|
+
raw?: Array<[number, RawSelectorTokens | null | undefined]>;
|
|
1327
1731
|
/**
|
|
1328
1732
|
* optimized selectors cache ({@link AstArena})
|
|
1329
1733
|
*/
|
|
1330
|
-
optimized?: Array<OptimizedSelector | null | undefined>;
|
|
1734
|
+
optimized?: Array<[number, OptimizedSelector | null | undefined]>;
|
|
1735
|
+
/**
|
|
1736
|
+
* input length of the parsed stylesheets ({@link AstArena})
|
|
1737
|
+
*/
|
|
1738
|
+
inputLengths?: Array<number | undefined>;
|
|
1331
1739
|
}
|
|
1332
1740
|
/**
|
|
1333
1741
|
* Column buffers of an arena, in the order of {@link arenaColumns}. See {@link Arena.toTransferableArenaObject}
|
|
@@ -1348,13 +1756,9 @@ declare const arenaColumns: readonly ["dataTypes", "parents", "nextSibling", "pr
|
|
|
1348
1756
|
declare class Arena {
|
|
1349
1757
|
#private;
|
|
1350
1758
|
/**
|
|
1351
|
-
*
|
|
1759
|
+
* interned strings: ranges of the sources, of the canonical text, of the pool, or strings. see {@link StringTable}
|
|
1352
1760
|
*/
|
|
1353
|
-
|
|
1354
|
-
/**
|
|
1355
|
-
* string interner values
|
|
1356
|
-
*/
|
|
1357
|
-
strings: string[];
|
|
1761
|
+
protected stringTable: StringTable;
|
|
1358
1762
|
/**
|
|
1359
1763
|
* root node
|
|
1360
1764
|
*/
|
|
@@ -1488,10 +1892,140 @@ declare class Arena {
|
|
|
1488
1892
|
recycle(id: number): void;
|
|
1489
1893
|
/**
|
|
1490
1894
|
* Interns a string and returns its unique ID. If the string has already been interned, it returns the existing ID.
|
|
1895
|
+
* The strings are looked up by the hash of their code units, see {@link internRange}
|
|
1491
1896
|
* @param str
|
|
1492
1897
|
* @returns
|
|
1493
1898
|
*/
|
|
1494
1899
|
internString(str: string): number;
|
|
1900
|
+
/**
|
|
1901
|
+
* Interns the string made of a range of code units and returns its unique ID. Same ID as {@link internString} for
|
|
1902
|
+
* the same content. The range is looked up by its hash and compared with the code units of the interned strings:
|
|
1903
|
+
* no string is created.
|
|
1904
|
+
*
|
|
1905
|
+
* - a range of a source (the code units read by the tokenizer): the source index and the offsets are stored, the
|
|
1906
|
+
* text of the source is set with {@link setSourceText}
|
|
1907
|
+
* - `StringSource.Canonical`: a range of the canonical text (the spelling of the known units and function names)
|
|
1908
|
+
* - `StringSource.Pool`: the code units are copied (decoded escape sequences, ...)
|
|
1909
|
+
*
|
|
1910
|
+
* @param codes code units
|
|
1911
|
+
* @param start start offset of the range
|
|
1912
|
+
* @param end end offset of the range
|
|
1913
|
+
* @param source source index, `StringSource.Canonical` or `StringSource.Pool`
|
|
1914
|
+
*/
|
|
1915
|
+
internRange(codes: CodeUnits, start: number, end: number, source: number): number;
|
|
1916
|
+
/**
|
|
1917
|
+
* set the text of a source: the strings interned from the source are ranges of the text, see {@link internRange}
|
|
1918
|
+
* @param source source index
|
|
1919
|
+
* @param text content of the source
|
|
1920
|
+
* @param codes code units of the text while the source is tokenized (faster comparisons)
|
|
1921
|
+
*/
|
|
1922
|
+
setSourceText(source: number, text: string, codes?: CodeUnits | null): void;
|
|
1923
|
+
/**
|
|
1924
|
+
* drop the code units of a source set by {@link setSourceText}: the source is no longer tokenized
|
|
1925
|
+
* @param source source index
|
|
1926
|
+
*/
|
|
1927
|
+
releaseSourceCodes(source: number): void;
|
|
1928
|
+
/**
|
|
1929
|
+
* id of an interned string, -1 when the string is not interned
|
|
1930
|
+
* @param str
|
|
1931
|
+
*/
|
|
1932
|
+
stringId(str: string): number;
|
|
1933
|
+
/**
|
|
1934
|
+
* length of an interned string. the string is not created
|
|
1935
|
+
* @param id
|
|
1936
|
+
*/
|
|
1937
|
+
stringLength(id: number): number;
|
|
1938
|
+
/**
|
|
1939
|
+
* code unit of an interned string. the string is not created
|
|
1940
|
+
* @param id
|
|
1941
|
+
* @param index
|
|
1942
|
+
*/
|
|
1943
|
+
stringCodeAt(id: number, index: number): number;
|
|
1944
|
+
/**
|
|
1945
|
+
* index of the first occurrence of a code unit in an interned string, -1 when it is not found. the string is not
|
|
1946
|
+
* created
|
|
1947
|
+
* @param id
|
|
1948
|
+
* @param code
|
|
1949
|
+
*/
|
|
1950
|
+
stringIndexOf(id: number, code: number): number;
|
|
1951
|
+
/**
|
|
1952
|
+
* true if an interned string equals a string. the interned string is not created
|
|
1953
|
+
* @param id
|
|
1954
|
+
* @param str
|
|
1955
|
+
*/
|
|
1956
|
+
stringEquals(id: number, str: string): boolean;
|
|
1957
|
+
/**
|
|
1958
|
+
* true if an interned string equals a string, ignoring the case of the ascii letters. the interned string is not
|
|
1959
|
+
* created
|
|
1960
|
+
* @param id
|
|
1961
|
+
* @param str
|
|
1962
|
+
*/
|
|
1963
|
+
stringEqualsIgnoreCase(id: number, str: string): boolean;
|
|
1964
|
+
/**
|
|
1965
|
+
* true if an interned string starts with a string. the interned string is not created
|
|
1966
|
+
* @param id
|
|
1967
|
+
* @param str
|
|
1968
|
+
*/
|
|
1969
|
+
stringStartsWith(id: number, str: string): boolean;
|
|
1970
|
+
/**
|
|
1971
|
+
* id of the lowercase version of an interned string (like `toLowerCase()`). no string is created when the string
|
|
1972
|
+
* is ascii. the result is cached
|
|
1973
|
+
* @param id
|
|
1974
|
+
*/
|
|
1975
|
+
lowerStringId(id: number): number;
|
|
1976
|
+
/**
|
|
1977
|
+
* copy an interned string to a byte buffer when it is ascii (UTF-8 encoding). the string is not created
|
|
1978
|
+
* @param id
|
|
1979
|
+
* @param target
|
|
1980
|
+
* @param offset offset in the target. the target has room for the string ({@link stringLength})
|
|
1981
|
+
* @returns the number of bytes, -1 when the string is not ascii
|
|
1982
|
+
*/
|
|
1983
|
+
copyStringAscii(id: number, target: Uint8Array, offset: number): number;
|
|
1984
|
+
/**
|
|
1985
|
+
* a boolean property of an interned string, computed once per string id: the string is read once
|
|
1986
|
+
* @param id
|
|
1987
|
+
* @param flag
|
|
1988
|
+
* @param compute computes the property from the string
|
|
1989
|
+
*/
|
|
1990
|
+
stringFlag(id: number, flag: StringFlag, compute: (str: string) => boolean): boolean;
|
|
1991
|
+
/**
|
|
1992
|
+
* a boolean property of an interned string, computed once per string id from the id (see {@link stringCodeAt})
|
|
1993
|
+
* @param id
|
|
1994
|
+
* @param flag
|
|
1995
|
+
* @param compute computes the property from the string id
|
|
1996
|
+
*/
|
|
1997
|
+
stringFlagId(id: number, flag: StringFlag, compute: (id: number) => boolean): boolean;
|
|
1998
|
+
/**
|
|
1999
|
+
* a value derived from an interned string, computed once per string id
|
|
2000
|
+
* @param id
|
|
2001
|
+
* @param slot
|
|
2002
|
+
* @param compute computes the value from the string id
|
|
2003
|
+
*/
|
|
2004
|
+
stringDerived<T>(id: number, slot: StringDerived, compute: (id: number) => T): T;
|
|
2005
|
+
/**
|
|
2006
|
+
* copy the code units of an interned string to a buffer. the string is not created
|
|
2007
|
+
* @param id
|
|
2008
|
+
* @param target the target has room for the string ({@link stringLength})
|
|
2009
|
+
* @param offset
|
|
2010
|
+
* @returns the number of code units
|
|
2011
|
+
*/
|
|
2012
|
+
copyString(id: number, target: Uint16Array, offset: number): number;
|
|
2013
|
+
/**
|
|
2014
|
+
* append an interned string to a builder. the string is not created
|
|
2015
|
+
* @param builder
|
|
2016
|
+
* @param id
|
|
2017
|
+
*/
|
|
2018
|
+
appendString(builder: StringBuilder, id: number): StringBuilder;
|
|
2019
|
+
/**
|
|
2020
|
+
* intern the string built by a builder: no string is created
|
|
2021
|
+
* @param builder
|
|
2022
|
+
*/
|
|
2023
|
+
internBuilder(builder: StringBuilder): number;
|
|
2024
|
+
/**
|
|
2025
|
+
* identity of the string ids: a new object when the strings are renumbered ({@link compact},
|
|
2026
|
+
* {@link compactStrings}). the caches keyed by string ids use it as a key
|
|
2027
|
+
*/
|
|
2028
|
+
get stringEpoch(): object;
|
|
1495
2029
|
/**
|
|
1496
2030
|
*
|
|
1497
2031
|
* @param id
|
|
@@ -2180,17 +2714,22 @@ declare class Arena {
|
|
|
2180
2714
|
*/
|
|
2181
2715
|
declare class AstArena extends Arena {
|
|
2182
2716
|
/**
|
|
2183
|
-
* raw selector (minification cache)
|
|
2717
|
+
* raw selector (minification cache), by rule id
|
|
2184
2718
|
*/
|
|
2185
|
-
raw:
|
|
2719
|
+
raw: Map<number, RawSelectorTokens | null | undefined>;
|
|
2186
2720
|
/**
|
|
2187
|
-
* optimized selector (minification cache)
|
|
2721
|
+
* optimized selector (minification cache), by rule id
|
|
2188
2722
|
*/
|
|
2189
|
-
optimized:
|
|
2723
|
+
optimized: Map<number, OptimizedSelector | null | undefined>;
|
|
2190
2724
|
/**
|
|
2191
2725
|
* source ids. `spans` store the index in this table (8 bits)
|
|
2192
2726
|
*/
|
|
2193
2727
|
sources: number[];
|
|
2728
|
+
/**
|
|
2729
|
+
* length of the css parsed into a stylesheet, imported files included. sparse: only the stylesheets created by
|
|
2730
|
+
* the parser have an entry. the render buffer is allocated from this length
|
|
2731
|
+
*/
|
|
2732
|
+
inputLengths: Array<number | undefined>;
|
|
2194
2733
|
/**
|
|
2195
2734
|
*
|
|
2196
2735
|
* @param size
|
|
@@ -2281,7 +2820,7 @@ declare class AstArena extends Arena {
|
|
|
2281
2820
|
* @param state
|
|
2282
2821
|
* @param errors
|
|
2283
2822
|
*/
|
|
2284
|
-
createRule(typ: EnumToken, sel: string, tokens: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2823
|
+
createRule(typ: EnumToken, sel: string | number, tokens: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2285
2824
|
/**
|
|
2286
2825
|
* allocate an at-rule node
|
|
2287
2826
|
* @param typ
|
|
@@ -2292,7 +2831,7 @@ declare class AstArena extends Arena {
|
|
|
2292
2831
|
* @param state
|
|
2293
2832
|
* @param errors
|
|
2294
2833
|
*/
|
|
2295
|
-
createAtRule(typ: EnumToken, nam: string, val: string, block: boolean, tokens: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2834
|
+
createAtRule(typ: EnumToken, nam: string | number, val: string | number, block: boolean, tokens: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2296
2835
|
/**
|
|
2297
2836
|
* allocate a declaration node
|
|
2298
2837
|
* @param typ
|
|
@@ -2301,13 +2840,13 @@ declare class AstArena extends Arena {
|
|
|
2301
2840
|
* @param state
|
|
2302
2841
|
* @param errors
|
|
2303
2842
|
*/
|
|
2304
|
-
createDeclaration(typ: EnumToken, nam: string, val: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2843
|
+
createDeclaration(typ: EnumToken, nam: string | number, val: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2305
2844
|
/**
|
|
2306
2845
|
* allocate a comment node
|
|
2307
2846
|
* @param typ
|
|
2308
2847
|
* @param val
|
|
2309
2848
|
*/
|
|
2310
|
-
createComment(typ: EnumToken, val: string): number;
|
|
2849
|
+
createComment(typ: EnumToken, val: string | number): number;
|
|
2311
2850
|
/**
|
|
2312
2851
|
* allocate a token. string values are interned, numeric values are stored in the `numericValue` column
|
|
2313
2852
|
* @param typ
|
|
@@ -2463,10 +3002,17 @@ declare class AstArena extends Arena {
|
|
|
2463
3002
|
*/
|
|
2464
3003
|
tokenToObject(id: number): PlainToken;
|
|
2465
3004
|
/**
|
|
2466
|
-
*
|
|
3005
|
+
* copy the data of a node (type, strings, values, flags, location, errors): its tokens, its children and the
|
|
3006
|
+
* minifier caches (`raw`, `optimized`) are not copied
|
|
2467
3007
|
* @param id
|
|
2468
|
-
|
|
2469
|
-
|
|
3008
|
+
*/
|
|
3009
|
+
cloneNode(id: number): number;
|
|
3010
|
+
/**
|
|
3011
|
+
* copy a node or a token. the tokens of a node are copied, its children are copied with `deep`. the values of a
|
|
3012
|
+
* declaration are copied with `deep`
|
|
3013
|
+
* @param id
|
|
3014
|
+
* @param deep copy the children and the values of the declarations
|
|
3015
|
+
* @param cloneMap records the copies: id of the copy by original id
|
|
2470
3016
|
*/
|
|
2471
3017
|
clone(id: number, deep?: boolean, cloneMap?: Map<number, number> | null): number;
|
|
2472
3018
|
/**
|
|
@@ -5338,12 +5884,6 @@ export declare interface PropertyListOptions {
|
|
|
5338
5884
|
* parse info
|
|
5339
5885
|
*/
|
|
5340
5886
|
export declare interface ParseInfo$1 {
|
|
5341
|
-
/**
|
|
5342
|
-
* the text of the css. the css input (a string, an ArrayBuffer or a view of an ArrayBuffer) is converted by the
|
|
5343
|
-
* tokenizer
|
|
5344
|
-
*/
|
|
5345
|
-
stream: string;
|
|
5346
|
-
|
|
5347
5887
|
/**
|
|
5348
5888
|
* the utf-16 code units of the css, read by the tokenizer. the code units of an ascii ArrayBuffer are its bytes
|
|
5349
5889
|
*/
|
|
@@ -6449,6 +6989,124 @@ export declare interface WalkerValueOptions {
|
|
|
6449
6989
|
type?: EnumToken | EnumToken[] | ((arena: AstArena, token: Token) => boolean) | null;
|
|
6450
6990
|
}
|
|
6451
6991
|
|
|
6992
|
+
/**
|
|
6993
|
+
* Render result.
|
|
6994
|
+
*
|
|
6995
|
+
* The generated css is stored as UTF-8 bytes in {@link RenderResult.write}: it can be written to a file or sent over
|
|
6996
|
+
* the network as is. {@link RenderResult.code} decodes the bytes the first time it is read, the string is kept.
|
|
6997
|
+
*
|
|
6998
|
+
* ```ts
|
|
6999
|
+
* import {render} from '@tbela99/css-parser';
|
|
7000
|
+
* import {writeFile} from 'node:fs/promises';
|
|
7001
|
+
*
|
|
7002
|
+
* const result = render(parseResult.arena, parseResult.ast);
|
|
7003
|
+
*
|
|
7004
|
+
* // bytes, no string conversion
|
|
7005
|
+
* await writeFile('out.css', result.write);
|
|
7006
|
+
*
|
|
7007
|
+
* // string, decoded once
|
|
7008
|
+
* console.log(result.code);
|
|
7009
|
+
* ```
|
|
7010
|
+
*/
|
|
7011
|
+
declare class RenderResult {
|
|
7012
|
+
#private;
|
|
7013
|
+
/**
|
|
7014
|
+
* An instance is kept alive: the hidden class of the instances would otherwise be collected by a full garbage
|
|
7015
|
+
* collection when no instance is alive, and the optimized code that depends on it discarded (deoptimized)
|
|
7016
|
+
*
|
|
7017
|
+
* @internal
|
|
7018
|
+
*/
|
|
7019
|
+
static readonly shape: RenderResult;
|
|
7020
|
+
/**
|
|
7021
|
+
* Rendered CSS, encoded as UTF-8
|
|
7022
|
+
*/
|
|
7023
|
+
write: Uint8Array;
|
|
7024
|
+
/**
|
|
7025
|
+
* Render errors
|
|
7026
|
+
*/
|
|
7027
|
+
errors: ErrorDescription[];
|
|
7028
|
+
/**
|
|
7029
|
+
* Render stats
|
|
7030
|
+
*/
|
|
7031
|
+
stats: RenderResultStats;
|
|
7032
|
+
/**
|
|
7033
|
+
* Source map
|
|
7034
|
+
*/
|
|
7035
|
+
map?: SourceMap;
|
|
7036
|
+
/**
|
|
7037
|
+
* @param write rendered css, encoded as UTF-8
|
|
7038
|
+
* @param errors
|
|
7039
|
+
* @param stats
|
|
7040
|
+
* @param map
|
|
7041
|
+
* @param codeLength length of the decoded css (`code.length`), computed when it is not provided
|
|
7042
|
+
*/
|
|
7043
|
+
constructor(write: Uint8Array, errors: ErrorDescription[], stats: RenderResultStats, map?: SourceMap, codeLength?: number);
|
|
7044
|
+
/**
|
|
7045
|
+
* length of the rendered css once decoded (`result.code.length`), without decoding it
|
|
7046
|
+
* @param result
|
|
7047
|
+
*
|
|
7048
|
+
* @internal
|
|
7049
|
+
*/
|
|
7050
|
+
static codeLength(result: RenderResult): number;
|
|
7051
|
+
/**
|
|
7052
|
+
* Rendered CSS. The bytes of {@link RenderResult.write} are decoded the first time the property is read
|
|
7053
|
+
*/
|
|
7054
|
+
get code(): string;
|
|
7055
|
+
/**
|
|
7056
|
+
* JSON representation: the css is serialized as a string, the bytes are not serialized
|
|
7057
|
+
*/
|
|
7058
|
+
toJSON(): Record<string, any>;
|
|
7059
|
+
}
|
|
7060
|
+
/**
|
|
7061
|
+
* Transform result: the parse result and the render result
|
|
7062
|
+
*/
|
|
7063
|
+
declare class TransformResult extends RenderResult {
|
|
7064
|
+
/**
|
|
7065
|
+
* An instance is kept alive: the hidden class of the instances would otherwise be collected by a full garbage
|
|
7066
|
+
* collection when no instance is alive, and the optimized code that depends on it discarded (deoptimized)
|
|
7067
|
+
*
|
|
7068
|
+
* @internal
|
|
7069
|
+
*/
|
|
7070
|
+
static readonly shape: TransformResult;
|
|
7071
|
+
/**
|
|
7072
|
+
* Parsed ast tree: the id of the stylesheet node in {@link TransformResult.arena}
|
|
7073
|
+
*/
|
|
7074
|
+
ast: AstStyleSheet;
|
|
7075
|
+
/**
|
|
7076
|
+
* arena the ast nodes are stored in
|
|
7077
|
+
*/
|
|
7078
|
+
arena: AstArena;
|
|
7079
|
+
/**
|
|
7080
|
+
* Transform stats
|
|
7081
|
+
*/
|
|
7082
|
+
stats: TransformResultStats;
|
|
7083
|
+
/**
|
|
7084
|
+
* CSS module mapping
|
|
7085
|
+
*/
|
|
7086
|
+
mapping?: Record<string, string>;
|
|
7087
|
+
/**
|
|
7088
|
+
* CSS module variables
|
|
7089
|
+
* @private
|
|
7090
|
+
*/
|
|
7091
|
+
cssModuleVariables?: Record<string, AstArenaNode>;
|
|
7092
|
+
/**
|
|
7093
|
+
* css module import mapping
|
|
7094
|
+
* @private
|
|
7095
|
+
*/
|
|
7096
|
+
importMapping?: Record<string, Record<string, string>>;
|
|
7097
|
+
/**
|
|
7098
|
+
* CSS module reverse mapping
|
|
7099
|
+
* @private
|
|
7100
|
+
*/
|
|
7101
|
+
revMapping?: Record<string, string>;
|
|
7102
|
+
/**
|
|
7103
|
+
* @param parseResult
|
|
7104
|
+
* @param renderResult
|
|
7105
|
+
* @param stats
|
|
7106
|
+
*/
|
|
7107
|
+
constructor(parseResult: ParseResult, renderResult: RenderResult, stats: TransformResultStats);
|
|
7108
|
+
}
|
|
7109
|
+
|
|
6452
7110
|
/**
|
|
6453
7111
|
* Error description
|
|
6454
7112
|
*/
|
|
@@ -6504,13 +7162,6 @@ interface ValidationOptions {
|
|
|
6504
7162
|
*/
|
|
6505
7163
|
lenient?: boolean;
|
|
6506
7164
|
|
|
6507
|
-
/**
|
|
6508
|
-
* Visited tokens
|
|
6509
|
-
*
|
|
6510
|
-
* @private
|
|
6511
|
-
*/
|
|
6512
|
-
visited?: Map<Token, Set<ValidationToken$1>>;
|
|
6513
|
-
|
|
6514
7165
|
/**
|
|
6515
7166
|
* Is optional
|
|
6516
7167
|
*
|
|
@@ -6617,6 +7268,39 @@ interface MinifyOptions {
|
|
|
6617
7268
|
* Inline css variables
|
|
6618
7269
|
*/
|
|
6619
7270
|
inlineCssVariables?: boolean;
|
|
7271
|
+
/**
|
|
7272
|
+
* Evaluate css mixins and custom functions: the `@apply` rules are replaced by the body of the mixin they reference,
|
|
7273
|
+
* the private variables (`@private`, mixin arguments and the custom properties of the rule) are substituted.
|
|
7274
|
+
* the custom function calls (`--fn(1px)`) are replaced by the result of the function.
|
|
7275
|
+
* see https://drafts.csswg.org/css-mixins-1/
|
|
7276
|
+
*
|
|
7277
|
+
* ```ts
|
|
7278
|
+
*
|
|
7279
|
+
* import {transform} from '@tbela99/css-parser';
|
|
7280
|
+
*
|
|
7281
|
+
* const css = `
|
|
7282
|
+
* @mixin --only-descs(--arg) {
|
|
7283
|
+
* color: var(--arg);
|
|
7284
|
+
* & * { color: var(--arg, red); }
|
|
7285
|
+
* }
|
|
7286
|
+
* .foo {
|
|
7287
|
+
* @apply --only-descs(green);
|
|
7288
|
+
* }
|
|
7289
|
+
* `;
|
|
7290
|
+
*
|
|
7291
|
+
* const result = await transform(css, {evaluateMixins: true, expandNestingRules: true});
|
|
7292
|
+
*
|
|
7293
|
+
* console.log(result.code);
|
|
7294
|
+
* // .foo,.foo *{color:green}
|
|
7295
|
+
* ```
|
|
7296
|
+
*/
|
|
7297
|
+
evaluateMixins?: boolean;
|
|
7298
|
+
/**
|
|
7299
|
+
* Keep the mixins and the custom functions once they are evaluated, see {@link evaluateMixins}.
|
|
7300
|
+
* By default, the evaluated mixins and custom functions, and the mixins that are not referenced, are dropped and
|
|
7301
|
+
* replaced with a comment
|
|
7302
|
+
*/
|
|
7303
|
+
keepMixins?: boolean;
|
|
6620
7304
|
/**
|
|
6621
7305
|
* Remove empty ast nodes
|
|
6622
7306
|
*/
|
|
@@ -7009,11 +7693,11 @@ export declare interface ParserSyncOptions
|
|
|
7009
7693
|
*/
|
|
7010
7694
|
setParent?: boolean;
|
|
7011
7695
|
/**
|
|
7012
|
-
*
|
|
7696
|
+
* Rendered size of the nodes, in bytes
|
|
7013
7697
|
*
|
|
7014
7698
|
* @private
|
|
7015
7699
|
*/
|
|
7016
|
-
cache?: Map<AstNode,
|
|
7700
|
+
cache?: Map<AstNode, number>;
|
|
7017
7701
|
|
|
7018
7702
|
/**
|
|
7019
7703
|
* CSS modules options
|
|
@@ -7341,79 +8025,30 @@ export declare interface ParseResult {
|
|
|
7341
8025
|
}
|
|
7342
8026
|
|
|
7343
8027
|
/**
|
|
7344
|
-
* Render
|
|
8028
|
+
* Render stats
|
|
7345
8029
|
*/
|
|
7346
|
-
export declare interface
|
|
7347
|
-
/**
|
|
7348
|
-
* Rendered CSS
|
|
7349
|
-
*/
|
|
7350
|
-
code: string;
|
|
8030
|
+
export declare interface RenderResultStats {
|
|
7351
8031
|
/**
|
|
7352
|
-
* Render
|
|
8032
|
+
* Render time
|
|
7353
8033
|
*/
|
|
7354
|
-
|
|
7355
|
-
/**
|
|
7356
|
-
* Render stats
|
|
7357
|
-
*/
|
|
7358
|
-
stats: {
|
|
7359
|
-
/**
|
|
7360
|
-
* Render time
|
|
7361
|
-
*/
|
|
7362
|
-
total: string;
|
|
7363
|
-
};
|
|
7364
|
-
/**
|
|
7365
|
-
* Source map
|
|
7366
|
-
*/
|
|
7367
|
-
map?: SourceMap;
|
|
8034
|
+
total: string;
|
|
7368
8035
|
}
|
|
7369
8036
|
|
|
7370
8037
|
/**
|
|
7371
|
-
* Transform
|
|
8038
|
+
* Transform stats
|
|
7372
8039
|
*/
|
|
7373
|
-
export declare interface
|
|
8040
|
+
export declare interface TransformResultStats extends ParseResultStats {
|
|
7374
8041
|
/**
|
|
7375
|
-
*
|
|
8042
|
+
* Generated CSS size: the length of {@link TransformResult.code}
|
|
7376
8043
|
*/
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
/**
|
|
7383
|
-
* Bytes read
|
|
7384
|
-
*/
|
|
7385
|
-
bytesIn: number;
|
|
7386
|
-
/**
|
|
7387
|
-
* Generated CSS size
|
|
7388
|
-
*/
|
|
7389
|
-
bytesOut: number;
|
|
7390
|
-
/**
|
|
7391
|
-
* Bytes read from imported files
|
|
7392
|
-
*/
|
|
7393
|
-
importedBytesIn: number;
|
|
7394
|
-
/**
|
|
7395
|
-
* Parse time
|
|
7396
|
-
*/
|
|
7397
|
-
parse: string;
|
|
7398
|
-
/**
|
|
7399
|
-
* Minify time
|
|
7400
|
-
*/
|
|
7401
|
-
minify: string;
|
|
7402
|
-
/**
|
|
7403
|
-
* Render time
|
|
7404
|
-
*/
|
|
7405
|
-
render: string;
|
|
7406
|
-
/**
|
|
7407
|
-
* Total time
|
|
7408
|
-
*/
|
|
7409
|
-
total: string;
|
|
7410
|
-
/**
|
|
7411
|
-
* Imported files stats
|
|
7412
|
-
*/
|
|
7413
|
-
imports: ParseResultStats[];
|
|
7414
|
-
};
|
|
8044
|
+
bytesOut: number;
|
|
8045
|
+
/**
|
|
8046
|
+
* Render time
|
|
8047
|
+
*/
|
|
8048
|
+
render: string;
|
|
7415
8049
|
}
|
|
7416
8050
|
|
|
8051
|
+
|
|
7417
8052
|
/**
|
|
7418
8053
|
* Parse token options
|
|
7419
8054
|
*/
|
|
@@ -7769,7 +8404,10 @@ declare function isOkLabClose(arena: AstArena, color1: Token, color2: Token, thr
|
|
|
7769
8404
|
*/
|
|
7770
8405
|
declare function parseSyntax(syntax: string): ValidationToken$1[];
|
|
7771
8406
|
|
|
7772
|
-
|
|
8407
|
+
/**
|
|
8408
|
+
* Version number
|
|
8409
|
+
*/
|
|
8410
|
+
declare const version = "2.3.0";
|
|
7773
8411
|
|
|
7774
8412
|
/**
|
|
7775
8413
|
* Load file or url
|
|
@@ -8108,5 +8746,5 @@ declare function transform(options: ParseInputStreamOptions & TransformOptions):
|
|
|
8108
8746
|
*/
|
|
8109
8747
|
declare function transform(options: ParseInputFileOptions & TransformOptions): Promise<TransformResult>;
|
|
8110
8748
|
|
|
8111
|
-
export { ARENA, ARENAID, Arena, AstArena, AstArenaNode, ColorType$1 as ColorType, EnumAstNodeStatus, EnumToken, FeatureWalkMode, ModuleCaseTransformEnum, ModuleScopeEnumOptions, ResponseType, SourceMap, TokenField, WalkerEvent, WalkerOptionEnum, arenaColumns, convertColor, dirname, isOkLabClose, load, minify, okLabDistance, parse, parseDeclarations, parseString, parseSync, parseSyntax, render, renderValue, resolve, transform, transformSync, version };
|
|
8112
|
-
export type { AddToken, AndToken, AngleToken, ArenaProperties, ArenaTransferables, AstArenaNodeInput, AstAtRule, AstComment, AstDeclaration, AstKeyframesAtRule, AstKeyframesRule, AstNode, AstNodeMatcher, AstRule, AstRuleList, AstStyleSheet, AstValueMatcher, AtRuleToken, AtRuleVisitorHandler, AttrEndToken, AttrStartToken, AttrToken, Background, BackgroundAttachmentMapping, BackgroundPosition, BackgroundPositionClass, BackgroundPositionConstraints, BackgroundPositionMapping, BackgroundProperties, BackgroundRepeat, BackgroundRepeatMapping, BackgroundSize, BackgroundSizeMapping, BadCDOCommentToken, BadCommentToken, BadStringToken, BadUrlToken, BaseToken, BinaryExpressionNode, BinaryExpressionToken, BlockEndToken, BlockStartToken, Border, BorderColor, BorderColorClass, BorderProperties, BorderRadius, CDOCommentToken, ChildCombinatorToken, ClassSelectorToken, ColonToken, ColorToken, ColumnCombinatorToken, CommaToken, CommentToken, ComposesSelectorToken, ConstraintsMapping, ContainMatchToken, ContainerStyleRangeToken, CssInput, CssTypeTokenType, CssVariableImportTokenType, CssVariableMapTokenType, CssVariableToken, DashMatchToken, DashedIdentToken, DeclarationToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, DoubleColonToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionDefToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorAstNodeSyncHandlerMap, GenericVisitorAsyncResult, GenericVisitorHandler, GenericVisitorResult, GenericVisitorSyncHandler, GenericVisitorSyncResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, IfConditionToken, IfElseConditionToken, ImportantToken, IncludeMatchToken, InfinityToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureOnlyToken, MediaFeatureToken, MediaQueryConditionToken, MediaQueryUnaryFeatureToken, MediaRangeQueryToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, ModuleAsyncOptions, ModuleSyncOptions, MulToken, NaNToken, NameSpaceAttributeToken, NegativeInfinityToken, NestingSelectorToken, NextSiblingCombinatorToken, NotToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, OrToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo$1 as ParseInfo, ParseInputFileOptions, ParseInputOptions, ParseInputStreamOptions, ParseResult, ParseResultStats, ParseSourceOptions, ParseTokenOptions, ParsedVisitorHandlers, ParserOptions, ParserSourceMapOptions, ParserSyncOptions, PercentageToken, PlainAstNode, PlainToken, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawNodeToken, RawSelectorTokens, RenderOptions,
|
|
8749
|
+
export { ARENA, ARENAID, Arena, AstArena, AstArenaNode, ColorType$1 as ColorType, EnumAstNodeStatus, EnumToken, FeatureWalkMode, ModuleCaseTransformEnum, ModuleScopeEnumOptions, RenderResult, ResponseType, SourceMap, TokenField, TransformResult, WalkerEvent, WalkerOptionEnum, arenaColumns, convertColor, dirname, isOkLabClose, load, minify, okLabDistance, parse, parseDeclarations, parseString, parseSync, parseSyntax, render, renderValue, resolve, transform, transformSync, version };
|
|
8750
|
+
export type { AddToken, AndToken, AngleToken, ArenaProperties, ArenaTransferables, AstArenaNodeInput, AstAtRule, AstComment, AstDeclaration, AstKeyframesAtRule, AstKeyframesRule, AstNode, AstNodeMatcher, AstRule, AstRuleList, AstStyleSheet, AstValueMatcher, AtRuleToken, AtRuleVisitorHandler, AttrEndToken, AttrStartToken, AttrToken, Background, BackgroundAttachmentMapping, BackgroundPosition, BackgroundPositionClass, BackgroundPositionConstraints, BackgroundPositionMapping, BackgroundProperties, BackgroundRepeat, BackgroundRepeatMapping, BackgroundSize, BackgroundSizeMapping, BadCDOCommentToken, BadCommentToken, BadStringToken, BadUrlToken, BaseToken, BinaryExpressionNode, BinaryExpressionToken, BlockEndToken, BlockStartToken, Border, BorderColor, BorderColorClass, BorderProperties, BorderRadius, CDOCommentToken, ChildCombinatorToken, ClassSelectorToken, ColonToken, ColorToken, ColumnCombinatorToken, CommaToken, CommentToken, ComposesSelectorToken, ConstraintsMapping, ContainMatchToken, ContainerStyleRangeToken, CssInput, CssTypeTokenType, CssVariableImportTokenType, CssVariableMapTokenType, CssVariableToken, DashMatchToken, DashedIdentToken, DeclarationToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, DoubleColonToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionDefToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorAstNodeSyncHandlerMap, GenericVisitorAsyncResult, GenericVisitorHandler, GenericVisitorResult, GenericVisitorSyncHandler, GenericVisitorSyncResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, IfConditionToken, IfElseConditionToken, ImportantToken, IncludeMatchToken, InfinityToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureOnlyToken, MediaFeatureToken, MediaQueryConditionToken, MediaQueryUnaryFeatureToken, MediaRangeQueryToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, ModuleAsyncOptions, ModuleSyncOptions, MulToken, NaNToken, NameSpaceAttributeToken, NegativeInfinityToken, NestingSelectorToken, NextSiblingCombinatorToken, NotToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, OrToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo$1 as ParseInfo, ParseInputFileOptions, ParseInputOptions, ParseInputStreamOptions, ParseResult, ParseResultStats, ParseSourceOptions, ParseTokenOptions, ParsedVisitorHandlers, ParserOptions, ParserSourceMapOptions, ParserSyncOptions, PercentageToken, PlainAstNode, PlainToken, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawNodeToken, RawSelectorTokens, RenderOptions, RenderResultStats, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SinglePropertyType, SinglePropertyTypeMapping, SourceLocation, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, SupportsQueryConditionToken, SupportsQueryUnaryConditionToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token, TokenizeResult, TransformOptions, TransformResultStats, TransformSyncOptions, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniCodeRangeToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationMediaFeature, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, ValidationToken$1 as ValidationToken, Value, ValueVisitorHandler, ValueVisitorSyncHandler, VariableScopeInfo, VisitorNodeMap, VisitorSyncNodeMap, WalkerFilter, WalkerOption, WalkerOptions, WalkerValueFilter, WalkerValueOptions, WhenElseQueryConditionToken, WhenElseUnaryConditionToken, WhitespaceToken, WrappedValuesToken };
|