@webspatial/react-sdk 0.0.2 → 0.0.4

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.
@@ -31,9 +31,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  ));
32
32
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
33
 
34
- // dist/cjs/web/index.js
35
- var require_web = __commonJS({
36
- "dist/cjs/web/index.js"(exports, module2) {
34
+ // dist/cjs/default/index.js
35
+ var require_default = __commonJS({
36
+ "dist/cjs/default/index.js"(exports, module2) {
37
37
  "use strict";
38
38
  var __create2 = Object.create;
39
39
  var __defProp2 = Object.defineProperty;
@@ -221,14 +221,13 @@ var require_web = __commonJS({
221
221
  "tspan"
222
222
  ];
223
223
  var import_react10 = require("react");
224
- var SpatialHelper = {};
225
- var Spatial = {};
224
+ var import_core_sdk = require("@webspatial/core-sdk");
226
225
  var spatial = null;
227
226
  var _currentSession = null;
228
227
  function getSession3() {
229
- if (true) return null;
228
+ if (false) return null;
230
229
  if (!spatial) {
231
- spatial = new Spatial();
230
+ spatial = new import_core_sdk.Spatial();
232
231
  }
233
232
  if (!spatial.isSupported()) {
234
233
  return null;
@@ -242,7 +241,7 @@ var require_web = __commonJS({
242
241
  __name(getSession3, "getSession");
243
242
  __name2(getSession3, "getSession");
244
243
  async function getStat() {
245
- if (true) return;
244
+ if (false) return;
246
245
  const statsInfo = await getSession3()._getStats();
247
246
  return statsInfo;
248
247
  }
@@ -305,7 +304,7 @@ var require_web = __commonJS({
305
304
  __name(inspectRootWindowContainer, "inspectRootWindowContainer");
306
305
  __name2(inspectRootWindowContainer, "inspectRootWindowContainer");
307
306
  function enableDebugTool() {
308
- if (true) return;
307
+ if (false) return;
309
308
  const session = getSession3();
310
309
  Object.assign(window, {
311
310
  session,
@@ -543,7 +542,7 @@ var require_web = __commonJS({
543
542
  this.entity?._setName(debugName);
544
543
  }
545
544
  async initInternal(url) {
546
- if (true) return;
545
+ if (false) return;
547
546
  this.entity = await getSession3().createEntity();
548
547
  this.webview = await getSession3().createWindowComponent();
549
548
  await this.webview.loadURL(url);
@@ -556,7 +555,7 @@ var require_web = __commonJS({
556
555
  await this.entity.setParent(ent);
557
556
  }
558
557
  async initInternalFromWindow(parentSpatialWindowManager) {
559
- if (true) return;
558
+ if (false) return;
560
559
  var w = await getSession3().createWindowContext();
561
560
  this.window = w;
562
561
  this.entity = await getSession3().createEntity();
@@ -900,7 +899,7 @@ var require_web = __commonJS({
900
899
  }
901
900
  __name(syncDefaultSpatialStyle, "syncDefaultSpatialStyle");
902
901
  __name2(syncDefaultSpatialStyle, "syncDefaultSpatialStyle");
903
- function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, cornerRadiusFromStyle, opacity) {
902
+ function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, cornerRadiusFromStyle, opacity, stylePosition) {
904
903
  let { allowScroll, scrollWithParent, style, spatialStyle = {} } = props;
905
904
  let {
906
905
  position = { x: 0, y: 0, z: 1 },
@@ -910,7 +909,6 @@ var require_web = __commonJS({
910
909
  cornerRadius = cornerRadiusFromStyle,
911
910
  zIndex = 0
912
911
  } = spatialStyle;
913
- let stylePosition = style?.position;
914
912
  let styleOverflow = style?.overflow;
915
913
  const visible = (0, import_react8.useMemo)(() => {
916
914
  return spatialStyle.visible !== false && domRect.width > 0 && domRect.height > 0;
@@ -1143,7 +1141,8 @@ var require_web = __commonJS({
1143
1141
  domRect,
1144
1142
  anchor,
1145
1143
  cornerRadius,
1146
- opacity
1144
+ opacity,
1145
+ inheritedPortalStyle.position
1147
1146
  );
1148
1147
  const JSXPortalInstance = renderJSXPortalInstance(
1149
1148
  props,
@@ -1152,7 +1151,7 @@ var require_web = __commonJS({
1152
1151
  inheritedPortalStyle,
1153
1152
  className
1154
1153
  );
1155
- const needRenderPlaceHolder = isSubPortal && inheritedPortalStyle.position !== "absolute";
1154
+ const needRenderPlaceHolder = isSubPortal && inheritedPortalStyle.position !== "absolute" && inheritedPortalStyle.position !== "fixed";
1156
1155
  return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(SpatialWindowManagerContext.Provider, { value: spatialWindowManager, children: [
1157
1156
  needRenderPlaceHolder && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1158
1157
  "div",
@@ -1441,7 +1440,7 @@ var require_web = __commonJS({
1441
1440
  __name(parseTransform, "parseTransform");
1442
1441
  __name2(parseTransform, "parseTransform");
1443
1442
  function parseBack(computedStyle) {
1444
- let useBackProperty = computedStyle.position === "absolute" || computedStyle.position === "relative";
1443
+ let useBackProperty = computedStyle.position === "absolute" || computedStyle.position === "relative" || computedStyle.position === "fixed";
1445
1444
  if (!useBackProperty) return new import_Matrix4.Matrix4();
1446
1445
  let backProperty = computedStyle.getPropertyValue(SpatialCustomVars.back);
1447
1446
  let back = void 0;
@@ -1864,6 +1863,7 @@ var require_web = __commonJS({
1864
1863
  ...style,
1865
1864
  width: 0,
1866
1865
  height: 0,
1866
+ padding: 0,
1867
1867
  transition: "none"
1868
1868
  };
1869
1869
  const spatialDivStyle = {
@@ -1893,7 +1893,8 @@ var require_web = __commonJS({
1893
1893
  style: divRefStyle,
1894
1894
  className: divRefClassName,
1895
1895
  ...props,
1896
- ref
1896
+ ref,
1897
+ "data-cssparser": true
1897
1898
  }
1898
1899
  )
1899
1900
  ] });
@@ -1941,6 +1942,7 @@ var require_web = __commonJS({
1941
1942
  ...style,
1942
1943
  width: 0,
1943
1944
  height: 0,
1945
+ padding: 0,
1944
1946
  transition: "none"
1945
1947
  };
1946
1948
  const spatialDivStyle = {
@@ -1980,7 +1982,7 @@ var require_web = __commonJS({
1980
1982
  __name2(renderInPortalInstance, "renderInPortalInstance");
1981
1983
  function CSSSpatialComponentBase(inProps, ref) {
1982
1984
  const { [CSSSpatialID]: cssSpatialID, ...props } = inProps;
1983
- const isWebEnv = true;
1985
+ const isWebEnv = !getSession3();
1984
1986
  if (isWebEnv) {
1985
1987
  return renderInWebEnv(props, ref);
1986
1988
  } else {
@@ -2072,6 +2074,7 @@ var require_web = __commonJS({
2072
2074
  });
2073
2075
  }, "createSpatialPrimitive2"), "createSpatialPrimitive"))(CSSSpatialPrimitive);
2074
2076
  var CSSSpatialDiv = CSSSpatialPrimitive.div;
2077
+ var import_core_sdk2 = require("@webspatial/core-sdk");
2075
2078
  var import_react21 = require("react");
2076
2079
  var import_jsx_runtime8 = require("react/jsx-runtime");
2077
2080
  var runAsync = /* @__PURE__ */ __name2((fn) => {
@@ -2095,12 +2098,12 @@ var require_web = __commonJS({
2095
2098
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ref: divRef, ...props, children: "WebSpatial is not supported in this browser" });
2096
2099
  }
2097
2100
  (0, import_react21.useEffect)(() => {
2098
- if (true) return;
2101
+ if (false) return;
2099
2102
  activePromise.current = runAsync(async () => {
2100
2103
  if (activePromise.current) {
2101
2104
  await activePromise.current;
2102
2105
  }
2103
- let sh = new SpatialHelper(getSession3());
2106
+ let sh = new import_core_sdk2.SpatialHelper(getSession3());
2104
2107
  let x = await sh.dom.attachSpatialView(divRef.current);
2105
2108
  spatialEntity.current = x.entity;
2106
2109
  if (props.onViewLoad) {
@@ -2108,7 +2111,7 @@ var require_web = __commonJS({
2108
2111
  }
2109
2112
  });
2110
2113
  return () => {
2111
- if (true) return;
2114
+ if (false) return;
2112
2115
  runAsync(async () => {
2113
2116
  await activePromise.current;
2114
2117
  spatialEntity.current?.destroy();
@@ -2221,7 +2224,7 @@ var require_web = __commonJS({
2221
2224
  return this.initPromise;
2222
2225
  }
2223
2226
  async initInternal(modelUrl, onSuccess, onFailure) {
2224
- if (true) return;
2227
+ if (false) return;
2225
2228
  var session = getSession3();
2226
2229
  if (!session) {
2227
2230
  return;
@@ -3033,7 +3036,8 @@ var require_web = __commonJS({
3033
3036
  const cssParserDomStyle = {
3034
3037
  ...style,
3035
3038
  width: 0,
3036
- height: 0
3039
+ height: 0,
3040
+ padding: 0
3037
3041
  };
3038
3042
  const { ref: cssParserDomRef, spatialStyle, ready } = useSpatialStyle();
3039
3043
  const ref = useHijackSpatialDivRef(
@@ -3120,7 +3124,8 @@ var require_web = __commonJS({
3120
3124
  const cssParserDomStyle = {
3121
3125
  ...style,
3122
3126
  width: 0,
3123
- height: 0
3127
+ height: 0,
3128
+ padding: 0
3124
3129
  };
3125
3130
  const model3DStyle = {
3126
3131
  ...style,
@@ -3426,9 +3431,9 @@ var require_web = __commonJS({
3426
3431
  }
3427
3432
  });
3428
3433
 
3429
- // dist/cjs/default/index.js
3430
- var require_default = __commonJS({
3431
- "dist/cjs/default/index.js"(exports, module2) {
3434
+ // dist/cjs/web/index.js
3435
+ var require_web = __commonJS({
3436
+ "dist/cjs/web/index.js"(exports, module2) {
3432
3437
  "use strict";
3433
3438
  var __create2 = Object.create;
3434
3439
  var __defProp2 = Object.defineProperty;
@@ -3616,13 +3621,14 @@ var require_default = __commonJS({
3616
3621
  "tspan"
3617
3622
  ];
3618
3623
  var import_react10 = require("react");
3619
- var import_core_sdk = require("@webspatial/core-sdk");
3624
+ var SpatialHelper = {};
3625
+ var Spatial = {};
3620
3626
  var spatial = null;
3621
3627
  var _currentSession = null;
3622
3628
  function getSession3() {
3623
- if (false) return null;
3629
+ if (true) return null;
3624
3630
  if (!spatial) {
3625
- spatial = new import_core_sdk.Spatial();
3631
+ spatial = new Spatial();
3626
3632
  }
3627
3633
  if (!spatial.isSupported()) {
3628
3634
  return null;
@@ -3636,7 +3642,7 @@ var require_default = __commonJS({
3636
3642
  __name(getSession3, "getSession");
3637
3643
  __name2(getSession3, "getSession");
3638
3644
  async function getStat() {
3639
- if (false) return;
3645
+ if (true) return;
3640
3646
  const statsInfo = await getSession3()._getStats();
3641
3647
  return statsInfo;
3642
3648
  }
@@ -3699,7 +3705,7 @@ var require_default = __commonJS({
3699
3705
  __name(inspectRootWindowContainer, "inspectRootWindowContainer");
3700
3706
  __name2(inspectRootWindowContainer, "inspectRootWindowContainer");
3701
3707
  function enableDebugTool() {
3702
- if (false) return;
3708
+ if (true) return;
3703
3709
  const session = getSession3();
3704
3710
  Object.assign(window, {
3705
3711
  session,
@@ -3937,7 +3943,7 @@ var require_default = __commonJS({
3937
3943
  this.entity?._setName(debugName);
3938
3944
  }
3939
3945
  async initInternal(url) {
3940
- if (false) return;
3946
+ if (true) return;
3941
3947
  this.entity = await getSession3().createEntity();
3942
3948
  this.webview = await getSession3().createWindowComponent();
3943
3949
  await this.webview.loadURL(url);
@@ -3950,7 +3956,7 @@ var require_default = __commonJS({
3950
3956
  await this.entity.setParent(ent);
3951
3957
  }
3952
3958
  async initInternalFromWindow(parentSpatialWindowManager) {
3953
- if (false) return;
3959
+ if (true) return;
3954
3960
  var w = await getSession3().createWindowContext();
3955
3961
  this.window = w;
3956
3962
  this.entity = await getSession3().createEntity();
@@ -4294,7 +4300,7 @@ var require_default = __commonJS({
4294
4300
  }
4295
4301
  __name(syncDefaultSpatialStyle, "syncDefaultSpatialStyle");
4296
4302
  __name2(syncDefaultSpatialStyle, "syncDefaultSpatialStyle");
4297
- function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, cornerRadiusFromStyle, opacity) {
4303
+ function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, cornerRadiusFromStyle, opacity, stylePosition) {
4298
4304
  let { allowScroll, scrollWithParent, style, spatialStyle = {} } = props;
4299
4305
  let {
4300
4306
  position = { x: 0, y: 0, z: 1 },
@@ -4304,7 +4310,6 @@ var require_default = __commonJS({
4304
4310
  cornerRadius = cornerRadiusFromStyle,
4305
4311
  zIndex = 0
4306
4312
  } = spatialStyle;
4307
- let stylePosition = style?.position;
4308
4313
  let styleOverflow = style?.overflow;
4309
4314
  const visible = (0, import_react8.useMemo)(() => {
4310
4315
  return spatialStyle.visible !== false && domRect.width > 0 && domRect.height > 0;
@@ -4537,7 +4542,8 @@ var require_default = __commonJS({
4537
4542
  domRect,
4538
4543
  anchor,
4539
4544
  cornerRadius,
4540
- opacity
4545
+ opacity,
4546
+ inheritedPortalStyle.position
4541
4547
  );
4542
4548
  const JSXPortalInstance = renderJSXPortalInstance(
4543
4549
  props,
@@ -4546,7 +4552,7 @@ var require_default = __commonJS({
4546
4552
  inheritedPortalStyle,
4547
4553
  className
4548
4554
  );
4549
- const needRenderPlaceHolder = isSubPortal && inheritedPortalStyle.position !== "absolute";
4555
+ const needRenderPlaceHolder = isSubPortal && inheritedPortalStyle.position !== "absolute" && inheritedPortalStyle.position !== "fixed";
4550
4556
  return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(SpatialWindowManagerContext.Provider, { value: spatialWindowManager, children: [
4551
4557
  needRenderPlaceHolder && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
4552
4558
  "div",
@@ -4835,7 +4841,7 @@ var require_default = __commonJS({
4835
4841
  __name(parseTransform, "parseTransform");
4836
4842
  __name2(parseTransform, "parseTransform");
4837
4843
  function parseBack(computedStyle) {
4838
- let useBackProperty = computedStyle.position === "absolute" || computedStyle.position === "relative";
4844
+ let useBackProperty = computedStyle.position === "absolute" || computedStyle.position === "relative" || computedStyle.position === "fixed";
4839
4845
  if (!useBackProperty) return new import_Matrix4.Matrix4();
4840
4846
  let backProperty = computedStyle.getPropertyValue(SpatialCustomVars.back);
4841
4847
  let back = void 0;
@@ -5258,6 +5264,7 @@ var require_default = __commonJS({
5258
5264
  ...style,
5259
5265
  width: 0,
5260
5266
  height: 0,
5267
+ padding: 0,
5261
5268
  transition: "none"
5262
5269
  };
5263
5270
  const spatialDivStyle = {
@@ -5287,7 +5294,8 @@ var require_default = __commonJS({
5287
5294
  style: divRefStyle,
5288
5295
  className: divRefClassName,
5289
5296
  ...props,
5290
- ref
5297
+ ref,
5298
+ "data-cssparser": true
5291
5299
  }
5292
5300
  )
5293
5301
  ] });
@@ -5335,6 +5343,7 @@ var require_default = __commonJS({
5335
5343
  ...style,
5336
5344
  width: 0,
5337
5345
  height: 0,
5346
+ padding: 0,
5338
5347
  transition: "none"
5339
5348
  };
5340
5349
  const spatialDivStyle = {
@@ -5374,7 +5383,7 @@ var require_default = __commonJS({
5374
5383
  __name2(renderInPortalInstance, "renderInPortalInstance");
5375
5384
  function CSSSpatialComponentBase(inProps, ref) {
5376
5385
  const { [CSSSpatialID]: cssSpatialID, ...props } = inProps;
5377
- const isWebEnv = !getSession3();
5386
+ const isWebEnv = true;
5378
5387
  if (isWebEnv) {
5379
5388
  return renderInWebEnv(props, ref);
5380
5389
  } else {
@@ -5466,7 +5475,6 @@ var require_default = __commonJS({
5466
5475
  });
5467
5476
  }, "createSpatialPrimitive2"), "createSpatialPrimitive"))(CSSSpatialPrimitive);
5468
5477
  var CSSSpatialDiv = CSSSpatialPrimitive.div;
5469
- var import_core_sdk2 = require("@webspatial/core-sdk");
5470
5478
  var import_react21 = require("react");
5471
5479
  var import_jsx_runtime8 = require("react/jsx-runtime");
5472
5480
  var runAsync = /* @__PURE__ */ __name2((fn) => {
@@ -5490,12 +5498,12 @@ var require_default = __commonJS({
5490
5498
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ref: divRef, ...props, children: "WebSpatial is not supported in this browser" });
5491
5499
  }
5492
5500
  (0, import_react21.useEffect)(() => {
5493
- if (false) return;
5501
+ if (true) return;
5494
5502
  activePromise.current = runAsync(async () => {
5495
5503
  if (activePromise.current) {
5496
5504
  await activePromise.current;
5497
5505
  }
5498
- let sh = new import_core_sdk2.SpatialHelper(getSession3());
5506
+ let sh = new SpatialHelper(getSession3());
5499
5507
  let x = await sh.dom.attachSpatialView(divRef.current);
5500
5508
  spatialEntity.current = x.entity;
5501
5509
  if (props.onViewLoad) {
@@ -5503,7 +5511,7 @@ var require_default = __commonJS({
5503
5511
  }
5504
5512
  });
5505
5513
  return () => {
5506
- if (false) return;
5514
+ if (true) return;
5507
5515
  runAsync(async () => {
5508
5516
  await activePromise.current;
5509
5517
  spatialEntity.current?.destroy();
@@ -5616,7 +5624,7 @@ var require_default = __commonJS({
5616
5624
  return this.initPromise;
5617
5625
  }
5618
5626
  async initInternal(modelUrl, onSuccess, onFailure) {
5619
- if (false) return;
5627
+ if (true) return;
5620
5628
  var session = getSession3();
5621
5629
  if (!session) {
5622
5630
  return;
@@ -6428,7 +6436,8 @@ var require_default = __commonJS({
6428
6436
  const cssParserDomStyle = {
6429
6437
  ...style,
6430
6438
  width: 0,
6431
- height: 0
6439
+ height: 0,
6440
+ padding: 0
6432
6441
  };
6433
6442
  const { ref: cssParserDomRef, spatialStyle, ready } = useSpatialStyle();
6434
6443
  const ref = useHijackSpatialDivRef(
@@ -6515,7 +6524,8 @@ var require_default = __commonJS({
6515
6524
  const cssParserDomStyle = {
6516
6525
  ...style,
6517
6526
  width: 0,
6518
- height: 0
6527
+ height: 0,
6528
+ padding: 0
6519
6529
  };
6520
6530
  const model3DStyle = {
6521
6531
  ...style,
@@ -6825,10 +6835,10 @@ var require_default = __commonJS({
6825
6835
  var require_npm = __commonJS({
6826
6836
  "npm/index.js"(exports, module2) {
6827
6837
  "use strict";
6828
- if (process.env.XR_ENV === "web") {
6829
- module2.exports = require_web();
6830
- } else {
6838
+ if (process.env.XR_ENV === "avp") {
6831
6839
  module2.exports = require_default();
6840
+ } else {
6841
+ module2.exports = require_web();
6832
6842
  }
6833
6843
  }
6834
6844
  });
@@ -6851,7 +6861,15 @@ async function injectSceneHook() {
6851
6861
  if (!window.opener) return;
6852
6862
  if (window._SceneHookOff) return;
6853
6863
  await (0, import_react_sdk.getSession)()?.setLoading("show");
6854
- document.addEventListener("DOMContentLoaded", async () => {
6864
+ function onContentLoaded(callback) {
6865
+ if (document.readyState === "interactive" || document.readyState === "complete") {
6866
+ callback();
6867
+ } else {
6868
+ document.addEventListener("DOMContentLoaded", callback);
6869
+ }
6870
+ }
6871
+ __name(onContentLoaded, "onContentLoaded");
6872
+ onContentLoaded(async () => {
6855
6873
  let cfg = import_react_sdk.defaultSceneConfig;
6856
6874
  if (typeof window.xrCurrentSceneDefaults === "function") {
6857
6875
  try {