Turns a CSS colour into a key safe for a MapLibre image id.
Runs of non-alphanumeric characters collapse to a single -, so the key can
never itself contain the -- separator: #6A1B9A → 6a1b9a,
rgb(255, 0, 0) → rgb-255-0-0. Collapsing runs (rather than stripping them)
keeps distinct colours distinct — stripping would fold rgb(255,0,0) and
rgb(25,50,0) onto the same key.
Parameters
color: string
Any CSS colour string.
Returns string|null
The id-safe key, or null when nothing usable remains.
Turns a CSS colour into a key safe for a MapLibre image id.
Runs of non-alphanumeric characters collapse to a single
-, so the key can never itself contain the--separator:#6A1B9A→6a1b9a,rgb(255, 0, 0)→rgb-255-0-0. Collapsing runs (rather than stripping them) keeps distinct colours distinct — stripping would foldrgb(255,0,0)andrgb(25,50,0)onto the same key.