const e=require("./util.js"),t=require("./conversion.js"),n=require("./css-color-names.js");function r(n){var r={r:0,g:0,b:0},i=1,a=null,o=null,s=null,u=!1,d=!1;return typeof n==`string`&&(n=c(n)),typeof n==`object`&&(l(n.r)&&l(n.g)&&l(n.b)?(r=t.rgbToRgb(n.r,n.g,n.b),u=!0,d=String(n.r).substr(-1)===`%`?`prgb`:`rgb`):l(n.h)&&l(n.s)&&l(n.v)?(a=e.convertToPercentage(n.s),o=e.convertToPercentage(n.v),r=t.hsvToRgb(n.h,a,o),u=!0,d=`hsv`):l(n.h)&&l(n.s)&&l(n.l)&&(a=e.convertToPercentage(n.s),s=e.convertToPercentage(n.l),r=t.hslToRgb(n.h,a,s),u=!0,d=`hsl`),Object.prototype.hasOwnProperty.call(n,`a`)&&(i=n.a)),i=e.boundAlpha(i),{ok:u,format:n.format||d,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:i}}var i=`(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)`,a=`[\\s|\\(]+(${i})[,|\\s]+(${i})[,|\\s]+(${i})\\s*\\)?`,o=`[\\s|\\(]+(${i})[,|\\s]+(${i})[,|\\s]+(${i})[,|\\s]+(${i})\\s*\\)?`,s={CSS_UNIT:new RegExp(i),rgb:RegExp(`rgb`+a),rgba:RegExp(`rgba`+o),hsl:RegExp(`hsl`+a),hsla:RegExp(`hsla`+o),hsv:RegExp(`hsv`+a),hsva:RegExp(`hsva`+o),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 c(e){if(e=e.trim().toLowerCase(),e.length===0)return!1;var r=!1;if(n.names[e])e=n.names[e],r=!0;else if(e===`transparent`)return{r:0,g:0,b:0,a:0,format:`name`};var i=s.rgb.exec(e);return i?{r:i[1],g:i[2],b:i[3]}:(i=s.rgba.exec(e),i?{r:i[1],g:i[2],b:i[3],a:i[4]}:(i=s.hsl.exec(e),i?{h:i[1],s:i[2],l:i[3]}:(i=s.hsla.exec(e),i?{h:i[1],s:i[2],l:i[3],a:i[4]}:(i=s.hsv.exec(e),i?{h:i[1],s:i[2],v:i[3]}:(i=s.hsva.exec(e),i?{h:i[1],s:i[2],v:i[3],a:i[4]}:(i=s.hex8.exec(e),i?{r:t.parseIntFromHex(i[1]),g:t.parseIntFromHex(i[2]),b:t.parseIntFromHex(i[3]),a:t.convertHexToDecimal(i[4]),format:r?`name`:`hex8`}:(i=s.hex6.exec(e),i?{r:t.parseIntFromHex(i[1]),g:t.parseIntFromHex(i[2]),b:t.parseIntFromHex(i[3]),format:r?`name`:`hex`}:(i=s.hex4.exec(e),i?{r:t.parseIntFromHex(i[1]+i[1]),g:t.parseIntFromHex(i[2]+i[2]),b:t.parseIntFromHex(i[3]+i[3]),a:t.convertHexToDecimal(i[4]+i[4]),format:r?`name`:`hex8`}:(i=s.hex3.exec(e),i?{r:t.parseIntFromHex(i[1]+i[1]),g:t.parseIntFromHex(i[2]+i[2]),b:t.parseIntFromHex(i[3]+i[3]),format:r?`name`:`hex`}:!1)))))))))}function l(e){return!!s.CSS_UNIT.exec(String(e))}exports.inputToRGB=r,exports.isValidCSSUnit=l,exports.stringInputToObject=c;