@zoompinch/core 0.0.27 → 0.0.30

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,58 +1,53 @@
1
- var x = Object.defineProperty;
2
- var I = (o, h, t) => h in o ? x(o, h, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[h] = t;
3
- var f = (o, h, t) => I(o, typeof h != "symbol" ? h + "" : h, t);
4
- function W(o) {
5
- return o * Math.PI / 180;
1
+ var P = Object.defineProperty;
2
+ var z = (h, l, t) => l in h ? P(h, l, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[l] = t;
3
+ var d = (h, l, t) => z(h, typeof l != "symbol" ? l + "" : l, t);
4
+ function F(h) {
5
+ return h * Math.PI / 180;
6
6
  }
7
- function C(o, h, t) {
8
- return Math.min(Math.max(o, h), t);
7
+ function B(h, l, t) {
8
+ return Math.min(Math.max(h, l), t);
9
9
  }
10
- function w(o, h, t) {
11
- const [s, e] = o, [a, n] = h, r = Math.cos(t) * (s - a) - Math.sin(t) * (e - n) + a, i = Math.sin(t) * (s - a) + Math.cos(t) * (e - n) + n;
10
+ function v(h, l, t) {
11
+ const [e, s] = h, [a, n] = l, r = Math.cos(t) * (e - a) - Math.sin(t) * (s - n) + a, i = Math.sin(t) * (e - a) + Math.cos(t) * (s - n) + n;
12
12
  return [r, i];
13
13
  }
14
- function Y(o, h) {
15
- const t = Math.pow(10, h);
16
- return Math.round(o * t) / t;
17
- }
18
- function z(o) {
19
- var h = !1;
20
- return o.wheelDeltaY ? o.wheelDeltaY === o.deltaY * -3 && (h = !0) : o.deltaMode === 0 && (h = !0), h;
21
- }
22
- function B(o, h) {
23
- const t = h.find((s) => o % s === 0);
24
- return t ? o / t : 1;
25
- }
26
- function y(o, h, t, s, e) {
27
- let a = o.left - h, n = o.top - t;
28
- const r = Math.cos(-e), i = Math.sin(-e);
29
- let c = a * r - n * i, l = a * i + n * r;
30
- const u = o.width / s, d = o.height / s;
31
- return c /= s, l /= s, { x: Y(c, 4), y: Y(l, 4), width: Y(u, 4), height: Y(d, 4) };
14
+ function I(h) {
15
+ if (h.ctrlKey) {
16
+ const { deltaY: t, deltaMode: e, ctrlKey: s } = h, a = Math.abs(t), n = a === 120 || a === 100 || a === 3, r = t % 1 !== 0, i = e === 0;
17
+ return s ? a < 50 && i || r : !n && (r || i && a < 50);
18
+ } else {
19
+ var l = !1;
20
+ return h.wheelDeltaY ? h.wheelDeltaY === h.deltaY * -3 && (l = !0) : h.deltaMode === 0 && (l = !0), l;
21
+ }
32
22
  }
33
- class E extends EventTarget {
34
- constructor(t, s, e, a, n, r, i = 0.1, c = 10, l = !1, u = !0) {
23
+ class x extends EventTarget {
24
+ constructor(t, e, s, a, n, r, i = 0.1, c = 10, o = !1, u = !0) {
35
25
  super();
36
- f(this, "wrapperBounds");
37
- f(this, "canvasBounds");
38
- f(this, "gestureStartRotate", 0);
39
- f(this, "dragStart", null);
40
- f(this, "dragStartFrozenX", null);
41
- f(this, "dragStartFrozenY", null);
42
- f(this, "touchStarts", null);
43
- f(this, "touchStartTranslateX", 0);
44
- f(this, "touchStartTranslateY", 0);
45
- this.element = t, this.offset = s, this.translateX = e, this.translateY = a, this.scale = n, this.rotate = r, this.minScale = i, this.maxScale = c, this.clampBounds = l, this.rotation = u;
46
- const d = new ResizeObserver(() => {
47
- const { x: g, y: m, width: S, height: v } = this.element.getBoundingClientRect();
48
- this.wrapperBounds = { x: g, y: m, width: S, height: v }, this.update();
49
- }), p = new ResizeObserver(() => {
50
- const { x: g, y: m, width: S, height: v } = y(this.canvasElement.getBoundingClientRect(), this.renderingTranslateX, this.renderingTranslateY, this.renderinScale, this.renderingRotate);
51
- this.canvasBounds = { x: g, y: m, width: S, height: v }, this.update();
26
+ d(this, "wrapperBounds");
27
+ d(this, "canvasBounds");
28
+ d(this, "translateSpeed", 1);
29
+ d(this, "zoomSpeed", 1);
30
+ d(this, "translateSpeedAppleTrackpad", 1);
31
+ d(this, "zoomSpeedAppleTrackpad", 1);
32
+ d(this, "isGestureActive", !1);
33
+ d(this, "gestureStartRotate", 0);
34
+ d(this, "dragStart", null);
35
+ d(this, "dragStartFrozenX", null);
36
+ d(this, "dragStartFrozenY", null);
37
+ d(this, "touchStarts", null);
38
+ d(this, "touchStartTranslateX", 0);
39
+ d(this, "touchStartTranslateY", 0);
40
+ this.element = t, this.offset = e, this.translateX = s, this.translateY = a, this.scale = n, this.rotate = r, this.minScale = i, this.maxScale = c, this.clampBounds = o, this.rotation = u;
41
+ const p = new ResizeObserver(() => {
42
+ const { x: g, y: m, width: S, height: Y } = this.element.getBoundingClientRect();
43
+ this.wrapperBounds = { x: g, y: m, width: S, height: Y }, this.update();
44
+ }), f = new ResizeObserver((g) => {
45
+ const { width: m, height: S } = g[0].contentRect;
46
+ (m !== this.canvasBounds.width || S !== this.canvasBounds.height) && (this.canvasBounds = { ...this.canvasBounds, width: m, height: S }, this.isGestureActive || this.update());
52
47
  });
53
48
  requestAnimationFrame(() => {
54
49
  this.wrapperBounds = this.element.getBoundingClientRect(), this.canvasBounds = this.canvasElement.getBoundingClientRect(), this.update(), this.dispatchEvent(new Event("init"));
55
- }), p.observe(this.canvasElement), d.observe(this.element);
50
+ }), f.observe(this.canvasElement), p.observe(this.element);
56
51
  }
57
52
  get canvasElement() {
58
53
  return this.element.querySelector(".canvas");
@@ -82,22 +77,22 @@ class E extends EventTarget {
82
77
  }
83
78
  // The clamping is an explicit user intention
84
79
  // The reason is that we do not want side effects when toggling the clamp
85
- setTranslateFromUserGesture(t, s) {
80
+ setTranslateFromUserGesture(t, e) {
86
81
  if (this.clampBounds) {
87
- const e = this.clampTranslate({ translateX: t, translateY: s, scale: this.scale, rotate: this.rotate });
88
- this.translateX = e.translateX, this.translateY = e.translateY, this.rotate = 0;
82
+ const s = this.clampTranslate({ translateX: t, translateY: e, scale: this.scale, rotate: this.rotate });
83
+ this.translateX = s.translateX, this.translateY = s.translateY, this.rotate = 0;
89
84
  } else
90
- this.translateX = t, this.translateY = s;
85
+ this.translateX = t, this.translateY = e;
91
86
  }
92
87
  handleGesturestart(t) {
93
88
  this.gestureStartRotate = this.rotate;
94
89
  }
95
90
  handleGesturechange(t) {
96
- const { clientX: s, clientY: e } = t, a = t.rotation;
91
+ const { clientX: e, clientY: s } = t, a = t.rotation;
97
92
  if (a === 0 || !this.rotation)
98
93
  return;
99
- const n = this.normalizeClientCoords(s, e);
100
- this.rotateCanvas(n[0], n[1], this.gestureStartRotate + W(a));
94
+ const n = this.normalizeClientCoords(e, s);
95
+ this.rotateCanvas(n[0], n[1], this.gestureStartRotate + F(a));
101
96
  }
102
97
  handleGestureend(t) {
103
98
  }
@@ -109,109 +104,117 @@ class E extends EventTarget {
109
104
  }
110
105
  handleMousemove(t) {
111
106
  if (t.preventDefault(), this.dragStart && this.dragStartFrozenX !== null && this.dragStartFrozenY !== null) {
112
- const s = t.clientX - this.dragStart[0], e = t.clientY - this.dragStart[1], a = this.dragStartFrozenX - -s, n = this.dragStartFrozenY - -e;
107
+ const e = t.clientX - this.dragStart[0], s = t.clientY - this.dragStart[1], a = this.dragStartFrozenX - -e, n = this.dragStartFrozenY - -s;
113
108
  this.setTranslateFromUserGesture(a, n), this.update();
114
109
  }
115
110
  }
116
111
  handleWheel(t) {
117
- let { deltaX: s, deltaY: e, ctrlKey: a } = t;
118
- const n = [120, 100], r = 2;
119
- z(t) || ((Math.abs(s) === 120 || Math.abs(s) === 200) && (s = s / (100 / r * B(s, n)) * Math.sign(s)), (Math.abs(e) === 120 || Math.abs(e) === 200) && (e = e / (100 / r * B(e, n)) * Math.sign(e)));
120
- const i = this.scale;
112
+ let { deltaX: e, deltaY: s, ctrlKey: a } = t;
113
+ const n = I(t);
114
+ n || (Math.abs(s) >= 100 && (s = Math.sign(s) * (Math.abs(s) / 120)), Math.abs(e) >= 100 && (e = Math.sign(e) * (Math.abs(e) / 120)));
115
+ const r = this.scale;
121
116
  if (a) {
122
- const c = -e / 100 * i, l = C(i + c, this.minScale, this.maxScale), u = this.relativeWrapperCoordinatesFromClientCoords(t.clientX, t.clientY), [d, p] = this.calcProjectionTranslate(l, u, this.normalizeMatrixCoordinates(t.clientX, t.clientY));
123
- this.setTranslateFromUserGesture(d, p), this.scale = l;
124
- } else
125
- this.setTranslateFromUserGesture(this.translateX - s, this.translateY - e);
117
+ const i = n ? 0.01 * this.zoomSpeedAppleTrackpad : 0.1 * this.zoomSpeed, c = 1 + -s * i;
118
+ let o = r * c;
119
+ if (o = B(o, this.minScale, this.maxScale), (o === this.minScale || o === this.maxScale) && (o === this.minScale && c < 1 || o === this.maxScale && c > 1)) {
120
+ t.preventDefault();
121
+ return;
122
+ }
123
+ const u = this.relativeWrapperCoordinatesFromClientCoords(t.clientX, t.clientY), [p, f] = this.calcProjectionTranslate(o, u, this.normalizeMatrixCoordinates(t.clientX, t.clientY));
124
+ this.setTranslateFromUserGesture(p, f), this.scale = o;
125
+ } else {
126
+ const i = n ? 1 * this.translateSpeedAppleTrackpad : 25 * this.translateSpeed;
127
+ this.setTranslateFromUserGesture(this.translateX - e * i, this.translateY - s * i);
128
+ }
126
129
  this.update(), t.preventDefault();
127
130
  }
128
131
  freezeTouches(t) {
129
- return Array.from(t).map((s) => {
130
- const e = this.clientCoordsToWrapperCoords(s.clientX, s.clientY);
132
+ return Array.from(t).map((e) => {
133
+ const s = this.clientCoordsToWrapperCoords(e.clientX, e.clientY);
131
134
  return {
132
- client: [s.clientX, s.clientY],
133
- canvasRel: this.getCanvasCoordsRel(e[0], e[1])
135
+ client: [e.clientX, e.clientY],
136
+ canvasRel: this.getCanvasCoordsRel(s[0], s[1])
134
137
  };
135
138
  });
136
139
  }
137
140
  handleTouchstart(t) {
138
- this.touchStarts = this.freezeTouches(t.touches), this.touchStartTranslateX = this.translateX, this.touchStartTranslateY = this.translateY, t.preventDefault();
141
+ this.touchStarts = this.freezeTouches(t.touches), this.touchStartTranslateX = this.translateX, this.touchStartTranslateY = this.translateY, this.isGestureActive = !0, t.preventDefault();
139
142
  }
140
143
  handleTouchmove(t) {
141
144
  t.preventDefault();
142
- const s = Array.from(t.touches).map((e) => this.clientCoordsToWrapperCoords(e.clientX, e.clientY));
145
+ const e = Array.from(t.touches).map((s) => this.clientCoordsToWrapperCoords(s.clientX, s.clientY));
143
146
  if (this.touchStarts) {
144
- if (s.length >= 2 && this.touchStarts.length >= 2) {
145
- const e = [this.touchStarts[0].canvasRel[0] * this.canvasBounds.width, this.touchStarts[0].canvasRel[1] * this.canvasBounds.height], a = [this.touchStarts[1].canvasRel[0] * this.canvasBounds.width, this.touchStarts[1].canvasRel[1] * this.canvasBounds.height], n = Math.sqrt(Math.pow(e[0] - a[0], 2) + Math.pow(e[1] - a[1], 2)), r = Math.sqrt(Math.pow(s[0][0] - s[1][0], 2) + Math.pow(s[0][1] - s[1][1], 2)) / this.naturalScale, i = C(r / n, this.minScale, this.maxScale), c = [s[0][0] / this.wrapperInnerWidth, s[0][1] / this.wrapperInnerHeight], l = this.touchStarts[0].canvasRel, [u, d] = this.calcProjectionTranslate(i, c, l, 0);
147
+ if (e.length >= 2 && this.touchStarts.length >= 2) {
148
+ const s = [this.touchStarts[0].canvasRel[0] * this.canvasBounds.width, this.touchStarts[0].canvasRel[1] * this.canvasBounds.height], a = [this.touchStarts[1].canvasRel[0] * this.canvasBounds.width, this.touchStarts[1].canvasRel[1] * this.canvasBounds.height], n = Math.sqrt(Math.pow(s[0] - a[0], 2) + Math.pow(s[1] - a[1], 2)), r = Math.sqrt(Math.pow(e[0][0] - e[1][0], 2) + Math.pow(e[0][1] - e[1][1], 2)) / this.naturalScale, i = B(r / n, this.minScale, this.maxScale), c = [e[0][0] / this.wrapperInnerWidth, e[0][1] / this.wrapperInnerHeight], o = this.touchStarts[0].canvasRel, [u, p] = this.calcProjectionTranslate(i, c, o, 0);
146
149
  if (this.rotation) {
147
- let p = 0, g = 0, m = 0;
148
- const S = Math.atan2(a[1] - e[1], a[0] - e[0]);
149
- m = Math.atan2(s[1][1] - s[0][1], s[1][0] - s[0][0]) - S;
150
- const T = (P, F) => [this.offset.left + this.canvasBounds.width * P * this.naturalScale * i + u, this.offset.top + this.canvasBounds.height * F * this.naturalScale * i + d], X = T(0, 0), M = T(this.touchStarts[0].canvasRel[0], this.touchStarts[0].canvasRel[1]), R = w(X, M, m);
151
- p = R[0] - X[0], g = R[1] - X[1], this.scale = i, this.rotate = m, this.setTranslateFromUserGesture(u + p, d + g);
150
+ let f = 0, g = 0, m = 0;
151
+ const S = Math.atan2(a[1] - s[1], a[0] - s[0]);
152
+ m = Math.atan2(e[1][1] - e[0][1], e[1][0] - e[0][0]) - S;
153
+ const X = (R, M) => [this.offset.left + this.canvasBounds.width * R * this.naturalScale * i + u, this.offset.top + this.canvasBounds.height * M * this.naturalScale * i + p], w = X(0, 0), C = X(this.touchStarts[0].canvasRel[0], this.touchStarts[0].canvasRel[1]), T = v(w, C, m);
154
+ f = T[0] - w[0], g = T[1] - w[1], this.scale = i, this.rotate = m, this.setTranslateFromUserGesture(u + f, p + g);
152
155
  } else
153
- this.scale = i, this.setTranslateFromUserGesture(u, d);
156
+ this.scale = i, this.setTranslateFromUserGesture(u, p);
154
157
  } else {
155
- const e = t.touches[0].clientX - this.touchStarts[0].client[0], a = t.touches[0].clientY - this.touchStarts[0].client[1], n = this.touchStartTranslateX + e, r = this.touchStartTranslateY + a;
158
+ const s = t.touches[0].clientX - this.touchStarts[0].client[0], a = t.touches[0].clientY - this.touchStarts[0].client[1], n = this.touchStartTranslateX + s, r = this.touchStartTranslateY + a;
156
159
  this.setTranslateFromUserGesture(n, r);
157
160
  }
158
161
  this.update();
159
162
  }
160
163
  }
161
164
  handleTouchend(t) {
162
- t.touches.length === 0 ? this.touchStarts = null : (this.touchStarts = this.freezeTouches(t.touches), this.touchStartTranslateX = this.translateX, this.touchStartTranslateY = this.translateY);
165
+ t.touches.length === 0 ? this.touchStarts = null : (this.touchStarts = this.freezeTouches(t.touches), this.touchStartTranslateX = this.translateX, this.touchStartTranslateY = this.translateY), this.isGestureActive = !1;
163
166
  }
164
- calcProjectionTranslate(t, s, e, a) {
165
- const n = this.canvasBounds.width * this.naturalScale, r = this.canvasBounds.height * this.naturalScale, i = e[0] * n * t, c = e[1] * r * t, l = w([i, c], [0, 0], a ?? this.rotate), u = s[0] * this.wrapperInnerWidth, d = s[1] * this.wrapperInnerHeight, p = u - l[0], g = d - l[1];
166
- return [p, g];
167
+ calcProjectionTranslate(t, e, s, a) {
168
+ const n = this.canvasBounds.width * this.naturalScale, r = this.canvasBounds.height * this.naturalScale, i = s[0] * n * t, c = s[1] * r * t, o = v([i, c], [0, 0], a ?? this.rotate), u = e[0] * this.wrapperInnerWidth, p = e[1] * this.wrapperInnerHeight, f = u - o[0], g = p - o[1];
169
+ return [f, g];
167
170
  }
168
- applyTransform(t, s, e) {
169
- const a = this.calcProjectionTranslate(t, s, e, 0);
171
+ applyTransform(t, e, s) {
172
+ const a = this.calcProjectionTranslate(t, e, s, 0);
170
173
  this.scale = t, this.setTranslateFromUserGesture(a[0], a[1]), this.update();
171
174
  }
172
- composeRelPoint(t, s, e, a, n, r) {
173
- e = e ?? this.scale, a = a ?? this.translateX, n = n ?? this.translateY, r = r ?? this.rotate;
174
- const i = [this.offset.left, this.offset.top], c = [this.offset.left + this.canvasBounds.width * (e * this.naturalScale) * t, this.offset.top + this.canvasBounds.height * (e * this.naturalScale) * s], l = w(c, i, r);
175
- return [l[0] + a, l[1] + n];
175
+ composeRelPoint(t, e, s, a, n, r) {
176
+ s = s ?? this.scale, a = a ?? this.translateX, n = n ?? this.translateY, r = r ?? this.rotate;
177
+ const i = [this.offset.left, this.offset.top], c = [this.offset.left + this.canvasBounds.width * (s * this.naturalScale) * t, this.offset.top + this.canvasBounds.height * (s * this.naturalScale) * e], o = v(c, i, r);
178
+ return [o[0] + a, o[1] + n];
176
179
  }
177
- composePoint(t, s) {
178
- const e = t / this.canvasBounds.width, a = s / this.canvasBounds.height;
179
- return this.composeRelPoint(e, a);
180
+ composePoint(t, e) {
181
+ const s = t / this.canvasBounds.width, a = e / this.canvasBounds.height;
182
+ return this.composeRelPoint(s, a);
180
183
  }
181
- getAnchorOffset(t, s, e, a, n = [0.5, 0.5]) {
184
+ getAnchorOffset(t, e, s, a, n = [0.5, 0.5]) {
182
185
  const r = this.calcProjectionTranslate(t, n, n, 0), i = [
183
186
  this.offset.left + r[0] + this.canvasBounds.width * (t * this.naturalScale) * n[0],
184
187
  this.offset.top + r[1] + this.canvasBounds.height * (t * this.naturalScale) * n[1]
185
- ], c = this.composeRelPoint(n[0], n[1], t, s, e, a), l = c[0] - i[0], u = c[1] - i[1];
186
- return [l, u];
188
+ ], c = this.composeRelPoint(n[0], n[1], t, e, s, a), o = c[0] - i[0], u = c[1] - i[1];
189
+ return [o, u];
187
190
  }
188
191
  // Converts absolute inner wrapper coordinates to relative canvas coordinates (0-1, 0-1)
189
- getCanvasCoordsRel(t, s) {
190
- const e = [0, 0], a = [t - this.translateX, s - this.translateY], n = w(a, e, -this.rotate), r = [n[0] / this.renderinScale, n[1] / this.renderinScale];
192
+ getCanvasCoordsRel(t, e) {
193
+ const s = [0, 0], a = [t - this.translateX, e - this.translateY], n = v(a, s, -this.rotate), r = [n[0] / this.renderinScale, n[1] / this.renderinScale];
191
194
  return [r[0] / this.canvasBounds.width, r[1] / this.canvasBounds.height];
192
195
  }
193
196
  // Converts absolute client to coordinates to absolute inner-wrapper coorinates
194
- clientCoordsToWrapperCoords(t, s) {
195
- return [t - this.wrapperInnerX, s - this.wrapperInnerY];
197
+ clientCoordsToWrapperCoords(t, e) {
198
+ return [t - this.wrapperInnerX, e - this.wrapperInnerY];
196
199
  }
197
200
  // Converts absolute client coordinates to relative wrapper coordinates (0-1, 0-1)
198
- relativeWrapperCoordinatesFromClientCoords(t, s) {
199
- const [e, a] = this.clientCoordsToWrapperCoords(t, s);
200
- return [e / this.wrapperInnerWidth, a / this.wrapperInnerHeight];
201
+ relativeWrapperCoordinatesFromClientCoords(t, e) {
202
+ const [s, a] = this.clientCoordsToWrapperCoords(t, e);
203
+ return [s / this.wrapperInnerWidth, a / this.wrapperInnerHeight];
201
204
  }
202
205
  // Converts client coordinates to relative canvas coordinates (0-1, 0-1)
203
- normalizeMatrixCoordinates(t, s) {
204
- const e = this.clientCoordsToWrapperCoords(t, s);
205
- return this.getCanvasCoordsRel(e[0], e[1]);
206
+ normalizeMatrixCoordinates(t, e) {
207
+ const s = this.clientCoordsToWrapperCoords(t, e);
208
+ return this.getCanvasCoordsRel(s[0], s[1]);
206
209
  }
207
210
  // Converts client coordinates to absolute canvas coordinates
208
- normalizeClientCoords(t, s) {
209
- const [e, a] = this.normalizeMatrixCoordinates(t, s);
210
- return [e * this.canvasBounds.width, a * this.canvasBounds.height];
211
+ normalizeClientCoords(t, e) {
212
+ const [s, a] = this.normalizeMatrixCoordinates(t, e);
213
+ return [s * this.canvasBounds.width, a * this.canvasBounds.height];
211
214
  }
212
- rotateCanvas(t, s, e) {
213
- const a = t / this.canvasBounds.width, n = s / this.canvasBounds.height, r = this.composeRelPoint(a, n, this.scale, 0, 0, e), i = this.composeRelPoint(a, n);
214
- this.setTranslateFromUserGesture(i[0] - r[0], i[1] - r[1]), this.rotate = e, this.update();
215
+ rotateCanvas(t, e, s) {
216
+ const a = t / this.canvasBounds.width, n = e / this.canvasBounds.height, r = this.composeRelPoint(a, n, this.scale, 0, 0, s), i = this.composeRelPoint(a, n);
217
+ this.setTranslateFromUserGesture(i[0] - r[0], i[1] - r[1]), this.rotate = s, this.update();
215
218
  }
216
219
  get renderinScale() {
217
220
  return this.naturalScale * this.scale;
@@ -225,11 +228,11 @@ class E extends EventTarget {
225
228
  get renderingRotate() {
226
229
  return this.rotate;
227
230
  }
228
- clampTranslate(t, s = [0.5, 0.5]) {
229
- const e = this.canvasBounds.width * this.naturalScale * t.scale, a = this.canvasBounds.height * this.naturalScale * t.scale, n = e - this.wrapperInnerWidth, r = a - this.wrapperInnerHeight, i = n > 0 ? -n : 0, c = Math.min(0, Math.max(t.translateX, i)), l = r > 0 ? -r : 0, u = Math.min(0, Math.max(t.translateY, l)), d = -Math.min(0, n) * s[0], p = -Math.min(0, r) * s[1];
231
+ clampTranslate(t, e = [0.5, 0.5]) {
232
+ const s = this.canvasBounds.width * this.naturalScale * t.scale, a = this.canvasBounds.height * this.naturalScale * t.scale, n = s - this.wrapperInnerWidth, r = a - this.wrapperInnerHeight, i = n > 0 ? -n : 0, c = Math.min(0, Math.max(t.translateX, i)), o = r > 0 ? -r : 0, u = Math.min(0, Math.max(t.translateY, o)), p = -Math.min(0, n) * e[0], f = -Math.min(0, r) * e[1];
230
233
  return {
231
- translateX: c + d,
232
- translateY: u + p
234
+ translateX: c + p,
235
+ translateY: u + f
233
236
  };
234
237
  }
235
238
  update() {
@@ -239,5 +242,5 @@ class E extends EventTarget {
239
242
  }
240
243
  }
241
244
  export {
242
- E as Zoompinch
245
+ x as Zoompinch
243
246
  };
@@ -1 +1 @@
1
- (function(f,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(f=typeof globalThis<"u"?globalThis:f||self,d(f.Zoompinch={}))})(this,(function(f){"use strict";var D=Object.defineProperty;var b=(f,d,v)=>d in f?D(f,d,{enumerable:!0,configurable:!0,writable:!0,value:v}):f[d]=v;var m=(f,d,v)=>b(f,typeof d!="symbol"?d+"":d,v);function d(o){return o*Math.PI/180}function v(o,u,t){return Math.min(Math.max(o,u),t)}function X(o,u,t){const[e,s]=o,[a,n]=u,r=Math.cos(t)*(e-a)-Math.sin(t)*(s-n)+a,i=Math.sin(t)*(e-a)+Math.cos(t)*(s-n)+n;return[r,i]}function T(o,u){const t=Math.pow(10,u);return Math.round(o*t)/t}function x(o){var u=!1;return o.wheelDeltaY?o.wheelDeltaY===o.deltaY*-3&&(u=!0):o.deltaMode===0&&(u=!0),u}function B(o,u){const t=u.find(e=>o%e===0);return t?o/t:1}function F(o,u,t,e,s){let a=o.left-u,n=o.top-t;const r=Math.cos(-s),i=Math.sin(-s);let l=a*r-n*i,h=a*i+n*r;const c=o.width/e,p=o.height/e;return l/=e,h/=e,{x:T(l,4),y:T(h,4),width:T(c,4),height:T(p,4)}}class I extends EventTarget{constructor(t,e,s,a,n,r,i=.1,l=10,h=!1,c=!0){super();m(this,"wrapperBounds");m(this,"canvasBounds");m(this,"gestureStartRotate",0);m(this,"dragStart",null);m(this,"dragStartFrozenX",null);m(this,"dragStartFrozenY",null);m(this,"touchStarts",null);m(this,"touchStartTranslateX",0);m(this,"touchStartTranslateY",0);this.element=t,this.offset=e,this.translateX=s,this.translateY=a,this.scale=n,this.rotate=r,this.minScale=i,this.maxScale=l,this.clampBounds=h,this.rotation=c;const p=new ResizeObserver(()=>{const{x:S,y:w,width:Y,height:R}=this.element.getBoundingClientRect();this.wrapperBounds={x:S,y:w,width:Y,height:R},this.update()}),g=new ResizeObserver(()=>{const{x:S,y:w,width:Y,height:R}=F(this.canvasElement.getBoundingClientRect(),this.renderingTranslateX,this.renderingTranslateY,this.renderinScale,this.renderingRotate);this.canvasBounds={x:S,y:w,width:Y,height:R},this.update()});requestAnimationFrame(()=>{this.wrapperBounds=this.element.getBoundingClientRect(),this.canvasBounds=this.canvasElement.getBoundingClientRect(),this.update(),this.dispatchEvent(new Event("init"))}),g.observe(this.canvasElement),p.observe(this.element)}get canvasElement(){return this.element.querySelector(".canvas")}get wrapperInnerX(){return this.wrapperBounds.x+this.offset.left}get wrapperInnerY(){return this.wrapperBounds.y+this.offset.top}get wrapperInnerWidth(){return this.wrapperBounds.width-this.offset.left-this.offset.right}get wrapperInnerHeight(){return this.wrapperBounds.height-this.offset.top-this.offset.bottom}get wrapperInnerRatio(){return this.wrapperInnerWidth/this.wrapperInnerHeight}get canvasNaturalRatio(){return this.canvasBounds.width/this.canvasBounds.height}get naturalScale(){return this.canvasNaturalRatio>=this.wrapperInnerRatio?this.wrapperInnerWidth/this.canvasBounds.width:this.wrapperInnerHeight/this.canvasBounds.height}setTranslateFromUserGesture(t,e){if(this.clampBounds){const s=this.clampTranslate({translateX:t,translateY:e,scale:this.scale,rotate:this.rotate});this.translateX=s.translateX,this.translateY=s.translateY,this.rotate=0}else this.translateX=t,this.translateY=e}handleGesturestart(t){this.gestureStartRotate=this.rotate}handleGesturechange(t){const{clientX:e,clientY:s}=t,a=t.rotation;if(a===0||!this.rotation)return;const n=this.normalizeClientCoords(e,s);this.rotateCanvas(n[0],n[1],this.gestureStartRotate+d(a))}handleGestureend(t){}handleMousedown(t){t.preventDefault(),this.dragStart=[t.clientX,t.clientY],this.dragStartFrozenX=this.translateX,this.dragStartFrozenY=this.translateY}handleMouseup(t){t.preventDefault(),this.dragStart=null,this.dragStartFrozenX=null,this.dragStartFrozenY=null}handleMousemove(t){if(t.preventDefault(),this.dragStart&&this.dragStartFrozenX!==null&&this.dragStartFrozenY!==null){const e=t.clientX-this.dragStart[0],s=t.clientY-this.dragStart[1],a=this.dragStartFrozenX- -e,n=this.dragStartFrozenY- -s;this.setTranslateFromUserGesture(a,n),this.update()}}handleWheel(t){let{deltaX:e,deltaY:s,ctrlKey:a}=t;const n=[120,100],r=2;x(t)||((Math.abs(e)===120||Math.abs(e)===200)&&(e=e/(100/r*B(e,n))*Math.sign(e)),(Math.abs(s)===120||Math.abs(s)===200)&&(s=s/(100/r*B(s,n))*Math.sign(s)));const i=this.scale;if(a){const l=-s/100*i,h=v(i+l,this.minScale,this.maxScale),c=this.relativeWrapperCoordinatesFromClientCoords(t.clientX,t.clientY),[p,g]=this.calcProjectionTranslate(h,c,this.normalizeMatrixCoordinates(t.clientX,t.clientY));this.setTranslateFromUserGesture(p,g),this.scale=h}else this.setTranslateFromUserGesture(this.translateX-e,this.translateY-s);this.update(),t.preventDefault()}freezeTouches(t){return Array.from(t).map(e=>{const s=this.clientCoordsToWrapperCoords(e.clientX,e.clientY);return{client:[e.clientX,e.clientY],canvasRel:this.getCanvasCoordsRel(s[0],s[1])}})}handleTouchstart(t){this.touchStarts=this.freezeTouches(t.touches),this.touchStartTranslateX=this.translateX,this.touchStartTranslateY=this.translateY,t.preventDefault()}handleTouchmove(t){t.preventDefault();const e=Array.from(t.touches).map(s=>this.clientCoordsToWrapperCoords(s.clientX,s.clientY));if(this.touchStarts){if(e.length>=2&&this.touchStarts.length>=2){const s=[this.touchStarts[0].canvasRel[0]*this.canvasBounds.width,this.touchStarts[0].canvasRel[1]*this.canvasBounds.height],a=[this.touchStarts[1].canvasRel[0]*this.canvasBounds.width,this.touchStarts[1].canvasRel[1]*this.canvasBounds.height],n=Math.sqrt(Math.pow(s[0]-a[0],2)+Math.pow(s[1]-a[1],2)),r=Math.sqrt(Math.pow(e[0][0]-e[1][0],2)+Math.pow(e[0][1]-e[1][1],2))/this.naturalScale,i=v(r/n,this.minScale,this.maxScale),l=[e[0][0]/this.wrapperInnerWidth,e[0][1]/this.wrapperInnerHeight],h=this.touchStarts[0].canvasRel,[c,p]=this.calcProjectionTranslate(i,l,h,0);if(this.rotation){let g=0,S=0,w=0;const Y=Math.atan2(a[1]-s[1],a[0]-s[0]);w=Math.atan2(e[1][1]-e[0][1],e[1][0]-e[0][0])-Y;const M=(y,z)=>[this.offset.left+this.canvasBounds.width*y*this.naturalScale*i+c,this.offset.top+this.canvasBounds.height*z*this.naturalScale*i+p],C=M(0,0),W=M(this.touchStarts[0].canvasRel[0],this.touchStarts[0].canvasRel[1]),P=X(C,W,w);g=P[0]-C[0],S=P[1]-C[1],this.scale=i,this.rotate=w,this.setTranslateFromUserGesture(c+g,p+S)}else this.scale=i,this.setTranslateFromUserGesture(c,p)}else{const s=t.touches[0].clientX-this.touchStarts[0].client[0],a=t.touches[0].clientY-this.touchStarts[0].client[1],n=this.touchStartTranslateX+s,r=this.touchStartTranslateY+a;this.setTranslateFromUserGesture(n,r)}this.update()}}handleTouchend(t){t.touches.length===0?this.touchStarts=null:(this.touchStarts=this.freezeTouches(t.touches),this.touchStartTranslateX=this.translateX,this.touchStartTranslateY=this.translateY)}calcProjectionTranslate(t,e,s,a){const n=this.canvasBounds.width*this.naturalScale,r=this.canvasBounds.height*this.naturalScale,i=s[0]*n*t,l=s[1]*r*t,h=X([i,l],[0,0],a??this.rotate),c=e[0]*this.wrapperInnerWidth,p=e[1]*this.wrapperInnerHeight,g=c-h[0],S=p-h[1];return[g,S]}applyTransform(t,e,s){const a=this.calcProjectionTranslate(t,e,s,0);this.scale=t,this.setTranslateFromUserGesture(a[0],a[1]),this.update()}composeRelPoint(t,e,s,a,n,r){s=s??this.scale,a=a??this.translateX,n=n??this.translateY,r=r??this.rotate;const i=[this.offset.left,this.offset.top],l=[this.offset.left+this.canvasBounds.width*(s*this.naturalScale)*t,this.offset.top+this.canvasBounds.height*(s*this.naturalScale)*e],h=X(l,i,r);return[h[0]+a,h[1]+n]}composePoint(t,e){const s=t/this.canvasBounds.width,a=e/this.canvasBounds.height;return this.composeRelPoint(s,a)}getAnchorOffset(t,e,s,a,n=[.5,.5]){const r=this.calcProjectionTranslate(t,n,n,0),i=[this.offset.left+r[0]+this.canvasBounds.width*(t*this.naturalScale)*n[0],this.offset.top+r[1]+this.canvasBounds.height*(t*this.naturalScale)*n[1]],l=this.composeRelPoint(n[0],n[1],t,e,s,a),h=l[0]-i[0],c=l[1]-i[1];return[h,c]}getCanvasCoordsRel(t,e){const s=[0,0],a=[t-this.translateX,e-this.translateY],n=X(a,s,-this.rotate),r=[n[0]/this.renderinScale,n[1]/this.renderinScale];return[r[0]/this.canvasBounds.width,r[1]/this.canvasBounds.height]}clientCoordsToWrapperCoords(t,e){return[t-this.wrapperInnerX,e-this.wrapperInnerY]}relativeWrapperCoordinatesFromClientCoords(t,e){const[s,a]=this.clientCoordsToWrapperCoords(t,e);return[s/this.wrapperInnerWidth,a/this.wrapperInnerHeight]}normalizeMatrixCoordinates(t,e){const s=this.clientCoordsToWrapperCoords(t,e);return this.getCanvasCoordsRel(s[0],s[1])}normalizeClientCoords(t,e){const[s,a]=this.normalizeMatrixCoordinates(t,e);return[s*this.canvasBounds.width,a*this.canvasBounds.height]}rotateCanvas(t,e,s){const a=t/this.canvasBounds.width,n=e/this.canvasBounds.height,r=this.composeRelPoint(a,n,this.scale,0,0,s),i=this.composeRelPoint(a,n);this.setTranslateFromUserGesture(i[0]-r[0],i[1]-r[1]),this.rotate=s,this.update()}get renderinScale(){return this.naturalScale*this.scale}get renderingTranslateX(){return this.offset.left+this.translateX}get renderingTranslateY(){return this.offset.top+this.translateY}get renderingRotate(){return this.rotate}clampTranslate(t,e=[.5,.5]){const s=this.canvasBounds.width*this.naturalScale*t.scale,a=this.canvasBounds.height*this.naturalScale*t.scale,n=s-this.wrapperInnerWidth,r=a-this.wrapperInnerHeight,i=n>0?-n:0,l=Math.min(0,Math.max(t.translateX,i)),h=r>0?-r:0,c=Math.min(0,Math.max(t.translateY,h)),p=-Math.min(0,n)*e[0],g=-Math.min(0,r)*e[1];return{translateX:l+p,translateY:c+g}}update(){this.canvasElement.style.transformOrigin="top left",this.canvasElement.style.transform=`translateX(${this.renderingTranslateX}px) translateY(${this.renderingTranslateY}px) scale(${this.renderinScale}) rotate(${this.renderingRotate}rad)`,this.dispatchEvent(new Event("update"))}destroy(){}}f.Zoompinch=I,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(p,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(p=typeof globalThis<"u"?globalThis:p||self,d(p.Zoompinch={}))})(this,(function(p){"use strict";var I=Object.defineProperty;var W=(p,d,w)=>d in p?I(p,d,{enumerable:!0,configurable:!0,writable:!0,value:w}):p[d]=w;var l=(p,d,w)=>W(p,typeof d!="symbol"?d+"":d,w);function d(u){return u*Math.PI/180}function w(u,m,t){return Math.min(Math.max(u,m),t)}function X(u,m,t){const[e,s]=u,[a,n]=m,r=Math.cos(t)*(e-a)-Math.sin(t)*(s-n)+a,i=Math.sin(t)*(e-a)+Math.cos(t)*(s-n)+n;return[r,i]}function M(u){if(u.ctrlKey){const{deltaY:t,deltaMode:e,ctrlKey:s}=u,a=Math.abs(t),n=a===120||a===100||a===3,r=t%1!==0,i=e===0;return s?a<50&&i||r:!n&&(r||i&&a<50)}else{var m=!1;return u.wheelDeltaY?u.wheelDeltaY===u.deltaY*-3&&(m=!0):u.deltaMode===0&&(m=!0),m}}class P extends EventTarget{constructor(t,e,s,a,n,r,i=.1,h=10,o=!1,c=!0){super();l(this,"wrapperBounds");l(this,"canvasBounds");l(this,"translateSpeed",1);l(this,"zoomSpeed",1);l(this,"translateSpeedAppleTrackpad",1);l(this,"zoomSpeedAppleTrackpad",1);l(this,"isGestureActive",!1);l(this,"gestureStartRotate",0);l(this,"dragStart",null);l(this,"dragStartFrozenX",null);l(this,"dragStartFrozenY",null);l(this,"touchStarts",null);l(this,"touchStartTranslateX",0);l(this,"touchStartTranslateY",0);this.element=t,this.offset=e,this.translateX=s,this.translateY=a,this.scale=n,this.rotate=r,this.minScale=i,this.maxScale=h,this.clampBounds=o,this.rotation=c;const f=new ResizeObserver(()=>{const{x:S,y:v,width:Y,height:B}=this.element.getBoundingClientRect();this.wrapperBounds={x:S,y:v,width:Y,height:B},this.update()}),g=new ResizeObserver(S=>{const{width:v,height:Y}=S[0].contentRect;(v!==this.canvasBounds.width||Y!==this.canvasBounds.height)&&(this.canvasBounds={...this.canvasBounds,width:v,height:Y},this.isGestureActive||this.update())});requestAnimationFrame(()=>{this.wrapperBounds=this.element.getBoundingClientRect(),this.canvasBounds=this.canvasElement.getBoundingClientRect(),this.update(),this.dispatchEvent(new Event("init"))}),g.observe(this.canvasElement),f.observe(this.element)}get canvasElement(){return this.element.querySelector(".canvas")}get wrapperInnerX(){return this.wrapperBounds.x+this.offset.left}get wrapperInnerY(){return this.wrapperBounds.y+this.offset.top}get wrapperInnerWidth(){return this.wrapperBounds.width-this.offset.left-this.offset.right}get wrapperInnerHeight(){return this.wrapperBounds.height-this.offset.top-this.offset.bottom}get wrapperInnerRatio(){return this.wrapperInnerWidth/this.wrapperInnerHeight}get canvasNaturalRatio(){return this.canvasBounds.width/this.canvasBounds.height}get naturalScale(){return this.canvasNaturalRatio>=this.wrapperInnerRatio?this.wrapperInnerWidth/this.canvasBounds.width:this.wrapperInnerHeight/this.canvasBounds.height}setTranslateFromUserGesture(t,e){if(this.clampBounds){const s=this.clampTranslate({translateX:t,translateY:e,scale:this.scale,rotate:this.rotate});this.translateX=s.translateX,this.translateY=s.translateY,this.rotate=0}else this.translateX=t,this.translateY=e}handleGesturestart(t){this.gestureStartRotate=this.rotate}handleGesturechange(t){const{clientX:e,clientY:s}=t,a=t.rotation;if(a===0||!this.rotation)return;const n=this.normalizeClientCoords(e,s);this.rotateCanvas(n[0],n[1],this.gestureStartRotate+d(a))}handleGestureend(t){}handleMousedown(t){t.preventDefault(),this.dragStart=[t.clientX,t.clientY],this.dragStartFrozenX=this.translateX,this.dragStartFrozenY=this.translateY}handleMouseup(t){t.preventDefault(),this.dragStart=null,this.dragStartFrozenX=null,this.dragStartFrozenY=null}handleMousemove(t){if(t.preventDefault(),this.dragStart&&this.dragStartFrozenX!==null&&this.dragStartFrozenY!==null){const e=t.clientX-this.dragStart[0],s=t.clientY-this.dragStart[1],a=this.dragStartFrozenX- -e,n=this.dragStartFrozenY- -s;this.setTranslateFromUserGesture(a,n),this.update()}}handleWheel(t){let{deltaX:e,deltaY:s,ctrlKey:a}=t;const n=M(t);n||(Math.abs(s)>=100&&(s=Math.sign(s)*(Math.abs(s)/120)),Math.abs(e)>=100&&(e=Math.sign(e)*(Math.abs(e)/120)));const r=this.scale;if(a){const i=n?.01*this.zoomSpeedAppleTrackpad:.1*this.zoomSpeed,h=1+-s*i;let o=r*h;if(o=w(o,this.minScale,this.maxScale),(o===this.minScale||o===this.maxScale)&&(o===this.minScale&&h<1||o===this.maxScale&&h>1)){t.preventDefault();return}const c=this.relativeWrapperCoordinatesFromClientCoords(t.clientX,t.clientY),[f,g]=this.calcProjectionTranslate(o,c,this.normalizeMatrixCoordinates(t.clientX,t.clientY));this.setTranslateFromUserGesture(f,g),this.scale=o}else{const i=n?1*this.translateSpeedAppleTrackpad:25*this.translateSpeed;this.setTranslateFromUserGesture(this.translateX-e*i,this.translateY-s*i)}this.update(),t.preventDefault()}freezeTouches(t){return Array.from(t).map(e=>{const s=this.clientCoordsToWrapperCoords(e.clientX,e.clientY);return{client:[e.clientX,e.clientY],canvasRel:this.getCanvasCoordsRel(s[0],s[1])}})}handleTouchstart(t){this.touchStarts=this.freezeTouches(t.touches),this.touchStartTranslateX=this.translateX,this.touchStartTranslateY=this.translateY,this.isGestureActive=!0,t.preventDefault()}handleTouchmove(t){t.preventDefault();const e=Array.from(t.touches).map(s=>this.clientCoordsToWrapperCoords(s.clientX,s.clientY));if(this.touchStarts){if(e.length>=2&&this.touchStarts.length>=2){const s=[this.touchStarts[0].canvasRel[0]*this.canvasBounds.width,this.touchStarts[0].canvasRel[1]*this.canvasBounds.height],a=[this.touchStarts[1].canvasRel[0]*this.canvasBounds.width,this.touchStarts[1].canvasRel[1]*this.canvasBounds.height],n=Math.sqrt(Math.pow(s[0]-a[0],2)+Math.pow(s[1]-a[1],2)),r=Math.sqrt(Math.pow(e[0][0]-e[1][0],2)+Math.pow(e[0][1]-e[1][1],2))/this.naturalScale,i=w(r/n,this.minScale,this.maxScale),h=[e[0][0]/this.wrapperInnerWidth,e[0][1]/this.wrapperInnerHeight],o=this.touchStarts[0].canvasRel,[c,f]=this.calcProjectionTranslate(i,h,o,0);if(this.rotation){let g=0,S=0,v=0;const Y=Math.atan2(a[1]-s[1],a[0]-s[0]);v=Math.atan2(e[1][1]-e[0][1],e[1][0]-e[0][0])-Y;const C=(F,x)=>[this.offset.left+this.canvasBounds.width*F*this.naturalScale*i+c,this.offset.top+this.canvasBounds.height*x*this.naturalScale*i+f],T=C(0,0),z=C(this.touchStarts[0].canvasRel[0],this.touchStarts[0].canvasRel[1]),R=X(T,z,v);g=R[0]-T[0],S=R[1]-T[1],this.scale=i,this.rotate=v,this.setTranslateFromUserGesture(c+g,f+S)}else this.scale=i,this.setTranslateFromUserGesture(c,f)}else{const s=t.touches[0].clientX-this.touchStarts[0].client[0],a=t.touches[0].clientY-this.touchStarts[0].client[1],n=this.touchStartTranslateX+s,r=this.touchStartTranslateY+a;this.setTranslateFromUserGesture(n,r)}this.update()}}handleTouchend(t){t.touches.length===0?this.touchStarts=null:(this.touchStarts=this.freezeTouches(t.touches),this.touchStartTranslateX=this.translateX,this.touchStartTranslateY=this.translateY),this.isGestureActive=!1}calcProjectionTranslate(t,e,s,a){const n=this.canvasBounds.width*this.naturalScale,r=this.canvasBounds.height*this.naturalScale,i=s[0]*n*t,h=s[1]*r*t,o=X([i,h],[0,0],a??this.rotate),c=e[0]*this.wrapperInnerWidth,f=e[1]*this.wrapperInnerHeight,g=c-o[0],S=f-o[1];return[g,S]}applyTransform(t,e,s){const a=this.calcProjectionTranslate(t,e,s,0);this.scale=t,this.setTranslateFromUserGesture(a[0],a[1]),this.update()}composeRelPoint(t,e,s,a,n,r){s=s??this.scale,a=a??this.translateX,n=n??this.translateY,r=r??this.rotate;const i=[this.offset.left,this.offset.top],h=[this.offset.left+this.canvasBounds.width*(s*this.naturalScale)*t,this.offset.top+this.canvasBounds.height*(s*this.naturalScale)*e],o=X(h,i,r);return[o[0]+a,o[1]+n]}composePoint(t,e){const s=t/this.canvasBounds.width,a=e/this.canvasBounds.height;return this.composeRelPoint(s,a)}getAnchorOffset(t,e,s,a,n=[.5,.5]){const r=this.calcProjectionTranslate(t,n,n,0),i=[this.offset.left+r[0]+this.canvasBounds.width*(t*this.naturalScale)*n[0],this.offset.top+r[1]+this.canvasBounds.height*(t*this.naturalScale)*n[1]],h=this.composeRelPoint(n[0],n[1],t,e,s,a),o=h[0]-i[0],c=h[1]-i[1];return[o,c]}getCanvasCoordsRel(t,e){const s=[0,0],a=[t-this.translateX,e-this.translateY],n=X(a,s,-this.rotate),r=[n[0]/this.renderinScale,n[1]/this.renderinScale];return[r[0]/this.canvasBounds.width,r[1]/this.canvasBounds.height]}clientCoordsToWrapperCoords(t,e){return[t-this.wrapperInnerX,e-this.wrapperInnerY]}relativeWrapperCoordinatesFromClientCoords(t,e){const[s,a]=this.clientCoordsToWrapperCoords(t,e);return[s/this.wrapperInnerWidth,a/this.wrapperInnerHeight]}normalizeMatrixCoordinates(t,e){const s=this.clientCoordsToWrapperCoords(t,e);return this.getCanvasCoordsRel(s[0],s[1])}normalizeClientCoords(t,e){const[s,a]=this.normalizeMatrixCoordinates(t,e);return[s*this.canvasBounds.width,a*this.canvasBounds.height]}rotateCanvas(t,e,s){const a=t/this.canvasBounds.width,n=e/this.canvasBounds.height,r=this.composeRelPoint(a,n,this.scale,0,0,s),i=this.composeRelPoint(a,n);this.setTranslateFromUserGesture(i[0]-r[0],i[1]-r[1]),this.rotate=s,this.update()}get renderinScale(){return this.naturalScale*this.scale}get renderingTranslateX(){return this.offset.left+this.translateX}get renderingTranslateY(){return this.offset.top+this.translateY}get renderingRotate(){return this.rotate}clampTranslate(t,e=[.5,.5]){const s=this.canvasBounds.width*this.naturalScale*t.scale,a=this.canvasBounds.height*this.naturalScale*t.scale,n=s-this.wrapperInnerWidth,r=a-this.wrapperInnerHeight,i=n>0?-n:0,h=Math.min(0,Math.max(t.translateX,i)),o=r>0?-r:0,c=Math.min(0,Math.max(t.translateY,o)),f=-Math.min(0,n)*e[0],g=-Math.min(0,r)*e[1];return{translateX:h+f,translateY:c+g}}update(){this.canvasElement.style.transformOrigin="top left",this.canvasElement.style.transform=`translateX(${this.renderingTranslateX}px) translateY(${this.renderingTranslateY}px) scale(${this.renderinScale}) rotate(${this.renderingRotate}rad)`,this.dispatchEvent(new Event("update"))}destroy(){}}p.Zoompinch=P,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
@@ -29,6 +29,11 @@ export declare class Zoompinch extends EventTarget {
29
29
  rotation: boolean;
30
30
  wrapperBounds: Bounds;
31
31
  canvasBounds: Bounds;
32
+ translateSpeed: number;
33
+ zoomSpeed: number;
34
+ translateSpeedAppleTrackpad: number;
35
+ zoomSpeedAppleTrackpad: number;
36
+ private isGestureActive;
32
37
  constructor(element: HTMLElement, offset: Offset, translateX: number, translateY: number, scale: number, rotate: number, minScale?: number, maxScale?: number, clampBounds?: boolean, rotation?: boolean);
33
38
  get canvasElement(): HTMLElement;
34
39
  get wrapperInnerX(): number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zoompinch/core",
3
3
  "description": "Pinch-and-zoom experience that's feels native and communicates the transform reactively and lets you project any layer on top of the transformed canvas",
4
- "version": "0.0.27",
4
+ "version": "0.0.30",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "main": "./dist/zoompinch-core.umd.js",