On this page

← All documentation

Nodes and context reference

The node kinds of theme.ts, their attributes, the typed context (bind, field, on, t, fmt, conditions) and the closed lists and limits of a template.

A template is a function that receives a typed context c and returns a tree of nodes from a closed list of 17 kinds. This page is generated from theme.d.ts, the declarations the game writes from its Rust contracts: every signature, attribute and closed list below is read from it, so it cannot drift from the validator. The descriptions come from the notes of content/dev-src/notes/themes-nodes.<lang>.md, checked for coverage in both languages. For the screens and components a template may be written for, see the contracts reference; for a guided tour, see templates.

The same builders also exist as untyped globals (box, row, bind('a.b'), on.press('confirm')…). Use c.… for completion and for the checks of the type checker. A script that declares a top-level name of its own (const box = …) adds export {} to be a module.

defineTheme

defineTheme is called once, at the top level of theme.ts. Each template is built once from its typed context.

theme.ts calls it once with two optional tables: screens (keyed by the screen name without screen.: library, settings) and components (keyed by contract name: library.footer). Each entry is a function that receives the typed context c of that screen or component and returns one node. A template you do not write is inherited from _base. An unknown screen or contract name is refused with the list of the known ones.

A script runs once: loops, helper functions and constants build the tree; nothing else survives, and a function, a NaN or a cycle in the result is refused.

screens?: { [screen name without `screen.`]?: (c: ThemeContext<'screen.<name>'>) => ThemeNode }
components?: { [contract name]?: (c: ThemeContext<'<contract>'>) => ThemeNode }

Node constructors

Each constructor returns a node. The children are nodes, lists of nodes, or null, undefined and false for an empty place (cond && node). The first argument may be an attributes object.

box

A block.

A plain block: a container with no layout of its own, whose children flow as normal blocks. Give it as to choose the element (section, header, nav, ul…). It takes the common, layout and container attributes. Prefer row or column when the children must line up.

box(...children: ThemeChild[]): ThemeNode
box(attrs: ThemeContainerAttrs, ...children: ThemeChild[]): ThemeNode

Also takes: common attributes, layout attributes, container attributes (attributes).

row

Children side by side.

A flex container with flex-direction: row: the children sit side by side. gap, align, justify, wrap and grow tune it.

row(...children: ThemeChild[]): ThemeNode
row(attrs: ThemeContainerAttrs, ...children: ThemeChild[]): ThemeNode

Also takes: common attributes, layout attributes, container attributes (attributes).

column

Children one under the other.

A flex container with flex-direction: column: the children stand one under the other.

column(...children: ThemeChild[]): ThemeNode
column(attrs: ThemeContainerAttrs, ...children: ThemeChild[]): ThemeNode

Also takes: common attributes, layout attributes, container attributes (attributes).

stack

Children on top of each other.

A container whose children are all drawn in the same cell, on top of each other, the last one on top. Use it for a banner picture behind a title, or an overlay on a card.

stack(...children: ThemeChild[]): ThemeNode
stack(attrs: ThemeContainerAttrs, ...children: ThemeChild[]): ThemeNode

Also takes: common attributes, layout attributes, container attributes (attributes).

grid

A grid; tracks are auto, 1fr, 120px, 50%, minmax(0,1fr).

A CSS grid. columns and rows are lists of at most 12 tracks written as auto, <n>px, <n>fr, <n>%, minmax(0,<n>fr) or minmax(<n>px,<n>fr). Children fill the cells in order. It takes the common and layout attributes, not as.

grid(...children: ThemeChild[]): ThemeNode
grid(attrs: ThemeLayout & { columns?: readonly string[]; rows?: readonly string[] }, ...children: ThemeChild[]): ThemeNode

Also takes: common attributes, layout attributes (attributes).

Own attributes of this node

Attribute Type
columns? readonly string[]
rows? readonly string[]

scroll

A scrolling area.

A scrolling area. axis is y (default), x or both. The area shrinks to its container (min-width and min-height are 0), so give its parent a height.

scroll(...children: ThemeChild[]): ThemeNode
scroll(attrs: ThemeLayout & { axis?: "y" | "x" | "both" }, ...children: ThemeChild[]): ThemeNode

Also takes: common attributes, layout attributes (attributes).

Own attributes of this node

Attribute Type
axis? "y" | "x" | "both"

spacer

Empty room that grows, or a fixed size.

Empty room. Without size it grows to fill the free space of a row or column (it pushes what follows to the end); with a size from 0 to 10 it is a fixed square of that step of the spacing scale.

spacer(attrs?: ThemeAttrs & { size?: ThemeStep }): ThemeNode

Also takes: common attributes (attributes).

Own attributes of this node

Attribute Type
size? ThemeStep

text

Text: a literal, bind("path"), t("key"), fmt.rate("path") or a list of those. tween: true (a fmt value only) counts the number up or down to its new value instead of jumping, and puts data-changed="up" or "down" on the element for 700 ms after each change (what a theme.css animation hangs on); under reduced motion the number jumps and the mark is still set. letters: true makes each letter its own element ([data-letter], --i its position from 0, --n on the text the number of letters): a theme.css staggers an animation along the word with animation-delay: calc(var(--i) * 40ms). scramble: true shows random characters that settle on the new text, left to right, in 400 ms each time the value changes (never the first value, never under reduced motion); both carry data-changed for 700 ms after a change. Neither goes with tween.

A text. value is a literal, a binding (c.bind('map.title')), a translated key (c.t('menu.play')), a formatted number (c.fmt.rate('map.rate')) or a list of these written one after the other. as chooses the element (span by default, p, h1 to h3, strong, em, label, small). A literal is at most 200 characters.

text(value: ThemeText, attrs?: ThemeAttrs & { as?: ThemeTextTag; tween?: boolean; letters?: boolean; scramble?: boolean }): ThemeNode

Also takes: common attributes (attributes).

Own attributes of this node

Attribute Type
as? ThemeTextTag
tween? boolean
letters? boolean
scramble? boolean

icon

A lucide icon: its name, or bind("path") of a text field that holds one (mod.bind("icon"): the mod's own icon).

An icon from the game's closed list (icons). size is a whole number from 12 to 64 (pixels). The icon is decoration: it is hidden from screen readers, so put the meaning in a label.

icon(name: ThemeIcon | ThemeValue<string>, attrs?: ThemeAttrs & { size?: number }): ThemeNode

Also takes: common attributes (attributes).

Own attributes of this node

Attribute Type
size? number

image

An image of the theme ("images/x.png") or the picture found at a path of the data (bind("path")).

A picture. src is either the path of a picture of the theme ('images/logo.png', which must exist in the theme's images/ folder) or a path of the data that holds a picture URL (c.bind('map.background')). alt is required: the text a screen reader says. fit is cover or contain. A path that is neither is refused.

image(src: string | ThemeValue<string>, attrs: ThemeAttrs & { alt: ThemeText; fit?: "cover" | "contain" }): ThemeNode

Also takes: common attributes (attributes).

Own attributes of this node

Attribute Type
alt ThemeText
fit? "cover" | "contain"

button

A button; its on is on.press("output").

A real button: the game's own Button (a plain button element under Classic). It needs a label or children, which give its name, and an on: c.on.press('output'). variant is primary, plain (default) or quiet. disabled and pressed are conditions; describedBy names a part whose text describes the button (how the Play button tells why it is off). A button is not allowed inside a face.

button(attrs: ThemeAttrs & { variant?: "primary" | "plain" | "quiet"; label?: ThemeText; disabled?: ThemeCond; pressed?: ThemeCond; describedBy?: Part; on: ThemeEvent<"press"> }, ...children: ThemeChild[]): ThemeNode

Also takes: common attributes (attributes).

Own attributes of this node

Attribute Type
variant? "primary" | "plain" | "quiet"
label? ThemeText
disabled? ThemeCond
pressed? ThemeCond
describedBy? Part
on ThemeEvent<"press">

toggle

A switch; its on is on.change("output").

A switch. label is its name, checked a condition, on is c.on.change('output'): the output receives the new state (a boolean) after the arguments you give. Not allowed inside a face.

toggle(attrs: ThemeAttrs & { label: ThemeText; checked: ThemeCond; on: ThemeEvent<"change"> }): ThemeNode

Also takes: common attributes (attributes).

Own attributes of this node

Attribute Type
label ThemeText
checked ThemeCond
on ThemeEvent<"change">

meter

A gauge.

A gauge. value must be a number of the data; min and max are literal numbers; label is the accessible name.

meter(attrs: ThemeAttrs & { value: ThemeText; min?: number; max?: number; label: ThemeText }): ThemeNode

Also takes: common attributes (attributes).

Own attributes of this node

Attribute Type
value ThemeText
min? number
max? number
label ThemeText

dropdown

A drop-down list of the { value, label, group, detail } options found at the path options; its on is on.pick("output").

The game's own drop-down list. options is the path of a list of objects with a text value and label (and optionally group and detail), value the current value, label the visible name, displayValue an optional text shown on the closed control, and on is c.on.pick('output'): the picked value is appended to the arguments. A dropdown has no children. Not allowed inside a face.

dropdown(attrs: ThemeAttrs & { label: ThemeText; ariaLabel?: ThemeText; value: ThemeText; options: keyof S["paths"] & string | keyof S["lists"] & string; displayValue?: ThemeText; on: ThemeEvent<"pick"> }): ThemeNode

Also takes: common attributes (attributes).

Own attributes of this node

Attribute Type
label ThemeText
ariaLabel? ThemeText
value ThemeText
options keyof S["paths"] & string | keyof S["lists"] & string
displayValue? ThemeText
on ThemeEvent<"pick">

slot

A named place of the screen (a screen template) or of the contract (a component template).

Puts a part of the screen or component where you say. slot('name') places a place of the current screen (a screen template) or a place a component leaves free (slots of its contract); a place can be used several times. slot('library.chartRow', { from: 'entries[]' }) mounts a whole contract with the data found at from: it renders with its own template. [] is only valid in from, and a contract cannot mount itself. A face can only place its own slots.

slot(name: Slot): ThemeNode
slot(contract: Contract, options: { from: ThemeFrom<S> }): ThemeNode

each

Repeats what build returns for every element of a list; item reads the element (item.bind("name")).

Repeats what its function returns for every element of a list of the data: each('entries', (item) => …). Inside, item.bind('name') reads a field of the element, and a path may start with $alias. for the element of an enclosing each (as names the alias of the item, a letter then letters or digits, at most 16; key names a text or number field that identifies the element). The path must be a list.

each<L extends keyof S["lists"] & string>(of: L, build: (item: ThemeBuilders<T, S["lists"][L]>) => ThemeNode | readonly ThemeNode[], options?: { as?: string; key?: keyof S["lists"][L]["paths"] & string }): ThemeNode

when

Shows then while the condition holds, otherwise else.

Shows then while a condition holds, otherwise (optional) else: when(c.field('pauses.total').gt(0), then, otherwise). A place put in a when still counts as placed for the required-slot check. For "this class only when", use classWhen.

when(test: ThemeCond, then: ThemeNode | readonly ThemeNode[], otherwise?: ThemeNode | readonly ThemeNode[]): ThemeNode

Attributes

Attributes are the members of the object given as the first argument. Three groups are shared by several nodes.

Common attributes

Attribute Type Description
class? HostClass | string | readonly (HostClass | string)[] Classes: the theme's own (selectors of its theme.css) or host classes of the screen or contract. The classes of the node: classes of your theme.css (written without a prefix) or classes the screen or contract lists as host classes. A class that is neither is refused, and a class defined in both places is ambiguous. At most 8 per node; each is lower-case letters, digits and -, starting with a letter (40 characters at most).
classWhen? { readonly [name: string]: ThemeCond } | readonly { class: string; if: ThemeCond }[] Classes present while a condition holds: { selected: field("selected").truthy() }. Classes that are present only while a condition holds: { selected: c.field('selected').truthy() }, or a list of { class, if }. At most 8 entries.
part? Part data-part of an element of the contract. The data-part of the element: a part the contract declares (a screen has none). Styles and tests find elements by their part, and the game itself reads a few (the artist and creator of a card are what a Ctrl-click filters).
role? ThemeRole The ARIA role of the element, from the closed list roles. Layout nodes are generic by default: give role only when the element really is that (a toolbar, a list).
aria? { busy?: ThemeText; live?: "polite" | "assertive" | "off"; label?: ThemeText; pressed?: ThemeText; expanded?: ThemeText; current?: ThemeText; describedby?: ThemeText } ARIA attributes: busy, label, pressed, expanded, current, describedby take text; live takes polite, assertive or off.
hidden? ThemeCond A condition: while it holds the node is hidden (not drawn, not read, not focusable).
inert? ThemeCond A condition: while it holds the node and its children cannot be focused or clicked.
data? { readonly [name: string]: ThemeText } data-<name> attributes: true gives data-name="", false leaves the attribute out. data-<name> attributes: true gives data-name="", false leaves it out. Style them with [data-name] in theme.css. At most 8 entries, names of 24 characters at most, and a few names the game reserves.
vars? { readonly [K in CssVar | --tpl-${string}]?: ThemeText } Custom properties: the CSS variables of the screen or --tpl-*. CSS custom properties set on the element: --tpl-<name> of your own, or the variables the screen or contract lists. Read them with var(--tpl-…) in theme.css. At most 8 entries.

Layout attributes

Attribute Type Description
gap? ThemeStep The space between children, a step of the spacing scale (0 to 10, the tokens --pv-s0 to --pv-s10).
pad? ThemeStep The padding of the container, a step of the spacing scale (0 to 10).
align? "start" | "center" | "end" | "stretch" | "baseline" align-items of the container: where children stand on the cross axis.
justify? "start" | "center" | "end" | "between" | "around" | "evenly" justify-content of the container: how children share the main axis (between, around, evenly space them).
wrap? boolean true lets the children of a flex container (row or column) wrap onto several lines.
grow? 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 flex-grow, 0 to 12. flex-grow of the node in its parent, a whole number from 0 to 12.
focusable? boolean The node can take keyboard focus (a container that acts as a control). Makes the node a target for programmatic focus (tabindex="-1"): the game can focus it, but it is never a tab stop. Keyboard order is always the order of the tree.

Container attributes

Attribute Type Description
as? ThemeContainerTag The HTML element of a container (div by default; section, header, footer, nav, aside, main, article, ul, li).

The aria attribute

aria takes these keys; each value is text (a literal, a value of the data or a list of them), except live.

Attribute Type
busy ThemeText
live "polite" | "assertive" | "off"
label ThemeText
pressed ThemeText
expanded ThemeText
current ThemeText
describedby ThemeText

Reserved data names

data sets data-<name> attributes (at most 8 entries). These names belong to the renderer or the game's styles and cannot be set: part, contract, state, direction, gap, align, justify, wrap, grow, pad, size, axis, variant, kind, slot.

Values, conditions and events

The members of the context that are not nodes: they build the values a node shows, the conditions that show or hide, and the events that call an output.

Values

c.bind

The data at a path of the input ("" is the item of an each).

c.bind('path') reads the data at a dotted path of the input of the screen or component: text, a number or a boolean (a list or an object cannot be bound). Inside an each, item.bind('field') reads the element and c.bind('$alias.field') an outer one. A path that exists in no state of the input is refused when the theme loads; a path that exists but is empty in the current state reads as empty text.

bind<P extends ThemeBindable<S>>(path: P): ThemeValue<S["paths"][P]>

c.t

A translated text; args fill its placeholders.

c.t('menu.key', { name: value }) is the game's own translated text for a catalogue key (lower-case letters, digits, _ and ., at most 64 characters), with placeholders filled by the arguments (at most 8, names of at most 16 letters or digits). It follows the player's language, which a literal does not.

t(key: string, args?: { readonly [name: string]: ThemeText }): ThemeValue<string>

fmt.rate

A playback rate: 1.25 (no x).

A playback rate written without the x: 1.25. digits (0 to 6) is optional. The path must be a number.

rate(path: ThemeNumeric<S>, digits?: 0 | 1 | 2 | 3 | 4 | 5 | 6): ThemeValue<string>

fmt.count

A compact count, floored: 12k, 1.9k.

A compact count, rounded down: 12k, 1.9k. digits (0 to 6) is optional.

count(path: ThemeNumeric<S>, digits?: 0 | 1 | 2 | 3 | 4 | 5 | 6): ThemeValue<string>

fmt.percent

A number that is ALREADY a percentage (97.4 gives 97.40%); 2 digits by default.

A number that is already a percentage: 97.4 gives 97.40% (2 digits by default). A fraction such as 0.974 is not multiplied.

percent(path: ThemeNumeric<S>, digits?: 0 | 1 | 2 | 3 | 4 | 5 | 6): ThemeValue<string>

fmt.duration

A duration in SECONDS as m:ss (or h:mm:ss).

A duration given in seconds, written m:ss (or h:mm:ss from an hour).

duration(path: ThemeNumeric<S>, digits?: 0 | 1 | 2 | 3 | 4 | 5 | 6): ThemeValue<string>

fmt.fixed

A number with a fixed count of decimals (toFixed(digits), 2 by default).

A number with a fixed count of decimals (toFixed(digits), 2 by default).

fixed(path: ThemeNumeric<S>, digits?: 0 | 1 | 2 | 3 | 4 | 5 | 6): ThemeValue<string>

Conditions

c.field

A field of the input, to compare: field("pauses.total").gt(0).

c.field('path') names a field of the input to compare in a condition; it returns an object whose methods (eq, gt, truthy…) build a condition. The methods offered depend on the type of the field: numbers have gt, ge, lt, le; texts, enums and booleans have eq, ne, in; objects and lists only have truthy and falsy. The field state of a contract is its state (mapReady…).

field<P extends keyof S["paths"] & string>(path: P): ThemeFieldOf<S["paths"][P]>

field(…).truthy

The data is present (an object, a non-empty list or text, a number other than 0, true).

True when the data is present: an object that is not null, a list that is not empty, a text that is not empty, a number other than 0, true. The only test an object or a list accepts.

truthy(): ThemeCond

field(…).falsy

The opposite of truthy.

falsy(): ThemeCond

field(…).eq

True when the field equals the value. For text, enums and booleans. An enum field is only compared with one of its own values: any other word is refused with the list.

eq(value: T): ThemeCond

field(…).ne

True when the field differs from the value (same types as eq).

ne(value: T): ThemeCond

field(…).in

True when the field is one of 1 to 16 values (text or enum): c.field('state').in(['mapReady', 'mapBlocked']).

in(values: readonly T[]): ThemeCond

field(…).gt

True when the number is greater than the value.

gt(value: number): ThemeCond

field(…).ge

True when the number is greater than or equal to the value.

ge(value: number): ThemeCond

field(…).lt

True when the number is less than the value.

lt(value: number): ThemeCond

field(…).le

True when the number is less than or equal to the value.

le(value: number): ThemeCond

cond.and

cond.and(other, …) is true when this condition and all the others hold (at most 8 conditions in all).

and(...others: ThemeCond[]): ThemeCond

cond.or

cond.or(other, …) is true when this condition or any of the others holds (at most 8 conditions in all).

or(...others: ThemeCond[]): ThemeCond

cond.not

cond.not() inverts a condition. Conditions nest at most 6 levels.

not(): ThemeCond

Events

on.press

The button is pressed (click, Enter, Space): calls the output with these arguments.

c.on.press('output', arg, …) is the on of a button: the output is called when the button is pressed (click, Enter or Space) with the arguments, in order and of the type the output declares. The name must be an output of the screen or component, or the theme is refused with the list of its outputs.

press<O extends keyof T["outputs"] & string>(output: O, ...args: ThemeArgs<T["outputs"][O]>): ThemeEvent<"press">

on.change

The toggle changes: calls the output with these arguments, then the new state (a boolean).

c.on.change('output', arg, …) is the on of a toggle: the output is called with the arguments you give, then the new state (a boolean) as the last one.

change<O extends keyof T["outputs"] & string>(output: O, ...args: ThemeArgs<ThemeLead<T["outputs"][O]>>): ThemeEvent<"change">

on.pick

An option of the dropdown is picked: calls the output with these arguments, then the option's value (a string).

c.on.pick('output', arg, …) is the on of a dropdown: the output is called with the arguments you give, then the value of the picked option (a string) as the last one.

pick<O extends keyof T["outputs"] & string>(output: O, ...args: ThemeArgs<ThemeLead<T["outputs"][O]>>): ThemeEvent<"pick">

Closed lists

Every list below is closed: a value outside it is refused with its list in the message.

Roles

Values of role. group, region, toolbar, tablist, tabpanel, status, search, list, listitem, navigation, none, presentation, img.

Spacing steps

gap, pad and size take a step from 0 to 10, which is the spacing token --pv-s0 to --pv-s10 (tokens). 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

Element names

Values of as: for containers (box, row, column, stack), then for text.

  • box, row, column, stack: div, section, header, footer, nav, aside, main, article, ul, li

  • text: span, p, h1, h2, h3, strong, em, label, small

Icons

Values of the name of an icon node (and of a tab's icon): any lucide icon, by its name on lucide.dev/icons. The page loads an icon the first time it is drawn. For example: heart, music-2, play, skull, swords, zap.

Limits

Limits of the tree a template produces and of the script that builds it. A tree over a limit is refused with a message that names it; a script over a budget loads the theme without its templates.

Limit Value Where
Nesting depth of nodes in a template 24 validator (crates/themes/src/template)
Nodes of all the templates of one theme together 1,500 validator (crates/themes/src/template)
Characters of a literal text 200 validator (crates/themes/src/template)
Templates (screens and components) of one theme 64 validator (crates/themes/src/template)
Children of one node 64 validator (crates/themes/src/template)
Classes of one node (and conditional classes) 8 validator (crates/themes/src/template)
Entries of data and of vars of one node 8 validator (crates/themes/src/template)
Tracks of a grid (columns, rows) 12 validator (crates/themes/src/template)
Nesting depth of a value (a list of values inside a list…) 6 validator (crates/themes/src/template)
Nesting depth of a condition (and, or, not) 6 validator (crates/themes/src/template)
Arguments of an output call 8 validator (crates/themes/src/template)
Values of an in([…]) comparison 16 validator (crates/themes/src/template)
Themes loaded at once 64 crates/themes/src/library.rs
Wall time of theme.ts (the whole run, builders included) 500 ms ThemeScriptLimits (crates/modding/src/theme.rs)
Memory of the script engine 16 MiB ThemeScriptLimits (crates/modding/src/theme.rs)
Stack of the script engine 1 MiB ThemeScriptLimits (crates/modding/src/theme.rs)
Size of theme.ts 128 KiB ThemeScriptLimits (crates/modding/src/theme.rs)
Nodes the script may build (every template, counted with repetitions) 4,000 ThemeScriptLimits (crates/modding/src/theme.rs)
Size of the tree as JSON 1 MiB ThemeScriptLimits (crates/modding/src/theme.rs)

Source in the game repository: content/mods/sdk/theme.d.ts,crates/themes/src/template/mod.rs,crates/themes/src/template/validate.rs,crates/modding/src/theme.rs,content/dev-src/notes/themes-nodes.en.md