@plattar/plattar-ar-adapter 1.123.7 → 1.129.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.
@@ -4,12 +4,9 @@ import { PlattarController } from "./plattar-controller";
4
4
  * Manages an instance of the <plattar-configurator> HTML Element
5
5
  */
6
6
  export declare class ConfiguratorController extends PlattarController {
7
- private _state;
8
- private _element;
9
- private _prevQROpt;
10
7
  constructor(parent: HTMLElement);
11
8
  onAttributesUpdated(): void;
12
- startQRCode(options: any): Promise<HTMLElement>;
9
+ startViewerQRCode(options: any): Promise<HTMLElement>;
13
10
  startRenderer(): Promise<HTMLElement>;
14
11
  initAR(): Promise<LauncherAR>;
15
12
  /**
@@ -15,9 +15,6 @@ const plattar_controller_1 = require("./plattar-controller");
15
15
  class ConfiguratorController extends plattar_controller_1.PlattarController {
16
16
  constructor(parent) {
17
17
  super(parent);
18
- this._state = plattar_controller_1.ControllerState.None;
19
- this._element = null;
20
- this._prevQROpt = null;
21
18
  }
22
19
  onAttributesUpdated() {
23
20
  const state = this._state;
@@ -27,7 +24,7 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
27
24
  return;
28
25
  }
29
26
  }
30
- startQRCode(options) {
27
+ startViewerQRCode(options) {
31
28
  return new Promise((accept, reject) => {
32
29
  // remove the old renderer instance if any
33
30
  this.removeRenderer();
@@ -13,17 +13,15 @@ export declare abstract class PlattarController {
13
13
  */
14
14
  static get DEFAULT_QR_OPTIONS(): any;
15
15
  private readonly _parent;
16
+ protected _state: ControllerState;
17
+ protected _element: HTMLElement | null;
18
+ protected _prevQROpt: any;
16
19
  constructor(parent: HTMLElement);
17
20
  /**
18
21
  * Called by the parent when a HTML Attribute has changed and the controller
19
22
  * requires an update
20
23
  */
21
24
  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
25
  /**
28
26
  * Start the underlying Plattar Renderer for this Controller
29
27
  */
@@ -32,6 +30,23 @@ export declare abstract class PlattarController {
32
30
  * Initialise and start AR mode if available
33
31
  */
34
32
  startAR(): Promise<void>;
33
+ /**
34
+ * Start Rendering a QR Code with the provided options
35
+ * @param options (optional) - The QR Code Options
36
+ */
37
+ abstract startViewerQRCode(options: any | undefined | null): Promise<HTMLElement>;
38
+ /**
39
+ * Decide which QR Code to render according to the qr-type attribute
40
+ * @param options
41
+ * @returns
42
+ */
43
+ startQRCode(options: any): Promise<HTMLElement>;
44
+ /**
45
+ * Displays a QR Code that sends the user direct to AR
46
+ * @param options
47
+ * @returns
48
+ */
49
+ startARQRCode(options: any): Promise<HTMLElement>;
35
50
  /**
36
51
  * Initialise and return a launcher that can be used to start AR
37
52
  */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlattarController = exports.ControllerState = void 0;
4
+ const plattar_api_1 = require("@plattar/plattar-api");
4
5
  var ControllerState;
5
6
  (function (ControllerState) {
6
7
  ControllerState[ControllerState["None"] = 0] = "None";
@@ -12,6 +13,9 @@ var ControllerState;
12
13
  */
13
14
  class PlattarController {
14
15
  constructor(parent) {
16
+ this._state = ControllerState.None;
17
+ this._element = null;
18
+ this._prevQROpt = null;
15
19
  this._parent = parent;
16
20
  }
17
21
  /**
@@ -36,6 +40,86 @@ class PlattarController {
36
40
  }).catch(reject);
37
41
  });
38
42
  }
43
+ /**
44
+ * Decide which QR Code to render according to the qr-type attribute
45
+ * @param options
46
+ * @returns
47
+ */
48
+ startQRCode(options) {
49
+ const qrType = this.getAttribute("qr-type") || "viewer";
50
+ switch (qrType.toLowerCase()) {
51
+ case "ar":
52
+ return this.startARQRCode(options);
53
+ case "viewer":
54
+ default:
55
+ return this.startViewerQRCode(options);
56
+ }
57
+ }
58
+ /**
59
+ * Displays a QR Code that sends the user direct to AR
60
+ * @param options
61
+ * @returns
62
+ */
63
+ startARQRCode(options) {
64
+ return new Promise((accept, reject) => {
65
+ // remove the old renderer instance if any
66
+ this.removeRenderer();
67
+ const opt = options || PlattarController.DEFAULT_QR_OPTIONS;
68
+ const viewer = document.createElement("plattar-qrcode");
69
+ // required attributes with defaults for plattar-viewer node
70
+ const width = this.getAttribute("width") || "500px";
71
+ const height = this.getAttribute("height") || "500px";
72
+ viewer.setAttribute("width", width);
73
+ viewer.setAttribute("height", height);
74
+ if (opt.color) {
75
+ viewer.setAttribute("color", opt.color);
76
+ }
77
+ if (opt.margin) {
78
+ viewer.setAttribute("margin", "" + opt.margin);
79
+ }
80
+ if (opt.qrType) {
81
+ viewer.setAttribute("qr-type", opt.qrType);
82
+ }
83
+ const qrOptions = btoa(JSON.stringify(opt));
84
+ let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
85
+ const sceneID = this.getAttribute("scene-id");
86
+ const configState = this.getAttribute("config-state");
87
+ const embedType = this.getAttribute("embed-type");
88
+ const productID = this.getAttribute("product-id");
89
+ const sceneProductID = this.getAttribute("scene-product-id");
90
+ const variationID = this.getAttribute("variation-id");
91
+ const arMode = this.getAttribute("ar-mode");
92
+ if (configState) {
93
+ dst += "&config_state=" + configState;
94
+ }
95
+ if (embedType) {
96
+ dst += "&embed_type=" + embedType;
97
+ }
98
+ if (productID) {
99
+ dst += "&product_id=" + productID;
100
+ }
101
+ if (sceneProductID) {
102
+ dst += "&scene_product_id=" + sceneProductID;
103
+ }
104
+ if (variationID) {
105
+ dst += "&variation_id=" + variationID;
106
+ }
107
+ if (arMode) {
108
+ dst += "&ar_mode=" + arMode;
109
+ }
110
+ if (sceneID) {
111
+ dst += "&scene_id=" + sceneID;
112
+ }
113
+ viewer.setAttribute("url", opt.url || dst);
114
+ viewer.onload = () => {
115
+ return accept(viewer);
116
+ };
117
+ this._element = viewer;
118
+ this._state = ControllerState.QRCode;
119
+ this._prevQROpt = opt;
120
+ this.append(viewer);
121
+ });
122
+ }
39
123
  /**
40
124
  * Returns the Parent Instance
41
125
  */
@@ -4,12 +4,9 @@ import { PlattarController } from "./plattar-controller";
4
4
  * Manages an instance of the <plattar-product> HTML Element
5
5
  */
6
6
  export declare class ProductController extends PlattarController {
7
- private _state;
8
- private _element;
9
- private _prevQROpt;
10
7
  constructor(parent: HTMLElement);
11
8
  onAttributesUpdated(): void;
12
- startQRCode(options: any): Promise<HTMLElement>;
9
+ startViewerQRCode(options: any): Promise<HTMLElement>;
13
10
  startRenderer(): Promise<HTMLElement>;
14
11
  initAR(): Promise<LauncherAR>;
15
12
  removeRenderer(): boolean;
@@ -11,9 +11,6 @@ const plattar_controller_1 = require("./plattar-controller");
11
11
  class ProductController extends plattar_controller_1.PlattarController {
12
12
  constructor(parent) {
13
13
  super(parent);
14
- this._state = plattar_controller_1.ControllerState.None;
15
- this._element = null;
16
- this._prevQROpt = null;
17
14
  }
18
15
  onAttributesUpdated() {
19
16
  const state = this._state;
@@ -34,7 +31,7 @@ class ProductController extends plattar_controller_1.PlattarController {
34
31
  return;
35
32
  }
36
33
  }
37
- startQRCode(options) {
34
+ startViewerQRCode(options) {
38
35
  return new Promise((accept, reject) => {
39
36
  // remove the old renderer instance if any
40
37
  this.removeRenderer();
@@ -58,10 +55,14 @@ class ProductController extends plattar_controller_1.PlattarController {
58
55
  }
59
56
  // optional attributes
60
57
  const variationID = this.getAttribute("variation-id");
58
+ const showAR = this.getAttribute("show-ar");
61
59
  let dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
62
60
  if (variationID) {
63
61
  dst += "&variation_id=" + variationID;
64
62
  }
63
+ if (showAR) {
64
+ dst += "&show_ar=" + showAR;
65
+ }
65
66
  viewer.setAttribute("url", opt.url || dst);
66
67
  viewer.onload = () => {
67
68
  return accept(viewer);
@@ -92,9 +93,13 @@ class ProductController extends plattar_controller_1.PlattarController {
92
93
  viewer.setAttribute("product-id", productID);
93
94
  // optional attributes
94
95
  const variationID = this.getAttribute("variation-id");
96
+ const showAR = this.getAttribute("show-ar");
95
97
  if (variationID) {
96
98
  viewer.setAttribute("variation-id", variationID);
97
99
  }
100
+ if (showAR) {
101
+ viewer.setAttribute("show-ar", showAR);
102
+ }
98
103
  viewer.onload = () => {
99
104
  return accept(viewer);
100
105
  };
@@ -4,12 +4,9 @@ import { PlattarController } from "./plattar-controller";
4
4
  * Manages an instance of the <plattar-viewer> HTML Element
5
5
  */
6
6
  export declare class ViewerController extends PlattarController {
7
- private _state;
8
- private _element;
9
- private _prevQROpt;
10
7
  constructor(parent: HTMLElement);
11
8
  onAttributesUpdated(): void;
12
- startQRCode(options: any): Promise<HTMLElement>;
9
+ startViewerQRCode(options: any): Promise<HTMLElement>;
13
10
  startRenderer(): Promise<HTMLElement>;
14
11
  initAR(): Promise<LauncherAR>;
15
12
  removeRenderer(): boolean;
@@ -4,6 +4,7 @@ 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
6
  const scene_product_ar_1 = require("../../ar/scene-product-ar");
7
+ const configurator_state_1 = require("../../util/configurator-state");
7
8
  const util_1 = require("../../util/util");
8
9
  const plattar_controller_1 = require("./plattar-controller");
9
10
  /**
@@ -12,9 +13,6 @@ const plattar_controller_1 = require("./plattar-controller");
12
13
  class ViewerController extends plattar_controller_1.PlattarController {
13
14
  constructor(parent) {
14
15
  super(parent);
15
- this._state = plattar_controller_1.ControllerState.None;
16
- this._element = null;
17
- this._prevQROpt = null;
18
16
  }
19
17
  onAttributesUpdated() {
20
18
  const state = this._state;
@@ -36,7 +34,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
36
34
  return;
37
35
  }
38
36
  }
39
- startQRCode(options) {
37
+ startViewerQRCode(options) {
40
38
  return new Promise((accept, reject) => {
41
39
  // remove the old renderer instance if any
42
40
  this.removeRenderer();
@@ -62,12 +60,16 @@ class ViewerController extends plattar_controller_1.PlattarController {
62
60
  // optional attributes
63
61
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
64
62
  const variationID = this.getAttribute("variation-id");
63
+ const showAR = this.getAttribute("show-ar");
65
64
  if (productID) {
66
65
  dst += "&productId=" + productID;
67
66
  }
68
67
  if (variationID) {
69
68
  dst += "&variationId=" + variationID;
70
69
  }
70
+ if (showAR) {
71
+ dst += "&show_ar=" + showAR;
72
+ }
71
73
  viewer.setAttribute("url", opt.url || dst);
72
74
  viewer.onload = () => {
73
75
  return accept(viewer);
@@ -99,12 +101,16 @@ class ViewerController extends plattar_controller_1.PlattarController {
99
101
  // optional attributes
100
102
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
101
103
  const variationID = this.getAttribute("variation-id");
104
+ const showAR = this.getAttribute("show-ar");
102
105
  if (productID) {
103
106
  viewer.setAttribute("product-id", productID);
104
107
  }
105
108
  if (variationID) {
106
109
  viewer.setAttribute("variation-id", variationID);
107
110
  }
111
+ if (showAR) {
112
+ viewer.setAttribute("show-ar", showAR);
113
+ }
108
114
  viewer.onload = () => {
109
115
  return accept(viewer);
110
116
  };
@@ -136,11 +142,18 @@ class ViewerController extends plattar_controller_1.PlattarController {
136
142
  return product.init().then(accept).catch(reject);
137
143
  }
138
144
  const sceneID = this.getAttribute("scene-id");
139
- // otherwise, scene was set so use SceneAR
145
+ // use the first default product-variation id if available
140
146
  if (sceneID) {
141
- return reject(new Error("ViewerController.initAR() - AR mode for scene-id not yet supported, use product-id or scene-product-id"));
147
+ return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
148
+ const first = state.first();
149
+ if (first) {
150
+ const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
151
+ return sceneProductAR.init().then(accept).catch(reject);
152
+ }
153
+ return reject(new Error("ViewerController.initAR() - your scene does not contain any valid products"));
154
+ }).catch(reject);
142
155
  }
143
- return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use product-id or scene-product-id as a minimum"));
156
+ return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
144
157
  });
145
158
  }
146
159
  removeRenderer() {
@@ -4,12 +4,9 @@ import { PlattarController } from "./plattar-controller";
4
4
  * Manages an instance of the <plattar-configurator> HTML Element
5
5
  */
6
6
  export declare class VTOController extends PlattarController {
7
- private _state;
8
- private _element;
9
- private _prevQROpt;
10
7
  constructor(parent: HTMLElement);
11
8
  onAttributesUpdated(): void;
12
- startQRCode(options: any): Promise<HTMLElement>;
9
+ startViewerQRCode(options: any): Promise<HTMLElement>;
13
10
  startRenderer(): Promise<HTMLElement>;
14
11
  initAR(): Promise<LauncherAR>;
15
12
  /**
@@ -13,9 +13,6 @@ const plattar_controller_1 = require("./plattar-controller");
13
13
  class VTOController extends plattar_controller_1.PlattarController {
14
14
  constructor(parent) {
15
15
  super(parent);
16
- this._state = plattar_controller_1.ControllerState.None;
17
- this._element = null;
18
- this._prevQROpt = null;
19
16
  }
20
17
  onAttributesUpdated() {
21
18
  const state = this._state;
@@ -25,7 +22,7 @@ class VTOController extends plattar_controller_1.PlattarController {
25
22
  return;
26
23
  }
27
24
  }
28
- startQRCode(options) {
25
+ startViewerQRCode(options) {
29
26
  return new Promise((accept, reject) => {
30
27
  // remove the old renderer instance if any
31
28
  this.removeRenderer();
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.123.7";
1
+ declare const _default: "1.129.1";
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.7";
3
+ exports.default = "1.129.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.123.7",
3
+ "version": "1.129.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",
@@ -37,19 +37,19 @@
37
37
  },
38
38
  "homepage": "https://www.plattar.com",
39
39
  "dependencies": {
40
- "@plattar/plattar-analytics": "^1.117.2",
40
+ "@plattar/plattar-analytics": "^1.124.1",
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.123.1"
44
+ "@plattar/plattar-web": "^1.128.1"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/cli": "^7.17.3",
48
- "@babel/core": "^7.17.4",
49
- "@babel/preset-env": "^7.16.11",
47
+ "@babel/cli": "^7.17.10",
48
+ "@babel/core": "^7.17.10",
49
+ "@babel/preset-env": "^7.17.10",
50
50
  "browserify": "^17.0.0",
51
- "typescript": "^4.5.5",
52
- "uglify-js": "^3.15.1"
51
+ "typescript": "^4.6.4",
52
+ "uglify-js": "^3.15.4"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"