@roomle/embedding-lib 5.5.0-debug.4 → 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.
- package/docs/md/web/embedding/CHANGELOG.md +3 -3
- package/drag-in-B_Ab1D0Y.mjs +357 -0
- package/drag-in-DKZRYdaz.mjs +7 -0
- package/embedding-lib-BdWR8XoQ.mjs +539 -0
- package/embedding-lib-Cf_bgB5_.mjs +8 -0
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/roomle-embedding-lib.es.js +2 -536
- package/roomle-embedding-lib.es.min.js +1 -8
- package/roomle-embedding-lib.umd.js +14 -14
- package/roomle-embedding-lib.umd.min.js +13 -13
- package/drag-in-CXPjCiN1.mjs +0 -338
- package/drag-in-DhWNfKDL.mjs +0 -7
package/drag-in-CXPjCiN1.mjs
DELETED
|
@@ -1,338 +0,0 @@
|
|
|
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
|
-
};
|
package/drag-in-DhWNfKDL.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
var R=Object.defineProperty,q=(n,t,e)=>t in n?R(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,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};
|