UNPKG

@kcuf/mere-color

Version:

Mere color utils for generating, manipulation, a11y purposes.

21 lines (20 loc) 495 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = rgbToHsv; function rgbToHsv(rgb) { var r = rgb.r, g = rgb.g, b = rgb.b, a = rgb.a; var max = Math.max(r, g, b); var delta = max - Math.min(r, g, b); var hh = delta ? max === r ? (g - b) / delta : max === g ? 2 + (b - r) / delta : 4 + (r - g) / delta : 0; return { h: 60 * (hh < 0 ? hh + 6 : hh), s: max ? delta / max * 100 : 0, v: max / 255 * 100, a: a }; }