import{c as p}from"./color.e1b5fced.js";import{b as k}from"./balanced-match.d2a36341.js";import{b as $}from"./debug.f174a91e.js";var M={},g=k,s=$.exports("css-color-function:parse"),E=A;function A(e){typeof e!="string"&&(e=e.toString()),s("string %s",e);function f(n){var a=n.exec(e);if(!!a)return e=e.slice(a[0].length),a.slice(1)}function c(){f(/^\s+/)}function o(){var n=f(/^\)/);if(!!n)return s("rparen"),n}function h(){var n=f(/^([\+\-\*])/);if(!!n){var a={};return a.type="modifier",a.value=n[0],s("modifier %o",a),a}}function v(){var n=f(/^([^\)\s]+)/);if(!!n){var a={};return a.type="number",a.value=n[0],s("number %o",a),a}}function t(){for(var n=[],a;a=h()||u()||v();)n.push(a),c();return s("args %o",n),n}function r(){var n=f(/^(\w+)\(/);if(!!n){c();var a={};return a.type="function",a.name=n[0],a.arguments=t(),o(),s("adjuster %o",a),a}}function i(){var n={};n.type="color";var a=f(/([^\)\s]+)/)[0];if(a.indexOf("(")!=-1){var l=f(/([^\)]*?\))/)[0];a=a+l}return n.value=a,c(),n}function u(){if(!!e.match(/^color\(/)){var n=g("(",")",e);if(!n)throw new SyntaxError("Missing closing parenthese for '"+e+"'");if(n.body==="")throw new SyntaxError("color() function cannot be empty");e=n.body,c();var a={};a.type="function",a.name="color",a.arguments=[u()||i()],s("function arguments %o",a.arguments);for(var l;l=r();)a.arguments.push(l),c();return e=n.post,c(),s("function %o",a),a}}return u()}var S={};(function(e){var f=p;e.red=c("red"),e.blue=c("blue"),e.green=c("green"),e.alpha=e.a=c("alpha"),e.rgb=function(){},e.hue=e.h=o("hue"),e.saturation=e.s=o("saturation"),e.lightness=e.l=o("lightness"),e.whiteness=e.w=o("whiteness"),e.blackness=e.b=o("blackness"),e.blend=function(t,r){var i=t.alpha();t.alpha(1);var u=new f(r[0].value),n=1-parseInt(r[1].value,10)/100;t.mix(u,n).alpha(i)},e.tint=function(t,r){r.unshift({type:"argument",value:"white"}),e.blend(t,r)},e.shade=function(t,r){r.unshift({type:"argument",value:"black"}),e.blend(t,r)},e.contrast=function(t,r){r.length==0&&r.push({type:"argument",value:"100%"});var i=1-parseInt(r[0].value,10)/100,u=t.luminosity()<.5?new f({h:t.hue(),w:100,b:0}):new f({h:t.hue(),w:0,b:100}),n=u,a=4.5;if(t.contrast(u)>a){var n=v(a,t,u),l=n.alpha();n.alpha(1),n.mix(u,i).alpha(l)}t.hwb(n.hwb())};function c(t){return function(r,i){var u;i[0].type=="modifier"&&(u=i.shift().value);var n=i[0].value;n.indexOf("%")!=-1?(n=parseInt(n,10)/100,u?u!="*"&&(n=r[t]()*n):n=n*(t=="alpha"?1:255)):n=Number(n),r[t](h(r[t](),n,u))}}function o(t){return function(r,i){var u;i[0].type=="modifier"&&(u=i.shift().value);var n=parseFloat(i[0].value,10);r[t](h(r[t](),n,u))}}function h(t,r,i){switch(i){case"+":return t+r;case"-":return t-r;case"*":return t*r;default:return r}}function v(t,r,i){r.hue();for(var u=r.clone(),n=r.whiteness(),a=r.blackness(),l=i.whiteness(),m=i.blackness();Math.abs(n-l)>1||Math.abs(a-m)>1;){var b=Math.round((l+n)/2),w=Math.round((m+a)/2);u.whiteness(b),u.blackness(w),u.contrast(r)>t?(l=b,m=w):(n=b,a=w)}return u}})(S);var C=k,I=p,O=E,y=S,R=j;function j(e){var f=e.indexOf("color(");if(f==-1)return e;if(e=e.slice(f),e=C("(",")",e),!e)throw new SyntaxError("Missing closing parenthese for '"+e+"'");var c=O("color("+e.body+")");return d(c)+j(e.post)}function d(e){var f=new I(e.arguments[0].type=="function"?d(e.arguments[0]):e.arguments[0].value),c=e.arguments.slice(1);return c.forEach(function(o){var h=o.name;if(!y[h])throw new Error("Unknown <color-adjuster> '"+h+"'");o.arguments.forEach(function(v){v.type=="function"&&v.name=="color"&&(v.value=d(v),v.type="color",delete v.name)}),y[h](f,o.arguments)}),f.rgbString()}var B=R,_=E;M.convert=B;M.parse=_;export{M as l};
