//#region src/charts/zoom.ts
var e = .1, t = 10, n = .001, r = class {
	canvas;
	onZoom;
	transform;
	dragging = !1;
	lastX = 0;
	lastY = 0;
	handleWheel;
	handleMouseDown;
	handleMouseMove;
	handleMouseUp;
	constructor(e, t) {
		this.canvas = e, this.onZoom = t, this.transform = {
			scaleX: 1,
			scaleY: 1,
			translateX: 0,
			translateY: 0
		}, this.handleWheel = (e) => {
			e.preventDefault();
			let t = -e.deltaY * n, r = i(this.transform.scaleX + t), a = i(this.transform.scaleY + t);
			this.transform = {
				...this.transform,
				scaleX: r,
				scaleY: a
			}, this.onZoom(this.getTransform());
		}, this.handleMouseDown = (e) => {
			this.dragging = !0, this.lastX = e.clientX, this.lastY = e.clientY, this.canvas.style.cursor = "grabbing";
		}, this.handleMouseMove = (e) => {
			if (!this.dragging) return;
			let t = e.clientX - this.lastX, n = e.clientY - this.lastY;
			this.lastX = e.clientX, this.lastY = e.clientY, this.transform = {
				...this.transform,
				translateX: this.transform.translateX + t,
				translateY: this.transform.translateY + n
			}, this.onZoom(this.getTransform());
		}, this.handleMouseUp = () => {
			this.dragging = !1, this.canvas.style.cursor = "";
		}, this.canvas.addEventListener("wheel", this.handleWheel, { passive: !1 }), this.canvas.addEventListener("mousedown", this.handleMouseDown), window.addEventListener("mousemove", this.handleMouseMove), window.addEventListener("mouseup", this.handleMouseUp);
	}
	reset() {
		this.transform = {
			scaleX: 1,
			scaleY: 1,
			translateX: 0,
			translateY: 0
		}, this.onZoom(this.getTransform());
	}
	getTransform() {
		return { ...this.transform };
	}
	destroy() {
		this.canvas.removeEventListener("wheel", this.handleWheel), this.canvas.removeEventListener("mousedown", this.handleMouseDown), window.removeEventListener("mousemove", this.handleMouseMove), window.removeEventListener("mouseup", this.handleMouseUp);
	}
};
function i(n) {
	return Math.min(Math.max(n, e), t);
}
//#endregion
export { r as ChartZoom };

//# sourceMappingURL=zoom.js.map