@projectwallace/css-parser 0.18.9 → 0.18.12

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.
Files changed (40) hide show
  1. package/README.md +186 -18
  2. package/dist/{arena-e9O_g2AN.js → arena-Bsf96CQK.js} +27 -19
  3. package/dist/{arena-BGvFdbj5.d.ts → arena-DvT75bvK.d.ts} +2 -0
  4. package/dist/constants.d.ts +1 -1
  5. package/dist/constants.js +1 -1
  6. package/dist/{css-node-DfJEsKN0.js → css-node-yoUdFtNg.js} +101 -100
  7. package/dist/index.d.ts +6 -20
  8. package/dist/index.js +9 -146
  9. package/dist/{node-types-YnOKcNfU.d.ts → node-types-CY0JK9_a.d.ts} +9 -55
  10. package/dist/node-types.d.ts +2 -0
  11. package/dist/node-types.js +142 -0
  12. package/dist/parse-anplusb.d.ts +2 -2
  13. package/dist/parse-anplusb.js +5 -4
  14. package/dist/parse-atrule-prelude.d.ts +2 -2
  15. package/dist/parse-atrule-prelude.js +62 -61
  16. package/dist/parse-declaration.d.ts +3 -3
  17. package/dist/parse-declaration.js +20 -19
  18. package/dist/parse-dimension.js +47 -1
  19. package/dist/{parse-selector-rTXB4IN2.js → parse-selector-CqIpnBrQ.js} +74 -81
  20. package/dist/parse-selector.d.ts +2 -2
  21. package/dist/parse-selector.js +1 -1
  22. package/dist/parse-value.d.ts +2 -2
  23. package/dist/parse-value.js +8 -8
  24. package/dist/parse.d.ts +3 -3
  25. package/dist/parse.js +67 -46
  26. package/dist/string-helpers-BMWJduts.d.ts +18 -0
  27. package/dist/string-helpers.d.ts +2 -0
  28. package/dist/string-helpers.js +1 -0
  29. package/dist/{parse-dimension-CIaPOmBc.js → string-utils-DiRRd28d.js} +5 -49
  30. package/dist/token-types-Bqsf5FX-.d.ts +38 -0
  31. package/dist/token-types.d.ts +2 -0
  32. package/dist/token-types.js +30 -0
  33. package/dist/{tokenize-0ADWAELW.js → tokenize-Ccg58Z_k.js} +67 -96
  34. package/dist/tokenize.d.ts +97 -2
  35. package/dist/tokenize.js +1 -1
  36. package/dist/{value-node-parser-DizbcN1a.js → value-node-parser-BBwBxFR_.js} +133 -135
  37. package/dist/walk.d.ts +3 -2
  38. package/dist/walk.js +2 -2
  39. package/package.json +17 -4
  40. package/dist/tokenize-CaWtrHw_.d.ts +0 -134
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectwallace/css-parser",
3
- "version": "0.18.9",
3
+ "version": "0.18.12",
4
4
  "description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
5
5
  "keywords": [
6
6
  "ast",
@@ -69,6 +69,18 @@
69
69
  "./nodes": {
70
70
  "types": "./dist/constants.d.ts",
71
71
  "import": "./dist/constants.js"
72
+ },
73
+ "./node-types": {
74
+ "types": "./dist/node-types.d.ts",
75
+ "import": "./dist/node-types.js"
76
+ },
77
+ "./string-utils": {
78
+ "types": "./dist/string-helpers.d.ts",
79
+ "import": "./dist/string-helpers.js"
80
+ },
81
+ "./token-types": {
82
+ "types": "./dist/token-types.d.ts",
83
+ "import": "./dist/token-types.js"
72
84
  }
73
85
  },
74
86
  "publishConfig": {
@@ -87,7 +99,7 @@
87
99
  "postcss": "^8.5.29",
88
100
  "publint": "^0.3.25",
89
101
  "tinybench": "^6.2.1",
90
- "tsdown": "^0.23.0",
102
+ "tsdown": "^0.23.1",
91
103
  "typescript": "^7.0.2",
92
104
  "vite": "^8.3.4",
93
105
  "vitest": "^5.0.3"
@@ -101,10 +113,11 @@
101
113
  "test-coverage": "vitest --coverage",
102
114
  "test-build": "pnpm run build && vitest run --config vitest.config.build.ts",
103
115
  "build": "tsdown",
104
- "benchmark": "pnpm run build && node --expose-gc benchmark/index.ts",
116
+ "benchmark:compare": "pnpm run build && node --expose-gc benchmark/comparison.ts",
117
+ "benchmark": "pnpm run build && node --expose-gc benchmark/parsing.ts",
105
118
  "lint": "oxlint --config .oxlintrc.json && oxfmt --check",
106
119
  "check": "tsc --noEmit",
107
120
  "knip": "knip",
108
- "precommit": "pnpm run test --run; pnpm run lint; pnpm run check"
121
+ "precommit": "pnpm run test --run && pnpm run lint && pnpm run check && pnpm knip"
109
122
  }
110
123
  }
@@ -1,134 +0,0 @@
1
- //#region src/token-types.d.ts
2
- declare const TOKEN_IDENT = 1;
3
- declare const TOKEN_FUNCTION = 2;
4
- declare const TOKEN_AT_KEYWORD = 3;
5
- declare const TOKEN_HASH = 4;
6
- declare const TOKEN_STRING = 5;
7
- declare const TOKEN_BAD_STRING = 6;
8
- declare const TOKEN_URL = 7;
9
- declare const TOKEN_BAD_URL = 8;
10
- declare const TOKEN_DELIM = 9;
11
- declare const TOKEN_NUMBER = 10;
12
- declare const TOKEN_PERCENTAGE = 11;
13
- declare const TOKEN_DIMENSION = 12;
14
- declare const TOKEN_WHITESPACE = 13;
15
- declare const TOKEN_CDO = 14;
16
- declare const TOKEN_CDC = 15;
17
- declare const TOKEN_COLON = 16;
18
- declare const TOKEN_SEMICOLON = 17;
19
- declare const TOKEN_COMMA = 18;
20
- declare const TOKEN_LEFT_BRACKET = 19;
21
- declare const TOKEN_RIGHT_BRACKET = 20;
22
- declare const TOKEN_LEFT_PAREN = 21;
23
- declare const TOKEN_RIGHT_PAREN = 22;
24
- declare const TOKEN_LEFT_BRACE = 23;
25
- declare const TOKEN_RIGHT_BRACE = 24;
26
- declare const TOKEN_COMMENT = 25;
27
- declare const TOKEN_EOF = 26;
28
- declare const TOKEN_UNICODE_RANGE = 27;
29
- type TokenType = typeof TOKEN_IDENT | typeof TOKEN_FUNCTION | typeof TOKEN_AT_KEYWORD | typeof TOKEN_HASH | typeof TOKEN_STRING | typeof TOKEN_BAD_STRING | typeof TOKEN_URL | typeof TOKEN_BAD_URL | typeof TOKEN_DELIM | typeof TOKEN_NUMBER | typeof TOKEN_PERCENTAGE | typeof TOKEN_DIMENSION | typeof TOKEN_WHITESPACE | typeof TOKEN_CDO | typeof TOKEN_CDC | typeof TOKEN_COLON | typeof TOKEN_SEMICOLON | typeof TOKEN_COMMA | typeof TOKEN_LEFT_BRACKET | typeof TOKEN_RIGHT_BRACKET | typeof TOKEN_LEFT_PAREN | typeof TOKEN_RIGHT_PAREN | typeof TOKEN_LEFT_BRACE | typeof TOKEN_RIGHT_BRACE | typeof TOKEN_COMMENT | typeof TOKEN_EOF | typeof TOKEN_UNICODE_RANGE;
30
- type Token = {
31
- type: TokenType;
32
- start: number;
33
- end: number;
34
- line: number;
35
- column: number;
36
- };
37
- //#endregion
38
- //#region src/tokenize.d.ts
39
- interface LexerPosition {
40
- pos: number;
41
- line: number;
42
- column: number;
43
- _line_offset: number;
44
- token_type: TokenType;
45
- token_start: number;
46
- token_end: number;
47
- token_line: number;
48
- token_column: number;
49
- }
50
- interface CommentInfo {
51
- start: number;
52
- end: number;
53
- length: number;
54
- line: number;
55
- column: number;
56
- }
57
- /** @internal */
58
- declare class Lexer {
59
- source: string;
60
- pos: number;
61
- private _line;
62
- private _line_offset;
63
- on_comment: ((info: CommentInfo) => void) | undefined;
64
- token_type: TokenType;
65
- token_start: number;
66
- token_end: number;
67
- token_line: number;
68
- token_column: number;
69
- constructor(source: string, on_comment?: (info: CommentInfo) => void);
70
- get line(): number;
71
- get column(): number;
72
- seek(pos: number, line: number, column?: number): void;
73
- next_token_fast(skip_whitespace?: boolean): TokenType;
74
- private _scan_newlines;
75
- private _skip_comment;
76
- /**
77
- * Fast-forward to the next `target` char that isn't inside a string or comment, without
78
- * fully tokenizing what's in between — used by callers that only need to know *where a
79
- * construct ends* (e.g. a selector's `{`), since the sub-parser for that construct
80
- * re-tokenizes the span properly afterward.
81
- *
82
- * Strings go through consume_string and comments through _skip_comment, so escapes and
83
- * on_comment callbacks behave identically to real tokenization. Ordinary characters cost
84
- * one SKIP_SCAN_INTERESTING lookup each, same as consume_ident_or_function's inner loop.
85
- *
86
- * Returns true with this.pos at target, or false with this.pos at source_length.
87
- */
88
- skip_to_unquoted(target: number): boolean;
89
- /**
90
- * Same approach as skip_to_unquoted, but stops at any of `; { } ( ) !` — the stop
91
- * characters parse-declaration.ts's value scan needs (paren depth, statement end,
92
- * !important). The caller decides what each one means; this only locates the next one.
93
- *
94
- * Returns the stop character's code (this.pos left at it), or 0 at `end` if none found.
95
- */
96
- skip_to_declaration_stop(end: number): number;
97
- consume_whitespace(start_line: number, start_column: number): TokenType;
98
- consume_string(quote: number, start_line: number, start_column: number): TokenType;
99
- consume_hex_escape(): void;
100
- consume_number(start_line: number, start_column: number): TokenType;
101
- consume_ident_or_function(start_line: number, start_column: number): TokenType;
102
- consume_unicode_range(start: number, start_line: number, start_column: number): TokenType;
103
- consume_at_keyword(start_line: number, start_column: number): TokenType;
104
- consume_hash(start_line: number, start_column: number): TokenType;
105
- advance(count?: number): void;
106
- peek(offset?: number): number;
107
- make_token(type: TokenType, start: number, end: number, line?: number, column?: number): TokenType;
108
- next_token(skip_whitespace?: boolean): Token | null;
109
- /**
110
- * Save complete lexer state for backtracking
111
- * @returns Object containing all lexer state
112
- */
113
- save_position(): LexerPosition;
114
- save_position_into(target: LexerPosition): LexerPosition;
115
- /**
116
- * Restore lexer state from saved position
117
- * @param saved The saved position to restore
118
- */
119
- restore_position(saved: LexerPosition): void;
120
- /**
121
- * Skip whitespace and comments within a range, maintaining line/column tracking
122
- * @param end The end boundary (exclusive)
123
- */
124
- skip_whitespace_in_range(end: number): void;
125
- }
126
- /**
127
- * Tokenize CSS source code
128
- * @param source - The CSS source code to tokenize
129
- * @param on_comment - Optional callback for comment tokens
130
- * @yields CSS tokens
131
- */
132
- declare function tokenize(source: string, on_comment?: (info: CommentInfo) => void): Generator<Token, void, undefined>;
133
- //#endregion
134
- export { TOKEN_URL as A, TOKEN_PERCENTAGE as C, TOKEN_SEMICOLON as D, TOKEN_RIGHT_PAREN as E, Token as M, TokenType as N, TOKEN_STRING as O, TOKEN_NUMBER as S, TOKEN_RIGHT_BRACKET as T, TOKEN_HASH as _, TOKEN_AT_KEYWORD as a, TOKEN_LEFT_BRACKET as b, TOKEN_CDC as c, TOKEN_COMMA as d, TOKEN_COMMENT as f, TOKEN_FUNCTION as g, TOKEN_EOF as h, tokenize as i, TOKEN_WHITESPACE as j, TOKEN_UNICODE_RANGE as k, TOKEN_CDO as l, TOKEN_DIMENSION as m, Lexer as n, TOKEN_BAD_STRING as o, TOKEN_DELIM as p, LexerPosition as r, TOKEN_BAD_URL as s, CommentInfo as t, TOKEN_COLON as u, TOKEN_IDENT as v, TOKEN_RIGHT_BRACE as w, TOKEN_LEFT_PAREN as x, TOKEN_LEFT_BRACE as y };