u-space 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,405 @@
1
+ const x = "u-space-model-loader-cache", _ = `${x}-v2`, L = `${x}-metadata-v2`, k = "__u_space_cache_variant", A = "x-u-space-cache-stored-at", C = Object.freeze({
2
+ maxAgeMs: 10080 * 60 * 1e3,
3
+ maxEntries: 64,
4
+ maxBytes: 512 * 1024 * 1024
5
+ });
6
+ let T = !1;
7
+ function w(t) {
8
+ if (t?.aborted)
9
+ throw t.reason ?? new DOMException("Aborted", "AbortError");
10
+ }
11
+ function E() {
12
+ return typeof caches < "u";
13
+ }
14
+ function R(t) {
15
+ return !t.startsWith("data:") && !t.startsWith("blob:");
16
+ }
17
+ function z(t) {
18
+ return {
19
+ maxAgeMs: Math.max(0, t?.maxAgeMs ?? C.maxAgeMs),
20
+ maxEntries: Math.max(0, Math.floor(t?.maxEntries ?? C.maxEntries)),
21
+ maxBytes: Math.max(0, t?.maxBytes ?? C.maxBytes)
22
+ };
23
+ }
24
+ function I(t) {
25
+ return typeof location < "u" ? new URL(t, location.href).href : new URL(t).href;
26
+ }
27
+ async function j(t) {
28
+ if (globalThis.crypto?.subtle) {
29
+ const r = await globalThis.crypto.subtle.digest(
30
+ "SHA-256",
31
+ new TextEncoder().encode(t)
32
+ );
33
+ return Array.from(
34
+ new Uint8Array(r),
35
+ (s) => s.toString(16).padStart(2, "0")
36
+ ).join("");
37
+ }
38
+ let e = 2166136261;
39
+ for (let r = 0; r < t.length; r++)
40
+ e ^= t.charCodeAt(r), e = Math.imul(e, 16777619);
41
+ return (e >>> 0).toString(16).padStart(8, "0");
42
+ }
43
+ async function P(t, e, r = "same-origin", s) {
44
+ const n = I(t), c = new Headers(e), d = Array.from(c.entries()).map(([o, f]) => [o.toLowerCase(), f]).sort(([o], [f]) => o.localeCompare(f));
45
+ if (d.length === 0 && r === "same-origin" && s === void 0)
46
+ return n;
47
+ const i = await j(JSON.stringify([r, d, s])), a = new URL(n);
48
+ return a.searchParams.set(k, i), a.href;
49
+ }
50
+ function N(t, e, r) {
51
+ const s = new Headers(t);
52
+ return s.delete("content-encoding"), s.delete("transfer-encoding"), s.set("content-length", String(e)), r !== void 0 && s.set(A, String(r)), s;
53
+ }
54
+ function G(t, e, r, s, n) {
55
+ return new Response(t.slice(0), {
56
+ headers: N(e, t.byteLength, n),
57
+ status: r,
58
+ statusText: s
59
+ });
60
+ }
61
+ function g(t, e, r, s, n, c) {
62
+ return {
63
+ url: t,
64
+ buffer: e,
65
+ headers: N(r, e.byteLength),
66
+ status: s,
67
+ statusText: n,
68
+ fromCache: c
69
+ };
70
+ }
71
+ function O(t) {
72
+ return new Set(
73
+ (t.get("cache-control") ?? "").toLowerCase().split(",").map((e) => e.trim()).filter(Boolean)
74
+ );
75
+ }
76
+ function W(t) {
77
+ if (t.status !== 200) return !1;
78
+ const e = O(t.headers);
79
+ if (e.has("no-store") || e.has("private")) return !1;
80
+ const r = (t.headers.get("vary") ?? "").toLowerCase().split(",").map((s) => s.trim());
81
+ return !r.includes("*") && !r.includes("cookie");
82
+ }
83
+ function X(t, e) {
84
+ const r = O(t);
85
+ if (r.has("no-cache")) return 0;
86
+ for (const c of r) {
87
+ const d = /^max-age=(\d+)$/.exec(c);
88
+ if (d) return Math.min(Number(d[1]) * 1e3, e.maxAgeMs);
89
+ }
90
+ const s = Date.parse(t.get("expires") ?? ""), n = Date.parse(t.get("date") ?? "");
91
+ return Number.isFinite(s) && Number.isFinite(n) ? Math.min(Math.max(0, s - n), e.maxAgeMs) : e.maxAgeMs;
92
+ }
93
+ function J(t, e) {
94
+ const r = new Headers(t), s = e.headers.get("etag"), n = e.headers.get("last-modified");
95
+ return s && r.set("if-none-match", s), n && r.set("if-modified-since", n), r;
96
+ }
97
+ function K(t, e) {
98
+ const r = new Headers(t);
99
+ return e.forEach((s, n) => r.set(n, s)), r;
100
+ }
101
+ async function V() {
102
+ if (!(T || !E())) {
103
+ T = !0;
104
+ try {
105
+ const t = await caches.keys();
106
+ await Promise.all(
107
+ t.filter((e) => e.startsWith(x) && e !== _ && e !== L).map((e) => caches.delete(e))
108
+ );
109
+ } catch (t) {
110
+ console.warn("[ModelPersistentCache] Failed to remove legacy caches:", t);
111
+ }
112
+ }
113
+ }
114
+ async function S(t, e) {
115
+ try {
116
+ const r = await t.match(e);
117
+ if (!r) return null;
118
+ const s = await r.json();
119
+ return !Number.isFinite(s.size) || !Number.isFinite(s.storedAt) || !Number.isFinite(s.lastAccess) ? null : s;
120
+ } catch {
121
+ return null;
122
+ }
123
+ }
124
+ async function b(t, e, r) {
125
+ await t.put(e, new Response(JSON.stringify(r), {
126
+ headers: { "content-type": "application/json" }
127
+ }));
128
+ }
129
+ async function M(t, e, r) {
130
+ await Promise.all([t.delete(r), e.delete(r)]);
131
+ }
132
+ async function Y(t, e, r) {
133
+ const s = await t.keys(), n = await Promise.all(s.map(async (i) => {
134
+ const a = await S(e, i.url);
135
+ if (a) return { request: i, metadata: a };
136
+ const o = await t.match(i), f = Number(o?.headers.get("content-length")) || 0, l = Number(o?.headers.get(A)) || 0;
137
+ return {
138
+ request: i,
139
+ metadata: { size: f, storedAt: l, lastAccess: l }
140
+ };
141
+ }));
142
+ n.sort((i, a) => i.metadata.lastAccess - a.metadata.lastAccess);
143
+ let c = n.reduce((i, a) => i + a.metadata.size, 0), d = n.length;
144
+ for (const i of n) {
145
+ if (d <= r.maxEntries && c <= r.maxBytes) break;
146
+ await M(t, e, i.request.url), d--, c -= i.metadata.size;
147
+ }
148
+ }
149
+ async function U() {
150
+ return await V(), Promise.all([
151
+ caches.open(_),
152
+ caches.open(L)
153
+ ]);
154
+ }
155
+ async function p(t, e, r, s, n, c) {
156
+ if (s.buffer.byteLength === 0 || n.maxEntries === 0 || s.buffer.byteLength > n.maxBytes) return;
157
+ const d = G(
158
+ s.buffer,
159
+ s.headers,
160
+ s.status,
161
+ s.statusText,
162
+ c
163
+ );
164
+ await t.put(r, d), await b(e, r, {
165
+ size: s.buffer.byteLength,
166
+ storedAt: c,
167
+ lastAccess: c
168
+ }), await Y(t, e, n);
169
+ }
170
+ async function $(t, e, r) {
171
+ const s = await fetch(t, {
172
+ headers: r,
173
+ credentials: e.credentials ?? "same-origin",
174
+ signal: e.signal
175
+ });
176
+ if (!s.ok)
177
+ throw new Error(
178
+ `Failed to load model resource ${t}: ${s.status} ${s.statusText}`
179
+ );
180
+ const n = await s.arrayBuffer();
181
+ return w(e.signal), g(
182
+ t,
183
+ n,
184
+ s.headers,
185
+ s.status,
186
+ s.statusText,
187
+ !1
188
+ );
189
+ }
190
+ async function q(t, e = {}) {
191
+ w(e.signal);
192
+ const r = e.cacheMode;
193
+ if (!(e.persistent !== !1 && r !== "no-store") || !E() || !R(t))
194
+ return $(t, e, e.headers);
195
+ const n = z(e.policy), c = await P(t, e.headers, e.credentials, e.cacheKey);
196
+ let d, i;
197
+ try {
198
+ [d, i] = await U();
199
+ } catch (h) {
200
+ return w(e.signal), console.warn(`[ModelPersistentCache] Cache Storage is unavailable for ${t}:`, h), $(t, e, e.headers);
201
+ }
202
+ let a;
203
+ try {
204
+ a = await d.match(c);
205
+ } catch (h) {
206
+ w(e.signal), console.warn(`[ModelPersistentCache] Failed to read ${t}:`, h);
207
+ }
208
+ let o, f = await S(i, c);
209
+ if (a) {
210
+ try {
211
+ o = await a.clone().arrayBuffer();
212
+ } catch {
213
+ o = new ArrayBuffer(0);
214
+ }
215
+ if (w(e.signal), o.byteLength === 0) {
216
+ try {
217
+ await M(d, i, c);
218
+ } catch (h) {
219
+ console.warn(`[ModelPersistentCache] Failed to delete corrupt ${t}:`, h);
220
+ }
221
+ a = void 0, o = void 0, f = null;
222
+ }
223
+ }
224
+ const l = Date.now();
225
+ if (a && o) {
226
+ const h = f?.storedAt ?? (Number(a.headers.get(A)) || 0), m = l - h, y = m >= 0 && m < X(a.headers, n);
227
+ if (r === "force-cache" || y && r !== "reload" && r !== "revalidate") {
228
+ try {
229
+ await b(i, c, {
230
+ size: o.byteLength,
231
+ storedAt: h,
232
+ lastAccess: l
233
+ });
234
+ } catch (B) {
235
+ console.warn(`[ModelPersistentCache] Failed to update access time for ${t}:`, B);
236
+ }
237
+ return g(
238
+ t,
239
+ o,
240
+ a.headers,
241
+ a.status,
242
+ a.statusText,
243
+ !0
244
+ );
245
+ }
246
+ }
247
+ let u;
248
+ try {
249
+ u = await fetch(t, {
250
+ headers: a && r !== "reload" ? J(e.headers, a) : e.headers,
251
+ credentials: e.credentials ?? "same-origin",
252
+ signal: e.signal
253
+ });
254
+ } catch (h) {
255
+ if (w(e.signal), a && o) {
256
+ const m = f?.storedAt ?? (Number(a.headers.get(A)) || 0);
257
+ try {
258
+ await b(i, c, {
259
+ size: o.byteLength,
260
+ storedAt: m,
261
+ lastAccess: l
262
+ });
263
+ } catch (y) {
264
+ console.warn(`[ModelPersistentCache] Failed to update access time for ${t}:`, y);
265
+ }
266
+ return g(
267
+ t,
268
+ o,
269
+ a.headers,
270
+ a.status,
271
+ a.statusText,
272
+ !0
273
+ );
274
+ }
275
+ throw h;
276
+ }
277
+ if (u.status === 304 && a && o) {
278
+ const h = K(a.headers, u.headers), m = g(
279
+ t,
280
+ o,
281
+ h,
282
+ a.status,
283
+ a.statusText,
284
+ !0
285
+ );
286
+ try {
287
+ await p(d, i, c, m, n, l);
288
+ } catch (y) {
289
+ console.warn(`[ModelPersistentCache] Failed to store revalidated ${t}:`, y);
290
+ }
291
+ return m;
292
+ }
293
+ if (!u.ok) {
294
+ if (a && o && u.status >= 500)
295
+ return g(
296
+ t,
297
+ o,
298
+ a.headers,
299
+ a.status,
300
+ a.statusText,
301
+ !0
302
+ );
303
+ throw new Error(
304
+ `Failed to load model resource ${t}: ${u.status} ${u.statusText}`
305
+ );
306
+ }
307
+ const H = await u.arrayBuffer();
308
+ w(e.signal);
309
+ const D = g(
310
+ t,
311
+ H,
312
+ u.headers,
313
+ u.status,
314
+ u.statusText,
315
+ !1
316
+ );
317
+ if (W(u))
318
+ try {
319
+ await p(d, i, c, D, n, l);
320
+ } catch (h) {
321
+ w(e.signal), console.warn(`[ModelPersistentCache] Failed to cache ${t}:`, h);
322
+ }
323
+ else if (a)
324
+ try {
325
+ await M(d, i, c);
326
+ } catch (h) {
327
+ console.warn(`[ModelPersistentCache] Failed to remove uncacheable ${t}:`, h);
328
+ }
329
+ return D;
330
+ }
331
+ async function Q(t, e = {}) {
332
+ if (!E() || !R(t)) return;
333
+ const r = await P(t, e.headers, e.credentials, e.cacheKey), [s, n] = await U();
334
+ await M(s, n, r);
335
+ }
336
+ async function Z() {
337
+ if (!E()) return;
338
+ const t = await caches.keys();
339
+ await Promise.all(
340
+ t.filter((e) => e.startsWith(x)).map((e) => caches.delete(e))
341
+ );
342
+ }
343
+ function ee() {
344
+ return E();
345
+ }
346
+ const te = 3, v = 1e5, F = 512;
347
+ function ae(t) {
348
+ const e = t.nodes ?? [];
349
+ if (e.length > v)
350
+ throw new Error(
351
+ `Decoded glTF contains ${e.length} nodes; the safe limit is ${v}.`
352
+ );
353
+ const r = new Uint8Array(e.length);
354
+ for (let a = 0; a < e.length; a++) {
355
+ const o = e[a].children ?? [], f = /* @__PURE__ */ new Set();
356
+ for (const l of o) {
357
+ if (!Number.isInteger(l) || l < 0 || l >= e.length)
358
+ throw new Error(`Decoded glTF node ${a} references invalid child ${l}.`);
359
+ if (f.has(l))
360
+ throw new Error(`Decoded glTF node ${a} repeats child ${l}.`);
361
+ if (f.add(l), r[l]++, r[l] > 1)
362
+ throw new Error(`Decoded glTF node ${l} has multiple parents.`);
363
+ }
364
+ }
365
+ const s = new Uint8Array(e.length), n = (a, o) => {
366
+ if (o > F)
367
+ throw new Error(
368
+ `Decoded glTF node graph exceeds the safe depth of ${F}.`
369
+ );
370
+ if (s[a] === 1)
371
+ throw new Error(`Decoded glTF node graph contains a cycle at ${a}.`);
372
+ if (s[a] !== 2) {
373
+ s[a] = 1;
374
+ for (const f of e[a].children ?? []) n(f, o + 1);
375
+ s[a] = 2;
376
+ }
377
+ };
378
+ for (let a = 0; a < e.length; a++) n(a, 1);
379
+ const c = t.scene ?? 0, d = t.scenes?.[c];
380
+ if (!d) throw new Error(`Decoded glTF references missing scene ${c}.`);
381
+ const i = /* @__PURE__ */ new Set();
382
+ for (const a of d.nodes ?? []) {
383
+ if (!Number.isInteger(a) || a < 0 || a >= e.length)
384
+ throw new Error(`Decoded glTF scene ${c} references invalid node ${a}.`);
385
+ if (i.has(a))
386
+ throw new Error(`Decoded glTF scene ${c} repeats root node ${a}.`);
387
+ if (i.add(a), r[a] > 0)
388
+ throw new Error(`Decoded glTF scene root ${a} is also referenced as a child.`);
389
+ }
390
+ }
391
+ class re extends Error {
392
+ name = "UnsupportedModelDecodeError";
393
+ constructor(e) {
394
+ super(e);
395
+ }
396
+ }
397
+ export {
398
+ te as M,
399
+ re as U,
400
+ Z as c,
401
+ Q as d,
402
+ q as l,
403
+ ee as m,
404
+ ae as v
405
+ };
@@ -0,0 +1 @@
1
+ "use strict";const C="u-space-model-loader-cache",F=`${C}-v2`,R=`${C}-metadata-v2`,k="__u_space_cache_variant",A="x-u-space-cache-stored-at",x=Object.freeze({maxAgeMs:10080*60*1e3,maxEntries:64,maxBytes:512*1024*1024});let p=!1;function w(t){if(t?.aborted)throw t.reason??new DOMException("Aborted","AbortError")}function E(){return typeof caches<"u"}function L(t){return!t.startsWith("data:")&&!t.startsWith("blob:")}function I(t){return{maxAgeMs:Math.max(0,t?.maxAgeMs??x.maxAgeMs),maxEntries:Math.max(0,Math.floor(t?.maxEntries??x.maxEntries)),maxBytes:Math.max(0,t?.maxBytes??x.maxBytes)}}function z(t){return typeof location<"u"?new URL(t,location.href).href:new URL(t).href}async function G(t){if(globalThis.crypto?.subtle){const r=await globalThis.crypto.subtle.digest("SHA-256",new TextEncoder().encode(t));return Array.from(new Uint8Array(r),s=>s.toString(16).padStart(2,"0")).join("")}let e=2166136261;for(let r=0;r<t.length;r++)e^=t.charCodeAt(r),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}async function O(t,e,r="same-origin",s){const n=z(t),c=new Headers(e),d=Array.from(c.entries()).map(([o,f])=>[o.toLowerCase(),f]).sort(([o],[f])=>o.localeCompare(f));if(d.length===0&&r==="same-origin"&&s===void 0)return n;const i=await G(JSON.stringify([r,d,s])),a=new URL(n);return a.searchParams.set(k,i),a.href}function P(t,e,r){const s=new Headers(t);return s.delete("content-encoding"),s.delete("transfer-encoding"),s.set("content-length",String(e)),r!==void 0&&s.set(A,String(r)),s}function j(t,e,r,s,n){return new Response(t.slice(0),{headers:P(e,t.byteLength,n),status:r,statusText:s})}function g(t,e,r,s,n,c){return{url:t,buffer:e,headers:P(r,e.byteLength),status:s,statusText:n,fromCache:c}}function N(t){return new Set((t.get("cache-control")??"").toLowerCase().split(",").map(e=>e.trim()).filter(Boolean))}function W(t){if(t.status!==200)return!1;const e=N(t.headers);if(e.has("no-store")||e.has("private"))return!1;const r=(t.headers.get("vary")??"").toLowerCase().split(",").map(s=>s.trim());return!r.includes("*")&&!r.includes("cookie")}function V(t,e){const r=N(t);if(r.has("no-cache"))return 0;for(const c of r){const d=/^max-age=(\d+)$/.exec(c);if(d)return Math.min(Number(d[1])*1e3,e.maxAgeMs)}const s=Date.parse(t.get("expires")??""),n=Date.parse(t.get("date")??"");return Number.isFinite(s)&&Number.isFinite(n)?Math.min(Math.max(0,s-n),e.maxAgeMs):e.maxAgeMs}function X(t,e){const r=new Headers(t),s=e.headers.get("etag"),n=e.headers.get("last-modified");return s&&r.set("if-none-match",s),n&&r.set("if-modified-since",n),r}function J(t,e){const r=new Headers(t);return e.forEach((s,n)=>r.set(n,s)),r}async function K(){if(!(p||!E())){p=!0;try{const t=await caches.keys();await Promise.all(t.filter(e=>e.startsWith(C)&&e!==F&&e!==R).map(e=>caches.delete(e)))}catch(t){console.warn("[ModelPersistentCache] Failed to remove legacy caches:",t)}}}async function S(t,e){try{const r=await t.match(e);if(!r)return null;const s=await r.json();return!Number.isFinite(s.size)||!Number.isFinite(s.storedAt)||!Number.isFinite(s.lastAccess)?null:s}catch{return null}}async function b(t,e,r){await t.put(e,new Response(JSON.stringify(r),{headers:{"content-type":"application/json"}}))}async function M(t,e,r){await Promise.all([t.delete(r),e.delete(r)])}async function Y(t,e,r){const s=await t.keys(),n=await Promise.all(s.map(async i=>{const a=await S(e,i.url);if(a)return{request:i,metadata:a};const o=await t.match(i),f=Number(o?.headers.get("content-length"))||0,l=Number(o?.headers.get(A))||0;return{request:i,metadata:{size:f,storedAt:l,lastAccess:l}}}));n.sort((i,a)=>i.metadata.lastAccess-a.metadata.lastAccess);let c=n.reduce((i,a)=>i+a.metadata.size,0),d=n.length;for(const i of n){if(d<=r.maxEntries&&c<=r.maxBytes)break;await M(t,e,i.request.url),d--,c-=i.metadata.size}}async function U(){return await K(),Promise.all([caches.open(F),caches.open(R)])}async function T(t,e,r,s,n,c){if(s.buffer.byteLength===0||n.maxEntries===0||s.buffer.byteLength>n.maxBytes)return;const d=j(s.buffer,s.headers,s.status,s.statusText,c);await t.put(r,d),await b(e,r,{size:s.buffer.byteLength,storedAt:c,lastAccess:c}),await Y(t,e,n)}async function _(t,e,r){const s=await fetch(t,{headers:r,credentials:e.credentials??"same-origin",signal:e.signal});if(!s.ok)throw new Error(`Failed to load model resource ${t}: ${s.status} ${s.statusText}`);const n=await s.arrayBuffer();return w(e.signal),g(t,n,s.headers,s.status,s.statusText,!1)}async function q(t,e={}){w(e.signal);const r=e.cacheMode;if(!(e.persistent!==!1&&r!=="no-store")||!E()||!L(t))return _(t,e,e.headers);const n=I(e.policy),c=await O(t,e.headers,e.credentials,e.cacheKey);let d,i;try{[d,i]=await U()}catch(h){return w(e.signal),console.warn(`[ModelPersistentCache] Cache Storage is unavailable for ${t}:`,h),_(t,e,e.headers)}let a;try{a=await d.match(c)}catch(h){w(e.signal),console.warn(`[ModelPersistentCache] Failed to read ${t}:`,h)}let o,f=await S(i,c);if(a){try{o=await a.clone().arrayBuffer()}catch{o=new ArrayBuffer(0)}if(w(e.signal),o.byteLength===0){try{await M(d,i,c)}catch(h){console.warn(`[ModelPersistentCache] Failed to delete corrupt ${t}:`,h)}a=void 0,o=void 0,f=null}}const l=Date.now();if(a&&o){const h=f?.storedAt??(Number(a.headers.get(A))||0),m=l-h,y=m>=0&&m<V(a.headers,n);if(r==="force-cache"||y&&r!=="reload"&&r!=="revalidate"){try{await b(i,c,{size:o.byteLength,storedAt:h,lastAccess:l})}catch(B){console.warn(`[ModelPersistentCache] Failed to update access time for ${t}:`,B)}return g(t,o,a.headers,a.status,a.statusText,!0)}}let u;try{u=await fetch(t,{headers:a&&r!=="reload"?X(e.headers,a):e.headers,credentials:e.credentials??"same-origin",signal:e.signal})}catch(h){if(w(e.signal),a&&o){const m=f?.storedAt??(Number(a.headers.get(A))||0);try{await b(i,c,{size:o.byteLength,storedAt:m,lastAccess:l})}catch(y){console.warn(`[ModelPersistentCache] Failed to update access time for ${t}:`,y)}return g(t,o,a.headers,a.status,a.statusText,!0)}throw h}if(u.status===304&&a&&o){const h=J(a.headers,u.headers),m=g(t,o,h,a.status,a.statusText,!0);try{await T(d,i,c,m,n,l)}catch(y){console.warn(`[ModelPersistentCache] Failed to store revalidated ${t}:`,y)}return m}if(!u.ok){if(a&&o&&u.status>=500)return g(t,o,a.headers,a.status,a.statusText,!0);throw new Error(`Failed to load model resource ${t}: ${u.status} ${u.statusText}`)}const H=await u.arrayBuffer();w(e.signal);const D=g(t,H,u.headers,u.status,u.statusText,!1);if(W(u))try{await T(d,i,c,D,n,l)}catch(h){w(e.signal),console.warn(`[ModelPersistentCache] Failed to cache ${t}:`,h)}else if(a)try{await M(d,i,c)}catch(h){console.warn(`[ModelPersistentCache] Failed to remove uncacheable ${t}:`,h)}return D}async function Q(t,e={}){if(!E()||!L(t))return;const r=await O(t,e.headers,e.credentials,e.cacheKey),[s,n]=await U();await M(s,n,r)}async function Z(){if(!E())return;const t=await caches.keys();await Promise.all(t.filter(e=>e.startsWith(C)).map(e=>caches.delete(e)))}function ee(){return E()}const te=3,$=1e5,v=512;function ae(t){const e=t.nodes??[];if(e.length>$)throw new Error(`Decoded glTF contains ${e.length} nodes; the safe limit is ${$}.`);const r=new Uint8Array(e.length);for(let a=0;a<e.length;a++){const o=e[a].children??[],f=new Set;for(const l of o){if(!Number.isInteger(l)||l<0||l>=e.length)throw new Error(`Decoded glTF node ${a} references invalid child ${l}.`);if(f.has(l))throw new Error(`Decoded glTF node ${a} repeats child ${l}.`);if(f.add(l),r[l]++,r[l]>1)throw new Error(`Decoded glTF node ${l} has multiple parents.`)}}const s=new Uint8Array(e.length),n=(a,o)=>{if(o>v)throw new Error(`Decoded glTF node graph exceeds the safe depth of ${v}.`);if(s[a]===1)throw new Error(`Decoded glTF node graph contains a cycle at ${a}.`);if(s[a]!==2){s[a]=1;for(const f of e[a].children??[])n(f,o+1);s[a]=2}};for(let a=0;a<e.length;a++)n(a,1);const c=t.scene??0,d=t.scenes?.[c];if(!d)throw new Error(`Decoded glTF references missing scene ${c}.`);const i=new Set;for(const a of d.nodes??[]){if(!Number.isInteger(a)||a<0||a>=e.length)throw new Error(`Decoded glTF scene ${c} references invalid node ${a}.`);if(i.has(a))throw new Error(`Decoded glTF scene ${c} repeats root node ${a}.`);if(i.add(a),r[a]>0)throw new Error(`Decoded glTF scene root ${a} is also referenced as a child.`)}}class re extends Error{name="UnsupportedModelDecodeError";constructor(e){super(e)}}exports.MODEL_DECODE_PROTOCOL_VERSION=te;exports.UnsupportedModelDecodeError=re;exports.clearModelPersistentCache=Z;exports.deleteModelResourceCache=Q;exports.loadModelResource=q;exports.modelPersistentCacheAvailable=ee;exports.validateDecodedGltfNodeGraph=ae;