21 lines
1019 B
JavaScript
21 lines
1019 B
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { mapPoint } from '../src/lib/gestures.ts'
|
|
|
|
const phone = { width: 1080, height: 2400 }
|
|
test('maps the same phone position across zoom and pane scroll offsets', () => {
|
|
for (const rect of [
|
|
{ left: 30, top: 110, width: 348, height: 773.333 },
|
|
{ left: -300, top: -600, width: 1152, height: 2560 },
|
|
{ left: 100, top: 80, width: 288, height: 640 },
|
|
]) {
|
|
assert.deepEqual(mapPoint(rect.left + rect.width / 2, rect.top + rect.height / 2, rect, phone), { x: 540, y: 1200 })
|
|
assert.deepEqual(mapPoint(rect.left, rect.top, rect, phone), { x: 0, y: 0 })
|
|
assert.deepEqual(mapPoint(rect.left + rect.width, rect.top + rect.height, rect, phone), { x: 1079, y: 2399 })
|
|
}
|
|
})
|
|
test('maps landscape video coordinates and clamps endpoints outside the image', () => {
|
|
const rotated = { width: 1280, height: 576 }
|
|
assert.deepEqual(mapPoint(2000, -300, { left: 0, top: 0, width: 600, height: 270 }, rotated), { x: 1279, y: 0 })
|
|
})
|