@plattar/plattar-ar-adapter 1.123.6 → 1.128.1

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.
@@ -628,6 +628,9 @@ exports.ConfiguratorController = void 0;
628
628
  const plattar_api_1 = require("@plattar/plattar-api");
629
629
  const plattar_services_1 = require("@plattar/plattar-services");
630
630
  const raw_ar_1 = require("../../ar/raw-ar");
631
+ const scene_ar_1 = require("../../ar/scene-ar");
632
+ const scene_product_ar_1 = require("../../ar/scene-product-ar");
633
+ const configurator_state_1 = require("../../util/configurator-state");
631
634
  const util_1 = require("../../util/util");
632
635
  const plattar_controller_1 = require("./plattar-controller");
633
636
  /**
@@ -733,59 +736,103 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
733
736
  if (!util_1.Util.canAugment()) {
734
737
  return reject(new Error("ConfiguratorController.initAR() - cannot proceed as AR not available in context"));
735
738
  }
736
- // if scene ID is available and the state is a configurator viewer
737
- // we can use the real-time configurator state to launch the AR view
738
- const viewer = this.element;
739
- const sceneID = this.getAttribute("scene-id");
740
- if (viewer && sceneID) {
741
- let output = "glb";
742
- if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
743
- output = "usdz";
739
+ const arMode = this.getAttribute("ar-mode") || "generated";
740
+ switch (arMode.toLowerCase()) {
741
+ case "inherited":
742
+ this._InitARInherited(accept, reject);
743
+ return;
744
+ case "generated":
745
+ default:
746
+ this._InitARGenerated(accept, reject);
747
+ }
748
+ });
749
+ }
750
+ /**
751
+ * Private Function - This launches the Static/Inherited AR Mode
752
+ */
753
+ _InitARInherited(accept, reject) {
754
+ const sceneID = this.getAttribute("scene-id");
755
+ const configState = this.getAttribute("config-state");
756
+ // use config-state if its available
757
+ if (sceneID && configState) {
758
+ const state = configurator_state_1.ConfiguratorState.decode(configState);
759
+ const first = state.first();
760
+ if (first) {
761
+ const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
762
+ sceneProductAR.init().then(accept).catch(reject);
763
+ return;
764
+ }
765
+ return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
766
+ }
767
+ // otherwise fallback to using scene
768
+ if (sceneID) {
769
+ configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
770
+ const first = state.first();
771
+ if (first) {
772
+ const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
773
+ return sceneProductAR.init().then(accept).catch(reject);
744
774
  }
745
- return viewer.messenger.getARFile(output).then((result) => {
746
- const rawAR = new raw_ar_1.RawAR(result.filename);
747
- return rawAR.init().then(accept).catch(reject);
748
- }).catch(reject);
775
+ return reject(new Error("ConfiguratorController.initAR() - invalid Scene does not have any product states"));
776
+ }).catch(reject);
777
+ return;
778
+ }
779
+ return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
780
+ }
781
+ /**
782
+ * Private Function - This launches the Dynamic/Generated AR Mode
783
+ */
784
+ _InitARGenerated(accept, reject) {
785
+ // if scene ID is available and the state is a configurator viewer
786
+ // we can use the real-time configurator state to launch the AR view
787
+ const viewer = this.element;
788
+ const sceneID = this.getAttribute("scene-id");
789
+ if (viewer && sceneID && viewer.messenger) {
790
+ let output = "glb";
791
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
792
+ output = "usdz";
749
793
  }
750
- const configState = this.getAttribute("config-state");
751
- // otherwise scene ID is available to the viewer is not launched
752
- // we can use the static configuration state to launch the AR view
753
- if (sceneID && configState) {
754
- try {
755
- const decodedb64State = atob(configState);
756
- const state = JSON.parse(decodedb64State);
757
- if (state.meta) {
758
- const sceneProductIndex = state.meta.scene_product_index || 0;
759
- const variationIndex = state.meta.product_variation_index || 1;
760
- const states = state.states || [];
761
- if (states.length > 0) {
762
- const configurator = new plattar_services_1.Configurator();
763
- states.forEach((productState) => {
764
- configurator.addSceneProduct(productState[sceneProductIndex], productState[variationIndex]);
765
- });
766
- if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
767
- configurator.output = "usdz";
768
- }
769
- if (util_1.Util.canSceneViewer()) {
770
- configurator.output = "glb";
771
- }
772
- const server = this.getAttribute("server") || "production";
773
- configurator.server = server;
774
- return configurator.get().then((result) => {
775
- const rawAR = new raw_ar_1.RawAR(result.filename);
776
- rawAR.init().then(accept).catch(reject);
777
- }).catch(reject);
778
- }
779
- return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
780
- }
781
- return reject(new Error("ConfiguratorController.initAR() - invalid config-state for configurator"));
794
+ viewer.messenger.getARFile(output).then((result) => {
795
+ const rawAR = new raw_ar_1.RawAR(result.filename);
796
+ return rawAR.init().then(accept).catch(reject);
797
+ }).catch(reject);
798
+ return;
799
+ }
800
+ const configState = this.getAttribute("config-state");
801
+ // otherwise scene ID is available to the viewer is not launched
802
+ // we can use the static configuration state to launch the AR view
803
+ if (sceneID && configState) {
804
+ const state = configurator_state_1.ConfiguratorState.decode(configState);
805
+ if (state.length > 0) {
806
+ const server = this.getAttribute("server") || "production";
807
+ const configurator = new plattar_services_1.Configurator();
808
+ configurator.server = server;
809
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
810
+ configurator.output = "usdz";
782
811
  }
783
- catch (err) {
784
- return reject(err);
812
+ if (util_1.Util.canSceneViewer()) {
813
+ configurator.output = "glb";
785
814
  }
815
+ state.forEach((productState) => {
816
+ if (productState.meta_data.augment === true) {
817
+ configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
818
+ }
819
+ });
820
+ configurator.get().then((result) => {
821
+ const rawAR = new raw_ar_1.RawAR(result.filename);
822
+ rawAR.init().then(accept).catch(reject);
823
+ }).catch(reject);
824
+ return;
786
825
  }
787
- return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
788
- });
826
+ return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
827
+ }
828
+ // otherwise no config-state or viewer is active
829
+ // fallback to using default SceneAR implementation
830
+ if (sceneID) {
831
+ const sceneAR = new scene_ar_1.SceneAR(sceneID);
832
+ sceneAR.init().then(accept).catch(reject);
833
+ return;
834
+ }
835
+ return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
789
836
  }
790
837
  removeRenderer() {
791
838
  if (this._element) {
@@ -801,7 +848,7 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
801
848
  }
802
849
  exports.ConfiguratorController = ConfiguratorController;
803
850
 
804
- },{"../../ar/raw-ar":4,"../../util/util":15,"./plattar-controller":8,"@plattar/plattar-api":42,"@plattar/plattar-services":113}],8:[function(require,module,exports){
851
+ },{"../../ar/raw-ar":4,"../../ar/scene-ar":5,"../../ar/scene-product-ar":6,"../../util/configurator-state":14,"../../util/util":15,"./plattar-controller":8,"@plattar/plattar-api":42,"@plattar/plattar-services":113}],8:[function(require,module,exports){
805
852
  "use strict";
806
853
  Object.defineProperty(exports, "__esModule", { value: true });
807
854
  exports.PlattarController = exports.ControllerState = void 0;
@@ -926,10 +973,14 @@ class ProductController extends plattar_controller_1.PlattarController {
926
973
  }
927
974
  // optional attributes
928
975
  const variationID = this.getAttribute("variation-id");
976
+ const showAR = this.getAttribute("show-ar");
929
977
  let dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
930
978
  if (variationID) {
931
979
  dst += "&variation_id=" + variationID;
932
980
  }
981
+ if (showAR) {
982
+ dst += "&show_ar=" + showAR;
983
+ }
933
984
  viewer.setAttribute("url", opt.url || dst);
934
985
  viewer.onload = () => {
935
986
  return accept(viewer);
@@ -960,9 +1011,13 @@ class ProductController extends plattar_controller_1.PlattarController {
960
1011
  viewer.setAttribute("product-id", productID);
961
1012
  // optional attributes
962
1013
  const variationID = this.getAttribute("variation-id");
1014
+ const showAR = this.getAttribute("show-ar");
963
1015
  if (variationID) {
964
1016
  viewer.setAttribute("variation-id", variationID);
965
1017
  }
1018
+ if (showAR) {
1019
+ viewer.setAttribute("show-ar", showAR);
1020
+ }
966
1021
  viewer.onload = () => {
967
1022
  return accept(viewer);
968
1023
  };
@@ -1009,6 +1064,7 @@ exports.ViewerController = void 0;
1009
1064
  const plattar_api_1 = require("@plattar/plattar-api");
1010
1065
  const product_ar_1 = require("../../ar/product-ar");
1011
1066
  const scene_product_ar_1 = require("../../ar/scene-product-ar");
1067
+ const configurator_state_1 = require("../../util/configurator-state");
1012
1068
  const util_1 = require("../../util/util");
1013
1069
  const plattar_controller_1 = require("./plattar-controller");
1014
1070
  /**
@@ -1067,12 +1123,16 @@ class ViewerController extends plattar_controller_1.PlattarController {
1067
1123
  // optional attributes
1068
1124
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
1069
1125
  const variationID = this.getAttribute("variation-id");
1126
+ const showAR = this.getAttribute("show-ar");
1070
1127
  if (productID) {
1071
1128
  dst += "&productId=" + productID;
1072
1129
  }
1073
1130
  if (variationID) {
1074
1131
  dst += "&variationId=" + variationID;
1075
1132
  }
1133
+ if (showAR) {
1134
+ dst += "&show_ar=" + showAR;
1135
+ }
1076
1136
  viewer.setAttribute("url", opt.url || dst);
1077
1137
  viewer.onload = () => {
1078
1138
  return accept(viewer);
@@ -1104,12 +1164,16 @@ class ViewerController extends plattar_controller_1.PlattarController {
1104
1164
  // optional attributes
1105
1165
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
1106
1166
  const variationID = this.getAttribute("variation-id");
1167
+ const showAR = this.getAttribute("show-ar");
1107
1168
  if (productID) {
1108
1169
  viewer.setAttribute("product-id", productID);
1109
1170
  }
1110
1171
  if (variationID) {
1111
1172
  viewer.setAttribute("variation-id", variationID);
1112
1173
  }
1174
+ if (showAR) {
1175
+ viewer.setAttribute("show-ar", showAR);
1176
+ }
1113
1177
  viewer.onload = () => {
1114
1178
  return accept(viewer);
1115
1179
  };
@@ -1141,11 +1205,18 @@ class ViewerController extends plattar_controller_1.PlattarController {
1141
1205
  return product.init().then(accept).catch(reject);
1142
1206
  }
1143
1207
  const sceneID = this.getAttribute("scene-id");
1144
- // otherwise, scene was set so use SceneAR
1208
+ // use the first default product-variation id if available
1145
1209
  if (sceneID) {
1146
- return reject(new Error("ViewerController.initAR() - AR mode for scene-id not yet supported, use product-id or scene-product-id"));
1210
+ return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
1211
+ const first = state.first();
1212
+ if (first) {
1213
+ const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
1214
+ return sceneProductAR.init().then(accept).catch(reject);
1215
+ }
1216
+ return reject(new Error("ViewerController.initAR() - your scene does not contain any valid products"));
1217
+ }).catch(reject);
1147
1218
  }
1148
- return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use product-id or scene-product-id as a minimum"));
1219
+ return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1149
1220
  });
1150
1221
  }
1151
1222
  removeRenderer() {
@@ -1162,7 +1233,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
1162
1233
  }
1163
1234
  exports.ViewerController = ViewerController;
1164
1235
 
1165
- },{"../../ar/product-ar":3,"../../ar/scene-product-ar":6,"../../util/util":15,"./plattar-controller":8,"@plattar/plattar-api":42}],11:[function(require,module,exports){
1236
+ },{"../../ar/product-ar":3,"../../ar/scene-product-ar":6,"../../util/configurator-state":14,"../../util/util":15,"./plattar-controller":8,"@plattar/plattar-api":42}],11:[function(require,module,exports){
1166
1237
  "use strict";
1167
1238
  Object.defineProperty(exports, "__esModule", { value: true });
1168
1239
  exports.VTOController = void 0;
@@ -1278,46 +1349,94 @@ class VTOController extends plattar_controller_1.PlattarController {
1278
1349
  if (!(util_1.Util.isSafari() || util_1.Util.isChromeOnIOS())) {
1279
1350
  return reject(new Error("VTOController.initAR() - cannot proceed as VTO AR only available on IOS Mobile devices"));
1280
1351
  }
1281
- // if scene ID is available and the state is a configurator viewer
1282
- // we can use the real-time configurator state to launch the AR view
1283
- const viewer = this.element;
1284
- const sceneID = this.getAttribute("scene-id");
1285
- if (viewer && sceneID) {
1286
- return viewer.messenger.getARFile("vto").then((result) => {
1287
- const rawAR = new raw_ar_1.RawAR(result.filename);
1288
- return rawAR.init().then(accept).catch(reject);
1289
- }).catch(reject);
1352
+ const arMode = this.getAttribute("ar-mode") || "generated";
1353
+ switch (arMode.toLowerCase()) {
1354
+ case "inherited":
1355
+ this._InitARInherited(accept, reject);
1356
+ return;
1357
+ case "generated":
1358
+ default:
1359
+ this._InitARGenerated(accept, reject);
1290
1360
  }
1291
- const configState = this.getAttribute("config-state");
1292
- // otherwise scene ID is available to the viewer is not launched
1293
- // we can use the static configuration state to launch the AR view
1294
- if (sceneID && configState) {
1295
- const state = __1.ConfiguratorState.decode(configState);
1296
- if (state.length > 0) {
1297
- const server = this.getAttribute("server") || "production";
1298
- const configurator = new plattar_services_1.Configurator();
1299
- configurator.server = server;
1300
- configurator.output = "vto";
1301
- state.forEach((productState) => {
1302
- if (productState.meta_data.augment === true) {
1303
- configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
1304
- }
1305
- });
1306
- return configurator.get().then((result) => {
1307
- const rawAR = new raw_ar_1.RawAR(result.filename);
1308
- rawAR.init().then(accept).catch(reject);
1309
- }).catch(reject);
1310
- }
1311
- return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
1361
+ });
1362
+ }
1363
+ /**
1364
+ * Private Function - This launches the Static/Inherited AR Mode
1365
+ */
1366
+ _InitARInherited(accept, reject) {
1367
+ const sceneID = this.getAttribute("scene-id");
1368
+ const configState = this.getAttribute("config-state");
1369
+ // use config-state if its available
1370
+ if (sceneID && configState) {
1371
+ const state = __1.ConfiguratorState.decode(configState);
1372
+ const first = state.first();
1373
+ if (first) {
1374
+ const sceneProductAR = new __1.SceneProductAR(first.scene_product_id, first.product_variation_id);
1375
+ sceneProductAR.init().then(accept).catch(reject);
1376
+ return;
1312
1377
  }
1313
- // otherwise no config-state or viewer is active
1314
- // fallback to using default SceneAR implementation
1315
- if (sceneID) {
1316
- const sceneAR = new __1.SceneAR(sceneID);
1317
- return sceneAR.init().then(accept).catch(reject);
1378
+ return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
1379
+ }
1380
+ // otherwise fallback to using scene
1381
+ if (sceneID) {
1382
+ __1.ConfiguratorState.decodeScene(sceneID).then((state) => {
1383
+ const first = state.first();
1384
+ if (first) {
1385
+ const sceneProductAR = new __1.SceneProductAR(first.scene_product_id, first.product_variation_id);
1386
+ return sceneProductAR.init().then(accept).catch(reject);
1387
+ }
1388
+ return reject(new Error("VTOController.initAR() - invalid Scene does not have any product states"));
1389
+ }).catch(reject);
1390
+ return;
1391
+ }
1392
+ return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1393
+ }
1394
+ /**
1395
+ * Private Function - This launches the Dynamic/Generated AR Mode
1396
+ */
1397
+ _InitARGenerated(accept, reject) {
1398
+ // if scene ID is available and the state is a configurator viewer
1399
+ // we can use the real-time configurator state to launch the AR view
1400
+ const viewer = this.element;
1401
+ const sceneID = this.getAttribute("scene-id");
1402
+ if (viewer && sceneID && viewer.messenger) {
1403
+ viewer.messenger.getARFile("vto").then((result) => {
1404
+ const rawAR = new raw_ar_1.RawAR(result.filename);
1405
+ return rawAR.init().then(accept).catch(reject);
1406
+ }).catch(reject);
1407
+ return;
1408
+ }
1409
+ const configState = this.getAttribute("config-state");
1410
+ // otherwise scene ID is available to the viewer is not launched
1411
+ // we can use the static configuration state to launch the AR view
1412
+ if (sceneID && configState) {
1413
+ const state = __1.ConfiguratorState.decode(configState);
1414
+ if (state.length > 0) {
1415
+ const server = this.getAttribute("server") || "production";
1416
+ const configurator = new plattar_services_1.Configurator();
1417
+ configurator.server = server;
1418
+ configurator.output = "vto";
1419
+ state.forEach((productState) => {
1420
+ if (productState.meta_data.augment === true) {
1421
+ configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
1422
+ }
1423
+ });
1424
+ configurator.get().then((result) => {
1425
+ const rawAR = new raw_ar_1.RawAR(result.filename);
1426
+ rawAR.init().then(accept).catch(reject);
1427
+ }).catch(reject);
1428
+ return;
1318
1429
  }
1319
- return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1320
- });
1430
+ return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
1431
+ }
1432
+ // otherwise no config-state or viewer is active
1433
+ // fallback to using default SceneAR implementation
1434
+ if (sceneID) {
1435
+ const sceneAR = new __1.SceneAR(sceneID);
1436
+ sceneAR.init().then(accept).catch(reject);
1437
+ return;
1438
+ }
1439
+ return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1321
1440
  }
1322
1441
  removeRenderer() {
1323
1442
  if (this._element) {
@@ -1495,7 +1614,11 @@ exports.default = PlattarEmbed;
1495
1614
  "use strict";
1496
1615
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1497
1616
  if (k2 === undefined) k2 = k;
1498
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1617
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1618
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1619
+ desc = { enumerable: true, get: function() { return m[k]; } };
1620
+ }
1621
+ Object.defineProperty(o, k2, desc);
1499
1622
  }) : (function(o, m, k, k2) {
1500
1623
  if (k2 === undefined) k2 = k;
1501
1624
  o[k2] = m[k];
@@ -1547,6 +1670,7 @@ console.log("using @plattar/plattar-ar-adapter v" + version_1.default);
1547
1670
  "use strict";
1548
1671
  Object.defineProperty(exports, "__esModule", { value: true });
1549
1672
  exports.ConfiguratorState = void 0;
1673
+ const plattar_api_1 = require("@plattar/plattar-api");
1550
1674
  class ConfiguratorState {
1551
1675
  constructor(state = null) {
1552
1676
  const defaultState = {
@@ -1576,6 +1700,16 @@ class ConfiguratorState {
1576
1700
  }
1577
1701
  this._state = defaultState;
1578
1702
  }
1703
+ /**
1704
+ * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
1705
+ *
1706
+ * @param sceneProductID - The Scene Product ID to be used (as defined in Plattar CMS)
1707
+ * @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
1708
+ * @param metaData - Arbitrary meta-data that can be used against certain operaions
1709
+ */
1710
+ setSceneProduct(sceneProductID, productVariationID, metaData = null) {
1711
+ this.addSceneProduct(sceneProductID, productVariationID, metaData);
1712
+ }
1579
1713
  /**
1580
1714
  * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
1581
1715
  *
@@ -1587,14 +1721,62 @@ class ConfiguratorState {
1587
1721
  if (sceneProductID && productVariationID) {
1588
1722
  const states = this._state.states;
1589
1723
  const meta = this._state.meta;
1590
- const newData = [];
1591
- newData.splice(meta.scene_product_index, 0, sceneProductID);
1592
- newData.splice(meta.product_variation_index, 0, productVariationID);
1724
+ let newData = null;
1725
+ const existingData = this.findSceneProductIndex(sceneProductID);
1726
+ if (existingData) {
1727
+ newData = existingData;
1728
+ }
1729
+ else {
1730
+ newData = [];
1731
+ // push the new data into the stack
1732
+ states.push(newData);
1733
+ }
1734
+ newData[meta.scene_product_index] = sceneProductID;
1735
+ newData[meta.product_variation_index] = productVariationID;
1593
1736
  if (metaData) {
1594
- newData.splice(meta.meta_index, 0, metaData);
1737
+ newData[meta.meta_index] = metaData;
1738
+ }
1739
+ }
1740
+ }
1741
+ /**
1742
+ * Search and return the data index reference for the provided Scene Product ID
1743
+ * if not found, will return null
1744
+ * @param sceneProductID
1745
+ */
1746
+ findSceneProductIndex(sceneProductID) {
1747
+ const states = this._state.states;
1748
+ if (states.length > 0) {
1749
+ const meta = this._state.meta;
1750
+ const found = states.find((productState) => {
1751
+ return productState[meta.scene_product_index] === sceneProductID;
1752
+ });
1753
+ return found ? found : null;
1754
+ }
1755
+ return null;
1756
+ }
1757
+ /**
1758
+ * Search and return the data for the provided Scene Product ID
1759
+ * if not found, will return null
1760
+ * @param sceneProductID
1761
+ */
1762
+ findSceneProduct(sceneProductID) {
1763
+ const found = this.findSceneProductIndex(sceneProductID);
1764
+ if (found) {
1765
+ const meta = this._state.meta;
1766
+ const data = {
1767
+ scene_product_id: found[meta.scene_product_index],
1768
+ product_variation_id: found[meta.product_variation_index],
1769
+ meta_data: {
1770
+ augment: true
1771
+ }
1772
+ };
1773
+ // include the meta-data
1774
+ if (found.length === 3) {
1775
+ data.meta_data.augment = found[meta.meta_index].augment || true;
1595
1776
  }
1596
- states.push(newData);
1777
+ return data;
1597
1778
  }
1779
+ return null;
1598
1780
  }
1599
1781
  /**
1600
1782
  * Iterate over the internal state data
@@ -1625,19 +1807,91 @@ class ConfiguratorState {
1625
1807
  });
1626
1808
  }
1627
1809
  }
1810
+ /**
1811
+ * @returns Returns the first reference of data in the stack, otherwise returns null
1812
+ */
1813
+ first() {
1814
+ const states = this._state.states;
1815
+ if (states.length > 0) {
1816
+ const meta = this._state.meta;
1817
+ const found = states.find((productState) => {
1818
+ const check = productState[meta.scene_product_index];
1819
+ // ensure the data contains valid elements
1820
+ return check !== null && check !== undefined;
1821
+ });
1822
+ if (!found) {
1823
+ return null;
1824
+ }
1825
+ const data = {
1826
+ scene_product_id: found[meta.scene_product_index],
1827
+ product_variation_id: found[meta.product_variation_index],
1828
+ meta_data: {
1829
+ augment: true
1830
+ }
1831
+ };
1832
+ // include the meta-data
1833
+ if (found.length === 3) {
1834
+ data.meta_data.augment = found[meta.meta_index].augment || true;
1835
+ }
1836
+ return data;
1837
+ }
1838
+ return null;
1839
+ }
1628
1840
  get length() {
1629
1841
  return this._state.states.length;
1630
1842
  }
1843
+ /**
1844
+ * Decodes and returns an instance of ConfiguratorState from a previously
1845
+ * encoded state
1846
+ * @param state - The previously encoded state as a Base64 String
1847
+ * @returns - ConfiguratorState instance
1848
+ */
1631
1849
  static decode(state) {
1632
1850
  return new ConfiguratorState(state);
1633
1851
  }
1852
+ /**
1853
+ * Generates a new ConfiguratorState instance from all SceneProducts and default
1854
+ * variations from the provided Scene ID
1855
+ * @param sceneID - the Scene ID to generate
1856
+ * @returns - Promise that resolves into a ConfiguratorState instance
1857
+ */
1858
+ static decodeScene(sceneID = null) {
1859
+ return new Promise((accept, reject) => {
1860
+ const configState = new ConfiguratorState();
1861
+ if (!sceneID) {
1862
+ return reject(new Error("ConfiguratorState.decodeScene(sceneID) - sceneID must be defined"));
1863
+ }
1864
+ const scene = new plattar_api_1.Scene(sceneID);
1865
+ scene.include(plattar_api_1.SceneProduct);
1866
+ scene.include(plattar_api_1.SceneProduct.include(plattar_api_1.Product));
1867
+ scene.get().then((scene) => {
1868
+ const sceneProducts = scene.relationships.filter(plattar_api_1.SceneProduct);
1869
+ // nothing to do if no AR components can be found
1870
+ if (sceneProducts.length <= 0) {
1871
+ return accept(configState);
1872
+ }
1873
+ // add out scene models
1874
+ sceneProducts.forEach((sceneProduct) => {
1875
+ const product = sceneProduct.relationships.find(plattar_api_1.Product);
1876
+ if (product && product.attributes.product_variation_id) {
1877
+ configState.setSceneProduct(sceneProduct.id, product.attributes.product_variation_id);
1878
+ }
1879
+ });
1880
+ accept(configState);
1881
+ }).catch(reject);
1882
+ });
1883
+ }
1884
+ /**
1885
+ * Encode and return the internal ConfiguratorState as a Base64 String
1886
+ * @returns - Base64 String
1887
+ */
1634
1888
  encode() {
1635
1889
  return btoa(JSON.stringify(this._state));
1636
1890
  }
1637
1891
  }
1638
1892
  exports.ConfiguratorState = ConfiguratorState;
1639
1893
 
1640
- },{}],15:[function(require,module,exports){
1894
+ },{"@plattar/plattar-api":42}],15:[function(require,module,exports){
1641
1895
  "use strict";
1642
1896
  Object.defineProperty(exports, "__esModule", { value: true });
1643
1897
  exports.Util = void 0;
@@ -1727,7 +1981,7 @@ exports.Util = Util;
1727
1981
  },{}],16:[function(require,module,exports){
1728
1982
  "use strict";
1729
1983
  Object.defineProperty(exports, "__esModule", { value: true });
1730
- exports.default = "1.123.6";
1984
+ exports.default = "1.128.1";
1731
1985
 
1732
1986
  },{}],17:[function(require,module,exports){
1733
1987
  "use strict";
@@ -3140,7 +3394,11 @@ exports.Analytics = Analytics;
3140
3394
  "use strict";
3141
3395
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3142
3396
  if (k2 === undefined) k2 = k;
3143
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3397
+ var desc = Object.getOwnPropertyDescriptor(m, k);
3398
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
3399
+ desc = { enumerable: true, get: function() { return m[k]; } };
3400
+ }
3401
+ Object.defineProperty(o, k2, desc);
3144
3402
  }) : (function(o, m, k, k2) {
3145
3403
  if (k2 === undefined) k2 = k;
3146
3404
  o[k2] = m[k];
@@ -3263,7 +3521,7 @@ exports.Util = Util;
3263
3521
  },{}],41:[function(require,module,exports){
3264
3522
  "use strict";
3265
3523
  Object.defineProperty(exports, "__esModule", { value: true });
3266
- exports.default = "1.117.2";
3524
+ exports.default = "1.124.1";
3267
3525
 
3268
3526
  },{}],42:[function(require,module,exports){
3269
3527
  "use strict";
@@ -6305,7 +6563,7 @@ class EWallElement extends BaseElement {
6305
6563
  }
6306
6564
  }
6307
6565
 
6308
- window.addEventListener('load', onLoad, false)
6566
+ window.addEventListener("load", onLoad, false)
6309
6567
  }
6310
6568
 
6311
6569
  get permissions() {
@@ -6404,6 +6662,9 @@ class ProductElement extends BaseElement {
6404
6662
  return [{
6405
6663
  key: "variation-id",
6406
6664
  map: "variation_id"
6665
+ }, {
6666
+ key: "show-ar",
6667
+ map: "show_ar"
6407
6668
  }];
6408
6669
  }
6409
6670
  }
@@ -6450,6 +6711,9 @@ class ViewerElement extends BaseElement {
6450
6711
  }, {
6451
6712
  key: "product-id",
6452
6713
  map: "productId"
6714
+ }, {
6715
+ key: "show-ar",
6716
+ map: "show_ar"
6453
6717
  }];
6454
6718
  }
6455
6719
  }
@@ -6603,7 +6867,7 @@ class Util {
6603
6867
 
6604
6868
  module.exports = Util;
6605
6869
  },{}],129:[function(require,module,exports){
6606
- module.exports = "1.123.1";
6870
+ module.exports = "1.128.1";
6607
6871
 
6608
6872
  },{}],130:[function(require,module,exports){
6609
6873
  (function (global){(function (){