@plattar/plattar-ar-adapter 1.128.1 → 1.130.2

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.
@@ -3,7 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.LauncherAR = void 0;
5
5
  class LauncherAR {
6
- constructor() { }
6
+ constructor() {
7
+ this._opt = {
8
+ anchor: "horizontal_vertical"
9
+ };
10
+ }
7
11
  /**
8
12
  * Initialise and launch with a single function call. this is mostly for convenience.
9
13
  * Use .init() and .start() separately for fine-grained control
@@ -16,6 +20,12 @@ class LauncherAR {
16
20
  }).catch(reject);
17
21
  });
18
22
  }
23
+ /**
24
+ * AR Options used for launching AR
25
+ */
26
+ get options() {
27
+ return this._opt;
28
+ }
19
29
  }
20
30
  exports.LauncherAR = LauncherAR;
21
31
 
@@ -102,8 +112,10 @@ class ModelAR extends launcher_ar_1.LauncherAR {
102
112
  }
103
113
  // check android
104
114
  if (util_1.Util.canSceneViewer()) {
105
- this._ar = new scene_viewer_1.default();
106
- this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
115
+ const arviewer = new scene_viewer_1.default();
116
+ arviewer.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
117
+ arviewer.isVertical = this.options.anchor === "vertical" ? true : false;
118
+ this._ar = arviewer;
107
119
  return accept(this);
108
120
  }
109
121
  // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
@@ -267,8 +279,17 @@ class ProductAR extends launcher_ar_1.LauncherAR {
267
279
  }
268
280
  // check android
269
281
  if (util_1.Util.canSceneViewer()) {
270
- this._ar = new scene_viewer_1.default();
271
- this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
282
+ const arviewer = new scene_viewer_1.default();
283
+ arviewer.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
284
+ arviewer.isVertical = this.options.anchor === "vertical" ? true : false;
285
+ const scene = product.relationships.find(plattar_api_1.Scene);
286
+ if (scene) {
287
+ const sceneOpt = scene.attributes.custom_json || {};
288
+ if (sceneOpt.anchor === "vertical") {
289
+ arviewer.isVertical = true;
290
+ }
291
+ }
292
+ this._ar = arviewer;
272
293
  return accept(this);
273
294
  }
274
295
  // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
@@ -374,8 +395,10 @@ class RawAR extends launcher_ar_1.LauncherAR {
374
395
  // check android
375
396
  if (util_1.Util.canSceneViewer()) {
376
397
  if (lowerLoc.endsWith("glb") || lowerLoc.endsWith("gltf")) {
377
- this._ar = new scene_viewer_1.default();
378
- this._ar.modelUrl = modelLocation;
398
+ const arviewer = new scene_viewer_1.default();
399
+ arviewer.modelUrl = modelLocation;
400
+ arviewer.isVertical = this.options.anchor === "vertical" ? true : false;
401
+ this._ar = arviewer;
379
402
  return accept(this);
380
403
  }
381
404
  return reject(new Error("RawAR.init() - cannot proceed as model is not a .glb or .gltf file"));
@@ -533,8 +556,13 @@ class SceneAR extends launcher_ar_1.LauncherAR {
533
556
  // check android
534
557
  if (util_1.Util.canSceneViewer()) {
535
558
  return this._ComposeScene(scene, "glb").then((modelUrl) => {
536
- this._ar = new scene_viewer_1.default();
537
- this._ar.modelUrl = modelUrl;
559
+ const arviewer = new scene_viewer_1.default();
560
+ arviewer.modelUrl = modelUrl;
561
+ arviewer.isVertical = this.options.anchor === "vertical" ? true : false;
562
+ if (sceneOpt.anchor === "vertical") {
563
+ arviewer.isVertical = true;
564
+ }
565
+ this._ar = arviewer;
538
566
  return accept(this);
539
567
  }).catch(reject);
540
568
  }
@@ -639,9 +667,6 @@ const plattar_controller_1 = require("./plattar-controller");
639
667
  class ConfiguratorController extends plattar_controller_1.PlattarController {
640
668
  constructor(parent) {
641
669
  super(parent);
642
- this._state = plattar_controller_1.ControllerState.None;
643
- this._element = null;
644
- this._prevQROpt = null;
645
670
  }
646
671
  onAttributesUpdated() {
647
672
  const state = this._state;
@@ -651,7 +676,7 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
651
676
  return;
652
677
  }
653
678
  }
654
- startQRCode(options) {
679
+ startViewerQRCode(options) {
655
680
  return new Promise((accept, reject) => {
656
681
  // remove the old renderer instance if any
657
682
  this.removeRenderer();
@@ -852,6 +877,7 @@ exports.ConfiguratorController = ConfiguratorController;
852
877
  "use strict";
853
878
  Object.defineProperty(exports, "__esModule", { value: true });
854
879
  exports.PlattarController = exports.ControllerState = void 0;
880
+ const plattar_api_1 = require("@plattar/plattar-api");
855
881
  var ControllerState;
856
882
  (function (ControllerState) {
857
883
  ControllerState[ControllerState["None"] = 0] = "None";
@@ -863,6 +889,9 @@ var ControllerState;
863
889
  */
864
890
  class PlattarController {
865
891
  constructor(parent) {
892
+ this._state = ControllerState.None;
893
+ this._element = null;
894
+ this._prevQROpt = null;
866
895
  this._parent = parent;
867
896
  }
868
897
  /**
@@ -887,6 +916,86 @@ class PlattarController {
887
916
  }).catch(reject);
888
917
  });
889
918
  }
919
+ /**
920
+ * Decide which QR Code to render according to the qr-type attribute
921
+ * @param options
922
+ * @returns
923
+ */
924
+ startQRCode(options) {
925
+ const qrType = this.getAttribute("qr-type") || "viewer";
926
+ switch (qrType.toLowerCase()) {
927
+ case "ar":
928
+ return this.startARQRCode(options);
929
+ case "viewer":
930
+ default:
931
+ return this.startViewerQRCode(options);
932
+ }
933
+ }
934
+ /**
935
+ * Displays a QR Code that sends the user direct to AR
936
+ * @param options
937
+ * @returns
938
+ */
939
+ startARQRCode(options) {
940
+ return new Promise((accept, reject) => {
941
+ // remove the old renderer instance if any
942
+ this.removeRenderer();
943
+ const opt = options || PlattarController.DEFAULT_QR_OPTIONS;
944
+ const viewer = document.createElement("plattar-qrcode");
945
+ // required attributes with defaults for plattar-viewer node
946
+ const width = this.getAttribute("width") || "500px";
947
+ const height = this.getAttribute("height") || "500px";
948
+ viewer.setAttribute("width", width);
949
+ viewer.setAttribute("height", height);
950
+ if (opt.color) {
951
+ viewer.setAttribute("color", opt.color);
952
+ }
953
+ if (opt.margin) {
954
+ viewer.setAttribute("margin", "" + opt.margin);
955
+ }
956
+ if (opt.qrType) {
957
+ viewer.setAttribute("qr-type", opt.qrType);
958
+ }
959
+ const qrOptions = btoa(JSON.stringify(opt));
960
+ let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
961
+ const sceneID = this.getAttribute("scene-id");
962
+ const configState = this.getAttribute("config-state");
963
+ const embedType = this.getAttribute("embed-type");
964
+ const productID = this.getAttribute("product-id");
965
+ const sceneProductID = this.getAttribute("scene-product-id");
966
+ const variationID = this.getAttribute("variation-id");
967
+ const arMode = this.getAttribute("ar-mode");
968
+ if (configState) {
969
+ dst += "&config_state=" + configState;
970
+ }
971
+ if (embedType) {
972
+ dst += "&embed_type=" + embedType;
973
+ }
974
+ if (productID) {
975
+ dst += "&product_id=" + productID;
976
+ }
977
+ if (sceneProductID) {
978
+ dst += "&scene_product_id=" + sceneProductID;
979
+ }
980
+ if (variationID) {
981
+ dst += "&variation_id=" + variationID;
982
+ }
983
+ if (arMode) {
984
+ dst += "&ar_mode=" + arMode;
985
+ }
986
+ if (sceneID) {
987
+ dst += "&scene_id=" + sceneID;
988
+ }
989
+ viewer.setAttribute("url", opt.url || dst);
990
+ viewer.onload = () => {
991
+ return accept(viewer);
992
+ };
993
+ this._element = viewer;
994
+ this._state = ControllerState.QRCode;
995
+ this._prevQROpt = opt;
996
+ this.append(viewer);
997
+ });
998
+ }
890
999
  /**
891
1000
  * Returns the Parent Instance
892
1001
  */
@@ -912,7 +1021,7 @@ class PlattarController {
912
1021
  }
913
1022
  exports.PlattarController = PlattarController;
914
1023
 
915
- },{}],9:[function(require,module,exports){
1024
+ },{"@plattar/plattar-api":42}],9:[function(require,module,exports){
916
1025
  "use strict";
917
1026
  Object.defineProperty(exports, "__esModule", { value: true });
918
1027
  exports.ProductController = void 0;
@@ -926,9 +1035,6 @@ const plattar_controller_1 = require("./plattar-controller");
926
1035
  class ProductController extends plattar_controller_1.PlattarController {
927
1036
  constructor(parent) {
928
1037
  super(parent);
929
- this._state = plattar_controller_1.ControllerState.None;
930
- this._element = null;
931
- this._prevQROpt = null;
932
1038
  }
933
1039
  onAttributesUpdated() {
934
1040
  const state = this._state;
@@ -949,7 +1055,7 @@ class ProductController extends plattar_controller_1.PlattarController {
949
1055
  return;
950
1056
  }
951
1057
  }
952
- startQRCode(options) {
1058
+ startViewerQRCode(options) {
953
1059
  return new Promise((accept, reject) => {
954
1060
  // remove the old renderer instance if any
955
1061
  this.removeRenderer();
@@ -1063,8 +1169,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
1063
1169
  exports.ViewerController = void 0;
1064
1170
  const plattar_api_1 = require("@plattar/plattar-api");
1065
1171
  const product_ar_1 = require("../../ar/product-ar");
1172
+ const scene_ar_1 = require("../../ar/scene-ar");
1066
1173
  const scene_product_ar_1 = require("../../ar/scene-product-ar");
1067
- const configurator_state_1 = require("../../util/configurator-state");
1068
1174
  const util_1 = require("../../util/util");
1069
1175
  const plattar_controller_1 = require("./plattar-controller");
1070
1176
  /**
@@ -1073,9 +1179,6 @@ const plattar_controller_1 = require("./plattar-controller");
1073
1179
  class ViewerController extends plattar_controller_1.PlattarController {
1074
1180
  constructor(parent) {
1075
1181
  super(parent);
1076
- this._state = plattar_controller_1.ControllerState.None;
1077
- this._element = null;
1078
- this._prevQROpt = null;
1079
1182
  }
1080
1183
  onAttributesUpdated() {
1081
1184
  const state = this._state;
@@ -1097,7 +1200,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
1097
1200
  return;
1098
1201
  }
1099
1202
  }
1100
- startQRCode(options) {
1203
+ startViewerQRCode(options) {
1101
1204
  return new Promise((accept, reject) => {
1102
1205
  // remove the old renderer instance if any
1103
1206
  this.removeRenderer();
@@ -1205,16 +1308,11 @@ class ViewerController extends plattar_controller_1.PlattarController {
1205
1308
  return product.init().then(accept).catch(reject);
1206
1309
  }
1207
1310
  const sceneID = this.getAttribute("scene-id");
1208
- // use the first default product-variation id if available
1311
+ // fallback to using default SceneAR implementation
1209
1312
  if (sceneID) {
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);
1313
+ const sceneAR = new scene_ar_1.SceneAR(sceneID);
1314
+ sceneAR.init().then(accept).catch(reject);
1315
+ return;
1218
1316
  }
1219
1317
  return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
1220
1318
  });
@@ -1233,7 +1331,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
1233
1331
  }
1234
1332
  exports.ViewerController = ViewerController;
1235
1333
 
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){
1334
+ },{"../../ar/product-ar":3,"../../ar/scene-ar":5,"../../ar/scene-product-ar":6,"../../util/util":15,"./plattar-controller":8,"@plattar/plattar-api":42}],11:[function(require,module,exports){
1237
1335
  "use strict";
1238
1336
  Object.defineProperty(exports, "__esModule", { value: true });
1239
1337
  exports.VTOController = void 0;
@@ -1249,9 +1347,6 @@ const plattar_controller_1 = require("./plattar-controller");
1249
1347
  class VTOController extends plattar_controller_1.PlattarController {
1250
1348
  constructor(parent) {
1251
1349
  super(parent);
1252
- this._state = plattar_controller_1.ControllerState.None;
1253
- this._element = null;
1254
- this._prevQROpt = null;
1255
1350
  }
1256
1351
  onAttributesUpdated() {
1257
1352
  const state = this._state;
@@ -1261,7 +1356,7 @@ class VTOController extends plattar_controller_1.PlattarController {
1261
1356
  return;
1262
1357
  }
1263
1358
  }
1264
- startQRCode(options) {
1359
+ startViewerQRCode(options) {
1265
1360
  return new Promise((accept, reject) => {
1266
1361
  // remove the old renderer instance if any
1267
1362
  this.removeRenderer();
@@ -1639,10 +1734,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1639
1734
  return (mod && mod.__esModule) ? mod : { "default": mod };
1640
1735
  };
1641
1736
  Object.defineProperty(exports, "__esModule", { value: true });
1642
- exports.ConfiguratorState = exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.SceneProductAR = exports.ProductAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
1737
+ exports.ConfiguratorState = exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.SceneProductAR = exports.ProductAR = exports.LauncherAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
1643
1738
  exports.PlattarWeb = __importStar(require("@plattar/plattar-web"));
1644
1739
  exports.PlattarQRCode = __importStar(require("@plattar/plattar-qrcode"));
1645
1740
  exports.version = __importStar(require("./version"));
1741
+ var launcher_ar_1 = require("./ar/launcher-ar");
1742
+ Object.defineProperty(exports, "LauncherAR", { enumerable: true, get: function () { return launcher_ar_1.LauncherAR; } });
1646
1743
  var product_ar_1 = require("./ar/product-ar");
1647
1744
  Object.defineProperty(exports, "ProductAR", { enumerable: true, get: function () { return product_ar_1.ProductAR; } });
1648
1745
  var scene_product_ar_1 = require("./ar/scene-product-ar");
@@ -1666,7 +1763,7 @@ if (customElements) {
1666
1763
  }
1667
1764
  console.log("using @plattar/plattar-ar-adapter v" + version_1.default);
1668
1765
 
1669
- },{"./ar/model-ar":2,"./ar/product-ar":3,"./ar/raw-ar":4,"./ar/scene-ar":5,"./ar/scene-product-ar":6,"./embed/plattar-embed":12,"./util/configurator-state":14,"./util/util":15,"./version":16,"@plattar/plattar-qrcode":108,"@plattar/plattar-web":127}],14:[function(require,module,exports){
1766
+ },{"./ar/launcher-ar":1,"./ar/model-ar":2,"./ar/product-ar":3,"./ar/raw-ar":4,"./ar/scene-ar":5,"./ar/scene-product-ar":6,"./embed/plattar-embed":12,"./util/configurator-state":14,"./util/util":15,"./version":16,"@plattar/plattar-qrcode":108,"@plattar/plattar-web":127}],14:[function(require,module,exports){
1670
1767
  "use strict";
1671
1768
  Object.defineProperty(exports, "__esModule", { value: true });
1672
1769
  exports.ConfiguratorState = void 0;
@@ -1981,7 +2078,7 @@ exports.Util = Util;
1981
2078
  },{}],16:[function(require,module,exports){
1982
2079
  "use strict";
1983
2080
  Object.defineProperty(exports, "__esModule", { value: true });
1984
- exports.default = "1.128.1";
2081
+ exports.default = "1.130.2";
1985
2082
 
1986
2083
  },{}],17:[function(require,module,exports){
1987
2084
  "use strict";
@@ -6183,6 +6280,10 @@ class BaseElement extends HTMLElement {
6183
6280
  return this._controller ? this._controller.context : undefined;
6184
6281
  }
6185
6282
 
6283
+ get parent() {
6284
+ return this._controller ? this._controller.parent : undefined;
6285
+ }
6286
+
6186
6287
  get element() {
6187
6288
  return this._controller;
6188
6289
  }
@@ -6405,6 +6506,10 @@ class ElementController {
6405
6506
  return messenger.self;
6406
6507
  }
6407
6508
 
6509
+ get parent() {
6510
+ return messenger.parent;
6511
+ }
6512
+
6408
6513
  get controller() {
6409
6514
  return this._controller;
6410
6515
  }
@@ -6867,7 +6972,7 @@ class Util {
6867
6972
 
6868
6973
  module.exports = Util;
6869
6974
  },{}],129:[function(require,module,exports){
6870
- module.exports = "1.128.1";
6975
+ module.exports = "1.129.1";
6871
6976
 
6872
6977
  },{}],130:[function(require,module,exports){
6873
6978
  (function (global){(function (){