/** * `@quantize` CSS block parser and compiler. * * Parses custom `@quantize boundaryName { state { prop: value } }` blocks * from CSS source and compiles them into native `@container` queries using * resolved `BoundaryDef` thresholds. * * @module */ import { type Boundary } from '@czap/core'; /** * A nested `@supports` / `@media` group inside a `@quantize` state body. * Serialized inside the state's `@container` block as a real at-rule group. * Nested at-rule groups are preserved (depth ≥ 2); silent drop is forbidden (#110). */ export interface QuantizeAtRuleGroup { /** The at-rule prelude exactly as authored (e.g. `@supports (display: grid)`). */ readonly prelude: string; /** Declarations authored directly inside the at-rule (no nested selector). */ readonly bareProps: Record; /** Nested selector rules inside the at-rule. */ readonly rules: readonly QuantizeNestedRule[]; /** Nested `@supports` / `@media` groups inside this at-rule (#110 depth ≥ 2). */ readonly atRuleGroups?: readonly QuantizeAtRuleGroup[]; } /** * A nested rule inside a `@quantize` state: a CSS selector plus the * property map applied to it when the state is active. */ export interface QuantizeNestedRule { /** CSS selector exactly as authored (e.g. `.grid`, `.hero__title`). */ readonly selector: string; /** `{ cssProp: value }` declarations inside the nested rule. */ readonly props: Record; } /** * The non-CSS cast targets authored as nested `@ { … }` segments * inside a `@quantize` state. Each is a sibling of the CSS body * (`bareProps` / `rules`) and routes through its own compiler arm in the * build cast loop: * * - `aria` — `aria-*` / `role` attributes → `ARIACompiler`. * - `glsl` — numeric GLSL uniforms → `GLSLCompiler`. * - `wgsl` — numeric WGSL uniforms → `WGSLCompiler`. * * The marker name (`@aria` / `@glsl` / `@wgsl`) names the target; the nested * declarations are that target's per-state attribute/uniform map. */ export type CastTarget = 'aria' | 'glsl' | 'wgsl'; /** Ordered cast targets parsed from `@ { … }` segments. */ export declare const CAST_TARGETS: readonly CastTarget[]; /** * The parsed body of one `@quantize` state: bare declarations that apply * to the boundary element selector (the documented flat form) plus * nested per-selector rules (the adaptive per-element form). */ export interface QuantizeStateBody { /** Declarations written directly inside the state (flat form). */ readonly bareProps: Record; /** Nested ` { ... }` rules written inside the state. */ readonly rules: readonly QuantizeNestedRule[]; /** Nested `@supports` / `@media` groups authored inside the state (#110). */ readonly atRuleGroups?: readonly QuantizeAtRuleGroup[]; /** * Authored per-state non-CSS cast attributes, keyed by cast target. Each * entry holds the raw `{ key: value }` declarations from a nested * `@ { … }` segment (quotes stripped). Generalized from the * original `@aria`-only form so adding a cast target is a registration in * {@link CAST_TARGETS}, not a new field. Targets the state did not author * are absent; the field itself is absent when no cast segment was authored. * * Downstream each target routes through its compiler arm via `dispatch` * (ARIA → `ARIACompiler`, GLSL → `GLSLCompiler`, WGSL → `WGSLCompiler`). */ readonly castAttrs?: Partial>>; /** * Authored per-state ARIA/data attributes from a nested `@aria { … }` * segment (e.g. `aria-expanded: false; role: button`). Quotes are stripped. * Validated downstream by `ARIACompiler` against `BoundaryAttribute.isAllowedKey` * (`aria-*` / `role`). Absent when the state declares no `@aria` block. * * Derived from `castAttrs.aria` and kept as a parallel field so existing * ARIA consumers/tests read it unchanged. */ readonly ariaAttrs?: Record; } /** * A single parsed `@quantize` block: the boundary being quantised, the * per-state bodies, and provenance info so HMR can emit * source-mapped warnings. */ export interface QuantizeBlock { /** Boundary name referenced in the at-rule preamble. */ readonly boundaryName: string; /** `{ stateName: { bareProps, rules } }` mapping. */ readonly states: Record; /** Absolute path of the CSS source file. */ readonly sourceFile: string; /** 1-based source line where the block begins. */ readonly line: number; } /** * Parse every `@quantize` block from CSS source text. * * Grammar (states accept bare declarations, nested selector rules, or * both): * * ```css * @quantize boundaryName { * stateName { * property: value; * .selector { * property: value; * } * } * } * ``` * * Parsing is fully character-level: upstream compilers (e.g. the Astro * compiler re-serializing a `