@sardine/colour 3.0.0 → 4.0.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/convertHextoCSSRGB.d.ts +1 -1
- package/dist/convertHextoRGB.d.ts +2 -2
- package/dist/getContrastRatioFromHex.d.ts +1 -1
- package/dist/getContrastRatioFromNamedCSSColour.d.ts +1 -1
- package/dist/getSRGBLuminanceFromHex.d.ts +1 -1
- package/dist/index.cjs +984 -646
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +986 -683
- package/dist/pickHexColourContrast.d.ts +1 -1
- package/dist/sortHexColours.d.ts +1 -1
- package/package.json +3 -3
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const $=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"],["orange","#ffa500"],["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"],["rebeccapurple","#663399"],["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"]]),j=/^#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{4}|[0-9a-fA-F]{3})$/,Q=/^rgba?\(\s*([-+]?\d*\.?\d+%?)\s*[,\s]\s*([-+]?\d*\.?\d+%?)\s*[,\s]\s*([-+]?\d*\.?\d+%?)\s*(?:[,/]\s*([-+]?\d*\.?\d+%?))?\s*\)$/i;function x(e){return Q.test(e)}function L(e){return j.test(e)}function A(e){return $.has(e)}function J(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 Se({C1:e,C2:t,h1_d:n,h2_d:o}){if(e*t===0)return 0;const r=o-n;return Math.abs(r)<=180?r:r>180?r-360:r+360}function Re({C1:e,C2:t,h1_d:n,h2_d:o}){if(e*t===0)return o+n;const r=Math.abs(n-o);return r<=180?(o+n)/2:r>180&&n+o<360?(o+n+360)/2:(o+n-360)/2}const ve=Math.PI/180,m=e=>e*ve,Be=25**7,K=e=>Math.sqrt(e**7/(e**7+Be));function C(e,t){const n=e/255,o=t?.03928:.04045;let r;return n>o?r=((n+.055)/1.055)**2.4:r=n/12.92,r}const ee=6/29,Ge=ee**3,we=3*ee**2;function H(e){return e>Ge?Math.cbrt(e):e/we+4/29}function ke(e,t,n){return Math.min(Math.max(e,t),n)}const w="https://developer.mozilla.org/en-US/docs/Web/CSS/named-color";function te(e,t){const n=e.L,o=e.a,r=e.b,a=t.L,s=t.a,f=t.b,c=1,i=1,l=1,u=Math.sqrt(o**2+r**2),p=Math.sqrt(s**2+f**2),de=a-n,ge=(u+p)/2,D=.5*(1-K(ge)),F=o*(1+D),T=s*(1+D),k=Math.sqrt(F**2+r**2),y=Math.sqrt(T**2+f**2),M=(k+y)/2,Y=y-k,O=J(r,F),X=J(f,T),he=Se({C1:u,C2:p,h1_d:O,h2_d:X}),Z=2*Math.sqrt(k*y)*Math.sin(m(he)/2),S=Re({C1:u,C2:p,h1_d:O,h2_d:X}),V=(n+a)/2,be=1-.17*Math.cos(m(S-30))+.24*Math.cos(m(2*S))+.32*Math.cos(m(3*S+6))-.2*Math.cos(m(4*S-63)),me=1+.015*(V-50)**2/Math.sqrt(20+(V-50)**2),U=.045*M+1,z=1+.015*M*be,Ce=30*Math.exp(-(((S-275)/25)**2)),pe=-2*K(M)*Math.sin(m(Ce*2));return Math.sqrt((de/(c*me))**2+(Y/(i*U))**2+(Z/(l*z))**2+pe*(Y/(i*U))*(Z/(l*z)))}function ne(e,t=!1){if(e.endsWith("%")){const n=Number.parseFloat(e.slice(0,-1));return t?n/100:Math.round(n/100*255)}return Number.parseFloat(e)}function I(e){if(e)return ne(e)}function ye(e){if(e)return ne(e,!0)}function d(e){const t=e.match(Q);if(!t)throw new Error(`convertCSSRGBtoRGB expects a valid CSS RGB string but got ${e}`);return{R:I(t[1]),G:I(t[2]),B:I(t[3]),A:ye(t[4])}}function R({R:e,G:t,B:n,A:o}){const r=a=>ke(a,0,255).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}${o?r(Math.round(o*255)):""}`}function N(e){const t=d(e);return R(t)}function g(e){if(typeof e!="string")throw new Error(`convertHextoRGB expects a string but got a ${typeof e}`);if(!j.test(e))throw new Error(`convertHextoRGB expects a valid hexadecimal colour value but got ${e}`);switch(e.length){case 7:return{R:parseInt(e.slice(1,3),16),G:parseInt(e.slice(3,5),16),B:parseInt(e.slice(5,7),16)};case 4:return{R:parseInt(e.slice(1,2).repeat(2),16),G:parseInt(e.slice(2,3).repeat(2),16),B:parseInt(e.slice(3,4).repeat(2),16)};case 9:return{R:parseInt(e.slice(1,3),16),G:parseInt(e.slice(3,5),16),B:parseInt(e.slice(5,7),16),A:Math.round(parseInt(e.slice(7,9),16)/255*100)/100};default:return{R:parseInt(e.slice(1,2).repeat(2),16),G:parseInt(e.slice(2,3).repeat(2),16),B:parseInt(e.slice(3,4).repeat(2),16),A:Math.round(parseInt(e.slice(4,5).repeat(2),16)/255*100)/100}}}function Me(e){const t=g(e);return t.A?`rgba(${t.R},${t.G},${t.B},${t.A})`:`rgb(${t.R},${t.G},${t.B})`}function re(e){for(const[t,n]of $.entries())if(n===e)return t}function h(e){return $.get(e)}function v(e){const t=h(e);if(t)return g(t)}function _({R:e,G:t,B:n,A:o}){return`rgb(${e} ${t} ${n}${o?` / ${o}`:""})`}function oe(e){const{R:t,G:n,B:o}=e,r=C(t)*100,a=C(n)*100,s=C(o)*100,f=r*.4124+a*.3576+s*.1805,c=r*.2126+a*.7152+s*.0722,i=r*.0193+a*.1192+s*.9505;return{X:f,Y:c,Z:i}}function ae(e){const{X:t,Y:n,Z:o}=e,r=t/95.047,a=n/100,s=o/108.883,f=H(r),c=H(a),i=H(s),l=116*c-16,u=500*(f-c),p=200*(c-i);return{L:l,a:u,b:p}}function q(e){const t=oe(e);return ae(t)}function E(e){const t=R(e);return re(t)}const se=(e,t)=>{const n=q(e),o=q(t);return te(n,o)};function B(e,t){if(!t||t.length<2)return e;let n=e,o=Number.POSITIVE_INFINITY;for(const r of t){const a=se(e,r);a<o&&(o=a,n=r)}return n}function $e(e,t){if(!t||t.length<2)return e;let n,o;const r=[];if(L(e)?(n=g(e),o="hex"):x(e)?(n=d(e),o="cssRGB"):A(e)&&(n=v(e),o="namedCSS"),!n)return;for(const s of t)if(L(s))r.push(g(s));else if(x(s))r.push(d(s));else if(A(s)){const f=v(s);f&&r.push(f)}if(r.length<2)return e;const a=B(n,r);return o==="hex"?R(a):o==="cssRGB"?_(a):E(a)}function xe(e,t){if(!t||t.length<2)return e;const n=d(e),o=t.map(a=>d(a)),r=B(n,o);return _(r)}function Le(e,t){if(!t||t.length<2)return e;const n=g(e),o=t.map(a=>g(a)),r=B(n,o);return R(r)}function Ae(e,t){if(!t||t.length<2)return e;const n=v(e),r=t.map(s=>v(s)).filter(s=>s!==void 0);if(!n||r.length<2)return e;const a=B(n,r);return E(a)}function G({R:e,G:t,B:n},o){const r=o==="WCAG2.1",a=C(e,r),s=C(t,r),f=C(n,r);return .2126*a+.7152*s+.0722*f}function b(e,t){const n=g(e);return G(n,t)}function ce(e,t){const n=Math.max(e,t),o=Math.min(e,t),r=(n+.05)/(o+.05);return Math.floor(r*1e3)/1e3}function P(e,t,n){const o=b(e,n),r=b(t,n);return ce(o,r)}function He(e,t,n){let o,r;if(e.startsWith("#"))o=e;else if(e.startsWith("rgb"))o=N(e);else{const a=h(e);if(a===void 0)throw new Error(`getContrastRatio expects valid CSS named colours. ${e} is not a valid CSS named colour. See ${w}`);o=a}if(t.startsWith("#"))r=t;else if(t.startsWith("rgb"))r=N(t);else{const a=h(t);if(a===void 0)throw new Error(`getContrastRatio expects valid CSS named colours. ${t} is not a valid CSS named colour. See ${w}`);r=a}return P(o,r,n)}function Ie(e,t,n){const o=d(e),r=d(t),a=G(o,n),s=G(r,n);return ce(a,s)}function Ne(e,t,n){const o=h(e),r=h(t);if(o===void 0||r===void 0)throw new Error(`getContrastRatioFromNamedCSSColour expects valid CSS named colours. ${e} or ${t} are not valid CSS named colours. See ${w}`);return P(o,r,n)}function W(e,t){const n=b(e,t)+.05,o=1.05/n,r=n/.05;return o>r}function fe(e,t){const n=h(e);if(n)return W(n,t);throw new Error(`${e} is not a valid colour format. isCSSNamedDarkColour only accepts CSS named colours. See ${w}`)}function ie(e,t){const n=d(e),o=G(n,t),r=1.05/o,a=o/.05;return r>a}function _e(e,t){try{return e.startsWith("#")?W(e,t):e.startsWith("rgb")?ie(e,t):fe(e,t)}catch{throw new Error(`${e} is not a valid colour format. isDarkColour accepts CSS RGB formats, ie rgb(0,0,0), rgba(255, 255, 255, 0.4), rgb(50%, 25%, 100%), and rgba(50%, 25%, 100%, 80%), hexadecimal and CSS named colours.`)}}const ue=(e,t)=>e>t?e/t:t/e,qe=({backgroundColour:e,optionOneColour:t,optionTwoColour:n},o)=>{const r=b(e,o)+.05,a=b(t,o)+.05,s=b(n,o)+.05,f=ue(a,r),c=ue(s,r);return f>c?t:n};function Ee(e,t,n){const o=e/255,r=t/255,a=n/255,s=Math.max(o,r,a),f=Math.min(o,r,a);let c=0,i=0;const l=s,u=s-f;return s===0?i=0:i=u/s,u!==0&&(s===o?c=(r-a)/u%6:s===r?c=(a-o)/u+2:s===a&&(c=(o-r)/u+4),c=c*60,c<0&&(c=c+360)),{h:c,s:i,v:l}}function Pe(e){const{R:t,G:n,B:o,A:r}=g(e),a=typeof r=="number"?r:1,{h:s,s:f,v:c}=Ee(t,n,o);return{h:s,s:f,v:c,a}}function le(e){return e===0?1:e===1?2:0}function We(e){const t=new Map;for(const a of e)t.has(a)||t.set(a,Pe(a));const n=[],o=[],r=[];for(const a of e){const{s,a:f}=t.get(a);f===0?r.push(a):s===0?o.push(a):n.push(a)}return n.sort((a,s)=>{const f=t.get(a),c=t.get(s);return f.h!==c.h?f.h-c.h:c.s-f.s}),o.sort((a,s)=>{const f=t.get(a),c=t.get(s),i=le(f.v),l=le(c.v);return i!==l?i-l:f.v-c.v}),r.sort((a,s)=>{const f=t.get(a),c=t.get(s);return f.v-c.v}),[...n,...o,...r]}export{se as RGBdistance,te as ciede2000,N as convertCSSRGBtoHex,d as convertCSSRGBtoRGB,Me as convertHextoCSSRGB,re as convertHextoNamedCSSColour,g as convertHextoRGB,h as convertNamedCSSColourtoHex,v as convertNamedCSSColourtoRGB,_ as convertRGBtoCSSRGB,R as convertRGBtoHex,q as convertRGBtoLab,E as convertRGBtoNamedCSSColour,oe as convertRGBtoXYZ,ae as convertXYZtoLab,xe as findNearestCSSRGBColour,$e as findNearestColour,Le as findNearestHexColour,Ae as findNearestNamedCSSColour,B as findNearestRGBColour,He as getContrastRatio,Ie as getContrastRatioFromCSSRGB,P as getContrastRatioFromHex,Ne as getContrastRatioFromNamedCSSColour,b as getSRGBLuminanceFromHex,G as getSRGBLuminanceFromRGB,fe as isCSSNamedDarkColour,x as isCSSRGBColour,ie as isCSSRGBDarkColour,_e as isDarkColour,L as isHexColour,W as isHexDarkColour,A as isNamedCSSColour,qe as pickHexColourContrast,We as sortHexColours};
|
|
1
|
+
"use strict";var $=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"],["orange","#ffa500"],["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"],["rebeccapurple","#663399"],["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"]]),j=/^#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{4}|[0-9a-fA-F]{3})$/,Q=/^rgba?\(\s*([-+]?\d*\.?\d+%?)\s*[,\s]\s*([-+]?\d*\.?\d+%?)\s*[,\s]\s*([-+]?\d*\.?\d+%?)\s*(?:[,/]\s*([-+]?\d*\.?\d+%?))?\s*\)$/i;function L(e){return Q.test(e)}function x(e){return j.test(e)}function A(e){return $.has(e)}function J(e,t){if(e===0&&t===0)return 0;const r=Math.atan2(e,t)*(180/Math.PI);return r>=0?r:r+360}function Se({C1:e,C2:t,h1_d:r,h2_d:n}){if(e*t===0)return 0;const o=n-r;return Math.abs(o)<=180?o:o>180?o-360:o+360}function pe({C1:e,C2:t,h1_d:r,h2_d:n}){if(e*t===0)return n+r;const o=Math.abs(r-n);return o<=180?(n+r)/2:o>180&&r+n<360?(n+r+360)/2:(n+r-360)/2}var ve=Math.PI/180,m=e=>e*ve,Re=25**7,K=e=>Math.sqrt(e**7/(e**7+Re));function C(e,t){const r=e/255,n=t?.03928:.04045;let o;return r>n?o=((r+.055)/1.055)**2.4:o=r/12.92,o}var ee=6/29,Be=ee**3,Ge=3*ee**2;function I(e){return e>Be?Math.cbrt(e):e/Ge+4/29}function ke(e,t,r){return Math.min(Math.max(e,t),r)}var G="https://developer.mozilla.org/en-US/docs/Web/CSS/named-color";function te(e,t){const r=e.L,n=e.a,o=e.b,a=t.L,s=t.a,f=t.b,i=1,c=1,g=1,u=Math.sqrt(n**2+o**2),k=Math.sqrt(s**2+f**2),de=a-r,D=.5*(1-K((u+k)/2)),F=n*(1+D),T=s*(1+D),w=Math.sqrt(F**2+o**2),y=Math.sqrt(T**2+f**2),M=(w+y)/2,Y=y-w,O=J(o,F),V=J(f,T),ge=Se({C1:u,C2:k,h1_d:O,h2_d:V}),X=2*Math.sqrt(w*y)*Math.sin(m(ge)/2),S=pe({C1:u,C2:k,h1_d:O,h2_d:V}),Z=(r+a)/2,he=1-.17*Math.cos(m(S-30))+.24*Math.cos(m(2*S))+.32*Math.cos(m(3*S+6))-.2*Math.cos(m(4*S-63)),be=1+.015*(Z-50)**2/Math.sqrt(20+(Z-50)**2),U=.045*M+1,z=1+.015*M*he,me=30*Math.exp(-(((S-275)/25)**2)),Ce=-2*K(M)*Math.sin(m(me*2));return Math.sqrt((de/(i*be))**2+(Y/(c*U))**2+(X/(g*z))**2+Ce*(Y/(c*U))*(X/(g*z)))}function re(e,t=!1){if(e.endsWith("%")){const r=Number.parseFloat(e.slice(0,-1));return t?r/100:Math.round(r/100*255)}return Number.parseFloat(e)}function N(e){if(e)return re(e)}function we(e){if(e)return re(e,!0)}function l(e){const t=e.match(Q);if(!t)throw new Error(`convertCSSRGBtoRGB expects a valid CSS RGB string but got ${e}`);return{R:N(t[1]),G:N(t[2]),B:N(t[3]),A:we(t[4])}}function p({R:e,G:t,B:r,A:n}){const o=a=>ke(a,0,255).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(r)}${n?o(Math.round(n*255)):""}`}function H(e){return p(l(e))}function d(e){if(typeof e!="string"||!j.test(e))return null;switch(e.length){case 7:return{R:parseInt(e.slice(1,3),16),G:parseInt(e.slice(3,5),16),B:parseInt(e.slice(5,7),16)};case 4:return{R:parseInt(e.slice(1,2).repeat(2),16),G:parseInt(e.slice(2,3).repeat(2),16),B:parseInt(e.slice(3,4).repeat(2),16)};case 9:return{R:parseInt(e.slice(1,3),16),G:parseInt(e.slice(3,5),16),B:parseInt(e.slice(5,7),16),A:Math.round(parseInt(e.slice(7,9),16)/255*100)/100};default:return{R:parseInt(e.slice(1,2).repeat(2),16),G:parseInt(e.slice(2,3).repeat(2),16),B:parseInt(e.slice(3,4).repeat(2),16),A:Math.round(parseInt(e.slice(4,5).repeat(2),16)/255*100)/100}}}function ye(e){const t=d(e);return t?t.A?`rgba(${t.R},${t.G},${t.B},${t.A})`:`rgb(${t.R},${t.G},${t.B})`:null}function ne(e){for(const[t,r]of $.entries())if(r===e)return t}function h(e){return $.get(e)}function v(e){const t=h(e);if(t)return d(t)||void 0}function _({R:e,G:t,B:r,A:n}){return`rgb(${e} ${t} ${r}${n?` / ${n}`:""})`}function oe(e){const{R:t,G:r,B:n}=e,o=C(t)*100,a=C(r)*100,s=C(n)*100;return{X:o*.4124+a*.3576+s*.1805,Y:o*.2126+a*.7152+s*.0722,Z:o*.0193+a*.1192+s*.9505}}function ae(e){const{X:t,Y:r,Z:n}=e,o=t/95.047,a=r/100,s=n/108.883,f=I(o),i=I(a),c=I(s);return{L:116*i-16,a:500*(f-i),b:200*(i-c)}}function q(e){return ae(oe(e))}function P(e){return ne(p(e))}var se=(e,t)=>te(q(e),q(t));function R(e,t){if(!t||t.length<2)return e;let r=e,n=Number.POSITIVE_INFINITY;for(const o of t){const a=se(e,o);a<n&&(n=a,r=o)}return r}function Me(e,t){if(!t||t.length<2)return e;let r,n;const o=[];if(x(e)?(r=d(e),n="hex"):L(e)?(r=l(e),n="cssRGB"):A(e)&&(r=v(e),n="namedCSS"),!r)return;for(const s of t)if(x(s)){const f=d(s);f&&o.push(f)}else if(L(s))o.push(l(s));else if(A(s)){const f=v(s);f&&o.push(f)}if(o.length<2)return e;const a=R(r,o);return n==="hex"?p(a):n==="cssRGB"?_(a):P(a)}function $e(e,t){return!t||t.length<2?e:_(R(l(e),t.map(r=>l(r))))}function Le(e,t){if(!t||t.length<2)return e;const r=d(e);return r?p(R(r,t.map(n=>d(n)).filter(n=>n!==null))):e}function xe(e,t){if(!t||t.length<2)return e;const r=v(e),n=t.map(o=>v(o)).filter(o=>o!==void 0);return!r||n.length<2?e:P(R(r,n))}function B({R:e,G:t,B:r},n){const o=n==="WCAG2.1",a=C(e,o),s=C(t,o),f=C(r,o);return .2126*a+.7152*s+.0722*f}function b(e,t){const r=d(e);return r?B(r,t):null}function fe(e,t){const r=Math.max(e,t),n=Math.min(e,t),o=(r+.05)/(n+.05);return Math.floor(o*1e3)/1e3}function E(e,t,r){const n=b(e,r),o=b(t,r);return n===null||o===null?null:fe(n,o)}function Ae(e,t,r){let n,o;if(e.startsWith("#"))n=e;else if(e.startsWith("rgb"))n=H(e);else{const s=h(e);if(s===void 0)throw new Error(`getContrastRatio expects valid CSS named colours. ${e} is not a valid CSS named colour. See ${G}`);n=s}if(t.startsWith("#"))o=t;else if(t.startsWith("rgb"))o=H(t);else{const s=h(t);if(s===void 0)throw new Error(`getContrastRatio expects valid CSS named colours. ${t} is not a valid CSS named colour. See ${G}`);o=s}const a=E(n,o,r);if(a===null)throw new Error(`getContrastRatio expects valid hexadecimal colours but received ${n} or ${o}.`);return a}function Ie(e,t,r){const n=l(e),o=l(t);return fe(B(n,r),B(o,r))}function Ne(e,t,r){const n=h(e),o=h(t);if(n===void 0||o===void 0)throw new Error(`getContrastRatioFromNamedCSSColour expects valid CSS named colours. ${e} or ${t} are not valid CSS named colours. See ${G}`);return E(n,o,r)}function W(e,t){const r=b(e,t);if(r===null)return!1;const n=r+.05;return 1.05/n>n/.05}function ie(e,t){const r=h(e);if(r)return W(r,t);throw new Error(`${e} is not a valid colour format. isCSSNamedDarkColour only accepts CSS named colours. See ${G}`)}function ce(e,t){const r=B(l(e),t);return 1.05/r>r/.05}function He(e,t){try{return e.startsWith("#")?W(e,t):e.startsWith("rgb")?ce(e,t):ie(e,t)}catch{throw new Error(`${e} is not a valid colour format. isDarkColour accepts CSS RGB formats, ie rgb(0,0,0), rgba(255, 255, 255, 0.4), rgb(50%, 25%, 100%), and rgba(50%, 25%, 100%, 80%), hexadecimal and CSS named colours.`)}}var ue=(e,t)=>e>t?e/t:t/e,_e=({backgroundColour:e,optionOneColour:t,optionTwoColour:r},n)=>{const o=b(e,n),a=b(t,n),s=b(r,n);if(o===null||a===null||s===null)return null;const f=o+.05,i=a+.05,c=s+.05;return ue(i,f)>ue(c,f)?t:r};function qe(e,t,r){const n=e/255,o=t/255,a=r/255,s=Math.max(n,o,a),f=Math.min(n,o,a);let i=0,c=0;const g=s,u=s-f;return s===0?c=0:c=u/s,u!==0&&(s===n?i=(o-a)/u%6:s===o?i=(a-n)/u+2:s===a&&(i=(n-o)/u+4),i=i*60,i<0&&(i=i+360)),{h:i,s:c,v:g}}function Pe(e){const t=d(e);if(!t)return null;const{R:r,G:n,B:o,A:a}=t,s=typeof a=="number"?a:1,{h:f,s:i,v:c}=qe(r,n,o);return{h:f,s:i,v:c,a:s}}function le(e){return e===0?1:e===1?2:0}function Ee(e){const t=new Map;for(const a of e)if(!t.has(a)){const s=Pe(a);s&&t.set(a,s)}const r=[],n=[],o=[];for(const a of e){const s=t.get(a);if(!s)continue;const{s:f,a:i}=s;i===0?o.push(a):f===0?n.push(a):r.push(a)}return r.sort((a,s)=>{const f=t.get(a),i=t.get(s);return f.h!==i.h?f.h-i.h:i.s-f.s}),n.sort((a,s)=>{const f=t.get(a),i=t.get(s),c=le(f.v),g=le(i.v);return c!==g?c-g:f.v-i.v}),o.sort((a,s)=>{const f=t.get(a),i=t.get(s);return f.v-i.v}),[...r,...n,...o]}export{se as RGBdistance,te as ciede2000,H as convertCSSRGBtoHex,l as convertCSSRGBtoRGB,ye as convertHextoCSSRGB,ne as convertHextoNamedCSSColour,d as convertHextoRGB,h as convertNamedCSSColourtoHex,v as convertNamedCSSColourtoRGB,_ as convertRGBtoCSSRGB,p as convertRGBtoHex,q as convertRGBtoLab,P as convertRGBtoNamedCSSColour,oe as convertRGBtoXYZ,ae as convertXYZtoLab,$e as findNearestCSSRGBColour,Me as findNearestColour,Le as findNearestHexColour,xe as findNearestNamedCSSColour,R as findNearestRGBColour,Ae as getContrastRatio,Ie as getContrastRatioFromCSSRGB,E as getContrastRatioFromHex,Ne as getContrastRatioFromNamedCSSColour,b as getSRGBLuminanceFromHex,B as getSRGBLuminanceFromRGB,ie as isCSSNamedDarkColour,L as isCSSRGBColour,ce as isCSSRGBDarkColour,He as isDarkColour,x as isHexColour,W as isHexDarkColour,A as isNamedCSSColour,_e as pickHexColourContrast,Ee as sortHexColours};
|