@webspatial/react-sdk 1.4.0 → 1.5.0

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.
@@ -313,7 +313,8 @@ declare const ModelAsset: React__default.FC<Props>;
313
313
 
314
314
  declare const ModelEntity: React__default.ForwardRefExoticComponent<EntityProps & {
315
315
  model: string;
316
- } & {
316
+ materials?: string[];
317
+ } & EntityEventHandler & {
317
318
  children?: React__default.ReactNode;
318
319
  } & React__default.RefAttributes<EntityRefShape>>;
319
320
 
@@ -2,7 +2,7 @@
2
2
  (function(){
3
3
  if(typeof window === 'undefined') return;
4
4
  if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
5
- window.__webspatialsdk__['react-sdk-version'] = "1.4.0"
5
+ window.__webspatialsdk__['react-sdk-version'] = "1.5.0"
6
6
  window.__webspatialsdk__['XR_ENV'] = "avp"
7
7
  })()
8
8
 
@@ -2349,6 +2349,20 @@ function shallowEqualRotation(a, b) {
2349
2349
  if (!a || !b) return false;
2350
2350
  return a.x === b.x && a.y === b.y && a.z === b.z && ("w" in a ? a.w === b.w : true);
2351
2351
  }
2352
+ function shallowEqualObject(a, b) {
2353
+ if (a === b) return true;
2354
+ if (!a || !b) return false;
2355
+ const keysA = Object.keys(a);
2356
+ const keysB = Object.keys(b);
2357
+ if (keysA.length !== keysB.length) return false;
2358
+ return keysA.every((key) => a[key] === b[key]);
2359
+ }
2360
+ function shallowEqualArray(a, b) {
2361
+ if (a === b) return true;
2362
+ if (!a || !b) return false;
2363
+ if (a.length !== b.length) return false;
2364
+ return a.every((val, i) => val === b[i]);
2365
+ }
2352
2366
 
2353
2367
  // src/reality/utils/AbortResourceManager.ts
2354
2368
  var AbortResourceManager = class {
@@ -2493,9 +2507,150 @@ var EntityRef = class {
2493
2507
  }
2494
2508
  };
2495
2509
 
2510
+ // src/reality/hooks/useEntityEvent.tsx
2511
+ function createEventProxy2(ev, instance) {
2512
+ return new Proxy(ev, {
2513
+ get(target, prop) {
2514
+ if (prop === "currentTarget") {
2515
+ return instance;
2516
+ }
2517
+ if (prop === "target") {
2518
+ const origin = target.__origin;
2519
+ if (origin) {
2520
+ return new EntityRef(origin, null);
2521
+ }
2522
+ return instance;
2523
+ }
2524
+ if (prop === "bubbles") {
2525
+ return true;
2526
+ }
2527
+ if (prop === "offsetX") {
2528
+ const type = target.type;
2529
+ if (type === "spatialtap") {
2530
+ return target.detail?.location3D?.x ?? 0;
2531
+ }
2532
+ if (type === "spatialdragstart") {
2533
+ return target.detail?.startLocation3D?.x ?? 0;
2534
+ }
2535
+ return void 0;
2536
+ }
2537
+ if (prop === "offsetY") {
2538
+ const type = target.type;
2539
+ if (type === "spatialtap") {
2540
+ return target.detail?.location3D?.y ?? 0;
2541
+ }
2542
+ if (type === "spatialdragstart") {
2543
+ return target.detail?.startLocation3D?.y ?? 0;
2544
+ }
2545
+ return void 0;
2546
+ }
2547
+ if (prop === "offsetZ") {
2548
+ const type = target.type;
2549
+ if (type === "spatialtap") {
2550
+ return target.detail?.location3D?.z ?? 0;
2551
+ }
2552
+ if (type === "spatialdragstart") {
2553
+ return target.detail?.startLocation3D?.z ?? 0;
2554
+ }
2555
+ return void 0;
2556
+ }
2557
+ if (prop === "translationX") {
2558
+ const type = target.type;
2559
+ if (type === "spatialdrag") {
2560
+ return target.detail?.translation3D?.x ?? 0;
2561
+ }
2562
+ return void 0;
2563
+ }
2564
+ if (prop === "translationY") {
2565
+ const type = target.type;
2566
+ if (type === "spatialdrag") {
2567
+ return target.detail?.translation3D?.y ?? 0;
2568
+ }
2569
+ return void 0;
2570
+ }
2571
+ if (prop === "translationZ") {
2572
+ const type = target.type;
2573
+ if (type === "spatialdrag") {
2574
+ return target.detail?.translation3D?.z ?? 0;
2575
+ }
2576
+ return void 0;
2577
+ }
2578
+ if (prop === "quaternion") {
2579
+ const type = target.type;
2580
+ if (type === "spatialrotate") {
2581
+ return target.detail?.quaternion ?? {
2582
+ x: 0,
2583
+ y: 0,
2584
+ z: 0,
2585
+ w: 1
2586
+ };
2587
+ }
2588
+ return void 0;
2589
+ }
2590
+ if (prop === "magnification") {
2591
+ const type = target.type;
2592
+ if (type === "spatialmagnify") {
2593
+ return target.detail?.magnification ?? 1;
2594
+ }
2595
+ return void 0;
2596
+ }
2597
+ if (prop === "clientX") {
2598
+ const type = target.type;
2599
+ if (type === "spatialtap" || type === "spatialdragstart") {
2600
+ return target.detail?.globalLocation3D?.x ?? 0;
2601
+ }
2602
+ return void 0;
2603
+ }
2604
+ if (prop === "clientY") {
2605
+ const type = target.type;
2606
+ if (type === "spatialtap" || type === "spatialdragstart") {
2607
+ return target.detail?.globalLocation3D?.y ?? 0;
2608
+ }
2609
+ return void 0;
2610
+ }
2611
+ if (prop === "clientZ") {
2612
+ const type = target.type;
2613
+ if (type === "spatialtap" || type === "spatialdragstart") {
2614
+ return target.detail?.globalLocation3D?.z ?? 0;
2615
+ }
2616
+ return void 0;
2617
+ }
2618
+ const val = target[prop];
2619
+ return typeof val === "function" ? val.bind(target) : val;
2620
+ }
2621
+ });
2622
+ }
2623
+ var useEntityEvent = ({ instance, ...handlers }) => {
2624
+ const eventsSetRef = useRef9(/* @__PURE__ */ new Set());
2625
+ useEffect18(() => {
2626
+ const entity = instance.entity;
2627
+ if (!entity) return;
2628
+ Object.entries(eventMap).forEach(([reactKey, spatialEvent]) => {
2629
+ const handlerFn = handlers[reactKey];
2630
+ if (!handlerFn) return;
2631
+ const wrapped = (ev) => handlerFn(createEventProxy2(ev, instance));
2632
+ entity.addEvent(spatialEvent, wrapped);
2633
+ eventsSetRef.current.add(reactKey);
2634
+ });
2635
+ return () => {
2636
+ };
2637
+ }, [instance.entity, ...Object.values(handlers)]);
2638
+ useEffect18(() => {
2639
+ const entity = instance.entity;
2640
+ if (!entity) return;
2641
+ return () => {
2642
+ for (let x of eventsSetRef.current) {
2643
+ entity.removeEvent(x);
2644
+ }
2645
+ eventsSetRef.current.clear();
2646
+ };
2647
+ }, [instance.entity]);
2648
+ return null;
2649
+ };
2650
+
2496
2651
  // src/reality/hooks/useRealityEvents.tsx
2497
2652
  import { useEffect as useEffect19, useRef as useRef10 } from "react";
2498
- function createEventProxy2(ev, instance) {
2653
+ function createEventProxy3(ev, instance) {
2499
2654
  return new Proxy(ev, {
2500
2655
  get(target, prop) {
2501
2656
  if (prop === "currentTarget") {
@@ -2614,7 +2769,7 @@ var useRealityEvents = ({ instance, ...handlers }) => {
2614
2769
  Object.entries(eventMap).forEach(([reactKey, spatialEvent]) => {
2615
2770
  const handlerFn = handlers[reactKey];
2616
2771
  if (!handlerFn) return;
2617
- const wrapped = (ev) => handlerFn(createEventProxy2(ev, instance));
2772
+ const wrapped = (ev) => handlerFn(createEventProxy3(ev, instance));
2618
2773
  instance.addEvent(spatialEvent, wrapped);
2619
2774
  eventsSetRef.current.add(spatialEvent);
2620
2775
  });
@@ -2652,7 +2807,16 @@ var useEntity = ({
2652
2807
  rotation,
2653
2808
  scale,
2654
2809
  enableInput,
2655
- createEntity
2810
+ onSpatialTap,
2811
+ onSpatialDragStart,
2812
+ onSpatialDrag,
2813
+ onSpatialDragEnd,
2814
+ onSpatialRotate,
2815
+ onSpatialRotateEnd,
2816
+ onSpatialMagnify,
2817
+ onSpatialMagnifyEnd,
2818
+ createEntity,
2819
+ recreateKey
2656
2820
  }) => {
2657
2821
  const ctx = useRealityContext();
2658
2822
  const parent = useParentContext();
@@ -2669,6 +2833,11 @@ var useEntity = ({
2669
2833
  ent.destroy();
2670
2834
  return;
2671
2835
  }
2836
+ await ent.updateTransform({ position, rotation, scale });
2837
+ if (controller.signal.aborted) {
2838
+ ent.destroy();
2839
+ return;
2840
+ }
2672
2841
  if (parent) {
2673
2842
  const result = await parent.addEntity(ent);
2674
2843
  if (!result.success) throw new Error("parent.addEntity failed");
@@ -2687,10 +2856,21 @@ var useEntity = ({
2687
2856
  controller.abort();
2688
2857
  instanceRef.current?.destroy();
2689
2858
  };
2690
- }, [ctx, parent]);
2859
+ }, [ctx, parent, recreateKey]);
2691
2860
  useEntityId({ id, entity: instanceRef.current.entity });
2692
2861
  useEntityTransform(instanceRef.current.entity, { position, rotation, scale });
2693
2862
  useEntityRef(ref, instanceRef.current);
2863
+ useEntityEvent({
2864
+ instance: instanceRef.current,
2865
+ onSpatialTap,
2866
+ onSpatialDragStart,
2867
+ onSpatialDrag,
2868
+ onSpatialDragEnd,
2869
+ onSpatialRotate,
2870
+ onSpatialRotateEnd,
2871
+ onSpatialMagnify,
2872
+ onSpatialMagnifyEnd
2873
+ });
2694
2874
  useEffect21(() => {
2695
2875
  const ent = instanceRef.current.entity;
2696
2876
  if (!ent) return;
@@ -2702,20 +2882,21 @@ var useEntity = ({
2702
2882
  };
2703
2883
 
2704
2884
  // src/reality/hooks/useForceUpdate.tsx
2705
- import { useCallback as useCallback7, useState as useState7 } from "react";
2885
+ import { useCallback as useCallback7, useState as useState6 } from "react";
2706
2886
  var useForceUpdate2 = () => {
2707
- const [, setTick] = useState7(0);
2887
+ const [, setTick] = useState6(0);
2708
2888
  return useCallback7(() => setTick((tick) => tick + 1), []);
2709
2889
  };
2710
2890
 
2711
2891
  // src/reality/components/BaseEntity.tsx
2712
2892
  import { jsx as jsx12 } from "react/jsx-runtime";
2713
2893
  var BaseEntity = forwardRef10(
2714
- ({ children, createEntity, ...rest }, ref) => {
2894
+ ({ children, createEntity, recreateKey, ...rest }, ref) => {
2715
2895
  const ctx = useRealityContext();
2716
2896
  const entity = useEntity({
2717
2897
  ...rest,
2718
2898
  ref,
2899
+ recreateKey,
2719
2900
  createEntity: (signal) => createEntity(ctx, signal)
2720
2901
  });
2721
2902
  if (!entity) return null;
@@ -2743,35 +2924,102 @@ var Entity = forwardRef11((props, ref) => {
2743
2924
  import { forwardRef as forwardRef13 } from "react";
2744
2925
 
2745
2926
  // src/reality/components/GeometryEntity.tsx
2746
- import { forwardRef as forwardRef12 } from "react";
2927
+ import { forwardRef as forwardRef12, useEffect as useEffect22, useRef as useRef12 } from "react";
2747
2928
  import { jsx as jsx14 } from "react/jsx-runtime";
2748
2929
  var GeometryEntity = forwardRef12(
2749
2930
  ({ id, children, name, materials, geometryOptions, createGeometry, ...rest }, ref) => {
2931
+ const ctx = useRealityContext();
2932
+ const entityRef = useRef12(null);
2933
+ const componentRef = useRef12(null);
2934
+ const mutableRef = useRef12({
2935
+ lastSnapshot: null,
2936
+ rebuildGen: 0
2937
+ });
2938
+ useEffect22(() => {
2939
+ const { lastSnapshot } = mutableRef.current;
2940
+ if (!ctx || !entityRef.current || lastSnapshot === null) return;
2941
+ const geometryChanged = !shallowEqualObject(
2942
+ lastSnapshot.geometryOptions,
2943
+ geometryOptions
2944
+ );
2945
+ const materialsChanged = !shallowEqualArray(
2946
+ lastSnapshot.materials,
2947
+ materials
2948
+ );
2949
+ if (!geometryChanged && !materialsChanged) return;
2950
+ mutableRef.current.lastSnapshot = { geometryOptions, materials };
2951
+ mutableRef.current.rebuildGen += 1;
2952
+ const gen = mutableRef.current.rebuildGen;
2953
+ const rebuild = async () => {
2954
+ const entity = entityRef.current;
2955
+ if (!entity) return;
2956
+ try {
2957
+ const oldComponent = componentRef.current;
2958
+ if (oldComponent) {
2959
+ await entity.removeComponent(oldComponent);
2960
+ await oldComponent.destroy();
2961
+ componentRef.current = null;
2962
+ if (gen !== mutableRef.current.rebuildGen) return;
2963
+ }
2964
+ const geometry = await createGeometry(geometryOptions);
2965
+ if (gen !== mutableRef.current.rebuildGen) {
2966
+ await geometry.destroy();
2967
+ return;
2968
+ }
2969
+ const materialList = await Promise.all(
2970
+ materials?.map((mid) => ctx.resourceRegistry.get(mid)).filter(Boolean) ?? []
2971
+ );
2972
+ if (gen !== mutableRef.current.rebuildGen) {
2973
+ await geometry.destroy();
2974
+ return;
2975
+ }
2976
+ const modelComponent = await ctx.session.createModelComponent({
2977
+ mesh: geometry,
2978
+ materials: materialList
2979
+ });
2980
+ if (gen !== mutableRef.current.rebuildGen) {
2981
+ await modelComponent.destroy();
2982
+ await geometry.destroy();
2983
+ return;
2984
+ }
2985
+ await entity.addComponent(modelComponent);
2986
+ componentRef.current = modelComponent;
2987
+ } catch (error) {
2988
+ if (gen === mutableRef.current.rebuildGen) {
2989
+ console.error("GeometryEntity: rebuild failed", error);
2990
+ }
2991
+ }
2992
+ };
2993
+ rebuild();
2994
+ }, [ctx, geometryOptions, materials, createGeometry]);
2750
2995
  return /* @__PURE__ */ jsx14(
2751
2996
  BaseEntity,
2752
2997
  {
2753
2998
  ...rest,
2754
2999
  id,
2755
3000
  ref,
2756
- createEntity: async (ctx, signal) => {
3001
+ createEntity: async (ctx2, signal) => {
2757
3002
  const manager = new AbortResourceManager(signal);
2758
3003
  try {
2759
3004
  const ent = await manager.addResource(
2760
- () => ctx.session.createEntity({ id, name })
3005
+ () => ctx2.session.createEntity({ id, name })
2761
3006
  );
2762
3007
  const geometry = await manager.addResource(
2763
3008
  () => createGeometry(geometryOptions)
2764
3009
  );
2765
3010
  const materialList = await Promise.all(
2766
- materials?.map((id2) => ctx.resourceRegistry.get(id2)).filter(Boolean) ?? []
3011
+ materials?.map((id2) => ctx2.resourceRegistry.get(id2)).filter(Boolean) ?? []
2767
3012
  );
2768
3013
  const modelComponent = await manager.addResource(
2769
- () => ctx.session.createModelComponent({
3014
+ () => ctx2.session.createModelComponent({
2770
3015
  mesh: geometry,
2771
3016
  materials: materialList
2772
3017
  })
2773
3018
  );
2774
3019
  await ent.addComponent(modelComponent);
3020
+ entityRef.current = ent;
3021
+ componentRef.current = modelComponent;
3022
+ mutableRef.current.lastSnapshot = { geometryOptions, materials };
2775
3023
  return ent;
2776
3024
  } catch (error) {
2777
3025
  await manager.dispose();
@@ -2809,14 +3057,15 @@ var BoxEntity = forwardRef13(
2809
3057
  );
2810
3058
 
2811
3059
  // src/reality/components/UnlitMaterial.tsx
2812
- import { useEffect as useEffect22, useRef as useRef12 } from "react";
3060
+ import { useEffect as useEffect23, useRef as useRef13 } from "react";
2813
3061
  var UnlitMaterial = ({
2814
3062
  children,
2815
3063
  ...options
2816
3064
  }) => {
2817
3065
  const ctx = useRealityContext();
2818
- const materialRef = useRef12();
2819
- useEffect22(() => {
3066
+ const materialRef = useRef13();
3067
+ const isInitializedRef = useRef13(false);
3068
+ useEffect23(() => {
2820
3069
  if (!ctx) return;
2821
3070
  const { session, reality, resourceRegistry } = ctx;
2822
3071
  const init = async () => {
@@ -2825,6 +3074,7 @@ var UnlitMaterial = ({
2825
3074
  try {
2826
3075
  const mat = await materialPromise;
2827
3076
  materialRef.current = mat;
3077
+ isInitializedRef.current = true;
2828
3078
  } catch (error) {
2829
3079
  console.error(" ~ UnlitMaterial ~ error:", error);
2830
3080
  }
@@ -2832,8 +3082,21 @@ var UnlitMaterial = ({
2832
3082
  init();
2833
3083
  return () => {
2834
3084
  resourceRegistry.removeAndDestroy(options.id);
3085
+ materialRef.current = void 0;
3086
+ isInitializedRef.current = false;
2835
3087
  };
2836
3088
  }, [ctx]);
3089
+ useEffect23(() => {
3090
+ if (!isInitializedRef.current || !materialRef.current) return;
3091
+ const updates = {};
3092
+ if (options.color !== void 0) updates.color = options.color;
3093
+ if (options.transparent !== void 0)
3094
+ updates.transparent = options.transparent;
3095
+ if (options.opacity !== void 0) updates.opacity = options.opacity;
3096
+ if (Object.keys(updates).length > 0) {
3097
+ materialRef.current.updateProperties(updates);
3098
+ }
3099
+ }, [options.color, options.transparent, options.opacity]);
2837
3100
  return null;
2838
3101
  };
2839
3102
 
@@ -2932,7 +3195,7 @@ var SceneGraph = ({ children }) => {
2932
3195
  };
2933
3196
 
2934
3197
  // src/reality/components/ModelAsset.tsx
2935
- import { useEffect as useEffect23, useRef as useRef13 } from "react";
3198
+ import { useEffect as useEffect24, useRef as useRef14 } from "react";
2936
3199
  var resolveAssetUrl = (url) => {
2937
3200
  if (url.startsWith("http://") || url.startsWith("https://")) {
2938
3201
  return url;
@@ -2941,8 +3204,8 @@ var resolveAssetUrl = (url) => {
2941
3204
  };
2942
3205
  var ModelAsset = ({ children, ...options }) => {
2943
3206
  const ctx = useRealityContext();
2944
- const materialRef = useRef13();
2945
- useEffect23(() => {
3207
+ const materialRef = useRef14();
3208
+ useEffect24(() => {
2946
3209
  const controller = new AbortController();
2947
3210
  if (!ctx) return;
2948
3211
  const { session, reality, resourceRegistry } = ctx;
@@ -2972,29 +3235,66 @@ var ModelAsset = ({ children, ...options }) => {
2972
3235
  };
2973
3236
 
2974
3237
  // src/reality/components/ModelEntity.tsx
2975
- import { forwardRef as forwardRef18 } from "react";
3238
+ import { forwardRef as forwardRef18, useEffect as useEffect25, useRef as useRef15 } from "react";
2976
3239
  import { jsx as jsx21 } from "react/jsx-runtime";
2977
3240
  var ModelEntity = forwardRef18(
2978
- ({ id, model, children, name, ...rest }, ref) => {
3241
+ ({ id, model, children, name, materials, ...rest }, ref) => {
3242
+ const ctx = useRealityContext();
3243
+ const entityRef = useRef15(null);
3244
+ const lastMaterialsRef = useRef15(void 0);
3245
+ useEffect25(() => {
3246
+ if (!ctx || !entityRef.current) return;
3247
+ const next = materials ?? [];
3248
+ const prev = lastMaterialsRef.current ?? [];
3249
+ if (shallowEqualArray(prev, next)) return;
3250
+ lastMaterialsRef.current = next;
3251
+ const apply = async () => {
3252
+ try {
3253
+ const materialList = (await Promise.all(
3254
+ next.map((mid) => ctx.resourceRegistry.get(mid))
3255
+ )).filter(Boolean);
3256
+ if (entityRef.current) {
3257
+ await entityRef.current.setMaterials(materialList);
3258
+ }
3259
+ } catch (error) {
3260
+ console.error("ModelEntity: failed to set materials", error);
3261
+ }
3262
+ };
3263
+ apply();
3264
+ }, [ctx, materials]);
2979
3265
  return /* @__PURE__ */ jsx21(
2980
3266
  BaseEntity,
2981
3267
  {
2982
3268
  ...rest,
2983
3269
  id,
2984
3270
  ref,
2985
- createEntity: async (ctx, signal) => {
3271
+ recreateKey: model,
3272
+ createEntity: async (ctx2, signal) => {
2986
3273
  try {
2987
- const modelAsset = await ctx.resourceRegistry.get(model);
3274
+ const modelAsset = await ctx2.resourceRegistry.get(model);
2988
3275
  if (!modelAsset)
2989
3276
  throw new Error(`ModelEntity: model not found ${model}`);
2990
3277
  if (signal.aborted) return null;
2991
- return ctx.session.createSpatialModelEntity(
3278
+ const ent = await ctx2.session.createSpatialModelEntity(
2992
3279
  {
2993
3280
  modelAssetId: modelAsset.id,
2994
3281
  name
2995
3282
  },
2996
3283
  { id, name }
2997
3284
  );
3285
+ entityRef.current = ent;
3286
+ if (materials && materials.length > 0) {
3287
+ const materialList = (await Promise.all(
3288
+ materials.map(
3289
+ (mid) => ctx2.resourceRegistry.get(mid)
3290
+ )
3291
+ )).filter(Boolean);
3292
+ if (materialList.length > 0 && !signal.aborted) {
3293
+ await ent.setMaterials(materialList);
3294
+ }
3295
+ }
3296
+ lastMaterialsRef.current = materials ?? [];
3297
+ return ent;
2998
3298
  } catch (error) {
2999
3299
  return null;
3000
3300
  }
@@ -3009,9 +3309,9 @@ var ModelEntity = forwardRef18(
3009
3309
  import {
3010
3310
  forwardRef as forwardRef19,
3011
3311
  useCallback as useCallback8,
3012
- useEffect as useEffect24,
3013
- useRef as useRef14,
3014
- useState as useState8
3312
+ useEffect as useEffect26,
3313
+ useRef as useRef16,
3314
+ useState as useState7
3015
3315
  } from "react";
3016
3316
  import { Fragment as Fragment3, jsx as jsx22, jsxs as jsxs3 } from "react/jsx-runtime";
3017
3317
  var Reality = forwardRef19(
@@ -3034,9 +3334,9 @@ var Reality = forwardRef19(
3034
3334
  onSpatialMagnifyEnd,
3035
3335
  ...props
3036
3336
  } = inProps;
3037
- const ctxRef = useRef14(null);
3038
- const creationId = useRef14(0);
3039
- const [isReady, setIsReady] = useState8(false);
3337
+ const ctxRef = useRef16(null);
3338
+ const creationId = useRef16(0);
3339
+ const [isReady, setIsReady] = useState7(false);
3040
3340
  const cleanupReality = useCallback8(() => {
3041
3341
  ctxRef.current?.attachmentRegistry.destroy();
3042
3342
  ctxRef.current?.resourceRegistry.destroy();
@@ -3044,7 +3344,7 @@ var Reality = forwardRef19(
3044
3344
  ctxRef.current = null;
3045
3345
  setIsReady(false);
3046
3346
  }, []);
3047
- useEffect24(() => {
3347
+ useEffect26(() => {
3048
3348
  return () => {
3049
3349
  creationId.current++;
3050
3350
  cleanupReality();
@@ -3122,7 +3422,7 @@ var Reality = forwardRef19(
3122
3422
  );
3123
3423
 
3124
3424
  // src/reality/components/AttachmentAsset.tsx
3125
- import { useEffect as useEffect25, useState as useState9 } from "react";
3425
+ import { useEffect as useEffect27, useState as useState8 } from "react";
3126
3426
  import { createPortal as createPortal3 } from "react-dom";
3127
3427
  import { jsx as jsx23 } from "react/jsx-runtime";
3128
3428
  var AttachmentAsset = ({
@@ -3130,8 +3430,8 @@ var AttachmentAsset = ({
3130
3430
  children
3131
3431
  }) => {
3132
3432
  const ctx = useRealityContext();
3133
- const [containers, setContainers] = useState9([]);
3134
- useEffect25(() => {
3433
+ const [containers, setContainers] = useState8([]);
3434
+ useEffect27(() => {
3135
3435
  if (!ctx) return;
3136
3436
  return ctx.attachmentRegistry.onContainersChange(name, setContainers);
3137
3437
  }, [ctx, name]);
@@ -3142,7 +3442,7 @@ var AttachmentAsset = ({
3142
3442
  };
3143
3443
 
3144
3444
  // src/reality/components/AttachmentEntity.tsx
3145
- import { useEffect as useEffect26, useRef as useRef15, useState as useState10 } from "react";
3445
+ import { useEffect as useEffect28, useRef as useRef17, useState as useState9 } from "react";
3146
3446
  var instanceCounter = 0;
3147
3447
  var AttachmentEntity = ({
3148
3448
  attachment: attachmentName,
@@ -3151,12 +3451,12 @@ var AttachmentEntity = ({
3151
3451
  }) => {
3152
3452
  const ctx = useRealityContext();
3153
3453
  const parent = useParentContext();
3154
- const attachmentRef = useRef15(null);
3155
- const parentIdRef = useRef15(null);
3156
- const instanceIdRef = useRef15(`att_${++instanceCounter}`);
3157
- const attachmentNameRef = useRef15(attachmentName);
3158
- const [childWindow, setChildWindow] = useState10(null);
3159
- useEffect26(() => {
3454
+ const attachmentRef = useRef17(null);
3455
+ const parentIdRef = useRef17(null);
3456
+ const instanceIdRef = useRef17(`att_${++instanceCounter}`);
3457
+ const attachmentNameRef = useRef17(attachmentName);
3458
+ const [childWindow, setChildWindow] = useState9(null);
3459
+ useEffect28(() => {
3160
3460
  if (!ctx || !parent) return;
3161
3461
  if (attachmentRef.current) return;
3162
3462
  const parentId = parent.id;
@@ -3218,7 +3518,7 @@ var AttachmentEntity = ({
3218
3518
  }
3219
3519
  };
3220
3520
  }, [ctx, parent]);
3221
- useEffect26(() => {
3521
+ useEffect28(() => {
3222
3522
  if (!ctx) return;
3223
3523
  const att = attachmentRef.current;
3224
3524
  const prevName = attachmentNameRef.current;
@@ -3235,7 +3535,7 @@ var AttachmentEntity = ({
3235
3535
  }
3236
3536
  }, [ctx, attachmentName]);
3237
3537
  useSyncHeadStyles(childWindow, { subtree: false });
3238
- useEffect26(() => {
3538
+ useEffect28(() => {
3239
3539
  if (!attachmentRef.current) return;
3240
3540
  attachmentRef.current.update({ position, size });
3241
3541
  }, [position?.[0], position?.[1], position?.[2], size?.width, size?.height]);
@@ -3371,7 +3671,7 @@ async function convertCoordinate(position, { from, to }) {
3371
3671
  }
3372
3672
 
3373
3673
  // src/index.ts
3374
- var version = "1.4.0";
3674
+ var version = "1.5.0";
3375
3675
  if (typeof window !== "undefined") {
3376
3676
  initPolyfill();
3377
3677
  }