@webspatial/react-sdk 1.0.4 → 1.0.5
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 +262 -166
- package/dist/default/index.js +2512 -3495
- package/dist/default/index.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.d.ts +13 -6
- package/dist/jsx/jsx-dev-runtime.js +12 -213
- package/dist/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.web.js +1 -1
- package/dist/jsx/jsx-runtime.d.ts +1 -1
- package/dist/jsx/jsx-runtime.js +12 -213
- package/dist/jsx/jsx-runtime.js.map +1 -1
- package/dist/jsx/jsx-runtime.web.js +1 -1
- package/dist/web/index.d.ts +262 -166
- package/dist/web/index.js +2546 -3520
- package/dist/web/index.js.map +1 -1
- package/package.json +12 -14
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { JSXSource } from 'react/jsx-dev-runtime';
|
|
4
|
-
import {
|
|
4
|
+
import { SpatialTapEvent, SpatialDragStartEvent, SpatialDragEvent, SpatialDragEndEvent, SpatialRotateStartEvent, SpatialRotateEvent, SpatialRotateEndEvent, SpatialMagnifyStartEvent, SpatialMagnifyEvent, SpatialMagnifyEndEvent } from '@webspatial/react-sdk';
|
|
5
5
|
|
|
6
6
|
declare function jsxs(type: React.ElementType, props: unknown, key?: React.Key): react.ReactElement<any, string | react.JSXElementConstructor<any>>;
|
|
7
7
|
declare function jsx(type: React.ElementType, props: unknown, key?: React.Key): react.ReactElement<any, string | react.JSXElementConstructor<any>>;
|
|
@@ -45,6 +45,16 @@ declare namespace WebSpatialJSX {
|
|
|
45
45
|
[K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
|
|
46
46
|
style?: React.CSSProperties;
|
|
47
47
|
'enable-xr'?: boolean;
|
|
48
|
+
onSpatialTap?: (e: SpatialTapEvent) => void;
|
|
49
|
+
onSpatialDragStart?: (e: SpatialDragStartEvent) => void;
|
|
50
|
+
onSpatialDrag?: (e: SpatialDragEvent) => void;
|
|
51
|
+
onSpatialDragEnd?: (e: SpatialDragEndEvent) => void;
|
|
52
|
+
onSpatialRotateStart?: (e: SpatialRotateStartEvent) => void;
|
|
53
|
+
onSpatialRotate?: (e: SpatialRotateEvent) => void;
|
|
54
|
+
onSpatialRotateEnd?: (e: SpatialRotateEndEvent) => void;
|
|
55
|
+
onSpatialMagnifyStart?: (e: SpatialMagnifyStartEvent) => void;
|
|
56
|
+
onSpatialMagnify?: (e: SpatialMagnifyEvent) => void;
|
|
57
|
+
onSpatialMagnifyEnd?: (e: SpatialMagnifyEndEvent) => void;
|
|
48
58
|
};
|
|
49
59
|
};
|
|
50
60
|
}
|
|
@@ -52,20 +62,17 @@ declare module 'react' {
|
|
|
52
62
|
interface CSSProperties {
|
|
53
63
|
'--xr-background-material'?: string;
|
|
54
64
|
'--xr-back'?: number | string;
|
|
65
|
+
'--xr-depth'?: number | string;
|
|
55
66
|
'--xr-z-index'?: number | string;
|
|
56
67
|
enableXr?: boolean;
|
|
57
68
|
}
|
|
58
69
|
}
|
|
59
|
-
declare global {
|
|
60
|
-
interface Window {
|
|
61
|
-
xrCurrentSceneDefaults: (defaultConfig: WindowContainerOptions) => Promise<WindowContainerOptions>;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
70
|
|
|
65
71
|
declare global {
|
|
66
72
|
interface CSSStyleDeclaration {
|
|
67
73
|
'--xr-background-material'?: string;
|
|
68
74
|
'--xr-back'?: number | string;
|
|
75
|
+
'--xr-depth'?: number | string;
|
|
69
76
|
'--xr-z-index'?: number | string;
|
|
70
77
|
enableXr?: boolean;
|
|
71
78
|
}
|
|
@@ -2,232 +2,34 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['react-sdk-version'] = "1.0.
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.0.5"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "avp"
|
|
7
7
|
})()
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
// src/polyfill/spatialPolyfill.ts
|
|
11
|
-
import { parseCornerRadius, getSession as getSession2, XRApp as XRApp2 } from "@webspatial/react-sdk";
|
|
12
|
-
|
|
13
|
-
// src/polyfill/injectSceneHook.ts
|
|
14
|
-
import { getSession } from "@webspatial/react-sdk";
|
|
15
|
-
import { defaultSceneConfig, XRApp } from "@webspatial/react-sdk";
|
|
16
|
-
async function injectSceneHook() {
|
|
17
|
-
if (!window.opener) return;
|
|
18
|
-
if (window._SceneHookOff) return;
|
|
19
|
-
await getSession()?.setLoading("show");
|
|
20
|
-
function onContentLoaded(callback) {
|
|
21
|
-
if (document.readyState === "interactive" || document.readyState === "complete") {
|
|
22
|
-
callback();
|
|
23
|
-
} else {
|
|
24
|
-
document.addEventListener("DOMContentLoaded", callback);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
onContentLoaded(async () => {
|
|
28
|
-
let cfg = defaultSceneConfig;
|
|
29
|
-
if (typeof window.xrCurrentSceneDefaults === "function") {
|
|
30
|
-
try {
|
|
31
|
-
cfg = await window.xrCurrentSceneDefaults?.(defaultSceneConfig);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error(error);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
await new Promise((resolve, reject) => {
|
|
37
|
-
setTimeout(() => {
|
|
38
|
-
resolve(null);
|
|
39
|
-
}, 1e3);
|
|
40
|
-
});
|
|
41
|
-
await getSession()?.setLoading("hide");
|
|
42
|
-
await XRApp.getInstance().show(window, cfg);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/polyfill/spatialPolyfill.ts
|
|
47
|
-
var isWebSpatialEnv = getSession2() !== null;
|
|
48
|
-
var SpatialGlobalCustomVars = {
|
|
49
|
-
backgroundMaterial: "--xr-background-material"
|
|
50
|
-
};
|
|
51
|
-
var htmlBackgroundMaterial = "";
|
|
52
|
-
function setCurrentWindowStyle(backgroundMaterial) {
|
|
53
|
-
if (backgroundMaterial !== htmlBackgroundMaterial) {
|
|
54
|
-
const session = getSession2();
|
|
55
|
-
session.getCurrentWindowComponent().setStyle({
|
|
56
|
-
material: { type: backgroundMaterial }
|
|
57
|
-
});
|
|
58
|
-
htmlBackgroundMaterial = backgroundMaterial;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function checkHtmlBackgroundMaterial() {
|
|
62
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
63
|
-
const backgroundMaterial = computedStyle.getPropertyValue(
|
|
64
|
-
SpatialGlobalCustomVars.backgroundMaterial
|
|
65
|
-
);
|
|
66
|
-
setCurrentWindowStyle(backgroundMaterial || "none");
|
|
67
|
-
}
|
|
68
|
-
var htmlCornerRadius = {
|
|
69
|
-
topLeading: 0,
|
|
70
|
-
bottomLeading: 0,
|
|
71
|
-
topTrailing: 0,
|
|
72
|
-
bottomTrailing: 0
|
|
73
|
-
};
|
|
74
|
-
function checkCornerRadius() {
|
|
75
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
76
|
-
const cornerRadius = parseCornerRadius(computedStyle);
|
|
77
|
-
setCornerRadius(cornerRadius);
|
|
78
|
-
}
|
|
79
|
-
function setCornerRadius(cornerRadius) {
|
|
80
|
-
if (htmlCornerRadius.topLeading !== cornerRadius.topLeading || htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading || htmlCornerRadius.topTrailing !== cornerRadius.topTrailing || htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing) {
|
|
81
|
-
const session = getSession2();
|
|
82
|
-
if (!session) return;
|
|
83
|
-
session.getCurrentWindowComponent().setStyle({
|
|
84
|
-
cornerRadius
|
|
85
|
-
});
|
|
86
|
-
htmlCornerRadius.topLeading = cornerRadius.topLeading;
|
|
87
|
-
htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading;
|
|
88
|
-
htmlCornerRadius.topTrailing = cornerRadius.topTrailing;
|
|
89
|
-
htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function setOpacity(opacity) {
|
|
93
|
-
const session = getSession2();
|
|
94
|
-
if (!session) return;
|
|
95
|
-
session.getCurrentWindowComponent().setOpacity(opacity);
|
|
96
|
-
}
|
|
97
|
-
function checkOpacity() {
|
|
98
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
99
|
-
const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
|
|
100
|
-
setOpacity(opacity);
|
|
101
|
-
}
|
|
102
|
-
async function setHtmlVisible(visible) {
|
|
103
|
-
const session = getSession2();
|
|
104
|
-
if (!session) return;
|
|
105
|
-
const wc = session.getCurrentWindowComponent();
|
|
106
|
-
const ent = await wc.getEntity();
|
|
107
|
-
ent?.setVisible(visible);
|
|
108
|
-
}
|
|
109
|
-
function checkHtmlVisible() {
|
|
110
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
111
|
-
const visibility = computedStyle.getPropertyValue("visibility") !== "hidden";
|
|
112
|
-
setHtmlVisible(visibility);
|
|
113
|
-
}
|
|
114
|
-
function hijackDocumentElementStyle() {
|
|
115
|
-
const rawDocumentStyle = document.documentElement.style;
|
|
116
|
-
const styleProxy = new Proxy(rawDocumentStyle, {
|
|
117
|
-
set: function(target, key, value) {
|
|
118
|
-
const ret = Reflect.set(target, key, value);
|
|
119
|
-
if (key === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
120
|
-
setCurrentWindowStyle(value);
|
|
121
|
-
}
|
|
122
|
-
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") {
|
|
123
|
-
checkCornerRadius();
|
|
124
|
-
}
|
|
125
|
-
if (key === "opacity") {
|
|
126
|
-
checkOpacity();
|
|
127
|
-
}
|
|
128
|
-
if (key === "visibility" || key === "display") {
|
|
129
|
-
checkHtmlVisible();
|
|
130
|
-
}
|
|
131
|
-
return ret;
|
|
132
|
-
},
|
|
133
|
-
get: function(target, prop) {
|
|
134
|
-
if (typeof target[prop] === "function") {
|
|
135
|
-
return function(...args) {
|
|
136
|
-
if (prop === "setProperty") {
|
|
137
|
-
const [property, value] = args;
|
|
138
|
-
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
139
|
-
setCurrentWindowStyle(value);
|
|
140
|
-
}
|
|
141
|
-
} else if (prop === "removeProperty") {
|
|
142
|
-
const [property] = args;
|
|
143
|
-
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
144
|
-
setCurrentWindowStyle("none");
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return target[prop](
|
|
148
|
-
...args
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
return Reflect.get(target, prop);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
Object.defineProperty(document.documentElement, "style", {
|
|
156
|
-
get: function() {
|
|
157
|
-
return styleProxy;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
function monitorExternalStyleChange() {
|
|
162
|
-
const headObserver = new MutationObserver(function(mutationsList) {
|
|
163
|
-
checkCSSProperties();
|
|
164
|
-
});
|
|
165
|
-
headObserver.observe(document.head, { childList: true, subtree: true });
|
|
166
|
-
}
|
|
167
|
-
function checkCSSProperties() {
|
|
168
|
-
checkHtmlBackgroundMaterial();
|
|
169
|
-
checkCornerRadius();
|
|
170
|
-
checkOpacity();
|
|
171
|
-
checkHtmlVisible();
|
|
172
|
-
window.addEventListener("resize", checkHtmlVisible);
|
|
173
|
-
}
|
|
174
|
-
function hijackGetComputedStyle() {
|
|
175
|
-
const rawFn = window.getComputedStyle.bind(window);
|
|
176
|
-
window.getComputedStyle = (element, pseudoElt) => {
|
|
177
|
-
if (element.__isSpatialDiv) {
|
|
178
|
-
return element.__getComputedStyle(rawFn, pseudoElt);
|
|
179
|
-
}
|
|
180
|
-
return rawFn(element, pseudoElt);
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function hijackWindowOpen() {
|
|
184
|
-
XRApp2.getInstance().init();
|
|
185
|
-
}
|
|
186
|
-
function monitorHTMLAttributeChange() {
|
|
187
|
-
const observer = new MutationObserver((mutations) => {
|
|
188
|
-
mutations.forEach((mutation) => {
|
|
189
|
-
if (mutation.type === "attributes" && mutation.attributeName) {
|
|
190
|
-
checkCSSProperties();
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
observer.observe(document.documentElement, {
|
|
195
|
-
attributes: true,
|
|
196
|
-
attributeFilter: ["style", "class"]
|
|
197
|
-
});
|
|
198
|
-
window.addEventListener("load", () => {
|
|
199
|
-
checkCSSProperties();
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
function spatialPolyfill() {
|
|
203
|
-
if (!isWebSpatialEnv) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
injectSceneHook();
|
|
207
|
-
hijackWindowOpen();
|
|
208
|
-
checkCSSProperties();
|
|
209
|
-
hijackGetComputedStyle();
|
|
210
|
-
hijackDocumentElementStyle();
|
|
211
|
-
monitorExternalStyleChange();
|
|
212
|
-
monitorHTMLAttributeChange();
|
|
213
|
-
}
|
|
214
|
-
|
|
215
10
|
// src/jsx/jsx-dev-runtime.ts
|
|
216
11
|
import { Fragment } from "react/jsx-runtime";
|
|
217
12
|
|
|
218
13
|
// src/jsx/jsx-shared.ts
|
|
219
14
|
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
220
15
|
import reactJSXRuntime from "react/jsx-runtime";
|
|
221
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
withSpatialMonitor,
|
|
18
|
+
withSpatialized2DElementContainer,
|
|
19
|
+
Model
|
|
20
|
+
} from "@webspatial/react-sdk";
|
|
222
21
|
var attributeFlag = "enable-xr";
|
|
223
22
|
var styleFlag = "enableXr";
|
|
224
23
|
var classFlag = "__enableXr__";
|
|
225
24
|
var xrMonitorFlag = "enable-xr-monitor";
|
|
226
25
|
function replaceToSpatialPrimitiveType(type, props) {
|
|
26
|
+
if (type === Model) {
|
|
27
|
+
return type;
|
|
28
|
+
}
|
|
227
29
|
const propsObject = props;
|
|
228
30
|
if (attributeFlag in propsObject) {
|
|
229
31
|
delete propsObject[attributeFlag];
|
|
230
|
-
return
|
|
32
|
+
return withSpatialized2DElementContainer(type);
|
|
231
33
|
}
|
|
232
34
|
if (xrMonitorFlag in propsObject) {
|
|
233
35
|
delete propsObject[xrMonitorFlag];
|
|
@@ -235,7 +37,7 @@ function replaceToSpatialPrimitiveType(type, props) {
|
|
|
235
37
|
}
|
|
236
38
|
if (propsObject && propsObject.style && styleFlag in propsObject.style) {
|
|
237
39
|
delete propsObject.style[styleFlag];
|
|
238
|
-
return
|
|
40
|
+
return withSpatialized2DElementContainer(type);
|
|
239
41
|
}
|
|
240
42
|
if (propsObject && propsObject.className) {
|
|
241
43
|
const originalClassNames = propsObject.className.split(" ");
|
|
@@ -243,7 +45,7 @@ function replaceToSpatialPrimitiveType(type, props) {
|
|
|
243
45
|
if (idx !== -1) {
|
|
244
46
|
originalClassNames.splice(idx, 1);
|
|
245
47
|
propsObject.className = originalClassNames.join(" ");
|
|
246
|
-
return
|
|
48
|
+
return withSpatialized2DElementContainer(type);
|
|
247
49
|
}
|
|
248
50
|
}
|
|
249
51
|
return type;
|
|
@@ -256,9 +58,6 @@ function jsxDEV(type, props, key, isStatic, source, self) {
|
|
|
256
58
|
type = replaceToSpatialPrimitiveType(type, props);
|
|
257
59
|
return _jsxDEV(type, props, key, isStatic, source, self);
|
|
258
60
|
}
|
|
259
|
-
|
|
260
|
-
// src/jsx/jsx-dev-runtime.ts
|
|
261
|
-
spatialPolyfill();
|
|
262
61
|
export {
|
|
263
62
|
Fragment,
|
|
264
63
|
jsx,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/polyfill/spatialPolyfill.ts","../../src/polyfill/injectSceneHook.ts","../../src/jsx/jsx-dev-runtime.ts","../../src/jsx/jsx-shared.ts"],"sourcesContent":["//@ts-ignore\nimport { parseCornerRadius, getSession, XRApp } from '@webspatial/react-sdk'\nimport { injectSceneHook } from './injectSceneHook'\n\nconst isWebSpatialEnv = getSession() !== null\n\nconst SpatialGlobalCustomVars = {\n backgroundMaterial: '--xr-background-material',\n}\n\n// keep track of current html background material\nlet htmlBackgroundMaterial = ''\nfunction setCurrentWindowStyle(backgroundMaterial: string) {\n if (backgroundMaterial !== htmlBackgroundMaterial) {\n const session = getSession()!\n session.getCurrentWindowComponent().setStyle({\n material: { type: backgroundMaterial as any },\n })\n htmlBackgroundMaterial = backgroundMaterial\n }\n}\n\nfunction checkHtmlBackgroundMaterial() {\n const computedStyle = getComputedStyle(document.documentElement)\n\n const backgroundMaterial = computedStyle.getPropertyValue(\n SpatialGlobalCustomVars.backgroundMaterial,\n )\n\n setCurrentWindowStyle(backgroundMaterial || 'none')\n}\n\n// keep track of current corner radius\nlet htmlCornerRadius = {\n topLeading: 0,\n bottomLeading: 0,\n topTrailing: 0,\n bottomTrailing: 0,\n}\nfunction checkCornerRadius() {\n const computedStyle = getComputedStyle(document.documentElement)\n const cornerRadius = parseCornerRadius(computedStyle)\n setCornerRadius(cornerRadius)\n}\n\nfunction setCornerRadius(cornerRadius: any) {\n if (\n htmlCornerRadius.topLeading !== cornerRadius.topLeading ||\n htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading ||\n htmlCornerRadius.topTrailing !== cornerRadius.topTrailing ||\n htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing\n ) {\n const session = getSession()!\n if (!session) return\n session.getCurrentWindowComponent().setStyle({\n cornerRadius,\n })\n htmlCornerRadius.topLeading = cornerRadius.topLeading\n htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading\n htmlCornerRadius.topTrailing = cornerRadius.topTrailing\n htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing\n }\n}\n\nfunction setOpacity(opacity: number) {\n const session = getSession()!\n if (!session) return\n session.getCurrentWindowComponent().setOpacity(opacity)\n}\n\nfunction checkOpacity() {\n const computedStyle = getComputedStyle(document.documentElement)\n const opacity = parseFloat(computedStyle.getPropertyValue('opacity'))\n setOpacity(opacity)\n}\n\nasync function setHtmlVisible(visible: boolean) {\n const session = getSession()!\n if (!session) return\n const wc = session.getCurrentWindowComponent()\n const ent = await wc.getEntity()\n ent?.setVisible(visible)\n}\n\nfunction checkHtmlVisible() {\n const computedStyle = getComputedStyle(document.documentElement)\n const visibility = computedStyle.getPropertyValue('visibility') !== 'hidden'\n setHtmlVisible(visibility)\n}\n\nfunction hijackDocumentElementStyle() {\n const rawDocumentStyle = document.documentElement.style\n const styleProxy = new Proxy(rawDocumentStyle, {\n set: function (target, key, value) {\n const ret = Reflect.set(target, key, value)\n\n if (key === SpatialGlobalCustomVars.backgroundMaterial) {\n setCurrentWindowStyle(value)\n }\n\n if (\n key === 'border-radius' ||\n key === 'borderRadius' ||\n key === 'border-top-left-radius' ||\n key === 'borderTopLeftRadius' ||\n key === 'border-top-right-radius' ||\n key === 'borderTopRightRadius' ||\n key === 'border-bottom-left-radius' ||\n key === 'borderBottomLeftRadius' ||\n key === 'border-bottom-right-radius' ||\n key === 'borderBottomRightRadius'\n ) {\n checkCornerRadius()\n }\n\n if (key === 'opacity') {\n checkOpacity()\n }\n\n if (key === 'visibility' || key === 'display') {\n checkHtmlVisible()\n }\n\n return ret\n },\n get: function (target, prop: string) {\n if (typeof target[prop as keyof CSSStyleDeclaration] === 'function') {\n return function (this: any, ...args: any[]) {\n if (prop === 'setProperty') {\n const [property, value] = args\n if (property === SpatialGlobalCustomVars.backgroundMaterial) {\n setCurrentWindowStyle(value)\n }\n } else if (prop === 'removeProperty') {\n const [property] = args\n if (property === SpatialGlobalCustomVars.backgroundMaterial) {\n setCurrentWindowStyle('none')\n }\n }\n return (target[prop as keyof CSSStyleDeclaration] as Function)(\n ...args,\n )\n }\n }\n return Reflect.get(target, prop)\n },\n })\n Object.defineProperty(document.documentElement, 'style', {\n get: function () {\n return styleProxy\n },\n })\n}\n\nfunction monitorExternalStyleChange() {\n const headObserver = new MutationObserver(function (mutationsList) {\n checkCSSProperties()\n })\n\n headObserver.observe(document.head, { childList: true, subtree: true })\n}\n\nfunction checkCSSProperties() {\n checkHtmlBackgroundMaterial()\n checkCornerRadius()\n checkOpacity()\n checkHtmlVisible()\n window.addEventListener('resize', checkHtmlVisible)\n}\n\nfunction hijackGetComputedStyle() {\n const rawFn = window.getComputedStyle.bind(window)\n window.getComputedStyle = (element, pseudoElt) => {\n if ((element as any).__isSpatialDiv) {\n return (element as any).__getComputedStyle(rawFn, pseudoElt)\n }\n return rawFn(element, pseudoElt)\n }\n}\n\nfunction hijackWindowOpen() {\n XRApp.getInstance().init()\n}\n\nfunction monitorHTMLAttributeChange() {\n const observer = new MutationObserver(mutations => {\n mutations.forEach(mutation => {\n if (mutation.type === 'attributes' && mutation.attributeName) {\n checkCSSProperties()\n }\n })\n })\n\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['style', 'class'],\n })\n\n // some css may still loading, need to checkCSSProperties after all window document loaded\n window.addEventListener('load', () => {\n checkCSSProperties()\n })\n}\n\nexport function spatialPolyfill() {\n if (!isWebSpatialEnv) {\n return\n }\n\n injectSceneHook()\n hijackWindowOpen()\n checkCSSProperties()\n hijackGetComputedStyle()\n hijackDocumentElementStyle()\n monitorExternalStyleChange()\n monitorHTMLAttributeChange()\n}\n","//@ts-ignore\nimport { getSession } from '@webspatial/react-sdk'\n//@ts-ignore\nimport { defaultSceneConfig, XRApp } from '@webspatial/react-sdk'\n\nexport async function injectSceneHook() {\n if (!window.opener) return\n if ((window as any)._SceneHookOff) return\n\n await getSession()?.setLoading('show')\n // see this flag, we have done create the root scene\n\n function onContentLoaded(callback: any) {\n if (\n document.readyState === 'interactive' ||\n document.readyState === 'complete'\n ) {\n callback()\n } else {\n document.addEventListener('DOMContentLoaded', callback)\n }\n }\n\n onContentLoaded(async () => {\n let cfg = defaultSceneConfig\n if (typeof (window as any).xrCurrentSceneDefaults === 'function') {\n try {\n cfg = await (window as any).xrCurrentSceneDefaults?.(defaultSceneConfig)\n } catch (error) {\n console.error(error)\n }\n }\n // fixme: this duration is too short so that hide and show is at racing, so add a little delay to avoid\n await new Promise((resolve, reject) => {\n setTimeout(() => {\n resolve(null)\n }, 1000)\n })\n await getSession()?.setLoading('hide')\n await XRApp.getInstance().show(window, cfg)\n })\n}\n","import { spatialPolyfill } from '../polyfill'\n\nspatialPolyfill()\n\nexport { Fragment } from 'react/jsx-runtime'\nexport { jsxDEV, jsx } from './jsx-shared'\n\nexport type { WebSpatialJSX as JSX } from './jsx-namespace'\nexport * from './xr-css-extension'\n","import { jsxDEV as _jsxDEV, JSXSource } from 'react/jsx-dev-runtime'\nimport reactJSXRuntime from 'react/jsx-runtime'\n//@ts-ignore bypass ts check for external\nimport { withCSSSpatial, withSpatialMonitor } from '@webspatial/react-sdk'\nconst attributeFlag = 'enable-xr'\nconst styleFlag = 'enableXr'\nconst classFlag = '__enableXr__'\nconst xrMonitorFlag = 'enable-xr-monitor'\n\nexport function replaceToSpatialPrimitiveType(\n type: React.ElementType,\n props: unknown,\n) {\n const propsObject = props as Record<string, any>\n if (attributeFlag in propsObject) {\n delete propsObject[attributeFlag]\n return withCSSSpatial(type)\n }\n\n if (xrMonitorFlag in propsObject) {\n delete propsObject[xrMonitorFlag]\n return withSpatialMonitor(type)\n }\n\n if (propsObject && propsObject.style && styleFlag in propsObject.style) {\n delete propsObject.style[styleFlag]\n return withCSSSpatial(type)\n }\n\n if (propsObject && propsObject.className) {\n const originalClassNames = propsObject.className.split(' ')\n const idx = originalClassNames.indexOf(classFlag)\n if (idx !== -1) {\n originalClassNames.splice(idx, 1)\n propsObject.className = originalClassNames.join(' ')\n return withCSSSpatial(type)\n }\n }\n\n return type\n}\n\nexport function jsxs(type: React.ElementType, props: unknown, key?: React.Key) {\n type = replaceToSpatialPrimitiveType(type, props)\n return reactJSXRuntime.jsxs(type, props, key)\n}\n\nexport function jsx(type: React.ElementType, props: unknown, key?: React.Key) {\n type = replaceToSpatialPrimitiveType(type, props)\n return reactJSXRuntime.jsx(type, props, key)\n}\n\nexport function jsxDEV(\n type: React.ElementType,\n props: unknown,\n key: React.Key,\n isStatic: boolean,\n source?: JSXSource,\n self?: unknown,\n) {\n type = replaceToSpatialPrimitiveType(type, props)\n return _jsxDEV(type, props, key, isStatic, source, self)\n}\n"],"mappings":";;;;;;;;;;AACA,SAAS,mBAAmB,cAAAA,aAAY,SAAAC,cAAa;;;ACArD,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB,aAAa;AAE1C,eAAsB,kBAAkB;AACtC,MAAI,CAAC,OAAO,OAAQ;AACpB,MAAK,OAAe,cAAe;AAEnC,QAAM,WAAW,GAAG,WAAW,MAAM;AAGrC,WAAS,gBAAgB,UAAe;AACtC,QACE,SAAS,eAAe,iBACxB,SAAS,eAAe,YACxB;AACA,eAAS;AAAA,IACX,OAAO;AACL,eAAS,iBAAiB,oBAAoB,QAAQ;AAAA,IACxD;AAAA,EACF;AAEA,kBAAgB,YAAY;AAC1B,QAAI,MAAM;AACV,QAAI,OAAQ,OAAe,2BAA2B,YAAY;AAChE,UAAI;AACF,cAAM,MAAO,OAAe,yBAAyB,kBAAkB;AAAA,MACzE,SAAS,OAAO;AACd,gBAAQ,MAAM,KAAK;AAAA,MACrB;AAAA,IACF;AAEA,UAAM,IAAI,QAAQ,CAAC,SAAS,WAAW;AACrC,iBAAW,MAAM;AACf,gBAAQ,IAAI;AAAA,MACd,GAAG,GAAI;AAAA,IACT,CAAC;AACD,UA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AiB;AAC5E,SAAO,8BAA8B,MAAM,KAAK;AAChD,SAAO,gBAAgB,IAAI,MAAM,OAAO,GAAG;AAC7C;AAEO,SAAS,OACd,MACA,OACA,KACA,UACA,QACA,MACA;AACA,SAAO,8BAA8B,MAAM,KAAK;AAChD,SAAO,QAAQ,MAAM,OAAO,KAAK,UAAU,QAAQ,IAAI;AACzD;;;AD5DA,gBAAgB;","names":["getSession","XRApp","getSession","XRApp"]}
|
|
1
|
+
{"version":3,"sources":["../../src/jsx/jsx-dev-runtime.ts","../../src/jsx/jsx-shared.ts"],"sourcesContent":["export { Fragment } from 'react/jsx-runtime'\nexport { jsxDEV, jsx } from './jsx-shared'\n\nexport type { WebSpatialJSX as JSX } from './jsx-namespace'\nexport * from './xr-css-extension'\n","import { jsxDEV as _jsxDEV, JSXSource } from 'react/jsx-dev-runtime'\nimport reactJSXRuntime from 'react/jsx-runtime'\nimport {\n withSpatialMonitor,\n withSpatialized2DElementContainer,\n Model,\n //@ts-ignore bypass ts check for external\n} from '@webspatial/react-sdk'\nconst attributeFlag = 'enable-xr'\nconst styleFlag = 'enableXr'\nconst classFlag = '__enableXr__'\nconst xrMonitorFlag = 'enable-xr-monitor'\n\nexport function replaceToSpatialPrimitiveType(\n type: React.ElementType,\n props: unknown,\n) {\n if (type === Model) {\n return type\n }\n\n const propsObject = props as Record<string, any>\n if (attributeFlag in propsObject) {\n delete propsObject[attributeFlag]\n return withSpatialized2DElementContainer(type)\n }\n\n if (xrMonitorFlag in propsObject) {\n delete propsObject[xrMonitorFlag]\n return withSpatialMonitor(type)\n }\n\n if (propsObject && propsObject.style && styleFlag in propsObject.style) {\n delete propsObject.style[styleFlag]\n return withSpatialized2DElementContainer(type)\n }\n\n if (propsObject && propsObject.className) {\n const originalClassNames = propsObject.className.split(' ')\n const idx = originalClassNames.indexOf(classFlag)\n if (idx !== -1) {\n originalClassNames.splice(idx, 1)\n propsObject.className = originalClassNames.join(' ')\n return withSpatialized2DElementContainer(type)\n }\n }\n\n return type\n}\n\nexport function jsxs(type: React.ElementType, props: unknown, key?: React.Key) {\n type = replaceToSpatialPrimitiveType(type, props)\n return reactJSXRuntime.jsxs(type, props, key)\n}\n\nexport function jsx(type: React.ElementType, props: unknown, key?: React.Key) {\n type = replaceToSpatialPrimitiveType(type, props)\n return reactJSXRuntime.jsx(type, props, key)\n}\n\nexport function jsxDEV(\n type: React.ElementType,\n props: unknown,\n key: React.Key,\n isStatic: boolean,\n source?: JSXSource,\n self?: unknown,\n) {\n type = replaceToSpatialPrimitiveType(type, props)\n return _jsxDEV(type, props, key, isStatic, source, self)\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,gBAAgB;;;ACAzB,SAAS,UAAU,eAA0B;AAC7C,OAAO,qBAAqB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,IAAM,gBAAgB;AACtB,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,gBAAgB;AAEf,SAAS,8BACd,MACA,OACA;AACA,MAAI,SAAS,OAAO;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,cAAc;AACpB,MAAI,iBAAiB,aAAa;AAChC,WAAO,YAAY,aAAa;AAChC,WAAO,kCAAkC,IAAI;AAAA,EAC/C;AAEA,MAAI,iBAAiB,aAAa;AAChC,WAAO,YAAY,aAAa;AAChC,WAAO,mBAAmB,IAAI;AAAA,EAChC;AAEA,MAAI,eAAe,YAAY,SAAS,aAAa,YAAY,OAAO;AACtE,WAAO,YAAY,MAAM,SAAS;AAClC,WAAO,kCAAkC,IAAI;AAAA,EAC/C;AAEA,MAAI,eAAe,YAAY,WAAW;AACxC,UAAM,qBAAqB,YAAY,UAAU,MAAM,GAAG;AAC1D,UAAM,MAAM,mBAAmB,QAAQ,SAAS;AAChD,QAAI,QAAQ,IAAI;AACd,yBAAmB,OAAO,KAAK,CAAC;AAChC,kBAAY,YAAY,mBAAmB,KAAK,GAAG;AACnD,aAAO,kCAAkC,IAAI;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;AAOO,SAAS,IAAI,MAAyB,OAAgB,KAAiB;AAC5E,SAAO,8BAA8B,MAAM,KAAK;AAChD,SAAO,gBAAgB,IAAI,MAAM,OAAO,GAAG;AAC7C;AAEO,SAAS,OACd,MACA,OACA,KACA,UACA,QACA,MACA;AACA,SAAO,8BAA8B,MAAM,KAAK;AAChD,SAAO,QAAQ,MAAM,OAAO,KAAK,UAAU,QAAQ,IAAI;AACzD;","names":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['react-sdk-version'] = "1.0.
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.0.5"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "web"
|
|
7
7
|
})()
|
|
8
8
|
|
package/dist/jsx/jsx-runtime.js
CHANGED
|
@@ -2,232 +2,34 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['react-sdk-version'] = "1.0.
|
|
5
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.0.5"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "avp"
|
|
7
7
|
})()
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
// src/polyfill/spatialPolyfill.ts
|
|
11
|
-
import { parseCornerRadius, getSession as getSession2, XRApp as XRApp2 } from "@webspatial/react-sdk";
|
|
12
|
-
|
|
13
|
-
// src/polyfill/injectSceneHook.ts
|
|
14
|
-
import { getSession } from "@webspatial/react-sdk";
|
|
15
|
-
import { defaultSceneConfig, XRApp } from "@webspatial/react-sdk";
|
|
16
|
-
async function injectSceneHook() {
|
|
17
|
-
if (!window.opener) return;
|
|
18
|
-
if (window._SceneHookOff) return;
|
|
19
|
-
await getSession()?.setLoading("show");
|
|
20
|
-
function onContentLoaded(callback) {
|
|
21
|
-
if (document.readyState === "interactive" || document.readyState === "complete") {
|
|
22
|
-
callback();
|
|
23
|
-
} else {
|
|
24
|
-
document.addEventListener("DOMContentLoaded", callback);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
onContentLoaded(async () => {
|
|
28
|
-
let cfg = defaultSceneConfig;
|
|
29
|
-
if (typeof window.xrCurrentSceneDefaults === "function") {
|
|
30
|
-
try {
|
|
31
|
-
cfg = await window.xrCurrentSceneDefaults?.(defaultSceneConfig);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error(error);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
await new Promise((resolve, reject) => {
|
|
37
|
-
setTimeout(() => {
|
|
38
|
-
resolve(null);
|
|
39
|
-
}, 1e3);
|
|
40
|
-
});
|
|
41
|
-
await getSession()?.setLoading("hide");
|
|
42
|
-
await XRApp.getInstance().show(window, cfg);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/polyfill/spatialPolyfill.ts
|
|
47
|
-
var isWebSpatialEnv = getSession2() !== null;
|
|
48
|
-
var SpatialGlobalCustomVars = {
|
|
49
|
-
backgroundMaterial: "--xr-background-material"
|
|
50
|
-
};
|
|
51
|
-
var htmlBackgroundMaterial = "";
|
|
52
|
-
function setCurrentWindowStyle(backgroundMaterial) {
|
|
53
|
-
if (backgroundMaterial !== htmlBackgroundMaterial) {
|
|
54
|
-
const session = getSession2();
|
|
55
|
-
session.getCurrentWindowComponent().setStyle({
|
|
56
|
-
material: { type: backgroundMaterial }
|
|
57
|
-
});
|
|
58
|
-
htmlBackgroundMaterial = backgroundMaterial;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function checkHtmlBackgroundMaterial() {
|
|
62
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
63
|
-
const backgroundMaterial = computedStyle.getPropertyValue(
|
|
64
|
-
SpatialGlobalCustomVars.backgroundMaterial
|
|
65
|
-
);
|
|
66
|
-
setCurrentWindowStyle(backgroundMaterial || "none");
|
|
67
|
-
}
|
|
68
|
-
var htmlCornerRadius = {
|
|
69
|
-
topLeading: 0,
|
|
70
|
-
bottomLeading: 0,
|
|
71
|
-
topTrailing: 0,
|
|
72
|
-
bottomTrailing: 0
|
|
73
|
-
};
|
|
74
|
-
function checkCornerRadius() {
|
|
75
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
76
|
-
const cornerRadius = parseCornerRadius(computedStyle);
|
|
77
|
-
setCornerRadius(cornerRadius);
|
|
78
|
-
}
|
|
79
|
-
function setCornerRadius(cornerRadius) {
|
|
80
|
-
if (htmlCornerRadius.topLeading !== cornerRadius.topLeading || htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading || htmlCornerRadius.topTrailing !== cornerRadius.topTrailing || htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing) {
|
|
81
|
-
const session = getSession2();
|
|
82
|
-
if (!session) return;
|
|
83
|
-
session.getCurrentWindowComponent().setStyle({
|
|
84
|
-
cornerRadius
|
|
85
|
-
});
|
|
86
|
-
htmlCornerRadius.topLeading = cornerRadius.topLeading;
|
|
87
|
-
htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading;
|
|
88
|
-
htmlCornerRadius.topTrailing = cornerRadius.topTrailing;
|
|
89
|
-
htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function setOpacity(opacity) {
|
|
93
|
-
const session = getSession2();
|
|
94
|
-
if (!session) return;
|
|
95
|
-
session.getCurrentWindowComponent().setOpacity(opacity);
|
|
96
|
-
}
|
|
97
|
-
function checkOpacity() {
|
|
98
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
99
|
-
const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
|
|
100
|
-
setOpacity(opacity);
|
|
101
|
-
}
|
|
102
|
-
async function setHtmlVisible(visible) {
|
|
103
|
-
const session = getSession2();
|
|
104
|
-
if (!session) return;
|
|
105
|
-
const wc = session.getCurrentWindowComponent();
|
|
106
|
-
const ent = await wc.getEntity();
|
|
107
|
-
ent?.setVisible(visible);
|
|
108
|
-
}
|
|
109
|
-
function checkHtmlVisible() {
|
|
110
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
111
|
-
const visibility = computedStyle.getPropertyValue("visibility") !== "hidden";
|
|
112
|
-
setHtmlVisible(visibility);
|
|
113
|
-
}
|
|
114
|
-
function hijackDocumentElementStyle() {
|
|
115
|
-
const rawDocumentStyle = document.documentElement.style;
|
|
116
|
-
const styleProxy = new Proxy(rawDocumentStyle, {
|
|
117
|
-
set: function(target, key, value) {
|
|
118
|
-
const ret = Reflect.set(target, key, value);
|
|
119
|
-
if (key === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
120
|
-
setCurrentWindowStyle(value);
|
|
121
|
-
}
|
|
122
|
-
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") {
|
|
123
|
-
checkCornerRadius();
|
|
124
|
-
}
|
|
125
|
-
if (key === "opacity") {
|
|
126
|
-
checkOpacity();
|
|
127
|
-
}
|
|
128
|
-
if (key === "visibility" || key === "display") {
|
|
129
|
-
checkHtmlVisible();
|
|
130
|
-
}
|
|
131
|
-
return ret;
|
|
132
|
-
},
|
|
133
|
-
get: function(target, prop) {
|
|
134
|
-
if (typeof target[prop] === "function") {
|
|
135
|
-
return function(...args) {
|
|
136
|
-
if (prop === "setProperty") {
|
|
137
|
-
const [property, value] = args;
|
|
138
|
-
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
139
|
-
setCurrentWindowStyle(value);
|
|
140
|
-
}
|
|
141
|
-
} else if (prop === "removeProperty") {
|
|
142
|
-
const [property] = args;
|
|
143
|
-
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
144
|
-
setCurrentWindowStyle("none");
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return target[prop](
|
|
148
|
-
...args
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
return Reflect.get(target, prop);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
Object.defineProperty(document.documentElement, "style", {
|
|
156
|
-
get: function() {
|
|
157
|
-
return styleProxy;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
function monitorExternalStyleChange() {
|
|
162
|
-
const headObserver = new MutationObserver(function(mutationsList) {
|
|
163
|
-
checkCSSProperties();
|
|
164
|
-
});
|
|
165
|
-
headObserver.observe(document.head, { childList: true, subtree: true });
|
|
166
|
-
}
|
|
167
|
-
function checkCSSProperties() {
|
|
168
|
-
checkHtmlBackgroundMaterial();
|
|
169
|
-
checkCornerRadius();
|
|
170
|
-
checkOpacity();
|
|
171
|
-
checkHtmlVisible();
|
|
172
|
-
window.addEventListener("resize", checkHtmlVisible);
|
|
173
|
-
}
|
|
174
|
-
function hijackGetComputedStyle() {
|
|
175
|
-
const rawFn = window.getComputedStyle.bind(window);
|
|
176
|
-
window.getComputedStyle = (element, pseudoElt) => {
|
|
177
|
-
if (element.__isSpatialDiv) {
|
|
178
|
-
return element.__getComputedStyle(rawFn, pseudoElt);
|
|
179
|
-
}
|
|
180
|
-
return rawFn(element, pseudoElt);
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function hijackWindowOpen() {
|
|
184
|
-
XRApp2.getInstance().init();
|
|
185
|
-
}
|
|
186
|
-
function monitorHTMLAttributeChange() {
|
|
187
|
-
const observer = new MutationObserver((mutations) => {
|
|
188
|
-
mutations.forEach((mutation) => {
|
|
189
|
-
if (mutation.type === "attributes" && mutation.attributeName) {
|
|
190
|
-
checkCSSProperties();
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
observer.observe(document.documentElement, {
|
|
195
|
-
attributes: true,
|
|
196
|
-
attributeFilter: ["style", "class"]
|
|
197
|
-
});
|
|
198
|
-
window.addEventListener("load", () => {
|
|
199
|
-
checkCSSProperties();
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
function spatialPolyfill() {
|
|
203
|
-
if (!isWebSpatialEnv) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
injectSceneHook();
|
|
207
|
-
hijackWindowOpen();
|
|
208
|
-
checkCSSProperties();
|
|
209
|
-
hijackGetComputedStyle();
|
|
210
|
-
hijackDocumentElementStyle();
|
|
211
|
-
monitorExternalStyleChange();
|
|
212
|
-
monitorHTMLAttributeChange();
|
|
213
|
-
}
|
|
214
|
-
|
|
215
10
|
// src/jsx/jsx-runtime.ts
|
|
216
11
|
import { Fragment } from "react/jsx-runtime";
|
|
217
12
|
|
|
218
13
|
// src/jsx/jsx-shared.ts
|
|
219
14
|
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
220
15
|
import reactJSXRuntime from "react/jsx-runtime";
|
|
221
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
withSpatialMonitor,
|
|
18
|
+
withSpatialized2DElementContainer,
|
|
19
|
+
Model
|
|
20
|
+
} from "@webspatial/react-sdk";
|
|
222
21
|
var attributeFlag = "enable-xr";
|
|
223
22
|
var styleFlag = "enableXr";
|
|
224
23
|
var classFlag = "__enableXr__";
|
|
225
24
|
var xrMonitorFlag = "enable-xr-monitor";
|
|
226
25
|
function replaceToSpatialPrimitiveType(type, props) {
|
|
26
|
+
if (type === Model) {
|
|
27
|
+
return type;
|
|
28
|
+
}
|
|
227
29
|
const propsObject = props;
|
|
228
30
|
if (attributeFlag in propsObject) {
|
|
229
31
|
delete propsObject[attributeFlag];
|
|
230
|
-
return
|
|
32
|
+
return withSpatialized2DElementContainer(type);
|
|
231
33
|
}
|
|
232
34
|
if (xrMonitorFlag in propsObject) {
|
|
233
35
|
delete propsObject[xrMonitorFlag];
|
|
@@ -235,7 +37,7 @@ function replaceToSpatialPrimitiveType(type, props) {
|
|
|
235
37
|
}
|
|
236
38
|
if (propsObject && propsObject.style && styleFlag in propsObject.style) {
|
|
237
39
|
delete propsObject.style[styleFlag];
|
|
238
|
-
return
|
|
40
|
+
return withSpatialized2DElementContainer(type);
|
|
239
41
|
}
|
|
240
42
|
if (propsObject && propsObject.className) {
|
|
241
43
|
const originalClassNames = propsObject.className.split(" ");
|
|
@@ -243,7 +45,7 @@ function replaceToSpatialPrimitiveType(type, props) {
|
|
|
243
45
|
if (idx !== -1) {
|
|
244
46
|
originalClassNames.splice(idx, 1);
|
|
245
47
|
propsObject.className = originalClassNames.join(" ");
|
|
246
|
-
return
|
|
48
|
+
return withSpatialized2DElementContainer(type);
|
|
247
49
|
}
|
|
248
50
|
}
|
|
249
51
|
return type;
|
|
@@ -256,9 +58,6 @@ function jsx(type, props, key) {
|
|
|
256
58
|
type = replaceToSpatialPrimitiveType(type, props);
|
|
257
59
|
return reactJSXRuntime.jsx(type, props, key);
|
|
258
60
|
}
|
|
259
|
-
|
|
260
|
-
// src/jsx/jsx-runtime.ts
|
|
261
|
-
spatialPolyfill();
|
|
262
61
|
export {
|
|
263
62
|
Fragment,
|
|
264
63
|
jsx,
|