@pdfslick/core 2.1.3 → 2.2.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/dist/esm/PDFSlick.d.ts +2 -4
- package/dist/esm/PDFSlick.d.ts.map +1 -1
- package/dist/esm/PDFSlickPrintDialog.d.ts +24 -0
- package/dist/esm/PDFSlickPrintDialog.d.ts.map +1 -0
- package/dist/esm/PDFSlickPrintService.d.ts +23 -0
- package/dist/esm/PDFSlickPrintService.d.ts.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +763 -773
- package/dist/esm/lib/pdf_presentation_mode.d.ts +10 -9
- package/dist/esm/lib/pdf_presentation_mode.d.ts.map +1 -1
- package/dist/esm/lib/pdf_print_service.d.ts +26 -9
- package/dist/esm/lib/pdf_print_service.d.ts.map +1 -1
- package/dist/esm/lib/pdf_rendering_queue.d.ts +4 -12
- package/dist/esm/lib/pdf_rendering_queue.d.ts.map +1 -1
- package/dist/esm/lib/pdf_thumbnail_view.d.ts +33 -41
- package/dist/esm/lib/pdf_thumbnail_view.d.ts.map +1 -1
- package/dist/esm/lib/pdf_thumbnail_viewer.d.ts +35 -72
- package/dist/esm/lib/pdf_thumbnail_viewer.d.ts.map +1 -1
- package/dist/esm/lib/ui_utils.d.ts +42 -51
- package/dist/esm/lib/ui_utils.d.ts.map +1 -1
- package/dist/esm/types.d.ts +2 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/pdf_viewer.css +110 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/umd/index.js +2 -2
- package/package.json +4 -7
- package/dist/esm/lib/overlay_manager.d.ts +0 -32
- package/dist/esm/lib/overlay_manager.d.ts.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderingCancelledException, PixelsPerInch, getXfaPageViewport, AnnotationMode, AnnotationEditorType, GlobalWorkerOptions, getPdfFilenameFromUrl, getDocument,
|
|
1
|
+
import { RenderingCancelledException, PixelsPerInch, getXfaPageViewport, AnnotationMode, AnnotationEditorType, GlobalWorkerOptions, AnnotationEditorParamsType, getPdfFilenameFromUrl, getDocument, PDFDateString } from 'pdfjs-dist';
|
|
2
2
|
import { SimpleLinkService, XfaLayerBuilder, GenericL10n, DownloadManager, EventBus, PDFLinkService, PDFSinglePageViewer, PDFViewer } from 'pdfjs-dist/web/pdf_viewer.mjs';
|
|
3
3
|
import { createStore } from 'zustand/vanilla';
|
|
4
4
|
|
|
@@ -98,6 +98,7 @@ const RendererType = {
|
|
|
98
98
|
const TextLayerMode = {
|
|
99
99
|
DISABLE: 0,
|
|
100
100
|
ENABLE: 1,
|
|
101
|
+
ENABLE_PERMISSIONS: 2,
|
|
101
102
|
};
|
|
102
103
|
const ScrollMode = {
|
|
103
104
|
UNKNOWN: -1,
|
|
@@ -143,9 +144,11 @@ class OutputScale {
|
|
|
143
144
|
}
|
|
144
145
|
/**
|
|
145
146
|
* Scrolls specified element into view of its parent.
|
|
146
|
-
* @param {
|
|
147
|
-
* @param {Object} spot - An object with optional top and left properties,
|
|
147
|
+
* @param {HTMLElement} element - The element to be visible.
|
|
148
|
+
* @param {Object} [spot] - An object with optional top and left properties,
|
|
148
149
|
* specifying the offset from the top left edge.
|
|
150
|
+
* @param {number} [spot.left]
|
|
151
|
+
* @param {number} [spot.top]
|
|
149
152
|
* @param {boolean} [scrollMatches] - When scrolling search results into view,
|
|
150
153
|
* ignore elements that either: Contains marked content identifiers,
|
|
151
154
|
* or have the CSS-rule `overflow: hidden;` set. The default value is `false`.
|
|
@@ -183,13 +186,12 @@ function scrollIntoView(element, spot, scrollMatches = false) {
|
|
|
183
186
|
}
|
|
184
187
|
}
|
|
185
188
|
parent.scrollTop = offsetY;
|
|
186
|
-
parent.scrollLeft = offsetX;
|
|
187
189
|
}
|
|
188
190
|
/**
|
|
189
191
|
* Helper function to start monitoring the scroll event and converting them into
|
|
190
192
|
* PDF.js friendly one: with scroll debounce and scroll direction.
|
|
191
193
|
*/
|
|
192
|
-
function watchScroll(viewAreaElement, callback) {
|
|
194
|
+
function watchScroll(viewAreaElement, callback, abortSignal = undefined) {
|
|
193
195
|
const debounceScroll = function (evt) {
|
|
194
196
|
if (rAF) {
|
|
195
197
|
return;
|
|
@@ -220,12 +222,16 @@ function watchScroll(viewAreaElement, callback) {
|
|
|
220
222
|
_eventHandler: debounceScroll,
|
|
221
223
|
};
|
|
222
224
|
let rAF = null;
|
|
223
|
-
viewAreaElement.addEventListener("scroll", debounceScroll,
|
|
225
|
+
viewAreaElement.addEventListener("scroll", debounceScroll, {
|
|
226
|
+
useCapture: true,
|
|
227
|
+
signal: abortSignal,
|
|
228
|
+
});
|
|
229
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener("abort", () => window.cancelAnimationFrame(rAF), { once: true });
|
|
224
230
|
return state;
|
|
225
231
|
}
|
|
226
232
|
/**
|
|
227
233
|
* Helper function to parse query string (e.g. ?param1=value¶m2=...).
|
|
228
|
-
* @param {string}
|
|
234
|
+
* @param {string} query
|
|
229
235
|
* @returns {Map}
|
|
230
236
|
*/
|
|
231
237
|
function parseQueryString(query) {
|
|
@@ -235,21 +241,19 @@ function parseQueryString(query) {
|
|
|
235
241
|
}
|
|
236
242
|
return params;
|
|
237
243
|
}
|
|
238
|
-
const
|
|
239
|
-
const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
|
|
244
|
+
const InvisibleCharsRegExp = /[\x00-\x1F]/g;
|
|
240
245
|
/**
|
|
241
246
|
* @param {string} str
|
|
242
247
|
* @param {boolean} [replaceInvisible]
|
|
243
248
|
*/
|
|
244
249
|
function removeNullCharacters(str, replaceInvisible = false) {
|
|
245
|
-
if (
|
|
246
|
-
console.error(`The argument must be a string.`);
|
|
250
|
+
if (!InvisibleCharsRegExp.test(str)) {
|
|
247
251
|
return str;
|
|
248
252
|
}
|
|
249
253
|
if (replaceInvisible) {
|
|
250
|
-
|
|
254
|
+
return str.replaceAll(InvisibleCharsRegExp, m => (m === "\x00" ? "" : " "));
|
|
251
255
|
}
|
|
252
|
-
return str.
|
|
256
|
+
return str.replaceAll("\x00", "");
|
|
253
257
|
}
|
|
254
258
|
/**
|
|
255
259
|
* Use binary search to find the index of the first item in a given array which
|
|
@@ -287,6 +291,7 @@ function binarySearchFirstItem(items, condition, start = 0) {
|
|
|
287
291
|
* @param {number} x - Positive float number.
|
|
288
292
|
* @returns {Array} Estimated fraction: the first array item is a numerator,
|
|
289
293
|
* the second one is a denominator.
|
|
294
|
+
* They are both natural numbers.
|
|
290
295
|
*/
|
|
291
296
|
function approximateFraction(x) {
|
|
292
297
|
// Fast paths for int numbers or their inversions.
|
|
@@ -330,27 +335,19 @@ function approximateFraction(x) {
|
|
|
330
335
|
}
|
|
331
336
|
return result;
|
|
332
337
|
}
|
|
333
|
-
function roundToDivide(x, div) {
|
|
334
|
-
const r = x % div;
|
|
335
|
-
return r === 0 ? x : Math.round(x - r + div);
|
|
336
|
-
}
|
|
337
338
|
/**
|
|
338
|
-
* @
|
|
339
|
-
* @
|
|
340
|
-
* @property {number} userUnit
|
|
341
|
-
* @property {number} rotate
|
|
342
|
-
*/
|
|
343
|
-
/**
|
|
344
|
-
* @typedef {Object} PageSize
|
|
345
|
-
* @property {number} width - In inches.
|
|
346
|
-
* @property {number} height - In inches.
|
|
339
|
+
* @param {number} x - A positive number to round to a multiple of `div`.
|
|
340
|
+
* @param {number} div - A natural number.
|
|
347
341
|
*/
|
|
342
|
+
function floorToDivide(x, div) {
|
|
343
|
+
return x - (x % div);
|
|
344
|
+
}
|
|
348
345
|
/**
|
|
349
346
|
* Gets the size of the specified page, converted from PDF units to inches.
|
|
350
347
|
* @param {GetPageSizeInchesParameters} params
|
|
351
348
|
* @returns {PageSize}
|
|
352
349
|
*/
|
|
353
|
-
function getPageSizeInches({ view, userUnit, rotate
|
|
350
|
+
function getPageSizeInches({ view, userUnit, rotate }) {
|
|
354
351
|
const [x1, y1, x2, y2] = view;
|
|
355
352
|
// We need to take the page rotation into account as well.
|
|
356
353
|
const changeOrientation = rotate % 180 !== 0;
|
|
@@ -471,7 +468,7 @@ function backtrackBeforeAllVisibleElements(index, views, top) {
|
|
|
471
468
|
* rendering canvas. Earlier and later refer to index in `views`, not page
|
|
472
469
|
* layout.)
|
|
473
470
|
*
|
|
474
|
-
* @param {GetVisibleElementsParameters}
|
|
471
|
+
* @param {GetVisibleElementsParameters} params
|
|
475
472
|
* @returns {Object} `{ first, last, views: [{ id, x, y, view, percent }] }`
|
|
476
473
|
*/
|
|
477
474
|
function getVisibleElements({ scrollEl, views, sortByVisibility = false, horizontal = false, rtl = false, }) {
|
|
@@ -574,12 +571,6 @@ function getVisibleElements({ scrollEl, views, sortByVisibility = false, horizon
|
|
|
574
571
|
}
|
|
575
572
|
return { first, last, views: visible, ids };
|
|
576
573
|
}
|
|
577
|
-
/**
|
|
578
|
-
* Event handler to suppress context menu.
|
|
579
|
-
*/
|
|
580
|
-
function noContextMenuHandler(evt) {
|
|
581
|
-
evt.preventDefault();
|
|
582
|
-
}
|
|
583
574
|
function normalizeWheelEventDirection(evt) {
|
|
584
575
|
let delta = Math.hypot(evt.deltaX, evt.deltaY);
|
|
585
576
|
const angle = Math.atan2(evt.deltaY, evt.deltaX);
|
|
@@ -631,10 +622,10 @@ function clamp(v, min, max) {
|
|
|
631
622
|
}
|
|
632
623
|
class ProgressBar {
|
|
633
624
|
constructor(bar) {
|
|
634
|
-
_ProgressBar_classList.set(this,
|
|
625
|
+
_ProgressBar_classList.set(this, void 0);
|
|
635
626
|
_ProgressBar_disableAutoFetchTimeout.set(this, null);
|
|
636
627
|
_ProgressBar_percent.set(this, 0);
|
|
637
|
-
_ProgressBar_style.set(this,
|
|
628
|
+
_ProgressBar_style.set(this, void 0);
|
|
638
629
|
_ProgressBar_visible.set(this, true);
|
|
639
630
|
__classPrivateFieldSet(this, _ProgressBar_classList, bar.classList, "f");
|
|
640
631
|
__classPrivateFieldSet(this, _ProgressBar_style, bar.style, "f");
|
|
@@ -643,28 +634,26 @@ class ProgressBar {
|
|
|
643
634
|
return __classPrivateFieldGet(this, _ProgressBar_percent, "f");
|
|
644
635
|
}
|
|
645
636
|
set percent(val) {
|
|
646
|
-
var _a, _b, _c;
|
|
647
637
|
__classPrivateFieldSet(this, _ProgressBar_percent, clamp(val, 0, 100), "f");
|
|
648
638
|
if (isNaN(val)) {
|
|
649
|
-
|
|
639
|
+
__classPrivateFieldGet(this, _ProgressBar_classList, "f").add("indeterminate");
|
|
650
640
|
return;
|
|
651
641
|
}
|
|
652
|
-
|
|
653
|
-
|
|
642
|
+
__classPrivateFieldGet(this, _ProgressBar_classList, "f").remove("indeterminate");
|
|
643
|
+
__classPrivateFieldGet(this, _ProgressBar_style, "f").setProperty("--progressBar-percent", `${__classPrivateFieldGet(this, _ProgressBar_percent, "f")}%`);
|
|
654
644
|
}
|
|
655
645
|
setWidth(viewer) {
|
|
656
|
-
var _a;
|
|
657
646
|
if (!viewer) {
|
|
658
647
|
return;
|
|
659
648
|
}
|
|
660
649
|
const container = viewer.parentNode;
|
|
661
650
|
const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
|
|
662
651
|
if (scrollbarWidth > 0) {
|
|
663
|
-
|
|
652
|
+
__classPrivateFieldGet(this, _ProgressBar_style, "f").setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
|
|
664
653
|
}
|
|
665
654
|
}
|
|
666
655
|
setDisableAutoFetch(delay = /* ms = */ 5000) {
|
|
667
|
-
if (isNaN(__classPrivateFieldGet(this, _ProgressBar_percent, "f"))) {
|
|
656
|
+
if (__classPrivateFieldGet(this, _ProgressBar_percent, "f") === 100 || isNaN(__classPrivateFieldGet(this, _ProgressBar_percent, "f"))) {
|
|
668
657
|
return;
|
|
669
658
|
}
|
|
670
659
|
if (__classPrivateFieldGet(this, _ProgressBar_disableAutoFetchTimeout, "f")) {
|
|
@@ -677,20 +666,18 @@ class ProgressBar {
|
|
|
677
666
|
}, delay), "f");
|
|
678
667
|
}
|
|
679
668
|
hide() {
|
|
680
|
-
var _a;
|
|
681
669
|
if (!__classPrivateFieldGet(this, _ProgressBar_visible, "f")) {
|
|
682
670
|
return;
|
|
683
671
|
}
|
|
684
672
|
__classPrivateFieldSet(this, _ProgressBar_visible, false, "f");
|
|
685
|
-
|
|
673
|
+
__classPrivateFieldGet(this, _ProgressBar_classList, "f").add("hidden");
|
|
686
674
|
}
|
|
687
675
|
show() {
|
|
688
|
-
var _a;
|
|
689
676
|
if (__classPrivateFieldGet(this, _ProgressBar_visible, "f")) {
|
|
690
677
|
return;
|
|
691
678
|
}
|
|
692
679
|
__classPrivateFieldSet(this, _ProgressBar_visible, true, "f");
|
|
693
|
-
|
|
680
|
+
__classPrivateFieldGet(this, _ProgressBar_classList, "f").remove("hidden");
|
|
694
681
|
}
|
|
695
682
|
}
|
|
696
683
|
_ProgressBar_classList = new WeakMap(), _ProgressBar_disableAutoFetchTimeout = new WeakMap(), _ProgressBar_percent = new WeakMap(), _ProgressBar_style = new WeakMap(), _ProgressBar_visible = new WeakMap();
|
|
@@ -705,7 +692,7 @@ _ProgressBar_classList = new WeakMap(), _ProgressBar_disableAutoFetchTimeout = n
|
|
|
705
692
|
function getActiveOrFocusedElement() {
|
|
706
693
|
let curRoot = document;
|
|
707
694
|
let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
|
|
708
|
-
while (curActiveOrFocused === null || curActiveOrFocused ===
|
|
695
|
+
while (curActiveOrFocused === null || curActiveOrFocused === void 0 ? void 0 : curActiveOrFocused.shadowRoot) {
|
|
709
696
|
curRoot = curActiveOrFocused.shadowRoot;
|
|
710
697
|
curActiveOrFocused =
|
|
711
698
|
curRoot.activeElement || curRoot.querySelector(":focus");
|
|
@@ -714,7 +701,7 @@ function getActiveOrFocusedElement() {
|
|
|
714
701
|
}
|
|
715
702
|
/**
|
|
716
703
|
* Converts API PageLayout values to the format used by `BaseViewer`.
|
|
717
|
-
* @param {string}
|
|
704
|
+
* @param {string} layout - The API PageLayout value.
|
|
718
705
|
* @returns {Object}
|
|
719
706
|
*/
|
|
720
707
|
function apiPageLayoutToViewerModes(layout) {
|
|
@@ -763,6 +750,24 @@ function apiPageModeToSidebarView(mode) {
|
|
|
763
750
|
}
|
|
764
751
|
return SidebarView.NONE; // Default value.
|
|
765
752
|
}
|
|
753
|
+
function toggleCheckedBtn(button, toggle, view = null) {
|
|
754
|
+
button.classList.toggle("toggled", toggle);
|
|
755
|
+
button.setAttribute("aria-checked", String(toggle));
|
|
756
|
+
view === null || view === void 0 ? void 0 : view.classList.toggle("hidden", !toggle);
|
|
757
|
+
}
|
|
758
|
+
function toggleExpandedBtn(button, toggle, view = null) {
|
|
759
|
+
button.classList.toggle("toggled", toggle);
|
|
760
|
+
button.setAttribute("aria-expanded", String(toggle));
|
|
761
|
+
view === null || view === void 0 ? void 0 : view.classList.toggle("hidden", !toggle);
|
|
762
|
+
}
|
|
763
|
+
// In Firefox, the css calc function uses f32 precision but the Chrome or Safari
|
|
764
|
+
// are using f64 one. So in order to have the same rendering in all browsers, we
|
|
765
|
+
// need to use the right precision in order to have correct dimensions.
|
|
766
|
+
const calcRound = (function () {
|
|
767
|
+
const e = document.createElement("div");
|
|
768
|
+
e.style.width = "round(down, calc(1.6666666666666665 * 792px), 1px)";
|
|
769
|
+
return e.style.width === "calc(1320px)" ? Math.fround : x => x;
|
|
770
|
+
})();
|
|
766
771
|
|
|
767
772
|
/* Copyright 2012 Mozilla Foundation
|
|
768
773
|
*
|
|
@@ -796,6 +801,11 @@ class PDFRenderingQueue {
|
|
|
796
801
|
this.idleTimeout = null;
|
|
797
802
|
this.printing = false;
|
|
798
803
|
this.isThumbnailViewEnabled = false;
|
|
804
|
+
{
|
|
805
|
+
Object.defineProperty(this, "hasViewer", {
|
|
806
|
+
value: () => !!this.pdfViewer,
|
|
807
|
+
});
|
|
808
|
+
}
|
|
799
809
|
}
|
|
800
810
|
/**
|
|
801
811
|
* @param {PDFViewer} pdfViewer
|
|
@@ -816,28 +826,22 @@ class PDFRenderingQueue {
|
|
|
816
826
|
isHighestPriority(view) {
|
|
817
827
|
return this.highestPriorityPage === view.renderingId;
|
|
818
828
|
}
|
|
819
|
-
/**
|
|
820
|
-
* @returns {boolean}
|
|
821
|
-
*/
|
|
822
|
-
hasViewer() {
|
|
823
|
-
return !!this.pdfViewer;
|
|
824
|
-
}
|
|
825
829
|
/**
|
|
826
830
|
* @param {Object} currentlyVisiblePages
|
|
827
831
|
*/
|
|
828
832
|
renderHighestPriority(currentlyVisiblePages) {
|
|
829
|
-
var _a
|
|
833
|
+
var _a;
|
|
830
834
|
if (this.idleTimeout) {
|
|
831
835
|
clearTimeout(this.idleTimeout);
|
|
832
836
|
this.idleTimeout = null;
|
|
833
837
|
}
|
|
834
838
|
// Pages have a higher priority than thumbnails, so check them first.
|
|
835
|
-
if (
|
|
839
|
+
if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
|
|
836
840
|
return;
|
|
837
841
|
}
|
|
838
842
|
// No pages needed rendering, so check thumbnails.
|
|
839
843
|
if (this.isThumbnailViewEnabled &&
|
|
840
|
-
((
|
|
844
|
+
((_a = this.pdfThumbnailViewer) === null || _a === void 0 ? void 0 : _a.forceRendering())) {
|
|
841
845
|
return;
|
|
842
846
|
}
|
|
843
847
|
if (this.printing) {
|
|
@@ -939,11 +943,11 @@ class PDFRenderingQueue {
|
|
|
939
943
|
.finally(() => {
|
|
940
944
|
this.renderHighestPriority();
|
|
941
945
|
})
|
|
942
|
-
.catch(
|
|
946
|
+
.catch(reason => {
|
|
943
947
|
if (reason instanceof RenderingCancelledException) {
|
|
944
948
|
return;
|
|
945
949
|
}
|
|
946
|
-
console.error(
|
|
950
|
+
console.error("renderView:", reason);
|
|
947
951
|
});
|
|
948
952
|
break;
|
|
949
953
|
}
|
|
@@ -965,7 +969,7 @@ class PDFRenderingQueue {
|
|
|
965
969
|
* See the License for the specific language governing permissions and
|
|
966
970
|
* limitations under the License.
|
|
967
971
|
*/
|
|
968
|
-
var _a, _TempImageFactory_tempCanvas;
|
|
972
|
+
var _a, _TempImageFactory_tempCanvas, _PDFThumbnailView_instances, _PDFThumbnailView_updateDims, _PDFThumbnailView_getPageDrawContext, _PDFThumbnailView_convertCanvasToImage, _PDFThumbnailView_finishRenderTask, _PDFThumbnailView_reduceImage;
|
|
969
973
|
const DRAW_UPSCALE_FACTOR = 2; // See comment in `PDFThumbnailView.draw` below.
|
|
970
974
|
const MAX_NUM_SCALING_STEPS = 3;
|
|
971
975
|
/**
|
|
@@ -979,10 +983,11 @@ const MAX_NUM_SCALING_STEPS = 3;
|
|
|
979
983
|
* The default value is `null`.
|
|
980
984
|
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
|
981
985
|
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
|
982
|
-
* @property {IL10n} l10n - Localization service.
|
|
983
986
|
* @property {Object} [pageColors] - Overwrites background and foreground colors
|
|
984
987
|
* with user defined ones in order to improve readability in high contrast
|
|
985
988
|
* mode.
|
|
989
|
+
* @property {boolean} [enableHWA] - Enables hardware acceleration for
|
|
990
|
+
* rendering. The default value is `false`.
|
|
986
991
|
*/
|
|
987
992
|
class TempImageFactory {
|
|
988
993
|
static getCanvas(width, height) {
|
|
@@ -990,14 +995,13 @@ class TempImageFactory {
|
|
|
990
995
|
tempCanvas.width = width;
|
|
991
996
|
tempCanvas.height = height;
|
|
992
997
|
// Since this is a temporary canvas, we need to fill it with a white
|
|
993
|
-
// background ourselves. `
|
|
998
|
+
// background ourselves. `#getPageDrawContext` uses CSS rules for this.
|
|
994
999
|
const ctx = tempCanvas.getContext("2d", { alpha: false });
|
|
995
1000
|
ctx.save();
|
|
996
1001
|
ctx.fillStyle = "rgb(255, 255, 255)";
|
|
997
1002
|
ctx.fillRect(0, 0, width, height);
|
|
998
1003
|
ctx.restore();
|
|
999
|
-
|
|
1000
|
-
return [tempCanvas, c];
|
|
1004
|
+
return [tempCanvas, tempCanvas.getContext("2d")];
|
|
1001
1005
|
}
|
|
1002
1006
|
static destroyCanvas() {
|
|
1003
1007
|
const tempCanvas = __classPrivateFieldGet(this, _a, "f", _TempImageFactory_tempCanvas);
|
|
@@ -1019,37 +1023,56 @@ class PDFThumbnailView {
|
|
|
1019
1023
|
/**
|
|
1020
1024
|
* @param {PDFThumbnailViewOptions} options
|
|
1021
1025
|
*/
|
|
1022
|
-
constructor({ container, eventBus, id, defaultViewport, optionalContentConfigPromise, linkService, renderingQueue,
|
|
1023
|
-
this
|
|
1024
|
-
this.eventBus = eventBus;
|
|
1026
|
+
constructor({ container, eventBus, id, defaultViewport, optionalContentConfigPromise, linkService, renderingQueue, pageColors, enableHWA, store, thumbnailWidth, }) {
|
|
1027
|
+
_PDFThumbnailView_instances.add(this);
|
|
1025
1028
|
this.id = id;
|
|
1026
1029
|
this.renderingId = "thumbnail" + id;
|
|
1027
1030
|
this.pageLabel = null;
|
|
1028
|
-
this.store = store;
|
|
1029
|
-
this.loaded = false;
|
|
1030
1031
|
this.pdfPage = null;
|
|
1031
1032
|
this.rotation = 0;
|
|
1032
1033
|
this.viewport = defaultViewport;
|
|
1033
1034
|
this.pdfPageRotate = defaultViewport.rotation;
|
|
1034
1035
|
this._optionalContentConfigPromise = optionalContentConfigPromise || null;
|
|
1035
1036
|
this.pageColors = pageColors || null;
|
|
1037
|
+
this.enableHWA = enableHWA || false;
|
|
1038
|
+
this.eventBus = eventBus;
|
|
1036
1039
|
this.linkService = linkService;
|
|
1037
1040
|
this.renderingQueue = renderingQueue;
|
|
1038
1041
|
this.renderTask = null;
|
|
1039
1042
|
this.renderingState = RenderingStates.INITIAL;
|
|
1040
1043
|
this.resume = null;
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1044
|
+
// <pdf-slick>
|
|
1045
|
+
// const anchor = document.createElement("a");
|
|
1046
|
+
// anchor.href = linkService.getAnchorUrl("#page=" + id);
|
|
1047
|
+
// anchor.setAttribute("data-l10n-id", "pdfjs-thumb-page-title");
|
|
1048
|
+
// anchor.setAttribute("data-l10n-args", this.#pageL10nArgs);
|
|
1049
|
+
// anchor.onclick = function () {
|
|
1050
|
+
// linkService.goToPage(id);
|
|
1051
|
+
// return false;
|
|
1052
|
+
// };
|
|
1053
|
+
// this.anchor = anchor;
|
|
1054
|
+
// const div = document.createElement("div");
|
|
1055
|
+
// div.className = "thumbnail pdfSlickThumbHolder"; // <pdf-slick>
|
|
1056
|
+
// div.setAttribute("data-page-number", String(this.id));
|
|
1057
|
+
// this.div = div;
|
|
1058
|
+
// this.#updateDims();
|
|
1059
|
+
// const img = document.createElement("div");
|
|
1060
|
+
// img.className = "thumbnailImage";
|
|
1061
|
+
// this._placeholderImg = img;
|
|
1062
|
+
// div.append(img);
|
|
1063
|
+
// anchor.append(div);
|
|
1064
|
+
// container.append(anchor);
|
|
1065
|
+
// ---------------
|
|
1066
|
+
this.store = store;
|
|
1067
|
+
this.thumbnailWidth = thumbnailWidth;
|
|
1068
|
+
this.loaded = false;
|
|
1048
1069
|
const div = document.createElement("div");
|
|
1049
1070
|
div.className = "thumbnail pdfSlickThumbHolder";
|
|
1050
1071
|
div.setAttribute("data-page-number", this.id.toString());
|
|
1051
1072
|
this.div = div;
|
|
1073
|
+
__classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_updateDims).call(this);
|
|
1052
1074
|
container.append(div);
|
|
1075
|
+
// </pdf-slick>
|
|
1053
1076
|
}
|
|
1054
1077
|
setPdfPage(pdfPage) {
|
|
1055
1078
|
this.pdfPage = pdfPage;
|
|
@@ -1061,18 +1084,18 @@ class PDFThumbnailView {
|
|
|
1061
1084
|
reset() {
|
|
1062
1085
|
this.cancelRendering();
|
|
1063
1086
|
this.renderingState = RenderingStates.INITIAL;
|
|
1064
|
-
const pageWidth = this.viewport.width, pageHeight = this.viewport.height, pageRatio = pageWidth / pageHeight;
|
|
1065
|
-
this.canvasHeight = (this.canvasWidth / pageRatio) | 0;
|
|
1066
|
-
this.scale = this.canvasWidth / pageWidth;
|
|
1067
1087
|
this.div.removeAttribute("data-loaded");
|
|
1088
|
+
// <pdf-slick>
|
|
1089
|
+
//this.image?.replaceWith(this._placeholderImg);
|
|
1090
|
+
//this.#updateDims();
|
|
1091
|
+
// if (this.image) {
|
|
1092
|
+
// this.image.removeAttribute("src");
|
|
1093
|
+
// delete this.image;
|
|
1094
|
+
// }
|
|
1095
|
+
// -----------
|
|
1068
1096
|
this.loaded = false;
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
// resources immediately, which can greatly reduce memory consumption.
|
|
1072
|
-
this.canvas.width = 0;
|
|
1073
|
-
this.canvas.height = 0;
|
|
1074
|
-
delete this.canvas;
|
|
1075
|
-
}
|
|
1097
|
+
__classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_updateDims).call(this);
|
|
1098
|
+
// </pdf-slick>
|
|
1076
1099
|
}
|
|
1077
1100
|
update({ rotation = null }) {
|
|
1078
1101
|
if (typeof rotation === "number") {
|
|
@@ -1096,113 +1119,61 @@ class PDFThumbnailView {
|
|
|
1096
1119
|
}
|
|
1097
1120
|
this.resume = null;
|
|
1098
1121
|
}
|
|
1099
|
-
/**
|
|
1100
|
-
* @private
|
|
1101
|
-
*/
|
|
1102
|
-
_getPageDrawContext(upscaleFactor = 1) {
|
|
1103
|
-
// Keep the no-thumbnail outline visible, i.e. `data-loaded === false`,
|
|
1104
|
-
// until rendering/image conversion is complete, to avoid display issues.
|
|
1105
|
-
const canvas = document.createElement("canvas");
|
|
1106
|
-
const ctx = canvas.getContext("2d", { alpha: false });
|
|
1107
|
-
const outputScale = new OutputScale();
|
|
1108
|
-
canvas.width = (upscaleFactor * this.canvasWidth * outputScale.sx) | 0;
|
|
1109
|
-
canvas.height = (upscaleFactor * this.canvasHeight * outputScale.sy) | 0;
|
|
1110
|
-
const transform = outputScale.scaled
|
|
1111
|
-
? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
|
|
1112
|
-
: null;
|
|
1113
|
-
return { ctx, canvas, transform };
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* @private
|
|
1117
|
-
*/
|
|
1118
|
-
_convertCanvasToImage(canvas) {
|
|
1119
|
-
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
1120
|
-
throw new Error("_convertCanvasToImage: Rendering has not finished.");
|
|
1121
|
-
}
|
|
1122
|
-
const reducedCanvas = this._reduceImage(canvas);
|
|
1123
|
-
this.src = reducedCanvas.toDataURL();
|
|
1124
|
-
this.div.setAttribute("data-loaded", "true");
|
|
1125
|
-
this.loaded = true;
|
|
1126
|
-
// this.store.getState()._setThumbnail(this.id, this.src)
|
|
1127
|
-
this.store.getState()._setThumbnailView(this.id, this);
|
|
1128
|
-
// Zeroing the width and height causes Firefox to release graphics
|
|
1129
|
-
// resources immediately, which can greatly reduce memory consumption.
|
|
1130
|
-
reducedCanvas.width = 0;
|
|
1131
|
-
reducedCanvas.height = 0;
|
|
1132
|
-
}
|
|
1133
1122
|
draw() {
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
const { pdfPage } = this;
|
|
1139
|
-
if (!pdfPage) {
|
|
1140
|
-
this.renderingState = RenderingStates.FINISHED;
|
|
1141
|
-
return Promise.reject(new Error("pdfPage is not loaded"));
|
|
1142
|
-
}
|
|
1143
|
-
this.renderingState = RenderingStates.RUNNING;
|
|
1144
|
-
const finishRenderTask = (...args_1) => __awaiter(this, [...args_1], undefined, function* (error = null) {
|
|
1145
|
-
// The renderTask may have been replaced by a new one, so only remove
|
|
1146
|
-
// the reference to the renderTask if it matches the one that is
|
|
1147
|
-
// triggering this callback.
|
|
1148
|
-
if (renderTask === this.renderTask) {
|
|
1149
|
-
this.renderTask = null;
|
|
1150
|
-
}
|
|
1151
|
-
if (error instanceof RenderingCancelledException) {
|
|
1152
|
-
return;
|
|
1123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1124
|
+
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
1125
|
+
console.error("Must be in new state before drawing");
|
|
1126
|
+
return undefined;
|
|
1153
1127
|
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
throw
|
|
1128
|
+
const { pdfPage } = this;
|
|
1129
|
+
if (!pdfPage) {
|
|
1130
|
+
this.renderingState = RenderingStates.FINISHED;
|
|
1131
|
+
throw new Error("pdfPage is not loaded");
|
|
1158
1132
|
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
});
|
|
1169
|
-
const renderContinueCallback = (cont) => {
|
|
1170
|
-
if (!this.renderingQueue.isHighestPriority(this)) {
|
|
1171
|
-
this.renderingState = RenderingStates.PAUSED;
|
|
1172
|
-
this.resume = () => {
|
|
1173
|
-
this.renderingState = RenderingStates.RUNNING;
|
|
1174
|
-
cont();
|
|
1175
|
-
};
|
|
1176
|
-
return;
|
|
1177
|
-
}
|
|
1178
|
-
cont();
|
|
1179
|
-
};
|
|
1180
|
-
const renderContext = {
|
|
1181
|
-
canvasContext: ctx,
|
|
1182
|
-
transform,
|
|
1183
|
-
viewport: drawViewport,
|
|
1184
|
-
optionalContentConfigPromise: this._optionalContentConfigPromise,
|
|
1185
|
-
pageColors: this.pageColors,
|
|
1186
|
-
};
|
|
1187
|
-
const renderTask = (this.renderTask = pdfPage.render(renderContext));
|
|
1188
|
-
renderTask.onContinue = renderContinueCallback;
|
|
1189
|
-
const resultPromise = renderTask.promise.then(function () {
|
|
1190
|
-
return finishRenderTask(null);
|
|
1191
|
-
}, function (error) {
|
|
1192
|
-
return finishRenderTask(error);
|
|
1193
|
-
});
|
|
1194
|
-
resultPromise.finally(() => {
|
|
1195
|
-
// Zeroing the width and height causes Firefox to release graphics
|
|
1196
|
-
// resources immediately, which can greatly reduce memory consumption.
|
|
1197
|
-
canvas.width = 0;
|
|
1198
|
-
canvas.height = 0;
|
|
1199
|
-
this.eventBus.dispatch("thumbnailrendered", {
|
|
1200
|
-
source: this,
|
|
1201
|
-
pageNumber: this.id,
|
|
1202
|
-
pdfPage: this.pdfPage,
|
|
1133
|
+
this.renderingState = RenderingStates.RUNNING;
|
|
1134
|
+
// Render the thumbnail at a larger size and downsize the canvas (similar
|
|
1135
|
+
// to `setImage`), to improve consistency between thumbnails created by
|
|
1136
|
+
// the `draw` and `setImage` methods (fixes issue 8233).
|
|
1137
|
+
// NOTE: To primarily avoid increasing memory usage too much, but also to
|
|
1138
|
+
// reduce downsizing overhead, we purposely limit the up-scaling factor.
|
|
1139
|
+
const { ctx, canvas, transform } = __classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_getPageDrawContext).call(this, DRAW_UPSCALE_FACTOR);
|
|
1140
|
+
const drawViewport = this.viewport.clone({
|
|
1141
|
+
scale: DRAW_UPSCALE_FACTOR * this.scale,
|
|
1203
1142
|
});
|
|
1143
|
+
const renderContinueCallback = (cont) => {
|
|
1144
|
+
if (!this.renderingQueue.isHighestPriority(this)) {
|
|
1145
|
+
this.renderingState = RenderingStates.PAUSED;
|
|
1146
|
+
this.resume = () => {
|
|
1147
|
+
this.renderingState = RenderingStates.RUNNING;
|
|
1148
|
+
cont();
|
|
1149
|
+
};
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
cont();
|
|
1153
|
+
};
|
|
1154
|
+
const renderContext = {
|
|
1155
|
+
canvasContext: ctx,
|
|
1156
|
+
transform,
|
|
1157
|
+
viewport: drawViewport,
|
|
1158
|
+
optionalContentConfigPromise: this._optionalContentConfigPromise,
|
|
1159
|
+
pageColors: this.pageColors,
|
|
1160
|
+
};
|
|
1161
|
+
const renderTask = (this.renderTask = pdfPage.render(renderContext));
|
|
1162
|
+
renderTask.onContinue = renderContinueCallback;
|
|
1163
|
+
const resultPromise = renderTask.promise.then(() => __classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_finishRenderTask).call(this, renderTask, canvas), error => __classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_finishRenderTask).call(this, renderTask, canvas, error));
|
|
1164
|
+
resultPromise.finally(() => {
|
|
1165
|
+
// Zeroing the width and height causes Firefox to release graphics
|
|
1166
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
1167
|
+
canvas.width = 0;
|
|
1168
|
+
canvas.height = 0;
|
|
1169
|
+
this.eventBus.dispatch("thumbnailrendered", {
|
|
1170
|
+
source: this,
|
|
1171
|
+
pageNumber: this.id,
|
|
1172
|
+
pdfPage: this.pdfPage,
|
|
1173
|
+
});
|
|
1174
|
+
});
|
|
1175
|
+
return resultPromise;
|
|
1204
1176
|
});
|
|
1205
|
-
return resultPromise;
|
|
1206
1177
|
}
|
|
1207
1178
|
setImage(pageView) {
|
|
1208
1179
|
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
@@ -1220,62 +1191,110 @@ class PDFThumbnailView {
|
|
|
1220
1191
|
return;
|
|
1221
1192
|
}
|
|
1222
1193
|
this.renderingState = RenderingStates.FINISHED;
|
|
1223
|
-
this.
|
|
1224
|
-
}
|
|
1225
|
-
/**
|
|
1226
|
-
* @private
|
|
1227
|
-
*/
|
|
1228
|
-
_reduceImage(img) {
|
|
1229
|
-
const { ctx, canvas } = this._getPageDrawContext();
|
|
1230
|
-
if (img.width <= 2 * canvas.width) {
|
|
1231
|
-
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
|
|
1232
|
-
return canvas;
|
|
1233
|
-
}
|
|
1234
|
-
// drawImage does an awful job of rescaling the image, doing it gradually.
|
|
1235
|
-
let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
|
1236
|
-
let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
|
1237
|
-
const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
|
1238
|
-
while (reducedWidth > img.width || reducedHeight > img.height) {
|
|
1239
|
-
reducedWidth >>= 1;
|
|
1240
|
-
reducedHeight >>= 1;
|
|
1241
|
-
}
|
|
1242
|
-
reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
|
|
1243
|
-
while (reducedWidth > 2 * canvas.width) {
|
|
1244
|
-
reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
|
|
1245
|
-
reducedWidth >>= 1;
|
|
1246
|
-
reducedHeight >>= 1;
|
|
1247
|
-
}
|
|
1248
|
-
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
|
|
1249
|
-
return canvas;
|
|
1250
|
-
}
|
|
1251
|
-
get _thumbPageTitle() {
|
|
1252
|
-
var _b;
|
|
1253
|
-
return this.l10n.get("thumb_page_title", {
|
|
1254
|
-
page: (_b = this.pageLabel) !== null && _b !== undefined ? _b : this.id,
|
|
1255
|
-
});
|
|
1256
|
-
}
|
|
1257
|
-
get _thumbPageCanvas() {
|
|
1258
|
-
var _b;
|
|
1259
|
-
return this.l10n.get("thumb_page_canvas", {
|
|
1260
|
-
page: ((_b = this.pageLabel) !== null && _b !== undefined ? _b : this.id),
|
|
1261
|
-
});
|
|
1194
|
+
__classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_convertCanvasToImage).call(this, canvas);
|
|
1262
1195
|
}
|
|
1263
1196
|
/**
|
|
1264
1197
|
* @param {string|null} label
|
|
1265
1198
|
*/
|
|
1266
1199
|
setPageLabel(label) {
|
|
1267
1200
|
this.pageLabel = typeof label === "string" ? label : null;
|
|
1268
|
-
//
|
|
1269
|
-
//
|
|
1270
|
-
// });
|
|
1201
|
+
// <pdf-slick>
|
|
1202
|
+
// this.anchor.setAttribute("data-l10n-args", this.#pageL10nArgs);
|
|
1271
1203
|
// if (this.renderingState !== RenderingStates.FINISHED) {
|
|
1272
1204
|
// return;
|
|
1273
1205
|
// }
|
|
1274
|
-
// this.
|
|
1275
|
-
//
|
|
1276
|
-
// });
|
|
1206
|
+
// this.image?.setAttribute("data-l10n-args", this.#pageL10nArgs);
|
|
1207
|
+
// </pdf-slick>
|
|
1277
1208
|
}
|
|
1278
1209
|
}
|
|
1210
|
+
_PDFThumbnailView_instances = new WeakSet(), _PDFThumbnailView_updateDims = function _PDFThumbnailView_updateDims() {
|
|
1211
|
+
const { width, height } = this.viewport;
|
|
1212
|
+
const ratio = width / height;
|
|
1213
|
+
this.canvasWidth = this.thumbnailWidth; // <pdf-slick>
|
|
1214
|
+
this.canvasHeight = (this.canvasWidth / ratio) | 0;
|
|
1215
|
+
this.scale = this.canvasWidth / width;
|
|
1216
|
+
const { style } = this.div;
|
|
1217
|
+
style.setProperty("--thumbnail-width", `${this.canvasWidth}px`);
|
|
1218
|
+
style.setProperty("--thumbnail-height", `${this.canvasHeight}px`);
|
|
1219
|
+
}, _PDFThumbnailView_getPageDrawContext = function _PDFThumbnailView_getPageDrawContext(upscaleFactor = 1, enableHWA = this.enableHWA) {
|
|
1220
|
+
// Keep the no-thumbnail outline visible, i.e. `data-loaded === false`,
|
|
1221
|
+
// until rendering/image conversion is complete, to avoid display issues.
|
|
1222
|
+
const canvas = document.createElement("canvas");
|
|
1223
|
+
const ctx = canvas.getContext("2d", {
|
|
1224
|
+
alpha: false,
|
|
1225
|
+
willReadFrequently: !enableHWA,
|
|
1226
|
+
});
|
|
1227
|
+
const outputScale = new OutputScale();
|
|
1228
|
+
canvas.width = (upscaleFactor * this.canvasWidth * outputScale.sx) | 0;
|
|
1229
|
+
canvas.height = (upscaleFactor * this.canvasHeight * outputScale.sy) | 0;
|
|
1230
|
+
const transform = outputScale.scaled
|
|
1231
|
+
? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
|
|
1232
|
+
: null;
|
|
1233
|
+
return { ctx, canvas, transform };
|
|
1234
|
+
}, _PDFThumbnailView_convertCanvasToImage = function _PDFThumbnailView_convertCanvasToImage(canvas) {
|
|
1235
|
+
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
1236
|
+
throw new Error("#convertCanvasToImage: Rendering has not finished.");
|
|
1237
|
+
}
|
|
1238
|
+
const reducedCanvas = __classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_reduceImage).call(this, canvas);
|
|
1239
|
+
// <pdf-slick>
|
|
1240
|
+
// const image = document.createElement("img");
|
|
1241
|
+
// image.className = "thumbnailImage";
|
|
1242
|
+
// image.setAttribute("data-l10n-id", "pdfjs-thumb-page-canvas");
|
|
1243
|
+
// image.setAttribute("data-l10n-args", this.#pageL10nArgs);
|
|
1244
|
+
// image.src = reducedCanvas.toDataURL();
|
|
1245
|
+
// this.image = image;
|
|
1246
|
+
//this.div.setAttribute("data-loaded", 'true');
|
|
1247
|
+
//this._placeholderImg.replaceWith(image);
|
|
1248
|
+
// -------------
|
|
1249
|
+
this.src = reducedCanvas.toDataURL();
|
|
1250
|
+
this.div.setAttribute("data-loaded", "true");
|
|
1251
|
+
this.loaded = true;
|
|
1252
|
+
this.store.getState()._setThumbnailView(this.id, this);
|
|
1253
|
+
// </pdf-slick>
|
|
1254
|
+
// Zeroing the width and height causes Firefox to release graphics
|
|
1255
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
1256
|
+
reducedCanvas.width = 0;
|
|
1257
|
+
reducedCanvas.height = 0;
|
|
1258
|
+
}, _PDFThumbnailView_finishRenderTask = function _PDFThumbnailView_finishRenderTask(renderTask_1, canvas_1) {
|
|
1259
|
+
return __awaiter(this, arguments, void 0, function* (renderTask, canvas, error = null) {
|
|
1260
|
+
// The renderTask may have been replaced by a new one, so only remove
|
|
1261
|
+
// the reference to the renderTask if it matches the one that is
|
|
1262
|
+
// triggering this callback.
|
|
1263
|
+
if (renderTask === this.renderTask) {
|
|
1264
|
+
this.renderTask = null;
|
|
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
|
+
});
|
|
1275
|
+
}, _PDFThumbnailView_reduceImage = function _PDFThumbnailView_reduceImage(img) {
|
|
1276
|
+
const { ctx, canvas } = __classPrivateFieldGet(this, _PDFThumbnailView_instances, "m", _PDFThumbnailView_getPageDrawContext).call(this, 1, true);
|
|
1277
|
+
if (img.width <= 2 * canvas.width) {
|
|
1278
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
|
|
1279
|
+
return canvas;
|
|
1280
|
+
}
|
|
1281
|
+
// drawImage does an awful job of rescaling the image, doing it gradually.
|
|
1282
|
+
let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
|
1283
|
+
let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
|
1284
|
+
const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
|
1285
|
+
while (reducedWidth > img.width || reducedHeight > img.height) {
|
|
1286
|
+
reducedWidth >>= 1;
|
|
1287
|
+
reducedHeight >>= 1;
|
|
1288
|
+
}
|
|
1289
|
+
reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
|
|
1290
|
+
while (reducedWidth > 2 * canvas.width) {
|
|
1291
|
+
reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
|
|
1292
|
+
reducedWidth >>= 1;
|
|
1293
|
+
reducedHeight >>= 1;
|
|
1294
|
+
}
|
|
1295
|
+
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
|
|
1296
|
+
return canvas;
|
|
1297
|
+
};
|
|
1279
1298
|
|
|
1280
1299
|
/* Copyright 2012 Mozilla Foundation
|
|
1281
1300
|
*
|
|
@@ -1291,20 +1310,9 @@ class PDFThumbnailView {
|
|
|
1291
1310
|
* See the License for the specific language governing permissions and
|
|
1292
1311
|
* limitations under the License.
|
|
1293
1312
|
*/
|
|
1294
|
-
var _PDFThumbnailViewer_instances, _PDFThumbnailViewer_ensurePdfPageLoaded, _PDFThumbnailViewer_getScrollAhead;
|
|
1313
|
+
var _PDFThumbnailViewer_instances, _PDFThumbnailViewer_scrollUpdated, _PDFThumbnailViewer_getVisibleThumbs, _PDFThumbnailViewer_resetView, _PDFThumbnailViewer_cancelRendering, _PDFThumbnailViewer_ensurePdfPageLoaded, _PDFThumbnailViewer_getScrollAhead;
|
|
1295
1314
|
const THUMBNAIL_SCROLL_MARGIN = -19;
|
|
1296
1315
|
const THUMBNAIL_SELECTED_CLASS = "selected";
|
|
1297
|
-
/**
|
|
1298
|
-
* @typedef {Object} PDFThumbnailViewerOptions
|
|
1299
|
-
* @property {HTMLDivElement} container - The container for the thumbnail
|
|
1300
|
-
* elements.
|
|
1301
|
-
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
|
1302
|
-
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
|
1303
|
-
* @property {IL10n} l10n - Localization service.
|
|
1304
|
-
* @property {Object} [pageColors] - Overwrites background and foreground colors
|
|
1305
|
-
* with user defined ones in order to improve readability in high contrast
|
|
1306
|
-
* mode.
|
|
1307
|
-
*/
|
|
1308
1316
|
/**
|
|
1309
1317
|
* Viewer control to display thumbnails for pages in a PDF document.
|
|
1310
1318
|
*/
|
|
@@ -1312,50 +1320,24 @@ class PDFThumbnailViewer {
|
|
|
1312
1320
|
/**
|
|
1313
1321
|
* @param {PDFThumbnailViewerOptions} options
|
|
1314
1322
|
*/
|
|
1315
|
-
constructor({ container, eventBus, linkService, renderingQueue,
|
|
1323
|
+
constructor({ container, eventBus, linkService, renderingQueue, pageColors, abortSignal, enableHWA, store, thumbnailWidth, }) {
|
|
1316
1324
|
_PDFThumbnailViewer_instances.add(this);
|
|
1317
1325
|
this.container = container;
|
|
1318
1326
|
this.eventBus = eventBus;
|
|
1319
1327
|
this.linkService = linkService;
|
|
1320
1328
|
this.renderingQueue = renderingQueue;
|
|
1321
|
-
this.l10n = l10n;
|
|
1322
1329
|
this.pageColors = pageColors || null;
|
|
1323
|
-
this.
|
|
1324
|
-
|
|
1325
|
-
this._pagesRotation = 0;
|
|
1326
|
-
this._pageLabels = [];
|
|
1327
|
-
this.pdfDocument = null;
|
|
1330
|
+
this.enableHWA = enableHWA || false;
|
|
1331
|
+
// <pdf-slick>
|
|
1328
1332
|
this.store = store;
|
|
1329
1333
|
this.thumbnailWidth = thumbnailWidth;
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
if (this.pageColors.background || this.pageColors.foreground) {
|
|
1334
|
-
console.warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
|
|
1335
|
-
}
|
|
1336
|
-
this.pageColors = null;
|
|
1337
|
-
}
|
|
1338
|
-
this.scroll = watchScroll(this.container, this._scrollUpdated.bind(this));
|
|
1339
|
-
this._resetView();
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* @private
|
|
1343
|
-
*/
|
|
1344
|
-
_scrollUpdated() {
|
|
1345
|
-
this.renderingQueue.renderHighestPriority();
|
|
1334
|
+
// </pdf-slick>
|
|
1335
|
+
this.scroll = watchScroll(this.container, __classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_scrollUpdated).bind(this), abortSignal);
|
|
1336
|
+
__classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_resetView).call(this);
|
|
1346
1337
|
}
|
|
1347
1338
|
getThumbnail(index) {
|
|
1348
1339
|
return this._thumbnails[index];
|
|
1349
1340
|
}
|
|
1350
|
-
/**
|
|
1351
|
-
* @private
|
|
1352
|
-
*/
|
|
1353
|
-
_getVisibleThumbs() {
|
|
1354
|
-
return getVisibleElements({
|
|
1355
|
-
scrollEl: this.container,
|
|
1356
|
-
views: this._thumbnails,
|
|
1357
|
-
});
|
|
1358
|
-
}
|
|
1359
1341
|
scrollThumbnailIntoView(pageNumber) {
|
|
1360
1342
|
if (!this.pdfDocument) {
|
|
1361
1343
|
return;
|
|
@@ -1372,12 +1354,11 @@ class PDFThumbnailViewer {
|
|
|
1372
1354
|
// ... and add the highlight to the new thumbnail.
|
|
1373
1355
|
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
1374
1356
|
}
|
|
1375
|
-
const
|
|
1376
|
-
const { first, last, views } = visibleThumbs;
|
|
1357
|
+
const { first, last, views } = __classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_getVisibleThumbs).call(this);
|
|
1377
1358
|
// If the thumbnail isn't currently visible, scroll it into view.
|
|
1378
1359
|
if (views.length > 0) {
|
|
1379
1360
|
let shouldScroll = false;
|
|
1380
|
-
if (pageNumber <= first.id || pageNumber >=
|
|
1361
|
+
if (pageNumber <= first.id || pageNumber >= last.id) {
|
|
1381
1362
|
shouldScroll = true;
|
|
1382
1363
|
}
|
|
1383
1364
|
else {
|
|
@@ -1394,7 +1375,6 @@ class PDFThumbnailViewer {
|
|
|
1394
1375
|
}
|
|
1395
1376
|
}
|
|
1396
1377
|
this._currentPageNumber = pageNumber;
|
|
1397
|
-
this.forceRendering();
|
|
1398
1378
|
}
|
|
1399
1379
|
get pagesRotation() {
|
|
1400
1380
|
return this._pagesRotation;
|
|
@@ -1410,7 +1390,7 @@ class PDFThumbnailViewer {
|
|
|
1410
1390
|
return; // The rotation didn't change.
|
|
1411
1391
|
}
|
|
1412
1392
|
this._pagesRotation = rotation;
|
|
1413
|
-
const updateArgs = { rotation
|
|
1393
|
+
const updateArgs = { rotation };
|
|
1414
1394
|
for (const thumbnail of this._thumbnails) {
|
|
1415
1395
|
thumbnail.update(updateArgs);
|
|
1416
1396
|
}
|
|
@@ -1423,33 +1403,24 @@ class PDFThumbnailViewer {
|
|
|
1423
1403
|
}
|
|
1424
1404
|
TempImageFactory.destroyCanvas();
|
|
1425
1405
|
}
|
|
1426
|
-
/**
|
|
1427
|
-
* @private
|
|
1428
|
-
*/
|
|
1429
|
-
_resetView() {
|
|
1430
|
-
this._thumbnails = [];
|
|
1431
|
-
this._currentPageNumber = 1;
|
|
1432
|
-
this._pageLabels = [];
|
|
1433
|
-
this._pagesRotation = 0;
|
|
1434
|
-
// Remove the thumbnails from the DOM.
|
|
1435
|
-
this.container.textContent = "";
|
|
1436
|
-
}
|
|
1437
1406
|
/**
|
|
1438
1407
|
* @param {PDFDocumentProxy} pdfDocument
|
|
1439
1408
|
*/
|
|
1440
1409
|
setDocument(pdfDocument) {
|
|
1441
1410
|
if (this.pdfDocument) {
|
|
1442
|
-
this.
|
|
1443
|
-
this.
|
|
1411
|
+
__classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_cancelRendering).call(this);
|
|
1412
|
+
__classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_resetView).call(this);
|
|
1444
1413
|
}
|
|
1445
1414
|
this.pdfDocument = pdfDocument;
|
|
1446
1415
|
if (!pdfDocument) {
|
|
1447
1416
|
return;
|
|
1448
1417
|
}
|
|
1449
1418
|
const firstPagePromise = pdfDocument.getPage(1);
|
|
1450
|
-
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig(
|
|
1419
|
+
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({
|
|
1420
|
+
intent: "display",
|
|
1421
|
+
});
|
|
1451
1422
|
firstPagePromise
|
|
1452
|
-
.then(
|
|
1423
|
+
.then(firstPdfPage => {
|
|
1453
1424
|
var _a;
|
|
1454
1425
|
const pagesCount = pdfDocument.numPages;
|
|
1455
1426
|
const viewport = firstPdfPage.getViewport({ scale: 1 });
|
|
@@ -1462,8 +1433,8 @@ class PDFThumbnailViewer {
|
|
|
1462
1433
|
optionalContentConfigPromise,
|
|
1463
1434
|
linkService: this.linkService,
|
|
1464
1435
|
renderingQueue: this.renderingQueue,
|
|
1465
|
-
l10n: this.l10n,
|
|
1466
1436
|
pageColors: this.pageColors,
|
|
1437
|
+
enableHWA: this.enableHWA,
|
|
1467
1438
|
store: this.store,
|
|
1468
1439
|
thumbnailWidth: this.thumbnailWidth,
|
|
1469
1440
|
});
|
|
@@ -1472,24 +1443,18 @@ class PDFThumbnailViewer {
|
|
|
1472
1443
|
// Set the first `pdfPage` immediately, since it's already loaded,
|
|
1473
1444
|
// rather than having to repeat the `PDFDocumentProxy.getPage` call in
|
|
1474
1445
|
// the `this.#ensurePdfPageLoaded` method before rendering can start.
|
|
1475
|
-
(_a = this._thumbnails[0]) === null || _a ===
|
|
1446
|
+
(_a = this._thumbnails[0]) === null || _a === void 0 ? void 0 : _a.setPdfPage(firstPdfPage);
|
|
1476
1447
|
// Ensure that the current thumbnail is always highlighted on load.
|
|
1477
1448
|
const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
|
|
1478
1449
|
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
1450
|
+
// <pdf-slick>
|
|
1479
1451
|
this.store.getState()._setThumbnailsViews(this._thumbnails);
|
|
1452
|
+
// </pdf-slick>
|
|
1480
1453
|
})
|
|
1481
|
-
.catch(
|
|
1454
|
+
.catch(reason => {
|
|
1482
1455
|
console.error("Unable to initialize thumbnail viewer", reason);
|
|
1483
1456
|
});
|
|
1484
1457
|
}
|
|
1485
|
-
/**
|
|
1486
|
-
* @private
|
|
1487
|
-
*/
|
|
1488
|
-
_cancelRendering() {
|
|
1489
|
-
for (const thumbnail of this._thumbnails) {
|
|
1490
|
-
thumbnail.cancelRendering();
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
1458
|
/**
|
|
1494
1459
|
* @param {Array|null} labels
|
|
1495
1460
|
*/
|
|
@@ -1499,10 +1464,10 @@ class PDFThumbnailViewer {
|
|
|
1499
1464
|
return;
|
|
1500
1465
|
}
|
|
1501
1466
|
if (!labels) {
|
|
1502
|
-
this._pageLabels =
|
|
1467
|
+
this._pageLabels = null;
|
|
1503
1468
|
}
|
|
1504
1469
|
else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
|
|
1505
|
-
this._pageLabels =
|
|
1470
|
+
this._pageLabels = null;
|
|
1506
1471
|
console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
|
|
1507
1472
|
}
|
|
1508
1473
|
else {
|
|
@@ -1510,15 +1475,13 @@ class PDFThumbnailViewer {
|
|
|
1510
1475
|
}
|
|
1511
1476
|
// Update all the `PDFThumbnailView` instances.
|
|
1512
1477
|
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
1513
|
-
this._thumbnails[i].setPageLabel((_b = (_a = this._pageLabels) === null || _a ===
|
|
1478
|
+
this._thumbnails[i].setPageLabel((_b = (_a = this._pageLabels) === null || _a === void 0 ? void 0 : _a[i]) !== null && _b !== void 0 ? _b : null);
|
|
1514
1479
|
}
|
|
1515
1480
|
}
|
|
1516
1481
|
forceRendering() {
|
|
1517
|
-
const visibleThumbs = this.
|
|
1518
|
-
// console.log(`forceRendering, visibleThumbs: `, visibleThumbs)
|
|
1482
|
+
const visibleThumbs = __classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_getVisibleThumbs).call(this);
|
|
1519
1483
|
const scrollAhead = __classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_getScrollAhead).call(this, visibleThumbs);
|
|
1520
1484
|
const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
|
|
1521
|
-
// console.log(`forceRendering, thumbView: `, thumbView)
|
|
1522
1485
|
if (thumbView) {
|
|
1523
1486
|
__classPrivateFieldGet(this, _PDFThumbnailViewer_instances, "m", _PDFThumbnailViewer_ensurePdfPageLoaded).call(this, thumbView).then(() => {
|
|
1524
1487
|
this.renderingQueue.renderView(thumbView);
|
|
@@ -1528,15 +1491,32 @@ class PDFThumbnailViewer {
|
|
|
1528
1491
|
return false;
|
|
1529
1492
|
}
|
|
1530
1493
|
}
|
|
1531
|
-
_PDFThumbnailViewer_instances = new WeakSet(),
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1494
|
+
_PDFThumbnailViewer_instances = new WeakSet(), _PDFThumbnailViewer_scrollUpdated = function _PDFThumbnailViewer_scrollUpdated() {
|
|
1495
|
+
this.renderingQueue.renderHighestPriority();
|
|
1496
|
+
}, _PDFThumbnailViewer_getVisibleThumbs = function _PDFThumbnailViewer_getVisibleThumbs() {
|
|
1497
|
+
return getVisibleElements({
|
|
1498
|
+
scrollEl: this.container,
|
|
1499
|
+
views: this._thumbnails,
|
|
1500
|
+
});
|
|
1501
|
+
}, _PDFThumbnailViewer_resetView = function _PDFThumbnailViewer_resetView() {
|
|
1502
|
+
this._thumbnails = [];
|
|
1503
|
+
this._currentPageNumber = 1;
|
|
1504
|
+
this._pageLabels = null;
|
|
1505
|
+
this._pagesRotation = 0;
|
|
1506
|
+
// Remove the thumbnails from the DOM.
|
|
1507
|
+
this.container.textContent = "";
|
|
1508
|
+
}, _PDFThumbnailViewer_cancelRendering = function _PDFThumbnailViewer_cancelRendering() {
|
|
1509
|
+
for (const thumbnail of this._thumbnails) {
|
|
1510
|
+
thumbnail.cancelRendering();
|
|
1511
|
+
}
|
|
1512
|
+
}, _PDFThumbnailViewer_ensurePdfPageLoaded = function _PDFThumbnailViewer_ensurePdfPageLoaded(thumbView) {
|
|
1513
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1514
|
+
if (thumbView.pdfPage) {
|
|
1535
1515
|
return thumbView.pdfPage;
|
|
1536
1516
|
}
|
|
1537
1517
|
try {
|
|
1538
|
-
const pdfPage = yield
|
|
1539
|
-
if (!
|
|
1518
|
+
const pdfPage = yield this.pdfDocument.getPage(thumbView.id);
|
|
1519
|
+
if (!thumbView.pdfPage) {
|
|
1540
1520
|
thumbView.setPdfPage(pdfPage);
|
|
1541
1521
|
}
|
|
1542
1522
|
return pdfPage;
|
|
@@ -1548,124 +1528,15 @@ _PDFThumbnailViewer_instances = new WeakSet(), _PDFThumbnailViewer_ensurePdfPage
|
|
|
1548
1528
|
});
|
|
1549
1529
|
}, _PDFThumbnailViewer_getScrollAhead = function _PDFThumbnailViewer_getScrollAhead(visible) {
|
|
1550
1530
|
var _a, _b;
|
|
1551
|
-
|
|
1552
|
-
if (((_a = visible.first) === null || _a === undefined ? undefined : _a.id) === 1) {
|
|
1531
|
+
if (((_a = visible.first) === null || _a === void 0 ? void 0 : _a.id) === 1) {
|
|
1553
1532
|
return true;
|
|
1554
1533
|
}
|
|
1555
|
-
else if (((_b = visible.last) === null || _b ===
|
|
1534
|
+
else if (((_b = visible.last) === null || _b === void 0 ? void 0 : _b.id) === this._thumbnails.length) {
|
|
1556
1535
|
return false;
|
|
1557
1536
|
}
|
|
1558
1537
|
return this.scroll.down;
|
|
1559
1538
|
};
|
|
1560
1539
|
|
|
1561
|
-
/* Copyright 2014 Mozilla Foundation
|
|
1562
|
-
*
|
|
1563
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1564
|
-
* you may not use this file except in compliance with the License.
|
|
1565
|
-
* You may obtain a copy of the License at
|
|
1566
|
-
*
|
|
1567
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1568
|
-
*
|
|
1569
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1570
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1571
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1572
|
-
* See the License for the specific language governing permissions and
|
|
1573
|
-
* limitations under the License.
|
|
1574
|
-
*/
|
|
1575
|
-
var _OverlayManager_overlays, _OverlayManager_active;
|
|
1576
|
-
class OverlayManager {
|
|
1577
|
-
constructor() {
|
|
1578
|
-
_OverlayManager_overlays.set(this, new WeakMap());
|
|
1579
|
-
_OverlayManager_active.set(this, null);
|
|
1580
|
-
}
|
|
1581
|
-
get active() {
|
|
1582
|
-
return __classPrivateFieldGet(this, _OverlayManager_active, "f");
|
|
1583
|
-
}
|
|
1584
|
-
/**
|
|
1585
|
-
* @param {HTMLDialogElement} dialog - The overlay's DOM element.
|
|
1586
|
-
* @param {boolean} [canForceClose] - Indicates if opening the overlay closes
|
|
1587
|
-
* an active overlay. The default is `false`.
|
|
1588
|
-
* @returns {Promise} A promise that is resolved when the overlay has been
|
|
1589
|
-
* registered.
|
|
1590
|
-
*/
|
|
1591
|
-
register(dialog_1) {
|
|
1592
|
-
return __awaiter(this, arguments, undefined, function* (dialog, canForceClose = false) {
|
|
1593
|
-
if (typeof dialog !== "object") {
|
|
1594
|
-
throw new Error("Not enough parameters.");
|
|
1595
|
-
}
|
|
1596
|
-
else if (__classPrivateFieldGet(this, _OverlayManager_overlays, "f").has(dialog)) {
|
|
1597
|
-
throw new Error("The overlay is already registered.");
|
|
1598
|
-
}
|
|
1599
|
-
__classPrivateFieldGet(this, _OverlayManager_overlays, "f").set(dialog, { canForceClose });
|
|
1600
|
-
dialog.addEventListener("cancel", () => {
|
|
1601
|
-
__classPrivateFieldSet(this, _OverlayManager_active, null, "f");
|
|
1602
|
-
});
|
|
1603
|
-
});
|
|
1604
|
-
}
|
|
1605
|
-
/**
|
|
1606
|
-
* @param {HTMLDialogElement} dialog - The overlay's DOM element.
|
|
1607
|
-
* @returns {Promise} A promise that is resolved when the overlay has been
|
|
1608
|
-
* unregistered.
|
|
1609
|
-
*/
|
|
1610
|
-
unregister(dialog) {
|
|
1611
|
-
return __awaiter(this, undefined, undefined, function* () {
|
|
1612
|
-
if (!__classPrivateFieldGet(this, _OverlayManager_overlays, "f").has(dialog)) {
|
|
1613
|
-
throw new Error("The overlay does not exist.");
|
|
1614
|
-
}
|
|
1615
|
-
else if (__classPrivateFieldGet(this, _OverlayManager_active, "f") === dialog) {
|
|
1616
|
-
throw new Error("The overlay cannot be removed while it is active.");
|
|
1617
|
-
}
|
|
1618
|
-
__classPrivateFieldGet(this, _OverlayManager_overlays, "f").delete(dialog);
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
/**
|
|
1622
|
-
* @param {HTMLDialogElement} dialog - The overlay's DOM element.
|
|
1623
|
-
* @returns {Promise} A promise that is resolved when the overlay has been
|
|
1624
|
-
* opened.
|
|
1625
|
-
*/
|
|
1626
|
-
open(dialog) {
|
|
1627
|
-
return __awaiter(this, undefined, undefined, function* () {
|
|
1628
|
-
if (!__classPrivateFieldGet(this, _OverlayManager_overlays, "f").has(dialog)) {
|
|
1629
|
-
throw new Error("The overlay does not exist.");
|
|
1630
|
-
}
|
|
1631
|
-
else if (__classPrivateFieldGet(this, _OverlayManager_active, "f")) {
|
|
1632
|
-
if (__classPrivateFieldGet(this, _OverlayManager_active, "f") === dialog) {
|
|
1633
|
-
throw new Error("The overlay is already active.");
|
|
1634
|
-
}
|
|
1635
|
-
else if (__classPrivateFieldGet(this, _OverlayManager_overlays, "f").get(dialog).canForceClose) {
|
|
1636
|
-
yield this.close();
|
|
1637
|
-
}
|
|
1638
|
-
else {
|
|
1639
|
-
throw new Error("Another overlay is currently active.");
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
__classPrivateFieldSet(this, _OverlayManager_active, dialog, "f");
|
|
1643
|
-
dialog.showModal();
|
|
1644
|
-
});
|
|
1645
|
-
}
|
|
1646
|
-
/**
|
|
1647
|
-
* @param {HTMLDialogElement} dialog - The overlay's DOM element.
|
|
1648
|
-
* @returns {Promise} A promise that is resolved when the overlay has been
|
|
1649
|
-
* closed.
|
|
1650
|
-
*/
|
|
1651
|
-
close() {
|
|
1652
|
-
return __awaiter(this, arguments, undefined, function* (dialog = __classPrivateFieldGet(this, _OverlayManager_active, "f")) {
|
|
1653
|
-
if (!dialog || !__classPrivateFieldGet(this, _OverlayManager_overlays, "f").has(dialog)) {
|
|
1654
|
-
throw new Error("The overlay does not exist.");
|
|
1655
|
-
}
|
|
1656
|
-
else if (!__classPrivateFieldGet(this, _OverlayManager_active, "f")) {
|
|
1657
|
-
throw new Error("The overlay is currently not active.");
|
|
1658
|
-
}
|
|
1659
|
-
else if (__classPrivateFieldGet(this, _OverlayManager_active, "f") !== dialog) {
|
|
1660
|
-
throw new Error("Another overlay is currently active.");
|
|
1661
|
-
}
|
|
1662
|
-
dialog.close();
|
|
1663
|
-
__classPrivateFieldSet(this, _OverlayManager_active, null, "f");
|
|
1664
|
-
});
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
_OverlayManager_overlays = new WeakMap(), _OverlayManager_active = new WeakMap();
|
|
1668
|
-
|
|
1669
1540
|
/* Copyright 2016 Mozilla Foundation
|
|
1670
1541
|
*
|
|
1671
1542
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -1687,7 +1558,7 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
|
|
|
1687
1558
|
const xfaHtml = pdfDocument.allXfaHtml;
|
|
1688
1559
|
const linkService = new SimpleLinkService();
|
|
1689
1560
|
const scale = Math.round(PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
|
|
1690
|
-
for (const xfaPage of xfaHtml === null || xfaHtml ===
|
|
1561
|
+
for (const xfaPage of xfaHtml === null || xfaHtml === void 0 ? void 0 : xfaHtml.children) {
|
|
1691
1562
|
const page = document.createElement("div");
|
|
1692
1563
|
page.className = "xfaPrintedPage";
|
|
1693
1564
|
printContainer.append(page);
|
|
@@ -1703,12 +1574,10 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) {
|
|
|
1703
1574
|
}
|
|
1704
1575
|
}
|
|
1705
1576
|
let activeService = null;
|
|
1706
|
-
let dialog = null;
|
|
1707
|
-
let overlayManager = new OverlayManager();
|
|
1708
1577
|
// Renders the page to the canvas of the given print service, and returns
|
|
1709
1578
|
// the suggested dimensions of the output page.
|
|
1710
|
-
function renderPage(
|
|
1711
|
-
const scratchCanvas =
|
|
1579
|
+
function renderPage(printService, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
|
|
1580
|
+
const scratchCanvas = printService.scratchCanvas;
|
|
1712
1581
|
// The size of the canvas in pixels for printing.
|
|
1713
1582
|
const PRINT_UNITS = printResolution / PixelsPerInch.PDF;
|
|
1714
1583
|
scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
|
|
@@ -1731,20 +1600,26 @@ function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printRe
|
|
|
1731
1600
|
optionalContentConfigPromise,
|
|
1732
1601
|
printAnnotationStorage,
|
|
1733
1602
|
};
|
|
1734
|
-
|
|
1603
|
+
const renderTask = pdfPage.render(renderContext);
|
|
1604
|
+
return renderTask.promise.catch(reason => {
|
|
1605
|
+
if (!(reason instanceof RenderingCancelledException)) {
|
|
1606
|
+
console.error(reason);
|
|
1607
|
+
}
|
|
1608
|
+
throw reason;
|
|
1609
|
+
});
|
|
1735
1610
|
});
|
|
1736
1611
|
}
|
|
1737
1612
|
class PDFPrintService {
|
|
1738
|
-
constructor(pdfDocument, pagesOverview, printContainer, printResolution,
|
|
1613
|
+
constructor({ pdfDocument, pagesOverview, printContainer, printResolution, printAnnotationStoragePromise = null, }) {
|
|
1739
1614
|
this.pdfDocument = pdfDocument;
|
|
1740
1615
|
this.pagesOverview = pagesOverview;
|
|
1741
1616
|
this.printContainer = printContainer;
|
|
1742
1617
|
this._printResolution = printResolution || 150;
|
|
1743
|
-
this._optionalContentConfigPromise =
|
|
1744
|
-
|
|
1618
|
+
this._optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({
|
|
1619
|
+
intent: "print",
|
|
1620
|
+
});
|
|
1745
1621
|
this._printAnnotationStoragePromise =
|
|
1746
1622
|
printAnnotationStoragePromise || Promise.resolve();
|
|
1747
|
-
this.l10n = l10n;
|
|
1748
1623
|
this.currentPage = -1;
|
|
1749
1624
|
// The temporary canvas where renderPage paints one page at a time.
|
|
1750
1625
|
this.scratchCanvas = document.createElement("canvas");
|
|
@@ -1752,14 +1627,11 @@ class PDFPrintService {
|
|
|
1752
1627
|
layout() {
|
|
1753
1628
|
this.throwIfInactive();
|
|
1754
1629
|
const body = document.querySelector("body");
|
|
1755
|
-
body
|
|
1756
|
-
const
|
|
1757
|
-
|
|
1758
|
-
size.height === this.pagesOverview[0].height);
|
|
1759
|
-
}, this);
|
|
1630
|
+
body.setAttribute("data-pdfjsprinting", 'true');
|
|
1631
|
+
const { width, height } = this.pagesOverview[0];
|
|
1632
|
+
const hasEqualPageSizes = this.pagesOverview.every(size => size.width === width && size.height === height);
|
|
1760
1633
|
if (!hasEqualPageSizes) {
|
|
1761
|
-
console.warn("Not all pages have the same size. The printed "
|
|
1762
|
-
"result may be incorrect!");
|
|
1634
|
+
console.warn("Not all pages have the same size. The printed result may be incorrect!");
|
|
1763
1635
|
}
|
|
1764
1636
|
// Insert a @page + size rule to make sure that the page size is correctly
|
|
1765
1637
|
// set. Note that we assume that all pages have the same size, because
|
|
@@ -1767,14 +1639,12 @@ class PDFPrintService {
|
|
|
1767
1639
|
// TODO(robwu): Use named pages when size calculation bugs get resolved
|
|
1768
1640
|
// (e.g. https://crbug.com/355116) AND when support for named pages is
|
|
1769
1641
|
// added (http://www.w3.org/TR/css3-page/#using-named-pages).
|
|
1770
|
-
// In browsers where @page + size is not supported
|
|
1771
|
-
//
|
|
1772
|
-
//
|
|
1642
|
+
// In browsers where @page + size is not supported, the next stylesheet
|
|
1643
|
+
// will be ignored and the user has to select the correct paper size in
|
|
1644
|
+
// the UI if wanted.
|
|
1773
1645
|
this.pageStyleSheet = document.createElement("style");
|
|
1774
|
-
|
|
1775
|
-
this.pageStyleSheet
|
|
1776
|
-
"@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
|
|
1777
|
-
body === null || body === undefined ? undefined : body.append(this.pageStyleSheet);
|
|
1646
|
+
this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`;
|
|
1647
|
+
body.append(this.pageStyleSheet);
|
|
1778
1648
|
}
|
|
1779
1649
|
destroy() {
|
|
1780
1650
|
if (activeService !== this) {
|
|
@@ -1784,7 +1654,7 @@ class PDFPrintService {
|
|
|
1784
1654
|
}
|
|
1785
1655
|
this.printContainer.textContent = "";
|
|
1786
1656
|
const body = document.querySelector("body");
|
|
1787
|
-
body
|
|
1657
|
+
body.removeAttribute("data-pdfjsprinting");
|
|
1788
1658
|
if (this.pageStyleSheet) {
|
|
1789
1659
|
this.pageStyleSheet.remove();
|
|
1790
1660
|
this.pageStyleSheet = null;
|
|
@@ -1792,13 +1662,8 @@ class PDFPrintService {
|
|
|
1792
1662
|
this.scratchCanvas.width = this.scratchCanvas.height = 0;
|
|
1793
1663
|
this.scratchCanvas = null;
|
|
1794
1664
|
activeService = null;
|
|
1795
|
-
ensureOverlay().then(function () {
|
|
1796
|
-
if (overlayManager.active === dialog) {
|
|
1797
|
-
overlayManager.close(dialog);
|
|
1798
|
-
}
|
|
1799
|
-
});
|
|
1800
1665
|
}
|
|
1801
|
-
renderPages() {
|
|
1666
|
+
renderPages(renderProgress) {
|
|
1802
1667
|
if (this.pdfDocument.isPureXfa) {
|
|
1803
1668
|
getXfaHtmlForPrinting(this.printContainer, this.pdfDocument);
|
|
1804
1669
|
return Promise.resolve();
|
|
@@ -1807,12 +1672,12 @@ class PDFPrintService {
|
|
|
1807
1672
|
const renderNextPage = (resolve, reject) => {
|
|
1808
1673
|
this.throwIfInactive();
|
|
1809
1674
|
if (++this.currentPage >= pageCount) {
|
|
1810
|
-
renderProgress(pageCount, pageCount
|
|
1675
|
+
renderProgress({ index: pageCount, total: pageCount });
|
|
1811
1676
|
resolve();
|
|
1812
1677
|
return;
|
|
1813
1678
|
}
|
|
1814
1679
|
const index = this.currentPage;
|
|
1815
|
-
renderProgress(index, pageCount
|
|
1680
|
+
renderProgress({ index, total: pageCount });
|
|
1816
1681
|
renderPage(this, this.pdfDocument,
|
|
1817
1682
|
/* pageNumber = */ index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise)
|
|
1818
1683
|
.then(this.useRenderedPage.bind(this))
|
|
@@ -1825,23 +1690,24 @@ class PDFPrintService {
|
|
|
1825
1690
|
useRenderedPage() {
|
|
1826
1691
|
this.throwIfInactive();
|
|
1827
1692
|
const img = document.createElement("img");
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
img.src = URL.createObjectURL(blob);
|
|
1832
|
-
});
|
|
1833
|
-
}
|
|
1834
|
-
else {
|
|
1835
|
-
img.src = scratchCanvas.toDataURL();
|
|
1836
|
-
}
|
|
1693
|
+
this.scratchCanvas.toBlob(blob => {
|
|
1694
|
+
img.src = URL.createObjectURL(blob);
|
|
1695
|
+
});
|
|
1837
1696
|
const wrapper = document.createElement("div");
|
|
1838
1697
|
wrapper.className = "printedPage";
|
|
1839
1698
|
wrapper.append(img);
|
|
1840
1699
|
this.printContainer.append(wrapper);
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1700
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
1701
|
+
img.onload = resolve;
|
|
1702
|
+
img.onerror = reject;
|
|
1703
|
+
promise
|
|
1704
|
+
.catch(() => {
|
|
1705
|
+
// Avoid "Uncaught promise" messages in the console.
|
|
1706
|
+
})
|
|
1707
|
+
.then(() => {
|
|
1708
|
+
URL.revokeObjectURL(img.src);
|
|
1844
1709
|
});
|
|
1710
|
+
return promise;
|
|
1845
1711
|
}
|
|
1846
1712
|
performPrint() {
|
|
1847
1713
|
this.throwIfInactive();
|
|
@@ -1854,7 +1720,7 @@ class PDFPrintService {
|
|
|
1854
1720
|
resolve();
|
|
1855
1721
|
return;
|
|
1856
1722
|
}
|
|
1857
|
-
print
|
|
1723
|
+
window.print();
|
|
1858
1724
|
// Delay promise resolution in case print() was not synchronous.
|
|
1859
1725
|
setTimeout(resolve, 20); // Tidy-up.
|
|
1860
1726
|
}, 0);
|
|
@@ -1869,121 +1735,19 @@ class PDFPrintService {
|
|
|
1869
1735
|
}
|
|
1870
1736
|
}
|
|
1871
1737
|
}
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
console.warn("Ignored window.print() because of a pending print job.");
|
|
1876
|
-
return;
|
|
1877
|
-
}
|
|
1878
|
-
ensureOverlay().then(function () {
|
|
1879
|
-
if (activeService) {
|
|
1880
|
-
overlayManager.open(dialog);
|
|
1881
|
-
}
|
|
1882
|
-
});
|
|
1883
|
-
try {
|
|
1884
|
-
dispatchEvent("beforeprint");
|
|
1885
|
-
}
|
|
1886
|
-
finally {
|
|
1887
|
-
if (!activeService) {
|
|
1888
|
-
console.error("Expected print service to be initialized.");
|
|
1889
|
-
ensureOverlay().then(function () {
|
|
1890
|
-
if (overlayManager.active === dialog) {
|
|
1891
|
-
overlayManager.close(dialog);
|
|
1892
|
-
}
|
|
1893
|
-
});
|
|
1894
|
-
return; // eslint-disable-line no-unsafe-finally
|
|
1895
|
-
}
|
|
1896
|
-
const activeServiceOnEntry = activeService;
|
|
1897
|
-
activeService
|
|
1898
|
-
.renderPages()
|
|
1899
|
-
.then(function () {
|
|
1900
|
-
return activeServiceOnEntry.performPrint();
|
|
1901
|
-
})
|
|
1902
|
-
.catch(function () {
|
|
1903
|
-
// Ignore any error messages.
|
|
1904
|
-
})
|
|
1905
|
-
.then(function () {
|
|
1906
|
-
// aborts acts on the "active" print request, so we need to check
|
|
1907
|
-
// whether the print request (activeServiceOnEntry) is still active.
|
|
1908
|
-
// Without the check, an unrelated print request (created after aborting
|
|
1909
|
-
// this print request while the pages were being generated) would be
|
|
1910
|
-
// aborted.
|
|
1911
|
-
if (activeServiceOnEntry.active) {
|
|
1912
|
-
abort();
|
|
1913
|
-
}
|
|
1914
|
-
});
|
|
1915
|
-
}
|
|
1916
|
-
};
|
|
1917
|
-
function dispatchEvent(eventType) {
|
|
1918
|
-
const event = document.createEvent("CustomEvent");
|
|
1919
|
-
event.initCustomEvent(eventType, false, false, "custom");
|
|
1920
|
-
window.dispatchEvent(event);
|
|
1921
|
-
}
|
|
1922
|
-
function abort() {
|
|
1923
|
-
if (activeService) {
|
|
1924
|
-
activeService.destroy();
|
|
1925
|
-
dispatchEvent("afterprint");
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
function renderProgress(index, total, l10n) {
|
|
1929
|
-
dialog || (dialog = document.getElementById("printServiceDialog"));
|
|
1930
|
-
const progress = Math.round((100 * index) / total);
|
|
1931
|
-
const progressBar = dialog.querySelector("progress");
|
|
1932
|
-
const progressPerc = dialog.querySelector(".relative-progress");
|
|
1933
|
-
progressBar.value = progress;
|
|
1934
|
-
l10n.get("print_progress_percent", { progress }).then((msg) => {
|
|
1935
|
-
progressPerc.textContent = msg;
|
|
1936
|
-
});
|
|
1937
|
-
}
|
|
1938
|
-
window.addEventListener("keydown", function (event) {
|
|
1939
|
-
// Intercept Cmd/Ctrl + P in all browsers.
|
|
1940
|
-
// Also intercept Cmd/Ctrl + Shift + P in Chrome and Opera
|
|
1941
|
-
if (event.keyCode === /* P= */ 80 &&
|
|
1942
|
-
(event.ctrlKey || event.metaKey) &&
|
|
1943
|
-
!event.altKey &&
|
|
1944
|
-
!event.shiftKey // (!event.shiftKey || window.chrome || window.opera)
|
|
1945
|
-
) {
|
|
1946
|
-
window.print();
|
|
1947
|
-
event.preventDefault();
|
|
1948
|
-
event.stopImmediatePropagation();
|
|
1949
|
-
}
|
|
1950
|
-
}, true);
|
|
1951
|
-
if ("onbeforeprint" in window) {
|
|
1952
|
-
// Do not propagate before/afterprint events when they are not triggered
|
|
1953
|
-
// from within this polyfill. (FF / Chrome 63+).
|
|
1954
|
-
const stopPropagationIfNeeded = function (event) {
|
|
1955
|
-
if (event.detail !== "custom") {
|
|
1956
|
-
event.stopImmediatePropagation();
|
|
1957
|
-
}
|
|
1958
|
-
};
|
|
1959
|
-
window.addEventListener("beforeprint", stopPropagationIfNeeded);
|
|
1960
|
-
window.addEventListener("afterprint", stopPropagationIfNeeded);
|
|
1961
|
-
}
|
|
1962
|
-
let overlayPromise;
|
|
1963
|
-
function ensureOverlay() {
|
|
1964
|
-
if (!overlayPromise) {
|
|
1965
|
-
if (!overlayManager) {
|
|
1966
|
-
throw new Error("The overlay manager has not yet been initialized.");
|
|
1967
|
-
}
|
|
1968
|
-
dialog || (dialog = document.getElementById("printServiceDialog"));
|
|
1969
|
-
overlayPromise = overlayManager.register(dialog,
|
|
1970
|
-
/* canForceClose = */ true);
|
|
1971
|
-
document.getElementById("printCancel").onclick = abort;
|
|
1972
|
-
dialog.addEventListener("close", abort);
|
|
1973
|
-
}
|
|
1974
|
-
return overlayPromise;
|
|
1975
|
-
}
|
|
1738
|
+
/**
|
|
1739
|
+
* @implements {IPDFPrintServiceFactory}
|
|
1740
|
+
*/
|
|
1976
1741
|
const PDFPrintServiceFactory = {
|
|
1977
1742
|
instance: {
|
|
1978
1743
|
supportsPrinting: true,
|
|
1979
|
-
createPrintService(
|
|
1744
|
+
createPrintService(params) {
|
|
1980
1745
|
if (activeService) {
|
|
1981
1746
|
throw new Error("The print service is created and active.");
|
|
1982
1747
|
}
|
|
1983
|
-
activeService = new PDFPrintService(
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
},
|
|
1748
|
+
return (activeService = new PDFPrintService(params));
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1987
1751
|
};
|
|
1988
1752
|
|
|
1989
1753
|
/* Copyright 2012 Mozilla Foundation
|
|
@@ -2000,7 +1764,7 @@ const PDFPrintServiceFactory = {
|
|
|
2000
1764
|
* See the License for the specific language governing permissions and
|
|
2001
1765
|
* limitations under the License.
|
|
2002
1766
|
*/
|
|
2003
|
-
var _PDFPresentationMode_instances, _PDFPresentationMode_state, _PDFPresentationMode_args, _PDFPresentationMode_mouseWheel, _PDFPresentationMode_notifyStateChange, _PDFPresentationMode_enter, _PDFPresentationMode_exit, _PDFPresentationMode_mouseDown, _PDFPresentationMode_contextMenu, _PDFPresentationMode_showControls, _PDFPresentationMode_hideControls, _PDFPresentationMode_resetMouseScrollState, _PDFPresentationMode_touchSwipe, _PDFPresentationMode_addWindowListeners, _PDFPresentationMode_removeWindowListeners,
|
|
1767
|
+
var _PDFPresentationMode_instances, _PDFPresentationMode_state, _PDFPresentationMode_args, _PDFPresentationMode_fullscreenChangeAbortController, _PDFPresentationMode_windowAbortController, _PDFPresentationMode_mouseWheel, _PDFPresentationMode_notifyStateChange, _PDFPresentationMode_enter, _PDFPresentationMode_exit, _PDFPresentationMode_mouseDown, _PDFPresentationMode_contextMenu, _PDFPresentationMode_showControls, _PDFPresentationMode_hideControls, _PDFPresentationMode_resetMouseScrollState, _PDFPresentationMode_touchSwipe, _PDFPresentationMode_addWindowListeners, _PDFPresentationMode_removeWindowListeners, _PDFPresentationMode_addFullscreenChangeListeners, _PDFPresentationMode_removeFullscreenChangeListeners;
|
|
2004
1768
|
const DELAY_BEFORE_HIDING_CONTROLS = 3000; // in ms
|
|
2005
1769
|
const ACTIVE_SELECTOR = "pdfPresentationMode";
|
|
2006
1770
|
const CONTROLS_SELECTOR = "pdfPresentationModeControls";
|
|
@@ -2021,10 +1785,12 @@ class PDFPresentationMode {
|
|
|
2021
1785
|
/**
|
|
2022
1786
|
* @param {PDFPresentationModeOptions} options
|
|
2023
1787
|
*/
|
|
2024
|
-
constructor({ container, pdfViewer, eventBus
|
|
1788
|
+
constructor({ container, pdfViewer, eventBus }) {
|
|
2025
1789
|
_PDFPresentationMode_instances.add(this);
|
|
2026
1790
|
_PDFPresentationMode_state.set(this, PresentationModeState.UNKNOWN);
|
|
2027
1791
|
_PDFPresentationMode_args.set(this, null);
|
|
1792
|
+
_PDFPresentationMode_fullscreenChangeAbortController.set(this, null);
|
|
1793
|
+
_PDFPresentationMode_windowAbortController.set(this, null);
|
|
2028
1794
|
this.container = container;
|
|
2029
1795
|
this.pdfViewer = pdfViewer;
|
|
2030
1796
|
this.eventBus = eventBus;
|
|
@@ -2038,7 +1804,7 @@ class PDFPresentationMode {
|
|
|
2038
1804
|
* @returns {Promise<boolean>} Indicating if the request was successful.
|
|
2039
1805
|
*/
|
|
2040
1806
|
request() {
|
|
2041
|
-
return __awaiter(this,
|
|
1807
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2042
1808
|
const { container, pdfViewer } = this;
|
|
2043
1809
|
if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
|
|
2044
1810
|
return false;
|
|
@@ -2059,15 +1825,15 @@ class PDFPresentationMode {
|
|
|
2059
1825
|
"since the document may contain varying page sizes.");
|
|
2060
1826
|
__classPrivateFieldGet(this, _PDFPresentationMode_args, "f").spreadMode = pdfViewer.spreadMode;
|
|
2061
1827
|
}
|
|
2062
|
-
if (pdfViewer.annotationEditorMode
|
|
2063
|
-
__classPrivateFieldGet(this, _PDFPresentationMode_args, "f").annotationEditorMode = pdfViewer.annotationEditorMode
|
|
1828
|
+
if (pdfViewer.annotationEditorMode !== AnnotationEditorType.DISABLE) {
|
|
1829
|
+
__classPrivateFieldGet(this, _PDFPresentationMode_args, "f").annotationEditorMode = pdfViewer.annotationEditorMode;
|
|
2064
1830
|
}
|
|
2065
1831
|
try {
|
|
2066
1832
|
yield promise;
|
|
2067
1833
|
pdfViewer.focus(); // Fixes bug 1787456.
|
|
2068
1834
|
return true;
|
|
2069
1835
|
}
|
|
2070
|
-
catch (
|
|
1836
|
+
catch (_a) {
|
|
2071
1837
|
__classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_removeFullscreenChangeListeners).call(this);
|
|
2072
1838
|
__classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_notifyStateChange).call(this, PresentationModeState.NORMAL);
|
|
2073
1839
|
}
|
|
@@ -2079,7 +1845,7 @@ class PDFPresentationMode {
|
|
|
2079
1845
|
__classPrivateFieldGet(this, _PDFPresentationMode_state, "f") === PresentationModeState.FULLSCREEN);
|
|
2080
1846
|
}
|
|
2081
1847
|
}
|
|
2082
|
-
_PDFPresentationMode_state = new WeakMap(), _PDFPresentationMode_args = new WeakMap(), _PDFPresentationMode_instances = new WeakSet(), _PDFPresentationMode_mouseWheel = function _PDFPresentationMode_mouseWheel(evt) {
|
|
1848
|
+
_PDFPresentationMode_state = new WeakMap(), _PDFPresentationMode_args = new WeakMap(), _PDFPresentationMode_fullscreenChangeAbortController = new WeakMap(), _PDFPresentationMode_windowAbortController = new WeakMap(), _PDFPresentationMode_instances = new WeakSet(), _PDFPresentationMode_mouseWheel = function _PDFPresentationMode_mouseWheel(evt) {
|
|
2083
1849
|
if (!this.active) {
|
|
2084
1850
|
return;
|
|
2085
1851
|
}
|
|
@@ -2125,7 +1891,9 @@ _PDFPresentationMode_state = new WeakMap(), _PDFPresentationMode_args = new Weak
|
|
|
2125
1891
|
this.pdfViewer.currentPageNumber = __classPrivateFieldGet(this, _PDFPresentationMode_args, "f").pageNumber;
|
|
2126
1892
|
this.pdfViewer.currentScaleValue = "page-fit";
|
|
2127
1893
|
if (__classPrivateFieldGet(this, _PDFPresentationMode_args, "f").annotationEditorMode !== null) {
|
|
2128
|
-
this.pdfViewer.annotationEditorMode = {
|
|
1894
|
+
this.pdfViewer.annotationEditorMode = {
|
|
1895
|
+
mode: AnnotationEditorType.NONE,
|
|
1896
|
+
};
|
|
2129
1897
|
}
|
|
2130
1898
|
}, 0);
|
|
2131
1899
|
__classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_addWindowListeners).call(this);
|
|
@@ -2134,24 +1902,25 @@ _PDFPresentationMode_state = new WeakMap(), _PDFPresentationMode_args = new Weak
|
|
|
2134
1902
|
// Text selection is disabled in Presentation Mode, thus it's not possible
|
|
2135
1903
|
// for the user to deselect text that is selected (e.g. with "Select all")
|
|
2136
1904
|
// when entering Presentation Mode, hence we remove any active selection.
|
|
2137
|
-
(_a =
|
|
1905
|
+
(_a = document.getSelection()) === null || _a === void 0 ? void 0 : _a.empty();
|
|
2138
1906
|
}, _PDFPresentationMode_exit = function _PDFPresentationMode_exit() {
|
|
2139
1907
|
const pageNumber = this.pdfViewer.currentPageNumber;
|
|
2140
1908
|
this.container.classList.remove(ACTIVE_SELECTOR);
|
|
2141
1909
|
// Ensure that the correct page is scrolled into view when exiting
|
|
2142
1910
|
// Presentation Mode, by waiting until fullscreen mode is disabled.
|
|
2143
1911
|
setTimeout(() => {
|
|
2144
|
-
var _a;
|
|
2145
1912
|
__classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_removeFullscreenChangeListeners).call(this);
|
|
2146
1913
|
__classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_notifyStateChange).call(this, PresentationModeState.NORMAL);
|
|
2147
1914
|
this.pdfViewer.scrollMode = __classPrivateFieldGet(this, _PDFPresentationMode_args, "f").scrollMode;
|
|
2148
|
-
if (
|
|
1915
|
+
if (__classPrivateFieldGet(this, _PDFPresentationMode_args, "f").spreadMode !== null) {
|
|
2149
1916
|
this.pdfViewer.spreadMode = __classPrivateFieldGet(this, _PDFPresentationMode_args, "f").spreadMode;
|
|
2150
1917
|
}
|
|
2151
1918
|
this.pdfViewer.currentScaleValue = __classPrivateFieldGet(this, _PDFPresentationMode_args, "f").scaleValue;
|
|
2152
1919
|
this.pdfViewer.currentPageNumber = pageNumber;
|
|
2153
1920
|
if (__classPrivateFieldGet(this, _PDFPresentationMode_args, "f").annotationEditorMode !== null) {
|
|
2154
|
-
this.pdfViewer.annotationEditorMode = {
|
|
1921
|
+
this.pdfViewer.annotationEditorMode = {
|
|
1922
|
+
mode: __classPrivateFieldGet(this, _PDFPresentationMode_args, "f").annotationEditorMode,
|
|
1923
|
+
};
|
|
2155
1924
|
}
|
|
2156
1925
|
__classPrivateFieldSet(this, _PDFPresentationMode_args, null, "f");
|
|
2157
1926
|
}, 0);
|
|
@@ -2172,7 +1941,7 @@ _PDFPresentationMode_state = new WeakMap(), _PDFPresentationMode_args = new Weak
|
|
|
2172
1941
|
// Enable clicking of links in presentation mode. Note: only links
|
|
2173
1942
|
// pointing to destinations in the current PDF document work.
|
|
2174
1943
|
if (evt.target.href &&
|
|
2175
|
-
((_a = evt.target.parentNode) === null || _a ===
|
|
1944
|
+
((_a = evt.target.parentNode) === null || _a === void 0 ? void 0 : _a.hasAttribute("data-internal-link"))) {
|
|
2176
1945
|
return;
|
|
2177
1946
|
}
|
|
2178
1947
|
// Unless an internal link was clicked, advance one page.
|
|
@@ -2262,51 +2031,52 @@ _PDFPresentationMode_state = new WeakMap(), _PDFPresentationMode_args = new Weak
|
|
|
2262
2031
|
break;
|
|
2263
2032
|
}
|
|
2264
2033
|
}, _PDFPresentationMode_addWindowListeners = function _PDFPresentationMode_addWindowListeners() {
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
this
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
window.addEventListener("mousemove", this.
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
window.addEventListener("
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
window.addEventListener("
|
|
2278
|
-
window.addEventListener("touchend", this.touchSwipeBind);
|
|
2279
|
-
}, _PDFPresentationMode_removeWindowListeners = function _PDFPresentationMode_removeWindowListeners() {
|
|
2280
|
-
window.removeEventListener("mousemove", this.showControlsBind);
|
|
2281
|
-
window.removeEventListener("mousedown", this.mouseDownBind);
|
|
2282
|
-
window.removeEventListener("wheel", this.mouseWheelBind, {
|
|
2283
|
-
// @ts-ignore
|
|
2034
|
+
if (__classPrivateFieldGet(this, _PDFPresentationMode_windowAbortController, "f")) {
|
|
2035
|
+
return;
|
|
2036
|
+
}
|
|
2037
|
+
__classPrivateFieldSet(this, _PDFPresentationMode_windowAbortController, new AbortController(), "f");
|
|
2038
|
+
const { signal } = __classPrivateFieldGet(this, _PDFPresentationMode_windowAbortController, "f");
|
|
2039
|
+
const touchSwipeBind = __classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_touchSwipe).bind(this);
|
|
2040
|
+
window.addEventListener("mousemove", __classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_showControls).bind(this), {
|
|
2041
|
+
signal,
|
|
2042
|
+
});
|
|
2043
|
+
window.addEventListener("mousedown", __classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_mouseDown).bind(this), {
|
|
2044
|
+
signal,
|
|
2045
|
+
});
|
|
2046
|
+
window.addEventListener("wheel", __classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_mouseWheel).bind(this), {
|
|
2284
2047
|
passive: false,
|
|
2048
|
+
signal,
|
|
2285
2049
|
});
|
|
2286
|
-
window.
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
window.
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
__classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_enter).call(this);
|
|
2300
|
-
}
|
|
2301
|
-
else {
|
|
2302
|
-
__classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_exit).call(this);
|
|
2303
|
-
}
|
|
2050
|
+
window.addEventListener("keydown", __classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_resetMouseScrollState).bind(this), {
|
|
2051
|
+
signal,
|
|
2052
|
+
});
|
|
2053
|
+
window.addEventListener("contextmenu", __classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_contextMenu).bind(this), {
|
|
2054
|
+
signal,
|
|
2055
|
+
});
|
|
2056
|
+
window.addEventListener("touchstart", touchSwipeBind, { signal });
|
|
2057
|
+
window.addEventListener("touchmove", touchSwipeBind, { signal });
|
|
2058
|
+
window.addEventListener("touchend", touchSwipeBind, { signal });
|
|
2059
|
+
}, _PDFPresentationMode_removeWindowListeners = function _PDFPresentationMode_removeWindowListeners() {
|
|
2060
|
+
var _a;
|
|
2061
|
+
(_a = __classPrivateFieldGet(this, _PDFPresentationMode_windowAbortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
|
2062
|
+
__classPrivateFieldSet(this, _PDFPresentationMode_windowAbortController, null, "f");
|
|
2304
2063
|
}, _PDFPresentationMode_addFullscreenChangeListeners = function _PDFPresentationMode_addFullscreenChangeListeners() {
|
|
2305
|
-
|
|
2306
|
-
|
|
2064
|
+
if (__classPrivateFieldGet(this, _PDFPresentationMode_fullscreenChangeAbortController, "f")) {
|
|
2065
|
+
return;
|
|
2066
|
+
}
|
|
2067
|
+
__classPrivateFieldSet(this, _PDFPresentationMode_fullscreenChangeAbortController, new AbortController(), "f");
|
|
2068
|
+
window.addEventListener("fullscreenchange", () => {
|
|
2069
|
+
if ( /* isFullscreen = */document.fullscreenElement) {
|
|
2070
|
+
__classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_enter).call(this);
|
|
2071
|
+
}
|
|
2072
|
+
else {
|
|
2073
|
+
__classPrivateFieldGet(this, _PDFPresentationMode_instances, "m", _PDFPresentationMode_exit).call(this);
|
|
2074
|
+
}
|
|
2075
|
+
}, { signal: __classPrivateFieldGet(this, _PDFPresentationMode_fullscreenChangeAbortController, "f").signal });
|
|
2307
2076
|
}, _PDFPresentationMode_removeFullscreenChangeListeners = function _PDFPresentationMode_removeFullscreenChangeListeners() {
|
|
2308
|
-
|
|
2309
|
-
|
|
2077
|
+
var _a;
|
|
2078
|
+
(_a = __classPrivateFieldGet(this, _PDFPresentationMode_fullscreenChangeAbortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
|
2079
|
+
__classPrivateFieldSet(this, _PDFPresentationMode_fullscreenChangeAbortController, null, "f");
|
|
2310
2080
|
};
|
|
2311
2081
|
|
|
2312
2082
|
const initialState = {
|
|
@@ -2364,7 +2134,289 @@ const create = () => createStore((set, get) => (Object.assign(Object.assign({},
|
|
|
2364
2134
|
set({ thumbnailViews, thumbnails });
|
|
2365
2135
|
} })));
|
|
2366
2136
|
|
|
2367
|
-
var
|
|
2137
|
+
var _PDFSlickPrintService_instances, _PDFSlickPrintService_printService, _PDFSlickPrintService_eventAbortController, _PDFSlickPrintService_printContainer, _PDFSlickPrintService_beforePrint, _PDFSlickPrintService_afterPrint;
|
|
2138
|
+
class PDFSlickPrintService {
|
|
2139
|
+
constructor({ eventBus, slick, printDialog }) {
|
|
2140
|
+
_PDFSlickPrintService_instances.add(this);
|
|
2141
|
+
_PDFSlickPrintService_printService.set(this, null);
|
|
2142
|
+
_PDFSlickPrintService_eventAbortController.set(this, null);
|
|
2143
|
+
_PDFSlickPrintService_printContainer.set(this, null);
|
|
2144
|
+
this.eventBus = eventBus;
|
|
2145
|
+
this.slick = slick;
|
|
2146
|
+
this.printDialog = printDialog !== null && printDialog !== void 0 ? printDialog : null;
|
|
2147
|
+
this.bindEvents();
|
|
2148
|
+
}
|
|
2149
|
+
get supportsPrinting() {
|
|
2150
|
+
return PDFPrintServiceFactory.instance.supportsPrinting;
|
|
2151
|
+
}
|
|
2152
|
+
get printing() {
|
|
2153
|
+
return !!__classPrivateFieldGet(this, _PDFSlickPrintService_printService, "f");
|
|
2154
|
+
}
|
|
2155
|
+
print() {
|
|
2156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2157
|
+
var _a, _b;
|
|
2158
|
+
if (!this.supportsPrinting) {
|
|
2159
|
+
return;
|
|
2160
|
+
}
|
|
2161
|
+
if (this.printing) {
|
|
2162
|
+
console.warn("Ignored pdf print because of a pending print job.");
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
yield ((_a = this.printDialog) === null || _a === void 0 ? void 0 : _a.open({
|
|
2166
|
+
close: () => this.abort()
|
|
2167
|
+
}));
|
|
2168
|
+
try {
|
|
2169
|
+
this.eventBus.dispatch("beforeprint", { source: this });
|
|
2170
|
+
}
|
|
2171
|
+
finally {
|
|
2172
|
+
if (!this.printing) {
|
|
2173
|
+
console.error("Expected print service to be initialized.");
|
|
2174
|
+
(_b = this.printDialog) === null || _b === void 0 ? void 0 : _b.close();
|
|
2175
|
+
}
|
|
2176
|
+
else {
|
|
2177
|
+
const printService = __classPrivateFieldGet(this, _PDFSlickPrintService_printService, "f");
|
|
2178
|
+
yield printService
|
|
2179
|
+
.renderPages(x => { var _a; return (_a = this.printDialog) === null || _a === void 0 ? void 0 : _a.progress(x); })
|
|
2180
|
+
.then(() => printService.performPrint())
|
|
2181
|
+
.catch(() => {
|
|
2182
|
+
// Ignore any error messages.
|
|
2183
|
+
})
|
|
2184
|
+
.then(() => {
|
|
2185
|
+
// aborts acts on the "active" print request, so we need to check
|
|
2186
|
+
// whether the print request (activeServiceOnEntry) is still active.
|
|
2187
|
+
// Without the check, an unrelated print request (created after
|
|
2188
|
+
// aborting this print request while the pages were being generated)
|
|
2189
|
+
// would be aborted.
|
|
2190
|
+
const active = printService === __classPrivateFieldGet(this, _PDFSlickPrintService_printService, "f");
|
|
2191
|
+
if (active) {
|
|
2192
|
+
this.abort();
|
|
2193
|
+
}
|
|
2194
|
+
});
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
abort() {
|
|
2200
|
+
var _a;
|
|
2201
|
+
if (__classPrivateFieldGet(this, _PDFSlickPrintService_printService, "f")) {
|
|
2202
|
+
__classPrivateFieldGet(this, _PDFSlickPrintService_printService, "f").destroy();
|
|
2203
|
+
(_a = this.printDialog) === null || _a === void 0 ? void 0 : _a.close();
|
|
2204
|
+
this.eventBus.dispatch("afterprint", { source: this });
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
bindEvents() {
|
|
2208
|
+
__classPrivateFieldSet(this, _PDFSlickPrintService_eventAbortController, new AbortController(), "f");
|
|
2209
|
+
const { signal } = __classPrivateFieldGet(this, _PDFSlickPrintService_eventAbortController, "f");
|
|
2210
|
+
const opts = { signal };
|
|
2211
|
+
this.eventBus._on("beforeprint", __classPrivateFieldGet(this, _PDFSlickPrintService_instances, "m", _PDFSlickPrintService_beforePrint).bind(this), opts);
|
|
2212
|
+
this.eventBus._on("afterprint", __classPrivateFieldGet(this, _PDFSlickPrintService_instances, "m", _PDFSlickPrintService_afterPrint).bind(this), opts);
|
|
2213
|
+
window.addEventListener("beforeprint", () => this.eventBus.dispatch("beforeprint", { source: window }), opts);
|
|
2214
|
+
window.addEventListener("afterprint", () => this.eventBus.dispatch("afterprint", { source: window }), opts);
|
|
2215
|
+
window.addEventListener("keydown", (event) => {
|
|
2216
|
+
// Intercept Cmd/Ctrl + P in all browsers.
|
|
2217
|
+
// Also intercept Cmd/Ctrl + Shift + P in Chrome and Opera
|
|
2218
|
+
if (event.keyCode === /* P= */ 80 &&
|
|
2219
|
+
(event.ctrlKey || event.metaKey) &&
|
|
2220
|
+
!event.altKey &&
|
|
2221
|
+
(!event.shiftKey || window.chrome || window.opera)) {
|
|
2222
|
+
this.print();
|
|
2223
|
+
event.preventDefault();
|
|
2224
|
+
event.stopImmediatePropagation();
|
|
2225
|
+
}
|
|
2226
|
+
}, { signal, capture: true });
|
|
2227
|
+
}
|
|
2228
|
+
unbindEvents() {
|
|
2229
|
+
var _a;
|
|
2230
|
+
(_a = __classPrivateFieldGet(this, _PDFSlickPrintService_eventAbortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
|
2231
|
+
__classPrivateFieldSet(this, _PDFSlickPrintService_eventAbortController, null, "f");
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
_PDFSlickPrintService_printService = new WeakMap(), _PDFSlickPrintService_eventAbortController = new WeakMap(), _PDFSlickPrintService_printContainer = new WeakMap(), _PDFSlickPrintService_instances = new WeakSet(), _PDFSlickPrintService_beforePrint = function _PDFSlickPrintService_beforePrint() {
|
|
2235
|
+
if (__classPrivateFieldGet(this, _PDFSlickPrintService_printService, "f")) {
|
|
2236
|
+
// There is no way to suppress beforePrint/afterPrint events,
|
|
2237
|
+
// but PDFPrintService may generate double events -- this will ignore
|
|
2238
|
+
// the second event that will be coming from native window.print().
|
|
2239
|
+
return;
|
|
2240
|
+
}
|
|
2241
|
+
if (!this.supportsPrinting) {
|
|
2242
|
+
// this.l10n.get("printing_not_supported").then(msg => {
|
|
2243
|
+
// this._otherError(msg);
|
|
2244
|
+
// });
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
// The beforePrint is a sync method and we need to know layout before
|
|
2248
|
+
// returning from this method. Ensure that we can get sizes of the pages.
|
|
2249
|
+
if (!this.slick.viewer.pageViewsReady) {
|
|
2250
|
+
this.slick.l10n.get("printing_not_ready", null).then((msg) => {
|
|
2251
|
+
// eslint-disable-next-line no-alert
|
|
2252
|
+
window.alert(msg);
|
|
2253
|
+
});
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
__classPrivateFieldSet(this, _PDFSlickPrintService_printContainer, createPrintContainer(), "f");
|
|
2257
|
+
__classPrivateFieldSet(this, _PDFSlickPrintService_printService, PDFPrintServiceFactory.instance.createPrintService({
|
|
2258
|
+
pdfDocument: this.slick.document,
|
|
2259
|
+
pagesOverview: this.slick.viewer.getPagesOverview(),
|
|
2260
|
+
printContainer: __classPrivateFieldGet(this, _PDFSlickPrintService_printContainer, "f").element,
|
|
2261
|
+
printResolution: this.slick.printResolution,
|
|
2262
|
+
optionalContentConfigPromise: null,
|
|
2263
|
+
printAnnotationStoragePromise: null, // this._printAnnotationStoragePromise,
|
|
2264
|
+
}), "f");
|
|
2265
|
+
this.slick.forceRendering();
|
|
2266
|
+
__classPrivateFieldGet(this, _PDFSlickPrintService_printService, "f").layout();
|
|
2267
|
+
}, _PDFSlickPrintService_afterPrint = function _PDFSlickPrintService_afterPrint() {
|
|
2268
|
+
var _a, _b, _c;
|
|
2269
|
+
if (__classPrivateFieldGet(this, _PDFSlickPrintService_printService, "f")) {
|
|
2270
|
+
__classPrivateFieldGet(this, _PDFSlickPrintService_printService, "f").destroy();
|
|
2271
|
+
__classPrivateFieldSet(this, _PDFSlickPrintService_printService, null, "f");
|
|
2272
|
+
(_a = this.printDialog) === null || _a === void 0 ? void 0 : _a.close();
|
|
2273
|
+
(_b = __classPrivateFieldGet(this, _PDFSlickPrintService_printContainer, "f")) === null || _b === void 0 ? void 0 : _b.remove();
|
|
2274
|
+
__classPrivateFieldSet(this, _PDFSlickPrintService_printContainer, null, "f");
|
|
2275
|
+
(_c = this.slick.document) === null || _c === void 0 ? void 0 : _c.annotationStorage.resetModified();
|
|
2276
|
+
}
|
|
2277
|
+
this.slick.forceRendering();
|
|
2278
|
+
};
|
|
2279
|
+
function createPrintContainer() {
|
|
2280
|
+
const printContainer = document.createElement("div");
|
|
2281
|
+
printContainer.classList.add('pdfSlickPrintContainer');
|
|
2282
|
+
document.body.append(printContainer);
|
|
2283
|
+
const sheet = document.createElement("style");
|
|
2284
|
+
/** source: https://github.com/mozilla/pdf.js/blob/v4.10.38/web/viewer.css */
|
|
2285
|
+
sheet.textContent = `
|
|
2286
|
+
@page {
|
|
2287
|
+
margin: 0;
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
.pdfSlickPrintContainer {
|
|
2291
|
+
display: none;
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
@media print {
|
|
2295
|
+
body {
|
|
2296
|
+
background: rgb(0 0 0 / 0) none;
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
body[data-pdfjsprinting] > *:not(.pdfSlickPrintContainer) {
|
|
2300
|
+
display: none;
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
body[data-pdfjsprinting] .pdfSlickPrintContainer {
|
|
2304
|
+
display: block;
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
.pdfSlickPrintContainer {
|
|
2308
|
+
height: 100%;
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
/* wrapper around (scaled) print canvas elements */
|
|
2312
|
+
.pdfSlickPrintContainer > .printedPage {
|
|
2313
|
+
page-break-after: always;
|
|
2314
|
+
page-break-inside: avoid;
|
|
2315
|
+
|
|
2316
|
+
/* The wrapper always cover the whole page. */
|
|
2317
|
+
height: 100%;
|
|
2318
|
+
width: 100%;
|
|
2319
|
+
|
|
2320
|
+
display: flex;
|
|
2321
|
+
flex-direction: column;
|
|
2322
|
+
justify-content: center;
|
|
2323
|
+
align-items: center;
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
.pdfSlickPrintContainer > .xfaPrintedPage .xfaPage {
|
|
2327
|
+
position: absolute;
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
.pdfSlickPrintContainer > .xfaPrintedPage {
|
|
2331
|
+
page-break-after: always;
|
|
2332
|
+
page-break-inside: avoid;
|
|
2333
|
+
width: 100%;
|
|
2334
|
+
height: 100%;
|
|
2335
|
+
position: relative;
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
.pdfSlickPrintContainer > .printedPage :is(canvas, img) {
|
|
2339
|
+
/* The intrinsic canvas / image size will make sure that we fit the page. */
|
|
2340
|
+
max-width: 100%;
|
|
2341
|
+
max-height: 100%;
|
|
2342
|
+
|
|
2343
|
+
direction: ltr;
|
|
2344
|
+
display: block;
|
|
2345
|
+
}
|
|
2346
|
+
}`;
|
|
2347
|
+
document.body.append(sheet);
|
|
2348
|
+
return {
|
|
2349
|
+
get element() { return printContainer; },
|
|
2350
|
+
remove: () => {
|
|
2351
|
+
printContainer.remove();
|
|
2352
|
+
sheet.remove();
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
class PDFSlickPrintDialog {
|
|
2358
|
+
static create() {
|
|
2359
|
+
let dialog = document.querySelector('#printServiceDialog');
|
|
2360
|
+
if (!dialog) {
|
|
2361
|
+
/** A small helper to constuct DOM elements */
|
|
2362
|
+
const h = (tag, attr, children) => {
|
|
2363
|
+
const e = document.createElement(tag);
|
|
2364
|
+
Object.entries(attr).forEach(([k, v]) => e.setAttribute(k, v));
|
|
2365
|
+
e.append(...children);
|
|
2366
|
+
return e;
|
|
2367
|
+
};
|
|
2368
|
+
/** Print dialog as used in https://github.com/mozilla/pdf.js */
|
|
2369
|
+
dialog = h('dialog', { id: 'printServiceDialog', class: 'pdfSlick-dialog', style: 'min-width: 200px;' }, [
|
|
2370
|
+
h('div', { class: 'row' }, [
|
|
2371
|
+
h('span', { 'data-l10n-id': 'pdfjs-print-progress-message' }, ["Preparing document for printing…"]),
|
|
2372
|
+
]),
|
|
2373
|
+
h('div', { class: 'row' }, [
|
|
2374
|
+
h('progress', { value: '0', max: '100' }, []),
|
|
2375
|
+
h('span', { 'data-l10n-id': 'pdfjs-print-progress-percent', 'data-l10n-args': '{ "progress": 0 }', class: 'relative-progress' }, ['0%']),
|
|
2376
|
+
]),
|
|
2377
|
+
h('div', { class: 'buttonRow' }, [
|
|
2378
|
+
h('button', { id: 'printCancel', class: 'dialogButton', type: 'button' }, [
|
|
2379
|
+
h('span', { 'data-l10n-id': 'pdfjs-print-progress-close-button' }, ['Cancel'])
|
|
2380
|
+
]),
|
|
2381
|
+
]),
|
|
2382
|
+
]);
|
|
2383
|
+
document.body.append(dialog);
|
|
2384
|
+
}
|
|
2385
|
+
return new PDFSlickPrintDialog(dialog);
|
|
2386
|
+
}
|
|
2387
|
+
constructor(dialog) {
|
|
2388
|
+
this.dialog = dialog;
|
|
2389
|
+
}
|
|
2390
|
+
open(options) {
|
|
2391
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2392
|
+
const btnClose = this.dialog.querySelector('#printCancel');
|
|
2393
|
+
const cancelHandler = () => {
|
|
2394
|
+
var _a;
|
|
2395
|
+
this.dialog.removeEventListener("close", cancelHandler);
|
|
2396
|
+
this.dialog.removeEventListener("cancel", cancelHandler);
|
|
2397
|
+
btnClose === null || btnClose === void 0 ? void 0 : btnClose.removeEventListener("click", cancelHandler);
|
|
2398
|
+
(_a = options === null || options === void 0 ? void 0 : options.close) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
2399
|
+
this.close();
|
|
2400
|
+
};
|
|
2401
|
+
this.dialog.addEventListener("close", cancelHandler);
|
|
2402
|
+
this.dialog.addEventListener("cancel", cancelHandler);
|
|
2403
|
+
btnClose === null || btnClose === void 0 ? void 0 : btnClose.addEventListener("click", cancelHandler);
|
|
2404
|
+
this.dialog.showModal();
|
|
2405
|
+
});
|
|
2406
|
+
}
|
|
2407
|
+
close() {
|
|
2408
|
+
this.dialog.close();
|
|
2409
|
+
}
|
|
2410
|
+
progress({ index, total }) {
|
|
2411
|
+
const progress = Math.round((100 * index) / total);
|
|
2412
|
+
const progressBar = this.dialog.querySelector("progress");
|
|
2413
|
+
const progressPerc = this.dialog.querySelector(".relative-progress");
|
|
2414
|
+
progressBar.value = progress;
|
|
2415
|
+
progressPerc.setAttribute("data-l10n-args", JSON.stringify({ progress }));
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
var _PDFSlick_instances, _PDFSlick_renderingQueue, _PDFSlick_container, _PDFSlick_viewerContainer, _PDFSlick_thumbsContainer, _PDFSlick_printService, _PDFSlick_annotationMode, _PDFSlick_annotationEditorMode, _PDFSlick_onError, _PDFSlick_eventAbortController, _PDFSlick_initializePageLabels, _PDFSlick_parseDocumentInfo, _PDFSlick_parsePageSize, _PDFSlick_initInternalEventListeners, _PDFSlick_onDocumentReady, _PDFSlick_onRotationChanging, _PDFSlick_onSwitchSpreadMode, _PDFSlick_onSwitchScrollMode, _PDFSlick_onScaleChanging, _PDFSlick_onPageChanging, _PDFSlick_onPageRendered;
|
|
2368
2420
|
GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).toString();
|
|
2369
2421
|
const US_PAGE_NAMES = {
|
|
2370
2422
|
"8.5x11": "Letter",
|
|
@@ -2380,40 +2432,42 @@ function getPageName(size, isPortrait, pageNames) {
|
|
|
2380
2432
|
return pageNames[`${width}x${height}`];
|
|
2381
2433
|
}
|
|
2382
2434
|
class PDFSlick {
|
|
2383
|
-
constructor({ container, viewer, thumbs, store = create(), options, onError, }) {
|
|
2435
|
+
constructor({ container, viewer, thumbs, store = create(), options, onError, printDialog, }) {
|
|
2384
2436
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
2385
2437
|
_PDFSlick_instances.add(this);
|
|
2386
|
-
_PDFSlick_renderingQueue.set(this,
|
|
2387
|
-
_PDFSlick_container.set(this,
|
|
2388
|
-
_PDFSlick_viewerContainer.set(this,
|
|
2389
|
-
_PDFSlick_thumbsContainer.set(this,
|
|
2438
|
+
_PDFSlick_renderingQueue.set(this, void 0);
|
|
2439
|
+
_PDFSlick_container.set(this, void 0);
|
|
2440
|
+
_PDFSlick_viewerContainer.set(this, void 0);
|
|
2441
|
+
_PDFSlick_thumbsContainer.set(this, void 0);
|
|
2442
|
+
_PDFSlick_printService.set(this, void 0);
|
|
2390
2443
|
this.downloadManager = null;
|
|
2391
2444
|
this.findController = null;
|
|
2392
2445
|
this.pdfPresentationMode = null;
|
|
2393
2446
|
this.document = null;
|
|
2394
2447
|
// options
|
|
2395
|
-
_PDFSlick_annotationMode.set(this,
|
|
2396
|
-
_PDFSlick_annotationEditorMode.set(this,
|
|
2397
|
-
_PDFSlick_onError.set(this,
|
|
2448
|
+
_PDFSlick_annotationMode.set(this, void 0);
|
|
2449
|
+
_PDFSlick_annotationEditorMode.set(this, void 0);
|
|
2450
|
+
_PDFSlick_onError.set(this, void 0);
|
|
2451
|
+
_PDFSlick_eventAbortController.set(this, void 0);
|
|
2398
2452
|
__classPrivateFieldSet(this, _PDFSlick_container, container, "f");
|
|
2399
2453
|
__classPrivateFieldSet(this, _PDFSlick_viewerContainer, viewer, "f");
|
|
2400
2454
|
__classPrivateFieldSet(this, _PDFSlick_thumbsContainer, thumbs, "f");
|
|
2401
2455
|
__classPrivateFieldSet(this, _PDFSlick_onError, onError, "f");
|
|
2402
|
-
this.l10n = (_a = options === null || options ===
|
|
2456
|
+
this.l10n = (_a = options === null || options === void 0 ? void 0 : options.l10n) !== null && _a !== void 0 ? _a : new GenericL10n(navigator.language);
|
|
2403
2457
|
this.downloadManager = new DownloadManager();
|
|
2404
|
-
this.textLayerMode = (_b = options === null || options ===
|
|
2405
|
-
__classPrivateFieldSet(this, _PDFSlick_annotationMode, (_c = options === null || options ===
|
|
2406
|
-
__classPrivateFieldSet(this, _PDFSlick_annotationEditorMode, (_d = options === null || options ===
|
|
2407
|
-
this.annotationEditorHighlightColors = (_e = options === null || options ===
|
|
2408
|
-
this.removePageBorders = (_f = options === null || options ===
|
|
2409
|
-
this.singlePageViewer = (_g = options === null || options ===
|
|
2410
|
-
this.enablePrintAutoRotate = (_h = options === null || options ===
|
|
2411
|
-
this.useOnlyCssZoom = (_j = options === null || options ===
|
|
2412
|
-
this.pageColors = (_k = options === null || options ===
|
|
2413
|
-
this.maxCanvasPixels = (_l = options === null || options ===
|
|
2414
|
-
this.printResolution = (_m = options === null || options ===
|
|
2415
|
-
this.thumbnailWidth = (_o = options === null || options ===
|
|
2416
|
-
this.getDocumentParams = (_p = options === null || options ===
|
|
2458
|
+
this.textLayerMode = (_b = options === null || options === void 0 ? void 0 : options.textLayerMode) !== null && _b !== void 0 ? _b : TextLayerMode.ENABLE;
|
|
2459
|
+
__classPrivateFieldSet(this, _PDFSlick_annotationMode, (_c = options === null || options === void 0 ? void 0 : options.annotationMode) !== null && _c !== void 0 ? _c : AnnotationMode.ENABLE_FORMS, "f");
|
|
2460
|
+
__classPrivateFieldSet(this, _PDFSlick_annotationEditorMode, (_d = options === null || options === void 0 ? void 0 : options.annotationEditorMode) !== null && _d !== void 0 ? _d : AnnotationEditorType.NONE, "f");
|
|
2461
|
+
this.annotationEditorHighlightColors = (_e = options === null || options === void 0 ? void 0 : options.annotationEditorHighlightColors) !== null && _e !== void 0 ? _e : "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F";
|
|
2462
|
+
this.removePageBorders = (_f = options === null || options === void 0 ? void 0 : options.removePageBorders) !== null && _f !== void 0 ? _f : false;
|
|
2463
|
+
this.singlePageViewer = (_g = options === null || options === void 0 ? void 0 : options.singlePageViewer) !== null && _g !== void 0 ? _g : false;
|
|
2464
|
+
this.enablePrintAutoRotate = (_h = options === null || options === void 0 ? void 0 : options.enablePrintAutoRotate) !== null && _h !== void 0 ? _h : false;
|
|
2465
|
+
this.useOnlyCssZoom = (_j = options === null || options === void 0 ? void 0 : options.useOnlyCssZoom) !== null && _j !== void 0 ? _j : false;
|
|
2466
|
+
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 : 16777216;
|
|
2468
|
+
this.printResolution = (_m = options === null || options === void 0 ? void 0 : options.printResolution) !== null && _m !== void 0 ? _m : 96;
|
|
2469
|
+
this.thumbnailWidth = (_o = options === null || options === void 0 ? void 0 : options.thumbnailWidth) !== null && _o !== void 0 ? _o : 125;
|
|
2470
|
+
this.getDocumentParams = (_p = options === null || options === void 0 ? void 0 : options.getDocumentParams) !== null && _p !== void 0 ? _p : {};
|
|
2417
2471
|
if (this.pageColors &&
|
|
2418
2472
|
!(CSS.supports("color", this.pageColors.background) &&
|
|
2419
2473
|
CSS.supports("color", this.pageColors.foreground))) {
|
|
@@ -2435,8 +2489,7 @@ class PDFSlick {
|
|
|
2435
2489
|
ignoreDestinationZoom: false,
|
|
2436
2490
|
});
|
|
2437
2491
|
const viewerOptions = Object.assign(Object.assign({ container }, (viewer && { viewer })), { eventBus,
|
|
2438
|
-
linkService,
|
|
2439
|
-
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/" });
|
|
2492
|
+
linkService, 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/" });
|
|
2440
2493
|
const pdfViewer = this.singlePageViewer
|
|
2441
2494
|
? new PDFSinglePageViewer(viewerOptions)
|
|
2442
2495
|
: new PDFViewer(viewerOptions);
|
|
@@ -2447,8 +2500,8 @@ class PDFSlick {
|
|
|
2447
2500
|
eventBus,
|
|
2448
2501
|
linkService,
|
|
2449
2502
|
renderingQueue,
|
|
2450
|
-
l10n: this.l10n,
|
|
2451
2503
|
pageColors: this.pageColors,
|
|
2504
|
+
enableHWA: undefined,
|
|
2452
2505
|
store: store,
|
|
2453
2506
|
thumbnailWidth: this.thumbnailWidth,
|
|
2454
2507
|
});
|
|
@@ -2465,11 +2518,16 @@ class PDFSlick {
|
|
|
2465
2518
|
this.linkService = linkService;
|
|
2466
2519
|
this.viewer = pdfViewer;
|
|
2467
2520
|
this.linkService.setViewer(pdfViewer);
|
|
2468
|
-
|
|
2521
|
+
__classPrivateFieldSet(this, _PDFSlick_printService, new PDFSlickPrintService({
|
|
2522
|
+
eventBus,
|
|
2523
|
+
slick: this,
|
|
2524
|
+
printDialog: printDialog !== null && printDialog !== void 0 ? printDialog : PDFSlickPrintDialog.create(),
|
|
2525
|
+
}), "f");
|
|
2526
|
+
const scaleValue = (_q = options === null || options === void 0 ? void 0 : options.scaleValue) !== null && _q !== void 0 ? _q : "auto";
|
|
2469
2527
|
this.store.setState({ scaleValue });
|
|
2470
2528
|
}
|
|
2471
2529
|
loadDocument(url, options) {
|
|
2472
|
-
return __awaiter(this,
|
|
2530
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2473
2531
|
var _a, _b, _c, _d, _e;
|
|
2474
2532
|
if (this.url && typeof this.url === "string") {
|
|
2475
2533
|
try {
|
|
@@ -2527,9 +2585,8 @@ class PDFSlick {
|
|
|
2527
2585
|
});
|
|
2528
2586
|
}
|
|
2529
2587
|
forceRendering(isThumbnailViewEnabled = true) {
|
|
2530
|
-
__classPrivateFieldGet(this, _PDFSlick_renderingQueue, "f").printing = !!this.
|
|
2588
|
+
__classPrivateFieldGet(this, _PDFSlick_renderingQueue, "f").printing = !!__classPrivateFieldGet(this, _PDFSlick_printService, "f").printing;
|
|
2531
2589
|
__classPrivateFieldGet(this, _PDFSlick_renderingQueue, "f").isThumbnailViewEnabled = isThumbnailViewEnabled;
|
|
2532
|
-
// @ts-ignore
|
|
2533
2590
|
__classPrivateFieldGet(this, _PDFSlick_renderingQueue, "f").renderHighestPriority();
|
|
2534
2591
|
}
|
|
2535
2592
|
gotoPage(pageNumber) {
|
|
@@ -2537,10 +2594,10 @@ class PDFSlick {
|
|
|
2537
2594
|
}
|
|
2538
2595
|
openOrDownloadData(data, filename) {
|
|
2539
2596
|
var _a;
|
|
2540
|
-
(_a = this.downloadManager) === null || _a ===
|
|
2597
|
+
(_a = this.downloadManager) === null || _a === void 0 ? void 0 : _a.openOrDownloadData(data, filename);
|
|
2541
2598
|
}
|
|
2542
2599
|
download() {
|
|
2543
|
-
return __awaiter(this,
|
|
2600
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2544
2601
|
var _a, _b;
|
|
2545
2602
|
const url = this.url;
|
|
2546
2603
|
const { filename } = this;
|
|
@@ -2553,12 +2610,12 @@ class PDFSlick {
|
|
|
2553
2610
|
catch (reason) {
|
|
2554
2611
|
// When the PDF document isn't ready, or the PDF file is still
|
|
2555
2612
|
// downloading, simply download using the URL.
|
|
2556
|
-
yield ((_b = this.downloadManager) === null || _b ===
|
|
2613
|
+
yield ((_b = this.downloadManager) === null || _b === void 0 ? void 0 : _b.download(null, url, filename));
|
|
2557
2614
|
}
|
|
2558
2615
|
});
|
|
2559
2616
|
}
|
|
2560
2617
|
save() {
|
|
2561
|
-
return __awaiter(this,
|
|
2618
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2562
2619
|
// if (this._saveInProgress) return;
|
|
2563
2620
|
// this._saveInProgress = true;
|
|
2564
2621
|
// await this.pdfScriptingManager.dispatchWillSave();
|
|
@@ -2591,7 +2648,7 @@ class PDFSlick {
|
|
|
2591
2648
|
}
|
|
2592
2649
|
downloadOrSave() {
|
|
2593
2650
|
var _a;
|
|
2594
|
-
const { annotationStorage } = (_a = this.document) !== null && _a !==
|
|
2651
|
+
const { annotationStorage } = (_a = this.document) !== null && _a !== void 0 ? _a : {};
|
|
2595
2652
|
if (annotationStorage && annotationStorage.size > 0) {
|
|
2596
2653
|
this.save();
|
|
2597
2654
|
}
|
|
@@ -2600,82 +2657,20 @@ class PDFSlick {
|
|
|
2600
2657
|
}
|
|
2601
2658
|
}
|
|
2602
2659
|
get supportsPrinting() {
|
|
2603
|
-
return
|
|
2604
|
-
}
|
|
2605
|
-
beforePrint() {
|
|
2606
|
-
// this._printAnnotationStoragePromise = this.pdfScriptingManager
|
|
2607
|
-
// .dispatchWillPrint()
|
|
2608
|
-
// .catch(() => {
|
|
2609
|
-
// /* Avoid breaking printing; ignoring errors. */
|
|
2610
|
-
// })
|
|
2611
|
-
// .then(() => {
|
|
2612
|
-
// return this.document?.annotationStorage.print;
|
|
2613
|
-
// });
|
|
2614
|
-
if (this.printService) {
|
|
2615
|
-
// There is no way to suppress beforePrint/afterPrint events,
|
|
2616
|
-
// but PDFPrintService may generate double events -- this will ignore
|
|
2617
|
-
// the second event that will be coming from native window.print().
|
|
2618
|
-
return;
|
|
2619
|
-
}
|
|
2620
|
-
if (!this.supportsPrinting) {
|
|
2621
|
-
// this.l10n.get("printing_not_supported").then(msg => {
|
|
2622
|
-
// this._otherError(msg);
|
|
2623
|
-
// });
|
|
2624
|
-
return;
|
|
2625
|
-
}
|
|
2626
|
-
// The beforePrint is a sync method and we need to know layout before
|
|
2627
|
-
// returning from this method. Ensure that we can get sizes of the pages.
|
|
2628
|
-
if (!this.viewer.pageViewsReady) {
|
|
2629
|
-
this.l10n.get("printing_not_ready", null).then((msg) => {
|
|
2630
|
-
// eslint-disable-next-line no-alert
|
|
2631
|
-
window.alert(msg);
|
|
2632
|
-
});
|
|
2633
|
-
return;
|
|
2634
|
-
}
|
|
2635
|
-
const pagesOverview = this.viewer.getPagesOverview();
|
|
2636
|
-
const printContainer = document.getElementById("printContainer");
|
|
2637
|
-
const printResolution = this.printResolution;
|
|
2638
|
-
const optionalContentConfigPromise = this.viewer.optionalContentConfigPromise;
|
|
2639
|
-
const printService = PDFPrintServiceFactory.instance.createPrintService(this.document, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, null, // this._printAnnotationStoragePromise,
|
|
2640
|
-
this.l10n);
|
|
2641
|
-
this.printService = printService;
|
|
2642
|
-
this.forceRendering();
|
|
2643
|
-
// Disable the editor-indicator during printing (fixes bug 1790552).
|
|
2644
|
-
// this.setTitle();
|
|
2645
|
-
printService.layout();
|
|
2646
|
-
// if (this._hasAnnotationEditors) {
|
|
2647
|
-
// this.externalServices.reportTelemetry({
|
|
2648
|
-
// type: "editing",
|
|
2649
|
-
// data: { type: "print" },
|
|
2650
|
-
// });
|
|
2651
|
-
// }
|
|
2652
|
-
}
|
|
2653
|
-
afterPrint() {
|
|
2654
|
-
// if (this._printAnnotationStoragePromise) {
|
|
2655
|
-
// this._printAnnotationStoragePromise.then(() => {
|
|
2656
|
-
// this.pdfScriptingManager.dispatchDidPrint();
|
|
2657
|
-
// });
|
|
2658
|
-
// this._printAnnotationStoragePromise = null;
|
|
2659
|
-
// }
|
|
2660
|
-
var _a;
|
|
2661
|
-
if (this.printService) {
|
|
2662
|
-
this.printService.destroy();
|
|
2663
|
-
this.printService = null;
|
|
2664
|
-
(_a = this.document) === null || _a === undefined ? undefined : _a.annotationStorage.resetModified();
|
|
2665
|
-
}
|
|
2666
|
-
this.forceRendering();
|
|
2667
|
-
// Re-enable the editor-indicator after printing (fixes bug 1790552).
|
|
2668
|
-
// this.setTitle();
|
|
2660
|
+
return __classPrivateFieldGet(this, _PDFSlick_printService, "f").supportsPrinting;
|
|
2669
2661
|
}
|
|
2670
2662
|
requestPresentationMode() {
|
|
2671
2663
|
var _a;
|
|
2672
|
-
(_a = this.pdfPresentationMode) === null || _a ===
|
|
2664
|
+
(_a = this.pdfPresentationMode) === null || _a === void 0 ? void 0 : _a.request();
|
|
2673
2665
|
}
|
|
2674
2666
|
triggerPrinting() {
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2667
|
+
__classPrivateFieldGet(this, _PDFSlick_printService, "f").print();
|
|
2668
|
+
}
|
|
2669
|
+
unbindEvents() {
|
|
2670
|
+
var _a;
|
|
2671
|
+
(_a = __classPrivateFieldGet(this, _PDFSlick_eventAbortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
|
2672
|
+
__classPrivateFieldSet(this, _PDFSlick_eventAbortController, null, "f");
|
|
2673
|
+
__classPrivateFieldGet(this, _PDFSlick_printService, "f").unbindEvents();
|
|
2679
2674
|
}
|
|
2680
2675
|
_cleanup() {
|
|
2681
2676
|
var _a;
|
|
@@ -2802,11 +2797,11 @@ class PDFSlick {
|
|
|
2802
2797
|
this.eventBus.dispatch(eventName, data);
|
|
2803
2798
|
}
|
|
2804
2799
|
}
|
|
2805
|
-
_PDFSlick_renderingQueue = new WeakMap(), _PDFSlick_container = new WeakMap(), _PDFSlick_viewerContainer = new WeakMap(), _PDFSlick_thumbsContainer = new WeakMap(), _PDFSlick_annotationMode = new WeakMap(), _PDFSlick_annotationEditorMode = new WeakMap(), _PDFSlick_onError = new WeakMap(), _PDFSlick_instances = new WeakSet(), _PDFSlick_initializePageLabels = function _PDFSlick_initializePageLabels() {
|
|
2806
|
-
return __awaiter(this,
|
|
2800
|
+
_PDFSlick_renderingQueue = new WeakMap(), _PDFSlick_container = new WeakMap(), _PDFSlick_viewerContainer = new WeakMap(), _PDFSlick_thumbsContainer = new WeakMap(), _PDFSlick_printService = new WeakMap(), _PDFSlick_annotationMode = new WeakMap(), _PDFSlick_annotationEditorMode = new WeakMap(), _PDFSlick_onError = new WeakMap(), _PDFSlick_eventAbortController = new WeakMap(), _PDFSlick_instances = new WeakSet(), _PDFSlick_initializePageLabels = function _PDFSlick_initializePageLabels() {
|
|
2801
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2807
2802
|
var _a;
|
|
2808
2803
|
const pdfDocument = this.document;
|
|
2809
|
-
const labels = (_a = (yield pdfDocument.getPageLabels())) !== null && _a !==
|
|
2804
|
+
const labels = (_a = (yield pdfDocument.getPageLabels())) !== null && _a !== void 0 ? _a : [];
|
|
2810
2805
|
const numLabels = labels.length;
|
|
2811
2806
|
// Ignore page labels that correspond to standard page numbering,
|
|
2812
2807
|
// or page labels that are all empty.
|
|
@@ -2828,10 +2823,10 @@ _PDFSlick_renderingQueue = new WeakMap(), _PDFSlick_container = new WeakMap(), _
|
|
|
2828
2823
|
}
|
|
2829
2824
|
const { viewer: pdfViewer, thumbnailViewer: pdfThumbnailViewer } = this;
|
|
2830
2825
|
pdfViewer.setPageLabels(labels);
|
|
2831
|
-
pdfThumbnailViewer === null || pdfThumbnailViewer ===
|
|
2826
|
+
pdfThumbnailViewer === null || pdfThumbnailViewer === void 0 ? void 0 : pdfThumbnailViewer.setPageLabels(labels);
|
|
2832
2827
|
});
|
|
2833
2828
|
}, _PDFSlick_parseDocumentInfo = function _PDFSlick_parseDocumentInfo() {
|
|
2834
|
-
return __awaiter(this,
|
|
2829
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2835
2830
|
const { info, contentLength } = (yield this.document.getMetadata());
|
|
2836
2831
|
const pageSize = yield this.document.getPage(this.store.getState().pageNumber).then((pdfPage) => {
|
|
2837
2832
|
return __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_parsePageSize).call(this, getPageSizeInches(pdfPage), 0);
|
|
@@ -2852,7 +2847,7 @@ _PDFSlick_renderingQueue = new WeakMap(), _PDFSlick_container = new WeakMap(), _
|
|
|
2852
2847
|
});
|
|
2853
2848
|
});
|
|
2854
2849
|
}, _PDFSlick_parsePageSize = function _PDFSlick_parsePageSize(pageSizeInches, pagesRotation) {
|
|
2855
|
-
return __awaiter(this,
|
|
2850
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2856
2851
|
if (!pageSizeInches) {
|
|
2857
2852
|
return undefined;
|
|
2858
2853
|
}
|
|
@@ -2920,25 +2915,20 @@ _PDFSlick_renderingQueue = new WeakMap(), _PDFSlick_container = new WeakMap(), _
|
|
|
2920
2915
|
};
|
|
2921
2916
|
});
|
|
2922
2917
|
}, _PDFSlick_initInternalEventListeners = function _PDFSlick_initInternalEventListeners() {
|
|
2923
|
-
this
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
this.eventBus._on("
|
|
2927
|
-
this.eventBus._on("
|
|
2928
|
-
this.eventBus._on("
|
|
2929
|
-
this.eventBus._on("
|
|
2930
|
-
this.eventBus._on("
|
|
2931
|
-
this.eventBus._on("
|
|
2932
|
-
|
|
2933
|
-
this.eventBus.dispatch("beforeprint", { source: window });
|
|
2934
|
-
};
|
|
2935
|
-
window.onafterprint = (e) => {
|
|
2936
|
-
this.eventBus.dispatch("afterprint", { source: window });
|
|
2937
|
-
};
|
|
2918
|
+
__classPrivateFieldSet(this, _PDFSlick_eventAbortController, new AbortController(), "f");
|
|
2919
|
+
const { signal } = __classPrivateFieldGet(this, _PDFSlick_eventAbortController, "f");
|
|
2920
|
+
const opts = { signal };
|
|
2921
|
+
this.eventBus._on("pagesinit", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onDocumentReady).bind(this), opts);
|
|
2922
|
+
this.eventBus._on("scalechanging", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onScaleChanging).bind(this), opts);
|
|
2923
|
+
this.eventBus._on("pagechanging", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onPageChanging).bind(this), opts);
|
|
2924
|
+
this.eventBus._on("pagerendered", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onPageRendered).bind(this), opts);
|
|
2925
|
+
this.eventBus._on("rotationchanging", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onRotationChanging).bind(this), opts);
|
|
2926
|
+
this.eventBus._on("switchspreadmode", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onSwitchSpreadMode).bind(this), opts);
|
|
2927
|
+
this.eventBus._on("switchscrollmode", __classPrivateFieldGet(this, _PDFSlick_instances, "m", _PDFSlick_onSwitchScrollMode).bind(this), opts);
|
|
2938
2928
|
}, _PDFSlick_onDocumentReady = function _PDFSlick_onDocumentReady(_a) {
|
|
2939
|
-
return __awaiter(this, arguments,
|
|
2929
|
+
return __awaiter(this, arguments, void 0, function* ({ source }) {
|
|
2940
2930
|
var _b;
|
|
2941
|
-
const documentOutline = (yield ((_b = this.document) === null || _b ===
|
|
2931
|
+
const documentOutline = (yield ((_b = this.document) === null || _b === void 0 ? void 0 : _b.getOutline()));
|
|
2942
2932
|
const scaleValue = this.store.getState().scaleValue;
|
|
2943
2933
|
// source._setScale(scaleValue, {}); // page-fit, page-actual, auto, page-width
|
|
2944
2934
|
source.currentScale = 1;
|
|
@@ -2967,18 +2957,18 @@ _PDFSlick_renderingQueue = new WeakMap(), _PDFSlick_container = new WeakMap(), _
|
|
|
2967
2957
|
this.viewer.update();
|
|
2968
2958
|
}, _PDFSlick_onPageChanging = function _PDFSlick_onPageChanging({ pageNumber }) {
|
|
2969
2959
|
var _a;
|
|
2970
|
-
(_a = this.thumbnailViewer) === null || _a ===
|
|
2960
|
+
(_a = this.thumbnailViewer) === null || _a === void 0 ? void 0 : _a.scrollThumbnailIntoView(pageNumber);
|
|
2971
2961
|
this.store.setState({ pageNumber });
|
|
2972
2962
|
}, _PDFSlick_onPageRendered = function _PDFSlick_onPageRendered({ pageNumber, error }) {
|
|
2973
2963
|
var _a;
|
|
2974
2964
|
// Use the rendered page to set the corresponding thumbnail image.
|
|
2975
2965
|
if (__classPrivateFieldGet(this, _PDFSlick_thumbsContainer, "f")) {
|
|
2976
2966
|
const pageView = this.viewer.getPageView(pageNumber - 1);
|
|
2977
|
-
const thumbnailView = (_a = this.thumbnailViewer) === null || _a ===
|
|
2967
|
+
const thumbnailView = (_a = this.thumbnailViewer) === null || _a === void 0 ? void 0 : _a.getThumbnail(pageNumber - 1);
|
|
2978
2968
|
if (pageView && thumbnailView) {
|
|
2979
2969
|
thumbnailView.setImage(pageView);
|
|
2980
2970
|
}
|
|
2981
2971
|
}
|
|
2982
2972
|
};
|
|
2983
2973
|
|
|
2984
|
-
export { AutoPrintRegExp, CursorTool, DEFAULT_SCALE, DEFAULT_SCALE_DELTA, DEFAULT_SCALE_VALUE, MAX_AUTO_SCALE, MAX_SCALE, MIN_SCALE, OutputScale, PDFSlick, PresentationModeState, ProgressBar, RendererType, RenderingStates, SCROLLBAR_PADDING, ScrollMode, SidebarView, SpreadMode, TextLayerMode, UNKNOWN_SCALE, VERTICAL_PADDING, animationStarted, apiPageLayoutToViewerModes, apiPageModeToSidebarView, approximateFraction, backtrackBeforeAllVisibleElements, binarySearchFirstItem, create, docStyle, getActiveOrFocusedElement, getPageSizeInches, getVisibleElements, initialState, isPortraitOrientation, isValidRotation, isValidScrollMode, isValidSpreadMode,
|
|
2974
|
+
export { AutoPrintRegExp, CursorTool, DEFAULT_SCALE, DEFAULT_SCALE_DELTA, DEFAULT_SCALE_VALUE, MAX_AUTO_SCALE, MAX_SCALE, MIN_SCALE, OutputScale, 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 };
|