Each recipe is a complete theme, small enough to read in one sitting. It inherits the default templates, so it overrides one idea and leaves the rest alone. Every recipe comes from a shipped theme: the shipped one is the full version, the recipe is the idea with the rest removed.
How to use a recipe
The recipes are real folders in content/examples/themes/<name>/. The pages show them by inclusion, so what you read is what the test suite checks: each folder passes the same validator as the game, with no problem.
To try one, copy its folder next to your other themes and check it:
cargo run -p modding --example check_theme -- content/examples/themes
The command prints one line per theme and exits with code 1 if any file has a problem. See Errors to read its output.
A screen template replaces the whole screen, so each recipe that changes a screen writes out the default composition and changes one thing in it. This is also why a recipe keeps game classes such as song-select, pv-screen and map-browser: they are listed by the screen and the game styles them. The list of those classes, of the places a screen must fill and of the paths a template may read is on the contracts page.
Hero banner
From content/themes/stage/. Folder: content/examples/themes/recipe-hero-banner/.

What it does. The heading of the selected map sits on the map's own picture, blurred and shaded, and a strip of four facts (duration, BPM, notes, keys) stands under it. The tabs go to a rail beside their panel.
The picture. An image node bound to map.background reads the path of the map's picture from the input. It is drawn only when the map has one.
// The picture and its shade. The `image` node reads a path bound to the input (`map.background`), never a URL of the web.
// It is shown only when the map has a picture.
function backdrop(c: Screen): ThemeNode {
return c.box(
{ class: 'hero-backdrop', role: 'presentation' },
present(c, 'map.background', c.image(c.bind('map.background'), { class: 'hero-art', alt: '', fit: 'cover' })),
c.box({ class: 'hero-shade' }),
);
}
The edge trick. The backdrop is larger than the banner (inset with negative values) and the blur is applied to the backdrop as one piece, so the blur eats its own edges and the picture melts into the screen instead of stopping on a rectangle.
/* The banner is not a box: its backdrop reaches past it and is blurred as a whole, so the blur eats its own edges and the picture melts into the screen. */
.hero { position: relative; z-index: 0; flex: none; display: flex; flex-direction: column; margin-bottom: var(--pv-s3); }
.hero-backdrop { position: absolute; inset: -22px -22px -12px -14px; z-index: 0; overflow: hidden; filter: blur(16px); pointer-events: none; }
.hero-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scale(1.08); filter: saturate(1.4) brightness(.85); }
The title on the picture. The heading is the game's own, placed with slot('header'). A rule makes the plate it paints transparent through the plate variables, so the title stands on the picture. A rule may also set a design token for its subtree: here the rating figure is smaller inside the banner.
/* A design token can be set by a rule: here the heading's rating is smaller. `--plate` is the variable plates paint their background with: transparent lets the picture show. */
.hero-main { display: flex; flex-direction: column; gap: var(--pv-s1); min-width: 0; --pv-fs-rating: clamp(44px, 4.2vw, 76px); --pv-plate-filter: none; }
.hero-main [data-edge] { --plate: transparent; --edge: linear-gradient(180deg, var(--difficulty-color), transparent); }
The strip is a table. One row per fact. Add a row and the strip gets one more tile; nothing else changes.
// A table drives the strip: one row per fact, with its label key, its icon and how its value reads the input.
// Add a row and the strip has one more tile; nothing else changes.
interface Fact {
readonly label: string;
readonly icon: ThemeIcon;
readonly value: (c: Screen) => ThemeText;
}
const FACTS: readonly Fact[] = [
{ label: 'ui.duration', icon: 'clock', value: c => c.bind('map.duration.text') },
{ label: 'metrics.bpm', icon: 'activity', value: c => c.bind('map.bpm') },
{ label: 'maps.notes', icon: 'music', value: c => c.bind('map.notes') },
{ label: 'search.keys', icon: 'keyboard', value: c => c.bind('map.keysText') },
];
Why it is written this way
mask-imageis not in the CSS subset, andclip-pathonly has hard edges. A backdrop that overflows and is blurred whole is the way to a soft edge.- The picture is a
bindto the input, never a URL: a theme cannot load an address from the web. A picture of the theme itself is writtenc.image('images/x.png', …)and the file must exist in the theme'simages/folder. - An
imageneeds analt. A decorative picture usesalt: ''and sits in a node withrole: 'presentation'. - A playlist has no
mapfacts.present(c, 'map', …)wraps what needs them in awhenon that field, so a path that does not exist in the current state never breaks the template. - The game's own heading has four plates of figures.
classWhen: { lit: … }marks a banner that has the strip, sotheme.csscan hide them (.lit [data-part='stats']): the strip says the same. - Text is never put straight on a busy picture: the shade is a gradient made with
color-mixof the page colour, strongest where the heading is. tokens.csskeeps the game's own map picture visible:--pv-shadeand--pv-art-filtermay tint, dim and blur it, never hide it (see limits).
Limits to know. filter: blur() and backdrop-filter: blur() are in the allow-list; the allowed filter functions are listed on the CSS allow-list page. In tokens.css, blur() of --pv-art-filter is limited to 12 px (crates/themes/src/grammar.rs). In theme.css, backdrop-filter is bounded because the GPU recomputes it behind the whole box: blur() takes one written number from 0 to 64 px and saturate() one from 0 to 4 (or 0 % to 400 %), with no var() or calc() (crates/themes/src/stylesheet.rs, MAX_BACKDROP_BLUR, MAX_BACKDROP_SATURATE).
Slanted cards
From content/themes/carousel/. Folder: content/examples/themes/recipe-slanted-cards/.

What it does. Set cards are slanted panels on the set's picture, with the title and the artist over it. Each difficulty is a round badge with the key count and ten stars. The list curves: the farther a row is from the selected one, the more it slides right and fades.
Two faces. A set card, a difficulty row and a score card are faces: the game draws the card's root (its button, its keyboard, its menu, the virtual row it sits in) and the theme draws what is inside. That is why the template below has no button and calls no output.
// The set card: a slanted panel on the set's own picture, with the title and the artist over it, then the layout, one round dot per difficulty and the rating range.
// `part` names the parts the game hangs gestures on (Ctrl+click on the artist filters by it).
function setCard(c: SetCard): ThemeNode {
return c.row(
{ class: 'sc', align: 'center', gap: 3 },
panel(c),
c.column(
{ class: 'sc-info', grow: 1, gap: 0 },
c.text(c.bind('title'), { as: 'strong', part: 'title', class: 'sc-title' }),
c.text(c.bind('artist'), { as: 'small', part: 'artist', class: 'sc-artist' }),
c.row({ class: 'sc-foot', align: 'center', gap: 2 }, c.text(c.bind('keysText'), { part: 'keys', class: 'sc-keys' }), dots(c)),
),
c.text(c.bind('rating.range'), { as: 'strong', part: 'rating', class: 'sc-rating' }),
);
}
The ten stars. stars is a list of ten entries. The first ones are lit according to the rating, and a loop draws one text node for each. The theme only reads lit; the arithmetic belongs to the game.
// The difficulty row: a round badge with the key count, the name over ten stars, and the rating at the right.
// `stars` is a list of ten entries; the first ones are `lit` according to the rating, and a loop draws one text node for each.
function chartRow(c: ChartRow): ThemeNode {
return c.row(
{ class: 'dr', align: 'center', gap: 3 },
c.box({ class: 'dr-ring', part: 'keys' }, c.text(c.bind('keysText'), { class: 'dr-keys' })),
c.column(
{ class: 'dr-main', grow: 1, gap: 0 },
c.row({ class: 'dr-line', align: 'center', gap: 1 }, c.text(c.bind('name'), { as: 'strong', part: 'name', class: 'dr-name' }), c.slot('missing'), c.slot('goal')),
c.row({ class: 'dr-stars', role: 'presentation' }, c.each('stars', (star: StarItem) => star.text('★', { class: 'dr-star', classWhen: { lit: star.field('lit').truthy() } }))),
),
c.row({ class: 'dr-rate', part: 'rating', align: 'baseline', gap: 1 }, c.text(c.bind('rating'), { as: 'strong', class: 'dr-rating' }), c.text(c.bind('ratingUnit'), { as: 'small', class: 'dr-unit' })),
);
}
The curve. The list sets --row-distance on each row: how many rows separate it from the centre row (negative above). The centre is the chosen difficulty, else the chosen set, else the middle row of the list window. The theme reads it with var().
/* Recipe: slanted cards. The list's rows carry `--row-distance`: their number of rows from the selected one (negative above). A row slides right with its square,
up to a bound, and fades, so the list curves around the selection. The selected row (`data-active`) stays left and fully opaque. */
.rack [data-pvng-list] { overflow-x: hidden; }
.rack [data-contract='library.setCard'], .rack [data-contract='library.chartRow'] {
padding: 0;
gap: 0;
overflow: visible;
--plate: transparent;
--edge: transparent;
transform: translateX(min(calc(var(--row-distance) * var(--row-distance) * 60px), 64px));
opacity: calc(1 - min(calc(var(--row-distance) * var(--row-distance) * .04), .5));
}
.rack [data-contract='library.setCard'][data-active] { transform: translateX(-26px); opacity: 1; }
.rack [data-contract='library.chartRow'][data-active] { transform: translateX(-30px); opacity: 1; }
The slanted shape.
/* The set card. `--set-color` is the colour of the set's hardest difficulty: a variable of the game's row, readable here. */
.sc { position: relative; flex: 1; display: flex; align-items: center; min-width: 0; height: 100%; padding: 0 var(--pv-s5) 0 var(--pv-s6); }
.sc-art { position: absolute; inset: 0; z-index: -1; overflow: hidden; background: var(--pv-plate-raised); clip-path: polygon(24px 0, 100% 0, 100% 100%, 0 100%); border-left: 3px solid var(--set-color); }
Why it is written this way
- The curve uses the square of the distance, bounded:
min(…, 64px)for the slide,min(…, .5)for the fade. Near rows barely move, far rows never leave the window or vanish. - The selected row has its own rule through
[data-active], which the game sets on the open or selected card. It stays left and fully opaque. - The recipe changes the screen only to give the library column the class
rack. Atheme.cssselector must start with a class of the theme, so a game element such as[data-contract='library.setCard']is reached through a class of the theme placed above it. - A dot's colour travels as a variable of the theme: the node sets
--tpl-chipwithvars, and the stylesheet readsvar(--tpl-chip).varsaccepts only the variables of the screen or--tpl-*. - The game's variables
--set-color(the hardest difficulty's colour) and--difficulty-colorare read withvar(). The theme writes no colour of its own for them. part: 'artist'keeps Ctrl+click on the artist working: the game filters by that part. A face that does not set the part only loses that gesture.[data-pvng-list] { overflow-x: hidden }stops the slid rows from adding a horizontal scrollbar.
Limits to know. A face refuses button, toggle, dropdown, a slot that mounts another contract, and any output call: the message is a button is not allowed in library.setCard: … (see Errors). A filter or a box-shadow on the same element as a clip-path is cut by it, so the shadow disappears. For a shadow that follows a slanted shape, put filter: drop-shadow(…) on a parent of the clipped element and the clip-path on the child. In tokens.css, --pv-plate-filter does the same for the plates and takes a drop-shadow.
Poster and scrim
From content/themes/cinema/. Folder: content/examples/themes/recipe-poster-scrim/.

What it does. The selected map's picture is the whole page (the game draws it behind the menus). The theme adds a scrim, a gradient from clear to the page colour that darkens the foot of the poster, sets the heading as a large serif title, and puts the tabs and their panel on a sheet of glass. The list becomes a slim column on the right.
The scrim is a pseudo-element.
/* The poster rests on the foot of the window. Its scrim is a pseudo-element: a gradient from clear to the page colour, behind everything the poster holds.
`z-index: 0` on a positioned box makes it a stacking context, so the scrim's negative z-index stays inside the poster. */
.poster { position: relative; z-index: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: var(--pv-s4); min-width: 0; min-height: 0; }
.poster::before {
content: '';
position: absolute;
inset: -40px -24px 0 -24px;
z-index: -1;
pointer-events: none;
background: linear-gradient(180deg, transparent 0%, color-mix(in srgb, var(--pv-bg) 55%, transparent) 45%, color-mix(in srgb, var(--pv-bg) 92%, transparent) 100%);
}
The glass sheet is a translucent panel with a blurred backdrop.
/* The glass sheet: a blurred, translucent panel. `backdrop-filter` is in the allowed list (blur and saturate only). */
.sheet { flex: 0 1 46%; min-height: 0; padding: 0; background: color-mix(in srgb, var(--pv-bg) 55%, transparent); border-top: 1px solid var(--pv-line); backdrop-filter: blur(14px) saturate(1.2); }
The picture stays. The scrim is the theme's own box over the poster, but the game's picture behind the menus is governed by two tokens, and the recipe keeps them light on purpose.
/* The picture behind the menus is dimmed a little, never hidden: the validator keeps at least a fifth of its light on screen. */
--pv-art-filter: saturate(1.05) brightness(.9);
--pv-shade: linear-gradient(180deg, rgb(0 0 0 / .1), rgb(0 0 0 / .3));
Why it is written this way
- The scrim sits behind the poster's content with
z-index: -1.z-index: 0on the positioned poster makes it a stacking context, so the negative index stays inside the poster instead of going behind the page. - A scrim made of a gradient and no extra node:
::beforetakescontent: ''and is written last in its selector, once. - The heading's plates are made transparent with
--plate: transparenton[data-edge], so the serif title stands on the scrim. The game's heading is not replaced. - Play moves into a bar at the foot of the poster with
slot('footer'). Play can move; the footer place is required, so it can never disappear. --pv-layout-tabs: topputs the tab bar above the panel insideselected-body. The theme asks the game for a layout with a word of a closed list; it writes no CSS for it.- The nothing-selected state places the heading alone in the same spot, large: it is the invitation to pick a map.
Limits to know. The game's map picture must keep at least 20 % of its light on screen, averaged over the window. Each --pv-shade gradient may cover at most 90 % on average, so an opaque flat colour is refused. In --pv-art-filter, brightness() may not go below 0.25, opacity() below 0.4, contrast() below 0.5 (crates/themes/src/artwork.rs). backdrop-filter takes only blur and saturate. z-index runs from −50 to 50. A pseudo-element takes a content string of at most 80 characters, without \.
Terminal list
From content/themes/hack/. Folder: content/examples/themes/recipe-terminal-list/.

What it does. A phosphor-terminal look: monospace text, sharp rectangles, bracketed buttons, and one line per set in the list, like a directory listing.
Layout words do half the work. The tokens choose the shape of rows, buttons and tabs by a word of a closed list. No selector is written for it.
/* Layout words: dense spacing, text rows, bracketed buttons. */
--pv-layout-density: dense;
--pv-layout-rows: text;
--pv-layout-buttons: bracket;
--pv-layout-tabs: top;
One line per set. The face of the set card is a single row; a grid of four columns in theme.css aligns title, artist, rating and tags.
// The set card as one line: the title (with NEW when the set is new), the artist, the rating and the difficulties.
// `part` names the parts the game hangs gestures on (Ctrl+click on the artist filters by it). The game's marks (goal, missing file) stay available as slots.
function setCard(c: SetCard): ThemeNode {
return c.row(
{ class: 'sc', align: 'center' },
c.row(
{ class: 'sc-name', align: 'center', gap: 2 },
c.slot('goal'),
c.text(c.bind('title'), { as: 'strong', part: 'title', class: 'sc-title' }),
c.when(c.field('newText').truthy(), c.text(c.t('library.new'), { class: 'sc-new' })),
c.slot('missing'),
),
c.text(c.bind('artist'), { as: 'small', part: 'artist', class: 'sc-artist' }),
c.text(c.bind('rating.range'), { part: 'rating', class: 'sc-rating' }),
tags(c),
);
}
Brackets and cursor come from pseudo-elements.
/* The cursor: a `>` before the title of the open or selected line (the game marks it `data-active`), and a dim one under the pointer. */
.sc-name::before { content: '>'; flex: none; width: 1ch; color: var(--pv-accent); opacity: 0; }
.crate [data-contract='library.setCard']:hover .sc-name::before { opacity: .45; }
.crate [data-contract='library.setCard'][data-active] .sc-name::before { opacity: 1; }
/* A tag is the difficulty's rating between brackets, in the difficulty's colour. */
.sc-tags { justify-content: flex-end; min-width: 0; overflow: hidden; }
.tag { flex: none; font-size: var(--pv-fs-xs); color: var(--tpl-chip); }
.tag::before { content: '[ '; color: var(--pv-text-3); }
.tag::after { content: ' ]'; color: var(--pv-text-3); }
Why it is written this way
--pv-layout-buttons: bracketdraws every button as[ ]in the game's own components. The theme does not restyle buttons; it picks a word. The same holds for--pv-layout-rows: text(a row of a table) and--pv-layout-density: dense.- Each tag is the rating between two brackets written with
::beforeand::after. The game's selected line is markeddata-active, which the stylesheet uses for the>cursor. - Text from
contentis decoration that screen readers may read. Never put information in it: the brackets and the cursor are decoration, the rating is a real text node. - The mono stack ends with a generic family (
monospace), as a font token requires. - The recipe does not use
--pv-layout-focus: blink: it loops forever, which is an infinite animation (see Errors). The shipped Hack theme keeps the plain ring too.
Limits to know. A --pv-layout-* token takes one word from its list; any other word, several words, an empty value, a number or a var() is refused. A pseudo-element is allowed once, at the end of a selector, never after another pseudo-element. Font stacks have 1 to 8 families and end with a generic one.
Live bars
From content/themes/stage/. Folder: content/examples/themes/recipe-live-bars/.

What it does. A band of bars under the heading of the selected map. Each bar has two heights from 4 to 100: level, the note density of the map, and live, the same bar as the menu music plays it (the game's spectrum, folded into the same bars).
Bind live and you get the music. The theme gives each bar's live to the stylesheet as a variable.
// The band: a row of bars, drawn only when the map has an equalizer (a playlist has none). `data-listening` is set while the music drives the bars,
// so the stylesheet can light them. `each` repeats `bar` for every element of the list.
function equalizer(c: Screen): ThemeNode {
return c.when(c.field('map.equalizer').truthy(), c.row({ class: 'eq', role: 'presentation', data: { listening: c.bind('map.listening') } }, c.each('map.equalizer', bar)));
}
// One bar: an empty box that hands its live height to the stylesheet as a variable of this theme, `--tpl-live` (a number from 4 to 100).
function bar(item: BarItem): ThemeNode {
return item.box({ class: 'eq-bar', vars: { '--tpl-live': item.bind('live') } });
}
Scale, do not resize.
/* A bar is always full height and is SCALED: `transform` does not lay the page out again, where `height` would, thirty times a second. `--tpl-live` runs from 4 to 100.
There is NO `transition` here: the page has already eased the levels, and a transition makes the browser restyle every bar on every frame for nothing the eye can see. */
.eq-bar {
flex: 1 1 0;
min-width: 2px;
height: 100%;
opacity: .75;
transform-origin: bottom;
transform: scaleY(calc(var(--tpl-live) / 100));
background: linear-gradient(180deg, var(--pv-accent), color-mix(in srgb, var(--pv-accent) 20%, transparent));
}
Why it is written this way
- A theme that binds
live(ormap.listening) is enough: the screen then asks the game for the spectrum, only while a map is shown and the player has not asked for less motion. A theme that does not bind it costs nothing: no request, no analysis. - The bar is full height and scaled:
transform: scaleY(…)does not lay the page out again, whereheightwould, about thirty times a second. - There is no
transition. The page already eases the heights (a bar rises fast, falls slowly), and a transition would make the browser restyle every bar on every frame for nothing visible. - There is no animation at all, so nothing runs when the screen is at rest. An equalizer built from
@keyframeswithinfinitewould repaint the page every frame; the validator warns about it (see Errors). - Without music (menu music off, loading, paused for the settings, or during a play),
liveequalslevel: the bars glide to the density and stay there. For a player who asks for less motion the page never asks for the spectrum: the bars are still. data-listeningis set while the music drives the bars, so the stylesheet can make them brighter.varsis limited to the variables of the screen and--tpl-*, at most 8 entries per node.
Limits to know. The cost is one update of the screen input per spectrum frame, about thirty a second, and only while the music plays; at rest nothing runs. The bars come from one each: a single node in the template, however many bars the game gives. The tokens of the map picture and the filters of theme.css have their own limits (see limits).
Settings rail
From content/themes/stage/. Folder: content/examples/themes/recipe-settings-rail/.

What it does. The Settings window as a rail: the title with the count of changed settings, the search, the list of categories and the window's buttons in a column on the left, the panel of the open category on the right.
A second screen. The window is the screen screen.settings, with its own contract. The game keeps the modal dialog: the focus trap, Escape, giving focus back. The template composes what is inside it from places: it draws neither a setting row nor a control.
// The window: a left column (the rail) and a right column (the panel), side by side. Every place the contract requires is placed:
// `title`, `search`, `actions`, `close`, `notices`, `rail` and `panel`; `hints` (the keyboard hints) is the only optional one.
function settingsScreen(c: Settings): ThemeNode {
return c.row({ as: 'section', class: 'win' }, rail(c), main(c));
}
// The left column: the title with, under it, how many settings differ from the shipped ones, then the search, the list of categories, and at the foot the window's buttons.
// `changed` is a number of the input of the screen; `c.t` with an argument is the game's translated, pluralised sentence.
function rail(c: Settings): ThemeNode {
return c.column(
{ as: 'aside', class: 'side' },
c.column(
{ class: 'head', gap: 1 },
c.slot('title'),
c.when(c.field('changed').gt(0), c.text(c.t('settings.changed_count', { count: c.bind('changed') }), { as: 'small', class: 'changed' })),
),
c.box({ class: 'find' }, c.slot('search')),
c.slot('rail'),
c.row({ class: 'buttons', align: 'center', gap: 1 }, c.slot('actions'), c.slot('close')),
);
}
// The right column: the notices (the game's messages, an import review), the panel of the open category, the keyboard hints.
function main(c: Settings): ThemeNode {
return c.column({ class: 'main' }, c.slot('notices'), c.slot('panel'), c.slot('hints'));
}
Reaching the game's parts.
.side { flex: none; width: 280px; min-height: 0; gap: var(--pv-s3); }
.main { flex: 1; min-width: 0; min-height: 0; }
/* The game's own parts are reached by their `data-part` marks, never by their classes. The panel is the part that scrolls: it takes the room of the column. */
.main [data-part='panel'] { flex: 1; min-width: 0; }
.side [data-part='rail'] { flex: 1; min-height: 0; }
Why it is written this way
- Every place the screen requires is placed; only the optional ones may be left out. A missing required place is refused (see Errors). The list of places, with their required flag, is on the contracts page.
changedis a number of the screen's input.c.when(c.field('changed').gt(0), …)shows the sentence only when something changed;c.t('settings.changed_count', { count: c.bind('changed') })is the game's translated, pluralised sentence.- The panel and the rail are reached by
data-partmarks, never by classes of the game:[data-part='panel'],[data-part='rail']. - The tokens choose the look of the categories (
--pv-layout-settings: rail: a rounded vertical list) and of the groups of rows (--pv-layout-groups: inset). - The template calls no output: closing, searching and choosing a category are done by the components placed in
close,searchandrail. Abuttonthat does call one of the screen's outputs must name an output that the contract lists, with its arguments.
Limits to know. A button in a screen template may call only an output that the screen lists. A name outside the list is refused, with the list of the screen's own outputs in the message (see Errors).
Footer strip
Folder: content/examples/themes/recipe-footer-strip/. No shipped theme templates the footer: this recipe shows component templates. Its score card follows the face written by content/themes/stage/, simplified.
What it does. Two templates under components, where the other recipes write screens: the strip under the selected map (two drop-down lists, a refusal line and the main button), and one score of the leaderboard as a face with a grid, a meter and formatted numbers.
The strip. The two choosers on the left, a spacer, the refusal line only when there is one, then the Play button, or the two buttons of a playlist.
// The strip under the selected map: the two choosers on the left, then the refusal line (only when no judgement can be used), then the main button.
// The contract REQUIRES its `confirm` output to be called by a button, so a theme can move Play and restyle it, never remove it.
function footer(c: Footer): ThemeNode {
const playlist = c.field('state').in(['playlistReady', 'playlistBlocked']);
return c.row(
{ class: 'strip', align: 'center', gap: 3 },
chooser(c, 'rating'),
chooser(c, 'judgement'),
c.spacer(),
c.when(c.field('refusal').truthy(), c.text(c.bind('refusal'), { class: 'refusal', part: 'refusal', role: 'status' })),
// A map seen from a playlist has no Play: the playlist is what plays. Otherwise a playlist gets its two buttons, a map gets one.
c.when(c.field('state').ne('mapNoPlay'), c.when(playlist, playlistButtons(c), playButton(c))),
);
}
A drop-down list. The options come from a list of the input; the value is the one in force. Picking an entry calls an output with the entry's value appended to the arguments.
// A drop-down list: the options come from the input (`rating.options`), the value is the one in force, and picking an entry calls the output
// `rating.pick` (or `judgement.pick`) with the entry's value appended to the arguments.
function chooser(c: Footer, which: 'rating' | 'judgement'): ThemeNode {
return c.dropdown({
class: 'chooser',
part: which,
label: c.t(which === 'rating' ? 'rating.label' : 'judgement.title'),
value: c.bind(`${which}.value`),
options: `${which}.options`,
displayValue: which === 'judgement' ? c.bind('judgement.label') : undefined,
ariaLabel: which === 'judgement' ? c.bind('judgement.ariaLabel') : c.t('rating.label'),
on: c.on.pick(`${which}.pick`),
});
}
Play can move, never vanish. The contract requires its confirm output to be called by a button.
// The main button of a map. It is off in the two states where it cannot start, and the reason is a line of text it points at (`describedBy`), so it stays readable.
function playButton(c: Footer): ThemeNode {
const off = c.field('state').in(['mapBlocked', 'mapRefused']);
return c.row(
{ class: 'go-line', align: 'center', gap: 2 },
c.when(c.field('state').eq('mapBlocked'), c.text(c.bind('reason.text'), { class: 'reason', part: 'reason' })),
c.button({ variant: 'primary', class: 'go', part: 'play', label: c.bind('play.label'), disabled: off, classWhen: { off }, describedBy: 'reason', on: c.on.press('confirm') }),
);
}
Why it is written this way
- The keys of
componentsare contract names. Each template is validated alone against its contract, and a refused one is replaced by the default. confirmis a required output of the footer. A template without abuttonthat calls it is refused (see Errors).- A
dropdownis the game's own list and has no children: you give it the path of its options, its value, and an output foron.pick. disabledtakes a condition, not a boolean, anddescribedBynames a part of the contract: the reason text is what the disabled button points at, so it stays readable.- States are read with
c.field('state')and.eq,.neor.in([...]); conditions combine with.and(),.or()and.not(). - The score card is a face: no button, no output. The game keeps its plate and the buttons beside it, and
c.slot('tiers')places a widget of the game. The formattersc.fmt.rate,count,percentandfixedwrite numbers;percentexpects a number that is already a percentage (97.4 gives97.40%).
Limits to know. A grid has at most 12 tracks. The arguments of an output are checked in order and by type: a wrong count reads <output> takes <n> arguments (…) and <m> are given. A component template cannot call an output of a screen.
Combining recipes
A theme may hold several ideas, each as in its recipe. Two points keep the result valid.
- One template per screen. A screen is replaced as a whole, so two recipes that both change
screen.librarymust be merged into one function. Faces and component templates are separate and add up: the slanted cards and the terminal list both writelibrary.setCard, so a theme picks one. - Class names are one namespace per theme. Two recipes that define
.panelor.headdifferently collide when merged. Rename one.
Limits at a glance
| What | Limit | Where it is enforced |
|---|---|---|
theme.ts source |
128 KiB | crates/modding/src/theme.rs (ThemeScriptLimits) |
theme.ts run |
500 ms, 16 MiB, 4 000 nodes built, 1 MiB of JSON | crates/modding/src/theme.rs |
| Validated templates | 24 levels deep, 1 500 nodes per theme, 64 templates, 200 characters per text, 64 children per node, 8 classes per node, 8 entries in data or vars, 12 grid tracks |
crates/themes/src/template/mod.rs |
theme.css |
256 KiB, 2048 rules, 40 declarations per rule, z-index from −50 to 50 |
crates/themes/src/stylesheet.rs |
tokens.css |
64 KiB, 200 declarations, 600 characters per value, 2 @media blocks |
crates/themes/src/css.rs, crates/themes/src/grammar.rs |
| Pictures | 4 MiB each, 512 per theme | crates/themes/src/library.rs |
| Map picture | at least 20 % visible; a --pv-shade layer at most 90 %; brightness() ≥ 0.25, opacity() ≥ 0.4, contrast() ≥ 0.5 |
crates/themes/src/artwork.rs |
| Motion | no infinite animation (a warning) | crates/themes/src/stylesheet.rs |