feat: inital implementation

This commit is contained in:
jfmcarreira committed 2026-09-08 13:38:39 +01:00
commit 924f57fe03
37 files changed
+4815

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import {
clampOverlayTransform,
fitDisplayDimensions,
positionInCorner,
} from '../src/utils/editorMath.ts'
test('fitDisplayDimensions keeps source coordinates independent from display size', () => {
assert.deepEqual(fitDisplayDimensions({ width: 4032, height: 3024 }, 900), {
width: 900,
height: 675,
})
assert.deepEqual(fitDisplayDimensions({ width: 800, height: 600 }, 1200), {
width: 800,
height: 600,
})
})
test('clampOverlayTransform keeps the full overlay inside the source image', () => {
const result = clampOverlayTransform(400, 200, 950, -50, 0.5, {
width: 1000,
height: 500,
})
assert.equal(result.scale, 0.5)
assert.equal(result.width, 200)
assert.equal(result.height, 100)
assert.equal(result.x, 800)
assert.equal(result.y, 0)
})
test('clampOverlayTransform limits oversized overlays without changing aspect ratio', () => {
const result = clampOverlayTransform(2000, 1000, 0, 0, 1, {
width: 1000,
height: 400,
})
assert.equal(result.scale, 0.4)
assert.equal(result.width, 800)
assert.equal(result.height, 400)
})
test('positionInCorner uses a proportional margin and does not clip the object', () => {
const position = positionInCorner(
'bottom-right',
{ width: 200, height: 100 },
{ width: 1000, height: 500 },
)
assert.equal(position.x, 787.5)
assert.equal(position.y, 387.5)
})
+23
View File
@@ -0,0 +1,23 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { parseOverlayLibrary } from '../src/utils/overlayConfig.ts'
test('parseOverlayLibrary accepts simple local raster files', () => {
assert.deepEqual(
parseOverlayLibrary([{ id: 'crr', name: ' CRR Logo ', file: 'crr-logo.png' }]),
[{ id: 'crr', name: 'CRR Logo', file: 'crr-logo.png' }],
)
})
test('parseOverlayLibrary rejects duplicate ids', () => {
assert.throws(() => parseOverlayLibrary([
{ id: 'crr', name: 'One', file: 'one.png' },
{ id: 'crr', name: 'Two', file: 'two.png' },
]))
})
test('parseOverlayLibrary rejects paths, URLs, and SVG files', () => {
for (const file of ['../logo.png', 'nested/logo.png', 'https://example.test/logo.png', 'logo.svg']) {
assert.throws(() => parseOverlayLibrary([{ id: 'bad', name: 'Bad', file }]))
}
})