@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,71 +4,69 @@
4
4
  Copyright (c) 2026 D3plus - https://d3plus.org
5
5
  @license MIT
6
6
  */
7
- (o=>{"function"==typeof define&&define.amd?define(o):o()})(function(){if("undefined"!=typeof window){try{if("undefined"==typeof SVGElement||Boolean(SVGElement.prototype.innerHTML))return}catch(o){return}function n(o){switch(o.nodeType){case 1:var e=o,r="";return r+="<"+e.tagName,e.hasAttributes()&&[].forEach.call(e.attributes,function(o){r+=" "+o.name+'="'+o.value+'"'}),r+=">",e.hasChildNodes()&&[].forEach.call(e.childNodes,function(o){r+=n(o)}),r+="</"+e.tagName+">";case 3:return o.textContent.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");case 8:return"\x3c!--"+o.nodeValue+"--\x3e"}}Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var e="";return[].forEach.call(this.childNodes,function(o){e+=n(o)}),e},set:function(o){for(;this.firstChild;)this.removeChild(this.firstChild);try{var e=new DOMParser,r=(e.async=!1,"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+o+"</svg>"),n=e.parseFromString(r,"text/xml").documentElement;[].forEach.call(n.childNodes,function(o){this.appendChild(this.ownerDocument.importNode(o,!0))}.bind(this))}catch(o){throw new Error("Error parsing markup string")}}}),Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(o){this.innerHTML=o}})}}),((o,e)=>{"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-color"),require("d3-scale"),require("open-color/open-color.js")):"function"==typeof define&&define.amd?define("@d3plus/color",["exports","d3-color","d3-scale","open-color/open-color.js"],e):e((o="undefined"!=typeof globalThis?globalThis:o||self).d3plus={},o.d3Color,o.d3Scale,o.pkg)})(this,function(o,i,e,r){r=r.theme;
7
+ !function(o,l){"object"==typeof exports&&"undefined"!=typeof module?l(exports,require("d3-color"),require("d3-scale"),require("open-color/open-color.js")):"function"==typeof define&&define.amd?define("@d3plus/color",["exports","d3-color","d3-scale","open-color/open-color.js"],l):l((o="undefined"!=typeof globalThis?globalThis:o||self).d3plus={},o.d3Color,o.d3Scale,o.pkg)}(this,function(o,l,r,s){"use strict";
8
8
  /**
9
- @namespace {Object} colorDefaults
10
- @desc A set of default color values used when assigning colors based on data.
11
- */let n={dark:r.colors.gray[700],light:r.colors.gray[50],missing:r.colors.gray[400],off:r.colors.red[900],on:r.colors.green[900],scale:e.scaleOrdinal().range([r.colors.indigo[900],r.colors.yellow[600],r.colors.red[900],r.colors.green[900],r.colors.orange[600],r.colors.grape[900],r.colors.cyan[600],r.colors.pink[600],r.colors.lime[600],r.colors.blue[300],r.colors.pink[300],r.colors.lime[300],r.colors.violet[300],r.colors.cyan[100],r.colors.orange[100],r.colors.green[100],r.colors.grape[100],r.colors.red[100]])};
9
+ Adds two colors together.
10
+ @param c1 The first color, a valid CSS color string.
11
+ @param c2 The second color, also a valid CSS color string.
12
+ @param o1 Value from 0 to 1 of the first color's opacity.
13
+ @param o2 Value from 0 to 1 of the first color's opacity.
14
+ */const{theme:e}=s,n={dark:e.colors.gray[700],light:e.colors.gray[50],missing:e.colors.gray[400],off:e.colors.red[900],on:e.colors.green[900],scale:r.scaleOrdinal().range([e.colors.indigo[900],e.colors.yellow[600],e.colors.red[900],e.colors.green[900],e.colors.orange[600],e.colors.grape[900],e.colors.cyan[600],e.colors.pink[600],e.colors.lime[600],e.colors.blue[300],e.colors.pink[300],e.colors.lime[300],e.colors.violet[300],e.colors.cyan[100],e.colors.orange[100],e.colors.green[100],e.colors.grape[100],e.colors.red[100]])};
12
15
  /**
13
- Returns a color based on a key, whether it is present in a user supplied object or in the default object.
14
- @returns {String}
15
- @private
16
- */function t(o,e={}){return o in e?e[o]:o in n?n[o]:n.missing}
16
+ * A set of default color values used when assigning colors based on data.
17
+ *
18
+ * @defaultValue
19
+ * ```
20
+ * {
21
+ * dark: "#495057",
22
+ * light: "#f8f9fa",
23
+ * missing: "#ced4da",
24
+ * off: "#c92a2a",
25
+ * on: "#2b8a3e",
26
+ * scale: d3.scaleOrdinal().range([
27
+ * "#364fc7", "#fab005", "#c92a2a",
28
+ * "#2b8a3e", "#fd7e14", "#862e9c",
29
+ * "#15aabf", "#e64980", "#82c91e",
30
+ * "#74c0fc", "#faa2c1", "#c0eb75",
31
+ * "#b197fc", "#c5f6fa", "#ffe8cc",
32
+ * "#d3f9d8", "#f3d9fa", "#ffe3e3"
33
+ * ])
34
+ * }
35
+ * ```
36
+ */o.colorAdd=function(o,r,s=1,e=1){const n=l.hsl(o),c=l.hsl(r);let t=Math.abs(c.h*e-n.h*s);t>180&&(t-=360);let i=(Math.min(n.h,c.h)+t/2)%360;const a=n.l+(c.l*e-n.l*s)/2,g=n.s+(c.s*e-n.s*s)/2;return i<0&&(i+=360),l.hsl(`hsl(${i},${100*g}%,${100*a}%)`).toString()},o.colorAssign=
17
37
  /**
18
- @function colorAssign
19
- @desc Assigns a color to a value using a predefined set of defaults.
20
- @param {String} c A valid CSS color string.
21
- @param {Object} [u = defaults] An object containing overrides of the default colors.
22
- @returns {String}
23
- */o.colorAdd=
24
- /**
25
- @function colorAdd
26
- @desc Adds two colors together.
27
- @param {String} c1 The first color, a valid CSS color string.
28
- @param {String} c2 The second color, also a valid CSS color string.
29
- @param {String} [o1 = 1] Value from 0 to 1 of the first color's opacity.
30
- @param {String} [o2 = 1] Value from 0 to 1 of the first color's opacity.
31
- @returns {String}
32
- */function(o,e,r=1,n=1){o=i.hsl(o),e=i.hsl(e);let t=Math.abs(e.h*n-o.h*r),l=(180<t&&(t-=360),(Math.min(o.h,e.h)+t/2)%360);var s=o.l+(e.l*n-o.l*r)/2,e=o.s+(e.s*n-o.s*r)/2;
33
- // a = o1 + (o2 - o1) / 2;
34
- return l<0&&(l+=360),i.hsl(`hsl(${l},${100*e}%,${100*s}%)`).toString();
35
- // return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();
36
- },o.colorAssign=function(o,e={}){
38
+ Assigns a color to a value using a predefined set of defaults.
39
+ @param c A valid CSS color string.
40
+ @param u An object containing overrides of the default colors.
41
+ */
42
+ function(o,r={}){
37
43
  // If the value is null or undefined, set to grey.
38
- return 0<=[null,void 0].indexOf(o)?t("missing",e):!0===o?t("on",e):!1===o?t("off",e):
44
+ return[null,void 0].indexOf(o)>=0?r.missing||n.missing:!0===o?r.on||n.on:!1===o?r.off||n.off:
39
45
  // If the value is not a valid color string, use the color scale.
40
- i.color(o)?o.toString():t("scale",e)(o)}
46
+ l.color(o)?o:(r.scale||n.scale)(o)}
41
47
  /**
42
- @function colorContrast
43
- @desc A set of default color values used when assigning colors based on data.
44
- @param {String} c A valid CSS color string.
45
- @param {Object} [u = defaults] An object containing overrides of the default colors.
46
- @returns {String}
47
- */,o.colorContrast=function(o,e={}){return t(128<=(299*(o=i.rgb(o)).r+587*o.g+114*o.b)/1e3?"dark":"light",e)}
48
+ A set of default color values used when assigning colors based on data.
49
+ @param c A valid CSS color string.
50
+ @param u An object containing overrides of the default colors.
51
+ */,o.colorContrast=function(o,r={}){const s=l.rgb(o);return(299*s.r+587*s.g+114*s.b)/1e3>=128?r.dark||n.dark:r.light||n.light}
48
52
  /**
49
- @function colorLegible
50
- @desc Darkens a color so that it will appear legible on a white background.
51
- @param {String} c A valid CSS color string.
52
- @returns {String}
53
- */,o.colorDefaults=n,o.colorLegible=function(o){return.45<(o=i.hsl(o)).l&&(.8<o.s&&(o.s=.8),o.l=.45),o.toString()}
53
+ Darkens a color so that it will appear legible on a white background.
54
+ @param c A valid CSS color string.
55
+ */,o.colorDefaults=n,o.colorLegible=function(o){const r=l.hsl(o);return r.l>.45&&(r.s>.8&&(r.s=.8),r.l=.45),r.toString()}
54
56
  /**
55
- @function colorLighter
56
- @desc Similar to d3.color.brighter, except that this also reduces saturation so that colors don't appear neon.
57
- @param {String} c A valid CSS color string.
58
- @param {String} [i = 0.5] A value from 0 to 1 dictating the strength of the function.
59
- @returns {String}
60
- */,o.colorLighter=function(o,e=.5){return e*=1-(o=i.hsl(o)).l,o.l+=e,o.s-=e,o.toString()}
57
+ Similar to d3.color.brighter, except that this also reduces saturation so that colors don't appear neon.
58
+ @param c A valid CSS color string.
59
+ @param i Strength of the lightening effect, from 0 to 1.
60
+ */,o.colorLighter=function(o,r=.5){const s=l.hsl(o);return r*=1-s.l,s.l+=r,s.s-=r,s.toString()}
61
61
  /**
62
- @function colorSubtract
63
- @desc Subtracts one color from another.
64
- @param {String} c1 The base color, a valid CSS color string.
65
- @param {String} c2 The color to remove from the base color, also a valid CSS color string.
66
- @param {String} [o1 = 1] Value from 0 to 1 of the first color's opacity.
67
- @param {String} [o2 = 1] Value from 0 to 1 of the first color's opacity.
68
- @returns {String}
69
- */,o.colorSubtract=function(o,e,r=1,n=1){o=i.hsl(o);let t=(e=i.hsl(e)).h*n-o.h*r,l=(180<Math.abs(t)&&(t-=360),(o.h-t)%360);var s=o.l-(e.l*n-o.l*r)/2,e=o.s-(e.s*n-o.s*r)/2;
62
+ Subtracts one color from another.
63
+ @param c1 The base color, a valid CSS color string.
64
+ @param c2 The color to remove from the base color, also a valid CSS color string.
65
+ @param o1 Value from 0 to 1 of the first color's opacity.
66
+ @param o2 Value from 0 to 1 of the first color's opacity.
67
+ */,o.colorSubtract=function(o,r,s=1,e=1){const n=l.hsl(o),c=l.hsl(r);let t=c.h*e-n.h*s;Math.abs(t)>180&&(t-=360);let i=(n.h-t)%360;const a=n.l-(c.l*e-n.l*s)/2,g=n.s-(c.s*e-n.s*s)/2;
70
68
  // a = o1 - (o2 - o1) / 2;
71
- return l<0&&(l+=360),i.hsl(`hsl(${l},${100*e}%,${100*s}%)`).toString();
69
+ return i<0&&(i+=360),l.hsl(`hsl(${i},${100*g}%,${100*a}%)`).toString();
72
70
  // return hsl(`hsl(${h},${s * 100}%,${l * 100}%,${a})`).toString();
73
71
  }});
74
72
  //# sourceMappingURL=d3plus-color.js.map