first commit
Verify / test (push) Failing after 2m54s

This commit is contained in:
2026-11-05 17:31:17 +03:30
کامیت 56c5ee23d3
63فایلهای تغییر یافته به همراه2749 افزوده شده و 0 حذف شده
+20
مشاهده پرونده
@@ -0,0 +1,20 @@
/** SVG viewBox camera. All pointer math is in viewport pixels / document units. */
export class Camera {
constructor(bounds, width, height) { this.bounds = bounds; this.resize(width, height); this.fit(); }
resize(width, height) { this.width = Math.max(1, width); this.height = Math.max(1, height); }
fit() {
const b = this.bounds;
this.scale = Math.min(this.width / b.width, this.height / b.height);
this.fitScale = this.scale;
this.x = (this.width - b.width * this.scale) / 2 - b.x * this.scale;
this.y = (this.height - b.height * this.scale) / 2 - b.y * this.scale;
}
world(x, y) { return { x: (x - this.x) / this.scale, y: (y - this.y) / this.scale }; }
zoom(factor, x, y) {
const p = this.world(x, y);
this.scale = Math.min(this.fitScale * 200, Math.max(this.fitScale * .05, this.scale * factor));
this.x = x - p.x * this.scale; this.y = y - p.y * this.scale;
}
pan(x, y) { this.x += x; this.y += y; }
get viewBox() { return `${-this.x / this.scale} ${-this.y / this.scale} ${this.width / this.scale} ${this.height / this.scale}`; }
}