@plattar/plattar-ar-adapter 1.130.1 → 1.131.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.
@@ -172,7 +172,7 @@ const launcher_ar_1 = require("./launcher-ar");
172
172
  * Performs AR functionality related to Plattar Products and Variation types
173
173
  */
174
174
  class ProductAR extends launcher_ar_1.LauncherAR {
175
- constructor(productID = null, variationID = null) {
175
+ constructor(productID = null, variationID = null, variationSKU = null) {
176
176
  super();
177
177
  // analytics instance
178
178
  this._analytics = null;
@@ -180,7 +180,8 @@ class ProductAR extends launcher_ar_1.LauncherAR {
180
180
  throw new Error("ProductAR.constructor(productID, variationID) - productID must be defined");
181
181
  }
182
182
  this._productID = productID;
183
- this._variationID = variationID ? variationID : "default";
183
+ this._variationSKU = variationSKU;
184
+ this._variationID = variationID ? variationID : (variationSKU ? null : "default");
184
185
  this._ar = null;
185
186
  }
186
187
  get productID() {
@@ -189,6 +190,9 @@ class ProductAR extends launcher_ar_1.LauncherAR {
189
190
  get variationID() {
190
191
  return this._variationID;
191
192
  }
193
+ get variationSKU() {
194
+ return this._variationSKU;
195
+ }
192
196
  _SetupAnalytics(product, variation) {
193
197
  let analytics = null;
194
198
  const scene = product.relationships.find(plattar_api_1.Scene);
@@ -237,14 +241,27 @@ class ProductAR extends launcher_ar_1.LauncherAR {
237
241
  product.include(plattar_api_1.Scene.include(plattar_api_1.Project));
238
242
  product.get().then((product) => {
239
243
  // find the required variation from our product
240
- const variationID = this.variationID ? (this.variationID === "default" ? product.attributes.product_variation_id : this.variationID) : product.attributes.product_variation_id;
241
- if (!variationID) {
242
- return reject(new Error("ProductAR.init() - cannot proceed as variation was not defined correctly"));
244
+ const variationID = this.variationID ? (this.variationID === "default" ? product.attributes.product_variation_id : this.variationID) : null;
245
+ const variationSKU = this.variationSKU;
246
+ if (!variationID && !variationSKU) {
247
+ return reject(new Error("ProductAR.init() - cannot proceed as variation-id or variation-sku was not set correctly"));
248
+ }
249
+ let variation = undefined;
250
+ if (variationID) {
251
+ variation = product.relationships.find(plattar_api_1.ProductVariation, variationID);
252
+ }
253
+ // if no variation was found with variationID - try searching variation sku
254
+ if (!variation && variationSKU) {
255
+ const variations = product.relationships.filter(plattar_api_1.ProductVariation);
256
+ if (variations) {
257
+ variation = variations.find((element) => {
258
+ return element.attributes.sku === variationSKU;
259
+ });
260
+ }
243
261
  }
244
- const variation = product.relationships.find(plattar_api_1.ProductVariation, variationID);
245
262
  // make sure our variation is actually available before moving forward
246
263
  if (!variation) {
247
- return reject(new Error("ProductAR.init() - cannot proceed as variation with id " + variationID + " cannot be found"));
264
+ return reject(new Error("ProductAR.init() - cannot proceed as variation with id " + variationID + " or sku " + variationSKU + " cannot be found"));
248
265
  }
249
266
  // otherwise both the product and variation are available
250
267
  // we need to figure out if we can actually do AR though
@@ -611,8 +628,8 @@ const util_1 = require("../util/util");
611
628
  * SceneProducts are much more convenient to grab from the Plattar CMS
612
629
  */
613
630
  class SceneProductAR extends product_ar_1.ProductAR {
614
- constructor(sceneProductID = null, variationID = null) {
615
- super(sceneProductID, variationID);
631
+ constructor(sceneProductID = null, variationID = null, variationSKU = null) {
632
+ super(sceneProductID, variationID, variationSKU);
616
633
  // this is evaluated in the init() function
617
634
  this._attachedProductID = null;
618
635
  if (!sceneProductID) {
@@ -702,6 +719,10 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
702
719
  // optional attributes
703
720
  const configState = this.getAttribute("config-state");
704
721
  const showAR = this.getAttribute("show-ar");
722
+ const showUI = this.getAttribute("show-ui");
723
+ if (showUI && showUI === "true") {
724
+ dst = plattar_api_1.Server.location().base + "configurator/dist/index.html?scene_id=" + sceneID;
725
+ }
705
726
  if (configState) {
706
727
  dst += "&config_state=" + configState;
707
728
  }
@@ -739,12 +760,16 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
739
760
  // optional attributes
740
761
  const configState = this.getAttribute("config-state");
741
762
  const showAR = this.getAttribute("show-ar");
763
+ const showUI = this.getAttribute("show-ui");
742
764
  if (configState) {
743
765
  viewer.setAttribute("config-state", configState);
744
766
  }
745
767
  if (showAR) {
746
768
  viewer.setAttribute("show-ar", showAR);
747
769
  }
770
+ if (showUI) {
771
+ viewer.setAttribute("show-ui", showUI);
772
+ }
748
773
  viewer.onload = () => {
749
774
  return accept(viewer);
750
775
  };
@@ -964,6 +989,7 @@ class PlattarController {
964
989
  const productID = this.getAttribute("product-id");
965
990
  const sceneProductID = this.getAttribute("scene-product-id");
966
991
  const variationID = this.getAttribute("variation-id");
992
+ const variationSKU = this.getAttribute("variation-sku");
967
993
  const arMode = this.getAttribute("ar-mode");
968
994
  if (configState) {
969
995
  dst += "&config_state=" + configState;
@@ -980,6 +1006,9 @@ class PlattarController {
980
1006
  if (variationID) {
981
1007
  dst += "&variation_id=" + variationID;
982
1008
  }
1009
+ if (variationSKU) {
1010
+ dst += "&variation_sku=" + variationSKU;
1011
+ }
983
1012
  if (arMode) {
984
1013
  dst += "&ar_mode=" + arMode;
985
1014
  }
@@ -1079,10 +1108,14 @@ class ProductController extends plattar_controller_1.PlattarController {
1079
1108
  }
1080
1109
  // optional attributes
1081
1110
  const variationID = this.getAttribute("variation-id");
1111
+ const variationSKU = this.getAttribute("variation-sku");
1082
1112
  const showAR = this.getAttribute("show-ar");
1083
1113
  let dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
1084
1114
  if (variationID) {
1085
- dst += "&variation_id=" + variationID;
1115
+ dst += "&variationId=" + variationID;
1116
+ }
1117
+ if (variationSKU) {
1118
+ dst += "&variationSku=" + variationSKU;
1086
1119
  }
1087
1120
  if (showAR) {
1088
1121
  dst += "&show_ar=" + showAR;
@@ -1117,10 +1150,14 @@ class ProductController extends plattar_controller_1.PlattarController {
1117
1150
  viewer.setAttribute("product-id", productID);
1118
1151
  // optional attributes
1119
1152
  const variationID = this.getAttribute("variation-id");
1153
+ const variationSKU = this.getAttribute("variation-sku");
1120
1154
  const showAR = this.getAttribute("show-ar");
1121
1155
  if (variationID) {
1122
1156
  viewer.setAttribute("variation-id", variationID);
1123
1157
  }
1158
+ if (variationSKU) {
1159
+ viewer.setAttribute("variation-sku", variationSKU);
1160
+ }
1124
1161
  if (showAR) {
1125
1162
  viewer.setAttribute("show-ar", showAR);
1126
1163
  }
@@ -1143,7 +1180,8 @@ class ProductController extends plattar_controller_1.PlattarController {
1143
1180
  const productID = this.getAttribute("product-id");
1144
1181
  if (productID) {
1145
1182
  const variationID = this.getAttribute("variation-id");
1146
- const product = new product_ar_1.ProductAR(productID, variationID);
1183
+ const variationSKU = this.getAttribute("variation-sku");
1184
+ const product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
1147
1185
  return product.init().then(accept).catch(reject);
1148
1186
  }
1149
1187
  return reject(new Error("ProductController.initAR() - minimum required attributes not set, use product-id as a minimum"));
@@ -1169,6 +1207,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
1169
1207
  exports.ViewerController = void 0;
1170
1208
  const plattar_api_1 = require("@plattar/plattar-api");
1171
1209
  const product_ar_1 = require("../../ar/product-ar");
1210
+ const scene_ar_1 = require("../../ar/scene-ar");
1172
1211
  const scene_product_ar_1 = require("../../ar/scene-product-ar");
1173
1212
  const configurator_state_1 = require("../../util/configurator-state");
1174
1213
  const util_1 = require("../../util/util");
@@ -1226,6 +1265,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
1226
1265
  // optional attributes
1227
1266
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
1228
1267
  const variationID = this.getAttribute("variation-id");
1268
+ const variationSKU = this.getAttribute("variation-sku");
1229
1269
  const showAR = this.getAttribute("show-ar");
1230
1270
  if (productID) {
1231
1271
  dst += "&productId=" + productID;
@@ -1233,6 +1273,9 @@ class ViewerController extends plattar_controller_1.PlattarController {
1233
1273
  if (variationID) {
1234
1274
  dst += "&variationId=" + variationID;
1235
1275
  }
1276
+ if (variationSKU) {
1277
+ dst += "&variationSku=" + variationSKU;
1278
+ }
1236
1279
  if (showAR) {
1237
1280
  dst += "&show_ar=" + showAR;
1238
1281
  }
@@ -1267,6 +1310,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
1267
1310
  // optional attributes
1268
1311
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
1269
1312
  const variationID = this.getAttribute("variation-id");
1313
+ const variationSKU = this.getAttribute("variation-sku");
1270
1314
  const showAR = this.getAttribute("show-ar");
1271
1315
  if (productID) {
1272
1316
  viewer.setAttribute("product-id", productID);
@@ -1274,6 +1318,9 @@ class ViewerController extends plattar_controller_1.PlattarController {
1274
1318
  if (variationID) {
1275
1319
  viewer.setAttribute("variation-id", variationID);
1276
1320
  }
1321
+ if (variationSKU) {
1322
+ viewer.setAttribute("variation-sku", variationSKU);
1323
+ }
1277
1324
  if (showAR) {
1278
1325
  viewer.setAttribute("show-ar", showAR);
1279
1326
  }
@@ -1297,26 +1344,38 @@ class ViewerController extends plattar_controller_1.PlattarController {
1297
1344
  // use product-id if available
1298
1345
  if (productID) {
1299
1346
  const variationID = this.getAttribute("variation-id");
1300
- const product = new product_ar_1.ProductAR(productID, variationID);
1347
+ const variationSKU = this.getAttribute("variation-sku");
1348
+ const product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
1301
1349
  return product.init().then(accept).catch(reject);
1302
1350
  }
1303
1351
  const sceneProductID = this.getAttribute("scene-product-id");
1304
1352
  // use scene-product-id if available
1305
1353
  if (sceneProductID) {
1306
1354
  const variationID = this.getAttribute("variation-id");
1307
- const product = new scene_product_ar_1.SceneProductAR(sceneProductID, variationID);
1355
+ const variationSKU = this.getAttribute("variation-sku");
1356
+ const product = new scene_product_ar_1.SceneProductAR(sceneProductID, variationID, variationSKU);
1308
1357
  return product.init().then(accept).catch(reject);
1309
1358
  }
1310
1359
  const sceneID = this.getAttribute("scene-id");
1311
- // use the first default product-variation id if available
1360
+ // fallback to using default SceneAR implementation
1312
1361
  if (sceneID) {
1362
+ // special case - check if scene only has a single product, if so
1363
+ // we need to use provided variation-id or variation-sku to override
1364
+ const variationID = this.getAttribute("variation-id");
1365
+ const variationSKU = this.getAttribute("variation-sku");
1366
+ // just do scene-ar if variation ID and variation SKU is not set
1367
+ if (!variationID && !variationSKU) {
1368
+ const sceneAR = new scene_ar_1.SceneAR(sceneID);
1369
+ return sceneAR.init().then(accept).catch(reject);
1370
+ }
1371
+ // otherwise decode scene
1313
1372
  return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
1314
- const first = state.first();
1315
- if (first) {
1316
- const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
1317
- return sceneProductAR.init().then(accept).catch(reject);
1373
+ const firstProduct = state.first();
1374
+ if (state.length > 1 || !firstProduct) {
1375
+ return reject(new Error("ViewerController.initAR() - single product required to override variation-id or variation-sku"));
1318
1376
  }
1319
- return reject(new Error("ViewerController.initAR() - your scene does not contain any valid products"));
1377
+ const product = new scene_product_ar_1.SceneProductAR(firstProduct.scene_product_id, variationID, variationSKU);
1378
+ return product.init().then(accept).catch(reject);
1320
1379
  }).catch(reject);
1321
1380
  }
1322
1381
  return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
@@ -1336,7 +1395,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
1336
1395
  }
1337
1396
  exports.ViewerController = ViewerController;
1338
1397
 
1339
- },{"../../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){
1398
+ },{"../../ar/product-ar":3,"../../ar/scene-ar":5,"../../ar/scene-product-ar":6,"../../util/configurator-state":14,"../../util/util":15,"./plattar-controller":8,"@plattar/plattar-api":42}],11:[function(require,module,exports){
1340
1399
  "use strict";
1341
1400
  Object.defineProperty(exports, "__esModule", { value: true });
1342
1401
  exports.VTOController = void 0;
@@ -2083,7 +2142,7 @@ exports.Util = Util;
2083
2142
  },{}],16:[function(require,module,exports){
2084
2143
  "use strict";
2085
2144
  Object.defineProperty(exports, "__esModule", { value: true });
2086
- exports.default = "1.130.1";
2145
+ exports.default = "1.131.1";
2087
2146
 
2088
2147
  },{}],17:[function(require,module,exports){
2089
2148
  "use strict";
@@ -6256,6 +6315,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6256
6315
  exports.default = "1.120.1";
6257
6316
 
6258
6317
  },{}],115:[function(require,module,exports){
6318
+ const Util = require("../../util/util");
6259
6319
  const ElementController = require("../controllers/element-controller");
6260
6320
 
6261
6321
  class BaseElement extends HTMLElement {
@@ -6393,10 +6453,14 @@ class BaseElement extends HTMLElement {
6393
6453
  get elementType() {
6394
6454
  return "none";
6395
6455
  }
6456
+
6457
+ get elementLocation() {
6458
+ return Util.getElementLocation(this.elementType);
6459
+ }
6396
6460
  }
6397
6461
 
6398
6462
  module.exports = BaseElement;
6399
- },{"../controllers/element-controller":117}],116:[function(require,module,exports){
6463
+ },{"../../util/util":128,"../controllers/element-controller":117}],116:[function(require,module,exports){
6400
6464
  const BaseElement = require("./base/base-element.js");
6401
6465
 
6402
6466
  class ConfiguratorElement extends BaseElement {
@@ -6412,6 +6476,16 @@ class ConfiguratorElement extends BaseElement {
6412
6476
  return "configurator";
6413
6477
  }
6414
6478
 
6479
+ get elementLocation() {
6480
+ if (this.hasAttribute("show-ui")) {
6481
+ const state = this.getAttribute("show-ui");
6482
+
6483
+ return state === "true" ? "configurator/dist/index.html" : super.elementLocation;
6484
+ }
6485
+
6486
+ return super.elementLocation;
6487
+ }
6488
+
6415
6489
  get optionalAttributes() {
6416
6490
  return [{
6417
6491
  key: "config-state",
@@ -6469,7 +6543,7 @@ class ElementController {
6469
6543
  throw new Error("ElementController - attribute \"server\" must be one of \"production\", \"staging\" or \"dev\"");
6470
6544
  }
6471
6545
 
6472
- const embedLocation = Util.getElementLocation(element.elementType);
6546
+ const embedLocation = element.elementLocation;
6473
6547
 
6474
6548
  if (embedLocation === undefined) {
6475
6549
  throw new Error("ElementController - element named \"" + elementType + "\" is invalid");
@@ -6559,15 +6633,7 @@ class IFrameController {
6559
6633
  if (element.hasAttribute("fullscreen")) {
6560
6634
  const style = document.createElement('style');
6561
6635
 
6562
- style.textContent = `
6563
- ._PlattarFullScreen {
6564
- width: 100%;
6565
- height: 100%;
6566
- position: absolute;
6567
- top: 0;
6568
- left: 0;
6569
- }
6570
- `;
6636
+ style.textContent = `._PlattarFullScreen { width: 100%; height: 100%; position: absolute; top: 0; left: 0; }`;
6571
6637
 
6572
6638
  this._iframe.className = "_PlattarFullScreen";
6573
6639
 
@@ -6706,6 +6772,9 @@ class FaceARElement extends BaseElement {
6706
6772
  return [{
6707
6773
  key: "variation-id",
6708
6774
  map: "variationId"
6775
+ }, {
6776
+ key: "variation-sku",
6777
+ map: "variationSku"
6709
6778
  }, {
6710
6779
  key: "product-id",
6711
6780
  map: "productId"
@@ -6772,6 +6841,9 @@ class ProductElement extends BaseElement {
6772
6841
  return [{
6773
6842
  key: "variation-id",
6774
6843
  map: "variation_id"
6844
+ }, {
6845
+ key: "variation-sku",
6846
+ map: "variationSku"
6775
6847
  }, {
6776
6848
  key: "show-ar",
6777
6849
  map: "show_ar"
@@ -6818,6 +6890,9 @@ class ViewerElement extends BaseElement {
6818
6890
  return [{
6819
6891
  key: "variation-id",
6820
6892
  map: "variationId"
6893
+ }, {
6894
+ key: "variation-sku",
6895
+ map: "variationSku"
6821
6896
  }, {
6822
6897
  key: "product-id",
6823
6898
  map: "productId"
@@ -6905,9 +6980,9 @@ module.exports = {
6905
6980
  class Util {
6906
6981
  static getServerLocation(server) {
6907
6982
  switch (server) {
6908
- case "production": return "https://app.plattar.com/renderer/";
6909
- case "staging": return "https://staging.plattar.space/renderer/";
6910
- case "dev": return "https://localhost/renderer/";
6983
+ case "production": return "https://app.plattar.com/";
6984
+ case "staging": return "https://staging.plattar.space/";
6985
+ case "dev": return "https://localhost/";
6911
6986
  default: return undefined;
6912
6987
  }
6913
6988
  }
@@ -6916,25 +6991,7 @@ class Util {
6916
6991
  const isValid = Util.isValidType(etype);
6917
6992
 
6918
6993
  if (isValid) {
6919
- return etype + ".html";
6920
- }
6921
-
6922
- return undefined;
6923
- }
6924
-
6925
- static getElementBundleLocation(etype, server) {
6926
- const location = Util.getServerLocation(server);
6927
-
6928
- if (!location) {
6929
- return undefined;
6930
- }
6931
-
6932
- const isValid = Util.isValidType(etype);
6933
-
6934
- if (isValid) {
6935
- const isMinified = location === "dev" ? false : true;
6936
-
6937
- return isMinified ? (etype + "-bundle.min.js") : (etype + "-bundle.js");
6994
+ return "renderer/" + etype + ".html";
6938
6995
  }
6939
6996
 
6940
6997
  return undefined;
@@ -6977,7 +7034,7 @@ class Util {
6977
7034
 
6978
7035
  module.exports = Util;
6979
7036
  },{}],129:[function(require,module,exports){
6980
- module.exports = "1.129.1";
7037
+ module.exports = "1.131.1";
6981
7038
 
6982
7039
  },{}],130:[function(require,module,exports){
6983
7040
  (function (global){(function (){