communication-react-19
Version:
React library for building modern communication user experiences utilizing Azure Communication Services (React 19 compatible fork)
25 lines • 1.02 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @private
*/
export const isDarkThemed = (theme) => {
const themeBlackBrightness = getPerceptualBrightnessOfHexColor(theme.palette.black);
const themeWhiteBrightness = getPerceptualBrightnessOfHexColor(theme.palette.white);
if (Number.isNaN(themeBlackBrightness) || Number.isNaN(themeWhiteBrightness)) {
return false;
}
return themeBlackBrightness > themeWhiteBrightness;
};
const getPerceptualBrightnessOfHexColor = (hexColor) => {
// return NaN if hexColor is not a hex code
if (!/^#[0-9A-Fa-f]{6}$/i.test(hexColor)) {
return NaN;
}
const r = parseInt(hexColor.substring(1, 3), 16);
const g = parseInt(hexColor.substring(3, 5), 16);
const b = parseInt(hexColor.substring(5, 7), 16);
// arithmetic mean μ of the red, green, and blue color coordinates. Source: https://en.wikipedia.org/wiki/Brightness
return (r + g + b) / 3;
};
//# sourceMappingURL=themeUtils.js.map