@projectwallace/css-design-tokens 0.11.0 → 0.11.2

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.
@@ -1,1559 +0,0 @@
1
- import { cssKeywords as nt, colorKeywords as rt, namedColors as ot, systemColors as ht, colorFunctions as lt, analyze as at } from "@projectwallace/css-analyzer";
2
- import { convert as ut } from "css-time-sort";
3
- import { convert as _t } from "color-sorter";
4
- import { ColorSpace as a, sRGB as ct, XYZ_D65 as ft, XYZ_D50 as dt, XYZ_ABS_D65 as pt, Lab_D65 as gt, Lab as mt, LCH as vt, sRGB_Linear as Et, HSL as At, HWB as kt, HSV as xt, P3_Linear as Ct, P3 as Rt, A98RGB_Linear as wt, A98RGB as yt, ProPhoto_Linear as bt, ProPhoto as Tt, REC_2020_Linear as Ot, REC_2020 as Nt, OKLab as St, OKLCH as Lt, OKLrab as Ht, tryColor as $t } from "colorjs.io/fn";
5
- import { parse_value as He } from "@projectwallace/css-parser";
6
- const $e = 0, Ue = 1, Ie = 2, he = 3, Pe = 4, Fe = 5, De = 6, Ke = 7, Me = 8, Ge = 9, Be = 10, W = 11, Ut = /* @__PURE__ */ new Map([
7
- [$e, "white"],
8
- [Ue, "black"],
9
- [Ie, "grey"],
10
- [he, "red"],
11
- [Pe, "orange"],
12
- [Fe, "yellow"],
13
- [De, "green"],
14
- [Ke, "cyan"],
15
- [Me, "blue"],
16
- [Ge, "magenta"],
17
- [Be, "pink"],
18
- [W, "unknown"]
19
- ]);
20
- function It(r) {
21
- let e = /* @__PURE__ */ new Map();
22
- for (let t in r) {
23
- let s = W;
24
- if (!t.includes("var(") && !t.includes("calc(")) {
25
- let i = _t(t), { hue: n, saturation: o, lightness: h } = i;
26
- o < 10 && h === 100 ? s = $e : o < 10 && h === 0 ? s = Ue : o < 5 ? s = Ie : n < 22 ? s = he : n < 50 ? s = Pe : n < 72 ? s = Fe : n < 144 ? s = De : n < 180 ? s = Ke : n < 250 ? s = Me : n < 300 ? s = Ge : n < 350 ? s = Be : s = he;
27
- }
28
- e.has(s) ? e.get(s).push(t) : e.set(s, [t]);
29
- }
30
- return Array.from(e).sort(
31
- (t, s) => t[0] === W || s[0] === W ? -1 : s[1].length - t[1].length
32
- );
33
- }
34
- let de = 1, p = 2, ee = 4, S = 8, y = 16, l = new Uint8Array(128);
35
- for (let r = 48; r <= 57; r++)
36
- l[r] = p;
37
- for (let r = 48; r <= 57; r++)
38
- l[r] |= ee;
39
- for (let r = 65; r <= 70; r++)
40
- l[r] = ee;
41
- for (let r = 97; r <= 102; r++)
42
- l[r] = ee;
43
- for (let r = 65; r <= 90; r++)
44
- l[r] |= de;
45
- for (let r = 97; r <= 122; r++)
46
- l[r] |= de;
47
- l[32] = S;
48
- l[9] = S;
49
- l[10] = y;
50
- l[13] = y;
51
- l[12] = y;
52
- function Pt(r) {
53
- return r < 128 && (l[r] & p) !== 0;
54
- }
55
- function K(r) {
56
- return r < 128 && (l[r] & ee) !== 0;
57
- }
58
- function Ft(r) {
59
- return r < 128 && (l[r] & de) !== 0;
60
- }
61
- function Ae(r) {
62
- return r < 128 && (l[r] & S) !== 0;
63
- }
64
- function C(r) {
65
- return r < 128 && (l[r] & y) !== 0;
66
- }
67
- function P(r) {
68
- return r >= 128 || r === 95 ? !0 : Ft(r);
69
- }
70
- function M(r) {
71
- return r === 45 ? !0 : P(r) || Pt(r);
72
- }
73
- const Ye = 1, le = 2, Dt = 3, We = 4, ae = 5, ke = 6, qe = 9, je = 10, Xe = 11, ze = 12, Kt = 13, Mt = 14, Gt = 15, Bt = 16, Yt = 17, Qe = 18, Wt = 19, qt = 20, ue = 21, q = 22, jt = 23, Xt = 24, O = 26, zt = 123, Qt = 125, Vt = 58, Zt = 59, Jt = 44, es = 91, ts = 93, xe = 40, ss = 41, Ce = 47, Re = 42, is = 34, ns = 39, te = 46, rs = 60, os = 33, g = 45, hs = 62, ls = 64, as = 35, se = 92, G = 43, us = 37, _s = 101, cs = 69, we = 13, ye = 10;
74
- class fs {
75
- source;
76
- pos;
77
- line;
78
- column;
79
- on_comment;
80
- // Current token properties (avoiding object allocation)
81
- token_type;
82
- token_start;
83
- token_end;
84
- token_line;
85
- token_column;
86
- constructor(e, t) {
87
- this.source = e, this.pos = 0, this.line = 1, this.column = 1, this.on_comment = t, this.token_type = O, this.token_start = 0, this.token_end = 0, this.token_line = 1, this.token_column = 1;
88
- }
89
- // Fast token advancing without object allocation (for internal parser use)
90
- next_token_fast(e = !1) {
91
- if (e)
92
- for (; this.pos < this.source.length; ) {
93
- let o = this.source.charCodeAt(this.pos);
94
- if (o >= 128 || (l[o] & (S | y)) === 0) break;
95
- this.advance();
96
- }
97
- if (this.pos >= this.source.length)
98
- return this.make_token(O, this.pos, this.pos);
99
- let t = this.source.charCodeAt(this.pos), s = this.pos, i = this.line, n = this.column;
100
- switch (t) {
101
- case zt:
102
- return this.advance(), this.make_token(jt, s, this.pos, i, n);
103
- case Qt:
104
- return this.advance(), this.make_token(Xt, s, this.pos, i, n);
105
- case Vt:
106
- return this.advance(), this.make_token(Bt, s, this.pos, i, n);
107
- case Zt:
108
- return this.advance(), this.make_token(Yt, s, this.pos, i, n);
109
- case Jt:
110
- return this.advance(), this.make_token(Qe, s, this.pos, i, n);
111
- case es:
112
- return this.advance(), this.make_token(Wt, s, this.pos, i, n);
113
- case ts:
114
- return this.advance(), this.make_token(qt, s, this.pos, i, n);
115
- case xe:
116
- return this.advance(), this.make_token(ue, s, this.pos, i, n);
117
- case ss:
118
- return this.advance(), this.make_token(q, s, this.pos, i, n);
119
- }
120
- if (t < 128 && (l[t] & (S | y)) !== 0)
121
- return this.consume_whitespace(i, n);
122
- if (t === Ce && this.peek() === Re) {
123
- let o = s, h = i, u = n;
124
- for (this.advance(2); this.pos < this.source.length - 1; ) {
125
- if (this.source.charCodeAt(this.pos) === Re && this.peek() === Ce) {
126
- this.advance(2);
127
- break;
128
- }
129
- this.advance();
130
- }
131
- let f = this.pos;
132
- return this.on_comment && this.on_comment({
133
- start: o,
134
- end: f,
135
- length: f - o,
136
- line: h,
137
- column: u
138
- }), this.next_token_fast(e);
139
- }
140
- if (t === is || t === ns)
141
- return this.consume_string(t, i, n);
142
- if (t < 128 && (l[t] & p) !== 0)
143
- return this.consume_number(i, n);
144
- if (t === te) {
145
- let o = this.peek();
146
- if (o < 128 && (l[o] & p) !== 0)
147
- return this.consume_number(i, n);
148
- }
149
- if (t === rs && this.pos + 3 < this.source.length && this.peek() === os && this.peek(2) === g && this.peek(3) === g)
150
- return this.advance(4), this.make_token(Mt, s, this.pos, i, n);
151
- if (t === g && this.pos + 2 < this.source.length && this.peek() === g && this.peek(2) === hs)
152
- return this.advance(3), this.make_token(Gt, s, this.pos, i, n);
153
- if (t === ls)
154
- return this.consume_at_keyword(i, n);
155
- if (t === as)
156
- return this.consume_hash(i, n);
157
- if (P(t))
158
- return this.consume_ident_or_function(i, n);
159
- if (t === g) {
160
- let o = this.peek();
161
- if (P(o) || o === g)
162
- return this.consume_ident_or_function(i, n);
163
- }
164
- if (t === se) {
165
- let o = this.peek();
166
- if (o !== 0 && !C(o))
167
- return this.consume_ident_or_function(i, n);
168
- }
169
- if (t === g || t === G) {
170
- let o = this.peek();
171
- if (o < 128 && (l[o] & p) !== 0)
172
- return this.consume_number(i, n);
173
- if (o === te) {
174
- let u = this.peek(2);
175
- if (u < 128 && (l[u] & p) !== 0)
176
- return this.consume_number(i, n);
177
- }
178
- }
179
- return this.advance(), this.make_token(qe, s, this.pos, i, n);
180
- }
181
- consume_whitespace(e, t) {
182
- let s = this.pos;
183
- for (; this.pos < this.source.length; ) {
184
- let i = this.source.charCodeAt(this.pos);
185
- if (i >= 128 || (l[i] & (S | y)) === 0) break;
186
- this.advance();
187
- }
188
- return this.make_token(Kt, s, this.pos, e, t);
189
- }
190
- consume_string(e, t, s) {
191
- let i = this.pos;
192
- for (this.advance(); this.pos < this.source.length; ) {
193
- let n = this.source.charCodeAt(this.pos);
194
- if (n === e)
195
- return this.advance(), this.make_token(ae, i, this.pos, t, s);
196
- if (C(n))
197
- return this.make_token(ke, i, this.pos, t, s);
198
- if (n === se) {
199
- if (this.advance(), this.pos < this.source.length) {
200
- let o = this.source.charCodeAt(this.pos);
201
- K(o) ? this.consume_hex_escape() : C(o) ? this.advance() : this.advance();
202
- }
203
- continue;
204
- }
205
- this.advance();
206
- }
207
- return this.make_token(ke, i, this.pos, t, s);
208
- }
209
- consume_hex_escape() {
210
- let e = 0;
211
- for (; e < 6 && this.pos < this.source.length; ) {
212
- let t = this.source.charCodeAt(this.pos);
213
- if (!K(t)) break;
214
- this.advance(), e++;
215
- }
216
- if (this.pos < this.source.length) {
217
- let t = this.source.charCodeAt(this.pos);
218
- (Ae(t) || C(t)) && this.advance();
219
- }
220
- }
221
- consume_number(e, t) {
222
- let s = this.pos, i = this.source.charCodeAt(this.pos);
223
- for ((i === G || i === g) && this.advance(); this.pos < this.source.length; ) {
224
- let n = this.source.charCodeAt(this.pos);
225
- if (n >= 128 || (l[n] & p) === 0) break;
226
- this.advance();
227
- }
228
- if (this.pos < this.source.length && this.source.charCodeAt(this.pos) === te && this.pos + 1 < this.source.length) {
229
- let n = this.peek();
230
- if (n < 128 && (l[n] & p) !== 0)
231
- for (this.advance(); this.pos < this.source.length; ) {
232
- let o = this.source.charCodeAt(this.pos);
233
- if (o >= 128 || (l[o] & p) === 0) break;
234
- this.advance();
235
- }
236
- }
237
- if (this.pos < this.source.length) {
238
- let n = this.source.charCodeAt(this.pos);
239
- if (n === _s || n === cs) {
240
- let o = this.peek(), h = o < 128 && (l[o] & p) !== 0, u = this.peek(2), f = u < 128 && (l[u] & p) !== 0;
241
- if (h || (o === G || o === g) && f) {
242
- if (this.advance(), this.pos < this.source.length) {
243
- let d = this.source.charCodeAt(this.pos);
244
- (d === G || d === g) && this.advance();
245
- }
246
- for (; this.pos < this.source.length; ) {
247
- let d = this.source.charCodeAt(this.pos);
248
- if (d >= 128 || (l[d] & p) === 0) break;
249
- this.advance();
250
- }
251
- }
252
- }
253
- }
254
- if (this.pos < this.source.length) {
255
- let n = this.source.charCodeAt(this.pos);
256
- if (n === us)
257
- return this.advance(), this.make_token(Xe, s, this.pos, e, t);
258
- if (P(n) || n === g && P(this.peek())) {
259
- for (; this.pos < this.source.length && M(this.source.charCodeAt(this.pos)); )
260
- this.advance();
261
- return this.make_token(ze, s, this.pos, e, t);
262
- }
263
- }
264
- return this.make_token(je, s, this.pos, e, t);
265
- }
266
- consume_ident_or_function(e, t) {
267
- let s = this.pos;
268
- for (; this.pos < this.source.length; ) {
269
- let i = this.source.charCodeAt(this.pos);
270
- if (i === se) {
271
- if (this.pos + 1 >= this.source.length) break;
272
- let n = this.peek();
273
- if (C(n)) break;
274
- if (this.advance(), K(n)) {
275
- this.advance();
276
- for (let o = 0; o < 5 && this.pos < this.source.length && K(this.source.charCodeAt(this.pos)); o++)
277
- this.advance();
278
- if (this.pos < this.source.length) {
279
- let o = this.source.charCodeAt(this.pos);
280
- (Ae(o) || C(o)) && this.advance();
281
- }
282
- } else
283
- this.advance();
284
- } else if (M(i))
285
- this.advance();
286
- else
287
- break;
288
- }
289
- return this.pos < this.source.length && this.source.charCodeAt(this.pos) === xe ? (this.advance(), this.make_token(le, s, this.pos, e, t)) : this.make_token(Ye, s, this.pos, e, t);
290
- }
291
- consume_at_keyword(e, t) {
292
- let s = this.pos;
293
- for (this.advance(); this.pos < this.source.length && M(this.source.charCodeAt(this.pos)); )
294
- this.advance();
295
- return this.make_token(Dt, s, this.pos, e, t);
296
- }
297
- consume_hash(e, t) {
298
- let s = this.pos;
299
- for (this.advance(); this.pos < this.source.length && M(this.source.charCodeAt(this.pos)); )
300
- this.advance();
301
- return this.make_token(We, s, this.pos, e, t);
302
- }
303
- advance(e = 1) {
304
- if (e === 1) {
305
- if (this.pos >= this.source.length) return;
306
- let t = this.source.charCodeAt(this.pos);
307
- this.pos++, C(t) ? (t === we && this.pos < this.source.length && this.source.charCodeAt(this.pos) === ye && this.pos++, this.line++, this.column = 1) : this.column++;
308
- return;
309
- }
310
- for (let t = 0; t < e && !(this.pos >= this.source.length); t++) {
311
- let s = this.source.charCodeAt(this.pos);
312
- this.pos++, C(s) ? (s === we && this.pos < this.source.length && this.source.charCodeAt(this.pos) === ye && (this.pos++, t++), this.line++, this.column = 1) : this.column++;
313
- }
314
- }
315
- peek(e = 1) {
316
- let t = this.pos + e;
317
- return t >= this.source.length ? 0 : this.source.charCodeAt(t);
318
- }
319
- make_token(e, t, s, i = this.line, n = this.column) {
320
- return this.token_type = e, this.token_start = t, this.token_end = s, this.token_line = i, this.token_column = n, e;
321
- }
322
- // Public API: returns Token object for backwards compatibility
323
- next_token(e = !1) {
324
- return this.next_token_fast(e), {
325
- type: this.token_type,
326
- start: this.token_start,
327
- end: this.token_end,
328
- line: this.token_line,
329
- column: this.token_column
330
- };
331
- }
332
- /**
333
- * Save complete lexer state for backtracking
334
- * @returns Object containing all lexer state
335
- */
336
- save_position() {
337
- return {
338
- pos: this.pos,
339
- line: this.line,
340
- column: this.column,
341
- token_type: this.token_type,
342
- token_start: this.token_start,
343
- token_end: this.token_end,
344
- token_line: this.token_line,
345
- token_column: this.token_column
346
- };
347
- }
348
- /**
349
- * Restore lexer state from saved position
350
- * @param saved The saved position to restore
351
- */
352
- restore_position(e) {
353
- this.pos = e.pos, this.line = e.line, this.column = e.column, this.token_type = e.token_type, this.token_start = e.token_start, this.token_end = e.token_end, this.token_line = e.token_line, this.token_column = e.token_column;
354
- }
355
- }
356
- let B = 36;
357
- const ds = 1, j = 2, F = 3, R = 4, ps = 5, Ve = 6, X = 7, pe = 10, Z = 11, D = 12, ge = 13, Ze = 14, me = 15, _e = 16, Je = 17, ve = 18, ce = 19, et = 20, gs = 21, ms = 22, vs = 23, z = 24, Q = 25, fe = 26, Es = 27, As = 28, ks = 29, V = 30, w = 31, xs = 56, Cs = 32, Rs = 33, ws = 34, ys = 35, bs = 36, Ts = 37, Os = 38, Ns = 39, tt = 40, Ss = 1, Ls = 2, be = 4, Hs = 8, $s = 32, Us = 64, Is = 128;
358
- class L {
359
- buffer;
360
- view;
361
- capacity;
362
- // Number of nodes that can fit
363
- count;
364
- // Number of nodes currently allocated
365
- growth_count;
366
- // Number of times the arena has grown
367
- overflow_lengths;
368
- // Stores actual lengths for nodes > 65535 chars
369
- // Growth multiplier when capacity is exceeded
370
- static GROWTH_FACTOR = 1.3;
371
- // Estimated nodes per KB of CSS (based on real-world data)
372
- // Increased from 270 to 325 to account for VALUE wrapper nodes
373
- // (~20% of nodes are declarations, +1 VALUE node per declaration = +20% nodes)
374
- static NODES_PER_KB = 325;
375
- // Buffer to avoid frequent growth (15%)
376
- static CAPACITY_BUFFER = 1.2;
377
- constructor(e = 1024) {
378
- this.capacity = e, this.count = 1, this.growth_count = 0, this.buffer = new ArrayBuffer(e * B), this.view = new DataView(this.buffer), this.overflow_lengths = /* @__PURE__ */ new Map();
379
- }
380
- // Calculate recommended initial capacity based on CSS source size
381
- static capacity_for_source(e) {
382
- let t = e / 1024, s = Math.ceil(t * L.NODES_PER_KB), i = Math.ceil(s * L.CAPACITY_BUFFER);
383
- return Math.max(16, i);
384
- }
385
- // Get the number of nodes currently in the arena
386
- get_count() {
387
- return this.count;
388
- }
389
- // Get the capacity (max nodes without reallocation)
390
- get_capacity() {
391
- return this.capacity;
392
- }
393
- // Get the number of times the arena has grown
394
- get_growth_count() {
395
- return this.growth_count;
396
- }
397
- // Calculate byte offset for a node
398
- node_offset(e) {
399
- return e * B;
400
- }
401
- // Read node type
402
- get_type(e) {
403
- return this.view.getUint8(this.node_offset(e));
404
- }
405
- // Read node flags
406
- get_flags(e) {
407
- return this.view.getUint8(this.node_offset(e) + 1);
408
- }
409
- // Read start offset in source
410
- get_start_offset(e) {
411
- return this.view.getUint32(this.node_offset(e) + 12, !0);
412
- }
413
- // Read length in source
414
- get_length(e) {
415
- if (this.has_flag(e, be)) {
416
- const t = this.overflow_lengths.get(e);
417
- if (t !== void 0)
418
- return t;
419
- }
420
- return this.view.getUint16(this.node_offset(e) + 2, !0);
421
- }
422
- // Read content start offset (stored as delta from startOffset)
423
- get_content_start(e) {
424
- const t = this.get_start_offset(e), s = this.view.getUint16(this.node_offset(e) + 16, !0);
425
- return t + s;
426
- }
427
- // Read content length
428
- get_content_length(e) {
429
- return this.view.getUint16(this.node_offset(e) + 20, !0);
430
- }
431
- // Read attribute operator (for NODE_SELECTOR_ATTRIBUTE)
432
- get_attr_operator(e) {
433
- return this.view.getUint8(this.node_offset(e) + 32);
434
- }
435
- // Read attribute flags (for NODE_SELECTOR_ATTRIBUTE)
436
- get_attr_flags(e) {
437
- return this.view.getUint8(this.node_offset(e) + 33);
438
- }
439
- // Read first child index (0 = no children)
440
- get_first_child(e) {
441
- return this.view.getUint32(this.node_offset(e) + 4, !0);
442
- }
443
- // Read next sibling index (0 = no sibling)
444
- get_next_sibling(e) {
445
- return this.view.getUint32(this.node_offset(e) + 8, !0);
446
- }
447
- // Read start line
448
- get_start_line(e) {
449
- return this.view.getUint32(this.node_offset(e) + 24, !0);
450
- }
451
- // Read start column
452
- get_start_column(e) {
453
- return this.view.getUint32(this.node_offset(e) + 28, !0);
454
- }
455
- // Read value start offset (stored as delta from startOffset, declaration value / at-rule prelude)
456
- get_value_start(e) {
457
- const t = this.get_start_offset(e), s = this.view.getUint16(this.node_offset(e) + 18, !0);
458
- return t + s;
459
- }
460
- // Read value length
461
- get_value_length(e) {
462
- return this.view.getUint16(this.node_offset(e) + 22, !0);
463
- }
464
- // --- Write Methods ---
465
- // Write node type
466
- set_type(e, t) {
467
- this.view.setUint8(this.node_offset(e), t);
468
- }
469
- // Write node flags
470
- set_flags(e, t) {
471
- this.view.setUint8(this.node_offset(e) + 1, t);
472
- }
473
- // Write length in source
474
- set_length(e, t) {
475
- t > 65535 ? (this.view.setUint16(this.node_offset(e) + 2, 65535, !0), this.set_flag(e, be), this.overflow_lengths.set(e, t)) : this.view.setUint16(this.node_offset(e) + 2, t, !0);
476
- }
477
- // Write content start delta (offset from startOffset)
478
- set_content_start_delta(e, t) {
479
- this.view.setUint16(this.node_offset(e) + 16, t, !0);
480
- }
481
- // Write content length
482
- set_content_length(e, t) {
483
- this.view.setUint16(this.node_offset(e) + 20, t, !0);
484
- }
485
- // Write attribute operator (for NODE_SELECTOR_ATTRIBUTE)
486
- set_attr_operator(e, t) {
487
- this.view.setUint8(this.node_offset(e) + 32, t);
488
- }
489
- // Write attribute flags (for NODE_SELECTOR_ATTRIBUTE)
490
- set_attr_flags(e, t) {
491
- this.view.setUint8(this.node_offset(e) + 33, t);
492
- }
493
- // Write first child index
494
- set_first_child(e, t) {
495
- this.view.setUint32(this.node_offset(e) + 4, t, !0);
496
- }
497
- // Write next sibling index
498
- set_next_sibling(e, t) {
499
- this.view.setUint32(this.node_offset(e) + 8, t, !0);
500
- }
501
- // Write value start delta (offset from startOffset, declaration value / at-rule prelude)
502
- set_value_start_delta(e, t) {
503
- this.view.setUint16(this.node_offset(e) + 18, t, !0);
504
- }
505
- // Write value length
506
- set_value_length(e, t) {
507
- this.view.setUint16(this.node_offset(e) + 22, t, !0);
508
- }
509
- // --- Node Creation ---
510
- // Grow the arena by 1.3x when capacity is exceeded
511
- grow() {
512
- this.growth_count++;
513
- let e = Math.ceil(this.capacity * L.GROWTH_FACTOR), t = new ArrayBuffer(e * B);
514
- new Uint8Array(t).set(new Uint8Array(this.buffer)), this.buffer = t, this.view = new DataView(t), this.capacity = e;
515
- }
516
- // Allocate and initialize a new node with core properties
517
- // Automatically grows the arena if capacity is exceeded
518
- create_node(e, t, s, i, n) {
519
- this.count >= this.capacity && this.grow();
520
- const o = this.count;
521
- this.count++;
522
- const h = o * B;
523
- return this.view.setUint8(h, e), this.view.setUint32(h + 12, t, !0), this.view.setUint32(h + 24, i, !0), this.view.setUint32(h + 28, n, !0), this.set_length(o, s), o;
524
- }
525
- // --- Tree Building Helpers ---
526
- // Link multiple child nodes to a parent
527
- // Children are linked as siblings in the order provided
528
- append_children(e, t) {
529
- if (t.length === 0) return;
530
- const s = this.node_offset(e);
531
- this.view.setUint32(s + 4, t[0], !0);
532
- for (let i = 0; i < t.length - 1; i++)
533
- this.set_next_sibling(t[i], t[i + 1]);
534
- }
535
- // Check if a node has any children
536
- has_children(e) {
537
- return this.get_first_child(e) !== 0;
538
- }
539
- // Check if a node has a next sibling
540
- has_next_sibling(e) {
541
- return this.get_next_sibling(e) !== 0;
542
- }
543
- // --- Flag Management Helpers ---
544
- // Set a specific flag bit (doesn't clear other flags)
545
- set_flag(e, t) {
546
- let s = this.get_flags(e);
547
- this.set_flags(e, s | t);
548
- }
549
- // Clear a specific flag bit (doesn't affect other flags)
550
- clear_flag(e, t) {
551
- let s = this.get_flags(e);
552
- this.set_flags(e, s & ~t);
553
- }
554
- // Check if a specific flag is set
555
- has_flag(e, t) {
556
- return (this.get_flags(e) & t) !== 0;
557
- }
558
- }
559
- const Ps = 32, Fs = 9, Ds = 10, Ks = 13, Ms = 12, Gs = 47, Bs = 42, H = 45, Ee = 43, Ys = 46;
560
- function st(r) {
561
- return r === Ps || r === Fs || r === Ds || r === Ks || r === Ms;
562
- }
563
- function ie(r) {
564
- return r >= 48 && r <= 57;
565
- }
566
- function ne(r, e) {
567
- if (r.length !== e.length)
568
- return !1;
569
- for (let t = 0; t < r.length; t++) {
570
- let s = r.charCodeAt(t), i = e.charCodeAt(t);
571
- if (i |= 32, s !== i)
572
- return !1;
573
- }
574
- return !0;
575
- }
576
- function Ws(r, e) {
577
- if (r.length < e.length)
578
- return !1;
579
- for (let t = 0; t < e.length; t++) {
580
- let s = r.charCodeAt(t), i = e.charCodeAt(t);
581
- if (s >= 65 && s <= 90 && (s |= 32), s !== i)
582
- return !1;
583
- }
584
- return !0;
585
- }
586
- function I(r, e, t) {
587
- if ((e === void 0 || t === void 0) && (e = 0, t = r.length), r.charCodeAt(e) !== H || r.charCodeAt(e + 1) === H || t - e < 3)
588
- return !1;
589
- for (let i = e + 2; i < t; i++)
590
- if (r.charCodeAt(i) === H)
591
- return !0;
592
- return !1;
593
- }
594
- function re(r) {
595
- let e = 0;
596
- for (let n = 0; n < r.length; n++) {
597
- let o = r.charCodeAt(n);
598
- if (o === 101 || o === 69) {
599
- if (n + 1 < r.length) {
600
- let h = r.charCodeAt(n + 1);
601
- if (ie(h)) {
602
- e = n + 1;
603
- continue;
604
- }
605
- if ((h === 43 || h === 45) && n + 2 < r.length) {
606
- let u = r.charCodeAt(n + 2);
607
- if (ie(u)) {
608
- e = n + 1;
609
- continue;
610
- }
611
- }
612
- }
613
- break;
614
- }
615
- if (ie(o) || o === Ys || o === H || o === Ee)
616
- e = n + 1;
617
- else
618
- break;
619
- }
620
- let t = r.substring(0, e), s = r.substring(e);
621
- return { value: t ? parseFloat(t) : 0, unit: s };
622
- }
623
- const qs = {
624
- [ds]: "StyleSheet",
625
- [j]: "Rule",
626
- [F]: "Atrule",
627
- [R]: "Declaration",
628
- [ps]: "Selector",
629
- [Ve]: "Comment",
630
- [X]: "Block",
631
- [pe]: "Identifier",
632
- [Z]: "Number",
633
- [D]: "Dimension",
634
- [ge]: "String",
635
- [Ze]: "Hash",
636
- [me]: "Function",
637
- [_e]: "Operator",
638
- [Je]: "Parentheses",
639
- [ve]: "Url",
640
- [ce]: "Value",
641
- [et]: "SelectorList",
642
- [gs]: "TypeSelector",
643
- [ms]: "ClassSelector",
644
- [vs]: "IdSelector",
645
- [z]: "AttributeSelector",
646
- [Q]: "PseudoClassSelector",
647
- [fe]: "PseudoElementSelector",
648
- [Es]: "Combinator",
649
- [As]: "UniversalSelector",
650
- [ks]: "NestingSelector",
651
- [V]: "Nth",
652
- [w]: "NthOf",
653
- [xs]: "Lang",
654
- [Cs]: "MediaQuery",
655
- [Rs]: "Feature",
656
- [ws]: "MediaType",
657
- [ys]: "ContainerQuery",
658
- [bs]: "SupportsQuery",
659
- [Ts]: "Layer",
660
- [Os]: "Operator",
661
- [Ns]: "MediaFeatureRange",
662
- [tt]: "AtrulePrelude"
663
- };
664
- class J {
665
- arena;
666
- source;
667
- index;
668
- constructor(e, t, s) {
669
- this.arena = e, this.source = t, this.index = s;
670
- }
671
- /**
672
- * @internal
673
- * Get the arena (for internal/advanced use only)
674
- */
675
- __get_arena() {
676
- return this.arena;
677
- }
678
- /** Get node type as number (for performance) */
679
- get type() {
680
- return this.arena.get_type(this.index);
681
- }
682
- /** Get node type as human-readable string */
683
- get type_name() {
684
- return qs[this.type] || "unknown";
685
- }
686
- /** Get the full text of this node from source */
687
- get text() {
688
- let e = this.arena.get_start_offset(this.index), t = this.arena.get_length(this.index);
689
- return this.source.substring(e, e + t);
690
- }
691
- /** Get the "content" text (property name for declarations, at-rule name for at-rules, layer name for import layers) */
692
- get name() {
693
- let e = this.arena.get_content_start(this.index), t = this.arena.get_content_length(this.index);
694
- return t === 0 ? "" : this.source.substring(e, e + t);
695
- }
696
- /**
697
- * Alias for name (for declarations: "color" in "color: blue")
698
- * More semantic than `name` for declaration nodes
699
- */
700
- get property() {
701
- return this.name;
702
- }
703
- /**
704
- * Get the value text (for declarations: "blue" in "color: blue")
705
- * For dimension/number nodes: returns the numeric value as a number
706
- * For string nodes: returns the string content without quotes
707
- * For URL nodes with quoted string: returns the string with quotes (consistent with STRING node)
708
- * For URL nodes with unquoted URL: returns the URL content without quotes
709
- */
710
- get value() {
711
- let { type: e, text: t } = this;
712
- if (e === R && this.first_child)
713
- return this.first_child;
714
- if (e === D)
715
- return re(t).value;
716
- if (e === Z)
717
- return Number.parseFloat(this.text);
718
- if (e === ve) {
719
- let n = this.first_child;
720
- if (n && n.type === ge)
721
- return n.text;
722
- if (Ws(t, "url(")) {
723
- let o = t.indexOf("("), h = t.lastIndexOf(")");
724
- if (o !== -1 && h !== -1 && h > o)
725
- return t.substring(o + 1, h).trim();
726
- } else if (t.startsWith('"') || t.startsWith("'"))
727
- return t;
728
- }
729
- let s = this.arena.get_value_start(this.index), i = this.arena.get_value_length(this.index);
730
- return i === 0 ? null : this.source.substring(s, s + i);
731
- }
732
- /** Get the numeric value for NUMBER and DIMENSION nodes, or null for other node types */
733
- get value_as_number() {
734
- let e = this.text;
735
- return this.type === Z ? Number.parseFloat(e) : this.type === D ? re(e).value : null;
736
- }
737
- /**
738
- * Get the prelude node:
739
- * - For at-rules: AT_RULE_PRELUDE wrapper containing structured prelude children (media queries, layer names, etc.)
740
- * - For style rules: SELECTOR_LIST or SELECTOR node
741
- * Returns null if no prelude exists
742
- */
743
- get prelude() {
744
- if (this.type === F) {
745
- let e = this.first_child;
746
- return e && e.type === tt ? e : null;
747
- }
748
- if (this.type === j)
749
- return this.first_child;
750
- }
751
- /**
752
- * Get the attribute operator (for attribute selectors: =, ~=, |=, ^=, $=, *=)
753
- * Returns one of the ATTR_OPERATOR_* constants
754
- */
755
- get attr_operator() {
756
- if (this.type === z)
757
- return this.arena.get_attr_operator(this.index);
758
- }
759
- /**
760
- * Get the attribute flags (for attribute selectors: i, s)
761
- * Returns one of the ATTR_FLAG_* constants
762
- */
763
- get attr_flags() {
764
- if (this.type === z)
765
- return this.arena.get_attr_flags(this.index);
766
- }
767
- /** Get the unit for dimension nodes (e.g., "px" from "100px", "%" from "50%") */
768
- get unit() {
769
- if (this.type === D)
770
- return re(this.text).unit;
771
- }
772
- /** Check if this declaration has !important */
773
- get is_important() {
774
- if (this.type === R)
775
- return this.arena.has_flag(this.index, Ss);
776
- }
777
- /** Check if this declaration has a browser hack prefix */
778
- get is_browserhack() {
779
- if (this.type === R)
780
- return this.arena.has_flag(this.index, Is);
781
- }
782
- /** Check if this has a vendor prefix (computed on-demand) */
783
- get is_vendor_prefixed() {
784
- switch (this.type) {
785
- case R:
786
- return I(this.name);
787
- case Q:
788
- case fe:
789
- return I(this.name);
790
- case F:
791
- return I(this.name);
792
- case me:
793
- return I(this.name);
794
- case pe:
795
- return I(this.text);
796
- default:
797
- return !1;
798
- }
799
- }
800
- /** Check if this node has an error */
801
- get has_error() {
802
- return this.arena.has_flag(this.index, Ls);
803
- }
804
- /** Check if this node has a prelude (at-rules and style rules) */
805
- get has_prelude() {
806
- return this.type === F ? this.arena.get_value_length(this.index) > 0 : this.type === j ? this.first_child !== null : !1;
807
- }
808
- /** Check if this rule has a block { } */
809
- get has_block() {
810
- return this.arena.has_flag(this.index, Hs);
811
- }
812
- /** Check if this style rule has declarations */
813
- get has_declarations() {
814
- return this.arena.has_flag(this.index, $s);
815
- }
816
- /** Get the block node (for style rules and at-rules with blocks) */
817
- get block() {
818
- if (this.type === j) {
819
- let e = this.first_child;
820
- if (!e) return null;
821
- let t = e.next_sibling;
822
- return t && t.type === X ? t : null;
823
- }
824
- if (this.type === F) {
825
- let e = this.first_child;
826
- for (; e; ) {
827
- if (e.type === X && !e.next_sibling)
828
- return e;
829
- e = e.next_sibling;
830
- }
831
- return null;
832
- }
833
- return null;
834
- }
835
- /** Check if this block is empty (no declarations or rules, only comments allowed) */
836
- get is_empty() {
837
- if (this.type !== X) return;
838
- let e = this.first_child;
839
- for (; e; ) {
840
- if (e.type !== Ve)
841
- return !1;
842
- e = e.next_sibling;
843
- }
844
- return !0;
845
- }
846
- /** Get start line number */
847
- get line() {
848
- return this.arena.get_start_line(this.index);
849
- }
850
- /** Get start column number */
851
- get column() {
852
- return this.arena.get_start_column(this.index);
853
- }
854
- /** Get start offset in source */
855
- get start() {
856
- return this.arena.get_start_offset(this.index);
857
- }
858
- /** Get length in source */
859
- get length() {
860
- return this.arena.get_length(this.index);
861
- }
862
- /**
863
- * Get end offset in source
864
- * End is not stored, must be calculated
865
- */
866
- get end() {
867
- return this.start + this.length;
868
- }
869
- // --- Tree Traversal ---
870
- /** Get first child node */
871
- get first_child() {
872
- let e = this.arena.get_first_child(this.index);
873
- return e === 0 ? null : new J(this.arena, this.source, e);
874
- }
875
- /** Get next sibling node */
876
- get next_sibling() {
877
- let e = this.arena.get_next_sibling(this.index);
878
- return e === 0 ? null : new J(this.arena, this.source, e);
879
- }
880
- /** Check if this node has a next sibling */
881
- get has_next() {
882
- return this.arena.get_next_sibling(this.index) !== 0;
883
- }
884
- /**
885
- * Check if this node has children
886
- * For pseudo-class/pseudo-element functions, returns true if FLAG_HAS_PARENS is set
887
- * This allows formatters to distinguish :lang() from :hover
888
- */
889
- get has_children() {
890
- return (this.type === Q || this.type === fe) && this.arena.has_flag(this.index, Us) ? !0 : this.arena.has_children(this.index);
891
- }
892
- /** Get all children as an array */
893
- get children() {
894
- let e = [], t = this.first_child;
895
- for (; t; )
896
- e.push(t), t = t.next_sibling;
897
- return e;
898
- }
899
- /** Make CSSNode iterable over its children */
900
- *[Symbol.iterator]() {
901
- let e = this.first_child;
902
- for (; e; )
903
- yield e, e = e.next_sibling;
904
- }
905
- // --- An+B Expression Helpers (for NODE_SELECTOR_NTH) ---
906
- /** Get the 'a' coefficient from An+B expression (e.g., "2n" from "2n+1", "odd" from "odd") */
907
- get nth_a() {
908
- if (this.type !== V && this.type !== w) return;
909
- let e = this.arena.get_content_length(this.index);
910
- if (e === 0) return;
911
- let t = this.arena.get_content_start(this.index);
912
- return this.source.substring(t, t + e);
913
- }
914
- /** Get the 'b' coefficient from An+B expression (e.g., "+1" from "2n+1") */
915
- get nth_b() {
916
- if (this.type !== V && this.type !== w) return;
917
- let e = this.arena.get_value_length(this.index);
918
- if (e === 0) return;
919
- let t = this.arena.get_value_start(this.index), s = this.source.substring(t, t + e), i = t - 1;
920
- for (; i >= 0; ) {
921
- let n = this.source.charCodeAt(i);
922
- if (st(n)) {
923
- i--;
924
- continue;
925
- }
926
- n === H ? s = "-" + s : n === Ee && (s = "+" + s);
927
- break;
928
- }
929
- return s;
930
- }
931
- // --- Pseudo-Class Nth-Of Helpers (for NODE_SELECTOR_NTH_OF) ---
932
- /** Get the An+B formula node from :nth-child(2n+1 of .foo) */
933
- get nth() {
934
- if (this.type === w)
935
- return this.first_child ?? void 0;
936
- }
937
- /** Get the selector list from :nth-child(2n+1 of .foo) */
938
- get selector() {
939
- return this.type !== w ? void 0 : this.first_child?.next_sibling ?? void 0;
940
- }
941
- // --- Pseudo-Class Selector List Helper ---
942
- /**
943
- * Get selector list from pseudo-class functions
944
- * Works for :is(.a), :not(.b), :has(.c), :where(.d), :nth-child(2n of .e)
945
- */
946
- get selector_list() {
947
- if (this.type !== Q) return;
948
- let e = this.first_child;
949
- if (e) {
950
- if (e.type === et)
951
- return e;
952
- if (e.type === w)
953
- return e.selector;
954
- }
955
- }
956
- // --- Node Cloning ---
957
- /**
958
- * Clone this node as a mutable plain JavaScript object with children as arrays.
959
- * See API.md for examples.
960
- *
961
- * @param options - Cloning configuration
962
- * @param options.deep - Recursively clone children (default: true)
963
- * @param options.locations - Include line/column/start/length (default: false)
964
- */
965
- clone(e = {}) {
966
- const { deep: t = !0, locations: s = !1 } = e;
967
- let i = {
968
- type: this.type,
969
- type_name: this.type_name,
970
- text: this.text,
971
- children: []
972
- };
973
- if (this.name && (i.name = this.name), this.type === R && (i.property = this.name), this.value !== void 0 && this.value !== null && (i.value = this.value, this.unit && (i.unit = this.unit)), this.type === R && (i.is_important = this.is_important, i.is_browserhack = this.is_browserhack), i.is_vendor_prefixed = this.is_vendor_prefixed, i.has_error = this.has_error, this.type === z && (i.attr_operator = this.attr_operator, i.attr_flags = this.attr_flags), (this.type === V || this.type === w) && (i.nth_a = this.nth_a, i.nth_b = this.nth_b), s && (i.line = this.line, i.column = this.column, i.start = this.start, i.length = this.length, i.end = this.end), t)
974
- for (let n of this.children)
975
- i.children.push(n.clone({ deep: !0, locations: s }));
976
- return i;
977
- }
978
- }
979
- class js {
980
- lexer;
981
- arena;
982
- source;
983
- value_end;
984
- constructor(e, t) {
985
- this.arena = e, this.source = t, this.lexer = new fs(t), this.value_end = 0;
986
- }
987
- // Parse a declaration value range into a VALUE wrapper node
988
- // Returns single VALUE node index
989
- parse_value(e, t, s, i) {
990
- this.value_end = t, this.lexer.pos = e, this.lexer.line = s, this.lexer.column = i;
991
- let n = this.parse_value_tokens();
992
- if (n.length === 0)
993
- return this.arena.create_node(ce, e, 0, s, i);
994
- let o = this.arena.get_start_offset(n[0]), h = n[n.length - 1], u = this.arena.get_start_offset(h) + this.arena.get_length(h), f = this.arena.create_node(ce, o, u - o, s, i);
995
- return this.arena.append_children(f, n), f;
996
- }
997
- // Core token parsing logic
998
- parse_value_tokens() {
999
- let e = [];
1000
- for (; this.lexer.pos < this.value_end && (this.lexer.next_token_fast(!1), !(this.lexer.token_start >= this.value_end || this.lexer.token_type === O)); ) {
1001
- if (this.is_whitespace_inline())
1002
- continue;
1003
- let s = this.parse_value_node();
1004
- s !== null && e.push(s);
1005
- }
1006
- return e;
1007
- }
1008
- // Helper to check if token is all whitespace (inline for hot paths)
1009
- is_whitespace_inline() {
1010
- if (this.lexer.token_start >= this.lexer.token_end) return !1;
1011
- for (let e = this.lexer.token_start; e < this.lexer.token_end; e++)
1012
- if (!st(this.source.charCodeAt(e)))
1013
- return !1;
1014
- return !0;
1015
- }
1016
- parse_value_node() {
1017
- let e = this.lexer.token_type, t = this.lexer.token_start, s = this.lexer.token_end;
1018
- switch (e) {
1019
- case Ye:
1020
- return this.create_node(pe, t, s);
1021
- case je:
1022
- return this.create_node(Z, t, s);
1023
- case Xe:
1024
- case ze:
1025
- return this.create_node(D, t, s);
1026
- case ae:
1027
- return this.create_node(ge, t, s);
1028
- case We:
1029
- return this.create_node(Ze, t, s);
1030
- case le:
1031
- return this.parse_function_node(t, s);
1032
- case qe:
1033
- return this.parse_operator_node(t, s);
1034
- case Qe:
1035
- return this.create_node(_e, t, s);
1036
- case ue:
1037
- return this.parse_parenthesis_node(t, s);
1038
- default:
1039
- return null;
1040
- }
1041
- }
1042
- create_node(e, t, s) {
1043
- let i = this.arena.create_node(e, t, s - t, this.lexer.token_line, this.lexer.token_column);
1044
- return this.arena.set_content_length(i, s - t), i;
1045
- }
1046
- create_operator_node(e, t) {
1047
- return this.create_node(_e, e, t);
1048
- }
1049
- parse_operator_node(e, t) {
1050
- let s = this.source.charCodeAt(e);
1051
- return s === Ee || s === H || s === Bs || s === Gs ? this.create_operator_node(e, t) : null;
1052
- }
1053
- parse_function_node(e, t) {
1054
- let s = t - 1, i = this.source.substring(e, s), n = this.arena.create_node(
1055
- ne("url", i) ? ve : me,
1056
- e,
1057
- 0,
1058
- // length unknown yet
1059
- this.lexer.token_line,
1060
- this.lexer.token_column
1061
- );
1062
- if (this.arena.set_content_start_delta(n, 0), this.arena.set_content_length(n, s - e), ne("url", i) || ne("src", i)) {
1063
- let b = this.lexer.save_position();
1064
- for (this.lexer.next_token_fast(!1); this.is_whitespace_inline() && this.lexer.pos < this.value_end; )
1065
- this.lexer.next_token_fast(!1);
1066
- let m = this.lexer.token_type;
1067
- if (this.lexer.restore_position(b), m !== ae) {
1068
- let T = 1, $ = t, k = t, U = t;
1069
- for (; T > 0; ) {
1070
- this.lexer.next_token_fast(!1);
1071
- let x = this.lexer.token_type;
1072
- if (x === O) break;
1073
- if (x === ue || x === le)
1074
- T++;
1075
- else if (x === q && (T--, T === 0)) {
1076
- U = this.lexer.token_start, $ = this.lexer.token_end;
1077
- break;
1078
- }
1079
- }
1080
- return this.arena.set_length(n, $ - e), this.arena.set_value_start_delta(n, k - e), this.arena.set_value_length(n, U - k), n;
1081
- }
1082
- }
1083
- let o = [], h = 1, u = t, f = t, d = t;
1084
- for (; this.lexer.pos < this.value_end && h > 0; ) {
1085
- this.lexer.next_token_fast(!1);
1086
- let b = this.lexer.token_type;
1087
- if (b === O || this.lexer.token_start >= this.value_end) break;
1088
- if (b === q && (h--, h === 0)) {
1089
- d = this.lexer.token_start, u = this.lexer.token_end;
1090
- break;
1091
- }
1092
- if (this.is_whitespace_inline()) continue;
1093
- let m = this.parse_value_node();
1094
- m !== null && o.push(m);
1095
- }
1096
- return this.arena.set_length(n, u - e), this.arena.set_value_start_delta(n, f - e), this.arena.set_value_length(n, d - f), this.arena.append_children(n, o), n;
1097
- }
1098
- parse_parenthesis_node(e, t) {
1099
- let s = this.arena.create_node(
1100
- Je,
1101
- e,
1102
- 0,
1103
- // length unknown yet
1104
- this.lexer.token_line,
1105
- this.lexer.token_column
1106
- ), i = [], n = 1, o = t;
1107
- for (; this.lexer.pos < this.value_end && n > 0; ) {
1108
- this.lexer.next_token_fast(!1);
1109
- let h = this.lexer.token_type;
1110
- if (h === O || this.lexer.token_start >= this.value_end) break;
1111
- if (h === q && (n--, n === 0)) {
1112
- o = this.lexer.token_end;
1113
- break;
1114
- }
1115
- if (this.is_whitespace_inline()) continue;
1116
- let u = this.parse_value_node();
1117
- u !== null && i.push(u);
1118
- }
1119
- return this.arena.set_length(s, o - e), this.arena.append_children(s, i), s;
1120
- }
1121
- }
1122
- function it(r) {
1123
- const e = new L(L.capacity_for_source(r.length)), s = new js(e, r).parse_value(0, r.length, 1, 1);
1124
- return new J(e, r, s);
1125
- }
1126
- const v = "com.projectwallace.css-authored-as", _ = "com.projectwallace.usage-count", oe = "com.projectwallace.css-properties";
1127
- a.register(ct);
1128
- a.register(ft);
1129
- a.register(dt);
1130
- a.register(pt);
1131
- a.register(gt);
1132
- a.register(mt);
1133
- a.register(vt);
1134
- a.register(Et);
1135
- a.register(At);
1136
- a.register(kt);
1137
- a.register(xt);
1138
- a.register(Ct);
1139
- a.register(Rt);
1140
- a.register(wt);
1141
- a.register(yt);
1142
- a.register(bt);
1143
- a.register(Tt);
1144
- a.register(Ot);
1145
- a.register(Nt);
1146
- a.register(St);
1147
- a.register(Lt);
1148
- a.register(Ht);
1149
- function N(r) {
1150
- let e = r.toLowerCase();
1151
- if (e === "transparent")
1152
- return {
1153
- colorSpace: "srgb",
1154
- components: [0, 0, 0],
1155
- alpha: 0
1156
- };
1157
- if (nt.has(e) || rt.has(e) || e.includes("var("))
1158
- return null;
1159
- let t = $t(r);
1160
- if (t === null) return null;
1161
- let [s, i, n] = t.coords;
1162
- return {
1163
- colorSpace: t.space.id,
1164
- components: [s ?? "none", i ?? "none", n ?? "none"],
1165
- alpha: t.alpha ?? 1
1166
- };
1167
- }
1168
- function Te() {
1169
- return {
1170
- color: void 0,
1171
- offsetX: void 0,
1172
- offsetY: void 0,
1173
- blur: void 0,
1174
- spread: void 0,
1175
- inset: !1
1176
- };
1177
- }
1178
- function Xs(r) {
1179
- let e = it(r), t = Te(), s = [t];
1180
- if (e.children.length < 2)
1181
- return null;
1182
- for (let i of e.children)
1183
- if (i.type_name === "Identifier") {
1184
- if (i.name.toLowerCase() === "inset")
1185
- t.inset = !0;
1186
- else if (ot.has(i.name) || ht.has(i.name)) {
1187
- let n = N(i.name);
1188
- if (n === null)
1189
- continue;
1190
- t.color = n;
1191
- }
1192
- } else if (i.type_name === "Dimension" || i.type_name === "Number" && i.value === 0) {
1193
- let n = i.type_name === "Dimension" ? {
1194
- value: Number(i.value),
1195
- unit: i.unit
1196
- } : {
1197
- value: 0,
1198
- unit: "px"
1199
- };
1200
- t.offsetX ? t.offsetY ? t.blur ? t.spread || (t.spread = n) : t.blur = n : t.offsetY = n : t.offsetX = n;
1201
- } else if (i.type_name === "Function") {
1202
- if (lt.has(i.name)) {
1203
- let n = N(i.text);
1204
- if (n === null)
1205
- continue;
1206
- t.color = n;
1207
- } else if (i.name.toLowerCase() === "var" && !t.color) {
1208
- let n = N(i.text);
1209
- if (n === null)
1210
- continue;
1211
- t.color = n;
1212
- }
1213
- } else if (i.type_name === "Hash") {
1214
- let n = N(i.text);
1215
- if (n === null)
1216
- continue;
1217
- t.color = n;
1218
- } else i.type_name === "Operator" && i.name === "," && (Oe(t), t = Te(), s.push(t));
1219
- return Oe(t), s;
1220
- }
1221
- const Y = {
1222
- value: 0,
1223
- unit: "px"
1224
- };
1225
- function Oe(r) {
1226
- return r.offsetX || (r.offsetX = Y), r.offsetY || (r.offsetY = Y), r.blur || (r.blur = Y), r.spread || (r.spread = Y), r.color || (r.color = N("#000")), r;
1227
- }
1228
- const Ne = /* @__PURE__ */ new Map([
1229
- ["linear", [0, 0, 1, 1]],
1230
- ["ease", [0.25, 0.1, 0.25, 1]],
1231
- ["ease-in", [0.42, 0, 1, 1]],
1232
- ["ease-out", [0, 0, 0.58, 1]],
1233
- ["ease-in-out", [0.42, 0, 0.58, 1]]
1234
- ]);
1235
- function zs(r) {
1236
- if (r = r.trim().toLowerCase(), Ne.has(r))
1237
- return Ne.get(r);
1238
- if (r.includes("var("))
1239
- return null;
1240
- if (r.startsWith("cubic-bezier(")) {
1241
- let e = r.replace("cubic-bezier(", "").replace(")", "").split(",").map((t) => Number(t.trim()));
1242
- if (e.length === 4 && e.every((t) => Number.isFinite(t)))
1243
- return e;
1244
- }
1245
- return null;
1246
- }
1247
- function Se(r) {
1248
- return r.replaceAll(/^['"]|['"]$/g, "");
1249
- }
1250
- function Qs(r) {
1251
- if (r.toLowerCase().includes("var("))
1252
- return;
1253
- let e = it(r), t = [], { children: s, has_children: i } = e;
1254
- if (!i || s.length === 0)
1255
- return t;
1256
- let n = "", o;
1257
- for (let h of s) {
1258
- if (h.type_name === "Operator" && h.name === ",") {
1259
- t.push(Se(n)), n = "", o = h.type_name;
1260
- continue;
1261
- }
1262
- o === "Identifier" && h.type_name === "Identifier" && (n += " "), n += h.text, o = h.type_name;
1263
- }
1264
- return t.push(Se(n)), t;
1265
- }
1266
- function c(r) {
1267
- if (r === void 0 || typeof r == "number" && isNaN(r))
1268
- return "0";
1269
- typeof r != "string" && (r = r.toString());
1270
- let e = 0;
1271
- for (let t of r)
1272
- e = (e << 5) - e + t.charCodeAt(0), e |= 0;
1273
- return (e >>> 0).toString(16);
1274
- }
1275
- const Vs = /* @__PURE__ */ new Set(["px", "rem"]);
1276
- function Zs(r) {
1277
- let e = He(r);
1278
- if (!e.has_children || e.children.length !== 1) return null;
1279
- let t = e.first_child;
1280
- switch (t.type_name) {
1281
- case "Dimension": {
1282
- let { value: s, unit: i } = t;
1283
- return s === 0 ? 0 : i === "%" ? Number(s) / 100 : (i = i.toLowerCase(), Vs.has(i) ? {
1284
- value: s,
1285
- unit: i
1286
- } : null);
1287
- }
1288
- case "Number":
1289
- return Number(t.value);
1290
- case "Identifier":
1291
- if (t.name.toLowerCase() === "normal")
1292
- return 1.2;
1293
- }
1294
- return null;
1295
- }
1296
- let Le = /* @__PURE__ */ new Map([
1297
- ["xx-small", 0.6],
1298
- ["x-small", 0.75],
1299
- ["small", 0.89],
1300
- ["medium", 1],
1301
- ["large", 1.2],
1302
- ["x-large", 1.5],
1303
- ["xx-large", 2],
1304
- ["xxx-large", 3]
1305
- ]);
1306
- function Js(r) {
1307
- let e = He(r);
1308
- if (!e.has_children || e.children.length !== 1) return null;
1309
- let t = e.first_child;
1310
- switch (t.type_name) {
1311
- case "Dimension": {
1312
- let s = t.unit.toLowerCase();
1313
- if (s === "px" || s === "rem") {
1314
- let i = Number(t.value);
1315
- return i === 0 ? {
1316
- value: 0,
1317
- unit: "px"
1318
- } : {
1319
- value: i,
1320
- unit: s
1321
- };
1322
- }
1323
- break;
1324
- }
1325
- case "Identifier": {
1326
- let s = t.name.toLowerCase();
1327
- if (Le.has(s))
1328
- return {
1329
- value: Le.get(s),
1330
- unit: "rem"
1331
- };
1332
- break;
1333
- }
1334
- case "Number": {
1335
- if (Number(t.value) === 0)
1336
- return {
1337
- value: 0,
1338
- unit: "px"
1339
- };
1340
- break;
1341
- }
1342
- }
1343
- return null;
1344
- }
1345
- function oi(r) {
1346
- let e = at(r);
1347
- return ei(e);
1348
- }
1349
- function E(r) {
1350
- return "uniqueWithLocations" in r && r.uniqueWithLocations != null ? r.uniqueWithLocations : r.unique;
1351
- }
1352
- function A(r) {
1353
- return Array.isArray(r) ? r.length : r;
1354
- }
1355
- function ei(r) {
1356
- return {
1357
- color: (() => {
1358
- let e = /* @__PURE__ */ Object.create(null), t = E(r.values.colors), s = It(t);
1359
- for (let [i, n] of s)
1360
- for (let o of n) {
1361
- let h = N(o), u = A(t[o]);
1362
- if (h !== null) {
1363
- let { colorSpace: f, components: d, alpha: b } = h, m = `${Ut.get(i)}-${c([f, ...d, b].join(""))}`, T = r.values.colors.itemsPerContext, $ = Object.entries(T).reduce((k, [U, x]) => o in x.unique || x.uniqueWithLocations && o in x.uniqueWithLocations ? k.add(U) : k, /* @__PURE__ */ new Set());
1364
- if (e[m]) {
1365
- let k = e[m].$extensions[oe];
1366
- e[m].$extensions[oe] = Array.from(new Set(k).union($)), e[m].$extensions[_] += u;
1367
- } else
1368
- e[m] = {
1369
- $type: "color",
1370
- $value: h,
1371
- $extensions: {
1372
- [v]: o,
1373
- [_]: u,
1374
- [oe]: Array.from($)
1375
- }
1376
- };
1377
- }
1378
- }
1379
- return e;
1380
- })(),
1381
- font_size: (() => {
1382
- let e = /* @__PURE__ */ Object.create(null), t = E(r.values.fontSizes);
1383
- for (let s in t) {
1384
- let i = Js(s), n = {
1385
- [v]: s,
1386
- [_]: A(t[s])
1387
- };
1388
- if (i === null) {
1389
- let o = `fontSize-${c(s)}`;
1390
- e[o] = {
1391
- $value: s,
1392
- $extensions: n
1393
- };
1394
- } else {
1395
- let o = `fontSize-${c(i.value.toString() + i.unit)}`;
1396
- e[o] ? e[o].$extensions[_] += n[_] : e[o] = {
1397
- $type: "dimension",
1398
- $value: i,
1399
- $extensions: n
1400
- };
1401
- }
1402
- }
1403
- return e;
1404
- })(),
1405
- font_family: (() => {
1406
- let e = /* @__PURE__ */ Object.create(null), t = E(r.values.fontFamilies);
1407
- for (let s in t) {
1408
- let i = Qs(s), n = `fontFamily-${c(s)}`, o = {
1409
- [v]: s,
1410
- [_]: A(t[s])
1411
- };
1412
- i === void 0 ? e[n] = {
1413
- $value: s,
1414
- $extensions: o
1415
- } : e[n] = {
1416
- $type: "fontFamily",
1417
- $value: i,
1418
- $extensions: o
1419
- };
1420
- }
1421
- return e;
1422
- })(),
1423
- line_height: (() => {
1424
- let e = /* @__PURE__ */ Object.create(null), t = E(r.values.lineHeights);
1425
- for (let s in t) {
1426
- let i = Zs(s), n = {
1427
- [v]: s,
1428
- [_]: A(t[s])
1429
- };
1430
- if (i === null) {
1431
- let o = `lineHeight-${c(s)}`;
1432
- e[o] = {
1433
- $value: s,
1434
- $extensions: n
1435
- };
1436
- } else if (typeof i == "number") {
1437
- let o = `lineHeight-${c(i)}`;
1438
- e[o] ? e[o].$extensions[_] += n[_] : e[o] = {
1439
- $type: "number",
1440
- $value: i,
1441
- $extensions: n
1442
- };
1443
- } else if (typeof i == "object")
1444
- if (i.unit === "px" || i.unit === "rem") {
1445
- let o = `lineHeight-${c(i.value.toString() + i.unit)}`;
1446
- e[o] ? e[o].$extensions[_] += n[_] : e[o] = {
1447
- $type: "dimension",
1448
- $value: i,
1449
- $extensions: n
1450
- };
1451
- } else {
1452
- let o = `lineHeight-${c(s)}`;
1453
- e[o] = {
1454
- $value: s,
1455
- $extensions: n
1456
- };
1457
- }
1458
- }
1459
- return e;
1460
- })(),
1461
- gradient: (() => {
1462
- let e = /* @__PURE__ */ Object.create(null), t = E(r.values.gradients);
1463
- for (let s in t)
1464
- e[`gradient-${c(s)}`] = {
1465
- $value: s,
1466
- $extensions: {
1467
- [v]: s,
1468
- [_]: A(t[s])
1469
- }
1470
- };
1471
- return e;
1472
- })(),
1473
- box_shadow: (() => {
1474
- let e = /* @__PURE__ */ Object.create(null), t = E(r.values.boxShadows);
1475
- for (let s in t) {
1476
- let i = `boxShadow-${c(s)}`, n = Xs(s), o = {
1477
- [v]: s,
1478
- [_]: A(t[s])
1479
- };
1480
- n === null ? e[i] = {
1481
- $value: s,
1482
- $extensions: o
1483
- } : e[i] = {
1484
- $type: "shadow",
1485
- $value: n.length === 1 ? n[0] : n,
1486
- $extensions: o
1487
- };
1488
- }
1489
- return e;
1490
- })(),
1491
- radius: (() => {
1492
- let e = /* @__PURE__ */ Object.create(null), t = E(r.values.borderRadiuses);
1493
- for (let s in t) {
1494
- let i = `radius-${c(s)}`;
1495
- e[i] = {
1496
- $value: s,
1497
- $extensions: {
1498
- [v]: s,
1499
- [_]: A(t[s])
1500
- }
1501
- };
1502
- }
1503
- return e;
1504
- })(),
1505
- duration: (() => {
1506
- let e = /* @__PURE__ */ Object.create(null), t = E(r.values.animations.durations);
1507
- for (let s in t) {
1508
- let i = ut(s), n = i < Number.MAX_SAFE_INTEGER - 1, o = {
1509
- [v]: s,
1510
- [_]: A(t[s])
1511
- };
1512
- if (n) {
1513
- let h = `duration-${c(i.toString())}`;
1514
- e[h] ? e[h].$extensions[_] += o[_] : e[h] = {
1515
- $type: "duration",
1516
- $value: {
1517
- value: i,
1518
- unit: "ms"
1519
- },
1520
- $extensions: o
1521
- };
1522
- } else {
1523
- let h = `duration-${c("invalid" + i.toString())}`;
1524
- e[h] = {
1525
- $value: s,
1526
- $extensions: o
1527
- };
1528
- }
1529
- }
1530
- return e;
1531
- })(),
1532
- easing: (() => {
1533
- let e = /* @__PURE__ */ Object.create(null), t = E(r.values.animations.timingFunctions);
1534
- for (let s in t) {
1535
- let i = `easing-${c(s)}`, n = zs(s), o = {
1536
- [v]: s,
1537
- [_]: A(t[s])
1538
- };
1539
- n !== null ? e[i] = {
1540
- $value: n,
1541
- $type: "cubicBezier",
1542
- $extensions: o
1543
- } : e[i] = {
1544
- $value: s,
1545
- $extensions: o
1546
- };
1547
- }
1548
- return e;
1549
- })()
1550
- };
1551
- }
1552
- export {
1553
- v as EXTENSION_AUTHORED_AS,
1554
- oe as EXTENSION_CSS_PROPERTIES,
1555
- _ as EXTENSION_USAGE_COUNT,
1556
- ei as analysis_to_tokens,
1557
- N as color_to_token,
1558
- oi as css_to_tokens
1559
- };