@react-pdf-kit/viewer 2.9.2 → 2.10.0-beta.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/dist/AnnotationLayer-lagF0zYo.js +116 -0
- package/dist/{Button-DBu3SaMk.js → Button-B_yuVBQ_.js} +1 -1
- package/dist/{Checkbox-CSIEUyO8.js → Checkbox-BVARFFLh.js} +2 -2
- package/dist/{Combination-11kyhTGt.js → Combination-ILTe_xfZ.js} +2 -2
- package/dist/{Container-BuamPhw4.js → Container-CY9sCoDd.js} +1 -1
- package/dist/{DocumentDialog-cRr9sSSH.js → DocumentDialog-CYKsfOE1.js} +4 -4
- package/dist/{DropDown-CM6xEwZC.js → DropDown-DEnDtOIT.js} +2 -2
- package/dist/{Input-Dpo1Xfxe.js → Input-CVjTHdhy.js} +1 -1
- package/dist/{LoaderIcon-B3ddfd0D.js → LoaderIcon-SD35XFV2.js} +1 -1
- package/dist/{LoadingIndicator-0E8WHnSN.js → LoadingIndicator-SLpllUQ1.js} +1 -1
- package/dist/{MenuItem-lItnKNd5.js → MenuItem-DEd62cAM.js} +2 -2
- package/dist/{MenuSeparator-CaFxd8b5.js → MenuSeparator-BVQWugN3.js} +1 -1
- package/dist/{PasswordModal-CxHFn0pB.js → PasswordModal-BCjtXHN4.js} +1 -1
- package/dist/{RPDropFileZone-Bq1bzWmO.js → RPDropFileZone-lI-AmN-1.js} +3 -3
- package/dist/{RPPages-BZwgKgfJ.js → RPPages-BVSFaPUT.js} +2 -2
- package/dist/{RPTooltip-QWwWh4HW.js → RPTooltip-KdCUxOyM.js} +3 -3
- package/dist/TextHighlightLayer-BMhYl-9Q.js +162 -0
- package/dist/{TextLayer-Bp1CDIIa.js → TextLayer-CUtANGvL.js} +2 -2
- package/dist/{Thumbnail-BXMk0OWF.js → Thumbnail-BDGp0xdd.js} +3 -3
- package/dist/{Thumbnails-BIuN8LZ8.js → Thumbnails-C6maORBh.js} +1 -1
- package/dist/XfaLayer.module-w4FOd2dm.js +4 -0
- package/dist/assets/XfaLayer.css +1 -0
- package/dist/assets/style.js +1 -1
- package/dist/components/RPController.js +1 -1
- package/dist/components/RPDropFileZone.js +1 -1
- package/dist/components/RPPages.js +1 -1
- package/dist/components/RPProvider.js +1 -1
- package/dist/components/icons/DarkPdfIcon.js +1 -1
- package/dist/components/icons/LightPdfIcon.js +1 -1
- package/dist/components/icons/LoaderIcon.js +1 -1
- package/dist/components/layout/Container.js +1 -1
- package/dist/components/layout/LayoutContainer.js +2 -2
- package/dist/components/layout/LayoutWrapper.js +1 -1
- package/dist/components/layout/RPDefaultLayout.js +5 -5
- package/dist/components/layout/RPLayout.js +5 -5
- package/dist/components/layout/SkipLink.js +1 -1
- package/dist/components/layout/WrapperLayout.js +1 -1
- package/dist/components/layout/sidebar/CustomThumbnailElement.js +1 -1
- package/dist/components/layout/sidebar/RPSidebar.js +4 -4
- package/dist/components/layout/sidebar/RPSplitter.js +1 -1
- package/dist/components/layout/sidebar/Thumbnail.js +1 -1
- package/dist/components/layout/sidebar/Thumbnails.js +1 -1
- package/dist/components/layout/toolbar/DarkModeTool.js +2 -2
- package/dist/components/layout/toolbar/DocumentDialog.js +1 -1
- package/dist/components/layout/toolbar/DocumentProperties.js +3 -3
- package/dist/components/layout/toolbar/FileDownloadTool.js +3 -3
- package/dist/components/layout/toolbar/FileUploadTool.js +3 -3
- package/dist/components/layout/toolbar/FullScreenTool.js +3 -3
- package/dist/components/layout/toolbar/MenuItem.js +1 -1
- package/dist/components/layout/toolbar/MenuSeparator.js +1 -1
- package/dist/components/layout/toolbar/MostPageTool.js +5 -5
- package/dist/components/layout/toolbar/OtherTool.js +7 -7
- package/dist/components/layout/toolbar/Paginate.js +4 -4
- package/dist/components/layout/toolbar/PrintTool.js +3 -3
- package/dist/components/layout/toolbar/PropertyItem.js +1 -1
- package/dist/components/layout/toolbar/RPMenuItem.js +3 -3
- package/dist/components/layout/toolbar/RPMoreOptions.js +7 -7
- package/dist/components/layout/toolbar/RPToolbar.js +2 -2
- package/dist/components/layout/toolbar/RotateTool.js +5 -5
- package/dist/components/layout/toolbar/ScrollModeTool.js +3 -3
- package/dist/components/layout/toolbar/SearchCloseButton.js +3 -3
- package/dist/components/layout/toolbar/SearchResultNavigator.js +3 -3
- package/dist/components/layout/toolbar/SearchTool.js +7 -7
- package/dist/components/layout/toolbar/SelectionModeTool.js +4 -4
- package/dist/components/layout/toolbar/ThumbnailTool.js +2 -2
- package/dist/components/layout/toolbar/ToolbarCustom.js +4 -4
- package/dist/components/layout/toolbar/ToolbarDefault.js +4 -4
- package/dist/components/layout/toolbar/ViewModeTool.js +4 -4
- package/dist/components/layout/toolbar/ZoomTool.js +8 -8
- package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +3 -3
- package/dist/components/layout/toolbar/tools/DualPageTool.js +2 -2
- package/dist/components/layout/toolbar/tools/DualPageWithCoverTool.js +1 -1
- package/dist/components/layout/toolbar/tools/FileDownloadTool.js +2 -2
- package/dist/components/layout/toolbar/tools/FileUploadTool.js +2 -2
- package/dist/components/layout/toolbar/tools/FirstPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/FullScreenTool.js +2 -2
- package/dist/components/layout/toolbar/tools/HorizontalScrollingTool.js +2 -2
- package/dist/components/layout/toolbar/tools/InputPageTool.js +3 -3
- package/dist/components/layout/toolbar/tools/LastPageTool.js +1 -1
- package/dist/components/layout/toolbar/tools/NextPageTool.js +2 -2
- package/dist/components/layout/toolbar/tools/PageScrollingTool.js +2 -2
- package/dist/components/layout/toolbar/tools/PreviousPageTool.js +2 -2
- package/dist/components/layout/toolbar/tools/PrintTool.js +2 -2
- package/dist/components/layout/toolbar/tools/RotateClockwiseTool.js +2 -2
- package/dist/components/layout/toolbar/tools/RotateCounterclockwiseTool.js +3 -3
- package/dist/components/layout/toolbar/tools/SelectionModeSwitcherTool.js +2 -2
- package/dist/components/layout/toolbar/tools/SinglePageTool.js +2 -2
- package/dist/components/layout/toolbar/tools/ThemeSwitcherTool.js +2 -2
- package/dist/components/layout/toolbar/tools/ThumbnailTool.js +2 -2
- package/dist/components/layout/toolbar/tools/VerticalScrollingTool.js +2 -2
- package/dist/components/layout/toolbar/tools/ZoomInTool.js +2 -2
- package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +7 -7
- package/dist/components/layout/toolbar/tools/ZoomOutTool.js +2 -2
- package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +1 -1
- 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 +5 -5
- package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +2 -2
- package/dist/components/layout/toolbar/tools/more-options/RotateTool.js +5 -5
- package/dist/components/layout/toolbar/tools/more-options/ScrollModeTool.js +3 -3
- package/dist/components/layout/toolbar/tools/more-options/SelectionModeTool.js +4 -4
- package/dist/components/layout/toolbar/tools/more-options/ViewModeTool.js +4 -4
- package/dist/components/page/AnnotationLayer.js +1 -1
- package/dist/components/page/CanvasLayer.js +1 -1
- package/dist/components/page/RPPage.js +54 -52
- package/dist/components/page/TextHighlightLayer.js +1 -1
- package/dist/components/page/TextLayer.js +1 -1
- package/dist/components/page/XfaLayer.js +49 -0
- package/dist/components/ui/Button.js +1 -1
- package/dist/components/ui/Checkbox.js +1 -1
- package/dist/components/ui/DropDown.js +1 -1
- package/dist/components/ui/Input.js +1 -1
- package/dist/components/ui/LoadingIndicator.js +1 -1
- package/dist/components/ui/PasswordModal.js +1 -1
- package/dist/components/ui/RPTooltip.js +1 -1
- package/dist/contexts/LoaderContext.js +1 -1
- package/dist/contexts/RenderQueueProvider.js +46 -43
- package/dist/{dist-CNbFpoT1.js → dist-BgFO-PWQ.js} +1 -1
- package/dist/{dist-VbpVNBs6.js → dist-CtoH1CMU.js} +4 -4
- package/dist/{dist-B2hwhF6G.js → dist-D6Fk7CTS.js} +3 -3
- package/dist/{dist-BfuBBQ14.js → dist-SBjhcXgf.js} +1 -1
- package/dist/icons.js +3 -3
- package/dist/{main-DCzVrq0G.js → main-DrddwgsH.js} +3 -3
- package/dist/main.js +4 -4
- package/dist/{style-dcYpxEeL.js → style-DW_uCDpt.js} +1 -1
- package/dist/types/components/page/XfaLayer.d.ts +6 -0
- package/dist/types/utils/pdfOperationTracker.d.ts +20 -0
- package/dist/utils/annotations.js +72 -71
- package/dist/utils/hooks/useFileDownload.js +10 -6
- package/dist/utils/hooks/useHighlight.js +43 -42
- package/dist/utils/hooks/useLicense.js +2 -2
- package/dist/utils/hooks/useLoadPdf.js +66 -64
- package/dist/utils/hooks/usePdfProperties.js +33 -32
- package/dist/utils/hooks/usePrint.js +123 -88
- package/dist/utils/hooks/useSearch.js +84 -83
- package/dist/utils/hooks/useWatermark.js +1 -1
- package/dist/utils/injectPrintCSS.js +1 -1
- package/dist/utils/link_service.js +33 -17
- package/dist/utils/pdfOperationTracker.js +27 -4
- package/package.json +1 -1
- package/dist/AnnotationLayer-oDu2B4X1.js +0 -114
- package/dist/TextHighlightLayer-3vIZbRyL.js +0 -157
- /package/dist/{CanvasLayer-C3gb8EXu.js → CanvasLayer-DkVH-tX2.js} +0 -0
- /package/dist/{CustomThumbnailElement-C2quEICO.js → CustomThumbnailElement-BxTSbzpP.js} +0 -0
- /package/dist/{DarkPdfIcon-B5ehd9CV.js → DarkPdfIcon-2aDGWxuA.js} +0 -0
- /package/dist/{LightPdfIcon-DL8MYtWQ.js → LightPdfIcon-LatCGY0T.js} +0 -0
- /package/dist/{MostPageTool.module-BRVv-sGz.js → MostPageTool.module-BP2BMoK8.js} +0 -0
- /package/dist/{OtherTool.module-BQY9Nfqz.js → OtherTool.module-CMbI70sn.js} +0 -0
- /package/dist/{Paginate.module-DhE7N8AA.js → Paginate.module-DxXyYoYp.js} +0 -0
- /package/dist/{PropertyItem-evJWWmWZ.js → PropertyItem-CmRC2e5Z.js} +0 -0
- /package/dist/{RPLayout.module-BH5r8dDc.js → RPLayout.module-DLX1UwA3.js} +0 -0
- /package/dist/{RPSplitter-C63X9M8w.js → RPSplitter-DGnDuwsT.js} +0 -0
- /package/dist/{RPToolbar.module-BwqWLviy.js → RPToolbar.module-ODOa9FwW.js} +0 -0
- /package/dist/{RotateTool.module-DH5yWbvM.js → RotateTool.module-BHFeo1yn.js} +0 -0
- /package/dist/{SearchTool.module-DY8Ucfb_.js → SearchTool.module-BQDBENlo.js} +0 -0
- /package/dist/{SkipLink-Dj83gZdk.js → SkipLink-mnqFQj0O.js} +0 -0
- /package/dist/{ToolbarLayout.module-Zo715dbb.js → ToolbarLayout.module-BC9eQ9LN.js} +0 -0
- /package/dist/{WrapperLayout-Dcd9l9xH.js → WrapperLayout-NjsBnUaz.js} +0 -0
- /package/dist/{ZoomTool.module-BrIPy8pO.js → ZoomTool.module-DO-r2IDy.js} +0 -0
- /package/dist/{clsx-DSGuh5YW.js → clsx-BD2qMUU1.js} +0 -0
- /package/dist/{dist-CgoP608h.js → dist-DjD1zIE0.js} +0 -0
- /package/dist/{lib-CSInlR9T.js → lib-DTkzWIMS.js} +0 -0
- /package/dist/{useWatermark-CvAAf66v.js → useWatermark-DlRNcg9p.js} +0 -0
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
//#region lib/utils/pdfOperationTracker.ts
|
|
2
|
-
var e = /* @__PURE__ */ new WeakMap()
|
|
3
|
-
|
|
2
|
+
var e = /* @__PURE__ */ new WeakMap(), t = /* @__PURE__ */ new WeakSet(), n = class extends Error {
|
|
3
|
+
constructor() {
|
|
4
|
+
super("PDF document has been destroyed"), this.name = "PdfDocumentDestroyedError";
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
function r(e) {
|
|
8
|
+
return e instanceof n;
|
|
9
|
+
}
|
|
10
|
+
function i(e) {
|
|
11
|
+
t.add(e);
|
|
12
|
+
}
|
|
13
|
+
function a(e) {
|
|
14
|
+
return e ? t.has(e) ? !0 : e.loadingTask?.destroyed === !0 : !1;
|
|
15
|
+
}
|
|
16
|
+
function o(t, n) {
|
|
4
17
|
if (!t) return n;
|
|
5
18
|
let r = e.get(t);
|
|
6
19
|
r || (r = /* @__PURE__ */ new Set(), e.set(t, r));
|
|
@@ -9,9 +22,19 @@ function t(t, n) {
|
|
|
9
22
|
r?.delete(i);
|
|
10
23
|
}), n;
|
|
11
24
|
}
|
|
12
|
-
function
|
|
25
|
+
function s(e, t) {
|
|
26
|
+
if (a(e)) return Promise.reject(new n());
|
|
27
|
+
let r;
|
|
28
|
+
try {
|
|
29
|
+
r = t();
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return Promise.reject(e);
|
|
32
|
+
}
|
|
33
|
+
return o(e, r);
|
|
34
|
+
}
|
|
35
|
+
function c(t) {
|
|
13
36
|
let n = e.get(t);
|
|
14
37
|
return !n || n.size === 0 ? Promise.resolve() : Promise.allSettled(Array.from(n)).then(() => void 0);
|
|
15
38
|
}
|
|
16
39
|
//#endregion
|
|
17
|
-
export {
|
|
40
|
+
export { n as PdfDocumentDestroyedError, a as isPdfDestroyed, r as isPdfDocumentDestroyedError, i as markPdfDestroying, s as runPdfOperation, o as trackPdfOperation, c as waitForPdfOperations };
|
package/package.json
CHANGED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { AnnotationSubType as e } from "./utils/types.js";
|
|
2
|
-
import { trackPdfOperation as t } from "./utils/pdfOperationTracker.js";
|
|
3
|
-
import { useDocumentContext as n } from "./contexts/RPDocumentContext.js";
|
|
4
|
-
import { useInitialStateContext as r } from "./contexts/InitialStateContext.js";
|
|
5
|
-
import { useScrollModeContext as i } from "./contexts/ScrollModeContext.js";
|
|
6
|
-
import { r as a } from "./PaginationContext-DIzsZhFd.js";
|
|
7
|
-
import { usePrintContext as o } from "./contexts/PrintContext.js";
|
|
8
|
-
import { SimpleLinkService as s } from "./utils/link_service.js";
|
|
9
|
-
import { annotationEventsHandler as c, bindLayerEvents as l, enhanceLinkAccessibility as u, fixTabIndexAccessibility as d, handleAnnotationWidget as f, insertDateText as p, unbindLayerEvents as m } from "./utils/annotations.js";
|
|
10
|
-
import { useFileDownload as h } from "./utils/hooks/useFileDownload.js";
|
|
11
|
-
import { useCallback as g, useEffect as _, useMemo as v, useRef as y, useState as b } from "react";
|
|
12
|
-
import { AnnotationLayer as x } from "pdfjs-dist";
|
|
13
|
-
import { jsx as S } from "react/jsx-runtime";
|
|
14
|
-
import './assets/AnnotationLayer.css';//#region lib/components/page/AnnotationLayer.module.css
|
|
15
|
-
var C = { "rp-annotation-layer": "_rp-annotation-layer_foiun_1" }, w = "https://unpkg.com/pdfjs-dist@4.4.168/web/images/", T = (T) => {
|
|
16
|
-
let { pageNumber: E } = T, D = y(null), { pages: O, pdf: k } = n(), { interactiveForm: A } = r(), j = y(), [M, N] = b(), { goToPage: P } = a(), { scrollMode: F } = i(), { print: I } = o(), { download: L } = h(), R = y(null), z = v(() => O.get(E), [O, E]), B = v(() => z?.page.getViewport(), [z]);
|
|
17
|
-
_(() => {
|
|
18
|
-
j.current &&= (j.current.div.replaceChildren(), void 0);
|
|
19
|
-
}, [k]), _(() => {
|
|
20
|
-
z && t(k, z.page.getAnnotations()).then((e) => {
|
|
21
|
-
j.current = void 0, N(e), D.current && (D.current.innerText = "");
|
|
22
|
-
});
|
|
23
|
-
}, [z]);
|
|
24
|
-
let V = g((e) => {
|
|
25
|
-
!M || !k || (p(D.current), c(e, k, M).then((e) => {
|
|
26
|
-
e?.data?.action === "Print" ? I() : e?.data?.action === "SaveAs" && L();
|
|
27
|
-
}));
|
|
28
|
-
}, [
|
|
29
|
-
k,
|
|
30
|
-
M,
|
|
31
|
-
F,
|
|
32
|
-
I,
|
|
33
|
-
L
|
|
34
|
-
]);
|
|
35
|
-
return _(() => {
|
|
36
|
-
if (!z || !M) return;
|
|
37
|
-
let t = z.page.getViewport();
|
|
38
|
-
if (j.current) {
|
|
39
|
-
j.current.update({ viewport: t.clone({ dontFlip: !0 }) });
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
let n = /* @__PURE__ */ new Map([]);
|
|
43
|
-
for (let r of M) {
|
|
44
|
-
let { annotationType: i } = r;
|
|
45
|
-
switch (i) {
|
|
46
|
-
case e.Widget:
|
|
47
|
-
f(r, t, n);
|
|
48
|
-
break;
|
|
49
|
-
default: break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
let r = new AbortController();
|
|
53
|
-
return (async () => {
|
|
54
|
-
j.current &&= (j.current.div.replaceChildren(), void 0), D.current && (D.current.innerText = ""), j.current = new x({
|
|
55
|
-
div: D.current,
|
|
56
|
-
accessibilityManager: void 0,
|
|
57
|
-
annotationCanvasMap: void 0,
|
|
58
|
-
annotationEditorUIManager: void 0,
|
|
59
|
-
structTreeLayer: null,
|
|
60
|
-
page: z.page,
|
|
61
|
-
viewport: t.clone({ dontFlip: !0 }),
|
|
62
|
-
commentManager: void 0,
|
|
63
|
-
linkService: new s(k, P),
|
|
64
|
-
annotationStorage: k?.annotationStorage
|
|
65
|
-
}), D.current && m(D.current, V);
|
|
66
|
-
let e = await k?.hasJSActions(), n = await k?.getFieldObjects();
|
|
67
|
-
if (r.signal.aborted) throw "abort";
|
|
68
|
-
return j.current?.render({
|
|
69
|
-
annotations: M,
|
|
70
|
-
annotationStorage: k?.annotationStorage,
|
|
71
|
-
hasJSActions: e,
|
|
72
|
-
fieldObjects: n,
|
|
73
|
-
div: D.current,
|
|
74
|
-
viewport: t.clone({ dontFlip: !0 }),
|
|
75
|
-
page: z.page,
|
|
76
|
-
imageResourcesPath: w,
|
|
77
|
-
renderForms: A ?? !0,
|
|
78
|
-
linkService: new s(k, P),
|
|
79
|
-
downloadManager: null,
|
|
80
|
-
enableScripting: !1
|
|
81
|
-
});
|
|
82
|
-
})().then(() => {
|
|
83
|
-
D.current && (l(D.current, V), d(D.current), u(D.current), R.current && R.current.disconnect(), R.current = new MutationObserver(() => {
|
|
84
|
-
D.current && (d(D.current), u(D.current));
|
|
85
|
-
}), R.current.observe(D.current, {
|
|
86
|
-
childList: !0,
|
|
87
|
-
subtree: !0,
|
|
88
|
-
attributes: !0,
|
|
89
|
-
attributeFilter: ["tabindex", "href"]
|
|
90
|
-
}));
|
|
91
|
-
}).catch((e) => {
|
|
92
|
-
if (e !== "abort") throw e;
|
|
93
|
-
}).finally(() => {
|
|
94
|
-
j.current = void 0;
|
|
95
|
-
}), () => {
|
|
96
|
-
r.abort("clear"), D.current && m(D.current, V), R.current &&= (R.current.disconnect(), null);
|
|
97
|
-
};
|
|
98
|
-
}, [
|
|
99
|
-
k,
|
|
100
|
-
M,
|
|
101
|
-
V,
|
|
102
|
-
P
|
|
103
|
-
]), /* @__PURE__ */ S("div", {
|
|
104
|
-
"data-rp": `page-${E}-annotationLayer`,
|
|
105
|
-
style: {
|
|
106
|
-
width: `${B?.width}px`,
|
|
107
|
-
height: `${B?.height}px`
|
|
108
|
-
},
|
|
109
|
-
className: C["rp-annotation-layer"],
|
|
110
|
-
ref: D
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
//#endregion
|
|
114
|
-
export { T as t };
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { useDocumentContext as e } from "./contexts/RPDocumentContext.js";
|
|
2
|
-
import { isMatchEntireWord as t } from "./utils/highlight.js";
|
|
3
|
-
import { useHighlightContext as n } from "./contexts/HighlightContext.js";
|
|
4
|
-
import { normalizeSingleKeyword as r, sortHighlightPosition as i, unwrap as a } from "./components/page/searchHighlight.js";
|
|
5
|
-
import { useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
|
|
6
|
-
import { Fragment as u, jsx as d } from "react/jsx-runtime";
|
|
7
|
-
import './assets/TextHighlightLayer.css';//#region lib/components/page/TextHighlightLayer.module.css
|
|
8
|
-
var f = { "rp-text-highlight": "_rp-text-highlight_jdkf8_1" }, p = ({ pageNumber: p, viewport: m }) => {
|
|
9
|
-
let [h, g] = l(), { pages: _ } = e(), { highlightKeywords: v } = n(), y = c(null), [b, x] = l(null), [S, C] = l([]);
|
|
10
|
-
o(() => {
|
|
11
|
-
y.current && x(y.current.parentElement);
|
|
12
|
-
}, [y]), o(() => {
|
|
13
|
-
(async () => {
|
|
14
|
-
let e = _.get(p);
|
|
15
|
-
!e || !y.current || g(await e.page.getTextContent());
|
|
16
|
-
})();
|
|
17
|
-
}, [_, p]);
|
|
18
|
-
let w = s(() => v ? v.map((e) => ({
|
|
19
|
-
...r(e.keyword, e.options?.matchCase, e.options?.wholeWords),
|
|
20
|
-
color: e.highlightColor
|
|
21
|
-
})) : [], [v]);
|
|
22
|
-
function T(e, t) {
|
|
23
|
-
if (!e) return;
|
|
24
|
-
let n = `[data-rp="page-${t}-textLayer"]`;
|
|
25
|
-
return new Promise((t) => {
|
|
26
|
-
let r = e.querySelector(n);
|
|
27
|
-
if (r) {
|
|
28
|
-
t(r);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
new MutationObserver((r, i) => {
|
|
32
|
-
let a = e.querySelector(n);
|
|
33
|
-
a && (t(a), i.disconnect());
|
|
34
|
-
}).observe(e, {
|
|
35
|
-
childList: !0,
|
|
36
|
-
subtree: !0
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function E(e) {
|
|
41
|
-
return new Promise((t) => {
|
|
42
|
-
let n = e.querySelectorAll("[data-rp=\"rp-text-layer-text\"]");
|
|
43
|
-
if (n.length) {
|
|
44
|
-
t(Array.from(n));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
new MutationObserver((n, r) => {
|
|
48
|
-
let i = e.querySelectorAll(".rp-text-layer-text");
|
|
49
|
-
i.length && (t(Array.from(i)), r.disconnect());
|
|
50
|
-
}).observe(e, {
|
|
51
|
-
childList: !0,
|
|
52
|
-
subtree: !0
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
let D = (e, t, n, r) => {
|
|
57
|
-
let i = document.createRange(), o = n.firstChild;
|
|
58
|
-
if (!o || o.nodeType !== Node.TEXT_NODE) return null;
|
|
59
|
-
let s = o.textContent?.length ?? 0, c = r[0].charIdxInSpan, l = r.length === 1 ? c : r[r.length - 1].charIdxInSpan;
|
|
60
|
-
if (c > s || l + 1 > s) return null;
|
|
61
|
-
i.setStart(o, c), i.setEnd(o, l + 1);
|
|
62
|
-
let u = document.createElement("span");
|
|
63
|
-
u.style.width = "auto", i.surroundContents(u);
|
|
64
|
-
let d = u.getBoundingClientRect(), f = e.getBoundingClientRect(), p = f.height, m = f.width, h = 100 * (d.left - f.left) / m, g = 100 * (d.top - f.top) / p, _ = 100 * d.height / p, v = 100 * d.width / m;
|
|
65
|
-
return a(u), {
|
|
66
|
-
keywordStr: t,
|
|
67
|
-
left: h,
|
|
68
|
-
top: g,
|
|
69
|
-
height: _,
|
|
70
|
-
width: v,
|
|
71
|
-
pageHeight: p,
|
|
72
|
-
pageWidth: m
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
async function O(e, t) {
|
|
76
|
-
let n = await T(b, e);
|
|
77
|
-
if (!n) return;
|
|
78
|
-
let r = await E(n);
|
|
79
|
-
r.length && C(k(n, t, r, r.map((e) => e.tagName === "BR" ? " " : e.textContent).reduce((e, t, n) => e.concat(t.split("").map((e, t) => ({
|
|
80
|
-
char: e,
|
|
81
|
-
charIdxInSpan: t,
|
|
82
|
-
spanIdx: n
|
|
83
|
-
}))), [{
|
|
84
|
-
char: "",
|
|
85
|
-
charIdxInSpan: 0,
|
|
86
|
-
spanIdx: 0
|
|
87
|
-
}]).slice(1)));
|
|
88
|
-
}
|
|
89
|
-
let k = (e, n, r, a) => {
|
|
90
|
-
let o = n.length;
|
|
91
|
-
if (!a.length || !o) return [];
|
|
92
|
-
let s = [], c = a.map((e) => e.char).join("");
|
|
93
|
-
return w.forEach((n) => {
|
|
94
|
-
let { keyword: i, regExp: o, wholeWords: l, color: u } = n, d = i;
|
|
95
|
-
if (!d.trim()) return;
|
|
96
|
-
let f = o.flags.indexOf("g") === -1 ? new RegExp(o, `${o.flags}g`) : o, p, m = [];
|
|
97
|
-
for (; (p = f.exec(c)) !== null;) l && !t(c, p.index, p[0].length) || m.push({
|
|
98
|
-
keyword: f,
|
|
99
|
-
startIndex: p.index,
|
|
100
|
-
endIndex: f.lastIndex
|
|
101
|
-
});
|
|
102
|
-
let h = m.map((e) => ({
|
|
103
|
-
keyword: e.keyword,
|
|
104
|
-
indexes: a.slice(e.startIndex, e.endIndex),
|
|
105
|
-
color: u
|
|
106
|
-
}));
|
|
107
|
-
for (let t of h) {
|
|
108
|
-
let n = t.indexes.reduce((e, t) => (e[t.spanIdx] = (e[t.spanIdx] || []).concat([t]), e), {});
|
|
109
|
-
for (let i of Object.values(n)) if (i.length !== 1 || i[0].char.trim() !== "") {
|
|
110
|
-
let n = i, a = r[n[0].spanIdx], o = D(e, d, a, n);
|
|
111
|
-
if (o) {
|
|
112
|
-
let { left: e, top: n } = o;
|
|
113
|
-
if (s.find((t) => t.left === e && t.top === n)) continue;
|
|
114
|
-
s.push({
|
|
115
|
-
...o,
|
|
116
|
-
highlightColor: t.color
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}), s.sort(i), s;
|
|
122
|
-
};
|
|
123
|
-
return o(() => {
|
|
124
|
-
(async () => {
|
|
125
|
-
if (!v || v.length === 0) {
|
|
126
|
-
C([]);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
await O(p, v);
|
|
131
|
-
} catch (e) {
|
|
132
|
-
console.error(e);
|
|
133
|
-
}
|
|
134
|
-
})();
|
|
135
|
-
}, [
|
|
136
|
-
!0,
|
|
137
|
-
v,
|
|
138
|
-
p,
|
|
139
|
-
h,
|
|
140
|
-
m
|
|
141
|
-
]), /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d("div", {
|
|
142
|
-
ref: y,
|
|
143
|
-
"data-rp": `page-${p}-textHighlightLayer`,
|
|
144
|
-
children: S.map((e, t) => /* @__PURE__ */ d("div", {
|
|
145
|
-
className: f["rp-text-highlight"],
|
|
146
|
-
style: {
|
|
147
|
-
top: `${e.top}%`,
|
|
148
|
-
left: `${e.left}%`,
|
|
149
|
-
width: `${e.width}%`,
|
|
150
|
-
height: `${e.height}%`,
|
|
151
|
-
backgroundColor: e.highlightColor
|
|
152
|
-
}
|
|
153
|
-
}, t))
|
|
154
|
-
}) });
|
|
155
|
-
};
|
|
156
|
-
//#endregion
|
|
157
|
-
export { p as t };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|