@file-viewer/renderer-pdf 3.1.2 → 3.2.1

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/pdfFit.js CHANGED
@@ -2,11 +2,6 @@ export const PDF_FIT_MIN_VIEWPORT_SIZE = 96;
2
2
  export const PDF_FIT_HORIZONTAL_PADDING = 28;
3
3
  export const PDF_PAGE_BORDER_WIDTH = 18;
4
4
  const normalizePadding = (padding) => (Number.isFinite(padding) && Number(padding) > 0 ? Number(padding) : 0);
5
- /**
6
- * Resolves the PDF page viewport after the navigation pane has been laid out.
7
- * Core request dimensions already exclude fit.padding; live container and
8
- * window fallback dimensions do not, so only those branches subtract it.
9
- */
10
5
  export const resolvePdfFitViewportSize = ({ containerWidth, containerHeight, fallbackWidth, fallbackHeight, request, }) => {
11
6
  const padding = normalizePadding(request.padding);
12
7
  const requestWidth = Number(request.viewportWidth) || 0;
@@ -22,11 +22,6 @@ export interface CreatePdfCjkFontFallbackManagerOptions {
22
22
  fontAssetPath: string;
23
23
  onWarning?: (message: string, error?: unknown) => void;
24
24
  }
25
- /**
26
- * Some PDF generators write TrueType glyph IDs through Identity-H but omit
27
- * ToUnicode. PDF.js then exposes those glyph IDs as control characters, so a
28
- * replacement font alone cannot recover the intended text.
29
- */
30
25
  export declare const detectMalformedIdentityCjkFontFamilies: (textContent: PdfTextContent, resolveFontFamily?: (fontName: string) => string) => string[];
31
26
  export declare const collectMalformedIdentityFontNames: (textContent: PdfTextContent) => string[];
32
27
  export declare const createPdfCjkFontFallbackManager: ({ documentRef, fontAssetPath, onWarning, }: CreatePdfCjkFontFallbackManagerOptions) => PdfCjkFontFallbackManager;
@@ -100,11 +100,6 @@ const isKnownCjkFontFamily = (family) => {
100
100
  /(?:cjk|han|song|hei|kai|fang|yahei|ming|gothic|mincho)/i.test(key) ||
101
101
  /[\u3400-\u9fff]/.test(family);
102
102
  };
103
- /**
104
- * Some PDF generators write TrueType glyph IDs through Identity-H but omit
105
- * ToUnicode. PDF.js then exposes those glyph IDs as control characters, so a
106
- * replacement font alone cannot recover the intended text.
107
- */
108
103
  export const detectMalformedIdentityCjkFontFamilies = (textContent, resolveFontFamily = () => '') => {
109
104
  var _a, _b;
110
105
  const styles = textContent.styles || {};
@@ -0,0 +1 @@
1
+ export declare function installPdfHandTool(container: HTMLElement): () => void;
@@ -0,0 +1,126 @@
1
+ export function installPdfHandTool(container) {
2
+ const view = container.ownerDocument.defaultView;
3
+ if (!view)
4
+ return () => { };
5
+ const previousCursor = container.style.getPropertyValue('cursor');
6
+ const cursorPriority = container.style.getPropertyPriority('cursor');
7
+ const interactive = 'a,button,input,textarea,select,option,[contenteditable]:not([contenteditable="false"]),[role="button"],[role="link"],[role="textbox"]';
8
+ let drag = null;
9
+ let suppressClick = false;
10
+ let clickTimer = 0;
11
+ container.style.cursor = 'grab';
12
+ const finish = () => {
13
+ var _a;
14
+ if (!drag)
15
+ return;
16
+ const state = drag;
17
+ drag = null;
18
+ container.style.setProperty('user-select', state.selection, state.priority);
19
+ container.style.cursor = 'grab';
20
+ view.removeEventListener('pointermove', move, true);
21
+ view.removeEventListener('pointerup', up, true);
22
+ view.removeEventListener('pointercancel', up, true);
23
+ view.removeEventListener('blur', finish);
24
+ if ((_a = container.hasPointerCapture) === null || _a === void 0 ? void 0 : _a.call(container, state.id))
25
+ container.releasePointerCapture(state.id);
26
+ suppressClick = state.moved;
27
+ view.clearTimeout(clickTimer);
28
+ clickTimer = view.setTimeout(() => {
29
+ suppressClick = false;
30
+ }, 0);
31
+ };
32
+ const move = (event) => {
33
+ if (!drag || event.pointerId !== drag.id)
34
+ return;
35
+ if (!(event.buttons & 1)) {
36
+ finish();
37
+ return;
38
+ }
39
+ const dx = (event.clientX - drag.x) / drag.ratio;
40
+ const dy = (event.clientY - drag.y) / drag.ratio;
41
+ drag.moved || (drag.moved = Math.hypot(dx, dy) >= 3);
42
+ container.scrollLeft = drag.left - dx;
43
+ container.scrollTop = drag.top - dy;
44
+ event.preventDefault();
45
+ };
46
+ const up = (event) => {
47
+ if (event.pointerId === (drag === null || drag === void 0 ? void 0 : drag.id))
48
+ finish();
49
+ };
50
+ const down = (event) => {
51
+ var _a;
52
+ if (event.defaultPrevented ||
53
+ event.pointerType !== 'mouse' ||
54
+ event.button !== 0 ||
55
+ event.isPrimary === false ||
56
+ event.ctrlKey ||
57
+ event.metaKey ||
58
+ event.altKey ||
59
+ event.shiftKey)
60
+ return;
61
+ if (event
62
+ .composedPath()
63
+ .some((node) => { var _a, _b; return node !== container && ((_b = (_a = node).matches) === null || _b === void 0 ? void 0 : _b.call(_a, interactive)); }))
64
+ return;
65
+ if (container.scrollWidth <= container.clientWidth &&
66
+ container.scrollHeight <= container.clientHeight)
67
+ return;
68
+ const rect = container.getBoundingClientRect();
69
+ const ratio = container.offsetWidth > 0 ? rect.width / container.offsetWidth : 1;
70
+ if (!Number.isFinite(ratio) || ratio <= 0)
71
+ return;
72
+ const x = (event.clientX - rect.left) / ratio - container.clientLeft;
73
+ const y = (event.clientY - rect.top) / ratio - container.clientTop;
74
+ if (x < 0 || y < 0 || x >= container.clientWidth || y >= container.clientHeight)
75
+ return;
76
+ finish();
77
+ suppressClick = false;
78
+ drag = {
79
+ id: event.pointerId,
80
+ x: event.clientX,
81
+ y: event.clientY,
82
+ left: container.scrollLeft,
83
+ top: container.scrollTop,
84
+ ratio,
85
+ moved: false,
86
+ selection: container.style.getPropertyValue('user-select'),
87
+ priority: container.style.getPropertyPriority('user-select')
88
+ };
89
+ container.style.cursor = 'grabbing';
90
+ container.style.setProperty('user-select', 'none');
91
+ try {
92
+ (_a = container.setPointerCapture) === null || _a === void 0 ? void 0 : _a.call(container, event.pointerId);
93
+ }
94
+ catch {
95
+ }
96
+ view.addEventListener('pointermove', move, { capture: true, passive: false });
97
+ view.addEventListener('pointerup', up, true);
98
+ view.addEventListener('pointercancel', up, true);
99
+ view.addEventListener('blur', finish);
100
+ event.preventDefault();
101
+ };
102
+ const click = (event) => {
103
+ if (suppressClick && event.detail > 0) {
104
+ event.preventDefault();
105
+ event.stopImmediatePropagation();
106
+ }
107
+ };
108
+ const nativeDrag = (event) => {
109
+ if (drag)
110
+ event.preventDefault();
111
+ };
112
+ container.addEventListener('pointerdown', down);
113
+ container.addEventListener('lostpointercapture', up);
114
+ container.addEventListener('click', click, true);
115
+ container.addEventListener('dragstart', nativeDrag);
116
+ return () => {
117
+ finish();
118
+ view.clearTimeout(clickTimer);
119
+ suppressClick = false;
120
+ container.style.setProperty('cursor', previousCursor, cursorPriority);
121
+ container.removeEventListener('pointerdown', down);
122
+ container.removeEventListener('lostpointercapture', up);
123
+ container.removeEventListener('click', click, true);
124
+ container.removeEventListener('dragstart', nativeDrag);
125
+ };
126
+ }
@@ -1,2 +1 @@
1
- /** @internal Shared only with the source-level regression tests. */
2
1
  export declare const normalizePdfIdentityFontFamily: (value: string) => string;
@@ -42,7 +42,6 @@ const stripFontStyleSuffix = (value) => {
42
42
  }
43
43
  return value;
44
44
  };
45
- /** @internal Shared only with the source-level regression tests. */
46
45
  export const normalizePdfIdentityFontFamily = (value) => {
47
46
  if (!value || value.length > MAX_PDF_IDENTITY_FONT_NAME_CHARACTERS)
48
47
  return '';
@@ -425,7 +425,6 @@ export const repairMalformedIdentityCjkFonts = async (sourceBytes, candidateFami
425
425
  }
426
426
  }
427
427
  catch {
428
- // A different same-family embedded font may still provide a valid cmap.
429
428
  }
430
429
  }
431
430
  if (!bestMap || bestMap.size < 2) {
@@ -0,0 +1 @@
1
+ export declare function scrollPdfPageWithinContainer(container: HTMLElement, page: HTMLElement | null): boolean;
@@ -0,0 +1,12 @@
1
+ export function scrollPdfPageWithinContainer(container, page) {
2
+ if (!page || !container.contains(page) || container.clientHeight <= 0)
3
+ return false;
4
+ const containerRect = container.getBoundingClientRect();
5
+ const pageRect = page.getBoundingClientRect();
6
+ const scale = container.offsetHeight > 0 ? containerRect.height / container.offsetHeight : 1;
7
+ if (!Number.isFinite(scale) || scale <= 0 || pageRect.height <= 0)
8
+ return false;
9
+ const top = container.scrollTop + (pageRect.top - containerRect.top) / scale - container.clientTop;
10
+ container.scrollTop = Math.min(Math.max(0, top), Math.max(0, container.scrollHeight - container.clientHeight));
11
+ return true;
12
+ }
@@ -1,6 +1,7 @@
1
1
  import type { FileViewerViewState } from '@file-viewer/core';
2
2
  export type PdfRotation = 0 | 90 | 180 | 270;
3
3
  export declare const normalizePdfRotation: (rotation: number) => PdfRotation;
4
+ export declare const resolvePdfPageRotation: (pageRotation: number, viewerRotation: number) => PdfRotation;
4
5
  export declare const clampPdfScale: (scale: number, minScale: number, maxScale: number) => number;
5
6
  export declare const resolvePdfViewStateUpdate: (state: FileViewerViewState, current: {
6
7
  rotation: number;
@@ -2,6 +2,7 @@ export const normalizePdfRotation = (rotation) => {
2
2
  const normalized = (((Math.round(rotation / 90) * 90) % 360) + 360) % 360;
3
3
  return (normalized === 90 || normalized === 180 || normalized === 270 ? normalized : 0);
4
4
  };
5
+ export const resolvePdfPageRotation = (pageRotation, viewerRotation) => normalizePdfRotation(normalizePdfRotation(pageRotation) + normalizePdfRotation(viewerRotation));
5
6
  export const clampPdfScale = (scale, minScale, maxScale) => {
6
7
  return Number(Math.min(maxScale, Math.max(minScale, scale)).toFixed(2));
7
8
  };
@@ -15,13 +15,4 @@ export type PdfJsWorkerGlobalSnapshot = {
15
15
  namespace: PdfJsWorkerNamespace | undefined;
16
16
  };
17
17
  export declare const capturePdfJsWorkerGlobal: (workerGlobal: PdfJsWorkerGlobal) => PdfJsWorkerGlobalSnapshot;
18
- /**
19
- * Temporarily own the fake-worker handler used by this renderer.
20
- *
21
- * Host applications can load another PDF.js build before File Viewer. Reusing
22
- * that global handler is unsafe because PDF.js requires its API and worker
23
- * versions to match exactly. The original namespace is restored after our
24
- * PDFWorker has captured and initialized the bundled handler, so a host PDF.js
25
- * build can continue using its own global afterwards.
26
- */
27
18
  export declare const scopePdfJsWorkerMessageHandler: (workerGlobal: PdfJsWorkerGlobal, WorkerMessageHandler: unknown, restoreSnapshot?: PdfJsWorkerGlobalSnapshot) => PdfJsWorkerHandlerScope;
@@ -2,15 +2,6 @@ export const capturePdfJsWorkerGlobal = (workerGlobal) => ({
2
2
  hadOwnNamespace: Object.prototype.hasOwnProperty.call(workerGlobal, 'pdfjsWorker'),
3
3
  namespace: workerGlobal.pdfjsWorker,
4
4
  });
5
- /**
6
- * Temporarily own the fake-worker handler used by this renderer.
7
- *
8
- * Host applications can load another PDF.js build before File Viewer. Reusing
9
- * that global handler is unsafe because PDF.js requires its API and worker
10
- * versions to match exactly. The original namespace is restored after our
11
- * PDFWorker has captured and initialized the bundled handler, so a host PDF.js
12
- * build can continue using its own global afterwards.
13
- */
14
5
  export const scopePdfJsWorkerMessageHandler = (workerGlobal, WorkerMessageHandler, restoreSnapshot = capturePdfJsWorkerGlobal(workerGlobal)) => {
15
6
  const currentNamespace = workerGlobal.pdfjsWorker;
16
7
  const installResult = (currentNamespace === null || currentNamespace === void 0 ? void 0 : currentNamespace.WorkerMessageHandler) === WorkerMessageHandler
@@ -0,0 +1,2 @@
1
+ export declare const isPdfWorkerVersionMismatch: (error: unknown, apiVersion: string) => boolean;
2
+ export declare const hasNativePdfWorkerPort: (port: unknown, constructors: Array<typeof Worker | undefined>) => boolean;
@@ -0,0 +1,4 @@
1
+ export const isPdfWorkerVersionMismatch = (error, apiVersion) => typeof error === 'object' && error !== null && 'message' in error &&
2
+ typeof error.message === 'string' &&
3
+ error.message.startsWith(`The API version "${apiVersion}" does not match the Worker version "`);
4
+ export const hasNativePdfWorkerPort = (port, constructors) => constructors.some(WorkerClass => typeof WorkerClass === 'function' && port instanceof WorkerClass);
@@ -1,9 +1 @@
1
- /**
2
- * Read the version marker emitted by official PDF.js worker bundles.
3
- *
4
- * The marker is intentionally read from a small source prefix before a Worker
5
- * is constructed. PDF.js does not reject an API/worker mismatch until the
6
- * first document request, which is too late for `PDFWorker.promise` to be a
7
- * useful compatibility probe.
8
- */
9
1
  export declare const readPdfJsWorkerVersion: (sourcePrefix: string) => string | null;
@@ -4,14 +4,6 @@ const PDF_JS_WORKER_VERSION_PATTERNS = [
4
4
  new RegExp(`\\bworkerVersion\\s*=\\s*["']${PDF_JS_SEMVER_PATTERN}["']`, 'i'),
5
5
  new RegExp(`\\bPDF\\.js\\s+v${PDF_JS_SEMVER_PATTERN}`, 'i'),
6
6
  ];
7
- /**
8
- * Read the version marker emitted by official PDF.js worker bundles.
9
- *
10
- * The marker is intentionally read from a small source prefix before a Worker
11
- * is constructed. PDF.js does not reject an API/worker mismatch until the
12
- * first document request, which is too late for `PDFWorker.promise` to be a
13
- * useful compatibility probe.
14
- */
15
7
  export const readPdfJsWorkerVersion = (sourcePrefix) => {
16
8
  for (const pattern of PDF_JS_WORKER_VERSION_PATTERNS) {
17
9
  const match = pattern.exec(sourcePrefix);
@@ -1,4 +1,4 @@
1
- /* File Viewer modification: isolated PDF.js internal webpack runtime identifiers for webpack 4 compatibility. */
1
+ /* File Viewer modification: isolated PDF.js internal webpack runtime identifiers for webpack 4 compatibility and removed unavailable source-map metadata. */
2
2
  /**
3
3
  * @licstart The following is the entire license notice for the
4
4
  * JavaScript code in this page
@@ -32797,4 +32797,3 @@ globalThis.pdfjsLib = {
32797
32797
 
32798
32798
  export { AbortException, AnnotationEditorLayer, AnnotationEditorParamsType, AnnotationEditorType, AnnotationEditorUIManager, AnnotationLayer, AnnotationMode, AnnotationType, CSSConstants, ColorPicker, DOMSVGFactory, DrawLayer, util_FeatureTest as FeatureTest, GlobalWorkerOptions, util_ImageKind as ImageKind, InvalidPDFException, MathClamp, OPS, OutputScale, PDFDataRangeTransport, PDFDateString, PDFWorker, PagesMapper, PasswordResponses, PermissionFlag, PixelsPerInch, RenderingCancelledException, ResponseException, SignatureExtractor, SupportedImageMimeTypes, TextLayer, TouchManager, Util, VerbosityLevel, XfaLayer, applyOpacity, build, createValidAbsoluteUrl, fetchData, findContrastColor, getDocument, getFilenameFromUrl, getPdfFilenameFromUrl, getRGB, getUuid, getXfaPageViewport, isDataScheme, isPdfFile, isValidExplicitDest, noContextMenu, normalizeUnicode, renderRichText, setLayerDimensions, shadow, stopEvent, updateUrlHash, version };
32799
32799
 
32800
- //# sourceMappingURL=pdf.mjs.map
@@ -1,4 +1,4 @@
1
- /* File Viewer modification: isolated PDF.js internal webpack runtime identifiers for webpack 4 compatibility. */
1
+ /* File Viewer modification: isolated PDF.js internal webpack runtime identifiers for webpack 4 compatibility and removed unavailable source-map metadata. */
2
2
  /**
3
3
  * @licstart The following is the entire license notice for the
4
4
  * JavaScript code in this page
@@ -67399,4 +67399,3 @@ globalThis.pdfjsWorker = {
67399
67399
 
67400
67400
  export { WorkerMessageHandler };
67401
67401
 
67402
- //# sourceMappingURL=pdf.worker.mjs.map
@@ -1,4 +1,4 @@
1
- /* File Viewer modification: isolated PDF.js internal webpack runtime identifiers for webpack 4 compatibility. */
1
+ /* File Viewer modification: isolated PDF.js internal webpack runtime identifiers for webpack 4 compatibility and removed unavailable source-map metadata. */
2
2
  /**
3
3
  * @licstart The following is the entire license notice for the
4
4
  * JavaScript code in this page
@@ -14445,4 +14445,3 @@ globalThis.pdfjsViewer = {
14445
14445
 
14446
14446
  export { AnnotationLayerBuilder, DownloadManager, EventBus, FindState, genericl10n_GenericL10n as GenericL10n, LinkTarget, PDFFindController, PDFHistory, PDFLinkService, PDFPageView, PDFScriptingManagerComponents as PDFScriptingManager, PDFSinglePageViewer, PDFViewer, ProgressBar, RenderingStates, ScrollMode, SimpleLinkService, SpreadMode, StructTreeLayerBuilder, TextLayerBuilder, XfaLayerBuilder, parseQueryString };
14447
14447
 
14448
- //# sourceMappingURL=pdf_viewer.mjs.map
@@ -4,7 +4,7 @@
4
4
  "version": "5.4.624",
5
5
  "sourceRepository": "https://github.com/mozilla/pdf.js",
6
6
  "licenseSpdx": "Apache-2.0",
7
- "runtimeTransform": "isolate-pdfjs-webpack4-runtime-v1",
7
+ "runtimeTransform": "isolate-pdfjs-webpack4-runtime-v2",
8
8
  "sourcePatches": [
9
9
  {
10
10
  "path": "patches/pdfjs-dist@5.4.624.patch",
@@ -18,24 +18,24 @@
18
18
  "sourceSize": 976824,
19
19
  "sourceSha256": "5464c1bf96dddd169eed8f4afacffde4c9369d397b7eb383fb6bbe2e28fa400c",
20
20
  "runtimeBindingReplacements": 843,
21
- "size": 981996,
22
- "sha256": "af40b0e9b6f237cb40659afcd100f84ec21bc7d5d9044fa0cfc2d6a506b8e489"
21
+ "size": 982008,
22
+ "sha256": "e194c0650817dffdbdf0bf76bfde918b64021c4b699d6914f7d3ae20cec6d4dd"
23
23
  },
24
24
  {
25
25
  "path": "legacy/build/pdf.worker.mjs",
26
26
  "sourceSize": 2139821,
27
27
  "sourceSha256": "6c97b16c12986a5043311d7c4a15043e6f160db2503795e9a6804b85e8054c1d",
28
28
  "runtimeBindingReplacements": 793,
29
- "size": 2144693,
30
- "sha256": "6dbca20dcff89ef88c00b543bf66873be2ad778d17a65f9e426f75b57774d432"
29
+ "size": 2144698,
30
+ "sha256": "195cbedfa6bb5d7f4e6296c06fdf38b193a53de623127865677355ea164e1b03"
31
31
  },
32
32
  {
33
33
  "path": "legacy/web/pdf_viewer.mjs",
34
34
  "sourceSize": 453414,
35
35
  "sourceSha256": "c993ef3af7e11a28e7ce15bef6717adf14617a0451f02861a5cd90c5fe5bf00e",
36
36
  "runtimeBindingReplacements": 687,
37
- "size": 457650,
38
- "sha256": "b5856515ea724805f70febb0694e729a88604bc1071d01091bb35595d4808b99"
37
+ "size": 457655,
38
+ "sha256": "03ccd6120d3149278a90c9b58e6b7ab90eb80d3d5bb6f6f70f5635a3f145cfe9"
39
39
  }
40
40
  ],
41
41
  "assetDirectories": [