@3dsource/metabox-front-api 0.0.1 → 0.0.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.
- package/README.md +169 -21
- package/package.json +15 -7
- package/actions/ApiAction.js +0 -8
- package/actions/GetFastRender.js +0 -34
- package/actions/GetPdf.js +0 -24
- package/actions/SetEnvironment.js +0 -27
- package/actions/SetMaterial.js +0 -33
- package/actions/SetProduct.js +0 -27
- package/actions/ShowEmbeddedMenu.js +0 -27
- package/index.js +0 -17
- package/lib/MetaBoxApiAction.js +0 -60
- package/lib/UrlUtils.js +0 -25
- package/lib/initializeCommunicator.js +0 -117
- package/lib/integrateMetaBox.js +0 -41
- package/lib/saveImage.js +0 -13
- package/lib/sleep.js +0 -8
package/README.md
CHANGED
|
@@ -1,48 +1,196 @@
|
|
|
1
|
-
````markdown
|
|
2
1
|
# MetaBox API
|
|
3
2
|
|
|
4
|
-
This package provides an API for interacting with the MetaBox configurator.
|
|
3
|
+
This package provides an API for interacting with the MetaBox configurator using plain JavaScript.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
### Installation (for using with frameworks like Angular, React, etc.)
|
|
7
6
|
|
|
8
7
|
```sh
|
|
9
|
-
npm install @3dsource/metabox-front-api
|
|
8
|
+
npm install @3dsource/metabox-front-api --save
|
|
10
9
|
```
|
|
11
|
-
````
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
then
|
|
14
12
|
|
|
15
13
|
```typescript
|
|
16
|
-
import { SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu } from 'metabox-api';
|
|
14
|
+
import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from '@3dsource/metabox-front-api';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**OR** work with direct import from `NPM` using `CDN` network unpkg.com (you can also download package and use it locally):
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
17
24
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
### 1. Include Required Scripts
|
|
26
|
+
|
|
27
|
+
Below is an example demonstrating how to use the MetaBox API functions:
|
|
28
|
+
|
|
29
|
+
Insert this code into your HTML file just before the closing `</body>` tag:
|
|
30
|
+
|
|
31
|
+
**EXAMPLE:**
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<script type="module">
|
|
35
|
+
import { integrateMetaBox, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage } from '@3dsource/metabox-front-api';
|
|
36
|
+
|
|
37
|
+
// Expose API
|
|
38
|
+
window.env3DSource.apiReady = (api) => {
|
|
39
|
+
this.api = api;
|
|
40
|
+
this.api.addEventListener('metaboxData', (data) => {
|
|
41
|
+
const { action, payload, eventType } = data;
|
|
42
|
+
if (action !== FromMetaBoxApiAction.bridge) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (eventType === 'viewportReady' && payload === true) {
|
|
47
|
+
//You can use this event to trigger any action that can work only when the viewport is ready,
|
|
48
|
+
//i.e. GetPdf or GetFastRender
|
|
49
|
+
|
|
50
|
+
// Get a fast render (optionally specify size)
|
|
51
|
+
new GetFastRender('image/png', { x: 1024, y: 1024 });
|
|
52
|
+
|
|
53
|
+
// Generate a PDF of the current view
|
|
54
|
+
new GetPdf();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (eventType === 'basicConfiguratorDataWithState') {
|
|
58
|
+
this.updateConfiguratorData(data);
|
|
59
|
+
this.setupInitialState();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (eventType === 'getFastRender') {
|
|
63
|
+
//Catches the render image
|
|
64
|
+
saveImage(payload, 'Render.png');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @see examples, @see documentation
|
|
71
|
+
* @param data
|
|
72
|
+
*/
|
|
73
|
+
function updateConfiguratorData(data) {
|
|
74
|
+
//Use data on your own
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Setup initial state
|
|
79
|
+
*/
|
|
80
|
+
function setupInitialState() {
|
|
81
|
+
// Set product
|
|
82
|
+
new SetProduct('product-id');
|
|
83
|
+
|
|
84
|
+
// Set environment
|
|
85
|
+
new SetEnvironment('env-id');
|
|
86
|
+
|
|
87
|
+
// Set material
|
|
88
|
+
new SetMaterial('product-id', 'slot-id', 'material-id');
|
|
89
|
+
|
|
90
|
+
// Toggle embedded menu
|
|
91
|
+
new ShowEmbeddedMenu(false);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Integrate the 3D configurator into your page
|
|
95
|
+
|
|
96
|
+
const url = 'https://metabox.3dsource.com/metabox-configurator/basic/your-configurator-id?sidebar=false';
|
|
97
|
+
// Additional url parameters:
|
|
98
|
+
// sidebar=false - disables the internal MetaBox menu
|
|
99
|
+
// introImage=https://example.com/image.png - sets the intro image
|
|
100
|
+
// 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
|
|
101
|
+
integrateMetaBox(url, 'embed3DSource');
|
|
102
|
+
</script>
|
|
23
103
|
```
|
|
24
104
|
|
|
25
|
-
|
|
105
|
+
### 2. HTML Structure
|
|
106
|
+
|
|
107
|
+
Ensure your HTML page has the following structure, where the MetaBox Configurator will be integrated:
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<div class="container">
|
|
111
|
+
<div id="embed3DSource">
|
|
112
|
+
<!-- Your Configurator iframe will be embedded here -->
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Documentation for current example
|
|
118
|
+
|
|
119
|
+
### `integrateMetaBox`
|
|
120
|
+
|
|
121
|
+
- **Description**: Integrates the MetaBox configurator into the specified container.
|
|
122
|
+
- **Usage**:
|
|
123
|
+
```typescript
|
|
124
|
+
integrateMetaBox(configuratorUrl: string, containerId: string): void;
|
|
125
|
+
```
|
|
26
126
|
|
|
27
127
|
### `SetEnvironment`
|
|
28
128
|
|
|
29
|
-
- **Description**:
|
|
30
|
-
- **Constructor**:
|
|
129
|
+
- **Description**: Sets the environment by ID.
|
|
130
|
+
- **Constructor**:
|
|
131
|
+
```typescript
|
|
132
|
+
new SetEnvironment(environmentId: string);
|
|
133
|
+
```
|
|
31
134
|
|
|
32
135
|
### `SetMaterial`
|
|
33
136
|
|
|
34
|
-
- **Description**:
|
|
35
|
-
- **Constructor**:
|
|
137
|
+
- **Description**: Sets the material for a given product slot.
|
|
138
|
+
- **Constructor**:
|
|
139
|
+
```typescript
|
|
140
|
+
new SetMaterial(productId: string, slotId: string, materialId: string);
|
|
141
|
+
```
|
|
36
142
|
|
|
37
143
|
### `SetProduct`
|
|
38
144
|
|
|
39
|
-
- **Description**:
|
|
40
|
-
- **Constructor**:
|
|
145
|
+
- **Description**: Sets the product by ID.
|
|
146
|
+
- **Constructor**:
|
|
147
|
+
```typescript
|
|
148
|
+
new SetProduct(productId: string);
|
|
149
|
+
```
|
|
41
150
|
|
|
42
151
|
### `ShowEmbeddedMenu`
|
|
43
152
|
|
|
44
|
-
- **Description**: Toggles
|
|
45
|
-
- **Constructor**:
|
|
153
|
+
- **Description**: Toggles the embedded menu in the MetaBox configurator.
|
|
154
|
+
- **Constructor**:
|
|
155
|
+
```typescript
|
|
156
|
+
new ShowEmbeddedMenu(visible: boolean);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### `GetFastRender`
|
|
160
|
+
|
|
161
|
+
**Important:** Before invoking this action, ensure that the MetaBox viewport is fully loaded. This is indicated by the event:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
data.eventType === 'viewportReady' && data.payload === true.
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
- **Description**: Retrieves a fast render of the current view.
|
|
168
|
+
- **Usage**:
|
|
169
|
+
```typescript
|
|
170
|
+
new GetFastRender(mimeType: string, size?: { x: number, y: number });
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### `GetPdf`
|
|
174
|
+
|
|
175
|
+
**Important:** Before invoking this action, ensure that the MetaBox viewport is fully loaded. This is indicated by the event:
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
data.eventType === 'viewportReady' && data.payload === true.
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- **Description**: Generates a PDF of the current view.
|
|
182
|
+
- **Usage**:
|
|
183
|
+
```typescript
|
|
184
|
+
new GetPdf();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### `saveImage`
|
|
188
|
+
|
|
189
|
+
- **Description**: Saves the arrived rendered image to a file using utility function.
|
|
190
|
+
- **Usage**:
|
|
191
|
+
```typescript
|
|
192
|
+
saveImage(renderData: string, fileName: string): void;
|
|
193
|
+
```
|
|
46
194
|
|
|
47
195
|
```
|
|
48
196
|
|
package/package.json
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3dsource/metabox-front-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "API for MetaBox configurator",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"unpkg": "index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"unpkg": "dist/index.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"clean": "rimraf dist",
|
|
11
|
+
"publishApi": "npm pack && npm publish --access public",
|
|
12
|
+
"apiDoc": "typedoc --entryPointStrategy Expand src/index.ts --tsconfig ./../../tsconfig.typedoc.json --out ./../../dist/browser/apiDoc"
|
|
9
13
|
},
|
|
10
14
|
"files": [
|
|
11
|
-
"
|
|
12
|
-
"lib",
|
|
13
|
-
"index.js"
|
|
15
|
+
"dist"
|
|
14
16
|
],
|
|
15
17
|
"repository": {
|
|
16
18
|
"type": "git",
|
|
17
19
|
"url": "git@bitbucket.org:dreamsoft/ams_vps-frontend.git"
|
|
18
20
|
},
|
|
19
|
-
"keywords": [
|
|
21
|
+
"keywords": [
|
|
22
|
+
"metabox",
|
|
23
|
+
"api",
|
|
24
|
+
"configurator"
|
|
25
|
+
],
|
|
20
26
|
"author": "3dsource.com",
|
|
21
27
|
"license": "MIT",
|
|
22
28
|
"devDependencies": {
|
|
29
|
+
"typescript": "~5.7.3",
|
|
30
|
+
"rimraf": "^3.0.2"
|
|
23
31
|
}
|
|
24
32
|
}
|
package/actions/ApiAction.js
DELETED
package/actions/GetFastRender.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction.js';
|
|
7
|
-
import { ApiAction } from './ApiAction';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {"image/png" | "image/jpeg"} ImageFormat
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Get fast render.
|
|
15
|
-
* @param {ImageFormat} format - The output format.
|
|
16
|
-
* @param {{x: number, y: number}} [size] - Size in pixels.
|
|
17
|
-
*/
|
|
18
|
-
export class GetFastRender extends ApiAction {
|
|
19
|
-
/**
|
|
20
|
-
* Get fast render.
|
|
21
|
-
* @param {ImageFormat} format - The output format.
|
|
22
|
-
* @param {{x: number, y: number}} [size] - Size in pixels.
|
|
23
|
-
*/
|
|
24
|
-
constructor(format, size) {
|
|
25
|
-
super();
|
|
26
|
-
this.api.sendMessageToMetaBox({
|
|
27
|
-
payload: {
|
|
28
|
-
format,
|
|
29
|
-
size,
|
|
30
|
-
},
|
|
31
|
-
action: ToMetaBoxApiAction.GetFastRender,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
package/actions/GetPdf.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction.js';
|
|
7
|
-
import { ApiAction } from './ApiAction';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Get Pdf from Metabox.
|
|
11
|
-
* No parameters required at this moment.
|
|
12
|
-
*/
|
|
13
|
-
export class GetPdf extends ApiAction {
|
|
14
|
-
/**
|
|
15
|
-
* Get Pdf from Metabox.
|
|
16
|
-
* No parameters required at this moment.
|
|
17
|
-
*/
|
|
18
|
-
constructor() {
|
|
19
|
-
super();
|
|
20
|
-
this.api.sendMessageToMetaBox({
|
|
21
|
-
action: ToMetaBoxApiAction.GetPdf,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction.js';
|
|
7
|
-
import { ApiAction } from './ApiAction';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Set environment by ID.
|
|
11
|
-
* @param {string} environmentId - The environment ID.
|
|
12
|
-
*/
|
|
13
|
-
export class SetEnvironment extends ApiAction {
|
|
14
|
-
/**
|
|
15
|
-
* Set environment by ID.
|
|
16
|
-
* @param {string} environmentId - The environment ID.
|
|
17
|
-
*/
|
|
18
|
-
constructor(environmentId) {
|
|
19
|
-
super();
|
|
20
|
-
this.api.sendMessageToMetaBox({
|
|
21
|
-
payload: {
|
|
22
|
-
id: environmentId,
|
|
23
|
-
},
|
|
24
|
-
action: ToMetaBoxApiAction.LoadLevel,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
package/actions/SetMaterial.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction.js';
|
|
7
|
-
import { ApiAction } from './ApiAction';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Set material by ID.
|
|
11
|
-
* @param {string} productId - The product ID.
|
|
12
|
-
* @param {string} slotId - The slot ID.
|
|
13
|
-
* @param {string} materialId - The material ID.
|
|
14
|
-
*/
|
|
15
|
-
export class SetMaterial extends ApiAction {
|
|
16
|
-
/**
|
|
17
|
-
* Set material by ID.
|
|
18
|
-
* @param {string} productId - The product ID.
|
|
19
|
-
* @param {string} slotId - The slot ID.
|
|
20
|
-
* @param {string} materialId - The material ID.
|
|
21
|
-
*/
|
|
22
|
-
constructor(productId, slotId, materialId) {
|
|
23
|
-
super();
|
|
24
|
-
this.api.sendMessageToMetaBox({
|
|
25
|
-
payload: {
|
|
26
|
-
productId,
|
|
27
|
-
slotId,
|
|
28
|
-
materialId,
|
|
29
|
-
},
|
|
30
|
-
action: ToMetaBoxApiAction.SetMaterialById,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
package/actions/SetProduct.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction.js';
|
|
7
|
-
import { ApiAction } from './ApiAction';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Set product by ID.
|
|
11
|
-
* @param {string} productId - The product ID.
|
|
12
|
-
*/
|
|
13
|
-
export class SetProduct extends ApiAction {
|
|
14
|
-
/**
|
|
15
|
-
* Set product by ID.
|
|
16
|
-
* @param {string} productId - The product ID.
|
|
17
|
-
*/
|
|
18
|
-
constructor(productId) {
|
|
19
|
-
super();
|
|
20
|
-
this.api.sendMessageToMetaBox({
|
|
21
|
-
payload: {
|
|
22
|
-
productId,
|
|
23
|
-
},
|
|
24
|
-
action: ToMetaBoxApiAction.SetProduct,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction.js';
|
|
7
|
-
import { ApiAction } from './ApiAction';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Toggles EmbeddedMenu in MetaBox.
|
|
11
|
-
* @param {boolean} visible - A flag indicating whether the embedded menu should be visible.
|
|
12
|
-
*/
|
|
13
|
-
export class ShowEmbeddedMenu extends ApiAction {
|
|
14
|
-
/**
|
|
15
|
-
* Toggles EmbeddedMenu in MetaBox.
|
|
16
|
-
* @param {boolean} visible - A flag indicating whether the embedded menu should be visible.
|
|
17
|
-
*/
|
|
18
|
-
constructor(visible) {
|
|
19
|
-
super();
|
|
20
|
-
this.api.sendMessageToMetaBox({
|
|
21
|
-
action: ToMetaBoxApiAction.ShowEmbeddedMenu,
|
|
22
|
-
payload: {
|
|
23
|
-
visible,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
package/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export { ShowEmbeddedMenu } from './actions/ShowEmbeddedMenu.js';
|
|
7
|
-
export { SetEnvironment } from './actions/SetEnvironment.js';
|
|
8
|
-
export { SetProduct } from './actions/SetProduct.js';
|
|
9
|
-
export { GetPdf } from './actions/GetPdf.js';
|
|
10
|
-
export { SetMaterial } from './actions/SetMaterial.js';
|
|
11
|
-
export { GetFastRender } from './actions/GetFastRender.js';
|
|
12
|
-
|
|
13
|
-
export * from './lib/MetaBoxApiAction.js';
|
|
14
|
-
export * from './lib/integrateMetaBox.js';
|
|
15
|
-
export * from './lib/saveImage.js';
|
|
16
|
-
export * from './lib/sleep.js';
|
|
17
|
-
export * from './lib/UrlUtils.js';
|
package/lib/MetaBoxApiAction.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export const FromMetaBoxApiAction = {
|
|
7
|
-
Bridge: 'bridge',
|
|
8
|
-
UnrealCallback: 'unrealCallback',
|
|
9
|
-
UnrealFeatureBridge: 'unrealFeatureBridge',
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
13
|
-
*/
|
|
14
|
-
ConfiguratorDataWithStateBridge: 'configuratorDataWithStateBridge',
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
18
|
-
*/
|
|
19
|
-
ConfiguratorDataBridge: 'configuratorDataBridge',
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
23
|
-
*/
|
|
24
|
-
MenuDataBridge: 'menuDataBridge',
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
|
|
28
|
-
*/
|
|
29
|
-
FlatMenuDataBridge: 'flatMenuDataBridge',
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated, use Bridge with isFullscreen
|
|
33
|
-
*/
|
|
34
|
-
FullScreenBridge: 'fullScreenBridge',
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated, use Bridge with streamResolution
|
|
38
|
-
*/
|
|
39
|
-
VideoSize: 'videoSize',
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Used in platform
|
|
43
|
-
*/
|
|
44
|
-
UnrealResponse: 'unrealResponse',
|
|
45
|
-
GetFastRender: 'getFastRender',
|
|
46
|
-
AppLoaded: 'appLoaded',
|
|
47
|
-
};
|
|
48
|
-
export const ToMetaBoxApiAction = {
|
|
49
|
-
GetPdf: 'getPdf',
|
|
50
|
-
LoadLevel: 'loadLevel',
|
|
51
|
-
SetProduct: 'setProduct',
|
|
52
|
-
AddResponse: 'addResponse',
|
|
53
|
-
SetMaterial: 'setMaterial',
|
|
54
|
-
GetFastRender: 'getFastRender',
|
|
55
|
-
WatchCallbacks: 'watchCallbacks',
|
|
56
|
-
SetExternalMode: 'setExternalMode',
|
|
57
|
-
SetMaterialById: 'setMaterialById',
|
|
58
|
-
ShowEmbeddedMenu: 'showEmbeddedMenu',
|
|
59
|
-
ForceSetDeviceType: 'forceSetDeviceType',
|
|
60
|
-
};
|
package/lib/UrlUtils.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Set the URL parameters based on the provided state.
|
|
3
|
-
* @param state Object containing the state to set as URL parameters.
|
|
4
|
-
*/
|
|
5
|
-
export function setUrlParams(state) {
|
|
6
|
-
const url = new URL(window.location);
|
|
7
|
-
url.search = '';
|
|
8
|
-
Object.entries(state).forEach(([key, value]) => {
|
|
9
|
-
url.searchParams.set(key, value);
|
|
10
|
-
});
|
|
11
|
-
history.replaceState(null, '', url);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Get the URL parameters as an object.
|
|
16
|
-
* @returns Object containing the URL parameters.
|
|
17
|
-
*/
|
|
18
|
-
export function getUrlParams() {
|
|
19
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
20
|
-
const selections = {};
|
|
21
|
-
urlParams.forEach((value, key) => {
|
|
22
|
-
selections[key] = value;
|
|
23
|
-
});
|
|
24
|
-
return selections;
|
|
25
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* API class to handle communication with the embedded content.
|
|
8
|
-
*/
|
|
9
|
-
const messageType = 'metaboxData';
|
|
10
|
-
|
|
11
|
-
class Communicator {
|
|
12
|
-
// Initialize a storage for callbacks by message types
|
|
13
|
-
listeners = [];
|
|
14
|
-
instance = null;
|
|
15
|
-
binder = this.handleMessageReceived.bind(this, messageType);
|
|
16
|
-
|
|
17
|
-
constructor() {
|
|
18
|
-
Communicator.instance?.destroy();
|
|
19
|
-
Communicator.instance = this;
|
|
20
|
-
// Listen for messages from the iframe
|
|
21
|
-
window.addEventListener('message', this.binder);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
destroy() {
|
|
25
|
-
this.listeners = [];
|
|
26
|
-
window.removeEventListener('message', this.binder);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Sends a message to the embedded content (MetaBox).
|
|
31
|
-
*
|
|
32
|
-
* @param {ToMetaBoxMessagePayload} data The data to send.
|
|
33
|
-
*/
|
|
34
|
-
sendMessageToMetaBox(data) {
|
|
35
|
-
const iframe = document.getElementById('embeddedContent');
|
|
36
|
-
const dataToSend = {
|
|
37
|
-
host: 'metaBoxHost',
|
|
38
|
-
payload: { ...data },
|
|
39
|
-
};
|
|
40
|
-
iframe.contentWindow.postMessage(dataToSend, '*'); // In production, replace "*" with the actual origin
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Adds an event listener for receiving specific types of messages.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} messageType The message type to listen for.
|
|
47
|
-
* @param {Function} callback The callback function to execute when a message is received.
|
|
48
|
-
*/
|
|
49
|
-
addEventListener(messageType, callback) {
|
|
50
|
-
this.listeners.push({ messageType, callback });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Dispatches an event to all listeners.
|
|
55
|
-
* @param messageType
|
|
56
|
-
* @param data
|
|
57
|
-
*/
|
|
58
|
-
dispatchEvent(messageType, data) {
|
|
59
|
-
this.listeners
|
|
60
|
-
.filter((listener) => listener.messageType === messageType)
|
|
61
|
-
.forEach((listener) => listener.callback(data));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Handles incoming messages by invoking the appropriate callback.
|
|
66
|
-
*
|
|
67
|
-
* @param messageType
|
|
68
|
-
* @param {MessageEvent} event The incoming message event.
|
|
69
|
-
*/
|
|
70
|
-
handleMessageReceived(messageType, event) {
|
|
71
|
-
// Optional: Perform origin check here for added security
|
|
72
|
-
// if (event.origin !== "EXPECTED_ORIGIN") return;
|
|
73
|
-
if (event?.data?.host !== 'metabox') {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
// Trigger the listener if the messageType is recognized
|
|
77
|
-
this.listeners
|
|
78
|
-
.filter((listener) => listener.messageType === messageType)
|
|
79
|
-
.forEach((listener) => {
|
|
80
|
-
listener.callback(event.data.payload);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Removes an event listener for a specific type of message.
|
|
86
|
-
*
|
|
87
|
-
* @param {string} messageType The message type.
|
|
88
|
-
* @param callback
|
|
89
|
-
*/
|
|
90
|
-
removeEventListener(messageType, callback) {
|
|
91
|
-
this.listeners = this.listeners.filter(
|
|
92
|
-
(listener) =>
|
|
93
|
-
!(
|
|
94
|
-
listener.messageType === messageType && listener.callback === callback
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Initializes the API when the embedded content is ready.
|
|
102
|
-
*/
|
|
103
|
-
export function initializeCommunicator() {
|
|
104
|
-
window.env3DSource = window.env3DSource || {};
|
|
105
|
-
const startHandler = (event) => {
|
|
106
|
-
if (
|
|
107
|
-
event?.data?.payload?.action === 'appLoaded' &&
|
|
108
|
-
'apiReady' in window.env3DSource
|
|
109
|
-
) {
|
|
110
|
-
window.env3DSource.api = new Communicator();
|
|
111
|
-
window.env3DSource.apiReady(window.env3DSource.api);
|
|
112
|
-
window.removeEventListener('message', startHandler);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
window.addEventListener('message', startHandler);
|
|
117
|
-
}
|
package/lib/integrateMetaBox.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025.
|
|
3
|
-
* Sergii Karanda - All Rights Reserved
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { initializeCommunicator } from './initializeCommunicator.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Integrates the MetaBox into the provided layout.
|
|
10
|
-
* @param iframeSrc The source URL of the MetaBox iframe
|
|
11
|
-
* @param containerId='embed3DSource' The ID of the layout element
|
|
12
|
-
*/
|
|
13
|
-
export function integrateMetaBox(iframeSrc, containerId = 'embed3DSource') {
|
|
14
|
-
const container = document.getElementById(containerId);
|
|
15
|
-
if (!container) {
|
|
16
|
-
throw new Error(`Container element with id ${containerId} not found`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
initializeCommunicator();
|
|
20
|
-
|
|
21
|
-
const style = document.createElement('style');
|
|
22
|
-
style.innerHTML = `
|
|
23
|
-
#${containerId} {
|
|
24
|
-
width: 100%;
|
|
25
|
-
height: 100%;
|
|
26
|
-
overflow: hidden;
|
|
27
|
-
position: relative;
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
document.head.appendChild(style);
|
|
32
|
-
const iframe = document.createElement('iframe');
|
|
33
|
-
iframe.setAttribute('referrerPolicy', 'no-referrer-when-downgrade');
|
|
34
|
-
iframe.setAttribute('id', 'embeddedContent');
|
|
35
|
-
iframe.style.border = '0';
|
|
36
|
-
iframe.style.width = '100%';
|
|
37
|
-
iframe.style.height = '100%';
|
|
38
|
-
iframe.style.overflow = 'hidden';
|
|
39
|
-
iframe.src = iframeSrc;
|
|
40
|
-
container.appendChild(iframe);
|
|
41
|
-
}
|
package/lib/saveImage.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param image Url of the image to save
|
|
4
|
-
* @param filename Name of the file to save
|
|
5
|
-
*/
|
|
6
|
-
export function saveImage(image, filename) {
|
|
7
|
-
const a = document.createElement('a');
|
|
8
|
-
a.href = image;
|
|
9
|
-
a.download = filename;
|
|
10
|
-
document.body.appendChild(a);
|
|
11
|
-
a.click();
|
|
12
|
-
document.body.removeChild(a);
|
|
13
|
-
}
|