Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

colortranslator

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colortranslator - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

11

CHANGELOG.md
# Changelog
## [1.1.0] - 2019-07-12
### Added
- Add the possibility to instantiate the class using any of the inputs
- Add 11 public chainable methods and 25 public readonly properties
- Update some demo examples to use the new class, methods, and properties
- Solve a bug with webpack and the clean-webpack-plugin package
- Fix a bug with RGBA and HSLA CSS output
- Change the CSS CMYK output from `device-cmyk` to `cmyk`
## [1.0.5] - 2019-07-05

@@ -4,0 +15,0 @@

2

dist/colortranslator.web.js

@@ -1,1 +0,1 @@

!function(r,t){for(var e in t)r[e]=t[e]}(window,function(r){var t={};function e(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)e.d(n,o,function(t){return r[t]}.bind(null,o));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=2)}([function(r,t,e){"use strict";var n;Object.defineProperty(t,"__esModule",{value:!0}),t.CONST={HEX:"HEX",RGB:"RGB",RGBA:"RGBA",HSL:"HSL",HSLA:"HSLA",CMYK:"CMYK"},t.COLORREGS=((n={})[t.CONST.HEX]=/^#(?:([a-f\d])([a-f\d])([a-f\d])([a-f\d])?|([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?)$/i,n[t.CONST.RGB]=/^rgb\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*\)$/,n[t.CONST.RGBA]=/^rgba\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*,\s*(\d\.?\d*)\s*\)$/,n[t.CONST.HSL]=/^hsl\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%s*\)$/,n[t.CONST.HSLA]=/^hsla\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%\s*,\s*(\d\.?\d*)\s*\)$/,n[t.CONST.CMYK]=/^(?:device-cmyk|cmyk)\s*\(\s*(?:(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)|(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*))\s*\)$/,n),t.PCENT=/^([\d.]+)%$/,t.HEX=/^0x([a-f\d]{1,2})$/i,t.ERRORS={NOT_ACCEPTED_STRING_INPUT:"The provided string color doesn't have a correct format",NOT_ACCEPTED_OBJECT_INPUT:"The provided color object doesn't have the proper keys"}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(0);t.hasProp=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},t.percent=function(r){return n.PCENT.test(""+r)?+(""+r).replace(n.PCENT,"$1"):Math.min(+r,100)},t.getDEC=function(r){return 1===r.length&&(r+=r),parseInt(r,16)},t.getHEX=function(r){var t=parseInt(""+r).toString(16).toUpperCase();return 1===t.length?"0x0"+t:"0x"+t},t.toHEX=function(r){var t=parseInt(""+r).toString(16).toUpperCase();return 1===t.length&&(t="0"+t),t},t.getBase255Number=function(r,t){return void 0===t&&(t=!1),!t&&n.PCENT.test(r)?Math.min(255*+r.replace(n.PCENT,"$1")/100,255):n.HEX.test(r)?3===r.length?t?parseInt(r+r.slice(-1))/255:parseInt(r+r.slice(-1)):t?parseInt(r)/255:parseInt(r):Math.min(+r,t?1:255)},t.getCMYKNumber=function(r){return Math.min(n.PCENT.test(r)?+r.replace(n.PCENT,"$1")/100:+r,1)},t.getOrderedArrayString=function(r){return r.sort().join().toUpperCase()},t.round=function(r,t){void 0===t&&(t=0);var e=Math.pow(10,t);return Math.round(+r*e)/e}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(0),o=e(3),u=e(5),a=function(r,t){return"string"==typeof r&&t||"object"==typeof r&&!t},s=function(r,t,e,n,u){var a=n("string"==typeof r?o.getRGBObjectFromString[t](r):o.getRGBObjectFromObject[t](r));return e?u(a):a},i=function(){function r(){}return r.toRGB=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.RGB,u.CSS.RGB)},r.toRGBA=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.RGBA,u.CSS.RGB)},r.toHEX=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.HEX,u.CSS.HEX)},r.toHEXA=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.HEXA,u.CSS.HEX)},r.toHSL=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return e===n.CONST.HSL&&a(r,t)?r:s(r,e,t,o.translateColor.HSL,u.CSS.HSL)},r.toHSLA=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return e===n.CONST.HSLA&&a(r,t)?r:s(r,e,t,o.translateColor.HSLA,u.CSS.HSL)},r.toCMYK=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return e===n.CONST.CMYK&&a(r,t)?r:s(r,e,t,o.translateColor.CMYK,u.CSS.CMYK)},r}();t.ColorTranslator=i},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(0),o=e(1),u=e(4);t.getColorModel=function(r){return"string"==typeof r?function(r){var t;if(Object.keys(n.CONST).some(function(e){if(n.COLORREGS[e].test(r))return t=e,!0}),!t)throw new Error(n.ERRORS.NOT_ACCEPTED_STRING_INPUT);return t}(r):function(r){var t,e=o.getOrderedArrayString(Object.keys(r));if(Object.keys(n.CONST).some(function(r){if(o.getOrderedArrayString(r.split(""))===e)return t=r,!0}),!t)throw new Error(n.ERRORS.NOT_ACCEPTED_OBJECT_INPUT);return t}(r)},t.getRGBObjectFromString={HEX:function(r){var t=r.match(n.COLORREGS.HEX),e={r:o.getDEC(t[1]||t[5]),g:o.getDEC(t[2]||t[6]),b:o.getDEC(t[3]||t[7])},u=t[4]||t[8];return void 0!==u&&(e.a=o.getDEC(u)/255),e},RGB:function(r){var t=r.match(n.COLORREGS.RGB),e=o.getBase255Number(t[1]||t[4]),u=o.getBase255Number(t[2]||t[5]),a=o.getBase255Number(t[3]||t[6]);return{r:Math.min(e,255),g:Math.min(u,255),b:Math.min(a,255)}},RGBA:function(r){var t=r.match(n.COLORREGS.RGBA),e=o.getBase255Number(t[1]||t[4]),u=o.getBase255Number(t[2]||t[5]),a=o.getBase255Number(t[3]||t[6]),s=+t[7];return{r:Math.min(e,255),g:Math.min(u,255),b:Math.min(a,255),a:isNaN(s)||s>1?1:o.round(s,2)}},HSL:function(r){var t=r.match(n.COLORREGS.HSL),e=+t[1],a=o.percent(t[2]),s=o.percent(t[3]);return u.hslToRGB(e,a,s)},HSLA:function(r){var t=r.match(n.COLORREGS.HSLA),e=+t[4],a=+t[1],s=o.percent(t[2]),i=o.percent(t[3]),d=u.hslToRGB(a,s,i);return d.a=isNaN(e)||e>1?1:o.round(e,2),d},CMYK:function(r){var t=r.match(n.COLORREGS.CMYK),e=o.getCMYKNumber(t[1]||t[5]),a=o.getCMYKNumber(t[2]||t[6]),s=o.getCMYKNumber(t[3]||t[7]),i=o.getCMYKNumber(t[4]||t[8]);return u.cmykToRGB(e,a,s,i)}},t.getRGBObjectFromObject={RGB:function(r){return{r:o.getBase255Number(""+r.r),g:o.getBase255Number(""+r.g),b:o.getBase255Number(""+r.b)}},RGBA:function(r){var t=this.RGB(r);return t.a=o.hasProp(r,"a")?Math.min(o.getBase255Number(""+r.a,!0),1):1,t},HSL:function(r){var t=o.percent(""+r.s),e=o.percent(""+r.l);return u.hslToRGB(r.h,t,e)},HSLA:function(r){var t=this.HSL(r);return t.a=isNaN(+r.a)||+r.a>1?1:o.round(r.a,2),t},CMYK:function(r){var t=o.getCMYKNumber(""+r.c),e=o.getCMYKNumber(""+r.m),n=o.getCMYKNumber(""+r.y),a=o.getCMYKNumber(""+r.k);return u.cmykToRGB(t,e,n,a)}},t.translateColor={HEX:function(r){return{r:o.getHEX(r.r),g:o.getHEX(r.g),b:o.getHEX(r.b)}},HEXA:function(r){var e=t.translateColor.HEX(r);return e.a=o.hasProp(r,"a")?o.getHEX(255*r.a):"0xFF",e},RGB:function(r){return o.hasProp(r,"a")&&delete r.a,r},RGBA:function(r){return r.a=o.hasProp(r,"a")?o.round(r.a,2):1,r},HSL:function(r){var t=u.rgbToHSL(r.r,r.g,r.b);return delete t.a,t},HSLA:function(r){var e=t.translateColor.HSL(r);return e.a=o.hasProp(r,"a")?o.round(r.a,2):1,e},CMYK:function(r){return u.rgbToCMYK(r.r,r.g,r.b)}}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.hueToRGB=function(r,t,e){return e<0&&(e+=6),e>=6&&(e-=6),e<1?Math.round(255*((t-r)*e+r)):e<3?Math.round(255*t):e<4?Math.round(255*((t-r)*(4-e)+r)):Math.round(255*r)},t.hslToRGB=function(r,e,n){r/=60,e/=100;var o=(n/=100)<=.5?n*(e+1):n+e-n*e,u=2*n-o;return{r:t.hueToRGB(u,o,r+2),g:t.hueToRGB(u,o,r),b:t.hueToRGB(u,o,r-2)}},t.cmykToRGB=function(r,t,e,n){return n=1-n,{r:Math.round(255*(1-r)*n),g:Math.round(255*(1-t)*n),b:Math.round(255*(1-e)*n)}},t.rgbToCMYK=function(r,t,e){r/=255,t/=255,e/=255;var n=1-Math.max(r,t,e),o=1-n,u=(o-r)/o,a=(o-t)/o,s=(o-e)/o;return{c:Math.round(100*u),m:Math.round(100*a),y:Math.round(100*s),k:Math.round(100*n)}},t.rgbToHSL=function(r,t,e,n){void 0===n&&(n=1),r/=255,t/=255,e/=255,n=Math.min(n,1);var o=Math.max(r,t,e),u=Math.min(r,t,e),a=o-u,s=0,i=0,d=(o+u)/2;if(0===a)s=0,i=0;else{switch(o){case r:s=(t-e)/a%6;break;case t:s=(e-r)/a+2;break;case e:s=(r-t)/a+4}(s=Math.round(60*s))<0&&(s+=360),i=a/(1-Math.abs(2*d-1))}return{h:s,s:Math.round(100*i),l:Math.round(100*d),a:n}}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(1);t.CSS={HEX:function(r){return"#"+n.toHEX(r.r)+n.toHEX(r.g)+n.toHEX(r.b)+(r.a&&n.toHEX(r.a)||"")},RGB:function(r){return"rgb"+(r.a?"a":"")+"("+n.round(r.r)+","+n.round(r.g)+","+n.round(r.b)+(n.hasProp(r,"a")&&","+n.round(r.a,2)||"")+")"},HSL:function(r){return"hsl"+(r.a?"a":"")+"("+n.round(r.h)+","+n.round(r.s)+"%,"+n.round(r.l)+"%"+(n.hasProp(r,"a")&&","+n.round(r.a,2)||"")+")"},CMYK:function(r){return"device-cmyk("+n.round(r.c)+"%,"+n.round(r.m)+"%,"+n.round(r.y)+"%,"+n.round(r.k)+"%)"}}}]));
!function(t,e){for(var r in e)t[r]=e[r]}(window,function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=3)}([function(t,e,r){"use strict";var n;Object.defineProperty(e,"__esModule",{value:!0}),e.CONST={HEX:"HEX",RGB:"RGB",RGBA:"RGBA",HSL:"HSL",HSLA:"HSLA",CMYK:"CMYK"},e.COLORREGS=((n={})[e.CONST.HEX]=/^#(?:([a-f\d])([a-f\d])([a-f\d])([a-f\d])?|([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?)$/i,n[e.CONST.RGB]=/^rgb\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*\)$/,n[e.CONST.RGBA]=/^rgba\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*,\s*(\d\.?\d*)\s*\)$/,n[e.CONST.HSL]=/^hsl\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%s*\)$/,n[e.CONST.HSLA]=/^hsla\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%\s*,\s*(\d\.?\d*)\s*\)$/,n[e.CONST.CMYK]=/^(?:device-cmyk|cmyk)\s*\(\s*(?:(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)|(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*))\s*\)$/,n),e.PCENT=/^([\d.]+)%$/,e.HEX=/^0x([a-f\d]{1,2})$/i,e.ERRORS={NOT_ACCEPTED_STRING_INPUT:"The provided string color doesn't have a correct format",NOT_ACCEPTED_OBJECT_INPUT:"The provided color object doesn't have the proper keys"}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(0);e.hasProp=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.percent=function(t){return n.PCENT.test(""+t)?+(""+t).replace(n.PCENT,"$1"):Math.min(+t,100)},e.getDEC=function(t){return 1===t.length&&(t+=t),parseInt(t,16)},e.getHEX=function(t){var e=parseInt(""+t).toString(16).toUpperCase();return 1===e.length?"0x0"+e:"0x"+e},e.toHEX=function(t){var e=parseInt(""+t).toString(16).toUpperCase();return 1===e.length&&(e="0"+e),e},e.getBase255Number=function(t,e){return void 0===e&&(e=!1),!e&&n.PCENT.test(t)?Math.min(255*+t.replace(n.PCENT,"$1")/100,255):n.HEX.test(t)?3===t.length?e?parseInt(t+t.slice(-1))/255:parseInt(t+t.slice(-1)):e?parseInt(t)/255:parseInt(t):Math.min(+t,e?1:255)},e.getCMYKNumber=function(t){return Math.min(n.PCENT.test(t)?+t.replace(n.PCENT,"$1")/100:+t,1)},e.getOrderedArrayString=function(t){return t.sort().join().toUpperCase()},e.round=function(t,e){void 0===e&&(e=0);var r=Math.pow(10,e);return Math.round(+t*r)/r},e.minmax=function(t,e,r){return Math.max(e,Math.min(t,r))}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.hueToRGB=function(t,e,r){return r<0&&(r+=6),r>=6&&(r-=6),r<1?Math.round(255*((e-t)*r+t)):r<3?Math.round(255*e):r<4?Math.round(255*((e-t)*(4-r)+t)):Math.round(255*t)},e.hslToRGB=function(t,r,n){t/=60,r/=100;var o=(n/=100)<=.5?n*(r+1):n+r-n*r,u=2*n-o;return{r:e.hueToRGB(u,o,t+2),g:e.hueToRGB(u,o,t),b:e.hueToRGB(u,o,t-2)}},e.cmykToRGB=function(t,e,r,n){return n=1-n,{r:Math.round(255*(1-t)*n),g:Math.round(255*(1-e)*n),b:Math.round(255*(1-r)*n)}},e.rgbToCMYK=function(t,e,r){t/=255,e/=255,r/=255;var n=1-Math.max(t,e,r),o=1-n,u=(o-t)/o,i=(o-e)/o,a=(o-r)/o;return{c:Math.round(100*u),m:Math.round(100*i),y:Math.round(100*a),k:Math.round(100*n)}},e.rgbToHSL=function(t,e,r,n){void 0===n&&(n=1),t/=255,e/=255,r/=255,n=Math.min(n,1);var o=Math.max(t,e,r),u=Math.min(t,e,r),i=o-u,a=0,s=0,c=(o+u)/2;if(0===i)a=0,s=0;else{switch(o){case t:a=(e-r)/i%6;break;case e:a=(r-t)/i+2;break;case r:a=(t-e)/i+4}(a=Math.round(60*a))<0&&(a+=360),s=i/(1-Math.abs(2*c-1))}return{h:a,s:Math.round(100*s),l:Math.round(100*c),a:n}}},function(t,e,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0});var o=r(0),u=r(2),i=r(1),a=r(4),s=r(5),c=function(t,e){return"string"==typeof t&&e||"object"==typeof t&&!e},d=function(t,e){return void 0===e&&(e=a.getColorModel(t)),"string"==typeof t?a.getRGBObjectFromString[e](t):a.getRGBObjectFromObject[e](t)},h=function(t,e,r,n,o){var u=n(d(t,e));return r?o(u):u},p=function(){function t(t){this.pi2=360,this.rgb=d(t),this.hsl=u.rgbToHSL(this.rgb.r,this.rgb.g,this.rgb.b,this.rgb.a),this.updateCMYK()}return t.prototype.updateRGB=function(){this.rgb=n({},u.hslToRGB(this.hsl.h,this.hsl.s,this.hsl.l),{a:this.hsl.a})},t.prototype.updateRGBFromCMYK=function(){this.rgb=n({},u.cmykToRGB(this.cmyk.c,this.cmyk.m,this.cmyk.y,this.cmyk.k),{a:this.rgb.a})},t.prototype.updateHSL=function(){this.hsl=n({},u.rgbToHSL(this.rgb.r,this.rgb.g,this.rgb.b),{a:this.rgb.a})},t.prototype.updateCMYK=function(){this.cmyk=u.rgbToCMYK(this.rgb.r,this.rgb.g,this.rgb.b)},t.prototype.updateRGBAndCMYK=function(){return this.updateRGB(),this.updateCMYK(),this},t.prototype.updateHSLAndCMYK=function(){return this.updateHSL(),this.updateCMYK(),this},t.prototype.updateRGBAndHSL=function(){return this.updateRGBFromCMYK(),this.updateHSL(),this},t.prototype.setH=function(t){return t>360?t-=Math.floor(t/this.pi2)*this.pi2:t<0&&(t=Math.ceil(t/this.pi2)*this.pi2-t),this.hsl.h=t,this.updateRGBAndCMYK()},t.prototype.setS=function(t){return this.hsl.s=i.minmax(t,0,100),this.updateRGBAndCMYK()},t.prototype.setL=function(t){return this.hsl.l=i.minmax(t,0,100),this.updateRGBAndCMYK()},t.prototype.setR=function(t){return this.rgb.r=i.minmax(t,0,255),this.updateHSLAndCMYK()},t.prototype.setG=function(t){return this.rgb.g=i.minmax(t,0,255),this.updateHSLAndCMYK()},t.prototype.setB=function(t){return this.rgb.b=i.minmax(t,0,255),this.updateHSLAndCMYK()},t.prototype.setA=function(t){return this.hsl.a=this.rgb.a=i.minmax(t,0,1),this},t.prototype.setC=function(t){return this.cmyk.c=i.minmax(t,0,100),this.updateRGBAndHSL()},t.prototype.setM=function(t){return this.cmyk.m=i.minmax(t,0,100),this.updateRGBAndHSL()},t.prototype.setY=function(t){return this.cmyk.y=i.minmax(t,0,100),this.updateRGBAndHSL()},t.prototype.setK=function(t){return this.cmyk.k=i.minmax(t,0,100),this.updateRGBAndHSL()},Object.defineProperty(t.prototype,"H",{get:function(){return i.round(this.hsl.h)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"S",{get:function(){return i.round(this.hsl.s)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"L",{get:function(){return i.round(this.hsl.l)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"R",{get:function(){return i.round(this.rgb.r)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"G",{get:function(){return i.round(this.rgb.g)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"B",{get:function(){return i.round(this.rgb.b)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"A",{get:function(){return i.round(this.hsl.a,2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"C",{get:function(){return i.round(this.cmyk.c)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"M",{get:function(){return i.round(this.cmyk.m)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Y",{get:function(){return i.round(this.cmyk.y)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"K",{get:function(){return i.round(this.cmyk.k)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HEXObject",{get:function(){return a.translateColor.HEX(this.rgb)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HEXAObject",{get:function(){return a.translateColor.HEXA(this.rgb)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"RGBObject",{get:function(){var t=n({},this.rgb);return a.translateColor.RGB(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"RGBAObject",{get:function(){var t=n({},this.rgb);return a.translateColor.RGBA(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HSLObject",{get:function(){return{h:i.round(this.hsl.h),s:i.round(this.hsl.s),l:i.round(this.hsl.l)}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HSLAObject",{get:function(){return{h:i.round(this.hsl.h),s:i.round(this.hsl.s),l:i.round(this.hsl.l),a:i.hasProp(this.hsl,"a")?i.round(this.hsl.a,2):1}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"CMYKObject",{get:function(){return{c:i.round(this.cmyk.c),m:i.round(this.cmyk.m),y:i.round(this.cmyk.y),k:i.round(this.cmyk.k)}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HEX",{get:function(){var t=this.rgb,e={r:t.r,g:t.g,b:t.b};return s.CSS.HEX(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HEXA",{get:function(){var t=this.rgb,e=t.r,r=t.g,n=t.b,o=t.a,u={r:e,g:r,b:n,a:255*(void 0===o?1:o)};return s.CSS.HEX(u)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"RGB",{get:function(){var t=this.rgb,e={r:t.r,g:t.g,b:t.b};return s.CSS.RGB(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"RGBA",{get:function(){var t=this.rgb,e=t.r,r=t.g,n=t.b,o=t.a,u={r:e,g:r,b:n,a:void 0===o?1:o};return s.CSS.RGB(u)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HSL",{get:function(){var t=this.hsl,e={h:t.h,s:t.s,l:t.l};return s.CSS.HSL(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HSLA",{get:function(){var t=this.hsl,e=t.h,r=t.s,n=t.l,o=t.a,u={h:e,s:r,l:n,a:void 0===o?1:o};return s.CSS.HSL(u)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"CMYK",{get:function(){return s.CSS.CMYK(this.cmyk)},enumerable:!0,configurable:!0}),t.toHEX=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return h(t,r,e,a.translateColor.HEX,s.CSS.HEX)},t.toHEXA=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return h(t,r,e,a.translateColor.HEXA,s.CSS.HEX)},t.toRGB=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return h(t,r,e,a.translateColor.RGB,s.CSS.RGB)},t.toRGBA=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return h(t,r,e,a.translateColor.RGBA,s.CSS.RGB)},t.toHSL=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return r===o.CONST.HSL&&c(t,e)?t:h(t,r,e,a.translateColor.HSL,s.CSS.HSL)},t.toHSLA=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return r===o.CONST.HSLA&&c(t,e)?t:h(t,r,e,a.translateColor.HSLA,s.CSS.HSL)},t.toCMYK=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return r===o.CONST.CMYK&&c(t,e)?t:h(t,r,e,a.translateColor.CMYK,s.CSS.CMYK)},t}();e.ColorTranslator=p},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(0),o=r(1),u=r(2);e.getColorModel=function(t){return"string"==typeof t?function(t){var e;if(Object.keys(n.CONST).some(function(r){if(n.COLORREGS[r].test(t))return e=r,!0}),!e)throw new Error(n.ERRORS.NOT_ACCEPTED_STRING_INPUT);return e}(t):function(t){var e,r=o.getOrderedArrayString(Object.keys(t));if(Object.keys(n.CONST).some(function(t){if(o.getOrderedArrayString(t.split(""))===r)return e=t,!0}),!e)throw new Error(n.ERRORS.NOT_ACCEPTED_OBJECT_INPUT);return e}(t)},e.getRGBObjectFromString={HEX:function(t){var e=t.match(n.COLORREGS.HEX),r={r:o.getDEC(e[1]||e[5]),g:o.getDEC(e[2]||e[6]),b:o.getDEC(e[3]||e[7])},u=e[4]||e[8];return void 0!==u&&(r.a=o.getDEC(u)/255),r},RGB:function(t){var e=t.match(n.COLORREGS.RGB),r=o.getBase255Number(e[1]||e[4]),u=o.getBase255Number(e[2]||e[5]),i=o.getBase255Number(e[3]||e[6]);return{r:Math.min(r,255),g:Math.min(u,255),b:Math.min(i,255)}},RGBA:function(t){var e=t.match(n.COLORREGS.RGBA),r=o.getBase255Number(e[1]||e[4]),u=o.getBase255Number(e[2]||e[5]),i=o.getBase255Number(e[3]||e[6]),a=+e[7];return{r:Math.min(r,255),g:Math.min(u,255),b:Math.min(i,255),a:isNaN(a)||a>1?1:o.round(a,2)}},HSL:function(t){var e=t.match(n.COLORREGS.HSL),r=+e[1],i=o.percent(e[2]),a=o.percent(e[3]);return u.hslToRGB(r,i,a)},HSLA:function(t){var e=t.match(n.COLORREGS.HSLA),r=+e[4],i=+e[1],a=o.percent(e[2]),s=o.percent(e[3]),c=u.hslToRGB(i,a,s);return c.a=isNaN(r)||r>1?1:o.round(r,2),c},CMYK:function(t){var e=t.match(n.COLORREGS.CMYK),r=o.getCMYKNumber(e[1]||e[5]),i=o.getCMYKNumber(e[2]||e[6]),a=o.getCMYKNumber(e[3]||e[7]),s=o.getCMYKNumber(e[4]||e[8]);return u.cmykToRGB(r,i,a,s)}},e.getRGBObjectFromObject={RGB:function(t){return{r:o.getBase255Number(""+t.r),g:o.getBase255Number(""+t.g),b:o.getBase255Number(""+t.b)}},RGBA:function(t){var e=this.RGB(t);return e.a=o.hasProp(t,"a")?Math.min(o.getBase255Number(""+t.a,!0),1):1,e},HSL:function(t){var e=o.percent(""+t.s),r=o.percent(""+t.l);return u.hslToRGB(t.h,e,r)},HSLA:function(t){var e=this.HSL(t);return e.a=isNaN(+t.a)||+t.a>1?1:o.round(t.a,2),e},CMYK:function(t){var e=o.getCMYKNumber(""+t.c),r=o.getCMYKNumber(""+t.m),n=o.getCMYKNumber(""+t.y),i=o.getCMYKNumber(""+t.k);return u.cmykToRGB(e,r,n,i)}},e.translateColor={HEX:function(t){return{r:o.getHEX(t.r),g:o.getHEX(t.g),b:o.getHEX(t.b)}},HEXA:function(t){var r=e.translateColor.HEX(t);return r.a=o.hasProp(t,"a")?o.getHEX(255*t.a):"0xFF",r},RGB:function(t){return o.hasProp(t,"a")&&delete t.a,t},RGBA:function(t){return t.a=o.hasProp(t,"a")?o.round(t.a,2):1,t},HSL:function(t){var e=u.rgbToHSL(t.r,t.g,t.b);return delete e.a,e},HSLA:function(t){var r=e.translateColor.HSL(t);return r.a=o.hasProp(t,"a")?o.round(t.a,2):1,r},CMYK:function(t){return u.rgbToCMYK(t.r,t.g,t.b)}}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(1);e.CSS={HEX:function(t){return"#"+n.toHEX(t.r)+n.toHEX(t.g)+n.toHEX(t.b)+(t.a&&n.toHEX(t.a)||"")},RGB:function(t){return"rgb"+(n.hasProp(t,"a")?"a":"")+"("+n.round(t.r)+","+n.round(t.g)+","+n.round(t.b)+(n.hasProp(t,"a")&&","+n.round(t.a,2)||"")+")"},HSL:function(t){return"hsl"+(n.hasProp(t,"a")?"a":"")+"("+n.round(t.h)+","+n.round(t.s)+"%,"+n.round(t.l)+"%"+(n.hasProp(t,"a")&&","+n.round(t.a,2)||"")+")"},CMYK:function(t){return"cmyk("+n.round(t.c)+"%,"+n.round(t.m)+"%,"+n.round(t.y)+"%,"+n.round(t.k)+"%)"}}}]));

@@ -11,1 +11,2 @@ import { NumberOrString } from '../@types';

export declare const round: (value: NumberOrString, decimals?: number) => number;
export declare const minmax: (n: number, min: number, max: number) => number;

@@ -1,7 +0,55 @@

import { ColorInput, RGBOutput, HSLOutput, CMYKOutput } from './@types';
import { RGBObject, HSLObject, CMYKObject, ColorInput, RGBOutput, HSLOutput, CMYKOutput } from './@types';
export declare class ColorTranslator {
constructor(color: ColorInput);
private rgb;
private hsl;
private cmyk;
private pi2;
private updateRGB;
private updateRGBFromCMYK;
private updateHSL;
private updateCMYK;
private updateRGBAndCMYK;
private updateHSLAndCMYK;
private updateRGBAndHSL;
setH(h: number): ColorTranslator;
setS(s: number): ColorTranslator;
setL(l: number): ColorTranslator;
setR(r: number): ColorTranslator;
setG(g: number): ColorTranslator;
setB(b: number): ColorTranslator;
setA(a: number): ColorTranslator;
setC(c: number): ColorTranslator;
setM(m: number): ColorTranslator;
setY(y: number): ColorTranslator;
setK(k: number): ColorTranslator;
readonly H: number;
readonly S: number;
readonly L: number;
readonly R: number;
readonly G: number;
readonly B: number;
readonly A: number;
readonly C: number;
readonly M: number;
readonly Y: number;
readonly K: number;
readonly HEXObject: RGBObject;
readonly HEXAObject: RGBObject;
readonly RGBObject: RGBObject;
readonly RGBAObject: RGBObject;
readonly HSLObject: HSLObject;
readonly HSLAObject: HSLObject;
readonly CMYKObject: CMYKObject;
readonly HEX: string;
readonly HEXA: string;
readonly RGB: string;
readonly RGBA: string;
readonly HSL: string;
readonly HSLA: string;
readonly CMYK: string;
static toHEX(color: ColorInput, css?: boolean): RGBOutput;
static toHEXA(color: ColorInput, css?: boolean): RGBOutput;
static toRGB(color: ColorInput, css?: boolean): RGBOutput;
static toRGBA(color: ColorInput, css?: boolean): RGBOutput;
static toHEX(color: ColorInput, css?: boolean): RGBOutput;
static toHEXA(color: ColorInput, css?: boolean): RGBOutput;
static toHSL(color: ColorInput, css?: boolean): HSLOutput;

@@ -8,0 +56,0 @@ static toHSLA(color: ColorInput, css?: boolean): HSLOutput;

@@ -1,1 +0,1 @@

!function(r,t){for(var e in t)r[e]=t[e]}(exports,function(r){var t={};function e(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)e.d(n,o,function(t){return r[t]}.bind(null,o));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=2)}([function(r,t,e){"use strict";var n;Object.defineProperty(t,"__esModule",{value:!0}),t.CONST={HEX:"HEX",RGB:"RGB",RGBA:"RGBA",HSL:"HSL",HSLA:"HSLA",CMYK:"CMYK"},t.COLORREGS=((n={})[t.CONST.HEX]=/^#(?:([a-f\d])([a-f\d])([a-f\d])([a-f\d])?|([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?)$/i,n[t.CONST.RGB]=/^rgb\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*\)$/,n[t.CONST.RGBA]=/^rgba\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*,\s*(\d\.?\d*)\s*\)$/,n[t.CONST.HSL]=/^hsl\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%s*\)$/,n[t.CONST.HSLA]=/^hsla\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%\s*,\s*(\d\.?\d*)\s*\)$/,n[t.CONST.CMYK]=/^(?:device-cmyk|cmyk)\s*\(\s*(?:(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)|(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*))\s*\)$/,n),t.PCENT=/^([\d.]+)%$/,t.HEX=/^0x([a-f\d]{1,2})$/i,t.ERRORS={NOT_ACCEPTED_STRING_INPUT:"The provided string color doesn't have a correct format",NOT_ACCEPTED_OBJECT_INPUT:"The provided color object doesn't have the proper keys"}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(0);t.hasProp=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},t.percent=function(r){return n.PCENT.test(""+r)?+(""+r).replace(n.PCENT,"$1"):Math.min(+r,100)},t.getDEC=function(r){return 1===r.length&&(r+=r),parseInt(r,16)},t.getHEX=function(r){var t=parseInt(""+r).toString(16).toUpperCase();return 1===t.length?"0x0"+t:"0x"+t},t.toHEX=function(r){var t=parseInt(""+r).toString(16).toUpperCase();return 1===t.length&&(t="0"+t),t},t.getBase255Number=function(r,t){return void 0===t&&(t=!1),!t&&n.PCENT.test(r)?Math.min(255*+r.replace(n.PCENT,"$1")/100,255):n.HEX.test(r)?3===r.length?t?parseInt(r+r.slice(-1))/255:parseInt(r+r.slice(-1)):t?parseInt(r)/255:parseInt(r):Math.min(+r,t?1:255)},t.getCMYKNumber=function(r){return Math.min(n.PCENT.test(r)?+r.replace(n.PCENT,"$1")/100:+r,1)},t.getOrderedArrayString=function(r){return r.sort().join().toUpperCase()},t.round=function(r,t){void 0===t&&(t=0);var e=Math.pow(10,t);return Math.round(+r*e)/e}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(0),o=e(3),u=e(5),a=function(r,t){return"string"==typeof r&&t||"object"==typeof r&&!t},s=function(r,t,e,n,u){var a=n("string"==typeof r?o.getRGBObjectFromString[t](r):o.getRGBObjectFromObject[t](r));return e?u(a):a},i=function(){function r(){}return r.toRGB=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.RGB,u.CSS.RGB)},r.toRGBA=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.RGBA,u.CSS.RGB)},r.toHEX=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.HEX,u.CSS.HEX)},r.toHEXA=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return s(r,e,t,o.translateColor.HEXA,u.CSS.HEX)},r.toHSL=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return e===n.CONST.HSL&&a(r,t)?r:s(r,e,t,o.translateColor.HSL,u.CSS.HSL)},r.toHSLA=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return e===n.CONST.HSLA&&a(r,t)?r:s(r,e,t,o.translateColor.HSLA,u.CSS.HSL)},r.toCMYK=function(r,t){void 0===t&&(t=!0);var e=o.getColorModel(r);return e===n.CONST.CMYK&&a(r,t)?r:s(r,e,t,o.translateColor.CMYK,u.CSS.CMYK)},r}();t.ColorTranslator=i},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(0),o=e(1),u=e(4);t.getColorModel=function(r){return"string"==typeof r?function(r){var t;if(Object.keys(n.CONST).some(function(e){if(n.COLORREGS[e].test(r))return t=e,!0}),!t)throw new Error(n.ERRORS.NOT_ACCEPTED_STRING_INPUT);return t}(r):function(r){var t,e=o.getOrderedArrayString(Object.keys(r));if(Object.keys(n.CONST).some(function(r){if(o.getOrderedArrayString(r.split(""))===e)return t=r,!0}),!t)throw new Error(n.ERRORS.NOT_ACCEPTED_OBJECT_INPUT);return t}(r)},t.getRGBObjectFromString={HEX:function(r){var t=r.match(n.COLORREGS.HEX),e={r:o.getDEC(t[1]||t[5]),g:o.getDEC(t[2]||t[6]),b:o.getDEC(t[3]||t[7])},u=t[4]||t[8];return void 0!==u&&(e.a=o.getDEC(u)/255),e},RGB:function(r){var t=r.match(n.COLORREGS.RGB),e=o.getBase255Number(t[1]||t[4]),u=o.getBase255Number(t[2]||t[5]),a=o.getBase255Number(t[3]||t[6]);return{r:Math.min(e,255),g:Math.min(u,255),b:Math.min(a,255)}},RGBA:function(r){var t=r.match(n.COLORREGS.RGBA),e=o.getBase255Number(t[1]||t[4]),u=o.getBase255Number(t[2]||t[5]),a=o.getBase255Number(t[3]||t[6]),s=+t[7];return{r:Math.min(e,255),g:Math.min(u,255),b:Math.min(a,255),a:isNaN(s)||s>1?1:o.round(s,2)}},HSL:function(r){var t=r.match(n.COLORREGS.HSL),e=+t[1],a=o.percent(t[2]),s=o.percent(t[3]);return u.hslToRGB(e,a,s)},HSLA:function(r){var t=r.match(n.COLORREGS.HSLA),e=+t[4],a=+t[1],s=o.percent(t[2]),i=o.percent(t[3]),d=u.hslToRGB(a,s,i);return d.a=isNaN(e)||e>1?1:o.round(e,2),d},CMYK:function(r){var t=r.match(n.COLORREGS.CMYK),e=o.getCMYKNumber(t[1]||t[5]),a=o.getCMYKNumber(t[2]||t[6]),s=o.getCMYKNumber(t[3]||t[7]),i=o.getCMYKNumber(t[4]||t[8]);return u.cmykToRGB(e,a,s,i)}},t.getRGBObjectFromObject={RGB:function(r){return{r:o.getBase255Number(""+r.r),g:o.getBase255Number(""+r.g),b:o.getBase255Number(""+r.b)}},RGBA:function(r){var t=this.RGB(r);return t.a=o.hasProp(r,"a")?Math.min(o.getBase255Number(""+r.a,!0),1):1,t},HSL:function(r){var t=o.percent(""+r.s),e=o.percent(""+r.l);return u.hslToRGB(r.h,t,e)},HSLA:function(r){var t=this.HSL(r);return t.a=isNaN(+r.a)||+r.a>1?1:o.round(r.a,2),t},CMYK:function(r){var t=o.getCMYKNumber(""+r.c),e=o.getCMYKNumber(""+r.m),n=o.getCMYKNumber(""+r.y),a=o.getCMYKNumber(""+r.k);return u.cmykToRGB(t,e,n,a)}},t.translateColor={HEX:function(r){return{r:o.getHEX(r.r),g:o.getHEX(r.g),b:o.getHEX(r.b)}},HEXA:function(r){var e=t.translateColor.HEX(r);return e.a=o.hasProp(r,"a")?o.getHEX(255*r.a):"0xFF",e},RGB:function(r){return o.hasProp(r,"a")&&delete r.a,r},RGBA:function(r){return r.a=o.hasProp(r,"a")?o.round(r.a,2):1,r},HSL:function(r){var t=u.rgbToHSL(r.r,r.g,r.b);return delete t.a,t},HSLA:function(r){var e=t.translateColor.HSL(r);return e.a=o.hasProp(r,"a")?o.round(r.a,2):1,e},CMYK:function(r){return u.rgbToCMYK(r.r,r.g,r.b)}}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.hueToRGB=function(r,t,e){return e<0&&(e+=6),e>=6&&(e-=6),e<1?Math.round(255*((t-r)*e+r)):e<3?Math.round(255*t):e<4?Math.round(255*((t-r)*(4-e)+r)):Math.round(255*r)},t.hslToRGB=function(r,e,n){r/=60,e/=100;var o=(n/=100)<=.5?n*(e+1):n+e-n*e,u=2*n-o;return{r:t.hueToRGB(u,o,r+2),g:t.hueToRGB(u,o,r),b:t.hueToRGB(u,o,r-2)}},t.cmykToRGB=function(r,t,e,n){return n=1-n,{r:Math.round(255*(1-r)*n),g:Math.round(255*(1-t)*n),b:Math.round(255*(1-e)*n)}},t.rgbToCMYK=function(r,t,e){r/=255,t/=255,e/=255;var n=1-Math.max(r,t,e),o=1-n,u=(o-r)/o,a=(o-t)/o,s=(o-e)/o;return{c:Math.round(100*u),m:Math.round(100*a),y:Math.round(100*s),k:Math.round(100*n)}},t.rgbToHSL=function(r,t,e,n){void 0===n&&(n=1),r/=255,t/=255,e/=255,n=Math.min(n,1);var o=Math.max(r,t,e),u=Math.min(r,t,e),a=o-u,s=0,i=0,d=(o+u)/2;if(0===a)s=0,i=0;else{switch(o){case r:s=(t-e)/a%6;break;case t:s=(e-r)/a+2;break;case e:s=(r-t)/a+4}(s=Math.round(60*s))<0&&(s+=360),i=a/(1-Math.abs(2*d-1))}return{h:s,s:Math.round(100*i),l:Math.round(100*d),a:n}}},function(r,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=e(1);t.CSS={HEX:function(r){return"#"+n.toHEX(r.r)+n.toHEX(r.g)+n.toHEX(r.b)+(r.a&&n.toHEX(r.a)||"")},RGB:function(r){return"rgb"+(r.a?"a":"")+"("+n.round(r.r)+","+n.round(r.g)+","+n.round(r.b)+(n.hasProp(r,"a")&&","+n.round(r.a,2)||"")+")"},HSL:function(r){return"hsl"+(r.a?"a":"")+"("+n.round(r.h)+","+n.round(r.s)+"%,"+n.round(r.l)+"%"+(n.hasProp(r,"a")&&","+n.round(r.a,2)||"")+")"},CMYK:function(r){return"device-cmyk("+n.round(r.c)+"%,"+n.round(r.m)+"%,"+n.round(r.y)+"%,"+n.round(r.k)+"%)"}}}]));
!function(t,e){for(var r in e)t[r]=e[r]}(exports,function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=3)}([function(t,e,r){"use strict";var n;Object.defineProperty(e,"__esModule",{value:!0}),e.CONST={HEX:"HEX",RGB:"RGB",RGBA:"RGBA",HSL:"HSL",HSLA:"HSLA",CMYK:"CMYK"},e.COLORREGS=((n={})[e.CONST.HEX]=/^#(?:([a-f\d])([a-f\d])([a-f\d])([a-f\d])?|([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?)$/i,n[e.CONST.RGB]=/^rgb\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*\)$/,n[e.CONST.RGBA]=/^rgba\s*\(\s*(?:(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)|(\d+)\s*,\s*(\d+)\s*,\s*(\d+))\s*,\s*(\d\.?\d*)\s*\)$/,n[e.CONST.HSL]=/^hsl\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%s*\)$/,n[e.CONST.HSLA]=/^hsla\s*\(\s*(-?\d+\.?\d*)\s*,\s*(\d+\.?\d*)%\s*,\s*(\d+\.?\d*)%\s*,\s*(\d\.?\d*)\s*\)$/,n[e.CONST.CMYK]=/^(?:device-cmyk|cmyk)\s*\(\s*(?:(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)\s*,\s*(\d+\.?\d*%)|(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*)\s*,\s*(\d\.?\d*))\s*\)$/,n),e.PCENT=/^([\d.]+)%$/,e.HEX=/^0x([a-f\d]{1,2})$/i,e.ERRORS={NOT_ACCEPTED_STRING_INPUT:"The provided string color doesn't have a correct format",NOT_ACCEPTED_OBJECT_INPUT:"The provided color object doesn't have the proper keys"}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(0);e.hasProp=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.percent=function(t){return n.PCENT.test(""+t)?+(""+t).replace(n.PCENT,"$1"):Math.min(+t,100)},e.getDEC=function(t){return 1===t.length&&(t+=t),parseInt(t,16)},e.getHEX=function(t){var e=parseInt(""+t).toString(16).toUpperCase();return 1===e.length?"0x0"+e:"0x"+e},e.toHEX=function(t){var e=parseInt(""+t).toString(16).toUpperCase();return 1===e.length&&(e="0"+e),e},e.getBase255Number=function(t,e){return void 0===e&&(e=!1),!e&&n.PCENT.test(t)?Math.min(255*+t.replace(n.PCENT,"$1")/100,255):n.HEX.test(t)?3===t.length?e?parseInt(t+t.slice(-1))/255:parseInt(t+t.slice(-1)):e?parseInt(t)/255:parseInt(t):Math.min(+t,e?1:255)},e.getCMYKNumber=function(t){return Math.min(n.PCENT.test(t)?+t.replace(n.PCENT,"$1")/100:+t,1)},e.getOrderedArrayString=function(t){return t.sort().join().toUpperCase()},e.round=function(t,e){void 0===e&&(e=0);var r=Math.pow(10,e);return Math.round(+t*r)/r},e.minmax=function(t,e,r){return Math.max(e,Math.min(t,r))}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.hueToRGB=function(t,e,r){return r<0&&(r+=6),r>=6&&(r-=6),r<1?Math.round(255*((e-t)*r+t)):r<3?Math.round(255*e):r<4?Math.round(255*((e-t)*(4-r)+t)):Math.round(255*t)},e.hslToRGB=function(t,r,n){t/=60,r/=100;var o=(n/=100)<=.5?n*(r+1):n+r-n*r,u=2*n-o;return{r:e.hueToRGB(u,o,t+2),g:e.hueToRGB(u,o,t),b:e.hueToRGB(u,o,t-2)}},e.cmykToRGB=function(t,e,r,n){return n=1-n,{r:Math.round(255*(1-t)*n),g:Math.round(255*(1-e)*n),b:Math.round(255*(1-r)*n)}},e.rgbToCMYK=function(t,e,r){t/=255,e/=255,r/=255;var n=1-Math.max(t,e,r),o=1-n,u=(o-t)/o,i=(o-e)/o,a=(o-r)/o;return{c:Math.round(100*u),m:Math.round(100*i),y:Math.round(100*a),k:Math.round(100*n)}},e.rgbToHSL=function(t,e,r,n){void 0===n&&(n=1),t/=255,e/=255,r/=255,n=Math.min(n,1);var o=Math.max(t,e,r),u=Math.min(t,e,r),i=o-u,a=0,s=0,c=(o+u)/2;if(0===i)a=0,s=0;else{switch(o){case t:a=(e-r)/i%6;break;case e:a=(r-t)/i+2;break;case r:a=(t-e)/i+4}(a=Math.round(60*a))<0&&(a+=360),s=i/(1-Math.abs(2*c-1))}return{h:a,s:Math.round(100*s),l:Math.round(100*c),a:n}}},function(t,e,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0});var o=r(0),u=r(2),i=r(1),a=r(4),s=r(5),c=function(t,e){return"string"==typeof t&&e||"object"==typeof t&&!e},d=function(t,e){return void 0===e&&(e=a.getColorModel(t)),"string"==typeof t?a.getRGBObjectFromString[e](t):a.getRGBObjectFromObject[e](t)},h=function(t,e,r,n,o){var u=n(d(t,e));return r?o(u):u},p=function(){function t(t){this.pi2=360,this.rgb=d(t),this.hsl=u.rgbToHSL(this.rgb.r,this.rgb.g,this.rgb.b,this.rgb.a),this.updateCMYK()}return t.prototype.updateRGB=function(){this.rgb=n({},u.hslToRGB(this.hsl.h,this.hsl.s,this.hsl.l),{a:this.hsl.a})},t.prototype.updateRGBFromCMYK=function(){this.rgb=n({},u.cmykToRGB(this.cmyk.c,this.cmyk.m,this.cmyk.y,this.cmyk.k),{a:this.rgb.a})},t.prototype.updateHSL=function(){this.hsl=n({},u.rgbToHSL(this.rgb.r,this.rgb.g,this.rgb.b),{a:this.rgb.a})},t.prototype.updateCMYK=function(){this.cmyk=u.rgbToCMYK(this.rgb.r,this.rgb.g,this.rgb.b)},t.prototype.updateRGBAndCMYK=function(){return this.updateRGB(),this.updateCMYK(),this},t.prototype.updateHSLAndCMYK=function(){return this.updateHSL(),this.updateCMYK(),this},t.prototype.updateRGBAndHSL=function(){return this.updateRGBFromCMYK(),this.updateHSL(),this},t.prototype.setH=function(t){return t>360?t-=Math.floor(t/this.pi2)*this.pi2:t<0&&(t=Math.ceil(t/this.pi2)*this.pi2-t),this.hsl.h=t,this.updateRGBAndCMYK()},t.prototype.setS=function(t){return this.hsl.s=i.minmax(t,0,100),this.updateRGBAndCMYK()},t.prototype.setL=function(t){return this.hsl.l=i.minmax(t,0,100),this.updateRGBAndCMYK()},t.prototype.setR=function(t){return this.rgb.r=i.minmax(t,0,255),this.updateHSLAndCMYK()},t.prototype.setG=function(t){return this.rgb.g=i.minmax(t,0,255),this.updateHSLAndCMYK()},t.prototype.setB=function(t){return this.rgb.b=i.minmax(t,0,255),this.updateHSLAndCMYK()},t.prototype.setA=function(t){return this.hsl.a=this.rgb.a=i.minmax(t,0,1),this},t.prototype.setC=function(t){return this.cmyk.c=i.minmax(t,0,100),this.updateRGBAndHSL()},t.prototype.setM=function(t){return this.cmyk.m=i.minmax(t,0,100),this.updateRGBAndHSL()},t.prototype.setY=function(t){return this.cmyk.y=i.minmax(t,0,100),this.updateRGBAndHSL()},t.prototype.setK=function(t){return this.cmyk.k=i.minmax(t,0,100),this.updateRGBAndHSL()},Object.defineProperty(t.prototype,"H",{get:function(){return i.round(this.hsl.h)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"S",{get:function(){return i.round(this.hsl.s)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"L",{get:function(){return i.round(this.hsl.l)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"R",{get:function(){return i.round(this.rgb.r)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"G",{get:function(){return i.round(this.rgb.g)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"B",{get:function(){return i.round(this.rgb.b)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"A",{get:function(){return i.round(this.hsl.a,2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"C",{get:function(){return i.round(this.cmyk.c)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"M",{get:function(){return i.round(this.cmyk.m)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Y",{get:function(){return i.round(this.cmyk.y)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"K",{get:function(){return i.round(this.cmyk.k)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HEXObject",{get:function(){return a.translateColor.HEX(this.rgb)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HEXAObject",{get:function(){return a.translateColor.HEXA(this.rgb)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"RGBObject",{get:function(){var t=n({},this.rgb);return a.translateColor.RGB(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"RGBAObject",{get:function(){var t=n({},this.rgb);return a.translateColor.RGBA(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HSLObject",{get:function(){return{h:i.round(this.hsl.h),s:i.round(this.hsl.s),l:i.round(this.hsl.l)}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HSLAObject",{get:function(){return{h:i.round(this.hsl.h),s:i.round(this.hsl.s),l:i.round(this.hsl.l),a:i.hasProp(this.hsl,"a")?i.round(this.hsl.a,2):1}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"CMYKObject",{get:function(){return{c:i.round(this.cmyk.c),m:i.round(this.cmyk.m),y:i.round(this.cmyk.y),k:i.round(this.cmyk.k)}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HEX",{get:function(){var t=this.rgb,e={r:t.r,g:t.g,b:t.b};return s.CSS.HEX(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HEXA",{get:function(){var t=this.rgb,e=t.r,r=t.g,n=t.b,o=t.a,u={r:e,g:r,b:n,a:255*(void 0===o?1:o)};return s.CSS.HEX(u)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"RGB",{get:function(){var t=this.rgb,e={r:t.r,g:t.g,b:t.b};return s.CSS.RGB(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"RGBA",{get:function(){var t=this.rgb,e=t.r,r=t.g,n=t.b,o=t.a,u={r:e,g:r,b:n,a:void 0===o?1:o};return s.CSS.RGB(u)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HSL",{get:function(){var t=this.hsl,e={h:t.h,s:t.s,l:t.l};return s.CSS.HSL(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"HSLA",{get:function(){var t=this.hsl,e=t.h,r=t.s,n=t.l,o=t.a,u={h:e,s:r,l:n,a:void 0===o?1:o};return s.CSS.HSL(u)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"CMYK",{get:function(){return s.CSS.CMYK(this.cmyk)},enumerable:!0,configurable:!0}),t.toHEX=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return h(t,r,e,a.translateColor.HEX,s.CSS.HEX)},t.toHEXA=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return h(t,r,e,a.translateColor.HEXA,s.CSS.HEX)},t.toRGB=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return h(t,r,e,a.translateColor.RGB,s.CSS.RGB)},t.toRGBA=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return h(t,r,e,a.translateColor.RGBA,s.CSS.RGB)},t.toHSL=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return r===o.CONST.HSL&&c(t,e)?t:h(t,r,e,a.translateColor.HSL,s.CSS.HSL)},t.toHSLA=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return r===o.CONST.HSLA&&c(t,e)?t:h(t,r,e,a.translateColor.HSLA,s.CSS.HSL)},t.toCMYK=function(t,e){void 0===e&&(e=!0);var r=a.getColorModel(t);return r===o.CONST.CMYK&&c(t,e)?t:h(t,r,e,a.translateColor.CMYK,s.CSS.CMYK)},t}();e.ColorTranslator=p},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(0),o=r(1),u=r(2);e.getColorModel=function(t){return"string"==typeof t?function(t){var e;if(Object.keys(n.CONST).some(function(r){if(n.COLORREGS[r].test(t))return e=r,!0}),!e)throw new Error(n.ERRORS.NOT_ACCEPTED_STRING_INPUT);return e}(t):function(t){var e,r=o.getOrderedArrayString(Object.keys(t));if(Object.keys(n.CONST).some(function(t){if(o.getOrderedArrayString(t.split(""))===r)return e=t,!0}),!e)throw new Error(n.ERRORS.NOT_ACCEPTED_OBJECT_INPUT);return e}(t)},e.getRGBObjectFromString={HEX:function(t){var e=t.match(n.COLORREGS.HEX),r={r:o.getDEC(e[1]||e[5]),g:o.getDEC(e[2]||e[6]),b:o.getDEC(e[3]||e[7])},u=e[4]||e[8];return void 0!==u&&(r.a=o.getDEC(u)/255),r},RGB:function(t){var e=t.match(n.COLORREGS.RGB),r=o.getBase255Number(e[1]||e[4]),u=o.getBase255Number(e[2]||e[5]),i=o.getBase255Number(e[3]||e[6]);return{r:Math.min(r,255),g:Math.min(u,255),b:Math.min(i,255)}},RGBA:function(t){var e=t.match(n.COLORREGS.RGBA),r=o.getBase255Number(e[1]||e[4]),u=o.getBase255Number(e[2]||e[5]),i=o.getBase255Number(e[3]||e[6]),a=+e[7];return{r:Math.min(r,255),g:Math.min(u,255),b:Math.min(i,255),a:isNaN(a)||a>1?1:o.round(a,2)}},HSL:function(t){var e=t.match(n.COLORREGS.HSL),r=+e[1],i=o.percent(e[2]),a=o.percent(e[3]);return u.hslToRGB(r,i,a)},HSLA:function(t){var e=t.match(n.COLORREGS.HSLA),r=+e[4],i=+e[1],a=o.percent(e[2]),s=o.percent(e[3]),c=u.hslToRGB(i,a,s);return c.a=isNaN(r)||r>1?1:o.round(r,2),c},CMYK:function(t){var e=t.match(n.COLORREGS.CMYK),r=o.getCMYKNumber(e[1]||e[5]),i=o.getCMYKNumber(e[2]||e[6]),a=o.getCMYKNumber(e[3]||e[7]),s=o.getCMYKNumber(e[4]||e[8]);return u.cmykToRGB(r,i,a,s)}},e.getRGBObjectFromObject={RGB:function(t){return{r:o.getBase255Number(""+t.r),g:o.getBase255Number(""+t.g),b:o.getBase255Number(""+t.b)}},RGBA:function(t){var e=this.RGB(t);return e.a=o.hasProp(t,"a")?Math.min(o.getBase255Number(""+t.a,!0),1):1,e},HSL:function(t){var e=o.percent(""+t.s),r=o.percent(""+t.l);return u.hslToRGB(t.h,e,r)},HSLA:function(t){var e=this.HSL(t);return e.a=isNaN(+t.a)||+t.a>1?1:o.round(t.a,2),e},CMYK:function(t){var e=o.getCMYKNumber(""+t.c),r=o.getCMYKNumber(""+t.m),n=o.getCMYKNumber(""+t.y),i=o.getCMYKNumber(""+t.k);return u.cmykToRGB(e,r,n,i)}},e.translateColor={HEX:function(t){return{r:o.getHEX(t.r),g:o.getHEX(t.g),b:o.getHEX(t.b)}},HEXA:function(t){var r=e.translateColor.HEX(t);return r.a=o.hasProp(t,"a")?o.getHEX(255*t.a):"0xFF",r},RGB:function(t){return o.hasProp(t,"a")&&delete t.a,t},RGBA:function(t){return t.a=o.hasProp(t,"a")?o.round(t.a,2):1,t},HSL:function(t){var e=u.rgbToHSL(t.r,t.g,t.b);return delete e.a,e},HSLA:function(t){var r=e.translateColor.HSL(t);return r.a=o.hasProp(t,"a")?o.round(t.a,2):1,r},CMYK:function(t){return u.rgbToCMYK(t.r,t.g,t.b)}}},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(1);e.CSS={HEX:function(t){return"#"+n.toHEX(t.r)+n.toHEX(t.g)+n.toHEX(t.b)+(t.a&&n.toHEX(t.a)||"")},RGB:function(t){return"rgb"+(n.hasProp(t,"a")?"a":"")+"("+n.round(t.r)+","+n.round(t.g)+","+n.round(t.b)+(n.hasProp(t,"a")&&","+n.round(t.a,2)||"")+")"},HSL:function(t){return"hsl"+(n.hasProp(t,"a")?"a":"")+"("+n.round(t.h)+","+n.round(t.s)+"%,"+n.round(t.l)+"%"+(n.hasProp(t,"a")&&","+n.round(t.a,2)||"")+")"},CMYK:function(t){return"cmyk("+n.round(t.c)+"%,"+n.round(t.m)+"%,"+n.round(t.y)+"%,"+n.round(t.k)+"%)"}}}]));
{
"name": "colortranslator",
"version": "1.0.5",
"version": "1.1.0",
"description": "A JavaScript library, written in TypeScript, to convert among different color models",

@@ -27,4 +27,7 @@ "main": "dist/index.js",

"color",
"converter",
"translator",
"color-converter",
"color-translator",
"color-manipulation",
"css-color",
"css-color-convert",
"rgb",

@@ -66,3 +69,3 @@ "rgba",

"typescript": "^3.5.2",
"webpack": "^4.35.0",
"webpack": "^4.35.3",
"webpack-cli": "^3.3.5",

@@ -69,0 +72,0 @@ "webpack-dev-server": "^3.7.2"

@@ -35,5 +35,5 @@ <p align="center">

```javascript
<script src="wherever/you/instelled/colortranslator.web.js" />
```
<script src="wherever/you/instelled/colortranslator.web.js"></script>
```

@@ -68,3 +68,3 @@ #### Importing using CommonJS

Transpiles the TypeScript code and creates two bundles in the `dist` folder (`colortranslator.node.js` for Node environments and `colortranslator.web.js` to use directly in the browser).
Transpiles the TypeScript code and creates two bundles in the `dist` folder (`index.js` for Node environments and `colortranslator.web.js` to use directly in the browser).

@@ -91,7 +91,7 @@ #### test

It is not needed to specify the color model from which you are converting, the API will detect the format. You only need to specify to which color model you want to convert calling the specific method.
> **Note:** The conversion to a CMYK color is made taking a random value of black as a base (in this case, taking the greater value from red, green or blue). When a value of black is assumed, the rest of the colors can be calculated from it. The result will be visually similar to the original light color, but if you try to convert it back you will not obtain the same original value.
#### Input
It is possible to convert from a CSS string or an object.
The input can be a CSS string or an object:

@@ -116,37 +116,151 @@ ###### CSS string inputs

| Example of object inputs | Description |
| ---------------------------------------------- | ------------------------------ |
| `{r: "0xFF", g: "0x00", b: "0xFF"}` | Hexadecimal color |
| `{r: "0xF", g: "0x0", b: "0xF"}` | Shorthand hexadecimal color |
| `{r: "0xFF", g: "0x00", b: "0xFF", a: "0x80"}` | Hexadecimal color with alpha |
| `{r: 255, g: 0, b: 255}` | RGB notation |
| `{r: 255, g: 0, b: 255, a: 0.5}` | RGB notation with alpha |
| `{h: 300, s: "100%", l: "50%"}` | HSL notation |
| `{h: 300, s: "100%", l: "50%", a: 0.5}` | HSL notation with alpha |
| `{c: "0%", m: "100%", y: "100%", k: "0%"}` | CMYK notation with percentages |
| `{c: 0, m: 1, y: 1, k: 0}` | CMYK notation with numbers |
| Example of object inputs | Description |
| ---------------------------------------------- | ----------------------------------------- |
| `{r: "0xFF", g: "0x00", b: "0xFF"}` | Hexadecimal color |
| `{r: "0xF", g: "0x0", b: "0xF"}` | Shorthand hexadecimal color |
| `{r: "0xFF", g: "0x00", b: "0xFF", a: "0x80"}` | Hexadecimal color with alpha |
| `{r: 255, g: 0, b: 255}` | RGB notation |
| `{r: 255, g: 0, b: 255, a: 0.5}` | RGB notation with alpha |
| `{h: 300, s: "100%", l: "50%"}` | HSL notation using percentages |
| `{h: 300, s: 100, l: 50}` | HSL notation using numbers |
| `{h: 300, s: "100%", l: "50%", a: 0.5}` | HSL notation with alpha using percentages |
| `{h: 300, s: 100, l: 50, a: 0.5}` | HSL notation with alpha using numbers |
| `{c: "0%", m: "100%", y: "100%", k: "0%"}` | CMYK notation using percentages |
| `{c: 0, m: 1, y: 1, k: 0}` | CMYK notation using numbers |
#### Methods
#### Class instantiation
There are 7 methods available and all of them accept any of the previous inputs as the first parameter. The second parameter is optional and it specifies if the output should be a CSS string or an object:
It is possible to instantiate the class using any of the previous inputs:
###### Class instantiation examples
```javascript
const hex = new ColorTranslator('#FF00FF');
const rgb = new ColorTranslator('rgb(255, 0, 0)');
const hsl = new ColorTranslator('hsl(50, 20%, 90%)');
const hsla = new ColorTranslator({ r: 115, g: 200, b: 150, a: 0.5 });
const cmyk = new ColorTranslator({ c: 100, m: 100, y: 0, k: 0 });
```
anyMethod(color: string | object, css: boolean = true)
#### Class public methods
There are 11 chainable public methods and all of them accept a number as input:
| Public methods | Input | Description |
| -------------- | --------------- | -------------------------------------------------- |
| setH | 0 ≤ input ≤ 360 | Set the color hue |
| setS | 0 ≤ input ≤ 100 | Set the color saturation percentage |
| setL | 0 ≤ input ≤ 100 | Set the color lightness percentage |
| setR | 0 ≤ input ≤ 255 | Set the red value of the color |
| setG | 0 ≤ input ≤ 255 | Set the green value of the color |
| setB | 0 ≤ input ≤ 255 | Set the blue value of the color |
| setC | 0 ≤ input ≤ 100 | Set the CMYK cyan percentage value of the color |
| setM | 0 ≤ input ≤ 100 | Set the CMYK magenta percentage value of the color |
| setY | 0 ≤ input ≤ 100 | Set the CMYK yellow percentage value of the color |
| setK | 0 ≤ input ≤ 100 | Set the CMYK black percentage value of the color |
| setA | 0 ≤ input ≤ 1 | Set the alpha value of the color |
###### Class public methods examples
You can also consult the [demo 1](https://elchininet.github.io/ColorTranslator/#demo1) and the [demo 2](https://elchininet.github.io/ColorTranslator/#demo2) to check the use of the public methods.
```javascript
const color = new ColorTranslator('#FF00FF');
color
.setH(120)
.setS(80)
.setA(0.5);
color
.setR(255)
.setG(150)
.setA(0.25);
```
| Available methods | Description |
| ----------------- | --------------------------------------------- |
| toHEX | Convert to an hexadecimal notation |
| toHEXA | Convert to an hexadecimal notation with alpha |
| toRGB | Convert to an RGB notation |
| toRGBA | Convert to an RGB notation with alpha |
| toHSL | Convert to an HSL notation |
| toHSLA | Convert to an HSL notation with alpha |
| toCMYK | Convert to a CMYK notation |
#### Class public readonly properties
> **Note:** The conversion to a CMYK color is made taking a random value of black as a base (in this case, taking the greater value from red, green or blue). When a value of black is assumed, the rest of the colors can be calculated from it. The result will be visually similar to the original light color, but if you try to convert it back you will not obtain the same original value.
There are 7 properties to get the CSS representation of the color:
## Example methods
| Property | Description |
| -------- | --------------------------------------------------- |
| HEX | Get the the object hex representation of the color |
| HEXA | Get the the object hexa representation of the color |
| RGB | Get the the object rgb representation of the color |
| RGBA | Get the the object rgba representation of the color |
| HSL | Get the the object hsl representation of the color |
| HSLA | Get the the object hsla representation of the color |
| CMYK | Get the the object cmyk representation of the color |
There are 7 properties to get the object representation of the color:
| Property | Description |
| ---------- | --------------------------------------------------- |
| HEXObject | Get the the object hex representation of the color |
| HEXAObject | Get the the object hexa representation of the color |
| RGBObject | Get the the object rgb representation of the color |
| RGBAObject | Get the the object rgba representation of the color |
| HSLObject | Get the the object hsl representation of the color |
| HSLAObject | Get the the object hsla representation of the color |
| CMYKObject | Get the the object cmyk representation of the color |
There are 11 properties to get the individual color values:
| Property | Description |
| -------- | -------------------------------------------------- |
| H | Get the color hue |
| S | Get the color saturation percentage |
| L | Get the color lightness percentage |
| R | Get the red value of the color |
| G | Get the green value of the color |
| B | Get the blue value of the color |
| C | Get the CMYK cyan percentage value of the color |
| M | Get the CMYK magenta percentage value of the color |
| Y | Get the CMYK yellow percentage value of the color |
| K | Get the CMYK black percentage value of the color |
| A | Get the alpha value of the color |
###### Class public properties examples
You can also consult the [demo 1](https://elchininet.github.io/ColorTranslator/#demo1) and the [demo 2](https://elchininet.github.io/ColorTranslator/#demo2) to check the use of the public properties.
```javascript
const color = new ColorTranslator('#FF00FF');
color.R; // 255
color.G; // 0
color.B; // 255
color.RGB; // rgb(255,0,255)
color.HSLA; // hsla(300,100%,50%,1)
```
#### Class static methods
It is not needed to specify the color model from which you are converting, the API will detect the format. You only need to specify to which color model you want to convert calling the specific static method.
There are 7 static methods available and all of them accept any of the mentioned inputs as the first parameter. The second parameter is optional and it specifies if the output should be a CSS string or an object:
```
anyStaticMethod(color: string | object, css: boolean = true)
```
| Static method | Description |
| ------------- | --------------------------------------------- |
| toHEX | Convert to an hexadecimal notation |
| toHEXA | Convert to an hexadecimal notation with alpha |
| toRGB | Convert to an RGB notation |
| toRGBA | Convert to an RGB notation with alpha |
| toHSL | Convert to an HSL notation |
| toHSLA | Convert to an HSL notation with alpha |
| toCMYK | Convert to a CMYK notation |
#### Static methods examples
You can also consult the [demo 3](https://elchininet.github.io/ColorTranslator/#demo3) and the [demo 4](https://elchininet.github.io/ColorTranslator/#demo4) to check the use of static methods.
```javascript
ColorTranslator.toRGB('#FF00FF'); // rgb(255,0,255)

@@ -162,2 +276,4 @@

ColorTranslator.toCMYK('#F0F'); // cmyk(0%,100%,0%,0%)
ColorTranslator.toRGB({ h: 115, s: '70%', l: '45%' }); // rgb(48,195,34)

@@ -164,0 +280,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc