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 { 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: [], shifts: [], maps: [], templates: [], ...overrides, }; } export function entityRow(id: string, kind: ExportData["entities"][number]["kind"], name: string, extra: Partial = {}): ExportData["entities"][number] { return { id, kind, name, code: null, summary: null, tags: [], data: {}, image: 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 { 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()); }