@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
package/drag-in-Dq8ixDxG.mjs
DELETED
|
@@ -1,323 +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 c = (n, t, e) => k(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
class U {
|
|
5
|
-
constructor(t = 16) {
|
|
6
|
-
c(this, "_computedStyleCache", /* @__PURE__ */ new Map());
|
|
7
|
-
c(this, "_maxLifetime", 16);
|
|
8
|
-
c(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 o = getComputedStyle(t);
|
|
16
|
-
return this._computedStyleCache.set(t, { style: o, updated: i }), this._cacheCleanInterval || (this._cacheCleanInterval = setInterval(
|
|
17
|
-
() => this._cleanUpCache,
|
|
18
|
-
Math.max(this._maxLifetime * 1e3, 5e3)
|
|
19
|
-
)), o;
|
|
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 F = (n) => window.TouchEvent && n instanceof window.TouchEvent;
|
|
29
|
-
let N;
|
|
30
|
-
const C = (n) => (N || (N = new U()), N.get(n)), O = (n, t, e) => {
|
|
31
|
-
const i = parseFloat(n), o = window.devicePixelRatio || 1;
|
|
32
|
-
if (t === "px")
|
|
33
|
-
return i;
|
|
34
|
-
if (t === "%") {
|
|
35
|
-
const s = e === document.documentElement ? window.innerWidth : e.offsetWidth;
|
|
36
|
-
return i / 100 * s;
|
|
37
|
-
}
|
|
38
|
-
if (t === "rem") {
|
|
39
|
-
const s = parseFloat(
|
|
40
|
-
C(document.documentElement).fontSize
|
|
41
|
-
);
|
|
42
|
-
return i * s;
|
|
43
|
-
}
|
|
44
|
-
if (t === "em") {
|
|
45
|
-
const s = parseFloat(
|
|
46
|
-
C(e).fontSize
|
|
47
|
-
);
|
|
48
|
-
return i * s;
|
|
49
|
-
}
|
|
50
|
-
if (t === "vh" || t === "vw" || t === "vmin" || t === "vmax") {
|
|
51
|
-
const s = {
|
|
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 * s[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] * o : (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
|
-
}, R = (n, t, e = { x: 0, y: 0 }) => {
|
|
68
|
-
const i = n.getBoundingClientRect(), a = C(n).transform;
|
|
69
|
-
let s = 0, l = 0;
|
|
70
|
-
if (a !== "none") {
|
|
71
|
-
const g = /translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/, d = a.match(g);
|
|
72
|
-
d && (s = O(d[1], d[2], n), l = O(d[3], d[4], n));
|
|
73
|
-
}
|
|
74
|
-
const { clientX: h, clientY: u } = E(t, e), r = h - i.left - s + n.scrollLeft, _ = u - i.top - l + n.scrollTop;
|
|
75
|
-
return { x: r, y: _ };
|
|
76
|
-
}, E = (n, t) => {
|
|
77
|
-
const { clientX: e, clientY: i } = F(n) ? H(n) : n, o = e > 0 ? e : t.x, a = i > 0 ? i : t.y;
|
|
78
|
-
return { clientX: o, clientY: a };
|
|
79
|
-
}, H = (n) => {
|
|
80
|
-
if (n.touches.length) {
|
|
81
|
-
let { clientX: e, clientY: i } = n.touches[0];
|
|
82
|
-
if (n.touches.length > 1) {
|
|
83
|
-
const o = n.touches[1], a = o.clientX, s = o.clientY;
|
|
84
|
-
e = (e + a) / 2, i = (i + s) / 2;
|
|
85
|
-
}
|
|
86
|
-
return { clientX: e, clientY: i };
|
|
87
|
-
}
|
|
88
|
-
const t = n.changedTouches[0];
|
|
89
|
-
return { clientX: t.clientX, clientY: t.clientY };
|
|
90
|
-
}, B = (n, t) => {
|
|
91
|
-
const e = t.x + t.width, i = t.x, o = t.y + t.height, a = t.y, { x: s, y: l } = n;
|
|
92
|
-
return s >= i && s <= e && l >= a && l <= o;
|
|
93
|
-
}, Y = 500, X = 10;
|
|
94
|
-
class V {
|
|
95
|
-
constructor(t, { onTouchDragStart: e }, i = {}) {
|
|
96
|
-
c(this, "_touchDragTimeOut");
|
|
97
|
-
c(this, "_onTouchDragStart");
|
|
98
|
-
c(this, "_payload", null);
|
|
99
|
-
c(this, "_delay", Y);
|
|
100
|
-
c(this, "_firstTouch", null);
|
|
101
|
-
c(this, "_lastTouch", null);
|
|
102
|
-
c(this, "_epsilon", X);
|
|
103
|
-
this._payload = t, this._onTouchDragStart = e, this._delay = i.delay || Y, this._epsilon = i.epsilon || X;
|
|
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 W {
|
|
136
|
-
constructor() {
|
|
137
|
-
c(this, "_instance", null);
|
|
138
|
-
c(this, "_mode", "website");
|
|
139
|
-
c(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 $ = "rml-drag-in-styles", j = "rml-drag-in-drag-element", w = "rml-drag-in-overlay", S = "rml-drag-in-drag-ghost", A = "rml-drag-in-fade-in", P = "rml-drag-in-fade-out", b = {
|
|
152
|
-
DISPLAY_NONE: "rml-display-none"
|
|
153
|
-
}, G = 0.5, v = "250ms", M = "forwards", x = (n) => n ? !0 : (console.warn("No instance set, cancel drag-in"), !1);
|
|
154
|
-
class J extends W {
|
|
155
|
-
constructor(e) {
|
|
156
|
-
super();
|
|
157
|
-
c(this, "_mainDomElement");
|
|
158
|
-
c(this, "_currentDrag", {});
|
|
159
|
-
c(this, "_currentTouch", null);
|
|
160
|
-
c(this, "_firefoxDragPosition", { x: 0, y: 0 });
|
|
161
|
-
c(this, "options", {});
|
|
162
|
-
c(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._mainDomElement = e, this._injectStyles(), this._initializeDragGhost(), this._firefoxFallback = this._firefoxFallback.bind(this), document.addEventListener("dragover", this._firefoxFallback);
|
|
169
|
-
}
|
|
170
|
-
_injectStyles() {
|
|
171
|
-
if (!!!document.getElementById($)) {
|
|
172
|
-
const i = document.createElement("style");
|
|
173
|
-
i.type = "text/css", i.id = $, i.innerHTML = `
|
|
174
|
-
.${b.DISPLAY_NONE}{display:none}
|
|
175
|
-
.${w}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
|
|
176
|
-
.${S}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
|
|
177
|
-
@keyframes ${A} {from{opacity: 0;}to {opacity: ${G};}}
|
|
178
|
-
@keyframes ${P} {from{opacity: ${G};}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
|
-
"." + S
|
|
186
|
-
);
|
|
187
|
-
i || (i = document.createElement("div"), i.classList.add(S), i.innerText = " ", e.appendChild(i));
|
|
188
|
-
}
|
|
189
|
-
setInstance(e) {
|
|
190
|
-
this._instance = e;
|
|
191
|
-
}
|
|
192
|
-
setMode(e) {
|
|
193
|
-
this._mode = e;
|
|
194
|
-
}
|
|
195
|
-
async dragStart(e, i, o = "rml_id") {
|
|
196
|
-
const a = this._mainDomElement.parentNode, s = a.querySelector(
|
|
197
|
-
"." + S
|
|
198
|
-
);
|
|
199
|
-
if (i instanceof DragEvent && i.dataTransfer && i.dataTransfer.setDragImage && i.dataTransfer.setDragImage(s, 0, 0), this._mode === "custom-view" && x(this._instance)) {
|
|
200
|
-
const f = await this._instance.getBoundingClientRect("iframe"), m = this.options.domContainer;
|
|
201
|
-
if (!m)
|
|
202
|
-
throw new Error("No container set, can not expand custom view");
|
|
203
|
-
m.style.position = "absolute", m.style.top = `${f.top}px`, m.style.left = `${f.left}px`, m.style.width = `${f.width}px`, m.style.height = `${f.height}px`, await this._instance.expandCustomView(this._viewName);
|
|
204
|
-
}
|
|
205
|
-
const l = C(a);
|
|
206
|
-
if (this._mode === "website" && l.position !== "relative") {
|
|
207
|
-
console.warn(
|
|
208
|
-
"Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly"
|
|
209
|
-
);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
this._mainDomElement.style.pointerEvents = "none";
|
|
213
|
-
let h = a.querySelector(
|
|
214
|
-
"." + w
|
|
215
|
-
);
|
|
216
|
-
h || (h = document.createElement("div"), h.classList.add(w), a.appendChild(h)), h.classList.remove(b.DISPLAY_NONE), i.target.getAttribute("draggable") || console.warn(
|
|
217
|
-
`Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`
|
|
218
|
-
), this._currentDrag.event = i;
|
|
219
|
-
const r = i.target.cloneNode();
|
|
220
|
-
r.style.position = "fixed", r.style.pointerEvents = "none", r.style.opacity = "0", r.style.animation = `${A} ${v} ${M}`, r.id = j, r.style.zIndex = "9999", document.body.appendChild(r), this._currentDrag.element = r;
|
|
221
|
-
const _ = i.target.getBoundingClientRect();
|
|
222
|
-
this._currentDrag.offset || (this._currentDrag.offset = { x: 0, y: 0 });
|
|
223
|
-
const { clientX: g, clientY: d } = E(
|
|
224
|
-
i,
|
|
225
|
-
this._firefoxDragPosition
|
|
226
|
-
);
|
|
227
|
-
this._currentDrag.offset.x = this._mode === "website" ? g - _.left : _.width / 2, this._currentDrag.offset.y = this._mode === "website" ? d - _.top : _.height / 2, r.style.top = d + "px", r.style.left = g + "px";
|
|
228
|
-
const { x: p, y } = R(
|
|
229
|
-
a,
|
|
230
|
-
this._currentDrag.event || i,
|
|
231
|
-
this._firefoxDragPosition
|
|
232
|
-
), I = Math.max(1, p), D = Math.max(1, y);
|
|
233
|
-
x(this._instance) && this._instance.dragInObject(e, I, D, o);
|
|
234
|
-
}
|
|
235
|
-
dragUpdate(e) {
|
|
236
|
-
var _, g;
|
|
237
|
-
const { clientX: i, clientY: o } = E(
|
|
238
|
-
e,
|
|
239
|
-
this._firefoxDragPosition
|
|
240
|
-
), a = i <= 0 || o <= 0;
|
|
241
|
-
if (this._mode === "custom-view" && a)
|
|
242
|
-
return;
|
|
243
|
-
const s = this._mainDomElement.parentNode, { x: l, y: h } = R(s, e, this._firefoxDragPosition);
|
|
244
|
-
if (l === 0 && h === 0)
|
|
245
|
-
return;
|
|
246
|
-
const u = Math.max(1, l), r = Math.max(1, h);
|
|
247
|
-
if (this._currentDrag.element) {
|
|
248
|
-
const { clientX: d, clientY: p } = E(
|
|
249
|
-
e,
|
|
250
|
-
this._firefoxDragPosition
|
|
251
|
-
), y = ((_ = this._currentDrag.offset) == null ? void 0 : _.x) || 0, I = ((g = this._currentDrag.offset) == null ? void 0 : g.y) || 0;
|
|
252
|
-
this._currentDrag.element.style.left = `${d - y}px`, this._currentDrag.element.style.top = `${p - I}px`;
|
|
253
|
-
const D = (this.options.dragInOverlapX || 0) + 1, f = (this.options.dragInOverlapY || 0) + 1;
|
|
254
|
-
let m = u > D && r > f;
|
|
255
|
-
if (this._mode === "custom-view") {
|
|
256
|
-
const L = this.options.domContainer;
|
|
257
|
-
if (!L)
|
|
258
|
-
throw new Error("No container set, can not fade in/out drag ghost");
|
|
259
|
-
const T = L.getBoundingClientRect();
|
|
260
|
-
m = !B(
|
|
261
|
-
{ x: u, y: r },
|
|
262
|
-
{
|
|
263
|
-
x: T.left - D,
|
|
264
|
-
y: T.top - f,
|
|
265
|
-
width: T.width + D,
|
|
266
|
-
height: T.height + f
|
|
267
|
-
}
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
m ? this._currentDrag.element.style.animation = `${P} ${v} ${M}` : this._currentDrag.element.style.animation = `${A} ${v} ${M}`;
|
|
271
|
-
}
|
|
272
|
-
if (!(u === 1 && r === 1) && x(this._instance)) {
|
|
273
|
-
let d = u, p = r;
|
|
274
|
-
if (F(e)) {
|
|
275
|
-
const y = this.options.fingerSize || 0;
|
|
276
|
-
d = Math.max(2, u + y), p = Math.max(2, r - y);
|
|
277
|
-
}
|
|
278
|
-
this._instance.updateDrag(d, p);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
async dragEnd() {
|
|
282
|
-
if (x(this._instance) && this._mode === "custom-view") {
|
|
283
|
-
await this._instance.collapseCustomView(this._viewName);
|
|
284
|
-
const o = this.options.domContainer;
|
|
285
|
-
if (!o)
|
|
286
|
-
throw new Error("No container set, can not collapse custom view");
|
|
287
|
-
o.style.position = "", o.style.top = "", o.style.left = "", o.style.width = "", o.style.height = "";
|
|
288
|
-
}
|
|
289
|
-
this._mainDomElement.style.pointerEvents = "all";
|
|
290
|
-
const e = this._mainDomElement.parentNode;
|
|
291
|
-
x(this._instance) && this._instance.dragInObjectEnd(), this._currentDrag.element && document.body.removeChild(this._currentDrag.element), this._currentDrag = {}, this._firefoxDragPosition = { x: 0, y: 0 };
|
|
292
|
-
const i = e.querySelector(
|
|
293
|
-
"." + w
|
|
294
|
-
);
|
|
295
|
-
i && i.classList.add(b.DISPLAY_NONE);
|
|
296
|
-
}
|
|
297
|
-
touchStart(e, i, o = "rml_id") {
|
|
298
|
-
var l, h;
|
|
299
|
-
i.preventDefault();
|
|
300
|
-
const a = (u, r) => {
|
|
301
|
-
this.dragStart(e, r, o);
|
|
302
|
-
}, s = {};
|
|
303
|
-
typeof ((l = this.options) == null ? void 0 : l.touchDragDelay) == "number" && (s.delay = this.options.touchDragDelay), (h = this.options) != null && h.touchDragEpsilon && (s.epsilon = this.options.touchDragEpsilon), this._currentTouch = new V(
|
|
304
|
-
void 0,
|
|
305
|
-
{
|
|
306
|
-
onTouchDragStart: a
|
|
307
|
-
},
|
|
308
|
-
s
|
|
309
|
-
), this._currentTouch.onTouchStart(i);
|
|
310
|
-
}
|
|
311
|
-
touchMove(e) {
|
|
312
|
-
this._currentTouch && this._currentTouch.onTouchMove(e), this._currentDrag.event && this.dragUpdate(e);
|
|
313
|
-
}
|
|
314
|
-
touchEnd() {
|
|
315
|
-
this._currentTouch && this._currentTouch.onTouchEnd(), this._currentTouch = null, this.dragEnd();
|
|
316
|
-
}
|
|
317
|
-
dispose() {
|
|
318
|
-
document.removeEventListener("dragover", this._firefoxFallback);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
export {
|
|
322
|
-
J as DragIn
|
|
323
|
-
};
|
package/drag-in-Dq_vb7GH.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
var R=Object.defineProperty,j=(n,t,e)=>t in n?R(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,a=(n,t,e)=>j(n,typeof t!="symbol"?t+"":t,e);class A{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 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 M=n=>window.TouchEvent&&n instanceof window.TouchEvent;let b;const D=n=>(b||(b=new A),b.get(n)),X=(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(D(document.documentElement).fontSize);return i*s}if(t==="em"){const s=parseFloat(D(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 r={cm:37.7952755906,mm:3.77952755906,in:96};return t in r?i*r[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)},Y=(n,t,e={x:0,y:0})=>{const i=n.getBoundingClientRect(),o=D(n).transform;let r=0,s=0;if(o!=="none"){const m=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,l=o.match(m);l&&(r=X(l[1],l[2],n),s=X(l[3],l[4],n))}const{clientX:c,clientY:h}=w(t,e),u=c-i.left-r+n.scrollLeft,d=h-i.top-s+n.scrollTop;return{x:u,y:d}},w=(n,t)=>{const{clientX:e,clientY:i}=M(n)?B(n):n,o=e>0?e:t.x,r=i>0?i:t.y;return{clientX:o,clientY:r}},B=n=>{if(n.touches.length){let{clientX:e,clientY:i}=n.touches[0];if(n.touches.length>1){const o=n.touches[1],r=o.clientX,s=o.clientY;e=(e+r)/2,i=(i+s)/2}return{clientX:e,clientY:i}}const t=n.changedTouches[0];return{clientX:t.clientX,clientY:t.clientY}},U=(n,t)=>{const e=t.x+t.width,i=t.x,o=t.y+t.height,r=t.y,{x:s,y:c}=n;return s>=i&&s<=e&&c>=r&&c<=o},P=500,O=10;class W{constructor(t,{onTouchDragStart:e},i={}){a(this,"_touchDragTimeOut"),a(this,"_onTouchDragStart"),a(this,"_payload",null),a(this,"_delay",P),a(this,"_firstTouch",null),a(this,"_lastTouch",null),a(this,"_epsilon",O),this._payload=t,this._onTouchDragStart=e,this._delay=i.delay||P,this._epsilon=i.epsilon||O}onTouchStart(t){var e;!t||!((e=t?.touches)!=null&&e.length)||this._touchDragTimeOut||(this._firstTouch=t.touches[t.touches.length-1],this._touchDragTimeOut=setTimeout(()=>{this._clearTimeout(),this._lastTouch||(this._lastTouch=t.touches[0]),this._checkXDistance(t)()},this._delay))}onTouchEnd(){this._resetTouches()}onTouchMove(t){var e;!t||!((e=t?.touches)!=null&&e.length)||(this._lastTouch=t.touches[0])}_clearTimeout(){this._touchDragTimeOut&&(clearTimeout(this._touchDragTimeOut),this._touchDragTimeOut=null)}_resetTouches(){this._clearTimeout(),this._lastTouch=null,this._firstTouch=null,this._payload=null}_checkXDistance(t){return()=>{if(!this._firstTouch||!this._lastTouch)return;let e=!1;e=Math.abs(this._firstTouch.clientX-this._lastTouch.clientX)<this._epsilon,e&&(this._onTouchDragStart(this._payload,t),this._resetTouches())}}}class H{constructor(){a(this,"_instance",null),a(this,"_mode","website"),a(this,"_viewName","main")}setInstance(t){this._instance=t}setMode(t){this._mode=t}setViewName(t){this._viewName=t}}const k="rml-drag-in-styles",q="rml-drag-in-drag-element",x="rml-drag-in-overlay",T="rml-drag-in-drag-ghost",S="rml-drag-in-fade-in",z="rml-drag-in-fade-out",C={DISPLAY_NONE:"rml-display-none"},F=.5,I="250ms",N="forwards",y=n=>n?!0:(console.warn("No instance set, cancel drag-in"),!1);class V extends H{constructor(t){super(),a(this,"_mainDomElement"),a(this,"_currentDrag",{}),a(this,"_currentTouch",null),a(this,"_firefoxDragPosition",{x:0,y:0}),a(this,"options",{}),a(this,"_firefoxFallback",e=>{if(!this._currentDrag.event)return;const i=e||window.event;this._firefoxDragPosition.x=i.pageX||0,this._firefoxDragPosition.y=i.pageY||0}),this._mainDomElement=t,this._injectStyles(),this._initializeDragGhost(),this._firefoxFallback=this._firefoxFallback.bind(this),document.addEventListener("dragover",this._firefoxFallback)}_injectStyles(){if(!document.getElementById(k)){const t=document.createElement("style");t.type="text/css",t.id=k,t.innerHTML=`
|
|
2
|
-
.${C.DISPLAY_NONE}{display:none}
|
|
3
|
-
.${x}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
|
|
4
|
-
.${T}{position:absolute;top:0;left:0;width:1px;height:1px;z-index:999;pointer-events:none;background-color:transparent;}
|
|
5
|
-
@keyframes ${S} {from{opacity: 0;}to {opacity: ${F};}}
|
|
6
|
-
@keyframes ${z} {from{opacity: ${F};}to {opacity: 0;}}
|
|
7
|
-
`,document.head.appendChild(t)}}_initializeDragGhost(){const t=this._mode==="custom-view"?document.body:this._mainDomElement.parentNode;let e=t.querySelector("."+T);e||(e=document.createElement("div"),e.classList.add(T),e.innerText=" ",t.appendChild(e))}setInstance(t){this._instance=t}setMode(t){this._mode=t}async dragStart(t,e,i="rml_id"){const o=this._mainDomElement.parentNode,r=o.querySelector("."+T);if(e instanceof DragEvent&&e.dataTransfer&&e.dataTransfer.setDragImage&&e.dataTransfer.setDragImage(r,0,0),this._mode==="custom-view"&&y(this._instance)){const g=await this._instance.getBoundingClientRect("iframe"),_=this.options.domContainer;if(!_)throw new Error("No container set, can not expand custom view");_.style.position="absolute",_.style.top=`${g.top}px`,_.style.left=`${g.left}px`,_.style.width=`${g.width}px`,_.style.height=`${g.height}px`,await this._instance.expandCustomView(this._viewName)}const s=D(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("."+x);c||(c=document.createElement("div"),c.classList.add(x),o.appendChild(c)),c.classList.remove(C.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;const h=e.target.cloneNode();h.style.position="fixed",h.style.pointerEvents="none",h.style.opacity="0",h.style.animation=`${S} ${I} ${N}`,h.id=q,h.style.zIndex="9999",document.body.appendChild(h),this._currentDrag.element=h;const u=e.target.getBoundingClientRect();this._currentDrag.offset||(this._currentDrag.offset={x:0,y:0});const{clientX:d,clientY:m}=w(e,this._firefoxDragPosition);this._currentDrag.offset.x=this._mode==="website"?d-u.left:u.width/2,this._currentDrag.offset.y=this._mode==="website"?m-u.top:u.height/2,h.style.top=m+"px",h.style.left=d+"px";const{x:l,y:f}=Y(o,this._currentDrag.event||e,this._firefoxDragPosition),p=Math.max(1,l),E=Math.max(1,f);y(this._instance)&&this._instance.dragInObject(t,p,E,i)}dragUpdate(t){var e,i;const{clientX:o,clientY:r}=w(t,this._firefoxDragPosition),s=o<=0||r<=0;if(this._mode==="custom-view"&&s)return;const c=this._mainDomElement.parentNode,{x:h,y:u}=Y(c,t,this._firefoxDragPosition);if(h===0&&u===0)return;const d=Math.max(1,h),m=Math.max(1,u);if(this._currentDrag.element){const{clientX:l,clientY:f}=w(t,this._firefoxDragPosition),p=((e=this._currentDrag.offset)==null?void 0:e.x)||0,E=((i=this._currentDrag.offset)==null?void 0:i.y)||0;this._currentDrag.element.style.left=`${l-p}px`,this._currentDrag.element.style.top=`${f-E}px`;const g=(this.options.dragInOverlapX||0)+1,_=(this.options.dragInOverlapY||0)+1;let $=d>g&&m>_;if(this._mode==="custom-view"){const L=this.options.domContainer;if(!L)throw new Error("No container set, can not fade in/out drag ghost");const v=L.getBoundingClientRect();$=!U({x:d,y:m},{x:v.left-g,y:v.top-_,width:v.width+g,height:v.height+_})}$?this._currentDrag.element.style.animation=`${z} ${I} ${N}`:this._currentDrag.element.style.animation=`${S} ${I} ${N}`}if(!(d===1&&m===1)&&y(this._instance)){let l=d,f=m;if(M(t)){const p=this.options.fingerSize||0;l=Math.max(2,d+p),f=Math.max(2,m-p)}this._instance.updateDrag(l,f)}}async dragEnd(){if(y(this._instance)&&this._mode==="custom-view"){await this._instance.collapseCustomView(this._viewName);const i=this.options.domContainer;if(!i)throw new Error("No container set, can not collapse custom view");i.style.position="",i.style.top="",i.style.left="",i.style.width="",i.style.height=""}this._mainDomElement.style.pointerEvents="all";const t=this._mainDomElement.parentNode;y(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("."+x);e&&e.classList.add(C.DISPLAY_NONE)}touchStart(t,e,i="rml_id"){var o,r;e.preventDefault();const s=(h,u)=>{this.dragStart(t,u,i)},c={};typeof((o=this.options)==null?void 0:o.touchDragDelay)=="number"&&(c.delay=this.options.touchDragDelay),(r=this.options)!=null&&r.touchDragEpsilon&&(c.epsilon=this.options.touchDragEpsilon),this._currentTouch=new W(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{V as DragIn};
|