@plattar/plattar-ar-adapter 1.123.6 → 1.123.7
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/build/es2015/plattar-ar-adapter.js +393 -93
- package/build/es2015/plattar-ar-adapter.min.js +1 -1
- package/build/es2019/plattar-ar-adapter.js +319 -93
- package/build/es2019/plattar-ar-adapter.min.js +1 -1
- package/dist/embed/controllers/configurator-controller.d.ts +8 -0
- package/dist/embed/controllers/configurator-controller.js +95 -48
- package/dist/embed/controllers/vto-controller.d.ts +8 -0
- package/dist/embed/controllers/vto-controller.js +85 -37
- package/dist/util/configurator-state.d.ts +41 -0
- package/dist/util/configurator-state.js +136 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -12,6 +12,14 @@ export declare class ConfiguratorController extends PlattarController {
|
|
|
12
12
|
startQRCode(options: any): Promise<HTMLElement>;
|
|
13
13
|
startRenderer(): Promise<HTMLElement>;
|
|
14
14
|
initAR(): Promise<LauncherAR>;
|
|
15
|
+
/**
|
|
16
|
+
* Private Function - This launches the Static/Inherited AR Mode
|
|
17
|
+
*/
|
|
18
|
+
private _InitARInherited;
|
|
19
|
+
/**
|
|
20
|
+
* Private Function - This launches the Dynamic/Generated AR Mode
|
|
21
|
+
*/
|
|
22
|
+
private _InitARGenerated;
|
|
15
23
|
removeRenderer(): boolean;
|
|
16
24
|
get element(): HTMLElement | null;
|
|
17
25
|
}
|
|
@@ -4,6 +4,9 @@ exports.ConfiguratorController = void 0;
|
|
|
4
4
|
const plattar_api_1 = require("@plattar/plattar-api");
|
|
5
5
|
const plattar_services_1 = require("@plattar/plattar-services");
|
|
6
6
|
const raw_ar_1 = require("../../ar/raw-ar");
|
|
7
|
+
const scene_ar_1 = require("../../ar/scene-ar");
|
|
8
|
+
const scene_product_ar_1 = require("../../ar/scene-product-ar");
|
|
9
|
+
const configurator_state_1 = require("../../util/configurator-state");
|
|
7
10
|
const util_1 = require("../../util/util");
|
|
8
11
|
const plattar_controller_1 = require("./plattar-controller");
|
|
9
12
|
/**
|
|
@@ -109,59 +112,103 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
|
|
|
109
112
|
if (!util_1.Util.canAugment()) {
|
|
110
113
|
return reject(new Error("ConfiguratorController.initAR() - cannot proceed as AR not available in context"));
|
|
111
114
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
const arMode = this.getAttribute("ar-mode") || "generated";
|
|
116
|
+
switch (arMode.toLowerCase()) {
|
|
117
|
+
case "inherited":
|
|
118
|
+
this._InitARInherited(accept, reject);
|
|
119
|
+
return;
|
|
120
|
+
case "generated":
|
|
121
|
+
default:
|
|
122
|
+
this._InitARGenerated(accept, reject);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Private Function - This launches the Static/Inherited AR Mode
|
|
128
|
+
*/
|
|
129
|
+
_InitARInherited(accept, reject) {
|
|
130
|
+
const sceneID = this.getAttribute("scene-id");
|
|
131
|
+
const configState = this.getAttribute("config-state");
|
|
132
|
+
// use config-state if its available
|
|
133
|
+
if (sceneID && configState) {
|
|
134
|
+
const state = configurator_state_1.ConfiguratorState.decode(configState);
|
|
135
|
+
const first = state.first();
|
|
136
|
+
if (first) {
|
|
137
|
+
const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
|
|
138
|
+
sceneProductAR.init().then(accept).catch(reject);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
|
|
142
|
+
}
|
|
143
|
+
// otherwise fallback to using scene
|
|
144
|
+
if (sceneID) {
|
|
145
|
+
configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
|
|
146
|
+
const first = state.first();
|
|
147
|
+
if (first) {
|
|
148
|
+
const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
|
|
149
|
+
return sceneProductAR.init().then(accept).catch(reject);
|
|
120
150
|
}
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
151
|
+
return reject(new Error("ConfiguratorController.initAR() - invalid Scene does not have any product states"));
|
|
152
|
+
}).catch(reject);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Private Function - This launches the Dynamic/Generated AR Mode
|
|
159
|
+
*/
|
|
160
|
+
_InitARGenerated(accept, reject) {
|
|
161
|
+
// if scene ID is available and the state is a configurator viewer
|
|
162
|
+
// we can use the real-time configurator state to launch the AR view
|
|
163
|
+
const viewer = this.element;
|
|
164
|
+
const sceneID = this.getAttribute("scene-id");
|
|
165
|
+
if (viewer && sceneID && viewer.messenger) {
|
|
166
|
+
let output = "glb";
|
|
167
|
+
if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
|
|
168
|
+
output = "usdz";
|
|
125
169
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
configurator.output = "usdz";
|
|
144
|
-
}
|
|
145
|
-
if (util_1.Util.canSceneViewer()) {
|
|
146
|
-
configurator.output = "glb";
|
|
147
|
-
}
|
|
148
|
-
const server = this.getAttribute("server") || "production";
|
|
149
|
-
configurator.server = server;
|
|
150
|
-
return configurator.get().then((result) => {
|
|
151
|
-
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
152
|
-
rawAR.init().then(accept).catch(reject);
|
|
153
|
-
}).catch(reject);
|
|
154
|
-
}
|
|
155
|
-
return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
|
|
156
|
-
}
|
|
157
|
-
return reject(new Error("ConfiguratorController.initAR() - invalid config-state for configurator"));
|
|
170
|
+
viewer.messenger.getARFile(output).then((result) => {
|
|
171
|
+
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
172
|
+
return rawAR.init().then(accept).catch(reject);
|
|
173
|
+
}).catch(reject);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const configState = this.getAttribute("config-state");
|
|
177
|
+
// otherwise scene ID is available to the viewer is not launched
|
|
178
|
+
// we can use the static configuration state to launch the AR view
|
|
179
|
+
if (sceneID && configState) {
|
|
180
|
+
const state = configurator_state_1.ConfiguratorState.decode(configState);
|
|
181
|
+
if (state.length > 0) {
|
|
182
|
+
const server = this.getAttribute("server") || "production";
|
|
183
|
+
const configurator = new plattar_services_1.Configurator();
|
|
184
|
+
configurator.server = server;
|
|
185
|
+
if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
|
|
186
|
+
configurator.output = "usdz";
|
|
158
187
|
}
|
|
159
|
-
|
|
160
|
-
|
|
188
|
+
if (util_1.Util.canSceneViewer()) {
|
|
189
|
+
configurator.output = "glb";
|
|
161
190
|
}
|
|
191
|
+
state.forEach((productState) => {
|
|
192
|
+
if (productState.meta_data.augment === true) {
|
|
193
|
+
configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
configurator.get().then((result) => {
|
|
197
|
+
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
198
|
+
rawAR.init().then(accept).catch(reject);
|
|
199
|
+
}).catch(reject);
|
|
200
|
+
return;
|
|
162
201
|
}
|
|
163
|
-
return reject(new Error("ConfiguratorController.initAR() -
|
|
164
|
-
}
|
|
202
|
+
return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
|
|
203
|
+
}
|
|
204
|
+
// otherwise no config-state or viewer is active
|
|
205
|
+
// fallback to using default SceneAR implementation
|
|
206
|
+
if (sceneID) {
|
|
207
|
+
const sceneAR = new scene_ar_1.SceneAR(sceneID);
|
|
208
|
+
sceneAR.init().then(accept).catch(reject);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
|
|
165
212
|
}
|
|
166
213
|
removeRenderer() {
|
|
167
214
|
if (this._element) {
|
|
@@ -12,6 +12,14 @@ export declare class VTOController extends PlattarController {
|
|
|
12
12
|
startQRCode(options: any): Promise<HTMLElement>;
|
|
13
13
|
startRenderer(): Promise<HTMLElement>;
|
|
14
14
|
initAR(): Promise<LauncherAR>;
|
|
15
|
+
/**
|
|
16
|
+
* Private Function - This launches the Static/Inherited AR Mode
|
|
17
|
+
*/
|
|
18
|
+
private _InitARInherited;
|
|
19
|
+
/**
|
|
20
|
+
* Private Function - This launches the Dynamic/Generated AR Mode
|
|
21
|
+
*/
|
|
22
|
+
private _InitARGenerated;
|
|
15
23
|
removeRenderer(): boolean;
|
|
16
24
|
get element(): HTMLElement | null;
|
|
17
25
|
}
|
|
@@ -113,46 +113,94 @@ class VTOController extends plattar_controller_1.PlattarController {
|
|
|
113
113
|
if (!(util_1.Util.isSafari() || util_1.Util.isChromeOnIOS())) {
|
|
114
114
|
return reject(new Error("VTOController.initAR() - cannot proceed as VTO AR only available on IOS Mobile devices"));
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}).catch(reject);
|
|
116
|
+
const arMode = this.getAttribute("ar-mode") || "generated";
|
|
117
|
+
switch (arMode.toLowerCase()) {
|
|
118
|
+
case "inherited":
|
|
119
|
+
this._InitARInherited(accept, reject);
|
|
120
|
+
return;
|
|
121
|
+
case "generated":
|
|
122
|
+
default:
|
|
123
|
+
this._InitARGenerated(accept, reject);
|
|
125
124
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
143
|
-
rawAR.init().then(accept).catch(reject);
|
|
144
|
-
}).catch(reject);
|
|
145
|
-
}
|
|
146
|
-
return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Private Function - This launches the Static/Inherited AR Mode
|
|
129
|
+
*/
|
|
130
|
+
_InitARInherited(accept, reject) {
|
|
131
|
+
const sceneID = this.getAttribute("scene-id");
|
|
132
|
+
const configState = this.getAttribute("config-state");
|
|
133
|
+
// use config-state if its available
|
|
134
|
+
if (sceneID && configState) {
|
|
135
|
+
const state = __1.ConfiguratorState.decode(configState);
|
|
136
|
+
const first = state.first();
|
|
137
|
+
if (first) {
|
|
138
|
+
const sceneProductAR = new __1.SceneProductAR(first.scene_product_id, first.product_variation_id);
|
|
139
|
+
sceneProductAR.init().then(accept).catch(reject);
|
|
140
|
+
return;
|
|
147
141
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
142
|
+
return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
|
|
143
|
+
}
|
|
144
|
+
// otherwise fallback to using scene
|
|
145
|
+
if (sceneID) {
|
|
146
|
+
__1.ConfiguratorState.decodeScene(sceneID).then((state) => {
|
|
147
|
+
const first = state.first();
|
|
148
|
+
if (first) {
|
|
149
|
+
const sceneProductAR = new __1.SceneProductAR(first.scene_product_id, first.product_variation_id);
|
|
150
|
+
return sceneProductAR.init().then(accept).catch(reject);
|
|
151
|
+
}
|
|
152
|
+
return reject(new Error("VTOController.initAR() - invalid Scene does not have any product states"));
|
|
153
|
+
}).catch(reject);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Private Function - This launches the Dynamic/Generated AR Mode
|
|
160
|
+
*/
|
|
161
|
+
_InitARGenerated(accept, reject) {
|
|
162
|
+
// if scene ID is available and the state is a configurator viewer
|
|
163
|
+
// we can use the real-time configurator state to launch the AR view
|
|
164
|
+
const viewer = this.element;
|
|
165
|
+
const sceneID = this.getAttribute("scene-id");
|
|
166
|
+
if (viewer && sceneID && viewer.messenger) {
|
|
167
|
+
viewer.messenger.getARFile("vto").then((result) => {
|
|
168
|
+
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
169
|
+
return rawAR.init().then(accept).catch(reject);
|
|
170
|
+
}).catch(reject);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const configState = this.getAttribute("config-state");
|
|
174
|
+
// otherwise scene ID is available to the viewer is not launched
|
|
175
|
+
// we can use the static configuration state to launch the AR view
|
|
176
|
+
if (sceneID && configState) {
|
|
177
|
+
const state = __1.ConfiguratorState.decode(configState);
|
|
178
|
+
if (state.length > 0) {
|
|
179
|
+
const server = this.getAttribute("server") || "production";
|
|
180
|
+
const configurator = new plattar_services_1.Configurator();
|
|
181
|
+
configurator.server = server;
|
|
182
|
+
configurator.output = "vto";
|
|
183
|
+
state.forEach((productState) => {
|
|
184
|
+
if (productState.meta_data.augment === true) {
|
|
185
|
+
configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
configurator.get().then((result) => {
|
|
189
|
+
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
190
|
+
rawAR.init().then(accept).catch(reject);
|
|
191
|
+
}).catch(reject);
|
|
192
|
+
return;
|
|
153
193
|
}
|
|
154
|
-
return reject(new Error("VTOController.initAR() -
|
|
155
|
-
}
|
|
194
|
+
return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
|
|
195
|
+
}
|
|
196
|
+
// otherwise no config-state or viewer is active
|
|
197
|
+
// fallback to using default SceneAR implementation
|
|
198
|
+
if (sceneID) {
|
|
199
|
+
const sceneAR = new __1.SceneAR(sceneID);
|
|
200
|
+
sceneAR.init().then(accept).catch(reject);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
|
|
156
204
|
}
|
|
157
205
|
removeRenderer() {
|
|
158
206
|
if (this._element) {
|
|
@@ -8,6 +8,14 @@ export interface SceneProductData {
|
|
|
8
8
|
export declare class ConfiguratorState {
|
|
9
9
|
private readonly _state;
|
|
10
10
|
constructor(state?: string | null | undefined);
|
|
11
|
+
/**
|
|
12
|
+
* Adds a new Scene Product/Variation combo with meta-data into the Configurator State
|
|
13
|
+
*
|
|
14
|
+
* @param sceneProductID - The Scene Product ID to be used (as defined in Plattar CMS)
|
|
15
|
+
* @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
|
|
16
|
+
* @param metaData - Arbitrary meta-data that can be used against certain operaions
|
|
17
|
+
*/
|
|
18
|
+
setSceneProduct(sceneProductID: string, productVariationID: string, metaData?: any | null | undefined): void;
|
|
11
19
|
/**
|
|
12
20
|
* Adds a new Scene Product/Variation combo with meta-data into the Configurator State
|
|
13
21
|
*
|
|
@@ -16,11 +24,44 @@ export declare class ConfiguratorState {
|
|
|
16
24
|
* @param metaData - Arbitrary meta-data that can be used against certain operaions
|
|
17
25
|
*/
|
|
18
26
|
addSceneProduct(sceneProductID: string, productVariationID: string, metaData?: any | null | undefined): void;
|
|
27
|
+
/**
|
|
28
|
+
* Search and return the data index reference for the provided Scene Product ID
|
|
29
|
+
* if not found, will return null
|
|
30
|
+
* @param sceneProductID
|
|
31
|
+
*/
|
|
32
|
+
findSceneProductIndex(sceneProductID: string): any[] | null;
|
|
33
|
+
/**
|
|
34
|
+
* Search and return the data for the provided Scene Product ID
|
|
35
|
+
* if not found, will return null
|
|
36
|
+
* @param sceneProductID
|
|
37
|
+
*/
|
|
38
|
+
findSceneProduct(sceneProductID: string): SceneProductData | null;
|
|
19
39
|
/**
|
|
20
40
|
* Iterate over the internal state data
|
|
21
41
|
*/
|
|
22
42
|
forEach(callback: (data: SceneProductData) => void): void;
|
|
43
|
+
/**
|
|
44
|
+
* @returns Returns the first reference of data in the stack, otherwise returns null
|
|
45
|
+
*/
|
|
46
|
+
first(): SceneProductData | null;
|
|
23
47
|
get length(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Decodes and returns an instance of ConfiguratorState from a previously
|
|
50
|
+
* encoded state
|
|
51
|
+
* @param state - The previously encoded state as a Base64 String
|
|
52
|
+
* @returns - ConfiguratorState instance
|
|
53
|
+
*/
|
|
24
54
|
static decode(state: string): ConfiguratorState;
|
|
55
|
+
/**
|
|
56
|
+
* Generates a new ConfiguratorState instance from all SceneProducts and default
|
|
57
|
+
* variations from the provided Scene ID
|
|
58
|
+
* @param sceneID - the Scene ID to generate
|
|
59
|
+
* @returns - Promise that resolves into a ConfiguratorState instance
|
|
60
|
+
*/
|
|
61
|
+
static decodeScene(sceneID?: string | null | undefined): Promise<ConfiguratorState>;
|
|
62
|
+
/**
|
|
63
|
+
* Encode and return the internal ConfiguratorState as a Base64 String
|
|
64
|
+
* @returns - Base64 String
|
|
65
|
+
*/
|
|
25
66
|
encode(): string;
|
|
26
67
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConfiguratorState = void 0;
|
|
4
|
+
const plattar_api_1 = require("@plattar/plattar-api");
|
|
4
5
|
class ConfiguratorState {
|
|
5
6
|
constructor(state = null) {
|
|
6
7
|
const defaultState = {
|
|
@@ -30,6 +31,16 @@ class ConfiguratorState {
|
|
|
30
31
|
}
|
|
31
32
|
this._state = defaultState;
|
|
32
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Adds a new Scene Product/Variation combo with meta-data into the Configurator State
|
|
36
|
+
*
|
|
37
|
+
* @param sceneProductID - The Scene Product ID to be used (as defined in Plattar CMS)
|
|
38
|
+
* @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
|
|
39
|
+
* @param metaData - Arbitrary meta-data that can be used against certain operaions
|
|
40
|
+
*/
|
|
41
|
+
setSceneProduct(sceneProductID, productVariationID, metaData = null) {
|
|
42
|
+
this.addSceneProduct(sceneProductID, productVariationID, metaData);
|
|
43
|
+
}
|
|
33
44
|
/**
|
|
34
45
|
* Adds a new Scene Product/Variation combo with meta-data into the Configurator State
|
|
35
46
|
*
|
|
@@ -41,15 +52,63 @@ class ConfiguratorState {
|
|
|
41
52
|
if (sceneProductID && productVariationID) {
|
|
42
53
|
const states = this._state.states;
|
|
43
54
|
const meta = this._state.meta;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
let newData = null;
|
|
56
|
+
const existingData = this.findSceneProductIndex(sceneProductID);
|
|
57
|
+
if (existingData) {
|
|
58
|
+
newData = existingData;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
newData = [];
|
|
62
|
+
// push the new data into the stack
|
|
63
|
+
states.push(newData);
|
|
64
|
+
}
|
|
65
|
+
newData[meta.scene_product_index] = sceneProductID;
|
|
66
|
+
newData[meta.product_variation_index] = productVariationID;
|
|
47
67
|
if (metaData) {
|
|
48
|
-
newData
|
|
68
|
+
newData[meta.meta_index] = metaData;
|
|
49
69
|
}
|
|
50
|
-
states.push(newData);
|
|
51
70
|
}
|
|
52
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Search and return the data index reference for the provided Scene Product ID
|
|
74
|
+
* if not found, will return null
|
|
75
|
+
* @param sceneProductID
|
|
76
|
+
*/
|
|
77
|
+
findSceneProductIndex(sceneProductID) {
|
|
78
|
+
const states = this._state.states;
|
|
79
|
+
if (states.length > 0) {
|
|
80
|
+
const meta = this._state.meta;
|
|
81
|
+
const found = states.find((productState) => {
|
|
82
|
+
return productState[meta.scene_product_index] === sceneProductID;
|
|
83
|
+
});
|
|
84
|
+
return found ? found : null;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Search and return the data for the provided Scene Product ID
|
|
90
|
+
* if not found, will return null
|
|
91
|
+
* @param sceneProductID
|
|
92
|
+
*/
|
|
93
|
+
findSceneProduct(sceneProductID) {
|
|
94
|
+
const found = this.findSceneProductIndex(sceneProductID);
|
|
95
|
+
if (found) {
|
|
96
|
+
const meta = this._state.meta;
|
|
97
|
+
const data = {
|
|
98
|
+
scene_product_id: found[meta.scene_product_index],
|
|
99
|
+
product_variation_id: found[meta.product_variation_index],
|
|
100
|
+
meta_data: {
|
|
101
|
+
augment: true
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
// include the meta-data
|
|
105
|
+
if (found.length === 3) {
|
|
106
|
+
data.meta_data.augment = found[meta.meta_index].augment || true;
|
|
107
|
+
}
|
|
108
|
+
return data;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
53
112
|
/**
|
|
54
113
|
* Iterate over the internal state data
|
|
55
114
|
*/
|
|
@@ -79,12 +138,84 @@ class ConfiguratorState {
|
|
|
79
138
|
});
|
|
80
139
|
}
|
|
81
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* @returns Returns the first reference of data in the stack, otherwise returns null
|
|
143
|
+
*/
|
|
144
|
+
first() {
|
|
145
|
+
const states = this._state.states;
|
|
146
|
+
if (states.length > 0) {
|
|
147
|
+
const meta = this._state.meta;
|
|
148
|
+
const found = states.find((productState) => {
|
|
149
|
+
const check = productState[meta.scene_product_index];
|
|
150
|
+
// ensure the data contains valid elements
|
|
151
|
+
return check !== null && check !== undefined;
|
|
152
|
+
});
|
|
153
|
+
if (!found) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const data = {
|
|
157
|
+
scene_product_id: found[meta.scene_product_index],
|
|
158
|
+
product_variation_id: found[meta.product_variation_index],
|
|
159
|
+
meta_data: {
|
|
160
|
+
augment: true
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
// include the meta-data
|
|
164
|
+
if (found.length === 3) {
|
|
165
|
+
data.meta_data.augment = found[meta.meta_index].augment || true;
|
|
166
|
+
}
|
|
167
|
+
return data;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
82
171
|
get length() {
|
|
83
172
|
return this._state.states.length;
|
|
84
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Decodes and returns an instance of ConfiguratorState from a previously
|
|
176
|
+
* encoded state
|
|
177
|
+
* @param state - The previously encoded state as a Base64 String
|
|
178
|
+
* @returns - ConfiguratorState instance
|
|
179
|
+
*/
|
|
85
180
|
static decode(state) {
|
|
86
181
|
return new ConfiguratorState(state);
|
|
87
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Generates a new ConfiguratorState instance from all SceneProducts and default
|
|
185
|
+
* variations from the provided Scene ID
|
|
186
|
+
* @param sceneID - the Scene ID to generate
|
|
187
|
+
* @returns - Promise that resolves into a ConfiguratorState instance
|
|
188
|
+
*/
|
|
189
|
+
static decodeScene(sceneID = null) {
|
|
190
|
+
return new Promise((accept, reject) => {
|
|
191
|
+
const configState = new ConfiguratorState();
|
|
192
|
+
if (!sceneID) {
|
|
193
|
+
return reject(new Error("ConfiguratorState.decodeScene(sceneID) - sceneID must be defined"));
|
|
194
|
+
}
|
|
195
|
+
const scene = new plattar_api_1.Scene(sceneID);
|
|
196
|
+
scene.include(plattar_api_1.SceneProduct);
|
|
197
|
+
scene.include(plattar_api_1.SceneProduct.include(plattar_api_1.Product));
|
|
198
|
+
scene.get().then((scene) => {
|
|
199
|
+
const sceneProducts = scene.relationships.filter(plattar_api_1.SceneProduct);
|
|
200
|
+
// nothing to do if no AR components can be found
|
|
201
|
+
if (sceneProducts.length <= 0) {
|
|
202
|
+
return accept(configState);
|
|
203
|
+
}
|
|
204
|
+
// add out scene models
|
|
205
|
+
sceneProducts.forEach((sceneProduct) => {
|
|
206
|
+
const product = sceneProduct.relationships.find(plattar_api_1.Product);
|
|
207
|
+
if (product && product.attributes.product_variation_id) {
|
|
208
|
+
configState.setSceneProduct(sceneProduct.id, product.attributes.product_variation_id);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
accept(configState);
|
|
212
|
+
}).catch(reject);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Encode and return the internal ConfiguratorState as a Base64 String
|
|
217
|
+
* @returns - Base64 String
|
|
218
|
+
*/
|
|
88
219
|
encode() {
|
|
89
220
|
return btoa(JSON.stringify(this._state));
|
|
90
221
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.123.
|
|
1
|
+
declare const _default: "1.123.7";
|
|
2
2
|
export default _default;
|
package/dist/version.js
CHANGED