@tbela99/css-parser 2.1.0 → 2.2.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 +42 -1
- package/README.md +14 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +5 -2
- package/dist/index-umd-web.js +10738 -4359
- package/dist/index.d.ts +734 -100
- package/dist/{src/lib → lib}/ast/arena-node.js +10 -10
- package/dist/{src/lib → lib}/ast/arena.js +304 -139
- package/dist/{src/lib → lib}/ast/cache.js +2 -2
- package/dist/{src/lib → lib}/ast/features/calc.js +11 -9
- package/dist/{src/lib → lib}/ast/features/if.js +6 -6
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +12 -10
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +39 -39
- package/dist/lib/ast/features/shorthand.js +129 -0
- package/dist/lib/ast/features/transform.js +188 -0
- package/dist/{src/lib → lib}/ast/features/type.js +2 -2
- package/dist/{src/lib → lib}/ast/math/expression.js +24 -24
- package/dist/{src/lib → lib}/ast/math/math.js +2 -2
- package/dist/{src/lib → lib}/ast/minify.js +745 -201
- package/dist/lib/ast/mixins/custom-function.js +393 -0
- package/dist/lib/ast/mixins/utils.js +53 -0
- package/dist/lib/ast/mixins/variables.js +678 -0
- package/dist/lib/ast/strings.js +906 -0
- package/dist/lib/ast/transform/compute.js +560 -0
- package/dist/lib/ast/transform/matrix.js +67 -0
- package/dist/lib/ast/transform/minify.js +325 -0
- package/dist/lib/ast/transform/perspective.js +24 -0
- package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
- package/dist/lib/ast/transform/scale.js +43 -0
- package/dist/lib/ast/transform/skew.js +38 -0
- package/dist/lib/ast/transform/translate.js +56 -0
- package/dist/lib/ast/transform/utils.js +390 -0
- package/dist/{src/lib → lib}/ast/types.js +2 -2
- package/dist/{src/lib → lib}/ast/walk.js +2 -2
- package/dist/{src/lib → lib}/fs/resolve.js +2 -2
- package/dist/{src/lib → lib}/parser/declaration/list.js +25 -8
- package/dist/{src/lib → lib}/parser/declaration/map.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/set.js +5 -5
- package/dist/{src/lib → lib}/parser/input.js +18 -3
- package/dist/{src/lib → lib}/parser/linesmap.js +2 -2
- package/dist/{src/lib → lib}/parser/parse.js +425 -258
- package/dist/{src/lib → lib}/parser/source.js +2 -2
- package/dist/{src/lib → lib}/parser/tokenize.js +480 -312
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +12 -12
- package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +7 -7
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +10 -10
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +9 -14
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +6 -6
- package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
- package/dist/lib/parser/utils/cache.js +53 -0
- package/dist/lib/parser/utils/canonical.js +78 -0
- package/dist/lib/parser/utils/codes.js +93 -0
- package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/declaration.js +31 -26
- package/dist/{src/lib → lib}/parser/utils/eq.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/hash.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/selector.js +305 -63
- package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/type.js +9 -7
- package/dist/{src/lib → lib}/printer/render.js +420 -152
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +2 -2
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +2 -2
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/alpha.js +10 -10
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +18 -18
- package/dist/{src/lib → lib}/syntax/color/color.js +18 -18
- package/dist/{src/lib → lib}/syntax/color/hex.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/hsl.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/hwb.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/lab.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/lch.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/oklab.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/oklch.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +14 -14
- package/dist/{src/lib → lib}/syntax/color/rgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/srgb.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +10 -10
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +2 -2
- package/dist/{src/lib → lib}/syntax/constants.js +26 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +37 -29
- package/dist/{src/lib → lib}/validation/config.js +23 -10
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +292 -150
- package/dist/{src/lib → lib}/validation/parser/parse.js +2 -2
- package/dist/{src/lib → lib}/validation/parser/typedef.js +2 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +52 -34
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +10 -5
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +47 -34
- package/package.json +12 -12
- 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/index.d.ts
CHANGED
|
@@ -1242,6 +1242,406 @@ 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
|
+
/**
|
|
1318
|
+
* structured-cloneable copy of a string table, see {@link StringTable.export}
|
|
1319
|
+
*/
|
|
1320
|
+
interface StringTableData {
|
|
1321
|
+
/**
|
|
1322
|
+
* number of strings
|
|
1323
|
+
*/
|
|
1324
|
+
count: number;
|
|
1325
|
+
/**
|
|
1326
|
+
* hash, source, start and end of each string
|
|
1327
|
+
*/
|
|
1328
|
+
hashes: Int32Array;
|
|
1329
|
+
sources: Int32Array;
|
|
1330
|
+
starts: Int32Array;
|
|
1331
|
+
ends: Int32Array;
|
|
1332
|
+
/**
|
|
1333
|
+
* text of each source, by source index
|
|
1334
|
+
*/
|
|
1335
|
+
texts: string[];
|
|
1336
|
+
/**
|
|
1337
|
+
* code units of the pool
|
|
1338
|
+
*/
|
|
1339
|
+
pool: Uint16Array;
|
|
1340
|
+
/**
|
|
1341
|
+
* the strings of the `StringSource.Value` entries, by id
|
|
1342
|
+
*/
|
|
1343
|
+
values: Array<string | undefined>;
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* builds a string from code units, strings and interned strings, then interns it: no string is created
|
|
1347
|
+
*
|
|
1348
|
+
* @internal
|
|
1349
|
+
*/
|
|
1350
|
+
declare class StringBuilder {
|
|
1351
|
+
/**
|
|
1352
|
+
* code units
|
|
1353
|
+
*/
|
|
1354
|
+
codes: Uint16Array;
|
|
1355
|
+
/**
|
|
1356
|
+
* number of code units
|
|
1357
|
+
*/
|
|
1358
|
+
length: number;
|
|
1359
|
+
/**
|
|
1360
|
+
* drop the code units
|
|
1361
|
+
*/
|
|
1362
|
+
reset(): this;
|
|
1363
|
+
/**
|
|
1364
|
+
* append the code units of an interned string
|
|
1365
|
+
* @param table
|
|
1366
|
+
* @param id
|
|
1367
|
+
*/
|
|
1368
|
+
appendId(table: StringTable, id: number): this;
|
|
1369
|
+
/**
|
|
1370
|
+
* append a string
|
|
1371
|
+
* @param str
|
|
1372
|
+
*/
|
|
1373
|
+
appendString(str: string): this;
|
|
1374
|
+
/**
|
|
1375
|
+
* append a code unit
|
|
1376
|
+
* @param code
|
|
1377
|
+
*/
|
|
1378
|
+
appendCode(code: number): this;
|
|
1379
|
+
/**
|
|
1380
|
+
* intern the string
|
|
1381
|
+
* @param table
|
|
1382
|
+
*/
|
|
1383
|
+
intern(table: StringTable): number;
|
|
1384
|
+
/**
|
|
1385
|
+
* make room for more code units
|
|
1386
|
+
* @param size
|
|
1387
|
+
*/
|
|
1388
|
+
private reserve;
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* interned strings of an arena
|
|
1392
|
+
*
|
|
1393
|
+
* @internal
|
|
1394
|
+
*/
|
|
1395
|
+
declare class StringTable {
|
|
1396
|
+
/**
|
|
1397
|
+
* An instance is kept alive: the hidden class of the instances would otherwise be collected by a full garbage
|
|
1398
|
+
* collection when no instance is alive, and the optimized code that depends on it discarded (deoptimized)
|
|
1399
|
+
*/
|
|
1400
|
+
static readonly shape: StringTable;
|
|
1401
|
+
/**
|
|
1402
|
+
* number of strings
|
|
1403
|
+
*/
|
|
1404
|
+
count: number;
|
|
1405
|
+
/**
|
|
1406
|
+
* strings by id: the strings that have been read (see {@link get}) and the `StringSource.Value` strings
|
|
1407
|
+
*/
|
|
1408
|
+
cache: Array<string | undefined>;
|
|
1409
|
+
/**
|
|
1410
|
+
* identity of the ids: replaced when the ids change (see {@link compact}). the caches keyed by string ids use it
|
|
1411
|
+
* as a key
|
|
1412
|
+
*/
|
|
1413
|
+
epoch: object;
|
|
1414
|
+
/**
|
|
1415
|
+
* hash of each string
|
|
1416
|
+
*/
|
|
1417
|
+
private hashes;
|
|
1418
|
+
/**
|
|
1419
|
+
* source of each string, see {@link StringSource}
|
|
1420
|
+
*/
|
|
1421
|
+
private sources;
|
|
1422
|
+
/**
|
|
1423
|
+
* start of each string in its source
|
|
1424
|
+
*/
|
|
1425
|
+
private starts;
|
|
1426
|
+
/**
|
|
1427
|
+
* end of each string in its source
|
|
1428
|
+
*/
|
|
1429
|
+
private ends;
|
|
1430
|
+
/**
|
|
1431
|
+
* hash table: string id + 1 by slot, 0 when the slot is empty (open addressing, linear probing). the load factor
|
|
1432
|
+
* is at most 0.5
|
|
1433
|
+
*/
|
|
1434
|
+
private slots;
|
|
1435
|
+
/**
|
|
1436
|
+
* text of the sources, by source index
|
|
1437
|
+
*/
|
|
1438
|
+
private texts;
|
|
1439
|
+
/**
|
|
1440
|
+
* code units of the sources being tokenized, by source index
|
|
1441
|
+
*/
|
|
1442
|
+
private codes;
|
|
1443
|
+
/**
|
|
1444
|
+
* values derived from the strings, by slot and by id (see {@link derived})
|
|
1445
|
+
*/
|
|
1446
|
+
private derivedValues;
|
|
1447
|
+
/**
|
|
1448
|
+
* properties of the strings, by id (see {@link flag})
|
|
1449
|
+
*/
|
|
1450
|
+
private flags;
|
|
1451
|
+
/**
|
|
1452
|
+
* id of the lowercase string + 1, by id. 0 when it is not computed (see {@link lower})
|
|
1453
|
+
*/
|
|
1454
|
+
private lowers;
|
|
1455
|
+
/**
|
|
1456
|
+
* builder of the lowercase strings
|
|
1457
|
+
*/
|
|
1458
|
+
private readonly builder;
|
|
1459
|
+
/**
|
|
1460
|
+
* code units of the strings that are not a range of a source
|
|
1461
|
+
*/
|
|
1462
|
+
private pool;
|
|
1463
|
+
/**
|
|
1464
|
+
* used length of the pool
|
|
1465
|
+
*/
|
|
1466
|
+
private poolLength;
|
|
1467
|
+
/**
|
|
1468
|
+
* set the text of a source: the strings of the source are ranges of the text
|
|
1469
|
+
* @param source source index
|
|
1470
|
+
* @param text content of the source
|
|
1471
|
+
* @param codes code units of the text, while the source is tokenized: the ranges are compared with the code units
|
|
1472
|
+
* (faster than the text). see {@link releaseCodes}
|
|
1473
|
+
*/
|
|
1474
|
+
setText(source: number, text: string, codes?: CodeUnits | null): void;
|
|
1475
|
+
/**
|
|
1476
|
+
* drop the code units of a source: the source is no longer tokenized, see {@link setText}
|
|
1477
|
+
* @param source
|
|
1478
|
+
*/
|
|
1479
|
+
releaseCodes(source: number): void;
|
|
1480
|
+
/**
|
|
1481
|
+
* intern a string
|
|
1482
|
+
* @param str
|
|
1483
|
+
* @returns the string id
|
|
1484
|
+
*/
|
|
1485
|
+
intern(str: string): number;
|
|
1486
|
+
/**
|
|
1487
|
+
* intern a range of code units
|
|
1488
|
+
* @param codes code units
|
|
1489
|
+
* @param start
|
|
1490
|
+
* @param end
|
|
1491
|
+
* @param source where the range is stored when it is interned: the index of the source the code units are read
|
|
1492
|
+
* from (the range is kept), `StringSource.Canonical` (the code units are the canonical text) or `StringSource.Pool`
|
|
1493
|
+
* (the code units are copied)
|
|
1494
|
+
* @returns the string id
|
|
1495
|
+
*/
|
|
1496
|
+
internRange(codes: CodeUnits, start: number, end: number, source: number): number;
|
|
1497
|
+
/**
|
|
1498
|
+
* id of a string, -1 when the string is not interned
|
|
1499
|
+
* @param str
|
|
1500
|
+
*/
|
|
1501
|
+
lookup(str: string): number;
|
|
1502
|
+
/**
|
|
1503
|
+
* the string of an id. the string is created the first time it is read
|
|
1504
|
+
* @param id
|
|
1505
|
+
*/
|
|
1506
|
+
get(id: number): string;
|
|
1507
|
+
/**
|
|
1508
|
+
* length of a string
|
|
1509
|
+
* @param id
|
|
1510
|
+
*/
|
|
1511
|
+
length(id: number): number;
|
|
1512
|
+
/**
|
|
1513
|
+
* code unit of a string
|
|
1514
|
+
* @param id
|
|
1515
|
+
* @param index
|
|
1516
|
+
*/
|
|
1517
|
+
codeAt(id: number, index: number): number;
|
|
1518
|
+
/**
|
|
1519
|
+
* copy the code units of a string to a buffer. the string is not created
|
|
1520
|
+
* @param id
|
|
1521
|
+
* @param target
|
|
1522
|
+
* @param offset offset in the target
|
|
1523
|
+
* @returns the number of code units
|
|
1524
|
+
*/
|
|
1525
|
+
copy(id: number, target: Uint16Array, offset: number): number;
|
|
1526
|
+
/**
|
|
1527
|
+
* a boolean property of a string, computed once per id: the string is read once (see {@link StringFlag})
|
|
1528
|
+
* @param id
|
|
1529
|
+
* @param flag
|
|
1530
|
+
* @param compute computes the property from the string
|
|
1531
|
+
*/
|
|
1532
|
+
flag(id: number, flag: StringFlag, compute: (str: string) => boolean): boolean;
|
|
1533
|
+
/**
|
|
1534
|
+
* a boolean property of a string, computed once per id from the string id (the string is not necessarily read),
|
|
1535
|
+
* see {@link flag}
|
|
1536
|
+
* @param id
|
|
1537
|
+
* @param flag
|
|
1538
|
+
* @param compute computes the property from the string id
|
|
1539
|
+
*/
|
|
1540
|
+
flagId(id: number, flag: StringFlag, compute: (id: number) => boolean): boolean;
|
|
1541
|
+
/**
|
|
1542
|
+
* a value derived from a string, computed once per id (see {@link StringDerived})
|
|
1543
|
+
* @param id
|
|
1544
|
+
* @param slot
|
|
1545
|
+
* @param compute computes the value from the string id
|
|
1546
|
+
*/
|
|
1547
|
+
derived<T>(id: number, slot: StringDerived, compute: (id: number) => T): T;
|
|
1548
|
+
/**
|
|
1549
|
+
* copy the code units of a string to a byte buffer when they are all ascii (UTF-8 encoding). the string is not
|
|
1550
|
+
* created
|
|
1551
|
+
* @param id
|
|
1552
|
+
* @param target
|
|
1553
|
+
* @param offset offset in the target. the target has room for the string
|
|
1554
|
+
* @returns the number of bytes, -1 when the string is not ascii
|
|
1555
|
+
*/
|
|
1556
|
+
copyAscii(id: number, target: Uint8Array, offset: number): number;
|
|
1557
|
+
/**
|
|
1558
|
+
* index of the first occurrence of a code unit in a string, -1 when it is not found. the string is not created
|
|
1559
|
+
* @param id
|
|
1560
|
+
* @param code
|
|
1561
|
+
*/
|
|
1562
|
+
indexOfCode(id: number, code: number): number;
|
|
1563
|
+
/**
|
|
1564
|
+
* true if the string of an id equals a string. the string is not created
|
|
1565
|
+
* @param id
|
|
1566
|
+
* @param str
|
|
1567
|
+
*/
|
|
1568
|
+
equals(id: number, str: string): boolean;
|
|
1569
|
+
/**
|
|
1570
|
+
* id of the lowercase string (like `toLowerCase()`): the id itself when the string has no uppercase letter. the
|
|
1571
|
+
* string is not created when it is ascii
|
|
1572
|
+
* @param id
|
|
1573
|
+
*/
|
|
1574
|
+
lower(id: number): number;
|
|
1575
|
+
/**
|
|
1576
|
+
* true if the string of an id starts with a string. the string is not created
|
|
1577
|
+
* @param id
|
|
1578
|
+
* @param str
|
|
1579
|
+
*/
|
|
1580
|
+
startsWith(id: number, str: string): boolean;
|
|
1581
|
+
/**
|
|
1582
|
+
* true if the string of an id equals a string, ignoring the case of the ascii letters. the string is not created
|
|
1583
|
+
* @param id
|
|
1584
|
+
* @param str
|
|
1585
|
+
*/
|
|
1586
|
+
equalsIgnoreCase(id: number, str: string): boolean;
|
|
1587
|
+
/**
|
|
1588
|
+
* drop the strings that are not used and renumber the others
|
|
1589
|
+
* @param used used strings, by id
|
|
1590
|
+
* @returns the new id of each string
|
|
1591
|
+
*/
|
|
1592
|
+
compact(used: Uint8Array): Uint32Array;
|
|
1593
|
+
/**
|
|
1594
|
+
* structured-cloneable copy of the table
|
|
1595
|
+
*/
|
|
1596
|
+
export(): StringTableData;
|
|
1597
|
+
/**
|
|
1598
|
+
* initialize the table from an exported copy
|
|
1599
|
+
* @param data
|
|
1600
|
+
*/
|
|
1601
|
+
import(data: StringTableData): void;
|
|
1602
|
+
/**
|
|
1603
|
+
* add a string
|
|
1604
|
+
* @param hash
|
|
1605
|
+
* @param slot empty slot of the hash table
|
|
1606
|
+
* @param source
|
|
1607
|
+
* @param start
|
|
1608
|
+
* @param end
|
|
1609
|
+
*/
|
|
1610
|
+
private add;
|
|
1611
|
+
/**
|
|
1612
|
+
* true if a string has the code units of a range
|
|
1613
|
+
* @param id
|
|
1614
|
+
* @param codes
|
|
1615
|
+
* @param start
|
|
1616
|
+
* @param end
|
|
1617
|
+
*/
|
|
1618
|
+
private equalsRange;
|
|
1619
|
+
/**
|
|
1620
|
+
* true if a string equals a string
|
|
1621
|
+
* @param id
|
|
1622
|
+
* @param str
|
|
1623
|
+
*/
|
|
1624
|
+
private equalsString;
|
|
1625
|
+
/**
|
|
1626
|
+
* grow the columns of the strings
|
|
1627
|
+
* @param size
|
|
1628
|
+
*/
|
|
1629
|
+
private grow;
|
|
1630
|
+
/**
|
|
1631
|
+
* drop the strings, allocate the columns for `count` strings. the ids change
|
|
1632
|
+
* @param count
|
|
1633
|
+
*/
|
|
1634
|
+
private reset;
|
|
1635
|
+
/**
|
|
1636
|
+
* rebuild the hash table
|
|
1637
|
+
*/
|
|
1638
|
+
private rehash;
|
|
1639
|
+
/**
|
|
1640
|
+
* shallow copy of the table
|
|
1641
|
+
*/
|
|
1642
|
+
private clone;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1245
1645
|
/**
|
|
1246
1646
|
* Arena memory manager: ast nodes and value tokens are integer ids, their data is stored column-wise
|
|
1247
1647
|
* in typed arrays (structure of arrays), lists are doubly linked lists stored in the `firstChild` /
|
|
@@ -1311,7 +1711,7 @@ interface ArenaProperties {
|
|
|
1311
1711
|
/**
|
|
1312
1712
|
* interned strings
|
|
1313
1713
|
*/
|
|
1314
|
-
strings:
|
|
1714
|
+
strings: StringTableData;
|
|
1315
1715
|
/**
|
|
1316
1716
|
* validation errors by node id
|
|
1317
1717
|
*/
|
|
@@ -1323,11 +1723,15 @@ interface ArenaProperties {
|
|
|
1323
1723
|
/**
|
|
1324
1724
|
* raw selectors cache ({@link AstArena})
|
|
1325
1725
|
*/
|
|
1326
|
-
raw?: Array<RawSelectorTokens | null | undefined>;
|
|
1726
|
+
raw?: Array<[number, RawSelectorTokens | null | undefined]>;
|
|
1327
1727
|
/**
|
|
1328
1728
|
* optimized selectors cache ({@link AstArena})
|
|
1329
1729
|
*/
|
|
1330
|
-
optimized?: Array<OptimizedSelector | null | undefined>;
|
|
1730
|
+
optimized?: Array<[number, OptimizedSelector | null | undefined]>;
|
|
1731
|
+
/**
|
|
1732
|
+
* input length of the parsed stylesheets ({@link AstArena})
|
|
1733
|
+
*/
|
|
1734
|
+
inputLengths?: Array<number | undefined>;
|
|
1331
1735
|
}
|
|
1332
1736
|
/**
|
|
1333
1737
|
* Column buffers of an arena, in the order of {@link arenaColumns}. See {@link Arena.toTransferableArenaObject}
|
|
@@ -1348,13 +1752,9 @@ declare const arenaColumns: readonly ["dataTypes", "parents", "nextSibling", "pr
|
|
|
1348
1752
|
declare class Arena {
|
|
1349
1753
|
#private;
|
|
1350
1754
|
/**
|
|
1351
|
-
*
|
|
1352
|
-
*/
|
|
1353
|
-
stringIds: Map<string, number>;
|
|
1354
|
-
/**
|
|
1355
|
-
* string interner values
|
|
1755
|
+
* interned strings: ranges of the sources, of the canonical text, of the pool, or strings. see {@link StringTable}
|
|
1356
1756
|
*/
|
|
1357
|
-
|
|
1757
|
+
protected stringTable: StringTable;
|
|
1358
1758
|
/**
|
|
1359
1759
|
* root node
|
|
1360
1760
|
*/
|
|
@@ -1488,10 +1888,140 @@ declare class Arena {
|
|
|
1488
1888
|
recycle(id: number): void;
|
|
1489
1889
|
/**
|
|
1490
1890
|
* Interns a string and returns its unique ID. If the string has already been interned, it returns the existing ID.
|
|
1891
|
+
* The strings are looked up by the hash of their code units, see {@link internRange}
|
|
1491
1892
|
* @param str
|
|
1492
1893
|
* @returns
|
|
1493
1894
|
*/
|
|
1494
1895
|
internString(str: string): number;
|
|
1896
|
+
/**
|
|
1897
|
+
* Interns the string made of a range of code units and returns its unique ID. Same ID as {@link internString} for
|
|
1898
|
+
* the same content. The range is looked up by its hash and compared with the code units of the interned strings:
|
|
1899
|
+
* no string is created.
|
|
1900
|
+
*
|
|
1901
|
+
* - a range of a source (the code units read by the tokenizer): the source index and the offsets are stored, the
|
|
1902
|
+
* text of the source is set with {@link setSourceText}
|
|
1903
|
+
* - `StringSource.Canonical`: a range of the canonical text (the spelling of the known units and function names)
|
|
1904
|
+
* - `StringSource.Pool`: the code units are copied (decoded escape sequences, ...)
|
|
1905
|
+
*
|
|
1906
|
+
* @param codes code units
|
|
1907
|
+
* @param start start offset of the range
|
|
1908
|
+
* @param end end offset of the range
|
|
1909
|
+
* @param source source index, `StringSource.Canonical` or `StringSource.Pool`
|
|
1910
|
+
*/
|
|
1911
|
+
internRange(codes: CodeUnits, start: number, end: number, source: number): number;
|
|
1912
|
+
/**
|
|
1913
|
+
* set the text of a source: the strings interned from the source are ranges of the text, see {@link internRange}
|
|
1914
|
+
* @param source source index
|
|
1915
|
+
* @param text content of the source
|
|
1916
|
+
* @param codes code units of the text while the source is tokenized (faster comparisons)
|
|
1917
|
+
*/
|
|
1918
|
+
setSourceText(source: number, text: string, codes?: CodeUnits | null): void;
|
|
1919
|
+
/**
|
|
1920
|
+
* drop the code units of a source set by {@link setSourceText}: the source is no longer tokenized
|
|
1921
|
+
* @param source source index
|
|
1922
|
+
*/
|
|
1923
|
+
releaseSourceCodes(source: number): void;
|
|
1924
|
+
/**
|
|
1925
|
+
* id of an interned string, -1 when the string is not interned
|
|
1926
|
+
* @param str
|
|
1927
|
+
*/
|
|
1928
|
+
stringId(str: string): number;
|
|
1929
|
+
/**
|
|
1930
|
+
* length of an interned string. the string is not created
|
|
1931
|
+
* @param id
|
|
1932
|
+
*/
|
|
1933
|
+
stringLength(id: number): number;
|
|
1934
|
+
/**
|
|
1935
|
+
* code unit of an interned string. the string is not created
|
|
1936
|
+
* @param id
|
|
1937
|
+
* @param index
|
|
1938
|
+
*/
|
|
1939
|
+
stringCodeAt(id: number, index: number): number;
|
|
1940
|
+
/**
|
|
1941
|
+
* index of the first occurrence of a code unit in an interned string, -1 when it is not found. the string is not
|
|
1942
|
+
* created
|
|
1943
|
+
* @param id
|
|
1944
|
+
* @param code
|
|
1945
|
+
*/
|
|
1946
|
+
stringIndexOf(id: number, code: number): number;
|
|
1947
|
+
/**
|
|
1948
|
+
* true if an interned string equals a string. the interned string is not created
|
|
1949
|
+
* @param id
|
|
1950
|
+
* @param str
|
|
1951
|
+
*/
|
|
1952
|
+
stringEquals(id: number, str: string): boolean;
|
|
1953
|
+
/**
|
|
1954
|
+
* true if an interned string equals a string, ignoring the case of the ascii letters. the interned string is not
|
|
1955
|
+
* created
|
|
1956
|
+
* @param id
|
|
1957
|
+
* @param str
|
|
1958
|
+
*/
|
|
1959
|
+
stringEqualsIgnoreCase(id: number, str: string): boolean;
|
|
1960
|
+
/**
|
|
1961
|
+
* true if an interned string starts with a string. the interned string is not created
|
|
1962
|
+
* @param id
|
|
1963
|
+
* @param str
|
|
1964
|
+
*/
|
|
1965
|
+
stringStartsWith(id: number, str: string): boolean;
|
|
1966
|
+
/**
|
|
1967
|
+
* id of the lowercase version of an interned string (like `toLowerCase()`). no string is created when the string
|
|
1968
|
+
* is ascii. the result is cached
|
|
1969
|
+
* @param id
|
|
1970
|
+
*/
|
|
1971
|
+
lowerStringId(id: number): number;
|
|
1972
|
+
/**
|
|
1973
|
+
* copy an interned string to a byte buffer when it is ascii (UTF-8 encoding). the string is not created
|
|
1974
|
+
* @param id
|
|
1975
|
+
* @param target
|
|
1976
|
+
* @param offset offset in the target. the target has room for the string ({@link stringLength})
|
|
1977
|
+
* @returns the number of bytes, -1 when the string is not ascii
|
|
1978
|
+
*/
|
|
1979
|
+
copyStringAscii(id: number, target: Uint8Array, offset: number): number;
|
|
1980
|
+
/**
|
|
1981
|
+
* a boolean property of an interned string, computed once per string id: the string is read once
|
|
1982
|
+
* @param id
|
|
1983
|
+
* @param flag
|
|
1984
|
+
* @param compute computes the property from the string
|
|
1985
|
+
*/
|
|
1986
|
+
stringFlag(id: number, flag: StringFlag, compute: (str: string) => boolean): boolean;
|
|
1987
|
+
/**
|
|
1988
|
+
* a boolean property of an interned string, computed once per string id from the id (see {@link stringCodeAt})
|
|
1989
|
+
* @param id
|
|
1990
|
+
* @param flag
|
|
1991
|
+
* @param compute computes the property from the string id
|
|
1992
|
+
*/
|
|
1993
|
+
stringFlagId(id: number, flag: StringFlag, compute: (id: number) => boolean): boolean;
|
|
1994
|
+
/**
|
|
1995
|
+
* a value derived from an interned string, computed once per string id
|
|
1996
|
+
* @param id
|
|
1997
|
+
* @param slot
|
|
1998
|
+
* @param compute computes the value from the string id
|
|
1999
|
+
*/
|
|
2000
|
+
stringDerived<T>(id: number, slot: StringDerived, compute: (id: number) => T): T;
|
|
2001
|
+
/**
|
|
2002
|
+
* copy the code units of an interned string to a buffer. the string is not created
|
|
2003
|
+
* @param id
|
|
2004
|
+
* @param target the target has room for the string ({@link stringLength})
|
|
2005
|
+
* @param offset
|
|
2006
|
+
* @returns the number of code units
|
|
2007
|
+
*/
|
|
2008
|
+
copyString(id: number, target: Uint16Array, offset: number): number;
|
|
2009
|
+
/**
|
|
2010
|
+
* append an interned string to a builder. the string is not created
|
|
2011
|
+
* @param builder
|
|
2012
|
+
* @param id
|
|
2013
|
+
*/
|
|
2014
|
+
appendString(builder: StringBuilder, id: number): StringBuilder;
|
|
2015
|
+
/**
|
|
2016
|
+
* intern the string built by a builder: no string is created
|
|
2017
|
+
* @param builder
|
|
2018
|
+
*/
|
|
2019
|
+
internBuilder(builder: StringBuilder): number;
|
|
2020
|
+
/**
|
|
2021
|
+
* identity of the string ids: a new object when the strings are renumbered ({@link compact},
|
|
2022
|
+
* {@link compactStrings}). the caches keyed by string ids use it as a key
|
|
2023
|
+
*/
|
|
2024
|
+
get stringEpoch(): object;
|
|
1495
2025
|
/**
|
|
1496
2026
|
*
|
|
1497
2027
|
* @param id
|
|
@@ -2180,17 +2710,22 @@ declare class Arena {
|
|
|
2180
2710
|
*/
|
|
2181
2711
|
declare class AstArena extends Arena {
|
|
2182
2712
|
/**
|
|
2183
|
-
* raw selector (minification cache)
|
|
2713
|
+
* raw selector (minification cache), by rule id
|
|
2184
2714
|
*/
|
|
2185
|
-
raw:
|
|
2715
|
+
raw: Map<number, RawSelectorTokens | null | undefined>;
|
|
2186
2716
|
/**
|
|
2187
|
-
* optimized selector (minification cache)
|
|
2717
|
+
* optimized selector (minification cache), by rule id
|
|
2188
2718
|
*/
|
|
2189
|
-
optimized:
|
|
2719
|
+
optimized: Map<number, OptimizedSelector | null | undefined>;
|
|
2190
2720
|
/**
|
|
2191
2721
|
* source ids. `spans` store the index in this table (8 bits)
|
|
2192
2722
|
*/
|
|
2193
2723
|
sources: number[];
|
|
2724
|
+
/**
|
|
2725
|
+
* length of the css parsed into a stylesheet, imported files included. sparse: only the stylesheets created by
|
|
2726
|
+
* the parser have an entry. the render buffer is allocated from this length
|
|
2727
|
+
*/
|
|
2728
|
+
inputLengths: Array<number | undefined>;
|
|
2194
2729
|
/**
|
|
2195
2730
|
*
|
|
2196
2731
|
* @param size
|
|
@@ -2281,7 +2816,7 @@ declare class AstArena extends Arena {
|
|
|
2281
2816
|
* @param state
|
|
2282
2817
|
* @param errors
|
|
2283
2818
|
*/
|
|
2284
|
-
createRule(typ: EnumToken, sel: string, tokens: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2819
|
+
createRule(typ: EnumToken, sel: string | number, tokens: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2285
2820
|
/**
|
|
2286
2821
|
* allocate an at-rule node
|
|
2287
2822
|
* @param typ
|
|
@@ -2292,7 +2827,7 @@ declare class AstArena extends Arena {
|
|
|
2292
2827
|
* @param state
|
|
2293
2828
|
* @param errors
|
|
2294
2829
|
*/
|
|
2295
|
-
createAtRule(typ: EnumToken, nam: string, val: string, block: boolean, tokens: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2830
|
+
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
2831
|
/**
|
|
2297
2832
|
* allocate a declaration node
|
|
2298
2833
|
* @param typ
|
|
@@ -2301,13 +2836,13 @@ declare class AstArena extends Arena {
|
|
|
2301
2836
|
* @param state
|
|
2302
2837
|
* @param errors
|
|
2303
2838
|
*/
|
|
2304
|
-
createDeclaration(typ: EnumToken, nam: string, val: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2839
|
+
createDeclaration(typ: EnumToken, nam: string | number, val: number[] | null | undefined, state: EnumAstNodeStatus | null | undefined, errors: ErrorDescription[] | null | undefined): number;
|
|
2305
2840
|
/**
|
|
2306
2841
|
* allocate a comment node
|
|
2307
2842
|
* @param typ
|
|
2308
2843
|
* @param val
|
|
2309
2844
|
*/
|
|
2310
|
-
createComment(typ: EnumToken, val: string): number;
|
|
2845
|
+
createComment(typ: EnumToken, val: string | number): number;
|
|
2311
2846
|
/**
|
|
2312
2847
|
* allocate a token. string values are interned, numeric values are stored in the `numericValue` column
|
|
2313
2848
|
* @param typ
|
|
@@ -2463,10 +2998,17 @@ declare class AstArena extends Arena {
|
|
|
2463
2998
|
*/
|
|
2464
2999
|
tokenToObject(id: number): PlainToken;
|
|
2465
3000
|
/**
|
|
2466
|
-
*
|
|
3001
|
+
* copy the data of a node (type, strings, values, flags, location, errors): its tokens, its children and the
|
|
3002
|
+
* minifier caches (`raw`, `optimized`) are not copied
|
|
3003
|
+
* @param id
|
|
3004
|
+
*/
|
|
3005
|
+
cloneNode(id: number): number;
|
|
3006
|
+
/**
|
|
3007
|
+
* copy a node or a token. the tokens of a node are copied, its children are copied with `deep`. the values of a
|
|
3008
|
+
* declaration are copied with `deep`
|
|
2467
3009
|
* @param id
|
|
2468
|
-
* @param deep
|
|
2469
|
-
* @param cloneMap
|
|
3010
|
+
* @param deep copy the children and the values of the declarations
|
|
3011
|
+
* @param cloneMap records the copies: id of the copy by original id
|
|
2470
3012
|
*/
|
|
2471
3013
|
clone(id: number, deep?: boolean, cloneMap?: Map<number, number> | null): number;
|
|
2472
3014
|
/**
|
|
@@ -5338,12 +5880,6 @@ export declare interface PropertyListOptions {
|
|
|
5338
5880
|
* parse info
|
|
5339
5881
|
*/
|
|
5340
5882
|
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
5883
|
/**
|
|
5348
5884
|
* the utf-16 code units of the css, read by the tokenizer. the code units of an ascii ArrayBuffer are its bytes
|
|
5349
5885
|
*/
|
|
@@ -6449,6 +6985,124 @@ export declare interface WalkerValueOptions {
|
|
|
6449
6985
|
type?: EnumToken | EnumToken[] | ((arena: AstArena, token: Token) => boolean) | null;
|
|
6450
6986
|
}
|
|
6451
6987
|
|
|
6988
|
+
/**
|
|
6989
|
+
* Render result.
|
|
6990
|
+
*
|
|
6991
|
+
* The generated css is stored as UTF-8 bytes in {@link RenderResult.write}: it can be written to a file or sent over
|
|
6992
|
+
* the network as is. {@link RenderResult.code} decodes the bytes the first time it is read, the string is kept.
|
|
6993
|
+
*
|
|
6994
|
+
* ```ts
|
|
6995
|
+
* import {render} from '@tbela99/css-parser';
|
|
6996
|
+
* import {writeFile} from 'node:fs/promises';
|
|
6997
|
+
*
|
|
6998
|
+
* const result = render(parseResult.arena, parseResult.ast);
|
|
6999
|
+
*
|
|
7000
|
+
* // bytes, no string conversion
|
|
7001
|
+
* await writeFile('out.css', result.write);
|
|
7002
|
+
*
|
|
7003
|
+
* // string, decoded once
|
|
7004
|
+
* console.log(result.code);
|
|
7005
|
+
* ```
|
|
7006
|
+
*/
|
|
7007
|
+
declare class RenderResult {
|
|
7008
|
+
#private;
|
|
7009
|
+
/**
|
|
7010
|
+
* An instance is kept alive: the hidden class of the instances would otherwise be collected by a full garbage
|
|
7011
|
+
* collection when no instance is alive, and the optimized code that depends on it discarded (deoptimized)
|
|
7012
|
+
*
|
|
7013
|
+
* @internal
|
|
7014
|
+
*/
|
|
7015
|
+
static readonly shape: RenderResult;
|
|
7016
|
+
/**
|
|
7017
|
+
* Rendered CSS, encoded as UTF-8
|
|
7018
|
+
*/
|
|
7019
|
+
write: Uint8Array;
|
|
7020
|
+
/**
|
|
7021
|
+
* Render errors
|
|
7022
|
+
*/
|
|
7023
|
+
errors: ErrorDescription[];
|
|
7024
|
+
/**
|
|
7025
|
+
* Render stats
|
|
7026
|
+
*/
|
|
7027
|
+
stats: RenderResultStats;
|
|
7028
|
+
/**
|
|
7029
|
+
* Source map
|
|
7030
|
+
*/
|
|
7031
|
+
map?: SourceMap;
|
|
7032
|
+
/**
|
|
7033
|
+
* @param write rendered css, encoded as UTF-8
|
|
7034
|
+
* @param errors
|
|
7035
|
+
* @param stats
|
|
7036
|
+
* @param map
|
|
7037
|
+
* @param codeLength length of the decoded css (`code.length`), computed when it is not provided
|
|
7038
|
+
*/
|
|
7039
|
+
constructor(write: Uint8Array, errors: ErrorDescription[], stats: RenderResultStats, map?: SourceMap, codeLength?: number);
|
|
7040
|
+
/**
|
|
7041
|
+
* length of the rendered css once decoded (`result.code.length`), without decoding it
|
|
7042
|
+
* @param result
|
|
7043
|
+
*
|
|
7044
|
+
* @internal
|
|
7045
|
+
*/
|
|
7046
|
+
static codeLength(result: RenderResult): number;
|
|
7047
|
+
/**
|
|
7048
|
+
* Rendered CSS. The bytes of {@link RenderResult.write} are decoded the first time the property is read
|
|
7049
|
+
*/
|
|
7050
|
+
get code(): string;
|
|
7051
|
+
/**
|
|
7052
|
+
* JSON representation: the css is serialized as a string, the bytes are not serialized
|
|
7053
|
+
*/
|
|
7054
|
+
toJSON(): Record<string, any>;
|
|
7055
|
+
}
|
|
7056
|
+
/**
|
|
7057
|
+
* Transform result: the parse result and the render result
|
|
7058
|
+
*/
|
|
7059
|
+
declare class TransformResult extends RenderResult {
|
|
7060
|
+
/**
|
|
7061
|
+
* An instance is kept alive: the hidden class of the instances would otherwise be collected by a full garbage
|
|
7062
|
+
* collection when no instance is alive, and the optimized code that depends on it discarded (deoptimized)
|
|
7063
|
+
*
|
|
7064
|
+
* @internal
|
|
7065
|
+
*/
|
|
7066
|
+
static readonly shape: TransformResult;
|
|
7067
|
+
/**
|
|
7068
|
+
* Parsed ast tree: the id of the stylesheet node in {@link TransformResult.arena}
|
|
7069
|
+
*/
|
|
7070
|
+
ast: AstStyleSheet;
|
|
7071
|
+
/**
|
|
7072
|
+
* arena the ast nodes are stored in
|
|
7073
|
+
*/
|
|
7074
|
+
arena: AstArena;
|
|
7075
|
+
/**
|
|
7076
|
+
* Transform stats
|
|
7077
|
+
*/
|
|
7078
|
+
stats: TransformResultStats;
|
|
7079
|
+
/**
|
|
7080
|
+
* CSS module mapping
|
|
7081
|
+
*/
|
|
7082
|
+
mapping?: Record<string, string>;
|
|
7083
|
+
/**
|
|
7084
|
+
* CSS module variables
|
|
7085
|
+
* @private
|
|
7086
|
+
*/
|
|
7087
|
+
cssModuleVariables?: Record<string, AstArenaNode>;
|
|
7088
|
+
/**
|
|
7089
|
+
* css module import mapping
|
|
7090
|
+
* @private
|
|
7091
|
+
*/
|
|
7092
|
+
importMapping?: Record<string, Record<string, string>>;
|
|
7093
|
+
/**
|
|
7094
|
+
* CSS module reverse mapping
|
|
7095
|
+
* @private
|
|
7096
|
+
*/
|
|
7097
|
+
revMapping?: Record<string, string>;
|
|
7098
|
+
/**
|
|
7099
|
+
* @param parseResult
|
|
7100
|
+
* @param renderResult
|
|
7101
|
+
* @param stats
|
|
7102
|
+
*/
|
|
7103
|
+
constructor(parseResult: ParseResult, renderResult: RenderResult, stats: TransformResultStats);
|
|
7104
|
+
}
|
|
7105
|
+
|
|
6452
7106
|
/**
|
|
6453
7107
|
* Error description
|
|
6454
7108
|
*/
|
|
@@ -6504,13 +7158,6 @@ interface ValidationOptions {
|
|
|
6504
7158
|
*/
|
|
6505
7159
|
lenient?: boolean;
|
|
6506
7160
|
|
|
6507
|
-
/**
|
|
6508
|
-
* Visited tokens
|
|
6509
|
-
*
|
|
6510
|
-
* @private
|
|
6511
|
-
*/
|
|
6512
|
-
visited?: Map<Token, Set<ValidationToken$1>>;
|
|
6513
|
-
|
|
6514
7161
|
/**
|
|
6515
7162
|
* Is optional
|
|
6516
7163
|
*
|
|
@@ -6617,6 +7264,39 @@ interface MinifyOptions {
|
|
|
6617
7264
|
* Inline css variables
|
|
6618
7265
|
*/
|
|
6619
7266
|
inlineCssVariables?: boolean;
|
|
7267
|
+
/**
|
|
7268
|
+
* Evaluate css mixins and custom functions: the `@apply` rules are replaced by the body of the mixin they reference,
|
|
7269
|
+
* the private variables (`@private`, mixin arguments and the custom properties of the rule) are substituted.
|
|
7270
|
+
* the custom function calls (`--fn(1px)`) are replaced by the result of the function.
|
|
7271
|
+
* see https://drafts.csswg.org/css-mixins-1/
|
|
7272
|
+
*
|
|
7273
|
+
* ```ts
|
|
7274
|
+
*
|
|
7275
|
+
* import {transform} from '@tbela99/css-parser';
|
|
7276
|
+
*
|
|
7277
|
+
* const css = `
|
|
7278
|
+
* @mixin --only-descs(--arg) {
|
|
7279
|
+
* color: var(--arg);
|
|
7280
|
+
* & * { color: var(--arg, red); }
|
|
7281
|
+
* }
|
|
7282
|
+
* .foo {
|
|
7283
|
+
* @apply --only-descs(green);
|
|
7284
|
+
* }
|
|
7285
|
+
* `;
|
|
7286
|
+
*
|
|
7287
|
+
* const result = await transform(css, {evaluateMixins: true, expandNestingRules: true});
|
|
7288
|
+
*
|
|
7289
|
+
* console.log(result.code);
|
|
7290
|
+
* // .foo,.foo *{color:green}
|
|
7291
|
+
* ```
|
|
7292
|
+
*/
|
|
7293
|
+
evaluateMixins?: boolean;
|
|
7294
|
+
/**
|
|
7295
|
+
* Keep the mixins and the custom functions once they are evaluated, see {@link evaluateMixins}.
|
|
7296
|
+
* By default, the evaluated mixins and custom functions, and the mixins that are not referenced, are dropped and
|
|
7297
|
+
* replaced with a comment
|
|
7298
|
+
*/
|
|
7299
|
+
keepMixins?: boolean;
|
|
6620
7300
|
/**
|
|
6621
7301
|
* Remove empty ast nodes
|
|
6622
7302
|
*/
|
|
@@ -7009,11 +7689,11 @@ export declare interface ParserSyncOptions
|
|
|
7009
7689
|
*/
|
|
7010
7690
|
setParent?: boolean;
|
|
7011
7691
|
/**
|
|
7012
|
-
*
|
|
7692
|
+
* Rendered size of the nodes, in bytes
|
|
7013
7693
|
*
|
|
7014
7694
|
* @private
|
|
7015
7695
|
*/
|
|
7016
|
-
cache?: Map<AstNode,
|
|
7696
|
+
cache?: Map<AstNode, number>;
|
|
7017
7697
|
|
|
7018
7698
|
/**
|
|
7019
7699
|
* CSS modules options
|
|
@@ -7341,79 +8021,30 @@ export declare interface ParseResult {
|
|
|
7341
8021
|
}
|
|
7342
8022
|
|
|
7343
8023
|
/**
|
|
7344
|
-
* Render
|
|
8024
|
+
* Render stats
|
|
7345
8025
|
*/
|
|
7346
|
-
export declare interface
|
|
7347
|
-
/**
|
|
7348
|
-
* Rendered CSS
|
|
7349
|
-
*/
|
|
7350
|
-
code: string;
|
|
8026
|
+
export declare interface RenderResultStats {
|
|
7351
8027
|
/**
|
|
7352
|
-
* Render
|
|
8028
|
+
* Render time
|
|
7353
8029
|
*/
|
|
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;
|
|
8030
|
+
total: string;
|
|
7368
8031
|
}
|
|
7369
8032
|
|
|
7370
8033
|
/**
|
|
7371
|
-
* Transform
|
|
8034
|
+
* Transform stats
|
|
7372
8035
|
*/
|
|
7373
|
-
export declare interface
|
|
8036
|
+
export declare interface TransformResultStats extends ParseResultStats {
|
|
7374
8037
|
/**
|
|
7375
|
-
*
|
|
8038
|
+
* Generated CSS size: the length of {@link TransformResult.code}
|
|
7376
8039
|
*/
|
|
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
|
-
};
|
|
8040
|
+
bytesOut: number;
|
|
8041
|
+
/**
|
|
8042
|
+
* Render time
|
|
8043
|
+
*/
|
|
8044
|
+
render: string;
|
|
7415
8045
|
}
|
|
7416
8046
|
|
|
8047
|
+
|
|
7417
8048
|
/**
|
|
7418
8049
|
* Parse token options
|
|
7419
8050
|
*/
|
|
@@ -7769,7 +8400,10 @@ declare function isOkLabClose(arena: AstArena, color1: Token, color2: Token, thr
|
|
|
7769
8400
|
*/
|
|
7770
8401
|
declare function parseSyntax(syntax: string): ValidationToken$1[];
|
|
7771
8402
|
|
|
7772
|
-
|
|
8403
|
+
/**
|
|
8404
|
+
* Version number
|
|
8405
|
+
*/
|
|
8406
|
+
declare const version = "2.2.0";
|
|
7773
8407
|
|
|
7774
8408
|
/**
|
|
7775
8409
|
* Load file or url
|
|
@@ -8108,5 +8742,5 @@ declare function transform(options: ParseInputStreamOptions & TransformOptions):
|
|
|
8108
8742
|
*/
|
|
8109
8743
|
declare function transform(options: ParseInputFileOptions & TransformOptions): Promise<TransformResult>;
|
|
8110
8744
|
|
|
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,
|
|
8745
|
+
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 };
|
|
8746
|
+
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 };
|