Skip to main content

Tokens

Part of Design system, which is built from DESIGN.md in the repository, where it is edited.

The colours, type, spacing and other values the interface is built from.

  • Colour roles: surface, surface-raised, text, text-muted, accent, accent-tint, hairline, danger, scrim, focus-ring, page-background, map-background, map-globe-space. The neutral ramp is OKLCH with a faint cool tint. The accent is one clear blue. Page-background follows the theme and sits behind full pages such as the privacy policy. Map-background is the land colour of the theme's default basemap, Bright's in the light theme and Fiord's in the dark theme, so the map region before the map draws matches the map that follows for a visitor who has not chosen another basemap. A visitor who chose one sees that colour only until it draws. Map-globe-space is the space around the sphere when the map is a globe, and only then: a cool mid grey in the light theme (oklch(0.82 0.02 250)), dark enough that pale land at the edge of the globe still shows and light enough to sit with the light chrome, and a dark blue in the dark theme (oklch(0.31 0.025 255)), dark against the dark chrome yet lighter and bluer than the near-black Dark basemap, so its edge shows too. A test keeps it at 1.2:1 or more against the land of every built-in basemap, and the chrome text over it at 4.5:1.

  • Basemap: the default basemap follows the theme until the visitor chooses one: Bright in the light theme, Fiord in the dark theme, so dark controls sit over a dark map on a first visit. A basemap the visitor has chosen never changes by itself: it stays across theme changes and reloads, and pressing the tile that is already shown counts as choosing it. A visitor who never chose follows the theme live, so switching the theme switches the map. Nothing is saved until a choice, so an old saved "auto" or a removed id is no choice. A shared link names the basemap that was showing, so the same link shows the same map to everyone, whatever their theme; a link with no basemap, such as one typed by hand, shows the viewer's own default. Links made before this rule named Bright, so they still open on Bright in either theme. A reload keeps the basemap the address names, so a visitor who never chose and reloads in the other theme sees the map the address names, not their theme's default; the next theme change drops it and following resumes. The picker offers what the host supplies. The reference host offers six, in this order: Bright (the light theme's default), Liberty, Positron, Streets, Fiord and Dark, as manual choices like any other. They sit in a grid of three columns: Bright, Liberty and Positron on the first row, and Streets, Fiord and Dark on the second. The SDK defines seven (BASEMAPS): the six the host offers, and Colorful, which a host may offer. The reference host builds its own catalogue from a subset of the SDK's list, to ask fewer volunteer-run servers for tiles and to keep the picker short. The reference site once offered Topographic and Satellite; both were removed, Topographic because its provider is volunteer-run with no availability guarantee, and Satellite because its imagery is licensed for non-commercial use only. A saved or linked id the host does not offer (colorful, the removed satellite or topographic, the old "auto", or the retired maptoolkit-dark) shows the default for the viewer's theme, and a saved value is left alone. Dark is OpenFreeMap's neutral dark style, and it asks for no more than the credit text the other OpenFreeMap styles carry. Fiord is OpenFreeMap's blue-toned dark style, the default in the dark theme, and asks for the same credit text. Its land colour, #45516e, is a mid-dark blue-grey that is neither contrast extreme, so it is a backdrop of its own in the contrast tests. All of the interface is checked over it in both themes, because light chrome over Fiord happens when a visitor picks it in the light theme, and dark chrome over Bright when they pick Bright in the dark theme. A tile with no swatch of its own shows the light default's land colour in either theme, wherever it shows a plain swatch (no preview image, or a preview that failed to load). In the SDK, Colorful is VersaTiles' style, from a provider other than OpenFreeMap, which carries its credit text (OpenStreetMap contributors, VersaTiles, ESA WorldCover 2021 and the CC BY 4.0 licence it is under) and nothing else; its land colour is the default's, so it needs no swatch. A basemap with no preview image, or whose preview image fails to load, shows a plain swatch. The SDK's definitions name no preview at all, so a host that serves none shows a swatch for each of them; the reference host adds previews for the six it offers (BASEMAP_THUMBNAILS in packages/web/src/basemaps/basemapThumbnails.ts). A definition may set swatch, a hex colour for that tile, so a dark basemap does not look like the pale default: Dark's and Fiord's are their styles' own land colours. The picker applies it with a custom property set through CSSOM, never an inline style attribute. On it, the selected tile's check badge stays legible in both themes (the tick on the accent disc, and the disc or its raised-surface ring against the swatch, at least 3:1), and the name sits below the tile on the sheet. The SDK carries no provider whose licence it would have to accept; a host adds one as data (see ARCHITECTURE.md, host-supplied basemaps).

  • Map overlays: the pin, the measure line, the vertices and handles of drawn shapes and the accuracy circle draw in the theme's overlay colours: accent-600 with a white halo in the light theme, accent-400 with the near-black surface halo in the dark theme. The pin, every line and the accuracy outline are drawn on a halo (a wider stroke of the halo colour beneath them). Over a basemap each shows when the mark or its halo reaches 3:1 against the land and the mark reaches 3:1 against its halo, which the token tests check over white, black, a light map, Bright and Fiord in both themes. Only a role the map draws on a halo gets that credit in the tests; a mark drawn without one must reach 3:1 against the map itself. A saved image always uses the light theme's colours, because its white halo shows on every basemap, and its credits strip is white with dark text on any of them. Data layers draw with the data palette, whose dark edge and white halo carry them over any basemap.

  • Data palette: the one set of colours data layers draw with, separate from the interface roles. Seven Okabe-Ito categorical colours (without black) and a five-step ordered ramp, light to dark, in tokenValues.dataPalette. Definitions name a slot (vermillion, ordinal-3), never a value; categories must use categorical slots and steps ordinal ones. Every marker has a dark edge inside a white halo (tokenValues.dataMarker), the same on the map and in the legend, so the pale steps show on a light map and the dark ones on a dark surface; contrast tests cover both. Validation refuses a colour rule with no shape, size or words beside it.

  • Syntax palette: the colours of highlighted code on the documentation site, in tokenValues.syntaxPalette for each theme. It is the one exception to the one-accent rule, for code only: the interface, the map and every other page keep one accent. Nine roles, each its own muted hue so a reader tells them apart without the accent alone: keyword (purple), string (green), number (rust), function (the accent blue), class name (teal), property (gold), and comment, punctuation and operator from the neutral ramp, with comments italic and lower in emphasis than punctuation. The background is not a role: a code block sits on surfaceRaised over the page background, and a highlighted line on accentTint over that (--docusaurus-highlighted-code-line-bg), so nothing here adds a surface colour. Added hues have chroma 0.12 or less. sites/docs/scripts/syntaxCss.ts writes each role as --mc-syntax-<role> (generated, git-ignored), and custom.css maps the highlighter's token classes onto them. syntaxPalette.test.ts holds every role to 4.5:1 on the code block and on a highlighted line in the default, opaque and prefers-contrast: more colour sets, in both themes, and requires five or more hues. Contrast in the default set (code block, highlighted line):

    RoleLight valueLightDark valueDark
    Keywordoklch(0.45 0.12 305)7.8 and 6.4oklch(0.8 0.1 305)8.3 and 7.1
    Stringoklch(0.45 0.09 155)7.1 and 5.8oklch(0.82 0.1 155)9.6 and 8.1
    Numberoklch(0.47 0.1 40)7.1 and 5.8oklch(0.82 0.1 40)8.9 and 7.6
    Functionaccent 7007.2 and 5.9accent 3008.6 and 7.3
    Class nameoklch(0.45 0.08 200)7.1 and 5.8oklch(0.82 0.08 200)9.5 and 8.1
    Propertyoklch(0.45 0.08 100)7.3 and 6.0oklch(0.84 0.09 100)9.9 and 8.4
    Commentoklch(0.49 0.012 250)6.2 and 5.1neutral 4007.0 and 5.9
    Punctuationneutral 7007.7 and 6.3neutral 30010.5 and 8.9
    Operatorneutral 80011.6 and 9.6neutral 20012.5 and 10.6
  • Surfaces: translucent with backdrop blur, at most a tenth of the map showing through (the surface colour is 92 percent opaque in both themes), so place names under a panel cannot be read through its text, with an opaque fallback and the -webkit- prefix. prefers-contrast: more and prefers-reduced-transparency make them opaque and remove blur. Contrast is computed over the worst-case backdrops (pure white and pure black map) and over the land colour of both default basemaps, Bright's and Fiord's, because either theme can sit over either map once a visitor chooses one, and Fiord's mid-tone is the worst case for some colours.

  • Checking a host's colours: checkThemeContrast(override) in @mapcairn/theme takes a partial override of 14 interface roles (surface, surfaceRaised, text, textMuted, accent, accentTint, accentContrast, hairline, controlBoundary, danger, dangerTint, scrim, focusRing, focusRingInner) for light and dark. A role left out keeps its default. It returns data, never throws and never decides whether a theme is accepted: one finding for each pair, theme and backdrop (the ratio, the minimum, the backdrop and whether it passes), plus a list of colours it could not check (unparseable, an oklch() colour outside the sRGB gamut, translucent where the role must be opaque, not an overridable role, or an object that throws when read). The parser reads numbers and percentages strictly and clamps out-of-range components as CSS does; it refuses keywords such as none, empty or extra arguments, a slash or comma in the wrong place and angle units other than degrees. Only hex, rgb()/rgba() and oklch() are supported; named colours, hsl(), oklab() and color() are reported as unparseable. An override that is not a plain object, a section that is not, or a key that is not part of the shape is reported too, never passed. The minimums are WCAG 2.2 AA: 4.5:1 for text, 3:1 for control edges, the focus ring and its inner ring; hairlines and the scrim are exempt. Translucent surfaces are flattened over white, black, a light map and the land colour of each theme's default basemap (Bright's and Fiord's). On the bare map the focus ring is judged by its better tone: it passes when the outer or the inner tone reaches 3:1. Muted text is held to 4.5:1 and the control edge to 3:1 on the accent tint, as a selected list row and a switch hover draw them. Text, muted text and the accent are also held to 4.5:1 on the page background, and text to 4.5:1 on the map halo; those two backgrounds are not overridable, so they stay at their defaults. Only the default colour set is checked. The pair table is internal (packages/theme/src/contrastPairs.ts), shared with the token tests in contrast.test.ts. The function only checks; createThemeStylesheet below applies an override.

  • Applying a host's colours: createThemeStylesheet(override, { scope }) in @mapcairn/theme turns the same override into a stylesheet, or refuses. A theme below WCAG 2.2 AA is refused: the result has ok: false, no CSS and the findings (and the colours or scope it could not use), so a host fixes its colours first. A theme that passes returns ok: true, the CSS and the findings. The host serves the CSS as a same-origin file and links it after tokens.css and styles.css, so it needs no inline style, no nonce and shows no flash. The scope is the selector of an element the host owns around the SDK's interface (:root, #id or .class, ASCII only; anything else is refused), and the SDK adds no markup or attribute for it. Two scopes are two calls and two independent stylesheets. The rules read data-theme on the root element, or the operating system's colour scheme when there is none, in four contexts that never overlap, so a role set for light only does not show in dark. Every rule is inside (not (prefers-contrast: more)) and (not (forced-colors: active)), so in high-contrast and forced-colours modes the SDK's own values apply. Each colour is parsed with the strict reader above and written back as #rrggbb or #rrggbbaa, and the check runs on the written values, so no other text reaches the stylesheet. Where the surface is translucent the generator also writes an opaque surface, the surface flattened over the theme's page background, for browsers without backdrop-filter and for prefers-reduced-transparency, and sets the inner focus ring to it unless the host chose one; both are checked too. The page background, the map overlay roles and the data palette cannot be overridden, and neither can anything but colour, the font family and the corner preset. fontFamily is a closed list of plain family names, quoted or not, and generic families, so no brace, semicolon, url(), var(), comment or newline reaches the sheet; it is written once for the scope, outside the high-contrast conditions, with the SDK's stack after it as the fallback, through the same private name as the typeface token. The host loads the font file, from its own origin or an origin its font-src allows. A font's width cannot be known when the stylesheet is made, so the layout is tested instead: packages/web/e2e/theme-font.spec.ts puts a deliberately wide face on the chrome at 320 and 390 px in both themes and checks that no control gets smaller than it is with the SDK's font and that nothing overlaps; text in a control may be cut short. The tooltip, which renders in a portal, copies the font family from its trigger as it does the colours. The custom property names are build hashes the generator reads from tokens; they match the SDK's stylesheet only when both come from the same installed @mapcairn/theme, and they are not public. A tooltip renders in a portal under body, outside the host's scope, so it copies the colour properties its trigger sees onto the bubble when it opens (inheritTheme, through the style object, which the strict policy allows); the host does nothing for it, and it is the only component that renders in a portal. A portal added later must do the same. The steps for a host are in Theme the SDK with your own colours.

  • Spacing: 4, 8, 12, 16, 24, 32. Screen inset is 12.

  • Radii: pill 24, sheet 20, control and card 14, inner 10. Fully circular elements use 50%. A host can choose a square or round preset with shape in createThemeStylesheet, which sets those four radii for its scope: square is 4, 4, 2 and 2; round is 24 (still a pill, half the 48px search row), 28, 22 and 16, so no radius reaches past half a control's 44px minimum height. The circular role is never changed. packages/web/e2e/theme-shape.spec.ts walks every chrome state at phone, tablet and desktop sizes in both themes for each preset and checks that nothing overlaps, no control gets smaller and no corner cuts text, an icon, a field or a focus ring; the tooltip copies the radii from its trigger like the colours.

  • Elevation: two shadows, floating and sheet, each with light and dark values. No borders on floating elements. Hairlines only inside lists and between grouped controls.

  • Type: IBM Plex Sans only, self-hosted through Fontsource (variable, Latin and Latin Extended), weights 400 and 600. Sizes 13, 15, 17 and 22, defined in rem with a line height and tracking each, and one display size, 40 (type.display), for the heading of a full page that is not the map (the product page's h1, which scales between the title and display sizes with the viewport); the map's chrome never uses it. Code samples, and nothing else, use type.familyMono, the system's own monospaced faces, so no second web font is downloaded. Nothing below 13px. Numbers use tabular-nums. Inputs are 17px, never below 16px. The stack puts a metric-matched fallback face, IBM Plex Sans Fallback, right after Plex. It has no font file: a local() face over Arial or Liberation Sans with size-adjust and metric overrides derived from Plex's metrics, so the swap to Plex moves the layout very little. It is declared once, in packages/theme/src/tokens.css.ts, so @mapcairn/theme/tokens.css ships it to every app and the host declares none of its own; tokens.css.test.ts checks that the face and the stack name the same family. The rest of the fallback stack is system-ui, -apple-system, "Segoe UI", Roboto, sans-serif, which also covers non-Latin place names. The scale is script-aware: tracking is negative on the large, title and display steps and line heights are tight, which suit Latin text and break Arabic joining and Indic conjuncts. Text whose lang is in tokenValues.nonLatinLanguages (Arabic-script, Hebrew, Indic, Thai, Lao, Khmer, Burmese, Amharic, Georgian, Armenian, Japanese, Korean and Chinese) reads the type.nonLatin tokens instead: tracking 0em (small's 0.01em is zeroed too, since any letter spacing breaks joining) and a line height of 1.6 on small, body and large and 1.5 on title and display, applied by one :lang() rule that sets the variables on the element carrying the language. Latin output is unchanged, except that custom properties inherit, so a Latin span inside a listed language keeps the looser values, which is harmless. The list is not exhaustive and a host adds rules for others. The SDK ships no non-Latin font; a host sets type.family (and, if it wants other values, type.nonLatin) under its own :lang() rule, as sites/docs/docs/guides/translate-the-sdk.md shows, and the theme's rule never sets type.family.

  • Size: controls are 48px minimum, targets never below 44px, switches and slider thumbs included (their hit area is larger than what they draw), with at least 8px between neighbours.

  • Icons: @phosphor-icons/react only, imported by name, 24px, one weight (regular, and fill for a solid heart), through the Icon component.

  • Focus ring: two tones (an inner surface ring and an outer ring, 2px each) so it shows on any basemap. Every interactive element and the focused map use it. In the dark theme the outer tone is accent-400, light enough to show on Fiord's mid-dark land, where the inner tone, the dark surface colour, shows over a white map.

  • Right to left: styles use logical properties only (marginInlineStart, paddingInlineEnd, insetInlineStart, borderStartStartRadius, textAlign: "start"), never left, right or their margin, padding and border forms, and the harmony scanner fails a physical one (logical-property). Layout that has to move sideways with a transform (a slide, a switch thumb, a scale bar) sets it again in the same rule under [dir="rtl"] with the sign reversed; the scanner accepts a horizontal translation, a gradient direction or a transform origin only when its rule has a [dir="rtl"] selector. Use the attribute selector, not :dir(rtl): the build rewrites :dir() into a list of languages, which does not match English text on a right-to-left page. The device safe-area insets are physical (env(safe-area-inset-left)), so safeArea in packages/map/src/chrome/safeArea.ts gives the ltr pair and the rtl pair, set under [dir="rtl"]. The tokens hold no direction. A host that ships a right-to-left language sets dir="rtl" on <html> (with lang), and nothing else in the SDK needs to change; useReadingDirection in @mapcairn/react reads it for the Radix slider and segmented control and for map fitting, and the chrome measures its offsets from the inline-start side. Icons that point along the reading direction, such as a back arrow, a next or previous chevron and undo and redo, mirror: pass mirrorInRtl to Icon, Button or IconButton. Icons that do not, such as a magnifier, a pin, a clock or a vertical chevron, do not. A map direction (the arrow keys panning the map, the compass) stays physical. Text that is not catalogue copy is isolated so it keeps its own order inside right-to-left text: components wrap place names, addresses, feature titles, the scale label, distances and areas, and coordinates in Isolate (figure for the ASCII coordinates). A message's own parameters (a coordinate in "Pin dropped at {position}", a layer name in a sentence, each item of a list) are wrapped by createMessageCatalogue in Unicode first-strong isolates (U+2068 to U+2069) when its language reads right to left, or when the host passes isolateParameters: true; a left-to-right catalogue returns plain strings. The marks are invisible, so a host's tests strip U+2066 to U+2069 from text before an exact-name assertion; a translator writes the same {name} placeholders as before, and no message carries markup. No right-to-left language ships on the reference site, but a host can offer one; the rtl-chromium and rtl-mobile-chromium Playwright projects keep the layout honest (see AGENTS.md).

  • Motion: 120, 200 and 320ms, one easing curve, one spring for the sheet. Only transform and opacity animate. prefers-reduced-motion turns motion off, including MapLibre's own animation.

  • Z layers, bottom to top: map, mapOverlay, chrome, chromeRaised, sheet, toolbar, popover, toast. Components name a layer and never write a number. The tokens file and the map engine style file are the only places raw z-index values may appear.