@tbela99/css-parser 1.4.8 → 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 +28 -3
- package/dist/index-umd-web.js +12897 -13217
- package/dist/index.cjs +10394 -10716
- package/dist/index.d.ts +816 -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 +8 -0
- package/dist/lib/fs/resolve.js +1 -16
- package/dist/lib/parser/declaration/list.js +6 -1
- package/dist/lib/parser/{linemap.js → linesmap.js} +25 -9
- package/dist/lib/parser/parse.js +1264 -151
- package/dist/lib/parser/source.js +48 -17
- 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 +14 -251
- 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 +76 -43
- 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 +7 -7
- package/dist/lib/syntax/color/color.js +7 -7
- 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/relative-color.js +8 -1
- package/dist/lib/syntax/color/utils/distance.js +2 -2
- package/dist/lib/syntax/constants.js +2 -1
- package/dist/lib/syntax/syntax.js +11 -8
- package/dist/lib/validation/config.json.js +27 -6
- package/dist/lib/validation/match.js +42 -845
- package/dist/node.js +134 -9
- package/dist/web.js +133 -6
- package/llms.txt +73 -0
- package/package.json +13 -16
- package/dist/lib/parser/arena.js +0 -206
package/dist/index.d.ts
CHANGED
|
@@ -2360,6 +2360,14 @@ declare enum ColorType$1 {
|
|
|
2360
2360
|
* color using display-p3-linear
|
|
2361
2361
|
*/
|
|
2362
2362
|
DISPLAY_P3_LINEAR = 26,
|
|
2363
|
+
/**
|
|
2364
|
+
* Contrast color
|
|
2365
|
+
*/
|
|
2366
|
+
CONTRAST_COLOR = 27,
|
|
2367
|
+
/**
|
|
2368
|
+
* color layers
|
|
2369
|
+
*/
|
|
2370
|
+
COLOR_LAYERS = 28,
|
|
2363
2371
|
/**
|
|
2364
2372
|
* alias for rgba
|
|
2365
2373
|
*/
|
|
@@ -2453,40 +2461,22 @@ declare const TOKENS: unique symbol;
|
|
|
2453
2461
|
declare const PARENT: unique symbol;
|
|
2454
2462
|
declare const OPTIMIZED: unique symbol;
|
|
2455
2463
|
|
|
2456
|
-
/**
|
|
2457
|
-
* Position
|
|
2458
|
-
*/
|
|
2459
|
-
export declare interface Position$1 {
|
|
2460
|
-
/**
|
|
2461
|
-
* index in the source
|
|
2462
|
-
*/
|
|
2463
|
-
ind: number;
|
|
2464
|
-
/**
|
|
2465
|
-
* line number
|
|
2466
|
-
*/
|
|
2467
|
-
lin: number;
|
|
2468
|
-
/**
|
|
2469
|
-
* column number
|
|
2470
|
-
*/
|
|
2471
|
-
col: number;
|
|
2472
|
-
}
|
|
2473
|
-
|
|
2474
2464
|
/**
|
|
2475
2465
|
* token or node location
|
|
2476
2466
|
*/
|
|
2477
|
-
export declare interface
|
|
2467
|
+
export declare interface SourceLocation {
|
|
2478
2468
|
/**
|
|
2479
2469
|
* start position
|
|
2480
2470
|
*/
|
|
2481
|
-
sta:
|
|
2471
|
+
sta: number;
|
|
2482
2472
|
/**
|
|
2483
2473
|
* end position
|
|
2484
2474
|
*/
|
|
2485
|
-
end:
|
|
2475
|
+
end: number;
|
|
2486
2476
|
/**
|
|
2487
2477
|
* source file
|
|
2488
2478
|
*/
|
|
2489
|
-
|
|
2479
|
+
srcId: number;
|
|
2490
2480
|
}
|
|
2491
2481
|
|
|
2492
2482
|
/**
|
|
@@ -2501,7 +2491,7 @@ export declare interface BaseToken {
|
|
|
2501
2491
|
* location info
|
|
2502
2492
|
* @private
|
|
2503
2493
|
*/
|
|
2504
|
-
[LOC]?:
|
|
2494
|
+
[LOC]?: SourceLocation;
|
|
2505
2495
|
/**
|
|
2506
2496
|
* parent node
|
|
2507
2497
|
* @private
|
|
@@ -3070,12 +3060,285 @@ declare function walkValues(values: Token$1[], root?: AstNode$1 | Token$1 | null
|
|
|
3070
3060
|
type?: EnumToken | EnumToken[] | ((token: Token$1) => boolean);
|
|
3071
3061
|
}, reverse?: boolean): Generator<WalkAttributesResult>;
|
|
3072
3062
|
|
|
3073
|
-
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
|
+
|
|
3074
3336
|
export declare type GenericVisitorHandler<T> = (
|
|
3075
3337
|
node: T,
|
|
3076
3338
|
parent?: AstNode | Token,
|
|
3077
3339
|
root?: AstNode | Token,
|
|
3078
|
-
) =>
|
|
3340
|
+
) => GenericVisitorSyncResult<T> | GenericVisitorAsyncResult<T>;
|
|
3341
|
+
|
|
3079
3342
|
export declare type GenericVisitorAstNodeHandlerMap<T> =
|
|
3080
3343
|
| Record<string, GenericVisitorHandler<T>>
|
|
3081
3344
|
| GenericVisitorHandler<T>
|
|
@@ -3088,6 +3351,15 @@ export declare type ValueVisitorHandler = GenericVisitorHandler<Token>;
|
|
|
3088
3351
|
* Declaration visitor handler
|
|
3089
3352
|
*/
|
|
3090
3353
|
export declare type DeclarationVisitorHandler = GenericVisitorHandler<AstDeclaration>;
|
|
3354
|
+
|
|
3355
|
+
/**
|
|
3356
|
+
* Declaration visitor handler
|
|
3357
|
+
*/
|
|
3358
|
+
export declare type DeclarationVisitorHandler = GenericVisitorHandler<AstDeclaration>;
|
|
3359
|
+
/**
|
|
3360
|
+
* Rule visitor handler
|
|
3361
|
+
*/
|
|
3362
|
+
export declare type RuleVisitorHandler = GenericVisitorHandler<AstRule>;
|
|
3091
3363
|
/**
|
|
3092
3364
|
* Rule visitor handler
|
|
3093
3365
|
*/
|
|
@@ -3098,6 +3370,11 @@ export declare type RuleVisitorHandler = GenericVisitorHandler<AstRule>;
|
|
|
3098
3370
|
*/
|
|
3099
3371
|
export declare type AtRuleVisitorHandler = GenericVisitorHandler<AstAtRule>;
|
|
3100
3372
|
|
|
3373
|
+
/**
|
|
3374
|
+
* AtRule visitor handler
|
|
3375
|
+
*/
|
|
3376
|
+
export declare type AtRuleVisitorHandler = GenericVisitorHandler<AstAtRule>;
|
|
3377
|
+
|
|
3101
3378
|
/**
|
|
3102
3379
|
* node visitor callback map
|
|
3103
3380
|
*
|
|
@@ -3355,17 +3632,41 @@ export declare interface VisitorNodeMap {
|
|
|
3355
3632
|
* @internal
|
|
3356
3633
|
*/
|
|
3357
3634
|
declare class SourceMap {
|
|
3358
|
-
#private;
|
|
3359
3635
|
/**
|
|
3360
3636
|
* Last location
|
|
3361
3637
|
*/
|
|
3362
|
-
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;
|
|
3363
3664
|
/**
|
|
3364
3665
|
* Add a location
|
|
3365
3666
|
* @param source
|
|
3366
3667
|
* @param original
|
|
3367
3668
|
*/
|
|
3368
|
-
add(
|
|
3669
|
+
add(newLine: number, newColumn: number, srcId: number, ln: number, col: number, sourceFileName: string, sourceContent: string): void;
|
|
3369
3670
|
/**
|
|
3370
3671
|
* Convert to URL encoded string
|
|
3371
3672
|
*/
|
|
@@ -3376,6 +3677,122 @@ declare class SourceMap {
|
|
|
3376
3677
|
toJSON(): SourceMapObject;
|
|
3377
3678
|
}
|
|
3378
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
|
+
|
|
3379
3796
|
export declare interface PropertyListOptions {
|
|
3380
3797
|
|
|
3381
3798
|
removeDuplicateDeclarations?: boolean | string | string[];
|
|
@@ -3387,11 +3804,6 @@ export declare interface PropertyListOptions {
|
|
|
3387
3804
|
*/
|
|
3388
3805
|
export declare interface ParseInfo$1 {
|
|
3389
3806
|
|
|
3390
|
-
/**
|
|
3391
|
-
* source file or url
|
|
3392
|
-
*/
|
|
3393
|
-
src: string;
|
|
3394
|
-
|
|
3395
3807
|
/**
|
|
3396
3808
|
* read buffer
|
|
3397
3809
|
*/
|
|
@@ -3402,18 +3814,19 @@ export declare interface ParseInfo$1 {
|
|
|
3402
3814
|
stream: string;
|
|
3403
3815
|
|
|
3404
3816
|
/**
|
|
3405
|
-
*
|
|
3817
|
+
* Source file
|
|
3406
3818
|
*/
|
|
3407
|
-
|
|
3819
|
+
source: SourceFile;
|
|
3408
3820
|
|
|
3409
3821
|
/**
|
|
3410
3822
|
* last token position
|
|
3411
3823
|
*/
|
|
3412
|
-
position:
|
|
3824
|
+
position: number;
|
|
3825
|
+
|
|
3413
3826
|
/**
|
|
3414
3827
|
* current parsing position
|
|
3415
3828
|
*/
|
|
3416
|
-
currentPosition:
|
|
3829
|
+
currentPosition: number;
|
|
3417
3830
|
|
|
3418
3831
|
/**
|
|
3419
3832
|
* offset
|
|
@@ -4225,7 +4638,7 @@ export declare interface ErrorDescription$1 {
|
|
|
4225
4638
|
/**
|
|
4226
4639
|
* Error location
|
|
4227
4640
|
*/
|
|
4228
|
-
location?:
|
|
4641
|
+
location?: [string | null, number, number];
|
|
4229
4642
|
/**
|
|
4230
4643
|
* Error object
|
|
4231
4644
|
*/
|
|
@@ -4391,22 +4804,117 @@ export declare type LoadResult =
|
|
|
4391
4804
|
/**
|
|
4392
4805
|
* CSS module parser options
|
|
4393
4806
|
*/
|
|
4394
|
-
export declare interface
|
|
4807
|
+
export declare interface ModuleSyncOptions {
|
|
4395
4808
|
/**
|
|
4396
4809
|
* Use local scope vs global scope
|
|
4397
4810
|
*/
|
|
4398
|
-
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;
|
|
4399
4894
|
|
|
4400
4895
|
/**
|
|
4401
|
-
*
|
|
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
|
+
*
|
|
4402
4904
|
*/
|
|
4403
|
-
|
|
4905
|
+
naming?: ModuleCaseTransformEnum;
|
|
4404
4906
|
|
|
4405
4907
|
/**
|
|
4406
|
-
*
|
|
4908
|
+
* Function to generate scoped name
|
|
4909
|
+
* @param localName
|
|
4910
|
+
* @param filePath
|
|
4911
|
+
* @param pattern see {@link ModuleSyncOptions.pattern}
|
|
4912
|
+
* @param hashLength
|
|
4407
4913
|
*/
|
|
4408
|
-
hashLength?: number;
|
|
4914
|
+
generateScopedName?: (localName: string, filePath: string, pattern: string, hashLength?: number) => string;
|
|
4915
|
+
}
|
|
4409
4916
|
|
|
4917
|
+
export declare interface ModuleAsyncOptions extends ModuleSyncOptions {
|
|
4410
4918
|
/**
|
|
4411
4919
|
* The pattern used to generate scoped names. the supported placeholders are:
|
|
4412
4920
|
* - name: the file base name without the extension
|
|
@@ -4483,23 +4991,11 @@ export declare interface ModuleOptions {
|
|
|
4483
4991
|
*/
|
|
4484
4992
|
pattern?: string;
|
|
4485
4993
|
|
|
4486
|
-
/**
|
|
4487
|
-
* optional. function change the case of the scoped name and the class mapping
|
|
4488
|
-
*
|
|
4489
|
-
* - {@link ModuleCaseTransformEnum.IgnoreCase}: do not change case
|
|
4490
|
-
* - {@link ModuleCaseTransformEnum.CamelCase}: camelCase {@link ParseResult.mapping} key name
|
|
4491
|
-
* - {@link ModuleCaseTransformEnum.CamelCaseOnly}: camelCase {@link ParseResult.mapping} key name and the scoped class name
|
|
4492
|
-
* - {@link ModuleCaseTransformEnum.DashCase}: dashCase {@link ParseResult.mapping} key name
|
|
4493
|
-
* - {@link ModuleCaseTransformEnum.DashCaseOnly}: dashCase {@link ParseResult.mapping} key name and the scoped class name
|
|
4494
|
-
*
|
|
4495
|
-
*/
|
|
4496
|
-
naming?: ModuleCaseTransformEnum;
|
|
4497
|
-
|
|
4498
4994
|
/**
|
|
4499
4995
|
* Function to generate scoped name
|
|
4500
4996
|
* @param localName
|
|
4501
4997
|
* @param filePath
|
|
4502
|
-
* @param pattern see {@link
|
|
4998
|
+
* @param pattern see {@link ModuleSyncOptions.pattern}
|
|
4503
4999
|
* @param hashLength
|
|
4504
5000
|
*/
|
|
4505
5001
|
generateScopedName?: (
|
|
@@ -4525,6 +5021,15 @@ export declare interface ParseInputFileOptions {
|
|
|
4525
5021
|
asStream?: boolean;
|
|
4526
5022
|
}
|
|
4527
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
|
+
}
|
|
4528
5033
|
/**
|
|
4529
5034
|
* Input options for string or stream
|
|
4530
5035
|
*/
|
|
@@ -4535,11 +5040,13 @@ export declare interface ParseInputStreamOptions {
|
|
|
4535
5040
|
input: string | ReadableStream<Uint8Array>;
|
|
4536
5041
|
}
|
|
4537
5042
|
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
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 {
|
|
4543
5050
|
/**
|
|
4544
5051
|
* Source file to be used for sourcemap
|
|
4545
5052
|
*/
|
|
@@ -4552,10 +5059,6 @@ export declare interface ParserOptions
|
|
|
4552
5059
|
* Remove at-rule charset
|
|
4553
5060
|
*/
|
|
4554
5061
|
removeCharset?: boolean;
|
|
4555
|
-
/**
|
|
4556
|
-
* Resolve import
|
|
4557
|
-
*/
|
|
4558
|
-
resolveImport?: boolean;
|
|
4559
5062
|
/**
|
|
4560
5063
|
* Current working directory
|
|
4561
5064
|
*
|
|
@@ -4572,18 +5075,6 @@ export declare interface ParserOptions
|
|
|
4572
5075
|
*/
|
|
4573
5076
|
expandIfSyntax?: boolean;
|
|
4574
5077
|
|
|
4575
|
-
/**
|
|
4576
|
-
* Custom URL and file loader.
|
|
4577
|
-
* @param url
|
|
4578
|
-
* @param currentDirectory
|
|
4579
|
-
* @param responseType
|
|
4580
|
-
*
|
|
4581
|
-
*/
|
|
4582
|
-
load?: (
|
|
4583
|
-
url: string | { absolute: string; relative: string },
|
|
4584
|
-
currentDirectory: string,
|
|
4585
|
-
responseType?: boolean | ResponseType,
|
|
4586
|
-
) => Promise<string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
4587
5078
|
/**
|
|
4588
5079
|
* Get directory name
|
|
4589
5080
|
* @param path
|
|
@@ -4619,9 +5110,9 @@ export declare interface ParserOptions
|
|
|
4619
5110
|
|
|
4620
5111
|
/**
|
|
4621
5112
|
* Node visitor
|
|
4622
|
-
* {@link
|
|
5113
|
+
* {@link VisitorSyncNodeMap | VisitorSyncNodeMap[]}
|
|
4623
5114
|
*/
|
|
4624
|
-
visitor?:
|
|
5115
|
+
visitor?: VisitorSyncNodeMap | VisitorSyncNodeMap[];
|
|
4625
5116
|
/**
|
|
4626
5117
|
* Abort signal
|
|
4627
5118
|
*
|
|
@@ -4651,7 +5142,7 @@ export declare interface ParserOptions
|
|
|
4651
5142
|
/**
|
|
4652
5143
|
* CSS modules options
|
|
4653
5144
|
*/
|
|
4654
|
-
module?: boolean | ModuleCaseTransformEnum | ModuleScopeEnumOptions |
|
|
5145
|
+
module?: boolean | ModuleCaseTransformEnum | ModuleScopeEnumOptions | ModuleSyncOptions;
|
|
4655
5146
|
|
|
4656
5147
|
/**
|
|
4657
5148
|
* Tokenizing info
|
|
@@ -4660,6 +5151,35 @@ export declare interface ParserOptions
|
|
|
4660
5151
|
parseInfo?: ParseInfo;
|
|
4661
5152
|
}
|
|
4662
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
|
+
|
|
4663
5183
|
/**
|
|
4664
5184
|
* Minify feature options
|
|
4665
5185
|
*
|
|
@@ -4811,8 +5331,19 @@ export declare interface RenderOptions {
|
|
|
4811
5331
|
* @internal
|
|
4812
5332
|
*/
|
|
4813
5333
|
resolve?: (url: string, currentUrl: string, currentWorkingDirectory?: string) => ResolvedPath;
|
|
5334
|
+
|
|
5335
|
+
/**
|
|
5336
|
+
* Source map
|
|
5337
|
+
* @internal
|
|
5338
|
+
*/
|
|
5339
|
+
sourcesMap?: Map<number, SourceFile>;
|
|
4814
5340
|
}
|
|
4815
5341
|
|
|
5342
|
+
/**
|
|
5343
|
+
* Transform options
|
|
5344
|
+
*/
|
|
5345
|
+
export declare interface TransformSyncOptions extends ParserSyncOptions, RenderOptions {}
|
|
5346
|
+
|
|
4816
5347
|
/**
|
|
4817
5348
|
* Transform options
|
|
4818
5349
|
*/
|
|
@@ -5081,7 +5612,7 @@ export declare interface SourceMapObject {
|
|
|
5081
5612
|
/**
|
|
5082
5613
|
* Source files
|
|
5083
5614
|
*/
|
|
5084
|
-
sources?: string
|
|
5615
|
+
sources?: Array<string | null>;
|
|
5085
5616
|
/**
|
|
5086
5617
|
* Source files content
|
|
5087
5618
|
*/
|
|
@@ -5332,7 +5863,7 @@ button {
|
|
|
5332
5863
|
* @param matcher
|
|
5333
5864
|
* @returns
|
|
5334
5865
|
*/
|
|
5335
|
-
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;
|
|
5336
5867
|
/**
|
|
5337
5868
|
* Search the ast sub-tree by checking each node's value token and return the first match
|
|
5338
5869
|
*
|
|
@@ -5402,7 +5933,7 @@ button-small {
|
|
|
5402
5933
|
* @param matcher
|
|
5403
5934
|
* @returns
|
|
5404
5935
|
*/
|
|
5405
|
-
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[];
|
|
5406
5937
|
/**
|
|
5407
5938
|
* Search the ast sub-tree and return the last match.
|
|
5408
5939
|
*
|
|
@@ -5433,7 +5964,7 @@ button {
|
|
|
5433
5964
|
* @param matcher
|
|
5434
5965
|
* @returns
|
|
5435
5966
|
*/
|
|
5436
|
-
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;
|
|
5437
5968
|
|
|
5438
5969
|
/**
|
|
5439
5970
|
*
|
|
@@ -5534,6 +6065,74 @@ declare function render(data: AstNode$1, options?: RenderOptions, mapping?: {
|
|
|
5534
6065
|
* ```
|
|
5535
6066
|
*/
|
|
5536
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;
|
|
5537
6136
|
/**
|
|
5538
6137
|
* Parse css
|
|
5539
6138
|
* @param stream
|
|
@@ -5680,9 +6279,137 @@ declare function parse(options: ParseInputStreamOptions & ParserOptions): Promis
|
|
|
5680
6279
|
* ```
|
|
5681
6280
|
*/
|
|
5682
6281
|
declare const transformFile: (file: string, options?: TransformOptions, asStream?: boolean) => Promise<TransformResult>;
|
|
5683
|
-
|
|
5684
|
-
|
|
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
|
+
*/
|
|
5685
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>;
|
|
5686
6413
|
|
|
5687
|
-
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 };
|
|
5688
|
-
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 };
|