@plattar/plattar-ar-adapter 1.122.1 → 1.123.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.
- package/build/es2015/plattar-ar-adapter.js +8328 -5558
- package/build/es2015/plattar-ar-adapter.min.js +1 -1
- package/build/es2019/plattar-ar-adapter.js +1280 -289
- 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/controllers/configurator-controller.d.ts +18 -0
- package/dist/embed/controllers/configurator-controller.js +186 -0
- package/dist/embed/controllers/plattar-controller.d.ts +62 -0
- package/dist/embed/controllers/plattar-controller.js +51 -0
- package/dist/embed/controllers/product-controller.d.ts +18 -0
- package/dist/embed/controllers/product-controller.js +141 -0
- package/dist/embed/controllers/viewer-controller.d.ts +18 -0
- package/dist/embed/controllers/viewer-controller.js +155 -0
- package/dist/embed/plattar-embed.d.ts +7 -8
- package/dist/embed/plattar-embed.js +72 -156
- 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 +8 -7
|
@@ -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;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LauncherAR } from "../../ar/launcher-ar";
|
|
2
|
+
import { PlattarController } from "./plattar-controller";
|
|
3
|
+
/**
|
|
4
|
+
* Manages an instance of the <plattar-configurator> HTML Element
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConfiguratorController extends PlattarController {
|
|
7
|
+
private _state;
|
|
8
|
+
private _element;
|
|
9
|
+
private _prevQROpt;
|
|
10
|
+
constructor(parent: HTMLElement);
|
|
11
|
+
onAttributesUpdated(): void;
|
|
12
|
+
startQRCode(options: any): Promise<HTMLElement>;
|
|
13
|
+
startRenderer(): Promise<HTMLElement>;
|
|
14
|
+
startAR(): Promise<void>;
|
|
15
|
+
initAR(): Promise<LauncherAR>;
|
|
16
|
+
removeRenderer(): boolean;
|
|
17
|
+
get element(): HTMLElement | null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfiguratorController = void 0;
|
|
4
|
+
const plattar_api_1 = require("@plattar/plattar-api");
|
|
5
|
+
const plattar_services_1 = require("@plattar/plattar-services");
|
|
6
|
+
const raw_ar_1 = require("../../ar/raw-ar");
|
|
7
|
+
const util_1 = require("../../util/util");
|
|
8
|
+
const plattar_controller_1 = require("./plattar-controller");
|
|
9
|
+
/**
|
|
10
|
+
* Manages an instance of the <plattar-configurator> HTML Element
|
|
11
|
+
*/
|
|
12
|
+
class ConfiguratorController extends plattar_controller_1.PlattarController {
|
|
13
|
+
constructor(parent) {
|
|
14
|
+
super(parent);
|
|
15
|
+
this._state = plattar_controller_1.ControllerState.None;
|
|
16
|
+
this._element = null;
|
|
17
|
+
this._prevQROpt = null;
|
|
18
|
+
}
|
|
19
|
+
onAttributesUpdated() {
|
|
20
|
+
const state = this._state;
|
|
21
|
+
// re-render the QR Code when attributes have changed
|
|
22
|
+
if (state === plattar_controller_1.ControllerState.QRCode) {
|
|
23
|
+
this.startQRCode(this._prevQROpt);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
startQRCode(options) {
|
|
28
|
+
return new Promise((accept, reject) => {
|
|
29
|
+
// remove the old renderer instance if any
|
|
30
|
+
this.removeRenderer();
|
|
31
|
+
const sceneID = this.getAttribute("scene-id");
|
|
32
|
+
if (sceneID) {
|
|
33
|
+
const opt = options || plattar_controller_1.PlattarController.DEFAULT_QR_OPTIONS;
|
|
34
|
+
const viewer = document.createElement("plattar-qrcode");
|
|
35
|
+
// required attributes with defaults for plattar-viewer node
|
|
36
|
+
const width = this.getAttribute("width") || "500px";
|
|
37
|
+
const height = this.getAttribute("height") || "500px";
|
|
38
|
+
viewer.setAttribute("width", width);
|
|
39
|
+
viewer.setAttribute("height", height);
|
|
40
|
+
if (opt.color) {
|
|
41
|
+
viewer.setAttribute("color", opt.color);
|
|
42
|
+
}
|
|
43
|
+
if (opt.margin) {
|
|
44
|
+
viewer.setAttribute("margin", "" + opt.margin);
|
|
45
|
+
}
|
|
46
|
+
if (opt.qrType) {
|
|
47
|
+
viewer.setAttribute("qr-type", opt.qrType);
|
|
48
|
+
}
|
|
49
|
+
let dst = plattar_api_1.Server.location().base + "renderer/configurator.html?scene_id=" + sceneID;
|
|
50
|
+
// optional attributes
|
|
51
|
+
const configState = this.getAttribute("config-state");
|
|
52
|
+
const showAR = this.getAttribute("show-ar");
|
|
53
|
+
if (configState) {
|
|
54
|
+
dst += "&config_state=" + configState;
|
|
55
|
+
}
|
|
56
|
+
if (showAR) {
|
|
57
|
+
dst += "&show_ar=" + showAR;
|
|
58
|
+
}
|
|
59
|
+
viewer.setAttribute("url", opt.url || dst);
|
|
60
|
+
viewer.onload = () => {
|
|
61
|
+
return accept(viewer);
|
|
62
|
+
};
|
|
63
|
+
this.append(viewer);
|
|
64
|
+
this._element = viewer;
|
|
65
|
+
this._state = plattar_controller_1.ControllerState.QRCode;
|
|
66
|
+
this._prevQROpt = opt;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
return reject(new Error("ConfiguratorController.startQRCode() - minimum required attributes not set, use scene-id as a minimum"));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
startRenderer() {
|
|
73
|
+
return new Promise((accept, reject) => {
|
|
74
|
+
// remove the old renderer instance if any
|
|
75
|
+
this.removeRenderer();
|
|
76
|
+
const sceneID = this.getAttribute("scene-id");
|
|
77
|
+
if (sceneID) {
|
|
78
|
+
// required attributes with defaults for plattar-configurator node
|
|
79
|
+
const width = this.getAttribute("width") || "500px";
|
|
80
|
+
const height = this.getAttribute("height") || "500px";
|
|
81
|
+
const server = this.getAttribute("server") || "production";
|
|
82
|
+
const viewer = document.createElement("plattar-configurator");
|
|
83
|
+
viewer.setAttribute("width", width);
|
|
84
|
+
viewer.setAttribute("height", height);
|
|
85
|
+
viewer.setAttribute("server", server);
|
|
86
|
+
viewer.setAttribute("scene-id", sceneID);
|
|
87
|
+
// optional attributes
|
|
88
|
+
const configState = this.getAttribute("config-state");
|
|
89
|
+
const showAR = this.getAttribute("show-ar");
|
|
90
|
+
if (configState) {
|
|
91
|
+
viewer.setAttribute("config-state", configState);
|
|
92
|
+
}
|
|
93
|
+
if (showAR) {
|
|
94
|
+
viewer.setAttribute("show-ar", showAR);
|
|
95
|
+
}
|
|
96
|
+
viewer.onload = () => {
|
|
97
|
+
return accept(viewer);
|
|
98
|
+
};
|
|
99
|
+
this.append(viewer);
|
|
100
|
+
this._element = viewer;
|
|
101
|
+
this._state = plattar_controller_1.ControllerState.Renderer;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
return reject(new Error("ConfiguratorController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
startAR() {
|
|
108
|
+
return new Promise((accept, reject) => {
|
|
109
|
+
this.initAR().then((launcher) => {
|
|
110
|
+
launcher.start();
|
|
111
|
+
accept();
|
|
112
|
+
}).catch(reject);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
initAR() {
|
|
116
|
+
return new Promise((accept, reject) => {
|
|
117
|
+
if (!util_1.Util.canAugment()) {
|
|
118
|
+
return reject(new Error("ConfiguratorController.initAR() - cannot proceed as AR not available in context"));
|
|
119
|
+
}
|
|
120
|
+
// if scene ID is available and the state is a configurator viewer
|
|
121
|
+
// we can use the real-time configurator state to launch the AR view
|
|
122
|
+
const viewer = this.element;
|
|
123
|
+
const sceneID = this.getAttribute("scene-id");
|
|
124
|
+
if (viewer && sceneID) {
|
|
125
|
+
let output = "glb";
|
|
126
|
+
if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
|
|
127
|
+
output = "usdz";
|
|
128
|
+
}
|
|
129
|
+
return viewer.messenger.getARFile(output).then((result) => {
|
|
130
|
+
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
131
|
+
return rawAR.init().then(accept).catch(reject);
|
|
132
|
+
}).catch(reject);
|
|
133
|
+
}
|
|
134
|
+
const configState = this.getAttribute("config-state");
|
|
135
|
+
// otherwise scene ID is available to the viewer is not launched
|
|
136
|
+
// we can use the static configuration state to launch the AR view
|
|
137
|
+
if (sceneID && configState) {
|
|
138
|
+
try {
|
|
139
|
+
const decodedb64State = atob(configState);
|
|
140
|
+
const state = JSON.parse(decodedb64State);
|
|
141
|
+
if (state.meta) {
|
|
142
|
+
const sceneProductIndex = state.meta.scene_product_index || 0;
|
|
143
|
+
const variationIndex = state.meta.product_variation_index || 1;
|
|
144
|
+
const states = state.states || [];
|
|
145
|
+
if (states.length > 0) {
|
|
146
|
+
const configurator = new plattar_services_1.Configurator();
|
|
147
|
+
states.forEach((productState) => {
|
|
148
|
+
configurator.addSceneProduct(productState[sceneProductIndex], productState[variationIndex]);
|
|
149
|
+
});
|
|
150
|
+
if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
|
|
151
|
+
configurator.output = "usdz";
|
|
152
|
+
}
|
|
153
|
+
if (util_1.Util.canSceneViewer()) {
|
|
154
|
+
configurator.output = "glb";
|
|
155
|
+
}
|
|
156
|
+
const server = this.getAttribute("server") || "production";
|
|
157
|
+
configurator.server = server;
|
|
158
|
+
return configurator.get().then((result) => {
|
|
159
|
+
const rawAR = new raw_ar_1.RawAR(result.filename);
|
|
160
|
+
rawAR.init().then(accept).catch(reject);
|
|
161
|
+
}).catch(reject);
|
|
162
|
+
}
|
|
163
|
+
return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
|
|
164
|
+
}
|
|
165
|
+
return reject(new Error("ConfiguratorController.initAR() - invalid config-state for configurator"));
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
return reject(err);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
removeRenderer() {
|
|
175
|
+
if (this._element) {
|
|
176
|
+
this._element.remove();
|
|
177
|
+
this._element = null;
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
get element() {
|
|
183
|
+
return this._element;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.ConfiguratorController = ConfiguratorController;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LauncherAR } from "../../ar/launcher-ar";
|
|
2
|
+
export declare enum ControllerState {
|
|
3
|
+
None = 0,
|
|
4
|
+
Renderer = 1,
|
|
5
|
+
QRCode = 2
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* All Plattar Controllers are derived from the same interface
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class PlattarController {
|
|
11
|
+
/**
|
|
12
|
+
* Default QR Code rendering options
|
|
13
|
+
*/
|
|
14
|
+
static get DEFAULT_QR_OPTIONS(): any;
|
|
15
|
+
private readonly _parent;
|
|
16
|
+
constructor(parent: HTMLElement);
|
|
17
|
+
/**
|
|
18
|
+
* Called by the parent when a HTML Attribute has changed and the controller
|
|
19
|
+
* requires an update
|
|
20
|
+
*/
|
|
21
|
+
abstract onAttributesUpdated(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Start Rendering a QR Code with the provided options
|
|
24
|
+
* @param options (optional) - The QR Code Options
|
|
25
|
+
*/
|
|
26
|
+
abstract startQRCode(options: any | undefined | null): Promise<HTMLElement>;
|
|
27
|
+
/**
|
|
28
|
+
* Start the underlying Plattar Renderer for this Controller
|
|
29
|
+
*/
|
|
30
|
+
abstract startRenderer(): Promise<HTMLElement>;
|
|
31
|
+
/**
|
|
32
|
+
* Initialise and start AR mode if available
|
|
33
|
+
*/
|
|
34
|
+
abstract startAR(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Initialise and return a launcher that can be used to start AR
|
|
37
|
+
*/
|
|
38
|
+
abstract initAR(): Promise<LauncherAR>;
|
|
39
|
+
/**
|
|
40
|
+
* Removes the currently active renderer view from the DOM
|
|
41
|
+
*/
|
|
42
|
+
abstract removeRenderer(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get the underlying renderer component (if any)
|
|
45
|
+
*/
|
|
46
|
+
abstract get element(): HTMLElement | null;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the Parent Instance
|
|
49
|
+
*/
|
|
50
|
+
get parent(): HTMLElement;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the specified attribute from the parent
|
|
53
|
+
* @param attribute - The name of thhe attribute
|
|
54
|
+
* @returns - The attribute value or null
|
|
55
|
+
*/
|
|
56
|
+
getAttribute(attribute: string): string | null;
|
|
57
|
+
/**
|
|
58
|
+
* Appends the provided element into the shadow-root of the parent element
|
|
59
|
+
* @param element - The element to append
|
|
60
|
+
*/
|
|
61
|
+
append(element: HTMLElement): void;
|
|
62
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlattarController = exports.ControllerState = void 0;
|
|
4
|
+
var ControllerState;
|
|
5
|
+
(function (ControllerState) {
|
|
6
|
+
ControllerState[ControllerState["None"] = 0] = "None";
|
|
7
|
+
ControllerState[ControllerState["Renderer"] = 1] = "Renderer";
|
|
8
|
+
ControllerState[ControllerState["QRCode"] = 2] = "QRCode";
|
|
9
|
+
})(ControllerState = exports.ControllerState || (exports.ControllerState = {}));
|
|
10
|
+
/**
|
|
11
|
+
* All Plattar Controllers are derived from the same interface
|
|
12
|
+
*/
|
|
13
|
+
class PlattarController {
|
|
14
|
+
constructor(parent) {
|
|
15
|
+
this._parent = parent;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Default QR Code rendering options
|
|
19
|
+
*/
|
|
20
|
+
static get DEFAULT_QR_OPTIONS() {
|
|
21
|
+
return {
|
|
22
|
+
color: "#101721",
|
|
23
|
+
qrType: "default",
|
|
24
|
+
margin: 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the Parent Instance
|
|
30
|
+
*/
|
|
31
|
+
get parent() {
|
|
32
|
+
return this._parent;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns the specified attribute from the parent
|
|
36
|
+
* @param attribute - The name of thhe attribute
|
|
37
|
+
* @returns - The attribute value or null
|
|
38
|
+
*/
|
|
39
|
+
getAttribute(attribute) {
|
|
40
|
+
return this.parent ? (this.parent.hasAttribute(attribute) ? this.parent.getAttribute(attribute) : null) : null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Appends the provided element into the shadow-root of the parent element
|
|
44
|
+
* @param element - The element to append
|
|
45
|
+
*/
|
|
46
|
+
append(element) {
|
|
47
|
+
const shadow = this.parent.shadowRoot || this.parent.attachShadow({ mode: 'open' });
|
|
48
|
+
shadow.append(element);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.PlattarController = PlattarController;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LauncherAR } from "../../ar/launcher-ar";
|
|
2
|
+
import { PlattarController } from "./plattar-controller";
|
|
3
|
+
/**
|
|
4
|
+
* Manages an instance of the <plattar-product> HTML Element
|
|
5
|
+
*/
|
|
6
|
+
export declare class ProductController extends PlattarController {
|
|
7
|
+
private _state;
|
|
8
|
+
private _element;
|
|
9
|
+
private _prevQROpt;
|
|
10
|
+
constructor(parent: HTMLElement);
|
|
11
|
+
onAttributesUpdated(): void;
|
|
12
|
+
startQRCode(options: any): Promise<HTMLElement>;
|
|
13
|
+
startRenderer(): Promise<HTMLElement>;
|
|
14
|
+
startAR(): Promise<void>;
|
|
15
|
+
initAR(): Promise<LauncherAR>;
|
|
16
|
+
removeRenderer(): boolean;
|
|
17
|
+
get element(): HTMLElement | null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductController = void 0;
|
|
4
|
+
const plattar_api_1 = require("@plattar/plattar-api");
|
|
5
|
+
const product_ar_1 = require("../../ar/product-ar");
|
|
6
|
+
const util_1 = require("../../util/util");
|
|
7
|
+
const plattar_controller_1 = require("./plattar-controller");
|
|
8
|
+
/**
|
|
9
|
+
* Manages an instance of the <plattar-product> HTML Element
|
|
10
|
+
*/
|
|
11
|
+
class ProductController extends plattar_controller_1.PlattarController {
|
|
12
|
+
constructor(parent) {
|
|
13
|
+
super(parent);
|
|
14
|
+
this._state = plattar_controller_1.ControllerState.None;
|
|
15
|
+
this._element = null;
|
|
16
|
+
this._prevQROpt = null;
|
|
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 variationID = this.getAttribute("variation-id");
|
|
30
|
+
viewer.messenger.selectVariation(variationID);
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
startQRCode(options) {
|
|
36
|
+
return new Promise((accept, reject) => {
|
|
37
|
+
// remove the old renderer instance if any
|
|
38
|
+
this.removeRenderer();
|
|
39
|
+
const productID = this.getAttribute("product-id");
|
|
40
|
+
if (productID) {
|
|
41
|
+
const opt = options || plattar_controller_1.PlattarController.DEFAULT_QR_OPTIONS;
|
|
42
|
+
const viewer = document.createElement("plattar-qrcode");
|
|
43
|
+
// required attributes with defaults for plattar-viewer node
|
|
44
|
+
const width = this.getAttribute("width") || "500px";
|
|
45
|
+
const height = this.getAttribute("height") || "500px";
|
|
46
|
+
viewer.setAttribute("width", width);
|
|
47
|
+
viewer.setAttribute("height", height);
|
|
48
|
+
if (opt.color) {
|
|
49
|
+
viewer.setAttribute("color", opt.color);
|
|
50
|
+
}
|
|
51
|
+
if (opt.margin) {
|
|
52
|
+
viewer.setAttribute("margin", "" + opt.margin);
|
|
53
|
+
}
|
|
54
|
+
if (opt.qrType) {
|
|
55
|
+
viewer.setAttribute("qr-type", opt.qrType);
|
|
56
|
+
}
|
|
57
|
+
// optional attributes
|
|
58
|
+
const variationID = this.getAttribute("variation-id");
|
|
59
|
+
let dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
|
|
60
|
+
if (variationID) {
|
|
61
|
+
dst += "&variation_id=" + variationID;
|
|
62
|
+
}
|
|
63
|
+
viewer.setAttribute("url", opt.url || dst);
|
|
64
|
+
viewer.onload = () => {
|
|
65
|
+
return accept(viewer);
|
|
66
|
+
};
|
|
67
|
+
this.append(viewer);
|
|
68
|
+
this._element = viewer;
|
|
69
|
+
this._state = plattar_controller_1.ControllerState.QRCode;
|
|
70
|
+
this._prevQROpt = opt;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
return reject(new Error("ProductController.startQRCode() - minimum required attributes not set, use product-id as a minimum"));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
startRenderer() {
|
|
77
|
+
return new Promise((accept, reject) => {
|
|
78
|
+
// remove the old renderer instance if any
|
|
79
|
+
this.removeRenderer();
|
|
80
|
+
const productID = this.getAttribute("product-id");
|
|
81
|
+
if (productID) {
|
|
82
|
+
// required attributes with defaults for plattar-product node
|
|
83
|
+
const width = this.getAttribute("width") || "500px";
|
|
84
|
+
const height = this.getAttribute("height") || "500px";
|
|
85
|
+
const server = this.getAttribute("server") || "production";
|
|
86
|
+
const viewer = document.createElement("plattar-product");
|
|
87
|
+
viewer.setAttribute("width", width);
|
|
88
|
+
viewer.setAttribute("height", height);
|
|
89
|
+
viewer.setAttribute("server", server);
|
|
90
|
+
viewer.setAttribute("product-id", productID);
|
|
91
|
+
// optional attributes
|
|
92
|
+
const variationID = this.getAttribute("variation-id");
|
|
93
|
+
if (variationID) {
|
|
94
|
+
viewer.setAttribute("variation-id", variationID);
|
|
95
|
+
}
|
|
96
|
+
viewer.onload = () => {
|
|
97
|
+
return accept(viewer);
|
|
98
|
+
};
|
|
99
|
+
this.append(viewer);
|
|
100
|
+
this._element = viewer;
|
|
101
|
+
this._state = plattar_controller_1.ControllerState.Renderer;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
return reject(new Error("ProductController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
startAR() {
|
|
108
|
+
return new Promise((accept, reject) => {
|
|
109
|
+
this.initAR().then((launcher) => {
|
|
110
|
+
launcher.start();
|
|
111
|
+
accept();
|
|
112
|
+
}).catch(reject);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
initAR() {
|
|
116
|
+
return new Promise((accept, reject) => {
|
|
117
|
+
if (!util_1.Util.canAugment()) {
|
|
118
|
+
return reject(new Error("ProductController.initAR() - cannot proceed as AR not available in context"));
|
|
119
|
+
}
|
|
120
|
+
const productID = this.getAttribute("product-id");
|
|
121
|
+
if (productID) {
|
|
122
|
+
const variationID = this.getAttribute("variation-id");
|
|
123
|
+
const product = new product_ar_1.ProductAR(productID, variationID);
|
|
124
|
+
return product.init().then(accept).catch(reject);
|
|
125
|
+
}
|
|
126
|
+
return reject(new Error("ProductController.initAR() - minimum required attributes not set, use product-id as a minimum"));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
removeRenderer() {
|
|
130
|
+
if (this._element) {
|
|
131
|
+
this._element.remove();
|
|
132
|
+
this._element = null;
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
get element() {
|
|
138
|
+
return this._element;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.ProductController = ProductController;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
private _state;
|
|
8
|
+
private _element;
|
|
9
|
+
private _prevQROpt;
|
|
10
|
+
constructor(parent: HTMLElement);
|
|
11
|
+
onAttributesUpdated(): void;
|
|
12
|
+
startQRCode(options: any): Promise<HTMLElement>;
|
|
13
|
+
startRenderer(): Promise<HTMLElement>;
|
|
14
|
+
startAR(): Promise<void>;
|
|
15
|
+
initAR(): Promise<LauncherAR>;
|
|
16
|
+
removeRenderer(): boolean;
|
|
17
|
+
get element(): HTMLElement | null;
|
|
18
|
+
}
|