feat(web): let users set their own photo on the account page
Pick a PNG/JPEG/WebP file, crop it to a square on a canvas (drag, wheel, slider or keyboard), export a 256x256 PNG and send it to Hub. Adds remove photo, error states, RU/EN copy and privacy policy text about the stored photo and 30-day backups.
This commit is contained in:
parent
a4cae66336
commit
4c06a17d7e
10 changed files with 739 additions and 14 deletions
40
tests/crop.test.ts
Normal file
40
tests/crop.test.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { test } from "bun:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
MAX_ZOOM,
|
||||
clampCrop,
|
||||
initialCrop,
|
||||
panBy,
|
||||
sourceRect,
|
||||
zoomTo,
|
||||
} from "../src/crop";
|
||||
|
||||
test("the first frame is centred and fills the square", () => {
|
||||
const rect = sourceRect(initialCrop(400, 200));
|
||||
assert.deepEqual(rect, { sx: 100, sy: 0, side: 200 });
|
||||
});
|
||||
test("panning never leaves empty edges and never stretches", () => {
|
||||
let state = initialCrop(400, 200);
|
||||
state = panBy(state, -10_000, 10_000, 280);
|
||||
let rect = sourceRect(state);
|
||||
assert.equal(rect.sx + rect.side, 400);
|
||||
assert.equal(rect.sy, 0);
|
||||
state = zoomTo(state, 2);
|
||||
state = panBy(state, 10_000, -10_000, 280);
|
||||
rect = sourceRect(state);
|
||||
assert.equal(rect.side, 100);
|
||||
assert.equal(rect.sx, 0);
|
||||
assert.equal(rect.sy, 100);
|
||||
});
|
||||
test("zoom is clamped and keeps the area inside the image", () => {
|
||||
const state = clampCrop({
|
||||
...initialCrop(300, 300),
|
||||
zoom: 99,
|
||||
x: -5,
|
||||
y: 900,
|
||||
});
|
||||
assert.equal(state.zoom, MAX_ZOOM);
|
||||
const { sx, sy, side } = sourceRect(state);
|
||||
assert.ok(sx >= 0 && sy >= 0 && sx + side <= 300 && sy + side <= 300);
|
||||
assert.equal(zoomTo(initialCrop(300, 300), 0.2).zoom, 1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue