react-pdf-highlighter-plus 1.1.4 → 1.3.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.
@@ -459,6 +459,16 @@ type PdfHighlighterUtils = {
459
459
  * Clear active search highlights.
460
460
  */
461
461
  clearSearch(): void;
462
+ /**
463
+ * Marks a highlight as selected/deselected (its floating toolbar is open).
464
+ * Counter-backed, so overlapping select/deselect from different highlights
465
+ * resolves correctly. Used to suppress hover tips while a toolbar is shown.
466
+ */
467
+ setHighlightSelected(selected: boolean): void;
468
+ /**
469
+ * Whether any highlight is currently selected (toolbar showing).
470
+ */
471
+ isHighlightSelected(): boolean;
462
472
  };
463
473
  /**
464
474
  * Custom hook for providing {@link PdfHighlighterUtils}. Must be used
@@ -476,8 +486,8 @@ declare const usePdfHighlighterContext: () => PdfHighlighterUtils;
476
486
  */
477
487
  interface PdfHighlighterTheme {
478
488
  /**
479
- * Theme mode - controls PDF page color inversion.
480
- * In dark mode, PDF pages are inverted for comfortable reading.
489
+ * Theme mode. In dark mode, pages are recolored at draw time (hue-preserving,
490
+ * photos kept) using {@link PdfHighlighterTheme.darkModeColors}.
481
491
  * @default "light"
482
492
  */
483
493
  mode?: "light" | "dark";
@@ -504,8 +514,24 @@ interface PdfHighlighterTheme {
504
514
  * - 0.85 = Softer gray ~#262626 (very comfortable)
505
515
  * - 0.8 = Medium gray ~#333333 (maximum softness)
506
516
  * @default 0.9
517
+ * @deprecated Dark mode now recolors at draw time (OKLab, hue-preserving,
518
+ * photos untouched) instead of a CSS `invert()` filter. This value is
519
+ * ignored. Use {@link PdfHighlighterTheme.darkModeColors} instead.
507
520
  */
508
521
  darkModeInvertIntensity?: number;
522
+ /**
523
+ * Dark-mode recolor palette. White paper maps to `background` and black
524
+ * text/line-art to `foreground`, recolored per-color at draw time (OKLab
525
+ * ramp) so hues are preserved and embedded photos keep their pixels.
526
+ * Only used when `mode === "dark"`.
527
+ * @default { background: "#141210", foreground: "#eae6e0" }
528
+ */
529
+ darkModeColors?: {
530
+ /** Replaces the white paper background. */
531
+ background: string;
532
+ /** Replaces black text and line art. */
533
+ foreground: string;
534
+ };
509
535
  }
510
536
  /**
511
537
  * The props type for {@link PdfHighlighter}.
@@ -527,6 +553,27 @@ interface PdfHighlighterProps {
527
553
  * What scale to render the PDF at inside the viewer.
528
554
  */
529
555
  pdfScaleValue?: PdfScaleValue;
556
+ /**
557
+ * Fired when the user changes zoom by pinch / ctrl+wheel gesture, with the new
558
+ * numeric scale. Use it to keep an external zoom indicator / `pdfScaleValue`
559
+ * state in sync.
560
+ *
561
+ * @param scale - The new numeric scale (e.g. 1.25).
562
+ */
563
+ onZoomChange?(scale: number): void;
564
+ /**
565
+ * Page to scroll to once the document first finishes loading (1-indexed).
566
+ * Use for deep-linking (e.g. `?page=12`) or restoring a saved position.
567
+ * Applied only on initial load, not on subsequent re-renders.
568
+ */
569
+ initialPage?: number;
570
+ /**
571
+ * Callback fired whenever the current (most visible) page changes, including
572
+ * the initial page. Use to sync the page into a URL/localStorage.
573
+ *
574
+ * @param pageNumber - The new current page (1-indexed).
575
+ */
576
+ onPageChange?(pageNumber: number): void;
530
577
  /**
531
578
  * Callback triggered whenever a user finishes making a mouse selection or has
532
579
  * selected text.
@@ -690,7 +737,7 @@ interface PdfHighlighterProps {
690
737
  *
691
738
  * @category Component
692
739
  */
693
- declare const PdfHighlighter: ({ highlights, onScrollAway, pdfScaleValue, onSelection: onSelectionFinished, onCreateGhostHighlight, onRemoveGhostHighlight, selectionTip, enableAreaSelection, areaSelectionMode, mouseSelectionStyle, pdfDocument, children, textSelectionColor, utilsRef, style, enableFreetextCreation, onFreetextClick, enableImageCreation, onImageClick, enableDrawingMode, onDrawingComplete, onDrawingCancel, drawingStrokeColor, drawingStrokeWidth, enableShapeMode, onShapeComplete, onShapeCancel, shapeStrokeColor, shapeStrokeWidth, theme: userTheme, }: PdfHighlighterProps) => React.JSX.Element;
740
+ declare const PdfHighlighter: ({ highlights, onScrollAway, pdfScaleValue, onZoomChange, initialPage, onPageChange, onSelection: onSelectionFinished, onCreateGhostHighlight, onRemoveGhostHighlight, selectionTip, enableAreaSelection, areaSelectionMode, mouseSelectionStyle, pdfDocument, children, textSelectionColor, utilsRef, style, enableFreetextCreation, onFreetextClick, enableImageCreation, onImageClick, enableDrawingMode, onDrawingComplete, onDrawingCancel, drawingStrokeColor: drawingStrokeColorProp, drawingStrokeWidth, enableShapeMode, onShapeComplete, onShapeCancel, shapeStrokeColor: shapeStrokeColorProp, shapeStrokeWidth, theme: userTheme, }: PdfHighlighterProps) => React.JSX.Element;
694
741
 
695
742
  /**
696
743
  * Style options for text highlight appearance.
@@ -779,13 +826,25 @@ interface TextHighlightProps {
779
826
  * Default: ["rgba(255, 226, 143, 1)", "#ffcdd2", "#c8e6c9", "#bbdefb", "#e1bee7"]
780
827
  */
781
828
  colorPresets?: string[];
829
+ /**
830
+ * Extra buttons rendered in the same toolbar row, after the copy button.
831
+ * Use this to add consumer-defined actions (e.g. a comment toggle) without
832
+ * needing a second, separate popup.
833
+ */
834
+ extraButtons?: ReactNode;
835
+ /**
836
+ * Extra content rendered below the toolbar row, in the same slot as the
837
+ * built-in style panel (e.g. a comment editor opened by an extraButtons
838
+ * toggle).
839
+ */
840
+ extraPanel?: ReactNode;
782
841
  }
783
842
  /**
784
843
  * A component for displaying a highlighted text area.
785
844
  *
786
845
  * @category Component
787
846
  */
788
- declare const TextHighlight: ({ highlight, onClick, onMouseOver, onMouseOut, isScrolledTo, onContextMenu, style, highlightColor, highlightStyle, onStyleChange, onDelete, styleIcon, deleteIcon, copyText, colorPresets, }: TextHighlightProps) => React.JSX.Element;
847
+ declare const TextHighlight: React.MemoExoticComponent<({ highlight, onClick, onMouseOver, onMouseOut, isScrolledTo, onContextMenu, style, highlightColor, highlightStyle, onStyleChange, onDelete, styleIcon, deleteIcon, copyText, colorPresets, extraButtons, extraPanel, }: TextHighlightProps) => React.JSX.Element>;
789
848
 
790
849
  /**
791
850
  * The props type for {@link MonitoredHighlightContainer}.
@@ -886,10 +945,6 @@ interface AreaHighlightProps {
886
945
  * Callback triggered when the delete button is clicked.
887
946
  */
888
947
  onDelete?(): void;
889
- /**
890
- * Custom style icon. Replaces the default palette icon.
891
- */
892
- styleIcon?: ReactNode;
893
948
  /**
894
949
  * Custom delete icon. Replaces the default trash icon.
895
950
  */
@@ -899,13 +954,25 @@ interface AreaHighlightProps {
899
954
  * Default: ["rgba(255, 226, 143, 1)", "#ffcdd2", "#c8e6c9", "#bbdefb", "#e1bee7"]
900
955
  */
901
956
  colorPresets?: string[];
957
+ /**
958
+ * Extra buttons rendered in the same toolbar row, after the copy button.
959
+ * Use this to add consumer-defined actions (e.g. a comment toggle) without
960
+ * needing a second, separate popup.
961
+ */
962
+ extraButtons?: ReactNode;
963
+ /**
964
+ * Extra content rendered below the toolbar row, in the same slot as the
965
+ * built-in style panel (e.g. a comment editor opened by an extraButtons
966
+ * toggle).
967
+ */
968
+ extraPanel?: ReactNode;
902
969
  }
903
970
  /**
904
971
  * Renders a resizeable and interactive rectangular area for a highlight.
905
972
  *
906
973
  * @category Component
907
974
  */
908
- declare const AreaHighlight: ({ highlight, onChange, isScrolledTo, bounds, onContextMenu, onEditStart, style, highlightColor, onStyleChange, onDelete, styleIcon, deleteIcon, copyText, colorPresets, }: AreaHighlightProps) => React.JSX.Element;
975
+ declare const AreaHighlight: React.MemoExoticComponent<({ highlight, onChange, isScrolledTo, bounds, onContextMenu, onEditStart, style, highlightColor, onStyleChange, onDelete, deleteIcon, copyText, colorPresets, extraButtons, extraPanel, }: AreaHighlightProps) => React.JSX.Element>;
909
976
 
910
977
  /**
911
978
  * Style options for freetext highlight appearance.
@@ -1082,13 +1149,20 @@ interface ImageHighlightProps {
1082
1149
  * Custom delete icon. Replaces the default trash icon.
1083
1150
  */
1084
1151
  deleteIcon?: ReactNode;
1152
+ /**
1153
+ * Callback triggered when the image is rotated 90°. Receives the
1154
+ * re-rendered PNG data URL (rotated, dimensions swapped to match).
1155
+ * Pair with `onChange` to persist the swapped bounding rect this
1156
+ * component already computes and passes to it.
1157
+ */
1158
+ onImageChange?(newImage: string): void;
1085
1159
  }
1086
1160
  /**
1087
1161
  * Renders a draggable, resizable image/signature annotation.
1088
1162
  *
1089
1163
  * @category Component
1090
1164
  */
1091
- declare const ImageHighlight: ({ highlight, onChange, isScrolledTo, bounds, onContextMenu, onEditStart, onEditEnd, style, dragIcon, onDelete, deleteIcon, }: ImageHighlightProps) => React.JSX.Element;
1165
+ declare const ImageHighlight: ({ highlight, onChange, isScrolledTo, bounds, onContextMenu, onEditStart, onEditEnd, style, dragIcon, onDelete, deleteIcon, onImageChange, }: ImageHighlightProps) => React.JSX.Element;
1092
1166
 
1093
1167
  /**
1094
1168
  * The props type for {@link SignaturePad}.
@@ -1408,12 +1482,13 @@ interface PdfLoaderProps {
1408
1482
  */
1409
1483
  document: string | URL | TypedArray | DocumentInitParameters;
1410
1484
  /**
1411
- * Callback to render content before the PDF document is loaded.
1485
+ * Callback to render content before the PDF document is loaded. Receives the
1486
+ * PDF.js progress, or `null` before any progress is known (e.g. a cache hit).
1412
1487
  *
1413
- * @param progress - PDF.js progress status.
1488
+ * @param progress - PDF.js progress status, or null.
1414
1489
  * @returns - Component to be rendered in space of the PDF document while loading.
1415
1490
  */
1416
- beforeLoad?(progress: OnProgressParameters): ReactNode;
1491
+ beforeLoad?(progress: OnProgressParameters | null): ReactNode;
1417
1492
  /**
1418
1493
  * Component to render in the case of any PDF loading errors.
1419
1494
  *
@@ -1440,13 +1515,36 @@ interface PdfLoaderProps {
1440
1515
  * worker from the installed pdfjs-dist package so bundlers can emit it locally.
1441
1516
  */
1442
1517
  workerSrc?: string;
1518
+ /**
1519
+ * Only fetch the pages needed to render, instead of background-downloading the
1520
+ * whole file. Makes the first page appear fast for large PDFs served over an
1521
+ * API — provided the server supports HTTP range requests (`Accept-Ranges:
1522
+ * bytes`). Has no effect for servers without range support or for raw bytes.
1523
+ * @default true
1524
+ */
1525
+ disableAutoFetch?: boolean;
1526
+ /** Disable progressive streaming of the response. @default false */
1527
+ disableStream?: boolean;
1528
+ /** Size (bytes) of each range request when streaming. PDF.js default ~64KB. */
1529
+ rangeChunkSize?: number;
1530
+ /** Send credentials (cookies) with the document request. */
1531
+ withCredentials?: boolean;
1532
+ /** Extra HTTP headers for the document request (e.g. an auth token). */
1533
+ httpHeaders?: Record<string, string>;
1534
+ /**
1535
+ * Cache the loaded document so re-opening the same URL (or a StrictMode/
1536
+ * remount) reuses it instead of re-downloading. Only URL-based documents are
1537
+ * cached. Disable if the same URL can return different content.
1538
+ * @default true
1539
+ */
1540
+ enableCache?: boolean;
1443
1541
  }
1444
1542
  /**
1445
1543
  * A component for loading a PDF document and passing it to a child.
1446
1544
  *
1447
1545
  * @category Component
1448
1546
  */
1449
- declare const PdfLoader: ({ document, beforeLoad, errorMessage, children, onError, workerSrc, }: PdfLoaderProps) => React.ReactNode;
1547
+ declare const PdfLoader: ({ document, beforeLoad, errorMessage, children, onError, workerSrc, disableAutoFetch, disableStream, rangeChunkSize, withCredentials, httpHeaders, enableCache, }: PdfLoaderProps) => React.ReactNode;
1450
1548
 
1451
1549
  /**
1452
1550
  * A set of utilities for rendering highlights. Designed to be used within a
@@ -1517,7 +1615,7 @@ type PdfExtractedPage = {
1517
1615
  textItems: PdfTextItem[];
1518
1616
  columns?: PdfTextColumn[];
1519
1617
  };
1520
- type PdfTextUnitType = "paragraph" | "title" | "heading" | "author" | "affiliation" | "footnote" | "reference" | "unknown";
1618
+ type PdfTextUnitType = "paragraph" | "title" | "heading" | "author" | "affiliation" | "footnote" | "reference" | "caption" | "figureLabel" | "unknown";
1521
1619
  type PdfTextUnit = {
1522
1620
  id: string;
1523
1621
  type: PdfTextUnitType;
@@ -1566,6 +1664,37 @@ declare const extractSentences: (pdfDocument: PDFDocumentProxy, options?: Extrac
1566
1664
  declare const sentenceToHighlight: (sentence: PdfSentence, options?: {
1567
1665
  id?: string;
1568
1666
  }) => Highlight;
1667
+ /**
1668
+ * The result of {@link getTextPosition}.
1669
+ *
1670
+ * @category Type
1671
+ */
1672
+ interface TextPositionMatch {
1673
+ /** Scaled position of the matched text, ready to use as a highlight position. */
1674
+ position: ScaledPosition;
1675
+ /** 1-indexed page the match was found on. */
1676
+ pageNumber: number;
1677
+ /** The exact document text that was matched. */
1678
+ matchedText: string;
1679
+ /** "exact" = whitespace-insensitive verbatim, "fuzzy" = approximate match. */
1680
+ confidence: "exact" | "fuzzy";
1681
+ }
1682
+ /**
1683
+ * Locate a piece of text in the PDF and return its precise position — the rects
1684
+ * of the exact phrase (sub-item, per-line), not a whole sentence. Use it to turn
1685
+ * an external quote / citation into a highlight you can render or scroll to.
1686
+ *
1687
+ * Robust to PDF quirks: matching ignores whitespace (so line-wraps and spacing
1688
+ * differences don't matter) and falls back to bounded fuzzy matching for minor
1689
+ * differences (hyphenation, OCR, slight paraphrase). Returns the first match
1690
+ * (optionally restrict the page range), or null.
1691
+ *
1692
+ * @category Utility
1693
+ */
1694
+ declare const getTextPosition: (pdfDocument: PDFDocumentProxy, query: string, options?: {
1695
+ pages?: "all" | number[];
1696
+ fuzzy?: boolean;
1697
+ }) => Promise<TextPositionMatch | null>;
1569
1698
 
1570
1699
  /** Style configuration for outline items */
1571
1700
  interface OutlineItemStyles {
@@ -1846,7 +1975,10 @@ interface LeftPanelProps {
1846
1975
  thumbnailWidth?: number;
1847
1976
  /** Children for custom content */
1848
1977
  children?: React.ReactNode;
1849
- /** Theme customization */
1978
+ /** Color scheme. "dark" swaps in a dark default palette; `theme` overrides
1979
+ * individual colors on top of whichever preset is chosen. @default "light" */
1980
+ mode?: "light" | "dark";
1981
+ /** Theme customization (merged over the mode preset) */
1850
1982
  theme?: LeftPanelTheme;
1851
1983
  /** Show page count in footer */
1852
1984
  showFooter?: boolean;
@@ -2030,4 +2162,4 @@ declare function usePageNavigation(options: UsePageNavigationOptions): UsePageNa
2030
2162
 
2031
2163
  declare const exportPdf: typeof exportPdf$1;
2032
2164
 
2033
- export { AreaHighlight, type AreaHighlightProps, type AreaHighlightStyle, type Content, DocumentOutline, type DocumentOutlineClassNames, type DocumentOutlineProps, type DocumentOutlineStyles, DrawingCanvas, type DrawingCanvasProps, DrawingHighlight, type DrawingHighlightProps, type DrawingPoint, type DrawingStroke, type ExportPdfOptions, type ExportableHighlight, type ExtractSentencesOptions, type FooterClassNames, type FooterStyles, FreetextHighlight, type FreetextHighlightProps, type FreetextStyle, type GhostHighlight, type Highlight, type HighlightBindings, type HighlightContainerUtils, type HighlightType, ImageHighlight, type ImageHighlightProps, type LTWH, type LTWHP, LeftPanel, type LeftPanelProps, type LeftPanelTab, type LeftPanelTheme, type LeftPanelUtils, MonitoredHighlightContainer, type MonitoredHighlightContainerProps, OutlineItem, type OutlineItemClassNames, type OutlineItemProps, type OutlineItemRenderProps, type OutlineItemStyles, type Page, type PdfColumnDetection, type PdfExtractedPage, PdfHighlighter, type PdfHighlighterProps, type PdfHighlighterTheme, type PdfHighlighterUtils, PdfLoader, type PdfLoaderProps, type PdfReadingOrder, type PdfScaleValue, type PdfSearchOptions, type PdfSelection, type PdfSentence, type PdfSentenceSource, type PdfTextColumn, type PdfTextItem, type PdfTextUnit, type PdfTextUnitType, type ProcessedOutlineItem, type Scaled, type ScaledPosition, ShapeCanvas, type ShapeCanvasProps, type ShapeData, ShapeHighlight, type ShapeHighlightProps, type ShapeStyle, type ShapeType, SignaturePad, type SignaturePadProps, type TabClassNames, type TabStyles, TextHighlight, type TextHighlightProps, type TextHighlightStyle, type ThumbnailData, ThumbnailItem, type ThumbnailItemProps, ThumbnailPanel, type ThumbnailPanelProps, type Tip, type ToggleButtonClassNames, type ToggleButtonStyles, type ViewportHighlight, type ViewportPosition, exportPdf, extractPageTextItems, extractSentences, extractTextUnits, scaledPositionToViewport, sentenceToHighlight, useDocumentOutline, useHighlightContainerContext, useLeftPanelContext, usePageNavigation, usePdfHighlighterContext, useThumbnails, viewportPositionToScaled };
2165
+ export { AreaHighlight, type AreaHighlightProps, type AreaHighlightStyle, type Content, DocumentOutline, type DocumentOutlineClassNames, type DocumentOutlineProps, type DocumentOutlineStyles, DrawingCanvas, type DrawingCanvasProps, DrawingHighlight, type DrawingHighlightProps, type DrawingPoint, type DrawingStroke, type ExportPdfOptions, type ExportableHighlight, type ExtractSentencesOptions, type FooterClassNames, type FooterStyles, FreetextHighlight, type FreetextHighlightProps, type FreetextStyle, type GhostHighlight, type Highlight, type HighlightBindings, type HighlightContainerUtils, type HighlightType, ImageHighlight, type ImageHighlightProps, type LTWH, type LTWHP, LeftPanel, type LeftPanelProps, type LeftPanelTab, type LeftPanelTheme, type LeftPanelUtils, MonitoredHighlightContainer, type MonitoredHighlightContainerProps, OutlineItem, type OutlineItemClassNames, type OutlineItemProps, type OutlineItemRenderProps, type OutlineItemStyles, type Page, type PdfColumnDetection, type PdfExtractedPage, PdfHighlighter, type PdfHighlighterProps, type PdfHighlighterTheme, type PdfHighlighterUtils, PdfLoader, type PdfLoaderProps, type PdfReadingOrder, type PdfScaleValue, type PdfSearchOptions, type PdfSelection, type PdfSentence, type PdfSentenceSource, type PdfTextColumn, type PdfTextItem, type PdfTextUnit, type PdfTextUnitType, type ProcessedOutlineItem, type Scaled, type ScaledPosition, ShapeCanvas, type ShapeCanvasProps, type ShapeData, ShapeHighlight, type ShapeHighlightProps, type ShapeStyle, type ShapeType, SignaturePad, type SignaturePadProps, type TabClassNames, type TabStyles, TextHighlight, type TextHighlightProps, type TextHighlightStyle, type TextPositionMatch, type ThumbnailData, ThumbnailItem, type ThumbnailItemProps, ThumbnailPanel, type ThumbnailPanelProps, type Tip, type ToggleButtonClassNames, type ToggleButtonStyles, type ViewportHighlight, type ViewportPosition, exportPdf, extractPageTextItems, extractSentences, extractTextUnits, getTextPosition, scaledPositionToViewport, sentenceToHighlight, useDocumentOutline, useHighlightContainerContext, useLeftPanelContext, usePageNavigation, usePdfHighlighterContext, useThumbnails, viewportPositionToScaled };