@roomle/embedding-lib 5.5.0-debug.3 → 5.5.0-debug.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,6 @@
1
- ## [5.5.0-debug.3](https://github.com/roomle-dev/roomle-ui/compare/embedding-lib-v5.5.0-debug.2...embedding-lib-v5.5.0-debug.3) (2024-10-18)
1
+ ## [5.5.0-debug.4](https://github.com/roomle-dev/roomle-ui/compare/embedding-lib-v5.5.0-debug.3...embedding-lib-v5.5.0-debug.4) (2024-10-18)
2
2
 
3
3
 
4
- ### Bug Fixes
4
+ ### Features
5
5
 
6
- * make drag-in for custom-view more stable against different timings ([3ebd477](https://github.com/roomle-dev/roomle-ui/commit/3ebd47785d3ed030cd8aa316d442223c03644bc1))
7
- * make typescript happy ([7613796](https://github.com/roomle-dev/roomle-ui/commit/7613796f23b9ed7b815cc280db589e863110123e))
8
- * ts ([cbc5407](https://github.com/roomle-dev/roomle-ui/commit/cbc5407d30ed9677a4733f09e463ca7500024bcb))
6
+ * make things more stable ([432c571](https://github.com/roomle-dev/roomle-ui/commit/432c5713b1504e865d3152f888940b72d3767516))
@@ -1,7 +1,7 @@
1
1
  var z = Object.defineProperty;
2
- var k = (n, t, e) => t in n ? z(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var r = (n, t, e) => k(n, typeof t != "symbol" ? t + "" : t, e);
4
- class H {
2
+ var k = (s, t, e) => t in s ? z(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var r = (s, t, e) => k(s, typeof t != "symbol" ? t + "" : t, e);
4
+ class q {
5
5
  constructor(t = 16) {
6
6
  r(this, "_computedStyleCache", /* @__PURE__ */ new Map());
7
7
  r(this, "_maxLifetime", 16);
@@ -12,11 +12,11 @@ class H {
12
12
  const e = this._computedStyleCache.get(t), i = Date.now();
13
13
  if (e && i - e.updated < this._maxLifetime)
14
14
  return e.style;
15
- const s = getComputedStyle(t);
16
- return this._computedStyleCache.set(t, { style: s, updated: i }), this._cacheCleanInterval || (this._cacheCleanInterval = setInterval(
15
+ const n = getComputedStyle(t);
16
+ return this._computedStyleCache.set(t, { style: n, updated: i }), this._cacheCleanInterval || (this._cacheCleanInterval = setInterval(
17
17
  () => this._cleanUpCache,
18
18
  Math.max(this._maxLifetime * 1e3, 5e3)
19
- )), s;
19
+ )), n;
20
20
  }
21
21
  _cleanUpCache() {
22
22
  const t = Date.now();
@@ -25,10 +25,10 @@ class H {
25
25
  this._computedStyleCache.size === 0 && this._cacheCleanInterval && (clearInterval(this._cacheCleanInterval), this._cacheCleanInterval = null);
26
26
  }
27
27
  }
28
- const P = (n) => window.TouchEvent && n instanceof window.TouchEvent;
29
- let E;
30
- const x = (n) => (E || (E = new H()), E.get(n)), M = (n, t, e) => {
31
- const i = parseFloat(n), s = window.devicePixelRatio || 1;
28
+ const P = (s) => window.TouchEvent && s instanceof window.TouchEvent;
29
+ let C;
30
+ const T = (s) => (C || (C = new q()), C.get(s)), O = (s, t, e) => {
31
+ const i = parseFloat(s), n = window.devicePixelRatio || 1;
32
32
  if (t === "px")
33
33
  return i;
34
34
  if (t === "%") {
@@ -37,13 +37,13 @@ const x = (n) => (E || (E = new H()), E.get(n)), M = (n, t, e) => {
37
37
  }
38
38
  if (t === "rem") {
39
39
  const o = parseFloat(
40
- x(document.documentElement).fontSize
40
+ T(document.documentElement).fontSize
41
41
  );
42
42
  return i * o;
43
43
  }
44
44
  if (t === "em") {
45
45
  const o = parseFloat(
46
- x(e).fontSize
46
+ T(e).fontSize
47
47
  );
48
48
  return i * o;
49
49
  }
@@ -61,46 +61,46 @@ const x = (n) => (E || (E = new H()), E.get(n)), M = (n, t, e) => {
61
61
  mm: 3.77952755906,
62
62
  in: 96
63
63
  };
64
- return t in a ? i * a[t] * s : (console.warn(
64
+ return t in a ? i * a[t] * n : (console.warn(
65
65
  "Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"
66
66
  ), 0);
67
- }, q = (n, t, e = { x: 0, y: 0 }) => {
68
- const i = n.getBoundingClientRect(), a = x(n).transform;
69
- let o = 0, d = 0;
67
+ }, H = (s, t, e = { x: 0, y: 0 }) => {
68
+ const i = s.getBoundingClientRect(), a = T(s).transform;
69
+ let o = 0, h = 0;
70
70
  if (a !== "none") {
71
- const c = /translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/, f = a.match(c);
72
- f && (o = M(f[1], f[2], n), d = M(f[3], f[4], n));
73
- }
74
- const { clientX: u, clientY: m } = U(t, e), h = u - i.left - o + n.scrollLeft, g = m - i.top - d + n.scrollTop;
75
- return { x: h, y: g };
76
- }, U = (n, t) => {
77
- const { clientX: e, clientY: i } = P(n) ? B(n) : n, s = e > 0 ? e : t.x, a = i > 0 ? i : t.y;
78
- return { clientX: s, clientY: a };
79
- }, B = (n) => {
80
- if (n.touches.length) {
81
- let { clientX: e, clientY: i } = n.touches[0];
82
- if (n.touches.length > 1) {
83
- const s = n.touches[1], a = s.clientX, o = s.clientY;
71
+ const x = /translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/, m = a.match(x);
72
+ m && (o = O(m[1], m[2], s), h = O(m[3], m[4], s));
73
+ }
74
+ const { clientX: l, clientY: u } = U(t, e), _ = l - i.left - o + s.scrollLeft, w = u - i.top - h + s.scrollTop;
75
+ return { x: _, y: w };
76
+ }, U = (s, t) => {
77
+ const { clientX: e, clientY: i } = P(s) ? B(s) : s, n = e > 0 ? e : t.x, a = i > 0 ? i : t.y;
78
+ return { clientX: n, clientY: a };
79
+ }, B = (s) => {
80
+ if (s.touches.length) {
81
+ let { clientX: e, clientY: i } = s.touches[0];
82
+ if (s.touches.length > 1) {
83
+ const n = s.touches[1], a = n.clientX, o = n.clientY;
84
84
  e = (e + a) / 2, i = (i + o) / 2;
85
85
  }
86
86
  return { clientX: e, clientY: i };
87
87
  }
88
- const t = n.changedTouches[0];
88
+ const t = s.changedTouches[0];
89
89
  return { clientX: t.clientX, clientY: t.clientY };
90
- }, V = (n, t) => {
91
- const e = t.x + t.width, i = t.x, s = t.y + t.height, a = t.y, { x: o, y: d } = n;
92
- return o >= i && o <= e && d >= a && d <= s;
93
- }, O = 500, Y = 10;
90
+ }, V = (s, t) => {
91
+ const e = t.x + t.width, i = t.x, n = t.y + t.height, a = t.y, { x: o, y: h } = s;
92
+ return o >= i && o <= e && h >= a && h <= n;
93
+ }, M = 500, Y = 10;
94
94
  class W {
95
95
  constructor(t, { onTouchDragStart: e }, i = {}) {
96
96
  r(this, "_touchDragTimeOut");
97
97
  r(this, "_onTouchDragStart");
98
98
  r(this, "_payload", null);
99
- r(this, "_delay", O);
99
+ r(this, "_delay", M);
100
100
  r(this, "_firstTouch", null);
101
101
  r(this, "_lastTouch", null);
102
102
  r(this, "_epsilon", Y);
103
- this._payload = t, this._onTouchDragStart = e, this._delay = i.delay || O, this._epsilon = i.epsilon || Y;
103
+ this._payload = t, this._onTouchDragStart = e, this._delay = i.delay || M, this._epsilon = i.epsilon || Y;
104
104
  }
105
105
  onTouchStart(t) {
106
106
  var e;
@@ -133,32 +133,31 @@ class W {
133
133
  }
134
134
  }
135
135
  class j {
136
- constructor() {
136
+ constructor(t, e) {
137
+ r(this, "_mainDomElement");
137
138
  r(this, "_instance", null);
138
139
  r(this, "_mode", "website");
139
140
  r(this, "_viewName", "main");
141
+ this._mainDomElement = t, this._mode = e;
140
142
  }
141
143
  setInstance(t) {
142
144
  this._instance = t;
143
145
  }
144
- setMode(t) {
145
- this._mode = t;
146
- }
147
146
  setViewName(t) {
148
147
  this._viewName = t;
149
148
  }
150
149
  }
151
- const J = (n) => new Promise((t) => setTimeout(t, n)), $ = "rml-drag-in-styles", K = "rml-drag-in-drag-element", y = "rml-drag-in-overlay", C = "rml-drag-in-spacer", D = "rml-drag-in-drag-ghost", I = "rml-drag-in-fade-in", X = "rml-drag-in-fade-out", N = {
150
+ const J = (s) => new Promise((t) => setTimeout(t, s)), X = "rml-drag-in-styles", K = "rml-drag-in-drag-element", f = "rml-drag-in-overlay", y = "rml-drag-in-spacer", D = "rml-drag-in-drag-ghost", I = "rml-drag-in-fade-in", $ = "rml-drag-in-fade-out", N = {
152
151
  DISPLAY_NONE: "rml-display-none"
153
- }, F = 0.5, b = "250ms", A = "forwards", w = (n) => n ? !0 : (console.warn("No instance set, cancel drag-in"), !1);
152
+ }, F = 0.5, b = "250ms", A = "forwards", g = (s) => s ? !0 : (console.warn("No instance set, cancel drag-in"), !1);
154
153
  class Z extends j {
155
- constructor(e) {
156
- super();
157
- r(this, "_mainDomElement");
154
+ constructor(e, i) {
155
+ super(e, i);
158
156
  r(this, "_currentDrag", {});
159
157
  r(this, "_currentTouch", null);
160
158
  r(this, "_firefoxDragPosition", { x: 0, y: 0 });
161
159
  r(this, "_readyForDragUpdates", !1);
160
+ r(this, "_paddingTop", 0);
162
161
  r(this, "options", {});
163
162
  r(this, "_firefoxFallback", (e) => {
164
163
  if (!this._currentDrag.event)
@@ -166,17 +165,17 @@ class Z extends j {
166
165
  const i = e || window.event;
167
166
  this._firefoxDragPosition.x = i.pageX || 0, this._firefoxDragPosition.y = i.pageY || 0;
168
167
  });
169
- this._mainDomElement = e, this._injectStyles(), this._initializeDragGhost(), this._firefoxFallback = this._firefoxFallback.bind(this), this._initReadyForDragUpdates(), document.addEventListener("dragover", this._firefoxFallback);
168
+ this._initReadyForDragUpdates(), this._injectStyles(), this._initializeDragGhost(), this._firefoxFallback = this._firefoxFallback.bind(this), this._initReadyForDragUpdates(), document.addEventListener("dragover", this._firefoxFallback);
170
169
  }
171
170
  _injectStyles() {
172
- if (!!!document.getElementById($)) {
171
+ if (!!!document.getElementById(X)) {
173
172
  const i = document.createElement("style");
174
- i.type = "text/css", i.id = $, i.innerHTML = `
173
+ i.type = "text/css", i.id = X, i.innerHTML = `
175
174
  .${N.DISPLAY_NONE}{display:none}
176
- .${y}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
175
+ .${f}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
177
176
  .${D}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
178
177
  @keyframes ${I} {from{opacity: 0;}to {opacity: ${F};}}
179
- @keyframes ${X} {from{opacity: ${F};}to {opacity: 0;}}
178
+ @keyframes ${$} {from{opacity: ${F};}to {opacity: 0;}}
180
179
  `, document.head.appendChild(i);
181
180
  }
182
181
  }
@@ -191,95 +190,99 @@ class Z extends j {
191
190
  this._readyForDragUpdates = this._mode !== "custom-view";
192
191
  }
193
192
  setInstance(e) {
194
- this._instance = e;
195
- }
196
- setMode(e) {
197
- this._mode = e, this._initReadyForDragUpdates();
193
+ this._instance = e, this._initDom();
194
+ }
195
+ async _initDom() {
196
+ if (this._mode === "custom-view" && g(this._instance)) {
197
+ const e = await this._instance.getBoundingClientRect("iframe");
198
+ this._paddingTop = e.top;
199
+ const i = this.options.domContainer;
200
+ if (!i)
201
+ throw new Error("No container set, can not expand custom view");
202
+ i.style.position = "absolute", i.style.top = "0", i.style.right = "0", i.style.width = `${e.width}px`;
203
+ let n = document.body.querySelector(
204
+ `.${y}`
205
+ );
206
+ n || (n = document.createElement("div"), n.classList.add(y), document.body.appendChild(n)), n = document.body.querySelector(
207
+ `.${y}`
208
+ ), n && (n.style.position = "fixed", n.style.backgroundColor = "blue", n.style.top = "0px", n.style.right = "0px", n.style.width = `${e.width}px`, n.style.height = `${e.height + e.top}px`, n.style.opacity = "0", n.style.pointerEvents = "none", n.style.zIndex = "-1");
209
+ }
198
210
  }
199
- async dragStart(e, i, s = "rml_id") {
211
+ async dragStart(e, i, n = "rml_id") {
200
212
  const a = this._mainDomElement.parentNode, o = a.querySelector(
201
213
  "." + D
202
214
  );
203
- if (i instanceof DragEvent && i.dataTransfer && i.dataTransfer.setDragImage && i.dataTransfer.setDragImage(o, 0, 0), this._mode === "custom-view" && w(this._instance)) {
204
- const h = await this._instance.getBoundingClientRect("iframe"), g = this.options.domContainer;
205
- if (!g)
206
- throw new Error("No container set, can not expand custom view");
207
- g.style.position = "absolute", g.style.top = `${h.top}px`, g.style.left = `${h.left}px`, g.style.width = `${h.width}px`;
208
- let c = document.body.querySelector(
209
- `.${C}`
210
- );
211
- c || (c = document.createElement("div"), c.classList.add(C), document.body.appendChild(c)), c = document.body.querySelector(
212
- `.${C}`
213
- ), c && (c.style.position = "fixed", c.style.backgroundColor = "blue", c.style.top = "0px", c.style.left = `${h.left}px`, c.style.width = `${h.width}px`, c.style.height = `${h.height + h.top}px`, c.style.opacity = "0", c.style.pointerEvents = "none", c.style.zIndex = "-1", this._currentDrag.spacer = c), await this._instance.expandCustomView(this._viewName), await J(
214
- 50
215
- );
216
- }
217
- const d = x(a);
218
- if (this._mode === "website" && d.position !== "relative") {
215
+ i instanceof DragEvent && i.dataTransfer && i.dataTransfer.setDragImage && i.dataTransfer.setDragImage(o, 0, 0), this._mode === "custom-view" && g(this._instance) && (await this._instance.expandCustomView(this._viewName), this.options.domContainer && (this.options.domContainer.style.paddingTop = `${this._paddingTop}px`), await J(
216
+ 50
217
+ ));
218
+ const h = T(a);
219
+ if (this._mode === "website" && h.position !== "relative") {
219
220
  console.warn(
220
221
  "Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly"
221
222
  );
222
223
  return;
223
224
  }
224
225
  this._mainDomElement.style.pointerEvents = "none";
225
- let u = a.querySelector(
226
- "." + y
226
+ let l = a.querySelector(
227
+ "." + f
227
228
  );
228
- u || (u = document.createElement("div"), u.classList.add(y), a.appendChild(u)), u.classList.remove(N.DISPLAY_NONE), i.target.getAttribute("draggable") || console.warn(
229
+ l || (l = document.createElement("div"), l.classList.add(f), a.appendChild(l)), l.classList.remove(N.DISPLAY_NONE), i.target.getAttribute("draggable") || console.warn(
229
230
  `Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`
230
- ), this._currentDrag.event = i, this._currentDrag.id = e, this._currentDrag.type = s, this._readyForDragUpdates = !0;
231
+ ), this._currentDrag.event = i, this._currentDrag.id = e, this._currentDrag.type = n, this._readyForDragUpdates = !0;
231
232
  }
232
233
  /** MUST NOT BE ASYNC, OTHERWISE ACCESS TO event.clientX could be wrong */
233
234
  dragUpdate(e) {
234
235
  var R, L;
235
236
  if (!this._readyForDragUpdates)
236
237
  return;
237
- const { clientX: i, clientY: s } = U(
238
+ const { clientX: i, clientY: n } = U(
238
239
  e,
239
240
  this._firefoxDragPosition
240
- ), a = i <= 0 || s <= 0;
241
+ ), a = i <= 0 || n <= 0;
241
242
  if (this._mode === "custom-view" && a)
242
243
  return;
243
- const o = this._mainDomElement.parentNode, { x: d, y: u } = q(o, e, this._firefoxDragPosition);
244
- if (d === 0 && u === 0)
244
+ const o = this._mainDomElement.parentNode, { x: h, y: l } = H(o, e, this._firefoxDragPosition);
245
+ if (h === 0 && l === 0)
245
246
  return;
246
247
  if (!this._currentDrag.element) {
247
- const l = e.target.cloneNode();
248
- l.style.position = "fixed", l.style.pointerEvents = "none", l.style.opacity = "0", l.style.animation = `${I} ${b} ${A}`, l.id = K, l.style.zIndex = "9999", document.body.appendChild(l), this._currentDrag.element = l;
249
- const _ = e.target.getBoundingClientRect();
250
- this._currentDrag.offset || (this._currentDrag.offset = { x: 0, y: 0 }), this._currentDrag.offset.x = this._mode === "website" ? i - _.left : _.width / 2, this._currentDrag.offset.y = this._mode === "website" ? s - _.top : _.height / 2;
248
+ const c = e.target.cloneNode();
249
+ c.style.position = "fixed", c.style.pointerEvents = "none", c.style.opacity = "0", c.style.animation = `${I} ${b} ${A}`, c.id = K, c.style.zIndex = "9999", document.body.appendChild(c), this._currentDrag.element = c;
250
+ const d = e.target.getBoundingClientRect();
251
+ this._currentDrag.offset || (this._currentDrag.offset = { x: 0, y: 0 }), this._currentDrag.offset.x = this._mode === "website" ? i - d.left : d.width / 2, this._currentDrag.offset.y = this._mode === "website" ? n - d.top : d.height / 2;
251
252
  }
252
- const m = Math.max(1, d), h = Math.max(1, u), g = ((R = this._currentDrag.offset) == null ? void 0 : R.x) || 0, c = ((L = this._currentDrag.offset) == null ? void 0 : L.y) || 0, f = i - g, G = s - c;
253
- this._currentDrag.element.style.left = `${f}px`, this._currentDrag.element.style.top = `${G}px`;
254
- const T = (this.options.dragInOverlapX || 0) + 1, S = (this.options.dragInOverlapY || 0) + 1;
255
- let v = m > T && h > S;
253
+ const u = Math.max(1, h), _ = Math.max(1, l), w = ((R = this._currentDrag.offset) == null ? void 0 : R.x) || 0, x = ((L = this._currentDrag.offset) == null ? void 0 : L.y) || 0, m = i - w, G = n - x;
254
+ this._currentDrag.element.style.left = `${m}px`, this._currentDrag.element.style.top = `${G}px`;
255
+ const S = (this.options.dragInOverlapX || 0) + 1, E = (this.options.dragInOverlapY || 0) + 1;
256
+ let v = u > S && _ > E;
256
257
  if (this._mode === "custom-view") {
257
- const l = this._currentDrag.spacer;
258
- if (!l)
258
+ const c = document.body.querySelector(
259
+ `.${y}`
260
+ );
261
+ if (!c)
259
262
  throw new Error("No spacer set, can not fade in/out drag ghost");
260
- const _ = l.getBoundingClientRect();
263
+ const d = c.getBoundingClientRect();
261
264
  v = !V(
262
- { x: m, y: h },
265
+ { x: u, y: _ },
263
266
  {
264
- x: _.left - T,
265
- y: _.top - S,
266
- width: _.width + T,
267
- height: _.height + S
267
+ x: d.left - S,
268
+ y: d.top - E,
269
+ width: d.width + S,
270
+ height: d.height + E
268
271
  }
269
272
  );
270
273
  }
271
- if (v ? this._currentDrag.element.style.animation = `${X} ${b} ${A}` : this._currentDrag.element.style.animation = `${I} ${b} ${A}`, !(m === 1 && h === 1) && w(this._instance)) {
272
- let l = m, _ = h;
274
+ if (v ? this._currentDrag.element.style.animation = `${$} ${b} ${A}` : this._currentDrag.element.style.animation = `${I} ${b} ${A}`, !(u === 1 && _ === 1) && g(this._instance)) {
275
+ let c = u, d = _;
273
276
  if (P(e)) {
274
277
  const p = this.options.fingerSize || 0;
275
- l = Math.max(2, m + p), _ = Math.max(2, h - p);
278
+ c = Math.max(2, u + p), d = Math.max(2, _ - p);
276
279
  }
277
280
  if (this._currentDrag.inserted === "done")
278
- this._instance.updateDrag(l, _);
281
+ this._instance.updateDrag(c, d);
279
282
  else if (this._currentDrag.inserted !== "inprogress") {
280
283
  if (this._currentDrag.inserted = "inprogress", !this._currentDrag.id || !this._currentDrag.type)
281
284
  return;
282
- this._instance.dragInObject(this._currentDrag.id, l, _, this._currentDrag.type).then(
285
+ this._instance.dragInObject(this._currentDrag.id, c, d, this._currentDrag.type).then(
283
286
  () => {
284
287
  this._currentDrag.inserted = "done";
285
288
  },
@@ -291,28 +294,28 @@ class Z extends j {
291
294
  }
292
295
  }
293
296
  async dragEnd() {
294
- if (this._initReadyForDragUpdates(), w(this._instance) && this._mode === "custom-view") {
297
+ if (this._initReadyForDragUpdates(), g(this._instance) && this._mode === "custom-view") {
295
298
  await this._instance.collapseCustomView(this._viewName);
296
- const s = this.options.domContainer;
297
- if (!s)
299
+ const n = this.options.domContainer;
300
+ if (!n)
298
301
  throw new Error("No container set, can not collapse custom view");
299
- s.style.position = "", s.style.top = "", s.style.left = "", s.style.width = "", s.style.height = "";
302
+ n.style.paddingTop = "";
300
303
  }
301
304
  this._mainDomElement.style.pointerEvents = "all";
302
305
  const e = this._mainDomElement.parentNode;
303
- w(this._instance) && this._instance.dragInObjectEnd(), this._currentDrag.element && document.body.removeChild(this._currentDrag.element), this._currentDrag.spacer && document.body.removeChild(this._currentDrag.spacer), this._currentDrag = {}, this._firefoxDragPosition = { x: 0, y: 0 };
306
+ g(this._instance) && this._instance.dragInObjectEnd(), this._currentDrag.element && document.body.removeChild(this._currentDrag.element), this._currentDrag = {}, this._firefoxDragPosition = { x: 0, y: 0 };
304
307
  const i = e.querySelector(
305
- "." + y
308
+ "." + f
306
309
  );
307
310
  i && i.classList.add(N.DISPLAY_NONE);
308
311
  }
309
- touchStart(e, i, s = "rml_id") {
310
- var d, u;
312
+ touchStart(e, i, n = "rml_id") {
313
+ var h, l;
311
314
  i.preventDefault();
312
- const a = (m, h) => {
313
- this.dragStart(e, h, s);
315
+ const a = (u, _) => {
316
+ this.dragStart(e, _, n);
314
317
  }, o = {};
315
- typeof ((d = this.options) == null ? void 0 : d.touchDragDelay) == "number" && (o.delay = this.options.touchDragDelay), (u = this.options) != null && u.touchDragEpsilon && (o.epsilon = this.options.touchDragEpsilon), this._currentTouch = new W(
318
+ typeof ((h = this.options) == null ? void 0 : h.touchDragDelay) == "number" && (o.delay = this.options.touchDragDelay), (l = this.options) != null && l.touchDragEpsilon && (o.epsilon = this.options.touchDragEpsilon), this._currentTouch = new W(
316
319
  void 0,
317
320
  {
318
321
  onTouchDragStart: a
@@ -0,0 +1,7 @@
1
+ var R=Object.defineProperty,q=(n,t,e)=>t in n?R(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,r=(n,t,e)=>q(n,typeof t!="symbol"?t+"":t,e);class j{constructor(t=16){r(this,"_computedStyleCache",new Map),r(this,"_maxLifetime",16),r(this,"_cacheCleanInterval",null),this._maxLifetime=t}get(t){const e=this._computedStyleCache.get(t),i=Date.now();if(e&&i-e.updated<this._maxLifetime)return e.style;const o=getComputedStyle(t);return this._computedStyleCache.set(t,{style:o,updated:i}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),o}_cleanUpCache(){const t=Date.now();for(const[e,{updated:i}]of this._computedStyleCache.entries())t-i>=this._maxLifetime&&this._computedStyleCache.delete(e);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const N=n=>window.TouchEvent&&n instanceof window.TouchEvent;let b;const y=n=>(b||(b=new j),b.get(n)),L=(n,t,e)=>{const i=parseFloat(n),o=window.devicePixelRatio||1;if(t==="px")return i;if(t==="%"){const s=e===document.documentElement?window.innerWidth:e.offsetWidth;return i/100*s}if(t==="rem"){const s=parseFloat(y(document.documentElement).fontSize);return i*s}if(t==="em"){const s=parseFloat(y(e).fontSize);return i*s}if(t==="vh"||t==="vw"||t==="vmin"||t==="vmax"){const s={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return i/100*s[t]}const a={cm:37.7952755906,mm:3.77952755906,in:96};return t in a?i*a[t]*o:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},A=(n,t,e={x:0,y:0})=>{const i=n.getBoundingClientRect(),o=y(n).transform;let a=0,s=0;if(o!=="none"){const u=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,m=o.match(u);m&&(a=L(m[1],m[2],n),s=L(m[3],m[4],n))}const{clientX:c,clientY:g}=F(t,e),_=c-i.left-a+n.scrollLeft,d=g-i.top-s+n.scrollTop;return{x:_,y:d}},F=(n,t)=>{const{clientX:e,clientY:i}=N(n)?B(n):n,o=e>0?e:t.x,a=i>0?i:t.y;return{clientX:o,clientY:a}},B=n=>{if(n.touches.length){let{clientX:e,clientY:i}=n.touches[0];if(n.touches.length>1){const o=n.touches[1],a=o.clientX,s=o.clientY;e=(e+a)/2,i=(i+s)/2}return{clientX:e,clientY:i}}const t=n.changedTouches[0];return{clientX:t.clientX,clientY:t.clientY}},W=(n,t)=>{const e=t.x+t.width,i=t.x,o=t.y+t.height,a=t.y,{x:s,y:c}=n;return s>=i&&s<=e&&c>=a&&c<=o},O=500,X=10;class H{constructor(t,{onTouchDragStart:e},i={}){r(this,"_touchDragTimeOut"),r(this,"_onTouchDragStart"),r(this,"_payload",null),r(this,"_delay",O),r(this,"_firstTouch",null),r(this,"_lastTouch",null),r(this,"_epsilon",X),this._payload=t,this._onTouchDragStart=e,this._delay=i.delay||O,this._epsilon=i.epsilon||X}onTouchStart(t){var e;!t||!((e=t?.touches)!=null&&e.length)||this._touchDragTimeOut||(this._firstTouch=t.touches[t.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=t.touches[0]),this._checkXDistance(t)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(t){var e;!t||!((e=t?.touches)!=null&&e.length)||(this._lastTouch=t.touches[0])}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(t){return()=>{if(!this._firstTouch||!this._lastTouch)return;let e=!1;e=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,e&&(this._onTouchDragStart(this._payload,t),this._resetTouches())}}}class V{constructor(t,e){r(this,"_mainDomElement"),r(this,"_instance",null),r(this,"_mode","website"),r(this,"_viewName","main"),this._mainDomElement=t,this._mode=e}setInstance(t){this._instance=t}setViewName(t){this._viewName=t}}const G=n=>new Promise(t=>setTimeout(t,n)),Y="rml-drag-in-styles",J="rml-drag-in-drag-element",D="rml-drag-in-overlay",w="rml-drag-in-spacer",v="rml-drag-in-drag-ghost",E="rml-drag-in-fade-in",P="rml-drag-in-fade-out",S={DISPLAY_NONE:"rml-display-none"},M=.5,C="250ms",I="forwards",p=n=>n?!0:(console.warn("No instance set, cancel drag-in"),!1);class K extends V{constructor(t,e){super(t,e),r(this,"_currentDrag",{}),r(this,"_currentTouch",null),r(this,"_firefoxDragPosition",{x:0,y:0}),r(this,"_readyForDragUpdates",!1),r(this,"_paddingTop",0),r(this,"options",{}),r(this,"_firefoxFallback",i=>{if(!this._currentDrag.event)return;const o=i||window.event;this._firefoxDragPosition.x=o.pageX||0,this._firefoxDragPosition.y=o.pageY||0}),this._initReadyForDragUpdates(),this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),this._initReadyForDragUpdates(),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!document.getElementById(Y)){const t=document.createElement("style");t.type="text/css",t.id=Y,t.innerHTML=`
2
+ .${S.DISPLAY_NONE}{display:none}
3
+ .${D}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
4
+ .${v}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
5
+ @keyframes ${E} {from{opacity: 0;}to {opacity: ${M};}}
6
+ @keyframes ${P} {from{opacity: ${M};}to {opacity: 0;}}
7
+ `,document.head.appendChild(t)}}_initializeDragGhost(){const t=this._mode==="custom-view"?document.body:this._mainDomElement.parentNode;let e=t.querySelector("."+v);e||(e=document.createElement("div"),e.classList.add(v),e.innerText=" ",t.appendChild(e))}_initReadyForDragUpdates(){this._readyForDragUpdates=this._mode!=="custom-view"}setInstance(t){this._instance=t,this._initDom()}async _initDom(){if(this._mode==="custom-view"&&p(this._instance)){const t=await this._instance.getBoundingClientRect("iframe");this._paddingTop=t.top;const e=this.options.domContainer;if(!e)throw new Error("No container set, can not expand custom view");e.style.position="absolute",e.style.top="0",e.style.right="0",e.style.width=`${t.width}px`;let i=document.body.querySelector(`.${w}`);i||(i=document.createElement("div"),i.classList.add(w),document.body.appendChild(i)),i=document.body.querySelector(`.${w}`),i&&(i.style.position="fixed",i.style.backgroundColor="blue",i.style.top="0px",i.style.right="0px",i.style.width=`${t.width}px`,i.style.height=`${t.height+t.top}px`,i.style.opacity="0",i.style.pointerEvents="none",i.style.zIndex="-1")}}async dragStart(t,e,i="rml_id"){const o=this._mainDomElement.parentNode,a=o.querySelector("."+v);e instanceof DragEvent&&e.dataTransfer&&e.dataTransfer.setDragImage&&e.dataTransfer.setDragImage(a,0,0),this._mode==="custom-view"&&p(this._instance)&&(await this._instance.expandCustomView(this._viewName),this.options.domContainer&&(this.options.domContainer.style.paddingTop=`${this._paddingTop}px`),await G(50));const s=y(o);if(this._mode==="website"&&s.position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._mainDomElement.style.pointerEvents="none";let c=o.querySelector("."+D);c||(c=document.createElement("div"),c.classList.add(D),o.appendChild(c)),c.classList.remove(S.DISPLAY_NONE),e.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`),this._currentDrag.event=e,this._currentDrag.id=t,this._currentDrag.type=i,this._readyForDragUpdates=!0}dragUpdate(t){var e,i;if(!this._readyForDragUpdates)return;const{clientX:o,clientY:a}=F(t,this._firefoxDragPosition),s=o<=0||a<=0;if(this._mode==="custom-view"&&s)return;const c=this._mainDomElement.parentNode,{x:g,y:_}=A(c,t,this._firefoxDragPosition);if(g===0&&_===0)return;if(!this._currentDrag.element){const h=t.target.cloneNode();h.style.position="fixed",h.style.pointerEvents="none",h.style.opacity="0",h.style.animation=`${E} ${C} ${I}`,h.id=J,h.style.zIndex="9999",document.body.appendChild(h),this._currentDrag.element=h;const l=t.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0}),this._currentDrag.offset.x=this._mode==="website"?o-l.left:l.width/2,this._currentDrag.offset.y=this._mode==="website"?a-l.top:l.height/2}const d=Math.max(1,g),u=Math.max(1,_),m=((e=this._currentDrag.offset)==null?void 0:e.x)||0,U=((i=this._currentDrag.offset)==null?void 0:i.y)||0,k=o-m,z=a-U;this._currentDrag.element.style.left=`${k}px`,this._currentDrag.element.style.top=`${z}px`;const x=(this.options.dragInOverlapX||0)+1,T=(this.options.dragInOverlapY||0)+1;let $=d>x&&u>T;if(this._mode==="custom-view"){const h=document.body.querySelector(`.${w}`);if(!h)throw new Error("No spacer set, can not fade in/out drag ghost");const l=h.getBoundingClientRect();$=!W({x:d,y:u},{x:l.left-x,y:l.top-T,width:l.width+x,height:l.height+T})}if($?this._currentDrag.element.style.animation=`${P} ${C} ${I}`:this._currentDrag.element.style.animation=`${E} ${C} ${I}`,!(d===1&&u===1)&&p(this._instance)){let h=d,l=u;if(N(t)){const f=this.options.fingerSize||0;h=Math.max(2,d+f),l=Math.max(2,u-f)}if(this._currentDrag.inserted==="done")this._instance.updateDrag(h,l);else if(this._currentDrag.inserted!=="inprogress"){if(this._currentDrag.inserted="inprogress",!this._currentDrag.id||!this._currentDrag.type)return;this._instance.dragInObject(this._currentDrag.id,h,l,this._currentDrag.type).then(()=>{this._currentDrag.inserted="done"},f=>{console.error(f),this._currentDrag.inserted="failed"})}}}async dragEnd(){if(this._initReadyForDragUpdates(),p(this._instance)&&this._mode==="custom-view"){await this._instance.collapseCustomView(this._viewName);const i=this.options.domContainer;if(!i)throw new Error("No container set, can not collapse custom view");i.style.paddingTop=""}this._mainDomElement.style.pointerEvents="all";const t=this._mainDomElement.parentNode;p(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const e=t.querySelector("."+D);e&&e.classList.add(S.DISPLAY_NONE)}touchStart(t,e,i="rml_id"){var o,a;e.preventDefault();const s=(g,_)=>{this.dragStart(t,_,i)},c={};typeof((o=this.options)==null?void 0:o.touchDragDelay)=="number"&&(c.delay=this.options.touchDragDelay),(a=this.options)!=null&&a.touchDragEpsilon&&(c.epsilon=this.options.touchDragEpsilon),this._currentTouch=new H(void 0,{onTouchDragStart:s},c),this._currentTouch.onTouchStart(e)}touchMove(t){this._currentTouch&&this._currentTouch.onTouchMove(t),this._currentDrag.event&&this.dragUpdate(t)}touchEnd(){this._currentTouch&&this._currentTouch.onTouchEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}}export{K as DragIn};
package/index.d.ts CHANGED
@@ -16,9 +16,9 @@ import { PossibleCustomViewsAndMain as PossibleCustomViewsAndMain_2 } from '../.
16
16
  import { RapiId } from '@roomle/web-sdk/lib/definitions/typings/rapi-types';
17
17
  import { UiInitData } from '../../../src/configurator/embedding/types';
18
18
 
19
- declare interface AvailablePlugins {
20
- dragIn?: DragIn;
21
- }
19
+ declare type AvailablePlugins = {
20
+ [K in keyof PluginMap]?: InstanceType<PluginMap[K]>;
21
+ };
22
22
 
23
23
  declare class Connector<SdkType, SdkCallbacks> implements RoomleEmbeddingApiKeys {
24
24
  protected _messageHandler: Nullable<MessageHandler>;
@@ -47,11 +47,11 @@ declare class Connector<SdkType, SdkCallbacks> implements RoomleEmbeddingApiKeys
47
47
  }
48
48
 
49
49
  declare class DragIn extends EmbeddingPlugin {
50
- private _mainDomElement;
51
50
  private _currentDrag;
52
51
  private _currentTouch;
53
52
  private _firefoxDragPosition;
54
53
  private _readyForDragUpdates;
54
+ private _paddingTop;
55
55
  options: {
56
56
  dragInOverlapX?: number;
57
57
  dragInOverlapY?: number;
@@ -63,9 +63,9 @@ declare class DragIn extends EmbeddingPlugin {
63
63
  private _injectStyles;
64
64
  private _initializeDragGhost;
65
65
  private _initReadyForDragUpdates;
66
- constructor(iframe: HTMLIFrameElement | HTMLBodyElement);
66
+ constructor(iframe: HTMLIFrameElement | HTMLBodyElement, mode: EmbeddingPluginMode);
67
67
  setInstance(instance: ExposedApi): void;
68
- setMode(mode: EmbeddingPluginMode): void;
68
+ private _initDom;
69
69
  private _firefoxFallback;
70
70
  dragStart(id: RapiId, event: DragEvent | TouchEvent, type?: string): Promise<void>;
71
71
  /** MUST NOT BE ASYNC, OTHERWISE ACCESS TO event.clientX could be wrong */
@@ -77,22 +77,31 @@ declare class DragIn extends EmbeddingPlugin {
77
77
  dispose(): void;
78
78
  }
79
79
 
80
- declare abstract class EmbeddingPlugin {
80
+ declare class EmbeddingPlugin {
81
+ protected _mainDomElement: HTMLIFrameElement | HTMLBodyElement;
81
82
  protected _instance: Nullable_2<ExposedApi>;
82
83
  protected _mode: EmbeddingPluginMode;
83
84
  protected _viewName: PossibleCustomViewsAndMain_2;
85
+ constructor(iframe: HTMLIFrameElement | HTMLBodyElement, mode: EmbeddingPluginMode);
84
86
  setInstance(instance: ExposedApi): void;
85
- setMode(mode: EmbeddingPluginMode): void;
86
87
  setViewName(viewName: PossibleCustomViewsAndMain_2): void;
87
88
  }
88
89
 
89
90
  declare type EmbeddingPluginMode = 'website' | 'custom-view';
90
91
 
92
+ declare type PluginConstructors = {
93
+ [K in keyof PluginMap]: PluginMap[K];
94
+ };
95
+
91
96
  declare type PluginDefinitions = Array<keyof AvailablePlugins | {
92
97
  name: keyof AvailablePlugins;
93
- loader: () => Promise<any>;
98
+ loader: () => Promise<PluginConstructors[keyof PluginConstructors]>;
94
99
  }>;
95
100
 
101
+ declare interface PluginMap {
102
+ dragIn: typeof DragIn;
103
+ }
104
+
96
105
  declare type RoomleConfiguratorApi = RoomleEmbeddingApi<default_2, default_4>;
97
106
 
98
107
  declare class RoomleEmbeddingApi<SdkType, SdkCallbacks> extends Connector<SdkType, SdkCallbacks> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomle/embedding-lib",
3
- "version": "5.5.0-debug.3",
3
+ "version": "5.5.0-debug.4",
4
4
  "description": "This is a small library which can be used to communicate with the Roomle Configurator",
5
5
  "type": "module",
6
6
  "main": "./roomle-embedding-lib.umd.js",
@@ -1,7 +1,7 @@
1
1
  var C = Object.defineProperty;
2
2
  var F = (r, s, e) => s in r ? C(r, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[s] = e;
3
3
  var c = (r, s, e) => F(r, typeof s != "symbol" ? s + "" : s, e);
4
- class M {
4
+ class y {
5
5
  constructor(s, e, o, t) {
6
6
  c(this, "_side");
7
7
  // for better debugging (who handles message? iframe or website?)
@@ -152,7 +152,7 @@ const p = ".", E = {
152
152
  }
153
153
  const { hostname: e } = new URL(s);
154
154
  return e;
155
- }, x = (r) => !!(k.includes(r) || r.endsWith("roomle.com") || r.endsWith("gitlab.io") || r.endsWith("gitlab.com")), y = [
155
+ }, x = (r) => !!(k.includes(r) || r.endsWith("roomle.com") || r.endsWith("gitlab.io") || r.endsWith("gitlab.com")), M = [
156
156
  "language",
157
157
  "browserLanguage",
158
158
  "userLanguage",
@@ -163,8 +163,8 @@ const p = ".", E = {
163
163
  return r.substr(0, 2);
164
164
  if (Array.isArray(s.languages) && s.languages.length > 0)
165
165
  return s.languages[0].substr(0, 2);
166
- for (let e = 0, o = y.length; e < o; e++) {
167
- const t = s[y[e]];
166
+ for (let e = 0, o = M.length; e < o; e++) {
167
+ const t = s[M[e]];
168
168
  if (t)
169
169
  return t.substr(0, 2);
170
170
  }
@@ -287,10 +287,10 @@ class T {
287
287
  typeof t == "string" && t === "dragIn" ? this.pluginsLoaded.push(
288
288
  new Promise((n, l) => {
289
289
  try {
290
- import("./drag-in-DpqY8yyT.mjs").then(
290
+ import("./drag-in-CXPjCiN1.mjs").then(
291
291
  ({ DragIn: a }) => {
292
- const i = new a(e);
293
- i.setInstance(this.ui), i.setMode(o), i.setViewName(this.viewName), this.plugins.dragIn = i, n();
292
+ const i = new a(e, o);
293
+ i.setInstance(this.ui), i.setViewName(this.viewName), this.plugins.dragIn = i, n();
294
294
  }
295
295
  );
296
296
  } catch (a) {
@@ -301,8 +301,8 @@ class T {
301
301
  new Promise((n, l) => {
302
302
  try {
303
303
  t.loader().then((a) => {
304
- const i = new a(e);
305
- i.setInstance(this.ui), i.setMode(o), i.setViewName(this.viewName), this.plugins[t.name] = i, n();
304
+ const i = new a(e, o);
305
+ i.setInstance(this.ui), i.setViewName(this.viewName), this.plugins[t.name] = i, n();
306
306
  });
307
307
  } catch (a) {
308
308
  l(a);
@@ -372,7 +372,7 @@ class ee extends T {
372
372
  `, document.head.appendChild(h);
373
373
  }
374
374
  this._executeMessage = this._executeMessage.bind(this);
375
- const i = new M(
375
+ const i = new y(
376
376
  "website",
377
377
  window,
378
378
  null,
@@ -407,7 +407,7 @@ class ee extends T {
407
407
  }
408
408
  if (t.isSetupDone)
409
409
  return t.executeMessage({ message: f, args: m });
410
- }, g = new M(
410
+ }, g = new y(
411
411
  "custom-view",
412
412
  window,
413
413
  window.parent,
@@ -1,8 +1,8 @@
1
- var H=Object.defineProperty,A=(r,e,t)=>e in r?H(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,c=(r,e,t)=>A(r,typeof e!="symbol"?e+"":e,t);class O{constructor(e,t,s,i){c(this,"_side"),c(this,"_incomingMessageBus"),c(this,"_outgoingMessageBus",null),c(this,"_execMessage",null),this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=s,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((s,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 l;try{l=JSON.parse(o.data)}catch(u){return n.port1.close(),n.port2.close(),this._prepareError(u),i(u)}l.error?i(l.error):l.result!==void 0?s(l.result):s(void 0),n.port1.close(),n.port2.close()};let a="";try{a=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(a,"*",[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 s=JSON.parse(e.data);if(!this._execMessage)return t.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(s.args)||(s.args=[s.args]);const i=this._execMessage(s,e);if(i===void 0)return;i.then((n={})=>{let a,o;typeof n=="object"&&n!==null&&(a=n.error,o=n.result),a?t.postMessage(JSON.stringify({error:a})):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(s){t.postMessage(JSON.stringify({error:this._prepareError(s)}))}}_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=".",f={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},_={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},U=async(r,e)=>{if(typeof r!="string")throw new Error('Configurator ID is not a string type: "'+typeof r+'"');const t=e.customApiUrl?e.customApiUrl:"https://api.roomle.com/v2",s=e.overrideTenant||9,i=t+"/configurators/"+r,n="roomle_portal_v2",a="03-"+window.btoa(new Date().toISOString()+";anonymous;"+n),o=()=>{const h={apiKey:n,currentTenant:s,locale:"en",language:"en",device:1,token:a,platform:"web"};return new Headers(h)},l=new Request(i,{method:"GET",headers:o(),mode:"cors",cache:"default"}),u=await fetch(l),{configurator:d}=await u.json();return d},F=()=>{try{return window.self!==window.top}catch{return!0}},x=["127.0.0.1","localhost","0.0.0.0"],B=()=>{const r=F();let e=window.location.href;if(r){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},C=r=>!!(x.includes(r)||r.endsWith("roomle.com")||r.endsWith("gitlab.io")||r.endsWith("gitlab.com")),b=["language","browserLanguage","userLanguage","systemLanguage"],W=(r=null)=>{const e=window.navigator;if(r)return r.substr(0,2);if(Array.isArray(e.languages)&&e.languages.length>0)return e.languages[0].substr(0,2);for(let t=0,s=b.length;t<s;t++){const i=e[b[t]];if(i)return i.substr(0,2)}return"en"},k=(r,e)=>{const t=JSON.parse(JSON.stringify(r));return w(t,e)},w=(r,e)=>{for(const t in e)try{e[t].constructor===Object?r[t]=w(r[t],e[t]):r[t]=e[t]}catch{r[t]=e[t]}return r};var V={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const G={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)",$=r=>(E(r),r!=null&&r.customApiUrl&&(r.customApiUrl=decodeURIComponent(r.customApiUrl)),r.shareUrl&&(r.deeplink=r.shareUrl.replace(q,Y)),r),E=r=>{if(!r)return;const e=Object.keys(r);for(const t of e){const s=r[t];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&E(s),Array.isArray(s))for(const i of s)E(i);(s==="true"||s==="false")&&(r[t]=s==="true")}},j=(r,e)=>{e.configuratorId=r.id;const t=r.settings||{};return!e.overrideTenant&&r.tenant&&(e.overrideTenant=r.tenant),k(t,e)},z=()=>{const r={...G};r.locale||(r.locale=W()),r.id===J&&delete r.id;const e=B();return e&&C(e)&&(r.configuratorId="demoConfigurator"),r.customApiUrl=V.VITE_RAPI_URL,r.emails=!1,r},q="<CONF_ID>",Y="#CONFIGURATIONID#",M=()=>/(android)/i.test(navigator.userAgent);class v{constructor(){c(this,"_messageHandler",null),c(this,"isSetupDone",!1),c(this,"viewName","main"),c(this,"plugins",{}),c(this,"pluginsLoaded",[]),c(this,"ui",{callbacks:null}),c(this,"extended",{callbacks:null}),c(this,"configurator",{callbacks:null}),c(this,"analytics",{callbacks:{}}),c(this,"global",{callbacks:{}})}setMessageHandler(e){this._messageHandler=e}handleSetup(e){const{methods:t,callbacks:s}=e;t.forEach(i=>{const n=i.split(p),a=n[0],o=n[1];this[a]||(this[a]={}),this[a][o]=function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(i,[...arguments])}.bind(this)}),s.forEach(i=>{const n=i.split(p),a=n[0],o=n[1],l=n[2];this[a]||(this[a]={}),this[a][o]||(this[a][o]={}),this[a][o][l]=()=>{}}),this.isSetupDone=!0}executeMessage({message:e,args:t}){const s=e.split(p),i=s[0],n=s[1],a=s.length===3?s[2]:null;if(a&&this[i][n][a]){const o=this[i][n][a](...t);return o instanceof Promise?o.then(l=>({result:l})):o!==void 0?Promise.resolve({result:o}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}setupPlugins(e,t,s="website"){for(const i of e)typeof i=="string"&&i==="dragIn"?this.pluginsLoaded.push(new Promise((n,a)=>{try{import("./drag-in-BMAQiIyL.mjs").then(({DragIn:o})=>{const l=new o(t);l.setInstance(this.ui),l.setMode(s),l.setViewName(this.viewName),this.plugins.dragIn=l,n()})}catch(o){a(o)}})):i.name&&i.loader&&this.pluginsLoaded.push(new Promise((n,a)=>{try{i.loader().then(o=>{const l=new o(t);l.setInstance(this.ui),l.setMode(s),l.setViewName(this.viewName),this.plugins[i.name]=l,n()})}catch(o){a(o)}}))}}const T=()=>{let r,e;return{promise:new Promise((t,s)=>{r=t,e=s}),resolve:r,reject:e}},S=(r,e,t)=>{let s=null;Object.defineProperty(r,e,{get(){return s||t},set(i){i!=null&&i.mute?s=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 }"),s=i)}})},R=()=>window.innerHeight*.01+"px",N=r=>{r&&setTimeout(()=>r.style.setProperty(y,R()),0)},D="rml-styles",Q=450,y="--rml-full-height",g={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},I=new Map;class K extends v{constructor(e,t,s,i,n){if(super(),c(this,"_waitForIframe"),c(this,"_container"),c(this,"_configuratorSettings"),c(this,"_initData",{}),c(this,"_iframe"),!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(I.has(t))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(D)){const l=s.zIndex||9999999,u=document.createElement("style");u.type="text/css",u.id=D;const d="transition:all ease-in-out "+Q+"ms;",h=["-webkit-","-o-"].reduce((L,P)=>L+=P+d,"")+d,m=R();u.innerHTML=`
1
+ var H=Object.defineProperty,A=(r,e,t)=>e in r?H(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,c=(r,e,t)=>A(r,typeof e!="symbol"?e+"":e,t);class O{constructor(e,t,s,i){c(this,"_side"),c(this,"_incomingMessageBus"),c(this,"_outgoingMessageBus",null),c(this,"_execMessage",null),this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=s,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((s,i)=>{const o=new MessageChannel;o.port1.onmessage=n=>{if(!n||!n.data)return o.port1.close(),o.port2.close(),i(new Error(this._side+" received message but response can not be interpreted"));let l;try{l=JSON.parse(n.data)}catch(u){return o.port1.close(),o.port2.close(),this._prepareError(u),i(u)}l.error?i(l.error):l.result!==void 0?s(l.result):s(void 0),o.port1.close(),o.port2.close()};let a="";try{a=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(a,"*",[o.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 s=JSON.parse(e.data);if(!this._execMessage)return t.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(s.args)||(s.args=[s.args]);const i=this._execMessage(s,e);if(i===void 0)return;i.then((o={})=>{let a,n;typeof o=="object"&&o!==null&&(a=o.error,n=o.result),a?t.postMessage(JSON.stringify({error:a})):n!==void 0?t.postMessage(JSON.stringify({result:n})):t.postMessage(JSON.stringify({result:o}))},o=>{t.postMessage(JSON.stringify({error:this._prepareError(o)}))})}catch(s){t.postMessage(JSON.stringify({error:this._prepareError(s)}))}}_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=".",f={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},_={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},U=async(r,e)=>{if(typeof r!="string")throw new Error('Configurator ID is not a string type: "'+typeof r+'"');const t=e.customApiUrl?e.customApiUrl:"https://api.roomle.com/v2",s=e.overrideTenant||9,i=t+"/configurators/"+r,o="roomle_portal_v2",a="03-"+window.btoa(new Date().toISOString()+";anonymous;"+o),n=()=>{const h={apiKey:o,currentTenant:s,locale:"en",language:"en",device:1,token:a,platform:"web"};return new Headers(h)},l=new Request(i,{method:"GET",headers:n(),mode:"cors",cache:"default"}),u=await fetch(l),{configurator:d}=await u.json();return d},F=()=>{try{return window.self!==window.top}catch{return!0}},x=["127.0.0.1","localhost","0.0.0.0"],B=()=>{const r=F();let e=window.location.href;if(r){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},C=r=>!!(x.includes(r)||r.endsWith("roomle.com")||r.endsWith("gitlab.io")||r.endsWith("gitlab.com")),b=["language","browserLanguage","userLanguage","systemLanguage"],W=(r=null)=>{const e=window.navigator;if(r)return r.substr(0,2);if(Array.isArray(e.languages)&&e.languages.length>0)return e.languages[0].substr(0,2);for(let t=0,s=b.length;t<s;t++){const i=e[b[t]];if(i)return i.substr(0,2)}return"en"},k=(r,e)=>{const t=JSON.parse(JSON.stringify(r));return w(t,e)},w=(r,e)=>{for(const t in e)try{e[t].constructor===Object?r[t]=w(r[t],e[t]):r[t]=e[t]}catch{r[t]=e[t]}return r};var V={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const G={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)",$=r=>(E(r),r!=null&&r.customApiUrl&&(r.customApiUrl=decodeURIComponent(r.customApiUrl)),r.shareUrl&&(r.deeplink=r.shareUrl.replace(q,Y)),r),E=r=>{if(!r)return;const e=Object.keys(r);for(const t of e){const s=r[t];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&E(s),Array.isArray(s))for(const i of s)E(i);(s==="true"||s==="false")&&(r[t]=s==="true")}},j=(r,e)=>{e.configuratorId=r.id;const t=r.settings||{};return!e.overrideTenant&&r.tenant&&(e.overrideTenant=r.tenant),k(t,e)},z=()=>{const r={...G};r.locale||(r.locale=W()),r.id===J&&delete r.id;const e=B();return e&&C(e)&&(r.configuratorId="demoConfigurator"),r.customApiUrl=V.VITE_RAPI_URL,r.emails=!1,r},q="<CONF_ID>",Y="#CONFIGURATIONID#",v=()=>/(android)/i.test(navigator.userAgent);class M{constructor(){c(this,"_messageHandler",null),c(this,"isSetupDone",!1),c(this,"viewName","main"),c(this,"plugins",{}),c(this,"pluginsLoaded",[]),c(this,"ui",{callbacks:null}),c(this,"extended",{callbacks:null}),c(this,"configurator",{callbacks:null}),c(this,"analytics",{callbacks:{}}),c(this,"global",{callbacks:{}})}setMessageHandler(e){this._messageHandler=e}handleSetup(e){const{methods:t,callbacks:s}=e;t.forEach(i=>{const o=i.split(p),a=o[0],n=o[1];this[a]||(this[a]={}),this[a][n]=function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(i,[...arguments])}.bind(this)}),s.forEach(i=>{const o=i.split(p),a=o[0],n=o[1],l=o[2];this[a]||(this[a]={}),this[a][n]||(this[a][n]={}),this[a][n][l]=()=>{}}),this.isSetupDone=!0}executeMessage({message:e,args:t}){const s=e.split(p),i=s[0],o=s[1],a=s.length===3?s[2]:null;if(a&&this[i][o][a]){const n=this[i][o][a](...t);return n instanceof Promise?n.then(l=>({result:l})):n!==void 0?Promise.resolve({result:n}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}setupPlugins(e,t,s="website"){for(const i of e)typeof i=="string"&&i==="dragIn"?this.pluginsLoaded.push(new Promise((o,a)=>{try{import("./drag-in-DhWNfKDL.mjs").then(({DragIn:n})=>{const l=new n(t,s);l.setInstance(this.ui),l.setViewName(this.viewName),this.plugins.dragIn=l,o()})}catch(n){a(n)}})):i.name&&i.loader&&this.pluginsLoaded.push(new Promise((o,a)=>{try{i.loader().then(n=>{const l=new n(t,s);l.setInstance(this.ui),l.setViewName(this.viewName),this.plugins[i.name]=l,o()})}catch(n){a(n)}}))}}const T=()=>{let r,e;return{promise:new Promise((t,s)=>{r=t,e=s}),resolve:r,reject:e}},S=(r,e,t)=>{let s=null;Object.defineProperty(r,e,{get(){return s||t},set(i){i!=null&&i.mute?s=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 }"),s=i)}})},R=()=>window.innerHeight*.01+"px",N=r=>{r&&setTimeout(()=>r.style.setProperty(y,R()),0)},D="rml-styles",Q=450,y="--rml-full-height",g={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},I=new Map;class K extends M{constructor(e,t,s,i,o){if(super(),c(this,"_waitForIframe"),c(this,"_container"),c(this,"_configuratorSettings"),c(this,"_initData",{}),c(this,"_iframe"),!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(I.has(t))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(D)){const l=s.zIndex||9999999,u=document.createElement("style");u.type="text/css",u.id=D;const d="transition:all ease-in-out "+Q+"ms;",h=["-webkit-","-o-"].reduce((L,P)=>L+=P+d,"")+d,m=R();u.innerHTML=`
2
2
  .${g.CONTAINER}{${y}:${m};}
3
3
  .${g.POSITION}{position:fixed;top:0;left:0;z-index:${l};opacity:0}
4
4
  .${g.TRANSITION}{${h}}
5
5
  .${g.FILL}{width:100%;height:100%;opacity:1}
6
6
  .${g.ANDROID_HEIGHT}{height:calc(var(${y},1vh)*100)}
7
7
  .${g.OVERFLOW_HIDDEN}{overflow:hidden}
8
- `,document.head.appendChild(u)}this._executeMessage=this._executeMessage.bind(this);const a=new O("website",window,null,this._executeMessage);this.setMessageHandler(a),this._onResize=this._onResize.bind(this),M()&&window.addEventListener("resize",this._onResize),this._container=t,this._initData=s,this._configuratorSettings=e;const o=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=n,this._container.appendChild(o),this._iframe=o,this.setupPlugins(i,this._iframe),I.set(t,!0)}static createPlanner(e,t,s,i=[]){return this._create(e,t,s,i)}static async connect(e,t=[]){const s=new v;s.viewName=e;const{resolve:i,promise:n}=T(),{resolve:a,promise:o}=T(),l=({message:h,args:m})=>{if(h===_.REGISTER_CUSTOM_VIEW_DONE){i();return}if(h===_.RETURN_METHODS){s.handleSetup(m[0]),a();return}if(s.isSetupDone)return s.executeMessage({message:h,args:m})},u=new O("custom-view",window,window.parent,l);s.setMessageHandler(u);const d=[e];return u.sendMessage(_.REGISTER_CUSTOM_VIEW,d),await n,u.sendMessage(_.GET_METHODS,d),await o,s.setupPlugins(t,document.body,"custom-view"),await Promise.allSettled(s.pluginsLoaded),s}static createConfigurator(e,t,s,i=[]){return this._create(e,t,s,i)}static create(e,t,s,i){return this._create(e,t,s,i)}static createViewer(e,t,s,i=[]){return this._create(e,t,s,i)}static async _create(e,t,s,i){return new Promise(async(n,a)=>{try{const o=w(z(),$(s));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 l=await U(e,o);s=j(l,o);const u=new this(l,t,s,i,n);return await Promise.allSettled(u.pluginsLoaded),u}catch(o){return a(o)}})}teardown(){this._container&&I.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 s=((e=this._configuratorSettings)==null?void 0:e.url)||"https://www.roomle.com/t/cp/";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),t.src=s,t.classList.add(g.CONTAINER),t.classList.add(g.FILL),t}_onResize(){N(this._iframe)}_onUseFullPage(){this._iframe.classList.add(g.POSITION),document.documentElement.classList.add(g.OVERFLOW_HIDDEN),window.document.body.classList.add(g.OVERFLOW_HIDDEN),M()&&(N(this._iframe),this._iframe.classList.add(g.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(g.POSITION),this._iframe.classList.remove(g.ANDROID_HEIGHT),document.documentElement.classList.remove(g.OVERFLOW_HIDDEN),window.document.body.classList.remove(g.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:t},s){var i;if(s.source&&s.source===((i=this._iframe)==null?void 0:i.contentWindow))return e===f.REQUEST_BOOT?this._messageHandler?(this._messageHandler.setOutgoingMessageBus(s.source),Promise.resolve({result:this._initData})):(console.error("MessageHandler not set"),Promise.resolve({error:"MessageHandler not set"})):e===f.SETUP?(this.handleSetup(t[0]),S(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),S(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(f.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:e,args:t})}}export{K as default};
8
+ `,document.head.appendChild(u)}this._executeMessage=this._executeMessage.bind(this);const a=new O("website",window,null,this._executeMessage);this.setMessageHandler(a),this._onResize=this._onResize.bind(this),v()&&window.addEventListener("resize",this._onResize),this._container=t,this._initData=s,this._configuratorSettings=e;const n=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=o,this._container.appendChild(n),this._iframe=n,this.setupPlugins(i,this._iframe),I.set(t,!0)}static createPlanner(e,t,s,i=[]){return this._create(e,t,s,i)}static async connect(e,t=[]){const s=new M;s.viewName=e;const{resolve:i,promise:o}=T(),{resolve:a,promise:n}=T(),l=({message:h,args:m})=>{if(h===_.REGISTER_CUSTOM_VIEW_DONE){i();return}if(h===_.RETURN_METHODS){s.handleSetup(m[0]),a();return}if(s.isSetupDone)return s.executeMessage({message:h,args:m})},u=new O("custom-view",window,window.parent,l);s.setMessageHandler(u);const d=[e];return u.sendMessage(_.REGISTER_CUSTOM_VIEW,d),await o,u.sendMessage(_.GET_METHODS,d),await n,s.setupPlugins(t,document.body,"custom-view"),await Promise.allSettled(s.pluginsLoaded),s}static createConfigurator(e,t,s,i=[]){return this._create(e,t,s,i)}static create(e,t,s,i){return this._create(e,t,s,i)}static createViewer(e,t,s,i=[]){return this._create(e,t,s,i)}static async _create(e,t,s,i){return new Promise(async(o,a)=>{try{const n=w(z(),$(s));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);const l=await U(e,n);s=j(l,n);const u=new this(l,t,s,i,o);return await Promise.allSettled(u.pluginsLoaded),u}catch(n){return a(n)}})}teardown(){this._container&&I.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 s=((e=this._configuratorSettings)==null?void 0:e.url)||"https://www.roomle.com/t/cp/";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),t.src=s,t.classList.add(g.CONTAINER),t.classList.add(g.FILL),t}_onResize(){N(this._iframe)}_onUseFullPage(){this._iframe.classList.add(g.POSITION),document.documentElement.classList.add(g.OVERFLOW_HIDDEN),window.document.body.classList.add(g.OVERFLOW_HIDDEN),v()&&(N(this._iframe),this._iframe.classList.add(g.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(g.POSITION),this._iframe.classList.remove(g.ANDROID_HEIGHT),document.documentElement.classList.remove(g.OVERFLOW_HIDDEN),window.document.body.classList.remove(g.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:t},s){var i;if(s.source&&s.source===((i=this._iframe)==null?void 0:i.contentWindow))return e===f.REQUEST_BOOT?this._messageHandler?(this._messageHandler.setOutgoingMessageBus(s.source),Promise.resolve({result:this._initData})):(console.error("MessageHandler not set"),Promise.resolve({error:"MessageHandler not set"})):e===f.SETUP?(this.handleSetup(t[0]),S(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),S(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(f.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:e,args:t})}}export{K as default};
@@ -1,14 +1,14 @@
1
- (function(_,f){typeof exports=="object"&&typeof module<"u"?module.exports=f():typeof define=="function"&&define.amd?define(f):(_=typeof globalThis<"u"?globalThis:_||self,_["roomle-embedding-lib"]=_["roomle-embedding-lib"]||{},_["roomle-embedding-lib"].umd=_["roomle-embedding-lib"].umd||{},_["roomle-embedding-lib"].umd.js=f())})(this,function(){"use strict";var ve=Object.defineProperty;var Le=(_,f,E)=>f in _?ve(_,f,{enumerable:!0,configurable:!0,writable:!0,value:E}):_[f]=E;var l=(_,f,E)=>Le(_,typeof f!="symbol"?f+"":f,E);class _{constructor(t,e,s,r){l(this,"_side");l(this,"_incomingMessageBus");l(this,"_outgoingMessageBus",null);l(this,"_execMessage",null);this._side=t,this._incomingMessageBus=e,this._outgoingMessageBus=s,this._execMessage=r,this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(t){this._outgoingMessageBus=t}setMessageExecution(t){this._execMessage=t}sendMessage(t,e=[]){return new Promise((s,r)=>{const i=new MessageChannel;i.port1.onmessage=c=>{if(!c||!c.data)return i.port1.close(),i.port2.close(),r(new Error(this._side+" received message but response can not be interpreted"));let a;try{a=JSON.parse(c.data)}catch(d){return i.port1.close(),i.port2.close(),this._prepareError(d),r(d)}a.error?r(a.error):a.result!==void 0?s(a.result):s(void 0),i.port1.close(),i.port2.close()};let o="";try{o=JSON.stringify({message:t,args:e})}catch{return r(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return r(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(o,"*",[i.port2])})}_handleMessage(t){const e=t.ports&&Array.isArray(t.ports)&&t.ports.length>0?t.ports[0]:null;if(t.data&&e)try{const s=JSON.parse(t.data);if(!this._execMessage)return e.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(s.args)||(s.args=[s.args]);const r=this._execMessage(s,t);if(r===void 0)return;r.then((i={})=>{let o,c;typeof i=="object"&&i!==null&&(o=i.error,c=i.result),o?e.postMessage(JSON.stringify({error:o})):c!==void 0?e.postMessage(JSON.stringify({result:c})):e.postMessage(JSON.stringify({result:i}))},i=>{e.postMessage(JSON.stringify({error:this._prepareError(i)}))})}catch(s){e.postMessage(JSON.stringify({error:this._prepareError(s)}))}}_prepareError(t){if(typeof t=="string"){const e=this._side+": "+t;return console.error(e),e}return t.message=this._side+": "+t.message,console.error(t),t.message}}const f=".",E={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},S={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},ie=async(n,t)=>{if(typeof n!="string")throw new Error('Configurator ID is not a string type: "'+typeof n+'"');const e=t.customApiUrl?t.customApiUrl:"https://api.roomle.com/v2",s=t.overrideTenant||9,r=e+"/configurators/"+n,i="roomle_portal_v2",o="03-"+window.btoa(new Date().toISOString()+";anonymous;"+i),c=()=>{const g={apiKey:i,currentTenant:s,locale:"en",language:"en",device:1,token:o,platform:"web"};return new Headers(g)},a=new Request(r,{method:"GET",headers:c(),mode:"cors",cache:"default"}),d=await fetch(a),{configurator:u}=await d.json();return u},oe=()=>{try{return window.self!==window.top}catch{return!0}},ae=["127.0.0.1","localhost","0.0.0.0"],ce=()=>{const n=oe();let t=window.location.href;if(n){if(!document.referrer)return null;t=document.referrer}const{hostname:e}=new URL(t);return e},le=n=>!!(ae.includes(n)||n.endsWith("roomle.com")||n.endsWith("gitlab.io")||n.endsWith("gitlab.com")),k=["language","browserLanguage","userLanguage","systemLanguage"],ue=(n=null)=>{const t=window.navigator;if(n)return n.substr(0,2);if(Array.isArray(t.languages)&&t.languages.length>0)return t.languages[0].substr(0,2);for(let e=0,s=k.length;e<s;e++){const r=t[k[e]];if(r)return r.substr(0,2)}return"en"},he=(n,t)=>{const e=JSON.parse(JSON.stringify(n));return M(e,t)},M=(n,t)=>{for(const e in t)try{t[e].constructor===Object?n[e]=M(n[e],t[e]):n[e]=t[e]}catch{n[e]=t[e]}return n};var de={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const ge={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},_e="(idle)",me=n=>(N(n),n!=null&&n.customApiUrl&&(n.customApiUrl=decodeURIComponent(n.customApiUrl)),n.shareUrl&&(n.deeplink=n.shareUrl.replace(ye,we)),n),N=n=>{if(!n)return;const t=Object.keys(n);for(const e of t){const s=n[e];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&N(s),Array.isArray(s))for(const r of s)N(r);(s==="true"||s==="false")&&(n[e]=s==="true")}},fe=(n,t)=>{t.configuratorId=n.id;const e=n.settings||{};return!t.overrideTenant&&n.tenant&&(t.overrideTenant=n.tenant),he(e,t)},pe=()=>{const n={...ge};n.locale||(n.locale=ue()),n.id===_e&&delete n.id;const t=ce();return t&&le(t)&&(n.configuratorId="demoConfigurator"),n.customApiUrl=de.VITE_RAPI_URL,n.emails=!1,n},ye="<CONF_ID>",we="#CONFIGURATIONID#",G=()=>/(android)/i.test(navigator.userAgent);class Y{constructor(){l(this,"_messageHandler",null);l(this,"isSetupDone",!1);l(this,"viewName","main");l(this,"plugins",{});l(this,"pluginsLoaded",[]);l(this,"ui",{callbacks:null});l(this,"extended",{callbacks:null});l(this,"configurator",{callbacks:null});l(this,"analytics",{callbacks:{}});l(this,"global",{callbacks:{}})}setMessageHandler(t){this._messageHandler=t}handleSetup(t){const{methods:e,callbacks:s}=t;e.forEach(r=>{const i=r.split(f),o=i[0],c=i[1];this[o]||(this[o]={}),this[o][c]=(function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(r,[...arguments])}).bind(this)}),s.forEach(r=>{const i=r.split(f),o=i[0],c=i[1],a=i[2];this[o]||(this[o]={}),this[o][c]||(this[o][c]={}),this[o][c][a]=()=>{}}),this.isSetupDone=!0}executeMessage({message:t,args:e}){const s=t.split(f),r=s[0],i=s[1],o=s.length===3?s[2]:null;if(o&&this[r][i][o]){const c=this[r][i][o](...e);return c instanceof Promise?c.then(a=>({result:a})):c!==void 0?Promise.resolve({result:c}):Promise.resolve({result:null})}return Promise.reject('Message "'+t+'" is unkown')}setupPlugins(t,e,s="website"){for(const r of t)typeof r=="string"&&r==="dragIn"?this.pluginsLoaded.push(new Promise((i,o)=>{try{Promise.resolve().then(()=>xe).then(({DragIn:c})=>{const a=new c(e);a.setInstance(this.ui),a.setMode(s),a.setViewName(this.viewName),this.plugins.dragIn=a,i()})}catch(c){o(c)}})):r.name&&r.loader&&this.pluginsLoaded.push(new Promise((i,o)=>{try{r.loader().then(c=>{const a=new c(e);a.setInstance(this.ui),a.setMode(s),a.setViewName(this.viewName),this.plugins[r.name]=a,i()})}catch(c){o(c)}}))}}const B=()=>{let n,t;return{promise:new Promise((s,r)=>{n=s,t=r}),resolve:n,reject:t}},W=(n,t,e)=>{let s=null;Object.defineProperty(n,t,{get(){return s||e},set(r){r!=null&&r.mute?s=r.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 }"),s=r)}})},z=()=>window.innerHeight*.01+"px",X=n=>{n&&setTimeout(()=>n.style.setProperty(x,z()),0)},V="rml-styles",Ee=450,x="--rml-full-height",m={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},v=new Map;class De extends Y{constructor(e,s,r,i,o){super();l(this,"_waitForIframe");l(this,"_container");l(this,"_configuratorSettings");l(this,"_initData",{});l(this,"_iframe");if(!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(v.has(s))throw new Error("There is already an instance on this DOM element");if(!!!document.getElementById(V)){const u=r.zIndex||9999999,g=document.createElement("style");g.type="text/css",g.id=V;const h="transition:all ease-in-out "+Ee+"ms;",w=["-webkit-","-o-"].reduce((D,T)=>D+=T+h,"")+h,$=z();g.innerHTML=`
2
- .${m.CONTAINER}{${x}:${$};}
3
- .${m.POSITION}{position:fixed;top:0;left:0;z-index:${u};opacity:0}
4
- .${m.TRANSITION}{${w}}
5
- .${m.FILL}{width:100%;height:100%;opacity:1}
6
- .${m.ANDROID_HEIGHT}{height:calc(var(${x},1vh)*100)}
7
- .${m.OVERFLOW_HIDDEN}{overflow:hidden}
8
- `,document.head.appendChild(g)}this._executeMessage=this._executeMessage.bind(this);const a=new _("website",window,null,this._executeMessage);this.setMessageHandler(a),this._onResize=this._onResize.bind(this),G()&&window.addEventListener("resize",this._onResize),this._container=s,this._initData=r,this._configuratorSettings=e;const d=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=o,this._container.appendChild(d),this._iframe=d,this.setupPlugins(i,this._iframe),v.set(s,!0)}static createPlanner(e,s,r,i=[]){return this._create(e,s,r,i)}static async connect(e,s=[]){const r=new Y;r.viewName=e;const{resolve:i,promise:o}=B(),{resolve:c,promise:a}=B(),d=({message:h,args:w})=>{if(h===S.REGISTER_CUSTOM_VIEW_DONE){i();return}if(h===S.RETURN_METHODS){r.handleSetup(w[0]),c();return}if(r.isSetupDone)return r.executeMessage({message:h,args:w})},u=new _("custom-view",window,window.parent,d);r.setMessageHandler(u);const g=[e];return u.sendMessage(S.REGISTER_CUSTOM_VIEW,g),await o,u.sendMessage(S.GET_METHODS,g),await a,r.setupPlugins(s,document.body,"custom-view"),await Promise.allSettled(r.pluginsLoaded),r}static createConfigurator(e,s,r,i=[]){return this._create(e,s,r,i)}static create(e,s,r,i){return this._create(e,s,r,i)}static createViewer(e,s,r,i=[]){return this._create(e,s,r,i)}static async _create(e,s,r,i){return new Promise(async(o,c)=>{try{const a=M(pe(),me(r));a.featureFlags||(a.featureFlags={}),typeof a.featureFlags.realPartList!="boolean"&&(a.featureFlags.realPartList=!0),typeof a.featureFlags.globalCallbacks!="boolean"&&(a.featureFlags.globalCallbacks=!0),typeof a.featureFlags.mocAr!="boolean"&&(a.featureFlags.mocAr=!1);const d=await ie(e,a);r=fe(d,a);const u=new this(d,s,r,i,o);return await Promise.allSettled(u.pluginsLoaded),u}catch(a){return c(a)}})}teardown(){this._container&&v.delete(this._container);const e=this._container.querySelector("iframe");e&&this._container.removeChild(e),window.removeEventListener("resize",this._onResize)}_createIframe(){var r;const e=document.createElement("iframe");let s=((r=this._configuratorSettings)==null?void 0:r.url)||"https://www.roomle.com/t/cp/";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(m.CONTAINER),e.classList.add(m.FILL),e}_onResize(){X(this._iframe)}_onUseFullPage(){this._iframe.classList.add(m.POSITION),document.documentElement.classList.add(m.OVERFLOW_HIDDEN),window.document.body.classList.add(m.OVERFLOW_HIDDEN),G()&&(X(this._iframe),this._iframe.classList.add(m.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(m.POSITION),this._iframe.classList.remove(m.ANDROID_HEIGHT),document.documentElement.classList.remove(m.OVERFLOW_HIDDEN),window.document.body.classList.remove(m.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:s},r){var i;if(r.source&&r.source===((i=this._iframe)==null?void 0:i.contentWindow))return e===E.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===E.SETUP?(this.handleSetup(s[0]),W(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),W(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(E.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:e,args:s})}}class Te{constructor(t=16){l(this,"_computedStyleCache",new Map);l(this,"_maxLifetime",16);l(this,"_cacheCleanInterval",null);this._maxLifetime=t}get(t){const e=this._computedStyleCache.get(t),s=Date.now();if(e&&s-e.updated<this._maxLifetime)return e.style;const r=getComputedStyle(t);return this._computedStyleCache.set(t,{style:r,updated:s}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),r}_cleanUpCache(){const t=Date.now();for(const[e,{updated:s}]of this._computedStyleCache.entries())t-s>=this._maxLifetime&&this._computedStyleCache.delete(e);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const q=n=>window.TouchEvent&&n instanceof window.TouchEvent;let L;const I=n=>(L||(L=new Te),L.get(n)),J=(n,t,e)=>{const s=parseFloat(n),r=window.devicePixelRatio||1;if(t==="px")return s;if(t==="%"){const o=e===document.documentElement?window.innerWidth:e.offsetWidth;return s/100*o}if(t==="rem"){const o=parseFloat(I(document.documentElement).fontSize);return s*o}if(t==="em"){const o=parseFloat(I(e).fontSize);return s*o}if(t==="vh"||t==="vw"||t==="vmin"||t==="vmax"){const o={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return s/100*o[t]}const i={cm:37.7952755906,mm:3.77952755906,in:96};return t in i?s*i[t]*r:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},Se=(n,t,e={x:0,y:0})=>{const s=n.getBoundingClientRect(),i=I(n).transform;let o=0,c=0;if(i!=="none"){const h=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,w=i.match(h);w&&(o=J(w[1],w[2],n),c=J(w[3],w[4],n))}const{clientX:a,clientY:d}=K(t,e),u=a-s.left-o+n.scrollLeft,g=d-s.top-c+n.scrollTop;return{x:u,y:g}},K=(n,t)=>{const{clientX:e,clientY:s}=q(n)?Ie(n):n,r=e>0?e:t.x,i=s>0?s:t.y;return{clientX:r,clientY:i}},Ie=n=>{if(n.touches.length){let{clientX:e,clientY:s}=n.touches[0];if(n.touches.length>1){const r=n.touches[1],i=r.clientX,o=r.clientY;e=(e+i)/2,s=(s+o)/2}return{clientX:e,clientY:s}}const t=n.changedTouches[0];return{clientX:t.clientX,clientY:t.clientY}},Oe=(n,t)=>{const e=t.x+t.width,s=t.x,r=t.y+t.height,i=t.y,{x:o,y:c}=n;return o>=s&&o<=e&&c>=i&&c<=r},j=500,Q=10;class be{constructor(t,{onTouchDragStart:e},s={}){l(this,"_touchDragTimeOut");l(this,"_onTouchDragStart");l(this,"_payload",null);l(this,"_delay",j);l(this,"_firstTouch",null);l(this,"_lastTouch",null);l(this,"_epsilon",Q);this._payload=t,this._onTouchDragStart=e,this._delay=s.delay||j,this._epsilon=s.epsilon||Q}onTouchStart(t){var e;!t||!((e=t==null?void 0:t.touches)!=null&&e.length)||this._touchDragTimeOut||(this._firstTouch=t.touches[t.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=t.touches[0]),this._checkXDistance(t)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(t){var e;!t||!((e=t==null?void 0:t.touches)!=null&&e.length)||(this._lastTouch=t.touches[0])}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(t){return()=>{if(!this._firstTouch||!this._lastTouch)return;let e=!1;e=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,e&&(this._onTouchDragStart(this._payload,t),this._resetTouches())}}}class Ae{constructor(){l(this,"_instance",null);l(this,"_mode","website");l(this,"_viewName","main")}setInstance(t){this._instance=t}setMode(t){this._mode=t}setViewName(t){this._viewName=t}}const Re=n=>new Promise(t=>setTimeout(t,n)),Z="rml-drag-in-styles",Me="rml-drag-in-drag-element",O="rml-drag-in-overlay",C="rml-drag-in-spacer",b="rml-drag-in-drag-ghost",P="rml-drag-in-fade-in",ee="rml-drag-in-fade-out",H={DISPLAY_NONE:"rml-display-none"},te=.5,F="250ms",U="forwards",A=n=>n?!0:(console.warn("No instance set, cancel drag-in"),!1);class Ne extends Ae{constructor(e){super();l(this,"_mainDomElement");l(this,"_currentDrag",{});l(this,"_currentTouch",null);l(this,"_firefoxDragPosition",{x:0,y:0});l(this,"_readyForDragUpdates",!1);l(this,"options",{});l(this,"_firefoxFallback",e=>{if(!this._currentDrag.event)return;const s=e||window.event;this._firefoxDragPosition.x=s.pageX||0,this._firefoxDragPosition.y=s.pageY||0});this._mainDomElement=e,this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),this._initReadyForDragUpdates(),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!!!document.getElementById(Z)){const s=document.createElement("style");s.type="text/css",s.id=Z,s.innerHTML=`
1
+ (function(h,_){typeof exports=="object"&&typeof module<"u"?module.exports=_():typeof define=="function"&&define.amd?define(_):(h=typeof globalThis<"u"?globalThis:h||self,h["roomle-embedding-lib"]=h["roomle-embedding-lib"]||{},h["roomle-embedding-lib"].umd=h["roomle-embedding-lib"].umd||{},h["roomle-embedding-lib"].umd.js=_())})(this,function(){"use strict";var ve=Object.defineProperty;var Le=(h,_,E)=>_ in h?ve(h,_,{enumerable:!0,configurable:!0,writable:!0,value:E}):h[_]=E;var l=(h,_,E)=>Le(h,typeof _!="symbol"?_+"":_,E);class h{constructor(s,e,t,r){l(this,"_side");l(this,"_incomingMessageBus");l(this,"_outgoingMessageBus",null);l(this,"_execMessage",null);this._side=s,this._incomingMessageBus=e,this._outgoingMessageBus=t,this._execMessage=r,this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(s){this._outgoingMessageBus=s}setMessageExecution(s){this._execMessage=s}sendMessage(s,e=[]){return new Promise((t,r)=>{const i=new MessageChannel;i.port1.onmessage=c=>{if(!c||!c.data)return i.port1.close(),i.port2.close(),r(new Error(this._side+" received message but response can not be interpreted"));let a;try{a=JSON.parse(c.data)}catch(u){return i.port1.close(),i.port2.close(),this._prepareError(u),r(u)}a.error?r(a.error):a.result!==void 0?t(a.result):t(void 0),i.port1.close(),i.port2.close()};let o="";try{o=JSON.stringify({message:s,args:e})}catch{return r(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return r(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(o,"*",[i.port2])})}_handleMessage(s){const e=s.ports&&Array.isArray(s.ports)&&s.ports.length>0?s.ports[0]:null;if(s.data&&e)try{const t=JSON.parse(s.data);if(!this._execMessage)return e.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(t.args)||(t.args=[t.args]);const r=this._execMessage(t,s);if(r===void 0)return;r.then((i={})=>{let o,c;typeof i=="object"&&i!==null&&(o=i.error,c=i.result),o?e.postMessage(JSON.stringify({error:o})):c!==void 0?e.postMessage(JSON.stringify({result:c})):e.postMessage(JSON.stringify({result:i}))},i=>{e.postMessage(JSON.stringify({error:this._prepareError(i)}))})}catch(t){e.postMessage(JSON.stringify({error:this._prepareError(t)}))}}_prepareError(s){if(typeof s=="string"){const e=this._side+": "+s;return console.error(e),e}return s.message=this._side+": "+s.message,console.error(s),s.message}}const _=".",E={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},I={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},ie=async(n,s)=>{if(typeof n!="string")throw new Error('Configurator ID is not a string type: "'+typeof n+'"');const e=s.customApiUrl?s.customApiUrl:"https://api.roomle.com/v2",t=s.overrideTenant||9,r=e+"/configurators/"+n,i="roomle_portal_v2",o="03-"+window.btoa(new Date().toISOString()+";anonymous;"+i),c=()=>{const f={apiKey:i,currentTenant:t,locale:"en",language:"en",device:1,token:o,platform:"web"};return new Headers(f)},a=new Request(r,{method:"GET",headers:c(),mode:"cors",cache:"default"}),u=await fetch(a),{configurator:d}=await u.json();return d},oe=()=>{try{return window.self!==window.top}catch{return!0}},ae=["127.0.0.1","localhost","0.0.0.0"],ce=()=>{const n=oe();let s=window.location.href;if(n){if(!document.referrer)return null;s=document.referrer}const{hostname:e}=new URL(s);return e},le=n=>!!(ae.includes(n)||n.endsWith("roomle.com")||n.endsWith("gitlab.io")||n.endsWith("gitlab.com")),$=["language","browserLanguage","userLanguage","systemLanguage"],ue=(n=null)=>{const s=window.navigator;if(n)return n.substr(0,2);if(Array.isArray(s.languages)&&s.languages.length>0)return s.languages[0].substr(0,2);for(let e=0,t=$.length;e<t;e++){const r=s[$[e]];if(r)return r.substr(0,2)}return"en"},de=(n,s)=>{const e=JSON.parse(JSON.stringify(n));return M(e,s)},M=(n,s)=>{for(const e in s)try{s[e].constructor===Object?n[e]=M(n[e],s[e]):n[e]=s[e]}catch{n[e]=s[e]}return n};var he={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const ge={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},_e="(idle)",me=n=>(x(n),n!=null&&n.customApiUrl&&(n.customApiUrl=decodeURIComponent(n.customApiUrl)),n.shareUrl&&(n.deeplink=n.shareUrl.replace(ye,we)),n),x=n=>{if(!n)return;const s=Object.keys(n);for(const e of s){const t=n[e];if(!Array.isArray(t)&&typeof t=="object"&&t!==null&&x(t),Array.isArray(t))for(const r of t)x(r);(t==="true"||t==="false")&&(n[e]=t==="true")}},fe=(n,s)=>{s.configuratorId=n.id;const e=n.settings||{};return!s.overrideTenant&&n.tenant&&(s.overrideTenant=n.tenant),de(e,s)},pe=()=>{const n={...ge};n.locale||(n.locale=ue()),n.id===_e&&delete n.id;const s=ce();return s&&le(s)&&(n.configuratorId="demoConfigurator"),n.customApiUrl=he.VITE_RAPI_URL,n.emails=!1,n},ye="<CONF_ID>",we="#CONFIGURATIONID#",G=()=>/(android)/i.test(navigator.userAgent);class Y{constructor(){l(this,"_messageHandler",null);l(this,"isSetupDone",!1);l(this,"viewName","main");l(this,"plugins",{});l(this,"pluginsLoaded",[]);l(this,"ui",{callbacks:null});l(this,"extended",{callbacks:null});l(this,"configurator",{callbacks:null});l(this,"analytics",{callbacks:{}});l(this,"global",{callbacks:{}})}setMessageHandler(s){this._messageHandler=s}handleSetup(s){const{methods:e,callbacks:t}=s;e.forEach(r=>{const i=r.split(_),o=i[0],c=i[1];this[o]||(this[o]={}),this[o][c]=(function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(r,[...arguments])}).bind(this)}),t.forEach(r=>{const i=r.split(_),o=i[0],c=i[1],a=i[2];this[o]||(this[o]={}),this[o][c]||(this[o][c]={}),this[o][c][a]=()=>{}}),this.isSetupDone=!0}executeMessage({message:s,args:e}){const t=s.split(_),r=t[0],i=t[1],o=t.length===3?t[2]:null;if(o&&this[r][i][o]){const c=this[r][i][o](...e);return c instanceof Promise?c.then(a=>({result:a})):c!==void 0?Promise.resolve({result:c}):Promise.resolve({result:null})}return Promise.reject('Message "'+s+'" is unkown')}setupPlugins(s,e,t="website"){for(const r of s)typeof r=="string"&&r==="dragIn"?this.pluginsLoaded.push(new Promise((i,o)=>{try{Promise.resolve().then(()=>xe).then(({DragIn:c})=>{const a=new c(e,t);a.setInstance(this.ui),a.setViewName(this.viewName),this.plugins.dragIn=a,i()})}catch(c){o(c)}})):r.name&&r.loader&&this.pluginsLoaded.push(new Promise((i,o)=>{try{r.loader().then(c=>{const a=new c(e,t);a.setInstance(this.ui),a.setViewName(this.viewName),this.plugins[r.name]=a,i()})}catch(c){o(c)}}))}}const B=()=>{let n,s;return{promise:new Promise((t,r)=>{n=t,s=r}),resolve:n,reject:s}},W=(n,s,e)=>{let t=null;Object.defineProperty(n,s,{get(){return t||e},set(r){r!=null&&r.mute?t=r.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 }"),t=r)}})},z=()=>window.innerHeight*.01+"px",X=n=>{n&&setTimeout(()=>n.style.setProperty(v,z()),0)},V="rml-styles",Ee=450,v="--rml-full-height",g={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},L=new Map;class De extends Y{constructor(e,t,r,i,o){super();l(this,"_waitForIframe");l(this,"_container");l(this,"_configuratorSettings");l(this,"_initData",{});l(this,"_iframe");if(!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(L.has(t))throw new Error("There is already an instance on this DOM element");if(!!!document.getElementById(V)){const d=r.zIndex||9999999,f=document.createElement("style");f.type="text/css",f.id=V;const w="transition:all ease-in-out "+Ee+"ms;",y=["-webkit-","-o-"].reduce((T,S)=>T+=S+w,"")+w,k=z();f.innerHTML=`
2
+ .${g.CONTAINER}{${v}:${k};}
3
+ .${g.POSITION}{position:fixed;top:0;left:0;z-index:${d};opacity:0}
4
+ .${g.TRANSITION}{${y}}
5
+ .${g.FILL}{width:100%;height:100%;opacity:1}
6
+ .${g.ANDROID_HEIGHT}{height:calc(var(${v},1vh)*100)}
7
+ .${g.OVERFLOW_HIDDEN}{overflow:hidden}
8
+ `,document.head.appendChild(f)}this._executeMessage=this._executeMessage.bind(this);const a=new h("website",window,null,this._executeMessage);this.setMessageHandler(a),this._onResize=this._onResize.bind(this),G()&&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._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=o,this._container.appendChild(u),this._iframe=u,this.setupPlugins(i,this._iframe),L.set(t,!0)}static createPlanner(e,t,r,i=[]){return this._create(e,t,r,i)}static async connect(e,t=[]){const r=new Y;r.viewName=e;const{resolve:i,promise:o}=B(),{resolve:c,promise:a}=B(),u=({message:w,args:y})=>{if(w===I.REGISTER_CUSTOM_VIEW_DONE){i();return}if(w===I.RETURN_METHODS){r.handleSetup(y[0]),c();return}if(r.isSetupDone)return r.executeMessage({message:w,args:y})},d=new h("custom-view",window,window.parent,u);r.setMessageHandler(d);const f=[e];return d.sendMessage(I.REGISTER_CUSTOM_VIEW,f),await o,d.sendMessage(I.GET_METHODS,f),await a,r.setupPlugins(t,document.body,"custom-view"),await Promise.allSettled(r.pluginsLoaded),r}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(o,c)=>{try{const a=M(pe(),me(r));a.featureFlags||(a.featureFlags={}),typeof a.featureFlags.realPartList!="boolean"&&(a.featureFlags.realPartList=!0),typeof a.featureFlags.globalCallbacks!="boolean"&&(a.featureFlags.globalCallbacks=!0),typeof a.featureFlags.mocAr!="boolean"&&(a.featureFlags.mocAr=!1);const u=await ie(e,a);r=fe(u,a);const d=new this(u,t,r,i,o);return await Promise.allSettled(d.pluginsLoaded),d}catch(a){return c(a)}})}teardown(){this._container&&L.delete(this._container);const e=this._container.querySelector("iframe");e&&this._container.removeChild(e),window.removeEventListener("resize",this._onResize)}_createIframe(){var r;const e=document.createElement("iframe");let t=((r=this._configuratorSettings)==null?void 0:r.url)||"https://www.roomle.com/t/cp/";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(g.CONTAINER),e.classList.add(g.FILL),e}_onResize(){X(this._iframe)}_onUseFullPage(){this._iframe.classList.add(g.POSITION),document.documentElement.classList.add(g.OVERFLOW_HIDDEN),window.document.body.classList.add(g.OVERFLOW_HIDDEN),G()&&(X(this._iframe),this._iframe.classList.add(g.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(g.POSITION),this._iframe.classList.remove(g.ANDROID_HEIGHT),document.documentElement.classList.remove(g.OVERFLOW_HIDDEN),window.document.body.classList.remove(g.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:t},r){var i;if(r.source&&r.source===((i=this._iframe)==null?void 0:i.contentWindow))return e===E.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===E.SETUP?(this.handleSetup(t[0]),W(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),W(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(E.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:e,args:t})}}class Te{constructor(s=16){l(this,"_computedStyleCache",new Map);l(this,"_maxLifetime",16);l(this,"_cacheCleanInterval",null);this._maxLifetime=s}get(s){const e=this._computedStyleCache.get(s),t=Date.now();if(e&&t-e.updated<this._maxLifetime)return e.style;const r=getComputedStyle(s);return this._computedStyleCache.set(s,{style:r,updated:t}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),r}_cleanUpCache(){const s=Date.now();for(const[e,{updated:t}]of this._computedStyleCache.entries())s-t>=this._maxLifetime&&this._computedStyleCache.delete(e);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const q=n=>window.TouchEvent&&n instanceof window.TouchEvent;let C;const O=n=>(C||(C=new Te),C.get(n)),J=(n,s,e)=>{const t=parseFloat(n),r=window.devicePixelRatio||1;if(s==="px")return t;if(s==="%"){const o=e===document.documentElement?window.innerWidth:e.offsetWidth;return t/100*o}if(s==="rem"){const o=parseFloat(O(document.documentElement).fontSize);return t*o}if(s==="em"){const o=parseFloat(O(e).fontSize);return t*o}if(s==="vh"||s==="vw"||s==="vmin"||s==="vmax"){const o={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return t/100*o[s]}const i={cm:37.7952755906,mm:3.77952755906,in:96};return s in i?t*i[s]*r:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},Se=(n,s,e={x:0,y:0})=>{const t=n.getBoundingClientRect(),i=O(n).transform;let o=0,c=0;if(i!=="none"){const w=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,y=i.match(w);y&&(o=J(y[1],y[2],n),c=J(y[3],y[4],n))}const{clientX:a,clientY:u}=K(s,e),d=a-t.left-o+n.scrollLeft,f=u-t.top-c+n.scrollTop;return{x:d,y:f}},K=(n,s)=>{const{clientX:e,clientY:t}=q(n)?Ie(n):n,r=e>0?e:s.x,i=t>0?t:s.y;return{clientX:r,clientY:i}},Ie=n=>{if(n.touches.length){let{clientX:e,clientY:t}=n.touches[0];if(n.touches.length>1){const r=n.touches[1],i=r.clientX,o=r.clientY;e=(e+i)/2,t=(t+o)/2}return{clientX:e,clientY:t}}const s=n.changedTouches[0];return{clientX:s.clientX,clientY:s.clientY}},Oe=(n,s)=>{const e=s.x+s.width,t=s.x,r=s.y+s.height,i=s.y,{x:o,y:c}=n;return o>=t&&o<=e&&c>=i&&c<=r},j=500,Q=10;class be{constructor(s,{onTouchDragStart:e},t={}){l(this,"_touchDragTimeOut");l(this,"_onTouchDragStart");l(this,"_payload",null);l(this,"_delay",j);l(this,"_firstTouch",null);l(this,"_lastTouch",null);l(this,"_epsilon",Q);this._payload=s,this._onTouchDragStart=e,this._delay=t.delay||j,this._epsilon=t.epsilon||Q}onTouchStart(s){var e;!s||!((e=s==null?void 0:s.touches)!=null&&e.length)||this._touchDragTimeOut||(this._firstTouch=s.touches[s.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=s.touches[0]),this._checkXDistance(s)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(s){var e;!s||!((e=s==null?void 0:s.touches)!=null&&e.length)||(this._lastTouch=s.touches[0])}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(s){return()=>{if(!this._firstTouch||!this._lastTouch)return;let e=!1;e=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,e&&(this._onTouchDragStart(this._payload,s),this._resetTouches())}}}class Ae{constructor(s,e){l(this,"_mainDomElement");l(this,"_instance",null);l(this,"_mode","website");l(this,"_viewName","main");this._mainDomElement=s,this._mode=e}setInstance(s){this._instance=s}setViewName(s){this._viewName=s}}const Re=n=>new Promise(s=>setTimeout(s,n)),Z="rml-drag-in-styles",Ne="rml-drag-in-drag-element",b="rml-drag-in-overlay",A="rml-drag-in-spacer",R="rml-drag-in-drag-ghost",P="rml-drag-in-fade-in",ee="rml-drag-in-fade-out",H={DISPLAY_NONE:"rml-display-none"},te=.5,F="250ms",U="forwards",D=n=>n?!0:(console.warn("No instance set, cancel drag-in"),!1);class Me extends Ae{constructor(e,t){super(e,t);l(this,"_currentDrag",{});l(this,"_currentTouch",null);l(this,"_firefoxDragPosition",{x:0,y:0});l(this,"_readyForDragUpdates",!1);l(this,"_paddingTop",0);l(this,"options",{});l(this,"_firefoxFallback",e=>{if(!this._currentDrag.event)return;const t=e||window.event;this._firefoxDragPosition.x=t.pageX||0,this._firefoxDragPosition.y=t.pageY||0});this._initReadyForDragUpdates(),this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),this._initReadyForDragUpdates(),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!!!document.getElementById(Z)){const t=document.createElement("style");t.type="text/css",t.id=Z,t.innerHTML=`
9
9
  .${H.DISPLAY_NONE}{display:none}
10
- .${O}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
- .${b}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
10
+ .${b}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
+ .${R}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
12
12
  @keyframes ${P} {from{opacity: 0;}to {opacity: ${te};}}
13
13
  @keyframes ${ee} {from{opacity: ${te};}to {opacity: 0;}}
14
- `,document.head.appendChild(s)}}_initializeDragGhost(){const e=this._mode==="custom-view"?document.body:this._mainDomElement.parentNode;let s=e.querySelector("."+b);s||(s=document.createElement("div"),s.classList.add(b),s.innerText=" ",e.appendChild(s))}_initReadyForDragUpdates(){this._readyForDragUpdates=this._mode!=="custom-view"}setInstance(e){this._instance=e}setMode(e){this._mode=e,this._initReadyForDragUpdates()}async dragStart(e,s,r="rml_id"){const i=this._mainDomElement.parentNode,o=i.querySelector("."+b);if(s instanceof DragEvent&&s.dataTransfer&&s.dataTransfer.setDragImage&&s.dataTransfer.setDragImage(o,0,0),this._mode==="custom-view"&&A(this._instance)){const u=await this._instance.getBoundingClientRect("iframe"),g=this.options.domContainer;if(!g)throw new Error("No container set, can not expand custom view");g.style.position="absolute",g.style.top=`${u.top}px`,g.style.left=`${u.left}px`,g.style.width=`${u.width}px`;let h=document.body.querySelector(`.${C}`);h||(h=document.createElement("div"),h.classList.add(C),document.body.appendChild(h)),h=document.body.querySelector(`.${C}`),h&&(h.style.position="fixed",h.style.backgroundColor="blue",h.style.top="0px",h.style.left=`${u.left}px`,h.style.width=`${u.width}px`,h.style.height=`${u.height+u.top}px`,h.style.opacity="0",h.style.pointerEvents="none",h.style.zIndex="-1",this._currentDrag.spacer=h),await this._instance.expandCustomView(this._viewName),await Re(50)}const c=I(i);if(this._mode==="website"&&c.position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._mainDomElement.style.pointerEvents="none";let a=i.querySelector("."+O);a||(a=document.createElement("div"),a.classList.add(O),i.appendChild(a)),a.classList.remove(H.DISPLAY_NONE),s.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`),this._currentDrag.event=s,this._currentDrag.id=e,this._currentDrag.type=r,this._readyForDragUpdates=!0}dragUpdate(e){var re,ne;if(!this._readyForDragUpdates)return;const{clientX:s,clientY:r}=K(e,this._firefoxDragPosition),i=s<=0||r<=0;if(this._mode==="custom-view"&&i)return;const o=this._mainDomElement.parentNode,{x:c,y:a}=Se(o,e,this._firefoxDragPosition);if(c===0&&a===0)return;if(!this._currentDrag.element){const p=e.target.cloneNode();p.style.position="fixed",p.style.pointerEvents="none",p.style.opacity="0",p.style.animation=`${P} ${F} ${U}`,p.id=Me,p.style.zIndex="9999",document.body.appendChild(p),this._currentDrag.element=p;const y=e.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0}),this._currentDrag.offset.x=this._mode==="website"?s-y.left:y.width/2,this._currentDrag.offset.y=this._mode==="website"?r-y.top:y.height/2}const d=Math.max(1,c),u=Math.max(1,a),g=((re=this._currentDrag.offset)==null?void 0:re.x)||0,h=((ne=this._currentDrag.offset)==null?void 0:ne.y)||0,w=s-g,$=r-h;this._currentDrag.element.style.left=`${w}px`,this._currentDrag.element.style.top=`${$}px`;const D=(this.options.dragInOverlapX||0)+1,T=(this.options.dragInOverlapY||0)+1;let se=d>D&&u>T;if(this._mode==="custom-view"){const p=this._currentDrag.spacer;if(!p)throw new Error("No spacer set, can not fade in/out drag ghost");const y=p.getBoundingClientRect();se=!Oe({x:d,y:u},{x:y.left-D,y:y.top-T,width:y.width+D,height:y.height+T})}if(se?this._currentDrag.element.style.animation=`${ee} ${F} ${U}`:this._currentDrag.element.style.animation=`${P} ${F} ${U}`,!(d===1&&u===1)&&A(this._instance)){let p=d,y=u;if(q(e)){const R=this.options.fingerSize||0;p=Math.max(2,d+R),y=Math.max(2,u-R)}if(this._currentDrag.inserted==="done")this._instance.updateDrag(p,y);else if(this._currentDrag.inserted!=="inprogress"){if(this._currentDrag.inserted="inprogress",!this._currentDrag.id||!this._currentDrag.type)return;this._instance.dragInObject(this._currentDrag.id,p,y,this._currentDrag.type).then(()=>{this._currentDrag.inserted="done"},R=>{console.error(R),this._currentDrag.inserted="failed"})}}}async dragEnd(){if(this._initReadyForDragUpdates(),A(this._instance)&&this._mode==="custom-view"){await this._instance.collapseCustomView(this._viewName);const r=this.options.domContainer;if(!r)throw new Error("No container set, can not collapse custom view");r.style.position="",r.style.top="",r.style.left="",r.style.width="",r.style.height=""}this._mainDomElement.style.pointerEvents="all";const e=this._mainDomElement.parentNode;A(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag.spacer&&document.body.removeChild(this._currentDrag.spacer),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const s=e.querySelector("."+O);s&&s.classList.add(H.DISPLAY_NONE)}touchStart(e,s,r="rml_id"){var c,a;s.preventDefault();const i=(d,u)=>{this.dragStart(e,u,r)},o={};typeof((c=this.options)==null?void 0:c.touchDragDelay)=="number"&&(o.delay=this.options.touchDragDelay),(a=this.options)!=null&&a.touchDragEpsilon&&(o.epsilon=this.options.touchDragEpsilon),this._currentTouch=new be(void 0,{onTouchDragStart:i},o),this._currentTouch.onTouchStart(s)}touchMove(e){this._currentTouch&&this._currentTouch.onTouchMove(e),this._currentDrag.event&&this.dragUpdate(e)}touchEnd(){this._currentTouch&&this._currentTouch.onTouchEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}}const xe=Object.freeze(Object.defineProperty({__proto__:null,DragIn:Ne},Symbol.toStringTag,{value:"Module"}));return De});
14
+ `,document.head.appendChild(t)}}_initializeDragGhost(){const e=this._mode==="custom-view"?document.body:this._mainDomElement.parentNode;let t=e.querySelector("."+R);t||(t=document.createElement("div"),t.classList.add(R),t.innerText=" ",e.appendChild(t))}_initReadyForDragUpdates(){this._readyForDragUpdates=this._mode!=="custom-view"}setInstance(e){this._instance=e,this._initDom()}async _initDom(){if(this._mode==="custom-view"&&D(this._instance)){const e=await this._instance.getBoundingClientRect("iframe");this._paddingTop=e.top;const t=this.options.domContainer;if(!t)throw new Error("No container set, can not expand custom view");t.style.position="absolute",t.style.top="0",t.style.right="0",t.style.width=`${e.width}px`;let r=document.body.querySelector(`.${A}`);r||(r=document.createElement("div"),r.classList.add(A),document.body.appendChild(r)),r=document.body.querySelector(`.${A}`),r&&(r.style.position="fixed",r.style.backgroundColor="blue",r.style.top="0px",r.style.right="0px",r.style.width=`${e.width}px`,r.style.height=`${e.height+e.top}px`,r.style.opacity="0",r.style.pointerEvents="none",r.style.zIndex="-1")}}async dragStart(e,t,r="rml_id"){const i=this._mainDomElement.parentNode,o=i.querySelector("."+R);t instanceof DragEvent&&t.dataTransfer&&t.dataTransfer.setDragImage&&t.dataTransfer.setDragImage(o,0,0),this._mode==="custom-view"&&D(this._instance)&&(await this._instance.expandCustomView(this._viewName),this.options.domContainer&&(this.options.domContainer.style.paddingTop=`${this._paddingTop}px`),await Re(50));const c=O(i);if(this._mode==="website"&&c.position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._mainDomElement.style.pointerEvents="none";let a=i.querySelector("."+b);a||(a=document.createElement("div"),a.classList.add(b),i.appendChild(a)),a.classList.remove(H.DISPLAY_NONE),t.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`),this._currentDrag.event=t,this._currentDrag.id=e,this._currentDrag.type=r,this._readyForDragUpdates=!0}dragUpdate(e){var re,ne;if(!this._readyForDragUpdates)return;const{clientX:t,clientY:r}=K(e,this._firefoxDragPosition),i=t<=0||r<=0;if(this._mode==="custom-view"&&i)return;const o=this._mainDomElement.parentNode,{x:c,y:a}=Se(o,e,this._firefoxDragPosition);if(c===0&&a===0)return;if(!this._currentDrag.element){const m=e.target.cloneNode();m.style.position="fixed",m.style.pointerEvents="none",m.style.opacity="0",m.style.animation=`${P} ${F} ${U}`,m.id=Ne,m.style.zIndex="9999",document.body.appendChild(m),this._currentDrag.element=m;const p=e.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0}),this._currentDrag.offset.x=this._mode==="website"?t-p.left:p.width/2,this._currentDrag.offset.y=this._mode==="website"?r-p.top:p.height/2}const u=Math.max(1,c),d=Math.max(1,a),f=((re=this._currentDrag.offset)==null?void 0:re.x)||0,w=((ne=this._currentDrag.offset)==null?void 0:ne.y)||0,y=t-f,k=r-w;this._currentDrag.element.style.left=`${y}px`,this._currentDrag.element.style.top=`${k}px`;const T=(this.options.dragInOverlapX||0)+1,S=(this.options.dragInOverlapY||0)+1;let se=u>T&&d>S;if(this._mode==="custom-view"){const m=document.body.querySelector(`.${A}`);if(!m)throw new Error("No spacer set, can not fade in/out drag ghost");const p=m.getBoundingClientRect();se=!Oe({x:u,y:d},{x:p.left-T,y:p.top-S,width:p.width+T,height:p.height+S})}if(se?this._currentDrag.element.style.animation=`${ee} ${F} ${U}`:this._currentDrag.element.style.animation=`${P} ${F} ${U}`,!(u===1&&d===1)&&D(this._instance)){let m=u,p=d;if(q(e)){const N=this.options.fingerSize||0;m=Math.max(2,u+N),p=Math.max(2,d-N)}if(this._currentDrag.inserted==="done")this._instance.updateDrag(m,p);else if(this._currentDrag.inserted!=="inprogress"){if(this._currentDrag.inserted="inprogress",!this._currentDrag.id||!this._currentDrag.type)return;this._instance.dragInObject(this._currentDrag.id,m,p,this._currentDrag.type).then(()=>{this._currentDrag.inserted="done"},N=>{console.error(N),this._currentDrag.inserted="failed"})}}}async dragEnd(){if(this._initReadyForDragUpdates(),D(this._instance)&&this._mode==="custom-view"){await this._instance.collapseCustomView(this._viewName);const r=this.options.domContainer;if(!r)throw new Error("No container set, can not collapse custom view");r.style.paddingTop=""}this._mainDomElement.style.pointerEvents="all";const e=this._mainDomElement.parentNode;D(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const t=e.querySelector("."+b);t&&t.classList.add(H.DISPLAY_NONE)}touchStart(e,t,r="rml_id"){var c,a;t.preventDefault();const i=(u,d)=>{this.dragStart(e,d,r)},o={};typeof((c=this.options)==null?void 0:c.touchDragDelay)=="number"&&(o.delay=this.options.touchDragDelay),(a=this.options)!=null&&a.touchDragEpsilon&&(o.epsilon=this.options.touchDragEpsilon),this._currentTouch=new be(void 0,{onTouchDragStart:i},o),this._currentTouch.onTouchStart(t)}touchMove(e){this._currentTouch&&this._currentTouch.onTouchMove(e),this._currentDrag.event&&this.dragUpdate(e)}touchEnd(){this._currentTouch&&this._currentTouch.onTouchEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}}const xe=Object.freeze(Object.defineProperty({__proto__:null,DragIn:Me},Symbol.toStringTag,{value:"Module"}));return De});
@@ -1,14 +1,14 @@
1
- (function(f,y){typeof exports=="object"&&typeof module<"u"?module.exports=y():typeof define=="function"&&define.amd?define(y):(f=typeof globalThis<"u"?globalThis:f||self,f["roomle-embedding-lib"]=f["roomle-embedding-lib"]||{},f["roomle-embedding-lib"].umd=f["roomle-embedding-lib"].umd||{},f["roomle-embedding-lib"].umd.min=f["roomle-embedding-lib"].umd.min||{},f["roomle-embedding-lib"].umd.min.js=y())})(this,function(){"use strict";var f=Object.defineProperty,y=(i,e,t)=>e in i?f(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,c=(i,e,t)=>y(i,typeof e!="symbol"?e+"":e,t);class B{constructor(e,t,s,r){c(this,"_side"),c(this,"_incomingMessageBus"),c(this,"_outgoingMessageBus",null),c(this,"_execMessage",null),this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=s,this._execMessage=r,this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(e){this._outgoingMessageBus=e}setMessageExecution(e){this._execMessage=e}sendMessage(e,t=[]){return new Promise((s,r)=>{const o=new MessageChannel;o.port1.onmessage=n=>{if(!n||!n.data)return o.port1.close(),o.port2.close(),r(new Error(this._side+" received message but response can not be interpreted"));let l;try{l=JSON.parse(n.data)}catch(u){return o.port1.close(),o.port2.close(),this._prepareError(u),r(u)}l.error?r(l.error):l.result!==void 0?s(l.result):s(void 0),o.port1.close(),o.port2.close()};let a="";try{a=JSON.stringify({message:e,args:t})}catch{return r(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return r(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(a,"*",[o.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 s=JSON.parse(e.data);if(!this._execMessage)return t.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(s.args)||(s.args=[s.args]);const r=this._execMessage(s,e);if(r===void 0)return;r.then((o={})=>{let a,n;typeof o=="object"&&o!==null&&(a=o.error,n=o.result),a?t.postMessage(JSON.stringify({error:a})):n!==void 0?t.postMessage(JSON.stringify({result:n})):t.postMessage(JSON.stringify({result:o}))},o=>{t.postMessage(JSON.stringify({error:this._prepareError(o)}))})}catch(s){t.postMessage(JSON.stringify({error:this._prepareError(s)}))}}_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 I=".",S={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},w={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},ne=async(i,e)=>{if(typeof i!="string")throw new Error('Configurator ID is not a string type: "'+typeof i+'"');const t=e.customApiUrl?e.customApiUrl:"https://api.roomle.com/v2",s=e.overrideTenant||9,r=t+"/configurators/"+i,o="roomle_portal_v2",a="03-"+window.btoa(new Date().toISOString()+";anonymous;"+o),n=()=>{const g={apiKey:o,currentTenant:s,locale:"en",language:"en",device:1,token:a,platform:"web"};return new Headers(g)},l=new Request(r,{method:"GET",headers:n(),mode:"cors",cache:"default"}),u=await fetch(l),{configurator:h}=await u.json();return h},oe=()=>{try{return window.self!==window.top}catch{return!0}},ae=["127.0.0.1","localhost","0.0.0.0"],le=()=>{const i=oe();let e=window.location.href;if(i){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},ce=i=>!!(ae.includes(i)||i.endsWith("roomle.com")||i.endsWith("gitlab.io")||i.endsWith("gitlab.com")),W=["language","browserLanguage","userLanguage","systemLanguage"],he=(i=null)=>{const e=window.navigator;if(i)return i.substr(0,2);if(Array.isArray(e.languages)&&e.languages.length>0)return e.languages[0].substr(0,2);for(let t=0,s=W.length;t<s;t++){const r=e[W[t]];if(r)return r.substr(0,2)}return"en"},ue=(i,e)=>{const t=JSON.parse(JSON.stringify(i));return x(t,e)},x=(i,e)=>{for(const t in e)try{e[t].constructor===Object?i[t]=x(i[t],e[t]):i[t]=e[t]}catch{i[t]=e[t]}return i};var de={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const ge={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},me="(idle)",_e=i=>(O(i),i!=null&&i.customApiUrl&&(i.customApiUrl=decodeURIComponent(i.customApiUrl)),i.shareUrl&&(i.deeplink=i.shareUrl.replace(ye,we)),i),O=i=>{if(!i)return;const e=Object.keys(i);for(const t of e){const s=i[t];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&O(s),Array.isArray(s))for(const r of s)O(r);(s==="true"||s==="false")&&(i[t]=s==="true")}},pe=(i,e)=>{e.configuratorId=i.id;const t=i.settings||{};return!e.overrideTenant&&i.tenant&&(e.overrideTenant=i.tenant),ue(t,e)},fe=()=>{const i={...ge};i.locale||(i.locale=he()),i.id===me&&delete i.id;const e=le();return e&&ce(e)&&(i.configuratorId="demoConfigurator"),i.customApiUrl=de.VITE_RAPI_URL,i.emails=!1,i},ye="<CONF_ID>",we="#CONFIGURATIONID#",V=()=>/(android)/i.test(navigator.userAgent);class z{constructor(){c(this,"_messageHandler",null),c(this,"isSetupDone",!1),c(this,"viewName","main"),c(this,"plugins",{}),c(this,"pluginsLoaded",[]),c(this,"ui",{callbacks:null}),c(this,"extended",{callbacks:null}),c(this,"configurator",{callbacks:null}),c(this,"analytics",{callbacks:{}}),c(this,"global",{callbacks:{}})}setMessageHandler(e){this._messageHandler=e}handleSetup(e){const{methods:t,callbacks:s}=e;t.forEach(r=>{const o=r.split(I),a=o[0],n=o[1];this[a]||(this[a]={}),this[a][n]=function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(r,[...arguments])}.bind(this)}),s.forEach(r=>{const o=r.split(I),a=o[0],n=o[1],l=o[2];this[a]||(this[a]={}),this[a][n]||(this[a][n]={}),this[a][n][l]=()=>{}}),this.isSetupDone=!0}executeMessage({message:e,args:t}){const s=e.split(I),r=s[0],o=s[1],a=s.length===3?s[2]:null;if(a&&this[r][o][a]){const n=this[r][o][a](...t);return n instanceof Promise?n.then(l=>({result:l})):n!==void 0?Promise.resolve({result:n}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}setupPlugins(e,t,s="website"){for(const r of e)typeof r=="string"&&r==="dragIn"?this.pluginsLoaded.push(new Promise((o,a)=>{try{Promise.resolve().then(()=>Re).then(({DragIn:n})=>{const l=new n(t);l.setInstance(this.ui),l.setMode(s),l.setViewName(this.viewName),this.plugins.dragIn=l,o()})}catch(n){a(n)}})):r.name&&r.loader&&this.pluginsLoaded.push(new Promise((o,a)=>{try{r.loader().then(n=>{const l=new n(t);l.setInstance(this.ui),l.setMode(s),l.setViewName(this.viewName),this.plugins[r.name]=l,o()})}catch(n){a(n)}}))}}const j=()=>{let i,e;return{promise:new Promise((t,s)=>{i=t,e=s}),resolve:i,reject:e}},Y=(i,e,t)=>{let s=null;Object.defineProperty(i,e,{get(){return s||t},set(r){r!=null&&r.mute?s=r.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 }"),s=r)}})},X=()=>window.innerHeight*.01+"px",G=i=>{i&&setTimeout(()=>i.style.setProperty(M,X()),0)},J="rml-styles",De=450,M="--rml-full-height",d={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},N=new Map;class ve extends z{constructor(e,t,s,r,o){if(super(),c(this,"_waitForIframe"),c(this,"_container"),c(this,"_configuratorSettings"),c(this,"_initData",{}),c(this,"_iframe"),!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(N.has(t))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(J)){const l=s.zIndex||9999999,u=document.createElement("style");u.type="text/css",u.id=J;const h="transition:all ease-in-out "+De+"ms;",g=["-webkit-","-o-"].reduce((A,H)=>A+=H+h,"")+h,p=X();u.innerHTML=`
2
- .${d.CONTAINER}{${M}:${p};}
3
- .${d.POSITION}{position:fixed;top:0;left:0;z-index:${l};opacity:0}
4
- .${d.TRANSITION}{${g}}
5
- .${d.FILL}{width:100%;height:100%;opacity:1}
6
- .${d.ANDROID_HEIGHT}{height:calc(var(${M},1vh)*100)}
7
- .${d.OVERFLOW_HIDDEN}{overflow:hidden}
8
- `,document.head.appendChild(u)}this._executeMessage=this._executeMessage.bind(this);const a=new B("website",window,null,this._executeMessage);this.setMessageHandler(a),this._onResize=this._onResize.bind(this),V()&&window.addEventListener("resize",this._onResize),this._container=t,this._initData=s,this._configuratorSettings=e;const n=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=o,this._container.appendChild(n),this._iframe=n,this.setupPlugins(r,this._iframe),N.set(t,!0)}static createPlanner(e,t,s,r=[]){return this._create(e,t,s,r)}static async connect(e,t=[]){const s=new z;s.viewName=e;const{resolve:r,promise:o}=j(),{resolve:a,promise:n}=j(),l=({message:g,args:p})=>{if(g===w.REGISTER_CUSTOM_VIEW_DONE){r();return}if(g===w.RETURN_METHODS){s.handleSetup(p[0]),a();return}if(s.isSetupDone)return s.executeMessage({message:g,args:p})},u=new B("custom-view",window,window.parent,l);s.setMessageHandler(u);const h=[e];return u.sendMessage(w.REGISTER_CUSTOM_VIEW,h),await o,u.sendMessage(w.GET_METHODS,h),await n,s.setupPlugins(t,document.body,"custom-view"),await Promise.allSettled(s.pluginsLoaded),s}static createConfigurator(e,t,s,r=[]){return this._create(e,t,s,r)}static create(e,t,s,r){return this._create(e,t,s,r)}static createViewer(e,t,s,r=[]){return this._create(e,t,s,r)}static async _create(e,t,s,r){return new Promise(async(o,a)=>{try{const n=x(fe(),_e(s));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);const l=await ne(e,n);s=pe(l,n);const u=new this(l,t,s,r,o);return await Promise.allSettled(u.pluginsLoaded),u}catch(n){return a(n)}})}teardown(){this._container&&N.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 s=((e=this._configuratorSettings)==null?void 0:e.url)||"https://www.roomle.com/t/cp/";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),t.src=s,t.classList.add(d.CONTAINER),t.classList.add(d.FILL),t}_onResize(){G(this._iframe)}_onUseFullPage(){this._iframe.classList.add(d.POSITION),document.documentElement.classList.add(d.OVERFLOW_HIDDEN),window.document.body.classList.add(d.OVERFLOW_HIDDEN),V()&&(G(this._iframe),this._iframe.classList.add(d.ANDROID_HEIGHT))}_onBackToWebsite(){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)}_executeMessage({message:e,args:t},s){var r;if(s.source&&s.source===((r=this._iframe)==null?void 0:r.contentWindow))return e===S.REQUEST_BOOT?this._messageHandler?(this._messageHandler.setOutgoingMessageBus(s.source),Promise.resolve({result:this._initData})):(console.error("MessageHandler not set"),Promise.resolve({error:"MessageHandler not set"})):e===S.SETUP?(this.handleSetup(t[0]),Y(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),Y(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(S.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:e,args:t})}}class be{constructor(e=16){c(this,"_computedStyleCache",new Map),c(this,"_maxLifetime",16),c(this,"_cacheCleanInterval",null),this._maxLifetime=e}get(e){const t=this._computedStyleCache.get(e),s=Date.now();if(t&&s-t.updated<this._maxLifetime)return t.style;const r=getComputedStyle(e);return this._computedStyleCache.set(e,{style:r,updated:s}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),r}_cleanUpCache(){const e=Date.now();for(const[t,{updated:s}]of this._computedStyleCache.entries())e-s>=this._maxLifetime&&this._computedStyleCache.delete(t);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const q=i=>window.TouchEvent&&i instanceof window.TouchEvent;let R;const D=i=>(R||(R=new be),R.get(i)),Q=(i,e,t)=>{const s=parseFloat(i),r=window.devicePixelRatio||1;if(e==="px")return s;if(e==="%"){const a=t===document.documentElement?window.innerWidth:t.offsetWidth;return s/100*a}if(e==="rem"){const a=parseFloat(D(document.documentElement).fontSize);return s*a}if(e==="em"){const a=parseFloat(D(t).fontSize);return s*a}if(e==="vh"||e==="vw"||e==="vmin"||e==="vmax"){const a={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return s/100*a[e]}const o={cm:37.7952755906,mm:3.77952755906,in:96};return e in o?s*o[e]*r:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},Ee=(i,e,t={x:0,y:0})=>{const s=i.getBoundingClientRect(),r=D(i).transform;let o=0,a=0;if(r!=="none"){const g=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,p=r.match(g);p&&(o=Q(p[1],p[2],i),a=Q(p[3],p[4],i))}const{clientX:n,clientY:l}=K(e,t),u=n-s.left-o+i.scrollLeft,h=l-s.top-a+i.scrollTop;return{x:u,y:h}},K=(i,e)=>{const{clientX:t,clientY:s}=q(i)?Te(i):i,r=t>0?t:e.x,o=s>0?s:e.y;return{clientX:r,clientY:o}},Te=i=>{if(i.touches.length){let{clientX:t,clientY:s}=i.touches[0];if(i.touches.length>1){const r=i.touches[1],o=r.clientX,a=r.clientY;t=(t+o)/2,s=(s+a)/2}return{clientX:t,clientY:s}}const e=i.changedTouches[0];return{clientX:e.clientX,clientY:e.clientY}},Ie=(i,e)=>{const t=e.x+e.width,s=e.x,r=e.y+e.height,o=e.y,{x:a,y:n}=i;return a>=s&&a<=t&&n>=o&&n<=r},Z=500,ee=10;class Se{constructor(e,{onTouchDragStart:t},s={}){c(this,"_touchDragTimeOut"),c(this,"_onTouchDragStart"),c(this,"_payload",null),c(this,"_delay",Z),c(this,"_firstTouch",null),c(this,"_lastTouch",null),c(this,"_epsilon",ee),this._payload=e,this._onTouchDragStart=t,this._delay=s.delay||Z,this._epsilon=s.epsilon||ee}onTouchStart(e){var t;!e||!((t=e?.touches)!=null&&t.length)||this._touchDragTimeOut||(this._firstTouch=e.touches[e.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=e.touches[0]),this._checkXDistance(e)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(e){var t;!e||!((t=e?.touches)!=null&&t.length)||(this._lastTouch=e.touches[0])}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(e){return()=>{if(!this._firstTouch||!this._lastTouch)return;let t=!1;t=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,t&&(this._onTouchDragStart(this._payload,e),this._resetTouches())}}}class xe{constructor(){c(this,"_instance",null),c(this,"_mode","website"),c(this,"_viewName","main")}setInstance(e){this._instance=e}setMode(e){this._mode=e}setViewName(e){this._viewName=e}}const Oe=i=>new Promise(e=>setTimeout(e,i)),te="rml-drag-in-styles",Me="rml-drag-in-drag-element",v="rml-drag-in-overlay",L="rml-drag-in-spacer",b="rml-drag-in-drag-ghost",C="rml-drag-in-fade-in",se="rml-drag-in-fade-out",P={DISPLAY_NONE:"rml-display-none"},ie=.5,F="250ms",U="forwards",E=i=>i?!0:(console.warn("No instance set, cancel drag-in"),!1);class Ne extends xe{constructor(e){super(),c(this,"_mainDomElement"),c(this,"_currentDrag",{}),c(this,"_currentTouch",null),c(this,"_firefoxDragPosition",{x:0,y:0}),c(this,"_readyForDragUpdates",!1),c(this,"options",{}),c(this,"_firefoxFallback",t=>{if(!this._currentDrag.event)return;const s=t||window.event;this._firefoxDragPosition.x=s.pageX||0,this._firefoxDragPosition.y=s.pageY||0}),this._mainDomElement=e,this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),this._initReadyForDragUpdates(),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!document.getElementById(te)){const e=document.createElement("style");e.type="text/css",e.id=te,e.innerHTML=`
1
+ (function(f,y){typeof exports=="object"&&typeof module<"u"?module.exports=y():typeof define=="function"&&define.amd?define(y):(f=typeof globalThis<"u"?globalThis:f||self,f["roomle-embedding-lib"]=f["roomle-embedding-lib"]||{},f["roomle-embedding-lib"].umd=f["roomle-embedding-lib"].umd||{},f["roomle-embedding-lib"].umd.min=f["roomle-embedding-lib"].umd.min||{},f["roomle-embedding-lib"].umd.min.js=y())})(this,function(){"use strict";var f=Object.defineProperty,y=(i,e,t)=>e in i?f(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,c=(i,e,t)=>y(i,typeof e!="symbol"?e+"":e,t);class B{constructor(e,t,s,r){c(this,"_side"),c(this,"_incomingMessageBus"),c(this,"_outgoingMessageBus",null),c(this,"_execMessage",null),this._side=e,this._incomingMessageBus=t,this._outgoingMessageBus=s,this._execMessage=r,this._incomingMessageBus.addEventListener("message",this._handleMessage.bind(this))}setOutgoingMessageBus(e){this._outgoingMessageBus=e}setMessageExecution(e){this._execMessage=e}sendMessage(e,t=[]){return new Promise((s,r)=>{const o=new MessageChannel;o.port1.onmessage=n=>{if(!n||!n.data)return o.port1.close(),o.port2.close(),r(new Error(this._side+" received message but response can not be interpreted"));let l;try{l=JSON.parse(n.data)}catch(h){return o.port1.close(),o.port2.close(),this._prepareError(h),r(h)}l.error?r(l.error):l.result!==void 0?s(l.result):s(void 0),o.port1.close(),o.port2.close()};let a="";try{a=JSON.stringify({message:e,args:t})}catch{return r(new Error(this._side+": can not create command because it is not JSON.stringify able"))}if(!this._outgoingMessageBus)return r(new Error(this._side+": outgoing bus not set yet"));this._outgoingMessageBus.postMessage(a,"*",[o.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 s=JSON.parse(e.data);if(!this._execMessage)return t.postMessage(JSON.stringify({error:this._side+" is not ready to handle messages"}));Array.isArray(s.args)||(s.args=[s.args]);const r=this._execMessage(s,e);if(r===void 0)return;r.then((o={})=>{let a,n;typeof o=="object"&&o!==null&&(a=o.error,n=o.result),a?t.postMessage(JSON.stringify({error:a})):n!==void 0?t.postMessage(JSON.stringify({result:n})):t.postMessage(JSON.stringify({result:o}))},o=>{t.postMessage(JSON.stringify({error:this._prepareError(o)}))})}catch(s){t.postMessage(JSON.stringify({error:this._prepareError(s)}))}}_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 I=".",x={REQUEST_BOOT:"requestBoot",SETUP:"setup",WEBSITE_READY:"websiteReady"},D={GET_METHODS:"getMethods",RETURN_METHODS:"returnMethods",REGISTER_CUSTOM_VIEW:"registerCustomView",REGISTER_CUSTOM_VIEW_DONE:"registerCustomViewDone"},ne=async(i,e)=>{if(typeof i!="string")throw new Error('Configurator ID is not a string type: "'+typeof i+'"');const t=e.customApiUrl?e.customApiUrl:"https://api.roomle.com/v2",s=e.overrideTenant||9,r=t+"/configurators/"+i,o="roomle_portal_v2",a="03-"+window.btoa(new Date().toISOString()+";anonymous;"+o),n=()=>{const g={apiKey:o,currentTenant:s,locale:"en",language:"en",device:1,token:a,platform:"web"};return new Headers(g)},l=new Request(r,{method:"GET",headers:n(),mode:"cors",cache:"default"}),h=await fetch(l),{configurator:d}=await h.json();return d},oe=()=>{try{return window.self!==window.top}catch{return!0}},ae=["127.0.0.1","localhost","0.0.0.0"],ce=()=>{const i=oe();let e=window.location.href;if(i){if(!document.referrer)return null;e=document.referrer}const{hostname:t}=new URL(e);return t},le=i=>!!(ae.includes(i)||i.endsWith("roomle.com")||i.endsWith("gitlab.io")||i.endsWith("gitlab.com")),W=["language","browserLanguage","userLanguage","systemLanguage"],he=(i=null)=>{const e=window.navigator;if(i)return i.substr(0,2);if(Array.isArray(e.languages)&&e.languages.length>0)return e.languages[0].substr(0,2);for(let t=0,s=W.length;t<s;t++){const r=e[W[t]];if(r)return r.substr(0,2)}return"en"},ue=(i,e)=>{const t=JSON.parse(JSON.stringify(i));return O(t,e)},O=(i,e)=>{for(const t in e)try{e[t].constructor===Object?i[t]=O(i[t],e[t]):i[t]=e[t]}catch{i[t]=e[t]}return i};var de={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1};const ge={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},me="(idle)",_e=i=>(M(i),i!=null&&i.customApiUrl&&(i.customApiUrl=decodeURIComponent(i.customApiUrl)),i.shareUrl&&(i.deeplink=i.shareUrl.replace(ye,we)),i),M=i=>{if(!i)return;const e=Object.keys(i);for(const t of e){const s=i[t];if(!Array.isArray(s)&&typeof s=="object"&&s!==null&&M(s),Array.isArray(s))for(const r of s)M(r);(s==="true"||s==="false")&&(i[t]=s==="true")}},pe=(i,e)=>{e.configuratorId=i.id;const t=i.settings||{};return!e.overrideTenant&&i.tenant&&(e.overrideTenant=i.tenant),ue(t,e)},fe=()=>{const i={...ge};i.locale||(i.locale=he()),i.id===me&&delete i.id;const e=ce();return e&&le(e)&&(i.configuratorId="demoConfigurator"),i.customApiUrl=de.VITE_RAPI_URL,i.emails=!1,i},ye="<CONF_ID>",we="#CONFIGURATIONID#",V=()=>/(android)/i.test(navigator.userAgent);class z{constructor(){c(this,"_messageHandler",null),c(this,"isSetupDone",!1),c(this,"viewName","main"),c(this,"plugins",{}),c(this,"pluginsLoaded",[]),c(this,"ui",{callbacks:null}),c(this,"extended",{callbacks:null}),c(this,"configurator",{callbacks:null}),c(this,"analytics",{callbacks:{}}),c(this,"global",{callbacks:{}})}setMessageHandler(e){this._messageHandler=e}handleSetup(e){const{methods:t,callbacks:s}=e;t.forEach(r=>{const o=r.split(I),a=o[0],n=o[1];this[a]||(this[a]={}),this[a][n]=function(){if(!this._messageHandler){console.error("MessageHandler not set");return}return this._messageHandler.sendMessage(r,[...arguments])}.bind(this)}),s.forEach(r=>{const o=r.split(I),a=o[0],n=o[1],l=o[2];this[a]||(this[a]={}),this[a][n]||(this[a][n]={}),this[a][n][l]=()=>{}}),this.isSetupDone=!0}executeMessage({message:e,args:t}){const s=e.split(I),r=s[0],o=s[1],a=s.length===3?s[2]:null;if(a&&this[r][o][a]){const n=this[r][o][a](...t);return n instanceof Promise?n.then(l=>({result:l})):n!==void 0?Promise.resolve({result:n}):Promise.resolve({result:null})}return Promise.reject('Message "'+e+'" is unkown')}setupPlugins(e,t,s="website"){for(const r of e)typeof r=="string"&&r==="dragIn"?this.pluginsLoaded.push(new Promise((o,a)=>{try{Promise.resolve().then(()=>Re).then(({DragIn:n})=>{const l=new n(t,s);l.setInstance(this.ui),l.setViewName(this.viewName),this.plugins.dragIn=l,o()})}catch(n){a(n)}})):r.name&&r.loader&&this.pluginsLoaded.push(new Promise((o,a)=>{try{r.loader().then(n=>{const l=new n(t,s);l.setInstance(this.ui),l.setViewName(this.viewName),this.plugins[r.name]=l,o()})}catch(n){a(n)}}))}}const j=()=>{let i,e;return{promise:new Promise((t,s)=>{i=t,e=s}),resolve:i,reject:e}},Y=(i,e,t)=>{let s=null;Object.defineProperty(i,e,{get(){return s||t},set(r){r!=null&&r.mute?s=r.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 }"),s=r)}})},X=()=>window.innerHeight*.01+"px",G=i=>{i&&setTimeout(()=>i.style.setProperty(N,X()),0)},q="rml-styles",De=450,N="--rml-full-height",u={CONTAINER:"rml-container",FILL:"rml-fill",POSITION:"rml-pos",TRANSITION:"rml-transition",ANDROID_HEIGHT:"rml-android-height",OVERFLOW_HIDDEN:"rml-overflow-hidden"},R=new Map;class ve extends z{constructor(e,t,s,r,o){if(super(),c(this,"_waitForIframe"),c(this,"_container"),c(this,"_configuratorSettings"),c(this,"_initData",{}),c(this,"_iframe"),!e||typeof e.id!="string")throw new Error("Please provide a correct configuratorId, you get the correct ID from your Roomle Contact Person");if(R.has(t))throw new Error("There is already an instance on this DOM element");if(!document.getElementById(q)){const l=s.zIndex||9999999,h=document.createElement("style");h.type="text/css",h.id=q;const d="transition:all ease-in-out "+De+"ms;",g=["-webkit-","-o-"].reduce((A,H)=>A+=H+d,"")+d,p=X();h.innerHTML=`
2
+ .${u.CONTAINER}{${N}:${p};}
3
+ .${u.POSITION}{position:fixed;top:0;left:0;z-index:${l};opacity:0}
4
+ .${u.TRANSITION}{${g}}
5
+ .${u.FILL}{width:100%;height:100%;opacity:1}
6
+ .${u.ANDROID_HEIGHT}{height:calc(var(${N},1vh)*100)}
7
+ .${u.OVERFLOW_HIDDEN}{overflow:hidden}
8
+ `,document.head.appendChild(h)}this._executeMessage=this._executeMessage.bind(this);const a=new B("website",window,null,this._executeMessage);this.setMessageHandler(a),this._onResize=this._onResize.bind(this),V()&&window.addEventListener("resize",this._onResize),this._container=t,this._initData=s,this._configuratorSettings=e;const n=this._createIframe();this._onUseFullPage=this._onUseFullPage.bind(this),this._onBackToWebsite=this._onBackToWebsite.bind(this),this._waitForIframe=o,this._container.appendChild(n),this._iframe=n,this.setupPlugins(r,this._iframe),R.set(t,!0)}static createPlanner(e,t,s,r=[]){return this._create(e,t,s,r)}static async connect(e,t=[]){const s=new z;s.viewName=e;const{resolve:r,promise:o}=j(),{resolve:a,promise:n}=j(),l=({message:g,args:p})=>{if(g===D.REGISTER_CUSTOM_VIEW_DONE){r();return}if(g===D.RETURN_METHODS){s.handleSetup(p[0]),a();return}if(s.isSetupDone)return s.executeMessage({message:g,args:p})},h=new B("custom-view",window,window.parent,l);s.setMessageHandler(h);const d=[e];return h.sendMessage(D.REGISTER_CUSTOM_VIEW,d),await o,h.sendMessage(D.GET_METHODS,d),await n,s.setupPlugins(t,document.body,"custom-view"),await Promise.allSettled(s.pluginsLoaded),s}static createConfigurator(e,t,s,r=[]){return this._create(e,t,s,r)}static create(e,t,s,r){return this._create(e,t,s,r)}static createViewer(e,t,s,r=[]){return this._create(e,t,s,r)}static async _create(e,t,s,r){return new Promise(async(o,a)=>{try{const n=O(fe(),_e(s));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);const l=await ne(e,n);s=pe(l,n);const h=new this(l,t,s,r,o);return await Promise.allSettled(h.pluginsLoaded),h}catch(n){return a(n)}})}teardown(){this._container&&R.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 s=((e=this._configuratorSettings)==null?void 0:e.url)||"https://www.roomle.com/t/cp/";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),t.src=s,t.classList.add(u.CONTAINER),t.classList.add(u.FILL),t}_onResize(){G(this._iframe)}_onUseFullPage(){this._iframe.classList.add(u.POSITION),document.documentElement.classList.add(u.OVERFLOW_HIDDEN),window.document.body.classList.add(u.OVERFLOW_HIDDEN),V()&&(G(this._iframe),this._iframe.classList.add(u.ANDROID_HEIGHT))}_onBackToWebsite(){this._iframe.classList.remove(u.POSITION),this._iframe.classList.remove(u.ANDROID_HEIGHT),document.documentElement.classList.remove(u.OVERFLOW_HIDDEN),window.document.body.classList.remove(u.OVERFLOW_HIDDEN)}_executeMessage({message:e,args:t},s){var r;if(s.source&&s.source===((r=this._iframe)==null?void 0:r.contentWindow))return e===x.REQUEST_BOOT?this._messageHandler?(this._messageHandler.setOutgoingMessageBus(s.source),Promise.resolve({result:this._initData})):(console.error("MessageHandler not set"),Promise.resolve({error:"MessageHandler not set"})):e===x.SETUP?(this.handleSetup(t[0]),Y(this.ui.callbacks,"onUseFullPage",this._onUseFullPage),Y(this.ui.callbacks,"onBackToWebsite",this._onBackToWebsite),this._waitForIframe(this),setTimeout(()=>{if(!this._messageHandler){console.error("MessageHandler not set");return}this._messageHandler.sendMessage(x.WEBSITE_READY)},0),Promise.resolve({result:null})):this.executeMessage({message:e,args:t})}}class Te{constructor(e=16){c(this,"_computedStyleCache",new Map),c(this,"_maxLifetime",16),c(this,"_cacheCleanInterval",null),this._maxLifetime=e}get(e){const t=this._computedStyleCache.get(e),s=Date.now();if(t&&s-t.updated<this._maxLifetime)return t.style;const r=getComputedStyle(e);return this._computedStyleCache.set(e,{style:r,updated:s}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),r}_cleanUpCache(){const e=Date.now();for(const[t,{updated:s}]of this._computedStyleCache.entries())e-s>=this._maxLifetime&&this._computedStyleCache.delete(t);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const J=i=>window.TouchEvent&&i instanceof window.TouchEvent;let L;const v=i=>(L||(L=new Te),L.get(i)),Q=(i,e,t)=>{const s=parseFloat(i),r=window.devicePixelRatio||1;if(e==="px")return s;if(e==="%"){const a=t===document.documentElement?window.innerWidth:t.offsetWidth;return s/100*a}if(e==="rem"){const a=parseFloat(v(document.documentElement).fontSize);return s*a}if(e==="em"){const a=parseFloat(v(t).fontSize);return s*a}if(e==="vh"||e==="vw"||e==="vmin"||e==="vmax"){const a={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return s/100*a[e]}const o={cm:37.7952755906,mm:3.77952755906,in:96};return e in o?s*o[e]*r:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},be=(i,e,t={x:0,y:0})=>{const s=i.getBoundingClientRect(),r=v(i).transform;let o=0,a=0;if(r!=="none"){const g=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,p=r.match(g);p&&(o=Q(p[1],p[2],i),a=Q(p[3],p[4],i))}const{clientX:n,clientY:l}=K(e,t),h=n-s.left-o+i.scrollLeft,d=l-s.top-a+i.scrollTop;return{x:h,y:d}},K=(i,e)=>{const{clientX:t,clientY:s}=J(i)?Ee(i):i,r=t>0?t:e.x,o=s>0?s:e.y;return{clientX:r,clientY:o}},Ee=i=>{if(i.touches.length){let{clientX:t,clientY:s}=i.touches[0];if(i.touches.length>1){const r=i.touches[1],o=r.clientX,a=r.clientY;t=(t+o)/2,s=(s+a)/2}return{clientX:t,clientY:s}}const e=i.changedTouches[0];return{clientX:e.clientX,clientY:e.clientY}},Se=(i,e)=>{const t=e.x+e.width,s=e.x,r=e.y+e.height,o=e.y,{x:a,y:n}=i;return a>=s&&a<=t&&n>=o&&n<=r},Z=500,ee=10;class Ie{constructor(e,{onTouchDragStart:t},s={}){c(this,"_touchDragTimeOut"),c(this,"_onTouchDragStart"),c(this,"_payload",null),c(this,"_delay",Z),c(this,"_firstTouch",null),c(this,"_lastTouch",null),c(this,"_epsilon",ee),this._payload=e,this._onTouchDragStart=t,this._delay=s.delay||Z,this._epsilon=s.epsilon||ee}onTouchStart(e){var t;!e||!((t=e?.touches)!=null&&t.length)||this._touchDragTimeOut||(this._firstTouch=e.touches[e.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=e.touches[0]),this._checkXDistance(e)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(e){var t;!e||!((t=e?.touches)!=null&&t.length)||(this._lastTouch=e.touches[0])}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(e){return()=>{if(!this._firstTouch||!this._lastTouch)return;let t=!1;t=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,t&&(this._onTouchDragStart(this._payload,e),this._resetTouches())}}}class xe{constructor(e,t){c(this,"_mainDomElement"),c(this,"_instance",null),c(this,"_mode","website"),c(this,"_viewName","main"),this._mainDomElement=e,this._mode=t}setInstance(e){this._instance=e}setViewName(e){this._viewName=e}}const Oe=i=>new Promise(e=>setTimeout(e,i)),te="rml-drag-in-styles",Me="rml-drag-in-drag-element",T="rml-drag-in-overlay",b="rml-drag-in-spacer",E="rml-drag-in-drag-ghost",C="rml-drag-in-fade-in",se="rml-drag-in-fade-out",P={DISPLAY_NONE:"rml-display-none"},ie=.5,F="250ms",U="forwards",w=i=>i?!0:(console.warn("No instance set, cancel drag-in"),!1);class Ne extends xe{constructor(e,t){super(e,t),c(this,"_currentDrag",{}),c(this,"_currentTouch",null),c(this,"_firefoxDragPosition",{x:0,y:0}),c(this,"_readyForDragUpdates",!1),c(this,"_paddingTop",0),c(this,"options",{}),c(this,"_firefoxFallback",s=>{if(!this._currentDrag.event)return;const r=s||window.event;this._firefoxDragPosition.x=r.pageX||0,this._firefoxDragPosition.y=r.pageY||0}),this._initReadyForDragUpdates(),this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),this._initReadyForDragUpdates(),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!document.getElementById(te)){const e=document.createElement("style");e.type="text/css",e.id=te,e.innerHTML=`
9
9
  .${P.DISPLAY_NONE}{display:none}
10
- .${v}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
- .${b}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
10
+ .${T}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
11
+ .${E}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
12
12
  @keyframes ${C} {from{opacity: 0;}to {opacity: ${ie};}}
13
13
  @keyframes ${se} {from{opacity: ${ie};}to {opacity: 0;}}
14
- `,document.head.appendChild(e)}}_initializeDragGhost(){const e=this._mode==="custom-view"?document.body:this._mainDomElement.parentNode;let t=e.querySelector("."+b);t||(t=document.createElement("div"),t.classList.add(b),t.innerText=" ",e.appendChild(t))}_initReadyForDragUpdates(){this._readyForDragUpdates=this._mode!=="custom-view"}setInstance(e){this._instance=e}setMode(e){this._mode=e,this._initReadyForDragUpdates()}async dragStart(e,t,s="rml_id"){const r=this._mainDomElement.parentNode,o=r.querySelector("."+b);if(t instanceof DragEvent&&t.dataTransfer&&t.dataTransfer.setDragImage&&t.dataTransfer.setDragImage(o,0,0),this._mode==="custom-view"&&E(this._instance)){const l=await this._instance.getBoundingClientRect("iframe"),u=this.options.domContainer;if(!u)throw new Error("No container set, can not expand custom view");u.style.position="absolute",u.style.top=`${l.top}px`,u.style.left=`${l.left}px`,u.style.width=`${l.width}px`;let h=document.body.querySelector(`.${L}`);h||(h=document.createElement("div"),h.classList.add(L),document.body.appendChild(h)),h=document.body.querySelector(`.${L}`),h&&(h.style.position="fixed",h.style.backgroundColor="blue",h.style.top="0px",h.style.left=`${l.left}px`,h.style.width=`${l.width}px`,h.style.height=`${l.height+l.top}px`,h.style.opacity="0",h.style.pointerEvents="none",h.style.zIndex="-1",this._currentDrag.spacer=h),await this._instance.expandCustomView(this._viewName),await Oe(50)}const a=D(r);if(this._mode==="website"&&a.position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._mainDomElement.style.pointerEvents="none";let n=r.querySelector("."+v);n||(n=document.createElement("div"),n.classList.add(v),r.appendChild(n)),n.classList.remove(P.DISPLAY_NONE),t.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`),this._currentDrag.event=t,this._currentDrag.id=e,this._currentDrag.type=s,this._readyForDragUpdates=!0}dragUpdate(e){var t,s;if(!this._readyForDragUpdates)return;const{clientX:r,clientY:o}=K(e,this._firefoxDragPosition),a=r<=0||o<=0;if(this._mode==="custom-view"&&a)return;const n=this._mainDomElement.parentNode,{x:l,y:u}=Ee(n,e,this._firefoxDragPosition);if(l===0&&u===0)return;if(!this._currentDrag.element){const m=e.target.cloneNode();m.style.position="fixed",m.style.pointerEvents="none",m.style.opacity="0",m.style.animation=`${C} ${F} ${U}`,m.id=Me,m.style.zIndex="9999",document.body.appendChild(m),this._currentDrag.element=m;const _=e.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0}),this._currentDrag.offset.x=this._mode==="website"?r-_.left:_.width/2,this._currentDrag.offset.y=this._mode==="website"?o-_.top:_.height/2}const h=Math.max(1,l),g=Math.max(1,u),p=((t=this._currentDrag.offset)==null?void 0:t.x)||0,A=((s=this._currentDrag.offset)==null?void 0:s.y)||0,H=r-p,Le=o-A;this._currentDrag.element.style.left=`${H}px`,this._currentDrag.element.style.top=`${Le}px`;const $=(this.options.dragInOverlapX||0)+1,k=(this.options.dragInOverlapY||0)+1;let re=h>$&&g>k;if(this._mode==="custom-view"){const m=this._currentDrag.spacer;if(!m)throw new Error("No spacer set, can not fade in/out drag ghost");const _=m.getBoundingClientRect();re=!Ie({x:h,y:g},{x:_.left-$,y:_.top-k,width:_.width+$,height:_.height+k})}if(re?this._currentDrag.element.style.animation=`${se} ${F} ${U}`:this._currentDrag.element.style.animation=`${C} ${F} ${U}`,!(h===1&&g===1)&&E(this._instance)){let m=h,_=g;if(q(e)){const T=this.options.fingerSize||0;m=Math.max(2,h+T),_=Math.max(2,g-T)}if(this._currentDrag.inserted==="done")this._instance.updateDrag(m,_);else if(this._currentDrag.inserted!=="inprogress"){if(this._currentDrag.inserted="inprogress",!this._currentDrag.id||!this._currentDrag.type)return;this._instance.dragInObject(this._currentDrag.id,m,_,this._currentDrag.type).then(()=>{this._currentDrag.inserted="done"},T=>{console.error(T),this._currentDrag.inserted="failed"})}}}async dragEnd(){if(this._initReadyForDragUpdates(),E(this._instance)&&this._mode==="custom-view"){await this._instance.collapseCustomView(this._viewName);const s=this.options.domContainer;if(!s)throw new Error("No container set, can not collapse custom view");s.style.position="",s.style.top="",s.style.left="",s.style.width="",s.style.height=""}this._mainDomElement.style.pointerEvents="all";const e=this._mainDomElement.parentNode;E(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag.spacer&&document.body.removeChild(this._currentDrag.spacer),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const t=e.querySelector("."+v);t&&t.classList.add(P.DISPLAY_NONE)}touchStart(e,t,s="rml_id"){var r,o;t.preventDefault();const a=(l,u)=>{this.dragStart(e,u,s)},n={};typeof((r=this.options)==null?void 0:r.touchDragDelay)=="number"&&(n.delay=this.options.touchDragDelay),(o=this.options)!=null&&o.touchDragEpsilon&&(n.epsilon=this.options.touchDragEpsilon),this._currentTouch=new Se(void 0,{onTouchDragStart:a},n),this._currentTouch.onTouchStart(t)}touchMove(e){this._currentTouch&&this._currentTouch.onTouchMove(e),this._currentDrag.event&&this.dragUpdate(e)}touchEnd(){this._currentTouch&&this._currentTouch.onTouchEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}}const Re=Object.freeze(Object.defineProperty({__proto__:null,DragIn:Ne},Symbol.toStringTag,{value:"Module"}));return ve});
14
+ `,document.head.appendChild(e)}}_initializeDragGhost(){const e=this._mode==="custom-view"?document.body:this._mainDomElement.parentNode;let t=e.querySelector("."+E);t||(t=document.createElement("div"),t.classList.add(E),t.innerText=" ",e.appendChild(t))}_initReadyForDragUpdates(){this._readyForDragUpdates=this._mode!=="custom-view"}setInstance(e){this._instance=e,this._initDom()}async _initDom(){if(this._mode==="custom-view"&&w(this._instance)){const e=await this._instance.getBoundingClientRect("iframe");this._paddingTop=e.top;const t=this.options.domContainer;if(!t)throw new Error("No container set, can not expand custom view");t.style.position="absolute",t.style.top="0",t.style.right="0",t.style.width=`${e.width}px`;let s=document.body.querySelector(`.${b}`);s||(s=document.createElement("div"),s.classList.add(b),document.body.appendChild(s)),s=document.body.querySelector(`.${b}`),s&&(s.style.position="fixed",s.style.backgroundColor="blue",s.style.top="0px",s.style.right="0px",s.style.width=`${e.width}px`,s.style.height=`${e.height+e.top}px`,s.style.opacity="0",s.style.pointerEvents="none",s.style.zIndex="-1")}}async dragStart(e,t,s="rml_id"){const r=this._mainDomElement.parentNode,o=r.querySelector("."+E);t instanceof DragEvent&&t.dataTransfer&&t.dataTransfer.setDragImage&&t.dataTransfer.setDragImage(o,0,0),this._mode==="custom-view"&&w(this._instance)&&(await this._instance.expandCustomView(this._viewName),this.options.domContainer&&(this.options.domContainer.style.paddingTop=`${this._paddingTop}px`),await Oe(50));const a=v(r);if(this._mode==="website"&&a.position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._mainDomElement.style.pointerEvents="none";let n=r.querySelector("."+T);n||(n=document.createElement("div"),n.classList.add(T),r.appendChild(n)),n.classList.remove(P.DISPLAY_NONE),t.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`),this._currentDrag.event=t,this._currentDrag.id=e,this._currentDrag.type=s,this._readyForDragUpdates=!0}dragUpdate(e){var t,s;if(!this._readyForDragUpdates)return;const{clientX:r,clientY:o}=K(e,this._firefoxDragPosition),a=r<=0||o<=0;if(this._mode==="custom-view"&&a)return;const n=this._mainDomElement.parentNode,{x:l,y:h}=be(n,e,this._firefoxDragPosition);if(l===0&&h===0)return;if(!this._currentDrag.element){const m=e.target.cloneNode();m.style.position="fixed",m.style.pointerEvents="none",m.style.opacity="0",m.style.animation=`${C} ${F} ${U}`,m.id=Me,m.style.zIndex="9999",document.body.appendChild(m),this._currentDrag.element=m;const _=e.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0}),this._currentDrag.offset.x=this._mode==="website"?r-_.left:_.width/2,this._currentDrag.offset.y=this._mode==="website"?o-_.top:_.height/2}const d=Math.max(1,l),g=Math.max(1,h),p=((t=this._currentDrag.offset)==null?void 0:t.x)||0,A=((s=this._currentDrag.offset)==null?void 0:s.y)||0,H=r-p,Le=o-A;this._currentDrag.element.style.left=`${H}px`,this._currentDrag.element.style.top=`${Le}px`;const $=(this.options.dragInOverlapX||0)+1,k=(this.options.dragInOverlapY||0)+1;let re=d>$&&g>k;if(this._mode==="custom-view"){const m=document.body.querySelector(`.${b}`);if(!m)throw new Error("No spacer set, can not fade in/out drag ghost");const _=m.getBoundingClientRect();re=!Se({x:d,y:g},{x:_.left-$,y:_.top-k,width:_.width+$,height:_.height+k})}if(re?this._currentDrag.element.style.animation=`${se} ${F} ${U}`:this._currentDrag.element.style.animation=`${C} ${F} ${U}`,!(d===1&&g===1)&&w(this._instance)){let m=d,_=g;if(J(e)){const S=this.options.fingerSize||0;m=Math.max(2,d+S),_=Math.max(2,g-S)}if(this._currentDrag.inserted==="done")this._instance.updateDrag(m,_);else if(this._currentDrag.inserted!=="inprogress"){if(this._currentDrag.inserted="inprogress",!this._currentDrag.id||!this._currentDrag.type)return;this._instance.dragInObject(this._currentDrag.id,m,_,this._currentDrag.type).then(()=>{this._currentDrag.inserted="done"},S=>{console.error(S),this._currentDrag.inserted="failed"})}}}async dragEnd(){if(this._initReadyForDragUpdates(),w(this._instance)&&this._mode==="custom-view"){await this._instance.collapseCustomView(this._viewName);const s=this.options.domContainer;if(!s)throw new Error("No container set, can not collapse custom view");s.style.paddingTop=""}this._mainDomElement.style.pointerEvents="all";const e=this._mainDomElement.parentNode;w(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const t=e.querySelector("."+T);t&&t.classList.add(P.DISPLAY_NONE)}touchStart(e,t,s="rml_id"){var r,o;t.preventDefault();const a=(l,h)=>{this.dragStart(e,h,s)},n={};typeof((r=this.options)==null?void 0:r.touchDragDelay)=="number"&&(n.delay=this.options.touchDragDelay),(o=this.options)!=null&&o.touchDragEpsilon&&(n.epsilon=this.options.touchDragEpsilon),this._currentTouch=new Ie(void 0,{onTouchDragStart:a},n),this._currentTouch.onTouchStart(t)}touchMove(e){this._currentTouch&&this._currentTouch.onTouchMove(e),this._currentDrag.event&&this.dragUpdate(e)}touchEnd(){this._currentTouch&&this._currentTouch.onTouchEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}}const Re=Object.freeze(Object.defineProperty({__proto__:null,DragIn:Ne},Symbol.toStringTag,{value:"Module"}));return ve});
@@ -1,7 +0,0 @@
1
- var R=Object.defineProperty,q=(n,t,e)=>t in n?R(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t,e)=>q(n,typeof t!="symbol"?t+"":t,e);class j{constructor(t=16){c(this,"_computedStyleCache",new Map),c(this,"_maxLifetime",16),c(this,"_cacheCleanInterval",null),this._maxLifetime=t}get(t){const e=this._computedStyleCache.get(t),i=Date.now();if(e&&i-e.updated<this._maxLifetime)return e.style;const s=getComputedStyle(t);return this._computedStyleCache.set(t,{style:s,updated:i}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),s}_cleanUpCache(){const t=Date.now();for(const[e,{updated:i}]of this._computedStyleCache.entries())t-i>=this._maxLifetime&&this._computedStyleCache.delete(e);this._computedStyleCache.size===0&&this._cacheCleanInterval&&(clearInterval(this._cacheCleanInterval),this._cacheCleanInterval=null)}}const N=n=>window.TouchEvent&&n instanceof window.TouchEvent;let T;const f=n=>(T||(T=new j),T.get(n)),L=(n,t,e)=>{const i=parseFloat(n),s=window.devicePixelRatio||1;if(t==="px")return i;if(t==="%"){const r=e===document.documentElement?window.innerWidth:e.offsetWidth;return i/100*r}if(t==="rem"){const r=parseFloat(f(document.documentElement).fontSize);return i*r}if(t==="em"){const r=parseFloat(f(e).fontSize);return i*r}if(t==="vh"||t==="vw"||t==="vmin"||t==="vmax"){const r={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return i/100*r[t]}const a={cm:37.7952755906,mm:3.77952755906,in:96};return t in a?i*a[t]*s:(console.warn("Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"),0)},A=(n,t,e={x:0,y:0})=>{const i=n.getBoundingClientRect(),s=f(n).transform;let a=0,r=0;if(s!=="none"){const _=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,g=s.match(_);g&&(a=L(g[1],g[2],n),r=L(g[3],g[4],n))}const{clientX:h,clientY:d}=F(t,e),m=h-i.left-a+n.scrollLeft,o=d-i.top-r+n.scrollTop;return{x:m,y:o}},F=(n,t)=>{const{clientX:e,clientY:i}=N(n)?B(n):n,s=e>0?e:t.x,a=i>0?i:t.y;return{clientX:s,clientY:a}},B=n=>{if(n.touches.length){let{clientX:e,clientY:i}=n.touches[0];if(n.touches.length>1){const s=n.touches[1],a=s.clientX,r=s.clientY;e=(e+a)/2,i=(i+r)/2}return{clientX:e,clientY:i}}const t=n.changedTouches[0];return{clientX:t.clientX,clientY:t.clientY}},W=(n,t)=>{const e=t.x+t.width,i=t.x,s=t.y+t.height,a=t.y,{x:r,y:h}=n;return r>=i&&r<=e&&h>=a&&h<=s},M=500,O=10;class H{constructor(t,{onTouchDragStart:e},i={}){c(this,"_touchDragTimeOut"),c(this,"_onTouchDragStart"),c(this,"_payload",null),c(this,"_delay",M),c(this,"_firstTouch",null),c(this,"_lastTouch",null),c(this,"_epsilon",O),this._payload=t,this._onTouchDragStart=e,this._delay=i.delay||M,this._epsilon=i.epsilon||O}onTouchStart(t){var e;!t||!((e=t?.touches)!=null&&e.length)||this._touchDragTimeOut||(this._firstTouch=t.touches[t.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=t.touches[0]),this._checkXDistance(t)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(t){var e;!t||!((e=t?.touches)!=null&&e.length)||(this._lastTouch=t.touches[0])}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(t){return()=>{if(!this._firstTouch||!this._lastTouch)return;let e=!1;e=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,e&&(this._onTouchDragStart(this._payload,t),this._resetTouches())}}}class V{constructor(){c(this,"_instance",null),c(this,"_mode","website"),c(this,"_viewName","main")}setInstance(t){this._instance=t}setMode(t){this._mode=t}setViewName(t){this._viewName=t}}const G=n=>new Promise(t=>setTimeout(t,n)),X="rml-drag-in-styles",J="rml-drag-in-drag-element",y="rml-drag-in-overlay",b="rml-drag-in-spacer",D="rml-drag-in-drag-ghost",E="rml-drag-in-fade-in",Y="rml-drag-in-fade-out",S={DISPLAY_NONE:"rml-display-none"},P=.5,C="250ms",$="forwards",w=n=>n?!0:(console.warn("No instance set, cancel drag-in"),!1);class K extends V{constructor(t){super(),c(this,"_mainDomElement"),c(this,"_currentDrag",{}),c(this,"_currentTouch",null),c(this,"_firefoxDragPosition",{x:0,y:0}),c(this,"_readyForDragUpdates",!1),c(this,"options",{}),c(this,"_firefoxFallback",e=>{if(!this._currentDrag.event)return;const i=e||window.event;this._firefoxDragPosition.x=i.pageX||0,this._firefoxDragPosition.y=i.pageY||0}),this._mainDomElement=t,this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),this._initReadyForDragUpdates(),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!document.getElementById(X)){const t=document.createElement("style");t.type="text/css",t.id=X,t.innerHTML=`
2
- .${S.DISPLAY_NONE}{display:none}
3
- .${y}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
4
- .${D}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
5
- @keyframes ${E} {from{opacity: 0;}to {opacity: ${P};}}
6
- @keyframes ${Y} {from{opacity: ${P};}to {opacity: 0;}}
7
- `,document.head.appendChild(t)}}_initializeDragGhost(){const t=this._mode==="custom-view"?document.body:this._mainDomElement.parentNode;let e=t.querySelector("."+D);e||(e=document.createElement("div"),e.classList.add(D),e.innerText=" ",t.appendChild(e))}_initReadyForDragUpdates(){this._readyForDragUpdates=this._mode!=="custom-view"}setInstance(t){this._instance=t}setMode(t){this._mode=t,this._initReadyForDragUpdates()}async dragStart(t,e,i="rml_id"){const s=this._mainDomElement.parentNode,a=s.querySelector("."+D);if(e instanceof DragEvent&&e.dataTransfer&&e.dataTransfer.setDragImage&&e.dataTransfer.setDragImage(a,0,0),this._mode==="custom-view"&&w(this._instance)){const d=await this._instance.getBoundingClientRect("iframe"),m=this.options.domContainer;if(!m)throw new Error("No container set, can not expand custom view");m.style.position="absolute",m.style.top=`${d.top}px`,m.style.left=`${d.left}px`,m.style.width=`${d.width}px`;let o=document.body.querySelector(`.${b}`);o||(o=document.createElement("div"),o.classList.add(b),document.body.appendChild(o)),o=document.body.querySelector(`.${b}`),o&&(o.style.position="fixed",o.style.backgroundColor="blue",o.style.top="0px",o.style.left=`${d.left}px`,o.style.width=`${d.width}px`,o.style.height=`${d.height+d.top}px`,o.style.opacity="0",o.style.pointerEvents="none",o.style.zIndex="-1",this._currentDrag.spacer=o),await this._instance.expandCustomView(this._viewName),await G(50)}const r=f(s);if(this._mode==="website"&&r.position!=="relative"){console.warn("Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly");return}this._mainDomElement.style.pointerEvents="none";let h=s.querySelector("."+y);h||(h=document.createElement("div"),h.classList.add(y),s.appendChild(h)),h.classList.remove(S.DISPLAY_NONE),e.target.getAttribute("draggable")||console.warn(`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`),this._currentDrag.event=e,this._currentDrag.id=t,this._currentDrag.type=i,this._readyForDragUpdates=!0}dragUpdate(t){var e,i;if(!this._readyForDragUpdates)return;const{clientX:s,clientY:a}=F(t,this._firefoxDragPosition),r=s<=0||a<=0;if(this._mode==="custom-view"&&r)return;const h=this._mainDomElement.parentNode,{x:d,y:m}=A(h,t,this._firefoxDragPosition);if(d===0&&m===0)return;if(!this._currentDrag.element){const l=t.target.cloneNode();l.style.position="fixed",l.style.pointerEvents="none",l.style.opacity="0",l.style.animation=`${E} ${C} ${$}`,l.id=J,l.style.zIndex="9999",document.body.appendChild(l),this._currentDrag.element=l;const u=t.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0}),this._currentDrag.offset.x=this._mode==="website"?s-u.left:u.width/2,this._currentDrag.offset.y=this._mode==="website"?a-u.top:u.height/2}const o=Math.max(1,d),_=Math.max(1,m),g=((e=this._currentDrag.offset)==null?void 0:e.x)||0,U=((i=this._currentDrag.offset)==null?void 0:i.y)||0,k=s-g,z=a-U;this._currentDrag.element.style.left=`${k}px`,this._currentDrag.element.style.top=`${z}px`;const v=(this.options.dragInOverlapX||0)+1,x=(this.options.dragInOverlapY||0)+1;let I=o>v&&_>x;if(this._mode==="custom-view"){const l=this._currentDrag.spacer;if(!l)throw new Error("No spacer set, can not fade in/out drag ghost");const u=l.getBoundingClientRect();I=!W({x:o,y:_},{x:u.left-v,y:u.top-x,width:u.width+v,height:u.height+x})}if(I?this._currentDrag.element.style.animation=`${Y} ${C} ${$}`:this._currentDrag.element.style.animation=`${E} ${C} ${$}`,!(o===1&&_===1)&&w(this._instance)){let l=o,u=_;if(N(t)){const p=this.options.fingerSize||0;l=Math.max(2,o+p),u=Math.max(2,_-p)}if(this._currentDrag.inserted==="done")this._instance.updateDrag(l,u);else if(this._currentDrag.inserted!=="inprogress"){if(this._currentDrag.inserted="inprogress",!this._currentDrag.id||!this._currentDrag.type)return;this._instance.dragInObject(this._currentDrag.id,l,u,this._currentDrag.type).then(()=>{this._currentDrag.inserted="done"},p=>{console.error(p),this._currentDrag.inserted="failed"})}}}async dragEnd(){if(this._initReadyForDragUpdates(),w(this._instance)&&this._mode==="custom-view"){await this._instance.collapseCustomView(this._viewName);const i=this.options.domContainer;if(!i)throw new Error("No container set, can not collapse custom view");i.style.position="",i.style.top="",i.style.left="",i.style.width="",i.style.height=""}this._mainDomElement.style.pointerEvents="all";const t=this._mainDomElement.parentNode;w(this._instance)&&this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag.spacer&&document.body.removeChild(this._currentDrag.spacer),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const e=t.querySelector("."+y);e&&e.classList.add(S.DISPLAY_NONE)}touchStart(t,e,i="rml_id"){var s,a;e.preventDefault();const r=(d,m)=>{this.dragStart(t,m,i)},h={};typeof((s=this.options)==null?void 0:s.touchDragDelay)=="number"&&(h.delay=this.options.touchDragDelay),(a=this.options)!=null&&a.touchDragEpsilon&&(h.epsilon=this.options.touchDragEpsilon),this._currentTouch=new H(void 0,{onTouchDragStart:r},h),this._currentTouch.onTouchStart(e)}touchMove(t){this._currentTouch&&this._currentTouch.onTouchMove(t),this._currentDrag.event&&this.dragUpdate(t)}touchEnd(){this._currentTouch&&this._currentTouch.onTouchEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}}export{K as DragIn};