@roomle/embedding-lib 5.5.0-debug.5 → 5.6.0-alpha.1

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,357 +0,0 @@
1
- var j = Object.defineProperty;
2
- var q = (n, t, e) => t in n ? j(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var a = (n, t, e) => q(n, typeof t != "symbol" ? t + "" : t, e);
4
- import { p as Y } from "./embedding-lib-BdWR8XoQ.mjs";
5
- class H {
6
- constructor(t = 16) {
7
- a(this, "_computedStyleCache", /* @__PURE__ */ new Map());
8
- a(this, "_maxLifetime", 16);
9
- a(this, "_cacheCleanInterval", null);
10
- this._maxLifetime = t;
11
- }
12
- get(t) {
13
- const e = this._computedStyleCache.get(t), i = Date.now();
14
- if (e && i - e.updated < this._maxLifetime)
15
- return e.style;
16
- const s = getComputedStyle(t);
17
- return this._computedStyleCache.set(t, { style: s, updated: i }), this._cacheCleanInterval || (this._cacheCleanInterval = setInterval(
18
- () => this._cleanUpCache,
19
- Math.max(this._maxLifetime * 1e3, 5e3)
20
- )), s;
21
- }
22
- _cleanUpCache() {
23
- const t = Date.now();
24
- for (const [e, { updated: i }] of this._computedStyleCache.entries())
25
- t - i >= this._maxLifetime && this._computedStyleCache.delete(e);
26
- this._computedStyleCache.size === 0 && this._cacheCleanInterval && (clearInterval(this._cacheCleanInterval), this._cacheCleanInterval = null);
27
- }
28
- }
29
- const G = (n) => window.TouchEvent && n instanceof window.TouchEvent;
30
- let v;
31
- const R = (n) => (v || (v = new H()), v.get(n)), z = (n, t, e) => {
32
- const i = parseFloat(n), s = window.devicePixelRatio || 1;
33
- if (t === "px")
34
- return i;
35
- if (t === "%") {
36
- const o = e === document.documentElement ? window.innerWidth : e.offsetWidth;
37
- return i / 100 * o;
38
- }
39
- if (t === "rem") {
40
- const o = parseFloat(
41
- R(document.documentElement).fontSize
42
- );
43
- return i * o;
44
- }
45
- if (t === "em") {
46
- const o = parseFloat(
47
- R(e).fontSize
48
- );
49
- return i * o;
50
- }
51
- if (t === "vh" || t === "vw" || t === "vmin" || t === "vmax") {
52
- const o = {
53
- vh: window.innerHeight,
54
- vw: window.innerWidth,
55
- vmin: Math.min(window.innerWidth, window.innerHeight),
56
- vmax: Math.max(window.innerWidth, window.innerHeight)
57
- };
58
- return i / 100 * o[t];
59
- }
60
- const r = {
61
- cm: 37.7952755906,
62
- mm: 3.77952755906,
63
- in: 96
64
- };
65
- return t in r ? i * r[t] * s : (console.warn(
66
- "Unable to determine coordinates for drag-in. Therefore drag-in is not possible. Check the CSS that positions the iframe of Roomle"
67
- ), 0);
68
- }, B = (n, t, e = { x: 0, y: 0 }) => {
69
- const i = n.getBoundingClientRect(), r = R(n).transform;
70
- let o = 0, c = 0;
71
- if (r !== "none") {
72
- const f = /translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/, m = r.match(f);
73
- m && (o = z(m[1], m[2], n), c = z(m[3], m[4], n));
74
- }
75
- const { clientX: h, clientY: u } = k(t, e), _ = h - i.left - o + n.scrollLeft, g = u - i.top - c + n.scrollTop;
76
- return { x: _, y: g };
77
- }, k = (n, t) => {
78
- const { clientX: e, clientY: i } = G(n) ? V(n) : n, s = e > 0 ? e : t.x, r = i > 0 ? i : t.y;
79
- return { clientX: s, clientY: r };
80
- }, V = (n) => {
81
- if (n.touches.length) {
82
- let { clientX: e, clientY: i } = n.touches[0];
83
- if (n.touches.length > 1) {
84
- const s = n.touches[1], r = s.clientX, o = s.clientY;
85
- e = (e + r) / 2, i = (i + o) / 2;
86
- }
87
- return { clientX: e, clientY: i };
88
- }
89
- const t = n.changedTouches[0];
90
- return { clientX: t.clientX, clientY: t.clientY };
91
- }, W = (n, t) => {
92
- const e = t.x + t.width, i = t.x, s = t.y + t.height, r = t.y, { x: o, y: c } = n;
93
- return o >= i && o <= e && c >= r && c <= s;
94
- }, X = 500, $ = 10;
95
- class Z {
96
- constructor(t, { onTouchDragStart: e }, i = {}) {
97
- a(this, "_touchDragTimeOut");
98
- a(this, "_onTouchDragStart");
99
- a(this, "_payload", null);
100
- a(this, "_delay", X);
101
- a(this, "_firstTouch", null);
102
- a(this, "_lastTouch", null);
103
- a(this, "_epsilon", $);
104
- this._payload = t, this._onTouchDragStart = e, this._delay = i.delay || X, this._epsilon = i.epsilon || $;
105
- }
106
- onTouchStart(t) {
107
- var e;
108
- !t || !((e = t == null ? void 0 : t.touches) != null && e.length) || this._touchDragTimeOut || (this._firstTouch = t.touches[t.touches.length - 1], this._touchDragTimeOut = setTimeout(() => {
109
- this._clearTimeout(), this._lastTouch || (this._lastTouch = t.touches[0]), this._checkXDistance(t)();
110
- }, this._delay));
111
- }
112
- onTouchEnd() {
113
- this._resetTouches();
114
- }
115
- onTouchMove(t) {
116
- var e;
117
- !t || !((e = t == null ? void 0 : t.touches) != null && e.length) || (this._lastTouch = t.touches[0]);
118
- }
119
- _clearTimeout() {
120
- this._touchDragTimeOut && (clearTimeout(this._touchDragTimeOut), this._touchDragTimeOut = null);
121
- }
122
- _resetTouches() {
123
- this._clearTimeout(), this._lastTouch = null, this._firstTouch = null, this._payload = null;
124
- }
125
- _checkXDistance(t) {
126
- return () => {
127
- if (!this._firstTouch || !this._lastTouch)
128
- return;
129
- let e = !1;
130
- e = Math.abs(
131
- this._firstTouch.clientX - this._lastTouch.clientX
132
- ) < this._epsilon, e && (this._onTouchDragStart(this._payload, t), this._resetTouches());
133
- };
134
- }
135
- }
136
- class J {
137
- constructor(t, e) {
138
- a(this, "_mainDomElement");
139
- a(this, "_instance", null);
140
- a(this, "_mode", "website");
141
- a(this, "_viewName", "main");
142
- this._mainDomElement = t, this._mode = e;
143
- }
144
- setInstance(t) {
145
- this._instance = t;
146
- }
147
- setViewName(t) {
148
- this._viewName = t;
149
- }
150
- }
151
- const K = (n) => new Promise((t) => setTimeout(t, n)), F = "rml-drag-in-styles", Q = "rml-drag-in-drag-element", x = "rml-drag-in-overlay", T = "rml-drag-in-spacer", S = "rml-drag-in-drag-ghost", I = "rml-drag-in-fade-in", P = "rml-drag-in-fade-out", b = {
152
- DISPLAY_NONE: "rml-display-none"
153
- }, U = 0.5, A = "250ms", N = "forwards", E = "Resize observer did not return exactly one entry", y = (n) => n ? !0 : (console.warn("No instance set, cancel drag-in"), !1);
154
- class it extends J {
155
- constructor(e, i) {
156
- super(e, i);
157
- a(this, "_currentDrag", {});
158
- a(this, "_currentTouch", null);
159
- a(this, "_firefoxDragPosition", { x: 0, y: 0 });
160
- a(this, "_readyForDragUpdates", !1);
161
- a(this, "_clientRect", null);
162
- a(this, "options", {});
163
- a(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._initReadyForDragUpdates(), this._injectStyles(), this._initializeDragGhost(), this._firefoxFallback = this._firefoxFallback.bind(this), this._initReadyForDragUpdates(), document.addEventListener("dragover", this._firefoxFallback);
170
- }
171
- _injectStyles() {
172
- if (!!!document.getElementById(F)) {
173
- const i = document.createElement("style");
174
- i.type = "text/css", i.id = F, i.innerHTML = `
175
- .${b.DISPLAY_NONE}{display:none}
176
- .${x}{position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;}
177
- .${S}{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: ${U};}}
179
- @keyframes ${P} {from{opacity: ${U};}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
- "." + S
187
- );
188
- i || (i = document.createElement("div"), i.classList.add(S), i.innerText = " ", e.appendChild(i));
189
- }
190
- _initReadyForDragUpdates() {
191
- this._readyForDragUpdates = this._mode !== "custom-view";
192
- }
193
- setInstance(e) {
194
- this._instance = e, this._initDom();
195
- }
196
- async _initDom() {
197
- if (this._mode === "custom-view" && y(this._instance)) {
198
- const e = await this._instance.getBoundingClientRect("iframe");
199
- this._clientRect = e;
200
- const i = this.options.domContainer;
201
- if (!i)
202
- throw new Error("No container set, can not expand custom view");
203
- i.style.position = "absolute", i.style.top = "0", i.style.right = "0", i.style.width = `${this._clientRect.width}px`, i.style.willChange = "transform";
204
- let s = document.body.querySelector(
205
- `.${T}`
206
- );
207
- s || (s = document.createElement("div"), s.classList.add(T), document.body.appendChild(s)), s = document.body.querySelector(
208
- `.${T}`
209
- ), s && (s.style.position = "fixed", s.style.backgroundColor = "blue", s.style.top = "0px", s.style.right = "0px", s.style.width = `${e.width}px`, s.style.height = `${e.height + e.top}px`, s.style.opacity = "0", s.style.pointerEvents = "none", s.style.zIndex = "-1");
210
- }
211
- }
212
- async dragStart(e, i, s = "rml_id") {
213
- const r = this._mainDomElement.parentNode, o = r.querySelector(
214
- "." + S
215
- );
216
- if (i instanceof DragEvent && i.dataTransfer && i.dataTransfer.setDragImage && i.dataTransfer.setDragImage(o, 0, 0), this._mode === "custom-view" && y(this._instance)) {
217
- const {
218
- resolve: _,
219
- reject: g,
220
- promise: f
221
- } = Y(), m = new ResizeObserver((D) => {
222
- if (D.length !== 1)
223
- return console.error(E), g(E);
224
- const p = D[0];
225
- !this._clientRect || p.contentRect.width === this._clientRect.width || (this.options.domContainer && (this.options.domContainer.style.transform = `translate3d(1px,${this._clientRect.top}px,0)`), m.disconnect(), _());
226
- });
227
- m.observe(this._mainDomElement), await this._instance.expandCustomView(this._viewName), await f, await K(
228
- 50
229
- );
230
- }
231
- const c = R(r);
232
- if (this._mode === "website" && c.position !== "relative") {
233
- console.warn(
234
- "Parent of iframe should have position relative, otherwise drag-in can not detect the x/y coordinates correctly"
235
- );
236
- return;
237
- }
238
- this._mainDomElement.style.pointerEvents = "none";
239
- let h = r.querySelector(
240
- "." + x
241
- );
242
- h || (h = document.createElement("div"), h.classList.add(x), r.appendChild(h)), h.classList.remove(b.DISPLAY_NONE), i.target.getAttribute("draggable") || console.warn(
243
- `Draggable not detected correctly! Did you add draggable="true" to the element? In Sarafi only 'draggable' is too less`
244
- ), this._currentDrag.event = i, this._currentDrag.id = e, this._currentDrag.type = s, this._readyForDragUpdates = !0;
245
- }
246
- /** MUST NOT BE ASYNC, OTHERWISE ACCESS TO event.clientX could be wrong */
247
- dragUpdate(e) {
248
- var L, M;
249
- if (!this._readyForDragUpdates)
250
- return;
251
- const { clientX: i, clientY: s } = k(
252
- e,
253
- this._firefoxDragPosition
254
- ), r = i <= 0 || s <= 0;
255
- if (this._mode === "custom-view" && r)
256
- return;
257
- const o = this._mainDomElement.parentNode, { x: c, y: h } = B(o, e, this._firefoxDragPosition);
258
- if (c === 0 && h === 0)
259
- return;
260
- if (!this._currentDrag.element) {
261
- const l = e.target.cloneNode();
262
- l.style.position = "fixed", l.style.pointerEvents = "none", l.style.opacity = "0", l.style.animation = `${I} ${A} ${N}`, l.id = Q, l.style.zIndex = "9999", document.body.appendChild(l), this._currentDrag.element = l;
263
- const d = e.target.getBoundingClientRect();
264
- 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" ? s - d.top : d.height / 2;
265
- }
266
- const u = Math.max(1, c), _ = Math.max(1, h), g = ((L = this._currentDrag.offset) == null ? void 0 : L.x) || 0, f = ((M = this._currentDrag.offset) == null ? void 0 : M.y) || 0, m = i - g, D = s - f;
267
- this._currentDrag.element.style.left = `${m}px`, this._currentDrag.element.style.top = `${D}px`;
268
- const p = (this.options.dragInOverlapX || 0) + 1, C = (this.options.dragInOverlapY || 0) + 1;
269
- let O = u > p && _ > C;
270
- if (this._mode === "custom-view") {
271
- const l = document.body.querySelector(
272
- `.${T}`
273
- );
274
- if (!l)
275
- throw new Error("No spacer set, can not fade in/out drag ghost");
276
- const d = l.getBoundingClientRect();
277
- O = !W(
278
- { x: u, y: _ },
279
- {
280
- x: d.left - p,
281
- y: d.top - C,
282
- width: d.width + p,
283
- height: d.height + C
284
- }
285
- );
286
- }
287
- if (O ? this._currentDrag.element.style.animation = `${P} ${A} ${N}` : this._currentDrag.element.style.animation = `${I} ${A} ${N}`, !(u === 1 && _ === 1) && y(this._instance)) {
288
- let l = u, d = _;
289
- if (G(e)) {
290
- const w = this.options.fingerSize || 0;
291
- l = Math.max(2, u + w), d = Math.max(2, _ - w);
292
- }
293
- if (this._currentDrag.inserted === "done")
294
- this._instance.updateDrag(l, d);
295
- else if (this._currentDrag.inserted !== "inprogress") {
296
- if (this._currentDrag.inserted = "inprogress", !this._currentDrag.id || !this._currentDrag.type)
297
- return;
298
- this._instance.dragInObject(this._currentDrag.id, l, d, this._currentDrag.type).then(
299
- () => {
300
- this._currentDrag.inserted = "done";
301
- },
302
- (w) => {
303
- console.error(w), this._currentDrag.inserted = "failed";
304
- }
305
- );
306
- }
307
- }
308
- }
309
- async dragEnd() {
310
- if (this._initReadyForDragUpdates(), y(this._instance) && this._mode === "custom-view") {
311
- const {
312
- resolve: s,
313
- reject: r,
314
- promise: o
315
- } = Y(), c = new ResizeObserver((h) => {
316
- if (h.length !== 1)
317
- return console.error(E), r(E);
318
- const u = h[0];
319
- !this._clientRect || u.contentRect.width !== this._clientRect.width || (this.options.domContainer && (this.options.domContainer.style.transform = ""), c.disconnect(), s());
320
- });
321
- c.observe(this._mainDomElement), await this._instance.collapseCustomView(this._viewName), await o;
322
- }
323
- this._mainDomElement.style.pointerEvents = "all";
324
- const e = this._mainDomElement.parentNode;
325
- y(this._instance) && this._instance.dragInObjectEnd(), this._currentDrag.element && document.body.removeChild(this._currentDrag.element), this._currentDrag = {}, this._firefoxDragPosition = { x: 0, y: 0 };
326
- const i = e.querySelector(
327
- "." + x
328
- );
329
- i && i.classList.add(b.DISPLAY_NONE);
330
- }
331
- touchStart(e, i, s = "rml_id") {
332
- var c, h;
333
- i.preventDefault();
334
- const r = (u, _) => {
335
- this.dragStart(e, _, s);
336
- }, o = {};
337
- typeof ((c = this.options) == null ? void 0 : c.touchDragDelay) == "number" && (o.delay = this.options.touchDragDelay), (h = this.options) != null && h.touchDragEpsilon && (o.epsilon = this.options.touchDragEpsilon), this._currentTouch = new Z(
338
- void 0,
339
- {
340
- onTouchDragStart: r
341
- },
342
- o
343
- ), this._currentTouch.onTouchStart(i);
344
- }
345
- touchMove(e) {
346
- this._currentTouch && this._currentTouch.onTouchMove(e), this._currentDrag.event && this.dragUpdate(e);
347
- }
348
- touchEnd() {
349
- this._currentTouch && this._currentTouch.onTouchEnd(), this._currentTouch = null, this.dragEnd();
350
- }
351
- dispose() {
352
- document.removeEventListener("dragover", this._firefoxFallback);
353
- }
354
- }
355
- export {
356
- it as DragIn
357
- };
@@ -1,7 +0,0 @@
1
- var q=Object.defineProperty,A=(n,t,e)=>t in n?q(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,a=(n,t,e)=>A(n,typeof t!="symbol"?t+"":t,e);import{p as L}from"./embedding-lib-Cf_bgB5_.mjs";class B{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 s=getComputedStyle(t);return this._computedStyleCache.set(t,{style:s,updated:i}),this._cacheCleanInterval||(this._cacheCleanInterval=setInterval(()=>this._cleanUpCache,Math.max(this._maxLifetime*1e3,5e3))),s}_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 O=n=>window.TouchEvent&&n instanceof window.TouchEvent;let C;const y=n=>(C||(C=new B),C.get(n)),F=(n,t,e)=>{const i=parseFloat(n),s=window.devicePixelRatio||1;if(t==="px")return i;if(t==="%"){const o=e===document.documentElement?window.innerWidth:e.offsetWidth;return i/100*o}if(t==="rem"){const o=parseFloat(y(document.documentElement).fontSize);return i*o}if(t==="em"){const o=parseFloat(y(e).fontSize);return i*o}if(t==="vh"||t==="vw"||t==="vmin"||t==="vmax"){const o={vh:window.innerHeight,vw:window.innerWidth,vmin:Math.min(window.innerWidth,window.innerHeight),vmax:Math.max(window.innerWidth,window.innerHeight)};return i/100*o[t]}const r={cm:37.7952755906,mm:3.77952755906,in:96};return t in r?i*r[t]*s:(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)},W=(n,t,e={x:0,y:0})=>{const i=n.getBoundingClientRect(),s=y(n).transform;let r=0,o=0;if(s!=="none"){const d=/translate\(\s*([-+]?\d*\.?\d+|\d+)(px|%)?,?\s*([-+]?\d*\.?\d+|\d+)?(px|%)?\s*\)/,u=s.match(d);u&&(r=F(u[1],u[2],n),o=F(u[3],u[4],n))}const{clientX:c,clientY:m}=X(t,e),g=c-i.left-r+n.scrollLeft,_=m-i.top-o+n.scrollTop;return{x:g,y:_}},X=(n,t)=>{const{clientX:e,clientY:i}=O(n)?H(n):n,s=e>0?e:t.x,r=i>0?i:t.y;return{clientX:s,clientY:r}},H=n=>{if(n.touches.length){let{clientX:e,clientY:i}=n.touches[0];if(n.touches.length>1){const s=n.touches[1],r=s.clientX,o=s.clientY;e=(e+r)/2,i=(i+o)/2}return{clientX:e,clientY:i}}const t=n.changedTouches[0];return{clientX:t.clientX,clientY:t.clientY}},V=(n,t)=>{const e=t.x+t.width,i=t.x,s=t.y+t.height,r=t.y,{x:o,y:c}=n;return o>=i&&o<=e&&c>=r&&c<=s},Y=500,P=10;class G{constructor(t,{onTouchDragStart:e},i={}){a(this,"_touchDragTimeOut"),a(this,"_onTouchDragStart"),a(this,"_payload",null),a(this,"_delay",Y),a(this,"_firstTouch",null),a(this,"_lastTouch",null),a(this,"_epsilon",P),this._payload=t,this._onTouchDragStart=e,this._delay=i.delay||Y,this._epsilon=i.epsilon||P}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 J{constructor(t,e){a(this,"_mainDomElement"),a(this,"_instance",null),a(this,"_mode","website"),a(this,"_viewName","main"),this._mainDomElement=t,this._mode=e}setInstance(t){this._instance=t}setViewName(t){this._viewName=t}}const K=n=>new Promise(t=>setTimeout(t,n)),z="rml-drag-in-styles",Q="rml-drag-in-drag-element",D="rml-drag-in-overlay",w="rml-drag-in-spacer",v="rml-drag-in-drag-ghost",S="rml-drag-in-fade-in",M="rml-drag-in-fade-out",I={DISPLAY_NONE:"rml-display-none"},U=.5,$="250ms",R="forwards",x="Resize observer did not return exactly one entry",p=n=>n?!0:(console.warn("No instance set, cancel drag-in"),!1);class Z extends J{constructor(t,e){super(t,e),a(this,"_currentDrag",{}),a(this,"_currentTouch",null),a(this,"_firefoxDragPosition",{x:0,y:0}),a(this,"_readyForDragUpdates",!1),a(this,"_clientRect",null),a(this,"options",{}),a(this,"_firefoxFallback",i=>{if(!this._currentDrag.event)return;const s=i||window.event;this._firefoxDragPosition.x=s.pageX||0,this._firefoxDragPosition.y=s.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(z)){const t=document.createElement("style");t.type="text/css",t.id=z,t.innerHTML=`
2
- .${I.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 ${S} {from{opacity: 0;}to {opacity: ${U};}}
6
- @keyframes ${M} {from{opacity: ${U};}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._clientRect=t;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=`${this._clientRect.width}px`,e.style.willChange="transform";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 s=this._mainDomElement.parentNode,r=s.querySelector("."+v);if(e instanceof DragEvent&&e.dataTransfer&&e.dataTransfer.setDragImage&&e.dataTransfer.setDragImage(r,0,0),this._mode==="custom-view"&&p(this._instance)){const{resolve:m,reject:g,promise:_}=L(),d=new ResizeObserver(u=>{if(u.length!==1)return console.error(x),g(x);const T=u[0];!this._clientRect||T.contentRect.width===this._clientRect.width||(this.options.domContainer&&(this.options.domContainer.style.transform=`translate3d(1px,${this._clientRect.top}px,0)`),d.disconnect(),m())});d.observe(this._mainDomElement),await this._instance.expandCustomView(this._viewName),await _,await K(50)}const o=y(s);if(this._mode==="website"&&o.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=s.querySelector("."+D);c||(c=document.createElement("div"),c.classList.add(D),s.appendChild(c)),c.classList.remove(I.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:s,clientY:r}=X(t,this._firefoxDragPosition),o=s<=0||r<=0;if(this._mode==="custom-view"&&o)return;const c=this._mainDomElement.parentNode,{x:m,y:g}=W(c,t,this._firefoxDragPosition);if(m===0&&g===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=`${S} ${$} ${R}`,h.id=Q,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"?s-l.left:l.width/2,this._currentDrag.offset.y=this._mode==="website"?r-l.top:l.height/2}const _=Math.max(1,m),d=Math.max(1,g),u=((e=this._currentDrag.offset)==null?void 0:e.x)||0,T=((i=this._currentDrag.offset)==null?void 0:i.y)||0,k=s-u,j=r-T;this._currentDrag.element.style.left=`${k}px`,this._currentDrag.element.style.top=`${j}px`;const b=(this.options.dragInOverlapX||0)+1,E=(this.options.dragInOverlapY||0)+1;let N=_>b&&d>E;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();N=!V({x:_,y:d},{x:l.left-b,y:l.top-E,width:l.width+b,height:l.height+E})}if(N?this._currentDrag.element.style.animation=`${M} ${$} ${R}`:this._currentDrag.element.style.animation=`${S} ${$} ${R}`,!(_===1&&d===1)&&p(this._instance)){let h=_,l=d;if(O(t)){const f=this.options.fingerSize||0;h=Math.max(2,_+f),l=Math.max(2,d-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"){const{resolve:i,reject:s,promise:r}=L(),o=new ResizeObserver(c=>{if(c.length!==1)return console.error(x),s(x);const m=c[0];!this._clientRect||m.contentRect.width!==this._clientRect.width||(this.options.domContainer&&(this.options.domContainer.style.transform=""),o.disconnect(),i())});o.observe(this._mainDomElement),await this._instance.collapseCustomView(this._viewName),await r}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(I.DISPLAY_NONE)}touchStart(t,e,i="rml_id"){var s,r;e.preventDefault();const o=(m,g)=>{this.dragStart(t,g,i)},c={};typeof((s=this.options)==null?void 0:s.touchDragDelay)=="number"&&(c.delay=this.options.touchDragDelay),(r=this.options)!=null&&r.touchDragEpsilon&&(c.epsilon=this.options.touchDragEpsilon),this._currentTouch=new G(void 0,{onTouchDragStart:o},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{Z as DragIn};