@roomle/embedding-lib 5.6.0 → 5.7.0-debug.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.
@@ -1,183 +1,190 @@
1
- var M = Object.defineProperty;
2
- var v = (t, e, s) => e in t ? M(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
- var c = (t, e, s) => v(t, typeof e != "symbol" ? e + "" : e, s);
4
- class P {
5
- constructor(e, s, r, o) {
1
+ var C = Object.defineProperty;
2
+ var F = (r, s, e) => s in r ? C(r, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[s] = e;
3
+ var c = (r, s, e) => F(r, typeof s != "symbol" ? s + "" : s, e);
4
+ class M {
5
+ constructor(s, e, n, t) {
6
6
  c(this, "_side");
7
7
  // for better debugging (who handles message? iframe or website?)
8
- c(this, "_incomingMessageBus");
8
+ c(this, "_incomingMessageBus", null);
9
9
  c(this, "_outgoingMessageBus", null);
10
10
  c(this, "_execMessage", null);
11
- this._side = e, this._incomingMessageBus = s, this._outgoingMessageBus = r, this._execMessage = o, this._incomingMessageBus.addEventListener(
11
+ this._side = s, this._incomingMessageBus = e, this._outgoingMessageBus = n, this._execMessage = t, this._incomingMessageBus && this._incomingMessageBus.addEventListener(
12
12
  "message",
13
13
  this._handleMessage.bind(this)
14
14
  );
15
15
  }
16
- setOutgoingMessageBus(e) {
17
- this._outgoingMessageBus = e;
16
+ setOutgoingMessageBus(s) {
17
+ this._outgoingMessageBus = s;
18
18
  }
19
- setMessageExecution(e) {
20
- this._execMessage = e;
19
+ setMessageExecution(s) {
20
+ this._execMessage = s;
21
21
  }
22
- sendMessage(e, s = []) {
23
- return new Promise((r, o) => {
24
- const i = new MessageChannel();
25
- i.port1.onmessage = (n) => {
26
- if (!n || !n.data)
27
- return i.port1.close(), i.port2.close(), o(
22
+ sendMessage(s, e = []) {
23
+ return new Promise((n, t) => {
24
+ if (this._incomingMessageBus === this._outgoingMessageBus)
25
+ return n(void 0);
26
+ const o = new MessageChannel();
27
+ o.port1.onmessage = (i) => {
28
+ if (!i || !i.data)
29
+ return o.port1.close(), o.port2.close(), t(
28
30
  new Error(
29
31
  this._side + " received message but response can not be interpreted"
30
32
  )
31
33
  );
32
34
  let l;
33
35
  try {
34
- l = JSON.parse(n.data);
35
- } catch (a) {
36
- return i.port1.close(), i.port2.close(), this._prepareError(a), o(a);
36
+ l = JSON.parse(i.data);
37
+ } catch (d) {
38
+ return o.port1.close(), o.port2.close(), this._prepareError(d), t(d);
37
39
  }
38
- l.error ? o(l.error) : l.result !== void 0 ? r(l.result) : r(void 0), i.port1.close(), i.port2.close();
40
+ l.error ? t(l.error) : l.result !== void 0 ? n(l.result) : n(void 0), o.port1.close(), o.port2.close();
39
41
  };
40
- let g = "";
42
+ let a = "";
41
43
  try {
42
- g = JSON.stringify({ message: e, args: s });
44
+ a = JSON.stringify({ message: s, args: e });
43
45
  } catch {
44
- return o(
46
+ return t(
45
47
  new Error(
46
48
  this._side + ": can not create command because it is not JSON.stringify able"
47
49
  )
48
50
  );
49
51
  }
50
52
  if (!this._outgoingMessageBus)
51
- return o(new Error(this._side + ": outgoing bus not set yet"));
52
- this._outgoingMessageBus.postMessage(g, "*", [
53
- i.port2
53
+ return t(new Error(this._side + ": outgoing bus not set yet"));
54
+ this._outgoingMessageBus.postMessage(a, "*", [
55
+ o.port2
54
56
  ]);
55
57
  });
56
58
  }
57
- _handleMessage(e) {
58
- const s = e.ports && Array.isArray(e.ports) && e.ports.length > 0 ? e.ports[0] : null;
59
- if (e.data && s)
59
+ _handleMessage(s) {
60
+ const e = s.ports && Array.isArray(s.ports) && s.ports.length > 0 ? s.ports[0] : null;
61
+ if (s.data && e)
60
62
  try {
61
- const r = JSON.parse(e.data);
63
+ const n = JSON.parse(s.data);
62
64
  if (!this._execMessage)
63
- return s.postMessage(
65
+ return e.postMessage(
64
66
  JSON.stringify({
65
67
  error: this._side + " is not ready to handle messages"
66
68
  })
67
69
  );
68
- Array.isArray(r.args) || (r.args = [r.args]);
69
- const o = this._execMessage(r, e);
70
- if (o === void 0)
70
+ Array.isArray(n.args) || (n.args = [n.args]);
71
+ const t = this._execMessage(n, s);
72
+ if (t === void 0)
71
73
  return;
72
- o.then(
73
- (i = {}) => {
74
- let g, n;
75
- typeof i == "object" && i !== null && (g = i.error, n = i.result), g ? s.postMessage(
76
- JSON.stringify({ error: g })
77
- ) : n !== void 0 ? s.postMessage(
78
- JSON.stringify({ result: n })
79
- ) : s.postMessage(
74
+ t.then(
75
+ (o = {}) => {
76
+ let a, i;
77
+ typeof o == "object" && o !== null && (a = o.error, i = o.result), a ? e.postMessage(
78
+ JSON.stringify({ error: a })
79
+ ) : i !== void 0 ? e.postMessage(
80
80
  JSON.stringify({ result: i })
81
+ ) : e.postMessage(
82
+ JSON.stringify({ result: o })
81
83
  );
82
84
  },
83
- (i) => {
84
- s.postMessage(
85
+ (o) => {
86
+ e.postMessage(
85
87
  JSON.stringify({
86
- error: this._prepareError(i)
88
+ error: this._prepareError(o)
87
89
  })
88
90
  );
89
91
  }
90
92
  );
91
- } catch (r) {
92
- s.postMessage(
93
+ } catch (n) {
94
+ e.postMessage(
93
95
  JSON.stringify({
94
- error: this._prepareError(r)
96
+ error: this._prepareError(n)
95
97
  })
96
98
  );
97
99
  }
98
100
  }
99
- _prepareError(e) {
100
- if (typeof e == "string") {
101
- const s = this._side + ": " + e;
102
- return console.error(s), s;
101
+ _prepareError(s) {
102
+ if (typeof s == "string") {
103
+ const e = this._side + ": " + s;
104
+ return console.error(e), e;
103
105
  }
104
- return e.message = this._side + ": " + e.message, console.error(e), e.message;
106
+ return s.message = this._side + ": " + s.message, console.error(s), s.message;
105
107
  }
106
108
  }
107
109
  const p = ".", E = {
108
110
  REQUEST_BOOT: "requestBoot",
109
111
  SETUP: "setup",
110
112
  WEBSITE_READY: "websiteReady"
111
- }, D = async (t, e) => {
112
- if (typeof t != "string")
113
+ }, _ = {
114
+ GET_METHODS: "getMethods",
115
+ RETURN_METHODS: "returnMethods",
116
+ REGISTER_CUSTOM_VIEW: "registerCustomView",
117
+ REGISTER_CUSTOM_VIEW_DONE: "registerCustomViewDone"
118
+ }, U = async (r, s) => {
119
+ if (typeof r != "string")
113
120
  throw new Error(
114
- 'Configurator ID is not a string type: "' + typeof t + '"'
121
+ 'Configurator ID is not a string type: "' + typeof r + '"'
115
122
  );
116
- const s = e.customApiUrl ? e.customApiUrl : "https://api.roomle.com/v2", r = e.overrideTenant || 9, o = s + "/configurators/" + t, i = "roomle_portal_v2", g = "03-" + window.btoa((/* @__PURE__ */ new Date()).toISOString() + ";anonymous;" + i), n = () => {
117
- const u = {
118
- apiKey: i,
119
- currentTenant: r,
123
+ const e = s.customApiUrl ? s.customApiUrl : "https://api.roomle.com/v2", n = s.overrideTenant || 9, t = e + "/configurators/" + r, o = "roomle_portal_v2", a = "03-" + window.btoa((/* @__PURE__ */ new Date()).toISOString() + ";anonymous;" + o), i = () => {
124
+ const h = {
125
+ apiKey: o,
126
+ currentTenant: n,
120
127
  locale: "en",
121
128
  language: "en",
122
129
  device: 1,
123
- token: g,
130
+ token: a,
124
131
  platform: "web"
125
132
  };
126
- return new Headers(u);
127
- }, l = new Request(o, {
133
+ return new Headers(h);
134
+ }, l = new Request(t, {
128
135
  method: "GET",
129
- headers: n(),
136
+ headers: i(),
130
137
  mode: "cors",
131
138
  cache: "default"
132
- }), a = await fetch(l), { configurator: f } = await a.json();
133
- return f;
134
- }, H = () => {
139
+ }), d = await fetch(l), { configurator: g } = await d.json();
140
+ return g;
141
+ }, B = () => {
135
142
  try {
136
143
  return window.self !== window.top;
137
144
  } catch {
138
145
  return !0;
139
146
  }
140
- }, F = ["127.0.0.1", "localhost", "0.0.0.0"], C = () => {
141
- const t = H();
142
- let e = window.location.href;
143
- if (t) {
147
+ }, k = ["127.0.0.1", "localhost", "0.0.0.0"], W = () => {
148
+ const r = B();
149
+ let s = window.location.href;
150
+ if (r) {
144
151
  if (!document.referrer)
145
152
  return null;
146
- e = document.referrer;
153
+ s = document.referrer;
147
154
  }
148
- const { hostname: s } = new URL(e);
149
- return s;
150
- }, B = (t) => !!(F.includes(t) || t.endsWith("roomle.com") || t.endsWith("gitlab.io") || t.endsWith("gitlab.com")), A = [
155
+ const { hostname: e } = new URL(s);
156
+ return e;
157
+ }, x = (r) => !!(k.includes(r) || r.endsWith("roomle.com") || r.endsWith("gitlab.io") || r.endsWith("gitlab.com")), y = [
151
158
  "language",
152
159
  "browserLanguage",
153
160
  "userLanguage",
154
161
  "systemLanguage"
155
- ], U = (t = null) => {
156
- const e = window.navigator;
157
- if (t)
158
- return t.substr(0, 2);
159
- if (Array.isArray(e.languages) && e.languages.length > 0)
160
- return e.languages[0].substr(0, 2);
161
- for (let s = 0, r = A.length; s < r; s++) {
162
- const o = e[A[s]];
163
- if (o)
164
- return o.substr(0, 2);
162
+ ], G = (r = null) => {
163
+ const s = window.navigator;
164
+ if (r)
165
+ return r.substr(0, 2);
166
+ if (Array.isArray(s.languages) && s.languages.length > 0)
167
+ return s.languages[0].substr(0, 2);
168
+ for (let e = 0, n = y.length; e < n; e++) {
169
+ const t = s[y[e]];
170
+ if (t)
171
+ return t.substr(0, 2);
165
172
  }
166
173
  return "en";
167
- }, k = (t, e) => {
168
- const s = JSON.parse(JSON.stringify(t));
169
- return O(s, e);
170
- }, O = (t, e) => {
171
- for (const s in e)
174
+ }, V = (r, s) => {
175
+ const e = JSON.parse(JSON.stringify(r));
176
+ return S(e, s);
177
+ }, S = (r, s) => {
178
+ for (const e in s)
172
179
  try {
173
- e[s].constructor === Object ? t[s] = O(t[s], e[s]) : t[s] = e[s];
180
+ s[e].constructor === Object ? r[e] = S(r[e], s[e]) : r[e] = s[e];
174
181
  } catch {
175
- t[s] = e[s];
182
+ r[e] = s[e];
176
183
  }
177
- return t;
184
+ return r;
178
185
  };
179
- var x = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 };
180
- const W = {
186
+ var J = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1 };
187
+ const $ = {
181
188
  mobileLandscape: !0,
182
189
  floorMaterialRootTag: "materials_root",
183
190
  buttons: {
@@ -199,58 +206,39 @@ const W = {
199
206
  wallAutoHeight: !1
200
207
  },
201
208
  rotationSnapDegrees: 10
202
- }, G = "(idle)", J = (t) => (I(t), t != null && t.customApiUrl && (t.customApiUrl = decodeURIComponent(t.customApiUrl)), t.shareUrl && (t.deeplink = t.shareUrl.replace(
203
- z,
204
- Y
205
- )), t), I = (t) => {
206
- if (!t)
209
+ }, z = "(idle)", Y = (r) => (O(r), r != null && r.customApiUrl && (r.customApiUrl = decodeURIComponent(r.customApiUrl)), r.shareUrl && (r.deeplink = r.shareUrl.replace(
210
+ Q,
211
+ X
212
+ )), r), O = (r) => {
213
+ if (!r)
207
214
  return;
208
- const e = Object.keys(t);
209
- for (const s of e) {
210
- const r = t[s];
211
- if (!Array.isArray(r) && typeof r == "object" && r !== null && I(r), Array.isArray(r))
212
- for (const o of r)
213
- I(o);
214
- (r === "true" || r === "false") && (t[s] = r === "true");
215
+ const s = Object.keys(r);
216
+ for (const e of s) {
217
+ const n = r[e];
218
+ if (!Array.isArray(n) && typeof n == "object" && n !== null && O(n), Array.isArray(n))
219
+ for (const t of n)
220
+ O(t);
221
+ (n === "true" || n === "false") && (r[e] = n === "true");
215
222
  }
216
- }, V = (t, e) => {
217
- e.configuratorId = t.id;
218
- const s = t.settings || {};
219
- return !e.overrideTenant && t.tenant && (e.overrideTenant = t.tenant), k(s, e);
220
- }, $ = () => {
221
- const t = {
222
- ...W
223
+ }, q = (r, s) => {
224
+ s.configuratorId = r.id;
225
+ const e = r.settings || {};
226
+ return !s.overrideTenant && r.tenant && (s.overrideTenant = r.tenant), V(e, s);
227
+ }, K = () => {
228
+ const r = {
229
+ ...$
223
230
  };
224
- t.locale || (t.locale = U()), t.id === G && delete t.id;
225
- const e = C();
226
- return e && B(e) && (t.configuratorId = "demoConfigurator"), t.customApiUrl = x.VITE_RAPI_URL, t.emails = !1, t;
227
- }, z = "<CONF_ID>", Y = "#CONFIGURATIONID#", L = () => /(android)/i.test(navigator.userAgent), R = (t, e, s) => {
228
- let r = null;
229
- Object.defineProperty(t, e, {
230
- get() {
231
- return r || s;
232
- },
233
- set(o) {
234
- o != null && o.mute ? r = o.value : (console.warn(
235
- "You override Roomle defined behaviour. To disalbe this warning pass in an object with the following properties"
236
- ), console.warn("{ mute: true, value: () => void }"), r = o);
237
- }
238
- });
239
- }, T = () => window.innerHeight * 0.01 + "px", b = (t) => {
240
- t && setTimeout(
241
- () => t.style.setProperty(y, T()),
242
- 0
243
- );
244
- }, S = "rml-styles", q = 450, y = "--rml-full-height", d = {
245
- CONTAINER: "rml-container",
246
- FILL: "rml-fill",
247
- POSITION: "rml-pos",
248
- TRANSITION: "rml-transition",
249
- ANDROID_HEIGHT: "rml-android-height",
250
- OVERFLOW_HIDDEN: "rml-overflow-hidden"
251
- }, w = /* @__PURE__ */ new Map();
252
- class Q {
253
- constructor(e, s, r, o, i) {
231
+ r.locale || (r.locale = G()), r.id === z && delete r.id;
232
+ const s = W();
233
+ return s && x(s) && (r.configuratorId = "demoConfigurator"), r.customApiUrl = J.VITE_RAPI_URL, r.emails = !1, r;
234
+ }, Q = "<CONF_ID>", X = "#CONFIGURATIONID#", R = () => /(android)/i.test(navigator.userAgent);
235
+ class A {
236
+ constructor() {
237
+ c(this, "_messageHandler", null);
238
+ c(this, "isSetupDone", !1);
239
+ c(this, "viewName", "main");
240
+ c(this, "plugins", {});
241
+ c(this, "pluginsLoaded", []);
254
242
  c(this, "ui", {
255
243
  callbacks: null
256
244
  });
@@ -266,91 +254,204 @@ class Q {
266
254
  c(this, "global", {
267
255
  callbacks: {}
268
256
  });
269
- c(this, "plugins", {});
257
+ }
258
+ setMessageHandler(s) {
259
+ this._messageHandler = s;
260
+ }
261
+ handleSetup(s) {
262
+ const { methods: e, callbacks: n } = s;
263
+ e.forEach((t) => {
264
+ const o = t.split(p), a = o[0], i = o[1];
265
+ this[a] || (this[a] = {}), this[a][i] = (function() {
266
+ if (!this._messageHandler) {
267
+ console.error("MessageHandler not set");
268
+ return;
269
+ }
270
+ return this._messageHandler.sendMessage(t, [...arguments]);
271
+ }).bind(this);
272
+ }), n.forEach((t) => {
273
+ const o = t.split(p), a = o[0], i = o[1], l = o[2];
274
+ this[a] || (this[a] = {}), this[a][i] || (this[a][i] = {}), this[a][i][l] = () => {
275
+ };
276
+ }), this.isSetupDone = !0;
277
+ }
278
+ executeMessage({ message: s, args: e }) {
279
+ const n = s.split(p), t = n[0], o = n[1], a = n.length === 3 ? n[2] : null;
280
+ if (a && this[t][o][a]) {
281
+ const i = this[t][o][a](
282
+ ...e
283
+ );
284
+ return i instanceof Promise ? i.then((l) => ({ result: l })) : i !== void 0 ? Promise.resolve({ result: i }) : Promise.resolve({ result: null });
285
+ }
286
+ return Promise.reject('Message "' + s + '" is unkown');
287
+ }
288
+ setupPlugins(s, e, n = "website") {
289
+ for (const t of s)
290
+ typeof t == "string" && t === "dragIn" ? this.pluginsLoaded.push(
291
+ new Promise((o, a) => {
292
+ try {
293
+ import("./drag-in-3CJWP_Px.mjs").then((i) => i.l).then(
294
+ ({ DragIn: i }) => {
295
+ const l = new i(
296
+ this.ui,
297
+ e,
298
+ n,
299
+ this.viewName
300
+ );
301
+ l.init().then(() => {
302
+ this.plugins.dragIn = l, o();
303
+ }, a);
304
+ }
305
+ );
306
+ } catch (i) {
307
+ a(i);
308
+ }
309
+ })
310
+ ) : t.name && t.loader && this.pluginsLoaded.push(
311
+ new Promise((o, a) => {
312
+ try {
313
+ t.loader().then((i) => {
314
+ const l = new i(
315
+ this.ui,
316
+ e,
317
+ n,
318
+ this.viewName
319
+ );
320
+ l.init().then(() => {
321
+ this.plugins[t.name] = l, o();
322
+ }, a);
323
+ });
324
+ } catch (i) {
325
+ a(i);
326
+ }
327
+ })
328
+ );
329
+ }
330
+ }
331
+ const T = () => {
332
+ let r, s;
333
+ return { promise: new Promise((n, t) => {
334
+ r = n, s = t;
335
+ }), resolve: r, reject: s };
336
+ }, N = (r, s, e) => {
337
+ let n = null;
338
+ Object.defineProperty(r, s, {
339
+ get() {
340
+ return n || e;
341
+ },
342
+ set(t) {
343
+ t != null && t.mute ? n = t.value : (console.warn(
344
+ "You override Roomle defined behaviour. To disalbe this warning pass in an object with the following properties"
345
+ ), console.warn("{ mute: true, value: () => void }"), n = t);
346
+ }
347
+ });
348
+ }, v = () => window.innerHeight * 0.01 + "px", L = (r) => {
349
+ r && setTimeout(
350
+ () => r.style.setProperty(I, v()),
351
+ 0
352
+ );
353
+ }, b = "rml-styles", Z = 450, I = "--rml-full-height", u = {
354
+ CONTAINER: "rml-container",
355
+ FILL: "rml-fill",
356
+ POSITION: "rml-pos",
357
+ TRANSITION: "rml-transition",
358
+ ANDROID_HEIGHT: "rml-android-height",
359
+ OVERFLOW_HIDDEN: "rml-overflow-hidden"
360
+ }, w = /* @__PURE__ */ new Map();
361
+ class ee extends A {
362
+ constructor(e, n, t, o, a) {
363
+ super();
270
364
  c(this, "_waitForIframe");
271
365
  c(this, "_container");
272
- c(this, "_messageHandler");
273
366
  c(this, "_configuratorSettings");
274
367
  c(this, "_initData", {});
275
368
  c(this, "_iframe");
276
- c(this, "pluginsLoaded", []);
277
369
  if (!e || typeof e.id != "string")
278
370
  throw new Error(
279
371
  "Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person"
280
372
  );
281
- if (w.has(s))
373
+ if (w.has(n))
282
374
  throw new Error("There is already an instance on this DOM element");
283
- if (!!!document.getElementById(S)) {
284
- const l = r.zIndex || 9999999, a = document.createElement("style");
285
- a.type = "text/css", a.id = S;
286
- const f = "transition:all ease-in-out " + q + "ms;", u = ["-webkit-", "-o-"].reduce(
287
- (m, _) => m += _ + f,
375
+ if (!!!document.getElementById(b)) {
376
+ const g = t.zIndex || 9999999, h = document.createElement("style");
377
+ h.type = "text/css", h.id = b;
378
+ const f = "transition:all ease-in-out " + Z + "ms;", m = ["-webkit-", "-o-"].reduce(
379
+ (P, D) => P += D + f,
288
380
  ""
289
- ) + f, h = T();
290
- a.innerHTML = `
291
- .${d.CONTAINER}{${y}:${h};}
292
- .${d.POSITION}{position:fixed;top:0;left:0;z-index:${l};opacity:0}
293
- .${d.TRANSITION}{${u}}
294
- .${d.FILL}{width:100%;height:100%;opacity:1}
295
- .${d.ANDROID_HEIGHT}{height:calc(var(${y},1vh)*100)}
296
- .${d.OVERFLOW_HIDDEN}{overflow:hidden}
297
- `, document.head.appendChild(a);
381
+ ) + f, H = v();
382
+ h.innerHTML = `
383
+ .${u.CONTAINER}{${I}:${H};}
384
+ .${u.POSITION}{position:fixed;top:0;left:0;z-index:${g};opacity:0}
385
+ .${u.TRANSITION}{${m}}
386
+ .${u.FILL}{width:100%;height:100%;opacity:1}
387
+ .${u.ANDROID_HEIGHT}{height:calc(var(${I},1vh)*100)}
388
+ .${u.OVERFLOW_HIDDEN}{overflow:hidden}
389
+ `, document.head.appendChild(h);
298
390
  }
299
- this._onResize = this._onResize.bind(this), L() && window.addEventListener("resize", this._onResize), this._container = s, this._initData = r, this._configuratorSettings = e;
300
- const n = this._createIframe();
301
- this._onUseFullPage = this._onUseFullPage.bind(this), this._executeMessage = this._executeMessage.bind(this), this._onBackToWebsite = this._onBackToWebsite.bind(this), this._messageHandler = new P(
391
+ this._executeMessage = this._executeMessage.bind(this);
392
+ const l = new M(
302
393
  "website",
303
394
  window,
304
395
  null,
305
396
  this._executeMessage
306
- ), this._waitForIframe = i, this._container.appendChild(n), this._iframe = n;
307
- for (const l of o)
308
- typeof l == "string" && l === "dragIn" ? this.pluginsLoaded.push(
309
- new Promise((a, f) => {
310
- try {
311
- import("./drag-in-DC-05b4s.mjs").then(
312
- ({ DragIn: u }) => {
313
- const h = new u(this._iframe);
314
- h.setInstance(this.ui), this.plugins.dragIn = h, a();
315
- }
316
- );
317
- } catch (u) {
318
- f(u);
319
- }
320
- })
321
- ) : l.name && l.loader && this.pluginsLoaded.push(
322
- new Promise((a, f) => {
323
- try {
324
- l.loader().then((u) => {
325
- const h = new u(this._iframe);
326
- h.setInstance(this.ui), this.plugins[l.name] = h, a();
327
- });
328
- } catch (u) {
329
- f(u);
330
- }
331
- })
332
- );
333
- w.set(s, !0);
397
+ );
398
+ this.setMessageHandler(l), this._onResize = this._onResize.bind(this), R() && window.addEventListener("resize", this._onResize), this._container = n, this._initData = t, this._configuratorSettings = e;
399
+ const d = this._createIframe();
400
+ this._onUseFullPage = this._onUseFullPage.bind(this), this._onBackToWebsite = this._onBackToWebsite.bind(this), this._waitForIframe = a, this._container.appendChild(d), this._iframe = d, this.setupPlugins(o, this._iframe), w.set(n, !0);
334
401
  }
335
- static createPlanner(e, s, r, o = []) {
402
+ static createPlanner(e, n, t, o = []) {
336
403
  return this._create(
337
404
  e,
338
- s,
339
- r,
405
+ n,
406
+ t,
340
407
  o
341
408
  );
342
409
  }
410
+ static async connect(e, n = []) {
411
+ const t = new A();
412
+ t.viewName = e;
413
+ const { resolve: o, promise: a } = T(), { resolve: i, promise: l } = T(), d = ({
414
+ message: f,
415
+ args: m
416
+ }) => {
417
+ if (f === _.REGISTER_CUSTOM_VIEW_DONE) {
418
+ o();
419
+ return;
420
+ }
421
+ if (f === _.RETURN_METHODS) {
422
+ t.handleSetup(m[0]), i();
423
+ return;
424
+ }
425
+ if (t.isSetupDone)
426
+ return t.executeMessage({ message: f, args: m });
427
+ }, g = new M(
428
+ "custom-view-" + e,
429
+ window,
430
+ window.parent,
431
+ d
432
+ );
433
+ t.setMessageHandler(g);
434
+ const h = [e];
435
+ return g.sendMessage(
436
+ _.REGISTER_CUSTOM_VIEW,
437
+ h
438
+ ), await a, g.sendMessage(_.GET_METHODS, h), await l, t.setupPlugins(
439
+ n,
440
+ document.body,
441
+ "custom-view"
442
+ ), await Promise.allSettled(t.pluginsLoaded), t;
443
+ }
343
444
  /**
344
445
  * Method to create a new instance of a Roomle Configurator
345
446
  * @param configuratorId the id which identifies your configurator, you will get this ID from your Roomle Contact Person
346
447
  * @param container DOM container in which the configurator should be placed
347
448
  * @param initData settings with which the configurator should be started
348
449
  */
349
- static createConfigurator(e, s, r, o = []) {
450
+ static createConfigurator(e, n, t, o = []) {
350
451
  return this._create(
351
452
  e,
352
- s,
353
- r,
453
+ n,
454
+ t,
354
455
  o
355
456
  );
356
457
  }
@@ -361,11 +462,11 @@ class Q {
361
462
  * @param container DOM container in which the configurator should be placed
362
463
  * @param initData settings with which the configurator should be started
363
464
  */
364
- static create(e, s, r, o) {
465
+ static create(e, n, t, o) {
365
466
  return this._create(
366
467
  e,
367
- s,
368
- r,
468
+ n,
469
+ t,
369
470
  o
370
471
  );
371
472
  }
@@ -375,37 +476,37 @@ class Q {
375
476
  * @param container DOM container in which the configurator should be placed
376
477
  * @param initData settings with which the configurator should be started
377
478
  */
378
- static createViewer(e, s, r, o = []) {
479
+ static createViewer(e, n, t, o = []) {
379
480
  return this._create(
380
481
  e,
381
- s,
382
- r,
482
+ n,
483
+ t,
383
484
  o
384
485
  );
385
486
  }
386
- static async _create(e, s, r, o) {
387
- return new Promise(async (i, g) => {
487
+ static async _create(e, n, t, o) {
488
+ return new Promise(async (a, i) => {
388
489
  try {
389
- const n = O(
390
- $(),
391
- J(r)
490
+ const l = S(
491
+ K(),
492
+ Y(t)
392
493
  );
393
- n.featureFlags || (n.featureFlags = {}), typeof n.featureFlags.realPartList != "boolean" && (n.featureFlags.realPartList = !0), typeof n.featureFlags.globalCallbacks != "boolean" && (n.featureFlags.globalCallbacks = !0), typeof n.featureFlags.mocAr != "boolean" && (n.featureFlags.mocAr = !1);
394
- const l = await D(
494
+ l.featureFlags || (l.featureFlags = {}), typeof l.featureFlags.realPartList != "boolean" && (l.featureFlags.realPartList = !0), typeof l.featureFlags.globalCallbacks != "boolean" && (l.featureFlags.globalCallbacks = !0), typeof l.featureFlags.mocAr != "boolean" && (l.featureFlags.mocAr = !1);
495
+ const d = await U(
395
496
  e,
396
- n
497
+ l
397
498
  );
398
- r = V(l, n);
399
- const a = new this(
400
- l,
401
- s,
402
- r,
499
+ t = q(d, l);
500
+ const g = new this(
501
+ d,
502
+ n,
503
+ t,
403
504
  o,
404
- i
505
+ a
405
506
  );
406
- return console.info(a), await Promise.allSettled(a.pluginsLoaded), a;
407
- } catch (n) {
408
- return g(n);
507
+ return await Promise.allSettled(g.pluginsLoaded), g;
508
+ } catch (l) {
509
+ return i(l);
409
510
  }
410
511
  });
411
512
  }
@@ -415,60 +516,40 @@ class Q {
415
516
  e && this._container.removeChild(e), window.removeEventListener("resize", this._onResize);
416
517
  }
417
518
  _createIframe() {
418
- var r;
519
+ var t;
419
520
  const e = document.createElement("iframe");
420
- let s = ((r = this._configuratorSettings) == null ? void 0 : r.url) || "https://www.roomle.com/t/cp/";
421
- return this._initData.useLocalRoomle && (s = location.href.replace("embedding.html", "")), location.href.includes("roomle.gitlab.io") && (s = location.href.replace("embedding.html", "index.html")), this._initData.overrideServerUrl && (s = this._initData.overrideServerUrl), e.src = s, e.classList.add(d.CONTAINER), e.classList.add(d.FILL), e;
521
+ let n = ((t = this._configuratorSettings) == null ? void 0 : t.url) || "https://www.roomle.com/t/cp/";
522
+ return this._initData.useLocalRoomle && (n = location.href.replace("embedding.html", "")), location.href.includes("roomle.gitlab.io") && (n = location.href.replace("embedding.html", "index.html")), this._initData.overrideServerUrl && (n = this._initData.overrideServerUrl), e.src = n, e.classList.add(u.CONTAINER), e.classList.add(u.FILL), e;
422
523
  }
423
524
  _onResize() {
424
- b(this._iframe);
525
+ L(this._iframe);
425
526
  }
426
527
  _onUseFullPage() {
427
- this._iframe.classList.add(d.POSITION), document.documentElement.classList.add(d.OVERFLOW_HIDDEN), window.document.body.classList.add(d.OVERFLOW_HIDDEN), L() && (b(this._iframe), this._iframe.classList.add(d.ANDROID_HEIGHT));
528
+ this._iframe.classList.add(u.POSITION), document.documentElement.classList.add(u.OVERFLOW_HIDDEN), window.document.body.classList.add(u.OVERFLOW_HIDDEN), R() && (L(this._iframe), this._iframe.classList.add(u.ANDROID_HEIGHT));
428
529
  }
429
530
  _onBackToWebsite() {
430
- this._iframe.classList.remove(d.POSITION), this._iframe.classList.remove(d.ANDROID_HEIGHT), document.documentElement.classList.remove(d.OVERFLOW_HIDDEN), window.document.body.classList.remove(d.OVERFLOW_HIDDEN);
531
+ this._iframe.classList.remove(u.POSITION), this._iframe.classList.remove(u.ANDROID_HEIGHT), document.documentElement.classList.remove(u.OVERFLOW_HIDDEN), window.document.body.classList.remove(u.OVERFLOW_HIDDEN);
431
532
  }
432
- _executeMessage({ message: e, args: s }, r) {
433
- var l;
434
- if (!r.source || r.source !== ((l = this._iframe) == null ? void 0 : l.contentWindow))
435
- return;
436
- if (e === E.REQUEST_BOOT)
437
- return this._messageHandler.setOutgoingMessageBus(r.source), Promise.resolve({ result: this._initData });
438
- if (e === E.SETUP) {
439
- const { methods: a, callbacks: f } = s[0];
440
- return a.forEach((u) => {
441
- const h = u.split(p), m = h[0], _ = h[1];
442
- this[m] || (this[m] = {}), this[m][_] = (function() {
443
- return this._messageHandler.sendMessage(u, [...arguments]);
444
- }).bind(this);
445
- }), f.forEach((u) => {
446
- const h = u.split(p), m = h[0], _ = h[1], N = h[2];
447
- this[m] || (this[m] = {}), this[m][_] || (this[m][_] = {}), this[m][_][N] = () => {
448
- };
449
- }), R(
533
+ _executeMessage({ message: e, args: n }, t) {
534
+ var o;
535
+ if (t.source && t.source === ((o = this._iframe) == null ? void 0 : o.contentWindow))
536
+ return e === E.REQUEST_BOOT ? this._messageHandler ? (this._messageHandler.setOutgoingMessageBus(t.source), Promise.resolve({ result: this._initData })) : (console.error("MessageHandler not set"), Promise.resolve({ error: "MessageHandler not set" })) : e === E.SETUP ? (this.handleSetup(n[0]), N(
450
537
  this.ui.callbacks,
451
538
  "onUseFullPage",
452
539
  this._onUseFullPage
453
- ), R(
540
+ ), N(
454
541
  this.ui.callbacks,
455
542
  "onBackToWebsite",
456
543
  this._onBackToWebsite
457
- ), this._waitForIframe(this), setTimeout(
458
- () => this._messageHandler.sendMessage(E.WEBSITE_READY),
459
- 0
460
- ), Promise.resolve({ result: null });
461
- }
462
- const o = e.split(p), i = o[0], g = o[1], n = o.length === 3 ? o[2] : null;
463
- if (n && this[i][g][n]) {
464
- const a = this[i][g][n](
465
- ...s
466
- );
467
- return a instanceof Promise ? a.then((f) => ({ result: f })) : a !== void 0 ? Promise.resolve({ result: a }) : Promise.resolve({ result: null });
468
- }
469
- return Promise.reject('Message "' + e + '" is unkown');
544
+ ), this._waitForIframe(this), setTimeout(() => {
545
+ if (!this._messageHandler) {
546
+ console.error("MessageHandler not set");
547
+ return;
548
+ }
549
+ this._messageHandler.sendMessage(E.WEBSITE_READY);
550
+ }, 0), Promise.resolve({ result: null })) : this.executeMessage({ message: e, args: n });
470
551
  }
471
552
  }
472
553
  export {
473
- Q as default
554
+ ee as default
474
555
  };