@webspatial/react-sdk 0.1.10 → 0.1.13
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 +41 -7
- package/dist/default/index.js +208 -18
- 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 +15 -5
- package/dist/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.web.js +18 -0
- 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 +15 -5
- package/dist/jsx/jsx-runtime.js.map +1 -1
- package/dist/jsx/jsx-runtime.web.js +18 -0
- package/dist/jsx/jsx-runtime.web.js.map +1 -0
- package/dist/web/index.d.ts +41 -7
- package/dist/web/index.js +239 -20
- package/dist/web/index.js.map +1 -1
- package/package.json +18 -13
- package/dist/jsx/jsx-dev-runtime.react-server.js +0 -9
- package/dist/jsx/jsx-dev-runtime.react-server.js.map +0 -1
- package/dist/jsx/jsx-runtime.react-server.js +0 -9
- package/dist/jsx/jsx-runtime.react-server.js.map +0 -1
- package/npm/plugin/esbuild.js +0 -11
- package/npm/plugin/rollup.js +0 -8
- package/npm/plugin/shared.js +0 -9
- package/npm/plugin/vite.d.ts +0 -5
- package/npm/plugin/vite.js +0 -86
- package/npm/plugin/webpack.js +0 -9
- /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/dist/web/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
(function(){
|
|
3
|
+
if(typeof window === 'undefined') return;
|
|
4
|
+
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "0.1.13"
|
|
6
|
+
window.__webspatialsdk__['XR_ENV'] = "web"
|
|
7
|
+
})()
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
// src/spatial-react-components/SpatialPrimitive.tsx
|
|
2
11
|
import { forwardRef as forwardRef3 } from "react";
|
|
3
12
|
|
|
@@ -144,13 +153,41 @@ import { forwardRef as forwardRef2, useMemo as useMemo2, useContext as useContex
|
|
|
144
153
|
|
|
145
154
|
// src/noRuntime.ts
|
|
146
155
|
var SpatialHelper = {};
|
|
147
|
-
var Spatial = {
|
|
156
|
+
var Spatial = class {
|
|
157
|
+
/**
|
|
158
|
+
* Requests a session object from the browser
|
|
159
|
+
* @returns The session or null if not availible in the current browser
|
|
160
|
+
* [TODO] discuss implications of this not being async
|
|
161
|
+
*/
|
|
162
|
+
requestSession() {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @returns true if web spatial is supported by this webpage
|
|
167
|
+
*/
|
|
168
|
+
isSupported() {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Gets the native version, format is "x.x.x"
|
|
173
|
+
* @returns native version string
|
|
174
|
+
*/
|
|
175
|
+
getNativeVersion() {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Gets the client version, format is "x.x.x"
|
|
180
|
+
* @returns client version string
|
|
181
|
+
*/
|
|
182
|
+
getClientVersion() {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
148
186
|
|
|
149
187
|
// src/utils/getSession.ts
|
|
150
188
|
var spatial = null;
|
|
151
189
|
var _currentSession = null;
|
|
152
190
|
function getSession() {
|
|
153
|
-
if (true) return null;
|
|
154
191
|
if (!spatial) {
|
|
155
192
|
spatial = new Spatial();
|
|
156
193
|
}
|
|
@@ -166,7 +203,6 @@ function getSession() {
|
|
|
166
203
|
|
|
167
204
|
// src/utils/debugTool.ts
|
|
168
205
|
async function getStat() {
|
|
169
|
-
if (true) return;
|
|
170
206
|
const statsInfo = await getSession()._getStats();
|
|
171
207
|
return statsInfo;
|
|
172
208
|
}
|
|
@@ -221,7 +257,6 @@ async function inspectRootWindowContainer(simple) {
|
|
|
221
257
|
return rootWindowContainerInfo;
|
|
222
258
|
}
|
|
223
259
|
function enableDebugTool() {
|
|
224
|
-
if (true) return;
|
|
225
260
|
const session = getSession();
|
|
226
261
|
Object.assign(window, {
|
|
227
262
|
session,
|
|
@@ -480,7 +515,6 @@ var SpatialWindowManager = class {
|
|
|
480
515
|
this.entity?._setName(debugName);
|
|
481
516
|
}
|
|
482
517
|
async initInternal(url) {
|
|
483
|
-
if (true) return;
|
|
484
518
|
this.entity = await getSession().createEntity();
|
|
485
519
|
this.webview = await getSession().createWindowComponent();
|
|
486
520
|
await this.webview.loadURL(url);
|
|
@@ -493,7 +527,6 @@ var SpatialWindowManager = class {
|
|
|
493
527
|
await this.entity.setParent(ent);
|
|
494
528
|
}
|
|
495
529
|
async initInternalFromWindow() {
|
|
496
|
-
if (true) return;
|
|
497
530
|
var w = await getSession().createWindowContext();
|
|
498
531
|
this.window = w;
|
|
499
532
|
this.entity = await getSession().createEntity();
|
|
@@ -667,7 +700,8 @@ function getInheritedStyleProps(computedStyle) {
|
|
|
667
700
|
// position also need to be synced
|
|
668
701
|
"position",
|
|
669
702
|
"width",
|
|
670
|
-
"height"
|
|
703
|
+
"height",
|
|
704
|
+
"display"
|
|
671
705
|
];
|
|
672
706
|
var props = {};
|
|
673
707
|
for (var cssName of propNames) {
|
|
@@ -759,8 +793,6 @@ var XRApp = class _XRApp {
|
|
|
759
793
|
if (target && target !== "_self") {
|
|
760
794
|
event.preventDefault();
|
|
761
795
|
window.open(url, target);
|
|
762
|
-
} else {
|
|
763
|
-
window.location.href = url;
|
|
764
796
|
}
|
|
765
797
|
}
|
|
766
798
|
}
|
|
@@ -849,9 +881,6 @@ var XRApp = class _XRApp {
|
|
|
849
881
|
this.configMap[name] = callback({ ...defaultSceneConfig });
|
|
850
882
|
}
|
|
851
883
|
};
|
|
852
|
-
function initScene(name, callback) {
|
|
853
|
-
return XRApp.getInstance().initScene(name, callback);
|
|
854
|
-
}
|
|
855
884
|
|
|
856
885
|
// src/spatial-react-components/SpatialReactComponent/PortalInstance.tsx
|
|
857
886
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
@@ -868,8 +897,7 @@ function renderJSXPortalInstance(inProps, inheritedPortalStyle, className) {
|
|
|
868
897
|
marginTop: "0px",
|
|
869
898
|
marginBottom: "0px",
|
|
870
899
|
borderRadius: "0px",
|
|
871
|
-
overflow: ""
|
|
872
|
-
display: "block"
|
|
900
|
+
overflow: ""
|
|
873
901
|
};
|
|
874
902
|
const style = {
|
|
875
903
|
...inStyle,
|
|
@@ -1325,8 +1353,8 @@ function SpatialReactComponentRefactor(inProps, ref) {
|
|
|
1325
1353
|
}
|
|
1326
1354
|
function renderContentInLayer(inProps, ref) {
|
|
1327
1355
|
const isInStandardInstance = useContext4(SpatialIsStandardInstanceContext);
|
|
1328
|
-
const
|
|
1329
|
-
if (isInStandardInstance || !
|
|
1356
|
+
const isWebSpatialEnv2 = getSession() !== null;
|
|
1357
|
+
if (isInStandardInstance || !isWebSpatialEnv2) {
|
|
1330
1358
|
return renderWebReactComponent(inProps, ref);
|
|
1331
1359
|
} else {
|
|
1332
1360
|
const parentSpatialReactContextObject = useContext4(SpatialReactContext);
|
|
@@ -2122,7 +2150,7 @@ function renderInPortalInstance(cssSpatialRootContextObject, cssSpatialID, inPro
|
|
|
2122
2150
|
}
|
|
2123
2151
|
function CSSSpatialComponentBase(inProps, ref) {
|
|
2124
2152
|
const { [CSSSpatialID]: cssSpatialID, ...props } = inProps;
|
|
2125
|
-
const isWebEnv =
|
|
2153
|
+
const isWebEnv = !getSession();
|
|
2126
2154
|
if (isWebEnv) {
|
|
2127
2155
|
return renderInWebEnv(props, ref);
|
|
2128
2156
|
} else {
|
|
@@ -2240,7 +2268,6 @@ var SpatialViewEl = forwardRef8(
|
|
|
2240
2268
|
return /* @__PURE__ */ jsx9("div", { ref: divRef, ...props, children: "WebSpatial is not supported in this browser" });
|
|
2241
2269
|
}
|
|
2242
2270
|
useEffect8(() => {
|
|
2243
|
-
if (true) return;
|
|
2244
2271
|
activePromise.current = runAsync(async () => {
|
|
2245
2272
|
if (activePromise.current) {
|
|
2246
2273
|
await activePromise.current;
|
|
@@ -2253,7 +2280,6 @@ var SpatialViewEl = forwardRef8(
|
|
|
2253
2280
|
}
|
|
2254
2281
|
});
|
|
2255
2282
|
return () => {
|
|
2256
|
-
if (true) return;
|
|
2257
2283
|
runAsync(async () => {
|
|
2258
2284
|
await activePromise.current;
|
|
2259
2285
|
spatialEntity.current?.destroy();
|
|
@@ -2382,7 +2408,6 @@ var Model3DNative = class {
|
|
|
2382
2408
|
return this.initPromise;
|
|
2383
2409
|
}
|
|
2384
2410
|
async initInternal(modelUrl, onSuccess, onFailure) {
|
|
2385
|
-
if (true) return;
|
|
2386
2411
|
var session = getSession();
|
|
2387
2412
|
if (!session) {
|
|
2388
2413
|
return;
|
|
@@ -3584,6 +3609,198 @@ function ModelBase(inProps, ref) {
|
|
|
3584
3609
|
}
|
|
3585
3610
|
var Model = forwardRef11(ModelBase);
|
|
3586
3611
|
Model.displayName = "Model";
|
|
3612
|
+
|
|
3613
|
+
// src/initScene.web.ts
|
|
3614
|
+
function initScene(name, callback) {
|
|
3615
|
+
return;
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
// src/polyfill/injectSceneHook.ts
|
|
3619
|
+
async function injectSceneHook() {
|
|
3620
|
+
if (!window.opener) return;
|
|
3621
|
+
if (window._SceneHookOff) return;
|
|
3622
|
+
await getSession()?.setLoading("show");
|
|
3623
|
+
function onContentLoaded(callback) {
|
|
3624
|
+
if (document.readyState === "interactive" || document.readyState === "complete") {
|
|
3625
|
+
callback();
|
|
3626
|
+
} else {
|
|
3627
|
+
document.addEventListener("DOMContentLoaded", callback);
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
onContentLoaded(async () => {
|
|
3631
|
+
let cfg = defaultSceneConfig;
|
|
3632
|
+
if (typeof window.xrCurrentSceneDefaults === "function") {
|
|
3633
|
+
try {
|
|
3634
|
+
cfg = await window.xrCurrentSceneDefaults?.();
|
|
3635
|
+
} catch (error) {
|
|
3636
|
+
console.error(error);
|
|
3637
|
+
}
|
|
3638
|
+
}
|
|
3639
|
+
await new Promise((resolve, reject) => {
|
|
3640
|
+
setTimeout(() => {
|
|
3641
|
+
resolve(null);
|
|
3642
|
+
}, 1e3);
|
|
3643
|
+
});
|
|
3644
|
+
await getSession()?.setLoading("hide");
|
|
3645
|
+
await XRApp.getInstance().show(window, cfg);
|
|
3646
|
+
});
|
|
3647
|
+
}
|
|
3648
|
+
|
|
3649
|
+
// src/polyfill/spatialPolyfill.ts
|
|
3650
|
+
var isWebSpatialEnv = getSession() !== null;
|
|
3651
|
+
var SpatialGlobalCustomVars = {
|
|
3652
|
+
backgroundMaterial: "--xr-background-material"
|
|
3653
|
+
};
|
|
3654
|
+
var htmlBackgroundMaterial = "";
|
|
3655
|
+
function setCurrentWindowStyle(backgroundMaterial) {
|
|
3656
|
+
if (backgroundMaterial !== htmlBackgroundMaterial) {
|
|
3657
|
+
const session = getSession();
|
|
3658
|
+
session.getCurrentWindowComponent().setStyle({
|
|
3659
|
+
material: { type: backgroundMaterial }
|
|
3660
|
+
});
|
|
3661
|
+
htmlBackgroundMaterial = backgroundMaterial;
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
function checkHtmlBackgroundMaterial() {
|
|
3665
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3666
|
+
const backgroundMaterial = computedStyle.getPropertyValue(
|
|
3667
|
+
SpatialGlobalCustomVars.backgroundMaterial
|
|
3668
|
+
);
|
|
3669
|
+
setCurrentWindowStyle(backgroundMaterial || "none");
|
|
3670
|
+
}
|
|
3671
|
+
var htmlCornerRadius = {
|
|
3672
|
+
topLeading: 0,
|
|
3673
|
+
bottomLeading: 0,
|
|
3674
|
+
topTrailing: 0,
|
|
3675
|
+
bottomTrailing: 0
|
|
3676
|
+
};
|
|
3677
|
+
function checkCornerRadius() {
|
|
3678
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3679
|
+
const cornerRadius = parseCornerRadius(computedStyle);
|
|
3680
|
+
setCornerRadius(cornerRadius);
|
|
3681
|
+
}
|
|
3682
|
+
function setCornerRadius(cornerRadius) {
|
|
3683
|
+
if (htmlCornerRadius.topLeading !== cornerRadius.topLeading || htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading || htmlCornerRadius.topTrailing !== cornerRadius.topTrailing || htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing) {
|
|
3684
|
+
const session = getSession();
|
|
3685
|
+
if (!session) return;
|
|
3686
|
+
session.getCurrentWindowComponent().setStyle({
|
|
3687
|
+
cornerRadius
|
|
3688
|
+
});
|
|
3689
|
+
htmlCornerRadius.topLeading = cornerRadius.topLeading;
|
|
3690
|
+
htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading;
|
|
3691
|
+
htmlCornerRadius.topTrailing = cornerRadius.topTrailing;
|
|
3692
|
+
htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing;
|
|
3693
|
+
}
|
|
3694
|
+
}
|
|
3695
|
+
function setOpacity(opacity) {
|
|
3696
|
+
const session = getSession();
|
|
3697
|
+
if (!session) return;
|
|
3698
|
+
session.getCurrentWindowComponent().setOpacity(opacity);
|
|
3699
|
+
}
|
|
3700
|
+
function checkOpacity() {
|
|
3701
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3702
|
+
const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
|
|
3703
|
+
setOpacity(opacity);
|
|
3704
|
+
}
|
|
3705
|
+
async function setHtmlVisible(visible) {
|
|
3706
|
+
const session = getSession();
|
|
3707
|
+
if (!session) return;
|
|
3708
|
+
const wc = session.getCurrentWindowComponent();
|
|
3709
|
+
const ent = await wc.getEntity();
|
|
3710
|
+
ent?.setVisible(visible);
|
|
3711
|
+
}
|
|
3712
|
+
function checkHtmlVisible() {
|
|
3713
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3714
|
+
const visibility = computedStyle.getPropertyValue("visibility") !== "hidden";
|
|
3715
|
+
const widthGtZero = parseFloat(computedStyle.getPropertyValue("width")) > 0;
|
|
3716
|
+
setHtmlVisible(visibility && widthGtZero);
|
|
3717
|
+
}
|
|
3718
|
+
function hijackDocumentElementStyle() {
|
|
3719
|
+
const rawDocumentStyle = document.documentElement.style;
|
|
3720
|
+
const styleProxy = new Proxy(rawDocumentStyle, {
|
|
3721
|
+
set: function(target, key, value) {
|
|
3722
|
+
const ret = Reflect.set(target, key, value);
|
|
3723
|
+
if (key === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3724
|
+
setCurrentWindowStyle(value);
|
|
3725
|
+
}
|
|
3726
|
+
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") {
|
|
3727
|
+
checkCornerRadius();
|
|
3728
|
+
}
|
|
3729
|
+
if (key === "opacity") {
|
|
3730
|
+
checkOpacity();
|
|
3731
|
+
}
|
|
3732
|
+
if (key === "visibility" || key === "display") {
|
|
3733
|
+
checkHtmlVisible();
|
|
3734
|
+
}
|
|
3735
|
+
return ret;
|
|
3736
|
+
},
|
|
3737
|
+
get: function(target, prop) {
|
|
3738
|
+
if (typeof target[prop] === "function") {
|
|
3739
|
+
return function(...args) {
|
|
3740
|
+
if (prop === "setProperty") {
|
|
3741
|
+
const [property, value] = args;
|
|
3742
|
+
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3743
|
+
setCurrentWindowStyle(value);
|
|
3744
|
+
}
|
|
3745
|
+
} else if (prop === "removeProperty") {
|
|
3746
|
+
const [property] = args;
|
|
3747
|
+
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3748
|
+
setCurrentWindowStyle("none");
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
return target[prop](
|
|
3752
|
+
...args
|
|
3753
|
+
);
|
|
3754
|
+
};
|
|
3755
|
+
}
|
|
3756
|
+
return Reflect.get(target, prop);
|
|
3757
|
+
}
|
|
3758
|
+
});
|
|
3759
|
+
Object.defineProperty(document.documentElement, "style", {
|
|
3760
|
+
get: function() {
|
|
3761
|
+
return styleProxy;
|
|
3762
|
+
}
|
|
3763
|
+
});
|
|
3764
|
+
}
|
|
3765
|
+
function monitorExternalStyleChange() {
|
|
3766
|
+
const headObserver = new MutationObserver(function(mutationsList) {
|
|
3767
|
+
checkCSSProperties();
|
|
3768
|
+
});
|
|
3769
|
+
headObserver.observe(document.head, { childList: true, subtree: true });
|
|
3770
|
+
}
|
|
3771
|
+
function checkCSSProperties() {
|
|
3772
|
+
checkHtmlBackgroundMaterial();
|
|
3773
|
+
checkCornerRadius();
|
|
3774
|
+
checkOpacity();
|
|
3775
|
+
checkHtmlVisible();
|
|
3776
|
+
window.addEventListener("resize", checkHtmlVisible);
|
|
3777
|
+
}
|
|
3778
|
+
function hijackGetComputedStyle() {
|
|
3779
|
+
const rawFn = window.getComputedStyle.bind(window);
|
|
3780
|
+
window.getComputedStyle = (element, pseudoElt) => {
|
|
3781
|
+
if (element.__isSpatialDiv) {
|
|
3782
|
+
return element.__getComputedStyle(rawFn, pseudoElt);
|
|
3783
|
+
}
|
|
3784
|
+
return rawFn(element, pseudoElt);
|
|
3785
|
+
};
|
|
3786
|
+
}
|
|
3787
|
+
function hijackWindowOpen() {
|
|
3788
|
+
XRApp.getInstance().init();
|
|
3789
|
+
}
|
|
3790
|
+
function spatialPolyfill() {
|
|
3791
|
+
if (!isWebSpatialEnv) {
|
|
3792
|
+
return;
|
|
3793
|
+
}
|
|
3794
|
+
injectSceneHook();
|
|
3795
|
+
hijackWindowOpen();
|
|
3796
|
+
checkCSSProperties();
|
|
3797
|
+
hijackGetComputedStyle();
|
|
3798
|
+
hijackDocumentElementStyle();
|
|
3799
|
+
monitorExternalStyleChange();
|
|
3800
|
+
}
|
|
3801
|
+
|
|
3802
|
+
// src/index.ts
|
|
3803
|
+
var version = "0.1.13";
|
|
3587
3804
|
export {
|
|
3588
3805
|
CSSSpatialDiv,
|
|
3589
3806
|
CSSSpatialPrimitive,
|
|
@@ -3599,6 +3816,8 @@ export {
|
|
|
3599
3816
|
initScene,
|
|
3600
3817
|
notifyUpdateStandInstanceLayout,
|
|
3601
3818
|
parseCornerRadius,
|
|
3819
|
+
spatialPolyfill,
|
|
3820
|
+
version,
|
|
3602
3821
|
withCSSSpatial,
|
|
3603
3822
|
withSpatial,
|
|
3604
3823
|
withSpatialMonitor
|