polychrome
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -92,7 +92,6 @@ var patterns = { | ||
var c = parse(color); | ||
var h = c.h; | ||
var s = c.s; | ||
var l = c.l; | ||
var a = c.a; | ||
var h = color.h; | ||
var s = color.s; | ||
var l = color.l; | ||
var a = color.a; | ||
var newLightness = l - (l * (percentage / 100)); | ||
@@ -105,7 +104,6 @@ return make.fromHsl(h, s, (newLightness < 0) ? 0 : newLightness, a); | ||
var c = parse(color); | ||
var h = c.h; | ||
var s = c.s; | ||
var l = c.l; | ||
var a = c.a; | ||
var h = color.h; | ||
var s = color.s; | ||
var l = color.l; | ||
var a = color.a; | ||
var newLightness = l + (l * (percentage / 100)); | ||
@@ -118,7 +116,6 @@ return make.fromHsl(h, s, (newLightness > 100) ? 100 : newLightness, a); | ||
var c = parse(color); | ||
var h = c.h; | ||
var s = c.s; | ||
var l = c.l; | ||
var a = c.a; | ||
var h = color.h; | ||
var s = color.s; | ||
var l = color.l; | ||
var a = color.a; | ||
var newAlpha = a + (a * (percentage / 100)); | ||
@@ -131,7 +128,6 @@ return make.fromHsl(h, s, l, (newAlpha > 1) ? 1 : newAlpha); | ||
var c = parse(color); | ||
var h = c.h; | ||
var s = c.s; | ||
var l = c.l; | ||
var a = c.a; | ||
var h = color.h; | ||
var s = color.s; | ||
var l = color.l; | ||
var a = color.a; | ||
var newAlpha = a - (a * (percentage / 100)); | ||
@@ -154,7 +150,6 @@ return make.fromHsl(h, s, l, (newAlpha < 0) ? 0 : newAlpha); | ||
var c = parse(color); | ||
var h = c.h; | ||
var s = c.s; | ||
var l = c.l; | ||
var a = c.a; | ||
var h = color.h; | ||
var s = color.s; | ||
var l = color.l; | ||
var a = color.a; | ||
var newSaturation = s + (s * (percentage / 100)); | ||
@@ -167,7 +162,6 @@ return make.fromHsl(h, (newSaturation > 100) ? 100 : newSaturation, l, a); | ||
var c = parse(color); | ||
var h = c.h; | ||
var s = c.s; | ||
var l = c.l; | ||
var a = c.a; | ||
var h = color.h; | ||
var s = color.s; | ||
var l = color.l; | ||
var a = color.a; | ||
var newSaturation = s - (s * (percentage / 100)); | ||
@@ -174,0 +168,0 @@ return make.fromHsl(h, (newSaturation < 0) ? 0 : newSaturation, l, a); |
@@ -1,2 +0,2 @@ | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):r.polychrome=n()}(this,function(){"use strict";var r={hex:/^#(?:[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,rgb:/^rgba?\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),?\s*(\d\.\d+)?\)$/,hsl:/^hsla?\((\d{1,3}),\s*(\d{1,3})%,\s*(\d{1,3})%,?\s*(\d\.\d+)?\)$/},n=Object.assign({},r,{asList:Object.keys(r).map(function(n){return{name:n,regex:r[n]}})}),t=function(r,n,t){return[r,n,t].map(function(r){return parseInt(r,16)})},e=function(r,n,t){return[r,n,t].map(function(r){return("0"+parseInt(r,10).toString(16)).toUpperCase().slice(-2)})},u=function(r,n,t,e){void 0===e&&(e=1);var u=[r,n,t].map(function(r){return r/255}),o=u[0],a=u[1],i=u[2],c=Math.max(o,a,i),f=Math.min(o,a,i),s=c-f,l=(c+f)/2;if(c===f)return[0,0,Math.round(100*l),e];var d=l<.5?s/(c+f):s/(2-c-f),h=[o,a,i].map(function(r){return((c-r)/6+s/2)/s}),p=h[0],v=h[1],m=h[2],g=0;switch(c){case o:g=m-v;break;case a:g=1/3+p-m;break;case i:g=2/3+v-p}return g<0&&(g+=1),g>1&&(g-=1),[360*g,100*d,100*l,e].map(function(r){return Math.round(r)})},o=function(r,n,t,e){void 0===e&&(e=1);var u=[r/360,n/100,t/100],o=u[0],a=u[1],i=u[2];if(0==a)return[i,i,i].map(function(r){return Math.round(255*r)}).concat(e);var c=function(r,n,t){return t<0&&(t+=1),t>1&&(t-=1),6*t<1?r+6*(n-r)*t:2*t<1?n:3*t<2?r+(n-r)*(2/3-t)*6:r},f=i<.5?i*(1+a):i+a-i*a,s=2*i-f;return[c(s,f,o+1/3),c(s,f,o),c(s,f,o-1/3)].map(function(r){return Math.round(255*r)}).concat(e)},a=function(r,n){void 0===n&&(n=10);var t=m(r),e=t.h,u=t.s,o=t.l,a=t.a,i=o-o*(n/100);return p.fromHsl(e,u,i<0?0:i,a)},i=function(r,n){void 0===n&&(n=10);var t=m(r),e=t.h,u=t.s,o=t.l,a=t.a,i=o+o*(n/100);return p.fromHsl(e,u,i>100?100:i,a)},c=function(r,n){void 0===n&&(n=50);var t=m(r),e=t.h,u=t.s,o=t.l,a=t.a,i=a+a*(n/100);return p.fromHsl(e,u,o,i>1?1:i)},f=function(r,n){void 0===n&&(n=50);var t=m(r),e=t.h,u=t.s,o=t.l,a=t.a,i=a-a*(n/100);return p.fromHsl(e,u,o,i<0?0:i)},s=function(r,n,t){void 0===n&&(n=m("#000")),void 0===t&&(t=m("#FFF"));var e="string"==typeof n?m(n):n,u="string"==typeof t?m(t):t;return m(r).luma<128?u:e},l=function(r,n){void 0===n&&(n=10);var t=m(r),e=t.h,u=t.s,o=t.l,a=t.a,i=u+u*(n/100);return p.fromHsl(e,i>100?100:i,o,a)},d=function(r,n){void 0===n&&(n=10);var t=m(r),e=t.h,u=t.s,o=t.l,a=t.a,i=u-u*(n/100);return p.fromHsl(e,i<0?0:i,o,a)},h=function(r){var n=r.rHex,t=r.gHex,e=r.bHex,u=r.r,o=r.g,h=r.b,p=r.h,v=r.s,m=r.l,g=r.a;void 0===g&&(g=1);var b=Object.assign({},r,{hex:function(){return"#"+n+t+e},rgb:function(){return g<1?"rgba("+u+","+o+","+h+","+g+")":"rgb("+u+","+o+","+h+")"},hsl:function(){return g<1?"hsla("+p+","+v+"%,"+m+"%,"+g+")":"hsl("+p+","+v+"%,"+m+"%)"},luma:(299*u+587*o+114*h)/1e3});return Object.assign({},b,{darken:function(r){return a(b,r)},lighten:function(r){return i(b,r)},fadeIn:function(r){return c(b,r)},fadeOut:function(r){return f(b,r)},contrast:function(r,n){return s(b,r,n)},saturate:function(r){return l(b,r)},desaturate:function(r){return d(b,r)}})},p={fromHex:function(r,n,e){var o=t(r,n,e),a=o[0],i=o[1],c=o[2],f=u(a,i,c);return h({rHex:r,gHex:n,bHex:e,r:a,g:i,b:c,h:f[0],s:f[1],l:f[2],a:f[3]})},fromRgb:function(r,n,t,o){void 0===o&&(o=1);var a=e(r,n,t),i=a[0],c=a[1],f=a[2],s=u(r,n,t);return h({rHex:i,gHex:c,bHex:f,r:r,g:n,b:t,h:s[0],s:s[1],l:s[2],a:o})},fromHsl:function(r,n,t,u){void 0===u&&(u=1);var a=o(r,n,t),i=a[0],c=a[1],f=a[2],s=e(i,c,f);return h({rHex:s[0],gHex:s[1],bHex:s[2],r:i,g:c,b:f,h:r,s:n,l:t,a:u})}},v={hex:function r(n){var r=n.replace("#","");return r.length<6&&(r=r.split("").map(function(r){return r.concat(r)}).join("")),[r.slice(0,2),r.slice(2,4),r.slice(4,6)]},rgb:function(r){var t=r.match(n.rgb).slice(1),e=t[0],u=t[1],o=t[2],a=t[3];return void 0===a&&(a=1),[parseInt(e),parseInt(u),parseInt(o),parseFloat(a)]},hsl:function(r){var t=r.match(n.hsl).slice(1),e=t[0],u=t[1],o=t[2],a=t[3];return void 0===a&&(a=1),[parseInt(e),parseInt(u),parseInt(o),parseFloat(a)]}},m=function(r){if(!r)return p.fromRgb(0,0,0);if("string"!=typeof r)return r;var t=n.asList.filter(function(n){return r.match(n.regex)});if(!t.length)throw new Error("No matching color patterns found for "+r);return t.reduce(function(n,t){var e=t.name;return p["from"+e.charAt(0).toUpperCase()+e.slice(1)].apply(p,v[e](r))},{})};return m}); | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):r.polychrome=n()}(this,function(){"use strict";var r={hex:/^#(?:[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,rgb:/^rgba?\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),?\s*(\d\.\d+)?\)$/,hsl:/^hsla?\((\d{1,3}),\s*(\d{1,3})%,\s*(\d{1,3})%,?\s*(\d\.\d+)?\)$/},n=Object.assign({},r,{asList:Object.keys(r).map(function(n){return{name:n,regex:r[n]}})}),t=function(r,n,t){return[r,n,t].map(function(r){return parseInt(r,16)})},e=function(r,n,t){return[r,n,t].map(function(r){return("0"+parseInt(r,10).toString(16)).toUpperCase().slice(-2)})},u=function(r,n,t,e){void 0===e&&(e=1);var u=[r,n,t].map(function(r){return r/255}),o=u[0],a=u[1],i=u[2],c=Math.max(o,a,i),f=Math.min(o,a,i),s=c-f,l=(c+f)/2;if(c===f)return[0,0,Math.round(100*l),e];var d=l<.5?s/(c+f):s/(2-c-f),h=[o,a,i].map(function(r){return((c-r)/6+s/2)/s}),p=h[0],v=h[1],m=h[2],g=0;switch(c){case o:g=m-v;break;case a:g=1/3+p-m;break;case i:g=2/3+v-p}return g<0&&(g+=1),g>1&&(g-=1),[360*g,100*d,100*l,e].map(function(r){return Math.round(r)})},o=function(r,n,t,e){void 0===e&&(e=1);var u=[r/360,n/100,t/100],o=u[0],a=u[1],i=u[2];if(0==a)return[i,i,i].map(function(r){return Math.round(255*r)}).concat(e);var c=function(r,n,t){return t<0&&(t+=1),t>1&&(t-=1),6*t<1?r+6*(n-r)*t:2*t<1?n:3*t<2?r+(n-r)*(2/3-t)*6:r},f=i<.5?i*(1+a):i+a-i*a,s=2*i-f;return[c(s,f,o+1/3),c(s,f,o),c(s,f,o-1/3)].map(function(r){return Math.round(255*r)}).concat(e)},a=function(r,n){void 0===n&&(n=10);var t=r.h,e=r.s,u=r.l,o=r.a,a=u-u*(n/100);return p.fromHsl(t,e,a<0?0:a,o)},i=function(r,n){void 0===n&&(n=10);var t=r.h,e=r.s,u=r.l,o=r.a,a=u+u*(n/100);return p.fromHsl(t,e,a>100?100:a,o)},c=function(r,n){void 0===n&&(n=50);var t=r.h,e=r.s,u=r.l,o=r.a,a=o+o*(n/100);return p.fromHsl(t,e,u,a>1?1:a)},f=function(r,n){void 0===n&&(n=50);var t=r.h,e=r.s,u=r.l,o=r.a,a=o-o*(n/100);return p.fromHsl(t,e,u,a<0?0:a)},s=function(r,n,t){void 0===n&&(n=m("#000")),void 0===t&&(t=m("#FFF"));var e="string"==typeof n?m(n):n,u="string"==typeof t?m(t):t;return m(r).luma<128?u:e},l=function(r,n){void 0===n&&(n=10);var t=r.h,e=r.s,u=r.l,o=r.a,a=e+e*(n/100);return p.fromHsl(t,a>100?100:a,u,o)},d=function(r,n){void 0===n&&(n=10);var t=r.h,e=r.s,u=r.l,o=r.a,a=e-e*(n/100);return p.fromHsl(t,a<0?0:a,u,o)},h=function(r){var n=r.rHex,t=r.gHex,e=r.bHex,u=r.r,o=r.g,h=r.b,p=r.h,v=r.s,m=r.l,g=r.a;void 0===g&&(g=1);var b=Object.assign({},r,{hex:function(){return"#"+n+t+e},rgb:function(){return g<1?"rgba("+u+","+o+","+h+","+g+")":"rgb("+u+","+o+","+h+")"},hsl:function(){return g<1?"hsla("+p+","+v+"%,"+m+"%,"+g+")":"hsl("+p+","+v+"%,"+m+"%)"},luma:(299*u+587*o+114*h)/1e3});return Object.assign({},b,{darken:function(r){return a(b,r)},lighten:function(r){return i(b,r)},fadeIn:function(r){return c(b,r)},fadeOut:function(r){return f(b,r)},contrast:function(r,n){return s(b,r,n)},saturate:function(r){return l(b,r)},desaturate:function(r){return d(b,r)}})},p={fromHex:function(r,n,e){var o=t(r,n,e),a=o[0],i=o[1],c=o[2],f=u(a,i,c);return h({rHex:r,gHex:n,bHex:e,r:a,g:i,b:c,h:f[0],s:f[1],l:f[2],a:f[3]})},fromRgb:function(r,n,t,o){void 0===o&&(o=1);var a=e(r,n,t),i=a[0],c=a[1],f=a[2],s=u(r,n,t);return h({rHex:i,gHex:c,bHex:f,r:r,g:n,b:t,h:s[0],s:s[1],l:s[2],a:o})},fromHsl:function(r,n,t,u){void 0===u&&(u=1);var a=o(r,n,t),i=a[0],c=a[1],f=a[2],s=e(i,c,f);return h({rHex:s[0],gHex:s[1],bHex:s[2],r:i,g:c,b:f,h:r,s:n,l:t,a:u})}},v={hex:function r(n){var r=n.replace("#","");return r.length<6&&(r=r.split("").map(function(r){return r.concat(r)}).join("")),[r.slice(0,2),r.slice(2,4),r.slice(4,6)]},rgb:function(r){var t=r.match(n.rgb).slice(1),e=t[0],u=t[1],o=t[2],a=t[3];return void 0===a&&(a=1),[parseInt(e),parseInt(u),parseInt(o),parseFloat(a)]},hsl:function(r){var t=r.match(n.hsl).slice(1),e=t[0],u=t[1],o=t[2],a=t[3];return void 0===a&&(a=1),[parseInt(e),parseInt(u),parseInt(o),parseFloat(a)]}},m=function(r){if(!r)return p.fromRgb(0,0,0);if("string"!=typeof r)return r;var t=n.asList.filter(function(n){return r.match(n.regex)});if(!t.length)throw new Error("No matching color patterns found for "+r);return t.reduce(function(n,t){var e=t.name;return p["from"+e.charAt(0).toUpperCase()+e.slice(1)].apply(p,v[e](r))},{})};return m}); | ||
//# sourceMappingURL=polychrome.js.map |
{ | ||
"name": "polychrome", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"author": "Chad Donohue <chad.donohue@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "A small library for parsing and manipulating colors", |
# 🎨 `polychrome` | ||
>A small `< 2kB (gzipped)` library for parsing and manipulating colors | ||
>A small `1.65kB (gzipped)` library for parsing and manipulating colors | ||
@@ -30,7 +30,7 @@ ## Installation | ||
// Manipulate polychrome colors | ||
const darkerRed = red.darken(); // darkens 10% by default (pass in a percentage) | ||
darkerRed.hsl() // "hsl(0,100%,45%)" | ||
const darkerRed = red.darken(20); // (pass in an integer percentage) | ||
darkerRed.hsl() // "hsl(0,100%,40%)" | ||
// Chain polychrome methods together before outputting | ||
polychrome("#F00").darken().fadeOut().rgb() // "rgba(230,0,0,0.5)" | ||
polychrome("#F00").darken(20).fadeOut(60).rgb() // "rgba(204,0,0,0.4)" | ||
``` | ||
@@ -73,3 +73,3 @@ | ||
polychrome("#000").rgb() // "rgb(0,0,0)" | ||
polychrome("#000").fadeOut().rgb() // "rgba(0,0,0,.5) | ||
polychrome("#000").fadeOut(60).rgb() // "rgba(0,0,0,.4) | ||
``` | ||
@@ -82,3 +82,3 @@ | ||
polychrome("#000").hsl() // "hsl(0,0%,0%)" | ||
polychrome("#000").fadeOut().hsl() // "hsla(0,0%,0%,.5) | ||
polychrome("#000").fadeOut(60).hsl() // "hsla(0,0%,0%,.4) | ||
``` | ||
@@ -101,15 +101,15 @@ | ||
Returns a `polychrome` darkened by `percentage`. Default `10%` if no percentage is passed in. | ||
Returns a `polychrome` darkened by `percentage`. Default `10` if no percentage is passed in. | ||
- `.desaturate(percentage)` | ||
Returns a `polychrome` desaturated by `percentage`. Default `10%` if no percentage is passed in. | ||
Returns a `polychrome` desaturated by `percentage`. Default `10` if no percentage is passed in. | ||
- `.fadeIn(percentage)` | ||
Returns a `polychrome` faded in by `percentage`. Default `50%` if no percentage is passed in. | ||
Returns a `polychrome` faded in by `percentage`. Default `50` if no percentage is passed in. | ||
- `.fadeOut(percentage)` | ||
Returns a `polychrome` faded out by `percentage`. Default `50%` if no percentage is passed in. | ||
Returns a `polychrome` faded out by `percentage`. Default `50` if no percentage is passed in. | ||
@@ -119,7 +119,7 @@ | ||
Returns a `polychrome` lightened by `percentage`. Default `10%` if no percentage is passed in. | ||
Returns a `polychrome` lightened by `percentage`. Default `10` if no percentage is passed in. | ||
- `.saturate(percentage)` | ||
Returns a `polychrome` saturated by `percentage`. Default `10%` if no percentage is passed in. | ||
Returns a `polychrome` saturated by `percentage`. Default `10` if no percentage is passed in. | ||
@@ -126,0 +126,0 @@ --- |
@@ -142,6 +142,2 @@ import { expect } from "chai"; | ||
it("should lighten a color when passed a color string", () => { | ||
expect(lighten("#00F").hsl()).to.equal("hsl(240,100%,55%)"); | ||
}); | ||
it("should not lighten a color higher than 100%", () => { | ||
@@ -148,0 +144,0 @@ const white = parse("#FFF"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
158872
452