@plattar/plattar-ar-adapter 1.121.1 → 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 +3670 -1318
- package/build/es2015/plattar-ar-adapter.min.js +1 -1
- package/build/es2019/plattar-ar-adapter.js +869 -137
- package/build/es2019/plattar-ar-adapter.min.js +1 -1
- package/dist/ar/raw-ar.d.ts +30 -0
- package/dist/ar/raw-ar.js +110 -0
- package/dist/embed/plattar-embed.d.ts +8 -0
- package/dist/embed/plattar-embed.js +258 -16
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -6
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LauncherAR } from "./launcher-ar";
|
|
2
|
+
/**
|
|
3
|
+
* Allows launching AR Experiences provided a single remote 3D Model file
|
|
4
|
+
*/
|
|
5
|
+
export declare class RawAR extends LauncherAR {
|
|
6
|
+
private readonly _modelLocation;
|
|
7
|
+
private _ar;
|
|
8
|
+
constructor(modelLocation?: string | undefined | null);
|
|
9
|
+
get modelLocation(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Initialise the RawAR instance. This returns a Promise that resolves
|
|
12
|
+
* successfully if initialisation is successful, otherwise it will fail.
|
|
13
|
+
*
|
|
14
|
+
* filure can occur for a number of reasons but it generally means that AR
|
|
15
|
+
* cannot be performed.
|
|
16
|
+
*/
|
|
17
|
+
init(): Promise<LauncherAR>;
|
|
18
|
+
/**
|
|
19
|
+
* Initialise and launch with a single function call. this is mostly for convenience.
|
|
20
|
+
* Use .init() and .start() separately for fine-grained control
|
|
21
|
+
*/
|
|
22
|
+
launch(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Launches the internal AR instance using an appropriate version of AR Viewers
|
|
25
|
+
*/
|
|
26
|
+
start(): void;
|
|
27
|
+
canQuicklook(): boolean;
|
|
28
|
+
canRealityViewer(): boolean;
|
|
29
|
+
canSceneViewer(): boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RawAR = void 0;
|
|
7
|
+
const util_1 = require("../util/util");
|
|
8
|
+
const quicklook_viewer_1 = __importDefault(require("../viewers/quicklook-viewer"));
|
|
9
|
+
const reality_viewer_1 = __importDefault(require("../viewers/reality-viewer"));
|
|
10
|
+
const scene_viewer_1 = __importDefault(require("../viewers/scene-viewer"));
|
|
11
|
+
const launcher_ar_1 = require("./launcher-ar");
|
|
12
|
+
/**
|
|
13
|
+
* Allows launching AR Experiences provided a single remote 3D Model file
|
|
14
|
+
*/
|
|
15
|
+
class RawAR extends launcher_ar_1.LauncherAR {
|
|
16
|
+
constructor(modelLocation = null) {
|
|
17
|
+
super();
|
|
18
|
+
if (!modelLocation) {
|
|
19
|
+
throw new Error("RawAR.constructor(modelLocation) - modelLocation must be defined");
|
|
20
|
+
}
|
|
21
|
+
const lowerLoc = modelLocation.toLowerCase();
|
|
22
|
+
if (lowerLoc.endsWith("usdz") || lowerLoc.endsWith("glb") || lowerLoc.endsWith("gltf") || lowerLoc.endsWith("reality")) {
|
|
23
|
+
this._modelLocation = modelLocation;
|
|
24
|
+
this._ar = null;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error("RawAR.constructor(modelLocation) - modelLocation must be one of gltf, glb, usdz or reality");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
get modelLocation() {
|
|
31
|
+
return this._modelLocation;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Initialise the RawAR instance. This returns a Promise that resolves
|
|
35
|
+
* successfully if initialisation is successful, otherwise it will fail.
|
|
36
|
+
*
|
|
37
|
+
* filure can occur for a number of reasons but it generally means that AR
|
|
38
|
+
* cannot be performed.
|
|
39
|
+
*/
|
|
40
|
+
init() {
|
|
41
|
+
return new Promise((accept, reject) => {
|
|
42
|
+
if (!util_1.Util.canAugment()) {
|
|
43
|
+
return reject(new Error("RawAR.init() - cannot proceed as AR not available in context"));
|
|
44
|
+
}
|
|
45
|
+
const modelLocation = this._modelLocation;
|
|
46
|
+
const lowerLoc = modelLocation.toLowerCase();
|
|
47
|
+
// we need to define our AR module here
|
|
48
|
+
// we are in Safari/Quicklook mode here
|
|
49
|
+
if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
|
|
50
|
+
// load the reality experience if dealing with reality file
|
|
51
|
+
if (lowerLoc.endsWith("reality") && util_1.Util.canRealityViewer()) {
|
|
52
|
+
this._ar = new reality_viewer_1.default();
|
|
53
|
+
this._ar.modelUrl = modelLocation;
|
|
54
|
+
return accept(this);
|
|
55
|
+
}
|
|
56
|
+
// load the usdz experience if dealing with usdz file
|
|
57
|
+
if (lowerLoc.endsWith("usdz") && util_1.Util.canQuicklook()) {
|
|
58
|
+
this._ar = new quicklook_viewer_1.default();
|
|
59
|
+
this._ar.modelUrl = modelLocation;
|
|
60
|
+
return accept(this);
|
|
61
|
+
}
|
|
62
|
+
return reject(new Error("RawAR.init() - cannot proceed as model is not a .usdz or .reality file"));
|
|
63
|
+
}
|
|
64
|
+
// check android
|
|
65
|
+
if (util_1.Util.canSceneViewer()) {
|
|
66
|
+
if (lowerLoc.endsWith("glb") || lowerLoc.endsWith("gltf")) {
|
|
67
|
+
this._ar = new scene_viewer_1.default();
|
|
68
|
+
this._ar.modelUrl = modelLocation;
|
|
69
|
+
return accept(this);
|
|
70
|
+
}
|
|
71
|
+
return reject(new Error("RawAR.init() - cannot proceed as model is not a .glb or .gltf file"));
|
|
72
|
+
}
|
|
73
|
+
// otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
|
|
74
|
+
// earlier in the process
|
|
75
|
+
return reject(new Error("RawAR.init() - could not initialise AR correctly, check values"));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Initialise and launch with a single function call. this is mostly for convenience.
|
|
80
|
+
* Use .init() and .start() separately for fine-grained control
|
|
81
|
+
*/
|
|
82
|
+
launch() {
|
|
83
|
+
return new Promise((accept, reject) => {
|
|
84
|
+
this.init().then((value) => {
|
|
85
|
+
value.start();
|
|
86
|
+
return accept();
|
|
87
|
+
}).catch(reject);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Launches the internal AR instance using an appropriate version of AR Viewers
|
|
92
|
+
*/
|
|
93
|
+
start() {
|
|
94
|
+
if (!this._ar) {
|
|
95
|
+
throw new Error("RawAR.start() - cannot proceed as AR instance is null");
|
|
96
|
+
}
|
|
97
|
+
// this was initialised via the init() function
|
|
98
|
+
this._ar.start();
|
|
99
|
+
}
|
|
100
|
+
canQuicklook() {
|
|
101
|
+
return this._ar && this._ar.nodeType === "Quick Look" ? true : false;
|
|
102
|
+
}
|
|
103
|
+
canRealityViewer() {
|
|
104
|
+
return this._ar && this._ar.nodeType === "Reality Viewer" ? true : false;
|
|
105
|
+
}
|
|
106
|
+
canSceneViewer() {
|
|
107
|
+
return this._ar && this._ar.nodeType === "Scene Viewer" ? true : false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.RawAR = RawAR;
|
|
@@ -4,6 +4,9 @@ import { LauncherAR } from "../ar/launcher-ar";
|
|
|
4
4
|
* of Plattar related content
|
|
5
5
|
*/
|
|
6
6
|
export default class PlattarEmbed extends HTMLElement {
|
|
7
|
+
private _currentState;
|
|
8
|
+
private _currentType;
|
|
9
|
+
private _qrCodeOptions;
|
|
7
10
|
private _sceneID;
|
|
8
11
|
private _productID;
|
|
9
12
|
private _variationID;
|
|
@@ -19,4 +22,9 @@ export default class PlattarEmbed extends HTMLElement {
|
|
|
19
22
|
startAR(): Promise<void>;
|
|
20
23
|
startViewer(): Promise<HTMLElement>;
|
|
21
24
|
startQRCode(options?: any | undefined | null): Promise<HTMLElement>;
|
|
25
|
+
/**
|
|
26
|
+
* This is called by the observer if any of the embed attributes have changed
|
|
27
|
+
* based on the state of the embed, we update the internal structure accordingly
|
|
28
|
+
*/
|
|
29
|
+
private _OnAttributesUpdated;
|
|
22
30
|
}
|
|
@@ -2,6 +2,29 @@
|
|
|
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");
|
|
8
|
+
/**
|
|
9
|
+
* This tracks the current state of the Embed
|
|
10
|
+
*/
|
|
11
|
+
var EmbedState;
|
|
12
|
+
(function (EmbedState) {
|
|
13
|
+
EmbedState[EmbedState["None"] = 0] = "None";
|
|
14
|
+
EmbedState[EmbedState["SceneViewer"] = 1] = "SceneViewer";
|
|
15
|
+
EmbedState[EmbedState["ProductViewer"] = 2] = "ProductViewer";
|
|
16
|
+
EmbedState[EmbedState["ConfiguratorViewer"] = 3] = "ConfiguratorViewer";
|
|
17
|
+
EmbedState[EmbedState["ProductAR"] = 4] = "ProductAR";
|
|
18
|
+
EmbedState[EmbedState["QRCode"] = 5] = "QRCode";
|
|
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 = {}));
|
|
5
28
|
/**
|
|
6
29
|
* This is the primary <plattar-embed /> node that allows easy embedding
|
|
7
30
|
* of Plattar related content
|
|
@@ -9,6 +32,15 @@ const product_ar_1 = require("../ar/product-ar");
|
|
|
9
32
|
class PlattarEmbed extends HTMLElement {
|
|
10
33
|
constructor() {
|
|
11
34
|
super();
|
|
35
|
+
// this is the current state of the embed, none by default
|
|
36
|
+
this._currentState = EmbedState.None;
|
|
37
|
+
// this is the current embed type, viewer by default
|
|
38
|
+
this._currentType = EmbedType.Viewer;
|
|
39
|
+
this._qrCodeOptions = {
|
|
40
|
+
color: "#101721",
|
|
41
|
+
qrType: "default",
|
|
42
|
+
margin: 0
|
|
43
|
+
};
|
|
12
44
|
this._sceneID = null;
|
|
13
45
|
this._productID = null;
|
|
14
46
|
this._variationID = null;
|
|
@@ -22,6 +54,48 @@ class PlattarEmbed extends HTMLElement {
|
|
|
22
54
|
return this._viewer;
|
|
23
55
|
}
|
|
24
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
|
+
}
|
|
70
|
+
const observer = new MutationObserver((mutations) => {
|
|
71
|
+
mutations.forEach((mutation) => {
|
|
72
|
+
if (mutation.type === "attributes") {
|
|
73
|
+
const sceneID = this.hasAttribute("scene-id") ? this.getAttribute("scene-id") : null;
|
|
74
|
+
const productID = this.hasAttribute("product-id") ? this.getAttribute("product-id") : null;
|
|
75
|
+
const variationID = this.hasAttribute("variation-id") ? this.getAttribute("variation-id") : null;
|
|
76
|
+
let updated = false;
|
|
77
|
+
if (sceneID !== this._sceneID) {
|
|
78
|
+
this._sceneID = sceneID;
|
|
79
|
+
updated = true;
|
|
80
|
+
}
|
|
81
|
+
if (productID !== this._productID) {
|
|
82
|
+
this._productID = productID;
|
|
83
|
+
updated = true;
|
|
84
|
+
}
|
|
85
|
+
if (variationID !== this._variationID) {
|
|
86
|
+
this._variationID = variationID;
|
|
87
|
+
updated = true;
|
|
88
|
+
}
|
|
89
|
+
if (updated) {
|
|
90
|
+
// re-render based on internal state
|
|
91
|
+
this._OnAttributesUpdated();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
observer.observe(this, {
|
|
97
|
+
attributes: true
|
|
98
|
+
});
|
|
25
99
|
const server = this.hasAttribute("server") ? this.getAttribute("server") : "production";
|
|
26
100
|
plattar_api_1.Server.create(plattar_api_1.Server.match(server || "production"));
|
|
27
101
|
if (server) {
|
|
@@ -69,10 +143,73 @@ class PlattarEmbed extends HTMLElement {
|
|
|
69
143
|
if (!this._isReady) {
|
|
70
144
|
return reject(new Error("PlattarEmbed.initAR() - cannot execute as page has not loaded yet"));
|
|
71
145
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
146
|
+
if (!util_1.Util.canAugment()) {
|
|
147
|
+
return reject(new Error("PlattarEmbed.initAR() - cannot proceed as AR not available in context"));
|
|
148
|
+
}
|
|
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
|
+
}
|
|
76
213
|
}
|
|
77
214
|
// otherwise, scene was set so use SceneAR
|
|
78
215
|
if (this._sceneID) {
|
|
@@ -101,19 +238,50 @@ class PlattarEmbed extends HTMLElement {
|
|
|
101
238
|
this._viewer.remove();
|
|
102
239
|
this._viewer = null;
|
|
103
240
|
}
|
|
104
|
-
// if scene is set, we use <plattar-viewer /> node from plattar-web
|
|
105
|
-
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) {
|
|
106
243
|
const viewer = document.createElement("plattar-viewer");
|
|
107
244
|
viewer.setAttribute("width", this._width);
|
|
108
245
|
viewer.setAttribute("height", this._height);
|
|
109
246
|
viewer.setAttribute("server", this._server);
|
|
110
247
|
viewer.setAttribute("scene-id", this._sceneID);
|
|
248
|
+
if (this._productID) {
|
|
249
|
+
viewer.setAttribute("product-id", this._productID);
|
|
250
|
+
}
|
|
251
|
+
if (this._variationID) {
|
|
252
|
+
viewer.setAttribute("variation-id", this._variationID);
|
|
253
|
+
}
|
|
254
|
+
viewer.onload = () => {
|
|
255
|
+
return accept(viewer);
|
|
256
|
+
};
|
|
257
|
+
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
258
|
+
shadow.append(viewer);
|
|
259
|
+
this._viewer = viewer;
|
|
260
|
+
this._currentState = EmbedState.SceneViewer;
|
|
261
|
+
return;
|
|
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
|
+
}
|
|
111
278
|
viewer.onload = () => {
|
|
112
279
|
return accept(viewer);
|
|
113
280
|
};
|
|
114
281
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
115
282
|
shadow.append(viewer);
|
|
116
283
|
this._viewer = viewer;
|
|
284
|
+
this._currentState = EmbedState.ConfiguratorViewer;
|
|
117
285
|
return;
|
|
118
286
|
}
|
|
119
287
|
// if product is set, we use <plattar-product /> node from plattar-web
|
|
@@ -132,6 +300,7 @@ class PlattarEmbed extends HTMLElement {
|
|
|
132
300
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
133
301
|
shadow.append(viewer);
|
|
134
302
|
this._viewer = viewer;
|
|
303
|
+
this._currentState = EmbedState.ProductViewer;
|
|
135
304
|
return;
|
|
136
305
|
}
|
|
137
306
|
return reject(new Error("PlattarEmbed.startViewer() - minimum required attributes not set, use scene-id or product-id as a minimum"));
|
|
@@ -142,17 +311,48 @@ class PlattarEmbed extends HTMLElement {
|
|
|
142
311
|
if (!this._isReady) {
|
|
143
312
|
return reject(new Error("PlattarEmbed.startQRCode() - cannot execute as page has not loaded yet"));
|
|
144
313
|
}
|
|
145
|
-
const opt = options ||
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
margin: 0
|
|
149
|
-
};
|
|
314
|
+
const opt = options || this._qrCodeOptions;
|
|
315
|
+
// reset instance for later use
|
|
316
|
+
this._qrCodeOptions = opt;
|
|
150
317
|
if (this._viewer) {
|
|
151
318
|
this._viewer.remove();
|
|
152
319
|
this._viewer = null;
|
|
153
320
|
}
|
|
154
|
-
// if scene is set
|
|
155
|
-
|
|
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) {
|
|
324
|
+
const viewer = document.createElement("plattar-qrcode");
|
|
325
|
+
viewer.setAttribute("width", this._width);
|
|
326
|
+
viewer.setAttribute("height", this._height);
|
|
327
|
+
if (opt.color) {
|
|
328
|
+
viewer.setAttribute("color", opt.color);
|
|
329
|
+
}
|
|
330
|
+
if (opt.margin) {
|
|
331
|
+
viewer.setAttribute("margin", "" + opt.margin);
|
|
332
|
+
}
|
|
333
|
+
if (opt.qrType) {
|
|
334
|
+
viewer.setAttribute("qr-type", opt.qrType);
|
|
335
|
+
}
|
|
336
|
+
let dst = plattar_api_1.Server.location().base + "renderer/viewer.html?scene_id=" + this._sceneID;
|
|
337
|
+
if (this._productID) {
|
|
338
|
+
dst += "&productId=" + this._productID;
|
|
339
|
+
}
|
|
340
|
+
if (this._variationID) {
|
|
341
|
+
dst += "&variationId=" + this._variationID;
|
|
342
|
+
}
|
|
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) {
|
|
156
356
|
const viewer = document.createElement("plattar-qrcode");
|
|
157
357
|
viewer.setAttribute("width", this._width);
|
|
158
358
|
viewer.setAttribute("height", this._height);
|
|
@@ -165,14 +365,23 @@ class PlattarEmbed extends HTMLElement {
|
|
|
165
365
|
if (opt.qrType) {
|
|
166
366
|
viewer.setAttribute("qr-type", opt.qrType);
|
|
167
367
|
}
|
|
168
|
-
|
|
169
|
-
|
|
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);
|
|
170
378
|
viewer.onload = () => {
|
|
171
379
|
return accept(viewer);
|
|
172
380
|
};
|
|
173
381
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
174
382
|
shadow.append(viewer);
|
|
175
383
|
this._viewer = viewer;
|
|
384
|
+
this._currentState = EmbedState.QRCode;
|
|
176
385
|
return;
|
|
177
386
|
}
|
|
178
387
|
// if product is set, we embed a QR code that takes us to product.html
|
|
@@ -193,17 +402,50 @@ class PlattarEmbed extends HTMLElement {
|
|
|
193
402
|
if (this._variationID) {
|
|
194
403
|
dst += "&variation_id=" + this._variationID;
|
|
195
404
|
}
|
|
196
|
-
viewer.setAttribute("url", dst);
|
|
405
|
+
viewer.setAttribute("url", opt.url || dst);
|
|
197
406
|
viewer.onload = () => {
|
|
198
407
|
return accept(viewer);
|
|
199
408
|
};
|
|
200
409
|
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
201
410
|
shadow.append(viewer);
|
|
202
411
|
this._viewer = viewer;
|
|
412
|
+
this._currentState = EmbedState.QRCode;
|
|
203
413
|
return;
|
|
204
414
|
}
|
|
205
415
|
return reject(new Error("PlattarEmbed.startQRCode() - minimum required attributes not set, use scene-id or product-id as a minimum"));
|
|
206
416
|
});
|
|
207
417
|
}
|
|
418
|
+
/**
|
|
419
|
+
* This is called by the observer if any of the embed attributes have changed
|
|
420
|
+
* based on the state of the embed, we update the internal structure accordingly
|
|
421
|
+
*/
|
|
422
|
+
_OnAttributesUpdated() {
|
|
423
|
+
// nothing to update in these scenarios
|
|
424
|
+
if (this._currentState === EmbedState.None ||
|
|
425
|
+
this._currentState === EmbedState.ProductAR ||
|
|
426
|
+
this._currentState === EmbedState.ConfiguratorViewer) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
// re-render the QR Code when attributes have changed
|
|
430
|
+
if (this._currentState === EmbedState.QRCode) {
|
|
431
|
+
this.startQRCode(this._qrCodeOptions);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
// use the messenger function to change variation when attributes have changed
|
|
435
|
+
if (this._currentState === EmbedState.SceneViewer) {
|
|
436
|
+
const viewer = this.viewer;
|
|
437
|
+
if (viewer) {
|
|
438
|
+
viewer.messenger.selectVariation(this._productID, this._variationID);
|
|
439
|
+
}
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (this._currentState === EmbedState.ProductViewer) {
|
|
443
|
+
const viewer = this.viewer;
|
|
444
|
+
if (viewer) {
|
|
445
|
+
viewer.messenger.selectVariation(this._variationID);
|
|
446
|
+
}
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
208
450
|
}
|
|
209
451
|
exports.default = PlattarEmbed;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ 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.ConfiguratorAR = 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"));
|
|
@@ -34,6 +34,8 @@ var scene_ar_1 = require("./ar/scene-ar");
|
|
|
34
34
|
Object.defineProperty(exports, "SceneAR", { enumerable: true, get: function () { return scene_ar_1.SceneAR; } });
|
|
35
35
|
var model_ar_1 = require("./ar/model-ar");
|
|
36
36
|
Object.defineProperty(exports, "ModelAR", { enumerable: true, get: function () { return model_ar_1.ModelAR; } });
|
|
37
|
+
var raw_ar_1 = require("./ar/raw-ar");
|
|
38
|
+
Object.defineProperty(exports, "RawAR", { enumerable: true, get: function () { return raw_ar_1.RawAR; } });
|
|
37
39
|
var util_1 = require("./util/util");
|
|
38
40
|
Object.defineProperty(exports, "Util", { enumerable: true, get: function () { return util_1.Util; } });
|
|
39
41
|
const plattar_embed_1 = __importDefault(require("./embed/plattar-embed"));
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
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.
|
|
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,14 +40,15 @@
|
|
|
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
|
-
"@babel/cli": "^7.16.
|
|
47
|
-
"@babel/core": "^7.16.
|
|
48
|
-
"@babel/preset-env": "^7.16.
|
|
47
|
+
"@babel/cli": "^7.16.8",
|
|
48
|
+
"@babel/core": "^7.16.12",
|
|
49
|
+
"@babel/preset-env": "^7.16.11",
|
|
49
50
|
"browserify": "^17.0.0",
|
|
50
|
-
"typescript": "^4.5.
|
|
51
|
+
"typescript": "^4.5.5",
|
|
51
52
|
"uglify-es": "^3.3.9"
|
|
52
53
|
},
|
|
53
54
|
"publishConfig": {
|