@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/web/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/web/index.js
CHANGED
|
@@ -144,13 +144,41 @@ import { forwardRef as forwardRef2, useMemo as useMemo2, useContext as useContex
|
|
|
144
144
|
|
|
145
145
|
// src/noRuntime.ts
|
|
146
146
|
var SpatialHelper = {};
|
|
147
|
-
var Spatial = {
|
|
147
|
+
var Spatial = class {
|
|
148
|
+
/**
|
|
149
|
+
* Requests a session object from the browser
|
|
150
|
+
* @returns The session or null if not availible in the current browser
|
|
151
|
+
* [TODO] discuss implications of this not being async
|
|
152
|
+
*/
|
|
153
|
+
requestSession() {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @returns true if web spatial is supported by this webpage
|
|
158
|
+
*/
|
|
159
|
+
isSupported() {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Gets the native version, format is "x.x.x"
|
|
164
|
+
* @returns native version string
|
|
165
|
+
*/
|
|
166
|
+
getNativeVersion() {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Gets the client version, format is "x.x.x"
|
|
171
|
+
* @returns client version string
|
|
172
|
+
*/
|
|
173
|
+
getClientVersion() {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
148
177
|
|
|
149
178
|
// src/utils/getSession.ts
|
|
150
179
|
var spatial = null;
|
|
151
180
|
var _currentSession = null;
|
|
152
181
|
function getSession() {
|
|
153
|
-
if (true) return null;
|
|
154
182
|
if (!spatial) {
|
|
155
183
|
spatial = new Spatial();
|
|
156
184
|
}
|
|
@@ -166,7 +194,6 @@ function getSession() {
|
|
|
166
194
|
|
|
167
195
|
// src/utils/debugTool.ts
|
|
168
196
|
async function getStat() {
|
|
169
|
-
if (true) return;
|
|
170
197
|
const statsInfo = await getSession()._getStats();
|
|
171
198
|
return statsInfo;
|
|
172
199
|
}
|
|
@@ -221,7 +248,6 @@ async function inspectRootWindowContainer(simple) {
|
|
|
221
248
|
return rootWindowContainerInfo;
|
|
222
249
|
}
|
|
223
250
|
function enableDebugTool() {
|
|
224
|
-
if (true) return;
|
|
225
251
|
const session = getSession();
|
|
226
252
|
Object.assign(window, {
|
|
227
253
|
session,
|
|
@@ -480,7 +506,6 @@ var SpatialWindowManager = class {
|
|
|
480
506
|
this.entity?._setName(debugName);
|
|
481
507
|
}
|
|
482
508
|
async initInternal(url) {
|
|
483
|
-
if (true) return;
|
|
484
509
|
this.entity = await getSession().createEntity();
|
|
485
510
|
this.webview = await getSession().createWindowComponent();
|
|
486
511
|
await this.webview.loadURL(url);
|
|
@@ -493,7 +518,6 @@ var SpatialWindowManager = class {
|
|
|
493
518
|
await this.entity.setParent(ent);
|
|
494
519
|
}
|
|
495
520
|
async initInternalFromWindow() {
|
|
496
|
-
if (true) return;
|
|
497
521
|
var w = await getSession().createWindowContext();
|
|
498
522
|
this.window = w;
|
|
499
523
|
this.entity = await getSession().createEntity();
|
|
@@ -759,8 +783,6 @@ var XRApp = class _XRApp {
|
|
|
759
783
|
if (target && target !== "_self") {
|
|
760
784
|
event.preventDefault();
|
|
761
785
|
window.open(url, target);
|
|
762
|
-
} else {
|
|
763
|
-
window.location.href = url;
|
|
764
786
|
}
|
|
765
787
|
}
|
|
766
788
|
}
|
|
@@ -849,9 +871,6 @@ var XRApp = class _XRApp {
|
|
|
849
871
|
this.configMap[name] = callback({ ...defaultSceneConfig });
|
|
850
872
|
}
|
|
851
873
|
};
|
|
852
|
-
function initScene(name, callback) {
|
|
853
|
-
return XRApp.getInstance().initScene(name, callback);
|
|
854
|
-
}
|
|
855
874
|
|
|
856
875
|
// src/spatial-react-components/SpatialReactComponent/PortalInstance.tsx
|
|
857
876
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
@@ -1325,8 +1344,8 @@ function SpatialReactComponentRefactor(inProps, ref) {
|
|
|
1325
1344
|
}
|
|
1326
1345
|
function renderContentInLayer(inProps, ref) {
|
|
1327
1346
|
const isInStandardInstance = useContext4(SpatialIsStandardInstanceContext);
|
|
1328
|
-
const
|
|
1329
|
-
if (isInStandardInstance || !
|
|
1347
|
+
const isWebSpatialEnv2 = getSession() !== null;
|
|
1348
|
+
if (isInStandardInstance || !isWebSpatialEnv2) {
|
|
1330
1349
|
return renderWebReactComponent(inProps, ref);
|
|
1331
1350
|
} else {
|
|
1332
1351
|
const parentSpatialReactContextObject = useContext4(SpatialReactContext);
|
|
@@ -2122,7 +2141,7 @@ function renderInPortalInstance(cssSpatialRootContextObject, cssSpatialID, inPro
|
|
|
2122
2141
|
}
|
|
2123
2142
|
function CSSSpatialComponentBase(inProps, ref) {
|
|
2124
2143
|
const { [CSSSpatialID]: cssSpatialID, ...props } = inProps;
|
|
2125
|
-
const isWebEnv =
|
|
2144
|
+
const isWebEnv = !getSession();
|
|
2126
2145
|
if (isWebEnv) {
|
|
2127
2146
|
return renderInWebEnv(props, ref);
|
|
2128
2147
|
} else {
|
|
@@ -2240,7 +2259,6 @@ var SpatialViewEl = forwardRef8(
|
|
|
2240
2259
|
return /* @__PURE__ */ jsx9("div", { ref: divRef, ...props, children: "WebSpatial is not supported in this browser" });
|
|
2241
2260
|
}
|
|
2242
2261
|
useEffect8(() => {
|
|
2243
|
-
if (true) return;
|
|
2244
2262
|
activePromise.current = runAsync(async () => {
|
|
2245
2263
|
if (activePromise.current) {
|
|
2246
2264
|
await activePromise.current;
|
|
@@ -2253,7 +2271,6 @@ var SpatialViewEl = forwardRef8(
|
|
|
2253
2271
|
}
|
|
2254
2272
|
});
|
|
2255
2273
|
return () => {
|
|
2256
|
-
if (true) return;
|
|
2257
2274
|
runAsync(async () => {
|
|
2258
2275
|
await activePromise.current;
|
|
2259
2276
|
spatialEntity.current?.destroy();
|
|
@@ -2382,7 +2399,6 @@ var Model3DNative = class {
|
|
|
2382
2399
|
return this.initPromise;
|
|
2383
2400
|
}
|
|
2384
2401
|
async initInternal(modelUrl, onSuccess, onFailure) {
|
|
2385
|
-
if (true) return;
|
|
2386
2402
|
var session = getSession();
|
|
2387
2403
|
if (!session) {
|
|
2388
2404
|
return;
|
|
@@ -3584,6 +3600,195 @@ function ModelBase(inProps, ref) {
|
|
|
3584
3600
|
}
|
|
3585
3601
|
var Model = forwardRef11(ModelBase);
|
|
3586
3602
|
Model.displayName = "Model";
|
|
3603
|
+
|
|
3604
|
+
// src/initScene.web.ts
|
|
3605
|
+
function initScene(name, callback) {
|
|
3606
|
+
return;
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
// src/polyfill/injectSceneHook.ts
|
|
3610
|
+
async function injectSceneHook() {
|
|
3611
|
+
if (!window.opener) return;
|
|
3612
|
+
if (window._SceneHookOff) return;
|
|
3613
|
+
await getSession()?.setLoading("show");
|
|
3614
|
+
function onContentLoaded(callback) {
|
|
3615
|
+
if (document.readyState === "interactive" || document.readyState === "complete") {
|
|
3616
|
+
callback();
|
|
3617
|
+
} else {
|
|
3618
|
+
document.addEventListener("DOMContentLoaded", callback);
|
|
3619
|
+
}
|
|
3620
|
+
}
|
|
3621
|
+
onContentLoaded(async () => {
|
|
3622
|
+
let cfg = defaultSceneConfig;
|
|
3623
|
+
if (typeof window.xrCurrentSceneDefaults === "function") {
|
|
3624
|
+
try {
|
|
3625
|
+
cfg = await window.xrCurrentSceneDefaults?.();
|
|
3626
|
+
} catch (error) {
|
|
3627
|
+
console.error(error);
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
await new Promise((resolve, reject) => {
|
|
3631
|
+
setTimeout(() => {
|
|
3632
|
+
resolve(null);
|
|
3633
|
+
}, 1e3);
|
|
3634
|
+
});
|
|
3635
|
+
await getSession()?.setLoading("hide");
|
|
3636
|
+
await XRApp.getInstance().show(window, cfg);
|
|
3637
|
+
});
|
|
3638
|
+
}
|
|
3639
|
+
|
|
3640
|
+
// src/polyfill/spatialPolyfill.ts
|
|
3641
|
+
var isWebSpatialEnv = getSession() !== null;
|
|
3642
|
+
var SpatialGlobalCustomVars = {
|
|
3643
|
+
backgroundMaterial: "--xr-background-material"
|
|
3644
|
+
};
|
|
3645
|
+
var htmlBackgroundMaterial = "";
|
|
3646
|
+
function setCurrentWindowStyle(backgroundMaterial) {
|
|
3647
|
+
if (backgroundMaterial !== htmlBackgroundMaterial) {
|
|
3648
|
+
const session = getSession();
|
|
3649
|
+
session.getCurrentWindowComponent().setStyle({
|
|
3650
|
+
material: { type: backgroundMaterial }
|
|
3651
|
+
});
|
|
3652
|
+
htmlBackgroundMaterial = backgroundMaterial;
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
function checkHtmlBackgroundMaterial() {
|
|
3656
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3657
|
+
const backgroundMaterial = computedStyle.getPropertyValue(
|
|
3658
|
+
SpatialGlobalCustomVars.backgroundMaterial
|
|
3659
|
+
);
|
|
3660
|
+
setCurrentWindowStyle(backgroundMaterial || "none");
|
|
3661
|
+
}
|
|
3662
|
+
var htmlCornerRadius = {
|
|
3663
|
+
topLeading: 0,
|
|
3664
|
+
bottomLeading: 0,
|
|
3665
|
+
topTrailing: 0,
|
|
3666
|
+
bottomTrailing: 0
|
|
3667
|
+
};
|
|
3668
|
+
function checkCornerRadius() {
|
|
3669
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3670
|
+
const cornerRadius = parseCornerRadius(computedStyle);
|
|
3671
|
+
setCornerRadius(cornerRadius);
|
|
3672
|
+
}
|
|
3673
|
+
function setCornerRadius(cornerRadius) {
|
|
3674
|
+
if (htmlCornerRadius.topLeading !== cornerRadius.topLeading || htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading || htmlCornerRadius.topTrailing !== cornerRadius.topTrailing || htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing) {
|
|
3675
|
+
const session = getSession();
|
|
3676
|
+
if (!session) return;
|
|
3677
|
+
session.getCurrentWindowComponent().setStyle({
|
|
3678
|
+
cornerRadius
|
|
3679
|
+
});
|
|
3680
|
+
htmlCornerRadius.topLeading = cornerRadius.topLeading;
|
|
3681
|
+
htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading;
|
|
3682
|
+
htmlCornerRadius.topTrailing = cornerRadius.topTrailing;
|
|
3683
|
+
htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing;
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
function setOpacity(opacity) {
|
|
3687
|
+
const session = getSession();
|
|
3688
|
+
if (!session) return;
|
|
3689
|
+
session.getCurrentWindowComponent().setOpacity(opacity);
|
|
3690
|
+
}
|
|
3691
|
+
function checkOpacity() {
|
|
3692
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3693
|
+
const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
|
|
3694
|
+
setOpacity(opacity);
|
|
3695
|
+
}
|
|
3696
|
+
async function setHtmlVisible(visible) {
|
|
3697
|
+
const session = getSession();
|
|
3698
|
+
if (!session) return;
|
|
3699
|
+
const wc = session.getCurrentWindowComponent();
|
|
3700
|
+
const ent = await wc.getEntity();
|
|
3701
|
+
ent?.setVisible(visible);
|
|
3702
|
+
}
|
|
3703
|
+
function checkHtmlVisible() {
|
|
3704
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
3705
|
+
const visibility = computedStyle.getPropertyValue("visibility") !== "hidden";
|
|
3706
|
+
const widthGtZero = parseFloat(computedStyle.getPropertyValue("width")) > 0;
|
|
3707
|
+
setHtmlVisible(visibility && widthGtZero);
|
|
3708
|
+
}
|
|
3709
|
+
function hijackDocumentElementStyle() {
|
|
3710
|
+
const rawDocumentStyle = document.documentElement.style;
|
|
3711
|
+
const styleProxy = new Proxy(rawDocumentStyle, {
|
|
3712
|
+
set: function(target, key, value) {
|
|
3713
|
+
const ret = Reflect.set(target, key, value);
|
|
3714
|
+
if (key === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3715
|
+
setCurrentWindowStyle(value);
|
|
3716
|
+
}
|
|
3717
|
+
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") {
|
|
3718
|
+
checkCornerRadius();
|
|
3719
|
+
}
|
|
3720
|
+
if (key === "opacity") {
|
|
3721
|
+
checkOpacity();
|
|
3722
|
+
}
|
|
3723
|
+
if (key === "visibility" || key === "display") {
|
|
3724
|
+
checkHtmlVisible();
|
|
3725
|
+
}
|
|
3726
|
+
return ret;
|
|
3727
|
+
},
|
|
3728
|
+
get: function(target, prop) {
|
|
3729
|
+
if (typeof target[prop] === "function") {
|
|
3730
|
+
return function(...args) {
|
|
3731
|
+
if (prop === "setProperty") {
|
|
3732
|
+
const [property, value] = args;
|
|
3733
|
+
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3734
|
+
setCurrentWindowStyle(value);
|
|
3735
|
+
}
|
|
3736
|
+
} else if (prop === "removeProperty") {
|
|
3737
|
+
const [property] = args;
|
|
3738
|
+
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3739
|
+
setCurrentWindowStyle("none");
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
return target[prop](
|
|
3743
|
+
...args
|
|
3744
|
+
);
|
|
3745
|
+
};
|
|
3746
|
+
}
|
|
3747
|
+
return Reflect.get(target, prop);
|
|
3748
|
+
}
|
|
3749
|
+
});
|
|
3750
|
+
Object.defineProperty(document.documentElement, "style", {
|
|
3751
|
+
get: function() {
|
|
3752
|
+
return styleProxy;
|
|
3753
|
+
}
|
|
3754
|
+
});
|
|
3755
|
+
}
|
|
3756
|
+
function monitorExternalStyleChange() {
|
|
3757
|
+
const headObserver = new MutationObserver(function(mutationsList) {
|
|
3758
|
+
checkCSSProperties();
|
|
3759
|
+
});
|
|
3760
|
+
headObserver.observe(document.head, { childList: true, subtree: true });
|
|
3761
|
+
}
|
|
3762
|
+
function checkCSSProperties() {
|
|
3763
|
+
checkHtmlBackgroundMaterial();
|
|
3764
|
+
checkCornerRadius();
|
|
3765
|
+
checkOpacity();
|
|
3766
|
+
checkHtmlVisible();
|
|
3767
|
+
window.addEventListener("resize", checkHtmlVisible);
|
|
3768
|
+
}
|
|
3769
|
+
function hijackGetComputedStyle() {
|
|
3770
|
+
const rawFn = window.getComputedStyle.bind(window);
|
|
3771
|
+
window.getComputedStyle = (element, pseudoElt) => {
|
|
3772
|
+
if (element.__isSpatialDiv) {
|
|
3773
|
+
return element.__getComputedStyle(rawFn, pseudoElt);
|
|
3774
|
+
}
|
|
3775
|
+
return rawFn(element, pseudoElt);
|
|
3776
|
+
};
|
|
3777
|
+
}
|
|
3778
|
+
function hijackWindowOpen() {
|
|
3779
|
+
XRApp.getInstance().init();
|
|
3780
|
+
}
|
|
3781
|
+
function spatialPolyfill() {
|
|
3782
|
+
if (!isWebSpatialEnv) {
|
|
3783
|
+
return;
|
|
3784
|
+
}
|
|
3785
|
+
injectSceneHook();
|
|
3786
|
+
hijackWindowOpen();
|
|
3787
|
+
checkCSSProperties();
|
|
3788
|
+
hijackGetComputedStyle();
|
|
3789
|
+
hijackDocumentElementStyle();
|
|
3790
|
+
monitorExternalStyleChange();
|
|
3791
|
+
}
|
|
3587
3792
|
export {
|
|
3588
3793
|
CSSSpatialDiv,
|
|
3589
3794
|
CSSSpatialPrimitive,
|
|
@@ -3599,6 +3804,7 @@ export {
|
|
|
3599
3804
|
initScene,
|
|
3600
3805
|
notifyUpdateStandInstanceLayout,
|
|
3601
3806
|
parseCornerRadius,
|
|
3807
|
+
spatialPolyfill,
|
|
3602
3808
|
withCSSSpatial,
|
|
3603
3809
|
withSpatial,
|
|
3604
3810
|
withSpatialMonitor
|