@plattar/plattar-ar-adapter 1.123.2 → 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;
@@ -11,7 +11,6 @@ export declare class ConfiguratorController extends PlattarController {
11
11
  onAttributesUpdated(): void;
12
12
  startQRCode(options: any): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
- startAR(): Promise<void>;
15
14
  initAR(): Promise<LauncherAR>;
16
15
  removeRenderer(): boolean;
17
16
  get element(): HTMLElement | null;
@@ -104,14 +104,6 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
104
104
  return reject(new Error("ConfiguratorController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
105
105
  });
106
106
  }
107
- startAR() {
108
- return new Promise((accept, reject) => {
109
- this.initAR().then((launcher) => {
110
- launcher.start();
111
- accept();
112
- }).catch(reject);
113
- });
114
- }
115
107
  initAR() {
116
108
  return new Promise((accept, reject) => {
117
109
  if (!util_1.Util.canAugment()) {
@@ -31,7 +31,7 @@ export declare abstract class PlattarController {
31
31
  /**
32
32
  * Initialise and start AR mode if available
33
33
  */
34
- abstract startAR(): Promise<void>;
34
+ startAR(): Promise<void>;
35
35
  /**
36
36
  * Initialise and return a launcher that can be used to start AR
37
37
  */
@@ -25,6 +25,17 @@ class PlattarController {
25
25
  };
26
26
  }
27
27
  ;
28
+ /**
29
+ * Initialise and start AR mode if available
30
+ */
31
+ startAR() {
32
+ return new Promise((accept, reject) => {
33
+ this.initAR().then((launcher) => {
34
+ launcher.start();
35
+ accept();
36
+ }).catch(reject);
37
+ });
38
+ }
28
39
  /**
29
40
  * Returns the Parent Instance
30
41
  */
@@ -11,7 +11,6 @@ export declare class ProductController extends PlattarController {
11
11
  onAttributesUpdated(): void;
12
12
  startQRCode(options: any): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
- startAR(): Promise<void>;
15
14
  initAR(): Promise<LauncherAR>;
16
15
  removeRenderer(): boolean;
17
16
  get element(): HTMLElement | null;
@@ -27,7 +27,9 @@ class ProductController extends plattar_controller_1.PlattarController {
27
27
  const viewer = this._element;
28
28
  if (viewer) {
29
29
  const variationID = this.getAttribute("variation-id");
30
- viewer.messenger.selectVariation(variationID);
30
+ if (variationID && viewer.messenger) {
31
+ viewer.messenger.selectVariation(variationID);
32
+ }
31
33
  }
32
34
  return;
33
35
  }
@@ -104,14 +106,6 @@ class ProductController extends plattar_controller_1.PlattarController {
104
106
  return reject(new Error("ProductController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
105
107
  });
106
108
  }
107
- startAR() {
108
- return new Promise((accept, reject) => {
109
- this.initAR().then((launcher) => {
110
- launcher.start();
111
- accept();
112
- }).catch(reject);
113
- });
114
- }
115
109
  initAR() {
116
110
  return new Promise((accept, reject) => {
117
111
  if (!util_1.Util.canAugment()) {
@@ -11,7 +11,6 @@ export declare class ViewerController extends PlattarController {
11
11
  onAttributesUpdated(): void;
12
12
  startQRCode(options: any): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
- startAR(): Promise<void>;
15
14
  initAR(): Promise<LauncherAR>;
16
15
  removeRenderer(): boolean;
17
16
  get element(): HTMLElement | null;
@@ -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,9 +27,11 @@ 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
- viewer.messenger.selectVariation(productID, variationID);
32
+ if (productID && variationID && viewer.messenger) {
33
+ viewer.messenger.selectVariation(productID, variationID);
34
+ }
32
35
  }
33
36
  return;
34
37
  }
@@ -57,7 +60,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
57
60
  }
58
61
  let dst = plattar_api_1.Server.location().base + "renderer/viewer.html?scene_id=" + sceneID;
59
62
  // optional attributes
60
- const productID = this.getAttribute("product-id");
63
+ const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
61
64
  const variationID = this.getAttribute("variation-id");
62
65
  if (productID) {
63
66
  dst += "&productId=" + productID;
@@ -94,7 +97,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
94
97
  viewer.setAttribute("server", server);
95
98
  viewer.setAttribute("scene-id", sceneID);
96
99
  // optional attributes
97
- const productID = this.getAttribute("product-id");
100
+ const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
98
101
  const variationID = this.getAttribute("variation-id");
99
102
  if (productID) {
100
103
  viewer.setAttribute("product-id", productID);
@@ -113,31 +116,31 @@ class ViewerController extends plattar_controller_1.PlattarController {
113
116
  return reject(new Error("ViewerController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
114
117
  });
115
118
  }
116
- startAR() {
117
- return new Promise((accept, reject) => {
118
- this.initAR().then((launcher) => {
119
- launcher.start();
120
- accept();
121
- }).catch(reject);
122
- });
123
- }
124
119
  initAR() {
125
120
  return new Promise((accept, reject) => {
126
121
  if (!util_1.Util.canAugment()) {
127
122
  return reject(new Error("ViewerController.initAR() - cannot proceed as AR not available in context"));
128
123
  }
129
124
  const productID = this.getAttribute("product-id");
125
+ // use product-id if available
130
126
  if (productID) {
131
127
  const variationID = this.getAttribute("variation-id");
132
128
  const product = new product_ar_1.ProductAR(productID, variationID);
133
129
  return product.init().then(accept).catch(reject);
134
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
+ }
135
138
  const sceneID = this.getAttribute("scene-id");
136
139
  // otherwise, scene was set so use SceneAR
137
140
  if (sceneID) {
138
- 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"));
139
142
  }
140
- 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"));
141
144
  });
142
145
  }
143
146
  removeRenderer() {
@@ -0,0 +1,17 @@
1
+ import { LauncherAR } from "../../ar/launcher-ar";
2
+ import { PlattarController } from "./plattar-controller";
3
+ /**
4
+ * Manages an instance of the <plattar-configurator> HTML Element
5
+ */
6
+ export declare class VTOController extends PlattarController {
7
+ private _state;
8
+ private _element;
9
+ private _prevQROpt;
10
+ constructor(parent: HTMLElement);
11
+ onAttributesUpdated(): void;
12
+ startQRCode(options: any): Promise<HTMLElement>;
13
+ startRenderer(): Promise<HTMLElement>;
14
+ initAR(): Promise<LauncherAR>;
15
+ removeRenderer(): boolean;
16
+ get element(): HTMLElement | null;
17
+ }
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VTOController = void 0;
4
+ const plattar_api_1 = require("@plattar/plattar-api");
5
+ const plattar_services_1 = require("@plattar/plattar-services");
6
+ const __1 = require("../..");
7
+ const raw_ar_1 = require("../../ar/raw-ar");
8
+ const util_1 = require("../../util/util");
9
+ const plattar_controller_1 = require("./plattar-controller");
10
+ /**
11
+ * Manages an instance of the <plattar-configurator> HTML Element
12
+ */
13
+ class VTOController extends plattar_controller_1.PlattarController {
14
+ constructor(parent) {
15
+ super(parent);
16
+ this._state = plattar_controller_1.ControllerState.None;
17
+ this._element = null;
18
+ this._prevQROpt = null;
19
+ }
20
+ onAttributesUpdated() {
21
+ const state = this._state;
22
+ // re-render the QR Code when attributes have changed
23
+ if (state === plattar_controller_1.ControllerState.QRCode) {
24
+ this.startQRCode(this._prevQROpt);
25
+ return;
26
+ }
27
+ }
28
+ startQRCode(options) {
29
+ return new Promise((accept, reject) => {
30
+ // remove the old renderer instance if any
31
+ this.removeRenderer();
32
+ const sceneID = this.getAttribute("scene-id");
33
+ if (sceneID) {
34
+ const opt = options || plattar_controller_1.PlattarController.DEFAULT_QR_OPTIONS;
35
+ const viewer = document.createElement("plattar-qrcode");
36
+ // required attributes with defaults for plattar-viewer node
37
+ const width = this.getAttribute("width") || "500px";
38
+ const height = this.getAttribute("height") || "500px";
39
+ viewer.setAttribute("width", width);
40
+ viewer.setAttribute("height", height);
41
+ if (opt.color) {
42
+ viewer.setAttribute("color", opt.color);
43
+ }
44
+ if (opt.margin) {
45
+ viewer.setAttribute("margin", "" + opt.margin);
46
+ }
47
+ if (opt.qrType) {
48
+ viewer.setAttribute("qr-type", opt.qrType);
49
+ }
50
+ let dst = plattar_api_1.Server.location().base + "renderer/facear.html?scene_id=" + sceneID;
51
+ // optional attributes
52
+ const configState = this.getAttribute("config-state");
53
+ const showAR = this.getAttribute("show-ar");
54
+ if (configState) {
55
+ dst += "&config_state=" + configState;
56
+ }
57
+ if (showAR) {
58
+ dst += "&show_ar=" + showAR;
59
+ }
60
+ viewer.setAttribute("url", opt.url || dst);
61
+ viewer.onload = () => {
62
+ return accept(viewer);
63
+ };
64
+ this.append(viewer);
65
+ this._element = viewer;
66
+ this._state = plattar_controller_1.ControllerState.QRCode;
67
+ this._prevQROpt = opt;
68
+ return;
69
+ }
70
+ return reject(new Error("VTOController.startQRCode() - minimum required attributes not set, use scene-id as a minimum"));
71
+ });
72
+ }
73
+ startRenderer() {
74
+ return new Promise((accept, reject) => {
75
+ // remove the old renderer instance if any
76
+ this.removeRenderer();
77
+ const sceneID = this.getAttribute("scene-id");
78
+ if (sceneID) {
79
+ // required attributes with defaults for plattar-facear node
80
+ const width = this.getAttribute("width") || "500px";
81
+ const height = this.getAttribute("height") || "500px";
82
+ const server = this.getAttribute("server") || "production";
83
+ const viewer = document.createElement("plattar-facear");
84
+ viewer.setAttribute("width", width);
85
+ viewer.setAttribute("height", height);
86
+ viewer.setAttribute("server", server);
87
+ viewer.setAttribute("scene-id", sceneID);
88
+ // optional attributes
89
+ const configState = this.getAttribute("config-state");
90
+ const showAR = this.getAttribute("show-ar");
91
+ if (configState) {
92
+ viewer.setAttribute("config-state", configState);
93
+ }
94
+ if (showAR) {
95
+ viewer.setAttribute("show-ar", showAR);
96
+ }
97
+ viewer.onload = () => {
98
+ return accept(viewer);
99
+ };
100
+ this.append(viewer);
101
+ this._element = viewer;
102
+ this._state = plattar_controller_1.ControllerState.Renderer;
103
+ return;
104
+ }
105
+ return reject(new Error("VTOController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
106
+ });
107
+ }
108
+ initAR() {
109
+ return new Promise((accept, reject) => {
110
+ if (!util_1.Util.canAugment()) {
111
+ return reject(new Error("VTOController.initAR() - cannot proceed as VTO AR not available in context"));
112
+ }
113
+ if (!(util_1.Util.isSafari() || util_1.Util.isChromeOnIOS())) {
114
+ return reject(new Error("VTOController.initAR() - cannot proceed as VTO AR only available on IOS Mobile devices"));
115
+ }
116
+ // if scene ID is available and the state is a configurator viewer
117
+ // we can use the real-time configurator state to launch the AR view
118
+ const viewer = this.element;
119
+ const sceneID = this.getAttribute("scene-id");
120
+ if (viewer && sceneID) {
121
+ return viewer.messenger.getARFile("vto").then((result) => {
122
+ const rawAR = new raw_ar_1.RawAR(result.filename);
123
+ return rawAR.init().then(accept).catch(reject);
124
+ }).catch(reject);
125
+ }
126
+ const configState = this.getAttribute("config-state");
127
+ // otherwise scene ID is available to the viewer is not launched
128
+ // we can use the static configuration state to launch the AR view
129
+ if (sceneID && configState) {
130
+ const state = __1.ConfiguratorState.decode(configState);
131
+ if (state.length > 0) {
132
+ const server = this.getAttribute("server") || "production";
133
+ const configurator = new plattar_services_1.Configurator();
134
+ configurator.server = server;
135
+ configurator.output = "vto";
136
+ state.forEach((productState) => {
137
+ if (productState.meta_data.augment === true) {
138
+ configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
139
+ }
140
+ });
141
+ return configurator.get().then((result) => {
142
+ const rawAR = new raw_ar_1.RawAR(result.filename);
143
+ rawAR.init().then(accept).catch(reject);
144
+ }).catch(reject);
145
+ }
146
+ return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
147
+ }
148
+ // otherwise no config-state or viewer is active
149
+ // fallback to using default SceneAR implementation
150
+ if (sceneID) {
151
+ const sceneAR = new __1.SceneAR(sceneID);
152
+ return sceneAR.init().then(accept).catch(reject);
153
+ }
154
+ return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
155
+ });
156
+ }
157
+ removeRenderer() {
158
+ if (this._element) {
159
+ this._element.remove();
160
+ this._element = null;
161
+ return true;
162
+ }
163
+ return false;
164
+ }
165
+ get element() {
166
+ return this._element;
167
+ }
168
+ }
169
+ exports.VTOController = VTOController;
@@ -13,6 +13,12 @@ export default class PlattarEmbed extends HTMLElement {
13
13
  startAR(): Promise<void>;
14
14
  startViewer(): Promise<HTMLElement>;
15
15
  startQRCode(options?: any | undefined | null): Promise<HTMLElement>;
16
+ /**
17
+ * This will remove the currently active Renderer
18
+ *
19
+ * @returns - true if removed successfully, false otherwise
20
+ */
21
+ removeRenderer(): boolean;
16
22
  /**
17
23
  * This is called by the observer if any of the embed attributes have changed
18
24
  * based on the state of the embed, we update the internal structure accordingly
@@ -4,6 +4,7 @@ const plattar_api_1 = require("@plattar/plattar-api");
4
4
  const product_controller_1 = require("./controllers/product-controller");
5
5
  const viewer_controller_1 = require("./controllers/viewer-controller");
6
6
  const configurator_controller_1 = require("./controllers/configurator-controller");
7
+ const vto_controller_1 = require("./controllers/vto-controller");
7
8
  /**
8
9
  * This tracks the current embed type
9
10
  */
@@ -11,6 +12,7 @@ var EmbedType;
11
12
  (function (EmbedType) {
12
13
  EmbedType[EmbedType["Viewer"] = 0] = "Viewer";
13
14
  EmbedType[EmbedType["Configurator"] = 1] = "Configurator";
15
+ EmbedType[EmbedType["VTO"] = 2] = "VTO";
14
16
  })(EmbedType || (EmbedType = {}));
15
17
  /**
16
18
  * This is the primary <plattar-embed /> node that allows easy embedding
@@ -33,6 +35,9 @@ class PlattarEmbed extends HTMLElement {
33
35
  case "viewer":
34
36
  this._currentType = EmbedType.Viewer;
35
37
  break;
38
+ case "vto":
39
+ this._currentType = EmbedType.VTO;
40
+ break;
36
41
  case "configurator":
37
42
  this._currentType = EmbedType.Configurator;
38
43
  break;
@@ -67,6 +72,9 @@ class PlattarEmbed extends HTMLElement {
67
72
  else if (this._currentType === EmbedType.Configurator) {
68
73
  this._controller = new configurator_controller_1.ConfiguratorController(this);
69
74
  }
75
+ else if (this._currentType === EmbedType.VTO) {
76
+ this._controller = new vto_controller_1.VTOController(this);
77
+ }
70
78
  const init = this.hasAttribute("init") ? this.getAttribute("init") : null;
71
79
  if (init === "ar") {
72
80
  this.startAR();
@@ -124,6 +132,17 @@ class PlattarEmbed extends HTMLElement {
124
132
  return this._controller.startQRCode(options).then(accept).catch(reject);
125
133
  });
126
134
  }
135
+ /**
136
+ * This will remove the currently active Renderer
137
+ *
138
+ * @returns - true if removed successfully, false otherwise
139
+ */
140
+ removeRenderer() {
141
+ if (!this._controller) {
142
+ return false;
143
+ }
144
+ return this._controller.removeRenderer();
145
+ }
127
146
  /**
128
147
  * This is called by the observer if any of the embed attributes have changed
129
148
  * based on the state of the embed, we update the internal structure accordingly
package/dist/index.d.ts CHANGED
@@ -2,7 +2,9 @@ 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";
8
9
  export { Util } from "./util/util";
10
+ export { ConfiguratorState } from "./util/configurator-state";
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.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");
@@ -36,6 +38,8 @@ var raw_ar_1 = require("./ar/raw-ar");
36
38
  Object.defineProperty(exports, "RawAR", { enumerable: true, get: function () { return raw_ar_1.RawAR; } });
37
39
  var util_1 = require("./util/util");
38
40
  Object.defineProperty(exports, "Util", { enumerable: true, get: function () { return util_1.Util; } });
41
+ var configurator_state_1 = require("./util/configurator-state");
42
+ Object.defineProperty(exports, "ConfiguratorState", { enumerable: true, get: function () { return configurator_state_1.ConfiguratorState; } });
39
43
  const plattar_embed_1 = __importDefault(require("./embed/plattar-embed"));
40
44
  const version_1 = __importDefault(require("./version"));
41
45
  if (customElements) {
@@ -0,0 +1,26 @@
1
+ export interface SceneProductData {
2
+ scene_product_id: string;
3
+ product_variation_id: string;
4
+ meta_data: {
5
+ augment: boolean;
6
+ };
7
+ }
8
+ export declare class ConfiguratorState {
9
+ private readonly _state;
10
+ constructor(state?: string | null | undefined);
11
+ /**
12
+ * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
13
+ *
14
+ * @param sceneProductID - The Scene Product ID to be used (as defined in Plattar CMS)
15
+ * @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
16
+ * @param metaData - Arbitrary meta-data that can be used against certain operaions
17
+ */
18
+ addSceneProduct(sceneProductID: string, productVariationID: string, metaData?: any | null | undefined): void;
19
+ /**
20
+ * Iterate over the internal state data
21
+ */
22
+ forEach(callback: (data: SceneProductData) => void): void;
23
+ get length(): number;
24
+ static decode(state: string): ConfiguratorState;
25
+ encode(): string;
26
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfiguratorState = void 0;
4
+ class ConfiguratorState {
5
+ constructor(state = null) {
6
+ const defaultState = {
7
+ meta: {
8
+ scene_product_index: 0,
9
+ product_variation_index: 1,
10
+ meta_index: 2,
11
+ },
12
+ states: []
13
+ };
14
+ if (state) {
15
+ try {
16
+ const decodedb64State = atob(state);
17
+ const parsedState = JSON.parse(decodedb64State);
18
+ // set the meta data
19
+ if (parsedState.meta) {
20
+ defaultState.meta.scene_product_index = parsedState.meta.scene_product_index || 0;
21
+ defaultState.meta.product_variation_index = parsedState.meta.product_variation_index || 1;
22
+ defaultState.meta.meta_index = parsedState.meta.meta_index || 2;
23
+ }
24
+ defaultState.states = parsedState.states || [];
25
+ }
26
+ catch (err) {
27
+ console.error("ConfiguratorState.constructor() - there was an error parsing configurator state");
28
+ console.error(err);
29
+ }
30
+ }
31
+ this._state = defaultState;
32
+ }
33
+ /**
34
+ * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
35
+ *
36
+ * @param sceneProductID - The Scene Product ID to be used (as defined in Plattar CMS)
37
+ * @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
38
+ * @param metaData - Arbitrary meta-data that can be used against certain operaions
39
+ */
40
+ addSceneProduct(sceneProductID, productVariationID, metaData = null) {
41
+ if (sceneProductID && productVariationID) {
42
+ const states = this._state.states;
43
+ const meta = this._state.meta;
44
+ const newData = [];
45
+ newData.splice(meta.scene_product_index, 0, sceneProductID);
46
+ newData.splice(meta.product_variation_index, 0, productVariationID);
47
+ if (metaData) {
48
+ newData.splice(meta.meta_index, 0, metaData);
49
+ }
50
+ states.push(newData);
51
+ }
52
+ }
53
+ /**
54
+ * Iterate over the internal state data
55
+ */
56
+ forEach(callback) {
57
+ const states = this._state.states;
58
+ const meta = this._state.meta;
59
+ if (states.length > 0) {
60
+ states.forEach((productState) => {
61
+ if (productState.length === 2) {
62
+ callback({
63
+ scene_product_id: productState[meta.scene_product_index],
64
+ product_variation_id: productState[meta.product_variation_index],
65
+ meta_data: {
66
+ augment: true
67
+ }
68
+ });
69
+ }
70
+ else if (productState.length === 3) {
71
+ callback({
72
+ scene_product_id: productState[meta.scene_product_index],
73
+ product_variation_id: productState[meta.product_variation_index],
74
+ meta_data: {
75
+ augment: productState[meta.meta_index].augment || true
76
+ }
77
+ });
78
+ }
79
+ });
80
+ }
81
+ }
82
+ get length() {
83
+ return this._state.states.length;
84
+ }
85
+ static decode(state) {
86
+ return new ConfiguratorState(state);
87
+ }
88
+ encode() {
89
+ return btoa(JSON.stringify(this._state));
90
+ }
91
+ }
92
+ exports.ConfiguratorState = ConfiguratorState;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.123.2";
1
+ declare const _default: "1.123.6";
2
2
  export default _default;