UNPKG

@shopware-ag/dive

Version:

Shopware Spatial Framework

110 lines (109 loc) 2.75 kB
var _ = Object.defineProperty; var f = (i, e, t) => e in i ? _(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t; var s = (i, e, t) => f(i, typeof e != "symbol" ? e + "" : e, t); import "./FileTypes-Ck6z0LqE.mjs"; import "three/webgpu"; import "three/examples/jsm/loaders/HDRLoader.js"; import "three/tsl"; import { N as d, F as l } from "./network-error-BONfHWQq.mjs"; class y { constructor(e) { s(this, "_promise"); s(this, "_resolve"); s(this, "_arrayBuffer", null); // metadata s(this, "_size", 0); s(this, "_createdAt"); s(this, "_updatedAt"); this._uri = e, this._promise = new Promise((t) => { this._resolve = t; }), this._createdAt = /* @__PURE__ */ new Date(), this._updatedAt = /* @__PURE__ */ 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 h of e) r.set(h, a), a += h.byteLength; return r.buffer; } async _readBodyWithReader(e) { const t = e.body.getReader(), r = []; let a = 0; try { for (; ; ) { const c = await t.read(); if (c.done) break; const u = c.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 d(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 = /* @__PURE__ */ new Date(); } catch { throw new l(this._uri); } return this._resolve(this._arrayBuffer), this._arrayBuffer; } } class w { constructor() { s(this, "_cache", /* @__PURE__ */ new Map()); } get() { return this._cache; } create(e) { const t = new y(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 n = Symbol.for("@shopware-ag/dive/assetcache"), o = globalThis; o[n] || (o[n] = new w()); const k = o[n]; export { k as A, y as C };