@plattar/plattar-ar-adapter 1.158.2 → 1.163.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.
Files changed (37) hide show
  1. package/build/es2015/plattar-ar-adapter.js +571 -335
  2. package/build/es2015/plattar-ar-adapter.min.js +1 -1
  3. package/build/es2019/plattar-ar-adapter.js +206 -100
  4. package/build/es2019/plattar-ar-adapter.min.js +1 -1
  5. package/dist/ar/configurator-ar.d.ts +6 -2
  6. package/dist/ar/configurator-ar.js +17 -8
  7. package/dist/ar/launcher-ar.d.ts +2 -0
  8. package/dist/ar/launcher-ar.js +2 -1
  9. package/dist/ar/model-ar.d.ts +6 -2
  10. package/dist/ar/model-ar.js +14 -4
  11. package/dist/ar/product-ar.d.ts +8 -4
  12. package/dist/ar/product-ar.js +28 -6
  13. package/dist/ar/raw-ar.d.ts +7 -3
  14. package/dist/ar/raw-ar.js +16 -8
  15. package/dist/ar/scene-ar.d.ts +7 -3
  16. package/dist/ar/scene-ar.js +16 -8
  17. package/dist/ar/scene-product-ar.d.ts +2 -2
  18. package/dist/ar/scene-product-ar.js +5 -4
  19. package/dist/embed/controllers/configurator-controller.js +16 -2
  20. package/dist/embed/controllers/plattar-controller.d.ts +12 -0
  21. package/dist/embed/controllers/plattar-controller.js +22 -0
  22. package/dist/embed/controllers/product-controller.js +11 -1
  23. package/dist/embed/controllers/vto-controller.js +7 -2
  24. package/dist/embed/plattar-embed.d.ts +2 -0
  25. package/dist/embed/plattar-embed.js +16 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/version.d.ts +1 -1
  28. package/dist/version.js +1 -1
  29. package/dist/viewers/ar-viewer.d.ts +8 -1
  30. package/dist/viewers/ar-viewer.js +8 -2
  31. package/dist/viewers/quicklook-viewer.d.ts +1 -4
  32. package/dist/viewers/quicklook-viewer.js +9 -18
  33. package/dist/viewers/reality-viewer.d.ts +1 -1
  34. package/dist/viewers/reality-viewer.js +2 -5
  35. package/dist/viewers/scene-viewer.d.ts +1 -3
  36. package/dist/viewers/scene-viewer.js +9 -23
  37. package/package.json +7 -7
@@ -156,6 +156,7 @@ class PlattarController {
156
156
  const variationID = this.getAttribute("variation-id");
157
157
  const variationSKU = this.getAttribute("variation-sku");
158
158
  const arMode = this.getAttribute("ar-mode");
159
+ const showBanner = this.getAttribute("show-ar-banner");
159
160
  try {
160
161
  configState = (await this.getConfiguratorState()).state.encode();
161
162
  }
@@ -187,6 +188,9 @@ class PlattarController {
187
188
  if (sceneID) {
188
189
  dst += "&scene_id=" + sceneID;
189
190
  }
191
+ if (showBanner) {
192
+ dst += "&show_ar_banner=" + showBanner;
193
+ }
190
194
  viewer.setAttribute("url", opt.url || dst);
191
195
  this._state = ControllerState.QRCode;
192
196
  this._prevQROpt = opt;
@@ -211,6 +215,14 @@ class PlattarController {
211
215
  getAttribute(attribute) {
212
216
  return this.parent ? (this.parent.hasAttribute(attribute) ? this.parent.getAttribute(attribute) : null) : null;
213
217
  }
218
+ /**
219
+ * Returns the specified attribute from the parent as a boolean
220
+ * @param attribute - The name of the attribute
221
+ * @returns - The attribute value
222
+ */
223
+ getBooleanAttribute(attribute) {
224
+ return this.parent ? (this.parent.hasAttribute(attribute) ? (this.parent.getAttribute(attribute)?.toLowerCase() === "true" ? true : false) : false) : false;
225
+ }
214
226
  /**
215
227
  * Sets a particular attribute into the HTML DOM
216
228
  *
@@ -222,6 +234,16 @@ class PlattarController {
222
234
  this.parent.setAttribute(attribute, value);
223
235
  }
224
236
  }
237
+ /**
238
+ * Removes a particular attribute from HTML DOM
239
+ *
240
+ * @param attribute - The name of the attribute
241
+ */
242
+ removeAttribute(attribute) {
243
+ if (this.parent) {
244
+ this.parent.removeAttribute(attribute);
245
+ }
246
+ }
225
247
  /**
226
248
  * Appends the provided element into the shadow-root of the parent element
227
249
  * @param element - The element to append
@@ -119,6 +119,7 @@ class ProductController extends plattar_controller_1.PlattarController {
119
119
  const variationID = this.getAttribute("variation-id");
120
120
  const variationSKU = this.getAttribute("variation-sku");
121
121
  const arMode = this.getAttribute("ar-mode");
122
+ const showBanner = this.getAttribute("show-ar-banner");
122
123
  if (configState) {
123
124
  dst += "&config_state=" + configState;
124
125
  }
@@ -143,6 +144,9 @@ class ProductController extends plattar_controller_1.PlattarController {
143
144
  if (sceneID) {
144
145
  dst += "&scene_id=" + sceneID;
145
146
  }
147
+ if (showBanner) {
148
+ dst += "&show_ar_banner=" + showBanner;
149
+ }
146
150
  viewer.setAttribute("url", opt.url || dst);
147
151
  viewer.onload = () => {
148
152
  return accept(viewer);
@@ -201,7 +205,13 @@ class ProductController extends plattar_controller_1.PlattarController {
201
205
  if (productID) {
202
206
  const variationID = this.getAttribute("variation-id");
203
207
  const variationSKU = this.getAttribute("variation-sku");
204
- const product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
208
+ //const product: ProductAR = new ProductAR(productID, variationID, variationSKU);
209
+ const product = new product_ar_1.ProductAR({
210
+ productID: productID,
211
+ variationID: variationID ? variationID : (variationSKU ? null : "default"),
212
+ variationSKU: variationSKU,
213
+ useARBanner: this.getBooleanAttribute("show-ar-banner")
214
+ });
205
215
  return product.init().then(accept).catch(reject);
206
216
  }
207
217
  return reject(new Error("ProductController.initAR() - minimum required attributes not set, use product-id as a minimum"));
@@ -210,7 +210,12 @@ class VTOController extends plattar_controller_1.PlattarController {
210
210
  const state = (await this.getConfiguratorState()).state;
211
211
  const first = state.first();
212
212
  if (first) {
213
- const sceneProductAR = new __1.SceneProductAR(first.scene_product_id, first.product_variation_id);
213
+ const sceneProductAR = new __1.SceneProductAR({
214
+ productID: first.scene_product_id,
215
+ variationID: first.product_variation_id,
216
+ variationSKU: null,
217
+ useARBanner: this.getBooleanAttribute("show-ar-banner")
218
+ });
214
219
  return sceneProductAR.init();
215
220
  }
216
221
  throw new Error("VTOController.initAR() - invalid decoded config-state does not have any product states");
@@ -223,7 +228,7 @@ class VTOController extends plattar_controller_1.PlattarController {
223
228
  if (!sceneID) {
224
229
  throw new Error("VTOController.initAR() - generated AR minimum required attributes not set, use scene-id as a minimum");
225
230
  }
226
- const configAR = new configurator_ar_1.ConfiguratorAR(await this.getConfiguratorState());
231
+ const configAR = new configurator_ar_1.ConfiguratorAR({ state: await this.getConfiguratorState(), useARBanner: this.getBooleanAttribute("show-ar-banner") });
227
232
  return configAR.init();
228
233
  }
229
234
  removeRenderer() {
@@ -57,4 +57,6 @@ export default class PlattarEmbed extends HTMLElement {
57
57
  * based on the state of the embed, we update the internal structure accordingly
58
58
  */
59
59
  private _OnAttributesUpdated;
60
+ addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void;
61
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void;
60
62
  }
@@ -223,5 +223,21 @@ class PlattarEmbed extends HTMLElement {
223
223
  this._controller.onAttributesUpdated(attributeName);
224
224
  }
225
225
  }
226
+ addEventListener(type, listener, options) {
227
+ // add to the element event listener
228
+ super.addEventListener(type, listener, options);
229
+ const eventType = 'arclick';
230
+ if (type === eventType) {
231
+ // automatically enable `show-ar-banner` to true if an arclick event is added
232
+ this.setAttribute('show-ar-banner', 'true');
233
+ // if this is a redirect url from an AR Action - we need to fire the event listener now
234
+ const url = new URL(location.href);
235
+ if (url.searchParams.get('plattar_ar_action') === 'true') {
236
+ setTimeout(() => {
237
+ this.dispatchEvent(new Event(eventType));
238
+ }, 200);
239
+ }
240
+ }
241
+ }
226
242
  }
227
243
  exports.default = PlattarEmbed;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference types="@plattar/plattar-web" />
2
+ /// <reference types="@plattar/plattar-qrcode" />
1
3
  export * as PlattarWeb from "@plattar/plattar-web";
2
4
  export * as PlattarQRCode from "@plattar/plattar-qrcode";
3
5
  export * as version from "./version";
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.158.2";
1
+ declare const _default: "1.163.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.158.2";
3
+ exports.default = "1.163.1";
@@ -1,7 +1,14 @@
1
- export default abstract class ARViewer {
1
+ export interface ARBanner {
2
+ readonly title: string;
3
+ readonly subtitle: string;
4
+ readonly button: 'Visit';
5
+ }
6
+ export declare abstract class ARViewer {
2
7
  modelUrl: string | null;
8
+ banner: ARBanner | null;
3
9
  constructor();
4
10
  abstract start(): void;
5
11
  abstract get nodeType(): string;
6
12
  abstract get device(): string;
13
+ get composedActionURL(): string;
7
14
  }
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ARViewer = void 0;
3
4
  class ARViewer {
4
5
  constructor() {
5
6
  this.modelUrl = null;
6
- this.modelUrl = null;
7
+ this.banner = null;
8
+ }
9
+ get composedActionURL() {
10
+ const link = new URL(location.href);
11
+ link.searchParams.set("plattar_ar_action", "true");
12
+ return encodeURI(link.href);
7
13
  }
8
14
  }
9
- exports.default = ARViewer;
15
+ exports.ARViewer = ARViewer;
@@ -1,8 +1,5 @@
1
- import ARViewer from "./ar-viewer";
1
+ import { ARViewer } from "./ar-viewer";
2
2
  export default class QuicklookViewer extends ARViewer {
3
- araction: string | null;
4
- arcallback: () => void;
5
- titleHTML: string;
6
3
  constructor();
7
4
  get nodeType(): string;
8
5
  get device(): string;
@@ -1,15 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ar_viewer_1 = __importDefault(require("./ar-viewer"));
7
- class QuicklookViewer extends ar_viewer_1.default {
3
+ const ar_viewer_1 = require("./ar-viewer");
4
+ class QuicklookViewer extends ar_viewer_1.ARViewer {
8
5
  constructor() {
9
6
  super();
10
- this.araction = null;
11
- this.titleHTML = "&checkoutTitle=" + document.title + "&checkoutSubtitle=" + document.title;
12
- this.arcallback = () => { };
13
7
  }
14
8
  get nodeType() {
15
9
  return "Quick Look";
@@ -24,23 +18,20 @@ class QuicklookViewer extends ar_viewer_1.default {
24
18
  const anchor = document.createElement("a");
25
19
  anchor.setAttribute("rel", "ar");
26
20
  anchor.appendChild(document.createElement("img"));
21
+ const banner = this.banner;
27
22
  let url = this.modelUrl;
28
- const araction = this.araction;
29
- if (araction) {
23
+ if (banner) {
24
+ url += `#callToAction=${banner.button}`;
25
+ url += `&checkoutTitle=${banner.title}`;
26
+ url += `&checkoutSubtitle=${banner.subtitle}`;
30
27
  const handleQuicklook = (event) => {
31
28
  if (event.data === "_apple_ar_quicklook_button_tapped") {
32
- this.arcallback();
29
+ window.location.assign(this.composedActionURL);
33
30
  }
34
- document.body.removeChild(anchor);
35
- anchor.removeEventListener("message", handleQuicklook, false);
36
31
  };
37
32
  anchor.addEventListener("message", handleQuicklook, false);
38
- document.body.appendChild(anchor);
39
- url += "#callToAction=" + araction;
40
- if (this.titleHTML) {
41
- url += this.titleHTML;
42
- }
43
33
  }
34
+ document.body.appendChild(anchor);
44
35
  anchor.setAttribute("href", encodeURI(url));
45
36
  anchor.click();
46
37
  }
@@ -1,4 +1,4 @@
1
- import ARViewer from "./ar-viewer";
1
+ import { ARViewer } from "./ar-viewer";
2
2
  export default class RealityViewer extends ARViewer {
3
3
  constructor();
4
4
  get nodeType(): string;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ar_viewer_1 = __importDefault(require("./ar-viewer"));
7
- class RealityViewer extends ar_viewer_1.default {
3
+ const ar_viewer_1 = require("./ar-viewer");
4
+ class RealityViewer extends ar_viewer_1.ARViewer {
8
5
  constructor() {
9
6
  super();
10
7
  }
@@ -1,7 +1,5 @@
1
- import ARViewer from "./ar-viewer";
1
+ import { ARViewer } from "./ar-viewer";
2
2
  export default class SceneViewer extends ARViewer {
3
- araction: string | null;
4
- titleHTML: string;
5
3
  isVertical: boolean;
6
4
  constructor();
7
5
  get nodeType(): string;
@@ -1,15 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ar_viewer_1 = __importDefault(require("./ar-viewer"));
7
- class SceneViewer extends ar_viewer_1.default {
3
+ const ar_viewer_1 = require("./ar-viewer");
4
+ class SceneViewer extends ar_viewer_1.ARViewer {
8
5
  constructor() {
9
6
  super();
10
- this.araction = null;
11
7
  this.isVertical = false;
12
- this.titleHTML = "<b>" + document.title;
13
8
  this.isVertical = false;
14
9
  }
15
10
  get nodeType() {
@@ -22,27 +17,18 @@ class SceneViewer extends ar_viewer_1.default {
22
17
  if (!this.modelUrl) {
23
18
  throw new Error("SceneViewer.start() - model url not set, use SceneViewer.modelUrl");
24
19
  }
25
- const araction = this.araction;
26
- let composedLink = encodeURIComponent(location.href);
27
- if (araction) {
28
- const link = new URL(location.href);
29
- link.searchParams.set("araction", araction);
30
- composedLink = encodeURIComponent(link.href);
20
+ const linkOverride = encodeURIComponent(`${location.href}#no-ar-fallback`);
21
+ let intent = `intent://arvr.google.com/scene-viewer/1.1?file=${this.modelUrl}&mode=ar_preferred`;
22
+ const banner = this.banner;
23
+ if (banner) {
24
+ intent += `&title=<b>${banner.title}</b><br>${banner.subtitle}`;
25
+ intent += `&link=${this.composedActionURL}`;
31
26
  }
32
- if (!composedLink) {
33
- throw new Error("SceneViewer.start() - failed to create composition link, check parameters");
34
- }
35
- const linkOverride = encodeURIComponent(location.href + '#no-ar-fallback');
36
- let intent = 'intent://arvr.google.com/scene-viewer/1.1';
37
- intent += '?file=' + this.modelUrl;
38
- intent += '&mode=ar_preferred';
39
- intent += '&link=' + composedLink;
40
- intent += '&title=<b>' + this.titleHTML;
41
27
  if (this.isVertical) {
42
28
  intent += '&enable_vertical_placement=true';
43
29
  }
44
30
  intent += ' #Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;';
45
- intent += 'S.browser_fallback_url=' + linkOverride + ';end;';
31
+ intent += `S.browser_fallback_url=${linkOverride};end;`;
46
32
  const anchor = document.createElement("a");
47
33
  anchor.setAttribute("href", intent);
48
34
  anchor.click();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.158.2",
3
+ "version": "1.163.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",
@@ -38,17 +38,17 @@
38
38
  "homepage": "https://www.plattar.com",
39
39
  "dependencies": {
40
40
  "@plattar/plattar-analytics": "^1.152.2",
41
- "@plattar/plattar-api": "^1.154.1",
42
- "@plattar/plattar-qrcode": "1.150.2",
41
+ "@plattar/plattar-api": "^1.159.1",
42
+ "@plattar/plattar-qrcode": "1.160.1",
43
43
  "@plattar/plattar-services": "^1.157.1",
44
44
  "@plattar/plattar-web": "^1.154.3"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/cli": "^7.22.15",
48
- "@babel/core": "^7.22.15",
49
- "@babel/preset-env": "^7.22.15",
47
+ "@babel/cli": "^7.23.4",
48
+ "@babel/core": "^7.23.3",
49
+ "@babel/preset-env": "^7.23.3",
50
50
  "browserify": "^17.0.0",
51
- "typescript": "^5.2.2",
51
+ "typescript": "^5.3.2",
52
52
  "uglify-js": "^3.17.4"
53
53
  },
54
54
  "publishConfig": {