@plattar/plattar-ar-adapter 1.154.2 → 1.155.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 +2125 -1140
- package/build/es2015/plattar-ar-adapter.min.js +1 -1
- package/build/es2019/plattar-ar-adapter.js +1059 -787
- package/build/es2019/plattar-ar-adapter.min.js +1 -1
- package/dist/ar/configurator-ar.d.ts +29 -0
- package/dist/ar/configurator-ar.js +161 -0
- package/dist/ar/launcher-ar.js +3 -7
- package/dist/ar/model-ar.js +2 -0
- package/dist/ar/product-ar.js +2 -0
- package/dist/ar/raw-ar.js +2 -0
- package/dist/ar/scene-ar.js +2 -0
- package/dist/embed/controllers/configurator-controller.d.ts +4 -2
- package/dist/embed/controllers/configurator-controller.js +171 -179
- package/dist/embed/controllers/plattar-controller.d.ts +21 -1
- package/dist/embed/controllers/plattar-controller.js +138 -67
- package/dist/embed/controllers/product-controller.d.ts +12 -1
- package/dist/embed/controllers/product-controller.js +79 -2
- package/dist/embed/controllers/vto-controller.d.ts +4 -2
- package/dist/embed/controllers/vto-controller.js +190 -194
- package/dist/embed/plattar-embed.d.ts +23 -0
- package/dist/embed/plattar-embed.js +138 -91
- package/dist/util/configurator-state.d.ts +48 -6
- package/dist/util/configurator-state.js +145 -28
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/embed/controllers/viewer-controller.d.ts +0 -14
- package/dist/embed/controllers/viewer-controller.js +0 -193
package/package.json
CHANGED
|
@@ -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;
|