refract v0.1 · beta
Subsystems / Globals

Globals

The base/element layer every subsystem above sits on — a normalization preset plus themed element rules. The one subsystem that mints no classes, styling bare elements only.

raw slice the input
live render isolated · bare HTML
refracted · the odd one out: globals mints no classes — a :where(…) preset layer (zero specificity) plus themed bare-element rules (a, a.subtle, headings). Themed values are token refs; headings bind to the type scale. The preview is sandboxed in a shadow root so those global element rules don't touch this page's own chrome.

Overview

The globals subsystem (formerly reset) is the base/element layer — the only subsystem that mints no classes. It has two tiers: a preset (a static normalization base plus a default h1h6 → type-scale map, rendered as zero-specificity :where(…) and ordered ahead of everything), and your themed elements (bare-selector rules at a higher tier that read token refs — now with states, responsive overrides and delta-only variants).

Authoring

The one form is an object — globals: { preset, elements }, both optional (no bare-string shorthand). The preset must be explicit for the static + default-heading layers to emit; a bare { elements } emits only your element rules, so an override() child inherits the parent's preset instead of reverting.

FieldTypeDescription
preset"preflight" | "normalize" | "reset" | falseThe static normalization + default-heading layers (see below). false disables them (elements only).
elementsRecord<selector, GlobalsElement>Themed bare-selector rules. Each leaf is literal-first — a bare string is a raw literal, and ref("colors.brand") / { ref: "…" } is a token reference. An element may carry states, responsive, and delta-only variants. No cross-subsystem composition refs, no modes (dark rides the referenced token's own modes). A ref() at an unknown token throws at build.

Presets

PresetBehaviour
preflightOpinionated, token-first — strips UA styling (box-sizing, zero margins, unstyled headings/lists/anchors) so the design tokens are the sole source. Includes the default-heading map.
normalizeLight — fixes a few cross-browser bugs but preserves UA defaults (no margin zeroing / heading strip, no default-heading map).
resetAggressive classic — zeroes margin/padding/border on everything and unstyles headings & lists. Includes the default-heading map. (A preset value, not the old subsystem name.)
falseDisables the static + default-heading layers; only your elements emit.

Default headings → the type scale

Because preflight / reset strip heading sizes to inherit, the preset re-binds h1h6 to typography's fontSize scale. It's opportunistic — a heading whose scale step wasn't generated (a ratio-less fontSize) is dropped.

ElementBinds font-size to
h1typography.fontSize.4xl
h2typography.fontSize.3xl
h3typography.fontSize.2xl
h4typography.fontSize.xl
h5typography.fontSize.lg
h6typography.fontSize.md

Output — two tiers

The preset lowers to kind: "reset" rule-sets rendered as :where(sel){…}zero specificity, so any class trivially overrides them, and ordered ahead of every recipe and variable. Your themed elements lower to kind: "globals" rule-sets rendered as bare selectors at a higher tier: a, a :hover state as a:hover, a responsive override in an @media, and a variant self-scoped as a.subtle. No classes are minted either way.

globals.ts
globals: {
  preset: "preflight",
  elements: {
    a: {
      color: ref("colors.brand"),                    // ref() = token reference
      textDecoration: "underline",               // bare string = literal
      states: [{ state: "hover", color: "colors.brand.dark" }],
      responsive: [{ breakpoint: "md", query: "min", fontSize: "typography.fontSize.lg" }],
      variants: { subtle: { color: "colors.scale.500" } },  // → a.subtle (delta-only)
    },
    h1:         { color: "colors.ink" },
    blockquote: { color: "colors.accent", borderColor: "colors.accent" },
  },
}
dist/theme.css · emitted
/* preset — static normalize (:where = zero specificity) */
:where(*,::before,::after) { box-sizing: border-box; border-width: 0; border-style: solid; }
:where(h1,h2,h3,h4,h5,h6) { font-size: inherit; font-weight: inherit; margin: 0; }
:where(a) { color: inherit; text-decoration: inherit; }

/* preset — default headings → the type scale */
:where(h1) { font-size: var(--dt-typography-fontsize-4xl); }   /* … through h6 */

/* your themed elements — BARE selectors, higher tier */
a          { color: var(--dt-colors-brand); text-decoration: underline; }
a:hover    { color: var(--dt-colors-brand-dark); }
a.subtle   { color: var(--dt-colors-scale-500); }
@media (min-width: 768px) { a { font-size: var(--dt-typography-fontsize-lg); } }
h1         { color: var(--dt-colors-ink); }
blockquote { color: var(--dt-colors-accent); border-color: var(--dt-colors-accent); }
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.