text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.11/esri/copyright.txt for details.
  //>>built
  define("require exports ../../../../../../core/tsSupport/awaiterHelper ../../../../../../core/tsSupport/generatorHelper ../../../../../../symbols ../../../../../../core/Error ../../../../../../core/Logger ../../../../../../core/promiseUtils ../../../cim/cimAnalyzer ./WGLDynamicMarkerTemplate ./WGLFillTemplate ./WGLLineTemplate ./WGLMarkerTemplate ./WGLTextTemplate ../../util/BidiText ../../util/Lock ../../util/Result".split(" "),function(v,q,h,k,r,B,C,p,D,E,t,w,u,F,x,y,n){function m(b,a){var d=b.length;
  b.push(null);a.then(function(a){return b[d]=a});return b}function z(b){return!!(b&1)}Object.defineProperty(q,"__esModule",{value:!0});var g=C.getLogger("esri.views.2d.engine.webgl.mesh.templates.WGLTemplateStore"),A=[],G=new r.SimpleFillSymbol({color:"black",outline:null}),H=new r.SimpleMarkerSymbol({size:"14px",color:"black",outline:null}),I=new r.SimpleLineSymbol({color:"black",width:"2px"});q.isDynamicId=z;v=function(){function b(a){this._templateIdCounter=this._idCounter=0;this._idToTemplateGroup=
  new Map;this._symbolToTemplate=new Map;this._fetchQueue=[];this._idToResolver=new Map;this._lock=new y.default;this._fetchResource=a}Object.defineProperty(b.prototype,"_markerError",{get:function(){return this._errorTemplates.marker[0]},enumerable:!0,configurable:!0});Object.defineProperty(b.prototype,"_fillError",{get:function(){return this._errorTemplates.fill[0]},enumerable:!0,configurable:!0});Object.defineProperty(b.prototype,"_lineError",{get:function(){return this._errorTemplates.line[0]},
  enumerable:!0,configurable:!0});b.prototype.createTemplateGroup=function(a,d,c,e){this._initErrorTemplates();var b=this._hashSymbol(a);if(!this._symbolToTemplate.has(b)){var l=[];d&&this._createMeshTemplates(l,d,c,e,!0);this._createMeshTemplates(l,a,c,e,!1);a=this._createGroupId("cim"===a.type);this._idToTemplateGroup.set(a,l);this._symbolToTemplate.set(b,a)}return this._symbolToTemplate.get(b)};b.prototype.getMosaicItem=function(a){var d=this,c=this._createTemplateId(),e;if("text"===a.type){var b=
  x.bidiText(a.text)[0];e=[];for(var l=0;l<b.length;l++)e.push(b.charCodeAt(l))}b=p.create(function(a){return d._idToResolver.set(c,a)});this._fetchQueue.push({symbol:a,id:c,glyphIds:e});return b};b.prototype.getTemplateGroup=function(a){return this._idToTemplateGroup.has(a)?this._idToTemplateGroup.get(a):A};b.prototype.getDynamicTemplateGroup=function(a){if(!this._idToTemplateGroup.has(a))return A;z(a)||g.error("mapview-template-store","Id "+a+" does not refer to a dynamic template");return this._idToTemplateGroup.get(a)};
  b.prototype.finalize=function(){return this._fetchQueue.length||this._lock.isHeld()?y.withLock(this._lock,this._fetchAllQueuedResources.bind(this)):p.resolve()};b.prototype._initErrorTemplates=function(){if(!this._errorTemplates){var a=this._createMeshTemplates([],G,null,null,!1),d=this._createMeshTemplates([],H,null,null,!1),c=this._createMeshTemplates([],I,null,null,!1);this._errorTemplates={fill:a,marker:d,line:c}}};b.prototype._fetchAllQueuedResources=function(){var a=this;if(!this._fetchQueue.length)return p.resolve();
  var d=this._fetchQueue;this._fetchQueue=[];return this._fetchResource(d).then(function(c){for(var d=0;d<c.length;d++){var b=c[d],l=b.id,b=b.mosaicItem;a._idToResolver.get(l)(b);a._idToResolver.delete(l)}}).catch(function(c){"cancel"===c.dojoType?a._fetchQueue=a._fetchQueue.concat(d):g.error(B("mapview-template-store","Unable to fetch requested texture resources",c))})};b.prototype._createGroupId=function(a){return this._idCounter++<<1|(a?1:0)};b.prototype._createTemplateId=function(){return this._templateIdCounter++};
  b.prototype._getCodepoints=function(a){a=x.bidiText(a.text)[0];for(var d=[],c=0;c<a.length;c++)d.push(a.charCodeAt(c));return d};b.prototype._getMosaicItem=function(a){var d=this,c=this._createTemplateId(),b="text"===a.type&&this._getCodepoints(a),f=p.create(function(a){return d._idToResolver.set(c,a)});this._fetchQueue.push({symbol:a.toJSON(),id:c,glyphIds:b});return f};b.prototype._hashSymbol=function(a){return a.id?a.id:JSON.stringify(a)};b.prototype._createSMS=function(a,d){return h(this,void 0,
  void 0,function(){var c;return k(this,function(b){switch(b.label){case 0:return[4,this._getMosaicItem(a)];case 1:return c=b.sent().spriteMosaicItem,n.ok(c,g)?[2,u.default.fromSimpleMarker(d,a,c)]:[2,this._markerError]}})})};b.prototype._createPMS=function(a,d){return h(this,void 0,void 0,function(){var c;return k(this,function(b){switch(b.label){case 0:return[4,this._getMosaicItem(a)];case 1:return c=b.sent().spriteMosaicItem,n.ok(c,g)?[2,u.default.fromPictureMarker(d,a,c)]:[2,this._markerError]}})})};
  b.prototype._createSFS=function(a,d,c){return h(this,void 0,void 0,function(){var b,f;return k(this,function(e){switch(e.label){case 0:return[4,this._getMosaicItem(a)];case 1:return b=e.sent().spriteMosaicItem,f=a,n.ok(b,g)?[2,t.default.fromSimpleFill(d,f,b,c)]:[2,this._fillError]}})})};b.prototype._createPFS=function(a,d,b){return h(this,void 0,void 0,function(){var c,f;return k(this,function(e){switch(e.label){case 0:return[4,this._getMosaicItem(a)];case 1:return c=e.sent().spriteMosaicItem,f=a,
  n.ok(c,g)?[2,t.default.fromPictureFill(d,f,c,b)]:[2,this._fillError]}})})};b.prototype._createSLS=function(a,b,c){return h(this,void 0,void 0,function(){var d,f;return k(this,function(e){switch(e.label){case 0:return[4,this._getMosaicItem(a)];case 1:return d=e.sent().spriteMosaicItem,f=a,n.ok(d,g)?[2,w.default.fromSimpleLine(b,c,f,d)]:[2,this._lineError]}})})};b.prototype._createTS=function(a,b){return h(this,void 0,void 0,function(){var d;return k(this,function(c){switch(c.label){case 0:return[4,
  this._getMosaicItem(a)];case 1:return d=c.sent().glyphMosaicItems,[2,F.default.fromText(b,a,d)]}})})};b.prototype._createCIMText=function(a,b){return h(this,void 0,void 0,function(){return k(this,function(a){return[2,p.resolve(null)]})})};b.prototype._createCIMFill=function(a,b){return h(this,void 0,void 0,function(){var d;return k(this,function(c){switch(c.label){case 0:return[4,this.getMosaicItem(a.cim)];case 1:return d=c.sent().spriteMosaicItem,n.ok(d,g)?[2,t.default.fromCIMFill(b,a,d,!1)]:[2,
  this._fillError]}})})};b.prototype._createCIMLine=function(a,b){return h(this,void 0,void 0,function(){var d;return k(this,function(c){switch(c.label){case 0:return[4,this.getMosaicItem(a.cim)];case 1:return d=c.sent().spriteMosaicItem,n.ok(d,g)?[2,w.default.fromCIMLine(b,a,d,!1)]:[2,this._lineError]}})})};b.prototype._createCIMMarker=function(a,b){return h(this,void 0,void 0,function(){var d;return k(this,function(c){switch(c.label){case 0:return a.materialHash?[2,p.resolve(E.default.fromCIMMarker(b,
  a))]:[4,this.getMosaicItem(a.cim)];case 1:return d=c.sent().spriteMosaicItem,n.ok(d,g)?[2,u.default.fromCIMMarker(b,a,d)]:[2,this._markerError]}})})};b.prototype._createCIM=function(a,b){switch(a.type){case "marker":return this._createCIMMarker(a,b);case "line":return this._createCIMLine(a,b);case "fill":return this._createCIMFill(a,b);case "text":return this._createCIMText(a,b)}};b.prototype._createCIMMeshTemplates=function(a,b,c,e){var d=0;for(b=D.analyzeCIMSymbol(b,e);d<b.length;d++)m(a,this._createCIM(b[d],
  c))};b.prototype._createMeshTemplates=function(a,b,c,e,f){if(-1!==b.type.indexOf("3d"))return g.error("3D symbols are not supported with MapView"),a;switch(b.type){case "cim":return this._createCIMMeshTemplates(a,b,c,e),a;case "simple-marker":return m(a,this._createSMS(b,c));case "picture-marker":return m(a,this._createPMS(b,c));case "simple-fill":return m(a,this._createSFS(b,c,f)),b.outline&&m(a,this._createSLS(b.outline,c,!0)),a;case "picture-fill":return m(a,this._createPFS(b,c,f)),b.outline&&
  m(a,this._createSLS(b.outline,c,!0)),a;case "simple-line":return m(a,this._createSLS(b,c,!1));case "text":return m(a,this._createTS(b,c));default:return g.error("Unable to create mesh template for unknown symbol type {: $ }{symbol.type}"),a}};return b}();q.default=v});