Something went wrong. Try again.
Generate web slides from Comark
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051/** * Raw token values for consumers that need a literal color string * (canvas strokeStyle, SVG color attributes, build-time HTML * templating) where CSS custom properties cannot be used directly. * * Sourced from `tokens/colors.json` so a palette change is single- * source. The CSS variable surface in `@morkdeck/theme/css` is the * preferred path for styling; reach for `colorHex` only when the * consumer truly needs a literal hex. */
import colorsToken from "./tokens/colors.json" with { type: "json" };
export type ColorTokenName = | "base" | "surface" | "overlay" | "muted" | "subtle" | "text" | "danger" | "warning" | "success" | "match" | "bright" | "link" | "highlight.low" | "highlight.med" | "highlight.high";
/** * Resolve a color token name to its `#rrggbb` hex string. Throws if * the name does not exist in the token tree, so a typo in a call site * surfaces at runtime instead of silently returning undefined. */export function colorHex(name: ColorTokenName): string { // deno-lint-ignore no-explicit-any let node: any = colorsToken; for (const part of name.split(".")) { node = node?.[part]; if (node === undefined) { throw new Error(`Unknown color token: ${name}`); } } const hex = node.$value?.hex; if (typeof hex !== "string") { throw new Error(`Color token has no hex value: ${name}`); } return hex;}