@tbela99/css-parser 0.0.1-alpha5 → 0.0.1-rc1
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/.gitattributes +1 -0
- package/README.md +18 -6
- package/dist/config.json.js +95 -4
- package/dist/index-umd-web.js +1609 -1391
- package/dist/index.cjs +1609 -1391
- package/dist/index.d.ts +317 -9
- package/dist/index.js +6 -2
- package/dist/lib/{parser/deduplicate.js → ast/minify.js} +393 -414
- package/dist/lib/parser/declaration/list.js +38 -9
- package/dist/lib/parser/declaration/map.js +203 -145
- package/dist/lib/parser/declaration/set.js +26 -34
- package/dist/lib/parser/parse.js +237 -683
- package/dist/lib/parser/tokenize.js +452 -0
- package/dist/lib/parser/utils/eq.js +29 -5
- package/dist/lib/parser/utils/syntax.js +24 -7
- package/dist/lib/renderer/render.js +9 -6
- package/dist/lib/transform.js +1 -1
- package/dist/node/index.js +1 -0
- package/dist/web/index.js +6 -2
- package/package.json +11 -5
- /package/dist/lib/{walker → ast}/walk.js +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -173,6 +173,275 @@ interface AttrToken {
|
|
|
173
173
|
}
|
|
174
174
|
declare type Token = LiteralToken | IdentToken | CommaToken | ColonToken | SemiColonToken | NumberToken | AtRuleToken | PercentageToken | FunctionURLToken | FunctionToken | DimensionToken | LengthToken | AngleToken | StringToken | TimeToken | FrequencyToken | ResolutionToken | UnclosedStringToken | HashToken | BadStringToken | BlockStartToken | BlockEndToken | AttrStartToken | AttrEndToken | ParensStartToken | ParensEndToken | CDOCommentToken | BadCDOCommentToken | CommentToken | BadCommentToken | WhitespaceToken | IncludesToken | DashMatchToken | LessThanToken | GreaterThanToken | PseudoClassToken | PseudoClassFunctionToken | DelimToken | BadUrlToken | UrlToken | ImportantToken | ColorToken | AttrToken | EOFToken;
|
|
175
175
|
|
|
176
|
+
interface PropertiesConfig {
|
|
177
|
+
properties: PropertiesConfigProperties;
|
|
178
|
+
map: Map;
|
|
179
|
+
}
|
|
180
|
+
interface Map {
|
|
181
|
+
border: Border;
|
|
182
|
+
"border-color": BackgroundPositionClass;
|
|
183
|
+
"border-style": BackgroundPositionClass;
|
|
184
|
+
"border-width": BackgroundPositionClass;
|
|
185
|
+
outline: Outline;
|
|
186
|
+
"outline-color": BackgroundPositionClass;
|
|
187
|
+
"outline-style": BackgroundPositionClass;
|
|
188
|
+
"outline-width": BackgroundPositionClass;
|
|
189
|
+
font: Font;
|
|
190
|
+
"font-weight": BackgroundPositionClass;
|
|
191
|
+
"font-style": BackgroundPositionClass;
|
|
192
|
+
"font-size": BackgroundPositionClass;
|
|
193
|
+
"line-height": BackgroundPositionClass;
|
|
194
|
+
"font-stretch": BackgroundPositionClass;
|
|
195
|
+
"font-variant": BackgroundPositionClass;
|
|
196
|
+
"font-family": BackgroundPositionClass;
|
|
197
|
+
background: Background;
|
|
198
|
+
"background-repeat": BackgroundPositionClass;
|
|
199
|
+
"background-color": BackgroundPositionClass;
|
|
200
|
+
"background-image": BackgroundPositionClass;
|
|
201
|
+
"background-attachment": BackgroundPositionClass;
|
|
202
|
+
"background-clip": BackgroundPositionClass;
|
|
203
|
+
"background-origin": BackgroundPositionClass;
|
|
204
|
+
"background-position": BackgroundPositionClass;
|
|
205
|
+
"background-size": BackgroundPositionClass;
|
|
206
|
+
}
|
|
207
|
+
interface Background {
|
|
208
|
+
shorthand: string;
|
|
209
|
+
pattern: string;
|
|
210
|
+
keywords: string[];
|
|
211
|
+
default: any[];
|
|
212
|
+
multiple: boolean;
|
|
213
|
+
separator: Separator;
|
|
214
|
+
properties: BackgroundProperties;
|
|
215
|
+
}
|
|
216
|
+
interface BackgroundProperties {
|
|
217
|
+
"background-repeat": BackgroundRepeat;
|
|
218
|
+
"background-color": PurpleBackgroundAttachment;
|
|
219
|
+
"background-image": PurpleBackgroundAttachment;
|
|
220
|
+
"background-attachment": PurpleBackgroundAttachment;
|
|
221
|
+
"background-clip": PurpleBackgroundAttachment;
|
|
222
|
+
"background-origin": PurpleBackgroundAttachment;
|
|
223
|
+
"background-position": BackgroundPosition;
|
|
224
|
+
"background-size": BackgroundSize;
|
|
225
|
+
}
|
|
226
|
+
interface PurpleBackgroundAttachment {
|
|
227
|
+
types: string[];
|
|
228
|
+
default: string[];
|
|
229
|
+
keywords: string[];
|
|
230
|
+
required?: boolean;
|
|
231
|
+
mapping?: BackgroundAttachmentMapping;
|
|
232
|
+
}
|
|
233
|
+
interface BackgroundAttachmentMapping {
|
|
234
|
+
"ultra-condensed": string;
|
|
235
|
+
"extra-condensed": string;
|
|
236
|
+
condensed: string;
|
|
237
|
+
"semi-condensed": string;
|
|
238
|
+
normal: string;
|
|
239
|
+
"semi-expanded": string;
|
|
240
|
+
expanded: string;
|
|
241
|
+
"extra-expanded": string;
|
|
242
|
+
"ultra-expanded": string;
|
|
243
|
+
}
|
|
244
|
+
interface BackgroundPosition {
|
|
245
|
+
multiple: boolean;
|
|
246
|
+
types: string[];
|
|
247
|
+
default: string[];
|
|
248
|
+
keywords: string[];
|
|
249
|
+
mapping: BackgroundPositionMapping;
|
|
250
|
+
constraints: BackgroundPositionConstraints;
|
|
251
|
+
}
|
|
252
|
+
interface BackgroundPositionConstraints {
|
|
253
|
+
mapping: ConstraintsMapping;
|
|
254
|
+
}
|
|
255
|
+
interface ConstraintsMapping {
|
|
256
|
+
max: number;
|
|
257
|
+
}
|
|
258
|
+
interface BackgroundPositionMapping {
|
|
259
|
+
left: string;
|
|
260
|
+
top: string;
|
|
261
|
+
center: string;
|
|
262
|
+
bottom: string;
|
|
263
|
+
right: string;
|
|
264
|
+
}
|
|
265
|
+
interface BackgroundRepeat {
|
|
266
|
+
types: any[];
|
|
267
|
+
default: string[];
|
|
268
|
+
multiple: boolean;
|
|
269
|
+
keywords: string[];
|
|
270
|
+
mapping: BackgroundRepeatMapping;
|
|
271
|
+
}
|
|
272
|
+
interface BackgroundRepeatMapping {
|
|
273
|
+
"repeat no-repeat": string;
|
|
274
|
+
"no-repeat repeat": string;
|
|
275
|
+
"repeat repeat": string;
|
|
276
|
+
"space space": string;
|
|
277
|
+
"round round": string;
|
|
278
|
+
"no-repeat no-repeat": string;
|
|
279
|
+
}
|
|
280
|
+
interface BackgroundSize {
|
|
281
|
+
multiple: boolean;
|
|
282
|
+
previous: string;
|
|
283
|
+
prefix: Prefix;
|
|
284
|
+
types: string[];
|
|
285
|
+
default: string[];
|
|
286
|
+
keywords: string[];
|
|
287
|
+
mapping: BackgroundSizeMapping;
|
|
288
|
+
}
|
|
289
|
+
interface BackgroundSizeMapping {
|
|
290
|
+
"auto auto": string;
|
|
291
|
+
}
|
|
292
|
+
interface Prefix {
|
|
293
|
+
typ: string;
|
|
294
|
+
val: string;
|
|
295
|
+
}
|
|
296
|
+
interface Separator {
|
|
297
|
+
typ: string;
|
|
298
|
+
}
|
|
299
|
+
interface BackgroundPositionClass {
|
|
300
|
+
shorthand: string;
|
|
301
|
+
}
|
|
302
|
+
interface Border {
|
|
303
|
+
shorthand: string;
|
|
304
|
+
pattern: string;
|
|
305
|
+
keywords: string[];
|
|
306
|
+
default: string[];
|
|
307
|
+
properties: BorderProperties;
|
|
308
|
+
}
|
|
309
|
+
interface BorderProperties {
|
|
310
|
+
"border-color": BorderColorClass;
|
|
311
|
+
"border-style": BorderColorClass;
|
|
312
|
+
"border-width": BorderColorClass;
|
|
313
|
+
}
|
|
314
|
+
interface BorderColorClass {
|
|
315
|
+
}
|
|
316
|
+
interface Font {
|
|
317
|
+
shorthand: string;
|
|
318
|
+
pattern: string;
|
|
319
|
+
keywords: string[];
|
|
320
|
+
default: any[];
|
|
321
|
+
properties: FontProperties;
|
|
322
|
+
}
|
|
323
|
+
interface FontProperties {
|
|
324
|
+
"font-weight": FontWeight;
|
|
325
|
+
"font-style": PurpleBackgroundAttachment;
|
|
326
|
+
"font-size": PurpleBackgroundAttachment;
|
|
327
|
+
"line-height": LineHeight;
|
|
328
|
+
"font-stretch": PurpleBackgroundAttachment;
|
|
329
|
+
"font-variant": PurpleBackgroundAttachment;
|
|
330
|
+
"font-family": FontFamily;
|
|
331
|
+
}
|
|
332
|
+
interface FontFamily {
|
|
333
|
+
types: string[];
|
|
334
|
+
default: any[];
|
|
335
|
+
keywords: string[];
|
|
336
|
+
required: boolean;
|
|
337
|
+
multiple: boolean;
|
|
338
|
+
separator: Separator;
|
|
339
|
+
}
|
|
340
|
+
interface FontWeight {
|
|
341
|
+
types: string[];
|
|
342
|
+
default: string[];
|
|
343
|
+
keywords: string[];
|
|
344
|
+
constraints: FontWeightConstraints;
|
|
345
|
+
mapping: FontWeightMapping;
|
|
346
|
+
}
|
|
347
|
+
interface FontWeightConstraints {
|
|
348
|
+
value: Value;
|
|
349
|
+
}
|
|
350
|
+
interface Value {
|
|
351
|
+
min: string;
|
|
352
|
+
max: string;
|
|
353
|
+
}
|
|
354
|
+
interface FontWeightMapping {
|
|
355
|
+
thin: string;
|
|
356
|
+
hairline: string;
|
|
357
|
+
"extra light": string;
|
|
358
|
+
"ultra light": string;
|
|
359
|
+
light: string;
|
|
360
|
+
normal: string;
|
|
361
|
+
regular: string;
|
|
362
|
+
medium: string;
|
|
363
|
+
"semi bold": string;
|
|
364
|
+
"demi bold": string;
|
|
365
|
+
bold: string;
|
|
366
|
+
"extra bold": string;
|
|
367
|
+
"ultra bold": string;
|
|
368
|
+
black: string;
|
|
369
|
+
heavy: string;
|
|
370
|
+
"extra black": string;
|
|
371
|
+
"ultra black": string;
|
|
372
|
+
}
|
|
373
|
+
interface LineHeight {
|
|
374
|
+
types: string[];
|
|
375
|
+
default: string[];
|
|
376
|
+
keywords: string[];
|
|
377
|
+
previous: string;
|
|
378
|
+
prefix: Prefix;
|
|
379
|
+
}
|
|
380
|
+
interface Outline {
|
|
381
|
+
shorthand: string;
|
|
382
|
+
pattern: string;
|
|
383
|
+
keywords: string[];
|
|
384
|
+
default: string[];
|
|
385
|
+
properties: OutlineProperties;
|
|
386
|
+
}
|
|
387
|
+
interface OutlineProperties {
|
|
388
|
+
"outline-color": PurpleBackgroundAttachment;
|
|
389
|
+
"outline-style": PurpleBackgroundAttachment;
|
|
390
|
+
"outline-width": PurpleBackgroundAttachment;
|
|
391
|
+
}
|
|
392
|
+
interface PropertiesConfigProperties {
|
|
393
|
+
inset: BorderRadius;
|
|
394
|
+
top: BackgroundPositionClass;
|
|
395
|
+
right: BackgroundPositionClass;
|
|
396
|
+
bottom: BackgroundPositionClass;
|
|
397
|
+
left: BackgroundPositionClass;
|
|
398
|
+
margin: BorderRadius;
|
|
399
|
+
"margin-top": BackgroundPositionClass;
|
|
400
|
+
"margin-right": BackgroundPositionClass;
|
|
401
|
+
"margin-bottom": BackgroundPositionClass;
|
|
402
|
+
"margin-left": BackgroundPositionClass;
|
|
403
|
+
padding: BorderColor;
|
|
404
|
+
"padding-top": BackgroundPositionClass;
|
|
405
|
+
"padding-right": BackgroundPositionClass;
|
|
406
|
+
"padding-bottom": BackgroundPositionClass;
|
|
407
|
+
"padding-left": BackgroundPositionClass;
|
|
408
|
+
"border-radius": BorderRadius;
|
|
409
|
+
"border-top-left-radius": BackgroundPositionClass;
|
|
410
|
+
"border-top-right-radius": BackgroundPositionClass;
|
|
411
|
+
"border-bottom-right-radius": BackgroundPositionClass;
|
|
412
|
+
"border-bottom-left-radius": BackgroundPositionClass;
|
|
413
|
+
"border-width": BorderColor;
|
|
414
|
+
"border-top-width": BackgroundPositionClass;
|
|
415
|
+
"border-right-width": BackgroundPositionClass;
|
|
416
|
+
"border-bottom-width": BackgroundPositionClass;
|
|
417
|
+
"border-left-width": BackgroundPositionClass;
|
|
418
|
+
"border-style": BorderColor;
|
|
419
|
+
"border-top-style": BackgroundPositionClass;
|
|
420
|
+
"border-right-style": BackgroundPositionClass;
|
|
421
|
+
"border-bottom-style": BackgroundPositionClass;
|
|
422
|
+
"border-left-style": BackgroundPositionClass;
|
|
423
|
+
"border-color": BorderColor;
|
|
424
|
+
"border-top-color": BackgroundPositionClass;
|
|
425
|
+
"border-right-color": BackgroundPositionClass;
|
|
426
|
+
"border-bottom-color": BackgroundPositionClass;
|
|
427
|
+
"border-left-color": BackgroundPositionClass;
|
|
428
|
+
}
|
|
429
|
+
interface BorderColor {
|
|
430
|
+
shorthand: string;
|
|
431
|
+
map?: string;
|
|
432
|
+
properties: string[];
|
|
433
|
+
types: string[];
|
|
434
|
+
keywords: string[];
|
|
435
|
+
}
|
|
436
|
+
interface BorderRadius {
|
|
437
|
+
shorthand: string;
|
|
438
|
+
properties: string[];
|
|
439
|
+
types: string[];
|
|
440
|
+
multiple: boolean;
|
|
441
|
+
separator: null | string;
|
|
442
|
+
keywords: string[];
|
|
443
|
+
}
|
|
444
|
+
|
|
176
445
|
interface ErrorDescription {
|
|
177
446
|
|
|
178
447
|
// drop rule or declaration | fix rule or declaration
|
|
@@ -190,7 +459,7 @@ interface ParserOptions {
|
|
|
190
459
|
|
|
191
460
|
src?: string;
|
|
192
461
|
sourcemap?: boolean;
|
|
193
|
-
|
|
462
|
+
minify?: boolean;
|
|
194
463
|
nestingRules?: boolean;
|
|
195
464
|
removeEmpty?: boolean;
|
|
196
465
|
resolveUrls?: boolean;
|
|
@@ -203,7 +472,7 @@ interface ParserOptions {
|
|
|
203
472
|
|
|
204
473
|
interface RenderOptions {
|
|
205
474
|
|
|
206
|
-
|
|
475
|
+
minify?: boolean;
|
|
207
476
|
preserveLicense?: boolean;
|
|
208
477
|
indent?: string;
|
|
209
478
|
newLine?: string;
|
|
@@ -236,6 +505,13 @@ interface TransformResult extends ParseResult, RenderResult {
|
|
|
236
505
|
}
|
|
237
506
|
}
|
|
238
507
|
|
|
508
|
+
interface TokenizeResult {
|
|
509
|
+
token: string;
|
|
510
|
+
hint?: string;
|
|
511
|
+
position: Position;
|
|
512
|
+
bytesIn: number;
|
|
513
|
+
}
|
|
514
|
+
|
|
239
515
|
interface Position {
|
|
240
516
|
|
|
241
517
|
ind: number;
|
|
@@ -313,18 +589,50 @@ type AstNode =
|
|
|
313
589
|
| AstRule
|
|
314
590
|
| AstDeclaration;
|
|
315
591
|
|
|
316
|
-
declare
|
|
317
|
-
declare function
|
|
318
|
-
|
|
592
|
+
declare const urlTokenMatcher: RegExp;
|
|
593
|
+
declare function parseString(src: string, options?: {
|
|
594
|
+
location: boolean;
|
|
595
|
+
}): Token[];
|
|
596
|
+
|
|
597
|
+
declare function tokenize(iterator: string): Generator<TokenizeResult>;
|
|
598
|
+
|
|
599
|
+
declare function isLength(dimension: DimensionToken): boolean;
|
|
600
|
+
declare function isResolution(dimension: DimensionToken): boolean;
|
|
601
|
+
declare function isAngle(dimension: DimensionToken): boolean;
|
|
602
|
+
declare function isTime(dimension: DimensionToken): boolean;
|
|
603
|
+
declare function isFrequency(dimension: DimensionToken): boolean;
|
|
604
|
+
declare function isIdentStart(codepoint: number): boolean;
|
|
605
|
+
declare function isDigit(codepoint: number): boolean;
|
|
606
|
+
declare function isIdentCodepoint(codepoint: number): boolean;
|
|
607
|
+
declare function isIdent(name: string): boolean;
|
|
608
|
+
declare function isPseudo(name: string): boolean;
|
|
609
|
+
declare function isHash(name: string): boolean;
|
|
610
|
+
declare function isNumber(name: string): boolean;
|
|
611
|
+
declare function isDimension(name: string): boolean;
|
|
612
|
+
declare function isPercentage(name: string): boolean;
|
|
613
|
+
declare function parseDimension(name: string): DimensionToken | LengthToken | AngleToken;
|
|
614
|
+
declare function isHexColor(name: string): boolean;
|
|
615
|
+
declare function isHexDigit(name: string): boolean;
|
|
616
|
+
declare function isFunction(name: string): boolean;
|
|
617
|
+
declare function isAtKeyword(name: string): boolean;
|
|
618
|
+
declare function isNewLine(codepoint: number): boolean;
|
|
619
|
+
declare function isWhiteSpace(codepoint: number): boolean;
|
|
620
|
+
|
|
621
|
+
declare const getConfig: () => PropertiesConfig;
|
|
622
|
+
|
|
623
|
+
declare function render(data: AstNode, opt?: RenderOptions): RenderResult;
|
|
624
|
+
declare function renderToken(token: Token, options?: RenderOptions): string;
|
|
625
|
+
|
|
626
|
+
declare const combinators: string[];
|
|
627
|
+
declare function minify(ast: AstNode, options?: ParserOptions, recursive?: boolean): AstNode;
|
|
319
628
|
declare function reduceSelector(selector: string[][]): {
|
|
320
629
|
match: boolean;
|
|
321
630
|
optimized: string[];
|
|
322
631
|
selector: string[][];
|
|
323
632
|
reducible: boolean;
|
|
324
633
|
} | null;
|
|
325
|
-
|
|
326
|
-
declare function
|
|
327
|
-
declare function renderToken(token: Token, options?: RenderOptions): string;
|
|
634
|
+
declare function hasDeclaration(node: AstRule): boolean;
|
|
635
|
+
declare function minifyRule(ast: AstRule | AstAtRule): AstRule | AstAtRule;
|
|
328
636
|
|
|
329
637
|
declare function walk(node: AstNode): Generator<{
|
|
330
638
|
node: AstNode;
|
|
@@ -344,4 +652,4 @@ declare function resolve(url: string, currentDirectory: string, cwd?: string): {
|
|
|
344
652
|
declare function parse(iterator: string, opt?: ParserOptions): Promise<ParseResult>;
|
|
345
653
|
declare function transform(css: string, options?: TransformOptions): Promise<TransformResult>;
|
|
346
654
|
|
|
347
|
-
export {
|
|
655
|
+
export { combinators, dirname, getConfig, hasDeclaration, isAngle, isAtKeyword, isDigit, isDimension, isFrequency, isFunction, isHash, isHexColor, isHexDigit, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNumber, isPercentage, isPseudo, isResolution, isTime, isWhiteSpace, load, matchUrl, minify, minifyRule, parse, parseDimension, parseString, reduceSelector, render, renderToken, resolve, tokenize, transform, urlTokenMatcher, walk };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { parse, transform } from './node/index.js';
|
|
2
|
-
export {
|
|
2
|
+
export { parseString, urlTokenMatcher } from './lib/parser/parse.js';
|
|
3
|
+
export { tokenize } from './lib/parser/tokenize.js';
|
|
4
|
+
export { isAngle, isAtKeyword, isDigit, isDimension, isFrequency, isFunction, isHash, isHexColor, isHexDigit, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNumber, isPercentage, isPseudo, isResolution, isTime, isWhiteSpace, parseDimension } from './lib/parser/utils/syntax.js';
|
|
5
|
+
export { getConfig } from './lib/parser/utils/config.js';
|
|
3
6
|
export { render, renderToken } from './lib/renderer/render.js';
|
|
4
|
-
export {
|
|
7
|
+
export { combinators, hasDeclaration, minify, minifyRule, reduceSelector } from './lib/ast/minify.js';
|
|
8
|
+
export { walk } from './lib/ast/walk.js';
|
|
5
9
|
export { load } from './node/load.js';
|
|
6
10
|
export { dirname, matchUrl, resolve } from './lib/fs/resolve.js';
|