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

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,335 +0,0 @@
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 {
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 s = getComputedStyle(t);
16
- return this._computedStyleCache.set(t, { style: s, updated: i }), this._cacheCleanInterval || (this._cacheCleanInterval = setInterval(
17
- () => this._cleanUpCache,
18
- Math.max(this._maxLifetime * 1e3, 5e3)
19
- )), s;
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 = (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;
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
- x(document.documentElement).fontSize
41
- );
42
- return i * o;
43
- }
44
- if (t === "em") {
45
- const o = parseFloat(
46
- x(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] * s : (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
- }, q = (n, t, e = { x: 0, y: 0 }) => {
68
- const i = n.getBoundingClientRect(), a = x(n).transform;
69
- let o = 0, d = 0;
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;
84
- e = (e + a) / 2, i = (i + o) / 2;
85
- }
86
- return { clientX: e, clientY: i };
87
- }
88
- const t = n.changedTouches[0];
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;
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", O);
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 || O, 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() {
137
- r(this, "_instance", null);
138
- r(this, "_mode", "website");
139
- r(this, "_viewName", "main");
140
- }
141
- setInstance(t) {
142
- this._instance = t;
143
- }
144
- setMode(t) {
145
- this._mode = t;
146
- }
147
- setViewName(t) {
148
- this._viewName = t;
149
- }
150
- }
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 = {
152
- 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);
154
- class Z extends j {
155
- constructor(e) {
156
- super();
157
- r(this, "_mainDomElement");
158
- r(this, "_currentDrag", {});
159
- r(this, "_currentTouch", null);
160
- r(this, "_firefoxDragPosition", { x: 0, y: 0 });
161
- r(this, "_readyForDragUpdates", !1);
162
- r(this, "options", {});
163
- r(this, "_firefoxFallback", (e) => {
164
- if (!this._currentDrag.event)
165
- return;
166
- const i = e || window.event;
167
- this._firefoxDragPosition.x = i.pageX || 0, this._firefoxDragPosition.y = i.pageY || 0;
168
- });
169
- this._mainDomElement = e, this._injectStyles(), this._initializeDragGhost(), this._firefoxFallback = this._firefoxFallback.bind(this), this._initReadyForDragUpdates(), document.addEventListener("dragover", this._firefoxFallback);
170
- }
171
- _injectStyles() {
172
- if (!!!document.getElementById($)) {
173
- const i = document.createElement("style");
174
- i.type = "text/css", i.id = $, i.innerHTML = `
175
- .${N.DISPLAY_NONE}{display:none}
176
- .${y}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
177
- .${D}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
178
- @keyframes ${I} {from{opacity: 0;}to {opacity: ${F};}}
179
- @keyframes ${X} {from{opacity: ${F};}to {opacity: 0;}}
180
- `, document.head.appendChild(i);
181
- }
182
- }
183
- _initializeDragGhost() {
184
- const e = this._mode === "custom-view" ? document.body : this._mainDomElement.parentNode;
185
- let i = e.querySelector(
186
- "." + D
187
- );
188
- i || (i = document.createElement("div"), i.classList.add(D), i.innerText = " ", e.appendChild(i));
189
- }
190
- _initReadyForDragUpdates() {
191
- this._readyForDragUpdates = this._mode !== "custom-view";
192
- }
193
- setInstance(e) {
194
- this._instance = e;
195
- }
196
- setMode(e) {
197
- this._mode = e, this._initReadyForDragUpdates();
198
- }
199
- async dragStart(e, i, s = "rml_id") {
200
- const a = this._mainDomElement.parentNode, o = a.querySelector(
201
- "." + D
202
- );
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") {
219
- console.warn(
220
- "Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly"
221
- );
222
- return;
223
- }
224
- this._mainDomElement.style.pointerEvents = "none";
225
- let u = a.querySelector(
226
- "." + y
227
- );
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
- `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
- }
232
- /** MUST NOT BE ASYNC, OTHERWISE ACCESS TO event.clientX could be wrong */
233
- dragUpdate(e) {
234
- var R, L;
235
- if (!this._readyForDragUpdates)
236
- return;
237
- const { clientX: i, clientY: s } = U(
238
- e,
239
- this._firefoxDragPosition
240
- ), a = i <= 0 || s <= 0;
241
- if (this._mode === "custom-view" && a)
242
- return;
243
- const o = this._mainDomElement.parentNode, { x: d, y: u } = q(o, e, this._firefoxDragPosition);
244
- if (d === 0 && u === 0)
245
- return;
246
- 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;
251
- }
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;
256
- if (this._mode === "custom-view") {
257
- const l = this._currentDrag.spacer;
258
- if (!l)
259
- throw new Error("No spacer set, can not fade in/out drag ghost");
260
- const _ = l.getBoundingClientRect();
261
- v = !V(
262
- { x: m, y: h },
263
- {
264
- x: _.left - T,
265
- y: _.top - S,
266
- width: _.width + T,
267
- height: _.height + S
268
- }
269
- );
270
- }
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;
273
- if (P(e)) {
274
- const p = this.options.fingerSize || 0;
275
- l = Math.max(2, m + p), _ = Math.max(2, h - p);
276
- }
277
- if (this._currentDrag.inserted === "done")
278
- this._instance.updateDrag(l, _);
279
- else if (this._currentDrag.inserted !== "inprogress") {
280
- if (this._currentDrag.inserted = "inprogress", !this._currentDrag.id || !this._currentDrag.type)
281
- return;
282
- this._instance.dragInObject(this._currentDrag.id, l, _, this._currentDrag.type).then(
283
- () => {
284
- this._currentDrag.inserted = "done";
285
- },
286
- (p) => {
287
- console.error(p), this._currentDrag.inserted = "failed";
288
- }
289
- );
290
- }
291
- }
292
- }
293
- async dragEnd() {
294
- if (this._initReadyForDragUpdates(), w(this._instance) && this._mode === "custom-view") {
295
- await this._instance.collapseCustomView(this._viewName);
296
- const s = this.options.domContainer;
297
- if (!s)
298
- 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 = "";
300
- }
301
- this._mainDomElement.style.pointerEvents = "all";
302
- 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 };
304
- const i = e.querySelector(
305
- "." + y
306
- );
307
- i && i.classList.add(N.DISPLAY_NONE);
308
- }
309
- touchStart(e, i, s = "rml_id") {
310
- var d, u;
311
- i.preventDefault();
312
- const a = (m, h) => {
313
- this.dragStart(e, h, s);
314
- }, 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(
316
- void 0,
317
- {
318
- onTouchDragStart: a
319
- },
320
- o
321
- ), this._currentTouch.onTouchStart(i);
322
- }
323
- touchMove(e) {
324
- this._currentTouch && this._currentTouch.onTouchMove(e), this._currentDrag.event && this.dragUpdate(e);
325
- }
326
- touchEnd() {
327
- this._currentTouch && this._currentTouch.onTouchEnd(), this._currentTouch = null, this.dragEnd();
328
- }
329
- dispose() {
330
- document.removeEventListener("dragover", this._firefoxFallback);
331
- }
332
- }
333
- export {
334
- Z as DragIn
335
- };