@shopware-ag/dive
Version:
Shopware Spatial Framework
2 lines (1 loc) • 2.06 kB
JavaScript
"use strict";var d=Object.defineProperty;var l=(i,e,t)=>e in i?d(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var s=(i,e,t)=>l(i,typeof e!="symbol"?e+"":e,t);require("./FileTypes-Ba65iQSJ.cjs");require("three/webgpu");require("three/examples/jsm/loaders/HDRLoader.js");require("three/tsl");const _=require("./network-error-CdDXil5g.cjs");class f{constructor(e){s(this,"_promise");s(this,"_resolve");s(this,"_arrayBuffer",null);s(this,"_size",0);s(this,"_createdAt");s(this,"_updatedAt");this._uri=e,this._promise=new Promise(t=>{this._resolve=t}),this._createdAt=new Date,this._updatedAt=new Date}get promise(){return this._promise}get size(){return this._size}get createdAt(){return this._createdAt}get updatedAt(){return this._updatedAt}get arrayBuffer(){return this._arrayBuffer}_getHeader(e,t){var r,a;return((a=(r=e.headers)==null?void 0:r.get)==null?void 0:a.call(r,t))??null}_concatChunks(e,t){const r=new Uint8Array(t);let a=0;for(const n of e)r.set(n,a),a+=n.byteLength;return r.buffer}async _readBodyWithReader(e){const t=e.body.getReader(),r=[];let a=0;try{for(;;){const o=await t.read();if(o.done)break;const u=o.value??new Uint8Array(0);r.push(u),a+=u.byteLength}}finally{t.releaseLock()}return this._concatChunks(r,a)}async load(){var t;const e=await fetch(this._uri);if(!e.ok)throw new _.NetworkError(this._uri);try{(t=e.body)!=null&&t.getReader?this._arrayBuffer=await this._readBodyWithReader(e):this._arrayBuffer=await e.arrayBuffer(),this._size+=this._arrayBuffer.byteLength,this._updatedAt=new Date}catch{throw new _.FileContentError(this._uri)}return this._resolve(this._arrayBuffer),this._arrayBuffer}}class y{constructor(){s(this,"_cache",new Map)}get(){return this._cache}create(e){const t=new f(e);return this._cache.set(e,t),t}write(e,t){this._cache.set(e,t)}read(e){return this._cache.get(e)??null}delete(...e){e.forEach(t=>{this._cache.delete(t)})}clear(){this._cache.clear()}}const h=Symbol.for("@shopware-ag/dive/assetcache"),c=globalThis;c[h]||(c[h]=new y);const w=c[h];exports.AssetCache=w;exports.Chunk=f;