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