Select tool (S): lasso picks ink strokes and images that lie entirely inside the loop, a tap picks one object. Move, uniform resize, nudge, delete, recolour, copy/cut/paste/duplicate, each one undo step. Holding the pen's barrel button lassoes with any tool (Settings > Pen & touch). Copying also writes a PNG of the selection to the system clipboard. Images come in by paste, drop, the Insert image button or the page menu. They are capped at 2400 px, stored as PNG/JPEG by content hash in a new IndexedDB store, drawn between the markdown and the ink, and written to the PDF both visibly and as papure/assets + per-page images.json. Dark pages now invert each layer except images, so images keep their colours; the inverted ink layer is screen-blended so highlighted text stays bright. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UcbKnqfprs8hMkTVsYx1dh
38 lines
1.8 KiB
TypeScript
38 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { PageImage, Stroke } from '$lib/model/types';
|
|
import { imageSize, instantiate, makeClip, placeCentred } from './clip';
|
|
|
|
const s: Stroke = { id: 's', tool: 'pen', color: '#000', width: 2, pressure: false, points: [110, 210, 0.5, 0, 0, 0, 150, 260, 0.5, 0, 0, 8] };
|
|
const img: PageImage = { id: 'i', assetId: 'a', x: 100, y: 200, width: 20, height: 10 };
|
|
const A4 = { width: 595.28, height: 841.89 };
|
|
|
|
describe('clip', () => {
|
|
it('normalises to the bounding box and pastes fresh copies', () => {
|
|
const clip = makeClip([s], [img])!;
|
|
expect(clip).toMatchObject({ width: 51, height: 61 });
|
|
expect(clip.images[0]).toMatchObject({ x: 0, y: 0 });
|
|
expect(clip.strokes[0].points.slice(0, 2)).toEqual([10, 10]);
|
|
|
|
const pasted = instantiate(clip, 300, 400);
|
|
expect(pasted.images[0]).toMatchObject({ x: 300, y: 400, assetId: 'a' });
|
|
expect(pasted.strokes[0].points.slice(6, 8)).toEqual([350, 460]);
|
|
expect(pasted.strokes[0].id).not.toBe('s');
|
|
expect(pasted.images[0].id).not.toBe('i');
|
|
expect(makeClip([], [])).toBeNull();
|
|
});
|
|
|
|
it('keeps pasted things on the page', () => {
|
|
expect(placeCentred(300, 400, { width: 100, height: 50 }, A4)).toEqual({ x: 250, y: 375 });
|
|
expect(placeCentred(10, 10, { width: 100, height: 50 }, A4)).toEqual({ x: 0, y: 0 });
|
|
expect(placeCentred(590, 840, { width: 100, height: 50 }, A4)).toEqual({ x: 495.28, y: 791.89 });
|
|
// Larger than the page: centred on it.
|
|
expect(placeCentred(0, 0, { width: 700, height: 50 }, A4).x).toBeCloseTo(-52.36);
|
|
});
|
|
|
|
it('sizes images at 96 dpi, at most 80 % of the page', () => {
|
|
expect(imageSize({ width: 400, height: 200 }, A4)).toEqual({ width: 300, height: 150 });
|
|
const big = imageSize({ width: 2400, height: 1200 }, A4);
|
|
expect(big.width).toBeCloseTo(476.22);
|
|
expect(big.height).toBeCloseTo(238.11);
|
|
});
|
|
});
|