@3dsource/metabox-front-api 0.0.10 → 0.0.12

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