/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../kernel","../../request","../../core/colorUtils","../../core/Error","../../core/has","../../libs/maquette/projection","../../libs/maquette/projector","./svgUtils","./utils"],(function(t,e,i,n,r,o,a,c,l,s){"use strict";const h=c.createProjector();function g(t,e,i){const n=Math.ceil(e[0]),r=Math.ceil(e[1]);if(!t.some((t=>!!t.length)))return null;const o=i&&i.node||document.createElement("div");return null!=i.opacity&&(o.style.opacity=i.opacity.toString()),null!=i.effectView&&(o.style.filter=s.getCSSFilterFromEffectList(i.effectView)),h.append(o,l.renderSVG.bind(null,t,n,r,i)),o}function u(t,e){t=Math.ceil(t),e=Math.ceil(e);const i=document.createElement("canvas");i.width=t,i.height=e,i.style.width=t+"px",i.style.height=e+"px";const n=i.getContext("2d");return n.clearRect(0,0,t,e),n}function d(t,e,n){return t?i(t,{responseType:"image"}).then((t=>{const i=t.data,r=i.width,o=i.height,a=r/o;let c=e;if(n){const t=Math.max(r,o);c=Math.min(c,t)}return{image:i,width:a<=1?Math.ceil(c*a):c,height:a<=1?c:Math.ceil(c/a)}})):Promise.reject(new r("renderUtils: imageDataSize","href not provided."))}function m(t,e){return!(!t||"ignore"===e)&&("multiply"!==e||255!==t.r||255!==t.g||255!==t.b||1!==t.a)}function f(t,e,i,r,o){switch(o){case"multiply":t[e+0]*=i[0],t[e+1]*=i[1],t[e+2]*=i[2],t[e+3]*=i[3];break;default:{const o=n.toHSV({r:t[e+0],g:t[e+1],b:t[e+2]});o.h=r.h,o.s=r.s,o.v=o.v/100*r.v;const a=n.toRGB(o);t[e+0]=a.r,t[e+1]=a.g,t[e+2]=a.b,t[e+3]*=i[3];break}}}function p(t,i,r,a,c){return d(t,i,c).then((c=>{const l=c.width?c.width:i,s=c.height?c.height:i;if(c.image&&m(r,a)){let e=c.image.width,i=c.image.height;o("edge")&&/\.svg$/i.test(t)&&(e-=1,i-=1);const h=u(l,s);h.drawImage(c.image,0,0,e,i,0,0,l,s);const g=h.getImageData(0,0,l,s),d=[r.r/255,r.g/255,r.b/255,r.a],m=n.toHSV(r);for(let t=0;t<g.data.length;t+=4)f(g.data,t,d,m,a);h.putImageData(g,0,0),t=h.canvas.toDataURL("image/png")}else{const i=e.id&&e.id.findCredential(t);if(i&&i.token){const e=t.includes("?")?"&":"?";t=`${t}${e}token=${i.token}`}}return{url:t,width:l,height:s}})).catch((()=>({url:t,width:i,height:i})))}t.renderSymbol=g,t.tintImageWithColor=p,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
