gesturx 1.2.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,483 +1,501 @@
1
- var ae = Object.defineProperty;
2
- var ce = (e, n, t) => n in e ? ae(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var w = (e, n, t) => (ce(e, typeof n != "symbol" ? n + "" : n, t), t);
4
- import { filter as v, NEVER as K, merge as A, BehaviorSubject as le, scan as E, map as h, fromEvent as b, mergeMap as T, defer as ge, of as q, takeUntil as x, endWith as he, switchMap as R, exhaustMap as j, shareReplay as Q, withLatestFrom as Y, first as O, share as M, skipUntil as $e, combineLatest as S, ignoreElements as ue, timer as de, buffer as ve, debounceTime as fe, distinctUntilChanged as z } from "rxjs";
5
- function Ae(e, n) {
1
+ var ee = Object.defineProperty;
2
+ var te = (t, s, e) => s in t ? ee(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
3
+ var h = (t, s, e) => (te(t, typeof s != "symbol" ? s + "" : s, e), e);
4
+ import { filter as l, mergeMap as T, defer as ne, of as b, merge as m, takeWhile as N, scan as O, map as g, fromEvent as S, BehaviorSubject as B, switchMap as v, NEVER as se, shareReplay as w, exhaustMap as G, first as Y, share as M, timer as H, withLatestFrom as j, takeUntil as k, skip as ie, tap as pe, ignoreElements as oe, buffer as re, debounceTime as ae, startWith as le, pairwise as he, combineLatest as ce } from "rxjs";
5
+ function ue(t, s) {
6
6
  return Math.sqrt(
7
- Math.pow(n.x - e.x, 2) + Math.pow(n.y - e.y, 2)
7
+ Math.pow(s.x - t.x, 2) + Math.pow(s.y - t.y, 2)
8
8
  );
9
9
  }
10
- function De(e) {
11
- const n = e.length;
12
- if (n < 2)
10
+ function ge(t) {
11
+ const s = t.length;
12
+ if (s < 2)
13
13
  return 0;
14
- const t = e.reduce((o, r, p) => o + e.slice(p + 1).reduce((l, a) => l + Ae(r, a), 0), 0), s = n * (n - 1) / 2;
15
- return t / s;
14
+ const e = t.reduce((n, r, a) => n + t.slice(a + 1).reduce((p, o) => p + ue(r, o), 0), 0), i = s * (s - 1) / 2;
15
+ return e / i;
16
16
  }
17
- function _(e, n) {
18
- const t = n.x - e.x, s = n.y - e.y;
19
- return Math.atan2(s, t);
17
+ function U(t, s) {
18
+ const e = s.x - t.x, i = s.y - t.y;
19
+ return Math.atan2(i, e);
20
20
  }
21
- function ye(e, n) {
22
- return _(e, n) * (180 / Math.PI);
21
+ function $e(t, s) {
22
+ return U(t, s) * (180 / Math.PI);
23
23
  }
24
- function C(e) {
25
- const n = e.reduce(
26
- (s, o) => (s.x += o.x, s.y += o.y, s),
24
+ function z(t) {
25
+ const s = t.reduce(
26
+ (i, n) => (i.x += n.x, i.y += n.y, i),
27
27
  { x: 0, y: 0 }
28
- ), t = e.length || 1;
28
+ ), e = t.length || 1;
29
29
  return {
30
- x: n.x / t,
31
- y: n.y / t
30
+ x: s.x / e,
31
+ y: s.y / e
32
32
  };
33
33
  }
34
- function me(e, n) {
35
- if (e.length !== n.length)
34
+ function de(t, s) {
35
+ if (t.length !== s.length)
36
36
  throw new Error("Initial and new points arrays must have the same length.");
37
- const t = C(e), s = C(n);
38
- let o = 0;
39
- for (let l = 0; l < e.length; l++) {
40
- const a = _(
41
- t,
42
- e[l]
37
+ const e = z(t), i = z(s);
38
+ let n = 0;
39
+ for (let p = 0; p < t.length; p++) {
40
+ const o = U(
41
+ e,
42
+ t[p]
43
43
  );
44
- let c = _(
45
- s,
46
- n[l]
47
- ) - a;
48
- c > Math.PI ? c -= 2 * Math.PI : c < -Math.PI && (c += 2 * Math.PI), o += c;
44
+ let u = U(
45
+ i,
46
+ s[p]
47
+ ) - o;
48
+ u > Math.PI ? u -= 2 * Math.PI : u < -Math.PI && (u += 2 * Math.PI), n += u;
49
49
  }
50
- const r = o / e.length, p = r * (180 / Math.PI);
51
- return { radianDelta: r, degreesDelta: p };
50
+ const r = n / t.length, a = r * (180 / Math.PI);
51
+ return { radianDelta: r, degreesDelta: a };
52
52
  }
53
- function we(e) {
54
- return e != null;
53
+ function ve(t) {
54
+ return t != null;
55
55
  }
56
- const Pe = (e) => e.length > 0, Me = (e) => e.pipe(v(Pe));
57
- function Z(e, n, t) {
58
- const s = C([e]), o = C([n]);
59
- return Math.abs(o.x - s.x) > t || Math.abs(o.y - s.y) > t;
56
+ const ye = (t) => t.length > 0, me = (t) => t.pipe(l(ye));
57
+ function J(t, s, e) {
58
+ const i = z([t]), n = z([s]);
59
+ return Math.abs(n.x - i.x) >= e || Math.abs(n.y - i.y) >= e;
60
60
  }
61
- const Te = (e) => e != null && e.length ? A(...(e == null ? void 0 : e.map(({ start$: n }) => n)) ?? []) : K, xe = (e, n, t) => {
62
- const s = e > 0 ? n / e : 0, o = e > 0 ? t / e : 0;
61
+ const De = (t, s, e) => {
62
+ const i = t > 0 ? s / t : 0, n = t > 0 ? e / t : 0;
63
63
  return {
64
- velocityX: s,
65
- velocityY: o
64
+ velocityX: i,
65
+ velocityY: n
66
66
  };
67
67
  };
68
- class F {
69
- constructor(n) {
70
- w(this, "config$", new le({}));
71
- w(this, "validConfig$", this.config$.pipe(
72
- v(
73
- (n) => !!n.container
74
- )
75
- ));
76
- this.update(n);
77
- }
78
- initialize(n) {
79
- const t = this.config$.getValue();
80
- this.config$.next({
81
- ...t,
82
- ...n,
83
- options: {
84
- ...t.options,
85
- ...n.options
86
- }
87
- });
88
- }
89
- update(n) {
90
- const t = this.config$.getValue();
91
- this.config$.next({
92
- ...t,
93
- options: {
94
- ...t.options,
95
- ...n
96
- }
97
- });
98
- }
68
+ function F(t) {
69
+ return (s) => s.pipe(
70
+ l((e) => e.pointerId === t.pointerId)
71
+ );
99
72
  }
100
- const J = (e, n, t, s) => {
101
- const o = e.x - n.x + t, r = e.y - n.y + s;
73
+ const K = (t) => t.type === "pointerleave" || t.type === "pointercancel" || t.type === "pointerup", Pe = ({
74
+ container: t,
75
+ afterEventReceived: s = (e) => e
76
+ }) => S(t, "pointerdown").pipe(
77
+ g(s)
78
+ ), Q = ({
79
+ pointerEvent$: t
80
+ }) => (s) => {
81
+ const e = t.pipe(
82
+ l((p) => p.type === "pointerup")
83
+ ), i = t.pipe(
84
+ l((p) => p.type === "pointerleave")
85
+ ), n = t.pipe(
86
+ l((p) => p.type === "pointercancel")
87
+ ), r = t.pipe(
88
+ l((p) => p.type === "pointermove")
89
+ ), a = (p) => ["pointercancel", "pointerleave", "pointerup"].includes(p.type);
90
+ return s.pipe(
91
+ T((p) => {
92
+ const o = ne(() => b(p));
93
+ return m(
94
+ o,
95
+ m(r, n, i, e)
96
+ ).pipe(
97
+ F(p),
98
+ N((u) => !a(u), !0)
99
+ );
100
+ }),
101
+ O((p, o) => {
102
+ if (a(o)) {
103
+ const { [o.pointerId]: c, ...u } = (p == null ? void 0 : p.pointers) ?? {};
104
+ return {
105
+ event: o,
106
+ pointers: u
107
+ };
108
+ }
109
+ return {
110
+ event: o,
111
+ pointers: {
112
+ ...(p == null ? void 0 : p.pointers) ?? {},
113
+ [o.pointerId]: o
114
+ }
115
+ };
116
+ }, void 0),
117
+ g(({ event: p, pointers: o }) => ({
118
+ event: p,
119
+ pointers: Object.values(o).filter(ve)
120
+ }))
121
+ );
122
+ }, _ = (t, s, e, i) => {
123
+ const n = t.x - s.x + e, r = t.y - s.y + i;
102
124
  return {
103
- deltaX: o,
125
+ deltaX: n,
104
126
  deltaY: r
105
127
  };
106
- }, W = (e) => {
107
- const n = (t) => C(
108
- t.latestActivePointers.length ? t.latestActivePointers : [t.event]
128
+ }, Z = (t) => {
129
+ const s = (e) => z(
130
+ e.latestActivePointers.length ? e.latestActivePointers : [e.event]
109
131
  );
110
- return e.pipe(
111
- E(
112
- (t, s) => {
113
- var D, m;
114
- const o = n(s), r = t.center, p = t.deltaX, l = t.deltaY, a = ((D = t.latestActivePointers) == null ? void 0 : D.length) ?? 0, $ = ((m = s.latestActivePointers) == null ? void 0 : m.length) ?? 0, c = [
115
- "pointerdown",
116
- "pointercancel",
117
- "pointerleave",
118
- "pointerup"
119
- ].includes(s.event.type) && a !== $, i = $ > 0, { deltaX: g, deltaY: d } = c && i ? J(o, o, p, l) : J(o, r, p, l), { degreesDelta: f } = a === $ && a >= 2 && $ >= 2 ? me(
120
- t.latestActivePointers ?? [],
121
- s.latestActivePointers ?? []
122
- ) : { degreesDelta: 0 };
123
- return {
124
- startTime: (/* @__PURE__ */ new Date()).getTime(),
125
- ...t,
126
- ...s,
127
- center: o,
128
- deltaX: g,
129
- deltaY: d,
130
- deltaPointersAngle: f
131
- };
132
- },
133
- {
134
- deltaX: 0,
135
- deltaY: 0,
136
- center: { x: 0, y: 0 },
137
- latestActivePointers: []
138
- }
139
- ),
140
- h((t) => {
132
+ return t.pipe(
133
+ O((e, i) => {
134
+ var d, x;
135
+ const n = s(i), r = (e == null ? void 0 : e.center) ?? n, a = (e == null ? void 0 : e.deltaX) ?? 0, p = (e == null ? void 0 : e.deltaY) ?? 0, o = ((d = e == null ? void 0 : e.latestActivePointers) == null ? void 0 : d.length) ?? 1, c = ((x = i.latestActivePointers) == null ? void 0 : x.length) ?? 1, u = ["pointerdown", "pointercancel", "pointerleave", "pointerup"].includes(
136
+ i.event.type
137
+ ) && o !== c, f = c > 0, { deltaX: $, deltaY: P } = u && f ? _(n, n, a, p) : _(n, r, a, p), { degreesDelta: D } = o === c && o >= 2 && c >= 2 ? de(
138
+ (e == null ? void 0 : e.latestActivePointers) ?? [],
139
+ i.latestActivePointers ?? []
140
+ ) : { degreesDelta: 0 };
141
+ return {
142
+ startTime: (/* @__PURE__ */ new Date()).getTime(),
143
+ ...e,
144
+ ...i,
145
+ center: n,
146
+ deltaX: $,
147
+ deltaY: P,
148
+ deltaPointersAngle: D
149
+ };
150
+ }, void 0),
151
+ g((e) => {
141
152
  const {
142
- deltaX: s,
143
- deltaY: o,
153
+ deltaX: i,
154
+ deltaY: n,
144
155
  latestActivePointers: r,
145
- startTime: p,
146
- center: l,
147
- event: a,
148
- deltaPointersAngle: $
149
- } = t, c = r ?? [], g = Date.now() - p, { velocityX: d, velocityY: f } = xe(g, s, o), D = De(r);
156
+ startTime: a,
157
+ center: p,
158
+ event: o,
159
+ deltaPointersAngle: c
160
+ } = e, u = r ?? [], $ = Date.now() - a, { velocityX: P, velocityY: D } = De($, i, n), d = ge(r);
150
161
  return {
151
- deltaX: s,
152
- deltaY: o,
153
- velocityX: d,
154
- velocityY: f,
155
- delay: g,
156
- center: l,
157
- pointers: c,
158
- startTime: p,
159
- event: a,
160
- deltaPointersAngle: $,
161
- pointersAverageDistance: D
162
+ deltaX: i,
163
+ deltaY: n,
164
+ velocityX: P,
165
+ velocityY: D,
166
+ delay: $,
167
+ center: p,
168
+ pointers: u,
169
+ startTime: a,
170
+ event: o,
171
+ deltaPointersAngle: c,
172
+ pointersAverageDistance: d
162
173
  };
163
174
  })
164
175
  );
165
- };
166
- function U(e) {
167
- return (n) => n.pipe(
168
- v((t) => t.pointerId === e.pointerId)
169
- );
170
- }
171
- const N = ({
172
- container: e,
173
- afterEventReceived: n = (t) => t
176
+ }, q = (t) => t.pipe(
177
+ l(
178
+ (s) => !!s.container
179
+ )
180
+ ), W = (t) => t.pipe(l(K)), Ae = ({
181
+ container: t,
182
+ afterEventReceived: s = (e) => e
174
183
  }) => {
175
- const t = ee({ afterEventReceived: n, container: e }), s = b(e, "pointerup").pipe(
176
- h(n)
177
- ), o = b(e, "pointermove").pipe(
178
- h(n)
179
- ), r = b(e, "pointerleave").pipe(
180
- h(n)
181
- ), p = b(
182
- e,
184
+ const e = Pe({ afterEventReceived: s, container: t }), i = S(t, "pointerup").pipe(
185
+ g(s)
186
+ ), n = S(t, "pointermove").pipe(
187
+ g(s)
188
+ ), r = S(t, "pointerleave").pipe(
189
+ g(s)
190
+ ), a = S(
191
+ t,
183
192
  "pointercancel"
184
- ).pipe(h(n));
185
- return {
186
- pointerDown$: t,
187
- pointerCancel$: p,
188
- pointerLeave$: r,
189
- pointerUp$: s,
190
- pointerMove$: o
191
- };
192
- }, ee = ({
193
- container: e,
194
- afterEventReceived: n = (t) => t
195
- }) => b(e, "pointerdown").pipe(
196
- h(n)
197
- ), V = ({
198
- pointerCancel$: e,
199
- pointerLeave$: n,
200
- pointerUp$: t,
201
- pointerMove$: s,
202
- trackMove: o
203
- }) => (r) => r.pipe(
204
- T((p) => {
205
- const l = A(
206
- t,
207
- n,
208
- e
209
- ).pipe(U(p)), a = ge(() => q(p));
210
- return A(
211
- a,
212
- o ? s : K
213
- ).pipe(
214
- U(p),
215
- h((c) => ({ id: c.pointerId, event: c })),
216
- x(l),
217
- he({ id: p.pointerId, event: void 0 })
218
- );
219
- }),
220
- E(
221
- (p, { event: l, id: a }) => {
222
- if (!l) {
223
- const { [a]: $, ...c } = p;
224
- return c;
225
- }
226
- return {
227
- ...p,
228
- [a]: l
229
- };
230
- },
231
- {}
232
- ),
233
- h((p) => Object.values(p).filter(we))
234
- );
235
- class B extends F {
236
- constructor(t = {}) {
237
- super(t);
238
- w(this, "events$");
239
- w(this, "start$");
240
- w(this, "end$");
241
- w(this, "fingers$");
242
- this.options = t, this.events$ = this.validConfig$.pipe(
243
- R((s) => {
244
- const { container: o, afterEventReceived: r } = s, { posThreshold: p = 15 } = s.options ?? {}, {
245
- pointerCancel$: l,
246
- pointerDown$: a,
247
- pointerLeave$: $,
248
- pointerMove$: c,
249
- pointerUp$: i
250
- } = N({
251
- container: o,
193
+ ).pipe(g(s));
194
+ return m(
195
+ e,
196
+ a,
197
+ r,
198
+ i,
199
+ n
200
+ );
201
+ };
202
+ class C {
203
+ constructor(s, e) {
204
+ h(this, "configSubject", new B({}));
205
+ h(this, "panEvent$");
206
+ h(this, "pointerEvent$");
207
+ h(this, "pointerDown$");
208
+ h(this, "pointerUp$");
209
+ h(this, "pointerCancel$");
210
+ h(this, "pointerMove$");
211
+ h(this, "pointerOff$");
212
+ h(this, "state$");
213
+ h(this, "failWith$");
214
+ h(this, "config$", this.configSubject.pipe(q));
215
+ const i = new B({
216
+ fingers: 0
217
+ });
218
+ this.pointerEvent$ = this.config$.pipe(
219
+ v(
220
+ ({ container: n, afterEventReceived: r }) => Ae({
221
+ container: n,
252
222
  afterEventReceived: r
253
- });
254
- return a.pipe(
255
- j((g) => {
256
- const d = A(
257
- q(g),
258
- a
259
- ), f = A(
260
- l,
261
- a,
262
- $,
263
- c,
264
- i
265
- ), D = d.pipe(
266
- V({
267
- pointerCancel$: l,
268
- pointerLeave$: $,
269
- pointerUp$: i,
270
- pointerMove$: c,
271
- trackMove: !0
272
- }),
273
- Q()
274
- ), m = A(
275
- i,
276
- $,
277
- l
278
- ).pipe(
279
- Y(D),
280
- v(([u, y]) => !y.length),
281
- h(([u]) => u),
282
- O(),
223
+ })
224
+ )
225
+ ), this.pointerDown$ = this.pointerEvent$.pipe(
226
+ l((n) => n.type === "pointerdown")
227
+ ), this.pointerUp$ = this.pointerEvent$.pipe(
228
+ l((n) => n.type === "pointerup")
229
+ ), this.pointerMove$ = this.pointerEvent$.pipe(
230
+ l((n) => n.type === "pointermove")
231
+ ), this.pointerCancel$ = this.pointerEvent$.pipe(
232
+ l((n) => n.type === "pointercancel")
233
+ ), this.pointerOff$ = this.pointerEvent$.pipe(W), this.failWith$ = this.config$.pipe(
234
+ v(
235
+ ({ failWith: n }) => n != null && n.length ? m(...(n == null ? void 0 : n.map(({ start$: r }) => r)) ?? []) : se
236
+ )
237
+ ), this.panEvent$ = this.configSubject.pipe(
238
+ q,
239
+ v((n) => {
240
+ var f, $, P;
241
+ const r = Math.max(1, ((f = n.panConfig) == null ? void 0 : f.numInputs) ?? 1), a = Math.max(0, (($ = n.panConfig) == null ? void 0 : $.posThreshold) ?? 0), p = Math.max(0, ((P = n.panConfig) == null ? void 0 : P.delay) ?? 0), o = this.pointerDown$.pipe(
242
+ Q({
243
+ pointerEvent$: this.pointerEvent$,
244
+ trackMove: !0
245
+ }),
246
+ w(1)
247
+ ), c = (D) => D.pipe(
248
+ l(
249
+ (d) => d.pointers.length >= r
250
+ )
251
+ ), u = (D) => D.pipe(l((d) => d.pointers.length < r));
252
+ return o.pipe(
253
+ c,
254
+ G(({ pointers: D }) => {
255
+ const d = o.pipe(
256
+ u,
257
+ Y(),
283
258
  M()
284
- ), I = d.pipe(
259
+ ), x = H(p), I = m(
260
+ ...D.map((y) => b(y)),
261
+ this.pointerDown$
262
+ ).pipe(
285
263
  T(
286
- (u) => c.pipe(
287
- U(u),
288
- // we start pan only if the user started moving a certain distance
289
- v(
290
- (y) => Z(
291
- u,
264
+ (y) => m(this.pointerMove$, b(y)).pipe(
265
+ F(y),
266
+ l(
267
+ (E) => J(
292
268
  y,
293
- p
269
+ E,
270
+ a
294
271
  )
295
272
  )
296
273
  )
297
274
  ),
298
- O()
275
+ Y()
299
276
  ).pipe(
300
- h(() => ({
277
+ v(() => x),
278
+ j(o),
279
+ g(([, { event: y, pointers: E }]) => ({
301
280
  type: "panStart",
302
- event: g
281
+ event: y,
282
+ latestActivePointers: E
303
283
  })),
304
- M(),
305
- x(m)
306
- ), k = I.pipe(
284
+ w({
285
+ bufferSize: 1,
286
+ refCount: !1
287
+ }),
288
+ k(d)
289
+ ), A = I.pipe(
290
+ T(
291
+ () => o.pipe(
292
+ ie(1),
293
+ g(({ event: y, pointers: E }) => ({
294
+ type: "panMove",
295
+ event: y,
296
+ latestActivePointers: E
297
+ }))
298
+ )
299
+ ),
300
+ k(d)
301
+ ), L = I.pipe(
307
302
  T(
308
- () => m.pipe(
309
- h((u) => ({
303
+ () => d.pipe(
304
+ g(({ event: y, pointers: E }) => ({
310
305
  type: "panEnd",
311
- event: u
306
+ event: y,
307
+ latestActivePointers: E
312
308
  }))
313
309
  )
314
310
  )
315
- ), L = f.pipe(
316
- $e(I),
317
- h((u) => ({
318
- type: "panMove",
319
- event: u
320
- })),
321
- x(m)
322
- ), X = A(I, L, k).pipe(
323
- Y(D),
324
- h(([u, y]) => ({
325
- ...u,
326
- latestActivePointers: y
327
- })),
328
- M()
311
+ ), R = m(I, A, L).pipe(
312
+ w(1)
329
313
  );
330
- return S([
331
- X.pipe(W),
332
- X
333
- ]).pipe(
334
- h(([u, { type: y }]) => ({
335
- ...u,
336
- type: y
314
+ return R.pipe(
315
+ Z,
316
+ j(R),
317
+ g(([y, { type: E }]) => ({
318
+ ...y,
319
+ type: E
337
320
  }))
338
321
  );
339
322
  })
340
323
  );
341
324
  }),
342
- M()
343
- ), this.start$ = this.events$.pipe(
344
- v((s) => s.type === "panStart")
345
- ), this.end$ = this.events$.pipe(v((s) => s.type === "panEnd")), this.fingers$ = this.validConfig$.pipe(
346
- R(({ container: s, afterEventReceived: o }) => {
347
- const r = N({
348
- container: s,
349
- afterEventReceived: o
325
+ pe((n) => {
326
+ i.next({
327
+ fingers: n.pointers.length
350
328
  });
351
- return r.pointerDown$.pipe(
352
- V({
353
- ...r,
354
- trackMove: !1
355
- })
356
- );
357
329
  }),
358
- h((s) => s.length)
359
- );
330
+ M()
331
+ ), this.state$ = i.asObservable(), this.updateInternal(s ?? {}, e);
332
+ }
333
+ updateInternal(s, e) {
334
+ const i = this.configSubject.getValue();
335
+ this.configSubject.next({
336
+ ...i,
337
+ ...s,
338
+ ...s.options && {
339
+ options: { ...i.options, ...s.options }
340
+ },
341
+ panConfig: {
342
+ ...i.panConfig,
343
+ ...e
344
+ }
345
+ });
346
+ }
347
+ update(s, e) {
348
+ this.updateInternal(s, e);
349
+ }
350
+ }
351
+ class Ie extends C {
352
+ constructor(e) {
353
+ var i;
354
+ super(e, {
355
+ ...e,
356
+ posThreshold: ((i = e == null ? void 0 : e.options) == null ? void 0 : i.posThreshold) ?? 15
357
+ });
358
+ h(this, "events$");
359
+ h(this, "start$");
360
+ h(this, "end$");
361
+ this.events$ = this.panEvent$, this.start$ = this.panEvent$.pipe(
362
+ l((n) => n.type === "panStart")
363
+ ), this.end$ = this.events$.pipe(l((n) => n.type === "panEnd"));
364
+ }
365
+ update(e) {
366
+ super.update(e, e.options);
360
367
  }
361
368
  }
362
- const Re = (e) => (n) => n.pipe(
363
- v((t) => Math.abs(t.velocityX) >= e || Math.abs(t.velocityY) >= e)
369
+ const Ee = (t) => (s) => s.pipe(
370
+ l((e) => Math.abs(e.velocityX) >= t || Math.abs(e.velocityY) >= t)
364
371
  );
365
- class be extends F {
366
- constructor(t = {}) {
367
- super(t);
368
- w(this, "events$");
369
- this.options = t, this.events$ = this.validConfig$.pipe(
370
- R((s) => {
371
- const { escapeVelocity: o = 0.9, posThreshold: r } = s.options ?? {}, p = new B({ posThreshold: r });
372
- p.initialize(s);
373
- const l = p.events$.pipe(
374
- v(({ pointers: a }) => a.length > 1)
375
- );
376
- return p.start$.pipe(
377
- j((a) => p.end$.pipe(
378
- O(),
379
- Re(o),
380
- h(({ type: $, ...c }) => ({
372
+ class Te extends C {
373
+ constructor(e) {
374
+ super(e, {
375
+ posThreshold: 0,
376
+ numInputs: 1
377
+ });
378
+ h(this, "events$");
379
+ this.events$ = this.config$.pipe(
380
+ v((i) => {
381
+ const { escapeVelocity: n = 0.9 } = i.options ?? {}, r = this.panEvent$.pipe(
382
+ l((p) => p.type === "panStart")
383
+ ), a = this.panEvent$.pipe(l((p) => p.type === "panEnd"));
384
+ return r.pipe(
385
+ v((p) => a.pipe(
386
+ Ee(n),
387
+ g(({ type: o, ...c }) => ({
381
388
  type: "swipe",
382
- angle: ye(
383
- a.event,
389
+ angle: $e(
390
+ p.event,
384
391
  c.event
385
392
  ),
386
393
  ...c
387
- })),
388
- x(l)
394
+ }))
389
395
  )),
390
396
  M()
391
397
  );
392
398
  })
393
399
  );
394
400
  }
401
+ update(e) {
402
+ super.update(e);
403
+ }
395
404
  }
396
- class Ce extends F {
397
- constructor(t) {
398
- super(t);
399
- w(this, "events$");
400
- this.options = t, this.events$ = this.validConfig$.pipe(
401
- R((s) => {
402
- const { container: o, afterEventReceived: r } = s, {
403
- multiTapThreshold: p = 200,
404
- maximumPressTime: l = 250,
405
- maxTaps: a = 2,
406
- // threshold should be high because of fingers size
407
- // and potential margin due to it. clicks are nearly perfect
408
- // not fingers.
409
- posThreshold: $ = 10,
410
- failWith: c
411
- } = s.options ?? {}, { pointerUp$: i, pointerLeave$: g, pointerCancel$: d, pointerMove$: f } = N({
412
- container: o,
413
- afterEventReceived: r
414
- }), D = ee({ container: o, afterEventReceived: r }), m = D.pipe(
415
- V({
416
- pointerCancel$: d,
417
- pointerLeave$: g,
418
- pointerMove$: f,
419
- pointerUp$: i,
420
- trackMove: !1
405
+ const fe = ({
406
+ timeout: t,
407
+ pointerEvent$: s
408
+ }) => (e) => e.pipe(
409
+ T(
410
+ (i) => H(t).pipe(
411
+ k(
412
+ s.pipe(W, F(i))
413
+ )
414
+ )
415
+ )
416
+ ), we = ({
417
+ initialPointerEvent: t,
418
+ pointerEvent$: s,
419
+ tolerance: e
420
+ }) => (i) => i.pipe(
421
+ T(
422
+ (n) => s.pipe(
423
+ F(n),
424
+ N((r) => !K(r), !0),
425
+ l(
426
+ (r) => J(t, r, e)
427
+ )
428
+ )
429
+ )
430
+ );
431
+ class be extends C {
432
+ constructor(e) {
433
+ super(e);
434
+ h(this, "events$");
435
+ this.events$ = this.config$.pipe(
436
+ v((i) => {
437
+ const {
438
+ multiTapThreshold: n = 0,
439
+ maximumPressTime: r = 150,
440
+ maxTaps: a = 1,
441
+ tolerance: p = 10
442
+ } = i.options ?? {}, o = this.pointerDown$.pipe(
443
+ Q({
444
+ pointerEvent$: this.pointerEvent$,
445
+ trackMove: !0
421
446
  }),
422
- Q(1)
423
- ), G = m.pipe(
424
- v((u) => u.length > 1)
425
- ), I = (u) => u.pipe(
426
- Y(m),
427
- v(([, y]) => y.length === 1),
428
- h(([y]) => y)
429
- ), k = (u) => u.pipe(
430
- ve(i.pipe(fe(p))),
431
- O()
432
- ), L = Te(c);
433
- return A(
434
- D,
435
- m.pipe(ue())
447
+ w(1)
448
+ ), c = o.pipe(
449
+ l(({ pointers: $ }) => $.length > 1)
450
+ ), u = ($) => $.pipe(
451
+ re(this.pointerUp$.pipe(ae(n))),
452
+ Y()
453
+ );
454
+ return m(
455
+ this.pointerDown$,
456
+ o.pipe(oe())
436
457
  ).pipe(
437
- I,
438
- j((u) => {
439
- const y = A(q(u), D), te = A(
440
- i,
441
- g,
442
- d,
443
- f
444
- ), ne = y.pipe(k), se = te.pipe(
445
- v(
446
- (P) => Z(
447
- u,
448
- P,
449
- $
450
- )
451
- ),
452
- O()
453
- ), oe = m.pipe(
454
- R(() => de(l))
455
- ), ie = A(
456
- L,
458
+ G(($) => {
459
+ const P = m(
460
+ b($),
461
+ this.pointerDown$
462
+ ).pipe(w(1)), D = P.pipe(u), d = P.pipe(
463
+ we({
464
+ initialPointerEvent: $,
465
+ pointerEvent$: this.pointerEvent$,
466
+ tolerance: p
467
+ })
468
+ ), x = P.pipe(
469
+ fe({
470
+ pointerEvent$: this.pointerEvent$,
471
+ timeout: r
472
+ })
473
+ ), V = m(
474
+ this.failWith$,
475
+ this.pointerCancel$,
476
+ c,
457
477
  d,
458
- G,
459
- se,
460
- oe
461
- ), H = ne.pipe(
462
- Me,
463
- v((P) => P.length <= a),
464
- h((P) => ({
478
+ x
479
+ ), I = D.pipe(
480
+ me,
481
+ l((A) => A.length <= a),
482
+ g((A) => ({
465
483
  type: "tap",
466
- taps: P.length,
467
- latestActivePointers: P,
468
- event: P[0]
469
- }))
484
+ taps: A.length,
485
+ latestActivePointers: A,
486
+ event: A[0]
487
+ })),
488
+ w(1)
470
489
  );
471
- return S([
472
- H.pipe(W),
473
- H
474
- ]).pipe(
475
- h(([P, { type: re, taps: pe }]) => ({
476
- ...P,
477
- type: re,
478
- taps: pe
490
+ return I.pipe(
491
+ Z,
492
+ j(I),
493
+ g(([A, { type: L, taps: R }]) => ({
494
+ ...A,
495
+ type: L,
496
+ taps: R
479
497
  })),
480
- x(ie)
498
+ k(V)
481
499
  );
482
500
  })
483
501
  );
@@ -485,143 +503,167 @@ class Ce extends F {
485
503
  M()
486
504
  );
487
505
  }
506
+ update(e) {
507
+ super.update(e);
508
+ }
488
509
  }
489
- class Fe extends F {
490
- constructor(t = {}) {
491
- super(t);
492
- w(this, "events$");
493
- this.options = t, this.events$ = this.config$.pipe(
494
- R((s) => {
495
- const { posThreshold: o } = s.options ?? {}, r = new B({ posThreshold: o });
496
- r.initialize(s);
497
- const p = r.events$.pipe(
498
- v(({ pointers: i }) => i.length < 2),
499
- z()
500
- ), a = r.events$.pipe(
501
- h((i) => [i, i.pointers.length > 1]),
502
- z(
503
- ([i, g], [d, f]) => g === f
504
- ),
505
- v(([i, g]) => g)
506
- ).pipe(
507
- h(([i]) => ({
508
- ...i,
510
+ class Se extends C {
511
+ constructor(e = {}) {
512
+ super(e, {
513
+ numInputs: 2,
514
+ posThreshold: 15,
515
+ ...e.options
516
+ });
517
+ h(this, "events$");
518
+ this.events$ = this.config$.pipe(
519
+ v(() => {
520
+ const i = this.panEvent$.pipe(
521
+ l((p) => p.type === "panStart"),
522
+ g((p) => ({
523
+ ...p,
509
524
  type: "rotateStart",
510
525
  angle: 0,
511
526
  deltaAngle: 0
512
- }))
513
- ), $ = a.pipe(
514
- T(
515
- () => r.events$.pipe(
516
- E(
517
- (i, g) => {
518
- const d = i.angle + g.deltaPointersAngle;
519
- return {
520
- ...i,
521
- ...g,
522
- type: "rotate",
523
- angle: d,
524
- deltaAngle: g.deltaPointersAngle
525
- };
526
- },
527
- { angle: 0, deltaAngle: 0 }
528
- ),
529
- x(p)
530
- )
531
- )
532
- ), c = a.pipe(
533
- T(
534
- () => S([$, p]).pipe(
535
- O(),
536
- h(([i]) => ({
537
- ...i,
538
- type: "rotateEnd"
539
- }))
527
+ })),
528
+ w(1)
529
+ ), n = i.pipe(
530
+ v(
531
+ () => this.panEvent$.pipe(
532
+ O((p, o) => {
533
+ const c = ((p == null ? void 0 : p.angle) ?? 0) + o.deltaPointersAngle;
534
+ return {
535
+ ...p,
536
+ ...o,
537
+ angle: c,
538
+ deltaAngle: o.deltaPointersAngle
539
+ };
540
+ }, void 0)
540
541
  )
541
- )
542
+ ),
543
+ M()
544
+ ), r = n.pipe(
545
+ l((p) => p.type === "panMove"),
546
+ g((p) => ({ ...p, type: "rotateMove" }))
547
+ ), a = n.pipe(
548
+ l((p) => p.type === "panEnd"),
549
+ g((p) => ({ ...p, type: "rotateEnd" }))
542
550
  );
543
- return A(a, $, c);
544
- })
551
+ return m(i, r, a);
552
+ }),
553
+ M()
545
554
  );
546
555
  }
556
+ update(e) {
557
+ super.update(e, e.options);
558
+ }
547
559
  }
548
- class ze extends F {
549
- constructor(t = {}) {
550
- super(t);
551
- w(this, "events$");
552
- this.options = t, this.events$ = this.config$.pipe(
553
- R((s) => {
554
- const { posThreshold: o } = s.options ?? {}, r = new B({ posThreshold: o });
555
- r.initialize(s);
556
- const p = r.events$.pipe(
557
- v(({ pointers: i }) => i.length < 2),
558
- z()
559
- ), a = r.events$.pipe(
560
- h((i) => [i, i.pointers.length > 1]),
561
- z(
562
- ([i, g], [d, f]) => g === f
560
+ const X = ({
561
+ type: t,
562
+ initialEvent: s
563
+ }) => (e) => e.pipe(
564
+ O((i, n) => {
565
+ const a = ((i == null ? void 0 : i.pointers.length) ?? 0) !== n.pointers.length, p = (i == null ? void 0 : i.pointersAverageDistance) ?? n.pointersAverageDistance, o = a ? n.pointersAverageDistance : i && "initialPointersAverageDistance" in i ? i.initialPointersAverageDistance : n.pointersAverageDistance, c = o === 0 ? 1 : n.pointersAverageDistance / o, u = n.pointersAverageDistance - o, f = n.pointersAverageDistance - o, $ = a || p === 0 ? 1 : n.pointersAverageDistance / p;
566
+ return {
567
+ ...i,
568
+ ...n,
569
+ type: t,
570
+ initialPointersAverageDistance: o,
571
+ scale: c,
572
+ distance: u,
573
+ deltaDistance: f,
574
+ deltaDistanceScale: $
575
+ };
576
+ }, s),
577
+ g(({ initialPointersAverageDistance: i, ...n }) => n)
578
+ );
579
+ class ze extends C {
580
+ constructor(e) {
581
+ super(e, {
582
+ ...e == null ? void 0 : e.options,
583
+ numInputs: 2
584
+ });
585
+ h(this, "events$");
586
+ this.events$ = this.config$.pipe(
587
+ v(() => {
588
+ const i = this.panEvent$.pipe(
589
+ l((a) => a.type === "panStart"),
590
+ v(
591
+ (a) => b(a).pipe(
592
+ X({
593
+ type: "pinchStart",
594
+ initialEvent: void 0
595
+ })
596
+ )
563
597
  ),
564
- v(([i, g]) => g)
565
- ).pipe(
566
- h(([i]) => ({
567
- ...i,
568
- type: "pinchStart",
569
- scale: 1,
570
- distance: 0,
571
- deltaDistance: 0,
572
- deltaDistanceScale: 1
573
- }))
574
- ), $ = a.pipe(
575
- T((i) => r.events$.pipe(
576
- E(
577
- (g, d) => {
578
- const f = g.pointersAverageDistance ?? d.pointersAverageDistance, D = d.pointersAverageDistance / i.pointersAverageDistance;
579
- return {
580
- ...g,
581
- ...d,
582
- scale: D,
583
- distance: d.pointersAverageDistance - i.pointersAverageDistance,
584
- deltaDistance: d.pointersAverageDistance - f,
585
- deltaDistanceScale: d.pointersAverageDistance / f,
586
- type: "pinchMove"
587
- };
588
- },
589
- { scale: 0 }
590
- ),
591
- x(p)
598
+ w(1)
599
+ ), n = i.pipe(
600
+ v((a) => this.panEvent$.pipe(
601
+ N((p) => p.type !== "panEnd"),
602
+ X({
603
+ type: "pinchMove",
604
+ initialEvent: a
605
+ })
592
606
  ))
593
- ), c = a.pipe(
594
- T(
595
- () => S([$, p]).pipe(
596
- O(),
597
- h(([i]) => ({
598
- ...i,
599
- type: "pinchEnd"
600
- }))
607
+ ), r = i.pipe(
608
+ v(
609
+ (a) => this.panEvent$.pipe(
610
+ // we cannot have a panEnd without a previous event so it will always emit
611
+ le(a),
612
+ he(),
613
+ l(([p, o]) => o.type === "panEnd"),
614
+ v(
615
+ ([p, o]) => b(o).pipe(
616
+ X({
617
+ type: "pinchEnd",
618
+ initialEvent: p
619
+ })
620
+ )
621
+ )
601
622
  )
602
623
  )
603
624
  );
604
- return A(a, $, c);
605
- })
625
+ return m(i, n, r);
626
+ }),
627
+ M()
606
628
  );
607
629
  }
630
+ update(e) {
631
+ super.update(e, e.options);
632
+ }
633
+ }
634
+ class Ce {
635
+ constructor(s) {
636
+ h(this, "events$");
637
+ h(this, "recognizers");
638
+ h(this, "state$");
639
+ this.options = s, this.recognizers = s.recognizers, this.events$ = m(
640
+ ...s.recognizers.map((e) => e.events$)
641
+ ).pipe(M()), this.state$ = ce(
642
+ this.recognizers.map((e) => e.state$)
643
+ ).pipe(
644
+ g(
645
+ (e) => e.reduce((i, n) => ({
646
+ fingers: Math.max(i.fingers, n.fingers)
647
+ }))
648
+ )
649
+ );
650
+ }
651
+ initialize(s) {
652
+ s.style.touchAction = "none", s.style.userSelect = "none", this.options.recognizers.forEach((e) => {
653
+ console.log("recognizable update"), e.update({
654
+ container: s,
655
+ afterEventReceived: this.options.afterEventReceived
656
+ });
657
+ });
658
+ }
608
659
  }
609
- const Ee = ({
610
- afterEventReceived: e = (t) => t,
611
- recognizers: n
612
- }) => ({ events$: A(
613
- ...n.map((o) => o.events$)
614
- ).pipe(M()), initialize: (o) => {
615
- o.style.touchAction = "none", o.style.userSelect = "none", n.forEach((r) => {
616
- r.initialize({ container: o, afterEventReceived: e });
617
- });
618
- }, recognizers: n });
619
660
  export {
620
- B as PanRecognizer,
661
+ Ie as PanRecognizer,
621
662
  ze as PinchRecognizer,
622
- Fe as RotateRecognizer,
623
- be as SwipeRecognizer,
624
- Ce as TapRecognizer,
625
- Ee as createManager
663
+ Ce as Recognizable,
664
+ C as Recognizer,
665
+ Se as RotateRecognizer,
666
+ Te as SwipeRecognizer,
667
+ be as TapRecognizer
626
668
  };
627
669
  //# sourceMappingURL=index.js.map