"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./conversion.js"),p=require("./css-color-names.js"),i=require("./util.js");function I(a){var r={r:0,g:0,b:0},e=1,h=null,v=null,b=null,x=!1,g=!1;return typeof a=="string"&&(a=F(a)),typeof a=="object"&&(s(a.r)&&s(a.g)&&s(a.b)?(r=t.rgbToRgb(a.r,a.g,a.b),x=!0,g=String(a.r).substr(-1)==="%"?"prgb":"rgb"):s(a.h)&&s(a.s)&&s(a.v)?(h=i.convertToPercentage(a.s),v=i.convertToPercentage(a.v),r=t.hsvToRgb(a.h,h,v),x=!0,g="hsv"):s(a.h)&&s(a.s)&&s(a.l)&&(h=i.convertToPercentage(a.s),b=i.convertToPercentage(a.l),r=t.hslToRgb(a.h,h,b),x=!0,g="hsl"),Object.prototype.hasOwnProperty.call(a,"a")&&(e=a.a)),e=i.boundAlpha(e),{ok:x,format:a.format||g,r:Math.min(255,Math.max(r.r,0)),g:Math.min(255,Math.max(r.g,0)),b:Math.min(255,Math.max(r.b,0)),a:e}}var S="[-\\+]?\\d+%?",T="[-\\+]?\\d*\\.\\d+%?",f="(?:".concat(T,")|(?:").concat(S,")"),m="[\\s|\\(]+(".concat(f,")[,|\\s]+(").concat(f,")[,|\\s]+(").concat(f,")\\s*\\)?"),u="[\\s|\\(]+(".concat(f,")[,|\\s]+(").concat(f,")[,|\\s]+(").concat(f,")[,|\\s]+(").concat(f,")\\s*\\)?"),n={CSS_UNIT:new RegExp(f),rgb:new RegExp("rgb"+m),rgba:new RegExp("rgba"+u),hsl:new RegExp("hsl"+m),hsla:new RegExp("hsla"+u),hsv:new RegExp("hsv"+m),hsva:new RegExp("hsva"+u),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/};function F(a){if(a=a.trim().toLowerCase(),a.length===0)return!1;var r=!1;if(p.names[a])a=p.names[a],r=!0;else if(a==="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var e=n.rgb.exec(a);return e?{r:e[1],g:e[2],b:e[3]}:(e=n.rgba.exec(a),e?{r:e[1],g:e[2],b:e[3],a:e[4]}:(e=n.hsl.exec(a),e?{h:e[1],s:e[2],l:e[3]}:(e=n.hsla.exec(a),e?{h:e[1],s:e[2],l:e[3],a:e[4]}:(e=n.hsv.exec(a),e?{h:e[1],s:e[2],v:e[3]}:(e=n.hsva.exec(a),e?{h:e[1],s:e[2],v:e[3],a:e[4]}:(e=n.hex8.exec(a),e?{r:t.parseIntFromHex(e[1]),g:t.parseIntFromHex(e[2]),b:t.parseIntFromHex(e[3]),a:t.convertHexToDecimal(e[4]),format:r?"name":"hex8"}:(e=n.hex6.exec(a),e?{r:t.parseIntFromHex(e[1]),g:t.parseIntFromHex(e[2]),b:t.parseIntFromHex(e[3]),format:r?"name":"hex"}:(e=n.hex4.exec(a),e?{r:t.parseIntFromHex(e[1]+e[1]),g:t.parseIntFromHex(e[2]+e[2]),b:t.parseIntFromHex(e[3]+e[3]),a:t.convertHexToDecimal(e[4]+e[4]),format:r?"name":"hex8"}:(e=n.hex3.exec(a),e?{r:t.parseIntFromHex(e[1]+e[1]),g:t.parseIntFromHex(e[2]+e[2]),b:t.parseIntFromHex(e[3]+e[3]),format:r?"name":"hex"}:!1)))))))))}function s(a){return!!n.CSS_UNIT.exec(String(a))}exports.inputToRGB=I;exports.isValidCSSUnit=s;exports.stringInputToObject=F;
