UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) • 24 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{bidiText as e}from"../../core/BidiText.js";import has from"../../core/has.js";import{clone as t}from"../../core/lang.js";import r from"../../core/Logger.js";import o from"../../core/RandomLCG.js";import{px2pt as a}from"../../core/screenUtils.js";import{create as s,expandPointInPlace as i}from"../../geometry/support/aaBoundingRect.js";import{getBoundsXY as n}from"../../geometry/support/boundsUtils.js";import l from"../Font.js";import{Placement as c}from"./CIMPlacements.js";import{EnvDrawHelper as m,Transformation as f,CanvasDrawHelper as y,lineGapType2LineHeight as h}from"./CIMSymbolDrawHelper.js";import{defaultCIMValues as u}from"./defaultCIMValues.js";import{TextureFilter as M,LineJoinStyle as p,LineCapStyle as S,ExtremityPlacement as d,BillBoardMode as g,VerticalGlyphOrientation as b,TextReadingDirection as C,GlyphHinting as x,FontType as I,FontEncoding as k,FontEffects as w,BlockProgression as P,LineDashEnding as L}from"./enums.js";import{getNumericValue as F,fromCIMFontStyle as z,fromCIMFontDecoration as D,isGeometryEngineRequired as E,importGeometryEngine as T}from"./utils.js";import{defaultPolylineSymbol2D as G}from"../support/defaults.js";import{cInfinity as v}from"../../views/2d/engine/vectorTiles/GeometryUtils.js";import{magicLabelLineHeight as A,glyphSize as R,randomInsidePolygonTextureSize as j}from"../../views/2d/engine/webgl/definitions.js";import{shapeGlyphs as B}from"../../views/2d/engine/webgl/mesh/templates/shapingUtils.js";import{roundPtToWholePixel as X,getLineWidth as V}from"../../views/2d/layers/graphics/graphicsUtils.js";const N=Math.PI,Y=N/2,_=Math.PI/180,U=96/72,q=1.4142135623730951,H=2,O=4,W=()=>r.getLogger("esri.symbols.cim.CIMSymbolHelper");function $(e){let t;switch(e.type){case"cim":return e.data;case"web-style":return e;case"simple-marker":{const r=te.fromSimpleMarker(e);if(!r)throw new Error("InternalError: Cannot convert symbol to CIM");t=r;break}case"picture-marker":t=te.fromPictureMarker(e);break;case"simple-line":t=te.fromSimpleLineSymbol(e);break;case"simple-fill":t=te.fromSimpleFillSymbol(e);break;case"picture-fill":t=te.fromPictureFillSymbol(e);break;case"text":t=te.fromTextSymbol(e)}return{type:"CIMSymbolReference",symbol:t}}function J(e,t,r){switch(t.type){case"CIMSymbolReference":return J(e,t.symbol,r);case"CIMPointSymbol":null==r&&(r={x:0,y:0}),e.drawSymbol(t,r);break;case"CIMLineSymbol":null==r&&(r={paths:[[[0,0],[10,0]]]}),e.drawSymbol(t,r);break;case"CIMPolygonSymbol":null==r&&(r={rings:[[[0,0],[0,10],[10,10],[10,0],[0,0]]]}),e.drawSymbol(t,r);break;case"CIMTextSymbol":{const r={x:0,y:0};e.drawSymbol(t,r);break}case"CIMVectorMarker":{const r=new c;e.drawMarker(t,r);break}}return e.envelope()}function K(e){if(!e)return 0;switch(e.type){case"CIMMarkerPlacementAlongLineSameSize":case"CIMMarkerPlacementAlongLineRandomSize":case"CIMMarkerPlacementAtExtremities":case"CIMMarkerPlacementAtMeasuredUnits":case"CIMMarkerPlacementAtRatioPositions":case"CIMMarkerPlacementOnLine":case"CIMMarkerPlacementOnVertices":return Math.abs(e.offset);default:return 0}}function Q(e){if(!e)return 0;switch(e.type){case"CIMGeometricEffectArrow":return Math.abs(.5*e.width);case"CIMGeometricEffectBuffer":return Math.abs(e.size);case"CIMGeometricEffectControlMeasureLine":return 500;case"CIMGeometricEffectExtension":case"CIMGeometricEffectRadial":return Math.abs(e.length);case"CIMGeometricEffectJog":return Math.abs(.5*e.length);case"CIMGeometricEffectMove":return Math.max(Math.abs(F(e.offsetX)),Math.abs(F(e.offsetY)));case"CIMGeometricEffectOffset":case"CIMGeometricEffectOffsetTangent":return Math.abs(e.offset);case"CIMGeometricEffectRegularPolygon":return Math.abs(e.radius);case"CIMGeometricEffectRotate":case"CIMGeometricEffectScale":default:return 0;case"CIMGeometricEffectTaperedPolygon":return.5*Math.max(Math.abs(e.fromWidth),Math.abs(e.toWidth));case"CIMGeometricEffectWave":return Math.abs(e.amplitude);case"CIMGeometricEffectDonut":return Math.abs(e.width)}}function Z(e){if(!e)return 0;let t=0;for(const r of e)t+=Q(r);return t}class ee{static getSymbolInflateSize(e,t,r,o,a){return e||(e=[0,0,0,0]),t?this._getInflateSize(e,t,r,o,a):e}static safeSize(e){const t=Math.max(Math.abs(e[0]),Math.abs(e[2])),r=Math.max(Math.abs(e[1]),Math.abs(e[3]));return Math.sqrt(t*t+r*r)}static _vectorMarkerBounds(e,t,r,o){let a=!0;const i=s();if(t?.markerGraphics)for(const s of t.markerGraphics){const t=[0,0,0,0];s.geometry&&(n(i,s.geometry),t[0]=0,t[1]=0,t[2]=0,t[3]=0,this.getSymbolInflateSize(t,s.symbol,r,0,o),i[0]+=t[0],i[1]+=t[1],i[2]+=t[2],i[3]+=t[3],a?(e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],a=!1):(e[0]=Math.min(e[0],i[0]),e[1]=Math.min(e[1],i[1]),e[2]=Math.max(e[2],i[2]),e[3]=Math.max(e[3],i[3])))}return e}static _getInflateSize(e,t,r,o,a){if(ye(t)){const s=this._getLayersInflateSize(e,t.symbolLayers,r,o,a),i=Z(t.effects);return i>0&&(s[0]-=i,s[1]-=i,s[2]+=i,s[3]+=i),s}return this._getTextInflatedSize(e,t,a)}static _getLayersInflateSize(e,t,r,o,a){let n=!0;if(!t)return e;for(const l of t){if(!l)continue;let t=[0,0,0,0];switch(l.type){case"CIMSolidFill":case"CIMPictureFill":case"CIMHatchFill":case"CIMGradientFill":break;case"CIMSolidStroke":case"CIMPictureStroke":case"CIMGradientStroke":{const e=l;let r=e.width;null!=r&&(e.capStyle===S.Square||e.joinStyle===p.Miter?r/=q:r/=2,t[0]=-r,t[1]=-r,t[2]=r,t[3]=r);break}case"CIMCharacterMarker":case"CIMVectorMarker":case"CIMPictureMarker":{const e=l;if("CIMVectorMarker"===l.type){const e=l;if(t=this._vectorMarkerBounds(t,e,r,a),e.frame){const r=(e.frame.xmin+e.frame.xmax)/2,o=(e.frame.ymin+e.frame.ymax)/2;if(t[0]-=r,t[1]-=o,t[2]-=r,t[3]-=o,null!=e.size){const r=e.size/(e.frame.ymax-e.frame.ymin);t[0]*=r,t[1]*=r,t[2]*=r,t[3]*=r}}}else if("CIMPictureMarker"===l.type){const o=l,a=r.getResource(o.url);let s=1;if(null!=a&&a.height&&(s=a.width/a.height),null!=e.size){const r=e.size/2,a=e.size*s*o.scaleX/2;t=[-a,-r,a,r]}}else if(null!=e.size){const r=e.size/2;t=[-r,-r,r,r]}if(e.anchorPoint){let r,o;"Absolute"===e.anchorPointUnits?(r=e.anchorPoint.x,o=e.anchorPoint.y):(r=e.anchorPoint.x*(t[2]-t[0]),o=e.anchorPoint.y*(t[3]-t[1]));const a=1.25*Math.sqrt(r*r+o*o);t[0]-=a,t[1]-=a,t[2]+=a,t[3]+=a}let n=F(e.rotation);if(e.rotateClockwise&&(n=-n),o&&(n-=o),n){const e=_*n,r=Math.cos(e),o=Math.sin(e),a=s([v,v,-v,-v]);i(a,[t[0]*r-t[1]*o,t[0]*o+t[1]*r]),i(a,[t[0]*r-t[3]*o,t[0]*o+t[3]*r]),i(a,[t[2]*r-t[1]*o,t[2]*o+t[1]*r]),i(a,[t[2]*r-t[3]*o,t[2]*o+t[3]*r]),t=a}let c=F(e.offsetX),m=F(e.offsetY);if(o){const e=_*o,t=Math.cos(e),r=Math.sin(e),a=c*r+m*t;c=c*t-m*r,m=a}t[0]+=c,t[1]+=m,t[2]+=c,t[3]+=m;const f=K(e.markerPlacement);f>0&&(t[0]-=f,t[1]-=f,t[2]+=f,t[3]+=f);break}}const c=Z(l.effects);c>0&&(t[0]-=c,t[1]-=c,t[2]+=c,t[3]+=c),n?(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],n=!1):(e[0]=Math.min(e[0],t[0]),e[1]=Math.min(e[1],t[1]),e[2]=Math.max(e[2],t[2]),e[3]=Math.max(e[3],t[3]))}return e}static _getTextInflatedSize(e,t,r){const o=X(t.height??u.CIMTextSymbol.height);if(e[0]=-o/2,e[1]=-o/2,e[2]=o/2,e[3]=o/2,!r)return e;const a=r.get(t);if(!a)return e;if(!a.glyphMosaicItems.glyphs.length)return e;const{lineGapType:s,lineGap:i}=t,n=s?h(s,i??0,o):0,l="CIMBackgroundCallout"===t.callout?.type,c=B(a.glyphMosaicItems,{scale:o/R,angle:F(t.angle),xOffset:F(t.offsetX),yOffset:F(t.offsetY),horizontalAlignment:t.horizontalAlignment,verticalAlignment:t.verticalAlignment,maxLineWidth:V(t.lineWidth),lineHeight:A*Math.max(.25,Math.min(n||1,4)),decoration:t.font.decoration||"none",useCIMAngleBehavior:!0,hasBackground:l}).boundsT,m=Math.sqrt(c.width*c.width+c.height*c.height);return e[0]-=c.x+m,e[1]-=c.y-m,e[2]+=c.x+m,e[3]+=-c.y+m,e}}class te{static getEnvelope(e,t,r){if(!e)return null;const o=new m(r);if(Array.isArray(e)){let r;for(const a of e)r?r.union(J(o,a,t)):r=J(o,a,t);return r}return J(o,e,t)}static getTextureInfo(e,t,r,o,a){const s=o??this.getEnvelope(e,null,t);if(!s)return[0,0,0,0,1];const i=Math.max(s.width,s.height)*U;let n=null!=a?Math.max(a/i,1):1;n*=U,s.x*=n,s.y*=n,s.width*=n,s.height*=n,s.width=Math.max(Math.ceil(s.x+s.width)-Math.floor(s.x),1)-1,s.height=Math.max(Math.ceil(s.y+s.height)-Math.floor(s.y),1)-1;let l=s.x+.5*s.width,c=s.y+.5*s.height;return l+=s.x-Math.floor(s.x),c+=s.y-Math.floor(s.y),o||(s.width+=r,s.height+=r,l+=r/2,c+=r/2),[s.width,s.height,l,c,n]}static getTextureAnchor(e,t,r){const[o,a,s,i,n]=this.getTextureInfo(e,t,H,null,r);return[-s/o,-i/a,a/n*U]}static rasterize(e,t,r,o,a=!0,s){const[i,n,l,m,h]=this.getTextureInfo(t,o,H,r,s);e.width=i,e.height=n;const u=e.getContext("2d",{willReadFrequently:!0}),M=f.createScale(h,-h);M.translate(.5*i-l,.5*n+m);const p=new y(u,o,M);switch(t.type){case"CIMPointSymbol":{const e={type:"point",x:0,y:0};p.drawSymbol(t,e);break}case"CIMVectorMarker":{const e=new c;p.drawMarker(t,e);break}}const S=u.getImageData(0,0,e.width,e.height),d=new Uint8Array(S.data);if(a){let e;for(let t=0;t<d.length;t+=4)e=d[t+3]/255,d[t]=d[t]*e,d[t+1]=d[t+1]*e,d[t+2]=d[t+2]*e}return[d,e.width,e.height,-l/i,-m/n]}static fromTextSymbol(e){const{text:t}=e;return{type:"CIMPointSymbol",symbolLayers:[{type:"CIMVectorMarker",enable:!0,anchorPointUnits:"Relative",dominantSizeAxis3D:"Y",size:10,billboardMode3D:"FaceNearPlane",frame:{xmin:-5,ymin:-5,xmax:5,ymax:5},markerGraphics:[{type:"CIMMarkerGraphic",geometry:{x:0,y:0},symbol:te.createCIMTextSymbolfromTextSymbol(e),textString:t}],scaleSymbolsProportionally:!0,respectFrame:!0}],scaleX:1,angleAlignment:"Display"}}static fromPictureFillSymbol(e){const{height:t,outline:r,width:o,xoffset:a,xscale:s,yoffset:i,yscale:n}=e,l=[],c={type:"CIMPolygonSymbol",symbolLayers:l};if(r){const e=pe(r);e&&l.push(e)}let m=e.url;"esriPFS"===e.type&&e.imageData&&(m=e.imageData);const f="angle"in e?e.angle??0:0,y=(o??0)*(s||1),h=(t??0)*(n||1);return l.push({type:"CIMPictureFill",invertBackfaceTexture:!1,scaleX:1,textureFilter:M.Picture,tintColor:null,url:m,height:h,width:y,offsetX:F(a),offsetY:F(i),rotation:F(-f),colorSubstitutions:null}),c}static fromSimpleFillSymbol(e){const{color:r,style:o,outline:s}=e,i=[],n={type:"CIMPolygonSymbol",symbolLayers:i};if(s){const e=pe(s);e&&i.push(e)}if(o&&"solid"!==o&&"none"!==o&&"esriSFSSolid"!==o&&"esriSFSNull"!==o){const e={type:"CIMLineSymbol",symbolLayers:[{type:"CIMSolidStroke",color:ne(r),capStyle:S.Butt,joinStyle:p.Miter,width:.75}]};let s=0;const n=a(ue(o)?8:10);switch(o){case"vertical":case"esriSFSVertical":s=90;break;case"forward-diagonal":case"esriSFSForwardDiagonal":case"diagonal-cross":case"esriSFSDiagonalCross":s=-45;break;case"backward-diagonal":case"esriSFSBackwardDiagonal":s=45;break;case"cross":case"esriSFSCross":s=0}i.push({type:"CIMHatchFill",lineSymbol:e,offsetX:0,offsetY:0,rotation:s,separation:n}),"cross"===o||"esriSFSCross"===o?i.push({type:"CIMHatchFill",lineSymbol:t(e),offsetX:0,offsetY:0,rotation:90,separation:n}):"diagonal-cross"!==o&&"esriSFSDiagonalCross"!==o||i.push({type:"CIMHatchFill",lineSymbol:t(e),offsetX:0,offsetY:0,rotation:45,separation:n})}else!o||"solid"!==o&&"esriSFSSolid"!==o||i.push({type:"CIMSolidFill",enable:!0,color:ne(r)});return n}static fromSimpleLineSymbol(e){const{cap:t,color:r,join:o,marker:a,miterLimit:s,style:i,width:n}=e;let l=null;"solid"!==i&&"none"!==i&&"esriSLSSolid"!==i&&"esriSLSNull"!==i&&(l=[{type:"CIMGeometricEffectDashes",dashTemplate:fe(i,t),lineDashEnding:"NoConstraint",scaleDash:!0,offsetAlongLine:null}]);const c=[];if(a){let e;switch(a.placement){case"begin-end":e=d.Both;break;case"begin":e=d.JustBegin;break;case"end":e=d.JustEnd;break;default:e=d.None}const t=te.fromSimpleMarker(a,n,r).symbolLayers[0];t.markerPlacement={type:"CIMMarkerPlacementAtExtremities",placePerPart:!1,angleToLine:!0,offset:0,extremityPlacement:e,offsetAlongLine:0},c.push(t)}return c.push({type:"CIMSolidStroke",color:"none"!==i&&"esriSLSNull"!==i?ne(r):[0,0,0,0],capStyle:oe(t),joinStyle:ae(o),miterLimit:s,width:n,effects:l}),{type:"CIMLineSymbol",symbolLayers:c}}static fromPictureMarker(e){const{angle:t,height:r,width:o,xoffset:a,yoffset:s}=e;let i=e.url;return"esriPMS"===e.type&&e.imageData&&(i=e.imageData),{type:"CIMPointSymbol",symbolLayers:[{type:"CIMPictureMarker",invertBackfaceTexture:!1,scaleX:1,textureFilter:M.Picture,tintColor:null,url:i,size:r,width:o,offsetX:F(a),offsetY:F(s),rotation:F(-t)}]}}static createCIMTextSymbolfromTextSymbol(t){const{angle:r,color:o,font:a,haloColor:s,haloSize:i,horizontalAlignment:n,kerning:l,lineWidth:c,text:m,verticalAlignment:f,xoffset:y,yoffset:h,backgroundColor:u,borderLineColor:M,borderLineSize:p}=t;let S,d,L,z,D,E;a&&(S=a.family,d=a.style,L=a.weight,z=a.size,D=a.decoration);let T=!1;if(m){T=e(m)[1]}return(u||p)&&(E={type:"CIMBackgroundCallout",margin:null,backgroundSymbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",color:ne(u)},{type:"CIMSolidStroke",color:ne(M),width:p}]},accentBarSymbol:null,gap:null,leaderLineSymbol:null,lineStyle:null}),{type:"CIMTextSymbol",angle:r,blockProgression:P.BTT,depth3D:1,extrapolateBaselines:!0,fontEffects:w.Normal,fontEncoding:k.Unicode,fontFamilyName:S||"Arial",fontStyleName:le(d,L),fontType:I.Unspecified,haloSize:i,height:z,hinting:x.Default,horizontalAlignment:se(n??"center"),kerning:l,letterWidth:100,ligatures:!0,lineGapType:"Multiple",lineWidth:c,offsetX:F(y),offsetY:F(h),strikethrough:"line-through"===D,underline:"underline"===D,symbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:ne(o)}]},haloSymbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidFill",enable:!0,color:ne(s)}]},shadowColor:[0,0,0,255],shadowOffsetX:1,shadowOffsetY:1,textCase:"Normal",textDirection:T?C.RTL:C.LTR,verticalAlignment:ie(f??"baseline"),verticalGlyphOrientation:b.Right,wordSpacing:100,billboardMode3D:g.FaceNearPlane,callout:E}}static createPictureMarkerRasterizationParam(e){const{angle:t,height:r,width:o,xoffset:a,yoffset:s}=e,i=e.url??e.source?.url??e.source?.imageData;return i?{type:"sprite-rasterization-param",overrides:[],resource:{type:"CIMPictureMarker",invertBackfaceTexture:!1,scaleX:1,textureFilter:M.Picture,tintColor:null,url:i,size:r,width:o,offsetX:F(a),offsetY:F(s),rotation:F(-t)}}:null}static createPictureFillRasterizationParam(e){const{width:t,height:r,xoffset:o,yoffset:a,url:s}=e;return s?{type:"sprite-rasterization-param",overrides:[],resource:{type:"CIMPictureFill",scaleX:1,textureFilter:M.Picture,tintColor:null,url:s,width:t,height:r,offsetX:F(o),offsetY:F(a),rotation:0}}:null}static fromSimpleMarker(e,t,r){const{style:o}=e,a=e.color??r;if("path"===o||"esriSMSPath"===o){const t=[];if("outline"in e&&e.outline){const r=e.outline;t.push({type:"CIMSolidStroke",enable:!0,width:r.width,color:ne(r.color),path:e.path})}t.push({type:"CIMSolidFill",enable:!0,color:ne(a),path:e.path});const[r,o]=he("square");return{type:"CIMPointSymbol",symbolLayers:[{type:"CIMVectorMarker",enable:!0,rotation:-F(e.angle),size:F(e.size||6),offsetX:F(e.xoffset),offsetY:F(e.yoffset),scaleSymbolsProportionally:!1,frame:r,markerGraphics:[{type:"CIMMarkerGraphic",geometry:o,symbol:{type:"CIMPolygonSymbol",symbolLayers:t}}]}]}}const s=[];let i,n,l=e.size;if("outline"in e&&e.outline&&"none"!==e.outline.style&&"esriSLSNull"!==e.outline.style){const t=e.outline,r="solid"!==t.style&&"esriSLSSolid"!==t.style;[i,n]=r?he(o,e.size):he(o);const a=t.width??G.width;if(r){const t=a/e.size,r=(i.xmax-i.xmin)*t/2,o=(i.ymax-i.ymin)*t/2;i.xmin-=r,i.xmax+=r,i.ymin-=o,i.ymax+=o,l&&(l+=a)}const c="cross"!==e.style&&"x"!==e.style||"dot"===e?.outline.style||"short-dot"===e?.outline.style?L.HalfGap:L.FullPattern,m=r?[{type:"CIMGeometricEffectAddControlPoints"},{type:"CIMGeometricEffectDashes",dashTemplate:fe(t.style,null).map((e=>t.width&&t.width>0?e*t.width:e)),lineDashEnding:c,controlPointEnding:L.FullPattern}]:void 0;s.push({type:"CIMSolidStroke",capStyle:r?S.Round:S.Butt,enable:!0,width:a,color:ne(t.color),effects:m})}else!t||"line-marker"!==e.type||"cross"!==e.style&&"x"!==e.style?[i,n]=he(o):([i,n]=he(o),s.push({type:"CIMSolidStroke",enable:!0,width:t,color:ne(a)}));s.push({type:"CIMSolidFill",enable:!0,color:ne(a)});const c={type:"CIMPolygonSymbol",symbolLayers:s};return{type:"CIMPointSymbol",symbolLayers:[{type:"CIMVectorMarker",enable:!0,rotation:F(-e.angle),size:F(l||6*t),offsetX:F(e.xoffset),offsetY:F(e.yoffset),scaleSymbolsProportionally:!1,frame:i,markerGraphics:[{type:"CIMMarkerGraphic",geometry:n,symbol:c}]}]}}static fromCIMHatchFill(e,r){const o=r*(e.separation??u.CIMHatchFill.separation),a=o/2,s=t(e.lineSymbol);s.symbolLayers?.forEach((e=>{switch(e.type){case"CIMSolidStroke":null!=e.width&&(e.width*=r),e.effects?.forEach((e=>{if("CIMGeometricEffectDashes"===e.type){const t=e.dashTemplate;e.dashTemplate=t?.map((e=>e*r))}}));break;case"CIMVectorMarker":{null!=e.size&&(e.size*=r);const t=e.markerPlacement;null!=t&&"placementTemplate"in t&&(t.placementTemplate=t.placementTemplate.map((e=>e*r)));break}}}));let i=this._getLineSymbolPeriod(s)||O;for(;i<O;)i*=2;const n=i/2;return{type:"CIMVectorMarker",frame:{xmin:-n,xmax:n,ymin:-a,ymax:a},markerGraphics:[{type:"CIMMarkerGraphic",geometry:{paths:[[[-n,0],[n,0]]]},symbol:s}],size:o}}static fetchResources(e,t,r,o=null){return e&&t?(re(e,(e=>{Me(e,t,r),"url"in e&&e.url&&r.push(t.fetchResource(e.url,{signal:o}))})),r):r}static fetchFonts(e,t,r){if(e&&t)if("symbolLayers"in e&&e.symbolLayers){for(const o of e.symbolLayers)if("CIMVectorMarker"===o.type&&o.markerGraphics)for(const e of o.markerGraphics)e?.symbol&&te.fetchFonts(e.symbol,t,r)}else if("CIMTextSymbol"===e.type){const{fontFamilyName:o,fontStyleName:a}=e;if(!o||"calcitewebcoreicons"===o.toLowerCase())return;const{style:s,weight:i}=z(a),n=D(e),c=new l({family:o,style:s,weight:i,decoration:n});r.push(t.loadFont(c).catch((()=>{W().error(`Unsupported font ${o} in CIM symbol`)})))}}static _getLineSymbolPeriod(e){if(e){const t=this._getEffectsRepeat(e.effects);if(t)return t;if(e.symbolLayers)for(const r of e.symbolLayers)if(r){const e=this._getEffectsRepeat(r.effects);if(e)return e;switch(r.type){case"CIMCharacterMarker":case"CIMPictureMarker":case"CIMVectorMarker":case"CIMObjectMarker3D":case"CIMglTFMarker3D":{const e=this._getPlacementRepeat(r.markerPlacement);if(e)return e}}}}return 0}static _getEffectsRepeat(e){if(e)for(const t of e)if(t)switch(t.type){case"CIMGeometricEffectDashes":{const e=t.dashTemplate;if(e&&e.length){let t=0;for(const r of e)t+=r;return 1&e.length&&(t*=2),t}break}case"CIMGeometricEffectWave":return t.period;default:W().error(`unsupported geometric effect type ${t.type}`)}return 0}static _getPlacementRepeat(e){if(e)switch(e.type){case"CIMMarkerPlacementAlongLineSameSize":case"CIMMarkerPlacementAlongLineRandomSize":case"CIMMarkerPlacementAlongLineVariableSize":{const t=e.placementTemplate;if(t&&t.length){let e=0;for(const r of t)e+=+r;return 1&t.length&&(e*=2),e}break}}return 0}static fromCIMInsidePolygon(e){const t=e.markerPlacement,r={...e};r.markerPlacement=null,r.anchorPoint=null;const s=Math.abs(t.stepX),i=Math.abs(t.stepY),n=(t.randomness??100)/100;let l,c,m,f;if("Random"===t.gridType){const e=a(j),r=Math.max(Math.floor(e/s),1),y=Math.max(Math.floor(e/i),1);l=r*s/2,c=y*i/2,m=2*c;const h=new o(t.seed),u=n*s/1.5,M=n*i/1.5;f=[];for(let t=0;t<r;t++)for(let e=0;e<y;e++){const r=t*s-l+u*(.5-h.getFloat()),o=e*i-c+M*(.5-h.getFloat());f.push({x:r,y:o}),0===t&&f.push({x:r+2*l,y:o}),0===e&&f.push({x:r,y:o+2*c})}}else!0===t.shiftOddRows?(l=s/2,c=i,m=2*i,f=[{x:-l,y:0},{x:l,y:0},{x:0,y:c},{x:0,y:-c}]):(l=s/2,c=i/2,m=i,f=[{x:-s,y:0},{x:0,y:-i},{x:-s,y:-i},{x:0,y:0},{x:s,y:0},{x:0,y:i},{x:s,y:i},{x:-s,y:i},{x:s,y:-i}]);return{type:"CIMVectorMarker",frame:{xmin:-l,xmax:l,ymin:-c,ymax:c},markerGraphics:f.map((e=>({type:"CIMMarkerGraphic",geometry:e,symbol:{type:"CIMPointSymbol",symbolLayers:[r]}}))),size:m}}}function re(e,t){if(e)switch(e.type){case"CIMPointSymbol":case"CIMLineSymbol":case"CIMPolygonSymbol":{const r=e.symbolLayers;if(!r)return;for(const e of r)if(t(e),"CIMVectorMarker"===e.type){const r=e.markerGraphics;if(!r)continue;for(const e of r)if(e){const r=e.symbol;r&&re(r,t)}}break}}}const oe=e=>{if(!e)return S.Butt;switch(e){case"butt":return S.Butt;case"square":return S.Square;case"round":return S.Round}},ae=e=>{if(!e)return p.Miter;switch(e){case"miter":return p.Miter;case"round":return p.Round;case"bevel":return p.Bevel}},se=e=>{if(null==e)return"Center";switch(e){case"left":return"Left";case"right":return"Right";case"center":return"Center"}},ie=e=>{if(null==e)return"Center";switch(e){case"baseline":return"Baseline";case"top":return"Top";case"middle":return"Center";case"bottom":return"Bottom"}},ne=e=>{if(!e)return[0,0,0,0];const{r:t,g:r,b:o,a}=e;return[t,r,o,255*a]},le=(e,t)=>{const r=ce(t),o=me(e);return r&&o?`${r}-${o}`:`${r}${o}`},ce=e=>{if(!e)return"";switch(e.toLowerCase()){case"bold":case"bolder":return"bold"}return""},me=e=>{if(!e)return"";switch(e.toLowerCase()){case"italic":case"oblique":return"italic"}return""},fe=(e,t)=>{const r=has("safari")?.001:0,o="butt"===t;switch(e){case"dash":case"esriSLSDash":return o?[4,3]:[3,4];case"dash-dot":case"esriSLSDashDot":return o?[4,3,1,3]:[3,4,r,4];case"dot":case"esriSLSDot":return o?[1,3]:[r,4];case"long-dash":case"esriSLSLongDash":return o?[8,3]:[7,4];case"long-dash-dot":case"esriSLSLongDashDot":return o?[8,3,1,3]:[7,4,r,4];case"long-dash-dot-dot":case"esriSLSDashDotDot":return o?[8,3,1,3,1,3]:[7,4,r,4,r,4];case"short-dash":case"esriSLSShortDash":return o?[4,1]:[3,2];case"short-dash-dot":case"esriSLSShortDashDot":return o?[4,1,1,1]:[3,2,r,2];case"short-dash-dot-dot":case"esriSLSShortDashDotDot":return o?[4,1,1,1,1,1]:[3,2,r,2,r,2];case"short-dot":case"esriSLSShortDot":return o?[1,1]:[r,2];case"solid":case"esriSLSSolid":case"none":return W().error("Unexpected: style does not require rasterization"),[0,0];default:return W().error(`Tried to rasterize SLS, but found an unexpected style: ${e}!`),[0,0]}};function ye(e){return void 0!==e.symbolLayers}const he=(e,t=100)=>{const r=t/2;let o,a;const s=e;if("circle"===s||"esriSMSCircle"===s){const e=.25;let t=Math.acos(1-e/r),s=Math.ceil(N/t/4);0===s&&(s=1),t=Y/s,s*=4;const i=[];i.push([r,0]);for(let o=1;o<s;o++)i.push([r*Math.cos(o*t),-r*Math.sin(o*t)]);i.push([r,0]),o={rings:[i]},a={xmin:-r,ymin:-r,xmax:r,ymax:r}}else if("cross"===s||"esriSMSCross"===s){const e=0;o={paths:[[[e,r],[e,-r]],[[r,e],[-r,e]]]},a={xmin:-r,ymin:-r,xmax:r,ymax:r}}else if("diamond"===s||"esriSMSDiamond"===s)o={rings:[[[-r,0],[0,r],[r,0],[0,-r],[-r,0]]]},a={xmin:-r,ymin:-r,xmax:r,ymax:r};else if("square"===s||"esriSMSSquare"===s)o={rings:[[[-r,-r],[-r,r],[r,r],[r,-r],[-r,-r]]]},a={xmin:-r,ymin:-r,xmax:r,ymax:r};else if("x"===s||"esriSMSX"===s)o={paths:[[[r,r],[-r,-r]],[[r,-r],[-r,r]]]},a={xmin:-r,ymin:-r,xmax:r,ymax:r};else if("triangle"===s||"esriSMSTriangle"===s){const e=t*.5773502691896257,r=-e,s=2/3*t,i=s-t;o={rings:[[[r,i],[0,s],[e,i],[r,i]]]},a={xmin:r,ymin:i,xmax:e,ymax:s}}else"arrow"===s&&(o={rings:[[[-50,50],[50,0],[-50,-50],[-33,-20],[-33,20],[-50,50]]]},a={xmin:-r,ymin:-r,xmax:r,ymax:r});return[a,o]},ue=e=>"vertical"===e||"horizontal"===e||"cross"===e||"esriSFSCross"===e||"esriSFSVertical"===e||"esriSFSHorizontal"===e;function Me(e,t,r){if(!e.effects||null!=t.geometryEngine)return;if(t.geometryEnginePromise)return void r.push(t.geometryEnginePromise);E(e.effects)&&(t.geometryEnginePromise=T(),r.push(t.geometryEnginePromise),t.geometryEnginePromise.then((e=>t.geometryEngine=e)))}function pe(e){if(!e)return null;let t=null;const{cap:r,color:o,join:a,miterLimit:s,style:i,width:n}=e;return"solid"!==i&&"none"!==i&&"esriSLSSolid"!==i&&"esriSLSNull"!==i&&(t=[{type:"CIMGeometricEffectDashes",dashTemplate:fe(i,r),lineDashEnding:"NoConstraint",scaleDash:!0,offsetAlongLine:null}]),{type:"CIMSolidStroke",color:"esriSLSNull"!==i&&"none"!==i?ne(o):[0,0,0,0],capStyle:oe(r),joinStyle:ae(a),miterLimit:s,width:n,effects:t}}export{te as CIMSymbolHelper,ee as CIMSymbolInflatedSizeHelper,oe as capTypeToEnum,Z as getEffectsInflateSize,fe as slsDashToTemplateArray,$ as symbolToCIM};