Skip to content

Commit 757909c

Browse files
authored
Move lengthy comments (#86)
follow-up of #84
1 parent 95d63e8 commit 757909c

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

API.md

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,65 @@ function parse(source: string, options?: ParserOptions): CSSNode
3131

3232
`CSSNode` - Root stylesheet node with the following properties:
3333

34+
**Core Properties:**
3435
- `type` - Node type constant (e.g., `STYLESHEET`, `STYLE_RULE`)
3536
- `type_name` - CSSTree-compatible type name (e.g., `'StyleSheet'`, `'Rule'`)
3637
- `text` - Full text of the node from source
37-
- `name` - Property name, at-rule name, or layer name
38-
- `property` - Alias for `name` (for declarations)
39-
- `value` - Value text (for declarations), URL content (for URL nodes with quoted strings, includes quotes to match STRING node behavior), or `null`
38+
39+
**Content Properties:**
40+
- `name` - Property name for declarations, at-rule name for at-rules, layer name for import layers
41+
- `property` - Alias for `name` (for declarations, more semantic)
42+
- `value` - Value text (for declarations), numeric value (for NUMBER/DIMENSION), string content without quotes (for STRING), URL content (for URL), or `null`
43+
- `value_as_number` - Numeric value for NUMBER and DIMENSION nodes, or `null` for other types
44+
- `unit` - Unit string for DIMENSION nodes (e.g., `"px"`, `"%"`), or `null` for other types
4045
- `prelude` - At-rule prelude text or `null`
46+
47+
**Location Properties:**
4148
- `line` - Starting line number (1-based)
42-
- `offset` - Starting offset in source
49+
- `column` - Starting column number (1-based)
50+
- `start` - Starting offset in source (0-based)
4351
- `length` - Length in source
44-
- `is_important` - Whether declaration has `!important`
45-
- `is_vendor_prefixed` - Whether name has vendor prefix
52+
- `end` - End offset in source (calculated as `start + length`)
53+
54+
**Flags:**
55+
- `is_important` - Whether declaration has `!important` (DECLARATION only)
56+
- `is_vendor_prefixed` - Whether node has vendor prefix (checks name/text based on type)
4657
- `has_error` - Whether node has syntax error
4758
- `has_prelude` - Whether at-rule has a prelude
4859
- `has_block` - Whether rule has a `{ }` block
49-
- `has_children` - Whether node has child nodes (for pseudo-class/pseudo-element functions, returns `true` even if empty to indicate function syntax)
50-
- `block` - Block node containing declarations/nested rules (for style rules and at-rules with blocks)
51-
- `is_empty` - Whether block has no declarations or rules (only comments allowed)
60+
- `has_declarations` - Whether style rule has declarations
61+
- `has_children` - Whether node has child nodes (for pseudo-class/pseudo-element, returns `true` even if empty to indicate function syntax)
62+
- `has_next` - Whether node has a next sibling
63+
64+
**Tree Structure:**
5265
- `first_child` - First child node or `null`
5366
- `next_sibling` - Next sibling node or `null`
5467
- `children` - Array of all child nodes
68+
- `block` - Block node containing declarations/nested rules (for style rules and at-rules with blocks)
69+
- `is_empty` - Whether block has no declarations or rules (only comments allowed)
70+
71+
**Value Access (Declarations):**
5572
- `values` - Array of value nodes (for declarations)
73+
74+
**Selector Properties:**
5675
- `selector_list` - Selector list from pseudo-classes like `:is()`, `:not()`, `:has()`, `:where()`, or `:nth-child(of)`
5776
- `nth` - An+B formula node from `:nth-child(of)` wrapper (for NTH_OF_SELECTOR nodes)
5877
- `selector` - Selector list from `:nth-child(of)` wrapper (for NTH_OF_SELECTOR nodes)
59-
- `nth_a` - The 'a' coefficient from An+B expressions like `2n` from `:nth-child(2n+1)`
60-
- `nth_b` - The 'b' coefficient from An+B expressions like `+1` from `:nth-child(2n+1)`
61-
- `compound_parts()` - Iterator over first compound selector parts (zero allocation, for SELECTOR)
62-
- `first_compound` - Array of parts before first combinator (for SELECTOR)
63-
- `all_compounds` - Array of compound arrays split by combinators (for SELECTOR)
64-
- `is_compound` - Whether selector has no combinators (for SELECTOR)
65-
- `first_compound_text` - Text of first compound selector (for SELECTOR)
78+
- `nth_a` - The 'a' coefficient from An+B expressions like `"2n"` from `:nth-child(2n+1)` (for NTH_SELECTOR)
79+
- `nth_b` - The 'b' coefficient from An+B expressions like `"+1"` from `:nth-child(2n+1)` (for NTH_SELECTOR)
80+
81+
**Attribute Selector Properties:**
82+
- `attr_operator` - Attribute operator constant (for ATTRIBUTE_SELECTOR): `ATTR_OPERATOR_NONE`, `ATTR_OPERATOR_EQUAL`, etc.
83+
- `attr_flags` - Attribute flags constant (for ATTRIBUTE_SELECTOR): `ATTR_FLAG_NONE`, `ATTR_FLAG_CASE_INSENSITIVE`, `ATTR_FLAG_CASE_SENSITIVE`
84+
85+
**Compound Selector Helpers (SELECTOR nodes):**
86+
- `compound_parts()` - Iterator over first compound selector parts (zero allocation)
87+
- `first_compound` - Array of parts before first combinator
88+
- `all_compounds` - Array of compound arrays split by combinators
89+
- `is_compound` - Whether selector has no combinators
90+
- `first_compound_text` - Text of first compound selector (no node allocation)
91+
92+
**Methods:**
6693
- `clone(options?)` - Clone node as a mutable plain object with children as arrays
6794

6895
### Example 1: Basic Parsing
@@ -470,7 +497,8 @@ console.log(deep.children[1].value) // 20
470497
const withLocation = marginDecl.clone({ locations: true })
471498
console.log(withLocation.line) // 1
472499
console.log(withLocation.column) // 6
473-
console.log(withLocation.offset) // 6
500+
console.log(withLocation.start) // 6
501+
console.log(withLocation.end) // 28
474502

475503
// Cloned objects are mutable
476504
const clone = marginDecl.clone()
@@ -489,7 +517,7 @@ clone.children.push({ type: 99, text: 'test', children: [] })
489517
**Options**:
490518

491519
- `deep?: boolean` (default: `true`) - Recursively clone children
492-
- `locations?: boolean` (default: `false`) - Include line/column/offset/length
520+
- `locations?: boolean` (default: `false`) - Include line/column/start/length/end
493521

494522
**Return Type**: Plain object with:
495523

0 commit comments

Comments
 (0)