@react-pdf-kit/viewer 2.1.0-beta.1 → 2.1.0-beta.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.
- package/README.md +84 -49
- package/dist/components/layout/toolbar/DocumentDialog.js +36 -28
- package/dist/utils/highlight.js +36 -36
- package/dist/utils/hooks/useHighlight.js +78 -40
- package/dist/utils/hooks/useLicense.js +1 -1
- package/dist/utils/hooks/usePrint.js +69 -76
- package/dist/utils/injectPrintCSS.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<a href="https://www.react-pdf.dev/" target="_blank">
|
|
2
|
+
<a href="https://www.react-pdf-kit.dev/" target="_blank">
|
|
3
3
|
<picture>
|
|
4
4
|
<source srcset="https://raw.githubusercontent.com/pdf-viewer-react/react-pdf/2308e7d88cde64bf343f1509150ebf6c91a15664/assets/img/react-pdf_cover.webp" width="100%">
|
|
5
5
|
<img alt="React PDF" src="https://raw.githubusercontent.com/pdf-viewer-react/react-pdf/2308e7d88cde64bf343f1509150ebf6c91a15664/assets/img/react-pdf_cover.webp" width="100%">
|
|
@@ -9,28 +9,28 @@
|
|
|
9
9
|
|
|
10
10
|
<br/>
|
|
11
11
|
<div align="center">
|
|
12
|
-
Works seamlessly on your React.js websites. Fast, Customizable and Web Responsive PDF viewer. Save you weeks of development time.
|
|
12
|
+
Works seamlessly on your React or Next.js websites. Fast, Customizable and Web Responsive PDF viewer. Save you weeks of development time.
|
|
13
13
|
</div>
|
|
14
14
|
<br/>
|
|
15
15
|
|
|
16
16
|
<div align="center">
|
|
17
17
|
|
|
18
|
-
[React PDF Home][reactpdf] - [License](#page_facing_up-license) - [Documentation][reactpdf-docs]
|
|
18
|
+
[React PDF Kit Home][reactpdf] - [License](#page_facing_up-license) - [Documentation][reactpdf-docs]
|
|
19
19
|
|
|
20
|
-
[][npm]
|
|
21
21
|
[][twitter]
|
|
22
22
|
|
|
23
23
|
</div>
|
|
24
24
|
|
|
25
|
-
# :star: Why React PDF
|
|
25
|
+
# :star: Why React PDF Kit
|
|
26
26
|
|
|
27
|
-
- **Save Weeks of Development Time**: React PDF simplifies PDF integration with ready-to-use tools, minimizing the need for custom development and saving you valuable time.
|
|
27
|
+
- **Save Weeks of Development Time**: React PDF Kit simplifies PDF integration with ready-to-use tools, minimizing the need for custom development and saving you valuable time.
|
|
28
28
|
- **Tailored for React.js**: React PDF is native to React.js, ensuring smooth integration into your projects.
|
|
29
29
|
- **Customizability at Its Core**: Built with flexibility in mind, allowing you to match your application’s unique style and functionality.
|
|
30
30
|
- **High-Performance & Rapid Rendering**: Optimized for rendering large PDFs efficiently, React PDF delivers lightning-fast load times with features like virtual scrolling.
|
|
31
|
-
- **Accessibility**: Designed with inclusivity in mind, React PDF supports ARIA attributes, catering to diverse user bases.
|
|
32
|
-
- **Modern Browser Compatibility**:
|
|
33
|
-
- **Active Development & Support**: With regular updates and a responsive support team, React PDF evolves to meet developer needs.
|
|
31
|
+
- **Accessibility**: Designed with inclusivity in mind, React PDF Kit supports ARIA attributes, catering to diverse user bases.
|
|
32
|
+
- **Modern Browser Compatibility**: The React PDF Viewer components seamlessly across modern browsers, eliminating compatibility headaches.
|
|
33
|
+
- **Active Development & Support**: With regular updates and a responsive support team, React PDF Kit evolves to meet developer needs.
|
|
34
34
|
|
|
35
35
|
# 📜 Background
|
|
36
36
|
|
|
@@ -47,35 +47,58 @@ As developers ourselves, we faced many issues such as browser incompatibility an
|
|
|
47
47
|
- 📂 **Document Management Tools**, including features like downloading and printing.
|
|
48
48
|
- 👁️ **Accessibility Support** to built-in support for ARIA attributes and tooltips, catering to diverse user bases.
|
|
49
49
|
|
|
50
|
-
For the full feature set, visit [React PDF Features](https://www.react-pdf.dev/features?utm_source=github).
|
|
50
|
+
For the full feature set, visit [React PDF Kit Features](https://www.react-pdf-kit.dev/features?utm_source=github&utm_medium=referral).
|
|
51
51
|
|
|
52
52
|
# :zap: Quick Start Guide
|
|
53
53
|
|
|
54
|
-
Here’s how to get started with React PDF in your React.js project:
|
|
54
|
+
Here’s how to get started with React PDF Kit in your React.js project:
|
|
55
55
|
|
|
56
|
-
## 1. Check
|
|
56
|
+
## 1. Check Prerequsities
|
|
57
57
|
|
|
58
|
-
Here are the basic system requirements to run the React PDF component:
|
|
58
|
+
Here are the basic system requirements to run the React PDF Viewer component:
|
|
59
59
|
|
|
60
60
|
- React version: >= 18.0
|
|
61
|
+
- React version: >= 19.0
|
|
61
62
|
|
|
62
|
-
If you are working with a React framework such as Next and Gatsby, React PDF can run smoothly as long as you are using React 18 and above.
|
|
63
|
+
If you are working with a React framework such as Next.js (App Router and Pages Router) or Gatsby, React PDF can run smoothly as long as you are using React 18 and above.
|
|
63
64
|
|
|
64
|
-
React PDF
|
|
65
|
+
React PDF also works well with other React.js UI libraries such as MUI, Ant Design and Chakra UI.
|
|
65
66
|
|
|
66
|
-
Although React PDF can run on most JavaScript module bundlers, it is more vigorously tested on Vite and Webpack.
|
|
67
|
+
Although React PDF Kit can run on most JavaScript module bundlers, it is more vigorously tested on Vite and Webpack.
|
|
67
68
|
|
|
68
69
|
_Remark: <br/>- If using TypeScript, it requires >= TypeScript 4.6._
|
|
69
70
|
|
|
70
71
|
### Browser support
|
|
71
72
|
|
|
73
|
+
Starting from [`@react-pdf-kit/viewer@^2.0.0`](https://www.npmjs.com/package/@react-pdf-kit/viewer), we officially support PDF.js 5 and default to PDF.js `5.4.530`.
|
|
74
|
+
|
|
75
|
+
As newer PDF.js versions rely on more modern browser APIs, minimum supported browser versions have changed. Please review the compatibility details below before choosing a PDF.js version.
|
|
76
|
+
|
|
77
|
+
#### Default (PDF.js 5.4.530)
|
|
78
|
+
|
|
79
|
+
React PDF Kit v2.0.0 defaults to PDF.js `5.4.530`.
|
|
80
|
+
|
|
72
81
|
| Chrome | Firefox | Edge | Safari | Safari iOS | Chrome Android |
|
|
73
82
|
| ------ | ------- | ---- | ------ | ---------- | -------------- |
|
|
74
|
-
|
|
|
83
|
+
| 126+ | 126+ | 126+ | 18.4+ | 18.4+ | 126+ |
|
|
84
|
+
|
|
85
|
+
<Aside>
|
|
86
|
+
It's currently not recommended to use a PDF.js worker version beyond `5.4.530` because it will support fewer browser versions.
|
|
87
|
+
</Aside>
|
|
88
|
+
|
|
89
|
+
#### Using PDF.js 4.10.38
|
|
90
|
+
|
|
91
|
+
If you need broader browser compatibility, you can continue using PDF.js `4.10.38`, which supports:
|
|
92
|
+
|
|
93
|
+
| Chrome | Firefox | Edge | Safari | Safari iOS | Chrome Android |
|
|
94
|
+
| ------ | ------- | ---- | ------ | ---------- | -------------- |
|
|
95
|
+
| 119+ | 115+ | 115+ | 17.4+ | 17.4+ | 126+ |
|
|
96
|
+
|
|
97
|
+
To change the version of PDF.js used, refer to [Dependency Override](https://docs.react-pdf-kit.dev/usage-guide/overriding-dependency?utm_source=github&utm_medium=referral) guide.
|
|
75
98
|
|
|
76
99
|
## 2. Install the Package
|
|
77
100
|
|
|
78
|
-
There are a few ways you can install React PDF, namely `bun`, `npm`, `pnpm` or `yarn`.
|
|
101
|
+
There are a few ways you can install React PDF Kit, namely `bun`, `npm`, `pnpm` or `yarn`.
|
|
79
102
|
|
|
80
103
|
### Using bun:
|
|
81
104
|
|
|
@@ -110,50 +133,42 @@ yarn add @react-pdf-kit/viewer
|
|
|
110
133
|
pnpm add @react-pdf-kit/viewer
|
|
111
134
|
```
|
|
112
135
|
|
|
113
|
-
For more information on how to use different package managers, please visit our [installation guide](https://docs.react-pdf.dev/introduction/getting-started
|
|
136
|
+
For more information on how to use different package managers, please visit our [installation guide](https://docs.react-pdf-kit.dev/introduction/getting-started/#installation?utm_source=github&utm_medium=referral).
|
|
114
137
|
|
|
115
138
|
## 3. Import and Use the Component
|
|
116
139
|
|
|
117
140
|
The following structure demonstrates how to build a React PDF viewer by importing and assembling components. This modular approach gives you the flexibility to customize the viewer as needed.
|
|
118
141
|
|
|
119
142
|
```tsx
|
|
120
|
-
<RPConfig>
|
|
121
|
-
{
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
{/* Theme customization (optional) */}
|
|
129
|
-
<RPDefaultLayout>
|
|
130
|
-
{' '}
|
|
131
|
-
{/* Default layout container */}
|
|
132
|
-
<RPPages /> {/* PDF pages renderer */}
|
|
133
|
-
</RPDefaultLayout>
|
|
134
|
-
</RPTheme>
|
|
135
|
-
</RPProvider>
|
|
143
|
+
<RPConfig> {/* Configuration license and pdfjs-dist worker */}
|
|
144
|
+
<RPTheme> {/* Theme customization (optional) */}
|
|
145
|
+
<RPProvider> {/* Viewer context provider */}
|
|
146
|
+
<RPLayout toolbar> {/* Provide the default toolbar structure */}
|
|
147
|
+
<RPPages /> {/* Render the actual PDF content */}
|
|
148
|
+
</RPLayout>
|
|
149
|
+
</RPProvider>
|
|
150
|
+
</RPTheme>
|
|
136
151
|
</RPConfig>
|
|
137
152
|
```
|
|
138
153
|
|
|
139
|
-
_Remark: For more information on each component, please refer to [Component](https://docs.react-pdf.dev/components/overview?utm_source=github)._
|
|
154
|
+
_Remark: For more information on each component, please refer to [Component](https://docs.react-pdf-kit.dev/components/overview?utm_source=github&utm_medium=referral)._
|
|
140
155
|
|
|
141
156
|
### Basic Usage
|
|
142
157
|
|
|
143
|
-
The most basic usage of React PDF viewer needs four components, namely: `RPConfig`, `RPProvider`, `
|
|
158
|
+
The most basic usage of React PDF viewer needs four components, namely: `RPConfig`, `RPProvider`, `RPLayout`, and `RPPages`.
|
|
144
159
|
|
|
145
160
|
Here's how to implement a basic PDF viewer in a React application:
|
|
146
161
|
|
|
147
162
|
```jsx
|
|
148
|
-
import { RPProvider,
|
|
163
|
+
import { RPProvider, RPLayout, RPPages, RPConfig } from '@react-pdf-kit/viewer'
|
|
149
164
|
|
|
150
165
|
const App = () => {
|
|
151
166
|
return (
|
|
152
167
|
<RPConfig>
|
|
153
168
|
<RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf">
|
|
154
|
-
<
|
|
169
|
+
<RPLayout toolbar style={{ height: '660px' }}>
|
|
155
170
|
<RPPages />
|
|
156
|
-
</
|
|
171
|
+
</RPLayout>
|
|
157
172
|
</RPProvider>
|
|
158
173
|
</RPConfig>
|
|
159
174
|
)
|
|
@@ -161,13 +176,13 @@ const App = () => {
|
|
|
161
176
|
export default App
|
|
162
177
|
```
|
|
163
178
|
|
|
164
|
-
The PDF viewer will automatically adjust to fit its container's dimensions. You can control the size by setting the `style` prop on `
|
|
179
|
+
The PDF viewer will automatically adjust to fit its container's dimensions. You can control the size by setting the `style` prop on `RPLayout`. For more information on using React PDF, visit our [basic usage guide](https://docs.react-pdf-kit.dev/introduction/basic-usage?utm_source=github&utm_medium=referral)
|
|
165
180
|
|
|
166
181
|
You may also check out our [Starter Toolkit](#pushpin-starter-toolkit) for examples to get you started.
|
|
167
182
|
|
|
168
183
|
### 4. Customize with Hooks and Props
|
|
169
184
|
|
|
170
|
-
To enhance React PDF further, we offer built-in hooks and props that let you fine-tune functionality, adjust appearance, and integrate custom behaviors into your application.
|
|
185
|
+
To enhance React PDF Kit further, we offer built-in hooks and props that let you fine-tune functionality, adjust appearance, and integrate custom behaviors into your application.
|
|
171
186
|
|
|
172
187
|
For detailed usage, refer to our [Documentation][reactpdf-docs].
|
|
173
188
|
|
|
@@ -176,11 +191,31 @@ For detailed usage, refer to our [Documentation][reactpdf-docs].
|
|
|
176
191
|
Here are some sample projects to get started on React PDF quickly:
|
|
177
192
|
|
|
178
193
|
1. [React (webpack) - JavaScript](https://github.com/react-pdf-kit/starter-rp-react-js-webpack)
|
|
179
|
-
2. [React (webpack) - TypeScript](https://github.com/
|
|
194
|
+
2. [React (webpack) - TypeScript](https://github.com/react-pdf-kit/starter-rp-react-ts-webpack)
|
|
180
195
|
3. [React (vite) - JavaScript](https://github.com/react-pdf-kit/starter-rp-react-js-vite)
|
|
181
196
|
4. [React (vite) - TypeScript](https://github.com/react-pdf-kit/starter-rp-react-ts-vite)
|
|
182
|
-
5. [
|
|
183
|
-
6. [Next -
|
|
197
|
+
5. [React (vite) - TypeScript - Turborepo](https://github.com/react-pdf-kit/starter-rp-react-vite-ts-turborepo)
|
|
198
|
+
6. [Next.js - JavaScript (App Router)](https://github.com/react-pdf-kit/starter-rp-nextjs-app-router-js)
|
|
199
|
+
7. [Next.js - TypeScript (App Router)](https://github.com/react-pdf-kit/starter-rp-nextjs-app-router-ts)
|
|
200
|
+
8. [Next.js - JavaScript (Pages Router)](https://github.com/react-pdf-kit/starter-rp-nextjs-pages-router-js)
|
|
201
|
+
9. [Next.js - TypeScript (Pages Router)](https://github.com/react-pdf-kit/starter-rp-nextjs-pages-router-ts)
|
|
202
|
+
10. [Next.js - TypeScript - Turborepo](https://github.com/react-pdf-kit/starter-rp-next-ts-turborepo)
|
|
203
|
+
11. [Remix - JavaScript](https://github.com/react-pdf-kit/starter-rp-remix-js)
|
|
204
|
+
12. [Remix - TypeScript](https://github.com/react-pdf-kit/starter-rp-remix-ts)
|
|
205
|
+
13. [Gatsby - JavaScript](https://github.com/react-pdf-kit/starter-rp-gatsby-js)
|
|
206
|
+
14. [Gatsby - TypeScript](https://github.com/react-pdf-kit/starter-rp-gatsby-ts)
|
|
207
|
+
15. [Docusaurus - JavaScript](https://github.com/react-pdf-kit/starter-rp-docusaurus-js)
|
|
208
|
+
16. [Docusaurus - TypeScript](https://github.com/react-pdf-kit/starter-rp-docusaurus-ts)
|
|
209
|
+
17. [Electron - JavaScript](https://github.com/react-pdf-kit/starter-rp-electron-js-vite)
|
|
210
|
+
18. [Electron - TypeScript](https://github.com/react-pdf-kit/starter-rp-electron-ts-vite)
|
|
211
|
+
19. [React Router - JavaScript](https://github.com/react-pdf-kit/starter-rp-react-router-js)
|
|
212
|
+
20. [React Router - TypeScript](https://github.com/react-pdf-kit/starter-rp-react-router-ts)
|
|
213
|
+
21. [TanStack - JavaScript](https://github.com/react-pdf-kit/starter-rp-tanstack-router-js)
|
|
214
|
+
22. [TanStack - TypeScript](https://github.com/react-pdf-kit/starter-rp-tanstack-router-ts)
|
|
215
|
+
|
|
216
|
+
# 📝 Changelog
|
|
217
|
+
|
|
218
|
+
Check out our latest release [v2.0.0 (20 February 2026)](https://docs.react-pdf-kit.dev/introduction/changelog/#v200-20-february-2026?utm_source=github&utm_medium=referral)
|
|
184
219
|
|
|
185
220
|
# :raising_hand: Need Help?
|
|
186
221
|
|
|
@@ -188,9 +223,9 @@ We are more than happy to help you. If you have any questions, run into any erro
|
|
|
188
223
|
|
|
189
224
|
# :page_facing_up: License
|
|
190
225
|
|
|
191
|
-
React PDF is distributed under our proprietary license. Please refer to our [License page](https://www.react-pdf.dev/license-agreement?utm_source=github) file for more details.
|
|
226
|
+
React PDF Kit is distributed under our proprietary license. Please refer to our [License page](https://www.react-pdf-kit.dev/license-agreement?utm_source=github&utm_medium=referral) file for more details.
|
|
192
227
|
|
|
193
|
-
If you would like to use React PDF commercially, please purchase a license from [our website][reactpdf] or reach out to us directly at [
|
|
228
|
+
If you would like to use React PDF commercially, please purchase a license from [our website][reactpdf] or reach out to us directly at [https://www.react-pdf-kit.dev/contact-us](https://www.react-pdf-kit.dev/contact-us?utm_source=github&utm_medium=referral).
|
|
194
229
|
|
|
195
230
|
# Acknowledgement
|
|
196
231
|
|
|
@@ -198,7 +233,7 @@ If you would like to use React PDF commercially, please purchase a license from
|
|
|
198
233
|
- [Img Shields](https://shields.io)
|
|
199
234
|
- [React.js](https://reactjs.org/)
|
|
200
235
|
|
|
201
|
-
[reactpdf]: https://www.react-pdf.dev
|
|
202
|
-
[reactpdf-docs]: https://docs.react-pdf.dev
|
|
236
|
+
[reactpdf]: https://www.react-pdf-kit.dev/?utm_source=github&utm_medium=referral
|
|
237
|
+
[reactpdf-docs]: https://docs.react-pdf-kit.dev/?utm_source=github&utm_medium=referral
|
|
203
238
|
[npm]: https://www.npmjs.com/package/@react-pdf-kit/viewer
|
|
204
239
|
[twitter]: https://www.x.com/ReactPDF
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { jsx as a, jsxs as C, Fragment as x } from "react/jsx-runtime";
|
|
2
2
|
import * as c from "react";
|
|
3
3
|
import { useMemo as J } from "react";
|
|
4
|
-
import { c as Q, a as
|
|
5
|
-
import { D as te, u as
|
|
4
|
+
import { c as Q, a as R, P as D, b as v, d as y, e as X, f as M, g as ee } from "../../../index-c0faa594.js";
|
|
5
|
+
import { D as te, u as P } from "../../../index-e3ee9457.js";
|
|
6
6
|
import { R as oe, h as re, u as ne, F as ie, P as ae } from "../../../Combination-136ff99c.js";
|
|
7
7
|
import { useLayoutContainer as le } from "../../../contexts/LayoutContainerContext.js";
|
|
8
8
|
import { CloseIcon as ce } from "../../icons/CloseIcon.js";
|
|
9
9
|
import { dateFormatter as A } from "../../../utils/dateFormatter.js";
|
|
10
10
|
import { useDocumentContext as se } from "../../../contexts/RPDocumentContext.js";
|
|
11
11
|
import { PropertyItem as ue } from "./PropertyItem.js";
|
|
12
|
-
import { useOtherToolContext as
|
|
13
|
-
import { useLocalizationContext as
|
|
12
|
+
import { useOtherToolContext as pe } from "../../../contexts/OtherToolContext.js";
|
|
13
|
+
import { useLocalizationContext as de } from "../../../contexts/LocalizationContext.js";
|
|
14
14
|
import "react-dom";
|
|
15
15
|
import "../../../utils/hooks/useLoadPdf.js";
|
|
16
16
|
import "pdfjs-dist";
|
|
@@ -32,7 +32,7 @@ var h = "Dialog", [T, tt] = Q(h), [fe, u] = T(h), L = (t) => {
|
|
|
32
32
|
defaultOpen: e,
|
|
33
33
|
onOpenChange: o,
|
|
34
34
|
modal: l = !0
|
|
35
|
-
} = t, s = c.useRef(null),
|
|
35
|
+
} = t, s = c.useRef(null), p = c.useRef(null), [d, g] = M({
|
|
36
36
|
prop: i,
|
|
37
37
|
defaultProp: e ?? !1,
|
|
38
38
|
onChange: o,
|
|
@@ -43,11 +43,11 @@ var h = "Dialog", [T, tt] = Q(h), [fe, u] = T(h), L = (t) => {
|
|
|
43
43
|
{
|
|
44
44
|
scope: r,
|
|
45
45
|
triggerRef: s,
|
|
46
|
-
contentRef:
|
|
47
|
-
contentId:
|
|
48
|
-
titleId:
|
|
49
|
-
descriptionId:
|
|
50
|
-
open:
|
|
46
|
+
contentRef: p,
|
|
47
|
+
contentId: P(),
|
|
48
|
+
titleId: P(),
|
|
49
|
+
descriptionId: P(),
|
|
50
|
+
open: d,
|
|
51
51
|
onOpenChange: g,
|
|
52
52
|
onOpenToggle: c.useCallback(() => g((_) => !_), [g]),
|
|
53
53
|
modal: l,
|
|
@@ -58,7 +58,7 @@ var h = "Dialog", [T, tt] = Q(h), [fe, u] = T(h), L = (t) => {
|
|
|
58
58
|
L.displayName = h;
|
|
59
59
|
var w = "DialogTrigger", me = c.forwardRef(
|
|
60
60
|
(t, r) => {
|
|
61
|
-
const { __scopeDialog: n, ...i } = t, e = u(w, n), o =
|
|
61
|
+
const { __scopeDialog: n, ...i } = t, e = u(w, n), o = R(r, e.triggerRef);
|
|
62
62
|
return /* @__PURE__ */ a(
|
|
63
63
|
D.button,
|
|
64
64
|
{
|
|
@@ -115,7 +115,7 @@ var ve = ee("DialogOverlay.RemoveScroll"), De = c.forwardRef(
|
|
|
115
115
|
k.displayName = m;
|
|
116
116
|
var _e = c.forwardRef(
|
|
117
117
|
(t, r) => {
|
|
118
|
-
const n = u(m, t.__scopeDialog), i = c.useRef(null), e =
|
|
118
|
+
const n = u(m, t.__scopeDialog), i = c.useRef(null), e = R(r, n.contentRef, i);
|
|
119
119
|
return c.useEffect(() => {
|
|
120
120
|
const o = i.current;
|
|
121
121
|
if (o)
|
|
@@ -157,17 +157,17 @@ var _e = c.forwardRef(
|
|
|
157
157
|
(l = t.onCloseAutoFocus) == null || l.call(t, o), o.defaultPrevented || (i.current || (s = n.triggerRef.current) == null || s.focus(), o.preventDefault()), i.current = !1, e.current = !1;
|
|
158
158
|
},
|
|
159
159
|
onInteractOutside: (o) => {
|
|
160
|
-
var
|
|
161
|
-
(
|
|
160
|
+
var p, d;
|
|
161
|
+
(p = t.onInteractOutside) == null || p.call(t, o), o.defaultPrevented || (i.current = !0, o.detail.originalEvent.type === "pointerdown" && (e.current = !0));
|
|
162
162
|
const l = o.target;
|
|
163
|
-
((
|
|
163
|
+
((d = n.triggerRef.current) == null ? void 0 : d.contains(l)) && o.preventDefault(), o.detail.originalEvent.type === "focusin" && e.current && o.preventDefault();
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
), q = c.forwardRef(
|
|
169
169
|
(t, r) => {
|
|
170
|
-
const { __scopeDialog: n, trapFocus: i, onOpenAutoFocus: e, onCloseAutoFocus: o, ...l } = t, s = u(m, n),
|
|
170
|
+
const { __scopeDialog: n, trapFocus: i, onOpenAutoFocus: e, onCloseAutoFocus: o, ...l } = t, s = u(m, n), p = c.useRef(null), d = R(r, p);
|
|
171
171
|
return ne(), /* @__PURE__ */ C(x, { children: [
|
|
172
172
|
/* @__PURE__ */ a(
|
|
173
173
|
ie,
|
|
@@ -186,7 +186,7 @@ var _e = c.forwardRef(
|
|
|
186
186
|
"aria-labelledby": s.titleId,
|
|
187
187
|
"data-state": E(s.open),
|
|
188
188
|
...l,
|
|
189
|
-
ref:
|
|
189
|
+
ref: d,
|
|
190
190
|
onDismiss: () => s.onOpenChange(!1)
|
|
191
191
|
}
|
|
192
192
|
)
|
|
@@ -194,7 +194,7 @@ var _e = c.forwardRef(
|
|
|
194
194
|
),
|
|
195
195
|
/* @__PURE__ */ C(x, { children: [
|
|
196
196
|
/* @__PURE__ */ a(he, { titleId: s.titleId }),
|
|
197
|
-
/* @__PURE__ */ a(
|
|
197
|
+
/* @__PURE__ */ a(Re, { contentRef: p, descriptionId: s.descriptionId })
|
|
198
198
|
] })
|
|
199
199
|
] });
|
|
200
200
|
}
|
|
@@ -243,8 +243,8 @@ For more information, see https://radix-ui.com/primitives/docs/components/${r.do
|
|
|
243
243
|
return c.useEffect(() => {
|
|
244
244
|
t && (document.getElementById(t) || console.error(n));
|
|
245
245
|
}, [n, t]), null;
|
|
246
|
-
},
|
|
247
|
-
const i = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${V(
|
|
246
|
+
}, Pe = "DialogDescriptionWarning", Re = ({ contentRef: t, descriptionId: r }) => {
|
|
247
|
+
const i = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${V(Pe).contentName}}.`;
|
|
248
248
|
return c.useEffect(() => {
|
|
249
249
|
var o;
|
|
250
250
|
const e = (o = t.current) == null ? void 0 : o.getAttribute("aria-describedby");
|
|
@@ -260,14 +260,14 @@ const f = {
|
|
|
260
260
|
"rp-dialog-close": "_rp-dialog-close_slqo7_47",
|
|
261
261
|
"rp-properties-divider": "_rp-properties-divider_slqo7_55"
|
|
262
262
|
}, rt = () => {
|
|
263
|
-
const { pdfProperties: t } = se(), { container: r } = le(), { activeDocumentProperties: n, setActiveDocumentProperties: i } =
|
|
263
|
+
const { pdfProperties: t } = se(), { container: r } = le(), { activeDocumentProperties: n, setActiveDocumentProperties: i } = pe(), { localeMessages: e } = de(), o = J(() => {
|
|
264
264
|
if (!t)
|
|
265
265
|
return [];
|
|
266
266
|
const {
|
|
267
267
|
fileSize: l,
|
|
268
268
|
filename: s,
|
|
269
|
-
title:
|
|
270
|
-
author:
|
|
269
|
+
title: p,
|
|
270
|
+
author: d,
|
|
271
271
|
subject: g,
|
|
272
272
|
createdOn: _,
|
|
273
273
|
creator: H,
|
|
@@ -281,8 +281,8 @@ const f = {
|
|
|
281
281
|
{ label: e == null ? void 0 : e.propertiesFilenameLabel, value: s },
|
|
282
282
|
{ label: e == null ? void 0 : e.propertiesFileSizeLabel, value: l },
|
|
283
283
|
{ separate: !0 },
|
|
284
|
-
{ label: e == null ? void 0 : e.propertiesTitleLabel, value:
|
|
285
|
-
{ label: e == null ? void 0 : e.propertiesAuthorLabel, value:
|
|
284
|
+
{ label: e == null ? void 0 : e.propertiesTitleLabel, value: p },
|
|
285
|
+
{ label: e == null ? void 0 : e.propertiesAuthorLabel, value: d },
|
|
286
286
|
{ label: e == null ? void 0 : e.propertiesSubjectLabel, value: g },
|
|
287
287
|
{ label: e == null ? void 0 : e.propertiesKeywordLabel, value: K },
|
|
288
288
|
{ label: e == null ? void 0 : e.propertiesCreatorLabel, value: H },
|
|
@@ -302,9 +302,17 @@ const f = {
|
|
|
302
302
|
}, [t, e]);
|
|
303
303
|
return /* @__PURE__ */ a(ye, { open: n, onOpenChange: i, children: /* @__PURE__ */ a(Ne, { container: r, children: /* @__PURE__ */ C("div", { className: f["rp-dialog-wrapper"], children: [
|
|
304
304
|
/* @__PURE__ */ a(Oe, { className: f["rp-dialog-overlay"] }),
|
|
305
|
-
/* @__PURE__ */ C(Ee, { className: f["rp-document-dialog"],
|
|
306
|
-
/* @__PURE__ */ a(Ie, {
|
|
307
|
-
/* @__PURE__ */ a(
|
|
305
|
+
/* @__PURE__ */ C(Ee, { className: f["rp-document-dialog"], children: [
|
|
306
|
+
/* @__PURE__ */ a(Ie, { className: f["rp-dialog-title"], children: (e == null ? void 0 : e.documentPropertiesLabel) ?? "Document properties" }),
|
|
307
|
+
/* @__PURE__ */ a(
|
|
308
|
+
"div",
|
|
309
|
+
{
|
|
310
|
+
className: f["rp-document-properties"],
|
|
311
|
+
role: "region",
|
|
312
|
+
"aria-label": (e == null ? void 0 : e.documentPropertiesLabel) ?? "Document properties",
|
|
313
|
+
children: o.map((l, s) => /* @__PURE__ */ a("div", { children: l.separate ? /* @__PURE__ */ a("div", { className: f["rp-properties-divider"], role: "separator", "aria-orientation": "horizontal" }) : /* @__PURE__ */ a(ue, { label: l.label, value: l.value }) }, s))
|
|
314
|
+
}
|
|
315
|
+
),
|
|
308
316
|
/* @__PURE__ */ a(xe, { asChild: !0, className: f["rp-dialog-close"], "aria-label": (e == null ? void 0 : e.searchCloseButtonTooltip) || "Close dialog", children: /* @__PURE__ */ a(ce, { "aria-hidden": "true" }) })
|
|
309
317
|
] })
|
|
310
318
|
] }) }) });
|
package/dist/utils/highlight.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { getCharacterType as D } from "./charators.js";
|
|
2
|
-
function _(
|
|
2
|
+
function _(l, c, m, i) {
|
|
3
3
|
const s = [];
|
|
4
|
-
for (const n of
|
|
4
|
+
for (const n of l) {
|
|
5
5
|
const o = y(c, n, i);
|
|
6
6
|
s.push(...R(o, c, m));
|
|
7
7
|
}
|
|
8
8
|
return s;
|
|
9
9
|
}
|
|
10
|
-
const L = (
|
|
10
|
+
const L = (l, c) => {
|
|
11
11
|
const m = ["g"];
|
|
12
12
|
c.matchCase || m.push("i");
|
|
13
|
-
let s =
|
|
13
|
+
let s = l.replace(/[.^$*+?()[{|\\]/g, (n) => `\\${n}`).trim();
|
|
14
14
|
return new RegExp(s, m.join(""));
|
|
15
15
|
};
|
|
16
|
-
function y(
|
|
16
|
+
function y(l, c, m) {
|
|
17
17
|
const i = [];
|
|
18
|
-
for (const t of
|
|
18
|
+
for (const t of l.items)
|
|
19
19
|
if (t.hasEOL)
|
|
20
20
|
if (t.str.endsWith("-")) {
|
|
21
21
|
const d = t.str.lastIndexOf("-");
|
|
@@ -34,14 +34,14 @@ function y(r, c, m) {
|
|
|
34
34
|
m.wholeWords && !W(s, e.index, e[0].length) || o.push([e.index, e[0].length, e[0]]);
|
|
35
35
|
return o;
|
|
36
36
|
}
|
|
37
|
-
function R(
|
|
37
|
+
function R(l, c, m) {
|
|
38
38
|
function i(d) {
|
|
39
39
|
return d.hasEOL ? d.str.endsWith("-") ? -1 : 1 : 0;
|
|
40
40
|
}
|
|
41
41
|
let s = 0, n = 0;
|
|
42
42
|
const o = c.items, e = o.length - 1, t = [];
|
|
43
|
-
for (let d = 0; d <
|
|
44
|
-
let h =
|
|
43
|
+
for (let d = 0; d < l.length; d++) {
|
|
44
|
+
let h = l[d][0];
|
|
45
45
|
for (; s !== e && h >= n + o[s].str.length; ) {
|
|
46
46
|
const x = o[s];
|
|
47
47
|
n += x.str.length + i(x), s++;
|
|
@@ -50,19 +50,19 @@ function R(r, c, m) {
|
|
|
50
50
|
idx: s,
|
|
51
51
|
offset: h - n
|
|
52
52
|
};
|
|
53
|
-
for (h +=
|
|
53
|
+
for (h += l[d][1]; s !== e && h > n + o[s].str.length; ) {
|
|
54
54
|
const x = o[s];
|
|
55
55
|
n += x.str.length + i(x), s++;
|
|
56
56
|
}
|
|
57
|
-
const
|
|
57
|
+
const r = {
|
|
58
58
|
idx: s,
|
|
59
59
|
offset: h - n
|
|
60
60
|
};
|
|
61
61
|
t.push({
|
|
62
62
|
start: g,
|
|
63
|
-
end:
|
|
64
|
-
str:
|
|
65
|
-
oIndex:
|
|
63
|
+
end: r,
|
|
64
|
+
str: l[d][2],
|
|
65
|
+
oIndex: l[d][0],
|
|
66
66
|
pageIndex: m,
|
|
67
67
|
rect: { left: 0, bottom: 0, width: 0, height: 0 },
|
|
68
68
|
rects: []
|
|
@@ -71,45 +71,45 @@ function R(r, c, m) {
|
|
|
71
71
|
for (const d of t) {
|
|
72
72
|
const h = [];
|
|
73
73
|
for (let g = d.start.idx; g <= d.end.idx; g++) {
|
|
74
|
-
const
|
|
75
|
-
|
|
74
|
+
const r = o[g], x = r.transform[4], C = r.transform[5], a = r.str.length > 0 ? r.width / r.str.length : 0, M = g === d.start.idx ? d.start.offset : 0, N = g === d.end.idx ? d.end.offset : r.str.length, f = x + M * a, E = (N - M) * a, u = (c.styles ?? {})[r.fontName], T = (u == null ? void 0 : u.ascent) ?? 1, v = (u == null ? void 0 : u.descent) != null ? Math.abs(u.descent) : 1 - T, b = C - v * r.height;
|
|
75
|
+
r.height > 0 && r.width > 0 && h.push({
|
|
76
76
|
left: f,
|
|
77
77
|
bottom: b,
|
|
78
78
|
width: E,
|
|
79
|
-
height:
|
|
79
|
+
height: r.height
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
d.rect = h[0], d.rects = h;
|
|
83
83
|
}
|
|
84
84
|
return t;
|
|
85
85
|
}
|
|
86
|
-
function W(
|
|
87
|
-
let i =
|
|
86
|
+
function W(l, c, m) {
|
|
87
|
+
let i = l.slice(0, c).match(/([^\p{M}])\p{M}*$/u);
|
|
88
88
|
if (i) {
|
|
89
|
-
const s =
|
|
89
|
+
const s = l.charCodeAt(c), n = i[1].charCodeAt(0);
|
|
90
90
|
if (D(s) === D(n))
|
|
91
91
|
return !1;
|
|
92
92
|
}
|
|
93
|
-
if (i =
|
|
94
|
-
const s =
|
|
93
|
+
if (i = l.slice(c + m).match(/^\p{M}*([^\p{M}])/u), i) {
|
|
94
|
+
const s = l.charCodeAt(c + m - 1), n = i[1].charCodeAt(0);
|
|
95
95
|
if (D(s) === D(n))
|
|
96
96
|
return !1;
|
|
97
97
|
}
|
|
98
98
|
return !0;
|
|
99
99
|
}
|
|
100
|
-
function I(
|
|
100
|
+
function I(l, c, m) {
|
|
101
101
|
const i = [];
|
|
102
102
|
function s(n, o, e = -1, t = -1, d = "") {
|
|
103
103
|
const h = c.items[n], g = [];
|
|
104
|
-
let
|
|
104
|
+
let r = "", x = "", C = "", a = m[n];
|
|
105
105
|
if (!a)
|
|
106
106
|
return;
|
|
107
107
|
if (a.nodeType === Node.TEXT_NODE) {
|
|
108
108
|
const f = document.createElement("span");
|
|
109
109
|
a.before(f), f.append(a), m[n] = f, a = f;
|
|
110
110
|
}
|
|
111
|
-
e >= 0 && t >= 0 ?
|
|
112
|
-
const M = document.createTextNode(
|
|
111
|
+
e >= 0 && t >= 0 ? r = h.str.substring(e, t) : e < 0 && t < 0 ? r = h.str : e >= 0 ? r = h.str.substring(e) : t >= 0 && (r = h.str.substring(0, t));
|
|
112
|
+
const M = document.createTextNode(r), N = document.createElement("span");
|
|
113
113
|
if (N.className = "highlight appended " + d, N.setAttribute("data-match-index", `${o}`), N.append(M), g.push(N), i.push({ element: N, index: o }), e > 0)
|
|
114
114
|
if (a.childNodes.length === 1 && a.childNodes[0].nodeType === Node.TEXT_NODE) {
|
|
115
115
|
x = h.str.substring(0, e);
|
|
@@ -135,7 +135,7 @@ function I(r, c, m) {
|
|
|
135
135
|
}
|
|
136
136
|
a.replaceChildren(...g);
|
|
137
137
|
}
|
|
138
|
-
for (const [n, o] of
|
|
138
|
+
for (const [n, o] of l.entries())
|
|
139
139
|
if (o.start.idx === o.end.idx)
|
|
140
140
|
s(o.start.idx, n, o.start.offset, o.end.offset);
|
|
141
141
|
else
|
|
@@ -143,8 +143,8 @@ function I(r, c, m) {
|
|
|
143
143
|
e === o.start.idx ? s(e, n, o.start.offset, -1, "begin") : e === o.end.idx ? s(e, n, -1, o.end.offset, "end") : s(e, n, -1, -1, "middle");
|
|
144
144
|
return i;
|
|
145
145
|
}
|
|
146
|
-
function V(
|
|
147
|
-
const m =
|
|
146
|
+
function V(l, c) {
|
|
147
|
+
const m = l.items.map((i) => i.str);
|
|
148
148
|
for (let i = 0; i < c.length; i++) {
|
|
149
149
|
const s = c[i];
|
|
150
150
|
if (s && s.nodeType !== Node.TEXT_NODE) {
|
|
@@ -153,19 +153,19 @@ function V(r, c) {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
function H(
|
|
157
|
-
return { matchCase: !1, wholeWords: !1, ...
|
|
156
|
+
function H(l = {}) {
|
|
157
|
+
return { matchCase: !1, wholeWords: !1, ...l };
|
|
158
158
|
}
|
|
159
|
-
function S(
|
|
159
|
+
function S(l, c, m) {
|
|
160
160
|
const i = [];
|
|
161
161
|
function s(n, o, e = -1, t = -1, d) {
|
|
162
162
|
var f, E;
|
|
163
163
|
const h = c.items[n], g = [];
|
|
164
|
-
let
|
|
164
|
+
let r = "", x = "", C = "", a = m[n];
|
|
165
165
|
if (!a)
|
|
166
166
|
return;
|
|
167
|
-
e >= 0 && t >= 0 ?
|
|
168
|
-
const M = document.createTextNode(
|
|
167
|
+
e >= 0 && t >= 0 ? r = h.str.substring(e, t) : e < 0 && t < 0 ? r = h.str : e >= 0 ? r = h.str.substring(e) : t >= 0 && (r = h.str.substring(0, t));
|
|
168
|
+
const M = document.createTextNode(r), N = document.createElement("span");
|
|
169
169
|
if (N.style.background = d, N.append(M), g.push(N), e > 0)
|
|
170
170
|
if (a.childNodes.length === 1 && a.childNodes[0].nodeType === Node.TEXT_NODE) {
|
|
171
171
|
x = h.str.substring(0, e);
|
|
@@ -205,7 +205,7 @@ function S(r, c, m) {
|
|
|
205
205
|
}
|
|
206
206
|
a.replaceChildren(...g), i.push({ element: N, index: o });
|
|
207
207
|
}
|
|
208
|
-
for (const [n, o] of
|
|
208
|
+
for (const [n, o] of l.entries()) {
|
|
209
209
|
const { start: e, end: t, color: d } = o;
|
|
210
210
|
e.idx === t.idx && s(e.idx, n, e.offset, t.offset, d);
|
|
211
211
|
}
|
|
@@ -1,55 +1,93 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { getHighlightOptionsWithDefaults as
|
|
1
|
+
import { useState as f, useCallback as p, useEffect as w } from "react";
|
|
2
|
+
import { getHighlightOptionsWithDefaults as k, findMatches as P } from "../highlight.js";
|
|
3
3
|
import "../charators.js";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
4
|
+
const x = (n) => {
|
|
5
|
+
const e = Math.min(...n.map((s) => s.left)), c = Math.max(...n.map((s) => s.left + s.width)), o = Math.min(...n.map((s) => s.bottom)), t = Math.max(...n.map((s) => s.height));
|
|
6
|
+
return { left: e, bottom: o, width: c - e, height: t };
|
|
7
|
+
}, N = (n) => n.flatMap((e) => e.rects ?? (e.rect ? [e.rect] : [])), O = (n) => {
|
|
8
|
+
const e = n.reduce((o, t) => {
|
|
9
|
+
const s = Math.round(t.bottom);
|
|
10
|
+
return o[s] || (o[s] = []), o[s].push(t), o;
|
|
11
|
+
}, {});
|
|
12
|
+
return Object.entries(e).sort((o, t) => Number(t[0]) - Number(o[0])).map(([o, t]) => x(t));
|
|
13
|
+
}, L = (n) => {
|
|
14
|
+
const e = {};
|
|
15
|
+
for (const c of n) {
|
|
16
|
+
const o = c.keyword, t = e[o] ?? [];
|
|
17
|
+
t.push(c), e[o] = t;
|
|
18
|
+
}
|
|
19
|
+
return e;
|
|
20
|
+
}, j = (n, e) => {
|
|
21
|
+
const c = n[0], o = N(n), t = o.length > 0 ? O(o) : c.rect ? [c.rect] : [];
|
|
22
|
+
return {
|
|
23
|
+
...c,
|
|
24
|
+
pageMatchIdx: e,
|
|
25
|
+
rect: t[0] ?? c.rect,
|
|
26
|
+
rects: t
|
|
27
|
+
};
|
|
28
|
+
}, v = (n) => {
|
|
29
|
+
const e = {};
|
|
30
|
+
for (const t of n) {
|
|
31
|
+
const s = e[t.page] ?? [];
|
|
32
|
+
s.push(t), e[t.page] = s;
|
|
33
|
+
}
|
|
34
|
+
let c = 0;
|
|
35
|
+
const o = [];
|
|
36
|
+
for (const t of Object.values(e)) {
|
|
37
|
+
const s = L(t);
|
|
38
|
+
for (const g of Object.values(s))
|
|
39
|
+
o.push(j(g, c++));
|
|
40
|
+
}
|
|
41
|
+
return o;
|
|
42
|
+
}, K = (n) => {
|
|
43
|
+
const [e, c] = f(void 0), [o, t] = f([]), s = p(async (r) => {
|
|
44
|
+
if (!r)
|
|
7
45
|
return {};
|
|
8
|
-
const i =
|
|
9
|
-
for (let
|
|
10
|
-
const
|
|
11
|
-
|
|
46
|
+
const i = r.numPages, h = {};
|
|
47
|
+
for (let a = 1; a <= i; a++) {
|
|
48
|
+
const u = await r.getPage(a);
|
|
49
|
+
h[a.toString()] = await u.getTextContent();
|
|
12
50
|
}
|
|
13
|
-
return
|
|
14
|
-
}, []),
|
|
15
|
-
c(
|
|
16
|
-
}, []),
|
|
17
|
-
|
|
51
|
+
return h;
|
|
52
|
+
}, []), g = p(async (r) => {
|
|
53
|
+
c(r);
|
|
54
|
+
}, []), l = p(() => {
|
|
55
|
+
t([]), c(void 0);
|
|
18
56
|
}, []);
|
|
19
|
-
return
|
|
20
|
-
|
|
57
|
+
return w(() => {
|
|
58
|
+
n && s(n).then((r) => {
|
|
21
59
|
let i = [];
|
|
22
|
-
for (const { keyword:
|
|
23
|
-
if (!
|
|
60
|
+
for (const { keyword: h, highlightColor: a, options: u } of e) {
|
|
61
|
+
if (!h)
|
|
24
62
|
continue;
|
|
25
|
-
const
|
|
26
|
-
for (const
|
|
27
|
-
const
|
|
28
|
-
[
|
|
29
|
-
|
|
30
|
-
Number(
|
|
31
|
-
|
|
32
|
-
).map((
|
|
33
|
-
...
|
|
34
|
-
page: Number(
|
|
35
|
-
pageMatchIdx:
|
|
36
|
-
color:
|
|
37
|
-
keyword:
|
|
63
|
+
const b = k(u);
|
|
64
|
+
for (const m of Object.keys(r)) {
|
|
65
|
+
const d = P(
|
|
66
|
+
[h],
|
|
67
|
+
r[m],
|
|
68
|
+
Number(m) - 1,
|
|
69
|
+
b
|
|
70
|
+
).map((M, y) => ({
|
|
71
|
+
...M,
|
|
72
|
+
page: Number(m),
|
|
73
|
+
pageMatchIdx: y,
|
|
74
|
+
color: a,
|
|
75
|
+
keyword: h
|
|
38
76
|
}));
|
|
39
|
-
i = [...i, ...
|
|
77
|
+
i = [...i, ...d];
|
|
40
78
|
}
|
|
41
79
|
}
|
|
42
|
-
|
|
80
|
+
t(v(i));
|
|
43
81
|
}).catch(() => {
|
|
44
|
-
|
|
82
|
+
l();
|
|
45
83
|
});
|
|
46
|
-
}, [
|
|
47
|
-
highlight:
|
|
48
|
-
clear:
|
|
49
|
-
highlightMatches:
|
|
50
|
-
highlightKeywords:
|
|
84
|
+
}, [e, n, l, s]), {
|
|
85
|
+
highlight: g,
|
|
86
|
+
clear: l,
|
|
87
|
+
highlightMatches: o,
|
|
88
|
+
highlightKeywords: e
|
|
51
89
|
};
|
|
52
90
|
};
|
|
53
91
|
export {
|
|
54
|
-
|
|
92
|
+
K as useHighlight
|
|
55
93
|
};
|
|
@@ -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("2026-
|
|
3
|
+
const b = /* @__PURE__ */ new Date("2026-03-04T09:04:06.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,6 +1,6 @@
|
|
|
1
|
-
import { useState as g, useRef as
|
|
2
|
-
import { useDocumentContext as
|
|
3
|
-
import { PixelsPerInch as
|
|
1
|
+
import { useState as g, useRef as k, useEffect as D, useCallback as P } from "react";
|
|
2
|
+
import { useDocumentContext as q } from "../../contexts/RPDocumentContext.js";
|
|
3
|
+
import { PixelsPerInch as V, AnnotationMode as O, RenderingCancelledException as U } from "pdfjs-dist";
|
|
4
4
|
import "react/jsx-runtime";
|
|
5
5
|
import "./useLoadPdf.js";
|
|
6
6
|
import "../types.js";
|
|
@@ -13,118 +13,111 @@ import "./usePdfProperties.js";
|
|
|
13
13
|
import "../convertPdfDate.js";
|
|
14
14
|
import "../formatFileSize.js";
|
|
15
15
|
const re = () => {
|
|
16
|
-
const { pdf: l, pages: f } =
|
|
16
|
+
const { pdf: l, pages: f } = q(), [R, E] = g({
|
|
17
17
|
loadedPages: 0,
|
|
18
18
|
totalPages: 0,
|
|
19
19
|
percentage: 0
|
|
20
|
-
}), [T,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}, [
|
|
24
|
-
const
|
|
20
|
+
}), [T, y] = g(!1), [A, b] = g(!1), [Z, C] = g(null), [M, w] = g(void 0), i = k(!1);
|
|
21
|
+
D(() => {
|
|
22
|
+
i.current;
|
|
23
|
+
}, [i]);
|
|
24
|
+
const S = P(() => {
|
|
25
25
|
document.documentElement.classList.remove("rp-print-html-printing"), document.body.classList.remove("rp-print-body-printing");
|
|
26
26
|
const e = document.querySelector(".rp-print-zone");
|
|
27
27
|
e && e.remove();
|
|
28
|
-
}, []),
|
|
29
|
-
|
|
28
|
+
}, []), s = P(() => {
|
|
29
|
+
i.current = !1, y(!1), b(!1), C(null), w(void 0), E({
|
|
30
30
|
loadedPages: 0,
|
|
31
31
|
totalPages: 0,
|
|
32
32
|
percentage: 0
|
|
33
33
|
});
|
|
34
|
-
}, []),
|
|
35
|
-
|
|
34
|
+
}, []), F = () => {
|
|
35
|
+
i.current = !0;
|
|
36
36
|
}, I = async ({
|
|
37
37
|
scratchCanvas: e,
|
|
38
38
|
pdfDocument: n,
|
|
39
39
|
pageNumber: t,
|
|
40
|
-
viewerPdfPage:
|
|
41
|
-
printResolution:
|
|
42
|
-
optionalContentConfigPromise:
|
|
40
|
+
viewerPdfPage: r,
|
|
41
|
+
printResolution: o,
|
|
42
|
+
optionalContentConfigPromise: c,
|
|
43
43
|
printAnnotationStoragePromise: u
|
|
44
44
|
}) => {
|
|
45
|
-
if (
|
|
46
|
-
|
|
45
|
+
if (i.current) {
|
|
46
|
+
s();
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
e.width = Math.floor(
|
|
49
|
+
const a = o / V.PDF;
|
|
50
|
+
e.width = Math.floor(r.width * a), e.height = Math.floor(r.height * a);
|
|
51
51
|
const p = e.getContext("2d");
|
|
52
52
|
p.save(), p.fillStyle = "rgb(255, 255, 255)", p.fillRect(0, 0, e.width, e.height), p.restore();
|
|
53
53
|
const [m, h] = await Promise.all([
|
|
54
54
|
n.getPage(t),
|
|
55
55
|
u
|
|
56
56
|
]);
|
|
57
|
-
if (
|
|
58
|
-
|
|
57
|
+
if (i.current) {
|
|
58
|
+
s();
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
const v = {
|
|
62
62
|
canvas: e,
|
|
63
63
|
canvasContext: p,
|
|
64
|
-
transform: [
|
|
65
|
-
viewport: m.getViewport({ scale: 1, rotation:
|
|
64
|
+
transform: [a, 0, 0, a, 0, 0],
|
|
65
|
+
viewport: m.getViewport({ scale: 1, rotation: r.rotation }),
|
|
66
66
|
intent: "print",
|
|
67
|
-
annotationMode:
|
|
68
|
-
optionalContentConfigPromise:
|
|
67
|
+
annotationMode: O.ENABLE_STORAGE,
|
|
68
|
+
optionalContentConfigPromise: c,
|
|
69
69
|
printAnnotationStorage: h
|
|
70
70
|
};
|
|
71
71
|
try {
|
|
72
72
|
return m.render(v).promise;
|
|
73
73
|
} catch (d) {
|
|
74
|
-
throw d instanceof
|
|
74
|
+
throw d instanceof U || console.error(d), d;
|
|
75
75
|
}
|
|
76
|
-
},
|
|
76
|
+
}, L = P(() => {
|
|
77
77
|
const e = window.print;
|
|
78
78
|
return new Promise((n) => {
|
|
79
|
-
const t = (
|
|
79
|
+
const t = (c) => {
|
|
80
80
|
setTimeout(() => {
|
|
81
|
-
e.call(window), setTimeout(() =>
|
|
81
|
+
e.call(window), setTimeout(() => c(), 20);
|
|
82
82
|
}, 0);
|
|
83
83
|
};
|
|
84
84
|
if (document.querySelector(".rp-print-zone")) {
|
|
85
85
|
t(n);
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
const
|
|
89
|
-
document.querySelector(".rp-print-zone") && (t(n),
|
|
88
|
+
const o = new MutationObserver(() => {
|
|
89
|
+
document.querySelector(".rp-print-zone") && (t(n), o.disconnect());
|
|
90
90
|
});
|
|
91
|
-
|
|
91
|
+
o.observe(document.body, { childList: !0, subtree: !0 });
|
|
92
92
|
});
|
|
93
|
-
}, []),
|
|
93
|
+
}, []), z = (e) => {
|
|
94
94
|
const n = document.createElement("img"), t = document.createElement("div");
|
|
95
|
-
return t.classList.add("rp-print-page"),
|
|
96
|
-
e.toBlob((i) => {
|
|
97
|
-
i ? (n.src = URL.createObjectURL(i), n.onload = () => {
|
|
98
|
-
URL.revokeObjectURL(n.src), o();
|
|
99
|
-
}, n.onerror = r) : r(new Error("Failed to create blob"));
|
|
100
|
-
});
|
|
101
|
-
}).catch(() => {
|
|
102
|
-
}), t.appendChild(n), t;
|
|
95
|
+
return t.classList.add("rp-print-page"), n.src = e.toDataURL(), t.appendChild(n), t;
|
|
103
96
|
}, x = (e, n) => {
|
|
104
97
|
const t = document.createElement("div");
|
|
105
98
|
t.classList.add("rp-print-zone");
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
const
|
|
109
|
-
|
|
99
|
+
const r = document.createElement("style"), o = n.get(1);
|
|
100
|
+
if (o) {
|
|
101
|
+
const c = o.page.getViewport({ scale: 1 }), { width: u, height: a } = c;
|
|
102
|
+
r.innerHTML = `@page { size: ${u}pt ${a}pt; margin: 0; }`;
|
|
110
103
|
}
|
|
111
|
-
return t.appendChild(
|
|
112
|
-
},
|
|
104
|
+
return t.appendChild(r), t.append(...e), t;
|
|
105
|
+
}, N = P(
|
|
113
106
|
async (e) => {
|
|
114
107
|
if (!l)
|
|
115
108
|
return;
|
|
116
|
-
|
|
109
|
+
s();
|
|
117
110
|
const n = e && "visibleDefaultProgress" in e ? e : void 0;
|
|
118
111
|
(n == null ? void 0 : n.visibleDefaultProgress) !== void 0 ? w(n.visibleDefaultProgress) : w(!0);
|
|
119
|
-
const t = document.createElement("canvas"),
|
|
112
|
+
const t = document.createElement("canvas"), r = [];
|
|
120
113
|
try {
|
|
121
114
|
l.isPureXfa && console.warn("[rp] XFA Form is not supported at the moment.");
|
|
122
|
-
const
|
|
115
|
+
const c = l.getOptionalContentConfig({ intent: "print" }), u = Promise.resolve(
|
|
123
116
|
l.annotationStorage.print ?? void 0
|
|
124
|
-
),
|
|
117
|
+
), a = f.size;
|
|
125
118
|
for (const [m, h] of f) {
|
|
126
|
-
if (
|
|
127
|
-
|
|
119
|
+
if (i.current) {
|
|
120
|
+
s();
|
|
128
121
|
return;
|
|
129
122
|
}
|
|
130
123
|
const v = h.page.getViewport({ scale: 1 });
|
|
@@ -134,50 +127,50 @@ const re = () => {
|
|
|
134
127
|
pageNumber: m,
|
|
135
128
|
viewerPdfPage: v,
|
|
136
129
|
printResolution: 150,
|
|
137
|
-
optionalContentConfigPromise:
|
|
130
|
+
optionalContentConfigPromise: c,
|
|
138
131
|
printAnnotationStoragePromise: u
|
|
139
|
-
}),
|
|
140
|
-
|
|
132
|
+
}), i.current) {
|
|
133
|
+
s();
|
|
141
134
|
return;
|
|
142
135
|
}
|
|
143
|
-
const d =
|
|
144
|
-
|
|
145
|
-
const
|
|
136
|
+
const d = z(t);
|
|
137
|
+
r.push(d);
|
|
138
|
+
const X = parseFloat((r.length / a * 100).toFixed(2));
|
|
146
139
|
E({
|
|
147
140
|
loadedPages: m,
|
|
148
|
-
totalPages:
|
|
149
|
-
percentage:
|
|
141
|
+
totalPages: a,
|
|
142
|
+
percentage: X
|
|
150
143
|
});
|
|
151
144
|
}
|
|
152
|
-
if (
|
|
153
|
-
|
|
145
|
+
if (i.current) {
|
|
146
|
+
s();
|
|
154
147
|
return;
|
|
155
148
|
}
|
|
156
|
-
const p = x(
|
|
157
|
-
document.body.appendChild(p), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"),
|
|
158
|
-
} catch (
|
|
159
|
-
|
|
149
|
+
const p = x(r, f);
|
|
150
|
+
document.body.appendChild(p), document.documentElement.classList.add("rp-print-html-printing"), document.body.classList.add("rp-print-body-printing"), y(!0), await L();
|
|
151
|
+
} catch (o) {
|
|
152
|
+
b(!0), o instanceof Error && C(o);
|
|
160
153
|
} finally {
|
|
161
154
|
t.height = 0, t.width = 0;
|
|
162
155
|
}
|
|
163
156
|
},
|
|
164
|
-
[l, f,
|
|
157
|
+
[l, f, i, s, x, L]
|
|
165
158
|
);
|
|
166
|
-
return
|
|
159
|
+
return D(() => {
|
|
167
160
|
const e = () => {
|
|
168
|
-
|
|
161
|
+
s(), S();
|
|
169
162
|
};
|
|
170
163
|
return window.addEventListener("afterprint", e, !0), () => {
|
|
171
164
|
window.removeEventListener("afterprint", e, !0);
|
|
172
165
|
};
|
|
173
|
-
}, [
|
|
174
|
-
print:
|
|
175
|
-
cancel:
|
|
176
|
-
progress:
|
|
166
|
+
}, [S, s]), {
|
|
167
|
+
print: N,
|
|
168
|
+
cancel: F,
|
|
169
|
+
progress: R,
|
|
177
170
|
isComplete: T,
|
|
178
171
|
isError: A,
|
|
179
172
|
error: Z,
|
|
180
|
-
showDefaultProgress:
|
|
173
|
+
showDefaultProgress: M
|
|
181
174
|
};
|
|
182
175
|
};
|
|
183
176
|
export {
|
|
@@ -3,17 +3,18 @@ function e() {
|
|
|
3
3
|
return;
|
|
4
4
|
const t = document.createElement("style");
|
|
5
5
|
t.id = "rp-print-style", t.textContent = `
|
|
6
|
+
@page { margin: 0; }
|
|
7
|
+
|
|
6
8
|
.rp-print-zone { display: none; }
|
|
7
9
|
|
|
8
10
|
@media print {
|
|
9
|
-
@page { margin: 0; }
|
|
10
11
|
.rp-print-html-printing { height: 100%; }
|
|
11
|
-
.rp-print-body-printing { background:
|
|
12
|
+
.rp-print-body-printing { background: rgb(0 0 0 / 0) none; height: 100% !important; margin: 0 !important; display: block !important; }
|
|
12
13
|
.rp-print-body-printing * { display: none; }
|
|
13
14
|
.rp-print-zone { display: block; height: 100%; }
|
|
14
15
|
.rp-print-page { display: flex; align-items: center; flex-direction: column; justify-content: center; height: 100%; width: 100%; page-break-after: always; page-break-inside: avoid; }
|
|
15
16
|
.rp-print-page:last-child { page-break-after: auto; }
|
|
16
|
-
.rp-print-page img, .rp-print-page canvas { display: block; max-
|
|
17
|
+
.rp-print-page img, .rp-print-page canvas { display: block; max-width: 100%; max-height: 100%; direction: ltr; }
|
|
17
18
|
}
|
|
18
19
|
`, document.head.appendChild(t);
|
|
19
20
|
}
|