@plattar/plattar-ar-adapter 1.122.1 → 1.122.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.
- package/build/es2015/plattar-ar-adapter.js +112 -7
- package/build/es2015/plattar-ar-adapter.min.js +1 -1
- package/build/es2019/plattar-ar-adapter.js +92 -6
- package/build/es2019/plattar-ar-adapter.min.js +1 -1
- package/dist/embed/plattar-embed.d.ts +7 -0
- package/dist/embed/plattar-embed.js +91 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -364,6 +364,17 @@ exports.SceneAR = SceneAR;
|
|
|
364
364
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
365
365
|
const plattar_api_1 = require("@plattar/plattar-api");
|
|
366
366
|
const product_ar_1 = require("../ar/product-ar");
|
|
367
|
+
/**
|
|
368
|
+
* This tracks the current state of the Embed
|
|
369
|
+
*/
|
|
370
|
+
var EmbedState;
|
|
371
|
+
(function (EmbedState) {
|
|
372
|
+
EmbedState[EmbedState["None"] = 0] = "None";
|
|
373
|
+
EmbedState[EmbedState["SceneViewer"] = 1] = "SceneViewer";
|
|
374
|
+
EmbedState[EmbedState["ProductViewer"] = 2] = "ProductViewer";
|
|
375
|
+
EmbedState[EmbedState["ProductAR"] = 3] = "ProductAR";
|
|
376
|
+
EmbedState[EmbedState["QRCode"] = 4] = "QRCode";
|
|
377
|
+
})(EmbedState || (EmbedState = {}));
|
|
367
378
|
/**
|
|
368
379
|
* This is the primary <plattar-embed /> node that allows easy embedding
|
|
369
380
|
* of Plattar related content
|
|
@@ -371,6 +382,13 @@ const product_ar_1 = require("../ar/product-ar");
|
|
|
371
382
|
class PlattarEmbed extends HTMLElement {
|
|
372
383
|
constructor() {
|
|
373
384
|
super();
|
|
385
|
+
// this is the current state of the embed, none by default
|
|
386
|
+
this._currentState = EmbedState.None;
|
|
387
|
+
this._qrCodeOptions = {
|
|
388
|
+
color: "#101721",
|
|
389
|
+
qrType: "default",
|
|
390
|
+
margin: 0
|
|
391
|
+
};
|
|
374
392
|
this._sceneID = null;
|
|
375
393
|
this._productID = null;
|
|
376
394
|
this._variationID = null;
|
|
@@ -384,6 +402,35 @@ class PlattarEmbed extends HTMLElement {
|
|
|
384
402
|
return this._viewer;
|
|
385
403
|
}
|
|
386
404
|
connectedCallback() {
|
|
405
|
+
const observer = new MutationObserver((mutations) => {
|
|
406
|
+
mutations.forEach((mutation) => {
|
|
407
|
+
if (mutation.type === "attributes") {
|
|
408
|
+
const sceneID = this.hasAttribute("scene-id") ? this.getAttribute("scene-id") : null;
|
|
409
|
+
const productID = this.hasAttribute("product-id") ? this.getAttribute("product-id") : null;
|
|
410
|
+
const variationID = this.hasAttribute("variation-id") ? this.getAttribute("variation-id") : null;
|
|
411
|
+
let updated = false;
|
|
412
|
+
if (sceneID !== this._sceneID) {
|
|
413
|
+
this._sceneID = sceneID;
|
|
414
|
+
updated = true;
|
|
415
|
+
}
|
|
416
|
+
if (productID !== this._productID) {
|
|
417
|
+
this._productID = productID;
|
|
418
|
+
updated = true;
|
|
419
|
+
}
|
|
420
|
+
if (variationID !== this._variationID) {
|
|
421
|
+
this._variationID = variationID;
|
|
422
|
+
updated = true;
|
|
423
|
+
}
|
|
424
|
+
if (updated) {
|
|
425
|
+
// re-render based on internal state
|
|
426
|
+
this._OnAttributesUpdated();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
observer.observe(this, {
|
|
432
|
+
attributes: true
|
|
433
|
+
});
|
|
387
434
|
const server = this.hasAttribute("server") ? this.getAttribute("server") : "production";
|
|
388
435
|
plattar_api_1.Server.create(plattar_api_1.Server.match(server || "production"));
|
|
389
436
|
if (server) {
|
|
@@ -436,6 +483,13 @@ class PlattarEmbed extends HTMLElement {
|
|
|
436
483
|
const product = new product_ar_1.ProductAR(this._productID, this._variationID);
|
|
437
484
|
return product.init().then(accept).catch(reject);
|
|
438
485
|
}
|
|
486
|
+
// If Product is set (under any scenario) then use ProductAR
|
|
487
|
+
// NOTE: At some point this should check for Scenes when SceneAR
|
|
488
|
+
// is implemented
|
|
489
|
+
if (this._productID) {
|
|
490
|
+
const product = new product_ar_1.ProductAR(this._productID, this._variationID);
|
|
491
|
+
return product.init().then(accept).catch(reject);
|
|
492
|
+
}
|
|
439
493
|
// otherwise, scene was set so use SceneAR
|
|
440
494
|
if (this._sceneID) {
|
|
441
495
|
return reject(new Error("PlattarEmbed.initAR() - scene-id not yet supported"));
|
|
@@ -482,6 +536,7 @@ class PlattarEmbed extends HTMLElement {
|
|
|
482
536
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
483
537
|
shadow.append(viewer);
|
|
484
538
|
this._viewer = viewer;
|
|
539
|
+
this._currentState = EmbedState.SceneViewer;
|
|
485
540
|
return;
|
|
486
541
|
}
|
|
487
542
|
// if product is set, we use <plattar-product /> node from plattar-web
|
|
@@ -500,6 +555,7 @@ class PlattarEmbed extends HTMLElement {
|
|
|
500
555
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
501
556
|
shadow.append(viewer);
|
|
502
557
|
this._viewer = viewer;
|
|
558
|
+
this._currentState = EmbedState.ProductViewer;
|
|
503
559
|
return;
|
|
504
560
|
}
|
|
505
561
|
return reject(new Error("PlattarEmbed.startViewer() - minimum required attributes not set, use scene-id or product-id as a minimum"));
|
|
@@ -510,11 +566,9 @@ class PlattarEmbed extends HTMLElement {
|
|
|
510
566
|
if (!this._isReady) {
|
|
511
567
|
return reject(new Error("PlattarEmbed.startQRCode() - cannot execute as page has not loaded yet"));
|
|
512
568
|
}
|
|
513
|
-
const opt = options ||
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
margin: 0
|
|
517
|
-
};
|
|
569
|
+
const opt = options || this._qrCodeOptions;
|
|
570
|
+
// reset instance for later use
|
|
571
|
+
this._qrCodeOptions = opt;
|
|
518
572
|
if (this._viewer) {
|
|
519
573
|
this._viewer.remove();
|
|
520
574
|
this._viewer = null;
|
|
@@ -547,6 +601,7 @@ class PlattarEmbed extends HTMLElement {
|
|
|
547
601
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
548
602
|
shadow.append(viewer);
|
|
549
603
|
this._viewer = viewer;
|
|
604
|
+
this._currentState = EmbedState.QRCode;
|
|
550
605
|
return;
|
|
551
606
|
}
|
|
552
607
|
// if product is set, we embed a QR code that takes us to product.html
|
|
@@ -574,11 +629,42 @@ class PlattarEmbed extends HTMLElement {
|
|
|
574
629
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
575
630
|
shadow.append(viewer);
|
|
576
631
|
this._viewer = viewer;
|
|
632
|
+
this._currentState = EmbedState.QRCode;
|
|
577
633
|
return;
|
|
578
634
|
}
|
|
579
635
|
return reject(new Error("PlattarEmbed.startQRCode() - minimum required attributes not set, use scene-id or product-id as a minimum"));
|
|
580
636
|
});
|
|
581
637
|
}
|
|
638
|
+
/**
|
|
639
|
+
* This is called by the observer if any of the embed attributes have changed
|
|
640
|
+
* based on the state of the embed, we update the internal structure accordingly
|
|
641
|
+
*/
|
|
642
|
+
_OnAttributesUpdated() {
|
|
643
|
+
// nothing to update in these scenarios
|
|
644
|
+
if (this._currentState === EmbedState.None || this._currentState === EmbedState.ProductAR) {
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
// re-render the QR Code when attributes have changed
|
|
648
|
+
if (this._currentState === EmbedState.QRCode) {
|
|
649
|
+
this.startQRCode(this._qrCodeOptions);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
// use the messenger function to change variation when attributes have changed
|
|
653
|
+
if (this._currentState === EmbedState.SceneViewer) {
|
|
654
|
+
const viewer = this.viewer;
|
|
655
|
+
if (viewer) {
|
|
656
|
+
viewer.messenger.selectVariation(this._productID, this._variationID);
|
|
657
|
+
}
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (this._currentState === EmbedState.ProductViewer) {
|
|
661
|
+
const viewer = this.viewer;
|
|
662
|
+
if (viewer) {
|
|
663
|
+
viewer.messenger.selectVariation(this._variationID);
|
|
664
|
+
}
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
582
668
|
}
|
|
583
669
|
exports.default = PlattarEmbed;
|
|
584
670
|
|
|
@@ -720,7 +806,7 @@ exports.Util = Util;
|
|
|
720
806
|
},{}],9:[function(require,module,exports){
|
|
721
807
|
"use strict";
|
|
722
808
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
723
|
-
exports.default = "1.122.
|
|
809
|
+
exports.default = "1.122.2";
|
|
724
810
|
|
|
725
811
|
},{}],10:[function(require,module,exports){
|
|
726
812
|
"use strict";
|