@roomle/embedding-lib 6.5.0 → 6.6.0-alpha.2

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