@3dsource/metabox-front-api 0.0.13 → 0.0.15

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
@@ -14,13 +14,13 @@ then
14
14
  import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from '@3dsource/metabox-front-api';
15
15
  ```
16
16
 
17
- **OR** work with direct import from `NPM` using `CDN` network unpkg.com (you can also download package and use it locally):
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
18
 
19
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';
20
+ import { FromMetaBoxApiAction, GetFastRender, GetPdf, integrateMetaBox, saveImage, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu,... } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
21
21
  ```
22
22
 
23
- **WE ARE HIGHLY RECOMMENDING TO USE THE FIRST OPTION WITH NPM, AS THE SECOND ONE CAN RAPIDLY CHANGE AND MAY CAUSE UNEXPECTED BEHAVIOR WITH CODE YOU ARE ALREADY USING.**
23
+ **We strongly recommend using the first option with npm and locking it to the latest version at the time of integration, as the second option can change rapidly and may cause unexpected behavior in your existing code.**
24
24
 
25
25
  ## Usage
26
26
 
@@ -45,8 +45,7 @@ Insert this code into your HTML file just before the closing `</body>` tag:
45
45
 
46
46
  ```html
47
47
  <script type="module">
48
- import { integrateMetaBox, SetEnvironment, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, FromMetaboxApiAction } from '@3dsource/metabox-front-api';
49
- let initilaized = false;
48
+ import { integrateMetaBox, SetEnvironment, SetEnvironmentMaterial, SetMaterial, SetProduct, ShowEmbeddedMenu, GetFastRender, GetPdf, saveImage, FromMetaboxApiAction } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
50
49
  // Expose API
51
50
  window.env3DSource.apiReady = (api) => {
52
51
  api.addEventListener('metaboxData', (data) => {
@@ -55,20 +54,8 @@ Insert this code into your HTML file just before the closing `</body>` tag:
55
54
  return;
56
55
  }
57
56
 
58
- if (eventType === 'viewportReady' && payload === true) {
59
- //You can use this event to trigger any action that can work only when the viewport is ready,
60
- //i.e. GetPdf or GetFastRender
61
-
62
- // Get a fast render (optionally specify size)
63
- new GetFastRender('image/png', { x: 1024, y: 1024 });
64
-
65
- // Generate a PDF of the current view
66
- new GetPdf();
67
- }
68
-
69
57
  if (eventType === 'basicConfiguratorDataWithState') {
70
58
  updateConfiguratorData(data);
71
- setupInitialState();
72
59
  }
73
60
 
74
61
  if (eventType === 'fastRender') {
@@ -76,6 +63,7 @@ Insert this code into your HTML file just before the closing `</body>` tag:
76
63
  saveImage(payload, 'Render.png');
77
64
  }
78
65
  });
66
+ setupInitialState();
79
67
  };
80
68
 
81
69
  /**
@@ -87,27 +75,36 @@ Insert this code into your HTML file just before the closing `</body>` tag:
87
75
  }
88
76
 
89
77
  /**
90
- * Setup initial state
78
+ * Setup initial state,
79
+ * Executes additional commands as example
91
80
  */
92
81
  function setupInitialState() {
93
- if (initilaized) {
94
- return;
95
- }
82
+ // All commands can be used at any time from the moment api is ready and will be buffered automatically
83
+ // i.e. GetFastRender and GetPdf will be executed when the viewport is ready
84
+
96
85
  // Set product
97
- new SetProduct('product-id');
86
+ new SetProduct('productId');
98
87
 
99
88
  // Set environment
100
- new SetEnvironment('env-id');
89
+ new SetEnvironment('environmentId');
101
90
 
102
91
  // Set material
103
- new SetMaterial('product-id', 'slot-id', 'material-id');
92
+ new SetMaterial('productId', 'slotId', 'materialId');
93
+
94
+ // Set environment material
95
+ new SetEnvironmentMaterial('productId', 'slotId', 'materialId');
104
96
 
105
97
  // Toggle embedded menu
106
98
  new ShowEmbeddedMenu(false);
99
+
100
+ //Request Pdf, Will execute as stream is ready, will be auto-downloaded
101
+ new GetPdf();
102
+
103
+ //Request Fast Render, Will execute as stream is ready, will be sent back as a callback
104
+ new GetFastRender('image/png', { x: 1024, y: 1024 });
107
105
  }
108
106
 
109
107
  // Integrate the 3D configurator into your page
110
-
111
108
  /**
112
109
  * Additional url parameters:
113
110
  * @see integrateMetaBox
@@ -144,6 +141,14 @@ Insert this code into your HTML file just before the closing `</body>` tag:
144
141
  new SetMaterial(productId: string, slotId: string, materialId: string);
145
142
  ```
146
143
 
144
+ ### `SetEnvironmentMaterial`
145
+
146
+ - **Description**: Sets the material for a given environment slot.
147
+ - **Constructor**:
148
+ ```typescript
149
+ new SetEnvironmentMaterial(productId: string, slotId: string, materialId: string);
150
+ ```
151
+
147
152
  ### `SetProduct`
148
153
 
149
154
  - **Description**: Sets the product by ID.
@@ -162,12 +167,6 @@ Insert this code into your HTML file just before the closing `</body>` tag:
162
167
 
163
168
  ### `GetFastRender`
164
169
 
165
- **Important:** Before invoking this action, ensure that the MetaBox viewport is fully loaded. This is indicated by the event:
166
-
167
- ```javascript
168
- data.eventType === 'viewportReady' && data.payload === true.
169
- ```
170
-
171
170
  - **Description**: Retrieves a fast render of the current view.
172
171
  - **Usage**:
173
172
  ```typescript
@@ -176,12 +175,6 @@ data.eventType === 'viewportReady' && data.payload === true.
176
175
 
177
176
  ### `GetPdf`
178
177
 
179
- **Important:** Before invoking this action, ensure that the MetaBox viewport is fully loaded. This is indicated by the event:
180
-
181
- ```javascript
182
- data.eventType === 'viewportReady' && data.payload === true.
183
- ```
184
-
185
178
  - **Description**: Generates a PDF of the current view.
186
179
  - **Usage**:
187
180
  ```typescript
@@ -1,7 +1,25 @@
1
1
  import type { Communicator } from '../lib/initializeCommunicator';
2
2
  /**
3
- * Base class for all API actions.
4
- * @hidden
3
+ * To integrate the MetaBox configurator into an HTML element, use the following example:
4
+ *
5
+ * **We strongly recommend using the option with npm and locking it to the latest version at the time of integration, as the option with cdn can change rapidly and may cause unexpected behavior in your existing code. See root documentation.**
6
+ *
7
+ * ```typescript
8
+ * import { integrateMetaBox } from 'https://cdn.jsdelivr.net/npm/@3dsource/metabox-front-api@latest/dist/index.js';
9
+ *
10
+ * integrateMetaBox(
11
+ * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
12
+ * 'embed3DSource'
13
+ * );
14
+ *
15
+ * // Set up the global API environment
16
+ * window.env3DSource = window.env3DSource || {};
17
+ *
18
+ * //Listen for the API ready event
19
+ * window.env3DSource.apiReady = (api) => {
20
+ * // Use the API actions here
21
+ * };
22
+ * ```
5
23
  */
6
24
  export declare class ApiAction {
7
25
  protected api: Communicator;
@@ -6,40 +6,25 @@ import { ApiAction } from './ApiAction';
6
6
  */
7
7
  export type MimeType = 'image/png' | 'image/jpeg' | 'image/webp';
8
8
  /**
9
+ * {@inheritDoc ApiAction}
10
+ *
9
11
  * Represents a fast render action.
10
12
  * @remarks
11
13
  * This class sends a message to the MetaBox API to obtain a fast render based on the provided format and optional size.
12
14
  *
13
- * **Important:** Before invoking this action, ensure that the MetaBox viewport is fully loaded. This is indicated by the event:
14
- * ```javascript
15
- * data.eventType === 'viewportReady' && data.payload === true.
16
- * ```
17
- * Only then request be processed.
15
+ * **Important**: Invoking this action will buffer it until the viewport is ready. Only then will the request be processed.
18
16
  *
19
17
  * @example
20
- * import { integrateMetaBox, GetFastRender, saveImage } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
21
- *
22
- * // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
23
- * integrateMetaBox(
24
- * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
25
- * 'embed3DSource'
26
- * );
27
- *
28
- * // Set up the global API environment
29
- * window.env3DSource = window.env3DSource || {};
18
+ * import { GetFastRender,saveImage } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
30
19
  * window.env3DSource.apiReady = (api) => {
31
20
  * // Listen for events from the MetaBox API
32
21
  * api.addEventListener('metaboxData', (data) => {
33
- * // Ensure the viewport is ready before sending render requests
34
- * if (data.eventType === 'viewportReady' && data.payload === true) {
35
- * // Request a fast render (PNG image with 1024x1024 dimensions)
36
- * new GetFastRender('image/png', { x: 1024, y: 1024 });
37
- * }
38
22
  * // Process the fast render response
39
23
  * if (data.eventType === 'fastRender') {
40
24
  * saveImage(data.payload, 'Render.png');
41
25
  * }
42
26
  * });
27
+ * new GetFastRender('image/png', { x: 1024, y: 1024 });
43
28
  * };
44
29
  */
45
30
  export declare class GetFastRender extends ApiAction {
@@ -1,32 +1,18 @@
1
1
  import { ApiAction } from './ApiAction';
2
2
  /**
3
+ * {@inheritDoc ApiAction}
4
+ *
3
5
  * Represents an action to get a PDF from Metabox.
4
6
  * @remarks
5
7
  * This class sends a message to the MetaBox API to generate a PDF based on the current configuration.
6
8
  * This action does not require any parameters.
7
9
  *
8
- * **Important:** Before invoking this action, ensure that the MetaBox viewport is fully loaded. This is indicated by the event:
9
- *```javascript
10
- * data.eventType === 'viewportReady' && data.payload === true.
11
- * ```
12
- * Only then request be processed.
10
+ * **Important**: Invoking this action will buffer it until the viewport is ready. Only then will the request be processed.
13
11
  *
14
12
  * @example
15
- * import { integrateMetaBox, GetPdf } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
16
- *
17
- * integrateMetaBox(
18
- * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
19
- * 'embed3DSource'
20
- * );
21
- *
22
- * window.env3DSource = window.env3DSource || {};
13
+ * import { GetPdf } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
23
14
  * window.env3DSource.apiReady = (api) => {
24
- * api.addEventListener('metaboxData', (data) => {
25
- * if (data.eventType === 'viewportReady' && data.payload === true) {
26
- * // Request a PDF of the current configuration
27
- * new GetPdf();
28
- * }
29
- * });
15
+ * new GetPdf();
30
16
  * };
31
17
  */
32
18
  export declare class GetPdf extends ApiAction {
@@ -1,5 +1,6 @@
1
1
  import { ApiAction } from './ApiAction';
2
2
  /**
3
+ * {@inheritDoc ApiAction}
3
4
  * @internal
4
5
  * @hidden
5
6
  * Represents an action to send Unreal command.
@@ -1,21 +1,13 @@
1
1
  import { ApiAction } from './ApiAction';
2
2
  /**
3
+ * {@inheritDoc ApiAction}
4
+ *
3
5
  * Represents an action to set the environment by its ID.
4
6
  * @remarks
5
7
  * This action sends a message to the MetaBox API to load the environment level using the specified environment ID.
6
- * It requires the MetaBox API to be properly initialized and an event listener to be registered.
7
8
  *
8
9
  * @example
9
- * import { integrateMetaBox, SetEnvironment } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
10
- *
11
- * // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
12
- * integrateMetaBox(
13
- * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
14
- * 'embed3DSource'
15
- * );
16
- *
17
- * // Setup API ready callback
18
- * window.env3DSource = window.env3DSource || {};
10
+ * import { SetEnvironment } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
19
11
  * window.env3DSource.apiReady = (api) => {
20
12
  * // Change the environment to '55555555-1234-1234-1234-01234567890'
21
13
  * new SetEnvironment('55555555-1234-1234-1234-01234567890');
@@ -1,45 +1,25 @@
1
1
  import { ApiAction } from './ApiAction';
2
2
  /**
3
- * Represents an action to set a material by its ID.
3
+ * {@inheritDoc ApiAction}
4
+ *
5
+ * Represents an action to set a environment material by its ID.
4
6
  *
5
7
  * @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
- * **Important:** Before invoking this action, ensure that the MetaBox already dispatched
9
- * as minimum one eventType:"basicConfiguratorDataWithState":
10
- * ```javascript
11
- * data.eventType === 'basicConfiguratorDataWithState'.
12
- * ```
13
- * Only then request be processed.
8
+ * This action sends a message to the MetaBox API to update the material on a specific environment slot using the provided identifiers.
14
9
  *
15
10
  * @example
16
- * import { SetMaterial } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
17
- *
18
- * // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
19
- * integrateMetaBox(
20
- * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
21
- * 'embed3DSource'
22
- * );
23
- *
24
- * // Set up the global API environment
25
- * window.env3DSource = window.env3DSource || {};
11
+ * import { SetEnvironmentMaterial } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
26
12
  * window.env3DSource.apiReady = (api) => {
27
- * // Listen for events from the MetaBox API
28
- * api.addEventListener('metaboxData', (data) => {
29
- * // Process SetMaterial
30
- * if (data.eventType === 'basicConfiguratorDataWithState') {
31
- * new SetEnvironmentMaterial(
32
- * 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
33
- * 'carpaint',
34
- * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
35
- * );
36
- * }
37
- * });
13
+ * new SetEnvironmentMaterial(
14
+ * 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
15
+ * 'carpaint',
16
+ * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
17
+ * );
38
18
  * };
39
19
  */
40
20
  export declare class SetEnvironmentMaterial extends ApiAction {
41
21
  /**
42
- * Creates an instance of SetMaterial.
22
+ * Creates an instance of SetEnvironmentMaterial.
43
23
  *
44
24
  * @param productId - The product ID.
45
25
  * @param slotId - The slot ID.
@@ -1,40 +1,20 @@
1
1
  import { ApiAction } from './ApiAction';
2
2
  /**
3
+ * {@inheritDoc ApiAction}
4
+ *
3
5
  * Represents an action to set a material by its ID.
4
6
  *
5
7
  * @remarks
6
8
  * This action sends a message to the MetaBox API to update the material on a specific product slot using the provided identifiers.
7
-
8
- * **Important:** Before invoking this action, ensure that the MetaBox already dispatched
9
- * as minimum one eventType:"basicConfiguratorDataWithState":
10
- * ```javascript
11
- * data.eventType === 'basicConfiguratorDataWithState'.
12
- * ```
13
- * Only then request be processed.
14
9
  *
15
10
  * @example
16
11
  * import { SetMaterial } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
17
- *
18
- * // Integrate the MetaBox configurator into an HTML element with the ID 'embed3DSource'
19
- * integrateMetaBox(
20
- * 'https://metabox.3dsource.com/metabox-configurator/basic/12345678-1234-1234-1234-01234567890?introImage=https://example.com/intro.webp&sidebar=false',
21
- * 'embed3DSource'
22
- * );
23
- *
24
- * // Set up the global API environment
25
- * window.env3DSource = window.env3DSource || {};
26
12
  * window.env3DSource.apiReady = (api) => {
27
- * // Listen for events from the MetaBox API
28
- * api.addEventListener('metaboxData', (data) => {
29
- * // Process SetMaterial
30
- * if (data.eventType === 'basicConfiguratorDataWithState') {
31
- * new SetMaterial(
32
- * 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
33
- * 'carpaint',
34
- * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
35
- * );
36
- * }
37
- * });
13
+ * new SetMaterial(
14
+ * 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3',
15
+ * 'carpaint',
16
+ * 'dd829d6e-9200-47a7-8d5b-af5df89b7e91',
17
+ * );
38
18
  * };
39
19
  */
40
20
  export declare class SetMaterial extends ApiAction {
@@ -1,9 +1,19 @@
1
1
  import { ApiAction } from './ApiAction';
2
2
  /**
3
+ * {@inheritDoc ApiAction}
4
+ *
3
5
  * Represents an action to set a product by its ID.
4
6
  *
5
7
  * @remarks
6
8
  * This action sends a message to the MetaBox API to set a product using the provided product ID.
9
+ *
10
+ * @example
11
+ * import { SetProduct } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
12
+ * window.env3DSource.apiReady = (api) => {
13
+ * new SetProduct(
14
+ * 'ffea6b5c-3a8a-4f56-9417-e605acb5cca3'
15
+ * );
16
+ * };
7
17
  */
8
18
  export declare class SetProduct extends ApiAction {
9
19
  /**
@@ -1,9 +1,17 @@
1
1
  import { ApiAction } from './ApiAction';
2
2
  /**
3
- * Represents an action to toggle the Embedded Menu in MetaBox.
3
+ * {@inheritDoc ApiAction}
4
+ *
5
+ * Represents an action to toggle the Embedded MetaBox Menu.
4
6
  *
5
7
  * @remarks
6
8
  * This action sends a message to the MetaBox API to toggle the visibility of the embedded menu.
9
+ *
10
+ * @example
11
+ * import { ShowEmbeddedMenu } from 'https://unpkg.com/@3dsource/metabox-front-api@latest/dist/index.js';
12
+ * window.env3DSource.apiReady = (api) => {
13
+ * new ShowEmbeddedMenu(true);
14
+ * };
7
15
  */
8
16
  export declare class ShowEmbeddedMenu extends ApiAction {
9
17
  /**
@@ -1,6 +1,8 @@
1
1
  import { ApiAction } from './ApiAction';
2
2
  /**
3
3
  * @experimental
4
+ * @internal
5
+ * @hidden
4
6
  * @remarks
5
7
  * Represents an action to watch Unreal callbacks from Unreal engine.
6
8
  * Can be useful for custom solutions.
package/dist/index.d.ts CHANGED
@@ -7,14 +7,14 @@ export { SetEnvironmentMaterial } from './actions/SetEnvironmentMaterial';
7
7
  export { GetFastRender } from './actions/GetFastRender';
8
8
  export { SendCommandToUnreal } from './actions/SendCommandToUnreal';
9
9
  export { WatchCallbacks } from './actions/WatchCallbacks';
10
- export { MimeType } from './actions/GetFastRender';
10
+ export type { MimeType } from './actions/GetFastRender';
11
11
  export { ApiAction } from './actions/ApiAction';
12
12
  export * from './lib/integrateMetaBox';
13
13
  export * from './lib/initializeCommunicator';
14
14
  export * from './lib/saveImage';
15
15
  export * from './lib/sleep';
16
16
  export * from './lib/UrlUtils';
17
- export * from './interfaces/UniversalConfigurator';
17
+ export type * from './interfaces/UniversalConfigurator';
18
18
  export * from './interfaces/ToMetaboxMessagePayloads';
19
19
  export * from './interfaces/FromMetaboxMessagePayloads';
20
20
  export * from './interfaces/application-device-types';