@plattar/plattar-ar-adapter 1.122.4 → 1.123.4

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.
Files changed (35) hide show
  1. package/build/es2015/plattar-ar-adapter.js +2296 -1346
  2. package/build/es2015/plattar-ar-adapter.min.js +1 -1
  3. package/build/es2019/plattar-ar-adapter.js +1218 -560
  4. package/build/es2019/plattar-ar-adapter.min.js +9 -1
  5. package/dist/ar/launcher-ar.d.ts +8 -1
  6. package/dist/ar/launcher-ar.js +12 -0
  7. package/dist/ar/model-ar.d.ts +0 -5
  8. package/dist/ar/model-ar.js +1 -12
  9. package/dist/ar/product-ar.d.ts +1 -6
  10. package/dist/ar/product-ar.js +3 -14
  11. package/dist/ar/raw-ar.d.ts +0 -5
  12. package/dist/ar/raw-ar.js +0 -12
  13. package/dist/ar/scene-ar.d.ts +21 -1
  14. package/dist/ar/scene-ar.js +148 -5
  15. package/dist/embed/controllers/configurator-controller.d.ts +17 -0
  16. package/dist/embed/controllers/configurator-controller.js +178 -0
  17. package/dist/embed/controllers/plattar-controller.d.ts +62 -0
  18. package/dist/embed/controllers/plattar-controller.js +62 -0
  19. package/dist/embed/controllers/product-controller.d.ts +17 -0
  20. package/dist/embed/controllers/product-controller.js +133 -0
  21. package/dist/embed/controllers/viewer-controller.d.ts +17 -0
  22. package/dist/embed/controllers/viewer-controller.js +147 -0
  23. package/dist/embed/controllers/vto-controller.d.ts +17 -0
  24. package/dist/embed/controllers/vto-controller.js +169 -0
  25. package/dist/embed/plattar-embed.d.ts +7 -10
  26. package/dist/embed/plattar-embed.js +51 -346
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +3 -3
  29. package/dist/util/configurator-state.d.ts +26 -0
  30. package/dist/util/configurator-state.js +92 -0
  31. package/dist/version.d.ts +1 -1
  32. package/dist/version.js +1 -1
  33. package/package.json +6 -6
  34. package/dist/ar/configurator-ar.d.ts +0 -9
  35. package/dist/ar/configurator-ar.js +0 -19
@@ -1,6 +1,13 @@
1
1
  export declare abstract class LauncherAR {
2
2
  constructor();
3
3
  abstract init(): Promise<LauncherAR>;
4
- abstract launch(): Promise<void>;
5
4
  abstract start(): void;
5
+ abstract canQuicklook(): boolean;
6
+ abstract canRealityViewer(): boolean;
7
+ abstract canSceneViewer(): boolean;
8
+ /**
9
+ * Initialise and launch with a single function call. this is mostly for convenience.
10
+ * Use .init() and .start() separately for fine-grained control
11
+ */
12
+ launch(): Promise<void>;
6
13
  }
@@ -3,5 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LauncherAR = void 0;
4
4
  class LauncherAR {
5
5
  constructor() { }
6
+ /**
7
+ * Initialise and launch with a single function call. this is mostly for convenience.
8
+ * Use .init() and .start() separately for fine-grained control
9
+ */
10
+ launch() {
11
+ return new Promise((accept, reject) => {
12
+ this.init().then((value) => {
13
+ value.start();
14
+ return accept();
15
+ }).catch(reject);
16
+ });
17
+ }
6
18
  }
7
19
  exports.LauncherAR = LauncherAR;
@@ -17,11 +17,6 @@ export declare class ModelAR extends LauncherAR {
17
17
  * cannot be performed.
18
18
  */
19
19
  init(): Promise<LauncherAR>;
20
- /**
21
- * Initialise and launch with a single function call. this is mostly for convenience.
22
- * Use .init() and .start() separately for fine-grained control
23
- */
24
- launch(): Promise<void>;
25
20
  /**
26
21
  * Launches the internal AR instance using an appropriate version of AR Viewers
27
22
  */
@@ -35,6 +35,7 @@ class ModelAR extends launcher_ar_1.LauncherAR {
35
35
  if (project) {
36
36
  analytics = new plattar_analytics_1.Analytics(project.id);
37
37
  analytics.origin = plattar_api_1.Server.location().type;
38
+ analytics.data.push("type", "model-ar");
38
39
  analytics.data.push("applicationId", project.id);
39
40
  analytics.data.push("applicationTitle", project.attributes.title);
40
41
  analytics.data.push("modelId", model.id);
@@ -89,18 +90,6 @@ class ModelAR extends launcher_ar_1.LauncherAR {
89
90
  }).catch(reject);
90
91
  });
91
92
  }
92
- /**
93
- * Initialise and launch with a single function call. this is mostly for convenience.
94
- * Use .init() and .start() separately for fine-grained control
95
- */
96
- launch() {
97
- return new Promise((accept, reject) => {
98
- this.init().then((value) => {
99
- value.start();
100
- return accept();
101
- }).catch(reject);
102
- });
103
- }
104
93
  /**
105
94
  * Launches the internal AR instance using an appropriate version of AR Viewers
106
95
  */
@@ -10,7 +10,7 @@ export declare class ProductAR extends LauncherAR {
10
10
  constructor(productID?: string | undefined | null, variationID?: string | undefined | null);
11
11
  get productID(): string;
12
12
  get variationID(): string;
13
- private _setupAnalytics;
13
+ private _SetupAnalytics;
14
14
  /**
15
15
  * Initialise the ProductAR instance. This returns a Promise that resolves
16
16
  * successfully if initialisation is successful, otherwise it will fail.
@@ -19,11 +19,6 @@ export declare class ProductAR extends LauncherAR {
19
19
  * cannot be performed.
20
20
  */
21
21
  init(): Promise<LauncherAR>;
22
- /**
23
- * Initialise and launch with a single function call. this is mostly for convenience.
24
- * Use .init() and .start() separately for fine-grained control
25
- */
26
- launch(): Promise<void>;
27
22
  /**
28
23
  * Launches the internal AR instance using an appropriate version of AR Viewers
29
24
  */
@@ -32,7 +32,7 @@ class ProductAR extends launcher_ar_1.LauncherAR {
32
32
  get variationID() {
33
33
  return this._variationID;
34
34
  }
35
- _setupAnalytics(product, variation) {
35
+ _SetupAnalytics(product, variation) {
36
36
  let analytics = null;
37
37
  const scene = product.relationships.find(plattar_api_1.Scene);
38
38
  // setup scene stuff (if any)
@@ -40,6 +40,7 @@ class ProductAR extends launcher_ar_1.LauncherAR {
40
40
  analytics = new plattar_analytics_1.Analytics(scene.attributes.application_id);
41
41
  analytics.origin = plattar_api_1.Server.location().type;
42
42
  this._analytics = analytics;
43
+ analytics.data.push("type", "product-ar");
43
44
  analytics.data.push("sceneId", scene.id);
44
45
  analytics.data.push("sceneTitle", scene.attributes.title);
45
46
  const application = scene.relationships.find(plattar_api_1.Project);
@@ -100,7 +101,7 @@ class ProductAR extends launcher_ar_1.LauncherAR {
100
101
  if (!model) {
101
102
  return reject(new Error("ProductAR.init() - cannot proceed as ModelFile for selected variation is corrupt"));
102
103
  }
103
- this._setupAnalytics(product, variation);
104
+ this._SetupAnalytics(product, variation);
104
105
  // we need to define our AR module here
105
106
  // we are in Safari/Quicklook mode here
106
107
  if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
@@ -131,18 +132,6 @@ class ProductAR extends launcher_ar_1.LauncherAR {
131
132
  }).catch(reject);
132
133
  });
133
134
  }
134
- /**
135
- * Initialise and launch with a single function call. this is mostly for convenience.
136
- * Use .init() and .start() separately for fine-grained control
137
- */
138
- launch() {
139
- return new Promise((accept, reject) => {
140
- this.init().then((value) => {
141
- value.start();
142
- return accept();
143
- }).catch(reject);
144
- });
145
- }
146
135
  /**
147
136
  * Launches the internal AR instance using an appropriate version of AR Viewers
148
137
  */
@@ -15,11 +15,6 @@ export declare class RawAR extends LauncherAR {
15
15
  * cannot be performed.
16
16
  */
17
17
  init(): Promise<LauncherAR>;
18
- /**
19
- * Initialise and launch with a single function call. this is mostly for convenience.
20
- * Use .init() and .start() separately for fine-grained control
21
- */
22
- launch(): Promise<void>;
23
18
  /**
24
19
  * Launches the internal AR instance using an appropriate version of AR Viewers
25
20
  */
package/dist/ar/raw-ar.js CHANGED
@@ -75,18 +75,6 @@ class RawAR extends launcher_ar_1.LauncherAR {
75
75
  return reject(new Error("RawAR.init() - could not initialise AR correctly, check values"));
76
76
  });
77
77
  }
78
- /**
79
- * Initialise and launch with a single function call. this is mostly for convenience.
80
- * Use .init() and .start() separately for fine-grained control
81
- */
82
- launch() {
83
- return new Promise((accept, reject) => {
84
- this.init().then((value) => {
85
- value.start();
86
- return accept();
87
- }).catch(reject);
88
- });
89
- }
90
78
  /**
91
79
  * Launches the internal AR instance using an appropriate version of AR Viewers
92
80
  */
@@ -3,7 +3,27 @@ import { LauncherAR } from "./launcher-ar";
3
3
  * Performs AR functionality related to Plattar Scenes
4
4
  */
5
5
  export declare class SceneAR extends LauncherAR {
6
+ private _analytics;
7
+ private readonly _sceneID;
8
+ private _ar;
9
+ constructor(sceneID?: string | undefined | null);
10
+ get sceneID(): string;
11
+ private _SetupAnalytics;
12
+ /**
13
+ * Composes a Scene into an AR Model (remote operation) that can be used to launch
14
+ * an AR File
15
+ */
16
+ private _ComposeScene;
17
+ /**
18
+ * Initialise the SceneAR instance. This returns a Promise that resolves
19
+ * successfully if initialisation is successful, otherwise it will fail.
20
+ *
21
+ * filure can occur for a number of reasons but it generally means that AR
22
+ * cannot be performed.
23
+ */
6
24
  init(): Promise<LauncherAR>;
7
- launch(): Promise<void>;
8
25
  start(): void;
26
+ canQuicklook(): boolean;
27
+ canRealityViewer(): boolean;
28
+ canSceneViewer(): boolean;
9
29
  }
@@ -1,19 +1,162 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.SceneAR = void 0;
7
+ const plattar_analytics_1 = require("@plattar/plattar-analytics");
8
+ const plattar_api_1 = require("@plattar/plattar-api");
9
+ const plattar_services_1 = require("@plattar/plattar-services");
10
+ const util_1 = require("../util/util");
11
+ const quicklook_viewer_1 = __importDefault(require("../viewers/quicklook-viewer"));
12
+ const reality_viewer_1 = __importDefault(require("../viewers/reality-viewer"));
13
+ const scene_viewer_1 = __importDefault(require("../viewers/scene-viewer"));
4
14
  const launcher_ar_1 = require("./launcher-ar");
5
15
  /**
6
16
  * Performs AR functionality related to Plattar Scenes
7
17
  */
8
18
  class SceneAR extends launcher_ar_1.LauncherAR {
9
- init() {
10
- throw new Error("Method not implemented.");
19
+ constructor(sceneID = null) {
20
+ super();
21
+ // analytics instance
22
+ this._analytics = null;
23
+ if (!sceneID) {
24
+ throw new Error("SceneAR.constructor(sceneID) - sceneID must be defined");
25
+ }
26
+ this._sceneID = sceneID;
27
+ this._ar = null;
28
+ }
29
+ get sceneID() {
30
+ return this._sceneID;
31
+ }
32
+ _SetupAnalytics(scene) {
33
+ let analytics = null;
34
+ // setup scene stuff (if any)
35
+ if (scene) {
36
+ analytics = new plattar_analytics_1.Analytics(scene.attributes.application_id);
37
+ analytics.origin = plattar_api_1.Server.location().type;
38
+ this._analytics = analytics;
39
+ analytics.data.push("type", "scene-ar");
40
+ analytics.data.push("sceneId", scene.id);
41
+ analytics.data.push("sceneTitle", scene.attributes.title);
42
+ const application = scene.relationships.find(plattar_api_1.Project);
43
+ // setup application stuff (if any)
44
+ if (application) {
45
+ analytics.data.push("applicationId", application.id);
46
+ analytics.data.push("applicationTitle", application.attributes.title);
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Composes a Scene into an AR Model (remote operation) that can be used to launch
52
+ * an AR File
53
+ */
54
+ _ComposeScene(scene, output) {
55
+ return new Promise((accept, reject) => {
56
+ const sceneProducts = scene.relationships.filter(plattar_api_1.SceneProduct);
57
+ // nothing to do if no AR components can be found
58
+ if (sceneProducts.length <= 0) {
59
+ return reject(new Error("SceneAR.ComposeScene() - cannot proceed as scene does not contain AR components"));
60
+ }
61
+ // define our configurator
62
+ const configurator = new plattar_services_1.Configurator();
63
+ configurator.server = plattar_api_1.Server.location().type;
64
+ configurator.output = output;
65
+ // add out scene models
66
+ sceneProducts.forEach((sceneProduct) => {
67
+ const product = sceneProduct.relationships.find(plattar_api_1.Product);
68
+ if (product && product.attributes.product_variation_id) {
69
+ configurator.addSceneProduct(sceneProduct.id, product.attributes.product_variation_id);
70
+ }
71
+ });
72
+ return configurator.get().then((result) => {
73
+ accept(result.filename);
74
+ }).catch(reject);
75
+ });
11
76
  }
12
- launch() {
13
- throw new Error("Method not implemented.");
77
+ /**
78
+ * Initialise the SceneAR instance. This returns a Promise that resolves
79
+ * successfully if initialisation is successful, otherwise it will fail.
80
+ *
81
+ * filure can occur for a number of reasons but it generally means that AR
82
+ * cannot be performed.
83
+ */
84
+ init() {
85
+ return new Promise((accept, reject) => {
86
+ if (!util_1.Util.canAugment()) {
87
+ return reject(new Error("SceneAR.init() - cannot proceed as AR not available in context"));
88
+ }
89
+ const scene = new plattar_api_1.Scene(this.sceneID);
90
+ scene.include(plattar_api_1.Project);
91
+ scene.include(plattar_api_1.SceneProduct);
92
+ scene.include(plattar_api_1.SceneProduct.include(plattar_api_1.Product));
93
+ scene.get().then((scene) => {
94
+ this._SetupAnalytics(scene);
95
+ const sceneOpt = scene.attributes.custom_json || {};
96
+ // we need to define our AR module here
97
+ // we are in Safari/Quicklook mode here
98
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
99
+ // we need to launch a VTO experience here
100
+ // VTO requires Reality Support
101
+ if (sceneOpt.anchor === "face") {
102
+ if (util_1.Util.canRealityViewer()) {
103
+ return this._ComposeScene(scene, "vto").then((modelUrl) => {
104
+ this._ar = new reality_viewer_1.default();
105
+ this._ar.modelUrl = modelUrl;
106
+ return accept(this);
107
+ }).catch(reject);
108
+ }
109
+ else {
110
+ return reject(new Error("SceneAR.init() - cannot proceed as VTO AR requires Reality Viewer support"));
111
+ }
112
+ }
113
+ // otherwise, load the USDZ stuff second if available
114
+ if (util_1.Util.canQuicklook()) {
115
+ return this._ComposeScene(scene, "usdz").then((modelUrl) => {
116
+ this._ar = new quicklook_viewer_1.default();
117
+ this._ar.modelUrl = modelUrl;
118
+ return accept(this);
119
+ }).catch(reject);
120
+ }
121
+ return reject(new Error("SceneAR.init() - cannot proceed as IOS device does not support AR Mode"));
122
+ }
123
+ // check android
124
+ if (util_1.Util.canSceneViewer()) {
125
+ return this._ComposeScene(scene, "glb").then((modelUrl) => {
126
+ this._ar = new scene_viewer_1.default();
127
+ this._ar.modelUrl = modelUrl;
128
+ return accept(this);
129
+ }).catch(reject);
130
+ }
131
+ // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
132
+ // earlier in the process
133
+ return reject(new Error("SceneAR.init() - could not initialise AR correctly, check values"));
134
+ }).catch(reject);
135
+ });
14
136
  }
15
137
  start() {
16
- throw new Error("Method not implemented.");
138
+ if (!this._ar) {
139
+ throw new Error("SceneAR.start() - cannot proceed as AR instance is null");
140
+ }
141
+ const analytics = this._analytics;
142
+ if (analytics) {
143
+ analytics.data.push("device", this._ar.device);
144
+ analytics.data.push("eventCategory", this._ar.nodeType);
145
+ analytics.data.push("eventAction", "Start Scene Augment");
146
+ analytics.write();
147
+ analytics.startRecordEngagement();
148
+ }
149
+ // this was initialised via the init() function
150
+ this._ar.start();
151
+ }
152
+ canQuicklook() {
153
+ return this._ar && this._ar.nodeType === "Quick Look" ? true : false;
154
+ }
155
+ canRealityViewer() {
156
+ return this._ar && this._ar.nodeType === "Reality Viewer" ? true : false;
157
+ }
158
+ canSceneViewer() {
159
+ return this._ar && this._ar.nodeType === "Scene Viewer" ? true : false;
17
160
  }
18
161
  }
19
162
  exports.SceneAR = SceneAR;
@@ -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 ConfiguratorController 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,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfiguratorController = void 0;
4
+ const plattar_api_1 = require("@plattar/plattar-api");
5
+ const plattar_services_1 = require("@plattar/plattar-services");
6
+ const raw_ar_1 = require("../../ar/raw-ar");
7
+ const util_1 = require("../../util/util");
8
+ const plattar_controller_1 = require("./plattar-controller");
9
+ /**
10
+ * Manages an instance of the <plattar-configurator> HTML Element
11
+ */
12
+ class ConfiguratorController extends plattar_controller_1.PlattarController {
13
+ constructor(parent) {
14
+ super(parent);
15
+ this._state = plattar_controller_1.ControllerState.None;
16
+ this._element = null;
17
+ this._prevQROpt = null;
18
+ }
19
+ onAttributesUpdated() {
20
+ const state = this._state;
21
+ // re-render the QR Code when attributes have changed
22
+ if (state === plattar_controller_1.ControllerState.QRCode) {
23
+ this.startQRCode(this._prevQROpt);
24
+ return;
25
+ }
26
+ }
27
+ startQRCode(options) {
28
+ return new Promise((accept, reject) => {
29
+ // remove the old renderer instance if any
30
+ this.removeRenderer();
31
+ const sceneID = this.getAttribute("scene-id");
32
+ if (sceneID) {
33
+ const opt = options || plattar_controller_1.PlattarController.DEFAULT_QR_OPTIONS;
34
+ const viewer = document.createElement("plattar-qrcode");
35
+ // required attributes with defaults for plattar-viewer node
36
+ const width = this.getAttribute("width") || "500px";
37
+ const height = this.getAttribute("height") || "500px";
38
+ viewer.setAttribute("width", width);
39
+ viewer.setAttribute("height", height);
40
+ if (opt.color) {
41
+ viewer.setAttribute("color", opt.color);
42
+ }
43
+ if (opt.margin) {
44
+ viewer.setAttribute("margin", "" + opt.margin);
45
+ }
46
+ if (opt.qrType) {
47
+ viewer.setAttribute("qr-type", opt.qrType);
48
+ }
49
+ let dst = plattar_api_1.Server.location().base + "renderer/configurator.html?scene_id=" + sceneID;
50
+ // optional attributes
51
+ const configState = this.getAttribute("config-state");
52
+ const showAR = this.getAttribute("show-ar");
53
+ if (configState) {
54
+ dst += "&config_state=" + configState;
55
+ }
56
+ if (showAR) {
57
+ dst += "&show_ar=" + showAR;
58
+ }
59
+ viewer.setAttribute("url", opt.url || dst);
60
+ viewer.onload = () => {
61
+ return accept(viewer);
62
+ };
63
+ this.append(viewer);
64
+ this._element = viewer;
65
+ this._state = plattar_controller_1.ControllerState.QRCode;
66
+ this._prevQROpt = opt;
67
+ return;
68
+ }
69
+ return reject(new Error("ConfiguratorController.startQRCode() - minimum required attributes not set, use scene-id as a minimum"));
70
+ });
71
+ }
72
+ startRenderer() {
73
+ return new Promise((accept, reject) => {
74
+ // remove the old renderer instance if any
75
+ this.removeRenderer();
76
+ const sceneID = this.getAttribute("scene-id");
77
+ if (sceneID) {
78
+ // required attributes with defaults for plattar-configurator node
79
+ const width = this.getAttribute("width") || "500px";
80
+ const height = this.getAttribute("height") || "500px";
81
+ const server = this.getAttribute("server") || "production";
82
+ const viewer = document.createElement("plattar-configurator");
83
+ viewer.setAttribute("width", width);
84
+ viewer.setAttribute("height", height);
85
+ viewer.setAttribute("server", server);
86
+ viewer.setAttribute("scene-id", sceneID);
87
+ // optional attributes
88
+ const configState = this.getAttribute("config-state");
89
+ const showAR = this.getAttribute("show-ar");
90
+ if (configState) {
91
+ viewer.setAttribute("config-state", configState);
92
+ }
93
+ if (showAR) {
94
+ viewer.setAttribute("show-ar", showAR);
95
+ }
96
+ viewer.onload = () => {
97
+ return accept(viewer);
98
+ };
99
+ this.append(viewer);
100
+ this._element = viewer;
101
+ this._state = plattar_controller_1.ControllerState.Renderer;
102
+ return;
103
+ }
104
+ return reject(new Error("ConfiguratorController.startRenderer() - minimum required attributes not set, use scene-id as a minimum"));
105
+ });
106
+ }
107
+ initAR() {
108
+ return new Promise((accept, reject) => {
109
+ if (!util_1.Util.canAugment()) {
110
+ return reject(new Error("ConfiguratorController.initAR() - cannot proceed as AR not available in context"));
111
+ }
112
+ // if scene ID is available and the state is a configurator viewer
113
+ // we can use the real-time configurator state to launch the AR view
114
+ const viewer = this.element;
115
+ const sceneID = this.getAttribute("scene-id");
116
+ if (viewer && sceneID) {
117
+ let output = "glb";
118
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
119
+ output = "usdz";
120
+ }
121
+ return viewer.messenger.getARFile(output).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
+ try {
131
+ const decodedb64State = atob(configState);
132
+ const state = JSON.parse(decodedb64State);
133
+ if (state.meta) {
134
+ const sceneProductIndex = state.meta.scene_product_index || 0;
135
+ const variationIndex = state.meta.product_variation_index || 1;
136
+ const states = state.states || [];
137
+ if (states.length > 0) {
138
+ const configurator = new plattar_services_1.Configurator();
139
+ states.forEach((productState) => {
140
+ configurator.addSceneProduct(productState[sceneProductIndex], productState[variationIndex]);
141
+ });
142
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
143
+ configurator.output = "usdz";
144
+ }
145
+ if (util_1.Util.canSceneViewer()) {
146
+ configurator.output = "glb";
147
+ }
148
+ const server = this.getAttribute("server") || "production";
149
+ configurator.server = server;
150
+ return configurator.get().then((result) => {
151
+ const rawAR = new raw_ar_1.RawAR(result.filename);
152
+ rawAR.init().then(accept).catch(reject);
153
+ }).catch(reject);
154
+ }
155
+ return reject(new Error("ConfiguratorController.initAR() - invalid config-state does not have any product states"));
156
+ }
157
+ return reject(new Error("ConfiguratorController.initAR() - invalid config-state for configurator"));
158
+ }
159
+ catch (err) {
160
+ return reject(err);
161
+ }
162
+ }
163
+ return reject(new Error("ConfiguratorController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
164
+ });
165
+ }
166
+ removeRenderer() {
167
+ if (this._element) {
168
+ this._element.remove();
169
+ this._element = null;
170
+ return true;
171
+ }
172
+ return false;
173
+ }
174
+ get element() {
175
+ return this._element;
176
+ }
177
+ }
178
+ exports.ConfiguratorController = ConfiguratorController;
@@ -0,0 +1,62 @@
1
+ import { LauncherAR } from "../../ar/launcher-ar";
2
+ export declare enum ControllerState {
3
+ None = 0,
4
+ Renderer = 1,
5
+ QRCode = 2
6
+ }
7
+ /**
8
+ * All Plattar Controllers are derived from the same interface
9
+ */
10
+ export declare abstract class PlattarController {
11
+ /**
12
+ * Default QR Code rendering options
13
+ */
14
+ static get DEFAULT_QR_OPTIONS(): any;
15
+ private readonly _parent;
16
+ constructor(parent: HTMLElement);
17
+ /**
18
+ * Called by the parent when a HTML Attribute has changed and the controller
19
+ * requires an update
20
+ */
21
+ 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
+ /**
28
+ * Start the underlying Plattar Renderer for this Controller
29
+ */
30
+ abstract startRenderer(): Promise<HTMLElement>;
31
+ /**
32
+ * Initialise and start AR mode if available
33
+ */
34
+ startAR(): Promise<void>;
35
+ /**
36
+ * Initialise and return a launcher that can be used to start AR
37
+ */
38
+ abstract initAR(): Promise<LauncherAR>;
39
+ /**
40
+ * Removes the currently active renderer view from the DOM
41
+ */
42
+ abstract removeRenderer(): boolean;
43
+ /**
44
+ * Get the underlying renderer component (if any)
45
+ */
46
+ abstract get element(): HTMLElement | null;
47
+ /**
48
+ * Returns the Parent Instance
49
+ */
50
+ get parent(): HTMLElement;
51
+ /**
52
+ * Returns the specified attribute from the parent
53
+ * @param attribute - The name of thhe attribute
54
+ * @returns - The attribute value or null
55
+ */
56
+ getAttribute(attribute: string): string | null;
57
+ /**
58
+ * Appends the provided element into the shadow-root of the parent element
59
+ * @param element - The element to append
60
+ */
61
+ append(element: HTMLElement): void;
62
+ }