@plattar/plattar-ar-adapter 1.120.2 → 1.122.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.
@@ -0,0 +1,30 @@
1
+ import { LauncherAR } from "./launcher-ar";
2
+ /**
3
+ * Allows launching AR Experiences provided a single remote 3D Model file
4
+ */
5
+ export declare class RawAR extends LauncherAR {
6
+ private readonly _modelLocation;
7
+ private _ar;
8
+ constructor(modelLocation?: string | undefined | null);
9
+ get modelLocation(): string;
10
+ /**
11
+ * Initialise the RawAR instance. This returns a Promise that resolves
12
+ * successfully if initialisation is successful, otherwise it will fail.
13
+ *
14
+ * filure can occur for a number of reasons but it generally means that AR
15
+ * cannot be performed.
16
+ */
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
+ /**
24
+ * Launches the internal AR instance using an appropriate version of AR Viewers
25
+ */
26
+ start(): void;
27
+ canQuicklook(): boolean;
28
+ canRealityViewer(): boolean;
29
+ canSceneViewer(): boolean;
30
+ }
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RawAR = void 0;
7
+ const util_1 = require("../util/util");
8
+ const quicklook_viewer_1 = __importDefault(require("../viewers/quicklook-viewer"));
9
+ const reality_viewer_1 = __importDefault(require("../viewers/reality-viewer"));
10
+ const scene_viewer_1 = __importDefault(require("../viewers/scene-viewer"));
11
+ const launcher_ar_1 = require("./launcher-ar");
12
+ /**
13
+ * Allows launching AR Experiences provided a single remote 3D Model file
14
+ */
15
+ class RawAR extends launcher_ar_1.LauncherAR {
16
+ constructor(modelLocation = null) {
17
+ super();
18
+ if (!modelLocation) {
19
+ throw new Error("RawAR.constructor(modelLocation) - modelLocation must be defined");
20
+ }
21
+ const lowerLoc = modelLocation.toLowerCase();
22
+ if (lowerLoc.endsWith("usdz") || lowerLoc.endsWith("glb") || lowerLoc.endsWith("gltf") || lowerLoc.endsWith("reality")) {
23
+ this._modelLocation = modelLocation;
24
+ this._ar = null;
25
+ }
26
+ else {
27
+ throw new Error("RawAR.constructor(modelLocation) - modelLocation must be one of gltf, glb, usdz or reality");
28
+ }
29
+ }
30
+ get modelLocation() {
31
+ return this._modelLocation;
32
+ }
33
+ /**
34
+ * Initialise the RawAR instance. This returns a Promise that resolves
35
+ * successfully if initialisation is successful, otherwise it will fail.
36
+ *
37
+ * filure can occur for a number of reasons but it generally means that AR
38
+ * cannot be performed.
39
+ */
40
+ init() {
41
+ return new Promise((accept, reject) => {
42
+ if (!util_1.Util.canAugment()) {
43
+ return reject(new Error("RawAR.init() - cannot proceed as AR not available in context"));
44
+ }
45
+ const modelLocation = this._modelLocation;
46
+ const lowerLoc = modelLocation.toLowerCase();
47
+ // we need to define our AR module here
48
+ // we are in Safari/Quicklook mode here
49
+ if (util_1.Util.isSafari() || util_1.Util.isChromeOnIOS()) {
50
+ // load the reality experience if dealing with reality file
51
+ if (lowerLoc.endsWith("reality") && util_1.Util.canRealityViewer()) {
52
+ this._ar = new reality_viewer_1.default();
53
+ this._ar.modelUrl = modelLocation;
54
+ return accept(this);
55
+ }
56
+ // load the usdz experience if dealing with usdz file
57
+ if (lowerLoc.endsWith("usdz") && util_1.Util.canQuicklook()) {
58
+ this._ar = new quicklook_viewer_1.default();
59
+ this._ar.modelUrl = modelLocation;
60
+ return accept(this);
61
+ }
62
+ return reject(new Error("RawAR.init() - cannot proceed as model is not a .usdz or .reality file"));
63
+ }
64
+ // check android
65
+ if (util_1.Util.canSceneViewer()) {
66
+ if (lowerLoc.endsWith("glb") || lowerLoc.endsWith("gltf")) {
67
+ this._ar = new scene_viewer_1.default();
68
+ this._ar.modelUrl = modelLocation;
69
+ return accept(this);
70
+ }
71
+ return reject(new Error("RawAR.init() - cannot proceed as model is not a .glb or .gltf file"));
72
+ }
73
+ // otherwise, we didn't have AR available - it should never really reach this stage as this should be caught
74
+ // earlier in the process
75
+ return reject(new Error("RawAR.init() - could not initialise AR correctly, check values"));
76
+ });
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
+ /**
91
+ * Launches the internal AR instance using an appropriate version of AR Viewers
92
+ */
93
+ start() {
94
+ if (!this._ar) {
95
+ throw new Error("RawAR.start() - cannot proceed as AR instance is null");
96
+ }
97
+ // this was initialised via the init() function
98
+ this._ar.start();
99
+ }
100
+ canQuicklook() {
101
+ return this._ar && this._ar.nodeType === "Quick Look" ? true : false;
102
+ }
103
+ canRealityViewer() {
104
+ return this._ar && this._ar.nodeType === "Reality Viewer" ? true : false;
105
+ }
106
+ canSceneViewer() {
107
+ return this._ar && this._ar.nodeType === "Scene Viewer" ? true : false;
108
+ }
109
+ }
110
+ exports.RawAR = RawAR;
@@ -4,6 +4,8 @@ import { LauncherAR } from "../ar/launcher-ar";
4
4
  * of Plattar related content
5
5
  */
6
6
  export default class PlattarEmbed extends HTMLElement {
7
+ private _currentState;
8
+ private _qrCodeOptions;
7
9
  private _sceneID;
8
10
  private _productID;
9
11
  private _variationID;
@@ -19,4 +21,9 @@ export default class PlattarEmbed extends HTMLElement {
19
21
  startAR(): Promise<void>;
20
22
  startViewer(): Promise<HTMLElement>;
21
23
  startQRCode(options?: any | undefined | null): Promise<HTMLElement>;
24
+ /**
25
+ * This is called by the observer if any of the embed attributes have changed
26
+ * based on the state of the embed, we update the internal structure accordingly
27
+ */
28
+ private _OnAttributesUpdated;
22
29
  }
@@ -2,6 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const plattar_api_1 = require("@plattar/plattar-api");
4
4
  const product_ar_1 = require("../ar/product-ar");
5
+ /**
6
+ * This tracks the current state of the Embed
7
+ */
8
+ var EmbedState;
9
+ (function (EmbedState) {
10
+ EmbedState[EmbedState["None"] = 0] = "None";
11
+ EmbedState[EmbedState["SceneViewer"] = 1] = "SceneViewer";
12
+ EmbedState[EmbedState["ProductViewer"] = 2] = "ProductViewer";
13
+ EmbedState[EmbedState["ProductAR"] = 3] = "ProductAR";
14
+ EmbedState[EmbedState["QRCode"] = 4] = "QRCode";
15
+ })(EmbedState || (EmbedState = {}));
5
16
  /**
6
17
  * This is the primary <plattar-embed /> node that allows easy embedding
7
18
  * of Plattar related content
@@ -9,6 +20,13 @@ const product_ar_1 = require("../ar/product-ar");
9
20
  class PlattarEmbed extends HTMLElement {
10
21
  constructor() {
11
22
  super();
23
+ // this is the current state of the embed, none by default
24
+ this._currentState = EmbedState.None;
25
+ this._qrCodeOptions = {
26
+ color: "#101721",
27
+ qrType: "default",
28
+ margin: 0
29
+ };
12
30
  this._sceneID = null;
13
31
  this._productID = null;
14
32
  this._variationID = null;
@@ -22,6 +40,35 @@ class PlattarEmbed extends HTMLElement {
22
40
  return this._viewer;
23
41
  }
24
42
  connectedCallback() {
43
+ const observer = new MutationObserver((mutations) => {
44
+ mutations.forEach((mutation) => {
45
+ if (mutation.type === "attributes") {
46
+ const sceneID = this.hasAttribute("scene-id") ? this.getAttribute("scene-id") : null;
47
+ const productID = this.hasAttribute("product-id") ? this.getAttribute("product-id") : null;
48
+ const variationID = this.hasAttribute("variation-id") ? this.getAttribute("variation-id") : null;
49
+ let updated = false;
50
+ if (sceneID !== this._sceneID) {
51
+ this._sceneID = sceneID;
52
+ updated = true;
53
+ }
54
+ if (productID !== this._productID) {
55
+ this._productID = productID;
56
+ updated = true;
57
+ }
58
+ if (variationID !== this._variationID) {
59
+ this._variationID = variationID;
60
+ updated = true;
61
+ }
62
+ if (updated) {
63
+ // re-render based on internal state
64
+ this._OnAttributesUpdated();
65
+ }
66
+ }
67
+ });
68
+ });
69
+ observer.observe(this, {
70
+ attributes: true
71
+ });
25
72
  const server = this.hasAttribute("server") ? this.getAttribute("server") : "production";
26
73
  plattar_api_1.Server.create(plattar_api_1.Server.match(server || "production"));
27
74
  if (server) {
@@ -74,6 +121,13 @@ class PlattarEmbed extends HTMLElement {
74
121
  const product = new product_ar_1.ProductAR(this._productID, this._variationID);
75
122
  return product.init().then(accept).catch(reject);
76
123
  }
124
+ // If Product is set (under any scenario) then use ProductAR
125
+ // NOTE: At some point this should check for Scenes when SceneAR
126
+ // is implemented
127
+ if (this._productID) {
128
+ const product = new product_ar_1.ProductAR(this._productID, this._variationID);
129
+ return product.init().then(accept).catch(reject);
130
+ }
77
131
  // otherwise, scene was set so use SceneAR
78
132
  if (this._sceneID) {
79
133
  return reject(new Error("PlattarEmbed.initAR() - scene-id not yet supported"));
@@ -108,12 +162,19 @@ class PlattarEmbed extends HTMLElement {
108
162
  viewer.setAttribute("height", this._height);
109
163
  viewer.setAttribute("server", this._server);
110
164
  viewer.setAttribute("scene-id", this._sceneID);
165
+ if (this._productID) {
166
+ viewer.setAttribute("product-id", this._productID);
167
+ }
168
+ if (this._variationID) {
169
+ viewer.setAttribute("variation-id", this._variationID);
170
+ }
111
171
  viewer.onload = () => {
112
172
  return accept(viewer);
113
173
  };
114
174
  const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
115
175
  shadow.append(viewer);
116
176
  this._viewer = viewer;
177
+ this._currentState = EmbedState.SceneViewer;
117
178
  return;
118
179
  }
119
180
  // if product is set, we use <plattar-product /> node from plattar-web
@@ -132,6 +193,7 @@ class PlattarEmbed extends HTMLElement {
132
193
  const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
133
194
  shadow.append(viewer);
134
195
  this._viewer = viewer;
196
+ this._currentState = EmbedState.ProductViewer;
135
197
  return;
136
198
  }
137
199
  return reject(new Error("PlattarEmbed.startViewer() - minimum required attributes not set, use scene-id or product-id as a minimum"));
@@ -142,11 +204,9 @@ class PlattarEmbed extends HTMLElement {
142
204
  if (!this._isReady) {
143
205
  return reject(new Error("PlattarEmbed.startQRCode() - cannot execute as page has not loaded yet"));
144
206
  }
145
- const opt = options || {
146
- color: "#101721",
147
- qrType: "default",
148
- margin: 0
149
- };
207
+ const opt = options || this._qrCodeOptions;
208
+ // reset instance for later use
209
+ this._qrCodeOptions = opt;
150
210
  if (this._viewer) {
151
211
  this._viewer.remove();
152
212
  this._viewer = null;
@@ -165,7 +225,13 @@ class PlattarEmbed extends HTMLElement {
165
225
  if (opt.qrType) {
166
226
  viewer.setAttribute("qr-type", opt.qrType);
167
227
  }
168
- const dst = plattar_api_1.Server.location().base + "renderer/viewer.html?scene_id=" + this._sceneID;
228
+ let dst = plattar_api_1.Server.location().base + "renderer/viewer.html?scene_id=" + this._sceneID;
229
+ if (this._productID) {
230
+ dst += "&productId=" + this._productID;
231
+ }
232
+ if (this._variationID) {
233
+ dst += "&variationId=" + this._variationID;
234
+ }
169
235
  viewer.setAttribute("url", dst);
170
236
  viewer.onload = () => {
171
237
  return accept(viewer);
@@ -173,6 +239,7 @@ class PlattarEmbed extends HTMLElement {
173
239
  const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
174
240
  shadow.append(viewer);
175
241
  this._viewer = viewer;
242
+ this._currentState = EmbedState.QRCode;
176
243
  return;
177
244
  }
178
245
  // if product is set, we embed a QR code that takes us to product.html
@@ -200,10 +267,41 @@ class PlattarEmbed extends HTMLElement {
200
267
  const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
201
268
  shadow.append(viewer);
202
269
  this._viewer = viewer;
270
+ this._currentState = EmbedState.QRCode;
203
271
  return;
204
272
  }
205
273
  return reject(new Error("PlattarEmbed.startQRCode() - minimum required attributes not set, use scene-id or product-id as a minimum"));
206
274
  });
207
275
  }
276
+ /**
277
+ * This is called by the observer if any of the embed attributes have changed
278
+ * based on the state of the embed, we update the internal structure accordingly
279
+ */
280
+ _OnAttributesUpdated() {
281
+ // nothing to update in these scenarios
282
+ if (this._currentState === EmbedState.None || this._currentState === EmbedState.ProductAR) {
283
+ return;
284
+ }
285
+ // re-render the QR Code when attributes have changed
286
+ if (this._currentState === EmbedState.QRCode) {
287
+ this.startQRCode(this._qrCodeOptions);
288
+ return;
289
+ }
290
+ // use the messenger function to change variation when attributes have changed
291
+ if (this._currentState === EmbedState.SceneViewer) {
292
+ const viewer = this.viewer;
293
+ if (viewer) {
294
+ viewer.messenger.selectVariation(this._productID, this._variationID);
295
+ }
296
+ return;
297
+ }
298
+ if (this._currentState === EmbedState.ProductViewer) {
299
+ const viewer = this.viewer;
300
+ if (viewer) {
301
+ viewer.messenger.selectVariation(this._variationID);
302
+ }
303
+ return;
304
+ }
305
+ }
208
306
  }
209
307
  exports.default = PlattarEmbed;
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export { ConfiguratorAR } from "./ar/configurator-ar";
5
5
  export { ProductAR } from "./ar/product-ar";
6
6
  export { SceneAR } from "./ar/scene-ar";
7
7
  export { ModelAR } from "./ar/model-ar";
8
+ export { RawAR } from "./ar/raw-ar";
8
9
  export { Util } from "./util/util";
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.ModelAR = exports.SceneAR = exports.ProductAR = exports.ConfiguratorAR = exports.version = exports.PlattarQRCode = exports.PlattarWeb = void 0;
25
+ exports.Util = exports.RawAR = exports.ModelAR = exports.SceneAR = exports.ProductAR = exports.ConfiguratorAR = 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"));
@@ -34,11 +34,15 @@ var scene_ar_1 = require("./ar/scene-ar");
34
34
  Object.defineProperty(exports, "SceneAR", { enumerable: true, get: function () { return scene_ar_1.SceneAR; } });
35
35
  var model_ar_1 = require("./ar/model-ar");
36
36
  Object.defineProperty(exports, "ModelAR", { enumerable: true, get: function () { return model_ar_1.ModelAR; } });
37
+ var raw_ar_1 = require("./ar/raw-ar");
38
+ Object.defineProperty(exports, "RawAR", { enumerable: true, get: function () { return raw_ar_1.RawAR; } });
37
39
  var util_1 = require("./util/util");
38
40
  Object.defineProperty(exports, "Util", { enumerable: true, get: function () { return util_1.Util; } });
39
41
  const plattar_embed_1 = __importDefault(require("./embed/plattar-embed"));
40
42
  const version_1 = __importDefault(require("./version"));
41
43
  if (customElements) {
42
- customElements.define("plattar-embed", plattar_embed_1.default);
44
+ if (customElements.get("plattar-embed") === undefined) {
45
+ customElements.define("plattar-embed", plattar_embed_1.default);
46
+ }
43
47
  }
44
48
  console.log("using @plattar/plattar-ar-adapter v" + version_1.default);
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.120.2";
1
+ declare const _default: "1.122.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.120.2";
3
+ exports.default = "1.122.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.120.2",
3
+ "version": "1.122.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",
@@ -40,14 +40,14 @@
40
40
  "@plattar/plattar-analytics": "^1.117.2",
41
41
  "@plattar/plattar-api": "^1.120.1",
42
42
  "@plattar/plattar-qrcode": "1.120.3",
43
- "@plattar/plattar-web": "^1.117.1"
43
+ "@plattar/plattar-web": "^1.122.2"
44
44
  },
45
45
  "devDependencies": {
46
- "@babel/cli": "^7.16.0",
47
- "@babel/core": "^7.16.0",
48
- "@babel/preset-env": "^7.16.4",
46
+ "@babel/cli": "^7.16.8",
47
+ "@babel/core": "^7.16.12",
48
+ "@babel/preset-env": "^7.16.11",
49
49
  "browserify": "^17.0.0",
50
- "typescript": "^4.5.2",
50
+ "typescript": "^4.5.5",
51
51
  "uglify-es": "^3.3.9"
52
52
  },
53
53
  "publishConfig": {