@3dsource/metabox-front-api 0.0.11 → 0.0.13

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.
@@ -0,0 +1,773 @@
1
+ /*
2
+ * Copyright (c) 2025.
3
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
4
+ * All Rights Reserved
5
+ */
6
+ /**
7
+ * Base class for all API actions.
8
+ * @hidden
9
+ */
10
+ class ApiAction {
11
+ constructor() {
12
+ this.api = window.env3DSource.api;
13
+ }
14
+ }
15
+
16
+ /*
17
+ * Copyright (c) 2025.
18
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
19
+ * All Rights Reserved
20
+ */
21
+ const ToMetaBoxApiAction = {
22
+ getPdf: 'getPdf',
23
+ loadLevel: 'loadLevel',
24
+ setProduct: 'setProduct',
25
+ /**
26
+ * @deprecated, use 'watchCallbacks'"
27
+ * use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
28
+ * @hidden
29
+ */
30
+ addResponse: 'addResponse',
31
+ getFastRender: 'getFastRender',
32
+ watchCallbacks: 'watchCallbacks',
33
+ setMaterialById: 'setMaterialById',
34
+ showEmbeddedMenu: 'showEmbeddedMenu',
35
+ forceSetDeviceType: 'forceSetDeviceType',
36
+ sendCommandToUnreal: 'sendCommandToUnreal',
37
+ setEnvironmentMaterialById: 'setEnvironmentMaterialById',
38
+ };
39
+
40
+ /*
41
+ * Copyright (c) 2025.
42
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
43
+ * All Rights Reserved
44
+ */
45
+ /**
46
+ * Represents an action to toggle the Embedded Menu in MetaBox.
47
+ *
48
+ * @remarks
49
+ * This action sends a message to the MetaBox API to toggle the visibility of the embedded menu.
50
+ */
51
+ class ShowEmbeddedMenu extends ApiAction {
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.api.sendMessageToMetaBox({
60
+ action: ToMetaBoxApiAction.showEmbeddedMenu,
61
+ payload: {
62
+ visible,
63
+ },
64
+ });
65
+ }
66
+ }
67
+
68
+ /*
69
+ * Copyright (c) 2025.
70
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
71
+ * All Rights Reserved
72
+ */
73
+ /**
74
+ * Represents an action to set the environment by its ID.
75
+ * @remarks
76
+ * This action sends a message to the MetaBox API to load the environment level using the specified environment ID.
77
+ * It requires the MetaBox API to be properly initialized and an event listener to be registered.
78
+ *
79
+ * @example
80
+ * import { integrateMetaBox, SetEnvironment } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
81
+ *
82
+ * // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
83
+ * integrateMetaBox(
84
+ * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
85
+ * 'embed3DSource'
86
+ * );
87
+ *
88
+ * // Setup API ready callback
89
+ * window.env3DSource = window.env3DSource || {};
90
+ * window.env3DSource.apiReady = (api) => {
91
+ * // Change the environment to '55555555-1234-1234-1234-01234567890'
92
+ * new SetEnvironment('55555555-1234-1234-1234-01234567890');
93
+ * };
94
+ */
95
+ class SetEnvironment extends ApiAction {
96
+ /**
97
+ * Creates an instance of SetEnvironment.
98
+ *
99
+ * @param environmentId - The environment ID.
100
+ */
101
+ constructor(environmentId) {
102
+ super();
103
+ this.api.sendMessageToMetaBox({
104
+ payload: {
105
+ id: environmentId,
106
+ },
107
+ action: ToMetaBoxApiAction.loadLevel,
108
+ });
109
+ }
110
+ }
111
+
112
+ /*
113
+ * Copyright (c) 2025.
114
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
115
+ * All Rights Reserved
116
+ */
117
+ /**
118
+ * Represents an action to set a product by its ID.
119
+ *
120
+ * @remarks
121
+ * This action sends a message to the MetaBox API to set a product using the provided product ID.
122
+ */
123
+ class SetProduct extends ApiAction {
124
+ /**
125
+ * Creates an instance of SetProduct.
126
+ *
127
+ * @param productId - The product ID.
128
+ */
129
+ constructor(productId) {
130
+ super();
131
+ this.api.sendMessageToMetaBox({
132
+ payload: {
133
+ productId,
134
+ },
135
+ action: ToMetaBoxApiAction.setProduct,
136
+ });
137
+ }
138
+ }
139
+
140
+ /*
141
+ * Copyright (c) 2025.
142
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
143
+ * All Rights Reserved
144
+ */
145
+ /**
146
+ * Represents an action to get a PDF from Metabox.
147
+ * @remarks
148
+ * This class sends a message to the MetaBox API to generate a PDF based on the current configuration.
149
+ * This action does not require any parameters.
150
+ *
151
+ * **Important:** Before invoking this action, ensure that the MetaBox viewport is fully loaded. This is indicated by the event:
152
+ *```javascript
153
+ * data.eventType === 'viewportReady' && data.payload === true.
154
+ * ```
155
+ * Only then request be processed.
156
+ *
157
+ * @example
158
+ * import { integrateMetaBox, GetPdf } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
159
+ *
160
+ * integrateMetaBox(
161
+ * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
162
+ * 'embed3DSource'
163
+ * );
164
+ *
165
+ * window.env3DSource = window.env3DSource || {};
166
+ * window.env3DSource.apiReady = (api) => {
167
+ * api.addEventListener('metaboxData', (data) => {
168
+ * if (data.eventType === 'viewportReady' && data.payload === true) {
169
+ * // Request a PDF of the current configuration
170
+ * new GetPdf();
171
+ * }
172
+ * });
173
+ * };
174
+ */
175
+ class GetPdf extends ApiAction {
176
+ /**
177
+ * Creates an instance of GetPdf.
178
+ *
179
+ * @remarks
180
+ * This constructor does not require any parameters.
181
+ */
182
+ constructor() {
183
+ super();
184
+ this.api.sendMessageToMetaBox({
185
+ action: ToMetaBoxApiAction.getPdf,
186
+ });
187
+ }
188
+ }
189
+
190
+ /*
191
+ * Copyright (c) 2025.
192
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
193
+ * All Rights Reserved
194
+ */
195
+ /**
196
+ * Represents an action to set a material by its ID.
197
+ *
198
+ * @remarks
199
+ * This action sends a message to the MetaBox API to update the material on a specific product slot using the provided identifiers.
200
+
201
+ * **Important:** Before invoking this action, ensure that the MetaBox already dispatched
202
+ * as minimum one eventType:"basicConfiguratorDataWithState":
203
+ * ```javascript
204
+ * data.eventType === 'basicConfiguratorDataWithState'.
205
+ * ```
206
+ * Only then request be processed.
207
+ *
208
+ * @example
209
+ * import { SetMaterial } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
210
+ *
211
+ * // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
212
+ * integrateMetaBox(
213
+ * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
214
+ * 'embed3DSource'
215
+ * );
216
+ *
217
+ * // Set up the global API environment
218
+ * window.env3DSource = window.env3DSource || {};
219
+ * window.env3DSource.apiReady = (api) => {
220
+ * // Listen for events from the MetaBox API
221
+ * api.addEventListener('metaboxData', (data) => {
222
+ * // Process SetMaterial
223
+ * if (data.eventType === 'basicConfiguratorDataWithState') {
224
+ * new SetMaterial(
225
+ * 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
226
+ * 'carpaint',
227
+ * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
228
+ * );
229
+ * }
230
+ * });
231
+ * };
232
+ */
233
+ class SetMaterial extends ApiAction {
234
+ /**
235
+ * Creates an instance of SetMaterial.
236
+ *
237
+ * @param productId - The product ID.
238
+ * @param slotId - The slot ID.
239
+ * @param materialId - The material ID.
240
+ */
241
+ constructor(productId, slotId, materialId) {
242
+ super();
243
+ this.api.sendMessageToMetaBox({
244
+ payload: {
245
+ productId,
246
+ slotId,
247
+ materialId,
248
+ },
249
+ action: ToMetaBoxApiAction.setMaterialById,
250
+ });
251
+ }
252
+ }
253
+
254
+ /*
255
+ * Copyright (c) 2025.
256
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
257
+ * All Rights Reserved
258
+ */
259
+ /**
260
+ * Represents an action to set a material by its ID.
261
+ *
262
+ * @remarks
263
+ * This action sends a message to the MetaBox API to update the material on a specific product slot using the provided identifiers.
264
+
265
+ * **Important:** Before invoking this action, ensure that the MetaBox already dispatched
266
+ * as minimum one eventType:"basicConfiguratorDataWithState":
267
+ * ```javascript
268
+ * data.eventType === 'basicConfiguratorDataWithState'.
269
+ * ```
270
+ * Only then request be processed.
271
+ *
272
+ * @example
273
+ * import { SetMaterial } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
274
+ *
275
+ * // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
276
+ * integrateMetaBox(
277
+ * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
278
+ * 'embed3DSource'
279
+ * );
280
+ *
281
+ * // Set up the global API environment
282
+ * window.env3DSource = window.env3DSource || {};
283
+ * window.env3DSource.apiReady = (api) => {
284
+ * // Listen for events from the MetaBox API
285
+ * api.addEventListener('metaboxData', (data) => {
286
+ * // Process SetMaterial
287
+ * if (data.eventType === 'basicConfiguratorDataWithState') {
288
+ * new SetEnvironmentMaterial(
289
+ * 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
290
+ * 'carpaint',
291
+ * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
292
+ * );
293
+ * }
294
+ * });
295
+ * };
296
+ */
297
+ class SetEnvironmentMaterial extends ApiAction {
298
+ /**
299
+ * Creates an instance of SetMaterial.
300
+ *
301
+ * @param productId - The product ID.
302
+ * @param slotId - The slot ID.
303
+ * @param materialId - The material ID.
304
+ */
305
+ constructor(productId, slotId, materialId) {
306
+ super();
307
+ this.api.sendMessageToMetaBox({
308
+ payload: {
309
+ productId,
310
+ slotId,
311
+ materialId,
312
+ },
313
+ action: ToMetaBoxApiAction.setEnvironmentMaterialById,
314
+ });
315
+ }
316
+ }
317
+
318
+ /*
319
+ * Copyright (c) 2025.
320
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
321
+ * All Rights Reserved
322
+ */
323
+ /**
324
+ * Represents a fast render action.
325
+ * @remarks
326
+ * This class sends a message to the MetaBox API to obtain a fast render based on the provided format and optional size.
327
+ *
328
+ * **Important:** Before invoking this action, ensure that the MetaBox viewport is fully loaded. This is indicated by the event:
329
+ * ```javascript
330
+ * data.eventType === 'viewportReady' && data.payload === true.
331
+ * ```
332
+ * Only then request be processed.
333
+ *
334
+ * @example
335
+ * import { integrateMetaBox, GetFastRender, saveImage } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
336
+ *
337
+ * // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
338
+ * integrateMetaBox(
339
+ * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
340
+ * 'embed3DSource'
341
+ * );
342
+ *
343
+ * // Set up the global API environment
344
+ * window.env3DSource = window.env3DSource || {};
345
+ * window.env3DSource.apiReady = (api) => {
346
+ * // Listen for events from the MetaBox API
347
+ * api.addEventListener('metaboxData', (data) => {
348
+ * // Ensure the viewport is ready before sending render requests
349
+ * if (data.eventType === 'viewportReady' && data.payload === true) {
350
+ * // Request a fast render (PNG image with 1024x1024 dimensions)
351
+ * new GetFastRender('image/png', { x: 1024, y: 1024 });
352
+ * }
353
+ * // Process the fast render response
354
+ * if (data.eventType === 'fastRender') {
355
+ * saveImage(data.payload, 'Render.png');
356
+ * }
357
+ * });
358
+ * };
359
+ */
360
+ class GetFastRender extends ApiAction {
361
+ /**
362
+ * Constructs an instance of GetFastRender.
363
+ * @param mimeType - The output format.
364
+ * @param size - Optional size in pixels.
365
+ */
366
+ constructor(mimeType, size) {
367
+ super();
368
+ this.api.sendMessageToMetaBox({
369
+ payload: {
370
+ format: mimeType,
371
+ size,
372
+ },
373
+ action: ToMetaBoxApiAction.getFastRender,
374
+ });
375
+ }
376
+ }
377
+
378
+ /*
379
+ * Copyright (c) 2025.
380
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
381
+ * All Rights Reserved
382
+ */
383
+ /**
384
+ * @internal
385
+ * @hidden
386
+ * Represents an action to send Unreal command.
387
+ */
388
+ class SendCommandToUnreal extends ApiAction {
389
+ constructor(payload) {
390
+ super();
391
+ this.api.sendMessageToMetaBox({
392
+ payload,
393
+ action: ToMetaBoxApiAction.sendCommandToUnreal,
394
+ });
395
+ }
396
+ }
397
+
398
+ /*
399
+ * Copyright (c) 2025.
400
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
401
+ * All Rights Reserved
402
+ */
403
+ /**
404
+ * @experimental
405
+ * @remarks
406
+ * Represents an action to watch Unreal callbacks from Unreal engine.
407
+ * Can be useful for custom solutions.
408
+ */
409
+ class WatchCallbacks extends ApiAction {
410
+ /**
411
+ * Creates an instance of WatchCallbacks.
412
+ *
413
+ * @remarks
414
+ * This constructor does not require any parameters.
415
+ */
416
+ constructor() {
417
+ super();
418
+ this.api.sendMessageToMetaBox({
419
+ action: ToMetaBoxApiAction.watchCallbacks,
420
+ });
421
+ }
422
+ }
423
+
424
+ /*
425
+ * Copyright (c) 2025.
426
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
427
+ * All Rights Reserved
428
+ */
429
+ const messageType = 'metaboxData';
430
+ /**
431
+ * API class to handle communication with the embedded content.
432
+ * @internal Do not Create an instance of this class directly.
433
+ * integrateMetabox will create an instance of this class.
434
+ *
435
+ * @remarks
436
+ * This class sets up a communication channel with the embedded content via window messages.
437
+ * @hidden
438
+ */
439
+ class Communicator {
440
+ /**
441
+ * Creates an instance of Communicator.
442
+ * @internal
443
+ * @remarks
444
+ * If an instance already exists, it will be destroyed before creating a new one.
445
+ * The instance listens for messages from the iframe.
446
+ */
447
+ constructor() {
448
+ var _a;
449
+ /**
450
+ * Storage for callback listeners by message type.
451
+ */
452
+ this.listeners = [];
453
+ /**
454
+ * Binder function for handling incoming messages.
455
+ */
456
+ this.binder = this.handleMessageReceived.bind(this, messageType);
457
+ (_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
458
+ Communicator.instance = this;
459
+ window.addEventListener('message', this.binder);
460
+ }
461
+ /**
462
+ * Destroys the communicator instance by clearing listeners and removing event listeners.
463
+ */
464
+ destroy() {
465
+ this.listeners = [];
466
+ window.removeEventListener('message', this.binder);
467
+ }
468
+ /**
469
+ * Sends a message to the embedded content (MetaBox).
470
+ *
471
+ * @param data - The data to send.
472
+ */
473
+ sendMessageToMetaBox(data) {
474
+ var _a;
475
+ const iframe = document.getElementById('embeddedContent');
476
+ const dataToSend = {
477
+ host: 'metaBoxHost',
478
+ payload: Object.assign({}, data),
479
+ };
480
+ // In production, replace "*" with the actual origin for added security.
481
+ (_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(dataToSend, '*');
482
+ }
483
+ /**
484
+ * Adds an event listener for receiving specific types of messages.
485
+ *
486
+ * @param messageType - The message type to listen for.
487
+ * @param callback - The callback function to execute when a message is received.
488
+ */
489
+ addEventListener(messageType, callback) {
490
+ this.listeners.push({ messageType, callback });
491
+ }
492
+ /**
493
+ * Dispatches an event to all listeners of a specific message type.
494
+ *
495
+ * @param messageType - The message type.
496
+ * @param data - The data associated with the event.
497
+ */
498
+ dispatchEvent(messageType, data) {
499
+ this.listeners
500
+ .filter((listener) => listener.messageType === messageType)
501
+ .forEach((listener) => listener.callback(data));
502
+ }
503
+ /**
504
+ * Handles incoming messages by invoking the appropriate callbacks.
505
+ *
506
+ * @param messageType - The message type to filter for.
507
+ * @param event - The incoming message event.
508
+ *
509
+ * @remarks
510
+ * Optionally, you can perform an origin check for added security.
511
+ */
512
+ handleMessageReceived(messageType, event) {
513
+ var _a;
514
+ // Optional: Perform origin check here for added security
515
+ // if (event.origin !== "EXPECTED_ORIGIN") return;
516
+ if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.host) !== 'metabox') {
517
+ return;
518
+ }
519
+ this.listeners
520
+ .filter((listener) => listener.messageType === messageType)
521
+ .forEach((listener) => {
522
+ listener.callback(event.data.payload);
523
+ });
524
+ }
525
+ /**
526
+ * Removes an event listener for a specific type of message.
527
+ *
528
+ * @param messageType - The message type.
529
+ * @param callback - The callback function to remove.
530
+ */
531
+ removeEventListener(messageType, callback) {
532
+ this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
533
+ }
534
+ /**
535
+ * Initializes the communicator when the embedded content is ready.
536
+ * @internal
537
+ * @remarks
538
+ * This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
539
+ */
540
+ static createInstance() {
541
+ window.env3DSource = window.env3DSource || {};
542
+ const startHandler = (event) => {
543
+ var _a, _b;
544
+ if (((_b = (_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.action) === 'appLoaded' &&
545
+ 'apiReady' in window.env3DSource) {
546
+ window.env3DSource.api = new Communicator();
547
+ window.env3DSource.apiReady(window.env3DSource.api);
548
+ window.removeEventListener('message', startHandler);
549
+ }
550
+ };
551
+ window.addEventListener('message', startHandler);
552
+ }
553
+ }
554
+ /**
555
+ * The singleton instance of the communicator.
556
+ */
557
+ Communicator.instance = null;
558
+
559
+ /*
560
+ * Copyright (c) 2025.
561
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
562
+ * All Rights Reserved
563
+ */
564
+ /**
565
+ * Integrates the MetaBox into the provided layout.
566
+ *
567
+ * @remarks
568
+ * This function injects an iframe into a specified container element in the DOM and initializes
569
+ * the communicator for interacting with the MetaBox embedded content.
570
+ *
571
+ * @param iframeSrc - The source URL of the MetaBox iframe.
572
+ * Additional url parameters:
573
+ * ```javascript
574
+ * sidebar=false - disables the internal MetaBox menu
575
+ * introImage=https://example.com/image.png - sets the intro image
576
+ * ```
577
+ * 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
578
+ *
579
+ * @param containerId - The ID of the layout element. Defaults to 'embed3DSource'.
580
+ *
581
+ * @throws Error if the container element with the specified ID is not found.
582
+ *
583
+ * @example
584
+ * import {
585
+ * integrateMetaBox,
586
+ * } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
587
+ *
588
+ * integrateMetaBox(
589
+ * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
590
+ * 'embed3DSource'
591
+ * );
592
+ */
593
+ function integrateMetaBox(iframeSrc, containerId = 'embed3DSource') {
594
+ const container = document.getElementById(containerId);
595
+ if (!container) {
596
+ throw new Error(`Container element with id ${containerId} not found`);
597
+ }
598
+ Communicator.createInstance();
599
+ const style = document.createElement('style');
600
+ style.innerHTML = `
601
+ #${containerId} {
602
+ width: 100%;
603
+ height: 100%;
604
+ overflow: hidden;
605
+ position: relative;
606
+ }
607
+ `;
608
+ document.head.appendChild(style);
609
+ const iframe = document.createElement('iframe');
610
+ iframe.setAttribute('referrerPolicy', 'no-referrer-when-downgrade');
611
+ iframe.setAttribute('id', 'embeddedContent');
612
+ iframe.style.border = '0';
613
+ iframe.style.width = '100%';
614
+ iframe.style.height = '100%';
615
+ iframe.style.overflow = 'hidden';
616
+ iframe.src = iframeSrc;
617
+ container.appendChild(iframe);
618
+ }
619
+
620
+ /*
621
+ * Copyright (c) 2025.
622
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
623
+ * All Rights Reserved
624
+ */
625
+ /**
626
+ * Saves an image by triggering a download.
627
+ *
628
+ * @remarks
629
+ * This function creates an anchor element, sets its `href` attribute to the provided image URL,
630
+ * and triggers a click event to initiate a download with the specified filename.
631
+ *
632
+ * @param image - The URL of the image to save.
633
+ * @param filename - The name of the file to save.
634
+ */
635
+ function saveImage(image, filename) {
636
+ const a = document.createElement('a');
637
+ a.href = image;
638
+ a.download = filename;
639
+ document.body.appendChild(a);
640
+ a.click();
641
+ document.body.removeChild(a);
642
+ }
643
+
644
+ /*
645
+ * Copyright (c) 2025.
646
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
647
+ * All Rights Reserved
648
+ */
649
+ /**
650
+ * Pauses execution for a specified duration.
651
+ *
652
+ * @remarks
653
+ * This function returns a promise that resolves after the given number of milliseconds.
654
+ *
655
+ * @param time - The time to sleep in milliseconds.
656
+ * @returns A promise that resolves after the specified duration.
657
+ */
658
+ function sleep(time) {
659
+ return new Promise((resolve) => setTimeout(resolve, time));
660
+ }
661
+
662
+ /*
663
+ * Copyright (c) 2025.
664
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
665
+ * All Rights Reserved
666
+ */
667
+ /**
668
+ * Sets the URL parameters based on the provided state.
669
+ *
670
+ * @remarks
671
+ * This function updates the current URL by replacing its search parameters with the key-value pairs from the provided state object.
672
+ *
673
+ * @param state - An object containing key-value pairs to set as URL parameters.
674
+ */
675
+ function setUrlParams(state) {
676
+ const url = new URL(window.location.href);
677
+ url.search = '';
678
+ Object.entries(state).forEach(([key, value]) => {
679
+ url.searchParams.set(key, value);
680
+ });
681
+ history.replaceState(null, '', url.toString());
682
+ }
683
+ /**
684
+ * Retrieves the URL parameters as an object.
685
+ *
686
+ * @remarks
687
+ * This function parses the current URL's search parameters and returns them as a key-value object.
688
+ *
689
+ * @returns An object containing the URL parameters.
690
+ */
691
+ function getUrlParams() {
692
+ const urlParams = new URLSearchParams(window.location.search);
693
+ const selections = {};
694
+ urlParams.forEach((value, key) => {
695
+ selections[key] = value;
696
+ });
697
+ return selections;
698
+ }
699
+
700
+ /*
701
+ * Copyright (c) 2025.
702
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
703
+ * All Rights Reserved
704
+ */
705
+ const FromMetaboxApiAction = {
706
+ bridge: 'bridge',
707
+ appLoaded: 'appLoaded',
708
+ /**
709
+ * @hidden
710
+ * @deprecated, use MetaBoxApiAction.Bridge with eventType: "unrealFeature"
711
+ */
712
+ unrealFeatureBridge: 'unrealFeatureBridge',
713
+ /**
714
+ * @hidden
715
+ * @deprecated, use MetaBoxApiAction.Bridge with eventType: "unrealCallback"
716
+ */
717
+ unrealCallback: 'unrealCallback',
718
+ /**
719
+ * @hidden
720
+ * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
721
+ */
722
+ configuratorDataWithStateBridge: 'configuratorDataWithStateBridge',
723
+ /**
724
+ * @hidden
725
+ * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
726
+ */
727
+ configuratorDataBridge: 'configuratorDataBridge',
728
+ /**
729
+ * @hidden
730
+ * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
731
+ */
732
+ menuDataBridge: 'menuDataBridge',
733
+ /**
734
+ * @hidden
735
+ * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
736
+ */
737
+ flatMenuDataBridge: 'flatMenuDataBridge',
738
+ /**
739
+ * @hidden
740
+ * @deprecated, use Bridge with isFullscreen
741
+ */
742
+ fullScreenBridge: 'fullScreenBridge',
743
+ /**
744
+ * @hidden
745
+ * @deprecated, use Bridge with streamResolution
746
+ */
747
+ videoSize: 'videoSize',
748
+ /**
749
+ * @hidden
750
+ * Used in platform, must be removed in future
751
+ * @deprecated
752
+ */
753
+ unrealResponse: 'unrealResponse',
754
+ /**
755
+ * @hidden
756
+ * @deprecated\
757
+ */
758
+ getFastRender: 'getFastRender',
759
+ };
760
+
761
+ /*
762
+ * Copyright (c) 2025.
763
+ * 3DSource.com, Sergii Karanda steve@3dsource.com
764
+ * All Rights Reserved
765
+ */
766
+ const APPLICATION_DEVICE_TYPES = {
767
+ deviceTypeAuto: 'deviceTypeAuto',
768
+ deviceTypeMobile: 'deviceTypeMobile',
769
+ deviceTypeDesktop: 'deviceTypeDesktop',
770
+ };
771
+
772
+ export { APPLICATION_DEVICE_TYPES, ApiAction, Communicator, FromMetaboxApiAction, GetFastRender, GetPdf, SendCommandToUnreal, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, ToMetaBoxApiAction, WatchCallbacks, getUrlParams, integrateMetaBox, saveImage, setUrlParams, sleep };
773
+ //# sourceMappingURL=index.esm.js.map