/** * StyleDef -- adaptive style primitive for constraint-based rendering. * * A style binds a base style layer to optional boundary states with * per-state overrides and transitions. Content-addressed via FNV-1a. * * @module */ import type { ContentAddress } from './brands.js'; import { Millis } from './brands.js'; import type { Boundary } from './boundary.js'; import type { StateUnion } from './type-utils.js'; /** Single `box-shadow` layer — compiled into a space-separated CSS value by {@link Style.tap}. */ export interface ShadowLayer { readonly x: number; readonly y: number; readonly blur: number; readonly spread?: number; readonly color: string; readonly inset?: boolean; } /** * One layer of a {@link Style}: a flat property bag plus optional pseudo * selectors (`:hover`, `::before`, …) and structured `box-shadow` layers. */ export interface StyleLayer { readonly properties: Record; readonly pseudo?: Record>; readonly boxShadow?: readonly ShadowLayer[]; } interface StyleDef { readonly _tag: 'StyleDef'; readonly _version: 1; readonly id: ContentAddress; readonly boundary?: B; readonly base: StyleLayer; readonly states?: { readonly [S in StateUnion & string]?: StyleLayer; }; readonly transition?: { readonly duration: Millis; readonly easing?: string; readonly properties?: readonly string[]; }; } /** `Style.make` transition input — plain `number` durations are branded with {@link Millis} internally. */ interface TransitionConfig { readonly duration: number; readonly easing?: string; readonly properties?: readonly string[]; } interface StyleFactory { make(config: { readonly boundary?: B; readonly base: StyleLayer; readonly states?: { readonly [S in StateUnion & string]?: StyleLayer; }; readonly transition?: TransitionConfig; }): StyleDef; } /** * Deep merge two style layers: properties spread, pseudo merge per selector, boxShadow concat. * * Override properties win over base. Pseudo-element selectors are merged per * key. Box shadows are concatenated (base first, then override). * * @example * ```ts * const base = { properties: { color: 'red', padding: '4px' } }; * const override = { properties: { color: 'blue', margin: '8px' } }; * const merged = Style.mergeLayers(base, override); * // merged.properties === { color: 'blue', padding: '4px', margin: '8px' } * ``` */ declare function _mergeLayers(base: StyleLayer, override: StyleLayer): StyleLayer; /** * Resolve a style to a flat `Record` for the given state. * * Merges base layer with the state-specific override (if any), flattens * pseudo selectors and box-shadow into the result map. * * @example * ```ts * const style = Style.make({ * base: { properties: { color: 'black' } }, * states: { dark: { properties: { color: 'white' } } }, * }); * const props = Style.tap(style, 'dark'); * // props === { color: 'white' } * const baseProps = Style.tap(style); * // baseProps === { color: 'black' } * ``` */ declare function _tap(style: StyleDef, state?: string): Record; /** * Style namespace -- adaptive style primitive for constraint-based rendering. * * Bind base styles to optional boundary states with per-state overrides and * CSS transitions. Resolve to flat property maps for any given state. * * @example * ```ts * import { Boundary, Style } from '@czap/core'; * * const bp = Boundary.make({ input: 'viewport.width', at: [[0, 'sm'], [768, 'lg']] }); * const style = Style.make({ * boundary: bp, * base: { properties: { 'font-size': '14px' } }, * states: { lg: { properties: { 'font-size': '18px' } } }, * transition: { duration: 200 }, * }); * const resolved = Style.tap(style, 'lg'); * // resolved === { 'font-size': '18px' } * ``` */ export declare const Style: StyleFactory & { tap: typeof _tap; mergeLayers: typeof _mergeLayers; }; export declare namespace Style { /** Structural shape of a style definition parameterized by its governing {@link Boundary}. */ type Shape = StyleDef; } export {}; //# sourceMappingURL=style.d.ts.map