@plattar/plattar-ar-adapter 1.123.7 → 1.129.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.
@@ -639,9 +639,6 @@ const plattar_controller_1 = require("./plattar-controller");
639
639
  class ConfiguratorController extends plattar_controller_1.PlattarController {
640
640
  constructor(parent) {
641
641
  super(parent);
642
- this._state = plattar_controller_1.ControllerState.None;
643
- this._element = null;
644
- this._prevQROpt = null;
645
642
  }
646
643
  onAttributesUpdated() {
647
644
  const state = this._state;
@@ -651,7 +648,7 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
651
648
  return;
652
649
  }
653
650
  }
654
- startQRCode(options) {
651
+ startViewerQRCode(options) {
655
652
  return new Promise((accept, reject) => {
656
653
  // remove the old renderer instance if any
657
654
  this.removeRenderer();
@@ -852,6 +849,7 @@ exports.ConfiguratorController = ConfiguratorController;
852
849
  "use strict";
853
850
  Object.defineProperty(exports, "__esModule", { value: true });
854
851
  exports.PlattarController = exports.ControllerState = void 0;
852
+ const plattar_api_1 = require("@plattar/plattar-api");
855
853
  var ControllerState;
856
854
  (function (ControllerState) {
857
855
  ControllerState[ControllerState["None"] = 0] = "None";
@@ -863,6 +861,9 @@ var ControllerState;
863
861
  */
864
862
  class PlattarController {
865
863
  constructor(parent) {
864
+ this._state = ControllerState.None;
865
+ this._element = null;
866
+ this._prevQROpt = null;
866
867
  this._parent = parent;
867
868
  }
868
869
  /**
@@ -887,6 +888,86 @@ class PlattarController {
887
888
  }).catch(reject);
888
889
  });
889
890
  }
891
+ /**
892
+ * Decide which QR Code to render according to the qr-type attribute
893
+ * @param options
894
+ * @returns
895
+ */
896
+ startQRCode(options) {
897
+ const qrType = this.getAttribute("qr-type") || "viewer";
898
+ switch (qrType.toLowerCase()) {
899
+ case "ar":
900
+ return this.startARQRCode(options);
901
+ case "viewer":
902
+ default:
903
+ return this.startViewerQRCode(options);
904
+ }
905
+ }
906
+ /**
907
+ * Displays a QR Code that sends the user direct to AR
908
+ * @param options
909
+ * @returns
910
+ */
911
+ startARQRCode(options) {
912
+ return new Promise((accept, reject) => {
913
+ // remove the old renderer instance if any
914
+ this.removeRenderer();
915
+ const opt = options || PlattarController.DEFAULT_QR_OPTIONS;
916
+ const viewer = document.createElement("plattar-qrcode");
917
+ // required attributes with defaults for plattar-viewer node
918
+ const width = this.getAttribute("width") || "500px";
919
+ const height = this.getAttribute("height") || "500px";
920
+ viewer.setAttribute("width", width);
921
+ viewer.setAttribute("height", height);
922
+ if (opt.color) {
923
+ viewer.setAttribute("color", opt.color);
924
+ }
925
+ if (opt.margin) {
926
+ viewer.setAttribute("margin", "" + opt.margin);
927
+ }
928
+ if (opt.qrType) {
929
+ viewer.setAttribute("qr-type", opt.qrType);
930
+ }
931
+ const qrOptions = btoa(JSON.stringify(opt));
932
+ let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
933
+ const sceneID = this.getAttribute("scene-id");
934
+ const configState = this.getAttribute("config-state");
935
+ const embedType = this.getAttribute("embed-type");
936
+ const productID = this.getAttribute("product-id");
937
+ const sceneProductID = this.getAttribute("scene-product-id");
938
+ const variationID = this.getAttribute("variation-id");
939
+ const arMode = this.getAttribute("ar-mode");
940
+ if (configState) {
941
+ dst += "&config_state=" + configState;
942
+ }
943
+ if (embedType) {
944
+ dst += "&embed_type=" + embedType;
945
+ }
946
+ if (productID) {
947
+ dst += "&product_id=" + productID;
948
+ }
949
+ if (sceneProductID) {
950
+ dst += "&scene_product_id=" + sceneProductID;
951
+ }
952
+ if (variationID) {
953
+ dst += "&variation_id=" + variationID;
954
+ }
955
+ if (arMode) {
956
+ dst += "&ar_mode=" + arMode;
957
+ }
958
+ if (sceneID) {
959
+ dst += "&scene_id=" + sceneID;
960
+ }
961
+ viewer.setAttribute("url", opt.url || dst);
962
+ viewer.onload = () => {
963
+ return accept(viewer);
964
+ };
965
+ this._element = viewer;
966
+ this._state = ControllerState.QRCode;
967
+ this._prevQROpt = opt;
968
+ this.append(viewer);
969
+ });
970
+ }
890
971
  /**
891
972
  * Returns the Parent Instance
892
973
  */
@@ -912,7 +993,7 @@ class PlattarController {
912
993
  }
913
994
  exports.PlattarController = PlattarController;
914
995
 
915
- },{}],9:[function(require,module,exports){
996
+ },{"@plattar/plattar-api":42}],9:[function(require,module,exports){
916
997
  "use strict";
917
998
  Object.defineProperty(exports, "__esModule", { value: true });
918
999
  exports.ProductController = void 0;
@@ -926,9 +1007,6 @@ const plattar_controller_1 = require("./plattar-controller");
926
1007
  class ProductController extends plattar_controller_1.PlattarController {
927
1008
  constructor(parent) {
928
1009
  super(parent);
929
- this._state = plattar_controller_1.ControllerState.None;
930
- this._element = null;
931
- this._prevQROpt = null;
932
1010
  }
933
1011
  onAttributesUpdated() {
934
1012
  const state = this._state;
@@ -949,7 +1027,7 @@ class ProductController extends plattar_controller_1.PlattarController {
949
1027
  return;
950
1028
  }
951
1029
  }
952
- startQRCode(options) {
1030
+ startViewerQRCode(options) {
953
1031
  return new Promise((accept, reject) => {
954
1032
  // remove the old renderer instance if any
955
1033
  this.removeRenderer();
@@ -973,10 +1051,14 @@ class ProductController extends plattar_controller_1.PlattarController {
973
1051
  }
974
1052
  // optional attributes
975
1053
  const variationID = this.getAttribute("variation-id");
1054
+ const showAR = this.getAttribute("show-ar");
976
1055
  let dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
977
1056
  if (variationID) {
978
1057
  dst += "&variation_id=" + variationID;
979
1058
  }
1059
+ if (showAR) {
1060
+ dst += "&show_ar=" + showAR;
1061
+ }
980
1062
  viewer.setAttribute("url", opt.url || dst);
981
1063
  viewer.onload = () => {
982
1064
  return accept(viewer);
@@ -1007,9 +1089,13 @@ class ProductController extends plattar_controller_1.PlattarController {
1007
1089
  viewer.setAttribute("product-id", productID);
1008
1090
  // optional attributes
1009
1091
  const variationID = this.getAttribute("variation-id");
1092
+ const showAR = this.getAttribute("show-ar");
1010
1093
  if (variationID) {
1011
1094
  viewer.setAttribute("variation-id", variationID);
1012
1095
  }
1096
+ if (showAR) {
1097
+ viewer.setAttribute("show-ar", showAR);
1098
+ }
1013
1099
  viewer.onload = () => {
1014
1100
  return accept(viewer);
1015
1101
  };
@@ -1056,6 +1142,7 @@ exports.ViewerController = void 0;
1056
1142
  const plattar_api_1 = require("@plattar/plattar-api");
1057
1143
  const product_ar_1 = require("../../ar/product-ar");
1058
1144
  const scene_product_ar_1 = require("../../ar/scene-product-ar");
1145
+ const configurator_state_1 = require("../../util/configurator-state");
1059
1146
  const util_1 = require("../../util/util");
1060
1147
  const plattar_controller_1 = require("./plattar-controller");
1061
1148
  /**
@@ -1064,9 +1151,6 @@ const plattar_controller_1 = require("./plattar-controller");
1064
1151
  class ViewerController extends plattar_controller_1.PlattarController {
1065
1152
  constructor(parent) {
1066
1153
  super(parent);
1067
- this._state = plattar_controller_1.ControllerState.None;
1068
- this._element = null;
1069
- this._prevQROpt = null;
1070
1154
  }
1071
1155
  onAttributesUpdated() {
1072
1156
  const state = this._state;
@@ -1088,7 +1172,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
1088
1172
  return;
1089
1173
  }
1090
1174
  }
1091
- startQRCode(options) {
1175
+ startViewerQRCode(options) {
1092
1176
  return new Promise((accept, reject) => {
1093
1177
  // remove the old renderer instance if any
1094
1178
  this.removeRenderer();
@@ -1114,12 +1198,16 @@ class ViewerController extends plattar_controller_1.PlattarController {
1114
1198
  // optional attributes
1115
1199
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
1116
1200
  const variationID = this.getAttribute("variation-id");
1201
+ const showAR = this.getAttribute("show-ar");
1117
1202
  if (productID) {
1118
1203
  dst += "&productId=" + productID;
1119
1204
  }
1120
1205
  if (variationID) {
1121
1206
  dst += "&variationId=" + variationID;
1122
1207
  }
1208
+ if (showAR) {
1209
+ dst += "&show_ar=" + showAR;
1210
+ }
1123
1211
  viewer.setAttribute("url", opt.url || dst);
1124
1212
  viewer.onload = () => {
1125
1213
  return accept(viewer);
@@ -1151,12 +1239,16 @@ class ViewerController extends plattar_controller_1.PlattarController {
1151
1239
  // optional attributes
1152
1240
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
1153
1241
  const variationID = this.getAttribute("variation-id");
1242
+ const showAR = this.getAttribute("show-ar");
1154
1243
  if (productID) {
1155
1244
  viewer.setAttribute("product-id", productID);
1156
1245
  }
1157
1246
  if (variationID) {
1158
1247
  viewer.setAttribute("variation-id", variationID);
1159
1248
  }
1249
+ if (showAR) {
1250
+ viewer.setAttribute("show-ar", showAR);
1251
+ }
1160
1252
  viewer.onload = () => {
1161
1253
  return accept(viewer);
1162
1254
  };
@@ -1188,11 +1280,18 @@ class ViewerController extends plattar_controller_1.PlattarController {
1188
1280
  return product.init().then(accept).catch(reject);
1189
1281
  }
1190
1282
  const sceneID = this.getAttribute("scene-id");
1191
- // otherwise, scene was set so use SceneAR
1283
+ // use the first default product-variation id if available
1192
1284
  if (sceneID) {
1193
- return reject(new Error("ViewerController.initAR() - AR mode for scene-id not yet supported, use product-id or scene-product-id"));
1285
+ return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
1286
+ const first = state.first();
1287
+ if (first) {
1288
+ const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
1289
+ return sceneProductAR.init().then(accept).catch(reject);
1290
+ }
1291
+ return reject(new Error("ViewerController.initAR() - your scene does not contain any valid products"));
1292
+ }).catch(reject);
1194
1293
  }
1195
- return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use product-id or scene-product-id as a minimum"));
1294
+ return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1196
1295
  });
1197
1296
  }
1198
1297
  removeRenderer() {
@@ -1209,7 +1308,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
1209
1308
  }
1210
1309
  exports.ViewerController = ViewerController;
1211
1310
 
1212
- },{"../../ar/product-ar":3,"../../ar/scene-product-ar":6,"../../util/util":15,"./plattar-controller":8,"@plattar/plattar-api":42}],11:[function(require,module,exports){
1311
+ },{"../../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){
1213
1312
  "use strict";
1214
1313
  Object.defineProperty(exports, "__esModule", { value: true });
1215
1314
  exports.VTOController = void 0;
@@ -1225,9 +1324,6 @@ const plattar_controller_1 = require("./plattar-controller");
1225
1324
  class VTOController extends plattar_controller_1.PlattarController {
1226
1325
  constructor(parent) {
1227
1326
  super(parent);
1228
- this._state = plattar_controller_1.ControllerState.None;
1229
- this._element = null;
1230
- this._prevQROpt = null;
1231
1327
  }
1232
1328
  onAttributesUpdated() {
1233
1329
  const state = this._state;
@@ -1237,7 +1333,7 @@ class VTOController extends plattar_controller_1.PlattarController {
1237
1333
  return;
1238
1334
  }
1239
1335
  }
1240
- startQRCode(options) {
1336
+ startViewerQRCode(options) {
1241
1337
  return new Promise((accept, reject) => {
1242
1338
  // remove the old renderer instance if any
1243
1339
  this.removeRenderer();
@@ -1590,7 +1686,11 @@ exports.default = PlattarEmbed;
1590
1686
  "use strict";
1591
1687
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1592
1688
  if (k2 === undefined) k2 = k;
1593
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
1689
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1690
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1691
+ desc = { enumerable: true, get: function() { return m[k]; } };
1692
+ }
1693
+ Object.defineProperty(o, k2, desc);
1594
1694
  }) : (function(o, m, k, k2) {
1595
1695
  if (k2 === undefined) k2 = k;
1596
1696
  o[k2] = m[k];
@@ -1953,7 +2053,7 @@ exports.Util = Util;
1953
2053
  },{}],16:[function(require,module,exports){
1954
2054
  "use strict";
1955
2055
  Object.defineProperty(exports, "__esModule", { value: true });
1956
- exports.default = "1.123.7";
2056
+ exports.default = "1.129.1";
1957
2057
 
1958
2058
  },{}],17:[function(require,module,exports){
1959
2059
  "use strict";
@@ -3366,7 +3466,11 @@ exports.Analytics = Analytics;
3366
3466
  "use strict";
3367
3467
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3368
3468
  if (k2 === undefined) k2 = k;
3369
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3469
+ var desc = Object.getOwnPropertyDescriptor(m, k);
3470
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
3471
+ desc = { enumerable: true, get: function() { return m[k]; } };
3472
+ }
3473
+ Object.defineProperty(o, k2, desc);
3370
3474
  }) : (function(o, m, k, k2) {
3371
3475
  if (k2 === undefined) k2 = k;
3372
3476
  o[k2] = m[k];
@@ -3489,7 +3593,7 @@ exports.Util = Util;
3489
3593
  },{}],41:[function(require,module,exports){
3490
3594
  "use strict";
3491
3595
  Object.defineProperty(exports, "__esModule", { value: true });
3492
- exports.default = "1.117.2";
3596
+ exports.default = "1.124.1";
3493
3597
 
3494
3598
  },{}],42:[function(require,module,exports){
3495
3599
  "use strict";
@@ -6531,7 +6635,7 @@ class EWallElement extends BaseElement {
6531
6635
  }
6532
6636
  }
6533
6637
 
6534
- window.addEventListener('load', onLoad, false)
6638
+ window.addEventListener("load", onLoad, false)
6535
6639
  }
6536
6640
 
6537
6641
  get permissions() {
@@ -6630,6 +6734,9 @@ class ProductElement extends BaseElement {
6630
6734
  return [{
6631
6735
  key: "variation-id",
6632
6736
  map: "variation_id"
6737
+ }, {
6738
+ key: "show-ar",
6739
+ map: "show_ar"
6633
6740
  }];
6634
6741
  }
6635
6742
  }
@@ -6676,6 +6783,9 @@ class ViewerElement extends BaseElement {
6676
6783
  }, {
6677
6784
  key: "product-id",
6678
6785
  map: "productId"
6786
+ }, {
6787
+ key: "show-ar",
6788
+ map: "show_ar"
6679
6789
  }];
6680
6790
  }
6681
6791
  }
@@ -6829,7 +6939,7 @@ class Util {
6829
6939
 
6830
6940
  module.exports = Util;
6831
6941
  },{}],129:[function(require,module,exports){
6832
- module.exports = "1.123.1";
6942
+ module.exports = "1.128.1";
6833
6943
 
6834
6944
  },{}],130:[function(require,module,exports){
6835
6945
  (function (global){(function (){