@tbela99/css-parser 1.4.7 → 1.4.9
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 +33 -2
- package/dist/index-umd-web.js +12953 -13248
- package/dist/index.cjs +10358 -10655
- package/dist/index.d.ts +820 -89
- package/dist/lib/ast/features/calc.js +3 -1
- package/dist/lib/ast/features/if.js +2 -96
- package/dist/lib/ast/features/prefix.js +7 -2
- package/dist/lib/ast/features/shorthand.js +1 -1
- package/dist/lib/ast/features/transform.js +1 -1
- package/dist/lib/ast/find.js +6 -6
- package/dist/lib/ast/math/expression.js +30 -12
- package/dist/lib/ast/minify.js +34 -5
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/utils.js +29 -21
- package/dist/lib/ast/types.js +12 -0
- package/dist/lib/fs/resolve.js +2 -17
- package/dist/lib/parser/declaration/list.js +6 -1
- package/dist/lib/parser/linesmap.js +78 -0
- package/dist/lib/parser/parse.js +1264 -151
- package/dist/lib/parser/source.js +103 -0
- package/dist/lib/parser/tokenize.js +112 -133
- package/dist/lib/parser/utils/at-rule-container.js +12 -44
- package/dist/lib/parser/utils/at-rule-generic.js +12 -24
- package/dist/lib/parser/utils/at-rule-import.js +4 -172
- package/dist/lib/parser/utils/at-rule-media.js +27 -263
- package/dist/lib/parser/utils/at-rule-support.js +8 -258
- package/dist/lib/parser/utils/at-rule-when-else.js +4 -214
- package/dist/lib/parser/utils/declaration.js +5 -95
- package/dist/lib/parser/utils/hash.js +54 -1
- package/dist/lib/parser/utils/selector.js +1 -1
- package/dist/lib/parser/utils/token.js +1 -0
- package/dist/lib/renderer/render.js +79 -45
- package/dist/lib/renderer/sourcemap/sourcemap.js +47 -43
- package/dist/lib/syntax/color/cmyk.js +3 -3
- package/dist/lib/syntax/color/color-mix.js +15 -8
- package/dist/lib/syntax/color/color.js +19 -11
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/hsl.js +6 -6
- package/dist/lib/syntax/color/hwb.js +6 -6
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +6 -6
- package/dist/lib/syntax/color/oklab.js +5 -5
- package/dist/lib/syntax/color/oklch.js +5 -5
- package/dist/lib/syntax/color/p3.js +9 -1
- package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +8 -1
- package/dist/lib/syntax/color/utils/distance.js +7 -2
- package/dist/lib/syntax/constants.js +5 -1
- package/dist/lib/syntax/syntax.js +12 -21
- package/dist/lib/validation/config.json.js +27 -6
- package/dist/lib/validation/match.js +42 -845
- package/dist/node.js +136 -11
- package/dist/web.js +135 -8
- package/llms.txt +73 -0
- package/package.json +14 -17
package/dist/index.d.ts
CHANGED
|
@@ -2356,6 +2356,18 @@ declare enum ColorType$1 {
|
|
|
2356
2356
|
* alpha() color function
|
|
2357
2357
|
*/
|
|
2358
2358
|
ALPHA = 25,
|
|
2359
|
+
/**
|
|
2360
|
+
* color using display-p3-linear
|
|
2361
|
+
*/
|
|
2362
|
+
DISPLAY_P3_LINEAR = 26,
|
|
2363
|
+
/**
|
|
2364
|
+
* Contrast color
|
|
2365
|
+
*/
|
|
2366
|
+
CONTRAST_COLOR = 27,
|
|
2367
|
+
/**
|
|
2368
|
+
* color layers
|
|
2369
|
+
*/
|
|
2370
|
+
COLOR_LAYERS = 28,
|
|
2359
2371
|
/**
|
|
2360
2372
|
* alias for rgba
|
|
2361
2373
|
*/
|
|
@@ -2449,40 +2461,22 @@ declare const TOKENS: unique symbol;
|
|
|
2449
2461
|
declare const PARENT: unique symbol;
|
|
2450
2462
|
declare const OPTIMIZED: unique symbol;
|
|
2451
2463
|
|
|
2452
|
-
/**
|
|
2453
|
-
* Position
|
|
2454
|
-
*/
|
|
2455
|
-
export declare interface Position$1 {
|
|
2456
|
-
/**
|
|
2457
|
-
* index in the source
|
|
2458
|
-
*/
|
|
2459
|
-
ind: number;
|
|
2460
|
-
/**
|
|
2461
|
-
* line number
|
|
2462
|
-
*/
|
|
2463
|
-
lin: number;
|
|
2464
|
-
/**
|
|
2465
|
-
* column number
|
|
2466
|
-
*/
|
|
2467
|
-
col: number;
|
|
2468
|
-
}
|
|
2469
|
-
|
|
2470
2464
|
/**
|
|
2471
2465
|
* token or node location
|
|
2472
2466
|
*/
|
|
2473
|
-
export declare interface
|
|
2467
|
+
export declare interface SourceLocation {
|
|
2474
2468
|
/**
|
|
2475
2469
|
* start position
|
|
2476
2470
|
*/
|
|
2477
|
-
sta:
|
|
2471
|
+
sta: number;
|
|
2478
2472
|
/**
|
|
2479
2473
|
* end position
|
|
2480
2474
|
*/
|
|
2481
|
-
end:
|
|
2475
|
+
end: number;
|
|
2482
2476
|
/**
|
|
2483
2477
|
* source file
|
|
2484
2478
|
*/
|
|
2485
|
-
|
|
2479
|
+
srcId: number;
|
|
2486
2480
|
}
|
|
2487
2481
|
|
|
2488
2482
|
/**
|
|
@@ -2497,7 +2491,7 @@ export declare interface BaseToken {
|
|
|
2497
2491
|
* location info
|
|
2498
2492
|
* @private
|
|
2499
2493
|
*/
|
|
2500
|
-
[LOC]?:
|
|
2494
|
+
[LOC]?: SourceLocation;
|
|
2501
2495
|
/**
|
|
2502
2496
|
* parent node
|
|
2503
2497
|
* @private
|
|
@@ -3066,12 +3060,285 @@ declare function walkValues(values: Token$1[], root?: AstNode$1 | Token$1 | null
|
|
|
3066
3060
|
type?: EnumToken | EnumToken[] | ((token: Token$1) => boolean);
|
|
3067
3061
|
}, reverse?: boolean): Generator<WalkAttributesResult>;
|
|
3068
3062
|
|
|
3069
|
-
export declare type
|
|
3063
|
+
export declare type GenericVisitorSyncResult<T> = T | T[] | null;
|
|
3064
|
+
export declare type GenericVisitorAsyncResult<T> = Promise<T> | Promise<T[]>| Promise<null>;
|
|
3065
|
+
export declare type GenericVisitorResult<T> = GenericVisitorSyncResult<T> | GenericVisitorAsyncResult<T>;
|
|
3066
|
+
|
|
3067
|
+
|
|
3068
|
+
|
|
3069
|
+
export declare type GenericVisitorSyncHandler<T> = (
|
|
3070
|
+
node: T,
|
|
3071
|
+
parent?: AstNode | Token,
|
|
3072
|
+
root?: AstNode | Token,
|
|
3073
|
+
) => GenericVisitorSyncResult<T>;
|
|
3074
|
+
|
|
3075
|
+
export declare type GenericVisitorAstNodeSyncHandlerMap<T> =
|
|
3076
|
+
| Record<string, GenericVisitorSyncHandler<T>>
|
|
3077
|
+
| GenericVisitorSyncHandler<T>
|
|
3078
|
+
| { type: WalkerEvent; handler: GenericVisitorSyncHandler<T> }
|
|
3079
|
+
| { type: WalkerEvent; handler: Record<string, GenericVisitorSyncHandler<T>> };
|
|
3080
|
+
|
|
3081
|
+
export declare type ValueVisitorSyncHandler = GenericVisitorSyncHandler<Token>;
|
|
3082
|
+
|
|
3083
|
+
/**
|
|
3084
|
+
* node visitor callback map
|
|
3085
|
+
*
|
|
3086
|
+
*/
|
|
3087
|
+
export declare interface VisitorSyncNodeMap {
|
|
3088
|
+
/**
|
|
3089
|
+
* at rule visitor
|
|
3090
|
+
*
|
|
3091
|
+
* Example: change media at-rule prelude
|
|
3092
|
+
*
|
|
3093
|
+
* ```ts
|
|
3094
|
+
*
|
|
3095
|
+
* import {transform, AstAtRule, ParserOptions} from "@tbela99/css-parser";
|
|
3096
|
+
*
|
|
3097
|
+
* const options: ParserOptions = {
|
|
3098
|
+
*
|
|
3099
|
+
* visitor: {
|
|
3100
|
+
*
|
|
3101
|
+
* AtRule: {
|
|
3102
|
+
*
|
|
3103
|
+
* media: (node: AstAtRule): AstAtRule => {
|
|
3104
|
+
*
|
|
3105
|
+
* node.val = 'tv,screen';
|
|
3106
|
+
* return node
|
|
3107
|
+
* }
|
|
3108
|
+
* }
|
|
3109
|
+
* }
|
|
3110
|
+
* };
|
|
3111
|
+
*
|
|
3112
|
+
* const css = `
|
|
3113
|
+
*
|
|
3114
|
+
* @media screen {
|
|
3115
|
+
*
|
|
3116
|
+
* .foo {
|
|
3117
|
+
*
|
|
3118
|
+
* height: calc(100px * 2/ 15);
|
|
3119
|
+
* }
|
|
3120
|
+
* }
|
|
3121
|
+
* `;
|
|
3122
|
+
*
|
|
3123
|
+
* const result = await transform(css, options);
|
|
3124
|
+
*
|
|
3125
|
+
* console.debug(result.code);
|
|
3126
|
+
*
|
|
3127
|
+
* // @media tv,screen{.foo{height:calc(40px/3)}}
|
|
3128
|
+
* ```
|
|
3129
|
+
*/
|
|
3130
|
+
AtRule?: GenericVisitorAstNodeSyncHandlerMap<AstAtRule>;
|
|
3131
|
+
/**
|
|
3132
|
+
* declaration visitor
|
|
3133
|
+
*
|
|
3134
|
+
* Example: add 'width: 3px' everytime a declaration with the name 'height' is found
|
|
3135
|
+
*
|
|
3136
|
+
* ```ts
|
|
3137
|
+
*
|
|
3138
|
+
* import {transform, parseDeclarations} from "@tbela99/css-parser";
|
|
3139
|
+
*
|
|
3140
|
+
* const options: ParserOptions = {
|
|
3141
|
+
*
|
|
3142
|
+
* removeEmpty: false,
|
|
3143
|
+
* visitor: {
|
|
3144
|
+
*
|
|
3145
|
+
* Declaration: {
|
|
3146
|
+
*
|
|
3147
|
+
* // called only for height declaration
|
|
3148
|
+
* height: (node: AstDeclaration): AstDeclaration[] => {
|
|
3149
|
+
*
|
|
3150
|
+
*
|
|
3151
|
+
* return [
|
|
3152
|
+
* node,
|
|
3153
|
+
* {
|
|
3154
|
+
*
|
|
3155
|
+
* typ: EnumToken.DeclarationNodeType,
|
|
3156
|
+
* nam: 'width',
|
|
3157
|
+
* val: [
|
|
3158
|
+
* <LengthToken>{
|
|
3159
|
+
* typ: EnumToken.LengthTokenType,
|
|
3160
|
+
* val: 3,
|
|
3161
|
+
* unit: 'px'
|
|
3162
|
+
* }
|
|
3163
|
+
* ]
|
|
3164
|
+
* }
|
|
3165
|
+
* ];
|
|
3166
|
+
* }
|
|
3167
|
+
* }
|
|
3168
|
+
* }
|
|
3169
|
+
* };
|
|
3170
|
+
*
|
|
3171
|
+
* const css = `
|
|
3172
|
+
*
|
|
3173
|
+
* .foo {
|
|
3174
|
+
* height: calc(100px * 2/ 15);
|
|
3175
|
+
* }
|
|
3176
|
+
* .selector {
|
|
3177
|
+
* color: lch(from peru calc(l * 0.8) calc(c * 0.7) calc(h + 180))
|
|
3178
|
+
* }
|
|
3179
|
+
* `;
|
|
3180
|
+
*
|
|
3181
|
+
* console.debug(await transform(css, options));
|
|
3182
|
+
*
|
|
3183
|
+
* // .foo{height:calc(40px/3);width:3px}.selector{color:#0880b0}
|
|
3184
|
+
* ```
|
|
3185
|
+
*
|
|
3186
|
+
* Example: rename 'margin' to 'padding' and 'height' to 'width'
|
|
3187
|
+
*
|
|
3188
|
+
* ```ts
|
|
3189
|
+
* import {AstDeclaration, ParserOptions, transform} from "../src/node.ts";
|
|
3190
|
+
*
|
|
3191
|
+
* const options: ParserOptions = {
|
|
3192
|
+
*
|
|
3193
|
+
* visitor: {
|
|
3194
|
+
*
|
|
3195
|
+
* // called for every declaration
|
|
3196
|
+
* Declaration: (node: AstDeclaration): null => {
|
|
3197
|
+
*
|
|
3198
|
+
*
|
|
3199
|
+
* if (node.nam == 'height') {
|
|
3200
|
+
*
|
|
3201
|
+
* node.nam = 'width';
|
|
3202
|
+
* }
|
|
3203
|
+
*
|
|
3204
|
+
* else if (node.nam == 'margin') {
|
|
3205
|
+
*
|
|
3206
|
+
* node.nam = 'padding'
|
|
3207
|
+
* }
|
|
3208
|
+
*
|
|
3209
|
+
* return null;
|
|
3210
|
+
* }
|
|
3211
|
+
* }
|
|
3212
|
+
* };
|
|
3213
|
+
*
|
|
3214
|
+
* const css = `
|
|
3215
|
+
*
|
|
3216
|
+
* .foo {
|
|
3217
|
+
* height: calc(100px * 2/ 15);
|
|
3218
|
+
* margin: 10px;
|
|
3219
|
+
* }
|
|
3220
|
+
* .selector {
|
|
3221
|
+
*
|
|
3222
|
+
* margin: 20px;}
|
|
3223
|
+
* `;
|
|
3224
|
+
*
|
|
3225
|
+
* const result = await transform(css, options);
|
|
3226
|
+
*
|
|
3227
|
+
* console.debug(result.code);
|
|
3228
|
+
*
|
|
3229
|
+
* // .foo{width:calc(40px/3);padding:10px}.selector{padding:20px}
|
|
3230
|
+
* ```
|
|
3231
|
+
*/
|
|
3232
|
+
Declaration?: GenericVisitorAstNodeSyncHandlerMap<AstDeclaration>;
|
|
3233
|
+
|
|
3234
|
+
/**
|
|
3235
|
+
* rule visitor
|
|
3236
|
+
*
|
|
3237
|
+
* Example: add 'width: 3px' to every rule with the selector '.foo'
|
|
3238
|
+
*
|
|
3239
|
+
* ```ts
|
|
3240
|
+
*
|
|
3241
|
+
* import {transform, parseDeclarations} from "@tbela99/css-parser";
|
|
3242
|
+
*
|
|
3243
|
+
* const options: ParserOptions = {
|
|
3244
|
+
*
|
|
3245
|
+
* removeEmpty: false,
|
|
3246
|
+
* visitor: {
|
|
3247
|
+
*
|
|
3248
|
+
* Rule: async (node: AstRule): Promise<AstRule | null> => {
|
|
3249
|
+
*
|
|
3250
|
+
* if (node.sel == '.foo') {
|
|
3251
|
+
*
|
|
3252
|
+
* node.chi.push(...await parseDeclarations('width: 3px'));
|
|
3253
|
+
* return node;
|
|
3254
|
+
* }
|
|
3255
|
+
*
|
|
3256
|
+
* return null;
|
|
3257
|
+
* }
|
|
3258
|
+
* }
|
|
3259
|
+
* };
|
|
3260
|
+
*
|
|
3261
|
+
* const css = `
|
|
3262
|
+
*
|
|
3263
|
+
* .foo {
|
|
3264
|
+
* .foo {
|
|
3265
|
+
* }
|
|
3266
|
+
* }
|
|
3267
|
+
* `;
|
|
3268
|
+
*
|
|
3269
|
+
* console.debug(await transform(css, options));
|
|
3270
|
+
*
|
|
3271
|
+
* // .foo{width:3px;.foo{width:3px}}
|
|
3272
|
+
* ```
|
|
3273
|
+
*/
|
|
3274
|
+
Rule?: GenericVisitorAstNodeSyncHandlerMap<AstRule>;
|
|
3275
|
+
|
|
3276
|
+
KeyframesRule?: GenericVisitorAstNodeSyncHandlerMap<AstKeyframesRule>;
|
|
3277
|
+
|
|
3278
|
+
KeyframesAtRule?: GenericVisitorAstNodeSyncHandlerMap<AstKeyframesAtRule>;
|
|
3279
|
+
|
|
3280
|
+
/**
|
|
3281
|
+
* value visitor
|
|
3282
|
+
*/
|
|
3283
|
+
Value?: GenericVisitorAstNodeSyncHandlerMap<Token>;
|
|
3284
|
+
|
|
3285
|
+
/**
|
|
3286
|
+
* generic token visitor. the key name is of type keyof EnumToken.
|
|
3287
|
+
* generic tokens are called for every token of the specified type.
|
|
3288
|
+
*
|
|
3289
|
+
* ```ts
|
|
3290
|
+
*
|
|
3291
|
+
* import {transform, parse, parseDeclarations} from "@tbela99/css-parser";
|
|
3292
|
+
*
|
|
3293
|
+
* const options: ParserOptions = {
|
|
3294
|
+
*
|
|
3295
|
+
* inlineCssVariables: true,
|
|
3296
|
+
* visitor: {
|
|
3297
|
+
*
|
|
3298
|
+
* // Stylesheet node visitor
|
|
3299
|
+
* StyleSheetNodeType: async (node) => {
|
|
3300
|
+
*
|
|
3301
|
+
* // insert a new rule
|
|
3302
|
+
* node.chi.unshift(await parse('html {--base-color: pink}').then(result => result.ast.chi[0]))
|
|
3303
|
+
* },
|
|
3304
|
+
* ColorTokenType: (node) => {
|
|
3305
|
+
*
|
|
3306
|
+
* // dump all color tokens
|
|
3307
|
+
* // console.debug(node);
|
|
3308
|
+
* },
|
|
3309
|
+
* FunctionTokenType: (node) => {
|
|
3310
|
+
*
|
|
3311
|
+
* // dump all function tokens
|
|
3312
|
+
* // console.debug(node);
|
|
3313
|
+
* },
|
|
3314
|
+
* DeclarationNodeType: (node) => {
|
|
3315
|
+
*
|
|
3316
|
+
* // dump all declaration nodes
|
|
3317
|
+
* // console.debug(node);
|
|
3318
|
+
* }
|
|
3319
|
+
* }
|
|
3320
|
+
* };
|
|
3321
|
+
*
|
|
3322
|
+
* const css = `
|
|
3323
|
+
*
|
|
3324
|
+
* body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
|
|
3325
|
+
* `;
|
|
3326
|
+
*
|
|
3327
|
+
* console.debug(await transform(css, options));
|
|
3328
|
+
*
|
|
3329
|
+
* // body {color:#f3fff0}
|
|
3330
|
+
* ```
|
|
3331
|
+
*/
|
|
3332
|
+
[key: keyof typeof EnumToken]: GenericVisitorAstNodeSyncHandlerMap<Token> | GenericVisitorAstNodeSyncHandlerMap<AstNode>;
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3335
|
+
|
|
3070
3336
|
export declare type GenericVisitorHandler<T> = (
|
|
3071
3337
|
node: T,
|
|
3072
3338
|
parent?: AstNode | Token,
|
|
3073
3339
|
root?: AstNode | Token,
|
|
3074
|
-
) =>
|
|
3340
|
+
) => GenericVisitorSyncResult<T> | GenericVisitorAsyncResult<T>;
|
|
3341
|
+
|
|
3075
3342
|
export declare type GenericVisitorAstNodeHandlerMap<T> =
|
|
3076
3343
|
| Record<string, GenericVisitorHandler<T>>
|
|
3077
3344
|
| GenericVisitorHandler<T>
|
|
@@ -3080,6 +3347,11 @@ export declare type GenericVisitorAstNodeHandlerMap<T> =
|
|
|
3080
3347
|
|
|
3081
3348
|
export declare type ValueVisitorHandler = GenericVisitorHandler<Token>;
|
|
3082
3349
|
|
|
3350
|
+
/**
|
|
3351
|
+
* Declaration visitor handler
|
|
3352
|
+
*/
|
|
3353
|
+
export declare type DeclarationVisitorHandler = GenericVisitorHandler<AstDeclaration>;
|
|
3354
|
+
|
|
3083
3355
|
/**
|
|
3084
3356
|
* Declaration visitor handler
|
|
3085
3357
|
*/
|
|
@@ -3088,6 +3360,15 @@ export declare type DeclarationVisitorHandler = GenericVisitorHandler<AstDeclara
|
|
|
3088
3360
|
* Rule visitor handler
|
|
3089
3361
|
*/
|
|
3090
3362
|
export declare type RuleVisitorHandler = GenericVisitorHandler<AstRule>;
|
|
3363
|
+
/**
|
|
3364
|
+
* Rule visitor handler
|
|
3365
|
+
*/
|
|
3366
|
+
export declare type RuleVisitorHandler = GenericVisitorHandler<AstRule>;
|
|
3367
|
+
|
|
3368
|
+
/**
|
|
3369
|
+
* AtRule visitor handler
|
|
3370
|
+
*/
|
|
3371
|
+
export declare type AtRuleVisitorHandler = GenericVisitorHandler<AstAtRule>;
|
|
3091
3372
|
|
|
3092
3373
|
/**
|
|
3093
3374
|
* AtRule visitor handler
|
|
@@ -3351,17 +3632,41 @@ export declare interface VisitorNodeMap {
|
|
|
3351
3632
|
* @internal
|
|
3352
3633
|
*/
|
|
3353
3634
|
declare class SourceMap {
|
|
3354
|
-
#private;
|
|
3355
3635
|
/**
|
|
3356
3636
|
* Last location
|
|
3357
3637
|
*/
|
|
3358
|
-
lastLocation
|
|
3638
|
+
private lastLocation;
|
|
3639
|
+
/**
|
|
3640
|
+
* Version
|
|
3641
|
+
* @private
|
|
3642
|
+
*/
|
|
3643
|
+
private version;
|
|
3644
|
+
/**
|
|
3645
|
+
* Sources map
|
|
3646
|
+
* @private
|
|
3647
|
+
*/
|
|
3648
|
+
private sourcesMap;
|
|
3649
|
+
/**
|
|
3650
|
+
* Sources
|
|
3651
|
+
* @private
|
|
3652
|
+
*/
|
|
3653
|
+
private sources;
|
|
3654
|
+
/**
|
|
3655
|
+
* Map
|
|
3656
|
+
* @private
|
|
3657
|
+
*/
|
|
3658
|
+
private map;
|
|
3659
|
+
/**
|
|
3660
|
+
* Line
|
|
3661
|
+
* @private
|
|
3662
|
+
*/
|
|
3663
|
+
private line;
|
|
3359
3664
|
/**
|
|
3360
3665
|
* Add a location
|
|
3361
3666
|
* @param source
|
|
3362
3667
|
* @param original
|
|
3363
3668
|
*/
|
|
3364
|
-
add(
|
|
3669
|
+
add(newLine: number, newColumn: number, srcId: number, ln: number, col: number, sourceFileName: string, sourceContent: string): void;
|
|
3365
3670
|
/**
|
|
3366
3671
|
* Convert to URL encoded string
|
|
3367
3672
|
*/
|
|
@@ -3372,6 +3677,122 @@ declare class SourceMap {
|
|
|
3372
3677
|
toJSON(): SourceMapObject;
|
|
3373
3678
|
}
|
|
3374
3679
|
|
|
3680
|
+
/**
|
|
3681
|
+
* Compute line and column of the offset
|
|
3682
|
+
*/
|
|
3683
|
+
declare class LineMap {
|
|
3684
|
+
/**
|
|
3685
|
+
* line starts
|
|
3686
|
+
*/
|
|
3687
|
+
readonly lineStarts: number[];
|
|
3688
|
+
/**
|
|
3689
|
+
* Constructor
|
|
3690
|
+
* @param lines
|
|
3691
|
+
*/
|
|
3692
|
+
constructor(lines: number[]);
|
|
3693
|
+
/**
|
|
3694
|
+
* Compute line and column of the offset
|
|
3695
|
+
* @param offset
|
|
3696
|
+
* @returns
|
|
3697
|
+
*/
|
|
3698
|
+
getOffsets(offset: number): [number, number];
|
|
3699
|
+
/**
|
|
3700
|
+
* search the greatest index of the value less than or equal to offset
|
|
3701
|
+
* @param offset
|
|
3702
|
+
* @returns
|
|
3703
|
+
*/
|
|
3704
|
+
search(offset: number): number;
|
|
3705
|
+
/**
|
|
3706
|
+
* get line starts
|
|
3707
|
+
* @returns
|
|
3708
|
+
*/
|
|
3709
|
+
getLineStarts(): number[];
|
|
3710
|
+
/**
|
|
3711
|
+
* add line start
|
|
3712
|
+
*/
|
|
3713
|
+
addLineStart(lineStart: number): void;
|
|
3714
|
+
/**
|
|
3715
|
+
* clone the linemap
|
|
3716
|
+
* @returns
|
|
3717
|
+
*/
|
|
3718
|
+
clone(): LineMap;
|
|
3719
|
+
}
|
|
3720
|
+
|
|
3721
|
+
/**
|
|
3722
|
+
* Source file helper class
|
|
3723
|
+
*/
|
|
3724
|
+
declare class SourceFile {
|
|
3725
|
+
/**
|
|
3726
|
+
* Source file ID
|
|
3727
|
+
*/
|
|
3728
|
+
readonly id: number;
|
|
3729
|
+
/**
|
|
3730
|
+
* Source file path
|
|
3731
|
+
*/
|
|
3732
|
+
readonly file: string | null;
|
|
3733
|
+
/**
|
|
3734
|
+
* Line map
|
|
3735
|
+
*/
|
|
3736
|
+
readonly lineStarts: LineMap;
|
|
3737
|
+
/**
|
|
3738
|
+
* Source file content
|
|
3739
|
+
*/
|
|
3740
|
+
private content;
|
|
3741
|
+
/**
|
|
3742
|
+
* Constructor
|
|
3743
|
+
* @param id
|
|
3744
|
+
* @param content
|
|
3745
|
+
* @param lines
|
|
3746
|
+
* @param file
|
|
3747
|
+
*/
|
|
3748
|
+
constructor(content: string, lines: number[], file?: string | null);
|
|
3749
|
+
/**
|
|
3750
|
+
* Update source content
|
|
3751
|
+
* @param content
|
|
3752
|
+
* @param lines
|
|
3753
|
+
*/
|
|
3754
|
+
append(content: string): void;
|
|
3755
|
+
/**
|
|
3756
|
+
* get file name
|
|
3757
|
+
* @returns
|
|
3758
|
+
*/
|
|
3759
|
+
getFileName(): string | null;
|
|
3760
|
+
/**
|
|
3761
|
+
* get content
|
|
3762
|
+
* @returns
|
|
3763
|
+
*/
|
|
3764
|
+
getContent(): string;
|
|
3765
|
+
/**
|
|
3766
|
+
* get text
|
|
3767
|
+
* @param start
|
|
3768
|
+
* @param length
|
|
3769
|
+
* @returns
|
|
3770
|
+
*/
|
|
3771
|
+
getText(start: number, length: number): string;
|
|
3772
|
+
/**
|
|
3773
|
+
* Compute line and column of the offset
|
|
3774
|
+
* @param offset
|
|
3775
|
+
* @returns
|
|
3776
|
+
*/
|
|
3777
|
+
getOffsets(offset: number): [number, number];
|
|
3778
|
+
/**
|
|
3779
|
+
* get source location
|
|
3780
|
+
* @param offset
|
|
3781
|
+
* @returns
|
|
3782
|
+
*/
|
|
3783
|
+
getSourceLocation(offset: number): [string | null, number, number];
|
|
3784
|
+
/**
|
|
3785
|
+
* get line starts
|
|
3786
|
+
* @returns
|
|
3787
|
+
*/
|
|
3788
|
+
getLineStarts(): number[];
|
|
3789
|
+
/**
|
|
3790
|
+
* add line start
|
|
3791
|
+
* @param lineStart
|
|
3792
|
+
*/
|
|
3793
|
+
addLineStart(lineStart: number): void;
|
|
3794
|
+
}
|
|
3795
|
+
|
|
3375
3796
|
export declare interface PropertyListOptions {
|
|
3376
3797
|
|
|
3377
3798
|
removeDuplicateDeclarations?: boolean | string | string[];
|
|
@@ -3383,11 +3804,6 @@ export declare interface PropertyListOptions {
|
|
|
3383
3804
|
*/
|
|
3384
3805
|
export declare interface ParseInfo$1 {
|
|
3385
3806
|
|
|
3386
|
-
/**
|
|
3387
|
-
* source file or url
|
|
3388
|
-
*/
|
|
3389
|
-
src: string;
|
|
3390
|
-
|
|
3391
3807
|
/**
|
|
3392
3808
|
* read buffer
|
|
3393
3809
|
*/
|
|
@@ -3398,18 +3814,19 @@ export declare interface ParseInfo$1 {
|
|
|
3398
3814
|
stream: string;
|
|
3399
3815
|
|
|
3400
3816
|
/**
|
|
3401
|
-
*
|
|
3817
|
+
* Source file
|
|
3402
3818
|
*/
|
|
3403
|
-
|
|
3819
|
+
source: SourceFile;
|
|
3404
3820
|
|
|
3405
3821
|
/**
|
|
3406
3822
|
* last token position
|
|
3407
3823
|
*/
|
|
3408
|
-
position:
|
|
3824
|
+
position: number;
|
|
3825
|
+
|
|
3409
3826
|
/**
|
|
3410
3827
|
* current parsing position
|
|
3411
3828
|
*/
|
|
3412
|
-
currentPosition:
|
|
3829
|
+
currentPosition: number;
|
|
3413
3830
|
|
|
3414
3831
|
/**
|
|
3415
3832
|
* offset
|
|
@@ -4221,7 +4638,7 @@ export declare interface ErrorDescription$1 {
|
|
|
4221
4638
|
/**
|
|
4222
4639
|
* Error location
|
|
4223
4640
|
*/
|
|
4224
|
-
location?:
|
|
4641
|
+
location?: [string | null, number, number];
|
|
4225
4642
|
/**
|
|
4226
4643
|
* Error object
|
|
4227
4644
|
*/
|
|
@@ -4387,22 +4804,117 @@ export declare type LoadResult =
|
|
|
4387
4804
|
/**
|
|
4388
4805
|
* CSS module parser options
|
|
4389
4806
|
*/
|
|
4390
|
-
export declare interface
|
|
4807
|
+
export declare interface ModuleSyncOptions {
|
|
4391
4808
|
/**
|
|
4392
4809
|
* Use local scope vs global scope
|
|
4393
4810
|
*/
|
|
4394
|
-
scoped?: boolean | ModuleScopeEnumOptions;
|
|
4811
|
+
scoped?: boolean | ModuleScopeEnumOptions;
|
|
4812
|
+
|
|
4813
|
+
/**
|
|
4814
|
+
* 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
|
|
4815
|
+
*/
|
|
4816
|
+
filePath?: string;
|
|
4817
|
+
|
|
4818
|
+
/**
|
|
4819
|
+
* Generated scope hash length. the default is 5
|
|
4820
|
+
*/
|
|
4821
|
+
hashLength?: number;
|
|
4822
|
+
|
|
4823
|
+
/**
|
|
4824
|
+
* The pattern used to generate scoped names. the supported placeholders are:
|
|
4825
|
+
* - name: the file base name without the extension
|
|
4826
|
+
* - hash: the file path hash
|
|
4827
|
+
* - local: the local name
|
|
4828
|
+
* - path: the file path
|
|
4829
|
+
* - folder: the folder name
|
|
4830
|
+
* - ext: the file extension
|
|
4831
|
+
*
|
|
4832
|
+
* the pattern can optionally have a maximum number of characters:
|
|
4833
|
+
* ```
|
|
4834
|
+
* pattern: '[local:2]-[hash:5]'
|
|
4835
|
+
* ```
|
|
4836
|
+
* the hash pattern can take an algorithm, a maximum number of characters or both:
|
|
4837
|
+
* ```
|
|
4838
|
+
* pattern: '[local]-[hash:base64:5]'
|
|
4839
|
+
* ```
|
|
4840
|
+
* or
|
|
4841
|
+
* ```
|
|
4842
|
+
* pattern: '[local]-[hash:5]'
|
|
4843
|
+
* ```
|
|
4844
|
+
* or
|
|
4845
|
+
* ```
|
|
4846
|
+
* pattern: '[local]-[hash:sha1]'
|
|
4847
|
+
* ```
|
|
4848
|
+
*
|
|
4849
|
+
* supported hash algorithms are:
|
|
4850
|
+
* - base64
|
|
4851
|
+
* - hex
|
|
4852
|
+
* - base64url
|
|
4853
|
+
*
|
|
4854
|
+
* ```typescript
|
|
4855
|
+
*
|
|
4856
|
+
* import {transform, ModuleCaseTransformEnum} from '@tbela99/css-parser';
|
|
4857
|
+
* import type {TransformResult} from '@tbela99/css-parser';
|
|
4858
|
+
* css = `
|
|
4859
|
+
* :local(.className) {
|
|
4860
|
+
* background: red;
|
|
4861
|
+
* color: yellow;
|
|
4862
|
+
* }
|
|
4863
|
+
*
|
|
4864
|
+
* :local(.subClass) {
|
|
4865
|
+
* composes: className;
|
|
4866
|
+
* background: blue;
|
|
4867
|
+
* }
|
|
4868
|
+
* `;
|
|
4869
|
+
*
|
|
4870
|
+
* let result: TransformResult = await transform(css, {
|
|
4871
|
+
*
|
|
4872
|
+
* beautify:true,
|
|
4873
|
+
* module: {
|
|
4874
|
+
* pattern: '[local]-[hash:sha256]'
|
|
4875
|
+
* }
|
|
4876
|
+
*
|
|
4877
|
+
* });
|
|
4878
|
+
*
|
|
4879
|
+
* console.log(result.code);
|
|
4880
|
+
* ```
|
|
4881
|
+
* generated css
|
|
4882
|
+
*
|
|
4883
|
+
* ```css
|
|
4884
|
+
* .className-b629f {
|
|
4885
|
+
* background: red;
|
|
4886
|
+
* color: #ff0
|
|
4887
|
+
* }
|
|
4888
|
+
* .subClass-a0c35 {
|
|
4889
|
+
* background: blue
|
|
4890
|
+
* }
|
|
4891
|
+
* ```
|
|
4892
|
+
*/
|
|
4893
|
+
pattern?: string;
|
|
4395
4894
|
|
|
4396
4895
|
/**
|
|
4397
|
-
*
|
|
4896
|
+
* optional. function change the case of the scoped name and the class mapping
|
|
4897
|
+
*
|
|
4898
|
+
* - {@link ModuleCaseTransformEnum.IgnoreCase}: do not change case
|
|
4899
|
+
* - {@link ModuleCaseTransformEnum.CamelCase}: camelCase {@link ParseResult.mapping} key name
|
|
4900
|
+
* - {@link ModuleCaseTransformEnum.CamelCaseOnly}: camelCase {@link ParseResult.mapping} key name and the scoped class name
|
|
4901
|
+
* - {@link ModuleCaseTransformEnum.DashCase}: dashCase {@link ParseResult.mapping} key name
|
|
4902
|
+
* - {@link ModuleCaseTransformEnum.DashCaseOnly}: dashCase {@link ParseResult.mapping} key name and the scoped class name
|
|
4903
|
+
*
|
|
4398
4904
|
*/
|
|
4399
|
-
|
|
4905
|
+
naming?: ModuleCaseTransformEnum;
|
|
4400
4906
|
|
|
4401
4907
|
/**
|
|
4402
|
-
*
|
|
4908
|
+
* Function to generate scoped name
|
|
4909
|
+
* @param localName
|
|
4910
|
+
* @param filePath
|
|
4911
|
+
* @param pattern see {@link ModuleSyncOptions.pattern}
|
|
4912
|
+
* @param hashLength
|
|
4403
4913
|
*/
|
|
4404
|
-
hashLength?: number;
|
|
4914
|
+
generateScopedName?: (localName: string, filePath: string, pattern: string, hashLength?: number) => string;
|
|
4915
|
+
}
|
|
4405
4916
|
|
|
4917
|
+
export declare interface ModuleAsyncOptions extends ModuleSyncOptions {
|
|
4406
4918
|
/**
|
|
4407
4919
|
* The pattern used to generate scoped names. the supported placeholders are:
|
|
4408
4920
|
* - name: the file base name without the extension
|
|
@@ -4479,23 +4991,11 @@ export declare interface ModuleOptions {
|
|
|
4479
4991
|
*/
|
|
4480
4992
|
pattern?: string;
|
|
4481
4993
|
|
|
4482
|
-
/**
|
|
4483
|
-
* optional. function change the case of the scoped name and the class mapping
|
|
4484
|
-
*
|
|
4485
|
-
* - {@link ModuleCaseTransformEnum.IgnoreCase}: do not change case
|
|
4486
|
-
* - {@link ModuleCaseTransformEnum.CamelCase}: camelCase {@link ParseResult.mapping} key name
|
|
4487
|
-
* - {@link ModuleCaseTransformEnum.CamelCaseOnly}: camelCase {@link ParseResult.mapping} key name and the scoped class name
|
|
4488
|
-
* - {@link ModuleCaseTransformEnum.DashCase}: dashCase {@link ParseResult.mapping} key name
|
|
4489
|
-
* - {@link ModuleCaseTransformEnum.DashCaseOnly}: dashCase {@link ParseResult.mapping} key name and the scoped class name
|
|
4490
|
-
*
|
|
4491
|
-
*/
|
|
4492
|
-
naming?: ModuleCaseTransformEnum;
|
|
4493
|
-
|
|
4494
4994
|
/**
|
|
4495
4995
|
* Function to generate scoped name
|
|
4496
4996
|
* @param localName
|
|
4497
4997
|
* @param filePath
|
|
4498
|
-
* @param pattern see {@link
|
|
4998
|
+
* @param pattern see {@link ModuleSyncOptions.pattern}
|
|
4499
4999
|
* @param hashLength
|
|
4500
5000
|
*/
|
|
4501
5001
|
generateScopedName?: (
|
|
@@ -4521,6 +5021,15 @@ export declare interface ParseInputFileOptions {
|
|
|
4521
5021
|
asStream?: boolean;
|
|
4522
5022
|
}
|
|
4523
5023
|
|
|
5024
|
+
/**
|
|
5025
|
+
* Input options for string or stream
|
|
5026
|
+
*/
|
|
5027
|
+
export declare interface ParseInputOptions {
|
|
5028
|
+
/**
|
|
5029
|
+
* Input string or stream
|
|
5030
|
+
*/
|
|
5031
|
+
input: string;
|
|
5032
|
+
}
|
|
4524
5033
|
/**
|
|
4525
5034
|
* Input options for string or stream
|
|
4526
5035
|
*/
|
|
@@ -4531,11 +5040,13 @@ export declare interface ParseInputStreamOptions {
|
|
|
4531
5040
|
input: string | ReadableStream<Uint8Array>;
|
|
4532
5041
|
}
|
|
4533
5042
|
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
5043
|
+
export declare interface ParseSourceOptions {
|
|
5044
|
+
sourcesMap?: Map<number, SourceFile>;
|
|
5045
|
+
source?: SourceFile | null;
|
|
5046
|
+
}
|
|
5047
|
+
|
|
5048
|
+
export declare interface ParserSyncOptions
|
|
5049
|
+
extends MinifyOptions, MinifyFeatureOptions, ValidationOptions, PropertyListOptions, ParseSourceOptions {
|
|
4539
5050
|
/**
|
|
4540
5051
|
* Source file to be used for sourcemap
|
|
4541
5052
|
*/
|
|
@@ -4548,10 +5059,6 @@ export declare interface ParserOptions
|
|
|
4548
5059
|
* Remove at-rule charset
|
|
4549
5060
|
*/
|
|
4550
5061
|
removeCharset?: boolean;
|
|
4551
|
-
/**
|
|
4552
|
-
* Resolve import
|
|
4553
|
-
*/
|
|
4554
|
-
resolveImport?: boolean;
|
|
4555
5062
|
/**
|
|
4556
5063
|
* Current working directory
|
|
4557
5064
|
*
|
|
@@ -4568,18 +5075,6 @@ export declare interface ParserOptions
|
|
|
4568
5075
|
*/
|
|
4569
5076
|
expandIfSyntax?: boolean;
|
|
4570
5077
|
|
|
4571
|
-
/**
|
|
4572
|
-
* Custom URL and file loader.
|
|
4573
|
-
* @param url
|
|
4574
|
-
* @param currentDirectory
|
|
4575
|
-
* @param responseType
|
|
4576
|
-
*
|
|
4577
|
-
*/
|
|
4578
|
-
load?: (
|
|
4579
|
-
url: string | { absolute: string; relative: string },
|
|
4580
|
-
currentDirectory: string,
|
|
4581
|
-
responseType?: boolean | ResponseType,
|
|
4582
|
-
) => Promise<string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
4583
5078
|
/**
|
|
4584
5079
|
* Get directory name
|
|
4585
5080
|
* @param path
|
|
@@ -4615,9 +5110,9 @@ export declare interface ParserOptions
|
|
|
4615
5110
|
|
|
4616
5111
|
/**
|
|
4617
5112
|
* Node visitor
|
|
4618
|
-
* {@link
|
|
5113
|
+
* {@link VisitorSyncNodeMap | VisitorSyncNodeMap[]}
|
|
4619
5114
|
*/
|
|
4620
|
-
visitor?:
|
|
5115
|
+
visitor?: VisitorSyncNodeMap | VisitorSyncNodeMap[];
|
|
4621
5116
|
/**
|
|
4622
5117
|
* Abort signal
|
|
4623
5118
|
*
|
|
@@ -4647,7 +5142,7 @@ export declare interface ParserOptions
|
|
|
4647
5142
|
/**
|
|
4648
5143
|
* CSS modules options
|
|
4649
5144
|
*/
|
|
4650
|
-
module?: boolean | ModuleCaseTransformEnum | ModuleScopeEnumOptions |
|
|
5145
|
+
module?: boolean | ModuleCaseTransformEnum | ModuleScopeEnumOptions | ModuleSyncOptions;
|
|
4651
5146
|
|
|
4652
5147
|
/**
|
|
4653
5148
|
* Tokenizing info
|
|
@@ -4656,6 +5151,35 @@ export declare interface ParserOptions
|
|
|
4656
5151
|
parseInfo?: ParseInfo;
|
|
4657
5152
|
}
|
|
4658
5153
|
|
|
5154
|
+
/**
|
|
5155
|
+
* Parser options
|
|
5156
|
+
*/
|
|
5157
|
+
export declare interface ParserOptions extends ParserSyncOptions, ModuleAsyncOptions {
|
|
5158
|
+
/**
|
|
5159
|
+
* Resolve import
|
|
5160
|
+
*/
|
|
5161
|
+
resolveImport?: boolean;
|
|
5162
|
+
|
|
5163
|
+
/**
|
|
5164
|
+
* Custom URL and file loader.
|
|
5165
|
+
* @param url
|
|
5166
|
+
* @param currentDirectory
|
|
5167
|
+
* @param responseType
|
|
5168
|
+
*
|
|
5169
|
+
*/
|
|
5170
|
+
load?: (
|
|
5171
|
+
url: string | { absolute: string; relative: string },
|
|
5172
|
+
currentDirectory?: string,
|
|
5173
|
+
responseType?: boolean | ResponseType,
|
|
5174
|
+
) => Promise<string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
5175
|
+
|
|
5176
|
+
/**
|
|
5177
|
+
* Node visitor
|
|
5178
|
+
* {@link VisitorNodeMap | VisitorNodeMap[]}
|
|
5179
|
+
*/
|
|
5180
|
+
visitor?: VisitorNodeMap | VisitorNodeMap[];
|
|
5181
|
+
}
|
|
5182
|
+
|
|
4659
5183
|
/**
|
|
4660
5184
|
* Minify feature options
|
|
4661
5185
|
*
|
|
@@ -4807,8 +5331,19 @@ export declare interface RenderOptions {
|
|
|
4807
5331
|
* @internal
|
|
4808
5332
|
*/
|
|
4809
5333
|
resolve?: (url: string, currentUrl: string, currentWorkingDirectory?: string) => ResolvedPath;
|
|
5334
|
+
|
|
5335
|
+
/**
|
|
5336
|
+
* Source map
|
|
5337
|
+
* @internal
|
|
5338
|
+
*/
|
|
5339
|
+
sourcesMap?: Map<number, SourceFile>;
|
|
4810
5340
|
}
|
|
4811
5341
|
|
|
5342
|
+
/**
|
|
5343
|
+
* Transform options
|
|
5344
|
+
*/
|
|
5345
|
+
export declare interface TransformSyncOptions extends ParserSyncOptions, RenderOptions {}
|
|
5346
|
+
|
|
4812
5347
|
/**
|
|
4813
5348
|
* Transform options
|
|
4814
5349
|
*/
|
|
@@ -5077,7 +5612,7 @@ export declare interface SourceMapObject {
|
|
|
5077
5612
|
/**
|
|
5078
5613
|
* Source files
|
|
5079
5614
|
*/
|
|
5080
|
-
sources?: string
|
|
5615
|
+
sources?: Array<string | null>;
|
|
5081
5616
|
/**
|
|
5082
5617
|
* Source files content
|
|
5083
5618
|
*/
|
|
@@ -5328,7 +5863,7 @@ button {
|
|
|
5328
5863
|
* @param matcher
|
|
5329
5864
|
* @returns
|
|
5330
5865
|
*/
|
|
5331
|
-
declare function find(ast: AstNode$1, matcher: (node: AstNode$1) => boolean): AstNode$1 | null;
|
|
5866
|
+
declare function find(ast: AstNode$1, matcher: (node: AstNode$1, parent?: AstNode$1 | null) => boolean): AstNode$1 | null;
|
|
5332
5867
|
/**
|
|
5333
5868
|
* Search the ast sub-tree by checking each node's value token and return the first match
|
|
5334
5869
|
*
|
|
@@ -5398,7 +5933,7 @@ button-small {
|
|
|
5398
5933
|
* @param matcher
|
|
5399
5934
|
* @returns
|
|
5400
5935
|
*/
|
|
5401
|
-
declare function findAll(ast: AstNode$1, matcher: (node: AstNode$1) => boolean): AstNode$1[];
|
|
5936
|
+
declare function findAll(ast: AstNode$1, matcher: (node: AstNode$1, parent?: AstNode$1 | null) => boolean): AstNode$1[];
|
|
5402
5937
|
/**
|
|
5403
5938
|
* Search the ast sub-tree and return the last match.
|
|
5404
5939
|
*
|
|
@@ -5429,7 +5964,7 @@ button {
|
|
|
5429
5964
|
* @param matcher
|
|
5430
5965
|
* @returns
|
|
5431
5966
|
*/
|
|
5432
|
-
declare function findLast(ast: AstNode$1, matcher: (node: AstNode$1) => boolean): AstNode$1 | null;
|
|
5967
|
+
declare function findLast(ast: AstNode$1, matcher: (node: AstNode$1, parent?: AstNode$1 | null) => boolean): AstNode$1 | null;
|
|
5433
5968
|
|
|
5434
5969
|
/**
|
|
5435
5970
|
*
|
|
@@ -5530,6 +6065,74 @@ declare function render(data: AstNode$1, options?: RenderOptions, mapping?: {
|
|
|
5530
6065
|
* ```
|
|
5531
6066
|
*/
|
|
5532
6067
|
declare const parseFile: (file: string, options?: ParserOptions, asStream?: boolean) => Promise<ParseResult>;
|
|
6068
|
+
/**
|
|
6069
|
+
* Parse css string
|
|
6070
|
+
* @param stream
|
|
6071
|
+
* @param options
|
|
6072
|
+
*
|
|
6073
|
+
* Example:
|
|
6074
|
+
*
|
|
6075
|
+
* ```ts
|
|
6076
|
+
*
|
|
6077
|
+
* import {parse} from '@tbela99/css-parser';
|
|
6078
|
+
*
|
|
6079
|
+
* // css string
|
|
6080
|
+
* let result = await parse(css, {nestingRules: true});
|
|
6081
|
+
* console.log(result.ast);
|
|
6082
|
+
* ```
|
|
6083
|
+
*
|
|
6084
|
+
*/
|
|
6085
|
+
declare function parseSync(stream: string, options?: ParserSyncOptions): ParseResult;
|
|
6086
|
+
/**
|
|
6087
|
+
* Parse css string
|
|
6088
|
+
* @param stream
|
|
6089
|
+
* @param options
|
|
6090
|
+
*
|
|
6091
|
+
* Parsing a string
|
|
6092
|
+
*
|
|
6093
|
+
* ```ts
|
|
6094
|
+
*
|
|
6095
|
+
* import {parse} from '@tbela99/css-parser';
|
|
6096
|
+
*
|
|
6097
|
+
* // css string
|
|
6098
|
+
* let result = await parse({input: css, nestingRules: true});
|
|
6099
|
+
* console.log(result.ast);
|
|
6100
|
+
* ```
|
|
6101
|
+
*
|
|
6102
|
+
*/
|
|
6103
|
+
declare function parseSync(options: ParseInputOptions & ParserSyncOptions): ParseResult;
|
|
6104
|
+
/**
|
|
6105
|
+
* Transform css
|
|
6106
|
+
* @param css
|
|
6107
|
+
* @param options
|
|
6108
|
+
*
|
|
6109
|
+
*
|
|
6110
|
+
* ```ts
|
|
6111
|
+
*
|
|
6112
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6113
|
+
*
|
|
6114
|
+
* // css string
|
|
6115
|
+
* const result = await transform(css, {beautify: true});
|
|
6116
|
+
* console.log(result.code);
|
|
6117
|
+
* ```
|
|
6118
|
+
*
|
|
6119
|
+
*/
|
|
6120
|
+
declare function transformSync(css: string, options?: TransformSyncOptions): TransformResult;
|
|
6121
|
+
/**
|
|
6122
|
+
* Transform css
|
|
6123
|
+
* @param options
|
|
6124
|
+
*
|
|
6125
|
+
* ```ts
|
|
6126
|
+
*
|
|
6127
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6128
|
+
*
|
|
6129
|
+
* // css string
|
|
6130
|
+
* const result = await transform({input: css, beautify: true});
|
|
6131
|
+
* console.log(result.code);
|
|
6132
|
+
* ```
|
|
6133
|
+
*
|
|
6134
|
+
*/
|
|
6135
|
+
declare function transformSync(options: ParseInputOptions & TransformSyncOptions): TransformResult;
|
|
5533
6136
|
/**
|
|
5534
6137
|
* Parse css
|
|
5535
6138
|
* @param stream
|
|
@@ -5676,9 +6279,137 @@ declare function parse(options: ParseInputStreamOptions & ParserOptions): Promis
|
|
|
5676
6279
|
* ```
|
|
5677
6280
|
*/
|
|
5678
6281
|
declare const transformFile: (file: string, options?: TransformOptions, asStream?: boolean) => Promise<TransformResult>;
|
|
5679
|
-
|
|
5680
|
-
|
|
6282
|
+
/**
|
|
6283
|
+
* Transform css
|
|
6284
|
+
* @param css
|
|
6285
|
+
* @param options
|
|
6286
|
+
*
|
|
6287
|
+
* Parsing a string
|
|
6288
|
+
*
|
|
6289
|
+
* ```ts
|
|
6290
|
+
*
|
|
6291
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6292
|
+
*
|
|
6293
|
+
* // css string
|
|
6294
|
+
* const result = await transform(css);
|
|
6295
|
+
* console.log(result.code);
|
|
6296
|
+
* ```
|
|
6297
|
+
*
|
|
6298
|
+
* Parsing a Readable stream
|
|
6299
|
+
*
|
|
6300
|
+
* ```ts
|
|
6301
|
+
*
|
|
6302
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6303
|
+
* import {Readable} from "node:stream";
|
|
6304
|
+
*
|
|
6305
|
+
* // usage: node index.ts < styles.css or cat styles.css | node index.ts
|
|
6306
|
+
*
|
|
6307
|
+
* const readableStream = Readable.toWeb(process.stdin);
|
|
6308
|
+
* const result = await transform(readableStream, {beautify: true});
|
|
6309
|
+
*
|
|
6310
|
+
* console.log(result.code);
|
|
6311
|
+
* ```
|
|
6312
|
+
*
|
|
6313
|
+
* Example using fetch
|
|
6314
|
+
*
|
|
6315
|
+
* ```ts
|
|
6316
|
+
*
|
|
6317
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6318
|
+
*
|
|
6319
|
+
* const response = await fetch('https://docs.deno.com/styles.css');
|
|
6320
|
+
* result = await transform(response.body, {beautify: true});
|
|
6321
|
+
*
|
|
6322
|
+
* console.log(result.code);
|
|
6323
|
+
* ```
|
|
6324
|
+
*/
|
|
6325
|
+
declare function transform(css: string | ReadableStream<Uint8Array>, options?: TransformOptions): Promise<TransformResult>;
|
|
6326
|
+
/**
|
|
6327
|
+
* Transform css
|
|
6328
|
+
* @param css
|
|
6329
|
+
* @param options
|
|
6330
|
+
*
|
|
6331
|
+
* Parsing a string
|
|
6332
|
+
*
|
|
6333
|
+
* ```ts
|
|
6334
|
+
*
|
|
6335
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6336
|
+
*
|
|
6337
|
+
* // css string
|
|
6338
|
+
* const result = await transform({input: css});
|
|
6339
|
+
* console.log(result.code);
|
|
6340
|
+
* ```
|
|
6341
|
+
*
|
|
6342
|
+
* Parsing a Readable stream
|
|
6343
|
+
*
|
|
6344
|
+
* ```ts
|
|
6345
|
+
*
|
|
6346
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6347
|
+
* import {Readable} from "node:stream";
|
|
6348
|
+
*
|
|
6349
|
+
* // usage: node index.ts < styles.css or cat styles.css | node index.ts
|
|
6350
|
+
*
|
|
6351
|
+
* const readableStream = Readable.toWeb(process.stdin);
|
|
6352
|
+
* const result = await transform( {input: readableStream, beautify: true});
|
|
6353
|
+
*
|
|
6354
|
+
* console.log(result.code);
|
|
6355
|
+
* ```
|
|
6356
|
+
*
|
|
6357
|
+
* Example using fetch
|
|
6358
|
+
*
|
|
6359
|
+
* ```ts
|
|
6360
|
+
*
|
|
6361
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6362
|
+
*
|
|
6363
|
+
* const response = await fetch('https://docs.deno.com/styles.css');
|
|
6364
|
+
* result = await transform({input: response.body, beautify: true});
|
|
6365
|
+
*
|
|
6366
|
+
* console.log(result.code);
|
|
6367
|
+
* ```
|
|
6368
|
+
*/
|
|
5681
6369
|
declare function transform(options: ParseInputStreamOptions & TransformOptions): Promise<TransformResult>;
|
|
6370
|
+
/**
|
|
6371
|
+
* Transform css
|
|
6372
|
+
* @param css
|
|
6373
|
+
* @param options
|
|
6374
|
+
*
|
|
6375
|
+
* Parsing a string
|
|
6376
|
+
*
|
|
6377
|
+
* ```ts
|
|
6378
|
+
*
|
|
6379
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6380
|
+
*
|
|
6381
|
+
* // css string
|
|
6382
|
+
* const result = await transform({input: css});
|
|
6383
|
+
* console.log(result.code);
|
|
6384
|
+
* ```
|
|
6385
|
+
*
|
|
6386
|
+
* Parsing a Readable stream
|
|
6387
|
+
*
|
|
6388
|
+
* ```ts
|
|
6389
|
+
*
|
|
6390
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6391
|
+
* import {Readable} from "node:stream";
|
|
6392
|
+
*
|
|
6393
|
+
* // usage: node index.ts < styles.css or cat styles.css | node index.ts
|
|
6394
|
+
*
|
|
6395
|
+
* const readableStream = Readable.toWeb(process.stdin);
|
|
6396
|
+
* const result = await transform( {input: readableStream, beautify: true});
|
|
6397
|
+
*
|
|
6398
|
+
* console.log(result.code);
|
|
6399
|
+
* ```
|
|
6400
|
+
*
|
|
6401
|
+
* Example using fetch
|
|
6402
|
+
*
|
|
6403
|
+
* ```ts
|
|
6404
|
+
*
|
|
6405
|
+
* import {transform} from '@tbela99/css-parser';
|
|
6406
|
+
*
|
|
6407
|
+
* result = await transform({file: 'https://docs.deno.com/styles.css', beautify: true});
|
|
6408
|
+
*
|
|
6409
|
+
* console.log(result.code);
|
|
6410
|
+
* ```
|
|
6411
|
+
*/
|
|
6412
|
+
declare function transform(options: ParseInputFileOptions & TransformOptions): Promise<TransformResult>;
|
|
5682
6413
|
|
|
5683
|
-
export { ColorType$1 as ColorType, EnumAstNodeStatus$1 as EnumAstNodeStatus, EnumToken, FeatureWalkMode, ModuleCaseTransformEnum, ModuleScopeEnumOptions, ResponseType$1 as ResponseType, SourceMap, ValidationLevel, WalkerEvent, WalkerOptionEnum, cloneNode, convertColor, dirname, expand, find, findAll, findByValue, findLast, isOkLabClose, load, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, render, renderValue as renderToken, replaceNodeOrValue, resolve, transform, transformFile, walk, walkValues };
|
|
5684
|
-
export type { AddToken, AndToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyFrameRule, AstKeyframesAtRule, AstKeyframesRule, AstNode$1 as AstNode, AstNodeStatus, 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, Context, CssVariableImportTokenType$1 as CssVariableImportTokenType, CssVariableMapTokenType, CssVariableToken$1 as CssVariableToken, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, DoubleColonToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription$1 as ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionDefToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorHandler, GenericVisitorResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, IfConditionToken, IfElseConditionToken, ImportantToken, IncludeMatchToken, InvalidAttrToken, InvalidClassSelectorToken, InvalidMediaQueryToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult,
|
|
6414
|
+
export { ColorType$1 as ColorType, EnumAstNodeStatus$1 as EnumAstNodeStatus, EnumToken, FeatureWalkMode, ModuleCaseTransformEnum, ModuleScopeEnumOptions, ResponseType$1 as ResponseType, SourceMap, ValidationLevel, WalkerEvent, WalkerOptionEnum, cloneNode, convertColor, dirname, expand, find, findAll, findByValue, findLast, isOkLabClose, load, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, parseSync, render, renderValue as renderToken, replaceNodeOrValue, resolve, transform, transformFile, transformSync, walk, walkValues };
|
|
6415
|
+
export type { AddToken, AndToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyFrameRule, AstKeyframesAtRule, AstKeyframesRule, AstNode$1 as AstNode, AstNodeStatus, 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, Context, CssVariableImportTokenType$1 as CssVariableImportTokenType, CssVariableMapTokenType, CssVariableToken$1 as CssVariableToken, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, DoubleColonToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription$1 as 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, InvalidAttrToken, InvalidClassSelectorToken, InvalidMediaQueryToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureOnlyToken, MediaFeatureToken, MediaQueryConditionToken, MediaQueryUnaryFeatureToken, MediaRangeQueryToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, ModuleAsyncOptions, ModuleSyncOptions, MulToken, NameSpaceAttributeToken, NestingSelectorToken, NextSiblingCombinatorToken, NotToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, OrToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo$1 as ParseInfo, ParseInputFileOptions, ParseInputOptions, ParseInputStreamOptions, ParseResult, ParseResultStats, ParseSourceOptions, ParseTokenOptions, ParserOptions, ParserSyncOptions, PercentageToken, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawNodeToken, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SinglePropertyType, SinglePropertyTypeMapping, SourceLocation, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, SupportsQueryConditionToken, SupportsQueryUnaryConditionToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token$1 as Token, TokenSearchResult, TokenizeResult, TransformOptions, TransformResult, TransformSyncOptions, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationMediaFeature, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, ValidationToken$1 as ValidationToken, Value, ValueVisitorHandler, ValueVisitorSyncHandler, VariableScopeInfo, VisitorNodeMap, VisitorSyncNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerValueFilter, WhenElseQueryConditionToken, WhenElseUnaryConditionToken, WhitespaceToken, WrappedValuesToken };
|