colors-generator
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,1 +0,1 @@ | ||
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.colors=r():t.colors=r()}(this,function(){return function(t){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}var e={};return r.m=t,r.c=e,r.i=function(t){return t},r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get: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,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=2)}([function(t,r,e){"use strict";var n=e(1);t.exports={generate:function(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,e=(0,n.RGBToHSL)(t),o=360*e[0],u=360/r,i=[],c=0;c<r;c++){var a=(o+c*u)%360/360;i.push((0,n.HSLToRGB)([a,e[1],e[2]]))}return i}}},function(t,r,e){"use strict";function n(t){var r=c(t,3),e=r[0],n=r[1],o=r[2],u=void 0,a=void 0,f=void 0,s=function(t,r,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?t+6*(r-t)*e:e<.5?r:e<2/3?t+(r-t)*(2/3-e)*6:t};if(0===n)u=a=f=o;else{var l=o<.5?o*(1+n):o+n-o*n,p=2*o-l;u=s(p,l,e+1/3),a=s(p,l,e),f=s(p,l,e-1/3)}return"#"+[255*u,255*a,255*f].map(function(t){return i(Math.round(t))}).join("")}function o(t){t=t.substr(t.indexOf("#")+1),3===t.length&&(t=t.charAt(0)+t.charAt(0)+t.charAt(1)+t.charAt(1)+t.charAt(2)+t.charAt(2));var r=u(t.substr(0,2))/255,e=u(t.substr(2,2))/255,n=u(t.substr(4,2))/255,o=Math.max(r,e,n),i=Math.min(r,e,n),c=o-i,a=(o+i)/2,f=0,s=0;if(c){switch(s=a>.5?c/(2-o-i):c/(o+i),o){case r:f=(e-n)/c+(e<n?6:0);break;case e:f=(n-r)/c+2;break;case n:f=(r-e)/c+4}f/=6}return[f,s,a]}function u(t){return parseInt(t,16)}function i(t){var r=t.toString(16);return 1===r.length?"0"+r:r}Object.defineProperty(r,"__esModule",{value:!0});var c=function(){function t(t,r){var e=[],n=!0,o=!1,u=void 0;try{for(var i,c=t[Symbol.iterator]();!(n=(i=c.next()).done)&&(e.push(i.value),!r||e.length!==r);n=!0);}catch(t){o=!0,u=t}finally{try{!n&&c.return&&c.return()}finally{if(o)throw u}}return e}return function(r,e){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return t(r,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();r.HSLToRGB=n,r.RGBToHSL=o},function(t,r,e){"use strict";t.exports=e(0)}])}); | ||
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.colors=r():t.colors=r()}(this,function(){return function(t){function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var n={};return r.m=t,r.c=n,r.i=function(t){return t},r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:e})},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=2)}([function(t,r,n){"use strict";function e(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}var o=function(){function t(t,r){for(var n=0;n<r.length;n++){var e=r[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}return function(r,n,e){return n&&t(r.prototype,n),e&&t(r,e),r}}(),u=n(1),i=function(){function t(){e(this,t),this.colors=[]}return o(t,[{key:"get",value:function(){return this.colors}},{key:"generate",value:function(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,n=(0,u.RGBToHSL)(t),e=360*n[0],o=360/r,i=[],a=0;a<r;a++){var c=(e+a*o)%360/360;i.push((0,u.HSLToRGB)([c,n[1],n[2]]))}return this.colors=i,this}},{key:"lighter",value:function(t){return this.colors=this.colors.map(function(r){var n=(0,u.RGBToHSL)(r);return n[2]=Math.min(n[2]+t,1),(0,u.HSLToRGB)(n)}),this}},{key:"darker",value:function(t){return this.colors=this.colors.map(function(r){var n=(0,u.RGBToHSL)(r);return n[2]=Math.max(n[2]-t,0),(0,u.HSLToRGB)(n)}),this}},{key:"purer",value:function(t){return this.colors=this.colors.map(function(r){var n=(0,u.RGBToHSL)(r);return n[1]=Math.min(n[1]+t,1),(0,u.HSLToRGB)(n)}),this}},{key:"impurer",value:function(t){return this.colors=this.colors.map(function(r){var n=(0,u.RGBToHSL)(r);return n[1]=Math.max(n[1]-t,0),(0,u.HSLToRGB)(n)}),this}}]),t}();t.exports=new i},function(t,r,n){"use strict";function e(t){var r=a(t,3),n=r[0],e=r[1],o=r[2],u=void 0,c=void 0,s=void 0,f=function(t,r,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(r-t)*n:n<.5?r:n<2/3?t+(r-t)*(2/3-n)*6:t};if(0===e)u=c=s=o;else{var l=o<.5?o*(1+e):o+e-o*e,h=2*o-l;u=f(h,l,n+1/3),c=f(h,l,n),s=f(h,l,n-1/3)}return"#"+[255*u,255*c,255*s].map(function(t){return i(Math.round(t))}).join("")}function o(t){t=t.substr(t.indexOf("#")+1),3===t.length&&(t=t.charAt(0)+t.charAt(0)+t.charAt(1)+t.charAt(1)+t.charAt(2)+t.charAt(2));var r=u(t.substr(0,2))/255,n=u(t.substr(2,2))/255,e=u(t.substr(4,2))/255,o=Math.max(r,n,e),i=Math.min(r,n,e),a=o-i,c=(o+i)/2,s=0,f=0;if(a){switch(f=c>.5?a/(2-o-i):a/(o+i),o){case r:s=(n-e)/a+(n<e?6:0);break;case n:s=(e-r)/a+2;break;case e:s=(r-n)/a+4}s/=6}return[s,f,c]}function u(t){return parseInt(t,16)}function i(t){var r=t.toString(16);return 1===r.length?"0"+r:r}Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function t(t,r){var n=[],e=!0,o=!1,u=void 0;try{for(var i,a=t[Symbol.iterator]();!(e=(i=a.next()).done)&&(n.push(i.value),!r||n.length!==r);e=!0);}catch(t){o=!0,u=t}finally{try{!e&&a.return&&a.return()}finally{if(o)throw u}}return n}return function(r,n){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return t(r,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();r.HSLToRGB=e,r.RGBToHSL=o},function(t,r,n){"use strict";t.exports=n(0)}])}); |
{ | ||
"name": "colors-generator", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/colors-generator.js", |
# 颜色生成 | ||
在基础色的基础上,,通过H值多层均分,生成多个颜色,应用场景如图表的图例展示 | ||
在基础色的基础上,,通过H值多层均分,生成同一亮度和纯度的多个颜色,应用场景如图表的图例展示 | ||
## api | ||
``` | ||
// 根据基础色生成色系 | ||
generate(color, num).get() | ||
// 提高亮度 | ||
generate(color, num).lighter(0.2).get() | ||
// 减少亮度 | ||
generate(color, num).darker(0.2).get() | ||
// 提高纯度 | ||
generate(color, num).purer(0.2).get() | ||
// 减少纯度 | ||
generate(color, num).impurer(0.2).get() | ||
``` |
@@ -7,3 +7,11 @@ import { | ||
module.exports = { | ||
class Colors { | ||
constructor() { | ||
this.colors = [] | ||
} | ||
get() { | ||
return this.colors | ||
} | ||
generate(color, num = 20) { | ||
@@ -13,12 +21,50 @@ const hsl = RGBToHSL(color) | ||
const step = 360 / num | ||
const colors = [] | ||
const ret = [] | ||
for (let i = 0; i < num; i++) { | ||
const newH = ((h + i * step) % 360) / 360 | ||
ret.push(HSLToRGB([newH, hsl[1], hsl[2]])) | ||
colors.push(HSLToRGB([newH, hsl[1], hsl[2]])) | ||
} | ||
return ret | ||
this.colors = colors | ||
return this | ||
} | ||
lighter(val) { | ||
this.colors = this.colors.map((color) => { | ||
const hsl = RGBToHSL(color) | ||
hsl[2] = Math.min(hsl[2] + val, 1) | ||
return HSLToRGB(hsl) | ||
}) | ||
return this | ||
} | ||
darker(val) { | ||
this.colors = this.colors.map((color) => { | ||
const hsl = RGBToHSL(color) | ||
hsl[2] = Math.max(hsl[2] - val, 0) | ||
return HSLToRGB(hsl) | ||
}) | ||
return this | ||
} | ||
purer(val) { | ||
this.colors = this.colors.map((color) => { | ||
const hsl = RGBToHSL(color) | ||
hsl[1] = Math.min(hsl[1] + val, 1) | ||
return HSLToRGB(hsl) | ||
}) | ||
return this | ||
} | ||
impurer(val) { | ||
this.colors = this.colors.map((color) => { | ||
const hsl = RGBToHSL(color) | ||
hsl[1] = Math.max(hsl[1] - val, 0) | ||
return HSLToRGB(hsl) | ||
}) | ||
return this | ||
} | ||
} | ||
module.exports = new Colors() |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
'use strict' | ||
/** | ||
@@ -68,9 +68,9 @@ * https://zh.wikipedia.org/wiki/HSL%E5%92%8CHSV%E8%89%B2%E5%BD%A9%E7%A9%BA%E9%97%B4#.E4.BB.8ERGB.E5.88.B0HSL.E6.88.96HSV.E7.9A.84.E8.BD.AC.E6.8D.A2 | ||
h = (g - b) / diff + (g < b ? 6 : 0) | ||
break; | ||
break | ||
case g: | ||
h = (b - r) / diff + 2 | ||
break; | ||
break | ||
case b: | ||
h = (r - g) / diff + 4 | ||
break; | ||
break | ||
} | ||
@@ -77,0 +77,0 @@ |
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
9154
166
23