@tbela99/css-parser 1.3.4 → 1.4.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 +37 -0
- package/README.md +44 -31
- package/dist/config.json.js +3 -0
- package/dist/index-umd-web.js +1247 -72
- package/dist/index.cjs +1258 -72
- package/dist/index.d.ts +282 -17
- package/dist/lib/ast/features/type.js +1 -1
- package/dist/lib/ast/minify.js +1 -1
- package/dist/lib/ast/types.js +62 -3
- package/dist/lib/ast/walk.js +16 -9
- package/dist/lib/fs/resolve.js +63 -7
- package/dist/lib/parser/declaration/list.js +4 -1
- package/dist/lib/parser/parse.js +830 -13
- package/dist/lib/parser/tokenize.js +22 -7
- package/dist/lib/parser/utils/declaration.js +54 -0
- package/dist/lib/parser/utils/hash.js +86 -0
- package/dist/lib/parser/utils/text.js +8 -0
- package/dist/lib/renderer/render.js +25 -6
- package/dist/lib/syntax/color/relativecolor.js +0 -3
- package/dist/lib/validation/config.json.js +15 -3
- package/dist/lib/validation/syntax.js +6 -1
- package/dist/lib/validation/syntaxes/compound-selector.js +1 -2
- package/dist/lib/validation/syntaxes/relative-selector-list.js +2 -5
- package/dist/node.js +48 -11
- package/dist/types.d.ts +17 -0
- package/dist/types.js +20 -0
- package/dist/web.js +35 -9
- package/package.json +16 -16
package/dist/index.d.ts
CHANGED
|
@@ -422,6 +422,22 @@ declare enum EnumToken {
|
|
|
422
422
|
* invalid declaration node type
|
|
423
423
|
*/
|
|
424
424
|
InvalidDeclarationNodeType = 94,
|
|
425
|
+
/**
|
|
426
|
+
* composes token node type
|
|
427
|
+
*/
|
|
428
|
+
ComposesSelectorNodeType = 95,
|
|
429
|
+
/**
|
|
430
|
+
* css variable token type
|
|
431
|
+
*/
|
|
432
|
+
CssVariableTokenType = 96,
|
|
433
|
+
/**
|
|
434
|
+
* css variable import token type
|
|
435
|
+
*/
|
|
436
|
+
CssVariableImportTokenType = 97,
|
|
437
|
+
/**
|
|
438
|
+
* css variable declaration map token type
|
|
439
|
+
*/
|
|
440
|
+
CssVariableDeclarationMapTokenType = 98,
|
|
425
441
|
/**
|
|
426
442
|
* alias for time token type
|
|
427
443
|
*/
|
|
@@ -536,7 +552,7 @@ declare enum EnumToken {
|
|
|
536
552
|
*/
|
|
537
553
|
declare enum ColorType {
|
|
538
554
|
/**
|
|
539
|
-
* system colors
|
|
555
|
+
* deprecated system colors
|
|
540
556
|
*/
|
|
541
557
|
SYS = 0,
|
|
542
558
|
/**
|
|
@@ -544,7 +560,7 @@ declare enum ColorType {
|
|
|
544
560
|
*/
|
|
545
561
|
DPSYS = 1,
|
|
546
562
|
/**
|
|
547
|
-
* colors
|
|
563
|
+
* named colors
|
|
548
564
|
*/
|
|
549
565
|
LIT = 2,
|
|
550
566
|
/**
|
|
@@ -644,6 +660,46 @@ declare enum ColorType {
|
|
|
644
660
|
*/
|
|
645
661
|
DEVICE_CMYK = 7
|
|
646
662
|
}
|
|
663
|
+
declare enum ModuleCaseTransformEnum {
|
|
664
|
+
/**
|
|
665
|
+
* export class names as-is
|
|
666
|
+
*/
|
|
667
|
+
IgnoreCase = 1,
|
|
668
|
+
/**
|
|
669
|
+
* transform mapping key name to camel case
|
|
670
|
+
*/
|
|
671
|
+
CamelCase = 2,
|
|
672
|
+
/**
|
|
673
|
+
* transform class names and mapping key name to camel case
|
|
674
|
+
*/
|
|
675
|
+
CamelCaseOnly = 4,
|
|
676
|
+
/**
|
|
677
|
+
* transform mapping key name to dash case
|
|
678
|
+
*/
|
|
679
|
+
DashCase = 8,
|
|
680
|
+
/**
|
|
681
|
+
* transform class names and mapping key name to dash case
|
|
682
|
+
*/
|
|
683
|
+
DashCaseOnly = 16
|
|
684
|
+
}
|
|
685
|
+
declare enum ModuleScopeEnumOptions {
|
|
686
|
+
/**
|
|
687
|
+
* use the global scope
|
|
688
|
+
*/
|
|
689
|
+
Global = 32,
|
|
690
|
+
/**
|
|
691
|
+
* use the local scope
|
|
692
|
+
*/
|
|
693
|
+
Local = 64,
|
|
694
|
+
/**
|
|
695
|
+
* do not allow selector without an id or class
|
|
696
|
+
*/
|
|
697
|
+
Pure = 128,
|
|
698
|
+
/**
|
|
699
|
+
* export using ICSS module format
|
|
700
|
+
*/
|
|
701
|
+
ICSS = 256
|
|
702
|
+
}
|
|
647
703
|
|
|
648
704
|
/**
|
|
649
705
|
* apply minification rules to the ast tree
|
|
@@ -1078,7 +1134,7 @@ export declare interface FunctionURLToken extends BaseToken {
|
|
|
1078
1134
|
|
|
1079
1135
|
typ: EnumToken.UrlFunctionTokenType,
|
|
1080
1136
|
val: 'url';
|
|
1081
|
-
chi: Array<UrlToken | CommentToken>;
|
|
1137
|
+
chi: Array<UrlToken | StringToken | CommentToken>;
|
|
1082
1138
|
}
|
|
1083
1139
|
|
|
1084
1140
|
/**
|
|
@@ -1693,6 +1749,40 @@ export declare interface ListToken extends BaseToken {
|
|
|
1693
1749
|
chi: Token$1[];
|
|
1694
1750
|
}
|
|
1695
1751
|
|
|
1752
|
+
/**
|
|
1753
|
+
* Composes selector token
|
|
1754
|
+
*/
|
|
1755
|
+
export declare interface ComposesSelectorToken extends BaseToken {
|
|
1756
|
+
|
|
1757
|
+
typ: EnumToken.ComposesSelectorTokenType;
|
|
1758
|
+
l: Token$1[];
|
|
1759
|
+
r: Token$1 | null;
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
/**
|
|
1763
|
+
* Css variable token
|
|
1764
|
+
*/
|
|
1765
|
+
export declare interface CssVariableToken$1 extends BaseToken {
|
|
1766
|
+
|
|
1767
|
+
typ: EnumToken.CssVariableTokenType;
|
|
1768
|
+
nam: string;
|
|
1769
|
+
val: Token$1[];
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
export declare interface CssVariableImportTokenType$1 extends BaseToken {
|
|
1773
|
+
|
|
1774
|
+
typ: EnumToken.CssVariableImportTokenType;
|
|
1775
|
+
nam: string;
|
|
1776
|
+
val: Token$1[];
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
export declare interface CssVariableMapTokenType extends BaseToken {
|
|
1780
|
+
|
|
1781
|
+
typ: EnumToken.CssVariableMapTokenType;
|
|
1782
|
+
vars: Token$1[];
|
|
1783
|
+
from: Token$1[];
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1696
1786
|
/**
|
|
1697
1787
|
* Unary expression node
|
|
1698
1788
|
*/
|
|
@@ -1784,6 +1874,8 @@ export declare type Token$1 =
|
|
|
1784
1874
|
| ContainMatchToken
|
|
1785
1875
|
| MatchExpressionToken
|
|
1786
1876
|
| NameSpaceAttributeToken
|
|
1877
|
+
| ComposesSelectorToken
|
|
1878
|
+
| CssVariableToken$1
|
|
1787
1879
|
|
|
|
1788
1880
|
DashMatchToken
|
|
1789
1881
|
| EqualMatchToken
|
|
@@ -2226,7 +2318,9 @@ export declare type AstNode$1 =
|
|
|
2226
2318
|
| AstKeyFrameRule
|
|
2227
2319
|
| AstInvalidRule
|
|
2228
2320
|
| AstInvalidAtRule
|
|
2229
|
-
| AstInvalidDeclaration
|
|
2321
|
+
| AstInvalidDeclaration
|
|
2322
|
+
| CssVariableToken
|
|
2323
|
+
| CssVariableImportTokenType;
|
|
2230
2324
|
|
|
2231
2325
|
export declare type GenericVisitorResult<T> = T | T[] | Promise<T> | Promise<T[]> | null | Promise<null>;
|
|
2232
2326
|
export declare type GenericVisitorHandler<T> = ((node: T, parent?: AstNode | Token, root?: AstNode | Token) => GenericVisitorResult<T>);
|
|
@@ -2502,7 +2596,7 @@ export declare interface VisitorNodeMap {
|
|
|
2502
2596
|
* // body {color:#f3fff0}
|
|
2503
2597
|
* ```
|
|
2504
2598
|
*/
|
|
2505
|
-
[key: keyof typeof EnumToken]: GenericVisitorAstNodeHandlerMap<Token> | GenericVisitorAstNodeHandlerMap<AstNode>;
|
|
2599
|
+
[key : keyof typeof EnumToken]: GenericVisitorAstNodeHandlerMap<Token> | GenericVisitorAstNodeHandlerMap<AstNode>;
|
|
2506
2600
|
}
|
|
2507
2601
|
|
|
2508
2602
|
export declare interface PropertyListOptions {
|
|
@@ -2532,12 +2626,17 @@ export declare interface ParseInfo {
|
|
|
2532
2626
|
* current parsing position
|
|
2533
2627
|
*/
|
|
2534
2628
|
currentPosition: Position;
|
|
2629
|
+
|
|
2630
|
+
/**
|
|
2631
|
+
* offset
|
|
2632
|
+
*/
|
|
2633
|
+
offset: number;
|
|
2535
2634
|
}
|
|
2536
2635
|
|
|
2537
2636
|
/**
|
|
2538
2637
|
* feature walk mode
|
|
2539
2638
|
*
|
|
2540
|
-
* @
|
|
2639
|
+
* @private
|
|
2541
2640
|
*/
|
|
2542
2641
|
declare enum FeatureWalkMode {
|
|
2543
2642
|
/**
|
|
@@ -3074,9 +3173,9 @@ export declare type WalkerOption = WalkerOptionEnum | AstNode$1 | Token$1 | null
|
|
|
3074
3173
|
export declare type WalkerFilter = (node: AstNode$1) => WalkerOption;
|
|
3075
3174
|
|
|
3076
3175
|
/**
|
|
3077
|
-
* filter
|
|
3176
|
+
* filter nodes
|
|
3078
3177
|
*/
|
|
3079
|
-
export declare type WalkerValueFilter = (node: AstNode$1 | Token$1, parent?: AstNode$1 | Token$1 | null, event?: WalkerEvent) => WalkerOption | null;
|
|
3178
|
+
export declare type WalkerValueFilter = (node: AstNode$1 | Token$1, parent?: AstNode$1 | Token$1 | AstNode$1[] | Token$1[] | null, event?: WalkerEvent) => WalkerOption | null;
|
|
3080
3179
|
|
|
3081
3180
|
export declare interface WalkResult {
|
|
3082
3181
|
node: AstNode$1;
|
|
@@ -3268,6 +3367,126 @@ export declare type LoadResult =
|
|
|
3268
3367
|
| string
|
|
3269
3368
|
| Promise<string>;
|
|
3270
3369
|
|
|
3370
|
+
export declare interface ModuleOptions {
|
|
3371
|
+
|
|
3372
|
+
/**
|
|
3373
|
+
* use local scope vs global scope
|
|
3374
|
+
*/
|
|
3375
|
+
scoped?: boolean | ModuleScopeEnumOptions;
|
|
3376
|
+
|
|
3377
|
+
/**
|
|
3378
|
+
* module output file path. it is used to generate the scoped name. if not provided, [options.src](../docs/interfaces/node.ParserOptions.html#src) will be used
|
|
3379
|
+
*/
|
|
3380
|
+
filePath?: string;
|
|
3381
|
+
|
|
3382
|
+
/**
|
|
3383
|
+
* generated scope hash length. the default is 5
|
|
3384
|
+
*/
|
|
3385
|
+
hashLength?: number;
|
|
3386
|
+
|
|
3387
|
+
/**
|
|
3388
|
+
* the pattern used to generate scoped names. the supported placeholders are:
|
|
3389
|
+
* - name: the file base name without the extension
|
|
3390
|
+
* - hash: the file path hash
|
|
3391
|
+
* - local: the local name
|
|
3392
|
+
* - path: the file path
|
|
3393
|
+
* - folder: the folder name
|
|
3394
|
+
* - ext: the file extension
|
|
3395
|
+
*
|
|
3396
|
+
* the pattern can optionally have a maximum number of characters:
|
|
3397
|
+
* ```
|
|
3398
|
+
* pattern: '[local:2]-[hash:5]'
|
|
3399
|
+
* ```
|
|
3400
|
+
* the hash pattern can take an algorithm, a maximum number of characters or both:
|
|
3401
|
+
* ```
|
|
3402
|
+
* pattern: '[local]-[hash:base64:5]'
|
|
3403
|
+
* ```
|
|
3404
|
+
* or
|
|
3405
|
+
* ```
|
|
3406
|
+
* pattern: '[local]-[hash:5]'
|
|
3407
|
+
* ```
|
|
3408
|
+
* or
|
|
3409
|
+
* ```
|
|
3410
|
+
* pattern: '[local]-[hash:sha1]'
|
|
3411
|
+
* ```
|
|
3412
|
+
*
|
|
3413
|
+
* supported hash algorithms are:
|
|
3414
|
+
* - base64
|
|
3415
|
+
* - hex
|
|
3416
|
+
* - base64url
|
|
3417
|
+
* - sha1
|
|
3418
|
+
* - sha256
|
|
3419
|
+
* - sha384
|
|
3420
|
+
* - sha512
|
|
3421
|
+
*
|
|
3422
|
+
* ```typescript
|
|
3423
|
+
*
|
|
3424
|
+
* import {transform, ModuleCaseTransformEnum} from '@tbela99/css-parser';
|
|
3425
|
+
* import type {TransformResult} from '@tbela99/css-parser';
|
|
3426
|
+
* css = `
|
|
3427
|
+
* :local(.className) {
|
|
3428
|
+
* background: red;
|
|
3429
|
+
* color: yellow;
|
|
3430
|
+
* }
|
|
3431
|
+
*
|
|
3432
|
+
* :local(.subClass) {
|
|
3433
|
+
* composes: className;
|
|
3434
|
+
* background: blue;
|
|
3435
|
+
* }
|
|
3436
|
+
* `;
|
|
3437
|
+
*
|
|
3438
|
+
* let result: TransformResult = await transform(css, {
|
|
3439
|
+
*
|
|
3440
|
+
* beautify:true,
|
|
3441
|
+
* module: {
|
|
3442
|
+
* pattern: '[local]-[hash:sha256]'
|
|
3443
|
+
* }
|
|
3444
|
+
*
|
|
3445
|
+
* });
|
|
3446
|
+
*
|
|
3447
|
+
* console.log(result.code);
|
|
3448
|
+
* ```
|
|
3449
|
+
* generated css
|
|
3450
|
+
*
|
|
3451
|
+
* ```css
|
|
3452
|
+
* .className-b629f {
|
|
3453
|
+
* background: red;
|
|
3454
|
+
* color: #ff0
|
|
3455
|
+
* }
|
|
3456
|
+
* .subClass-a0c35 {
|
|
3457
|
+
* background: blue
|
|
3458
|
+
* }
|
|
3459
|
+
* ```
|
|
3460
|
+
*/
|
|
3461
|
+
pattern?: string;
|
|
3462
|
+
|
|
3463
|
+
/**
|
|
3464
|
+
* optional. function change the case of the scoped name and the class mapping
|
|
3465
|
+
*
|
|
3466
|
+
* - {@link ModuleCaseTransformEnum.IgnoreCase}: do not change case
|
|
3467
|
+
* - {@link ModuleCaseTransformEnum.CamelCase}: camelCase {@link ParseResult.mapping} key name
|
|
3468
|
+
* - {@link ModuleCaseTransformEnum.CamelCaseOnly}: camelCase {@link ParseResult.mapping} key name and the scoped class name
|
|
3469
|
+
* - {@link ModuleCaseTransformEnum.DashCase}: dashCase {@link ParseResult.mapping} key name
|
|
3470
|
+
* - {@link ModuleCaseTransformEnum.DashCaseOnly}: dashCase {@link ParseResult.mapping} key name and the scoped class name
|
|
3471
|
+
*
|
|
3472
|
+
*/
|
|
3473
|
+
naming?: ModuleCaseTransformEnum,
|
|
3474
|
+
|
|
3475
|
+
/**
|
|
3476
|
+
* optional function to generate scoped name
|
|
3477
|
+
* @param localName
|
|
3478
|
+
* @param filePath
|
|
3479
|
+
* @param pattern see {@link ModuleOptions.pattern}
|
|
3480
|
+
* @param hashLength
|
|
3481
|
+
*/
|
|
3482
|
+
generateScopedName?: (
|
|
3483
|
+
localName: string,
|
|
3484
|
+
filePath: string,
|
|
3485
|
+
pattern: string,
|
|
3486
|
+
hashLength?: number
|
|
3487
|
+
) => string | Promise<string>;
|
|
3488
|
+
}
|
|
3489
|
+
|
|
3271
3490
|
/**
|
|
3272
3491
|
* parser options
|
|
3273
3492
|
*/
|
|
@@ -3306,7 +3525,7 @@ export declare interface ParserOptions extends MinifyOptions, MinifyFeatureOptio
|
|
|
3306
3525
|
* @param asStream
|
|
3307
3526
|
*
|
|
3308
3527
|
*/
|
|
3309
|
-
load?: (url: string, currentUrl
|
|
3528
|
+
load?: (url: string, currentUrl?: string, asStream?: boolean) => LoadResult;
|
|
3310
3529
|
/**
|
|
3311
3530
|
* get directory name
|
|
3312
3531
|
* @param path
|
|
@@ -3360,6 +3579,11 @@ export declare interface ParserOptions extends MinifyOptions, MinifyFeatureOptio
|
|
|
3360
3579
|
* @private
|
|
3361
3580
|
*/
|
|
3362
3581
|
cache?: WeakMap<AstNode$1, string>;
|
|
3582
|
+
|
|
3583
|
+
/**
|
|
3584
|
+
* css modules options
|
|
3585
|
+
*/
|
|
3586
|
+
module?: boolean | ModuleCaseTransformEnum | ModuleScopeEnumOptions | ModuleOptions
|
|
3363
3587
|
}
|
|
3364
3588
|
|
|
3365
3589
|
/**
|
|
@@ -3536,13 +3760,17 @@ export declare interface ParseResultStats {
|
|
|
3536
3760
|
*/
|
|
3537
3761
|
importedBytesIn: number;
|
|
3538
3762
|
/**
|
|
3539
|
-
* parse time
|
|
3763
|
+
* parse processing time
|
|
3540
3764
|
*/
|
|
3541
3765
|
parse: string;
|
|
3542
3766
|
/**
|
|
3543
|
-
* minify time
|
|
3767
|
+
* minify processing time
|
|
3544
3768
|
*/
|
|
3545
3769
|
minify: string;
|
|
3770
|
+
/**
|
|
3771
|
+
* module processing time
|
|
3772
|
+
*/
|
|
3773
|
+
module?: string;
|
|
3546
3774
|
/**
|
|
3547
3775
|
* total time
|
|
3548
3776
|
*/
|
|
@@ -3578,7 +3806,22 @@ export declare interface ParseResult {
|
|
|
3578
3806
|
/**
|
|
3579
3807
|
* parse stats
|
|
3580
3808
|
*/
|
|
3581
|
-
stats: ParseResultStats
|
|
3809
|
+
stats: ParseResultStats;
|
|
3810
|
+
|
|
3811
|
+
/**
|
|
3812
|
+
* css module mapping
|
|
3813
|
+
*/
|
|
3814
|
+
mapping?: Record<string, string>;
|
|
3815
|
+
|
|
3816
|
+
cssModuleVariables?: Record<string, CssVariableToken$1>;
|
|
3817
|
+
|
|
3818
|
+
importMapping?: Record<string, Record<string, string>>;
|
|
3819
|
+
|
|
3820
|
+
/**
|
|
3821
|
+
* css module reverse mapping
|
|
3822
|
+
* @private
|
|
3823
|
+
*/
|
|
3824
|
+
revMapping?: Record<string, string>;
|
|
3582
3825
|
}
|
|
3583
3826
|
|
|
3584
3827
|
/**
|
|
@@ -3781,20 +4024,39 @@ declare function resolve(url: string, currentDirectory: string, cwd?: string): {
|
|
|
3781
4024
|
relative: string;
|
|
3782
4025
|
};
|
|
3783
4026
|
|
|
4027
|
+
/**
|
|
4028
|
+
* response type
|
|
4029
|
+
*/
|
|
4030
|
+
declare enum ResponseType {
|
|
4031
|
+
/**
|
|
4032
|
+
* return text
|
|
4033
|
+
*/
|
|
4034
|
+
Text = 0,
|
|
4035
|
+
/**
|
|
4036
|
+
* return a readable stream
|
|
4037
|
+
*/
|
|
4038
|
+
ReadableStream = 1,
|
|
4039
|
+
/**
|
|
4040
|
+
* return an arraybuffer
|
|
4041
|
+
*/
|
|
4042
|
+
ArrayBuffer = 2
|
|
4043
|
+
}
|
|
4044
|
+
|
|
3784
4045
|
/**
|
|
3785
4046
|
* load file or url as stream
|
|
3786
4047
|
* @param url
|
|
3787
4048
|
* @param currentFile
|
|
3788
|
-
* @param
|
|
4049
|
+
* @param responseType
|
|
3789
4050
|
* @throws Error file not found
|
|
3790
4051
|
*
|
|
3791
4052
|
* @private
|
|
3792
4053
|
*/
|
|
3793
|
-
declare function load(url: string, currentFile?: string,
|
|
4054
|
+
declare function load(url: string, currentFile?: string, responseType?: boolean | ResponseType): Promise<string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
3794
4055
|
/**
|
|
3795
4056
|
* render the ast tree
|
|
3796
4057
|
* @param data
|
|
3797
4058
|
* @param options
|
|
4059
|
+
* @param mapping
|
|
3798
4060
|
*
|
|
3799
4061
|
* Example:
|
|
3800
4062
|
*
|
|
@@ -3819,7 +4081,10 @@ declare function load(url: string, currentFile?: string, asStream?: boolean): Pr
|
|
|
3819
4081
|
* // }
|
|
3820
4082
|
* ```
|
|
3821
4083
|
*/
|
|
3822
|
-
declare function render(data: AstNode$1, options?: RenderOptions
|
|
4084
|
+
declare function render(data: AstNode$1, options?: RenderOptions, mapping?: {
|
|
4085
|
+
mapping: Record<string, string>;
|
|
4086
|
+
importMapping: Record<string, Record<string, string>> | null;
|
|
4087
|
+
} | null): RenderResult;
|
|
3823
4088
|
/**
|
|
3824
4089
|
* parse css file
|
|
3825
4090
|
* @param file url or path
|
|
@@ -3957,5 +4222,5 @@ declare function transformFile(file: string, options?: TransformOptions, asStrea
|
|
|
3957
4222
|
*/
|
|
3958
4223
|
declare function transform(css: string | ReadableStream<Uint8Array>, options?: TransformOptions): Promise<TransformResult>;
|
|
3959
4224
|
|
|
3960
|
-
export { ColorType, EnumToken, FeatureWalkMode, SourceMap, ValidationLevel, WalkerEvent, WalkerOptionEnum, convertColor, dirname, expand, isOkLabClose, load, mathFuncs, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, parseTokens, render, renderToken, resolve, transform, transformFile, transformFunctions, walk, walkValues };
|
|
3961
|
-
export type { AddToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyFrameRule, AstKeyframesAtRule, AstKeyframesRule, AstNode$1 as AstNode, AstRule, AstRuleList, AstStyleSheet, 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, ConstraintsMapping, ContainMatchToken, Context, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorHandler, GenericVisitorResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, ImportantToken, IncludeMatchToken, InvalidAttrToken, InvalidClassSelectorToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Location, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureAndToken, MediaFeatureNotToken, MediaFeatureOnlyToken, MediaFeatureOrToken, MediaFeatureToken, MediaQueryConditionToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, MulToken, NameSpaceAttributeToken, NestingSelectorToken, NextSiblingCombinatorToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo, ParseResult, ParseResultStats, ParseTokenOptions, ParserOptions, PercentageToken, Position, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token$1 as Token, TokenizeResult, TransformOptions, TransformResult, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, Value, ValueVisitorHandler, VariableScopeInfo, VisitorNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerValueFilter, WhitespaceToken };
|
|
4225
|
+
export { ColorType, EnumToken, FeatureWalkMode, ModuleCaseTransformEnum, ModuleScopeEnumOptions, ResponseType, SourceMap, ValidationLevel, WalkerEvent, WalkerOptionEnum, convertColor, dirname, expand, isOkLabClose, load, mathFuncs, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, parseTokens, render, renderToken, resolve, transform, transformFile, transformFunctions, walk, walkValues };
|
|
4226
|
+
export type { AddToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyFrameRule, AstKeyframesAtRule, AstKeyframesRule, AstNode$1 as AstNode, AstRule, AstRuleList, AstStyleSheet, 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, Context, CssVariableImportTokenType$1 as CssVariableImportTokenType, CssVariableMapTokenType, CssVariableToken$1 as CssVariableToken, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorHandler, GenericVisitorResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, ImportantToken, IncludeMatchToken, InvalidAttrToken, InvalidClassSelectorToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Location, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureAndToken, MediaFeatureNotToken, MediaFeatureOnlyToken, MediaFeatureOrToken, MediaFeatureToken, MediaQueryConditionToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, ModuleOptions, MulToken, NameSpaceAttributeToken, NestingSelectorToken, NextSiblingCombinatorToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo, ParseResult, ParseResultStats, ParseTokenOptions, ParserOptions, PercentageToken, Position, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token$1 as Token, TokenizeResult, TransformOptions, TransformResult, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, Value, ValueVisitorHandler, VariableScopeInfo, VisitorNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerValueFilter, WhitespaceToken };
|
package/dist/lib/ast/minify.js
CHANGED
|
@@ -439,7 +439,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
439
439
|
nodeIndex = i;
|
|
440
440
|
}
|
|
441
441
|
if (recursive && node != null && ('chi' in node)) {
|
|
442
|
-
if (node.typ == EnumToken.KeyframesAtRuleNodeType || !node.chi.some(n => n.typ == EnumToken.DeclarationNodeType)) {
|
|
442
|
+
if (node.typ == EnumToken.KeyframesAtRuleNodeType || !node.chi.some((n) => n.typ == EnumToken.DeclarationNodeType)) {
|
|
443
443
|
if (!(node.typ == EnumToken.AtRuleNodeType && node.nam != 'font-face')) {
|
|
444
444
|
doMinify(node, options, recursive, errors, nestingContent, context);
|
|
445
445
|
}
|
package/dist/lib/ast/types.js
CHANGED
|
@@ -427,6 +427,23 @@ var EnumToken;
|
|
|
427
427
|
* invalid declaration node type
|
|
428
428
|
*/
|
|
429
429
|
EnumToken[EnumToken["InvalidDeclarationNodeType"] = 94] = "InvalidDeclarationNodeType";
|
|
430
|
+
/* css module nodes */
|
|
431
|
+
/**
|
|
432
|
+
* composes token node type
|
|
433
|
+
*/
|
|
434
|
+
EnumToken[EnumToken["ComposesSelectorNodeType"] = 95] = "ComposesSelectorNodeType";
|
|
435
|
+
/**
|
|
436
|
+
* css variable token type
|
|
437
|
+
*/
|
|
438
|
+
EnumToken[EnumToken["CssVariableTokenType"] = 96] = "CssVariableTokenType";
|
|
439
|
+
/**
|
|
440
|
+
* css variable import token type
|
|
441
|
+
*/
|
|
442
|
+
EnumToken[EnumToken["CssVariableImportTokenType"] = 97] = "CssVariableImportTokenType";
|
|
443
|
+
/**
|
|
444
|
+
* css variable declaration map token type
|
|
445
|
+
*/
|
|
446
|
+
EnumToken[EnumToken["CssVariableDeclarationMapTokenType"] = 98] = "CssVariableDeclarationMapTokenType";
|
|
430
447
|
/* aliases */
|
|
431
448
|
/**
|
|
432
449
|
* alias for time token type
|
|
@@ -543,7 +560,7 @@ var EnumToken;
|
|
|
543
560
|
var ColorType;
|
|
544
561
|
(function (ColorType) {
|
|
545
562
|
/**
|
|
546
|
-
* system colors
|
|
563
|
+
* deprecated system colors
|
|
547
564
|
*/
|
|
548
565
|
ColorType[ColorType["SYS"] = 0] = "SYS";
|
|
549
566
|
/**
|
|
@@ -551,7 +568,7 @@ var ColorType;
|
|
|
551
568
|
*/
|
|
552
569
|
ColorType[ColorType["DPSYS"] = 1] = "DPSYS";
|
|
553
570
|
/**
|
|
554
|
-
* colors
|
|
571
|
+
* named colors
|
|
555
572
|
*/
|
|
556
573
|
ColorType[ColorType["LIT"] = 2] = "LIT";
|
|
557
574
|
/**
|
|
@@ -651,5 +668,47 @@ var ColorType;
|
|
|
651
668
|
*/
|
|
652
669
|
ColorType[ColorType["DEVICE_CMYK"] = 7] = "DEVICE_CMYK";
|
|
653
670
|
})(ColorType || (ColorType = {}));
|
|
671
|
+
var ModuleCaseTransformEnum;
|
|
672
|
+
(function (ModuleCaseTransformEnum) {
|
|
673
|
+
/**
|
|
674
|
+
* export class names as-is
|
|
675
|
+
*/
|
|
676
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["IgnoreCase"] = 1] = "IgnoreCase";
|
|
677
|
+
/**
|
|
678
|
+
* transform mapping key name to camel case
|
|
679
|
+
*/
|
|
680
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCase"] = 2] = "CamelCase";
|
|
681
|
+
/**
|
|
682
|
+
* transform class names and mapping key name to camel case
|
|
683
|
+
*/
|
|
684
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCaseOnly"] = 4] = "CamelCaseOnly";
|
|
685
|
+
/**
|
|
686
|
+
* transform mapping key name to dash case
|
|
687
|
+
*/
|
|
688
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["DashCase"] = 8] = "DashCase";
|
|
689
|
+
/**
|
|
690
|
+
* transform class names and mapping key name to dash case
|
|
691
|
+
*/
|
|
692
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["DashCaseOnly"] = 16] = "DashCaseOnly";
|
|
693
|
+
})(ModuleCaseTransformEnum || (ModuleCaseTransformEnum = {}));
|
|
694
|
+
var ModuleScopeEnumOptions;
|
|
695
|
+
(function (ModuleScopeEnumOptions) {
|
|
696
|
+
/**
|
|
697
|
+
* use the global scope
|
|
698
|
+
*/
|
|
699
|
+
ModuleScopeEnumOptions[ModuleScopeEnumOptions["Global"] = 32] = "Global";
|
|
700
|
+
/**
|
|
701
|
+
* use the local scope
|
|
702
|
+
*/
|
|
703
|
+
ModuleScopeEnumOptions[ModuleScopeEnumOptions["Local"] = 64] = "Local";
|
|
704
|
+
/**
|
|
705
|
+
* do not allow selector without an id or class
|
|
706
|
+
*/
|
|
707
|
+
ModuleScopeEnumOptions[ModuleScopeEnumOptions["Pure"] = 128] = "Pure";
|
|
708
|
+
/**
|
|
709
|
+
* export using ICSS module format
|
|
710
|
+
*/
|
|
711
|
+
ModuleScopeEnumOptions[ModuleScopeEnumOptions["ICSS"] = 256] = "ICSS";
|
|
712
|
+
})(ModuleScopeEnumOptions || (ModuleScopeEnumOptions = {}));
|
|
654
713
|
|
|
655
|
-
export { ColorType, EnumToken, SyntaxValidationResult, ValidationLevel };
|
|
714
|
+
export { ColorType, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, SyntaxValidationResult, ValidationLevel };
|
package/dist/lib/ast/walk.js
CHANGED
|
@@ -187,7 +187,6 @@ function* walk(node, filter, reverse) {
|
|
|
187
187
|
* ```
|
|
188
188
|
*/
|
|
189
189
|
function* walkValues(values, root = null, filter, reverse) {
|
|
190
|
-
// const set = new Set<Token>();
|
|
191
190
|
const stack = values.slice();
|
|
192
191
|
const map = new Map;
|
|
193
192
|
let previous = null;
|
|
@@ -221,8 +220,12 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
221
220
|
continue;
|
|
222
221
|
}
|
|
223
222
|
// @ts-ignore
|
|
224
|
-
if (option != null && typeof option == 'object' && 'typ' in option) {
|
|
225
|
-
|
|
223
|
+
if (option != null && typeof option == 'object' && ('typ' in option || Array.isArray(option))) {
|
|
224
|
+
const op = Array.isArray(option) ? option : [option];
|
|
225
|
+
for (const o of op) {
|
|
226
|
+
map.set(o, map.get(value) ?? root);
|
|
227
|
+
}
|
|
228
|
+
stack[reverse ? 'push' : 'unshift'](...op);
|
|
226
229
|
}
|
|
227
230
|
}
|
|
228
231
|
}
|
|
@@ -245,12 +248,12 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
245
248
|
const values = [];
|
|
246
249
|
if ('l' in value && value.l != null) {
|
|
247
250
|
// @ts-ignore
|
|
248
|
-
values
|
|
251
|
+
values.push(value.l);
|
|
249
252
|
// @ts-ignore
|
|
250
253
|
map.set(value.l, value);
|
|
251
254
|
}
|
|
252
255
|
if ('op' in value && typeof value.op == 'object') {
|
|
253
|
-
values
|
|
256
|
+
values.push(value.op);
|
|
254
257
|
// @ts-ignore
|
|
255
258
|
map.set(value.op, value);
|
|
256
259
|
}
|
|
@@ -258,14 +261,14 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
258
261
|
if (Array.isArray(value.r)) {
|
|
259
262
|
for (const r of value.r) {
|
|
260
263
|
// @ts-ignore
|
|
261
|
-
values
|
|
264
|
+
values.push(r);
|
|
262
265
|
// @ts-ignore
|
|
263
266
|
map.set(r, value);
|
|
264
267
|
}
|
|
265
268
|
}
|
|
266
269
|
else {
|
|
267
270
|
// @ts-ignore
|
|
268
|
-
values
|
|
271
|
+
values.push(value.r);
|
|
269
272
|
// @ts-ignore
|
|
270
273
|
map.set(value.r, value);
|
|
271
274
|
}
|
|
@@ -281,8 +284,12 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
281
284
|
if (isValid) {
|
|
282
285
|
option = filter.fn(value, map.get(value), WalkerEvent.Leave);
|
|
283
286
|
// @ts-ignore
|
|
284
|
-
if (option != null && 'typ' in option) {
|
|
285
|
-
|
|
287
|
+
if (option != null && ('typ' in option || Array.isArray(option))) {
|
|
288
|
+
const op = Array.isArray(option) ? option : [option];
|
|
289
|
+
for (const o of op) {
|
|
290
|
+
map.set(o, map.get(value) ?? root);
|
|
291
|
+
}
|
|
292
|
+
stack[reverse ? 'push' : 'unshift'](...op);
|
|
286
293
|
}
|
|
287
294
|
}
|
|
288
295
|
}
|