import { pageNumberOf } from "@/lib/model/locus" import type { FacsimileConfig } from "@/lib/schemas/model" /** * Facsimile asset resolution (ยง4). The catalog stores **relative** keys; the * delivery base is a runtime env (`VITE_FACSIMILE_BASE`) so one catalog serves * both dev (the `public/facsimile/` copy) and prod (the R2 public base). */ export type ImagesConfig = Extract export type PdfConfig = Extract export function facsimileBase(): string { const base = import.meta.env.VITE_FACSIMILE_BASE ?? "/facsimile/" return base.endsWith("/") ? base : `${base}/` } /** Husserl: the page image for an anchor, or null if that page isn't mapped. */ export function imageUrlFor(config: ImagesConfig, anchorId: string | null): string | null { if (!anchorId) return null const key = config.pages[anchorId] return key ? facsimileBase() + key : null } /** Heidegger: the source PDF URL (rendered client-side via pdf.js). */ export function pdfUrlFor(config: PdfConfig): string { return facsimileBase() + config.pdfKey } /** Heidegger: 1-based PDF page for an anchor (print page + delta), or null. */ export function pdfPageFor(config: PdfConfig, anchorId: string | null): number | null { if (!anchorId) return null const n = pageNumberOf(anchorId) return n === null ? null : n + config.pageDelta }