@plattar/plattar-ar-adapter 1.172.1 → 1.178.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.
@@ -0,0 +1,15 @@
1
+ import { LauncherAR } from "../../ar/launcher-ar";
2
+ import { DecodedConfiguratorState } from "../../util/configurator-state";
3
+ import { PlattarController } from "./plattar-controller";
4
+ /**
5
+ * Manages an instance of the <plattar-configurator> HTML Element
6
+ */
7
+ export declare class GalleryController extends PlattarController {
8
+ private _cachedConfigState;
9
+ getConfiguratorState(): Promise<DecodedConfiguratorState>;
10
+ onAttributesUpdated(attributeName: string): Promise<void>;
11
+ startViewerQRCode(options: any): Promise<HTMLElement>;
12
+ startRenderer(): Promise<HTMLElement>;
13
+ initAR(): Promise<LauncherAR>;
14
+ get element(): HTMLElement | null;
15
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GalleryController = void 0;
4
+ const plattar_api_1 = require("@plattar/plattar-api");
5
+ const plattar_controller_1 = require("./plattar-controller");
6
+ /**
7
+ * Manages an instance of the <plattar-configurator> HTML Element
8
+ */
9
+ class GalleryController extends plattar_controller_1.PlattarController {
10
+ constructor() {
11
+ super(...arguments);
12
+ this._cachedConfigState = null;
13
+ }
14
+ async getConfiguratorState() {
15
+ if (this._cachedConfigState) {
16
+ return this._cachedConfigState;
17
+ }
18
+ this._cachedConfigState = this.createConfiguratorState();
19
+ return this._cachedConfigState;
20
+ }
21
+ async onAttributesUpdated(attributeName) {
22
+ const state = this._state;
23
+ // re-render the QR Code when attributes have changed
24
+ if (state === plattar_controller_1.ControllerState.QRCode) {
25
+ if (attributeName === "variation-id") {
26
+ const configState = await this.getConfiguratorState();
27
+ const variationIDs = this.getAttribute("variation-id");
28
+ const variationIDsList = variationIDs ? variationIDs.split(",") : [];
29
+ variationIDsList.forEach((variationID) => {
30
+ configState.state.setVariationID(variationID);
31
+ });
32
+ }
33
+ if (attributeName === "variation-sku") {
34
+ const configState = await this.getConfiguratorState();
35
+ const variationSKUs = this.getAttribute("variation-sku");
36
+ const variationSKUList = variationSKUs ? variationSKUs.split(",") : [];
37
+ variationSKUList.forEach((variationSKU) => {
38
+ configState.state.setVariationSKU(variationSKU);
39
+ });
40
+ }
41
+ this.startQRCode(this._prevQROpt);
42
+ return;
43
+ }
44
+ }
45
+ async startViewerQRCode(options) {
46
+ // remove the old renderer instance if any
47
+ this.removeRenderer();
48
+ const sceneID = this.getAttribute("scene-id");
49
+ if (!sceneID) {
50
+ throw new Error("GalleryController.startViewerQRCode() - minimum required attributes not set, use scene-id as a minimum");
51
+ }
52
+ const opt = options || this._GetDefaultQROptions();
53
+ const viewer = document.createElement("plattar-qrcode");
54
+ this._element = viewer;
55
+ // required attributes with defaults for plattar-viewer node
56
+ const width = this.getAttribute("width") || "500px";
57
+ const height = this.getAttribute("height") || "500px";
58
+ viewer.setAttribute("width", width);
59
+ viewer.setAttribute("height", height);
60
+ if (opt.color) {
61
+ viewer.setAttribute("color", opt.color);
62
+ }
63
+ if (opt.margin) {
64
+ viewer.setAttribute("margin", "" + opt.margin);
65
+ }
66
+ if (opt.qrType) {
67
+ viewer.setAttribute("qr-type", opt.qrType);
68
+ }
69
+ viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
70
+ const dst = plattar_api_1.Server.location().base + "renderer/gallery.html?scene_id=" + sceneID;
71
+ viewer.setAttribute("url", opt.url || dst);
72
+ this._state = plattar_controller_1.ControllerState.QRCode;
73
+ this._prevQROpt = opt;
74
+ return new Promise((accept, reject) => {
75
+ viewer.onload = () => {
76
+ return accept(viewer);
77
+ };
78
+ this.append(viewer);
79
+ });
80
+ }
81
+ async startRenderer() {
82
+ // remove the old renderer instance if any
83
+ this.removeRenderer();
84
+ const sceneID = this.getAttribute("scene-id");
85
+ if (!sceneID) {
86
+ throw new Error("GalleryController.startRenderer() - minimum required attributes not set, use scene-id as a minimum");
87
+ }
88
+ this._state = plattar_controller_1.ControllerState.Renderer;
89
+ // required attributes with defaults for plattar-configurator node
90
+ const width = this.getAttribute("width") || "500px";
91
+ const height = this.getAttribute("height") || "500px";
92
+ const server = this.getAttribute("server") || "production";
93
+ const viewer = document.createElement("plattar-gallery");
94
+ this._element = viewer;
95
+ viewer.setAttribute("width", width);
96
+ viewer.setAttribute("height", height);
97
+ viewer.setAttribute("server", server);
98
+ viewer.setAttribute("scene-id", sceneID);
99
+ return new Promise((accept, reject) => {
100
+ this.append(viewer);
101
+ return accept(viewer);
102
+ });
103
+ }
104
+ async initAR() {
105
+ throw new Error("GalleryController.initAR() - cannot proceed as AR not available in gallery context");
106
+ }
107
+ get element() {
108
+ return this._element;
109
+ }
110
+ }
111
+ exports.GalleryController = GalleryController;
@@ -0,0 +1,24 @@
1
+ import { LauncherAR } from "../../ar/launcher-ar";
2
+ import { DecodedConfiguratorState } from "../../util/configurator-state";
3
+ import { PlattarController } from "./plattar-controller";
4
+ /**
5
+ * Manages an instance of the <plattar-configurator> HTML Element
6
+ */
7
+ export declare class LauncherController extends PlattarController {
8
+ private _cachedConfigState;
9
+ getConfiguratorState(): Promise<DecodedConfiguratorState>;
10
+ onAttributesUpdated(attributeName: string): Promise<void>;
11
+ startARQRCode(options: any): Promise<HTMLElement>;
12
+ startViewerQRCode(options: any): Promise<HTMLElement>;
13
+ startRenderer(): Promise<HTMLElement>;
14
+ initAR(): Promise<LauncherAR>;
15
+ /**
16
+ * Private Function - This launches the Static/Inherited AR Mode
17
+ */
18
+ private _InitARInherited;
19
+ /**
20
+ * Private Function - This launches the Dynamic/Generated AR Mode
21
+ */
22
+ private _InitARGenerated;
23
+ get element(): HTMLElement | null;
24
+ }
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LauncherController = void 0;
4
+ const scene_product_ar_1 = require("../../ar/scene-product-ar");
5
+ const util_1 = require("../../util/util");
6
+ const plattar_controller_1 = require("./plattar-controller");
7
+ const configurator_ar_1 = require("../../ar/configurator-ar");
8
+ /**
9
+ * Manages an instance of the <plattar-configurator> HTML Element
10
+ */
11
+ class LauncherController extends plattar_controller_1.PlattarController {
12
+ constructor() {
13
+ super(...arguments);
14
+ this._cachedConfigState = null;
15
+ }
16
+ async getConfiguratorState() {
17
+ if (this._cachedConfigState) {
18
+ return this._cachedConfigState;
19
+ }
20
+ this._cachedConfigState = this.createConfiguratorState();
21
+ return this._cachedConfigState;
22
+ }
23
+ async onAttributesUpdated(attributeName) {
24
+ const state = this._state;
25
+ // re-render the QR Code when attributes have changed
26
+ if (state === plattar_controller_1.ControllerState.QRCode) {
27
+ if (attributeName === "variation-id") {
28
+ const configState = await this.getConfiguratorState();
29
+ const variationIDs = this.getAttribute("variation-id");
30
+ const variationIDsList = variationIDs ? variationIDs.split(",") : [];
31
+ variationIDsList.forEach((variationID) => {
32
+ configState.state.setVariationID(variationID);
33
+ });
34
+ }
35
+ if (attributeName === "variation-sku") {
36
+ const configState = await this.getConfiguratorState();
37
+ const variationSKUs = this.getAttribute("variation-sku");
38
+ const variationSKUList = variationSKUs ? variationSKUs.split(",") : [];
39
+ variationSKUList.forEach((variationSKU) => {
40
+ configState.state.setVariationSKU(variationSKU);
41
+ });
42
+ }
43
+ this.startQRCode(this._prevQROpt);
44
+ return;
45
+ }
46
+ }
47
+ async startARQRCode(options) {
48
+ try {
49
+ const dState = await this.getConfiguratorState();
50
+ // if this is declared, we have a furniture scene that we need to re-create the embed
51
+ // with new attributes
52
+ const product = dState.state.firstOfType("product");
53
+ if (product) {
54
+ this.parent.lockObserver();
55
+ this.parent.destroy();
56
+ this.setAttribute("product-id", product.scene_product_id);
57
+ this.removeAttribute("scene-id");
58
+ this.parent.unlockObserver();
59
+ const controller = this.parent.create();
60
+ if (controller) {
61
+ return controller.startARQRCode(options);
62
+ }
63
+ return Promise.reject(new Error("LauncherController.startARQRCode() - legacy product transition failed"));
64
+ }
65
+ }
66
+ catch (_err) {
67
+ }
68
+ return super.startARQRCode(options);
69
+ }
70
+ async startViewerQRCode(options) {
71
+ return this.startARQRCode(options);
72
+ }
73
+ async startRenderer() {
74
+ // remove the old renderer instance if any
75
+ this.removeRenderer();
76
+ const sceneID = this.getAttribute("scene-id");
77
+ if (!sceneID) {
78
+ throw new Error("LauncherController.startRenderer() - minimum required attributes not set, use scene-id as a minimum");
79
+ }
80
+ // optional attributes
81
+ const configState = await this.getConfiguratorState();
82
+ this._state = plattar_controller_1.ControllerState.Renderer;
83
+ const qrOptions = btoa(JSON.stringify(this._GetDefaultQROptions()));
84
+ const embedType = this.getAttribute("embed-type");
85
+ const productID = this.getAttribute("product-id");
86
+ const sceneProductID = this.getAttribute("scene-product-id");
87
+ const variationID = this.getAttribute("variation-id");
88
+ const variationSKU = this.getAttribute("variation-sku");
89
+ const arMode = this.getAttribute("ar-mode");
90
+ const showBanner = this.getAttribute("show-ar-banner");
91
+ // required attributes with defaults for plattar-launcher node
92
+ const width = this.getAttribute("width") || "500px";
93
+ const height = this.getAttribute("height") || "500px";
94
+ const server = this.getAttribute("server") || "production";
95
+ const viewer = document.createElement("plattar-launcher");
96
+ this._element = viewer;
97
+ viewer.setAttribute("width", width);
98
+ viewer.setAttribute("height", height);
99
+ viewer.setAttribute("server", server);
100
+ viewer.setAttribute("scene-id", sceneID);
101
+ viewer.setAttribute("qr-options", qrOptions);
102
+ if (embedType) {
103
+ viewer.setAttribute("embed-type", embedType);
104
+ }
105
+ if (productID) {
106
+ viewer.setAttribute("product-id", productID);
107
+ }
108
+ if (sceneProductID) {
109
+ viewer.setAttribute("scene-product-id", sceneProductID);
110
+ }
111
+ if (variationID) {
112
+ viewer.setAttribute("variation-id", variationID);
113
+ }
114
+ if (variationSKU) {
115
+ viewer.setAttribute("variation-sku", variationSKU);
116
+ }
117
+ if (arMode) {
118
+ viewer.setAttribute("ar-mode", arMode);
119
+ }
120
+ if (showBanner) {
121
+ viewer.setAttribute("show-ar-banner", showBanner);
122
+ }
123
+ if (configState) {
124
+ const encodedState = configState.state.encode();
125
+ if (encodedState.length < 6000) {
126
+ viewer.setAttribute("config-state", encodedState);
127
+ }
128
+ }
129
+ return new Promise((accept, reject) => {
130
+ this.append(viewer);
131
+ if (configState) {
132
+ this.setupMessengerObservers(viewer, configState);
133
+ }
134
+ return accept(viewer);
135
+ });
136
+ }
137
+ async initAR() {
138
+ if (!util_1.Util.canAugment()) {
139
+ throw new Error("LauncherController.initAR() - cannot proceed as AR not available in context");
140
+ }
141
+ try {
142
+ const dState = await this.getConfiguratorState();
143
+ // if this is declared, we have a furniture scene that we need to re-create the embed
144
+ // with new attributes
145
+ const product = dState.state.firstOfType("product");
146
+ if (product) {
147
+ this.parent.lockObserver();
148
+ this.parent.destroy();
149
+ this.setAttribute("product-id", product.scene_product_id);
150
+ this.removeAttribute("scene-id");
151
+ this.parent.unlockObserver();
152
+ const controller = this.parent.create();
153
+ if (controller) {
154
+ return controller.initAR();
155
+ }
156
+ return Promise.reject(new Error("LauncherController.initAR() - legacy product transition failed"));
157
+ }
158
+ }
159
+ catch (_err) {
160
+ // config state is not available
161
+ }
162
+ const arMode = this.getAttribute("ar-mode") || "generated";
163
+ switch (arMode.toLowerCase()) {
164
+ case "inherited":
165
+ return this._InitARInherited();
166
+ case "generated":
167
+ default:
168
+ return this._InitARGenerated();
169
+ }
170
+ }
171
+ /**
172
+ * Private Function - This launches the Static/Inherited AR Mode
173
+ */
174
+ async _InitARInherited() {
175
+ const sceneID = this.getAttribute("scene-id");
176
+ if (!sceneID) {
177
+ throw new Error("LauncherController.initAR() - inherited AR minimum required attributes not set, use scene-id as a minimum");
178
+ }
179
+ const state = (await this.getConfiguratorState()).state;
180
+ const first = state.first();
181
+ if (first) {
182
+ //const sceneProductAR: SceneProductAR = new SceneProductAR(first.scene_product_id, first.product_variation_id);
183
+ const sceneProductAR = new scene_product_ar_1.SceneProductAR({
184
+ productID: first.scene_product_id,
185
+ variationID: first.product_variation_id,
186
+ variationSKU: null,
187
+ useARBanner: this.getBooleanAttribute("show-ar-banner")
188
+ });
189
+ return sceneProductAR.init();
190
+ }
191
+ throw new Error("LauncherController.initAR() - invalid decoded config-state does not have any product states");
192
+ }
193
+ /**
194
+ * Private Function - This launches the Dynamic/Generated AR Mode
195
+ */
196
+ async _InitARGenerated() {
197
+ const sceneID = this.getAttribute("scene-id");
198
+ if (!sceneID) {
199
+ throw new Error("LauncherController.initAR() - generated AR minimum required attributes not set, use scene-id as a minimum");
200
+ }
201
+ const configAR = new configurator_ar_1.ConfiguratorAR({ state: await this.getConfiguratorState(), useARBanner: this.getBooleanAttribute("show-ar-banner") });
202
+ return configAR.init();
203
+ }
204
+ get element() {
205
+ return this._element;
206
+ }
207
+ }
208
+ exports.LauncherController = LauncherController;
@@ -6,6 +6,8 @@ const vto_controller_1 = require("./controllers/vto-controller");
6
6
  const product_controller_1 = require("./controllers/product-controller");
7
7
  const util_1 = require("../util/util");
8
8
  const webxr_controller_1 = require("./controllers/webxr-controller");
9
+ const gallery_controller_1 = require("./controllers/gallery-controller");
10
+ const launcher_controller_1 = require("./controllers/launcher-controller");
9
11
  /**
10
12
  * This tracks the current embed type
11
13
  */
@@ -15,7 +17,9 @@ var EmbedType;
15
17
  EmbedType[EmbedType["Legacy"] = 1] = "Legacy";
16
18
  EmbedType[EmbedType["VTO"] = 2] = "VTO";
17
19
  EmbedType[EmbedType["WebXR"] = 3] = "WebXR";
18
- EmbedType[EmbedType["None"] = 4] = "None";
20
+ EmbedType[EmbedType["Gallery"] = 4] = "Gallery";
21
+ EmbedType[EmbedType["Launcher"] = 5] = "Launcher";
22
+ EmbedType[EmbedType["None"] = 6] = "None";
19
23
  })(EmbedType || (EmbedType = {}));
20
24
  /**
21
25
  * Controls the state of the observer
@@ -158,6 +162,12 @@ class PlattarEmbed extends HTMLElement {
158
162
  case "webxr":
159
163
  this._currentType = EmbedType.WebXR;
160
164
  break;
165
+ case "gallery":
166
+ this._currentType = EmbedType.Gallery;
167
+ break;
168
+ case "launcher":
169
+ this._currentType = EmbedType.Launcher;
170
+ break;
161
171
  case "viewer":
162
172
  case "configurator":
163
173
  default:
@@ -189,6 +199,12 @@ class PlattarEmbed extends HTMLElement {
189
199
  case EmbedType.WebXR:
190
200
  this._controller = new webxr_controller_1.WebXRController(this);
191
201
  break;
202
+ case EmbedType.Gallery:
203
+ this._controller = new gallery_controller_1.GalleryController(this);
204
+ break;
205
+ case EmbedType.Launcher:
206
+ this._controller = new launcher_controller_1.LauncherController(this);
207
+ break;
192
208
  case EmbedType.VTO:
193
209
  this._controller = new vto_controller_1.VTOController(this);
194
210
  break;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="@plattar/plattar-web" />
2
- /// <reference types="@plattar/plattar-qrcode" />
3
1
  export * as PlattarWeb from "@plattar/plattar-web";
4
2
  export * as PlattarQRCode from "@plattar/plattar-qrcode";
5
3
  export * as version from "./version";
package/dist/index.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.172.1";
1
+ declare const _default: "1.178.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.172.1";
3
+ exports.default = "1.178.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.172.1",
3
+ "version": "1.178.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,18 +38,18 @@
38
38
  "homepage": "https://www.plattar.com",
39
39
  "dependencies": {
40
40
  "@plattar/plattar-analytics": "^1.152.2",
41
- "@plattar/plattar-api": "^1.159.1",
41
+ "@plattar/plattar-api": "^1.178.1",
42
42
  "@plattar/plattar-qrcode": "1.165.1",
43
43
  "@plattar/plattar-services": "^1.157.1",
44
- "@plattar/plattar-web": "^1.169.1"
44
+ "@plattar/plattar-web": "^1.178.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/cli": "^7.24.6",
48
- "@babel/core": "^7.24.6",
49
- "@babel/preset-env": "^7.24.6",
50
- "browserify": "^17.0.0",
51
- "typescript": "^5.4.5",
52
- "uglify-js": "^3.17.4"
47
+ "@babel/cli": "^7.25.9",
48
+ "@babel/core": "^7.26.0",
49
+ "@babel/preset-env": "^7.26.0",
50
+ "browserify": "^17.0.1",
51
+ "typescript": "^5.7.2",
52
+ "uglify-js": "^3.19.3"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"