Skip to main content

@mapcairn/theme

MapCairn's typed design tokens, light and dark themes, and contrast checks; plain CSS, no plugin needed.

Checked against version 0.2.0. Install it with npm install @mapcairn/theme; import from @mapcairn/theme.

Tokens​

  • focusRing: Two-tone focus ring for every interactive element and the focused map.
  • mapOverlayTokens: The CSS variable references for everything drawn over the map: pin, measure line and fill, accuracy circle, halo, loading indicator and tile-error banner.
  • surfaceBlurStyle: Surface styling for floating chrome: the translucent surface colour with its backdrop blur, with the -webkit- spelling Safari needs.
  • surfaceBlurSupported: The support test for backdrop-filter in both spellings.
  • tokens: The whole token contract: every custom property that components may read.
  • tokenValues: Every design-token value as plain typed data: the oklch colours, spacing, sizes and type scale that tokens turns into CSS custom properties.

Functions​

  • checkThemeContrast: Checks a proposed theme against WCAG 2.2 AA: 4.5:1 for text, 3:1 for icons, control edges, selection and the focus ring.
  • compositeOver: Composites foreground over backdrop in gamma-encoded sRGB, which is what browsers do for rgba() and oklch(...
  • contrastRatio: WCAG contrast ratio, from 1 to 21, between two opaque colours.
  • createThemeStylesheet: Generates the stylesheet that applies a colour override to the SDK's interface inside options.scope, or refuses.
  • parseColour: Parses a hex, rgb()/rgba() or oklch() colour to gamma-encoded sRGB.
  • toHex: Formats a colour as #rrggbb, or #rrggbbaa when it is translucent.
  • zLayer: The z-index variable for a named layer, bottom to top: map, mapOverlay, chrome, chromeRaised, sheet, toolbar, popover, toast.

Constants​

  • blur_2: The backdrop blur applied behind translucent surfaces, or none when they are opaque.

Types​

  • BackdropName: Name of one of the representative map backdrops: white, black, a light map and the land colours of the light and dark default basemaps.
  • ColourInput: A colour as the token files write it, or one already parsed.
  • ContrastBackground: The colour a pair's foreground sits on.
  • ContrastFinding: The measured contrast of one pair, in one theme, over one backdrop.
  • InvalidColour: A proposed colour that was not checked, so its pairs are missing from the findings.
  • InvalidColourReason: Why a proposed colour could not be checked.
  • PairKind: What a pair's foreground is: text, or a non-text mark such as an edge or ring.
  • Rgba: A colour in gamma-encoded sRGB.
  • ThemeColourRole: The interface colour roles a host may override, and so the roles a finding's foreground can name.
  • ThemeColours: The interface colour roles a host may override.
  • ThemeContrastCheck: The result of checkThemeContrast.
  • ThemeName: The two themes.
  • ThemeOverride: A proposed theme: some colour roles, per theme.
  • ThemeStylesheet: The result of createThemeStylesheet.
  • ThemeStylesheetCreated: A theme override that was accepted: the stylesheet and what was measured.
  • ThemeStylesheetOptions: Where a theme override applies.
  • ThemeStylesheetRefused: A theme override that was refused, with the reasons and no stylesheet.
  • ZLayerName: Name of a z layer.