@roomle/embedding-lib 6.6.0-alpha.1 → 6.6.0-alpha.3

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