@webspatial/react-sdk 0.1.10 → 0.1.11
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.
- package/dist/default/index.d.ts +6 -3
- package/dist/default/index.js +192 -15
- package/dist/default/index.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx/jsx-dev-runtime.js +3500 -20
- package/dist/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx/{jsx-dev-runtime.react-server.js → jsx-dev-runtime.web.js} +2 -2
- package/dist/jsx/jsx-dev-runtime.web.js.map +1 -0
- package/dist/jsx/{jsx-runtime-DjvfDSm5.d.ts → jsx-runtime-zHGvMrtA.d.ts} +1 -0
- package/dist/jsx/jsx-runtime.d.ts +1 -1
- package/dist/jsx/jsx-runtime.js +3502 -22
- package/dist/jsx/jsx-runtime.js.map +1 -1
- package/dist/jsx/{jsx-runtime.react-server.js → jsx-runtime.web.js} +2 -2
- package/dist/jsx/jsx-runtime.web.js.map +1 -0
- package/dist/web/index.d.ts +6 -3
- package/dist/web/index.js +223 -17
- package/dist/web/index.js.map +1 -1
- package/package.json +18 -11
- package/dist/jsx/jsx-dev-runtime.react-server.js.map +0 -1
- package/dist/jsx/jsx-runtime.react-server.js.map +0 -1
- /package/dist/jsx/{jsx-dev-runtime.react-server.d.ts → jsx-dev-runtime.web.d.ts} +0 -0
- /package/dist/jsx/{jsx-runtime.react-server.d.ts → jsx-runtime.web.d.ts} +0 -0
- /package/npm/plugin/{esbuild.js → esbuild.mjs} +0 -0
package/dist/default/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { ReactNode, CSSProperties, ElementType, ForwardedRef } from 'react';
|
|
3
|
-
import { BackgroundMaterialType, CornerRadius, SpatialEntity, Vec3, SpatialSession } from '@webspatial/core-sdk';
|
|
3
|
+
import { BackgroundMaterialType, CornerRadius, SpatialEntity, Vec3, SpatialSession, WindowContainerOptions as WindowContainerOptions$1 } from '@webspatial/core-sdk';
|
|
4
4
|
import { ModelViewerElement } from '@google/model-viewer';
|
|
5
5
|
import { WindowContainerOptions } from '@webspatial/core-sdk/';
|
|
6
6
|
|
|
@@ -159,6 +159,9 @@ declare class XRApp {
|
|
|
159
159
|
open: (url?: string, target?: string, features?: string) => Window | null;
|
|
160
160
|
initScene(name: string, callback: (pre: WindowContainerOptions) => WindowContainerOptions): void;
|
|
161
161
|
}
|
|
162
|
-
declare function initScene(name: string, callback: (pre: WindowContainerOptions) => WindowContainerOptions): void;
|
|
163
162
|
|
|
164
|
-
|
|
163
|
+
declare function initScene(name: string, callback: (pre: WindowContainerOptions$1) => WindowContainerOptions$1): void;
|
|
164
|
+
|
|
165
|
+
declare function spatialPolyfill(): void;
|
|
166
|
+
|
|
167
|
+
export { CSSSpatialDiv, CSSSpatialPrimitive, Model, type ModelProps, SpatialDiv, type SpatialReactComponentProps as SpatialDivProps, type SpatialReactComponentRef as SpatialDivRef, SpatialMonitor, SpatialPrimitive, type SpatialReactComponentProps, type SpatialReactComponentRef, SpatialView, type SpatialViewRef, XRApp, defaultSceneConfig, enableDebugTool, getSession, initScene, notifyUpdateStandInstanceLayout, parseCornerRadius, spatialPolyfill, withCSSSpatial, withSpatial, withSpatialMonitor };
|
package/dist/default/index.js
CHANGED
|
@@ -147,7 +147,6 @@ import { Spatial } from "@webspatial/core-sdk";
|
|
|
147
147
|
var spatial = null;
|
|
148
148
|
var _currentSession = null;
|
|
149
149
|
function getSession() {
|
|
150
|
-
if (false) return null;
|
|
151
150
|
if (!spatial) {
|
|
152
151
|
spatial = new Spatial();
|
|
153
152
|
}
|
|
@@ -163,7 +162,6 @@ function getSession() {
|
|
|
163
162
|
|
|
164
163
|
// src/utils/debugTool.ts
|
|
165
164
|
async function getStat() {
|
|
166
|
-
if (false) return;
|
|
167
165
|
const statsInfo = await getSession()._getStats();
|
|
168
166
|
return statsInfo;
|
|
169
167
|
}
|
|
@@ -218,7 +216,6 @@ async function inspectRootWindowContainer(simple) {
|
|
|
218
216
|
return rootWindowContainerInfo;
|
|
219
217
|
}
|
|
220
218
|
function enableDebugTool() {
|
|
221
|
-
if (false) return;
|
|
222
219
|
const session = getSession();
|
|
223
220
|
Object.assign(window, {
|
|
224
221
|
session,
|
|
@@ -477,7 +474,6 @@ var SpatialWindowManager = class {
|
|
|
477
474
|
this.entity?._setName(debugName);
|
|
478
475
|
}
|
|
479
476
|
async initInternal(url) {
|
|
480
|
-
if (false) return;
|
|
481
477
|
this.entity = await getSession().createEntity();
|
|
482
478
|
this.webview = await getSession().createWindowComponent();
|
|
483
479
|
await this.webview.loadURL(url);
|
|
@@ -490,7 +486,6 @@ var SpatialWindowManager = class {
|
|
|
490
486
|
await this.entity.setParent(ent);
|
|
491
487
|
}
|
|
492
488
|
async initInternalFromWindow() {
|
|
493
|
-
if (false) return;
|
|
494
489
|
var w = await getSession().createWindowContext();
|
|
495
490
|
this.window = w;
|
|
496
491
|
this.entity = await getSession().createEntity();
|
|
@@ -756,8 +751,6 @@ var XRApp = class _XRApp {
|
|
|
756
751
|
if (target && target !== "_self") {
|
|
757
752
|
event.preventDefault();
|
|
758
753
|
window.open(url, target);
|
|
759
|
-
} else {
|
|
760
|
-
window.location.href = url;
|
|
761
754
|
}
|
|
762
755
|
}
|
|
763
756
|
}
|
|
@@ -846,9 +839,6 @@ var XRApp = class _XRApp {
|
|
|
846
839
|
this.configMap[name] = callback({ ...defaultSceneConfig });
|
|
847
840
|
}
|
|
848
841
|
};
|
|
849
|
-
function initScene(name, callback) {
|
|
850
|
-
return XRApp.getInstance().initScene(name, callback);
|
|
851
|
-
}
|
|
852
842
|
|
|
853
843
|
// src/spatial-react-components/SpatialReactComponent/PortalInstance.tsx
|
|
854
844
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
@@ -1322,8 +1312,8 @@ function SpatialReactComponentRefactor(inProps, ref) {
|
|
|
1322
1312
|
}
|
|
1323
1313
|
function renderContentInLayer(inProps, ref) {
|
|
1324
1314
|
const isInStandardInstance = useContext4(SpatialIsStandardInstanceContext);
|
|
1325
|
-
const
|
|
1326
|
-
if (isInStandardInstance || !
|
|
1315
|
+
const isWebSpatialEnv2 = getSession() !== null;
|
|
1316
|
+
if (isInStandardInstance || !isWebSpatialEnv2) {
|
|
1327
1317
|
return renderWebReactComponent(inProps, ref);
|
|
1328
1318
|
} else {
|
|
1329
1319
|
const parentSpatialReactContextObject = useContext4(SpatialReactContext);
|
|
@@ -2238,7 +2228,6 @@ var SpatialViewEl = forwardRef8(
|
|
|
2238
2228
|
return /* @__PURE__ */ jsx9("div", { ref: divRef, ...props, children: "WebSpatial is not supported in this browser" });
|
|
2239
2229
|
}
|
|
2240
2230
|
useEffect8(() => {
|
|
2241
|
-
if (false) return;
|
|
2242
2231
|
activePromise.current = runAsync(async () => {
|
|
2243
2232
|
if (activePromise.current) {
|
|
2244
2233
|
await activePromise.current;
|
|
@@ -2251,7 +2240,6 @@ var SpatialViewEl = forwardRef8(
|
|
|
2251
2240
|
}
|
|
2252
2241
|
});
|
|
2253
2242
|
return () => {
|
|
2254
|
-
if (false) return;
|
|
2255
2243
|
runAsync(async () => {
|
|
2256
2244
|
await activePromise.current;
|
|
2257
2245
|
spatialEntity.current?.destroy();
|
|
@@ -2380,7 +2368,6 @@ var Model3DNative = class {
|
|
|
2380
2368
|
return this.initPromise;
|
|
2381
2369
|
}
|
|
2382
2370
|
async initInternal(modelUrl, onSuccess, onFailure) {
|
|
2383
|
-
if (false) return;
|
|
2384
2371
|
var session = getSession();
|
|
2385
2372
|
if (!session) {
|
|
2386
2373
|
return;
|
|
@@ -3582,6 +3569,195 @@ function ModelBase(inProps, ref) {
|
|
|
3582
3569
|
}
|
|
3583
3570
|
var Model = forwardRef11(ModelBase);
|
|
3584
3571
|
Model.displayName = "Model";
|
|
3572
|
+
|
|
3573
|
+
// src/initScene.ts
|
|
3574
|
+
function initScene(name, callback) {
|
|
3575
|
+
return XRApp.getInstance().initScene(name, callback);
|
|
3576
|
+
}
|
|
3577
|
+
|
|
3578
|
+
// src/polyfill/injectSceneHook.ts
|
|
3579
|
+
async function injectSceneHook() {
|
|
3580
|
+
if (!window.opener) return;
|
|
3581
|
+
if (window._SceneHookOff) return;
|
|
3582
|
+
await getSession()?.setLoading("show");
|
|
3583
|
+
function onContentLoaded(callback) {
|
|
3584
|
+
if (document.readyState === "interactive" || document.readyState === "complete") {
|
|
3585
|
+
callback();
|
|
3586
|
+
} else {
|
|
3587
|
+
document.addEventListener("DOMContentLoaded", callback);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
onContentLoaded(async () => {
|
|
3591
|
+
let cfg = defaultSceneConfig;
|
|
3592
|
+
if (typeof window.xrCurrentSceneDefaults === "function") {
|
|
3593
|
+
try {
|
|
3594
|
+
cfg = await window.xrCurrentSceneDefaults?.();
|
|
3595
|
+
} catch (error) {
|
|
3596
|
+
console.error(error);
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
await new Promise((resolve, reject) => {
|
|
3600
|
+
setTimeout(() => {
|
|
3601
|
+
resolve(null);
|
|
3602
|
+
}, 1e3);
|
|
3603
|
+
});
|
|
3604
|
+
await getSession()?.setLoading("hide");
|
|
3605
|
+
await XRApp.getInstance().show(window, cfg);
|
|
3606
|
+
});
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
// src/polyfill/spatialPolyfill.ts
|
|
3610
|
+
var isWebSpatialEnv = getSession() !== null;
|
|
3611
|
+
var SpatialGlobalCustomVars = {
|
|
3612
|
+
backgroundMaterial: "--xr-background-material"
|
|
3613
|
+
};
|
|
3614
|
+
var htmlBackgroundMaterial = "";
|
|
3615
|
+
function setCurrentWindowStyle(backgroundMaterial) {
|
|
3616
|
+
if (backgroundMaterial !== htmlBackgroundMaterial) {
|
|
3617
|
+
const session = getSession();
|
|
3618
|
+
session.getCurrentWindowComponent().setStyle({
|
|
3619
|
+
material: { type: backgroundMaterial }
|
|
3620
|
+
});
|
|
3621
|
+
htmlBackgroundMaterial = backgroundMaterial;
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
function checkHtmlBackgroundMaterial() {
|
|
3625
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3626
|
+
const backgroundMaterial = computedStyle.getPropertyValue(
|
|
3627
|
+
SpatialGlobalCustomVars.backgroundMaterial
|
|
3628
|
+
);
|
|
3629
|
+
setCurrentWindowStyle(backgroundMaterial || "none");
|
|
3630
|
+
}
|
|
3631
|
+
var htmlCornerRadius = {
|
|
3632
|
+
topLeading: 0,
|
|
3633
|
+
bottomLeading: 0,
|
|
3634
|
+
topTrailing: 0,
|
|
3635
|
+
bottomTrailing: 0
|
|
3636
|
+
};
|
|
3637
|
+
function checkCornerRadius() {
|
|
3638
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3639
|
+
const cornerRadius = parseCornerRadius(computedStyle);
|
|
3640
|
+
setCornerRadius(cornerRadius);
|
|
3641
|
+
}
|
|
3642
|
+
function setCornerRadius(cornerRadius) {
|
|
3643
|
+
if (htmlCornerRadius.topLeading !== cornerRadius.topLeading || htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading || htmlCornerRadius.topTrailing !== cornerRadius.topTrailing || htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing) {
|
|
3644
|
+
const session = getSession();
|
|
3645
|
+
if (!session) return;
|
|
3646
|
+
session.getCurrentWindowComponent().setStyle({
|
|
3647
|
+
cornerRadius
|
|
3648
|
+
});
|
|
3649
|
+
htmlCornerRadius.topLeading = cornerRadius.topLeading;
|
|
3650
|
+
htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading;
|
|
3651
|
+
htmlCornerRadius.topTrailing = cornerRadius.topTrailing;
|
|
3652
|
+
htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing;
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
function setOpacity(opacity) {
|
|
3656
|
+
const session = getSession();
|
|
3657
|
+
if (!session) return;
|
|
3658
|
+
session.getCurrentWindowComponent().setOpacity(opacity);
|
|
3659
|
+
}
|
|
3660
|
+
function checkOpacity() {
|
|
3661
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3662
|
+
const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
|
|
3663
|
+
setOpacity(opacity);
|
|
3664
|
+
}
|
|
3665
|
+
async function setHtmlVisible(visible) {
|
|
3666
|
+
const session = getSession();
|
|
3667
|
+
if (!session) return;
|
|
3668
|
+
const wc = session.getCurrentWindowComponent();
|
|
3669
|
+
const ent = await wc.getEntity();
|
|
3670
|
+
ent?.setVisible(visible);
|
|
3671
|
+
}
|
|
3672
|
+
function checkHtmlVisible() {
|
|
3673
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3674
|
+
const visibility = computedStyle.getPropertyValue("visibility") !== "hidden";
|
|
3675
|
+
const widthGtZero = parseFloat(computedStyle.getPropertyValue("width")) > 0;
|
|
3676
|
+
setHtmlVisible(visibility && widthGtZero);
|
|
3677
|
+
}
|
|
3678
|
+
function hijackDocumentElementStyle() {
|
|
3679
|
+
const rawDocumentStyle = document.documentElement.style;
|
|
3680
|
+
const styleProxy = new Proxy(rawDocumentStyle, {
|
|
3681
|
+
set: function(target, key, value) {
|
|
3682
|
+
const ret = Reflect.set(target, key, value);
|
|
3683
|
+
if (key === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3684
|
+
setCurrentWindowStyle(value);
|
|
3685
|
+
}
|
|
3686
|
+
if (key === "border-radius" || key === "borderRadius" || key === "border-top-left-radius" || key === "borderTopLeftRadius" || key === "border-top-right-radius" || key === "borderTopRightRadius" || key === "border-bottom-left-radius" || key === "borderBottomLeftRadius" || key === "border-bottom-right-radius" || key === "borderBottomRightRadius") {
|
|
3687
|
+
checkCornerRadius();
|
|
3688
|
+
}
|
|
3689
|
+
if (key === "opacity") {
|
|
3690
|
+
checkOpacity();
|
|
3691
|
+
}
|
|
3692
|
+
if (key === "visibility" || key === "display") {
|
|
3693
|
+
checkHtmlVisible();
|
|
3694
|
+
}
|
|
3695
|
+
return ret;
|
|
3696
|
+
},
|
|
3697
|
+
get: function(target, prop) {
|
|
3698
|
+
if (typeof target[prop] === "function") {
|
|
3699
|
+
return function(...args) {
|
|
3700
|
+
if (prop === "setProperty") {
|
|
3701
|
+
const [property, value] = args;
|
|
3702
|
+
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3703
|
+
setCurrentWindowStyle(value);
|
|
3704
|
+
}
|
|
3705
|
+
} else if (prop === "removeProperty") {
|
|
3706
|
+
const [property] = args;
|
|
3707
|
+
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3708
|
+
setCurrentWindowStyle("none");
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
return target[prop](
|
|
3712
|
+
...args
|
|
3713
|
+
);
|
|
3714
|
+
};
|
|
3715
|
+
}
|
|
3716
|
+
return Reflect.get(target, prop);
|
|
3717
|
+
}
|
|
3718
|
+
});
|
|
3719
|
+
Object.defineProperty(document.documentElement, "style", {
|
|
3720
|
+
get: function() {
|
|
3721
|
+
return styleProxy;
|
|
3722
|
+
}
|
|
3723
|
+
});
|
|
3724
|
+
}
|
|
3725
|
+
function monitorExternalStyleChange() {
|
|
3726
|
+
const headObserver = new MutationObserver(function(mutationsList) {
|
|
3727
|
+
checkCSSProperties();
|
|
3728
|
+
});
|
|
3729
|
+
headObserver.observe(document.head, { childList: true, subtree: true });
|
|
3730
|
+
}
|
|
3731
|
+
function checkCSSProperties() {
|
|
3732
|
+
checkHtmlBackgroundMaterial();
|
|
3733
|
+
checkCornerRadius();
|
|
3734
|
+
checkOpacity();
|
|
3735
|
+
checkHtmlVisible();
|
|
3736
|
+
window.addEventListener("resize", checkHtmlVisible);
|
|
3737
|
+
}
|
|
3738
|
+
function hijackGetComputedStyle() {
|
|
3739
|
+
const rawFn = window.getComputedStyle.bind(window);
|
|
3740
|
+
window.getComputedStyle = (element, pseudoElt) => {
|
|
3741
|
+
if (element.__isSpatialDiv) {
|
|
3742
|
+
return element.__getComputedStyle(rawFn, pseudoElt);
|
|
3743
|
+
}
|
|
3744
|
+
return rawFn(element, pseudoElt);
|
|
3745
|
+
};
|
|
3746
|
+
}
|
|
3747
|
+
function hijackWindowOpen() {
|
|
3748
|
+
XRApp.getInstance().init();
|
|
3749
|
+
}
|
|
3750
|
+
function spatialPolyfill() {
|
|
3751
|
+
if (!isWebSpatialEnv) {
|
|
3752
|
+
return;
|
|
3753
|
+
}
|
|
3754
|
+
injectSceneHook();
|
|
3755
|
+
hijackWindowOpen();
|
|
3756
|
+
checkCSSProperties();
|
|
3757
|
+
hijackGetComputedStyle();
|
|
3758
|
+
hijackDocumentElementStyle();
|
|
3759
|
+
monitorExternalStyleChange();
|
|
3760
|
+
}
|
|
3585
3761
|
export {
|
|
3586
3762
|
CSSSpatialDiv,
|
|
3587
3763
|
CSSSpatialPrimitive,
|
|
@@ -3597,6 +3773,7 @@ export {
|
|
|
3597
3773
|
initScene,
|
|
3598
3774
|
notifyUpdateStandInstanceLayout,
|
|
3599
3775
|
parseCornerRadius,
|
|
3776
|
+
spatialPolyfill,
|
|
3600
3777
|
withCSSSpatial,
|
|
3601
3778
|
withSpatial,
|
|
3602
3779
|
withSpatialMonitor
|