@stacksjs/ts-css 0.1.0 → 0.1.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.
@@ -0,0 +1,10 @@
1
+ import { compileGeneric } from './selectors';
2
+ import type { CompiledQuery, Options } from '../types';
3
+ import type { Selector } from '../../what/index';
4
+ export declare function compilePseudo<Node, ElementNode extends Node>(token: PseudoToken, options: Options<Node, ElementNode>, next: CompiledQuery<ElementNode>): CompiledQuery<ElementNode>;
5
+ declare interface PseudoToken {
6
+ type: 'pseudo' | 'pseudo-element'
7
+ name: string
8
+ data: string | Selector[][] | null
9
+ }
10
+ export { compileGeneric };
@@ -0,0 +1,4 @@
1
+ import type { CompiledQuery, Options } from '../types';
2
+ import type { Selector } from '../../what/index';
3
+ export declare function compileGeneric<Node, ElementNode extends Node>(segments: Selector[][], options: Options<Node, ElementNode>): CompiledQuery<ElementNode>;
4
+ export declare function parseAndCompile<Node, ElementNode extends Node>(tokens: Selector[], options: Options<Node, ElementNode>): CompiledQuery<ElementNode>;
@@ -1,514 +1,2 @@
1
1
  // @bun
2
- var __defProp = Object.defineProperty;
3
- var __returnValue = (v) => v;
4
- function __exportSetter(name, newValue) {
5
- this[name] = __returnValue.bind(null, newValue);
6
- }
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, {
10
- get: all[name],
11
- enumerable: true,
12
- configurable: true,
13
- set: __exportSetter.bind(all, name)
14
- });
15
- };
16
- var __require = import.meta.require;
17
-
18
- // src/what/index.ts
19
- var exports_what = {};
20
- __export(exports_what, {
21
- stringify: () => stringify,
22
- parse: () => parse,
23
- isTraversal: () => isTraversal,
24
- IgnoreCaseMode: () => IgnoreCaseMode
25
- });
26
-
27
- // src/what/parse.ts
28
- var RE_NAME_STICKY = /(?:\\(?:[\dA-Fa-f]{1,6} ?|[^])|[\w\-\u00B0-\uFFFF])+/y;
29
- var RE_ESCAPE = /\\([\dA-Fa-f]{1,6} ?|[^])/g;
30
- function unescape(name) {
31
- return name.replace(RE_ESCAPE, (_m, escape) => {
32
- if (escape.length > 1 && /^[\dA-Fa-f]/.test(escape)) {
33
- const code = Number.parseInt(escape, 16);
34
- if (code >= 55296 && code <= 57343)
35
- return "\uFFFD";
36
- return String.fromCodePoint(code);
37
- }
38
- return escape;
39
- });
40
- }
41
- function unescapeIfNeeded(name) {
42
- return name.indexOf("\\") < 0 ? name : unescape(name);
43
- }
44
- var ATTRIBUTES_QUIRKS = new Set([
45
- "accept",
46
- "accept-charset",
47
- "align",
48
- "alink",
49
- "axis",
50
- "bgcolor",
51
- "charset",
52
- "checked",
53
- "clear",
54
- "codetype",
55
- "color",
56
- "compact",
57
- "declare",
58
- "defer",
59
- "dir",
60
- "direction",
61
- "disabled",
62
- "enctype",
63
- "face",
64
- "frame",
65
- "hreflang",
66
- "http-equiv",
67
- "lang",
68
- "language",
69
- "link",
70
- "media",
71
- "method",
72
- "multiple",
73
- "nohref",
74
- "noresize",
75
- "noshade",
76
- "nowrap",
77
- "readonly",
78
- "rel",
79
- "rev",
80
- "rules",
81
- "scope",
82
- "scrolling",
83
- "selected",
84
- "shape",
85
- "target",
86
- "text",
87
- "type",
88
- "valign",
89
- "valuetype",
90
- "vlink"
91
- ]);
92
- function actionFromChar(ch) {
93
- switch (ch) {
94
- case 126:
95
- return "element";
96
- case 94:
97
- return "start";
98
- case 36:
99
- return "end";
100
- case 42:
101
- return "any";
102
- case 33:
103
- return "not";
104
- case 124:
105
- return "hyphen";
106
- default:
107
- return null;
108
- }
109
- }
110
- function isWsCode(c) {
111
- return c === 32 || c === 9 || c === 10 || c === 13 || c === 12;
112
- }
113
- function parse(selector, options = {}) {
114
- const subselects = [];
115
- const endIndex = parseSelectorImpl(subselects, selector, options, 0);
116
- if (endIndex < selector.length)
117
- throw new Error(`Unmatched selector: ${selector.slice(endIndex)}`);
118
- return subselects;
119
- }
120
- function readName(selector, from) {
121
- RE_NAME_STICKY.lastIndex = from;
122
- const m = RE_NAME_STICKY.exec(selector);
123
- if (!m)
124
- throw new Error(`Expected name, found ${selector.slice(from)}`);
125
- return { value: unescapeIfNeeded(m[0]), end: from + m[0].length };
126
- }
127
- function stripWS(selector, from) {
128
- while (from < selector.length && isWsCode(selector.charCodeAt(from)))
129
- from++;
130
- return from;
131
- }
132
- function parseSelectorImpl(subselects, selector, options, startIndex) {
133
- let tokens = [];
134
- let i = stripWS(selector, startIndex);
135
- const len = selector.length;
136
- const xmlMode = options.xmlMode === true;
137
- const lowerCaseAttrs = options.lowerCaseAttributeNames !== false && !xmlMode;
138
- const lowerCaseTagsFlag = options.lowerCaseTags !== false;
139
- while (i < len) {
140
- const code = selector.charCodeAt(i);
141
- if (isWsCode(code)) {
142
- let trimmed = i + 1;
143
- while (trimmed < len && isWsCode(selector.charCodeAt(trimmed)))
144
- trimmed++;
145
- if (tokens.length === 0)
146
- return trimmed;
147
- i = trimmed;
148
- addTraversal(tokens, "descendant");
149
- continue;
150
- }
151
- if (code === 62 || code === 60 || code === 126 || code === 43 || code === 124) {
152
- let j = i + 1;
153
- while (j < len && isWsCode(selector.charCodeAt(j)))
154
- j++;
155
- i = j;
156
- switch (code) {
157
- case 62:
158
- addTraversal(tokens, "child");
159
- break;
160
- case 60:
161
- addTraversal(tokens, "parent");
162
- break;
163
- case 126:
164
- addTraversal(tokens, "sibling");
165
- break;
166
- case 43:
167
- addTraversal(tokens, "adjacent");
168
- break;
169
- case 124:
170
- if (i < len && selector.charCodeAt(i) === 124) {
171
- i++;
172
- i = stripWS(selector, i);
173
- addTraversal(tokens, "column-combinator");
174
- } else {
175
- tokens.push({ type: "tag", name: "", namespace: "" });
176
- }
177
- break;
178
- }
179
- continue;
180
- }
181
- if (code === 44) {
182
- if (tokens.length === 0)
183
- throw new Error("Empty sub-selector");
184
- subselects.push(tokens);
185
- tokens = [];
186
- i = stripWS(selector, i + 1);
187
- continue;
188
- }
189
- if (code === 47 && selector.charCodeAt(i + 1) === 42) {
190
- const end = selector.indexOf("*/", i + 2);
191
- if (end < 0)
192
- throw new Error("Unmatched comment");
193
- i = stripWS(selector, end + 2);
194
- continue;
195
- }
196
- if (code === 42) {
197
- i++;
198
- tokens.push({ type: "universal", namespace: null });
199
- continue;
200
- }
201
- if (code === 35) {
202
- const r = readName(selector, i + 1);
203
- i = r.end;
204
- tokens.push({
205
- type: "attribute",
206
- name: "id",
207
- action: "equals",
208
- value: r.value,
209
- namespace: null,
210
- ignoreCase: false
211
- });
212
- continue;
213
- }
214
- if (code === 46) {
215
- const r = readName(selector, i + 1);
216
- i = r.end;
217
- tokens.push({
218
- type: "attribute",
219
- name: "class",
220
- action: "element",
221
- value: r.value,
222
- namespace: null,
223
- ignoreCase: false
224
- });
225
- continue;
226
- }
227
- if (code === 91) {
228
- i = parseAttribute(selector, i, tokens, options, xmlMode, lowerCaseAttrs);
229
- continue;
230
- }
231
- if (code === 58) {
232
- i = parsePseudo(selector, i, tokens, options);
233
- continue;
234
- }
235
- if (code === 124) {
236
- i++;
237
- const r = readName(selector, i);
238
- i = r.end;
239
- tokens.push({ type: "tag", name: lowerCaseTagsFlag ? r.value.toLowerCase() : r.value, namespace: "" });
240
- continue;
241
- }
242
- {
243
- const r1 = readName(selector, i);
244
- i = r1.end;
245
- if (i < len && selector.charCodeAt(i) === 124 && selector.charCodeAt(i + 1) !== 61) {
246
- i++;
247
- const r2 = readName(selector, i);
248
- i = r2.end;
249
- tokens.push({ type: "tag", name: lowerCaseTagsFlag ? r2.value.toLowerCase() : r2.value, namespace: r1.value });
250
- } else {
251
- tokens.push({ type: "tag", name: lowerCaseTagsFlag ? r1.value.toLowerCase() : r1.value, namespace: null });
252
- }
253
- }
254
- }
255
- if (tokens.length > 0)
256
- subselects.push(tokens);
257
- return i;
258
- }
259
- function parseAttribute(selector, idx, tokens, options, xmlMode, lowerCaseAttrs) {
260
- let i = idx + 1;
261
- const len = selector.length;
262
- let attribute;
263
- if (selector.charCodeAt(i) === 124)
264
- throw new Error("Empty namespace not supported");
265
- if (selector.charCodeAt(i) === 42 && selector.charCodeAt(i + 1) === 124) {
266
- i += 2;
267
- const r = readName(selector, i);
268
- i = r.end;
269
- attribute = r.value;
270
- } else {
271
- const r = readName(selector, i);
272
- i = r.end;
273
- attribute = r.value;
274
- if (selector.charCodeAt(i) === 124 && selector.charCodeAt(i + 1) !== 61) {
275
- i++;
276
- const r2 = readName(selector, i);
277
- i = r2.end;
278
- attribute = r2.value;
279
- }
280
- }
281
- i = stripWS(selector, i);
282
- let action = "exists";
283
- let value = "";
284
- let ignoreCase = null;
285
- const opCode = selector.charCodeAt(i);
286
- if (opCode === 61) {
287
- action = "equals";
288
- i++;
289
- } else if (opCode === 33 && selector.charCodeAt(i + 1) === 61) {
290
- action = "not";
291
- i += 2;
292
- } else {
293
- const a = actionFromChar(opCode);
294
- if (a !== null && selector.charCodeAt(i + 1) === 61) {
295
- action = a;
296
- i += 2;
297
- }
298
- }
299
- if (action !== "exists") {
300
- i = stripWS(selector, i);
301
- const q = selector.charCodeAt(i);
302
- if (q === 34 || q === 39) {
303
- const end = findEndOfString(selector, i + 1, q);
304
- value = unescapeIfNeeded(selector.slice(i + 1, end));
305
- i = end + 1;
306
- } else {
307
- const r = readName(selector, i);
308
- value = r.value;
309
- i = r.end;
310
- }
311
- i = stripWS(selector, i);
312
- const flag = selector.charCodeAt(i);
313
- if (flag === 105 || flag === 73) {
314
- ignoreCase = true;
315
- i++;
316
- } else if (flag === 115 || flag === 83) {
317
- ignoreCase = false;
318
- i++;
319
- }
320
- }
321
- if (selector.charCodeAt(i) !== 93)
322
- throw new Error("Expected ]");
323
- i++;
324
- if (ignoreCase === null && !xmlMode && ATTRIBUTES_QUIRKS.has(attribute.toLowerCase()))
325
- ignoreCase = "quirks";
326
- tokens.push({
327
- type: "attribute",
328
- name: lowerCaseAttrs ? attribute.toLowerCase() : attribute,
329
- action,
330
- value,
331
- namespace: null,
332
- ignoreCase
333
- });
334
- return i;
335
- }
336
- function parsePseudo(selector, idx, tokens, options) {
337
- if (selector.charCodeAt(idx + 1) === 58) {
338
- let i2 = idx + 2;
339
- const r2 = readName(selector, i2);
340
- i2 = r2.end;
341
- const name2 = r2.value.toLowerCase();
342
- let data = null;
343
- if (selector.charCodeAt(i2) === 40) {
344
- const end = findClose(selector, i2);
345
- data = selector.slice(i2 + 1, end).trim();
346
- i2 = end + 1;
347
- }
348
- tokens.push({ type: "pseudo-element", name: name2, data });
349
- return i2;
350
- }
351
- let i = idx + 1;
352
- const r = readName(selector, i);
353
- i = r.end;
354
- const name = r.value.toLowerCase();
355
- if (selector.charCodeAt(i) === 40) {
356
- const end = findClose(selector, i);
357
- const inner = selector.slice(i + 1, end);
358
- i = end + 1;
359
- if (name === "is" || name === "not" || name === "where" || name === "has" || name === "matches" || name === "-moz-any" || name === "-webkit-any") {
360
- const sub = [];
361
- parseSelectorImpl(sub, inner.trim(), options, 0);
362
- tokens.push({ type: "pseudo", name, data: sub });
363
- } else {
364
- tokens.push({ type: "pseudo", name, data: inner.trim() });
365
- }
366
- } else {
367
- tokens.push({ type: "pseudo", name, data: null });
368
- }
369
- return i;
370
- }
371
- function addTraversal(tokens, type) {
372
- if (tokens.length > 0 && tokens[tokens.length - 1].type === "descendant" && type !== "descendant")
373
- tokens.pop();
374
- if (tokens.length > 0 && tokens[tokens.length - 1].type === type)
375
- return;
376
- tokens.push({ type });
377
- }
378
- function findEndOfString(selector, start, qCode) {
379
- let i = start;
380
- const len = selector.length;
381
- while (i < len) {
382
- const c = selector.charCodeAt(i);
383
- if (c === 92) {
384
- i += 2;
385
- continue;
386
- }
387
- if (c === qCode)
388
- return i;
389
- i++;
390
- }
391
- throw new Error("Unterminated string");
392
- }
393
- function findClose(selector, openParen) {
394
- let depth = 1;
395
- let i = openParen + 1;
396
- const len = selector.length;
397
- while (i < len) {
398
- const c = selector.charCodeAt(i);
399
- if (c === 92) {
400
- i += 2;
401
- continue;
402
- }
403
- if (c === 34 || c === 39) {
404
- i = findEndOfString(selector, i + 1, c) + 1;
405
- continue;
406
- }
407
- if (c === 40)
408
- depth++;
409
- else if (c === 41) {
410
- depth--;
411
- if (depth === 0)
412
- return i;
413
- }
414
- i++;
415
- }
416
- throw new Error("Unterminated parenthesis");
417
- }
418
- // src/what/stringify.ts
419
- var COMBINATORS = {
420
- child: " > ",
421
- parent: " < ",
422
- sibling: " ~ ",
423
- adjacent: " + ",
424
- descendant: " ",
425
- "column-combinator": " || "
426
- };
427
- function stringify(selector) {
428
- return selector.map(stringifySegments).join(", ");
429
- }
430
- function stringifySegments(tokens) {
431
- return tokens.map((t, i) => stringifyOne(t, tokens[i - 1])).join("");
432
- }
433
- function stringifyOne(token, _prev) {
434
- switch (token.type) {
435
- case "tag":
436
- return `${nsPrefix(token.namespace)}${escapeIdent(token.name)}`;
437
- case "universal":
438
- return `${nsPrefix(token.namespace)}*`;
439
- case "attribute": {
440
- if (token.name === "id" && token.action === "equals" && !token.ignoreCase && !token.namespace)
441
- return `#${escapeIdent(token.value)}`;
442
- if (token.name === "class" && token.action === "element" && !token.ignoreCase && !token.namespace)
443
- return `.${escapeIdent(token.value)}`;
444
- let out = `[${nsPrefix(token.namespace)}${escapeIdent(token.name)}`;
445
- if (token.action !== "exists") {
446
- const op = ACTION_OP[token.action] ?? "=";
447
- out += op;
448
- out += `"${token.value.replace(/"/g, "\\\"")}"`;
449
- if (token.ignoreCase === true)
450
- out += " i";
451
- else if (token.ignoreCase === false)
452
- out += " s";
453
- }
454
- out += "]";
455
- return out;
456
- }
457
- case "pseudo":
458
- if (token.data === null)
459
- return `:${token.name}`;
460
- if (typeof token.data === "string")
461
- return `:${token.name}(${token.data})`;
462
- return `:${token.name}(${stringify(token.data)})`;
463
- case "pseudo-element":
464
- return token.data === null ? `::${token.name}` : `::${token.name}(${token.data})`;
465
- case "descendant":
466
- case "child":
467
- case "parent":
468
- case "sibling":
469
- case "adjacent":
470
- case "column-combinator":
471
- return COMBINATORS[token.type] ?? " ";
472
- }
473
- return "";
474
- }
475
- var ACTION_OP = {
476
- equals: "=",
477
- element: "~=",
478
- start: "^=",
479
- end: "$=",
480
- any: "*=",
481
- not: "!=",
482
- hyphen: "|="
483
- };
484
- function nsPrefix(ns) {
485
- if (ns === null)
486
- return "";
487
- if (ns === "")
488
- return "|";
489
- return `${escapeIdent(ns)}|`;
490
- }
491
- var RE_INVALID_ID_CHAR = /[^\w\u00B0-\uFFFF-]/g;
492
- function escapeIdent(name) {
493
- if (name === "")
494
- return "";
495
- return name.replace(RE_INVALID_ID_CHAR, (m) => `\\${m}`);
496
- }
497
- // src/what/traversal.ts
498
- var TRAVERSAL_TYPES = new Set(["adjacent", "child", "descendant", "parent", "sibling", "column-combinator"]);
499
- function isTraversal(token) {
500
- return TRAVERSAL_TYPES.has(token.type);
501
- }
502
- // src/what/types.ts
503
- var IgnoreCaseMode = {
504
- Unknown: null,
505
- QuirksMode: "quirks",
506
- IgnoreCase: true,
507
- CaseSensitive: false
508
- };
509
- export {
510
- stringify,
511
- parse,
512
- isTraversal,
513
- IgnoreCaseMode
514
- };
2
+ var b=Object.defineProperty;var S=(z)=>z;function T(z,G){this[z]=S.bind(null,G)}var x=(z,G)=>{for(var Z in G)b(z,Z,{get:G[Z],enumerable:!0,configurable:!0,set:T.bind(G,Z)})};var r=import.meta.require;var c={};x(c,{stringify:()=>O,parse:()=>W,isTraversal:()=>E,IgnoreCaseMode:()=>N});var w=/(?:\\(?:[\dA-Fa-f]{1,6} ?|[^])|[\w\-\u00B0-\uFFFF])+/y,g=/\\([\dA-Fa-f]{1,6} ?|[^])/g;function I(z){return z.replace(g,(G,Z)=>{if(Z.length>1&&/^[\dA-Fa-f]/.test(Z)){let Q=Number.parseInt(Z,16);if(Q>=55296&&Q<=57343)return"\uFFFD";return String.fromCodePoint(Q)}return Z})}function R(z){return z.indexOf("\\")<0?z:I(z)}var f=new Set(["accept","accept-charset","align","alink","axis","bgcolor","charset","checked","clear","codetype","color","compact","declare","defer","dir","direction","disabled","enctype","face","frame","hreflang","http-equiv","lang","language","link","media","method","multiple","nohref","noresize","noshade","nowrap","readonly","rel","rev","rules","scope","scrolling","selected","shape","target","text","type","valign","valuetype","vlink"]);function u(z){switch(z){case 126:return"element";case 94:return"start";case 36:return"end";case 42:return"any";case 33:return"not";case 124:return"hyphen";default:return null}}function P(z){return z===32||z===9||z===10||z===13||z===12}function W(z,G={}){let Z=[],Q=_(Z,z,G,0);if(Q<z.length)throw Error(`Unmatched selector: ${z.slice(Q)}`);return Z}function Y(z,G){w.lastIndex=G;let Z=w.exec(z);if(!Z)throw Error(`Expected name, found ${z.slice(G)}`);return{value:R(Z[0]),end:G+Z[0].length}}function L(z,G){while(G<z.length&&P(z.charCodeAt(G)))G++;return G}function _(z,G,Z,Q){let H=[],X=L(G,Q),J=G.length,B=Z.xmlMode===!0,D=Z.lowerCaseAttributeNames!==!1&&!B,V=Z.lowerCaseTags!==!1;while(X<J){let U=G.charCodeAt(X);if(P(U)){let $=X+1;while($<J&&P(G.charCodeAt($)))$++;if(H.length===0)return $;X=$,h(H,"descendant");continue}if(U===62||U===60||U===126||U===43||U===124){let $=X+1;while($<J&&P(G.charCodeAt($)))$++;switch(X=$,U){case 62:h(H,"child");break;case 60:h(H,"parent");break;case 126:h(H,"sibling");break;case 43:h(H,"adjacent");break;case 124:if(X<J&&G.charCodeAt(X)===124)X++,X=L(G,X),h(H,"column-combinator");else H.push({type:"tag",name:"",namespace:""});break}continue}if(U===44){if(H.length===0)throw Error("Empty sub-selector");z.push(H),H=[],X=L(G,X+1);continue}if(U===47&&G.charCodeAt(X+1)===42){let $=G.indexOf("*/",X+2);if($<0)throw Error("Unmatched comment");X=L(G,$+2);continue}if(U===42){X++,H.push({type:"universal",namespace:null});continue}if(U===35){let $=Y(G,X+1);X=$.end,H.push({type:"attribute",name:"id",action:"equals",value:$.value,namespace:null,ignoreCase:!1});continue}if(U===46){let $=Y(G,X+1);X=$.end,H.push({type:"attribute",name:"class",action:"element",value:$.value,namespace:null,ignoreCase:!1});continue}if(U===91){X=C(G,X,H,Z,B,D);continue}if(U===58){X=p(G,X,H,Z);continue}if(U===124){X++;let $=Y(G,X);X=$.end,H.push({type:"tag",name:V?$.value.toLowerCase():$.value,namespace:""});continue}{let $=Y(G,X);if(X=$.end,X<J&&G.charCodeAt(X)===124&&G.charCodeAt(X+1)!==61){X++;let j=Y(G,X);X=j.end,H.push({type:"tag",name:V?j.value.toLowerCase():j.value,namespace:$.value})}else H.push({type:"tag",name:V?$.value.toLowerCase():$.value,namespace:null})}}if(H.length>0)z.push(H);return X}function C(z,G,Z,Q,H,X){let J=G+1,B=z.length,D;if(z.charCodeAt(J)===124)throw Error("Empty namespace not supported");if(z.charCodeAt(J)===42&&z.charCodeAt(J+1)===124){J+=2;let K=Y(z,J);J=K.end,D=K.value}else{let K=Y(z,J);if(J=K.end,D=K.value,z.charCodeAt(J)===124&&z.charCodeAt(J+1)!==61){J++;let F=Y(z,J);J=F.end,D=F.value}}J=L(z,J);let V="exists",U="",$=null,j=z.charCodeAt(J);if(j===61)V="equals",J++;else if(j===33&&z.charCodeAt(J+1)===61)V="not",J+=2;else{let K=u(j);if(K!==null&&z.charCodeAt(J+1)===61)V=K,J+=2}if(V!=="exists"){J=L(z,J);let K=z.charCodeAt(J);if(K===34||K===39){let q=A(z,J+1,K);U=R(z.slice(J+1,q)),J=q+1}else{let q=Y(z,J);U=q.value,J=q.end}J=L(z,J);let F=z.charCodeAt(J);if(F===105||F===73)$=!0,J++;else if(F===115||F===83)$=!1,J++}if(z.charCodeAt(J)!==93)throw Error("Expected ]");if(J++,$===null&&!H&&f.has(D.toLowerCase()))$="quirks";return Z.push({type:"attribute",name:X?D.toLowerCase():D,action:V,value:U,namespace:null,ignoreCase:$}),J}function p(z,G,Z,Q){if(z.charCodeAt(G+1)===58){let B=G+2,D=Y(z,B);B=D.end;let V=D.value.toLowerCase(),U=null;if(z.charCodeAt(B)===40){let $=v(z,B);U=z.slice(B+1,$).trim(),B=$+1}return Z.push({type:"pseudo-element",name:V,data:U}),B}let H=G+1,X=Y(z,H);H=X.end;let J=X.value.toLowerCase();if(z.charCodeAt(H)===40){let B=v(z,H),D=z.slice(H+1,B);if(H=B+1,J==="is"||J==="not"||J==="where"||J==="has"||J==="matches"||J==="-moz-any"||J==="-webkit-any"){let V=[];_(V,D.trim(),Q,0),Z.push({type:"pseudo",name:J,data:V})}else Z.push({type:"pseudo",name:J,data:D.trim()})}else Z.push({type:"pseudo",name:J,data:null});return H}function h(z,G){if(z.length>0&&z[z.length-1].type==="descendant"&&G!=="descendant")z.pop();if(z.length>0&&z[z.length-1].type===G)return;z.push({type:G})}function A(z,G,Z){let Q=G,H=z.length;while(Q<H){let X=z.charCodeAt(Q);if(X===92){Q+=2;continue}if(X===Z)return Q;Q++}throw Error("Unterminated string")}function v(z,G){let Z=1,Q=G+1,H=z.length;while(Q<H){let X=z.charCodeAt(Q);if(X===92){Q+=2;continue}if(X===34||X===39){Q=A(z,Q+1,X)+1;continue}if(X===40)Z++;else if(X===41){if(Z--,Z===0)return Q}Q++}throw Error("Unterminated parenthesis")}var m={child:" > ",parent:" < ",sibling:" ~ ",adjacent:" + ",descendant:" ","column-combinator":" || "};function O(z){return z.map(d).join(", ")}function d(z){return z.map((G,Z)=>k(G,z[Z-1])).join("")}function k(z,G){switch(z.type){case"tag":return`${M(z.namespace)}${y(z.name)}`;case"universal":return`${M(z.namespace)}*`;case"attribute":{if(z.name==="id"&&z.action==="equals"&&!z.ignoreCase&&!z.namespace)return`#${y(z.value)}`;if(z.name==="class"&&z.action==="element"&&!z.ignoreCase&&!z.namespace)return`.${y(z.value)}`;let Z=`[${M(z.namespace)}${y(z.name)}`;if(z.action!=="exists"){let Q=a[z.action]??"=";if(Z+=Q,Z+=`"${z.value.replace(/"/g,"\\\"")}"`,z.ignoreCase===!0)Z+=" i";else if(z.ignoreCase===!1)Z+=" s"}return Z+="]",Z}case"pseudo":if(z.data===null)return`:${z.name}`;if(typeof z.data==="string")return`:${z.name}(${z.data})`;return`:${z.name}(${O(z.data)})`;case"pseudo-element":return z.data===null?`::${z.name}`:`::${z.name}(${z.data})`;case"descendant":case"child":case"parent":case"sibling":case"adjacent":case"column-combinator":return m[z.type]??" "}return""}var a={equals:"=",element:"~=",start:"^=",end:"$=",any:"*=",not:"!=",hyphen:"|="};function M(z){if(z===null)return"";if(z==="")return"|";return`${y(z)}|`}var l=/[^\w\u00B0-\uFFFF-]/g;function y(z){if(z==="")return"";return z.replace(l,(G)=>`\\${G}`)}var i=new Set(["adjacent","child","descendant","parent","sibling","column-combinator"]);function E(z){return i.has(z.type)}var N={Unknown:null,QuirksMode:"quirks",IgnoreCase:!0,CaseSensitive:!1};export{O as stringify,W as parse,E as isTraversal,N as IgnoreCaseMode};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/ts-css",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "description": "Pure-TypeScript CSS toolkit for Bun/Node — parser, walker, generator, selector engine, and minifier. Zero runtime deps.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -86,10 +86,9 @@
86
86
  "lint:fix": "bunx --bun pickier . --fix",
87
87
  "changelog": "bunx --bun logsmith --verbose",
88
88
  "changelog:generate": "bunx --bun logsmith --output CHANGELOG.md",
89
- "release": "bun --bun run changelog:generate && bunx --bun bumpx prompt --recursive",
90
- "release:patch": "bun --bun run changelog:generate && bunx --bun bumpx patch --yes --recursive",
91
- "release:minor": "bun --bun run changelog:generate && bunx --bun bumpx minor --yes --recursive",
92
- "postinstall": "bunx git-hooks",
89
+ "release": "bunx --bun bumpx prompt --recursive",
90
+ "release:patch": "bunx --bun bumpx patch --yes --recursive",
91
+ "release:minor": "bunx --bun bumpx minor --yes --recursive",
93
92
  "dev:docs": "bun --bun bunpress dev docs",
94
93
  "build:docs": "bun --bun bunpress build docs",
95
94
  "preview:docs": "bun --bun bunpress preview docs",
@@ -104,7 +103,7 @@
104
103
  "@types/bun": "latest",
105
104
  "@types/css-tree": "^2.3.11",
106
105
  "@types/csso": "^5.0.4",
107
- "better-dx": "^0.2.7",
106
+ "better-dx": "^0.2.15",
108
107
  "css-select": "^7.0.0",
109
108
  "css-tree": "^3.2.1",
110
109
  "css-what": "^8.0.0",
@@ -113,7 +112,7 @@
113
112
  },
114
113
  "git-hooks": {
115
114
  "pre-commit": {
116
- "stagedLint": {
115
+ "staged-lint": {
117
116
  "*.{js,ts,json,yaml,yml,md}": "bunx --bun pickier lint --fix"
118
117
  },
119
118
  "autoRestage": true