@pdf-viewer/react 1.3.0 → 1.4.0-beta.1
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/RPDefaultLayout-838ad8e8.js +2907 -0
- package/dist/assets/RPDefaultLayout.css +1 -1
- package/dist/components/RPController.js +24 -23
- package/dist/components/RPPages.js +3 -2
- package/dist/components/RPProvider.js +4 -3
- package/dist/components/layout/RPDefaultLayout.js +1 -1
- package/dist/components/layout/sidebar/RPSidebar.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/DocumentDialog.js +3 -2
- package/dist/components/layout/toolbar/FileDownloadTool.js +1 -1
- package/dist/components/layout/toolbar/MostPageTool.js +3 -2
- package/dist/components/layout/toolbar/OtherTool.js +1 -1
- package/dist/components/layout/toolbar/Paginate.js +2 -2
- package/dist/components/layout/toolbar/PrintTool.js +2 -2
- package/dist/components/layout/toolbar/RPToolbar.js +1 -1
- package/dist/components/layout/toolbar/RPToolbarEnd.js +2 -2
- package/dist/components/layout/toolbar/SearchTool.js +3 -2
- package/dist/components/layout/toolbar/ZoomTool.js +3 -2
- package/dist/components/page/AnnotationLayer.js +3 -2
- package/dist/components/page/CanvasLayer.js +3 -2
- package/dist/components/page/DualPage.js +1 -1
- package/dist/components/page/RPPage.js +3 -2
- package/dist/components/page/SinglePage.js +2 -2
- package/dist/components/page/TextHighlightLayer.js +32 -0
- package/dist/components/page/TextLayer.js +3 -2
- package/dist/components/ui/LoadingIndicator.js +1 -1
- package/dist/contexts/HighlightContext.js +18 -0
- package/dist/contexts/PaginationContext.js +1 -1
- package/dist/contexts/PrintContext.js +1 -1
- package/dist/contexts/SearchContext.js +1 -1
- package/dist/contexts/ThumbnailsContext.js +1 -1
- package/dist/main.js +22 -20
- package/dist/types/components/page/TextHighlightLayer.d.ts +6 -0
- package/dist/types/contexts/HighlightContext.d.ts +8 -0
- package/dist/types/main.d.ts +1 -0
- package/dist/types/utils/highlight.d.ts +6 -1
- package/dist/types/utils/hooks/useHighlight.d.ts +10 -0
- package/dist/types/utils/types.d.ts +15 -0
- package/dist/utils/highlight.js +157 -97
- package/dist/utils/hooks/useFileDownload.js +3 -2
- package/dist/utils/hooks/useHighlight.js +52 -0
- package/dist/utils/hooks/useLicense.js +59 -60
- package/dist/utils/hooks/usePaginate.js +3 -2
- package/dist/utils/hooks/usePrint.js +3 -2
- package/dist/utils/hooks/useScrollToPage.js +3 -2
- package/dist/utils/hooks/useSearch.js +3 -2
- package/dist/utils/hooks/useThumbnail.js +3 -2
- package/dist/utils/hooks/useVirtualReactWindow.js +3 -2
- package/package.json +1 -1
- package/dist/RPDefaultLayout-6fe6be3d.js +0 -2832
package/dist/main.js
CHANGED
|
@@ -1,42 +1,44 @@
|
|
|
1
1
|
import { RPProvider as t } from "./components/RPProvider.js";
|
|
2
|
-
import { b as x, R as n, c as s, u as m, d as p, e as f } from "./RPDefaultLayout-
|
|
2
|
+
import { b as x, R as n, c as s, u as m, d as p, e as f } from "./RPDefaultLayout-838ad8e8.js";
|
|
3
3
|
import { RPConfig as a } from "./components/RPConfig.js";
|
|
4
|
-
import { RPController as
|
|
4
|
+
import { RPController as l } from "./components/RPController.js";
|
|
5
5
|
import { RPTheme as P } from "./components/RPTheme.js";
|
|
6
6
|
import { RPDropFileZone as d } from "./components/RPDropFileZone.js";
|
|
7
7
|
import { useDarkModeContext as D } from "./contexts/DarkModeContext.js";
|
|
8
|
-
import { useDocumentContext as
|
|
9
|
-
import { useRotationContext as
|
|
10
|
-
import { useViewModeContext as
|
|
11
|
-
import { useDropFileZoneContext as
|
|
8
|
+
import { useDocumentContext as F } from "./contexts/RPDocumentContext.js";
|
|
9
|
+
import { useRotationContext as M } from "./contexts/RotationContext.js";
|
|
10
|
+
import { useViewModeContext as w } from "./contexts/ViewModeContext.js";
|
|
11
|
+
import { useDropFileZoneContext as S } from "./contexts/DropFileZoneContext.js";
|
|
12
12
|
import { useOpenFileContext as V } from "./contexts/FileInputContext.js";
|
|
13
13
|
import { useZoomContext as k } from "./contexts/ZoomContext.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
14
|
+
import { useHighlightContext as H } from "./contexts/HighlightContext.js";
|
|
15
|
+
import { usePdfProperties as T } from "./utils/hooks/usePdfProperties.js";
|
|
16
|
+
import { useFullScreenContext as q } from "./contexts/FullScreenContext.js";
|
|
17
|
+
import { Locales as A, ScrollMode as B, ViewMode as E, ZoomLevel as G } from "./utils/types.js";
|
|
17
18
|
export {
|
|
18
|
-
|
|
19
|
+
A as Locales,
|
|
19
20
|
a as RPConfig,
|
|
20
|
-
|
|
21
|
+
l as RPController,
|
|
21
22
|
x as RPDefaultLayout,
|
|
22
23
|
d as RPDropFileZone,
|
|
23
24
|
n as RPPages,
|
|
24
25
|
t as RPProvider,
|
|
25
26
|
P as RPTheme,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
B as ScrollMode,
|
|
28
|
+
E as ViewMode,
|
|
29
|
+
G as ZoomLevel,
|
|
29
30
|
D as useDarkModeContext,
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
F as useDocumentContext,
|
|
32
|
+
S as useDropFileZoneContext,
|
|
32
33
|
s as useFileDownload,
|
|
33
|
-
|
|
34
|
+
q as useFullScreenContext,
|
|
35
|
+
H as useHighlightContext,
|
|
34
36
|
V as useOpenFileContext,
|
|
35
37
|
m as usePaginationContext,
|
|
36
|
-
|
|
38
|
+
T as usePdfProperties,
|
|
37
39
|
p as usePrintContext,
|
|
38
|
-
|
|
40
|
+
M as useRotationContext,
|
|
39
41
|
f as useSearchContext,
|
|
40
|
-
|
|
42
|
+
w as useViewModeContext,
|
|
41
43
|
k as useZoomContext
|
|
42
44
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UseHighlight } from '../utils/types';
|
|
2
|
+
interface HighlightProvider {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export declare const HighlightContext: import('react').Context<UseHighlight | undefined>;
|
|
6
|
+
export declare const HighlightProvider: ({ children }: HighlightProvider) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare const useHighlightContext: () => UseHighlight;
|
|
8
|
+
export {};
|
package/dist/types/main.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { useOpenFileContext } from './contexts/FileInputContext';
|
|
|
16
16
|
export { usePrintContext } from './contexts/PrintContext';
|
|
17
17
|
export { useZoomContext } from './contexts/ZoomContext';
|
|
18
18
|
export { useSearchContext } from './contexts/SearchContext';
|
|
19
|
+
export { useHighlightContext } from './contexts/HighlightContext';
|
|
19
20
|
export { usePdfProperties } from './utils/hooks/usePdfProperties';
|
|
20
21
|
export { useFullScreenContext } from './contexts/FullScreenContext';
|
|
21
22
|
export { type PDFDocumentProxy } from 'pdfjs-dist';
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { TextContent } from 'pdfjs-dist/types/src/display/text_layer';
|
|
2
|
-
import { SearchOptions, Match } from './types';
|
|
2
|
+
import { SearchOptions, Match, MatchHighlight } from './types';
|
|
3
3
|
export declare function findMatches(queries: (string | RegExp)[], textContent: TextContent, pageIndex: number, options: SearchOptions): Match[];
|
|
4
4
|
export declare function highlightMatches(matches: Match[], textContent: TextContent, textDivs: HTMLElement[]): {
|
|
5
5
|
element: HTMLElement;
|
|
6
6
|
index: number;
|
|
7
7
|
}[];
|
|
8
8
|
export declare function resetDivs(textContent: TextContent, textDivs: HTMLElement[]): void;
|
|
9
|
+
export declare function getHighlightOptionsWithDefaults(options?: SearchOptions): SearchOptions;
|
|
10
|
+
export declare function highlightMultipleColorMatches(matches: MatchHighlight[], textContent: TextContent, textDivs: HTMLElement[]): {
|
|
11
|
+
element: HTMLElement;
|
|
12
|
+
index: number;
|
|
13
|
+
}[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PDFDocumentProxy } from 'pdfjs-dist';
|
|
2
|
+
import { MatchHighlight, TextHighlight } from '../types';
|
|
3
|
+
interface UseHighlight {
|
|
4
|
+
highlight: (value: TextHighlight[]) => Promise<void>;
|
|
5
|
+
highlightMatches: MatchHighlight[];
|
|
6
|
+
highlightKeywords: TextHighlight[] | undefined;
|
|
7
|
+
clear: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const useHighlight: (pdf: PDFDocumentProxy | undefined) => UseHighlight;
|
|
10
|
+
export {};
|
|
@@ -602,4 +602,19 @@ export interface LocalizationProps {
|
|
|
602
602
|
export interface LoaderContextType {
|
|
603
603
|
LoaderImageComponent?: React.FC;
|
|
604
604
|
}
|
|
605
|
+
export interface TextHighlight {
|
|
606
|
+
keyword: string | RegExp;
|
|
607
|
+
highlightColor: string;
|
|
608
|
+
options?: SearchOptions;
|
|
609
|
+
}
|
|
610
|
+
export interface UseHighlight {
|
|
611
|
+
highlight: (value: TextHighlight[]) => Promise<void>;
|
|
612
|
+
highlightMatches: MatchHighlight[];
|
|
613
|
+
highlightKeywords: TextHighlight[] | undefined;
|
|
614
|
+
clear: () => void;
|
|
615
|
+
}
|
|
616
|
+
export interface MatchHighlight extends MatchValue {
|
|
617
|
+
keyword: string | RegExp;
|
|
618
|
+
color: string;
|
|
619
|
+
}
|
|
605
620
|
export {};
|
package/dist/utils/highlight.js
CHANGED
|
@@ -1,145 +1,205 @@
|
|
|
1
|
-
import { getCharacterType as
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
for (const
|
|
5
|
-
const i =
|
|
6
|
-
|
|
1
|
+
import { getCharacterType as D } from "./charators.js";
|
|
2
|
+
function H(d, c, l, s) {
|
|
3
|
+
const o = [];
|
|
4
|
+
for (const n of d) {
|
|
5
|
+
const i = X(c, n, s);
|
|
6
|
+
o.push(..._(i, c, l));
|
|
7
7
|
}
|
|
8
|
-
return
|
|
8
|
+
return o;
|
|
9
9
|
}
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
let
|
|
14
|
-
return new RegExp(
|
|
10
|
+
const L = (d, c) => {
|
|
11
|
+
const l = ["g"];
|
|
12
|
+
c.matchCase || l.push("i");
|
|
13
|
+
let o = d.replace(/[.^$*+?()[{|\\]/g, (n) => `\\${n}`).trim();
|
|
14
|
+
return new RegExp(o, l.join(""));
|
|
15
15
|
};
|
|
16
|
-
function
|
|
16
|
+
function X(d, c, l) {
|
|
17
17
|
const s = [];
|
|
18
|
-
for (const
|
|
19
|
-
if (
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
s.push(
|
|
18
|
+
for (const t of d.items)
|
|
19
|
+
if (t.hasEOL)
|
|
20
|
+
if (t.str.endsWith("-")) {
|
|
21
|
+
const a = t.str.lastIndexOf("-");
|
|
22
|
+
s.push(t.str.substring(0, a));
|
|
23
23
|
} else
|
|
24
|
-
s.push(
|
|
24
|
+
s.push(t.str, `
|
|
25
25
|
`);
|
|
26
26
|
else
|
|
27
|
-
s.push(
|
|
28
|
-
const
|
|
29
|
-
let t;
|
|
30
|
-
o instanceof RegExp ? t = o.flags.indexOf("g") === -1 ? new RegExp(o, `${o.flags}g`) : o : t = C(o, d);
|
|
31
|
-
const i = [];
|
|
27
|
+
s.push(t.str);
|
|
28
|
+
const o = s.join("").replace(/\n/g, " ");
|
|
32
29
|
let n;
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
c instanceof RegExp ? n = c.flags.indexOf("g") === -1 ? new RegExp(c, `${c.flags}g`) : c : n = L(c, l);
|
|
31
|
+
const i = [];
|
|
32
|
+
let e;
|
|
33
|
+
for (; (e = n.exec(o)) !== null; )
|
|
34
|
+
l.wholeWords && !w(o, e.index, e[0].length) || i.push([e.index, e[0].length, e[0]]);
|
|
35
35
|
return i;
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
function s(
|
|
39
|
-
return
|
|
37
|
+
function _(d, c, l) {
|
|
38
|
+
function s(a) {
|
|
39
|
+
return a.hasEOL ? a.str.endsWith("-") ? -1 : 1 : 0;
|
|
40
40
|
}
|
|
41
|
-
let
|
|
42
|
-
const i =
|
|
43
|
-
for (let
|
|
44
|
-
let
|
|
45
|
-
for (;
|
|
46
|
-
const
|
|
47
|
-
|
|
41
|
+
let o = 0, n = 0;
|
|
42
|
+
const i = c.items, e = i.length - 1, t = [];
|
|
43
|
+
for (let a = 0; a < d.length; a++) {
|
|
44
|
+
let r = d[a][0];
|
|
45
|
+
for (; o !== e && r >= n + i[o].str.length; ) {
|
|
46
|
+
const f = i[o];
|
|
47
|
+
n += f.str.length + s(f), o++;
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
idx:
|
|
51
|
-
offset:
|
|
49
|
+
const p = {
|
|
50
|
+
idx: o,
|
|
51
|
+
offset: r - n
|
|
52
52
|
};
|
|
53
|
-
for (
|
|
54
|
-
const
|
|
55
|
-
|
|
53
|
+
for (r += d[a][1]; o !== e && r > n + i[o].str.length; ) {
|
|
54
|
+
const f = i[o];
|
|
55
|
+
n += f.str.length + s(f), o++;
|
|
56
56
|
}
|
|
57
|
-
const
|
|
58
|
-
idx:
|
|
59
|
-
offset:
|
|
57
|
+
const m = {
|
|
58
|
+
idx: o,
|
|
59
|
+
offset: r - n
|
|
60
60
|
};
|
|
61
|
-
|
|
62
|
-
start:
|
|
63
|
-
end:
|
|
64
|
-
str:
|
|
65
|
-
oIndex:
|
|
66
|
-
pageIndex:
|
|
61
|
+
t.push({
|
|
62
|
+
start: p,
|
|
63
|
+
end: m,
|
|
64
|
+
str: d[a][2],
|
|
65
|
+
oIndex: d[a][0],
|
|
66
|
+
pageIndex: l
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
return
|
|
69
|
+
return t;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
let s =
|
|
71
|
+
function w(d, c, l) {
|
|
72
|
+
let s = d.slice(0, c).match(/([^\p{M}])\p{M}*$/u);
|
|
73
73
|
if (s) {
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
74
|
+
const o = d.charCodeAt(c), n = s[1].charCodeAt(0);
|
|
75
|
+
if (D(o) === D(n))
|
|
76
76
|
return !1;
|
|
77
77
|
}
|
|
78
|
-
if (s =
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
78
|
+
if (s = d.slice(c + l).match(/^\p{M}*([^\p{M}])/u), s) {
|
|
79
|
+
const o = d.charCodeAt(c + l - 1), n = s[1].charCodeAt(0);
|
|
80
|
+
if (D(o) === D(n))
|
|
81
81
|
return !1;
|
|
82
82
|
}
|
|
83
83
|
return !0;
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function I(d, c, l) {
|
|
86
86
|
const s = [];
|
|
87
|
-
function
|
|
88
|
-
const
|
|
89
|
-
let
|
|
87
|
+
function o(n, i, e = -1, t = -1, a = "") {
|
|
88
|
+
const r = c.items[n], p = [];
|
|
89
|
+
let m = "", f = "", b = "", u = l[n];
|
|
90
90
|
if (!u)
|
|
91
91
|
return;
|
|
92
92
|
if (u.nodeType === Node.TEXT_NODE) {
|
|
93
|
-
const
|
|
94
|
-
u.before(
|
|
93
|
+
const g = document.createElement("span");
|
|
94
|
+
u.before(g), g.append(u), l[n] = g, u = g;
|
|
95
95
|
}
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
96
|
+
e >= 0 && t >= 0 ? m = r.str.substring(e, t) : e < 0 && t < 0 ? m = r.str : e >= 0 ? m = r.str.substring(e) : t >= 0 && (m = r.str.substring(0, t));
|
|
97
|
+
const y = document.createTextNode(m), N = document.createElement("span");
|
|
98
|
+
if (N.className = "highlight appended " + a, N.setAttribute("data-match-index", `${i}`), N.append(y), p.push(N), s.push({ element: N, index: i }), e > 0)
|
|
99
99
|
if (u.childNodes.length === 1 && u.childNodes[0].nodeType === Node.TEXT_NODE) {
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
100
|
+
f = r.str.substring(0, e);
|
|
101
|
+
const g = document.createTextNode(f);
|
|
102
|
+
p.unshift(g);
|
|
103
103
|
} else {
|
|
104
|
-
let
|
|
105
|
-
const
|
|
106
|
-
for (const
|
|
107
|
-
const
|
|
108
|
-
|
|
104
|
+
let g = 0;
|
|
105
|
+
const E = [];
|
|
106
|
+
for (const h of u.childNodes) {
|
|
107
|
+
const x = h.nodeType === Node.TEXT_NODE ? h.nodeValue : h.firstChild.nodeValue;
|
|
108
|
+
g += x.length, g <= e ? E.push(h) : e >= g - x.length && t <= g && E.push(
|
|
109
109
|
document.createTextNode(
|
|
110
|
-
|
|
110
|
+
x.substring(0, e - (g - x.length))
|
|
111
111
|
)
|
|
112
112
|
);
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
p.unshift(...E);
|
|
115
115
|
}
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
116
|
+
if (t > 0) {
|
|
117
|
+
b = r.str.substring(t);
|
|
118
|
+
const g = document.createTextNode(b);
|
|
119
|
+
p.push(g);
|
|
120
120
|
}
|
|
121
|
-
u.replaceChildren(...
|
|
121
|
+
u.replaceChildren(...p);
|
|
122
122
|
}
|
|
123
|
-
for (const [
|
|
123
|
+
for (const [n, i] of d.entries())
|
|
124
124
|
if (i.start.idx === i.end.idx)
|
|
125
|
-
|
|
125
|
+
o(i.start.idx, n, i.start.offset, i.end.offset);
|
|
126
126
|
else
|
|
127
|
-
for (let
|
|
128
|
-
|
|
127
|
+
for (let e = i.start.idx, t = i.end.idx; e <= t; e++)
|
|
128
|
+
e === i.start.idx ? o(e, n, i.start.offset, -1, "begin") : e === i.end.idx ? o(e, n, -1, i.end.offset, "end") : o(e, n, -1, -1, "middle");
|
|
129
129
|
return s;
|
|
130
130
|
}
|
|
131
|
-
function
|
|
132
|
-
const
|
|
133
|
-
for (let s = 0; s <
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
137
|
-
|
|
131
|
+
function R(d, c) {
|
|
132
|
+
const l = d.items.map((s) => s.str);
|
|
133
|
+
for (let s = 0; s < c.length; s++) {
|
|
134
|
+
const o = c[s];
|
|
135
|
+
if (o && o.nodeType !== Node.TEXT_NODE) {
|
|
136
|
+
const n = document.createTextNode(l[s]);
|
|
137
|
+
o.replaceChildren(n);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
+
function W(d = {}) {
|
|
142
|
+
return { matchCase: !1, wholeWords: !1, ...d };
|
|
143
|
+
}
|
|
144
|
+
function A(d, c, l) {
|
|
145
|
+
const s = [];
|
|
146
|
+
function o(n, i, e = -1, t = -1, a) {
|
|
147
|
+
var g, E;
|
|
148
|
+
const r = c.items[n], p = [];
|
|
149
|
+
let m = "", f = "", b = "", u = l[n];
|
|
150
|
+
if (!u)
|
|
151
|
+
return;
|
|
152
|
+
e >= 0 && t >= 0 ? m = r.str.substring(e, t) : e < 0 && t < 0 ? m = r.str : e >= 0 ? m = r.str.substring(e) : t >= 0 && (m = r.str.substring(0, t));
|
|
153
|
+
const y = document.createTextNode(m), N = document.createElement("span");
|
|
154
|
+
if (N.style.background = a, N.append(y), p.push(N), e > 0)
|
|
155
|
+
if (u.childNodes.length === 1 && u.childNodes[0].nodeType === Node.TEXT_NODE) {
|
|
156
|
+
f = r.str.substring(0, e);
|
|
157
|
+
const h = document.createTextNode(f);
|
|
158
|
+
p.unshift(h);
|
|
159
|
+
} else {
|
|
160
|
+
let h = 0;
|
|
161
|
+
const x = [];
|
|
162
|
+
for (const T of u.childNodes) {
|
|
163
|
+
const v = T.nodeType === Node.TEXT_NODE ? T.nodeValue || "" : ((g = T.firstChild) == null ? void 0 : g.nodeValue) || "", C = v.length;
|
|
164
|
+
if (h += C, h <= e)
|
|
165
|
+
x.push(T);
|
|
166
|
+
else if (e >= h - C && t <= h) {
|
|
167
|
+
const M = v.substring(0, e - (h - C));
|
|
168
|
+
x.push(document.createTextNode(M));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
p.unshift(...x);
|
|
172
|
+
}
|
|
173
|
+
if (t > 0)
|
|
174
|
+
if (u.childNodes.length === 1 && u.childNodes[0].nodeType === Node.TEXT_NODE) {
|
|
175
|
+
b = r.str.substring(t);
|
|
176
|
+
const h = document.createTextNode(b);
|
|
177
|
+
p.push(h);
|
|
178
|
+
} else {
|
|
179
|
+
let h = 0;
|
|
180
|
+
const x = [];
|
|
181
|
+
for (const T of u.childNodes) {
|
|
182
|
+
h >= t && x.push(T);
|
|
183
|
+
const v = T.nodeType === Node.TEXT_NODE ? T.nodeValue || "" : ((E = T.firstChild) == null ? void 0 : E.nodeValue) || "", C = v.length;
|
|
184
|
+
if (h += C, h > t) {
|
|
185
|
+
const M = v.substring(t - (h - C));
|
|
186
|
+
M && x.push(document.createTextNode(M));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
x.length > 0 && p.push(...x);
|
|
190
|
+
}
|
|
191
|
+
u.replaceChildren(...p), s.push({ element: N, index: i });
|
|
192
|
+
}
|
|
193
|
+
for (const [n, i] of d.entries()) {
|
|
194
|
+
const { start: e, end: t, color: a } = i;
|
|
195
|
+
e.idx === t.idx && o(e.idx, n, e.offset, t.offset, a);
|
|
196
|
+
}
|
|
197
|
+
return s;
|
|
198
|
+
}
|
|
141
199
|
export {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
200
|
+
H as findMatches,
|
|
201
|
+
W as getHighlightOptionsWithDefaults,
|
|
202
|
+
I as highlightMatches,
|
|
203
|
+
A as highlightMultipleColorMatches,
|
|
204
|
+
R as resetDivs
|
|
145
205
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
2
|
import "../../contexts/RPDocumentContext.js";
|
|
3
3
|
import "react";
|
|
4
|
-
import { c as
|
|
4
|
+
import { c as A } from "../../RPDefaultLayout-838ad8e8.js";
|
|
5
5
|
import "../../contexts/DarkModeContext.js";
|
|
6
6
|
import "../../contexts/RotationContext.js";
|
|
7
7
|
import "../../contexts/LayerContext.js";
|
|
@@ -19,11 +19,12 @@ import "../../contexts/DropFileZoneContext.js";
|
|
|
19
19
|
import "../../contexts/LayoutContainerContext.js";
|
|
20
20
|
import "../../contexts/DimensionPagesContext.js";
|
|
21
21
|
import "../../contexts/LocalizationContext.js";
|
|
22
|
+
import "../../contexts/HighlightContext.js";
|
|
22
23
|
import "../../contexts/LoaderContext.js";
|
|
23
24
|
import "../../components/RPConfig.js";
|
|
24
25
|
import "../../contexts/ThemeContext.js";
|
|
25
26
|
import "../../components/RPDropFileZone.js";
|
|
26
27
|
import "../../contexts/ToolbarComponentContext.js";
|
|
27
28
|
export {
|
|
28
|
-
|
|
29
|
+
A as useFileDownload
|
|
29
30
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useState as c, useCallback as x, useEffect as C } from "react";
|
|
2
|
+
import { getHighlightOptionsWithDefaults as H, findMatches as M } from "../highlight.js";
|
|
3
|
+
const d = (i) => {
|
|
4
|
+
const [g, r] = c(void 0), [l, a] = c([]), u = x(async (t) => {
|
|
5
|
+
if (!t)
|
|
6
|
+
return {};
|
|
7
|
+
const o = t.numPages, s = {};
|
|
8
|
+
for (let e = 1; e <= o; e++) {
|
|
9
|
+
const h = await t.getPage(e);
|
|
10
|
+
s[e.toString()] = await h.getTextContent();
|
|
11
|
+
}
|
|
12
|
+
return s;
|
|
13
|
+
}, []), m = async (t) => {
|
|
14
|
+
r(t);
|
|
15
|
+
}, f = () => {
|
|
16
|
+
a([]), r(void 0);
|
|
17
|
+
};
|
|
18
|
+
return C(() => {
|
|
19
|
+
i && u(i).then((t) => {
|
|
20
|
+
let o = [];
|
|
21
|
+
for (const { keyword: s, highlightColor: e, options: h } of g) {
|
|
22
|
+
const p = H(h);
|
|
23
|
+
for (const n of Object.keys(t)) {
|
|
24
|
+
const y = M(
|
|
25
|
+
[s],
|
|
26
|
+
t[n],
|
|
27
|
+
Number(n) - 1,
|
|
28
|
+
p
|
|
29
|
+
).map((b, w) => ({
|
|
30
|
+
...b,
|
|
31
|
+
page: Number(n),
|
|
32
|
+
pageMatchIdx: w,
|
|
33
|
+
color: e,
|
|
34
|
+
keyword: s
|
|
35
|
+
}));
|
|
36
|
+
o = [...o, ...y];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
a(o);
|
|
40
|
+
}).catch((t) => {
|
|
41
|
+
console.error(t);
|
|
42
|
+
});
|
|
43
|
+
}, [g, i]), {
|
|
44
|
+
highlight: m,
|
|
45
|
+
clear: f,
|
|
46
|
+
highlightMatches: l,
|
|
47
|
+
highlightKeywords: g
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
d as useHighlight
|
|
52
|
+
};
|