@zoompinch/core 0.0.9 → 0.0.11
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/zoompinch-core.es.js +7 -48
- package/package.json +9 -1
|
@@ -47,13 +47,7 @@ class E extends EventTarget {
|
|
|
47
47
|
const { x: u, y: p, width: g, height: S } = this.element.getBoundingClientRect();
|
|
48
48
|
this.wrapperBounds = { x: u, y: p, width: g, height: S }, this.update();
|
|
49
49
|
}), d = new ResizeObserver(() => {
|
|
50
|
-
const { x: u, y: p, width: g, height: S } = y(
|
|
51
|
-
this.canvasElement.getBoundingClientRect(),
|
|
52
|
-
this.renderingTranslateX,
|
|
53
|
-
this.renderingTranslateY,
|
|
54
|
-
this.renderinScale,
|
|
55
|
-
this.renderingRotate
|
|
56
|
-
);
|
|
50
|
+
const { x: u, y: p, width: g, height: S } = y(this.canvasElement.getBoundingClientRect(), this.renderingTranslateX, this.renderingTranslateY, this.renderinScale, this.renderingRotate);
|
|
57
51
|
this.canvasBounds = { x: u, y: p, width: g, height: S }, this.update();
|
|
58
52
|
});
|
|
59
53
|
requestAnimationFrame(() => {
|
|
@@ -116,11 +110,7 @@ class E extends EventTarget {
|
|
|
116
110
|
W(t) || ((Math.abs(e) === 120 || Math.abs(e) === 200) && (e = e / (100 / i * C(e, n)) * Math.sign(e)), (Math.abs(s) === 120 || Math.abs(s) === 200) && (s = s / (100 / i * C(s, n)) * Math.sign(s)));
|
|
117
111
|
const h = this.scale;
|
|
118
112
|
if (a) {
|
|
119
|
-
const c = -s / 100 * h, l = R(h + c, this.minScale, this.maxScale), d = this.relativeWrapperCoordinatesFromClientCoords(t.clientX, t.clientY), [u, p] = this.calcProjectionTranslate(
|
|
120
|
-
l,
|
|
121
|
-
d,
|
|
122
|
-
this.normalizeMatrixCoordinates(t.clientX, t.clientY)
|
|
123
|
-
);
|
|
113
|
+
const c = -s / 100 * h, l = R(h + c, this.minScale, this.maxScale), d = this.relativeWrapperCoordinatesFromClientCoords(t.clientX, t.clientY), [u, p] = this.calcProjectionTranslate(l, d, this.normalizeMatrixCoordinates(t.clientX, t.clientY));
|
|
124
114
|
this.translateX = u, this.translateY = p, this.scale = l;
|
|
125
115
|
} else
|
|
126
116
|
this.translateX = this.translateX - e, this.translateY = this.translateY - s;
|
|
@@ -140,42 +130,14 @@ class E extends EventTarget {
|
|
|
140
130
|
}
|
|
141
131
|
handleTouchmove(t) {
|
|
142
132
|
t.preventDefault();
|
|
143
|
-
const e = Array.from(t.touches).map(
|
|
144
|
-
(s) => this.clientCoordsToWrapperCoords(s.clientX, s.clientY)
|
|
145
|
-
);
|
|
133
|
+
const e = Array.from(t.touches).map((s) => this.clientCoordsToWrapperCoords(s.clientX, s.clientY));
|
|
146
134
|
if (this.touchStarts) {
|
|
147
135
|
if (e.length >= 2 && this.touchStarts.length >= 2) {
|
|
148
|
-
const s = [
|
|
149
|
-
this.touchStarts[0].canvasRel[0] * this.canvasBounds.width,
|
|
150
|
-
this.touchStarts[0].canvasRel[1] * this.canvasBounds.height
|
|
151
|
-
], a = [
|
|
152
|
-
this.touchStarts[1].canvasRel[0] * this.canvasBounds.width,
|
|
153
|
-
this.touchStarts[1].canvasRel[1] * this.canvasBounds.height
|
|
154
|
-
], n = Math.sqrt(
|
|
155
|
-
Math.pow(s[0] - a[0], 2) + Math.pow(s[1] - a[1], 2)
|
|
156
|
-
), i = Math.sqrt(
|
|
157
|
-
Math.pow(e[0][0] - e[1][0], 2) + Math.pow(e[0][1] - e[1][1], 2)
|
|
158
|
-
) / this.naturalScale, h = R(i / n, this.minScale, this.maxScale), c = [
|
|
159
|
-
e[0][0] / this.wrapperInnerWidth,
|
|
160
|
-
e[0][1] / this.wrapperInnerHeight
|
|
161
|
-
], l = this.touchStarts[0].canvasRel, [d, u] = this.calcProjectionTranslate(h, c, l, 0);
|
|
136
|
+
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)), i = Math.sqrt(Math.pow(e[0][0] - e[1][0], 2) + Math.pow(e[0][1] - e[1][1], 2)) / this.naturalScale, h = R(i / n, this.minScale, this.maxScale), c = [e[0][0] / this.wrapperInnerWidth, e[0][1] / this.wrapperInnerHeight], l = this.touchStarts[0].canvasRel, [d, u] = this.calcProjectionTranslate(h, c, l, 0);
|
|
162
137
|
let p = 0, g = 0, S = 0;
|
|
163
|
-
const T = Math.atan2(
|
|
164
|
-
a[1] - s[1],
|
|
165
|
-
a[0] - s[0]
|
|
166
|
-
);
|
|
138
|
+
const T = Math.atan2(a[1] - s[1], a[0] - s[0]);
|
|
167
139
|
S = Math.atan2(e[1][1] - e[0][1], e[1][0] - e[0][0]) - T;
|
|
168
|
-
const m = (M, P) => [
|
|
169
|
-
this.offset.left + this.canvasBounds.width * M * this.naturalScale * h + d,
|
|
170
|
-
this.offset.top + this.canvasBounds.height * P * this.naturalScale * h + u
|
|
171
|
-
], Y = m(0, 0), B = m(
|
|
172
|
-
this.touchStarts[0].canvasRel[0],
|
|
173
|
-
this.touchStarts[0].canvasRel[1]
|
|
174
|
-
), X = v(
|
|
175
|
-
Y,
|
|
176
|
-
B,
|
|
177
|
-
S
|
|
178
|
-
);
|
|
140
|
+
const m = (M, P) => [this.offset.left + this.canvasBounds.width * M * this.naturalScale * h + d, this.offset.top + this.canvasBounds.height * P * this.naturalScale * h + u], Y = m(0, 0), B = m(this.touchStarts[0].canvasRel[0], this.touchStarts[0].canvasRel[1]), X = v(Y, B, S);
|
|
179
141
|
p = X[0] - Y[0], g = X[1] - Y[1], this.scale = h, this.rotate = S, this.translateX = d + p, this.translateY = u + g;
|
|
180
142
|
} else {
|
|
181
143
|
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, i = this.touchStartTranslateY + a;
|
|
@@ -198,10 +160,7 @@ class E extends EventTarget {
|
|
|
198
160
|
}
|
|
199
161
|
composeRelPoint(t, e, s, a, n, i) {
|
|
200
162
|
s = s ?? this.scale, a = a ?? this.translateX, n = n ?? this.translateY, i = i ?? this.rotate;
|
|
201
|
-
const h = [this.offset.left, this.offset.top], c = [
|
|
202
|
-
this.offset.left + this.canvasBounds.width * (s * this.naturalScale) * t,
|
|
203
|
-
this.offset.top + this.canvasBounds.height * (s * this.naturalScale) * e
|
|
204
|
-
], l = v(c, h, i);
|
|
163
|
+
const h = [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], l = v(c, h, i);
|
|
205
164
|
return [l[0] + a, l[1] + n];
|
|
206
165
|
}
|
|
207
166
|
composePoint(t, e) {
|
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.
|
|
4
|
+
"version": "0.0.11",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/zoompinch-core.umd.js",
|
|
@@ -24,5 +24,13 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"typescript": "^5.9.3",
|
|
26
26
|
"vite": "^6.4.1"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://zoompinch.pages.dev/",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/ElyaConrad/zoompinch"
|
|
27
35
|
}
|
|
28
36
|
}
|