@pdfslick/core 3.0.0 → 4.0.0
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 +4 -0
- package/dist/esm/PDFSlick.d.ts +8 -2
- package/dist/esm/PDFSlick.d.ts.map +1 -1
- package/dist/esm/PDFSlickPrintService.d.ts.map +1 -1
- package/dist/esm/index.js +163 -120
- package/dist/esm/lib/pdf_rendering_queue.d.ts +13 -10
- package/dist/esm/lib/pdf_rendering_queue.d.ts.map +1 -1
- package/dist/esm/lib/pdf_thumbnail_view.d.ts +12 -2
- package/dist/esm/lib/pdf_thumbnail_view.d.ts.map +1 -1
- package/dist/esm/lib/pdf_thumbnail_viewer.d.ts +14 -1
- package/dist/esm/lib/pdf_thumbnail_viewer.d.ts.map +1 -1
- package/dist/esm/lib/ui_utils.d.ts +19 -13
- package/dist/esm/lib/ui_utils.d.ts.map +1 -1
- package/dist/esm/types.d.ts +6 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/pdf_viewer.css +3689 -2001
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/umd/index.js +3 -3
- package/package.json +9 -9
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderingCancelledException, PixelsPerInch,
|
|
1
|
+
import { MathClamp, RenderingCancelledException, OutputScale, PixelsPerInch, XfaLayer, AnnotationMode, AnnotationEditorType, GlobalWorkerOptions, AnnotationEditorParamsType, getPdfFilenameFromUrl, getDocument, PDFDateString } from 'pdfjs-dist';
|
|
2
2
|
import { SimpleLinkService, XfaLayerBuilder, GenericL10n, DownloadManager, EventBus, PDFLinkService, PDFFindController, PDFSinglePageViewer, PDFViewer } from 'pdfjs-dist/web/pdf_viewer.mjs';
|
|
3
3
|
import { createStore } from 'zustand/vanilla';
|
|
4
4
|
|
|
@@ -120,28 +120,6 @@ const CursorTool = {
|
|
|
120
120
|
};
|
|
121
121
|
// Used by `PDFViewerApplication`, and by the API unit-tests.
|
|
122
122
|
const AutoPrintRegExp = /\bprint\s*\(/;
|
|
123
|
-
/**
|
|
124
|
-
* Scale factors for the canvas, necessary with HiDPI displays.
|
|
125
|
-
*/
|
|
126
|
-
class OutputScale {
|
|
127
|
-
constructor() {
|
|
128
|
-
const pixelRatio = window.devicePixelRatio || 1;
|
|
129
|
-
/**
|
|
130
|
-
* @type {number} Horizontal scale.
|
|
131
|
-
*/
|
|
132
|
-
this.sx = pixelRatio;
|
|
133
|
-
/**
|
|
134
|
-
* @type {number} Vertical scale.
|
|
135
|
-
*/
|
|
136
|
-
this.sy = pixelRatio;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* @type {boolean} Returns `true` when scaling is required, `false` otherwise.
|
|
140
|
-
*/
|
|
141
|
-
get scaled() {
|
|
142
|
-
return this.sx !== 1 || this.sy !== 1;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
123
|
/**
|
|
146
124
|
* Scrolls specified element into view of its parent.
|
|
147
125
|
* @param {HTMLElement} element - The element to be visible.
|
|
@@ -181,7 +159,14 @@ function scrollIntoView(element, spot, scrollMatches = false) {
|
|
|
181
159
|
offsetY += spot.top;
|
|
182
160
|
}
|
|
183
161
|
if (spot.left !== undefined) {
|
|
184
|
-
|
|
162
|
+
if (scrollMatches) {
|
|
163
|
+
const elementWidth = element.getBoundingClientRect().width;
|
|
164
|
+
const padding = MathClamp((parent.clientWidth - elementWidth) / 2, 20, 400);
|
|
165
|
+
offsetX += spot.left - padding;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
offsetX += spot.left;
|
|
169
|
+
}
|
|
185
170
|
parent.scrollLeft = offsetX;
|
|
186
171
|
}
|
|
187
172
|
}
|
|
@@ -545,14 +530,28 @@ function getVisibleElements({ scrollEl, views, sortByVisibility = false, horizon
|
|
|
545
530
|
currentWidth >= right) {
|
|
546
531
|
continue;
|
|
547
532
|
}
|
|
548
|
-
const
|
|
549
|
-
const
|
|
533
|
+
const minY = Math.max(0, top - currentHeight);
|
|
534
|
+
const minX = Math.max(0, left - currentWidth);
|
|
535
|
+
const hiddenHeight = minY + Math.max(0, viewBottom - bottom);
|
|
536
|
+
const hiddenWidth = minX + Math.max(0, viewRight - right);
|
|
550
537
|
const fractionHeight = (viewHeight - hiddenHeight) / viewHeight, fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
|
|
551
538
|
const percent = (fractionHeight * fractionWidth * 100) | 0;
|
|
552
539
|
visible.push({
|
|
553
540
|
id: view.id,
|
|
554
541
|
x: currentWidth,
|
|
555
542
|
y: currentHeight,
|
|
543
|
+
visibleArea:
|
|
544
|
+
// We only specify which part of the page is visible when it's not
|
|
545
|
+
// the full page, as there is no point in handling a partial page
|
|
546
|
+
// rendering otherwise.
|
|
547
|
+
percent === 100
|
|
548
|
+
? null
|
|
549
|
+
: {
|
|
550
|
+
minX,
|
|
551
|
+
minY,
|
|
552
|
+
maxX: Math.min(viewRight, right) - currentWidth,
|
|
553
|
+
maxY: Math.min(viewBottom, bottom) - currentHeight,
|
|
554
|
+
},
|
|
556
555
|
view,
|
|
557
556
|
percent,
|
|
558
557
|
widthPercent: (fractionWidth * 100) | 0,
|
|
@@ -617,9 +616,6 @@ const animationStarted = new Promise(function (resolve) {
|
|
|
617
616
|
window.requestAnimationFrame(resolve);
|
|
618
617
|
});
|
|
619
618
|
const docStyle = document.documentElement.style;
|
|
620
|
-
function clamp(v, min, max) {
|
|
621
|
-
return Math.min(Math.max(v, min), max);
|
|
622
|
-
}
|
|
623
619
|
class ProgressBar {
|
|
624
620
|
constructor(bar) {
|
|
625
621
|
_ProgressBar_classList.set(this, void 0);
|
|
@@ -634,7 +630,7 @@ class ProgressBar {
|
|
|
634
630
|
return __classPrivateFieldGet(this, _ProgressBar_percent, "f");
|
|
635
631
|
}
|
|
636
632
|
set percent(val) {
|
|
637
|
-
__classPrivateFieldSet(this, _ProgressBar_percent,
|
|
633
|
+
__classPrivateFieldSet(this, _ProgressBar_percent, MathClamp(val, 0, 100), "f");
|
|
638
634
|
if (isNaN(val)) {
|
|
639
635
|
__classPrivateFieldGet(this, _ProgressBar_classList, "f").add("indeterminate");
|
|
640
636
|
return;
|
|
@@ -783,9 +779,8 @@ const calcRound = (function () {
|
|
|
783
779
|
* See the License for the specific language governing permissions and
|
|
784
780
|
* limitations under the License.
|
|
785
781
|
*/
|
|
786
|
-
/** @typedef {import("./interfaces").
|
|
782
|
+
/** @typedef {import("./interfaces").RenderableView} RenderableView */
|
|
787
783
|
/** @typedef {import("./pdf_viewer").PDFViewer} PDFViewer */
|
|
788
|
-
// eslint-disable-next-line max-len
|
|
789
784
|
/** @typedef {import("./pdf_thumbnail_viewer").PDFThumbnailViewer} PDFThumbnailViewer */
|
|
790
785
|
const CLEANUP_TIMEOUT = 30000;
|
|
791
786
|
/**
|
|
@@ -820,7 +815,7 @@ class PDFRenderingQueue {
|
|
|
820
815
|
this.pdfThumbnailViewer = pdfThumbnailViewer;
|
|
821
816
|
}
|
|
822
817
|
/**
|
|
823
|
-
* @param {
|
|
818
|
+
* @param {RenderableView} view
|
|
824
819
|
* @returns {boolean}
|
|
825
820
|
*/
|
|
826
821
|
isHighestPriority(view) {
|
|
@@ -858,14 +853,15 @@ class PDFRenderingQueue {
|
|
|
858
853
|
* @param {boolean} scrolledDown
|
|
859
854
|
* @param {boolean} [preRenderExtra]
|
|
860
855
|
*/
|
|
861
|
-
getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
|
|
856
|
+
getHighestPriority(visible, views, scrolledDown, preRenderExtra = false, ignoreDetailViews = false) {
|
|
862
857
|
/**
|
|
863
858
|
* The state has changed. Figure out which page has the highest priority to
|
|
864
859
|
* render next (if any).
|
|
865
860
|
*
|
|
866
861
|
* Priority:
|
|
867
862
|
* 1. visible pages
|
|
868
|
-
* 2.
|
|
863
|
+
* 2. zoomed-in partial views of visible pages, unless `ignoreDetailViews`
|
|
864
|
+
* 3. if last scrolled down, the page after the visible pages, or
|
|
869
865
|
* if last scrolled up, the page before the visible pages
|
|
870
866
|
*/
|
|
871
867
|
const visibleViews = visible.views, numVisible = visibleViews.length;
|
|
@@ -878,6 +874,14 @@ class PDFRenderingQueue {
|
|
|
878
874
|
return view;
|
|
879
875
|
}
|
|
880
876
|
}
|
|
877
|
+
if (!ignoreDetailViews) {
|
|
878
|
+
for (let i = 0; i < numVisible; i++) {
|
|
879
|
+
const { detailView } = visibleViews[i].view;
|
|
880
|
+
if (detailView && !this.isViewFinished(detailView)) {
|
|
881
|
+
return detailView;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
881
885
|
const firstId = visible.first.id, lastId = visible.last.id;
|
|
882
886
|
// All the visible views have rendered; try to handle any "holes" in the
|
|
883
887
|
// page layout (can happen e.g. with spreadModes at higher zoom levels).
|
|
@@ -912,7 +916,7 @@ class PDFRenderingQueue {
|
|
|
912
916
|
return null;
|
|
913
917
|
}
|
|
914
918
|
/**
|
|
915
|
-
* @param {
|
|
919
|
+
* @param {RenderableView} view
|
|
916
920
|
* @returns {boolean}
|
|
917
921
|
*/
|
|
918
922
|
isViewFinished(view) {
|
|
@@ -923,7 +927,7 @@ class PDFRenderingQueue {
|
|
|
923
927
|
* based on the views state. If the view is already rendered it will return
|
|
924
928
|
* `false`.
|
|
925
929
|
*
|
|
926
|
-
* @param {
|
|
930
|
+
* @param {RenderableView} view
|
|
927
931
|
*/
|
|
928
932
|
renderView(view) {
|
|
929
933
|
switch (view.renderingState) {
|
|
@@ -969,9 +973,15 @@ class PDFRenderingQueue {
|
|
|
969
973
|
* See the License for the specific language governing permissions and
|
|
970
974
|
* limitations under the License.
|
|
971
975
|
*/
|
|
972
|
-
var _a, _TempImageFactory_tempCanvas, _PDFThumbnailView_instances, _PDFThumbnailView_updateDims, _PDFThumbnailView_getPageDrawContext, _PDFThumbnailView_convertCanvasToImage,
|
|
976
|
+
var _a, _TempImageFactory_tempCanvas, _PDFThumbnailView_instances, _PDFThumbnailView_updateDims, _PDFThumbnailView_getPageDrawContext, _PDFThumbnailView_convertCanvasToImage, _PDFThumbnailView_getReducedImageDims, _PDFThumbnailView_reduceImage;
|
|
973
977
|
const DRAW_UPSCALE_FACTOR = 2; // See comment in `PDFThumbnailView.draw` below.
|
|
974
978
|
const MAX_NUM_SCALING_STEPS = 3;
|
|
979
|
+
function zeroCanvas(c) {
|
|
980
|
+
// Zeroing the width and height causes Firefox to release graphics
|
|
981
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
982
|
+
c.width = 0;
|
|
983
|
+
c.height = 0;
|
|
984
|
+
}
|
|
975
985
|
/**
|
|
976
986
|
* @typedef {Object} PDFThumbnailViewOptions
|
|
977
987
|
* @property {HTMLDivElement} container - The viewer element.
|
|
@@ -983,6 +993,12 @@ const MAX_NUM_SCALING_STEPS = 3;
|
|
|
983
993
|
* The default value is `null`.
|
|
984
994
|
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
|
985
995
|
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
|
996
|
+
* @property {number} [maxCanvasPixels] - The maximum supported canvas size in
|
|
997
|
+
* total pixels, i.e. width * height. Use `-1` for no limit, or `0` for
|
|
998
|
+
* CSS-only zooming. The default value is 4096 * 8192 (32 mega-pixels).
|
|
999
|
+
* @property {number} [maxCanvasDim] - The maximum supported canvas dimension,
|
|
1000
|
+
* in either width or height. Use `-1` for no limit.
|
|
1001
|
+
* The default value is 32767.
|
|
986
1002
|
* @property {Object} [pageColors] - Overwrites background and foreground colors
|
|
987
1003
|
* with user defined ones in order to improve readability in high contrast
|
|
988
1004
|
* mode.
|
|
@@ -1004,12 +1020,8 @@ class TempImageFactory {
|
|
|
1004
1020
|
return [tempCanvas, tempCanvas.getContext("2d")];
|
|
1005
1021
|
}
|
|
1006
1022
|
static destroyCanvas() {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
// Zeroing the width and height causes Firefox to release graphics
|
|
1010
|
-
// resources immediately, which can greatly reduce memory consumption.
|
|
1011
|
-
tempCanvas.width = 0;
|
|
1012
|
-
tempCanvas.height = 0;
|
|
1023
|
+
if (__classPrivateFieldGet(this, _a, "f", _TempImageFactory_tempCanvas)) {
|
|
1024
|
+
zeroCanvas(__classPrivateFieldGet(this, _a, "f", _TempImageFactory_tempCanvas));
|
|
1013
1025
|
}
|
|
1014
1026
|
__classPrivateFieldSet(this, _a, null, "f", _TempImageFactory_tempCanvas);
|
|
1015
1027
|
}
|
|
@@ -1023,7 +1035,7 @@ class PDFThumbnailView {
|
|
|
1023
1035
|
/**
|
|
1024
1036
|
* @param {PDFThumbnailViewOptions} options
|
|
1025
1037
|
*/
|
|
1026
|
-
constructor({ container, eventBus, id, defaultViewport, optionalContentConfigPromise, linkService, renderingQueue, pageColors, enableHWA, store, thumbnailWidth, }) {
|
|
1038
|
+
constructor({ container, eventBus, id, defaultViewport, optionalContentConfigPromise, linkService, renderingQueue, maxCanvasPixels, maxCanvasDim, pageColors, enableHWA, store, thumbnailWidth, }) {
|
|
1027
1039
|
_PDFThumbnailView_instances.add(this);
|
|
1028
1040
|
this.id = id;
|
|
1029
1041
|
this.renderingId = "thumbnail" + id;
|
|
@@ -1033,6 +1045,8 @@ class PDFThumbnailView {
|
|
|
1033
1045
|
this.viewport = defaultViewport;
|
|
1034
1046
|
this.pdfPageRotate = defaultViewport.rotation;
|
|
1035
1047
|
this._optionalContentConfigPromise = optionalContentConfigPromise || null;
|
|
1048
|
+
this.maxCanvasPixels = maxCanvasPixels !== null && maxCanvasPixels !== void 0 ? maxCanvasPixels : 4096 * 8192;
|
|
1049
|
+
this.maxCanvasDim = maxCanvasDim || 32767;
|
|
1036
1050
|
this.pageColors = pageColors || null;
|
|
1037
1051
|
this.enableHWA = enableHWA || false;
|
|
1038
1052
|
this.eventBus = eventBus;
|
|
@@ -1125,7 +1139,7 @@ class PDFThumbnailView {
|
|
|
1125
1139
|
console.error("Must be in new state before drawing");
|
|
1126
1140
|
return undefined;
|
|
1127
1141
|
}
|
|
1128
|
-
const { pdfPage } = this;
|
|
1142
|
+
const { pageColors, pdfPage } = this;
|
|
1129
1143
|
if (!pdfPage) {
|
|
1130
1144
|
this.renderingState = RenderingStates.FINISHED;
|
|
1131
1145
|
throw new Error("pdfPage is not loaded");
|
|
@@ -1152,27 +1166,45 @@ class PDFThumbnailView {
|
|
|
1152
1166
|
cont();
|
|
1153
1167
|
};
|
|
1154
1168
|
const renderContext = {
|
|
1169
|
+
canvas: canvas,
|
|
1155
1170
|
canvasContext: ctx,
|
|
1156
1171
|
transform,
|
|
1157
1172
|
viewport: drawViewport,
|
|
1158
1173
|
optionalContentConfigPromise: this._optionalContentConfigPromise,
|
|
1159
|
-
pageColors
|
|
1174
|
+
pageColors,
|
|
1160
1175
|
};
|
|
1161
1176
|
const renderTask = (this.renderTask = pdfPage.render(renderContext));
|
|
1162
1177
|
renderTask.onContinue = renderContinueCallback;
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1178
|
+
let error = null;
|
|
1179
|
+
try {
|
|
1180
|
+
yield renderTask.promise;
|
|
1181
|
+
}
|
|
1182
|
+
catch (e) {
|
|
1183
|
+
if (e instanceof RenderingCancelledException) {
|
|
1184
|
+
zeroCanvas(canvas);
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
error = e;
|
|
1188
|
+
}
|
|
1189
|
+
finally {
|
|
1190
|
+
// The renderTask may have been replaced by a new one, so only remove
|
|
1191
|
+
// the reference to the renderTask if it matches the one that is
|
|
1192
|
+
// triggering this callback.
|
|
1193
|
+
if (renderTask === this.renderTask) {
|
|
1194
|
+
this.renderTask = null;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
this.renderingState = RenderingStates.FINISHED;
|
|
1198
|
+
__classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_convertCanvasToImage).call(this, canvas);
|
|
1199
|
+
zeroCanvas(canvas);
|
|
1200
|
+
this.eventBus.dispatch("thumbnailrendered", {
|
|
1201
|
+
source: this,
|
|
1202
|
+
pageNumber: this.id,
|
|
1203
|
+
pdfPage,
|
|
1174
1204
|
});
|
|
1175
|
-
|
|
1205
|
+
if (error) {
|
|
1206
|
+
throw error;
|
|
1207
|
+
}
|
|
1176
1208
|
});
|
|
1177
1209
|
}
|
|
1178
1210
|
setImage(pageView) {
|
|
@@ -1225,8 +1257,10 @@ _PDFThumbnailView_instances = new WeakSet(), _PDFThumbnailView_updateDims = func
|
|
|
1225
1257
|
willReadFrequently: !enableHWA,
|
|
1226
1258
|
});
|
|
1227
1259
|
const outputScale = new OutputScale();
|
|
1228
|
-
|
|
1229
|
-
|
|
1260
|
+
const width = upscaleFactor * this.canvasWidth, height = upscaleFactor * this.canvasHeight;
|
|
1261
|
+
outputScale.limitCanvas(width, height, this.maxCanvasPixels, this.maxCanvasDim);
|
|
1262
|
+
canvas.width = (width * outputScale.sx) | 0;
|
|
1263
|
+
canvas.height = (height * outputScale.sy) | 0;
|
|
1230
1264
|
const transform = outputScale.scaled
|
|
1231
1265
|
? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
|
|
1232
1266
|
: null;
|
|
@@ -1255,23 +1289,14 @@ _PDFThumbnailView_instances = new WeakSet(), _PDFThumbnailView_updateDims = func
|
|
|
1255
1289
|
// resources immediately, which can greatly reduce memory consumption.
|
|
1256
1290
|
reducedCanvas.width = 0;
|
|
1257
1291
|
reducedCanvas.height = 0;
|
|
1258
|
-
},
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
if (error instanceof RenderingCancelledException) {
|
|
1267
|
-
return;
|
|
1268
|
-
}
|
|
1269
|
-
this.renderingState = RenderingStates.FINISHED;
|
|
1270
|
-
__classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_convertCanvasToImage).call(this, canvas);
|
|
1271
|
-
if (error) {
|
|
1272
|
-
throw error;
|
|
1273
|
-
}
|
|
1274
|
-
});
|
|
1292
|
+
}, _PDFThumbnailView_getReducedImageDims = function _PDFThumbnailView_getReducedImageDims(canvas) {
|
|
1293
|
+
const width = canvas.width << MAX_NUM_SCALING_STEPS, height = canvas.height << MAX_NUM_SCALING_STEPS;
|
|
1294
|
+
const outputScale = new OutputScale();
|
|
1295
|
+
// Here we're not actually "rendering" to the canvas and the `OutputScale`
|
|
1296
|
+
// is thus only used to limit the canvas size, hence the identity scale.
|
|
1297
|
+
outputScale.sx = outputScale.sy = 1;
|
|
1298
|
+
outputScale.limitCanvas(width, height, this.maxCanvasPixels, this.maxCanvasDim);
|
|
1299
|
+
return [(width * outputScale.sx) | 0, (height * outputScale.sy) | 0];
|
|
1275
1300
|
}, _PDFThumbnailView_reduceImage = function _PDFThumbnailView_reduceImage(img) {
|
|
1276
1301
|
const { ctx, canvas } = __classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_getPageDrawContext).call(this, 1, true);
|
|
1277
1302
|
if (img.width <= 2 * canvas.width) {
|
|
@@ -1279,8 +1304,7 @@ _PDFThumbnailView_instances = new WeakSet(), _PDFThumbnailView_updateDims = func
|
|
|
1279
1304
|
return canvas;
|
|
1280
1305
|
}
|
|
1281
1306
|
// drawImage does an awful job of rescaling the image, doing it gradually.
|
|
1282
|
-
let reducedWidth =
|
|
1283
|
-
let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
|
1307
|
+
let [reducedWidth, reducedHeight] = __classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_getReducedImageDims).call(this, canvas);
|
|
1284
1308
|
const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
|
1285
1309
|
while (reducedWidth > img.width || reducedHeight > img.height) {
|
|
1286
1310
|
reducedWidth >>= 1;
|
|
@@ -1320,12 +1344,14 @@ class PDFThumbnailViewer {
|
|
|
1320
1344
|
/**
|
|
1321
1345
|
* @param {PDFThumbnailViewerOptions} options
|
|
1322
1346
|
*/
|
|
1323
|
-
constructor({ container, eventBus, linkService, renderingQueue, pageColors, abortSignal, enableHWA, store, thumbnailWidth, }) {
|
|
1347
|
+
constructor({ container, eventBus, linkService, renderingQueue, maxCanvasPixels, maxCanvasDim, pageColors, abortSignal, enableHWA, store, thumbnailWidth, }) {
|
|
1324
1348
|
_PDFThumbnailViewer_instances.add(this);
|
|
1325
1349
|
this.container = container;
|
|
1326
1350
|
this.eventBus = eventBus;
|
|
1327
1351
|
this.linkService = linkService;
|
|
1328
1352
|
this.renderingQueue = renderingQueue;
|
|
1353
|
+
this.maxCanvasPixels = maxCanvasPixels || 4096 * 8192;
|
|
1354
|
+
this.maxCanvasDim = maxCanvasDim || 32767;
|
|
1329
1355
|
this.pageColors = pageColors || null;
|
|
1330
1356
|
this.enableHWA = enableHWA || false;
|
|
1331
1357
|
// <pdf-slick>
|
|
@@ -1433,6 +1459,8 @@ class PDFThumbnailViewer {
|
|
|
1433
1459
|
optionalContentConfigPromise,
|
|
1434
1460
|
linkService: this.linkService,
|
|
1435
1461
|
renderingQueue: this.renderingQueue,
|
|
1462
|
+
maxCanvasPixels: this.maxCanvasPixels,
|
|
1463
|
+
maxCanvasDim: this.maxCanvasDim,
|
|
1436
1464
|
pageColors: this.pageColors,
|
|
1437
1465
|
enableHWA: this.enableHWA,
|
|
1438
1466
|
store: this.store,
|
|
@@ -1481,7 +1509,9 @@ class PDFThumbnailViewer {
|
|
|
1481
1509
|
forceRendering() {
|
|
1482
1510
|
const visibleThumbs = __classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_getVisibleThumbs).call(this);
|
|
1483
1511
|
const scrollAhead = __classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_getScrollAhead).call(this, visibleThumbs);
|
|
1484
|
-
const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead
|
|
1512
|
+
const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead,
|
|
1513
|
+
/* preRenderExtra */ false,
|
|
1514
|
+
/* ignoreDetailViews */ true);
|
|
1485
1515
|
if (thumbView) {
|
|
1486
1516
|
__classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_ensurePdfPageLoaded).call(this, thumbView).then(() => {
|
|
1487
1517
|
this.renderingQueue.renderView(thumbView);
|
|
@@ -1568,7 +1598,7 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
|
|
|
1568
1598
|
linkService,
|
|
1569
1599
|
xfaHtml: xfaPage,
|
|
1570
1600
|
});
|
|
1571
|
-
const viewport =
|
|
1601
|
+
const viewport = XfaLayer.getPageViewport(xfaPage, { scale });
|
|
1572
1602
|
builder.render({ viewport, intent: "print" });
|
|
1573
1603
|
page.append(builder.div);
|
|
1574
1604
|
}
|
|
@@ -2208,8 +2238,8 @@ class PDFSlickPrintService {
|
|
|
2208
2238
|
__classPrivateFieldSet(this, _PDFSlickPrintService_eventAbortController, new AbortController(), "f");
|
|
2209
2239
|
const { signal } = __classPrivateFieldGet(this, _PDFSlickPrintService_eventAbortController, "f");
|
|
2210
2240
|
const opts = { signal };
|
|
2211
|
-
this.eventBus.
|
|
2212
|
-
this.eventBus.
|
|
2241
|
+
this.eventBus.on("beforeprint", __classPrivateFieldGet(this, _PDFSlickPrintService_instances, "m", _PDFSlickPrintService_beforePrint).bind(this), opts);
|
|
2242
|
+
this.eventBus.on("afterprint", __classPrivateFieldGet(this, _PDFSlickPrintService_instances, "m", _PDFSlickPrintService_afterPrint).bind(this), opts);
|
|
2213
2243
|
window.addEventListener("beforeprint", () => this.eventBus.dispatch("beforeprint", { source: window }), opts);
|
|
2214
2244
|
window.addEventListener("afterprint", () => this.eventBus.dispatch("afterprint", { source: window }), opts);
|
|
2215
2245
|
window.addEventListener("keydown", (event) => {
|
|
@@ -2247,7 +2277,7 @@ _PDFSlickPrintService_printService = new WeakMap(), _PDFSlickPrintService_eventA
|
|
|
2247
2277
|
// The beforePrint is a sync method and we need to know layout before
|
|
2248
2278
|
// returning from this method. Ensure that we can get sizes of the pages.
|
|
2249
2279
|
if (!this.slick.viewer.pageViewsReady) {
|
|
2250
|
-
this.slick.l10n.get("printing_not_ready", null).then((msg) => {
|
|
2280
|
+
this.slick.l10n.get("printing_not_ready", null, "Warning: The PDF is not fully loaded for printing.").then((msg) => {
|
|
2251
2281
|
// eslint-disable-next-line no-alert
|
|
2252
2282
|
window.alert(msg);
|
|
2253
2283
|
});
|
|
@@ -2433,7 +2463,7 @@ function getPageName(size, isPortrait, pageNames) {
|
|
|
2433
2463
|
}
|
|
2434
2464
|
class PDFSlick {
|
|
2435
2465
|
constructor({ container, viewer, thumbs, store = create(), options, onError, printDialog, }) {
|
|
2436
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
2466
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
2437
2467
|
_PDFSlick_instances.add(this);
|
|
2438
2468
|
_PDFSlick_renderingQueue.set(this, void 0);
|
|
2439
2469
|
_PDFSlick_container.set(this, void 0);
|
|
@@ -2464,10 +2494,16 @@ class PDFSlick {
|
|
|
2464
2494
|
this.enablePrintAutoRotate = (_h = options === null || options === void 0 ? void 0 : options.enablePrintAutoRotate) !== null && _h !== void 0 ? _h : false;
|
|
2465
2495
|
this.useOnlyCssZoom = (_j = options === null || options === void 0 ? void 0 : options.useOnlyCssZoom) !== null && _j !== void 0 ? _j : false;
|
|
2466
2496
|
this.pageColors = (_k = options === null || options === void 0 ? void 0 : options.pageColors) !== null && _k !== void 0 ? _k : null;
|
|
2467
|
-
this.maxCanvasPixels = (_l = options === null || options === void 0 ? void 0 : options.maxCanvasPixels) !== null && _l !== void 0 ? _l :
|
|
2468
|
-
this.
|
|
2469
|
-
this.
|
|
2470
|
-
this.
|
|
2497
|
+
this.maxCanvasPixels = (_l = options === null || options === void 0 ? void 0 : options.maxCanvasPixels) !== null && _l !== void 0 ? _l : Math.pow(2, 24);
|
|
2498
|
+
this.maxCanvasDim = (_m = options === null || options === void 0 ? void 0 : options.maxCanvasDim) !== null && _m !== void 0 ? _m : 32767;
|
|
2499
|
+
this.capCanvasAreaFactor = (_o = options === null || options === void 0 ? void 0 : options.capCanvasAreaFactor) !== null && _o !== void 0 ? _o : 200;
|
|
2500
|
+
this.printResolution = (_p = options === null || options === void 0 ? void 0 : options.printResolution) !== null && _p !== void 0 ? _p : 96;
|
|
2501
|
+
this.thumbnailWidth = (_q = options === null || options === void 0 ? void 0 : options.thumbnailWidth) !== null && _q !== void 0 ? _q : 125;
|
|
2502
|
+
this.enableHWA = (_r = options === null || options === void 0 ? void 0 : options.enableHWA) !== null && _r !== void 0 ? _r : false;
|
|
2503
|
+
this.enableDetailCanvas = (_s = options === null || options === void 0 ? void 0 : options.enableDetailCanvas) !== null && _s !== void 0 ? _s : true;
|
|
2504
|
+
this.enableOptimizedPartialRendering = (_t = options === null || options === void 0 ? void 0 : options.enableOptimizedPartialRendering) !== null && _t !== void 0 ? _t : false;
|
|
2505
|
+
this.minDurationToUpdateCanvas = (_u = options === null || options === void 0 ? void 0 : options.minDurationToUpdateCanvas) !== null && _u !== void 0 ? _u : 500;
|
|
2506
|
+
this.getDocumentParams = (_v = options === null || options === void 0 ? void 0 : options.getDocumentParams) !== null && _v !== void 0 ? _v : {};
|
|
2471
2507
|
if (this.pageColors &&
|
|
2472
2508
|
!(CSS.supports("color", this.pageColors.background) &&
|
|
2473
2509
|
CSS.supports("color", this.pageColors.foreground))) {
|
|
@@ -2491,7 +2527,7 @@ class PDFSlick {
|
|
|
2491
2527
|
const findController = new PDFFindController({ eventBus, linkService });
|
|
2492
2528
|
const viewerOptions = Object.assign(Object.assign({ container }, (viewer && { viewer })), { eventBus,
|
|
2493
2529
|
linkService,
|
|
2494
|
-
findController, renderingQueue: renderingQueue, textLayerMode: this.textLayerMode, annotationEditorHighlightColors: this.annotationEditorHighlightColors, l10n: this.l10n, annotationMode: __classPrivateFieldGet(this, _PDFSlick_annotationMode, "f"), annotationEditorMode: __classPrivateFieldGet(this, _PDFSlick_annotationEditorMode, "f"), removePageBorders: this.removePageBorders, imageResourcesPath: "/images/" });
|
|
2530
|
+
findController, renderingQueue: renderingQueue, textLayerMode: this.textLayerMode, annotationEditorHighlightColors: this.annotationEditorHighlightColors, l10n: this.l10n, annotationMode: __classPrivateFieldGet(this, _PDFSlick_annotationMode, "f"), annotationEditorMode: __classPrivateFieldGet(this, _PDFSlick_annotationEditorMode, "f"), removePageBorders: this.removePageBorders, imageResourcesPath: "/images/", enableDetailCanvas: this.enableDetailCanvas, enableOptimizedPartialRendering: this.enableOptimizedPartialRendering, minDurationToUpdateCanvas: this.minDurationToUpdateCanvas, maxCanvasPixels: this.useOnlyCssZoom === true ? 0 : this.maxCanvasPixels, maxCanvasDim: this.maxCanvasDim, capCanvasAreaFactor: this.capCanvasAreaFactor });
|
|
2495
2531
|
const pdfViewer = this.singlePageViewer
|
|
2496
2532
|
? new PDFSinglePageViewer(viewerOptions)
|
|
2497
2533
|
: new PDFViewer(viewerOptions);
|
|
@@ -2502,10 +2538,13 @@ class PDFSlick {
|
|
|
2502
2538
|
eventBus,
|
|
2503
2539
|
linkService,
|
|
2504
2540
|
renderingQueue,
|
|
2541
|
+
maxCanvasPixels: this.useOnlyCssZoom === true ? 0 : this.maxCanvasPixels,
|
|
2542
|
+
maxCanvasDim: this.maxCanvasDim,
|
|
2505
2543
|
pageColors: this.pageColors,
|
|
2506
|
-
enableHWA:
|
|
2544
|
+
enableHWA: this.enableHWA,
|
|
2507
2545
|
store: store,
|
|
2508
2546
|
thumbnailWidth: this.thumbnailWidth,
|
|
2547
|
+
abortSignal: (_w = __classPrivateFieldGet(this, _PDFSlick_eventAbortController, "f")) === null || _w === void 0 ? void 0 : _w.signal,
|
|
2509
2548
|
});
|
|
2510
2549
|
renderingQueue.setThumbnailViewer(this.thumbnailViewer);
|
|
2511
2550
|
}
|
|
@@ -2526,7 +2565,7 @@ class PDFSlick {
|
|
|
2526
2565
|
slick: this,
|
|
2527
2566
|
printDialog: printDialog !== null && printDialog !== void 0 ? printDialog : PDFSlickPrintDialog.create(),
|
|
2528
2567
|
}), "f");
|
|
2529
|
-
const scaleValue = (
|
|
2568
|
+
const scaleValue = (_x = options === null || options === void 0 ? void 0 : options.scaleValue) !== null && _x !== void 0 ? _x : "auto";
|
|
2530
2569
|
this.store.setState({ scaleValue });
|
|
2531
2570
|
}
|
|
2532
2571
|
loadDocument(url, options) {
|
|
@@ -2539,7 +2578,9 @@ class PDFSlick {
|
|
|
2539
2578
|
catch (err) { }
|
|
2540
2579
|
}
|
|
2541
2580
|
try {
|
|
2542
|
-
|
|
2581
|
+
// `PDFDocumentProxy.destroy()` was removed in pdfjs-dist v6; tear
|
|
2582
|
+
// down the previous document through its loading task instead.
|
|
2583
|
+
(_a = this.document) === null || _a === void 0 ? void 0 : _a.loadingTask.destroy();
|
|
2543
2584
|
(_b = this.viewer) === null || _b === void 0 ? void 0 : _b.cleanup();
|
|
2544
2585
|
if (url instanceof URL) {
|
|
2545
2586
|
this.url = url.toString();
|
|
@@ -2552,7 +2593,7 @@ class PDFSlick {
|
|
|
2552
2593
|
}
|
|
2553
2594
|
const filename = (_c = options === null || options === void 0 ? void 0 : options.filename) !== null && _c !== void 0 ? _c : getPdfFilenameFromUrl((_d = this.url) === null || _d === void 0 ? void 0 : _d.toString());
|
|
2554
2595
|
this.filename = filename;
|
|
2555
|
-
const pdfDocumentLoader = getDocument(Object.assign(Object.assign({}, this.getDocumentParams), { url: this.url,
|
|
2596
|
+
const pdfDocumentLoader = getDocument(Object.assign(Object.assign({}, this.getDocumentParams), { url: this.url, enableHWA: this.enableHWA }));
|
|
2556
2597
|
if (!!(options === null || options === void 0 ? void 0 : options.onProgress)) {
|
|
2557
2598
|
pdfDocumentLoader.onProgress = options.onProgress;
|
|
2558
2599
|
}
|
|
@@ -2601,20 +2642,22 @@ class PDFSlick {
|
|
|
2601
2642
|
}
|
|
2602
2643
|
download() {
|
|
2603
2644
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2604
|
-
var _a
|
|
2645
|
+
var _a;
|
|
2605
2646
|
const url = this.url;
|
|
2606
2647
|
const { filename } = this;
|
|
2648
|
+
let data;
|
|
2607
2649
|
try {
|
|
2608
2650
|
// this._ensureDownloadComplete();
|
|
2609
|
-
|
|
2610
|
-
const blob = new Blob([data], { type: "application/pdf" });
|
|
2611
|
-
yield ((_a = this.downloadManager) === null || _a === void 0 ? void 0 : _a.download(blob, url, filename));
|
|
2651
|
+
data = (yield this.document.getData()).slice(0);
|
|
2612
2652
|
}
|
|
2613
|
-
catch (
|
|
2653
|
+
catch (_b) {
|
|
2614
2654
|
// When the PDF document isn't ready, or the PDF file is still
|
|
2615
2655
|
// downloading, simply download using the URL.
|
|
2616
|
-
yield ((_b = this.downloadManager) === null || _b === void 0 ? void 0 : _b.download(null, url, filename));
|
|
2617
2656
|
}
|
|
2657
|
+
// As of pdfjs-dist v6, `download` takes the raw document data (a
|
|
2658
|
+
// `Uint8Array`) and builds the blob internally; a falsy `data` makes
|
|
2659
|
+
// it fall back to downloading directly from the URL.
|
|
2660
|
+
yield ((_a = this.downloadManager) === null || _a === void 0 ? void 0 : _a.download(data, url, filename));
|
|
2618
2661
|
});
|
|
2619
2662
|
}
|
|
2620
2663
|
save() {
|
|
@@ -2627,9 +2670,8 @@ class PDFSlick {
|
|
|
2627
2670
|
const { filename } = this;
|
|
2628
2671
|
try {
|
|
2629
2672
|
// this._ensureDownloadComplete();
|
|
2630
|
-
const data = yield this.document.saveDocument();
|
|
2631
|
-
|
|
2632
|
-
yield ((_a = this.downloadManager) === null || _a === void 0 ? void 0 : _a.download(blob, url, filename));
|
|
2673
|
+
const data = (yield this.document.saveDocument()).slice(0);
|
|
2674
|
+
yield ((_a = this.downloadManager) === null || _a === void 0 ? void 0 : _a.download(data, url, filename));
|
|
2633
2675
|
}
|
|
2634
2676
|
catch (reason) {
|
|
2635
2677
|
// When the PDF document isn't ready, or the PDF file is still
|
|
@@ -2713,7 +2755,7 @@ class PDFSlick {
|
|
|
2713
2755
|
this.setAnnotationEditorMode(AnnotationEditorType.HIGHLIGHT);
|
|
2714
2756
|
this.setAnnotationEditorParams([
|
|
2715
2757
|
{
|
|
2716
|
-
type: AnnotationEditorParamsType.
|
|
2758
|
+
type: AnnotationEditorParamsType.HIGHLIGHT_COLOR,
|
|
2717
2759
|
value: color,
|
|
2718
2760
|
},
|
|
2719
2761
|
]);
|
|
@@ -2904,10 +2946,12 @@ _PDFSlick_renderingQueue = new WeakMap(), _PDFSlick_container = new WeakMap(), _
|
|
|
2904
2946
|
}
|
|
2905
2947
|
const [{ width, height }, unit, name, orientation] = yield Promise.all([
|
|
2906
2948
|
sizeInches ,
|
|
2907
|
-
|
|
2949
|
+
// pdfjs-dist v6 `L10n.get(ids, args, fallback)` requires a fallback
|
|
2950
|
+
// value, which is returned when the id isn't in the l10n bundle.
|
|
2951
|
+
this.l10n.get(`document_properties_page_size_unit_${"inches" }`, null, "in" ),
|
|
2908
2952
|
rawName &&
|
|
2909
|
-
this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`, null),
|
|
2910
|
-
this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`, null),
|
|
2953
|
+
this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`, null, rawName),
|
|
2954
|
+
this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`, null, isPortrait ? "portrait" : "landscape"),
|
|
2911
2955
|
]);
|
|
2912
2956
|
return {
|
|
2913
2957
|
width: width.toLocaleString(),
|
|
@@ -2921,21 +2965,20 @@ _PDFSlick_renderingQueue = new WeakMap(), _PDFSlick_container = new WeakMap(), _
|
|
|
2921
2965
|
__classPrivateFieldSet(this, _PDFSlick_eventAbortController, new AbortController(), "f");
|
|
2922
2966
|
const { signal } = __classPrivateFieldGet(this, _PDFSlick_eventAbortController, "f");
|
|
2923
2967
|
const opts = { signal };
|
|
2924
|
-
this.eventBus.
|
|
2925
|
-
this.eventBus.
|
|
2926
|
-
this.eventBus.
|
|
2927
|
-
this.eventBus.
|
|
2928
|
-
this.eventBus.
|
|
2929
|
-
this.eventBus.
|
|
2930
|
-
this.eventBus.
|
|
2968
|
+
this.eventBus.on("pagesinit", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onDocumentReady).bind(this), opts);
|
|
2969
|
+
this.eventBus.on("scalechanging", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onScaleChanging).bind(this), opts);
|
|
2970
|
+
this.eventBus.on("pagechanging", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onPageChanging).bind(this), opts);
|
|
2971
|
+
this.eventBus.on("pagerendered", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onPageRendered).bind(this), opts);
|
|
2972
|
+
this.eventBus.on("rotationchanging", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onRotationChanging).bind(this), opts);
|
|
2973
|
+
this.eventBus.on("switchspreadmode", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onSwitchSpreadMode).bind(this), opts);
|
|
2974
|
+
this.eventBus.on("switchscrollmode", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onSwitchScrollMode).bind(this), opts);
|
|
2931
2975
|
}, _PDFSlick_onDocumentReady = function _PDFSlick_onDocumentReady(_a) {
|
|
2932
2976
|
return __awaiter(this, arguments, void 0, function* ({ source }) {
|
|
2933
2977
|
var _b;
|
|
2934
2978
|
const documentOutline = (yield ((_b = this.document) === null || _b === void 0 ? void 0 : _b.getOutline()));
|
|
2935
2979
|
const scaleValue = this.store.getState().scaleValue;
|
|
2936
|
-
// source.
|
|
2937
|
-
source.
|
|
2938
|
-
source.currentScaleValue = "auto";
|
|
2980
|
+
// source.currentScale = 1;
|
|
2981
|
+
source.currentScaleValue = scaleValue !== null && scaleValue !== void 0 ? scaleValue : "auto";
|
|
2939
2982
|
this.store.setState({
|
|
2940
2983
|
documentOutline,
|
|
2941
2984
|
pageNumber: 1,
|
|
@@ -2974,4 +3017,4 @@ _PDFSlick_renderingQueue = new WeakMap(), _PDFSlick_container = new WeakMap(), _
|
|
|
2974
3017
|
}
|
|
2975
3018
|
};
|
|
2976
3019
|
|
|
2977
|
-
export { AutoPrintRegExp, CursorTool, DEFAULT_SCALE, DEFAULT_SCALE_DELTA, DEFAULT_SCALE_VALUE, MAX_AUTO_SCALE, MAX_SCALE, MIN_SCALE,
|
|
3020
|
+
export { AutoPrintRegExp, CursorTool, DEFAULT_SCALE, DEFAULT_SCALE_DELTA, DEFAULT_SCALE_VALUE, MAX_AUTO_SCALE, MAX_SCALE, MIN_SCALE, PDFSlick, PresentationModeState, ProgressBar, RendererType, RenderingStates, SCROLLBAR_PADDING, ScrollMode, SidebarView, SpreadMode, TextLayerMode, UNKNOWN_SCALE, VERTICAL_PADDING, animationStarted, apiPageLayoutToViewerModes, apiPageModeToSidebarView, approximateFraction, backtrackBeforeAllVisibleElements, binarySearchFirstItem, calcRound, create, docStyle, floorToDivide, getActiveOrFocusedElement, getPageSizeInches, getVisibleElements, initialState, isPortraitOrientation, isValidRotation, isValidScrollMode, isValidSpreadMode, normalizeWheelEventDelta, normalizeWheelEventDirection, parseQueryString, removeNullCharacters, scrollIntoView, toggleCheckedBtn, toggleExpandedBtn, watchScroll };
|