@zoompinch/elements 0.0.24 → 0.0.26
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/README.md +2 -1
- package/dist/zoompinch-elements.es.js +41 -268
- package/dist/zoompinch-elements.umd.js +2 -2
- package/package.json +14 -2
package/README.md
CHANGED
|
@@ -359,6 +359,7 @@ MIT
|
|
|
359
359
|
## Related
|
|
360
360
|
|
|
361
361
|
- [@zoompinch/core](https://www.npmjs.com/package/@zoompinch/core) - Core engine
|
|
362
|
-
- [@zoompinch/vue](https://www.npmjs.com/package/@zoompinch/vue) - Vue 3
|
|
362
|
+
- [@zoompinch/vue](https://www.npmjs.com/package/@zoompinch/vue) - Vue 3
|
|
363
|
+
- [@zoompinch/react](https://www.npmjs.com/package/@zoompinch/react) - React
|
|
363
364
|
|
|
364
365
|
Built with ❤️ by Elya Maurice Conrad
|
|
@@ -1,238 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return r * Math.PI / 180;
|
|
7
|
-
}
|
|
8
|
-
function Y(r, t, e) {
|
|
9
|
-
return Math.min(Math.max(r, t), e);
|
|
10
|
-
}
|
|
11
|
-
function w(r, t, e) {
|
|
12
|
-
const [s, n] = r, [a, i] = t, h = Math.cos(e) * (s - a) - Math.sin(e) * (n - i) + a, c = Math.sin(e) * (s - a) + Math.cos(e) * (n - i) + i;
|
|
13
|
-
return [h, c];
|
|
14
|
-
}
|
|
15
|
-
function S(r, t) {
|
|
16
|
-
const e = Math.pow(10, t);
|
|
17
|
-
return Math.round(r * e) / e;
|
|
18
|
-
}
|
|
19
|
-
function F(r) {
|
|
20
|
-
var t = !1;
|
|
21
|
-
return r.wheelDeltaY ? r.wheelDeltaY === r.deltaY * -3 && (t = !0) : r.deltaMode === 0 && (t = !0), t;
|
|
22
|
-
}
|
|
23
|
-
function X(r, t) {
|
|
24
|
-
const e = t.find((s) => r % s === 0);
|
|
25
|
-
return e ? r / e : 1;
|
|
26
|
-
}
|
|
27
|
-
function I(r, t, e, s, n) {
|
|
28
|
-
let a = r.left - t, i = r.top - e;
|
|
29
|
-
const h = Math.cos(-n), c = Math.sin(-n);
|
|
30
|
-
let l = a * h - i * c, u = a * c + i * h;
|
|
31
|
-
const d = r.width / s, g = r.height / s;
|
|
32
|
-
return l /= s, u /= s, { x: S(l, 4), y: S(u, 4), width: S(d, 4), height: S(g, 4) };
|
|
33
|
-
}
|
|
34
|
-
class W extends EventTarget {
|
|
35
|
-
constructor(t, e, s, n, a, i, h = 0.1, c = 10, l = !1, u = !0) {
|
|
36
|
-
super(), v(this, "wrapperBounds"), v(this, "canvasBounds"), v(this, "gestureStartRotate", 0), v(this, "dragStart", null), v(this, "dragStartFrozenX", null), v(this, "dragStartFrozenY", null), v(this, "touchStarts", null), v(this, "touchStartTranslateX", 0), v(this, "touchStartTranslateY", 0), this.element = t, this.offset = e, this.translateX = s, this.translateY = n, this.scale = a, this.rotate = i, this.minScale = h, this.maxScale = c, this.clampBounds = l, this.rotation = u;
|
|
37
|
-
const d = new ResizeObserver(() => {
|
|
38
|
-
const { x: o, y: p, width: m, height: f } = this.element.getBoundingClientRect();
|
|
39
|
-
this.wrapperBounds = { x: o, y: p, width: m, height: f }, this.update();
|
|
40
|
-
}), g = new ResizeObserver(() => {
|
|
41
|
-
const { x: o, y: p, width: m, height: f } = I(this.canvasElement.getBoundingClientRect(), this.renderingTranslateX, this.renderingTranslateY, this.renderinScale, this.renderingRotate);
|
|
42
|
-
this.canvasBounds = { x: o, y: p, width: m, height: f }, this.update();
|
|
43
|
-
});
|
|
44
|
-
requestAnimationFrame(() => {
|
|
45
|
-
this.wrapperBounds = this.element.getBoundingClientRect(), this.canvasBounds = this.canvasElement.getBoundingClientRect(), this.update(), this.dispatchEvent(new Event("init"));
|
|
46
|
-
}), g.observe(this.canvasElement), d.observe(this.element);
|
|
47
|
-
}
|
|
48
|
-
get canvasElement() {
|
|
49
|
-
return this.element.querySelector(".canvas");
|
|
50
|
-
}
|
|
51
|
-
get wrapperInnerX() {
|
|
52
|
-
return this.wrapperBounds.x + this.offset.left;
|
|
53
|
-
}
|
|
54
|
-
get wrapperInnerY() {
|
|
55
|
-
return this.wrapperBounds.y + this.offset.top;
|
|
56
|
-
}
|
|
57
|
-
get wrapperInnerWidth() {
|
|
58
|
-
return this.wrapperBounds.width - this.offset.left - this.offset.right;
|
|
59
|
-
}
|
|
60
|
-
get wrapperInnerHeight() {
|
|
61
|
-
return this.wrapperBounds.height - this.offset.top - this.offset.bottom;
|
|
62
|
-
}
|
|
63
|
-
// Calculate the inner ratio
|
|
64
|
-
get wrapperInnerRatio() {
|
|
65
|
-
return this.wrapperInnerWidth / this.wrapperInnerHeight;
|
|
66
|
-
}
|
|
67
|
-
get canvasNaturalRatio() {
|
|
68
|
-
return this.canvasBounds.width / this.canvasBounds.height;
|
|
69
|
-
}
|
|
70
|
-
// Get natural scale
|
|
71
|
-
get naturalScale() {
|
|
72
|
-
return this.canvasNaturalRatio >= this.wrapperInnerRatio ? this.wrapperInnerWidth / this.canvasBounds.width : this.wrapperInnerHeight / this.canvasBounds.height;
|
|
73
|
-
}
|
|
74
|
-
// The clamping is an explicit user intention
|
|
75
|
-
// The reason is that we do not want side effects when toggling the clamp
|
|
76
|
-
setTranslateFromUserGesture(t, e) {
|
|
77
|
-
if (this.clampBounds) {
|
|
78
|
-
const s = this.clampTranslate({ translateX: t, translateY: e, scale: this.scale, rotate: this.rotate });
|
|
79
|
-
this.translateX = s.translateX, this.translateY = s.translateY, this.rotate = 0;
|
|
80
|
-
} else
|
|
81
|
-
this.translateX = t, this.translateY = e;
|
|
82
|
-
}
|
|
83
|
-
handleGesturestart(t) {
|
|
84
|
-
this.gestureStartRotate = this.rotate;
|
|
85
|
-
}
|
|
86
|
-
handleGesturechange(t) {
|
|
87
|
-
const { clientX: e, clientY: s } = t, n = t.rotation;
|
|
88
|
-
if (n === 0 || !this.rotation)
|
|
89
|
-
return;
|
|
90
|
-
const a = this.normalizeClientCoords(e, s);
|
|
91
|
-
this.rotateCanvas(a[0], a[1], this.gestureStartRotate + z(n));
|
|
92
|
-
}
|
|
93
|
-
handleGestureend(t) {
|
|
94
|
-
}
|
|
95
|
-
handleMousedown(t) {
|
|
96
|
-
t.preventDefault(), this.dragStart = [t.clientX, t.clientY], this.dragStartFrozenX = this.translateX, this.dragStartFrozenY = this.translateY;
|
|
97
|
-
}
|
|
98
|
-
handleMouseup(t) {
|
|
99
|
-
t.preventDefault(), this.dragStart = null, this.dragStartFrozenX = null, this.dragStartFrozenY = null;
|
|
100
|
-
}
|
|
101
|
-
handleMousemove(t) {
|
|
102
|
-
if (t.preventDefault(), this.dragStart && this.dragStartFrozenX !== null && this.dragStartFrozenY !== null) {
|
|
103
|
-
const e = t.clientX - this.dragStart[0], s = t.clientY - this.dragStart[1], n = this.dragStartFrozenX - -e, a = this.dragStartFrozenY - -s;
|
|
104
|
-
this.setTranslateFromUserGesture(n, a), this.update();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
handleWheel(t) {
|
|
108
|
-
let { deltaX: e, deltaY: s, ctrlKey: n } = t;
|
|
109
|
-
const a = [120, 100], i = 2;
|
|
110
|
-
F(t) || ((Math.abs(e) === 120 || Math.abs(e) === 200) && (e = e / (100 / i * X(e, a)) * Math.sign(e)), (Math.abs(s) === 120 || Math.abs(s) === 200) && (s = s / (100 / i * X(s, a)) * Math.sign(s)));
|
|
111
|
-
const h = this.scale;
|
|
112
|
-
if (n) {
|
|
113
|
-
const c = -s / 100 * h, l = Y(h + c, this.minScale, this.maxScale), u = this.relativeWrapperCoordinatesFromClientCoords(t.clientX, t.clientY), [d, g] = this.calcProjectionTranslate(l, u, this.normalizeMatrixCoordinates(t.clientX, t.clientY));
|
|
114
|
-
this.setTranslateFromUserGesture(d, g), this.scale = l;
|
|
115
|
-
} else
|
|
116
|
-
this.setTranslateFromUserGesture(this.translateX - e, this.translateY - s);
|
|
117
|
-
this.update(), t.preventDefault();
|
|
118
|
-
}
|
|
119
|
-
freezeTouches(t) {
|
|
120
|
-
return Array.from(t).map((e) => {
|
|
121
|
-
const s = this.clientCoordsToWrapperCoords(e.clientX, e.clientY);
|
|
122
|
-
return {
|
|
123
|
-
client: [e.clientX, e.clientY],
|
|
124
|
-
canvasRel: this.getCanvasCoordsRel(s[0], s[1])
|
|
125
|
-
};
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
handleTouchstart(t) {
|
|
129
|
-
this.touchStarts = this.freezeTouches(t.touches), this.touchStartTranslateX = this.translateX, this.touchStartTranslateY = this.translateY, t.preventDefault();
|
|
130
|
-
}
|
|
131
|
-
handleTouchmove(t) {
|
|
132
|
-
t.preventDefault();
|
|
133
|
-
const e = Array.from(t.touches).map((s) => this.clientCoordsToWrapperCoords(s.clientX, s.clientY));
|
|
134
|
-
if (this.touchStarts) {
|
|
135
|
-
if (e.length >= 2 && this.touchStarts.length >= 2) {
|
|
136
|
-
const s = [this.touchStarts[0].canvasRel[0] * this.canvasBounds.width, this.touchStarts[0].canvasRel[1] * this.canvasBounds.height], n = [this.touchStarts[1].canvasRel[0] * this.canvasBounds.width, this.touchStarts[1].canvasRel[1] * this.canvasBounds.height], a = Math.sqrt(Math.pow(s[0] - n[0], 2) + Math.pow(s[1] - n[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 = Y(i / a, this.minScale, this.maxScale), c = [e[0][0] / this.wrapperInnerWidth, e[0][1] / this.wrapperInnerHeight], l = this.touchStarts[0].canvasRel, [u, d] = this.calcProjectionTranslate(h, c, l, 0);
|
|
137
|
-
if (this.rotation) {
|
|
138
|
-
let g = 0, o = 0, p = 0;
|
|
139
|
-
const m = Math.atan2(n[1] - s[1], n[0] - s[0]);
|
|
140
|
-
p = Math.atan2(e[1][1] - e[0][1], e[1][0] - e[0][0]) - m;
|
|
141
|
-
const f = (R, E) => [this.offset.left + this.canvasBounds.width * R * this.naturalScale * h + u, this.offset.top + this.canvasBounds.height * E * this.naturalScale * h + d], b = f(0, 0), C = f(this.touchStarts[0].canvasRel[0], this.touchStarts[0].canvasRel[1]), B = w(b, C, p);
|
|
142
|
-
g = B[0] - b[0], o = B[1] - b[1], this.scale = h, this.rotate = p, this.setTranslateFromUserGesture(u + g, d + o);
|
|
143
|
-
} else
|
|
144
|
-
this.scale = h, this.setTranslateFromUserGesture(u, d);
|
|
145
|
-
} else {
|
|
146
|
-
const s = t.touches[0].clientX - this.touchStarts[0].client[0], n = t.touches[0].clientY - this.touchStarts[0].client[1], a = this.touchStartTranslateX + s, i = this.touchStartTranslateY + n;
|
|
147
|
-
this.setTranslateFromUserGesture(a, i);
|
|
148
|
-
}
|
|
149
|
-
this.update();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
handleTouchend(t) {
|
|
153
|
-
t.touches.length === 0 ? this.touchStarts = null : (this.touchStarts = this.freezeTouches(t.touches), this.touchStartTranslateX = this.translateX, this.touchStartTranslateY = this.translateY);
|
|
154
|
-
}
|
|
155
|
-
calcProjectionTranslate(t, e, s, n) {
|
|
156
|
-
const a = this.canvasBounds.width * this.naturalScale, i = this.canvasBounds.height * this.naturalScale, h = s[0] * a * t, c = s[1] * i * t, l = w([h, c], [0, 0], n ?? this.rotate), u = e[0] * this.wrapperInnerWidth, d = e[1] * this.wrapperInnerHeight, g = u - l[0], o = d - l[1];
|
|
157
|
-
return [g, o];
|
|
158
|
-
}
|
|
159
|
-
applyTransform(t, e, s) {
|
|
160
|
-
const n = this.calcProjectionTranslate(t, e, s, 0);
|
|
161
|
-
this.scale = t, this.setTranslateFromUserGesture(n[0], n[1]), this.update();
|
|
162
|
-
}
|
|
163
|
-
composeRelPoint(t, e, s, n, a, i) {
|
|
164
|
-
s = s ?? this.scale, n = n ?? this.translateX, a = a ?? this.translateY, i = i ?? this.rotate;
|
|
165
|
-
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 = w(c, h, i);
|
|
166
|
-
return [l[0] + n, l[1] + a];
|
|
167
|
-
}
|
|
168
|
-
composePoint(t, e) {
|
|
169
|
-
const s = t / this.canvasBounds.width, n = e / this.canvasBounds.height;
|
|
170
|
-
return this.composeRelPoint(s, n);
|
|
171
|
-
}
|
|
172
|
-
getAnchorOffset(t, e, s, n, a = [0.5, 0.5]) {
|
|
173
|
-
const i = this.calcProjectionTranslate(t, a, a, 0), h = [
|
|
174
|
-
this.offset.left + i[0] + this.canvasBounds.width * (t * this.naturalScale) * a[0],
|
|
175
|
-
this.offset.top + i[1] + this.canvasBounds.height * (t * this.naturalScale) * a[1]
|
|
176
|
-
], c = this.composeRelPoint(a[0], a[1], t, e, s, n), l = c[0] - h[0], u = c[1] - h[1];
|
|
177
|
-
return [l, u];
|
|
178
|
-
}
|
|
179
|
-
// Converts absolute inner wrapper coordinates to relative canvas coordinates (0-1, 0-1)
|
|
180
|
-
getCanvasCoordsRel(t, e) {
|
|
181
|
-
const s = [0, 0], n = [t - this.translateX, e - this.translateY], a = w(n, s, -this.rotate), i = [a[0] / this.renderinScale, a[1] / this.renderinScale];
|
|
182
|
-
return [i[0] / this.canvasBounds.width, i[1] / this.canvasBounds.height];
|
|
183
|
-
}
|
|
184
|
-
// Converts absolute client to coordinates to absolute inner-wrapper coorinates
|
|
185
|
-
clientCoordsToWrapperCoords(t, e) {
|
|
186
|
-
return [t - this.wrapperInnerX, e - this.wrapperInnerY];
|
|
187
|
-
}
|
|
188
|
-
// Converts absolute client coordinates to relative wrapper coordinates (0-1, 0-1)
|
|
189
|
-
relativeWrapperCoordinatesFromClientCoords(t, e) {
|
|
190
|
-
const [s, n] = this.clientCoordsToWrapperCoords(t, e);
|
|
191
|
-
return [s / this.wrapperInnerWidth, n / this.wrapperInnerHeight];
|
|
192
|
-
}
|
|
193
|
-
// Converts client coordinates to relative canvas coordinates (0-1, 0-1)
|
|
194
|
-
normalizeMatrixCoordinates(t, e) {
|
|
195
|
-
const s = this.clientCoordsToWrapperCoords(t, e);
|
|
196
|
-
return this.getCanvasCoordsRel(s[0], s[1]);
|
|
197
|
-
}
|
|
198
|
-
// Converts client coordinates to absolute canvas coordinates
|
|
199
|
-
normalizeClientCoords(t, e) {
|
|
200
|
-
const [s, n] = this.normalizeMatrixCoordinates(t, e);
|
|
201
|
-
return [s * this.canvasBounds.width, n * this.canvasBounds.height];
|
|
202
|
-
}
|
|
203
|
-
rotateCanvas(t, e, s) {
|
|
204
|
-
const n = t / this.canvasBounds.width, a = e / this.canvasBounds.height, i = this.composeRelPoint(n, a, this.scale, 0, 0, s), h = this.composeRelPoint(n, a);
|
|
205
|
-
this.setTranslateFromUserGesture(h[0] - i[0], h[1] - i[1]), this.rotate = s, this.update();
|
|
206
|
-
}
|
|
207
|
-
get renderinScale() {
|
|
208
|
-
return this.naturalScale * this.scale;
|
|
209
|
-
}
|
|
210
|
-
get renderingTranslateX() {
|
|
211
|
-
return this.offset.left + this.translateX;
|
|
212
|
-
}
|
|
213
|
-
get renderingTranslateY() {
|
|
214
|
-
return this.offset.top + this.translateY;
|
|
215
|
-
}
|
|
216
|
-
get renderingRotate() {
|
|
217
|
-
return this.rotate;
|
|
218
|
-
}
|
|
219
|
-
clampTranslate(t, e = [0.5, 0.5]) {
|
|
220
|
-
const s = this.canvasBounds.width * this.naturalScale * t.scale, n = this.canvasBounds.height * this.naturalScale * t.scale, a = s - this.wrapperInnerWidth, i = n - this.wrapperInnerHeight, h = a > 0 ? -a : 0, c = Math.min(0, Math.max(t.translateX, h)), l = i > 0 ? -i : 0, u = Math.min(0, Math.max(t.translateY, l)), d = -Math.min(0, a) * e[0], g = -Math.min(0, i) * e[1];
|
|
221
|
-
return {
|
|
222
|
-
translateX: c + d,
|
|
223
|
-
translateY: u + g
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
update() {
|
|
227
|
-
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"));
|
|
228
|
-
}
|
|
229
|
-
destroy() {
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
class M extends HTMLElement {
|
|
1
|
+
var v = Object.defineProperty;
|
|
2
|
+
var w = (a, i, e) => i in a ? v(a, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[i] = e;
|
|
3
|
+
var p = (a, i, e) => w(a, typeof i != "symbol" ? i + "" : i, e);
|
|
4
|
+
import { Zoompinch as E } from "@zoompinch/core";
|
|
5
|
+
class N extends HTMLElement {
|
|
233
6
|
constructor() {
|
|
234
7
|
super();
|
|
235
|
-
|
|
8
|
+
p(this, "engine");
|
|
236
9
|
this.attachShadow({ mode: "open" });
|
|
237
10
|
}
|
|
238
11
|
get contentEl() {
|
|
@@ -277,25 +50,25 @@ class M extends HTMLElement {
|
|
|
277
50
|
</div>
|
|
278
51
|
</div>
|
|
279
52
|
`;
|
|
280
|
-
const e = Number(this.getAttribute("translate-x") || "0"), s = Number(this.getAttribute("translate-y") || "0"), n = Number(this.getAttribute("scale") || "1"),
|
|
281
|
-
this.getAttribute("rotation"), this.engine = new
|
|
53
|
+
const e = Number(this.getAttribute("translate-x") || "0"), s = Number(this.getAttribute("translate-y") || "0"), n = Number(this.getAttribute("scale") || "1"), u = Number(this.getAttribute("rotate") || "0"), h = Number(this.getAttribute("min-scale")), c = Number(this.getAttribute("max-scale")), l = Number(this.getAttribute("offset-top")), o = Number(this.getAttribute("offset-right")), r = Number(this.getAttribute("offset-bottom")), f = Number(this.getAttribute("offset-left")), b = this.getAttribute("clamp-bounds") === "true";
|
|
54
|
+
this.getAttribute("rotation"), this.engine = new E(
|
|
282
55
|
this.contentEl,
|
|
283
56
|
{
|
|
284
|
-
top: isNaN(
|
|
285
|
-
left: isNaN(
|
|
286
|
-
right: isNaN(
|
|
287
|
-
bottom: isNaN(
|
|
57
|
+
top: isNaN(l) ? 100 : l,
|
|
58
|
+
left: isNaN(f) ? 0 : f,
|
|
59
|
+
right: isNaN(o) ? 0 : o,
|
|
60
|
+
bottom: isNaN(r) ? 0 : r
|
|
288
61
|
},
|
|
289
62
|
e,
|
|
290
63
|
s,
|
|
291
64
|
n,
|
|
292
|
-
|
|
293
|
-
isNaN(i) ? void 0 : i,
|
|
65
|
+
u,
|
|
294
66
|
isNaN(h) ? void 0 : h,
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
67
|
+
isNaN(c) ? void 0 : c,
|
|
68
|
+
b
|
|
69
|
+
), this.contentEl.addEventListener("wheel", (t) => this.engine.handleWheel(t)), this.contentEl.addEventListener("gesturestart", (t) => this.engine.handleGesturestart(t)), window.addEventListener("gesturechange", (t) => this.engine.handleGesturechange(t)), window.addEventListener("gestureend", (t) => this.engine.handleGestureend(t)), this.contentEl.addEventListener("mousedown", (t) => this.engine.handleMousedown(t)), window.addEventListener("mousemove", (t) => this.engine.handleMousemove(t)), window.addEventListener("mouseup", (t) => this.engine.handleMouseup(t)), this.contentEl.addEventListener("touchstart", (t) => this.engine.handleTouchstart(t)), window.addEventListener("touchmove", (t) => this.engine.handleTouchmove(t)), window.addEventListener("touchend", (t) => this.engine.handleTouchend(t)), this.engine.addEventListener("update", () => {
|
|
70
|
+
const t = this.engine.translateX.toString(), m = this.engine.translateY.toString(), g = this.engine.scale.toString(), d = this.engine.rotate.toString();
|
|
71
|
+
this.getAttribute("translate-x") !== t && this.setAttribute("translate-x", t), this.getAttribute("translate-y") !== m && this.setAttribute("translate-y", m), this.getAttribute("scale") !== g && this.setAttribute("scale", g), this.getAttribute("rotate") !== d && this.setAttribute("rotate", d), this.dispatchEvent(new Event("update"));
|
|
299
72
|
}), this.engine.addEventListener("init", () => {
|
|
300
73
|
this.dispatchEvent(new Event("init"));
|
|
301
74
|
});
|
|
@@ -307,48 +80,48 @@ class M extends HTMLElement {
|
|
|
307
80
|
if (this.engine)
|
|
308
81
|
switch (e) {
|
|
309
82
|
case "translate-x":
|
|
310
|
-
const
|
|
311
|
-
this.engine.translateX !==
|
|
83
|
+
const u = Number(n);
|
|
84
|
+
this.engine.translateX !== u && (this.engine.translateX = u, this.engine.update());
|
|
312
85
|
break;
|
|
313
86
|
case "translate-y":
|
|
314
|
-
const
|
|
315
|
-
this.engine.translateY !==
|
|
87
|
+
const h = Number(n);
|
|
88
|
+
this.engine.translateY !== h && (this.engine.translateY = h, this.engine.update());
|
|
316
89
|
break;
|
|
317
90
|
case "scale":
|
|
318
|
-
const
|
|
319
|
-
this.engine.scale !==
|
|
91
|
+
const c = Number(n);
|
|
92
|
+
this.engine.scale !== c && (this.engine.scale = c, this.engine.update());
|
|
320
93
|
break;
|
|
321
94
|
case "rotate":
|
|
322
|
-
const
|
|
323
|
-
this.engine.rotate !==
|
|
95
|
+
const l = Number(n);
|
|
96
|
+
this.engine.rotate !== l && (this.engine.rotate = l, this.engine.update());
|
|
324
97
|
break;
|
|
325
98
|
case "min-scale":
|
|
326
|
-
const
|
|
327
|
-
!isNaN(
|
|
99
|
+
const o = Number(n);
|
|
100
|
+
!isNaN(o) && this.engine.minScale !== o && (this.engine.minScale = o, this.engine.update());
|
|
328
101
|
break;
|
|
329
102
|
case "max-scale":
|
|
330
|
-
const
|
|
331
|
-
!isNaN(
|
|
103
|
+
const r = Number(n);
|
|
104
|
+
!isNaN(r) && this.engine.maxScale !== r && (this.engine.maxScale = r, this.engine.update());
|
|
332
105
|
break;
|
|
333
106
|
case "offset-top":
|
|
334
107
|
case "offset-right":
|
|
335
108
|
case "offset-bottom":
|
|
336
109
|
case "offset-left":
|
|
337
|
-
const
|
|
110
|
+
const f = Number(this.getAttribute("offset-top") || "0"), b = Number(this.getAttribute("offset-right") || "0"), t = Number(this.getAttribute("offset-bottom") || "0"), m = Number(this.getAttribute("offset-left") || "0");
|
|
338
111
|
this.engine.offset = {
|
|
339
|
-
top:
|
|
340
|
-
right:
|
|
341
|
-
bottom:
|
|
342
|
-
left:
|
|
112
|
+
top: f,
|
|
113
|
+
right: b,
|
|
114
|
+
bottom: t,
|
|
115
|
+
left: m
|
|
343
116
|
}, this.engine.update();
|
|
344
117
|
break;
|
|
345
118
|
case "clamp-bounds":
|
|
346
|
-
const
|
|
347
|
-
this.engine.clampBounds !==
|
|
119
|
+
const g = n === "true";
|
|
120
|
+
this.engine.clampBounds !== g && (this.engine.clampBounds = g, this.engine.setTranslateFromUserGesture(this.engine.translateX, this.engine.translateY), this.engine.update());
|
|
348
121
|
break;
|
|
349
122
|
case "rotation":
|
|
350
|
-
const
|
|
351
|
-
this.engine.rotation !==
|
|
123
|
+
const d = n === "true";
|
|
124
|
+
this.engine.rotation !== d && (this.engine.rotation = d, this.engine.update());
|
|
352
125
|
}
|
|
353
126
|
}
|
|
354
127
|
get canvasWidth() {
|
|
@@ -367,5 +140,5 @@ class M extends HTMLElement {
|
|
|
367
140
|
return this.engine.composePoint(e, s);
|
|
368
141
|
}
|
|
369
142
|
}
|
|
370
|
-
|
|
371
|
-
customElements.get("zoom-pinch") || customElements.define("zoom-pinch",
|
|
143
|
+
p(N, "observedAttributes", ["translate-x", "translate-y", "scale", "rotate", "min-scale", "max-scale", "offset-top", "offset-right", "offset-bottom", "offset-left", "clamp-bounds", "rotation"]);
|
|
144
|
+
customElements.get("zoom-pinch") || customElements.define("zoom-pinch", N);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(i,e){typeof exports=="object"&&typeof module<"u"?e(require("@zoompinch/core")):typeof define=="function"&&define.amd?define(["@zoompinch/core"],e):(i=typeof globalThis<"u"?globalThis:i||self,e(i.ZoompinchCore))})(this,(function(i){"use strict";var v=Object.defineProperty;var w=(i,e,h)=>e in i?v(i,e,{enumerable:!0,configurable:!0,writable:!0,value:h}):i[e]=h;var N=(i,e,h)=>w(i,typeof e!="symbol"?e+"":e,h);class e extends HTMLElement{constructor(){super();N(this,"engine");this.attachShadow({mode:"open"})}get contentEl(){return this.shadowRoot.querySelector(".content")}get canvasElement(){return this.shadowRoot.querySelector(".canvas")}connectedCallback(){this.shadowRoot.innerHTML=`
|
|
2
2
|
<style>
|
|
3
3
|
:host {
|
|
4
4
|
display: block;
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
<slot name="matrix"></slot>
|
|
33
33
|
</div>
|
|
34
34
|
</div>
|
|
35
|
-
`;const
|
|
35
|
+
`;const s=Number(this.getAttribute("translate-x")||"0"),a=Number(this.getAttribute("translate-y")||"0"),n=Number(this.getAttribute("scale")||"1"),f=Number(this.getAttribute("rotate")||"0"),c=Number(this.getAttribute("min-scale")),l=Number(this.getAttribute("max-scale")),d=Number(this.getAttribute("offset-top")),o=Number(this.getAttribute("offset-right")),r=Number(this.getAttribute("offset-bottom")),m=Number(this.getAttribute("offset-left")),p=this.getAttribute("clamp-bounds")==="true";this.getAttribute("rotation"),this.engine=new i.Zoompinch(this.contentEl,{top:isNaN(d)?100:d,left:isNaN(m)?0:m,right:isNaN(o)?0:o,bottom:isNaN(r)?0:r},s,a,n,f,isNaN(c)?void 0:c,isNaN(l)?void 0:l,p),this.contentEl.addEventListener("wheel",t=>this.engine.handleWheel(t)),this.contentEl.addEventListener("gesturestart",t=>this.engine.handleGesturestart(t)),window.addEventListener("gesturechange",t=>this.engine.handleGesturechange(t)),window.addEventListener("gestureend",t=>this.engine.handleGestureend(t)),this.contentEl.addEventListener("mousedown",t=>this.engine.handleMousedown(t)),window.addEventListener("mousemove",t=>this.engine.handleMousemove(t)),window.addEventListener("mouseup",t=>this.engine.handleMouseup(t)),this.contentEl.addEventListener("touchstart",t=>this.engine.handleTouchstart(t)),window.addEventListener("touchmove",t=>this.engine.handleTouchmove(t)),window.addEventListener("touchend",t=>this.engine.handleTouchend(t)),this.engine.addEventListener("update",()=>{const t=this.engine.translateX.toString(),b=this.engine.translateY.toString(),u=this.engine.scale.toString(),g=this.engine.rotate.toString();this.getAttribute("translate-x")!==t&&this.setAttribute("translate-x",t),this.getAttribute("translate-y")!==b&&this.setAttribute("translate-y",b),this.getAttribute("scale")!==u&&this.setAttribute("scale",u),this.getAttribute("rotate")!==g&&this.setAttribute("rotate",g),this.dispatchEvent(new Event("update"))}),this.engine.addEventListener("init",()=>{this.dispatchEvent(new Event("init"))})}disconnectedCallback(){this.engine.destroy()}attributeChangedCallback(s,a,n){if(this.engine)switch(s){case"translate-x":const f=Number(n);this.engine.translateX!==f&&(this.engine.translateX=f,this.engine.update());break;case"translate-y":const c=Number(n);this.engine.translateY!==c&&(this.engine.translateY=c,this.engine.update());break;case"scale":const l=Number(n);this.engine.scale!==l&&(this.engine.scale=l,this.engine.update());break;case"rotate":const d=Number(n);this.engine.rotate!==d&&(this.engine.rotate=d,this.engine.update());break;case"min-scale":const o=Number(n);!isNaN(o)&&this.engine.minScale!==o&&(this.engine.minScale=o,this.engine.update());break;case"max-scale":const r=Number(n);!isNaN(r)&&this.engine.maxScale!==r&&(this.engine.maxScale=r,this.engine.update());break;case"offset-top":case"offset-right":case"offset-bottom":case"offset-left":const m=Number(this.getAttribute("offset-top")||"0"),p=Number(this.getAttribute("offset-right")||"0"),t=Number(this.getAttribute("offset-bottom")||"0"),b=Number(this.getAttribute("offset-left")||"0");this.engine.offset={top:m,right:p,bottom:t,left:b},this.engine.update();break;case"clamp-bounds":const u=n==="true";this.engine.clampBounds!==u&&(this.engine.clampBounds=u,this.engine.setTranslateFromUserGesture(this.engine.translateX,this.engine.translateY),this.engine.update());break;case"rotation":const g=n==="true";this.engine.rotation!==g&&(this.engine.rotation=g,this.engine.update())}}get canvasWidth(){return this.engine.canvasBounds.width}get canvasHeight(){return this.engine.canvasBounds.height}applyTransform(s,a,n){this.engine.applyTransform(s,a,n)}normalizeClientCoords(s,a){return this.engine.normalizeClientCoords(s,a)}composePoint(s,a){return this.engine.composePoint(s,a)}}N(e,"observedAttributes",["translate-x","translate-y","scale","rotate","min-scale","max-scale","offset-top","offset-right","offset-bottom","offset-left","clamp-bounds","rotation"]),customElements.get("zoom-pinch")||customElements.define("zoom-pinch",e)}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zoompinch/elements",
|
|
3
3
|
"description": "Custom elements wrapper ZoomPinch - reactive pinch & zoom component",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.26",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/zoompinch-elements.umd.js",
|
|
@@ -14,6 +14,18 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"custom elements",
|
|
19
|
+
"zoompinch",
|
|
20
|
+
"zoom images",
|
|
21
|
+
"pinch to zoom",
|
|
22
|
+
"image zoom",
|
|
23
|
+
"pan gesture",
|
|
24
|
+
"pan and zoom",
|
|
25
|
+
"panzoom",
|
|
26
|
+
"gesture library",
|
|
27
|
+
"touch gestures"
|
|
28
|
+
],
|
|
17
29
|
"files": [
|
|
18
30
|
"dist"
|
|
19
31
|
],
|
|
@@ -26,7 +38,7 @@
|
|
|
26
38
|
"vite": "^6.4.1"
|
|
27
39
|
},
|
|
28
40
|
"dependencies": {
|
|
29
|
-
"@zoompinch/core": "^0.0.
|
|
41
|
+
"@zoompinch/core": "^0.0.25"
|
|
30
42
|
},
|
|
31
43
|
"publishConfig": {
|
|
32
44
|
"access": "public"
|