only render route colours if the value is a valid color

addresses https://github.com/openstreetmap/iD/pull/9424#discussion_r1046495633
This commit is contained in:
Martin Raifer
2023-11-17 13:45:49 +01:00
parent beea585251
commit 20b72a2b68
5 changed files with 21 additions and 14 deletions
+1 -10
View File
@@ -9,6 +9,7 @@ import { t, localizer } from '../../core/localizer';
import { utilDetect, utilGetSetValue, utilNoAuto, utilRebind, utilTotalExtent } from '../../util';
import { svgIcon } from '../../svg/icon';
import { cardinal } from '../../osm/node';
import { isColourValid } from '../../osm/tags';
import { uiLengthIndicator } from '..';
import { uiTooltip } from '../tooltip';
import { isEqual } from 'lodash-es';
@@ -228,16 +229,6 @@ export function uiFieldText(field, context) {
function updateColourPreview() {
function isColourValid(colour) {
if (!colour.match(/^(#([0-9a-fA-F]{3}){1,2}|\w+)$/)) {
// OSM only supports hex or named colors
return false;
} else if (!CSS.supports('color', colour) || ['unset', 'inherit', 'initial', 'revert'].includes(colour)) {
// see https://stackoverflow.com/a/68217760/1627467
return false;
}
return true;
}
wrap.selectAll('.colour-preview')
.remove();