fix: cleanup

This commit is contained in:
2026-06-04 06:42:27 -05:00
parent f989b144cf
commit 654cfec147
52 changed files with 290 additions and 540 deletions
+1 -29
View File
@@ -7,10 +7,6 @@ export interface ParsedPdfAnchor {
const PDF_ANCHOR_PREFIX = "pdf:v1:";
export function isPdfAnchor(anchor: string): boolean {
return anchor.startsWith(PDF_ANCHOR_PREFIX) || anchor.startsWith("pdf:page:");
}
export function parsePageHref(href: string): number | null {
const match = href.match(/^pdf:page:(\d+)$/);
if (!match) return null;
@@ -38,7 +34,7 @@ export function parsePdfAnchor(anchor: string): ParsedPdfAnchor | null {
const rectsMatch = anchor.match(/rects=([^;]+)/);
let rects: PdfRect[] = [];
if (rectsMatch) {
if (rectsMatch?.[1]) {
try {
const parsed = JSON.parse(decodeURIComponent(rectsMatch[1])) as unknown;
if (Array.isArray(parsed)) {
@@ -56,27 +52,3 @@ export function parsePdfAnchor(anchor: string): ParsedPdfAnchor | null {
return { page, rects };
}
export function rectsFromSelection(
range: Range,
pageElement: HTMLElement,
): PdfRect[] {
const pageRect = pageElement.getBoundingClientRect();
if (pageRect.width <= 0 || pageRect.height <= 0) return [];
const rects: PdfRect[] = [];
for (const clientRect of range.getClientRects()) {
if (clientRect.width <= 0 || clientRect.height <= 0) continue;
const x = (clientRect.left - pageRect.left) / pageRect.width;
const y = (clientRect.top - pageRect.top) / pageRect.height;
const w = clientRect.width / pageRect.width;
const h = clientRect.height / pageRect.height;
rects.push([
Math.max(0, Math.min(1, x)),
Math.max(0, Math.min(1, y)),
Math.max(0, Math.min(1, w)),
Math.max(0, Math.min(1, h)),
]);
}
return rects;
}