@anaralabs/lector 3.14.13 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -232,6 +232,14 @@ export declare function computeBaseScale(dpr: number, zoom: number, pageWidth: n
232
232
 
233
233
  export declare function computeTargetScale(dpr: number, zoom: number): number;
234
234
 
235
+ declare type CopyOptions = false | SelectionTextOptions;
236
+
237
+ declare type CopyRegistration = {
238
+ container: HTMLElement;
239
+ options: () => CopyOptions;
240
+ read?: (options: SelectionTextOptions) => string | null | undefined;
241
+ };
242
+
235
243
  /** Reuses two rows across candidate windows and only visits the edit band. */
236
244
  export declare function createBoundedDistance(query: string, maxDistance: number): (text: string, offset: number) => number;
237
245
 
@@ -302,6 +310,13 @@ declare const DEFAULT_DARK_MODE_COLORS: Required<DarkModeColors>;
302
310
  export { DEFAULT_DARK_MODE_COLORS }
303
311
  export { DEFAULT_DARK_MODE_COLORS as DEFAULT_DARK_MODE_COLORS_alias_1 }
304
312
 
313
+ declare type Edit = {
314
+ start: number;
315
+ end: number;
316
+ sourceStart: number;
317
+ sourceEnd: number;
318
+ };
319
+
305
320
  export declare const ensureAnnotationLayerStyles: () => void;
306
321
 
307
322
  export declare const firstMemo: <T>(first: boolean, memo: unknown, initializer: () => T) => T;
@@ -319,6 +334,13 @@ export declare const getFitWidthZoom: (containerWidth: number, viewports: PageVi
319
334
 
320
335
  export declare const getMidHeightOfHighlightLine: (selection: ColoredHighlight) => number;
321
336
 
337
+ /**
338
+ * Read mounted PDF text in DOM/PDF.js order, including explicit line breaks.
339
+ * Null means the selection isn't wholly owned by this viewer or skips pages.
340
+ * Never reorder columns/RTL runs heuristically or silently omit unmounted pages.
341
+ */
342
+ export declare function getPdfSelectionText(selection: Selection | null, container: HTMLElement, options?: SelectionTextOptions): string | null;
343
+
322
344
  /**
323
345
  * Per-text-node client rects for a selection. Avoids the block-level rects
324
346
  * that `range.getClientRects()` returns for `.textLayer` / page wrappers,
@@ -411,6 +433,26 @@ export declare const mergeTextRuns: <T extends Rect>(rects: T[]) => T[];
411
433
 
412
434
  export declare const NextPage: () => void;
413
435
 
436
+ export declare interface NormalizedText {
437
+ text: string;
438
+ maps: Edit[][];
439
+ }
440
+
441
+ /** Search representation; rendering and copied/source text are never lowercased. */
442
+ export declare function normalizeSearchText(text: string, options?: TextNormalizationOptions, lineBreaks?: readonly number[]): NormalizedText;
443
+
444
+ /** Plain text for quotes/copy. Preserve case, accents, punctuation and paragraphs. */
445
+ export declare function normalizeSelectionText(text: string, options?: SelectionTextOptions): string;
446
+
447
+ /** Expand typographic ligatures without changing mathematical compatibility symbols. */
448
+ export declare function normalizeUnicode(text: string, matchDiacritics?: boolean): string;
449
+
450
+ /** Translate a normalized match back to its complete original glyph span. */
451
+ export declare function originalTextRange(normalized: NormalizedText, start: number, end: number): {
452
+ start: number;
453
+ end: number;
454
+ };
455
+
414
456
  export declare const Outline: ({ children, ...props }: HTMLProps<HTMLUListElement> & {
415
457
  children: ReactElement<typeof OutlineItem>;
416
458
  }) => JSX.Element;
@@ -472,7 +514,7 @@ export declare class PageResources {
472
514
  dispose: () => void;
473
515
  }
474
516
 
475
- export declare const Pages: ({ children, gap, virtualizerOptions, initialOffset, onOffsetChange, ...props }: HTMLProps<HTMLDivElement> & {
517
+ export declare const Pages: ({ children, gap, virtualizerOptions, initialOffset, onOffsetChange, copyOptions, ...props }: HTMLProps<HTMLDivElement> & {
476
518
  virtualizerOptions?: {
477
519
  overscan?: number;
478
520
  };
@@ -480,12 +522,19 @@ export declare const Pages: ({ children, gap, virtualizerOptions, initialOffset,
480
522
  children: ReactElement;
481
523
  initialOffset?: number;
482
524
  onOffsetChange?: (offset: number) => void;
525
+ /** Plain-text PDF copying. Preserve line breaks by default; false uses native copying. */
526
+ copyOptions?: false | SelectionTextOptions;
483
527
  }) => JSX.Element;
484
528
 
485
- declare type PageText = {
529
+ /** Text offsets always address the original, concatenated PDF.js strings. */
530
+ declare interface PageText {
486
531
  pageNumber: number;
487
532
  text: string;
488
- };
533
+ /** Sorted UTF-16 offsets after items with hasEOL, without inserting characters. */
534
+ lineBreaks?: readonly number[];
535
+ }
536
+ export { PageText }
537
+ export { PageText as PageText_alias_1 }
489
538
 
490
539
  export declare interface PdfJsAssetUrls {
491
540
  wasmUrl: string;
@@ -496,7 +545,68 @@ export declare interface PdfJsAssetUrls {
496
545
 
497
546
  export declare const PDFLinkServiceContext: Context<LinkService>;
498
547
 
548
+ /** Document-owned selection; mounted text layers are replaceable projections. */
549
+ export declare class PDFSelectionController {
550
+ private readonly options;
551
+ private snapshot;
552
+ private listeners;
553
+ private layers;
554
+ private pages;
555
+ private container;
556
+ private projection;
557
+ private frame;
558
+ private work;
559
+ private structuralChange;
560
+ private drag;
561
+ private connectedCleanup;
562
+ private generation;
563
+ private keyboardWork;
564
+ private keyboardMoves;
565
+ constructor(options: {
566
+ pageCount: number;
567
+ loadPage: (page: number) => Promise<PDFPageProxy>;
568
+ revealPage?: (page: number) => void;
569
+ });
570
+ getSnapshot: () => PDFTextSelection | null;
571
+ subscribe: (listener: () => void) => () => void;
572
+ get isDragging(): boolean;
573
+ includesPage(page: number): boolean;
574
+ private publish;
575
+ private ordered;
576
+ private bounds;
577
+ private remember;
578
+ private complete;
579
+ setSelection: (anchor: PDFTextAnchor, focus: PDFTextAnchor) => void;
580
+ clear: () => void;
581
+ getText: (options?: SelectionTextOptions) => string | null;
582
+ getSelection: (options?: SelectionTextOptions) => PDFSelectionResult | null;
583
+ getSelectionAsync: (options?: SelectionTextOptions) => Promise<PDFSelectionResult | null>;
584
+ private finishSelection;
585
+ registerLayer(element: HTMLElement, pageNumber: number, width: number, height: number): () => void;
586
+ private anchorFor;
587
+ private capture;
588
+ private schedule;
589
+ private project;
590
+ private hydrate;
591
+ private caret;
592
+ private autoScroll;
593
+ private flushKeyboard;
594
+ connect(container: HTMLElement): () => void;
595
+ }
596
+
597
+ declare interface PDFSelectionResult {
598
+ anchor: PDFTextAnchor;
599
+ focus: PDFTextAnchor;
600
+ text: string;
601
+ highlights: HighlightRect[];
602
+ underlines: HighlightRect[];
603
+ isCollapsed: false;
604
+ }
605
+ export { PDFSelectionResult }
606
+ export { PDFSelectionResult as PDFSelectionResult_alias_1 }
607
+
499
608
  declare interface PDFState {
609
+ selection: PDFSelectionController;
500
610
  pdfDocumentProxy: PDFDocumentProxy;
501
611
  zoom: number;
502
612
  updateZoom: (zoom: number | ((prevZoom: number) => number), isZoomFitWidth?: boolean) => void;
@@ -553,6 +663,23 @@ export declare const PDFStore: {
553
663
  }) => JSX.Element;
554
664
  };
555
665
 
666
+ /** One-based page and UTF-16 offset in that page's selectable text (BRs excluded). */
667
+ declare interface PDFTextAnchor {
668
+ pageNumber: number;
669
+ offset: number;
670
+ }
671
+ export { PDFTextAnchor }
672
+ export { PDFTextAnchor as PDFTextAnchor_alias_1 }
673
+
674
+ declare interface PDFTextSelection {
675
+ anchor: PDFTextAnchor;
676
+ focus: PDFTextAnchor;
677
+ status: "loading" | "ready" | "error";
678
+ error?: unknown;
679
+ }
680
+ export { PDFTextSelection }
681
+ export { PDFTextSelection as PDFTextSelection_alias_1 }
682
+
556
683
  export declare type PDFVirtualizer = Virtualizer<any, any>;
557
684
 
558
685
  export declare const PreviousPage: () => void;
@@ -576,6 +703,9 @@ declare type Rect = {
576
703
  height: number;
577
704
  };
578
705
 
706
+ /** One copy listener per owner document; no work runs during scroll or render. */
707
+ export declare function registerPdfCopy(container: HTMLElement, options: () => CopyOptions, read?: CopyRegistration["read"]): () => void;
708
+
579
709
  export declare function registerViewportZoom(viewport: HTMLDivElement, apply: ApplyZoom): () => void;
580
710
 
581
711
  /**
@@ -663,7 +793,7 @@ export declare function searchDocument(pages: SearchPage[], searchText: string,
663
793
 
664
794
  export declare function searchDocumentAsync(pages: SearchPage[], searchText: string, options?: AsyncSearchOptions): Promise<SearchResults>;
665
795
 
666
- declare interface SearchOptions {
796
+ declare interface SearchOptions extends TextNormalizationOptions {
667
797
  threshold?: number;
668
798
  limit?: number;
669
799
  textSize?: number;
@@ -671,10 +801,7 @@ declare interface SearchOptions {
671
801
  export { SearchOptions }
672
802
  export { SearchOptions as SearchOptions_alias_1 }
673
803
 
674
- declare type SearchPage = {
675
- pageNumber: number;
676
- text: string;
677
- };
804
+ declare type SearchPage = PageText;
678
805
 
679
806
  declare interface SearchProps {
680
807
  children: React.ReactNode;
@@ -703,6 +830,41 @@ export declare interface SearchResults {
703
830
  hasMoreResults: boolean;
704
831
  }
705
832
 
833
+ /** A mounted text layer. Only this object owns DOM nodes; snapshots never do. */
834
+ export declare class SelectionPage {
835
+ readonly element: HTMLElement;
836
+ readonly pageNumber: number;
837
+ readonly width: number;
838
+ readonly height: number;
839
+ readonly nodes: {
840
+ node: Text;
841
+ start: number;
842
+ end: number;
843
+ }[];
844
+ readonly content: SelectionPageText;
845
+ constructor(element: HTMLElement, pageNumber: number, width: number, height: number);
846
+ offset(node: Node, offset: number): number | null;
847
+ point(offset: number, end?: boolean): {
848
+ node: Text;
849
+ offset: number;
850
+ } | null;
851
+ rects(from: number, to: number): HighlightRect[];
852
+ }
853
+
854
+ export declare interface SelectionPageText {
855
+ text: string;
856
+ lineBreaks: number[];
857
+ }
858
+
859
+ declare interface SelectionTextOptions {
860
+ /** Preserve line and page breaks by default; space joins single line breaks. */
861
+ lineBreaks?: "preserve" | "space";
862
+ /** Join wrapped words ending in a hard hyphen. Defaults to false. */
863
+ ignoreHyphenation?: boolean;
864
+ }
865
+ export { SelectionTextOptions }
866
+ export { SelectionTextOptions as SelectionTextOptions_alias_1 }
867
+
706
868
  export declare const SelectionTooltip: ({ children }: SelectionTooltipProps) => JSX.Element;
707
869
 
708
870
  declare interface SelectionTooltipProps {
@@ -725,10 +887,7 @@ export declare function sourceSize(source: CanvasImageSource): {
725
887
 
726
888
  export declare const subscribeToViewportInvalidation: (viewport: HTMLDivElement, callback: ViewportCallback) => () => void;
727
889
 
728
- declare type TextContent = {
729
- pageNumber: number;
730
- text: string;
731
- };
890
+ declare type TextContent = PageText;
732
891
 
733
892
  export declare const TextLayer: MemoExoticComponent<({ className, style, ...props }: HTMLProps<HTMLDivElement>) => JSX.Element>;
734
893
 
@@ -737,6 +896,13 @@ declare type TextNodeRect = {
737
896
  element: Element | null;
738
897
  };
739
898
 
899
+ export declare interface TextNormalizationOptions {
900
+ /** Preserve accents by default. False folds Latin, Greek and Cyrillic accents. */
901
+ matchDiacritics?: boolean;
902
+ /** Join letter-hyphen-linebreak-lowercase sequences. Defaults to false. */
903
+ ignoreHyphenation?: boolean;
904
+ }
905
+
740
906
  declare interface TextPosition {
741
907
  pageNumber: number;
742
908
  text: string;
@@ -892,11 +1058,20 @@ declare const usePDFOutline: () => {
892
1058
 
893
1059
  export declare const usePDFPageNumber: () => number;
894
1060
 
1061
+ /** Selection anchors survive virtualized text-layer removal. */
1062
+ declare function usePdfSelection(): {
1063
+ selection: PDFTextSelection | null;
1064
+ setSelection: (anchor: PDFTextAnchor, focus: PDFTextAnchor) => void;
1065
+ clearSelection: () => void;
1066
+ getText: (options?: SelectionTextOptions) => string | null;
1067
+ getSelection: (options?: SelectionTextOptions) => PDFSelectionResult | null;
1068
+ getSelectionAsync: (options?: SelectionTextOptions) => Promise<PDFSelectionResult | null>;
1069
+ };
1070
+ export { usePdfSelection }
1071
+ export { usePdfSelection as usePdfSelection_alias_1 }
1072
+
895
1073
  export declare const useSearch: () => {
896
- textContent: {
897
- pageNumber: number;
898
- text: string;
899
- }[];
1074
+ textContent: PageText[];
900
1075
  keywords: string[];
901
1076
  searchResults: SearchResults;
902
1077
  search: (searchText: string, options?: SearchOptions) => SearchResults;
@@ -906,22 +1081,26 @@ export declare const useSearch: () => {
906
1081
  };
907
1082
 
908
1083
  export declare const useSelectionDimensions: () => {
909
- getDimension: () => {
1084
+ getDimension: () => PDFSelectionResult | {
910
1085
  highlights: HighlightRect[];
911
1086
  text: string;
912
1087
  isCollapsed: boolean;
913
1088
  } | undefined;
914
1089
  getSelection: () => CollapsibleSelection;
915
- getAnnotationDimension: () => {
1090
+ getAnnotationDimension: () => PDFSelectionResult | {
916
1091
  highlights: HighlightRect[];
917
1092
  underlines: HighlightRect[];
918
1093
  text: string;
919
1094
  isCollapsed: boolean;
920
1095
  } | undefined;
1096
+ getText: (options?: SelectionTextOptions) => string | null;
921
1097
  };
922
1098
 
923
1099
  declare type ViewportCallback = () => void;
924
1100
 
1101
+ /** Materialize one missing selected page as text only, never as a page canvas. */
1102
+ export declare function withSelectionPage<T>(proxy: PDFPageProxy, owner: Document, signal: AbortSignal, read: (page: SelectionPage) => T): Promise<T>;
1103
+
925
1104
  export declare const ZoomIn: ({ ...props }: HTMLProps<HTMLButtonElement>) => JSX.Element;
926
1105
 
927
1106
  export declare interface ZoomOptions {
package/dist/index.d.ts CHANGED
@@ -39,6 +39,7 @@ export { PDFLinkServiceContext } from './_tsup-dts-rollup.js';
39
39
  export { useCreatePDFLinkService } from './_tsup-dts-rollup.js';
40
40
  export { usePDFLinkService } from './_tsup-dts-rollup.js';
41
41
  export { usePDFPageNumber } from './_tsup-dts-rollup.js';
42
+ export { usePdfSelection } from './_tsup-dts-rollup.js';
42
43
  export { useSelectionDimensions } from './_tsup-dts-rollup.js';
43
44
  export { ColoredHighlight } from './_tsup-dts-rollup.js';
44
45
  export { HighlightRect } from './_tsup-dts-rollup.js';
@@ -48,5 +49,10 @@ export { createDarkModeColorMap } from './_tsup-dts-rollup.js';
48
49
  export { DarkModeColors } from './_tsup-dts-rollup.js';
49
50
  export { DEFAULT_DARK_MODE_COLORS } from './_tsup-dts-rollup.js';
50
51
  export { RenderColorMap } from './_tsup-dts-rollup.js';
52
+ export { PDFSelectionResult } from './_tsup-dts-rollup.js';
53
+ export { PDFTextAnchor } from './_tsup-dts-rollup.js';
54
+ export { PDFTextSelection } from './_tsup-dts-rollup.js';
51
55
  export { AsyncSearchOptions } from './_tsup-dts-rollup.js';
52
56
  export { SearchOptions } from './_tsup-dts-rollup.js';
57
+ export { PageText } from './_tsup-dts-rollup.js';
58
+ export { SelectionTextOptions } from './_tsup-dts-rollup.js';