react-pdf-highlighter-plus 1.0.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.
- package/LICENSE +22 -0
- package/README.md +411 -0
- package/dist/esm/components/AreaHighlight.d.ts +82 -0
- package/dist/esm/components/AreaHighlight.js +109 -0
- package/dist/esm/components/AreaHighlight.js.map +1 -0
- package/dist/esm/components/DrawingCanvas.d.ts +48 -0
- package/dist/esm/components/DrawingCanvas.js +277 -0
- package/dist/esm/components/DrawingCanvas.js.map +1 -0
- package/dist/esm/components/DrawingHighlight.d.ts +70 -0
- package/dist/esm/components/DrawingHighlight.js +164 -0
- package/dist/esm/components/DrawingHighlight.js.map +1 -0
- package/dist/esm/components/FreetextHighlight.d.ts +112 -0
- package/dist/esm/components/FreetextHighlight.js +193 -0
- package/dist/esm/components/FreetextHighlight.js.map +1 -0
- package/dist/esm/components/HighlightLayer.d.ts +49 -0
- package/dist/esm/components/HighlightLayer.js +37 -0
- package/dist/esm/components/HighlightLayer.js.map +1 -0
- package/dist/esm/components/ImageHighlight.d.ts +63 -0
- package/dist/esm/components/ImageHighlight.js +65 -0
- package/dist/esm/components/ImageHighlight.js.map +1 -0
- package/dist/esm/components/MonitoredHighlightContainer.d.ts +37 -0
- package/dist/esm/components/MonitoredHighlightContainer.js +42 -0
- package/dist/esm/components/MonitoredHighlightContainer.js.map +1 -0
- package/dist/esm/components/MouseMonitor.d.ts +34 -0
- package/dist/esm/components/MouseMonitor.js +30 -0
- package/dist/esm/components/MouseMonitor.js.map +1 -0
- package/dist/esm/components/MouseSelection.d.ts +66 -0
- package/dist/esm/components/MouseSelection.js +122 -0
- package/dist/esm/components/MouseSelection.js.map +1 -0
- package/dist/esm/components/PdfHighlighter.d.ts +184 -0
- package/dist/esm/components/PdfHighlighter.js +410 -0
- package/dist/esm/components/PdfHighlighter.js.map +1 -0
- package/dist/esm/components/PdfLoader.d.ts +55 -0
- package/dist/esm/components/PdfLoader.js +57 -0
- package/dist/esm/components/PdfLoader.js.map +1 -0
- package/dist/esm/components/ShapeCanvas.d.ts +51 -0
- package/dist/esm/components/ShapeCanvas.js +205 -0
- package/dist/esm/components/ShapeCanvas.js.map +1 -0
- package/dist/esm/components/ShapeHighlight.d.ts +107 -0
- package/dist/esm/components/ShapeHighlight.js +140 -0
- package/dist/esm/components/ShapeHighlight.js.map +1 -0
- package/dist/esm/components/SignaturePad.d.ts +40 -0
- package/dist/esm/components/SignaturePad.js +138 -0
- package/dist/esm/components/SignaturePad.js.map +1 -0
- package/dist/esm/components/TextHighlight.d.ts +93 -0
- package/dist/esm/components/TextHighlight.js +115 -0
- package/dist/esm/components/TextHighlight.js.map +1 -0
- package/dist/esm/components/TipContainer.d.ts +27 -0
- package/dist/esm/components/TipContainer.js +58 -0
- package/dist/esm/components/TipContainer.js.map +1 -0
- package/dist/esm/contexts/HighlightContext.d.ts +44 -0
- package/dist/esm/contexts/HighlightContext.js +16 -0
- package/dist/esm/contexts/HighlightContext.js.map +1 -0
- package/dist/esm/contexts/PdfHighlighterContext.d.ts +89 -0
- package/dist/esm/contexts/PdfHighlighterContext.js +16 -0
- package/dist/esm/contexts/PdfHighlighterContext.js.map +1 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.js +19 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/coordinates.d.ts +16 -0
- package/dist/esm/lib/coordinates.js +69 -0
- package/dist/esm/lib/coordinates.js.map +1 -0
- package/dist/esm/lib/export-pdf.d.ts +81 -0
- package/dist/esm/lib/export-pdf.js +511 -0
- package/dist/esm/lib/export-pdf.js.map +1 -0
- package/dist/esm/lib/get-bounding-rect.d.ts +3 -0
- package/dist/esm/lib/get-bounding-rect.js +35 -0
- package/dist/esm/lib/get-bounding-rect.js.map +1 -0
- package/dist/esm/lib/get-client-rects.d.ts +3 -0
- package/dist/esm/lib/get-client-rects.js +43 -0
- package/dist/esm/lib/get-client-rects.js.map +1 -0
- package/dist/esm/lib/group-highlights-by-page.d.ts +6 -0
- package/dist/esm/lib/group-highlights-by-page.js +23 -0
- package/dist/esm/lib/group-highlights-by-page.js.map +1 -0
- package/dist/esm/lib/optimize-client-rects.d.ts +3 -0
- package/dist/esm/lib/optimize-client-rects.js +65 -0
- package/dist/esm/lib/optimize-client-rects.js.map +1 -0
- package/dist/esm/lib/pdfjs-dom.d.ts +9 -0
- package/dist/esm/lib/pdfjs-dom.js +55 -0
- package/dist/esm/lib/pdfjs-dom.js.map +1 -0
- package/dist/esm/lib/screenshot.d.ts +4 -0
- package/dist/esm/lib/screenshot.js +24 -0
- package/dist/esm/lib/screenshot.js.map +1 -0
- package/dist/esm/style/AreaHighlight.css +134 -0
- package/dist/esm/style/DrawingCanvas.css +62 -0
- package/dist/esm/style/DrawingHighlight.css +184 -0
- package/dist/esm/style/FreetextHighlight.css +249 -0
- package/dist/esm/style/ImageHighlight.css +97 -0
- package/dist/esm/style/MouseSelection.css +15 -0
- package/dist/esm/style/PdfHighlighter.css +77 -0
- package/dist/esm/style/ShapeCanvas.css +47 -0
- package/dist/esm/style/ShapeHighlight.css +182 -0
- package/dist/esm/style/SignaturePad.css +83 -0
- package/dist/esm/style/TextHighlight.css +199 -0
- package/dist/esm/style/pdf_viewer.css +41 -0
- package/dist/esm/types.d.ts +213 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { CSSProperties } from "react";
|
|
2
|
+
import "../style/MouseSelection.css";
|
|
3
|
+
import { PDFViewer } from "pdfjs-dist/types/web/pdf_viewer";
|
|
4
|
+
import type { ScaledPosition, ViewportPosition } from "../types";
|
|
5
|
+
/**
|
|
6
|
+
* The props type for {@link MouseSelection}.
|
|
7
|
+
*
|
|
8
|
+
* @category Component Properties
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export interface MouseSelectionProps {
|
|
12
|
+
/**
|
|
13
|
+
* The PDFViewer instance containing this MouseSelection.
|
|
14
|
+
*/
|
|
15
|
+
viewer: PDFViewer;
|
|
16
|
+
/**
|
|
17
|
+
* Callback triggered whenever the user stops dragging their mouse and a valid
|
|
18
|
+
* mouse selection is made. In general, this will only be called if a mouse
|
|
19
|
+
* selection is rendered.
|
|
20
|
+
*
|
|
21
|
+
* @param viewportPosition - viewport position of the mouse selection.
|
|
22
|
+
* @param scaledPosition - scaled position of the mouse selection.
|
|
23
|
+
* @param image - PNG screenshot of the mouse selection.
|
|
24
|
+
* @param resetSelection - Callback to reset the current selection.
|
|
25
|
+
* @param event - Mouse event associated with ending the selection.
|
|
26
|
+
*/
|
|
27
|
+
onSelection?(viewportPosition: ViewportPosition, scaledPosition: ScaledPosition, image: string, resetSelection: () => void, event: MouseEvent): void;
|
|
28
|
+
/**
|
|
29
|
+
* Callback triggered whenever the current mouse selection is reset.
|
|
30
|
+
* This includes when dragging ends but the selection is invalid.
|
|
31
|
+
*/
|
|
32
|
+
onReset?(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Callback triggered whenever a new valid mouse selection begins.
|
|
35
|
+
*
|
|
36
|
+
* @param event - mouse event associated with the new selection.
|
|
37
|
+
*/
|
|
38
|
+
onDragStart?(event: MouseEvent): void;
|
|
39
|
+
/**
|
|
40
|
+
* Condition to check before any mouse selection starts.
|
|
41
|
+
*
|
|
42
|
+
* @param event - mouse event associated with the new selection.
|
|
43
|
+
* @returns - `True` if mouse selection should start.
|
|
44
|
+
*/
|
|
45
|
+
enableAreaSelection(event: MouseEvent): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Callback whenever the mouse selection area changes.
|
|
48
|
+
*
|
|
49
|
+
* @param isVisible - Whether the mouse selection is rendered (i.e., non-zero area)
|
|
50
|
+
*/
|
|
51
|
+
onChange?(isVisible: boolean): void;
|
|
52
|
+
/**
|
|
53
|
+
* Optional style props for the mouse selection rectangle.
|
|
54
|
+
*/
|
|
55
|
+
style?: CSSProperties;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A component that enables the creation of rectangular and interactive mouse
|
|
59
|
+
* selections within a given container. NOTE: This does not disable selection in
|
|
60
|
+
* whatever container the component is placed in. That must be handled through
|
|
61
|
+
* the component's events.
|
|
62
|
+
*
|
|
63
|
+
* @category Component
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export declare const MouseSelection: ({ viewer, onSelection, onReset, onDragStart, enableAreaSelection, onChange, style, }: MouseSelectionProps) => React.JSX.Element;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { asElement, getPageFromElement, isHTMLElement } from "../lib/pdfjs-dom";
|
|
3
|
+
import "../style/MouseSelection.css";
|
|
4
|
+
import { viewportPositionToScaled } from "../lib/coordinates";
|
|
5
|
+
import screenshot from "../lib/screenshot";
|
|
6
|
+
const getBoundingRect = (start, end) => {
|
|
7
|
+
return {
|
|
8
|
+
left: Math.min(end.x, start.x),
|
|
9
|
+
top: Math.min(end.y, start.y),
|
|
10
|
+
width: Math.abs(end.x - start.x),
|
|
11
|
+
height: Math.abs(end.y - start.y),
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const getContainerCoords = (container, pageX, pageY) => {
|
|
15
|
+
const containerBoundingRect = container.getBoundingClientRect();
|
|
16
|
+
return {
|
|
17
|
+
x: pageX - containerBoundingRect.left + container.scrollLeft,
|
|
18
|
+
y: pageY - containerBoundingRect.top + container.scrollTop - window.scrollY,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A component that enables the creation of rectangular and interactive mouse
|
|
23
|
+
* selections within a given container. NOTE: This does not disable selection in
|
|
24
|
+
* whatever container the component is placed in. That must be handled through
|
|
25
|
+
* the component's events.
|
|
26
|
+
*
|
|
27
|
+
* @category Component
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export const MouseSelection = ({ viewer, onSelection, onReset, onDragStart, enableAreaSelection, onChange, style, }) => {
|
|
31
|
+
const [start, setStart] = useState(null);
|
|
32
|
+
const [end, setEnd] = useState(null);
|
|
33
|
+
const [locked, setLocked] = useState(false);
|
|
34
|
+
const rootRef = useRef(null);
|
|
35
|
+
// Needed in order to grab the page info of a mouse selection
|
|
36
|
+
const startTargetRef = useRef(null);
|
|
37
|
+
const reset = () => {
|
|
38
|
+
onReset && onReset();
|
|
39
|
+
setStart(null);
|
|
40
|
+
setEnd(null);
|
|
41
|
+
setLocked(false);
|
|
42
|
+
};
|
|
43
|
+
// Register event listeners onChange
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
onChange && onChange(Boolean(start && end));
|
|
46
|
+
if (!rootRef.current)
|
|
47
|
+
return;
|
|
48
|
+
// Should be the PdfHighlighter
|
|
49
|
+
const container = asElement(rootRef.current.parentElement);
|
|
50
|
+
const handleMouseUp = (event) => {
|
|
51
|
+
if (!start || !end || !startTargetRef.current)
|
|
52
|
+
return;
|
|
53
|
+
const boundingRect = getBoundingRect(start, end);
|
|
54
|
+
// Check if the bounding rectangle has a minimum width and height
|
|
55
|
+
// to prevent recording selections with 0 area
|
|
56
|
+
const shouldEnd = boundingRect.width >= 1 && boundingRect.height >= 1;
|
|
57
|
+
if (!container.contains(asElement(event.target)) || !shouldEnd) {
|
|
58
|
+
reset();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
setLocked(true);
|
|
62
|
+
const page = getPageFromElement(startTargetRef.current);
|
|
63
|
+
if (!page)
|
|
64
|
+
return;
|
|
65
|
+
const pageBoundingRect = {
|
|
66
|
+
...boundingRect,
|
|
67
|
+
top: boundingRect.top - page.node.offsetTop,
|
|
68
|
+
left: boundingRect.left - page.node.offsetLeft,
|
|
69
|
+
pageNumber: page.number,
|
|
70
|
+
};
|
|
71
|
+
const viewportPosition = {
|
|
72
|
+
boundingRect: pageBoundingRect,
|
|
73
|
+
rects: [],
|
|
74
|
+
};
|
|
75
|
+
const scaledPosition = viewportPositionToScaled(viewportPosition, viewer);
|
|
76
|
+
const image = screenshot(pageBoundingRect, pageBoundingRect.pageNumber, viewer);
|
|
77
|
+
onSelection &&
|
|
78
|
+
onSelection(viewportPosition, scaledPosition, image, reset, event);
|
|
79
|
+
};
|
|
80
|
+
const handleMouseMove = (event) => {
|
|
81
|
+
if (!rootRef.current || !start || locked)
|
|
82
|
+
return;
|
|
83
|
+
setEnd(getContainerCoords(container, event.pageX, event.pageY));
|
|
84
|
+
};
|
|
85
|
+
const handleMouseDown = (event) => {
|
|
86
|
+
const shouldStart = (event) => enableAreaSelection(event) &&
|
|
87
|
+
isHTMLElement(event.target) &&
|
|
88
|
+
Boolean(asElement(event.target).closest(".page"));
|
|
89
|
+
// If the user clicks anywhere outside a tip, reset the selection
|
|
90
|
+
const shouldReset = (event) => start &&
|
|
91
|
+
!asElement(event.target).closest(".PdfHighlighter__tip-container");
|
|
92
|
+
if (!shouldStart(event)) {
|
|
93
|
+
if (shouldReset(event))
|
|
94
|
+
reset();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
startTargetRef.current = asElement(event.target);
|
|
98
|
+
onDragStart && onDragStart(event);
|
|
99
|
+
setStart(getContainerCoords(container, event.pageX, event.pageY));
|
|
100
|
+
setEnd(null);
|
|
101
|
+
setLocked(false);
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Although we register the event listeners on the PdfHighlighter component, we encapsulate
|
|
105
|
+
* them in this separate component to enhance maintainability and prevent unnecessary
|
|
106
|
+
* rerenders of the PdfHighlighter itself. While synthetic events on PdfHighlighter would
|
|
107
|
+
* be preferable, we need to register "mouseup" on the entire document anyway. Therefore,
|
|
108
|
+
* we can't avoid using useEffect. We must re-register all events on state changes, as
|
|
109
|
+
* custom event listeners may otherwise receive stale state.
|
|
110
|
+
*/
|
|
111
|
+
container.addEventListener("mousemove", handleMouseMove);
|
|
112
|
+
container.addEventListener("mousedown", handleMouseDown);
|
|
113
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
114
|
+
return () => {
|
|
115
|
+
container.removeEventListener("mousemove", handleMouseMove);
|
|
116
|
+
container.removeEventListener("mousedown", handleMouseDown);
|
|
117
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
118
|
+
};
|
|
119
|
+
}, [start, end, enableAreaSelection]);
|
|
120
|
+
return (React.createElement("div", { className: "MouseSelection-container", ref: rootRef }, start && end && (React.createElement("div", { className: "MouseSelection", style: { ...getBoundingRect(start, end), ...style } }))));
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=MouseSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MouseSelection.js","sourceRoot":"","sources":["../../../src/components/MouseSelection.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,6BAA6B,CAAC;AAGrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,UAAU,MAAM,mBAAmB,CAAC;AAQ3C,MAAM,eAAe,GAAG,CAAC,KAAa,EAAE,GAAW,EAAQ,EAAE;IAC3D,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;QAC9B,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;QAE7B,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;QAChC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;KAClC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CACzB,SAAsB,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QACnB,CAAC,CAAC;QAEF;;;;;;;WAOG;QACH,SAAS,CAAC,gBAAgB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QACzD,SAAS,CAAC,gBAAgB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QAEzD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAEpD,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,mBAAmB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;YAC5D,SAAS,CAAC,mBAAmB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;YAC5D,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QACzD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAEtC,OAAO,CACL,6BAAK,SAAS,EAAC,0BAA0B,EAAC,GAAG,EAAE,OAAO,IACnD,KAAK,IAAI,GAAG,IAAI,CACf,6BACE,SAAS,EAAC,gBAAgB,EAC1B,KAAK,EAAE,EAAE,GAAG,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,KAAK,EAAE,GACnD,CACH,CACG,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import "pdfjs-dist/web/pdf_viewer.css";
|
|
2
|
+
import "../style/PdfHighlighter.css";
|
|
3
|
+
import "../style/pdf_viewer.css";
|
|
4
|
+
import { PDFDocumentProxy } from "pdfjs-dist";
|
|
5
|
+
import React, { CSSProperties, ReactNode } from "react";
|
|
6
|
+
import { PdfHighlighterUtils } from "../contexts/PdfHighlighterContext";
|
|
7
|
+
import { DrawingStroke, GhostHighlight, Highlight, PdfScaleValue, PdfSelection, ScaledPosition, ShapeData, ShapeType } from "../types";
|
|
8
|
+
/**
|
|
9
|
+
* The props type for {@link PdfHighlighter}.
|
|
10
|
+
*
|
|
11
|
+
* @category Component Properties
|
|
12
|
+
*/
|
|
13
|
+
export interface PdfHighlighterProps {
|
|
14
|
+
/**
|
|
15
|
+
* Array of all highlights to be organised and fed through to the child
|
|
16
|
+
* highlight container.
|
|
17
|
+
*/
|
|
18
|
+
highlights: Array<Highlight>;
|
|
19
|
+
/**
|
|
20
|
+
* Event is called only once whenever the user changes scroll after
|
|
21
|
+
* the autoscroll function, scrollToHighlight, has been called.
|
|
22
|
+
*/
|
|
23
|
+
onScrollAway?(): void;
|
|
24
|
+
/**
|
|
25
|
+
* What scale to render the PDF at inside the viewer.
|
|
26
|
+
*/
|
|
27
|
+
pdfScaleValue?: PdfScaleValue;
|
|
28
|
+
/**
|
|
29
|
+
* Callback triggered whenever a user finishes making a mouse selection or has
|
|
30
|
+
* selected text.
|
|
31
|
+
*
|
|
32
|
+
* @param PdfSelection - Content and positioning of the selection. NOTE:
|
|
33
|
+
* `makeGhostHighlight` will not work if the selection disappears.
|
|
34
|
+
*/
|
|
35
|
+
onSelection?(PdfSelection: PdfSelection): void;
|
|
36
|
+
/**
|
|
37
|
+
* Callback triggered whenever a ghost (non-permanent) highlight is created.
|
|
38
|
+
*
|
|
39
|
+
* @param ghostHighlight - Ghost Highlight that has been created.
|
|
40
|
+
*/
|
|
41
|
+
onCreateGhostHighlight?(ghostHighlight: GhostHighlight): void;
|
|
42
|
+
/**
|
|
43
|
+
* Callback triggered whenever a ghost (non-permanent) highlight is removed.
|
|
44
|
+
*
|
|
45
|
+
* @param ghostHighlight - Ghost Highlight that has been removed.
|
|
46
|
+
*/
|
|
47
|
+
onRemoveGhostHighlight?(ghostHighlight: GhostHighlight): void;
|
|
48
|
+
/**
|
|
49
|
+
* Optional element that can be displayed as a tip whenever a user makes a
|
|
50
|
+
* selection.
|
|
51
|
+
*/
|
|
52
|
+
selectionTip?: ReactNode;
|
|
53
|
+
/**
|
|
54
|
+
* Condition to check before any mouse selection starts.
|
|
55
|
+
*
|
|
56
|
+
* @param event - mouse event associated with the new selection.
|
|
57
|
+
* @returns - `True` if mouse selection should start.
|
|
58
|
+
*/
|
|
59
|
+
enableAreaSelection?(event: MouseEvent): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* When true, shows crosshair cursor indicating area selection mode is active.
|
|
62
|
+
* Use this when area selection should be persistently enabled (not just on modifier key).
|
|
63
|
+
*/
|
|
64
|
+
areaSelectionMode?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Optional CSS styling for the rectangular mouse selection.
|
|
67
|
+
*/
|
|
68
|
+
mouseSelectionStyle?: CSSProperties;
|
|
69
|
+
/**
|
|
70
|
+
* PDF document to view and overlay highlights.
|
|
71
|
+
*/
|
|
72
|
+
pdfDocument: PDFDocumentProxy;
|
|
73
|
+
/**
|
|
74
|
+
* This should be a highlight container/renderer of some sorts. It will be
|
|
75
|
+
* given appropriate context for a single highlight which it can then use to
|
|
76
|
+
* render a TextHighlight, AreaHighlight, etc. in the correct place.
|
|
77
|
+
*/
|
|
78
|
+
children: ReactNode;
|
|
79
|
+
/**
|
|
80
|
+
* Coloring for unhighlighted, selected text.
|
|
81
|
+
*/
|
|
82
|
+
textSelectionColor?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a reference to the PdfHighlighterContext above the component.
|
|
85
|
+
*
|
|
86
|
+
* @param pdfHighlighterUtils - various useful tools with a PdfHighlighter.
|
|
87
|
+
* See {@link PdfHighlighterContext} for more description.
|
|
88
|
+
*/
|
|
89
|
+
utilsRef(pdfHighlighterUtils: PdfHighlighterUtils): void;
|
|
90
|
+
/**
|
|
91
|
+
* Style properties for the PdfHighlighter (scrollbar, background, etc.), NOT
|
|
92
|
+
* the PDF.js viewer it encloses. If you want to edit the latter, use the
|
|
93
|
+
* other style props like `textSelectionColor` or overwrite pdf_viewer.css
|
|
94
|
+
*/
|
|
95
|
+
style?: CSSProperties;
|
|
96
|
+
/**
|
|
97
|
+
* Condition to check before freetext creation starts.
|
|
98
|
+
*
|
|
99
|
+
* @param event - mouse event associated with the click.
|
|
100
|
+
* @returns - `True` if freetext creation should occur.
|
|
101
|
+
*/
|
|
102
|
+
enableFreetextCreation?(event: MouseEvent): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Callback triggered when user clicks to create a freetext annotation.
|
|
105
|
+
*
|
|
106
|
+
* @param position - Scaled position where the click occurred.
|
|
107
|
+
*/
|
|
108
|
+
onFreetextClick?(position: ScaledPosition): void;
|
|
109
|
+
/**
|
|
110
|
+
* Condition to check before image creation starts.
|
|
111
|
+
*
|
|
112
|
+
* @param event - mouse event associated with the click.
|
|
113
|
+
* @returns - `True` if image creation should occur.
|
|
114
|
+
*/
|
|
115
|
+
enableImageCreation?(event: MouseEvent): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Callback triggered when user clicks to create an image annotation.
|
|
118
|
+
*
|
|
119
|
+
* @param position - Scaled position where the click occurred.
|
|
120
|
+
*/
|
|
121
|
+
onImageClick?(position: ScaledPosition): void;
|
|
122
|
+
/**
|
|
123
|
+
* Whether drawing mode is enabled.
|
|
124
|
+
*/
|
|
125
|
+
enableDrawingMode?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Callback triggered when a drawing is completed.
|
|
128
|
+
*
|
|
129
|
+
* @param dataUrl - The drawing as a PNG data URL.
|
|
130
|
+
* @param position - Scaled position of the drawing on the page.
|
|
131
|
+
* @param strokes - The stroke data for later editing.
|
|
132
|
+
*/
|
|
133
|
+
onDrawingComplete?(dataUrl: string, position: ScaledPosition, strokes: DrawingStroke[]): void;
|
|
134
|
+
/**
|
|
135
|
+
* Callback triggered when drawing is cancelled.
|
|
136
|
+
*/
|
|
137
|
+
onDrawingCancel?(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Stroke color for drawing mode.
|
|
140
|
+
* @default "#000000"
|
|
141
|
+
*/
|
|
142
|
+
drawingStrokeColor?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Stroke width for drawing mode.
|
|
145
|
+
* @default 3
|
|
146
|
+
*/
|
|
147
|
+
drawingStrokeWidth?: number;
|
|
148
|
+
/**
|
|
149
|
+
* The type of shape to create, or null if shape mode is not active.
|
|
150
|
+
*/
|
|
151
|
+
enableShapeMode?: ShapeType | null;
|
|
152
|
+
/**
|
|
153
|
+
* Callback triggered when a shape is completed.
|
|
154
|
+
*
|
|
155
|
+
* @param position - Scaled position of the shape on the page.
|
|
156
|
+
* @param shape - The shape data (type, color, width).
|
|
157
|
+
*/
|
|
158
|
+
onShapeComplete?(position: ScaledPosition, shape: ShapeData): void;
|
|
159
|
+
/**
|
|
160
|
+
* Callback triggered when shape creation is cancelled.
|
|
161
|
+
*/
|
|
162
|
+
onShapeCancel?(): void;
|
|
163
|
+
/**
|
|
164
|
+
* Stroke color for shape mode.
|
|
165
|
+
* @default "#000000"
|
|
166
|
+
*/
|
|
167
|
+
shapeStrokeColor?: string;
|
|
168
|
+
/**
|
|
169
|
+
* Stroke width for shape mode.
|
|
170
|
+
* @default 2
|
|
171
|
+
*/
|
|
172
|
+
shapeStrokeWidth?: number;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* This is a large-scale PDF viewer component designed to facilitate
|
|
176
|
+
* highlighting. It should be used as a child to a {@link PdfLoader} to ensure
|
|
177
|
+
* proper document loading. This does not itself render any highlights, but
|
|
178
|
+
* instead its child should be the container component for each individual
|
|
179
|
+
* highlight. This component will be provided appropriate HighlightContext for
|
|
180
|
+
* rendering.
|
|
181
|
+
*
|
|
182
|
+
* @category Component
|
|
183
|
+
*/
|
|
184
|
+
export 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, }: PdfHighlighterProps) => React.JSX.Element;
|