@roomle/embedding-lib 5.5.0-debug.2 → 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.
- package/docs/md/web/embedding/CHANGELOG.md +3 -3
- package/drag-in-CXPjCiN1.mjs +338 -0
- package/drag-in-DhWNfKDL.mjs +7 -0
- package/index.d.ts +21 -9
- package/package.json +1 -1
- package/roomle-embedding-lib.es.js +11 -11
- package/roomle-embedding-lib.es.min.js +2 -2
- package/roomle-embedding-lib.umd.js +14 -14
- package/roomle-embedding-lib.umd.min.js +14 -14
- package/drag-in-Dq8ixDxG.mjs +0 -323
- package/drag-in-Dq_vb7GH.mjs +0 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
## [5.5.0-debug.
|
|
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
|
-
###
|
|
4
|
+
### Features
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* make things more stable ([432c571](https://github.com/roomle-dev/roomle-ui/commit/432c5713b1504e865d3152f888940b72d3767516))
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
var z = Object.defineProperty;
|
|
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
|
+
constructor(t = 16) {
|
|
6
|
+
r(this, "_computedStyleCache", /* @__PURE__ */ new Map());
|
|
7
|
+
r(this, "_maxLifetime", 16);
|
|
8
|
+
r(this, "_cacheCleanInterval", null);
|
|
9
|
+
this._maxLifetime = t;
|
|
10
|
+
}
|
|
11
|
+
get(t) {
|
|
12
|
+
const e = this._computedStyleCache.get(t), i = Date.now();
|
|
13
|
+
if (e && i - e.updated < this._maxLifetime)
|
|
14
|
+
return e.style;
|
|
15
|
+
const n = getComputedStyle(t);
|
|
16
|
+
return this._computedStyleCache.set(t, { style: n, updated: i }), this._cacheCleanInterval || (this._cacheCleanInterval = setInterval(
|
|
17
|
+
() => this._cleanUpCache,
|
|
18
|
+
Math.max(this._maxLifetime * 1e3, 5e3)
|
|
19
|
+
)), n;
|
|
20
|
+
}
|
|
21
|
+
_cleanUpCache() {
|
|
22
|
+
const t = Date.now();
|
|
23
|
+
for (const [e, { updated: i }] of this._computedStyleCache.entries())
|
|
24
|
+
t - i >= this._maxLifetime && this._computedStyleCache.delete(e);
|
|
25
|
+
this._computedStyleCache.size === 0 && this._cacheCleanInterval && (clearInterval(this._cacheCleanInterval), this._cacheCleanInterval = null);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
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
|
+
if (t === "px")
|
|
33
|
+
return i;
|
|
34
|
+
if (t === "%") {
|
|
35
|
+
const o = e === document.documentElement ? window.innerWidth : e.offsetWidth;
|
|
36
|
+
return i / 100 * o;
|
|
37
|
+
}
|
|
38
|
+
if (t === "rem") {
|
|
39
|
+
const o = parseFloat(
|
|
40
|
+
T(document.documentElement).fontSize
|
|
41
|
+
);
|
|
42
|
+
return i * o;
|
|
43
|
+
}
|
|
44
|
+
if (t === "em") {
|
|
45
|
+
const o = parseFloat(
|
|
46
|
+
T(e).fontSize
|
|
47
|
+
);
|
|
48
|
+
return i * o;
|
|
49
|
+
}
|
|
50
|
+
if (t === "vh" || t === "vw" || t === "vmin" || t === "vmax") {
|
|
51
|
+
const o = {
|
|
52
|
+
vh: window.innerHeight,
|
|
53
|
+
vw: window.innerWidth,
|
|
54
|
+
vmin: Math.min(window.innerWidth, window.innerHeight),
|
|
55
|
+
vmax: Math.max(window.innerWidth, window.innerHeight)
|
|
56
|
+
};
|
|
57
|
+
return i / 100 * o[t];
|
|
58
|
+
}
|
|
59
|
+
const a = {
|
|
60
|
+
cm: 37.7952755906,
|
|
61
|
+
mm: 3.77952755906,
|
|
62
|
+
in: 96
|
|
63
|
+
};
|
|
64
|
+
return t in a ? i * a[t] * n : (console.warn(
|
|
65
|
+
"Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"
|
|
66
|
+
), 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
|
+
if (a !== "none") {
|
|
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
|
+
e = (e + a) / 2, i = (i + o) / 2;
|
|
85
|
+
}
|
|
86
|
+
return { clientX: e, clientY: i };
|
|
87
|
+
}
|
|
88
|
+
const t = s.changedTouches[0];
|
|
89
|
+
return { clientX: t.clientX, clientY: t.clientY };
|
|
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
|
+
class W {
|
|
95
|
+
constructor(t, { onTouchDragStart: e }, i = {}) {
|
|
96
|
+
r(this, "_touchDragTimeOut");
|
|
97
|
+
r(this, "_onTouchDragStart");
|
|
98
|
+
r(this, "_payload", null);
|
|
99
|
+
r(this, "_delay", M);
|
|
100
|
+
r(this, "_firstTouch", null);
|
|
101
|
+
r(this, "_lastTouch", null);
|
|
102
|
+
r(this, "_epsilon", Y);
|
|
103
|
+
this._payload = t, this._onTouchDragStart = e, this._delay = i.delay || M, this._epsilon = i.epsilon || Y;
|
|
104
|
+
}
|
|
105
|
+
onTouchStart(t) {
|
|
106
|
+
var e;
|
|
107
|
+
!t || !((e = t == null ? void 0 : t.touches) != null && e.length) || this._touchDragTimeOut || (this._firstTouch = t.touches[t.touches.length - 1], this._touchDragTimeOut = setTimeout(() => {
|
|
108
|
+
this._clearTimeout(), this._lastTouch || (this._lastTouch = t.touches[0]), this._checkXDistance(t)();
|
|
109
|
+
}, this._delay));
|
|
110
|
+
}
|
|
111
|
+
onTouchEnd() {
|
|
112
|
+
this._resetTouches();
|
|
113
|
+
}
|
|
114
|
+
onTouchMove(t) {
|
|
115
|
+
var e;
|
|
116
|
+
!t || !((e = t == null ? void 0 : t.touches) != null && e.length) || (this._lastTouch = t.touches[0]);
|
|
117
|
+
}
|
|
118
|
+
_clearTimeout() {
|
|
119
|
+
this._touchDragTimeOut && (clearTimeout(this._touchDragTimeOut), this._touchDragTimeOut = null);
|
|
120
|
+
}
|
|
121
|
+
_resetTouches() {
|
|
122
|
+
this._clearTimeout(), this._lastTouch = null, this._firstTouch = null, this._payload = null;
|
|
123
|
+
}
|
|
124
|
+
_checkXDistance(t) {
|
|
125
|
+
return () => {
|
|
126
|
+
if (!this._firstTouch || !this._lastTouch)
|
|
127
|
+
return;
|
|
128
|
+
let e = !1;
|
|
129
|
+
e = Math.abs(
|
|
130
|
+
this._firstTouch.clientX - this._lastTouch.clientX
|
|
131
|
+
) < this._epsilon, e && (this._onTouchDragStart(this._payload, t), this._resetTouches());
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
class j {
|
|
136
|
+
constructor(t, e) {
|
|
137
|
+
r(this, "_mainDomElement");
|
|
138
|
+
r(this, "_instance", null);
|
|
139
|
+
r(this, "_mode", "website");
|
|
140
|
+
r(this, "_viewName", "main");
|
|
141
|
+
this._mainDomElement = t, this._mode = e;
|
|
142
|
+
}
|
|
143
|
+
setInstance(t) {
|
|
144
|
+
this._instance = t;
|
|
145
|
+
}
|
|
146
|
+
setViewName(t) {
|
|
147
|
+
this._viewName = t;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
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 = {
|
|
151
|
+
DISPLAY_NONE: "rml-display-none"
|
|
152
|
+
}, F = 0.5, b = "250ms", A = "forwards", g = (s) => s ? !0 : (console.warn("No instance set, cancel drag-in"), !1);
|
|
153
|
+
class Z extends j {
|
|
154
|
+
constructor(e, i) {
|
|
155
|
+
super(e, i);
|
|
156
|
+
r(this, "_currentDrag", {});
|
|
157
|
+
r(this, "_currentTouch", null);
|
|
158
|
+
r(this, "_firefoxDragPosition", { x: 0, y: 0 });
|
|
159
|
+
r(this, "_readyForDragUpdates", !1);
|
|
160
|
+
r(this, "_paddingTop", 0);
|
|
161
|
+
r(this, "options", {});
|
|
162
|
+
r(this, "_firefoxFallback", (e) => {
|
|
163
|
+
if (!this._currentDrag.event)
|
|
164
|
+
return;
|
|
165
|
+
const i = e || window.event;
|
|
166
|
+
this._firefoxDragPosition.x = i.pageX || 0, this._firefoxDragPosition.y = i.pageY || 0;
|
|
167
|
+
});
|
|
168
|
+
this._initReadyForDragUpdates(), this._injectStyles(), this._initializeDragGhost(), this._firefoxFallback = this._firefoxFallback.bind(this), this._initReadyForDragUpdates(), document.addEventListener("dragover", this._firefoxFallback);
|
|
169
|
+
}
|
|
170
|
+
_injectStyles() {
|
|
171
|
+
if (!!!document.getElementById(X)) {
|
|
172
|
+
const i = document.createElement("style");
|
|
173
|
+
i.type = "text/css", i.id = X, i.innerHTML = `
|
|
174
|
+
.${N.DISPLAY_NONE}{display:none}
|
|
175
|
+
.${f}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
|
|
176
|
+
.${D}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
|
|
177
|
+
@keyframes ${I} {from{opacity: 0;}to {opacity: ${F};}}
|
|
178
|
+
@keyframes ${$} {from{opacity: ${F};}to {opacity: 0;}}
|
|
179
|
+
`, document.head.appendChild(i);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
_initializeDragGhost() {
|
|
183
|
+
const e = this._mode === "custom-view" ? document.body : this._mainDomElement.parentNode;
|
|
184
|
+
let i = e.querySelector(
|
|
185
|
+
"." + D
|
|
186
|
+
);
|
|
187
|
+
i || (i = document.createElement("div"), i.classList.add(D), i.innerText = " ", e.appendChild(i));
|
|
188
|
+
}
|
|
189
|
+
_initReadyForDragUpdates() {
|
|
190
|
+
this._readyForDragUpdates = this._mode !== "custom-view";
|
|
191
|
+
}
|
|
192
|
+
setInstance(e) {
|
|
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
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async dragStart(e, i, n = "rml_id") {
|
|
212
|
+
const a = this._mainDomElement.parentNode, o = a.querySelector(
|
|
213
|
+
"." + D
|
|
214
|
+
);
|
|
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") {
|
|
220
|
+
console.warn(
|
|
221
|
+
"Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly"
|
|
222
|
+
);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
this._mainDomElement.style.pointerEvents = "none";
|
|
226
|
+
let l = a.querySelector(
|
|
227
|
+
"." + f
|
|
228
|
+
);
|
|
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(
|
|
230
|
+
`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`
|
|
231
|
+
), this._currentDrag.event = i, this._currentDrag.id = e, this._currentDrag.type = n, this._readyForDragUpdates = !0;
|
|
232
|
+
}
|
|
233
|
+
/** MUST NOT BE ASYNC, OTHERWISE ACCESS TO event.clientX could be wrong */
|
|
234
|
+
dragUpdate(e) {
|
|
235
|
+
var R, L;
|
|
236
|
+
if (!this._readyForDragUpdates)
|
|
237
|
+
return;
|
|
238
|
+
const { clientX: i, clientY: n } = U(
|
|
239
|
+
e,
|
|
240
|
+
this._firefoxDragPosition
|
|
241
|
+
), a = i <= 0 || n <= 0;
|
|
242
|
+
if (this._mode === "custom-view" && a)
|
|
243
|
+
return;
|
|
244
|
+
const o = this._mainDomElement.parentNode, { x: h, y: l } = H(o, e, this._firefoxDragPosition);
|
|
245
|
+
if (h === 0 && l === 0)
|
|
246
|
+
return;
|
|
247
|
+
if (!this._currentDrag.element) {
|
|
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;
|
|
252
|
+
}
|
|
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;
|
|
257
|
+
if (this._mode === "custom-view") {
|
|
258
|
+
const c = document.body.querySelector(
|
|
259
|
+
`.${y}`
|
|
260
|
+
);
|
|
261
|
+
if (!c)
|
|
262
|
+
throw new Error("No spacer set, can not fade in/out drag ghost");
|
|
263
|
+
const d = c.getBoundingClientRect();
|
|
264
|
+
v = !V(
|
|
265
|
+
{ x: u, y: _ },
|
|
266
|
+
{
|
|
267
|
+
x: d.left - S,
|
|
268
|
+
y: d.top - E,
|
|
269
|
+
width: d.width + S,
|
|
270
|
+
height: d.height + E
|
|
271
|
+
}
|
|
272
|
+
);
|
|
273
|
+
}
|
|
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 = _;
|
|
276
|
+
if (P(e)) {
|
|
277
|
+
const p = this.options.fingerSize || 0;
|
|
278
|
+
c = Math.max(2, u + p), d = Math.max(2, _ - p);
|
|
279
|
+
}
|
|
280
|
+
if (this._currentDrag.inserted === "done")
|
|
281
|
+
this._instance.updateDrag(c, d);
|
|
282
|
+
else if (this._currentDrag.inserted !== "inprogress") {
|
|
283
|
+
if (this._currentDrag.inserted = "inprogress", !this._currentDrag.id || !this._currentDrag.type)
|
|
284
|
+
return;
|
|
285
|
+
this._instance.dragInObject(this._currentDrag.id, c, d, this._currentDrag.type).then(
|
|
286
|
+
() => {
|
|
287
|
+
this._currentDrag.inserted = "done";
|
|
288
|
+
},
|
|
289
|
+
(p) => {
|
|
290
|
+
console.error(p), this._currentDrag.inserted = "failed";
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async dragEnd() {
|
|
297
|
+
if (this._initReadyForDragUpdates(), g(this._instance) && this._mode === "custom-view") {
|
|
298
|
+
await this._instance.collapseCustomView(this._viewName);
|
|
299
|
+
const n = this.options.domContainer;
|
|
300
|
+
if (!n)
|
|
301
|
+
throw new Error("No container set, can not collapse custom view");
|
|
302
|
+
n.style.paddingTop = "";
|
|
303
|
+
}
|
|
304
|
+
this._mainDomElement.style.pointerEvents = "all";
|
|
305
|
+
const e = this._mainDomElement.parentNode;
|
|
306
|
+
g(this._instance) && this._instance.dragInObjectEnd(), this._currentDrag.element && document.body.removeChild(this._currentDrag.element), this._currentDrag = {}, this._firefoxDragPosition = { x: 0, y: 0 };
|
|
307
|
+
const i = e.querySelector(
|
|
308
|
+
"." + f
|
|
309
|
+
);
|
|
310
|
+
i && i.classList.add(N.DISPLAY_NONE);
|
|
311
|
+
}
|
|
312
|
+
touchStart(e, i, n = "rml_id") {
|
|
313
|
+
var h, l;
|
|
314
|
+
i.preventDefault();
|
|
315
|
+
const a = (u, _) => {
|
|
316
|
+
this.dragStart(e, _, n);
|
|
317
|
+
}, o = {};
|
|
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(
|
|
319
|
+
void 0,
|
|
320
|
+
{
|
|
321
|
+
onTouchDragStart: a
|
|
322
|
+
},
|
|
323
|
+
o
|
|
324
|
+
), this._currentTouch.onTouchStart(i);
|
|
325
|
+
}
|
|
326
|
+
touchMove(e) {
|
|
327
|
+
this._currentTouch && this._currentTouch.onTouchMove(e), this._currentDrag.event && this.dragUpdate(e);
|
|
328
|
+
}
|
|
329
|
+
touchEnd() {
|
|
330
|
+
this._currentTouch && this._currentTouch.onTouchEnd(), this._currentTouch = null, this.dragEnd();
|
|
331
|
+
}
|
|
332
|
+
dispose() {
|
|
333
|
+
document.removeEventListener("dragover", this._firefoxFallback);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
export {
|
|
337
|
+
Z as DragIn
|
|
338
|
+
};
|
|
@@ -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
|
|
20
|
-
|
|
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,10 +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;
|
|
53
|
+
private _readyForDragUpdates;
|
|
54
|
+
private _paddingTop;
|
|
54
55
|
options: {
|
|
55
56
|
dragInOverlapX?: number;
|
|
56
57
|
dragInOverlapY?: number;
|
|
@@ -61,11 +62,13 @@ declare class DragIn extends EmbeddingPlugin {
|
|
|
61
62
|
};
|
|
62
63
|
private _injectStyles;
|
|
63
64
|
private _initializeDragGhost;
|
|
64
|
-
|
|
65
|
+
private _initReadyForDragUpdates;
|
|
66
|
+
constructor(iframe: HTMLIFrameElement | HTMLBodyElement, mode: EmbeddingPluginMode);
|
|
65
67
|
setInstance(instance: ExposedApi): void;
|
|
66
|
-
|
|
68
|
+
private _initDom;
|
|
67
69
|
private _firefoxFallback;
|
|
68
70
|
dragStart(id: RapiId, event: DragEvent | TouchEvent, type?: string): Promise<void>;
|
|
71
|
+
/** MUST NOT BE ASYNC, OTHERWISE ACCESS TO event.clientX could be wrong */
|
|
69
72
|
dragUpdate(event: DragEvent | TouchEvent): void;
|
|
70
73
|
dragEnd(): Promise<void>;
|
|
71
74
|
touchStart(id: RapiId, event: TouchEvent, type?: string): void;
|
|
@@ -74,22 +77,31 @@ declare class DragIn extends EmbeddingPlugin {
|
|
|
74
77
|
dispose(): void;
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
declare
|
|
80
|
+
declare class EmbeddingPlugin {
|
|
81
|
+
protected _mainDomElement: HTMLIFrameElement | HTMLBodyElement;
|
|
78
82
|
protected _instance: Nullable_2<ExposedApi>;
|
|
79
83
|
protected _mode: EmbeddingPluginMode;
|
|
80
84
|
protected _viewName: PossibleCustomViewsAndMain_2;
|
|
85
|
+
constructor(iframe: HTMLIFrameElement | HTMLBodyElement, mode: EmbeddingPluginMode);
|
|
81
86
|
setInstance(instance: ExposedApi): void;
|
|
82
|
-
setMode(mode: EmbeddingPluginMode): void;
|
|
83
87
|
setViewName(viewName: PossibleCustomViewsAndMain_2): void;
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
declare type EmbeddingPluginMode = 'website' | 'custom-view';
|
|
87
91
|
|
|
92
|
+
declare type PluginConstructors = {
|
|
93
|
+
[K in keyof PluginMap]: PluginMap[K];
|
|
94
|
+
};
|
|
95
|
+
|
|
88
96
|
declare type PluginDefinitions = Array<keyof AvailablePlugins | {
|
|
89
97
|
name: keyof AvailablePlugins;
|
|
90
|
-
loader: () => Promise<
|
|
98
|
+
loader: () => Promise<PluginConstructors[keyof PluginConstructors]>;
|
|
91
99
|
}>;
|
|
92
100
|
|
|
101
|
+
declare interface PluginMap {
|
|
102
|
+
dragIn: typeof DragIn;
|
|
103
|
+
}
|
|
104
|
+
|
|
93
105
|
declare type RoomleConfiguratorApi = RoomleEmbeddingApi<default_2, default_4>;
|
|
94
106
|
|
|
95
107
|
declare class RoomleEmbeddingApi<SdkType, SdkCallbacks> extends Connector<SdkType, SdkCallbacks> {
|
package/package.json
CHANGED
|
@@ -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
|
|
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")),
|
|
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 =
|
|
167
|
-
const t = s[
|
|
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-
|
|
290
|
+
import("./drag-in-CXPjCiN1.mjs").then(
|
|
291
291
|
({ DragIn: a }) => {
|
|
292
|
-
const i = new a(e);
|
|
293
|
-
i.setInstance(this.ui), i.
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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),
|
|
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};
|