/* get-svg-colors-browser v2.0.8 Copyright (c) 2022 Georg Fischer @license MIT https://github.com/snorpey/get-svg-colors-browser.git */ const htmlCommentRegex=//g,svgNamespace="http://www.w3.org/2000/svg",colorRegex=/(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))/i,colornames=["black","silver","gray","white","maroon","red","purple","fuchsia","green","lime","olive","yellow","navy","blue","teal","aqua","aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];function unique(e,r,t){return t.indexOf(e)===r}function compact(e){for(var r=-1,t=e?e.length:0,l=0,o=[];++r]*>\s*)?(?:]*\s*(?:\[?(?:\s*]*>\s*)*\]?)*[^>]*>\s*)?]*>[^]*<\/svg>\s*$/i.test(e.replace(htmlCommentRegex,""))}function isSVGEl(e){return e instanceof SVGElement}function getEls(e,r){return toArray(r.querySelectorAll(e))}function toArray(e){return Array.prototype.slice.call(e)}function getSVGEl(e,r){return isSVGEl(e)?Promise.resolve(e):isSVGStr(e)?Promise.resolve(svgElFromString(e)):"string"==typeof e?fetch(e).then(e=>e.text()).then(e=>svgElFromString(e)):void 0}function getColorsInCSSStr(e,r){return e.replace(/(\s|\n|\R|\r)/g,"").split(/(\{|\}|\;)/).map(e=>e.trim()).map(toLowerCase).filter(e=>e&&e.length).filter(e=>0===e.indexOf(r)).map(e=>e.split(":").map(e=>e.trim()).filter(e=>e!==r)).reduce((e,r)=>e.concat(r),[]).filter(e=>-1!==colornames.indexOf(e)||colorRegex.test(e))}function getSVGColors(e,r){return getSVGEl(e).then(e=>{const t=getEls("[fill]",e).map(e=>e.getAttribute("fill")),l=getEls("[stroke]",e).map(e=>e.getAttribute("stroke")),o=getEls("[stop-color]",e).map(e=>e.getAttribute("stop-color"));return getEls("[style]",e).forEach(e=>{t.push(e.style.fill),l.push(e.style.stroke),o.push(e.style.stopColor)}),getEls("style",e).forEach(e=>{const r=e.textContent;getColorsInCSSStr(r,"fill").forEach(e=>t.push(e)),getColorsInCSSStr(r,"stroke").forEach(e=>l.push(e)),getColorsInCSSStr(r,"stop-color").forEach(e=>o.push(e))}),r&&r.flat?compact(t.concat(l).concat(o).filter(isColorString).map(toLowerCase).filter(unique)):{fills:compact(t.filter(isColorString).map(toLowerCase).filter(unique)),strokes:compact(l.filter(isColorString).map(toLowerCase).filter(unique)),stops:compact(o.filter(isColorString).map(toLowerCase).filter(unique))}})}export default getSVGColors;