pdfjs-reader-core 0.1.2 → 0.1.3
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/dist/index.cjs +66 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +84 -56
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8740,7 +8740,7 @@ var PDFViewerClient_exports = {};
|
|
|
8740
8740
|
__export(PDFViewerClient_exports, {
|
|
8741
8741
|
PDFViewerClient: () => PDFViewerClient
|
|
8742
8742
|
});
|
|
8743
|
-
import { useEffect as useEffect22, useCallback as useCallback32, memo as memo24, useRef as useRef19 } from "react";
|
|
8743
|
+
import { useEffect as useEffect22, useCallback as useCallback32, memo as memo24, useRef as useRef19, useState as useState21 } from "react";
|
|
8744
8744
|
import { jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
8745
8745
|
var PDFViewerInner, PDFViewerClient;
|
|
8746
8746
|
var init_PDFViewerClient = __esm({
|
|
@@ -8773,66 +8773,94 @@ var init_PDFViewerClient = __esm({
|
|
|
8773
8773
|
const { viewerStore } = usePDFViewerStores();
|
|
8774
8774
|
const loadingRef = useRef19(false);
|
|
8775
8775
|
const srcRef = useRef19(src);
|
|
8776
|
+
const onDocumentLoadRef = useRef19(onDocumentLoad);
|
|
8777
|
+
const onErrorRef = useRef19(onError);
|
|
8778
|
+
const onPageChangeRef = useRef19(onPageChange);
|
|
8779
|
+
const onScaleChangeRef = useRef19(onScaleChange);
|
|
8780
|
+
onDocumentLoadRef.current = onDocumentLoad;
|
|
8781
|
+
onErrorRef.current = onError;
|
|
8782
|
+
onPageChangeRef.current = onPageChange;
|
|
8783
|
+
onScaleChangeRef.current = onScaleChange;
|
|
8776
8784
|
const currentPage = useViewerStore((s) => s.currentPage);
|
|
8777
8785
|
const scale = useViewerStore((s) => s.scale);
|
|
8778
8786
|
const theme = useViewerStore((s) => s.theme);
|
|
8779
8787
|
const isLoading = useViewerStore((s) => s.isLoading);
|
|
8780
8788
|
const error = useViewerStore((s) => s.error);
|
|
8781
8789
|
const sidebarOpen = useViewerStore((s) => s.sidebarOpen);
|
|
8782
|
-
const
|
|
8783
|
-
|
|
8784
|
-
loadingRef.current =
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
src,
|
|
8790
|
-
workerSrc
|
|
8791
|
-
});
|
|
8792
|
-
if (srcRef.current === src) {
|
|
8793
|
-
viewerStore.getState().setDocument(document2);
|
|
8794
|
-
if (initialPage !== 1) {
|
|
8795
|
-
viewerStore.getState().goToPage(initialPage);
|
|
8796
|
-
}
|
|
8797
|
-
if (typeof initialScale === "number" && initialScale !== 1) {
|
|
8798
|
-
viewerStore.getState().setScale(initialScale);
|
|
8799
|
-
}
|
|
8800
|
-
onDocumentLoad?.({ document: document2, numPages });
|
|
8801
|
-
} else {
|
|
8802
|
-
document2.destroy();
|
|
8803
|
-
}
|
|
8804
|
-
} catch (err) {
|
|
8805
|
-
if (srcRef.current === src) {
|
|
8806
|
-
const error2 = err instanceof Error ? err : new Error("Failed to load document");
|
|
8807
|
-
viewerStore.getState().setError(error2);
|
|
8808
|
-
onError?.(error2);
|
|
8809
|
-
}
|
|
8810
|
-
} finally {
|
|
8811
|
-
loadingRef.current = false;
|
|
8812
|
-
}
|
|
8813
|
-
}, [src, workerSrc, initialPage, initialScale, onDocumentLoad, onError, viewerStore]);
|
|
8790
|
+
const [retryTrigger, setRetryTrigger] = useState21(0);
|
|
8791
|
+
const handleRetry = useCallback32(() => {
|
|
8792
|
+
loadingRef.current = false;
|
|
8793
|
+
srcRef.current = null;
|
|
8794
|
+
viewerStore.getState().setError(null);
|
|
8795
|
+
setRetryTrigger((c) => c + 1);
|
|
8796
|
+
}, [viewerStore, src]);
|
|
8814
8797
|
useEffect22(() => {
|
|
8798
|
+
if (loadingRef.current) {
|
|
8799
|
+
return;
|
|
8800
|
+
}
|
|
8801
|
+
if (srcRef.current === src && viewerStore.getState().document) {
|
|
8802
|
+
return;
|
|
8803
|
+
}
|
|
8815
8804
|
srcRef.current = src;
|
|
8805
|
+
loadingRef.current = true;
|
|
8816
8806
|
const currentDoc = viewerStore.getState().document;
|
|
8817
8807
|
if (currentDoc) {
|
|
8818
8808
|
viewerStore.getState().reset();
|
|
8819
8809
|
}
|
|
8810
|
+
const loadDoc = async () => {
|
|
8811
|
+
try {
|
|
8812
|
+
viewerStore.getState().setLoading(true);
|
|
8813
|
+
viewerStore.getState().setError(null);
|
|
8814
|
+
const { document: document2, numPages } = await loadDocument({
|
|
8815
|
+
src,
|
|
8816
|
+
workerSrc
|
|
8817
|
+
});
|
|
8818
|
+
if (srcRef.current === src) {
|
|
8819
|
+
viewerStore.getState().setDocument(document2);
|
|
8820
|
+
if (initialPage !== 1) {
|
|
8821
|
+
viewerStore.getState().goToPage(initialPage);
|
|
8822
|
+
}
|
|
8823
|
+
if (typeof initialScale === "number" && initialScale !== 1) {
|
|
8824
|
+
viewerStore.getState().setScale(initialScale);
|
|
8825
|
+
}
|
|
8826
|
+
onDocumentLoadRef.current?.({ document: document2, numPages });
|
|
8827
|
+
} else {
|
|
8828
|
+
document2.destroy();
|
|
8829
|
+
}
|
|
8830
|
+
} catch (err) {
|
|
8831
|
+
if (srcRef.current === src) {
|
|
8832
|
+
const error2 = err instanceof Error ? err : new Error("Failed to load document");
|
|
8833
|
+
viewerStore.getState().setError(error2);
|
|
8834
|
+
onErrorRef.current?.(error2);
|
|
8835
|
+
}
|
|
8836
|
+
} finally {
|
|
8837
|
+
loadingRef.current = false;
|
|
8838
|
+
}
|
|
8839
|
+
};
|
|
8820
8840
|
loadDoc();
|
|
8821
8841
|
return () => {
|
|
8822
8842
|
srcRef.current = null;
|
|
8823
8843
|
};
|
|
8824
|
-
}, [src,
|
|
8844
|
+
}, [src, workerSrc, initialPage, initialScale, viewerStore, retryTrigger]);
|
|
8825
8845
|
useEffect22(() => {
|
|
8826
8846
|
return () => {
|
|
8827
8847
|
viewerStore.getState().reset();
|
|
8828
8848
|
};
|
|
8829
8849
|
}, [viewerStore]);
|
|
8850
|
+
const prevPageRef = useRef19(currentPage);
|
|
8830
8851
|
useEffect22(() => {
|
|
8831
|
-
|
|
8832
|
-
|
|
8852
|
+
if (prevPageRef.current !== currentPage) {
|
|
8853
|
+
prevPageRef.current = currentPage;
|
|
8854
|
+
onPageChangeRef.current?.(currentPage);
|
|
8855
|
+
}
|
|
8856
|
+
}, [currentPage]);
|
|
8857
|
+
const prevScaleRef = useRef19(scale);
|
|
8833
8858
|
useEffect22(() => {
|
|
8834
|
-
|
|
8835
|
-
|
|
8859
|
+
if (prevScaleRef.current !== scale) {
|
|
8860
|
+
prevScaleRef.current = scale;
|
|
8861
|
+
onScaleChangeRef.current?.(scale);
|
|
8862
|
+
}
|
|
8863
|
+
}, [scale]);
|
|
8836
8864
|
const themeClass = theme === "dark" ? "dark" : "";
|
|
8837
8865
|
if (error) {
|
|
8838
8866
|
return /* @__PURE__ */ jsx25(
|
|
@@ -8851,7 +8879,7 @@ var init_PDFViewerClient = __esm({
|
|
|
8851
8879
|
/* @__PURE__ */ jsx25(
|
|
8852
8880
|
"button",
|
|
8853
8881
|
{
|
|
8854
|
-
onClick:
|
|
8882
|
+
onClick: handleRetry,
|
|
8855
8883
|
className: "mt-4 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600",
|
|
8856
8884
|
children: "Retry"
|
|
8857
8885
|
}
|
|
@@ -8973,7 +9001,7 @@ init_AnnotationToolbar2();
|
|
|
8973
9001
|
|
|
8974
9002
|
// src/components/Annotations/StickyNote.tsx
|
|
8975
9003
|
init_utils();
|
|
8976
|
-
import { memo as memo26, useState as
|
|
9004
|
+
import { memo as memo26, useState as useState22, useRef as useRef20, useEffect as useEffect23, useCallback as useCallback33 } from "react";
|
|
8977
9005
|
import { jsx as jsx27, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
8978
9006
|
var NOTE_COLORS = [
|
|
8979
9007
|
"#fef08a",
|
|
@@ -9000,8 +9028,8 @@ var StickyNote = memo26(function StickyNote2({
|
|
|
9000
9028
|
onDragStart,
|
|
9001
9029
|
className
|
|
9002
9030
|
}) {
|
|
9003
|
-
const [isExpanded, setIsExpanded] =
|
|
9004
|
-
const [localContent, setLocalContent] =
|
|
9031
|
+
const [isExpanded, setIsExpanded] = useState22(false);
|
|
9032
|
+
const [localContent, setLocalContent] = useState22(note.content);
|
|
9005
9033
|
const textareaRef = useRef20(null);
|
|
9006
9034
|
const noteRef = useRef20(null);
|
|
9007
9035
|
useEffect23(() => {
|
|
@@ -9190,7 +9218,7 @@ var StickyNote = memo26(function StickyNote2({
|
|
|
9190
9218
|
|
|
9191
9219
|
// src/components/Annotations/DrawingCanvas.tsx
|
|
9192
9220
|
init_utils();
|
|
9193
|
-
import { memo as memo27, useRef as useRef21, useCallback as useCallback34, useState as
|
|
9221
|
+
import { memo as memo27, useRef as useRef21, useCallback as useCallback34, useState as useState23 } from "react";
|
|
9194
9222
|
import { jsx as jsx28 } from "react/jsx-runtime";
|
|
9195
9223
|
function pointsToSvgPath(points) {
|
|
9196
9224
|
if (points.length === 0) return "";
|
|
@@ -9240,8 +9268,8 @@ var DrawingCanvas = memo27(function DrawingCanvas2({
|
|
|
9240
9268
|
className
|
|
9241
9269
|
}) {
|
|
9242
9270
|
const svgRef = useRef21(null);
|
|
9243
|
-
const [isDrawing, setIsDrawing] =
|
|
9244
|
-
const [currentPath, setCurrentPath] =
|
|
9271
|
+
const [isDrawing, setIsDrawing] = useState23(false);
|
|
9272
|
+
const [currentPath, setCurrentPath] = useState23([]);
|
|
9245
9273
|
const getPoint = useCallback34((e) => {
|
|
9246
9274
|
if (!svgRef.current) return null;
|
|
9247
9275
|
const svg = svgRef.current;
|
|
@@ -9324,7 +9352,7 @@ var DrawingCanvas = memo27(function DrawingCanvas2({
|
|
|
9324
9352
|
|
|
9325
9353
|
// src/components/Annotations/ShapeRenderer.tsx
|
|
9326
9354
|
init_utils();
|
|
9327
|
-
import { memo as memo28, useCallback as useCallback35, useState as
|
|
9355
|
+
import { memo as memo28, useCallback as useCallback35, useState as useState24, useRef as useRef22 } from "react";
|
|
9328
9356
|
import { jsx as jsx29, jsxs as jsxs24 } from "react/jsx-runtime";
|
|
9329
9357
|
var ShapeRenderer = memo28(function ShapeRenderer2({
|
|
9330
9358
|
shape,
|
|
@@ -9336,9 +9364,9 @@ var ShapeRenderer = memo28(function ShapeRenderer2({
|
|
|
9336
9364
|
onDelete: _onDelete,
|
|
9337
9365
|
className
|
|
9338
9366
|
}) {
|
|
9339
|
-
const [_isDragging, setIsDragging] =
|
|
9340
|
-
const [_isResizing, setIsResizing] =
|
|
9341
|
-
const [activeHandle, setActiveHandle] =
|
|
9367
|
+
const [_isDragging, setIsDragging] = useState24(false);
|
|
9368
|
+
const [_isResizing, setIsResizing] = useState24(false);
|
|
9369
|
+
const [activeHandle, setActiveHandle] = useState24(null);
|
|
9342
9370
|
const startPosRef = useRef22({ x: 0, y: 0 });
|
|
9343
9371
|
const startShapeRef = useRef22({ x: 0, y: 0, width: 0, height: 0 });
|
|
9344
9372
|
const { shapeType, x, y, width, height, color, strokeWidth, id: _id } = shape;
|
|
@@ -9629,7 +9657,7 @@ var ShapePreview = memo28(function ShapePreview2({
|
|
|
9629
9657
|
|
|
9630
9658
|
// src/components/Annotations/QuickNoteButton.tsx
|
|
9631
9659
|
init_utils();
|
|
9632
|
-
import { memo as memo29, useCallback as useCallback36, useState as
|
|
9660
|
+
import { memo as memo29, useCallback as useCallback36, useState as useState25 } from "react";
|
|
9633
9661
|
import { jsx as jsx30 } from "react/jsx-runtime";
|
|
9634
9662
|
var QuickNoteButton = memo29(function QuickNoteButton2({
|
|
9635
9663
|
pageNumber,
|
|
@@ -9639,7 +9667,7 @@ var QuickNoteButton = memo29(function QuickNoteButton2({
|
|
|
9639
9667
|
className,
|
|
9640
9668
|
visible = true
|
|
9641
9669
|
}) {
|
|
9642
|
-
const [isHovered, setIsHovered] =
|
|
9670
|
+
const [isHovered, setIsHovered] = useState25(false);
|
|
9643
9671
|
const handleClick = useCallback36(
|
|
9644
9672
|
(e) => {
|
|
9645
9673
|
e.stopPropagation();
|
|
@@ -9691,7 +9719,7 @@ var QuickNoteButton = memo29(function QuickNoteButton2({
|
|
|
9691
9719
|
|
|
9692
9720
|
// src/components/Annotations/QuickNotePopover.tsx
|
|
9693
9721
|
init_utils();
|
|
9694
|
-
import { memo as memo30, useCallback as useCallback37, useState as
|
|
9722
|
+
import { memo as memo30, useCallback as useCallback37, useState as useState26, useRef as useRef23, useEffect as useEffect24 } from "react";
|
|
9695
9723
|
import { jsx as jsx31, jsxs as jsxs25 } from "react/jsx-runtime";
|
|
9696
9724
|
var QuickNotePopover = memo30(function QuickNotePopover2({
|
|
9697
9725
|
visible,
|
|
@@ -9702,10 +9730,10 @@ var QuickNotePopover = memo30(function QuickNotePopover2({
|
|
|
9702
9730
|
onCancel,
|
|
9703
9731
|
className
|
|
9704
9732
|
}) {
|
|
9705
|
-
const [content, setContent] =
|
|
9733
|
+
const [content, setContent] = useState26(initialContent);
|
|
9706
9734
|
const textareaRef = useRef23(null);
|
|
9707
9735
|
const popoverRef = useRef23(null);
|
|
9708
|
-
const [adjustedPosition, setAdjustedPosition] =
|
|
9736
|
+
const [adjustedPosition, setAdjustedPosition] = useState26(position);
|
|
9709
9737
|
useEffect24(() => {
|
|
9710
9738
|
if (visible && textareaRef.current) {
|
|
9711
9739
|
textareaRef.current.focus();
|
|
@@ -9957,7 +9985,7 @@ var AskAboutOverlay = memo31(function AskAboutOverlay2({
|
|
|
9957
9985
|
|
|
9958
9986
|
// src/components/AskAbout/AskAboutTrigger.tsx
|
|
9959
9987
|
init_utils();
|
|
9960
|
-
import { memo as memo32, useCallback as useCallback38, useState as
|
|
9988
|
+
import { memo as memo32, useCallback as useCallback38, useState as useState27, useRef as useRef24, useEffect as useEffect25 } from "react";
|
|
9961
9989
|
import { jsx as jsx33, jsxs as jsxs27 } from "react/jsx-runtime";
|
|
9962
9990
|
var AskAboutTrigger = memo32(function AskAboutTrigger2({
|
|
9963
9991
|
position,
|
|
@@ -9967,7 +9995,7 @@ var AskAboutTrigger = memo32(function AskAboutTrigger2({
|
|
|
9967
9995
|
autoHideDelay = 5e3,
|
|
9968
9996
|
className
|
|
9969
9997
|
}) {
|
|
9970
|
-
const [adjustedPosition, setAdjustedPosition] =
|
|
9998
|
+
const [adjustedPosition, setAdjustedPosition] = useState27(position);
|
|
9971
9999
|
const triggerRef = useRef24(null);
|
|
9972
10000
|
useEffect25(() => {
|
|
9973
10001
|
if (!visible || !triggerRef.current) return;
|