@plattar/plattar-ar-adapter 1.154.2 → 1.155.1

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,14 +0,0 @@
1
- import { LauncherAR } from "../../ar/launcher-ar";
2
- import { PlattarController } from "./plattar-controller";
3
- /**
4
- * Manages an instance of the <plattar-viewer> HTML Element
5
- */
6
- export declare class ViewerController extends PlattarController {
7
- constructor(parent: HTMLElement);
8
- onAttributesUpdated(): void;
9
- startViewerQRCode(options: any): Promise<HTMLElement>;
10
- startRenderer(): Promise<HTMLElement>;
11
- initAR(): Promise<LauncherAR>;
12
- removeRenderer(): boolean;
13
- get element(): HTMLElement | null;
14
- }
@@ -1,193 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ViewerController = void 0;
4
- const plattar_api_1 = require("@plattar/plattar-api");
5
- const product_ar_1 = require("../../ar/product-ar");
6
- const scene_ar_1 = require("../../ar/scene-ar");
7
- const scene_product_ar_1 = require("../../ar/scene-product-ar");
8
- const configurator_state_1 = require("../../util/configurator-state");
9
- const util_1 = require("../../util/util");
10
- const plattar_controller_1 = require("./plattar-controller");
11
- /**
12
- * Manages an instance of the <plattar-viewer> HTML Element
13
- */
14
- class ViewerController extends plattar_controller_1.PlattarController {
15
- constructor(parent) {
16
- super(parent);
17
- }
18
- onAttributesUpdated() {
19
- const state = this._state;
20
- // re-render the QR Code when attributes have changed
21
- if (state === plattar_controller_1.ControllerState.QRCode) {
22
- this.startQRCode(this._prevQROpt);
23
- return;
24
- }
25
- // use the messenger function to change variation when attributes have changed
26
- if (state === plattar_controller_1.ControllerState.Renderer) {
27
- const viewer = this._element;
28
- if (viewer) {
29
- const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
30
- const variationID = this.getAttribute("variation-id");
31
- if (productID && variationID && viewer.messenger) {
32
- viewer.messenger.selectVariation(productID, variationID);
33
- }
34
- }
35
- return;
36
- }
37
- }
38
- startViewerQRCode(options) {
39
- return new Promise((accept, reject) => {
40
- // remove the old renderer instance if any
41
- this.removeRenderer();
42
- const sceneID = this.getAttribute("scene-id");
43
- if (sceneID) {
44
- const opt = options || this._GetDefaultQROptions();
45
- const viewer = document.createElement("plattar-qrcode");
46
- // required attributes with defaults for plattar-viewer node
47
- const width = this.getAttribute("width") || "500px";
48
- const height = this.getAttribute("height") || "500px";
49
- viewer.setAttribute("width", width);
50
- viewer.setAttribute("height", height);
51
- if (opt.color) {
52
- viewer.setAttribute("color", opt.color);
53
- }
54
- if (opt.margin) {
55
- viewer.setAttribute("margin", "" + opt.margin);
56
- }
57
- if (opt.qrType) {
58
- viewer.setAttribute("qr-type", opt.qrType);
59
- }
60
- viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
61
- let dst = plattar_api_1.Server.location().base + "renderer/viewer.html?scene_id=" + sceneID;
62
- // optional attributes
63
- const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
64
- const variationID = this.getAttribute("variation-id");
65
- const variationSKU = this.getAttribute("variation-sku");
66
- const showAR = this.getAttribute("show-ar");
67
- if (productID) {
68
- dst += "&productId=" + productID;
69
- }
70
- if (variationID) {
71
- dst += "&variationId=" + variationID;
72
- }
73
- if (variationSKU) {
74
- dst += "&variationSku=" + variationSKU;
75
- }
76
- if (showAR) {
77
- dst += "&show_ar=" + showAR;
78
- }
79
- viewer.setAttribute("url", opt.url || dst);
80
- viewer.onload = () => {
81
- return accept(viewer);
82
- };
83
- this.append(viewer);
84
- this._element = viewer;
85
- this._state = plattar_controller_1.ControllerState.QRCode;
86
- this._prevQROpt = opt;
87
- return;
88
- }
89
- return reject(new Error("ViewerController.startQRCode() - minimum required attributes not set, use scene-id as a minimum"));
90
- });
91
- }
92
- startRenderer() {
93
- return new Promise((accept, reject) => {
94
- // remove the old renderer instance if any
95
- this.removeRenderer();
96
- const sceneID = this.getAttribute("scene-id");
97
- if (sceneID) {
98
- // required attributes with defaults for plattar-viewer node
99
- const width = this.getAttribute("width") || "500px";
100
- const height = this.getAttribute("height") || "500px";
101
- const server = this.getAttribute("server") || "production";
102
- const viewer = document.createElement("plattar-viewer");
103
- viewer.setAttribute("width", width);
104
- viewer.setAttribute("height", height);
105
- viewer.setAttribute("server", server);
106
- viewer.setAttribute("scene-id", sceneID);
107
- // optional attributes
108
- const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
109
- const variationID = this.getAttribute("variation-id");
110
- const variationSKU = this.getAttribute("variation-sku");
111
- const showAR = this.getAttribute("show-ar");
112
- if (productID) {
113
- viewer.setAttribute("product-id", productID);
114
- }
115
- if (variationID) {
116
- viewer.setAttribute("variation-id", variationID);
117
- }
118
- if (variationSKU) {
119
- viewer.setAttribute("variation-sku", variationSKU);
120
- }
121
- if (showAR) {
122
- viewer.setAttribute("show-ar", showAR);
123
- }
124
- viewer.onload = () => {
125
- return accept(viewer);
126
- };
127
- this.append(viewer);
128
- this._element = viewer;
129
- this._state = plattar_controller_1.ControllerState.Renderer;
130
- return;
131
- }
132
- return reject(new Error("ViewerController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
133
- });
134
- }
135
- initAR() {
136
- return new Promise((accept, reject) => {
137
- if (!util_1.Util.canAugment()) {
138
- return reject(new Error("ViewerController.initAR() - cannot proceed as AR not available in context"));
139
- }
140
- const productID = this.getAttribute("product-id");
141
- // use product-id if available
142
- if (productID) {
143
- const variationID = this.getAttribute("variation-id");
144
- const variationSKU = this.getAttribute("variation-sku");
145
- const product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
146
- return product.init().then(accept).catch(reject);
147
- }
148
- const sceneProductID = this.getAttribute("scene-product-id");
149
- // use scene-product-id if available
150
- if (sceneProductID) {
151
- const variationID = this.getAttribute("variation-id");
152
- const variationSKU = this.getAttribute("variation-sku");
153
- const product = new scene_product_ar_1.SceneProductAR(sceneProductID, variationID, variationSKU);
154
- return product.init().then(accept).catch(reject);
155
- }
156
- const sceneID = this.getAttribute("scene-id");
157
- // fallback to using default SceneAR implementation
158
- if (sceneID) {
159
- // special case - check if scene only has a single product, if so
160
- // we need to use provided variation-id or variation-sku to override
161
- const variationID = this.getAttribute("variation-id");
162
- const variationSKU = this.getAttribute("variation-sku");
163
- // just do scene-ar if variation ID and variation SKU is not set
164
- if (!variationID && !variationSKU) {
165
- const sceneAR = new scene_ar_1.SceneAR(sceneID);
166
- return sceneAR.init().then(accept).catch(reject);
167
- }
168
- // otherwise decode scene
169
- return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
170
- const firstProduct = state.first();
171
- if (state.length > 1 || !firstProduct) {
172
- return reject(new Error("ViewerController.initAR() - single product required to override variation-id or variation-sku"));
173
- }
174
- const product = new scene_product_ar_1.SceneProductAR(firstProduct.scene_product_id, variationID, variationSKU);
175
- return product.init().then(accept).catch(reject);
176
- }).catch(reject);
177
- }
178
- return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
179
- });
180
- }
181
- removeRenderer() {
182
- if (this._element) {
183
- this._element.remove();
184
- this._element = null;
185
- return true;
186
- }
187
- return false;
188
- }
189
- get element() {
190
- return this._element;
191
- }
192
- }
193
- exports.ViewerController = ViewerController;