@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.
Files changed (53) hide show
  1. package/CHANGELOG.md +28 -3
  2. package/dist/index-umd-web.js +12897 -13217
  3. package/dist/index.cjs +10394 -10716
  4. package/dist/index.d.ts +816 -89
  5. package/dist/lib/ast/features/calc.js +3 -1
  6. package/dist/lib/ast/features/if.js +2 -96
  7. package/dist/lib/ast/features/prefix.js +7 -2
  8. package/dist/lib/ast/features/shorthand.js +1 -1
  9. package/dist/lib/ast/features/transform.js +1 -1
  10. package/dist/lib/ast/find.js +6 -6
  11. package/dist/lib/ast/math/expression.js +30 -12
  12. package/dist/lib/ast/minify.js +34 -5
  13. package/dist/lib/ast/transform/perspective.js +1 -1
  14. package/dist/lib/ast/transform/utils.js +29 -21
  15. package/dist/lib/ast/types.js +8 -0
  16. package/dist/lib/fs/resolve.js +1 -16
  17. package/dist/lib/parser/declaration/list.js +6 -1
  18. package/dist/lib/parser/{linemap.js → linesmap.js} +25 -9
  19. package/dist/lib/parser/parse.js +1264 -151
  20. package/dist/lib/parser/source.js +48 -17
  21. package/dist/lib/parser/tokenize.js +112 -133
  22. package/dist/lib/parser/utils/at-rule-container.js +12 -44
  23. package/dist/lib/parser/utils/at-rule-generic.js +12 -24
  24. package/dist/lib/parser/utils/at-rule-import.js +4 -172
  25. package/dist/lib/parser/utils/at-rule-media.js +14 -251
  26. package/dist/lib/parser/utils/at-rule-support.js +8 -258
  27. package/dist/lib/parser/utils/at-rule-when-else.js +4 -214
  28. package/dist/lib/parser/utils/declaration.js +5 -95
  29. package/dist/lib/parser/utils/hash.js +54 -1
  30. package/dist/lib/parser/utils/selector.js +1 -1
  31. package/dist/lib/parser/utils/token.js +1 -0
  32. package/dist/lib/renderer/render.js +76 -43
  33. package/dist/lib/renderer/sourcemap/sourcemap.js +47 -43
  34. package/dist/lib/syntax/color/cmyk.js +3 -3
  35. package/dist/lib/syntax/color/color-mix.js +7 -7
  36. package/dist/lib/syntax/color/color.js +7 -7
  37. package/dist/lib/syntax/color/hsl.js +6 -6
  38. package/dist/lib/syntax/color/hwb.js +6 -6
  39. package/dist/lib/syntax/color/lab.js +5 -5
  40. package/dist/lib/syntax/color/lch.js +6 -6
  41. package/dist/lib/syntax/color/oklab.js +5 -5
  42. package/dist/lib/syntax/color/oklch.js +5 -5
  43. package/dist/lib/syntax/color/relative-color.js +8 -1
  44. package/dist/lib/syntax/color/utils/distance.js +2 -2
  45. package/dist/lib/syntax/constants.js +2 -1
  46. package/dist/lib/syntax/syntax.js +11 -8
  47. package/dist/lib/validation/config.json.js +27 -6
  48. package/dist/lib/validation/match.js +42 -845
  49. package/dist/node.js +134 -9
  50. package/dist/web.js +133 -6
  51. package/llms.txt +73 -0
  52. package/package.json +13 -16
  53. package/dist/lib/parser/arena.js +0 -206
@@ -1,206 +0,0 @@
1
- import { EnumToken } from '../ast/types.js';
2
- import { SourceFile } from './source.js';
3
-
4
- // Node Data layout
5
- // (node area)
6
- // node type -> 1 byte
7
- // parent -> 4 bytes
8
- // firstChild -> 4 bytes
9
- // nextSibling -> 4 bytes
10
- // firstToken -> 4 bytes // parsed selector or at-rule prelude
11
- // nextToken -> 4 bytes
12
- // resolvedTokens -> 4 bytes // selector or at-rule prelude as string
13
- // flags -> 1 byte (validation state, resolved state, resolved prelude state, decoded string state)
14
- // SpanArena: (start offset 26)
15
- // sourceId -> 2 bytes
16
- // sourceSpanStart -> 4 byte
17
- // sourceSpanLength -> 4 bytes
18
- // payloadOffset -> 4 bytes
19
- // payloadType -> 1 byte
20
- // (data area)
21
- // data -> (start offset 41): union of ColorArena (ColorKind, r, g, b, a) | string intern id | number | DimensionArena
22
- // ColorArena (11 bytes):
23
- // ColorType -> 1 byte
24
- // resolved -> 4 bytes
25
- // componentsCount -> 1 byte
26
- // components -> 3 to 5 bytes (r,g,b / l, c, h / h , w, b / x, y, z / h, s, l), alpha or (c, m, y, k, alpha)
27
- // DimensionArena (8 bytes):
28
- // value -> 4 bytes
29
- // unit -> 4 bytes
30
- // String (4 bytes):
31
- // string id -> 4 bytes
32
- // Number (4 bytes):
33
- // number -> 4 bytes
34
- // Percentage (4 bytes):
35
- // number -> 4 bytes
36
- // absolute sizes
37
- const NODE_AREA_SIZE = 41;
38
- const COLOR_AREA_SIZE = 11;
39
- const DIMENSION_AREA_SIZE = 8;
40
- const STRING_AREA_SIZE = 4;
41
- const NUMBER_AREA_SIZE = 4;
42
- const PERCENTAGE_AREA_SIZE = 4;
43
- const NODE_SPAN_OFFSET = 26;
44
- const NODE_PAYLOAD_OFFSET = 36;
45
- const NODE_PAYLOAD_TYPE_OFFSET = 40;
46
- // relative offsets
47
- const COLOR_TYPE_OFFSET = 0;
48
- const COLOR_RESOLVED_OFFSET = 1;
49
- const COLOR_COMPONENTS_COUNT_OFFSET = 5;
50
- const COLOR_COMPONENTS_OFFSET = 6;
51
- var PayloadType;
52
- (function (PayloadType) {
53
- PayloadType[PayloadType["Unset"] = 0] = "Unset";
54
- PayloadType[PayloadType["Color"] = 1] = "Color";
55
- PayloadType[PayloadType["Dimension"] = 2] = "Dimension";
56
- PayloadType[PayloadType["String"] = 3] = "String";
57
- PayloadType[PayloadType["Number"] = 4] = "Number";
58
- PayloadType[PayloadType["Percentage"] = 5] = "Percentage";
59
- })(PayloadType || (PayloadType = {}));
60
- class Arena {
61
- capacity;
62
- buffer;
63
- view;
64
- count = NODE_AREA_SIZE; // node 0 = null
65
- // root ast node
66
- sources = [];
67
- strings;
68
- constructor(strings, size = 1024) {
69
- // Heuristic: one node per source character.
70
- this.capacity = Math.max(1024, size >>> 0);
71
- this.buffer = new ArrayBuffer(this.capacity * NODE_AREA_SIZE);
72
- this.view = new DataView(this.buffer);
73
- this.strings = strings;
74
- }
75
- get root() {
76
- return this.view.getInt32(NODE_AREA_SIZE);
77
- }
78
- allocateRoot() {
79
- if (this.root !== 0) {
80
- throw new Error("Root node already allocated");
81
- }
82
- return this.allocate(EnumToken.StyleSheetNodeType);
83
- }
84
- // =====================================================================
85
- // === API ===
86
- // ====================================================================
87
- getFile(id) {
88
- return this.sources[id].getFile();
89
- }
90
- getPosition(id) {
91
- return this.sources[this.view.getInt16(id + NODE_SPAN_OFFSET)].position(this.view.getInt16(id + NODE_SPAN_OFFSET + 2));
92
- }
93
- addSource(content, lines, file = null) {
94
- this.sources.push(new SourceFile(this.sources.length, content, lines, file));
95
- return this.sources[this.sources.length - 1];
96
- }
97
- allocate(type) {
98
- if (this.count + NODE_AREA_SIZE >= this.capacity) {
99
- this.grow();
100
- }
101
- const node = this.count;
102
- this.count += NODE_AREA_SIZE;
103
- this.view.setUint8(node, type);
104
- // Other arrays are already zero-initialized.
105
- // if (typeof data === "string") {
106
- // this.data[node] = this.allocate(EnumToken.ValueTokenType, this.strings.intern(data));
107
- // } else if (typeof data === "number") {
108
- // this.data[node] = this.allocate(EnumToken.ValueTokenType, data);
109
- // }
110
- return node;
111
- }
112
- allocateNumber(id, data) {
113
- if (this.view.getUint8(id + NODE_PAYLOAD_TYPE_OFFSET) === PayloadType.Number) {
114
- this.view.setFloat32(this.view.getInt32(id + NODE_PAYLOAD_OFFSET), data);
115
- return;
116
- }
117
- if (this.count + NUMBER_AREA_SIZE >= this.capacity) {
118
- this.grow();
119
- }
120
- this.view.setUint8(id + NODE_PAYLOAD_TYPE_OFFSET, PayloadType.Number);
121
- this.view.setInt32(id + NODE_PAYLOAD_OFFSET, this.count);
122
- this.view.setFloat32(this.count, data);
123
- this.count += NUMBER_AREA_SIZE;
124
- }
125
- allocatePercentage(id, data) {
126
- if (this.view.getUint8(id + NODE_PAYLOAD_TYPE_OFFSET) === PayloadType.Percentage) {
127
- this.view.setFloat32(this.view.getInt32(id + NODE_PAYLOAD_OFFSET), data);
128
- return;
129
- }
130
- if (this.count + PERCENTAGE_AREA_SIZE >= this.capacity) {
131
- this.grow();
132
- }
133
- this.view.setUint8(id + NODE_PAYLOAD_TYPE_OFFSET, PayloadType.Percentage);
134
- this.view.setInt32(id + NODE_PAYLOAD_OFFSET, this.count);
135
- this.view.setFloat32(this.count, data);
136
- this.count += PERCENTAGE_AREA_SIZE;
137
- }
138
- allocateString(id, data) {
139
- if (this.view.getUint8(id + NODE_PAYLOAD_TYPE_OFFSET) === PayloadType.String) {
140
- this.view.setInt32(this.view.getInt32(id + NODE_PAYLOAD_OFFSET), this.strings.intern(data));
141
- return;
142
- }
143
- if (this.count + STRING_AREA_SIZE >= this.capacity) {
144
- this.grow();
145
- }
146
- this.view.setUint8(id + NODE_PAYLOAD_TYPE_OFFSET, PayloadType.String);
147
- this.view.setInt32(id + NODE_PAYLOAD_OFFSET, this.count);
148
- this.view.setInt32(this.count, this.strings.intern(data));
149
- this.count += STRING_AREA_SIZE;
150
- }
151
- allocateDimension(id, value, dimension) {
152
- if (this.view.getUint8(id + NODE_PAYLOAD_TYPE_OFFSET) === PayloadType.Dimension) {
153
- const offset = this.view.getInt32(id + NODE_PAYLOAD_OFFSET);
154
- this.view.setFloat32(offset, value);
155
- this.view.setInt32(offset + 4, this.strings.intern(dimension));
156
- return;
157
- }
158
- if (this.count + DIMENSION_AREA_SIZE >= this.capacity) {
159
- this.grow();
160
- }
161
- this.view.setUint8(id + NODE_PAYLOAD_TYPE_OFFSET, PayloadType.Dimension);
162
- this.view.setInt32(id + NODE_PAYLOAD_OFFSET, this.count);
163
- this.view.setFloat32(this.count, value);
164
- this.view.setFloat32(this.count + 4, this.strings.intern(dimension));
165
- this.count += DIMENSION_AREA_SIZE;
166
- }
167
- allocateColor(id, type) {
168
- if (this.view.getUint8(id + NODE_PAYLOAD_TYPE_OFFSET) === PayloadType.Color) {
169
- this.view.setUint8(this.view.getInt32(id + NODE_PAYLOAD_OFFSET) + COLOR_TYPE_OFFSET, type);
170
- return;
171
- }
172
- if (this.count + COLOR_AREA_SIZE >= this.capacity) {
173
- this.grow();
174
- }
175
- this.view.setUint8(id + NODE_PAYLOAD_TYPE_OFFSET, PayloadType.Color);
176
- this.view.setInt32(id + NODE_PAYLOAD_OFFSET, this.count);
177
- this.view.setUint8(this.view.getInt32(id + NODE_PAYLOAD_OFFSET) + COLOR_TYPE_OFFSET, type);
178
- this.count += COLOR_AREA_SIZE;
179
- }
180
- resolveColor(id, resolved) {
181
- this.view.setInt32(this.view.getInt32(id + NODE_PAYLOAD_OFFSET) + COLOR_RESOLVED_OFFSET, this.strings.intern(resolved));
182
- }
183
- setColorComponents(id, data) {
184
- const offset = this.view.getInt32(id + NODE_PAYLOAD_OFFSET);
185
- this.view.setUint8(offset + COLOR_COMPONENTS_COUNT_OFFSET, data.length);
186
- for (let i = 0; i < data.length; i++) {
187
- this.view.setUint8(offset + COLOR_COMPONENTS_OFFSET + i, data[i]);
188
- }
189
- }
190
- setSpans(id, sourceId, start, end) {
191
- const offset = id + NODE_SPAN_OFFSET;
192
- this.view.setInt16(offset, sourceId);
193
- this.view.setInt32(offset + 2, start);
194
- this.view.setInt32(offset + 6, end);
195
- }
196
- grow() {
197
- const newCapacity = this.capacity * 2;
198
- const buffer = new ArrayBuffer(newCapacity);
199
- this.view = new DataView(buffer);
200
- new Uint8Array(buffer).set(new Uint8Array(this.buffer));
201
- this.buffer = buffer;
202
- this.capacity = newCapacity;
203
- }
204
- }
205
-
206
- export { Arena };