feat(web-admin): add image preview transform helpers for fit/zoom.
Pure functions for AttachmentUploadField image preview rotate/zoom math, with a Node assert script. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8435836d81
commit
0af792f535
2 files changed
+99
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
IMAGE_PREVIEW_ZOOM_MIN,
|
||||
IMAGE_PREVIEW_ZOOM_MAX,
|
||||
IMAGE_PREVIEW_ZOOM_STEP,
|
||||
clampPreviewZoom,
|
||||
computeFitBaseScale,
|
||||
buildPreviewTransformCss
|
||||
} from '../src/utils/image-preview-transform.js'
|
||||
|
||||
assert.equal(IMAGE_PREVIEW_ZOOM_MIN, 0.5)
|
||||
assert.equal(IMAGE_PREVIEW_ZOOM_MAX, 5)
|
||||
assert.equal(IMAGE_PREVIEW_ZOOM_STEP, 0.15)
|
||||
|
||||
assert.equal(clampPreviewZoom(0.1), 0.5)
|
||||
assert.equal(clampPreviewZoom(9), 5)
|
||||
assert.equal(clampPreviewZoom(1.234), 1.23)
|
||||
|
||||
// 未旋转:640x400 装入 320x200 → scale = 0.5
|
||||
assert.ok(
|
||||
Math.abs(computeFitBaseScale(640, 400, 0, 320, 200) - 0.5) < 1e-9
|
||||
)
|
||||
|
||||
// 旋转 90°:外接 400x640 装入 320x200 → scale = min(320/400, 200/640) = 0.3125
|
||||
assert.ok(
|
||||
Math.abs(computeFitBaseScale(640, 400, 90, 320, 200) - 0.3125) < 1e-9
|
||||
)
|
||||
|
||||
assert.equal(
|
||||
buildPreviewTransformCss(10, -20, 90, 0.5),
|
||||
'translate(10px, -20px) rotate(90deg) scale(0.5)'
|
||||
)
|
||||
|
||||
console.log('image-preview-transform ok')
|
||||
Reference in new issue
Block a user