@plattar/plattar-ar-adapter 1.122.2 → 1.123.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.
@@ -1,18 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plattar_api_1 = require("@plattar/plattar-api");
4
- const product_ar_1 = require("../ar/product-ar");
4
+ const product_controller_1 = require("./controllers/product-controller");
5
+ const viewer_controller_1 = require("./controllers/viewer-controller");
6
+ const configurator_controller_1 = require("./controllers/configurator-controller");
5
7
  /**
6
- * This tracks the current state of the Embed
8
+ * This tracks the current embed type
7
9
  */
8
- var EmbedState;
9
- (function (EmbedState) {
10
- EmbedState[EmbedState["None"] = 0] = "None";
11
- EmbedState[EmbedState["SceneViewer"] = 1] = "SceneViewer";
12
- EmbedState[EmbedState["ProductViewer"] = 2] = "ProductViewer";
13
- EmbedState[EmbedState["ProductAR"] = 3] = "ProductAR";
14
- EmbedState[EmbedState["QRCode"] = 4] = "QRCode";
15
- })(EmbedState || (EmbedState = {}));
10
+ var EmbedType;
11
+ (function (EmbedType) {
12
+ EmbedType[EmbedType["Viewer"] = 0] = "Viewer";
13
+ EmbedType[EmbedType["Configurator"] = 1] = "Configurator";
14
+ })(EmbedType || (EmbedType = {}));
16
15
  /**
17
16
  * This is the primary <plattar-embed /> node that allows easy embedding
18
17
  * of Plattar related content
@@ -20,49 +19,31 @@ var EmbedState;
20
19
  class PlattarEmbed extends HTMLElement {
21
20
  constructor() {
22
21
  super();
23
- // this is the current state of the embed, none by default
24
- this._currentState = EmbedState.None;
25
- this._qrCodeOptions = {
26
- color: "#101721",
27
- qrType: "default",
28
- margin: 0
29
- };
30
- this._sceneID = null;
31
- this._productID = null;
32
- this._variationID = null;
33
- this._isReady = false;
34
- this._width = "500px";
35
- this._height = "500px";
36
- this._server = "production";
37
- this._viewer = null;
22
+ // this is the current embed type, viewer by default
23
+ this._currentType = EmbedType.Viewer;
24
+ this._controller = null;
38
25
  }
39
26
  get viewer() {
40
- return this._viewer;
27
+ return this._controller ? this._controller.element : null;
41
28
  }
42
29
  connectedCallback() {
30
+ const embedType = this.hasAttribute("embed-type") ? this.getAttribute("embed-type") : "viewer";
31
+ if (embedType) {
32
+ switch (embedType.toLowerCase()) {
33
+ case "viewer":
34
+ this._currentType = EmbedType.Viewer;
35
+ break;
36
+ case "configurator":
37
+ this._currentType = EmbedType.Configurator;
38
+ break;
39
+ default:
40
+ this._currentType = EmbedType.Viewer;
41
+ }
42
+ }
43
43
  const observer = new MutationObserver((mutations) => {
44
44
  mutations.forEach((mutation) => {
45
45
  if (mutation.type === "attributes") {
46
- const sceneID = this.hasAttribute("scene-id") ? this.getAttribute("scene-id") : null;
47
- const productID = this.hasAttribute("product-id") ? this.getAttribute("product-id") : null;
48
- const variationID = this.hasAttribute("variation-id") ? this.getAttribute("variation-id") : null;
49
- let updated = false;
50
- if (sceneID !== this._sceneID) {
51
- this._sceneID = sceneID;
52
- updated = true;
53
- }
54
- if (productID !== this._productID) {
55
- this._productID = productID;
56
- updated = true;
57
- }
58
- if (variationID !== this._variationID) {
59
- this._variationID = variationID;
60
- updated = true;
61
- }
62
- if (updated) {
63
- // re-render based on internal state
64
- this._OnAttributesUpdated();
65
- }
46
+ this._OnAttributesUpdated();
66
47
  }
67
48
  });
68
49
  });
@@ -71,21 +52,21 @@ class PlattarEmbed extends HTMLElement {
71
52
  });
72
53
  const server = this.hasAttribute("server") ? this.getAttribute("server") : "production";
73
54
  plattar_api_1.Server.create(plattar_api_1.Server.match(server || "production"));
74
- if (server) {
75
- this._server = server;
76
- }
77
- this._sceneID = this.hasAttribute("scene-id") ? this.getAttribute("scene-id") : null;
78
- this._productID = this.hasAttribute("product-id") ? this.getAttribute("product-id") : null;
79
- this._variationID = this.hasAttribute("variation-id") ? this.getAttribute("variation-id") : null;
80
- const width = this.hasAttribute("width") ? this.getAttribute("width") : "500px";
81
- const height = this.hasAttribute("height") ? this.getAttribute("height") : "500px";
82
- if (width) {
83
- this._width = width;
55
+ const sceneID = this.hasAttribute("scene-id") ? this.getAttribute("scene-id") : null;
56
+ const productID = this.hasAttribute("product-id") ? this.getAttribute("product-id") : null;
57
+ // decide which controller to initialise
58
+ if (this._currentType === EmbedType.Viewer) {
59
+ // initialise product if scene-id is missing but product-id is defined
60
+ if (!sceneID && productID) {
61
+ this._controller = new product_controller_1.ProductController(this);
62
+ }
63
+ else if (sceneID) {
64
+ this._controller = new viewer_controller_1.ViewerController(this);
65
+ }
84
66
  }
85
- if (height) {
86
- this._height = height;
67
+ else if (this._currentType === EmbedType.Configurator) {
68
+ this._controller = new configurator_controller_1.ConfiguratorController(this);
87
69
  }
88
- this._isReady = true;
89
70
  const init = this.hasAttribute("init") ? this.getAttribute("init") : null;
90
71
  if (init === "ar") {
91
72
  this.startAR();
@@ -113,164 +94,34 @@ class PlattarEmbed extends HTMLElement {
113
94
  }
114
95
  initAR() {
115
96
  return new Promise((accept, reject) => {
116
- if (!this._isReady) {
117
- return reject(new Error("PlattarEmbed.initAR() - cannot execute as page has not loaded yet"));
118
- }
119
- // if scene is not set but product is, then use ProductAR
120
- if (!this._sceneID && this._productID) {
121
- const product = new product_ar_1.ProductAR(this._productID, this._variationID);
122
- return product.init().then(accept).catch(reject);
123
- }
124
- // If Product is set (under any scenario) then use ProductAR
125
- // NOTE: At some point this should check for Scenes when SceneAR
126
- // is implemented
127
- if (this._productID) {
128
- const product = new product_ar_1.ProductAR(this._productID, this._variationID);
129
- return product.init().then(accept).catch(reject);
130
- }
131
- // otherwise, scene was set so use SceneAR
132
- if (this._sceneID) {
133
- return reject(new Error("PlattarEmbed.initAR() - scene-id not yet supported"));
97
+ if (!this._controller) {
98
+ return reject(new Error("PlattarEmbed.initAR() - cannot execute as controller has not loaded yet"));
134
99
  }
135
- return reject(new Error("PlattarEmbed.initAR() - minimum required attributes not set, use scene-id or product-id as a minimum"));
100
+ return this._controller.initAR().then(accept).catch(reject);
136
101
  });
137
102
  }
138
103
  startAR() {
139
104
  return new Promise((accept, reject) => {
140
- if (!this._isReady) {
141
- return reject(new Error("PlattarEmbed.startAR() - cannot execute as page has not loaded yet"));
105
+ if (!this._controller) {
106
+ return reject(new Error("PlattarEmbed.startAR() - cannot execute as controller has not loaded yet"));
142
107
  }
143
- this.initAR().then((launcher) => {
144
- launcher.start();
145
- accept();
146
- }).catch(reject);
108
+ return this._controller.startAR().then(accept).catch(reject);
147
109
  });
148
110
  }
149
111
  startViewer() {
150
112
  return new Promise((accept, reject) => {
151
- if (!this._isReady) {
152
- return reject(new Error("PlattarEmbed.startViewer() - cannot execute as page has not loaded yet"));
113
+ if (!this._controller) {
114
+ return reject(new Error("PlattarEmbed.startViewer() - cannot execute as controller has not loaded yet"));
153
115
  }
154
- if (this._viewer) {
155
- this._viewer.remove();
156
- this._viewer = null;
157
- }
158
- // if scene is set, we use <plattar-viewer /> node from plattar-web
159
- if (this._sceneID) {
160
- const viewer = document.createElement("plattar-viewer");
161
- viewer.setAttribute("width", this._width);
162
- viewer.setAttribute("height", this._height);
163
- viewer.setAttribute("server", this._server);
164
- viewer.setAttribute("scene-id", this._sceneID);
165
- if (this._productID) {
166
- viewer.setAttribute("product-id", this._productID);
167
- }
168
- if (this._variationID) {
169
- viewer.setAttribute("variation-id", this._variationID);
170
- }
171
- viewer.onload = () => {
172
- return accept(viewer);
173
- };
174
- const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
175
- shadow.append(viewer);
176
- this._viewer = viewer;
177
- this._currentState = EmbedState.SceneViewer;
178
- return;
179
- }
180
- // if product is set, we use <plattar-product /> node from plattar-web
181
- if (this._productID) {
182
- const viewer = document.createElement("plattar-product");
183
- viewer.setAttribute("width", this._width);
184
- viewer.setAttribute("height", this._height);
185
- viewer.setAttribute("server", this._server);
186
- viewer.setAttribute("product-id", this._productID);
187
- if (this._variationID) {
188
- viewer.setAttribute("variation-id", this._variationID);
189
- }
190
- viewer.onload = () => {
191
- return accept(viewer);
192
- };
193
- const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
194
- shadow.append(viewer);
195
- this._viewer = viewer;
196
- this._currentState = EmbedState.ProductViewer;
197
- return;
198
- }
199
- return reject(new Error("PlattarEmbed.startViewer() - minimum required attributes not set, use scene-id or product-id as a minimum"));
116
+ return this._controller.startRenderer().then(accept).catch(reject);
200
117
  });
201
118
  }
202
119
  startQRCode(options = null) {
203
120
  return new Promise((accept, reject) => {
204
- if (!this._isReady) {
205
- return reject(new Error("PlattarEmbed.startQRCode() - cannot execute as page has not loaded yet"));
121
+ if (!this._controller) {
122
+ return reject(new Error("PlattarEmbed.startQRCode() - cannot execute as controller has not loaded yet"));
206
123
  }
207
- const opt = options || this._qrCodeOptions;
208
- // reset instance for later use
209
- this._qrCodeOptions = opt;
210
- if (this._viewer) {
211
- this._viewer.remove();
212
- this._viewer = null;
213
- }
214
- // if scene is set, we embed a QR code that takes us to viewer.html
215
- if (this._sceneID) {
216
- const viewer = document.createElement("plattar-qrcode");
217
- viewer.setAttribute("width", this._width);
218
- viewer.setAttribute("height", this._height);
219
- if (opt.color) {
220
- viewer.setAttribute("color", opt.color);
221
- }
222
- if (opt.margin) {
223
- viewer.setAttribute("margin", "" + opt.margin);
224
- }
225
- if (opt.qrType) {
226
- viewer.setAttribute("qr-type", opt.qrType);
227
- }
228
- let dst = plattar_api_1.Server.location().base + "renderer/viewer.html?scene_id=" + this._sceneID;
229
- if (this._productID) {
230
- dst += "&productId=" + this._productID;
231
- }
232
- if (this._variationID) {
233
- dst += "&variationId=" + this._variationID;
234
- }
235
- viewer.setAttribute("url", dst);
236
- viewer.onload = () => {
237
- return accept(viewer);
238
- };
239
- const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
240
- shadow.append(viewer);
241
- this._viewer = viewer;
242
- this._currentState = EmbedState.QRCode;
243
- return;
244
- }
245
- // if product is set, we embed a QR code that takes us to product.html
246
- if (this._productID) {
247
- const viewer = document.createElement("plattar-qrcode");
248
- viewer.setAttribute("width", this._width);
249
- viewer.setAttribute("height", this._height);
250
- if (opt.color) {
251
- viewer.setAttribute("color", opt.color);
252
- }
253
- if (opt.margin) {
254
- viewer.setAttribute("margin", "" + opt.margin);
255
- }
256
- if (opt.qrType) {
257
- viewer.setAttribute("qr-type", opt.qrType);
258
- }
259
- let dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + this._productID;
260
- if (this._variationID) {
261
- dst += "&variation_id=" + this._variationID;
262
- }
263
- viewer.setAttribute("url", dst);
264
- viewer.onload = () => {
265
- return accept(viewer);
266
- };
267
- const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
268
- shadow.append(viewer);
269
- this._viewer = viewer;
270
- this._currentState = EmbedState.QRCode;
271
- return;
272
- }
273
- return reject(new Error("PlattarEmbed.startQRCode() - minimum required attributes not set, use scene-id or product-id as a minimum"));
124
+ return this._controller.startQRCode(options).then(accept).catch(reject);
274
125
  });
275
126
  }
276
127
  /**
@@ -278,29 +129,8 @@ class PlattarEmbed extends HTMLElement {
278
129
  * based on the state of the embed, we update the internal structure accordingly
279
130
  */
280
131
  _OnAttributesUpdated() {
281
- // nothing to update in these scenarios
282
- if (this._currentState === EmbedState.None || this._currentState === EmbedState.ProductAR) {
283
- return;
284
- }
285
- // re-render the QR Code when attributes have changed
286
- if (this._currentState === EmbedState.QRCode) {
287
- this.startQRCode(this._qrCodeOptions);
288
- return;
289
- }
290
- // use the messenger function to change variation when attributes have changed
291
- if (this._currentState === EmbedState.SceneViewer) {
292
- const viewer = this.viewer;
293
- if (viewer) {
294
- viewer.messenger.selectVariation(this._productID, this._variationID);
295
- }
296
- return;
297
- }
298
- if (this._currentState === EmbedState.ProductViewer) {
299
- const viewer = this.viewer;
300
- if (viewer) {
301
- viewer.messenger.selectVariation(this._variationID);
302
- }
303
- return;
132
+ if (this._controller) {
133
+ this._controller.onAttributesUpdated();
304
134
  }
305
135
  }
306
136
  }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export * as PlattarWeb from "@plattar/plattar-web";
2
2
  export * as PlattarQRCode from "@plattar/plattar-qrcode";
3
3
  export * as version from "./version";
4
- export { ConfiguratorAR } from "./ar/configurator-ar";
5
4
  export { ProductAR } from "./ar/product-ar";
6
5
  export { SceneAR } from "./ar/scene-ar";
7
6
  export { ModelAR } from "./ar/model-ar";
7
+ export { RawAR } from "./ar/raw-ar";
8
8
  export { Util } from "./util/util";
package/dist/index.js CHANGED
@@ -22,18 +22,18 @@ 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.ModelAR = exports.SceneAR = exports.ProductAR = exports.ConfiguratorAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
25
+ exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = 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
- var configurator_ar_1 = require("./ar/configurator-ar");
30
- Object.defineProperty(exports, "ConfiguratorAR", { enumerable: true, get: function () { return configurator_ar_1.ConfiguratorAR; } });
31
29
  var product_ar_1 = require("./ar/product-ar");
32
30
  Object.defineProperty(exports, "ProductAR", { enumerable: true, get: function () { return product_ar_1.ProductAR; } });
33
31
  var scene_ar_1 = require("./ar/scene-ar");
34
32
  Object.defineProperty(exports, "SceneAR", { enumerable: true, get: function () { return scene_ar_1.SceneAR; } });
35
33
  var model_ar_1 = require("./ar/model-ar");
36
34
  Object.defineProperty(exports, "ModelAR", { enumerable: true, get: function () { return model_ar_1.ModelAR; } });
35
+ var raw_ar_1 = require("./ar/raw-ar");
36
+ Object.defineProperty(exports, "RawAR", { enumerable: true, get: function () { return raw_ar_1.RawAR; } });
37
37
  var util_1 = require("./util/util");
38
38
  Object.defineProperty(exports, "Util", { enumerable: true, get: function () { return util_1.Util; } });
39
39
  const plattar_embed_1 = __importDefault(require("./embed/plattar-embed"));
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.122.2";
1
+ declare const _default: "1.123.2";
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.122.2";
3
+ exports.default = "1.123.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.122.2",
3
+ "version": "1.123.2",
4
4
  "description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -39,12 +39,13 @@
39
39
  "dependencies": {
40
40
  "@plattar/plattar-analytics": "^1.117.2",
41
41
  "@plattar/plattar-api": "^1.120.1",
42
- "@plattar/plattar-qrcode": "1.120.3",
43
- "@plattar/plattar-web": "^1.122.2"
42
+ "@plattar/plattar-qrcode": "1.122.1",
43
+ "@plattar/plattar-services": "^1.120.1",
44
+ "@plattar/plattar-web": "^1.122.3"
44
45
  },
45
46
  "devDependencies": {
46
- "@babel/cli": "^7.16.8",
47
- "@babel/core": "^7.16.12",
47
+ "@babel/cli": "^7.17.0",
48
+ "@babel/core": "^7.17.0",
48
49
  "@babel/preset-env": "^7.16.11",
49
50
  "browserify": "^17.0.0",
50
51
  "typescript": "^4.5.5",
@@ -1,9 +0,0 @@
1
- import { LauncherAR } from "./launcher-ar";
2
- /**
3
- * Performs AR related to Plattar Configurator functionalities
4
- */
5
- export declare class ConfiguratorAR extends LauncherAR {
6
- init(): Promise<LauncherAR>;
7
- launch(): Promise<void>;
8
- start(): void;
9
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfiguratorAR = void 0;
4
- const launcher_ar_1 = require("./launcher-ar");
5
- /**
6
- * Performs AR related to Plattar Configurator functionalities
7
- */
8
- class ConfiguratorAR extends launcher_ar_1.LauncherAR {
9
- init() {
10
- throw new Error("Method not implemented.");
11
- }
12
- launch() {
13
- throw new Error("Method not implemented.");
14
- }
15
- start() {
16
- throw new Error("Method not implemented.");
17
- }
18
- }
19
- exports.ConfiguratorAR = ConfiguratorAR;