@3dsource/metabox-front-api 1.2.1-dev.0 → 1.2.1-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +218 -216
  3. package/{dist/index.esm.js → fesm2022/3dsource-metabox-front-api.mjs} +47 -46
  4. package/fesm2022/3dsource-metabox-front-api.mjs.map +1 -0
  5. package/index.d.ts +860 -0
  6. package/package.json +39 -53
  7. package/dist/actions/CommandBase.d.ts +0 -7
  8. package/dist/actions/GetFastRender.d.ts +0 -2
  9. package/dist/actions/GetPdf.d.ts +0 -24
  10. package/dist/actions/GetScreenshot.d.ts +0 -34
  11. package/dist/actions/SetEnvironment.d.ts +0 -21
  12. package/dist/actions/SetEnvironmentMaterial.d.ts +0 -24
  13. package/dist/actions/SetMaterial.d.ts +0 -24
  14. package/dist/actions/SetProduct.d.ts +0 -25
  15. package/dist/actions/ShowEmbeddedMenu.d.ts +0 -20
  16. package/dist/actions/ShowOverlayInterface.d.ts +0 -23
  17. package/dist/actions/UnrealCommand.d.ts +0 -14
  18. package/dist/actions/WatchCallbacks.d.ts +0 -18
  19. package/dist/const/FromMetaboxApiAction.d.ts +0 -58
  20. package/dist/index.d.ts +0 -23
  21. package/dist/index.esm.js.map +0 -1
  22. package/dist/index.umd.js +0 -604
  23. package/dist/index.umd.js.map +0 -1
  24. package/dist/interfaces/FromMetaboxMessagePayloads.d.ts +0 -134
  25. package/dist/interfaces/ToMetaboxMessagePayloads.d.ts +0 -72
  26. package/dist/interfaces/UniversalConfigurator.d.ts +0 -213
  27. package/dist/interfaces/application-device-types.d.ts +0 -1
  28. package/dist/lib/Communicator.d.ts +0 -57
  29. package/dist/lib/EventDispatcher.d.ts +0 -39
  30. package/dist/lib/UrlUtils.d.ts +0 -18
  31. package/dist/lib/fromCommunicatorEvent.d.ts +0 -9
  32. package/dist/lib/integrateMetaBox.d.ts +0 -31
  33. package/dist/lib/saveImage.d.ts +0 -11
  34. package/dist/lib/sleep.d.ts +0 -10
  35. package/dist/lib/test/Communicator.spec.d.ts +0 -1
  36. package/dist/lib/test/integrateMetabox.spec.d.ts +0 -9
package/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2025 3dsource
2
+ All Rights Reserved.
3
+
4
+ This software and associated documentation files (the “Software”) are proprietary
5
+ and confidential. Unauthorized copying, modification, distribution, or any other
6
+ use of the Software, in whole or in part, without the prior written consent of
7
+ the copyright holder is strictly prohibited.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
12
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,216 +1,218 @@
1
- # MetaBox Basic Configurators API
2
-
3
- This package provides an API for interacting with the MetaBox Basic Configurator using plain JavaScript.
4
-
5
- ### Installation (for using with frameworks like Angular, React, etc.) This is the recommended method
6
-
7
- ```sh
8
- npm install @3dsource/metabox-front-api@^1.0.0 --save
9
- ```
10
-
11
- then
12
-
13
- ```typescript
14
- import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, SetEnvironmentMaterial, Communicator, ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
15
- ```
16
-
17
- **OR** work with direct import from `NPM` using `CDN` network `unpkg.com` or `jsdelivr.net` (you can also download package and use it locally):
18
-
19
- ```javascript
20
- import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, SetEnvironmentMaterial, Communicator, ConfiguratorEnvelope } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@1.2.0';
21
- ```
22
-
23
- ## Usage
24
-
25
- ### 1. Create HTML Structure
26
-
27
- Ensure your HTML page has the following structure, where the MetaBox Configurator will be integrated.
28
- You **MUST** control CSS style of `embed3DSource` element to make the configurator responsive and fit your needs on your own.
29
-
30
- ```html
31
- <div id="embed3DSource">
32
- <!-- Your Configurator iframe will be embedded here -->
33
- </div>
34
- ```
35
-
36
- ### 2. Include Required Scripts
37
-
38
- Below is an example demonstrating how to use the MetaBox API functions:
39
-
40
- Insert this code into your HTML file just before the closing `</body>` tag:
41
-
42
- **EXAMPLE:**
43
-
44
- HTML:
45
-
46
- ```html
47
- <script type="module">
48
- import { integrateMetaBox, SetEnvironment, ShowOverlayInterface, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, Communicator, FromMetaboxApiAction } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@1.2.0';
49
-
50
- class JsIntegrator {
51
- constructor() {
52
- const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
53
- integrateMetaBox(url, 'embed3DSource', (api) => this.apiReady(api));
54
- }
55
-
56
- apiReady(api) {
57
- api.addEventListener('basicConfiguratorDataWithState', (data) => {
58
- this.updateConfiguratorData(data);
59
- });
60
- api.addEventListener('fastRender', (data) => {
61
- saveImage(data, 'Render.png');
62
- });
63
- this.setupInitialState(api);
64
- }
65
-
66
- updateConfiguratorData(data) {
67
- // Use data on your own
68
- }
69
-
70
- setupInitialState(api) {
71
- api.sendCommandToMetaBox(new SetProduct('productId'));
72
- api.sendCommandToMetaBox(new SetEnvironment('environmentId'));
73
- api.sendCommandToMetaBox(new SetMaterial('productId', 'slotId', 'materialId'));
74
- api.sendCommandToMetaBox(new SetEnvironmentMaterial('productId', 'slotId', 'materialId'));
75
- api.sendCommandToMetaBox(new ShowEmbeddedMenu(false));
76
- api.sendCommandToMetaBox(new ShowOverlayInterface(false));
77
- api.sendCommandToMetaBox(new GetPdf());
78
- api.sendCommandToMetaBox(new GetFastRender('image/png', { x: 1024, y: 1024 }));
79
- }
80
- }
81
-
82
- new JsIntegrator();
83
- </script>
84
- ```
85
-
86
- TypeScript:
87
-
88
- ```typescript
89
- import { ConfiguratorEnvelope, UniversalConfigurator, integrateMetaBox, SetEnvironment, ShowOverlayInterface, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, Communicator, FromMetaboxApiAction } from '@3dsource/metabox-front-api';
90
-
91
- class TsIntegrator {
92
- constructor() {
93
- const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
94
- integrateMetaBox(url, 'embed3DSource', (api) => this.apiReady(api));
95
- }
96
-
97
- apiReady(api: Communicator) {
98
- api.addEventListener('basicConfiguratorDataWithState', (data) => {
99
- this.updateConfiguratorData(data);
100
- });
101
- api.addEventListener('fastRender', (data) => {
102
- saveImage(data, 'Render.png');
103
- });
104
- this.setupInitialState(api);
105
- }
106
-
107
- updateConfiguratorData(data: ConfiguratorEnvelope) {
108
- // Use data on your own
109
- }
110
-
111
- setupInitialState(api: Communicator) {
112
- api.sendCommandToMetaBox(new SetProduct('productId'));
113
- api.sendCommandToMetaBox(new SetEnvironment('environmentId'));
114
- api.sendCommandToMetaBox(new SetMaterial('productId', 'slotId', 'materialId'));
115
- api.sendCommandToMetaBox(new SetEnvironmentMaterial('productId', 'slotId', 'materialId'));
116
- api.sendCommandToMetaBox(new ShowEmbeddedMenu(false));
117
- api.sendCommandToMetaBox(new ShowOverlayInterface(false));
118
- api.sendCommandToMetaBox(new GetPdf());
119
- api.sendCommandToMetaBox(new GetFastRender('image/png', { x: 1024, y: 1024 }));
120
- }
121
- }
122
-
123
- new TsIntegrator();
124
- ```
125
-
126
- ### Documentation for current example
127
-
128
- #### `integrateMetaBox`
129
-
130
- - **Description**: Integrates the MetaBox configurator into the specified container.
131
- - **Usage**:
132
-
133
- ```typescript
134
- integrateMetaBox(configuratorUrl: string, containerId: string, apiReadyCallback: (api: Communicator) => void);
135
- ```
136
-
137
- #### `SetEnvironment`
138
-
139
- - **Description**: Sets the environment by ID.
140
- - **Usage**:
141
-
142
- ```typescript
143
- api.sendCommandToMetaBox(new SetEnvironment(environmentId: string));
144
- ```
145
-
146
- #### `SetMaterial`
147
-
148
- - **Description**: Sets the material for a given product slot.
149
- - **Usage**:
150
-
151
- ```typescript
152
- api.sendCommandToMetaBox(new SetMaterial(productId: string, slotId: string, materialId: string));
153
- ```
154
-
155
- #### `SetEnvironmentMaterial`
156
-
157
- - **Description**: Sets the material for a given environment slot.
158
- - **Usage**:
159
-
160
- ```typescript
161
- api.sendCommandToMetaBox(new SetEnvironmentMaterial(productId: string, slotId: string, materialId: string));
162
- ```
163
-
164
- #### `SetProduct`
165
-
166
- - **Description**: Sets the product by ID.
167
- - **Usage**:
168
-
169
- ```typescript
170
- api.sendCommandToMetaBox(new SetProduct(productId: string));
171
- ```
172
-
173
- #### `ShowEmbeddedMenu`
174
-
175
- - **Description**: Toggles the embedded menu in the MetaBox configurator.
176
- - **Usage**:
177
-
178
- ```typescript
179
- api.sendCommandToMetaBox(new ShowEmbeddedMenu(visible: boolean));
180
- ```
181
-
182
- #### `ShowOverlayInterface`
183
-
184
- - **Description**: Toggles the overlay interface over Unreal viewport.
185
- - **Usage**:
186
-
187
- ```typescript
188
- api.sendCommandToMetaBox(new ShowOverlayInterface(visible: boolean));
189
- ```
190
-
191
- #### `GetFastRender`
192
-
193
- - **Description**: Retrieves a fast render of the current view.
194
- - **Usage**:
195
-
196
- ```typescript
197
- api.sendCommandToMetaBox(new GetFastRender(mimeType: string, size?: { x: number, y: number }));
198
- ```
199
-
200
- #### `GetPdf`
201
-
202
- - **Description**: Generates a PDF of the current view.
203
- - **Usage**:
204
-
205
- ```typescript
206
- api.sendCommandToMetaBox(new GetPdf());
207
- ```
208
-
209
- #### `saveImage`
210
-
211
- - **Description**: Saves the arrived rendered image to a file using utility function.
212
- - **Usage**:
213
-
214
- ```typescript
215
- saveImage(renderData: string, fileName: string): void;
216
- ```
1
+ # MetaBox Basic Configurators API
2
+
3
+ This package provides an API for interacting with the MetaBox Basic Configurator using plain JavaScript.
4
+
5
+ ### Installation (for using with frameworks like Angular, React, etc.) This is the recommended method
6
+
7
+ ```sh
8
+ npm install @3dsource/metabox-front-api@^1.0.0 --save
9
+ ```
10
+
11
+ then
12
+
13
+ ```typescript
14
+ import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, SetEnvironmentMaterial, Communicator, ConfiguratorEnvelope } from '@3dsource/metabox-front-api';
15
+ ```
16
+
17
+ **OR** work with direct import from `NPM` using `CDN` network `unpkg.com` or `jsdelivr.net` (you can also download package and use it locally):
18
+
19
+ ```javascript
20
+ import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu, ShowOverlayInterface, SetEnvironmentMaterial, Communicator, ConfiguratorEnvelope } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@1.2.0';
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### 1. Create HTML Structure
26
+
27
+ Ensure your HTML page has the following structure, where the MetaBox Configurator will be integrated.
28
+ You **MUST** control CSS style of `embed3DSource` element to make the configurator responsive and fit your needs on your own.
29
+
30
+ ```html
31
+
32
+ <div id="embed3DSource">
33
+ <!-- Your Configurator iframe will be embedded here -->
34
+ </div>
35
+ ```
36
+
37
+ ### 2. Include Required Scripts
38
+
39
+ Below is an example demonstrating how to use the MetaBox API functions:
40
+
41
+ Insert this code into your HTML file just before the closing `</body>` tag:
42
+
43
+ **EXAMPLE:**
44
+
45
+ HTML:
46
+
47
+ ```html
48
+
49
+ <script type="module">
50
+ import { integrateMetaBox, SetEnvironment, ShowOverlayInterface, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, Communicator, FromMetaboxApiAction } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@1.2.0';
51
+
52
+ class JsIntegrator {
53
+ constructor() {
54
+ const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
55
+ integrateMetaBox(url, 'embed3DSource', (api) => this.apiReady(api));
56
+ }
57
+
58
+ apiReady(api) {
59
+ api.addEventListener('basicConfiguratorDataWithState', (data) => {
60
+ this.updateConfiguratorData(data);
61
+ });
62
+ api.addEventListener('fastRender', (data) => {
63
+ saveImage(data, 'Render.png');
64
+ });
65
+ this.setupInitialState(api);
66
+ }
67
+
68
+ updateConfiguratorData(data) {
69
+ // Use data on your own
70
+ }
71
+
72
+ setupInitialState(api) {
73
+ api.sendCommandToMetaBox(new SetProduct('productId'));
74
+ api.sendCommandToMetaBox(new SetEnvironment('environmentId'));
75
+ api.sendCommandToMetaBox(new SetMaterial('productId', 'slotId', 'materialId'));
76
+ api.sendCommandToMetaBox(new SetEnvironmentMaterial('productId', 'slotId', 'materialId'));
77
+ api.sendCommandToMetaBox(new ShowEmbeddedMenu(false));
78
+ api.sendCommandToMetaBox(new ShowOverlayInterface(false));
79
+ api.sendCommandToMetaBox(new GetPdf());
80
+ api.sendCommandToMetaBox(new GetFastRender('image/png', { x: 1024, y: 1024 }));
81
+ }
82
+ }
83
+
84
+ new JsIntegrator();
85
+ </script>
86
+ ```
87
+
88
+ TypeScript:
89
+
90
+ ```typescript
91
+ import { ConfiguratorEnvelope, UniversalConfigurator, integrateMetaBox, SetEnvironment, ShowOverlayInterface, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, Communicator, FromMetaboxApiAction } from '@3dsource/metabox-front-api';
92
+
93
+ class TsIntegrator {
94
+ constructor() {
95
+ const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
96
+ integrateMetaBox(url, 'embed3DSource', (api) => this.apiReady(api));
97
+ }
98
+
99
+ apiReady(api: Communicator) {
100
+ api.addEventListener('basicConfiguratorDataWithState', (data) => {
101
+ this.updateConfiguratorData(data);
102
+ });
103
+ api.addEventListener('fastRender', (data) => {
104
+ saveImage(data, 'Render.png');
105
+ });
106
+ this.setupInitialState(api);
107
+ }
108
+
109
+ updateConfiguratorData(data: ConfiguratorEnvelope) {
110
+ // Use data on your own
111
+ }
112
+
113
+ setupInitialState(api: Communicator) {
114
+ api.sendCommandToMetaBox(new SetProduct('productId'));
115
+ api.sendCommandToMetaBox(new SetEnvironment('environmentId'));
116
+ api.sendCommandToMetaBox(new SetMaterial('productId', 'slotId', 'materialId'));
117
+ api.sendCommandToMetaBox(new SetEnvironmentMaterial('productId', 'slotId', 'materialId'));
118
+ api.sendCommandToMetaBox(new ShowEmbeddedMenu(false));
119
+ api.sendCommandToMetaBox(new ShowOverlayInterface(false));
120
+ api.sendCommandToMetaBox(new GetPdf());
121
+ api.sendCommandToMetaBox(new GetFastRender('image/png', { x: 1024, y: 1024 }));
122
+ }
123
+ }
124
+
125
+ new TsIntegrator();
126
+ ```
127
+
128
+ ### Documentation for current example
129
+
130
+ #### `integrateMetaBox`
131
+
132
+ - **Description**: Integrates the MetaBox configurator into the specified container.
133
+ - **Usage**:
134
+
135
+ ```typescript
136
+ integrateMetaBox(configuratorUrl: string, containerId: string, apiReadyCallback: (api: Communicator) => void);
137
+ ```
138
+
139
+ #### `SetEnvironment`
140
+
141
+ - **Description**: Sets the environment by ID.
142
+ - **Usage**:
143
+
144
+ ```typescript
145
+ api.sendCommandToMetaBox(new SetEnvironment(environmentId: string));
146
+ ```
147
+
148
+ #### `SetMaterial`
149
+
150
+ - **Description**: Sets the material for a given product slot.
151
+ - **Usage**:
152
+
153
+ ```typescript
154
+ api.sendCommandToMetaBox(new SetMaterial(productId: string, slotId: string, materialId: string));
155
+ ```
156
+
157
+ #### `SetEnvironmentMaterial`
158
+
159
+ - **Description**: Sets the material for a given environment slot.
160
+ - **Usage**:
161
+
162
+ ```typescript
163
+ api.sendCommandToMetaBox(new SetEnvironmentMaterial(productId: string, slotId: string, materialId: string));
164
+ ```
165
+
166
+ #### `SetProduct`
167
+
168
+ - **Description**: Sets the product by ID.
169
+ - **Usage**:
170
+
171
+ ```typescript
172
+ api.sendCommandToMetaBox(new SetProduct(productId: string));
173
+ ```
174
+
175
+ #### `ShowEmbeddedMenu`
176
+
177
+ - **Description**: Toggles the embedded menu in the MetaBox configurator.
178
+ - **Usage**:
179
+
180
+ ```typescript
181
+ api.sendCommandToMetaBox(new ShowEmbeddedMenu(visible: boolean));
182
+ ```
183
+
184
+ #### `ShowOverlayInterface`
185
+
186
+ - **Description**: Toggles the overlay interface over Unreal viewport.
187
+ - **Usage**:
188
+
189
+ ```typescript
190
+ api.sendCommandToMetaBox(new ShowOverlayInterface(visible: boolean));
191
+ ```
192
+
193
+ #### `GetFastRender`
194
+
195
+ - **Description**: Retrieves a fast render of the current view.
196
+ - **Usage**:
197
+
198
+ ```typescript
199
+ api.sendCommandToMetaBox(new GetFastRender(mimeType: string, size?: { x: number, y: number }));
200
+ ```
201
+
202
+ #### `GetPdf`
203
+
204
+ - **Description**: Generates a PDF of the current view.
205
+ - **Usage**:
206
+
207
+ ```typescript
208
+ api.sendCommandToMetaBox(new GetPdf());
209
+ ```
210
+
211
+ #### `saveImage`
212
+
213
+ - **Description**: Saves the arrived rendered image to a file using utility function.
214
+ - **Usage**:
215
+
216
+ ```typescript
217
+ saveImage(renderData: string, fileName: string): void;
218
+ ```
@@ -350,21 +350,38 @@ class EventDispatcher {
350
350
  * @internal Use {@link Communicator.createInstance} or the {@link integrateMetaBox} helper to instantiate.
351
351
  */
352
352
  class Communicator extends EventDispatcher {
353
+ /**
354
+ * Singleton reference to the current communicator instance.
355
+ */
356
+ static { this.instance = null; }
353
357
  /**
354
358
  * Constructs a Communicator, replacing any existing instance, and begins listening for messages.
355
359
  * @internal
356
360
  */
357
361
  constructor() {
358
- var _a;
359
362
  super();
360
363
  /**
361
364
  * Bound handler for incoming postMessage events.
362
365
  */
363
366
  this.binder = this.handleMessageReceived.bind(this, 'metaboxData');
364
- (_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
367
+ Communicator.instance?.destroy();
365
368
  Communicator.instance = this;
366
369
  window.addEventListener('message', this.binder);
367
370
  }
371
+ /**
372
+ * Listens for MetaBox to signal readiness, then initializes communicator.
373
+ * @param apiReadyCallback - Called with the new Communicator once MetaBox is loaded.
374
+ */
375
+ static createInstance(apiReadyCallback) {
376
+ const startHandler = (event) => {
377
+ const message = event.data;
378
+ if (message?.payload?.action === 'appLoaded') {
379
+ apiReadyCallback(new Communicator());
380
+ window.removeEventListener('message', startHandler);
381
+ }
382
+ };
383
+ window.addEventListener('message', startHandler);
384
+ }
368
385
  /**
369
386
  * Cleans up resources and stops listening for messages.
370
387
  */
@@ -379,46 +396,17 @@ class Communicator extends EventDispatcher {
379
396
  sendCommandToMetaBox(command) {
380
397
  const { data } = command;
381
398
  const iframe = document.getElementById('embeddedContent');
382
- if (!(iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow)) {
399
+ if (!iframe?.contentWindow) {
383
400
  console.warn('MetaBox IFrame not found or not ready.');
384
401
  return;
385
402
  }
386
403
  const message = {
387
404
  host: 'metaBoxHost',
388
- payload: Object.assign({}, data),
405
+ payload: { ...data },
389
406
  };
390
407
  // Replace '*' with a specific origin in production for better security.
391
408
  iframe.contentWindow.postMessage(message, '*');
392
409
  }
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
410
  /**
423
411
  * Registers an event listener for messages dispatched by MetaBox.
424
412
  * @override
@@ -440,11 +428,20 @@ class Communicator extends EventDispatcher {
440
428
  removeEventListener(messageType, callback) {
441
429
  return super.removeEventListener(messageType, callback);
442
430
  }
431
+ /**
432
+ * Filters and dispatches incoming messages from MetaBox.
433
+ * @param messageType - Expected message type for filtering ('metaboxData').
434
+ * @param event - The postMessage event received on window.
435
+ */
436
+ handleMessageReceived(messageType, event) {
437
+ // Optionally validate event.origin for security.
438
+ if (messageType !== 'metaboxData' || event.data?.host !== 'metabox') {
439
+ return;
440
+ }
441
+ const { eventType, payload } = event.data.payload;
442
+ this.dispatchEvent(eventType, payload);
443
+ }
443
444
  }
444
- /**
445
- * Singleton reference to the current communicator instance.
446
- */
447
- Communicator.instance = null;
448
445
 
449
446
  /**
450
447
  * Integrates the MetaBox into the provided layout.
@@ -482,13 +479,13 @@ function integrateMetaBox(iframeSrc, containerId = 'embed3DSource', apiReadyCall
482
479
  }
483
480
  Communicator.createInstance(apiReadyCallback);
484
481
  const style = document.createElement('style');
485
- style.innerHTML = `
486
- #${containerId} {
487
- width: 100%;
488
- height: 100%;
489
- overflow: hidden;
490
- position: relative;
491
- }
482
+ style.innerHTML = `
483
+ #${containerId} {
484
+ width: 100%;
485
+ height: 100%;
486
+ overflow: hidden;
487
+ position: relative;
488
+ }
492
489
  `;
493
490
  document.head.appendChild(style);
494
491
  const iframe = document.createElement('iframe');
@@ -503,7 +500,7 @@ function integrateMetaBox(iframeSrc, containerId = 'embed3DSource', apiReadyCall
503
500
  }
504
501
 
505
502
  /**
506
- * Wrapper helper function to use it with rxJs same as `fromEvent` to listen to events from the Communicator.
503
+ * Wrapper helper function to use it with rxJs the same as `fromEvent` to listen to events from the Communicator.
507
504
  * @param target
508
505
  * @param eventName
509
506
  */
@@ -576,5 +573,9 @@ function getUrlParams() {
576
573
  return selections;
577
574
  }
578
575
 
576
+ /**
577
+ * Generated bundle index. Do not edit.
578
+ */
579
+
579
580
  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
581
+ //# sourceMappingURL=3dsource-metabox-front-api.mjs.map