/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../chunks/_rollupPluginBabelHelpers","../config","../core/has","../core/maybe","../core/promiseUtils","../core/urlUtils"],(function(e,r,o,t,n,s,i){"use strict";function c(e,r,o=!1,i){return new Promise(((c,u)=>{if(s.isAborted(i))return void u(a());let l=()=>{m(),u(new Error(`Unable to load ${r}`))},d=()=>{const r=e;m(),c(r)},g=()=>{if(!e)return;const r=e;m(),r.src="",u(a())};const m=()=>{t("esri-image-decode")||(e.removeEventListener("error",l),e.removeEventListener("load",d)),l=null,d=null,e=null,n.isSome(i)&&i.removeEventListener("abort",g),g=null,o&&URL.revokeObjectURL(r)};n.isSome(i)&&i.addEventListener("abort",g),t("esri-image-decode")?e.decode().then(d,l):(e.addEventListener("error",l),e.addEventListener("load",d))}))}function a(){try{return new DOMException("Aborted","AbortError")}catch{const e=new Error;return e.name="AbortError",e}}function u(e){o.request.crossOriginNoCorsDomains||(o.request.crossOriginNoCorsDomains={});const r=o.request.crossOriginNoCorsDomains;for(let o of e)o=o.toLowerCase(),/^https?:\/\//.test(o)?r[i.getOrigin(o)]=0:(r[i.getOrigin("http://"+o)]=0,r[i.getOrigin("https://"+o)]=0)}function l(e){const r=o.request.crossOriginNoCorsDomains;if(r){let o=i.getOrigin(e);if(o)return o=o.toLowerCase(),!i.hasSameOrigin(o,i.getAppUrl())&&r[o]<Date.now()-36e5}return!1}function d(e){return g.apply(this,arguments)}function g(){return(g=r._asyncToGenerator((function*(e){var r;const t=o.request.crossOriginNoCorsDomains;t&&(t[i.getOrigin(e).toLowerCase()]=Date.now());const n=i.urlToObject(e);e=n.path,"json"===(null==(r=n.query)?void 0:r.f)&&(e+="?f=json");try{yield fetch(e,{mode:"no-cors",credentials:"include"})}catch{}}))).apply(this,arguments)}e.isNoCorsRequestRequired=l,e.loadImageAsync=c,e.registerNoCorsDomains=u,e.sendNoCorsRequest=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
