@plattar/plattar-ar-adapter 1.130.1 → 1.131.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 +145 -47
- package/build/es2015/plattar-ar-adapter.min.js +1 -1
- package/build/es2019/plattar-ar-adapter.js +112 -55
- package/build/es2019/plattar-ar-adapter.min.js +1 -9
- package/dist/ar/product-ar.d.ts +4 -2
- package/dist/ar/product-ar.js +24 -7
- package/dist/ar/scene-product-ar.d.ts +1 -1
- package/dist/ar/scene-product-ar.js +2 -2
- package/dist/embed/controllers/configurator-controller.js +8 -0
- package/dist/embed/controllers/plattar-controller.js +4 -0
- package/dist/embed/controllers/product-controller.js +11 -2
- package/dist/embed/controllers/viewer-controller.js +29 -8
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
package/dist/ar/product-ar.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ export declare class ProductAR extends LauncherAR {
|
|
|
6
6
|
private _analytics;
|
|
7
7
|
private readonly _productID;
|
|
8
8
|
private readonly _variationID;
|
|
9
|
+
private readonly _variationSKU;
|
|
9
10
|
private _ar;
|
|
10
|
-
constructor(productID?: string | undefined | null, variationID?: string | undefined | null);
|
|
11
|
+
constructor(productID?: string | undefined | null, variationID?: string | undefined | null, variationSKU?: string | undefined | null);
|
|
11
12
|
get productID(): string;
|
|
12
|
-
get variationID(): string;
|
|
13
|
+
get variationID(): string | null;
|
|
14
|
+
get variationSKU(): string | null;
|
|
13
15
|
private _SetupAnalytics;
|
|
14
16
|
/**
|
|
15
17
|
* Initialise the ProductAR instance. This returns a Promise that resolves
|
package/dist/ar/product-ar.js
CHANGED
|
@@ -15,7 +15,7 @@ const launcher_ar_1 = require("./launcher-ar");
|
|
|
15
15
|
* Performs AR functionality related to Plattar Products and Variation types
|
|
16
16
|
*/
|
|
17
17
|
class ProductAR extends launcher_ar_1.LauncherAR {
|
|
18
|
-
constructor(productID = null, variationID = null) {
|
|
18
|
+
constructor(productID = null, variationID = null, variationSKU = null) {
|
|
19
19
|
super();
|
|
20
20
|
// analytics instance
|
|
21
21
|
this._analytics = null;
|
|
@@ -23,7 +23,8 @@ class ProductAR extends launcher_ar_1.LauncherAR {
|
|
|
23
23
|
throw new Error("ProductAR.constructor(productID, variationID) - productID must be defined");
|
|
24
24
|
}
|
|
25
25
|
this._productID = productID;
|
|
26
|
-
this.
|
|
26
|
+
this._variationSKU = variationSKU;
|
|
27
|
+
this._variationID = variationID ? variationID : (variationSKU ? null : "default");
|
|
27
28
|
this._ar = null;
|
|
28
29
|
}
|
|
29
30
|
get productID() {
|
|
@@ -32,6 +33,9 @@ class ProductAR extends launcher_ar_1.LauncherAR {
|
|
|
32
33
|
get variationID() {
|
|
33
34
|
return this._variationID;
|
|
34
35
|
}
|
|
36
|
+
get variationSKU() {
|
|
37
|
+
return this._variationSKU;
|
|
38
|
+
}
|
|
35
39
|
_SetupAnalytics(product, variation) {
|
|
36
40
|
let analytics = null;
|
|
37
41
|
const scene = product.relationships.find(plattar_api_1.Scene);
|
|
@@ -80,14 +84,27 @@ class ProductAR extends launcher_ar_1.LauncherAR {
|
|
|
80
84
|
product.include(plattar_api_1.Scene.include(plattar_api_1.Project));
|
|
81
85
|
product.get().then((product) => {
|
|
82
86
|
// find the required variation from our product
|
|
83
|
-
const variationID = this.variationID ? (this.variationID === "default" ? product.attributes.product_variation_id : this.variationID) :
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
const variationID = this.variationID ? (this.variationID === "default" ? product.attributes.product_variation_id : this.variationID) : null;
|
|
88
|
+
const variationSKU = this.variationSKU;
|
|
89
|
+
if (!variationID && !variationSKU) {
|
|
90
|
+
return reject(new Error("ProductAR.init() - cannot proceed as variation-id or variation-sku was not set correctly"));
|
|
91
|
+
}
|
|
92
|
+
let variation = undefined;
|
|
93
|
+
if (variationID) {
|
|
94
|
+
variation = product.relationships.find(plattar_api_1.ProductVariation, variationID);
|
|
95
|
+
}
|
|
96
|
+
// if no variation was found with variationID - try searching variation sku
|
|
97
|
+
if (!variation && variationSKU) {
|
|
98
|
+
const variations = product.relationships.filter(plattar_api_1.ProductVariation);
|
|
99
|
+
if (variations) {
|
|
100
|
+
variation = variations.find((element) => {
|
|
101
|
+
return element.attributes.sku === variationSKU;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
86
104
|
}
|
|
87
|
-
const variation = product.relationships.find(plattar_api_1.ProductVariation, variationID);
|
|
88
105
|
// make sure our variation is actually available before moving forward
|
|
89
106
|
if (!variation) {
|
|
90
|
-
return reject(new Error("ProductAR.init() - cannot proceed as variation with id " + variationID + " cannot be found"));
|
|
107
|
+
return reject(new Error("ProductAR.init() - cannot proceed as variation with id " + variationID + " or sku " + variationSKU + " cannot be found"));
|
|
91
108
|
}
|
|
92
109
|
// otherwise both the product and variation are available
|
|
93
110
|
// we need to figure out if we can actually do AR though
|
|
@@ -7,7 +7,7 @@ import { LauncherAR } from "./launcher-ar";
|
|
|
7
7
|
export declare class SceneProductAR extends ProductAR {
|
|
8
8
|
private readonly _sceneProductID;
|
|
9
9
|
private _attachedProductID;
|
|
10
|
-
constructor(sceneProductID?: string | undefined | null, variationID?: string | undefined | null);
|
|
10
|
+
constructor(sceneProductID?: string | undefined | null, variationID?: string | undefined | null, variationSKU?: string | undefined | null);
|
|
11
11
|
get sceneProductID(): string;
|
|
12
12
|
get productID(): string;
|
|
13
13
|
init(): Promise<LauncherAR>;
|
|
@@ -9,8 +9,8 @@ const util_1 = require("../util/util");
|
|
|
9
9
|
* SceneProducts are much more convenient to grab from the Plattar CMS
|
|
10
10
|
*/
|
|
11
11
|
class SceneProductAR extends product_ar_1.ProductAR {
|
|
12
|
-
constructor(sceneProductID = null, variationID = null) {
|
|
13
|
-
super(sceneProductID, variationID);
|
|
12
|
+
constructor(sceneProductID = null, variationID = null, variationSKU = null) {
|
|
13
|
+
super(sceneProductID, variationID, variationSKU);
|
|
14
14
|
// this is evaluated in the init() function
|
|
15
15
|
this._attachedProductID = null;
|
|
16
16
|
if (!sceneProductID) {
|
|
@@ -50,6 +50,10 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
|
|
|
50
50
|
// optional attributes
|
|
51
51
|
const configState = this.getAttribute("config-state");
|
|
52
52
|
const showAR = this.getAttribute("show-ar");
|
|
53
|
+
const showUI = this.getAttribute("show-ui");
|
|
54
|
+
if (showUI && showUI === "true") {
|
|
55
|
+
dst = plattar_api_1.Server.location().base + "configurator/dist/index.html?scene_id=" + sceneID;
|
|
56
|
+
}
|
|
53
57
|
if (configState) {
|
|
54
58
|
dst += "&config_state=" + configState;
|
|
55
59
|
}
|
|
@@ -87,12 +91,16 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
|
|
|
87
91
|
// optional attributes
|
|
88
92
|
const configState = this.getAttribute("config-state");
|
|
89
93
|
const showAR = this.getAttribute("show-ar");
|
|
94
|
+
const showUI = this.getAttribute("show-ui");
|
|
90
95
|
if (configState) {
|
|
91
96
|
viewer.setAttribute("config-state", configState);
|
|
92
97
|
}
|
|
93
98
|
if (showAR) {
|
|
94
99
|
viewer.setAttribute("show-ar", showAR);
|
|
95
100
|
}
|
|
101
|
+
if (showUI) {
|
|
102
|
+
viewer.setAttribute("show-ui", showUI);
|
|
103
|
+
}
|
|
96
104
|
viewer.onload = () => {
|
|
97
105
|
return accept(viewer);
|
|
98
106
|
};
|
|
@@ -88,6 +88,7 @@ class PlattarController {
|
|
|
88
88
|
const productID = this.getAttribute("product-id");
|
|
89
89
|
const sceneProductID = this.getAttribute("scene-product-id");
|
|
90
90
|
const variationID = this.getAttribute("variation-id");
|
|
91
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
91
92
|
const arMode = this.getAttribute("ar-mode");
|
|
92
93
|
if (configState) {
|
|
93
94
|
dst += "&config_state=" + configState;
|
|
@@ -104,6 +105,9 @@ class PlattarController {
|
|
|
104
105
|
if (variationID) {
|
|
105
106
|
dst += "&variation_id=" + variationID;
|
|
106
107
|
}
|
|
108
|
+
if (variationSKU) {
|
|
109
|
+
dst += "&variation_sku=" + variationSKU;
|
|
110
|
+
}
|
|
107
111
|
if (arMode) {
|
|
108
112
|
dst += "&ar_mode=" + arMode;
|
|
109
113
|
}
|
|
@@ -55,10 +55,14 @@ class ProductController extends plattar_controller_1.PlattarController {
|
|
|
55
55
|
}
|
|
56
56
|
// optional attributes
|
|
57
57
|
const variationID = this.getAttribute("variation-id");
|
|
58
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
58
59
|
const showAR = this.getAttribute("show-ar");
|
|
59
60
|
let dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
|
|
60
61
|
if (variationID) {
|
|
61
|
-
dst += "&
|
|
62
|
+
dst += "&variationId=" + variationID;
|
|
63
|
+
}
|
|
64
|
+
if (variationSKU) {
|
|
65
|
+
dst += "&variationSku=" + variationSKU;
|
|
62
66
|
}
|
|
63
67
|
if (showAR) {
|
|
64
68
|
dst += "&show_ar=" + showAR;
|
|
@@ -93,10 +97,14 @@ class ProductController extends plattar_controller_1.PlattarController {
|
|
|
93
97
|
viewer.setAttribute("product-id", productID);
|
|
94
98
|
// optional attributes
|
|
95
99
|
const variationID = this.getAttribute("variation-id");
|
|
100
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
96
101
|
const showAR = this.getAttribute("show-ar");
|
|
97
102
|
if (variationID) {
|
|
98
103
|
viewer.setAttribute("variation-id", variationID);
|
|
99
104
|
}
|
|
105
|
+
if (variationSKU) {
|
|
106
|
+
viewer.setAttribute("variation-sku", variationSKU);
|
|
107
|
+
}
|
|
100
108
|
if (showAR) {
|
|
101
109
|
viewer.setAttribute("show-ar", showAR);
|
|
102
110
|
}
|
|
@@ -119,7 +127,8 @@ class ProductController extends plattar_controller_1.PlattarController {
|
|
|
119
127
|
const productID = this.getAttribute("product-id");
|
|
120
128
|
if (productID) {
|
|
121
129
|
const variationID = this.getAttribute("variation-id");
|
|
122
|
-
const
|
|
130
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
131
|
+
const product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
|
|
123
132
|
return product.init().then(accept).catch(reject);
|
|
124
133
|
}
|
|
125
134
|
return reject(new Error("ProductController.initAR() - minimum required attributes not set, use product-id as a minimum"));
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ViewerController = void 0;
|
|
4
4
|
const plattar_api_1 = require("@plattar/plattar-api");
|
|
5
5
|
const product_ar_1 = require("../../ar/product-ar");
|
|
6
|
+
const scene_ar_1 = require("../../ar/scene-ar");
|
|
6
7
|
const scene_product_ar_1 = require("../../ar/scene-product-ar");
|
|
7
8
|
const configurator_state_1 = require("../../util/configurator-state");
|
|
8
9
|
const util_1 = require("../../util/util");
|
|
@@ -60,6 +61,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
|
|
|
60
61
|
// optional attributes
|
|
61
62
|
const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
|
|
62
63
|
const variationID = this.getAttribute("variation-id");
|
|
64
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
63
65
|
const showAR = this.getAttribute("show-ar");
|
|
64
66
|
if (productID) {
|
|
65
67
|
dst += "&productId=" + productID;
|
|
@@ -67,6 +69,9 @@ class ViewerController extends plattar_controller_1.PlattarController {
|
|
|
67
69
|
if (variationID) {
|
|
68
70
|
dst += "&variationId=" + variationID;
|
|
69
71
|
}
|
|
72
|
+
if (variationSKU) {
|
|
73
|
+
dst += "&variationSku=" + variationSKU;
|
|
74
|
+
}
|
|
70
75
|
if (showAR) {
|
|
71
76
|
dst += "&show_ar=" + showAR;
|
|
72
77
|
}
|
|
@@ -101,6 +106,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
|
|
|
101
106
|
// optional attributes
|
|
102
107
|
const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
|
|
103
108
|
const variationID = this.getAttribute("variation-id");
|
|
109
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
104
110
|
const showAR = this.getAttribute("show-ar");
|
|
105
111
|
if (productID) {
|
|
106
112
|
viewer.setAttribute("product-id", productID);
|
|
@@ -108,6 +114,9 @@ class ViewerController extends plattar_controller_1.PlattarController {
|
|
|
108
114
|
if (variationID) {
|
|
109
115
|
viewer.setAttribute("variation-id", variationID);
|
|
110
116
|
}
|
|
117
|
+
if (variationSKU) {
|
|
118
|
+
viewer.setAttribute("variation-sku", variationSKU);
|
|
119
|
+
}
|
|
111
120
|
if (showAR) {
|
|
112
121
|
viewer.setAttribute("show-ar", showAR);
|
|
113
122
|
}
|
|
@@ -131,26 +140,38 @@ class ViewerController extends plattar_controller_1.PlattarController {
|
|
|
131
140
|
// use product-id if available
|
|
132
141
|
if (productID) {
|
|
133
142
|
const variationID = this.getAttribute("variation-id");
|
|
134
|
-
const
|
|
143
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
144
|
+
const product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
|
|
135
145
|
return product.init().then(accept).catch(reject);
|
|
136
146
|
}
|
|
137
147
|
const sceneProductID = this.getAttribute("scene-product-id");
|
|
138
148
|
// use scene-product-id if available
|
|
139
149
|
if (sceneProductID) {
|
|
140
150
|
const variationID = this.getAttribute("variation-id");
|
|
141
|
-
const
|
|
151
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
152
|
+
const product = new scene_product_ar_1.SceneProductAR(sceneProductID, variationID, variationSKU);
|
|
142
153
|
return product.init().then(accept).catch(reject);
|
|
143
154
|
}
|
|
144
155
|
const sceneID = this.getAttribute("scene-id");
|
|
145
|
-
//
|
|
156
|
+
// fallback to using default SceneAR implementation
|
|
146
157
|
if (sceneID) {
|
|
158
|
+
// special case - check if scene only has a single product, if so
|
|
159
|
+
// we need to use provided variation-id or variation-sku to override
|
|
160
|
+
const variationID = this.getAttribute("variation-id");
|
|
161
|
+
const variationSKU = this.getAttribute("variation-sku");
|
|
162
|
+
// just do scene-ar if variation ID and variation SKU is not set
|
|
163
|
+
if (!variationID && !variationSKU) {
|
|
164
|
+
const sceneAR = new scene_ar_1.SceneAR(sceneID);
|
|
165
|
+
return sceneAR.init().then(accept).catch(reject);
|
|
166
|
+
}
|
|
167
|
+
// otherwise decode scene
|
|
147
168
|
return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
return sceneProductAR.init().then(accept).catch(reject);
|
|
169
|
+
const firstProduct = state.first();
|
|
170
|
+
if (state.length > 1 || !firstProduct) {
|
|
171
|
+
return reject(new Error("ViewerController.initAR() - single product required to override variation-id or variation-sku"));
|
|
152
172
|
}
|
|
153
|
-
|
|
173
|
+
const product = new scene_product_ar_1.SceneProductAR(firstProduct.scene_product_id, variationID, variationSKU);
|
|
174
|
+
return product.init().then(accept).catch(reject);
|
|
154
175
|
}).catch(reject);
|
|
155
176
|
}
|
|
156
177
|
return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.131.1";
|
|
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.131.1",
|
|
4
4
|
"description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"@plattar/plattar-api": "^1.120.1",
|
|
42
42
|
"@plattar/plattar-qrcode": "1.122.1",
|
|
43
43
|
"@plattar/plattar-services": "^1.120.1",
|
|
44
|
-
"@plattar/plattar-web": "^1.
|
|
44
|
+
"@plattar/plattar-web": "^1.131.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/cli": "^7.17.10",
|
|
48
|
-
"@babel/core": "^7.
|
|
49
|
-
"@babel/preset-env": "^7.
|
|
48
|
+
"@babel/core": "^7.18.2",
|
|
49
|
+
"@babel/preset-env": "^7.18.2",
|
|
50
50
|
"browserify": "^17.0.0",
|
|
51
51
|
"typescript": "^4.6.4",
|
|
52
52
|
"uglify-js": "^3.15.5"
|