@plattar/plattar-ar-adapter 1.188.3 → 1.188.5

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,6 +1,6 @@
1
1
  import { LauncherAR } from "../../ar/launcher-ar";
2
2
  import { DecodedConfiguratorState } from "../../util/configurator-state";
3
- import { PlattarController } from "./plattar-controller";
3
+ import { PlattarController, QRCodeOptions } from "./plattar-controller";
4
4
  /**
5
5
  * Manages an instance of the <plattar-configurator> HTML Element
6
6
  */
@@ -9,7 +9,7 @@ export declare class ConfiguratorController extends PlattarController {
9
9
  getConfiguratorState(): Promise<DecodedConfiguratorState>;
10
10
  onAttributesUpdated(attributeName: string): Promise<void>;
11
11
  startARQRCode(options: any): Promise<HTMLElement>;
12
- startViewerQRCode(options: any): Promise<HTMLElement>;
12
+ startViewerQRCode(options: QRCodeOptions): Promise<HTMLElement>;
13
13
  startRenderer(): Promise<HTMLElement>;
14
14
  initAR(): Promise<LauncherAR>;
15
15
  /**
@@ -90,8 +90,11 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
90
90
  return super.startARQRCode(options);
91
91
  }
92
92
  async startViewerQRCode(options) {
93
+ const opt = this._GetDefaultQROptions(options);
93
94
  // remove the old renderer instance if any
94
- this.removeRenderer();
95
+ if (!opt.detached) {
96
+ this.removeRenderer();
97
+ }
95
98
  const sceneID = this.getAttribute("scene-id");
96
99
  if (!sceneID) {
97
100
  throw new Error("ConfiguratorController.startViewerQRCode() - minimum required attributes not set, use scene-id as a minimum");
@@ -121,9 +124,10 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
121
124
  // config state is not available
122
125
  configState = null;
123
126
  }
124
- const opt = options || this._GetDefaultQROptions();
125
127
  const viewer = document.createElement("plattar-qrcode");
126
- this._element = viewer;
128
+ if (!opt.detached) {
129
+ this._element = viewer;
130
+ }
127
131
  // required attributes with defaults for plattar-viewer node
128
132
  const width = this.getAttribute("width") || "500px";
129
133
  const height = this.getAttribute("height") || "500px";
@@ -160,13 +164,18 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
160
164
  dst += "&scene_graph_id=" + sceneGraphID;
161
165
  }
162
166
  viewer.setAttribute("url", opt.url || dst);
163
- this._state = plattar_controller_1.ControllerState.QRCode;
164
167
  this._prevQROpt = opt;
168
+ if (!opt.detached) {
169
+ this._state = plattar_controller_1.ControllerState.QRCode;
170
+ return new Promise((accept, reject) => {
171
+ viewer.onload = () => {
172
+ return accept(viewer);
173
+ };
174
+ this.append(viewer);
175
+ });
176
+ }
165
177
  return new Promise((accept, reject) => {
166
- viewer.onload = () => {
167
- return accept(viewer);
168
- };
169
- this.append(viewer);
178
+ return accept(viewer);
170
179
  });
171
180
  }
172
181
  async startRenderer() {
@@ -1,6 +1,6 @@
1
1
  import { LauncherAR } from "../../ar/launcher-ar";
2
2
  import { DecodedConfiguratorState } from "../../util/configurator-state";
3
- import { PlattarController } from "./plattar-controller";
3
+ import { PlattarController, QRCodeOptions } from "./plattar-controller";
4
4
  /**
5
5
  * Manages an instance of the <plattar-configurator> HTML Element
6
6
  */
@@ -8,7 +8,7 @@ export declare class GalleryController extends PlattarController {
8
8
  private _cachedConfigState;
9
9
  getConfiguratorState(): Promise<DecodedConfiguratorState>;
10
10
  onAttributesUpdated(attributeName: string): Promise<void>;
11
- startViewerQRCode(options: any): Promise<HTMLElement>;
11
+ startViewerQRCode(options: QRCodeOptions): Promise<HTMLElement>;
12
12
  startRenderer(): Promise<HTMLElement>;
13
13
  initAR(): Promise<LauncherAR>;
14
14
  get element(): HTMLElement | null;
@@ -43,15 +43,19 @@ class GalleryController extends plattar_controller_1.PlattarController {
43
43
  }
44
44
  }
45
45
  async startViewerQRCode(options) {
46
+ const opt = this._GetDefaultQROptions(options);
46
47
  // remove the old renderer instance if any
47
- this.removeRenderer();
48
+ if (!opt.detached) {
49
+ this.removeRenderer();
50
+ }
48
51
  const sceneID = this.getAttribute("scene-id");
49
52
  if (!sceneID) {
50
53
  throw new Error("GalleryController.startViewerQRCode() - minimum required attributes not set, use scene-id as a minimum");
51
54
  }
52
- const opt = options || this._GetDefaultQROptions();
53
55
  const viewer = document.createElement("plattar-qrcode");
54
- this._element = viewer;
56
+ if (!opt.detached) {
57
+ this._element = viewer;
58
+ }
55
59
  // required attributes with defaults for plattar-viewer node
56
60
  const width = this.getAttribute("width") || "500px";
57
61
  const height = this.getAttribute("height") || "500px";
@@ -69,13 +73,18 @@ class GalleryController extends plattar_controller_1.PlattarController {
69
73
  viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
70
74
  const dst = plattar_api_1.Server.location().base + "renderer/gallery.html?scene_id=" + sceneID;
71
75
  viewer.setAttribute("url", opt.url || dst);
72
- this._state = plattar_controller_1.ControllerState.QRCode;
73
76
  this._prevQROpt = opt;
77
+ if (!opt.detached) {
78
+ this._state = plattar_controller_1.ControllerState.QRCode;
79
+ return new Promise((accept, reject) => {
80
+ viewer.onload = () => {
81
+ return accept(viewer);
82
+ };
83
+ this.append(viewer);
84
+ });
85
+ }
74
86
  return new Promise((accept, reject) => {
75
- viewer.onload = () => {
76
- return accept(viewer);
77
- };
78
- this.append(viewer);
87
+ return accept(viewer);
79
88
  });
80
89
  }
81
90
  async startRenderer() {
@@ -23,24 +23,24 @@ class LauncherController extends plattar_controller_1.PlattarController {
23
23
  }
24
24
  async onAttributesUpdated(attributeName) {
25
25
  const state = this._state;
26
+ if (attributeName === "variation-id") {
27
+ const configState = await this.getConfiguratorState();
28
+ const variationIDs = this.getAttribute("variation-id");
29
+ const variationIDsList = variationIDs ? variationIDs.split(",") : [];
30
+ variationIDsList.forEach((variationID) => {
31
+ configState.state.setVariationID(variationID);
32
+ });
33
+ }
34
+ if (attributeName === "variation-sku") {
35
+ const configState = await this.getConfiguratorState();
36
+ const variationSKUs = this.getAttribute("variation-sku");
37
+ const variationSKUList = variationSKUs ? variationSKUs.split(",") : [];
38
+ variationSKUList.forEach((variationSKU) => {
39
+ configState.state.setVariationSKU(variationSKU);
40
+ });
41
+ }
26
42
  // re-render the QR Code when attributes have changed
27
43
  if (state === plattar_controller_1.ControllerState.QRCode) {
28
- if (attributeName === "variation-id") {
29
- const configState = await this.getConfiguratorState();
30
- const variationIDs = this.getAttribute("variation-id");
31
- const variationIDsList = variationIDs ? variationIDs.split(",") : [];
32
- variationIDsList.forEach((variationID) => {
33
- configState.state.setVariationID(variationID);
34
- });
35
- }
36
- if (attributeName === "variation-sku") {
37
- const configState = await this.getConfiguratorState();
38
- const variationSKUs = this.getAttribute("variation-sku");
39
- const variationSKUList = variationSKUs ? variationSKUs.split(",") : [];
40
- variationSKUList.forEach((variationSKU) => {
41
- configState.state.setVariationSKU(variationSKU);
42
- });
43
- }
44
44
  this.startQRCode(this._prevQROpt);
45
45
  return;
46
46
  }
@@ -122,15 +122,20 @@ class LauncherController extends plattar_controller_1.PlattarController {
122
122
  if (showBanner) {
123
123
  viewer.setAttribute("show-ar-banner", showBanner);
124
124
  }
125
- if (configState) {
126
- const encodedState = configState.state.encode();
127
- if (encodedState.length < 6000) {
128
- viewer.setAttribute("config-state", encodedState);
129
- }
130
- }
131
125
  if (sceneGraphID) {
132
126
  viewer.setAttribute("scene-graph-id", sceneGraphID);
133
127
  }
128
+ else {
129
+ try {
130
+ const sceneGraphID = await (await this.getConfiguratorState()).state.encodeSceneGraphID();
131
+ viewer.setAttribute("scene-graph-id", sceneGraphID);
132
+ }
133
+ catch (_err) {
134
+ // scene graph ID not available for some reason
135
+ // we will generate a new one
136
+ console.error(_err);
137
+ }
138
+ }
134
139
  return new Promise((accept, reject) => {
135
140
  this.append(viewer);
136
141
  if (configState) {
@@ -6,6 +6,14 @@ export declare enum ControllerState {
6
6
  Renderer = 1,
7
7
  QRCode = 2
8
8
  }
9
+ export interface QRCodeOptions {
10
+ readonly color: string;
11
+ readonly qrType: string;
12
+ readonly shorten: boolean;
13
+ readonly margin: number;
14
+ readonly detached: boolean;
15
+ readonly url?: string | null;
16
+ }
9
17
  /**
10
18
  * All Plattar Controllers are derived from the same interface
11
19
  */
@@ -13,7 +21,7 @@ export declare abstract class PlattarController {
13
21
  /**
14
22
  * Default QR Code rendering options
15
23
  */
16
- protected _GetDefaultQROptions(): any;
24
+ protected _GetDefaultQROptions(opt?: QRCodeOptions | undefined | null): QRCodeOptions;
17
25
  private readonly _parent;
18
26
  protected _state: ControllerState;
19
27
  protected _element: HTMLElement | null;
@@ -56,19 +64,19 @@ export declare abstract class PlattarController {
56
64
  * Start Rendering a QR Code with the provided options
57
65
  * @param options (optional) - The QR Code Options
58
66
  */
59
- abstract startViewerQRCode(options: any | undefined | null): Promise<HTMLElement>;
67
+ abstract startViewerQRCode(options: QRCodeOptions | undefined | null): Promise<HTMLElement>;
60
68
  /**
61
69
  * Decide which QR Code to render according to the qr-type attribute
62
70
  * @param options
63
71
  * @returns
64
72
  */
65
- startQRCode(options: any): Promise<HTMLElement>;
73
+ startQRCode(options: QRCodeOptions): Promise<HTMLElement>;
66
74
  /**
67
75
  * Displays a QR Code that sends the user direct to AR
68
76
  * @param options
69
77
  * @returns
70
78
  */
71
- startARQRCode(options: any): Promise<HTMLElement>;
79
+ startARQRCode(options: QRCodeOptions): Promise<HTMLElement>;
72
80
  /**
73
81
  * Initialise and return a launcher that can be used to start AR
74
82
  */
@@ -16,12 +16,15 @@ class PlattarController {
16
16
  /**
17
17
  * Default QR Code rendering options
18
18
  */
19
- _GetDefaultQROptions() {
19
+ _GetDefaultQROptions(opt = null) {
20
+ const options = opt ?? {};
20
21
  return {
21
- color: this.getAttribute("qr-color") || "#101721",
22
- qrType: this.getAttribute("qr-style") || "default",
23
- shorten: this.getAttribute("qr-shorten") || true,
24
- margin: 0
22
+ color: options.color ?? (this.getAttribute("qr-color") || "#101721"),
23
+ qrType: options.qrType ?? (this.getAttribute("qr-style") || "default"),
24
+ shorten: options.shorten ?? (this.getBooleanAttribute("qr-shorten") || true),
25
+ margin: options.margin ?? 0,
26
+ detached: options.detached ?? (this.getBooleanAttribute("qr-detached") || false),
27
+ url: options.url ?? null
25
28
  };
26
29
  }
27
30
  ;
@@ -140,11 +143,13 @@ class PlattarController {
140
143
  * @returns
141
144
  */
142
145
  async startARQRCode(options) {
143
- // remove the old renderer instance if any
144
- this.removeRenderer();
145
- const opt = options || this._GetDefaultQROptions();
146
+ const opt = this._GetDefaultQROptions(options);
146
147
  const viewer = document.createElement("plattar-qrcode");
147
- this._element = viewer;
148
+ // remove the old renderer instance if any
149
+ if (!opt.detached) {
150
+ this.removeRenderer();
151
+ this._element = viewer;
152
+ }
148
153
  // required attributes with defaults for plattar-viewer node
149
154
  const width = this.getAttribute("width") || "500px";
150
155
  const height = this.getAttribute("height") || "500px";
@@ -154,7 +159,7 @@ class PlattarController {
154
159
  viewer.setAttribute("color", opt.color);
155
160
  }
156
161
  if (opt.margin) {
157
- viewer.setAttribute("margin", "" + opt.margin);
162
+ viewer.setAttribute("margin", `${opt.margin}`);
158
163
  }
159
164
  if (opt.qrType) {
160
165
  viewer.setAttribute("qr-type", opt.qrType);
@@ -162,7 +167,7 @@ class PlattarController {
162
167
  viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
163
168
  const qrOptions = btoa(JSON.stringify(opt));
164
169
  let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
165
- let configState = null;
170
+ //let configState: string | null = null;
166
171
  const sceneID = this.getAttribute("scene-id");
167
172
  const embedType = this.getAttribute("embed-type");
168
173
  const productID = this.getAttribute("product-id");
@@ -172,16 +177,6 @@ class PlattarController {
172
177
  const arMode = this.getAttribute("ar-mode");
173
178
  const showBanner = this.getAttribute("show-ar-banner");
174
179
  const sceneGraphID = this.getAttribute("scene-graph-id");
175
- try {
176
- configState = (await this.getConfiguratorState()).state.encode();
177
- }
178
- catch (_err) {
179
- // config state not available for some reason
180
- configState = null;
181
- }
182
- if (configState) {
183
- dst += "&config_state=" + configState;
184
- }
185
180
  if (embedType) {
186
181
  dst += "&embed_type=" + embedType;
187
182
  }
@@ -209,14 +204,30 @@ class PlattarController {
209
204
  if (sceneGraphID) {
210
205
  dst += "&scene_graph_id" + sceneGraphID;
211
206
  }
207
+ else {
208
+ try {
209
+ const sceneGraphID = await (await this.getConfiguratorState()).state.encodeSceneGraphID();
210
+ dst += "&scene_graph_id=" + sceneGraphID;
211
+ }
212
+ catch (_err) {
213
+ // scene graph ID not available for some reason
214
+ // we will generate a new one
215
+ console.error(_err);
216
+ }
217
+ }
212
218
  viewer.setAttribute("url", opt.url || dst);
213
- this._state = ControllerState.QRCode;
214
219
  this._prevQROpt = opt;
220
+ if (!opt.detached) {
221
+ this._state = ControllerState.QRCode;
222
+ return new Promise((accept, reject) => {
223
+ this.append(viewer);
224
+ viewer.onload = () => {
225
+ return accept(viewer);
226
+ };
227
+ });
228
+ }
215
229
  return new Promise((accept, reject) => {
216
- this.append(viewer);
217
- viewer.onload = () => {
218
- return accept(viewer);
219
- };
230
+ return accept(viewer);
220
231
  });
221
232
  }
222
233
  /**
@@ -1,6 +1,6 @@
1
1
  import { LauncherAR } from "../../ar/launcher-ar";
2
2
  import { DecodedConfiguratorState } from "../../util/configurator-state";
3
- import { PlattarController } from "./plattar-controller";
3
+ import { PlattarController, QRCodeOptions } from "./plattar-controller";
4
4
  /**
5
5
  * Manages an instance of the <plattar-configurator> HTML Element
6
6
  */
@@ -8,7 +8,7 @@ export declare class VTOController extends PlattarController {
8
8
  private _cachedConfigState;
9
9
  getConfiguratorState(): Promise<DecodedConfiguratorState>;
10
10
  onAttributesUpdated(attributeName: string): Promise<void>;
11
- startViewerQRCode(options: any): Promise<HTMLElement>;
11
+ startViewerQRCode(options: QRCodeOptions): Promise<HTMLElement>;
12
12
  startRenderer(): Promise<HTMLElement>;
13
13
  initAR(): Promise<LauncherAR>;
14
14
  /**
@@ -66,15 +66,19 @@ class VTOController extends plattar_controller_1.PlattarController {
66
66
  }
67
67
  }
68
68
  async startViewerQRCode(options) {
69
+ const opt = this._GetDefaultQROptions(options);
69
70
  // remove the old renderer instance if any
70
- this.removeRenderer();
71
+ if (!opt.detached) {
72
+ this.removeRenderer();
73
+ }
71
74
  const sceneID = this.getAttribute("scene-id");
72
75
  if (!sceneID) {
73
76
  throw new Error("VTOController.startQRCode() - minimum required attributes not set, use scene-id as a minimum");
74
77
  }
75
- const opt = options || this._GetDefaultQROptions();
76
78
  const viewer = document.createElement("plattar-qrcode");
77
- this._element = viewer;
79
+ if (!opt.detached) {
80
+ this._element = viewer;
81
+ }
78
82
  // required attributes with defaults for plattar-viewer node
79
83
  const width = this.getAttribute("width") || "500px";
80
84
  const height = this.getAttribute("height") || "500px";
@@ -120,13 +124,18 @@ class VTOController extends plattar_controller_1.PlattarController {
120
124
  dst += "&variation_id=" + variationID;
121
125
  }
122
126
  viewer.setAttribute("url", opt.url || dst);
123
- this._state = plattar_controller_1.ControllerState.QRCode;
124
127
  this._prevQROpt = opt;
128
+ if (!opt.detached) {
129
+ this._state = plattar_controller_1.ControllerState.QRCode;
130
+ return new Promise((accept, reject) => {
131
+ viewer.onload = () => {
132
+ return accept(viewer);
133
+ };
134
+ this.append(viewer);
135
+ });
136
+ }
125
137
  return new Promise((accept, reject) => {
126
- viewer.onload = () => {
127
- return accept(viewer);
128
- };
129
- this.append(viewer);
138
+ return accept(viewer);
130
139
  });
131
140
  }
132
141
  async startRenderer() {
@@ -119,6 +119,7 @@ export declare class ConfiguratorState {
119
119
  * @returns - Base64 String
120
120
  */
121
121
  encode(): string;
122
+ encodeSceneGraphID(): Promise<string>;
122
123
  /**
123
124
  * Compiles and returns the Dynamic Scene Graph (Updated for 2025 for DynamicAR)
124
125
  * NOTE: Eventually this structure should replace ConfiguratorState
@@ -440,6 +440,37 @@ class ConfiguratorState {
440
440
  encode() {
441
441
  return btoa(JSON.stringify(this._state));
442
442
  }
443
+ async encodeSceneGraphID() {
444
+ const graph = this.sceneGraph;
445
+ // some scene-graphs are very large in size, we store it remotely
446
+ // this storage will expire in 10 minutes so this is a non-permanent version
447
+ // and is designed for quick ar
448
+ const url = `https://c.plattar.com/v3/redir/store`;
449
+ // finally send our scene-graph to the backend to generate the AR file and return
450
+ try {
451
+ const response = await fetch(url, {
452
+ method: "POST",
453
+ headers: {
454
+ "Content-Type": "application/json"
455
+ },
456
+ body: JSON.stringify({
457
+ data: {
458
+ attributes: {
459
+ data: graph
460
+ }
461
+ }
462
+ })
463
+ });
464
+ if (!response.ok) {
465
+ throw new Error(`ConfiguratorState.encodeSceneGraphID() - network response was not ok ${response.status}`);
466
+ }
467
+ const data = await response.json();
468
+ return data.data.id;
469
+ }
470
+ catch (error) {
471
+ throw new Error(`ConfiguratorState.encodeSceneGraphID() - there was a request error to ${url}, error was ${error.message}`);
472
+ }
473
+ }
443
474
  /**
444
475
  * Compiles and returns the Dynamic Scene Graph (Updated for 2025 for DynamicAR)
445
476
  * NOTE: Eventually this structure should replace ConfiguratorState
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.188.3";
1
+ declare const _default: "1.188.5";
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.188.3";
3
+ exports.default = "1.188.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.188.3",
3
+ "version": "1.188.5",
4
4
  "description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -44,9 +44,9 @@
44
44
  "@plattar/plattar-web": "^1.182.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/cli": "^7.27.0",
48
- "@babel/core": "^7.26.10",
49
- "@babel/preset-env": "^7.26.9",
47
+ "@babel/cli": "^7.27.2",
48
+ "@babel/core": "^7.27.4",
49
+ "@babel/preset-env": "^7.27.2",
50
50
  "browserify": "^17.0.1",
51
51
  "typescript": "^5.8.3",
52
52
  "uglify-js": "^3.19.3"