@3dsource/metabox-front-api 0.0.2 → 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 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
- ## Installation
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
- ## Usage
11
+ then
14
12
 
15
13
  ```typescript
16
- import { SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu } from '@3dsource/metabox-front-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
- // Example usage
19
- const loadEnv = new SetEnvironment('env-id');
20
- const setMaterial = new SetMaterial('product-id', 'slot-id', 'material-id');
21
- const setProduct = new SetProduct('product-id');
22
- const showMenu = new ShowEmbeddedMenu(true);
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
- ## API
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**: Set environment by ID.
30
- - **Constructor**: `constructor(environmentId: string)`
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**: Set material by ID.
35
- - **Constructor**: `constructor(productId: string, slotId: string, materialId: string)`
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**: Set product by ID.
40
- - **Constructor**: `constructor(productId: string)`
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 EmbeddedMenu in MetaBox.
45
- - **Constructor**: `constructor(visible: boolean)`
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@3dsource/metabox-front-api",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "API for MetaBox configurator",
5
5
  "main": "dist/index.js",
6
6
  "unpkg": "dist/index.js",
@@ -8,7 +8,8 @@
8
8
  "scripts": {
9
9
  "build": "tsc",
10
10
  "clean": "rimraf dist",
11
- "publishApi": "npm pack && npm publish --access public"
11
+ "publishApi": "npm pack && npm publish --access public",
12
+ "apiDoc": "typedoc --entryPointStrategy Expand src/index.ts --tsconfig ./../../tsconfig.typedoc.json --out ./../../dist/browser/apiDoc"
12
13
  },
13
14
  "files": [
14
15
  "dist"
@@ -1,3 +0,0 @@
1
- export declare class ApiAction {
2
- api: any;
3
- }
@@ -1,10 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- export class ApiAction {
7
- constructor() {
8
- this.api = window.env3DSource.api;
9
- }
10
- }
@@ -1,24 +0,0 @@
1
- import { ApiAction } from './ApiAction';
2
- /**
3
- * Image format.
4
- * @remarks
5
- * This type represents the allowed image formats.
6
- */
7
- export type ImageFormat = 'image/png' | 'image/jpeg';
8
- /**
9
- * Represents a fast render action.
10
- * @remarks
11
- * This class sends a message to the MetaBox API to obtain a fast render
12
- * based on the provided format and optional size.
13
- */
14
- export declare class GetFastRender extends ApiAction {
15
- /**
16
- * Constructs an instance of GetFastRender.
17
- * @param format - The output format.
18
- * @param size - Optional size in pixels.
19
- */
20
- constructor(format: ImageFormat, size?: {
21
- x: number;
22
- y: number;
23
- });
24
- }
@@ -1,30 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction';
7
- import { ApiAction } from './ApiAction';
8
- /**
9
- * Represents a fast render action.
10
- * @remarks
11
- * This class sends a message to the MetaBox API to obtain a fast render
12
- * based on the provided format and optional size.
13
- */
14
- export class GetFastRender extends ApiAction {
15
- /**
16
- * Constructs an instance of GetFastRender.
17
- * @param format - The output format.
18
- * @param size - Optional size in pixels.
19
- */
20
- constructor(format, size) {
21
- super();
22
- this.api.sendMessageToMetaBox({
23
- payload: {
24
- format,
25
- size,
26
- },
27
- action: ToMetaBoxApiAction.getFastRender,
28
- });
29
- }
30
- }
@@ -1,16 +0,0 @@
1
- import { ApiAction } from './ApiAction';
2
- /**
3
- * Represents an action to get a PDF from Metabox.
4
- *
5
- * @remarks
6
- * This action does not require any parameters.
7
- */
8
- export declare class GetPdf extends ApiAction {
9
- /**
10
- * Creates an instance of GetPdf.
11
- *
12
- * @remarks
13
- * This constructor does not require any parameters.
14
- */
15
- constructor();
16
- }
@@ -1,27 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction';
7
- import { ApiAction } from './ApiAction';
8
- /**
9
- * Represents an action to get a PDF from Metabox.
10
- *
11
- * @remarks
12
- * This action does not require any parameters.
13
- */
14
- export class GetPdf extends ApiAction {
15
- /**
16
- * Creates an instance of GetPdf.
17
- *
18
- * @remarks
19
- * This constructor does not require any parameters.
20
- */
21
- constructor() {
22
- super();
23
- this.api.sendMessageToMetaBox({
24
- action: ToMetaBoxApiAction.getPdf,
25
- });
26
- }
27
- }
@@ -1,15 +0,0 @@
1
- import { ApiAction } from './ApiAction';
2
- /**
3
- * Represents an action to set the environment by its ID.
4
- *
5
- * @remarks
6
- * This action sends a message to the MetaBox API to load the environment level using the specified environment ID.
7
- */
8
- export declare class SetEnvironment extends ApiAction {
9
- /**
10
- * Creates an instance of SetEnvironment.
11
- *
12
- * @param environmentId - The environment ID.
13
- */
14
- constructor(environmentId: string);
15
- }
@@ -1,29 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction';
7
- import { ApiAction } from './ApiAction';
8
- /**
9
- * Represents an action to set the environment by its ID.
10
- *
11
- * @remarks
12
- * This action sends a message to the MetaBox API to load the environment level using the specified environment ID.
13
- */
14
- export class SetEnvironment extends ApiAction {
15
- /**
16
- * Creates an instance of SetEnvironment.
17
- *
18
- * @param environmentId - The environment ID.
19
- */
20
- constructor(environmentId) {
21
- super();
22
- this.api.sendMessageToMetaBox({
23
- payload: {
24
- id: environmentId,
25
- },
26
- action: ToMetaBoxApiAction.loadLevel,
27
- });
28
- }
29
- }
@@ -1,17 +0,0 @@
1
- import { ApiAction } from './ApiAction';
2
- /**
3
- * Represents an action to set a material by its ID.
4
- *
5
- * @remarks
6
- * This action sends a message to the MetaBox API to update the material on a specific product slot using the provided identifiers.
7
- */
8
- export declare class SetMaterial extends ApiAction {
9
- /**
10
- * Creates an instance of SetMaterial.
11
- *
12
- * @param productId - The product ID.
13
- * @param slotId - The slot ID.
14
- * @param materialId - The material ID.
15
- */
16
- constructor(productId: string, slotId: string, materialId: string);
17
- }
@@ -1,33 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction';
7
- import { ApiAction } from './ApiAction';
8
- /**
9
- * Represents an action to set a material by its ID.
10
- *
11
- * @remarks
12
- * This action sends a message to the MetaBox API to update the material on a specific product slot using the provided identifiers.
13
- */
14
- export class SetMaterial extends ApiAction {
15
- /**
16
- * Creates an instance of SetMaterial.
17
- *
18
- * @param productId - The product ID.
19
- * @param slotId - The slot ID.
20
- * @param 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
- }
@@ -1,15 +0,0 @@
1
- import { ApiAction } from './ApiAction';
2
- /**
3
- * Represents an action to set a product by its ID.
4
- *
5
- * @remarks
6
- * This action sends a message to the MetaBox API to set a product using the provided product ID.
7
- */
8
- export declare class SetProduct extends ApiAction {
9
- /**
10
- * Creates an instance of SetProduct.
11
- *
12
- * @param productId - The product ID.
13
- */
14
- constructor(productId: string);
15
- }
@@ -1,29 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction';
7
- import { ApiAction } from './ApiAction';
8
- /**
9
- * Represents an action to set a product by its ID.
10
- *
11
- * @remarks
12
- * This action sends a message to the MetaBox API to set a product using the provided product ID.
13
- */
14
- export class SetProduct extends ApiAction {
15
- /**
16
- * Creates an instance of SetProduct.
17
- *
18
- * @param productId - The product ID.
19
- */
20
- constructor(productId) {
21
- super();
22
- this.api.sendMessageToMetaBox({
23
- payload: {
24
- productId,
25
- },
26
- action: ToMetaBoxApiAction.setProduct,
27
- });
28
- }
29
- }
@@ -1,15 +0,0 @@
1
- import { ApiAction } from './ApiAction';
2
- /**
3
- * Represents an action to toggle the Embedded Menu in MetaBox.
4
- *
5
- * @remarks
6
- * This action sends a message to the MetaBox API to toggle the visibility of the embedded menu.
7
- */
8
- export declare class ShowEmbeddedMenu extends ApiAction {
9
- /**
10
- * Creates an instance of ShowEmbeddedMenu.
11
- *
12
- * @param visible - A flag indicating whether the embedded menu should be visible.
13
- */
14
- constructor(visible: boolean);
15
- }
@@ -1,29 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- import { ToMetaBoxApiAction } from '../lib/MetaBoxApiAction';
7
- import { ApiAction } from './ApiAction';
8
- /**
9
- * Represents an action to toggle the Embedded Menu in MetaBox.
10
- *
11
- * @remarks
12
- * This action sends a message to the MetaBox API to toggle the visibility of the embedded menu.
13
- */
14
- export class ShowEmbeddedMenu extends ApiAction {
15
- /**
16
- * Creates an instance of ShowEmbeddedMenu.
17
- *
18
- * @param visible - A flag indicating whether the embedded menu should be visible.
19
- */
20
- constructor(visible) {
21
- super();
22
- this.api.sendMessageToMetaBox({
23
- action: ToMetaBoxApiAction.showEmbeddedMenu,
24
- payload: {
25
- visible,
26
- },
27
- });
28
- }
29
- }
package/dist/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export { ShowEmbeddedMenu } from './actions/ShowEmbeddedMenu';
2
- export { SetEnvironment } from './actions/SetEnvironment';
3
- export { SetProduct } from './actions/SetProduct';
4
- export { GetPdf } from './actions/GetPdf';
5
- export { SetMaterial } from './actions/SetMaterial';
6
- export { GetFastRender } from './actions/GetFastRender';
7
- export * from './lib/MetaBoxApiAction';
8
- export * from './lib/integrateMetaBox';
9
- export * from './lib/saveImage';
10
- export * from './lib/sleep';
11
- export * from './lib/UrlUtils';
package/dist/index.js DELETED
@@ -1,21 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- /*
7
- * Copyright (c) 2025.
8
- * 3DSource.com, Sergii Karanda steve@3dsource.com
9
- * All Rights Reserved
10
- */
11
- export { ShowEmbeddedMenu } from './actions/ShowEmbeddedMenu';
12
- export { SetEnvironment } from './actions/SetEnvironment';
13
- export { SetProduct } from './actions/SetProduct';
14
- export { GetPdf } from './actions/GetPdf';
15
- export { SetMaterial } from './actions/SetMaterial';
16
- export { GetFastRender } from './actions/GetFastRender';
17
- export * from './lib/MetaBoxApiAction';
18
- export * from './lib/integrateMetaBox';
19
- export * from './lib/saveImage';
20
- export * from './lib/sleep';
21
- export * from './lib/UrlUtils';
@@ -1,132 +0,0 @@
1
- export interface bridge {
2
- action: string;
3
- eventType: string;
4
- payload: ExportedConfigurator;
5
- }
6
- export interface ExportedConfigurator {
7
- configurator: UniversalConfigurator | null;
8
- selectedMaterials: SelectedMaterials;
9
- productId: string;
10
- environment: UniversalConfiguratorEnvironment;
11
- }
12
- export interface UniversalConfigurator {
13
- id: string;
14
- isActive: boolean;
15
- productCollectionLabel: string;
16
- name: string;
17
- camera: Camera;
18
- client: Client;
19
- products: UniversalConfiguratorProduct[];
20
- environments: UniversalConfiguratorEnvironment[];
21
- __typename: 'UniversalConfigurator';
22
- }
23
- export interface Camera {
24
- mode: string;
25
- fov: number;
26
- position: Position;
27
- rotation: Rotation;
28
- restrictions: Restrictions;
29
- __typename: 'Camera';
30
- }
31
- export interface Position {
32
- x: number;
33
- y: number;
34
- z: number;
35
- __typename: 'Position';
36
- }
37
- export interface Rotation {
38
- pitch: number;
39
- yaw: number;
40
- roll: number;
41
- __typename: 'Rotation';
42
- }
43
- export interface Restrictions {
44
- maxZoom?: null;
45
- minZoom: number;
46
- minPitch: number;
47
- maxPitch: number;
48
- maxYaw?: null;
49
- minYaw?: null;
50
- panBoundariesRadius?: null;
51
- panBoundariesBox?: null;
52
- __typename: 'Restrictions';
53
- }
54
- export interface Client {
55
- id: string;
56
- name: string;
57
- unrealVersion: string;
58
- hasPublicAssets: boolean;
59
- __typename: 'Client';
60
- }
61
- export interface UniversalConfiguratorProduct {
62
- productId: string;
63
- position: number;
64
- label: string;
65
- camera?: null;
66
- product: Product;
67
- __typename: 'UniversalConfiguratorProduct';
68
- }
69
- export interface Product {
70
- title: string;
71
- thumbnailList?: ThumbnailListEntity[] | null;
72
- slots?: Slot[] | null;
73
- model: Model;
74
- id: string;
75
- showcase: Showcase;
76
- __typename: 'Product';
77
- }
78
- export interface ThumbnailListEntity {
79
- width: number;
80
- height: number;
81
- urlPath: string;
82
- __typename: string;
83
- }
84
- export interface Slot {
85
- id: string;
86
- label: string;
87
- enabledMaterials?: Material[] | null;
88
- __typename: 'Slot';
89
- }
90
- export interface Material {
91
- id: string;
92
- title: string;
93
- thumbnailList?: ThumbnailListEntity[] | null;
94
- model: Model;
95
- __typename: 'Material';
96
- }
97
- export interface Model {
98
- id: string;
99
- pakFilePath: string;
100
- assetPath: string;
101
- unrealVersion: string;
102
- __typename: 'Model';
103
- }
104
- export interface Showcase {
105
- lowBandwidth?: (LowBandwidthEntity | null)[] | null;
106
- duration?: null;
107
- __typename: 'Showcase';
108
- }
109
- export interface LowBandwidthEntity {
110
- time: number;
111
- duration: number;
112
- __typename: string;
113
- }
114
- export interface UniversalConfiguratorEnvironment {
115
- environmentId: string;
116
- position: number;
117
- label: string;
118
- environment: Environment;
119
- __typename: 'UniversalConfiguratorEnvironment';
120
- }
121
- export interface Environment {
122
- id: string;
123
- title: string;
124
- udsEnabled: boolean;
125
- sunNorthYaw: number;
126
- udsHour: number;
127
- __typename: 'Environment';
128
- thumbnailList?: ThumbnailListEntity[] | null;
129
- slots?: null[] | null;
130
- model: Model;
131
- }
132
- export type SelectedMaterials = Record<string, Record<string, string>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- import type { FromMetaBoxAPIEnvelope, ToMetaBoxMessagePayload } from '@api/src';
2
-
3
- export interface FromMetaBoxMessage {
4
- host: 'metabox';
5
- payload: FromMetaBoxAPIEnvelope;
6
- }
7
- export interface ToMetaBoxMessage {
8
- host: 'metaBoxHost';
9
- payload: ToMetaBoxMessagePayload;
10
- }
@@ -1,6 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- export {};
@@ -1,92 +0,0 @@
1
- import { ExportedConfigurator } from '../interfaces/UniversalConfigurator';
2
- export declare const FromMetaBoxApiAction: {
3
- bridge: string;
4
- unrealCallback: string;
5
- unrealFeatureBridge: string;
6
- /**
7
- * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
8
- */
9
- configuratorDataWithStateBridge: string;
10
- /**
11
- * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
12
- */
13
- configuratorDataBridge: string;
14
- /**
15
- * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
16
- */
17
- menuDataBridge: string;
18
- /**
19
- * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
20
- */
21
- flatMenuDataBridge: string;
22
- /**
23
- * @deprecated, use Bridge with isFullscreen
24
- */
25
- fullScreenBridge: string;
26
- /**
27
- * @deprecated, use Bridge with streamResolution
28
- */
29
- videoSize: string;
30
- /**
31
- * Used in platform, must be removed in future
32
- */
33
- /**
34
- * @deprecated\
35
- */
36
- unrealResponse: string;
37
- /**
38
- * @deprecated\
39
- */
40
- getFastRender: string;
41
- appLoaded: string;
42
- };
43
- export declare const ToMetaBoxApiAction: {
44
- readonly getPdf: "getPdf";
45
- readonly loadLevel: "loadLevel";
46
- readonly setProduct: "setProduct";
47
- readonly addResponse: "addResponse";
48
- readonly getFastRender: "getFastRender";
49
- readonly watchCallbacks: "watchCallbacks";
50
- readonly setExternalMode: "setExternalMode";
51
- readonly setMaterialById: "setMaterialById";
52
- readonly showEmbeddedMenu: "showEmbeddedMenu";
53
- readonly forceSetDeviceType: "forceSetDeviceType";
54
- };
55
- export type ToMetaBoxApiTypeValue = (typeof ToMetaBoxApiAction)[keyof typeof ToMetaBoxApiAction];
56
- export type FromMetaBoxApiTypeValue = (typeof FromMetaBoxApiAction)[keyof typeof FromMetaBoxApiAction];
57
- export interface ToMetaBoxMessagePayload {
58
- action: ToMetaBoxApiTypeValue;
59
- payload?: Record<string, unknown> | never;
60
- }
61
- export interface MCAppLoaded {
62
- action: string;
63
- eventType?: unknown;
64
- payload?: unknown;
65
- }
66
- export interface MetaBoxAPIPayloads {
67
- basicConfiguratorDataWithState: ExportedConfigurator;
68
- dataChannelConnected: boolean;
69
- viewportReady: boolean;
70
- isFullscreen: boolean;
71
- statusMessage: string;
72
- freezeFrame: {
73
- dataUrl: string | null;
74
- progress: number | null;
75
- };
76
- unrealCallback: object;
77
- getFastRender: string | null;
78
- unrealFeature: object;
79
- streamResolution: {
80
- width: number;
81
- number: number;
82
- };
83
- }
84
- export type FromMetaBoxApiKeys = keyof MetaBoxAPIPayloads;
85
- export interface MetaBoxApiEnvelope<T extends FromMetaBoxApiKeys> {
86
- action: 'bridge';
87
- eventType: T;
88
- payload: MetaBoxAPIPayloads[T];
89
- }
90
- export type FromMetaBoxAPIEnvelope = {
91
- [K in keyof MetaBoxAPIPayloads]: MetaBoxApiEnvelope<K>;
92
- }[keyof MetaBoxAPIPayloads] | MCAppLoaded;
@@ -1,58 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- export const FromMetaBoxApiAction = {
7
- bridge: 'bridge',
8
- unrealCallback: 'unrealCallback',
9
- unrealFeatureBridge: 'unrealFeatureBridge',
10
- /**
11
- * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
12
- */
13
- configuratorDataWithStateBridge: 'configuratorDataWithStateBridge',
14
- /**
15
- * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
16
- */
17
- configuratorDataBridge: 'configuratorDataBridge',
18
- /**
19
- * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
20
- */
21
- menuDataBridge: 'menuDataBridge',
22
- /**
23
- * @deprecated, use MetaBoxApiAction.Bridge with eventType: "configuratorDataWithState"
24
- */
25
- flatMenuDataBridge: 'flatMenuDataBridge',
26
- /**
27
- * @deprecated, use Bridge with isFullscreen
28
- */
29
- fullScreenBridge: 'fullScreenBridge',
30
- /**
31
- * @deprecated, use Bridge with streamResolution
32
- */
33
- videoSize: 'videoSize',
34
- /**
35
- * Used in platform, must be removed in future
36
- */
37
- /**
38
- * @deprecated\
39
- */
40
- unrealResponse: 'unrealResponse',
41
- /**
42
- * @deprecated\
43
- */
44
- getFastRender: 'getFastRender',
45
- appLoaded: 'appLoaded',
46
- };
47
- export const ToMetaBoxApiAction = {
48
- getPdf: 'getPdf',
49
- loadLevel: 'loadLevel',
50
- setProduct: 'setProduct',
51
- addResponse: 'addResponse',
52
- getFastRender: 'getFastRender',
53
- watchCallbacks: 'watchCallbacks',
54
- setExternalMode: 'setExternalMode',
55
- setMaterialById: 'setMaterialById',
56
- showEmbeddedMenu: 'showEmbeddedMenu',
57
- forceSetDeviceType: 'forceSetDeviceType',
58
- };
@@ -1,18 +0,0 @@
1
- /**
2
- * Sets the URL parameters based on the provided state.
3
- *
4
- * @remarks
5
- * This function updates the current URL by replacing its search parameters with the key-value pairs from the provided state object.
6
- *
7
- * @param state - An object containing key-value pairs to set as URL parameters.
8
- */
9
- export declare function setUrlParams(state: Record<string, string>): void;
10
- /**
11
- * Retrieves the URL parameters as an object.
12
- *
13
- * @remarks
14
- * This function parses the current URL's search parameters and returns them as a key-value object.
15
- *
16
- * @returns An object containing the URL parameters.
17
- */
18
- export declare function getUrlParams(): Record<string, string>;
@@ -1,37 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- /**
7
- * Sets the URL parameters based on the provided state.
8
- *
9
- * @remarks
10
- * This function updates the current URL by replacing its search parameters with the key-value pairs from the provided state object.
11
- *
12
- * @param state - An object containing key-value pairs to set as URL parameters.
13
- */
14
- export function setUrlParams(state) {
15
- const url = new URL(window.location.href);
16
- url.search = '';
17
- Object.entries(state).forEach(([key, value]) => {
18
- url.searchParams.set(key, value);
19
- });
20
- history.replaceState(null, '', url.toString());
21
- }
22
- /**
23
- * Retrieves the URL parameters as an object.
24
- *
25
- * @remarks
26
- * This function parses the current URL's search parameters and returns them as a key-value object.
27
- *
28
- * @returns An object containing the URL parameters.
29
- */
30
- export function getUrlParams() {
31
- const urlParams = new URLSearchParams(window.location.search);
32
- const selections = {};
33
- urlParams.forEach((value, key) => {
34
- selections[key] = value;
35
- });
36
- return selections;
37
- }
@@ -1,86 +0,0 @@
1
- import { ToMetaBoxMessagePayload } from './MetaBoxApiAction';
2
- declare global {
3
- interface Window {
4
- env3DSource: {
5
- api: Communicator;
6
- apiReady: (api: Communicator) => void;
7
- };
8
- }
9
- }
10
- /**
11
- * API class to handle communication with the embedded content.
12
- *
13
- * @remarks
14
- * This class sets up a communication channel with the embedded content via window messages.
15
- */
16
- declare class Communicator {
17
- /**
18
- * Storage for callback listeners by message type.
19
- */
20
- private listeners;
21
- /**
22
- * Binder function for handling incoming messages.
23
- */
24
- private binder;
25
- /**
26
- * The singleton instance of the communicator.
27
- */
28
- static instance: Communicator | null;
29
- /**
30
- * Creates an instance of Communicator.
31
- *
32
- * @remarks
33
- * If an instance already exists, it will be destroyed before creating a new one.
34
- * The instance listens for messages from the iframe.
35
- */
36
- constructor();
37
- /**
38
- * Destroys the communicator instance by clearing listeners and removing event listeners.
39
- */
40
- destroy(): void;
41
- /**
42
- * Sends a message to the embedded content (MetaBox).
43
- *
44
- * @param data - The data to send.
45
- */
46
- sendMessageToMetaBox(data: ToMetaBoxMessagePayload): void;
47
- /**
48
- * Adds an event listener for receiving specific types of messages.
49
- *
50
- * @param messageType - The message type to listen for.
51
- * @param callback - The callback function to execute when a message is received.
52
- */
53
- addEventListener(messageType: string, callback: (data: unknown) => void): void;
54
- /**
55
- * Dispatches an event to all listeners of a specific message type.
56
- *
57
- * @param messageType - The message type.
58
- * @param data - The data associated with the event.
59
- */
60
- dispatchEvent(messageType: string, data: unknown): void;
61
- /**
62
- * Handles incoming messages by invoking the appropriate callbacks.
63
- *
64
- * @param messageType - The message type to filter for.
65
- * @param event - The incoming message event.
66
- *
67
- * @remarks
68
- * Optionally, you can perform an origin check for added security.
69
- */
70
- private handleMessageReceived;
71
- /**
72
- * Removes an event listener for a specific type of message.
73
- *
74
- * @param messageType - The message type.
75
- * @param callback - The callback function to remove.
76
- */
77
- removeEventListener(messageType: string, callback: (data: unknown) => void): void;
78
- }
79
- /**
80
- * Initializes the communicator when the embedded content is ready.
81
- *
82
- * @remarks
83
- * This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
84
- */
85
- export declare function initializeCommunicator(): void;
86
- export {};
@@ -1,131 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- const messageType = 'metaboxData';
7
- /**
8
- * API class to handle communication with the embedded content.
9
- *
10
- * @remarks
11
- * This class sets up a communication channel with the embedded content via window messages.
12
- */
13
- class Communicator {
14
- /**
15
- * Creates an instance of Communicator.
16
- *
17
- * @remarks
18
- * If an instance already exists, it will be destroyed before creating a new one.
19
- * The instance listens for messages from the iframe.
20
- */
21
- constructor() {
22
- var _a;
23
- /**
24
- * Storage for callback listeners by message type.
25
- */
26
- this.listeners = [];
27
- /**
28
- * Binder function for handling incoming messages.
29
- */
30
- this.binder = this.handleMessageReceived.bind(this, messageType);
31
- (_a = Communicator.instance) === null || _a === void 0 ? void 0 : _a.destroy();
32
- Communicator.instance = this;
33
- window.addEventListener('message', this.binder);
34
- }
35
- /**
36
- * Destroys the communicator instance by clearing listeners and removing event listeners.
37
- */
38
- destroy() {
39
- this.listeners = [];
40
- window.removeEventListener('message', this.binder);
41
- }
42
- /**
43
- * Sends a message to the embedded content (MetaBox).
44
- *
45
- * @param data - The data to send.
46
- */
47
- sendMessageToMetaBox(data) {
48
- var _a;
49
- const iframe = document.getElementById('embeddedContent');
50
- const dataToSend = {
51
- host: 'metaBoxHost',
52
- payload: Object.assign({}, data),
53
- };
54
- // In production, replace "*" with the actual origin for added security.
55
- (_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(dataToSend, '*');
56
- }
57
- /**
58
- * Adds an event listener for receiving specific types of messages.
59
- *
60
- * @param messageType - The message type to listen for.
61
- * @param callback - The callback function to execute when a message is received.
62
- */
63
- addEventListener(messageType, callback) {
64
- this.listeners.push({ messageType, callback });
65
- }
66
- /**
67
- * Dispatches an event to all listeners of a specific message type.
68
- *
69
- * @param messageType - The message type.
70
- * @param data - The data associated with the event.
71
- */
72
- dispatchEvent(messageType, data) {
73
- this.listeners
74
- .filter((listener) => listener.messageType === messageType)
75
- .forEach((listener) => listener.callback(data));
76
- }
77
- /**
78
- * Handles incoming messages by invoking the appropriate callbacks.
79
- *
80
- * @param messageType - The message type to filter for.
81
- * @param event - The incoming message event.
82
- *
83
- * @remarks
84
- * Optionally, you can perform an origin check for added security.
85
- */
86
- handleMessageReceived(messageType, event) {
87
- var _a;
88
- // Optional: Perform origin check here for added security
89
- // if (event.origin !== "EXPECTED_ORIGIN") return;
90
- if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.host) !== 'metabox') {
91
- return;
92
- }
93
- this.listeners
94
- .filter((listener) => listener.messageType === messageType)
95
- .forEach((listener) => {
96
- listener.callback(event.data.payload);
97
- });
98
- }
99
- /**
100
- * Removes an event listener for a specific type of message.
101
- *
102
- * @param messageType - The message type.
103
- * @param callback - The callback function to remove.
104
- */
105
- removeEventListener(messageType, callback) {
106
- this.listeners = this.listeners.filter((listener) => !(listener.messageType === messageType && listener.callback === callback));
107
- }
108
- }
109
- /**
110
- * The singleton instance of the communicator.
111
- */
112
- Communicator.instance = null;
113
- /**
114
- * Initializes the communicator when the embedded content is ready.
115
- *
116
- * @remarks
117
- * This function sets up a listener that waits for the 'appLoaded' action and then initializes the Communicator.
118
- */
119
- export function initializeCommunicator() {
120
- window.env3DSource = window.env3DSource || {};
121
- const startHandler = (event) => {
122
- var _a, _b;
123
- 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' &&
124
- 'apiReady' in window.env3DSource) {
125
- window.env3DSource.api = new Communicator();
126
- window.env3DSource.apiReady(window.env3DSource.api);
127
- window.removeEventListener('message', startHandler);
128
- }
129
- };
130
- window.addEventListener('message', startHandler);
131
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Integrates the MetaBox into the provided layout.
3
- *
4
- * @remarks
5
- * This function injects an iframe into a specified container element in the DOM and initializes
6
- * the communicator for interacting with the MetaBox embedded content.
7
- *
8
- * @param iframeSrc - The source URL of the MetaBox iframe.
9
- * @param containerId - The ID of the layout element. Defaults to 'embed3DSource'.
10
- *
11
- * @throws Error if the container element with the specified ID is not found.
12
- */
13
- export declare function integrateMetaBox(iframeSrc: string, containerId?: string): void;
@@ -1,44 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- import { initializeCommunicator } from './initializeCommunicator';
7
- /**
8
- * Integrates the MetaBox into the provided layout.
9
- *
10
- * @remarks
11
- * This function injects an iframe into a specified container element in the DOM and initializes
12
- * the communicator for interacting with the MetaBox embedded content.
13
- *
14
- * @param iframeSrc - The source URL of the MetaBox iframe.
15
- * @param containerId - The ID of the layout element. Defaults to 'embed3DSource'.
16
- *
17
- * @throws Error if the container element with the specified ID is not found.
18
- */
19
- export function integrateMetaBox(iframeSrc, containerId = 'embed3DSource') {
20
- const container = document.getElementById(containerId);
21
- if (!container) {
22
- throw new Error(`Container element with id ${containerId} not found`);
23
- }
24
- initializeCommunicator();
25
- const style = document.createElement('style');
26
- style.innerHTML = `
27
- #${containerId} {
28
- width: 100%;
29
- height: 100%;
30
- overflow: hidden;
31
- position: relative;
32
- }
33
- `;
34
- document.head.appendChild(style);
35
- const iframe = document.createElement('iframe');
36
- iframe.setAttribute('referrerPolicy', 'no-referrer-when-downgrade');
37
- iframe.setAttribute('id', 'embeddedContent');
38
- iframe.style.border = '0';
39
- iframe.style.width = '100%';
40
- iframe.style.height = '100%';
41
- iframe.style.overflow = 'hidden';
42
- iframe.src = iframeSrc;
43
- container.appendChild(iframe);
44
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Saves an image by triggering a download.
3
- *
4
- * @remarks
5
- * This function creates an anchor element, sets its `href` attribute to the provided image URL,
6
- * and triggers a click event to initiate a download with the specified filename.
7
- *
8
- * @param image - The URL of the image to save.
9
- * @param filename - The name of the file to save.
10
- */
11
- export declare function saveImage(image: string, filename: string): void;
@@ -1,23 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- /**
7
- * Saves an image by triggering a download.
8
- *
9
- * @remarks
10
- * This function creates an anchor element, sets its `href` attribute to the provided image URL,
11
- * and triggers a click event to initiate a download with the specified filename.
12
- *
13
- * @param image - The URL of the image to save.
14
- * @param filename - The name of the file to save.
15
- */
16
- export function saveImage(image, filename) {
17
- const a = document.createElement('a');
18
- a.href = image;
19
- a.download = filename;
20
- document.body.appendChild(a);
21
- a.click();
22
- document.body.removeChild(a);
23
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Pauses execution for a specified duration.
3
- *
4
- * @remarks
5
- * This function returns a promise that resolves after the given number of milliseconds.
6
- *
7
- * @param time - The time to sleep in milliseconds.
8
- * @returns A promise that resolves after the specified duration.
9
- */
10
- export declare function sleep(time: number): Promise<void>;
package/dist/lib/sleep.js DELETED
@@ -1,17 +0,0 @@
1
- /*
2
- * Copyright (c) 2025.
3
- * 3DSource.com, Sergii Karanda steve@3dsource.com
4
- * All Rights Reserved
5
- */
6
- /**
7
- * Pauses execution for a specified duration.
8
- *
9
- * @remarks
10
- * This function returns a promise that resolves after the given number of milliseconds.
11
- *
12
- * @param time - The time to sleep in milliseconds.
13
- * @returns A promise that resolves after the specified duration.
14
- */
15
- export function sleep(time) {
16
- return new Promise((resolve) => setTimeout(resolve, time));
17
- }