@olton/farbe
Version:
Color Manipulation library
10 lines (7 loc) • 19.7 kB
JavaScript
/*!
* Farbe v1.0.9. Color Routines for JavaScript.
* Build: 18.05.2025, 14:44:28
* Copyright 2025 by Serhii Pimenov
* Licensed under MIT
*/
var Le=Object.defineProperty;var $e=(e,t)=>{for(var s in t)Le(e,s,{get:t[s],enumerable:!0})};var xe={};$e(xe,{Primitives:()=>ue,add:()=>we,brighten:()=>_e,cmyk2rgb:()=>de,cmyk2websafe:()=>He,colorDefaultProps:()=>X,colorToString:()=>he,colorType:()=>S,colorTypes:()=>c,create:()=>Ee,createColor:()=>Me,createColorScheme:()=>ke,darken:()=>pe,desaturate:()=>ve,equal:()=>fe,expand:()=>Ne,expandHexColor:()=>j,grayscale:()=>ce,hex2hsv:()=>Ye,hex2rgb:()=>ee,hex2websafe:()=>Ce,hsl2hsv:()=>ie,hsl2websafe:()=>Ge,hsv2hex:()=>Oe,hsv2hsl:()=>se,hsv2rgb:()=>L,hsv2websafe:()=>Be,hueShift:()=>be,isCMYK:()=>T,isColor:()=>m,isDark:()=>Z,isHEX:()=>Q,isHSL:()=>W,isHSLA:()=>N,isHSV:()=>q,isLight:()=>oe,isPrimitive:()=>Ae,isRGB:()=>U,isRGBA:()=>V,lighten:()=>E,mix:()=>g,multiply:()=>re,parse:()=>J,parseColor:()=>k,random:()=>qe,randomColor:()=>ae,rgb2cmyk:()=>le,rgb2hex:()=>te,rgb2hsv:()=>y,rgb2websafe:()=>K,rgba2websafe:()=>Se,saturate:()=>Y,shade:()=>ge,spin:()=>me,test:()=>ye,toCMYK:()=>D,toColor:()=>w,toHEX:()=>M,toHSL:()=>P,toHSLA:()=>I,toHSV:()=>F,toRGB:()=>p,toRGBA:()=>$,websafe:()=>ne});var d=class{constructor(t=0,s=0,n=0){this.h=t,this.s=s,this.v=n}toString(){return"hsv("+[Math.round(this.h),Math.round(this.s*100)+"%",Math.round(this.v*100)+"%"].join(",")+")"}};var B=class{constructor(t=0,s=0,n=0){this.h=t,this.s=(""+s).includes("%")?parseInt(s)/100:s,this.l=(""+n).includes("%")?parseInt(n)/100:n}toString(){return"hsl("+[Math.round(this.h),Math.round(this.s*100)+"%",Math.round(this.l*100)+"%"].join(",")+")"}};var G=class{constructor(t=0,s=0,n=0,r=0){this.h=t,this.s=(""+s).includes("%")?parseInt(s)/100:s,this.l=(""+n).includes("%")?parseInt(n)/100:n,this.a=r}toString(){return"hsla("+[Math.round(this.h),Math.round(this.s*100)+"%",Math.round(this.l*100)+"%",parseFloat(this.a).toFixed(2)].join(",")+")"}};var b=class{constructor(t=0,s=0,n=0){this.r=t,this.g=s,this.b=n}toString(){return`rgb(${this.r},${this.g},${this.b})`}};var R=class{constructor(t=0,s=0,n=0,r=0){this.r=t,this.g=s,this.b=n,this.a=r}toString(){return`rgba(${this.r},${this.g},${this.b},${this.a})`}};var H=class{constructor(t=0,s=0,n=0,r=0){this.c=t,this.m=s,this.y=n,this.k=r}toString(){return`cmyk(${this.c},${this.m},${this.y},${this.k})`}};var O={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",darkKhaki:"#bdb76b",darkMagenta:"#8b008b",darkOliveGreen:"#556b2f",darkOrange:"#ff8c00",darkOrchid:"#9932cc",darkRed:"#8b0000",darkSalmon:"#e9967a",darkSeaGreen:"#8fbc8f",darkSlateBlue:"#483d8b",darkSlateGray:"#2f4f4f",darkTurquoise:"#00ced1",darkViolet:"#9400d3",deepPink:"#ff1493",deepSkyBlue:"#00bfff",dimGray:"#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",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",lightPink:"#ffb6c1",lightSalmon:"#ffa07a",lightSeaGreen:"#20b2aa",lightSkyBlue:"#87cefa",lightSlateGray:"#778899",lightSteelBlue:"#b0c4de",lightYellow:"#ffffe0",lime:"#00ff00",limeGreen:"#32dc32",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:"#fdd5e6",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",slyBlue:"#87ceeb",slateBlue:"#6a5acd",slateGray:"#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"},z={lime:"#a4c400",green:"#60a917",emerald:"#008a00",blue:"#00AFF0",teal:"#00aba9",cyan:"#1ba1e2",cobalt:"#0050ef",indigo:"#6a00ff",violet:"#aa00ff",pink:"#dc4fad",magenta:"#d80073",crimson:"#a20025",red:"#CE352C",orange:"#fa6800",amber:"#f0a30a",yellow:"#fff000",brown:"#825a2c",olive:"#6d8764",steel:"#647687",mauve:"#76608a",taupe:"#87794e"},Ve={color:function(e,t=O,s=void 0){return t[e]!==void 0?t[e]:s},palette:function(e=O){return Object.keys(e)},colors:function(e=O){return Object.values(e)}};var ue={HSV:d,HSL:B,HSLA:G,RGB:b,RGBA:R,CMYK:H},c={HEX:"hex",RGB:"rgb",RGBA:"rgba",HSV:"hsv",HSL:"hsl",HSLA:"hsla",CMYK:"cmyk",UNKNOWN:"unknown"},X={angle:30,algorithm:1,step:.1,distance:5,tint1:.8,tint2:.4,shade1:.6,shade2:.3,alpha:1,baseLight:"#ffffff",baseDark:"self"};function Pe(e,t){let s;switch(t){case"hex":s=e.map(function(n){return M(n)});break;case"rgb":s=e.map(function(n){return p(n)});break;case"rgba":s=e.map(function(n){return $(n,opt.alpha)});break;case"hsl":s=e.map(function(n){return P(n)});break;case"hsla":s=e.map(function(n){return I(n,opt.alpha)});break;case"cmyk":s=e.map(function(n){return D(n)});break;default:s=e}return s}function A(e,t,s){return Math.max(t,Math.min(e,s))}function _(e,t,s){return e<t?t:e>s?s:e}function v(e,t){for(e+=t;e>=360;)e-=360;for(;e<0;)e+=360;return e}var ye=e=>{let t=a=>/^#([A-Fa-f0-9]{3}){1,2}$/.test(a),s=a=>/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/.test(a),n=a=>/^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*(0(\.\d+)?|1(\.0+)?)\s*\)$/.test(a),r=a=>/^hsv\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/.test(a),u=a=>/^hsl\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/.test(a),i=a=>/^hsla\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*(0(\.\d+)?|1(\.0+)?)\s*\)$/.test(a),o=a=>/^cmyk\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/.test(a);return t(e)||s(e)||r(e)||i(e)||i(e)||n(e)||u(e)||o(e)},Me=(e="hex",t="#000000")=>{let s;return typeof t=="string"&&(s=k(t)),m(s)||(s="#000000"),w(s,e.toLowerCase())},Ee=Me,j=function(e){if(m(e)&&typeof e!="string")return e;if(typeof e!="string")throw new Error("Value is not a string!");if(e[0]==="#"&&e.length===4){let t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;return"#"+e.replace(t,(s,n,r,u)=>n+n+r+r+u+u)}return e[0]==="#"?e:"#"+e},Ne=j,Z=e=>{if(e=k(e),!m(e))return;let t=p(e);return(t.r*299+t.g*587+t.b*114)/1e3<128},oe=e=>!Z(e),q=e=>k(e)instanceof d,W=e=>k(e)instanceof B,N=e=>k(e)instanceof G,U=e=>k(e)instanceof b,V=e=>k(e)instanceof R,T=e=>k(e)instanceof H,Q=e=>/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e),m=e=>e?typeof e=="string"?ye(e):Q(e)||U(e)||V(e)||q(e)||W(e)||N(e)||T(e):!1,S=e=>Q(e)?c.HEX:U(e)?c.RGB:V(e)?c.RGBA:q(e)?c.HSV:W(e)?c.HSL:N(e)?c.HSLA:T(e)?c.CMYK:c.UNKNOWN,fe=(e,t)=>!m(e)||!m(t)?!1:M(e)===M(t),he=e=>e.toString(),ee=e=>{let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(j(e)),s=[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)];return t?new b(...s):null},te=e=>"#"+((1<<24)+(e.r<<16)+(e.g<<8)+e.b).toString(16).slice(1),y=e=>{let t=new d,s,n,r,u=e.r/255,i=e.g/255,o=e.b/255,a=Math.max(u,i,o),f=Math.min(u,i,o),l=a-f;return r=a,a===0?n=0:n=1-f/a,a===f?s=0:a===u&&i>=o?s=60*((i-o)/l):a===u&&i<o?s=60*((i-o)/l)+360:a===i?s=60*((o-u)/l)+120:a===o?s=60*((u-i)/l)+240:s=0,t.h=s,t.s=n,t.v=r,t},L=e=>{let t,s,n,r=e.h,u=e.s*100,i=e.v*100,o=Math.floor(r/60),a=(100-u)*i/100,f=(i-a)*(r%60/60),l=a+f,h=i-f;switch(o){case 0:t=i,s=l,n=a;break;case 1:t=h,s=i,n=a;break;case 2:t=a,s=i,n=l;break;case 3:t=a,s=h,n=i;break;case 4:t=l,s=a,n=i;break;case 5:t=i,s=a,n=h;break}return new b(Math.round(t*255/100),Math.round(s*255/100),Math.round(n*255/100))},Oe=e=>te(L(e)),Ye=e=>y(ee(e)),le=e=>{let t=new H,s=e.r/255,n=e.g/255,r=e.b/255;return t.k=Math.min(1-s,1-n,1-r),t.c=1-t.k===0?0:(1-s-t.k)/(1-t.k),t.m=1-t.k===0?0:(1-n-t.k)/(1-t.k),t.y=1-t.k===0?0:(1-r-t.k)/(1-t.k),t.c=Math.round(t.c*100),t.m=Math.round(t.m*100),t.y=Math.round(t.y*100),t.k=Math.round(t.k*100),t},de=e=>{let t=Math.floor(255*(1-e.c/100)*(1-e.k/100)),s=Math.ceil(255*(1-e.m/100)*(1-e.k/100)),n=Math.ceil(255*(1-e.y/100)*(1-e.k/100));return new b(t,s,n)},se=e=>{let t,s,n,r;return t=parseInt(e.h),n=(2-e.s)*e.v,s=e.s*e.v,n===0?s=0:(r=n<=1?n:2-n,r===0?s=0:s/=r),n/=2,Number.isNaN(s)&&(s=0),Number.isNaN(n)&&(n=0),new B(t,s,n)},ie=e=>{let t,s,n,r;return t=e.h,r=e.l*2,s=e.s*(r<=1?r:2-r),n=(r+s)/2,r+s===0?s=0:s=2*s/(r+s),new d(t,s,n)},K=e=>new b(Math.round(e.r/51)*51,Math.round(e.g/51)*51,Math.round(e.b/51)*51),Se=e=>{let t=K(e);return new R(t.r,t.g,t.b,e.a)},Ce=e=>te(K(ee(e))),Be=e=>y(K(p(e))),Ge=e=>se(y(K(p(e)))),He=e=>le(K(de(e))),ne=e=>Q(e)?Ce(e):U(e)?K(e):V(e)?Se(e):q(e)?Be(e):W(e)?Ge(e):T(e)?He(e):e,w=(e,t="rgb",s=1)=>{let n;switch(t.toLowerCase()){case"hex":n=M(e);break;case"rgb":n=p(e);break;case"rgba":n=$(e,s);break;case"hsl":n=P(e);break;case"hsla":n=I(e,s);break;case"hsv":n=F(e);break;case"cmyk":n=D(e);break;default:n=e}return n},M=e=>typeof e=="string"&&e[0]==="#"?j(e):te(p(J(e))),p=e=>{if(U(e))return e;if(V(e))return new b(e.r,e.g,e.b);if(q(e))return L(e);if(W(e)||N(e))return L(ie(e));if(Q(e))return ee(e);if(T(e))return de(e);throw new Error("Unknown color format!")},$=(e,t)=>{if(V(e))return typeof t<"u"&&(e.a=t),e;let s=p(e);return new R(s.r,s.g,s.b,typeof e.a<"u"?e.a:t)},F=e=>q(e)?e:y(p(e)),P=e=>W(e)?e:se(y(p(e))),I=(e,t=1)=>{if(N(e))return t&&(e.a=t),e;let s=se(y(p(e)));return s.a=typeof e.a<"u"?e.a:t,new G(s.h,s.s,s.l,s.a)},D=e=>T(e)?e:le(p(e)),ce=e=>{let t=p(e),s=S(e).toLowerCase(),n=Math.round(t.r*.2125+t.g*.7154+t.b*.0721),r=new b(n,n,n);return w(r,s)},pe=(e,t=10)=>E(e,-1*Math.abs(t)),E=(e,t=10)=>{let s,n,r=1,u=t>0,i=function(o,a){let f,l,h,C=o.slice(1),x=parseInt(C,16);return f=(x>>16)+a,f>255?f=255:f<0&&(f=0),h=(x>>8&255)+a,h>255?h=255:h<0&&(h=0),l=(x&255)+a,l>255?l=255:l<0&&(l=0),"#"+(l|h<<8|f<<16).toString(16)};s=S(e).toLowerCase(),s===c.RGBA&&(r=e.a);do n=i(M(e),t),u?t--:t++;while(n.length<7);return w(n,s)},be=(e,t,s=1)=>{let n=F(e),r=S(e).toLowerCase(),u=n.h;for(u+=t;u>=360;)u-=360;for(;u<0;)u+=360;return n.h=u,w(n,r,s)},g=(e,t,s)=>{s=s===0?0:s||50;let n=new b(0,0,0),r=p(e),u=p(t),i=s/100;return n.r=Math.round((u.r-r.r)*i+r.r),n.g=Math.round((u.g-r.g)*i+r.g),n.b=Math.round((u.b-r.b)*i+r.b),M(n)},re=(e,t)=>{let s=p(e),n=p(t),r=new b;return s.b=Math.floor(s.b*n.b/255),s.g=Math.floor(s.g*n.g/255),s.r=Math.floor(s.r*n.r/255),M(r)},ge=(e,t)=>{if(!m(e))throw new Error(e+" is not a valid color value!");t/=100;let s=S(e).toLowerCase(),n=p(e),r=t<0?0:255,u=t<0?t*-1:t,i,o,a,f;return i=Math.round((r-n.r)*u)+n.r,o=Math.round((r-n.g)*u)+n.g,a=Math.round((r-n.b)*u)+n.b,(s===c.RGBA||s===c.HSLA)&&(f=e.a),w(new b(i,o,a),s,f)},Y=(e,t)=>{let s,n,r;if(!m(e))throw new Error(e+" is not a valid color value!");return s=P(e),s.s+=t/100,s.s=A(0,1,s.s),n=S(e).toLowerCase(),(n===c.RGBA||n===c.HSLA)&&(r=e.a),w(s,n,r)},ve=(e,t)=>{let s,n,r;if(!m(e))throw new Error(e+" is not a valid color value!");return s=P(e),s.s-=t<1?t:t/100,s.s=A(s.s,0,1),n=S(e).toLowerCase(),(n===c.RGBA||n===c.HSLA)&&(r=e.a),w(s,n,r)},me=(e,t)=>{let s,n,r,u;if(!m(e))throw new Error(e+" is not a valid color value!");return s=P(e),u=s.h+t,u>360?u=u%360:u<0&&(u=360+u%360),s.h=u,n=S(e).toLowerCase(),(n===c.RGBA||n===c.HSLA)&&(r=e.a),n==="hsl"?s:w(s,n,r)},_e=(e,t)=>{let s,n,r;if(!m(e))throw new Error(e+" is not a valid color value!");return s=p(e),s.r=Math.max(0,Math.min(255,s.r-Math.round(255*-(t/100)))),s.g=Math.max(0,Math.min(255,s.g-Math.round(255*-(t/100)))),s.b=Math.max(0,Math.min(255,s.b-Math.round(255*-(t/100)))),n=S(e).toLowerCase(),(n===c.RGBA||n===c.HSLA)&&(r=e.a),w(s,n,r)},we=(e,t,s)=>{let n=J(e),r=J(t),u=$(n,void 0),i=$(r,void 0),o=new R,a=(""+s).toLowerCase()||"hex";return o.r=Math.round((u.r+i.r)/2),o.g=Math.round((u.g+i.g)/2),o.b=Math.round((u.b+i.b)/2),o.a=Math.round((u.a+i.a)/2),w(o,s,o.a)},ke=(e,t,s=c.HEX,n)=>{let r=Object.assign({},X,n),u,i=[],o,a,f,l,h;if(o=F(e),q(o)===!1)return console.warn("The value is a not supported color format!"),!1;switch(f=o.h,l=o.s,h=o.v,t){case"monochromatic":case"mono":{if(r.algorithm===1)a=L(o),a.r=_(Math.round(a.r+(255-a.r)*r.tint1),0,255),a.g=_(Math.round(a.g+(255-a.g)*r.tint1),0,255),a.b=_(Math.round(a.b+(255-a.b)*r.tint1),0,255),i.push(y(a)),a=L(o),a.r=_(Math.round(a.r+(255-a.r)*r.tint2),0,255),a.g=_(Math.round(a.g+(255-a.g)*r.tint2),0,255),a.b=_(Math.round(a.b+(255-a.b)*r.tint2),0,255),i.push(y(a)),i.push(o),a=L(o),a.r=_(Math.round(a.r*r.shade1),0,255),a.g=_(Math.round(a.g*r.shade1),0,255),a.b=_(Math.round(a.b*r.shade1),0,255),i.push(y(a)),a=L(o),a.r=_(Math.round(a.r*r.shade2),0,255),a.g=_(Math.round(a.g*r.shade2),0,255),a.b=_(Math.round(a.b*r.shade2),0,255),i.push(y(a));else if(r.algorithm===2)for(i.push(o),u=1;u<=r.distance;u++)h=A(h-r.step,0,1),l=A(l-r.step,0,1),i.push({h:f,s:l,v:h});else if(r.algorithm===3)for(i.push(o),u=1;u<=r.distance;u++)h=A(h-r.step,0,1),i.push({h:f,s:l,v:h});else h=A(o.v+r.step*2,0,1),i.push({h:f,s:l,v:h}),h=A(o.v+r.step,0,1),i.push({h:f,s:l,v:h}),i.push(o),l=o.s,h=o.v,h=A(o.v-r.step,0,1),i.push({h:f,s:l,v:h}),h=A(o.v-r.step*2,0,1),i.push({h:f,s:l,v:h});break}case"complementary":case"complement":case"comp":{i.push(o),f=v(o.h,180),i.push(new d(f,l,h));break}case"double-complementary":case"double-complement":case"double":{i.push(o),f=v(f,180),i.push(new d(f,l,h)),f=v(f,r.angle),i.push(new d(f,l,h)),f=v(f,180),i.push(new d(f,l,h));break}case"analogous":case"analog":{f=v(f,r.angle),i.push(new d(f,l,h)),i.push(o),f=v(o.h,0-r.angle),i.push(new d(f,l,h));break}case"triadic":case"triad":{for(i.push(o),u=1;u<3;u++)f=v(f,120),i.push(new d(f,l,h));break}case"tetradic":case"tetra":{i.push(o),f=v(o.h,180),i.push(new d(f,l,h)),f=v(o.h,-1*r.angle),i.push(new d(f,l,h)),f=v(f,180),i.push(new d(f,l,h));break}case"square":{for(i.push(o),u=1;u<4;u++)f=v(f,90),i.push(new d(f,l,h));break}case"split-complementary":case"split-complement":case"split":{f=v(f,180-r.angle),i.push(new d(f,l,h)),i.push(o),f=v(o.h,180+r.angle),i.push(new d(f,l,h));break}case"material":{var C=r.baseLight,x=r.baseDark==="self"||!r.baseDark?re(e,e):r.baseDark;i.push({50:g(C,e,10),100:g(C,e,30),200:g(C,e,50),300:g(C,e,70),400:g(C,e,85),500:g(C,e,100),600:g(x,e,92),700:g(x,e,83),800:g(x,e,74),900:g(x,e,65),A100:E(Y(g(x,e,15),80),65),A200:E(Y(g(x,e,15),80),55),A400:E(Y(g(C,e,100),55),10),A700:E(Y(g(x,e,83),65),10)});break}default:console.error("Unknown schema name")}return t==="material"?i[0]:Pe(i,s)},Ae=e=>e instanceof d||e instanceof B||e instanceof G||e instanceof b||e instanceof R||e instanceof H,k=function(e){if(Ae(e))return e;let t=(""+e).toLowerCase();typeof O[t]<"u"&&(t=O[t]),typeof z[t]<"u"&&(t=z[t]);let s=t.replace(/[^\d.,%]/g,"").split(",").map(n=>isNaN(n)?n:+n);return t[0]==="#"?j(t):t.includes("rgba")?new R(s[0],s[1],s[2],s[3]):t.includes("rgb")?new b(s[0],s[1],s[2]):t.includes("cmyk")?new H(s[0],s[1],s[2],s[3]):t.includes("hsv")?new d(s[0],s[1],s[2]):t.includes("hsla")?new G(s[0],s[1],s[2],s[3]):t.includes("hsl")?new B(s[0],s[1],s[2]):t},J=k,ae=(e="hex",t=1)=>{let s=(o,a)=>Math.floor(o+Math.random()*(a+1-o)),n,r,u,i;return r=s(0,255),u=s(0,255),i=s(0,255),n="#"+((1<<24)+(r<<16)+(u<<8)+i).toString(16).slice(1),e==="hex"?n:w(n,e,t)},qe=ae;var Re=class{_setValue(t){t||(t="#000000"),typeof t=="string"&&(t=k(t)),t&&m(t)?this._value=t:this._value=void 0}_setOptions(t){this._options=Object.assign({},X,t)}constructor(t="#000000",s=null){this._setValue(t),this._setOptions(s)}get options(){return this._options}set options(t){this._setOptions(t)}get value(){return this._value?this._value:void 0}set value(t){this._setValue(t)}toRGB(){if(this._value)return this._value=p(this._value),this}get rgb(){return this._value?p(this._value):void 0}toRGBA(t){if(this._value)return V(this._value)?t&&(this._value=$(this._value,t)):this._value=$(this._value,t||X.alpha),this}get rgba(){return this._value?V(this._value)?this._value:$(this._value,this._options.alpha):void 0}toHEX(){if(this._value)return this._value=M(this._value),this}get hex(){return this._value?M(this._value):void 0}toHSV(){if(this._value)return this._value=F(this._value),this}get hsv(){return this._value?F(this._value):void 0}toHSL(){if(this._value)return this._value=P(this._value),this}get hsl(){return this._value?P(this._value):void 0}toHSLA(t){if(this._value)return N(this._value)?t&&(this._value=I(this._value,t)):this._value=I(this._value,t),this}get hsla(){return this._value?N(this._value)?this._value:I(this._value,this._options.alpha):void 0}toCMYK(){if(this._value)return this._value=D(this._value),this}get cmyk(){return this._value?D(this._value):void 0}toWebsafe(){if(this._value)return this._value=ne(this._value),this}get websafe(){return this._value?ne(this._value):void 0}toString(){return this._value?he(this._value):void 0}darken(t=10){if(this._value)return this._value=pe(this._value,t),this}lighten(t=10){if(this._value)return this._value=E(this._value,t),this}isDark(){return this._value?Z(this._value):void 0}isLight(){return this._value?oe(this._value):void 0}hueShift(t){if(this._value)return this._value=be(this._value,t),this}grayscale(){if(!(!this._value||this.type===c.UNKNOWN))return this._value=ce(this._value,(""+this.type).toLowerCase()),this}get type(){return S(this._value)}getScheme(t,s,n){return this._value?ke(this._value,t,s,n):void 0}equal(t){return fe(this._value,t)}random(t,s){this._value=ae(t,s)}channel(t,s){let n=`${this.type}`.toUpperCase();if(["red","green","blue"].includes(t)){this.toRGB();let r={red:"r",green:"g",blue:"b"};this._value[r[t]]=s,this[`to${n}`]()}if(t==="alpha"&&this._value.a&&(this._value.a=s),["hue","saturation","value"].includes(t)){this.toHSV();let r={hue:"h",saturation:"s",value:"v"};this._value[r[t]]=s,this[`to${n}`]()}if(["lightness"].includes(t)&&(this.toHSL(),this._value.l=s,this[`to${n}`]()),["cyan","magenta","yellow","black"].includes(t)){this.toCMYK();let r={cyan:"c",magenta:"m",yellow:"y",black:"k"};this._value[r[t]]=s,this[`to${n}`]()}return this}add(t){this._setValue(we(this._value,t))}mix(t,s){this._setValue(g(this._value,t,s))}multiply(t){this._setValue(re(this._value,t))}shade(t){this._setValue(ge(this._value,t))}saturate(t){this._setValue(Y(this._value,t))}desaturate(t){this._setValue(ve(this._value,t))}spin(t){this._setValue(me(this._value,t))}brighten(t){this._setValue(_e(this._value,t))}};var ut={...ue},Ke="1.0.4",Fe="11.08.2024, 23:47:03",ot=()=>{console.info(`%c Farbe %c v${Ke} %c ${Fe} `,"color: #ffffff; font-weight: bold; background: #ff00ff","color: white; background: darkgreen","color: white; background: #0080fe;")};export{Re as Farbe,z as MetroColorPalette,Ve as Palette,ut as Primitives,xe as Routines,O as StandardColorPalette,ot as info};