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 CHANGED
@@ -101,10 +101,13 @@ async function loadDocument(options) {
101
101
  const cachedDoc = documentCache.get(cacheKey);
102
102
  try {
103
103
  const numPages = cachedDoc.numPages;
104
- return {
105
- document: cachedDoc,
106
- numPages
107
- };
104
+ if (numPages > 0) {
105
+ await cachedDoc.getPage(1);
106
+ return {
107
+ document: cachedDoc,
108
+ numPages
109
+ };
110
+ }
108
111
  } catch {
109
112
  documentCache.delete(cacheKey);
110
113
  }
@@ -182,6 +185,20 @@ async function getOutline(document2) {
182
185
  async function getMetadata(document2) {
183
186
  return document2.getMetadata();
184
187
  }
188
+ function clearDocumentCache(url) {
189
+ if (url) {
190
+ const doc = documentCache.get(url);
191
+ if (doc) {
192
+ doc.destroy();
193
+ documentCache.delete(url);
194
+ }
195
+ } else {
196
+ for (const doc of documentCache.values()) {
197
+ doc.destroy();
198
+ }
199
+ documentCache.clear();
200
+ }
201
+ }
185
202
  var documentCache;
186
203
  var init_document_loader = __esm({
187
204
  "src/utils/document-loader.ts"() {
@@ -7771,7 +7788,7 @@ function formatBytes(bytes) {
7771
7788
  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
7772
7789
  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
7773
7790
  }
7774
- var import_react33, import_jsx_runtime19, phaseMessages, phaseIcons, PDFLoadingScreen;
7791
+ var import_react33, import_jsx_runtime19, phaseMessages, PDFLoadingScreen;
7775
7792
  var init_PDFLoadingScreen = __esm({
7776
7793
  "src/components/PDFLoadingScreen/PDFLoadingScreen.tsx"() {
7777
7794
  "use strict";
@@ -7779,16 +7796,10 @@ var init_PDFLoadingScreen = __esm({
7779
7796
  init_utils();
7780
7797
  import_jsx_runtime19 = require("react/jsx-runtime");
7781
7798
  phaseMessages = {
7782
- initializing: "Preparing viewer...",
7783
- fetching: "Loading document...",
7784
- parsing: "Processing pages...",
7785
- rendering: "Almost ready..."
7786
- };
7787
- phaseIcons = {
7788
- initializing: "\u2699\uFE0F",
7789
- fetching: "\u{1F4C4}",
7790
- parsing: "\u{1F4D1}",
7791
- rendering: "\u2728"
7799
+ initializing: "Preparing viewer",
7800
+ fetching: "Loading document",
7801
+ parsing: "Processing pages",
7802
+ rendering: "Almost ready"
7792
7803
  };
7793
7804
  PDFLoadingScreen = (0, import_react33.memo)(function PDFLoadingScreen2({
7794
7805
  progress,
@@ -7805,122 +7816,219 @@ var init_PDFLoadingScreen = __esm({
7805
7816
  {
7806
7817
  className: cn(
7807
7818
  "pdf-loading-screen",
7808
- "flex flex-col items-center justify-center",
7809
- "w-full h-full min-h-[400px]",
7810
- "bg-gradient-to-b from-slate-50 to-slate-100",
7811
- "dark:from-slate-900 dark:to-slate-800",
7812
7819
  className
7813
7820
  ),
7821
+ style: {
7822
+ display: "flex",
7823
+ flexDirection: "column",
7824
+ alignItems: "center",
7825
+ justifyContent: "center",
7826
+ width: "100%",
7827
+ height: "100%",
7828
+ minHeight: "400px",
7829
+ background: "linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%)",
7830
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
7831
+ },
7814
7832
  role: "status",
7815
7833
  "aria-live": "polite",
7816
7834
  "aria-label": phaseMessages[phase],
7817
- children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "pdf-loading-card", children: [
7818
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "pdf-loading-icon-wrapper", children: [
7819
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "pdf-loading-icon-glow" }),
7820
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "pdf-loading-icon", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
7821
- "svg",
7822
- {
7823
- width: "64",
7824
- height: "80",
7825
- viewBox: "0 0 64 80",
7826
- fill: "none",
7827
- xmlns: "http://www.w3.org/2000/svg",
7828
- className: "pdf-document-icon",
7829
- children: [
7830
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7831
- "ellipse",
7832
- {
7833
- cx: "32",
7834
- cy: "76",
7835
- rx: "24",
7836
- ry: "4",
7837
- className: "fill-slate-200 dark:fill-slate-700",
7838
- opacity: "0.5"
7839
- }
7840
- ),
7841
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7842
- "path",
7843
- {
7844
- 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",
7845
- className: "fill-white dark:fill-slate-700"
7846
- }
7847
- ),
7848
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7849
- "path",
7850
- {
7851
- d: "M40 0L56 16H44C41.7909 16 40 14.2091 40 12V0Z",
7852
- className: "fill-blue-100 dark:fill-blue-900"
7853
- }
7854
- ),
7855
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7856
- "rect",
7857
- {
7858
- x: "14",
7859
- y: "28",
7860
- width: "28",
7861
- height: "12",
7862
- rx: "2",
7863
- className: "fill-blue-500 dark:fill-blue-400"
7864
- }
7865
- ),
7866
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7867
- "text",
7868
- {
7869
- x: "28",
7870
- y: "37",
7871
- textAnchor: "middle",
7872
- className: "fill-white text-[8px] font-bold",
7873
- style: { fontSize: "8px", fontWeight: 700 },
7874
- children: "PDF"
7875
- }
7876
- ),
7877
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("rect", { x: "14", y: "48", width: "28", height: "3", rx: "1.5", className: "pdf-line-1 fill-slate-200 dark:fill-slate-600" }),
7878
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("rect", { x: "14", y: "54", width: "22", height: "3", rx: "1.5", className: "pdf-line-2 fill-slate-200 dark:fill-slate-600" }),
7879
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("rect", { x: "14", y: "60", width: "18", height: "3", rx: "1.5", className: "pdf-line-3 fill-slate-200 dark:fill-slate-600" }),
7880
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7881
- "path",
7882
- {
7883
- 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",
7884
- className: "stroke-slate-200 dark:stroke-slate-600",
7885
- strokeWidth: "1.5",
7886
- fill: "none"
7887
- }
7888
- )
7889
- ]
7890
- }
7891
- ) })
7892
- ] }),
7893
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "pdf-loading-info", children: [
7894
- documentName && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "pdf-loading-document-name", children: documentName }),
7895
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "pdf-loading-message-wrapper", children: [
7896
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "pdf-loading-phase-icon", children: phaseIcons[phase] }),
7897
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", { className: "pdf-loading-message", children: phaseMessages[phase] })
7898
- ] }),
7899
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "pdf-loading-progress-container", children: [
7900
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "pdf-loading-progress-track", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7835
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
7836
+ "div",
7837
+ {
7838
+ style: {
7839
+ display: "flex",
7840
+ flexDirection: "column",
7841
+ alignItems: "center",
7842
+ padding: "48px 40px",
7843
+ background: "white",
7844
+ borderRadius: "20px",
7845
+ boxShadow: "0 10px 40px -10px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05)"
7846
+ },
7847
+ children: [
7848
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
7901
7849
  "div",
7902
7850
  {
7903
- className: cn(
7904
- "pdf-loading-progress-fill",
7905
- !hasProgress && "pdf-loading-progress-indeterminate"
7906
- ),
7907
- style: hasProgress ? { width: `${Math.min(100, progress)}%` } : void 0
7851
+ className: "pdf-loading-icon-container",
7852
+ style: {
7853
+ position: "relative",
7854
+ marginBottom: "32px"
7855
+ },
7856
+ children: [
7857
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7858
+ "div",
7859
+ {
7860
+ className: "pdf-loading-glow",
7861
+ style: {
7862
+ position: "absolute",
7863
+ top: "50%",
7864
+ left: "50%",
7865
+ width: "120px",
7866
+ height: "120px",
7867
+ transform: "translate(-50%, -50%)",
7868
+ background: "radial-gradient(circle, rgba(59, 130, 246, 0.15) 0%, transparent 70%)",
7869
+ borderRadius: "50%"
7870
+ }
7871
+ }
7872
+ ),
7873
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
7874
+ "svg",
7875
+ {
7876
+ width: "72",
7877
+ height: "88",
7878
+ viewBox: "0 0 72 88",
7879
+ fill: "none",
7880
+ xmlns: "http://www.w3.org/2000/svg",
7881
+ className: "pdf-document-icon",
7882
+ style: {
7883
+ position: "relative",
7884
+ zIndex: 1,
7885
+ filter: "drop-shadow(0 8px 16px rgba(0, 0, 0, 0.1))"
7886
+ },
7887
+ children: [
7888
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7889
+ "path",
7890
+ {
7891
+ 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",
7892
+ fill: "#ffffff",
7893
+ stroke: "#e2e8f0",
7894
+ strokeWidth: "2"
7895
+ }
7896
+ ),
7897
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7898
+ "path",
7899
+ {
7900
+ d: "M44 0L68 24H52C47.5817 24 44 20.4183 44 16V0Z",
7901
+ fill: "#dbeafe"
7902
+ }
7903
+ ),
7904
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7905
+ "rect",
7906
+ {
7907
+ x: "14",
7908
+ y: "36",
7909
+ width: "44",
7910
+ height: "20",
7911
+ rx: "4",
7912
+ fill: "#3b82f6"
7913
+ }
7914
+ ),
7915
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7916
+ "text",
7917
+ {
7918
+ x: "36",
7919
+ y: "50",
7920
+ textAnchor: "middle",
7921
+ fill: "white",
7922
+ style: {
7923
+ fontSize: "12px",
7924
+ fontWeight: 700,
7925
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
7926
+ },
7927
+ children: "PDF"
7928
+ }
7929
+ ),
7930
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("rect", { className: "pdf-line-1", x: "14", y: "64", width: "44", height: "4", rx: "2", fill: "#e2e8f0" }),
7931
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("rect", { className: "pdf-line-2", x: "14", y: "72", width: "32", height: "4", rx: "2", fill: "#e2e8f0" })
7932
+ ]
7933
+ }
7934
+ )
7935
+ ]
7908
7936
  }
7909
- ) }),
7910
- (hasProgress || hasBytes) && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "pdf-loading-progress-details", children: [
7911
- hasProgress && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "pdf-loading-progress-percent", children: [
7912
- Math.round(progress),
7913
- "%"
7914
- ] }),
7915
- hasBytes && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "pdf-loading-progress-bytes", children: [
7916
- formatBytes(bytesLoaded),
7917
- " / ",
7918
- formatBytes(totalBytes)
7919
- ] })
7937
+ ),
7938
+ documentName && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7939
+ "p",
7940
+ {
7941
+ style: {
7942
+ fontSize: "13px",
7943
+ fontWeight: 500,
7944
+ color: "#64748b",
7945
+ marginBottom: "8px",
7946
+ maxWidth: "240px",
7947
+ overflow: "hidden",
7948
+ textOverflow: "ellipsis",
7949
+ whiteSpace: "nowrap",
7950
+ textAlign: "center"
7951
+ },
7952
+ children: documentName
7953
+ }
7954
+ ),
7955
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
7956
+ "p",
7957
+ {
7958
+ style: {
7959
+ fontSize: "16px",
7960
+ fontWeight: 600,
7961
+ color: "#1e293b",
7962
+ marginBottom: "24px",
7963
+ textAlign: "center"
7964
+ },
7965
+ children: [
7966
+ phaseMessages[phase],
7967
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: "pdf-loading-dots", style: { display: "inline-block", width: "24px", textAlign: "left" }, children: [
7968
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "pdf-dot-1", children: "." }),
7969
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "pdf-dot-2", children: "." }),
7970
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "pdf-dot-3", children: "." })
7971
+ ] })
7972
+ ]
7973
+ }
7974
+ ),
7975
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { style: { width: "240px" }, children: [
7976
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7977
+ "div",
7978
+ {
7979
+ style: {
7980
+ width: "100%",
7981
+ height: "8px",
7982
+ borderRadius: "4px",
7983
+ background: "#e2e8f0",
7984
+ overflow: "hidden"
7985
+ },
7986
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
7987
+ "div",
7988
+ {
7989
+ className: cn(
7990
+ "pdf-loading-progress-fill",
7991
+ !hasProgress && "pdf-loading-progress-indeterminate"
7992
+ ),
7993
+ style: {
7994
+ height: "100%",
7995
+ borderRadius: "4px",
7996
+ background: "linear-gradient(90deg, #3b82f6 0%, #60a5fa 50%, #3b82f6 100%)",
7997
+ backgroundSize: "200% 100%",
7998
+ transition: "width 300ms ease-out",
7999
+ ...hasProgress ? { width: `${Math.min(100, progress)}%` } : {}
8000
+ }
8001
+ }
8002
+ )
8003
+ }
8004
+ ),
8005
+ (hasProgress || hasBytes) && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
8006
+ "div",
8007
+ {
8008
+ style: {
8009
+ display: "flex",
8010
+ justifyContent: "space-between",
8011
+ marginTop: "12px",
8012
+ fontSize: "13px",
8013
+ fontWeight: 500
8014
+ },
8015
+ children: [
8016
+ hasProgress && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { style: { color: "#3b82f6" }, children: [
8017
+ Math.round(progress),
8018
+ "%"
8019
+ ] }),
8020
+ hasBytes && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { style: { color: "#94a3b8", fontFamily: "ui-monospace, monospace", fontSize: "12px" }, children: [
8021
+ formatBytes(bytesLoaded),
8022
+ " / ",
8023
+ formatBytes(totalBytes)
8024
+ ] })
8025
+ ]
8026
+ }
8027
+ )
7920
8028
  ] })
7921
- ] })
7922
- ] })
7923
- ] })
8029
+ ]
8030
+ }
8031
+ )
7924
8032
  }
7925
8033
  );
7926
8034
  });
@@ -10078,6 +10186,7 @@ var init_PDFViewerClient = __esm({
10078
10186
  setLoadState("idle");
10079
10187
  }, [viewerStore]);
10080
10188
  const abortControllerRef = (0, import_react41.useRef)(null);
10189
+ const currentSrcRef = (0, import_react41.useRef)(null);
10081
10190
  (0, import_react41.useEffect)(() => {
10082
10191
  mountedRef.current = true;
10083
10192
  return () => {
@@ -10086,10 +10195,17 @@ var init_PDFViewerClient = __esm({
10086
10195
  abortControllerRef.current.abort();
10087
10196
  abortControllerRef.current = null;
10088
10197
  }
10198
+ if (currentSrcRef.current && typeof currentSrcRef.current === "string") {
10199
+ clearDocumentCache(currentSrcRef.current);
10200
+ }
10089
10201
  srcIdRef.current = null;
10202
+ currentSrcRef.current = null;
10090
10203
  const currentDoc = viewerStore.getState().document;
10091
10204
  if (currentDoc) {
10092
- currentDoc.destroy();
10205
+ try {
10206
+ currentDoc.destroy();
10207
+ } catch {
10208
+ }
10093
10209
  }
10094
10210
  viewerStore.getState().setDocument(null);
10095
10211
  viewerStore.getState().setLoading(false);
@@ -10102,6 +10218,7 @@ var init_PDFViewerClient = __esm({
10102
10218
  }
10103
10219
  const loadId = srcId;
10104
10220
  srcIdRef.current = srcId;
10221
+ currentSrcRef.current = src;
10105
10222
  if (abortControllerRef.current) {
10106
10223
  abortControllerRef.current.abort();
10107
10224
  }