pdfjs-reader-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/dist/index.cjs +240 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +240 -123
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -78,10 +78,13 @@ async function loadDocument(options) {
|
|
|
78
78
|
const cachedDoc = documentCache.get(cacheKey);
|
|
79
79
|
try {
|
|
80
80
|
const numPages = cachedDoc.numPages;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
if (numPages > 0) {
|
|
82
|
+
await cachedDoc.getPage(1);
|
|
83
|
+
return {
|
|
84
|
+
document: cachedDoc,
|
|
85
|
+
numPages
|
|
86
|
+
};
|
|
87
|
+
}
|
|
85
88
|
} catch {
|
|
86
89
|
documentCache.delete(cacheKey);
|
|
87
90
|
}
|
|
@@ -159,6 +162,20 @@ async function getOutline(document2) {
|
|
|
159
162
|
async function getMetadata(document2) {
|
|
160
163
|
return document2.getMetadata();
|
|
161
164
|
}
|
|
165
|
+
function clearDocumentCache(url) {
|
|
166
|
+
if (url) {
|
|
167
|
+
const doc = documentCache.get(url);
|
|
168
|
+
if (doc) {
|
|
169
|
+
doc.destroy();
|
|
170
|
+
documentCache.delete(url);
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
for (const doc of documentCache.values()) {
|
|
174
|
+
doc.destroy();
|
|
175
|
+
}
|
|
176
|
+
documentCache.clear();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
162
179
|
var documentCache;
|
|
163
180
|
var init_document_loader = __esm({
|
|
164
181
|
"src/utils/document-loader.ts"() {
|
|
@@ -7736,22 +7753,16 @@ function formatBytes(bytes) {
|
|
|
7736
7753
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
7737
7754
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
7738
7755
|
}
|
|
7739
|
-
var phaseMessages,
|
|
7756
|
+
var phaseMessages, PDFLoadingScreen;
|
|
7740
7757
|
var init_PDFLoadingScreen = __esm({
|
|
7741
7758
|
"src/components/PDFLoadingScreen/PDFLoadingScreen.tsx"() {
|
|
7742
7759
|
"use strict";
|
|
7743
7760
|
init_utils();
|
|
7744
7761
|
phaseMessages = {
|
|
7745
|
-
initializing: "Preparing viewer
|
|
7746
|
-
fetching: "Loading document
|
|
7747
|
-
parsing: "Processing pages
|
|
7748
|
-
rendering: "Almost ready
|
|
7749
|
-
};
|
|
7750
|
-
phaseIcons = {
|
|
7751
|
-
initializing: "\u2699\uFE0F",
|
|
7752
|
-
fetching: "\u{1F4C4}",
|
|
7753
|
-
parsing: "\u{1F4D1}",
|
|
7754
|
-
rendering: "\u2728"
|
|
7762
|
+
initializing: "Preparing viewer",
|
|
7763
|
+
fetching: "Loading document",
|
|
7764
|
+
parsing: "Processing pages",
|
|
7765
|
+
rendering: "Almost ready"
|
|
7755
7766
|
};
|
|
7756
7767
|
PDFLoadingScreen = memo18(function PDFLoadingScreen2({
|
|
7757
7768
|
progress,
|
|
@@ -7768,122 +7779,219 @@ var init_PDFLoadingScreen = __esm({
|
|
|
7768
7779
|
{
|
|
7769
7780
|
className: cn(
|
|
7770
7781
|
"pdf-loading-screen",
|
|
7771
|
-
"flex flex-col items-center justify-center",
|
|
7772
|
-
"w-full h-full min-h-[400px]",
|
|
7773
|
-
"bg-gradient-to-b from-slate-50 to-slate-100",
|
|
7774
|
-
"dark:from-slate-900 dark:to-slate-800",
|
|
7775
7782
|
className
|
|
7776
7783
|
),
|
|
7784
|
+
style: {
|
|
7785
|
+
display: "flex",
|
|
7786
|
+
flexDirection: "column",
|
|
7787
|
+
alignItems: "center",
|
|
7788
|
+
justifyContent: "center",
|
|
7789
|
+
width: "100%",
|
|
7790
|
+
height: "100%",
|
|
7791
|
+
minHeight: "400px",
|
|
7792
|
+
background: "linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%)",
|
|
7793
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
|
|
7794
|
+
},
|
|
7777
7795
|
role: "status",
|
|
7778
7796
|
"aria-live": "polite",
|
|
7779
7797
|
"aria-label": phaseMessages[phase],
|
|
7780
|
-
children: /* @__PURE__ */ jsxs16(
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
"
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
"ellipse",
|
|
7795
|
-
{
|
|
7796
|
-
cx: "32",
|
|
7797
|
-
cy: "76",
|
|
7798
|
-
rx: "24",
|
|
7799
|
-
ry: "4",
|
|
7800
|
-
className: "fill-slate-200 dark:fill-slate-700",
|
|
7801
|
-
opacity: "0.5"
|
|
7802
|
-
}
|
|
7803
|
-
),
|
|
7804
|
-
/* @__PURE__ */ jsx19(
|
|
7805
|
-
"path",
|
|
7806
|
-
{
|
|
7807
|
-
d: "M8 4C8 1.79086 9.79086 0 12 0H40L56 16V72C56 74.2091 54.2091 76 52 76H12C9.79086 76 8 74.2091 8 72V4Z",
|
|
7808
|
-
className: "fill-white dark:fill-slate-700"
|
|
7809
|
-
}
|
|
7810
|
-
),
|
|
7811
|
-
/* @__PURE__ */ jsx19(
|
|
7812
|
-
"path",
|
|
7813
|
-
{
|
|
7814
|
-
d: "M40 0L56 16H44C41.7909 16 40 14.2091 40 12V0Z",
|
|
7815
|
-
className: "fill-blue-100 dark:fill-blue-900"
|
|
7816
|
-
}
|
|
7817
|
-
),
|
|
7818
|
-
/* @__PURE__ */ jsx19(
|
|
7819
|
-
"rect",
|
|
7820
|
-
{
|
|
7821
|
-
x: "14",
|
|
7822
|
-
y: "28",
|
|
7823
|
-
width: "28",
|
|
7824
|
-
height: "12",
|
|
7825
|
-
rx: "2",
|
|
7826
|
-
className: "fill-blue-500 dark:fill-blue-400"
|
|
7827
|
-
}
|
|
7828
|
-
),
|
|
7829
|
-
/* @__PURE__ */ jsx19(
|
|
7830
|
-
"text",
|
|
7831
|
-
{
|
|
7832
|
-
x: "28",
|
|
7833
|
-
y: "37",
|
|
7834
|
-
textAnchor: "middle",
|
|
7835
|
-
className: "fill-white text-[8px] font-bold",
|
|
7836
|
-
style: { fontSize: "8px", fontWeight: 700 },
|
|
7837
|
-
children: "PDF"
|
|
7838
|
-
}
|
|
7839
|
-
),
|
|
7840
|
-
/* @__PURE__ */ jsx19("rect", { x: "14", y: "48", width: "28", height: "3", rx: "1.5", className: "pdf-line-1 fill-slate-200 dark:fill-slate-600" }),
|
|
7841
|
-
/* @__PURE__ */ jsx19("rect", { x: "14", y: "54", width: "22", height: "3", rx: "1.5", className: "pdf-line-2 fill-slate-200 dark:fill-slate-600" }),
|
|
7842
|
-
/* @__PURE__ */ jsx19("rect", { x: "14", y: "60", width: "18", height: "3", rx: "1.5", className: "pdf-line-3 fill-slate-200 dark:fill-slate-600" }),
|
|
7843
|
-
/* @__PURE__ */ jsx19(
|
|
7844
|
-
"path",
|
|
7845
|
-
{
|
|
7846
|
-
d: "M8 4C8 1.79086 9.79086 0 12 0H40L56 16V72C56 74.2091 54.2091 76 52 76H12C9.79086 76 8 74.2091 8 72V4Z",
|
|
7847
|
-
className: "stroke-slate-200 dark:stroke-slate-600",
|
|
7848
|
-
strokeWidth: "1.5",
|
|
7849
|
-
fill: "none"
|
|
7850
|
-
}
|
|
7851
|
-
)
|
|
7852
|
-
]
|
|
7853
|
-
}
|
|
7854
|
-
) })
|
|
7855
|
-
] }),
|
|
7856
|
-
/* @__PURE__ */ jsxs16("div", { className: "pdf-loading-info", children: [
|
|
7857
|
-
documentName && /* @__PURE__ */ jsx19("p", { className: "pdf-loading-document-name", children: documentName }),
|
|
7858
|
-
/* @__PURE__ */ jsxs16("div", { className: "pdf-loading-message-wrapper", children: [
|
|
7859
|
-
/* @__PURE__ */ jsx19("span", { className: "pdf-loading-phase-icon", children: phaseIcons[phase] }),
|
|
7860
|
-
/* @__PURE__ */ jsx19("p", { className: "pdf-loading-message", children: phaseMessages[phase] })
|
|
7861
|
-
] }),
|
|
7862
|
-
/* @__PURE__ */ jsxs16("div", { className: "pdf-loading-progress-container", children: [
|
|
7863
|
-
/* @__PURE__ */ jsx19("div", { className: "pdf-loading-progress-track", children: /* @__PURE__ */ jsx19(
|
|
7798
|
+
children: /* @__PURE__ */ jsxs16(
|
|
7799
|
+
"div",
|
|
7800
|
+
{
|
|
7801
|
+
style: {
|
|
7802
|
+
display: "flex",
|
|
7803
|
+
flexDirection: "column",
|
|
7804
|
+
alignItems: "center",
|
|
7805
|
+
padding: "48px 40px",
|
|
7806
|
+
background: "white",
|
|
7807
|
+
borderRadius: "20px",
|
|
7808
|
+
boxShadow: "0 10px 40px -10px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05)"
|
|
7809
|
+
},
|
|
7810
|
+
children: [
|
|
7811
|
+
/* @__PURE__ */ jsxs16(
|
|
7864
7812
|
"div",
|
|
7865
7813
|
{
|
|
7866
|
-
className:
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7814
|
+
className: "pdf-loading-icon-container",
|
|
7815
|
+
style: {
|
|
7816
|
+
position: "relative",
|
|
7817
|
+
marginBottom: "32px"
|
|
7818
|
+
},
|
|
7819
|
+
children: [
|
|
7820
|
+
/* @__PURE__ */ jsx19(
|
|
7821
|
+
"div",
|
|
7822
|
+
{
|
|
7823
|
+
className: "pdf-loading-glow",
|
|
7824
|
+
style: {
|
|
7825
|
+
position: "absolute",
|
|
7826
|
+
top: "50%",
|
|
7827
|
+
left: "50%",
|
|
7828
|
+
width: "120px",
|
|
7829
|
+
height: "120px",
|
|
7830
|
+
transform: "translate(-50%, -50%)",
|
|
7831
|
+
background: "radial-gradient(circle, rgba(59, 130, 246, 0.15) 0%, transparent 70%)",
|
|
7832
|
+
borderRadius: "50%"
|
|
7833
|
+
}
|
|
7834
|
+
}
|
|
7835
|
+
),
|
|
7836
|
+
/* @__PURE__ */ jsxs16(
|
|
7837
|
+
"svg",
|
|
7838
|
+
{
|
|
7839
|
+
width: "72",
|
|
7840
|
+
height: "88",
|
|
7841
|
+
viewBox: "0 0 72 88",
|
|
7842
|
+
fill: "none",
|
|
7843
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
7844
|
+
className: "pdf-document-icon",
|
|
7845
|
+
style: {
|
|
7846
|
+
position: "relative",
|
|
7847
|
+
zIndex: 1,
|
|
7848
|
+
filter: "drop-shadow(0 8px 16px rgba(0, 0, 0, 0.1))"
|
|
7849
|
+
},
|
|
7850
|
+
children: [
|
|
7851
|
+
/* @__PURE__ */ jsx19(
|
|
7852
|
+
"path",
|
|
7853
|
+
{
|
|
7854
|
+
d: "M4 8C4 3.58172 7.58172 0 12 0H44L68 24V80C68 84.4183 64.4183 88 60 88H12C7.58172 88 4 84.4183 4 80V8Z",
|
|
7855
|
+
fill: "#ffffff",
|
|
7856
|
+
stroke: "#e2e8f0",
|
|
7857
|
+
strokeWidth: "2"
|
|
7858
|
+
}
|
|
7859
|
+
),
|
|
7860
|
+
/* @__PURE__ */ jsx19(
|
|
7861
|
+
"path",
|
|
7862
|
+
{
|
|
7863
|
+
d: "M44 0L68 24H52C47.5817 24 44 20.4183 44 16V0Z",
|
|
7864
|
+
fill: "#dbeafe"
|
|
7865
|
+
}
|
|
7866
|
+
),
|
|
7867
|
+
/* @__PURE__ */ jsx19(
|
|
7868
|
+
"rect",
|
|
7869
|
+
{
|
|
7870
|
+
x: "14",
|
|
7871
|
+
y: "36",
|
|
7872
|
+
width: "44",
|
|
7873
|
+
height: "20",
|
|
7874
|
+
rx: "4",
|
|
7875
|
+
fill: "#3b82f6"
|
|
7876
|
+
}
|
|
7877
|
+
),
|
|
7878
|
+
/* @__PURE__ */ jsx19(
|
|
7879
|
+
"text",
|
|
7880
|
+
{
|
|
7881
|
+
x: "36",
|
|
7882
|
+
y: "50",
|
|
7883
|
+
textAnchor: "middle",
|
|
7884
|
+
fill: "white",
|
|
7885
|
+
style: {
|
|
7886
|
+
fontSize: "12px",
|
|
7887
|
+
fontWeight: 700,
|
|
7888
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
|
|
7889
|
+
},
|
|
7890
|
+
children: "PDF"
|
|
7891
|
+
}
|
|
7892
|
+
),
|
|
7893
|
+
/* @__PURE__ */ jsx19("rect", { className: "pdf-line-1", x: "14", y: "64", width: "44", height: "4", rx: "2", fill: "#e2e8f0" }),
|
|
7894
|
+
/* @__PURE__ */ jsx19("rect", { className: "pdf-line-2", x: "14", y: "72", width: "32", height: "4", rx: "2", fill: "#e2e8f0" })
|
|
7895
|
+
]
|
|
7896
|
+
}
|
|
7897
|
+
)
|
|
7898
|
+
]
|
|
7871
7899
|
}
|
|
7872
|
-
)
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7900
|
+
),
|
|
7901
|
+
documentName && /* @__PURE__ */ jsx19(
|
|
7902
|
+
"p",
|
|
7903
|
+
{
|
|
7904
|
+
style: {
|
|
7905
|
+
fontSize: "13px",
|
|
7906
|
+
fontWeight: 500,
|
|
7907
|
+
color: "#64748b",
|
|
7908
|
+
marginBottom: "8px",
|
|
7909
|
+
maxWidth: "240px",
|
|
7910
|
+
overflow: "hidden",
|
|
7911
|
+
textOverflow: "ellipsis",
|
|
7912
|
+
whiteSpace: "nowrap",
|
|
7913
|
+
textAlign: "center"
|
|
7914
|
+
},
|
|
7915
|
+
children: documentName
|
|
7916
|
+
}
|
|
7917
|
+
),
|
|
7918
|
+
/* @__PURE__ */ jsxs16(
|
|
7919
|
+
"p",
|
|
7920
|
+
{
|
|
7921
|
+
style: {
|
|
7922
|
+
fontSize: "16px",
|
|
7923
|
+
fontWeight: 600,
|
|
7924
|
+
color: "#1e293b",
|
|
7925
|
+
marginBottom: "24px",
|
|
7926
|
+
textAlign: "center"
|
|
7927
|
+
},
|
|
7928
|
+
children: [
|
|
7929
|
+
phaseMessages[phase],
|
|
7930
|
+
/* @__PURE__ */ jsxs16("span", { className: "pdf-loading-dots", style: { display: "inline-block", width: "24px", textAlign: "left" }, children: [
|
|
7931
|
+
/* @__PURE__ */ jsx19("span", { className: "pdf-dot-1", children: "." }),
|
|
7932
|
+
/* @__PURE__ */ jsx19("span", { className: "pdf-dot-2", children: "." }),
|
|
7933
|
+
/* @__PURE__ */ jsx19("span", { className: "pdf-dot-3", children: "." })
|
|
7934
|
+
] })
|
|
7935
|
+
]
|
|
7936
|
+
}
|
|
7937
|
+
),
|
|
7938
|
+
/* @__PURE__ */ jsxs16("div", { style: { width: "240px" }, children: [
|
|
7939
|
+
/* @__PURE__ */ jsx19(
|
|
7940
|
+
"div",
|
|
7941
|
+
{
|
|
7942
|
+
style: {
|
|
7943
|
+
width: "100%",
|
|
7944
|
+
height: "8px",
|
|
7945
|
+
borderRadius: "4px",
|
|
7946
|
+
background: "#e2e8f0",
|
|
7947
|
+
overflow: "hidden"
|
|
7948
|
+
},
|
|
7949
|
+
children: /* @__PURE__ */ jsx19(
|
|
7950
|
+
"div",
|
|
7951
|
+
{
|
|
7952
|
+
className: cn(
|
|
7953
|
+
"pdf-loading-progress-fill",
|
|
7954
|
+
!hasProgress && "pdf-loading-progress-indeterminate"
|
|
7955
|
+
),
|
|
7956
|
+
style: {
|
|
7957
|
+
height: "100%",
|
|
7958
|
+
borderRadius: "4px",
|
|
7959
|
+
background: "linear-gradient(90deg, #3b82f6 0%, #60a5fa 50%, #3b82f6 100%)",
|
|
7960
|
+
backgroundSize: "200% 100%",
|
|
7961
|
+
transition: "width 300ms ease-out",
|
|
7962
|
+
...hasProgress ? { width: `${Math.min(100, progress)}%` } : {}
|
|
7963
|
+
}
|
|
7964
|
+
}
|
|
7965
|
+
)
|
|
7966
|
+
}
|
|
7967
|
+
),
|
|
7968
|
+
(hasProgress || hasBytes) && /* @__PURE__ */ jsxs16(
|
|
7969
|
+
"div",
|
|
7970
|
+
{
|
|
7971
|
+
style: {
|
|
7972
|
+
display: "flex",
|
|
7973
|
+
justifyContent: "space-between",
|
|
7974
|
+
marginTop: "12px",
|
|
7975
|
+
fontSize: "13px",
|
|
7976
|
+
fontWeight: 500
|
|
7977
|
+
},
|
|
7978
|
+
children: [
|
|
7979
|
+
hasProgress && /* @__PURE__ */ jsxs16("span", { style: { color: "#3b82f6" }, children: [
|
|
7980
|
+
Math.round(progress),
|
|
7981
|
+
"%"
|
|
7982
|
+
] }),
|
|
7983
|
+
hasBytes && /* @__PURE__ */ jsxs16("span", { style: { color: "#94a3b8", fontFamily: "ui-monospace, monospace", fontSize: "12px" }, children: [
|
|
7984
|
+
formatBytes(bytesLoaded),
|
|
7985
|
+
" / ",
|
|
7986
|
+
formatBytes(totalBytes)
|
|
7987
|
+
] })
|
|
7988
|
+
]
|
|
7989
|
+
}
|
|
7990
|
+
)
|
|
7883
7991
|
] })
|
|
7884
|
-
]
|
|
7885
|
-
|
|
7886
|
-
|
|
7992
|
+
]
|
|
7993
|
+
}
|
|
7994
|
+
)
|
|
7887
7995
|
}
|
|
7888
7996
|
);
|
|
7889
7997
|
});
|
|
@@ -10048,6 +10156,7 @@ var init_PDFViewerClient = __esm({
|
|
|
10048
10156
|
setLoadState("idle");
|
|
10049
10157
|
}, [viewerStore]);
|
|
10050
10158
|
const abortControllerRef = useRef19(null);
|
|
10159
|
+
const currentSrcRef = useRef19(null);
|
|
10051
10160
|
useEffect22(() => {
|
|
10052
10161
|
mountedRef.current = true;
|
|
10053
10162
|
return () => {
|
|
@@ -10056,10 +10165,17 @@ var init_PDFViewerClient = __esm({
|
|
|
10056
10165
|
abortControllerRef.current.abort();
|
|
10057
10166
|
abortControllerRef.current = null;
|
|
10058
10167
|
}
|
|
10168
|
+
if (currentSrcRef.current && typeof currentSrcRef.current === "string") {
|
|
10169
|
+
clearDocumentCache(currentSrcRef.current);
|
|
10170
|
+
}
|
|
10059
10171
|
srcIdRef.current = null;
|
|
10172
|
+
currentSrcRef.current = null;
|
|
10060
10173
|
const currentDoc = viewerStore.getState().document;
|
|
10061
10174
|
if (currentDoc) {
|
|
10062
|
-
|
|
10175
|
+
try {
|
|
10176
|
+
currentDoc.destroy();
|
|
10177
|
+
} catch {
|
|
10178
|
+
}
|
|
10063
10179
|
}
|
|
10064
10180
|
viewerStore.getState().setDocument(null);
|
|
10065
10181
|
viewerStore.getState().setLoading(false);
|
|
@@ -10072,6 +10188,7 @@ var init_PDFViewerClient = __esm({
|
|
|
10072
10188
|
}
|
|
10073
10189
|
const loadId = srcId;
|
|
10074
10190
|
srcIdRef.current = srcId;
|
|
10191
|
+
currentSrcRef.current = src;
|
|
10075
10192
|
if (abortControllerRef.current) {
|
|
10076
10193
|
abortControllerRef.current.abort();
|
|
10077
10194
|
}
|