/** * `@style` CSS block parser and compiler. * * Parses custom `@style name { state { prop: value; } }` blocks from * CSS source and compiles them into scoped CSS with `@layer`, * `@scope`, and `@starting-style` rules using resolved `StyleDef` * definitions. * * @module */ import type { Style } from '@czap/core'; import { StyleCSSCompiler } from '@czap/compiler'; import { normalizeCssLineEndings } from './normalize-css-eol.js'; import { blankCssCommentsAndStrings, braceDepthDelta, lineOfOffset, parseFlatDeclarations, skipSegment, skipWsAndComments, } from './css-scan.js'; // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- /** * Single parsed `@style` block: the style name being referenced, its * per-state CSS property overrides, and provenance. */ export interface StyleBlock { /** Named style (resolved against exported `StyleDef` values). */ readonly styleName: string; /** `{ stateName: { cssProp: value } }` mapping. */ readonly states: Record>; /** Absolute source file path. */ readonly sourceFile: string; /** 1-based line where the block begins. */ readonly line: number; } // --------------------------------------------------------------------------- // Parser // --------------------------------------------------------------------------- /** * Parse every `@style` block from CSS source text. * * Grammar: * * ```css * @style name { * stateName { * property: value; * } * } * ``` * * Parsing is fully character-level via the shared `css-scan` helpers * (same scanner as `@token` / `@theme` / `@quantize`): upstream * compilers (e.g. the Astro compiler re-serializing a `