@dvvebond/core 0.2.12 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +249 -114
- package/dist/index.cjs +60708 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21553 -0
- package/dist/index.d.mts +1 -581
- package/dist/index.mjs +2 -1081
- package/dist/index.mjs.map +1 -1
- package/dist/parsing-worker-host-CBKQ4mss.cjs +652 -0
- package/dist/parsing-worker-host-CBKQ4mss.cjs.map +1 -0
- package/dist/parsing-worker-host-DIPVulML.cjs +3 -0
- package/dist/react.cjs +49896 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +11207 -0
- package/dist/react.d.mts +11207 -0
- package/dist/react.mjs +49855 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +23 -8
package/dist/index.mjs
CHANGED
|
@@ -10,11 +10,9 @@ import { Boolean, Constructed, Integer, Null, ObjectIdentifier, OctetString, Seq
|
|
|
10
10
|
import * as pkijs from "pkijs";
|
|
11
11
|
import { createCMSECDSASignature } from "pkijs";
|
|
12
12
|
import { base64 } from "@scure/base";
|
|
13
|
-
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef, useState } from "react";
|
|
14
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
13
|
|
|
16
14
|
//#region package.json
|
|
17
|
-
var version = "0.2.
|
|
15
|
+
var version = "0.2.14";
|
|
18
16
|
|
|
19
17
|
//#endregion
|
|
20
18
|
//#region src/objects/pdf-array.ts
|
|
@@ -60399,1082 +60397,5 @@ async function loadPDFFromBytes(data, options) {
|
|
|
60399
60397
|
}
|
|
60400
60398
|
|
|
60401
60399
|
//#endregion
|
|
60402
|
-
|
|
60403
|
-
/**
|
|
60404
|
-
* Custom React hooks for PDF viewer functionality.
|
|
60405
|
-
*
|
|
60406
|
-
* Provides hooks for managing PDF viewer state, search operations,
|
|
60407
|
-
* viewport management, and bounding box visualization.
|
|
60408
|
-
*/
|
|
60409
|
-
/**
|
|
60410
|
-
* Initial state for the PDF viewer.
|
|
60411
|
-
*/
|
|
60412
|
-
function createInitialViewerState() {
|
|
60413
|
-
return {
|
|
60414
|
-
initialized: false,
|
|
60415
|
-
loading: false,
|
|
60416
|
-
document: null,
|
|
60417
|
-
currentPage: 1,
|
|
60418
|
-
pageCount: 0,
|
|
60419
|
-
scale: 1,
|
|
60420
|
-
rotation: 0,
|
|
60421
|
-
error: null,
|
|
60422
|
-
pageStates: /* @__PURE__ */ new Map()
|
|
60423
|
-
};
|
|
60424
|
-
}
|
|
60425
|
-
/**
|
|
60426
|
-
* Reducer for PDF viewer state.
|
|
60427
|
-
*/
|
|
60428
|
-
function viewerReducer(state$1, action) {
|
|
60429
|
-
switch (action.type) {
|
|
60430
|
-
case "SET_LOADING": return {
|
|
60431
|
-
...state$1,
|
|
60432
|
-
loading: action.loading
|
|
60433
|
-
};
|
|
60434
|
-
case "SET_DOCUMENT": return {
|
|
60435
|
-
...state$1,
|
|
60436
|
-
document: action.document,
|
|
60437
|
-
pageCount: action.document?.getPageCount() ?? 0,
|
|
60438
|
-
currentPage: 1,
|
|
60439
|
-
error: null,
|
|
60440
|
-
pageStates: /* @__PURE__ */ new Map()
|
|
60441
|
-
};
|
|
60442
|
-
case "SET_ERROR": return {
|
|
60443
|
-
...state$1,
|
|
60444
|
-
error: action.error,
|
|
60445
|
-
loading: false
|
|
60446
|
-
};
|
|
60447
|
-
case "SET_INITIALIZED": return {
|
|
60448
|
-
...state$1,
|
|
60449
|
-
initialized: action.initialized
|
|
60450
|
-
};
|
|
60451
|
-
case "SET_CURRENT_PAGE": return {
|
|
60452
|
-
...state$1,
|
|
60453
|
-
currentPage: action.page
|
|
60454
|
-
};
|
|
60455
|
-
case "SET_SCALE": return {
|
|
60456
|
-
...state$1,
|
|
60457
|
-
scale: action.scale
|
|
60458
|
-
};
|
|
60459
|
-
case "SET_ROTATION": return {
|
|
60460
|
-
...state$1,
|
|
60461
|
-
rotation: action.rotation
|
|
60462
|
-
};
|
|
60463
|
-
case "SET_PAGE_STATE": {
|
|
60464
|
-
const newPageStates = new Map(state$1.pageStates);
|
|
60465
|
-
newPageStates.set(action.pageIndex, action.state);
|
|
60466
|
-
return {
|
|
60467
|
-
...state$1,
|
|
60468
|
-
pageStates: newPageStates
|
|
60469
|
-
};
|
|
60470
|
-
}
|
|
60471
|
-
case "CLEAR_PAGE_STATES": return {
|
|
60472
|
-
...state$1,
|
|
60473
|
-
pageStates: /* @__PURE__ */ new Map()
|
|
60474
|
-
};
|
|
60475
|
-
default: return state$1;
|
|
60476
|
-
}
|
|
60477
|
-
}
|
|
60478
|
-
/**
|
|
60479
|
-
* Hook for managing PDF viewer state.
|
|
60480
|
-
*
|
|
60481
|
-
* Handles document loading, page navigation, scale, and rotation.
|
|
60482
|
-
*
|
|
60483
|
-
* @example
|
|
60484
|
-
* ```tsx
|
|
60485
|
-
* const {
|
|
60486
|
-
* state,
|
|
60487
|
-
* loadDocument,
|
|
60488
|
-
* goToPage,
|
|
60489
|
-
* setScale,
|
|
60490
|
-
* setRotation,
|
|
60491
|
-
* viewer,
|
|
60492
|
-
* } = usePDFViewer({
|
|
60493
|
-
* initialScale: 1.5,
|
|
60494
|
-
* onDocumentLoad: (pdf) => console.log('Loaded:', pdf.getPageCount(), 'pages'),
|
|
60495
|
-
* });
|
|
60496
|
-
* ```
|
|
60497
|
-
*/
|
|
60498
|
-
function usePDFViewer(options = {}) {
|
|
60499
|
-
const [state$1, dispatch] = useReducer(viewerReducer, createInitialViewerState());
|
|
60500
|
-
const viewerRef = useRef(null);
|
|
60501
|
-
useEffect(() => {
|
|
60502
|
-
const viewer = new PDFViewer({
|
|
60503
|
-
scale: options.initialScale ?? 1,
|
|
60504
|
-
rotation: options.initialRotation ?? 0,
|
|
60505
|
-
...options.viewerOptions
|
|
60506
|
-
});
|
|
60507
|
-
viewerRef.current = viewer;
|
|
60508
|
-
viewer.initialize().then(() => {
|
|
60509
|
-
dispatch({
|
|
60510
|
-
type: "SET_INITIALIZED",
|
|
60511
|
-
initialized: true
|
|
60512
|
-
});
|
|
60513
|
-
dispatch({
|
|
60514
|
-
type: "SET_SCALE",
|
|
60515
|
-
scale: options.initialScale ?? 1
|
|
60516
|
-
});
|
|
60517
|
-
dispatch({
|
|
60518
|
-
type: "SET_ROTATION",
|
|
60519
|
-
rotation: options.initialRotation ?? 0
|
|
60520
|
-
});
|
|
60521
|
-
}).catch((error) => {
|
|
60522
|
-
dispatch({
|
|
60523
|
-
type: "SET_ERROR",
|
|
60524
|
-
error
|
|
60525
|
-
});
|
|
60526
|
-
});
|
|
60527
|
-
viewer.addEventListener("pagechange", (event) => {
|
|
60528
|
-
if (event.pageNumber !== void 0) {
|
|
60529
|
-
dispatch({
|
|
60530
|
-
type: "SET_CURRENT_PAGE",
|
|
60531
|
-
page: event.pageNumber
|
|
60532
|
-
});
|
|
60533
|
-
options.onPageChange?.(event.pageNumber);
|
|
60534
|
-
}
|
|
60535
|
-
});
|
|
60536
|
-
viewer.addEventListener("scalechange", (event) => {
|
|
60537
|
-
if (event.scale !== void 0) {
|
|
60538
|
-
dispatch({
|
|
60539
|
-
type: "SET_SCALE",
|
|
60540
|
-
scale: event.scale
|
|
60541
|
-
});
|
|
60542
|
-
options.onScaleChange?.(event.scale);
|
|
60543
|
-
}
|
|
60544
|
-
});
|
|
60545
|
-
return () => {
|
|
60546
|
-
viewer.destroy();
|
|
60547
|
-
viewerRef.current = null;
|
|
60548
|
-
};
|
|
60549
|
-
}, []);
|
|
60550
|
-
useEffect(() => {
|
|
60551
|
-
if (options.document) {
|
|
60552
|
-
dispatch({
|
|
60553
|
-
type: "SET_DOCUMENT",
|
|
60554
|
-
document: options.document
|
|
60555
|
-
});
|
|
60556
|
-
viewerRef.current?.setDocument(options.document);
|
|
60557
|
-
options.onDocumentLoad?.(options.document);
|
|
60558
|
-
}
|
|
60559
|
-
}, [options.document]);
|
|
60560
|
-
useEffect(() => {
|
|
60561
|
-
if (options.data && !options.document) {
|
|
60562
|
-
dispatch({
|
|
60563
|
-
type: "SET_LOADING",
|
|
60564
|
-
loading: true
|
|
60565
|
-
});
|
|
60566
|
-
PDF.load(options.data).then((pdf) => {
|
|
60567
|
-
dispatch({
|
|
60568
|
-
type: "SET_DOCUMENT",
|
|
60569
|
-
document: pdf
|
|
60570
|
-
});
|
|
60571
|
-
viewerRef.current?.setDocument(pdf);
|
|
60572
|
-
dispatch({
|
|
60573
|
-
type: "SET_LOADING",
|
|
60574
|
-
loading: false
|
|
60575
|
-
});
|
|
60576
|
-
options.onDocumentLoad?.(pdf);
|
|
60577
|
-
}).catch((error) => {
|
|
60578
|
-
dispatch({
|
|
60579
|
-
type: "SET_ERROR",
|
|
60580
|
-
error
|
|
60581
|
-
});
|
|
60582
|
-
options.onDocumentError?.(error);
|
|
60583
|
-
});
|
|
60584
|
-
}
|
|
60585
|
-
}, [options.data, options.document]);
|
|
60586
|
-
useEffect(() => {
|
|
60587
|
-
if (options.url && !options.document && !options.data) {
|
|
60588
|
-
dispatch({
|
|
60589
|
-
type: "SET_LOADING",
|
|
60590
|
-
loading: true
|
|
60591
|
-
});
|
|
60592
|
-
fetch(options.url).then((response) => {
|
|
60593
|
-
if (!response.ok) throw new Error(`Failed to fetch PDF: ${response.status}`);
|
|
60594
|
-
return response.arrayBuffer();
|
|
60595
|
-
}).then((buffer) => PDF.load(new Uint8Array(buffer))).then((pdf) => {
|
|
60596
|
-
dispatch({
|
|
60597
|
-
type: "SET_DOCUMENT",
|
|
60598
|
-
document: pdf
|
|
60599
|
-
});
|
|
60600
|
-
viewerRef.current?.setDocument(pdf);
|
|
60601
|
-
dispatch({
|
|
60602
|
-
type: "SET_LOADING",
|
|
60603
|
-
loading: false
|
|
60604
|
-
});
|
|
60605
|
-
options.onDocumentLoad?.(pdf);
|
|
60606
|
-
}).catch((error) => {
|
|
60607
|
-
dispatch({
|
|
60608
|
-
type: "SET_ERROR",
|
|
60609
|
-
error: error instanceof Error ? error : new Error(String(error))
|
|
60610
|
-
});
|
|
60611
|
-
options.onDocumentError?.(error instanceof Error ? error : new Error(String(error)));
|
|
60612
|
-
});
|
|
60613
|
-
}
|
|
60614
|
-
}, [
|
|
60615
|
-
options.url,
|
|
60616
|
-
options.document,
|
|
60617
|
-
options.data
|
|
60618
|
-
]);
|
|
60619
|
-
const goToPage = useCallback((pageNumber) => {
|
|
60620
|
-
if (viewerRef.current && pageNumber >= 1 && pageNumber <= state$1.pageCount) {
|
|
60621
|
-
viewerRef.current.goToPage(pageNumber);
|
|
60622
|
-
dispatch({
|
|
60623
|
-
type: "SET_CURRENT_PAGE",
|
|
60624
|
-
page: pageNumber
|
|
60625
|
-
});
|
|
60626
|
-
}
|
|
60627
|
-
}, [state$1.pageCount]);
|
|
60628
|
-
const nextPage = useCallback(() => {
|
|
60629
|
-
if (state$1.currentPage < state$1.pageCount) goToPage(state$1.currentPage + 1);
|
|
60630
|
-
}, [
|
|
60631
|
-
state$1.currentPage,
|
|
60632
|
-
state$1.pageCount,
|
|
60633
|
-
goToPage
|
|
60634
|
-
]);
|
|
60635
|
-
const previousPage = useCallback(() => {
|
|
60636
|
-
if (state$1.currentPage > 1) goToPage(state$1.currentPage - 1);
|
|
60637
|
-
}, [state$1.currentPage, goToPage]);
|
|
60638
|
-
const setScale = useCallback((scale) => {
|
|
60639
|
-
if (viewerRef.current && scale > 0) {
|
|
60640
|
-
viewerRef.current.setScale(scale);
|
|
60641
|
-
dispatch({
|
|
60642
|
-
type: "SET_SCALE",
|
|
60643
|
-
scale
|
|
60644
|
-
});
|
|
60645
|
-
}
|
|
60646
|
-
}, []);
|
|
60647
|
-
const zoomIn = useCallback((factor = 1.25) => {
|
|
60648
|
-
setScale(state$1.scale * factor);
|
|
60649
|
-
}, [state$1.scale, setScale]);
|
|
60650
|
-
const zoomOut = useCallback((factor = 1.25) => {
|
|
60651
|
-
setScale(state$1.scale / factor);
|
|
60652
|
-
}, [state$1.scale, setScale]);
|
|
60653
|
-
const setRotation = useCallback((rotation) => {
|
|
60654
|
-
if (viewerRef.current) {
|
|
60655
|
-
const normalized = (rotation % 360 + 360) % 360;
|
|
60656
|
-
viewerRef.current.setRotation(normalized);
|
|
60657
|
-
dispatch({
|
|
60658
|
-
type: "SET_ROTATION",
|
|
60659
|
-
rotation: normalized
|
|
60660
|
-
});
|
|
60661
|
-
}
|
|
60662
|
-
}, []);
|
|
60663
|
-
const rotateClockwise = useCallback(() => {
|
|
60664
|
-
setRotation(state$1.rotation + 90);
|
|
60665
|
-
}, [state$1.rotation, setRotation]);
|
|
60666
|
-
const rotateCounterClockwise = useCallback(() => {
|
|
60667
|
-
setRotation(state$1.rotation - 90);
|
|
60668
|
-
}, [state$1.rotation, setRotation]);
|
|
60669
|
-
const setPageState = useCallback((pageIndex, pageState) => {
|
|
60670
|
-
dispatch({
|
|
60671
|
-
type: "SET_PAGE_STATE",
|
|
60672
|
-
pageIndex,
|
|
60673
|
-
state: pageState
|
|
60674
|
-
});
|
|
60675
|
-
}, []);
|
|
60676
|
-
const refresh = useCallback(() => {
|
|
60677
|
-
dispatch({ type: "CLEAR_PAGE_STATES" });
|
|
60678
|
-
viewerRef.current?.clearCache();
|
|
60679
|
-
}, []);
|
|
60680
|
-
return {
|
|
60681
|
-
state: state$1,
|
|
60682
|
-
viewer: viewerRef.current,
|
|
60683
|
-
goToPage,
|
|
60684
|
-
nextPage,
|
|
60685
|
-
previousPage,
|
|
60686
|
-
setScale,
|
|
60687
|
-
zoomIn,
|
|
60688
|
-
zoomOut,
|
|
60689
|
-
setRotation,
|
|
60690
|
-
rotateClockwise,
|
|
60691
|
-
rotateCounterClockwise,
|
|
60692
|
-
setPageState,
|
|
60693
|
-
refresh
|
|
60694
|
-
};
|
|
60695
|
-
}
|
|
60696
|
-
/**
|
|
60697
|
-
* Hook for PDF search functionality.
|
|
60698
|
-
*
|
|
60699
|
-
* Provides search state and actions for searching text within a PDF document.
|
|
60700
|
-
*
|
|
60701
|
-
* @example
|
|
60702
|
-
* ```tsx
|
|
60703
|
-
* const { state, actions } = usePDFSearch({
|
|
60704
|
-
* document: pdf,
|
|
60705
|
-
* onSearchResults: (results) => console.log('Found:', results.length),
|
|
60706
|
-
* });
|
|
60707
|
-
*
|
|
60708
|
-
* // Execute search
|
|
60709
|
-
* actions.search('hello world', { caseSensitive: false });
|
|
60710
|
-
*
|
|
60711
|
-
* // Navigate results
|
|
60712
|
-
* actions.findNext();
|
|
60713
|
-
* actions.findPrevious();
|
|
60714
|
-
* ```
|
|
60715
|
-
*/
|
|
60716
|
-
function usePDFSearch(options) {
|
|
60717
|
-
const { document: document$1, enabled = true } = options;
|
|
60718
|
-
const [searchState, setSearchState] = useState({
|
|
60719
|
-
query: "",
|
|
60720
|
-
options: {},
|
|
60721
|
-
results: [],
|
|
60722
|
-
currentIndex: -1,
|
|
60723
|
-
isSearching: false,
|
|
60724
|
-
currentResult: null,
|
|
60725
|
-
resultCount: 0,
|
|
60726
|
-
error: null
|
|
60727
|
-
});
|
|
60728
|
-
const searchEngineRef = useRef(null);
|
|
60729
|
-
const textProvider = useMemo(() => {
|
|
60730
|
-
if (!document$1) return null;
|
|
60731
|
-
return {
|
|
60732
|
-
getPageCount: () => document$1.getPageCount(),
|
|
60733
|
-
getPageText: async (pageIndex) => {
|
|
60734
|
-
const page = document$1.getPage(pageIndex);
|
|
60735
|
-
if (!page) return null;
|
|
60736
|
-
return page.extractText().text;
|
|
60737
|
-
},
|
|
60738
|
-
getCharBounds: async (_pageIndex, _startOffset, _endOffset) => {
|
|
60739
|
-
return [];
|
|
60740
|
-
}
|
|
60741
|
-
};
|
|
60742
|
-
}, [document$1]);
|
|
60743
|
-
useEffect(() => {
|
|
60744
|
-
if (!textProvider || !enabled) {
|
|
60745
|
-
searchEngineRef.current = null;
|
|
60746
|
-
return;
|
|
60747
|
-
}
|
|
60748
|
-
const engine = new SearchEngine({ textProvider });
|
|
60749
|
-
engine.addEventListener("state-change", (event) => {
|
|
60750
|
-
if ("state" in event) {
|
|
60751
|
-
const engineState = event.state;
|
|
60752
|
-
setSearchState({
|
|
60753
|
-
query: engineState.query,
|
|
60754
|
-
options: engineState.options,
|
|
60755
|
-
results: engineState.results,
|
|
60756
|
-
currentIndex: engineState.currentIndex,
|
|
60757
|
-
isSearching: engineState.status === "searching",
|
|
60758
|
-
currentResult: engineState.currentIndex >= 0 ? engineState.results[engineState.currentIndex] : null,
|
|
60759
|
-
resultCount: engineState.results.length,
|
|
60760
|
-
error: engineState.errorMessage ?? null
|
|
60761
|
-
});
|
|
60762
|
-
options.onSearchStateChange?.(engineState);
|
|
60763
|
-
}
|
|
60764
|
-
});
|
|
60765
|
-
engine.addEventListener("search-complete", (event) => {
|
|
60766
|
-
if ("totalResults" in event) options.onSearchResults?.([...searchEngineRef.current?.results ?? []]);
|
|
60767
|
-
});
|
|
60768
|
-
engine.addEventListener("result-change", (event) => {
|
|
60769
|
-
if ("result" in event && "currentIndex" in event) options.onCurrentResultChange?.(event.result, event.currentIndex);
|
|
60770
|
-
});
|
|
60771
|
-
searchEngineRef.current = engine;
|
|
60772
|
-
return () => {
|
|
60773
|
-
engine.cancelSearch();
|
|
60774
|
-
};
|
|
60775
|
-
}, [textProvider, enabled]);
|
|
60776
|
-
return {
|
|
60777
|
-
state: searchState,
|
|
60778
|
-
actions: useMemo(() => ({
|
|
60779
|
-
search: async (query, searchOptions) => {
|
|
60780
|
-
if (!searchEngineRef.current) return [];
|
|
60781
|
-
return searchEngineRef.current.search(query, searchOptions);
|
|
60782
|
-
},
|
|
60783
|
-
findNext: () => {
|
|
60784
|
-
return searchEngineRef.current?.findNext() ?? null;
|
|
60785
|
-
},
|
|
60786
|
-
findPrevious: () => {
|
|
60787
|
-
return searchEngineRef.current?.findPrevious() ?? null;
|
|
60788
|
-
},
|
|
60789
|
-
goToResult: (index) => {
|
|
60790
|
-
return searchEngineRef.current?.goToResult(index) ?? null;
|
|
60791
|
-
},
|
|
60792
|
-
clearSearch: () => {
|
|
60793
|
-
searchEngineRef.current?.clearSearch();
|
|
60794
|
-
},
|
|
60795
|
-
cancelSearch: () => {
|
|
60796
|
-
searchEngineRef.current?.cancelSearch();
|
|
60797
|
-
}
|
|
60798
|
-
}), [])
|
|
60799
|
-
};
|
|
60800
|
-
}
|
|
60801
|
-
/**
|
|
60802
|
-
* Hook for bounding box visualization.
|
|
60803
|
-
*
|
|
60804
|
-
* Manages visibility and state for bounding box overlays.
|
|
60805
|
-
*
|
|
60806
|
-
* @example
|
|
60807
|
-
* ```tsx
|
|
60808
|
-
* const { state, actions, overlay } = useBoundingBoxOverlay({
|
|
60809
|
-
* initialVisibility: { character: true, word: true },
|
|
60810
|
-
* });
|
|
60811
|
-
*
|
|
60812
|
-
* // Set boxes for a page
|
|
60813
|
-
* actions.setBoundingBoxes(0, characterBoxes);
|
|
60814
|
-
*
|
|
60815
|
-
* // Toggle visibility
|
|
60816
|
-
* actions.toggleVisibility('word');
|
|
60817
|
-
* ```
|
|
60818
|
-
*/
|
|
60819
|
-
function useBoundingBoxOverlay(options) {
|
|
60820
|
-
const { enabled = true, initialVisibility } = options;
|
|
60821
|
-
const [state$1, setState] = useState({
|
|
60822
|
-
visibility: {
|
|
60823
|
-
character: false,
|
|
60824
|
-
word: false,
|
|
60825
|
-
line: false,
|
|
60826
|
-
paragraph: false,
|
|
60827
|
-
...initialVisibility
|
|
60828
|
-
},
|
|
60829
|
-
boxes: /* @__PURE__ */ new Map()
|
|
60830
|
-
});
|
|
60831
|
-
const overlayRef = useRef(null);
|
|
60832
|
-
useEffect(() => {
|
|
60833
|
-
if (!enabled) {
|
|
60834
|
-
overlayRef.current = null;
|
|
60835
|
-
return;
|
|
60836
|
-
}
|
|
60837
|
-
const overlay = new BoundingBoxOverlay({ ...options.overlayOptions });
|
|
60838
|
-
if (initialVisibility) overlay.setAllVisibility(initialVisibility);
|
|
60839
|
-
overlay.addEventListener("visibilityChange", (event) => {
|
|
60840
|
-
if (event.visibility) {
|
|
60841
|
-
setState((prev) => ({
|
|
60842
|
-
...prev,
|
|
60843
|
-
visibility: event.visibility
|
|
60844
|
-
}));
|
|
60845
|
-
options.onVisibilityChange?.(event.visibility);
|
|
60846
|
-
}
|
|
60847
|
-
});
|
|
60848
|
-
overlayRef.current = overlay;
|
|
60849
|
-
return () => {
|
|
60850
|
-
overlay.dispose();
|
|
60851
|
-
};
|
|
60852
|
-
}, [enabled]);
|
|
60853
|
-
return {
|
|
60854
|
-
state: state$1,
|
|
60855
|
-
actions: useMemo(() => ({
|
|
60856
|
-
setVisibility: (type, visible) => {
|
|
60857
|
-
overlayRef.current?.setVisibility(type, visible);
|
|
60858
|
-
setState((prev) => ({
|
|
60859
|
-
...prev,
|
|
60860
|
-
visibility: {
|
|
60861
|
-
...prev.visibility,
|
|
60862
|
-
[type]: visible
|
|
60863
|
-
}
|
|
60864
|
-
}));
|
|
60865
|
-
},
|
|
60866
|
-
toggleVisibility: (type) => {
|
|
60867
|
-
overlayRef.current?.toggleVisibility(type);
|
|
60868
|
-
setState((prev) => ({
|
|
60869
|
-
...prev,
|
|
60870
|
-
visibility: {
|
|
60871
|
-
...prev.visibility,
|
|
60872
|
-
[type]: !prev.visibility[type]
|
|
60873
|
-
}
|
|
60874
|
-
}));
|
|
60875
|
-
},
|
|
60876
|
-
setAllVisibility: (visibility) => {
|
|
60877
|
-
overlayRef.current?.setAllVisibility(visibility);
|
|
60878
|
-
setState((prev) => ({
|
|
60879
|
-
...prev,
|
|
60880
|
-
visibility: {
|
|
60881
|
-
...prev.visibility,
|
|
60882
|
-
...visibility
|
|
60883
|
-
}
|
|
60884
|
-
}));
|
|
60885
|
-
},
|
|
60886
|
-
setBoundingBoxes: (pageIndex, boxes) => {
|
|
60887
|
-
overlayRef.current?.setBoundingBoxes(pageIndex, boxes);
|
|
60888
|
-
setState((prev) => {
|
|
60889
|
-
const newBoxes = new Map(prev.boxes);
|
|
60890
|
-
newBoxes.set(pageIndex, boxes);
|
|
60891
|
-
return {
|
|
60892
|
-
...prev,
|
|
60893
|
-
boxes: newBoxes
|
|
60894
|
-
};
|
|
60895
|
-
});
|
|
60896
|
-
},
|
|
60897
|
-
clearBoundingBoxes: (pageIndex) => {
|
|
60898
|
-
overlayRef.current?.clearBoundingBoxes(pageIndex);
|
|
60899
|
-
setState((prev) => {
|
|
60900
|
-
const newBoxes = new Map(prev.boxes);
|
|
60901
|
-
newBoxes.delete(pageIndex);
|
|
60902
|
-
return {
|
|
60903
|
-
...prev,
|
|
60904
|
-
boxes: newBoxes
|
|
60905
|
-
};
|
|
60906
|
-
});
|
|
60907
|
-
},
|
|
60908
|
-
clearAllBoundingBoxes: () => {
|
|
60909
|
-
overlayRef.current?.clearAllBoundingBoxes();
|
|
60910
|
-
setState((prev) => ({
|
|
60911
|
-
...prev,
|
|
60912
|
-
boxes: /* @__PURE__ */ new Map()
|
|
60913
|
-
}));
|
|
60914
|
-
}
|
|
60915
|
-
}), []),
|
|
60916
|
-
overlay: overlayRef.current
|
|
60917
|
-
};
|
|
60918
|
-
}
|
|
60919
|
-
/**
|
|
60920
|
-
* Hook for viewport management.
|
|
60921
|
-
*
|
|
60922
|
-
* Tracks viewport dimensions and provides utilities for coordinate transformation.
|
|
60923
|
-
*/
|
|
60924
|
-
function useViewport(containerRef) {
|
|
60925
|
-
const [dimensions, setDimensions] = useState({
|
|
60926
|
-
width: 0,
|
|
60927
|
-
height: 0
|
|
60928
|
-
});
|
|
60929
|
-
useEffect(() => {
|
|
60930
|
-
const container = containerRef.current;
|
|
60931
|
-
if (!container) return;
|
|
60932
|
-
const updateDimensions = () => {
|
|
60933
|
-
setDimensions({
|
|
60934
|
-
width: container.clientWidth,
|
|
60935
|
-
height: container.clientHeight
|
|
60936
|
-
});
|
|
60937
|
-
};
|
|
60938
|
-
updateDimensions();
|
|
60939
|
-
const resizeObserver = new ResizeObserver(updateDimensions);
|
|
60940
|
-
resizeObserver.observe(container);
|
|
60941
|
-
return () => {
|
|
60942
|
-
resizeObserver.disconnect();
|
|
60943
|
-
};
|
|
60944
|
-
}, [containerRef]);
|
|
60945
|
-
return dimensions;
|
|
60946
|
-
}
|
|
60947
|
-
/**
|
|
60948
|
-
* Hook for scroll position tracking.
|
|
60949
|
-
*/
|
|
60950
|
-
function useScrollPosition(containerRef) {
|
|
60951
|
-
const [position, setPosition] = useState({
|
|
60952
|
-
scrollTop: 0,
|
|
60953
|
-
scrollLeft: 0
|
|
60954
|
-
});
|
|
60955
|
-
useEffect(() => {
|
|
60956
|
-
const container = containerRef.current;
|
|
60957
|
-
if (!container) return;
|
|
60958
|
-
const handleScroll = () => {
|
|
60959
|
-
setPosition({
|
|
60960
|
-
scrollTop: container.scrollTop,
|
|
60961
|
-
scrollLeft: container.scrollLeft
|
|
60962
|
-
});
|
|
60963
|
-
};
|
|
60964
|
-
container.addEventListener("scroll", handleScroll, { passive: true });
|
|
60965
|
-
return () => {
|
|
60966
|
-
container.removeEventListener("scroll", handleScroll);
|
|
60967
|
-
};
|
|
60968
|
-
}, [containerRef]);
|
|
60969
|
-
return position;
|
|
60970
|
-
}
|
|
60971
|
-
|
|
60972
|
-
//#endregion
|
|
60973
|
-
//#region src/react/ReactPDFViewer.tsx
|
|
60974
|
-
/**
|
|
60975
|
-
* ReactPDFViewer - React component wrapper for PDF viewing.
|
|
60976
|
-
*
|
|
60977
|
-
* Provides a complete PDF viewing solution with React integration,
|
|
60978
|
-
* including page rendering, navigation, search, and bounding box visualization.
|
|
60979
|
-
*
|
|
60980
|
-
* @example
|
|
60981
|
-
* ```tsx
|
|
60982
|
-
* import { ReactPDFViewer } from "@libpdf/core/react";
|
|
60983
|
-
*
|
|
60984
|
-
* function App() {
|
|
60985
|
-
* return (
|
|
60986
|
-
* <ReactPDFViewer
|
|
60987
|
-
* url="/document.pdf"
|
|
60988
|
-
* initialScale={1.5}
|
|
60989
|
-
* onPageChange={(page) => console.log('Page:', page)}
|
|
60990
|
-
* />
|
|
60991
|
-
* );
|
|
60992
|
-
* }
|
|
60993
|
-
* ```
|
|
60994
|
-
*/
|
|
60995
|
-
/**
|
|
60996
|
-
* Default styles for the viewer container.
|
|
60997
|
-
*/
|
|
60998
|
-
const defaultContainerStyle = {
|
|
60999
|
-
position: "relative",
|
|
61000
|
-
width: "100%",
|
|
61001
|
-
height: "100%",
|
|
61002
|
-
overflow: "auto",
|
|
61003
|
-
backgroundColor: "#525659"
|
|
61004
|
-
};
|
|
61005
|
-
/**
|
|
61006
|
-
* Default styles for a page container.
|
|
61007
|
-
*/
|
|
61008
|
-
const defaultPageStyle = {
|
|
61009
|
-
position: "relative",
|
|
61010
|
-
margin: "10px auto",
|
|
61011
|
-
backgroundColor: "#fff",
|
|
61012
|
-
boxShadow: "0 2px 10px rgba(0, 0, 0, 0.3)"
|
|
61013
|
-
};
|
|
61014
|
-
/**
|
|
61015
|
-
* ReactPDFViewer component for rendering PDF documents in React applications.
|
|
61016
|
-
*
|
|
61017
|
-
* This component wraps the core PDF viewer infrastructure and provides a React-friendly
|
|
61018
|
-
* API with hooks for state management, search, and bounding box visualization.
|
|
61019
|
-
*
|
|
61020
|
-
* @example
|
|
61021
|
-
* Basic usage with URL:
|
|
61022
|
-
* ```tsx
|
|
61023
|
-
* <ReactPDFViewer url="/path/to/document.pdf" />
|
|
61024
|
-
* ```
|
|
61025
|
-
*
|
|
61026
|
-
* @example
|
|
61027
|
-
* With document instance:
|
|
61028
|
-
* ```tsx
|
|
61029
|
-
* const pdf = await PDF.load(bytes);
|
|
61030
|
-
* <ReactPDFViewer document={pdf} initialScale={1.5} />
|
|
61031
|
-
* ```
|
|
61032
|
-
*
|
|
61033
|
-
* @example
|
|
61034
|
-
* With ref for imperative control:
|
|
61035
|
-
* ```tsx
|
|
61036
|
-
* const viewerRef = useRef<ReactPDFViewerRef>(null);
|
|
61037
|
-
*
|
|
61038
|
-
* // Navigate programmatically
|
|
61039
|
-
* viewerRef.current?.goToPage(5);
|
|
61040
|
-
* viewerRef.current?.zoomIn();
|
|
61041
|
-
*
|
|
61042
|
-
* <ReactPDFViewer ref={viewerRef} url="/document.pdf" />
|
|
61043
|
-
* ```
|
|
61044
|
-
*/
|
|
61045
|
-
const ReactPDFViewer = forwardRef(function ReactPDFViewer$1(props, ref) {
|
|
61046
|
-
const { document: providedDocument, data, url, renderer = "canvas", initialScale = 1, initialPage = 1, initialRotation = 0, scrollMode = "vertical", spreadMode = "none", enableTextLayer = true, enableAnnotationLayer = true, maxConcurrentRenders = 4, cacheSize = 10, className, style, onPageRender, onPageError, onPageChange, onScaleChange, onDocumentLoad, onDocumentError, children } = props;
|
|
61047
|
-
const containerRef = useRef(null);
|
|
61048
|
-
const pagesContainerRef = useRef(null);
|
|
61049
|
-
const [renderedPages, setRenderedPages] = useState(/* @__PURE__ */ new Map());
|
|
61050
|
-
const { state: viewerState, viewer, goToPage, nextPage, previousPage, setScale, zoomIn, zoomOut, setRotation, rotateClockwise, rotateCounterClockwise, setPageState, refresh } = usePDFViewer({
|
|
61051
|
-
document: providedDocument,
|
|
61052
|
-
data,
|
|
61053
|
-
url,
|
|
61054
|
-
initialScale,
|
|
61055
|
-
initialPage,
|
|
61056
|
-
initialRotation,
|
|
61057
|
-
viewerOptions: {
|
|
61058
|
-
renderer,
|
|
61059
|
-
scrollMode,
|
|
61060
|
-
spreadMode,
|
|
61061
|
-
maxConcurrent: maxConcurrentRenders,
|
|
61062
|
-
cacheSize
|
|
61063
|
-
},
|
|
61064
|
-
onDocumentLoad,
|
|
61065
|
-
onDocumentError,
|
|
61066
|
-
onPageChange,
|
|
61067
|
-
onScaleChange
|
|
61068
|
-
});
|
|
61069
|
-
const { state: searchState, actions: searchActions } = usePDFSearch({
|
|
61070
|
-
document: viewerState.document,
|
|
61071
|
-
enabled: true
|
|
61072
|
-
});
|
|
61073
|
-
const { state: bbState, actions: bbActions, overlay } = useBoundingBoxOverlay({ enabled: true });
|
|
61074
|
-
useViewport(containerRef);
|
|
61075
|
-
const renderPage = useCallback(async (pageIndex) => {
|
|
61076
|
-
if (!viewer || !viewerState.document || !viewerState.initialized) return;
|
|
61077
|
-
const pageNumber = pageIndex + 1;
|
|
61078
|
-
setPageState(pageIndex, {
|
|
61079
|
-
pageIndex,
|
|
61080
|
-
state: "rendering",
|
|
61081
|
-
element: null,
|
|
61082
|
-
error: null,
|
|
61083
|
-
viewport: null
|
|
61084
|
-
});
|
|
61085
|
-
try {
|
|
61086
|
-
const result = await viewer.renderPage(pageNumber).promise;
|
|
61087
|
-
const renderedElement = result.element;
|
|
61088
|
-
setRenderedPages((prev) => {
|
|
61089
|
-
const next = new Map(prev);
|
|
61090
|
-
next.set(pageIndex, renderedElement);
|
|
61091
|
-
return next;
|
|
61092
|
-
});
|
|
61093
|
-
setPageState(pageIndex, {
|
|
61094
|
-
pageIndex,
|
|
61095
|
-
state: "rendered",
|
|
61096
|
-
element: renderedElement,
|
|
61097
|
-
error: null,
|
|
61098
|
-
viewport: null
|
|
61099
|
-
});
|
|
61100
|
-
onPageRender?.(pageIndex, result);
|
|
61101
|
-
} catch (error) {
|
|
61102
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
61103
|
-
setPageState(pageIndex, {
|
|
61104
|
-
pageIndex,
|
|
61105
|
-
state: "error",
|
|
61106
|
-
element: null,
|
|
61107
|
-
error: err,
|
|
61108
|
-
viewport: null
|
|
61109
|
-
});
|
|
61110
|
-
onPageError?.(pageIndex, err);
|
|
61111
|
-
}
|
|
61112
|
-
}, [
|
|
61113
|
-
viewer,
|
|
61114
|
-
viewerState.document,
|
|
61115
|
-
viewerState.initialized,
|
|
61116
|
-
setPageState,
|
|
61117
|
-
onPageRender,
|
|
61118
|
-
onPageError
|
|
61119
|
-
]);
|
|
61120
|
-
useEffect(() => {
|
|
61121
|
-
if (!viewerState.document || !viewerState.initialized) return;
|
|
61122
|
-
setRenderedPages(/* @__PURE__ */ new Map());
|
|
61123
|
-
const currentIndex = viewerState.currentPage - 1;
|
|
61124
|
-
const pagesToRender = [currentIndex];
|
|
61125
|
-
if (currentIndex > 0) pagesToRender.push(currentIndex - 1);
|
|
61126
|
-
if (currentIndex < viewerState.pageCount - 1) pagesToRender.push(currentIndex + 1);
|
|
61127
|
-
for (const pageIndex of pagesToRender) renderPage(pageIndex);
|
|
61128
|
-
}, [
|
|
61129
|
-
viewerState.document,
|
|
61130
|
-
viewerState.initialized,
|
|
61131
|
-
viewerState.scale,
|
|
61132
|
-
viewerState.currentPage
|
|
61133
|
-
]);
|
|
61134
|
-
useEffect(() => {
|
|
61135
|
-
const container = pagesContainerRef.current;
|
|
61136
|
-
if (!container) return;
|
|
61137
|
-
const pageElement = container.querySelector(`[data-page-index="${viewerState.currentPage - 1}"]`);
|
|
61138
|
-
if (pageElement) pageElement.scrollIntoView({
|
|
61139
|
-
behavior: "smooth",
|
|
61140
|
-
block: "start"
|
|
61141
|
-
});
|
|
61142
|
-
}, [viewerState.currentPage]);
|
|
61143
|
-
useImperativeHandle(ref, () => ({
|
|
61144
|
-
goToPage,
|
|
61145
|
-
nextPage,
|
|
61146
|
-
previousPage,
|
|
61147
|
-
setScale,
|
|
61148
|
-
zoomIn,
|
|
61149
|
-
zoomOut,
|
|
61150
|
-
setRotation,
|
|
61151
|
-
rotateClockwise,
|
|
61152
|
-
rotateCounterClockwise,
|
|
61153
|
-
refresh,
|
|
61154
|
-
getState: () => viewerState,
|
|
61155
|
-
search: searchActions,
|
|
61156
|
-
boundingBox: bbActions
|
|
61157
|
-
}), [
|
|
61158
|
-
goToPage,
|
|
61159
|
-
nextPage,
|
|
61160
|
-
previousPage,
|
|
61161
|
-
setScale,
|
|
61162
|
-
zoomIn,
|
|
61163
|
-
zoomOut,
|
|
61164
|
-
setRotation,
|
|
61165
|
-
rotateClockwise,
|
|
61166
|
-
rotateCounterClockwise,
|
|
61167
|
-
refresh,
|
|
61168
|
-
viewerState,
|
|
61169
|
-
searchActions,
|
|
61170
|
-
bbActions
|
|
61171
|
-
]);
|
|
61172
|
-
if (viewerState.loading) return /* @__PURE__ */ jsx("div", {
|
|
61173
|
-
ref: containerRef,
|
|
61174
|
-
className,
|
|
61175
|
-
style: {
|
|
61176
|
-
...defaultContainerStyle,
|
|
61177
|
-
...style
|
|
61178
|
-
},
|
|
61179
|
-
role: "document",
|
|
61180
|
-
"aria-busy": "true",
|
|
61181
|
-
"aria-label": "Loading PDF document",
|
|
61182
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
61183
|
-
style: {
|
|
61184
|
-
display: "flex",
|
|
61185
|
-
alignItems: "center",
|
|
61186
|
-
justifyContent: "center",
|
|
61187
|
-
height: "100%",
|
|
61188
|
-
color: "#fff"
|
|
61189
|
-
},
|
|
61190
|
-
children: "Loading..."
|
|
61191
|
-
})
|
|
61192
|
-
});
|
|
61193
|
-
if (viewerState.error) return /* @__PURE__ */ jsx("div", {
|
|
61194
|
-
ref: containerRef,
|
|
61195
|
-
className,
|
|
61196
|
-
style: {
|
|
61197
|
-
...defaultContainerStyle,
|
|
61198
|
-
...style
|
|
61199
|
-
},
|
|
61200
|
-
role: "alert",
|
|
61201
|
-
"aria-label": "PDF loading error",
|
|
61202
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
61203
|
-
style: {
|
|
61204
|
-
display: "flex",
|
|
61205
|
-
alignItems: "center",
|
|
61206
|
-
justifyContent: "center",
|
|
61207
|
-
height: "100%",
|
|
61208
|
-
color: "#ff6b6b",
|
|
61209
|
-
padding: "20px",
|
|
61210
|
-
textAlign: "center"
|
|
61211
|
-
},
|
|
61212
|
-
children: /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
|
|
61213
|
-
style: { marginBottom: "10px" },
|
|
61214
|
-
children: "Failed to load PDF"
|
|
61215
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
61216
|
-
style: {
|
|
61217
|
-
fontSize: "0.875rem",
|
|
61218
|
-
opacity: .8
|
|
61219
|
-
},
|
|
61220
|
-
children: viewerState.error.message
|
|
61221
|
-
})] })
|
|
61222
|
-
})
|
|
61223
|
-
});
|
|
61224
|
-
if (!viewerState.document) return /* @__PURE__ */ jsx("div", {
|
|
61225
|
-
ref: containerRef,
|
|
61226
|
-
className,
|
|
61227
|
-
style: {
|
|
61228
|
-
...defaultContainerStyle,
|
|
61229
|
-
...style
|
|
61230
|
-
},
|
|
61231
|
-
role: "document",
|
|
61232
|
-
"aria-label": "No PDF document loaded",
|
|
61233
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
61234
|
-
style: {
|
|
61235
|
-
display: "flex",
|
|
61236
|
-
alignItems: "center",
|
|
61237
|
-
justifyContent: "center",
|
|
61238
|
-
height: "100%",
|
|
61239
|
-
color: "#888"
|
|
61240
|
-
},
|
|
61241
|
-
children: "No document loaded"
|
|
61242
|
-
})
|
|
61243
|
-
});
|
|
61244
|
-
const getPageDimensions = (pageIndex) => {
|
|
61245
|
-
const page = viewerState.document.getPage(pageIndex);
|
|
61246
|
-
if (!page) return {
|
|
61247
|
-
width: 612 * viewerState.scale,
|
|
61248
|
-
height: 792 * viewerState.scale
|
|
61249
|
-
};
|
|
61250
|
-
return {
|
|
61251
|
-
width: page.width * viewerState.scale,
|
|
61252
|
-
height: page.height * viewerState.scale
|
|
61253
|
-
};
|
|
61254
|
-
};
|
|
61255
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
61256
|
-
ref: containerRef,
|
|
61257
|
-
className,
|
|
61258
|
-
style: {
|
|
61259
|
-
...defaultContainerStyle,
|
|
61260
|
-
...style
|
|
61261
|
-
},
|
|
61262
|
-
role: "document",
|
|
61263
|
-
"aria-label": `PDF document with ${viewerState.pageCount} pages`,
|
|
61264
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
61265
|
-
ref: pagesContainerRef,
|
|
61266
|
-
style: {
|
|
61267
|
-
display: "flex",
|
|
61268
|
-
flexDirection: scrollMode === "horizontal" ? "row" : "column",
|
|
61269
|
-
alignItems: "center",
|
|
61270
|
-
padding: "20px",
|
|
61271
|
-
minHeight: "100%"
|
|
61272
|
-
},
|
|
61273
|
-
children: Array.from({ length: viewerState.pageCount }, (_, pageIndex) => {
|
|
61274
|
-
const dims = getPageDimensions(pageIndex);
|
|
61275
|
-
const renderedElement = renderedPages.get(pageIndex);
|
|
61276
|
-
const pageState = viewerState.pageStates.get(pageIndex);
|
|
61277
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
61278
|
-
"data-page-index": pageIndex,
|
|
61279
|
-
style: {
|
|
61280
|
-
...defaultPageStyle,
|
|
61281
|
-
width: dims.width,
|
|
61282
|
-
height: dims.height
|
|
61283
|
-
},
|
|
61284
|
-
role: "img",
|
|
61285
|
-
"aria-label": `Page ${pageIndex + 1} of ${viewerState.pageCount}`,
|
|
61286
|
-
children: [
|
|
61287
|
-
renderedElement && /* @__PURE__ */ jsx("div", {
|
|
61288
|
-
ref: (el) => {
|
|
61289
|
-
if (el && renderedElement && !el.contains(renderedElement)) {
|
|
61290
|
-
el.innerHTML = "";
|
|
61291
|
-
el.appendChild(renderedElement);
|
|
61292
|
-
}
|
|
61293
|
-
},
|
|
61294
|
-
style: {
|
|
61295
|
-
width: "100%",
|
|
61296
|
-
height: "100%"
|
|
61297
|
-
}
|
|
61298
|
-
}),
|
|
61299
|
-
pageState?.state === "rendering" && /* @__PURE__ */ jsxs("div", {
|
|
61300
|
-
style: {
|
|
61301
|
-
position: "absolute",
|
|
61302
|
-
top: "50%",
|
|
61303
|
-
left: "50%",
|
|
61304
|
-
transform: "translate(-50%, -50%)",
|
|
61305
|
-
color: "#666"
|
|
61306
|
-
},
|
|
61307
|
-
children: [
|
|
61308
|
-
"Loading page ",
|
|
61309
|
-
pageIndex + 1,
|
|
61310
|
-
"..."
|
|
61311
|
-
]
|
|
61312
|
-
}),
|
|
61313
|
-
pageState?.state === "error" && /* @__PURE__ */ jsxs("div", {
|
|
61314
|
-
style: {
|
|
61315
|
-
position: "absolute",
|
|
61316
|
-
top: "50%",
|
|
61317
|
-
left: "50%",
|
|
61318
|
-
transform: "translate(-50%, -50%)",
|
|
61319
|
-
color: "#ff6b6b",
|
|
61320
|
-
textAlign: "center",
|
|
61321
|
-
padding: "10px"
|
|
61322
|
-
},
|
|
61323
|
-
children: [/* @__PURE__ */ jsxs("div", { children: ["Failed to render page ", pageIndex + 1] }), /* @__PURE__ */ jsx("div", {
|
|
61324
|
-
style: {
|
|
61325
|
-
fontSize: "0.75rem",
|
|
61326
|
-
opacity: .8
|
|
61327
|
-
},
|
|
61328
|
-
children: pageState.error?.message
|
|
61329
|
-
})]
|
|
61330
|
-
})
|
|
61331
|
-
]
|
|
61332
|
-
}, pageIndex);
|
|
61333
|
-
})
|
|
61334
|
-
}), children]
|
|
61335
|
-
});
|
|
61336
|
-
});
|
|
61337
|
-
function PageNavigation({ currentPage, pageCount, onPageChange, className, style }) {
|
|
61338
|
-
const [inputValue, setInputValue] = useState(String(currentPage));
|
|
61339
|
-
useEffect(() => {
|
|
61340
|
-
setInputValue(String(currentPage));
|
|
61341
|
-
}, [currentPage]);
|
|
61342
|
-
const handleSubmit = (e) => {
|
|
61343
|
-
e.preventDefault();
|
|
61344
|
-
const page = parseInt(inputValue, 10);
|
|
61345
|
-
if (!isNaN(page) && page >= 1 && page <= pageCount) onPageChange(page);
|
|
61346
|
-
else setInputValue(String(currentPage));
|
|
61347
|
-
};
|
|
61348
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
61349
|
-
className,
|
|
61350
|
-
style,
|
|
61351
|
-
children: [
|
|
61352
|
-
/* @__PURE__ */ jsx("button", {
|
|
61353
|
-
onClick: () => onPageChange(currentPage - 1),
|
|
61354
|
-
disabled: currentPage <= 1,
|
|
61355
|
-
"aria-label": "Previous page",
|
|
61356
|
-
children: "Previous"
|
|
61357
|
-
}),
|
|
61358
|
-
/* @__PURE__ */ jsxs("form", {
|
|
61359
|
-
onSubmit: handleSubmit,
|
|
61360
|
-
style: { display: "inline" },
|
|
61361
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
61362
|
-
type: "text",
|
|
61363
|
-
value: inputValue,
|
|
61364
|
-
onChange: (e) => setInputValue(e.target.value),
|
|
61365
|
-
style: {
|
|
61366
|
-
width: "50px",
|
|
61367
|
-
textAlign: "center"
|
|
61368
|
-
},
|
|
61369
|
-
"aria-label": "Page number"
|
|
61370
|
-
}), /* @__PURE__ */ jsxs("span", { children: [" / ", pageCount] })]
|
|
61371
|
-
}),
|
|
61372
|
-
/* @__PURE__ */ jsx("button", {
|
|
61373
|
-
onClick: () => onPageChange(currentPage + 1),
|
|
61374
|
-
disabled: currentPage >= pageCount,
|
|
61375
|
-
"aria-label": "Next page",
|
|
61376
|
-
children: "Next"
|
|
61377
|
-
})
|
|
61378
|
-
]
|
|
61379
|
-
});
|
|
61380
|
-
}
|
|
61381
|
-
function ZoomControls({ scale, minScale = .25, maxScale = 4, onScaleChange, className, style }) {
|
|
61382
|
-
const handleZoomIn = () => {
|
|
61383
|
-
onScaleChange(Math.min(scale * 1.25, maxScale));
|
|
61384
|
-
};
|
|
61385
|
-
const handleZoomOut = () => {
|
|
61386
|
-
onScaleChange(Math.max(scale / 1.25, minScale));
|
|
61387
|
-
};
|
|
61388
|
-
const handleReset = () => {
|
|
61389
|
-
onScaleChange(1);
|
|
61390
|
-
};
|
|
61391
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
61392
|
-
className,
|
|
61393
|
-
style,
|
|
61394
|
-
children: [
|
|
61395
|
-
/* @__PURE__ */ jsx("button", {
|
|
61396
|
-
onClick: handleZoomOut,
|
|
61397
|
-
disabled: scale <= minScale,
|
|
61398
|
-
"aria-label": "Zoom out",
|
|
61399
|
-
children: "-"
|
|
61400
|
-
}),
|
|
61401
|
-
/* @__PURE__ */ jsxs("span", {
|
|
61402
|
-
style: { margin: "0 10px" },
|
|
61403
|
-
children: [Math.round(scale * 100), "%"]
|
|
61404
|
-
}),
|
|
61405
|
-
/* @__PURE__ */ jsx("button", {
|
|
61406
|
-
onClick: handleZoomIn,
|
|
61407
|
-
disabled: scale >= maxScale,
|
|
61408
|
-
"aria-label": "Zoom in",
|
|
61409
|
-
children: "+"
|
|
61410
|
-
}),
|
|
61411
|
-
/* @__PURE__ */ jsx("button", {
|
|
61412
|
-
onClick: handleReset,
|
|
61413
|
-
style: { marginLeft: "10px" },
|
|
61414
|
-
"aria-label": "Reset zoom",
|
|
61415
|
-
children: "Reset"
|
|
61416
|
-
})
|
|
61417
|
-
]
|
|
61418
|
-
});
|
|
61419
|
-
}
|
|
61420
|
-
function SearchInput({ searchState, searchActions, className, style }) {
|
|
61421
|
-
const [query, setQuery] = useState(searchState.query);
|
|
61422
|
-
const handleSubmit = (e) => {
|
|
61423
|
-
e.preventDefault();
|
|
61424
|
-
searchActions.search(query);
|
|
61425
|
-
};
|
|
61426
|
-
const handleClear = () => {
|
|
61427
|
-
setQuery("");
|
|
61428
|
-
searchActions.clearSearch();
|
|
61429
|
-
};
|
|
61430
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
61431
|
-
className,
|
|
61432
|
-
style,
|
|
61433
|
-
children: [
|
|
61434
|
-
/* @__PURE__ */ jsxs("form", {
|
|
61435
|
-
onSubmit: handleSubmit,
|
|
61436
|
-
style: { display: "inline" },
|
|
61437
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
61438
|
-
type: "text",
|
|
61439
|
-
value: query,
|
|
61440
|
-
onChange: (e) => setQuery(e.target.value),
|
|
61441
|
-
placeholder: "Search...",
|
|
61442
|
-
"aria-label": "Search text"
|
|
61443
|
-
}), /* @__PURE__ */ jsx("button", {
|
|
61444
|
-
type: "submit",
|
|
61445
|
-
disabled: searchState.isSearching,
|
|
61446
|
-
children: "Search"
|
|
61447
|
-
})]
|
|
61448
|
-
}),
|
|
61449
|
-
searchState.results.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
61450
|
-
/* @__PURE__ */ jsxs("span", {
|
|
61451
|
-
style: { margin: "0 10px" },
|
|
61452
|
-
children: [
|
|
61453
|
-
searchState.currentIndex + 1,
|
|
61454
|
-
" / ",
|
|
61455
|
-
searchState.results.length
|
|
61456
|
-
]
|
|
61457
|
-
}),
|
|
61458
|
-
/* @__PURE__ */ jsx("button", {
|
|
61459
|
-
onClick: searchActions.findPrevious,
|
|
61460
|
-
"aria-label": "Previous result",
|
|
61461
|
-
children: "Prev"
|
|
61462
|
-
}),
|
|
61463
|
-
/* @__PURE__ */ jsx("button", {
|
|
61464
|
-
onClick: searchActions.findNext,
|
|
61465
|
-
"aria-label": "Next result",
|
|
61466
|
-
children: "Next"
|
|
61467
|
-
})
|
|
61468
|
-
] }),
|
|
61469
|
-
(query || searchState.results.length > 0) && /* @__PURE__ */ jsx("button", {
|
|
61470
|
-
onClick: handleClear,
|
|
61471
|
-
"aria-label": "Clear search",
|
|
61472
|
-
children: "Clear"
|
|
61473
|
-
})
|
|
61474
|
-
]
|
|
61475
|
-
});
|
|
61476
|
-
}
|
|
61477
|
-
|
|
61478
|
-
//#endregion
|
|
61479
|
-
export { AnnotationFlags, AuthHandler, AuthenticationError as AuthHandlerAuthenticationError, BoundingBoxControls, BoundingBoxOverlay, BundledCMapProvider, CJKCMapLoader, CMap, CMapLoadError, CMapRegistry, CanvasRenderer, CertificateChainError, ColorSpace, ContentStreamProcessor, ContentType, CoordinateTransformer, CryptoKeySigner, DEFAULT_BOUNDING_BOX_BORDER_COLORS, DEFAULT_BOUNDING_BOX_COLORS, DEFAULT_PARSING_TIMEOUTS, DEFAULT_PROGRESS_INTERVAL, DEFAULT_TOGGLE_CONFIGS, DocumentParser, FileReadError, FontManager, GoogleKmsSigner, HierarchicalTextExtractor, HttpError, HttpTimestampAuthority, InvalidFileTypeError, KmsSignerError, LegacyCMapSupport, MAX_ZOOM, MIN_ZOOM, Matrix, NetworkError, ObjectParseError, OverlayManager, P12Signer, PDF, PDFAnnotation, PDFCaretAnnotation, PDFCircleAnnotation, PDFEmbeddedPage, PDFFileAttachmentAnnotation, PDFForm, PDFFreeTextAnnotation, PDFHighlightAnnotation, PDFImage, PDFInkAnnotation, PDFJSRenderer, PDFJSSearchEngine, PDFJSTextLayerBuilder, PDFLineAnnotation, PDFLinkAnnotation, PDFLoadError, PDFMarkupAnnotation, PDFPage, PDFPolygonAnnotation, PDFPolylineAnnotation, PDFPopupAnnotation, PDFResourceLoader, PDFSquareAnnotation, PDFSquigglyAnnotation, PDFStampAnnotation, PDFStrikeOutAnnotation, PDFTextAnnotation, PDFTextMarkupAnnotation, PDFUnderlineAnnotation, PDFUnknownAnnotation, PDFViewer, PDFWorker, PREDEFINED_CMAPS, PageNavigation, ParsingWorkerHost, PathBuilder, PdfArray, PdfBool, PdfDict, PdfName, PdfNull, PdfNumber, PdfRef, PdfStream, PdfString, PdfType, PdfTypeDetector, PermissionDeniedError, PlaceholderError, ProgressTracker, ReactPDFViewer, RecoverableParseError, RenderingPipeline, ResourceLoader, AuthenticationError$1 as ResourceLoaderAuthenticationError, ResourceLoaderError, RetryExhaustedError, RetryLogic, RetryPresets, RevocationError, STANDARD_STAMPS, LineCap as SVGLineCap, LineJoin as SVGLineJoin, SVGRenderer, TextRenderMode as SVGTextRenderMode, SearchEngine, SearchInput, SearchStateManager, SecurityError, SignatureError, SignerError, Standard14Font, StandardFonts, StreamDecodeError, StructureError, TextContentStreamParser, TextExtractor, TextLayerBuilder, TextPositionCalculator, TextState, TimestampError, ToolbarController, UIStateManager, UnrecoverableParseError, ViewportAwareBoundingBoxOverlay, ViewportManager, VirtualScroller, WorkerProxy, XRefParseError, ZoomControls, analyzeContentStream, analyzeFonts, analyzeImages, appearsScanned, black, blue, boxesOverlap, buildPDFJSTextLayer, calculateCenteredOffset, calculateParsingTimeout, cloneTextParams, closeDocument as closePDFJSDocument, cmyk, countFormXObjects, createAnnotation, createBoundingBoxControls, createBoundingBoxOverlay, createCJKCMapLoader, createCMapRegistry, createCanvasRenderer, createContentStreamProcessor, createCoordinateTransformer, createDefaultContentStats, createDefaultFontAnalysis, createDefaultImageAnalysis, createDefaultTextParams, createDeferred, createFontManager, createHierarchicalTextExtractor, createInitialSearchState, createLegacyCMapSupport, createLegacyEncodingCMap, createOverlayManager, createPageViewport as createPDFJSPageViewport, createPDFJSRenderer, createPDFJSSearchEngine, createPDFJSTextLayerBuilder, createPDFResourceLoader, createPDFViewer, createPDFWorker, createParsingWorkerHost, createPdfTypeDetector, createProgressTracker, createRenderingPipeline, createResourceLoader, createSVGRenderer, createSearchEngine, createSearchEvent, createSearchStateManager, createSelectionRect, createTextLayerBuilder, createTokenProvider, createToolbarController, createTransformerForPageContainer, createUIStateManager, createViewportAwareBoundingBoxOverlay, createViewportManager, createVirtualScroller, createWorkerProxy, decodeLegacyByte, decodeLegacyBytes, degrees, detectEnvironment, detectPdfType, extractTransferables, findAllBoxesAtPoint, findBoxesInSelection, generateParsingMessageId, generateParsingTaskId, getCurrentDocument as getCurrentPDFJSDocument, getDefaultRegistry, getDefaultRenderingStrategy, getGlobalFontManager, getImageDimensions, getMousePdfCoordinates, getPDFJS, getPage as getPDFJSPage, getPageCount as getPDFJSPageCount, getTextContent as getPDFJSTextContent, getPlainText, getPrimaryContentType, getRenderingStrategy, getTouchPdfCoordinates, glyphNameToUnicode, grayscale, green, groupCharactersIntoPage, groupCharsIntoLines, hitTestBoundingBoxes, horizontalGap, initializePDFJS, isFormXObject, isPDFJSInitialized, isTextItem as isPDFJSTextItem, isPopupAnnotation, isWidgetAnnotation, isWorkerContext, isWorkerSupported, layoutJustifiedLine, layoutText, lineCapToNumber, lineJoinToNumber, loadPDFFromBytes, loadPDFFromUrl, loadDocument as loadPDFJSDocument, loadDocumentFromUrl as loadPDFJSDocumentFromUrl, loadResource, measureText, mergeBoundingBoxes, mergeContentStats, operators_exports as ops, parseCMapData, parseCMapText, parseDocument, parseDocumentAsync, parsePem, rectToQuadPoints, rectsToQuadPoints, red, rgb, searchDocument as searchPDFJSDocument, searchPage, searchPages, setDefaultRegistry, transformBoundingBoxes, transformScreenRectToPdf, useBoundingBoxOverlay, usePDFSearch, usePDFViewer, useScrollPosition, useViewport, version, verticalGap, white };
|
|
60400
|
+
export { AnnotationFlags, AuthHandler, AuthenticationError as AuthHandlerAuthenticationError, BoundingBoxControls, BoundingBoxOverlay, BundledCMapProvider, CJKCMapLoader, CMap, CMapLoadError, CMapRegistry, CanvasRenderer, CertificateChainError, ColorSpace, ContentStreamProcessor, ContentType, CoordinateTransformer, CryptoKeySigner, DEFAULT_BOUNDING_BOX_BORDER_COLORS, DEFAULT_BOUNDING_BOX_COLORS, DEFAULT_PARSING_TIMEOUTS, DEFAULT_PROGRESS_INTERVAL, DEFAULT_TOGGLE_CONFIGS, DocumentParser, FileReadError, FontManager, GoogleKmsSigner, HierarchicalTextExtractor, HttpError, HttpTimestampAuthority, InvalidFileTypeError, KmsSignerError, LegacyCMapSupport, MAX_ZOOM, MIN_ZOOM, Matrix, NetworkError, ObjectParseError, OverlayManager, P12Signer, PDF, PDFAnnotation, PDFCaretAnnotation, PDFCircleAnnotation, PDFEmbeddedPage, PDFFileAttachmentAnnotation, PDFForm, PDFFreeTextAnnotation, PDFHighlightAnnotation, PDFImage, PDFInkAnnotation, PDFJSRenderer, PDFJSSearchEngine, PDFJSTextLayerBuilder, PDFLineAnnotation, PDFLinkAnnotation, PDFLoadError, PDFMarkupAnnotation, PDFPage, PDFPolygonAnnotation, PDFPolylineAnnotation, PDFPopupAnnotation, PDFResourceLoader, PDFSquareAnnotation, PDFSquigglyAnnotation, PDFStampAnnotation, PDFStrikeOutAnnotation, PDFTextAnnotation, PDFTextMarkupAnnotation, PDFUnderlineAnnotation, PDFUnknownAnnotation, PDFViewer, PDFWorker, PREDEFINED_CMAPS, ParsingWorkerHost, PathBuilder, PdfArray, PdfBool, PdfDict, PdfName, PdfNull, PdfNumber, PdfRef, PdfStream, PdfString, PdfType, PdfTypeDetector, PermissionDeniedError, PlaceholderError, ProgressTracker, RecoverableParseError, RenderingPipeline, ResourceLoader, AuthenticationError$1 as ResourceLoaderAuthenticationError, ResourceLoaderError, RetryExhaustedError, RetryLogic, RetryPresets, RevocationError, STANDARD_STAMPS, LineCap as SVGLineCap, LineJoin as SVGLineJoin, SVGRenderer, TextRenderMode as SVGTextRenderMode, SearchEngine, SearchStateManager, SecurityError, SignatureError, SignerError, Standard14Font, StandardFonts, StreamDecodeError, StructureError, TextContentStreamParser, TextExtractor, TextLayerBuilder, TextPositionCalculator, TextState, TimestampError, ToolbarController, UIStateManager, UnrecoverableParseError, ViewportAwareBoundingBoxOverlay, ViewportManager, VirtualScroller, WorkerProxy, XRefParseError, analyzeContentStream, analyzeFonts, analyzeImages, appearsScanned, black, blue, boxesOverlap, buildPDFJSTextLayer, calculateCenteredOffset, calculateParsingTimeout, cloneTextParams, closeDocument as closePDFJSDocument, cmyk, countFormXObjects, createAnnotation, createBoundingBoxControls, createBoundingBoxOverlay, createCJKCMapLoader, createCMapRegistry, createCanvasRenderer, createContentStreamProcessor, createCoordinateTransformer, createDefaultContentStats, createDefaultFontAnalysis, createDefaultImageAnalysis, createDefaultTextParams, createDeferred, createFontManager, createHierarchicalTextExtractor, createInitialSearchState, createLegacyCMapSupport, createLegacyEncodingCMap, createOverlayManager, createPageViewport as createPDFJSPageViewport, createPDFJSRenderer, createPDFJSSearchEngine, createPDFJSTextLayerBuilder, createPDFResourceLoader, createPDFViewer, createPDFWorker, createParsingWorkerHost, createPdfTypeDetector, createProgressTracker, createRenderingPipeline, createResourceLoader, createSVGRenderer, createSearchEngine, createSearchEvent, createSearchStateManager, createSelectionRect, createTextLayerBuilder, createTokenProvider, createToolbarController, createTransformerForPageContainer, createUIStateManager, createViewportAwareBoundingBoxOverlay, createViewportManager, createVirtualScroller, createWorkerProxy, decodeLegacyByte, decodeLegacyBytes, degrees, detectEnvironment, detectPdfType, extractTransferables, findAllBoxesAtPoint, findBoxesInSelection, generateParsingMessageId, generateParsingTaskId, getCurrentDocument as getCurrentPDFJSDocument, getDefaultRegistry, getDefaultRenderingStrategy, getGlobalFontManager, getImageDimensions, getMousePdfCoordinates, getPDFJS, getPage as getPDFJSPage, getPageCount as getPDFJSPageCount, getTextContent as getPDFJSTextContent, getPlainText, getPrimaryContentType, getRenderingStrategy, getTouchPdfCoordinates, glyphNameToUnicode, grayscale, green, groupCharactersIntoPage, groupCharsIntoLines, hitTestBoundingBoxes, horizontalGap, initializePDFJS, isFormXObject, isPDFJSInitialized, isTextItem as isPDFJSTextItem, isPopupAnnotation, isWidgetAnnotation, isWorkerContext, isWorkerSupported, layoutJustifiedLine, layoutText, lineCapToNumber, lineJoinToNumber, loadPDFFromBytes, loadPDFFromUrl, loadDocument as loadPDFJSDocument, loadDocumentFromUrl as loadPDFJSDocumentFromUrl, loadResource, measureText, mergeBoundingBoxes, mergeContentStats, operators_exports as ops, parseCMapData, parseCMapText, parseDocument, parseDocumentAsync, parsePem, rectToQuadPoints, rectsToQuadPoints, red, rgb, searchDocument as searchPDFJSDocument, searchPage, searchPages, setDefaultRegistry, transformBoundingBoxes, transformScreenRectToPdf, version, verticalGap, white };
|
|
61480
60401
|
//# sourceMappingURL=index.mjs.map
|