@@ -165,7 +165,7 @@ export type PlainCSSNode = {
165165 property ?: string
166166 value ?: string | number | null
167167 unit ?: string
168- prelude ?: string
168+ prelude ?: PlainCSSNode | null
169169
170170 // Flags (only when true)
171171 is_important ?: boolean
@@ -307,16 +307,24 @@ export class CSSNode {
307307 }
308308
309309 /**
310- * Get the prelude node (for at-rules: structured prelude with media queries, layer names, etc.)
311- * Returns the AT_RULE_PRELUDE wrapper node containing prelude children, or null if no prelude
310+ * Get the prelude node:
311+ * - For at-rules: AT_RULE_PRELUDE wrapper containing structured prelude children (media queries, layer names, etc.)
312+ * - For style rules: SELECTOR_LIST or SELECTOR node
313+ * Returns null if no prelude exists
312314 */
313- get prelude ( ) : CSSNode | null {
314- if ( this . type !== AT_RULE ) return null
315- let first = this . first_child
316- if ( first && first . type === AT_RULE_PRELUDE ) {
317- return first
315+ get prelude ( ) : CSSNode | null | undefined {
316+ if ( this . type === AT_RULE ) {
317+ let first = this . first_child
318+ if ( first && first . type === AT_RULE_PRELUDE ) {
319+ return first
320+ }
321+ return null
318322 }
319- return null
323+ if ( this . type === STYLE_RULE ) {
324+ // For style rules, prelude is the selector (first child)
325+ return this . first_child
326+ }
327+ return undefined
320328 }
321329
322330 /**
@@ -382,9 +390,15 @@ export class CSSNode {
382390 return this . arena . has_flag ( this . index , FLAG_HAS_ERROR )
383391 }
384392
385- /** Check if this at-rule has a prelude */
393+ /** Check if this node has a prelude (at-rules and style rules) */
386394 get has_prelude ( ) : boolean {
387- return this . arena . get_value_length ( this . index ) > 0
395+ if ( this . type === AT_RULE ) {
396+ return this . arena . get_value_length ( this . index ) > 0
397+ }
398+ if ( this . type === STYLE_RULE ) {
399+ return this . first_child !== null
400+ }
401+ return false
388402 }
389403
390404 /** Check if this rule has a block { } */
0 commit comments