@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.
Files changed (51) hide show
  1. package/dist/RPDefaultLayout-838ad8e8.js +2907 -0
  2. package/dist/assets/RPDefaultLayout.css +1 -1
  3. package/dist/components/RPController.js +24 -23
  4. package/dist/components/RPPages.js +3 -2
  5. package/dist/components/RPProvider.js +4 -3
  6. package/dist/components/layout/RPDefaultLayout.js +1 -1
  7. package/dist/components/layout/sidebar/RPSidebar.js +1 -1
  8. package/dist/components/layout/sidebar/Thumbnail.js +1 -1
  9. package/dist/components/layout/sidebar/Thumbnails.js +1 -1
  10. package/dist/components/layout/toolbar/DocumentDialog.js +3 -2
  11. package/dist/components/layout/toolbar/FileDownloadTool.js +1 -1
  12. package/dist/components/layout/toolbar/MostPageTool.js +3 -2
  13. package/dist/components/layout/toolbar/OtherTool.js +1 -1
  14. package/dist/components/layout/toolbar/Paginate.js +2 -2
  15. package/dist/components/layout/toolbar/PrintTool.js +2 -2
  16. package/dist/components/layout/toolbar/RPToolbar.js +1 -1
  17. package/dist/components/layout/toolbar/RPToolbarEnd.js +2 -2
  18. package/dist/components/layout/toolbar/SearchTool.js +3 -2
  19. package/dist/components/layout/toolbar/ZoomTool.js +3 -2
  20. package/dist/components/page/AnnotationLayer.js +3 -2
  21. package/dist/components/page/CanvasLayer.js +3 -2
  22. package/dist/components/page/DualPage.js +1 -1
  23. package/dist/components/page/RPPage.js +3 -2
  24. package/dist/components/page/SinglePage.js +2 -2
  25. package/dist/components/page/TextHighlightLayer.js +32 -0
  26. package/dist/components/page/TextLayer.js +3 -2
  27. package/dist/components/ui/LoadingIndicator.js +1 -1
  28. package/dist/contexts/HighlightContext.js +18 -0
  29. package/dist/contexts/PaginationContext.js +1 -1
  30. package/dist/contexts/PrintContext.js +1 -1
  31. package/dist/contexts/SearchContext.js +1 -1
  32. package/dist/contexts/ThumbnailsContext.js +1 -1
  33. package/dist/main.js +22 -20
  34. package/dist/types/components/page/TextHighlightLayer.d.ts +6 -0
  35. package/dist/types/contexts/HighlightContext.d.ts +8 -0
  36. package/dist/types/main.d.ts +1 -0
  37. package/dist/types/utils/highlight.d.ts +6 -1
  38. package/dist/types/utils/hooks/useHighlight.d.ts +10 -0
  39. package/dist/types/utils/types.d.ts +15 -0
  40. package/dist/utils/highlight.js +157 -97
  41. package/dist/utils/hooks/useFileDownload.js +3 -2
  42. package/dist/utils/hooks/useHighlight.js +52 -0
  43. package/dist/utils/hooks/useLicense.js +59 -60
  44. package/dist/utils/hooks/usePaginate.js +3 -2
  45. package/dist/utils/hooks/usePrint.js +3 -2
  46. package/dist/utils/hooks/useScrollToPage.js +3 -2
  47. package/dist/utils/hooks/useSearch.js +3 -2
  48. package/dist/utils/hooks/useThumbnail.js +3 -2
  49. package/dist/utils/hooks/useVirtualReactWindow.js +3 -2
  50. package/package.json +1 -1
  51. package/dist/RPDefaultLayout-6fe6be3d.js +0 -2832
@@ -1,6 +1,6 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
- import { l as i, T as r, m as e } from "../RPDefaultLayout-6fe6be3d.js";
3
+ import { l as i, T as r, m as e } from "../RPDefaultLayout-838ad8e8.js";
4
4
  export {
5
5
  i as ThumbnailContext,
6
6
  r as ThumbnailProvider,
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-6fe6be3d.js";
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 i } from "./components/RPController.js";
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 M } from "./contexts/RPDocumentContext.js";
9
- import { useRotationContext as g } from "./contexts/RotationContext.js";
10
- import { useViewModeContext as L } from "./contexts/ViewModeContext.js";
11
- import { useDropFileZoneContext as h } from "./contexts/DropFileZoneContext.js";
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 { usePdfProperties as O } from "./utils/hooks/usePdfProperties.js";
15
- import { useFullScreenContext as j } from "./contexts/FullScreenContext.js";
16
- import { Locales as z, ScrollMode as A, ViewMode as B, ZoomLevel as E } from "./utils/types.js";
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
- z as Locales,
19
+ A as Locales,
19
20
  a as RPConfig,
20
- i as RPController,
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
- A as ScrollMode,
27
- B as ViewMode,
28
- E as ZoomLevel,
27
+ B as ScrollMode,
28
+ E as ViewMode,
29
+ G as ZoomLevel,
29
30
  D as useDarkModeContext,
30
- M as useDocumentContext,
31
- h as useDropFileZoneContext,
31
+ F as useDocumentContext,
32
+ S as useDropFileZoneContext,
32
33
  s as useFileDownload,
33
- j as useFullScreenContext,
34
+ q as useFullScreenContext,
35
+ H as useHighlightContext,
34
36
  V as useOpenFileContext,
35
37
  m as usePaginationContext,
36
- O as usePdfProperties,
38
+ T as usePdfProperties,
37
39
  p as usePrintContext,
38
- g as useRotationContext,
40
+ M as useRotationContext,
39
41
  f as useSearchContext,
40
- L as useViewModeContext,
42
+ w as useViewModeContext,
41
43
  k as useZoomContext
42
44
  };
@@ -0,0 +1,6 @@
1
+ import { FC } from 'react';
2
+ interface Props {
3
+ pageNumber: number;
4
+ }
5
+ export declare const TextHighlightLayer: FC<Props>;
6
+ export {};
@@ -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 {};
@@ -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 {};
@@ -1,145 +1,205 @@
1
- import { getCharacterType as E } from "./charators.js";
2
- function I(r, o, d, s) {
3
- const e = [];
4
- for (const t of r) {
5
- const i = M(o, t, s);
6
- e.push(...w(i, o, d));
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 e;
8
+ return o;
9
9
  }
10
- const C = (r, o) => {
11
- const d = ["g"];
12
- o.matchCase || d.push("i");
13
- let e = r.replace(/[.^$*+?()[{|\\]/g, (t) => `\\${t}`).trim();
14
- return new RegExp(e, d.join(""));
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 M(r, o, d) {
16
+ function X(d, c, l) {
17
17
  const s = [];
18
- for (const c of r.items)
19
- if (c.hasEOL)
20
- if (c.str.endsWith("-")) {
21
- const h = c.str.lastIndexOf("-");
22
- s.push(c.str.substring(0, h));
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(c.str, `
24
+ s.push(t.str, `
25
25
  `);
26
26
  else
27
- s.push(c.str);
28
- const e = s.join("").replace(/\n/g, " ");
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
- for (; (n = t.exec(e)) !== null; )
34
- d.wholeWords && !R(e, n.index, n[0].length) || i.push([n.index, n[0].length, n[0]]);
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 w(r, o, d) {
38
- function s(h) {
39
- return h.hasEOL ? h.str.endsWith("-") ? -1 : 1 : 0;
37
+ function _(d, c, l) {
38
+ function s(a) {
39
+ return a.hasEOL ? a.str.endsWith("-") ? -1 : 1 : 0;
40
40
  }
41
- let e = 0, t = 0;
42
- const i = o.items, n = i.length - 1, c = [];
43
- for (let h = 0; h < r.length; h++) {
44
- let a = r[h][0];
45
- for (; e !== n && a >= t + i[e].str.length; ) {
46
- const p = i[e];
47
- t += p.str.length + s(p), e++;
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 g = {
50
- idx: e,
51
- offset: a - t
49
+ const p = {
50
+ idx: o,
51
+ offset: r - n
52
52
  };
53
- for (a += r[h][1]; e !== n && a > t + i[e].str.length; ) {
54
- const p = i[e];
55
- t += p.str.length + s(p), e++;
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 f = {
58
- idx: e,
59
- offset: a - t
57
+ const m = {
58
+ idx: o,
59
+ offset: r - n
60
60
  };
61
- c.push({
62
- start: g,
63
- end: f,
64
- str: r[h][2],
65
- oIndex: r[h][0],
66
- pageIndex: d
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 c;
69
+ return t;
70
70
  }
71
- function R(r, o, d) {
72
- let s = r.slice(0, o).match(/([^\p{M}])\p{M}*$/u);
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 e = r.charCodeAt(o), t = s[1].charCodeAt(0);
75
- if (E(e) === E(t))
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 = r.slice(o + d).match(/^\p{M}*([^\p{M}])/u), s) {
79
- const e = r.charCodeAt(o + d - 1), t = s[1].charCodeAt(0);
80
- if (E(e) === E(t))
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 $(r, o, d) {
85
+ function I(d, c, l) {
86
86
  const s = [];
87
- function e(t, i, n = -1, c = -1, h = "") {
88
- const a = o.items[t], g = [];
89
- let f = "", p = "", v = "", u = d[t];
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 l = document.createElement("span");
94
- u.before(l), l.append(u), d[t] = l, u = l;
93
+ const g = document.createElement("span");
94
+ u.before(g), g.append(u), l[n] = g, u = g;
95
95
  }
96
- n >= 0 && c >= 0 ? f = a.str.substring(n, c) : n < 0 && c < 0 ? f = a.str : n >= 0 ? f = a.str.substring(n) : c >= 0 && (f = a.str.substring(0, c));
97
- const b = document.createTextNode(f), m = document.createElement("span");
98
- if (m.className = "highlight appended " + h, m.setAttribute("data-match-index", `${i}`), m.append(b), g.push(m), s.push({ element: m, index: i }), n > 0)
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
- p = a.str.substring(0, n);
101
- const l = document.createTextNode(p);
102
- g.unshift(l);
100
+ f = r.str.substring(0, e);
101
+ const g = document.createTextNode(f);
102
+ p.unshift(g);
103
103
  } else {
104
- let l = 0;
105
- const T = [];
106
- for (const x of u.childNodes) {
107
- const N = x.nodeType === Node.TEXT_NODE ? x.nodeValue : x.firstChild.nodeValue;
108
- l += N.length, l <= n ? T.push(x) : n >= l - N.length && c <= l && T.push(
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
- N.substring(0, n - (l - N.length))
110
+ x.substring(0, e - (g - x.length))
111
111
  )
112
112
  );
113
113
  }
114
- g.unshift(...T);
114
+ p.unshift(...E);
115
115
  }
116
- if (c > 0) {
117
- v = a.str.substring(c);
118
- const l = document.createTextNode(v);
119
- g.push(l);
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(...g);
121
+ u.replaceChildren(...p);
122
122
  }
123
- for (const [t, i] of r.entries())
123
+ for (const [n, i] of d.entries())
124
124
  if (i.start.idx === i.end.idx)
125
- e(i.start.idx, t, i.start.offset, i.end.offset);
125
+ o(i.start.idx, n, i.start.offset, i.end.offset);
126
126
  else
127
- for (let n = i.start.idx, c = i.end.idx; n <= c; n++)
128
- n === i.start.idx ? e(n, t, i.start.offset, -1, "begin") : n === i.end.idx ? e(n, t, -1, i.end.offset, "end") : e(n, t, -1, -1, "middle");
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 y(r, o) {
132
- const d = r.items.map((s) => s.str);
133
- for (let s = 0; s < o.length; s++) {
134
- const e = o[s];
135
- if (e && e.nodeType !== Node.TEXT_NODE) {
136
- const t = document.createTextNode(d[s]);
137
- e.replaceChildren(t);
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
- I as findMatches,
143
- $ as highlightMatches,
144
- y as resetDivs
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 z } from "../../RPDefaultLayout-6fe6be3d.js";
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
- z as useFileDownload
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
+ };