HeadlinesBriefing favicon HeadlinesBriefing.com

Tasty: A Compiler That Makes CSS State Logic Predictable

Hacker News •
×

When a button is both hovered and disabled, browsers fall back to source order, turning a blue hover into gray or vice versa. This clash illustrates a deeper problem: CSS state management relies on cascade overlap, which quickly becomes fragile as more pseudo‑classes, media queries, and modifiers stack.

Enter Tasty, a compiler from @tenphi/tasty that lets developers declare a state map instead of tangled selectors. A button defined as: tasty({as:'button',styles:{fill:{'': '#primary',':hover':'#primary-hover',':active':'#primary-pressed','[disabled]':'#surface'}}}); maps states to priorities, eliminating manual cascade logic. By ordering keys, the library guarantees that the most specific state wins, so developers no longer need to juggle specificity hacks or source‑order tricks daily.

The compiler emits deterministic selectors that never overlap. For example, it outputs rules like .t0[disabled]{background:var(--surface-color);} and .t0:active:not([disabled]){background:var(--primary-pressed-color);}. Because each selector excludes conflicting states, the browser never resolves via source order, eliminating accidental regressions when new states are added. This clarity scales to complex components, ensuring that style changes remain predictable across themes, breakpoints, and overrides.

Tasty powers Cube UI Kit, a 100‑plus component system that feeds Cube Cloud, an enterprise product. Developers report fewer source‑order bugs and faster feature iteration after adopting the compiler. For teams scaling design systems, the ability to declare state priority once and trust automatic selector generation delivers measurable stability to developers and maintain consistent UI.