/*
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","../../../../core/Handles","../../../../core/handleUtils","../../../../core/maybe","../../../../core/promiseUtils","../../glTF/DefaultLoadingContext","../../glTF/loader","./wosrLoader"],(function(e,t,o,r,n,s,i,a,l){"use strict";let c=function(){function e(){this.gltfCache=new Map,this.wosrCache=new Map,this.evictHandles=new o}var c=e.prototype;return c.loadGLTF=function(e,t,o){const r=o?`gltfPBR:${e}`:`gltf:${e}`;return this._fromCache(this.gltfCache,r,(t=>a.load(new i.DefaultLoadingContext(t.streamDataRequester),e,t,o)),t)},c.loadWOSR=function(e,t){const o=`wosr:${e}:${t.disableTextures}`;return this._fromCache(this.wosrCache,o,(t=>l.load(e,t)),t)},c.destroy=function(){this.evictHandles.destroy(),this.gltfCache.clear(),this.wosrCache.clear()},c._fromCache=function(e,t,o,r){return new Promise(((i,a)=>{if(s.isAborted(r))return void a(s.createAbortError());const l=s.onAbort(r,(()=>{this._remove(e,t),a(s.createAbortError())})),c=e.get(t);if(c)return this.evictHandles.remove(t),c.refCount++,void c.item.then(i,a);const u=new AbortController,h={...r,signal:u.signal},d={refCount:1,abortController:u,item:o(h).then((o=>(d.abortController=null,o.remove=()=>this._remove(e,t),o)))};e.set(t,d),d.item.then((e=>{n.isSome(l)&&l.remove(),i(e)}),(e=>{n.isSome(l)&&l.remove(),a(e)}))}))},c._remove=function(e,t){const o=e.get(t);o&&(o.refCount--,0===o.refCount&&this.evictHandles.add(r.timeoutHandle((()=>{e.delete(t),n.isSome(o.abortController)&&o.abortController.abort()}),h),t))},t._createClass(e,[{key:"size",get:function(){return this.wosrCache.size+this.gltfCache.size}}]),e}();const u=1e4;let h=u;const d={overrideEvictDelay:e=>(h=e,{remove(){h=u}})};e.ObjectResourceCache=c,e.test=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
