@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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlattarController = exports.ControllerState = void 0;
|
|
4
4
|
const plattar_api_1 = require("@plattar/plattar-api");
|
|
5
|
+
const configurator_state_1 = require("../../util/configurator-state");
|
|
5
6
|
var ControllerState;
|
|
6
7
|
(function (ControllerState) {
|
|
7
8
|
ControllerState[ControllerState["None"] = 0] = "None";
|
|
@@ -28,25 +29,88 @@ class PlattarController {
|
|
|
28
29
|
this._state = ControllerState.None;
|
|
29
30
|
this._element = null;
|
|
30
31
|
this._prevQROpt = null;
|
|
32
|
+
this._selectVariationObserver = null;
|
|
33
|
+
this._selectVariationSKUObserver = null;
|
|
31
34
|
this._parent = parent;
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
|
-
*
|
|
37
|
+
* Generates a brand new Configurator State from the provided SceneID or inputted Configurator State
|
|
35
38
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
async createConfiguratorState() {
|
|
40
|
+
// get our Scene ID
|
|
41
|
+
const sceneID = this.getAttribute("scene-id");
|
|
42
|
+
if (!sceneID) {
|
|
43
|
+
throw new Error("PlattarController.createConfiguratorState() - cannot create as required attribute scene-id is not defined");
|
|
44
|
+
}
|
|
45
|
+
const configState = this.getAttribute("config-state");
|
|
46
|
+
// get a list of variation ID's to use for initialising
|
|
47
|
+
const variationIDs = this.getAttribute("variation-id");
|
|
48
|
+
// get a list of variation SKU's to use for initialising
|
|
49
|
+
const variationSKUs = this.getAttribute("variation-sku");
|
|
50
|
+
// generate the decoded configurator state
|
|
51
|
+
const decodedState = configState ? await configurator_state_1.ConfiguratorState.decodeState(sceneID, configState) : await configurator_state_1.ConfiguratorState.decodeScene(sceneID);
|
|
52
|
+
// change the ID's and SKU's (if any) of the default configuration state
|
|
53
|
+
const variationIDList = variationIDs ? variationIDs.split(",") : [];
|
|
54
|
+
const variationSKUList = variationSKUs ? variationSKUs.split(",") : [];
|
|
55
|
+
variationIDList.forEach((variationID) => {
|
|
56
|
+
decodedState.state.setVariationID(variationID);
|
|
57
|
+
});
|
|
58
|
+
variationSKUList.forEach((variationSKU) => {
|
|
59
|
+
decodedState.state.setVariationSKU(variationSKU);
|
|
60
|
+
});
|
|
61
|
+
// return fully modified configuration state
|
|
62
|
+
return decodedState;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Setup messenger observers to detect variation changes and apply to the internal
|
|
66
|
+
* configuration state
|
|
67
|
+
*/
|
|
68
|
+
setupMessengerObservers(viewer, configState) {
|
|
69
|
+
this._selectVariationObserver = viewer.messengerInstance.observer.subscribe("selectVariation", (cd) => {
|
|
70
|
+
if (cd.type === "call") {
|
|
71
|
+
const args = cd.data[0];
|
|
72
|
+
const variations = args ? (Array.isArray(args) ? args : [args]) : [];
|
|
73
|
+
variations.forEach((variationID) => {
|
|
74
|
+
configState.state.setVariationID(variationID);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
this._selectVariationSKUObserver = viewer.messengerInstance.observer.subscribe("selectVariationSKU", (cd) => {
|
|
79
|
+
if (cd.type === "call") {
|
|
80
|
+
const args = cd.data[0];
|
|
81
|
+
const variations = args ? (Array.isArray(args) ? args : [args]) : [];
|
|
82
|
+
variations.forEach((variationSKU) => {
|
|
83
|
+
configState.state.setVariationSKU(variationSKU);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
42
86
|
});
|
|
43
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Remove all pre-existing observers
|
|
90
|
+
*/
|
|
91
|
+
removeMessengerObservers() {
|
|
92
|
+
if (this._selectVariationObserver) {
|
|
93
|
+
this._selectVariationObserver();
|
|
94
|
+
this._selectVariationObserver = null;
|
|
95
|
+
}
|
|
96
|
+
if (this._selectVariationSKUObserver) {
|
|
97
|
+
this._selectVariationSKUObserver();
|
|
98
|
+
this._selectVariationSKUObserver = null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Initialise and start AR mode if available
|
|
103
|
+
*/
|
|
104
|
+
async startAR() {
|
|
105
|
+
const launcher = await this.initAR();
|
|
106
|
+
return launcher.start();
|
|
107
|
+
}
|
|
44
108
|
/**
|
|
45
109
|
* Decide which QR Code to render according to the qr-type attribute
|
|
46
110
|
* @param options
|
|
47
111
|
* @returns
|
|
48
112
|
*/
|
|
49
|
-
startQRCode(options) {
|
|
113
|
+
async startQRCode(options) {
|
|
50
114
|
const qrType = this.getAttribute("qr-type") || "viewer";
|
|
51
115
|
switch (qrType.toLowerCase()) {
|
|
52
116
|
case "ar":
|
|
@@ -61,69 +125,76 @@ class PlattarController {
|
|
|
61
125
|
* @param options
|
|
62
126
|
* @returns
|
|
63
127
|
*/
|
|
64
|
-
startARQRCode(options) {
|
|
128
|
+
async startARQRCode(options) {
|
|
129
|
+
// remove the old renderer instance if any
|
|
130
|
+
this.removeRenderer();
|
|
131
|
+
const opt = options || this._GetDefaultQROptions();
|
|
132
|
+
const viewer = document.createElement("plattar-qrcode");
|
|
133
|
+
this._element = viewer;
|
|
134
|
+
// required attributes with defaults for plattar-viewer node
|
|
135
|
+
const width = this.getAttribute("width") || "500px";
|
|
136
|
+
const height = this.getAttribute("height") || "500px";
|
|
137
|
+
viewer.setAttribute("width", width);
|
|
138
|
+
viewer.setAttribute("height", height);
|
|
139
|
+
if (opt.color) {
|
|
140
|
+
viewer.setAttribute("color", opt.color);
|
|
141
|
+
}
|
|
142
|
+
if (opt.margin) {
|
|
143
|
+
viewer.setAttribute("margin", "" + opt.margin);
|
|
144
|
+
}
|
|
145
|
+
if (opt.qrType) {
|
|
146
|
+
viewer.setAttribute("qr-type", opt.qrType);
|
|
147
|
+
}
|
|
148
|
+
viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
|
|
149
|
+
const qrOptions = btoa(JSON.stringify(opt));
|
|
150
|
+
let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
|
|
151
|
+
let configState = null;
|
|
152
|
+
const sceneID = this.getAttribute("scene-id");
|
|
153
|
+
const embedType = this.getAttribute("embed-type");
|
|
154
|
+
const productID = this.getAttribute("product-id");
|
|
155
|
+
const sceneProductID = this.getAttribute("scene-product-id");
|
|
156
|
+
const variationID = this.getAttribute("variation-id");
|
|
157
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
158
|
+
const arMode = this.getAttribute("ar-mode");
|
|
159
|
+
try {
|
|
160
|
+
configState = (await this.getConfiguratorState()).state.encode();
|
|
161
|
+
}
|
|
162
|
+
catch (_err) {
|
|
163
|
+
// config state not available for some reason
|
|
164
|
+
configState = null;
|
|
165
|
+
}
|
|
166
|
+
if (configState) {
|
|
167
|
+
dst += "&config_state=" + configState;
|
|
168
|
+
}
|
|
169
|
+
if (embedType) {
|
|
170
|
+
dst += "&embed_type=" + embedType;
|
|
171
|
+
}
|
|
172
|
+
if (productID) {
|
|
173
|
+
dst += "&product_id=" + productID;
|
|
174
|
+
}
|
|
175
|
+
if (sceneProductID) {
|
|
176
|
+
dst += "&scene_product_id=" + sceneProductID;
|
|
177
|
+
}
|
|
178
|
+
if (variationID) {
|
|
179
|
+
dst += "&variation_id=" + variationID;
|
|
180
|
+
}
|
|
181
|
+
if (variationSKU) {
|
|
182
|
+
dst += "&variation_sku=" + variationSKU;
|
|
183
|
+
}
|
|
184
|
+
if (arMode) {
|
|
185
|
+
dst += "&ar_mode=" + arMode;
|
|
186
|
+
}
|
|
187
|
+
if (sceneID) {
|
|
188
|
+
dst += "&scene_id=" + sceneID;
|
|
189
|
+
}
|
|
190
|
+
viewer.setAttribute("url", opt.url || dst);
|
|
191
|
+
this._state = ControllerState.QRCode;
|
|
192
|
+
this._prevQROpt = opt;
|
|
65
193
|
return new Promise((accept, reject) => {
|
|
66
|
-
|
|
67
|
-
this.removeRenderer();
|
|
68
|
-
const opt = options || this._GetDefaultQROptions();
|
|
69
|
-
const viewer = document.createElement("plattar-qrcode");
|
|
70
|
-
// required attributes with defaults for plattar-viewer node
|
|
71
|
-
const width = this.getAttribute("width") || "500px";
|
|
72
|
-
const height = this.getAttribute("height") || "500px";
|
|
73
|
-
viewer.setAttribute("width", width);
|
|
74
|
-
viewer.setAttribute("height", height);
|
|
75
|
-
if (opt.color) {
|
|
76
|
-
viewer.setAttribute("color", opt.color);
|
|
77
|
-
}
|
|
78
|
-
if (opt.margin) {
|
|
79
|
-
viewer.setAttribute("margin", "" + opt.margin);
|
|
80
|
-
}
|
|
81
|
-
if (opt.qrType) {
|
|
82
|
-
viewer.setAttribute("qr-type", opt.qrType);
|
|
83
|
-
}
|
|
84
|
-
viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
|
|
85
|
-
const qrOptions = btoa(JSON.stringify(opt));
|
|
86
|
-
let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
|
|
87
|
-
const sceneID = this.getAttribute("scene-id");
|
|
88
|
-
const configState = this.getAttribute("config-state");
|
|
89
|
-
const embedType = this.getAttribute("embed-type");
|
|
90
|
-
const productID = this.getAttribute("product-id");
|
|
91
|
-
const sceneProductID = this.getAttribute("scene-product-id");
|
|
92
|
-
const variationID = this.getAttribute("variation-id");
|
|
93
|
-
const variationSKU = this.getAttribute("variation-sku");
|
|
94
|
-
const arMode = this.getAttribute("ar-mode");
|
|
95
|
-
if (configState) {
|
|
96
|
-
dst += "&config_state=" + configState;
|
|
97
|
-
}
|
|
98
|
-
if (embedType) {
|
|
99
|
-
dst += "&embed_type=" + embedType;
|
|
100
|
-
}
|
|
101
|
-
if (productID) {
|
|
102
|
-
dst += "&product_id=" + productID;
|
|
103
|
-
}
|
|
104
|
-
if (sceneProductID) {
|
|
105
|
-
dst += "&scene_product_id=" + sceneProductID;
|
|
106
|
-
}
|
|
107
|
-
if (variationID) {
|
|
108
|
-
dst += "&variation_id=" + variationID;
|
|
109
|
-
}
|
|
110
|
-
if (variationSKU) {
|
|
111
|
-
dst += "&variation_sku=" + variationSKU;
|
|
112
|
-
}
|
|
113
|
-
if (arMode) {
|
|
114
|
-
dst += "&ar_mode=" + arMode;
|
|
115
|
-
}
|
|
116
|
-
if (sceneID) {
|
|
117
|
-
dst += "&scene_id=" + sceneID;
|
|
118
|
-
}
|
|
119
|
-
viewer.setAttribute("url", opt.url || dst);
|
|
194
|
+
this.append(viewer);
|
|
120
195
|
viewer.onload = () => {
|
|
121
196
|
return accept(viewer);
|
|
122
197
|
};
|
|
123
|
-
this._element = viewer;
|
|
124
|
-
this._state = ControllerState.QRCode;
|
|
125
|
-
this._prevQROpt = opt;
|
|
126
|
-
this.append(viewer);
|
|
127
198
|
});
|
|
128
199
|
}
|
|
129
200
|
/**
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { LauncherAR } from "../../ar/launcher-ar";
|
|
2
2
|
import { PlattarController } from "./plattar-controller";
|
|
3
|
+
import { DecodedConfiguratorState } from "../../util/configurator-state";
|
|
3
4
|
/**
|
|
4
5
|
* Manages an instance of the <plattar-product> HTML Element
|
|
6
|
+
*
|
|
7
|
+
* NOTE: As of 14th June 2023, this is now a legacy Controller and only used in legacy embeds
|
|
8
|
+
* and should be deprecated from both documentation and previous integrations
|
|
5
9
|
*/
|
|
6
10
|
export declare class ProductController extends PlattarController {
|
|
11
|
+
getConfiguratorState(): Promise<DecodedConfiguratorState>;
|
|
7
12
|
constructor(parent: HTMLElement);
|
|
8
|
-
onAttributesUpdated(): void
|
|
13
|
+
onAttributesUpdated(attributeName: string): Promise<void>;
|
|
9
14
|
startViewerQRCode(options: any): Promise<HTMLElement>;
|
|
15
|
+
/**
|
|
16
|
+
* Displays a QR Code that sends the user direct to AR
|
|
17
|
+
* @param options
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
startARQRCode(options: any): Promise<HTMLElement>;
|
|
10
21
|
startRenderer(): Promise<HTMLElement>;
|
|
11
22
|
initAR(): Promise<LauncherAR>;
|
|
12
23
|
removeRenderer(): boolean;
|
|
@@ -7,12 +7,20 @@ const util_1 = require("../../util/util");
|
|
|
7
7
|
const plattar_controller_1 = require("./plattar-controller");
|
|
8
8
|
/**
|
|
9
9
|
* Manages an instance of the <plattar-product> HTML Element
|
|
10
|
+
*
|
|
11
|
+
* NOTE: As of 14th June 2023, this is now a legacy Controller and only used in legacy embeds
|
|
12
|
+
* and should be deprecated from both documentation and previous integrations
|
|
10
13
|
*/
|
|
11
14
|
class ProductController extends plattar_controller_1.PlattarController {
|
|
15
|
+
async getConfiguratorState() {
|
|
16
|
+
throw new Error("ProductController.getConfiguratorState() - legacy embeds do not support configurator states");
|
|
17
|
+
}
|
|
12
18
|
constructor(parent) {
|
|
19
|
+
// this is a hack against DecodedConfiguratorState that's now stored in PlattarController
|
|
20
|
+
// this is not used in legacy mode
|
|
13
21
|
super(parent);
|
|
14
22
|
}
|
|
15
|
-
onAttributesUpdated() {
|
|
23
|
+
async onAttributesUpdated(attributeName) {
|
|
16
24
|
const state = this._state;
|
|
17
25
|
// re-render the QR Code when attributes have changed
|
|
18
26
|
if (state === plattar_controller_1.ControllerState.QRCode) {
|
|
@@ -28,7 +36,6 @@ class ProductController extends plattar_controller_1.PlattarController {
|
|
|
28
36
|
viewer.messenger.selectVariation(variationID);
|
|
29
37
|
}
|
|
30
38
|
}
|
|
31
|
-
return;
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
41
|
startViewerQRCode(options) {
|
|
@@ -81,6 +88,76 @@ class ProductController extends plattar_controller_1.PlattarController {
|
|
|
81
88
|
return reject(new Error("ProductController.startQRCode() - minimum required attributes not set, use product-id as a minimum"));
|
|
82
89
|
});
|
|
83
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Displays a QR Code that sends the user direct to AR
|
|
93
|
+
* @param options
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
startARQRCode(options) {
|
|
97
|
+
return new Promise((accept, reject) => {
|
|
98
|
+
// remove the old renderer instance if any
|
|
99
|
+
this.removeRenderer();
|
|
100
|
+
const opt = options || this._GetDefaultQROptions();
|
|
101
|
+
const viewer = document.createElement("plattar-qrcode");
|
|
102
|
+
// required attributes with defaults for plattar-viewer node
|
|
103
|
+
const width = this.getAttribute("width") || "500px";
|
|
104
|
+
const height = this.getAttribute("height") || "500px";
|
|
105
|
+
viewer.setAttribute("width", width);
|
|
106
|
+
viewer.setAttribute("height", height);
|
|
107
|
+
if (opt.color) {
|
|
108
|
+
viewer.setAttribute("color", opt.color);
|
|
109
|
+
}
|
|
110
|
+
if (opt.margin) {
|
|
111
|
+
viewer.setAttribute("margin", "" + opt.margin);
|
|
112
|
+
}
|
|
113
|
+
if (opt.qrType) {
|
|
114
|
+
viewer.setAttribute("qr-type", opt.qrType);
|
|
115
|
+
}
|
|
116
|
+
viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
|
|
117
|
+
const qrOptions = btoa(JSON.stringify(opt));
|
|
118
|
+
let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
|
|
119
|
+
const sceneID = this.getAttribute("scene-id");
|
|
120
|
+
const configState = this.getAttribute("config-state");
|
|
121
|
+
const embedType = this.getAttribute("embed-type");
|
|
122
|
+
const productID = this.getAttribute("product-id");
|
|
123
|
+
const sceneProductID = this.getAttribute("scene-product-id");
|
|
124
|
+
const variationID = this.getAttribute("variation-id");
|
|
125
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
126
|
+
const arMode = this.getAttribute("ar-mode");
|
|
127
|
+
if (configState) {
|
|
128
|
+
dst += "&config_state=" + configState;
|
|
129
|
+
}
|
|
130
|
+
if (embedType) {
|
|
131
|
+
dst += "&embed_type=" + embedType;
|
|
132
|
+
}
|
|
133
|
+
if (productID) {
|
|
134
|
+
dst += "&product_id=" + productID;
|
|
135
|
+
}
|
|
136
|
+
if (sceneProductID) {
|
|
137
|
+
dst += "&scene_product_id=" + sceneProductID;
|
|
138
|
+
}
|
|
139
|
+
if (variationID) {
|
|
140
|
+
dst += "&variation_id=" + variationID;
|
|
141
|
+
}
|
|
142
|
+
if (variationSKU) {
|
|
143
|
+
dst += "&variation_sku=" + variationSKU;
|
|
144
|
+
}
|
|
145
|
+
if (arMode) {
|
|
146
|
+
dst += "&ar_mode=" + arMode;
|
|
147
|
+
}
|
|
148
|
+
if (sceneID) {
|
|
149
|
+
dst += "&scene_id=" + sceneID;
|
|
150
|
+
}
|
|
151
|
+
viewer.setAttribute("url", opt.url || dst);
|
|
152
|
+
viewer.onload = () => {
|
|
153
|
+
return accept(viewer);
|
|
154
|
+
};
|
|
155
|
+
this._element = viewer;
|
|
156
|
+
this._state = plattar_controller_1.ControllerState.QRCode;
|
|
157
|
+
this._prevQROpt = opt;
|
|
158
|
+
this.append(viewer);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
84
161
|
startRenderer() {
|
|
85
162
|
return new Promise((accept, reject) => {
|
|
86
163
|
// remove the old renderer instance if any
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { LauncherAR } from "../../ar/launcher-ar";
|
|
2
|
+
import { DecodedConfiguratorState } from "../../util/configurator-state";
|
|
2
3
|
import { PlattarController } from "./plattar-controller";
|
|
3
4
|
/**
|
|
4
5
|
* Manages an instance of the <plattar-configurator> HTML Element
|
|
5
6
|
*/
|
|
6
7
|
export declare class VTOController extends PlattarController {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
private _cachedConfigState;
|
|
9
|
+
getConfiguratorState(): Promise<DecodedConfiguratorState>;
|
|
10
|
+
onAttributesUpdated(attributeName: string): Promise<void>;
|
|
9
11
|
startViewerQRCode(options: any): Promise<HTMLElement>;
|
|
10
12
|
startRenderer(): Promise<HTMLElement>;
|
|
11
13
|
initAR(): Promise<LauncherAR>;
|