@plattar/plattar-ar-adapter 1.122.3 → 1.122.4
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.
- package/build/es2015/plattar-ar-adapter.js +2733 -753
- package/build/es2015/plattar-ar-adapter.min.js +1 -1
- package/build/es2019/plattar-ar-adapter.js +518 -42
- package/build/es2019/plattar-ar-adapter.min.js +1 -1
- package/dist/embed/plattar-embed.d.ts +1 -0
- package/dist/embed/plattar-embed.js +163 -19
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -2
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const plattar_api_1 = require("@plattar/plattar-api");
|
|
4
4
|
const product_ar_1 = require("../ar/product-ar");
|
|
5
|
+
const plattar_services_1 = require("@plattar/plattar-services");
|
|
6
|
+
const util_1 = require("../util/util");
|
|
7
|
+
const raw_ar_1 = require("../ar/raw-ar");
|
|
5
8
|
/**
|
|
6
9
|
* This tracks the current state of the Embed
|
|
7
10
|
*/
|
|
@@ -10,9 +13,18 @@ var EmbedState;
|
|
|
10
13
|
EmbedState[EmbedState["None"] = 0] = "None";
|
|
11
14
|
EmbedState[EmbedState["SceneViewer"] = 1] = "SceneViewer";
|
|
12
15
|
EmbedState[EmbedState["ProductViewer"] = 2] = "ProductViewer";
|
|
13
|
-
EmbedState[EmbedState["
|
|
14
|
-
EmbedState[EmbedState["
|
|
16
|
+
EmbedState[EmbedState["ConfiguratorViewer"] = 3] = "ConfiguratorViewer";
|
|
17
|
+
EmbedState[EmbedState["ProductAR"] = 4] = "ProductAR";
|
|
18
|
+
EmbedState[EmbedState["QRCode"] = 5] = "QRCode";
|
|
15
19
|
})(EmbedState || (EmbedState = {}));
|
|
20
|
+
/**
|
|
21
|
+
* This tracks the current embed type
|
|
22
|
+
*/
|
|
23
|
+
var EmbedType;
|
|
24
|
+
(function (EmbedType) {
|
|
25
|
+
EmbedType[EmbedType["Viewer"] = 0] = "Viewer";
|
|
26
|
+
EmbedType[EmbedType["Configurator"] = 1] = "Configurator";
|
|
27
|
+
})(EmbedType || (EmbedType = {}));
|
|
16
28
|
/**
|
|
17
29
|
* This is the primary <plattar-embed /> node that allows easy embedding
|
|
18
30
|
* of Plattar related content
|
|
@@ -22,6 +34,8 @@ class PlattarEmbed extends HTMLElement {
|
|
|
22
34
|
super();
|
|
23
35
|
// this is the current state of the embed, none by default
|
|
24
36
|
this._currentState = EmbedState.None;
|
|
37
|
+
// this is the current embed type, viewer by default
|
|
38
|
+
this._currentType = EmbedType.Viewer;
|
|
25
39
|
this._qrCodeOptions = {
|
|
26
40
|
color: "#101721",
|
|
27
41
|
qrType: "default",
|
|
@@ -40,6 +54,19 @@ class PlattarEmbed extends HTMLElement {
|
|
|
40
54
|
return this._viewer;
|
|
41
55
|
}
|
|
42
56
|
connectedCallback() {
|
|
57
|
+
const embedType = this.hasAttribute("embed-type") ? this.getAttribute("embed-type") : "viewer";
|
|
58
|
+
if (embedType) {
|
|
59
|
+
switch (embedType.toLowerCase()) {
|
|
60
|
+
case "viewer":
|
|
61
|
+
this._currentType = EmbedType.Viewer;
|
|
62
|
+
break;
|
|
63
|
+
case "configurator":
|
|
64
|
+
this._currentType = EmbedType.Configurator;
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
this._currentType = EmbedType.Viewer;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
43
70
|
const observer = new MutationObserver((mutations) => {
|
|
44
71
|
mutations.forEach((mutation) => {
|
|
45
72
|
if (mutation.type === "attributes") {
|
|
@@ -116,17 +143,73 @@ class PlattarEmbed extends HTMLElement {
|
|
|
116
143
|
if (!this._isReady) {
|
|
117
144
|
return reject(new Error("PlattarEmbed.initAR() - cannot execute as page has not loaded yet"));
|
|
118
145
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const product = new product_ar_1.ProductAR(this._productID, this._variationID);
|
|
122
|
-
return product.init().then(accept).catch(reject);
|
|
146
|
+
if (!util_1.Util.canAugment()) {
|
|
147
|
+
return reject(new Error("PlattarEmbed.initAR() - cannot proceed as AR not available in context"));
|
|
123
148
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
149
|
+
if (this._currentType === EmbedType.Viewer) {
|
|
150
|
+
// if scene is not set but product is, then use ProductAR
|
|
151
|
+
if (!this._sceneID && this._productID) {
|
|
152
|
+
const product = new product_ar_1.ProductAR(this._productID, this._variationID);
|
|
153
|
+
return product.init().then(accept).catch(reject);
|
|
154
|
+
}
|
|
155
|
+
// If Product is set (under any scenario) then use ProductAR
|
|
156
|
+
// NOTE: At some point this should check for Scenes when SceneAR
|
|
157
|
+
// is implemented
|
|
158
|
+
if (this._productID) {
|
|
159
|
+
const product = new product_ar_1.ProductAR(this._productID, this._variationID);
|
|
160
|
+
return product.init().then(accept).catch(reject);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (this._currentType === EmbedType.Configurator) {
|
|
164
|
+
// if scene ID is available and the state is a configurator viewer
|
|
165
|
+
// we can use the real-time configurator state to launch the AR view
|
|
166
|
+
const viewer = this.viewer;
|
|
167
|
+
if (viewer && this._sceneID && this._currentState === EmbedState.ConfiguratorViewer) {
|
|
168
|
+
let output = "glb";
|
|
169
|
+
if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
|
|
170
|
+
output = "usdz";
|
|
171
|
+
}
|
|
172
|
+
viewer.messenger.getARFile(output).then((result) => {
|
|
173
|
+
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
174
|
+
return rawAR.init().then(accept).catch(reject);
|
|
175
|
+
}).catch(reject);
|
|
176
|
+
}
|
|
177
|
+
const configState = this.hasAttribute("config-state") ? this.getAttribute("config-state") : null;
|
|
178
|
+
// otherwise scene ID is available to the viewer is not launched
|
|
179
|
+
// we can use the static configuration state to launch the AR view
|
|
180
|
+
if (this._sceneID && configState) {
|
|
181
|
+
try {
|
|
182
|
+
const decodedb64State = atob(configState);
|
|
183
|
+
const state = JSON.parse(decodedb64State);
|
|
184
|
+
if (state.meta) {
|
|
185
|
+
const sceneProductIndex = state.meta.scene_product_index || 0;
|
|
186
|
+
const variationIndex = state.meta.product_variation_index || 1;
|
|
187
|
+
const states = state.states || [];
|
|
188
|
+
if (states.length > 0) {
|
|
189
|
+
const configurator = new plattar_services_1.Configurator();
|
|
190
|
+
states.forEach((productState) => {
|
|
191
|
+
configurator.addSceneProduct(productState[sceneProductIndex], productState[variationIndex]);
|
|
192
|
+
});
|
|
193
|
+
if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
|
|
194
|
+
configurator.output = "usdz";
|
|
195
|
+
}
|
|
196
|
+
if (util_1.Util.canSceneViewer()) {
|
|
197
|
+
configurator.output = "glb";
|
|
198
|
+
}
|
|
199
|
+
configurator.server = this._server;
|
|
200
|
+
return configurator.get().then((result) => {
|
|
201
|
+
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
202
|
+
rawAR.init().then(accept).catch(reject);
|
|
203
|
+
}).catch(reject);
|
|
204
|
+
}
|
|
205
|
+
return reject(new Error("PlattarEmbed.initAR() - invalid config-state does not have any product states"));
|
|
206
|
+
}
|
|
207
|
+
return reject(new Error("PlattarEmbed.initAR() - invalid config-state for configurator"));
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
return reject(err);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
130
213
|
}
|
|
131
214
|
// otherwise, scene was set so use SceneAR
|
|
132
215
|
if (this._sceneID) {
|
|
@@ -155,8 +238,8 @@ class PlattarEmbed extends HTMLElement {
|
|
|
155
238
|
this._viewer.remove();
|
|
156
239
|
this._viewer = null;
|
|
157
240
|
}
|
|
158
|
-
// if scene is set, we use <plattar-viewer /> node from plattar-web
|
|
159
|
-
if (this._sceneID) {
|
|
241
|
+
// if scene is set and embed is a viewer type, we use <plattar-viewer /> node from plattar-web
|
|
242
|
+
if (this._sceneID && this._currentType === EmbedType.Viewer) {
|
|
160
243
|
const viewer = document.createElement("plattar-viewer");
|
|
161
244
|
viewer.setAttribute("width", this._width);
|
|
162
245
|
viewer.setAttribute("height", this._height);
|
|
@@ -177,6 +260,30 @@ class PlattarEmbed extends HTMLElement {
|
|
|
177
260
|
this._currentState = EmbedState.SceneViewer;
|
|
178
261
|
return;
|
|
179
262
|
}
|
|
263
|
+
// if scene is set and embed is a configurator type, we use <plattar-configurator /> node from plattar-web
|
|
264
|
+
if (this._sceneID && this._currentType === EmbedType.Configurator) {
|
|
265
|
+
const viewer = document.createElement("plattar-configurator");
|
|
266
|
+
viewer.setAttribute("width", this._width);
|
|
267
|
+
viewer.setAttribute("height", this._height);
|
|
268
|
+
viewer.setAttribute("server", this._server);
|
|
269
|
+
viewer.setAttribute("scene-id", this._sceneID);
|
|
270
|
+
const configState = this.hasAttribute("config-state") ? this.getAttribute("config-state") : null;
|
|
271
|
+
const showAR = this.hasAttribute("show-ar") ? this.getAttribute("show-ar") : null;
|
|
272
|
+
if (configState) {
|
|
273
|
+
viewer.setAttribute("config-state", configState);
|
|
274
|
+
}
|
|
275
|
+
if (showAR) {
|
|
276
|
+
viewer.setAttribute("show-ar", showAR);
|
|
277
|
+
}
|
|
278
|
+
viewer.onload = () => {
|
|
279
|
+
return accept(viewer);
|
|
280
|
+
};
|
|
281
|
+
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
282
|
+
shadow.append(viewer);
|
|
283
|
+
this._viewer = viewer;
|
|
284
|
+
this._currentState = EmbedState.ConfiguratorViewer;
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
180
287
|
// if product is set, we use <plattar-product /> node from plattar-web
|
|
181
288
|
if (this._productID) {
|
|
182
289
|
const viewer = document.createElement("plattar-product");
|
|
@@ -211,8 +318,9 @@ class PlattarEmbed extends HTMLElement {
|
|
|
211
318
|
this._viewer.remove();
|
|
212
319
|
this._viewer = null;
|
|
213
320
|
}
|
|
214
|
-
// if scene is set
|
|
215
|
-
|
|
321
|
+
// if scene is set and embed type is viewer
|
|
322
|
+
// we embed a QR code that takes us to viewer.html
|
|
323
|
+
if (this._sceneID && this._currentType == EmbedType.Viewer) {
|
|
216
324
|
const viewer = document.createElement("plattar-qrcode");
|
|
217
325
|
viewer.setAttribute("width", this._width);
|
|
218
326
|
viewer.setAttribute("height", this._height);
|
|
@@ -232,7 +340,41 @@ class PlattarEmbed extends HTMLElement {
|
|
|
232
340
|
if (this._variationID) {
|
|
233
341
|
dst += "&variationId=" + this._variationID;
|
|
234
342
|
}
|
|
235
|
-
viewer.setAttribute("url", dst);
|
|
343
|
+
viewer.setAttribute("url", opt.url || dst);
|
|
344
|
+
viewer.onload = () => {
|
|
345
|
+
return accept(viewer);
|
|
346
|
+
};
|
|
347
|
+
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
348
|
+
shadow.append(viewer);
|
|
349
|
+
this._viewer = viewer;
|
|
350
|
+
this._currentState = EmbedState.QRCode;
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
// if scene is set and embed type is configurator
|
|
354
|
+
// we embed a QR code that takes us to configurator.html
|
|
355
|
+
if (this._sceneID && this._currentType == EmbedType.Configurator) {
|
|
356
|
+
const viewer = document.createElement("plattar-qrcode");
|
|
357
|
+
viewer.setAttribute("width", this._width);
|
|
358
|
+
viewer.setAttribute("height", this._height);
|
|
359
|
+
if (opt.color) {
|
|
360
|
+
viewer.setAttribute("color", opt.color);
|
|
361
|
+
}
|
|
362
|
+
if (opt.margin) {
|
|
363
|
+
viewer.setAttribute("margin", "" + opt.margin);
|
|
364
|
+
}
|
|
365
|
+
if (opt.qrType) {
|
|
366
|
+
viewer.setAttribute("qr-type", opt.qrType);
|
|
367
|
+
}
|
|
368
|
+
let dst = plattar_api_1.Server.location().base + "renderer/configurator.html?scene_id=" + this._sceneID;
|
|
369
|
+
const configState = this.hasAttribute("config-state") ? this.getAttribute("config-state") : null;
|
|
370
|
+
const showAR = this.hasAttribute("show-ar") ? this.getAttribute("show-ar") : null;
|
|
371
|
+
if (configState) {
|
|
372
|
+
dst += "&config_state=" + configState;
|
|
373
|
+
}
|
|
374
|
+
if (showAR) {
|
|
375
|
+
dst += "&show_ar=" + showAR;
|
|
376
|
+
}
|
|
377
|
+
viewer.setAttribute("url", opt.url || dst);
|
|
236
378
|
viewer.onload = () => {
|
|
237
379
|
return accept(viewer);
|
|
238
380
|
};
|
|
@@ -260,7 +402,7 @@ class PlattarEmbed extends HTMLElement {
|
|
|
260
402
|
if (this._variationID) {
|
|
261
403
|
dst += "&variation_id=" + this._variationID;
|
|
262
404
|
}
|
|
263
|
-
viewer.setAttribute("url", dst);
|
|
405
|
+
viewer.setAttribute("url", opt.url || dst);
|
|
264
406
|
viewer.onload = () => {
|
|
265
407
|
return accept(viewer);
|
|
266
408
|
};
|
|
@@ -279,7 +421,9 @@ class PlattarEmbed extends HTMLElement {
|
|
|
279
421
|
*/
|
|
280
422
|
_OnAttributesUpdated() {
|
|
281
423
|
// nothing to update in these scenarios
|
|
282
|
-
if (this._currentState === EmbedState.None ||
|
|
424
|
+
if (this._currentState === EmbedState.None ||
|
|
425
|
+
this._currentState === EmbedState.ProductAR ||
|
|
426
|
+
this._currentState === EmbedState.ConfiguratorViewer) {
|
|
283
427
|
return;
|
|
284
428
|
}
|
|
285
429
|
// re-render the QR Code when attributes have changed
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.122.
|
|
1
|
+
declare const _default: "1.122.4";
|
|
2
2
|
export default _default;
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plattar/plattar-ar-adapter",
|
|
3
|
-
"version": "1.122.
|
|
3
|
+
"version": "1.122.4",
|
|
4
4
|
"description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"@plattar/plattar-analytics": "^1.117.2",
|
|
41
41
|
"@plattar/plattar-api": "^1.120.1",
|
|
42
42
|
"@plattar/plattar-qrcode": "1.120.3",
|
|
43
|
-
"@plattar/plattar-
|
|
43
|
+
"@plattar/plattar-services": "^1.120.1",
|
|
44
|
+
"@plattar/plattar-web": "^1.122.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@babel/cli": "^7.16.8",
|