- Removed deprecated functions related to document parsing and blob storage in blobstore.ts. - Introduced new PDF rendering logic in pdf-preview-renderer.ts and pdf-preview-pdfjs-runtime.ts. - Updated previews-render.ts to utilize the new PDF rendering functions. - Refactored user-whisper-align-job.ts to use the compute-worker client for alignment requests. - Enhanced artifact.ts and operation.ts to validate parsed PDF artifacts and resolve current PDF parses. - Updated snapshot.ts to align with new worker operation types. - Adjusted runtime-config.ts to check for compute-worker availability. - Modified types in parsed-pdf.ts and tts.ts to reflect changes in the compute-worker protocol. - Added unit tests for PDF artifact validation and compute-worker client contract. - Removed obsolete pdf-op-key.vitest.spec.ts test file.
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
||
import { mergeTextWithRegions } from '../../../src/compute';
|
||
|
||
describe('mergeTextWithRegions', () => {
|
||
test('assigns text items to containing regions by centroid and joins in reading order', () => {
|
||
const regions = [
|
||
{ bbox: [0, 0, 100, 50] as [number, number, number, number], label: 'text' as const },
|
||
{ bbox: [0, 50, 100, 100] as [number, number, number, number], label: 'figure_title' as const },
|
||
];
|
||
|
||
const textItems = [
|
||
{ text: 'world', x: 40, y: 20, width: 20, height: 8 },
|
||
{ text: 'hello', x: 10, y: 20, width: 20, height: 8 },
|
||
{ text: 'Figure', x: 10, y: 70, width: 24, height: 8 },
|
||
{ text: '1.2', x: 40, y: 70, width: 10, height: 8 },
|
||
];
|
||
|
||
const merged = mergeTextWithRegions(regions, textItems);
|
||
expect(merged).toHaveLength(2);
|
||
expect(merged[0].text).toBe('hello world');
|
||
expect(merged[1].text).toBe('Figure 1.2');
|
||
});
|
||
|
||
test('drops text whose centroid is outside every region', () => {
|
||
const regions = [
|
||
{ bbox: [0, 0, 50, 50] as [number, number, number, number], label: 'text' as const },
|
||
];
|
||
const textItems = [
|
||
{ text: 'inside', x: 10, y: 10, width: 10, height: 8 },
|
||
{ text: 'outside', x: 80, y: 80, width: 12, height: 8 },
|
||
];
|
||
|
||
const merged = mergeTextWithRegions(regions, textItems);
|
||
expect(merged).toHaveLength(1);
|
||
expect(merged[0].text).toBe('inside');
|
||
});
|
||
|
||
test('keeps decorative drop caps attached to the same line when boxes overlap vertically', () => {
|
||
const regions = [
|
||
{ bbox: [0, 0, 200, 120] as [number, number, number, number], label: 'text' as const },
|
||
];
|
||
|
||
const textItems = [
|
||
{ text: 'I', x: 0, y: 10, width: 12, height: 60 },
|
||
{ text: 't’s funny,', x: 12, y: 40, width: 50, height: 12 },
|
||
];
|
||
|
||
const merged = mergeTextWithRegions(regions, textItems);
|
||
expect(merged).toHaveLength(1);
|
||
expect(merged[0].text).toBe('It’s funny,');
|
||
});
|
||
});
|