(function(p,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):u((p=typeof globalThis<"u"?globalThis:p||self)["@ergofriend/random-pair-colors"]={})})(this,function(p){"use strict";const u=(a=0,d=255)=>Math.floor(Math.random()*(d-a+1)+a),w=()=>`#${[u(),u(),u()].map(a=>a.toString(16).padStart(2,"0")).join("")}`;/** @preserve ///// CoLoR PaRsLeY a simple set of color parsing thingies! ///// Beta 0.1.8 Revision date: June 04, 2022 ///// ///// Functions to parse color values and return array ///// Copyright (c) 2019-2022 by Andrew Somers. All Rights Reserved. ///// LICENSE: AGPL 3 ///// CONTACT: Please use the ISSUES or DISCUSSIONS tab at: ///// https://github.com/Myndex/colorparsley/ ///// /////////////////////////////////////////////////////////////////////////////// ///// ///// IMPORT: ///// import { colorParsley } from 'colorparsley'; ///// ///// let rgbaArray = colorParsley('#abcdef'); ///// ///// Output as array: [r,g,b,a,isValid,colorspace] ///// Example: [123,123,123,1.0,true,'sRGB'] // */function M(a){if(typeof a=="string")return function(d="#abcdef"){d=(d=d.replace(/[^\w,.#%()\/ -]/g,"")).toLowerCase();let s=!1,r=[0,0,0,0,s,"sRGB"];if(d.match(/^(?:(?!rgb|l.h|hs|col|\d|#).{0,4})(?=[g-z])/)){let e={gray0:"000000",gray1:"111111",gray2:"222222",gray3:"333333",gray4:"444444",gray5:"555555",gray6:"666666",gray7:"777777",gray8:"888888",gray9:"999999",graya:"aaaaaa",grayb:"bbbbbb",grayc:"cccccc",grayd:"dddddd",graye:"eeeeee",grayf:"ffffff",midgray:"a0a0a0",grey0:"000000",grey1:"111111",grey2:"222222",grey3:"333333",grey4:"444444",grey5:"555555",grey6:"666666",grey7:"777777",grey8:"888888",grey9:"999999",greya:"aaaaaa",greyb:"bbbbbb",greyc:"cccccc",greyd:"dddddd",greye:"eeeeee",greyf:"ffffff",midgrey:"a0a0a0",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",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"ffffff",whitesmoke:"f5f5f5",yellow:"ffff00",yellowgreen:"9acd32"};for(let f in e)if(d==f){let c={rex:/^([\da-f]{2})([\da-f]{2})([\da-f]{2})$/,sprig:function(n){for(let l=0;l<3;l++)r[l]=parseInt(n[l+1],16);return r[3]=1,!0}},i=c.rex.exec(e[f]);return r[4]=s=c.sprig(i),r}}let m={rex:/(?:^(?:#|0x|)(?:(?:([\da-f])([\da-f])([\da-f])([\da-f])?)(?!\S)|(?:([\da-f]{2})(?:([\da-f]{2})([\da-f]{2})([\da-f]{2})?)?))|(?:(?:^(?:rgba?|)\(? ?(?:(?:(?:(255|(?:25[0-4]|2[0-4]\d|1?\d{1,2})(?:\.\d{1,24})?)))(?:,[^\S]*$|(?:(?:, ?| )(255|(?:25[0-4]|2[0-4]\d|1?\d{1,2})(?:\.\d{1,24})?)(?:, ?| )(255|(?:25[0-4]|2[0-4]\d|1?\d{1,2})(?:\.\d{1,24})?)))|(100%|\d{1,2}(?:\.\d{1,24})?%)(?:,?[^\S]*$|(?:(?:, ?| )(?:(100%|\d{1,2}(?:\.\d{1,24})?%)(?:, ?| )(100%|\d{1,2}(?:\.\d{1,24})?%)))))|^(?:color\((srgb|srgb-linear|display-p3|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65) (?:(100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])) (?:(100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])) (?:(100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])))|^(?:((?:r(?!gb)|c(?!olor)|[abd-qs-z])[a-z]{2,5})\( ?((?:\d{0,3}\.|)\d{1,24}%?)(?:, ?| )((?:\d{0,3}\.|)\d{1,24}%?)(?:, ?| )((?:\d{0,3}\.|)\d{1,24}%?))))(?:(?:,| \/| ) ?(?:(100%|\d{1,2}(?:\.\d{1,24})?%|[0 ]\.\d{1,24}|[01])))?(?:\)| |))[^\S]*$/,parsley:function(e){let f=0,c=0,i=10,n=100,l=2.55,h="1";e[23]&&(h=e[23],delete e[23]),r[3]=h.match(/%/g)?parseFloat(h)/n:parseFloat(h);for(let o=1;o=1){r[0]=r[1]=r[2]=b/(b+x),r[5]="sRGB";break}o=1,y=.5,k=1-b-x}r[0]=Math.round(255*(v(0)*k+b)),r[1]=Math.round(255*(v(8)*k+b)),r[2]=Math.round(255*(v(4)*k+b)),r[5]="sRGB"}}return!0}},g=m.rex.exec(d);return g?(r[4]=s=m.parsley(g),r):(s=!1,console.log("colorParsley error: unable to parse string"),[0,0,0,0,s,"parsleyError"])}(a);if(typeof a=="number")return[(16711680&a)>>16,(65280&a)>>8,255&a,1,!0,"unknown"];if(typeof a=="object"){if(Array.isArray(a))return a;if(!isNaN(a.r)||!isNaN(a.red)){let d=[0,0,0,0,!1,"unknown"];return d[0]=a.r?a.r:!!a.red&&a.red,d[1]=a.g?a.g:!!a.green&&a.green,d[2]=a.b?a.b:!!a.blue&&a.blue,d[3]=a.a?a.a:a.alpha?a.alpha:1,d[4]=!!(d[0]&&d[1]&&d[2]),d[5]=a.space?a.space:a.colorSpace?a.colorSpace:a.colorspace?a.colorspace:"unknown",d}}return console.log("colorParsley error: invalid input"),[0,0,0,0,!1,"inputError"]}const t={mainTRC:2.4,get mainTRCencode(){return 1/this.mainTRC},sRco:.2126729,sGco:.7151522,sBco:.072175,normBG:.56,normTXT:.57,revTXT:.62,revBG:.65,blkThrs:.022,blkClmp:1.414,scaleBoW:1.14,scaleWoB:1.14,loBoWoffset:.027,loWoBoffset:.027,deltaYmin:5e-4,loClip:.1,mFactor:1.9468554433171,get mFactInv(){return 1/this.mFactor},mOffsetIn:.0387393816571401,mExpAdj:.283343396420869,get mExp(){return this.mExpAdj/this.blkClmp},mOffsetOut:.312865795870758};function R(a,d,s=-1,r=!0){let m=M(d),g=M(a);return g[3]!=""&&g[3]!=1&&(g=function(e=[0,0,0,1],f=[0,0,0],c=!0){e[3]=Math.max(Math.min(e[3],1),0);let i=1-e[3],n=[0,0,0,1,!0];for(let l=0;l<3;l++)n[l]=f[l]*i+e[l]*e[3],c&&(n[l]=Math.min(Math.round(n[l]),255));return n}(g,m,r)),function(e,f,c=-1){const i=[0,1.1];if(isNaN(e)||isNaN(f)||Math.min(e,f)i[1])return 0;let n=0,l=0,h="BoW";return e=e>t.blkThrs?e:e+Math.pow(t.blkThrs-e,t.blkClmp),f=f>t.blkThrs?f:f+Math.pow(t.blkThrs-f,t.blkClmp),Math.abs(f-e)e?(n=(Math.pow(f,t.normBG)-Math.pow(e,t.normTXT))*t.scaleBoW,l=n-t.loClip?0:n+t.loWoBoffset),c<0?100*l:c==0?Math.round(100*Math.abs(l))+""+h+"":Number.isInteger(c)?(100*l).toFixed(c):0)}(T(g),T(m),s)}function T(a=[0,0,0]){function d(s){return Math.pow(s/255,t.mainTRC)}return t.sRco*d(a[0])+t.sGco*d(a[1])+t.sBco*d(a[2])}const B=({textColor:a,backgroundColor:d},s=45)=>s<=Math.abs(R(M(a),M(d)));p.generateRandomPairColor=a=>{const d={textColor:(a==null?void 0:a.textColor)||w(),backgroundColor:(a==null?void 0:a.backgroundColor)||w()};for(;!B(d,a==null?void 0:a.threshold);)a!=null&&a.textColor||(d.textColor=w()),a!=null&&a.backgroundColor||(d.backgroundColor=w());return d},p.isValidRandomPairColor=B,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});