Theme authoring›Theme Config API

Theme Config API

Theme configuration is declarative. Instead of writing transform logic, you describe what each rune should produce — which BEM block it maps to, what modifiers it reads, how it projects metadata (metaFields/blocks) and assembles its structure (layout) — and the identity transform engine handles the rest.

ThemeConfig

The top-level configuration object passed to createTransform().

interface ThemeConfig {
  prefix: string;       // BEM prefix, e.g., 'rf' → .rf-hint
  tokenPrefix: string;  // CSS variable prefix, e.g., '--rf' → --rf-color-text
  icons: Record<string, Record<string, string>>;  // SVG icons by group and variant
  runes: Record<string, RuneConfig>;               // Per-rune configuration
}
FieldDescription
prefixPrepended to all BEM class names. 'rf' produces .rf-hint, .rf-hint--note, .rf-hint__icon
tokenPrefixConvention for CSS custom property naming. Used by documentation and tooling, not the engine itself
iconsSVG strings organized by group and variant. Structural groups (e.g., hint) are used by StructureEntry.icon config to inject icons into rune headers. The global group is used by the {% icon %} content rune to resolve author-chosen icons by name
runesMaps each rune's typeName (PascalCase, e.g. Hint) to its transform configuration. The engine matches the kebab-cased key against the data-rune attribute on the tag
tints / backgrounds / framesNamed preset registries — color tints, bg layers, and frame media-surface chrome. All share the same extends resolution. See Surface chrome for frames.

RuneConfig

Each entry in runes describes how a single rune type is transformed. Every field is optional; almost every rune sets block.

warning

Some config paths are rune identity, not theme configuration. They say what a rune is — what its content means — rather than how it looks. A theme that could rewrite them could change what the same markdown means, so it may not: an override of one is ignored with a build warning naming the rune and the path, and a variant delta carrying one is a config-load error. Everything else here stays fully theme-owned.

Guarded paths

The guard is path-granular: a whole key where the whole key is identity, and a single sub-field where only that sub-field is.

PathWhy it is identity
block, modifiers, sectionsUniversal-attribute applicability derives from them — reading needs a body role, prominence a header-ish one, cover a declared media-position modifier
mediaSlots, frameTargetJoin tables that decide which zone is media and whether frame= applies at all
universalAttributes, providesDecide which attributes an author may write on the rune
schemaThe schema.org table — a claim about the content, not the skin
sequenceWhether an ordinal is information (below)
metaFields.*.metaTypeWhat kind of field a meta field is — label, sentimentMap and transform on the same entry stay overridable

sequence is the case that makes the rule concrete. On a playlist the number is the track number — an identifier a listener says out loud. A theme that restyled a playlist from numbered to connected would not change how it looks; it would delete the track numbers. So numbered vs connected encodes a fact about the content, and the rune owns it. sequenceDirection — the responsive collapse of the same list — is presentation, and stays the theme's.

metaFields.*.metaType is the same split one level down: a theme may relabel a status field, recolor it with its own sentimentMap, or give it a value transform, but retyping it from status to category changes what the author declared their data to mean. A guarded sub-field is dropped while the rest of its entry merges, and an override entry that leaves metaType out keeps the declared one.

A layout wrapper's attrs may not write an attribute an identity field emits — data-section (sections), data-media (mediaSlots), typeof / property (schema), data-sequence (sequence), data-meta-type (metaFields.*.metaType), or data-{name} for a declared modifier. The refused attribute is dropped and reported; the wrapper's other attributes stand. Presentation attributes such as data-zone-layout or data-color-scheme are unaffected. This is checked once, when the config is assembled, and refrakt plugin validate reports it as an error.

Composed runes

A composed rune's config cannot be overridden at all. It is generated from its definition, and a theme cannot know which definition it faces, so an override of its blocks or metaFields would be a guess that silently resolves to nothing. An entry under runes: keyed to a composed rune is reported at build time, naming the theme, the rune and the path, and dropped whole. Native runes are unaffected: only their identity paths above are guarded.

A theme has two routes instead. It styles a composed rune through the vocabulary it is built from, targeting [data-rune="…"] in CSS where it wants to special-case one, or it replaces the rune's template.

block

The BEM block name, without the prefix.

Grid: { block: 'grid' }
// → class="rf-grid"

The engine produces the block class (.rf-grid) and sets data-rune="grid" on the root element.

A config may leave block out. That is how a composed rune is configured: it has no BEM block and ships no CSS, but its modifiers, universal attributes and metadata blocks still have to render. With no block, the engine runs every step it runs for any rune except emitting rf-* classes. Modifiers become data-* attributes, universal attributes apply, metadata renders (a composed rune has no layout, so its template places each block with {% metablock %}, and a theme's blocks override reaches it as it reaches a projected block) and the internal field bag is stripped, but neither the root nor its named children get a class. Such a rune is addressable only by [data-rune], its data-* modifiers and the primitives it contains, and refrakt contracts describes it that way, with no BEM selectors.

Rune identity — not theme-overridable.

modifiers

Reads values from meta tags or HTML attributes and produces BEM modifier classes plus data attributes.

Rune identity — not theme-overridable. Which modifiers a rune declares is what gates the cover and content-place axes, so a theme that could add one would grant an attribute the rune's own schema rejects.

modifiers: {
  hintType: { source: 'meta', default: 'note' },
  align: { source: 'meta', default: 'center' },
}
PropertyDescription
source'meta' reads the field value from the rune's data-rune-fields bag (a JSON object on the root). 'attribute' reads from the element's own attributes
defaultFallback value when the field is absent

For each modifier with a resolved value, the engine:

  1. Adds a BEM modifier class: .rf-hint--note
  2. Sets a data attribute: data-hint-type="note" (camelCase → kebab-case)
  3. Strips the data-rune-fields bag from the output (it is an internal, pre-engine data channel — never a theming hook; themes target the BEM classes and the data-* attributes above)

Example: The Hint rune with hintType: 'warning':

<!-- Before transform — field data rides the data-rune-fields bag (camelCase keys) -->
<div data-rune="hint" data-rune-fields='{"hintType":"warning"}'>
  <p>Be careful!</p>
</div>

<!-- After transform -->
<div class="rf-hint rf-hint--warning" data-rune="hint" data-hint-type="warning">
  <!-- bag consumed, structural elements injected -->
  <p>Be careful!</p>
</div>

contextModifiers

Adds a BEM modifier class when the rune is nested inside a specific parent rune. The key is the parent's typeName (matched against data-rune after kebab-casing); the value is the modifier suffix.

// Hint config
contextModifiers: { 'Hero': 'in-hero', 'Feature': 'in-feature' }

// When Hint is inside a Hero:
// class="rf-hint rf-hint--note rf-hint--in-hero"

This enables context-aware styling — a Hint inside a Hero can be more compact, a CTA inside Pricing can be left-aligned.

staticModifiers

BEM modifier classes that are always applied, regardless of meta tag values. Useful for rune variants that share a block but have fixed differences.

// FeaturedTier shares the 'tier' block but always gets --featured
FeaturedTier: { block: 'tier', staticModifiers: ['featured'] }
// → class="rf-tier rf-tier--featured"

metaFields

A pure-data manifest of the rune's meta-bearing fields — what each field means (type, label, sentiment, optional rich rendering), with no placement. Blocks reference these fields by name. Use it instead of hand-built metadata in structure.

metaFields?: Record<string, MetaField>;

interface MetaField {
  metaType?: 'status' | 'category' | 'quantity' | 'temporal' | 'tag' | 'id' | 'code';
  label?: string;
  sentimentMap?: Record<string, 'positive' | 'negative' | 'caution' | 'neutral'>;
  condition?: string;
  renderWhenEmpty?: boolean;
  href?: string;
  rating?: { total?: string };
  icon?: { group: string };
  tag?: string;
  splitOn?: string;
  transform?: 'duration' | 'uppercase' | 'capitalize';
  i18nKey?: string;
}

metaType is rune identity — a theme override of it is dropped while the entry's other fields still merge (see Guarded paths). What each key does, and how a field renders, is in Blocks & layout.

blocks

Named metadata blocks projected from metaFields, each a flat list of fields rendered by one layout primitive. A block becomes an addressable element (.rf-{block}__{name}) placed via layout.

blocks?: Record<string, BlockDef>;

interface BlockDef {
  fields: (string | { field: string; align?: 'start' | 'end' })[];
  layout: 'bar' | 'definition-list' | 'lead';
  wrap?: boolean;
}

The primitives and the DOM each emits are in Blocks & layout.

layout

The recursive skeleton. The transform emits flat data-name slots; layout declares how they are grouped and ordered. Keyed by a container's data-name, or the reserved 'root' for the rune's top-level children.

layout: {
  root: ['media', 'content'],
  content: { tag: 'div', children: ['eyebrow', 'body', 'footer'] },
  preamble: { tag: 'header', children: ['eyebrow', 'headline', 'blurb'] },
}

Each value is a LayoutEntry:

  • a bare string[] orders an existing container's children;
  • { tag, children, attrs? } creates a wrapper element (<tag data-name=key>) and fills it from the flat transform slots. attrs may not set an attribute an identity field emits (data-section, typeof, property, …) — see Guarded paths.

Projected blocks and transform slots a list doesn't name are appended in transform order — rune content is never dropped. See Blocks & layout for name resolution and worked examples.

variants

Modifier-keyed config deltas: a rune's structure can vary by a modifier without branching in the transform. The outer key is a declared modifier (the axis), the inner key one of its values, and the payload a partial RuneConfig merged over base — in declaration order — before assembly.

variants: {
  'media-position': {
    cover: {
      layout: {
        root: ['cover-band', 'body'],
        'cover-band': { tag: 'div', children: ['media', 'preamble'] },
      },
    },
  },
}

Selection rides the modifier system — the modifier's own default picks the active value, so there is no separate condition language and no defaultVariants. A delta may override assembly/decoration fields (layout, structure, styles, contentWrapper, staticModifiers, autoLabel, editHints) but not identity paths (see Guarded paths); every axis must be a declared modifier. Both invariants are checked at config load. Requires the rune to be on the flat-slot + base-layout model. See the variants section in Blocks & layout.

structure

warning

structure is deprecated; use metaFields + blocks + layout above. No first-party rune declares it. The engine still applies it, for injecting icons or badges into a rune that projects no metadata. The StructureEntry API below documents its shape.

It injects new HTML elements into a rune's output — headers, icons, badges — keyed by name, each defining a StructureEntry:

structure: {
  header: {
    tag: 'div',
    before: true,
    children: [
      { tag: 'span', ref: 'icon', icon: { group: 'hint', variant: 'hintType' } },
      { tag: 'span', ref: 'title', metaText: 'hintType' },
    ],
  },
}

contentWrapper

Wraps all content children (non-structural) in a container element.

// Recipe config
contentWrapper: { tag: 'div', ref: 'content' }

// Output: recipe's structural header comes first, then content is wrapped
// <div class="rf-recipe">
//   <div class="rf-recipe__meta">...</div>       ← structure (before)
//   <div class="rf-recipe__content">              ← contentWrapper
//     <ul>ingredients...</ul>
//     <ol>steps...</ol>
//   </div>
// </div>

The ref value becomes the element's data-name, which the engine converts to a BEM element class (rf-recipe__content).

autoLabel

Maps child element tag names (or property attribute values) to data-name attributes. The engine then adds BEM element classes for these.

// AccordionItem config
autoLabel: { name: 'header' }

// A child with tag name "name" gets data-name="header"
// → class="rf-accordion-item__header"
// Details config
autoLabel: { summary: 'summary' }

// The <summary> child gets data-name="summary"
// → class="rf-details__summary"

styles

Maps modifier values to CSS custom properties or inline style declarations. Useful when CSS needs dynamic values that can't be expressed as BEM classes.

Simple form — sets a CSS custom property:

styles: { columns: '--sb-columns' }
// With columns=3: style="--sb-columns: 3"

Template form — interpolates the value into a CSS property:

styles: {
  columns: {
    prop: 'grid-template-columns',
    template: 'repeat({}, 1fr)'
  }
}
// With columns=3: style="grid-template-columns: repeat(3, 1fr)"

Transform form — reshapes the value with a named transform first:

styles: {
  ratio: { prop: '--split-ratio', transform: 'fr' },     // "2 1" → 2fr 1fr
  valign: { prop: '--split-valign', transform: 'align' }, // top → start
  gap: { prop: '--grid-gap', transform: 'gap' },          // tight → var(--rf-spacing-sm)
}

The transform is a name, not a function. It is the same vocabulary as a meta field's or structure entry's transform:

NameDoes
durationISO 8601 (PT30M) → 30m
uppercase / capitalizeCase transforms
alignAlignment keyword (top, center, bottom, stretch, baseline) → CSS align-* value
frSpace-separated ratio numbers → fr tracks
gapGap preset (tight, default, loose) → spacing token; raw CSS passes through

Keeping it a name is what keeps a RuneConfig plain data: postTransform is the only function a rune config may carry.

Multiple style entries produce semicolon-separated values. Existing inline styles on the tag are preserved.

defaultDensity

Controls how much detail a rune shows by default. The engine emits data-density on the root element.

Accordion: { block: 'accordion', defaultDensity: 'full' }
Details: { block: 'details', defaultDensity: 'compact' }
Breadcrumb: { block: 'breadcrumb', defaultDensity: 'minimal' }
ValueBehavior
'full'All sections visible, generous spacing (default)
'compact'Descriptions truncated, secondary metadata hidden
'minimal'Title and primary metadata only

Resolution order: author attribute > rendering context > config default > 'full'. The engine automatically applies compact inside Grid/Bento/Gallery and minimal inside backlog/decision-log contexts.

See Dimensions for the full CSS patterns and density interactions.

sections

Maps structural ref names (data-name values) to standard section roles. The engine emits data-section on matching elements, enabling generic layout styling.

Budget: {
  block: 'budget',
  sections: { header: 'header', title: 'title', footer: 'footer' },
}

Available roles: 'header', 'preamble', 'title', 'description', 'body', 'footer', 'media'.

Rune identity — not theme-overridable. This is a join table rather than a posture: the keys are data-name values the rune's own transform emits and the values are a closed engine vocabulary, so a theme owns neither side. All it could do is rewire a pair — and reading, prominence and frame applicability hang off exactly those pairs. Styling the emitted data-section stays entirely the theme's business.

The map is declared in the rune's tag module and referenced here, so createContentModelSchema has the fact at construction. mediaSlots and frameTarget are declared there for the same reason. The engine reads config.sections.

// tags/card.ts
export const cardSections = { media: 'media', body: 'body' } as const;
export const card = createContentModelSchema({ sections: cardSections, /* … */ });

// config.ts
Card: { block: 'card', sections: cardSections, /* … */ }

refrakt validate fails a config in which a rune declares a body or heading slot (in layout, structure, autoLabel, blocks or contentWrapper) with no matching role — that omission silently drops reading, dropcap or prominence, which is exactly how the original mismatches went unnoticed. The check is direction-only: it flags a missing role and never a role that is present, so a body role on a non-prose region stays untouched.

sectionRoleExceptions

Records a deliberate decision not to map a declared slot, keyed by slot name and valued by the reason. It silences the check for that slot and keeps the reasoning next to the decision.

AccordionItem: {
  block: 'accordion-item',
  sections: { body: 'body' },
  sectionRoleExceptions: {
    header: 'The `header` slot is the <summary> disclosure control, not a page-section header.',
  },
}

Use it for a genuine judgement, never to quiet a real omission. Most exceptions so far share one shape: a child rune takes the title role only when its parent does not already hold one — a second title inside the same subtree flattens the hierarchy prominence exists to scale.

See Dimensions for role descriptions and CSS.

mediaSlots

Maps ref names to media treatment types. The engine emits data-media on matching elements.

Figure: { block: 'figure', mediaSlots: { media: 'cover' } }

Available types: 'portrait', 'cover', 'thumbnail', 'hero', 'icon'.

See Dimensions for treatment descriptions and CSS.

checklist

When true, the engine scans <li> text for checkbox markers ([x], [ ], [>], [-]), strips the marker, and emits data-checked on the element.

Work: { block: 'work', checklist: true }

See Dimensions for marker values and CSS.

sequence

Ordered list style. The engine emits data-sequence on <ol> elements within the rune.

Rune identity — not theme-overridable. Whether the ordinal is information is a fact about the content: switching a playlist to connected would delete its track numbers. sequenceDirection stays theme-owned.

Steps: { block: 'steps', sequence: 'connected' }
ValueVisual treatment
'numbered'Counter circles
'connected'Vertical line with dots
'plain'No visual indicators

When the style depends on one of the rune's modifiers, read it from the modifier instead of writing a postTransform. valueMap translates a modifier value into a style, and default applies when the value is unset or has no entry. When neither gives a style, no <ol> is annotated. Without valueMap, the modifier's value must itself be a style.

// A linear plot's beats are a timeline; other structures are plain lists.
Plot: {
  block: 'plot',
  modifiers: { structure: { source: 'meta', default: 'linear' } },
  sequence: { fromModifier: 'structure', valueMap: { linear: 'connected' } },
}
KeyMeaning
fromModifierThe modifier whose value selects the style
valueMapModifier value → style (optional)
defaultThe style for an unset or unmapped value (optional)

The modifier form is identity too. It is the rune's own config that maps a value to a style, so a theme cannot override it.

Use sequenceDirection to control orientation:

Timeline: {
  block: 'timeline',
  sequence: 'connected',
  sequenceDirection: { fromModifier: 'direction', default: 'vertical' },
}

See Dimensions for CSS patterns.

parent

Groups a rune under a parent rune in the block editor palette. Advisory only — a rune may declare a typical parent yet still be valid standalone. Does not affect rendering.

AccordionItem: { block: 'accordion-item', parent: 'Accordion' }

frameTarget

Which surface frame chrome decorates: 'media' (the [data-section="media"] zone) or 'self' (the rune root, for runes whose body is the media, like figure/showcase). Defaults to 'media' when the rune declares a media section; frame on a rune with no resolvable target emits a build warning. See Surface chrome.

Figure: { block: 'figure', frameTarget: 'self' }

requiresParent

A hard nesting requirement: the rune is only meaningful inside the named parent (PascalCase typeName). Unlike parent (an advisory editor grouping), this is validated — the engine warns when the rune appears without that parent as its nearest ancestor rune.

BreadcrumbItem: { block: 'breadcrumb-item', parent: 'Breadcrumb', requiresParent: 'Breadcrumb' }

defaultWidth

Sets the default page grid width for the rune. The engine emits data-width on the root element.

Pricing: { block: 'pricing', defaultWidth: 'full' }
ValueBehavior
'content'Standard content width (default)
'wide'Wider than content, narrower than full
'full'Edge-to-edge

childDensity

Imposes a density level on all nested runes. Useful for runes that display children in a compact context.

Grid: { block: 'grid', childDensity: 'compact' }
Backlog: { block: 'backlog', childDensity: 'minimal' }

editHints

Declares how named sections are edited in the block editor. Keys are data-name values; values are edit mode hints.

Hint: {
  block: 'hint',
  editHints: { icon: 'none', title: 'inline' },
}
HintBehavior
'inline'Inline text editing
'link'Link editing
'code'Code editing
'image'Image picker
'icon'Icon picker
'none'Not editable (generated content)

rootAttributes

Extra attributes set on the root element unconditionally.

Sandbox: { block: 'sandbox', rootAttributes: { 'data-interactive': 'true' } }

projection

Declarative tree reshaping by data-name, applied after assembly. It is the escape hatch for bending a tree a theme does not own (a third-party rune's output); a rune declaring its own structure should use layout instead.

Comparison: {
  block: 'comparison',
  projection: {
    hide: ['meta'],   // drop elements by data-name (the only retained op)
  },
}
  • hide — drop elements by data-name. Retained.
  • group ({ tag, members, slot? }) and relocate ({ into, position? }) — deprecated: a layout tag-entry is a group, and you place a slot wherever you name it in the layout tree. The contract generator emits a deprecation warning for both.

Advanced modifier options

Modifiers support additional fields beyond source and default:

PropertyDescription
noBemClassWhen true, skips BEM modifier class generation — only the data attribute is emitted
valueMapMaps modifier values before emitting (e.g., { 'GET': 'read', 'POST': 'write' })
mapTargetCustom data attribute name for the mapped value (instead of the default)
modifiers: {
  method: {
    source: 'meta',
    default: 'GET',
    valueMap: { GET: 'read', POST: 'write', PUT: 'write', DELETE: 'danger' },
    mapTarget: 'intent',
  },
}
// Emits: data-method="GET" data-intent="read"

postTransform

A programmatic escape hatch that runs after all declarative processing. Receives the fully transformed node and resolved modifier values.

postTransform(node, ctx) {
  return {
    ...node,
    attributes: {
      ...node.attributes,
      'data-custom': `cols-${ctx.modifiers.columns}`,
    },
  };
}

The ctx object contains:

PropertyTypeDescription
modifiersRecord<string, string>All resolved modifier values
parentTypestring | undefinedThe parent rune's data-rune value (kebab-case), if nested
fieldsRecord<string, unknown>The parsed data-rune-fields bag — for non-modifier field values (the engine strips the bag attribute before postTransform runs)
warning

Use declarative config first. postTransform is for edge cases that truly can't be expressed with modifiers, structure, or styles. It makes the config harder to analyze statically — the inspect and audit tools can't introspect programmatic transforms.

StructureEntry

Defines an element injected into a rune's output via the deprecated structure config. New runes project metadata with metaFields + blocks instead.

interface StructureEntry {
  tag: string;                // HTML tag name ('div', 'span', 'a', etc.)
  ref?: string;               // Sets data-name (overrides the structure key)
  before?: boolean;           // Insert before content children (default: after)
  children?: (string | StructureEntry)[];  // Nested entries or text

  // Content
  metaText?: string;          // Inject resolved modifier value as text
  icon?: { group: string; variant: string };  // Icon from config.icons

  // Conditional
  condition?: string;         // Only render if named modifier is truthy
  conditionAny?: string[];    // Only render if any named modifier is truthy

  // Text transforms
  transform?: NamedTransform;   // 'duration' | 'uppercase' | 'capitalize' | 'align' | 'fr' | 'gap' — see styles
  textPrefix?: string;        // Prepend to metaText value
  textSuffix?: string;        // Append to metaText value

  // Labels
  label?: string;             // Emits <span data-meta-label>Label</span> child
  labelHidden?: boolean;      // Label visually hidden but accessible (sr-only)

  // Metadata dimensions (see Dimensions page)
  metaType?: 'status' | 'category' | 'quantity' | 'temporal' | 'tag' | 'id';
  sentimentMap?: Record<string, 'positive' | 'negative' | 'caution' | 'neutral'>;

  // Repetition — generate copies of a template element
  repeat?: {
    count: string;            // Modifier name providing the total count
    max?: number;             // Cap to prevent runaway generation (default 10)
    filled?: string;          // Modifier name for how many are "filled"
    element: StructureEntry;  // Template for each generated element
    filledElement?: StructureEntry;  // Optional template for filled elements
  };

  // Attributes — literal strings, or references to a modifier / page data
  attrs?: Record<string, string | { fromModifier: string } | { fromPageData: string }>;
}

Structural injection example

The Api rune demonstrates most structure features:

Api: {
  block: 'api',
  contentWrapper: { tag: 'div', ref: 'body' },
  modifiers: {
    method: { source: 'meta', default: 'GET' },
    path: { source: 'meta' },
    auth: { source: 'meta' },
  },
  structure: {
    header: {
      tag: 'div', before: true,
      children: [
        { tag: 'span', ref: 'method', metaText: 'method' },
        { tag: 'code', ref: 'path', metaText: 'path' },
        { tag: 'span', ref: 'auth', metaText: 'auth', condition: 'auth' },
      ],
    },
  },
}

This produces:

<div class="rf-api rf-api--GET" data-method="GET" data-rune="api">
  <div data-name="header" class="rf-api__header">
    <span data-name="method" class="rf-api__method">GET</span>
    <code data-name="path" class="rf-api__path">/api/users</code>
    <!-- auth span only present if auth modifier has a value -->
  </div>
  <div data-name="body" class="rf-api__body">
    <!-- content children -->
  </div>
</div>

Conditional elements

Use condition to only inject an element when a modifier has a truthy value:

{ tag: 'span', ref: 'auth', metaText: 'auth', condition: 'auth' }
// Only renders if the 'auth' modifier is present

Use conditionAny to render when at least one of several modifiers is present:

{
  tag: 'div', ref: 'meta', before: true,
  conditionAny: ['prepTime', 'cookTime', 'servings', 'difficulty'],
  children: [...]
}
// Only renders if any of those modifiers has a value

Dynamic attributes

The attrs field sets attributes on the injected element. Values can be literal strings or references to modifier values:

{
  tag: 'a', ref: 'register', condition: 'url',
  attrs: { href: { fromModifier: 'url' } },
  children: ['Register'],
}
// → <a href="https://example.com" class="rf-event__register">Register</a>

Repeated elements

The repeat field generates multiple copies of a template element — useful for star ratings, progress dots, and similar patterns. count and filled are modifier names.

{
  tag: 'div', ref: 'rating',
  repeat: {
    count: 'maxRating',   // modifier holding the total
    filled: 'rating',     // modifier holding how many are filled
    element: { tag: 'span', ref: 'star' },
  },
}
// With maxRating=5, rating=3:
// Produces 5 <span> elements, first 3 with data-filled="true"

Each generated element gets data-filled="true" or data-filled="false" based on whether its index is less than the filled count.

Text transforms

Built-in transforms applied to metaText values:

TransformInputOutput
durationPT1H30M1h 30m
uppercasegetGET
capitalizewarningWarning
{ tag: 'span', ref: 'meta-item', metaText: 'prepTime',
  transform: 'duration', textPrefix: 'Prep: ' }
// With prepTime="PT45M": "Prep: 45m"

Labels

The label field emits a separate <span data-meta-label> child element before the value text. This enables independent styling — themes can make labels thin and muted, or hide them entirely.

{ tag: 'span', ref: 'meta-item', metaText: 'prepTime',
  label: 'Prep:', metaType: 'temporal' }

Set labelHidden: true to make the label visually hidden but accessible to screen readers (sr-only pattern). Use this for values that are self-explanatory, like ID badges.

Metadata dimensions

metaType and sentimentMap on a StructureEntry emit data-meta-type and data-meta-sentiment on the generated element, exactly as the same keys do on a MetaField. See Universal Theming Dimensions for the CSS a theme writes against them.

mergeThemeConfig

Combines the base config with theme-specific overrides.

import { baseConfig } from '@refrakt-md/runes';
import { mergeThemeConfig } from '@refrakt-md/transform';

const myConfig = mergeThemeConfig(baseConfig, {
  // Override the BEM prefix (optional)
  prefix: 'my',

  // Add icon SVGs (merged by group)
  icons: {
    hint: {
      note: '<svg>...</svg>',
      warning: '<svg>...</svg>',
    },
  },

  // Override specific rune configs (shallow merge per rune)
  runes: {
    Hint: {
      // This replaces only the 'defaultElevation' field of the Hint config
      // All other fields (block, modifiers, blocks, layout) are preserved
      defaultElevation: 'raised',
    },
  },
});

Merge behavior:

FieldStrategy
prefixOverride replaces base
tokenPrefixOverride replaces base
iconsShallow merge by group (override groups replace base groups)
runesPer-rune merge: most fields replace, but metaFields, blocks, layout, and variants merge by inner key; the guarded paths are identity and cannot be overridden at all
note

Per-rune merge is shallow for most fields — overriding structure or styles replaces the entire object, not individual entries. The block-and-layout fields are the exception: metaFields, blocks, layout, and variants merge by inner key, so a theme can re-point a single field, swap one block's primitive, reshape one container, or add one variant without restating the whole map. When overriding a wrapper-creating layout entry, restate its tag (the entry is replaced as a whole).

warning

The guarded paths are rune identity and are not overridable here. An override carrying one is dropped — the rune's own declaration stands — and a build warning names the rune and the path. Adding a modifier, or rewiring a section role, would change which universal attributes an author may write on that rune, and applicability is a fact about the rune rather than about the theme. A theme still styles the emitted data-section / modifier attributes however it likes; it just does not define them.

Real-world examples

Simple rune: Grid

Minimal config — just a block name. CSS handles everything.

Grid: { block: 'grid' }

Modifier rune: Hint

Reads a modifier, adds context-awareness, injects a header with icon and title.

Hint: {
  block: 'hint',
  modifiers: { hintType: { source: 'meta', default: 'note' } },
  contextModifiers: { 'Hero': 'in-hero', 'Feature': 'in-feature' },
  structure: {
    header: {
      tag: 'div', before: true,
      children: [
        { tag: 'span', ref: 'icon', icon: { group: 'hint', variant: 'hintType' } },
        { tag: 'span', ref: 'title', metaText: 'hintType' },
      ],
    },
  },
}

Complex rune: Recipe

The current block-and-layout model: a metaFields manifest, a projected blocks metadata def-list, and a layout skeleton that assembles flat slots into a media + content split. (This is the actual @refrakt-md/learning config, trimmed.)

Recipe: {
  block: 'recipe',
  defaultDensity: 'full',
  sequence: 'numbered',
  sections: { preamble: 'preamble', headline: 'title', blurb: 'description', media: 'media' },
  mediaSlots: { media: 'cover' },
  modifiers: {
    'media-position': { source: 'meta', default: 'top', noBemClass: true },
    prepTime: { source: 'meta', noBemClass: true },
    cookTime: { source: 'meta', noBemClass: true },
    servings: { source: 'meta', noBemClass: true },
    difficulty: { source: 'meta', default: 'medium' },
  },
  metaFields: {
    prepTime: { metaType: 'temporal', label: 'Prep', condition: 'prepTime', transform: 'duration' },
    cookTime: { metaType: 'temporal', label: 'Cook', condition: 'cookTime', transform: 'duration' },
    servings: { metaType: 'quantity', label: 'Serves', condition: 'servings' },
    difficulty: {
      metaType: 'category', label: 'Difficulty', condition: 'difficulty',
      sentimentMap: { easy: 'positive', medium: 'neutral', hard: 'caution' },
    },
  },
  blocks: {
    metadata: { fields: ['prepTime', 'cookTime', 'servings', 'difficulty'], layout: 'definition-list' },
  },
  layout: {
    root: ['media', 'content'],
    content: { tag: 'div', children: ['preamble', 'metadata', 'ingredients', 'steps', 'tips'] },
    preamble: { tag: 'header', children: ['eyebrow', 'headline', 'blurb'] },
  },
}

metaFields declares the facts once; the metadata block projects them as a labelled def-list; layout nests that block in the content column under the header, beside the media. The metaType/sentimentMap fields drive generic badge styling — no rune-specific CSS. See Blocks & layout and Dimensions for the full system.

Background:

Attribute applicability is rune identity, not theme configuration

ADR-028accepted

Attribute applicability is rune identity, not theme configuration

runesattributesschemaconfigthemearchitecture

Context

Every rune built with createContentModelSchema gets ~37 universal attributes merged into its Markdoc schema — tint, width, reading, dropcap, elevation, prominence, frame*, substrate*, scrim* and the rest (UNIVERSAL_ATTRIBUTE_NAMES in packages/runes/src/attribute-presets.ts). refrakt reference prints them under the heading "Universal attributes (available on every rune)".

That heading is false, and the falsity is not marginal. Several of those attributes are silently or noisily inert depending on the rune's entry in ThemeConfig.runes:

AttributeGated onDiagnostic when inert
prominencesections has a header-ish rolewarns
dropcapresolved reading register is prosewarns
frame*frameTarget, or sections has a media rolewarns
substrate-target="media"sections has a media rolewarns (unreachable today: no rune sets substrateTarget, and it defaults to self)
readingsections has a body rolesilent
content-placerune declares a content-place modifiersilent
scrim* (cover)rune declares a media-position modifiersilent

The measurement that surfaced this is on WORK-527: the structure contract now records 686 per-rune unavailability entries across the 132-rune catalog. 111 runes can never carry data-reading; 92 can never carry data-prominence. None of that was inspectable before.

Three facts make this a decision rather than a bug report:

  • sections lives in ThemeConfig.runes, and mergeRuneConfig shallow-merges it. A theme can write runes: { Card: { sections: {} } } and silently disable reading on every card in a site. Nothing prevents it. (Lumina does not; the capability is unused, not absent.)
  • The project has already classified sections as identity. packages/transform/src/validate.ts enforces IDENTITY_FIELDS = ['block', 'modifiers', 'sections', 'variants'] against SPEC-091 variant deltas, with the rule that a delta "restructures a rune, never redefines it". The same field is unguarded on the theme-override path. This is one position applied to one of two merge paths.
  • The schema layer cannot see any of it. Markdoc schemas are built from rune definitions and know nothing about RuneConfig. That is why refrakt reference prints the blanket claim, and why the language server's completeAttributeNames offers every universal attribute on every rune: from where they stand, applicability is invisible.

Decision

Attribute applicability is a property of the rune, never of the theme. It is derived from rune-structural facts (which sections a rune has, which modifiers it declares), and those facts are identity fields that a theme override may not redefine.

Concretely:

  1. The IDENTITY_FIELDS rule already enforced for variant deltas extends to theme overrides. block, modifiers and sections become non-overridable on every merge path into RuneConfig.
  2. Applicability becomes visible at schema-build time, so a rune's Markdoc schema offers only the universal attributes that can do something on it. Every downstream consumer — refrakt reference, the language server, Markdoc validation — then becomes correct without loading theme config at all.
  3. Whether a rune offers universal attributes is answered by a declared rule, not by which schema constructor it happened to use.

The two senses of "a theme not supporting an attribute"

These were conflated in the discussion that produced this ADR, and separating them is most of the decision:

  • Styling — the theme's CSS does nothing with data-elevation. This is entirely the theme's business and is already fully decoupled: a theme that ignores an axis simply ships no rule for it. Nothing needs building, and nothing here restricts it.
  • Emission — the engine does not put data-elevation on the element.

Emission stays theme-agnostic, and no mechanism will be added for a theme to suppress it. A theme opting out of an axis is a CSS non-decision, not a config switch.

Theme-agnostic is not the same as universal

reading remains inapplicable on a rune with no body text. That is a rune fact and a permanent one. The rule being adopted is "applicability varies by rune, never by theme" — not "every attribute applies everywhere".

Consequences

Content becomes portable in fact, not just in principle. Today the same markdown can mean different things under different themes, because a theme can change which attributes do anything. Markdown is the source of truth in this project; a theme that can redefine what an author is allowed to express breaks that premise. This closes it.

The tooling becomes correct for free. Once schemas encode applicability, refrakt reference, editor completion and Markdoc validation all stop over-promising without any of them learning to read theme config. That is the main practical payoff, and it is why the fix belongs at schema-build time rather than in each consumer.

Silently-ignored attributes become validation errors. {% card reading="prose" %} moves from a silent no-op to a Markdoc error. This is the intended outcome — an author who writes it today gets no feedback at all — but it is a breaking change for existing content and needs a migration path. SPEC-125 owns that.

A data audit becomes a prerequisite. Applicability is only worth freezing into schemas if the underlying data is right, and it is not. Six runes have a body slot but no body section role — Card, BentoCell, Character, Realm, Faction, Playlist — and six have a title/header slot with no header-ish role — AccordionItem, BentoCell, CharacterSection, RealmSection, FactionSection, ItineraryDay. Card is the clearest: its layout is content: { children: ['eyebrow', 'body', 'footer'] } and its content model is literally "body (optional, repeatable any block)", yet sections is { media: 'media' }. A card obviously has body text; the role mapping was simply never declared. Narrowing schemas before fixing this would freeze six wrong exclusions and reject content whose author is right and whose config is wrong. The remaining 105 runes with neither a body role nor a body slot are genuinely bodyless, so the audit is small.

Some theme flexibility is deliberately given up. A theme can no longer restructure a rune's semantic roles. It retains layout, structure, styles, contentWrapper, staticModifiers, autoLabel, editHints and projection — the same split SPEC-091 already draws for variants — so it can hide, reorder, re-wrap and re-decorate, just not redefine what a section is.

Alternatives considered

Leave applicability in theme config and teach the consumers to read it. refrakt reference and the language server would load refrakt.config.json, resolve the merged theme, and annotate or filter accordingly. Rejected on two counts. It does not fix portability — a theme could still change what content means — and it pushes config resolution into every consumer, including an editor completion path that must stay fast and that today needs no theme at all. The structure contract's unavailable map would make this possible; it does not make it right.

Keep schemas permissive; annotate rather than reject. Schemas keep offering every universal attribute, and tooling marks the inapplicable ones as inert. Avoids the breaking change and keeps {% card reading="prose" %} working (harmlessly). Rejected as the primary model because it preserves the silent no-op as the default experience: the author still gets nothing unless they happen to be in an editor that surfaces the annotation. It is, however, a reasonable transitional mode, and SPEC-125 may adopt it as the migration step before schemas narrow.

Move sections out of RuneConfig entirely, onto the rune definition. Conceptually the cleanest expression of "this is rune identity" — the field would live where the schema can already see it, and the guard would be unnecessary because there would be nothing to override. Not decided here: it is a migration across ~50 rune configs with real churn, and the applicability guarantee does not depend on it. SPEC-125 evaluated placement as an implementation question and adopted the move — the deciding factor being the module graph, which runs config → tags uniformly and so forbids the reverse. Note that the guard above is still required either way: config would reference the rune's declaration, but the field remains on RuneConfig, so an unguarded theme override could still shadow it and diverge from the schema.

Placement was decided on a join table vs posture test rather than field by field — sections and mediaSlots map schema-emitted data-names to closed engine vocabularies and are owned by neither the theme nor either endpoint alone, while guestFit and substrateTarget are genuine theme postures that gate nothing. frameTarget is the one field that resists the test and is called out there.

References

  • SPEC-125 — the spec this decision governs
  • SPEC-091 — engine config variants; the source of the identity-field rule
  • SPEC-124 — facet registry; made the universal axes inspectable
  • WORK-527 — the measurement that surfaced this
  • SPEC-108 — reading register; the silent-drop case
  • SPEC-107 — elevation and prominence
  • SPEC-028 — rune output standards