// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See https://js.arcgis.com/4.16/esri/copyright.txt for details.
//>>built
define("require exports ../../core/tsSupport/generatorHelper ../../core/tsSupport/awaiterHelper ../../core/tsSupport/assignHelper ../../core/compilerUtils ../../core/maybe ../../core/promiseUtils ../../support/arcadeOnDemand ./previewCIMSymbol ./previewSymbol2D ./previewSymbol3D ./previewWebStyleSymbol ./utils".split(" "),function(D,p,E,F,G,H,q,I,J,K,L,M,N,x){function v(b,a){switch(b.type){case "web-style":return N.previewWebStyleSymbol(b,v,a);case "label-3d":case "line-3d":case "mesh-3d":case "point-3d":case "polygon-3d":return M.previewSymbol3D(b,
a);case "simple-marker":case "simple-line":case "simple-fill":case "picture-marker":case "picture-fill":case "text":return L.previewSymbol2D(b,a);case "cim":return K.previewCIMSymbol(b,a);default:H.neverReached(b)}}function A(b){return b&&"opacity"in b?b.opacity*A(b.parent):1}Object.defineProperty(p,"__esModule",{value:!0});var n=null;p.renderDotDensityPreviewHTML=function(b,a,c){var h=b.backgroundColor,k=b.outline;b=b.dotSize;var f=c&&c.swatchSize||22,d=Math.round(f*f/Math.pow(b,2)*.8),g=window.devicePixelRatio;
c=document.createElement("canvas");var l=f*g;c.width=l;c.height=l;c.style.width=c.width/g+"px";c.style.height=c.height/g+"px";var e=c.getContext("2d");h&&(e.fillStyle=h.toCss(!0),e.fillRect(0,0,l,l),e.fill());e.fillStyle=a.toCss(!0);if(n&&n.length/2===d)for(a=0;a<2*d;a+=2){var h=n[a],m=n[a+1];e.fillRect(h,m,b*g,b*g);e.fill()}else for(n=[],a=0;a<2*d;a+=2)h=Math.floor(Math.random()*(l-0+1)+0),m=Math.floor(Math.random()*(l-0+1)+0),n.push(h,m),e.fillRect(h,m,b*g,b*g),e.fill();k&&(k.color&&(e.strokeStyle=
k.color.toCss(!0)),e.lineWidth=k.width,e.strokeRect(0,0,l,l));k=new Image(f,f);k.src=c.toDataURL();return k};p.renderColorRampPreviewHTML=function(b,a){void 0===a&&(a={});var c="horizontal"===a.align,h=a.width,h=void 0===h?c?75:24:h,k=a.height,k=void 0===k?c?24:75:k;a=a.gradient;var f=void 0===a?!0:a;a=window.devicePixelRatio;var d=h*a,g=k*a;a=document.createElement("canvas");a.width=d;a.height=g;a.style.width=h+"px";a.style.height=k+"px";var l=a.getContext("2d"),e=c?d:0,m=c?0:g;if(f){var t=l.createLinearGradient(0,
0,e,m),q=1/(b.length-1);b.forEach(function(a,b){return t.addColorStop(b*q,a.toString())});l.fillStyle=t;l.fillRect(0,0,d,g)}else for(f=c?d/b.length:d,d=c?g:g/b.length,m=e=g=0;m<b.length;m++)l.fillStyle=b[m].toString(),l.fillRect(g,e,f,d),g=c?g+f:0,e=c?0:e+d;b=document.createElement("div");b.style.width=h+"px";b.style.height=k+"px";b.appendChild(a);return b};p.renderPreviewHTML=v;p.getDisplayedSymbol=function(b,a){return F(this,void 0,void 0,function(){var c,h,k,f,d,g,l,e,m,t,n,p,y,z,u,v,B,C,w;return E(this,
function(r){switch(r.label){case 0:if(!b)return[2,void 0];c=A(b.layer||b.sourceLayer);return!q.isSome(b.symbol)||q.isSome(a)&&!0===a.ignoreGraphicSymbol?[3,4]:"web-style"!==b.symbol.type?[3,2]:[4,b.symbol.fetchSymbol(q.isSome(a)?a.abortOptions:null)];case 1:return k=r.sent(),[3,3];case 2:k=b.symbol.clone(),r.label=3;case 3:return h=k,x.applyColorToSymbol(h,null,c),[2,h];case 4:return f=b.get("layer.renderer")||b.get("sourceLayer.renderer"),[4,f.getSymbolAsync(b)];case 5:return(d=r.sent())?"web-style"!==
d.type?[3,7]:[4,d.fetchSymbol(q.isSome(a)?a.abortOptions:null)]:[2,void 0];case 6:return d=r.sent(),[3,8];case 7:d=d.clone(),r.label=8;case 8:if(!("visualVariables"in f)||"visualVariables"in f&&!f.visualVariables||"visualVariables"in f&&f.visualVariables&&!f.visualVariables.length)return[2,d];if(!f.arcadeRequiredForVisualVariables||!q.isNone(a)&&!q.isNone(a.arcade))return[3,10];l=g=G({},q.unwrap(a));return[4,J.loadArcade()];case 9:l.arcade=r.sent(),a=g,r.label=10;case 10:return[4,I.create(function(a){return D(["../../renderers/visualVariables/support/visualVariableUtils"],
a)})];case 11:e=r.sent();m=[];t=[];n=[];p=[];y=0;for(z=f.visualVariables;y<z.length;y++)switch(u=z[y],u.type){case "color":m.push(u);break;case "opacity":t.push(u);break;case "rotation":p.push(u);break;case "size":n.push(u)}B=(v=!!m.length&&m[m.length-1])?e.getColor(v,b,a):null;w=(C=!!t.length&&t[t.length-1])?e.getOpacity(C,b,a):null;null!=c&&(w=null!=w?w*c:c);x.applyColorToSymbol(d,B,w);n.forEach(function(c){return x.applySizeToSymbol(d,e.getSize(c,b,a),c.axis)});p.forEach(function(c){return x.applyRotationToSymbol(d,
e.getRotationAngle(c,b,a),c.axis)});return[2,d]}})})}});