@d3plus/color 3.0.16 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,78 +4,76 @@
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT
6
6
  */
7
- (e=>{"function"==typeof define&&define.amd?define(e):e()})(function(){if("undefined"!=typeof window){try{if("undefined"==typeof SVGElement||Boolean(SVGElement.prototype.innerHTML))return}catch(e){return}function n(e){switch(e.nodeType){case 1:var t=e,r="";return r+="<"+t.tagName,t.hasAttributes()&&[].forEach.call(t.attributes,function(e){r+=" "+e.name+'="'+e.value+'"'}),r+=">",t.hasChildNodes()&&[].forEach.call(t.childNodes,function(e){r+=n(e)}),r+="</"+t.tagName+">";case 3:return e.textContent.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");case 8:return"\x3c!--"+e.nodeValue+"--\x3e"}}Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var t="";return[].forEach.call(this.childNodes,function(e){t+=n(e)}),t},set:function(e){for(;this.firstChild;)this.removeChild(this.firstChild);try{var t=new DOMParser,r=(t.async=!1,"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+e+"</svg>"),n=t.parseFromString(r,"text/xml").documentElement;[].forEach.call(n.childNodes,function(e){this.appendChild(this.ownerDocument.importNode(e,!0))}.bind(this))}catch(e){throw new Error("Error parsing markup string")}}}),Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(e){this.innerHTML=e}})}}),((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("@d3plus/color",["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).d3plus={})})(this,function(e){function t(e,t,r){(e.prototype=t.prototype=r).constructor=e}function r(e,t){var r,n=Object.create(e.prototype);for(r in t)n[r]=t[r];return n}function f(){}var n,i,a=1/.7,o="\\s*([+-]?\\d+)\\s*",s="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",l="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",c=/^#([0-9a-f]{3,8})$/,T=new RegExp(`^rgb\\(${o},${o},${o}\\)$`),P=new RegExp(`^rgb\\(${l},${l},${l}\\)$`),V=new RegExp(`^rgba\\(${o},${o},${o},${s}\\)$`),G=new RegExp(`^rgba\\(${l},${l},${l},${s}\\)$`),A=new RegExp(`^hsl\\(${s},${l},${l}\\)$`),D=new RegExp(`^hsla\\(${s},${l},${l},${s}\\)$`),h={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function u(){return this.rgb().formatHex()}function d(){return this.rgb().formatRgb()}function g(e){var t,r;return e=(e+"").trim().toLowerCase(),(t=c.exec(e))?(r=t[1].length,t=parseInt(t[1],16),6===r?b(t):3===r?new y(t>>8&15|t>>4&240,t>>4&15|240&t,(15&t)<<4|15&t,1):8===r?p(t>>24&255,t>>16&255,t>>8&255,(255&t)/255):4===r?p(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|240&t,((15&t)<<4|15&t)/255):null):(t=T.exec(e))?new y(t[1],t[2],t[3],1):(t=P.exec(e))?new y(255*t[1]/100,255*t[2]/100,255*t[3]/100,1):(t=V.exec(e))?p(t[1],t[2],t[3],t[4]):(t=G.exec(e))?p(255*t[1]/100,255*t[2]/100,255*t[3]/100,t[4]):(t=A.exec(e))?N(t[1],t[2]/100,t[3]/100,1):(t=D.exec(e))?N(t[1],t[2]/100,t[3]/100,t[4]):h.hasOwnProperty(e)?b(h[e]):"transparent"===e?new y(NaN,NaN,NaN,0):null}function b(e){return new y(e>>16&255,e>>8&255,255&e,1)}function p(e,t,r,n){return new y(e=n<=0?t=r=NaN:e,t,r,n)}function m(e,t,r,n){return 1===arguments.length?(i=(i=e)instanceof f?i:g(i))?new y((i=i.rgb()).r,i.g,i.b,i.opacity):new y:new y(e,t,r,null==n?1:n);var i}function y(e,t,r,n){this.r=+e,this.g=+t,this.b=+r,this.opacity=+n}function w(){return"#"+x(this.r)+x(this.g)+x(this.b)}function k(){var e=v(this.opacity);return(1===e?"rgb(":"rgba(")+$(this.r)+`, ${$(this.g)}, `+$(this.b)+(1===e?")":`, ${e})`)}function v(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function $(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function x(e){return((e=$(e))<16?"0":"")+e.toString(16)}function N(e,t,r,n){return n<=0?e=t=r=NaN:r<=0||1<=r?e=t=NaN:t<=0&&(e=NaN),new S(e,t,r,n)}function M(e){var t,r,n,i,a,o,s,l;return e instanceof S?new S(e.h,e.s,e.l,e.opacity):(e=e instanceof f?e:g(e))?e instanceof S?e:(t=(e=e.rgb()).r/255,r=e.g/255,n=e.b/255,i=Math.min(t,r,n),o=NaN,l=((a=Math.max(t,r,n))+i)/2,(s=a-i)?(o=t===a?(r-n)/s+6*(r<n):r===a?(n-t)/s+2:(t-r)/s+4,s/=l<.5?a+i:2-a-i,o*=60):s=0<l&&l<1?0:o,new S(o,s,l,e.opacity)):new S}function E(e,t,r,n){return 1===arguments.length?M(e):new S(e,t,r,null==n?1:n)}function S(e,t,r,n){this.h=+e,this.s=+t,this.l=+r,this.opacity=+n}function H(e){return(e=(e||0)%360)<0?e+360:e}function O(e){return Math.max(0,Math.min(1,e||0))}
8
- /* From FvD 13.37, CSS Color Module Level 3 */function _(e,t,r){return 255*(e<60?t+(r-t)*e/60:e<180?r:e<240?t+(r-t)*(240-e)/60:t)}
7
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("@d3plus/color",["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).d3plus={})}(this,function(e){function t(e,t,r){e.prototype=t.prototype=r,r.constructor=e}function r(e,t){var r=Object.create(e.prototype);for(var n in t)r[n]=t[n];return r}function n(){}var i=.7,o=1/i,a="\\s*([+-]?\\d+)\\s*",s="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",l="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",f=/^#([0-9a-f]{3,8})$/,c=new RegExp(`^rgb\\(${a},${a},${a}\\)$`),u=new RegExp(`^rgb\\(${l},${l},${l}\\)$`),h=new RegExp(`^rgba\\(${a},${a},${a},${s}\\)$`),d=new RegExp(`^rgba\\(${l},${l},${l},${s}\\)$`),g=new RegExp(`^hsl\\(${s},${l},${l}\\)$`),b=new RegExp(`^hsla\\(${s},${l},${l},${s}\\)$`),p={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function y(){return this.rgb().formatHex()}function m(){return this.rgb().formatRgb()}function w(e){var t,r;return e=(e+"").trim().toLowerCase(),(t=f.exec(e))?(r=t[1].length,t=parseInt(t[1],16),6===r?$(t):3===r?new x(t>>8&15|t>>4&240,t>>4&15|240&t,(15&t)<<4|15&t,1):8===r?k(t>>24&255,t>>16&255,t>>8&255,(255&t)/255):4===r?k(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|240&t,((15&t)<<4|15&t)/255):null):(t=c.exec(e))?new x(t[1],t[2],t[3],1):(t=u.exec(e))?new x(255*t[1]/100,255*t[2]/100,255*t[3]/100,1):(t=h.exec(e))?k(t[1],t[2],t[3],t[4]):(t=d.exec(e))?k(255*t[1]/100,255*t[2]/100,255*t[3]/100,t[4]):(t=g.exec(e))?R(t[1],t[2]/100,t[3]/100,1):(t=b.exec(e))?R(t[1],t[2]/100,t[3]/100,t[4]):p.hasOwnProperty(e)?$(p[e]):"transparent"===e?new x(NaN,NaN,NaN,0):null}function $(e){return new x(e>>16&255,e>>8&255,255&e,1)}function k(e,t,r,n){return n<=0&&(e=t=r=NaN),new x(e,t,r,n)}function v(e,t,r,i){return 1===arguments.length?((o=e)instanceof n||(o=w(o)),o?new x((o=o.rgb()).r,o.g,o.b,o.opacity):new x):new x(e,t,r,null==i?1:i);var o}function x(e,t,r,n){this.r=+e,this.g=+t,this.b=+r,this.opacity=+n}function N(){return`#${H(this.r)}${H(this.g)}${H(this.b)}`}function M(){const e=_(this.opacity);return`${1===e?"rgb(":"rgba("}${q(this.r)}, ${q(this.g)}, ${q(this.b)}${1===e?")":`, ${e})`}`}function _(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function q(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function H(e){return((e=q(e))<16?"0":"")+e.toString(16)}function R(e,t,r,n){return n<=0?e=t=r=NaN:r<=0||r>=1?e=t=NaN:t<=0&&(e=NaN),new O(e,t,r,n)}function S(e){if(e instanceof O)return new O(e.h,e.s,e.l,e.opacity);if(e instanceof n||(e=w(e)),!e)return new O;if(e instanceof O)return e;var t=(e=e.rgb()).r/255,r=e.g/255,i=e.b/255,o=Math.min(t,r,i),a=Math.max(t,r,i),s=NaN,l=a-o,f=(a+o)/2;return l?(s=t===a?(r-i)/l+6*(r<i):r===a?(i-t)/l+2:(t-r)/l+4,l/=f<.5?a+o:2-a-o,s*=60):l=f>0&&f<1?0:s,new O(s,l,f,e.opacity)}function E(e,t,r,n){return 1===arguments.length?S(e):new O(e,t,r,null==n?1:n)}function O(e,t,r,n){this.h=+e,this.s=+t,this.l=+r,this.opacity=+n}function j(e){return(e=(e||0)%360)<0?e+360:e}function A(e){return Math.max(0,Math.min(1,e||0))}
8
+ /* From FvD 13.37, CSS Color Module Level 3 */function L(e,t,r){return 255*(e<60?t+(r-t)*e/60:e<180?r:e<240?t+(r-t)*(240-e)/60:t)}
9
9
  /**
10
- @function colorAdd
11
- @desc Adds two colors together.
12
- @param {String} c1 The first color, a valid CSS color string.
13
- @param {String} c2 The second color, also a valid CSS color string.
14
- @param {String} [o1 = 1] Value from 0 to 1 of the first color's opacity.
15
- @param {String} [o2 = 1] Value from 0 to 1 of the first color's opacity.
16
- @returns {String}
17
- */t(f,g,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:u,formatHex:u,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return M(this).formatHsl()},formatRgb:d,toString:d}),t(y,m,r(f,{brighter(e){return e=null==e?a:Math.pow(a,e),new y(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=null==e?.7:Math.pow(.7,e),new y(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new y($(this.r),$(this.g),$(this.b),v(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:w,formatHex:w,formatHex8:function(){return"#"+x(this.r)+x(this.g)+x(this.b)+x(255*(isNaN(this.opacity)?1:this.opacity))},formatRgb:k,toString:k})),t(S,E,r(f,{brighter(e){return e=null==e?a:Math.pow(a,e),new S(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=null==e?.7:Math.pow(.7,e),new S(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+360*(this.h<0),t=isNaN(e)||isNaN(this.s)?0:this.s,r=this.l,t=r+(r<.5?r:1-r)*t,r=2*r-t;return new y(_(240<=e?e-240:120+e,r,t),_(e,r,t),_(e<120?240+e:e-120,r,t),this.opacity)},clamp(){return new S(H(this.h),O(this.s),O(this.l),v(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){var e=v(this.opacity);return(1===e?"hsl(":"hsla(")+H(this.h)+`, ${100*O(this.s)}%, ${100*O(this.l)}%`+(1===e?")":`, ${e})`)}}));class j extends Map{get(e){return super.get(q(this,e))}has(e){return super.has(q(this,e))}set(e,t){return super.set((({_intern:e,_key:t},r)=>(t=t(r),e.has(t)?e.get(t):(e.set(t,r),r)))(this,e),t)}delete(e){return super.delete((({_intern:e,_key:t},r)=>(t=t(r),e.has(t)&&(r=e.get(t),e.delete(t)),r))(this,e))}constructor(r,e=function(e){return null!==e&&"object"==typeof e?e.valueOf():e}){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:e}}),null!=r)for(let[e,t]of r)this.set(e,t)}}function q({_intern:e,_key:t},r){t=t(r);return e.has(t)?e.get(t):r}let R=Symbol("implicit");function z(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}
10
+ Adds two colors together.
11
+ @param c1 The first color, a valid CSS color string.
12
+ @param c2 The second color, also a valid CSS color string.
13
+ @param o1 Value from 0 to 1 of the first color's opacity.
14
+ @param o2 Value from 0 to 1 of the first color's opacity.
15
+ */t(n,w,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:y,formatHex:y,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return S(this).formatHsl()},formatRgb:m,toString:m}),t(x,v,r(n,{brighter(e){return e=null==e?o:Math.pow(o,e),new x(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=null==e?i:Math.pow(i,e),new x(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new x(q(this.r),q(this.g),q(this.b),_(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:N,formatHex:N,formatHex8:function(){return`#${H(this.r)}${H(this.g)}${H(this.b)}${H(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:M,toString:M})),t(O,E,r(n,{brighter(e){return e=null==e?o:Math.pow(o,e),new O(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=null==e?i:Math.pow(i,e),new O(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+360*(this.h<0),t=isNaN(e)||isNaN(this.s)?0:this.s,r=this.l,n=r+(r<.5?r:1-r)*t,i=2*r-n;return new x(L(e>=240?e-240:e+120,i,n),L(e,i,n),L(e<120?e+240:e-120,i,n),this.opacity)},clamp(){return new O(j(this.h),A(this.s),A(this.l),_(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=_(this.opacity);return`${1===e?"hsl(":"hsla("}${j(this.h)}, ${100*A(this.s)}%, ${100*A(this.l)}%${1===e?")":`, ${e})`}`}}));class P extends Map{get(e){return super.get(C(this,e))}has(e){return super.has(C(this,e))}set(e,t){return super.set(function({_intern:e,_key:t},r){const n=t(r);return e.has(n)?e.get(n):(e.set(n,r),r)}(this,e),t)}delete(e){return super.delete(function({_intern:e,_key:t},r){const n=t(r);e.has(n)&&(r=e.get(n),e.delete(n));return r}(this,e))}constructor(e,t=T){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:t}}),null!=e)for(const[t,r]of e)this.set(t,r)}}function C({_intern:e,_key:t},r){const n=t(r);return e.has(n)?e.get(n):r}function T(e){return null!==e&&"object"==typeof e?e.valueOf():e}function z(e,t){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(t).domain(e)}return this}const D=Symbol("implicit");function I(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}
18
16
  /*
19
17
  *
20
18
  * 𝗖 𝗢 𝗟 𝗢 𝗥
21
19
  * v 1.9.1
22
20
  *
23
- * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */i||(i=1,n={theme:{colors:{white:"#ffffff",black:"#000000",gray:{50:"#f8f9fa",100:"#f1f3f5",200:"#e9ecef",300:"#dee2e6",400:"#ced4da",500:"#adb5bd",600:"#868e96",700:"#495057",800:"#343a40",900:"#212529"},red:{50:"#fff5f5",100:"#ffe3e3",200:"#ffc9c9",300:"#ffa8a8",400:"#ff8787",500:"#ff6b6b",600:"#fa5252",700:"#f03e3e",800:"#e03131",900:"#c92a2a"},pink:{50:"#fff0f6",100:"#ffdeeb",200:"#fcc2d7",300:"#faa2c1",400:"#f783ac",500:"#f06595",600:"#e64980",700:"#d6336c",800:"#c2255c",900:"#a61e4d"},grape:{50:"#f8f0fc",100:"#f3d9fa",200:"#eebefa",300:"#e599f7",400:"#da77f2",500:"#cc5de8",600:"#be4bdb",700:"#ae3ec9",800:"#9c36b5",900:"#862e9c"},violet:{50:"#f3f0ff",100:"#e5dbff",200:"#d0bfff",300:"#b197fc",400:"#9775fa",500:"#845ef7",600:"#7950f2",700:"#7048e8",800:"#6741d9",900:"#5f3dc4"},indigo:{50:"#edf2ff",100:"#dbe4ff",200:"#bac8ff",300:"#91a7ff",400:"#748ffc",500:"#5c7cfa",600:"#4c6ef5",700:"#4263eb",800:"#3b5bdb",900:"#364fc7"},blue:{50:"#e7f5ff",100:"#d0ebff",200:"#a5d8ff",300:"#74c0fc",400:"#4dabf7",500:"#339af0",600:"#228be6",700:"#1c7ed6",800:"#1971c2",900:"#1864ab"},cyan:{50:"#e3fafc",100:"#c5f6fa",200:"#99e9f2",300:"#66d9e8",400:"#3bc9db",500:"#22b8cf",600:"#15aabf",700:"#1098ad",800:"#0c8599",900:"#0b7285"},teal:{50:"#e6fcf5",100:"#c3fae8",200:"#96f2d7",300:"#63e6be",400:"#38d9a9",500:"#20c997",600:"#12b886",700:"#0ca678",800:"#099268",900:"#087f5b"},green:{50:"#ebfbee",100:"#d3f9d8",200:"#b2f2bb",300:"#8ce99a",400:"#69db7c",500:"#51cf66",600:"#40c057",700:"#37b24d",800:"#2f9e44",900:"#2b8a3e"},lime:{50:"#f4fce3",100:"#e9fac8",200:"#d8f5a2",300:"#c0eb75",400:"#a9e34b",500:"#94d82d",600:"#82c91e",700:"#74b816",800:"#66a80f",900:"#5c940d"},yellow:{50:"#fff9db",100:"#fff3bf",200:"#ffec99",300:"#ffe066",400:"#ffd43b",500:"#fcc419",600:"#fab005",700:"#f59f00",800:"#f08c00",900:"#e67700"},orange:{50:"#fff4e6",100:"#ffe8cc",200:"#ffd8a8",300:"#ffc078",400:"#ffa94d",500:"#ff922b",600:"#fd7e14",700:"#f76707",800:"#e8590c",900:"#d9480f"}}},plugins:[]});o=z(n).theme;
21
+ * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */var B,F;var G=I(F?B:(F=1,B={theme:{colors:{white:"#ffffff",black:"#000000",gray:{50:"#f8f9fa",100:"#f1f3f5",200:"#e9ecef",300:"#dee2e6",400:"#ced4da",500:"#adb5bd",600:"#868e96",700:"#495057",800:"#343a40",900:"#212529"},red:{50:"#fff5f5",100:"#ffe3e3",200:"#ffc9c9",300:"#ffa8a8",400:"#ff8787",500:"#ff6b6b",600:"#fa5252",700:"#f03e3e",800:"#e03131",900:"#c92a2a"},pink:{50:"#fff0f6",100:"#ffdeeb",200:"#fcc2d7",300:"#faa2c1",400:"#f783ac",500:"#f06595",600:"#e64980",700:"#d6336c",800:"#c2255c",900:"#a61e4d"},grape:{50:"#f8f0fc",100:"#f3d9fa",200:"#eebefa",300:"#e599f7",400:"#da77f2",500:"#cc5de8",600:"#be4bdb",700:"#ae3ec9",800:"#9c36b5",900:"#862e9c"},violet:{50:"#f3f0ff",100:"#e5dbff",200:"#d0bfff",300:"#b197fc",400:"#9775fa",500:"#845ef7",600:"#7950f2",700:"#7048e8",800:"#6741d9",900:"#5f3dc4"},indigo:{50:"#edf2ff",100:"#dbe4ff",200:"#bac8ff",300:"#91a7ff",400:"#748ffc",500:"#5c7cfa",600:"#4c6ef5",700:"#4263eb",800:"#3b5bdb",900:"#364fc7"},blue:{50:"#e7f5ff",100:"#d0ebff",200:"#a5d8ff",300:"#74c0fc",400:"#4dabf7",500:"#339af0",600:"#228be6",700:"#1c7ed6",800:"#1971c2",900:"#1864ab"},cyan:{50:"#e3fafc",100:"#c5f6fa",200:"#99e9f2",300:"#66d9e8",400:"#3bc9db",500:"#22b8cf",600:"#15aabf",700:"#1098ad",800:"#0c8599",900:"#0b7285"},teal:{50:"#e6fcf5",100:"#c3fae8",200:"#96f2d7",300:"#63e6be",400:"#38d9a9",500:"#20c997",600:"#12b886",700:"#0ca678",800:"#099268",900:"#087f5b"},green:{50:"#ebfbee",100:"#d3f9d8",200:"#b2f2bb",300:"#8ce99a",400:"#69db7c",500:"#51cf66",600:"#40c057",700:"#37b24d",800:"#2f9e44",900:"#2b8a3e"},lime:{50:"#f4fce3",100:"#e9fac8",200:"#d8f5a2",300:"#c0eb75",400:"#a9e34b",500:"#94d82d",600:"#82c91e",700:"#74b816",800:"#66a80f",900:"#5c940d"},yellow:{50:"#fff9db",100:"#fff3bf",200:"#ffec99",300:"#ffe066",400:"#ffd43b",500:"#fcc419",600:"#fab005",700:"#f59f00",800:"#f08c00",900:"#e67700"},orange:{50:"#fff4e6",100:"#ffe8cc",200:"#ffd8a8",300:"#ffc078",400:"#ffa94d",500:"#ff922b",600:"#fd7e14",700:"#f76707",800:"#e8590c",900:"#d9480f"}}},plugins:[]}));const{theme:J}=G,K={dark:J.colors.gray[700],light:J.colors.gray[50],missing:J.colors.gray[400],off:J.colors.red[900],on:J.colors.green[900],scale:function e(){var t=new P,r=[],n=[],i=D;function o(e){let o=t.get(e);if(void 0===o){if(i!==D)return i;t.set(e,o=r.push(e)-1)}return n[o%n.length]}return o.domain=function(e){if(!arguments.length)return r.slice();r=[],t=new P;for(const n of e)t.has(n)||t.set(n,r.push(n)-1);return o},o.range=function(e){return arguments.length?(n=Array.from(e),o):n.slice()},o.unknown=function(e){return arguments.length?(i=e,o):i},o.copy=function(){return e(r,n).unknown(i)},z.apply(o,arguments),o}().range([J.colors.indigo[900],J.colors.yellow[600],J.colors.red[900],J.colors.green[900],J.colors.orange[600],J.colors.grape[900],J.colors.cyan[600],J.colors.pink[600],J.colors.lime[600],J.colors.blue[300],J.colors.pink[300],J.colors.lime[300],J.colors.violet[300],J.colors.cyan[100],J.colors.orange[100],J.colors.green[100],J.colors.grape[100],J.colors.red[100]])};
24
22
  /**
25
- @namespace {Object} colorDefaults
26
- @desc A set of default color values used when assigning colors based on data.
27
- */let C={dark:o.colors.gray[700],light:o.colors.gray[50],missing:o.colors.gray[400],off:o.colors.red[900],on:o.colors.green[900],scale:function e(){var r=new j,n=[],i=[],a=R;function o(e){let t=r.get(e);if(void 0===t){if(a!==R)return a;r.set(e,t=n.push(e)-1)}return i[t%i.length]}return o.domain=function(e){if(!arguments.length)return n.slice();n=[],r=new j;for(var t of e)r.has(t)||r.set(t,n.push(t)-1);return o},o.range=function(e){return arguments.length?(i=Array.from(e),o):i.slice()},o.unknown=function(e){return arguments.length?(a=e,o):a},o.copy=function(){return e(n,i).unknown(a)},function(e,t){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(t).domain(e)}return this}.apply(o,arguments),o}().range([o.colors.indigo[900],o.colors.yellow[600],o.colors.red[900],o.colors.green[900],o.colors.orange[600],o.colors.grape[900],o.colors.cyan[600],o.colors.pink[600],o.colors.lime[600],o.colors.blue[300],o.colors.pink[300],o.colors.lime[300],o.colors.violet[300],o.colors.cyan[100],o.colors.orange[100],o.colors.green[100],o.colors.grape[100],o.colors.red[100]])};
28
- /**
29
- Returns a color based on a key, whether it is present in a user supplied object or in the default object.
30
- @returns {String}
31
- @private
32
- */function L(e,t={}){return e in t?t[e]:e in C?C[e]:C.missing}
23
+ * A set of default color values used when assigning colors based on data.
24
+ *
25
+ * @defaultValue
26
+ * ```
27
+ * {
28
+ * dark: "#495057",
29
+ * light: "#f8f9fa",
30
+ * missing: "#ced4da",
31
+ * off: "#c92a2a",
32
+ * on: "#2b8a3e",
33
+ * scale: d3.scaleOrdinal().range([
34
+ * "#364fc7", "#fab005", "#c92a2a",
35
+ * "#2b8a3e", "#fd7e14", "#862e9c",
36
+ * "#15aabf", "#e64980", "#82c91e",
37
+ * "#74c0fc", "#faa2c1", "#c0eb75",
38
+ * "#b197fc", "#c5f6fa", "#ffe8cc",
39
+ * "#d3f9d8", "#f3d9fa", "#ffe3e3"
40
+ * ])
41
+ * }
42
+ * ```
43
+ */e.colorAdd=function(e,t,r=1,n=1){const i=E(e),o=E(t);let a=Math.abs(o.h*n-i.h*r);a>180&&(a-=360);let s=(Math.min(i.h,o.h)+a/2)%360;const l=i.l+(o.l*n-i.l*r)/2;return s<0&&(s+=360),E(`hsl(${s},${100*(i.s+(o.s*n-i.s*r)/2)}%,${100*l}%)`).toString()},e.colorAssign=
33
44
  /**
34
- @function colorAssign
35
- @desc Assigns a color to a value using a predefined set of defaults.
36
- @param {String} c A valid CSS color string.
37
- @param {Object} [u = defaults] An object containing overrides of the default colors.
38
- @returns {String}
39
- */e.colorAdd=function(e,t,r=1,n=1){e=E(e),t=E(t);let i=Math.abs(t.h*n-e.h*r),a=(180<i&&(i-=360),(Math.min(e.h,t.h)+i/2)%360);var o=e.l+(t.l*n-e.l*r)/2,t=e.s+(t.s*n-e.s*r)/2;
40
- // a = o1 + (o2 - o1) / 2;
41
- return a<0&&(a+=360),E(`hsl(${a},${100*t}%,${100*o}%)`).toString();
42
- // return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();
43
- },e.colorAssign=function(e,t={}){
45
+ Assigns a color to a value using a predefined set of defaults.
46
+ @param c A valid CSS color string.
47
+ @param u An object containing overrides of the default colors.
48
+ */
49
+ function(e,t={}){
44
50
  // If the value is null or undefined, set to grey.
45
- return 0<=[null,void 0].indexOf(e)?L("missing",t):!0===e?L("on",t):!1===e?L("off",t):
51
+ return[null,void 0].indexOf(e)>=0?t.missing||K.missing:!0===e?t.on||K.on:!1===e?t.off||K.off:
46
52
  // If the value is not a valid color string, use the color scale.
47
- g(e)?e.toString():L("scale",t)(e)}
53
+ w(e)?e:(t.scale||K.scale)(e)}
48
54
  /**
49
- @function colorContrast
50
- @desc A set of default color values used when assigning colors based on data.
51
- @param {String} c A valid CSS color string.
52
- @param {Object} [u = defaults] An object containing overrides of the default colors.
53
- @returns {String}
54
- */,e.colorContrast=function(e,t={}){return L(128<=(299*(e=m(e)).r+587*e.g+114*e.b)/1e3?"dark":"light",t)}
55
+ A set of default color values used when assigning colors based on data.
56
+ @param c A valid CSS color string.
57
+ @param u An object containing overrides of the default colors.
58
+ */,e.colorContrast=function(e,t={}){const r=v(e);return(299*r.r+587*r.g+114*r.b)/1e3>=128?t.dark||K.dark:t.light||K.light}
55
59
  /**
56
- @function colorLegible
57
- @desc Darkens a color so that it will appear legible on a white background.
58
- @param {String} c A valid CSS color string.
59
- @returns {String}
60
- */,e.colorDefaults=C,e.colorLegible=function(e){return.45<(e=E(e)).l&&(.8<e.s&&(e.s=.8),e.l=.45),e.toString()}
60
+ Darkens a color so that it will appear legible on a white background.
61
+ @param c A valid CSS color string.
62
+ */,e.colorDefaults=K,e.colorLegible=function(e){const t=E(e);return t.l>.45&&(t.s>.8&&(t.s=.8),t.l=.45),t.toString()}
61
63
  /**
62
- @function colorLighter
63
- @desc Similar to d3.color.brighter, except that this also reduces saturation so that colors don't appear neon.
64
- @param {String} c A valid CSS color string.
65
- @param {String} [i = 0.5] A value from 0 to 1 dictating the strength of the function.
66
- @returns {String}
67
- */,e.colorLighter=function(e,t=.5){return t*=1-(e=E(e)).l,e.l+=t,e.s-=t,e.toString()}
64
+ Similar to d3.color.brighter, except that this also reduces saturation so that colors don't appear neon.
65
+ @param c A valid CSS color string.
66
+ @param i Strength of the lightening effect, from 0 to 1.
67
+ */,e.colorLighter=function(e,t=.5){const r=E(e);return t*=1-r.l,r.l+=t,r.s-=t,r.toString()}
68
68
  /**
69
- @function colorSubtract
70
- @desc Subtracts one color from another.
71
- @param {String} c1 The base color, a valid CSS color string.
72
- @param {String} c2 The color to remove from the base color, also a valid CSS color string.
73
- @param {String} [o1 = 1] Value from 0 to 1 of the first color's opacity.
74
- @param {String} [o2 = 1] Value from 0 to 1 of the first color's opacity.
75
- @returns {String}
76
- */,e.colorSubtract=function(e,t,r=1,n=1){e=E(e);let i=(t=E(t)).h*n-e.h*r,a=(180<Math.abs(i)&&(i-=360),(e.h-i)%360);var o=e.l-(t.l*n-e.l*r)/2,t=e.s-(t.s*n-e.s*r)/2;
69
+ Subtracts one color from another.
70
+ @param c1 The base color, a valid CSS color string.
71
+ @param c2 The color to remove from the base color, also a valid CSS color string.
72
+ @param o1 Value from 0 to 1 of the first color's opacity.
73
+ @param o2 Value from 0 to 1 of the first color's opacity.
74
+ */,e.colorSubtract=function(e,t,r=1,n=1){const i=E(e),o=E(t);let a=o.h*n-i.h*r;Math.abs(a)>180&&(a-=360);let s=(i.h-a)%360;const l=i.l-(o.l*n-i.l*r)/2;
77
75
  // a = o1 - (o2 - o1) / 2;
78
- return a<0&&(a+=360),E(`hsl(${a},${100*t}%,${100*o}%)`).toString();
76
+ return s<0&&(s+=360),E(`hsl(${s},${100*(i.s-(o.s*n-i.s*r)/2)}%,${100*l}%)`).toString();
79
77
  // return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();
80
78
  }});
81
79
  //# sourceMappingURL=d3plus-color.full.js.map
@@ -4,110 +4,6 @@
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT
6
6
  */
7
-
8
- (function (factory) {
9
- typeof define === 'function' && define.amd ? define(factory) :
10
- factory();
11
- })((function () { 'use strict';
12
-
13
- if (typeof window !== "undefined") {
14
- (function () {
15
- try {
16
- if (typeof SVGElement === 'undefined' || Boolean(SVGElement.prototype.innerHTML)) {
17
- return;
18
- }
19
- } catch (e) {
20
- return;
21
- }
22
-
23
- function serializeNode (node) {
24
- switch (node.nodeType) {
25
- case 1:
26
- return serializeElementNode(node);
27
- case 3:
28
- return serializeTextNode(node);
29
- case 8:
30
- return serializeCommentNode(node);
31
- }
32
- }
33
-
34
- function serializeTextNode (node) {
35
- return node.textContent.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
36
- }
37
-
38
- function serializeCommentNode (node) {
39
- return '<!--' + node.nodeValue + '-->'
40
- }
41
-
42
- function serializeElementNode (node) {
43
- var output = '';
44
-
45
- output += '<' + node.tagName;
46
-
47
- if (node.hasAttributes()) {
48
- [].forEach.call(node.attributes, function(attrNode) {
49
- output += ' ' + attrNode.name + '="' + attrNode.value + '"';
50
- });
51
- }
52
-
53
- output += '>';
54
-
55
- if (node.hasChildNodes()) {
56
- [].forEach.call(node.childNodes, function(childNode) {
57
- output += serializeNode(childNode);
58
- });
59
- }
60
-
61
- output += '</' + node.tagName + '>';
62
-
63
- return output;
64
- }
65
-
66
- Object.defineProperty(SVGElement.prototype, 'innerHTML', {
67
- get: function () {
68
- var output = '';
69
-
70
- [].forEach.call(this.childNodes, function(childNode) {
71
- output += serializeNode(childNode);
72
- });
73
-
74
- return output;
75
- },
76
- set: function (markup) {
77
- while (this.firstChild) {
78
- this.removeChild(this.firstChild);
79
- }
80
-
81
- try {
82
- var dXML = new DOMParser();
83
- dXML.async = false;
84
-
85
- var sXML = '<svg xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'>' + markup + '</svg>';
86
- var svgDocElement = dXML.parseFromString(sXML, 'text/xml').documentElement;
87
-
88
- [].forEach.call(svgDocElement.childNodes, function(childNode) {
89
- this.appendChild(this.ownerDocument.importNode(childNode, true));
90
- }.bind(this));
91
- } catch (e) {
92
- throw new Error('Error parsing markup string');
93
- }
94
- }
95
- });
96
-
97
- Object.defineProperty(SVGElement.prototype, 'innerSVG', {
98
- get: function () {
99
- return this.innerHTML;
100
- },
101
- set: function (markup) {
102
- this.innerHTML = markup;
103
- }
104
- });
105
-
106
- })();
107
- }
108
-
109
- }));
110
-
111
7
  (function (global, factory) {
112
8
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-color'), require('d3-scale'), require('open-color/open-color.js')) :
113
9
  typeof define === 'function' && define.amd ? define('@d3plus/color', ['exports', 'd3-color', 'd3-scale', 'open-color/open-color.js'], factory) :
@@ -115,31 +11,45 @@
115
11
  })(this, (function (exports, d3Color, d3Scale, pkg) { 'use strict';
116
12
 
117
13
  /**
118
- @function colorAdd
119
- @desc Adds two colors together.
120
- @param {String} c1 The first color, a valid CSS color string.
121
- @param {String} c2 The second color, also a valid CSS color string.
122
- @param {String} [o1 = 1] Value from 0 to 1 of the first color's opacity.
123
- @param {String} [o2 = 1] Value from 0 to 1 of the first color's opacity.
124
- @returns {String}
14
+ Adds two colors together.
15
+ @param c1 The first color, a valid CSS color string.
16
+ @param c2 The second color, also a valid CSS color string.
17
+ @param o1 Value from 0 to 1 of the first color's opacity.
18
+ @param o2 Value from 0 to 1 of the first color's opacity.
125
19
  */ function add(c1, c2, o1 = 1, o2 = 1) {
126
- c1 = d3Color.hsl(c1);
127
- c2 = d3Color.hsl(c2);
128
- let d = Math.abs(c2.h * o2 - c1.h * o1);
20
+ const hsl1 = d3Color.hsl(c1);
21
+ const hsl2 = d3Color.hsl(c2);
22
+ let d = Math.abs(hsl2.h * o2 - hsl1.h * o1);
129
23
  if (d > 180) d -= 360;
130
- let h = (Math.min(c1.h, c2.h) + d / 2) % 360;
131
- const l = c1.l + (c2.l * o2 - c1.l * o1) / 2, s = c1.s + (c2.s * o2 - c1.s * o1) / 2;
132
- // a = o1 + (o2 - o1) / 2;
24
+ let h = (Math.min(hsl1.h, hsl2.h) + d / 2) % 360;
25
+ const l = hsl1.l + (hsl2.l * o2 - hsl1.l * o1) / 2, s = hsl1.s + (hsl2.s * o2 - hsl1.s * o1) / 2;
133
26
  if (h < 0) h += 360;
134
27
  return d3Color.hsl(`hsl(${h},${s * 100}%,${l * 100}%)`).toString();
135
- // return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();
136
28
  }
137
29
 
138
30
  const { theme: openColor } = pkg;
139
31
  /**
140
- @namespace {Object} colorDefaults
141
- @desc A set of default color values used when assigning colors based on data.
142
- */ const defaults = {
32
+ * A set of default color values used when assigning colors based on data.
33
+ *
34
+ * @defaultValue
35
+ * ```
36
+ * {
37
+ * dark: "#495057",
38
+ * light: "#f8f9fa",
39
+ * missing: "#ced4da",
40
+ * off: "#c92a2a",
41
+ * on: "#2b8a3e",
42
+ * scale: d3.scaleOrdinal().range([
43
+ * "#364fc7", "#fab005", "#c92a2a",
44
+ * "#2b8a3e", "#fd7e14", "#862e9c",
45
+ * "#15aabf", "#e64980", "#82c91e",
46
+ * "#74c0fc", "#faa2c1", "#c0eb75",
47
+ * "#b197fc", "#c5f6fa", "#ffe8cc",
48
+ * "#d3f9d8", "#f3d9fa", "#ffe3e3"
49
+ * ])
50
+ * }
51
+ * ```
52
+ */ const defaults = {
143
53
  dark: openColor.colors.gray[700],
144
54
  light: openColor.colors.gray[50],
145
55
  missing: openColor.colors.gray[400],
@@ -166,89 +76,74 @@
166
76
  openColor.colors.red[100]
167
77
  ])
168
78
  };
169
- /**
170
- Returns a color based on a key, whether it is present in a user supplied object or in the default object.
171
- @returns {String}
172
- @private
173
- */ function getColor(k, u = {}) {
174
- return k in u ? u[k] : k in defaults ? defaults[k] : defaults.missing;
175
- }
176
79
 
177
80
  /**
178
- @function colorAssign
179
- @desc Assigns a color to a value using a predefined set of defaults.
180
- @param {String} c A valid CSS color string.
181
- @param {Object} [u = defaults] An object containing overrides of the default colors.
182
- @returns {String}
81
+ Assigns a color to a value using a predefined set of defaults.
82
+ @param c A valid CSS color string.
83
+ @param u An object containing overrides of the default colors.
183
84
  */ function assign(c, u = {}) {
184
85
  // If the value is null or undefined, set to grey.
185
86
  if ([
186
87
  null,
187
- void 0
188
- ].indexOf(c) >= 0) return getColor("missing", u);
189
- else if (c === true) return getColor("on", u);
190
- else if (c === false) return getColor("off", u);
191
- const p = d3Color.color(c);
192
- // If the value is not a valid color string, use the color scale.
193
- if (!p) return getColor("scale", u)(c);
194
- return c.toString();
88
+ undefined
89
+ ].indexOf(c) >= 0) return u["missing"] || defaults["missing"];
90
+ else if (c === true) return u["on"] || defaults["on"];
91
+ else if (c === false) return u["off"] || defaults["off"];
92
+ else {
93
+ const p = d3Color.color(c);
94
+ // If the value is not a valid color string, use the color scale.
95
+ if (!p) return (u["scale"] || defaults["scale"])(c);
96
+ return c;
97
+ }
195
98
  }
196
99
 
197
100
  /**
198
- @function colorContrast
199
- @desc A set of default color values used when assigning colors based on data.
200
- @param {String} c A valid CSS color string.
201
- @param {Object} [u = defaults] An object containing overrides of the default colors.
202
- @returns {String}
101
+ A set of default color values used when assigning colors based on data.
102
+ @param c A valid CSS color string.
103
+ @param u An object containing overrides of the default colors.
203
104
  */ function contrast(c, u = {}) {
204
- c = d3Color.rgb(c);
205
- const yiq = (c.r * 299 + c.g * 587 + c.b * 114) / 1000;
206
- return yiq >= 128 ? getColor("dark", u) : getColor("light", u);
105
+ const rgbColor = d3Color.rgb(c);
106
+ const yiq = (rgbColor.r * 299 + rgbColor.g * 587 + rgbColor.b * 114) / 1000;
107
+ return yiq >= 128 ? u["dark"] || defaults["dark"] : u["light"] || defaults["light"];
207
108
  }
208
109
 
209
110
  /**
210
- @function colorLegible
211
- @desc Darkens a color so that it will appear legible on a white background.
212
- @param {String} c A valid CSS color string.
213
- @returns {String}
111
+ Darkens a color so that it will appear legible on a white background.
112
+ @param c A valid CSS color string.
214
113
  */ function legible(c) {
215
- c = d3Color.hsl(c);
216
- if (c.l > 0.45) {
217
- if (c.s > 0.8) c.s = 0.8;
218
- c.l = 0.45;
114
+ const hslColor = d3Color.hsl(c);
115
+ if (hslColor.l > 0.45) {
116
+ if (hslColor.s > 0.8) hslColor.s = 0.8;
117
+ hslColor.l = 0.45;
219
118
  }
220
- return c.toString();
119
+ return hslColor.toString();
221
120
  }
222
121
 
223
122
  /**
224
- @function colorLighter
225
- @desc Similar to d3.color.brighter, except that this also reduces saturation so that colors don't appear neon.
226
- @param {String} c A valid CSS color string.
227
- @param {String} [i = 0.5] A value from 0 to 1 dictating the strength of the function.
228
- @returns {String}
123
+ Similar to d3.color.brighter, except that this also reduces saturation so that colors don't appear neon.
124
+ @param c A valid CSS color string.
125
+ @param i Strength of the lightening effect, from 0 to 1.
229
126
  */ function lighter(c, i = 0.5) {
230
- c = d3Color.hsl(c);
231
- i *= 1 - c.l;
232
- c.l += i;
233
- c.s -= i;
234
- return c.toString();
127
+ const hslColor = d3Color.hsl(c);
128
+ i *= 1 - hslColor.l;
129
+ hslColor.l += i;
130
+ hslColor.s -= i;
131
+ return hslColor.toString();
235
132
  }
236
133
 
237
134
  /**
238
- @function colorSubtract
239
- @desc Subtracts one color from another.
240
- @param {String} c1 The base color, a valid CSS color string.
241
- @param {String} c2 The color to remove from the base color, also a valid CSS color string.
242
- @param {String} [o1 = 1] Value from 0 to 1 of the first color's opacity.
243
- @param {String} [o2 = 1] Value from 0 to 1 of the first color's opacity.
244
- @returns {String}
135
+ Subtracts one color from another.
136
+ @param c1 The base color, a valid CSS color string.
137
+ @param c2 The color to remove from the base color, also a valid CSS color string.
138
+ @param o1 Value from 0 to 1 of the first color's opacity.
139
+ @param o2 Value from 0 to 1 of the first color's opacity.
245
140
  */ function subtract(c1, c2, o1 = 1, o2 = 1) {
246
- c1 = d3Color.hsl(c1);
247
- c2 = d3Color.hsl(c2);
248
- let d = c2.h * o2 - c1.h * o1;
141
+ const hsl1 = d3Color.hsl(c1);
142
+ const hsl2 = d3Color.hsl(c2);
143
+ let d = hsl2.h * o2 - hsl1.h * o1;
249
144
  if (Math.abs(d) > 180) d -= 360;
250
- let h = (c1.h - d) % 360;
251
- const l = c1.l - (c2.l * o2 - c1.l * o1) / 2, s = c1.s - (c2.s * o2 - c1.s * o1) / 2;
145
+ let h = (hsl1.h - d) % 360;
146
+ const l = hsl1.l - (hsl2.l * o2 - hsl1.l * o1) / 2, s = hsl1.s - (hsl2.s * o2 - hsl1.s * o1) / 2;
252
147
  // a = o1 - (o2 - o1) / 2;
253
148
  if (h < 0) h += 360;
254
149
  return d3Color.hsl(`hsl(${h},${s * 100}%,${l * 100}%)`).toString();
@@ -1 +1 @@
1
- {"version":3,"file":"d3plus-color.js","sources":["../src/add.js","../src/defaults.js","../src/assign.js","../src/contrast.js","../src/legible.js","../src/lighter.js","../src/subtract.js"],"sourcesContent":["import {hsl} from \"d3-color\";\n\n/**\n @function colorAdd\n @desc Adds two colors together.\n @param {String} c1 The first color, a valid CSS color string.\n @param {String} c2 The second color, also a valid CSS color string.\n @param {String} [o1 = 1] Value from 0 to 1 of the first color's opacity.\n @param {String} [o2 = 1] Value from 0 to 1 of the first color's opacity.\n @returns {String}\n*/\nexport default function(c1, c2, o1 = 1, o2 = 1) {\n c1 = hsl(c1);\n c2 = hsl(c2);\n let d = Math.abs(c2.h * o2 - c1.h * o1);\n if (d > 180) d -= 360;\n let h = (Math.min(c1.h, c2.h) + d / 2) % 360;\n const l = c1.l + (c2.l * o2 - c1.l * o1) / 2,\n s = c1.s + (c2.s * o2 - c1.s * o1) / 2;\n // a = o1 + (o2 - o1) / 2;\n if (h < 0) h += 360;\n return hsl(`hsl(${h},${s * 100}%,${l * 100}%)`).toString();\n // return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();\n}\n","import {scaleOrdinal} from \"d3-scale\";\nimport pkg from \"open-color/open-color.js\";\nconst {theme: openColor} = pkg;\n\n/**\n @namespace {Object} colorDefaults\n @desc A set of default color values used when assigning colors based on data.\n*/\nconst defaults = {\n dark: openColor.colors.gray[700],\n light: openColor.colors.gray[50],\n missing: openColor.colors.gray[400],\n off: openColor.colors.red[900],\n on: openColor.colors.green[900],\n scale: scaleOrdinal().range([\n openColor.colors.indigo[900],\n openColor.colors.yellow[600],\n openColor.colors.red[900],\n openColor.colors.green[900],\n openColor.colors.orange[600],\n openColor.colors.grape[900],\n openColor.colors.cyan[600],\n openColor.colors.pink[600],\n openColor.colors.lime[600],\n openColor.colors.blue[300],\n openColor.colors.pink[300],\n openColor.colors.lime[300],\n openColor.colors.violet[300],\n openColor.colors.cyan[100],\n openColor.colors.orange[100],\n openColor.colors.green[100],\n openColor.colors.grape[100],\n openColor.colors.red[100],\n ])\n};\n\n/**\n Returns a color based on a key, whether it is present in a user supplied object or in the default object.\n @returns {String}\n @private\n*/\nexport function getColor(k, u = {}) {\n return k in u ? u[k] : k in defaults ? defaults[k] : defaults.missing;\n}\n\nexport default defaults;\n","import {color} from \"d3-color\";\nimport {getColor} from \"./defaults.js\";\n\n/**\n @function colorAssign\n @desc Assigns a color to a value using a predefined set of defaults.\n @param {String} c A valid CSS color string.\n @param {Object} [u = defaults] An object containing overrides of the default colors.\n @returns {String}\n*/\nexport default function(c, u = {}) {\n\n // If the value is null or undefined, set to grey.\n if ([null, void 0].indexOf(c) >= 0) return getColor(\"missing\", u);\n // Else if the value is true, set to green.\n else if (c === true) return getColor(\"on\", u);\n // Else if the value is false, set to red.\n else if (c === false) return getColor(\"off\", u);\n\n const p = color(c);\n // If the value is not a valid color string, use the color scale.\n if (!p) return getColor(\"scale\", u)(c);\n\n return c.toString();\n\n}\n","import {getColor} from \"./defaults.js\";\nimport {rgb} from \"d3-color\";\n\n/**\n @function colorContrast\n @desc A set of default color values used when assigning colors based on data.\n @param {String} c A valid CSS color string.\n @param {Object} [u = defaults] An object containing overrides of the default colors.\n @returns {String}\n*/\nexport default function(c, u = {}) {\n c = rgb(c);\n const yiq = (c.r * 299 + c.g * 587 + c.b * 114) / 1000;\n return yiq >= 128 ? getColor(\"dark\", u) : getColor(\"light\", u);\n}\n","import {hsl} from \"d3-color\";\n\n/**\n @function colorLegible\n @desc Darkens a color so that it will appear legible on a white background.\n @param {String} c A valid CSS color string.\n @returns {String}\n*/\nexport default function(c) {\n c = hsl(c);\n if (c.l > 0.45) {\n if (c.s > 0.8) c.s = 0.8;\n c.l = 0.45;\n }\n return c.toString();\n}\n","import {hsl} from \"d3-color\";\n\n/**\n @function colorLighter\n @desc Similar to d3.color.brighter, except that this also reduces saturation so that colors don't appear neon.\n @param {String} c A valid CSS color string.\n @param {String} [i = 0.5] A value from 0 to 1 dictating the strength of the function.\n @returns {String}\n*/\nexport default function(c, i = 0.5) {\n c = hsl(c);\n i *= 1 - c.l;\n c.l += i;\n c.s -= i;\n return c.toString();\n}\n","import {hsl} from \"d3-color\";\n\n/**\n @function colorSubtract\n @desc Subtracts one color from another.\n @param {String} c1 The base color, a valid CSS color string.\n @param {String} c2 The color to remove from the base color, also a valid CSS color string.\n @param {String} [o1 = 1] Value from 0 to 1 of the first color's opacity.\n @param {String} [o2 = 1] Value from 0 to 1 of the first color's opacity.\n @returns {String}\n*/\nexport default function(c1, c2, o1 = 1, o2 = 1) {\n c1 = hsl(c1);\n c2 = hsl(c2);\n let d = c2.h * o2 - c1.h * o1;\n if (Math.abs(d) > 180) d -= 360;\n let h = (c1.h - d) % 360;\n const l = c1.l - (c2.l * o2 - c1.l * o1) / 2,\n s = c1.s - (c2.s * o2 - c1.s * o1) / 2;\n // a = o1 - (o2 - o1) / 2;\n if (h < 0) h += 360;\n return hsl(`hsl(${h},${s * 100}%,${l * 100}%)`).toString();\n // return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();\n}\n"],"names":["c1","c2","o1","o2","hsl","d","Math","abs","h","min","l","s","toString","theme","openColor","pkg","defaults","dark","colors","gray","light","missing","off","red","on","green","scale","scaleOrdinal","range","indigo","yellow","orange","grape","cyan","pink","lime","blue","violet","getColor","k","u","c","indexOf","p","color","rgb","yiq","r","g","b","i"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEA;;;;;;;;EAQA,GACe,YAASA,CAAAA,EAAE,EAAEC,EAAE,EAAEC,EAAK,GAAA,CAAC,EAAEC,EAAAA,GAAK,CAAC,EAAA;EAC5CH,IAAAA,EAAAA,GAAKI,WAAIJ,CAAAA,EAAAA,CAAAA;EACTC,IAAAA,EAAAA,GAAKG,WAAIH,CAAAA,EAAAA,CAAAA;MACT,IAAII,CAAAA,GAAIC,IAAKC,CAAAA,GAAG,CAACN,EAAAA,CAAGO,CAAC,GAAGL,EAAAA,GAAKH,EAAGQ,CAAAA,CAAC,GAAGN,EAAAA,CAAAA;MACpC,IAAIG,CAAAA,GAAI,KAAKA,CAAK,IAAA,GAAA;EAClB,IAAA,IAAIG,CAAI,GAACF,CAAAA,IAAAA,CAAKG,GAAG,CAACT,EAAAA,CAAGQ,CAAC,EAAEP,EAAGO,CAAAA,CAAC,CAAIH,GAAAA,CAAAA,GAAI,CAAA,IAAK,GAAA;EACzC,IAAA,MAAMK,CAAIV,GAAAA,EAAAA,CAAGU,CAAC,GAAG,CAACT,EAAGS,CAAAA,CAAC,GAAGP,EAAAA,GAAKH,EAAGU,CAAAA,CAAC,GAAGR,EAAC,IAAK,CACrCS,EAAAA,CAAAA,GAAIX,EAAGW,CAAAA,CAAC,GAAIV,CAAAA,EAAAA,CAAGU,CAAC,GAAGR,EAAKH,GAAAA,EAAAA,CAAGW,CAAC,GAAGT,EAAC,IAAK,CAAA;;MAE3C,IAAIM,CAAAA,GAAI,GAAGA,CAAK,IAAA,GAAA;EAChB,IAAA,OAAOJ,YAAI,CAAC,IAAI,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{"version":3,"file":"d3plus-color.js","sources":["../src/add.ts","../src/defaults.ts","../src/assign.ts","../src/contrast.ts","../src/legible.ts","../src/lighter.ts","../src/subtract.ts"],"sourcesContent":["import {hsl} from \"d3-color\";\n\n/**\n Adds two colors together.\n @param c1 The first color, a valid CSS color string.\n @param c2 The second color, also a valid CSS color string.\n @param o1 Value from 0 to 1 of the first color's opacity.\n @param o2 Value from 0 to 1 of the first color's opacity.\n*/\nexport default function (\n c1: string,\n c2: string,\n o1: number = 1,\n o2: number = 1,\n): string {\n const hsl1 = hsl(c1);\n const hsl2 = hsl(c2);\n let d: number = Math.abs(hsl2.h * o2 - hsl1.h * o1);\n if (d > 180) d -= 360;\n let h: number = (Math.min(hsl1.h, hsl2.h) + d / 2) % 360;\n const l: number = hsl1.l + (hsl2.l * o2 - hsl1.l * o1) / 2,\n s: number = hsl1.s + (hsl2.s * o2 - hsl1.s * o1) / 2;\n if (h < 0) h += 360;\n return hsl(`hsl(${h},${s * 100}%,${l * 100}%)`).toString();\n}\n","import {ScaleOrdinal, scaleOrdinal} from \"d3-scale\";\n// @ts-ignore\nimport pkg from \"open-color/open-color.js\";\nconst {theme: openColor} = pkg;\n\nexport interface ColorDefaults {\n dark: string;\n light: string;\n missing: string;\n off: string;\n on: string;\n scale: ScaleOrdinal<string, string>;\n}\n\n/**\n * A set of default color values used when assigning colors based on data.\n *\n * @defaultValue\n * ```\n * {\n * dark: \"#495057\",\n * light: \"#f8f9fa\",\n * missing: \"#ced4da\",\n * off: \"#c92a2a\",\n * on: \"#2b8a3e\",\n * scale: d3.scaleOrdinal().range([\n * \"#364fc7\", \"#fab005\", \"#c92a2a\",\n * \"#2b8a3e\", \"#fd7e14\", \"#862e9c\",\n * \"#15aabf\", \"#e64980\", \"#82c91e\",\n * \"#74c0fc\", \"#faa2c1\", \"#c0eb75\",\n * \"#b197fc\", \"#c5f6fa\", \"#ffe8cc\",\n * \"#d3f9d8\", \"#f3d9fa\", \"#ffe3e3\"\n * ])\n * }\n * ```\n */\nconst defaults: ColorDefaults = {\n dark: openColor.colors.gray[700],\n light: openColor.colors.gray[50],\n missing: openColor.colors.gray[400],\n off: openColor.colors.red[900],\n on: openColor.colors.green[900],\n scale: scaleOrdinal<string>().range([\n openColor.colors.indigo[900],\n openColor.colors.yellow[600],\n openColor.colors.red[900],\n openColor.colors.green[900],\n openColor.colors.orange[600],\n openColor.colors.grape[900],\n openColor.colors.cyan[600],\n openColor.colors.pink[600],\n openColor.colors.lime[600],\n openColor.colors.blue[300],\n openColor.colors.pink[300],\n openColor.colors.lime[300],\n openColor.colors.violet[300],\n openColor.colors.cyan[100],\n openColor.colors.orange[100],\n openColor.colors.green[100],\n openColor.colors.grape[100],\n openColor.colors.red[100],\n ]),\n};\n\nexport default defaults;\n","import {color} from \"d3-color\";\nimport defaults, {ColorDefaults} from \"./defaults.js\";\n\n/**\n Assigns a color to a value using a predefined set of defaults.\n @param c A valid CSS color string.\n @param u An object containing overrides of the default colors.\n*/\nexport default function (\n c: string | boolean | null | undefined,\n u: Partial<ColorDefaults> = {},\n): string {\n // If the value is null or undefined, set to grey.\n if ([null, undefined].indexOf(c as null) >= 0)\n return u[\"missing\"] || defaults[\"missing\"];\n // Else if the value is true, set to green.\n else if (c === true) return u[\"on\"] || defaults[\"on\"];\n // Else if the value is false, set to red.\n else if (c === false) return u[\"off\"] || defaults[\"off\"];\n else {\n const p = color(c as string);\n // If the value is not a valid color string, use the color scale.\n if (!p) return (u[\"scale\"] || defaults[\"scale\"])(c as string);\n return c as string;\n }\n}\n","import defaults, {ColorDefaults} from \"./defaults.js\";\nimport {rgb} from \"d3-color\";\n\n/**\n A set of default color values used when assigning colors based on data.\n @param c A valid CSS color string.\n @param u An object containing overrides of the default colors.\n*/\nexport default function (c: string, u: Partial<ColorDefaults> = {}): string {\n const rgbColor = rgb(c);\n const yiq: number =\n (rgbColor.r * 299 + rgbColor.g * 587 + rgbColor.b * 114) / 1000;\n return yiq >= 128\n ? u[\"dark\"] || defaults[\"dark\"]\n : u[\"light\"] || defaults[\"light\"];\n}\n","import {hsl} from \"d3-color\";\n\n/**\n Darkens a color so that it will appear legible on a white background.\n @param c A valid CSS color string.\n*/\nexport default function (c: string): string {\n const hslColor = hsl(c);\n if (hslColor.l > 0.45) {\n if (hslColor.s > 0.8) hslColor.s = 0.8;\n hslColor.l = 0.45;\n }\n return hslColor.toString();\n}\n","import {hsl} from \"d3-color\";\n\n/**\n Similar to d3.color.brighter, except that this also reduces saturation so that colors don't appear neon.\n @param c A valid CSS color string.\n @param i Strength of the lightening effect, from 0 to 1.\n*/\nexport default function (c: string, i: number = 0.5): string {\n const hslColor = hsl(c);\n i *= 1 - hslColor.l;\n hslColor.l += i;\n hslColor.s -= i;\n return hslColor.toString();\n}\n","import {hsl} from \"d3-color\";\n\n/**\n Subtracts one color from another.\n @param c1 The base color, a valid CSS color string.\n @param c2 The color to remove from the base color, also a valid CSS color string.\n @param o1 Value from 0 to 1 of the first color's opacity.\n @param o2 Value from 0 to 1 of the first color's opacity.\n*/\nexport default function (\n c1: string,\n c2: string,\n o1: number = 1,\n o2: number = 1,\n): string {\n const hsl1 = hsl(c1);\n const hsl2 = hsl(c2);\n let d: number = hsl2.h * o2 - hsl1.h * o1;\n if (Math.abs(d) > 180) d -= 360;\n let h: number = (hsl1.h - d) % 360;\n const l: number = hsl1.l - (hsl2.l * o2 - hsl1.l * o1) / 2,\n s: number = hsl1.s - (hsl2.s * o2 - hsl1.s * o1) / 2;\n // a = o1 - (o2 - o1) / 2;\n if (h < 0) h += 360;\n return hsl(`hsl(${h},${s * 100}%,${l * 100}%)`).toString();\n // return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();\n}\n"],"names":["c1","c2","o1","o2","hsl1","hsl","hsl2","d","Math","abs","h","min","l","s","toString","theme","openColor","pkg","defaults","dark","colors","gray","light","missing","off","red","on","green","scale","scaleOrdinal","range","indigo","yellow","orange","grape","cyan","pink","lime","blue","violet","c","u","undefined","indexOf","p","color","rgbColor","rg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