/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{getAssetUrl as t}from"../../assets.js";import e from"../../Color.js";import o from"../../request.js";import{LRUCache as s}from"../../core/LRUCache.js";import{pt2px as r}from"../../core/screenUtils.js";import{getCIMSymbolColor as n}from"./cimSymbolUtils.js";const i="picture-fill",l="simple-fill",a="simple-line",c="simple-marker",h="text",d="cim",m=new Map([["dash",[4,3]],["dashdot",[4,3,1,3]],["dot",[1,3]],["longdash",[8,3]],["longdashdot",[8,3,1,3]],["longdashdotdot",[8,3,1,3,1,3]],["shortdash",[4,1]],["shortdashdot",[4,1,1,1]],["shortdashdotdot",[4,1,1,1,1,1]],["shortdot",[1,1]],["solid",[]]]),p=new s(1e3);function u(e){const o=e.style;let s=null;if(e)switch(e.type){case c:"cross"!==o&&"x"!==o&&(s=e.color);break;case l:o&&"solid"!==o?"none"!==o&&(s={type:"pattern",x:0,y:0,src:t(`esri/symbols/patterns/${o}.png`),width:5,height:5}):s=e.color;break;case i:s={type:"pattern",src:e.url,width:r(e.width)*e.xscale,height:r(e.height)*e.yscale,x:r(e.xoffset),y:r(e.yoffset)};break;case h:s=e.color;break;case d:s=n(e)}return s}function f(t,e){const s=t+"-"+e,r=p.get(s);return null!=r?Promise.resolve(r):o(t,{responseType:"image"}).then(t=>{const o=t.data,r=o.naturalWidth,n=o.naturalHeight,i=document.createElement("canvas");i.width=r,i.height=n;const l=i.getContext("2d");l.fillStyle=e,l.fillRect(0,0,r,n),l.globalCompositeOperation="destination-in",l.drawImage(o,0,0);const a=i.toDataURL();return p.put(s,a),a})}function y(t){if(!t)return null;let e=null;switch(t.type){case l:case i:case c:e=y(t.outline);break;case a:{const o=r(t.width);null!=t.style&&"none"!==t.style&&0!==o&&(e={color:t.color,style:w(t.style),width:o,cap:t.cap,join:"miter"===t.join?r(t.miterLimit):t.join},e.dashArray=g(e).join(",")||"none");break}default:e=null}return e}function g(t){if(!t?.style)return[];const{dashArray:e,style:o,width:s}=t;if("string"==typeof e&&"none"!==e)return e.split(",").map(t=>Number(t));const r=s??0,n=m.has(o)?m.get(o).map(t=>t*r):[];if("butt"!==t.cap)for(const[i,l]of n.entries())n[i]=i%2==1?l+r:Math.max(l-r,1);return n}const w=(()=>{const t={};return e=>{if(t[e])return t[e];const o=e.replaceAll("-","");return t[e]=o,o}})(),b=new e([128,128,128]);export{b as defaultThematicColor,w as dekebabifyLineStyle,g as getDashArray,u as getFill,f as getPatternUrlWithColor,y as getStroke};
