@react-pdf-kit/viewer 2.10.0-beta.0 → 2.10.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.
@@ -73,7 +73,7 @@ var b = a((a, b) => {
73
73
  children: /* @__PURE__ */ v(k, {})
74
74
  }),
75
75
  /* @__PURE__ */ v(d, { pageNumber: x }),
76
- E && /* @__PURE__ */ v(c, { pageNumber: x }),
76
+ E && !A?.page.isPureXfa && /* @__PURE__ */ v(c, { pageNumber: x }),
77
77
  /* @__PURE__ */ v(u, {
78
78
  pageNumber: x,
79
79
  viewport: F
@@ -1,49 +1,86 @@
1
1
  "use client";
2
- import { useDocumentContext as e } from "../../contexts/RPDocumentContext.js";
3
- import { useZoomContext as t } from "../../contexts/ZoomContext.js";
4
- import { usePagesRotateContext as n } from "../../contexts/PagesRotateContext.js";
5
- import { r } from "../../PaginationContext-DIzsZhFd.js";
6
- import { SimpleLinkService as i } from "../../utils/link_service.js";
7
- import { t as a } from "../../XfaLayer.module-w4FOd2dm.js";
8
- import { useEffect as o, useRef as s } from "react";
9
- import { XfaLayer as c } from "pdfjs-dist";
10
- import { jsx as l } from "react/jsx-runtime";
2
+ import { runPdfOperation as e } from "../../utils/pdfOperationTracker.js";
3
+ import { useDocumentContext as t } from "../../contexts/RPDocumentContext.js";
4
+ import { useZoomContext as n } from "../../contexts/ZoomContext.js";
5
+ import { usePagesRotateContext as r } from "../../contexts/PagesRotateContext.js";
6
+ import { useSmoothScrollContext as i } from "../../contexts/SmoothScrollContext.js";
7
+ import { r as a } from "../../PaginationContext-DIzsZhFd.js";
8
+ import { SimpleLinkService as o } from "../../utils/link_service.js";
9
+ import { t as s } from "../../XfaLayer.module-w4FOd2dm.js";
10
+ import { highlightMatches as c, resetDivs as l } from "../../utils/highlight.js";
11
+ import { useSearchContext as u } from "../../contexts/SearchContext.js";
12
+ import { useEffect as d, useRef as f, useState as p } from "react";
13
+ import { XfaLayer as m } from "pdfjs-dist";
14
+ import { jsx as h } from "react/jsx-runtime";
11
15
  //#region lib/components/page/XfaLayer.tsx
12
- var u = ({ pageNumber: u }) => {
13
- let d = s(null), f = s(null), { pages: p, pdf: m } = e(), { currentZoom: h, targetZoom: g } = t(), { pageRotate: _ } = n(), { goToPage: v } = r(), y = p.get(u), b = y ? _[u] ?? y.defaultRotation ?? 0 : 0;
14
- if (o(() => {
15
- if (!y || !m || !y.page.isPureXfa || !d.current || !h) return;
16
- let e = new AbortController();
16
+ var g = ({ pageNumber: g }) => {
17
+ let _ = f(null), v = f(null), [y, b] = p(0), [x, S] = p([]), { pages: C, pdf: w } = t(), { matches: T, currentMatch: E } = u(), { scrollBehavior: D } = i(), { currentZoom: O, targetZoom: k } = n(), { pageRotate: A } = r(), { goToPage: j } = a(), M = C.get(g), N = M ? A[g] ?? M.defaultRotation ?? 0 : 0;
18
+ if (d(() => {
19
+ if (!M || !w || !M.page.isPureXfa || !_.current || !O) return;
20
+ let t = new AbortController();
17
21
  return (async () => {
18
- let t = await y.page.getXfa();
19
- if (e.signal.aborted || !t || !d.current) return;
20
- let n = y.page.getViewport({
21
- scale: h,
22
- rotation: b
23
- }), r = document.createElement("div");
24
- d.current.replaceChildren(r), f.current = r, c.render({
25
- div: r,
26
- viewport: n.clone({ dontFlip: !0 }),
27
- xfaHtml: t,
28
- annotationStorage: m.annotationStorage,
29
- linkService: new i(m, v)
22
+ let [n, r] = await Promise.all([M.page.getXfa(), e(w, () => M.page.getTextContent())]);
23
+ if (t.signal.aborted || !n || !_.current) return;
24
+ let i = M.page.getViewport({
25
+ scale: O,
26
+ rotation: N
27
+ }), a = document.createElement("div");
28
+ _.current.replaceChildren(a);
29
+ let { textDivs: s } = m.render({
30
+ div: a,
31
+ viewport: i.clone({ dontFlip: !0 }),
32
+ xfaHtml: n,
33
+ annotationStorage: w.annotationStorage,
34
+ linkService: new o(w, j)
30
35
  });
36
+ v.current = {
37
+ content: r,
38
+ divs: s
39
+ }, b((e) => e + 1);
31
40
  })(), () => {
32
- e.abort(), f.current = null;
41
+ t.abort(), v.current = null;
33
42
  };
34
43
  }, [
35
- h,
36
- v,
37
- y,
38
- m,
39
- b
40
- ]), !y?.page.isPureXfa) return null;
41
- let x = h && g ? g / h : 1;
42
- return /* @__PURE__ */ l("div", {
43
- ref: d,
44
- className: a["rp-xfa-layer"],
45
- style: { "--rp-xfa-visual-scale": x }
44
+ O,
45
+ j,
46
+ M,
47
+ w,
48
+ N
49
+ ]), d(() => {
50
+ let e = v.current;
51
+ if (!e) return;
52
+ l(e.content, e.divs);
53
+ let t = T.filter((e) => e.pageIndex === g - 1);
54
+ S(t.length ? c(t, e.content, e.divs) : []);
55
+ }, [
56
+ T,
57
+ g,
58
+ y
59
+ ]), d(() => {
60
+ if (x.forEach(({ element: e }) => e.classList.remove("selected")), E?.pageIndex !== g - 1) return;
61
+ let e = x.find(({ index: e }) => e === E.pageMatchIdx)?.element;
62
+ if (!e) return;
63
+ e.classList.add("selected");
64
+ let t = requestAnimationFrame(() => {
65
+ e.scrollIntoView({
66
+ block: "center",
67
+ inline: "nearest",
68
+ behavior: D
69
+ });
70
+ });
71
+ return () => cancelAnimationFrame(t);
72
+ }, [
73
+ E,
74
+ x,
75
+ g,
76
+ D
77
+ ]), !M?.page.isPureXfa) return null;
78
+ let P = O && k ? k / O : 1;
79
+ return /* @__PURE__ */ h("div", {
80
+ ref: _,
81
+ className: s["rp-xfa-layer"],
82
+ style: { "--rp-xfa-visual-scale": P }
46
83
  });
47
84
  };
48
85
  //#endregion
49
- export { u as XfaLayer };
86
+ export { g as XfaLayer };
@@ -72,7 +72,9 @@ function i(e, t, n) {
72
72
  for (let e of c) {
73
73
  let n = [];
74
74
  for (let r = e.start.idx; r <= e.end.idx; r++) {
75
- let i = o[r], a = i.transform[4], s = i.transform[5], c = i.str.length > 0 ? i.width / i.str.length : 0, l = r === e.start.idx ? e.start.offset : 0, u = r === e.end.idx ? e.end.offset : i.str.length, d = a + l * c, f = (u - l) * c, p = (t.styles ?? {})[i.fontName], m = p?.ascent ?? 1, h = s - (p?.descent == null ? 1 - m : Math.abs(p.descent)) * i.height;
75
+ let i = o[r];
76
+ if (!i.transform) continue;
77
+ let a = i.transform[4], s = i.transform[5], c = i.str.length > 0 ? i.width / i.str.length : 0, l = r === e.start.idx ? e.start.offset : 0, u = r === e.end.idx ? e.end.offset : i.str.length, d = a + l * c, f = (u - l) * c, p = (t.styles ?? {})[i.fontName], m = p?.ascent ?? 1, h = s - (p?.descent == null ? 1 - m : Math.abs(p.descent)) * i.height;
76
78
  i.height > 0 && i.width > 0 && n.push({
77
79
  left: d,
78
80
  bottom: h,
@@ -80,7 +82,7 @@ function i(e, t, n) {
80
82
  height: i.height
81
83
  });
82
84
  }
83
- e.rect = n[0], e.rects = n;
85
+ e.rect = n[0] ?? e.rect, e.rects = n;
84
86
  }
85
87
  return c;
86
88
  }
@@ -3,7 +3,7 @@ import { LicenseType as t } from "../types.js";
3
3
  import { appConsole as n } from "../appConsole.js";
4
4
  import { useCallback as r, useEffect as i, useState as a } from "react";
5
5
  //#region lib/utils/hooks/useLicense.ts
6
- var o = /* @__PURE__ */ new Date("2026-09-23T06:43:32.834Z"), s = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx\ngr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b\nHLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y\nBm7PPGYdL2l2gvKDxchmmsHFPukGki9L4JOUeIVX0GXAxabENckaEH/iC1NZhX+W\nvXnpHeHuIIKlZ16LSivXNgo6BH2Z3GFdg4G3cAaXr6qNP8fsacYNqv2SpTW1viFD\nvzcGRabN25gpJAp9/syeScefWH3OiJY1lmw88oTiJbjIoiq6AkPhfn3G9mF54nvR\nkwIDAQAB\n-----END PUBLIC KEY-----", c = "Please visit https://app.react-pdf-kit.dev to generate a new license key.", l = {
6
+ var o = /* @__PURE__ */ new Date("2026-09-23T08:51:26.281Z"), s = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvIokvErJ0Fctu0jduSAx\ngr+5Har/VSuZLlOunS28hnlqqA+OF1apHL7RYkjBosS15yvviYdLrVWYHpHnoY4b\nHLQ9I6YX6FMB9T/VbB4xLdVdKvfi8r49aTScl5EKuSpgpPgz2VSJTfvVGcRuth/Y\nBm7PPGYdL2l2gvKDxchmmsHFPukGki9L4JOUeIVX0GXAxabENckaEH/iC1NZhX+W\nvXnpHeHuIIKlZ16LSivXNgo6BH2Z3GFdg4G3cAaXr6qNP8fsacYNqv2SpTW1viFD\nvzcGRabN25gpJAp9/syeScefWH3OiJY1lmw88oTiJbjIoiq6AkPhfn3G9mF54nvR\nkwIDAQAB\n-----END PUBLIC KEY-----", c = "Please visit https://app.react-pdf-kit.dev to generate a new license key.", l = {
7
7
  invalidLicense: `You are currently using without a valid license. ${c}`,
8
8
  mismatchedDomain: `Your license key is not valid for the current domain / IP. ${c}`,
9
9
  expired: `Your license key has expired. ${c}`,
@@ -39,7 +39,10 @@ var x = (x = {}, S = "") => {
39
39
  let s = {
40
40
  height: A[n.page - 1],
41
41
  width: k[n.page - 1]
42
- }, c = L[n.page], { leftInPage: l, topInPage: u } = h(s, U, n.rect, M, c), p = a.offsetLeft + o.left + l, m = a.offsetTop + o.top + u, g = {
42
+ }, c = L[n.page], { leftInPage: l, topInPage: u } = i.page.isPureXfa ? {
43
+ leftInPage: 0,
44
+ topInPage: 0
45
+ } : h(s, U, n.rect, M, c), p = a.offsetLeft + o.left + l, m = a.offsetTop + o.top + u, g = {
43
46
  left: Math.max(p, 0),
44
47
  top: Math.max(m, 0)
45
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pdf-kit/viewer",
3
- "version": "2.10.0-beta.0",
3
+ "version": "2.10.0-beta.1",
4
4
  "private": false,
5
5
  "description": "A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.",
6
6
  "keywords": [