@3dsource/metabox-front-api 1.2.1-dev.0 → 1.2.1-dev.2
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 +218 -216
- package/package.json +44 -53
- package/dist/actions/CommandBase.d.ts +0 -7
- package/dist/actions/GetFastRender.d.ts +0 -2
- package/dist/actions/GetPdf.d.ts +0 -24
- package/dist/actions/GetScreenshot.d.ts +0 -34
- package/dist/actions/SetEnvironment.d.ts +0 -21
- package/dist/actions/SetEnvironmentMaterial.d.ts +0 -24
- package/dist/actions/SetMaterial.d.ts +0 -24
- package/dist/actions/SetProduct.d.ts +0 -25
- package/dist/actions/ShowEmbeddedMenu.d.ts +0 -20
- package/dist/actions/ShowOverlayInterface.d.ts +0 -23
- package/dist/actions/UnrealCommand.d.ts +0 -14
- package/dist/actions/WatchCallbacks.d.ts +0 -18
- package/dist/const/FromMetaboxApiAction.d.ts +0 -58
- package/dist/index.d.ts +0 -23
- package/dist/index.esm.js +0 -580
- package/dist/index.esm.js.map +0 -1
- package/dist/index.umd.js +0 -604
- package/dist/index.umd.js.map +0 -1
- package/dist/interfaces/FromMetaboxMessagePayloads.d.ts +0 -134
- package/dist/interfaces/ToMetaboxMessagePayloads.d.ts +0 -72
- package/dist/interfaces/UniversalConfigurator.d.ts +0 -213
- package/dist/interfaces/application-device-types.d.ts +0 -1
- package/dist/lib/Communicator.d.ts +0 -57
- package/dist/lib/EventDispatcher.d.ts +0 -39
- package/dist/lib/UrlUtils.d.ts +0 -18
- package/dist/lib/fromCommunicatorEvent.d.ts +0 -9
- package/dist/lib/integrateMetaBox.d.ts +0 -31
- package/dist/lib/saveImage.d.ts +0 -11
- package/dist/lib/sleep.d.ts +0 -10
- package/dist/lib/test/Communicator.spec.d.ts +0 -1
- package/dist/lib/test/integrateMetabox.spec.d.ts +0 -9
package/dist/index.esm.js
DELETED
|
@@ -1,580 +0,0 @@
|
|
|
1
|
-
import { fromEvent } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base class for commands sent to the MetaBox.
|
|
5
|
-
*/
|
|
6
|
-
class CommandBase {
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Represents a command to toggle the Unreal Overlay Interface Menu.
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* This action sends a message to the MetaBox API to toggle the visibility of the Unreal overlay UI.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* import { ShowOverlayInterface,Communicator } from '@3dsource/metabox-front-api';
|
|
17
|
-
*
|
|
18
|
-
* //...Assume that the integration is already implemented
|
|
19
|
-
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
20
|
-
* api.setCommandToMetaBox(new ShowOverlayInterface(true));
|
|
21
|
-
* };
|
|
22
|
-
*/
|
|
23
|
-
class ShowOverlayInterface extends CommandBase {
|
|
24
|
-
/**
|
|
25
|
-
* Creates an instance of ShowOverlayInterface.
|
|
26
|
-
*
|
|
27
|
-
* @param visible - A flag indicating whether the Unreal overlay UI should be visible.
|
|
28
|
-
*/
|
|
29
|
-
constructor(visible) {
|
|
30
|
-
super();
|
|
31
|
-
this.data = {
|
|
32
|
-
action: 'showOverlayInterface',
|
|
33
|
-
payload: {
|
|
34
|
-
visible,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Represents a command to toggle the Embedded MetaBox Menu.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* import { ShowEmbeddedMenu,Communicator } from '@3dsource/metabox-front-api';
|
|
45
|
-
*
|
|
46
|
-
* //...Assume that the integration is already implemented
|
|
47
|
-
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
48
|
-
* api.setCommandToMetaBox(new ShowEmbeddedMenu(true));
|
|
49
|
-
* };
|
|
50
|
-
*/
|
|
51
|
-
class ShowEmbeddedMenu extends CommandBase {
|
|
52
|
-
/**
|
|
53
|
-
* Creates an instance of ShowEmbeddedMenu.
|
|
54
|
-
*
|
|
55
|
-
* @param visible - A flag indicating whether the embedded menu should be visible.
|
|
56
|
-
*/
|
|
57
|
-
constructor(visible) {
|
|
58
|
-
super();
|
|
59
|
-
this.data = {
|
|
60
|
-
action: 'showEmbeddedMenu',
|
|
61
|
-
payload: {
|
|
62
|
-
visible,
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Represents a command to set the environment by its ID.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* import { SetEnvironment,Communicator } from '@3dsource/metabox-front-api';
|
|
73
|
-
*
|
|
74
|
-
* //...Assume that the integration is already implemented
|
|
75
|
-
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
76
|
-
* // Change the environment to '55555555-1234-1234-1234-01234567890'
|
|
77
|
-
* api.sendCommandToMetaBox(new SetEnvironment('55555555-1234-1234-1234-01234567890'));
|
|
78
|
-
* };
|
|
79
|
-
*/
|
|
80
|
-
class SetEnvironment extends CommandBase {
|
|
81
|
-
/**
|
|
82
|
-
* Creates an instance of SetEnvironment.
|
|
83
|
-
*
|
|
84
|
-
* @param environmentId - The environment ID.
|
|
85
|
-
*/
|
|
86
|
-
constructor(environmentId) {
|
|
87
|
-
super();
|
|
88
|
-
this.data = {
|
|
89
|
-
payload: {
|
|
90
|
-
id: environmentId,
|
|
91
|
-
},
|
|
92
|
-
action: 'loadLevel',
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Represents a command to set a product by its ID.
|
|
99
|
-
*
|
|
100
|
-
* @remarks
|
|
101
|
-
* This action sends a message to the MetaBox API to set a product using the provided product ID.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* import { SetProduct,Communicator } from '@3dsource/metabox-front-api';
|
|
105
|
-
*
|
|
106
|
-
* //...Assume that the integration is already implemented
|
|
107
|
-
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
108
|
-
* api.setCommandToMetaBox(new SetProduct(
|
|
109
|
-
* 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3'
|
|
110
|
-
* ));
|
|
111
|
-
* };
|
|
112
|
-
*/
|
|
113
|
-
class SetProduct extends CommandBase {
|
|
114
|
-
/**
|
|
115
|
-
* Creates an instance of SetProduct.
|
|
116
|
-
*
|
|
117
|
-
* @param productId - The product ID.
|
|
118
|
-
*/
|
|
119
|
-
constructor(productId) {
|
|
120
|
-
super();
|
|
121
|
-
this.data = {
|
|
122
|
-
payload: {
|
|
123
|
-
productId,
|
|
124
|
-
},
|
|
125
|
-
action: 'setProduct',
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Represents a command to get a PDF from Metabox.
|
|
132
|
-
* @remarks
|
|
133
|
-
* This class sends a message to the MetaBox API to generate a PDF based on the current configuration.
|
|
134
|
-
* This action does not require any parameters.
|
|
135
|
-
*
|
|
136
|
-
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* import { GetPdf,Communicator } from '@3dsource/metabox-front-api';
|
|
140
|
-
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
141
|
-
* api.sendCommandToMetaBox(new GetPdf());
|
|
142
|
-
* };
|
|
143
|
-
*/
|
|
144
|
-
class GetPdf extends CommandBase {
|
|
145
|
-
/**
|
|
146
|
-
* Creates an instance of GetPdf.
|
|
147
|
-
*
|
|
148
|
-
* @remarks
|
|
149
|
-
* This constructor does not require any parameters.
|
|
150
|
-
*/
|
|
151
|
-
constructor() {
|
|
152
|
-
super();
|
|
153
|
-
this.data = {
|
|
154
|
-
action: 'getPdf',
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Represents a command to set a material by its ID.
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* import { SetMaterial,Communicator } from '@3dsource/metabox-front-api';
|
|
164
|
-
*
|
|
165
|
-
* //...Assume that the integration is already implemented
|
|
166
|
-
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
167
|
-
* api.sendCommandToMetaBox(new SetMaterial(
|
|
168
|
-
* 'carpaint',
|
|
169
|
-
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
170
|
-
* ));
|
|
171
|
-
* };
|
|
172
|
-
*/
|
|
173
|
-
class SetMaterial extends CommandBase {
|
|
174
|
-
/**
|
|
175
|
-
* Creates an instance of SetMaterial.
|
|
176
|
-
*
|
|
177
|
-
* @param slotId - The slot ID.
|
|
178
|
-
* @param materialId - The material ID.
|
|
179
|
-
*/
|
|
180
|
-
constructor(slotId, materialId) {
|
|
181
|
-
super();
|
|
182
|
-
this.data = {
|
|
183
|
-
payload: {
|
|
184
|
-
slotId,
|
|
185
|
-
materialId,
|
|
186
|
-
},
|
|
187
|
-
action: 'setMaterialById',
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Represents a command to set an environment material by its ID.
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* import { SetEnvironmentMaterial,Communicator } from '@3dsource/metabox-front-api';
|
|
197
|
-
*
|
|
198
|
-
* //...Assume that the integration is already implemented
|
|
199
|
-
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
200
|
-
* api.sendCommandToMetaBox(new SetEnvironmentMaterial(
|
|
201
|
-
* 'carpaint',
|
|
202
|
-
* 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
|
|
203
|
-
* ));
|
|
204
|
-
* };
|
|
205
|
-
*/
|
|
206
|
-
class SetEnvironmentMaterial extends CommandBase {
|
|
207
|
-
/**
|
|
208
|
-
* Creates an instance of SetEnvironmentMaterial.
|
|
209
|
-
*
|
|
210
|
-
* @param slotId - The slot ID.
|
|
211
|
-
* @param materialId - The material ID.
|
|
212
|
-
*/
|
|
213
|
-
constructor(slotId, materialId) {
|
|
214
|
-
super();
|
|
215
|
-
this.data = {
|
|
216
|
-
payload: {
|
|
217
|
-
slotId,
|
|
218
|
-
materialId,
|
|
219
|
-
},
|
|
220
|
-
action: 'setEnvironmentMaterialById',
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Represents a command to get fast render.
|
|
227
|
-
*
|
|
228
|
-
* **Important**: Invoking this command will buffer it until the viewport is ready. Only then will the request be processed.
|
|
229
|
-
*
|
|
230
|
-
* @example
|
|
231
|
-
* import { GetScreenshot,Communicator,saveImage } from '@3dsource/metabox-front-api';
|
|
232
|
-
* window.env3DSource.apiReady = (api:Communicator) => {
|
|
233
|
-
* // Listen for events from the MetaBox API
|
|
234
|
-
* api.addEventListener('screenshot', (data) => {
|
|
235
|
-
* // Process the fast render response
|
|
236
|
-
* saveImage(data, 'Render.png');
|
|
237
|
-
* });
|
|
238
|
-
* api.sendCommandToMetaBox(new GetScreenshot('image/png', { x: 1024, y: 1024 }));
|
|
239
|
-
* };
|
|
240
|
-
*/
|
|
241
|
-
class GetScreenshot extends CommandBase {
|
|
242
|
-
/**
|
|
243
|
-
* Constructs an instance of GetScreenshot.
|
|
244
|
-
* @param mimeType - The output format.
|
|
245
|
-
* @param size - Optional size in pixels.
|
|
246
|
-
*/
|
|
247
|
-
constructor(mimeType, size) {
|
|
248
|
-
super();
|
|
249
|
-
this.data = {
|
|
250
|
-
payload: {
|
|
251
|
-
format: mimeType,
|
|
252
|
-
size,
|
|
253
|
-
},
|
|
254
|
-
action: 'getScreenshot',
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* @internal
|
|
261
|
-
* @hidden
|
|
262
|
-
* Represents a command to send Unreal command.
|
|
263
|
-
*/
|
|
264
|
-
class UnrealCommand extends CommandBase {
|
|
265
|
-
constructor(payload) {
|
|
266
|
-
super();
|
|
267
|
-
this.data = {
|
|
268
|
-
payload,
|
|
269
|
-
action: 'sendCommandToUnreal',
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* @deprecated, use `UnrealCommand` instead.
|
|
275
|
-
*/
|
|
276
|
-
const SendCommandToUnreal = UnrealCommand;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* @experimental
|
|
280
|
-
* @internal
|
|
281
|
-
* @hidden
|
|
282
|
-
* @remarks
|
|
283
|
-
* Represents a command to watch Unreal callbacks from Unreal engine.
|
|
284
|
-
* Can be useful for custom solutions.
|
|
285
|
-
*/
|
|
286
|
-
class WatchCallbacks extends CommandBase {
|
|
287
|
-
/**
|
|
288
|
-
* Creates an instance of WatchCallbacks.
|
|
289
|
-
*
|
|
290
|
-
* @remarks
|
|
291
|
-
* This constructor does not require any parameters.
|
|
292
|
-
*/
|
|
293
|
-
constructor() {
|
|
294
|
-
super();
|
|
295
|
-
this.data = {
|
|
296
|
-
action: 'watchCallbacks',
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* EventDispatcher is a class that manages event listeners and dispatches events to them.
|
|
303
|
-
*/
|
|
304
|
-
class EventDispatcher {
|
|
305
|
-
constructor() {
|
|
306
|
-
/**
|
|
307
|
-
* Storage for callback listeners by message type.
|
|
308
|
-
*/
|
|
309
|
-
this.listeners = [];
|
|
310
|
-
}
|
|
311
|
-
destroy() {
|
|
312
|
-
this.listeners = [];
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Adds an event listener for receiving specific types of messages.
|
|
316
|
-
*
|
|
317
|
-
* @param messageType - The message type to listen for.
|
|
318
|
-
* @param callback - The callback function to execute when a message is received.
|
|
319
|
-
*/
|
|
320
|
-
addEventListener(messageType, callback) {
|
|
321
|
-
this.listeners.push({ messageType, callback });
|
|
322
|
-
return this;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Dispatches an event to all listeners of a specific message type.
|
|
326
|
-
*
|
|
327
|
-
* @param messageType - The message type.
|
|
328
|
-
* @param data - The data associated with the event.
|
|
329
|
-
*/
|
|
330
|
-
dispatchEvent(messageType, data) {
|
|
331
|
-
this.listeners
|
|
332
|
-
.filter((listener) => listener.messageType === messageType)
|
|
333
|
-
.forEach((listener) => listener.callback(data));
|
|
334
|
-
return this;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Removes an event listener for a specific type of message.
|
|
338
|
-
*
|
|
339
|
-
* @param messageType - The message type.
|
|
340
|
-
* @param callback - The callback function to remove.
|
|
341
|
-
*/
|
|
342
|
-
removeEventListener(messageType, callback) {
|
|
343
|
-
this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
|
|
344
|
-
return this;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Handles messaging between the host page and embedded MetaBox content.
|
|
350
|
-
* @internal Use {@link Communicator.createInstance} or the {@link integrateMetaBox} helper to instantiate.
|
|
351
|
-
*/
|
|
352
|
-
class Communicator extends EventDispatcher {
|
|
353
|
-
/**
|
|
354
|
-
* Constructs a Communicator, replacing any existing instance, and begins listening for messages.
|
|
355
|
-
* @internal
|
|
356
|
-
*/
|
|
357
|
-
constructor() {
|
|
358
|
-
var _a;
|
|
359
|
-
super();
|
|
360
|
-
/**
|
|
361
|
-
* Bound handler for incoming postMessage events.
|
|
362
|
-
*/
|
|
363
|
-
this.binder = this.handleMessageReceived.bind(this, 'metaboxData');
|
|
364
|
-
(_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
365
|
-
Communicator.instance = this;
|
|
366
|
-
window.addEventListener('message', this.binder);
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Cleans up resources and stops listening for messages.
|
|
370
|
-
*/
|
|
371
|
-
destroy() {
|
|
372
|
-
super.destroy();
|
|
373
|
-
window.removeEventListener('message', this.binder);
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Posts a command to the MetaBox iframe.
|
|
377
|
-
* @param command - An action command containing data to send.
|
|
378
|
-
*/
|
|
379
|
-
sendCommandToMetaBox(command) {
|
|
380
|
-
const { data } = command;
|
|
381
|
-
const iframe = document.getElementById('embeddedContent');
|
|
382
|
-
if (!(iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow)) {
|
|
383
|
-
console.warn('MetaBox IFrame not found or not ready.');
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
const message = {
|
|
387
|
-
host: 'metaBoxHost',
|
|
388
|
-
payload: Object.assign({}, data),
|
|
389
|
-
};
|
|
390
|
-
// Replace '*' with a specific origin in production for better security.
|
|
391
|
-
iframe.contentWindow.postMessage(message, '*');
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Filters and dispatches incoming messages from MetaBox.
|
|
395
|
-
* @param messageType - Expected message type for filtering ('metaboxData').
|
|
396
|
-
* @param event - The postMessage event received on window.
|
|
397
|
-
*/
|
|
398
|
-
handleMessageReceived(messageType, event) {
|
|
399
|
-
var _a;
|
|
400
|
-
// Optionally validate event.origin for security.
|
|
401
|
-
if (messageType !== 'metaboxData' || ((_a = event.data) === null || _a === void 0 ? void 0 : _a.host) !== 'metabox') {
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
const { eventType, payload } = event.data.payload;
|
|
405
|
-
this.dispatchEvent(eventType, payload);
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Listens for MetaBox to signal readiness, then initializes communicator.
|
|
409
|
-
* @param apiReadyCallback - Called with the new Communicator once MetaBox is loaded.
|
|
410
|
-
*/
|
|
411
|
-
static createInstance(apiReadyCallback) {
|
|
412
|
-
const startHandler = (event) => {
|
|
413
|
-
var _a;
|
|
414
|
-
const message = event.data;
|
|
415
|
-
if (((_a = message === null || message === void 0 ? void 0 : message.payload) === null || _a === void 0 ? void 0 : _a.action) === 'appLoaded') {
|
|
416
|
-
apiReadyCallback(new Communicator());
|
|
417
|
-
window.removeEventListener('message', startHandler);
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
window.addEventListener('message', startHandler);
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Registers an event listener for messages dispatched by MetaBox.
|
|
424
|
-
* @override
|
|
425
|
-
*/
|
|
426
|
-
addEventListener(messageType, callback) {
|
|
427
|
-
return super.addEventListener(messageType, callback);
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Dispatches a typed event to all registered listeners.
|
|
431
|
-
* @override
|
|
432
|
-
*/
|
|
433
|
-
dispatchEvent(messageType, data) {
|
|
434
|
-
return super.dispatchEvent(messageType, data);
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Removes a previously registered event listener.
|
|
438
|
-
* @override
|
|
439
|
-
*/
|
|
440
|
-
removeEventListener(messageType, callback) {
|
|
441
|
-
return super.removeEventListener(messageType, callback);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Singleton reference to the current communicator instance.
|
|
446
|
-
*/
|
|
447
|
-
Communicator.instance = null;
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Integrates the MetaBox into the provided layout.
|
|
451
|
-
*
|
|
452
|
-
* @remarks
|
|
453
|
-
* This function injects an iframe into a specified container element in the DOM and initializes
|
|
454
|
-
* the communicator for interacting with the MetaBox embedded content.
|
|
455
|
-
*
|
|
456
|
-
* @param iframeSrc - The source URL of the MetaBox iframe.
|
|
457
|
-
* Additional url parameters:
|
|
458
|
-
* ```javascript
|
|
459
|
-
* sidebar=false - disables the internal MetaBox menu
|
|
460
|
-
* introImage=https://example.com/image.png - sets the intro image
|
|
461
|
-
* ```
|
|
462
|
-
* i.e. final link will look like https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false&introImage=https://example.com/image.png
|
|
463
|
-
*
|
|
464
|
-
* @param containerId - The ID of the layout element. Defaults to 'embed3DSource'.
|
|
465
|
-
* @param apiReadyCallback
|
|
466
|
-
* @throws Error if the container element with the specified ID is not found.
|
|
467
|
-
*
|
|
468
|
-
* @example
|
|
469
|
-
* import {
|
|
470
|
-
* integrateMetaBox,
|
|
471
|
-
* } from '@3dsource/metabox-front-api';
|
|
472
|
-
*
|
|
473
|
-
* integrateMetaBox(
|
|
474
|
-
* 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
|
|
475
|
-
* 'embed3DSource'
|
|
476
|
-
* );
|
|
477
|
-
*/
|
|
478
|
-
function integrateMetaBox(iframeSrc, containerId = 'embed3DSource', apiReadyCallback) {
|
|
479
|
-
const container = document.getElementById(containerId);
|
|
480
|
-
if (!container) {
|
|
481
|
-
throw new Error(`Container element with id ${containerId} not found`);
|
|
482
|
-
}
|
|
483
|
-
Communicator.createInstance(apiReadyCallback);
|
|
484
|
-
const style = document.createElement('style');
|
|
485
|
-
style.innerHTML = `
|
|
486
|
-
#${containerId} {
|
|
487
|
-
width: 100%;
|
|
488
|
-
height: 100%;
|
|
489
|
-
overflow: hidden;
|
|
490
|
-
position: relative;
|
|
491
|
-
}
|
|
492
|
-
`;
|
|
493
|
-
document.head.appendChild(style);
|
|
494
|
-
const iframe = document.createElement('iframe');
|
|
495
|
-
iframe.setAttribute('referrerPolicy', 'no-referrer-when-downgrade');
|
|
496
|
-
iframe.setAttribute('id', 'embeddedContent');
|
|
497
|
-
iframe.style.border = '0';
|
|
498
|
-
iframe.style.width = '100%';
|
|
499
|
-
iframe.style.height = '100%';
|
|
500
|
-
iframe.style.overflow = 'hidden';
|
|
501
|
-
iframe.src = iframeSrc;
|
|
502
|
-
container.appendChild(iframe);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Wrapper helper function to use it with rxJs same as `fromEvent` to listen to events from the Communicator.
|
|
507
|
-
* @param target
|
|
508
|
-
* @param eventName
|
|
509
|
-
*/
|
|
510
|
-
function fromCommunicatorEvent(target, eventName) {
|
|
511
|
-
return fromEvent(target, eventName);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Saves an image by triggering a download.
|
|
516
|
-
*
|
|
517
|
-
* @remarks
|
|
518
|
-
* This function creates an anchor element, sets its `href` attribute to the provided image URL,
|
|
519
|
-
* and triggers a click event to initiate a download with the specified filename.
|
|
520
|
-
*
|
|
521
|
-
* @param imageUrl - The URL of the image to save.
|
|
522
|
-
* @param filename - The name of the file to save.
|
|
523
|
-
*/
|
|
524
|
-
function saveImage(imageUrl, filename) {
|
|
525
|
-
const a = document.createElement('a');
|
|
526
|
-
a.href = imageUrl;
|
|
527
|
-
a.download = filename;
|
|
528
|
-
document.body.appendChild(a);
|
|
529
|
-
a.click();
|
|
530
|
-
document.body.removeChild(a);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* Pauses execution for a specified duration.
|
|
535
|
-
*
|
|
536
|
-
* @remarks
|
|
537
|
-
* This function returns a promise that resolves after the given number of milliseconds.
|
|
538
|
-
*
|
|
539
|
-
* @param time - The time to sleep in milliseconds.
|
|
540
|
-
* @returns A promise that resolves after the specified duration.
|
|
541
|
-
*/
|
|
542
|
-
function sleep(time) {
|
|
543
|
-
return new Promise((resolve) => setTimeout(resolve, time));
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Sets the URL parameters based on the provided state.
|
|
548
|
-
*
|
|
549
|
-
* @remarks
|
|
550
|
-
* This function updates the current URL by replacing its search parameters with the key-value pairs from the provided state object.
|
|
551
|
-
*
|
|
552
|
-
* @param state - An object containing key-value pairs to set as URL parameters.
|
|
553
|
-
*/
|
|
554
|
-
function setUrlParams(state) {
|
|
555
|
-
const url = new URL(window.location.href);
|
|
556
|
-
url.search = '';
|
|
557
|
-
Object.entries(state).forEach(([key, value]) => {
|
|
558
|
-
url.searchParams.set(key, value);
|
|
559
|
-
});
|
|
560
|
-
history.replaceState(null, '', url.toString());
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Retrieves the URL parameters as an object.
|
|
564
|
-
*
|
|
565
|
-
* @remarks
|
|
566
|
-
* This function parses the current URL's search parameters and returns them as a key-value object.
|
|
567
|
-
*
|
|
568
|
-
* @returns An object containing the URL parameters.
|
|
569
|
-
*/
|
|
570
|
-
function getUrlParams() {
|
|
571
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
572
|
-
const selections = {};
|
|
573
|
-
urlParams.forEach((value, key) => {
|
|
574
|
-
selections[key] = value;
|
|
575
|
-
});
|
|
576
|
-
return selections;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
export { CommandBase, Communicator, GetPdf, GetScreenshot, SendCommandToUnreal, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, UnrealCommand, WatchCallbacks, fromCommunicatorEvent, getUrlParams, integrateMetaBox, saveImage, setUrlParams, sleep };
|
|
580
|
-
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|