/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../../../chunks/_rollupPluginBabelHelpers","../../../../../../core/maybe","../../../../../../core/screenUtils","../../../../../../symbols/cim/enums","../../alignmentUtils","../../color","../../definitions","../../number","../../materialKey/MaterialKey","./util","./WGLBaseTextTemplate","./WGLDynamicMeshTemplate","../../../../layers/features/textUtils"],(function(t,e,i,n,o,a,s,r,l,c,_,p,h){"use strict";const m=5;function u(t,e,i,n){return"string"==typeof t.text?t.text:"function"==typeof t.text?t.text(e,i,n):""}let f=function(_){function p(t,o,p){var h;(h=_.call(this,t)||this)._horizontalAlignment="center",h._verticalAlignment="middle",h._textToGlyphs=new Map,h._minMaxZoom=r.i1616to32(Math.round(o*s.MIN_MAX_ZOOM_PRECISION_FACTOR),Math.round(p*s.MIN_MAX_ZOOM_PRECISION_FACTOR));const u=t.scaleFactor||1;h._cimTextLayer=t;const f=t.color;if(c.isFunction(f)){const t=(t,e,i)=>a.premultiplyAlphaRGBA(f(t,e,i));h._dynamicPropertyMap.set("_color",t)}else h._color=a.premultiplyAlphaRGBA(f);const y=t.outlineColor;if(c.isFunction(y)){const t=(t,e,i)=>a.premultiplyAlphaRGBA(y(t,e,i));h._dynamicPropertyMap.set("_haloColor",t)}else h._haloColor=a.premultiplyAlphaRGBA(y);let M;c.isFunction(t.size)||(M=Math.min(Math.round(i.pt2px(t.size*t.sizeRatio)),127));const d=(e,n,o)=>c.isFunction(t.size)?Math.min(Math.round(i.pt2px(t.size(e,n,o)*t.sizeRatio)),127):M;if(h._dynamicPropertyMap.set("_size",d),c.isFunction(t.outlineSize)){const e=(e,n,o)=>Math.min(Math.floor(m*i.pt2px(t.outlineSize(e,n,o)*t.sizeRatio)),127);h._dynamicPropertyMap.set("_haloSize",e)}else h._haloSize=Math.min(Math.floor(m*i.pt2px(t.outlineSize*t.sizeRatio)),127);let g;c.isFunction(t.offsetX)||(g=Math.round(i.pt2px(t.offsetX*t.sizeRatio)));const x=(e,n,o)=>c.isFunction(t.offsetX)?Math.round(i.pt2px(t.offsetX(e,n,o)*t.sizeRatio)):g;let z;h._dynamicPropertyMap.set("_xOffset",x),c.isFunction(t.offsetY)||(z=Math.round(i.pt2px(t.offsetY*t.sizeRatio)));const A=(e,n,o)=>c.isFunction(t.offsetY)?Math.round(i.pt2px(t.offsetY(e,n,o)*t.sizeRatio)):z;if(h._dynamicPropertyMap.set("_yOffset",A),c.isFunction(t.angle)?h._dynamicPropertyMap.set("_angle",t.angle):h._angle=t.angle,c.isFunction(t.horizontalAlignment)?h._dynamicPropertyMap.set("_horizontalAlignment",t.horizontalAlignment):h._horizontalAlignment=t.horizontalAlignment,c.isFunction(t.verticalAlignment)?h._dynamicPropertyMap.set("_verticalAlignment",t.verticalAlignment):h._verticalAlignment=t.verticalAlignment,e.isSome(t.effects)){const e=t.effects;c.isFunction(e)?h._dynamicPropertyMap.set("_effects",e):h._effects=e}if(e.isSome(t.markerPlacement)){const e=t.markerPlacement;c.isFunction(e)?h._dynamicPropertyMap.set("_markerPlacement",e):h._textPlacement=e}c.isFunction(t.text)?h._dynamicPropertyMap.set("_text",t.text):h._text=t.text,h._scaleFactor=u;const F=Math.min(Math.round(i.pt2px(t.referenceSize*t.sizeRatio)),127);h._referenceSize=Math.round(Math.sqrt(256*F)),h._materialKey=t.materialKey;const P=l.TextMaterialKey.load(h._materialKey);return P.sdf=!0,h._bitset=(t.alignment===n.Alignment.MAP?1:0)|(t.colorLocked?1:0)<<1,h._materialKey=P.data,h._decoration="none",h._lineHeight=1,h._lineWidth=512,h._isCIM=!0,h}t._inheritsLoose(p,_),p.fromCIMText=function(t,e){const[i,n]=c.getMinMaxZoom(t.scaleInfo,e);return new p(t,i,n)};var f=p.prototype;return f.analyze=function(){var e=t._asyncToGenerator((function*(t,e,i,n){const o=e.readLegacyFeature(),a=u(this._cimTextLayer,o,i,n),s=yield _.prototype.analyze.call(this,t,e,i,n,h.codepoints(a));return s&&s.glyphMosaicItems&&this._textToGlyphs.set(a,s.glyphMosaicItems),s}));function i(t,i,n,o){return e.apply(this,arguments)}return i}(),f.bindFeature=function(t,i,n){const a=t.readLegacyFeature();if(this._dynamicPropertyMap.forEach(((t,e)=>{this[e]=t(a,i,n)})),!this._text||0===this._text.length)return void(this._shapingInfo=null);this._size*=this._scaleFactor,this._scale=this._size/s.GLYPH_SIZE,this._xOffset*=this._scaleFactor,this._yOffset*=this._scaleFactor,this._xAlignD=o.getXAnchorDirection(e.unwrapOr(this._horizontalAlignment,"center")),this._yAlignD=o.getYAnchorDirection(e.unwrapOr(this._verticalAlignment,"baseline"));const r=this._textToGlyphs.get(this._text);this.bindTextInfo(r,!1)},p}(_(p));return f}));
