import e from"@babel/runtime/helpers/defineProperty";import t from"lz-string";import r from"lodash/debounce";import{formatBytesToKB as n}from"../cache-utils/formatBytes.js";import{scheduleIdleWork as o}from"../cache-utils/idle-callback.js";import{DEBOUNCE_DELAY as i,CACHE_VERSION as s,CACHE_SCHEMA as a,STORAGE_KEY as c}from"./constants.js";import{validateEnvelope as f}from"./validateEnvelope.js";function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}var p=function(t){var r={},n=Date.now();try{var o=sessionStorage.getItem(c);if(o){var i=JSON.parse(o),s=f(i);s&&(r=s.state,n=s.timestamp)}}catch(e){}var a=function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?m(Object(n),!0).forEach((function(r){e(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}({},r),p=n;return t.forEach((function(e,t){a[t]=e.wellIds,e.timestamp>p&&(p=e.timestamp)})),{mergedState:a,latestTimestamp:p}},l=function(e){return r((function(){var r=e.pendingWritesRef.current;if(0!==r.size){var i=new Map(r),f=o((function(){e.idleHandlesRef.current.delete(f);try{var r=p(i),o=r.mergedState,m=r.latestTimestamp,l=JSON.stringify(o),u={version:s,timestamp:m,schema:a,compression:"lz-utf16",count:Object.keys(o).length,sizeKB:n(l.length),state:t.compressToUTF16(l)};sessionStorage.setItem(c,JSON.stringify(u))}finally{i.forEach((function(t,r){e.pendingWritesRef.current.delete(r)}))}}),{timeout:5e3});e.idleHandlesRef.current.add(f)}}),i)};export{l as createTileCacheFlusher};
//# sourceMappingURL=createTileCacheFlusher.js.map
