@tbela99/css-parser 0.0.1-alpha5 → 0.0.1-rc2

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/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
- compress?: boolean;
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
- compress?: boolean;
475
+ minify?: boolean;
207
476
  preserveLicense?: boolean;
208
477
  indent?: string;
209
478
  newLine?: string;
@@ -218,11 +487,19 @@ interface TransformOptions extends ParserOptions, RenderOptions {
218
487
  interface ParseResult {
219
488
  ast: AstRuleStyleSheet;
220
489
  errors: ErrorDescription[];
221
- bytesIn: number;
490
+ stats: {
491
+ bytesIn: number;
492
+ parse: string;
493
+ minify: string;
494
+ total: string;
495
+ }
222
496
  }
223
497
 
224
498
  interface RenderResult {
225
499
  code: string ;
500
+ stats: {
501
+ total: string;
502
+ }
226
503
  }
227
504
 
228
505
  interface TransformResult extends ParseResult, RenderResult {
@@ -231,11 +508,19 @@ interface TransformResult extends ParseResult, RenderResult {
231
508
  bytesIn: number;
232
509
  bytesOut: number;
233
510
  parse: string;
511
+ minify: string;
234
512
  render: string;
235
513
  total: string;
236
514
  }
237
515
  }
238
516
 
517
+ interface TokenizeResult {
518
+ token: string;
519
+ hint?: string;
520
+ position: Position;
521
+ bytesIn: number;
522
+ }
523
+
239
524
  interface Position {
240
525
 
241
526
  ind: number;
@@ -313,18 +598,50 @@ type AstNode =
313
598
  | AstRule
314
599
  | AstDeclaration;
315
600
 
316
- declare function deduplicate(ast: AstNode, options?: ParserOptions, recursive?: boolean): AstNode;
317
- declare function hasDeclaration(node: AstRule): boolean;
318
- declare function deduplicateRule(ast: AstRule | AstAtRule): AstRule | AstAtRule;
601
+ declare const urlTokenMatcher: RegExp;
602
+ declare function parseString(src: string, options?: {
603
+ location: boolean;
604
+ }): Token[];
605
+
606
+ declare function tokenize(iterator: string): Generator<TokenizeResult>;
607
+
608
+ declare function isLength(dimension: DimensionToken): boolean;
609
+ declare function isResolution(dimension: DimensionToken): boolean;
610
+ declare function isAngle(dimension: DimensionToken): boolean;
611
+ declare function isTime(dimension: DimensionToken): boolean;
612
+ declare function isFrequency(dimension: DimensionToken): boolean;
613
+ declare function isIdentStart(codepoint: number): boolean;
614
+ declare function isDigit(codepoint: number): boolean;
615
+ declare function isIdentCodepoint(codepoint: number): boolean;
616
+ declare function isIdent(name: string): boolean;
617
+ declare function isPseudo(name: string): boolean;
618
+ declare function isHash(name: string): boolean;
619
+ declare function isNumber(name: string): boolean;
620
+ declare function isDimension(name: string): boolean;
621
+ declare function isPercentage(name: string): boolean;
622
+ declare function parseDimension(name: string): DimensionToken | LengthToken | AngleToken;
623
+ declare function isHexColor(name: string): boolean;
624
+ declare function isHexDigit(name: string): boolean;
625
+ declare function isFunction(name: string): boolean;
626
+ declare function isAtKeyword(name: string): boolean;
627
+ declare function isNewLine(codepoint: number): boolean;
628
+ declare function isWhiteSpace(codepoint: number): boolean;
629
+
630
+ declare const getConfig: () => PropertiesConfig;
631
+
632
+ declare function render(data: AstNode, opt?: RenderOptions): RenderResult;
633
+ declare function renderToken(token: Token, options?: RenderOptions): string;
634
+
635
+ declare const combinators: string[];
636
+ declare function minify(ast: AstNode, options?: ParserOptions, recursive?: boolean): AstNode;
319
637
  declare function reduceSelector(selector: string[][]): {
320
638
  match: boolean;
321
639
  optimized: string[];
322
640
  selector: string[][];
323
641
  reducible: boolean;
324
642
  } | null;
325
-
326
- declare function render(data: AstNode, opt?: RenderOptions): RenderResult;
327
- declare function renderToken(token: Token, options?: RenderOptions): string;
643
+ declare function hasDeclaration(node: AstRule): boolean;
644
+ declare function minifyRule(ast: AstRule | AstAtRule): AstRule | AstAtRule;
328
645
 
329
646
  declare function walk(node: AstNode): Generator<{
330
647
  node: AstNode;
@@ -344,4 +661,4 @@ declare function resolve(url: string, currentDirectory: string, cwd?: string): {
344
661
  declare function parse(iterator: string, opt?: ParserOptions): Promise<ParseResult>;
345
662
  declare function transform(css: string, options?: TransformOptions): Promise<TransformResult>;
346
663
 
347
- export { deduplicate, deduplicateRule, dirname, hasDeclaration, load, matchUrl, parse, reduceSelector, render, renderToken, resolve, transform, walk };
664
+ 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 { deduplicate, deduplicateRule, hasDeclaration, reduceSelector } from './lib/parser/deduplicate.js';
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 { walk } from './lib/walker/walk.js';
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';