MCPcopy Create free account
hub / github.com/adobe/react-spectrum / toHSB

Method toHSB

packages/react-stately/src/color/Color.ts:703–714  ·  view source on GitHub ↗

* Converts a HSL color to HSB. * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV. * * @returns An HSBColor object.

()

Source from the content-addressed store, hash-verified

701 * @returns An HSBColor object.
702 */
703 private toHSB(): IColor {
704 let saturation = this.saturation / 100;
705 let lightness = this.lightness / 100;
706 let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);
707 saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);
708 return new HSBColor(
709 toFixedNumber(this.hue, 2),
710 toFixedNumber(saturation * 100, 2),
711 toFixedNumber(brightness * 100, 2),
712 this.alpha
713 );
714 }
715
716 /**
717 * Converts a HSL color to RGB. Conversion formula adapted from

Callers 1

toFormatMethod · 0.95

Calls 1

toFixedNumberFunction · 0.90

Tested by

no test coverage detected