@projectwallace/css-parser 0.14.9 → 0.14.10

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.
@@ -45,6 +45,22 @@ const TYPE_NAMES = {
45
45
  [40]: "AtrulePrelude",
46
46
  [41]: "PreludeSelectorList"
47
47
  };
48
+ const nodes_with_name = new Set([
49
+ 3,
50
+ 10,
51
+ 15,
52
+ 21,
53
+ 22,
54
+ 23,
55
+ 24,
56
+ 25,
57
+ 26,
58
+ 27,
59
+ 28,
60
+ 56,
61
+ 37,
62
+ 39
63
+ ]);
48
64
  const nodes_with_children = new Set([
49
65
  1,
50
66
  5,
@@ -61,6 +77,21 @@ const nodes_with_children = new Set([
61
77
  35,
62
78
  39
63
79
  ]);
80
+ const enumerable_properties = [
81
+ "name",
82
+ "property",
83
+ "value",
84
+ "unit",
85
+ "attr_operator",
86
+ "attr_flags",
87
+ "nth_a",
88
+ "nth_b",
89
+ "selector",
90
+ "is_browserhack",
91
+ "is_vendor_prefixed",
92
+ "has_error",
93
+ "is_important"
94
+ ];
64
95
  var CSSNode = class CSSNode {
65
96
  arena;
66
97
  source;
@@ -99,9 +130,11 @@ var CSSNode = class CSSNode {
99
130
  }
100
131
  /** Get the "content" text (at-rule name for at-rules, layer name for import layers) */
101
132
  get name() {
133
+ if (!nodes_with_name.has(this.type)) return;
134
+ let content = this.get_content();
102
135
  let { type } = this;
103
- if (type === 4 || type === 16 || type === 5 || type === 33) return;
104
- return this.get_content();
136
+ if ((type === 28 || type === 56) && content === "") return null;
137
+ return content;
105
138
  }
106
139
  /**
107
140
  * Alias for name (for declarations: "color" in "color: blue")
@@ -238,6 +271,8 @@ var CSSNode = class CSSNode {
238
271
  }
239
272
  /** Check if this style rule has declarations */
240
273
  get has_declarations() {
274
+ let { type } = this;
275
+ if (type !== 3 && type !== 2) return void 0;
241
276
  return this.arena.has_flag(this.index, 32);
242
277
  }
243
278
  /** Get the block node (for style rules and at-rules with blocks) */
@@ -354,7 +389,7 @@ var CSSNode = class CSSNode {
354
389
  let { type, arena, index } = this;
355
390
  if (type !== 30 && type !== 31) return void 0;
356
391
  let len = arena.get_content_length(index);
357
- if (len === 0) return void 0;
392
+ if (len === 0) return null;
358
393
  let start = arena.get_content_start(index);
359
394
  return this.source.substring(start, start + len);
360
395
  }
@@ -363,7 +398,7 @@ var CSSNode = class CSSNode {
363
398
  let { type, arena, index, source } = this;
364
399
  if (type !== 30 && type !== 31) return void 0;
365
400
  let len = arena.get_value_length(index);
366
- if (len === 0) return void 0;
401
+ if (len === 0) return null;
367
402
  let start = arena.get_value_start(index);
368
403
  let value = source.substring(start, start + len);
369
404
  let check_pos = start - 1;
@@ -400,35 +435,16 @@ var CSSNode = class CSSNode {
400
435
  */
401
436
  clone(options = {}) {
402
437
  const { deep = true, locations = false } = options;
403
- let { type, name, property, value, unit } = this;
438
+ let { type } = this;
404
439
  let plain = {
405
440
  type,
406
441
  type_name: this.type_name,
407
442
  text: this.text
408
443
  };
409
- if (name) plain.name = name;
410
- if (property) plain.property = property;
411
- if (value) {
412
- plain.value = value;
413
- if (unit) plain.unit = unit;
414
- }
415
- if (type === 4) {
416
- let { is_important, is_browserhack } = this;
417
- if (is_important) plain.is_important = true;
418
- if (is_browserhack) plain.is_browserhack = true;
419
- }
420
- let { is_vendor_prefixed, has_error } = this;
421
- if (is_vendor_prefixed) plain.is_vendor_prefixed = true;
422
- if (has_error) plain.has_error = true;
423
- if (type === 24) {
424
- plain.attr_operator = this.attr_operator;
425
- plain.attr_flags = this.attr_flags;
426
- }
427
- if (type === 30 || type === 31) {
428
- plain.nth_a = this.nth_a;
429
- plain.nth_b = this.nth_b;
444
+ for (let key of enumerable_properties) {
445
+ let val = this[key];
446
+ if (val !== void 0 && val !== false) plain[key] = val;
430
447
  }
431
- if (type === 31) plain.selector = this.selector;
432
448
  if (locations) {
433
449
  plain.line = this.line;
434
450
  plain.column = this.column;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { B as TYPE_SELECTOR, C as NESTING_SELECTOR, D as OPERATOR, E as NUMBER, F as SELECTOR_LIST, H as UNIVERSAL_SELECTOR, I as STRING, L as STYLESHEET, M as PSEUDO_ELEMENT_SELECTOR, N as RAW, O as PARENTHESIS, P as SELECTOR, R as STYLE_RULE, S as MEDIA_TYPE, T as NTH_SELECTOR, U as URL, V as UNICODE_RANGE, W as VALUE, _ as ID_SELECTOR, a as CLASS_SELECTOR, b as MEDIA_FEATURE, c as CONTAINER_QUERY, d as DIMENSION, f as FEATURE_RANGE, g as IDENTIFIER, h as HASH, i as BLOCK, j as PSEUDO_CLASS_SELECTOR, k as PRELUDE_OPERATOR, m as FUNCTION, n as AT_RULE, o as COMBINATOR, p as FLAG_IMPORTANT, r as AT_RULE_PRELUDE, s as COMMENT, t as ATTRIBUTE_SELECTOR, u as DECLARATION, v as LANG_SELECTOR, w as NTH_OF_SELECTOR, x as MEDIA_QUERY, y as LAYER_NAME, z as SUPPORTS_QUERY } from "./arena-D6TANE5e.js";
2
2
  import { NODE_TYPES } from "./constants.js";
3
3
  import { A as TOKEN_URL, C as TOKEN_PERCENTAGE, D as TOKEN_SEMICOLON, E as TOKEN_RIGHT_PAREN, M as Token, N as TokenType, O as TOKEN_STRING, S as TOKEN_NUMBER, T as TOKEN_RIGHT_BRACKET, _ as TOKEN_HASH, a as TOKEN_AT_KEYWORD, b as TOKEN_LEFT_BRACKET, c as TOKEN_CDC, d as TOKEN_COMMA, f as TOKEN_COMMENT, g as TOKEN_FUNCTION, h as TOKEN_EOF, i as tokenize, j as TOKEN_WHITESPACE, k as TOKEN_UNICODE_RANGE, l as TOKEN_CDO, m as TOKEN_DIMENSION, o as TOKEN_BAD_STRING, p as TOKEN_DELIM, r as LexerPosition, s as TOKEN_BAD_URL, t as CommentInfo, u as TOKEN_COLON, v as TOKEN_IDENT, w as TOKEN_RIGHT_BRACE, x as TOKEN_LEFT_PAREN, y as TOKEN_LEFT_BRACE } from "./tokenize-CyiJelQC.js";
4
- import { $ as is_combinator, A as PreludeSelectorList, At as is_supports_query, B as SupportsQuery, C as NestingSelector, Ct as is_pseudo_element_selector, D as Operator, Dt as is_selector_list, E as Number, Et as is_selector, F as Selector, Ft as is_value, G as Url, H as TypeSelector, I as SelectorList, It as CloneOptions, J as is_atrule, K as Value, L as SelectorNode, Lt as PlainCSSNode, M as PseudoElementSelector, Mt as is_unicode_range, N as Raw, Nt as is_universal_selector, O as Parenthesis, Ot as is_string, P as Rule, Pt as is_url, Q as is_class_selector, R as String, Rt as TYPE_NAMES, S as MediaType, St as is_pseudo_class_selector, T as NthSelector, Tt as is_rule, U as UnicodeRange, V as ToPlain, W as UniversalSelector, X as is_attribute_selector, Y as is_atrule_prelude, Z as is_block, _ as Identifier, _t as is_number, a as Block, at as is_function, b as MediaFeature, bt as is_prelude_operator, c as Combinator, ct as is_identifier, d as Declaration, dt as is_media_feature, et as is_comment, f as Dimension, ft as is_media_query, g as IdSelector, gt as is_nth_selector, h as Hash, ht as is_nth_of_selector, i as AttributeSelector, it as is_feature_range, j as PseudoClassSelector, jt as is_type_selector, k as PreludeOperator, kt as is_stylesheet, l as Comment, lt as is_lang_selector, m as Function, mt as is_nesting_selector, n as Atrule, nt as is_declaration, o as CSSNode, ot as is_hash, p as FeatureRange, pt as is_media_type, q as WithChildren, r as AtrulePrelude, rt as is_dimension, s as ClassSelector, st as is_id_selector, t as AnyNode, tt as is_container_query, u as ContainerQuery, ut as is_layer_name, v as LangSelector, vt as is_operator, w as NthOfSelector, wt as is_raw, x as MediaQuery, xt as is_prelude_selectorlist, y as LayerName, yt as is_parenthesis, z as StyleSheet } from "./node-types-CfWcbFWR.js";
4
+ import { $ as is_combinator, A as PreludeSelectorList, At as is_supports_query, B as SupportsQuery, C as NestingSelector, Ct as is_pseudo_element_selector, D as Operator, Dt as is_selector_list, E as Number, Et as is_selector, F as Selector, Ft as is_value, G as Url, H as TypeSelector, I as SelectorList, It as CloneOptions, J as is_atrule, K as Value, L as SelectorNode, Lt as PlainCSSNode, M as PseudoElementSelector, Mt as is_unicode_range, N as Raw, Nt as is_universal_selector, O as Parenthesis, Ot as is_string, P as Rule, Pt as is_url, Q as is_class_selector, R as String, Rt as TYPE_NAMES, S as MediaType, St as is_pseudo_class_selector, T as NthSelector, Tt as is_rule, U as UnicodeRange, V as ToPlain, W as UniversalSelector, X as is_attribute_selector, Y as is_atrule_prelude, Z as is_block, _ as Identifier, _t as is_number, a as Block, at as is_function, b as MediaFeature, bt as is_prelude_operator, c as Combinator, ct as is_identifier, d as Declaration, dt as is_media_feature, et as is_comment, f as Dimension, ft as is_media_query, g as IdSelector, gt as is_nth_selector, h as Hash, ht as is_nth_of_selector, i as AttributeSelector, it as is_feature_range, j as PseudoClassSelector, jt as is_type_selector, k as PreludeOperator, kt as is_stylesheet, l as Comment, lt as is_lang_selector, m as Function, mt as is_nesting_selector, n as Atrule, nt as is_declaration, o as CSSNode, ot as is_hash, p as FeatureRange, pt as is_media_type, q as WithChildren, r as AtrulePrelude, rt as is_dimension, s as ClassSelector, st as is_id_selector, t as AnyNode, tt as is_container_query, u as ContainerQuery, ut as is_layer_name, v as LangSelector, vt as is_operator, w as NthOfSelector, wt as is_raw, x as MediaQuery, xt as is_prelude_selectorlist, y as LayerName, yt as is_parenthesis, z as StyleSheet } from "./node-types-D282RMOz.js";
5
5
  import { ParserOptions, parse } from "./parse.js";
6
6
  import { parse_selector } from "./parse-selector.js";
7
7
  import { parse_atrule_prelude } from "./parse-atrule-prelude.js";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { C as TOKEN_RIGHT_BRACKET, D as TOKEN_UNICODE_RANGE, E as TOKEN_STRING, O as TOKEN_URL, S as TOKEN_RIGHT_BRACE, T as TOKEN_SEMICOLON, _ as TOKEN_LEFT_BRACE, a as TOKEN_BAD_URL, b as TOKEN_NUMBER, c as TOKEN_COLON, d as TOKEN_DELIM, f as TOKEN_DIMENSION, g as TOKEN_IDENT, h as TOKEN_HASH, i as TOKEN_BAD_STRING, k as TOKEN_WHITESPACE, l as TOKEN_COMMA, m as TOKEN_FUNCTION, n as tokenize, o as TOKEN_CDC, p as TOKEN_EOF, r as TOKEN_AT_KEYWORD, s as TOKEN_CDO, u as TOKEN_COMMENT, v as TOKEN_LEFT_BRACKET, w as TOKEN_RIGHT_PAREN, x as TOKEN_PERCENTAGE, y as TOKEN_LEFT_PAREN } from "./tokenize-BSycRGm0.js";
2
2
  import { A as PSEUDO_CLASS_SELECTOR, B as UNICODE_RANGE, C as NESTING_SELECTOR, D as OPERATOR, E as NUMBER, F as STRING, H as URL, I as STYLESHEET, L as STYLE_RULE, M as RAW, N as SELECTOR, O as PARENTHESIS, P as SELECTOR_LIST, R as SUPPORTS_QUERY, S as MEDIA_TYPE, T as NTH_SELECTOR, U as VALUE, V as UNIVERSAL_SELECTOR, _ as ID_SELECTOR, a as CLASS_SELECTOR, b as MEDIA_FEATURE, c as CONTAINER_QUERY, d as DIMENSION, f as FEATURE_RANGE, g as IDENTIFIER, h as HASH, i as BLOCK, j as PSEUDO_ELEMENT_SELECTOR, k as PRELUDE_OPERATOR, m as FUNCTION, n as AT_RULE, o as COMBINATOR, p as FLAG_IMPORTANT, r as AT_RULE_PRELUDE, s as COMMENT, t as ATTRIBUTE_SELECTOR, u as DECLARATION, v as LANG_SELECTOR, w as NTH_OF_SELECTOR, x as MEDIA_QUERY, y as LAYER_NAME, z as TYPE_SELECTOR } from "./arena-CveFYH2l.js";
3
3
  import { c as str_starts_with, i as is_vendor_prefixed, o as str_equals, r as is_custom, s as str_index_of, t as parse_dimension } from "./parse-dimension-CCn_XRDe.js";
4
- import { n as TYPE_NAMES } from "./css-node-DwKXZuNm.js";
4
+ import { n as TYPE_NAMES } from "./css-node-DMd5jbdm.js";
5
5
  import { parse_selector } from "./parse-selector.js";
6
6
  import { parse_atrule_prelude } from "./parse-atrule-prelude.js";
7
7
  import { parse_value } from "./parse-value.js";
@@ -148,7 +148,6 @@ type StyleSheet = CSSNode & WithChildren & {
148
148
  };
149
149
  type Rule = CSSNode & {
150
150
  readonly type: typeof STYLE_RULE;
151
- readonly name: string;
152
151
  readonly has_declarations: boolean;
153
152
  clone(options?: CloneOptions): ToPlain<Rule>;
154
153
  } & /** SELECTOR_LIST (parse_selectors=true) or RAW (parse_selectors=false) */({
@@ -199,9 +198,27 @@ type SelectorList = CSSNode & WithChildren<Selector> & {
199
198
  readonly type: typeof SELECTOR_LIST;
200
199
  clone(options?: CloneOptions): ToPlain<SelectorList>;
201
200
  };
201
+ /**
202
+ * A node that appears as a direct child of a Block.
203
+ *
204
+ * Identical to `Raw | Declaration | Atrule | Rule` except that `next_sibling`
205
+ * is narrowed to the same union instead of the generic `CSSNode`. This is
206
+ * safe because none of these four types use WithChildren themselves, so
207
+ * there is no recursive type graph to trigger TS2589.
208
+ */
209
+ type BlockChild = (Raw | Declaration | Atrule | Rule) & ({
210
+ readonly has_next: false;
211
+ readonly next_sibling: null;
212
+ } | {
213
+ readonly has_next: true;
214
+ readonly next_sibling: Raw | Declaration | Atrule | Rule;
215
+ });
202
216
  type Block = CSSNode & WithChildren<Raw | Declaration | Atrule | Rule> & {
203
217
  readonly type: typeof BLOCK;
204
- readonly is_empty: boolean;
218
+ readonly is_empty: boolean; /** Block children with next_sibling narrowed to the Block child union. */
219
+ readonly first_child: BlockChild;
220
+ readonly children: BlockChild[];
221
+ [Symbol.iterator](): Iterator<BlockChild>;
205
222
  clone(options?: CloneOptions): ToPlain<Block>;
206
223
  };
207
224
  type Comment = CSSNode & {
@@ -1,5 +1,5 @@
1
1
  import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
- import { T as NthSelector } from "./node-types-CfWcbFWR.js";
2
+ import { T as NthSelector } from "./node-types-D282RMOz.js";
3
3
 
4
4
  //#region src/parse-anplusb.d.ts
5
5
  /** @internal */
@@ -1,7 +1,7 @@
1
1
  import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
2
  import { l as CSSDataArena } from "./arena-CveFYH2l.js";
3
3
  import { o as str_equals, s as str_index_of } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DwKXZuNm.js";
4
+ import { t as CSSNode } from "./css-node-DMd5jbdm.js";
5
5
  //#region src/parse-anplusb.ts
6
6
  /** @internal */
7
7
  var ANplusBParser = class {
@@ -1,5 +1,5 @@
1
1
  import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
- import { t as AnyNode } from "./node-types-CfWcbFWR.js";
2
+ import { t as AnyNode } from "./node-types-D282RMOz.js";
3
3
 
4
4
  //#region src/parse-atrule-prelude.d.ts
5
5
  /** @internal */
@@ -1,7 +1,7 @@
1
1
  import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
2
  import { l as CSSDataArena } from "./arena-CveFYH2l.js";
3
3
  import { a as is_whitespace, l as strip_vendor_prefix, o as str_equals } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DwKXZuNm.js";
4
+ import { t as CSSNode } from "./css-node-DMd5jbdm.js";
5
5
  import { i as trim_boundaries, n as skip_whitespace_and_comments_forward } from "./parse-utils-BxrmqJxI.js";
6
6
  //#region src/parse-atrule-prelude.ts
7
7
  /** @internal */
@@ -1,6 +1,6 @@
1
1
  import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
2
  import { n as Lexer } from "./tokenize-CyiJelQC.js";
3
- import { d as Declaration } from "./node-types-CfWcbFWR.js";
3
+ import { d as Declaration } from "./node-types-D282RMOz.js";
4
4
 
5
5
  //#region src/parse-declaration.d.ts
6
6
  /** @internal */
@@ -1,7 +1,7 @@
1
1
  import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
2
  import { l as CSSDataArena } from "./arena-CveFYH2l.js";
3
3
  import { i as is_vendor_prefixed } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DwKXZuNm.js";
4
+ import { t as CSSNode } from "./css-node-DMd5jbdm.js";
5
5
  import { i as trim_boundaries } from "./parse-utils-BxrmqJxI.js";
6
6
  import { ValueParser } from "./parse-value.js";
7
7
  //#region src/parse-declaration.ts
@@ -1,5 +1,5 @@
1
1
  import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
- import { I as SelectorList } from "./node-types-CfWcbFWR.js";
2
+ import { I as SelectorList } from "./node-types-D282RMOz.js";
3
3
 
4
4
  //#region src/parse-selector.d.ts
5
5
  /** @internal */
@@ -1,7 +1,7 @@
1
1
  import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
2
  import { l as CSSDataArena } from "./arena-CveFYH2l.js";
3
3
  import { a as is_whitespace, n as is_combinator, o as str_equals } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DwKXZuNm.js";
4
+ import { t as CSSNode } from "./css-node-DMd5jbdm.js";
5
5
  import { n as skip_whitespace_and_comments_forward, r as skip_whitespace_forward, t as skip_whitespace_and_comments_backward } from "./parse-utils-BxrmqJxI.js";
6
6
  import { ANplusBParser } from "./parse-anplusb.js";
7
7
  //#region src/parse-selector.ts
@@ -1,5 +1,5 @@
1
1
  import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
- import { K as Value } from "./node-types-CfWcbFWR.js";
2
+ import { K as Value } from "./node-types-D282RMOz.js";
3
3
 
4
4
  //#region src/parse-value.d.ts
5
5
  /** @internal */
@@ -1,7 +1,7 @@
1
1
  import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
2
  import { l as CSSDataArena } from "./arena-CveFYH2l.js";
3
3
  import { a as is_whitespace, o as str_equals } from "./parse-dimension-CCn_XRDe.js";
4
- import { t as CSSNode } from "./css-node-DwKXZuNm.js";
4
+ import { t as CSSNode } from "./css-node-DMd5jbdm.js";
5
5
  //#region src/parse-value.ts
6
6
  /** @internal */
7
7
  var ValueParser = class {
package/dist/parse.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { l as CSSDataArena } from "./arena-D6TANE5e.js";
2
2
  import { t as CommentInfo } from "./tokenize-CyiJelQC.js";
3
- import { z as StyleSheet } from "./node-types-CfWcbFWR.js";
3
+ import { z as StyleSheet } from "./node-types-D282RMOz.js";
4
4
 
5
5
  //#region src/parse.d.ts
6
6
  interface ParserOptions {
package/dist/parse.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as Lexer } from "./tokenize-BSycRGm0.js";
2
2
  import { l as CSSDataArena } from "./arena-CveFYH2l.js";
3
- import { t as CSSNode } from "./css-node-DwKXZuNm.js";
3
+ import { t as CSSNode } from "./css-node-DMd5jbdm.js";
4
4
  import { i as trim_boundaries } from "./parse-utils-BxrmqJxI.js";
5
5
  import { SelectorParser } from "./parse-selector.js";
6
6
  import { AtRulePreludeParser } from "./parse-atrule-prelude.js";
package/dist/walk.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { o as CSSNode, t as AnyNode } from "./node-types-CfWcbFWR.js";
1
+ import { o as CSSNode, t as AnyNode } from "./node-types-D282RMOz.js";
2
2
 
3
3
  //#region src/walk.d.ts
4
4
  declare const SKIP: unique symbol;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectwallace/css-parser",
3
- "version": "0.14.9",
3
+ "version": "0.14.10",
4
4
  "description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
5
5
  "keywords": [
6
6
  "ast",