@plattar/plattar-ar-adapter 1.123.2 → 1.123.3

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.
@@ -11,7 +11,6 @@ export declare class ConfiguratorController extends PlattarController {
11
11
  onAttributesUpdated(): void;
12
12
  startQRCode(options: any): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
- startAR(): Promise<void>;
15
14
  initAR(): Promise<LauncherAR>;
16
15
  removeRenderer(): boolean;
17
16
  get element(): HTMLElement | null;
@@ -104,14 +104,6 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
104
104
  return reject(new Error("ConfiguratorController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
105
105
  });
106
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
107
  initAR() {
116
108
  return new Promise((accept, reject) => {
117
109
  if (!util_1.Util.canAugment()) {
@@ -31,7 +31,7 @@ export declare abstract class PlattarController {
31
31
  /**
32
32
  * Initialise and start AR mode if available
33
33
  */
34
- abstract startAR(): Promise<void>;
34
+ startAR(): Promise<void>;
35
35
  /**
36
36
  * Initialise and return a launcher that can be used to start AR
37
37
  */
@@ -25,6 +25,17 @@ class PlattarController {
25
25
  };
26
26
  }
27
27
  ;
28
+ /**
29
+ * Initialise and start AR mode if available
30
+ */
31
+ startAR() {
32
+ return new Promise((accept, reject) => {
33
+ this.initAR().then((launcher) => {
34
+ launcher.start();
35
+ accept();
36
+ }).catch(reject);
37
+ });
38
+ }
28
39
  /**
29
40
  * Returns the Parent Instance
30
41
  */
@@ -11,7 +11,6 @@ export declare class ProductController extends PlattarController {
11
11
  onAttributesUpdated(): void;
12
12
  startQRCode(options: any): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
- startAR(): Promise<void>;
15
14
  initAR(): Promise<LauncherAR>;
16
15
  removeRenderer(): boolean;
17
16
  get element(): HTMLElement | null;
@@ -104,14 +104,6 @@ class ProductController extends plattar_controller_1.PlattarController {
104
104
  return reject(new Error("ProductController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
105
105
  });
106
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
107
  initAR() {
116
108
  return new Promise((accept, reject) => {
117
109
  if (!util_1.Util.canAugment()) {
@@ -11,7 +11,6 @@ export declare class ViewerController extends PlattarController {
11
11
  onAttributesUpdated(): void;
12
12
  startQRCode(options: any): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
- startAR(): Promise<void>;
15
14
  initAR(): Promise<LauncherAR>;
16
15
  removeRenderer(): boolean;
17
16
  get element(): HTMLElement | null;
@@ -113,14 +113,6 @@ class ViewerController extends plattar_controller_1.PlattarController {
113
113
  return reject(new Error("ViewerController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
114
114
  });
115
115
  }
116
- startAR() {
117
- return new Promise((accept, reject) => {
118
- this.initAR().then((launcher) => {
119
- launcher.start();
120
- accept();
121
- }).catch(reject);
122
- });
123
- }
124
116
  initAR() {
125
117
  return new Promise((accept, reject) => {
126
118
  if (!util_1.Util.canAugment()) {
@@ -0,0 +1,17 @@
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 VTOController 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
+ initAR(): Promise<LauncherAR>;
15
+ removeRenderer(): boolean;
16
+ get element(): HTMLElement | null;
17
+ }
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VTOController = void 0;
4
+ const plattar_api_1 = require("@plattar/plattar-api");
5
+ const plattar_services_1 = require("@plattar/plattar-services");
6
+ const __1 = require("../..");
7
+ const raw_ar_1 = require("../../ar/raw-ar");
8
+ const util_1 = require("../../util/util");
9
+ const plattar_controller_1 = require("./plattar-controller");
10
+ /**
11
+ * Manages an instance of the <plattar-configurator> HTML Element
12
+ */
13
+ class VTOController extends plattar_controller_1.PlattarController {
14
+ constructor(parent) {
15
+ super(parent);
16
+ this._state = plattar_controller_1.ControllerState.None;
17
+ this._element = null;
18
+ this._prevQROpt = null;
19
+ }
20
+ onAttributesUpdated() {
21
+ const state = this._state;
22
+ // re-render the QR Code when attributes have changed
23
+ if (state === plattar_controller_1.ControllerState.QRCode) {
24
+ this.startQRCode(this._prevQROpt);
25
+ return;
26
+ }
27
+ }
28
+ startQRCode(options) {
29
+ return new Promise((accept, reject) => {
30
+ // remove the old renderer instance if any
31
+ this.removeRenderer();
32
+ const sceneID = this.getAttribute("scene-id");
33
+ if (sceneID) {
34
+ const opt = options || plattar_controller_1.PlattarController.DEFAULT_QR_OPTIONS;
35
+ const viewer = document.createElement("plattar-qrcode");
36
+ // required attributes with defaults for plattar-viewer node
37
+ const width = this.getAttribute("width") || "500px";
38
+ const height = this.getAttribute("height") || "500px";
39
+ viewer.setAttribute("width", width);
40
+ viewer.setAttribute("height", height);
41
+ if (opt.color) {
42
+ viewer.setAttribute("color", opt.color);
43
+ }
44
+ if (opt.margin) {
45
+ viewer.setAttribute("margin", "" + opt.margin);
46
+ }
47
+ if (opt.qrType) {
48
+ viewer.setAttribute("qr-type", opt.qrType);
49
+ }
50
+ let dst = plattar_api_1.Server.location().base + "renderer/facear.html?scene_id=" + sceneID;
51
+ // optional attributes
52
+ const configState = this.getAttribute("config-state");
53
+ const showAR = this.getAttribute("show-ar");
54
+ if (configState) {
55
+ dst += "&config_state=" + configState;
56
+ }
57
+ if (showAR) {
58
+ dst += "&show_ar=" + showAR;
59
+ }
60
+ viewer.setAttribute("url", opt.url || dst);
61
+ viewer.onload = () => {
62
+ return accept(viewer);
63
+ };
64
+ this.append(viewer);
65
+ this._element = viewer;
66
+ this._state = plattar_controller_1.ControllerState.QRCode;
67
+ this._prevQROpt = opt;
68
+ return;
69
+ }
70
+ return reject(new Error("VTOController.startQRCode() - minimum required attributes not set, use scene-id as a minimum"));
71
+ });
72
+ }
73
+ startRenderer() {
74
+ return new Promise((accept, reject) => {
75
+ // remove the old renderer instance if any
76
+ this.removeRenderer();
77
+ const sceneID = this.getAttribute("scene-id");
78
+ if (sceneID) {
79
+ // required attributes with defaults for plattar-facear node
80
+ const width = this.getAttribute("width") || "500px";
81
+ const height = this.getAttribute("height") || "500px";
82
+ const server = this.getAttribute("server") || "production";
83
+ const viewer = document.createElement("plattar-facear");
84
+ viewer.setAttribute("width", width);
85
+ viewer.setAttribute("height", height);
86
+ viewer.setAttribute("server", server);
87
+ viewer.setAttribute("scene-id", sceneID);
88
+ // optional attributes
89
+ const configState = this.getAttribute("config-state");
90
+ const showAR = this.getAttribute("show-ar");
91
+ if (configState) {
92
+ viewer.setAttribute("config-state", configState);
93
+ }
94
+ if (showAR) {
95
+ viewer.setAttribute("show-ar", showAR);
96
+ }
97
+ viewer.onload = () => {
98
+ return accept(viewer);
99
+ };
100
+ this.append(viewer);
101
+ this._element = viewer;
102
+ this._state = plattar_controller_1.ControllerState.Renderer;
103
+ return;
104
+ }
105
+ return reject(new Error("VTOController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
106
+ });
107
+ }
108
+ initAR() {
109
+ return new Promise((accept, reject) => {
110
+ if (!util_1.Util.canAugment()) {
111
+ return reject(new Error("VTOController.initAR() - cannot proceed as VTO AR not available in context"));
112
+ }
113
+ if (!(util_1.Util.isSafari() || util_1.Util.isChromeOnIOS())) {
114
+ return reject(new Error("VTOController.initAR() - cannot proceed as VTO AR only available on IOS Mobile devices"));
115
+ }
116
+ // if scene ID is available and the state is a configurator viewer
117
+ // we can use the real-time configurator state to launch the AR view
118
+ const viewer = this.element;
119
+ const sceneID = this.getAttribute("scene-id");
120
+ if (viewer && sceneID) {
121
+ return viewer.messenger.getARFile("vto").then((result) => {
122
+ const rawAR = new raw_ar_1.RawAR(result.filename);
123
+ return rawAR.init().then(accept).catch(reject);
124
+ }).catch(reject);
125
+ }
126
+ const configState = this.getAttribute("config-state");
127
+ // otherwise scene ID is available to the viewer is not launched
128
+ // we can use the static configuration state to launch the AR view
129
+ if (sceneID && configState) {
130
+ const state = __1.ConfiguratorState.decode(configState);
131
+ if (state.length > 0) {
132
+ const server = this.getAttribute("server") || "production";
133
+ const configurator = new plattar_services_1.Configurator();
134
+ configurator.server = server;
135
+ configurator.output = "vto";
136
+ state.forEach((productState) => {
137
+ if (productState.meta_data.augment === true) {
138
+ configurator.addSceneProduct(productState.scene_product_id, productState.product_variation_id);
139
+ }
140
+ });
141
+ return configurator.get().then((result) => {
142
+ const rawAR = new raw_ar_1.RawAR(result.filename);
143
+ rawAR.init().then(accept).catch(reject);
144
+ }).catch(reject);
145
+ }
146
+ return reject(new Error("VTOController.initAR() - invalid config-state does not have any product states"));
147
+ }
148
+ // otherwise no config-state or viewer is active
149
+ // fallback to using default SceneAR implementation
150
+ if (sceneID) {
151
+ const sceneAR = new __1.SceneAR(sceneID);
152
+ return sceneAR.init().then(accept).catch(reject);
153
+ }
154
+ return reject(new Error("VTOController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
155
+ });
156
+ }
157
+ removeRenderer() {
158
+ if (this._element) {
159
+ this._element.remove();
160
+ this._element = null;
161
+ return true;
162
+ }
163
+ return false;
164
+ }
165
+ get element() {
166
+ return this._element;
167
+ }
168
+ }
169
+ exports.VTOController = VTOController;
@@ -13,6 +13,12 @@ export default class PlattarEmbed extends HTMLElement {
13
13
  startAR(): Promise<void>;
14
14
  startViewer(): Promise<HTMLElement>;
15
15
  startQRCode(options?: any | undefined | null): Promise<HTMLElement>;
16
+ /**
17
+ * This will remove the currently active Renderer
18
+ *
19
+ * @returns - true if removed successfully, false otherwise
20
+ */
21
+ removeRenderer(): boolean;
16
22
  /**
17
23
  * This is called by the observer if any of the embed attributes have changed
18
24
  * based on the state of the embed, we update the internal structure accordingly
@@ -4,6 +4,7 @@ const plattar_api_1 = require("@plattar/plattar-api");
4
4
  const product_controller_1 = require("./controllers/product-controller");
5
5
  const viewer_controller_1 = require("./controllers/viewer-controller");
6
6
  const configurator_controller_1 = require("./controllers/configurator-controller");
7
+ const vto_controller_1 = require("./controllers/vto-controller");
7
8
  /**
8
9
  * This tracks the current embed type
9
10
  */
@@ -11,6 +12,7 @@ var EmbedType;
11
12
  (function (EmbedType) {
12
13
  EmbedType[EmbedType["Viewer"] = 0] = "Viewer";
13
14
  EmbedType[EmbedType["Configurator"] = 1] = "Configurator";
15
+ EmbedType[EmbedType["VTO"] = 2] = "VTO";
14
16
  })(EmbedType || (EmbedType = {}));
15
17
  /**
16
18
  * This is the primary <plattar-embed /> node that allows easy embedding
@@ -33,6 +35,9 @@ class PlattarEmbed extends HTMLElement {
33
35
  case "viewer":
34
36
  this._currentType = EmbedType.Viewer;
35
37
  break;
38
+ case "vto":
39
+ this._currentType = EmbedType.VTO;
40
+ break;
36
41
  case "configurator":
37
42
  this._currentType = EmbedType.Configurator;
38
43
  break;
@@ -67,6 +72,9 @@ class PlattarEmbed extends HTMLElement {
67
72
  else if (this._currentType === EmbedType.Configurator) {
68
73
  this._controller = new configurator_controller_1.ConfiguratorController(this);
69
74
  }
75
+ else if (this._currentType === EmbedType.VTO) {
76
+ this._controller = new vto_controller_1.VTOController(this);
77
+ }
70
78
  const init = this.hasAttribute("init") ? this.getAttribute("init") : null;
71
79
  if (init === "ar") {
72
80
  this.startAR();
@@ -124,6 +132,17 @@ class PlattarEmbed extends HTMLElement {
124
132
  return this._controller.startQRCode(options).then(accept).catch(reject);
125
133
  });
126
134
  }
135
+ /**
136
+ * This will remove the currently active Renderer
137
+ *
138
+ * @returns - true if removed successfully, false otherwise
139
+ */
140
+ removeRenderer() {
141
+ if (!this._controller) {
142
+ return false;
143
+ }
144
+ return this._controller.removeRenderer();
145
+ }
127
146
  /**
128
147
  * This is called by the observer if any of the embed attributes have changed
129
148
  * based on the state of the embed, we update the internal structure accordingly
package/dist/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export { SceneAR } from "./ar/scene-ar";
6
6
  export { ModelAR } from "./ar/model-ar";
7
7
  export { RawAR } from "./ar/raw-ar";
8
8
  export { Util } from "./util/util";
9
+ export { ConfiguratorState } from "./util/configurator-state";
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.RawAR = exports.ModelAR = exports.SceneAR = exports.ProductAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
25
+ exports.ConfiguratorState = exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.ProductAR = 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"));
@@ -36,6 +36,8 @@ var raw_ar_1 = require("./ar/raw-ar");
36
36
  Object.defineProperty(exports, "RawAR", { enumerable: true, get: function () { return raw_ar_1.RawAR; } });
37
37
  var util_1 = require("./util/util");
38
38
  Object.defineProperty(exports, "Util", { enumerable: true, get: function () { return util_1.Util; } });
39
+ var configurator_state_1 = require("./util/configurator-state");
40
+ Object.defineProperty(exports, "ConfiguratorState", { enumerable: true, get: function () { return configurator_state_1.ConfiguratorState; } });
39
41
  const plattar_embed_1 = __importDefault(require("./embed/plattar-embed"));
40
42
  const version_1 = __importDefault(require("./version"));
41
43
  if (customElements) {
@@ -0,0 +1,26 @@
1
+ export interface SceneProductData {
2
+ scene_product_id: string;
3
+ product_variation_id: string;
4
+ meta_data: {
5
+ augment: boolean;
6
+ };
7
+ }
8
+ export declare class ConfiguratorState {
9
+ private readonly _state;
10
+ constructor(state?: string | null | undefined);
11
+ /**
12
+ * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
13
+ *
14
+ * @param sceneProductID - The Scene Product ID to be used (as defined in Plattar CMS)
15
+ * @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
16
+ * @param metaData - Arbitrary meta-data that can be used against certain operaions
17
+ */
18
+ addSceneProduct(sceneProductID: string, productVariationID: string, metaData?: any | null | undefined): void;
19
+ /**
20
+ * Iterate over the internal state data
21
+ */
22
+ forEach(callback: (data: SceneProductData) => void): void;
23
+ get length(): number;
24
+ static decode(state: string): ConfiguratorState;
25
+ encode(): string;
26
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfiguratorState = void 0;
4
+ class ConfiguratorState {
5
+ constructor(state = null) {
6
+ const defaultState = {
7
+ meta: {
8
+ scene_product_index: 0,
9
+ product_variation_index: 1,
10
+ meta_index: 2,
11
+ },
12
+ states: []
13
+ };
14
+ if (state) {
15
+ try {
16
+ const decodedb64State = atob(state);
17
+ const parsedState = JSON.parse(decodedb64State);
18
+ // set the meta data
19
+ if (parsedState.meta) {
20
+ defaultState.meta.scene_product_index = parsedState.meta.scene_product_index || 0;
21
+ defaultState.meta.product_variation_index = parsedState.meta.product_variation_index || 1;
22
+ defaultState.meta.meta_index = parsedState.meta.meta_index || 2;
23
+ }
24
+ defaultState.states = parsedState.states || [];
25
+ }
26
+ catch (err) {
27
+ console.error("ConfiguratorState.constructor() - there was an error parsing configurator state");
28
+ console.error(err);
29
+ }
30
+ }
31
+ this._state = defaultState;
32
+ }
33
+ /**
34
+ * Adds a new Scene Product/Variation combo with meta-data into the Configurator State
35
+ *
36
+ * @param sceneProductID - The Scene Product ID to be used (as defined in Plattar CMS)
37
+ * @param productVariationID - The Product Variation ID to be used (as defined in Plattar CMS)
38
+ * @param metaData - Arbitrary meta-data that can be used against certain operaions
39
+ */
40
+ addSceneProduct(sceneProductID, productVariationID, metaData = null) {
41
+ if (sceneProductID && productVariationID) {
42
+ const states = this._state.states;
43
+ const meta = this._state.meta;
44
+ const newData = [];
45
+ newData.splice(meta.scene_product_index, 0, sceneProductID);
46
+ newData.splice(meta.product_variation_index, 0, productVariationID);
47
+ if (metaData) {
48
+ newData.splice(meta.meta_index, 0, metaData);
49
+ }
50
+ states.push(newData);
51
+ }
52
+ }
53
+ /**
54
+ * Iterate over the internal state data
55
+ */
56
+ forEach(callback) {
57
+ const states = this._state.states;
58
+ const meta = this._state.meta;
59
+ if (states.length > 0) {
60
+ states.forEach((productState) => {
61
+ if (productState.length === 2) {
62
+ callback({
63
+ scene_product_id: productState[meta.scene_product_index],
64
+ product_variation_id: productState[meta.product_variation_index],
65
+ meta_data: {
66
+ augment: true
67
+ }
68
+ });
69
+ }
70
+ else if (productState.length === 3) {
71
+ callback({
72
+ scene_product_id: productState[meta.scene_product_index],
73
+ product_variation_id: productState[meta.product_variation_index],
74
+ meta_data: {
75
+ augment: productState[meta.meta_index].augment || true
76
+ }
77
+ });
78
+ }
79
+ });
80
+ }
81
+ }
82
+ get length() {
83
+ return this._state.states.length;
84
+ }
85
+ static decode(state) {
86
+ return new ConfiguratorState(state);
87
+ }
88
+ encode() {
89
+ return btoa(JSON.stringify(this._state));
90
+ }
91
+ }
92
+ exports.ConfiguratorState = ConfiguratorState;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.123.2";
1
+ declare const _default: "1.123.3";
2
2
  export default _default;
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = "1.123.2";
3
+ exports.default = "1.123.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.123.2",
3
+ "version": "1.123.3",
4
4
  "description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -45,11 +45,11 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@babel/cli": "^7.17.0",
48
- "@babel/core": "^7.17.0",
48
+ "@babel/core": "^7.17.2",
49
49
  "@babel/preset-env": "^7.16.11",
50
50
  "browserify": "^17.0.0",
51
51
  "typescript": "^4.5.5",
52
- "uglify-es": "^3.3.9"
52
+ "uglify-js": "^3.15.1"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"