senangwebs-tour 1.0.2 → 1.0.3
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/README.md +190 -217
- package/dist/swt-editor.css +759 -730
- package/dist/swt-editor.css.map +1 -1
- package/dist/swt-editor.js +550 -602
- package/dist/swt-editor.js.map +1 -1
- package/dist/swt-editor.min.css +1 -1
- package/dist/swt-editor.min.js +1 -1
- package/dist/swt.js +56531 -867
- package/dist/swt.js.map +1 -1
- package/dist/swt.min.js +12 -1
- package/package.json +6 -3
- package/src/editor/css/main.css +610 -581
- package/src/editor/js/export-manager.js +175 -262
- package/src/editor/js/preview-controller.js +36 -17
- package/src/editor/js/ui-controller.js +377 -362
- package/src/index.js +45 -33
package/src/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SenangWebs Tour (SWT) - Main Library Entry Point
|
|
3
|
-
* Version 1.0.
|
|
3
|
+
* Version 1.0.3
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
6
|
+
import AFRAME from "aframe";
|
|
7
|
+
import "@bookklik/senangstart-icons/dist/senangstart-icon.min.js";
|
|
8
|
+
import "./components/hotspot-listener.js";
|
|
9
|
+
import { AssetManager } from "./AssetManager.js";
|
|
10
|
+
import { SceneManager } from "./SceneManager.js";
|
|
11
|
+
import { HotspotManager } from "./HotspotManager.js";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Main Tour class - The public API for the SWT library
|
|
@@ -14,11 +16,13 @@ import { HotspotManager } from './HotspotManager.js';
|
|
|
14
16
|
class Tour {
|
|
15
17
|
constructor(aframeSceneEl, tourConfig) {
|
|
16
18
|
if (!aframeSceneEl) {
|
|
17
|
-
throw new Error(
|
|
19
|
+
throw new Error("SWT.Tour requires an A-Frame scene element");
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
if (!tourConfig || !tourConfig.scenes || !tourConfig.initialScene) {
|
|
21
|
-
throw new Error(
|
|
23
|
+
throw new Error(
|
|
24
|
+
"SWT.Tour requires a valid tour configuration with scenes and initialScene"
|
|
25
|
+
);
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
this.sceneEl = aframeSceneEl;
|
|
@@ -28,17 +32,20 @@ class Tour {
|
|
|
28
32
|
// Initialize managers
|
|
29
33
|
this.assetManager = new AssetManager(this.sceneEl);
|
|
30
34
|
this.sceneManager = new SceneManager(this.sceneEl, this.assetManager);
|
|
31
|
-
|
|
35
|
+
|
|
32
36
|
const defaultHotspotSettings = this.config.settings?.defaultHotspot || {};
|
|
33
37
|
this.hotspotManager = new HotspotManager(
|
|
34
|
-
this.sceneEl,
|
|
35
|
-
this.assetManager,
|
|
38
|
+
this.sceneEl,
|
|
39
|
+
this.assetManager,
|
|
36
40
|
defaultHotspotSettings
|
|
37
41
|
);
|
|
38
42
|
|
|
39
43
|
// Event listeners
|
|
40
44
|
this.boundHandleHotspotClick = this.handleHotspotClick.bind(this);
|
|
41
|
-
this.sceneEl.addEventListener(
|
|
45
|
+
this.sceneEl.addEventListener(
|
|
46
|
+
"swt-hotspot-clicked",
|
|
47
|
+
this.boundHandleHotspotClick
|
|
48
|
+
);
|
|
42
49
|
|
|
43
50
|
// Ensure cursor exists for interaction
|
|
44
51
|
this.ensureCursor();
|
|
@@ -48,13 +55,13 @@ class Tour {
|
|
|
48
55
|
* Ensure the scene has a cursor for interaction
|
|
49
56
|
*/
|
|
50
57
|
ensureCursor() {
|
|
51
|
-
const camera = this.sceneEl.querySelector(
|
|
58
|
+
const camera = this.sceneEl.querySelector("[camera]");
|
|
52
59
|
if (camera) {
|
|
53
|
-
let cursor = camera.querySelector(
|
|
60
|
+
let cursor = camera.querySelector("[cursor]");
|
|
54
61
|
if (!cursor) {
|
|
55
|
-
cursor = document.createElement(
|
|
56
|
-
cursor.setAttribute(
|
|
57
|
-
cursor.setAttribute(
|
|
62
|
+
cursor = document.createElement("a-cursor");
|
|
63
|
+
cursor.setAttribute("fuse", "true");
|
|
64
|
+
cursor.setAttribute("fuse-timeout", "1500");
|
|
58
65
|
camera.appendChild(cursor);
|
|
59
66
|
}
|
|
60
67
|
}
|
|
@@ -66,7 +73,7 @@ class Tour {
|
|
|
66
73
|
*/
|
|
67
74
|
async start() {
|
|
68
75
|
if (this.isStarted) {
|
|
69
|
-
console.warn(
|
|
76
|
+
console.warn("Tour has already been started");
|
|
70
77
|
return Promise.resolve();
|
|
71
78
|
}
|
|
72
79
|
|
|
@@ -74,12 +81,14 @@ class Tour {
|
|
|
74
81
|
const initialSceneData = this.config.scenes[initialSceneId];
|
|
75
82
|
|
|
76
83
|
if (!initialSceneData) {
|
|
77
|
-
throw new Error(
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Initial scene "${initialSceneId}" not found in tour configuration`
|
|
86
|
+
);
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
try {
|
|
81
90
|
// Emit scene-loading event
|
|
82
|
-
this.emit(
|
|
91
|
+
this.emit("scene-loading", { sceneId: initialSceneId });
|
|
83
92
|
|
|
84
93
|
// Load the scene
|
|
85
94
|
await this.sceneManager.loadScene(initialSceneId, initialSceneData);
|
|
@@ -90,12 +99,12 @@ class Tour {
|
|
|
90
99
|
this.isStarted = true;
|
|
91
100
|
|
|
92
101
|
// Emit events
|
|
93
|
-
this.emit(
|
|
94
|
-
this.emit(
|
|
102
|
+
this.emit("scene-loaded", { sceneId: initialSceneId });
|
|
103
|
+
this.emit("tour-started", { sceneId: initialSceneId });
|
|
95
104
|
|
|
96
105
|
return Promise.resolve();
|
|
97
106
|
} catch (error) {
|
|
98
|
-
console.error(
|
|
107
|
+
console.error("Failed to start tour:", error);
|
|
99
108
|
throw error;
|
|
100
109
|
}
|
|
101
110
|
}
|
|
@@ -119,7 +128,7 @@ class Tour {
|
|
|
119
128
|
|
|
120
129
|
try {
|
|
121
130
|
// Emit scene-loading event
|
|
122
|
-
this.emit(
|
|
131
|
+
this.emit("scene-loading", { sceneId: sceneId });
|
|
123
132
|
|
|
124
133
|
// Remove old hotspots
|
|
125
134
|
this.hotspotManager.removeAllHotspots();
|
|
@@ -131,7 +140,7 @@ class Tour {
|
|
|
131
140
|
await this.hotspotManager.createHotspots(sceneData.hotspots || []);
|
|
132
141
|
|
|
133
142
|
// Emit scene-loaded event
|
|
134
|
-
this.emit(
|
|
143
|
+
this.emit("scene-loaded", { sceneId: sceneId });
|
|
135
144
|
|
|
136
145
|
return Promise.resolve();
|
|
137
146
|
} catch (error) {
|
|
@@ -149,9 +158,9 @@ class Tour {
|
|
|
149
158
|
const currentSceneId = this.sceneManager.getCurrentSceneId();
|
|
150
159
|
|
|
151
160
|
// Emit hotspot-activated event
|
|
152
|
-
this.emit(
|
|
161
|
+
this.emit("hotspot-activated", {
|
|
153
162
|
hotspotData: hotspotData,
|
|
154
|
-
sceneId: currentSceneId
|
|
163
|
+
sceneId: currentSceneId,
|
|
155
164
|
});
|
|
156
165
|
|
|
157
166
|
// Handle the action
|
|
@@ -166,14 +175,14 @@ class Tour {
|
|
|
166
175
|
*/
|
|
167
176
|
handleAction(action) {
|
|
168
177
|
switch (action.type) {
|
|
169
|
-
case
|
|
178
|
+
case "navigateTo":
|
|
170
179
|
if (action.target) {
|
|
171
|
-
this.navigateTo(action.target).catch(err => {
|
|
172
|
-
console.error(
|
|
180
|
+
this.navigateTo(action.target).catch((err) => {
|
|
181
|
+
console.error("Navigation failed:", err);
|
|
173
182
|
});
|
|
174
183
|
}
|
|
175
184
|
break;
|
|
176
|
-
|
|
185
|
+
|
|
177
186
|
default:
|
|
178
187
|
console.warn(`Unknown action type: ${action.type}`);
|
|
179
188
|
}
|
|
@@ -196,7 +205,7 @@ class Tour {
|
|
|
196
205
|
const event = new CustomEvent(eventName, {
|
|
197
206
|
detail: detail,
|
|
198
207
|
bubbles: true,
|
|
199
|
-
cancelable: true
|
|
208
|
+
cancelable: true,
|
|
200
209
|
});
|
|
201
210
|
this.sceneEl.dispatchEvent(event);
|
|
202
211
|
}
|
|
@@ -224,7 +233,10 @@ class Tour {
|
|
|
224
233
|
*/
|
|
225
234
|
destroy() {
|
|
226
235
|
// Remove event listeners
|
|
227
|
-
this.sceneEl.removeEventListener(
|
|
236
|
+
this.sceneEl.removeEventListener(
|
|
237
|
+
"swt-hotspot-clicked",
|
|
238
|
+
this.boundHandleHotspotClick
|
|
239
|
+
);
|
|
228
240
|
|
|
229
241
|
// Clean up managers
|
|
230
242
|
this.hotspotManager.destroy();
|
|
@@ -239,7 +251,7 @@ class Tour {
|
|
|
239
251
|
export { Tour };
|
|
240
252
|
|
|
241
253
|
// Also attach to window for UMD usage
|
|
242
|
-
if (typeof window !==
|
|
254
|
+
if (typeof window !== "undefined") {
|
|
243
255
|
window.SWT = window.SWT || {};
|
|
244
256
|
window.SWT.Tour = Tour;
|
|
245
257
|
}
|