@progress/kendo-react-pdf-viewer 13.3.0 → 13.4.0-develop.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/PDFViewer.d.ts +331 -0
- package/PDFViewer.js +1 -1
- package/PDFViewer.mjs +12 -12
- package/dist/cdn/js/kendo-react-pdf-viewer.js +1 -1
- package/index.d.mts +29 -367
- package/index.d.ts +29 -367
- package/messages.d.ts +102 -0
- package/package-metadata.d.ts +12 -0
- package/package-metadata.js +1 -1
- package/package-metadata.mjs +10 -16
- package/package.json +10 -10
package/PDFViewer.d.ts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2026 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
import { ToolbarProps } from '@progress/kendo-react-buttons';
|
|
9
|
+
import { SaveOptions } from '@progress/kendo-file-saver';
|
|
10
|
+
import { TypedArray } from '@progress/kendo-pdfviewer-common';
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
export type PDFViewerTool = 'pager' | 'spacer' | 'zoomInOut' | 'zoom' | 'selection' | 'search' | 'open' | 'download' | 'print';
|
|
13
|
+
interface PDFViewerEvent {
|
|
14
|
+
/**
|
|
15
|
+
* The event target object.
|
|
16
|
+
*/
|
|
17
|
+
target: PDFViewerHandle;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The KendoReact [PDF Viewer](https://www.telerik.com/kendo-react-ui/components/pdf-viewer/api/pdfviewer) ErrorEvent object.
|
|
21
|
+
*/
|
|
22
|
+
export interface ErrorEvent extends PDFViewerEvent {
|
|
23
|
+
/**
|
|
24
|
+
* The raised error.
|
|
25
|
+
*/
|
|
26
|
+
error: Error | {
|
|
27
|
+
message: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The KendoReact [PDF Viewer](https://www.telerik.com/kendo-react-ui/components/pdf-viewer/api/pdfviewer) DownloadEvent object.
|
|
32
|
+
*/
|
|
33
|
+
export interface DownloadEvent extends PDFViewerEvent {
|
|
34
|
+
/**
|
|
35
|
+
* The Blob object.
|
|
36
|
+
*/
|
|
37
|
+
blob: Blob;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the name for saving the file.
|
|
40
|
+
*/
|
|
41
|
+
fileName: string;
|
|
42
|
+
/**
|
|
43
|
+
* Sets the options for saving the file.
|
|
44
|
+
*/
|
|
45
|
+
saveOptions: SaveOptions;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The KendoReact [PDF Viewer](https://www.telerik.com/kendo-react-ui/components/pdf-viewer/api/pdfviewer) LoadEvent object.
|
|
49
|
+
*/
|
|
50
|
+
export interface LoadEvent extends PDFViewerEvent {
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The KendoReact [PDF Viewer](https://www.telerik.com/kendo-react-ui/components/pdf-viewer/api/pdfviewer) ZoomEvent object.
|
|
54
|
+
*/
|
|
55
|
+
export interface ZoomEvent extends PDFViewerEvent {
|
|
56
|
+
/**
|
|
57
|
+
* The zoom value.
|
|
58
|
+
*/
|
|
59
|
+
zoom: number;
|
|
60
|
+
/**
|
|
61
|
+
* A React `SyntheticEvent`.
|
|
62
|
+
*/
|
|
63
|
+
syntheticEvent: React.SyntheticEvent<any>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The KendoReact [PDF Viewer](https://www.telerik.com/kendo-react-ui/components/pdf-viewer/api/pdfviewer) PageEvent object.
|
|
67
|
+
*/
|
|
68
|
+
export interface PageEvent extends PDFViewerEvent {
|
|
69
|
+
/**
|
|
70
|
+
* The page number.
|
|
71
|
+
*/
|
|
72
|
+
page: number;
|
|
73
|
+
/**
|
|
74
|
+
* A React `SyntheticEvent`.
|
|
75
|
+
*/
|
|
76
|
+
syntheticEvent: React.SyntheticEvent<any>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The props of the KendoReact [PDF Viewer](https://www.telerik.com/kendo-react-ui/components/pdf-viewer/api/pdfviewer) component.
|
|
80
|
+
*/
|
|
81
|
+
export interface PDFViewerProps {
|
|
82
|
+
/**
|
|
83
|
+
* Sets the URL of the PDF file.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```jsx
|
|
87
|
+
* <PDFViewer url="https://example.com/sample.pdf" />
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
url?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Sets the data of the PDF file in Base64 format.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```jsx
|
|
96
|
+
* <PDFViewer data="JVBERi0xLjQKJ..." />
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
data?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Sets the raw binary data buffer of the PDF file.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```jsx
|
|
105
|
+
* <PDFViewer arrayBuffer={new ArrayBuffer(1024)} />
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
arrayBuffer?: ArrayBuffer;
|
|
109
|
+
/**
|
|
110
|
+
* Sets the data of the PDF file in typed array format.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```jsx
|
|
114
|
+
* <PDFViewer typedArray={new Uint8Array([0x25, 0x50, 0x44, 0x46])} />
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
typedArray?: TypedArray;
|
|
118
|
+
/**
|
|
119
|
+
* Sets the additional styles for the PDF Viewer component.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```jsx
|
|
123
|
+
* <PDFViewer style={{ height: '500px' }} />
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
style?: React.CSSProperties;
|
|
127
|
+
/**
|
|
128
|
+
* Sets the file name used to save the file when you click the download tool.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```jsx
|
|
132
|
+
* <PDFViewer saveFileName="document.pdf" />
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
saveFileName?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Sets the options for saving the file when you click the download tool.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```jsx
|
|
141
|
+
* <PDFViewer saveOptions={{ forceProxy: true }} />
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
saveOptions?: SaveOptions;
|
|
145
|
+
/**
|
|
146
|
+
* Sets the tools collection that renders in the toolbar.
|
|
147
|
+
*
|
|
148
|
+
* @default - ['pager', 'spacer', 'zoomInOut', 'zoom', 'selection', 'spacer', 'search', 'open', 'download', 'print']
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```jsx
|
|
152
|
+
* <PDFViewer tools={['pager', 'zoom']} />
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
tools?: PDFViewerTool[];
|
|
156
|
+
/**
|
|
157
|
+
* Sets the zoom levels populated in the ComboBox component.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```jsx
|
|
161
|
+
* <PDFViewer zoomLevels={[{ id: 1, value: 1, text: '100%' }]} />
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
zoomLevels?: {
|
|
165
|
+
id: number;
|
|
166
|
+
priority: number;
|
|
167
|
+
value: number;
|
|
168
|
+
text: string;
|
|
169
|
+
type: string;
|
|
170
|
+
locationString?: string;
|
|
171
|
+
}[];
|
|
172
|
+
/**
|
|
173
|
+
* Sets the zoom value of the document.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```jsx
|
|
177
|
+
* <PDFViewer zoom={1.5} />
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
zoom?: number;
|
|
181
|
+
/**
|
|
182
|
+
* Sets the default zoom value.
|
|
183
|
+
*
|
|
184
|
+
* @default 1
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```jsx
|
|
188
|
+
* <PDFViewer defaultZoom={1} />
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
defaultZoom?: number;
|
|
192
|
+
/**
|
|
193
|
+
* Sets the minimum zoom value.
|
|
194
|
+
*
|
|
195
|
+
* @default 0.5
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```jsx
|
|
199
|
+
* <PDFViewer minZoom={0.5} />
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
minZoom?: number;
|
|
203
|
+
/**
|
|
204
|
+
* Sets the maximum zoom value.
|
|
205
|
+
*
|
|
206
|
+
* @default 4
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```jsx
|
|
210
|
+
* <PDFViewer maxZoom={4} />
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
maxZoom?: number;
|
|
214
|
+
/**
|
|
215
|
+
* Sets the zoom rate value.
|
|
216
|
+
*
|
|
217
|
+
* @default 0.25
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```jsx
|
|
221
|
+
* <PDFViewer zoomRate={0.25} />
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
zoomRate?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Fires when an error occurs.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```jsx
|
|
230
|
+
* <PDFViewer onError={(event) => console.log(event.error)} />
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
onError?: (event: ErrorEvent) => void;
|
|
234
|
+
/**
|
|
235
|
+
* Fires when a PDF document has been loaded.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```jsx
|
|
239
|
+
* <PDFViewer onLoad={() => console.log('Document loaded')} />
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
onLoad?: (event: LoadEvent) => void;
|
|
243
|
+
/**
|
|
244
|
+
* Fires when the download tool has been clicked. To prevent the download, return `false`.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```jsx
|
|
248
|
+
* <PDFViewer onDownload={(event) => console.log(event.fileName)} />
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
onDownload?: (event: DownloadEvent) => boolean | void;
|
|
252
|
+
/**
|
|
253
|
+
* Fires when the zoom has changed.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```jsx
|
|
257
|
+
* <PDFViewer onZoom={(event) => console.log(event.zoom)} />
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
onZoom?: (event: ZoomEvent) => void;
|
|
261
|
+
/**
|
|
262
|
+
* Fires when the page has changed.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```jsx
|
|
266
|
+
* <PDFViewer onPageChange={(event) => console.log(event.page)} />
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
onPageChange?: (event: PageEvent) => void;
|
|
270
|
+
/**
|
|
271
|
+
* Fires when the toolbar component is about to be rendered. Use it to override the default appearance of the toolbar.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```jsx
|
|
275
|
+
* <PDFViewer onRenderToolbar={(defaultRendering) => <CustomToolbar />} />
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
onRenderToolbar?: (defaultRendering: React.ReactElement<ToolbarProps>) => React.ReactNode;
|
|
279
|
+
/**
|
|
280
|
+
* Fires when the content component is about to be rendered. Use it to override the default appearance of the content.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```jsx
|
|
284
|
+
* <PDFViewer onRenderContent={(defaultRendering) => <CustomContent />} />
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
onRenderContent?: (defaultRendering: React.ReactElement<HTMLDivElement>) => React.ReactNode;
|
|
288
|
+
/**
|
|
289
|
+
* Fires when the loading indication component is about to be rendered. Use it to override the default appearance of the loading.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```jsx
|
|
293
|
+
* <PDFViewer onRenderLoader={(defaultRendering) => <CustomLoader />} />
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
onRenderLoader?: (defaultRendering: React.ReactElement<HTMLDivElement> | null) => React.ReactNode;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Represents the object which is passed to the [`ref`](https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom)
|
|
300
|
+
* callback of the [PDF Viewer](https://www.telerik.com/kendo-react-ui/components/pdf-viewer/api/pdfviewer) component.
|
|
301
|
+
*/
|
|
302
|
+
export interface PDFViewerHandle {
|
|
303
|
+
/**
|
|
304
|
+
* The root DOM element of the PDF Viewer component.
|
|
305
|
+
*/
|
|
306
|
+
element: HTMLDivElement | null;
|
|
307
|
+
/**
|
|
308
|
+
* The props of the PDF Viewer component.
|
|
309
|
+
*/
|
|
310
|
+
props: PDFViewerProps;
|
|
311
|
+
/**
|
|
312
|
+
* The `PDF.js` document loaded in the PDF Viewer component.
|
|
313
|
+
*/
|
|
314
|
+
document: any;
|
|
315
|
+
/**
|
|
316
|
+
* The `PDF.js` pages loaded in the PDF Viewer component.
|
|
317
|
+
*/
|
|
318
|
+
pages: any[];
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Represents the [KendoReact PDF Viewer component](https://www.telerik.com/kendo-react-ui/components/pdf-viewer/api/pdfviewerprops).
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```jsx
|
|
325
|
+
* function App() {
|
|
326
|
+
* return <PDFViewer url="sample.pdf" />;
|
|
327
|
+
* }
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
export declare const PDFViewer: React.ForwardRefExoticComponent<PDFViewerProps & React.RefAttributes<PDFViewerHandle | null>>;
|
|
331
|
+
export {};
|
package/PDFViewer.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const qe=require("react"),s=require("prop-types"),m=require("@progress/kendo-react-buttons"),A=require("@progress/kendo-react-inputs"),je=require("@progress/kendo-react-data-tools"),Ae=require("@progress/kendo-react-upload"),Ve=require("@progress/kendo-react-dropdowns"),We=require("@progress/kendo-react-indicators"),T=require("@progress/kendo-react-common"),Ke=require("@progress/kendo-react-intl"),f=require("@progress/kendo-svg-icons");require("pdfjs-dist/build/pdf.worker.min.mjs");const oe=require("./package-metadata.js"),i=require("@progress/kendo-pdfviewer-common"),a=require("./messages.js");function Ue(n){const p=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const C in n)if(C!=="default"){const L=Object.getOwnPropertyDescriptor(n,C);Object.defineProperty(p,C,L.get?L:{enumerable:!0,get:()=>n[C]})}}return p.default=n,Object.freeze(p)}const e=Ue(qe),ae=["pager","spacer","zoomInOut","zoom","selection","spacer","search","open","download","print"],w={minZoom:.5,maxZoom:4,tools:[...ae],zoomRate:.25,zoomLevels:[{id:1,priority:1,value:1,text:"Actual width",type:"ActualWidth",locationString:a.actualWidth},{id:2,priority:2,value:1,text:"Fit to width",type:"FitToWidth",locationString:a.fitToWidth},{id:3,priority:3,value:1,text:"Fit to page",type:"FitToPage",locationString:a.fitToPage},{id:4,priority:4,value:.5,text:"50%",type:""},{id:5,priority:5,value:.75,text:"75%",type:""},{id:6,priority:100,value:1,text:"100%",type:""},{id:7,priority:7,value:1.25,text:"125%",type:""},{id:8,priority:8,value:1.5,text:"150%",type:""},{id:9,priority:9,value:2,text:"200%",type:""},{id:10,priority:10,value:3,text:"300%",type:""},{id:11,priority:11,value:4,text:"400%",type:""}],defaultZoom:i.DEFAULT_ZOOM_LEVEL},_e=[".k-toolbar > button",".k-toolbar .k-combobox > input",".k-toolbar .k-button-group > button",".k-toolbar .k-pager > a",".k-toolbar .k-pager input"];let ne=0;function He(){return ne++,ne}const Ge=(n,p)=>n.priority>p.priority?-1:n.priority<p.priority?1:0,V=e.forwardRef((n,p)=>{const C=!T.validatePackage(oe.packageMetadata,{component:"PDFViewer"}),L=T.getLicenseMessage(oe.packageMetadata),{zoom:W,zoomLevels:K=w.zoomLevels,defaultZoom:N=w.defaultZoom,minZoom:R=w.minZoom,maxZoom:B=w.maxZoom,zoomRate:M=w.zoomRate}=n,u=Ke.useLocalization(),c=e.useRef(null),[re,P]=e.useState(N),h=W!==void 0?W:re,Z=K.slice().sort(Ge).find(o=>o.value===h)||{text:h*100+"%",value:h,id:h,locationString:""};Z.locationString&&(Z.text=u.toLanguageString(Z.locationString,a.messages[Z.locationString]));const[g,O]=e.useState(!1),[le,k]=e.useState(!0),[E,U]=e.useState(0),[I,_]=e.useState(!0),[ce,H]=e.useState(!1),[y,D]=e.useState(0),[v,S]=e.useState(0),[x,G]=e.useState(!1),[F,J]=e.useState(""),t=e.useMemo(()=>({}),[]);t.currentZoom=h,t.props=n;const q=e.useCallback(o=>{c.current&&c.current.style.setProperty("--scale-factor",String(o))},[]),b=e.useRef(null),z=e.useRef(null);e.useImperativeHandle(b,()=>({get element(){return z.current},props:n,get pages(){return t.pages},get document(){return t.document}}),[]),e.useImperativeHandle(p,()=>b.current);const se=e.useCallback(()=>{if(t.props.onLoad){const o={target:b.current};t.props.onLoad.call(void 0,o)}},[]),Q=e.useCallback((o,r,l)=>{if(n.onDownload){const d={target:b.current,blob:o,fileName:r,saveOptions:l};return n.onDownload.call(void 0,d)===!1}return!1},[n.onDownload]),ie=e.useCallback(()=>{var o;t.scroller&&t.scroller.destroy(),t.scroller=new i.Scroller((o=c.current)==null?void 0:o.parentNode,{filter:".k-page",events:{}}),t.scroller.disablePanEventsTracking()},[]),ue=e.useCallback(o=>{const r=Array.from(o.querySelectorAll(".k-text-layer"));t.search=new i.SearchService({textContainers:r||[],highlightClass:"k-search-highlight",highlightMarkClass:"k-search-highlight-mark",charClass:"k-text-char"})},[]);t.done=e.useCallback(({pdfPages:o,pdfDoc:r,zoom:l})=>{t.document=r,t.pages=o,t.zoom=l,ie(),k(!1),O(!0),se(),c.current&&i.scrollToPage(c.current,0)},[]),t.error=e.useCallback(o=>{if(t.document=null,t.pages=[],k(!1),O(!1),n.onError){const r=typeof o=="string"?{message:o}:o,l={error:r!=null?r:u.toLanguageString(a.popupBlocked,a.messages[a.popupBlocked]),target:b.current};n.onError.call(void 0,l)}},[n.onError]),e.useEffect(()=>{c.current&&(n.url||n.data||n.arrayBuffer?(k(!0),i.removeChildren(c.current),i.loadPDF({url:n.url,data:n.data,arrayBuffer:n.arrayBuffer,dom:c.current,zoom:t.currentZoom,done:t.done,error:t.error}),q(t.currentZoom)):(t.document=null,t.pages=[],O(!1),k(!1),i.removeChildren(c.current)))},[n.url,n.data,n.arrayBuffer]);const X=e.useCallback((o,r,l)=>{c.current&&z.current&&(k(!0),i.removeChildren(c.current),i.reloadDocument({pdfDoc:o,zoom:r,dom:c.current,done:d=>{t.pages=d,t.zoom=r,k(!1),c.current&&l>0&&i.scrollToPage(c.current,l)},error:t.error}))},[t]);e.useEffect(()=>{q(h),c.current&&t.document&&h!==t.zoom&&X(t.document,h,E)},[h,t.document,t.zoom,X,q,E]),e.useEffect(()=>()=>{t.scroller&&t.scroller.destroy(),t.search&&t.search.destroy(),t.document=null,t.pages=[]},[]);const me=e.useCallback(()=>{H(!0),ue(c.current)},[]),de=e.useCallback(o=>{const r=o.value,l=t.search.search({text:r,matchCase:x});S(l.length?1:0),D(l.length),J(r)},[x]),ge=e.useCallback(()=>{const o=t.search.search({text:F,matchCase:!x});S(o.length?1:0),D(o.length),G(!x)},[x,F]),fe=e.useCallback(()=>{i.goToNextSearchMatch(t),S(v+1>y?1:v+1)},[v,y]),he=e.useCallback(()=>{i.goToPreviousSearchMatch(t),S(v-1<1?y:v-1)},[v,y]),Y=e.useCallback(()=>{t.search.destroy(),S(0),D(0),G(!1),J(""),H(!1)},[]),ke=e.useCallback(o=>{o.key==="Enter"?(o.preventDefault(),i.goToNextSearchMatch(t),S(v+1>y?1:v+1)):o.key==="Escape"&&Y()},[v,y]),ve=e.useCallback(o=>{if(c.current){const r=o.skip;i.scrollToPage(c.current,r);const l={page:r+1,target:b.current,syntheticEvent:o.syntheticEvent};n.onPageChange&&n.onPageChange.call(void 0,l)}U(o.skip)},[E,n.onPageChange]),be=e.useCallback(o=>{if(z.current){const r=i.currentPage(z.current);if(r!==E){U(r);const l={page:r+1,target:b.current,syntheticEvent:o};n.onPageChange&&n.onPageChange.call(void 0,l)}}},[E,n.onPageChange]),ye=e.useCallback(o=>{const r=Math.min(t.currentZoom+M,B);if(r!==t.currentZoom&&t.document&&(P(r),n.onZoom)){const l={zoom:r,target:b.current,syntheticEvent:o};n.onZoom.call(void 0,l)}},[t.currentZoom,t.document,M,B,n.onZoom]),pe=e.useCallback(o=>{const r=Math.max(t.currentZoom-M,R);if(r!==t.currentZoom&&t.document&&(P(r),n.onZoom)){const l={zoom:r,target:b.current,syntheticEvent:o};n.onZoom.call(void 0,l)}},[t.currentZoom,t.document,M,R,n.onZoom]),Ce=e.useCallback(o=>{const r=o.value===null?{text:"100%",value:1,id:100}:{...o.value};if(r.value===void 0){const d=parseFloat(r.text);typeof d=="number"&&!Number.isNaN(d)?r.value=d/100:r.value=1}let l=r?i.calculateZoomLevel(r.value,r.type,t.currentZoom,c.current):1;if(l=Math.round(l*100)/100,t.currentZoom!==l&&t.document&&(P(l),n.onZoom)){const d={zoom:l,target:b.current,syntheticEvent:o.syntheticEvent};n.onZoom.call(void 0,d)}},[n.onZoom]),Ee=e.useCallback(()=>{t.scroller.disablePanEventsTracking(),_(!0)},[]),Se=e.useCallback(()=>{t.scroller.enablePanEventsTracking(),_(!1)},[]),xe=e.useCallback(()=>{i.download({pdf:t.document,error:t.error},n.saveFileName,n.saveOptions,Q)},[n.url,n.data,n.arrayBuffer,n.saveFileName,n.saveOptions,Q]),we=e.useCallback(()=>{k(!0);const o=l=>{k(!1),t.error(l)},r=()=>{k(!1)};i.print(t.pages,r,o)},[]),Ze=e.useCallback(o=>{const r=o.newState;r[0]&&r[0].getRawFile&&r[0].getRawFile().arrayBuffer().then(d=>{if(c.current){k(!0),i.removeChildren(c.current);const j=t.props.zoom===void 0?N:t.props.zoom;i.loadPDF({arrayBuffer:d,dom:c.current,zoom:j,done:t.done,error:t.error}),P(j)}})},[N]),ze=e.useCallback(o=>{const r=o.target;if(r instanceof Element&&r.parentNode){const l=r.closest(".k-toolbar"),d=l&&l.querySelector(".k-upload input");d&&d.click()}},[]),$=le&&e.createElement("div",{className:"k-loader-container k-loader-container-md k-loader-top"},e.createElement("div",{className:"k-loader-container-overlay k-overlay-light"}),e.createElement("div",{className:"k-loader-container-inner "},e.createElement(We.Loader,{size:"large"}))),Le=e.createElement(m.ButtonGroup,{className:"k-toolbar-button-group k-button-group-solid"},e.createElement(m.Button,{className:"k-group-start",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.zoomOut,a.messages[a.zoomOut]),disabled:h<=R||!g,onClick:pe,icon:"zoom-out",svgIcon:f.zoomOutIcon}),e.createElement(m.Button,{className:"k-group-end",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.zoomIn,a.messages[a.zoomIn]),disabled:h>=B||!g,onClick:ye,icon:"zoom-in",svgIcon:f.zoomInIcon})),Me=e.createElement(Ve.ComboBox,{className:"k-toolbar-combobox",disabled:!g,data:K.map(o=>({...o,text:o.locationString?u.toLanguageString(o.locationString,a.messages[o.locationString]):o.text})),dataItemKey:"id",textField:"text",value:g?Z:null,allowCustom:!0,onChange:Ce,placeholder:u.toLanguageString(a.zoomLevel,a.messages[a.zoomLevel])}),Pe=e.createElement(je.Pager,{disabled:!g,previousNext:!0,type:"input",skip:E,take:1,total:t.pages?t.pages.length:0,info:!1,onPageChange:ve}),Ie=e.createElement(m.ToolbarSpacer,null),Te=e.createElement(m.ButtonGroup,{className:"k-toolbar-button-group k-button-group-solid"},e.createElement(m.Button,{className:"k-group-start",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.enableSelection,a.messages[a.enableSelection]),icon:"pointer",svgIcon:f.pointerIcon,disabled:!g,togglable:!0,selected:I&&g,onClick:Ee}),e.createElement(m.Button,{className:"k-group-end",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.enablePanning,a.messages[a.enablePanning]),icon:"hand",svgIcon:f.handIcon,disabled:!g,togglable:!0,selected:!I&&g,onClick:Se})),Ne=e.createElement(m.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.search,a.messages[a.search]),icon:"search",svgIcon:f.searchIcon,disabled:!g,onClick:me}),Re=e.createElement(e.Fragment,null,e.createElement(m.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.open,a.messages[a.open]),icon:"folder-open",svgIcon:f.folderOpenIcon,onClick:ze}),e.createElement("div",{style:{display:"none"}},e.createElement(Ae.Upload,{restrictions:{allowedExtensions:[".pdf"]},onAdd:Ze,autoUpload:!1,defaultFiles:[],multiple:!1,accept:".pdf,.PDF",withCredentials:!1}))),Be=e.createElement(m.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.download,a.messages[a.download]),icon:"download",svgIcon:f.downloadIcon,disabled:!g,onClick:xe}),Oe=e.createElement(m.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.print,a.messages[a.print]),icon:"print",svgIcon:f.printIcon,disabled:!g,onClick:we}),De={pager:Pe,spacer:Ie,zoomInOut:Le,zoom:Me,selection:Te,search:Ne,open:Re,download:Be,print:Oe},Fe=(n.tools||w.tools).map(o=>({...De[o],key:"toobar-tool-"+o+He()})),ee=e.createElement(m.Toolbar,{buttons:_e},...Fe),te=e.createElement("div",{className:T.classNames("k-canvas k-pdf-viewer-canvas k-pos-relative k-overflow-auto",{"k-enable-text-select":I,"k-enable-panning":!I}),onScroll:be},ce&&e.createElement("div",{className:"k-search-panel k-pos-sticky k-top-center"},e.createElement(A.TextBox,{value:F,onChange:de,placeholder:u.toLanguageString(a.search,a.messages[a.search]),autoFocus:!0,onKeyDown:ke,suffix:()=>e.createElement(e.Fragment,null,e.createElement(A.InputSeparator,null),e.createElement(A.InputSuffix,null,e.createElement(m.Button,{icon:"convert-lowercase",svgIcon:f.convertLowercaseIcon,title:u.toLanguageString(a.matchCase,a.messages[a.matchCase]),fillMode:"flat",togglable:!0,selected:x,onClick:ge})))}),e.createElement("span",{className:"k-search-matches"},e.createElement("span",null,v)," ",u.toLanguageString(a.searchOf,a.messages[a.searchOf]),e.createElement("span",null,y)),e.createElement(m.Button,{title:u.toLanguageString(a.prevMatch,a.messages[a.prevMatch]),fillMode:"flat",icon:"arrow-up",svgIcon:f.arrowUpIcon,disabled:y===0,onClick:he}),e.createElement(m.Button,{title:u.toLanguageString(a.nextMatch,a.messages[a.nextMatch]),fillMode:"flat",icon:"arrow-down",svgIcon:f.arrowDownIcon,disabled:y===0,onClick:fe}),e.createElement(m.Button,{title:u.toLanguageString(a.close,a.messages[a.close]),fillMode:"flat",icon:"x",svgIcon:f.xIcon,onClick:Y})),e.createElement("div",{ref:c,className:"k-pdf-viewer-pages"}));return e.createElement("div",{className:"k-pdf-viewer",style:n.style,ref:z},n.onRenderLoader?n.onRenderLoader.call(void 0,$||null):$,n.onRenderToolbar?n.onRenderToolbar.call(void 0,ee):ee,n.onRenderContent?n.onRenderContent.call(void 0,te):te,C&&e.createElement(T.WatermarkOverlay,{message:L}))});V.displayName="KendoReactPDFViewer";V.propTypes={url:s.string,data:s.string,arrayBuffer:s.any,typedArray:s.any,style:s.object,saveFileName:s.string,saveOptions:s.object,tools:s.arrayOf(s.oneOf(ae).isRequired),zoomLevels:s.arrayOf(s.any),zoom:s.number,defaultZoom:s.number,minZoom:s.number,maxZoom:s.number,zoomRate:s.number,onError:s.func,onLoad:s.func,onDownload:s.func,onRenderToolbar:s.func,onRenderContent:s.func,onRenderLoader:s.func,onZoom:s.func};exports.PDFViewer=V;
|
|
8
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const qe=require("react"),s=require("prop-types"),m=require("@progress/kendo-react-buttons"),A=require("@progress/kendo-react-inputs"),je=require("@progress/kendo-react-data-tools"),Ae=require("@progress/kendo-react-upload"),Ve=require("@progress/kendo-react-dropdowns"),We=require("@progress/kendo-react-indicators"),T=require("@progress/kendo-react-common"),Ke=require("@progress/kendo-react-intl"),f=require("@progress/kendo-svg-icons");require("pdfjs-dist/build/pdf.worker.min.mjs");const oe=require("./package-metadata.js"),i=require("@progress/kendo-pdfviewer-common"),a=require("./messages.js");function Ue(n){const p=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const C in n)if(C!=="default"){const L=Object.getOwnPropertyDescriptor(n,C);Object.defineProperty(p,C,L.get?L:{enumerable:!0,get:()=>n[C]})}}return p.default=n,Object.freeze(p)}const e=Ue(qe),ae=["pager","spacer","zoomInOut","zoom","selection","spacer","search","open","download","print"],w={minZoom:.5,maxZoom:4,tools:[...ae],zoomRate:.25,zoomLevels:[{id:1,priority:1,value:1,text:"Actual width",type:"ActualWidth",locationString:a.actualWidth},{id:2,priority:2,value:1,text:"Fit to width",type:"FitToWidth",locationString:a.fitToWidth},{id:3,priority:3,value:1,text:"Fit to page",type:"FitToPage",locationString:a.fitToPage},{id:4,priority:4,value:.5,text:"50%",type:""},{id:5,priority:5,value:.75,text:"75%",type:""},{id:6,priority:100,value:1,text:"100%",type:""},{id:7,priority:7,value:1.25,text:"125%",type:""},{id:8,priority:8,value:1.5,text:"150%",type:""},{id:9,priority:9,value:2,text:"200%",type:""},{id:10,priority:10,value:3,text:"300%",type:""},{id:11,priority:11,value:4,text:"400%",type:""}],defaultZoom:i.DEFAULT_ZOOM_LEVEL},_e=[".k-toolbar > button",".k-toolbar .k-combobox > input",".k-toolbar .k-button-group > button",".k-toolbar .k-pager > a",".k-toolbar .k-pager input"];let ne=0;function He(){return ne++,ne}const Ge=(n,p)=>n.priority>p.priority?-1:n.priority<p.priority?1:0,V=e.forwardRef((n,p)=>{const C=!T.validatePackage(oe.packageMetadata,{component:"PDFViewer"}),L=T.getLicenseMessage(oe.packageMetadata),{zoom:W,zoomLevels:K=w.zoomLevels,defaultZoom:N=w.defaultZoom,minZoom:R=w.minZoom,maxZoom:B=w.maxZoom,zoomRate:M=w.zoomRate}=n,u=Ke.useLocalization(),c=e.useRef(null),[re,P]=e.useState(N),h=W!==void 0?W:re,Z=K.slice().sort(Ge).find(o=>o.value===h)||{text:h*100+"%",value:h,id:h,locationString:""};Z.locationString&&(Z.text=u.toLanguageString(Z.locationString,a.messages[Z.locationString]));const[g,O]=e.useState(!1),[le,k]=e.useState(!0),[E,U]=e.useState(0),[I,_]=e.useState(!0),[ce,H]=e.useState(!1),[y,D]=e.useState(0),[v,S]=e.useState(0),[x,G]=e.useState(!1),[F,J]=e.useState(""),t=e.useMemo(()=>({}),[]);t.currentZoom=h,t.props=n;const q=e.useCallback(o=>{c.current&&c.current.style.setProperty("--scale-factor",String(o))},[]),b=e.useRef(null),z=e.useRef(null);e.useImperativeHandle(b,()=>({get element(){return z.current},props:n,get pages(){return t.pages},get document(){return t.document}}),[]),e.useImperativeHandle(p,()=>b.current);const se=e.useCallback(()=>{if(t.props.onLoad){const o={target:b.current};t.props.onLoad.call(void 0,o)}},[]),Q=e.useCallback((o,r,l)=>{if(n.onDownload){const d={target:b.current,blob:o,fileName:r,saveOptions:l};return n.onDownload.call(void 0,d)===!1}return!1},[n.onDownload]),ie=e.useCallback(()=>{var o;t.scroller&&t.scroller.destroy(),t.scroller=new i.Scroller((o=c.current)==null?void 0:o.parentNode,{filter:".k-page",events:{}}),t.scroller.disablePanEventsTracking()},[]),ue=e.useCallback(o=>{const r=Array.from(o.querySelectorAll(".k-text-layer"));t.search=new i.SearchService({textContainers:r||[],highlightClass:"k-search-highlight",highlightMarkClass:"k-search-highlight-mark",charClass:"k-text-char"})},[]);t.done=e.useCallback(({pdfPages:o,pdfDoc:r,zoom:l})=>{t.document=r,t.pages=o,t.zoom=l,ie(),k(!1),O(!0),se(),c.current&&i.scrollToPage(c.current,0)},[]),t.error=e.useCallback(o=>{if(t.document=null,t.pages=[],k(!1),O(!1),n.onError){const r=typeof o=="string"?{message:o}:o,l={error:r!=null?r:u.toLanguageString(a.popupBlocked,a.messages[a.popupBlocked]),target:b.current};n.onError.call(void 0,l)}},[n.onError]),e.useEffect(()=>{c.current&&(n.url||n.data||n.arrayBuffer?(k(!0),i.removeChildren(c.current),i.loadPDF({url:n.url,data:n.data,arrayBuffer:n.arrayBuffer,dom:c.current,zoom:t.currentZoom,done:t.done,error:t.error}),q(t.currentZoom)):(t.document=null,t.pages=[],O(!1),k(!1),i.removeChildren(c.current)))},[n.url,n.data,n.arrayBuffer]);const X=e.useCallback((o,r,l)=>{c.current&&z.current&&(k(!0),i.removeChildren(c.current),i.reloadDocument({pdfDoc:o,zoom:r,dom:c.current,done:d=>{t.pages=d,t.zoom=r,k(!1),c.current&&l>0&&i.scrollToPage(c.current,l)},error:t.error}))},[t]);e.useEffect(()=>{q(h),c.current&&t.document&&h!==t.zoom&&X(t.document,h,E)},[h,t.document,t.zoom,X,q,E]),e.useEffect(()=>()=>{t.scroller&&t.scroller.destroy(),t.search&&t.search.destroy(),t.document=null,t.pages=[]},[]);const me=e.useCallback(()=>{H(!0),ue(c.current)},[]),de=e.useCallback(o=>{const r=o.value,l=t.search.search({text:r,matchCase:x});S(l.length?1:0),D(l.length),J(r)},[x]),ge=e.useCallback(()=>{const o=t.search.search({text:F,matchCase:!x});S(o.length?1:0),D(o.length),G(!x)},[x,F]),fe=e.useCallback(()=>{i.goToNextSearchMatch(t),S(v+1>y?1:v+1)},[v,y]),he=e.useCallback(()=>{i.goToPreviousSearchMatch(t),S(v-1<1?y:v-1)},[v,y]),Y=e.useCallback(()=>{t.search.destroy(),S(0),D(0),G(!1),J(""),H(!1)},[]),ke=e.useCallback(o=>{o.key==="Enter"?(o.preventDefault(),i.goToNextSearchMatch(t),S(v+1>y?1:v+1)):o.key==="Escape"&&Y()},[v,y]),ve=e.useCallback(o=>{if(c.current){const r=o.skip;i.scrollToPage(c.current,r);const l={page:r+1,target:b.current,syntheticEvent:o.syntheticEvent};n.onPageChange&&n.onPageChange.call(void 0,l)}U(o.skip)},[E,n.onPageChange]),be=e.useCallback(o=>{if(z.current){const r=i.currentPage(z.current);if(r!==E){U(r);const l={page:r+1,target:b.current,syntheticEvent:o};n.onPageChange&&n.onPageChange.call(void 0,l)}}},[E,n.onPageChange]),ye=e.useCallback(o=>{const r=Math.min(t.currentZoom+M,B);if(r!==t.currentZoom&&t.document&&(P(r),n.onZoom)){const l={zoom:r,target:b.current,syntheticEvent:o};n.onZoom.call(void 0,l)}},[t.currentZoom,t.document,M,B,n.onZoom]),pe=e.useCallback(o=>{const r=Math.max(t.currentZoom-M,R);if(r!==t.currentZoom&&t.document&&(P(r),n.onZoom)){const l={zoom:r,target:b.current,syntheticEvent:o};n.onZoom.call(void 0,l)}},[t.currentZoom,t.document,M,R,n.onZoom]),Ce=e.useCallback(o=>{const r=o.value===null?{text:"100%",value:1}:{...o.value};if(r.value===void 0){const d=parseFloat(r.text);typeof d=="number"&&!Number.isNaN(d)?r.value=d/100:r.value=1}let l=r?i.calculateZoomLevel(r.value,r.type,t.currentZoom,c.current):1;if(l=Math.round(l*100)/100,t.currentZoom!==l&&t.document&&(P(l),n.onZoom)){const d={zoom:l,target:b.current,syntheticEvent:o.syntheticEvent};n.onZoom.call(void 0,d)}},[n.onZoom]),Ee=e.useCallback(()=>{t.scroller.disablePanEventsTracking(),_(!0)},[]),Se=e.useCallback(()=>{t.scroller.enablePanEventsTracking(),_(!1)},[]),xe=e.useCallback(()=>{i.download({pdf:t.document,error:t.error},n.saveFileName,n.saveOptions,Q)},[n.url,n.data,n.arrayBuffer,n.saveFileName,n.saveOptions,Q]),we=e.useCallback(()=>{k(!0);const o=l=>{k(!1),t.error(l)},r=()=>{k(!1)};i.print(t.pages,r,o)},[]),Ze=e.useCallback(o=>{const r=o.newState;r[0]&&r[0].getRawFile&&r[0].getRawFile().arrayBuffer().then(d=>{if(c.current){k(!0),i.removeChildren(c.current);const j=t.props.zoom===void 0?N:t.props.zoom;i.loadPDF({arrayBuffer:d,dom:c.current,zoom:j,done:t.done,error:t.error}),P(j)}})},[N]),ze=e.useCallback(o=>{const r=o.target;if(r instanceof Element&&r.parentNode){const l=r.closest(".k-toolbar"),d=l&&l.querySelector(".k-upload input");d&&d.click()}},[]),$=le&&e.createElement("div",{className:"k-loader-container k-loader-container-md k-loader-top"},e.createElement("div",{className:"k-loader-container-overlay k-overlay-light"}),e.createElement("div",{className:"k-loader-container-inner "},e.createElement(We.Loader,{size:"large"}))),Le=e.createElement(m.ButtonGroup,{className:"k-toolbar-button-group k-button-group-solid"},e.createElement(m.Button,{className:"k-group-start",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.zoomOut,a.messages[a.zoomOut]),disabled:h<=R||!g,onClick:pe,icon:"zoom-out",svgIcon:f.zoomOutIcon}),e.createElement(m.Button,{className:"k-group-end",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.zoomIn,a.messages[a.zoomIn]),disabled:h>=B||!g,onClick:ye,icon:"zoom-in",svgIcon:f.zoomInIcon})),Me=e.createElement(Ve.ComboBox,{className:"k-toolbar-combobox",disabled:!g,data:K.map(o=>({...o,text:o.locationString?u.toLanguageString(o.locationString,a.messages[o.locationString]):o.text})),dataItemKey:"id",textField:"text",value:g?Z:null,allowCustom:!0,onChange:Ce,placeholder:u.toLanguageString(a.zoomLevel,a.messages[a.zoomLevel])}),Pe=e.createElement(je.Pager,{disabled:!g,previousNext:!0,type:"input",skip:E,take:1,total:t.pages?t.pages.length:0,info:!1,onPageChange:ve}),Ie=e.createElement(m.ToolbarSpacer,null),Te=e.createElement(m.ButtonGroup,{className:"k-toolbar-button-group k-button-group-solid"},e.createElement(m.Button,{className:"k-group-start",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.enableSelection,a.messages[a.enableSelection]),icon:"pointer",svgIcon:f.pointerIcon,disabled:!g,togglable:!0,selected:I&&g,onClick:Ee}),e.createElement(m.Button,{className:"k-group-end",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.enablePanning,a.messages[a.enablePanning]),icon:"hand",svgIcon:f.handIcon,disabled:!g,togglable:!0,selected:!I&&g,onClick:Se})),Ne=e.createElement(m.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.search,a.messages[a.search]),icon:"search",svgIcon:f.searchIcon,disabled:!g,onClick:me}),Re=e.createElement(e.Fragment,null,e.createElement(m.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.open,a.messages[a.open]),icon:"folder-open",svgIcon:f.folderOpenIcon,onClick:ze}),e.createElement("div",{style:{display:"none"}},e.createElement(Ae.Upload,{restrictions:{allowedExtensions:[".pdf"]},onAdd:Ze,autoUpload:!1,defaultFiles:[],multiple:!1,accept:".pdf,.PDF",withCredentials:!1}))),Be=e.createElement(m.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.download,a.messages[a.download]),icon:"download",svgIcon:f.downloadIcon,disabled:!g,onClick:xe}),Oe=e.createElement(m.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:u.toLanguageString(a.print,a.messages[a.print]),icon:"print",svgIcon:f.printIcon,disabled:!g,onClick:we}),De={pager:Pe,spacer:Ie,zoomInOut:Le,zoom:Me,selection:Te,search:Ne,open:Re,download:Be,print:Oe},Fe=(n.tools||w.tools).map(o=>({...De[o],key:"toobar-tool-"+o+He()})),ee=e.createElement(m.Toolbar,{buttons:_e},...Fe),te=e.createElement("div",{className:T.classNames("k-canvas k-pdf-viewer-canvas k-pos-relative k-overflow-auto",{"k-enable-text-select":I,"k-enable-panning":!I}),onScroll:be},ce&&e.createElement("div",{className:"k-search-panel k-pos-sticky k-top-center"},e.createElement(A.TextBox,{value:F,onChange:de,placeholder:u.toLanguageString(a.search,a.messages[a.search]),autoFocus:!0,onKeyDown:ke,suffix:()=>e.createElement(e.Fragment,null,e.createElement(A.InputSeparator,null),e.createElement(A.InputSuffix,null,e.createElement(m.Button,{icon:"convert-lowercase",svgIcon:f.convertLowercaseIcon,title:u.toLanguageString(a.matchCase,a.messages[a.matchCase]),fillMode:"flat",togglable:!0,selected:x,onClick:ge})))}),e.createElement("span",{className:"k-search-matches"},e.createElement("span",null,v)," ",u.toLanguageString(a.searchOf,a.messages[a.searchOf]),e.createElement("span",null,y)),e.createElement(m.Button,{title:u.toLanguageString(a.prevMatch,a.messages[a.prevMatch]),fillMode:"flat",icon:"arrow-up",svgIcon:f.arrowUpIcon,disabled:y===0,onClick:he}),e.createElement(m.Button,{title:u.toLanguageString(a.nextMatch,a.messages[a.nextMatch]),fillMode:"flat",icon:"arrow-down",svgIcon:f.arrowDownIcon,disabled:y===0,onClick:fe}),e.createElement(m.Button,{title:u.toLanguageString(a.close,a.messages[a.close]),fillMode:"flat",icon:"x",svgIcon:f.xIcon,onClick:Y})),e.createElement("div",{ref:c,className:"k-pdf-viewer-pages"}));return e.createElement("div",{className:"k-pdf-viewer",style:n.style,ref:z},n.onRenderLoader?n.onRenderLoader.call(void 0,$||null):$,n.onRenderToolbar?n.onRenderToolbar.call(void 0,ee):ee,n.onRenderContent?n.onRenderContent.call(void 0,te):te,C&&e.createElement(T.WatermarkOverlay,{message:L}))});V.displayName="KendoReactPDFViewer";V.propTypes={url:s.string,data:s.string,arrayBuffer:s.any,typedArray:s.any,style:s.object,saveFileName:s.string,saveOptions:s.object,tools:s.arrayOf(s.oneOf(ae).isRequired),zoomLevels:s.arrayOf(s.any),zoom:s.number,defaultZoom:s.number,minZoom:s.number,maxZoom:s.number,zoomRate:s.number,onError:s.func,onLoad:s.func,onDownload:s.func,onRenderToolbar:s.func,onRenderContent:s.func,onRenderLoader:s.func,onZoom:s.func};exports.PDFViewer=V;
|
package/PDFViewer.mjs
CHANGED
|
@@ -18,8 +18,8 @@ import { useLocalization as ft } from "@progress/kendo-react-intl";
|
|
|
18
18
|
import { zoomOutIcon as ht, zoomInIcon as vt, pointerIcon as kt, handIcon as bt, searchIcon as pt, folderOpenIcon as yt, downloadIcon as Ct, printIcon as Et, convertLowercaseIcon as St, arrowUpIcon as xt, arrowDownIcon as wt, xIcon as Zt } from "@progress/kendo-svg-icons";
|
|
19
19
|
import "pdfjs-dist/build/pdf.worker.min.mjs";
|
|
20
20
|
import { packageMetadata as Y } from "./package-metadata.mjs";
|
|
21
|
-
import {
|
|
22
|
-
import { messages as i, popupBlocked as oe, zoomOut as ne, zoomIn as ae, zoomLevel as re, enableSelection as le, enablePanning as ce, search as I, open as se, download as ie, print as ue, matchCase as me, searchOf as de, prevMatch as ge, nextMatch as fe, close as he
|
|
21
|
+
import { DEFAULT_ZOOM_LEVEL as Lt, Scroller as zt, SearchService as It, scrollToPage as B, removeChildren as z, loadPDF as ee, reloadDocument as Mt, goToNextSearchMatch as te, goToPreviousSearchMatch as Tt, currentPage as Nt, calculateZoomLevel as Pt, download as Rt, print as Ft } from "@progress/kendo-pdfviewer-common";
|
|
22
|
+
import { actualWidth as Dt, fitToWidth as Ot, fitToPage as Bt, messages as i, popupBlocked as oe, zoomOut as ne, zoomIn as ae, zoomLevel as re, enableSelection as le, enablePanning as ce, search as I, open as se, download as ie, print as ue, matchCase as me, searchOf as de, prevMatch as ge, nextMatch as fe, close as he } from "./messages.mjs";
|
|
23
23
|
const ke = [
|
|
24
24
|
"pager",
|
|
25
25
|
"spacer",
|
|
@@ -49,7 +49,7 @@ const ke = [
|
|
|
49
49
|
{ id: 10, priority: 10, value: 3, text: "300%", type: "" },
|
|
50
50
|
{ id: 11, priority: 11, value: 4, text: "400%", type: "" }
|
|
51
51
|
],
|
|
52
|
-
defaultZoom:
|
|
52
|
+
defaultZoom: Lt
|
|
53
53
|
}, At = [
|
|
54
54
|
".k-toolbar > button",
|
|
55
55
|
".k-toolbar .k-combobox > input",
|
|
@@ -121,13 +121,13 @@ const Wt = (n, x) => n.priority > x.priority ? -1 : n.priority < x.priority ? 1
|
|
|
121
121
|
[n.onDownload]
|
|
122
122
|
), we = e.useCallback(() => {
|
|
123
123
|
var o;
|
|
124
|
-
t.scroller && t.scroller.destroy(), t.scroller = new
|
|
124
|
+
t.scroller && t.scroller.destroy(), t.scroller = new zt((o = l.current) == null ? void 0 : o.parentNode, {
|
|
125
125
|
filter: ".k-page",
|
|
126
126
|
events: {}
|
|
127
127
|
}), t.scroller.disablePanEventsTracking();
|
|
128
128
|
}, []), Ze = e.useCallback((o) => {
|
|
129
129
|
const a = Array.from(o.querySelectorAll(".k-text-layer"));
|
|
130
|
-
t.search = new
|
|
130
|
+
t.search = new It({
|
|
131
131
|
textContainers: a || [],
|
|
132
132
|
highlightClass: "k-search-highlight",
|
|
133
133
|
highlightMarkClass: "k-search-highlight-mark",
|
|
@@ -160,7 +160,7 @@ const Wt = (n, x) => n.priority > x.priority ? -1 : n.priority < x.priority ? 1
|
|
|
160
160
|
}, [n.url, n.data, n.arrayBuffer]);
|
|
161
161
|
const $ = e.useCallback(
|
|
162
162
|
(o, a, r) => {
|
|
163
|
-
l.current && S.current && (f(!0), z(l.current),
|
|
163
|
+
l.current && S.current && (f(!0), z(l.current), Mt({
|
|
164
164
|
pdfDoc: o,
|
|
165
165
|
zoom: a,
|
|
166
166
|
dom: l.current,
|
|
@@ -191,7 +191,7 @@ const Wt = (n, x) => n.priority > x.priority ? -1 : n.priority < x.priority ? 1
|
|
|
191
191
|
}, [y, F]), Me = e.useCallback(() => {
|
|
192
192
|
te(t), p(h + 1 > k ? 1 : h + 1);
|
|
193
193
|
}, [h, k]), Te = e.useCallback(() => {
|
|
194
|
-
|
|
194
|
+
Tt(t), p(h - 1 < 1 ? k : h - 1);
|
|
195
195
|
}, [h, k]), _ = e.useCallback(() => {
|
|
196
196
|
t.search.destroy(), p(0), R(0), j(!1), q(""), U(!1);
|
|
197
197
|
}, []), Ne = e.useCallback(
|
|
@@ -217,7 +217,7 @@ const Wt = (n, x) => n.priority > x.priority ? -1 : n.priority < x.priority ? 1
|
|
|
217
217
|
), Re = e.useCallback(
|
|
218
218
|
(o) => {
|
|
219
219
|
if (S.current) {
|
|
220
|
-
const a =
|
|
220
|
+
const a = Nt(S.current);
|
|
221
221
|
if (a !== b) {
|
|
222
222
|
W(a);
|
|
223
223
|
const r = {
|
|
@@ -258,12 +258,12 @@ const Wt = (n, x) => n.priority > x.priority ? -1 : n.priority < x.priority ? 1
|
|
|
258
258
|
[t.currentZoom, t.document, w, T, n.onZoom]
|
|
259
259
|
), Oe = e.useCallback(
|
|
260
260
|
(o) => {
|
|
261
|
-
const a = o.value === null ? { text: "100%", value: 1
|
|
261
|
+
const a = o.value === null ? { text: "100%", value: 1 } : { ...o.value };
|
|
262
262
|
if (a.value === void 0) {
|
|
263
263
|
const u = parseFloat(a.text);
|
|
264
264
|
typeof u == "number" && !Number.isNaN(u) ? a.value = u / 100 : a.value = 1;
|
|
265
265
|
}
|
|
266
|
-
let r = a ?
|
|
266
|
+
let r = a ? Pt(a.value, a.type, t.currentZoom, l.current) : 1;
|
|
267
267
|
if (r = Math.round(r * 100) / 100, t.currentZoom !== r && t.document && (Z(r), n.onZoom)) {
|
|
268
268
|
const u = {
|
|
269
269
|
zoom: r,
|
|
@@ -279,7 +279,7 @@ const Wt = (n, x) => n.priority > x.priority ? -1 : n.priority < x.priority ? 1
|
|
|
279
279
|
}, []), Ae = e.useCallback(() => {
|
|
280
280
|
t.scroller.enablePanEventsTracking(), K(!1);
|
|
281
281
|
}, []), Ve = e.useCallback(() => {
|
|
282
|
-
|
|
282
|
+
Rt(
|
|
283
283
|
{
|
|
284
284
|
pdf: t.document,
|
|
285
285
|
error: t.error
|
|
@@ -295,7 +295,7 @@ const Wt = (n, x) => n.priority > x.priority ? -1 : n.priority < x.priority ? 1
|
|
|
295
295
|
}, a = () => {
|
|
296
296
|
f(!1);
|
|
297
297
|
};
|
|
298
|
-
|
|
298
|
+
Ft(t.pages, a, o);
|
|
299
299
|
}, []), Ke = e.useCallback(
|
|
300
300
|
(o) => {
|
|
301
301
|
const a = o.newState;
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
13
13
|
*-------------------------------------------------------------------------------------------
|
|
14
14
|
*/
|
|
15
|
-
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@progress/kendo-pdfviewer-common"),require("react"),require("prop-types"),require("@progress/kendo-react-buttons"),require("@progress/kendo-react-inputs"),require("@progress/kendo-react-data-tools"),require("@progress/kendo-react-upload"),require("@progress/kendo-react-dropdowns"),require("@progress/kendo-react-indicators"),require("@progress/kendo-react-common"),require("@progress/kendo-react-intl"),require("@progress/kendo-svg-icons"),require("pdfjs-dist/build/pdf.worker.min.mjs")):"function"==typeof define&&define.amd?define(["exports","@progress/kendo-pdfviewer-common","react","prop-types","@progress/kendo-react-buttons","@progress/kendo-react-inputs","@progress/kendo-react-data-tools","@progress/kendo-react-upload","@progress/kendo-react-dropdowns","@progress/kendo-react-indicators","@progress/kendo-react-common","@progress/kendo-react-intl","@progress/kendo-svg-icons","pdfjs-dist/build/pdf.worker.min.mjs"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).KendoReactPdfViewer={},e.KendoPdfviewerCommon,e.React,e.PropTypes,e.KendoReactButtons,e.KendoReactInputs,e.KendoReactDataTools,e.KendoReactUpload,e.KendoReactDropdowns,e.KendoReactIndicators,e.KendoReactCommon,e.KendoReactIntl,e.KendoSvgIcons)}(this,(function(e,o,t,r,a,n,l,c,s,i,u,d,m){"use strict";function p(e){var o=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(o,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}})),o.default=e,Object.freeze(o)}var g=p(t);const f=Object.freeze({name:"@progress/kendo-react-pdf-viewer",productName:"KendoReact",productCode:"KENDOUIREACT",productCodes:["KENDOUIREACT"],publishDate:1673300081,version:"13.3.0",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning"}),v="pdfviewer.zoomIn",k="pdfviewer.zoomOut",b="pdfviewer.zoomLevel",h="pdfviewer.enableSelection",y="pdfviewer.enablePanning",C="pdfviewer.search",w="pdfviewer.open",E="pdfviewer.download",S="pdfviewer.print",x="pdfviewer.close",P="pdfviewer.matchCase",I="pdfviewer.prevMatch",z="pdfviewer.nextMatch",N="pdfviewer.actualWidth",L="pdfviewer.fitToWidth",Z="pdfviewer.fitToPage",R="pdfviewer.popupBlocked",T="pdfviewer.searchOf",O={[v]:"Zoom in",[k]:"Zoom out",[b]:"Choose zoom level",[h]:"Enable selection",[y]:"Enable panning",[C]:"Search",[w]:"Open",[E]:"Download",[T]:"of",[S]:"Print",[x]:"Close",[P]:"Match case",[I]:"Previous match",[z]:"Next match",[N]:"Actual width",[L]:"Fit to width",[Z]:"Fit to page",[R]:"Popup is blocked."},B=["pager","spacer","zoomInOut","zoom","selection","spacer","search","open","download","print"],D={minZoom:.5,maxZoom:4,tools:[...B],zoomRate:.25,zoomLevels:[{id:1,priority:1,value:1,text:"Actual width",type:"ActualWidth",locationString:N},{id:2,priority:2,value:1,text:"Fit to width",type:"FitToWidth",locationString:L},{id:3,priority:3,value:1,text:"Fit to page",type:"FitToPage",locationString:Z},{id:4,priority:4,value:.5,text:"50%",type:""},{id:5,priority:5,value:.75,text:"75%",type:""},{id:6,priority:100,value:1,text:"100%",type:""},{id:7,priority:7,value:1.25,text:"125%",type:""},{id:8,priority:8,value:1.5,text:"150%",type:""},{id:9,priority:9,value:2,text:"200%",type:""},{id:10,priority:10,value:3,text:"300%",type:""},{id:11,priority:11,value:4,text:"400%",type:""}],defaultZoom:o.DEFAULT_ZOOM_LEVEL},M=[".k-toolbar > button",".k-toolbar .k-combobox > input",".k-toolbar .k-button-group > button",".k-toolbar .k-pager > a",".k-toolbar .k-pager input"];let F=0;const K=(e,o)=>e.priority>o.priority?-1:e.priority<o.priority?1:0,q=g.forwardRef(((e,t)=>{const r=!u.validatePackage(f,{component:"PDFViewer"}),p=u.getLicenseMessage(f),{zoom:N,zoomLevels:L=D.zoomLevels,defaultZoom:Z=D.defaultZoom,minZoom:B=D.minZoom,maxZoom:q=D.maxZoom,zoomRate:j=D.zoomRate}=e,A=d.useLocalization(),U=g.useRef(null),[V,W]=g.useState(Z),_=void 0!==N?N:V,G=L.slice().sort(K).find((e=>e.value===_))||{text:100*_+"%",value:_,id:_,locationString:""};G.locationString&&(G.text=A.toLanguageString(G.locationString,O[G.locationString]));const[H,$]=g.useState(!1),[J,Q]=g.useState(!0),[X,Y]=g.useState(0),[ee,oe]=g.useState(!0),[te,re]=g.useState(!1),[ae,ne]=g.useState(0),[le,ce]=g.useState(0),[se,ie]=g.useState(!1),[ue,de]=g.useState(""),me=g.useMemo((()=>({})),[]);me.currentZoom=_,me.props=e;const pe=g.useCallback((e=>{U.current&&U.current.style.setProperty("--scale-factor",String(e))}),[]),ge=g.useRef(null),fe=g.useRef(null);g.useImperativeHandle(ge,(()=>({get element(){return fe.current},props:e,get pages(){return me.pages},get document(){return me.document}})),[]),g.useImperativeHandle(t,(()=>ge.current));const ve=g.useCallback((()=>{if(me.props.onLoad){const e={target:ge.current};me.props.onLoad.call(void 0,e)}}),[]),ke=g.useCallback(((o,t,r)=>{if(e.onDownload){const a={target:ge.current,blob:o,fileName:t,saveOptions:r};return!1===e.onDownload.call(void 0,a)}return!1}),[e.onDownload]),be=g.useCallback((()=>{var e;me.scroller&&me.scroller.destroy(),me.scroller=new o.Scroller(null==(e=U.current)?void 0:e.parentNode,{filter:".k-page",events:{}}),me.scroller.disablePanEventsTracking()}),[]),he=g.useCallback((e=>{const t=Array.from(e.querySelectorAll(".k-text-layer"));me.search=new o.SearchService({textContainers:t||[],highlightClass:"k-search-highlight",highlightMarkClass:"k-search-highlight-mark",charClass:"k-text-char"})}),[]);me.done=g.useCallback((({pdfPages:e,pdfDoc:t,zoom:r})=>{me.document=t,me.pages=e,me.zoom=r,be(),Q(!1),$(!0),ve(),U.current&&o.scrollToPage(U.current,0)}),[]),me.error=g.useCallback((o=>{if(me.document=null,me.pages=[],Q(!1),$(!1),e.onError){const t="string"==typeof o?{message:o}:o,r={error:null!=t?t:A.toLanguageString(R,O[R]),target:ge.current};e.onError.call(void 0,r)}}),[e.onError]),g.useEffect((()=>{U.current&&(e.url||e.data||e.arrayBuffer?(Q(!0),o.removeChildren(U.current),o.loadPDF({url:e.url,data:e.data,arrayBuffer:e.arrayBuffer,dom:U.current,zoom:me.currentZoom,done:me.done,error:me.error}),pe(me.currentZoom)):(me.document=null,me.pages=[],$(!1),Q(!1),o.removeChildren(U.current)))}),[e.url,e.data,e.arrayBuffer]);const ye=g.useCallback(((e,t,r)=>{U.current&&fe.current&&(Q(!0),o.removeChildren(U.current),o.reloadDocument({pdfDoc:e,zoom:t,dom:U.current,done:e=>{me.pages=e,me.zoom=t,Q(!1),U.current&&r>0&&o.scrollToPage(U.current,r)},error:me.error}))}),[me]);g.useEffect((()=>{pe(_),U.current&&me.document&&_!==me.zoom&&ye(me.document,_,X)}),[_,me.document,me.zoom,ye,pe,X]),g.useEffect((()=>()=>{me.scroller&&me.scroller.destroy(),me.search&&me.search.destroy(),me.document=null,me.pages=[]}),[]);const Ce=g.useCallback((()=>{re(!0),he(U.current)}),[]),we=g.useCallback((e=>{const o=e.value,t=me.search.search({text:o,matchCase:se});ce(t.length?1:0),ne(t.length),de(o)}),[se]),Ee=g.useCallback((()=>{const e=me.search.search({text:ue,matchCase:!se});ce(e.length?1:0),ne(e.length),ie(!se)}),[se,ue]),Se=g.useCallback((()=>{o.goToNextSearchMatch(me),ce(le+1>ae?1:le+1)}),[le,ae]),xe=g.useCallback((()=>{o.goToPreviousSearchMatch(me),ce(le-1<1?ae:le-1)}),[le,ae]),Pe=g.useCallback((()=>{me.search.destroy(),ce(0),ne(0),ie(!1),de(""),re(!1)}),[]),Ie=g.useCallback((e=>{"Enter"===e.key?(e.preventDefault(),o.goToNextSearchMatch(me),ce(le+1>ae?1:le+1)):"Escape"===e.key&&Pe()}),[le,ae]),ze=g.useCallback((t=>{if(U.current){const r=t.skip;o.scrollToPage(U.current,r);const a={page:r+1,target:ge.current,syntheticEvent:t.syntheticEvent};e.onPageChange&&e.onPageChange.call(void 0,a)}Y(t.skip)}),[X,e.onPageChange]),Ne=g.useCallback((t=>{if(fe.current){const r=o.currentPage(fe.current);if(r!==X){Y(r);const o={page:r+1,target:ge.current,syntheticEvent:t};e.onPageChange&&e.onPageChange.call(void 0,o)}}}),[X,e.onPageChange]),Le=g.useCallback((o=>{const t=Math.min(me.currentZoom+j,q);if(t!==me.currentZoom&&me.document&&(W(t),e.onZoom)){const r={zoom:t,target:ge.current,syntheticEvent:o};e.onZoom.call(void 0,r)}}),[me.currentZoom,me.document,j,q,e.onZoom]),Ze=g.useCallback((o=>{const t=Math.max(me.currentZoom-j,B);if(t!==me.currentZoom&&me.document&&(W(t),e.onZoom)){const r={zoom:t,target:ge.current,syntheticEvent:o};e.onZoom.call(void 0,r)}}),[me.currentZoom,me.document,j,B,e.onZoom]),Re=g.useCallback((t=>{const r=null===t.value?{text:"100%",value:1,id:100}:{...t.value};if(void 0===r.value){const e=parseFloat(r.text);"number"!=typeof e||Number.isNaN(e)?r.value=1:r.value=e/100}let a=r?o.calculateZoomLevel(r.value,r.type,me.currentZoom,U.current):1;if(a=Math.round(100*a)/100,me.currentZoom!==a&&me.document&&(W(a),e.onZoom)){const o={zoom:a,target:ge.current,syntheticEvent:t.syntheticEvent};e.onZoom.call(void 0,o)}}),[e.onZoom]),Te=g.useCallback((()=>{me.scroller.disablePanEventsTracking(),oe(!0)}),[]),Oe=g.useCallback((()=>{me.scroller.enablePanEventsTracking(),oe(!1)}),[]),Be=g.useCallback((()=>{o.download({pdf:me.document,error:me.error},e.saveFileName,e.saveOptions,ke)}),[e.url,e.data,e.arrayBuffer,e.saveFileName,e.saveOptions,ke]),De=g.useCallback((()=>{Q(!0);o.print(me.pages,(()=>{Q(!1)}),(e=>{Q(!1),me.error(e)}))}),[]),Me=g.useCallback((e=>{const t=e.newState;t[0]&&t[0].getRawFile&&t[0].getRawFile().arrayBuffer().then((e=>{if(U.current){Q(!0),o.removeChildren(U.current);const t=void 0===me.props.zoom?Z:me.props.zoom;o.loadPDF({arrayBuffer:e,dom:U.current,zoom:t,done:me.done,error:me.error}),W(t)}}))}),[Z]),Fe=g.useCallback((e=>{const o=e.target;if(o instanceof Element&&o.parentNode){const e=o.closest(".k-toolbar"),t=e&&e.querySelector(".k-upload input");t&&t.click()}}),[]),Ke=J&&g.createElement("div",{className:"k-loader-container k-loader-container-md k-loader-top"},g.createElement("div",{className:"k-loader-container-overlay k-overlay-light"}),g.createElement("div",{className:"k-loader-container-inner "},g.createElement(i.Loader,{size:"large"}))),qe=g.createElement(a.ButtonGroup,{className:"k-toolbar-button-group k-button-group-solid"},g.createElement(a.Button,{className:"k-group-start",fillMode:"flat",themeColor:"base",title:A.toLanguageString(k,O[k]),disabled:_<=B||!H,onClick:Ze,icon:"zoom-out",svgIcon:m.zoomOutIcon}),g.createElement(a.Button,{className:"k-group-end",fillMode:"flat",themeColor:"base",title:A.toLanguageString(v,O[v]),disabled:_>=q||!H,onClick:Le,icon:"zoom-in",svgIcon:m.zoomInIcon})),je=g.createElement(s.ComboBox,{className:"k-toolbar-combobox",disabled:!H,data:L.map((e=>({...e,text:e.locationString?A.toLanguageString(e.locationString,O[e.locationString]):e.text}))),dataItemKey:"id",textField:"text",value:H?G:null,allowCustom:!0,onChange:Re,placeholder:A.toLanguageString(b,O[b])}),Ae={pager:g.createElement(l.Pager,{disabled:!H,previousNext:!0,type:"input",skip:X,take:1,total:me.pages?me.pages.length:0,info:!1,onPageChange:ze}),spacer:g.createElement(a.ToolbarSpacer,null),zoomInOut:qe,zoom:je,selection:g.createElement(a.ButtonGroup,{className:"k-toolbar-button-group k-button-group-solid"},g.createElement(a.Button,{className:"k-group-start",fillMode:"flat",themeColor:"base",title:A.toLanguageString(h,O[h]),icon:"pointer",svgIcon:m.pointerIcon,disabled:!H,togglable:!0,selected:ee&&H,onClick:Te}),g.createElement(a.Button,{className:"k-group-end",fillMode:"flat",themeColor:"base",title:A.toLanguageString(y,O[y]),icon:"hand",svgIcon:m.handIcon,disabled:!H,togglable:!0,selected:!ee&&H,onClick:Oe})),search:g.createElement(a.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:A.toLanguageString(C,O[C]),icon:"search",svgIcon:m.searchIcon,disabled:!H,onClick:Ce}),open:g.createElement(g.Fragment,null,g.createElement(a.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:A.toLanguageString(w,O[w]),icon:"folder-open",svgIcon:m.folderOpenIcon,onClick:Fe}),g.createElement("div",{style:{display:"none"}},g.createElement(c.Upload,{restrictions:{allowedExtensions:[".pdf"]},onAdd:Me,autoUpload:!1,defaultFiles:[],multiple:!1,accept:".pdf,.PDF",withCredentials:!1}))),download:g.createElement(a.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:A.toLanguageString(E,O[E]),icon:"download",svgIcon:m.downloadIcon,disabled:!H,onClick:Be}),print:g.createElement(a.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:A.toLanguageString(S,O[S]),icon:"print",svgIcon:m.printIcon,disabled:!H,onClick:De})},Ue=(e.tools||D.tools).map((e=>({...Ae[e],key:"toobar-tool-"+e+(F++,F)}))),Ve=g.createElement(a.Toolbar,{buttons:M},...Ue),We=g.createElement("div",{className:u.classNames("k-canvas k-pdf-viewer-canvas k-pos-relative k-overflow-auto",{"k-enable-text-select":ee,"k-enable-panning":!ee}),onScroll:Ne},te&&g.createElement("div",{className:"k-search-panel k-pos-sticky k-top-center"},g.createElement(n.TextBox,{value:ue,onChange:we,placeholder:A.toLanguageString(C,O[C]),autoFocus:!0,onKeyDown:Ie,suffix:()=>g.createElement(g.Fragment,null,g.createElement(n.InputSeparator,null),g.createElement(n.InputSuffix,null,g.createElement(a.Button,{icon:"convert-lowercase",svgIcon:m.convertLowercaseIcon,title:A.toLanguageString(P,O[P]),fillMode:"flat",togglable:!0,selected:se,onClick:Ee})))}),g.createElement("span",{className:"k-search-matches"},g.createElement("span",null,le)," ",A.toLanguageString(T,O[T]),g.createElement("span",null,ae)),g.createElement(a.Button,{title:A.toLanguageString(I,O[I]),fillMode:"flat",icon:"arrow-up",svgIcon:m.arrowUpIcon,disabled:0===ae,onClick:xe}),g.createElement(a.Button,{title:A.toLanguageString(z,O[z]),fillMode:"flat",icon:"arrow-down",svgIcon:m.arrowDownIcon,disabled:0===ae,onClick:Se}),g.createElement(a.Button,{title:A.toLanguageString(x,O[x]),fillMode:"flat",icon:"x",svgIcon:m.xIcon,onClick:Pe})),g.createElement("div",{ref:U,className:"k-pdf-viewer-pages"}));return g.createElement("div",{className:"k-pdf-viewer",style:e.style,ref:fe},e.onRenderLoader?e.onRenderLoader.call(void 0,Ke||null):Ke,e.onRenderToolbar?e.onRenderToolbar.call(void 0,Ve):Ve,e.onRenderContent?e.onRenderContent.call(void 0,We):We,r&&g.createElement(u.WatermarkOverlay,{message:p}))}));q.displayName="KendoReactPDFViewer",q.propTypes={url:r.string,data:r.string,arrayBuffer:r.any,typedArray:r.any,style:r.object,saveFileName:r.string,saveOptions:r.object,tools:r.arrayOf(r.oneOf(B).isRequired),zoomLevels:r.arrayOf(r.any),zoom:r.number,defaultZoom:r.number,minZoom:r.number,maxZoom:r.number,zoomRate:r.number,onError:r.func,onLoad:r.func,onDownload:r.func,onRenderToolbar:r.func,onRenderContent:r.func,onRenderLoader:r.func,onZoom:r.func};const j=o.scrollToPage;Object.defineProperty(e,"currentPage",{enumerable:!0,get:function(){return o.currentPage}}),e.PDFViewer=q,e.scrollToPage=j}));
|
|
15
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@progress/kendo-pdfviewer-common"),require("react"),require("prop-types"),require("@progress/kendo-react-buttons"),require("@progress/kendo-react-inputs"),require("@progress/kendo-react-data-tools"),require("@progress/kendo-react-upload"),require("@progress/kendo-react-dropdowns"),require("@progress/kendo-react-indicators"),require("@progress/kendo-react-common"),require("@progress/kendo-react-intl"),require("@progress/kendo-svg-icons"),require("pdfjs-dist/build/pdf.worker.min.mjs")):"function"==typeof define&&define.amd?define(["exports","@progress/kendo-pdfviewer-common","react","prop-types","@progress/kendo-react-buttons","@progress/kendo-react-inputs","@progress/kendo-react-data-tools","@progress/kendo-react-upload","@progress/kendo-react-dropdowns","@progress/kendo-react-indicators","@progress/kendo-react-common","@progress/kendo-react-intl","@progress/kendo-svg-icons","pdfjs-dist/build/pdf.worker.min.mjs"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).KendoReactPdfViewer={},e.KendoPdfviewerCommon,e.React,e.PropTypes,e.KendoReactButtons,e.KendoReactInputs,e.KendoReactDataTools,e.KendoReactUpload,e.KendoReactDropdowns,e.KendoReactIndicators,e.KendoReactCommon,e.KendoReactIntl,e.KendoSvgIcons)}(this,function(e,o,t,r,a,n,l,c,s,i,u,d,m){"use strict";function p(e){var o=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(o,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}}),o.default=e,Object.freeze(o)}var g=p(t);const f=Object.freeze({name:"@progress/kendo-react-pdf-viewer",productName:"KendoReact",productCode:"KENDOUIREACT",productCodes:["KENDOUIREACT"],publishDate:1673300081,version:"13.4.0-develop.2",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/my-license/?utm_medium=product&utm_source=kendoreact&utm_campaign=kendo-ui-react-purchase-license-keys-warning"}),v="pdfviewer.zoomIn",k="pdfviewer.zoomOut",b="pdfviewer.zoomLevel",h="pdfviewer.enableSelection",y="pdfviewer.enablePanning",C="pdfviewer.search",w="pdfviewer.open",E="pdfviewer.download",S="pdfviewer.print",x="pdfviewer.close",P="pdfviewer.matchCase",I="pdfviewer.prevMatch",z="pdfviewer.nextMatch",N="pdfviewer.actualWidth",L="pdfviewer.fitToWidth",Z="pdfviewer.fitToPage",R="pdfviewer.popupBlocked",T="pdfviewer.searchOf",O={[v]:"Zoom in",[k]:"Zoom out",[b]:"Choose zoom level",[h]:"Enable selection",[y]:"Enable panning",[C]:"Search",[w]:"Open",[E]:"Download",[T]:"of",[S]:"Print",[x]:"Close",[P]:"Match case",[I]:"Previous match",[z]:"Next match",[N]:"Actual width",[L]:"Fit to width",[Z]:"Fit to page",[R]:"Popup is blocked."},B=["pager","spacer","zoomInOut","zoom","selection","spacer","search","open","download","print"],D={minZoom:.5,maxZoom:4,tools:[...B],zoomRate:.25,zoomLevels:[{id:1,priority:1,value:1,text:"Actual width",type:"ActualWidth",locationString:N},{id:2,priority:2,value:1,text:"Fit to width",type:"FitToWidth",locationString:L},{id:3,priority:3,value:1,text:"Fit to page",type:"FitToPage",locationString:Z},{id:4,priority:4,value:.5,text:"50%",type:""},{id:5,priority:5,value:.75,text:"75%",type:""},{id:6,priority:100,value:1,text:"100%",type:""},{id:7,priority:7,value:1.25,text:"125%",type:""},{id:8,priority:8,value:1.5,text:"150%",type:""},{id:9,priority:9,value:2,text:"200%",type:""},{id:10,priority:10,value:3,text:"300%",type:""},{id:11,priority:11,value:4,text:"400%",type:""}],defaultZoom:o.DEFAULT_ZOOM_LEVEL},M=[".k-toolbar > button",".k-toolbar .k-combobox > input",".k-toolbar .k-button-group > button",".k-toolbar .k-pager > a",".k-toolbar .k-pager input"];let F=0;const K=(e,o)=>e.priority>o.priority?-1:e.priority<o.priority?1:0,q=g.forwardRef((e,t)=>{const r=!u.validatePackage(f,{component:"PDFViewer"}),p=u.getLicenseMessage(f),{zoom:N,zoomLevels:L=D.zoomLevels,defaultZoom:Z=D.defaultZoom,minZoom:B=D.minZoom,maxZoom:q=D.maxZoom,zoomRate:j=D.zoomRate}=e,A=d.useLocalization(),U=g.useRef(null),[V,W]=g.useState(Z),_=void 0!==N?N:V,G=L.slice().sort(K).find(e=>e.value===_)||{text:100*_+"%",value:_,id:_,locationString:""};G.locationString&&(G.text=A.toLanguageString(G.locationString,O[G.locationString]));const[H,$]=g.useState(!1),[J,Q]=g.useState(!0),[X,Y]=g.useState(0),[ee,oe]=g.useState(!0),[te,re]=g.useState(!1),[ae,ne]=g.useState(0),[le,ce]=g.useState(0),[se,ie]=g.useState(!1),[ue,de]=g.useState(""),me=g.useMemo(()=>({}),[]);me.currentZoom=_,me.props=e;const pe=g.useCallback(e=>{U.current&&U.current.style.setProperty("--scale-factor",String(e))},[]),ge=g.useRef(null),fe=g.useRef(null);g.useImperativeHandle(ge,()=>({get element(){return fe.current},props:e,get pages(){return me.pages},get document(){return me.document}}),[]),g.useImperativeHandle(t,()=>ge.current);const ve=g.useCallback(()=>{if(me.props.onLoad){const e={target:ge.current};me.props.onLoad.call(void 0,e)}},[]),ke=g.useCallback((o,t,r)=>{if(e.onDownload){const a={target:ge.current,blob:o,fileName:t,saveOptions:r};return!1===e.onDownload.call(void 0,a)}return!1},[e.onDownload]),be=g.useCallback(()=>{var e;me.scroller&&me.scroller.destroy(),me.scroller=new o.Scroller(null==(e=U.current)?void 0:e.parentNode,{filter:".k-page",events:{}}),me.scroller.disablePanEventsTracking()},[]),he=g.useCallback(e=>{const t=Array.from(e.querySelectorAll(".k-text-layer"));me.search=new o.SearchService({textContainers:t||[],highlightClass:"k-search-highlight",highlightMarkClass:"k-search-highlight-mark",charClass:"k-text-char"})},[]);me.done=g.useCallback(({pdfPages:e,pdfDoc:t,zoom:r})=>{me.document=t,me.pages=e,me.zoom=r,be(),Q(!1),$(!0),ve(),U.current&&o.scrollToPage(U.current,0)},[]),me.error=g.useCallback(o=>{if(me.document=null,me.pages=[],Q(!1),$(!1),e.onError){const t="string"==typeof o?{message:o}:o,r={error:null!=t?t:A.toLanguageString(R,O[R]),target:ge.current};e.onError.call(void 0,r)}},[e.onError]),g.useEffect(()=>{U.current&&(e.url||e.data||e.arrayBuffer?(Q(!0),o.removeChildren(U.current),o.loadPDF({url:e.url,data:e.data,arrayBuffer:e.arrayBuffer,dom:U.current,zoom:me.currentZoom,done:me.done,error:me.error}),pe(me.currentZoom)):(me.document=null,me.pages=[],$(!1),Q(!1),o.removeChildren(U.current)))},[e.url,e.data,e.arrayBuffer]);const ye=g.useCallback((e,t,r)=>{U.current&&fe.current&&(Q(!0),o.removeChildren(U.current),o.reloadDocument({pdfDoc:e,zoom:t,dom:U.current,done:e=>{me.pages=e,me.zoom=t,Q(!1),U.current&&r>0&&o.scrollToPage(U.current,r)},error:me.error}))},[me]);g.useEffect(()=>{pe(_),U.current&&me.document&&_!==me.zoom&&ye(me.document,_,X)},[_,me.document,me.zoom,ye,pe,X]),g.useEffect(()=>()=>{me.scroller&&me.scroller.destroy(),me.search&&me.search.destroy(),me.document=null,me.pages=[]},[]);const Ce=g.useCallback(()=>{re(!0),he(U.current)},[]),we=g.useCallback(e=>{const o=e.value,t=me.search.search({text:o,matchCase:se});ce(t.length?1:0),ne(t.length),de(o)},[se]),Ee=g.useCallback(()=>{const e=me.search.search({text:ue,matchCase:!se});ce(e.length?1:0),ne(e.length),ie(!se)},[se,ue]),Se=g.useCallback(()=>{o.goToNextSearchMatch(me),ce(le+1>ae?1:le+1)},[le,ae]),xe=g.useCallback(()=>{o.goToPreviousSearchMatch(me),ce(le-1<1?ae:le-1)},[le,ae]),Pe=g.useCallback(()=>{me.search.destroy(),ce(0),ne(0),ie(!1),de(""),re(!1)},[]),Ie=g.useCallback(e=>{"Enter"===e.key?(e.preventDefault(),o.goToNextSearchMatch(me),ce(le+1>ae?1:le+1)):"Escape"===e.key&&Pe()},[le,ae]),ze=g.useCallback(t=>{if(U.current){const r=t.skip;o.scrollToPage(U.current,r);const a={page:r+1,target:ge.current,syntheticEvent:t.syntheticEvent};e.onPageChange&&e.onPageChange.call(void 0,a)}Y(t.skip)},[X,e.onPageChange]),Ne=g.useCallback(t=>{if(fe.current){const r=o.currentPage(fe.current);if(r!==X){Y(r);const o={page:r+1,target:ge.current,syntheticEvent:t};e.onPageChange&&e.onPageChange.call(void 0,o)}}},[X,e.onPageChange]),Le=g.useCallback(o=>{const t=Math.min(me.currentZoom+j,q);if(t!==me.currentZoom&&me.document&&(W(t),e.onZoom)){const r={zoom:t,target:ge.current,syntheticEvent:o};e.onZoom.call(void 0,r)}},[me.currentZoom,me.document,j,q,e.onZoom]),Ze=g.useCallback(o=>{const t=Math.max(me.currentZoom-j,B);if(t!==me.currentZoom&&me.document&&(W(t),e.onZoom)){const r={zoom:t,target:ge.current,syntheticEvent:o};e.onZoom.call(void 0,r)}},[me.currentZoom,me.document,j,B,e.onZoom]),Re=g.useCallback(t=>{const r=null===t.value?{text:"100%",value:1}:{...t.value};if(void 0===r.value){const e=parseFloat(r.text);"number"!=typeof e||Number.isNaN(e)?r.value=1:r.value=e/100}let a=r?o.calculateZoomLevel(r.value,r.type,me.currentZoom,U.current):1;if(a=Math.round(100*a)/100,me.currentZoom!==a&&me.document&&(W(a),e.onZoom)){const o={zoom:a,target:ge.current,syntheticEvent:t.syntheticEvent};e.onZoom.call(void 0,o)}},[e.onZoom]),Te=g.useCallback(()=>{me.scroller.disablePanEventsTracking(),oe(!0)},[]),Oe=g.useCallback(()=>{me.scroller.enablePanEventsTracking(),oe(!1)},[]),Be=g.useCallback(()=>{o.download({pdf:me.document,error:me.error},e.saveFileName,e.saveOptions,ke)},[e.url,e.data,e.arrayBuffer,e.saveFileName,e.saveOptions,ke]),De=g.useCallback(()=>{Q(!0);o.print(me.pages,()=>{Q(!1)},e=>{Q(!1),me.error(e)})},[]),Me=g.useCallback(e=>{const t=e.newState;t[0]&&t[0].getRawFile&&t[0].getRawFile().arrayBuffer().then(e=>{if(U.current){Q(!0),o.removeChildren(U.current);const t=void 0===me.props.zoom?Z:me.props.zoom;o.loadPDF({arrayBuffer:e,dom:U.current,zoom:t,done:me.done,error:me.error}),W(t)}})},[Z]),Fe=g.useCallback(e=>{const o=e.target;if(o instanceof Element&&o.parentNode){const e=o.closest(".k-toolbar"),t=e&&e.querySelector(".k-upload input");t&&t.click()}},[]),Ke=J&&g.createElement("div",{className:"k-loader-container k-loader-container-md k-loader-top"},g.createElement("div",{className:"k-loader-container-overlay k-overlay-light"}),g.createElement("div",{className:"k-loader-container-inner "},g.createElement(i.Loader,{size:"large"}))),qe=g.createElement(a.ButtonGroup,{className:"k-toolbar-button-group k-button-group-solid"},g.createElement(a.Button,{className:"k-group-start",fillMode:"flat",themeColor:"base",title:A.toLanguageString(k,O[k]),disabled:_<=B||!H,onClick:Ze,icon:"zoom-out",svgIcon:m.zoomOutIcon}),g.createElement(a.Button,{className:"k-group-end",fillMode:"flat",themeColor:"base",title:A.toLanguageString(v,O[v]),disabled:_>=q||!H,onClick:Le,icon:"zoom-in",svgIcon:m.zoomInIcon})),je=g.createElement(s.ComboBox,{className:"k-toolbar-combobox",disabled:!H,data:L.map(e=>({...e,text:e.locationString?A.toLanguageString(e.locationString,O[e.locationString]):e.text})),dataItemKey:"id",textField:"text",value:H?G:null,allowCustom:!0,onChange:Re,placeholder:A.toLanguageString(b,O[b])}),Ae={pager:g.createElement(l.Pager,{disabled:!H,previousNext:!0,type:"input",skip:X,take:1,total:me.pages?me.pages.length:0,info:!1,onPageChange:ze}),spacer:g.createElement(a.ToolbarSpacer,null),zoomInOut:qe,zoom:je,selection:g.createElement(a.ButtonGroup,{className:"k-toolbar-button-group k-button-group-solid"},g.createElement(a.Button,{className:"k-group-start",fillMode:"flat",themeColor:"base",title:A.toLanguageString(h,O[h]),icon:"pointer",svgIcon:m.pointerIcon,disabled:!H,togglable:!0,selected:ee&&H,onClick:Te}),g.createElement(a.Button,{className:"k-group-end",fillMode:"flat",themeColor:"base",title:A.toLanguageString(y,O[y]),icon:"hand",svgIcon:m.handIcon,disabled:!H,togglable:!0,selected:!ee&&H,onClick:Oe})),search:g.createElement(a.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:A.toLanguageString(C,O[C]),icon:"search",svgIcon:m.searchIcon,disabled:!H,onClick:Ce}),open:g.createElement(g.Fragment,null,g.createElement(a.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:A.toLanguageString(w,O[w]),icon:"folder-open",svgIcon:m.folderOpenIcon,onClick:Fe}),g.createElement("div",{style:{display:"none"}},g.createElement(c.Upload,{restrictions:{allowedExtensions:[".pdf"]},onAdd:Me,autoUpload:!1,defaultFiles:[],multiple:!1,accept:".pdf,.PDF",withCredentials:!1}))),download:g.createElement(a.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:A.toLanguageString(E,O[E]),icon:"download",svgIcon:m.downloadIcon,disabled:!H,onClick:Be}),print:g.createElement(a.Button,{className:"k-toolbar-button",fillMode:"flat",themeColor:"base",title:A.toLanguageString(S,O[S]),icon:"print",svgIcon:m.printIcon,disabled:!H,onClick:De})},Ue=(e.tools||D.tools).map(e=>({...Ae[e],key:"toobar-tool-"+e+(F++,F)})),Ve=g.createElement(a.Toolbar,{buttons:M},...Ue),We=g.createElement("div",{className:u.classNames("k-canvas k-pdf-viewer-canvas k-pos-relative k-overflow-auto",{"k-enable-text-select":ee,"k-enable-panning":!ee}),onScroll:Ne},te&&g.createElement("div",{className:"k-search-panel k-pos-sticky k-top-center"},g.createElement(n.TextBox,{value:ue,onChange:we,placeholder:A.toLanguageString(C,O[C]),autoFocus:!0,onKeyDown:Ie,suffix:()=>g.createElement(g.Fragment,null,g.createElement(n.InputSeparator,null),g.createElement(n.InputSuffix,null,g.createElement(a.Button,{icon:"convert-lowercase",svgIcon:m.convertLowercaseIcon,title:A.toLanguageString(P,O[P]),fillMode:"flat",togglable:!0,selected:se,onClick:Ee})))}),g.createElement("span",{className:"k-search-matches"},g.createElement("span",null,le)," ",A.toLanguageString(T,O[T]),g.createElement("span",null,ae)),g.createElement(a.Button,{title:A.toLanguageString(I,O[I]),fillMode:"flat",icon:"arrow-up",svgIcon:m.arrowUpIcon,disabled:0===ae,onClick:xe}),g.createElement(a.Button,{title:A.toLanguageString(z,O[z]),fillMode:"flat",icon:"arrow-down",svgIcon:m.arrowDownIcon,disabled:0===ae,onClick:Se}),g.createElement(a.Button,{title:A.toLanguageString(x,O[x]),fillMode:"flat",icon:"x",svgIcon:m.xIcon,onClick:Pe})),g.createElement("div",{ref:U,className:"k-pdf-viewer-pages"}));return g.createElement("div",{className:"k-pdf-viewer",style:e.style,ref:fe},e.onRenderLoader?e.onRenderLoader.call(void 0,Ke||null):Ke,e.onRenderToolbar?e.onRenderToolbar.call(void 0,Ve):Ve,e.onRenderContent?e.onRenderContent.call(void 0,We):We,r&&g.createElement(u.WatermarkOverlay,{message:p}))});q.displayName="KendoReactPDFViewer",q.propTypes={url:r.string,data:r.string,arrayBuffer:r.any,typedArray:r.any,style:r.object,saveFileName:r.string,saveOptions:r.object,tools:r.arrayOf(r.oneOf(B).isRequired),zoomLevels:r.arrayOf(r.any),zoom:r.number,defaultZoom:r.number,minZoom:r.number,maxZoom:r.number,zoomRate:r.number,onError:r.func,onLoad:r.func,onDownload:r.func,onRenderToolbar:r.func,onRenderContent:r.func,onRenderLoader:r.func,onZoom:r.func};const j=o.scrollToPage;Object.defineProperty(e,"currentPage",{enumerable:!0,get:function(){return o.currentPage}}),e.PDFViewer=q,e.scrollToPage=j});
|