@plattar/plattar-ar-adapter 1.128.1 → 1.130.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.
@@ -1,4 +1,8 @@
1
+ export interface LauncherAROptions {
2
+ anchor: "horizontal" | "vertical" | "vto" | "horizontal_vertical";
3
+ }
1
4
  export declare abstract class LauncherAR {
5
+ private readonly _opt;
2
6
  constructor();
3
7
  abstract init(): Promise<LauncherAR>;
4
8
  abstract start(): void;
@@ -10,4 +14,8 @@ export declare abstract class LauncherAR {
10
14
  * Use .init() and .start() separately for fine-grained control
11
15
  */
12
16
  launch(): Promise<void>;
17
+ /**
18
+ * AR Options used for launching AR
19
+ */
20
+ get options(): LauncherAROptions;
13
21
  }
@@ -2,7 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LauncherAR = void 0;
4
4
  class LauncherAR {
5
- constructor() { }
5
+ constructor() {
6
+ this._opt = {
7
+ anchor: "horizontal_vertical"
8
+ };
9
+ }
6
10
  /**
7
11
  * Initialise and launch with a single function call. this is mostly for convenience.
8
12
  * Use .init() and .start() separately for fine-grained control
@@ -15,5 +19,11 @@ class LauncherAR {
15
19
  }).catch(reject);
16
20
  });
17
21
  }
22
+ /**
23
+ * AR Options used for launching AR
24
+ */
25
+ get options() {
26
+ return this._opt;
27
+ }
18
28
  }
19
29
  exports.LauncherAR = LauncherAR;
@@ -80,8 +80,10 @@ class ModelAR extends launcher_ar_1.LauncherAR {
80
80
  }
81
81
  // check android
82
82
  if (util_1.Util.canSceneViewer()) {
83
- this._ar = new scene_viewer_1.default();
84
- this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
83
+ const arviewer = new scene_viewer_1.default();
84
+ arviewer.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
85
+ arviewer.isVertical = this.options.anchor === "vertical" ? true : false;
86
+ this._ar = arviewer;
85
87
  return accept(this);
86
88
  }
87
89
  // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
@@ -122,8 +122,17 @@ class ProductAR extends launcher_ar_1.LauncherAR {
122
122
  }
123
123
  // check android
124
124
  if (util_1.Util.canSceneViewer()) {
125
- this._ar = new scene_viewer_1.default();
126
- this._ar.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
125
+ const arviewer = new scene_viewer_1.default();
126
+ arviewer.modelUrl = plattar_api_1.Server.location().cdn + model.attributes.path + model.attributes.original_filename;
127
+ arviewer.isVertical = this.options.anchor === "vertical" ? true : false;
128
+ const scene = product.relationships.find(plattar_api_1.Scene);
129
+ if (scene) {
130
+ const sceneOpt = scene.attributes.custom_json || {};
131
+ if (sceneOpt.anchor === "vertical") {
132
+ arviewer.isVertical = true;
133
+ }
134
+ }
135
+ this._ar = arviewer;
127
136
  return accept(this);
128
137
  }
129
138
  // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
package/dist/ar/raw-ar.js CHANGED
@@ -64,8 +64,10 @@ class RawAR extends launcher_ar_1.LauncherAR {
64
64
  // check android
65
65
  if (util_1.Util.canSceneViewer()) {
66
66
  if (lowerLoc.endsWith("glb") || lowerLoc.endsWith("gltf")) {
67
- this._ar = new scene_viewer_1.default();
68
- this._ar.modelUrl = modelLocation;
67
+ const arviewer = new scene_viewer_1.default();
68
+ arviewer.modelUrl = modelLocation;
69
+ arviewer.isVertical = this.options.anchor === "vertical" ? true : false;
70
+ this._ar = arviewer;
69
71
  return accept(this);
70
72
  }
71
73
  return reject(new Error("RawAR.init() - cannot proceed as model is not a .glb or .gltf file"));
@@ -123,8 +123,13 @@ class SceneAR extends launcher_ar_1.LauncherAR {
123
123
  // check android
124
124
  if (util_1.Util.canSceneViewer()) {
125
125
  return this._ComposeScene(scene, "glb").then((modelUrl) => {
126
- this._ar = new scene_viewer_1.default();
127
- this._ar.modelUrl = modelUrl;
126
+ const arviewer = new scene_viewer_1.default();
127
+ arviewer.modelUrl = modelUrl;
128
+ arviewer.isVertical = this.options.anchor === "vertical" ? true : false;
129
+ if (sceneOpt.anchor === "vertical") {
130
+ arviewer.isVertical = true;
131
+ }
132
+ this._ar = arviewer;
128
133
  return accept(this);
129
134
  }).catch(reject);
130
135
  }
@@ -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();
@@ -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;
@@ -3,8 +3,8 @@ 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
- const configurator_state_1 = require("../../util/configurator-state");
8
8
  const util_1 = require("../../util/util");
9
9
  const plattar_controller_1 = require("./plattar-controller");
10
10
  /**
@@ -13,9 +13,6 @@ const plattar_controller_1 = require("./plattar-controller");
13
13
  class ViewerController 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;
@@ -37,7 +34,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
37
34
  return;
38
35
  }
39
36
  }
40
- startQRCode(options) {
37
+ startViewerQRCode(options) {
41
38
  return new Promise((accept, reject) => {
42
39
  // remove the old renderer instance if any
43
40
  this.removeRenderer();
@@ -145,16 +142,11 @@ class ViewerController extends plattar_controller_1.PlattarController {
145
142
  return product.init().then(accept).catch(reject);
146
143
  }
147
144
  const sceneID = this.getAttribute("scene-id");
148
- // use the first default product-variation id if available
145
+ // fallback to using default SceneAR implementation
149
146
  if (sceneID) {
150
- return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
151
- const first = state.first();
152
- if (first) {
153
- const sceneProductAR = new scene_product_ar_1.SceneProductAR(first.scene_product_id, first.product_variation_id);
154
- return sceneProductAR.init().then(accept).catch(reject);
155
- }
156
- return reject(new Error("ViewerController.initAR() - your scene does not contain any valid products"));
157
- }).catch(reject);
147
+ const sceneAR = new scene_ar_1.SceneAR(sceneID);
148
+ sceneAR.init().then(accept).catch(reject);
149
+ return;
158
150
  }
159
151
  return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
160
152
  });
@@ -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.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * as PlattarWeb from "@plattar/plattar-web";
2
2
  export * as PlattarQRCode from "@plattar/plattar-qrcode";
3
3
  export * as version from "./version";
4
+ export { LauncherAR } from "./ar/launcher-ar";
5
+ export { LauncherAROptions } from "./ar/launcher-ar";
4
6
  export { ProductAR } from "./ar/product-ar";
5
7
  export { SceneProductAR } from "./ar/scene-product-ar";
6
8
  export { SceneAR } from "./ar/scene-ar";
package/dist/index.js CHANGED
@@ -26,10 +26,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.ConfiguratorState = exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.SceneProductAR = exports.ProductAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
29
+ exports.ConfiguratorState = exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.SceneProductAR = exports.ProductAR = exports.LauncherAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
30
30
  exports.PlattarWeb = __importStar(require("@plattar/plattar-web"));
31
31
  exports.PlattarQRCode = __importStar(require("@plattar/plattar-qrcode"));
32
32
  exports.version = __importStar(require("./version"));
33
+ var launcher_ar_1 = require("./ar/launcher-ar");
34
+ Object.defineProperty(exports, "LauncherAR", { enumerable: true, get: function () { return launcher_ar_1.LauncherAR; } });
33
35
  var product_ar_1 = require("./ar/product-ar");
34
36
  Object.defineProperty(exports, "ProductAR", { enumerable: true, get: function () { return product_ar_1.ProductAR; } });
35
37
  var scene_product_ar_1 = require("./ar/scene-product-ar");
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.128.1";
1
+ declare const _default: "1.130.2";
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.128.1";
3
+ exports.default = "1.130.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.128.1",
3
+ "version": "1.130.2",
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,15 +41,15 @@
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.128.1"
44
+ "@plattar/plattar-web": "^1.129.1"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/cli": "^7.17.6",
48
- "@babel/core": "^7.17.9",
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.6.3",
52
- "uglify-js": "^3.15.4"
51
+ "typescript": "^4.6.4",
52
+ "uglify-js": "^3.15.5"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"