-
Notifications
You must be signed in to change notification settings - Fork 6
/
colorConvert.min.js
1 lines (1 loc) · 2.08 KB
/
colorConvert.min.js
1
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).colorConvert={})}(this,(function(e){"use strict";e.hex2rgb=function(e){var r=null;8===(e=e.replace(/^#/,"")).length&&(r=parseInt(e.slice(6,8),16)/255,e=e.slice(0,6)),4===e.length&&(r=parseInt(e.slice(3,4).repeat(2),16)/255,e=e.slice(0,3)),3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]);var t=parseInt(e,16),n=[t>>16,t>>8&255,255&t];return null!==r&&n.push(Math.round(100*r)),n},e.hsl2rgb=function(e,r,t){e/=360,t/=100;var n=0,a=0,o=0,u=0,s=0;function h(e,r,t){return e<1/6?r+6*(t-r)*e:e>=1/6&&e<.5?t:e>=.5&&e<2/3?r+(t-r)*(2/3-e)*6:r}function i(e){return e<0?e+1:e>1?e-1:e}return 0===(r/=100)?n=a=o=t:(u=2*t-(s=t<.5?t*(1+r):t+r-t*r),n=h(i(e+1/3),u,s),a=h(i(e),u,s),o=h(i(e-1/3),u,s)),[Math.round(255*n),Math.round(255*a),Math.round(255*o)]},e.hsv2rgb=function(e,r,t){t/=100;var n=0,a=0,o=0;if(0===(r/=100))n=a=o=t;else{var u=(e/=1)/60,s=Math.floor(u),h=u-s,i=t*(1-r),c=t*(1-h*r),d=t*(1-(1-h)*r);switch(s){case 0:n=t,a=d,o=i;break;case 1:n=c,a=t,o=i;break;case 2:n=i,a=t,o=d;break;case 3:n=i,a=c,o=t;break;case 4:n=d,a=i,o=t;break;case 5:n=t,a=i,o=c}}return[Math.round(255*n),Math.round(255*a),Math.round(255*o)]},e.rgb2hex=function(e,r,t,n){return n=void 0===n?"":(256|(n=Math.round(255*n/100))).toString(16).slice(1),"#"+(t|r<<8|e<<16|1<<24).toString(16).slice(1).toUpperCase()+n.toUpperCase()},e.rgb2hsl=function(e,r,t){e/=255,r/=255,t/=255;var n=Math.max(e,r,t),a=Math.min(e,r,t),o=n-a,u=0,s=(n+a)/2,h=0;return n===a?u=0:n===e&&r>=t?u=(r-t)/o*60:n===e&&r<t?u=(r-t)/o*60+360:n===r?u=(t-e)/o*60+120:n===t&&(u=(e-r)/o*60+240),0===s||n===a?h=0:0<s&&s<=.5?h=o/(2*s):s>.5&&(h=o/(2-2*s)),[Math.round(u),Math.round(100*h),Math.round(100*s)]},e.rgb2hsv=function(e,r,t){e/=255,r/=255,t/=255;var n=Math.max(e,r,t),a=Math.min(e,r,t),o=n-a,u=0,s=n,h=0===n?0:o/n;return n===a?u=0:n===e&&r>=t?u=(r-t)/o*60:n===e&&r<t?u=(r-t)/o*60+360:n===r?u=(t-e)/o*60+120:n===t&&(u=(e-r)/o*60+240),[Math.round(u),Math.round(100*h),Math.round(100*s)]},Object.defineProperty(e,"__esModule",{value:!0})}));