@roomle/embedding-lib 5.5.0-alpha.1 → 5.5.0-debug.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,12 +1,26 @@
1
- ## [5.5.0-alpha.1](https://github.com/roomle-dev/roomle-ui/compare/embedding-lib-v5.4.0...embedding-lib-v5.5.0-alpha.1) (2024-10-09)
1
+ ## [5.5.0-debug.1](https://github.com/roomle-dev/roomle-ui/compare/embedding-lib-v5.4.0...embedding-lib-v5.5.0-debug.1) (2024-10-16)
2
2
 
3
3
 
4
4
  ### Features
5
5
 
6
+ * dial points ([e15f238](https://github.com/roomle-dev/roomle-ui/commit/e15f238c05c04581f6349c84f104a8fe6ba60cc4))
7
+ * make communication from child to parent possible ([6d432ab](https://github.com/roomle-dev/roomle-ui/commit/6d432ab6ce892bdee65e4e70ba57b69d78a7f7dc))
8
+ * make custom views better extensible ([56d1e04](https://github.com/roomle-dev/roomle-ui/commit/56d1e046271745ba61728e02a8d6bbda2dd9400b))
9
+ * make it possible that a custom view can connect to us ([7a50358](https://github.com/roomle-dev/roomle-ui/commit/7a50358500e084bcf32635f72f70b4c4dbe354b5))
10
+ * new methods for exposed api ([264d34f](https://github.com/roomle-dev/roomle-ui/commit/264d34fae8e98b259bf4ef0e921622544ecd4bce))
6
11
  * **SDK:** upgrade to version 2.86.0 ([#1282](https://github.com/roomle-dev/roomle-ui/issues/1282)) ([fb599f0](https://github.com/roomle-dev/roomle-ui/commit/fb599f0680a45489a598c0e49f59ab04b1d2a23e))
7
12
  * **SDK:** upgrade to version 2.87.0-alpha.1 ([#1285](https://github.com/roomle-dev/roomle-ui/issues/1285)) ([fa214a9](https://github.com/roomle-dev/roomle-ui/commit/fa214a98b18edae8629f819b30ac7025508c1e96))
8
13
 
9
14
 
10
15
  ### Bug Fixes
11
16
 
17
+ * amount of ticks ([16d4f88](https://github.com/roomle-dev/roomle-ui/commit/16d4f8884e9bca0b9d2c103ad4d038dc983b4571))
18
+ * disable snapping when zero is supplied ([bb976d2](https://github.com/roomle-dev/roomle-ui/commit/bb976d2d9436d7212cbcf4936936892fd89a4bbc))
12
19
  * fix typescript issue in test causing tests to fail ([65fb1a3](https://github.com/roomle-dev/roomle-ui/commit/65fb1a382da215611761a3fa9739ee2dee632df9))
20
+ * make typescript work ([6d14255](https://github.com/roomle-dev/roomle-ui/commit/6d14255f1f9b57fde9a6efc4bb57fa39244b65b3))
21
+ * remove redundant CSS ([7b985c5](https://github.com/roomle-dev/roomle-ui/commit/7b985c5eb85363e7c15fb41adaaf93f0bd9f104d))
22
+ * Room Designer - Multi selection after movement not selected ([4a6e60a](https://github.com/roomle-dev/roomle-ui/commit/4a6e60aae10719f2bd50b9753d0ae9780cef3db5))
23
+ * search input showing when elements are empty ([e59f0a8](https://github.com/roomle-dev/roomle-ui/commit/e59f0a876df49caeb8c0526e6c0c36553006b214))
24
+ * tests ([9eccce6](https://github.com/roomle-dev/roomle-ui/commit/9eccce6919bad8bf0748b6b3be4c66f0cea4d588))
25
+ * ts errors ([faaf013](https://github.com/roomle-dev/roomle-ui/commit/faaf0138799af91f21af55a7994e3a4f22de1883))
26
+ * use correct imports so that we do not import all of Vue ([46dc577](https://github.com/roomle-dev/roomle-ui/commit/46dc577592dd88947c07cbf600f2d4988584f5d2))
@@ -0,0 +1,323 @@
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)) {
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
+ };
@@ -0,0 +1,7 @@
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 v=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(v(document.documentElement).fontSize);return i*s}if(t==="em"){const s=parseFloat(v(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=v(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=v(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 D=L.getBoundingClientRect();$=!U({x:d,y:m},{x:D.left-g,y:D.top-_,width:D.width+g,height:D.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)){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};
package/index.d.ts CHANGED
@@ -1,11 +1,18 @@
1
- import { default as default_2 } from '@roomle/web-sdk/lib/definitions/planner-core/src/roomle-planner';
2
- import { default as default_3 } from '@roomle/web-sdk/lib/definitions/configurator-core/src/services/configurator-ui-callback';
3
- import { default as default_4 } from '@roomle/web-sdk/lib/definitions/configurator-core/src/roomle-configurator';
1
+ import { default as default_2 } from '@roomle/web-sdk/lib/definitions/configurator-core/src/roomle-configurator';
2
+ import { default as default_3 } from '@roomle/web-sdk/lib/definitions/planner-core/src/roomle-planner';
3
+ import { default as default_4 } from '@roomle/web-sdk/lib/definitions/configurator-core/src/services/configurator-ui-callback';
4
4
  import { default as default_5 } from '@roomle/web-sdk/lib/definitions/glb-viewer-core/src/roomle-glb-viewer';
5
+ import { EmbeddingCommand } from '../../common/src/utils/message-handler';
5
6
  import { ExposedAnalyticsCallbacks } from '../../../src/configurator/embedding/exposed-analytics-callbacks';
6
7
  import { ExposedApi } from '../../../../src/configurator/embedding/exposed-api';
7
8
  import { ExposedApi as ExposedApi_2 } from '../../../src/configurator/embedding/exposed-api';
8
9
  import { GlobalCallback } from '@roomle/web-sdk/lib/definitions/common-core/src/services/global-callback';
10
+ import { MessageHandler } from '../../common/src/utils/message-handler';
11
+ import { Nullable } from '../../../src/common/utils/types';
12
+ import { Nullable as Nullable_2 } from '../../../../src/common/utils/types';
13
+ import { PossibleCustomViews } from '../../../src/configurator/embedding/types';
14
+ import { PossibleCustomViewsAndMain } from '../../../src/configurator/embedding/types';
15
+ import { PossibleCustomViewsAndMain as PossibleCustomViewsAndMain_2 } from '../../../../src/configurator/embedding/types';
9
16
  import { RapiId } from '@roomle/web-sdk/lib/definitions/typings/rapi-types';
10
17
  import { UiInitData } from '../../../src/configurator/embedding/types';
11
18
 
@@ -13,42 +20,81 @@ declare interface AvailablePlugins {
13
20
  dragIn?: DragIn;
14
21
  }
15
22
 
16
- declare class DragIn {
17
- private _iframe;
23
+ declare class Connector<SdkType, SdkCallbacks> implements RoomleEmbeddingApiKeys {
24
+ protected _messageHandler: Nullable<MessageHandler>;
25
+ isSetupDone: boolean;
26
+ viewName: PossibleCustomViewsAndMain;
27
+ plugins: AvailablePlugins;
28
+ pluginsLoaded: Array<Promise<void>>;
29
+ ui: ExposedApi_2;
30
+ extended: SdkType;
31
+ configurator: default_2;
32
+ analytics: {
33
+ callbacks: ExposedAnalyticsCallbacks;
34
+ };
35
+ global: {
36
+ callbacks: GlobalCallback;
37
+ };
38
+ setMessageHandler(messageHandler: MessageHandler): void;
39
+ handleSetup(methodsAndCallbacks: {
40
+ methods: string[];
41
+ callbacks: string[];
42
+ }): void;
43
+ executeMessage({ message, args }: EmbeddingCommand): Promise<{
44
+ result: any;
45
+ }>;
46
+ setupPlugins(plugins: PluginDefinitions, iframe: HTMLIFrameElement | HTMLBodyElement, mode?: EmbeddingPluginMode): void;
47
+ }
48
+
49
+ declare class DragIn extends EmbeddingPlugin {
50
+ private _mainDomElement;
18
51
  private _currentDrag;
19
52
  private _currentTouch;
20
53
  private _firefoxDragPosition;
21
- private _instance;
22
54
  options: {
23
55
  dragInOverlapX?: number;
24
56
  dragInOverlapY?: number;
25
57
  fingerSize?: number;
26
58
  touchDragDelay?: number;
27
59
  touchDragEpsilon?: number;
60
+ domContainer?: HTMLElement;
28
61
  };
29
62
  private _injectStyles;
30
63
  private _initializeDragGhost;
31
- constructor(iframe: HTMLIFrameElement);
64
+ constructor(iframe: HTMLIFrameElement | HTMLBodyElement);
32
65
  setInstance(instance: ExposedApi): void;
66
+ setMode(mode: EmbeddingPluginMode): void;
33
67
  private _firefoxFallback;
34
- dragStart(id: RapiId, event: DragEvent | TouchEvent, type?: string): void;
68
+ dragStart(id: RapiId, event: DragEvent | TouchEvent, type?: string): Promise<void>;
35
69
  dragUpdate(event: DragEvent | TouchEvent): void;
36
- dragEnd(): void;
70
+ dragEnd(): Promise<void>;
37
71
  touchStart(id: RapiId, event: TouchEvent, type?: string): void;
38
72
  touchMove(event: TouchEvent): void;
39
73
  touchEnd(): void;
40
74
  dispose(): void;
41
75
  }
42
76
 
77
+ declare abstract class EmbeddingPlugin {
78
+ protected _instance: Nullable_2<ExposedApi>;
79
+ protected _mode: EmbeddingPluginMode;
80
+ protected _viewName: PossibleCustomViewsAndMain_2;
81
+ setInstance(instance: ExposedApi): void;
82
+ setMode(mode: EmbeddingPluginMode): void;
83
+ setViewName(viewName: PossibleCustomViewsAndMain_2): void;
84
+ }
85
+
86
+ declare type EmbeddingPluginMode = 'website' | 'custom-view';
87
+
43
88
  declare type PluginDefinitions = Array<keyof AvailablePlugins | {
44
89
  name: keyof AvailablePlugins;
45
90
  loader: () => Promise<any>;
46
91
  }>;
47
92
 
48
- declare type RoomleConfiguratorApi = RoomleEmbeddingApi<default_4, default_3>;
93
+ declare type RoomleConfiguratorApi = RoomleEmbeddingApi<default_2, default_4>;
49
94
 
50
- declare class RoomleEmbeddingApi<SdkType, SdkCallbacks> implements RoomleEmbeddingApiKeys {
95
+ declare class RoomleEmbeddingApi<SdkType, SdkCallbacks> extends Connector<SdkType, SdkCallbacks> {
51
96
  static createPlanner(configuratorId: string, container: HTMLElement, initData: UiInitData, plugins?: PluginDefinitions): Promise<RoomlePlannerApi>;
97
+ static connect(customView: PossibleCustomViews, plugins?: PluginDefinitions): Promise<Connector<default_2, default_4>>;
52
98
  /**
53
99
  * Method to create a new instance of a Roomle Configurator
54
100
  * @param configuratorId the id which identifies your configurator, you will get this ID from your Roomle Contact Person
@@ -72,23 +118,11 @@ declare class RoomleEmbeddingApi<SdkType, SdkCallbacks> implements RoomleEmbeddi
72
118
  */
73
119
  static createViewer(configuratorId: string, container: HTMLElement, initData: UiInitData, plugins?: PluginDefinitions): Promise<RoomleViewerApi>;
74
120
  private static _create;
75
- ui: ExposedApi_2;
76
- extended: SdkType;
77
- configurator: default_4;
78
- analytics: {
79
- callbacks: ExposedAnalyticsCallbacks;
80
- };
81
- global: {
82
- callbacks: GlobalCallback;
83
- };
84
- plugins: AvailablePlugins;
85
121
  private _waitForIframe;
86
122
  private _container;
87
- private _messageHandler;
88
123
  private _configuratorSettings;
89
124
  private _initData;
90
125
  private _iframe;
91
- pluginsLoaded: Array<Promise<void>>;
92
126
  private constructor();
93
127
  teardown(): void;
94
128
  private _createIframe;
@@ -107,8 +141,8 @@ declare interface RoomleEmbeddingApiKeys {
107
141
  global: any;
108
142
  }
109
143
 
110
- declare type RoomlePlannerApi = RoomleEmbeddingApi<default_2, default_3>;
144
+ declare type RoomlePlannerApi = RoomleEmbeddingApi<default_3, default_4>;
111
145
 
112
- declare type RoomleViewerApi = RoomleEmbeddingApi<default_5, default_3>;
146
+ declare type RoomleViewerApi = RoomleEmbeddingApi<default_5, default_4>;
113
147
 
114
148
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomle/embedding-lib",
3
- "version": "5.5.0-alpha.1",
3
+ "version": "5.5.0-debug.1",
4
4
  "description": "This is a small library which can be used to communicate with the Roomle Configurator",
5
5
  "type": "module",
6
6
  "main": "./roomle-embedding-lib.umd.js",