Read CSS colour names as the default renderer reads them

cssColor (src/render/color.js) now reads the colour names the default
renderer knows, in any case, upper-cased as it looks them up: its table,
with grey aliases, transparent and its lavendar_blush spelling, and no
rebeccapurple. The local GeoJSON layers read simplestyle fill, stroke and
marker colours through it, so a named colour no longer falls back to the
layer colour; submarine cables read their marker colours the same way.
This commit is contained in:
Sameh Khamis committed 2026-11-07 23:47:04 -08:00
1 parent 38e0750715
commit 85d4f4840c
4 files changed
+236 -7

No files matched your search

+32
View File
@@ -22,11 +22,26 @@ test('CSS colours read as the default renderer reads them', async () => {
'hsl(120, 50%, 25%)',
'hsla(300, 100%, 75%, 0.4)',
'hsl(30, 0%, 40%)',
'red',
' Navy ',
'DARKGREY',
'lightSlateGray',
'transparent',
// Upper-cased as the default renderer does: dotless i and long s
// upper-case to I and S.
'wh\u0131te',
'\u017Fnow',
]) {
const c = Cesium.Color.fromCssColorString(css);
assert.deepEqual(cssColor(css), [c.red, c.green, c.blue, c.alpha], css);
}
assert.equal(cssColor('not a colour'), null);
assert.equal(cssColor('rebeccapurple'), null);
assert.equal(cssColor('lavenderblush'), null);
assert.equal(cssColor('constructor'), null);
assert.equal(cssColor('__proto__'), null);
// The Kelvin sign lower-cases to k, but does not upper-case to K.
assert.equal(cssColor('\u212Ahaki'), null);
assert.equal(cssColor(undefined), null);
});
@@ -44,3 +59,20 @@ test('HSL colours read as the default renderer computes them', async () => {
assert.deepEqual(hslColor(h, s, l, a), [c.red, c.green, c.blue, c.alpha]);
}
});
test('every colour name the default renderer knows reads as it does', async () => {
const Cesium = await import('cesium');
const { cssColor } = await import('./color.js');
const names = Object.keys(Cesium.Color).filter(
(key) => /^[A-Z_]+$/.test(key) && Cesium.Color[key] instanceof Cesium.Color,
);
assert.ok(names.length > 140);
for (const name of names) {
const c = Cesium.Color.fromCssColorString(name.toLowerCase());
assert.deepEqual(
cssColor(name.toLowerCase()),
[c.red, c.green, c.blue, c.alpha],
name,
);
}
});