/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import e from"../../request.js";import r from"../../core/Error.js";import{isAbortError as t}from"../../core/promiseUtils.js";const o=";base64,";class s{constructor(){this._resourceMap=new Map,this._inFlightResourceMap=new Map,this.geometryEngine=null}destroy(){this._inFlightResourceMap.clear(),this._resourceMap.clear()}getResource(e){return this._resourceMap.get(e)??null}async fetchResource(e,r){const t={width:0,height:0},o=this._resourceMap,s=o.get(e);if(s)return t.width=s.width,t.height=s.height,t;let c=this._inFlightResourceMap.get(e);return c||(c=i(e,r),this._inFlightResourceMap.set(e,c),c=c.then((r=>{if(this._inFlightResourceMap.delete(e),r.ok){o.set(e,r.value);const s=r.value;return t.width=s.width,t.height=s.height,t}return t})),c)}deleteResource(e){this._inFlightResourceMap.delete(e),this._resourceMap.delete(e)}}function i(s,i){if(s.includes(o)){const e=new Image;return e.src=s,e.decode().then((()=>({ok:!0,value:e}))).catch((e=>t(e)?{ok:!1,error:e}:{ok:!1,error:new r("invalid-resource",`Could not fetch requested resource at ${s}`)}))}return e(s,{responseType:"image",...i}).then((e=>({ok:!0,value:e.data}))).catch((e=>t(e)?{ok:!1,error:e}:{ok:!1,error:new r("invalid-resource",`Could not fetch requested resource at ${s}`)}))}export{s as default};