UNPKG

@giro3d/giro3d

Version:

A JS/WebGL framework for 3D geospatial data visualization

20 lines (17 loc) 674 B
/* * Copyright (c) 2015-2018, IGN France. * Copyright (c) 2018-2026, Giro3D team. * SPDX-License-Identifier: MIT */ import { Color } from 'three'; import { isColor } from './predicates'; // See https://www.codeproject.com/Articles/16565/Determining-Ideal-Text-Color-Based-on-Specified-Ba /** * Returns a hex color (including the leading #) that contrasts with the input color. */ export function getContrastColor(color) { const c = isColor(color) ? color : new Color(color); // Find a text color with enough contrast from the background color const bgDelta = c.r * 0.299 + c.g * 0.587 + c.b * 0.114; return 1 - bgDelta < 105 / 255 ? '#000000' : '#ffffff'; }