mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-09-08 17:51:20 +02:00
Update PDF.js integration and dependencies
This commit is contained in:
parent
1a3e8e7ecf
commit
7d89629ecb
5802
frontend/package-lock.json
generated
5802
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -7,34 +7,34 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@atlaskit/pragmatic-drag-and-drop": "^1.7.4",
|
"@atlaskit/pragmatic-drag-and-drop": "^1.7.4",
|
||||||
"@emotion/react": "^11.14.0",
|
"@emotion/react": "^11.14.0",
|
||||||
"@emotion/styled": "^11.14.0",
|
"@emotion/styled": "^11.14.1",
|
||||||
"@iconify/react": "^6.0.0",
|
"@iconify/react": "^6.0.1",
|
||||||
"@mantine/core": "^8.0.1",
|
"@mantine/core": "^8.2.8",
|
||||||
"@mantine/dropzone": "^8.0.1",
|
"@mantine/dropzone": "^8.2.8",
|
||||||
"@mantine/hooks": "^8.0.1",
|
"@mantine/hooks": "^8.2.8",
|
||||||
"@mui/icons-material": "^7.1.0",
|
"@mui/icons-material": "^7.3.2",
|
||||||
"@mui/material": "^7.1.0",
|
"@mui/material": "^7.3.2",
|
||||||
"@tailwindcss/postcss": "^4.1.8",
|
"@tailwindcss/postcss": "^4.1.12",
|
||||||
"@tanstack/react-virtual": "^3.13.12",
|
"@tanstack/react-virtual": "^3.13.12",
|
||||||
"@testing-library/dom": "^10.4.0",
|
"@testing-library/dom": "^10.4.1",
|
||||||
"@testing-library/jest-dom": "^6.6.3",
|
"@testing-library/jest-dom": "^6.8.0",
|
||||||
"@testing-library/react": "^16.3.0",
|
"@testing-library/react": "^16.3.0",
|
||||||
"@testing-library/user-event": "^13.5.0",
|
"@testing-library/user-event": "^14.6.1",
|
||||||
"autoprefixer": "^10.4.21",
|
"autoprefixer": "^10.4.21",
|
||||||
"axios": "^1.9.0",
|
"axios": "^1.11.0",
|
||||||
"i18next": "^25.2.1",
|
"i18next": "^25.4.2",
|
||||||
"i18next-browser-languagedetector": "^8.1.0",
|
"i18next-browser-languagedetector": "^8.2.0",
|
||||||
"i18next-http-backend": "^3.0.2",
|
"i18next-http-backend": "^3.0.2",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
"pdfjs-dist": "^3.11.174",
|
"pdfjs-dist": "^5.4.149",
|
||||||
"posthog-js": "^1.261.0",
|
"posthog-js": "^1.261.4",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.1",
|
||||||
"react-dom": "^19.1.0",
|
"react-dom": "^19.1.1",
|
||||||
"react-i18next": "^15.5.2",
|
"react-i18next": "^15.7.3",
|
||||||
"react-router-dom": "^7.6.0",
|
"react-router-dom": "^7.8.2",
|
||||||
"tailwindcss": "^4.1.8",
|
"tailwindcss": "^4.1.12",
|
||||||
"web-vitals": "^2.1.4"
|
"web-vitals": "^5.1.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"predev": "npm run generate-icons",
|
"predev": "npm run generate-icons",
|
||||||
@ -74,21 +74,23 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@iconify-json/material-symbols": "^1.2.33",
|
"@iconify-json/material-symbols": "^1.2.33",
|
||||||
"@iconify/utils": "^3.0.1",
|
"@iconify/utils": "^3.0.1",
|
||||||
"@playwright/test": "^1.40.0",
|
"@playwright/test": "^1.55.0",
|
||||||
"@types/node": "^24.2.1",
|
"@types/node": "^24.3.0",
|
||||||
"@types/react": "^19.1.4",
|
"@types/pdfjs-dist": "^2.10.378",
|
||||||
"@types/react-dom": "^19.1.5",
|
"@types/react": "^19.1.12",
|
||||||
"@vitejs/plugin-react": "^4.5.0",
|
"@types/react-dom": "^19.1.9",
|
||||||
"@vitest/coverage-v8": "^1.0.0",
|
"@vitejs/plugin-react": "^5.0.2",
|
||||||
"jsdom": "^23.0.0",
|
"@vitejs/plugin-react-swc": "^4.0.1",
|
||||||
|
"@vitest/coverage-v8": "^3.2.4",
|
||||||
|
"jsdom": "^26.1.0",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"madge": "^8.0.0",
|
"madge": "^8.0.0",
|
||||||
"postcss": "^8.5.3",
|
"postcss": "^8.5.6",
|
||||||
"postcss-cli": "^11.0.1",
|
"postcss-cli": "^11.0.1",
|
||||||
"postcss-preset-mantine": "^1.17.0",
|
"postcss-preset-mantine": "^1.18.0",
|
||||||
"postcss-simple-vars": "^7.0.1",
|
"postcss-simple-vars": "^7.0.1",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.9.2",
|
||||||
"vite": "^6.3.5",
|
"vite": "^7.1.4",
|
||||||
"vitest": "^1.0.0"
|
"vitest": "^3.2.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
58353
frontend/public/pdf.worker.js
vendored
58353
frontend/public/pdf.worker.js
vendored
File diff suppressed because one or more lines are too long
4
frontend/src/global.d.ts
vendored
4
frontend/src/global.d.ts
vendored
@ -15,4 +15,6 @@ declare module '../assets/material-symbols-icons.json' {
|
|||||||
height?: number;
|
height?: number;
|
||||||
};
|
};
|
||||||
export default value;
|
export default value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module 'pdfjs-dist/legacy/build/pdf.mjs'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import * as pdfjsLib from 'pdfjs-dist';
|
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.mjs';
|
||||||
import { pdfWorkerManager } from '../services/pdfWorkerManager';
|
import { pdfWorkerManager } from '../services/pdfWorkerManager';
|
||||||
|
|
||||||
export interface PdfSignatureDetectionResult {
|
export interface PdfSignatureDetectionResult {
|
||||||
@ -25,7 +25,7 @@ export const usePdfSignatureDetection = (files: File[]): PdfSignatureDetectionRe
|
|||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const arrayBuffer = await file.arrayBuffer();
|
const arrayBuffer = await file.arrayBuffer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pdf = await pdfWorkerManager.createDocument(arrayBuffer);
|
const pdf = await pdfWorkerManager.createDocument(arrayBuffer);
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ export const usePdfSignatureDetection = (files: File[]): PdfSignatureDetectionRe
|
|||||||
|
|
||||||
if (foundSignature) break;
|
if (foundSignature) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up PDF document using worker manager
|
// Clean up PDF document using worker manager
|
||||||
pdfWorkerManager.destroyDocument(pdf);
|
pdfWorkerManager.destroyDocument(pdf);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -65,4 +65,4 @@ export const usePdfSignatureDetection = (files: File[]): PdfSignatureDetectionRe
|
|||||||
hasDigitalSignatures,
|
hasDigitalSignatures,
|
||||||
isChecking
|
isChecking
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as pdfjsLib from 'pdfjs-dist';
|
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.mjs';
|
||||||
import { ProcessedFile, ProcessingState, PDFPage, ProcessingStrategy, ProcessingConfig, ProcessingMetrics } from '../types/processing';
|
import { ProcessedFile, ProcessingState, PDFPage, ProcessingStrategy, ProcessingConfig, ProcessingMetrics } from '../types/processing';
|
||||||
import { ProcessingCache } from './processingCache';
|
import { ProcessingCache } from './processingCache';
|
||||||
import { FileHasher } from '../utils/fileHash';
|
import { FileHasher } from '../utils/fileHash';
|
||||||
@ -182,7 +182,7 @@ export class EnhancedPDFProcessingService {
|
|||||||
): Promise<ProcessedFile> {
|
): Promise<ProcessedFile> {
|
||||||
const arrayBuffer = await file.arrayBuffer();
|
const arrayBuffer = await file.arrayBuffer();
|
||||||
const pdf = await pdfWorkerManager.createDocument(arrayBuffer);
|
const pdf = await pdfWorkerManager.createDocument(arrayBuffer);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const totalPages = pdf.numPages;
|
const totalPages = pdf.numPages;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Called when files are added to FileContext, before any view sees them
|
* Called when files are added to FileContext, before any view sees them
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as pdfjsLib from 'pdfjs-dist';
|
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.mjs';
|
||||||
import { generateThumbnailForFile } from '../utils/thumbnailUtils';
|
import { generateThumbnailForFile } from '../utils/thumbnailUtils';
|
||||||
import { pdfWorkerManager } from './pdfWorkerManager';
|
import { pdfWorkerManager } from './pdfWorkerManager';
|
||||||
import { FileId } from '../types/file';
|
import { FileId } from '../types/file';
|
||||||
|
@ -130,7 +130,7 @@ export class PDFExportService {
|
|||||||
newDoc.setModificationDate(new Date());
|
newDoc.setModificationDate(new Date());
|
||||||
|
|
||||||
const pdfBytes = await newDoc.save();
|
const pdfBytes = await newDoc.save();
|
||||||
return new Blob([pdfBytes], { type: 'application/pdf' });
|
return new Blob([new Uint8Array(pdfBytes)], { type: 'application/pdf' });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -176,7 +176,7 @@ export class PDFExportService {
|
|||||||
newDoc.setModificationDate(new Date());
|
newDoc.setModificationDate(new Date());
|
||||||
|
|
||||||
const pdfBytes = await newDoc.save();
|
const pdfBytes = await newDoc.save();
|
||||||
return new Blob([pdfBytes], { type: 'application/pdf' });
|
return new Blob([new Uint8Array(pdfBytes)], { type: 'application/pdf' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* PDF.js Worker Manager - Centralized worker lifecycle management
|
* PDF.js Worker Manager - Centralized worker lifecycle management
|
||||||
*
|
*
|
||||||
* Prevents infinite worker creation by managing PDF.js workers globally
|
* Prevents infinite worker creation by managing PDF.js workers globally
|
||||||
* and ensuring proper cleanup when operations complete.
|
* and ensuring proper cleanup when operations complete.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as pdfjsLib from 'pdfjs-dist';
|
import { GlobalWorkerOptions, getDocument } from 'pdfjs-dist/legacy/build/pdf.mjs';
|
||||||
const { getDocument, GlobalWorkerOptions } = pdfjsLib;
|
|
||||||
|
|
||||||
|
|
||||||
class PDFWorkerManager {
|
class PDFWorkerManager {
|
||||||
private static instance: PDFWorkerManager;
|
private static instance: PDFWorkerManager;
|
||||||
@ -31,7 +32,10 @@ class PDFWorkerManager {
|
|||||||
*/
|
*/
|
||||||
private initializeWorker(): void {
|
private initializeWorker(): void {
|
||||||
if (!this.isInitialized) {
|
if (!this.isInitialized) {
|
||||||
GlobalWorkerOptions.workerSrc = '/pdf.worker.js';
|
GlobalWorkerOptions.workerSrc = new URL(
|
||||||
|
'pdfjs-dist/legacy/build/pdf.worker.min.mjs',
|
||||||
|
import.meta.url
|
||||||
|
).toString();
|
||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,7 +90,7 @@ class PDFWorkerManager {
|
|||||||
const pdf = await loadingTask.promise;
|
const pdf = await loadingTask.promise;
|
||||||
this.activeDocuments.add(pdf);
|
this.activeDocuments.add(pdf);
|
||||||
this.workerCount++;
|
this.workerCount++;
|
||||||
|
|
||||||
return pdf;
|
return pdf;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If document creation fails, make sure to clean up the loading task
|
// If document creation fails, make sure to clean up the loading task
|
||||||
@ -125,7 +129,7 @@ class PDFWorkerManager {
|
|||||||
documentsToDestroy.forEach(pdf => {
|
documentsToDestroy.forEach(pdf => {
|
||||||
this.destroyDocument(pdf);
|
this.destroyDocument(pdf);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.activeDocuments.clear();
|
this.activeDocuments.clear();
|
||||||
this.workerCount = 0;
|
this.workerCount = 0;
|
||||||
}
|
}
|
||||||
@ -168,7 +172,7 @@ class PDFWorkerManager {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.activeDocuments.clear();
|
this.activeDocuments.clear();
|
||||||
this.workerCount = 0;
|
this.workerCount = 0;
|
||||||
}
|
}
|
||||||
@ -182,4 +186,4 @@ class PDFWorkerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Export singleton instance
|
// Export singleton instance
|
||||||
export const pdfWorkerManager = PDFWorkerManager.getInstance();
|
export const pdfWorkerManager = PDFWorkerManager.getInstance();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react-swc';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { defineConfig } from 'vitest/config'
|
import { defineConfig } from 'vitest/config'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react-swc';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
@ -37,4 +37,4 @@ export default defineConfig({
|
|||||||
'@': '/src'
|
'@': '/src'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user