feat(grid): add image preview viewer

This commit is contained in:
t8y2
2026-05-18 12:35:34 +08:00
parent cc96e2c38b
commit 29edc4c00a
7 changed files with 355 additions and 2 deletions
@@ -0,0 +1,26 @@
import { strict as assert } from "node:assert";
import test from "node:test";
import {
clampImagePreviewScale,
imagePreviewTransform,
nextImagePreviewScale,
} from "../../apps/desktop/src/lib/imagePreviewViewer.ts";
test("clamps image preview zoom to usable bounds", () => {
assert.equal(clampImagePreviewScale(0.1), 0.2);
assert.equal(clampImagePreviewScale(1.25), 1.25);
assert.equal(clampImagePreviewScale(12), 8);
});
test("zooms in fixed steps from wheel direction", () => {
assert.equal(nextImagePreviewScale(1, "in"), 1.2);
assert.equal(nextImagePreviewScale(1, "out"), 0.8);
assert.equal(nextImagePreviewScale(7.95, "in"), 8);
});
test("builds a stable CSS transform for image previews", () => {
assert.equal(
imagePreviewTransform({ scale: 1.5, rotation: 90, offsetX: 12, offsetY: -8 }),
"translate(12px, -8px) rotate(90deg) scale(1.5)",
);
});