mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-08 08:52:28 +01:00
feat: enhance PDF comparison with new change types and zoom functionality
- Added support for 'moved' and 'style-changed' change types in PDF comparison. - Implemented category filters for changes, allowing users to filter by text, images, headers, annotations, formatting, and background. - Introduced zoom functionality with buttons for zooming in, out, and resetting to default. - Updated UI to reflect new change types and categories, including visual indicators for moved and style-changed items. - Enhanced summary display to include counts for moved and style-changed changes. - Refactored rendering logic to accommodate zoom levels and improve performance. - Added tests for new change detection features and category assignments.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { diffTextRuns } from './diff-text-runs.ts';
|
||||
import { pairPages } from './pair-pages.ts';
|
||||
import type {
|
||||
CompareTextItem,
|
||||
ComparePageSignature,
|
||||
ComparePagePair,
|
||||
ComparePageResult,
|
||||
CompareChangeSummary,
|
||||
CompareTextChange,
|
||||
} from '../types.ts';
|
||||
|
||||
interface DiffMessage {
|
||||
type: 'diff';
|
||||
id: number;
|
||||
beforeItems: CompareTextItem[];
|
||||
afterItems: CompareTextItem[];
|
||||
}
|
||||
|
||||
interface PairMessage {
|
||||
type: 'pair';
|
||||
id: number;
|
||||
leftPages: ComparePageSignature[];
|
||||
rightPages: ComparePageSignature[];
|
||||
}
|
||||
|
||||
type WorkerMessage = DiffMessage | PairMessage;
|
||||
|
||||
interface DiffResult {
|
||||
type: 'diff';
|
||||
id: number;
|
||||
changes: CompareTextChange[];
|
||||
summary: CompareChangeSummary;
|
||||
}
|
||||
|
||||
interface PairResult {
|
||||
type: 'pair';
|
||||
id: number;
|
||||
pairs: ComparePagePair[];
|
||||
}
|
||||
|
||||
interface ErrorResult {
|
||||
type: 'error';
|
||||
id: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
type WorkerResult = DiffResult | PairResult | ErrorResult;
|
||||
|
||||
self.onmessage = function (e: MessageEvent<WorkerMessage>) {
|
||||
const msg = e.data;
|
||||
try {
|
||||
if (msg.type === 'diff') {
|
||||
const { changes, summary } = diffTextRuns(
|
||||
msg.beforeItems,
|
||||
msg.afterItems
|
||||
);
|
||||
const result: DiffResult = {
|
||||
type: 'diff',
|
||||
id: msg.id,
|
||||
changes,
|
||||
summary,
|
||||
};
|
||||
self.postMessage(result);
|
||||
} else if (msg.type === 'pair') {
|
||||
const pairs = pairPages(msg.leftPages, msg.rightPages);
|
||||
const result: PairResult = { type: 'pair', id: msg.id, pairs };
|
||||
self.postMessage(result);
|
||||
}
|
||||
} catch (err) {
|
||||
const result: ErrorResult = {
|
||||
type: 'error',
|
||||
id: msg.id,
|
||||
message: err instanceof Error ? err.message : String(err),
|
||||
};
|
||||
self.postMessage(result);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user