@pdf-viewer/react 0.0.0-experimental.0 → 0.0.0-experimental.2

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 (86) hide show
  1. package/dist/{ToolbarLayout.module-89451ab3.js → ToolbarLayout.module-185b677e.js} +1071 -1059
  2. package/dist/components/RPController.js +5 -3
  3. package/dist/components/RPPages.js +4 -2
  4. package/dist/components/RPProvider.js +37 -22
  5. package/dist/components/layout/LayoutContainer.js +5 -3
  6. package/dist/components/layout/RPDefaultLayout.js +5 -3
  7. package/dist/components/layout/RPLayout.js +5 -3
  8. package/dist/components/layout/sidebar/RPSidebar.js +5 -3
  9. package/dist/components/layout/sidebar/Thumbnail.js +5 -3
  10. package/dist/components/layout/sidebar/Thumbnails.js +5 -3
  11. package/dist/components/layout/toolbar/DocumentDialog.js +5 -3
  12. package/dist/components/layout/toolbar/FileDownloadTool.js +5 -3
  13. package/dist/components/layout/toolbar/MostPageTool.js +5 -3
  14. package/dist/components/layout/toolbar/OtherTool.js +5 -3
  15. package/dist/components/layout/toolbar/Paginate.js +5 -3
  16. package/dist/components/layout/toolbar/PrintTool.js +5 -3
  17. package/dist/components/layout/toolbar/RPMoreOptions.js +6 -4
  18. package/dist/components/layout/toolbar/RPToolbar.js +5 -3
  19. package/dist/components/layout/toolbar/RPToolbarEnd.js +5 -3
  20. package/dist/components/layout/toolbar/SearchResultNavigator.js +5 -3
  21. package/dist/components/layout/toolbar/SearchTool.js +5 -3
  22. package/dist/components/layout/toolbar/ThumbnailTool.js +6 -4
  23. package/dist/components/layout/toolbar/ToolbarCustom.js +6 -4
  24. package/dist/components/layout/toolbar/ToolbarDefault.js +6 -4
  25. package/dist/components/layout/toolbar/ToolbarLayout.js +6 -4
  26. package/dist/components/layout/toolbar/ZoomTool.js +3 -2
  27. package/dist/components/layout/toolbar/tools/DocumentPropertiesTool.js +6 -4
  28. package/dist/components/layout/toolbar/tools/FileDownloadTool.js +6 -4
  29. package/dist/components/layout/toolbar/tools/InputPageTool.js +6 -4
  30. package/dist/components/layout/toolbar/tools/NextPageTool.js +5 -3
  31. package/dist/components/layout/toolbar/tools/PreviousPageTool.js +6 -4
  32. package/dist/components/layout/toolbar/tools/PrintTool.js +6 -4
  33. package/dist/components/layout/toolbar/tools/ThumbnailTool.js +6 -4
  34. package/dist/components/layout/toolbar/tools/ZoomInTool.js +3 -2
  35. package/dist/components/layout/toolbar/tools/ZoomLevelTool.js +3 -2
  36. package/dist/components/layout/toolbar/tools/ZoomOutTool.js +3 -2
  37. package/dist/components/layout/toolbar/tools/defaults/RPHorizontalBar.js +5 -3
  38. package/dist/components/layout/toolbar/tools/defaults/RPVerticalBar.js +6 -4
  39. package/dist/components/layout/toolbar/tools/more-options/FileDownloadTool.js +6 -4
  40. package/dist/components/layout/toolbar/tools/more-options/FileUploadTool.js +6 -4
  41. package/dist/components/layout/toolbar/tools/more-options/MostPageTool.js +6 -4
  42. package/dist/components/layout/toolbar/tools/more-options/PrintTool.js +6 -4
  43. package/dist/components/page/AnnotationLayer.js +5 -3
  44. package/dist/components/page/CanvasLayer.js +5 -3
  45. package/dist/components/page/CustomElement.js +7 -2
  46. package/dist/components/page/DualPage.js +5 -3
  47. package/dist/components/page/RPPage.js +4 -2
  48. package/dist/components/page/SinglePage.js +5 -3
  49. package/dist/components/page/TextHighlightLayer.js +5 -3
  50. package/dist/components/page/TextLayer.js +5 -3
  51. package/dist/components/ui/LoadingIndicator.js +5 -3
  52. package/dist/contexts/DimensionPagesContext.js +10 -9
  53. package/dist/contexts/ElementPageContext.js +92 -49
  54. package/dist/contexts/EventCallbackContext.js +30 -0
  55. package/dist/contexts/GlobalCurrentPage.js +13 -10
  56. package/dist/contexts/PagesRotateContext.js +21 -15
  57. package/dist/contexts/PaginationContext.js +7 -5
  58. package/dist/contexts/PrintContext.js +7 -5
  59. package/dist/contexts/RPDocumentContext.js +21 -19
  60. package/dist/contexts/RenderQueueProvider.js +7 -5
  61. package/dist/contexts/SearchContext.js +7 -5
  62. package/dist/contexts/ThumbnailsContext.js +7 -5
  63. package/dist/contexts/ZoomContext.js +13 -12
  64. package/dist/main.js +86 -84
  65. package/dist/types/contexts/EventCallbackContext.d.ts +5 -0
  66. package/dist/types/utils/getElementPositionInPage.d.ts +5 -0
  67. package/dist/types/utils/link_service.d.ts +8 -0
  68. package/dist/types/utils/types.d.ts +10 -1
  69. package/dist/utils/getElementPositionInPage.js +84 -0
  70. package/dist/utils/hooks/useFileDownload.js +5 -3
  71. package/dist/utils/hooks/useLicense.js +1 -1
  72. package/dist/utils/hooks/useLoadPdf.js +49 -47
  73. package/dist/utils/hooks/useLoadWorker.js +8 -8
  74. package/dist/utils/hooks/usePageRotateContext.js +3 -2
  75. package/dist/utils/hooks/usePaginate.js +5 -3
  76. package/dist/utils/hooks/usePinch.js +15 -14
  77. package/dist/utils/hooks/usePresentPage.js +5 -3
  78. package/dist/utils/hooks/usePrint.js +5 -3
  79. package/dist/utils/hooks/useScrollToPage.js +4 -2
  80. package/dist/utils/hooks/useSearch.js +4 -2
  81. package/dist/utils/hooks/useThumbnail.js +5 -3
  82. package/dist/utils/hooks/useVirtualReactWindow.js +5 -3
  83. package/dist/utils/injectPrintCSS.js +11 -11
  84. package/dist/utils/link_service.js +14 -5
  85. package/dist/utils/renderPage.js +1 -0
  86. package/package.json +4 -4
@@ -0,0 +1,84 @@
1
+ function g(e, o) {
2
+ !e || typeof e != "object" || Object.entries(e).forEach(([d, i]) => {
3
+ if (i == null)
4
+ return;
5
+ const s = d.replace(/([A-Z])/g, "-$1").toLowerCase(), n = [
6
+ "width",
7
+ "height",
8
+ "top",
9
+ "right",
10
+ "bottom",
11
+ "left",
12
+ "margin",
13
+ "margin-top",
14
+ "margin-right",
15
+ "margin-bottom",
16
+ "margin-left",
17
+ "padding",
18
+ "padding-top",
19
+ "padding-right",
20
+ "padding-bottom",
21
+ "padding-left",
22
+ "border-width",
23
+ "border-top-width",
24
+ "border-right-width",
25
+ "border-bottom-width",
26
+ "border-left-width",
27
+ "font-size",
28
+ "line-height",
29
+ "letter-spacing",
30
+ "word-spacing",
31
+ "min-width",
32
+ "min-height",
33
+ "max-width",
34
+ "max-height",
35
+ "flex-basis",
36
+ "grid-gap",
37
+ "grid-row-gap",
38
+ "grid-column-gap"
39
+ ];
40
+ let t;
41
+ typeof i == "number" && i !== 0 ? t = n.includes(s) ? `${i}px` : String(i) : t = String(i), o.style.setProperty(s, t);
42
+ });
43
+ }
44
+ const f = (e, o, d, i, s) => {
45
+ let n = "center";
46
+ switch (i) {
47
+ case 90:
48
+ n = `${e.width / 2}px ${e.width / 2}px`;
49
+ break;
50
+ case -90:
51
+ case 270:
52
+ n = `${e.height / 2}px ${e.height / 2}px`;
53
+ break;
54
+ default:
55
+ n = "center";
56
+ }
57
+ const t = document.createElement("div");
58
+ t.id = "parent-element", t.style.width = `${e.width}px`, t.style.height = `${e.height}px`, t.style.setProperty("--scale-factor", s.toString()), t.style.setProperty("--rotation", i.toString()), t.style.setProperty("--transform-origin", n), t.style.left = "-99999px", t.style.visibility = "hidden", t.style.position = "absolute";
59
+ const l = document.createElement("div");
60
+ l.style.position = "relative", l.style.width = "100%", l.style.height = "100%", t.appendChild(l);
61
+ let r;
62
+ if (d instanceof HTMLElement)
63
+ r = d.cloneNode(!0), l.appendChild(r);
64
+ else {
65
+ const p = d.props;
66
+ r = document.createElement("div"), p.style && g(p.style, r), p.className && (r.className = p.className), l.appendChild(r);
67
+ }
68
+ o.appendChild(t);
69
+ const c = t.getBoundingClientRect(), h = r.getBoundingClientRect();
70
+ o.removeChild(t);
71
+ const a = {
72
+ top: o.clientHeight / 2,
73
+ left: o.clientWidth / 2
74
+ };
75
+ return {
76
+ left: h.left - c.left - a.left,
77
+ top: h.top - c.top - a.top,
78
+ width: h.width,
79
+ height: h.height
80
+ };
81
+ };
82
+ export {
83
+ f as getElementPagePosition
84
+ };
@@ -2,7 +2,7 @@ import "react/jsx-runtime";
2
2
  import "react";
3
3
  import "../../contexts/RPDocumentContext.js";
4
4
  import "../../contexts/DocumentPasswordContext.js";
5
- import { b as Er } from "../../ToolbarLayout.module-89451ab3.js";
5
+ import { b as Hr } from "../../ToolbarLayout.module-185b677e.js";
6
6
  import "../../contexts/DarkModeContext.js";
7
7
  import "../../contexts/RotationContext.js";
8
8
  import "../../contexts/LayerContext.js";
@@ -30,6 +30,7 @@ import "../../contexts/LoaderContext.js";
30
30
  import "../../contexts/ToolComponentContext.js";
31
31
  import "../../contexts/IconToolContext.js";
32
32
  import "../../contexts/OtherToolContext.js";
33
+ import "../../contexts/EventCallbackContext.js";
33
34
  import "../../components/RPConfig.js";
34
35
  import "../../components/layout/Container.js";
35
36
  import "../../contexts/ViewportContext.js";
@@ -82,13 +83,14 @@ import "../../components/page/CustomElement.js";
82
83
  import "../getZoomLevel.js";
83
84
  import "./useDebounce.js";
84
85
  import "./useLicense.js";
86
+ import "../getScrollDistance.js";
87
+ import "../getElementPositionInPage.js";
85
88
  import "../calculatePage.js";
86
89
  import "./useMousePressed.js";
87
90
  import "./useGrabScroll.js";
88
91
  import "./usePinch.js";
89
92
  import "../../components/ui/PasswordModal.js";
90
93
  import "./useLocalization.js";
91
- import "../getScrollDistance.js";
92
94
  import "../getWordPositionInPage.js";
93
95
  import "../smoothScrollTo.js";
94
96
  import "../../components/layout/toolbar/FileUploadTool.js";
@@ -136,5 +138,5 @@ import "./useLoadWorker.js";
136
138
  import "../../components/icons/LightPdfIcon.js";
137
139
  import "../../components/icons/DarkPdfIcon.js";
138
140
  export {
139
- Er as useFileDownload
141
+ Hr as useFileDownload
140
142
  };
@@ -1,6 +1,6 @@
1
1
  import { useState as E, useCallback as h, useEffect as A } from "react";
2
2
  import { appConsole as l } from "../appConsole.js";
3
- const b = /* @__PURE__ */ new Date("2025-11-03T08:03:37.519Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
3
+ const b = /* @__PURE__ */ new Date("2025-11-26T01:53:04.326Z"), d = "Please visit https://www.react-pdf.dev/manage-license/ to generate a new license key.", s = {
4
4
  invalidLicense: `You are currently using without a valid license. ${d}`,
5
5
  mismatchedDomain: `Your license key is not valid for the current domain / IP. ${d}`,
6
6
  expired: `Your license key has expired. ${d}`,
@@ -1,80 +1,82 @@
1
- import { useState as a, useRef as N, useEffect as k } from "react";
2
- import * as x from "pdfjs-dist";
3
- import { ErrorType as O } from "../types.js";
4
- import { getThumbnailViewport as U } from "../getThumbnailViewport.js";
5
- import { useConfigContext as h } from "../../contexts/ConfigContext.js";
6
- import { useDocumentPasswordContext as j } from "../../contexts/DocumentPasswordContext.js";
1
+ import { useState as a, useRef as O, useEffect as T } from "react";
2
+ import * as C from "pdfjs-dist";
3
+ import { ErrorType as U } from "../types.js";
4
+ import { getThumbnailViewport as h } from "../getThumbnailViewport.js";
5
+ import { useConfigContext as j } from "../../contexts/ConfigContext.js";
6
+ import { useDocumentPasswordContext as A } from "../../contexts/DocumentPasswordContext.js";
7
7
  import "../../th_TH-d627cd51.js";
8
8
  import "react/jsx-runtime";
9
9
  import "../appConsole.js";
10
- const K = (m, t, V = {}) => {
11
- const [n, C] = a(), { workerUrlAdded: y } = h(), [I, L] = a(/* @__PURE__ */ new Map()), d = N(), [S, f] = a(0), [P, T] = a(!1), [q, v] = a(), { password: u, passwordError: D, setPasswordError: c, passwordRequired: g, setPasswordRequired: p } = j(), { onLoadError: i, onLoaded: w } = V;
12
- return k(() => {
13
- if (!y || !m)
10
+ const Q = (l, s, I = {}) => {
11
+ const [n, S] = a(), { workerUrlAdded: k } = j(), [q, x] = a(/* @__PURE__ */ new Map()), d = O(), [m, P] = a(0), [g, V] = a(!1), [v, D] = a(), { password: u, passwordError: N, setPasswordError: c, passwordRequired: p, setPasswordRequired: w } = A(), { onLoadError: i, onLoaded: E, onLoadProgress: R } = I;
12
+ return T(() => {
13
+ R && R(m);
14
+ }, [m, R]), T(() => {
15
+ if (!k || !l)
14
16
  return;
15
- f(0), d.current = Date.now();
16
- const r = d.current, E = {
17
- url: m,
18
- cMapPacked: (t == null ? void 0 : t.isCompressed) ?? !0,
19
- ...(t == null ? void 0 : t.url) && { cMapUrl: t.url },
17
+ P(0), d.current = Date.now();
18
+ const r = d.current, b = {
19
+ url: l,
20
+ cMapPacked: (s == null ? void 0 : s.isCompressed) ?? !0,
21
+ ...(s == null ? void 0 : s.url) && { cMapUrl: s.url },
20
22
  ...u && { password: u },
21
- verbosity: x.VerbosityLevel.ERRORS
23
+ verbosity: C.VerbosityLevel.ERRORS
22
24
  };
23
25
  try {
24
- const e = x.getDocument(E);
26
+ const e = C.getDocument(b);
25
27
  e.onProgress = (o) => {
26
28
  if (r === d.current) {
27
- const { loaded: R, total: l } = o, b = l ? Math.min(100, Math.round(R / l * 100)) : 0;
28
- f(b);
29
+ const { loaded: y, total: f } = o, L = f ? Math.min(100, Math.round(y / f * 100)) : 0;
30
+ P(L);
29
31
  }
30
- }, T(!0);
31
- const s = e.promise.then((o) => (r === d.current && (C(o), f(100)), w && w(o), p(!1), c(""), o)).catch((o) => {
32
- o instanceof Error && o.name === "PasswordException" ? (p(!0), c(o.message || "Password required")) : o instanceof Error && o.name === "InvalidPDFException" && u ? (p(!0), c("Incorrect password")) : i && i(o);
32
+ }, V(!0);
33
+ const t = e.promise.then((o) => (r === d.current && (S(o), P(100)), E && E(o), w(!1), c(""), o)).catch((o) => {
34
+ o instanceof Error && o.name === "PasswordException" ? (w(!0), c(o.message || "Password required")) : o instanceof Error && o.name === "InvalidPDFException" && u ? (w(!0), c("Incorrect password")) : i && i(o);
33
35
  }).finally(() => {
34
- T(!1);
36
+ V(!1);
35
37
  });
36
38
  return () => {
37
- s.finally(() => {
39
+ t.finally(() => {
38
40
  e.destroy();
39
41
  });
40
42
  };
41
43
  } catch (e) {
42
- v(O.NOT_SUPPORTED), i && i(e);
44
+ D(U.NOT_SUPPORTED), i && i(e);
43
45
  }
44
- }, [m, y, u, i, w]), k(() => {
45
- if (g)
46
+ }, [l, k, u, i, E]), T(() => {
47
+ if (p)
46
48
  return;
47
49
  const r = /* @__PURE__ */ new Map();
48
- if (!n || P) {
49
- L(r);
50
+ if (!n || g) {
51
+ x(r);
50
52
  return;
51
53
  }
52
- const E = n.numPages, e = [];
53
- for (let s = 1; s <= E; s++) {
54
- const o = n.getPage(s);
54
+ const b = n.numPages, e = [];
55
+ for (let t = 1; t <= b; t++) {
56
+ const o = n.getPage(t);
55
57
  e.push(o);
56
58
  }
57
- Promise.all(e).then((s) => {
58
- s.map((o) => {
59
- const { thumbnailViewport: R, scale: l } = U(o), b = o.getViewport();
59
+ Promise.all(e).then((t) => {
60
+ t.map((o) => {
61
+ const { thumbnailViewport: y, scale: f } = h(o), L = o.getViewport();
60
62
  r.set(o.pageNumber, {
61
63
  page: o,
62
- thumbnailViewport: R,
63
- thumbnailScale: l,
64
- defaultRotation: b.rotation
64
+ thumbnailViewport: y,
65
+ thumbnailScale: f,
66
+ defaultRotation: L.rotation
65
67
  });
66
- }), L(r);
68
+ }), x(r);
67
69
  });
68
- }, [n, P, g]), {
70
+ }, [n, g, p]), {
69
71
  pdf: n,
70
- pages: I,
71
- loading: P,
72
- error: q,
73
- loadingProgress: S,
74
- passwordRequired: g,
75
- passwordError: D
72
+ pages: q,
73
+ loading: g,
74
+ error: v,
75
+ loadingProgress: m,
76
+ passwordRequired: p,
77
+ passwordError: N
76
78
  };
77
79
  };
78
80
  export {
79
- K as useLoadPdf
81
+ Q as useLoadPdf
80
82
  };