refract v0.1 · beta
Subsystems / Typography

Typography

A modular type scale, families and weights become tokens; heading and text recipes compose them into ready-to-use classes.

raw slice the input
live render real .dt- classes
refracted: the scale is computed from base × ratio. The recipe rows carry real emitted classes (dt-typography-heading-h1, dt-typography-body-base) from theme.css.

Overview

The typography subsystem owns the text tokens — font family, weight, line-height, letter-spacing, and the extra text properties (style / transform / decoration / align) — plus the fontSize modular scale, which (like colours) is synthesized: author a base and a ratio and refract computes xs…4xl. Recipes (heading, body, button, …) compose these into named text styles.

Properties

Each is a normal property (base + named variants). Note the emitted variable uses the CSS-property name directly — there's no typography segment — while the token path is typography.<prop>.

PropertyValue typeEmitted variableDescription
fontFamilystring--dt-typography-fontfamily-<v>Font stacks (e.g. base, display, mono).
fontWeightnumber--dt-typography-fontweight-<v>Weights (400, 600, …).
lineHeightnumber--dt-typography-lineheight-<v>Unitless line-heights.
letterSpacingstring--dt-typography-letterspacing-<v>Tracking (em / px strings).
fontStylestring--dt-typography-fontstyle-<v>normal / italic.
textTransformstring--dt-typography-texttransform-<v>none / uppercase / …
textDecorationstring--dt-typography-textdecoration-<v>none / underline / …
textAlignstring--dt-typography-textalign-<v>left / center / …
fontSizenumber--dt-typography-fontsize-<v>The modular scale — see below.

The modular scale — fontSize

Author a base and a ratio; refract generates the steps as base × ratiostep, rounded to precision. Steps: xs (−2) · sm (−1) · md/base (0) · lg (+1) · xl (+2) · 2xl (+3) · 3xl (+4) · 4xl (+5). An author-declared step seeds/overrides the computed value.

FieldTypeRequiredDefaultDescription
basenumberRequiredThe base size — the md / base step.
ratioRatioKeyOptionalThe scale ratio (see below). Without it, no steps are synthesized.
precisionnumberOptional4Decimal rounding for computed sizes.
unit"px" | "rem"OptionalpxAuthoring hint for the scale ratio math; the emitted unit is resolved by the units config (px by default).
baseFontSizenumberOptional16Divisor for rem conversion.
algorithm(base, key, step, prev) => numberOptionalCustom step function — overrides the ratio math.
variantsRecord<key, number>OptionalAuthor-declared step seeds (e.g. "4xl": 56 overrides the computed value).

Ratios: minor-second 1.067 · major-second 1.125 · minor-third 1.2 · major-third 1.25 · perfect-fourth 1.333 · augmented-fourth 1.414 · perfect-fifth 1.5 · golden 1.618.

typography.ts
typography: {
  fontFamily:    { base: "system-ui, sans-serif",
                   variants: { display: "'Iowan Old Style', serif", mono: "'JetBrains Mono', monospace" } },
  fontWeight:    { base: 400, variants: { medium: 500, semibold: 600, bold: 700 } },
  lineHeight:    { base: 1.55, variants: { tight: 1.15, snug: 1.35 } },
  letterSpacing: { base: "0", variants: { tight: "-0.02em", wide: "0.06em" } },
  textTransform: { base: "none", variants: { upper: "uppercase" } },
  // the modular scale
  fontSize:      { base: 16, ratio: "major-third", precision: 2, variants: { "4xl": 56 } },
}

Recipes — heading / body / button / …

A typography recipe composes token variants into one class. Each value names a variant (fontSize: "3xl", fontWeight: "bold", fontFamily: "display"; "base" for the base value).

Recipe propCSS declarationReferences
fontFamilyfont-familyfontFamily
fontSizefont-sizefontSize
fontWeightfont-weightfontWeight
lineHeightline-heightlineHeight
letterSpacingletter-spacingletterSpacing
fontStylefont-stylefontStyle
textTransformtext-transformtextTransform
textDecorationtext-decorationtextDecoration
textAligntext-aligntextAlign

Recipes also take states (e.g. a link hover underline) and a responsive list (e.g. a heading that bumps a size step on wide viewports) — see the Concepts pages.

typography.recipes.ts
typography.recipes: {
  heading: {
    h1: { fontFamily: "display", fontSize: "3xl", fontWeight: "bold",
          lineHeight: "tight", letterSpacing: "tight",
          responsive: [{ breakpoint: "lg", query: "min", fontSize: "4xl" }] },
  },
  link: { default: { textDecoration: "base", states: [{ state: "hover", textDecoration: "underline" }] } },
}
dist/theme.css · emitted
:root {
  --dt-typography-fontfamily-display: 'Iowan Old Style', serif;
  --dt-typography-fontsize: 16px;
  --dt-typography-fontsize-3xl: 39.06px;  /* 16 × 1.25⁴ */
  --dt-typography-fontsize-4xl: 56px;     /* authored seed */
  --dt-typography-fontweight-bold: 700;
}
.dt-typography-heading-h1 {
  font-family: var(--dt-typography-fontfamily-display);
  font-size: var(--dt-typography-fontsize-3xl);
  font-weight: var(--dt-typography-fontweight-bold);
  line-height: var(--dt-typography-lineheight-tight);
  letter-spacing: var(--dt-typography-letterspacing-tight);
}
@media (min-width: 1024px) {
  .dt-typography-heading-h1 { font-size: var(--dt-typography-fontsize-4xl); }
}
Technical documentation for @theme-registry/refract · all output is compiled client-side by the real library (CSS adapter). The chrome is theme-aware; the render panes carry each preset's own world. · MIT licensed.