59 lines
40 KiB
JavaScript
59 lines
40 KiB
JavaScript
|
/**
|
||
|
* chroma.js - JavaScript library for color conversions
|
||
|
*
|
||
|
* Copyright (c) 2011-2019, Gregor Aisch
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* Redistribution and use in source and binary forms, with or without
|
||
|
* modification, are permitted provided that the following conditions are met:
|
||
|
*
|
||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||
|
* list of conditions and the following disclaimer.
|
||
|
*
|
||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||
|
* this list of conditions and the following disclaimer in the documentation
|
||
|
* and/or other materials provided with the distribution.
|
||
|
*
|
||
|
* 3. The name Gregor Aisch may not be used to endorse or promote products
|
||
|
* derived from this software without specific prior written permission.
|
||
|
*
|
||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||
|
* DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||
|
*
|
||
|
* -------------------------------------------------------
|
||
|
*
|
||
|
* chroma.js includes colors from colorbrewer2.org, which are released under
|
||
|
* the following license:
|
||
|
*
|
||
|
* Copyright (c) 2002 Cynthia Brewer, Mark Harrower,
|
||
|
* and The Pennsylvania State University.
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing,
|
||
|
* software distributed under the License is distributed on an
|
||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||
|
* either express or implied. See the License for the specific
|
||
|
* language governing permissions and limitations under the License.
|
||
|
*
|
||
|
* ------------------------------------------------------
|
||
|
*
|
||
|
* Named colors are taken from X11 Color Names.
|
||
|
* http://www.w3.org/TR/css3-color/#svg-color
|
||
|
*
|
||
|
* @preserve
|
||
|
*/
|
||
|
|
||
|
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):r.chroma=e()}(this,function(){"use strict";for(var t=function(r,e,t){return void 0===e&&(e=0),void 0===t&&(t=1),r<e?e:t<r?t:r},e={},r=0,n=["Boolean","Number","String","Function","Array","Date","RegExp","Undefined","Null"];r<n.length;r+=1){var a=n[r];e["[object "+a+"]"]=a.toLowerCase()}var Y=function(r){return e[Object.prototype.toString.call(r)]||"object"},f=Math.PI,o={clip_rgb:function(r){r._clipped=!1,r._unclipped=r.slice(0);for(var e=0;e<=3;e++)e<3?((r[e]<0||255<r[e])&&(r._clipped=!0),r[e]=t(r[e],0,255)):3===e&&(r[e]=t(r[e],0,1));return r},limit:t,type:Y,unpack:function(e,r){return void 0===r&&(r=null),3<=e.length?Array.prototype.slice.call(e):"object"==Y(e[0])&&r?r.split("").filter(function(r){return void 0!==e[0][r]}).map(function(r){return e[0][r]}):e[0]},last:function(r){if(r.length<2)return null;var e=r.length-1;return"string"==Y(r[e])?r[e].toLowerCase():null},PI:f,TWOPI:2*f,PITHIRD:f/3,DEG2RAD:f/180,RAD2DEG:180/f},b={format:{},autodetect:[]},c=o.last,i=o.clip_rgb,l=o.type,u=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("object"===l(r[0])&&r[0].constructor&&r[0].constructor===this.constructor)return r[0];var t=c(r),n=!1;if(!t){n=!0,b.sorted||(b.autodetect=b.autodetect.sort(function(r,e){return e.p-r.p}),b.sorted=!0);for(var a=0,f=b.autodetect;a<f.length;a+=1){var o=f[a];if(t=o.test.apply(o,r))break}}if(!b.format[t])throw new Error("unknown format: "+r);var u=b.format[t].apply(null,n?r:r.slice(0,-1));this._rgb=i(u),3===this._rgb.length&&this._rgb.push(1)};u.prototype.toString=function(){return"function"==l(this.hex)?this.hex():"["+this._rgb.join(",")+"]"};var A=u,h=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(h.Color,[null].concat(r)))};h.Color=A,h.version="2.0.3";var N=h,d=o.unpack,s=Math.max,p=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var t=d(r,"rgb"),n=t[0],a=t[1],f=t[2],o=1-s(n/=255,s(a/=255,f/=255)),u=o<1?1/(1-o):0;return[(1-n-o)*u,(1-a-o)*u,(1-f-o)*u,o]},g=o.unpack,v=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var t=(r=g(r,"cmyk"))[0],n=r[1],a=r[2],f=r[3],o=4<r.length?r[4]:1;return 1===f?[0,0,0,o]:[1<=t?0:255*(1-t)*(1-f),1<=n?0:255*(1-n)*(1-f),1<=a?0:255*(1-a)*(1-f),o]},m=o.unpack,y=o.type;A.prototype.cmyk=function(){return p(this._rgb)},N.cmyk=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(A,[null].concat(r,["cmyk"])))},b.format.cmyk=v,b.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if(r=m(r,"cmyk"),"array"===y(r)&&4===r.length)return"cmyk"}});var w=o.unpack,k=o.last,M=function(r){return Math.round(100*r)/100},_=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var t=w(r,"hsla"),n=k(r)||"lsa";return t[0]=M(t[0]||0),t[1]=M(100*t[1])+"%",t[2]=M(100*t[2])+"%","hsla"===n||3<t.length&&t[3]<1?(t[3]=3<t.length?t[3]:1,n="hsla"):t.length=3,n+"("+t.join(",")+")"},x=o.unpack,E=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var t=(r=x(r,"rgba"))[0],n=r[1],a=r[2];t/=255,n/=255,a/=255;var f,o,u=Math.min(t,n,a),c=Math.max(t,n,a),i=(c+u)/2;return c===u?(f=0,o=Number.NaN):f=i<.5?(c-u)/(c+u):(c-u)/(2-c-u),t==c?o=(n-a)/(c-u):n==c?o=2+(a-t)/(c-u):a==c&&(o=4+(t-n)/(c-u)),(o*=60)<0&&(o+=360),3<r.length&&void 0!==r[3]?[o,f,i,r[3]]:[o,f,i]},P=o.unpack,F=o.last,O=Math.round,j=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var t=P(r,"rgba"),n=F(r)||"rgb";return"hsl"==n.substr(0,3)?_(E(t),n):(t[0]=O(t[0]),t[1]=O(t[1]),t[2]=O(t[2]),("rgba"===n||3<t.length&&t[3]<1)&&(t[3]=3<t.length?t[3]:1,n="rgba"),n+"("+t.slice(0,"rgb"===n?3:4).join(",")+")")},G=o.unpack,q=Math.round,L=function(){for(var r,e=[],t=arguments.length;t--;)e[t]=arguments[t];var n,a,f,o=(e=G(e,"hsl"))[0],u=e[1],c=e[2];if(0===u)n=a=f=255*c;else{var i=[0,0,0],l=[0,0,0],h=c<.5?c*(1+u):c+u-c*u,d=2*c-h,s=o/360;i[0]=s+1/3,i[1]=s,i[2]=s-1/3;for(var b=0;b<3;b++)
|