@roomle/embedding-lib 5.6.0-debug.1 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,513 +0,0 @@
1
- var W = Object.defineProperty;
2
- var k = (r, t, e) => t in r ? W(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var a = (r, t, e) => k(r, typeof t != "symbol" ? t + "" : t, e);
4
- class K {
5
- constructor(t, e, s, n) {
6
- a(this, "_mainDomElement");
7
- a(this, "_instance", null);
8
- a(this, "_mode", "website");
9
- a(this, "_viewName", "main");
10
- this._instance = t, this._mainDomElement = e, this._mode = s, this._viewName = n;
11
- }
12
- }
13
- const O = "rml-drag-in-styles", j = "rml-drag-in-drag-element", y = "rml-drag-in-overlay", T = "rml-drag-in-drag-ghost", G = "rml-drag-in-fade-in", U = "rml-drag-in-fade-out", w = {
14
- DISPLAY_NONE: "rml-display-none"
15
- }, B = 0.5, F = "250ms", P = "forwards", q = `@keyframes ${G} {from{opacity: 0;}to {opacity: ${B};}}`, V = `@keyframes ${U} {from{opacity: ${B};}to {opacity: 0;}}`, Y = `${G} ${F} ${P}`, J = `${U} ${F} ${P}`, b = "https://res.cloudinary.com/roomle/image/upload/v1729679975/fallback_afpyqr.jpg", Q = 112, Z = 112;
16
- class tt {
17
- constructor(t = 16) {
18
- a(this, "_computedStyleCache", /* @__PURE__ */ new Map());
19
- a(this, "_maxLifetime", 16);
20
- a(this, "_cacheCleanInterval", null);
21
- this._maxLifetime = t;
22
- }
23
- get(t) {
24
- const e = this._computedStyleCache.get(t), s = Date.now();
25
- if (e && s - e.updated < this._maxLifetime)
26
- return e.style;
27
- const n = getComputedStyle(t);
28
- return this._computedStyleCache.set(t, { style: n, updated: s }), this._cacheCleanInterval || (this._cacheCleanInterval = setInterval(
29
- () => this._cleanUpCache,
30
- Math.max(this._maxLifetime * 1e3, 5e3)
31
- )), n;
32
- }
33
- _cleanUpCache() {
34
- const t = Date.now();
35
- for (const [e, { updated: s }] of this._computedStyleCache.entries())
36
- t - s >= this._maxLifetime && this._computedStyleCache.delete(e);
37
- this._computedStyleCache.size === 0 && this._cacheCleanInterval && (clearInterval(this._cacheCleanInterval), this._cacheCleanInterval = null);
38
- }
39
- }
40
- const m = (r) => window.TouchEvent && r instanceof window.TouchEvent;
41
- let I;
42
- const S = (r) => (I || (I = new tt()), I.get(r)), M = (r, t, e) => {
43
- const s = parseFloat(r), n = window.devicePixelRatio || 1;
44
- if (t === "px")
45
- return s;
46
- if (t === "%") {
47
- const i = e === document.documentElement ? window.innerWidth : e.offsetWidth;
48
- return s / 100 * i;
49
- }
50
- if (t === "rem") {
51
- const i = parseFloat(
52
- S(document.documentElement).fontSize
53
- );
54
- return s * i;
55
- }
56
- if (t === "em") {
57
- const i = parseFloat(
58
- S(e).fontSize
59
- );
60
- return s * i;
61
- }
62
- if (t === "vh" || t === "vw" || t === "vmin" || t === "vmax") {
63
- const i = {
64
- vh: window.innerHeight,
65
- vw: window.innerWidth,
66
- vmin: Math.min(window.innerWidth, window.innerHeight),
67
- vmax: Math.max(window.innerWidth, window.innerHeight)
68
- };
69
- return s / 100 * i[t];
70
- }
71
- const o = {
72
- cm: 37.7952755906,
73
- mm: 3.77952755906,
74
- in: 96
75
- };
76
- return t in o ? s * o[t] * n : (console.warn(
77
- "Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"
78
- ), 0);
79
- }, X = (r, t, e = { x: 0, y: 0 }) => {
80
- const s = r.getBoundingClientRect(), o = S(r).transform;
81
- let i = 0, l = 0;
82
- if (o !== "none") {
83
- const g = /translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/, d = o.match(g);
84
- d && (i = M(d[1], d[2], r), l = M(d[3], d[4], r));
85
- }
86
- const { clientX: _, clientY: c } = D(t, e), h = _ - s.left - i + r.scrollLeft, u = c - s.top - l + r.scrollTop;
87
- return { x: h, y: u };
88
- }, D = (r, t = null) => {
89
- const { clientX: e, clientY: s } = m(r) ? et(r) : r, n = e > 0 ? e : t ? t.x : e, o = s > 0 ? s : t ? t.y : s;
90
- return { clientX: n, clientY: o };
91
- }, et = (r) => {
92
- if (r.touches.length) {
93
- let { clientX: e, clientY: s } = r.touches[0];
94
- if (r.touches.length > 1) {
95
- const n = r.touches[1], o = n.clientX, i = n.clientY;
96
- e = (e + o) / 2, s = (s + i) / 2;
97
- }
98
- return { clientX: e, clientY: s };
99
- }
100
- const t = r.changedTouches[0];
101
- return { clientX: t.clientX, clientY: t.clientY };
102
- }, L = 500, v = 10, H = 100, $ = 15, A = (r, t = 0) => m(r) ? {
103
- clientX: r.touches[t].clientX,
104
- clientY: r.touches[t].clientY
105
- } : {
106
- clientX: r.clientX,
107
- clientY: r.clientY
108
- }, N = (r) => r && m(r) ? r.touches.length > 0 : !0;
109
- class z {
110
- constructor(t, { onTouchDragStart: e }, s = {}) {
111
- a(this, "_touchDragTimeOut");
112
- a(this, "_onTouchDragStart");
113
- a(this, "_payload", null);
114
- a(this, "_delay", L);
115
- a(this, "_firstTouch", null);
116
- a(this, "_lastTouch", null);
117
- a(this, "_epsilon", v);
118
- this._payload = t, this._onTouchDragStart = e, this._delay = typeof s.delay == "number" ? s.delay : L, this._epsilon = typeof s.epsilon == "number" ? s.epsilon : v;
119
- }
120
- onStart(t) {
121
- N(t) && (this._touchDragTimeOut || (this._firstTouch = A(
122
- t,
123
- m(t) ? t.touches.length - 1 : 0
124
- ), this._touchDragTimeOut = setTimeout(() => {
125
- this._clearTimeout(), this._lastTouch || (this._lastTouch = A(t)), this._checkXDistance(t)();
126
- }, this._delay)));
127
- }
128
- onEnd() {
129
- this._resetTouches();
130
- }
131
- onMove(t) {
132
- N(t) && (this._lastTouch = A(t));
133
- }
134
- _clearTimeout() {
135
- this._touchDragTimeOut && (clearTimeout(this._touchDragTimeOut), this._touchDragTimeOut = null);
136
- }
137
- _resetTouches() {
138
- this._clearTimeout(), this._lastTouch = null, this._firstTouch = null, this._payload = null;
139
- }
140
- _checkXDistance(t) {
141
- return () => {
142
- if (!this._firstTouch || !this._lastTouch)
143
- return;
144
- let e = !1;
145
- e = Math.abs(
146
- this._firstTouch.clientX - this._lastTouch.clientX
147
- ) < this._epsilon, e && (this._onTouchDragStart(this._payload, t), this._resetTouches());
148
- };
149
- }
150
- }
151
- class st {
152
- constructor(t, e, s) {
153
- a(this, "_options", {});
154
- a(this, "_instance");
155
- a(this, "_mainDomElement");
156
- a(this, "_currentDrag", {});
157
- a(this, "_currentTouch", null);
158
- a(this, "_firefoxDragPosition", { x: 0, y: 0 });
159
- a(this, "isDragging", !1);
160
- a(this, "_firefoxFallback", (t) => {
161
- if (!this._currentDrag.event)
162
- return;
163
- const e = t || window.event;
164
- this._firefoxDragPosition.x = e.pageX || 0, this._firefoxDragPosition.y = e.pageY || 0;
165
- });
166
- this._instance = t, this._mainDomElement = e, this._options = s || {}, this._firefoxFallback = this._firefoxFallback.bind(this), document.addEventListener("dragover", this._firefoxFallback);
167
- }
168
- beforeUpdateGhost(t) {
169
- }
170
- dragStart(t, e, s = "rml_id") {
171
- const n = this._mainDomElement.parentNode;
172
- if (S(n).position !== "relative") {
173
- console.warn(
174
- "Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly"
175
- );
176
- return;
177
- }
178
- this._mainDomElement.style.pointerEvents = "none";
179
- let i = n.querySelector(
180
- "." + y
181
- );
182
- i || (i = document.createElement("div"), i.classList.add(y), n.appendChild(i)), i.classList.remove(w.DISPLAY_NONE), e.target.getAttribute("draggable") || console.warn(
183
- `Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`
184
- );
185
- const _ = n.querySelector(
186
- "." + T
187
- );
188
- this._currentDrag.event = e;
189
- const c = e.target.cloneNode();
190
- c.style.position = "fixed", c.style.pointerEvents = "none", c.style.opacity = "0", c.style.animation = Y, c.id = j, c.style.zIndex = "9999", document.body.appendChild(c), this._currentDrag.element = c;
191
- const h = e.target.getBoundingClientRect();
192
- this._currentDrag.offset || (this._currentDrag.offset = { x: 0, y: 0 });
193
- const { clientX: u, clientY: g } = D(
194
- e,
195
- this._firefoxDragPosition
196
- );
197
- this._currentDrag.offset.x = u - h.left, this._currentDrag.offset.y = g - h.top, c.style.top = g + "px", c.style.left = u + "px", e instanceof DragEvent && e.dataTransfer && e.dataTransfer.setDragImage && e.dataTransfer.setDragImage(_, 0, 0);
198
- const { x: d, y: f } = X(
199
- n,
200
- this._currentDrag.event || e,
201
- this._firefoxDragPosition
202
- ), p = Math.max(1, d), E = Math.max(1, f);
203
- this.isDragging = !0, this._instance.dragInObject(t, p, E, s);
204
- }
205
- dragUpdate(t) {
206
- var c, h;
207
- const e = this._mainDomElement.parentNode, { x: s, y: n } = X(e, t, this._firefoxDragPosition);
208
- if (s === 0 && n === 0)
209
- return;
210
- const o = Math.max(1, s), i = Math.max(1, n);
211
- if (this._currentDrag.element) {
212
- const { clientX: u, clientY: g } = D(
213
- t,
214
- this._firefoxDragPosition
215
- ), d = ((c = this._currentDrag.offset) == null ? void 0 : c.x) || 0, f = ((h = this._currentDrag.offset) == null ? void 0 : h.y) || 0;
216
- this._currentDrag.element.style.left = `${u - d}px`, this._currentDrag.element.style.top = `${g - f}px`;
217
- const p = (this._options.dragInOverlapX || 0) + 1, E = (this._options.dragInOverlapY || 0) + 1;
218
- o > p && i > E ? this._currentDrag.element.style.animation = J : this._currentDrag.element.style.animation = Y;
219
- }
220
- if (o === 1 && i === 1)
221
- return;
222
- let l = o, _ = i;
223
- if (m(t)) {
224
- const u = this._options.fingerSize || 0;
225
- l = Math.max(2, o + u), _ = Math.max(2, i - u);
226
- }
227
- this._instance.updateDrag(l, _);
228
- }
229
- dragEnd() {
230
- this._mainDomElement.style.pointerEvents = "all";
231
- const t = this._mainDomElement.parentNode;
232
- this.isDragging = !1, this._instance.dragInObjectEnd(), this._currentDrag.element && document.body.removeChild(this._currentDrag.element), this._currentDrag = {}, this._firefoxDragPosition = { x: 0, y: 0 };
233
- const e = t.querySelector(
234
- "." + y
235
- );
236
- e && e.classList.add(w.DISPLAY_NONE);
237
- }
238
- touchStart(t, e, s = "rml_id") {
239
- var i, l;
240
- e.preventDefault();
241
- const n = (_, c) => {
242
- this.dragStart(t, c, s);
243
- }, o = {};
244
- typeof ((i = this._options) == null ? void 0 : i.touchDragDelay) == "number" && (o.delay = this._options.touchDragDelay), (l = this._options) != null && l.touchDragEpsilon && (o.epsilon = this._options.touchDragEpsilon), this._currentTouch = new z(
245
- void 0,
246
- {
247
- onTouchDragStart: n
248
- },
249
- o
250
- ), this._currentTouch.onStart(e);
251
- }
252
- touchMove(t) {
253
- this._currentTouch && this._currentTouch.onMove(t), this._currentDrag.event && this.dragUpdate(t);
254
- }
255
- touchEnd() {
256
- this._currentTouch && this._currentTouch.onEnd(), this._currentTouch = null, this.dragEnd();
257
- }
258
- dispose() {
259
- document.removeEventListener("dragover", this._firefoxFallback);
260
- }
261
- releaseInput(t) {
262
- }
263
- }
264
- const rt = (r) => `[data-rml-custom-view="${r}"]`, C = (r) => {
265
- r.preventDefault(), r.stopPropagation();
266
- }, nt = (r, t, e, s) => {
267
- const n = e - r, o = s - t;
268
- return Math.sqrt(n * n + o * o);
269
- };
270
- class it {
271
- constructor({ onCustomDragStart: t }, e = {}) {
272
- a(this, "_startX", 0);
273
- a(this, "_startY", 0);
274
- a(this, "_lastX", 0);
275
- a(this, "_lastY", 0);
276
- a(this, "_delay");
277
- a(this, "_epsilon");
278
- a(this, "_isStarted", !1);
279
- a(this, "_isEnded", !1);
280
- a(this, "_isWaiting", !1);
281
- a(this, "_onCustomDragStart");
282
- this._delay = typeof e.delay == "number" ? e.delay : H, this._epsilon = typeof e.epsilon == "number" ? e.epsilon : $, this._onCustomDragStart = t;
283
- }
284
- onMove(t) {
285
- this._lastX = t.clientX, this._lastY = t.clientY, this._isWaiting && nt(
286
- this._startX,
287
- this._startY,
288
- this._lastX,
289
- this._lastY
290
- ) > this._epsilon && (this._onCustomDragStart(t), this._isWaiting = !1);
291
- }
292
- onStart(t) {
293
- this._startX = t.clientX, this._startY = t.clientY, this.onMove(t), this._isWaiting = !0;
294
- }
295
- onEnd() {
296
- this._reset();
297
- }
298
- _reset() {
299
- this._startX = 0, this._startY = 0, this._lastX = 0, this._lastY = 0, this._isWaiting = !1;
300
- }
301
- }
302
- const x = "data-rml-old-draggable", at = void 0, R = (r, t) => {
303
- const e = m(r), s = {
304
- delay: e ? L : H,
305
- epsilon: e ? v : $
306
- };
307
- if (!t)
308
- return s;
309
- if (!e && !(r instanceof MouseEvent))
310
- return console.warn(
311
- "Unsupported event! It is not TouchEvent and also not MouseEvent"
312
- ), s;
313
- const { delayKey: n, epsilonKey: o } = e ? { delayKey: "touchDragDelay", epsilonKey: "touchDragEpsilon" } : { delayKey: "customDragDelay", epsilonKey: "customDragEpsilon" };
314
- return typeof t[n] == "number" && (s.delay = t.touchDragDelay), typeof t[o] == "number" && (s.epsilon = t.touchDragEpsilon), s;
315
- }, ot = (r) => {
316
- let t = "", e = Q, s = Z;
317
- if (!r)
318
- return { url: b, width: e, height: s };
319
- const n = r;
320
- if (n instanceof HTMLElement) {
321
- const o = n.getBoundingClientRect(), i = n.getAttribute("data-rml-ghost-url"), l = n.getAttribute("data-rml-ghost-width"), _ = n.getAttribute("data-rml-ghost-height");
322
- i ? t = i : !i && n instanceof HTMLImageElement && n.src && (t = n.src), t ? (e = o.width, s = o.height) : t = b, e = l ? parseInt(l, 10) : e, s = _ ? parseInt(_, 10) : s;
323
- }
324
- return { url: t || b, width: e, height: s };
325
- };
326
- class ct {
327
- constructor(t, e, s) {
328
- a(this, "_options", {});
329
- a(this, "_instance");
330
- a(this, "_viewName");
331
- a(this, "_currentCustomDrag", null);
332
- a(this, "_currentBb", null);
333
- a(this, "_startTarget", null);
334
- a(this, "_onBeforeUpdateDrag", () => ({}));
335
- a(this, "isDragging", !1);
336
- this._instance = t, this._options = e || {}, this._viewName = s;
337
- }
338
- beforeUpdateGhost(t) {
339
- this._onBeforeUpdateDrag = t;
340
- }
341
- async _dragStart(t, e, s = "rml_id") {
342
- this._startTarget && (this._startTarget.style.pointerEvents = "none", this._startTarget.style.userSelect = "none", this._startTarget.setAttribute(
343
- x,
344
- this._startTarget.draggable.toString()
345
- ), this._startTarget.draggable = !1, this._startTarget.removeEventListener("dragstart", C), this._startTarget.addEventListener("dragstart", C)), this._currentBb = await this._instance.getBoundingClientRect(
346
- rt(this._viewName)
347
- );
348
- const { clientX: n, clientY: o } = D(e), i = this._currentBb.x + n, l = this._currentBb.y + o;
349
- this.isDragging = !0, this._instance.dragInObject(t, i, l, s);
350
- }
351
- _dragUpdate(t) {
352
- if (document.body.focus(), this._currentCustomDrag && this._currentCustomDrag.onMove(t), !this._currentBb || !this.isDragging)
353
- return;
354
- const { clientX: e, clientY: s } = D(t), { url: n, width: o, height: i } = ot(this._startTarget), l = this._currentBb.x + e, _ = this._currentBb.y + s, c = {
355
- ghost: {
356
- visibleIn: {
357
- x: this._currentBb.x - this._options.dragInOverlapX || 0,
358
- y: this._currentBb.y + this._options.dragInOverlapY || 0,
359
- width: this._currentBb.width + this._options.dragInOverlapX,
360
- height: this._currentBb.height + this._options.dragInOverlapY
361
- },
362
- url: n,
363
- width: o,
364
- height: i
365
- }
366
- }, {
367
- x: h,
368
- y: u,
369
- options: g
370
- } = this._onBeforeUpdateDrag(l, _, c), d = typeof h == "number" ? h : l, f = typeof u == "number" ? u : _, p = g || c;
371
- this._instance.updateDrag(d, f, p);
372
- }
373
- _dragEnd() {
374
- this._currentCustomDrag && this._currentCustomDrag.onEnd(), this._currentCustomDrag = null, this.isDragging = !1, this._currentBb = null, this._resetStartTarget(), this._instance.dragInObjectEnd();
375
- }
376
- dragStart(t, e, s) {
377
- this._startTarget = e.target;
378
- const n = (o, i) => {
379
- this._dragStart(t, i, s);
380
- };
381
- this._currentCustomDrag = m(e) ? new z(
382
- at,
383
- {
384
- onTouchDragStart: n
385
- },
386
- R(e, this._options)
387
- ) : new it(
388
- {
389
- onCustomDragStart: (o) => this._dragStart(t, o, s)
390
- },
391
- R(e, this._options)
392
- ), this._currentCustomDrag.onStart(e);
393
- }
394
- dragEnd() {
395
- this._dragEnd();
396
- }
397
- dragUpdate(t) {
398
- this._dragUpdate(t);
399
- }
400
- touchStart(t, e, s = "rml_id") {
401
- this.dragStart(t, e, s);
402
- }
403
- touchMove(t) {
404
- this.dragUpdate(t);
405
- }
406
- touchEnd() {
407
- this.dragEnd();
408
- }
409
- dispose() {
410
- }
411
- _resetStartTarget() {
412
- this._startTarget && (this._startTarget.style.pointerEvents = "", this._startTarget.style.userSelect = "", this._startTarget.draggable = this._startTarget.getAttribute(x) === "true", this._startTarget.removeAttribute(x), this._startTarget.removeEventListener("dragstart", C));
413
- }
414
- releaseInput(t) {
415
- this._currentCustomDrag && this._currentCustomDrag.onEnd(), this._resetStartTarget();
416
- }
417
- }
418
- class ht extends K {
419
- constructor(e, s, n, o) {
420
- super(e, s, n, o);
421
- a(this, "options", {});
422
- a(this, "_strategy");
423
- a(this, "_customDragSignal", new AbortController());
424
- if (this._mainDomElement = s, n === "website")
425
- this._strategy = new st(
426
- e,
427
- s,
428
- this.options
429
- );
430
- else if (n === "custom-view")
431
- this._strategy = new ct(
432
- e,
433
- this.options,
434
- this._viewName
435
- );
436
- else
437
- throw new Error("Unsupported mode");
438
- this._injectStyles(), this._initializeDragGhost();
439
- }
440
- _injectStyles() {
441
- if (!!!document.getElementById(O)) {
442
- const s = document.createElement("style");
443
- s.type = "text/css", s.id = O, s.innerHTML = `
444
- .${w.DISPLAY_NONE}{display:none}
445
- .${y}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
446
- .${T}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
447
- ${q}
448
- ${V}
449
- `, document.head.appendChild(s);
450
- }
451
- }
452
- _initializeDragGhost() {
453
- const e = this._mainDomElement.parentNode;
454
- let s = e.querySelector(
455
- "." + T
456
- );
457
- s || (s = document.createElement("div"), s.classList.add(T), s.innerText = " ", e.appendChild(s));
458
- }
459
- get isDragging() {
460
- return this._strategy.isDragging;
461
- }
462
- dragStart(e, s, n = "rml_id") {
463
- this._strategy.dragStart(e, s, n);
464
- }
465
- dragUpdate(e) {
466
- this._strategy.dragUpdate(e);
467
- }
468
- dragEnd() {
469
- this._strategy.dragEnd();
470
- }
471
- touchStart(e, s, n = "rml_id") {
472
- this._strategy.touchStart(e, s, n);
473
- }
474
- touchMove(e) {
475
- this._strategy.touchMove(e);
476
- }
477
- touchEnd() {
478
- this._strategy.touchEnd();
479
- }
480
- dispose() {
481
- this._strategy.dispose();
482
- }
483
- beforeUpdateGhost(e) {
484
- this._strategy.beforeUpdateGhost(e);
485
- }
486
- registerCustomDrag({
487
- customDragStart: e,
488
- customDragEnd: s,
489
- customDragUpdate: n,
490
- beforeUpdateGhost: o
491
- }) {
492
- o && this._strategy.beforeUpdateGhost(o);
493
- const i = this._customDragSignal.signal, l = (h) => {
494
- h.target.getAttribute("data-rml-draggable") === "true" && e(h);
495
- }, _ = (h) => {
496
- this._strategy.releaseInput(h), this._strategy.isDragging && s(h);
497
- }, c = (h) => {
498
- n(h);
499
- };
500
- document.querySelectorAll('[data-rml-draggable="true"]').forEach((h) => {
501
- h.draggable = !1;
502
- }), document.addEventListener("mousedown", l, { signal: i }), document.addEventListener("mouseup", _, { signal: i }), document.addEventListener("mousemove", c, { signal: i }), document.addEventListener("mouseleave", _, { signal: i }), document.addEventListener("touchstart", l, { signal: i }), document.addEventListener("touchend", _, { signal: i }), document.addEventListener("touchmove", c, { signal: i });
503
- }
504
- unregisterCustomDrag() {
505
- this._customDragSignal.abort(), this._customDragSignal = new AbortController();
506
- }
507
- releaseInput(e) {
508
- this._strategy.releaseInput(e);
509
- }
510
- }
511
- export {
512
- ht as DragIn
513
- };
@@ -1,7 +0,0 @@
1
- var G=Object.defineProperty,q=(s,t,e)=>t in s?G(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,a=(s,t,e)=>q(s,typeof t!="symbol"?t+"":t,e);class H{constructor(t,e,i,n){a(this,"_mainDomElement"),a(this,"_instance",null),a(this,"_mode","website"),a(this,"_viewName","main"),this._instance=t,this._mainDomElement=e,this._mode=i,this._viewName=n}}const Y="rml-drag-in-styles",K="rml-drag-in-drag-element",y="rml-drag-in-overlay",D="rml-drag-in-drag-ghost",L="rml-drag-in-fade-in",M="rml-drag-in-fade-out",E={DISPLAY_NONE:"rml-display-none"},U=.5,O="250ms",B="forwards",R=`@keyframes ${L} {from{opacity: 0;}to {opacity: ${U};}}`,J=`@keyframes ${M} {from{opacity: ${U};}to {opacity: 0;}}`,N=`${L} ${O} ${B}`,Q=`${M} ${O} ${B}`,T="https://res.cloudinary.com/roomle/image/upload/v1729679975/fallback_afpyqr.jpg",V=112,Z=112;class tt{constructor(t=16){a(this,"_computedStyleCache",new Map),a(this,"_maxLifetime",16),a(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 n=getComputedStyle(t);return this._computedStyleCache.set(t,{style:n,updated:i}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),n}_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 _=s=>window.TouchEvent&&s instanceof window.TouchEvent;let w;const v=s=>(w||(w=new tt),w.get(s)),$=(s,t,e)=>{const i=parseFloat(s),n=window.devicePixelRatio||1;if(t==="px")return i;if(t==="%"){const h=e===document.documentElement?window.innerWidth:e.offsetWidth;return i/100*h}if(t==="rem"){const h=parseFloat(v(document.documentElement).fontSize);return i*h}if(t==="em"){const h=parseFloat(v(e).fontSize);return i*h}if(t==="vh"||t==="vw"||t==="vmin"||t==="vmax"){const h={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return i/100*h[t]}const r={cm:37.7952755906,mm:3.77952755906,in:96};return t in r?i*r[t]*n:(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)},P=(s,t,e={x:0,y:0})=>{const i=s.getBoundingClientRect(),n=v(s).transform;let r=0,h=0;if(n!=="none"){const u=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,g=n.match(u);g&&(r=$(g[1],g[2],s),h=$(g[3],g[4],s))}const{clientX:o,clientY:c}=f(t,e),l=o-i.left-r+s.scrollLeft,d=c-i.top-h+s.scrollTop;return{x:l,y:d}},f=(s,t=null)=>{const{clientX:e,clientY:i}=_(s)?et(s):s,n=e>0?e:t?t.x:e,r=i>0?i:t?t.y:i;return{clientX:n,clientY:r}},et=s=>{if(s.touches.length){let{clientX:e,clientY:i}=s.touches[0];if(s.touches.length>1){const n=s.touches[1],r=n.clientX,h=n.clientY;e=(e+r)/2,i=(i+h)/2}return{clientX:e,clientY:i}}const t=s.changedTouches[0];return{clientX:t.clientX,clientY:t.clientY}},S=500,x=10,A=100,k=15,C=(s,t=0)=>_(s)?{clientX:s.touches[t].clientX,clientY:s.touches[t].clientY}:{clientX:s.clientX,clientY:s.clientY},W=s=>s&&_(s)?s.touches.length>0:!0;class z{constructor(t,{onTouchDragStart:e},i={}){a(this,"_touchDragTimeOut"),a(this,"_onTouchDragStart"),a(this,"_payload",null),a(this,"_delay",S),a(this,"_firstTouch",null),a(this,"_lastTouch",null),a(this,"_epsilon",x),this._payload=t,this._onTouchDragStart=e,this._delay=typeof i.delay=="number"?i.delay:S,this._epsilon=typeof i.epsilon=="number"?i.epsilon:x}onStart(t){W(t)&&(this._touchDragTimeOut||(this._firstTouch=C(t,_(t)?t.touches.length-1:0),this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=C(t)),this._checkXDistance(t)()},this._delay)))}onEnd(){this._resetTouches()}onMove(t){W(t)&&(this._lastTouch=C(t))}_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 it{constructor(t,e,i){a(this,"_options",{}),a(this,"_instance"),a(this,"_mainDomElement"),a(this,"_currentDrag",{}),a(this,"_currentTouch",null),a(this,"_firefoxDragPosition",{x:0,y:0}),a(this,"isDragging",!1),a(this,"_firefoxFallback",n=>{if(!this._currentDrag.event)return;const r=n||window.event;this._firefoxDragPosition.x=r.pageX||0,this._firefoxDragPosition.y=r.pageY||0}),this._instance=t,this._mainDomElement=e,this._options=i||{},this._firefoxFallback=this._firefoxFallback.bind(this),document.addEventListener("dragover",this._firefoxFallback)}beforeUpdateGhost(t){}dragStart(t,e,i="rml_id"){const n=this._mainDomElement.parentNode;if(v(n).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 r=n.querySelector("."+y);r||(r=document.createElement("div"),r.classList.add(y),n.appendChild(r)),r.classList.remove(E.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`);const h=n.querySelector("."+D);this._currentDrag.event=e;const o=e.target.cloneNode();o.style.position="fixed",o.style.pointerEvents="none",o.style.opacity="0",o.style.animation=N,o.id=K,o.style.zIndex="9999",document.body.appendChild(o),this._currentDrag.element=o;const c=e.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0});const{clientX:l,clientY:d}=f(e,this._firefoxDragPosition);this._currentDrag.offset.x=l-c.left,this._currentDrag.offset.y=d-c.top,o.style.top=d+"px",o.style.left=l+"px",e instanceof DragEvent&&e.dataTransfer&&e.dataTransfer.setDragImage&&e.dataTransfer.setDragImage(h,0,0);const{x:u,y:g}=P(n,this._currentDrag.event||e,this._firefoxDragPosition),m=Math.max(1,u),p=Math.max(1,g);this.isDragging=!0,this._instance.dragInObject(t,m,p,i)}dragUpdate(t){var e,i;const n=this._mainDomElement.parentNode,{x:r,y:h}=P(n,t,this._firefoxDragPosition);if(r===0&&h===0)return;const o=Math.max(1,r),c=Math.max(1,h);if(this._currentDrag.element){const{clientX:u,clientY:g}=f(t,this._firefoxDragPosition),m=((e=this._currentDrag.offset)==null?void 0:e.x)||0,p=((i=this._currentDrag.offset)==null?void 0:i.y)||0;this._currentDrag.element.style.left=`${u-m}px`,this._currentDrag.element.style.top=`${g-p}px`;const b=(this._options.dragInOverlapX||0)+1,F=(this._options.dragInOverlapY||0)+1;o>b&&c>F?this._currentDrag.element.style.animation=Q:this._currentDrag.element.style.animation=N}if(o===1&&c===1)return;let l=o,d=c;if(_(t)){const u=this._options.fingerSize||0;l=Math.max(2,o+u),d=Math.max(2,c-u)}this._instance.updateDrag(l,d)}dragEnd(){this._mainDomElement.style.pointerEvents="all";const t=this._mainDomElement.parentNode;this.isDragging=!1,this._instance.dragInObjectEnd(),this._currentDrag.element&&document.body.removeChild(this._currentDrag.element),this._currentDrag={},this._firefoxDragPosition={x:0,y:0};const e=t.querySelector("."+y);e&&e.classList.add(E.DISPLAY_NONE)}touchStart(t,e,i="rml_id"){var n,r;e.preventDefault();const h=(c,l)=>{this.dragStart(t,l,i)},o={};typeof((n=this._options)==null?void 0:n.touchDragDelay)=="number"&&(o.delay=this._options.touchDragDelay),(r=this._options)!=null&&r.touchDragEpsilon&&(o.epsilon=this._options.touchDragEpsilon),this._currentTouch=new z(void 0,{onTouchDragStart:h},o),this._currentTouch.onStart(e)}touchMove(t){this._currentTouch&&this._currentTouch.onMove(t),this._currentDrag.event&&this.dragUpdate(t)}touchEnd(){this._currentTouch&&this._currentTouch.onEnd(),this._currentTouch=null,this.dragEnd()}dispose(){document.removeEventListener("dragover",this._firefoxFallback)}releaseInput(t){}}const st=s=>`[data-rml-custom-view="${s}"]`,I=s=>{s.preventDefault(),s.stopPropagation()},nt=(s,t,e,i)=>{const n=e-s,r=i-t;return Math.sqrt(n*n+r*r)};class rt{constructor({onCustomDragStart:t},e={}){a(this,"_startX",0),a(this,"_startY",0),a(this,"_lastX",0),a(this,"_lastY",0),a(this,"_delay"),a(this,"_epsilon"),a(this,"_isStarted",!1),a(this,"_isEnded",!1),a(this,"_isWaiting",!1),a(this,"_onCustomDragStart"),this._delay=typeof e.delay=="number"?e.delay:A,this._epsilon=typeof e.epsilon=="number"?e.epsilon:k,this._onCustomDragStart=t}onMove(t){this._lastX=t.clientX,this._lastY=t.clientY,this._isWaiting&&nt(this._startX,this._startY,this._lastX,this._lastY)>this._epsilon&&(this._onCustomDragStart(t),this._isWaiting=!1)}onStart(t){this._startX=t.clientX,this._startY=t.clientY,this.onMove(t),this._isWaiting=!0}onEnd(){this._reset()}_reset(){this._startX=0,this._startY=0,this._lastX=0,this._lastY=0,this._isWaiting=!1}}const X="data-rml-old-draggable",at=void 0,j=(s,t)=>{const e=_(s),i={delay:e?S:A,epsilon:e?x:k};if(!t)return i;if(!e&&!(s instanceof MouseEvent))return console.warn("Unsupported event! It is not TouchEvent and also not MouseEvent"),i;const{delayKey:n,epsilonKey:r}=e?{delayKey:"touchDragDelay",epsilonKey:"touchDragEpsilon"}:{delayKey:"customDragDelay",epsilonKey:"customDragEpsilon"};return typeof t[n]=="number"&&(i.delay=t.touchDragDelay),typeof t[r]=="number"&&(i.epsilon=t.touchDragEpsilon),i},ot=s=>{let t="",e=V,i=Z;if(!s)return{url:T,width:e,height:i};const n=s;if(n instanceof HTMLElement){const r=n.getBoundingClientRect(),h=n.getAttribute("data-rml-ghost-url"),o=n.getAttribute("data-rml-ghost-width"),c=n.getAttribute("data-rml-ghost-height");h?t=h:!h&&n instanceof HTMLImageElement&&n.src&&(t=n.src),t?(e=r.width,i=r.height):t=T,e=o?parseInt(o,10):e,i=c?parseInt(c,10):i}return{url:t||T,width:e,height:i}};class ht{constructor(t,e,i){a(this,"_options",{}),a(this,"_instance"),a(this,"_viewName"),a(this,"_currentCustomDrag",null),a(this,"_currentBb",null),a(this,"_startTarget",null),a(this,"_onBeforeUpdateDrag",()=>({})),a(this,"isDragging",!1),this._instance=t,this._options=e||{},this._viewName=i}beforeUpdateGhost(t){this._onBeforeUpdateDrag=t}async _dragStart(t,e,i="rml_id"){this._startTarget&&(this._startTarget.style.pointerEvents="none",this._startTarget.style.userSelect="none",this._startTarget.setAttribute(X,this._startTarget.draggable.toString()),this._startTarget.draggable=!1,this._startTarget.removeEventListener("dragstart",I),this._startTarget.addEventListener("dragstart",I)),this._currentBb=await this._instance.getBoundingClientRect(st(this._viewName));const{clientX:n,clientY:r}=f(e),h=this._currentBb.x+n,o=this._currentBb.y+r;this.isDragging=!0,this._instance.dragInObject(t,h,o,i)}_dragUpdate(t){if(document.body.focus(),this._currentCustomDrag&&this._currentCustomDrag.onMove(t),!this._currentBb||!this.isDragging)return;const{clientX:e,clientY:i}=f(t),{url:n,width:r,height:h}=ot(this._startTarget),o=this._currentBb.x+e,c=this._currentBb.y+i,l={ghost:{visibleIn:{x:this._currentBb.x-this._options.dragInOverlapX||0,y:this._currentBb.y+this._options.dragInOverlapY||0,width:this._currentBb.width+this._options.dragInOverlapX,height:this._currentBb.height+this._options.dragInOverlapY},url:n,width:r,height:h}},{x:d,y:u,options:g}=this._onBeforeUpdateDrag(o,c,l),m=typeof d=="number"?d:o,p=typeof u=="number"?u:c,b=g||l;this._instance.updateDrag(m,p,b)}_dragEnd(){this._currentCustomDrag&&this._currentCustomDrag.onEnd(),this._currentCustomDrag=null,this.isDragging=!1,this._currentBb=null,this._resetStartTarget(),this._instance.dragInObjectEnd()}dragStart(t,e,i){this._startTarget=e.target;const n=(r,h)=>{this._dragStart(t,h,i)};this._currentCustomDrag=_(e)?new z(at,{onTouchDragStart:n},j(e,this._options)):new rt({onCustomDragStart:r=>this._dragStart(t,r,i)},j(e,this._options)),this._currentCustomDrag.onStart(e)}dragEnd(){this._dragEnd()}dragUpdate(t){this._dragUpdate(t)}touchStart(t,e,i="rml_id"){this.dragStart(t,e,i)}touchMove(t){this.dragUpdate(t)}touchEnd(){this.dragEnd()}dispose(){}_resetStartTarget(){this._startTarget&&(this._startTarget.style.pointerEvents="",this._startTarget.style.userSelect="",this._startTarget.draggable=this._startTarget.getAttribute(X)==="true",this._startTarget.removeAttribute(X),this._startTarget.removeEventListener("dragstart",I))}releaseInput(t){this._currentCustomDrag&&this._currentCustomDrag.onEnd(),this._resetStartTarget()}}class lt extends H{constructor(t,e,i,n){if(super(t,e,i,n),a(this,"options",{}),a(this,"_strategy"),a(this,"_customDragSignal",new AbortController),this._mainDomElement=e,i==="website")this._strategy=new it(t,e,this.options);else if(i==="custom-view")this._strategy=new ht(t,this.options,this._viewName);else throw new Error("Unsupported mode");this._injectStyles(),this._initializeDragGhost()}_injectStyles(){if(!document.getElementById(Y)){const t=document.createElement("style");t.type="text/css",t.id=Y,t.innerHTML=`
2
- .${E.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
- ${R}
6
- ${J}
7
- `,document.head.appendChild(t)}}_initializeDragGhost(){const t=this._mainDomElement.parentNode;let e=t.querySelector("."+D);e||(e=document.createElement("div"),e.classList.add(D),e.innerText=" ",t.appendChild(e))}get isDragging(){return this._strategy.isDragging}dragStart(t,e,i="rml_id"){this._strategy.dragStart(t,e,i)}dragUpdate(t){this._strategy.dragUpdate(t)}dragEnd(){this._strategy.dragEnd()}touchStart(t,e,i="rml_id"){this._strategy.touchStart(t,e,i)}touchMove(t){this._strategy.touchMove(t)}touchEnd(){this._strategy.touchEnd()}dispose(){this._strategy.dispose()}beforeUpdateGhost(t){this._strategy.beforeUpdateGhost(t)}registerCustomDrag({customDragStart:t,customDragEnd:e,customDragUpdate:i,beforeUpdateGhost:n}){n&&this._strategy.beforeUpdateGhost(n);const r=this._customDragSignal.signal,h=l=>{l.target.getAttribute("data-rml-draggable")==="true"&&t(l)},o=l=>{this._strategy.releaseInput(l),this._strategy.isDragging&&e(l)},c=l=>{i(l)};document.querySelectorAll('[data-rml-draggable="true"]').forEach(l=>{l.draggable=!1}),document.addEventListener("mousedown",h,{signal:r}),document.addEventListener("mouseup",o,{signal:r}),document.addEventListener("mousemove",c,{signal:r}),document.addEventListener("mouseleave",o,{signal:r}),document.addEventListener("touchstart",h,{signal:r}),document.addEventListener("touchend",o,{signal:r}),document.addEventListener("touchmove",c,{signal:r})}unregisterCustomDrag(){this._customDragSignal.abort(),this._customDragSignal=new AbortController}releaseInput(t){this._strategy.releaseInput(t)}}export{lt as DragIn};