Cette page n’est pas encore traduite. Elle est affichée en anglais.

Langage

Tokens and contexts

Typed design values with DTCG 2025.10 semantics, a resolver for themes and modes, and context axes that components read.

Tokens and groups

A group is a DTCG group; a token is a DTCG token. A group’s type is inherited by its tokens. Values use typed constructors: there is no implicit conversion between numbers, lengths, colors and strings.

token_source "foundation" {
  group "unit" {
    type        = "dimension"
    description = "Layout grid. Component dimensions are multiples of the base unit."

    token "base" {
      value = dp(16)
    }
  }

  group "type" {
    token "label" {
      type  = "typography"
      value = {
        font_family    = ["system-ui", "sans-serif"]
        font_size      = dp(16)
        font_weight    = 400
        letter_spacing = dp(0)
        line_height    = 1.5
      }
    }
  }
}
Type Literal
dimension dp(16) (logical), px(1) (physical), rem(1)
color hex("#2459d6"), color("oklch", [0.6, 0.15, 250]) — the 14 DTCG color spaces
duration ms(150), s(0.3)
typography, border, shadow, transition, gradient records with snake_case members (font_size, offset_x…)

A value that is exactly token.a.b is a DTCG alias. Names that are not identifiers use index syntax: token.space["100"].

Calculated values

Expressions are dimension-checked: length × number is a length, length × length is an error (DSF-T002).

min_width = token.unit.base * 9    # 144 logical units when the base unit is 16
padding   = insets(token.unit.base / 2, token.unit.base)

Resolver: themes and modes

With a resolver, tokens live in token_source documents and the resolver builds the token tree. A set always applies; a modifier applies the sources of one of its contexts. This is the DTCG Resolver Module, written in HCL.

resolver {
  set "foundation" {
    sources = [token_source.foundation]
  }

  modifier "theme" {
    default = "light"

    context "light" {
      sources = [token_source.light]
    }
    context "dark" {
      sources = [token_source.dark]
    }
  }

  resolution_order = [set.foundation, modifier.theme]
}

dsfc check resolves every permutation. A token missing from one of them is DSF-K006. See one permutation with dsfc tokens resolve . --input theme=dark.

Context axes

Every modifier is also a context axis: components read context.theme. Packages can declare other axes with context "<name>" { values = [...] default = "…" }. The host platform provides environment axes:

Axis Values
direction "ltr", "rtl"
reduced_motion true, false
contrast "standard", "high"
text_scale number, 1 by default
pointer "fine", "coarse"
available_width, available_height length proposed by the parent
locale string

A node can set axes for its subtree with provide. The value applies to the node itself and to its descendants; slot content resolves in the context where it is rendered.

stack "preview" {
  provide = {
    theme = "dark"
    layer = "01"
  }
}

Only design choices can be provided: resolver modifiers, declared contexts, direction and locale. User preferences (reduced_motion, contrast, text_scale) and device or layout facts are read-only; providing them is DSF-N011.

Modifier cette page sur GitHub