@react-pdf-kit/viewer 0.0.0-experimental.2 → 0.0.0-experimental.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.
- package/dist/{Combination-17ab8af1.js → Combination-479e39c6.js} +187 -184
- package/dist/RPLayout.module-7766e0b4.js +14 -0
- package/dist/assets/style.css +1 -1
- package/dist/assets/style.js +15 -15
- package/dist/components/RPController.js +24 -20
- package/dist/components/RPPages.js +322 -321
- package/dist/components/RPProvider.js +22 -19
- package/dist/components/layout/LayoutContainer.js +1 -1
- package/dist/components/layout/LayoutWrapper.js +1 -1
- package/dist/components/layout/RPDefaultLayout.js +7 -5
- package/dist/components/layout/RPLayout.js +7 -5
- package/dist/components/layout/toolbar/DocumentDialog.js +1 -1
- package/dist/components/layout/toolbar/DocumentProperties.js +2 -2
- package/dist/components/layout/toolbar/FileDownloadTool.js +2 -2
- package/dist/components/layout/toolbar/FileUploadTool.js +2 -2
- package/dist/components/layout/toolbar/FullScreenTool.js +2 -2
- package/dist/components/layout/toolbar/MenuItem.js +2 -2
- package/dist/components/layout/toolbar/MenuSeparator.js +2 -2
- package/dist/components/layout/toolbar/MostPageTool.js +2 -2
- package/dist/components/layout/toolbar/OtherTool.js +2 -2
- package/dist/components/layout/toolbar/PrintTool.js +2 -2
- package/dist/components/layout/toolbar/RPMenuItem.js +2 -2
- package/dist/components/layout/toolbar/RPMoreOptions.js +2 -2
- package/dist/components/layout/toolbar/RPToolbar.js +6 -4
- package/dist/components/layout/toolbar/RPToolbarEnd.js +2 -2
- package/dist/components/layout/toolbar/RotateTool.js +2 -2
- package/dist/components/layout/toolbar/ScrollModeTool.js +2 -2
- package/dist/components/layout/toolbar/SearchResultNavigator.js +4 -2
- package/dist/components/layout/toolbar/SearchTool.js +6 -4
- package/dist/components/layout/toolbar/SelectionModeTool.js +2 -2
- package/dist/components/layout/toolbar/ToolbarDefault.js +6 -4
- package/dist/components/layout/toolbar/ToolbarLayout.js +6 -4
- package/dist/components/layout/toolbar/ViewModeTool.js +2 -2
- package/dist/components/layout/toolbar/ZoomTool.js +2 -2
- package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +1 -1
- package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +9 -6
- package/dist/components/layout/toolbar/tools/FirstPageTool.js +9 -6
- package/dist/components/layout/toolbar/tools/LastPageTool.js +9 -6
- package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +2 -2
- package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +6 -4
- package/dist/components/layout/toolbar/tools/more-options/DocumentProperties.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/FullScreenTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/ScrollModeTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/SelectionModeTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/ViewModeTool.js +2 -2
- package/dist/components/page/AnnotationLayer.js +52 -52
- package/dist/components/page/DualPage.js +9 -4
- package/dist/components/page/DualPageWithCover.js +9 -4
- package/dist/components/page/RPPage.js +9 -4
- package/dist/components/page/SinglePage.js +9 -4
- package/dist/components/page/TextHighlightLayer.js +84 -177
- package/dist/components/page/TextLayer.js +124 -170
- package/dist/components/ui/DropDown.js +2 -2
- package/dist/contexts/HighlightContext.js +8 -6
- package/dist/contexts/SearchContext.js +6 -4
- package/dist/contexts/TextSelectionContext.js +191 -0
- package/dist/{index-11f3cd64.js → index-535ad364.js} +1 -1
- package/dist/main.js +116 -114
- package/dist/types/contexts/TextSelectionContext.d.ts +14 -0
- package/dist/types/utils/geometryCache.d.ts +15 -0
- package/dist/types/utils/glyphHitTest.d.ts +12 -0
- package/dist/types/utils/hooks/useTextSelection.d.ts +12 -3
- package/dist/types/utils/selectionUtils.d.ts +30 -0
- package/dist/utils/geometryCache.js +32 -0
- package/dist/utils/glyphHitTest.js +29 -0
- package/dist/utils/highlight.js +184 -158
- package/dist/utils/hooks/useCopyText.js +60 -22
- package/dist/utils/hooks/useHighlight.js +35 -33
- package/dist/utils/hooks/useLicense.js +1 -1
- package/dist/utils/hooks/useSearch.js +4 -2
- package/dist/utils/hooks/useTextSelection.js +2 -73
- package/dist/utils/selectionUtils.js +96 -0
- package/package.json +2 -2
- package/dist/RPLayout.module-b4b23e29.js +0 -14
- package/dist/types/utils/hooks/useFlickerSelectText.d.ts +0 -1
- package/dist/utils/hooks/useFlickerSelectText.js +0 -25
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { jsx as P } from "react/jsx-runtime";
|
|
2
|
-
import { useRef as
|
|
2
|
+
import { useRef as g, useState as F, useMemo as S, useEffect as b, useCallback as R } from "react";
|
|
3
3
|
import { u as j } from "../../PaginationContext-9217cab4.js";
|
|
4
4
|
import { usePrintContext as O } from "../../contexts/PrintContext.js";
|
|
5
5
|
import { AnnotationLayerBuilder as D } from "@pdf-viewer/pdfium/compat";
|
|
6
6
|
import { SimpleLinkService as A } from "../../utils/link_service.js";
|
|
7
7
|
import { AnnotationSubType as _ } from "../../utils/types.js";
|
|
8
8
|
import { useScrollModeContext as $ } from "../../contexts/ScrollModeContext.js";
|
|
9
|
-
import { insertDateText as J, annotationEventsHandler as N, handleAnnotationWidget as
|
|
9
|
+
import { insertDateText as J, annotationEventsHandler as N, handleAnnotationWidget as W, bindLayerEvents as Z, fixTabIndexAccessibility as C, enhanceLinkAccessibility as M, unbindLayerEvents as L } from "../../utils/annotations.js";
|
|
10
10
|
import { useInitialStateContext as B } from "../../contexts/InitialStateContext.js";
|
|
11
11
|
import { useDocumentContext as H } from "../../contexts/RPDocumentContext.js";
|
|
12
12
|
import { useFileDownload as U } from "../../utils/hooks/useFileDownload.js";
|
|
13
|
+
import { useZoomContext as V } from "../../contexts/ZoomContext.js";
|
|
13
14
|
import "../../utils/appConsole.js";
|
|
14
15
|
import "../../contexts/GlobalCurrentPage.js";
|
|
15
16
|
import "../../contexts/EventCallbackContext.js";
|
|
@@ -19,10 +20,8 @@ import "../../contexts/VirtualScrollContext.js";
|
|
|
19
20
|
import "../../contexts/VirtualGridContext.js";
|
|
20
21
|
import "../../utils/smoothScrollTo.js";
|
|
21
22
|
import "../../contexts/DimensionPagesContext.js";
|
|
22
|
-
import "../../contexts/ZoomContext.js";
|
|
23
23
|
import "../../utils/constants.js";
|
|
24
|
-
import "../../
|
|
25
|
-
import "../../contexts/LayoutContainerContext.js";
|
|
24
|
+
import "../../contexts/PagesRotateContext.js";
|
|
26
25
|
import "../../contexts/RotationContext.js";
|
|
27
26
|
import "../../utils/hooks/useLoadPdf.js";
|
|
28
27
|
import "@pdf-viewer/pdfium";
|
|
@@ -32,8 +31,9 @@ import "../../contexts/DocumentPasswordContext.js";
|
|
|
32
31
|
import "../../utils/hooks/usePdfProperties.js";
|
|
33
32
|
import "../../utils/convertPdfDate.js";
|
|
34
33
|
import "../../utils/formatFileSize.js";
|
|
34
|
+
import "../../utils/getZoomLevel.js";
|
|
35
|
+
import "../../contexts/LayoutContainerContext.js";
|
|
35
36
|
import "../../utils/hooks/useDebounce.js";
|
|
36
|
-
import "../../contexts/PagesRotateContext.js";
|
|
37
37
|
import "../../contexts/SmoothScrollContext.js";
|
|
38
38
|
import "../../utils/getScrollDistance.js";
|
|
39
39
|
import "../../utils/calculatePage.js";
|
|
@@ -45,69 +45,69 @@ const q = {
|
|
|
45
45
|
"rp-annotation-layer": "_rp-annotation-layer_rwxfx_1"
|
|
46
46
|
};
|
|
47
47
|
let z = "https://unpkg.com/pdfjs-dist@4.4.168/web/images/";
|
|
48
|
-
const
|
|
49
|
-
const { pageNumber:
|
|
50
|
-
|
|
48
|
+
const Jt = (T) => {
|
|
49
|
+
const { pageNumber: m } = T, t = g(null), { pages: h, pdf: r } = H(), { interactiveForm: k } = B(), n = g(), [c, E] = F(), { goToPage: d } = j(), { scrollMode: I } = $(), { print: x } = O(), { download: v } = U(), s = g(null), { currentZoom: y } = V(), o = S(() => h.get(m), [h, m]), e = S(() => o == null ? void 0 : o.page.getViewport({ scale: y }), [o, y]);
|
|
50
|
+
b(() => {
|
|
51
51
|
n.current && (n.current.div.replaceChildren(), n.current = void 0);
|
|
52
|
-
}, [r]),
|
|
53
|
-
|
|
54
|
-
n.current = void 0,
|
|
52
|
+
}, [r]), b(() => {
|
|
53
|
+
o && o.page.getAnnotations().then((u) => {
|
|
54
|
+
n.current = void 0, E(u), t.current && (t.current.innerText = "");
|
|
55
55
|
});
|
|
56
|
-
}, [
|
|
57
|
-
const
|
|
58
|
-
(
|
|
59
|
-
!
|
|
60
|
-
var
|
|
61
|
-
((
|
|
56
|
+
}, [o]);
|
|
57
|
+
const p = R(
|
|
58
|
+
(u) => {
|
|
59
|
+
!c || !r || (J(t.current), N(u, r, c).then((a) => {
|
|
60
|
+
var l, i;
|
|
61
|
+
((l = a == null ? void 0 : a.data) == null ? void 0 : l.action) === "Print" ? x() : ((i = a == null ? void 0 : a.data) == null ? void 0 : i.action) === "SaveAs" && v();
|
|
62
62
|
}));
|
|
63
63
|
},
|
|
64
|
-
[r,
|
|
64
|
+
[r, c, I, x, v]
|
|
65
65
|
);
|
|
66
|
-
return
|
|
67
|
-
if (!
|
|
66
|
+
return b(() => {
|
|
67
|
+
if (!o || !c || !e)
|
|
68
68
|
return;
|
|
69
|
-
const o = e.page.getViewport();
|
|
70
69
|
if (n.current) {
|
|
71
70
|
n.current.update({
|
|
72
|
-
viewport:
|
|
71
|
+
viewport: e
|
|
73
72
|
});
|
|
74
73
|
return;
|
|
75
74
|
}
|
|
76
|
-
const
|
|
77
|
-
for (const
|
|
78
|
-
const { annotationType:
|
|
79
|
-
switch (
|
|
75
|
+
const u = /* @__PURE__ */ new Map([]);
|
|
76
|
+
for (const i of c) {
|
|
77
|
+
const { annotationType: f } = i;
|
|
78
|
+
switch (f) {
|
|
80
79
|
case _.Widget:
|
|
81
|
-
|
|
80
|
+
W(i, e, u);
|
|
82
81
|
break;
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
|
-
const
|
|
84
|
+
const a = new AbortController();
|
|
86
85
|
return (async () => {
|
|
87
|
-
var
|
|
86
|
+
var w;
|
|
88
87
|
n.current && (n.current.div.replaceChildren(), n.current = void 0), t.current && (t.current.innerText = ""), n.current = new D({
|
|
89
88
|
div: t.current,
|
|
90
89
|
accessibilityManager: void 0,
|
|
91
90
|
annotationCanvasMap: void 0,
|
|
92
91
|
annotationEditorUIManager: void 0,
|
|
93
92
|
structTreeLayer: null,
|
|
94
|
-
page:
|
|
95
|
-
viewport:
|
|
93
|
+
page: o.page,
|
|
94
|
+
viewport: e,
|
|
96
95
|
commentManager: void 0,
|
|
97
96
|
linkService: new A(r, d),
|
|
98
|
-
annotationStorage: r == null ? void 0 : r.annotationStorage
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
annotationStorage: r == null ? void 0 : r.annotationStorage,
|
|
98
|
+
pageIndex: m - 1
|
|
99
|
+
}), t.current && L(t.current, p);
|
|
100
|
+
const i = await (r == null ? void 0 : r.hasJSActions()), f = await (r == null ? void 0 : r.getFieldObjects());
|
|
101
|
+
if (a.signal.aborted)
|
|
102
102
|
throw "abort";
|
|
103
|
-
return (
|
|
104
|
-
annotations:
|
|
103
|
+
return (w = n.current) == null ? void 0 : w.render({
|
|
104
|
+
annotations: c,
|
|
105
105
|
annotationStorage: r == null ? void 0 : r.annotationStorage,
|
|
106
|
-
hasJSActions:
|
|
107
|
-
fieldObjects:
|
|
106
|
+
hasJSActions: i,
|
|
107
|
+
fieldObjects: f,
|
|
108
108
|
div: t.current,
|
|
109
|
-
viewport:
|
|
110
|
-
page:
|
|
109
|
+
viewport: e,
|
|
110
|
+
page: o.page,
|
|
111
111
|
imageResourcesPath: z,
|
|
112
112
|
renderForms: k ?? !0,
|
|
113
113
|
linkService: new A(r, d),
|
|
@@ -115,32 +115,32 @@ const $t = (T) => {
|
|
|
115
115
|
enableScripting: !1
|
|
116
116
|
});
|
|
117
117
|
})().then(() => {
|
|
118
|
-
t.current && (
|
|
118
|
+
t.current && (Z(t.current, p), C(t.current), M(t.current), s.current && s.current.disconnect(), s.current = new MutationObserver(() => {
|
|
119
119
|
t.current && (C(t.current), M(t.current));
|
|
120
|
-
}),
|
|
120
|
+
}), s.current.observe(t.current, {
|
|
121
121
|
childList: !0,
|
|
122
122
|
subtree: !0,
|
|
123
123
|
attributes: !0,
|
|
124
124
|
attributeFilter: ["tabindex", "href"]
|
|
125
125
|
}));
|
|
126
|
-
}).catch((
|
|
127
|
-
if (
|
|
128
|
-
throw
|
|
126
|
+
}).catch((i) => {
|
|
127
|
+
if (i !== "abort")
|
|
128
|
+
throw i;
|
|
129
129
|
}).finally(() => {
|
|
130
130
|
n.current = void 0;
|
|
131
131
|
}), () => {
|
|
132
|
-
|
|
132
|
+
a.abort("clear"), t.current && L(t.current, p), s.current && (s.current.disconnect(), s.current = null);
|
|
133
133
|
};
|
|
134
|
-
}, [r,
|
|
134
|
+
}, [r, c, p, d, e]), /* @__PURE__ */ P(
|
|
135
135
|
"div",
|
|
136
136
|
{
|
|
137
|
-
"data-rp": `page-${
|
|
138
|
-
style: { width: `${
|
|
137
|
+
"data-rp": `page-${m}-annotationLayer`,
|
|
138
|
+
style: { width: `${e == null ? void 0 : e.width}px`, height: `${e == null ? void 0 : e.height}px` },
|
|
139
139
|
className: q["rp-annotation-layer"],
|
|
140
140
|
ref: t
|
|
141
141
|
}
|
|
142
142
|
);
|
|
143
143
|
};
|
|
144
144
|
export {
|
|
145
|
-
|
|
145
|
+
Jt as AnnotationLayer
|
|
146
146
|
};
|
|
@@ -39,11 +39,16 @@ import "../../contexts/RenderQueueProvider.js";
|
|
|
39
39
|
import "../../utils/Queue.js";
|
|
40
40
|
import "../../utils/renderPage.js";
|
|
41
41
|
import "./TextLayer.js";
|
|
42
|
-
import "../../utils/highlight.js";
|
|
43
|
-
import "../../utils/charators.js";
|
|
44
42
|
import "../../contexts/SearchContext.js";
|
|
45
43
|
import "../../utils/hooks/useSearch.js";
|
|
44
|
+
import "../../utils/highlight.js";
|
|
45
|
+
import "../../utils/charators.js";
|
|
46
|
+
import "../../utils/selectionUtils.js";
|
|
47
|
+
import "../../utils/geometryCache.js";
|
|
46
48
|
import "../../utils/getWordPositionInPage.js";
|
|
49
|
+
import "../../contexts/TextSelectionContext.js";
|
|
50
|
+
import "../../utils/glyphHitTest.js";
|
|
51
|
+
import "../../contexts/SelectionModeContext.js";
|
|
47
52
|
import "./AnnotationLayer.js";
|
|
48
53
|
import "../../contexts/PrintContext.js";
|
|
49
54
|
import "../../utils/hooks/usePrint.js";
|
|
@@ -68,7 +73,7 @@ import "../../contexts/LicenseContext.js";
|
|
|
68
73
|
import "../../utils/hooks/useLicense.js";
|
|
69
74
|
import "../../utils/getElementPositionInPage.js";
|
|
70
75
|
import "../../utils/withRef.js";
|
|
71
|
-
const
|
|
76
|
+
const Et = h(({ widths: m, heights: s }) => {
|
|
72
77
|
const { focusedPage: r, totalPages: n } = l(), a = e(() => {
|
|
73
78
|
const t = [], o = Math.ceil(r / 2) * 2 - 1;
|
|
74
79
|
if (t.push(o), o + 1 <= n) {
|
|
@@ -96,5 +101,5 @@ const kt = h(({ widths: m, heights: s }) => {
|
|
|
96
101
|
return /* @__PURE__ */ u("div", { style: { width: g, position: "relative" }, children: a.map((t, o) => /* @__PURE__ */ u(f, { style: p[o], pageNumber: t }, t)) });
|
|
97
102
|
});
|
|
98
103
|
export {
|
|
99
|
-
|
|
104
|
+
Et as DualPage
|
|
100
105
|
};
|
|
@@ -39,11 +39,16 @@ import "../../contexts/RenderQueueProvider.js";
|
|
|
39
39
|
import "../../utils/Queue.js";
|
|
40
40
|
import "../../utils/renderPage.js";
|
|
41
41
|
import "./TextLayer.js";
|
|
42
|
-
import "../../utils/highlight.js";
|
|
43
|
-
import "../../utils/charators.js";
|
|
44
42
|
import "../../contexts/SearchContext.js";
|
|
45
43
|
import "../../utils/hooks/useSearch.js";
|
|
44
|
+
import "../../utils/highlight.js";
|
|
45
|
+
import "../../utils/charators.js";
|
|
46
|
+
import "../../utils/selectionUtils.js";
|
|
47
|
+
import "../../utils/geometryCache.js";
|
|
46
48
|
import "../../utils/getWordPositionInPage.js";
|
|
49
|
+
import "../../contexts/TextSelectionContext.js";
|
|
50
|
+
import "../../utils/glyphHitTest.js";
|
|
51
|
+
import "../../contexts/SelectionModeContext.js";
|
|
47
52
|
import "./AnnotationLayer.js";
|
|
48
53
|
import "../../contexts/PrintContext.js";
|
|
49
54
|
import "../../utils/hooks/usePrint.js";
|
|
@@ -68,7 +73,7 @@ import "../../contexts/LicenseContext.js";
|
|
|
68
73
|
import "../../utils/hooks/useLicense.js";
|
|
69
74
|
import "../../utils/getElementPositionInPage.js";
|
|
70
75
|
import "../../utils/withRef.js";
|
|
71
|
-
const
|
|
76
|
+
const Qt = b(({ widths: o, heights: a }) => {
|
|
72
77
|
const { focusedPage: l, totalPages: m } = y(), i = f(() => {
|
|
73
78
|
const t = [];
|
|
74
79
|
if (l === 1)
|
|
@@ -128,5 +133,5 @@ const Ft = b(({ widths: o, heights: a }) => {
|
|
|
128
133
|
return /* @__PURE__ */ h("div", { style: W, children: i.map((t, r) => /* @__PURE__ */ h(I, { style: x[r], pageNumber: t }, t)) });
|
|
129
134
|
});
|
|
130
135
|
export {
|
|
131
|
-
|
|
136
|
+
Qt as DualPageWithCover
|
|
132
137
|
};
|
|
@@ -44,11 +44,16 @@ import "../../utils/hooks/useDebounce.js";
|
|
|
44
44
|
import "../../contexts/SmoothScrollContext.js";
|
|
45
45
|
import "../../utils/getScrollDistance.js";
|
|
46
46
|
import "../../utils/calculatePage.js";
|
|
47
|
-
import "../../utils/highlight.js";
|
|
48
|
-
import "../../utils/charators.js";
|
|
49
47
|
import "../../contexts/SearchContext.js";
|
|
50
48
|
import "../../utils/hooks/useSearch.js";
|
|
49
|
+
import "../../utils/highlight.js";
|
|
50
|
+
import "../../utils/charators.js";
|
|
51
|
+
import "../../utils/selectionUtils.js";
|
|
52
|
+
import "../../utils/geometryCache.js";
|
|
51
53
|
import "../../utils/getWordPositionInPage.js";
|
|
54
|
+
import "../../contexts/TextSelectionContext.js";
|
|
55
|
+
import "../../utils/glyphHitTest.js";
|
|
56
|
+
import "../../contexts/SelectionModeContext.js";
|
|
52
57
|
import "../../contexts/PrintContext.js";
|
|
53
58
|
import "../../utils/hooks/usePrint.js";
|
|
54
59
|
import "../../utils/link_service.js";
|
|
@@ -71,7 +76,7 @@ const a = {
|
|
|
71
76
|
"rp-page-wrapper": "_rp-page-wrapper_ii91u_1",
|
|
72
77
|
"rp-page": "_rp-page_ii91u_1",
|
|
73
78
|
"rp-loader-wrapper": "_rp-loader-wrapper_ii91u_15"
|
|
74
|
-
},
|
|
79
|
+
}, ar = O((h, w) => {
|
|
75
80
|
const { pageNumber: t, style: x, ...L } = h, { pages: p } = j(), { pageRotate: s } = D(), { textLayer: $ } = T(), { currentZoom: m } = Z(), { LoaderImageComponent: n } = k(), i = g(p.get(t)), [v, c] = l(!1), u = g(null), [r, y] = l({
|
|
76
81
|
width: 0,
|
|
77
82
|
height: 0
|
|
@@ -140,5 +145,5 @@ const a = {
|
|
|
140
145
|
);
|
|
141
146
|
});
|
|
142
147
|
export {
|
|
143
|
-
|
|
148
|
+
ar as RPPage
|
|
144
149
|
};
|
|
@@ -39,11 +39,16 @@ import "../../contexts/RenderQueueProvider.js";
|
|
|
39
39
|
import "../../utils/Queue.js";
|
|
40
40
|
import "../../utils/renderPage.js";
|
|
41
41
|
import "./TextLayer.js";
|
|
42
|
-
import "../../utils/highlight.js";
|
|
43
|
-
import "../../utils/charators.js";
|
|
44
42
|
import "../../contexts/SearchContext.js";
|
|
45
43
|
import "../../utils/hooks/useSearch.js";
|
|
44
|
+
import "../../utils/highlight.js";
|
|
45
|
+
import "../../utils/charators.js";
|
|
46
|
+
import "../../utils/selectionUtils.js";
|
|
47
|
+
import "../../utils/geometryCache.js";
|
|
46
48
|
import "../../utils/getWordPositionInPage.js";
|
|
49
|
+
import "../../contexts/TextSelectionContext.js";
|
|
50
|
+
import "../../utils/glyphHitTest.js";
|
|
51
|
+
import "../../contexts/SelectionModeContext.js";
|
|
47
52
|
import "./AnnotationLayer.js";
|
|
48
53
|
import "../../contexts/PrintContext.js";
|
|
49
54
|
import "../../utils/hooks/usePrint.js";
|
|
@@ -68,7 +73,7 @@ import "../../contexts/LicenseContext.js";
|
|
|
68
73
|
import "../../utils/hooks/useLicense.js";
|
|
69
74
|
import "../../utils/getElementPositionInPage.js";
|
|
70
75
|
import "../../utils/withRef.js";
|
|
71
|
-
const
|
|
76
|
+
const Ao = ({ widths: t, heights: r }) => {
|
|
72
77
|
const { focusedPage: o } = n(), p = m(() => ({
|
|
73
78
|
position: "absolute",
|
|
74
79
|
width: t(o - 1),
|
|
@@ -86,5 +91,5 @@ const So = ({ widths: t, heights: r }) => {
|
|
|
86
91
|
);
|
|
87
92
|
};
|
|
88
93
|
export {
|
|
89
|
-
|
|
94
|
+
Ao as SinglePage
|
|
90
95
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useDocumentContext as
|
|
4
|
-
import { useHighlightContext as
|
|
5
|
-
import { normalizeSingleKeyword as
|
|
6
|
-
import { isMatchEntireWord as
|
|
1
|
+
import { jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import { useState as $, useEffect as k, useMemo as y } from "react";
|
|
3
|
+
import { useDocumentContext as _ } from "../../contexts/RPDocumentContext.js";
|
|
4
|
+
import { useHighlightContext as L } from "../../contexts/HighlightContext.js";
|
|
5
|
+
import { normalizeSingleKeyword as M } from "./searchHighlight.js";
|
|
6
|
+
import { isMatchEntireWord as T } from "../../utils/highlight.js";
|
|
7
|
+
import { geometryCache as w } from "../../utils/geometryCache.js";
|
|
8
|
+
import { rectsForRange as G } from "../../utils/selectionUtils.js";
|
|
7
9
|
import "../../utils/hooks/useLoadPdf.js";
|
|
8
10
|
import "@pdf-viewer/pdfium";
|
|
9
11
|
import "@pdf-viewer/pdfium/compat";
|
|
@@ -19,181 +21,86 @@ import "../../utils/formatFileSize.js";
|
|
|
19
21
|
import "../../utils/hooks/useHighlight.js";
|
|
20
22
|
import "../../utils/charators.js";
|
|
21
23
|
import "../../utils/const.js";
|
|
22
|
-
const
|
|
23
|
-
"rp-text-highlight": "_rp-text-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (!e || !C.current)
|
|
32
|
-
return;
|
|
33
|
-
const n = await e.page.getTextContent();
|
|
34
|
-
v(n);
|
|
35
|
-
})();
|
|
36
|
-
}, [R, w]);
|
|
37
|
-
const j = Q(() => p ? p.map((t) => {
|
|
38
|
-
var e, n;
|
|
39
|
-
return {
|
|
40
|
-
...Y(t.keyword, (e = t.options) == null ? void 0 : e.matchCase, (n = t.options) == null ? void 0 : n.wholeWords),
|
|
41
|
-
color: t.highlightColor
|
|
42
|
-
};
|
|
43
|
-
}) : [], [p]);
|
|
44
|
-
function D(t, e) {
|
|
45
|
-
if (!t)
|
|
46
|
-
return;
|
|
47
|
-
const n = `[data-rp="page-${e}-textLayer"]`;
|
|
48
|
-
return new Promise((r) => {
|
|
49
|
-
const s = t.querySelector(n);
|
|
50
|
-
if (s) {
|
|
51
|
-
r(s);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
new MutationObserver((i, c) => {
|
|
55
|
-
const l = t.querySelector(n);
|
|
56
|
-
l && (r(l), c.disconnect());
|
|
57
|
-
}).observe(t, { childList: !0, subtree: !0 });
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function K(t) {
|
|
61
|
-
return new Promise((e) => {
|
|
62
|
-
const n = t.querySelectorAll(
|
|
63
|
-
'[data-rp="rp-text-layer-text"]'
|
|
64
|
-
);
|
|
65
|
-
if (n.length) {
|
|
66
|
-
e(Array.from(n));
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
new MutationObserver((s, o) => {
|
|
70
|
-
const i = t.querySelectorAll(
|
|
71
|
-
".rp-text-layer-text"
|
|
72
|
-
);
|
|
73
|
-
i.length && (e(Array.from(i)), o.disconnect());
|
|
74
|
-
}).observe(t, { childList: !0, subtree: !0 });
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
const W = (t, e, n, r) => {
|
|
78
|
-
var I;
|
|
79
|
-
const s = document.createRange(), o = n.firstChild;
|
|
80
|
-
if (!o || o.nodeType !== Node.TEXT_NODE)
|
|
81
|
-
return null;
|
|
82
|
-
const i = ((I = o.textContent) == null ? void 0 : I.length) ?? 0, c = r[0].charIdxInSpan, l = r.length === 1 ? c : r[r.length - 1].charIdxInSpan;
|
|
83
|
-
if (c > i || l + 1 > i)
|
|
84
|
-
return null;
|
|
85
|
-
s.setStart(o, c), s.setEnd(o, l + 1);
|
|
86
|
-
const h = document.createElement("span");
|
|
87
|
-
h.style.width = "auto", s.surroundContents(h);
|
|
88
|
-
const a = h.getBoundingClientRect(), f = t.getBoundingClientRect(), m = f.height, d = f.width, x = 100 * (a.left - f.left) / d, E = 100 * (a.top - f.top) / m, S = 100 * a.height / m, g = 100 * a.width / d;
|
|
89
|
-
return tt(h), {
|
|
90
|
-
keywordStr: e,
|
|
91
|
-
left: x,
|
|
92
|
-
top: E,
|
|
93
|
-
height: S,
|
|
94
|
-
width: g,
|
|
95
|
-
pageHeight: m,
|
|
96
|
-
pageWidth: d
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
async function z(t, e) {
|
|
100
|
-
const n = await D(P, t);
|
|
101
|
-
if (!n)
|
|
24
|
+
const C = {
|
|
25
|
+
"rp-text-highlight-layer": "_rp-text-highlight-layer_1gqf0_1",
|
|
26
|
+
"rp-text-highlight": "_rp-text-highlight_1gqf0_1"
|
|
27
|
+
}, Z = ({ pageNumber: n, viewport: p }) => {
|
|
28
|
+
const i = n - 1, { pages: h } = _(), { highlightKeywords: s } = L(), [r, m] = $(null);
|
|
29
|
+
k(() => {
|
|
30
|
+
const e = w.get(i);
|
|
31
|
+
if (e) {
|
|
32
|
+
m(e);
|
|
102
33
|
return;
|
|
103
|
-
const r = await K(n);
|
|
104
|
-
if (r.length) {
|
|
105
|
-
const s = r.map((i) => i.tagName === "BR" ? " " : i.textContent).reduce(
|
|
106
|
-
(i, c, l) => i.concat(
|
|
107
|
-
c.split("").map((h, a) => ({
|
|
108
|
-
char: h,
|
|
109
|
-
charIdxInSpan: a,
|
|
110
|
-
spanIdx: l
|
|
111
|
-
}))
|
|
112
|
-
),
|
|
113
|
-
[
|
|
114
|
-
{
|
|
115
|
-
char: "",
|
|
116
|
-
charIdxInSpan: 0,
|
|
117
|
-
spanIdx: 0
|
|
118
|
-
}
|
|
119
|
-
]
|
|
120
|
-
).slice(1), o = B(n, e, r, s);
|
|
121
|
-
b(o);
|
|
122
34
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
35
|
+
const o = h.get(n);
|
|
36
|
+
if (!o)
|
|
37
|
+
return;
|
|
38
|
+
const t = o.page.getViewport({ scale: (p.width > 0, 1) }), g = o.page.getPageGeometry(t);
|
|
39
|
+
w.set(i, g), m(g);
|
|
40
|
+
}, [h, n, i, p]);
|
|
41
|
+
const c = y(() => s ? s.map((e) => {
|
|
42
|
+
var o, t;
|
|
43
|
+
return {
|
|
44
|
+
...M(e.keyword, (o = e.options) == null ? void 0 : o.matchCase, (t = e.options) == null ? void 0 : t.wholeWords),
|
|
45
|
+
color: e.highlightColor
|
|
46
|
+
};
|
|
47
|
+
}) : [], [s]), a = y(() => {
|
|
48
|
+
if (!r || !c.length)
|
|
127
49
|
return [];
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
for (; (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const I = g.indexes.reduce(
|
|
149
|
-
(u, y) => (u[y.spanIdx] = (u[y.spanIdx] || []).concat([y]), u),
|
|
150
|
-
{}
|
|
151
|
-
);
|
|
152
|
-
for (const u of Object.values(I))
|
|
153
|
-
if (u.length !== 1 || u[0].char.trim() !== "") {
|
|
154
|
-
const y = u, F = n[y[0].spanIdx], T = W(
|
|
155
|
-
t,
|
|
156
|
-
m,
|
|
157
|
-
F,
|
|
158
|
-
y
|
|
159
|
-
);
|
|
160
|
-
if (T) {
|
|
161
|
-
const { left: X, top: G } = T;
|
|
162
|
-
if (o.find((L) => L.left === X && L.top === G))
|
|
163
|
-
continue;
|
|
164
|
-
o.push({ ...T, highlightColor: g.color });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}), o.sort(Z), o;
|
|
169
|
-
};
|
|
170
|
-
return H(() => {
|
|
171
|
-
(async () => {
|
|
172
|
-
if (!p || p.length === 0) {
|
|
173
|
-
b([]);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
try {
|
|
177
|
-
await z(w, p);
|
|
178
|
-
} catch (e) {
|
|
179
|
-
console.error(e);
|
|
180
|
-
}
|
|
181
|
-
})();
|
|
182
|
-
}, [M, p, w, $, O]), /* @__PURE__ */ k(J, { children: /* @__PURE__ */ k("div", { ref: C, "data-rp": `page-${w}-textHighlightLayer`, children: _.map((t, e) => /* @__PURE__ */ k(
|
|
183
|
-
"div",
|
|
184
|
-
{
|
|
185
|
-
className: nt["rp-text-highlight"],
|
|
186
|
-
style: {
|
|
187
|
-
top: `${t.top}%`,
|
|
188
|
-
left: `${t.left}%`,
|
|
189
|
-
width: `${t.width}%`,
|
|
190
|
-
height: `${t.height}%`,
|
|
191
|
-
backgroundColor: t.highlightColor
|
|
50
|
+
if (r.totalCharCount === 0)
|
|
51
|
+
return [];
|
|
52
|
+
const e = r.runs.map((t) => t.text).join(""), o = [];
|
|
53
|
+
for (const t of c) {
|
|
54
|
+
if (!t.keyword.trim())
|
|
55
|
+
continue;
|
|
56
|
+
const g = t.regExp.flags.indexOf("g") === -1 ? new RegExp(t.regExp, `${t.regExp.flags}g`) : t.regExp;
|
|
57
|
+
let l;
|
|
58
|
+
for (; (l = g.exec(e)) !== null; ) {
|
|
59
|
+
if (t.wholeWords && !T(e, l.index, l[0].length))
|
|
60
|
+
continue;
|
|
61
|
+
const x = E(r, l.index), f = E(r, l.index + l[0].length - 1);
|
|
62
|
+
if (x >= 0 && f >= 0) {
|
|
63
|
+
const u = G(r, x, f);
|
|
64
|
+
u.length > 0 && o.push({
|
|
65
|
+
rects: u,
|
|
66
|
+
color: t.color ?? "rgba(255, 235, 59, 0.4)",
|
|
67
|
+
keyword: t.keyword
|
|
68
|
+
});
|
|
69
|
+
}
|
|
192
70
|
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
71
|
+
}
|
|
72
|
+
return o;
|
|
73
|
+
}, [r, c]);
|
|
74
|
+
return a.length === 0 ? null : /* @__PURE__ */ d("div", { "data-rp": `page-${n}-textHighlightLayer`, className: C["rp-text-highlight-layer"], children: a.map(
|
|
75
|
+
(e, o) => e.rects.map((t, g) => /* @__PURE__ */ d(
|
|
76
|
+
"div",
|
|
77
|
+
{
|
|
78
|
+
className: C["rp-text-highlight"],
|
|
79
|
+
style: {
|
|
80
|
+
position: "absolute",
|
|
81
|
+
left: `${t.x}px`,
|
|
82
|
+
top: `${t.y}px`,
|
|
83
|
+
width: `${t.width}px`,
|
|
84
|
+
height: `${t.height}px`,
|
|
85
|
+
backgroundColor: e.color
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
`${o}-${g}`
|
|
89
|
+
))
|
|
90
|
+
) });
|
|
196
91
|
};
|
|
92
|
+
function E(n, p) {
|
|
93
|
+
let i = 0, h = 0;
|
|
94
|
+
for (const s of n.runs) {
|
|
95
|
+
const r = s.text.length, m = s.glyphs.length;
|
|
96
|
+
if (p < i + r) {
|
|
97
|
+
const c = p - i;
|
|
98
|
+
return h + Math.min(c, m - 1);
|
|
99
|
+
}
|
|
100
|
+
i += r, h += m;
|
|
101
|
+
}
|
|
102
|
+
return Math.max(0, h - 1);
|
|
103
|
+
}
|
|
197
104
|
export {
|
|
198
|
-
|
|
105
|
+
Z as TextHighlightLayer
|
|
199
106
|
};
|