@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.
@@ -1086,6 +1086,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1086
1086
 
1087
1087
  var raw_ar_1 = require("../../ar/raw-ar");
1088
1088
 
1089
+ var scene_ar_1 = require("../../ar/scene-ar");
1090
+
1091
+ var scene_product_ar_1 = require("../../ar/scene-product-ar");
1092
+
1093
+ var configurator_state_1 = require("../../util/configurator-state");
1094
+
1089
1095
  var util_1 = require("../../util/util");
1090
1096
 
1091
1097
  var plattar_controller_1 = require("./plattar-controller");
@@ -1240,74 +1246,133 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1240
1246
  return new Promise(function (accept, reject) {
1241
1247
  if (!util_1.Util.canAugment()) {
1242
1248
  return reject(new Error("ConfiguratorController.initAR() - cannot proceed as AR not available in context"));
1243
- } // if scene ID is available and the state is a configurator viewer
1244
- // we can use the real-time configurator state to launch the AR view
1249
+ }
1245
1250
 
1251
+ var arMode = _this15.getAttribute("ar-mode") || "generated";
1246
1252
 
1247
- var viewer = _this15.element;
1253
+ switch (arMode.toLowerCase()) {
1254
+ case "inherited":
1255
+ _this15._InitARInherited(accept, reject);
1248
1256
 
1249
- var sceneID = _this15.getAttribute("scene-id");
1257
+ return;
1250
1258
 
1251
- if (viewer && sceneID) {
1252
- var output = "glb";
1259
+ case "generated":
1260
+ default:
1261
+ _this15._InitARGenerated(accept, reject);
1253
1262
 
1254
- if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
1255
- output = "usdz";
1256
- }
1263
+ }
1264
+ });
1265
+ }
1266
+ /**
1267
+ * Private Function - This launches the Static/Inherited AR Mode
1268
+ */
1257
1269
 
1258
- return viewer.messenger.getARFile(output).then(function (result) {
1259
- var rawAR = new raw_ar_1.RawAR(result.filename);
1260
- return rawAR.init().then(accept)["catch"](reject);
1261
- })["catch"](reject);
1270
+ }, {
1271
+ key: "_InitARInherited",
1272
+ value: function _InitARInherited(accept, reject) {
1273
+ var sceneID = this.getAttribute("scene-id");
1274
+ var configState = this.getAttribute("config-state"); // use config-state if its available
1275
+
1276
+ if (sceneID && configState) {
1277
+ var state = configurator_state_1.ConfiguratorState.decode(configState);
1278
+ var first = state.first();
1279
+
1280
+ if (first) {
1281
+ var sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
1282
+ sceneProductAR.init().then(accept)["catch"](reject);
1283
+ return;
1262
1284
  }
1263
1285
 
1264
- var configState = _this15.getAttribute("config-state"); // otherwise scene ID is available to the viewer is not launched
1265
- // we can use the static configuration state to launch the AR view
1286
+ return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
1287
+ } // otherwise fallback to using scene
1266
1288
 
1267
1289
 
1268
- if (sceneID && configState) {
1269
- try {
1270
- var decodedb64State = atob(configState);
1271
- var state = JSON.parse(decodedb64State);
1272
-
1273
- if (state.meta) {
1274
- var sceneProductIndex = state.meta.scene_product_index || 0;
1275
- var variationIndex = state.meta.product_variation_index || 1;
1276
- var states = state.states || [];
1277
-
1278
- if (states.length > 0) {
1279
- var configurator = new plattar_services_1.Configurator();
1280
- states.forEach(function (productState) {
1281
- configurator.addSceneProduct(productState[sceneProductIndex], productState[variationIndex]);
1282
- });
1290
+ if (sceneID) {
1291
+ configurator_state_1.ConfiguratorState.decodeScene(sceneID).then(function (state) {
1292
+ var first = state.first();
1283
1293
 
1284
- if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
1285
- configurator.output = "usdz";
1286
- }
1294
+ if (first) {
1295
+ var _sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
1287
1296
 
1288
- if (util_1.Util.canSceneViewer()) {
1289
- configurator.output = "glb";
1290
- }
1297
+ return _sceneProductAR.init().then(accept)["catch"](reject);
1298
+ }
1291
1299
 
1292
- var server = _this15.getAttribute("server") || "production";
1293
- configurator.server = server;
1294
- return configurator.get().then(function (result) {
1295
- var rawAR = new raw_ar_1.RawAR(result.filename);
1296
- rawAR.init().then(accept)["catch"](reject);
1297
- })["catch"](reject);
1298
- }
1300
+ return reject(new Error("ConfiguratorController.initAR() - invalid Scene does not have any product states"));
1301
+ })["catch"](reject);
1302
+ return;
1303
+ }
1299
1304
 
1300
- return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
1301
- }
1305
+ return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1306
+ }
1307
+ /**
1308
+ * Private Function - This launches the Dynamic/Generated AR Mode
1309
+ */
1302
1310
 
1303
- return reject(new Error("ConfiguratorController.initAR() - invalid config-state for configurator"));
1304
- } catch (err) {
1305
- return reject(err);
1311
+ }, {
1312
+ key: "_InitARGenerated",
1313
+ value: function _InitARGenerated(accept, reject) {
1314
+ // if scene ID is available and the state is a configurator viewer
1315
+ // we can use the real-time configurator state to launch the AR view
1316
+ var viewer = this.element;
1317
+ var sceneID = this.getAttribute("scene-id");
1318
+
1319
+ if (viewer && sceneID && viewer.messenger) {
1320
+ var output = "glb";
1321
+
1322
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
1323
+ output = "usdz";
1324
+ }
1325
+
1326
+ viewer.messenger.getARFile(output).then(function (result) {
1327
+ var rawAR = new raw_ar_1.RawAR(result.filename);
1328
+ return rawAR.init().then(accept)["catch"](reject);
1329
+ })["catch"](reject);
1330
+ return;
1331
+ }
1332
+
1333
+ var configState = this.getAttribute("config-state"); // otherwise scene ID is available to the viewer is not launched
1334
+ // we can use the static configuration state to launch the AR view
1335
+
1336
+ if (sceneID && configState) {
1337
+ var state = configurator_state_1.ConfiguratorState.decode(configState);
1338
+
1339
+ if (state.length > 0) {
1340
+ var server = this.getAttribute("server") || "production";
1341
+ var configurator = new plattar_services_1.Configurator();
1342
+ configurator.server = server;
1343
+
1344
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
1345
+ configurator.output = "usdz";
1346
+ }
1347
+
1348
+ if (util_1.Util.canSceneViewer()) {
1349
+ configurator.output = "glb";
1306
1350
  }
1351
+
1352
+ state.forEach(function (productState) {
1353
+ if (productState.meta_data.augment === true) {
1354
+ configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
1355
+ }
1356
+ });
1357
+ configurator.get().then(function (result) {
1358
+ var rawAR = new raw_ar_1.RawAR(result.filename);
1359
+ rawAR.init().then(accept)["catch"](reject);
1360
+ })["catch"](reject);
1361
+ return;
1307
1362
  }
1308
1363
 
1309
- return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1310
- });
1364
+ return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
1365
+ } // otherwise no config-state or viewer is active
1366
+ // fallback to using default SceneAR implementation
1367
+
1368
+
1369
+ if (sceneID) {
1370
+ var sceneAR = new scene_ar_1.SceneAR(sceneID);
1371
+ sceneAR.init().then(accept)["catch"](reject);
1372
+ return;
1373
+ }
1374
+
1375
+ return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1311
1376
  }
1312
1377
  }, {
1313
1378
  key: "removeRenderer",
@@ -1334,6 +1399,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1334
1399
  exports.ConfiguratorController = ConfiguratorController;
1335
1400
  }, {
1336
1401
  "../../ar/raw-ar": 4,
1402
+ "../../ar/scene-ar": 5,
1403
+ "../../ar/scene-product-ar": 6,
1404
+ "../../util/configurator-state": 14,
1337
1405
  "../../util/util": 15,
1338
1406
  "./plattar-controller": 8,
1339
1407
  "@plattar/plattar-api": 42,
@@ -1531,12 +1599,18 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1531
1599
 
1532
1600
  var variationID = _this18.getAttribute("variation-id");
1533
1601
 
1602
+ var showAR = _this18.getAttribute("show-ar");
1603
+
1534
1604
  var dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
1535
1605
 
1536
1606
  if (variationID) {
1537
1607
  dst += "&variation_id=" + variationID;
1538
1608
  }
1539
1609
 
1610
+ if (showAR) {
1611
+ dst += "&show_ar=" + showAR;
1612
+ }
1613
+
1540
1614
  viewer.setAttribute("url", opt.url || dst);
1541
1615
 
1542
1616
  viewer.onload = function () {
@@ -1578,10 +1652,16 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1578
1652
 
1579
1653
  var variationID = _this19.getAttribute("variation-id");
1580
1654
 
1655
+ var showAR = _this19.getAttribute("show-ar");
1656
+
1581
1657
  if (variationID) {
1582
1658
  viewer.setAttribute("variation-id", variationID);
1583
1659
  }
1584
1660
 
1661
+ if (showAR) {
1662
+ viewer.setAttribute("show-ar", showAR);
1663
+ }
1664
+
1585
1665
  viewer.onload = function () {
1586
1666
  return accept(viewer);
1587
1667
  };
@@ -1661,6 +1741,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1661
1741
 
1662
1742
  var scene_product_ar_1 = require("../../ar/scene-product-ar");
1663
1743
 
1744
+ var configurator_state_1 = require("../../util/configurator-state");
1745
+
1664
1746
  var util_1 = require("../../util/util");
1665
1747
 
1666
1748
  var plattar_controller_1 = require("./plattar-controller");
@@ -1750,6 +1832,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1750
1832
 
1751
1833
  var variationID = _this22.getAttribute("variation-id");
1752
1834
 
1835
+ var showAR = _this22.getAttribute("show-ar");
1836
+
1753
1837
  if (productID) {
1754
1838
  dst += "&productId=" + productID;
1755
1839
  }
@@ -1758,6 +1842,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1758
1842
  dst += "&variationId=" + variationID;
1759
1843
  }
1760
1844
 
1845
+ if (showAR) {
1846
+ dst += "&show_ar=" + showAR;
1847
+ }
1848
+
1761
1849
  viewer.setAttribute("url", opt.url || dst);
1762
1850
 
1763
1851
  viewer.onload = function () {
@@ -1801,6 +1889,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1801
1889
 
1802
1890
  var variationID = _this23.getAttribute("variation-id");
1803
1891
 
1892
+ var showAR = _this23.getAttribute("show-ar");
1893
+
1804
1894
  if (productID) {
1805
1895
  viewer.setAttribute("product-id", productID);
1806
1896
  }
@@ -1809,6 +1899,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1809
1899
  viewer.setAttribute("variation-id", variationID);
1810
1900
  }
1811
1901
 
1902
+ if (showAR) {
1903
+ viewer.setAttribute("show-ar", showAR);
1904
+ }
1905
+
1812
1906
  viewer.onload = function () {
1813
1907
  return accept(viewer);
1814
1908
  };
@@ -1854,14 +1948,23 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1854
1948
  return _product.init().then(accept)["catch"](reject);
1855
1949
  }
1856
1950
 
1857
- var sceneID = _this24.getAttribute("scene-id"); // otherwise, scene was set so use SceneAR
1951
+ var sceneID = _this24.getAttribute("scene-id"); // use the first default product-variation id if available
1858
1952
 
1859
1953
 
1860
1954
  if (sceneID) {
1861
- return reject(new Error("ViewerController.initAR() - AR mode for scene-id not yet supported, use product-id or scene-product-id"));
1955
+ return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then(function (state) {
1956
+ var first = state.first();
1957
+
1958
+ if (first) {
1959
+ var sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
1960
+ return sceneProductAR.init().then(accept)["catch"](reject);
1961
+ }
1962
+
1963
+ return reject(new Error("ViewerController.initAR() - your scene does not contain any valid products"));
1964
+ })["catch"](reject);
1862
1965
  }
1863
1966
 
1864
- return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use product-id or scene-product-id as a minimum"));
1967
+ return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1865
1968
  });
1866
1969
  }
1867
1970
  }, {
@@ -1890,6 +1993,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1890
1993
  }, {
1891
1994
  "../../ar/product-ar": 3,
1892
1995
  "../../ar/scene-product-ar": 6,
1996
+ "../../util/configurator-state": 14,
1893
1997
  "../../util/util": 15,
1894
1998
  "./plattar-controller": 8,
1895
1999
  "@plattar/plattar-api": 42
@@ -2068,56 +2172,121 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2068
2172
 
2069
2173
  if (!(util_1.Util.isSafari() || util_1.Util.isChromeOnIOS())) {
2070
2174
  return reject(new Error("VTOController.initAR() - cannot proceed as VTO AR only available on IOS Mobile devices"));
2071
- } // if scene ID is available and the state is a configurator viewer
2072
- // we can use the real-time configurator state to launch the AR view
2175
+ }
2176
+
2177
+ var arMode = _this28.getAttribute("ar-mode") || "generated";
2073
2178
 
2179
+ switch (arMode.toLowerCase()) {
2180
+ case "inherited":
2181
+ _this28._InitARInherited(accept, reject);
2074
2182
 
2075
- var viewer = _this28.element;
2183
+ return;
2076
2184
 
2077
- var sceneID = _this28.getAttribute("scene-id");
2185
+ case "generated":
2186
+ default:
2187
+ _this28._InitARGenerated(accept, reject);
2078
2188
 
2079
- if (viewer && sceneID) {
2080
- return viewer.messenger.getARFile("vto").then(function (result) {
2081
- var rawAR = new raw_ar_1.RawAR(result.filename);
2082
- return rawAR.init().then(accept)["catch"](reject);
2083
- })["catch"](reject);
2084
2189
  }
2190
+ });
2191
+ }
2192
+ /**
2193
+ * Private Function - This launches the Static/Inherited AR Mode
2194
+ */
2085
2195
 
2086
- var configState = _this28.getAttribute("config-state"); // otherwise scene ID is available to the viewer is not launched
2087
- // we can use the static configuration state to launch the AR view
2196
+ }, {
2197
+ key: "_InitARInherited",
2198
+ value: function _InitARInherited(accept, reject) {
2199
+ var sceneID = this.getAttribute("scene-id");
2200
+ var configState = this.getAttribute("config-state"); // use config-state if its available
2088
2201
 
2202
+ if (sceneID && configState) {
2203
+ var state = __1.ConfiguratorState.decode(configState);
2089
2204
 
2090
- if (sceneID && configState) {
2091
- var state = __1.ConfiguratorState.decode(configState);
2205
+ var first = state.first();
2092
2206
 
2093
- if (state.length > 0) {
2094
- var server = _this28.getAttribute("server") || "production";
2095
- var configurator = new plattar_services_1.Configurator();
2096
- configurator.server = server;
2097
- configurator.output = "vto";
2098
- state.forEach(function (productState) {
2099
- if (productState.meta_data.augment === true) {
2100
- configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
2101
- }
2102
- });
2103
- return configurator.get().then(function (result) {
2104
- var rawAR = new raw_ar_1.RawAR(result.filename);
2105
- rawAR.init().then(accept)["catch"](reject);
2106
- })["catch"](reject);
2207
+ if (first) {
2208
+ var sceneProductAR = new __1.SceneProductAR(first.scene_product_id, first.product_variation_id);
2209
+ sceneProductAR.init().then(accept)["catch"](reject);
2210
+ return;
2211
+ }
2212
+
2213
+ return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
2214
+ } // otherwise fallback to using scene
2215
+
2216
+
2217
+ if (sceneID) {
2218
+ __1.ConfiguratorState.decodeScene(sceneID).then(function (state) {
2219
+ var first = state.first();
2220
+
2221
+ if (first) {
2222
+ var _sceneProductAR2 = new __1.SceneProductAR(first.scene_product_id, first.product_variation_id);
2223
+
2224
+ return _sceneProductAR2.init().then(accept)["catch"](reject);
2107
2225
  }
2108
2226
 
2109
- return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
2110
- } // otherwise no config-state or viewer is active
2111
- // fallback to using default SceneAR implementation
2227
+ return reject(new Error("VTOController.initAR() - invalid Scene does not have any product states"));
2228
+ })["catch"](reject);
2229
+
2230
+ return;
2231
+ }
2112
2232
 
2233
+ return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
2234
+ }
2235
+ /**
2236
+ * Private Function - This launches the Dynamic/Generated AR Mode
2237
+ */
2113
2238
 
2114
- if (sceneID) {
2115
- var sceneAR = new __1.SceneAR(sceneID);
2116
- return sceneAR.init().then(accept)["catch"](reject);
2239
+ }, {
2240
+ key: "_InitARGenerated",
2241
+ value: function _InitARGenerated(accept, reject) {
2242
+ // if scene ID is available and the state is a configurator viewer
2243
+ // we can use the real-time configurator state to launch the AR view
2244
+ var viewer = this.element;
2245
+ var sceneID = this.getAttribute("scene-id");
2246
+
2247
+ if (viewer && sceneID && viewer.messenger) {
2248
+ viewer.messenger.getARFile("vto").then(function (result) {
2249
+ var rawAR = new raw_ar_1.RawAR(result.filename);
2250
+ return rawAR.init().then(accept)["catch"](reject);
2251
+ })["catch"](reject);
2252
+ return;
2253
+ }
2254
+
2255
+ var configState = this.getAttribute("config-state"); // otherwise scene ID is available to the viewer is not launched
2256
+ // we can use the static configuration state to launch the AR view
2257
+
2258
+ if (sceneID && configState) {
2259
+ var state = __1.ConfiguratorState.decode(configState);
2260
+
2261
+ if (state.length > 0) {
2262
+ var server = this.getAttribute("server") || "production";
2263
+ var configurator = new plattar_services_1.Configurator();
2264
+ configurator.server = server;
2265
+ configurator.output = "vto";
2266
+ state.forEach(function (productState) {
2267
+ if (productState.meta_data.augment === true) {
2268
+ configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
2269
+ }
2270
+ });
2271
+ configurator.get().then(function (result) {
2272
+ var rawAR = new raw_ar_1.RawAR(result.filename);
2273
+ rawAR.init().then(accept)["catch"](reject);
2274
+ })["catch"](reject);
2275
+ return;
2117
2276
  }
2118
2277
 
2119
- return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
2120
- });
2278
+ return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
2279
+ } // otherwise no config-state or viewer is active
2280
+ // fallback to using default SceneAR implementation
2281
+
2282
+
2283
+ if (sceneID) {
2284
+ var sceneAR = new __1.SceneAR(sceneID);
2285
+ sceneAR.init().then(accept)["catch"](reject);
2286
+ return;
2287
+ }
2288
+
2289
+ return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
2121
2290
  }
2122
2291
  }, {
2123
2292
  key: "removeRenderer",
@@ -2378,12 +2547,18 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2378
2547
 
2379
2548
  var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
2380
2549
  if (k2 === undefined) k2 = k;
2381
- Object.defineProperty(o, k2, {
2382
- enumerable: true,
2383
- get: function get() {
2384
- return m[k];
2385
- }
2386
- });
2550
+ var desc = Object.getOwnPropertyDescriptor(m, k);
2551
+
2552
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
2553
+ desc = {
2554
+ enumerable: true,
2555
+ get: function get() {
2556
+ return m[k];
2557
+ }
2558
+ };
2559
+ }
2560
+
2561
+ Object.defineProperty(o, k2, desc);
2387
2562
  } : function (o, m, k, k2) {
2388
2563
  if (k2 === undefined) k2 = k;
2389
2564
  o[k2] = m[k];
@@ -2519,6 +2694,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2519
2694
  });
2520
2695
  exports.ConfiguratorState = void 0;
2521
2696
 
2697
+ var plattar_api_1 = require("@plattar/plattar-api");
2698
+
2522
2699
  var ConfiguratorState = /*#__PURE__*/function () {
2523
2700
  function ConfiguratorState() {
2524
2701
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
@@ -2564,6 +2741,20 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2564
2741
 
2565
2742
 
2566
2743
  _createClass(ConfiguratorState, [{
2744
+ key: "setSceneProduct",
2745
+ value: function setSceneProduct(sceneProductID, productVariationID) {
2746
+ var metaData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
2747
+ this.addSceneProduct(sceneProductID, productVariationID, metaData);
2748
+ }
2749
+ /**
2750
+ * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
2751
+ *
2752
+ * @param sceneProductID - The Scene Product ID to be used (as defined in Plattar CMS)
2753
+ * @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
2754
+ * @param metaData - Arbitrary meta-data that can be used against certain operaions
2755
+ */
2756
+
2757
+ }, {
2567
2758
  key: "addSceneProduct",
2568
2759
  value: function addSceneProduct(sceneProductID, productVariationID) {
2569
2760
  var metaData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
@@ -2571,16 +2762,75 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2571
2762
  if (sceneProductID && productVariationID) {
2572
2763
  var states = this._state.states;
2573
2764
  var meta = this._state.meta;
2574
- var newData = [];
2575
- newData.splice(meta.scene_product_index, 0, sceneProductID);
2576
- newData.splice(meta.product_variation_index, 0, productVariationID);
2765
+ var newData = null;
2766
+ var existingData = this.findSceneProductIndex(sceneProductID);
2767
+
2768
+ if (existingData) {
2769
+ newData = existingData;
2770
+ } else {
2771
+ newData = []; // push the new data into the stack
2772
+
2773
+ states.push(newData);
2774
+ }
2775
+
2776
+ newData[meta.scene_product_index] = sceneProductID;
2777
+ newData[meta.product_variation_index] = productVariationID;
2577
2778
 
2578
2779
  if (metaData) {
2579
- newData.splice(meta.meta_index, 0, metaData);
2780
+ newData[meta.meta_index] = metaData;
2781
+ }
2782
+ }
2783
+ }
2784
+ /**
2785
+ * Search and return the data index reference for the provided Scene Product ID
2786
+ * if not found, will return null
2787
+ * @param sceneProductID
2788
+ */
2789
+
2790
+ }, {
2791
+ key: "findSceneProductIndex",
2792
+ value: function findSceneProductIndex(sceneProductID) {
2793
+ var states = this._state.states;
2794
+
2795
+ if (states.length > 0) {
2796
+ var meta = this._state.meta;
2797
+ var found = states.find(function (productState) {
2798
+ return productState[meta.scene_product_index] === sceneProductID;
2799
+ });
2800
+ return found ? found : null;
2801
+ }
2802
+
2803
+ return null;
2804
+ }
2805
+ /**
2806
+ * Search and return the data for the provided Scene Product ID
2807
+ * if not found, will return null
2808
+ * @param sceneProductID
2809
+ */
2810
+
2811
+ }, {
2812
+ key: "findSceneProduct",
2813
+ value: function findSceneProduct(sceneProductID) {
2814
+ var found = this.findSceneProductIndex(sceneProductID);
2815
+
2816
+ if (found) {
2817
+ var meta = this._state.meta;
2818
+ var data = {
2819
+ scene_product_id: found[meta.scene_product_index],
2820
+ product_variation_id: found[meta.product_variation_index],
2821
+ meta_data: {
2822
+ augment: true
2823
+ }
2824
+ }; // include the meta-data
2825
+
2826
+ if (found.length === 3) {
2827
+ data.meta_data.augment = found[meta.meta_index].augment || true;
2580
2828
  }
2581
2829
 
2582
- states.push(newData);
2830
+ return data;
2583
2831
  }
2832
+
2833
+ return null;
2584
2834
  }
2585
2835
  /**
2586
2836
  * Iterate over the internal state data
@@ -2614,14 +2864,64 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2614
2864
  });
2615
2865
  }
2616
2866
  }
2867
+ /**
2868
+ * @returns Returns the first reference of data in the stack, otherwise returns null
2869
+ */
2870
+
2871
+ }, {
2872
+ key: "first",
2873
+ value: function first() {
2874
+ var states = this._state.states;
2875
+
2876
+ if (states.length > 0) {
2877
+ var meta = this._state.meta;
2878
+ var found = states.find(function (productState) {
2879
+ var check = productState[meta.scene_product_index]; // ensure the data contains valid elements
2880
+
2881
+ return check !== null && check !== undefined;
2882
+ });
2883
+
2884
+ if (!found) {
2885
+ return null;
2886
+ }
2887
+
2888
+ var data = {
2889
+ scene_product_id: found[meta.scene_product_index],
2890
+ product_variation_id: found[meta.product_variation_index],
2891
+ meta_data: {
2892
+ augment: true
2893
+ }
2894
+ }; // include the meta-data
2895
+
2896
+ if (found.length === 3) {
2897
+ data.meta_data.augment = found[meta.meta_index].augment || true;
2898
+ }
2899
+
2900
+ return data;
2901
+ }
2902
+
2903
+ return null;
2904
+ }
2617
2905
  }, {
2618
2906
  key: "length",
2619
2907
  get: function get() {
2620
2908
  return this._state.states.length;
2621
2909
  }
2910
+ /**
2911
+ * Decodes and returns an instance of ConfiguratorState from a previously
2912
+ * encoded state
2913
+ * @param state - The previously encoded state as a Base64 String
2914
+ * @returns - ConfiguratorState instance
2915
+ */
2916
+
2622
2917
  }, {
2623
2918
  key: "encode",
2624
- value: function encode() {
2919
+ value:
2920
+ /**
2921
+ * Encode and return the internal ConfiguratorState as a Base64 String
2922
+ * @returns - Base64 String
2923
+ */
2924
+ function encode() {
2625
2925
  return btoa(JSON.stringify(this._state));
2626
2926
  }
2627
2927
  }], [{
@@ -2629,13 +2929,55 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2629
2929
  value: function decode(state) {
2630
2930
  return new ConfiguratorState(state);
2631
2931
  }
2932
+ /**
2933
+ * Generates a new ConfiguratorState instance from all SceneProducts and default
2934
+ * variations from the provided Scene ID
2935
+ * @param sceneID - the Scene ID to generate
2936
+ * @returns - Promise that resolves into a ConfiguratorState instance
2937
+ */
2938
+
2939
+ }, {
2940
+ key: "decodeScene",
2941
+ value: function decodeScene() {
2942
+ var sceneID = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
2943
+ return new Promise(function (accept, reject) {
2944
+ var configState = new ConfiguratorState();
2945
+
2946
+ if (!sceneID) {
2947
+ return reject(new Error("ConfiguratorState.decodeScene(sceneID) - sceneID must be defined"));
2948
+ }
2949
+
2950
+ var scene = new plattar_api_1.Scene(sceneID);
2951
+ scene.include(plattar_api_1.SceneProduct);
2952
+ scene.include(plattar_api_1.SceneProduct.include(plattar_api_1.Product));
2953
+ scene.get().then(function (scene) {
2954
+ var sceneProducts = scene.relationships.filter(plattar_api_1.SceneProduct); // nothing to do if no AR components can be found
2955
+
2956
+ if (sceneProducts.length <= 0) {
2957
+ return accept(configState);
2958
+ } // add out scene models
2959
+
2960
+
2961
+ sceneProducts.forEach(function (sceneProduct) {
2962
+ var product = sceneProduct.relationships.find(plattar_api_1.Product);
2963
+
2964
+ if (product && product.attributes.product_variation_id) {
2965
+ configState.setSceneProduct(sceneProduct.id, product.attributes.product_variation_id);
2966
+ }
2967
+ });
2968
+ accept(configState);
2969
+ })["catch"](reject);
2970
+ });
2971
+ }
2632
2972
  }]);
2633
2973
 
2634
2974
  return ConfiguratorState;
2635
2975
  }();
2636
2976
 
2637
2977
  exports.ConfiguratorState = ConfiguratorState;
2638
- }, {}],
2978
+ }, {
2979
+ "@plattar/plattar-api": 42
2980
+ }],
2639
2981
  15: [function (require, module, exports) {
2640
2982
  "use strict";
2641
2983
 
@@ -2766,7 +3108,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2766
3108
  Object.defineProperty(exports, "__esModule", {
2767
3109
  value: true
2768
3110
  });
2769
- exports["default"] = "1.123.6";
3111
+ exports["default"] = "1.128.1";
2770
3112
  }, {}],
2771
3113
  17: [function (require, module, exports) {
2772
3114
  "use strict";
@@ -4586,12 +4928,18 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
4586
4928
 
4587
4929
  var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
4588
4930
  if (k2 === undefined) k2 = k;
4589
- Object.defineProperty(o, k2, {
4590
- enumerable: true,
4591
- get: function get() {
4592
- return m[k];
4593
- }
4594
- });
4931
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4932
+
4933
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
4934
+ desc = {
4935
+ enumerable: true,
4936
+ get: function get() {
4937
+ return m[k];
4938
+ }
4939
+ };
4940
+ }
4941
+
4942
+ Object.defineProperty(o, k2, desc);
4595
4943
  } : function (o, m, k, k2) {
4596
4944
  if (k2 === undefined) k2 = k;
4597
4945
  o[k2] = m[k];
@@ -4777,7 +5125,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
4777
5125
  Object.defineProperty(exports, "__esModule", {
4778
5126
  value: true
4779
5127
  });
4780
- exports["default"] = "1.117.2";
5128
+ exports["default"] = "1.124.1";
4781
5129
  }, {}],
4782
5130
  42: [function (require, module, exports) {
4783
5131
  "use strict";
@@ -9635,7 +9983,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
9635
9983
  }
9636
9984
  };
9637
9985
 
9638
- window.addEventListener('load', onLoad, false);
9986
+ window.addEventListener("load", onLoad, false);
9639
9987
  }
9640
9988
  }, {
9641
9989
  key: "permissions",
@@ -9785,6 +10133,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
9785
10133
  return [{
9786
10134
  key: "variation-id",
9787
10135
  map: "variation_id"
10136
+ }, {
10137
+ key: "show-ar",
10138
+ map: "show_ar"
9788
10139
  }];
9789
10140
  }
9790
10141
  }]);
@@ -9862,6 +10213,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
9862
10213
  }, {
9863
10214
  key: "product-id",
9864
10215
  map: "productId"
10216
+ }, {
10217
+ key: "show-ar",
10218
+ map: "show_ar"
9865
10219
  }];
9866
10220
  }
9867
10221
  }]);
@@ -10080,7 +10434,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
10080
10434
  module.exports = Util;
10081
10435
  }, {}],
10082
10436
  129: [function (require, module, exports) {
10083
- module.exports = "1.123.1";
10437
+ module.exports = "1.128.1";
10084
10438
  }, {}],
10085
10439
  130: [function (require, module, exports) {
10086
10440
  (function (global) {