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