@progress/kendo-react-pdf-viewer 7.2.4-develop.2 → 7.2.4-develop.4
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.js +8 -0
- package/PDFViewer.mjs +498 -0
- package/dist/cdn/js/kendo-react-pdf-viewer.js +8 -5
- package/index.d.mts +257 -5
- package/index.d.ts +255 -31
- package/index.js +8 -5
- package/index.mjs +14 -519
- package/messages.js +8 -0
- package/messages.mjs +47 -0
- package/package-metadata.js +8 -0
- package/package-metadata.mjs +19 -0
- package/package.json +9 -9
- package/PDFViewer.d.ts +0 -211
- package/messages.d.ts +0 -94
- package/package-metadata.d.ts +0 -9
package/PDFViewer.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Fe=require("react"),c=require("prop-types"),d=require("@progress/kendo-react-buttons"),ee=require("@progress/kendo-react-inputs"),qe=require("@progress/kendo-react-data-tools"),je=require("@progress/kendo-react-upload"),Ae=require("@progress/kendo-react-dropdowns"),Ve=require("@progress/kendo-react-indicators"),R=require("@progress/kendo-react-common"),Ue=require("@progress/kendo-react-intl"),g=require("@progress/kendo-svg-icons");require("pdfjs-dist/build/pdf.worker.entry.js");const te=require("./package-metadata.js"),i=require("@progress/kendo-pdfviewer-common"),a=require("./messages.js");function We(n){const p=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const S in n)if(S!=="default"){const w=Object.getOwnPropertyDescriptor(n,S);Object.defineProperty(p,S,w.get?w:{enumerable:!0,get:()=>n[S]})}}return p.default=n,Object.freeze(p)}const e=We(Fe),ne=["pager","spacer","zoomInOut","zoom","selection","spacer","search","open","download","print"],C={minZoom:.5,maxZoom:4,tools:[...ne],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},Ke=[".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 oe=0;function _e(){return oe++,oe}const He=(n,p)=>n.priority>p.priority?-1:n.priority<p.priority?1:0,N=e.forwardRef((n,p)=>{R.validatePackage(te.packageMetadata);const S=R.shouldShowValidationUI(te.packageMetadata),{zoom:w,zoomLevels:A=C.zoomLevels,defaultZoom:M=C.defaultZoom,minZoom:B=C.minZoom,maxZoom:O=C.maxZoom,zoomRate:z=C.zoomRate}=n,u=Ue.useLocalization(),s=e.useRef(null),[ae,L]=e.useState(M),f=w!==void 0?w:ae,Z=A.slice().sort(He).find(o=>o.value===f)||{text:f*100+"%",value:f,id:f,locationString:""};Z.locationString&&(Z.text=u.toLanguageString(Z.locationString,a.messages[Z.locationString]));const[h,D]=e.useState(!1),[re,b]=e.useState(!0),[P,V]=e.useState(0),[I,U]=e.useState(!1),[le,W]=e.useState(!1),[y,F]=e.useState(0),[v,E]=e.useState(0),[x,K]=e.useState(!1),[q,_]=e.useState(""),t=e.useMemo(()=>({}),[]);t.currentZoom=f,t.props=n;const H=e.useCallback(o=>{s.current&&s.current.style.setProperty("--scale-factor",String(o))},[]),k=e.useRef(null),T=e.useRef(null);e.useImperativeHandle(k,()=>({get element(){return T.current},props:n,get pages(){return t.pages},get document(){return t.document}}),[]),e.useImperativeHandle(p,()=>k.current);const ce=e.useCallback(()=>{if(t.props.onLoad){const o={target:k.current};t.props.onLoad.call(void 0,o)}},[]),G=e.useCallback((o,r,l)=>{if(n.onDownload){const m={target:k.current,blob:o,fileName:r,saveOptions:l};return n.onDownload.call(void 0,m)===!1}return!1},[n.onDownload]),se=e.useCallback(()=>{var o;t.scroller&&t.scroller.destroy(),t.scroller=new i.Scroller((o=s.current)==null?void 0:o.parentNode,{filter:".k-page",events:{}}),t.scroller.enablePanEventsTracking()},[]),ie=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,se(),b(!1),D(!0),ce(),s.current&&i.scrollToPage(s.current,0)},[]),t.error=e.useCallback(o=>{if(t.document=null,t.pages=[],b(!1),D(!1),n.onError){const r={error:typeof o=="string"?{message:o}:o,target:k.current};n.onError.call(void 0,r)}},[n.onError]),e.useEffect(()=>{s.current&&(n.url||n.data||n.arrayBuffer?(b(!0),i.removeChildren(s.current),i.loadPDF({url:n.url,data:n.data,arrayBuffer:n.arrayBuffer,dom:s.current,zoom:t.currentZoom,done:t.done,error:t.error}),H(t.currentZoom)):(t.document=null,t.pages=[],D(!1),b(!1),i.removeChildren(s.current)))},[n.url,n.data,n.arrayBuffer]);const J=e.useCallback((o,r)=>{s.current&&(b(!0),i.removeChildren(s.current),i.reloadDocument({pdfDoc:o,zoom:r,dom:s.current,done:l=>{t.pages=l,t.zoom=r,b(!1)},error:t.error}))},[]);e.useEffect(()=>{H(f),s.current&&t.document&&f!==t.zoom&&J(t.document,f)},[f,J]),e.useEffect(()=>()=>{t.scroller&&t.scroller.destroy(),t.search&&t.search.destroy(),t.document=null,t.pages=[]},[]);const ue=e.useCallback(()=>{W(!0),ie(s.current)},[]),de=e.useCallback(o=>{const r=o.value,l=t.search.search({text:r,matchCase:x});E(l.length?1:0),F(l.length),_(r)},[x]),me=e.useCallback(()=>{const o=t.search.search({text:q,matchCase:!x});E(o.length?1:0),F(o.length),K(!x)},[x,q]),ge=e.useCallback(()=>{i.goToNextSearchMatch(t),E(v+1>y?1:v+1)},[v,y]),fe=e.useCallback(()=>{i.goToPreviousSearchMatch(t),E(v-1<1?y:v-1)},[v,y]),Q=e.useCallback(()=>{t.search.destroy(),E(0),F(0),K(!1),_(""),W(!1)},[]),he=e.useCallback(o=>{o.key==="Enter"?(o.preventDefault(),i.goToNextSearchMatch(t),E(v+1>y?1:v+1)):o.key==="Escape"&&Q()},[v,y]),ve=e.useCallback(o=>{if(s.current){const r=o.skip;i.scrollToPage(s.current,r);const l={page:r+1,target:k.current,syntheticEvent:o.syntheticEvent};n.onPageChange&&n.onPageChange.call(void 0,l)}V(o.skip)},[P,n.onPageChange]),ke=e.useCallback(o=>{if(T.current){const r=i.currentPage(T.current);if(r!==P){V(r);const l={page:r+1,target:k.current,syntheticEvent:o};n.onPageChange&&n.onPageChange.call(void 0,l)}}},[P,n.onPageChange]),be=e.useCallback(o=>{const r=Math.min(t.currentZoom+z,O);if(r!==t.currentZoom&&t.document&&(L(r),n.onZoom)){const l={zoom:r,target:k.current,syntheticEvent:o};n.onZoom.call(void 0,l)}},[z,O,n.onZoom]),ye=e.useCallback(o=>{const r=Math.max(t.currentZoom-z,B);if(r!==t.currentZoom&&t.document&&(L(r),n.onZoom)){const l={zoom:r,target:k.current,syntheticEvent:o};n.onZoom.call(void 0,l)}},[z,B,n.onZoom]),pe=e.useCallback(o=>{const r=o.value===null?{text:"100%",value:1,id:100}:{...o.value};if(r.value===void 0){const m=parseFloat(r.text);typeof m=="number"&&!Number.isNaN(m)?r.value=m/100:r.value=1}let l=r?i.calculateZoomLevel(r.value,r.type,t.currentZoom,s.current):1;if(l=Math.round(l*100)/100,t.currentZoom!==l&&t.document&&(L(l),n.onZoom)){const m={zoom:l,target:k.current,syntheticEvent:o.syntheticEvent};n.onZoom.call(void 0,m)}},[n.onZoom]),Ce=e.useCallback(()=>{t.scroller.disablePanEventsTracking(),U(!0)},[]),Se=e.useCallback(()=>{t.scroller.enablePanEventsTracking(),U(!1)},[]),Ee=e.useCallback(()=>{i.download({pdf:t.document,error:t.error},n.saveFileName,n.saveOptions,G)},[n.url,n.data,n.arrayBuffer,n.saveFileName,n.saveOptions,G]),xe=e.useCallback(()=>{b(!0);const o=l=>{t.error(typeof(l?l.message||l:null)=="string"?l.message||l:u.toLanguageString(a.popupBlocked,a.messages[a.popupBlocked]))},r=()=>{b(!1)};i.print(t.pages,r,o)},[]),we=e.useCallback(o=>{const r=o.newState;r[0]&&r[0].getRawFile&&r[0].getRawFile().arrayBuffer().then(m=>{if(s.current){b(!0),i.removeChildren(s.current);const j=t.props.zoom===void 0?M:t.props.zoom;i.loadPDF({arrayBuffer:m,dom:s.current,zoom:j,done:t.done,error:t.error}),L(j)}})},[M]),Ze=e.useCallback(o=>{const r=o.target;if(r instanceof Element&&r.parentNode){const l=r.closest(".k-toolbar"),m=l&&l.querySelector(".k-upload input");m&&m.click()}},[]),X=re&&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(Ve.Loader,{size:"large"}))),ze=e.createElement(d.ButtonGroup,null,e.createElement(d.Button,{className:"k-toolbar-button",title:u.toLanguageString(a.zoomOut,a.messages[a.zoomOut]),disabled:f<=B||!h,onClick:ye,icon:"zoom-out",svgIcon:g.zoomOutIcon}),e.createElement(d.Button,{className:"k-toolbar-button",title:u.toLanguageString(a.zoomIn,a.messages[a.zoomIn]),disabled:f>=O||!h,onClick:be,icon:"zoom-in",svgIcon:g.zoomInIcon})),Le=e.createElement(Ae.ComboBox,{disabled:!h,data:A.map(o=>({...o,text:o.locationString?u.toLanguageString(o.locationString,a.messages[o.locationString]):o.text})),dataItemKey:"id",textField:"text",value:h?Z:null,allowCustom:!0,onChange:pe,placeholder:u.toLanguageString(a.zoomLevel,a.messages[a.zoomLevel])}),Pe=e.createElement(qe.Pager,{previousNext:!0,type:"input",skip:P,take:1,total:t.pages?t.pages.length:0,info:!1,onPageChange:ve}),Ie=e.createElement(d.ToolbarSpacer,null),Te=e.createElement(d.ButtonGroup,null,e.createElement(d.Button,{className:"k-toolbar-button",title:u.toLanguageString(a.enableSelection,a.messages[a.enableSelection]),icon:"pointer",svgIcon:g.pointerIcon,disabled:!h,togglable:!0,selected:I&&h,onClick:Ce}),e.createElement(d.Button,{className:"k-toolbar-button",title:u.toLanguageString(a.enablePanning,a.messages[a.enablePanning]),icon:"hand",svgIcon:g.handIcon,disabled:!h,togglable:!0,selected:!I&&h,onClick:Se})),Re=e.createElement(d.Button,{className:"k-toolbar-button",title:u.toLanguageString(a.search,a.messages[a.search]),icon:"search",svgIcon:g.searchIcon,disabled:!h,onClick:ue}),Ne=e.createElement(e.Fragment,null,e.createElement(d.Button,{className:"k-toolbar-button",title:u.toLanguageString(a.open,a.messages[a.open]),icon:"folder-open",svgIcon:g.folderOpenIcon,onClick:Ze}),e.createElement("div",{style:{display:"none"}},e.createElement(je.Upload,{restrictions:{allowedExtensions:[".pdf"]},onAdd:we,autoUpload:!1,defaultFiles:[],multiple:!1,accept:".pdf,.PDF",withCredentials:!1}))),Me=e.createElement(d.Button,{className:"k-toolbar-button",title:u.toLanguageString(a.download,a.messages[a.download]),icon:"download",svgIcon:g.downloadIcon,disabled:!h,onClick:Ee}),Be=e.createElement(d.Button,{className:"k-toolbar-button",title:u.toLanguageString(a.print,a.messages[a.print]),icon:"print",svgIcon:g.printIcon,disabled:!h,onClick:xe}),Oe={pager:Pe,spacer:Ie,zoomInOut:ze,zoom:Le,selection:Te,search:Re,open:Ne,download:Me,print:Be},De=(n.tools||C.tools).map(o=>({...Oe[o],key:"toobar-tool-"+o+_e()})),Y=e.createElement(d.Toolbar,{buttons:Ke},...De),$=e.createElement("div",{className:R.classNames("k-canvas k-pdf-viewer-canvas k-pos-relative k-overflow-auto",{"k-enable-text-select":I,"k-enable-panning":!I}),onScroll:ke},le&&e.createElement("div",{className:"k-search-panel k-pos-sticky k-top-center"},e.createElement(ee.TextBox,{value:q,onChange:de,placeholder:u.toLanguageString(a.search,a.messages[a.search]),autoFocus:!0,onKeyDown:he,suffix:()=>e.createElement(ee.InputSuffix,null,e.createElement(d.Button,{icon:"convert-lowercase",svgIcon:g.convertLowercaseIcon,title:u.toLanguageString(a.matchCase,a.messages[a.matchCase]),fillMode:"flat",togglable:!0,selected:x,onClick:me}))}),e.createElement("span",{className:"k-search-matches"},e.createElement("span",null,v)," of ",e.createElement("span",null,y)),e.createElement(d.Button,{title:u.toLanguageString(a.prevMatch,a.messages[a.prevMatch]),fillMode:"flat",icon:"arrow-up",svgIcon:g.arrowUpIcon,disabled:y===0,onClick:fe}),e.createElement(d.Button,{title:u.toLanguageString(a.nextMatch,a.messages[a.nextMatch]),fillMode:"flat",icon:"arrow-down",svgIcon:g.arrowDownIcon,disabled:y===0,onClick:ge}),e.createElement(d.Button,{title:u.toLanguageString(a.close,a.messages[a.close]),fillMode:"flat",icon:"x",svgIcon:g.xIcon,onClick:Q})),e.createElement("div",{ref:s,className:"k-pdf-viewer-pages"}));return e.createElement("div",{className:"k-pdf-viewer",style:n.style,ref:T},n.onRenderLoader?n.onRenderLoader.call(void 0,X||null):X,n.onRenderToolbar?n.onRenderToolbar.call(void 0,Y):Y,n.onRenderContent?n.onRenderContent.call(void 0,$):$,S&&e.createElement(R.WatermarkOverlay,null))});N.displayName="KendoReactPDFViewer";N.propTypes={url:c.string,data:c.string,arrayBuffer:c.any,typedArray:c.any,style:c.object,saveFileName:c.string,saveOptions:c.object,tools:c.arrayOf(c.oneOf(ne).isRequired),zoomLevels:c.arrayOf(c.any),zoom:c.number,defaultZoom:c.number,minZoom:c.number,maxZoom:c.number,zoomRate:c.number,onError:c.func,onLoad:c.func,onDownload:c.func,onRenderToolbar:c.func,onRenderContent:c.func,onRenderLoader:c.func,onZoom:c.func};N.defaultProps=C;exports.PDFViewer=N;
|
package/PDFViewer.mjs
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";
|
|
9
|
+
import * as e from "react";
|
|
10
|
+
import l from "prop-types";
|
|
11
|
+
import { ButtonGroup as X, Button as m, Toolbar as Ye, ToolbarSpacer as et } from "@progress/kendo-react-buttons";
|
|
12
|
+
import { TextBox as tt, InputSuffix as ot } from "@progress/kendo-react-inputs";
|
|
13
|
+
import { Pager as nt } from "@progress/kendo-react-data-tools";
|
|
14
|
+
import { Upload as at } from "@progress/kendo-react-upload";
|
|
15
|
+
import { ComboBox as rt } from "@progress/kendo-react-dropdowns";
|
|
16
|
+
import { Loader as lt } from "@progress/kendo-react-indicators";
|
|
17
|
+
import { validatePackage as ct, shouldShowValidationUI as st, classNames as it, WatermarkOverlay as ut } from "@progress/kendo-react-common";
|
|
18
|
+
import { useLocalization as mt } from "@progress/kendo-react-intl";
|
|
19
|
+
import { zoomOutIcon as dt, zoomInIcon as gt, pointerIcon as ft, handIcon as vt, searchIcon as ht, folderOpenIcon as kt, downloadIcon as bt, printIcon as yt, convertLowercaseIcon as pt, arrowUpIcon as Et, arrowDownIcon as Ct, xIcon as St } from "@progress/kendo-svg-icons";
|
|
20
|
+
import "pdfjs-dist/build/pdf.worker.entry.js";
|
|
21
|
+
import { packageMetadata as Y } from "./package-metadata.mjs";
|
|
22
|
+
import { Scroller as xt, SearchService as wt, scrollToPage as ee, removeChildren as z, loadPDF as te, reloadDocument as Zt, goToNextSearchMatch as oe, goToPreviousSearchMatch as Lt, currentPage as zt, calculateZoomLevel as It, download as Tt, print as Pt, DEFAULT_ZOOM_LEVEL as Nt } from "@progress/kendo-pdfviewer-common";
|
|
23
|
+
import { messages as i, 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, prevMatch as de, nextMatch as ge, close as fe, actualWidth as Mt, fitToWidth as Rt, fitToPage as Ft, popupBlocked as ve } from "./messages.mjs";
|
|
24
|
+
const ke = [
|
|
25
|
+
"pager",
|
|
26
|
+
"spacer",
|
|
27
|
+
"zoomInOut",
|
|
28
|
+
"zoom",
|
|
29
|
+
"selection",
|
|
30
|
+
"spacer",
|
|
31
|
+
"search",
|
|
32
|
+
"open",
|
|
33
|
+
"download",
|
|
34
|
+
"print"
|
|
35
|
+
], b = {
|
|
36
|
+
minZoom: 0.5,
|
|
37
|
+
maxZoom: 4,
|
|
38
|
+
tools: [...ke],
|
|
39
|
+
zoomRate: 0.25,
|
|
40
|
+
zoomLevels: [
|
|
41
|
+
{ id: 1, priority: 1, value: 1, text: "Actual width", type: "ActualWidth", locationString: Mt },
|
|
42
|
+
{ id: 2, priority: 2, value: 1, text: "Fit to width", type: "FitToWidth", locationString: Rt },
|
|
43
|
+
{ id: 3, priority: 3, value: 1, text: "Fit to page", type: "FitToPage", locationString: Ft },
|
|
44
|
+
{ id: 4, priority: 4, value: 0.5, text: "50%", type: "" },
|
|
45
|
+
{ id: 5, priority: 5, value: 0.75, text: "75%", type: "" },
|
|
46
|
+
{ id: 6, priority: 100, value: 1, text: "100%", type: "" },
|
|
47
|
+
{ id: 7, priority: 7, value: 1.25, text: "125%", type: "" },
|
|
48
|
+
{ id: 8, priority: 8, value: 1.5, text: "150%", type: "" },
|
|
49
|
+
{ id: 9, priority: 9, value: 2, text: "200%", type: "" },
|
|
50
|
+
{ id: 10, priority: 10, value: 3, text: "300%", type: "" },
|
|
51
|
+
{ id: 11, priority: 11, value: 4, text: "400%", type: "" }
|
|
52
|
+
],
|
|
53
|
+
defaultZoom: Nt
|
|
54
|
+
}, Dt = [
|
|
55
|
+
".k-toolbar > button",
|
|
56
|
+
".k-toolbar .k-combobox > input",
|
|
57
|
+
".k-toolbar .k-button-group > button",
|
|
58
|
+
".k-toolbar .k-pager > a",
|
|
59
|
+
".k-toolbar .k-pager input"
|
|
60
|
+
];
|
|
61
|
+
let he = 0;
|
|
62
|
+
function Ot() {
|
|
63
|
+
return he++, he;
|
|
64
|
+
}
|
|
65
|
+
const Bt = (n, C) => n.priority > C.priority ? -1 : n.priority < C.priority ? 1 : 0, O = e.forwardRef((n, C) => {
|
|
66
|
+
ct(Y);
|
|
67
|
+
const be = st(Y), {
|
|
68
|
+
zoom: B,
|
|
69
|
+
zoomLevels: A = b.zoomLevels,
|
|
70
|
+
defaultZoom: T = b.defaultZoom,
|
|
71
|
+
minZoom: P = b.minZoom,
|
|
72
|
+
maxZoom: N = b.maxZoom,
|
|
73
|
+
zoomRate: S = b.zoomRate
|
|
74
|
+
} = n, s = mt(), c = e.useRef(null), [ye, x] = e.useState(T), d = B !== void 0 ? B : ye, E = A.slice().sort(Bt).find((o) => o.value === d) || { text: d * 100 + "%", value: d, id: d, locationString: "" };
|
|
75
|
+
E.locationString && (E.text = s.toLanguageString(E.locationString, i[E.locationString]));
|
|
76
|
+
const [g, M] = e.useState(!1), [pe, h] = e.useState(!0), [w, V] = e.useState(0), [Z, W] = e.useState(!1), [Ee, K] = e.useState(!1), [k, R] = e.useState(0), [f, y] = e.useState(0), [p, U] = e.useState(!1), [F, j] = e.useState(""), t = e.useMemo(() => ({}), []);
|
|
77
|
+
t.currentZoom = d, t.props = n;
|
|
78
|
+
const q = e.useCallback((o) => {
|
|
79
|
+
c.current && c.current.style.setProperty("--scale-factor", String(o));
|
|
80
|
+
}, []), v = e.useRef(null), L = e.useRef(null);
|
|
81
|
+
e.useImperativeHandle(v, () => ({
|
|
82
|
+
get element() {
|
|
83
|
+
return L.current;
|
|
84
|
+
},
|
|
85
|
+
props: n,
|
|
86
|
+
get pages() {
|
|
87
|
+
return t.pages;
|
|
88
|
+
},
|
|
89
|
+
get document() {
|
|
90
|
+
return t.document;
|
|
91
|
+
}
|
|
92
|
+
}), []), e.useImperativeHandle(C, () => v.current);
|
|
93
|
+
const Ce = e.useCallback(() => {
|
|
94
|
+
if (t.props.onLoad) {
|
|
95
|
+
const o = { target: v.current };
|
|
96
|
+
t.props.onLoad.call(void 0, o);
|
|
97
|
+
}
|
|
98
|
+
}, []), H = e.useCallback((o, a, r) => {
|
|
99
|
+
if (n.onDownload) {
|
|
100
|
+
const u = {
|
|
101
|
+
target: v.current,
|
|
102
|
+
blob: o,
|
|
103
|
+
fileName: a,
|
|
104
|
+
saveOptions: r
|
|
105
|
+
};
|
|
106
|
+
return n.onDownload.call(void 0, u) === !1;
|
|
107
|
+
}
|
|
108
|
+
return !1;
|
|
109
|
+
}, [n.onDownload]), Se = e.useCallback(() => {
|
|
110
|
+
var o;
|
|
111
|
+
t.scroller && t.scroller.destroy(), t.scroller = new xt((o = c.current) == null ? void 0 : o.parentNode, {
|
|
112
|
+
filter: ".k-page",
|
|
113
|
+
events: {}
|
|
114
|
+
}), t.scroller.enablePanEventsTracking();
|
|
115
|
+
}, []), xe = e.useCallback((o) => {
|
|
116
|
+
const a = Array.from(o.querySelectorAll(".k-text-layer"));
|
|
117
|
+
t.search = new wt({
|
|
118
|
+
textContainers: a || [],
|
|
119
|
+
highlightClass: "k-search-highlight",
|
|
120
|
+
highlightMarkClass: "k-search-highlight-mark",
|
|
121
|
+
charClass: "k-text-char"
|
|
122
|
+
});
|
|
123
|
+
}, []);
|
|
124
|
+
t.done = e.useCallback(({ pdfPages: o, pdfDoc: a, zoom: r }) => {
|
|
125
|
+
t.document = a, t.pages = o, t.zoom = r, Se(), h(!1), M(!0), Ce(), c.current && ee(c.current, 0);
|
|
126
|
+
}, []), t.error = e.useCallback((o) => {
|
|
127
|
+
if (t.document = null, t.pages = [], h(!1), M(!1), n.onError) {
|
|
128
|
+
const a = {
|
|
129
|
+
error: typeof o == "string" ? { message: o } : o,
|
|
130
|
+
target: v.current
|
|
131
|
+
};
|
|
132
|
+
n.onError.call(void 0, a);
|
|
133
|
+
}
|
|
134
|
+
}, [n.onError]), e.useEffect(() => {
|
|
135
|
+
c.current && (n.url || n.data || n.arrayBuffer ? (h(!0), z(c.current), te({
|
|
136
|
+
url: n.url,
|
|
137
|
+
data: n.data,
|
|
138
|
+
arrayBuffer: n.arrayBuffer,
|
|
139
|
+
dom: c.current,
|
|
140
|
+
zoom: t.currentZoom,
|
|
141
|
+
done: t.done,
|
|
142
|
+
error: t.error
|
|
143
|
+
}), q(t.currentZoom)) : (t.document = null, t.pages = [], M(!1), h(!1), z(c.current)));
|
|
144
|
+
}, [n.url, n.data, n.arrayBuffer]);
|
|
145
|
+
const $ = e.useCallback((o, a) => {
|
|
146
|
+
c.current && (h(!0), z(c.current), Zt({
|
|
147
|
+
pdfDoc: o,
|
|
148
|
+
zoom: a,
|
|
149
|
+
dom: c.current,
|
|
150
|
+
done: (r) => {
|
|
151
|
+
t.pages = r, t.zoom = a, h(!1);
|
|
152
|
+
},
|
|
153
|
+
error: t.error
|
|
154
|
+
}));
|
|
155
|
+
}, []);
|
|
156
|
+
e.useEffect(() => {
|
|
157
|
+
q(d), c.current && t.document && d !== t.zoom && $(t.document, d);
|
|
158
|
+
}, [d, $]), e.useEffect(() => () => {
|
|
159
|
+
t.scroller && t.scroller.destroy(), t.search && t.search.destroy(), t.document = null, t.pages = [];
|
|
160
|
+
}, []);
|
|
161
|
+
const we = e.useCallback(() => {
|
|
162
|
+
K(!0), xe(c.current);
|
|
163
|
+
}, []), Ze = e.useCallback((o) => {
|
|
164
|
+
const a = o.value, r = t.search.search({ text: a, matchCase: p });
|
|
165
|
+
y(r.length ? 1 : 0), R(r.length), j(a);
|
|
166
|
+
}, [p]), Le = e.useCallback(() => {
|
|
167
|
+
const o = t.search.search({ text: F, matchCase: !p });
|
|
168
|
+
y(o.length ? 1 : 0), R(o.length), U(!p);
|
|
169
|
+
}, [p, F]), ze = e.useCallback(() => {
|
|
170
|
+
oe(t), y(f + 1 > k ? 1 : f + 1);
|
|
171
|
+
}, [f, k]), Ie = e.useCallback(() => {
|
|
172
|
+
Lt(t), y(f - 1 < 1 ? k : f - 1);
|
|
173
|
+
}, [f, k]), _ = e.useCallback(() => {
|
|
174
|
+
t.search.destroy(), y(0), R(0), U(!1), j(""), K(!1);
|
|
175
|
+
}, []), Te = e.useCallback((o) => {
|
|
176
|
+
o.key === "Enter" ? (o.preventDefault(), oe(t), y(f + 1 > k ? 1 : f + 1)) : o.key === "Escape" && _();
|
|
177
|
+
}, [f, k]), Pe = e.useCallback((o) => {
|
|
178
|
+
if (c.current) {
|
|
179
|
+
const a = o.skip;
|
|
180
|
+
ee(c.current, a);
|
|
181
|
+
const r = {
|
|
182
|
+
page: a + 1,
|
|
183
|
+
target: v.current,
|
|
184
|
+
syntheticEvent: o.syntheticEvent
|
|
185
|
+
};
|
|
186
|
+
n.onPageChange && n.onPageChange.call(void 0, r);
|
|
187
|
+
}
|
|
188
|
+
V(o.skip);
|
|
189
|
+
}, [w, n.onPageChange]), Ne = e.useCallback((o) => {
|
|
190
|
+
if (L.current) {
|
|
191
|
+
const a = zt(L.current);
|
|
192
|
+
if (a !== w) {
|
|
193
|
+
V(a);
|
|
194
|
+
const r = {
|
|
195
|
+
page: a + 1,
|
|
196
|
+
target: v.current,
|
|
197
|
+
syntheticEvent: o
|
|
198
|
+
};
|
|
199
|
+
n.onPageChange && n.onPageChange.call(void 0, r);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}, [w, n.onPageChange]), Me = e.useCallback((o) => {
|
|
203
|
+
const a = Math.min(t.currentZoom + S, N);
|
|
204
|
+
if (a !== t.currentZoom && t.document && (x(a), n.onZoom)) {
|
|
205
|
+
const r = {
|
|
206
|
+
zoom: a,
|
|
207
|
+
target: v.current,
|
|
208
|
+
syntheticEvent: o
|
|
209
|
+
};
|
|
210
|
+
n.onZoom.call(void 0, r);
|
|
211
|
+
}
|
|
212
|
+
}, [S, N, n.onZoom]), Re = e.useCallback((o) => {
|
|
213
|
+
const a = Math.max(t.currentZoom - S, P);
|
|
214
|
+
if (a !== t.currentZoom && t.document && (x(a), n.onZoom)) {
|
|
215
|
+
const r = {
|
|
216
|
+
zoom: a,
|
|
217
|
+
target: v.current,
|
|
218
|
+
syntheticEvent: o
|
|
219
|
+
};
|
|
220
|
+
n.onZoom.call(void 0, r);
|
|
221
|
+
}
|
|
222
|
+
}, [S, P, n.onZoom]), Fe = e.useCallback((o) => {
|
|
223
|
+
const a = o.value === null ? { text: "100%", value: 1, id: 100 } : { ...o.value };
|
|
224
|
+
if (a.value === void 0) {
|
|
225
|
+
const u = parseFloat(a.text);
|
|
226
|
+
typeof u == "number" && !Number.isNaN(u) ? a.value = u / 100 : a.value = 1;
|
|
227
|
+
}
|
|
228
|
+
let r = a ? It(a.value, a.type, t.currentZoom, c.current) : 1;
|
|
229
|
+
if (r = Math.round(r * 100) / 100, t.currentZoom !== r && t.document && (x(r), n.onZoom)) {
|
|
230
|
+
const u = {
|
|
231
|
+
zoom: r,
|
|
232
|
+
target: v.current,
|
|
233
|
+
syntheticEvent: o.syntheticEvent
|
|
234
|
+
};
|
|
235
|
+
n.onZoom.call(void 0, u);
|
|
236
|
+
}
|
|
237
|
+
}, [n.onZoom]), De = e.useCallback(() => {
|
|
238
|
+
t.scroller.disablePanEventsTracking(), W(!0);
|
|
239
|
+
}, []), Oe = e.useCallback(() => {
|
|
240
|
+
t.scroller.enablePanEventsTracking(), W(!1);
|
|
241
|
+
}, []), Be = e.useCallback(() => {
|
|
242
|
+
Tt({
|
|
243
|
+
pdf: t.document,
|
|
244
|
+
error: t.error
|
|
245
|
+
}, n.saveFileName, n.saveOptions, H);
|
|
246
|
+
}, [n.url, n.data, n.arrayBuffer, n.saveFileName, n.saveOptions, H]), Ae = e.useCallback(() => {
|
|
247
|
+
h(!0);
|
|
248
|
+
const o = (r) => {
|
|
249
|
+
t.error(typeof (r ? r.message || r : null) == "string" ? r.message || r : s.toLanguageString(ve, i[ve]));
|
|
250
|
+
}, a = () => {
|
|
251
|
+
h(!1);
|
|
252
|
+
};
|
|
253
|
+
Pt(t.pages, a, o);
|
|
254
|
+
}, []), Ve = e.useCallback((o) => {
|
|
255
|
+
const a = o.newState;
|
|
256
|
+
a[0] && a[0].getRawFile && a[0].getRawFile().arrayBuffer().then((u) => {
|
|
257
|
+
if (c.current) {
|
|
258
|
+
h(!0), z(c.current);
|
|
259
|
+
const D = t.props.zoom === void 0 ? T : t.props.zoom;
|
|
260
|
+
te({
|
|
261
|
+
arrayBuffer: u,
|
|
262
|
+
dom: c.current,
|
|
263
|
+
zoom: D,
|
|
264
|
+
done: t.done,
|
|
265
|
+
error: t.error
|
|
266
|
+
}), x(D);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}, [T]), We = e.useCallback((o) => {
|
|
270
|
+
const a = o.target;
|
|
271
|
+
if (a instanceof Element && a.parentNode) {
|
|
272
|
+
const r = a.closest(".k-toolbar"), u = r && r.querySelector(".k-upload input");
|
|
273
|
+
u && u.click();
|
|
274
|
+
}
|
|
275
|
+
}, []), G = pe && /* @__PURE__ */ e.createElement("div", { className: "k-loader-container k-loader-container-md k-loader-top" }, /* @__PURE__ */ e.createElement("div", { className: "k-loader-container-overlay k-overlay-light" }), /* @__PURE__ */ e.createElement("div", { className: "k-loader-container-inner " }, /* @__PURE__ */ e.createElement(lt, { size: "large" }))), Ke = /* @__PURE__ */ e.createElement(X, null, /* @__PURE__ */ e.createElement(
|
|
276
|
+
m,
|
|
277
|
+
{
|
|
278
|
+
className: "k-toolbar-button",
|
|
279
|
+
title: s.toLanguageString(ne, i[ne]),
|
|
280
|
+
disabled: d <= P || !g,
|
|
281
|
+
onClick: Re,
|
|
282
|
+
icon: "zoom-out",
|
|
283
|
+
svgIcon: dt
|
|
284
|
+
}
|
|
285
|
+
), /* @__PURE__ */ e.createElement(
|
|
286
|
+
m,
|
|
287
|
+
{
|
|
288
|
+
className: "k-toolbar-button",
|
|
289
|
+
title: s.toLanguageString(ae, i[ae]),
|
|
290
|
+
disabled: d >= N || !g,
|
|
291
|
+
onClick: Me,
|
|
292
|
+
icon: "zoom-in",
|
|
293
|
+
svgIcon: gt
|
|
294
|
+
}
|
|
295
|
+
)), Ue = /* @__PURE__ */ e.createElement(
|
|
296
|
+
rt,
|
|
297
|
+
{
|
|
298
|
+
disabled: !g,
|
|
299
|
+
data: A.map(
|
|
300
|
+
(o) => ({
|
|
301
|
+
...o,
|
|
302
|
+
text: o.locationString ? s.toLanguageString(o.locationString, i[o.locationString]) : o.text
|
|
303
|
+
})
|
|
304
|
+
),
|
|
305
|
+
dataItemKey: "id",
|
|
306
|
+
textField: "text",
|
|
307
|
+
value: g ? E : null,
|
|
308
|
+
allowCustom: !0,
|
|
309
|
+
onChange: Fe,
|
|
310
|
+
placeholder: s.toLanguageString(re, i[re])
|
|
311
|
+
}
|
|
312
|
+
), je = /* @__PURE__ */ e.createElement(
|
|
313
|
+
nt,
|
|
314
|
+
{
|
|
315
|
+
previousNext: !0,
|
|
316
|
+
type: "input",
|
|
317
|
+
skip: w,
|
|
318
|
+
take: 1,
|
|
319
|
+
total: t.pages ? t.pages.length : 0,
|
|
320
|
+
info: !1,
|
|
321
|
+
onPageChange: Pe
|
|
322
|
+
}
|
|
323
|
+
), qe = /* @__PURE__ */ e.createElement(et, null), He = /* @__PURE__ */ e.createElement(X, null, /* @__PURE__ */ e.createElement(
|
|
324
|
+
m,
|
|
325
|
+
{
|
|
326
|
+
className: "k-toolbar-button",
|
|
327
|
+
title: s.toLanguageString(le, i[le]),
|
|
328
|
+
icon: "pointer",
|
|
329
|
+
svgIcon: ft,
|
|
330
|
+
disabled: !g,
|
|
331
|
+
togglable: !0,
|
|
332
|
+
selected: Z && g,
|
|
333
|
+
onClick: De
|
|
334
|
+
}
|
|
335
|
+
), /* @__PURE__ */ e.createElement(
|
|
336
|
+
m,
|
|
337
|
+
{
|
|
338
|
+
className: "k-toolbar-button",
|
|
339
|
+
title: s.toLanguageString(ce, i[ce]),
|
|
340
|
+
icon: "hand",
|
|
341
|
+
svgIcon: vt,
|
|
342
|
+
disabled: !g,
|
|
343
|
+
togglable: !0,
|
|
344
|
+
selected: !Z && g,
|
|
345
|
+
onClick: Oe
|
|
346
|
+
}
|
|
347
|
+
)), $e = /* @__PURE__ */ e.createElement(
|
|
348
|
+
m,
|
|
349
|
+
{
|
|
350
|
+
className: "k-toolbar-button",
|
|
351
|
+
title: s.toLanguageString(I, i[I]),
|
|
352
|
+
icon: "search",
|
|
353
|
+
svgIcon: ht,
|
|
354
|
+
disabled: !g,
|
|
355
|
+
onClick: we
|
|
356
|
+
}
|
|
357
|
+
), _e = /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
|
|
358
|
+
m,
|
|
359
|
+
{
|
|
360
|
+
className: "k-toolbar-button",
|
|
361
|
+
title: s.toLanguageString(se, i[se]),
|
|
362
|
+
icon: "folder-open",
|
|
363
|
+
svgIcon: kt,
|
|
364
|
+
onClick: We
|
|
365
|
+
}
|
|
366
|
+
), /* @__PURE__ */ e.createElement("div", { style: { display: "none" } }, /* @__PURE__ */ e.createElement(
|
|
367
|
+
at,
|
|
368
|
+
{
|
|
369
|
+
restrictions: { allowedExtensions: [".pdf"] },
|
|
370
|
+
onAdd: Ve,
|
|
371
|
+
autoUpload: !1,
|
|
372
|
+
defaultFiles: [],
|
|
373
|
+
multiple: !1,
|
|
374
|
+
accept: ".pdf,.PDF",
|
|
375
|
+
withCredentials: !1
|
|
376
|
+
}
|
|
377
|
+
))), Ge = /* @__PURE__ */ e.createElement(
|
|
378
|
+
m,
|
|
379
|
+
{
|
|
380
|
+
className: "k-toolbar-button",
|
|
381
|
+
title: s.toLanguageString(ie, i[ie]),
|
|
382
|
+
icon: "download",
|
|
383
|
+
svgIcon: bt,
|
|
384
|
+
disabled: !g,
|
|
385
|
+
onClick: Be
|
|
386
|
+
}
|
|
387
|
+
), Je = /* @__PURE__ */ e.createElement(
|
|
388
|
+
m,
|
|
389
|
+
{
|
|
390
|
+
className: "k-toolbar-button",
|
|
391
|
+
title: s.toLanguageString(ue, i[ue]),
|
|
392
|
+
icon: "print",
|
|
393
|
+
svgIcon: yt,
|
|
394
|
+
disabled: !g,
|
|
395
|
+
onClick: Ae
|
|
396
|
+
}
|
|
397
|
+
), Qe = {
|
|
398
|
+
pager: je,
|
|
399
|
+
spacer: qe,
|
|
400
|
+
zoomInOut: Ke,
|
|
401
|
+
zoom: Ue,
|
|
402
|
+
selection: He,
|
|
403
|
+
search: $e,
|
|
404
|
+
open: _e,
|
|
405
|
+
download: Ge,
|
|
406
|
+
print: Je
|
|
407
|
+
}, Xe = (n.tools || b.tools).map((o) => ({ ...Qe[o], key: "toobar-tool-" + o + Ot() })), J = /* @__PURE__ */ e.createElement(Ye, { buttons: Dt }, ...Xe), Q = /* @__PURE__ */ e.createElement(
|
|
408
|
+
"div",
|
|
409
|
+
{
|
|
410
|
+
className: it("k-canvas k-pdf-viewer-canvas k-pos-relative k-overflow-auto", {
|
|
411
|
+
"k-enable-text-select": Z,
|
|
412
|
+
"k-enable-panning": !Z
|
|
413
|
+
}),
|
|
414
|
+
onScroll: Ne
|
|
415
|
+
},
|
|
416
|
+
Ee && /* @__PURE__ */ e.createElement("div", { className: "k-search-panel k-pos-sticky k-top-center" }, /* @__PURE__ */ e.createElement(
|
|
417
|
+
tt,
|
|
418
|
+
{
|
|
419
|
+
value: F,
|
|
420
|
+
onChange: Ze,
|
|
421
|
+
placeholder: s.toLanguageString(I, i[I]),
|
|
422
|
+
autoFocus: !0,
|
|
423
|
+
onKeyDown: Te,
|
|
424
|
+
suffix: () => /* @__PURE__ */ e.createElement(ot, null, /* @__PURE__ */ e.createElement(
|
|
425
|
+
m,
|
|
426
|
+
{
|
|
427
|
+
icon: "convert-lowercase",
|
|
428
|
+
svgIcon: pt,
|
|
429
|
+
title: s.toLanguageString(me, i[me]),
|
|
430
|
+
fillMode: "flat",
|
|
431
|
+
togglable: !0,
|
|
432
|
+
selected: p,
|
|
433
|
+
onClick: Le
|
|
434
|
+
}
|
|
435
|
+
))
|
|
436
|
+
}
|
|
437
|
+
), /* @__PURE__ */ e.createElement("span", { className: "k-search-matches" }, /* @__PURE__ */ e.createElement("span", null, f), " of ", /* @__PURE__ */ e.createElement("span", null, k)), /* @__PURE__ */ e.createElement(
|
|
438
|
+
m,
|
|
439
|
+
{
|
|
440
|
+
title: s.toLanguageString(de, i[de]),
|
|
441
|
+
fillMode: "flat",
|
|
442
|
+
icon: "arrow-up",
|
|
443
|
+
svgIcon: Et,
|
|
444
|
+
disabled: k === 0,
|
|
445
|
+
onClick: Ie
|
|
446
|
+
}
|
|
447
|
+
), /* @__PURE__ */ e.createElement(
|
|
448
|
+
m,
|
|
449
|
+
{
|
|
450
|
+
title: s.toLanguageString(ge, i[ge]),
|
|
451
|
+
fillMode: "flat",
|
|
452
|
+
icon: "arrow-down",
|
|
453
|
+
svgIcon: Ct,
|
|
454
|
+
disabled: k === 0,
|
|
455
|
+
onClick: ze
|
|
456
|
+
}
|
|
457
|
+
), /* @__PURE__ */ e.createElement(
|
|
458
|
+
m,
|
|
459
|
+
{
|
|
460
|
+
title: s.toLanguageString(fe, i[fe]),
|
|
461
|
+
fillMode: "flat",
|
|
462
|
+
icon: "x",
|
|
463
|
+
svgIcon: St,
|
|
464
|
+
onClick: _
|
|
465
|
+
}
|
|
466
|
+
)),
|
|
467
|
+
/* @__PURE__ */ e.createElement("div", { ref: c, className: "k-pdf-viewer-pages" })
|
|
468
|
+
);
|
|
469
|
+
return /* @__PURE__ */ e.createElement("div", { className: "k-pdf-viewer", style: n.style, ref: L }, n.onRenderLoader ? n.onRenderLoader.call(void 0, G || null) : G, n.onRenderToolbar ? n.onRenderToolbar.call(void 0, J) : J, n.onRenderContent ? n.onRenderContent.call(void 0, Q) : Q, be && /* @__PURE__ */ e.createElement(ut, null));
|
|
470
|
+
});
|
|
471
|
+
O.displayName = "KendoReactPDFViewer";
|
|
472
|
+
O.propTypes = {
|
|
473
|
+
url: l.string,
|
|
474
|
+
data: l.string,
|
|
475
|
+
arrayBuffer: l.any,
|
|
476
|
+
typedArray: l.any,
|
|
477
|
+
style: l.object,
|
|
478
|
+
saveFileName: l.string,
|
|
479
|
+
saveOptions: l.object,
|
|
480
|
+
tools: l.arrayOf(l.oneOf(ke).isRequired),
|
|
481
|
+
zoomLevels: l.arrayOf(l.any),
|
|
482
|
+
zoom: l.number,
|
|
483
|
+
defaultZoom: l.number,
|
|
484
|
+
minZoom: l.number,
|
|
485
|
+
maxZoom: l.number,
|
|
486
|
+
zoomRate: l.number,
|
|
487
|
+
onError: l.func,
|
|
488
|
+
onLoad: l.func,
|
|
489
|
+
onDownload: l.func,
|
|
490
|
+
onRenderToolbar: l.func,
|
|
491
|
+
onRenderContent: l.func,
|
|
492
|
+
onRenderLoader: l.func,
|
|
493
|
+
onZoom: l.func
|
|
494
|
+
};
|
|
495
|
+
O.defaultProps = b;
|
|
496
|
+
export {
|
|
497
|
+
O as PDFViewer
|
|
498
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
(function(i,c){typeof exports=="object"&&typeof module!="undefined"?c(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.entry.js")):typeof define=="function"&&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.entry.js"],c):(i=typeof globalThis!="undefined"?globalThis:i||self,c(i.KendoReactPdfViewer={},i.KendoPdfviewerCommon,i.React,i.PropTypes,i.KendoReactButtons,i.KendoReactInputs,i.KendoReactDataTools,i.KendoReactUpload,i.KendoReactDropdowns,i.KendoReactIndicators,i.KendoReactCommon,i.KendoReactIntl,i.KendoSvgIcons))})(this,function(i,c,we,l,g,oe,Se,Ce,xe,Ze,N,ze,m){"use strict";"use client";function Le(n){const y=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const S in n)if(S!=="default"){const z=Object.getOwnPropertyDescriptor(n,S);Object.defineProperty(y,S,z.get?z:{enumerable:!0,get:()=>n[S]})}}return y.default=n,Object.freeze(y)}const e=Le(we),ne={name:"@progress/kendo-react-pdf-viewer",productName:"KendoReact",productCodes:["KENDOUIREACT","KENDOUICOMPLETE"],publishDate:1673300081,version:"",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"},K="pdfviewer.zoomIn",R="pdfviewer.zoomOut",q="pdfviewer.zoomLevel",j="pdfviewer.enableSelection",B="pdfviewer.enablePanning",Z="pdfviewer.search",P="pdfviewer.open",A="pdfviewer.download",U="pdfviewer.print",V="pdfviewer.close",W="pdfviewer.matchCase",_="pdfviewer.prevMatch",H="pdfviewer.nextMatch",ae="pdfviewer.actualWidth",re="pdfviewer.fitToWidth",ce="pdfviewer.fitToPage",G="pdfviewer.popupBlocked",u={[K]:"Zoom in",[R]:"Zoom out",[q]:"Choose zoom level",[j]:"Enable selection",[B]:"Enable panning",[Z]:"Search",[P]:"Open",[A]:"Download",[U]:"Print",[V]:"Close",[W]:"Match case",[_]:"Previous match",[H]:"Next match",[ae]:"Actual width",[re]:"Fit to width",[ce]:"Fit to page",[G]:"Popup is blocked."},le=["pager","spacer","zoomInOut","zoom","selection","spacer","search","open","download","print"],w={minZoom:.5,maxZoom:4,tools:[...le],zoomRate:.25,zoomLevels:[{id:1,priority:1,value:1,text:"Actual width",type:"ActualWidth",locationString:ae},{id:2,priority:2,value:1,text:"Fit to width",type:"FitToWidth",locationString:re},{id:3,priority:3,value:1,text:"Fit to page",type:"FitToPage",locationString:ce},{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:c.DEFAULT_ZOOM_LEVEL},Ne=[".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 se=0;function Me(){return se++,se}const Oe=(n,y)=>n.priority>y.priority?-1:n.priority<y.priority?1:0,M=e.forwardRef((n,y)=>{N.validatePackage(ne);const S=N.shouldShowValidationUI(ne),{zoom:z,zoomLevels:ie=w.zoomLevels,defaultZoom:$=w.defaultZoom,minZoom:J=w.minZoom,maxZoom:Q=w.maxZoom,zoomRate:O=w.zoomRate}=n,d=ze.useLocalization(),s=e.useRef(null),[Ie,D]=e.useState($),h=z!==void 0?z:Ie,L=ie.slice().sort(Oe).find(o=>o.value===h)||{text:h*100+"%",value:h,id:h,locationString:""};L.locationString&&(L.text=d.toLanguageString(L.locationString,u[L.locationString]));const[v,X]=e.useState(!1),[Fe,k]=e.useState(!0),[I,ue]=e.useState(0),[F,de]=e.useState(!1),[Te,ge]=e.useState(!1),[E,Y]=e.useState(0),[b,C]=e.useState(0),[x,me]=e.useState(!1),[ee,fe]=e.useState(""),t=e.useMemo(()=>({}),[]);t.currentZoom=h,t.props=n;const he=e.useCallback(o=>{s.current&&s.current.style.setProperty("--scale-factor",String(o))},[]),p=e.useRef(null),T=e.useRef(null);e.useImperativeHandle(p,()=>({get element(){return T.current},props:n,get pages(){return t.pages},get document(){return t.document}}),[]),e.useImperativeHandle(y,()=>p.current);const Ke=e.useCallback(()=>{if(t.props.onLoad){const o={target:p.current};t.props.onLoad.call(void 0,o)}},[]),ve=e.useCallback((o,a,r)=>{if(n.onDownload){const f={target:p.current,blob:o,fileName:a,saveOptions:r};return n.onDownload.call(void 0,f)===!1}return!1},[n.onDownload]),Re=e.useCallback(()=>{var o;t.scroller&&t.scroller.destroy(),t.scroller=new c.Scroller((o=s.current)==null?void 0:o.parentNode,{filter:".k-page",events:{}}),t.scroller.enablePanEventsTracking()},[]),qe=e.useCallback(o=>{const a=Array.from(o.querySelectorAll(".k-text-layer"));t.search=new c.SearchService({textContainers:a||[],highlightClass:"k-search-highlight",highlightMarkClass:"k-search-highlight-mark",charClass:"k-text-char"})},[]);t.done=e.useCallback(({pdfPages:o,pdfDoc:a,zoom:r})=>{t.document=a,t.pages=o,t.zoom=r,Re(),k(!1),X(!0),Ke(),s.current&&c.scrollToPage(s.current,0)},[]),t.error=e.useCallback(o=>{if(t.document=null,t.pages=[],k(!1),X(!1),n.onError){const a={error:typeof o=="string"?{message:o}:o,target:p.current};n.onError.call(void 0,a)}},[n.onError]),e.useEffect(()=>{s.current&&(n.url||n.data||n.arrayBuffer?(k(!0),c.removeChildren(s.current),c.loadPDF({url:n.url,data:n.data,arrayBuffer:n.arrayBuffer,dom:s.current,zoom:t.currentZoom,done:t.done,error:t.error}),he(t.currentZoom)):(t.document=null,t.pages=[],X(!1),k(!1),c.removeChildren(s.current)))},[n.url,n.data,n.arrayBuffer]);const be=e.useCallback((o,a)=>{s.current&&(k(!0),c.removeChildren(s.current),c.reloadDocument({pdfDoc:o,zoom:a,dom:s.current,done:r=>{t.pages=r,t.zoom=a,k(!1)},error:t.error}))},[]);e.useEffect(()=>{he(h),s.current&&t.document&&h!==t.zoom&&be(t.document,h)},[h,be]),e.useEffect(()=>()=>{t.scroller&&t.scroller.destroy(),t.search&&t.search.destroy(),t.document=null,t.pages=[]},[]);const je=e.useCallback(()=>{ge(!0),qe(s.current)},[]),Be=e.useCallback(o=>{const a=o.value,r=t.search.search({text:a,matchCase:x});C(r.length?1:0),Y(r.length),fe(a)},[x]),Pe=e.useCallback(()=>{const o=t.search.search({text:ee,matchCase:!x});C(o.length?1:0),Y(o.length),me(!x)},[x,ee]),Ae=e.useCallback(()=>{c.goToNextSearchMatch(t),C(b+1>E?1:b+1)},[b,E]),Ue=e.useCallback(()=>{c.goToPreviousSearchMatch(t),C(b-1<1?E:b-1)},[b,E]),pe=e.useCallback(()=>{t.search.destroy(),C(0),Y(0),me(!1),fe(""),ge(!1)},[]),Ve=e.useCallback(o=>{o.key==="Enter"?(o.preventDefault(),c.goToNextSearchMatch(t),C(b+1>E?1:b+1)):o.key==="Escape"&&pe()},[b,E]),We=e.useCallback(o=>{if(s.current){const a=o.skip;c.scrollToPage(s.current,a);const r={page:a+1,target:p.current,syntheticEvent:o.syntheticEvent};n.onPageChange&&n.onPageChange.call(void 0,r)}ue(o.skip)},[I,n.onPageChange]),_e=e.useCallback(o=>{if(T.current){const a=c.currentPage(T.current);if(a!==I){ue(a);const r={page:a+1,target:p.current,syntheticEvent:o};n.onPageChange&&n.onPageChange.call(void 0,r)}}},[I,n.onPageChange]),He=e.useCallback(o=>{const a=Math.min(t.currentZoom+O,Q);if(a!==t.currentZoom&&t.document&&(D(a),n.onZoom)){const r={zoom:a,target:p.current,syntheticEvent:o};n.onZoom.call(void 0,r)}},[O,Q,n.onZoom]),Ge=e.useCallback(o=>{const a=Math.max(t.currentZoom-O,J);if(a!==t.currentZoom&&t.document&&(D(a),n.onZoom)){const r={zoom:a,target:p.current,syntheticEvent:o};n.onZoom.call(void 0,r)}},[O,J,n.onZoom]),$e=e.useCallback(o=>{const a=o.value===null?{text:"100%",value:1,id:100}:{...o.value};if(a.value===void 0){const f=parseFloat(a.text);typeof f=="number"&&!Number.isNaN(f)?a.value=f/100:a.value=1}let r=a?c.calculateZoomLevel(a.value,a.type,t.currentZoom,s.current):1;if(r=Math.round(r*100)/100,t.currentZoom!==r&&t.document&&(D(r),n.onZoom)){const f={zoom:r,target:p.current,syntheticEvent:o.syntheticEvent};n.onZoom.call(void 0,f)}},[n.onZoom]),Je=e.useCallback(()=>{t.scroller.disablePanEventsTracking(),de(!0)},[]),Qe=e.useCallback(()=>{t.scroller.enablePanEventsTracking(),de(!1)},[]),Xe=e.useCallback(()=>{c.download({pdf:t.document,error:t.error},n.saveFileName,n.saveOptions,ve)},[n.url,n.data,n.arrayBuffer,n.saveFileName,n.saveOptions,ve]),Ye=e.useCallback(()=>{k(!0);const o=r=>{t.error(typeof(r?r.message||r:null)=="string"?r.message||r:d.toLanguageString(G,u[G]))},a=()=>{k(!1)};c.print(t.pages,a,o)},[]),et=e.useCallback(o=>{const a=o.newState;a[0]&&a[0].getRawFile&&a[0].getRawFile().arrayBuffer().then(f=>{if(s.current){k(!0),c.removeChildren(s.current);const te=t.props.zoom===void 0?$:t.props.zoom;c.loadPDF({arrayBuffer:f,dom:s.current,zoom:te,done:t.done,error:t.error}),D(te)}})},[$]),tt=e.useCallback(o=>{const a=o.target;if(a instanceof Element&&a.parentNode){const r=a.closest(".k-toolbar"),f=r&&r.querySelector(".k-upload input");f&&f.click()}},[]),ke=Fe&&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(Ze.Loader,{size:"large"}))),ot=e.createElement(g.ButtonGroup,null,e.createElement(g.Button,{className:"k-toolbar-button",title:d.toLanguageString(R,u[R]),disabled:h<=J||!v,onClick:Ge,icon:"zoom-out",svgIcon:m.zoomOutIcon}),e.createElement(g.Button,{className:"k-toolbar-button",title:d.toLanguageString(K,u[K]),disabled:h>=Q||!v,onClick:He,icon:"zoom-in",svgIcon:m.zoomInIcon})),nt=e.createElement(xe.ComboBox,{disabled:!v,data:ie.map(o=>({...o,text:o.locationString?d.toLanguageString(o.locationString,u[o.locationString]):o.text})),dataItemKey:"id",textField:"text",value:v?L:null,allowCustom:!0,onChange:$e,placeholder:d.toLanguageString(q,u[q])}),at=e.createElement(Se.Pager,{previousNext:!0,type:"input",skip:I,take:1,total:t.pages?t.pages.length:0,info:!1,onPageChange:We}),rt=e.createElement(g.ToolbarSpacer,null),ct=e.createElement(g.ButtonGroup,null,e.createElement(g.Button,{className:"k-toolbar-button",title:d.toLanguageString(j,u[j]),icon:"pointer",svgIcon:m.pointerIcon,disabled:!v,togglable:!0,selected:F&&v,onClick:Je}),e.createElement(g.Button,{className:"k-toolbar-button",title:d.toLanguageString(B,u[B]),icon:"hand",svgIcon:m.handIcon,disabled:!v,togglable:!0,selected:!F&&v,onClick:Qe})),lt=e.createElement(g.Button,{className:"k-toolbar-button",title:d.toLanguageString(Z,u[Z]),icon:"search",svgIcon:m.searchIcon,disabled:!v,onClick:je}),st=e.createElement(e.Fragment,null,e.createElement(g.Button,{className:"k-toolbar-button",title:d.toLanguageString(P,u[P]),icon:"folder-open",svgIcon:m.folderOpenIcon,onClick:tt}),e.createElement("div",{style:{display:"none"}},e.createElement(Ce.Upload,{restrictions:{allowedExtensions:[".pdf"]},onAdd:et,autoUpload:!1,defaultFiles:[],multiple:!1,accept:".pdf,.PDF",withCredentials:!1}))),it=e.createElement(g.Button,{className:"k-toolbar-button",title:d.toLanguageString(A,u[A]),icon:"download",svgIcon:m.downloadIcon,disabled:!v,onClick:Xe}),ut=e.createElement(g.Button,{className:"k-toolbar-button",title:d.toLanguageString(U,u[U]),icon:"print",svgIcon:m.printIcon,disabled:!v,onClick:Ye}),dt={pager:at,spacer:rt,zoomInOut:ot,zoom:nt,selection:ct,search:lt,open:st,download:it,print:ut},gt=(n.tools||w.tools).map(o=>({...dt[o],key:"toobar-tool-"+o+Me()})),Ee=e.createElement(g.Toolbar,{buttons:Ne},...gt),ye=e.createElement("div",{className:N.classNames("k-canvas k-pdf-viewer-canvas k-pos-relative k-overflow-auto",{"k-enable-text-select":F,"k-enable-panning":!F}),onScroll:_e},Te&&e.createElement("div",{className:"k-search-panel k-pos-sticky k-top-center"},e.createElement(oe.TextBox,{value:ee,onChange:Be,placeholder:d.toLanguageString(Z,u[Z]),autoFocus:!0,onKeyDown:Ve,suffix:()=>e.createElement(oe.InputSuffix,null,e.createElement(g.Button,{icon:"convert-lowercase",svgIcon:m.convertLowercaseIcon,title:d.toLanguageString(W,u[W]),fillMode:"flat",togglable:!0,selected:x,onClick:Pe}))}),e.createElement("span",{className:"k-search-matches"},e.createElement("span",null,b)," of ",e.createElement("span",null,E)),e.createElement(g.Button,{title:d.toLanguageString(_,u[_]),fillMode:"flat",icon:"arrow-up",svgIcon:m.arrowUpIcon,disabled:E===0,onClick:Ue}),e.createElement(g.Button,{title:d.toLanguageString(H,u[H]),fillMode:"flat",icon:"arrow-down",svgIcon:m.arrowDownIcon,disabled:E===0,onClick:Ae}),e.createElement(g.Button,{title:d.toLanguageString(V,u[V]),fillMode:"flat",icon:"x",svgIcon:m.xIcon,onClick:pe})),e.createElement("div",{ref:s,className:"k-pdf-viewer-pages"}));return e.createElement("div",{className:"k-pdf-viewer",style:n.style,ref:T},n.onRenderLoader?n.onRenderLoader.call(void 0,ke||null):ke,n.onRenderToolbar?n.onRenderToolbar.call(void 0,Ee):Ee,n.onRenderContent?n.onRenderContent.call(void 0,ye):ye,S&&e.createElement(N.WatermarkOverlay,null))});M.displayName="KendoReactPDFViewer",M.propTypes={url:l.string,data:l.string,arrayBuffer:l.any,typedArray:l.any,style:l.object,saveFileName:l.string,saveOptions:l.object,tools:l.arrayOf(l.oneOf(le).isRequired),zoomLevels:l.arrayOf(l.any),zoom:l.number,defaultZoom:l.number,minZoom:l.number,maxZoom:l.number,zoomRate:l.number,onError:l.func,onLoad:l.func,onDownload:l.func,onRenderToolbar:l.func,onRenderContent:l.func,onRenderLoader:l.func,onZoom:l.func},M.defaultProps=w;const De=c.scrollToPage;Object.defineProperty(i,"currentPage",{enumerable:!0,get:()=>c.currentPage}),i.PDFViewer=M,i.scrollToPage=De,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
!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.entry.js")):"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.entry.js"],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,n,a,l,c,s,i,u,d,p){"use strict";function m(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=m(t);const f={name:"@progress/kendo-react-pdf-viewer",productName:"KendoReact",productCodes:["KENDOUIREACT","KENDOUICOMPLETE"],publishDate:1673300081,version:"",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",w="pdfviewer.search",C="pdfviewer.open",E="pdfviewer.download",S="pdfviewer.print",x="pdfviewer.close",P="pdfviewer.matchCase",I="pdfviewer.prevMatch",z="pdfviewer.nextMatch",L="pdfviewer.actualWidth",Z="pdfviewer.fitToWidth",N="pdfviewer.fitToPage",R="pdfviewer.popupBlocked",T={[v]:"Zoom in",[k]:"Zoom out",[b]:"Choose zoom level",[h]:"Enable selection",[y]:"Enable panning",[w]:"Search",[C]:"Open",[E]:"Download",[S]:"Print",[x]:"Close",[P]:"Match case",[I]:"Previous match",[z]:"Next match",[L]:"Actual width",[Z]:"Fit to width",[N]:"Fit to page",[R]:"Popup is blocked."},B=["pager","spacer","zoomInOut","zoom","selection","spacer","search","open","download","print"],O={minZoom:.5,maxZoom:4,tools:[...B],zoomRate:.25,zoomLevels:[{id:1,priority:1,value:1,text:"Actual width",type:"ActualWidth",locationString:L},{id:2,priority:2,value:1,text:"Fit to width",type:"FitToWidth",locationString:Z},{id:3,priority:3,value:1,text:"Fit to page",type:"FitToPage",locationString:N},{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},D=[".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,M=g.forwardRef(((e,t)=>{u.validatePackage(f);const r=u.shouldShowValidationUI(f),{zoom:m,zoomLevels:L=O.zoomLevels,defaultZoom:Z=O.defaultZoom,minZoom:N=O.minZoom,maxZoom:B=O.maxZoom,zoomRate:M=O.zoomRate}=e,q=d.useLocalization(),j=g.useRef(null),[A,U]=g.useState(Z),V=void 0!==m?m:A,W=L.slice().sort(K).find((e=>e.value===V))||{text:100*V+"%",value:V,id:V,locationString:""};W.locationString&&(W.text=q.toLanguageString(W.locationString,T[W.locationString]));const[_,G]=g.useState(!1),[H,J]=g.useState(!0),[Q,X]=g.useState(0),[Y,$]=g.useState(!1),[ee,oe]=g.useState(!1),[te,re]=g.useState(0),[ne,ae]=g.useState(0),[le,ce]=g.useState(!1),[se,ie]=g.useState(""),ue=g.useMemo((()=>({})),[]);ue.currentZoom=V,ue.props=e;const de=g.useCallback((e=>{j.current&&j.current.style.setProperty("--scale-factor",String(e))}),[]),pe=g.useRef(null),me=g.useRef(null);g.useImperativeHandle(pe,(()=>({get element(){return me.current},props:e,get pages(){return ue.pages},get document(){return ue.document}})),[]),g.useImperativeHandle(t,(()=>pe.current));const ge=g.useCallback((()=>{if(ue.props.onLoad){const e={target:pe.current};ue.props.onLoad.call(void 0,e)}}),[]),fe=g.useCallback(((o,t,r)=>{if(e.onDownload){const n={target:pe.current,blob:o,fileName:t,saveOptions:r};return!1===e.onDownload.call(void 0,n)}return!1}),[e.onDownload]),ve=g.useCallback((()=>{var e;ue.scroller&&ue.scroller.destroy(),ue.scroller=new o.Scroller(null==(e=j.current)?void 0:e.parentNode,{filter:".k-page",events:{}}),ue.scroller.enablePanEventsTracking()}),[]),ke=g.useCallback((e=>{const t=Array.from(e.querySelectorAll(".k-text-layer"));ue.search=new o.SearchService({textContainers:t||[],highlightClass:"k-search-highlight",highlightMarkClass:"k-search-highlight-mark",charClass:"k-text-char"})}),[]);ue.done=g.useCallback((({pdfPages:e,pdfDoc:t,zoom:r})=>{ue.document=t,ue.pages=e,ue.zoom=r,ve(),J(!1),G(!0),ge(),j.current&&o.scrollToPage(j.current,0)}),[]),ue.error=g.useCallback((o=>{if(ue.document=null,ue.pages=[],J(!1),G(!1),e.onError){const t={error:"string"==typeof o?{message:o}:o,target:pe.current};e.onError.call(void 0,t)}}),[e.onError]),g.useEffect((()=>{j.current&&(e.url||e.data||e.arrayBuffer?(J(!0),o.removeChildren(j.current),o.loadPDF({url:e.url,data:e.data,arrayBuffer:e.arrayBuffer,dom:j.current,zoom:ue.currentZoom,done:ue.done,error:ue.error}),de(ue.currentZoom)):(ue.document=null,ue.pages=[],G(!1),J(!1),o.removeChildren(j.current)))}),[e.url,e.data,e.arrayBuffer]);const be=g.useCallback(((e,t)=>{j.current&&(J(!0),o.removeChildren(j.current),o.reloadDocument({pdfDoc:e,zoom:t,dom:j.current,done:e=>{ue.pages=e,ue.zoom=t,J(!1)},error:ue.error}))}),[]);g.useEffect((()=>{de(V),j.current&&ue.document&&V!==ue.zoom&&be(ue.document,V)}),[V,be]),g.useEffect((()=>()=>{ue.scroller&&ue.scroller.destroy(),ue.search&&ue.search.destroy(),ue.document=null,ue.pages=[]}),[]);const he=g.useCallback((()=>{oe(!0),ke(j.current)}),[]),ye=g.useCallback((e=>{const o=e.value,t=ue.search.search({text:o,matchCase:le});ae(t.length?1:0),re(t.length),ie(o)}),[le]),we=g.useCallback((()=>{const e=ue.search.search({text:se,matchCase:!le});ae(e.length?1:0),re(e.length),ce(!le)}),[le,se]),Ce=g.useCallback((()=>{o.goToNextSearchMatch(ue),ae(ne+1>te?1:ne+1)}),[ne,te]),Ee=g.useCallback((()=>{o.goToPreviousSearchMatch(ue),ae(ne-1<1?te:ne-1)}),[ne,te]),Se=g.useCallback((()=>{ue.search.destroy(),ae(0),re(0),ce(!1),ie(""),oe(!1)}),[]),xe=g.useCallback((e=>{"Enter"===e.key?(e.preventDefault(),o.goToNextSearchMatch(ue),ae(ne+1>te?1:ne+1)):"Escape"===e.key&&Se()}),[ne,te]),Pe=g.useCallback((t=>{if(j.current){const r=t.skip;o.scrollToPage(j.current,r);const n={page:r+1,target:pe.current,syntheticEvent:t.syntheticEvent};e.onPageChange&&e.onPageChange.call(void 0,n)}X(t.skip)}),[Q,e.onPageChange]),Ie=g.useCallback((t=>{if(me.current){const r=o.currentPage(me.current);if(r!==Q){X(r);const o={page:r+1,target:pe.current,syntheticEvent:t};e.onPageChange&&e.onPageChange.call(void 0,o)}}}),[Q,e.onPageChange]),ze=g.useCallback((o=>{const t=Math.min(ue.currentZoom+M,B);if(t!==ue.currentZoom&&ue.document&&(U(t),e.onZoom)){const r={zoom:t,target:pe.current,syntheticEvent:o};e.onZoom.call(void 0,r)}}),[M,B,e.onZoom]),Le=g.useCallback((o=>{const t=Math.max(ue.currentZoom-M,N);if(t!==ue.currentZoom&&ue.document&&(U(t),e.onZoom)){const r={zoom:t,target:pe.current,syntheticEvent:o};e.onZoom.call(void 0,r)}}),[M,N,e.onZoom]),Ze=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 n=r?o.calculateZoomLevel(r.value,r.type,ue.currentZoom,j.current):1;if(n=Math.round(100*n)/100,ue.currentZoom!==n&&ue.document&&(U(n),e.onZoom)){const o={zoom:n,target:pe.current,syntheticEvent:t.syntheticEvent};e.onZoom.call(void 0,o)}}),[e.onZoom]),Ne=g.useCallback((()=>{ue.scroller.disablePanEventsTracking(),$(!0)}),[]),Re=g.useCallback((()=>{ue.scroller.enablePanEventsTracking(),$(!1)}),[]),Te=g.useCallback((()=>{o.download({pdf:ue.document,error:ue.error},e.saveFileName,e.saveOptions,fe)}),[e.url,e.data,e.arrayBuffer,e.saveFileName,e.saveOptions,fe]),Be=g.useCallback((()=>{J(!0);o.print(ue.pages,(()=>{J(!1)}),(e=>{ue.error("string"==typeof(e?e.message||e:null)?e.message||e:q.toLanguageString(R,T[R]))}))}),[]),Oe=g.useCallback((e=>{const t=e.newState;t[0]&&t[0].getRawFile&&t[0].getRawFile().arrayBuffer().then((e=>{if(j.current){J(!0),o.removeChildren(j.current);const t=void 0===ue.props.zoom?Z:ue.props.zoom;o.loadPDF({arrayBuffer:e,dom:j.current,zoom:t,done:ue.done,error:ue.error}),U(t)}}))}),[Z]),De=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()}}),[]),Fe=H&&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"}))),Ke=g.createElement(n.ButtonGroup,null,g.createElement(n.Button,{className:"k-toolbar-button",title:q.toLanguageString(k,T[k]),disabled:V<=N||!_,onClick:Le,icon:"zoom-out",svgIcon:p.zoomOutIcon}),g.createElement(n.Button,{className:"k-toolbar-button",title:q.toLanguageString(v,T[v]),disabled:V>=B||!_,onClick:ze,icon:"zoom-in",svgIcon:p.zoomInIcon})),Me=g.createElement(s.ComboBox,{disabled:!_,data:L.map((e=>({...e,text:e.locationString?q.toLanguageString(e.locationString,T[e.locationString]):e.text}))),dataItemKey:"id",textField:"text",value:_?W:null,allowCustom:!0,onChange:Ze,placeholder:q.toLanguageString(b,T[b])}),qe={pager:g.createElement(l.Pager,{previousNext:!0,type:"input",skip:Q,take:1,total:ue.pages?ue.pages.length:0,info:!1,onPageChange:Pe}),spacer:g.createElement(n.ToolbarSpacer,null),zoomInOut:Ke,zoom:Me,selection:g.createElement(n.ButtonGroup,null,g.createElement(n.Button,{className:"k-toolbar-button",title:q.toLanguageString(h,T[h]),icon:"pointer",svgIcon:p.pointerIcon,disabled:!_,togglable:!0,selected:Y&&_,onClick:Ne}),g.createElement(n.Button,{className:"k-toolbar-button",title:q.toLanguageString(y,T[y]),icon:"hand",svgIcon:p.handIcon,disabled:!_,togglable:!0,selected:!Y&&_,onClick:Re})),search:g.createElement(n.Button,{className:"k-toolbar-button",title:q.toLanguageString(w,T[w]),icon:"search",svgIcon:p.searchIcon,disabled:!_,onClick:he}),open:g.createElement(g.Fragment,null,g.createElement(n.Button,{className:"k-toolbar-button",title:q.toLanguageString(C,T[C]),icon:"folder-open",svgIcon:p.folderOpenIcon,onClick:De}),g.createElement("div",{style:{display:"none"}},g.createElement(c.Upload,{restrictions:{allowedExtensions:[".pdf"]},onAdd:Oe,autoUpload:!1,defaultFiles:[],multiple:!1,accept:".pdf,.PDF",withCredentials:!1}))),download:g.createElement(n.Button,{className:"k-toolbar-button",title:q.toLanguageString(E,T[E]),icon:"download",svgIcon:p.downloadIcon,disabled:!_,onClick:Te}),print:g.createElement(n.Button,{className:"k-toolbar-button",title:q.toLanguageString(S,T[S]),icon:"print",svgIcon:p.printIcon,disabled:!_,onClick:Be})},je=(e.tools||O.tools).map((e=>({...qe[e],key:"toobar-tool-"+e+(F++,F)}))),Ae=g.createElement(n.Toolbar,{buttons:D},...je),Ue=g.createElement("div",{className:u.classNames("k-canvas k-pdf-viewer-canvas k-pos-relative k-overflow-auto",{"k-enable-text-select":Y,"k-enable-panning":!Y}),onScroll:Ie},ee&&g.createElement("div",{className:"k-search-panel k-pos-sticky k-top-center"},g.createElement(a.TextBox,{value:se,onChange:ye,placeholder:q.toLanguageString(w,T[w]),autoFocus:!0,onKeyDown:xe,suffix:()=>g.createElement(a.InputSuffix,null,g.createElement(n.Button,{icon:"convert-lowercase",svgIcon:p.convertLowercaseIcon,title:q.toLanguageString(P,T[P]),fillMode:"flat",togglable:!0,selected:le,onClick:we}))}),g.createElement("span",{className:"k-search-matches"},g.createElement("span",null,ne)," of ",g.createElement("span",null,te)),g.createElement(n.Button,{title:q.toLanguageString(I,T[I]),fillMode:"flat",icon:"arrow-up",svgIcon:p.arrowUpIcon,disabled:0===te,onClick:Ee}),g.createElement(n.Button,{title:q.toLanguageString(z,T[z]),fillMode:"flat",icon:"arrow-down",svgIcon:p.arrowDownIcon,disabled:0===te,onClick:Ce}),g.createElement(n.Button,{title:q.toLanguageString(x,T[x]),fillMode:"flat",icon:"x",svgIcon:p.xIcon,onClick:Se})),g.createElement("div",{ref:j,className:"k-pdf-viewer-pages"}));return g.createElement("div",{className:"k-pdf-viewer",style:e.style,ref:me},e.onRenderLoader?e.onRenderLoader.call(void 0,Fe||null):Fe,e.onRenderToolbar?e.onRenderToolbar.call(void 0,Ae):Ae,e.onRenderContent?e.onRenderContent.call(void 0,Ue):Ue,r&&g.createElement(u.WatermarkOverlay,null))}));M.displayName="KendoReactPDFViewer",M.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},M.defaultProps=O;const q=o.scrollToPage;Object.defineProperty(e,"currentPage",{enumerable:!0,get:function(){return o.currentPage}}),e.PDFViewer=M,e.scrollToPage=q}));
|