Skip to content

feat(map): brand-colour the map markers and cluster paints #17

Description

@Ardnived

Summary

The brand palette themes the widget's React UI and stops at the map. The four marker images carry hard-coded fills (src/components/organisms/Mapbox/markers.ts:20-25), and two paints are hard-coded hex (layers.ts:29, layers.ts:116). So a maroon-branded tenant still gets teal pins. This brings the tenant's resolved palette into the markers and those two paints. The basemap styles stay out of scope.

Approach

The markers are app-owned SVGs already, built by pin(fill) and cluster(fill, ring) in markers.ts and rasterised from an inline data: URI. No SDF work is needed, and icon-color is not used.

1. Publish the resolved palette (src/config/theme/)

BrandTheme.tsx:31-47 resolves the palette per role (embed prop → client record color1/color2/color3 → built-in default) and paints it as CSS variables, but keeps the resolved object local. Add a zustand store beside it, set from the existing useLayoutEffect (BrandTheme.tsx:50-54), so the map reads the same PaletteRoles the UI was painted from. Precedent for a co-located store: usePaddingState (src/hooks/use-mapbox.ts:14).

Do not read the variables back with getComputedStyle: the map would then need its own change signal, and a role that fell back to the default writes no variable at all (palette.ts:207).

2. Hex accessors in palette.ts

buildScale returns HSL channel strings ('184 58% 28%'), which neither an SVG fill attribute nor a Mapbox paint accepts. Export two helpers from src/config/theme/palette.ts, so colord stays confined to that file:

  • stepHex(seedHex, mode, step) → #rrggbb
  • onHex(seedHex, mode) → the readable on-colour for step 9, as hex

3. Derive the marker colours

markers.ts takes a colour tuple instead of reading its module constants. For a role whose seed passes isBrandSeed (palette.ts:171-175):

image fill ring
sy-point primary step 9 —
sy-point-selected contrast step 9 —
sy-cluster primary step 9 its fill, L +21, S −16
sy-cluster-selected contrast step 9 its fill, L +21, S −16

Clamp ring L to ≤ 92 and S to ≥ 0. The Studio art's own two fill→ring deltas disagree (+21/−16 for the unselected pair, +9/+9 for the selected one), so one transform replaces both. The default never runs it.

⚠ The default must bypass derivation entirely, or the unbranded pin changes colour. Measured:

today primary/contrast step 9, light step 9, dark
sy-point #21C1A2 = hsl(168 71% 44%) hsl(184 58% 28%) hsl(184 58% 60%)
sy-point-selected #E87952 = hsl(16 77% 62%) hsl(12 60% 68%) hsl(12 60% 68%)

DEFAULT_SEEDS.primary is #1E6C71, a dark teal: its step 9 is 16pp darker and 16° bluer than today's pin, and in dark mode 16pp lighter — while today's pin is identical in both modes. So a role with no tenant seed keeps the constants at markers.ts:20-25 verbatim. This mirrors applyPalette's own contract (palette.ts:21-22): with no palette supplied, none of the derivation runs. isBrandSeed already rejects the #000000 that the client record defaults color1–color3 to, so an unconfigured tenant takes that same path.

A tenant's pins do track light/dark, because step 9 is mode-aware. That is the intent: it is what keeps a dark-seeded brand legible on the dark basemap.

4. Key the cache by colour, and update in place

decoded, decoding and failed (markers.ts:107-122) are keyed by image id. Key them by id plus the colour tuple. Keep them module-level, and keep the synchronous warm path: styleimagemissing must still be served inside the event, or the new style's first frame paints pinless (markers.ts:98-106).

add (markers.ts:172-199) returns early on map.hasImage(id), so a palette change alone registers nothing new. Track which tuple each id is registered with, and call map.updateImage(id, image) when it differs — the dimensions never change, so updateImage is the right call, and a second addImage on a live id makes Mapbox fire an error event instead.

registerMarkerImages(map) takes the tuple, and the effect at Map.tsx:275-277 adds it to its dependency list. The tuple already encodes the mode, so that one dependency covers both a palette change and a light/dark flip. The cache holds at most one entry per image per mode — eight per embed — so it needs no eviction.

5. layers.ts:29 and :116 become palette functions

  • clusterLayer → a factory. paint['text-color'] becomes the on-colour of the cluster fill's ramp (onHex), defaulting to #FFFFFF.
  • boundsLayer → a factory. paint['line-color'] comes from the primary ramp, defaulting to #888.

The other five exports carry no colour paint — leave them constants.

Map.tsx reads clusterLayer.id and unclusteredPointLayer.id at :381, :394 and :445 (interactiveLayerIds). Export a LAYER_IDS constant and read the ids from it, so the ids stay stable and interactiveLayerIds keeps a stable array identity. Memoise both factory results with useMemo on the tuple — docs/rules/mapbox.md forbids a fresh paint object per render.

boundsLayer renders only behind DEBUG_BOUNDARY = false (Map.tsx:101), so there is nothing to look at. Assert it in a spec instead.

6. Docs a host or a later run reads

  • docs/rules/mapbox.md — its markers section describes the registration mechanism, which now carries colours.
  • CHANGELOG.md [Unreleased] — a tenant's pins changing colour is host-observable.
  • docs/embedding.md — beside the brand-colours row (line 239), say the map's markers and cluster counts follow the client record's colours. No new origin and no new attribute, so the CSP table is unchanged.

Acceptance criteria

  • With no tenant seed, the four marker SVG strings are byte-identical to today's, in light and dark.
  • With a tenant seed, the pin and cluster fills derive from primary step 9 and the selected pair from contrast step 9, for the active mode.
  • The cluster count text and the bounds line colour come from the resolved palette, defaulting to #FFFFFF and #888.
  • A palette change repaints the registered marker images without a style reload.
  • A light/dark switch still has pins on the new style's first frame.
  • Layer ids are unchanged, and clustering, cluster expansion, pin navigation, selection and the card-hover highlight are unregressed.
  • No SDF assets, no icon-color, and no change to MAP_STYLES.
  • docs/rules/mapbox.md, CHANGELOG.md and docs/embedding.md updated.
  • The resolved palette reaches the map as React context, not the zustand store § 1 names — the value's lifetime is then the painter's, with no retraction to keep right (review, Ardnived, 2026-11-02)

Verification checklist

  • pnpm test:run src/components/organisms/Mapbox src/config/theme
  • A new node-lane spec src/components/organisms/Mapbox/markers.test.ts asserts the four default SVG strings against the constants named above, and the derived hexes for primary: '#64032e'. markers.ts must stay importable without a DOM (markers.ts:105-106), so the colour builder stays pure.
  • A new spec asserts clusterLayer(default).paint['text-color'] === '#FFFFFF', boundsLayer(default).paint['line-color'] === '#888', and that every LAYER_IDS value equals today's string.
  • .claude/skills/pr-prep/check.sh
  • pnpm build && pnpm size — colord is already eager through BrandTheme, so the budget should not move.
  • A BrandedMarkers story in Mapbox.stories.tsx wraps Mapbox in BrandTheme with palette={{ primary: '#64032e', contrast: '#64032e' }}. With VITE_MAPBOX_ACCESSTOKEN set, pnpm ladle shows maroon pins and clusters there, and today's teal and orange in the Default story.

Notes

Re-scoped on 2026-11-01. The markers stopped being Studio sprites when the widget took them over, so addImage(…, { sdf: true }) and icon-color are no longer needed. Per-tenant basemap styles and basemap tinting are dropped.

Nothing passes App's brand prop today (App.tsx:111, :204), so the only live palette source is the client record for the API key. That is why the Ladle story is the manual check.

The card-hover highlight reuses the selected marker images (layers.ts:69-74), so it follows the brand with no dedicated hover image. That comment's "one can land with #17" is out of scope here.

Activity

  1. added theissue type on Aug 28, 2026
  2. Ardnived commented on Sep 8, 2026

    @Ardnived
    ContributorAuthor

    Parked until 2026-10-02 (migrated from the retired Hold Until field). The loop mentions @Ardnived when that date passes.

  3. 37 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    Priority

    Low

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions