@plattar/plattar-ar-adapter 1.188.3 → 1.188.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.
@@ -1219,8 +1219,11 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
1219
1219
  return super.startARQRCode(options);
1220
1220
  }
1221
1221
  async startViewerQRCode(options) {
1222
+ const opt = this._GetDefaultQROptions(options);
1222
1223
  // remove the old renderer instance if any
1223
- this.removeRenderer();
1224
+ if (!opt.detached) {
1225
+ this.removeRenderer();
1226
+ }
1224
1227
  const sceneID = this.getAttribute("scene-id");
1225
1228
  if (!sceneID) {
1226
1229
  throw new Error("ConfiguratorController.startViewerQRCode() - minimum required attributes not set, use scene-id as a minimum");
@@ -1250,9 +1253,10 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
1250
1253
  // config state is not available
1251
1254
  configState = null;
1252
1255
  }
1253
- const opt = options || this._GetDefaultQROptions();
1254
1256
  const viewer = document.createElement("plattar-qrcode");
1255
- this._element = viewer;
1257
+ if (!opt.detached) {
1258
+ this._element = viewer;
1259
+ }
1256
1260
  // required attributes with defaults for plattar-viewer node
1257
1261
  const width = this.getAttribute("width") || "500px";
1258
1262
  const height = this.getAttribute("height") || "500px";
@@ -1289,13 +1293,18 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
1289
1293
  dst += "&scene_graph_id=" + sceneGraphID;
1290
1294
  }
1291
1295
  viewer.setAttribute("url", opt.url || dst);
1292
- this._state = plattar_controller_1.ControllerState.QRCode;
1293
1296
  this._prevQROpt = opt;
1297
+ if (!opt.detached) {
1298
+ this._state = plattar_controller_1.ControllerState.QRCode;
1299
+ return new Promise((accept, reject) => {
1300
+ viewer.onload = () => {
1301
+ return accept(viewer);
1302
+ };
1303
+ this.append(viewer);
1304
+ });
1305
+ }
1294
1306
  return new Promise((accept, reject) => {
1295
- viewer.onload = () => {
1296
- return accept(viewer);
1297
- };
1298
- this.append(viewer);
1307
+ return accept(viewer);
1299
1308
  });
1300
1309
  }
1301
1310
  async startRenderer() {
@@ -1492,15 +1501,19 @@ class GalleryController extends plattar_controller_1.PlattarController {
1492
1501
  }
1493
1502
  }
1494
1503
  async startViewerQRCode(options) {
1504
+ const opt = this._GetDefaultQROptions(options);
1495
1505
  // remove the old renderer instance if any
1496
- this.removeRenderer();
1506
+ if (!opt.detached) {
1507
+ this.removeRenderer();
1508
+ }
1497
1509
  const sceneID = this.getAttribute("scene-id");
1498
1510
  if (!sceneID) {
1499
1511
  throw new Error("GalleryController.startViewerQRCode() - minimum required attributes not set, use scene-id as a minimum");
1500
1512
  }
1501
- const opt = options || this._GetDefaultQROptions();
1502
1513
  const viewer = document.createElement("plattar-qrcode");
1503
- this._element = viewer;
1514
+ if (!opt.detached) {
1515
+ this._element = viewer;
1516
+ }
1504
1517
  // required attributes with defaults for plattar-viewer node
1505
1518
  const width = this.getAttribute("width") || "500px";
1506
1519
  const height = this.getAttribute("height") || "500px";
@@ -1518,13 +1531,18 @@ class GalleryController extends plattar_controller_1.PlattarController {
1518
1531
  viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
1519
1532
  const dst = plattar_api_1.Server.location().base + "renderer/gallery.html?scene_id=" + sceneID;
1520
1533
  viewer.setAttribute("url", opt.url || dst);
1521
- this._state = plattar_controller_1.ControllerState.QRCode;
1522
1534
  this._prevQROpt = opt;
1535
+ if (!opt.detached) {
1536
+ this._state = plattar_controller_1.ControllerState.QRCode;
1537
+ return new Promise((accept, reject) => {
1538
+ viewer.onload = () => {
1539
+ return accept(viewer);
1540
+ };
1541
+ this.append(viewer);
1542
+ });
1543
+ }
1523
1544
  return new Promise((accept, reject) => {
1524
- viewer.onload = () => {
1525
- return accept(viewer);
1526
- };
1527
- this.append(viewer);
1545
+ return accept(viewer);
1528
1546
  });
1529
1547
  }
1530
1548
  async startRenderer() {
@@ -1684,15 +1702,20 @@ class LauncherController extends plattar_controller_1.PlattarController {
1684
1702
  if (showBanner) {
1685
1703
  viewer.setAttribute("show-ar-banner", showBanner);
1686
1704
  }
1687
- if (configState) {
1688
- const encodedState = configState.state.encode();
1689
- if (encodedState.length < 6000) {
1690
- viewer.setAttribute("config-state", encodedState);
1691
- }
1692
- }
1693
1705
  if (sceneGraphID) {
1694
1706
  viewer.setAttribute("scene-graph-id", sceneGraphID);
1695
1707
  }
1708
+ else {
1709
+ try {
1710
+ const sceneGraphID = await (await this.getConfiguratorState()).state.encodeSceneGraphID();
1711
+ viewer.setAttribute("scene-graph-id", sceneGraphID);
1712
+ }
1713
+ catch (_err) {
1714
+ // scene graph ID not available for some reason
1715
+ // we will generate a new one
1716
+ console.error(_err);
1717
+ }
1718
+ }
1696
1719
  return new Promise((accept, reject) => {
1697
1720
  this.append(viewer);
1698
1721
  if (configState) {
@@ -1803,12 +1826,15 @@ class PlattarController {
1803
1826
  /**
1804
1827
  * Default QR Code rendering options
1805
1828
  */
1806
- _GetDefaultQROptions() {
1829
+ _GetDefaultQROptions(opt = null) {
1830
+ const options = opt ?? {};
1807
1831
  return {
1808
- color: this.getAttribute("qr-color") || "#101721",
1809
- qrType: this.getAttribute("qr-style") || "default",
1810
- shorten: this.getAttribute("qr-shorten") || true,
1811
- margin: 0
1832
+ color: options.color ?? (this.getAttribute("qr-color") || "#101721"),
1833
+ qrType: options.qrType ?? (this.getAttribute("qr-style") || "default"),
1834
+ shorten: options.shorten ?? (this.getBooleanAttribute("qr-shorten") || true),
1835
+ margin: options.margin ?? 0,
1836
+ detached: options.detached ?? (this.getBooleanAttribute("qr-detached") || false),
1837
+ url: options.url ?? null
1812
1838
  };
1813
1839
  }
1814
1840
  ;
@@ -1927,11 +1953,13 @@ class PlattarController {
1927
1953
  * @returns
1928
1954
  */
1929
1955
  async startARQRCode(options) {
1930
- // remove the old renderer instance if any
1931
- this.removeRenderer();
1932
- const opt = options || this._GetDefaultQROptions();
1956
+ const opt = this._GetDefaultQROptions(options);
1933
1957
  const viewer = document.createElement("plattar-qrcode");
1934
- this._element = viewer;
1958
+ // remove the old renderer instance if any
1959
+ if (!opt.detached) {
1960
+ this.removeRenderer();
1961
+ this._element = viewer;
1962
+ }
1935
1963
  // required attributes with defaults for plattar-viewer node
1936
1964
  const width = this.getAttribute("width") || "500px";
1937
1965
  const height = this.getAttribute("height") || "500px";
@@ -1941,7 +1969,7 @@ class PlattarController {
1941
1969
  viewer.setAttribute("color", opt.color);
1942
1970
  }
1943
1971
  if (opt.margin) {
1944
- viewer.setAttribute("margin", "" + opt.margin);
1972
+ viewer.setAttribute("margin", `${opt.margin}`);
1945
1973
  }
1946
1974
  if (opt.qrType) {
1947
1975
  viewer.setAttribute("qr-type", opt.qrType);
@@ -1949,7 +1977,7 @@ class PlattarController {
1949
1977
  viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
1950
1978
  const qrOptions = btoa(JSON.stringify(opt));
1951
1979
  let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
1952
- let configState = null;
1980
+ //let configState: string | null = null;
1953
1981
  const sceneID = this.getAttribute("scene-id");
1954
1982
  const embedType = this.getAttribute("embed-type");
1955
1983
  const productID = this.getAttribute("product-id");
@@ -1959,16 +1987,6 @@ class PlattarController {
1959
1987
  const arMode = this.getAttribute("ar-mode");
1960
1988
  const showBanner = this.getAttribute("show-ar-banner");
1961
1989
  const sceneGraphID = this.getAttribute("scene-graph-id");
1962
- try {
1963
- configState = (await this.getConfiguratorState()).state.encode();
1964
- }
1965
- catch (_err) {
1966
- // config state not available for some reason
1967
- configState = null;
1968
- }
1969
- if (configState) {
1970
- dst += "&config_state=" + configState;
1971
- }
1972
1990
  if (embedType) {
1973
1991
  dst += "&embed_type=" + embedType;
1974
1992
  }
@@ -1996,14 +2014,30 @@ class PlattarController {
1996
2014
  if (sceneGraphID) {
1997
2015
  dst += "&scene_graph_id" + sceneGraphID;
1998
2016
  }
2017
+ else {
2018
+ try {
2019
+ const sceneGraphID = await (await this.getConfiguratorState()).state.encodeSceneGraphID();
2020
+ dst += "&scene_graph_id=" + sceneGraphID;
2021
+ }
2022
+ catch (_err) {
2023
+ // scene graph ID not available for some reason
2024
+ // we will generate a new one
2025
+ console.error(_err);
2026
+ }
2027
+ }
1999
2028
  viewer.setAttribute("url", opt.url || dst);
2000
- this._state = ControllerState.QRCode;
2001
2029
  this._prevQROpt = opt;
2030
+ if (!opt.detached) {
2031
+ this._state = ControllerState.QRCode;
2032
+ return new Promise((accept, reject) => {
2033
+ this.append(viewer);
2034
+ viewer.onload = () => {
2035
+ return accept(viewer);
2036
+ };
2037
+ });
2038
+ }
2002
2039
  return new Promise((accept, reject) => {
2003
- this.append(viewer);
2004
- viewer.onload = () => {
2005
- return accept(viewer);
2006
- };
2040
+ return accept(viewer);
2007
2041
  });
2008
2042
  }
2009
2043
  /**
@@ -2397,15 +2431,19 @@ class VTOController extends plattar_controller_1.PlattarController {
2397
2431
  }
2398
2432
  }
2399
2433
  async startViewerQRCode(options) {
2434
+ const opt = this._GetDefaultQROptions(options);
2400
2435
  // remove the old renderer instance if any
2401
- this.removeRenderer();
2436
+ if (!opt.detached) {
2437
+ this.removeRenderer();
2438
+ }
2402
2439
  const sceneID = this.getAttribute("scene-id");
2403
2440
  if (!sceneID) {
2404
2441
  throw new Error("VTOController.startQRCode() - minimum required attributes not set, use scene-id as a minimum");
2405
2442
  }
2406
- const opt = options || this._GetDefaultQROptions();
2407
2443
  const viewer = document.createElement("plattar-qrcode");
2408
- this._element = viewer;
2444
+ if (!opt.detached) {
2445
+ this._element = viewer;
2446
+ }
2409
2447
  // required attributes with defaults for plattar-viewer node
2410
2448
  const width = this.getAttribute("width") || "500px";
2411
2449
  const height = this.getAttribute("height") || "500px";
@@ -2451,13 +2489,18 @@ class VTOController extends plattar_controller_1.PlattarController {
2451
2489
  dst += "&variation_id=" + variationID;
2452
2490
  }
2453
2491
  viewer.setAttribute("url", opt.url || dst);
2454
- this._state = plattar_controller_1.ControllerState.QRCode;
2455
2492
  this._prevQROpt = opt;
2493
+ if (!opt.detached) {
2494
+ this._state = plattar_controller_1.ControllerState.QRCode;
2495
+ return new Promise((accept, reject) => {
2496
+ viewer.onload = () => {
2497
+ return accept(viewer);
2498
+ };
2499
+ this.append(viewer);
2500
+ });
2501
+ }
2456
2502
  return new Promise((accept, reject) => {
2457
- viewer.onload = () => {
2458
- return accept(viewer);
2459
- };
2460
- this.append(viewer);
2503
+ return accept(viewer);
2461
2504
  });
2462
2505
  }
2463
2506
  async startRenderer() {
@@ -3516,6 +3559,37 @@ class ConfiguratorState {
3516
3559
  encode() {
3517
3560
  return btoa(JSON.stringify(this._state));
3518
3561
  }
3562
+ async encodeSceneGraphID() {
3563
+ const graph = this.sceneGraph;
3564
+ // some scene-graphs are very large in size, we store it remotely
3565
+ // this storage will expire in 10 minutes so this is a non-permanent version
3566
+ // and is designed for quick ar
3567
+ const url = `https://c.plattar.com/v3/redir/store`;
3568
+ // finally send our scene-graph to the backend to generate the AR file and return
3569
+ try {
3570
+ const response = await fetch(url, {
3571
+ method: "POST",
3572
+ headers: {
3573
+ "Content-Type": "application/json"
3574
+ },
3575
+ body: JSON.stringify({
3576
+ data: {
3577
+ attributes: {
3578
+ data: graph
3579
+ }
3580
+ }
3581
+ })
3582
+ });
3583
+ if (!response.ok) {
3584
+ throw new Error(`ConfiguratorState.encodeSceneGraphID() - network response was not ok ${response.status}`);
3585
+ }
3586
+ const data = await response.json();
3587
+ return data.data.id;
3588
+ }
3589
+ catch (error) {
3590
+ throw new Error(`ConfiguratorState.encodeSceneGraphID() - there was a request error to ${url}, error was ${error.message}`);
3591
+ }
3592
+ }
3519
3593
  /**
3520
3594
  * Compiles and returns the Dynamic Scene Graph (Updated for 2025 for DynamicAR)
3521
3595
  * NOTE: Eventually this structure should replace ConfiguratorState
@@ -3653,7 +3727,7 @@ exports.Util = Util;
3653
3727
  },{}],20:[function(require,module,exports){
3654
3728
  "use strict";
3655
3729
  Object.defineProperty(exports, "__esModule", { value: true });
3656
- exports.default = "1.188.3";
3730
+ exports.default = "1.188.4";
3657
3731
 
3658
3732
  },{}],21:[function(require,module,exports){
3659
3733
  "use strict";