From d52f1777e0f1644008e4d04fd66e8aafe69a4928 Mon Sep 17 00:00:00 2001 From: Reece Date: Fri, 14 Nov 2025 14:02:19 +0000 Subject: [PATCH] import annotation type enum --- frontend/src/core/components/viewer/HistoryAPIBridge.tsx | 8 ++++---- .../src/core/components/viewer/SignatureAPIBridge.tsx | 2 +- frontend/src/core/utils/signatureFlattening.ts | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/frontend/src/core/components/viewer/HistoryAPIBridge.tsx b/frontend/src/core/components/viewer/HistoryAPIBridge.tsx index 8c463d8e2..30378b950 100644 --- a/frontend/src/core/components/viewer/HistoryAPIBridge.tsx +++ b/frontend/src/core/components/viewer/HistoryAPIBridge.tsx @@ -2,7 +2,7 @@ import { useImperativeHandle, forwardRef, useEffect, useRef } from 'react'; import { useHistoryCapability } from '@embedpdf/plugin-history/react'; import { useAnnotationCapability } from '@embedpdf/plugin-annotation/react'; import { useSignature } from '@app/contexts/SignatureContext'; -import { uuidV4 } from '@embedpdf/models'; +import { PdfAnnotationSubtype, uuidV4 } from '@embedpdf/models'; import type { HistoryAPI } from '@app/components/viewer/viewerTypes'; import { ANNOTATION_RECREATION_DELAY_MS, ANNOTATION_VERIFICATION_DELAY_MS } from '@app/core/constants/app'; @@ -20,14 +20,14 @@ export const HistoryAPIBridge = forwardRef(function HistoryAPIBridge const annotation = event.annotation; // Store image data for all STAMP annotations immediately when created or modified - if (annotation && annotation.type === 13 && annotation.id && annotation.imageSrc) { + if (annotation && annotation.type === PdfAnnotationSubtype.STAMP && annotation.id && annotation.imageSrc) { const storedImageData = getImageData(annotation.id); if (!storedImageData) { storeImageData(annotation.id, annotation.imageSrc); } } - if (annotation && annotation.type === 13 && annotation.id) { + if (annotation && annotation.type === PdfAnnotationSubtype.STAMP && annotation.id) { // Prevent infinite loops when we recreate annotations if (restoringIds.current.has(annotation.id)) { restoringIds.current.delete(annotation.id); @@ -71,7 +71,7 @@ export const HistoryAPIBridge = forwardRef(function HistoryAPIBridge // Handle annotation restoration after undo operations if (event.type === 'create' && event.committed) { // Check if this is a STAMP annotation (signature) that might need image data restoration - if (annotation && annotation.type === 13 && annotation.id) { + if (annotation && annotation.type === PdfAnnotationSubtype.STAMP && annotation.id) { getImageData(annotation.id); // Delay the check to allow the annotation to be fully created diff --git a/frontend/src/core/components/viewer/SignatureAPIBridge.tsx b/frontend/src/core/components/viewer/SignatureAPIBridge.tsx index c222972eb..e66bc60e0 100644 --- a/frontend/src/core/components/viewer/SignatureAPIBridge.tsx +++ b/frontend/src/core/components/viewer/SignatureAPIBridge.tsx @@ -346,7 +346,7 @@ export const SignatureAPIBridge = forwardRef(function SignatureAPI if (pageAnnotationsTask) { pageAnnotationsTask.toPromise().then((pageAnnotations: any) => { const annotation = pageAnnotations?.find((ann: any) => ann.id === annotationId); - if (annotation && annotation.type === 13 && annotation.imageSrc) { + if (annotation && annotation.type === PdfAnnotationSubtype.STAMP && annotation.imageSrc) { // Store image data before deletion storeImageData(annotationId, annotation.imageSrc); } diff --git a/frontend/src/core/utils/signatureFlattening.ts b/frontend/src/core/utils/signatureFlattening.ts index 25c187020..f4c2fbed9 100644 --- a/frontend/src/core/utils/signatureFlattening.ts +++ b/frontend/src/core/utils/signatureFlattening.ts @@ -1,4 +1,5 @@ import { PDFDocument, rgb } from 'pdf-lib'; +import { PdfAnnotationSubtype } from '@embedpdf/models'; import { generateThumbnailWithMetadata } from '@app/utils/thumbnailUtils'; import { createProcessedFile, createChildStub } from '@app/contexts/file/fileActions'; import { createStirlingFile, StirlingFile, FileId, StirlingFileStub } from '@app/types/fileContext'; @@ -228,7 +229,7 @@ export async function flattenSignatures(options: SignatureFlatteningOptions): Pr size: 12, color: rgb(0, 0, 0) }); - } else if (annotation.type === 14 || annotation.type === 15) { + } else if (annotation.type === PdfAnnotationSubtype.INK || annotation.type === PdfAnnotationSubtype.LINE) { // Handle ink annotations (drawn signatures) page.drawRectangle({ x: pdfX,