Skip to main content

createThemeStylesheet

Generates the stylesheet that applies a colour override to the SDK's interface inside options.scope, or refuses.

This is a function exported by @mapcairn/theme, checked against version 0.2.0.

Signature​

import { createThemeStylesheet } from "@mapcairn/theme";

function createThemeStylesheet(override: ThemeOverride, options: ThemeStylesheetOptions): ThemeStylesheet;

Description​

The host serves the result as a same-origin file, linked after the SDK's own stylesheet: it holds no inline style, needs no nonce and shows no flash under a strict policy. The names it writes are resolved from the built tokens, so they match the SDK's stylesheet only for the same installed version of this package, and the host never writes one.

A theme below WCAG 2.2 AA is refused: the result carries the findings and no CSS, so a host fixes its colours first. The check measures the colours as written to the stylesheet, with the inner focus ring and the opaque surfaces derived. The opaque surface is the surface flattened over the theme's page background, used where backdrop-filter is not supported and under prefers-reduced-transparency. The page background, the map overlay roles and the data palette are not overridable.

Every rule is written for (not (prefers-contrast: more)) and (not (forced-colors: active)), so high-contrast and forced-colours users keep the SDK's own values. A colour is written back as #rrggbb or #rrggbbaa, parsed with the same strict reader as checkThemeContrast, so nothing else can enter the stylesheet.

shape (square, default or round) sets the pill, sheet, control and inner radii once for the scope, in the same rule as the font. default writes nothing. The circular role stays circular and the round preset keeps the search pill a pill. Any other value refuses the override, listed in invalid with the role shape. The browser tests check every chrome state at phone, tablet and desktop sizes in both themes for each preset, so nothing overlaps and no corner cuts text, an icon, a field or a focus ring.

fontFamily is written once for the scope, outside those conditions, since a typeface does not change with the theme or with high contrast. It must be a list of plain family names and generic families; anything else refuses the override, listed in invalid. The SDK's own stack follows the list as its fallback. The host loads the font file: it must be same-origin or allowed by the host's font-src, and the stylesheet must be linked, because a strict policy blocks an inline <style>. How wide a font is cannot be known here, so the layout holds instead: the browser tests put a deliberately wide face on the chrome and check that no control gets smaller and nothing overlaps. Text in a control may be cut short.

Total: it never throws. A tooltip renders in a portal outside the scope, so it keeps the SDK's colours in a #id or .class scope.

Parameters​

  • override (ThemeOverride): The colours to change, per theme, and the font family.
  • options (ThemeStylesheetOptions): The scope to apply them in.

Returns​

ThemeStylesheet: The stylesheet and the findings, or the reasons it was refused.

See also​

Source: packages/theme/src/createThemeStylesheet.ts:433