Relationer får ett släktband (förälder, partner, syskon) och en period. Nytt släktträd som ritas av släktbanden, och en tidslinje som samlar födelse och död, scenarier, egna händelser och relationsperioder med ålder vid varje tillfälle. Datum skrivs som ÅÅÅÅ, ÅÅÅÅ-MM eller ÅÅÅÅ-MM-DD. Följer med i export, import och papperskorg. Migreringen 0006 ger gamla relationer som "Förälder till" rätt släktband. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
44 lines
1.9 KiB
TypeScript
44 lines
1.9 KiB
TypeScript
import sharp from "sharp";
|
|
import type { ExportData } from "@/lib/book-transfer";
|
|
|
|
/** En giltig minimal exportfil. Åsidosätt delar för att testa enskilda fall. */
|
|
export function validExport(overrides: Partial<ExportData> = {}): ExportData {
|
|
return {
|
|
format: "bookmanager-export",
|
|
version: 1,
|
|
exportedAt: "2026-01-01T00:00:00.000Z",
|
|
includesImages: false,
|
|
book: { title: "Testbok", subtitle: null, genre: null, description: null },
|
|
entities: [],
|
|
relations: [],
|
|
events: [],
|
|
shifts: [],
|
|
maps: [],
|
|
templates: [],
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
export function entityRow(id: string, kind: ExportData["entities"][number]["kind"], name: string, extra: Partial<ExportData["entities"][number]> = {}): ExportData["entities"][number] {
|
|
return { id, kind, name, code: null, summary: null, tags: [], data: {}, image: null, ...extra };
|
|
}
|
|
|
|
export function relationRow(id: string, fromId: string, toId: string, type: string, extra: Partial<ExportData["relations"][number]> = {}): ExportData["relations"][number] {
|
|
return { id, code: null, fromId, toId, type, description: null, data: {}, members: [], bond: null, startDate: null, endDate: null, ...extra };
|
|
}
|
|
|
|
/** En riktig bild (PNG, JPEG eller WebP) av önskad storlek, för tester av bildbehandling och uppladdning. */
|
|
export async function makeImage(
|
|
width: number,
|
|
height: number,
|
|
format: "png" | "jpeg" | "webp" = "png",
|
|
options: { orientation?: number } = {},
|
|
): Promise<Uint8Array> {
|
|
let pipeline = sharp({ create: { width, height, channels: 3, background: { r: 200, g: 60, b: 60 } } });
|
|
if (format === "png") pipeline = pipeline.png();
|
|
else if (format === "jpeg") pipeline = pipeline.jpeg({ quality: 40 });
|
|
else pipeline = pipeline.webp({ quality: 40 });
|
|
if (options.orientation) pipeline = pipeline.withMetadata({ orientation: options.orientation });
|
|
return new Uint8Array(await pipeline.toBuffer());
|
|
}
|