@plattar/plattar-ar-adapter 1.139.1 → 1.140.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.
@@ -509,7 +509,7 @@ const launcher_ar_1 = require("./launcher-ar");
509
509
  * Performs AR functionality related to Plattar Scenes
510
510
  */
511
511
  class SceneAR extends launcher_ar_1.LauncherAR {
512
- constructor(sceneID = null) {
512
+ constructor(sceneID = null, variationSelection = null) {
513
513
  super();
514
514
  // analytics instance
515
515
  this._analytics = null;
@@ -517,6 +517,7 @@ class SceneAR extends launcher_ar_1.LauncherAR {
517
517
  throw new Error("SceneAR.constructor(sceneID) - sceneID must be defined");
518
518
  }
519
519
  this._sceneID = sceneID;
520
+ this._variationSelection = variationSelection || {};
520
521
  this._ar = null;
521
522
  }
522
523
  get sceneID() {
@@ -560,9 +561,25 @@ class SceneAR extends launcher_ar_1.LauncherAR {
560
561
  // add our scene products
561
562
  sceneProducts.forEach((sceneProduct) => {
562
563
  const product = sceneProduct.relationships.find(plattar_api_1.Product);
563
- if (sceneProduct.attributes.include_in_augment && product && product.attributes.product_variation_id) {
564
- configurator.addSceneProduct(sceneProduct.id, product.attributes.product_variation_id);
565
- totalARObjectCount++;
564
+ const selection = this._variationSelection;
565
+ // we have a specific product selection
566
+ if (sceneProduct.attributes.include_in_augment) {
567
+ // check if this product is the one we want (from selection optionally)
568
+ if (product && (product.id === selection.productID) && selection.variationID) {
569
+ configurator.addSceneProduct(sceneProduct.id, selection.variationID);
570
+ totalARObjectCount++;
571
+ }
572
+ else if (product) {
573
+ // check if this scene-product is the one we want (from selection)
574
+ if ((sceneProduct.id === selection.sceneProductID) && selection.variationID) {
575
+ configurator.addSceneProduct(sceneProduct.id, selection.variationID);
576
+ totalARObjectCount++;
577
+ }
578
+ else if (product.attributes.product_variation_id) {
579
+ configurator.addSceneProduct(sceneProduct.id, product.attributes.product_variation_id);
580
+ totalARObjectCount++;
581
+ }
582
+ }
566
583
  }
567
584
  });
568
585
  // add our scene models
@@ -1510,12 +1527,24 @@ class VTOController extends plattar_controller_1.PlattarController {
1510
1527
  // optional attributes
1511
1528
  const configState = this.getAttribute("config-state");
1512
1529
  const showAR = this.getAttribute("show-ar");
1530
+ const productID = this.getAttribute("product-id");
1531
+ const sceneProductID = this.getAttribute("scene-product-id");
1532
+ const variationID = this.getAttribute("variation-id");
1513
1533
  if (configState) {
1514
1534
  dst += "&config_state=" + configState;
1515
1535
  }
1516
1536
  if (showAR) {
1517
1537
  dst += "&show_ar=" + showAR;
1518
1538
  }
1539
+ if (productID) {
1540
+ dst += "&product_id=" + productID;
1541
+ }
1542
+ if (sceneProductID) {
1543
+ dst += "&scene_product_id=" + sceneProductID;
1544
+ }
1545
+ if (variationID) {
1546
+ dst += "&variation_id=" + variationID;
1547
+ }
1519
1548
  viewer.setAttribute("url", opt.url || dst);
1520
1549
  viewer.onload = () => {
1521
1550
  return accept(viewer);
@@ -1547,12 +1576,24 @@ class VTOController extends plattar_controller_1.PlattarController {
1547
1576
  // optional attributes
1548
1577
  const configState = this.getAttribute("config-state");
1549
1578
  const showAR = this.getAttribute("show-ar");
1579
+ const productID = this.getAttribute("product-id");
1580
+ const sceneProductID = this.getAttribute("scene-product-id");
1581
+ const variationID = this.getAttribute("variation-id");
1550
1582
  if (configState) {
1551
1583
  viewer.setAttribute("config-state", configState);
1552
1584
  }
1553
1585
  if (showAR) {
1554
1586
  viewer.setAttribute("show-ar", showAR);
1555
1587
  }
1588
+ if (productID) {
1589
+ viewer.setAttribute("product-id", productID);
1590
+ }
1591
+ if (sceneProductID) {
1592
+ viewer.setAttribute("scene-product-id", sceneProductID);
1593
+ }
1594
+ if (variationID) {
1595
+ viewer.setAttribute("variation-id", variationID);
1596
+ }
1556
1597
  viewer.onload = () => {
1557
1598
  return accept(viewer);
1558
1599
  };
@@ -1655,7 +1696,14 @@ class VTOController extends plattar_controller_1.PlattarController {
1655
1696
  // otherwise no config-state or viewer is active
1656
1697
  // fallback to using default SceneAR implementation
1657
1698
  if (sceneID) {
1658
- const sceneAR = new __1.SceneAR(sceneID);
1699
+ const productID = this.getAttribute("product-id");
1700
+ const sceneProductID = this.getAttribute("scene-product-id");
1701
+ const variationID = this.getAttribute("variation-id");
1702
+ const sceneAR = new __1.SceneAR(sceneID, {
1703
+ productID: productID ? productID : undefined,
1704
+ sceneProductID: sceneProductID ? sceneProductID : undefined,
1705
+ variationID: variationID ? variationID : undefined
1706
+ });
1659
1707
  sceneAR.init().then(accept).catch(reject);
1660
1708
  return;
1661
1709
  }
@@ -2125,58 +2173,45 @@ exports.Util = void 0;
2125
2173
  */
2126
2174
  class Util {
2127
2175
  static canAugment() {
2128
- const userAgent = navigator.userAgent;
2129
- // test google chrome on IOS and standard IOS test
2130
- if ((/CriOS/i.test(userAgent) || /Macintosh|iPad|iPhone|iPod/.test(userAgent)) && !window.MSStream) {
2131
- // inside facebook browser
2132
- if (/\bFB[\w_]+\//.test(userAgent)) {
2133
- return false;
2134
- }
2135
- // inside instagram browser
2136
- if (/\bInstagram/i.test(userAgent)) {
2137
- return false;
2176
+ return Util.canQuicklook() || Util.canSceneViewer();
2177
+ }
2178
+ static canQuicklook() {
2179
+ if (Util.isIOS()) {
2180
+ const isWKWebView = Boolean((window && window).webkit && window.webkit.messageHandlers);
2181
+ if (isWKWebView) {
2182
+ return Boolean(/CriOS\/|EdgiOS\/|FxiOS\/|GSA\/|DuckDuckGo\//.test(navigator.userAgent));
2138
2183
  }
2139
- return Util.canQuicklook();
2140
- }
2141
- else if (/android/i.test(userAgent)) {
2142
- return true;
2184
+ const tempAnchor = document.createElement("a");
2185
+ return tempAnchor.relList && tempAnchor.relList.supports && tempAnchor.relList.supports("ar");
2143
2186
  }
2144
2187
  return false;
2145
2188
  }
2146
- static canQuicklook() {
2147
- const tempAnchor = document.createElement("a");
2148
- return tempAnchor.relList &&
2149
- tempAnchor.relList.supports &&
2150
- tempAnchor.relList.supports("ar");
2151
- }
2152
2189
  static canSceneViewer() {
2153
- return Util.canAugment() && /android/i.test(navigator.userAgent);
2190
+ return Util.isAndroid() && !Util.isFirefox() && !Util.isOculus();
2154
2191
  }
2155
2192
  static canRealityViewer() {
2156
- if (!Util.canAugment()) {
2157
- return false;
2158
- }
2159
- if (/Macintosh|iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
2160
- if (Util.isSafari() && Util.getIOSVersion()[0] >= 13) {
2161
- return true;
2162
- }
2163
- }
2164
- return false;
2193
+ return Util.isIOS() && Util.getIOSVersion()[0] >= 13;
2165
2194
  }
2166
- static isSafari() {
2167
- if (navigator.vendor && navigator.userAgent) {
2168
- return navigator.vendor.indexOf("Apple") > -1 &&
2169
- navigator.userAgent.indexOf("CriOS") === -1 &&
2170
- navigator.userAgent.indexOf("FxiOS") === -1;
2171
- }
2172
- return false;
2195
+ static isSafariOnIOS() {
2196
+ return Util.isIOS() && Util.isSafari();
2173
2197
  }
2174
2198
  static isChromeOnIOS() {
2175
- const userAgent = navigator.userAgent;
2176
- if (userAgent) {
2177
- return Util.canAugment() && /CriOS/i.test(userAgent);
2178
- }
2179
- return false;
2199
+ return Util.isIOS() && /CriOS\//.test(navigator.userAgent);
2200
+ }
2201
+ static isIOS() {
2202
+ return (/iPad|iPhone|iPod/.test(navigator.userAgent) && !self.MSStream) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
2203
+ }
2204
+ static isAndroid() {
2205
+ return /android/i.test(navigator.userAgent);
2206
+ }
2207
+ static isFirefox() {
2208
+ return /firefox/i.test(navigator.userAgent);
2209
+ }
2210
+ static isOculus() {
2211
+ return /OculusBrowser/.test(navigator.userAgent);
2212
+ }
2213
+ static isSafari() {
2214
+ return /Safari\//.test(navigator.userAgent);
2180
2215
  }
2181
2216
  static getIOSVersion() {
2182
2217
  if (/iP(hone|od|ad)/.test(navigator.platform)) {
@@ -2206,7 +2241,7 @@ exports.Util = Util;
2206
2241
  },{}],16:[function(require,module,exports){
2207
2242
  "use strict";
2208
2243
  Object.defineProperty(exports, "__esModule", { value: true });
2209
- exports.default = "1.139.1";
2244
+ exports.default = "1.140.1";
2210
2245
 
2211
2246
  },{}],17:[function(require,module,exports){
2212
2247
  "use strict";