@vincentt-xr/sdk 2.0.0-alpha.21 → 2.0.0-alpha.22

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.
Files changed (61) hide show
  1. package/components.json +1 -1
  2. package/dist/{CanonicalHeadFrame-CQe2YX9a.js → CanonicalHeadFrame-S3Jk9F1P.js} +15 -15
  3. package/dist/{DebuggerUI-CKYrYmod.js → DebuggerUI-B8bheFk-.js} +1 -1
  4. package/dist/{FaceRetouch-l7y4oZBu.js → FaceRetouch-DW_9g5EA.js} +4 -4
  5. package/dist/{bodyMaskMaterial-BOdSJUEM.js → bodyMaskMaterial-CUlzyXnJ.js} +1 -1
  6. package/dist/cache-CsH3zPDX.js +307 -0
  7. package/dist/cache-DrEDi7qn.cjs +1 -0
  8. package/dist/components/Button/index.d.ts +1 -1
  9. package/dist/components/FaceSwap/settings.d.ts +1 -1
  10. package/dist/components/Light/index.d.ts +1 -1
  11. package/dist/components/Model/index.d.ts +1 -1
  12. package/dist/components/Object3D/index.d.ts +1 -1
  13. package/dist/components/PaintedFace/index.d.ts +1 -1
  14. package/dist/components/ScreenText/liveEditable.d.ts +1 -1
  15. package/dist/{contexts-Cl-4dUOI.js → contexts-C_l5hzI8.js} +52 -52
  16. package/dist/debug-ui/media-source.js +1 -1
  17. package/dist/debug-ui.cjs +1 -1
  18. package/dist/debug-ui.js +11 -11
  19. package/dist/{drawNormalizedCrop-D606u5-F.js → drawNormalizedCrop-D48Layv4.js} +14 -14
  20. package/dist/editor-defs/live.d.ts +18 -0
  21. package/dist/editor-defs/live.generated.d.ts +2 -0
  22. package/dist/face-effects.cjs +31 -31
  23. package/dist/face-effects.js +1287 -1287
  24. package/dist/{getFaceInfo-Mt44zlej.js → getFaceInfo-e9XzHPLC.js} +1 -1
  25. package/dist/{index-CicO_Tnw.js → index-B34w-TyW.js} +1 -1
  26. package/dist/{index-D5NbXaCn.js → index-B9ph9k5I.js} +4 -4
  27. package/dist/{index-Bn72laBn.js → index-BKZPBg1D.js} +1 -1
  28. package/dist/{index-CM3jkleV.js → index-DCjFgbB8.js} +12 -10
  29. package/dist/{index-fDwL47CM.cjs → index-DSMv6GWI.cjs} +1 -1
  30. package/dist/{index-CbBCl2ZU.js → index-Dk1UOe-H.js} +10 -10
  31. package/dist/{index-BDxJWWyy.js → index-MzlPbe9t.js} +9 -9
  32. package/dist/{index-B0EYdofX.js → index-em1AaMkI.js} +1 -1
  33. package/dist/instructions.js +7 -7
  34. package/dist/{internal-BoFDq5hC.js → internal-kwJxojDs.js} +3 -3
  35. package/dist/internal.js +2 -2
  36. package/dist/{landmarks-C3LvDhMt.js → landmarks-BgLF-yfd.js} +6 -6
  37. package/dist/low-level.js +17 -17
  38. package/dist/main.cjs +1 -1
  39. package/dist/main.js +720 -719
  40. package/dist/particles.js +5 -5
  41. package/dist/product.js +2 -2
  42. package/dist/{providers-Bxt_MfPK.js → providers-Bo1gfoXg.js} +3 -3
  43. package/dist/{renderGroups-uYPzUa66.js → renderGroups-Cul4eOG8.js} +1 -1
  44. package/dist/{renderPasses-C0wu5Cwg.js → renderPasses-CLOTeP38.js} +40 -40
  45. package/dist/scene-object.js +2 -2
  46. package/dist/{segmentation-DccvYBBO.js → segmentation-Q1eXSt_x.js} +1 -1
  47. package/dist/{selectors-J06V0eDb.js → selectors-CiawE6Ox.js} +4 -4
  48. package/dist/{session-CYiWfcvz.js → session-CmpigDxI.js} +9 -9
  49. package/dist/tracking.js +127 -127
  50. package/dist/{trigger-CQviD4xp.js → trigger-BHKfnvtB.js} +7 -7
  51. package/dist/{useBodies-DOuwRuew.js → useBodies-DzRzQg88.js} +7 -7
  52. package/dist/{useFaceInfo-XUGYTdfN.js → useFaceInfo-DUxqnPek.js} +10 -10
  53. package/dist/{useFaceResultReader-D8wXbF1L.js → useFaceResultReader-DSnUjQcw.js} +1 -1
  54. package/dist/{useIrisTracking-B0uLWgNE.js → useIrisTracking-Bfp1Fv66.js} +10 -10
  55. package/dist/{useXRCapabilities-DPUOvpdf.js → useXRCapabilities-BhN_CKwJ.js} +1 -1
  56. package/dist/utils/useEditOverrides.d.ts +4 -0
  57. package/dist/utils/useLiveProps.d.ts +8 -0
  58. package/package.json +1 -1
  59. package/settings.json +1 -1
  60. package/dist/cache-DFqZYsHC.cjs +0 -1
  61. package/dist/cache-Mu-VO_6E.js +0 -212
@@ -1,7 +1,7 @@
1
1
  import { useFrame as S } from "@react-three/fiber";
2
- import { useState as g, useRef as f, useCallback as M, useId as h, useEffect as j } from "react";
3
- import { f as p, g as C, h as E, X as m, j as I } from "./index-BDxJWWyy.js";
4
- import { u as v } from "./landmarks-C3LvDhMt.js";
2
+ import { useState as E, useRef as f, useCallback as M, useId as g, useEffect as h } from "react";
3
+ import { E as p, b as j, e as C, X as m, f as I } from "./index-MzlPbe9t.js";
4
+ import { u as v } from "./landmarks-BgLF-yfd.js";
5
5
  const X = (t, o) => {
6
6
  var r;
7
7
  for (let n = 0; n < m.body.max; n += 1)
@@ -13,7 +13,7 @@ const X = (t, o) => {
13
13
  if (r !== void 0)
14
14
  return { body: i(s.find((e) => e.id === r)), memory: u };
15
15
  if (n) {
16
- const e = C(E(s), n, u);
16
+ const e = j(C(s), n, u);
17
17
  return {
18
18
  body: e.index === null ? null : i(s[e.index]),
19
19
  memory: e.memory
@@ -24,7 +24,7 @@ const X = (t, o) => {
24
24
  const l = s.find((e) => e.pose === c);
25
25
  return { body: { pose: c, id: (l == null ? void 0 : l.id) ?? null, held: !1, index: o }, memory: u };
26
26
  }, R = (t, o = !0, r) => {
27
- const n = h(), { ready: u, node: s } = v(
27
+ const n = g(), { ready: u, node: s } = v(
28
28
  I.BODY_TRACKER,
29
29
  r,
30
30
  o
@@ -32,7 +32,7 @@ const X = (t, o) => {
32
32
  m.body.max,
33
33
  Math.max(1, Number.isFinite(t) ? Math.round(t) : 1)
34
34
  );
35
- return j(() => {
35
+ return h(() => {
36
36
  var c;
37
37
  return (c = s == null ? void 0 : s.requestBodies) == null ? void 0 : c.call(s, n, i);
38
38
  }, [s, n, i]), { ready: u, node: s };
@@ -40,7 +40,7 @@ const X = (t, o) => {
40
40
  numBodies: t = m.body.max,
41
41
  active: o = !0
42
42
  } = {}) => {
43
- const { node: r } = R(t, o), [n, u] = g([]), s = f("");
43
+ const { node: r } = R(t, o), [n, u] = E([]), s = f("");
44
44
  return S(() => {
45
45
  var l;
46
46
  const i = (((l = r == null ? void 0 : r.getBodies) == null ? void 0 : l.call(r)) ?? []).map((d) => d.id), c = i.join(",");
@@ -1,9 +1,9 @@
1
- import { useMemo as x, useEffect as h, useCallback as p, useRef as R } from "react";
2
- import { X as E, j as C, f as N, g as _ } from "./index-BDxJWWyy.js";
3
- import { useThree as b } from "@react-three/fiber";
4
- import { g as y } from "./getFaceInfo-Mt44zlej.js";
5
- import { u as T } from "./useFaceResultReader-D8wXbF1L.js";
6
- import { u as S } from "./landmarks-C3LvDhMt.js";
1
+ import { useMemo as x, useEffect as h, useCallback as p, useRef as E } from "react";
2
+ import { X as R, f as b, E as C, b as N } from "./index-MzlPbe9t.js";
3
+ import { useThree as _ } from "@react-three/fiber";
4
+ import { g as y } from "./getFaceInfo-e9XzHPLC.js";
5
+ import { u as T } from "./useFaceResultReader-DSnUjQcw.js";
6
+ import { u as S } from "./landmarks-BgLF-yfd.js";
7
7
  const X = ({
8
8
  active: i = !0,
9
9
  holdMs: l = 250,
@@ -11,14 +11,14 @@ const X = ({
11
11
  targetFps: s,
12
12
  throttleMs: o = 16
13
13
  } = {}) => {
14
- const { camera: t } = b(), u = Number.isFinite(r) ? Math.min(E.face.max, Math.max(1, Math.round(r))) : 1, m = s !== void 0 && Number.isFinite(s) && s > 0 ? s : void 0, e = x(
14
+ const { camera: t } = _(), u = Number.isFinite(r) ? Math.min(R.face.max, Math.max(1, Math.round(r))) : 1, m = s !== void 0 && Number.isFinite(s) && s > 0 ? s : void 0, e = x(
15
15
  () => ({
16
16
  numFaces: u,
17
17
  ...m ? { targetFps: m } : {}
18
18
  }),
19
19
  [u, m]
20
20
  ), { node: n, ready: c } = S(
21
- C.FACE_TRACKER,
21
+ b.FACE_TRACKER,
22
22
  e,
23
23
  i
24
24
  );
@@ -55,14 +55,14 @@ const X = ({
55
55
  const o = Number.isFinite(i) ? Math.max(0, Math.round(i)) : 0, t = X({
56
56
  ...s,
57
57
  numFaces: Math.max(l ?? (r ? A : o + 1), o + 1)
58
- }), u = R(N), m = JSON.stringify(r ?? null), e = x(() => {
58
+ }), u = E(C), m = JSON.stringify(r ?? null), e = x(() => {
59
59
  if (!r) return null;
60
60
  const n = t.map((c, d) => ({
61
61
  index: d,
62
62
  center: { x: c.bounds.centerX, y: c.bounds.centerY },
63
63
  size: c.bounds.width
64
64
  }));
65
- return _(n, r, u.current);
65
+ return N(n, r, u.current);
66
66
  }, [t, m]);
67
67
  return h(() => {
68
68
  e && (u.current = e.memory);
@@ -1,5 +1,5 @@
1
1
  import { useState as E, useEffect as N } from "react";
2
- import { c as P } from "./getFaceInfo-Mt44zlej.js";
2
+ import { c as P } from "./getFaceInfo-e9XzHPLC.js";
3
3
  const S = (t, i) => t.map((e) => ({
4
4
  landmarks: e,
5
5
  bounds: P(e)
@@ -2,25 +2,25 @@ var Gt = Object.defineProperty;
2
2
  var Xt = (t, e, s) => e in t ? Gt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
3
  var m = (t, e, s) => Xt(t, typeof e != "symbol" ? e + "" : e, s);
4
4
  import * as o from "three";
5
- import { t as $, k as kt, n as Te, J as ie, j as Tt, u as Kt, I as Yt, i as Qt, C as Ze } from "./index-BDxJWWyy.js";
6
- import { C as _, b as He, c as $t, d as Zt, a as Jt, e as e0, u as t0 } from "./CanonicalHeadFrame-CQe2YX9a.js";
7
- import { b as s0, a as r0, d as n0, e as a0, t as Ee, c as o0, s as Je } from "./index-CicO_Tnw.js";
8
- import { a as i0, g as l0, d as P } from "./getFaceInfo-Mt44zlej.js";
5
+ import { t as $, g as kt, n as Te, J as ie, f as Tt, u as Kt, I as Yt, i as Qt, C as Ze } from "./index-MzlPbe9t.js";
6
+ import { C as _, b as He, c as $t, d as Zt, a as Jt, e as e0, u as t0 } from "./CanonicalHeadFrame-S3Jk9F1P.js";
7
+ import { b as s0, a as r0, d as n0, e as a0, t as Ee, c as o0, s as Je } from "./index-B34w-TyW.js";
8
+ import { a as i0, g as l0, d as P } from "./getFaceInfo-e9XzHPLC.js";
9
9
  import { s as et, a as c0, L as u0, u as d0 } from "./useLandmarkPoseFit-Bmb3h6Mw.js";
10
10
  import { s as h0 } from "./similarityFit-Bbz-R8AY.js";
11
11
  import { C as z } from "./canonicalFace-BHwyCx1c.js";
12
12
  import { b as he, r as f0, a as p0, M as be } from "./renderState-CJNmj5jz.js";
13
13
  import { jsx as k, jsxs as m0, Fragment as g0 } from "react/jsx-runtime";
14
14
  import { useRef as T, useCallback as Nt, useMemo as oe, useState as Oe, useEffect as q, useContext as S0 } from "react";
15
- import { c as Ke } from "./segmentation-DccvYBBO.js";
15
+ import { c as Ke } from "./segmentation-Q1eXSt_x.js";
16
16
  import { useThree as Ce, useFrame as Ut } from "@react-three/fiber";
17
17
  import { c as w0 } from "./SkeletonUtils-C2r90MtN.js";
18
- import { T as A0, u as Dt } from "./index-CbBCl2ZU.js";
18
+ import { T as A0, u as Dt } from "./index-Dk1UOe-H.js";
19
19
  import { R as y0 } from "./uv-DJU_XfmN.js";
20
- import { f as v0, b as R0 } from "./selectors-J06V0eDb.js";
21
- import { u as M0 } from "./useBodies-DOuwRuew.js";
22
- import { c as E0, I as b0, u as tt } from "./providers-Bxt_MfPK.js";
23
- import { u as C0 } from "./landmarks-C3LvDhMt.js";
20
+ import { f as v0, u as R0 } from "./selectors-CiawE6Ox.js";
21
+ import { u as M0 } from "./useBodies-DzRzQg88.js";
22
+ import { c as E0, I as b0, u as tt } from "./providers-Bo1gfoXg.js";
23
+ import { u as C0 } from "./landmarks-BgLF-yfd.js";
24
24
  const x0 = {
25
25
  "body.head": 0,
26
26
  "body.leftShoulder": 11,
@@ -1,5 +1,5 @@
1
1
  import { useRef as m, useState as u, useCallback as E, useEffect as R } from "react";
2
- import { d as g } from "./index-BDxJWWyy.js";
2
+ import { d as g } from "./index-MzlPbe9t.js";
3
3
  const k = (t = {}) => {
4
4
  const { enabled: c = !0, timeoutMs: o, queryPermission: l } = t, f = (t.models ?? []).join("|"), i = m(t.models);
5
5
  i.current = t.models;
@@ -19,6 +19,10 @@ export interface EditOverrideStore {
19
19
  get(props: object): Readonly<Record<string, unknown>> | undefined;
20
20
  }
21
21
  export declare function editStore(): EditOverrideStore | undefined;
22
+ /** Checks for the values a panel can send for a live override: a finite number, a boolean, a `#rrggbb` colour. */
23
+ export declare const isLiveNumber: (v: unknown) => v is number;
24
+ export declare const isLiveBoolean: (v: unknown) => v is boolean;
25
+ export declare const isLiveColour: (v: unknown) => v is string;
22
26
  /**
23
27
  * A prop name, or a dotted path into an object prop (`settings.fillColor`,
24
28
  * `transform.position`): the same keys as the props in `settings.json`, and the keys the
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The one path every editable component reads the editor's unsaved panel values through. The keys
3
+ * and the checks on each value come from the component's entry in `components.json` (the generated
4
+ * live table), so a prop the editor lists is shown live without the component naming it again.
5
+ * `extra` adds keys the editor writes that components.json does not list (a placement).
6
+ * Call it with the component's own props object, before destructuring.
7
+ */
8
+ export declare function useLiveProps<P extends object>(name: string, props: P, extra?: readonly string[], accept?: Record<string, (v: unknown) => boolean>): P;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vincentt-xr/sdk",
3
- "version": "2.0.0-alpha.21",
3
+ "version": "2.0.0-alpha.22",
4
4
  "description": "XR SDK by Vincentt",
5
5
  "repository": {
6
6
  "type": "git",
package/settings.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": "vincentt.settings-decl/1",
3
3
  "package": "@vincentt-xr/sdk",
4
- "version": "2.0.0-alpha.21",
4
+ "version": "2.0.0-alpha.22",
5
5
  "components": {
6
6
  "AudioPlayer": {
7
7
  "element": "sound",
@@ -1 +0,0 @@
1
- "use strict";var S=Object.defineProperty;var v=(o,e,t)=>e in o?S(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var l=(o,e,t)=>v(o,typeof e!="symbol"?e+"":e,t);const f=require("react"),d=require("./index-J3Qy6hi3.cjs"),p=require("./selectors-Bq6tSgOY.cjs"),k=o=>{const{session:e}=d.useXRContext(),t=p.useXRQualityState(),i=p.useXRQualityConfig(),n=JSON.stringify(o??null),s=f.useMemo(()=>o?d.resolveQualityConfig(o):i??d.resolveQualityConfig(),[n,i]),r=s.tiers,a=f.useCallback(u=>{const c=e.store.getSnapshot().quality;c&&e._setQuality(d.setQualityTier(c,s,u,performance.now()))},[e,s]),h=f.useCallback(u=>{const c=e.store.getSnapshot().quality;c&&e._setQuality(d.lockQuality(c,s,u,performance.now()))},[e,s]),g=f.useCallback(()=>{const u=e.store.getSnapshot().quality;e._setQuality(d.resetQuality(s,(u==null?void 0:u.signals)??d.EMPTY_QUALITY_SIGNALS,performance.now()))},[e,s]);return f.useMemo(()=>({tier:(t==null?void 0:t.decision.tier)??null,index:(t==null?void 0:t.index)??-1,tiers:r,decision:(t==null?void 0:t.decision)??null,history:(t==null?void 0:t.history)??[],signals:(t==null?void 0:t.signals)??null,locked:(t==null?void 0:t.locked)??!1,setTier:a,lock:()=>h(!0),unlock:()=>h(!1),reset:g,state:t}),[t,r,a,h,g])},w=256*1024*1024;class m{constructor(e={}){l(this,"entries",new Map);l(this,"listeners",new Set);l(this,"budget");l(this,"now");l(this,"evictions",0);l(this,"hits",0);l(this,"misses",0);l(this,"statsSnapshot",null);this.budget=e.budgetBytes??w,this.now=e.now??(()=>typeof performance<"u"?performance.now():Date.now())}acquire(e,t){let i=this.entries.get(e.key);if(i&&i.status==="error"&&(this.entries.delete(e.key),i=void 0),!i){this.misses+=1;const n=typeof AbortController<"u"?new AbortController:null,s={definition:e,status:"loading",value:void 0,bytes:0,owners:new Set([t]),promise:null,controller:n,error:null,lastUsed:this.now(),disposed:!1};return s.promise=e.load((n==null?void 0:n.signal)??new AbortController().signal).then(r=>{var a,h;if(s.disposed||this.entries.get(e.key)!==s)throw(a=e.dispose)==null||a.call(e,r),new Error(`Asset "${e.key}" was released before it loaded`);return s.value=r,s.bytes=Math.max(0,Math.round(((h=e.bytes)==null?void 0:h.call(e,r))??0)),s.status="ready",s.promise=null,this.notify(),this.enforceBudget(),r}).catch(r=>{const a=r instanceof Error?r:new Error(String(r));throw this.entries.get(e.key)===s&&!s.disposed&&(s.status="error",s.error=a,s.promise=null,this.notify()),a}),this.entries.set(e.key,s),this.notify(),s.promise}return this.hits+=1,i.owners.add(t),i.lastUsed=this.now(),this.notify(),i.status==="ready"?Promise.resolve(i.value):i.promise}preload(e){const t="__preload__";return this.acquire(e,t).finally(()=>this.release(e.key,t))}release(e,t){var n;const i=this.entries.get(e);!i||!i.owners.delete(t)||(i.lastUsed=this.now(),i.owners.size===0&&i.status==="loading"&&((n=i.controller)==null||n.abort(),i.disposed=!0,this.entries.delete(e)),this.notify(),this.enforceBudget())}get(e){const t=this.entries.get(e);return(t==null?void 0:t.status)==="ready"?t.value:void 0}has(e){return this.entries.has(e)}entry(e){const t=this.entries.get(e);return t?b(e,t):void 0}list(){return Array.from(this.entries,([e,t])=>b(e,t))}setBudget(e){this.budget=e,this.enforceBudget(),this.notify()}evict(e){const t=e??Math.max(0,this.usage()-(Number.isFinite(this.budget)?this.budget:1/0));if(t<=0)return 0;const i=Array.from(this.entries).filter(([,s])=>s.owners.size===0&&s.status==="ready").sort((s,r)=>s[1].lastUsed-r[1].lastUsed);let n=0;for(const[s,r]of i){if(n>=t)break;n+=r.bytes,this.disposeEntry(s,r),this.evictions+=1}return n>0&&this.notify(),n}disposeUnreferenced(){let e=0;for(const[t,i]of Array.from(this.entries))i.owners.size===0&&(e+=i.bytes,this.disposeEntry(t,i));return e>0&&this.notify(),e}disposeAll(){for(const[e,t]of Array.from(this.entries))this.disposeEntry(e,t);this.notify()}getStats(){if(this.statsSnapshot)return this.statsSnapshot;let e=0,t=0,i=0,n=0,s=0;for(const r of this.entries.values())r.owners.size>0&&(e+=1),r.status==="loading"&&(t+=1),r.status==="error"&&(i+=1),r.status==="ready"&&(n+=r.bytes,r.owners.size===0&&(s+=r.bytes));return this.statsSnapshot={assets:this.entries.size,referencedAssets:e,loadingAssets:t,erroredAssets:i,usageBytes:n,reclaimableBytes:s,budgetBytes:this.budget,overBudget:n>this.budget,evictions:this.evictions,hits:this.hits,misses:this.misses},this.statsSnapshot}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}usage(){let e=0;for(const t of this.entries.values())t.status==="ready"&&(e+=t.bytes);return e}enforceBudget(){Number.isFinite(this.budget)&&this.usage()>this.budget&&this.evict()}disposeEntry(e,t){var i,n,s;if(!t.disposed){if(t.disposed=!0,(i=t.controller)==null||i.abort(),t.status==="ready"&&t.value!==void 0)try{(s=(n=t.definition).dispose)==null||s.call(n,t.value)}catch(r){console.warn(`[xr-sdk assets] dispose threw for ${e}`,r)}this.entries.delete(e)}}notify(){this.statsSnapshot=null,this.listeners.forEach(e=>e())}}const b=(o,e)=>({key:o,status:e.status,bytes:e.bytes,owners:e.owners.size,lastUsed:e.lastUsed,error:e.error}),A=o=>new m(o);let y;const C=()=>(y||(y=A()),y);exports.DEFAULT_ASSET_BUDGET_BYTES=w;exports.XRAssetCache=m;exports.createAssetCache=A;exports.getDefaultAssetCache=C;exports.useXRQuality=k;
@@ -1,212 +0,0 @@
1
- var w = Object.defineProperty;
2
- var m = (n, e, s) => e in n ? w(n, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[e] = s;
3
- var a = (n, e, s) => m(n, typeof e != "symbol" ? e + "" : e, s);
4
- import { useMemo as g, useCallback as f } from "react";
5
- import { u as v, r as p, a as S, l as A, b as k, E } from "./index-BDxJWWyy.js";
6
- import { u as B, a as _ } from "./selectors-J06V0eDb.js";
7
- const X = (n) => {
8
- const { session: e } = v(), s = B(), i = _(), o = JSON.stringify(n ?? null), t = g(
9
- () => n ? p(n) : i ?? p(),
10
- [o, i]
11
- // eslint-disable-line react-hooks/exhaustive-deps
12
- ), r = t.tiers, l = f(
13
- (u) => {
14
- const h = e.store.getSnapshot().quality;
15
- h && e._setQuality(S(h, t, u, performance.now()));
16
- },
17
- [e, t]
18
- ), d = f(
19
- (u) => {
20
- const h = e.store.getSnapshot().quality;
21
- h && e._setQuality(A(h, t, u, performance.now()));
22
- },
23
- [e, t]
24
- ), y = f(() => {
25
- const u = e.store.getSnapshot().quality;
26
- e._setQuality(
27
- k(t, (u == null ? void 0 : u.signals) ?? E, performance.now())
28
- );
29
- }, [e, t]);
30
- return g(
31
- () => ({
32
- tier: (s == null ? void 0 : s.decision.tier) ?? null,
33
- index: (s == null ? void 0 : s.index) ?? -1,
34
- tiers: r,
35
- decision: (s == null ? void 0 : s.decision) ?? null,
36
- history: (s == null ? void 0 : s.history) ?? [],
37
- signals: (s == null ? void 0 : s.signals) ?? null,
38
- locked: (s == null ? void 0 : s.locked) ?? !1,
39
- setTier: l,
40
- lock: () => d(!0),
41
- unlock: () => d(!1),
42
- reset: y,
43
- state: s
44
- }),
45
- [s, r, l, d, y]
46
- );
47
- }, C = 256 * 1024 * 1024;
48
- class Q {
49
- constructor(e = {}) {
50
- a(this, "entries", /* @__PURE__ */ new Map());
51
- a(this, "listeners", /* @__PURE__ */ new Set());
52
- a(this, "budget");
53
- a(this, "now");
54
- a(this, "evictions", 0);
55
- a(this, "hits", 0);
56
- a(this, "misses", 0);
57
- /** Memoised `getStats()` result; cleared on every change so `useSyncExternalStore` sees a stable snapshot. */
58
- a(this, "statsSnapshot", null);
59
- this.budget = e.budgetBytes ?? C, this.now = e.now ?? (() => typeof performance < "u" ? performance.now() : Date.now());
60
- }
61
- /** Acquire `asset` on behalf of `ownerId`; shares an in-flight or loaded value. */
62
- acquire(e, s) {
63
- let i = this.entries.get(e.key);
64
- if (i && i.status === "error" && (this.entries.delete(e.key), i = void 0), !i) {
65
- this.misses += 1;
66
- const o = typeof AbortController < "u" ? new AbortController() : null, t = {
67
- definition: e,
68
- status: "loading",
69
- value: void 0,
70
- bytes: 0,
71
- owners: /* @__PURE__ */ new Set([s]),
72
- promise: null,
73
- controller: o,
74
- error: null,
75
- lastUsed: this.now(),
76
- disposed: !1
77
- };
78
- return t.promise = e.load((o == null ? void 0 : o.signal) ?? new AbortController().signal).then((r) => {
79
- var l, d;
80
- if (t.disposed || this.entries.get(e.key) !== t)
81
- throw (l = e.dispose) == null || l.call(e, r), new Error(`Asset "${e.key}" was released before it loaded`);
82
- return t.value = r, t.bytes = Math.max(0, Math.round(((d = e.bytes) == null ? void 0 : d.call(e, r)) ?? 0)), t.status = "ready", t.promise = null, this.notify(), this.enforceBudget(), r;
83
- }).catch((r) => {
84
- const l = r instanceof Error ? r : new Error(String(r));
85
- throw this.entries.get(e.key) === t && !t.disposed && (t.status = "error", t.error = l, t.promise = null, this.notify()), l;
86
- }), this.entries.set(e.key, t), this.notify(), t.promise;
87
- }
88
- return this.hits += 1, i.owners.add(s), i.lastUsed = this.now(), this.notify(), i.status === "ready" ? Promise.resolve(i.value) : i.promise;
89
- }
90
- /** Start loading without holding a reference (warm the cache). */
91
- preload(e) {
92
- const s = "__preload__";
93
- return this.acquire(e, s).finally(() => this.release(e.key, s));
94
- }
95
- /** Drop `ownerId`'s reference. The value stays cached until evicted or disposed. */
96
- release(e, s) {
97
- var o;
98
- const i = this.entries.get(e);
99
- !i || !i.owners.delete(s) || (i.lastUsed = this.now(), i.owners.size === 0 && i.status === "loading" && ((o = i.controller) == null || o.abort(), i.disposed = !0, this.entries.delete(e)), this.notify(), this.enforceBudget());
100
- }
101
- /** Synchronous read of a loaded value (or `undefined`). Does not take a reference. */
102
- get(e) {
103
- const s = this.entries.get(e);
104
- return (s == null ? void 0 : s.status) === "ready" ? s.value : void 0;
105
- }
106
- has(e) {
107
- return this.entries.has(e);
108
- }
109
- entry(e) {
110
- const s = this.entries.get(e);
111
- return s ? b(e, s) : void 0;
112
- }
113
- list() {
114
- return Array.from(this.entries, ([e, s]) => b(e, s));
115
- }
116
- setBudget(e) {
117
- this.budget = e, this.enforceBudget(), this.notify();
118
- }
119
- /**
120
- * Dispose unreferenced values, least recently used first, until usage is
121
- * within the budget (or `bytesToFree` is reclaimed). Referenced values are
122
- * never touched. Returns the bytes reclaimed.
123
- */
124
- evict(e) {
125
- const s = e ?? Math.max(0, this.usage() - (Number.isFinite(this.budget) ? this.budget : 1 / 0));
126
- if (s <= 0) return 0;
127
- const i = Array.from(this.entries).filter(([, t]) => t.owners.size === 0 && t.status === "ready").sort((t, r) => t[1].lastUsed - r[1].lastUsed);
128
- let o = 0;
129
- for (const [t, r] of i) {
130
- if (o >= s) break;
131
- o += r.bytes, this.disposeEntry(t, r), this.evictions += 1;
132
- }
133
- return o > 0 && this.notify(), o;
134
- }
135
- /** Dispose every unreferenced value (route change, scene teardown). Returns the bytes freed. */
136
- disposeUnreferenced() {
137
- let e = 0;
138
- for (const [s, i] of Array.from(this.entries))
139
- i.owners.size === 0 && (e += i.bytes, this.disposeEntry(s, i));
140
- return e > 0 && this.notify(), e;
141
- }
142
- /** Dispose everything, referenced or not (app / session shutdown). Owners are forgotten. */
143
- disposeAll() {
144
- for (const [e, s] of Array.from(this.entries)) this.disposeEntry(e, s);
145
- this.notify();
146
- }
147
- /** Current statistics. The object is reused until the cache changes, so it is safe as a store snapshot. */
148
- getStats() {
149
- if (this.statsSnapshot) return this.statsSnapshot;
150
- let e = 0, s = 0, i = 0, o = 0, t = 0;
151
- for (const r of this.entries.values())
152
- r.owners.size > 0 && (e += 1), r.status === "loading" && (s += 1), r.status === "error" && (i += 1), r.status === "ready" && (o += r.bytes, r.owners.size === 0 && (t += r.bytes));
153
- return this.statsSnapshot = {
154
- assets: this.entries.size,
155
- referencedAssets: e,
156
- loadingAssets: s,
157
- erroredAssets: i,
158
- usageBytes: o,
159
- reclaimableBytes: t,
160
- budgetBytes: this.budget,
161
- overBudget: o > this.budget,
162
- evictions: this.evictions,
163
- hits: this.hits,
164
- misses: this.misses
165
- }, this.statsSnapshot;
166
- }
167
- subscribe(e) {
168
- return this.listeners.add(e), () => {
169
- this.listeners.delete(e);
170
- };
171
- }
172
- usage() {
173
- let e = 0;
174
- for (const s of this.entries.values()) s.status === "ready" && (e += s.bytes);
175
- return e;
176
- }
177
- enforceBudget() {
178
- Number.isFinite(this.budget) && this.usage() > this.budget && this.evict();
179
- }
180
- disposeEntry(e, s) {
181
- var i, o, t;
182
- if (!s.disposed) {
183
- if (s.disposed = !0, (i = s.controller) == null || i.abort(), s.status === "ready" && s.value !== void 0)
184
- try {
185
- (t = (o = s.definition).dispose) == null || t.call(o, s.value);
186
- } catch (r) {
187
- console.warn(`[xr-sdk assets] dispose threw for ${e}`, r);
188
- }
189
- this.entries.delete(e);
190
- }
191
- }
192
- notify() {
193
- this.statsSnapshot = null, this.listeners.forEach((e) => e());
194
- }
195
- }
196
- const b = (n, e) => ({
197
- key: n,
198
- status: e.status,
199
- bytes: e.bytes,
200
- owners: e.owners.size,
201
- lastUsed: e.lastUsed,
202
- error: e.error
203
- }), U = (n) => new Q(n);
204
- let c;
205
- const q = () => (c || (c = U()), c);
206
- export {
207
- C as D,
208
- Q as X,
209
- U as c,
210
- q as g,
211
- X as u
212
- };