@sardine/colour 2.1.0-rc.0 → 2.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.
package/dist/index.cjs CHANGED
@@ -1 +1,597 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function P(e,t){if(e===0&&t===0)return 0;const n=Math.atan2(e,t)*(180/Math.PI);return n>=0?n:n+360}function me({C1:e,C2:t,h1_d:n,h2_d:r}){return e*t===0?0:Math.abs(r-n)<=180?r-n:r-n>180?r-n-360:r-n<-180?r-n+360:0}function Ce({C1:e,C2:t,h1_d:n,h2_d:r}){return e*t===0?r+n:Math.abs(n-r)<=180?(r+n)/2:Math.abs(n-r)>180&&n+r<360?(r+n+360)/2:Math.abs(n-r)>180&&n+r>=360?(r+n-360)/2:0}const d=e=>e*(Math.PI/180),j=e=>Math.sqrt(e**7/(e**7+25**7));function b(e,t){const n=e/255,r=t?.03928:.04045;let o;return n>r?o=((n+.055)/1.055)**2.4:o=n/12.92,o}function $(e){const t=.20689655172413793,n=t**3;let r;return e>n?r=Math.cbrt(e):r=e/(3*t**2)+4/29,r}function ge(e,t,n){return Math.min(Math.max(e,t),n)}function V(e,t){const n=e.L,r=e.a,o=e.b,a=t.L,s=t.a,f=t.b,c=1,l=1,B=1,m=Math.sqrt(r**2+o**2),C=Math.sqrt(s**2+f**2),fe=a-n,ce=(m+C)/2,x=.5*(1-j(ce)),A=r*(1+x),D=s*(1+x),h=Math.sqrt(A**2+o**2),v=Math.sqrt(D**2+f**2),k=(h+v)/2,F=v-h,X=P(o,A),Y=P(f,D),ie=me({C1:m,C2:C,h1_d:X,h2_d:Y}),Z=2*Math.sqrt(h*v)*Math.sin(d(ie)/2),g=Ce({C1:m,C2:C,h1_d:X,h2_d:Y}),E=(n+a)/2,ue=1-.17*Math.cos(d(g-30))+.24*Math.cos(d(2*g))+.32*Math.cos(d(3*g+6))-.2*Math.cos(d(4*g-63)),le=1+.015*(E-50)**2/Math.sqrt(20+(E-50)**2),T=.045*k+1,W=1+.015*k*ue,de=30*Math.exp(-(((g-275)/25)**2)),be=-2*j(k)*Math.sin(d(de*2));return Math.sqrt((fe/(c*le))**2+(F/(l*T))**2+(Z/(B*W))**2+be*(F/(l*T))*(Z/(B*W)))}function J(e){const{R:t,G:n,B:r}=e,o=b(t)*100,a=b(n)*100,s=b(r)*100,f=o*.4124+a*.3576+s*.1805,c=o*.2126+a*.7152+s*.0722,l=o*.0193+a*.1192+s*.9505;return{X:f,Y:c,Z:l}}function K(e){const{X:t,Y:n,Z:r}=e,o=t/95.047,a=n/100,s=r/108.883,f=$(o),c=$(a),l=$(s),B=116*c-16,m=500*(f-c),C=200*(c-l);return{L:B,a:m,b:C}}function y(e){const t=J(e);return K(t)}const Q=(e,t)=>{const n=y(e),r=y(t);return V(n,r)},_=/^#[a-fA-F0-9]{6}$/,ee=/^#[a-fA-F0-9]{8}$/,te=/^#[a-fA-F0-9]{3}$/,ne=/^#[a-fA-F0-9]{4}$/,re=/^rgba*\(\s*([-+]?\d+)\s*(?:,)?\s*([-+]?\d+)\s*(?:,)?\s*([-+]?\d+)\s*(?:,*|\/*)\s*([-+]?\d*[.]?\d+[%]?)*\)$/i;function i(e){const t=e.match(re);if(!t)throw new Error(`convertCSSRGBtoHex expects a valid CSS RGB string but got ${e}`);const n=r=>r?Number.parseFloat(r):void 0;return{R:n(t[1]),G:n(t[2]),B:n(t[3]),A:n(t[4])}}function G({R:e,G:t,B:n,A:r}){const o=a=>ge(a,0,255).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}${r?o(Math.round(r*255)):""}`}function Se(e){const t=i(e);return G(t)}const w=new Map([["aliceblue","#f0f8ff"],["antiquewhite","#faebd7"],["aqua","#00ffff"],["aquamarine","#7fffd4"],["azure","#f0ffff"],["beige","#f5f5dc"],["bisque","#ffe4c4"],["black","#000000"],["blanchedalmond","#ffebcd"],["blue","#0000ff"],["blueviolet","#8a2be2"],["brown","#a52a2a"],["burlywood","#deb887"],["cadetblue","#5f9ea0"],["chartreuse","#7fff00"],["chocolate","#d2691e"],["coral","#ff7f50"],["cornflowerblue","#6495ed"],["cornsilk","#fff8dc"],["crimson","#dc143c"],["cyan","#00ffff"],["darkblue","#00008b"],["darkcyan","#008b8b"],["darkgoldenrod","#b8860b"],["darkgray","#a9a9a9"],["darkgreen","#006400"],["darkgrey","#a9a9a9"],["darkkhaki","#bdb76b"],["darkmagenta","#8b008b"],["darkolivegreen","#556b2f"],["darkorange","#ff8c00"],["darkorchid","#9932cc"],["darkred","#8b0000"],["darksalmon","#e9967a"],["darkseagreen","#8fbc8f"],["darkslateblue","#483d8b"],["darkslategray","#2f4f4f"],["darkslategrey","#2f4f4f"],["darkturquoise","#00ced1"],["darkviolet","#9400d3"],["deeppink","#ff1493"],["deepskyblue","#00bfff"],["dimgray","#696969"],["dimgrey","#696969"],["dodgerblue","#1e90ff"],["firebrick","#b22222"],["floralwhite","#fffaf0"],["forestgreen","#228b22"],["fuchsia","#ff00ff"],["gainsboro","#dcdcdc"],["ghostwhite","#f8f8ff"],["gold","#ffd700"],["goldenrod","#daa520"],["gray","#808080"],["green","#008000"],["greenyellow","#adff2f"],["grey","#808080"],["honeydew","#f0fff0"],["hotpink","#ff69b4"],["indianred","#cd5c5c"],["indigo","#4b0082"],["ivory","#fffff0"],["khaki","#f0e68c"],["lavender","#e6e6fa"],["lavenderblush","#fff0f5"],["lawngreen","#7cfc00"],["lemonchiffon","#fffacd"],["lightblue","#add8e6"],["lightcoral","#f08080"],["lightcyan","#e0ffff"],["lightgoldenrodyellow","#fafad2"],["lightgray","#d3d3d3"],["lightgreen","#90ee90"],["lightgrey","#d3d3d3"],["lightpink","#ffb6c1"],["lightsalmon","#ffa07a"],["lightseagreen","#20b2aa"],["lightskyblue","#87cefa"],["lightslategray","#778899"],["lightslategrey","#778899"],["lightsteelblue","#b0c4de"],["lightyellow","#ffffe0"],["lime","#00ff00"],["limegreen","#32cd32"],["linen","#faf0e6"],["magenta","#ff00ff"],["maroon","#800000"],["mediumaquamarine","#66cdaa"],["mediumblue","#0000cd"],["mediumorchid","#ba55d3"],["mediumpurple","#9370db"],["mediumseagreen","#3cb371"],["mediumslateblue","#7b68ee"],["mediumspringgreen","#00fa9a"],["mediumturquoise","#48d1cc"],["mediumvioletred","#c71585"],["midnightblue","#191970"],["mintcream","#f5fffa"],["mistyrose","#ffe4e1"],["moccasin","#ffe4b5"],["navajowhite","#ffdead"],["navy","#000080"],["oldlace","#fdf5e6"],["olive","#808000"],["olivedrab","#6b8e23"],["orangered","#ff4500"],["orchid","#da70d6"],["palegoldenrod","#eee8aa"],["palegreen","#98fb98"],["paleturquoise","#afeeee"],["palevioletred","#db7093"],["papayawhip","#ffefd5"],["peachpuff","#ffdab9"],["peru","#cd853f"],["pink","#ffc0cb"],["plum","#dda0dd"],["powderblue","#b0e0e6"],["purple","#800080"],["red","#ff0000"],["rosybrown","#bc8f8f"],["royalblue","#4169e1"],["saddlebrown","#8b4513"],["salmon","#fa8072"],["sandybrown","#f4a460"],["seagreen","#2e8b57"],["seashell","#fff5ee"],["sienna","#a0522d"],["silver","#c0c0c0"],["skyblue","#87ceeb"],["slateblue","#6a5acd"],["slategray","#708090"],["slategrey","#708090"],["snow","#fffafa"],["springgreen","#00ff7f"],["steelblue","#4682b4"],["tan","#d2b48c"],["teal","#008080"],["thistle","#d8bfd8"],["tomato","#ff6347"],["transparent","#00000000"],["turquoise","#40e0d0"],["violet","#ee82ee"],["wheat","#f5deb3"],["white","#ffffff"],["whitesmoke","#f5f5f5"],["yellow","#ffff00"],["yellowgreen","#9acd32"]]);function oe(e){for(const[t,n]of w.entries())if(n===e)return t}function u(e){if(typeof e!="string")throw new Error(`convertHextoRGB expects a string but got a ${typeof e}`);if(e.match(_))return{R:Number.parseInt(`${e[1]}${e[2]}`,16),G:Number.parseInt(`${e[3]}${e[4]}`,16),B:Number.parseInt(`${e[5]}${e[6]}`,16)};if(e.match(te))return{R:Number.parseInt(`${e[1]}${e[1]}`,16),G:Number.parseInt(`${e[2]}${e[2]}`,16),B:Number.parseInt(`${e[3]}${e[3]}`,16)};if(e.match(ee))return{R:Number.parseInt(`${e[1]}${e[2]}`,16),G:Number.parseInt(`${e[3]}${e[4]}`,16),B:Number.parseInt(`${e[5]}${e[6]}`,16),A:Number.parseInt(`${e[7]}${e[8]}`,16)/255};if(e.match(ne))return{R:Number.parseInt(`${e[1]}${e[1]}`,16),G:Number.parseInt(`${e[2]}${e[2]}`,16),B:Number.parseInt(`${e[3]}${e[3]}`,16),A:Number.parseInt(`${e[4]}${e[4]}`,16)/255};throw new Error(`convertHextoRGB expects an valid hexadecimal colour value but got ${e}`)}function H(e){return w.get(e)}function R(e){const t=H(e);if(t)return u(t)}function M({R:e,G:t,B:n,A:r}){return`rgb(${e} ${t} ${n}${r?` / ${r}`:""})`}function L(e){const t=G(e);return oe(t)}function p(e,t){if(!t||t.length<2)return e;const n=[];for(const o of t){const a=Q(e,o);n.push([o,a])}return n.sort((o,a)=>o[1]-a[1])[0][0]}function Re(e,t){if(!t||t.length<2)return e;const n=i(e),r=t.map(a=>i(a)),o=p(n,r);return M(o)}function N(e){return!!e.match(re)}function z(e){return!!e.match(_)||!!e.match(ee)||!!e.match(ne)||!!e.match(te)}function O(e){return w.has(e)}function Ge(e,t){if(!t||t.length<2)return e;let n,r;const o=[];if(z(e)&&(n=u(e),r="hex"),N(e)&&(n=i(e),r="cssRGB"),O(e)&&(n=R(e),r="namedCSS"),!n)return;for(const s of t)z(s)&&o.push(u(s)),N(s)&&o.push(i(s)),O(s)&&o.push(R(s));if(o.length<2)return e;const a=p(n,o);if(r==="hex")return G(a);if(r==="cssRGB")return M(a);if(r==="namedCSS")return L(a)}function pe(e,t){if(!t||t.length<2)return e;const n=u(e),r=t.map(a=>u(a)),o=p(n,r);return G(o)}function Be(e,t){if(!t||t.length<2)return e;const n=R(e),o=t.map(s=>R(s)).filter(s=>s!==void 0);if(!n||o.length<2)return e;const a=p(n,o);return L(a)}function q({R:e,G:t,B:n},r){const o=r==="WCAG2.1",a=b(e,o),s=b(t,o),f=b(n,o);return .2126*a+.7152*s+.0722*f}function S(e,t){const n=u(e);return q(n,t)}function I(e,t){const n=S(e,t)+.05,r=1.05/n,o=n/.05;return r>o}function ae(e,t){const n=H(e);if(n)return I(n,t);throw new Error(`${e} is not a valid colour format. isCSSNamedDarkColour only accepts CSS named colours. Check more details here https://developer.mozilla.org/en-US/docs/Web/CSS/named-color`)}function se(e,t){const n=i(e),r=q(n,t),o=1.05/r,a=r/.05;return o>a}function he(e,t){try{return e.startsWith("#")?I(e,t):e.startsWith("rgb")?se(e,t):ae(e,t)}catch{throw new Error(`${e} is not a valid colour format. isDarkColour accepts CSS RGB formats, ie rgb(0,0,0) and rgba(255, 255, 255, 0.4), hexadecimal and CSS named colours.`)}}const U=(e,t)=>e>t?e/t:t/e,ve=({backgroundColour:e,optionOneColour:t,optionTwoColour:n},r)=>{const o=S(e,r)+.05,a=S(t,r)+.05,s=S(n,r)+.05,f=U(a,o),c=U(s,o);return f>c?t:n};exports.RGBdistance=Q;exports.ciede2000=V;exports.convertCSSRGBtoHex=Se;exports.convertCSSRGBtoRGB=i;exports.convertHextoNamedCSSColour=oe;exports.convertHextoRGB=u;exports.convertNamedCSSColourtoHex=H;exports.convertNamedCSSColourtoRGB=R;exports.convertRGBtoCSSRGB=M;exports.convertRGBtoHex=G;exports.convertRGBtoLab=y;exports.convertRGBtoNamedCSSColour=L;exports.convertRGBtoXYZ=J;exports.convertXYZtoLab=K;exports.findNearestCSSRGBColour=Re;exports.findNearestColour=Ge;exports.findNearestHexColour=pe;exports.findNearestNamedCSSColour=Be;exports.findNearestRGBColour=p;exports.getSRGBLuminanceFromHex=S;exports.getSRGBLuminanceFromRGB=q;exports.isCSSNamedDarkColour=ae;exports.isCSSRGBColour=N;exports.isCSSRGBDarkColour=se;exports.isDarkColour=he;exports.isHexDarkColour=I;exports.pickHexColourContrast=ve;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function hue_d(x, y) {
4
+ if (x === 0 && y === 0) {
5
+ return 0;
6
+ }
7
+ const angle = Math.atan2(x, y) * (180 / Math.PI);
8
+ if (angle >= 0) {
9
+ return angle;
10
+ }
11
+ return angle + 360;
12
+ }
13
+ function deltaHue_d({ C1, C2, h1_d, h2_d }) {
14
+ if (C1 * C2 === 0) {
15
+ return 0;
16
+ }
17
+ if (Math.abs(h2_d - h1_d) <= 180) {
18
+ return h2_d - h1_d;
19
+ }
20
+ if (h2_d - h1_d > 180) {
21
+ return h2_d - h1_d - 360;
22
+ }
23
+ if (h2_d - h1_d < -180) {
24
+ return h2_d - h1_d + 360;
25
+ }
26
+ return 0;
27
+ }
28
+ function meanHue_d({ C1, C2, h1_d, h2_d }) {
29
+ if (C1 * C2 === 0) {
30
+ return h2_d + h1_d;
31
+ }
32
+ if (Math.abs(h1_d - h2_d) <= 180) {
33
+ return (h2_d + h1_d) / 2;
34
+ }
35
+ if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d < 360) {
36
+ return (h2_d + h1_d + 360) / 2;
37
+ }
38
+ if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d >= 360) {
39
+ return (h2_d + h1_d - 360) / 2;
40
+ }
41
+ return 0;
42
+ }
43
+ const toRadians = (n) => n * (Math.PI / 180);
44
+ const bigSquare = (n) => Math.sqrt(n ** 7 / (n ** 7 + 25 ** 7));
45
+ function linearRGB(rgbValue, WCAG21) {
46
+ const rgbRatio = rgbValue / 255;
47
+ const threshold = WCAG21 ? 0.03928 : 0.04045;
48
+ let linearValue;
49
+ if (rgbRatio > threshold) {
50
+ linearValue = ((rgbRatio + 0.055) / 1.055) ** 2.4;
51
+ } else {
52
+ linearValue = rgbRatio / 12.92;
53
+ }
54
+ return linearValue;
55
+ }
56
+ function constrainLab(n) {
57
+ const delta = 6 / 29;
58
+ const deltaCube = delta ** 3;
59
+ let t;
60
+ if (n > deltaCube) {
61
+ t = Math.cbrt(n);
62
+ } else {
63
+ t = n / (3 * delta ** 2) + 4 / 29;
64
+ }
65
+ return t;
66
+ }
67
+ function clamp(value, min, max) {
68
+ return Math.min(Math.max(value, min), max);
69
+ }
70
+ function ciede2000(colour1, colour2) {
71
+ const L1 = colour1.L;
72
+ const a1 = colour1.a;
73
+ const b1 = colour1.b;
74
+ const L2 = colour2.L;
75
+ const a2 = colour2.a;
76
+ const b2 = colour2.b;
77
+ const kL = 1;
78
+ const kC = 1;
79
+ const kH = 1;
80
+ const C1 = Math.sqrt(a1 ** 2 + b1 ** 2);
81
+ const C2 = Math.sqrt(a2 ** 2 + b2 ** 2);
82
+ const ΔL_d = L2 - L1;
83
+ const C̅ = (C1 + C2) / 2;
84
+ const G = 0.5 * (1 - bigSquare(C̅));
85
+ const a1_d = a1 * (1 + G);
86
+ const a2_d = a2 * (1 + G);
87
+ const C1_d = Math.sqrt(a1_d ** 2 + b1 ** 2);
88
+ const C2_d = Math.sqrt(a2_d ** 2 + b2 ** 2);
89
+ const C̅_d = (C1_d + C2_d) / 2;
90
+ const ΔC̅_d = C2_d - C1_d;
91
+ const h1_d = hue_d(b1, a1_d);
92
+ const h2_d = hue_d(b2, a2_d);
93
+ const Δh_d = deltaHue_d({ C1, C2, h1_d, h2_d });
94
+ const ΔH_d = 2 * Math.sqrt(C1_d * C2_d) * Math.sin(toRadians(Δh_d) / 2);
95
+ const H̅_d = meanHue_d({ C1, C2, h1_d, h2_d });
96
+ const L̅ = (L1 + L2) / 2;
97
+ const T = 1 - 0.17 * Math.cos(toRadians(H̅_d - 30)) + 0.24 * Math.cos(toRadians(2 * H̅_d)) + 0.32 * Math.cos(toRadians(3 * H̅_d + 6)) - 0.2 * Math.cos(toRadians(4 * H̅_d - 63));
98
+ const SL = 1 + 0.015 * (L̅ - 50) ** 2 / Math.sqrt(20 + (L̅ - 50) ** 2);
99
+ const SC = 0.045 * C̅_d + 1;
100
+ const SH = 1 + 0.015 * C̅_d * T;
101
+ const rotation = 30 * Math.exp(-(((H̅_d - 275) / 25) ** 2));
102
+ const RT = -2 * bigSquare(C̅_d) * Math.sin(toRadians(rotation * 2));
103
+ const ΔE = Math.sqrt(
104
+ (ΔL_d / (kL * SL)) ** 2 + (ΔC̅_d / (kC * SC)) ** 2 + (ΔH_d / (kH * SH)) ** 2 + RT * (ΔC̅_d / (kC * SC)) * (ΔH_d / (kH * SH))
105
+ );
106
+ return ΔE;
107
+ }
108
+ function convertRGBtoXYZ(colour) {
109
+ const { R, G, B } = colour;
110
+ const _R = linearRGB(R) * 100;
111
+ const _G = linearRGB(G) * 100;
112
+ const _B = linearRGB(B) * 100;
113
+ const X = _R * 0.4124 + _G * 0.3576 + _B * 0.1805;
114
+ const Y = _R * 0.2126 + _G * 0.7152 + _B * 0.0722;
115
+ const Z = _R * 0.0193 + _G * 0.1192 + _B * 0.9505;
116
+ return { X, Y, Z };
117
+ }
118
+ function convertXYZtoLab(colour) {
119
+ const { X, Y, Z } = colour;
120
+ const _X = X / 95.047;
121
+ const _Y = Y / 100;
122
+ const _Z = Z / 108.883;
123
+ const fX = constrainLab(_X);
124
+ const fY = constrainLab(_Y);
125
+ const fZ = constrainLab(_Z);
126
+ const L = 116 * fY - 16;
127
+ const a = 500 * (fX - fY);
128
+ const b = 200 * (fY - fZ);
129
+ return { L, a, b };
130
+ }
131
+ function convertRGBtoLab(colour) {
132
+ const XYZColour = convertRGBtoXYZ(colour);
133
+ return convertXYZtoLab(XYZColour);
134
+ }
135
+ const RGBdistance = (colour1, colour2) => {
136
+ const c1 = convertRGBtoLab(colour1);
137
+ const c2 = convertRGBtoLab(colour2);
138
+ return ciede2000(c1, c2);
139
+ };
140
+ const hexRegex = /^#[a-fA-F0-9]{6}$/;
141
+ const hexAlphaRegex = /^#[a-fA-F0-9]{8}$/;
142
+ const shortHexRegex = /^#[a-fA-F0-9]{3}$/;
143
+ const shortAlphaHexRegex = /^#[a-fA-F0-9]{4}$/;
144
+ const cssRGBARegex = /^rgba*\(\s*([-+]?\d+)\s*(?:,)?\s*([-+]?\d+)\s*(?:,)?\s*([-+]?\d+)\s*(?:,*|\/*)\s*([-+]?\d*[.]?\d+[%]?)*\)$/i;
145
+ function convertCSSRGBtoRGB(colour) {
146
+ const match = colour.match(cssRGBARegex);
147
+ if (!match) {
148
+ throw new Error(
149
+ `convertCSSRGBtoHex expects a valid CSS RGB string but got ${colour}`
150
+ );
151
+ }
152
+ const rgbNumber = (n) => n ? Number.parseFloat(n) : void 0;
153
+ return {
154
+ R: rgbNumber(match[1]),
155
+ G: rgbNumber(match[2]),
156
+ B: rgbNumber(match[3]),
157
+ A: rgbNumber(match[4])
158
+ };
159
+ }
160
+ function convertRGBtoHex({ R, G, B, A }) {
161
+ const hex = (n) => {
162
+ const value = clamp(n, 0, 255);
163
+ return value.toString(16).padStart(2, "0");
164
+ };
165
+ return `#${hex(R)}${hex(G)}${hex(B)}${A ? hex(Math.round(A * 255)) : ""}`;
166
+ }
167
+ function convertCSSRGBtoHex(colour) {
168
+ const rgb = convertCSSRGBtoRGB(colour);
169
+ return convertRGBtoHex(rgb);
170
+ }
171
+ const namedCSSColours = /* @__PURE__ */ new Map([
172
+ ["aliceblue", "#f0f8ff"],
173
+ ["antiquewhite", "#faebd7"],
174
+ ["aqua", "#00ffff"],
175
+ ["aquamarine", "#7fffd4"],
176
+ ["azure", "#f0ffff"],
177
+ ["beige", "#f5f5dc"],
178
+ ["bisque", "#ffe4c4"],
179
+ ["black", "#000000"],
180
+ ["blanchedalmond", "#ffebcd"],
181
+ ["blue", "#0000ff"],
182
+ ["blueviolet", "#8a2be2"],
183
+ ["brown", "#a52a2a"],
184
+ ["burlywood", "#deb887"],
185
+ ["cadetblue", "#5f9ea0"],
186
+ ["chartreuse", "#7fff00"],
187
+ ["chocolate", "#d2691e"],
188
+ ["coral", "#ff7f50"],
189
+ ["cornflowerblue", "#6495ed"],
190
+ ["cornsilk", "#fff8dc"],
191
+ ["crimson", "#dc143c"],
192
+ ["cyan", "#00ffff"],
193
+ ["darkblue", "#00008b"],
194
+ ["darkcyan", "#008b8b"],
195
+ ["darkgoldenrod", "#b8860b"],
196
+ ["darkgray", "#a9a9a9"],
197
+ ["darkgreen", "#006400"],
198
+ ["darkgrey", "#a9a9a9"],
199
+ ["darkkhaki", "#bdb76b"],
200
+ ["darkmagenta", "#8b008b"],
201
+ ["darkolivegreen", "#556b2f"],
202
+ ["darkorange", "#ff8c00"],
203
+ ["darkorchid", "#9932cc"],
204
+ ["darkred", "#8b0000"],
205
+ ["darksalmon", "#e9967a"],
206
+ ["darkseagreen", "#8fbc8f"],
207
+ ["darkslateblue", "#483d8b"],
208
+ ["darkslategray", "#2f4f4f"],
209
+ ["darkslategrey", "#2f4f4f"],
210
+ ["darkturquoise", "#00ced1"],
211
+ ["darkviolet", "#9400d3"],
212
+ ["deeppink", "#ff1493"],
213
+ ["deepskyblue", "#00bfff"],
214
+ ["dimgray", "#696969"],
215
+ ["dimgrey", "#696969"],
216
+ ["dodgerblue", "#1e90ff"],
217
+ ["firebrick", "#b22222"],
218
+ ["floralwhite", "#fffaf0"],
219
+ ["forestgreen", "#228b22"],
220
+ ["fuchsia", "#ff00ff"],
221
+ ["gainsboro", "#dcdcdc"],
222
+ ["ghostwhite", "#f8f8ff"],
223
+ ["gold", "#ffd700"],
224
+ ["goldenrod", "#daa520"],
225
+ ["gray", "#808080"],
226
+ ["green", "#008000"],
227
+ ["greenyellow", "#adff2f"],
228
+ ["grey", "#808080"],
229
+ ["honeydew", "#f0fff0"],
230
+ ["hotpink", "#ff69b4"],
231
+ ["indianred", "#cd5c5c"],
232
+ ["indigo", "#4b0082"],
233
+ ["ivory", "#fffff0"],
234
+ ["khaki", "#f0e68c"],
235
+ ["lavender", "#e6e6fa"],
236
+ ["lavenderblush", "#fff0f5"],
237
+ ["lawngreen", "#7cfc00"],
238
+ ["lemonchiffon", "#fffacd"],
239
+ ["lightblue", "#add8e6"],
240
+ ["lightcoral", "#f08080"],
241
+ ["lightcyan", "#e0ffff"],
242
+ ["lightgoldenrodyellow", "#fafad2"],
243
+ ["lightgray", "#d3d3d3"],
244
+ ["lightgreen", "#90ee90"],
245
+ ["lightgrey", "#d3d3d3"],
246
+ ["lightpink", "#ffb6c1"],
247
+ ["lightsalmon", "#ffa07a"],
248
+ ["lightseagreen", "#20b2aa"],
249
+ ["lightskyblue", "#87cefa"],
250
+ ["lightslategray", "#778899"],
251
+ ["lightslategrey", "#778899"],
252
+ ["lightsteelblue", "#b0c4de"],
253
+ ["lightyellow", "#ffffe0"],
254
+ ["lime", "#00ff00"],
255
+ ["limegreen", "#32cd32"],
256
+ ["linen", "#faf0e6"],
257
+ ["magenta", "#ff00ff"],
258
+ ["maroon", "#800000"],
259
+ ["mediumaquamarine", "#66cdaa"],
260
+ ["mediumblue", "#0000cd"],
261
+ ["mediumorchid", "#ba55d3"],
262
+ ["mediumpurple", "#9370db"],
263
+ ["mediumseagreen", "#3cb371"],
264
+ ["mediumslateblue", "#7b68ee"],
265
+ ["mediumspringgreen", "#00fa9a"],
266
+ ["mediumturquoise", "#48d1cc"],
267
+ ["mediumvioletred", "#c71585"],
268
+ ["midnightblue", "#191970"],
269
+ ["mintcream", "#f5fffa"],
270
+ ["mistyrose", "#ffe4e1"],
271
+ ["moccasin", "#ffe4b5"],
272
+ ["navajowhite", "#ffdead"],
273
+ ["navy", "#000080"],
274
+ ["oldlace", "#fdf5e6"],
275
+ ["olive", "#808000"],
276
+ ["olivedrab", "#6b8e23"],
277
+ ["orangered", "#ff4500"],
278
+ ["orchid", "#da70d6"],
279
+ ["palegoldenrod", "#eee8aa"],
280
+ ["palegreen", "#98fb98"],
281
+ ["paleturquoise", "#afeeee"],
282
+ ["palevioletred", "#db7093"],
283
+ ["papayawhip", "#ffefd5"],
284
+ ["peachpuff", "#ffdab9"],
285
+ ["peru", "#cd853f"],
286
+ ["pink", "#ffc0cb"],
287
+ ["plum", "#dda0dd"],
288
+ ["powderblue", "#b0e0e6"],
289
+ ["purple", "#800080"],
290
+ ["red", "#ff0000"],
291
+ ["rosybrown", "#bc8f8f"],
292
+ ["royalblue", "#4169e1"],
293
+ ["saddlebrown", "#8b4513"],
294
+ ["salmon", "#fa8072"],
295
+ ["sandybrown", "#f4a460"],
296
+ ["seagreen", "#2e8b57"],
297
+ ["seashell", "#fff5ee"],
298
+ ["sienna", "#a0522d"],
299
+ ["silver", "#c0c0c0"],
300
+ ["skyblue", "#87ceeb"],
301
+ ["slateblue", "#6a5acd"],
302
+ ["slategray", "#708090"],
303
+ ["slategrey", "#708090"],
304
+ ["snow", "#fffafa"],
305
+ ["springgreen", "#00ff7f"],
306
+ ["steelblue", "#4682b4"],
307
+ ["tan", "#d2b48c"],
308
+ ["teal", "#008080"],
309
+ ["thistle", "#d8bfd8"],
310
+ ["tomato", "#ff6347"],
311
+ ["transparent", "#00000000"],
312
+ ["turquoise", "#40e0d0"],
313
+ ["violet", "#ee82ee"],
314
+ ["wheat", "#f5deb3"],
315
+ ["white", "#ffffff"],
316
+ ["whitesmoke", "#f5f5f5"],
317
+ ["yellow", "#ffff00"],
318
+ ["yellowgreen", "#9acd32"]
319
+ ]);
320
+ function convertHextoNamedCSSColour(colour) {
321
+ for (const [name, hex] of namedCSSColours.entries()) {
322
+ if (hex === colour) {
323
+ return name;
324
+ }
325
+ }
326
+ return void 0;
327
+ }
328
+ function convertHextoRGB(hex) {
329
+ if (typeof hex !== "string") {
330
+ throw new Error(`convertHextoRGB expects a string but got a ${typeof hex}`);
331
+ }
332
+ if (hex.match(hexRegex)) {
333
+ return {
334
+ R: Number.parseInt(`${hex[1]}${hex[2]}`, 16),
335
+ G: Number.parseInt(`${hex[3]}${hex[4]}`, 16),
336
+ B: Number.parseInt(`${hex[5]}${hex[6]}`, 16)
337
+ };
338
+ }
339
+ if (hex.match(shortHexRegex)) {
340
+ return {
341
+ R: Number.parseInt(`${hex[1]}${hex[1]}`, 16),
342
+ G: Number.parseInt(`${hex[2]}${hex[2]}`, 16),
343
+ B: Number.parseInt(`${hex[3]}${hex[3]}`, 16)
344
+ };
345
+ }
346
+ if (hex.match(hexAlphaRegex)) {
347
+ return {
348
+ R: Number.parseInt(`${hex[1]}${hex[2]}`, 16),
349
+ G: Number.parseInt(`${hex[3]}${hex[4]}`, 16),
350
+ B: Number.parseInt(`${hex[5]}${hex[6]}`, 16),
351
+ A: Number.parseInt(`${hex[7]}${hex[8]}`, 16) / 255
352
+ };
353
+ }
354
+ if (hex.match(shortAlphaHexRegex)) {
355
+ return {
356
+ R: Number.parseInt(`${hex[1]}${hex[1]}`, 16),
357
+ G: Number.parseInt(`${hex[2]}${hex[2]}`, 16),
358
+ B: Number.parseInt(`${hex[3]}${hex[3]}`, 16),
359
+ A: Number.parseInt(`${hex[4]}${hex[4]}`, 16) / 255
360
+ };
361
+ }
362
+ throw new Error(
363
+ `convertHextoRGB expects an valid hexadecimal colour value but got ${hex}`
364
+ );
365
+ }
366
+ function convertNamedCSSColourtoHex(name) {
367
+ return namedCSSColours.get(name);
368
+ }
369
+ function convertNamedCSSColourtoRGB(colour) {
370
+ const hex = convertNamedCSSColourtoHex(colour);
371
+ if (!hex) {
372
+ return void 0;
373
+ }
374
+ return convertHextoRGB(hex);
375
+ }
376
+ function convertRGBtoCSSRGB({ R, G, B, A }) {
377
+ return `rgb(${R} ${G} ${B}${A ? ` / ${A}` : ""})`;
378
+ }
379
+ function convertRGBtoNamedCSSColour(colour) {
380
+ const hex = convertRGBtoHex(colour);
381
+ return convertHextoNamedCSSColour(hex);
382
+ }
383
+ function findNearestRGBColour(colour, palette) {
384
+ if (!palette || palette.length < 2) {
385
+ return colour;
386
+ }
387
+ const map = [];
388
+ for (const paletteColour of palette) {
389
+ const distance = RGBdistance(colour, paletteColour);
390
+ map.push([paletteColour, distance]);
391
+ }
392
+ const closest = map.sort((a, b) => a[1] - b[1]);
393
+ return closest[0][0];
394
+ }
395
+ function findNearestCSSRGBColour(colour, palette) {
396
+ if (!palette || palette.length < 2) {
397
+ return colour;
398
+ }
399
+ const baseRGBColour = convertCSSRGBtoRGB(colour);
400
+ const paletteRGBColours = palette.map(
401
+ (hexColour) => convertCSSRGBtoRGB(hexColour)
402
+ );
403
+ const nearestRGBColour = findNearestRGBColour(
404
+ baseRGBColour,
405
+ paletteRGBColours
406
+ );
407
+ return convertRGBtoCSSRGB(nearestRGBColour);
408
+ }
409
+ function isCSSRGBColour(colour) {
410
+ return !!colour.match(cssRGBARegex);
411
+ }
412
+ function isHexColour(colour) {
413
+ return !!colour.match(hexRegex) || !!colour.match(hexAlphaRegex) || !!colour.match(shortAlphaHexRegex) || !!colour.match(shortHexRegex);
414
+ }
415
+ function isNamedCSSColour(colour) {
416
+ return namedCSSColours.has(colour);
417
+ }
418
+ function findNearestColour(colour, palette) {
419
+ if (!palette || palette.length < 2) {
420
+ return colour;
421
+ }
422
+ let baseColour;
423
+ let colourType;
424
+ const paletteRGB = [];
425
+ if (isHexColour(colour)) {
426
+ baseColour = convertHextoRGB(colour);
427
+ colourType = "hex";
428
+ }
429
+ if (isCSSRGBColour(colour)) {
430
+ baseColour = convertCSSRGBtoRGB(colour);
431
+ colourType = "cssRGB";
432
+ }
433
+ if (isNamedCSSColour(colour)) {
434
+ baseColour = convertNamedCSSColourtoRGB(colour);
435
+ colourType = "namedCSS";
436
+ }
437
+ if (!baseColour) {
438
+ return void 0;
439
+ }
440
+ for (const paletteColour of palette) {
441
+ if (isHexColour(paletteColour)) {
442
+ paletteRGB.push(convertHextoRGB(paletteColour));
443
+ }
444
+ if (isCSSRGBColour(paletteColour)) {
445
+ paletteRGB.push(convertCSSRGBtoRGB(paletteColour));
446
+ }
447
+ if (isNamedCSSColour(paletteColour)) {
448
+ paletteRGB.push(convertNamedCSSColourtoRGB(paletteColour));
449
+ }
450
+ }
451
+ if (paletteRGB.length < 2) {
452
+ return colour;
453
+ }
454
+ const nearest = findNearestRGBColour(baseColour, paletteRGB);
455
+ if (colourType === "hex") {
456
+ return convertRGBtoHex(nearest);
457
+ }
458
+ if (colourType === "cssRGB") {
459
+ return convertRGBtoCSSRGB(nearest);
460
+ }
461
+ if (colourType === "namedCSS") {
462
+ return convertRGBtoNamedCSSColour(nearest);
463
+ }
464
+ return;
465
+ }
466
+ function findNearestHexColour(colour, palette) {
467
+ if (!palette || palette.length < 2) {
468
+ return colour;
469
+ }
470
+ const baseRGBColour = convertHextoRGB(colour);
471
+ const paletteRGBColours = palette.map(
472
+ (hexColour) => convertHextoRGB(hexColour)
473
+ );
474
+ const nearestRGBColour = findNearestRGBColour(
475
+ baseRGBColour,
476
+ paletteRGBColours
477
+ );
478
+ return convertRGBtoHex(nearestRGBColour);
479
+ }
480
+ function findNearestNamedCSSColour(colour, palette) {
481
+ if (!palette || palette.length < 2) {
482
+ return colour;
483
+ }
484
+ const baseRGBColour = convertNamedCSSColourtoRGB(colour);
485
+ const paletteRGBColours = palette.map(
486
+ (hexColour) => convertNamedCSSColourtoRGB(hexColour)
487
+ );
488
+ const filteredPaletteRGBColours = paletteRGBColours.filter(
489
+ (paletteRGBColour) => paletteRGBColour !== void 0
490
+ );
491
+ if (!baseRGBColour || filteredPaletteRGBColours.length < 2) {
492
+ return colour;
493
+ }
494
+ const nearestRGBColour = findNearestRGBColour(
495
+ baseRGBColour,
496
+ filteredPaletteRGBColours
497
+ );
498
+ return convertRGBtoNamedCSSColour(nearestRGBColour);
499
+ }
500
+ function getSRGBLuminanceFromRGB({ R, G, B }, standard) {
501
+ const isWCAG21 = standard === "WCAG2.1";
502
+ const r = linearRGB(R, isWCAG21);
503
+ const g = linearRGB(G, isWCAG21);
504
+ const b = linearRGB(B, isWCAG21);
505
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
506
+ }
507
+ function getSRGBLuminanceFromHex(colour, standard) {
508
+ const rgbColor = convertHextoRGB(colour);
509
+ return getSRGBLuminanceFromRGB(rgbColor, standard);
510
+ }
511
+ function isHexDarkColour(colour, standard) {
512
+ const colourLuminance = getSRGBLuminanceFromHex(colour, standard) + 0.05;
513
+ const whiteContrast = 1.05 / colourLuminance;
514
+ const blackContrast = colourLuminance / 0.05;
515
+ return whiteContrast > blackContrast;
516
+ }
517
+ function isCSSNamedDarkColour(name, standard) {
518
+ const hex = convertNamedCSSColourtoHex(name);
519
+ if (hex) {
520
+ return isHexDarkColour(hex, standard);
521
+ }
522
+ throw new Error(
523
+ `${name} is not a valid colour format. isCSSNamedDarkColour only accepts CSS named colours. Check more details here https://developer.mozilla.org/en-US/docs/Web/CSS/named-color`
524
+ );
525
+ }
526
+ function isCSSRGBDarkColour(colour, standard) {
527
+ const rgb = convertCSSRGBtoRGB(colour);
528
+ const colourLuminance = getSRGBLuminanceFromRGB(rgb, standard);
529
+ const whiteContrast = 1.05 / colourLuminance;
530
+ const blackContrast = colourLuminance / 0.05;
531
+ return whiteContrast > blackContrast;
532
+ }
533
+ function isDarkColour(colour, standard) {
534
+ try {
535
+ if (colour.startsWith("#")) {
536
+ return isHexDarkColour(colour, standard);
537
+ }
538
+ if (colour.startsWith("rgb")) {
539
+ return isCSSRGBDarkColour(colour, standard);
540
+ }
541
+ return isCSSNamedDarkColour(colour, standard);
542
+ } catch (error) {
543
+ throw new Error(
544
+ `${colour} is not a valid colour format. isDarkColour accepts CSS RGB formats, ie rgb(0,0,0) and rgba(255, 255, 255, 0.4), hexadecimal and CSS named colours.`
545
+ );
546
+ }
547
+ }
548
+ const relativeContrast = (firstColour, secondColour) => {
549
+ if (firstColour > secondColour) {
550
+ return firstColour / secondColour;
551
+ }
552
+ return secondColour / firstColour;
553
+ };
554
+ const pickHexColourContrast = ({ backgroundColour, optionOneColour, optionTwoColour }, standard) => {
555
+ const backgroundColourLuminance = getSRGBLuminanceFromHex(backgroundColour, standard) + 0.05;
556
+ const optionOneColourLuminance = getSRGBLuminanceFromHex(optionOneColour, standard) + 0.05;
557
+ const optionTwoColourLuminance = getSRGBLuminanceFromHex(optionTwoColour, standard) + 0.05;
558
+ const optionOneContrast = relativeContrast(
559
+ optionOneColourLuminance,
560
+ backgroundColourLuminance
561
+ );
562
+ const optionTwoContrast = relativeContrast(
563
+ optionTwoColourLuminance,
564
+ backgroundColourLuminance
565
+ );
566
+ if (optionOneContrast > optionTwoContrast) {
567
+ return optionOneColour;
568
+ }
569
+ return optionTwoColour;
570
+ };
571
+ exports.RGBdistance = RGBdistance;
572
+ exports.ciede2000 = ciede2000;
573
+ exports.convertCSSRGBtoHex = convertCSSRGBtoHex;
574
+ exports.convertCSSRGBtoRGB = convertCSSRGBtoRGB;
575
+ exports.convertHextoNamedCSSColour = convertHextoNamedCSSColour;
576
+ exports.convertHextoRGB = convertHextoRGB;
577
+ exports.convertNamedCSSColourtoHex = convertNamedCSSColourtoHex;
578
+ exports.convertNamedCSSColourtoRGB = convertNamedCSSColourtoRGB;
579
+ exports.convertRGBtoCSSRGB = convertRGBtoCSSRGB;
580
+ exports.convertRGBtoHex = convertRGBtoHex;
581
+ exports.convertRGBtoLab = convertRGBtoLab;
582
+ exports.convertRGBtoNamedCSSColour = convertRGBtoNamedCSSColour;
583
+ exports.convertRGBtoXYZ = convertRGBtoXYZ;
584
+ exports.convertXYZtoLab = convertXYZtoLab;
585
+ exports.findNearestCSSRGBColour = findNearestCSSRGBColour;
586
+ exports.findNearestColour = findNearestColour;
587
+ exports.findNearestHexColour = findNearestHexColour;
588
+ exports.findNearestNamedCSSColour = findNearestNamedCSSColour;
589
+ exports.findNearestRGBColour = findNearestRGBColour;
590
+ exports.getSRGBLuminanceFromHex = getSRGBLuminanceFromHex;
591
+ exports.getSRGBLuminanceFromRGB = getSRGBLuminanceFromRGB;
592
+ exports.isCSSNamedDarkColour = isCSSNamedDarkColour;
593
+ exports.isCSSRGBColour = isCSSRGBColour;
594
+ exports.isCSSRGBDarkColour = isCSSRGBDarkColour;
595
+ exports.isDarkColour = isDarkColour;
596
+ exports.isHexDarkColour = isHexDarkColour;
597
+ exports.pickHexColourContrast = pickHexColourContrast;
@@ -0,0 +1 @@
1
+ "use strict";function x(e,t){if(e===0&&t===0)return 0;const n=Math.atan2(e,t)*(180/Math.PI);return n>=0?n:n+360}function me({C1:e,C2:t,h1_d:n,h2_d:r}){return e*t===0?0:Math.abs(r-n)<=180?r-n:r-n>180?r-n-360:r-n<-180?r-n+360:0}function ge({C1:e,C2:t,h1_d:n,h2_d:r}){return e*t===0?r+n:Math.abs(n-r)<=180?(r+n)/2:Math.abs(n-r)>180&&n+r<360?(r+n+360)/2:Math.abs(n-r)>180&&n+r>=360?(r+n-360)/2:0}const d=e=>e*(Math.PI/180),z=e=>Math.sqrt(e**7/(e**7+25**7));function b(e,t){const n=e/255,r=t?.03928:.04045;let o;return n>r?o=((n+.055)/1.055)**2.4:o=n/12.92,o}function v(e){const t=.20689655172413793,n=t**3;let r;return e>n?r=Math.cbrt(e):r=e/(3*t**2)+4/29,r}function Ce(e,t,n){return Math.min(Math.max(e,t),n)}function j(e,t){const n=e.L,r=e.a,o=e.b,a=t.L,f=t.a,s=t.b,c=1,l=1,G=1,m=Math.sqrt(r**2+o**2),g=Math.sqrt(f**2+s**2),se=a-n,ce=(m+g)/2,A=.5*(1-z(ce)),E=r*(1+A),F=f*(1+A),k=Math.sqrt(E**2+o**2),B=Math.sqrt(F**2+s**2),$=(k+B)/2,X=B-k,Y=x(o,E),Z=x(s,F),ie=me({C1:m,C2:g,h1_d:Y,h2_d:Z}),D=2*Math.sqrt(k*B)*Math.sin(d(ie)/2),C=ge({C1:m,C2:g,h1_d:Y,h2_d:Z}),W=(n+a)/2,ue=1-.17*Math.cos(d(C-30))+.24*Math.cos(d(2*C))+.32*Math.cos(d(3*C+6))-.2*Math.cos(d(4*C-63)),le=1+.015*(W-50)**2/Math.sqrt(20+(W-50)**2),T=.045*$+1,P=1+.015*$*ue,de=30*Math.exp(-(((C-275)/25)**2)),be=-2*z($)*Math.sin(d(de*2));return Math.sqrt((se/(c*le))**2+(X/(l*T))**2+(D/(G*P))**2+be*(X/(l*T))*(D/(G*P)))}function O(e){const{R:t,G:n,B:r}=e,o=b(t)*100,a=b(n)*100,f=b(r)*100,s=o*.4124+a*.3576+f*.1805,c=o*.2126+a*.7152+f*.0722,l=o*.0193+a*.1192+f*.9505;return{X:s,Y:c,Z:l}}function U(e){const{X:t,Y:n,Z:r}=e,o=t/95.047,a=n/100,f=r/108.883,s=v(o),c=v(a),l=v(f),G=116*c-16,m=500*(s-c),g=200*(c-l);return{L:G,a:m,b:g}}function y(e){const t=O(e);return U(t)}const V=(e,t)=>{const n=y(e),r=y(t);return j(n,r)},J=/^#[a-fA-F0-9]{6}$/,K=/^#[a-fA-F0-9]{8}$/,Q=/^#[a-fA-F0-9]{3}$/,_=/^#[a-fA-F0-9]{4}$/,ee=/^rgba*\(\s*([-+]?\d+)\s*(?:,)?\s*([-+]?\d+)\s*(?:,)?\s*([-+]?\d+)\s*(?:,*|\/*)\s*([-+]?\d*[.]?\d+[%]?)*\)$/i;function i(e){const t=e.match(ee);if(!t)throw new Error(`convertCSSRGBtoHex expects a valid CSS RGB string but got ${e}`);const n=r=>r?Number.parseFloat(r):void 0;return{R:n(t[1]),G:n(t[2]),B:n(t[3]),A:n(t[4])}}function p({R:e,G:t,B:n,A:r}){const o=a=>Ce(a,0,255).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}${r?o(Math.round(r*255)):""}`}function pe(e){const t=i(e);return p(t)}const w=new Map([["aliceblue","#f0f8ff"],["antiquewhite","#faebd7"],["aqua","#00ffff"],["aquamarine","#7fffd4"],["azure","#f0ffff"],["beige","#f5f5dc"],["bisque","#ffe4c4"],["black","#000000"],["blanchedalmond","#ffebcd"],["blue","#0000ff"],["blueviolet","#8a2be2"],["brown","#a52a2a"],["burlywood","#deb887"],["cadetblue","#5f9ea0"],["chartreuse","#7fff00"],["chocolate","#d2691e"],["coral","#ff7f50"],["cornflowerblue","#6495ed"],["cornsilk","#fff8dc"],["crimson","#dc143c"],["cyan","#00ffff"],["darkblue","#00008b"],["darkcyan","#008b8b"],["darkgoldenrod","#b8860b"],["darkgray","#a9a9a9"],["darkgreen","#006400"],["darkgrey","#a9a9a9"],["darkkhaki","#bdb76b"],["darkmagenta","#8b008b"],["darkolivegreen","#556b2f"],["darkorange","#ff8c00"],["darkorchid","#9932cc"],["darkred","#8b0000"],["darksalmon","#e9967a"],["darkseagreen","#8fbc8f"],["darkslateblue","#483d8b"],["darkslategray","#2f4f4f"],["darkslategrey","#2f4f4f"],["darkturquoise","#00ced1"],["darkviolet","#9400d3"],["deeppink","#ff1493"],["deepskyblue","#00bfff"],["dimgray","#696969"],["dimgrey","#696969"],["dodgerblue","#1e90ff"],["firebrick","#b22222"],["floralwhite","#fffaf0"],["forestgreen","#228b22"],["fuchsia","#ff00ff"],["gainsboro","#dcdcdc"],["ghostwhite","#f8f8ff"],["gold","#ffd700"],["goldenrod","#daa520"],["gray","#808080"],["green","#008000"],["greenyellow","#adff2f"],["grey","#808080"],["honeydew","#f0fff0"],["hotpink","#ff69b4"],["indianred","#cd5c5c"],["indigo","#4b0082"],["ivory","#fffff0"],["khaki","#f0e68c"],["lavender","#e6e6fa"],["lavenderblush","#fff0f5"],["lawngreen","#7cfc00"],["lemonchiffon","#fffacd"],["lightblue","#add8e6"],["lightcoral","#f08080"],["lightcyan","#e0ffff"],["lightgoldenrodyellow","#fafad2"],["lightgray","#d3d3d3"],["lightgreen","#90ee90"],["lightgrey","#d3d3d3"],["lightpink","#ffb6c1"],["lightsalmon","#ffa07a"],["lightseagreen","#20b2aa"],["lightskyblue","#87cefa"],["lightslategray","#778899"],["lightslategrey","#778899"],["lightsteelblue","#b0c4de"],["lightyellow","#ffffe0"],["lime","#00ff00"],["limegreen","#32cd32"],["linen","#faf0e6"],["magenta","#ff00ff"],["maroon","#800000"],["mediumaquamarine","#66cdaa"],["mediumblue","#0000cd"],["mediumorchid","#ba55d3"],["mediumpurple","#9370db"],["mediumseagreen","#3cb371"],["mediumslateblue","#7b68ee"],["mediumspringgreen","#00fa9a"],["mediumturquoise","#48d1cc"],["mediumvioletred","#c71585"],["midnightblue","#191970"],["mintcream","#f5fffa"],["mistyrose","#ffe4e1"],["moccasin","#ffe4b5"],["navajowhite","#ffdead"],["navy","#000080"],["oldlace","#fdf5e6"],["olive","#808000"],["olivedrab","#6b8e23"],["orangered","#ff4500"],["orchid","#da70d6"],["palegoldenrod","#eee8aa"],["palegreen","#98fb98"],["paleturquoise","#afeeee"],["palevioletred","#db7093"],["papayawhip","#ffefd5"],["peachpuff","#ffdab9"],["peru","#cd853f"],["pink","#ffc0cb"],["plum","#dda0dd"],["powderblue","#b0e0e6"],["purple","#800080"],["red","#ff0000"],["rosybrown","#bc8f8f"],["royalblue","#4169e1"],["saddlebrown","#8b4513"],["salmon","#fa8072"],["sandybrown","#f4a460"],["seagreen","#2e8b57"],["seashell","#fff5ee"],["sienna","#a0522d"],["silver","#c0c0c0"],["skyblue","#87ceeb"],["slateblue","#6a5acd"],["slategray","#708090"],["slategrey","#708090"],["snow","#fffafa"],["springgreen","#00ff7f"],["steelblue","#4682b4"],["tan","#d2b48c"],["teal","#008080"],["thistle","#d8bfd8"],["tomato","#ff6347"],["transparent","#00000000"],["turquoise","#40e0d0"],["violet","#ee82ee"],["wheat","#f5deb3"],["white","#ffffff"],["whitesmoke","#f5f5f5"],["yellow","#ffff00"],["yellowgreen","#9acd32"]]);function te(e){for(const[t,n]of w.entries())if(n===e)return t}function u(e){if(typeof e!="string")throw new Error(`convertHextoRGB expects a string but got a ${typeof e}`);if(e.match(J))return{R:Number.parseInt(`${e[1]}${e[2]}`,16),G:Number.parseInt(`${e[3]}${e[4]}`,16),B:Number.parseInt(`${e[5]}${e[6]}`,16)};if(e.match(Q))return{R:Number.parseInt(`${e[1]}${e[1]}`,16),G:Number.parseInt(`${e[2]}${e[2]}`,16),B:Number.parseInt(`${e[3]}${e[3]}`,16)};if(e.match(K))return{R:Number.parseInt(`${e[1]}${e[2]}`,16),G:Number.parseInt(`${e[3]}${e[4]}`,16),B:Number.parseInt(`${e[5]}${e[6]}`,16),A:Number.parseInt(`${e[7]}${e[8]}`,16)/255};if(e.match(_))return{R:Number.parseInt(`${e[1]}${e[1]}`,16),G:Number.parseInt(`${e[2]}${e[2]}`,16),B:Number.parseInt(`${e[3]}${e[3]}`,16),A:Number.parseInt(`${e[4]}${e[4]}`,16)/255};throw new Error(`convertHextoRGB expects an valid hexadecimal colour value but got ${e}`)}function N(e){return w.get(e)}function h(e){const t=N(e);if(t)return u(t)}function M({R:e,G:t,B:n,A:r}){return`rgb(${e} ${t} ${n}${r?` / ${r}`:""})`}function H(e){const t=p(e);return te(t)}function R(e,t){if(!t||t.length<2)return e;const n=[];for(const o of t){const a=V(e,o);n.push([o,a])}return n.sort((o,a)=>o[1]-a[1])[0][0]}function he(e,t){if(!t||t.length<2)return e;const n=i(e),r=t.map(a=>i(a)),o=R(n,r);return M(o)}function L(e){return!!e.match(ee)}function ne(e){return!!e.match(J)||!!e.match(K)||!!e.match(_)||!!e.match(Q)}function re(e){return w.has(e)}function Re(e,t){if(!t||t.length<2)return e;let n,r;const o=[];if(ne(e)&&(n=u(e),r="hex"),L(e)&&(n=i(e),r="cssRGB"),re(e)&&(n=h(e),r="namedCSS"),!n)return;for(const f of t)ne(f)&&o.push(u(f)),L(f)&&o.push(i(f)),re(f)&&o.push(h(f));if(o.length<2)return e;const a=R(n,o);if(r==="hex")return p(a);if(r==="cssRGB")return M(a);if(r==="namedCSS")return H(a)}function Se(e,t){if(!t||t.length<2)return e;const n=u(e),r=t.map(a=>u(a)),o=R(n,r);return p(o)}function Ge(e,t){if(!t||t.length<2)return e;const n=h(e),o=t.map(f=>h(f)).filter(f=>f!==void 0);if(!n||o.length<2)return e;const a=R(n,o);return H(a)}function q({R:e,G:t,B:n},r){const o=r==="WCAG2.1",a=b(e,o),f=b(t,o),s=b(n,o);return .2126*a+.7152*f+.0722*s}function S(e,t){const n=u(e);return q(n,t)}function I(e,t){const n=S(e,t)+.05,r=1.05/n,o=n/.05;return r>o}function oe(e,t){const n=N(e);if(n)return I(n,t);throw new Error(`${e} is not a valid colour format. isCSSNamedDarkColour only accepts CSS named colours. Check more details here https://developer.mozilla.org/en-US/docs/Web/CSS/named-color`)}function ae(e,t){const n=i(e),r=q(n,t),o=1.05/r,a=r/.05;return o>a}function ke(e,t){try{return e.startsWith("#")?I(e,t):e.startsWith("rgb")?ae(e,t):oe(e,t)}catch{throw new Error(`${e} is not a valid colour format. isDarkColour accepts CSS RGB formats, ie rgb(0,0,0) and rgba(255, 255, 255, 0.4), hexadecimal and CSS named colours.`)}}const fe=(e,t)=>e>t?e/t:t/e,Be=({backgroundColour:e,optionOneColour:t,optionTwoColour:n},r)=>{const o=S(e,r)+.05,a=S(t,r)+.05,f=S(n,r)+.05,s=fe(a,o),c=fe(f,o);return s>c?t:n};export{V as RGBdistance,j as ciede2000,pe as convertCSSRGBtoHex,i as convertCSSRGBtoRGB,te as convertHextoNamedCSSColour,u as convertHextoRGB,N as convertNamedCSSColourtoHex,h as convertNamedCSSColourtoRGB,M as convertRGBtoCSSRGB,p as convertRGBtoHex,y as convertRGBtoLab,H as convertRGBtoNamedCSSColour,O as convertRGBtoXYZ,U as convertXYZtoLab,he as findNearestCSSRGBColour,Re as findNearestColour,Se as findNearestHexColour,Ge as findNearestNamedCSSColour,R as findNearestRGBColour,S as getSRGBLuminanceFromHex,q as getSRGBLuminanceFromRGB,oe as isCSSNamedDarkColour,L as isCSSRGBColour,ae as isCSSRGBDarkColour,ke as isDarkColour,I as isHexDarkColour,Be as pickHexColourContrast};