@webspatial/react-sdk 0.0.16-alpha.0 → 0.0.16-alpha.1

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.
@@ -1127,12 +1127,14 @@ function useSyncDomRect(spatialId) {
1127
1127
  const isFixedPosition = stylePosition === "fixed";
1128
1128
  let domRect2 = dom.getBoundingClientRect();
1129
1129
  let rectType = domRect2rectType(domRect2);
1130
- const parentDom = spatialReactContextObject?.queryParentSpatialDom(spatialId);
1131
- if (!isFixedPosition && parentDom) {
1132
- const parentDomRect = parentDom.getBoundingClientRect();
1133
- const parentRectType = domRect2rectType(parentDomRect);
1134
- rectType.x -= parentRectType.x;
1135
- rectType.y -= parentRectType.y;
1130
+ if (!isFixedPosition) {
1131
+ const parentDom = spatialReactContextObject?.queryParentSpatialDom(spatialId);
1132
+ if (parentDom) {
1133
+ const parentDomRect = parentDom.getBoundingClientRect();
1134
+ const parentRectType = domRect2rectType(parentDomRect);
1135
+ rectType.x -= parentRectType.x;
1136
+ rectType.y -= parentRectType.y;
1137
+ }
1136
1138
  }
1137
1139
  const anchor = parseTransformOrigin(computedStyle);
1138
1140
  anchorRef.current = anchor;
@@ -2395,9 +2397,12 @@ var Model3DNative = class {
2395
2397
  if (!this.entity || !this.spatialModel3DComponent) {
2396
2398
  return;
2397
2399
  }
2400
+ const computedStyle = getComputedStyle(dom);
2401
+ const isFixed = computedStyle.position === "fixed";
2402
+ const scrollY = isFixed ? 0 : window.scrollY;
2398
2403
  const rect = dom.getBoundingClientRect();
2399
2404
  const targetPosX = rect.left + (rect.right - rect.left) / 2;
2400
- const targetPosY = rect.bottom + (rect.top - rect.bottom) / 2 + window.scrollY;
2405
+ const targetPosY = rect.bottom + (rect.top - rect.bottom) / 2 + scrollY;
2401
2406
  const { spatialTransform } = options;
2402
2407
  const { position, rotation, scale } = spatialTransform;
2403
2408
  const entity = this.entity;
@@ -2414,7 +2419,6 @@ var Model3DNative = class {
2414
2419
  await entity.updateTransform();
2415
2420
  const spatialModel3DComponent = this.spatialModel3DComponent;
2416
2421
  await spatialModel3DComponent.setResolution(rect.width, rect.height);
2417
- const computedStyle = getComputedStyle(dom);
2418
2422
  const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
2419
2423
  await spatialModel3DComponent.setOpacity(opacity);
2420
2424
  const anchor = parseTransformOrigin(computedStyle);
@@ -2452,6 +2456,19 @@ var Model3DNative = class {
2452
2456
  this.spatialModel3DComponent.setOpacity(opacity);
2453
2457
  }
2454
2458
  }
2459
+ async setScrollWithParent(scrollWithParent) {
2460
+ if (this.spatialModel3DComponent) {
2461
+ this.spatialModel3DComponent.setScrollWithParent(scrollWithParent);
2462
+ }
2463
+ }
2464
+ async changeParentEntity(parentEntity) {
2465
+ if (this.parentEntity !== parentEntity) {
2466
+ if (this.entity) {
2467
+ await this.entity.setParent(parentEntity);
2468
+ }
2469
+ this.parentEntity = parentEntity;
2470
+ }
2471
+ }
2455
2472
  set onDragStart(callback) {
2456
2473
  if (this.spatialModel3DComponent) {
2457
2474
  this.spatialModel3DComponent.onDragStart = callback;
@@ -2869,17 +2886,21 @@ function useSyncDomInfoFromStandardInstance(spatialId) {
2869
2886
  return;
2870
2887
  }
2871
2888
  modelRef.current = dom;
2889
+ const computedStyle = getComputedStyle(dom);
2890
+ inheritedPortalStyleRef.current = getInheritedStyleProps(computedStyle);
2891
+ const stylePosition = inheritedPortalStyleRef.current.position;
2892
+ const isFixedPosition = stylePosition === "fixed";
2872
2893
  let domRect2 = dom.getBoundingClientRect();
2873
2894
  let rectType = domRect2rectType(domRect2);
2874
- const parentDom = spatialReactContextObject?.queryParentSpatialDom(spatialId);
2875
- if (parentDom) {
2876
- const parentDomRect = parentDom.getBoundingClientRect();
2877
- const parentRectType = domRect2rectType(parentDomRect);
2878
- rectType.x -= parentRectType.x;
2879
- rectType.y -= parentRectType.y;
2895
+ if (!isFixedPosition) {
2896
+ const parentDom = spatialReactContextObject?.queryParentSpatialDom(spatialId);
2897
+ if (parentDom) {
2898
+ const parentDomRect = parentDom.getBoundingClientRect();
2899
+ const parentRectType = domRect2rectType(parentDomRect);
2900
+ rectType.x -= parentRectType.x;
2901
+ rectType.y -= parentRectType.y;
2902
+ }
2880
2903
  }
2881
- const computedStyle = getComputedStyle(dom);
2882
- inheritedPortalStyleRef.current = getInheritedStyleProps(computedStyle);
2883
2904
  const anchor = parseTransformOrigin(computedStyle);
2884
2905
  anchorRef.current = anchor;
2885
2906
  const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
@@ -3053,6 +3074,22 @@ function renderModel3DPortalInstance(spatialId, props) {
3053
3074
  model3DNativeRef.current.setOpacity(opacity);
3054
3075
  }
3055
3076
  }, [model3DNativeRef.current, opacity]);
3077
+ const isFixedPosition = inheritedPortalStyle.position == "fixed";
3078
+ useEffect13(() => {
3079
+ if (model3DNativeRef.current) {
3080
+ model3DNativeRef.current.setScrollWithParent(
3081
+ inheritedPortalStyle.position !== "fixed"
3082
+ );
3083
+ if (isFixedPosition) {
3084
+ ;
3085
+ (async function() {
3086
+ var wc = await getSession().getCurrentWindowComponent();
3087
+ var ent = await wc.getEntity();
3088
+ model3DNativeRef.current?.changeParentEntity(ent);
3089
+ })();
3090
+ }
3091
+ }
3092
+ }, [model3DNativeRef.current, isFixedPosition]);
3056
3093
  const onSuccess = useCallback5(() => {
3057
3094
  ;
3058
3095
  modelRef.current.ready = true;
@@ -3090,7 +3127,7 @@ function renderModel3DPortalInstance(spatialId, props) {
3090
3127
  }
3091
3128
  };
3092
3129
  }, [modelUrl]);
3093
- const needRenderPlaceHolder = inheritedPortalStyle.position !== "absolute";
3130
+ const needRenderPlaceHolder = inheritedPortalStyle.position !== "absolute" && inheritedPortalStyle.position !== "fixed";
3094
3131
  if (!needRenderPlaceHolder && phase !== "failure") {
3095
3132
  return /* @__PURE__ */ jsx12(Fragment2, {});
3096
3133
  } else {