@gxpl/sdk 0.0.37 → 0.0.39
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/lib/sdk-nextjs/fixedLayers/FixedLayerTransitionsProvider.js +10 -9
- package/lib/sdk-nextjs/fixedLayers/FixedLayerTransitionsRegistry.d.ts +1 -1
- package/lib/sdk-nextjs/fixedLayers/FixedLayerTransitionsRegistry.js +2 -1
- package/package.json +1 -1
- package/lib/sdk-nextjs/utils/usePrelaodAssets.d.ts +0 -4
- package/lib/sdk-nextjs/utils/usePrelaodAssets.js +0 -38
|
@@ -9,29 +9,30 @@ const FixedLayerTransitionsRegistry_1 = require("./FixedLayerTransitionsRegistry
|
|
|
9
9
|
exports.FixedLayerTransitionsContext = (0, react_1.createContext)(undefined);
|
|
10
10
|
const FixedLayerTransitionsProvider = ({ fixedLayer, children }) => {
|
|
11
11
|
const actorRef = TransitionMachineContext_1.TransitionMachineContext.useActorRef();
|
|
12
|
-
const { isSettling,
|
|
12
|
+
const { isSettling, isTransitioning, startScene } = TransitionMachineContext_1.TransitionMachineContext.useSelector((state) => ({
|
|
13
13
|
startScene: state.context.input.startScene,
|
|
14
14
|
isSettling: state.matches('settling'),
|
|
15
|
-
|
|
15
|
+
isTransitioning: state.matches('transitioning') || state.matches('instant_transitioning'),
|
|
16
16
|
}));
|
|
17
17
|
const transitionsRegistry = (0, react_1.useMemo)(() => new FixedLayerTransitionsRegistry_1.FixedLayerTransitionsRegistry(fixedLayer, startScene), [fixedLayer, startScene]);
|
|
18
18
|
(0, react_1.useEffect)(() => {
|
|
19
19
|
if (isSettling && actorRef) {
|
|
20
20
|
const { context } = actorRef.getSnapshot();
|
|
21
21
|
const { transition } = context;
|
|
22
|
-
if (!transition || transition.stage !== 'settling')
|
|
22
|
+
if (!transition || transition.stage !== 'settling' || transition.success)
|
|
23
23
|
return;
|
|
24
|
-
transitionsRegistry.
|
|
24
|
+
transitionsRegistry.notifyOnActiveSceneChange(transition.from);
|
|
25
25
|
}
|
|
26
26
|
}, [isSettling, actorRef, transitionsRegistry]);
|
|
27
27
|
(0, react_1.useEffect)(() => {
|
|
28
|
-
if (
|
|
28
|
+
if (isTransitioning && actorRef) {
|
|
29
29
|
const { context } = actorRef.getSnapshot();
|
|
30
|
-
const {
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const { transition } = context;
|
|
31
|
+
if (!transition || transition.stage !== 'active')
|
|
32
|
+
return;
|
|
33
|
+
transitionsRegistry.notifyOnActiveSceneChange(transition.to);
|
|
33
34
|
}
|
|
34
|
-
}, [
|
|
35
|
+
}, [isTransitioning, actorRef, transitionsRegistry]);
|
|
35
36
|
return ((0, jsx_runtime_1.jsx)(exports.FixedLayerTransitionsContext.Provider, { value: transitionsRegistry, children: children }));
|
|
36
37
|
};
|
|
37
38
|
exports.FixedLayerTransitionsProvider = FixedLayerTransitionsProvider;
|
|
@@ -18,7 +18,7 @@ export declare class FixedLayerTransitionsRegistry implements InteractionsRegist
|
|
|
18
18
|
private getNestedItems;
|
|
19
19
|
private getDefaultItemStages;
|
|
20
20
|
notifyOnActiveSceneChange(sceneId: SceneId): void;
|
|
21
|
-
|
|
21
|
+
setActiveTransition(to: SceneId): void;
|
|
22
22
|
notifyTransitionStartForItems(activeStateId: string): void;
|
|
23
23
|
notifyTransitionEnd(itemId: string): void;
|
|
24
24
|
private notifyItemCtrlsChange;
|
|
@@ -109,6 +109,7 @@ class FixedLayerTransitionsRegistry {
|
|
|
109
109
|
return stages;
|
|
110
110
|
}
|
|
111
111
|
notifyOnActiveSceneChange(sceneId) {
|
|
112
|
+
this.setActiveTransition(sceneId);
|
|
112
113
|
this.itemsStages = this.itemsStages.map((stage) => {
|
|
113
114
|
return {
|
|
114
115
|
itemId: stage.itemId,
|
|
@@ -123,7 +124,7 @@ class FixedLayerTransitionsRegistry {
|
|
|
123
124
|
this.notifyTransitionStartForItems(sceneId);
|
|
124
125
|
this.activeSceneId = sceneId;
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
+
setActiveTransition(to) {
|
|
127
128
|
this.activeTransition = this.transitions.find((transition) => transition.to === to && transition.from === this.activeSceneId);
|
|
128
129
|
}
|
|
129
130
|
notifyTransitionStartForItems(activeStateId) {
|
package/package.json
CHANGED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePreloadAssets = usePreloadAssets;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
function isVideoAsset(url) {
|
|
6
|
-
const videoExtensions = ['.mp4', '.mov', '.webm'];
|
|
7
|
-
const lowerUrl = url.toLowerCase();
|
|
8
|
-
return videoExtensions.some(ext => lowerUrl.endsWith(ext));
|
|
9
|
-
}
|
|
10
|
-
function isImageAsset(url) {
|
|
11
|
-
const imageExtensions = ['.gif', '.png', '.jpg', '.jpeg', '.webp', '.avif', '.svg'];
|
|
12
|
-
const lowerUrl = url.toLowerCase();
|
|
13
|
-
return imageExtensions.some(ext => lowerUrl.endsWith(ext));
|
|
14
|
-
}
|
|
15
|
-
function usePreloadAssets(assets) {
|
|
16
|
-
(0, react_1.useEffect)(() => {
|
|
17
|
-
assets.forEach(({ url, id }) => {
|
|
18
|
-
if (isVideoAsset(url)) {
|
|
19
|
-
const video = document.createElement('video');
|
|
20
|
-
video.src = url;
|
|
21
|
-
video.preload = 'auto';
|
|
22
|
-
video.style.display = 'none';
|
|
23
|
-
document.body.appendChild(video);
|
|
24
|
-
video.addEventListener('loadeddata', () => {
|
|
25
|
-
setTimeout(() => {
|
|
26
|
-
if (video.parentNode) {
|
|
27
|
-
video.parentNode.removeChild(video);
|
|
28
|
-
}
|
|
29
|
-
}, 1000);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
if (isImageAsset(url)) {
|
|
33
|
-
const img = new Image();
|
|
34
|
-
img.src = url;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}, [assets]);
|
|
38
|
-
}
|