MCPcopy
hub / github.com/adobe/react-spectrum / toRGB

Method toRGB

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

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

()

Source from the content-addressed store, hash-verified

720 * @returns An RGBColor object.
721 */
722 private toRGB(): IColor {
723 let hue = this.hue;
724 let saturation = this.saturation / 100;
725 let lightness = this.lightness / 100;
726 let a = saturation * Math.min(lightness, 1 - lightness);
727 let fn = (n: number, k = (n + hue / 30) % 12) =>
728 lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
729 return new RGBColor(
730 Math.round(fn(0) * 255),
731 Math.round(fn(8) * 255),
732 Math.round(fn(4) * 255),
733 this.alpha
734 );
735 }
736
737 clone(): IColor {
738 return new HSLColor(this.hue, this.saturation, this.lightness, this.alpha);

Callers 2

toStringMethod · 0.95
toFormatMethod · 0.95

Calls 1

fnFunction · 0.85

Tested by

no test coverage detected