@plattar/plattar-ar-adapter 1.123.5 → 1.123.6

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.
@@ -0,0 +1,14 @@
1
+ import { ProductAR } from "./product-ar";
2
+ import { LauncherAR } from "./launcher-ar";
3
+ /**
4
+ * Allows launching Product AR by providing a SceneProduct ID instead.
5
+ * SceneProducts are much more convenient to grab from the Plattar CMS
6
+ */
7
+ export declare class SceneProductAR extends ProductAR {
8
+ private readonly _sceneProductID;
9
+ private _attachedProductID;
10
+ constructor(sceneProductID?: string | undefined | null, variationID?: string | undefined | null);
11
+ get sceneProductID(): string;
12
+ get productID(): string;
13
+ init(): Promise<LauncherAR>;
14
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SceneProductAR = void 0;
4
+ const product_ar_1 = require("./product-ar");
5
+ const plattar_api_1 = require("@plattar/plattar-api");
6
+ const util_1 = require("../util/util");
7
+ /**
8
+ * Allows launching Product AR by providing a SceneProduct ID instead.
9
+ * SceneProducts are much more convenient to grab from the Plattar CMS
10
+ */
11
+ class SceneProductAR extends product_ar_1.ProductAR {
12
+ constructor(sceneProductID = null, variationID = null) {
13
+ super(sceneProductID, variationID);
14
+ // this is evaluated in the init() function
15
+ this._attachedProductID = null;
16
+ if (!sceneProductID) {
17
+ throw new Error("SceneProductAR.constructor(sceneProductID, variationID) - sceneProductID must be defined");
18
+ }
19
+ this._sceneProductID = sceneProductID;
20
+ }
21
+ get sceneProductID() {
22
+ return this._sceneProductID;
23
+ }
24
+ get productID() {
25
+ if (!this._attachedProductID) {
26
+ throw new Error("SceneProductAR.productID() - product id was not defined, did you call init()?");
27
+ }
28
+ return this._attachedProductID;
29
+ }
30
+ init() {
31
+ return new Promise((accept, reject) => {
32
+ if (!util_1.Util.canAugment()) {
33
+ return reject(new Error("SceneProductAR.init() - cannot proceed as AR not available in context"));
34
+ }
35
+ const sceneProduct = new plattar_api_1.SceneProduct(this.sceneProductID);
36
+ sceneProduct.get().then((sceneProduct) => {
37
+ const productID = sceneProduct.attributes.product_id;
38
+ if (!productID) {
39
+ return reject("SceneProductAR.init() - Scene Product does not have an attached Product instance");
40
+ }
41
+ this._attachedProductID = productID;
42
+ // execute the standard Product AR functionality
43
+ return super.init().then(accept).catch(reject);
44
+ }).catch(reject);
45
+ });
46
+ }
47
+ }
48
+ exports.SceneProductAR = SceneProductAR;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ViewerController = void 0;
4
4
  const plattar_api_1 = require("@plattar/plattar-api");
5
5
  const product_ar_1 = require("../../ar/product-ar");
6
+ const scene_product_ar_1 = require("../../ar/scene-product-ar");
6
7
  const util_1 = require("../../util/util");
7
8
  const plattar_controller_1 = require("./plattar-controller");
8
9
  /**
@@ -26,7 +27,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
26
27
  if (state === plattar_controller_1.ControllerState.Renderer) {
27
28
  const viewer = this._element;
28
29
  if (viewer) {
29
- const productID = this.getAttribute("product-id");
30
+ const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
30
31
  const variationID = this.getAttribute("variation-id");
31
32
  if (productID && variationID && viewer.messenger) {
32
33
  viewer.messenger.selectVariation(productID, variationID);
@@ -59,7 +60,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
59
60
  }
60
61
  let dst = plattar_api_1.Server.location().base + "renderer/viewer.html?scene_id=" + sceneID;
61
62
  // optional attributes
62
- const productID = this.getAttribute("product-id");
63
+ const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
63
64
  const variationID = this.getAttribute("variation-id");
64
65
  if (productID) {
65
66
  dst += "&productId=" + productID;
@@ -96,7 +97,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
96
97
  viewer.setAttribute("server", server);
97
98
  viewer.setAttribute("scene-id", sceneID);
98
99
  // optional attributes
99
- const productID = this.getAttribute("product-id");
100
+ const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
100
101
  const variationID = this.getAttribute("variation-id");
101
102
  if (productID) {
102
103
  viewer.setAttribute("product-id", productID);
@@ -121,17 +122,25 @@ class ViewerController extends plattar_controller_1.PlattarController {
121
122
  return reject(new Error("ViewerController.initAR() - cannot proceed as AR not available in context"));
122
123
  }
123
124
  const productID = this.getAttribute("product-id");
125
+ // use product-id if available
124
126
  if (productID) {
125
127
  const variationID = this.getAttribute("variation-id");
126
128
  const product = new product_ar_1.ProductAR(productID, variationID);
127
129
  return product.init().then(accept).catch(reject);
128
130
  }
131
+ const sceneProductID = this.getAttribute("scene-product-id");
132
+ // use scene-product-id if available
133
+ if (sceneProductID) {
134
+ const variationID = this.getAttribute("variation-id");
135
+ const product = new scene_product_ar_1.SceneProductAR(sceneProductID, variationID);
136
+ return product.init().then(accept).catch(reject);
137
+ }
129
138
  const sceneID = this.getAttribute("scene-id");
130
139
  // otherwise, scene was set so use SceneAR
131
140
  if (sceneID) {
132
- return reject(new Error("ViewerController.initAR() - AR mode for scene-id not yet supported, use product-id"));
141
+ return reject(new Error("ViewerController.initAR() - AR mode for scene-id not yet supported, use product-id or scene-product-id"));
133
142
  }
134
- return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id or product-id as a minimum"));
143
+ return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use product-id or scene-product-id as a minimum"));
135
144
  });
136
145
  }
137
146
  removeRenderer() {
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * as PlattarWeb from "@plattar/plattar-web";
2
2
  export * as PlattarQRCode from "@plattar/plattar-qrcode";
3
3
  export * as version from "./version";
4
4
  export { ProductAR } from "./ar/product-ar";
5
+ export { SceneProductAR } from "./ar/scene-product-ar";
5
6
  export { SceneAR } from "./ar/scene-ar";
6
7
  export { ModelAR } from "./ar/model-ar";
7
8
  export { RawAR } from "./ar/raw-ar";
package/dist/index.js CHANGED
@@ -22,12 +22,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.ConfiguratorState = exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.ProductAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
25
+ exports.ConfiguratorState = exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.SceneProductAR = exports.ProductAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
26
26
  exports.PlattarWeb = __importStar(require("@plattar/plattar-web"));
27
27
  exports.PlattarQRCode = __importStar(require("@plattar/plattar-qrcode"));
28
28
  exports.version = __importStar(require("./version"));
29
29
  var product_ar_1 = require("./ar/product-ar");
30
30
  Object.defineProperty(exports, "ProductAR", { enumerable: true, get: function () { return product_ar_1.ProductAR; } });
31
+ var scene_product_ar_1 = require("./ar/scene-product-ar");
32
+ Object.defineProperty(exports, "SceneProductAR", { enumerable: true, get: function () { return scene_product_ar_1.SceneProductAR; } });
31
33
  var scene_ar_1 = require("./ar/scene-ar");
32
34
  Object.defineProperty(exports, "SceneAR", { enumerable: true, get: function () { return scene_ar_1.SceneAR; } });
33
35
  var model_ar_1 = require("./ar/model-ar");
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.123.5";
1
+ declare const _default: "1.123.6";
2
2
  export default _default;
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = "1.123.5";
3
+ exports.default = "1.123.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.123.5",
3
+ "version": "1.123.6",
4
4
  "description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",