Refactor and enhance type safety across various modules

- Updated function parameters and return types in `page-preview.ts`, `pdf-decrypt.ts`, and `pymupdf-loader.ts` for improved type safety.
- Introduced type definitions for `CpdfInstance`, `PyMuPDFInstance`, and other related types to ensure better type checking.
- Enhanced error handling in `sanitize.ts` by creating a utility function for error messages.
- Removed unnecessary type assertions and improved type inference in `editor.ts`, `serialization.ts`, and `tools.test.ts`.
- Added type definitions for markdown-it plugins to improve compatibility and type safety.
- Enforced stricter TypeScript settings by enabling `noImplicitAny` in `tsconfig.json`.
- Cleaned up test files by refining type assertions and ensuring consistency in type usage.
This commit is contained in:
alam00000
2026-03-31 17:59:49 +05:30
parent a1fc2fc3c6
commit 9d0b68e18c
114 changed files with 2577 additions and 1868 deletions

View File

@@ -28,7 +28,7 @@ type PdfViewerWindow = Window & {
};
import { initializeGlobalShortcuts } from '../utils/shortcuts-init.js';
import { downloadFile, hexToRgb, getPDFDocument } from '../utils/helpers.js';
import { downloadFile, hexToRgb } from '../utils/helpers.js';
import { loadPdfWithPasswordPrompt } from '../utils/password-prompt.js';
import { createIcons, icons } from 'lucide';
import * as pdfjsLib from 'pdfjs-dist';
@@ -319,15 +319,15 @@ toolItems.forEach((item) => {
let touchStartY = 0;
let isTouchDragging = false;
item.addEventListener('touchstart', (e) => {
item.addEventListener('touchstart', (e: TouchEvent) => {
const touch = e.touches[0];
touchStartX = touch.clientX;
touchStartY = touch.clientY;
isTouchDragging = false;
});
item.addEventListener('touchmove', (e) => {
e.preventDefault(); // Prevent scrolling while dragging
item.addEventListener('touchmove', (e: TouchEvent) => {
e.preventDefault();
const touch = e.touches[0];
const moveX = Math.abs(touch.clientX - touchStartX);
const moveY = Math.abs(touch.clientY - touchStartY);
@@ -338,7 +338,7 @@ toolItems.forEach((item) => {
}
});
item.addEventListener('touchend', (e) => {
item.addEventListener('touchend', (e: TouchEvent) => {
e.preventDefault();
if (!isTouchDragging) {
// It was a tap, treat as click
@@ -2131,8 +2131,7 @@ downloadBtn.addEventListener('click', async () => {
nameCount.set(field.name, count + 1);
if (existingFieldNames.has(field.name)) {
if (field.type === 'radio' && existingRadioGroups.has(field.name)) {
} else {
if (!(field.type === 'radio' && existingRadioGroups.has(field.name))) {
conflictsWithPdf.push(field.name);
}
}
@@ -2337,7 +2336,7 @@ downloadBtn.addEventListener('click', async () => {
const existingField = form.getFieldMaybe(groupName);
if (existingField) {
radioGroup = existingField;
radioGroup = existingField as PDFRadioGroup;
radioGroups.set(groupName, radioGroup);
console.log(`Using existing radio group from PDF: ${groupName}`);
} else {
@@ -2788,11 +2787,11 @@ function getPageDimensions(size: string): { width: number; height: number } {
case 'a3':
dimensions = PageSizes.A3;
break;
case 'custom':
// Get custom dimensions from inputs
case 'custom': {
const width = parseInt(customWidth.value) || 612;
const height = parseInt(customHeight.value) || 792;
return { width, height };
}
default:
dimensions = PageSizes.Letter;
}