react-pdf-highlighter-plus 1.1.2 → 1.1.4

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.
@@ -1,6 +1,6 @@
1
- import { PDFDocumentProxy, OnProgressParameters } from 'pdfjs-dist';
2
1
  import React, { ReactNode, CSSProperties, MouseEvent as MouseEvent$1 } from 'react';
3
2
  import { Root } from 'react-dom/client';
3
+ import { PDFDocumentProxy, OnProgressParameters } from 'pdfjs-dist';
4
4
  import { PDFViewer as PDFViewer$2 } from 'pdfjs-dist/types/web/pdf_viewer';
5
5
  import { PDFViewer as PDFViewer$3 } from 'pdfjs-dist/web/pdf_viewer.mjs';
6
6
  import { TypedArray, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
@@ -249,6 +249,102 @@ interface ThumbnailData {
249
249
  */
250
250
  type LeftPanelTab = 'outline' | 'thumbnails';
251
251
 
252
+ /**
253
+ * Options for the PDF export function.
254
+ *
255
+ * @category Type
256
+ */
257
+ interface ExportPdfOptions {
258
+ /** Default color for text highlights. Default: "rgba(255, 226, 143, 0.5)" */
259
+ textHighlightColor?: string;
260
+ /** Default color for area highlights. Default: "rgba(255, 226, 143, 0.5)" */
261
+ areaHighlightColor?: string;
262
+ /** Default text color for freetext. Default: "#333333" */
263
+ defaultFreetextColor?: string;
264
+ /** Default background for freetext. Default: "#ffffc8" */
265
+ defaultFreetextBgColor?: string;
266
+ /** Default font size for freetext. Default: 14 */
267
+ defaultFreetextFontSize?: number;
268
+ /** Progress callback for large PDFs */
269
+ onProgress?: (current: number, total: number) => void;
270
+ }
271
+ /**
272
+ * A highlight that can be exported to PDF.
273
+ *
274
+ * @category Type
275
+ */
276
+ interface ExportableHighlight {
277
+ id: string;
278
+ type?: "text" | "area" | "freetext" | "image" | "drawing" | "shape";
279
+ content?: {
280
+ text?: string;
281
+ image?: string;
282
+ shape?: ShapeData;
283
+ };
284
+ position: ScaledPosition;
285
+ /** Per-highlight color override (for text/area highlights) */
286
+ highlightColor?: string;
287
+ /** Style mode for text highlights: "highlight" (default), "underline", or "strikethrough" */
288
+ highlightStyle?: "highlight" | "underline" | "strikethrough";
289
+ /** Text color for freetext highlights */
290
+ color?: string;
291
+ /** Background color for freetext highlights */
292
+ backgroundColor?: string;
293
+ /** Font size for freetext highlights */
294
+ fontSize?: string;
295
+ /** Font family for freetext highlights (not used in export, Helvetica is always used) */
296
+ fontFamily?: string;
297
+ /** Shape type for shape highlights */
298
+ shapeType?: "rectangle" | "circle" | "arrow";
299
+ /** Stroke color for shape highlights */
300
+ strokeColor?: string;
301
+ /** Stroke width for shape highlights */
302
+ strokeWidth?: number;
303
+ }
304
+ /**
305
+ * Export a PDF with annotations embedded.
306
+ *
307
+ * @param pdfSource - The source PDF as a URL string, Uint8Array, or ArrayBuffer
308
+ * @param highlights - Array of highlights to embed in the PDF
309
+ * @param options - Export options for customizing colors and behavior
310
+ * @returns Promise<Uint8Array> - The modified PDF as bytes
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * const pdfBytes = await exportPdf(pdfUrl, highlights, {
315
+ * textHighlightColor: "rgba(255, 255, 0, 0.4)",
316
+ * onProgress: (current, total) => console.log(`${current}/${total} pages`)
317
+ * });
318
+ *
319
+ * // Download the file
320
+ * const blob = new Blob([pdfBytes], { type: "application/pdf" });
321
+ * const url = URL.createObjectURL(blob);
322
+ * const a = document.createElement("a");
323
+ * a.href = url;
324
+ * a.download = "annotated.pdf";
325
+ * a.click();
326
+ * URL.revokeObjectURL(url);
327
+ * ```
328
+ *
329
+ * @category Function
330
+ */
331
+ declare function exportPdf$1(pdfSource: string | Uint8Array | ArrayBuffer, highlights: ExportableHighlight[], options?: ExportPdfOptions): Promise<Uint8Array>;
332
+
333
+ /**
334
+ * Options for searching text in the PDF document.
335
+ *
336
+ * @category Type
337
+ */
338
+ type PdfSearchOptions = {
339
+ /** If true, search is case-sensitive. */
340
+ caseSensitive?: boolean;
341
+ /** If true, only whole-word matches are returned. */
342
+ entireWord?: boolean;
343
+ /** If true, all matches are highlighted, not just the selected match. */
344
+ highlightAll?: boolean;
345
+ /** If true, diacritics must match exactly. */
346
+ matchDiacritics?: boolean;
347
+ };
252
348
  /**
253
349
  * A set of utilities for to control the behaviour of {@link PdfHighlighter}.
254
350
  *
@@ -344,6 +440,25 @@ type PdfHighlighterUtils = {
344
440
  * @param pageNumber - 1-indexed page number to navigate to.
345
441
  */
346
442
  goToPage(pageNumber: number): void;
443
+ /**
444
+ * Search for text in the PDF document.
445
+ *
446
+ * @param query - Search text.
447
+ * @param options - Search options.
448
+ */
449
+ search(query: string, options?: PdfSearchOptions): void;
450
+ /**
451
+ * Move to the next search result.
452
+ */
453
+ findNext(): void;
454
+ /**
455
+ * Move to the previous search result.
456
+ */
457
+ findPrevious(): void;
458
+ /**
459
+ * Clear active search highlights.
460
+ */
461
+ clearSearch(): void;
347
462
  };
348
463
  /**
349
464
  * Custom hook for providing {@link PdfHighlighterUtils}. Must be used
@@ -643,6 +758,10 @@ interface TextHighlightProps {
643
758
  * Callback triggered when the style changes.
644
759
  */
645
760
  onStyleChange?(style: TextHighlightStyle): void;
761
+ /**
762
+ * Text to copy for this highlight.
763
+ */
764
+ copyText?: string;
646
765
  /**
647
766
  * Callback triggered when the delete button is clicked.
648
767
  */
@@ -666,7 +785,7 @@ interface TextHighlightProps {
666
785
  *
667
786
  * @category Component
668
787
  */
669
- declare const TextHighlight: ({ highlight, onClick, onMouseOver, onMouseOut, isScrolledTo, onContextMenu, style, highlightColor, highlightStyle, onStyleChange, onDelete, styleIcon, deleteIcon, colorPresets, }: TextHighlightProps) => React.JSX.Element;
788
+ declare const TextHighlight: ({ highlight, onClick, onMouseOver, onMouseOut, isScrolledTo, onContextMenu, style, highlightColor, highlightStyle, onStyleChange, onDelete, styleIcon, deleteIcon, copyText, colorPresets, }: TextHighlightProps) => React.JSX.Element;
670
789
 
671
790
  /**
672
791
  * The props type for {@link MonitoredHighlightContainer}.
@@ -759,6 +878,10 @@ interface AreaHighlightProps {
759
878
  * Callback triggered when the style changes.
760
879
  */
761
880
  onStyleChange?(style: AreaHighlightStyle): void;
881
+ /**
882
+ * Text to copy for this area highlight.
883
+ */
884
+ copyText?: string;
762
885
  /**
763
886
  * Callback triggered when the delete button is clicked.
764
887
  */
@@ -782,7 +905,7 @@ interface AreaHighlightProps {
782
905
  *
783
906
  * @category Component
784
907
  */
785
- declare const AreaHighlight: ({ highlight, onChange, isScrolledTo, bounds, onContextMenu, onEditStart, style, highlightColor, onStyleChange, onDelete, styleIcon, deleteIcon, colorPresets, }: AreaHighlightProps) => React.JSX.Element;
908
+ declare const AreaHighlight: ({ highlight, onChange, isScrolledTo, bounds, onContextMenu, onEditStart, style, highlightColor, onStyleChange, onDelete, styleIcon, deleteIcon, copyText, colorPresets, }: AreaHighlightProps) => React.JSX.Element;
786
909
 
787
910
  /**
788
911
  * Style options for freetext highlight appearance.
@@ -891,8 +1014,20 @@ interface FreetextHighlightProps {
891
1014
  * Custom delete icon. Replaces the default trash icon.
892
1015
  */
893
1016
  deleteIcon?: ReactNode;
1017
+ /**
1018
+ * Render the note as a compact marker until opened.
1019
+ */
1020
+ compact?: boolean;
1021
+ /**
1022
+ * Size of the compact marker in pixels.
1023
+ */
1024
+ compactSize?: number;
1025
+ /**
1026
+ * Custom compact marker icon.
1027
+ */
1028
+ compactIcon?: ReactNode;
894
1029
  }
895
- declare const FreetextHighlight: ({ highlight, onChange, onTextChange, onStyleChange, isScrolledTo, bounds, onContextMenu, onEditStart, onEditEnd, style, color, backgroundColor, fontFamily, fontSize, dragIcon, editIcon, styleIcon, backgroundColorPresets, textColorPresets, onDelete, deleteIcon, }: FreetextHighlightProps) => React.JSX.Element;
1030
+ declare const FreetextHighlight: ({ highlight, onChange, onTextChange, onStyleChange, isScrolledTo, bounds, onContextMenu, onEditStart, onEditEnd, style, color, backgroundColor, fontFamily, fontSize, dragIcon, editIcon, styleIcon, backgroundColorPresets, textColorPresets, onDelete, deleteIcon, compact, compactSize, compactIcon, }: FreetextHighlightProps) => React.JSX.Element;
896
1031
 
897
1032
  /**
898
1033
  * The props type for {@link ImageHighlight}.
@@ -1301,8 +1436,8 @@ interface PdfLoaderProps {
1301
1436
  */
1302
1437
  onError?(error: Error): void;
1303
1438
  /**
1304
- * NOTE: This will be applied to all PdfLoader instances.
1305
- * If you want to only apply a source to this instance, use the document parameters.
1439
+ * Optional PDF.js worker source override. By default, PdfLoader resolves the
1440
+ * worker from the installed pdfjs-dist package so bundlers can emit it locally.
1306
1441
  */
1307
1442
  workerSrc?: string;
1308
1443
  }
@@ -1360,86 +1495,77 @@ declare const viewportPositionToScaled: ({ boundingRect, rects }: ViewportPositi
1360
1495
  /** @category Utilities */
1361
1496
  declare const scaledPositionToViewport: ({ boundingRect, rects, usePdfCoordinates }: ScaledPosition, viewer: PDFViewer$2) => ViewportPosition;
1362
1497
 
1363
- /**
1364
- * Options for the PDF export function.
1365
- *
1366
- * @category Type
1367
- */
1368
- interface ExportPdfOptions {
1369
- /** Default color for text highlights. Default: "rgba(255, 226, 143, 0.5)" */
1370
- textHighlightColor?: string;
1371
- /** Default color for area highlights. Default: "rgba(255, 226, 143, 0.5)" */
1372
- areaHighlightColor?: string;
1373
- /** Default text color for freetext. Default: "#333333" */
1374
- defaultFreetextColor?: string;
1375
- /** Default background for freetext. Default: "#ffffc8" */
1376
- defaultFreetextBgColor?: string;
1377
- /** Default font size for freetext. Default: 14 */
1378
- defaultFreetextFontSize?: number;
1379
- /** Progress callback for large PDFs */
1380
- onProgress?: (current: number, total: number) => void;
1381
- }
1382
- /**
1383
- * A highlight that can be exported to PDF.
1384
- *
1385
- * @category Type
1386
- */
1387
- interface ExportableHighlight {
1498
+ type PdfTextItem = {
1499
+ text: string;
1500
+ index: number;
1501
+ pageNumber: number;
1502
+ rect: LTWHP;
1503
+ fontName?: string;
1504
+ columnIndex?: number;
1505
+ };
1506
+ type PdfTextColumn = {
1507
+ index: number;
1508
+ left: number;
1509
+ right: number;
1510
+ width: number;
1511
+ textItemIndexes: number[];
1512
+ };
1513
+ type PdfExtractedPage = {
1514
+ pageNumber: number;
1515
+ width: number;
1516
+ height: number;
1517
+ textItems: PdfTextItem[];
1518
+ columns?: PdfTextColumn[];
1519
+ };
1520
+ type PdfTextUnitType = "paragraph" | "title" | "heading" | "author" | "affiliation" | "footnote" | "reference" | "unknown";
1521
+ type PdfTextUnit = {
1388
1522
  id: string;
1389
- type?: "text" | "area" | "freetext" | "image" | "drawing" | "shape";
1390
- content?: {
1391
- text?: string;
1392
- image?: string;
1393
- shape?: ShapeData;
1523
+ type: PdfTextUnitType;
1524
+ text: string;
1525
+ rawText: string;
1526
+ pageNumber: number;
1527
+ indexInPage: number;
1528
+ columnIndex?: number;
1529
+ position?: ScaledPosition;
1530
+ source?: {
1531
+ textItemIndexes: number[];
1394
1532
  };
1395
- position: ScaledPosition;
1396
- /** Per-highlight color override (for text/area highlights) */
1397
- highlightColor?: string;
1398
- /** Style mode for text highlights: "highlight" (default), "underline", or "strikethrough" */
1399
- highlightStyle?: "highlight" | "underline" | "strikethrough";
1400
- /** Text color for freetext highlights */
1401
- color?: string;
1402
- /** Background color for freetext highlights */
1403
- backgroundColor?: string;
1404
- /** Font size for freetext highlights */
1405
- fontSize?: string;
1406
- /** Font family for freetext highlights (not used in export, Helvetica is always used) */
1407
- fontFamily?: string;
1408
- /** Shape type for shape highlights */
1409
- shapeType?: "rectangle" | "circle" | "arrow";
1410
- /** Stroke color for shape highlights */
1411
- strokeColor?: string;
1412
- /** Stroke width for shape highlights */
1413
- strokeWidth?: number;
1414
- }
1415
- /**
1416
- * Export a PDF with annotations embedded.
1417
- *
1418
- * @param pdfSource - The source PDF as a URL string, Uint8Array, or ArrayBuffer
1419
- * @param highlights - Array of highlights to embed in the PDF
1420
- * @param options - Export options for customizing colors and behavior
1421
- * @returns Promise<Uint8Array> - The modified PDF as bytes
1422
- *
1423
- * @example
1424
- * ```typescript
1425
- * const pdfBytes = await exportPdf(pdfUrl, highlights, {
1426
- * textHighlightColor: "rgba(255, 255, 0, 0.4)",
1427
- * onProgress: (current, total) => console.log(`${current}/${total} pages`)
1428
- * });
1429
- *
1430
- * // Download the file
1431
- * const blob = new Blob([pdfBytes], { type: "application/pdf" });
1432
- * const url = URL.createObjectURL(blob);
1433
- * const a = document.createElement("a");
1434
- * a.href = url;
1435
- * a.download = "annotated.pdf";
1436
- * a.click();
1437
- * URL.revokeObjectURL(url);
1438
- * ```
1439
- *
1440
- * @category Function
1441
- */
1442
- declare function exportPdf(pdfSource: string | Uint8Array | ArrayBuffer, highlights: ExportableHighlight[], options?: ExportPdfOptions): Promise<Uint8Array>;
1533
+ };
1534
+ type PdfSentenceSource = {
1535
+ startOffset: number;
1536
+ endOffset: number;
1537
+ textItemIndexes: number[];
1538
+ };
1539
+ type PdfSentence = {
1540
+ id: string;
1541
+ text: string;
1542
+ rawText: string;
1543
+ pageNumber: number;
1544
+ indexInPage: number;
1545
+ globalIndex: number;
1546
+ columnIndex?: number;
1547
+ position?: ScaledPosition;
1548
+ source?: PdfSentenceSource;
1549
+ };
1550
+ type PdfReadingOrder = "auto" | "document" | "position";
1551
+ type PdfColumnDetection = "auto" | "none";
1552
+ type ExtractSentencesOptions = {
1553
+ pages?: "all" | number[];
1554
+ includePositions?: boolean;
1555
+ includeSources?: boolean;
1556
+ normalize?: boolean;
1557
+ locale?: string;
1558
+ idPrefix?: string;
1559
+ includeTextUnitTypes?: PdfTextUnitType[];
1560
+ readingOrder?: PdfReadingOrder;
1561
+ columnDetection?: PdfColumnDetection;
1562
+ };
1563
+ declare const extractTextUnits: (pdfDocument: PDFDocumentProxy, options?: ExtractSentencesOptions) => Promise<PdfTextUnit[]>;
1564
+ declare const extractPageTextItems: (pdfDocument: PDFDocumentProxy, options?: Pick<ExtractSentencesOptions, "pages" | "columnDetection">) => Promise<PdfExtractedPage[]>;
1565
+ declare const extractSentences: (pdfDocument: PDFDocumentProxy, options?: ExtractSentencesOptions) => Promise<PdfSentence[]>;
1566
+ declare const sentenceToHighlight: (sentence: PdfSentence, options?: {
1567
+ id?: string;
1568
+ }) => Highlight;
1443
1569
 
1444
1570
  /** Style configuration for outline items */
1445
1571
  interface OutlineItemStyles {
@@ -1902,4 +2028,6 @@ interface UsePageNavigationResult {
1902
2028
  */
1903
2029
  declare function usePageNavigation(options: UsePageNavigationOptions): UsePageNavigationResult;
1904
2030
 
1905
- 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 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, PdfHighlighter, type PdfHighlighterProps, type PdfHighlighterTheme, type PdfHighlighterUtils, PdfLoader, type PdfLoaderProps, type PdfScaleValue, type PdfSelection, 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, scaledPositionToViewport, useDocumentOutline, useHighlightContainerContext, useLeftPanelContext, usePageNavigation, usePdfHighlighterContext, useThumbnails, viewportPositionToScaled };
2031
+ declare const exportPdf: typeof exportPdf$1;
2032
+
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 };