jc-color
Version:
A JavaScript tool for color compute and console print tool both for NodeJS and Browser.
1 lines • 998 B
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.channelsToHsl=exports.hexToHsl=exports.rgbToHsl=void 0;const types_1=require("../types"),toChannels_1=require("./toChannels"),jc_utils_1=require("@jcstdio/jc-utils");function channelsToHsl(e){var s=e.red/255,o=e.green/255,e=e.blue/255,r=Math.max(s,o,e),t=Math.min(s,o,e);let l=0,n=0;var a=(r+t)/2,t=r-t,r=(0!=t&&(n=t/(1-Math.abs(2*a-1)),l=r===s?(o-e)/t%6:r===o?(e-s)/t+2:(s-o)/t+4,(l*=60)<0)&&(l+=360),`hsl(${l.toFixed()}, ${(100*n).toFixed()}%, ${(100*a).toFixed()}%)`);return r}function rgbToHsl(e){if((0,types_1.isRgbColor)(e))return channelsToHsl((0,toChannels_1.rgbToChannels)(e));throw(0,jc_utils_1.ValueError)("param val must be a rgb color string")}function hexToHsl(e){if((0,types_1.isHexColor)(e))return channelsToHsl((0,toChannels_1.hexToChannels)(e));throw(0,jc_utils_1.ValueError)("param val must be a hex color string")}exports.channelsToHsl=channelsToHsl,exports.rgbToHsl=rgbToHsl,exports.hexToHsl=hexToHsl;