@plattar/plattar-ar-adapter 1.130.3 → 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.
@@ -24,17 +24,17 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
24
24
 
25
25
  function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
26
26
 
27
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
27
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
28
28
 
29
29
  function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
30
30
 
31
- function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
31
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
32
32
 
33
33
  function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
34
34
 
35
35
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
36
36
 
37
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
37
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
38
38
 
39
39
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
40
40
 
@@ -44,7 +44,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
44
44
 
45
45
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
46
46
 
47
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
47
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
48
48
 
49
49
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
50
50
 
@@ -394,6 +394,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
394
394
 
395
395
  var productID = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
396
396
  var variationID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
397
+ var variationSKU = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
397
398
 
398
399
  _classCallCheck(this, ProductAR);
399
400
 
@@ -406,7 +407,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
406
407
  }
407
408
 
408
409
  _this4._productID = productID;
409
- _this4._variationID = variationID ? variationID : "default";
410
+ _this4._variationSKU = variationSKU;
411
+ _this4._variationID = variationID ? variationID : variationSKU ? null : "default";
410
412
  _this4._ar = null;
411
413
  return _this4;
412
414
  }
@@ -421,6 +423,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
421
423
  get: function get() {
422
424
  return this._variationID;
423
425
  }
426
+ }, {
427
+ key: "variationSKU",
428
+ get: function get() {
429
+ return this._variationSKU;
430
+ }
424
431
  }, {
425
432
  key: "_SetupAnalytics",
426
433
  value: function _SetupAnalytics(product, variation) {
@@ -478,16 +485,33 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
478
485
  product.include(plattar_api_1.Scene.include(plattar_api_1.Project));
479
486
  product.get().then(function (product) {
480
487
  // find the required variation from our product
481
- var variationID = _this5.variationID ? _this5.variationID === "default" ? product.attributes.product_variation_id : _this5.variationID : product.attributes.product_variation_id;
488
+ var variationID = _this5.variationID ? _this5.variationID === "default" ? product.attributes.product_variation_id : _this5.variationID : null;
489
+ var variationSKU = _this5.variationSKU;
482
490
 
483
- if (!variationID) {
484
- return reject(new Error("ProductAR.init() - cannot proceed as variation was not defined correctly"));
491
+ if (!variationID && !variationSKU) {
492
+ return reject(new Error("ProductAR.init() - cannot proceed as variation-id or variation-sku was not set correctly"));
485
493
  }
486
494
 
487
- var variation = product.relationships.find(plattar_api_1.ProductVariation, variationID); // make sure our variation is actually available before moving forward
495
+ var variation = undefined;
496
+
497
+ if (variationID) {
498
+ variation = product.relationships.find(plattar_api_1.ProductVariation, variationID);
499
+ } // if no variation was found with variationID - try searching variation sku
500
+
501
+
502
+ if (!variation && variationSKU) {
503
+ var variations = product.relationships.filter(plattar_api_1.ProductVariation);
504
+
505
+ if (variations) {
506
+ variation = variations.find(function (element) {
507
+ return element.attributes.sku === variationSKU;
508
+ });
509
+ }
510
+ } // make sure our variation is actually available before moving forward
511
+
488
512
 
489
513
  if (!variation) {
490
- return reject(new Error("ProductAR.init() - cannot proceed as variation with id " + variationID + " cannot be found"));
514
+ return reject(new Error("ProductAR.init() - cannot proceed as variation with id " + variationID + " or sku " + variationSKU + " cannot be found"));
491
515
  } // otherwise both the product and variation are available
492
516
  // we need to figure out if we can actually do AR though
493
517
  // check if variation has a model file defined
@@ -1044,10 +1068,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1044
1068
 
1045
1069
  var sceneProductID = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1046
1070
  var variationID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1071
+ var variationSKU = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1047
1072
 
1048
1073
  _classCallCheck(this, SceneProductAR);
1049
1074
 
1050
- _this10 = _super5.call(this, sceneProductID, variationID); // this is evaluated in the init() function
1075
+ _this10 = _super5.call(this, sceneProductID, variationID, variationSKU); // this is evaluated in the init() function
1051
1076
 
1052
1077
  _this10._attachedProductID = null;
1053
1078
 
@@ -1571,6 +1596,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1571
1596
 
1572
1597
  var variationID = _this16.getAttribute("variation-id");
1573
1598
 
1599
+ var variationSKU = _this16.getAttribute("variation-sku");
1600
+
1574
1601
  var arMode = _this16.getAttribute("ar-mode");
1575
1602
 
1576
1603
  if (configState) {
@@ -1593,6 +1620,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1593
1620
  dst += "&variation_id=" + variationID;
1594
1621
  }
1595
1622
 
1623
+ if (variationSKU) {
1624
+ dst += "&variation_sku=" + variationSKU;
1625
+ }
1626
+
1596
1627
  if (arMode) {
1597
1628
  dst += "&ar_mode=" + arMode;
1598
1629
  }
@@ -1756,12 +1787,18 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1756
1787
 
1757
1788
  var variationID = _this17.getAttribute("variation-id");
1758
1789
 
1790
+ var variationSKU = _this17.getAttribute("variation-sku");
1791
+
1759
1792
  var showAR = _this17.getAttribute("show-ar");
1760
1793
 
1761
1794
  var dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
1762
1795
 
1763
1796
  if (variationID) {
1764
- dst += "&variation_id=" + variationID;
1797
+ dst += "&variationId=" + variationID;
1798
+ }
1799
+
1800
+ if (variationSKU) {
1801
+ dst += "&variationSku=" + variationSKU;
1765
1802
  }
1766
1803
 
1767
1804
  if (showAR) {
@@ -1809,12 +1846,18 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1809
1846
 
1810
1847
  var variationID = _this18.getAttribute("variation-id");
1811
1848
 
1849
+ var variationSKU = _this18.getAttribute("variation-sku");
1850
+
1812
1851
  var showAR = _this18.getAttribute("show-ar");
1813
1852
 
1814
1853
  if (variationID) {
1815
1854
  viewer.setAttribute("variation-id", variationID);
1816
1855
  }
1817
1856
 
1857
+ if (variationSKU) {
1858
+ viewer.setAttribute("variation-sku", variationSKU);
1859
+ }
1860
+
1818
1861
  if (showAR) {
1819
1862
  viewer.setAttribute("show-ar", showAR);
1820
1863
  }
@@ -1848,7 +1891,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1848
1891
  if (productID) {
1849
1892
  var variationID = _this19.getAttribute("variation-id");
1850
1893
 
1851
- var product = new product_ar_1.ProductAR(productID, variationID);
1894
+ var variationSKU = _this19.getAttribute("variation-sku");
1895
+
1896
+ var product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
1852
1897
  return product.init().then(accept)["catch"](reject);
1853
1898
  }
1854
1899
 
@@ -1900,6 +1945,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1900
1945
 
1901
1946
  var scene_product_ar_1 = require("../../ar/scene-product-ar");
1902
1947
 
1948
+ var configurator_state_1 = require("../../util/configurator-state");
1949
+
1903
1950
  var util_1 = require("../../util/util");
1904
1951
 
1905
1952
  var plattar_controller_1 = require("./plattar-controller");
@@ -1983,6 +2030,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1983
2030
 
1984
2031
  var variationID = _this20.getAttribute("variation-id");
1985
2032
 
2033
+ var variationSKU = _this20.getAttribute("variation-sku");
2034
+
1986
2035
  var showAR = _this20.getAttribute("show-ar");
1987
2036
 
1988
2037
  if (productID) {
@@ -1993,6 +2042,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
1993
2042
  dst += "&variationId=" + variationID;
1994
2043
  }
1995
2044
 
2045
+ if (variationSKU) {
2046
+ dst += "&variationSku=" + variationSKU;
2047
+ }
2048
+
1996
2049
  if (showAR) {
1997
2050
  dst += "&show_ar=" + showAR;
1998
2051
  }
@@ -2040,6 +2093,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2040
2093
 
2041
2094
  var variationID = _this21.getAttribute("variation-id");
2042
2095
 
2096
+ var variationSKU = _this21.getAttribute("variation-sku");
2097
+
2043
2098
  var showAR = _this21.getAttribute("show-ar");
2044
2099
 
2045
2100
  if (productID) {
@@ -2050,6 +2105,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2050
2105
  viewer.setAttribute("variation-id", variationID);
2051
2106
  }
2052
2107
 
2108
+ if (variationSKU) {
2109
+ viewer.setAttribute("variation-sku", variationSKU);
2110
+ }
2111
+
2053
2112
  if (showAR) {
2054
2113
  viewer.setAttribute("show-ar", showAR);
2055
2114
  }
@@ -2084,7 +2143,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2084
2143
  if (productID) {
2085
2144
  var variationID = _this22.getAttribute("variation-id");
2086
2145
 
2087
- var product = new product_ar_1.ProductAR(productID, variationID);
2146
+ var variationSKU = _this22.getAttribute("variation-sku");
2147
+
2148
+ var product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
2088
2149
  return product.init().then(accept)["catch"](reject);
2089
2150
  }
2090
2151
 
@@ -2094,7 +2155,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2094
2155
  if (sceneProductID) {
2095
2156
  var _variationID = _this22.getAttribute("variation-id");
2096
2157
 
2097
- var _product = new scene_product_ar_1.SceneProductAR(sceneProductID, _variationID);
2158
+ var _variationSKU = _this22.getAttribute("variation-sku");
2159
+
2160
+ var _product = new scene_product_ar_1.SceneProductAR(sceneProductID, _variationID, _variationSKU);
2098
2161
 
2099
2162
  return _product.init().then(accept)["catch"](reject);
2100
2163
  }
@@ -2103,9 +2166,29 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2103
2166
 
2104
2167
 
2105
2168
  if (sceneID) {
2106
- var sceneAR = new scene_ar_1.SceneAR(sceneID);
2107
- sceneAR.init().then(accept)["catch"](reject);
2108
- return;
2169
+ // special case - check if scene only has a single product, if so
2170
+ // we need to use provided variation-id or variation-sku to override
2171
+ var _variationID2 = _this22.getAttribute("variation-id");
2172
+
2173
+ var _variationSKU2 = _this22.getAttribute("variation-sku"); // just do scene-ar if variation ID and variation SKU is not set
2174
+
2175
+
2176
+ if (!_variationID2 && !_variationSKU2) {
2177
+ var sceneAR = new scene_ar_1.SceneAR(sceneID);
2178
+ return sceneAR.init().then(accept)["catch"](reject);
2179
+ } // otherwise decode scene
2180
+
2181
+
2182
+ return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then(function (state) {
2183
+ var firstProduct = state.first();
2184
+
2185
+ if (state.length > 1 || !firstProduct) {
2186
+ return reject(new Error("ViewerController.initAR() - single product required to override variation-id or variation-sku"));
2187
+ }
2188
+
2189
+ var product = new scene_product_ar_1.SceneProductAR(firstProduct.scene_product_id, _variationID2, _variationSKU2);
2190
+ return product.init().then(accept)["catch"](reject);
2191
+ })["catch"](reject);
2109
2192
  }
2110
2193
 
2111
2194
  return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
@@ -2138,6 +2221,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
2138
2221
  "../../ar/product-ar": 3,
2139
2222
  "../../ar/scene-ar": 5,
2140
2223
  "../../ar/scene-product-ar": 6,
2224
+ "../../util/configurator-state": 14,
2141
2225
  "../../util/util": 15,
2142
2226
  "./plattar-controller": 8,
2143
2227
  "@plattar/plattar-api": 42
@@ -3256,7 +3340,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
3256
3340
  Object.defineProperty(exports, "__esModule", {
3257
3341
  value: true
3258
3342
  });
3259
- exports["default"] = "1.130.3";
3343
+ exports["default"] = "1.131.1";
3260
3344
  }, {}],
3261
3345
  17: [function (require, module, exports) {
3262
3346
  "use strict";
@@ -10210,6 +10294,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
10210
10294
  return [{
10211
10295
  key: "variation-id",
10212
10296
  map: "variationId"
10297
+ }, {
10298
+ key: "variation-sku",
10299
+ map: "variationSku"
10213
10300
  }, {
10214
10301
  key: "product-id",
10215
10302
  map: "productId"
@@ -10309,6 +10396,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
10309
10396
  return [{
10310
10397
  key: "variation-id",
10311
10398
  map: "variation_id"
10399
+ }, {
10400
+ key: "variation-sku",
10401
+ map: "variationSku"
10312
10402
  }, {
10313
10403
  key: "show-ar",
10314
10404
  map: "show_ar"
@@ -10386,6 +10476,9 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
10386
10476
  return [{
10387
10477
  key: "variation-id",
10388
10478
  map: "variationId"
10479
+ }, {
10480
+ key: "variation-sku",
10481
+ map: "variationSku"
10389
10482
  }, {
10390
10483
  key: "product-id",
10391
10484
  map: "productId"
@@ -10592,7 +10685,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
10592
10685
  module.exports = Util;
10593
10686
  }, {}],
10594
10687
  129: [function (require, module, exports) {
10595
- module.exports = "1.130.1";
10688
+ module.exports = "1.131.1";
10596
10689
  }, {}],
10597
10690
  130: [function (require, module, exports) {
10598
10691
  (function (global) {