/** * Shared CSS utility regexes and `inferSyntax` helper used by both the CSS * compiler and the Token CSS compiler. * * `NUMBER_RE` uses non-overlapping alternation to avoid catastrophic * backtracking (ReDoS) on crafted inputs like `"1.1.1.1.1.1.1.1x"`. * * The regex structure is `^-?(?:\d+(?:\.\d*)?|\.\d+)(units)?$`, where the * two numeric branches are mutually exclusive: `\d+(?:\.\d*)?` for integer * or decimal like `1`, `1.`, `1.5`, and `\.\d+` for leading-dot decimal * like `.5`. This eliminates the overlapping `(\d+\.?\d*|\.\d+)` pattern * that could cause the engine to re-attempt partial matches at each * character boundary. * * @module */ /** Matches any CSS color literal (hex, rgb/rgba, hsl/hsla, oklch, oklab, color(), lab, lch, hwb). */ export const COLOR_RE = /^(#[0-9a-fA-F]{3,8}|rgba?\(|hsla?\(|oklch\(|oklab\(|color\(|lab\(|lch\(|hwb\()/; /** * Matches any CSS dimension with a known unit suffix. * * Capture group 1 is the unit (or undefined for a unitless number); * {@link inferSyntax} keys off the unit to pick a registered-property syntax. */ export const NUMBER_RE = /^-?(?:\d+(?:\.\d*)?|\.\d+)(px|rem|em|%|vw|vh|dvh|svh|lvh|vmin|vmax|fr|deg|rad|turn|s|ms|Hz|kHz)?$/; /** CSS registered-property syntax keyword produced by {@link inferSyntax}. */ export type CSSSyntax = '' | '' | '' | '' | '