Helpers, constants, metrics
Token factories, DTCG type guards, schema constants, font metrics and typography metadata.
These are the building blocks the engine uses internally, exported for tools built on top of it: bridge libraries, MCP servers, audits. Everything below comes from both @flexpixels/cortex and @flexpixels/cortex/browser.
Token factories
Used by every engine module to keep DTCG structure consistent. Build your own engine extensions on top of these instead of hand-rolling $value/$type objects.
import {
dimToken,
dimPx,
aliasToken,
colorToken,
cssExprToken,
shadowToken,
numberToken,
durationToken,
cubicBezierToken,
fontFamilyToken,
compositeTypographyToken,
} from "@flexpixels/cortex";| Helper | $type | Notes |
|---|---|---|
dimToken(value, unit?) | dimension | unit defaults to "rem"; px values are converted to rem (value / 16). |
dimPx(value) | dimension | Shorthand for dimToken(value, "px"). |
aliasToken(path, type) | <passed type> | Emits "{path}" as the alias value; the CSS serializer writes it as a var(--fp-…) reference. |
colorToken(colorSpace, components, alpha?, hex?) | color | Build a DTCG color literal (sRGB, OKLCH, P3, …). |
cssExprToken(type, css) | <passed type> | Escape hatch for raw CSS strings (e.g. oklch(from …)); stored as $value and in $extensions["com.flexpixels"].css. |
shadowToken(shadowOrShadows) | shadow | One or many DTCGShadowObjects. |
numberToken(value) | number | Plain numeric token (multipliers, opacity, axis values). |
durationToken(ms) | duration | Emits "<ms>ms" (the DTCG export writes it as { value, unit: "ms" }). |
cubicBezierToken(x1, y1, x2, y2) | cubicBezier | Four-element control-point array. |
fontFamilyToken(family) | fontFamily | CSS-ready font-family stack. |
compositeTypographyToken({ fontFamily, fontSize, lineHeight, fontWeight, letterSpacing }) | typography | DTCG composite (DTCG export only — no CSS shorthand maps cleanly). |
DTCG type guards + types
import {
isDimension,
isColor,
isShadowObject,
isShadowArray,
type DTCGValue,
type DTCGDimension,
type DTCGColor,
type DTCGShadowObject,
type W3CToken,
type TokenTree,
} from "@flexpixels/cortex";The guards narrow DTCGValue so consumers can walk the token tree without hand-typing. W3CToken is the leaf shape ({ $value, $type, $description?, $extensions? }); TokenTree is the recursive group shape ({ [key]: W3CToken | TokenTree }).
Schema constants
The constants below are plain data, frozen at every depth (copy one before changing it: a write throws in strict mode); all but TYPOGRAPHY_SCENARIOS, ELEVATION_SCENARIOS and DEFAULT_BREAKPOINTS are typed as const. The engine, the MCP server and this site read them, so code built on these lists follows cortex when it changes.
| Export | Description |
|---|---|
HUE_ANCHORS | Auto-generated semantic hues: { success: 145, danger: 25, warning: 85, info: 250 }. |
CHROMA_LIGHTNESS_RAMP_LIGHT | 12 OKLCH L values for the light-mode ramp (0.985 … 0.22). |
CHROMA_LIGHTNESS_RAMP_DARK | 12 OKLCH L values for the dark-mode ramp (0.15 … 0.92). |
CHROMA_CURVE | 12 Gaussian multipliers applied to seed chroma (peak at step 9). |
ALPHA_RAMP | 12 opacities for the static white / black roles. |
ALPHA_STOPS | 5 opacities for dynamic role tints (a1..a5 = [5%, 10%, 20%, 30%, 45%]). |
STEP_USAGE | Per-step usage guide ({ 1: "App Background (Page canvas)", 2: "Subtle Background (Sidebars, Cards)", … }). |
TYPOGRAPHY_SCENARIOS | Bundles applied when typography.scenario is set (marketing, app, editorial, dashboard). |
ELEVATION_SCENARIOS | Bundles applied when elevation.scenario is set (same intent keys as typography). |
COLOR_ROLES | ["primary","secondary","neutral","success","danger","warning","info"] as const. |
DEFAULT_BREAKPOINTS | { xs:320, sm:640, md:768, lg:1024, xl:1280, "2xl":1920 }. |
GRADIENT_PRESETS | ["none","primary-secondary","primary-neutral","secondary-neutral"] as const. |
Font metrics + shadow visibility
import {
INTER_METRICS,
GEIST_MONO_METRICS,
computeTrim,
computeShadowVisibility,
SURFACE_BACKGROUND_LIGHTNESS,
FLAT_SHADOW_LIGHTNESS,
type FontMetrics,
} from "@flexpixels/cortex";INTER_METRICS,GEIST_MONO_METRICS— bundledFontMetricsfor the default Inter (display + body) and Geist Mono (mono) family slots.INTER_METRICSis sourced from@capsizecss/metrics;GEIST_MONO_METRICSis extracted from the shippedGeistMono-Variablewoff2 via@capsizecss/unpack.computeTrim(metrics, lineHeightEm)— returns{ trimTop, trimBottom }in em (always ≥ 0). Consumers negate them in CSS:margin-top: calc(-1em * 0.522).computeShadowVisibility(shadowL, bgL, alpha)— returns{ contrast: 0..1, perceivedDepth: 0..10 }for a shadow of lightnessshadowLand opacityalphaon a background of lightnessbgL. The elevation engine uses it for the opt-in--fp-elevation-{n}-perceived-depth,-contrast-on-app-lightand-contrast-on-app-darktokens (elevation.perceptual, in the flat, liquid-glass orautostyle).SURFACE_BACKGROUND_LIGHTNESS—{ appLight: 0.985, appDark: 0.15, subtleLight: 0.96, subtleDark: 0.19 }. The canonical OKLCH L for--fp-neutral-1/--fp-neutral-2in each mode.FLAT_SHADOW_LIGHTNESS—0.1. The L of the flat-style shadow tint.
const trim = computeTrim(INTER_METRICS, 1.5);
// { trimTop: 0.5225, trimBottom: 0.25 }
const vis = computeShadowVisibility(
FLAT_SHADOW_LIGHTNESS,
SURFACE_BACKGROUND_LIGHTNESS.appDark,
0.12,
);
// { contrast: 0.006, perceivedDepth: 0.3 } — a 12% shadow all but disappears on the dark app backgroundTypography metadata accessors
import { getResolvedTypeStyle, listBuiltInTextRoles, type TypeStyleDef } from "@flexpixels/cortex";listBuiltInTextRoles()— canonical role list (caption,label,body,body-lg,title,headline,display,button,input,helper,code,link,quote,data).getResolvedTypeStyle(typography, role)— returns yourtypography.typeStyles[role]when you define it (it replaces the built-in definition whole), otherwise the built-in definition;undefinedfor an unknown role. Built-in definitions carryintent,whenToUse,whenNotToUseandexamples, and some carryminViewportWidth: the fields the MCP resourceflexpixels://typography/roles/{role}serves.
computeLineHeights
import { computeLineHeights, type LineHeightFormula } from "@flexpixels/cortex";
computeLineHeights([12, 14, 16, 18], "ratio-1.5");
// [18, 22, 24, 28]
computeLineHeights([13, 15], "compact", /* roundTo */ 1);
// [17, 20]The same helper the typography engine uses to fill in missing lineHeights entries. roundTo defaults to 2 (the 2px grid); pass 1 to disable snapping when strictGrid: false.