1 | window.ngxZone.runOutsideAngular(() => {
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | (() => {
|
25 | "use strict";
|
26 | var __webpack_modules__ = ([
|
27 | ,
|
28 |
|
29 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
30 |
|
31 |
|
32 |
|
33 | Object.defineProperty(exports, "__esModule", ({
|
34 | value: true
|
35 | }));
|
36 | exports.GenericCom = void 0;
|
37 | var _app = __webpack_require__(2);
|
38 | var _preferences = __webpack_require__(47);
|
39 | var _download_manager = __webpack_require__(48);
|
40 | var _genericl10n = __webpack_require__(49);
|
41 | var _generic_scripting = __webpack_require__(51);
|
42 | ;
|
43 | const GenericCom = {};
|
44 | exports.GenericCom = GenericCom;
|
45 | class GenericPreferences extends _preferences.BasePreferences {
|
46 | async _writeToStorage(prefObj) {
|
47 | try {
|
48 | localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
|
49 | } catch (safariSecurityException) {}
|
50 | }
|
51 | async _readFromStorage(prefObj) {
|
52 | try {
|
53 | return JSON.parse(localStorage.getItem("pdfjs.preferences"));
|
54 | } catch (safariSecurityException) {
|
55 | return {};
|
56 | }
|
57 | }
|
58 | }
|
59 | class GenericExternalServices extends _app.DefaultExternalServices {
|
60 | static createDownloadManager() {
|
61 | return new _download_manager.DownloadManager();
|
62 | }
|
63 | static createPreferences() {
|
64 | return new GenericPreferences();
|
65 | }
|
66 | static createL10n({
|
67 | locale = "en-US"
|
68 | }) {
|
69 | return new _genericl10n.GenericL10n(locale);
|
70 | }
|
71 | static createScripting({
|
72 | sandboxBundleSrc
|
73 | }) {
|
74 | return new _generic_scripting.GenericScripting(sandboxBundleSrc);
|
75 | }
|
76 | }
|
77 | _app.PDFViewerApplication.externalServices = GenericExternalServices;
|
78 |
|
79 | }),
|
80 |
|
81 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
82 |
|
83 |
|
84 |
|
85 | Object.defineProperty(exports, "__esModule", ({
|
86 | value: true
|
87 | }));
|
88 | exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
|
89 | var _ui_utils = __webpack_require__(3);
|
90 | var _pdfjsLib = __webpack_require__(4);
|
91 | var _app_options = __webpack_require__(5);
|
92 | var _event_utils = __webpack_require__(6);
|
93 | var _pdf_link_service = __webpack_require__(7);
|
94 | var _webAnnotation_editor_params = __webpack_require__(8);
|
95 | var _overlay_manager = __webpack_require__(9);
|
96 | var _password_prompt = __webpack_require__(10);
|
97 | var _webPdf_attachment_viewer = __webpack_require__(11);
|
98 | var _webPdf_cursor_tools = __webpack_require__(13);
|
99 | var _webPdf_document_properties = __webpack_require__(15);
|
100 | var _webPdf_find_bar = __webpack_require__(16);
|
101 | var _pdf_find_controller = __webpack_require__(17);
|
102 | var _pdf_history = __webpack_require__(21);
|
103 | var _webPdf_layer_viewer = __webpack_require__(22);
|
104 | var _webPdf_outline_viewer = __webpack_require__(23);
|
105 | var _webPdf_presentation_mode = __webpack_require__(24);
|
106 | var _pdf_rendering_queue = __webpack_require__(25);
|
107 | var _pdf_scripting_manager = __webpack_require__(26);
|
108 | var _webPdf_sidebar = __webpack_require__(27);
|
109 | var _webPdf_sidebar_resizer = __webpack_require__(28);
|
110 | var _webPdf_thumbnail_viewer = __webpack_require__(29);
|
111 | var _pdf_viewer = __webpack_require__(31);
|
112 | var _webSecondary_toolbar = __webpack_require__(44);
|
113 | var _webToolbar = __webpack_require__(45);
|
114 | var _view_history = __webpack_require__(46);
|
115 | const FORCE_PAGES_LOADED_TIMEOUT = 10;
|
116 | const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
|
117 | const ViewOnLoad = {
|
118 | UNKNOWN: -1,
|
119 | PREVIOUS: 0,
|
120 | INITIAL: 1
|
121 | };
|
122 | const ViewerCssTheme = {
|
123 | AUTOMATIC: 0,
|
124 | LIGHT: 1,
|
125 | DARK: 2
|
126 | };
|
127 | class DefaultExternalServices {
|
128 | constructor() {
|
129 | throw new Error("Cannot initialize DefaultExternalServices.");
|
130 | }
|
131 | static updateFindControlState(data) {}
|
132 | static updateFindMatchesCount(data) {}
|
133 | static initPassiveLoading(callbacks) {}
|
134 | static reportTelemetry(data) {}
|
135 | static createDownloadManager() {
|
136 | throw new Error("Not implemented: createDownloadManager");
|
137 | }
|
138 | static createPreferences() {
|
139 | throw new Error("Not implemented: createPreferences");
|
140 | }
|
141 | static createL10n(options) {
|
142 | throw new Error("Not implemented: createL10n");
|
143 | }
|
144 | static createScripting(options) {
|
145 | throw new Error("Not implemented: createScripting");
|
146 | }
|
147 | static get supportsPinchToZoom() {
|
148 | return (0, _pdfjsLib.shadow)(this, "supportsPinchToZoom", true);
|
149 | }
|
150 | static get supportsIntegratedFind() {
|
151 | return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
|
152 | }
|
153 | static get supportsDocumentFonts() {
|
154 | return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
|
155 | }
|
156 | static get supportedMouseWheelZoomModifierKeys() {
|
157 | return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
|
158 | ctrlKey: true,
|
159 | metaKey: true
|
160 | });
|
161 | }
|
162 | static get isInAutomation() {
|
163 | return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
|
164 | }
|
165 | static updateEditorStates(data) {
|
166 | throw new Error("Not implemented: updateEditorStates");
|
167 | }
|
168 | }
|
169 | exports.DefaultExternalServices = DefaultExternalServices;
|
170 | const PDFViewerApplication = {
|
171 | initialBookmark: document.location.hash.substring(1),
|
172 | _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
|
173 | appConfig: null,
|
174 | pdfDocument: null,
|
175 | pdfLoadingTask: null,
|
176 | printService: null,
|
177 | pdfViewer: null,
|
178 | pdfThumbnailViewer: null,
|
179 | pdfRenderingQueue: null,
|
180 | pdfPresentationMode: null,
|
181 | pdfDocumentProperties: null,
|
182 | pdfLinkService: null,
|
183 | pdfHistory: null,
|
184 | pdfSidebar: null,
|
185 | pdfSidebarResizer: null,
|
186 | pdfOutlineViewer: null,
|
187 | pdfAttachmentViewer: null,
|
188 | pdfLayerViewer: null,
|
189 | pdfCursorTools: null,
|
190 | pdfScriptingManager: null,
|
191 | store: null,
|
192 | downloadManager: null,
|
193 | overlayManager: null,
|
194 | preferences: null,
|
195 | toolbar: null,
|
196 | secondaryToolbar: null,
|
197 | eventBus: null,
|
198 | l10n: null,
|
199 | annotationEditorParams: null,
|
200 | isInitialViewSet: false,
|
201 | downloadComplete: false,
|
202 | isViewerEmbedded: window.parent !== window,
|
203 | url: "",
|
204 | baseUrl: "",
|
205 | _downloadUrl: "",
|
206 | externalServices: DefaultExternalServices,
|
207 | _boundEvents: Object.create(null),
|
208 | documentInfo: null,
|
209 | metadata: null,
|
210 | _contentDispositionFilename: null,
|
211 | _contentLength: null,
|
212 | _saveInProgress: false,
|
213 | _wheelUnusedTicks: 0,
|
214 | _wheelUnusedFactor: 1,
|
215 | _touchUnusedTicks: 0,
|
216 | _touchUnusedFactor: 1,
|
217 | _PDFBug: null,
|
218 | _hasAnnotationEditors: false,
|
219 | _title: document.title,
|
220 | _printAnnotationStoragePromise: null,
|
221 | _touchInfo: null,
|
222 | _isCtrlKeyDown: false,
|
223 | async initialize(appConfig) {
|
224 | this.preferences = this.externalServices.createPreferences();
|
225 | this.appConfig = appConfig;
|
226 | await this._initializeOptions();
|
227 | this._forceCssTheme();
|
228 | await this._initializeL10n();
|
229 | if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdf_link_service.LinkTarget.NONE) {
|
230 | _app_options.AppOptions.set("externalLinkTarget", _pdf_link_service.LinkTarget.TOP);
|
231 | }
|
232 | await this._initializeViewerComponents();
|
233 | this.bindEvents();
|
234 | this.bindWindowEvents();
|
235 | const appContainer = appConfig.appContainer || document.documentElement;
|
236 | this.l10n.translate(appContainer).then(() => {
|
237 | this.eventBus.dispatch("localized", {
|
238 | source: this
|
239 | });
|
240 | });
|
241 | this._initializedCapability.resolve();
|
242 | this.initializeLoadingBar();
|
243 | },
|
244 | async _initializeOptions() {
|
245 | if (_app_options.AppOptions.get("disablePreferences")) {
|
246 | if (_app_options.AppOptions.get("pdfBugEnabled")) {
|
247 | await this._parseHashParams();
|
248 | }
|
249 | return;
|
250 | }
|
251 | if (_app_options.AppOptions._hasUserOptions()) {
|
252 | Window['ngxConsole'].warn("_initializeOptions: The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option in order to prevent that.');
|
253 | }
|
254 | try {
|
255 | _app_options.AppOptions.setAll(await this.preferences.getAll());
|
256 | } catch (reason) {
|
257 | Window['ngxConsole'].error(`_initializeOptions: "${reason?.message}".`);
|
258 | }
|
259 | if (_app_options.AppOptions.get("pdfBugEnabled")) {
|
260 | await this._parseHashParams();
|
261 | }
|
262 | },
|
263 | async _parseHashParams() {
|
264 | const hash = document.location.hash.substring(1);
|
265 | if (!hash) {
|
266 | return;
|
267 | }
|
268 | const {
|
269 | mainContainer,
|
270 | viewerContainer
|
271 | } = this.appConfig,
|
272 | params = (0, _ui_utils.parseQueryString)(hash);
|
273 | if (params.get("disableworker") === "true") {
|
274 | try {
|
275 | await loadFakeWorker();
|
276 | } catch (ex) {
|
277 | console.error(`_parseHashParams: "${ex.message}".`);
|
278 | }
|
279 | }
|
280 | if (params.has("disablerange")) {
|
281 | _app_options.AppOptions.set("disableRange", params.get("disablerange") === "true");
|
282 | }
|
283 | if (params.has("disablestream")) {
|
284 | _app_options.AppOptions.set("disableStream", params.get("disablestream") === "true");
|
285 | }
|
286 | if (params.has("disableautofetch")) {
|
287 | _app_options.AppOptions.set("disableAutoFetch", params.get("disableautofetch") === "true");
|
288 | }
|
289 | if (params.has("disablefontface")) {
|
290 | _app_options.AppOptions.set("disableFontFace", params.get("disablefontface") === "true");
|
291 | }
|
292 | if (params.has("disablehistory")) {
|
293 | _app_options.AppOptions.set("disableHistory", params.get("disablehistory") === "true");
|
294 | }
|
295 | if (params.has("verbosity")) {
|
296 | _app_options.AppOptions.set("verbosity", params.get("verbosity") | 0);
|
297 | }
|
298 | if (params.has("textlayer")) {
|
299 | switch (params.get("textlayer")) {
|
300 | case "off":
|
301 | _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
|
302 | break;
|
303 | case "visible":
|
304 | case "shadow":
|
305 | case "hover":
|
306 | viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`);
|
307 | try {
|
308 | await loadPDFBug(this);
|
309 | this._PDFBug.loadCSS();
|
310 | } catch (ex) {
|
311 | console.error(`_parseHashParams: "${ex.message}".`);
|
312 | }
|
313 | break;
|
314 | }
|
315 | }
|
316 | if (params.has("pdfbug")) {
|
317 | _app_options.AppOptions.set("pdfBug", true);
|
318 | _app_options.AppOptions.set("fontExtraProperties", true);
|
319 | const enabled = params.get("pdfbug").split(",");
|
320 | try {
|
321 | await loadPDFBug(this);
|
322 | this._PDFBug.init({
|
323 | OPS: _pdfjsLib.OPS
|
324 | }, mainContainer, enabled);
|
325 | } catch (ex) {
|
326 | console.error(`_parseHashParams: "${ex.message}".`);
|
327 | }
|
328 | }
|
329 | if (params.has("locale")) {
|
330 | _app_options.AppOptions.set("locale", params.get("locale"));
|
331 | }
|
332 | },
|
333 | async _initializeL10n() {
|
334 | this.l10n = this.externalServices.createL10n({
|
335 | locale: _app_options.AppOptions.get("locale")
|
336 | });
|
337 | const dir = await this.l10n.getDirection();
|
338 | document.getElementsByTagName("html")[0].dir = dir;
|
339 | },
|
340 | _forceCssTheme() {
|
341 | const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
|
342 | if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
|
343 | return;
|
344 | }
|
345 | try {
|
346 | const styleSheet = document.styleSheets[0];
|
347 | const cssRules = styleSheet?.cssRules || [];
|
348 | for (let i = 0, ii = cssRules.length; i < ii; i++) {
|
349 | const rule = cssRules[i];
|
350 | if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
|
351 | if (cssTheme === ViewerCssTheme.LIGHT) {
|
352 | styleSheet.deleteRule(i);
|
353 | return;
|
354 | }
|
355 | const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
|
356 | if (darkRules?.[1]) {
|
357 | styleSheet.deleteRule(i);
|
358 | styleSheet.insertRule(darkRules[1], i);
|
359 | }
|
360 | return;
|
361 | }
|
362 | }
|
363 | } catch (reason) {
|
364 | Window['ngxConsole'].error(`_forceCssTheme: "${reason?.message}".`);
|
365 | }
|
366 | },
|
367 | async _initializeViewerComponents() {
|
368 | const {
|
369 | appConfig,
|
370 | externalServices
|
371 | } = this;
|
372 | const eventBus = externalServices.isInAutomation ? new _event_utils.AutomationEventBus() : new _event_utils.EventBus();
|
373 | this.eventBus = eventBus;
|
374 | this.overlayManager = new _overlay_manager.OverlayManager();
|
375 | const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
|
376 | pdfRenderingQueue.onIdle = this._cleanup.bind(this);
|
377 | this.pdfRenderingQueue = pdfRenderingQueue;
|
378 | const pdfLinkService = new _pdf_link_service.PDFLinkService({
|
379 | eventBus,
|
380 | externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
|
381 | externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
|
382 | ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
|
383 | });
|
384 | this.pdfLinkService = pdfLinkService;
|
385 | const downloadManager = externalServices.createDownloadManager();
|
386 | this.downloadManager = downloadManager;
|
387 | const findController = new _pdf_find_controller.PDFFindController({
|
388 | linkService: pdfLinkService,
|
389 | eventBus,
|
390 | pageViewMode: _app_options.AppOptions.get("pageViewMode"),
|
391 | updateMatchesCountOnProgress: true
|
392 | });
|
393 | this.findController = findController;
|
394 | const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
|
395 | eventBus,
|
396 | sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
|
397 | scriptingFactory: externalServices,
|
398 | docPropertiesLookup: this._scriptingDocProperties.bind(this)
|
399 | });
|
400 | this.pdfScriptingManager = pdfScriptingManager;
|
401 | const container = appConfig.mainContainer,
|
402 | viewer = appConfig.viewerContainer;
|
403 | const annotationEditorMode = _app_options.AppOptions.get("annotationEditorMode");
|
404 | const pageColors = _app_options.AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? {
|
405 | background: _app_options.AppOptions.get("pageColorsBackground"),
|
406 | foreground: _app_options.AppOptions.get("pageColorsForeground")
|
407 | } : null;
|
408 | this.pdfViewer = new _pdf_viewer.PDFViewer({
|
409 | container,
|
410 | viewer,
|
411 | eventBus,
|
412 | renderingQueue: pdfRenderingQueue,
|
413 | linkService: pdfLinkService,
|
414 | downloadManager,
|
415 | findController,
|
416 | scriptingManager: _app_options.AppOptions.get("enableScripting") && pdfScriptingManager,
|
417 | renderer: _app_options.AppOptions.get("renderer"),
|
418 | l10n: this.l10n,
|
419 | textLayerMode: _app_options.AppOptions.get("textLayerMode"),
|
420 | annotationMode: _app_options.AppOptions.get("annotationMode"),
|
421 | annotationEditorMode,
|
422 | imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
|
423 | removePageBorders: _app_options.AppOptions.get("removePageBorders"),
|
424 | enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
|
425 | useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
|
426 | isOffscreenCanvasSupported: _app_options.AppOptions.get("isOffscreenCanvasSupported"),
|
427 | maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
|
428 | pageViewMode: _app_options.AppOptions.get("pageViewMode"),
|
429 | enablePermissions: _app_options.AppOptions.get("enablePermissions"),
|
430 | pageColors
|
431 | });
|
432 | pdfRenderingQueue.setViewer(this.pdfViewer);
|
433 | pdfLinkService.setViewer(this.pdfViewer);
|
434 | pdfScriptingManager.setViewer(this.pdfViewer);
|
435 | if (appConfig.sidebar?.thumbnailView) {
|
436 | this.pdfThumbnailViewer = new _webPdf_thumbnail_viewer.PDFThumbnailViewer({
|
437 | container: appConfig.sidebar.thumbnailView,
|
438 | renderingQueue: pdfRenderingQueue,
|
439 | linkService: pdfLinkService,
|
440 | l10n: this.l10n,
|
441 | pageColors
|
442 | });
|
443 | pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
444 | }
|
445 | if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
|
446 | this.pdfHistory = new _pdf_history.PDFHistory({
|
447 | linkService: pdfLinkService,
|
448 | eventBus
|
449 | });
|
450 | pdfLinkService.setHistory(this.pdfHistory);
|
451 | }
|
452 | if (!this.supportsIntegratedFind && appConfig.findBar) {
|
453 | this.findBar = new _webPdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
|
454 | }
|
455 | if (appConfig.annotationEditorParams) {
|
456 | if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
|
457 | this.annotationEditorParams = new _webAnnotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
|
458 | } else {
|
459 | for (const id of ["editorModeButtons", "editorModeSeparator"]) {
|
460 | document.getElementById(id)?.classList.add("hidden");
|
461 | }
|
462 | }
|
463 | }
|
464 | if (appConfig.documentProperties) {
|
465 | this.pdfDocumentProperties = new _webPdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
|
466 | return this._docFilename;
|
467 | });
|
468 | }
|
469 | if (appConfig.secondaryToolbar?.cursorHandToolButton) {
|
470 | this.pdfCursorTools = new _webPdf_cursor_tools.PDFCursorTools({
|
471 | container,
|
472 | eventBus,
|
473 | cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
|
474 | });
|
475 | }
|
476 | if (appConfig.toolbar) {
|
477 | this.toolbar = new _webToolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
|
478 | }
|
479 | if (appConfig.secondaryToolbar) {
|
480 | this.secondaryToolbar = new _webSecondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices);
|
481 | }
|
482 | if (this.supportsFullscreen && appConfig.secondaryToolbar?.presentationModeButton) {
|
483 | this.pdfPresentationMode = new _webPdf_presentation_mode.PDFPresentationMode({
|
484 | container,
|
485 | pdfViewer: this.pdfViewer,
|
486 | eventBus
|
487 | });
|
488 | }
|
489 | let prompt = _app_options.AppOptions.get("passwordPrompt");
|
490 | if (!prompt) {
|
491 | if (appConfig.passwordOverlay) {
|
492 | prompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
|
493 | }
|
494 | }
|
495 | this.passwordPrompt = prompt;
|
496 | if (appConfig.sidebar?.outlineView) {
|
497 | this.pdfOutlineViewer = new _webPdf_outline_viewer.PDFOutlineViewer({
|
498 | container: appConfig.sidebar.outlineView,
|
499 | eventBus,
|
500 | linkService: pdfLinkService,
|
501 | downloadManager
|
502 | });
|
503 | }
|
504 | if (appConfig.sidebar?.attachmentsView) {
|
505 | this.pdfAttachmentViewer = new _webPdf_attachment_viewer.PDFAttachmentViewer({
|
506 | container: appConfig.sidebar.attachmentsView,
|
507 | eventBus,
|
508 | downloadManager
|
509 | });
|
510 | }
|
511 | if (appConfig.sidebar?.layersView) {
|
512 | this.pdfLayerViewer = new _webPdf_layer_viewer.PDFLayerViewer({
|
513 | container: appConfig.sidebar.layersView,
|
514 | eventBus,
|
515 | l10n: this.l10n
|
516 | });
|
517 | }
|
518 | if (appConfig.sidebar) {
|
519 | this.pdfSidebar = new _webPdf_sidebar.PDFSidebar({
|
520 | elements: appConfig.sidebar,
|
521 | pdfViewer: this.pdfViewer,
|
522 | pdfThumbnailViewer: this.pdfThumbnailViewer,
|
523 | eventBus,
|
524 | l10n: this.l10n
|
525 | });
|
526 | this.pdfSidebar.onToggled = this.forceRendering.bind(this);
|
527 | this.pdfSidebarResizer = new _webPdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
|
528 | }
|
529 | },
|
530 | run(config) {
|
531 | this.initialize(config).then(webViewerInitialized);
|
532 | },
|
533 | get initialized() {
|
534 | return this._initializedCapability.settled;
|
535 | },
|
536 | get initializedPromise() {
|
537 | return this._initializedCapability.promise;
|
538 | },
|
539 | zoomIn(steps, scaleFactor) {
|
540 | if (this.pdfViewer.isInPresentationMode) {
|
541 | return;
|
542 | }
|
543 | this.pdfViewer.increaseScale({
|
544 | drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
|
545 | steps,
|
546 | scaleFactor
|
547 | });
|
548 | },
|
549 | zoomOut(steps, scaleFactor) {
|
550 | if (this.pdfViewer.isInPresentationMode) {
|
551 | return;
|
552 | }
|
553 | this.pdfViewer.decreaseScale({
|
554 | drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
|
555 | steps,
|
556 | scaleFactor
|
557 | });
|
558 | },
|
559 | zoomReset() {
|
560 | if (this.pdfViewer.isInPresentationMode) {
|
561 | return;
|
562 | }
|
563 | this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
564 | },
|
565 | get pagesCount() {
|
566 | return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
567 | },
|
568 | get page() {
|
569 | return this.pdfViewer.currentPageNumber;
|
570 | },
|
571 | set page(val) {
|
572 | this.pdfViewer.currentPageNumber = val;
|
573 | },
|
574 | get supportsPrinting() {
|
575 | return PDFPrintServiceFactory.instance.supportsPrinting;
|
576 | },
|
577 | get supportsFullscreen() {
|
578 | return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", document.fullscreenEnabled);
|
579 | },
|
580 | get supportsPinchToZoom() {
|
581 | return this.externalServices.supportsPinchToZoom;
|
582 | },
|
583 | get supportsIntegratedFind() {
|
584 | return this.externalServices.supportsIntegratedFind;
|
585 | },
|
586 | get supportsDocumentFonts() {
|
587 | return this.externalServices.supportsDocumentFonts;
|
588 | },
|
589 | initializeLoadingBar() {
|
590 | const barElement = document.getElementById("loadingBar");
|
591 | const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null;
|
592 | bar.hide();
|
593 | return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
|
594 | },
|
595 | get supportedMouseWheelZoomModifierKeys() {
|
596 | return this.externalServices.supportedMouseWheelZoomModifierKeys;
|
597 | },
|
598 | initPassiveLoading() {
|
599 | throw new Error("Not implemented: initPassiveLoading");
|
600 | },
|
601 | setTitleUsingUrl(url = "", downloadUrl = null) {},
|
602 | setTitle(title = this._title) {
|
603 | this._title = title;
|
604 | if (this.isViewerEmbedded) {
|
605 | return;
|
606 | }
|
607 | const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
|
608 | document.title = `${editorIndicator ? "* " : ""}${title}`;
|
609 | },
|
610 | get _docFilename() {
|
611 | return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
|
612 | },
|
613 | _hideViewBookmark() {
|
614 | const {
|
615 | secondaryToolbar
|
616 | } = this.appConfig;
|
617 | secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
|
618 | if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
|
619 | document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
|
620 | }
|
621 | },
|
622 | async close() {
|
623 | this._unblockDocumentLoadEvent();
|
624 | this._hideViewBookmark();
|
625 | if (!this.pdfLoadingTask) {
|
626 | return;
|
627 | }
|
628 | if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
|
629 | try {
|
630 | await this.save();
|
631 | } catch (reason) {}
|
632 | }
|
633 | const promises = [];
|
634 | promises.push(this.pdfLoadingTask.destroy());
|
635 | this.pdfLoadingTask = null;
|
636 | if (this.pdfDocument) {
|
637 | this.pdfDocument = null;
|
638 | this.pdfThumbnailViewer?.setDocument(null);
|
639 | this.pdfViewer.setDocument(null);
|
640 | this.pdfLinkService.setDocument(null);
|
641 | this.pdfDocumentProperties?.setDocument(null);
|
642 | }
|
643 | this.pdfLinkService.externalLinkEnabled = true;
|
644 | this.store = null;
|
645 | this.isInitialViewSet = false;
|
646 | this.downloadComplete = false;
|
647 | this.url = "";
|
648 | this.baseUrl = "";
|
649 | this._downloadUrl = "";
|
650 | this.documentInfo = null;
|
651 | this.metadata = null;
|
652 | this._contentDispositionFilename = null;
|
653 | this._contentLength = null;
|
654 | this._saveInProgress = false;
|
655 | this._hasAnnotationEditors = false;
|
656 | promises.push(this.pdfScriptingManager.destroyPromise);
|
657 | this.setTitle();
|
658 | this.pdfSidebar?.reset();
|
659 | this.pdfOutlineViewer?.reset();
|
660 | this.pdfAttachmentViewer?.reset();
|
661 | this.pdfLayerViewer?.reset();
|
662 | this.pdfHistory?.reset();
|
663 | this.findBar?.reset();
|
664 | this.toolbar?.reset();
|
665 | this.secondaryToolbar?.reset();
|
666 | this._PDFBug?.cleanup();
|
667 | await Promise.all(promises);
|
668 | },
|
669 | async open(args) {
|
670 | window.adjacentPagesLoader = undefined;
|
671 | window.ngxZone.runOutsideAngular(async () => {
|
672 | let deprecatedArgs = false;
|
673 | if (typeof args === "string") {
|
674 | args = {
|
675 | url: args
|
676 | };
|
677 | deprecatedArgs = true;
|
678 | } else if (args?.byteLength) {
|
679 | args = {
|
680 | data: args
|
681 | };
|
682 | deprecatedArgs = true;
|
683 | }
|
684 | if (deprecatedArgs) {
|
685 | console.error("The `PDFViewerApplication.open` signature was updated, please use an object instead.");
|
686 | }
|
687 | if (this.pdfLoadingTask) {
|
688 | await this.close();
|
689 | }
|
690 | const workerParams = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
|
691 | Object.assign(_pdfjsLib.GlobalWorkerOptions, workerParams);
|
692 | if (args.url) {
|
693 | this.setTitleUsingUrl(args.originalUrl || args.url, args.url);
|
694 | }
|
695 | const apiParams = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
|
696 | const params = {
|
697 | ...apiParams,
|
698 | ...args
|
699 | };
|
700 | const loadingTask = (0, _pdfjsLib.getDocument)(params);
|
701 | this.pdfLoadingTask = loadingTask;
|
702 | loadingTask.onPassword = (updateCallback, reason) => {
|
703 | if (this.isViewerEmbedded) {
|
704 | this._unblockDocumentLoadEvent();
|
705 | }
|
706 | this.pdfLinkService.externalLinkEnabled = false;
|
707 | this.passwordPrompt.setUpdateCallback(updateCallback, reason);
|
708 | this.passwordPrompt.open();
|
709 | };
|
710 | loadingTask.onProgress = ({
|
711 | loaded,
|
712 | total
|
713 | }) => {
|
714 | this.progress(loaded / total);
|
715 | this.eventBus?.dispatch("progress", {
|
716 | source: this,
|
717 | type: "load",
|
718 | total,
|
719 | loaded,
|
720 | percent: 100 * loaded / total
|
721 | });
|
722 | };
|
723 | return loadingTask.promise.then(pdfDocument => {
|
724 | this.load(pdfDocument);
|
725 | }, reason => {
|
726 | if (loadingTask !== this.pdfLoadingTask) {
|
727 | return undefined;
|
728 | }
|
729 | let key = "loading_error";
|
730 | if (reason instanceof _pdfjsLib.InvalidPDFException) {
|
731 | key = "invalid_file_error";
|
732 | } else if (reason instanceof _pdfjsLib.MissingPDFException) {
|
733 | key = "missing_file_error";
|
734 | } else if (reason instanceof _pdfjsLib.UnexpectedResponseException) {
|
735 | key = "unexpected_response_error";
|
736 | }
|
737 | if (PDFViewerApplication.onError) {
|
738 | PDFViewerApplication.onError(reason);
|
739 | }
|
740 | return this.l10n.get(key).then(msg => {
|
741 | this._documentError(msg, {
|
742 | message: reason?.message
|
743 | });
|
744 | throw reason;
|
745 | });
|
746 | });
|
747 | });
|
748 | },
|
749 | _ensureDownloadComplete() {
|
750 | if (this.pdfDocument && this.downloadComplete) {
|
751 | return;
|
752 | }
|
753 | throw new Error("PDF document not downloaded.");
|
754 | },
|
755 | async download() {
|
756 | const url = this._downloadUrl,
|
757 | filename = this._docFilename;
|
758 | try {
|
759 | this._ensureDownloadComplete();
|
760 | const data = await this.pdfDocument.getData();
|
761 | const blob = new Blob([data], {
|
762 | type: "application/pdf"
|
763 | });
|
764 | await this.downloadManager.download(blob, url, filename);
|
765 | } catch (reason) {
|
766 | await this.downloadManager.downloadUrl(url, filename);
|
767 | }
|
768 | },
|
769 | async save() {
|
770 | if (this._saveInProgress) {
|
771 | return;
|
772 | }
|
773 | this._saveInProgress = true;
|
774 | await this.pdfScriptingManager.dispatchWillSave();
|
775 | const url = this._downloadUrl,
|
776 | filename = this._docFilename;
|
777 | try {
|
778 | this._ensureDownloadComplete();
|
779 | const data = await this.pdfDocument.saveDocument();
|
780 | const blob = new Blob([data], {
|
781 | type: "application/pdf"
|
782 | });
|
783 | await this.downloadManager.download(blob, url, filename);
|
784 | } catch (reason) {
|
785 | Window["ngxConsole"].error(`Error when saving the document: ${reason.message}`);
|
786 | await this.download();
|
787 | } finally {
|
788 | await this.pdfScriptingManager.dispatchDidSave();
|
789 | this._saveInProgress = false;
|
790 | }
|
791 | if (this._hasAnnotationEditors) {
|
792 | this.externalServices.reportTelemetry({
|
793 | type: "editing",
|
794 | data: {
|
795 | type: "save"
|
796 | }
|
797 | });
|
798 | }
|
799 | },
|
800 | downloadOrSave() {
|
801 | if (this.pdfDocument?.annotationStorage.size > 0) {
|
802 | this.save();
|
803 | } else {
|
804 | this.download();
|
805 | }
|
806 | },
|
807 | _documentError(message, moreInfo = null) {
|
808 | this._unblockDocumentLoadEvent();
|
809 | this._otherError(message, moreInfo);
|
810 | this.eventBus.dispatch("documenterror", {
|
811 | source: this,
|
812 | message,
|
813 | reason: moreInfo?.message ?? null
|
814 | });
|
815 | },
|
816 | _otherError(message, moreInfo = null) {
|
817 | const moreInfoText = [`PDF.js v${_pdfjsLib.version || "?"} (build: ${_pdfjsLib.build || "?"})`];
|
818 | if (moreInfo) {
|
819 | moreInfoText.push(`Message: ${moreInfo.message}`);
|
820 | if (moreInfo.stack) {
|
821 | moreInfoText.push(`Stack: ${moreInfo.stack}`);
|
822 | } else {
|
823 | if (moreInfo.filename) {
|
824 | moreInfoText.push(`File: ${moreInfo.filename}`);
|
825 | }
|
826 | if (moreInfo.lineNumber) {
|
827 | moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
|
828 | }
|
829 | }
|
830 | }
|
831 | console.error(`${message}\n\n${moreInfoText.join("\n")}`);
|
832 | },
|
833 | progress(level) {
|
834 | if (!this.loadingBar || this.downloadComplete) {
|
835 | return;
|
836 | }
|
837 | const percent = Math.round(level * 100);
|
838 | if (percent <= this.loadingBar.percent) {
|
839 | return;
|
840 | }
|
841 | this.loadingBar.percent = percent;
|
842 | if (this.pdfDocument?.loadingParams.disableAutoFetch ?? _app_options.AppOptions.get("disableAutoFetch")) {
|
843 | this.loadingBar.setDisableAutoFetch();
|
844 | }
|
845 | },
|
846 | load(pdfDocument) {
|
847 | this.pdfDocument = pdfDocument;
|
848 | pdfDocument.getDownloadInfo().then(({
|
849 | length
|
850 | }) => {
|
851 | this._contentLength = length;
|
852 | this.downloadComplete = true;
|
853 | this.loadingBar?.hide();
|
854 | firstPagePromise.then(() => {
|
855 | this.eventBus?.dispatch("documentloaded", {
|
856 | source: this
|
857 | });
|
858 | });
|
859 | });
|
860 | const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
|
861 | const pageModePromise = pdfDocument.getPageMode().catch(function () {});
|
862 | const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
|
863 | this.toolbar?.setPagesCount(pdfDocument.numPages, false);
|
864 | this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
|
865 | let baseDocumentUrl;
|
866 | baseDocumentUrl = null;
|
867 | if (baseDocumentUrl && (0, _pdfjsLib.isDataScheme)(baseDocumentUrl)) {
|
868 | baseDocumentUrl = null;
|
869 | }
|
870 | this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
871 | this.pdfDocumentProperties?.setDocument(pdfDocument);
|
872 | const pdfViewer = this.pdfViewer;
|
873 | pdfViewer.setDocument(pdfDocument);
|
874 | const {
|
875 | firstPagePromise,
|
876 | onePageRendered,
|
877 | pagesPromise
|
878 | } = pdfViewer;
|
879 | this.pdfThumbnailViewer?.setDocument(pdfDocument);
|
880 | const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
|
881 | page: null,
|
882 | zoom: _ui_utils.DEFAULT_SCALE_VALUE,
|
883 | scrollLeft: "0",
|
884 | scrollTop: "0",
|
885 | rotation: null,
|
886 | sidebarView: _ui_utils.SidebarView.UNKNOWN,
|
887 | scrollMode: _ui_utils.ScrollMode.UNKNOWN,
|
888 | spreadMode: _ui_utils.SpreadMode.UNKNOWN
|
889 | }).catch(() => {
|
890 | return Object.create(null);
|
891 | });
|
892 | firstPagePromise.then(pdfPage => {
|
893 | this.loadingBar?.setWidth(this.appConfig.viewerContainer);
|
894 | this._initializeAnnotationStorageCallbacks(pdfDocument);
|
895 | Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
|
896 | const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
|
897 | this._initializePdfHistory({
|
898 | fingerprint: pdfDocument.fingerprints[0],
|
899 | viewOnLoad,
|
900 | initialDest: openAction?.dest
|
901 | });
|
902 | const initialBookmark = this.initialBookmark;
|
903 | const zoom = _app_options.AppOptions.get("defaultZoomValue");
|
904 | let hash = zoom ? `zoom=${zoom}` : null;
|
905 | let rotation = null;
|
906 | let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
|
907 | let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
|
908 | let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
|
909 | if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
|
910 | hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
|
911 | rotation = parseInt(stored.rotation, 10);
|
912 | if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
|
913 | sidebarView = stored.sidebarView | 0;
|
914 | }
|
915 | if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
|
916 | scrollMode = stored.scrollMode | 0;
|
917 | }
|
918 | if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
|
919 | spreadMode = stored.spreadMode | 0;
|
920 | }
|
921 | }
|
922 | if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
|
923 | sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
|
924 | }
|
925 | if (pageLayout && scrollMode === _ui_utils.ScrollMode.UNKNOWN && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
|
926 | const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(pageLayout);
|
927 | spreadMode = modes.spreadMode;
|
928 | }
|
929 | this.setInitialView(hash, {
|
930 | rotation,
|
931 | sidebarView,
|
932 | scrollMode,
|
933 | spreadMode
|
934 | });
|
935 | this.eventBus.dispatch("documentinit", {
|
936 | source: this
|
937 | });
|
938 | if (!this.isViewerEmbedded) {
|
939 | pdfViewer.focus();
|
940 | }
|
941 | await Promise.race([pagesPromise, new Promise(resolve => {
|
942 | setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
|
943 | })]);
|
944 | if (!initialBookmark && !hash) {
|
945 | return;
|
946 | }
|
947 | if (pdfViewer.hasEqualPageSizes) {
|
948 | return;
|
949 | }
|
950 | this.initialBookmark = initialBookmark;
|
951 | pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
|
952 | this.setInitialView(hash);
|
953 | }).catch(() => {
|
954 | this.setInitialView();
|
955 | }).then(function () {
|
956 | pdfViewer.update();
|
957 | });
|
958 | });
|
959 | pagesPromise.then(() => {
|
960 | this._unblockDocumentLoadEvent();
|
961 | this._initializeAutoPrint(pdfDocument, openActionPromise);
|
962 | }, reason => {
|
963 | if (PDFViewerApplication.onError) {
|
964 | PDFViewerApplication.onError(reason);
|
965 | }
|
966 | this.l10n.get("loading_error").then(msg => {
|
967 | this._documentError(msg, {
|
968 | message: reason?.message
|
969 | });
|
970 | });
|
971 | });
|
972 | onePageRendered.then(data => {
|
973 | this.externalServices.reportTelemetry({
|
974 | type: "pageInfo",
|
975 | timestamp: data.timestamp
|
976 | });
|
977 | if (this.pdfOutlineViewer) {
|
978 | pdfDocument.getOutline().then(outline => {
|
979 | if (pdfDocument !== this.pdfDocument) {
|
980 | return;
|
981 | }
|
982 | this.pdfOutlineViewer.render({
|
983 | outline,
|
984 | pdfDocument
|
985 | });
|
986 | });
|
987 | }
|
988 | if (this.pdfAttachmentViewer) {
|
989 | pdfDocument.getAttachments().then(attachments => {
|
990 | if (pdfDocument !== this.pdfDocument) {
|
991 | return;
|
992 | }
|
993 | this.pdfAttachmentViewer.render({
|
994 | attachments
|
995 | });
|
996 | });
|
997 | }
|
998 | if (this.pdfLayerViewer) {
|
999 | pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
|
1000 | if (pdfDocument !== this.pdfDocument) {
|
1001 | return;
|
1002 | }
|
1003 | this.pdfLayerViewer.render({
|
1004 | optionalContentConfig,
|
1005 | pdfDocument
|
1006 | });
|
1007 | });
|
1008 | }
|
1009 | });
|
1010 | this._initializePageLabels(pdfDocument);
|
1011 | this._initializeMetadata(pdfDocument);
|
1012 | },
|
1013 | async _scriptingDocProperties(pdfDocument) {
|
1014 | if (!this.documentInfo) {
|
1015 | await new Promise(resolve => {
|
1016 | this.eventBus._on("metadataloaded", resolve, {
|
1017 | once: true
|
1018 | });
|
1019 | });
|
1020 | if (pdfDocument !== this.pdfDocument) {
|
1021 | return null;
|
1022 | }
|
1023 | }
|
1024 | if (!this._contentLength) {
|
1025 | await new Promise(resolve => {
|
1026 | this.eventBus._on("documentloaded", resolve, {
|
1027 | once: true
|
1028 | });
|
1029 | });
|
1030 | if (pdfDocument !== this.pdfDocument) {
|
1031 | return null;
|
1032 | }
|
1033 | }
|
1034 | return {
|
1035 | ...this.documentInfo,
|
1036 | baseURL: this.baseUrl,
|
1037 | filesize: this._contentLength,
|
1038 | filename: this._docFilename,
|
1039 | metadata: this.metadata?.getRaw(),
|
1040 | authors: this.metadata?.get("dc:creator"),
|
1041 | numPages: this.pagesCount,
|
1042 | URL: this.url
|
1043 | };
|
1044 | },
|
1045 | async _initializeAutoPrint(pdfDocument, openActionPromise) {
|
1046 | const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
|
1047 | if (pdfDocument !== this.pdfDocument) {
|
1048 | return;
|
1049 | }
|
1050 | let triggerAutoPrint = false;
|
1051 | if (openAction?.action === "Print") {
|
1052 | triggerAutoPrint = true;
|
1053 | }
|
1054 | if (javaScript) {
|
1055 | javaScript.some(js => {
|
1056 | if (!js) {
|
1057 | return false;
|
1058 | }
|
1059 | Window['ngxConsole'].warn("Warning: JavaScript support is not enabled");
|
1060 | return true;
|
1061 | });
|
1062 | if (!triggerAutoPrint) {
|
1063 | for (const js of javaScript) {
|
1064 | if (js && _ui_utils.AutoPrintRegExp.test(js)) {
|
1065 | triggerAutoPrint = true;
|
1066 | break;
|
1067 | }
|
1068 | }
|
1069 | }
|
1070 | }
|
1071 | if (triggerAutoPrint) {
|
1072 | this.triggerPrinting();
|
1073 | }
|
1074 | },
|
1075 | async _initializeMetadata(pdfDocument) {
|
1076 | const {
|
1077 | info,
|
1078 | metadata,
|
1079 | contentDispositionFilename,
|
1080 | contentLength
|
1081 | } = await pdfDocument.getMetadata();
|
1082 | if (pdfDocument !== this.pdfDocument) {
|
1083 | return;
|
1084 | }
|
1085 | this.documentInfo = info;
|
1086 | this.metadata = metadata;
|
1087 | this._contentDispositionFilename ??= contentDispositionFilename;
|
1088 | this._contentLength ??= contentLength;
|
1089 | console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}]) modified by ngx-extended-pdf-viewer`);
|
1090 | let pdfTitle = info.Title;
|
1091 | const metadataTitle = metadata?.get("dc:title");
|
1092 | if (metadataTitle) {
|
1093 | if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
|
1094 | pdfTitle = metadataTitle;
|
1095 | }
|
1096 | }
|
1097 | if (pdfTitle) {
|
1098 | this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`);
|
1099 | } else if (this._contentDispositionFilename) {
|
1100 | this.setTitle(this._contentDispositionFilename);
|
1101 | }
|
1102 | if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
|
1103 | if (pdfDocument.loadingParams.enableXfa) {
|
1104 | Window['ngxConsole'].warn("Warning: XFA Foreground documents are not supported");
|
1105 | } else {
|
1106 | Window['ngxConsole'].warn("Warning: XFA support is not enabled");
|
1107 | }
|
1108 | } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
|
1109 | console.warn("Warning: Interactive form support is not enabled");
|
1110 | }
|
1111 | if (info.IsSignaturesPresent) {
|
1112 | console.warn("Warning: Digital signatures validation is not supported");
|
1113 | }
|
1114 | this.eventBus.dispatch("metadataloaded", {
|
1115 | source: this
|
1116 | });
|
1117 | },
|
1118 | async _initializePageLabels(pdfDocument) {
|
1119 | const labels = await pdfDocument.getPageLabels();
|
1120 | if (pdfDocument !== this.pdfDocument) {
|
1121 | return;
|
1122 | }
|
1123 | if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
|
1124 | return;
|
1125 | }
|
1126 | const numLabels = labels.length;
|
1127 | let standardLabels = 0,
|
1128 | emptyLabels = 0;
|
1129 | for (let i = 0; i < numLabels; i++) {
|
1130 | const label = labels[i];
|
1131 | if (label === (i + 1).toString()) {
|
1132 | standardLabels++;
|
1133 | } else if (label === "") {
|
1134 | emptyLabels++;
|
1135 | } else {
|
1136 | break;
|
1137 | }
|
1138 | }
|
1139 | if (standardLabels >= numLabels || emptyLabels >= numLabels) {
|
1140 | return;
|
1141 | }
|
1142 | const {
|
1143 | pdfViewer,
|
1144 | pdfThumbnailViewer,
|
1145 | toolbar
|
1146 | } = this;
|
1147 | pdfViewer.setPageLabels(labels);
|
1148 | pdfThumbnailViewer?.setPageLabels(labels);
|
1149 | toolbar?.setPagesCount(numLabels, true);
|
1150 | toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
1151 | },
|
1152 | _initializePdfHistory({
|
1153 | fingerprint,
|
1154 | viewOnLoad,
|
1155 | initialDest = null
|
1156 | }) {
|
1157 | if (!this.pdfHistory) {
|
1158 | return;
|
1159 | }
|
1160 | this.pdfHistory.initialize({
|
1161 | fingerprint,
|
1162 | resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
|
1163 | updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
|
1164 | });
|
1165 | if (this.pdfHistory.initialBookmark) {
|
1166 | this.initialBookmark = this.pdfHistory.initialBookmark;
|
1167 | this.initialRotation = this.pdfHistory.initialRotation;
|
1168 | }
|
1169 | if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
|
1170 | this.initialBookmark = JSON.stringify(initialDest);
|
1171 | this.pdfHistory.push({
|
1172 | explicitDest: initialDest,
|
1173 | pageNumber: null
|
1174 | });
|
1175 | }
|
1176 | },
|
1177 | _initializeAnnotationStorageCallbacks(pdfDocument) {
|
1178 | if (pdfDocument !== this.pdfDocument) {
|
1179 | return;
|
1180 | }
|
1181 | const {
|
1182 | annotationStorage
|
1183 | } = pdfDocument;
|
1184 | annotationStorage.onSetModified = () => {
|
1185 | window.addEventListener("beforeunload", beforeUnload);
|
1186 | this._annotationStorageModified = true;
|
1187 | };
|
1188 | annotationStorage.onResetModified = () => {
|
1189 | window.removeEventListener("beforeunload", beforeUnload);
|
1190 | delete this._annotationStorageModified;
|
1191 | };
|
1192 | annotationStorage.onAnnotationEditor = typeStr => {
|
1193 | this._hasAnnotationEditors = !!typeStr;
|
1194 | this.setTitle();
|
1195 | if (typeStr) {
|
1196 | this.externalServices.reportTelemetry({
|
1197 | type: "editing",
|
1198 | data: {
|
1199 | type: typeStr
|
1200 | }
|
1201 | });
|
1202 | }
|
1203 | };
|
1204 | },
|
1205 | setInitialView(storedHash, {
|
1206 | rotation,
|
1207 | sidebarView,
|
1208 | scrollMode,
|
1209 | spreadMode
|
1210 | } = {}) {
|
1211 | const setRotation = angle => {
|
1212 | if ((0, _ui_utils.isValidRotation)(angle)) {
|
1213 | this.pdfViewer.pagesRotation = angle;
|
1214 | }
|
1215 | };
|
1216 | const setViewerModes = (scroll, spread) => {
|
1217 | if ((0, _ui_utils.isValidScrollMode)(scroll)) {
|
1218 | this.pdfViewer.scrollMode = scroll;
|
1219 | }
|
1220 | if ((0, _ui_utils.isValidSpreadMode)(spread)) {
|
1221 | this.pdfViewer.spreadMode = spread;
|
1222 | }
|
1223 | };
|
1224 | this.isInitialViewSet = true;
|
1225 | this.pdfSidebar?.setInitialView(sidebarView);
|
1226 | setViewerModes(scrollMode, spreadMode);
|
1227 | if (this.initialBookmark) {
|
1228 | setRotation(this.initialRotation);
|
1229 | delete this.initialRotation;
|
1230 | this.pdfLinkService.setHash(this.initialBookmark);
|
1231 | this.initialBookmark = null;
|
1232 | } else if (storedHash) {
|
1233 | setRotation(rotation);
|
1234 | this.pdfLinkService.setHash(storedHash);
|
1235 | }
|
1236 | this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
|
1237 | this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
|
1238 | if (!this.pdfViewer.currentScaleValue) {
|
1239 | const defaultZoomOption = PDFViewerApplicationOptions.get('defaultZoomValue');
|
1240 | if (defaultZoomOption) {
|
1241 | this.pdfViewer.currentScaleValue = defaultZoomOption;
|
1242 | }
|
1243 | }
|
1244 | },
|
1245 | _cleanup() {
|
1246 | if (!this.pdfDocument) {
|
1247 | return;
|
1248 | }
|
1249 | this.pdfViewer.cleanup();
|
1250 | this.pdfThumbnailViewer?.cleanup();
|
1251 | this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
|
1252 | },
|
1253 | forceRendering() {
|
1254 | this.pdfRenderingQueue.printing = !!this.printService;
|
1255 | this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS;
|
1256 | this.pdfRenderingQueue.renderHighestPriority();
|
1257 | },
|
1258 | beforePrint() {
|
1259 | this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => {
|
1260 | return this.pdfDocument?.annotationStorage.print;
|
1261 | });
|
1262 | if (this.printService) {
|
1263 | return;
|
1264 | }
|
1265 | if (!this.supportsPrinting) {
|
1266 | this.l10n.get("printing_not_supported").then(msg => {
|
1267 | this._otherError(msg);
|
1268 | });
|
1269 | return;
|
1270 | }
|
1271 | if (!this.pdfViewer.pageViewsReady) {
|
1272 | this.l10n.get("printing_not_ready").then(msg => {
|
1273 | window.alert(msg);
|
1274 | });
|
1275 | return;
|
1276 | }
|
1277 | const pagesOverview = this.pdfViewer.getPagesOverview();
|
1278 | const printContainer = this.appConfig.printContainer;
|
1279 | const printResolution = _app_options.AppOptions.get("printResolution");
|
1280 | const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
|
1281 | const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this._printAnnotationStoragePromise, this.l10n, this.pdfViewer.eventBus);
|
1282 | this.printService = printService;
|
1283 | this.forceRendering();
|
1284 | this.setTitle();
|
1285 | printService.layout();
|
1286 | if (this._hasAnnotationEditors) {
|
1287 | this.externalServices.reportTelemetry({
|
1288 | type: "editing",
|
1289 | data: {
|
1290 | type: "print"
|
1291 | }
|
1292 | });
|
1293 | }
|
1294 | },
|
1295 | afterPrint() {
|
1296 | if (this._printAnnotationStoragePromise) {
|
1297 | this._printAnnotationStoragePromise.then(() => {
|
1298 | this.pdfScriptingManager.dispatchDidPrint();
|
1299 | });
|
1300 | this._printAnnotationStoragePromise = null;
|
1301 | }
|
1302 | if (this.printService) {
|
1303 | this.printService.destroy();
|
1304 | this.printService = null;
|
1305 | this.pdfDocument?.annotationStorage.resetModified();
|
1306 | }
|
1307 | this.forceRendering();
|
1308 | this.setTitle();
|
1309 | },
|
1310 | rotatePages(delta) {
|
1311 | this.pdfViewer.pagesRotation += delta;
|
1312 | },
|
1313 | requestPresentationMode() {
|
1314 | this.pdfPresentationMode?.request();
|
1315 | },
|
1316 | triggerPrinting() {
|
1317 | if (!this.supportsPrinting) {
|
1318 | return;
|
1319 | }
|
1320 | window.printPDF();
|
1321 | },
|
1322 | bindEvents() {
|
1323 | const {
|
1324 | eventBus,
|
1325 | _boundEvents
|
1326 | } = this;
|
1327 | _boundEvents.beforePrint = this.beforePrint.bind(this);
|
1328 | _boundEvents.afterPrint = this.afterPrint.bind(this);
|
1329 | eventBus._on("resize", webViewerResize);
|
1330 | eventBus._on("hashchange", webViewerHashchange);
|
1331 | eventBus._on("beforeprint", _boundEvents.beforePrint);
|
1332 | eventBus._on("afterprint", _boundEvents.afterPrint);
|
1333 | eventBus._on("pagerender", webViewerPageRender);
|
1334 | eventBus._on("pagerendered", webViewerPageRendered);
|
1335 | eventBus._on("updateviewarea", webViewerUpdateViewarea);
|
1336 | eventBus._on("pagechanging", webViewerPageChanging);
|
1337 | eventBus._on("scalechanging", webViewerScaleChanging);
|
1338 | eventBus._on("rotationchanging", webViewerRotationChanging);
|
1339 | eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
|
1340 | eventBus._on("pagemode", webViewerPageMode);
|
1341 | eventBus._on("namedaction", webViewerNamedAction);
|
1342 | eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
|
1343 | eventBus._on("presentationmode", webViewerPresentationMode);
|
1344 | eventBus._on("switchannotationeditormode", webViewerSwitchAnnotationEditorMode);
|
1345 | eventBus._on("switchannotationeditorparams", webViewerSwitchAnnotationEditorParams);
|
1346 | eventBus._on("print", webViewerPrint);
|
1347 | eventBus._on("download", webViewerDownload);
|
1348 | eventBus._on("firstpage", webViewerFirstPage);
|
1349 | eventBus._on("lastpage", webViewerLastPage);
|
1350 | eventBus._on("nextpage", webViewerNextPage);
|
1351 | eventBus._on("previouspage", webViewerPreviousPage);
|
1352 | eventBus._on("zoomin", webViewerZoomIn);
|
1353 | eventBus._on("zoomout", webViewerZoomOut);
|
1354 | eventBus._on("zoomreset", webViewerZoomReset);
|
1355 | eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
|
1356 | eventBus._on("scalechanged", webViewerScaleChanged);
|
1357 | eventBus._on("rotatecw", webViewerRotateCw);
|
1358 | eventBus._on("rotateccw", webViewerRotateCcw);
|
1359 | eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
|
1360 | eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
|
1361 | eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
|
1362 | eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
|
1363 | eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
|
1364 | eventBus._on("documentproperties", webViewerDocumentProperties);
|
1365 | eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
|
1366 | eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
|
1367 | eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
|
1368 | if (_app_options.AppOptions.get("pdfBug")) {
|
1369 | _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
|
1370 | eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
|
1371 | eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
|
1372 | }
|
1373 | eventBus._on("fileinputchange", webViewerFileInputChange);
|
1374 | eventBus._on("openfile", webViewerOpenFile);
|
1375 | },
|
1376 | bindWindowEvents() {
|
1377 | const {
|
1378 | eventBus,
|
1379 | _boundEvents
|
1380 | } = this;
|
1381 | function addWindowResolutionChange(evt = null) {
|
1382 | if (evt) {
|
1383 | webViewerResolutionChange(evt);
|
1384 | }
|
1385 | const mediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
|
1386 | mediaQueryList.addEventListener("change", addWindowResolutionChange, {
|
1387 | once: true
|
1388 | });
|
1389 | _boundEvents.removeWindowResolutionChange ||= function () {
|
1390 | mediaQueryList.removeEventListener("change", addWindowResolutionChange);
|
1391 | _boundEvents.removeWindowResolutionChange = null;
|
1392 | };
|
1393 | }
|
1394 | addWindowResolutionChange();
|
1395 | _boundEvents.windowResize = () => {
|
1396 | eventBus.dispatch("resize", {
|
1397 | source: window
|
1398 | });
|
1399 | };
|
1400 | _boundEvents.windowHashChange = () => {
|
1401 | eventBus.dispatch("hashchange", {
|
1402 | source: window,
|
1403 | hash: document.location.hash.substring(1)
|
1404 | });
|
1405 | };
|
1406 | _boundEvents.windowBeforePrint = () => {
|
1407 | eventBus.dispatch("beforeprint", {
|
1408 | source: window
|
1409 | });
|
1410 | };
|
1411 | _boundEvents.windowAfterPrint = () => {
|
1412 | eventBus.dispatch("afterprint", {
|
1413 | source: window
|
1414 | });
|
1415 | };
|
1416 | _boundEvents.windowUpdateFromSandbox = event => {
|
1417 | eventBus.dispatch("updatefromsandbox", {
|
1418 | source: window,
|
1419 | detail: event.detail
|
1420 | });
|
1421 | };
|
1422 | window.addEventListener("visibilitychange", webViewerVisibilityChange);
|
1423 | window.addEventListener("wheel", webViewerWheel, {
|
1424 | passive: false
|
1425 | });
|
1426 | window.addEventListener("touchstart", webViewerTouchStart, {
|
1427 | passive: false
|
1428 | });
|
1429 | window.addEventListener("touchmove", webViewerTouchMove, {
|
1430 | passive: false
|
1431 | });
|
1432 | window.addEventListener("touchend", webViewerTouchEnd, {
|
1433 | passive: false
|
1434 | });
|
1435 | window.addEventListener("click", webViewerClick);
|
1436 | window.addEventListener("keydown", webViewerKeyDown);
|
1437 | window.addEventListener("keyup", webViewerKeyUp);
|
1438 | window.addEventListener("resize", _boundEvents.windowResize);
|
1439 | window.addEventListener("hashchange", _boundEvents.windowHashChange);
|
1440 | window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
1441 | window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
|
1442 | window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
|
1443 | },
|
1444 | unbindEvents() {
|
1445 | const {
|
1446 | eventBus,
|
1447 | _boundEvents
|
1448 | } = this;
|
1449 | eventBus._off("resize", webViewerResize);
|
1450 | eventBus._off("hashchange", webViewerHashchange);
|
1451 | eventBus._off("beforeprint", _boundEvents.beforePrint);
|
1452 | eventBus._off("afterprint", _boundEvents.afterPrint);
|
1453 | eventBus._off("pagerender", webViewerPageRender);
|
1454 | eventBus._off("pagerendered", webViewerPageRendered);
|
1455 | eventBus._off("updateviewarea", webViewerUpdateViewarea);
|
1456 | eventBus._off("pagechanging", webViewerPageChanging);
|
1457 | eventBus._off("scalechanging", webViewerScaleChanging);
|
1458 | eventBus._off("rotationchanging", webViewerRotationChanging);
|
1459 | eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
|
1460 | eventBus._off("pagemode", webViewerPageMode);
|
1461 | eventBus._off("namedaction", webViewerNamedAction);
|
1462 | eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
|
1463 | eventBus._off("presentationmode", webViewerPresentationMode);
|
1464 | eventBus._off("print", webViewerPrint);
|
1465 | eventBus._off("download", webViewerDownload);
|
1466 | eventBus._off("firstpage", webViewerFirstPage);
|
1467 | eventBus._off("lastpage", webViewerLastPage);
|
1468 | eventBus._off("nextpage", webViewerNextPage);
|
1469 | eventBus._off("previouspage", webViewerPreviousPage);
|
1470 | eventBus._off("zoomin", webViewerZoomIn);
|
1471 | eventBus._off("zoomout", webViewerZoomOut);
|
1472 | eventBus._off("zoomreset", webViewerZoomReset);
|
1473 | eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
|
1474 | eventBus._off("scalechanged", webViewerScaleChanged);
|
1475 | eventBus._off("rotatecw", webViewerRotateCw);
|
1476 | eventBus._off("rotateccw", webViewerRotateCcw);
|
1477 | eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
|
1478 | eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
|
1479 | eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
|
1480 | eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
|
1481 | eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
|
1482 | eventBus._off("documentproperties", webViewerDocumentProperties);
|
1483 | eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
|
1484 | eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
|
1485 | eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
|
1486 | if (_boundEvents.reportPageStatsPDFBug) {
|
1487 | eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
|
1488 | eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
|
1489 | _boundEvents.reportPageStatsPDFBug = null;
|
1490 | }
|
1491 | eventBus._off("fileinputchange", webViewerFileInputChange);
|
1492 | eventBus._off("openfile", webViewerOpenFile);
|
1493 | _boundEvents.beforePrint = null;
|
1494 | _boundEvents.afterPrint = null;
|
1495 | },
|
1496 | unbindWindowEvents() {
|
1497 | const {
|
1498 | _boundEvents
|
1499 | } = this;
|
1500 | window.removeEventListener("visibilitychange", webViewerVisibilityChange);
|
1501 | window.removeEventListener("wheel", webViewerWheel, {
|
1502 | passive: false
|
1503 | });
|
1504 | window.removeEventListener("touchstart", webViewerTouchStart, {
|
1505 | passive: false
|
1506 | });
|
1507 | window.removeEventListener("touchmove", webViewerTouchMove, {
|
1508 | passive: false
|
1509 | });
|
1510 | window.removeEventListener("touchend", webViewerTouchEnd, {
|
1511 | passive: false
|
1512 | });
|
1513 | window.removeEventListener("click", webViewerClick);
|
1514 | window.removeEventListener("keydown", webViewerKeyDown);
|
1515 | window.removeEventListener("keyup", webViewerKeyUp);
|
1516 | window.removeEventListener("resize", _boundEvents.windowResize);
|
1517 | window.removeEventListener("hashchange", _boundEvents.windowHashChange);
|
1518 | window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
|
1519 | window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
|
1520 | window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
|
1521 | _boundEvents.removeWindowResolutionChange?.();
|
1522 | _boundEvents.windowResize = null;
|
1523 | _boundEvents.windowHashChange = null;
|
1524 | _boundEvents.windowBeforePrint = null;
|
1525 | _boundEvents.windowAfterPrint = null;
|
1526 | _boundEvents.windowUpdateFromSandbox = null;
|
1527 | },
|
1528 | _accumulateTicks(ticks, prop) {
|
1529 | if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) {
|
1530 | this[prop] = 0;
|
1531 | }
|
1532 | this[prop] += ticks;
|
1533 | const wholeTicks = Math.trunc(this[prop]);
|
1534 | this[prop] -= wholeTicks;
|
1535 | return wholeTicks;
|
1536 | },
|
1537 | _accumulateFactor(previousScale, factor, prop) {
|
1538 | if (factor === 1) {
|
1539 | return 1;
|
1540 | }
|
1541 | if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) {
|
1542 | this[prop] = 1;
|
1543 | }
|
1544 | const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale);
|
1545 | this[prop] = factor / newFactor;
|
1546 | return newFactor;
|
1547 | },
|
1548 | _centerAtPos(previousScale, x, y) {
|
1549 | const {
|
1550 | pdfViewer
|
1551 | } = this;
|
1552 | const scaleDiff = pdfViewer.currentScale / previousScale - 1;
|
1553 | if (scaleDiff !== 0) {
|
1554 | const [top, left] = pdfViewer.containerTopLeft;
|
1555 | pdfViewer.container.scrollLeft += (x - left) * scaleDiff;
|
1556 | pdfViewer.container.scrollTop += (y - top) * scaleDiff;
|
1557 | }
|
1558 | },
|
1559 | _unblockDocumentLoadEvent() {
|
1560 | document.blockUnblockOnload?.(false);
|
1561 | this._unblockDocumentLoadEvent = () => {};
|
1562 | },
|
1563 | get scriptingReady() {
|
1564 | return this.pdfScriptingManager.ready;
|
1565 | }
|
1566 | };
|
1567 | exports.PDFViewerApplication = PDFViewerApplication;
|
1568 | {
|
1569 | const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
|
1570 | var validateFileURL = function (file) {
|
1571 | if (!file) {
|
1572 | return;
|
1573 | }
|
1574 | try {
|
1575 | const viewerOrigin = new URL(window.location.href).origin || "null";
|
1576 | if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
|
1577 | return;
|
1578 | }
|
1579 | const fileOrigin = new URL(file, window.location.href).origin;
|
1580 | if (fileOrigin !== viewerOrigin) {
|
1581 | throw new Error("file origin does not match viewer's");
|
1582 | }
|
1583 | } catch (ex) {
|
1584 | if (PDFViewerApplication.onError) {
|
1585 | PDFViewerApplication.onError(ex);
|
1586 | }
|
1587 | PDFViewerApplication.l10n.get("loading_error").then(msg => {
|
1588 | PDFViewerApplication._documentError(msg, {
|
1589 | message: ex?.message
|
1590 | });
|
1591 | });
|
1592 | throw ex;
|
1593 | }
|
1594 | };
|
1595 | }
|
1596 | async function loadFakeWorker() {
|
1597 | _pdfjsLib.GlobalWorkerOptions.workerSrc ||= _app_options.AppOptions.get("workerSrc");
|
1598 | if (_pdfjsLib.GlobalWorkerOptions.workerSrc.constructor.name === "Function") {
|
1599 | _pdfjsLib.GlobalWorkerOptions.workerSrc = _pdfjsLib.GlobalWorkerOptions.workerSrc();
|
1600 | }
|
1601 | await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
|
1602 | }
|
1603 | async function loadPDFBug(self) {
|
1604 | const {
|
1605 | debuggerScriptPath
|
1606 | } = self.appConfig;
|
1607 | const {
|
1608 | PDFBug
|
1609 | } = await import(debuggerScriptPath);
|
1610 | self._PDFBug = PDFBug;
|
1611 | }
|
1612 | function reportPageStatsPDFBug({
|
1613 | pageNumber
|
1614 | }) {
|
1615 | if (!globalThis.Stats?.enabled) {
|
1616 | return;
|
1617 | }
|
1618 | const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
|
1619 | globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
|
1620 | }
|
1621 | function webViewerInitialized() {
|
1622 | const {
|
1623 | appConfig,
|
1624 | eventBus,
|
1625 | l10n
|
1626 | } = PDFViewerApplication;
|
1627 | let file;
|
1628 | const queryString = document.location.search.substring(1);
|
1629 | const params = (0, _ui_utils.parseQueryString)(queryString);
|
1630 | file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
|
1631 | validateFileURL(file);
|
1632 | const fileInput = appConfig.openFileInput;
|
1633 | fileInput.value = null;
|
1634 | fileInput.addEventListener("change", function (evt) {
|
1635 | const {
|
1636 | files
|
1637 | } = evt.target;
|
1638 | if (!files || files.length === 0) {
|
1639 | return;
|
1640 | }
|
1641 | eventBus.dispatch("fileinputchange", {
|
1642 | source: this,
|
1643 | fileInput: evt.target
|
1644 | });
|
1645 | });
|
1646 | appConfig.mainContainer.addEventListener("dragover", function (evt) {
|
1647 | if (_app_options.AppOptions.get("enableDragAndDrop")) {
|
1648 | evt.preventDefault();
|
1649 | evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
|
1650 | }
|
1651 | });
|
1652 | appConfig.mainContainer.addEventListener("drop", function (evt) {
|
1653 | if (_app_options.AppOptions.get("enableDragAndDrop")) {
|
1654 | evt.preventDefault();
|
1655 | const {
|
1656 | files
|
1657 | } = evt.dataTransfer;
|
1658 | if (!files || files.length === 0) {
|
1659 | return;
|
1660 | }
|
1661 | PDFViewerApplication.eventBus.dispatch("fileinputchange", {
|
1662 | source: this,
|
1663 | fileInput: evt.dataTransfer,
|
1664 | dropEvent: evt
|
1665 | });
|
1666 | }
|
1667 | });
|
1668 | if (!PDFViewerApplication.supportsDocumentFonts) {
|
1669 | _app_options.AppOptions.set("disableFontFace", true);
|
1670 | l10n.get("web_fonts_disabled").then(msg => {
|
1671 | Window['ngxConsole'].warn(msg);
|
1672 | });
|
1673 | }
|
1674 | if (!PDFViewerApplication.supportsPrinting) {
|
1675 | appConfig.toolbar?.print.classList.add("hidden");
|
1676 | appConfig.secondaryToolbar?.printButton.classList.add("hidden");
|
1677 | }
|
1678 | if (!PDFViewerApplication.supportsFullscreen) {
|
1679 | appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
|
1680 | }
|
1681 | if (PDFViewerApplication.supportsIntegratedFind) {
|
1682 | appConfig.toolbar?.viewFind.classList.add("hidden");
|
1683 | }
|
1684 | appConfig.mainContainer.addEventListener("transitionend", function (evt) {
|
1685 | if (evt.target === this) {
|
1686 | eventBus.dispatch("resize", {
|
1687 | source: this
|
1688 | });
|
1689 | }
|
1690 | }, true);
|
1691 | try {
|
1692 | if (file) {
|
1693 | PDFViewerApplication.open({
|
1694 | url: file
|
1695 | });
|
1696 | } else {
|
1697 | PDFViewerApplication._hideViewBookmark();
|
1698 | }
|
1699 | } catch (reason) {
|
1700 | if (PDFViewerApplication.onError) {
|
1701 | PDFViewerApplication.onError(reason);
|
1702 | }
|
1703 | l10n.get("loading_error").then(msg => {
|
1704 | PDFViewerApplication._documentError(msg, reason);
|
1705 | });
|
1706 | }
|
1707 | }
|
1708 | function webViewerPageRender({
|
1709 | pageNumber
|
1710 | }) {
|
1711 | if (pageNumber === PDFViewerApplication.page) {
|
1712 | PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
|
1713 | }
|
1714 | }
|
1715 | function webViewerPageRendered({
|
1716 | pageNumber,
|
1717 | error
|
1718 | }) {
|
1719 | if (pageNumber === PDFViewerApplication.page) {
|
1720 | PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
|
1721 | }
|
1722 | if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
|
1723 | const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
|
1724 | const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
|
1725 | if (pageView && thumbnailView) {
|
1726 | thumbnailView.setImage(pageView);
|
1727 | }
|
1728 | }
|
1729 | if (error) {
|
1730 | PDFViewerApplication.l10n.get("rendering_error").then(msg => {
|
1731 | PDFViewerApplication._otherError(msg, error);
|
1732 | });
|
1733 | }
|
1734 | }
|
1735 | function webViewerPageMode({
|
1736 | mode
|
1737 | }) {
|
1738 | let view;
|
1739 | switch (mode) {
|
1740 | case "thumbs":
|
1741 | view = _ui_utils.SidebarView.THUMBS;
|
1742 | break;
|
1743 | case "bookmarks":
|
1744 | case "outline":
|
1745 | view = _ui_utils.SidebarView.OUTLINE;
|
1746 | break;
|
1747 | case "attachments":
|
1748 | view = _ui_utils.SidebarView.ATTACHMENTS;
|
1749 | break;
|
1750 | case "layers":
|
1751 | view = _ui_utils.SidebarView.LAYERS;
|
1752 | break;
|
1753 | case "none":
|
1754 | view = _ui_utils.SidebarView.NONE;
|
1755 | break;
|
1756 | default:
|
1757 | Window['ngxConsole'].error('Invalid "pagemode" hash parameter: ' + mode);
|
1758 | return;
|
1759 | }
|
1760 | PDFViewerApplication.pdfSidebar?.switchView(view, true);
|
1761 | }
|
1762 | function webViewerNamedAction(evt) {
|
1763 | switch (evt.action) {
|
1764 | case "GoToPage":
|
1765 | PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
|
1766 | break;
|
1767 | case "Find":
|
1768 | if (!PDFViewerApplication.supportsIntegratedFind) {
|
1769 | PDFViewerApplication?.findBar.toggle();
|
1770 | }
|
1771 | break;
|
1772 | case "Print":
|
1773 | PDFViewerApplication.triggerPrinting();
|
1774 | break;
|
1775 | case "SaveAs":
|
1776 | PDFViewerApplication.downloadOrSave();
|
1777 | break;
|
1778 | }
|
1779 | }
|
1780 | function webViewerPresentationModeChanged(evt) {
|
1781 | PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
|
1782 | }
|
1783 | function webViewerSidebarViewChanged({
|
1784 | view
|
1785 | }) {
|
1786 | PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = view === _ui_utils.SidebarView.THUMBS;
|
1787 | if (PDFViewerApplication.isInitialViewSet) {
|
1788 | PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
|
1789 | }
|
1790 | }
|
1791 | function webViewerUpdateViewarea({
|
1792 | location
|
1793 | }) {
|
1794 | if (PDFViewerApplication.isInitialViewSet) {
|
1795 | const settings = {};
|
1796 | if (location.pageNumber !== undefined || location.pageNumber !== null) {
|
1797 | settings.page = location.pageNumber;
|
1798 | }
|
1799 | if (location.scale) {
|
1800 | settings.zoom = location.scale;
|
1801 | }
|
1802 | if (location.left) {
|
1803 | settings.scrollLeft = location.left;
|
1804 | }
|
1805 | if (location.top) {
|
1806 | settings.scrollTop = location.top;
|
1807 | }
|
1808 | if (location.rotation !== undefined || location.rotation !== null) {
|
1809 | settings.rotation = location.rotation;
|
1810 | }
|
1811 | PDFViewerApplication.store?.setMultiple(settings).catch(() => {});
|
1812 | }
|
1813 | if (PDFViewerApplication.appConfig.secondaryToolbar) {
|
1814 | const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
|
1815 | PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
|
1816 | }
|
1817 | }
|
1818 | function webViewerScrollModeChanged(evt) {
|
1819 | if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
|
1820 | PDFViewerApplication.store?.set("scrollMode", evt.mode).catch(() => {});
|
1821 | }
|
1822 | }
|
1823 | function webViewerSpreadModeChanged(evt) {
|
1824 | if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
|
1825 | PDFViewerApplication.store?.set("spreadMode", evt.mode).catch(() => {});
|
1826 | }
|
1827 | }
|
1828 | function webViewerResize() {
|
1829 | const {
|
1830 | pdfDocument,
|
1831 | pdfViewer,
|
1832 | pdfRenderingQueue
|
1833 | } = PDFViewerApplication;
|
1834 | if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
|
1835 | return;
|
1836 | }
|
1837 | if (!pdfDocument) {
|
1838 | return;
|
1839 | }
|
1840 | const currentScaleValue = pdfViewer.currentScaleValue;
|
1841 | if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
|
1842 | pdfViewer.currentScaleValue = currentScaleValue;
|
1843 | }
|
1844 | pdfViewer.update();
|
1845 | }
|
1846 | function webViewerHashchange(evt) {
|
1847 | const hash = evt.hash;
|
1848 | if (!hash) {
|
1849 | return;
|
1850 | }
|
1851 | if (!PDFViewerApplication.isInitialViewSet) {
|
1852 | PDFViewerApplication.initialBookmark = hash;
|
1853 | } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
|
1854 | PDFViewerApplication.pdfLinkService.setHash(hash);
|
1855 | }
|
1856 | }
|
1857 | {
|
1858 | var webViewerFileInputChange = function (evt) {
|
1859 | if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
|
1860 | return;
|
1861 | }
|
1862 | const file = evt.fileInput.files[0];
|
1863 | PDFViewerApplication.open({
|
1864 | url: URL.createObjectURL(file),
|
1865 | originalUrl: file.name
|
1866 | });
|
1867 | if (window["setNgxExtendedPdfViewerSource"]) {
|
1868 | window["setNgxExtendedPdfViewerSource"](file.name ? file.name : URL.createObjectURL(file));
|
1869 | }
|
1870 | };
|
1871 | var webViewerOpenFile = function (evt) {
|
1872 | const fileInput = PDFViewerApplication.appConfig.openFileInput;
|
1873 | fileInput.click();
|
1874 | };
|
1875 | }
|
1876 | function webViewerPresentationMode() {
|
1877 | PDFViewerApplication.requestPresentationMode();
|
1878 | }
|
1879 | function webViewerSwitchAnnotationEditorMode(evt) {
|
1880 | PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
|
1881 | }
|
1882 | function webViewerSwitchAnnotationEditorParams(evt) {
|
1883 | PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
|
1884 | }
|
1885 | function webViewerPrint() {
|
1886 | PDFViewerApplication.triggerPrinting();
|
1887 | }
|
1888 | function webViewerDownload() {
|
1889 | PDFViewerApplication.downloadOrSave();
|
1890 | }
|
1891 | function webViewerFirstPage() {
|
1892 | PDFViewerApplication.page = 1;
|
1893 | }
|
1894 | function webViewerLastPage() {
|
1895 | PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
1896 | }
|
1897 | function webViewerNextPage() {
|
1898 | PDFViewerApplication.pdfViewer.nextPage();
|
1899 | }
|
1900 | function webViewerPreviousPage() {
|
1901 | PDFViewerApplication.pdfViewer.previousPage();
|
1902 | }
|
1903 | function webViewerZoomIn() {
|
1904 | PDFViewerApplication.zoomIn();
|
1905 | }
|
1906 | function webViewerZoomOut() {
|
1907 | PDFViewerApplication.zoomOut();
|
1908 | }
|
1909 | function webViewerZoomReset() {
|
1910 | PDFViewerApplication.zoomReset();
|
1911 | }
|
1912 | function webViewerPageNumberChanged(evt) {
|
1913 | const pdfViewer = PDFViewerApplication.pdfViewer;
|
1914 | if (evt.value !== "") {
|
1915 | PDFViewerApplication.pdfLinkService.goToPage(evt.value);
|
1916 | }
|
1917 | if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
|
1918 | PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
1919 | }
|
1920 | }
|
1921 | function webViewerScaleChanged(evt) {
|
1922 | PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
|
1923 | }
|
1924 | function webViewerRotateCw() {
|
1925 | PDFViewerApplication.rotatePages(90);
|
1926 | }
|
1927 | function webViewerRotateCcw() {
|
1928 | PDFViewerApplication.rotatePages(-90);
|
1929 | }
|
1930 | function webViewerOptionalContentConfig(evt) {
|
1931 | PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
|
1932 | }
|
1933 | function webViewerSwitchScrollMode(evt) {
|
1934 | PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
|
1935 | }
|
1936 | function webViewerSwitchSpreadMode(evt) {
|
1937 | PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
|
1938 | }
|
1939 | function webViewerDocumentProperties() {
|
1940 | PDFViewerApplication.pdfDocumentProperties?.open();
|
1941 | }
|
1942 | function webViewerFindFromUrlHash(evt) {
|
1943 | PDFViewerApplication.eventBus.dispatch("find", {
|
1944 | source: evt.source,
|
1945 | type: "",
|
1946 | query: evt.query,
|
1947 | phraseSearch: evt.phraseSearch,
|
1948 | caseSensitive: false,
|
1949 | entireWord: false,
|
1950 | ignoreAccents: false,
|
1951 | fuzzySearch: false,
|
1952 | highlightAll: true,
|
1953 | findPrevious: false,
|
1954 | matchDiacritics: true
|
1955 | });
|
1956 | }
|
1957 | function webViewerUpdateFindMatchesCount({
|
1958 | matchesCount
|
1959 | }) {
|
1960 | if (PDFViewerApplication.supportsIntegratedFind) {
|
1961 | PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
|
1962 | } else {
|
1963 | PDFViewerApplication.findBar.updateResultsCount(matchesCount);
|
1964 | }
|
1965 | }
|
1966 | function webViewerUpdateFindControlState({
|
1967 | state,
|
1968 | previous,
|
1969 | matchesCount,
|
1970 | rawQuery
|
1971 | }) {
|
1972 | if (PDFViewerApplication.supportsIntegratedFind) {
|
1973 | PDFViewerApplication.externalServices.updateFindControlState({
|
1974 | result: state,
|
1975 | findPrevious: previous,
|
1976 | matchesCount,
|
1977 | rawQuery
|
1978 | });
|
1979 | } else {
|
1980 | PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
|
1981 | }
|
1982 | }
|
1983 | function webViewerScaleChanging(evt) {
|
1984 | PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
|
1985 | PDFViewerApplication.pdfViewer.update();
|
1986 | }
|
1987 | function webViewerRotationChanging(evt) {
|
1988 | if (PDFViewerApplication.pdfThumbnailViewer) {
|
1989 | PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
|
1990 | }
|
1991 | PDFViewerApplication.forceRendering();
|
1992 | PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
|
1993 | }
|
1994 | function webViewerPageChanging({
|
1995 | pageNumber,
|
1996 | pageLabel
|
1997 | }) {
|
1998 | PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
|
1999 | PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
|
2000 | if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
|
2001 | PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
|
2002 | }
|
2003 | const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
|
2004 | PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING);
|
2005 | const pageNumberInput = document.getElementById("pageNumber");
|
2006 | if (pageNumberInput) {
|
2007 | const pageScrollEvent = new CustomEvent("page-change");
|
2008 | pageNumberInput.dispatchEvent(pageScrollEvent);
|
2009 | }
|
2010 | }
|
2011 | function webViewerResolutionChange(evt) {
|
2012 | PDFViewerApplication.pdfViewer.refresh();
|
2013 | }
|
2014 | function webViewerVisibilityChange(evt) {
|
2015 | if (document.visibilityState === "visible") {
|
2016 | setZoomDisabledTimeout();
|
2017 | }
|
2018 | }
|
2019 | let zoomDisabledTimeout = null;
|
2020 | function setZoomDisabledTimeout() {
|
2021 | if (zoomDisabledTimeout) {
|
2022 | clearTimeout(zoomDisabledTimeout);
|
2023 | }
|
2024 | zoomDisabledTimeout = setTimeout(function () {
|
2025 | zoomDisabledTimeout = null;
|
2026 | }, WHEEL_ZOOM_DISABLED_TIMEOUT);
|
2027 | }
|
2028 | function webViewerWheel(evt) {
|
2029 | const element = document.getElementById("viewerContainer");
|
2030 | const hover = element.parentNode.querySelector(":hover");
|
2031 | if (hover !== element) {
|
2032 | return;
|
2033 | }
|
2034 | const {
|
2035 | pdfViewer,
|
2036 | supportedMouseWheelZoomModifierKeys,
|
2037 | supportsPinchToZoom
|
2038 | } = PDFViewerApplication;
|
2039 | if (pdfViewer.isInPresentationMode) {
|
2040 | return;
|
2041 | }
|
2042 | const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
|
2043 | if (window.isKeyIgnored && window.isKeyIgnored(cmd, "WHEEL")) {
|
2044 | return;
|
2045 | }
|
2046 | const deltaMode = evt.deltaMode;
|
2047 | let scaleFactor = Math.exp(-evt.deltaY / 100);
|
2048 | const isBuiltInMac = false;
|
2049 | const isPinchToZoom = evt.ctrlKey && !PDFViewerApplication._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) && evt.deltaZ === 0;
|
2050 | if (isPinchToZoom || evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
|
2051 | evt.preventDefault();
|
2052 | if (zoomDisabledTimeout || document.visibilityState === "hidden") {
|
2053 | return;
|
2054 | }
|
2055 | const previousScale = pdfViewer.currentScale;
|
2056 | if (isPinchToZoom && supportsPinchToZoom) {
|
2057 | scaleFactor = PDFViewerApplication._accumulateFactor(previousScale, scaleFactor, "_wheelUnusedFactor");
|
2058 | if (scaleFactor < 1) {
|
2059 | PDFViewerApplication.zoomOut(null, scaleFactor);
|
2060 | } else if (scaleFactor > 1) {
|
2061 | PDFViewerApplication.zoomIn(null, scaleFactor);
|
2062 | } else {
|
2063 | return;
|
2064 | }
|
2065 | } else {
|
2066 | const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
|
2067 | let ticks = 0;
|
2068 | if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) {
|
2069 | if (Math.abs(delta) >= 1) {
|
2070 | ticks = Math.sign(delta);
|
2071 | } else {
|
2072 | ticks = PDFViewerApplication._accumulateTicks(delta, "_wheelUnusedTicks");
|
2073 | }
|
2074 | } else {
|
2075 | const PIXELS_PER_LINE_SCALE = 30;
|
2076 | ticks = PDFViewerApplication._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks");
|
2077 | }
|
2078 | if (ticks < 0) {
|
2079 | PDFViewerApplication.zoomOut(-ticks);
|
2080 | } else if (ticks > 0) {
|
2081 | PDFViewerApplication.zoomIn(ticks);
|
2082 | } else {
|
2083 | return;
|
2084 | }
|
2085 | }
|
2086 | PDFViewerApplication._centerAtPos(previousScale, evt.clientX, evt.clientY);
|
2087 | } else {
|
2088 | setZoomDisabledTimeout();
|
2089 | }
|
2090 | }
|
2091 | function webViewerTouchStart(evt) {
|
2092 | if (PDFViewerApplication.pdfViewer.isInPresentationMode || evt.touches.length < 2) {
|
2093 | return;
|
2094 | }
|
2095 | evt.preventDefault();
|
2096 | if (evt.touches.length !== 2) {
|
2097 | PDFViewerApplication._touchInfo = null;
|
2098 | return;
|
2099 | }
|
2100 | let [touch0, touch1] = evt.touches;
|
2101 | if (touch0.identifier > touch1.identifier) {
|
2102 | [touch0, touch1] = [touch1, touch0];
|
2103 | }
|
2104 | PDFViewerApplication._touchInfo = {
|
2105 | touch0X: touch0.pageX,
|
2106 | touch0Y: touch0.pageY,
|
2107 | touch1X: touch1.pageX,
|
2108 | touch1Y: touch1.pageY
|
2109 | };
|
2110 | }
|
2111 | function webViewerTouchMove(evt) {
|
2112 | if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) {
|
2113 | return;
|
2114 | }
|
2115 | const {
|
2116 | pdfViewer,
|
2117 | _touchInfo,
|
2118 | supportsPinchToZoom
|
2119 | } = PDFViewerApplication;
|
2120 | let [touch0, touch1] = evt.touches;
|
2121 | if (touch0.identifier > touch1.identifier) {
|
2122 | [touch0, touch1] = [touch1, touch0];
|
2123 | }
|
2124 | const {
|
2125 | pageX: page0X,
|
2126 | pageY: page0Y
|
2127 | } = touch0;
|
2128 | const {
|
2129 | pageX: page1X,
|
2130 | pageY: page1Y
|
2131 | } = touch1;
|
2132 | const {
|
2133 | touch0X: pTouch0X,
|
2134 | touch0Y: pTouch0Y,
|
2135 | touch1X: pTouch1X,
|
2136 | touch1Y: pTouch1Y
|
2137 | } = _touchInfo;
|
2138 | if (Math.abs(pTouch0X - page0X) <= 1 && Math.abs(pTouch0Y - page0Y) <= 1 && Math.abs(pTouch1X - page1X) <= 1 && Math.abs(pTouch1Y - page1Y) <= 1) {
|
2139 | return;
|
2140 | }
|
2141 | _touchInfo.touch0X = page0X;
|
2142 | _touchInfo.touch0Y = page0Y;
|
2143 | _touchInfo.touch1X = page1X;
|
2144 | _touchInfo.touch1Y = page1Y;
|
2145 | if (pTouch0X === page0X && pTouch0Y === page0Y) {
|
2146 | const v1X = pTouch1X - page0X;
|
2147 | const v1Y = pTouch1Y - page0Y;
|
2148 | const v2X = page1X - page0X;
|
2149 | const v2Y = page1Y - page0Y;
|
2150 | const det = v1X * v2Y - v1Y * v2X;
|
2151 | if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
|
2152 | return;
|
2153 | }
|
2154 | } else if (pTouch1X === page1X && pTouch1Y === page1Y) {
|
2155 | const v1X = pTouch0X - page1X;
|
2156 | const v1Y = pTouch0Y - page1Y;
|
2157 | const v2X = page0X - page1X;
|
2158 | const v2Y = page0Y - page1Y;
|
2159 | const det = v1X * v2Y - v1Y * v2X;
|
2160 | if (Math.abs(det) > 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)) {
|
2161 | return;
|
2162 | }
|
2163 | } else {
|
2164 | const diff0X = page0X - pTouch0X;
|
2165 | const diff1X = page1X - pTouch1X;
|
2166 | const diff0Y = page0Y - pTouch0Y;
|
2167 | const diff1Y = page1Y - pTouch1Y;
|
2168 | const dotProduct = diff0X * diff1X + diff0Y * diff1Y;
|
2169 | if (dotProduct >= 0) {
|
2170 | return;
|
2171 | }
|
2172 | }
|
2173 | evt.preventDefault();
|
2174 | const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
|
2175 | const pDistance = Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
|
2176 | const previousScale = pdfViewer.currentScale;
|
2177 | if (supportsPinchToZoom) {
|
2178 | const newScaleFactor = PDFViewerApplication._accumulateFactor(previousScale, distance / pDistance, "_touchUnusedFactor");
|
2179 | if (newScaleFactor < 1) {
|
2180 | PDFViewerApplication.zoomOut(null, newScaleFactor);
|
2181 | } else if (newScaleFactor > 1) {
|
2182 | PDFViewerApplication.zoomIn(null, newScaleFactor);
|
2183 | } else {
|
2184 | return;
|
2185 | }
|
2186 | } else {
|
2187 | const PIXELS_PER_LINE_SCALE = 30;
|
2188 | const ticks = PDFViewerApplication._accumulateTicks((distance - pDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks");
|
2189 | if (ticks < 0) {
|
2190 | PDFViewerApplication.zoomOut(-ticks);
|
2191 | } else if (ticks > 0) {
|
2192 | PDFViewerApplication.zoomIn(ticks);
|
2193 | } else {
|
2194 | return;
|
2195 | }
|
2196 | }
|
2197 | PDFViewerApplication._centerAtPos(previousScale, (page0X + page1X) / 2, (page0Y + page1Y) / 2);
|
2198 | }
|
2199 | function webViewerTouchEnd(evt) {
|
2200 | if (!PDFViewerApplication._touchInfo) {
|
2201 | return;
|
2202 | }
|
2203 | evt.preventDefault();
|
2204 | PDFViewerApplication._touchInfo = null;
|
2205 | PDFViewerApplication._touchUnusedTicks = 0;
|
2206 | PDFViewerApplication._touchUnusedFactor = 1;
|
2207 | }
|
2208 | function webViewerClick(evt) {
|
2209 | if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
|
2210 | return;
|
2211 | }
|
2212 | const appConfig = PDFViewerApplication.appConfig;
|
2213 | if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
|
2214 | if (evt.target && evt.target.parentElement === appConfig.secondaryToolbar.toggleButton) {
|
2215 | return;
|
2216 | }
|
2217 | if (evt.target && evt.target.parentElement && evt.target.parentElement.parentElement === appConfig.secondaryToolbar.toggleButton) {
|
2218 | return;
|
2219 | }
|
2220 | PDFViewerApplication.secondaryToolbar.close();
|
2221 | }
|
2222 | }
|
2223 | function webViewerKeyUp(evt) {
|
2224 | if (evt.key === "Control") {
|
2225 | PDFViewerApplication._isCtrlKeyDown = false;
|
2226 | }
|
2227 | }
|
2228 | function webViewerKeyDown(evt) {
|
2229 | PDFViewerApplication._isCtrlKeyDown = evt.key === "Control";
|
2230 | if (PDFViewerApplication.overlayManager.active) {
|
2231 | return;
|
2232 | }
|
2233 | const {
|
2234 | eventBus,
|
2235 | pdfViewer
|
2236 | } = PDFViewerApplication;
|
2237 | const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
|
2238 | let handled = false,
|
2239 | ensureViewerFocused = false;
|
2240 | const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
|
2241 | if (window.isKeyIgnored && window.isKeyIgnored(cmd, evt.keyCode)) {
|
2242 | return;
|
2243 | }
|
2244 | if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
|
2245 | switch (evt.keyCode) {
|
2246 | case 70:
|
2247 | if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
|
2248 | PDFViewerApplication.findBar?.open();
|
2249 | handled = true;
|
2250 | }
|
2251 | break;
|
2252 | case 71:
|
2253 | if (!PDFViewerApplication.supportsIntegratedFind) {
|
2254 | const {
|
2255 | state
|
2256 | } = PDFViewerApplication.findController;
|
2257 | if (state) {
|
2258 | const newState = {
|
2259 | source: window,
|
2260 | type: "again",
|
2261 | findPrevious: cmd === 5 || cmd === 12
|
2262 | };
|
2263 | eventBus.dispatch("find", {
|
2264 | ...state,
|
2265 | ...newState
|
2266 | });
|
2267 | }
|
2268 | handled = true;
|
2269 | }
|
2270 | break;
|
2271 | case 61:
|
2272 | case 107:
|
2273 | case 187:
|
2274 | case 171:
|
2275 | PDFViewerApplication.zoomIn();
|
2276 | handled = true;
|
2277 | break;
|
2278 | case 173:
|
2279 | case 109:
|
2280 | case 189:
|
2281 | PDFViewerApplication.zoomOut();
|
2282 | handled = true;
|
2283 | break;
|
2284 | case 48:
|
2285 | case 96:
|
2286 | if (!isViewerInPresentationMode) {
|
2287 | setTimeout(function () {
|
2288 | PDFViewerApplication.zoomReset();
|
2289 | });
|
2290 | handled = false;
|
2291 | }
|
2292 | break;
|
2293 | case 38:
|
2294 | if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
|
2295 | PDFViewerApplication.page = 1;
|
2296 | handled = true;
|
2297 | ensureViewerFocused = true;
|
2298 | }
|
2299 | break;
|
2300 | case 40:
|
2301 | if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
2302 | PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
2303 | handled = true;
|
2304 | ensureViewerFocused = true;
|
2305 | }
|
2306 | break;
|
2307 | }
|
2308 | }
|
2309 | if (cmd === 1 || cmd === 8) {
|
2310 | switch (evt.keyCode) {
|
2311 | case 83:
|
2312 | eventBus.dispatch("download", {
|
2313 | source: window
|
2314 | });
|
2315 | handled = true;
|
2316 | break;
|
2317 | case 79:
|
2318 | {
|
2319 | eventBus.dispatch("openfile", {
|
2320 | source: window
|
2321 | });
|
2322 | handled = true;
|
2323 | }
|
2324 | break;
|
2325 | }
|
2326 | }
|
2327 | if (cmd === 3 || cmd === 10) {
|
2328 | switch (evt.keyCode) {
|
2329 | case 80:
|
2330 | PDFViewerApplication.requestPresentationMode();
|
2331 | handled = true;
|
2332 | PDFViewerApplication.externalServices.reportTelemetry({
|
2333 | type: "buttons",
|
2334 | data: {
|
2335 | id: "presentationModeKeyboard"
|
2336 | }
|
2337 | });
|
2338 | break;
|
2339 | case 71:
|
2340 | if (PDFViewerApplication.appConfig.toolbar) {
|
2341 | PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
2342 | handled = true;
|
2343 | }
|
2344 | break;
|
2345 | }
|
2346 | }
|
2347 | if (handled) {
|
2348 | if (ensureViewerFocused && !isViewerInPresentationMode) {
|
2349 | pdfViewer.focus();
|
2350 | }
|
2351 | evt.preventDefault();
|
2352 | return;
|
2353 | }
|
2354 | const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
|
2355 | const curElementTagName = curElement?.tagName.toUpperCase();
|
2356 | if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
|
2357 | if (evt.keyCode !== 27) {
|
2358 | return;
|
2359 | }
|
2360 | }
|
2361 | if (cmd === 0) {
|
2362 | let turnPage = 0,
|
2363 | turnOnlyIfPageFit = false;
|
2364 | switch (evt.keyCode) {
|
2365 | case 38:
|
2366 | case 33:
|
2367 | if (pdfViewer.isVerticalScrollbarEnabled) {
|
2368 | turnOnlyIfPageFit = true;
|
2369 | }
|
2370 | turnPage = -1;
|
2371 | break;
|
2372 | case 8:
|
2373 | if (!isViewerInPresentationMode) {
|
2374 | turnOnlyIfPageFit = true;
|
2375 | }
|
2376 | turnPage = -1;
|
2377 | break;
|
2378 | case 37:
|
2379 | if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2380 | turnOnlyIfPageFit = true;
|
2381 | }
|
2382 | case 75:
|
2383 | case 80:
|
2384 | turnPage = -1;
|
2385 | break;
|
2386 | case 27:
|
2387 | if (PDFViewerApplication.secondaryToolbar?.isOpen) {
|
2388 | PDFViewerApplication.secondaryToolbar.close();
|
2389 | handled = true;
|
2390 | }
|
2391 | if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
|
2392 | PDFViewerApplication.findBar.close();
|
2393 | handled = true;
|
2394 | }
|
2395 | break;
|
2396 | case 40:
|
2397 | case 34:
|
2398 | if (pdfViewer.isVerticalScrollbarEnabled) {
|
2399 | turnOnlyIfPageFit = true;
|
2400 | }
|
2401 | turnPage = 1;
|
2402 | break;
|
2403 | case 13:
|
2404 | case 32:
|
2405 | if (!isViewerInPresentationMode) {
|
2406 | turnOnlyIfPageFit = true;
|
2407 | }
|
2408 | turnPage = 1;
|
2409 | break;
|
2410 | case 39:
|
2411 | if (pdfViewer.isHorizontalScrollbarEnabled) {
|
2412 | turnOnlyIfPageFit = true;
|
2413 | }
|
2414 | case 74:
|
2415 | case 78:
|
2416 | turnPage = 1;
|
2417 | break;
|
2418 | case 36:
|
2419 | if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
|
2420 | PDFViewerApplication.page = 1;
|
2421 | handled = true;
|
2422 | ensureViewerFocused = true;
|
2423 | }
|
2424 | break;
|
2425 | case 35:
|
2426 | if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
|
2427 | PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
2428 | handled = true;
|
2429 | ensureViewerFocused = true;
|
2430 | }
|
2431 | break;
|
2432 | case 83:
|
2433 | PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.SELECT);
|
2434 | break;
|
2435 | case 72:
|
2436 | PDFViewerApplication.pdfCursorTools?.switchTool(_ui_utils.CursorTool.HAND);
|
2437 | break;
|
2438 | case 82:
|
2439 | PDFViewerApplication.rotatePages(90);
|
2440 | break;
|
2441 | case 115:
|
2442 | PDFViewerApplication.pdfSidebar?.toggle();
|
2443 | break;
|
2444 | }
|
2445 | if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
|
2446 | if (turnPage > 0) {
|
2447 | pdfViewer.nextPage();
|
2448 | } else {
|
2449 | pdfViewer.previousPage();
|
2450 | }
|
2451 | handled = true;
|
2452 | }
|
2453 | }
|
2454 | if (cmd === 4) {
|
2455 | switch (evt.keyCode) {
|
2456 | case 13:
|
2457 | case 32:
|
2458 | if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
|
2459 | break;
|
2460 | }
|
2461 | pdfViewer.previousPage();
|
2462 | handled = true;
|
2463 | break;
|
2464 | case 82:
|
2465 | PDFViewerApplication.rotatePages(-90);
|
2466 | break;
|
2467 | }
|
2468 | }
|
2469 | if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
|
2470 | pdfViewer.focus();
|
2471 | }
|
2472 | if (handled) {
|
2473 | evt.preventDefault();
|
2474 | }
|
2475 | }
|
2476 | function beforeUnload(evt) {
|
2477 | evt.preventDefault();
|
2478 | evt.returnValue = "";
|
2479 | return false;
|
2480 | }
|
2481 | function webViewerAnnotationEditorStatesChanged(data) {
|
2482 | PDFViewerApplication.externalServices.updateEditorStates(data);
|
2483 | }
|
2484 | const PDFPrintServiceFactory = {
|
2485 | instance: {
|
2486 | supportsPrinting: false,
|
2487 | createPrintService() {
|
2488 | throw new Error("Not implemented: createPrintService");
|
2489 | }
|
2490 | }
|
2491 | };
|
2492 | exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
|
2493 |
|
2494 | }),
|
2495 |
|
2496 | ((__unused_webpack_module, exports) => {
|
2497 |
|
2498 |
|
2499 |
|
2500 | Object.defineProperty(exports, "__esModule", ({
|
2501 | value: true
|
2502 | }));
|
2503 | exports.animationStarted = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RenderingStates = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.OutputScale = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE_DELTA = exports.DEFAULT_SCALE = exports.CursorTool = exports.AutoPrintRegExp = void 0;
|
2504 | exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
|
2505 | exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
|
2506 | exports.approximateFraction = approximateFraction;
|
2507 | exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
|
2508 | exports.binarySearchFirstItem = binarySearchFirstItem;
|
2509 | exports.docStyle = void 0;
|
2510 | exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
|
2511 | exports.getPageSizeInches = getPageSizeInches;
|
2512 | exports.getVisibleElements = getVisibleElements;
|
2513 | exports.isPortraitOrientation = isPortraitOrientation;
|
2514 | exports.isValidRotation = isValidRotation;
|
2515 | exports.isValidScrollMode = isValidScrollMode;
|
2516 | exports.isValidSpreadMode = isValidSpreadMode;
|
2517 | exports.noContextMenuHandler = noContextMenuHandler;
|
2518 | exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
|
2519 | exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
|
2520 | exports.parseQueryString = parseQueryString;
|
2521 | exports.removeNullCharacters = removeNullCharacters;
|
2522 | exports.roundToDivide = roundToDivide;
|
2523 | exports.scrollIntoView = scrollIntoView;
|
2524 | exports.watchScroll = watchScroll;
|
2525 | const DEFAULT_SCALE_VALUE = "auto";
|
2526 | exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
|
2527 | const DEFAULT_SCALE = 1.0;
|
2528 | exports.DEFAULT_SCALE = DEFAULT_SCALE;
|
2529 | const DEFAULT_SCALE_DELTA = 1.1;
|
2530 | exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
|
2531 | const MIN_SCALE = 0.1;
|
2532 | exports.MIN_SCALE = MIN_SCALE;
|
2533 | const MAX_SCALE = 10.0;
|
2534 | exports.MAX_SCALE = MAX_SCALE;
|
2535 | const UNKNOWN_SCALE = 0;
|
2536 | exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
|
2537 | const MAX_AUTO_SCALE = 1.25;
|
2538 | exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
|
2539 | const SCROLLBAR_PADDING = 40;
|
2540 | exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
|
2541 | const VERTICAL_PADDING = 5;
|
2542 | exports.VERTICAL_PADDING = VERTICAL_PADDING;
|
2543 | const RenderingStates = {
|
2544 | INITIAL: 0,
|
2545 | RUNNING: 1,
|
2546 | PAUSED: 2,
|
2547 | FINISHED: 3
|
2548 | };
|
2549 | exports.RenderingStates = RenderingStates;
|
2550 | const PresentationModeState = {
|
2551 | UNKNOWN: 0,
|
2552 | NORMAL: 1,
|
2553 | CHANGING: 2,
|
2554 | FULLSCREEN: 3
|
2555 | };
|
2556 | exports.PresentationModeState = PresentationModeState;
|
2557 | const SidebarView = {
|
2558 | UNKNOWN: -1,
|
2559 | NONE: 0,
|
2560 | THUMBS: 1,
|
2561 | OUTLINE: 2,
|
2562 | ATTACHMENTS: 3,
|
2563 | LAYERS: 4
|
2564 | };
|
2565 | exports.SidebarView = SidebarView;
|
2566 | const RendererType = {
|
2567 | CANVAS: "canvas",
|
2568 | SVG: "svg"
|
2569 | };
|
2570 | exports.RendererType = RendererType;
|
2571 | const TextLayerMode = {
|
2572 | DISABLE: 0,
|
2573 | ENABLE: 1
|
2574 | };
|
2575 | exports.TextLayerMode = TextLayerMode;
|
2576 | const ScrollMode = {
|
2577 | UNKNOWN: -1,
|
2578 | VERTICAL: 0,
|
2579 | HORIZONTAL: 1,
|
2580 | WRAPPED: 2,
|
2581 | PAGE: 3
|
2582 | };
|
2583 | exports.ScrollMode = ScrollMode;
|
2584 | const SpreadMode = {
|
2585 | UNKNOWN: -1,
|
2586 | NONE: 0,
|
2587 | ODD: 1,
|
2588 | EVEN: 2
|
2589 | };
|
2590 | exports.SpreadMode = SpreadMode;
|
2591 | const CursorTool = {
|
2592 | SELECT: 0,
|
2593 | HAND: 1,
|
2594 | ZOOM: 2
|
2595 | };
|
2596 | exports.CursorTool = CursorTool;
|
2597 | const AutoPrintRegExp = /\bprint\s*\(/;
|
2598 | exports.AutoPrintRegExp = AutoPrintRegExp;
|
2599 | class OutputScale {
|
2600 | constructor() {
|
2601 | const pixelRatio = window.devicePixelRatio || 1;
|
2602 | this.sx = pixelRatio;
|
2603 | this.sy = pixelRatio;
|
2604 | }
|
2605 | get scaled() {
|
2606 | return this.sx !== 1 || this.sy !== 1;
|
2607 | }
|
2608 | }
|
2609 | exports.OutputScale = OutputScale;
|
2610 | function scrollIntoView(element, spot, scrollMatches = false, infiniteScroll = false) {
|
2611 | if (element.classList.contains("stf__item")) {
|
2612 | Window['ngxConsole'].log("don't scroll in book mode");
|
2613 | return;
|
2614 | }
|
2615 | let parent = element.offsetParent;
|
2616 | if (!parent) {
|
2617 | Window['ngxConsole'].error("offsetParent is not set -- cannot scroll");
|
2618 | return;
|
2619 | }
|
2620 | let offsetY = element.offsetTop + element.clientTop;
|
2621 | let offsetX = element.offsetLeft + element.clientLeft;
|
2622 | while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
|
2623 | offsetY += parent.offsetTop;
|
2624 | offsetX += parent.offsetLeft;
|
2625 | parent = parent.offsetParent;
|
2626 | if (!parent) {
|
2627 | if (infiniteScroll) {
|
2628 | if (document.body.clientHeight > offsetY) {
|
2629 | offsetY -= 32;
|
2630 | window.scrollTo(window.scrollX, offsetY);
|
2631 | }
|
2632 | }
|
2633 | return;
|
2634 | }
|
2635 | }
|
2636 | if (spot) {
|
2637 | if (spot.top !== undefined) {
|
2638 | offsetY += spot.top;
|
2639 | }
|
2640 | if (spot.left !== undefined) {
|
2641 | offsetX += spot.left;
|
2642 | parent.scrollLeft = offsetX;
|
2643 | }
|
2644 | }
|
2645 | parent.scrollTop = offsetY;
|
2646 | }
|
2647 | function watchScroll(viewAreaElement, callback) {
|
2648 | const debounceScroll = function (evt) {
|
2649 | if (rAF) {
|
2650 | return;
|
2651 | }
|
2652 | rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
|
2653 | rAF = null;
|
2654 | const currentX = viewAreaElement.scrollLeft;
|
2655 | const lastX = state.lastX;
|
2656 | if (currentX !== lastX) {
|
2657 | state.right = currentX > lastX;
|
2658 | }
|
2659 | state.lastX = currentX;
|
2660 | const currentY = viewAreaElement.scrollTop;
|
2661 | const lastY = state.lastY;
|
2662 | if (currentY !== lastY) {
|
2663 | state.down = currentY > lastY;
|
2664 | }
|
2665 | state.lastY = currentY;
|
2666 | callback(state);
|
2667 | });
|
2668 | };
|
2669 | const state = {
|
2670 | right: true,
|
2671 | down: true,
|
2672 | lastX: viewAreaElement.scrollLeft,
|
2673 | lastY: viewAreaElement.scrollTop,
|
2674 | _eventHandler: debounceScroll
|
2675 | };
|
2676 | let rAF = null;
|
2677 | viewAreaElement.addEventListener("scroll", debounceScroll, true);
|
2678 | return state;
|
2679 | }
|
2680 | function parseQueryString(query) {
|
2681 | const params = new Map();
|
2682 | for (const [key, value] of new URLSearchParams(query)) {
|
2683 | params.set(key.toLowerCase(), value);
|
2684 | }
|
2685 | return params;
|
2686 | }
|
2687 | const NullCharactersRegExp = /\x00/g;
|
2688 | const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
|
2689 | function removeNullCharacters(str, replaceInvisible = false) {
|
2690 | if (typeof str !== "string") {
|
2691 | console.error(`The argument must be a string.`);
|
2692 | return str;
|
2693 | }
|
2694 | if (replaceInvisible) {
|
2695 | str = str.replace(InvisibleCharactersRegExp, " ");
|
2696 | }
|
2697 | return str.replace(NullCharactersRegExp, "");
|
2698 | }
|
2699 | function binarySearchFirstItem(items, condition, start = 0) {
|
2700 | let minIndex = start;
|
2701 | let maxIndex = items.length - 1;
|
2702 | if (maxIndex < 0 || !condition(items[maxIndex])) {
|
2703 | return items.length;
|
2704 | }
|
2705 | if (condition(items[minIndex])) {
|
2706 | return minIndex;
|
2707 | }
|
2708 | while (minIndex < maxIndex) {
|
2709 | const currentIndex = minIndex + maxIndex >> 1;
|
2710 | const currentItem = items[currentIndex];
|
2711 | if (condition(currentItem)) {
|
2712 | maxIndex = currentIndex;
|
2713 | } else {
|
2714 | minIndex = currentIndex + 1;
|
2715 | }
|
2716 | }
|
2717 | return minIndex;
|
2718 | }
|
2719 | function approximateFraction(x) {
|
2720 | if (Math.floor(x) === x) {
|
2721 | return [x, 1];
|
2722 | }
|
2723 | const xinv = 1 / x;
|
2724 | const limit = 8;
|
2725 | if (xinv > limit) {
|
2726 | return [1, limit];
|
2727 | } else if (Math.floor(xinv) === xinv) {
|
2728 | return [1, xinv];
|
2729 | }
|
2730 | const x_ = x > 1 ? xinv : x;
|
2731 | let a = 0,
|
2732 | b = 1,
|
2733 | c = 1,
|
2734 | d = 1;
|
2735 | while (true) {
|
2736 | const p = a + c,
|
2737 | q = b + d;
|
2738 | if (q > limit) {
|
2739 | break;
|
2740 | }
|
2741 | if (x_ <= p / q) {
|
2742 | c = p;
|
2743 | d = q;
|
2744 | } else {
|
2745 | a = p;
|
2746 | b = q;
|
2747 | }
|
2748 | }
|
2749 | let result;
|
2750 | if (x_ - a / b < c / d - x_) {
|
2751 | result = x_ === x ? [a, b] : [b, a];
|
2752 | } else {
|
2753 | result = x_ === x ? [c, d] : [d, c];
|
2754 | }
|
2755 | return result;
|
2756 | }
|
2757 | function roundToDivide(x, div) {
|
2758 | const r = x % div;
|
2759 | return r === 0 ? x : Math.round(x - r + div);
|
2760 | }
|
2761 | function getPageSizeInches({
|
2762 | view,
|
2763 | userUnit,
|
2764 | rotate
|
2765 | }) {
|
2766 | const [x1, y1, x2, y2] = view;
|
2767 | const changeOrientation = rotate % 180 !== 0;
|
2768 | const width = (x2 - x1) / 72 * userUnit;
|
2769 | const height = (y2 - y1) / 72 * userUnit;
|
2770 | return {
|
2771 | width: changeOrientation ? height : width,
|
2772 | height: changeOrientation ? width : height
|
2773 | };
|
2774 | }
|
2775 | function backtrackBeforeAllVisibleElements(index, views, top) {
|
2776 | if (index < 2) {
|
2777 | return index;
|
2778 | }
|
2779 | let elt = views[index].div;
|
2780 | let pageTop = elt.offsetTop + elt.clientTop;
|
2781 | if (pageTop >= top) {
|
2782 | elt = views[index - 1].div;
|
2783 | pageTop = elt.offsetTop + elt.clientTop;
|
2784 | }
|
2785 | for (let i = index - 2; i >= 0; --i) {
|
2786 | elt = views[i].div;
|
2787 | if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
|
2788 | break;
|
2789 | }
|
2790 | index = i;
|
2791 | }
|
2792 | return index;
|
2793 | }
|
2794 | function getVisibleElements({
|
2795 | scrollEl,
|
2796 | views,
|
2797 | sortByVisibility = false,
|
2798 | horizontal = false,
|
2799 | rtl = false
|
2800 | }) {
|
2801 | const top = scrollEl.scrollTop,
|
2802 | bottom = top + scrollEl.clientHeight;
|
2803 | const left = scrollEl.scrollLeft,
|
2804 | right = left + scrollEl.clientWidth;
|
2805 | function isElementBottomAfterViewTop(view) {
|
2806 | const element = view.div;
|
2807 | const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
|
2808 | return elementBottom > top;
|
2809 | }
|
2810 | function isElementNextAfterViewHorizontally(view) {
|
2811 | const element = view.div;
|
2812 | const elementLeft = element.offsetLeft + element.clientLeft;
|
2813 | const elementRight = elementLeft + element.clientWidth;
|
2814 | return rtl ? elementLeft < right : elementRight > left;
|
2815 | }
|
2816 | const visible = [],
|
2817 | ids = new Set(),
|
2818 | numViews = views.length;
|
2819 | let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
|
2820 | if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
|
2821 | firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
|
2822 | }
|
2823 | let lastEdge = horizontal ? right : -1;
|
2824 | for (let i = firstVisibleElementInd; i < numViews; i++) {
|
2825 | const view = views[i],
|
2826 | element = view.div;
|
2827 | const currentWidth = element.offsetLeft + element.clientLeft;
|
2828 | const currentHeight = element.offsetTop + element.clientTop;
|
2829 | const viewWidth = element.clientWidth,
|
2830 | viewHeight = element.clientHeight;
|
2831 | const viewRight = currentWidth + viewWidth;
|
2832 | const viewBottom = currentHeight + viewHeight;
|
2833 | if (lastEdge === -1) {
|
2834 | if (viewBottom >= bottom) {
|
2835 | lastEdge = viewBottom;
|
2836 | }
|
2837 | } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
|
2838 | break;
|
2839 | }
|
2840 | if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
|
2841 | continue;
|
2842 | }
|
2843 | const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
|
2844 | const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
|
2845 | const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
|
2846 | fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
|
2847 | const percent = fractionHeight * fractionWidth * 100 | 0;
|
2848 | visible.push({
|
2849 | id: view.id,
|
2850 | x: currentWidth,
|
2851 | y: currentHeight,
|
2852 | view,
|
2853 | percent,
|
2854 | widthPercent: fractionWidth * 100 | 0
|
2855 | });
|
2856 | ids.add(view.id);
|
2857 | }
|
2858 | const first = visible[0],
|
2859 | last = visible.at(-1);
|
2860 | if (sortByVisibility) {
|
2861 | visible.sort(function (a, b) {
|
2862 | const pc = a.percent - b.percent;
|
2863 | if (Math.abs(pc) > 0.001) {
|
2864 | return -pc;
|
2865 | }
|
2866 | return a.id - b.id;
|
2867 | });
|
2868 | }
|
2869 | return {
|
2870 | first,
|
2871 | last,
|
2872 | views: visible,
|
2873 | ids
|
2874 | };
|
2875 | }
|
2876 | function noContextMenuHandler(evt) {
|
2877 | evt.preventDefault();
|
2878 | }
|
2879 | function normalizeWheelEventDirection(evt) {
|
2880 | let delta = Math.hypot(evt.deltaX, evt.deltaY);
|
2881 | const angle = Math.atan2(evt.deltaY, evt.deltaX);
|
2882 | if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
|
2883 | delta = -delta;
|
2884 | }
|
2885 | return delta;
|
2886 | }
|
2887 | function normalizeWheelEventDelta(evt) {
|
2888 | const deltaMode = evt.deltaMode;
|
2889 | let delta = normalizeWheelEventDirection(evt);
|
2890 | const MOUSE_PIXELS_PER_LINE = 30;
|
2891 | const MOUSE_LINES_PER_PAGE = 30;
|
2892 | if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
|
2893 | delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
|
2894 | } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
|
2895 | delta /= MOUSE_LINES_PER_PAGE;
|
2896 | }
|
2897 | return delta;
|
2898 | }
|
2899 | function isValidRotation(angle) {
|
2900 | return Number.isInteger(angle) && angle % 90 === 0;
|
2901 | }
|
2902 | function isValidScrollMode(mode) {
|
2903 | return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
|
2904 | }
|
2905 | function isValidSpreadMode(mode) {
|
2906 | return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
|
2907 | }
|
2908 | function isPortraitOrientation(size) {
|
2909 | return size.width <= size.height;
|
2910 | }
|
2911 | const animationStarted = new Promise(function (resolve) {
|
2912 | window.ngxZone.runOutsideAngular(() => {
|
2913 | window.requestAnimationFrame(resolve);
|
2914 | });
|
2915 | });
|
2916 | exports.animationStarted = animationStarted;
|
2917 | const docStyle = document.documentElement.style;
|
2918 | exports.docStyle = docStyle;
|
2919 | function clamp(v, min, max) {
|
2920 | return Math.min(Math.max(v, min), max);
|
2921 | }
|
2922 | class ProgressBar {
|
2923 | #classList = null;
|
2924 | #disableAutoFetchTimeout = null;
|
2925 | #percent = 0;
|
2926 | #style = null;
|
2927 | #visible = true;
|
2928 | constructor(bar) {
|
2929 | this.#classList = bar.classList;
|
2930 | this.#style = bar.style;
|
2931 | }
|
2932 | get percent() {
|
2933 | return this.#percent;
|
2934 | }
|
2935 | set percent(val) {
|
2936 | this.#percent = clamp(val, 0, 100);
|
2937 | if (isNaN(val)) {
|
2938 | this.#classList.add("indeterminate");
|
2939 | return;
|
2940 | }
|
2941 | this.#classList.remove("indeterminate");
|
2942 | this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
|
2943 | }
|
2944 | setWidth(viewer) {
|
2945 | if (!viewer) {
|
2946 | return;
|
2947 | }
|
2948 | const container = viewer.parentNode;
|
2949 | const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
|
2950 | if (scrollbarWidth > 0) {
|
2951 | this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
|
2952 | }
|
2953 | }
|
2954 | setDisableAutoFetch(delay = 5000) {
|
2955 | if (isNaN(this.#percent)) {
|
2956 | return;
|
2957 | }
|
2958 | if (this.#disableAutoFetchTimeout) {
|
2959 | clearTimeout(this.#disableAutoFetchTimeout);
|
2960 | }
|
2961 | this.show();
|
2962 | this.#disableAutoFetchTimeout = setTimeout(() => {
|
2963 | this.#disableAutoFetchTimeout = null;
|
2964 | this.hide();
|
2965 | }, delay);
|
2966 | }
|
2967 | hide() {
|
2968 | if (!this.#visible) {
|
2969 | return;
|
2970 | }
|
2971 | this.#visible = false;
|
2972 | this.#classList.add("hidden");
|
2973 | }
|
2974 | show() {
|
2975 | if (this.#visible) {
|
2976 | return;
|
2977 | }
|
2978 | this.#visible = true;
|
2979 | this.#classList.remove("hidden");
|
2980 | }
|
2981 | }
|
2982 | exports.ProgressBar = ProgressBar;
|
2983 | function getActiveOrFocusedElement() {
|
2984 | let curRoot = document;
|
2985 | let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
|
2986 | while (curActiveOrFocused?.shadowRoot) {
|
2987 | curRoot = curActiveOrFocused.shadowRoot;
|
2988 | curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
|
2989 | }
|
2990 | return curActiveOrFocused;
|
2991 | }
|
2992 | function apiPageLayoutToViewerModes(layout) {
|
2993 | let scrollMode = ScrollMode.VERTICAL,
|
2994 | spreadMode = SpreadMode.NONE;
|
2995 | switch (layout) {
|
2996 | case "SinglePage":
|
2997 | scrollMode = ScrollMode.PAGE;
|
2998 | break;
|
2999 | case "OneColumn":
|
3000 | break;
|
3001 | case "TwoPageLeft":
|
3002 | scrollMode = ScrollMode.PAGE;
|
3003 | case "TwoColumnLeft":
|
3004 | spreadMode = SpreadMode.ODD;
|
3005 | break;
|
3006 | case "TwoPageRight":
|
3007 | scrollMode = ScrollMode.PAGE;
|
3008 | case "TwoColumnRight":
|
3009 | spreadMode = SpreadMode.EVEN;
|
3010 | break;
|
3011 | }
|
3012 | return {
|
3013 | scrollMode,
|
3014 | spreadMode
|
3015 | };
|
3016 | }
|
3017 | function apiPageModeToSidebarView(mode) {
|
3018 | switch (mode) {
|
3019 | case "UseNone":
|
3020 | return SidebarView.NONE;
|
3021 | case "UseThumbs":
|
3022 | return SidebarView.THUMBS;
|
3023 | case "UseOutlines":
|
3024 | return SidebarView.OUTLINE;
|
3025 | case "UseAttachments":
|
3026 | return SidebarView.ATTACHMENTS;
|
3027 | case "UseOC":
|
3028 | return SidebarView.LAYERS;
|
3029 | }
|
3030 | return SidebarView.NONE;
|
3031 | }
|
3032 |
|
3033 | }),
|
3034 |
|
3035 | ((module) => {
|
3036 |
|
3037 |
|
3038 |
|
3039 | module.exports = window["pdfjs-dist/build/pdf"];
|
3040 |
|
3041 | }),
|
3042 |
|
3043 | ((__unused_webpack_module, exports) => {
|
3044 |
|
3045 |
|
3046 |
|
3047 | Object.defineProperty(exports, "__esModule", ({
|
3048 | value: true
|
3049 | }));
|
3050 | exports.compatibilityParams = exports.OptionKind = exports.AppOptions = void 0;
|
3051 | const compatibilityParams = Object.create(null);
|
3052 | exports.compatibilityParams = compatibilityParams;
|
3053 | {
|
3054 | const userAgent = navigator.userAgent || "";
|
3055 | const platform = navigator.platform || "";
|
3056 | const maxTouchPoints = navigator.maxTouchPoints || 1;
|
3057 | const isAndroid = /Android/.test(userAgent);
|
3058 | const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
|
3059 | (function checkCanvasSizeLimitation() {
|
3060 | if (isIOS || isAndroid) {
|
3061 | compatibilityParams.maxCanvasPixels = 5242880;
|
3062 | }
|
3063 | })();
|
3064 | }
|
3065 | const OptionKind = {
|
3066 | VIEWER: 0x02,
|
3067 | API: 0x04,
|
3068 | WORKER: 0x08,
|
3069 | PREFERENCE: 0x80
|
3070 | };
|
3071 | exports.OptionKind = OptionKind;
|
3072 | const defaultOptions = {
|
3073 | annotationEditorMode: {
|
3074 | value: 0,
|
3075 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3076 | },
|
3077 | annotationMode: {
|
3078 | value: 2,
|
3079 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3080 | },
|
3081 | cursorToolOnLoad: {
|
3082 | value: 0,
|
3083 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3084 | },
|
3085 | defaultZoomDelay: {
|
3086 | value: 400,
|
3087 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3088 | },
|
3089 | defaultZoomValue: {
|
3090 | value: "",
|
3091 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3092 | },
|
3093 | disableHistory: {
|
3094 | value: false,
|
3095 | kind: OptionKind.VIEWER
|
3096 | },
|
3097 | disablePageLabels: {
|
3098 | value: false,
|
3099 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3100 | },
|
3101 | enablePermissions: {
|
3102 | value: false,
|
3103 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3104 | },
|
3105 | enablePrintAutoRotate: {
|
3106 | value: true,
|
3107 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3108 | },
|
3109 | enableScripting: {
|
3110 | value: true,
|
3111 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3112 | },
|
3113 | externalLinkRel: {
|
3114 | value: "noopener noreferrer nofollow",
|
3115 | kind: OptionKind.VIEWER
|
3116 | },
|
3117 | externalLinkTarget: {
|
3118 | value: 0,
|
3119 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3120 | },
|
3121 | historyUpdateUrl: {
|
3122 | value: false,
|
3123 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3124 | },
|
3125 | ignoreDestinationZoom: {
|
3126 | value: false,
|
3127 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3128 | },
|
3129 | imageResourcesPath: {
|
3130 | value: "./images/",
|
3131 | kind: OptionKind.VIEWER
|
3132 | },
|
3133 | maxCanvasPixels: {
|
3134 | value: 16777216,
|
3135 | kind: OptionKind.VIEWER
|
3136 | },
|
3137 | forcePageColors: {
|
3138 | value: false,
|
3139 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3140 | },
|
3141 | pageColorsBackground: {
|
3142 | value: "Canvas",
|
3143 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3144 | },
|
3145 | pageColorsForeground: {
|
3146 | value: "CanvasText",
|
3147 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3148 | },
|
3149 | pdfBugEnabled: {
|
3150 | value: false,
|
3151 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3152 | },
|
3153 | printResolution: {
|
3154 | value: 150,
|
3155 | kind: OptionKind.VIEWER
|
3156 | },
|
3157 | removePageBorders: {
|
3158 | value: false,
|
3159 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3160 | },
|
3161 | sidebarViewOnLoad: {
|
3162 | value: -1,
|
3163 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3164 | },
|
3165 | scrollModeOnLoad: {
|
3166 | value: -1,
|
3167 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3168 | },
|
3169 | spreadModeOnLoad: {
|
3170 | value: -1,
|
3171 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3172 | },
|
3173 | textLayerMode: {
|
3174 | value: 1,
|
3175 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3176 | },
|
3177 | useOnlyCssZoom: {
|
3178 | value: false,
|
3179 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3180 | },
|
3181 | viewerCssTheme: {
|
3182 | value: 0,
|
3183 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3184 | },
|
3185 | viewOnLoad: {
|
3186 | value: 0,
|
3187 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3188 | },
|
3189 | cMapPacked: {
|
3190 | value: true,
|
3191 | kind: OptionKind.API
|
3192 | },
|
3193 | cMapUrl: {
|
3194 | value: "../web/cmaps/",
|
3195 | kind: OptionKind.API
|
3196 | },
|
3197 | disableAutoFetch: {
|
3198 | value: false,
|
3199 | kind: OptionKind.API + OptionKind.PREFERENCE
|
3200 | },
|
3201 | disableFontFace: {
|
3202 | value: false,
|
3203 | kind: OptionKind.API + OptionKind.PREFERENCE
|
3204 | },
|
3205 | disableRange: {
|
3206 | value: false,
|
3207 | kind: OptionKind.API + OptionKind.PREFERENCE
|
3208 | },
|
3209 | disableStream: {
|
3210 | value: false,
|
3211 | kind: OptionKind.API + OptionKind.PREFERENCE
|
3212 | },
|
3213 | docBaseUrl: {
|
3214 | value: "",
|
3215 | kind: OptionKind.API
|
3216 | },
|
3217 | enableXfa: {
|
3218 | value: true,
|
3219 | kind: OptionKind.API + OptionKind.PREFERENCE
|
3220 | },
|
3221 | fontExtraProperties: {
|
3222 | value: false,
|
3223 | kind: OptionKind.API
|
3224 | },
|
3225 | isEvalSupported: {
|
3226 | value: true,
|
3227 | kind: OptionKind.API
|
3228 | },
|
3229 | isOffscreenCanvasSupported: {
|
3230 | value: true,
|
3231 | kind: OptionKind.API
|
3232 | },
|
3233 | maxImageSize: {
|
3234 | value: -1,
|
3235 | kind: OptionKind.API
|
3236 | },
|
3237 | pdfBug: {
|
3238 | value: false,
|
3239 | kind: OptionKind.API
|
3240 | },
|
3241 | standardFontDataUrl: {
|
3242 | value: "../web/standard_fonts/",
|
3243 | kind: OptionKind.API
|
3244 | },
|
3245 | verbosity: {
|
3246 | value: 1,
|
3247 | kind: OptionKind.API
|
3248 | },
|
3249 | workerPort: {
|
3250 | value: null,
|
3251 | kind: OptionKind.WORKER
|
3252 | },
|
3253 | workerSrc: {
|
3254 | value: "./assets/pdf.worker.js",
|
3255 | kind: OptionKind.WORKER
|
3256 | }
|
3257 | };
|
3258 | {
|
3259 | defaultOptions.defaultUrl = {
|
3260 | value: "compressed.tracemonkey-pldi-09.pdf",
|
3261 | kind: OptionKind.VIEWER
|
3262 | };
|
3263 | defaultOptions.disablePreferences = {
|
3264 | value: false,
|
3265 | kind: OptionKind.VIEWER
|
3266 | };
|
3267 | defaultOptions.locale = {
|
3268 | value: navigator.language || "en-US",
|
3269 | kind: OptionKind.VIEWER
|
3270 | };
|
3271 | defaultOptions.renderer = {
|
3272 | value: "canvas",
|
3273 | kind: OptionKind.VIEWER + OptionKind.PREFERENCE
|
3274 | };
|
3275 | defaultOptions.sandboxBundleSrc = {
|
3276 | value: "../build/pdf.sandbox.js",
|
3277 | kind: OptionKind.VIEWER
|
3278 | };
|
3279 | }
|
3280 | const userOptions = Object.create(null);
|
3281 | if (globalThis.pdfDefaultOptions) {
|
3282 | for (const key in globalThis.pdfDefaultOptions) {
|
3283 | userOptions[key] = globalThis.pdfDefaultOptions[key];
|
3284 | }
|
3285 | }
|
3286 | class AppOptions {
|
3287 | constructor() {
|
3288 | throw new Error("Cannot initialize AppOptions.");
|
3289 | }
|
3290 | static get(name) {
|
3291 | const userOption = userOptions[name];
|
3292 | if (userOption !== undefined) {
|
3293 | return userOption;
|
3294 | }
|
3295 | const defaultOption = defaultOptions[name];
|
3296 | if (defaultOption !== undefined) {
|
3297 | return compatibilityParams[name] ?? defaultOption.value;
|
3298 | }
|
3299 | return undefined;
|
3300 | }
|
3301 | static getAll(kind = null) {
|
3302 | const options = Object.create(null);
|
3303 | for (const name in defaultOptions) {
|
3304 | const defaultOption = defaultOptions[name];
|
3305 | if (kind) {
|
3306 | if ((kind & defaultOption.kind) === 0) {
|
3307 | continue;
|
3308 | }
|
3309 | if (kind === OptionKind.PREFERENCE) {
|
3310 | const value = defaultOption.value,
|
3311 | valueType = typeof value;
|
3312 | if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
|
3313 | options[name] = value;
|
3314 | continue;
|
3315 | }
|
3316 | throw new Error(`Invalid type for preference: ${name}`);
|
3317 | }
|
3318 | }
|
3319 | const userOption = userOptions[name];
|
3320 | options[name] = userOption !== undefined ? userOption : compatibilityParams[name] ?? defaultOption.value;
|
3321 | }
|
3322 | return options;
|
3323 | }
|
3324 | static set(name, value) {
|
3325 | userOptions[name] = value;
|
3326 | }
|
3327 | static setAll(options) {
|
3328 | for (const name in options) {
|
3329 | userOptions[name] = options[name];
|
3330 | }
|
3331 | }
|
3332 | static remove(name) {
|
3333 | delete userOptions[name];
|
3334 | }
|
3335 | }
|
3336 | exports.AppOptions = AppOptions;
|
3337 | {
|
3338 | AppOptions._hasUserOptions = function () {
|
3339 | return Object.keys(userOptions).length > 0;
|
3340 | };
|
3341 | }
|
3342 |
|
3343 | }),
|
3344 |
|
3345 | ((__unused_webpack_module, exports) => {
|
3346 |
|
3347 |
|
3348 |
|
3349 | Object.defineProperty(exports, "__esModule", ({
|
3350 | value: true
|
3351 | }));
|
3352 | exports.WaitOnType = exports.EventBus = exports.AutomationEventBus = void 0;
|
3353 | exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
|
3354 | const WaitOnType = {
|
3355 | EVENT: "event",
|
3356 | TIMEOUT: "timeout"
|
3357 | };
|
3358 | exports.WaitOnType = WaitOnType;
|
3359 | function waitOnEventOrTimeout({
|
3360 | target,
|
3361 | name,
|
3362 | delay = 0
|
3363 | }) {
|
3364 | return new Promise(function (resolve, reject) {
|
3365 | if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
|
3366 | throw new Error("waitOnEventOrTimeout - invalid parameters.");
|
3367 | }
|
3368 | function handler(type) {
|
3369 | if (target instanceof EventBus) {
|
3370 | target._off(name, eventHandler);
|
3371 | } else {
|
3372 | target.removeEventListener(name, eventHandler);
|
3373 | }
|
3374 | if (timeout) {
|
3375 | clearTimeout(timeout);
|
3376 | }
|
3377 | resolve(type);
|
3378 | }
|
3379 | const eventHandler = handler.bind(null, WaitOnType.EVENT);
|
3380 | if (target instanceof EventBus) {
|
3381 | target._on(name, eventHandler);
|
3382 | } else {
|
3383 | target.addEventListener(name, eventHandler);
|
3384 | }
|
3385 | const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
|
3386 | const timeout = setTimeout(timeoutHandler, delay);
|
3387 | });
|
3388 | }
|
3389 | class EventBus {
|
3390 | #listeners = Object.create(null);
|
3391 | on(eventName, listener, options = null) {
|
3392 | this._on(eventName, listener, {
|
3393 | external: true,
|
3394 | once: options?.once
|
3395 | });
|
3396 | }
|
3397 | off(eventName, listener, options = null) {
|
3398 | this._off(eventName, listener, {
|
3399 | external: true,
|
3400 | once: options?.once
|
3401 | });
|
3402 | }
|
3403 | dispatch(eventName, data) {
|
3404 | const eventListeners = this.#listeners[eventName];
|
3405 | if (!eventListeners || eventListeners.length === 0) {
|
3406 | return;
|
3407 | }
|
3408 | let externalListeners;
|
3409 | for (const {
|
3410 | listener,
|
3411 | external,
|
3412 | once
|
3413 | } of eventListeners.slice(0)) {
|
3414 | if (once) {
|
3415 | this._off(eventName, listener);
|
3416 | }
|
3417 | if (external) {
|
3418 | (externalListeners ||= []).push(listener);
|
3419 | continue;
|
3420 | }
|
3421 | listener(data);
|
3422 | }
|
3423 | if (externalListeners) {
|
3424 | for (const listener of externalListeners) {
|
3425 | listener(data);
|
3426 | }
|
3427 | externalListeners = null;
|
3428 | }
|
3429 | }
|
3430 | _on(eventName, listener, options = null) {
|
3431 | const eventListeners = this.#listeners[eventName] ||= [];
|
3432 | eventListeners.push({
|
3433 | listener,
|
3434 | external: options?.external === true,
|
3435 | once: options?.once === true
|
3436 | });
|
3437 | }
|
3438 | _off(eventName, listener, options = null) {
|
3439 | const eventListeners = this.#listeners[eventName];
|
3440 | if (!eventListeners) {
|
3441 | return;
|
3442 | }
|
3443 | for (let i = 0, ii = eventListeners.length; i < ii; i++) {
|
3444 | if (eventListeners[i].listener === listener) {
|
3445 | eventListeners.splice(i, 1);
|
3446 | return;
|
3447 | }
|
3448 | }
|
3449 | }
|
3450 | }
|
3451 | exports.EventBus = EventBus;
|
3452 | class AutomationEventBus extends EventBus {
|
3453 | dispatch(eventName, data) {
|
3454 | throw new Error("Not implemented: AutomationEventBus.dispatch");
|
3455 | }
|
3456 | }
|
3457 | exports.AutomationEventBus = AutomationEventBus;
|
3458 |
|
3459 | }),
|
3460 |
|
3461 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
3462 |
|
3463 |
|
3464 |
|
3465 | Object.defineProperty(exports, "__esModule", ({
|
3466 | value: true
|
3467 | }));
|
3468 | exports.SimpleLinkService = exports.PDFLinkService = exports.LinkTarget = void 0;
|
3469 | var _ui_utils = __webpack_require__(3);
|
3470 | const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
|
3471 | const LinkTarget = {
|
3472 | NONE: 0,
|
3473 | SELF: 1,
|
3474 | BLANK: 2,
|
3475 | PARENT: 3,
|
3476 | TOP: 4
|
3477 | };
|
3478 | exports.LinkTarget = LinkTarget;
|
3479 | function addLinkAttributes(link, {
|
3480 | url,
|
3481 | target,
|
3482 | rel,
|
3483 | enabled = true
|
3484 | } = {}) {
|
3485 | if (!url || typeof url !== "string") {
|
3486 | throw new Error('A valid "url" parameter must provided.');
|
3487 | }
|
3488 | const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
|
3489 | if (enabled) {
|
3490 | link.href = link.title = urlNullRemoved;
|
3491 | } else {
|
3492 | link.href = "";
|
3493 | link.title = `Disabled: ${urlNullRemoved}`;
|
3494 | link.onclick = () => {
|
3495 | return false;
|
3496 | };
|
3497 | }
|
3498 | let targetStr = "";
|
3499 | switch (target) {
|
3500 | case LinkTarget.NONE:
|
3501 | break;
|
3502 | case LinkTarget.SELF:
|
3503 | targetStr = "_self";
|
3504 | break;
|
3505 | case LinkTarget.BLANK:
|
3506 | targetStr = "_blank";
|
3507 | break;
|
3508 | case LinkTarget.PARENT:
|
3509 | targetStr = "_parent";
|
3510 | break;
|
3511 | case LinkTarget.TOP:
|
3512 | targetStr = "_top";
|
3513 | break;
|
3514 | }
|
3515 | link.target = targetStr;
|
3516 | link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
|
3517 | }
|
3518 | class PDFLinkService {
|
3519 | #pagesRefCache = new Map();
|
3520 | constructor({
|
3521 | eventBus,
|
3522 | externalLinkTarget = null,
|
3523 | externalLinkRel = null,
|
3524 | ignoreDestinationZoom = false
|
3525 | } = {}) {
|
3526 | this.eventBus = eventBus;
|
3527 | this.externalLinkTarget = externalLinkTarget;
|
3528 | this.externalLinkRel = externalLinkRel;
|
3529 | this.externalLinkEnabled = true;
|
3530 | this._ignoreDestinationZoom = ignoreDestinationZoom;
|
3531 | this.baseUrl = null;
|
3532 | this.pdfDocument = null;
|
3533 | this.pdfViewer = null;
|
3534 | this.pdfHistory = null;
|
3535 | }
|
3536 | setDocument(pdfDocument, baseUrl = null) {
|
3537 | this.baseUrl = baseUrl;
|
3538 | this.pdfDocument = pdfDocument;
|
3539 | this.#pagesRefCache.clear();
|
3540 | }
|
3541 | setViewer(pdfViewer) {
|
3542 | this.pdfViewer = pdfViewer;
|
3543 | }
|
3544 | setHistory(pdfHistory) {
|
3545 | this.pdfHistory = pdfHistory;
|
3546 | }
|
3547 | get pagesCount() {
|
3548 | return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
3549 | }
|
3550 | get page() {
|
3551 | return this.pdfViewer.currentPageNumber;
|
3552 | }
|
3553 | set page(value) {
|
3554 | this.pdfViewer.currentPageNumber = value;
|
3555 | }
|
3556 | get rotation() {
|
3557 | return this.pdfViewer.pagesRotation;
|
3558 | }
|
3559 | set rotation(value) {
|
3560 | this.pdfViewer.pagesRotation = value;
|
3561 | }
|
3562 | get isInPresentationMode() {
|
3563 | return this.pdfViewer.isInPresentationMode;
|
3564 | }
|
3565 | #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
|
3566 | const destRef = explicitDest[0];
|
3567 | let pageNumber;
|
3568 | if (typeof destRef === "object" && destRef !== null) {
|
3569 | pageNumber = this._cachedPageNumber(destRef);
|
3570 | if (!pageNumber) {
|
3571 | this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
|
3572 | this.cachePageRef(pageIndex + 1, destRef);
|
3573 | this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
|
3574 | }).catch(() => {
|
3575 | Window['ngxConsole'].error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
|
3576 | });
|
3577 | return;
|
3578 | }
|
3579 | } else if (Number.isInteger(destRef)) {
|
3580 | pageNumber = destRef + 1;
|
3581 | } else {
|
3582 | Window['ngxConsole'].error(`PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
|
3583 | return;
|
3584 | }
|
3585 | if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
|
3586 | Window['ngxConsole'].error(`PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
|
3587 | return;
|
3588 | }
|
3589 | if (this.pdfHistory) {
|
3590 | this.pdfHistory.pushCurrentPosition();
|
3591 | this.pdfHistory.push({
|
3592 | namedDest,
|
3593 | explicitDest,
|
3594 | pageNumber
|
3595 | });
|
3596 | }
|
3597 | this.pdfViewer.scrollPageIntoView({
|
3598 | pageNumber,
|
3599 | destArray: explicitDest,
|
3600 | ignoreDestinationZoom: this._ignoreDestinationZoom
|
3601 | });
|
3602 | }
|
3603 | async goToDestination(dest) {
|
3604 | if (!this.pdfDocument) {
|
3605 | return;
|
3606 | }
|
3607 | let namedDest, explicitDest;
|
3608 | if (typeof dest === "string") {
|
3609 | namedDest = dest;
|
3610 | explicitDest = await this.pdfDocument.getDestination(dest);
|
3611 | } else {
|
3612 | namedDest = null;
|
3613 | explicitDest = await dest;
|
3614 | }
|
3615 | if (!Array.isArray(explicitDest)) {
|
3616 | Window['ngxConsole'].error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
|
3617 | return;
|
3618 | }
|
3619 | this.#goToDestinationHelper(dest, namedDest, explicitDest);
|
3620 | }
|
3621 | goToPage(val) {
|
3622 | if (!this.pdfDocument) {
|
3623 | return;
|
3624 | }
|
3625 | const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
|
3626 | if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
|
3627 | Window['ngxConsole'].error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
|
3628 | return;
|
3629 | }
|
3630 | if (this.pdfHistory) {
|
3631 | this.pdfHistory.pushCurrentPosition();
|
3632 | this.pdfHistory.pushPage(pageNumber);
|
3633 | }
|
3634 | if (this.pdfViewer.pageViewMode === "book") {
|
3635 | if (this.pdfViewer.pageFlip) {
|
3636 | this.pdfViewer.ensureAdjecentPagesAreLoaded();
|
3637 | const evenPage = this.pdfViewer.currentPageNumber - this.pdfViewer.currentPageNumber % 2;
|
3638 | const evenTargetPage = pageNumber - pageNumber % 2;
|
3639 | if (evenPage === evenTargetPage - 2) {
|
3640 | this.pdfViewer.pageFlip.flipNext();
|
3641 | } else if (evenPage === evenTargetPage + 2) {
|
3642 | this.pdfViewer.pageFlip.flipPrev();
|
3643 | } else {
|
3644 | this.pdfViewer.pageFlip.turnToPage(pageNumber - 1);
|
3645 | }
|
3646 | }
|
3647 | } else {
|
3648 | this.pdfViewer.scrollPageIntoView({
|
3649 | pageNumber
|
3650 | });
|
3651 | }
|
3652 | }
|
3653 | addLinkAttributes(link, url, newWindow = false) {
|
3654 | addLinkAttributes(link, {
|
3655 | url,
|
3656 | target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
|
3657 | rel: this.externalLinkRel,
|
3658 | enabled: this.externalLinkEnabled
|
3659 | });
|
3660 | }
|
3661 | getDestinationHash(dest) {
|
3662 | if (typeof dest === "string") {
|
3663 | if (dest.length > 0) {
|
3664 | return this.getAnchorUrl("#" + escape(dest));
|
3665 | }
|
3666 | } else if (Array.isArray(dest)) {
|
3667 | const str = JSON.stringify(dest);
|
3668 | if (str.length > 0) {
|
3669 | return this.getAnchorUrl("#" + escape(str));
|
3670 | }
|
3671 | }
|
3672 | return this.getAnchorUrl("");
|
3673 | }
|
3674 | getAnchorUrl(anchor) {
|
3675 | return (this.baseUrl || "") + anchor;
|
3676 | }
|
3677 | setHash(hash) {
|
3678 | if (!this.pdfDocument) {
|
3679 | return;
|
3680 | }
|
3681 | let pageNumber, dest;
|
3682 | if (hash.includes("=")) {
|
3683 | const params = (0, _ui_utils.parseQueryString)(hash);
|
3684 | if (params.has("search")) {
|
3685 | this.eventBus.dispatch("findfromurlhash", {
|
3686 | source: this,
|
3687 | query: params.get("search").replace(/"/g, ""),
|
3688 | phraseSearch: params.get("phrase") === "true"
|
3689 | });
|
3690 | }
|
3691 | if (params.has("page")) {
|
3692 | pageNumber = params.get("page") | 0 || 1;
|
3693 | }
|
3694 | if (params.has("zoom")) {
|
3695 | const zoomArgs = params.get("zoom").split(",");
|
3696 | const zoomArg = zoomArgs[0];
|
3697 | const zoomArgNumber = parseFloat(zoomArg);
|
3698 | if (!zoomArg.includes("Fit")) {
|
3699 | dest = [null, {
|
3700 | name: "XYZ"
|
3701 | }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
|
3702 | } else {
|
3703 | if (zoomArg === "Fit" || zoomArg === "FitB") {
|
3704 | dest = [null, {
|
3705 | name: zoomArg
|
3706 | }];
|
3707 | } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
|
3708 | dest = [null, {
|
3709 | name: zoomArg
|
3710 | }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
|
3711 | } else if (zoomArg === "FitR") {
|
3712 | if (zoomArgs.length !== 5) {
|
3713 | Window['ngxConsole'].error('PDFLinkService.setHash: Not enough parameters for "FitR".');
|
3714 | } else {
|
3715 | dest = [null, {
|
3716 | name: zoomArg
|
3717 | }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
|
3718 | }
|
3719 | } else {
|
3720 | Window['ngxConsole'].error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
|
3721 | }
|
3722 | }
|
3723 | }
|
3724 | if (dest) {
|
3725 | this.pdfViewer.scrollPageIntoView({
|
3726 | pageNumber: pageNumber || this.page,
|
3727 | destArray: dest,
|
3728 | allowNegativeOffset: true
|
3729 | });
|
3730 | } else if (pageNumber) {
|
3731 | this.page = pageNumber;
|
3732 | }
|
3733 | if (params.has("pagemode")) {
|
3734 | this.eventBus.dispatch("pagemode", {
|
3735 | source: this,
|
3736 | mode: params.get("pagemode")
|
3737 | });
|
3738 | }
|
3739 | if (params.has("nameddest")) {
|
3740 | this.goToDestination(params.get("nameddest"));
|
3741 | }
|
3742 | } else {
|
3743 | dest = unescape(hash);
|
3744 | try {
|
3745 | dest = JSON.parse(dest);
|
3746 | if (!Array.isArray(dest)) {
|
3747 | dest = dest.toString();
|
3748 | }
|
3749 | } catch (ex) {}
|
3750 | if (typeof dest === "string" || PDFLinkService.#isValidExplicitDestination(dest)) {
|
3751 | this.goToDestination(dest);
|
3752 | return;
|
3753 | }
|
3754 | Window['ngxConsole'].error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
|
3755 | }
|
3756 | }
|
3757 | executeNamedAction(action) {
|
3758 | switch (action) {
|
3759 | case "GoBack":
|
3760 | this.pdfHistory?.back();
|
3761 | break;
|
3762 | case "GoForward":
|
3763 | this.pdfHistory?.forward();
|
3764 | break;
|
3765 | case "NextPage":
|
3766 | this.pdfViewer.nextPage();
|
3767 | break;
|
3768 | case "PrevPage":
|
3769 | this.pdfViewer.previousPage();
|
3770 | break;
|
3771 | case "LastPage":
|
3772 | this.page = this.pagesCount;
|
3773 | break;
|
3774 | case "FirstPage":
|
3775 | this.page = 1;
|
3776 | break;
|
3777 | default:
|
3778 | break;
|
3779 | }
|
3780 | this.eventBus.dispatch("namedaction", {
|
3781 | source: this,
|
3782 | action
|
3783 | });
|
3784 | }
|
3785 | async executeSetOCGState(action) {
|
3786 | const pdfDocument = this.pdfDocument;
|
3787 | const optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
|
3788 | if (pdfDocument !== this.pdfDocument) {
|
3789 | return;
|
3790 | }
|
3791 | let operator;
|
3792 | for (const elem of action.state) {
|
3793 | switch (elem) {
|
3794 | case "ON":
|
3795 | case "OFF":
|
3796 | case "Toggle":
|
3797 | operator = elem;
|
3798 | continue;
|
3799 | }
|
3800 | switch (operator) {
|
3801 | case "ON":
|
3802 | optionalContentConfig.setVisibility(elem, true);
|
3803 | break;
|
3804 | case "OFF":
|
3805 | optionalContentConfig.setVisibility(elem, false);
|
3806 | break;
|
3807 | case "Toggle":
|
3808 | const group = optionalContentConfig.getGroup(elem);
|
3809 | if (group) {
|
3810 | optionalContentConfig.setVisibility(elem, !group.visible);
|
3811 | }
|
3812 | break;
|
3813 | }
|
3814 | }
|
3815 | this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
|
3816 | }
|
3817 | cachePageRef(pageNum, pageRef) {
|
3818 | if (!pageRef) {
|
3819 | return;
|
3820 | }
|
3821 | const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
|
3822 | this.#pagesRefCache.set(refStr, pageNum);
|
3823 | }
|
3824 | _cachedPageNumber(pageRef) {
|
3825 | if (!pageRef) {
|
3826 | return null;
|
3827 | }
|
3828 | const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
|
3829 | return this.#pagesRefCache.get(refStr) || null;
|
3830 | }
|
3831 | isPageVisible(pageNumber) {
|
3832 | return this.pdfViewer.isPageVisible(pageNumber);
|
3833 | }
|
3834 | isPageCached(pageNumber) {
|
3835 | return this.pdfViewer.isPageCached(pageNumber);
|
3836 | }
|
3837 | static #isValidExplicitDestination(dest) {
|
3838 | if (!Array.isArray(dest)) {
|
3839 | return false;
|
3840 | }
|
3841 | const destLength = dest.length;
|
3842 | if (destLength < 2) {
|
3843 | return false;
|
3844 | }
|
3845 | const page = dest[0];
|
3846 | if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
|
3847 | return false;
|
3848 | }
|
3849 | const zoom = dest[1];
|
3850 | if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
|
3851 | return false;
|
3852 | }
|
3853 | let allowNull = true;
|
3854 | switch (zoom.name) {
|
3855 | case "XYZ":
|
3856 | if (destLength !== 5) {
|
3857 | return false;
|
3858 | }
|
3859 | break;
|
3860 | case "Fit":
|
3861 | case "FitB":
|
3862 | return destLength === 2;
|
3863 | case "FitH":
|
3864 | case "FitBH":
|
3865 | case "FitV":
|
3866 | case "FitBV":
|
3867 | if (destLength !== 3) {
|
3868 | return false;
|
3869 | }
|
3870 | break;
|
3871 | case "FitR":
|
3872 | if (destLength !== 6) {
|
3873 | return false;
|
3874 | }
|
3875 | allowNull = false;
|
3876 | break;
|
3877 | default:
|
3878 | return false;
|
3879 | }
|
3880 | for (let i = 2; i < destLength; i++) {
|
3881 | const param = dest[i];
|
3882 | if (!(typeof param === "number" || allowNull && param === null)) {
|
3883 | return false;
|
3884 | }
|
3885 | }
|
3886 | return true;
|
3887 | }
|
3888 | }
|
3889 | exports.PDFLinkService = PDFLinkService;
|
3890 | class SimpleLinkService {
|
3891 | constructor() {
|
3892 | this.externalLinkEnabled = true;
|
3893 | }
|
3894 | get pagesCount() {
|
3895 | return 0;
|
3896 | }
|
3897 | get page() {
|
3898 | return 0;
|
3899 | }
|
3900 | set page(value) {}
|
3901 | get rotation() {
|
3902 | return 0;
|
3903 | }
|
3904 | set rotation(value) {}
|
3905 | get isInPresentationMode() {
|
3906 | return false;
|
3907 | }
|
3908 | async goToDestination(dest) {}
|
3909 | goToPage(val) {}
|
3910 | addLinkAttributes(link, url, newWindow = false) {
|
3911 | addLinkAttributes(link, {
|
3912 | url,
|
3913 | enabled: this.externalLinkEnabled
|
3914 | });
|
3915 | }
|
3916 | getDestinationHash(dest) {
|
3917 | return "#";
|
3918 | }
|
3919 | getAnchorUrl(hash) {
|
3920 | return "#";
|
3921 | }
|
3922 | setHash(hash) {}
|
3923 | executeNamedAction(action) {}
|
3924 | executeSetOCGState(action) {}
|
3925 | cachePageRef(pageNum, pageRef) {}
|
3926 | isPageVisible(pageNumber) {
|
3927 | return true;
|
3928 | }
|
3929 | isPageCached(pageNumber) {
|
3930 | return true;
|
3931 | }
|
3932 | }
|
3933 | exports.SimpleLinkService = SimpleLinkService;
|
3934 |
|
3935 | }),
|
3936 |
|
3937 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
3938 |
|
3939 |
|
3940 |
|
3941 | Object.defineProperty(exports, "__esModule", ({
|
3942 | value: true
|
3943 | }));
|
3944 | exports.AnnotationEditorParams = void 0;
|
3945 | var _pdfjsLib = __webpack_require__(4);
|
3946 | class AnnotationEditorParams {
|
3947 | constructor(options, eventBus) {
|
3948 | this.eventBus = eventBus;
|
3949 | this.#bindListeners(options);
|
3950 | }
|
3951 | #bindListeners({
|
3952 | editorFreeTextFontSize,
|
3953 | editorFreeTextColor,
|
3954 | editorInkColor,
|
3955 | editorInkThickness,
|
3956 | editorInkOpacity
|
3957 | }) {
|
3958 | editorFreeTextFontSize.addEventListener("input", evt => {
|
3959 | this.eventBus.dispatch("switchannotationeditorparams", {
|
3960 | source: this,
|
3961 | type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE,
|
3962 | value: editorFreeTextFontSize.valueAsNumber
|
3963 | });
|
3964 | });
|
3965 | editorFreeTextColor.addEventListener("input", evt => {
|
3966 | this.eventBus.dispatch("switchannotationeditorparams", {
|
3967 | source: this,
|
3968 | type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
|
3969 | value: editorFreeTextColor.value
|
3970 | });
|
3971 | });
|
3972 | editorInkColor.addEventListener("input", evt => {
|
3973 | this.eventBus.dispatch("switchannotationeditorparams", {
|
3974 | source: this,
|
3975 | type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR,
|
3976 | value: editorInkColor.value
|
3977 | });
|
3978 | });
|
3979 | editorInkThickness.addEventListener("input", evt => {
|
3980 | this.eventBus.dispatch("switchannotationeditorparams", {
|
3981 | source: this,
|
3982 | type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS,
|
3983 | value: editorInkThickness.valueAsNumber
|
3984 | });
|
3985 | });
|
3986 | editorInkOpacity.addEventListener("input", evt => {
|
3987 | this.eventBus.dispatch("switchannotationeditorparams", {
|
3988 | source: this,
|
3989 | type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY,
|
3990 | value: editorInkOpacity.valueAsNumber
|
3991 | });
|
3992 | });
|
3993 | this.eventBus._on("annotationeditorparamschanged", evt => {
|
3994 | for (const [type, value] of evt.details) {
|
3995 | switch (type) {
|
3996 | case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
|
3997 | editorFreeTextFontSize.value = value;
|
3998 | break;
|
3999 | case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
|
4000 | editorFreeTextColor.value = value;
|
4001 | break;
|
4002 | case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
|
4003 | editorInkColor.value = value;
|
4004 | break;
|
4005 | case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
|
4006 | editorInkThickness.value = value;
|
4007 | break;
|
4008 | case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
|
4009 | editorInkOpacity.value = value;
|
4010 | break;
|
4011 | }
|
4012 | }
|
4013 | });
|
4014 | }
|
4015 | }
|
4016 | exports.AnnotationEditorParams = AnnotationEditorParams;
|
4017 |
|
4018 | }),
|
4019 |
|
4020 | ((__unused_webpack_module, exports) => {
|
4021 |
|
4022 |
|
4023 |
|
4024 | Object.defineProperty(exports, "__esModule", ({
|
4025 | value: true
|
4026 | }));
|
4027 | exports.OverlayManager = void 0;
|
4028 | class OverlayManager {
|
4029 | #overlays = new WeakMap();
|
4030 | #active = null;
|
4031 | get active() {
|
4032 | return this.#active;
|
4033 | }
|
4034 | async register(dialog, canForceClose = false) {
|
4035 | if (typeof dialog !== "object") {
|
4036 | throw new Error("Not enough parameters.");
|
4037 | } else if (this.#overlays.has(dialog)) {
|
4038 | throw new Error("The overlay is already registered.");
|
4039 | }
|
4040 | this.#overlays.set(dialog, {
|
4041 | canForceClose
|
4042 | });
|
4043 | dialog.addEventListener("cancel", evt => {
|
4044 | this.#active = null;
|
4045 | });
|
4046 | }
|
4047 | async unregister(dialog) {
|
4048 | if (!this.#overlays.has(dialog)) {
|
4049 | throw new Error("The overlay does not exist.");
|
4050 | } else if (this.#active === dialog) {
|
4051 | throw new Error("The overlay cannot be removed while it is active.");
|
4052 | }
|
4053 | this.#overlays.delete(dialog);
|
4054 | }
|
4055 | async open(dialog) {
|
4056 | if (!this.#overlays.has(dialog)) {
|
4057 | throw new Error("The overlay does not exist.");
|
4058 | } else if (this.#active) {
|
4059 | if (this.#active === dialog) {
|
4060 | throw new Error("The overlay is already active.");
|
4061 | } else if (this.#overlays.get(dialog).canForceClose) {
|
4062 | await this.close();
|
4063 | } else {
|
4064 | throw new Error("Another overlay is currently active.");
|
4065 | }
|
4066 | }
|
4067 | this.#active = dialog;
|
4068 | dialog.showModal();
|
4069 | dialog.classList.remove("hidden");
|
4070 | }
|
4071 | async close(dialog = this.#active) {
|
4072 | if (!this.#overlays.has(dialog)) {
|
4073 | throw new Error("The overlay does not exist.");
|
4074 | } else if (!this.#active) {
|
4075 | throw new Error("The overlay is currently not active.");
|
4076 | } else if (this.#active !== dialog) {
|
4077 | throw new Error("Another overlay is currently active.");
|
4078 | }
|
4079 | dialog.close();
|
4080 | this.#active = null;
|
4081 | }
|
4082 | }
|
4083 | exports.OverlayManager = OverlayManager;
|
4084 |
|
4085 | }),
|
4086 |
|
4087 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
4088 |
|
4089 |
|
4090 |
|
4091 | Object.defineProperty(exports, "__esModule", ({
|
4092 | value: true
|
4093 | }));
|
4094 | exports.PasswordPrompt = void 0;
|
4095 | var _pdfjsLib = __webpack_require__(4);
|
4096 | class PasswordPrompt {
|
4097 | #activeCapability = null;
|
4098 | #updateCallback = null;
|
4099 | #reason = null;
|
4100 | constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
|
4101 | this.dialog = options.dialog;
|
4102 | this.label = options.label;
|
4103 | this.input = options.input;
|
4104 | this.submitButton = options.submitButton;
|
4105 | this.cancelButton = options.cancelButton;
|
4106 | this.overlayManager = overlayManager;
|
4107 | this.l10n = l10n;
|
4108 | this._isViewerEmbedded = isViewerEmbedded;
|
4109 | this.submitButton.addEventListener("click", this.#verify.bind(this));
|
4110 | this.cancelButton.addEventListener("click", this.close.bind(this));
|
4111 | this.input.addEventListener("keydown", e => {
|
4112 | if (e.keyCode === 13) {
|
4113 | this.#verify();
|
4114 | }
|
4115 | });
|
4116 | this.overlayManager.register(this.dialog, true);
|
4117 | this.dialog.addEventListener("close", this.#cancel.bind(this));
|
4118 | }
|
4119 | async open() {
|
4120 | if (this.#activeCapability) {
|
4121 | await this.#activeCapability.promise;
|
4122 | }
|
4123 | this.#activeCapability = (0, _pdfjsLib.createPromiseCapability)();
|
4124 | try {
|
4125 | await this.overlayManager.open(this.dialog);
|
4126 | this.input.type = "password";
|
4127 | this.input.focus();
|
4128 | } catch (ex) {
|
4129 | this.#activeCapability = null;
|
4130 | throw ex;
|
4131 | }
|
4132 | const passwordIncorrect = this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
|
4133 | if (!this._isViewerEmbedded || passwordIncorrect) {
|
4134 | this.input.focus();
|
4135 | }
|
4136 | this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
|
4137 | }
|
4138 | async close() {
|
4139 | if (this.overlayManager.active === this.dialog) {
|
4140 | this.overlayManager.close(this.dialog);
|
4141 | this.input.value = "";
|
4142 | this.input.type = "hidden";
|
4143 | }
|
4144 | }
|
4145 | #verify() {
|
4146 | const password = this.input.value;
|
4147 | if (password?.length > 0) {
|
4148 | this.#invokeCallback(password);
|
4149 | }
|
4150 | }
|
4151 | #cancel() {
|
4152 | this.#invokeCallback(new Error("PasswordPrompt cancelled."));
|
4153 | this.#activeCapability.resolve();
|
4154 | }
|
4155 | #invokeCallback(password) {
|
4156 | if (!this.#updateCallback) {
|
4157 | return;
|
4158 | }
|
4159 | this.close();
|
4160 | this.input.value = "";
|
4161 | this.#updateCallback(password);
|
4162 | this.#updateCallback = null;
|
4163 | }
|
4164 | async setUpdateCallback(updateCallback, reason) {
|
4165 | if (this.#activeCapability) {
|
4166 | await this.#activeCapability.promise;
|
4167 | }
|
4168 | this.#updateCallback = updateCallback;
|
4169 | this.#reason = reason;
|
4170 | }
|
4171 | }
|
4172 | exports.PasswordPrompt = PasswordPrompt;
|
4173 |
|
4174 | }),
|
4175 |
|
4176 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
4177 |
|
4178 |
|
4179 |
|
4180 | Object.defineProperty(exports, "__esModule", ({
|
4181 | value: true
|
4182 | }));
|
4183 | exports.PDFAttachmentViewer = void 0;
|
4184 | var _pdfjsLib = __webpack_require__(4);
|
4185 | var _base_tree_viewer = __webpack_require__(12);
|
4186 | var _event_utils = __webpack_require__(6);
|
4187 | class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
|
4188 | constructor(options) {
|
4189 | super(options);
|
4190 | this.downloadManager = options.downloadManager;
|
4191 | this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this));
|
4192 | }
|
4193 | reset(keepRenderedCapability = false) {
|
4194 | super.reset();
|
4195 | this._attachments = null;
|
4196 | if (!keepRenderedCapability) {
|
4197 | this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
|
4198 | }
|
4199 | this._pendingDispatchEvent = false;
|
4200 | }
|
4201 | async _dispatchEvent(attachmentsCount) {
|
4202 | this._renderedCapability.resolve();
|
4203 | if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
|
4204 | this._pendingDispatchEvent = true;
|
4205 | await (0, _event_utils.waitOnEventOrTimeout)({
|
4206 | target: this.eventBus,
|
4207 | name: "annotationlayerrendered",
|
4208 | delay: 1000
|
4209 | });
|
4210 | if (!this._pendingDispatchEvent) {
|
4211 | return;
|
4212 | }
|
4213 | }
|
4214 | this._pendingDispatchEvent = false;
|
4215 | this.eventBus.dispatch("attachmentsloaded", {
|
4216 | source: this,
|
4217 | attachmentsCount
|
4218 | });
|
4219 | }
|
4220 | _bindLink(element, {
|
4221 | content,
|
4222 | filename
|
4223 | }) {
|
4224 | element.onclick = () => {
|
4225 | this.downloadManager.openOrDownloadData(element, content, filename);
|
4226 | return false;
|
4227 | };
|
4228 | }
|
4229 | render({
|
4230 | attachments,
|
4231 | keepRenderedCapability = false
|
4232 | }) {
|
4233 | if (this._attachments) {
|
4234 | this.reset(keepRenderedCapability);
|
4235 | }
|
4236 | this._attachments = attachments || null;
|
4237 | if (!attachments) {
|
4238 | this._dispatchEvent(0);
|
4239 | return;
|
4240 | }
|
4241 | const names = Object.keys(attachments).sort(function (a, b) {
|
4242 | return a.toLowerCase().localeCompare(b.toLowerCase());
|
4243 | });
|
4244 | const fragment = document.createDocumentFragment();
|
4245 | let attachmentsCount = 0;
|
4246 | for (const name of names) {
|
4247 | const item = attachments[name];
|
4248 | const content = item.content,
|
4249 | filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
|
4250 | const div = document.createElement("div");
|
4251 | div.className = "treeItem";
|
4252 | const element = document.createElement("a");
|
4253 | this._bindLink(element, {
|
4254 | content,
|
4255 | filename
|
4256 | });
|
4257 | element.textContent = this._normalizeTextContent(filename);
|
4258 | div.append(element);
|
4259 | fragment.append(div);
|
4260 | attachmentsCount++;
|
4261 | }
|
4262 | this._finishRendering(fragment, attachmentsCount);
|
4263 | }
|
4264 | #appendAttachment({
|
4265 | filename,
|
4266 | content
|
4267 | }) {
|
4268 | const renderedPromise = this._renderedCapability.promise;
|
4269 | renderedPromise.then(() => {
|
4270 | if (renderedPromise !== this._renderedCapability.promise) {
|
4271 | return;
|
4272 | }
|
4273 | const attachments = this._attachments || Object.create(null);
|
4274 | for (const name in attachments) {
|
4275 | if (filename === name) {
|
4276 | return;
|
4277 | }
|
4278 | }
|
4279 | attachments[filename] = {
|
4280 | filename,
|
4281 | content
|
4282 | };
|
4283 | this.render({
|
4284 | attachments,
|
4285 | keepRenderedCapability: true
|
4286 | });
|
4287 | });
|
4288 | }
|
4289 | }
|
4290 | exports.PDFAttachmentViewer = PDFAttachmentViewer;
|
4291 |
|
4292 | }),
|
4293 |
|
4294 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
4295 |
|
4296 |
|
4297 |
|
4298 | Object.defineProperty(exports, "__esModule", ({
|
4299 | value: true
|
4300 | }));
|
4301 | exports.BaseTreeViewer = void 0;
|
4302 | var _ui_utils = __webpack_require__(3);
|
4303 | const TREEITEM_OFFSET_TOP = -100;
|
4304 | const TREEITEM_SELECTED_CLASS = "selected";
|
4305 | class BaseTreeViewer {
|
4306 | constructor(options) {
|
4307 | if (this.constructor === BaseTreeViewer) {
|
4308 | throw new Error("Cannot initialize BaseTreeViewer.");
|
4309 | }
|
4310 | this.container = options.container;
|
4311 | this.eventBus = options.eventBus;
|
4312 | this.reset();
|
4313 | }
|
4314 | reset() {
|
4315 | this._pdfDocument = null;
|
4316 | this._lastToggleIsShow = true;
|
4317 | this._currentTreeItem = null;
|
4318 | this.container.textContent = "";
|
4319 | this.container.classList.remove("treeWithDeepNesting");
|
4320 | }
|
4321 | _dispatchEvent(count) {
|
4322 | throw new Error("Not implemented: _dispatchEvent");
|
4323 | }
|
4324 | _bindLink(element, params) {
|
4325 | throw new Error("Not implemented: _bindLink");
|
4326 | }
|
4327 | _normalizeTextContent(str) {
|
4328 | return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
|
4329 | }
|
4330 | _addToggleButton(div, hidden = false) {
|
4331 | const toggler = document.createElement("div");
|
4332 | toggler.className = "treeItemToggler";
|
4333 | if (hidden) {
|
4334 | toggler.classList.add("treeItemsHidden");
|
4335 | }
|
4336 | toggler.onclick = evt => {
|
4337 | evt.stopPropagation();
|
4338 | toggler.classList.toggle("treeItemsHidden");
|
4339 | if (evt.shiftKey) {
|
4340 | const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
|
4341 | this._toggleTreeItem(div, shouldShowAll);
|
4342 | }
|
4343 | };
|
4344 | div.prepend(toggler);
|
4345 | }
|
4346 | _toggleTreeItem(root, show = false) {
|
4347 | this._lastToggleIsShow = show;
|
4348 | for (const toggler of root.querySelectorAll(".treeItemToggler")) {
|
4349 | toggler.classList.toggle("treeItemsHidden", !show);
|
4350 | }
|
4351 | }
|
4352 | _toggleAllTreeItems() {
|
4353 | this._toggleTreeItem(this.container, !this._lastToggleIsShow);
|
4354 | }
|
4355 | _finishRendering(fragment, count, hasAnyNesting = false) {
|
4356 | if (hasAnyNesting) {
|
4357 | this.container.classList.add("treeWithDeepNesting");
|
4358 | this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
|
4359 | }
|
4360 | this.container.append(fragment);
|
4361 | this._dispatchEvent(count);
|
4362 | }
|
4363 | render(params) {
|
4364 | throw new Error("Not implemented: render");
|
4365 | }
|
4366 | _updateCurrentTreeItem(treeItem = null) {
|
4367 | if (this._currentTreeItem) {
|
4368 | this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
|
4369 | this._currentTreeItem = null;
|
4370 | }
|
4371 | if (treeItem) {
|
4372 | treeItem.classList.add(TREEITEM_SELECTED_CLASS);
|
4373 | this._currentTreeItem = treeItem;
|
4374 | }
|
4375 | }
|
4376 | _scrollToCurrentTreeItem(treeItem) {
|
4377 | if (!treeItem) {
|
4378 | return;
|
4379 | }
|
4380 | let currentNode = treeItem.parentNode;
|
4381 | while (currentNode && currentNode !== this.container) {
|
4382 | if (currentNode.classList.contains("treeItem")) {
|
4383 | const toggler = currentNode.firstElementChild;
|
4384 | toggler?.classList.remove("treeItemsHidden");
|
4385 | }
|
4386 | currentNode = currentNode.parentNode;
|
4387 | }
|
4388 | this._updateCurrentTreeItem(treeItem);
|
4389 | this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
|
4390 | }
|
4391 | }
|
4392 | exports.BaseTreeViewer = BaseTreeViewer;
|
4393 |
|
4394 | }),
|
4395 |
|
4396 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
4397 |
|
4398 |
|
4399 |
|
4400 | Object.defineProperty(exports, "__esModule", ({
|
4401 | value: true
|
4402 | }));
|
4403 | exports.PDFCursorTools = void 0;
|
4404 | var _ui_utils = __webpack_require__(3);
|
4405 | var _pdfjsLib = __webpack_require__(4);
|
4406 | var _grab_to_pan = __webpack_require__(14);
|
4407 | class PDFCursorTools {
|
4408 | constructor({
|
4409 | container,
|
4410 | eventBus,
|
4411 | cursorToolOnLoad = _ui_utils.CursorTool.SELECT
|
4412 | }) {
|
4413 | this.container = container;
|
4414 | this.eventBus = eventBus;
|
4415 | this.active = _ui_utils.CursorTool.SELECT;
|
4416 | this.previouslyActive = null;
|
4417 | this.handTool = new _grab_to_pan.GrabToPan({
|
4418 | element: this.container
|
4419 | });
|
4420 | this.#addEventListeners();
|
4421 | Promise.resolve().then(() => {
|
4422 | this.switchTool(cursorToolOnLoad);
|
4423 | });
|
4424 | }
|
4425 | get activeTool() {
|
4426 | return this.active;
|
4427 | }
|
4428 | switchTool(tool) {
|
4429 | if (this.previouslyActive !== null) {
|
4430 | return;
|
4431 | }
|
4432 | if (tool === this.active) {
|
4433 | return;
|
4434 | }
|
4435 | const disableActiveTool = () => {
|
4436 | switch (this.active) {
|
4437 | case _ui_utils.CursorTool.SELECT:
|
4438 | break;
|
4439 | case _ui_utils.CursorTool.HAND:
|
4440 | this.handTool.deactivate();
|
4441 | break;
|
4442 | case _ui_utils.CursorTool.ZOOM:
|
4443 | }
|
4444 | };
|
4445 | switch (tool) {
|
4446 | case _ui_utils.CursorTool.SELECT:
|
4447 | disableActiveTool();
|
4448 | break;
|
4449 | case _ui_utils.CursorTool.HAND:
|
4450 | disableActiveTool();
|
4451 | this.handTool.activate();
|
4452 | break;
|
4453 | case _ui_utils.CursorTool.ZOOM:
|
4454 | default:
|
4455 | Window['ngxConsole'].error(`switchTool: "${tool}" is an unsupported value.`);
|
4456 | return;
|
4457 | }
|
4458 | this.active = tool;
|
4459 | this.#dispatchEvent();
|
4460 | }
|
4461 | #dispatchEvent() {
|
4462 | this.eventBus.dispatch("cursortoolchanged", {
|
4463 | source: this,
|
4464 | tool: this.active
|
4465 | });
|
4466 | }
|
4467 | #addEventListeners() {
|
4468 | this.eventBus._on("switchcursortool", evt => {
|
4469 | this.switchTool(evt.tool);
|
4470 | });
|
4471 | let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
|
4472 | presentationModeState = _ui_utils.PresentationModeState.NORMAL;
|
4473 | const disableActive = () => {
|
4474 | const previouslyActive = this.active;
|
4475 | this.switchTool(_ui_utils.CursorTool.SELECT);
|
4476 | this.previouslyActive ??= previouslyActive;
|
4477 | };
|
4478 | const enableActive = () => {
|
4479 | const previouslyActive = this.previouslyActive;
|
4480 | if (previouslyActive !== null && annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE && presentationModeState === _ui_utils.PresentationModeState.NORMAL) {
|
4481 | this.previouslyActive = null;
|
4482 | this.switchTool(previouslyActive);
|
4483 | }
|
4484 | };
|
4485 | this.eventBus._on("secondarytoolbarreset", evt => {
|
4486 | if (this.previouslyActive !== null) {
|
4487 | annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
|
4488 | presentationModeState = _ui_utils.PresentationModeState.NORMAL;
|
4489 | enableActive();
|
4490 | }
|
4491 | });
|
4492 | this.eventBus._on("annotationeditormodechanged", ({
|
4493 | mode
|
4494 | }) => {
|
4495 | annotationEditorMode = mode;
|
4496 | if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
|
4497 | enableActive();
|
4498 | } else {
|
4499 | disableActive();
|
4500 | }
|
4501 | });
|
4502 | this.eventBus._on("presentationmodechanged", ({
|
4503 | state
|
4504 | }) => {
|
4505 | presentationModeState = state;
|
4506 | if (state === _ui_utils.PresentationModeState.NORMAL) {
|
4507 | enableActive();
|
4508 | } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
|
4509 | disableActive();
|
4510 | }
|
4511 | });
|
4512 | }
|
4513 | }
|
4514 | exports.PDFCursorTools = PDFCursorTools;
|
4515 |
|
4516 | }),
|
4517 |
|
4518 | ((__unused_webpack_module, exports) => {
|
4519 |
|
4520 |
|
4521 |
|
4522 | Object.defineProperty(exports, "__esModule", ({
|
4523 | value: true
|
4524 | }));
|
4525 | exports.GrabToPan = void 0;
|
4526 | const CSS_CLASS_GRAB = "grab-to-pan-grab";
|
4527 | class GrabToPan {
|
4528 | constructor(options) {
|
4529 | this.element = options.element;
|
4530 | this.document = options.element.ownerDocument;
|
4531 | if (typeof options.ignoreTarget === "function") {
|
4532 | this.ignoreTarget = options.ignoreTarget;
|
4533 | }
|
4534 | this.onActiveChanged = options.onActiveChanged;
|
4535 | this.activate = this.activate.bind(this);
|
4536 | this.deactivate = this.deactivate.bind(this);
|
4537 | this.toggle = this.toggle.bind(this);
|
4538 | this._onMouseDown = this.#onMouseDown.bind(this);
|
4539 | this._onMouseMove = this.#onMouseMove.bind(this);
|
4540 | this._endPan = this.#endPan.bind(this);
|
4541 | const overlay = this.overlay = document.createElement("div");
|
4542 | overlay.className = "grab-to-pan-grabbing";
|
4543 | }
|
4544 | activate() {
|
4545 | if (!this.active) {
|
4546 | this.active = true;
|
4547 | this.element.addEventListener("mousedown", this._onMouseDown);
|
4548 | this.element.classList.add(CSS_CLASS_GRAB);
|
4549 | this.onActiveChanged?.(true);
|
4550 | }
|
4551 | }
|
4552 | deactivate() {
|
4553 | if (this.active) {
|
4554 | this.active = false;
|
4555 | this.element.removeEventListener("mousedown", this._onMouseDown);
|
4556 | this._endPan();
|
4557 | this.element.classList.remove(CSS_CLASS_GRAB);
|
4558 | this.onActiveChanged?.(false);
|
4559 | }
|
4560 | }
|
4561 | toggle() {
|
4562 | if (this.active) {
|
4563 | this.deactivate();
|
4564 | } else {
|
4565 | this.activate();
|
4566 | }
|
4567 | }
|
4568 | ignoreTarget(node) {
|
4569 | if (document.querySelector(".stf__item")) {
|
4570 | return true;
|
4571 | }
|
4572 | return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
|
4573 | }
|
4574 | #onMouseDown(event) {
|
4575 | if (event.button !== 0 || this.ignoreTarget(event.target)) {
|
4576 | return;
|
4577 | }
|
4578 | if (event.originalTarget) {
|
4579 | try {
|
4580 | event.originalTarget.tagName;
|
4581 | } catch (e) {
|
4582 | return;
|
4583 | }
|
4584 | }
|
4585 | this.scrollLeftStart = this.element.scrollLeft;
|
4586 | this.scrollTopStart = this.element.scrollTop;
|
4587 | this.clientXStart = event.clientX;
|
4588 | this.clientYStart = event.clientY;
|
4589 | if (isOverPerfectScrollbar(this.clientXStart, this.clientYStart, "ps__rail-x")) {
|
4590 | return;
|
4591 | }
|
4592 | if (isOverPerfectScrollbar(this.clientXStart, this.clientYStart, "ps__rail-y")) {
|
4593 | return;
|
4594 | }
|
4595 | this.document.addEventListener("mousemove", this._onMouseMove, true);
|
4596 | this.document.addEventListener("mouseup", this._endPan, true);
|
4597 | this.element.addEventListener("scroll", this._endPan, true);
|
4598 | event.preventDefault();
|
4599 | event.stopPropagation();
|
4600 | const focusedElement = document.activeElement;
|
4601 | if (focusedElement && !focusedElement.contains(event.target)) {
|
4602 | focusedElement.blur();
|
4603 | }
|
4604 | }
|
4605 | #onMouseMove(event) {
|
4606 | this.element.removeEventListener("scroll", this._endPan, true);
|
4607 | if (!(event.buttons & 1)) {
|
4608 | this._endPan();
|
4609 | return;
|
4610 | }
|
4611 | const xDiff = event.clientX - this.clientXStart;
|
4612 | const yDiff = event.clientY - this.clientYStart;
|
4613 | const scrollTop = this.scrollTopStart - yDiff;
|
4614 | const scrollLeft = this.scrollLeftStart - xDiff;
|
4615 | if (this.element.scrollTo) {
|
4616 | this.element.scrollTo({
|
4617 | top: scrollTop,
|
4618 | left: scrollLeft,
|
4619 | behavior: "instant"
|
4620 | });
|
4621 | } else {
|
4622 | this.element.scrollTop = scrollTop;
|
4623 | this.element.scrollLeft = scrollLeft;
|
4624 | }
|
4625 | if (!this.overlay.parentNode) {
|
4626 | document.body.append(this.overlay);
|
4627 | }
|
4628 | }
|
4629 | #endPan() {
|
4630 | this.element.removeEventListener("scroll", this._endPan, true);
|
4631 | this.document.removeEventListener("mousemove", this._onMouseMove, true);
|
4632 | this.document.removeEventListener("mouseup", this._endPan, true);
|
4633 | this.overlay.remove();
|
4634 | }
|
4635 | }
|
4636 | exports.GrabToPan = GrabToPan;
|
4637 | function isOverPerfectScrollbar(x, y, divName) {
|
4638 | const perfectScrollbar = document.getElementsByClassName(divName);
|
4639 | if (perfectScrollbar && perfectScrollbar.length === 1) {
|
4640 | var {
|
4641 | top,
|
4642 | right,
|
4643 | bottom,
|
4644 | left
|
4645 | } = perfectScrollbar[0].getBoundingClientRect();
|
4646 | if (y >= top && y <= bottom) {
|
4647 | if (x <= right && x >= left) {
|
4648 | return true;
|
4649 | }
|
4650 | }
|
4651 | }
|
4652 | return false;
|
4653 | }
|
4654 |
|
4655 | }),
|
4656 |
|
4657 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
4658 |
|
4659 |
|
4660 |
|
4661 | Object.defineProperty(exports, "__esModule", ({
|
4662 | value: true
|
4663 | }));
|
4664 | exports.PDFDocumentProperties = void 0;
|
4665 | var _pdfjsLib = __webpack_require__(4);
|
4666 | var _ui_utils = __webpack_require__(3);
|
4667 | const DEFAULT_FIELD_CONTENT = "-";
|
4668 | const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
|
4669 | const US_PAGE_NAMES = {
|
4670 | "8.5x11": "Letter",
|
4671 | "8.5x14": "Legal"
|
4672 | };
|
4673 | const METRIC_PAGE_NAMES = {
|
4674 | "297x420": "A3",
|
4675 | "210x297": "A4"
|
4676 | };
|
4677 | function getPageName(size, isPortrait, pageNames) {
|
4678 | const width = isPortrait ? size.width : size.height;
|
4679 | const height = isPortrait ? size.height : size.width;
|
4680 | return pageNames[`${width}x${height}`];
|
4681 | }
|
4682 | class PDFDocumentProperties {
|
4683 | #fieldData = null;
|
4684 | constructor({
|
4685 | dialog,
|
4686 | fields,
|
4687 | closeButton
|
4688 | }, overlayManager, eventBus, l10n, fileNameLookup) {
|
4689 | this.dialog = dialog;
|
4690 | this.fields = fields;
|
4691 | this.overlayManager = overlayManager;
|
4692 | this.l10n = l10n;
|
4693 | this._fileNameLookup = fileNameLookup;
|
4694 | this.#reset();
|
4695 | closeButton.addEventListener("click", this.close.bind(this));
|
4696 | this.overlayManager.register(this.dialog);
|
4697 | eventBus._on("pagechanging", evt => {
|
4698 | this._currentPageNumber = evt.pageNumber;
|
4699 | });
|
4700 | eventBus._on("rotationchanging", evt => {
|
4701 | this._pagesRotation = evt.pagesRotation;
|
4702 | });
|
4703 | this._isNonMetricLocale = true;
|
4704 | l10n.getLanguage().then(locale => {
|
4705 | this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
|
4706 | });
|
4707 | }
|
4708 | async open() {
|
4709 | await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]);
|
4710 | const currentPageNumber = this._currentPageNumber;
|
4711 | const pagesRotation = this._pagesRotation;
|
4712 | if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) {
|
4713 | this.#updateUI();
|
4714 | return;
|
4715 | }
|
4716 | const {
|
4717 | info,
|
4718 | contentLength
|
4719 | } = await this.pdfDocument.getMetadata();
|
4720 | const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([this._fileNameLookup(), this.#parseFileSize(contentLength), this.#parseDate(info.CreationDate), this.#parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
|
4721 | return this.#parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
|
4722 | }), this.#parseLinearization(info.IsLinearized)]);
|
4723 | this.#fieldData = Object.freeze({
|
4724 | fileName,
|
4725 | fileSize,
|
4726 | title: info.Title,
|
4727 | author: info.Author,
|
4728 | subject: info.Subject,
|
4729 | keywords: info.Keywords,
|
4730 | creationDate,
|
4731 | modificationDate,
|
4732 | creator: info.Creator,
|
4733 | producer: info.Producer,
|
4734 | version: info.PDFFormatVersion,
|
4735 | pageCount: this.pdfDocument.numPages,
|
4736 | pageSize,
|
4737 | linearized: isLinearized,
|
4738 | _currentPageNumber: currentPageNumber,
|
4739 | _pagesRotation: pagesRotation
|
4740 | });
|
4741 | this.#updateUI();
|
4742 | const {
|
4743 | length
|
4744 | } = await this.pdfDocument.getDownloadInfo();
|
4745 | if (contentLength === length) {
|
4746 | return;
|
4747 | }
|
4748 | const data = Object.assign(Object.create(null), this.#fieldData);
|
4749 | data.fileSize = await this.#parseFileSize(length);
|
4750 | this.#fieldData = Object.freeze(data);
|
4751 | this.#updateUI();
|
4752 | }
|
4753 | async close() {
|
4754 | this.overlayManager.close(this.dialog);
|
4755 | }
|
4756 | setDocument(pdfDocument) {
|
4757 | if (this.pdfDocument) {
|
4758 | this.#reset();
|
4759 | this.#updateUI(true);
|
4760 | }
|
4761 | if (!pdfDocument) {
|
4762 | return;
|
4763 | }
|
4764 | this.pdfDocument = pdfDocument;
|
4765 | this._dataAvailableCapability.resolve();
|
4766 | }
|
4767 | #reset() {
|
4768 | this.pdfDocument = null;
|
4769 | this.#fieldData = null;
|
4770 | this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
|
4771 | this._currentPageNumber = 1;
|
4772 | this._pagesRotation = 0;
|
4773 | }
|
4774 | #updateUI(reset = false) {
|
4775 | if (reset || !this.#fieldData) {
|
4776 | for (const id in this.fields) {
|
4777 | this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
|
4778 | }
|
4779 | return;
|
4780 | }
|
4781 | if (this.overlayManager.active !== this.dialog) {
|
4782 | return;
|
4783 | }
|
4784 | for (const id in this.fields) {
|
4785 | const content = this.#fieldData[id];
|
4786 | this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
|
4787 | }
|
4788 | }
|
4789 | async #parseFileSize(fileSize = 0) {
|
4790 | const kb = fileSize / 1024,
|
4791 | mb = kb / 1024;
|
4792 | if (!kb) {
|
4793 | return undefined;
|
4794 | }
|
4795 | return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
|
4796 | size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
|
4797 | size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
|
4798 | size_b: fileSize.toLocaleString()
|
4799 | });
|
4800 | }
|
4801 | async #parsePageSize(pageSizeInches, pagesRotation) {
|
4802 | if (!pageSizeInches) {
|
4803 | return undefined;
|
4804 | }
|
4805 | if (pagesRotation % 180 !== 0) {
|
4806 | pageSizeInches = {
|
4807 | width: pageSizeInches.height,
|
4808 | height: pageSizeInches.width
|
4809 | };
|
4810 | }
|
4811 | const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
|
4812 | let sizeInches = {
|
4813 | width: Math.round(pageSizeInches.width * 100) / 100,
|
4814 | height: Math.round(pageSizeInches.height * 100) / 100
|
4815 | };
|
4816 | let sizeMillimeters = {
|
4817 | width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
|
4818 | height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
|
4819 | };
|
4820 | let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
|
4821 | if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
|
4822 | const exactMillimeters = {
|
4823 | width: pageSizeInches.width * 25.4,
|
4824 | height: pageSizeInches.height * 25.4
|
4825 | };
|
4826 | const intMillimeters = {
|
4827 | width: Math.round(sizeMillimeters.width),
|
4828 | height: Math.round(sizeMillimeters.height)
|
4829 | };
|
4830 | if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
|
4831 | rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
|
4832 | if (rawName) {
|
4833 | sizeInches = {
|
4834 | width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
|
4835 | height: Math.round(intMillimeters.height / 25.4 * 100) / 100
|
4836 | };
|
4837 | sizeMillimeters = intMillimeters;
|
4838 | }
|
4839 | }
|
4840 | }
|
4841 | const [{
|
4842 | width,
|
4843 | height
|
4844 | }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]);
|
4845 | return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
|
4846 | width: width.toLocaleString(),
|
4847 | height: height.toLocaleString(),
|
4848 | unit,
|
4849 | name,
|
4850 | orientation
|
4851 | });
|
4852 | }
|
4853 | async #parseDate(inputDate) {
|
4854 | const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
|
4855 | if (!dateObject) {
|
4856 | return undefined;
|
4857 | }
|
4858 | return this.l10n.get("document_properties_date_string", {
|
4859 | date: dateObject.toLocaleDateString(),
|
4860 | time: dateObject.toLocaleTimeString()
|
4861 | });
|
4862 | }
|
4863 | #parseLinearization(isLinearized) {
|
4864 | return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
|
4865 | }
|
4866 | }
|
4867 | exports.PDFDocumentProperties = PDFDocumentProperties;
|
4868 |
|
4869 | }),
|
4870 |
|
4871 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
4872 |
|
4873 |
|
4874 |
|
4875 | Object.defineProperty(exports, "__esModule", ({
|
4876 | value: true
|
4877 | }));
|
4878 | exports.PDFFindBar = void 0;
|
4879 | var _pdf_find_controller = __webpack_require__(17);
|
4880 | const MATCHES_COUNT_LIMIT = 1000;
|
4881 | class PDFFindBar {
|
4882 | constructor(options, eventBus, l10n) {
|
4883 | this.opened = false;
|
4884 | this.bar = options.bar;
|
4885 | this.toggleButton = options.toggleButton;
|
4886 | this.findField = options.findField;
|
4887 | this.highlightAll = options.highlightAllCheckbox;
|
4888 | this.currentPage = options.findCurrentPageCheckbox;
|
4889 | this.pageRange = options.findPageRangeField;
|
4890 | this.caseSensitive = options.caseSensitiveCheckbox;
|
4891 | this.matchDiacritics = options.matchDiacriticsCheckbox;
|
4892 | this.entireWord = options.entireWordCheckbox;
|
4893 | this.findMsg = options.findMsg;
|
4894 | this.findResultsCount = options.findResultsCount;
|
4895 | this.findPreviousButton = options.findPreviousButton;
|
4896 | this.findNextButton = options.findNextButton;
|
4897 | this.findFieldMultiline = options.findFieldMultiline || null;
|
4898 | this.multipleSearchTexts = options.findMultipleSearchTextsCheckbox || null;
|
4899 | this.ignoreAccents = options.ignoreAccentsCheckbox || null;
|
4900 | this.fuzzySearch = options.fuzzyCheckbox || null;
|
4901 | this.eventBus = eventBus;
|
4902 | this.l10n = l10n;
|
4903 | this.toggleButton.addEventListener("click", () => {
|
4904 | this.toggle();
|
4905 | });
|
4906 | this.findFieldMultiline.addEventListener("input", () => {
|
4907 | this.dispatchEvent("");
|
4908 | });
|
4909 | this.findField.addEventListener("input", () => {
|
4910 | this.dispatchEvent("");
|
4911 | });
|
4912 | this.bar.addEventListener("keydown", e => {
|
4913 | switch (e.keyCode) {
|
4914 | case 13:
|
4915 | if (e.target === this.findField) {
|
4916 | this.dispatchEvent("again", e.shiftKey);
|
4917 | }
|
4918 | break;
|
4919 | case 27:
|
4920 | this.close();
|
4921 | break;
|
4922 | }
|
4923 | });
|
4924 | this.findPreviousButton.addEventListener("click", () => {
|
4925 | this.dispatchEvent("again", true);
|
4926 | });
|
4927 | this.findNextButton.addEventListener("click", () => {
|
4928 | this.dispatchEvent("again", false);
|
4929 | });
|
4930 | this.highlightAll.addEventListener("click", () => {
|
4931 | this.dispatchEvent("highlightallchange");
|
4932 | });
|
4933 | this.caseSensitive.addEventListener("click", () => {
|
4934 | this.dispatchEvent("casesensitivitychange");
|
4935 | });
|
4936 | this.entireWord.addEventListener("click", () => {
|
4937 | this.dispatchEvent("entirewordchange");
|
4938 | });
|
4939 | this.multipleSearchTexts.addEventListener("click", () => {
|
4940 | this.dispatchEvent("multiplesearchtextschange");
|
4941 | });
|
4942 | this.ignoreAccents.addEventListener("click", () => {
|
4943 | this.dispatchEvent("ignoreAccentsChange");
|
4944 | });
|
4945 | this.fuzzySearch.addEventListener("click", () => {
|
4946 | this.dispatchEvent("fuzzySearchChange");
|
4947 | });
|
4948 | this.currentPage.addEventListener("click", () => {
|
4949 | this.dispatchEvent("currentPageChange");
|
4950 | });
|
4951 | this.pageRange.addEventListener("input", () => {
|
4952 | this.dispatchEvent("pageRangeChange");
|
4953 | });
|
4954 | this.matchDiacritics?.addEventListener("click", () => {
|
4955 | this.dispatchEvent("diacriticmatchingchange");
|
4956 | });
|
4957 | this.eventBus._on("resize", this.#adjustWidth.bind(this));
|
4958 | }
|
4959 | reset() {
|
4960 | this.updateUIState();
|
4961 | }
|
4962 | dispatchEvent(type, findPrev = false) {
|
4963 | this.eventBus.dispatch("find", {
|
4964 | source: this,
|
4965 | type,
|
4966 | query: this.findFieldMultiline.classList.contains("hidden") ? this.findField.value : this.findFieldMultiline.value + "\n",
|
4967 | phraseSearch: !this.multipleSearchTexts.checked,
|
4968 | caseSensitive: this.caseSensitive.checked,
|
4969 | entireWord: this.entireWord.checked,
|
4970 | ignoreAccents: this.ignoreAccents.checked,
|
4971 | fuzzySearch: this.fuzzySearch.checked,
|
4972 | highlightAll: this.highlightAll.checked,
|
4973 | currentPage: this.currentPage.checked,
|
4974 | pageRange: this.pageRange.value,
|
4975 | findPrevious: findPrev,
|
4976 | matchDiacritics: this.matchDiacritics?.checked
|
4977 | });
|
4978 | }
|
4979 | updateUIState(state, previous, matchesCount) {
|
4980 | let findMsg = Promise.resolve("");
|
4981 | let status = "";
|
4982 | switch (state) {
|
4983 | case _pdf_find_controller.FindState.FOUND:
|
4984 | break;
|
4985 | case _pdf_find_controller.FindState.PENDING:
|
4986 | status = "pending";
|
4987 | break;
|
4988 | case _pdf_find_controller.FindState.NOT_FOUND:
|
4989 | findMsg = this.l10n.get("find_not_found");
|
4990 | status = "notFound";
|
4991 | break;
|
4992 | case _pdf_find_controller.FindState.WRAPPED:
|
4993 | findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
|
4994 | break;
|
4995 | }
|
4996 | this.findField.setAttribute("data-status", status);
|
4997 | this.findFieldMultiline.classList.toggle("notFound", status === "notFound");
|
4998 | this.findFieldMultiline.setAttribute("data-status", status);
|
4999 | this.findField.setAttribute("aria-invalid", state === _pdf_find_controller.FindState.NOT_FOUND);
|
5000 | findMsg.then(msg => {
|
5001 | this.findMsg.textContent = msg;
|
5002 | this.#adjustWidth();
|
5003 | });
|
5004 | this.updateResultsCount(matchesCount);
|
5005 | }
|
5006 | updateResultsCount({
|
5007 | current = 0,
|
5008 | total = 0
|
5009 | } = {}) {
|
5010 | const limit = MATCHES_COUNT_LIMIT;
|
5011 | let matchCountMsg = Promise.resolve("");
|
5012 | if (total > 0) {
|
5013 | if (total > limit) {
|
5014 | let key = "find_match_count_limit";
|
5015 | matchCountMsg = this.l10n.get(key, {
|
5016 | limit
|
5017 | });
|
5018 | } else {
|
5019 | let key = "find_match_count";
|
5020 | matchCountMsg = this.l10n.get(key, {
|
5021 | current,
|
5022 | total
|
5023 | });
|
5024 | }
|
5025 | }
|
5026 | matchCountMsg.then(msg => {
|
5027 | this.findResultsCount.textContent = msg;
|
5028 | this.#adjustWidth();
|
5029 | });
|
5030 | }
|
5031 | open() {
|
5032 | if (!this.opened) {
|
5033 | this.opened = true;
|
5034 | this.toggleButton.classList.add("toggled");
|
5035 | this.toggleButton.setAttribute("aria-expanded", "true");
|
5036 | this.bar.classList.remove("hidden");
|
5037 | }
|
5038 | this.findField.select();
|
5039 | this.findField.focus();
|
5040 | this.dispatchEvent("");
|
5041 | this.#adjustWidth();
|
5042 | }
|
5043 | close() {
|
5044 | if (!this.opened) {
|
5045 | return;
|
5046 | }
|
5047 | this.opened = false;
|
5048 | this.toggleButton.classList.remove("toggled");
|
5049 | this.toggleButton.setAttribute("aria-expanded", "false");
|
5050 | this.bar.classList.add("hidden");
|
5051 | this.eventBus.dispatch("findbarclose", {
|
5052 | source: this
|
5053 | });
|
5054 | }
|
5055 | toggle() {
|
5056 | if (this.opened) {
|
5057 | this.close();
|
5058 | } else {
|
5059 | this.open();
|
5060 | }
|
5061 | }
|
5062 | #adjustWidth() {
|
5063 | if (!this.opened) {
|
5064 | return;
|
5065 | }
|
5066 | this.bar.classList.remove("wrapContainers");
|
5067 | const findbarHeight = this.bar.clientHeight;
|
5068 | const inputContainerHeight = this.bar.firstElementChild.clientHeight;
|
5069 | if (findbarHeight > inputContainerHeight) {
|
5070 | this.bar.classList.add("wrapContainers");
|
5071 | }
|
5072 | }
|
5073 | }
|
5074 | exports.PDFFindBar = PDFFindBar;
|
5075 |
|
5076 | }),
|
5077 |
|
5078 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
5079 |
|
5080 |
|
5081 |
|
5082 | Object.defineProperty(exports, "__esModule", ({
|
5083 | value: true
|
5084 | }));
|
5085 | exports.PDFFindController = exports.FindState = void 0;
|
5086 | var _pdfjsLib = __webpack_require__(4);
|
5087 | var _index = __webpack_require__(18);
|
5088 | var _pdf_find_utils = __webpack_require__(19);
|
5089 | var _levenshtein = __webpack_require__(20);
|
5090 | var _ui_utils = __webpack_require__(3);
|
5091 | const FindState = {
|
5092 | FOUND: 0,
|
5093 | NOT_FOUND: 1,
|
5094 | WRAPPED: 2,
|
5095 | PENDING: 3
|
5096 | };
|
5097 | exports.FindState = FindState;
|
5098 | const FIND_TIMEOUT = 250;
|
5099 | const MATCH_SCROLL_OFFSET_TOP = -50;
|
5100 | const MATCH_SCROLL_OFFSET_LEFT = -400;
|
5101 | const CHARACTERS_TO_NORMALIZE = {
|
5102 | "\u2010": "-",
|
5103 | "\u2018": "'",
|
5104 | "\u2019": "'",
|
5105 | "\u201A": "'",
|
5106 | "\u201B": "'",
|
5107 | "\u201C": '"',
|
5108 | "\u201D": '"',
|
5109 | "\u201E": '"',
|
5110 | "\u201F": '"',
|
5111 | "\u00BC": "1/4",
|
5112 | "\u00BD": "1/2",
|
5113 | "\u00BE": "3/4",
|
5114 | "\n": " "
|
5115 | };
|
5116 | const DIACRITICS_EXCEPTION = new Set([0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d, 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039, 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2, 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed, 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74]);
|
5117 | let DIACRITICS_EXCEPTION_STR;
|
5118 | const DIACRITICS_REG_EXP = /\p{M}+/gu;
|
5119 | const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
|
5120 | const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
|
5121 | const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
|
5122 | const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
|
5123 | const SYLLABLES_LENGTHS = new Map();
|
5124 | const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
|
5125 | const NFKC_CHARS_TO_NORMALIZE = new Map();
|
5126 | let noSyllablesRegExp = null;
|
5127 | let withSyllablesRegExp = null;
|
5128 | function normalize(text) {
|
5129 | const syllablePositions = [];
|
5130 | let m;
|
5131 | while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
|
5132 | let {
|
5133 | index
|
5134 | } = m;
|
5135 | for (const char of m[0]) {
|
5136 | let len = SYLLABLES_LENGTHS.get(char);
|
5137 | if (!len) {
|
5138 | len = char.normalize("NFD").length;
|
5139 | SYLLABLES_LENGTHS.set(char, len);
|
5140 | }
|
5141 | syllablePositions.push([len, index++]);
|
5142 | }
|
5143 | }
|
5144 | let normalizationRegex;
|
5145 | if (syllablePositions.length === 0 && noSyllablesRegExp) {
|
5146 | normalizationRegex = noSyllablesRegExp;
|
5147 | } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
|
5148 | normalizationRegex = withSyllablesRegExp;
|
5149 | } else {
|
5150 | const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
|
5151 | const toNormalizeWithNFKC = "\u2460-\u2473" + "\u24b6-\u24ff" + "\u3244-\u32bf" + "\u32d0-\u32fe" + "\uff00-\uffef";
|
5152 | const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
|
5153 | const HKDiacritics = "(?:\u3099|\u309A)";
|
5154 | const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(${HKDiacritics}\\n)|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
|
5155 | if (syllablePositions.length === 0) {
|
5156 | normalizationRegex = noSyllablesRegExp = new RegExp(regexp + "|(\\u0000)", "gum");
|
5157 | } else {
|
5158 | normalizationRegex = withSyllablesRegExp = new RegExp(regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`, "gum");
|
5159 | }
|
5160 | }
|
5161 | const rawDiacriticsPositions = [];
|
5162 | while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
|
5163 | rawDiacriticsPositions.push([m[0].length, m.index]);
|
5164 | }
|
5165 | let normalized = text.normalize("NFD");
|
5166 | const positions = [[0, 0]];
|
5167 | let rawDiacriticsIndex = 0;
|
5168 | let syllableIndex = 0;
|
5169 | let shift = 0;
|
5170 | let shiftOrigin = 0;
|
5171 | let eol = 0;
|
5172 | let hasDiacritics = false;
|
5173 | normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, p8, i) => {
|
5174 | i -= shiftOrigin;
|
5175 | if (p1) {
|
5176 | const replacement = CHARACTERS_TO_NORMALIZE[p1];
|
5177 | const jj = replacement.length;
|
5178 | for (let j = 1; j < jj; j++) {
|
5179 | positions.push([i - shift + j, shift - j]);
|
5180 | }
|
5181 | shift -= jj - 1;
|
5182 | return replacement;
|
5183 | }
|
5184 | if (p2) {
|
5185 | let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
|
5186 | if (!replacement) {
|
5187 | replacement = p2.normalize("NFKC");
|
5188 | NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
|
5189 | }
|
5190 | const jj = replacement.length;
|
5191 | for (let j = 1; j < jj; j++) {
|
5192 | positions.push([i - shift + j, shift - j]);
|
5193 | }
|
5194 | shift -= jj - 1;
|
5195 | return replacement;
|
5196 | }
|
5197 | if (p3) {
|
5198 | hasDiacritics = true;
|
5199 | if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
|
5200 | ++rawDiacriticsIndex;
|
5201 | } else {
|
5202 | positions.push([i - 1 - shift + 1, shift - 1]);
|
5203 | shift -= 1;
|
5204 | shiftOrigin += 1;
|
5205 | }
|
5206 | positions.push([i - shift + 1, shift]);
|
5207 | shiftOrigin += 1;
|
5208 | eol += 1;
|
5209 | return p3.charAt(0);
|
5210 | }
|
5211 | if (p4) {
|
5212 | const hasTrailingDashEOL = p4.endsWith("\n");
|
5213 | const len = hasTrailingDashEOL ? p4.length - 2 : p4.length;
|
5214 | hasDiacritics = true;
|
5215 | let jj = len;
|
5216 | if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
|
5217 | jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
|
5218 | ++rawDiacriticsIndex;
|
5219 | }
|
5220 | for (let j = 1; j <= jj; j++) {
|
5221 | positions.push([i - 1 - shift + j, shift - j]);
|
5222 | }
|
5223 | shift -= jj;
|
5224 | shiftOrigin += jj;
|
5225 | if (hasTrailingDashEOL) {
|
5226 | i += len - 1;
|
5227 | positions.push([i - shift + 1, 1 + shift]);
|
5228 | shift += 1;
|
5229 | shiftOrigin += 1;
|
5230 | eol += 1;
|
5231 | return p4.slice(0, len);
|
5232 | }
|
5233 | return p4;
|
5234 | }
|
5235 | if (p5) {
|
5236 | positions.push([i - shift + 1, 1 + shift]);
|
5237 | shift += 1;
|
5238 | shiftOrigin += 1;
|
5239 | eol += 1;
|
5240 | return p5.charAt(0);
|
5241 | }
|
5242 | if (p6) {
|
5243 | positions.push([i - shift + 1, shift]);
|
5244 | shiftOrigin += 1;
|
5245 | eol += 1;
|
5246 | return p6.charAt(0);
|
5247 | }
|
5248 | if (p7) {
|
5249 | positions.push([i - shift + 1, shift - 1]);
|
5250 | shift -= 1;
|
5251 | shiftOrigin += 1;
|
5252 | eol += 1;
|
5253 | return " ";
|
5254 | }
|
5255 | if (i + eol === syllablePositions[syllableIndex]?.[1]) {
|
5256 | const newCharLen = syllablePositions[syllableIndex][0] - 1;
|
5257 | ++syllableIndex;
|
5258 | for (let j = 1; j <= newCharLen; j++) {
|
5259 | positions.push([i - (shift - j), shift - j]);
|
5260 | }
|
5261 | shift -= newCharLen;
|
5262 | shiftOrigin += newCharLen;
|
5263 | }
|
5264 | return p8;
|
5265 | });
|
5266 | positions.push([normalized.length, shift]);
|
5267 | return [normalized, positions, hasDiacritics];
|
5268 | }
|
5269 | function getOriginalIndex(matchIndex, diffs = null) {
|
5270 | if (!diffs) {
|
5271 | return matchIndex;
|
5272 | }
|
5273 | let totalDiff = 0;
|
5274 | for (const [index, diff] of diffs) {
|
5275 | const currentIndex = index + totalDiff;
|
5276 | if (index >= matchIndex) {
|
5277 | break;
|
5278 | }
|
5279 | if (index + diff > matchIndex) {
|
5280 | totalDiff += matchIndex - currentIndex;
|
5281 | break;
|
5282 | }
|
5283 | totalDiff += diff;
|
5284 | }
|
5285 | return matchIndex - totalDiff;
|
5286 | }
|
5287 | class PDFFindController {
|
5288 | constructor({
|
5289 | linkService,
|
5290 | eventBus,
|
5291 | pageViewMode
|
5292 | }) {
|
5293 | this._linkService = linkService;
|
5294 | this._eventBus = eventBus;
|
5295 | this._pageViewMode = pageViewMode;
|
5296 | this._reset();
|
5297 | eventBus._on("find", this._onFind.bind(this));
|
5298 | eventBus._on("findbarclose", this._onFindBarClose.bind(this));
|
5299 | this.executeCommand = (cmd, state) => {
|
5300 | Window['ngxConsole'].error("Deprecated method `PDFFindController.executeCommand` called, " + 'please dispatch a "find"-event using the EventBus instead.');
|
5301 | const eventState = Object.assign(Object.create(null), state, {
|
5302 | type: cmd.substring("find".length)
|
5303 | });
|
5304 | this._onFind(eventState);
|
5305 | };
|
5306 | }
|
5307 | get highlightMatches() {
|
5308 | return this._highlightMatches;
|
5309 | }
|
5310 | get pageMatches() {
|
5311 | return this._pageMatches;
|
5312 | }
|
5313 | get pageMatchesColor() {
|
5314 | return this._pageMatchesColor;
|
5315 | }
|
5316 | get pageMatchesLength() {
|
5317 | return this._pageMatchesLength;
|
5318 | }
|
5319 | get selected() {
|
5320 | return this._selected;
|
5321 | }
|
5322 | get state() {
|
5323 | return this._state;
|
5324 | }
|
5325 | setDocument(pdfDocument) {
|
5326 | if (this._pdfDocument) {
|
5327 | this._reset();
|
5328 | }
|
5329 | if (!pdfDocument) {
|
5330 | return;
|
5331 | }
|
5332 | this._pdfDocument = pdfDocument;
|
5333 | this._firstPageCapability.resolve();
|
5334 | }
|
5335 | _onFind(state) {
|
5336 | if (!state) {
|
5337 | return;
|
5338 | }
|
5339 | const pdfDocument = this._pdfDocument;
|
5340 | const {
|
5341 | type
|
5342 | } = state;
|
5343 | if (this._state === null || this._shouldDirtyMatch(state)) {
|
5344 | this._dirtyMatch = true;
|
5345 | }
|
5346 | this._state = state;
|
5347 | if (type !== "highlightallchange") {
|
5348 | this._updateUIState(FindState.PENDING);
|
5349 | }
|
5350 | this._firstPageCapability.promise.then(() => {
|
5351 | if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
|
5352 | return;
|
5353 | }
|
5354 | this._extractText();
|
5355 | const findbarClosed = !this._highlightMatches;
|
5356 | const pendingTimeout = !!this._findTimeout;
|
5357 | if (this._findTimeout) {
|
5358 | clearTimeout(this._findTimeout);
|
5359 | this._findTimeout = null;
|
5360 | }
|
5361 | if (!type) {
|
5362 | this._findTimeout = setTimeout(() => {
|
5363 | this._nextMatch();
|
5364 | this._findTimeout = null;
|
5365 | }, FIND_TIMEOUT);
|
5366 | } else if (this._dirtyMatch) {
|
5367 | this._nextMatch();
|
5368 | } else if (type === "again") {
|
5369 | this._nextMatch();
|
5370 | if (findbarClosed && this._state.highlightAll) {
|
5371 | this._updateAllPages();
|
5372 | }
|
5373 | } else if (type === "highlightallchange") {
|
5374 | if (pendingTimeout) {
|
5375 | this._nextMatch();
|
5376 | } else {
|
5377 | this._highlightMatches = true;
|
5378 | }
|
5379 | this._updateAllPages();
|
5380 | } else {
|
5381 | this._nextMatch();
|
5382 | }
|
5383 | });
|
5384 | }
|
5385 | scrollMatchIntoView({
|
5386 | element = null,
|
5387 | selectedLeft = 0,
|
5388 | pageIndex = -1,
|
5389 | matchIndex = -1
|
5390 | }) {
|
5391 | if (!this._scrollMatches || !element) {
|
5392 | return;
|
5393 | } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
|
5394 | return;
|
5395 | } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
|
5396 | return;
|
5397 | }
|
5398 | this._scrollMatches = false;
|
5399 | const spot = {
|
5400 | top: MATCH_SCROLL_OFFSET_TOP,
|
5401 | left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
|
5402 | };
|
5403 | (0, _ui_utils.scrollIntoView)(element, spot, true, this._pageViewMode === 'infinite-scroll');
|
5404 | }
|
5405 | _reset() {
|
5406 | this._highlightMatches = false;
|
5407 | this._scrollMatches = false;
|
5408 | this._pdfDocument = null;
|
5409 | this._pageMatches = [];
|
5410 | this._pageMatchesLength = [];
|
5411 | this._pageMatchesColor = [];
|
5412 | this._state = null;
|
5413 | this._selected = {
|
5414 | pageIdx: -1,
|
5415 | matchIdx: -1
|
5416 | };
|
5417 | this._offset = {
|
5418 | pageIdx: null,
|
5419 | matchIdx: null,
|
5420 | wrapped: false
|
5421 | };
|
5422 | this._extractTextPromises = [];
|
5423 | this._pageContents = [];
|
5424 | this._pageDiffs = [];
|
5425 | this._matchesCountTotal = 0;
|
5426 | this._pagesToSearch = null;
|
5427 | this._pendingFindMatches = new Set();
|
5428 | this._resumePageIdx = null;
|
5429 | this._dirtyMatch = false;
|
5430 | clearTimeout(this._findTimeout);
|
5431 | this._findTimeout = null;
|
5432 | this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
|
5433 | }
|
5434 | get _query() {
|
5435 | if (this._state.query !== this._rawQuery) {
|
5436 | this._rawQuery = this._state.query;
|
5437 | const queries = this._state.query.split("\n");
|
5438 | const normalizedQueries = queries.map(q => normalize(q)[0]);
|
5439 | this._normalizedQuery = normalizedQueries.join("\n");
|
5440 | }
|
5441 | return this._normalizedQuery;
|
5442 | }
|
5443 | _shouldDirtyMatch(state) {
|
5444 | if (state.query !== this._state.query) {
|
5445 | return true;
|
5446 | }
|
5447 | switch (state.type) {
|
5448 | case "again":
|
5449 | const pageNumber = this._selected.pageIdx + 1;
|
5450 | const linkService = this._linkService;
|
5451 | if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
|
5452 | return true;
|
5453 | }
|
5454 | return false;
|
5455 | case "highlightallchange":
|
5456 | return false;
|
5457 | }
|
5458 | return true;
|
5459 | }
|
5460 | _prepareMatches(matchesWithLength, matches, matchesLength, matchesColor) {
|
5461 | function isSubTerm(currentIndex) {
|
5462 | const currentElem = matchesWithLength[currentIndex];
|
5463 | const nextElem = matchesWithLength[currentIndex + 1];
|
5464 | if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
|
5465 | currentElem.skipped = true;
|
5466 | return true;
|
5467 | }
|
5468 | for (let i = currentIndex - 1; i >= 0; i--) {
|
5469 | const prevElem = matchesWithLength[i];
|
5470 | if (prevElem.skipped) {
|
5471 | continue;
|
5472 | }
|
5473 | if (prevElem.match + prevElem.matchLength < currentElem.match) {
|
5474 | break;
|
5475 | }
|
5476 | if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
|
5477 | currentElem.skipped = true;
|
5478 | return true;
|
5479 | }
|
5480 | }
|
5481 | return false;
|
5482 | }
|
5483 | matchesWithLength.sort(function (a, b) {
|
5484 | return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
|
5485 | });
|
5486 | for (let i = 0, len = matchesWithLength.length; i < len; i++) {
|
5487 | if (isSubTerm(i)) {
|
5488 | continue;
|
5489 | }
|
5490 | matches.push(matchesWithLength[i].match);
|
5491 | matchesLength.push(matchesWithLength[i].matchLength);
|
5492 | matchesColor.push(matchesWithLength[i].color);
|
5493 | }
|
5494 | }
|
5495 | _isEntireWord(content, startIdx, length) {
|
5496 | if (startIdx > 0) {
|
5497 | const first = content.charCodeAt(startIdx);
|
5498 | const limit = content.charCodeAt(startIdx - 1);
|
5499 | if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
|
5500 | return false;
|
5501 | }
|
5502 | }
|
5503 | const endIdx = startIdx + length - 1;
|
5504 | if (endIdx < content.length - 1) {
|
5505 | const last = content.charCodeAt(endIdx);
|
5506 | const limit = content.charCodeAt(endIdx + 1);
|
5507 | if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
|
5508 | return false;
|
5509 | }
|
5510 | }
|
5511 | return true;
|
5512 | }
|
5513 | _calculateFuzzyMatch(query, pageIndex, pageContent, pageDiffs) {
|
5514 | const matches = [];
|
5515 | const matchesLength = [];
|
5516 | const queryLen = query.length;
|
5517 | const shortLen = queryLen < 5 ? queryLen : 5;
|
5518 | const maxDistance = Math.round(queryLen / 5);
|
5519 | const shortQuery = query.substring(0, shortLen);
|
5520 | const options = {
|
5521 | useCollator: true
|
5522 | };
|
5523 | for (let i = 0; i < pageContent.length - queryLen; i++) {
|
5524 | const shortCurrentContent = pageContent.substring(i, i + shortLen);
|
5525 | if (_levenshtein.Levenshtein.distance(shortQuery, shortCurrentContent, options) < 3) {
|
5526 | const currentContent = pageContent.substring(i, i + queryLen);
|
5527 | const distance = _levenshtein.Levenshtein.distance(query, currentContent, options);
|
5528 | if (distance <= maxDistance) {
|
5529 | if (i + 1 < pageContent.length - queryLen) {
|
5530 | const nextCurrentContent = pageContent.substring(i + 1, i + 1 + queryLen);
|
5531 | const nextDistance = _levenshtein.Levenshtein.distance(query, nextCurrentContent, options);
|
5532 | if (distance >= nextDistance) {
|
5533 | continue;
|
5534 | }
|
5535 | }
|
5536 | const originalMatchIdx = getOriginalIndex(i, pageDiffs),
|
5537 | matchEnd = i + queryLen - 1,
|
5538 | originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
|
5539 | matches.push(originalMatchIdx);
|
5540 | matchesLength.push(originalQueryLen);
|
5541 | i += queryLen - 1;
|
5542 | }
|
5543 | }
|
5544 | }
|
5545 | this._pageMatches[pageIndex] = matches;
|
5546 | this._pageMatchesLength[pageIndex] = matchesLength;
|
5547 | }
|
5548 | _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord, ignoreAccents) {
|
5549 | if (ignoreAccents) {
|
5550 | pageContent = (0, _index.deburr)(pageContent);
|
5551 | query = (0, _index.deburr)(query);
|
5552 | }
|
5553 | const matches = [],
|
5554 | matchesLength = [];
|
5555 | const queryLen = query.length;
|
5556 | let matchIdx = -queryLen;
|
5557 | while (true) {
|
5558 | matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
|
5559 | if (matchIdx === -1) {
|
5560 | break;
|
5561 | }
|
5562 | if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
|
5563 | continue;
|
5564 | }
|
5565 | const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
|
5566 | matchEnd = matchIdx + queryLen - 1,
|
5567 | originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
|
5568 | matches.push(originalMatchIdx);
|
5569 | matchesLength.push(originalQueryLen);
|
5570 | }
|
5571 | this._pageMatches[pageIndex] = matches;
|
5572 | this._pageMatchesLength[pageIndex] = matchesLength;
|
5573 | }
|
5574 | _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord, ignoreAccents) {
|
5575 | if (ignoreAccents) {
|
5576 | pageContent = (0, _index.deburr)(pageContent);
|
5577 | query = (0, _index.deburr)(query);
|
5578 | }
|
5579 | const matchesWithLength = [];
|
5580 | const queryArray = query.includes("\n") ? query.trim().split(/\n+/g) : query.trim().match(/\S+/g);
|
5581 | for (let i = 0, len = queryArray.length; i < len; i++) {
|
5582 | const subquery = queryArray[i];
|
5583 | const subqueryLen = subquery.length;
|
5584 | if (subqueryLen === 0) {
|
5585 | continue;
|
5586 | }
|
5587 | let matchIdx = -subqueryLen;
|
5588 | while (true) {
|
5589 | matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
|
5590 | if (matchIdx === -1) {
|
5591 | break;
|
5592 | }
|
5593 | if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
|
5594 | continue;
|
5595 | }
|
5596 | const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
|
5597 | matchEnd = matchIdx + subqueryLen - 1,
|
5598 | originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
|
5599 | matchesWithLength.push({
|
5600 | match: originalMatchIdx,
|
5601 | matchLength: originalQueryLen,
|
5602 | skipped: false,
|
5603 | color: i
|
5604 | });
|
5605 | }
|
5606 | }
|
5607 | this._pageMatchesLength[pageIndex] = [];
|
5608 | this._pageMatchesColor[pageIndex] = [];
|
5609 | this._pageMatches[pageIndex] = [];
|
5610 | this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex], this._pageMatchesColor[pageIndex]);
|
5611 | }
|
5612 | _isInPageRanges(page = 1, commaSeparatedRanges) {
|
5613 | try {
|
5614 | if (!commaSeparatedRanges) {
|
5615 | return true;
|
5616 | }
|
5617 | const parts = commaSeparatedRanges.split(",");
|
5618 | return parts.some(range => this._isInPageRange(page, range));
|
5619 | } catch (e) {
|
5620 | return true;
|
5621 | }
|
5622 | }
|
5623 | _isInPageRange(page = 1, range = "6-7") {
|
5624 | try {
|
5625 | if (!range) {
|
5626 | return true;
|
5627 | }
|
5628 | if (range.includes("-")) {
|
5629 | const parts = range.split("-");
|
5630 | const from = parts[0].trim();
|
5631 | if (from.length > 0) {
|
5632 | if (page < Number(from)) {
|
5633 | return false;
|
5634 | }
|
5635 | }
|
5636 | const to = parts[1].trim();
|
5637 | if (to.length > 0) {
|
5638 | if (page > Number(to)) {
|
5639 | return false;
|
5640 | }
|
5641 | }
|
5642 | } else {
|
5643 | const from = range.trim();
|
5644 | if (from.length > 0) {
|
5645 | if (Number(from) === page) {
|
5646 | return true;
|
5647 | } else {
|
5648 | return false;
|
5649 | }
|
5650 | }
|
5651 | }
|
5652 | return true;
|
5653 | } catch (e) {
|
5654 | return true;
|
5655 | }
|
5656 | }
|
5657 | _calculateMatch(pageIndex) {
|
5658 | if (!this.state) {
|
5659 | return;
|
5660 | }
|
5661 | let pageContent = this._pageContents[pageIndex];
|
5662 | const pageDiffs = this._pageDiffs[pageIndex];
|
5663 | let query = this._query;
|
5664 | const {
|
5665 | caseSensitive,
|
5666 | entireWord,
|
5667 | ignoreAccents,
|
5668 | fuzzySearch,
|
5669 | phraseSearch,
|
5670 | currentPage,
|
5671 | pageRange
|
5672 | } = this._state;
|
5673 | let ignoreCurrentPage = false;
|
5674 | if (currentPage) {
|
5675 | if (pageIndex !== this._linkService.page - 1) {
|
5676 | ignoreCurrentPage = true;
|
5677 | this._pageMatches[pageIndex] = [];
|
5678 | }
|
5679 | }
|
5680 | if (!this._isInPageRanges(pageIndex + 1, pageRange)) {
|
5681 | ignoreCurrentPage = true;
|
5682 | this._pageMatches[pageIndex] = [];
|
5683 | }
|
5684 | if (query.length === 0) {
|
5685 | return;
|
5686 | }
|
5687 | if (!ignoreCurrentPage) {
|
5688 | if (!caseSensitive) {
|
5689 | pageContent = pageContent.toLowerCase();
|
5690 | query = query.toLowerCase();
|
5691 | }
|
5692 | if (fuzzySearch) {
|
5693 | if (query.length <= 2) {
|
5694 | this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, false);
|
5695 | } else {
|
5696 | this._calculateFuzzyMatch(query, pageIndex, pageContent, pageDiffs);
|
5697 | }
|
5698 | } else if (phraseSearch) {
|
5699 | this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord, ignoreAccents);
|
5700 | } else {
|
5701 | this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord, ignoreAccents);
|
5702 | }
|
5703 | }
|
5704 | if (this._state.highlightAll) {
|
5705 | this._updatePage(pageIndex);
|
5706 | }
|
5707 | if (this._resumePageIdx === pageIndex) {
|
5708 | this._resumePageIdx = null;
|
5709 | this._nextPageMatch();
|
5710 | }
|
5711 | const pageMatchesCount = this._pageMatches[pageIndex].length;
|
5712 | if (pageMatchesCount > 0) {
|
5713 | this._matchesCountTotal += pageMatchesCount;
|
5714 | this._updateUIResultsCount();
|
5715 | } else if (pageIndex + 1 === this._pageContents.length && this._matchesCountTotal === 0) {
|
5716 | this._updateUIResultsCount();
|
5717 | } else if (currentPage && !ignoreCurrentPage) {
|
5718 | this._updateMatch(false);
|
5719 | }
|
5720 | }
|
5721 | _extractText() {
|
5722 | if (this._extractTextPromises.length > 0) {
|
5723 | return;
|
5724 | }
|
5725 | let promise = Promise.resolve();
|
5726 | for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
|
5727 | const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
|
5728 | this._extractTextPromises[i] = extractTextCapability.promise;
|
5729 | promise = promise.then(() => {
|
5730 | if (this._pdfDocument && this._extractTextPromises.length > 0) {
|
5731 | return this._pdfDocument.getPage(i + 1).then(pdfPage => {
|
5732 | return pdfPage.getTextContent();
|
5733 | }).then(textContent => {
|
5734 | const textItems = textContent.items;
|
5735 | const strBuf = [];
|
5736 | for (let j = 0, jj = textItems.length; j < jj; j++) {
|
5737 | strBuf.push(textItems[j].str);
|
5738 | if (textItems[j].hasEOL) {
|
5739 | strBuf.push("\n");
|
5740 | }
|
5741 | }
|
5742 | [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""), false);
|
5743 | extractTextCapability.resolve(i);
|
5744 | }, reason => {
|
5745 | Window['ngxConsole'].error(`Unable to get text content for page ${i + 1}`, reason);
|
5746 | this._pageContents[i] = "";
|
5747 | this._pageDiffs[i] = null;
|
5748 | extractTextCapability.resolve(i);
|
5749 | });
|
5750 | }
|
5751 | return Promise.resolve();
|
5752 | });
|
5753 | }
|
5754 | }
|
5755 | _updatePage(index) {
|
5756 | if (this._scrollMatches && this._selected.pageIdx === index) {
|
5757 | this._linkService.page = index + 1;
|
5758 | }
|
5759 | this._eventBus.dispatch("updatetextlayermatches", {
|
5760 | source: this,
|
5761 | pageIndex: index
|
5762 | });
|
5763 | }
|
5764 | _updateAllPages() {
|
5765 | this._eventBus.dispatch("updatetextlayermatches", {
|
5766 | source: this,
|
5767 | pageIndex: -1
|
5768 | });
|
5769 | }
|
5770 | _nextMatch() {
|
5771 | const previous = this._state.findPrevious;
|
5772 | const currentPageIndex = this._linkService.page - 1;
|
5773 | const numPages = this._linkService.pagesCount;
|
5774 | this._highlightMatches = true;
|
5775 | if (this._dirtyMatch) {
|
5776 | this._dirtyMatch = false;
|
5777 | this._selected.pageIdx = this._selected.matchIdx = -1;
|
5778 | this._offset.pageIdx = currentPageIndex;
|
5779 | this._offset.matchIdx = null;
|
5780 | this._offset.wrapped = false;
|
5781 | this._resumePageIdx = null;
|
5782 | this._pageMatches.length = 0;
|
5783 | this._pageMatchesLength.length = 0;
|
5784 | this._pageMatchesColor.length = 0;
|
5785 | this._matchesCountTotal = 0;
|
5786 | this._updateAllPages();
|
5787 | const {
|
5788 | currentPage
|
5789 | } = this.state;
|
5790 | let startPage = 0;
|
5791 | let finalPage = numPages - 1;
|
5792 | if (currentPage) {
|
5793 | startPage = this._linkService.page - 1;
|
5794 | finalPage = startPage;
|
5795 | }
|
5796 | for (let i = startPage; i <= finalPage; i++) {
|
5797 | if (this._pendingFindMatches.has(i)) {
|
5798 | continue;
|
5799 | }
|
5800 | this._pendingFindMatches.add(i);
|
5801 | this._extractTextPromises[i].then(pageIdx => {
|
5802 | this._pendingFindMatches.delete(pageIdx);
|
5803 | this._calculateMatch(pageIdx);
|
5804 | });
|
5805 | }
|
5806 | }
|
5807 | if (this._query === "") {
|
5808 | this._updateUIState(FindState.FOUND);
|
5809 | return;
|
5810 | }
|
5811 | if (this._resumePageIdx) {
|
5812 | return;
|
5813 | }
|
5814 | const offset = this._offset;
|
5815 | this._pagesToSearch = numPages;
|
5816 | if (offset.matchIdx !== null) {
|
5817 | const numPageMatches = this._pageMatches[offset.pageIdx].length;
|
5818 | if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
|
5819 | offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
|
5820 | this._updateMatch(true);
|
5821 | return;
|
5822 | }
|
5823 | if (this.state.currentPage) {
|
5824 | if (previous) {
|
5825 | offset.matchIdx = numPageMatches - 1;
|
5826 | } else {
|
5827 | offset.matchIdx = 0;
|
5828 | }
|
5829 | this._updateMatch(true);
|
5830 | this._updateUIState(FindState.WRAPPED);
|
5831 | return;
|
5832 | } else {
|
5833 | this._advanceOffsetPage(previous);
|
5834 | }
|
5835 | }
|
5836 | this._nextPageMatch();
|
5837 | }
|
5838 | _matchesReady(matches) {
|
5839 | const offset = this._offset;
|
5840 | const numMatches = matches.length;
|
5841 | const previous = this._state.findPrevious;
|
5842 | if (numMatches) {
|
5843 | offset.matchIdx = previous ? numMatches - 1 : 0;
|
5844 | this._updateMatch(true);
|
5845 | return true;
|
5846 | }
|
5847 | this._advanceOffsetPage(previous);
|
5848 | if (offset.wrapped) {
|
5849 | offset.matchIdx = null;
|
5850 | if (this._pagesToSearch < 0) {
|
5851 | this._updateMatch(false);
|
5852 | return true;
|
5853 | }
|
5854 | }
|
5855 | return false;
|
5856 | }
|
5857 | _nextPageMatch() {
|
5858 | if (this._resumePageIdx !== null) {
|
5859 | Window['ngxConsole'].error("There can only be one pending page.");
|
5860 | }
|
5861 | let matches = null;
|
5862 | do {
|
5863 | const pageIdx = this._offset.pageIdx;
|
5864 | matches = this._pageMatches[pageIdx];
|
5865 | if (!matches) {
|
5866 | this._resumePageIdx = pageIdx;
|
5867 | break;
|
5868 | }
|
5869 | } while (!this._matchesReady(matches));
|
5870 | }
|
5871 | _advanceOffsetPage(previous) {
|
5872 | const offset = this._offset;
|
5873 | const numPages = this._linkService.pagesCount;
|
5874 | offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
|
5875 | offset.matchIdx = null;
|
5876 | this._pagesToSearch--;
|
5877 | if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
|
5878 | offset.pageIdx = previous ? numPages - 1 : 0;
|
5879 | offset.wrapped = true;
|
5880 | }
|
5881 | }
|
5882 | _updateMatch(found = false) {
|
5883 | let state = FindState.NOT_FOUND;
|
5884 | const wrapped = this._offset.wrapped;
|
5885 | this._offset.wrapped = false;
|
5886 | if (found) {
|
5887 | const previousPage = this._selected.pageIdx;
|
5888 | this._selected.pageIdx = this._offset.pageIdx;
|
5889 | this._selected.matchIdx = this._offset.matchIdx;
|
5890 | state = wrapped ? FindState.WRAPPED : FindState.FOUND;
|
5891 | if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
|
5892 | this._updatePage(previousPage);
|
5893 | }
|
5894 | }
|
5895 | this._updateUIState(state, this._state.findPrevious);
|
5896 | if (this._selected.pageIdx !== -1) {
|
5897 | this._scrollMatches = true;
|
5898 | this._updatePage(this._selected.pageIdx);
|
5899 | }
|
5900 | }
|
5901 | _onFindBarClose(evt) {
|
5902 | const pdfDocument = this._pdfDocument;
|
5903 | this._firstPageCapability.promise.then(() => {
|
5904 | if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
|
5905 | return;
|
5906 | }
|
5907 | if (this._findTimeout) {
|
5908 | clearTimeout(this._findTimeout);
|
5909 | this._findTimeout = null;
|
5910 | }
|
5911 | if (this._resumePageIdx) {
|
5912 | this._resumePageIdx = null;
|
5913 | this._dirtyMatch = true;
|
5914 | }
|
5915 | this._updateUIState(FindState.FOUND);
|
5916 | this._highlightMatches = false;
|
5917 | this._updateAllPages();
|
5918 | });
|
5919 | }
|
5920 | _requestMatchesCount() {
|
5921 | const {
|
5922 | pageIdx,
|
5923 | matchIdx
|
5924 | } = this._selected;
|
5925 | let current = 0,
|
5926 | total = this._matchesCountTotal;
|
5927 | if (matchIdx !== -1) {
|
5928 | for (let i = 0; i < pageIdx; i++) {
|
5929 | current += this._pageMatches[i]?.length || 0;
|
5930 | }
|
5931 | current += matchIdx + 1;
|
5932 | }
|
5933 | if (current < 1 || current > total) {
|
5934 | current = total = 0;
|
5935 | }
|
5936 | return {
|
5937 | current,
|
5938 | total
|
5939 | };
|
5940 | }
|
5941 | _updateUIResultsCount() {
|
5942 | this._eventBus.dispatch("updatefindmatchescount", {
|
5943 | source: this,
|
5944 | matchesCount: this._requestMatchesCount()
|
5945 | });
|
5946 | }
|
5947 | _updateUIState(state, previous = false) {
|
5948 | this._eventBus.dispatch("updatefindcontrolstate", {
|
5949 | source: this,
|
5950 | state,
|
5951 | previous,
|
5952 | matchesCount: this._requestMatchesCount(),
|
5953 | rawQuery: this._state?.query ?? null
|
5954 | });
|
5955 | }
|
5956 | }
|
5957 | exports.PDFFindController = PDFFindController;
|
5958 |
|
5959 | }),
|
5960 |
|
5961 | ((__unused_webpack_module, exports) => {
|
5962 |
|
5963 |
|
5964 |
|
5965 | Object.defineProperty(exports, "__esModule", ({
|
5966 | value: true
|
5967 | }));
|
5968 | exports.deburr = deburr;
|
5969 | var INFINITY = 1 / 0;
|
5970 | var symbolTag = '[object Symbol]';
|
5971 | var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
|
5972 | var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
|
5973 | rsComboSymbolsRange = '\\u20d0-\\u20f0';
|
5974 | var rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']';
|
5975 | var reComboMark = RegExp(rsCombo, 'g');
|
5976 | var deburredLetters = {
|
5977 | '\xc0': 'A',
|
5978 | '\xc1': 'A',
|
5979 | '\xc2': 'A',
|
5980 | '\xc3': 'A',
|
5981 | '\xc4': 'A',
|
5982 | '\xc5': 'A',
|
5983 | '\xe0': 'a',
|
5984 | '\xe1': 'a',
|
5985 | '\xe2': 'a',
|
5986 | '\xe3': 'a',
|
5987 | '\xe4': 'a',
|
5988 | '\xe5': 'a',
|
5989 | '\xc7': 'C',
|
5990 | '\xe7': 'c',
|
5991 | '\xd0': 'D',
|
5992 | '\xf0': 'd',
|
5993 | '\xc8': 'E',
|
5994 | '\xc9': 'E',
|
5995 | '\xca': 'E',
|
5996 | '\xcb': 'E',
|
5997 | '\xe8': 'e',
|
5998 | '\xe9': 'e',
|
5999 | '\xea': 'e',
|
6000 | '\xeb': 'e',
|
6001 | '\xcc': 'I',
|
6002 | '\xcd': 'I',
|
6003 | '\xce': 'I',
|
6004 | '\xcf': 'I',
|
6005 | '\xec': 'i',
|
6006 | '\xed': 'i',
|
6007 | '\xee': 'i',
|
6008 | '\xef': 'i',
|
6009 | '\xd1': 'N',
|
6010 | '\xf1': 'n',
|
6011 | '\xd2': 'O',
|
6012 | '\xd3': 'O',
|
6013 | '\xd4': 'O',
|
6014 | '\xd5': 'O',
|
6015 | '\xd6': 'O',
|
6016 | '\xd8': 'O',
|
6017 | '\xf2': 'o',
|
6018 | '\xf3': 'o',
|
6019 | '\xf4': 'o',
|
6020 | '\xf5': 'o',
|
6021 | '\xf6': 'o',
|
6022 | '\xf8': 'o',
|
6023 | '\xd9': 'U',
|
6024 | '\xda': 'U',
|
6025 | '\xdb': 'U',
|
6026 | '\xdc': 'U',
|
6027 | '\xf9': 'u',
|
6028 | '\xfa': 'u',
|
6029 | '\xfb': 'u',
|
6030 | '\xfc': 'u',
|
6031 | '\xdd': 'Y',
|
6032 | '\xfd': 'y',
|
6033 | '\xff': 'y',
|
6034 | '\xc6': 'Ae',
|
6035 | '\xe6': 'ae',
|
6036 | '\xde': 'Th',
|
6037 | '\xfe': 'th',
|
6038 | '\xdf': 'ss',
|
6039 | '\u0100': 'A',
|
6040 | '\u0102': 'A',
|
6041 | '\u0104': 'A',
|
6042 | '\u0101': 'a',
|
6043 | '\u0103': 'a',
|
6044 | '\u0105': 'a',
|
6045 | '\u0106': 'C',
|
6046 | '\u0108': 'C',
|
6047 | '\u010a': 'C',
|
6048 | '\u010c': 'C',
|
6049 | '\u0107': 'c',
|
6050 | '\u0109': 'c',
|
6051 | '\u010b': 'c',
|
6052 | '\u010d': 'c',
|
6053 | '\u010e': 'D',
|
6054 | '\u0110': 'D',
|
6055 | '\u010f': 'd',
|
6056 | '\u0111': 'd',
|
6057 | '\u0112': 'E',
|
6058 | '\u0114': 'E',
|
6059 | '\u0116': 'E',
|
6060 | '\u0118': 'E',
|
6061 | '\u011a': 'E',
|
6062 | '\u0113': 'e',
|
6063 | '\u0115': 'e',
|
6064 | '\u0117': 'e',
|
6065 | '\u0119': 'e',
|
6066 | '\u011b': 'e',
|
6067 | '\u011c': 'G',
|
6068 | '\u011e': 'G',
|
6069 | '\u0120': 'G',
|
6070 | '\u0122': 'G',
|
6071 | '\u011d': 'g',
|
6072 | '\u011f': 'g',
|
6073 | '\u0121': 'g',
|
6074 | '\u0123': 'g',
|
6075 | '\u0124': 'H',
|
6076 | '\u0126': 'H',
|
6077 | '\u0125': 'h',
|
6078 | '\u0127': 'h',
|
6079 | '\u0128': 'I',
|
6080 | '\u012a': 'I',
|
6081 | '\u012c': 'I',
|
6082 | '\u012e': 'I',
|
6083 | '\u0130': 'I',
|
6084 | '\u0129': 'i',
|
6085 | '\u012b': 'i',
|
6086 | '\u012d': 'i',
|
6087 | '\u012f': 'i',
|
6088 | '\u0131': 'i',
|
6089 | '\u0134': 'J',
|
6090 | '\u0135': 'j',
|
6091 | '\u0136': 'K',
|
6092 | '\u0137': 'k',
|
6093 | '\u0138': 'k',
|
6094 | '\u0139': 'L',
|
6095 | '\u013b': 'L',
|
6096 | '\u013d': 'L',
|
6097 | '\u013f': 'L',
|
6098 | '\u0141': 'L',
|
6099 | '\u013a': 'l',
|
6100 | '\u013c': 'l',
|
6101 | '\u013e': 'l',
|
6102 | '\u0140': 'l',
|
6103 | '\u0142': 'l',
|
6104 | '\u0143': 'N',
|
6105 | '\u0145': 'N',
|
6106 | '\u0147': 'N',
|
6107 | '\u014a': 'N',
|
6108 | '\u0144': 'n',
|
6109 | '\u0146': 'n',
|
6110 | '\u0148': 'n',
|
6111 | '\u014b': 'n',
|
6112 | '\u014c': 'O',
|
6113 | '\u014e': 'O',
|
6114 | '\u0150': 'O',
|
6115 | '\u014d': 'o',
|
6116 | '\u014f': 'o',
|
6117 | '\u0151': 'o',
|
6118 | '\u0154': 'R',
|
6119 | '\u0156': 'R',
|
6120 | '\u0158': 'R',
|
6121 | '\u0155': 'r',
|
6122 | '\u0157': 'r',
|
6123 | '\u0159': 'r',
|
6124 | '\u015a': 'S',
|
6125 | '\u015c': 'S',
|
6126 | '\u015e': 'S',
|
6127 | '\u0160': 'S',
|
6128 | '\u015b': 's',
|
6129 | '\u015d': 's',
|
6130 | '\u015f': 's',
|
6131 | '\u0161': 's',
|
6132 | '\u0162': 'T',
|
6133 | '\u0164': 'T',
|
6134 | '\u0166': 'T',
|
6135 | '\u0163': 't',
|
6136 | '\u0165': 't',
|
6137 | '\u0167': 't',
|
6138 | '\u0168': 'U',
|
6139 | '\u016a': 'U',
|
6140 | '\u016c': 'U',
|
6141 | '\u016e': 'U',
|
6142 | '\u0170': 'U',
|
6143 | '\u0172': 'U',
|
6144 | '\u0169': 'u',
|
6145 | '\u016b': 'u',
|
6146 | '\u016d': 'u',
|
6147 | '\u016f': 'u',
|
6148 | '\u0171': 'u',
|
6149 | '\u0173': 'u',
|
6150 | '\u0174': 'W',
|
6151 | '\u0175': 'w',
|
6152 | '\u0176': 'Y',
|
6153 | '\u0177': 'y',
|
6154 | '\u0178': 'Y',
|
6155 | '\u0179': 'Z',
|
6156 | '\u017b': 'Z',
|
6157 | '\u017d': 'Z',
|
6158 | '\u017a': 'z',
|
6159 | '\u017c': 'z',
|
6160 | '\u017e': 'z',
|
6161 | '\u0132': 'IJ',
|
6162 | '\u0133': 'ij',
|
6163 | '\u0152': 'Oe',
|
6164 | '\u0153': 'oe',
|
6165 | '\u0149': "'n",
|
6166 | '\u017f': 'ss'
|
6167 | };
|
6168 | var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
6169 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
6170 | var root = freeGlobal || freeSelf || Function('return this')();
|
6171 | function basePropertyOf(object) {
|
6172 | return function (key) {
|
6173 | return object == null ? undefined : object[key];
|
6174 | };
|
6175 | }
|
6176 | var deburrLetter = basePropertyOf(deburredLetters);
|
6177 | var objectProto = Object.prototype;
|
6178 | var objectToString = objectProto.toString;
|
6179 | var Symbol = root.Symbol;
|
6180 | var symbolProto = Symbol ? Symbol.prototype : undefined,
|
6181 | symbolToString = symbolProto ? symbolProto.toString : undefined;
|
6182 | function baseToString(value) {
|
6183 | if (typeof value == 'string') {
|
6184 | return value;
|
6185 | }
|
6186 | if (isSymbol(value)) {
|
6187 | return symbolToString ? symbolToString.call(value) : '';
|
6188 | }
|
6189 | var result = value + '';
|
6190 | return result == '0' && 1 / value == -INFINITY ? '-0' : result;
|
6191 | }
|
6192 | function isObjectLike(value) {
|
6193 | return !!value && typeof value == 'object';
|
6194 | }
|
6195 | function isSymbol(value) {
|
6196 | return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
|
6197 | }
|
6198 | function toString(value) {
|
6199 | return value == null ? '' : baseToString(value);
|
6200 | }
|
6201 | function deburr(string) {
|
6202 | string = toString(string);
|
6203 | return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
|
6204 | }
|
6205 |
|
6206 | }),
|
6207 |
|
6208 | ((__unused_webpack_module, exports) => {
|
6209 |
|
6210 |
|
6211 |
|
6212 | Object.defineProperty(exports, "__esModule", ({
|
6213 | value: true
|
6214 | }));
|
6215 | exports.CharacterType = void 0;
|
6216 | exports.getCharacterType = getCharacterType;
|
6217 | const CharacterType = {
|
6218 | SPACE: 0,
|
6219 | ALPHA_LETTER: 1,
|
6220 | PUNCT: 2,
|
6221 | HAN_LETTER: 3,
|
6222 | KATAKANA_LETTER: 4,
|
6223 | HIRAGANA_LETTER: 5,
|
6224 | HALFWIDTH_KATAKANA_LETTER: 6,
|
6225 | THAI_LETTER: 7
|
6226 | };
|
6227 | exports.CharacterType = CharacterType;
|
6228 | function isAlphabeticalScript(charCode) {
|
6229 | return charCode < 0x2e80;
|
6230 | }
|
6231 | function isAscii(charCode) {
|
6232 | return (charCode & 0xff80) === 0;
|
6233 | }
|
6234 | function isAsciiAlpha(charCode) {
|
6235 | return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
|
6236 | }
|
6237 | function isAsciiDigit(charCode) {
|
6238 | return charCode >= 0x30 && charCode <= 0x39;
|
6239 | }
|
6240 | function isAsciiSpace(charCode) {
|
6241 | return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
|
6242 | }
|
6243 | function isHan(charCode) {
|
6244 | return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
|
6245 | }
|
6246 | function isKatakana(charCode) {
|
6247 | return charCode >= 0x30a0 && charCode <= 0x30ff;
|
6248 | }
|
6249 | function isHiragana(charCode) {
|
6250 | return charCode >= 0x3040 && charCode <= 0x309f;
|
6251 | }
|
6252 | function isHalfwidthKatakana(charCode) {
|
6253 | return charCode >= 0xff60 && charCode <= 0xff9f;
|
6254 | }
|
6255 | function isThai(charCode) {
|
6256 | return (charCode & 0xff80) === 0x0e00;
|
6257 | }
|
6258 | function getCharacterType(charCode) {
|
6259 | if (isAlphabeticalScript(charCode)) {
|
6260 | if (isAscii(charCode)) {
|
6261 | if (isAsciiSpace(charCode)) {
|
6262 | return CharacterType.SPACE;
|
6263 | } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
|
6264 | return CharacterType.ALPHA_LETTER;
|
6265 | }
|
6266 | return CharacterType.PUNCT;
|
6267 | } else if (isThai(charCode)) {
|
6268 | return CharacterType.THAI_LETTER;
|
6269 | } else if (charCode === 0xa0) {
|
6270 | return CharacterType.SPACE;
|
6271 | }
|
6272 | return CharacterType.ALPHA_LETTER;
|
6273 | }
|
6274 | if (isHan(charCode)) {
|
6275 | return CharacterType.HAN_LETTER;
|
6276 | } else if (isKatakana(charCode)) {
|
6277 | return CharacterType.KATAKANA_LETTER;
|
6278 | } else if (isHiragana(charCode)) {
|
6279 | return CharacterType.HIRAGANA_LETTER;
|
6280 | } else if (isHalfwidthKatakana(charCode)) {
|
6281 | return CharacterType.HALFWIDTH_KATAKANA_LETTER;
|
6282 | }
|
6283 | return CharacterType.ALPHA_LETTER;
|
6284 | }
|
6285 |
|
6286 | }),
|
6287 |
|
6288 | ((__unused_webpack_module, exports) => {
|
6289 |
|
6290 |
|
6291 |
|
6292 | Object.defineProperty(exports, "__esModule", ({
|
6293 | value: true
|
6294 | }));
|
6295 | exports.Levenshtein = void 0;
|
6296 | let levenshtein_collator;
|
6297 | try {
|
6298 | levenshtein_collator = Intl.Collator("und", {
|
6299 | sensitivity: "base"
|
6300 | });
|
6301 | } catch (missingBrowserSupport) {
|
6302 | try {
|
6303 | levenshtein_collator = Intl.Collator("generic", {
|
6304 | sensitivity: "base"
|
6305 | });
|
6306 | } catch (noBrowserSupport) {
|
6307 | levenshtein_collator = undefined;
|
6308 | }
|
6309 | }
|
6310 | const levenshtein_prevRow = [];
|
6311 | const levenshtein_str2Char = [];
|
6312 | class Levenshtein {
|
6313 | static distance(str1, str2, options) {
|
6314 | const useCollator = options && levenshtein_collator && options.useCollator;
|
6315 | const str1Len = str1.length;
|
6316 | const str2Len = str2.length;
|
6317 | if (str1Len === 0) {
|
6318 | return str2Len;
|
6319 | }
|
6320 | if (str2Len === 0) {
|
6321 | return str1Len;
|
6322 | }
|
6323 | let curCol, nextCol, i, j, tmp;
|
6324 | for (i = 0; i < str2Len; ++i) {
|
6325 | levenshtein_prevRow[i] = i;
|
6326 | levenshtein_str2Char[i] = str2.charCodeAt(i);
|
6327 | }
|
6328 | levenshtein_prevRow[str2Len] = str2Len;
|
6329 | let strCmp;
|
6330 | if (useCollator) {
|
6331 | for (i = 0; i < str1Len; ++i) {
|
6332 | nextCol = i + 1;
|
6333 | for (j = 0; j < str2Len; ++j) {
|
6334 | curCol = nextCol;
|
6335 | strCmp = levenshtein_collator.compare(str1.charAt(i), String.fromCharCode(levenshtein_str2Char[j])) === 0;
|
6336 | nextCol = levenshtein_prevRow[j] + (strCmp ? 0 : 1);
|
6337 | tmp = curCol + 1;
|
6338 | if (nextCol > tmp) {
|
6339 | nextCol = tmp;
|
6340 | }
|
6341 | tmp = levenshtein_prevRow[j + 1] + 1;
|
6342 | if (nextCol > tmp) {
|
6343 | nextCol = tmp;
|
6344 | }
|
6345 | levenshtein_prevRow[j] = curCol;
|
6346 | }
|
6347 | levenshtein_prevRow[j] = nextCol;
|
6348 | }
|
6349 | } else {
|
6350 | for (i = 0; i < str1Len; ++i) {
|
6351 | nextCol = i + 1;
|
6352 | for (j = 0; j < str2Len; ++j) {
|
6353 | curCol = nextCol;
|
6354 | strCmp = str1.charCodeAt(i) === levenshtein_str2Char[j];
|
6355 | nextCol = levenshtein_prevRow[j] + (strCmp ? 0 : 1);
|
6356 | tmp = curCol + 1;
|
6357 | if (nextCol > tmp) {
|
6358 | nextCol = tmp;
|
6359 | }
|
6360 | tmp = levenshtein_prevRow[j + 1] + 1;
|
6361 | if (nextCol > tmp) {
|
6362 | nextCol = tmp;
|
6363 | }
|
6364 | levenshtein_prevRow[j] = curCol;
|
6365 | }
|
6366 | levenshtein_prevRow[j] = nextCol;
|
6367 | }
|
6368 | }
|
6369 | return nextCol;
|
6370 | }
|
6371 | }
|
6372 | exports.Levenshtein = Levenshtein;
|
6373 |
|
6374 | }),
|
6375 |
|
6376 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
6377 |
|
6378 |
|
6379 |
|
6380 | Object.defineProperty(exports, "__esModule", ({
|
6381 | value: true
|
6382 | }));
|
6383 | exports.PDFHistory = void 0;
|
6384 | exports.isDestArraysEqual = isDestArraysEqual;
|
6385 | exports.isDestHashesEqual = isDestHashesEqual;
|
6386 | var _ui_utils = __webpack_require__(3);
|
6387 | var _event_utils = __webpack_require__(6);
|
6388 | const HASH_CHANGE_TIMEOUT = 1000;
|
6389 | const POSITION_UPDATED_THRESHOLD = 50;
|
6390 | const UPDATE_VIEWAREA_TIMEOUT = 1000;
|
6391 | function getCurrentHash() {
|
6392 | return document.location.hash;
|
6393 | }
|
6394 | class PDFHistory {
|
6395 | constructor({
|
6396 | linkService,
|
6397 | eventBus
|
6398 | }) {
|
6399 | this.linkService = linkService;
|
6400 | this.eventBus = eventBus;
|
6401 | this._initialized = false;
|
6402 | this._fingerprint = "";
|
6403 | this.reset();
|
6404 | this._boundEvents = null;
|
6405 | this.eventBus._on("pagesinit", () => {
|
6406 | this._isPagesLoaded = false;
|
6407 | this.eventBus._on("pagesloaded", evt => {
|
6408 | this._isPagesLoaded = !!evt.pagesCount;
|
6409 | }, {
|
6410 | once: true
|
6411 | });
|
6412 | });
|
6413 | }
|
6414 | initialize({
|
6415 | fingerprint,
|
6416 | resetHistory = false,
|
6417 | updateUrl = false
|
6418 | }) {
|
6419 | if (!fingerprint || typeof fingerprint !== "string") {
|
6420 | Window['ngxConsole'].error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
|
6421 | return;
|
6422 | }
|
6423 | if (this._initialized) {
|
6424 | this.reset();
|
6425 | }
|
6426 | const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
|
6427 | this._fingerprint = fingerprint;
|
6428 | this._updateUrl = updateUrl === true;
|
6429 | this._initialized = true;
|
6430 | this._bindEvents();
|
6431 | const state = window.history.state;
|
6432 | this._popStateInProgress = false;
|
6433 | this._blockHashChange = 0;
|
6434 | this._currentHash = getCurrentHash();
|
6435 | this._numPositionUpdates = 0;
|
6436 | this._uid = this._maxUid = 0;
|
6437 | this._destination = null;
|
6438 | this._position = null;
|
6439 | if (!this._isValidState(state, true) || resetHistory) {
|
6440 | const {
|
6441 | hash,
|
6442 | page,
|
6443 | rotation
|
6444 | } = this._parseCurrentHash(true);
|
6445 | if (!hash || reInitialized || resetHistory) {
|
6446 | this._pushOrReplaceState(null, true);
|
6447 | return;
|
6448 | }
|
6449 | this._pushOrReplaceState({
|
6450 | hash,
|
6451 | page,
|
6452 | rotation
|
6453 | }, true);
|
6454 | return;
|
6455 | }
|
6456 | const destination = state.destination;
|
6457 | this._updateInternalState(destination, state.uid, true);
|
6458 | if (destination.rotation !== undefined) {
|
6459 | this._initialRotation = destination.rotation;
|
6460 | }
|
6461 | if (destination.dest) {
|
6462 | this._initialBookmark = JSON.stringify(destination.dest);
|
6463 | this._destination.page = null;
|
6464 | } else if (destination.hash) {
|
6465 | this._initialBookmark = destination.hash;
|
6466 | } else if (destination.page) {
|
6467 | this._initialBookmark = `page=${destination.page}`;
|
6468 | }
|
6469 | }
|
6470 | reset() {
|
6471 | if (this._initialized) {
|
6472 | this._pageHide();
|
6473 | this._initialized = false;
|
6474 | this._unbindEvents();
|
6475 | }
|
6476 | if (this._updateViewareaTimeout) {
|
6477 | clearTimeout(this._updateViewareaTimeout);
|
6478 | this._updateViewareaTimeout = null;
|
6479 | }
|
6480 | this._initialBookmark = null;
|
6481 | this._initialRotation = null;
|
6482 | }
|
6483 | push({
|
6484 | namedDest = null,
|
6485 | explicitDest,
|
6486 | pageNumber
|
6487 | }) {
|
6488 | if (!this._initialized) {
|
6489 | return;
|
6490 | }
|
6491 | if (namedDest && typeof namedDest !== "string") {
|
6492 | Window['ngxConsole'].error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
|
6493 | return;
|
6494 | } else if (!Array.isArray(explicitDest)) {
|
6495 | Window['ngxConsole'].error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
|
6496 | return;
|
6497 | } else if (!this._isValidPage(pageNumber)) {
|
6498 | if (pageNumber !== null || this._destination) {
|
6499 | Window['ngxConsole'].error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
|
6500 | return;
|
6501 | }
|
6502 | }
|
6503 | const hash = namedDest || JSON.stringify(explicitDest);
|
6504 | if (!hash) {
|
6505 | return;
|
6506 | }
|
6507 | let forceReplace = false;
|
6508 | if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
|
6509 | if (this._destination.page) {
|
6510 | return;
|
6511 | }
|
6512 | forceReplace = true;
|
6513 | }
|
6514 | if (this._popStateInProgress && !forceReplace) {
|
6515 | return;
|
6516 | }
|
6517 | this._pushOrReplaceState({
|
6518 | dest: explicitDest,
|
6519 | hash,
|
6520 | page: pageNumber,
|
6521 | rotation: this.linkService.rotation
|
6522 | }, forceReplace);
|
6523 | if (!this._popStateInProgress) {
|
6524 | this._popStateInProgress = true;
|
6525 | Promise.resolve().then(() => {
|
6526 | this._popStateInProgress = false;
|
6527 | });
|
6528 | }
|
6529 | }
|
6530 | pushPage(pageNumber) {
|
6531 | if (!this._initialized) {
|
6532 | return;
|
6533 | }
|
6534 | if (!this._isValidPage(pageNumber)) {
|
6535 | Window['ngxConsole'].error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
|
6536 | return;
|
6537 | }
|
6538 | if (this._destination?.page === pageNumber) {
|
6539 | return;
|
6540 | }
|
6541 | if (this._popStateInProgress) {
|
6542 | return;
|
6543 | }
|
6544 | this._pushOrReplaceState({
|
6545 | dest: null,
|
6546 | hash: `page=${pageNumber}`,
|
6547 | page: pageNumber,
|
6548 | rotation: this.linkService.rotation
|
6549 | });
|
6550 | if (!this._popStateInProgress) {
|
6551 | this._popStateInProgress = true;
|
6552 | Promise.resolve().then(() => {
|
6553 | this._popStateInProgress = false;
|
6554 | });
|
6555 | }
|
6556 | }
|
6557 | pushCurrentPosition() {
|
6558 | if (!this._initialized || this._popStateInProgress) {
|
6559 | return;
|
6560 | }
|
6561 | this._tryPushCurrentPosition();
|
6562 | }
|
6563 | back() {
|
6564 | if (!this._initialized || this._popStateInProgress) {
|
6565 | return;
|
6566 | }
|
6567 | const state = window.history.state;
|
6568 | if (this._isValidState(state) && state.uid > 0) {
|
6569 | window.history.back();
|
6570 | }
|
6571 | }
|
6572 | forward() {
|
6573 | if (!this._initialized || this._popStateInProgress) {
|
6574 | return;
|
6575 | }
|
6576 | const state = window.history.state;
|
6577 | if (this._isValidState(state) && state.uid < this._maxUid) {
|
6578 | window.history.forward();
|
6579 | }
|
6580 | }
|
6581 | get popStateInProgress() {
|
6582 | return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
|
6583 | }
|
6584 | get initialBookmark() {
|
6585 | return this._initialized ? this._initialBookmark : null;
|
6586 | }
|
6587 | get initialRotation() {
|
6588 | return this._initialized ? this._initialRotation : null;
|
6589 | }
|
6590 | _pushOrReplaceState(destination, forceReplace = false) {
|
6591 | const shouldReplace = forceReplace || !this._destination;
|
6592 | const newState = {
|
6593 | fingerprint: this._fingerprint,
|
6594 | uid: shouldReplace ? this._uid : this._uid + 1,
|
6595 | destination
|
6596 | };
|
6597 | this._updateInternalState(destination, newState.uid);
|
6598 | let newUrl;
|
6599 | if (this._updateUrl && destination?.hash) {
|
6600 | const baseUrl = document.location.href.split("#")[0];
|
6601 | if (!baseUrl.startsWith("file://")) {
|
6602 | newUrl = `${baseUrl}#${destination.hash}`;
|
6603 | }
|
6604 | }
|
6605 | if (shouldReplace) {
|
6606 | window.history.replaceState(newState, "", newUrl);
|
6607 | } else {
|
6608 | window.history.pushState(newState, "", newUrl);
|
6609 | }
|
6610 | }
|
6611 | _tryPushCurrentPosition(temporary = false) {
|
6612 | if (!this._position) {
|
6613 | return;
|
6614 | }
|
6615 | let position = this._position;
|
6616 | if (temporary) {
|
6617 | position = Object.assign(Object.create(null), this._position);
|
6618 | position.temporary = true;
|
6619 | }
|
6620 | if (!this._destination) {
|
6621 | this._pushOrReplaceState(position);
|
6622 | return;
|
6623 | }
|
6624 | if (this._destination.temporary) {
|
6625 | this._pushOrReplaceState(position, true);
|
6626 | return;
|
6627 | }
|
6628 | if (this._destination.hash === position.hash) {
|
6629 | return;
|
6630 | }
|
6631 | if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
|
6632 | return;
|
6633 | }
|
6634 | let forceReplace = false;
|
6635 | if (this._destination.page >= position.first && this._destination.page <= position.page) {
|
6636 | if (this._destination.dest !== undefined || !this._destination.first) {
|
6637 | return;
|
6638 | }
|
6639 | forceReplace = true;
|
6640 | }
|
6641 | this._pushOrReplaceState(position, forceReplace);
|
6642 | }
|
6643 | _isValidPage(val) {
|
6644 | return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
|
6645 | }
|
6646 | _isValidState(state, checkReload = false) {
|
6647 | if (!state) {
|
6648 | return false;
|
6649 | }
|
6650 | if (state.fingerprint !== this._fingerprint) {
|
6651 | if (checkReload) {
|
6652 | if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
|
6653 | return false;
|
6654 | }
|
6655 | const [perfEntry] = performance.getEntriesByType("navigation");
|
6656 | if (perfEntry?.type !== "reload") {
|
6657 | return false;
|
6658 | }
|
6659 | } else {
|
6660 | return false;
|
6661 | }
|
6662 | }
|
6663 | if (!Number.isInteger(state.uid) || state.uid < 0) {
|
6664 | return false;
|
6665 | }
|
6666 | if (state.destination === null || typeof state.destination !== "object") {
|
6667 | return false;
|
6668 | }
|
6669 | return true;
|
6670 | }
|
6671 | _updateInternalState(destination, uid, removeTemporary = false) {
|
6672 | if (this._updateViewareaTimeout) {
|
6673 | clearTimeout(this._updateViewareaTimeout);
|
6674 | this._updateViewareaTimeout = null;
|
6675 | }
|
6676 | if (removeTemporary && destination?.temporary) {
|
6677 | delete destination.temporary;
|
6678 | }
|
6679 | this._destination = destination;
|
6680 | this._uid = uid;
|
6681 | this._maxUid = Math.max(this._maxUid, uid);
|
6682 | this._numPositionUpdates = 0;
|
6683 | }
|
6684 | _parseCurrentHash(checkNameddest = false) {
|
6685 | const hash = unescape(getCurrentHash()).substring(1);
|
6686 | const params = (0, _ui_utils.parseQueryString)(hash);
|
6687 | const nameddest = params.get("nameddest") || "";
|
6688 | let page = params.get("page") | 0;
|
6689 | if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
|
6690 | page = null;
|
6691 | }
|
6692 | return {
|
6693 | hash,
|
6694 | page,
|
6695 | rotation: this.linkService.rotation
|
6696 | };
|
6697 | }
|
6698 | _updateViewarea({
|
6699 | location
|
6700 | }) {
|
6701 | if (this._updateViewareaTimeout) {
|
6702 | clearTimeout(this._updateViewareaTimeout);
|
6703 | this._updateViewareaTimeout = null;
|
6704 | }
|
6705 | this._position = {
|
6706 | hash: location.pdfOpenParams.substring(1),
|
6707 | page: this.linkService.page,
|
6708 | first: location.pageNumber,
|
6709 | rotation: location.rotation
|
6710 | };
|
6711 | if (this._popStateInProgress) {
|
6712 | return;
|
6713 | }
|
6714 | if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
|
6715 | this._numPositionUpdates++;
|
6716 | }
|
6717 | if (UPDATE_VIEWAREA_TIMEOUT > 0) {
|
6718 | this._updateViewareaTimeout = setTimeout(() => {
|
6719 | if (!this._popStateInProgress) {
|
6720 | this._tryPushCurrentPosition(true);
|
6721 | }
|
6722 | this._updateViewareaTimeout = null;
|
6723 | }, UPDATE_VIEWAREA_TIMEOUT);
|
6724 | }
|
6725 | }
|
6726 | _popState({
|
6727 | state
|
6728 | }) {
|
6729 | const newHash = getCurrentHash(),
|
6730 | hashChanged = this._currentHash !== newHash;
|
6731 | this._currentHash = newHash;
|
6732 | if (!state) {
|
6733 | this._uid++;
|
6734 | const {
|
6735 | hash,
|
6736 | page,
|
6737 | rotation
|
6738 | } = this._parseCurrentHash();
|
6739 | this._pushOrReplaceState({
|
6740 | hash,
|
6741 | page,
|
6742 | rotation
|
6743 | }, true);
|
6744 | return;
|
6745 | }
|
6746 | if (!this._isValidState(state)) {
|
6747 | return;
|
6748 | }
|
6749 | this._popStateInProgress = true;
|
6750 | if (hashChanged) {
|
6751 | this._blockHashChange++;
|
6752 | (0, _event_utils.waitOnEventOrTimeout)({
|
6753 | target: window,
|
6754 | name: "hashchange",
|
6755 | delay: HASH_CHANGE_TIMEOUT
|
6756 | }).then(() => {
|
6757 | this._blockHashChange--;
|
6758 | });
|
6759 | }
|
6760 | const destination = state.destination;
|
6761 | this._updateInternalState(destination, state.uid, true);
|
6762 | if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
|
6763 | this.linkService.rotation = destination.rotation;
|
6764 | }
|
6765 | if (destination.dest) {
|
6766 | this.linkService.goToDestination(destination.dest);
|
6767 | } else if (destination.hash) {
|
6768 | this.linkService.setHash(destination.hash);
|
6769 | } else if (destination.page) {
|
6770 | this.linkService.page = destination.page;
|
6771 | }
|
6772 | Promise.resolve().then(() => {
|
6773 | this._popStateInProgress = false;
|
6774 | });
|
6775 | }
|
6776 | _pageHide() {
|
6777 | if (!this._destination || this._destination.temporary) {
|
6778 | this._tryPushCurrentPosition();
|
6779 | }
|
6780 | }
|
6781 | _bindEvents() {
|
6782 | if (this._boundEvents) {
|
6783 | return;
|
6784 | }
|
6785 | this._boundEvents = {
|
6786 | updateViewarea: this._updateViewarea.bind(this),
|
6787 | popState: this._popState.bind(this),
|
6788 | pageHide: this._pageHide.bind(this)
|
6789 | };
|
6790 | this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
|
6791 | window.addEventListener("popstate", this._boundEvents.popState);
|
6792 | window.addEventListener("pagehide", this._boundEvents.pageHide);
|
6793 | }
|
6794 | _unbindEvents() {
|
6795 | if (!this._boundEvents) {
|
6796 | return;
|
6797 | }
|
6798 | this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
|
6799 | window.removeEventListener("popstate", this._boundEvents.popState);
|
6800 | window.removeEventListener("pagehide", this._boundEvents.pageHide);
|
6801 | this._boundEvents = null;
|
6802 | }
|
6803 | }
|
6804 | exports.PDFHistory = PDFHistory;
|
6805 | function isDestHashesEqual(destHash, pushHash) {
|
6806 | if (typeof destHash !== "string" || typeof pushHash !== "string") {
|
6807 | return false;
|
6808 | }
|
6809 | if (destHash === pushHash) {
|
6810 | return true;
|
6811 | }
|
6812 | const nameddest = (0, _ui_utils.parseQueryString)(destHash).get("nameddest");
|
6813 | if (nameddest === pushHash) {
|
6814 | return true;
|
6815 | }
|
6816 | return false;
|
6817 | }
|
6818 | function isDestArraysEqual(firstDest, secondDest) {
|
6819 | function isEntryEqual(first, second) {
|
6820 | if (typeof first !== typeof second) {
|
6821 | return false;
|
6822 | }
|
6823 | if (Array.isArray(first) || Array.isArray(second)) {
|
6824 | return false;
|
6825 | }
|
6826 | if (first !== null && typeof first === "object" && second !== null) {
|
6827 | if (Object.keys(first).length !== Object.keys(second).length) {
|
6828 | return false;
|
6829 | }
|
6830 | for (const key in first) {
|
6831 | if (!isEntryEqual(first[key], second[key])) {
|
6832 | return false;
|
6833 | }
|
6834 | }
|
6835 | return true;
|
6836 | }
|
6837 | return first === second || Number.isNaN(first) && Number.isNaN(second);
|
6838 | }
|
6839 | if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
|
6840 | return false;
|
6841 | }
|
6842 | if (firstDest.length !== secondDest.length) {
|
6843 | return false;
|
6844 | }
|
6845 | for (let i = 0, ii = firstDest.length; i < ii; i++) {
|
6846 | if (!isEntryEqual(firstDest[i], secondDest[i])) {
|
6847 | return false;
|
6848 | }
|
6849 | }
|
6850 | return true;
|
6851 | }
|
6852 |
|
6853 | }),
|
6854 |
|
6855 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
6856 |
|
6857 |
|
6858 |
|
6859 | Object.defineProperty(exports, "__esModule", ({
|
6860 | value: true
|
6861 | }));
|
6862 | exports.PDFLayerViewer = void 0;
|
6863 | var _base_tree_viewer = __webpack_require__(12);
|
6864 | class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
|
6865 | constructor(options) {
|
6866 | super(options);
|
6867 | this.l10n = options.l10n;
|
6868 | this.eventBus._on("optionalcontentconfigchanged", evt => {
|
6869 | this.#updateLayers(evt.promise);
|
6870 | });
|
6871 | this.eventBus._on("resetlayers", () => {
|
6872 | this.#updateLayers();
|
6873 | });
|
6874 | this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
|
6875 | }
|
6876 | reset() {
|
6877 | super.reset();
|
6878 | this._optionalContentConfig = null;
|
6879 | this._optionalContentHash = null;
|
6880 | }
|
6881 | _dispatchEvent(layersCount) {
|
6882 | this.eventBus.dispatch("layersloaded", {
|
6883 | source: this,
|
6884 | layersCount
|
6885 | });
|
6886 | }
|
6887 | _bindLink(element, {
|
6888 | groupId,
|
6889 | input
|
6890 | }) {
|
6891 | const setVisibility = () => {
|
6892 | this._optionalContentConfig.setVisibility(groupId, input.checked);
|
6893 | this._optionalContentHash = this._optionalContentConfig.getHash();
|
6894 | this.eventBus.dispatch("optionalcontentconfig", {
|
6895 | source: this,
|
6896 | promise: Promise.resolve(this._optionalContentConfig)
|
6897 | });
|
6898 | };
|
6899 | element.onclick = evt => {
|
6900 | if (evt.target === input) {
|
6901 | setVisibility();
|
6902 | return true;
|
6903 | } else if (evt.target !== element) {
|
6904 | return true;
|
6905 | }
|
6906 | input.checked = !input.checked;
|
6907 | setVisibility();
|
6908 | return false;
|
6909 | };
|
6910 | }
|
6911 | async _setNestedName(element, {
|
6912 | name = null
|
6913 | }) {
|
6914 | if (typeof name === "string") {
|
6915 | element.textContent = this._normalizeTextContent(name);
|
6916 | return;
|
6917 | }
|
6918 | element.textContent = await this.l10n.get("additional_layers");
|
6919 | element.style.fontStyle = "italic";
|
6920 | }
|
6921 | _addToggleButton(div, {
|
6922 | name = null
|
6923 | }) {
|
6924 | super._addToggleButton(div, name === null);
|
6925 | }
|
6926 | _toggleAllTreeItems() {
|
6927 | if (!this._optionalContentConfig) {
|
6928 | return;
|
6929 | }
|
6930 | super._toggleAllTreeItems();
|
6931 | }
|
6932 | render({
|
6933 | optionalContentConfig,
|
6934 | pdfDocument
|
6935 | }) {
|
6936 | if (this._optionalContentConfig) {
|
6937 | this.reset();
|
6938 | }
|
6939 | this._optionalContentConfig = optionalContentConfig || null;
|
6940 | this._pdfDocument = pdfDocument || null;
|
6941 | const groups = optionalContentConfig?.getOrder();
|
6942 | if (!groups) {
|
6943 | this._dispatchEvent(0);
|
6944 | return;
|
6945 | }
|
6946 | this._optionalContentHash = optionalContentConfig.getHash();
|
6947 | const fragment = document.createDocumentFragment(),
|
6948 | queue = [{
|
6949 | parent: fragment,
|
6950 | groups
|
6951 | }];
|
6952 | let layersCount = 0,
|
6953 | hasAnyNesting = false;
|
6954 | while (queue.length > 0) {
|
6955 | const levelData = queue.shift();
|
6956 | for (const groupId of levelData.groups) {
|
6957 | const div = document.createElement("div");
|
6958 | div.className = "treeItem";
|
6959 | const element = document.createElement("a");
|
6960 | div.append(element);
|
6961 | if (typeof groupId === "object") {
|
6962 | hasAnyNesting = true;
|
6963 | this._addToggleButton(div, groupId);
|
6964 | this._setNestedName(element, groupId);
|
6965 | const itemsDiv = document.createElement("div");
|
6966 | itemsDiv.className = "treeItems";
|
6967 | div.append(itemsDiv);
|
6968 | queue.push({
|
6969 | parent: itemsDiv,
|
6970 | groups: groupId.order
|
6971 | });
|
6972 | } else {
|
6973 | const group = optionalContentConfig.getGroup(groupId);
|
6974 | const input = document.createElement("input");
|
6975 | this._bindLink(element, {
|
6976 | groupId,
|
6977 | input
|
6978 | });
|
6979 | input.type = "checkbox";
|
6980 | input.checked = group.visible;
|
6981 | const label = document.createElement("label");
|
6982 | label.textContent = this._normalizeTextContent(group.name);
|
6983 | label.append(input);
|
6984 | element.append(label);
|
6985 | layersCount++;
|
6986 | }
|
6987 | levelData.parent.append(div);
|
6988 | }
|
6989 | }
|
6990 | this._finishRendering(fragment, layersCount, hasAnyNesting);
|
6991 | }
|
6992 | async #updateLayers(promise = null) {
|
6993 | if (!this._optionalContentConfig) {
|
6994 | return;
|
6995 | }
|
6996 | const pdfDocument = this._pdfDocument;
|
6997 | const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig());
|
6998 | if (pdfDocument !== this._pdfDocument) {
|
6999 | return;
|
7000 | }
|
7001 | if (promise) {
|
7002 | if (optionalContentConfig.getHash() === this._optionalContentHash) {
|
7003 | return;
|
7004 | }
|
7005 | } else {
|
7006 | this.eventBus.dispatch("optionalcontentconfig", {
|
7007 | source: this,
|
7008 | promise: Promise.resolve(optionalContentConfig)
|
7009 | });
|
7010 | }
|
7011 | this.render({
|
7012 | optionalContentConfig,
|
7013 | pdfDocument: this._pdfDocument
|
7014 | });
|
7015 | }
|
7016 | }
|
7017 | exports.PDFLayerViewer = PDFLayerViewer;
|
7018 |
|
7019 | }),
|
7020 |
|
7021 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
7022 |
|
7023 |
|
7024 |
|
7025 | Object.defineProperty(exports, "__esModule", ({
|
7026 | value: true
|
7027 | }));
|
7028 | exports.PDFOutlineViewer = void 0;
|
7029 | var _base_tree_viewer = __webpack_require__(12);
|
7030 | var _pdfjsLib = __webpack_require__(4);
|
7031 | var _ui_utils = __webpack_require__(3);
|
7032 | class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
|
7033 | constructor(options) {
|
7034 | super(options);
|
7035 | this.linkService = options.linkService;
|
7036 | this.downloadManager = options.downloadManager;
|
7037 | this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
|
7038 | this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
|
7039 | this.eventBus._on("pagechanging", evt => {
|
7040 | this._currentPageNumber = evt.pageNumber;
|
7041 | });
|
7042 | this.eventBus._on("pagesloaded", evt => {
|
7043 | this._isPagesLoaded = !!evt.pagesCount;
|
7044 | if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
|
7045 | this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
|
7046 | }
|
7047 | });
|
7048 | this.eventBus._on("sidebarviewchanged", evt => {
|
7049 | this._sidebarView = evt.view;
|
7050 | });
|
7051 | }
|
7052 | reset() {
|
7053 | super.reset();
|
7054 | this._outline = null;
|
7055 | this._pageNumberToDestHashCapability = null;
|
7056 | this._currentPageNumber = 1;
|
7057 | this._isPagesLoaded = null;
|
7058 | if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
|
7059 | this._currentOutlineItemCapability.resolve(false);
|
7060 | }
|
7061 | this._currentOutlineItemCapability = null;
|
7062 | }
|
7063 | _dispatchEvent(outlineCount) {
|
7064 | this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
|
7065 | if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
|
7066 | this._currentOutlineItemCapability.resolve(false);
|
7067 | } else if (this._isPagesLoaded !== null) {
|
7068 | this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
|
7069 | }
|
7070 | this.eventBus.dispatch("outlineloaded", {
|
7071 | source: this,
|
7072 | outlineCount,
|
7073 | currentOutlineItemPromise: this._currentOutlineItemCapability.promise
|
7074 | });
|
7075 | }
|
7076 | _bindLink(element, {
|
7077 | url,
|
7078 | newWindow,
|
7079 | action,
|
7080 | attachment,
|
7081 | dest,
|
7082 | setOCGState
|
7083 | }) {
|
7084 | const {
|
7085 | linkService
|
7086 | } = this;
|
7087 | if (url) {
|
7088 | linkService.addLinkAttributes(element, url, newWindow);
|
7089 | return;
|
7090 | }
|
7091 | if (action) {
|
7092 | element.href = linkService.getAnchorUrl("");
|
7093 | element.onclick = () => {
|
7094 | linkService.executeNamedAction(action);
|
7095 | return false;
|
7096 | };
|
7097 | return;
|
7098 | }
|
7099 | if (attachment) {
|
7100 | element.href = linkService.getAnchorUrl("");
|
7101 | element.onclick = () => {
|
7102 | this.downloadManager.openOrDownloadData(element, attachment.content, attachment.filename);
|
7103 | return false;
|
7104 | };
|
7105 | return;
|
7106 | }
|
7107 | if (setOCGState) {
|
7108 | element.href = linkService.getAnchorUrl("");
|
7109 | element.onclick = () => {
|
7110 | linkService.executeSetOCGState(setOCGState);
|
7111 | return false;
|
7112 | };
|
7113 | return;
|
7114 | }
|
7115 | element.href = linkService.getDestinationHash(dest);
|
7116 | element.onclick = evt => {
|
7117 | this._updateCurrentTreeItem(evt.target.parentNode);
|
7118 | if (dest) {
|
7119 | linkService.goToDestination(dest);
|
7120 | }
|
7121 | return false;
|
7122 | };
|
7123 | }
|
7124 | _setStyles(element, {
|
7125 | bold,
|
7126 | italic
|
7127 | }) {
|
7128 | if (bold) {
|
7129 | element.style.fontWeight = "bold";
|
7130 | }
|
7131 | if (italic) {
|
7132 | element.style.fontStyle = "italic";
|
7133 | }
|
7134 | }
|
7135 | _addToggleButton(div, {
|
7136 | count,
|
7137 | items
|
7138 | }) {
|
7139 | let hidden = false;
|
7140 | if (count < 0) {
|
7141 | let totalCount = items.length;
|
7142 | if (totalCount > 0) {
|
7143 | const queue = [...items];
|
7144 | while (queue.length > 0) {
|
7145 | const {
|
7146 | count: nestedCount,
|
7147 | items: nestedItems
|
7148 | } = queue.shift();
|
7149 | if (nestedCount > 0 && nestedItems.length > 0) {
|
7150 | totalCount += nestedItems.length;
|
7151 | queue.push(...nestedItems);
|
7152 | }
|
7153 | }
|
7154 | }
|
7155 | if (Math.abs(count) === totalCount) {
|
7156 | hidden = true;
|
7157 | }
|
7158 | }
|
7159 | super._addToggleButton(div, hidden);
|
7160 | }
|
7161 | _toggleAllTreeItems() {
|
7162 | if (!this._outline) {
|
7163 | return;
|
7164 | }
|
7165 | super._toggleAllTreeItems();
|
7166 | }
|
7167 | render({
|
7168 | outline,
|
7169 | pdfDocument
|
7170 | }) {
|
7171 | if (this._outline) {
|
7172 | this.reset();
|
7173 | }
|
7174 | this._outline = outline || null;
|
7175 | this._pdfDocument = pdfDocument || null;
|
7176 | if (!outline) {
|
7177 | this._dispatchEvent(0);
|
7178 | return;
|
7179 | }
|
7180 | const fragment = document.createDocumentFragment();
|
7181 | const queue = [{
|
7182 | parent: fragment,
|
7183 | items: outline
|
7184 | }];
|
7185 | let outlineCount = 0,
|
7186 | hasAnyNesting = false;
|
7187 | while (queue.length > 0) {
|
7188 | const levelData = queue.shift();
|
7189 | for (const item of levelData.items) {
|
7190 | const div = document.createElement("div");
|
7191 | div.className = "treeItem";
|
7192 | const element = document.createElement("a");
|
7193 | this._bindLink(element, item);
|
7194 | this._setStyles(element, item);
|
7195 | element.textContent = this._normalizeTextContent(item.title);
|
7196 | div.append(element);
|
7197 | if (item.items.length > 0) {
|
7198 | hasAnyNesting = true;
|
7199 | this._addToggleButton(div, item);
|
7200 | const itemsDiv = document.createElement("div");
|
7201 | itemsDiv.className = "treeItems";
|
7202 | div.append(itemsDiv);
|
7203 | queue.push({
|
7204 | parent: itemsDiv,
|
7205 | items: item.items
|
7206 | });
|
7207 | }
|
7208 | levelData.parent.append(div);
|
7209 | outlineCount++;
|
7210 | }
|
7211 | }
|
7212 | this._finishRendering(fragment, outlineCount, hasAnyNesting);
|
7213 | }
|
7214 | async _currentOutlineItem() {
|
7215 | if (!this._isPagesLoaded) {
|
7216 | throw new Error("_currentOutlineItem: All pages have not been loaded.");
|
7217 | }
|
7218 | if (!this._outline || !this._pdfDocument) {
|
7219 | return;
|
7220 | }
|
7221 | const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
|
7222 | if (!pageNumberToDestHash) {
|
7223 | return;
|
7224 | }
|
7225 | this._updateCurrentTreeItem(null);
|
7226 | if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
|
7227 | return;
|
7228 | }
|
7229 | for (let i = this._currentPageNumber; i > 0; i--) {
|
7230 | const destHash = pageNumberToDestHash.get(i);
|
7231 | if (!destHash) {
|
7232 | continue;
|
7233 | }
|
7234 | const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
|
7235 | if (!linkElement) {
|
7236 | continue;
|
7237 | }
|
7238 | this._scrollToCurrentTreeItem(linkElement.parentNode);
|
7239 | break;
|
7240 | }
|
7241 | }
|
7242 | async _getPageNumberToDestHash(pdfDocument) {
|
7243 | if (this._pageNumberToDestHashCapability) {
|
7244 | return this._pageNumberToDestHashCapability.promise;
|
7245 | }
|
7246 | this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
|
7247 | const pageNumberToDestHash = new Map(),
|
7248 | pageNumberNesting = new Map();
|
7249 | const queue = [{
|
7250 | nesting: 0,
|
7251 | items: this._outline
|
7252 | }];
|
7253 | while (queue.length > 0) {
|
7254 | const levelData = queue.shift(),
|
7255 | currentNesting = levelData.nesting;
|
7256 | for (const {
|
7257 | dest,
|
7258 | items
|
7259 | } of levelData.items) {
|
7260 | let explicitDest, pageNumber;
|
7261 | if (typeof dest === "string") {
|
7262 | explicitDest = await pdfDocument.getDestination(dest);
|
7263 | if (pdfDocument !== this._pdfDocument) {
|
7264 | return null;
|
7265 | }
|
7266 | } else {
|
7267 | explicitDest = dest;
|
7268 | }
|
7269 | if (Array.isArray(explicitDest)) {
|
7270 | const [destRef] = explicitDest;
|
7271 | if (typeof destRef === "object" && destRef !== null) {
|
7272 | pageNumber = this.linkService._cachedPageNumber(destRef);
|
7273 | if (!pageNumber) {
|
7274 | try {
|
7275 | pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
|
7276 | if (pdfDocument !== this._pdfDocument) {
|
7277 | return null;
|
7278 | }
|
7279 | this.linkService.cachePageRef(pageNumber, destRef);
|
7280 | } catch (ex) {}
|
7281 | }
|
7282 | } else if (Number.isInteger(destRef)) {
|
7283 | pageNumber = destRef + 1;
|
7284 | }
|
7285 | if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
|
7286 | const destHash = this.linkService.getDestinationHash(dest);
|
7287 | pageNumberToDestHash.set(pageNumber, destHash);
|
7288 | pageNumberNesting.set(pageNumber, currentNesting);
|
7289 | }
|
7290 | }
|
7291 | if (items.length > 0) {
|
7292 | queue.push({
|
7293 | nesting: currentNesting + 1,
|
7294 | items
|
7295 | });
|
7296 | }
|
7297 | }
|
7298 | }
|
7299 | this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
|
7300 | return this._pageNumberToDestHashCapability.promise;
|
7301 | }
|
7302 | }
|
7303 | exports.PDFOutlineViewer = PDFOutlineViewer;
|
7304 |
|
7305 | }),
|
7306 |
|
7307 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
7308 |
|
7309 |
|
7310 |
|
7311 | Object.defineProperty(exports, "__esModule", ({
|
7312 | value: true
|
7313 | }));
|
7314 | exports.PDFPresentationMode = void 0;
|
7315 | var _ui_utils = __webpack_require__(3);
|
7316 | var _pdfjsLib = __webpack_require__(4);
|
7317 | const DELAY_BEFORE_HIDING_CONTROLS = 3000;
|
7318 | const ACTIVE_SELECTOR = "pdfPresentationMode";
|
7319 | const CONTROLS_SELECTOR = "pdfPresentationModeControls";
|
7320 | const MOUSE_SCROLL_COOLDOWN_TIME = 50;
|
7321 | const PAGE_SWITCH_THRESHOLD = 0.1;
|
7322 | const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
|
7323 | const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
|
7324 | class PDFPresentationMode {
|
7325 | #state = _ui_utils.PresentationModeState.UNKNOWN;
|
7326 | #args = null;
|
7327 | constructor({
|
7328 | container,
|
7329 | pdfViewer,
|
7330 | eventBus
|
7331 | }) {
|
7332 | this.container = container;
|
7333 | this.pdfViewer = pdfViewer;
|
7334 | this.eventBus = eventBus;
|
7335 | this.contextMenuOpen = false;
|
7336 | this.mouseScrollTimeStamp = 0;
|
7337 | this.mouseScrollDelta = 0;
|
7338 | this.touchSwipeState = null;
|
7339 | }
|
7340 | async request() {
|
7341 | const {
|
7342 | container,
|
7343 | pdfViewer
|
7344 | } = this;
|
7345 | if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) {
|
7346 | return false;
|
7347 | }
|
7348 | this.#addFullscreenChangeListeners();
|
7349 | this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
|
7350 | const promise = container.requestFullscreen();
|
7351 | this.#args = {
|
7352 | pageNumber: pdfViewer.currentPageNumber,
|
7353 | scaleValue: pdfViewer.currentScaleValue,
|
7354 | scrollMode: pdfViewer.scrollMode,
|
7355 | spreadMode: null,
|
7356 | annotationEditorMode: null
|
7357 | };
|
7358 | if (pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) {
|
7359 | console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes.");
|
7360 | this.#args.spreadMode = pdfViewer.spreadMode;
|
7361 | }
|
7362 | if (pdfViewer.annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
|
7363 | this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
|
7364 | }
|
7365 | try {
|
7366 | await promise;
|
7367 | pdfViewer.focus();
|
7368 | return true;
|
7369 | } catch (reason) {
|
7370 | this.#removeFullscreenChangeListeners();
|
7371 | this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
|
7372 | }
|
7373 | return false;
|
7374 | }
|
7375 | get active() {
|
7376 | return this.#state === _ui_utils.PresentationModeState.CHANGING || this.#state === _ui_utils.PresentationModeState.FULLSCREEN;
|
7377 | }
|
7378 | #mouseWheel(evt) {
|
7379 | if (!this.active) {
|
7380 | return;
|
7381 | }
|
7382 | evt.preventDefault();
|
7383 | const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
|
7384 | const currentTime = Date.now();
|
7385 | const storedTime = this.mouseScrollTimeStamp;
|
7386 | if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
|
7387 | return;
|
7388 | }
|
7389 | if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
|
7390 | this.#resetMouseScrollState();
|
7391 | }
|
7392 | this.mouseScrollDelta += delta;
|
7393 | if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
|
7394 | const totalDelta = this.mouseScrollDelta;
|
7395 | this.#resetMouseScrollState();
|
7396 | const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
|
7397 | if (success) {
|
7398 | this.mouseScrollTimeStamp = currentTime;
|
7399 | }
|
7400 | }
|
7401 | }
|
7402 | #notifyStateChange(state) {
|
7403 | this.#state = state;
|
7404 | this.eventBus.dispatch("presentationmodechanged", {
|
7405 | source: this,
|
7406 | state
|
7407 | });
|
7408 | }
|
7409 | #enter() {
|
7410 | this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
|
7411 | this.container.classList.add(ACTIVE_SELECTOR);
|
7412 | setTimeout(() => {
|
7413 | this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
|
7414 | if (this.#args.spreadMode !== null) {
|
7415 | this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
|
7416 | }
|
7417 | this.pdfViewer.currentPageNumber = this.#args.pageNumber;
|
7418 | this.pdfViewer.currentScaleValue = "page-fit";
|
7419 | if (this.#args.annotationEditorMode !== null) {
|
7420 | this.pdfViewer.annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
|
7421 | }
|
7422 | }, 0);
|
7423 | this.#addWindowListeners();
|
7424 | this.#showControls();
|
7425 | this.contextMenuOpen = false;
|
7426 | window.getSelection().removeAllRanges();
|
7427 | }
|
7428 | #exit() {
|
7429 | const pageNumber = this.pdfViewer.currentPageNumber;
|
7430 | this.container.classList.remove(ACTIVE_SELECTOR);
|
7431 | setTimeout(() => {
|
7432 | this.#removeFullscreenChangeListeners();
|
7433 | this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
|
7434 | this.pdfViewer.scrollMode = this.#args.scrollMode;
|
7435 | if (this.#args.spreadMode !== null) {
|
7436 | this.pdfViewer.spreadMode = this.#args.spreadMode;
|
7437 | }
|
7438 | this.pdfViewer.currentScaleValue = this.#args.scaleValue;
|
7439 | this.pdfViewer.currentPageNumber = pageNumber;
|
7440 | if (this.#args.annotationEditorMode !== null) {
|
7441 | this.pdfViewer.annotationEditorMode = this.#args.annotationEditorMode;
|
7442 | }
|
7443 | this.#args = null;
|
7444 | }, 0);
|
7445 | this.#removeWindowListeners();
|
7446 | this.#hideControls();
|
7447 | this.#resetMouseScrollState();
|
7448 | this.contextMenuOpen = false;
|
7449 | }
|
7450 | _prepareFullscreenMode() {
|
7451 | const domElement = document.getElementsByClassName("zoom")[0].parentElement;
|
7452 | const parent = domElement.parentElement;
|
7453 | this.ngxContainer = parent;
|
7454 | for (let i = 0; i < parent.childElementCount; i++) {
|
7455 | if (parent.children.item(i) === domElement) {
|
7456 | this.ngxContainerIndex = i;
|
7457 | }
|
7458 | }
|
7459 | parent.removeChild(domElement);
|
7460 | document.body.append(domElement);
|
7461 | const siblings = document.body.children;
|
7462 | for (let i = 0; i < siblings.length; i++) {
|
7463 | const s = siblings.item(i);
|
7464 | if (s !== domElement && s instanceof HTMLElement) {
|
7465 | s.classList.add("hidden-by-fullscreen");
|
7466 | }
|
7467 | }
|
7468 | document.getElementById("sidebarContainer").classList.add("hidden-by-fullscreen");
|
7469 | document.getElementsByClassName("toolbar")[0].classList.add("hidden-by-fullscreen");
|
7470 | }
|
7471 | _tidyUpFullscreenMode() {
|
7472 | if (this.ngxContainer) {
|
7473 | const domElement = document.getElementsByClassName("zoom")[0].parentElement;
|
7474 | document.body.removeChild(domElement);
|
7475 | if (this.ngxContainerIndex >= this.ngxContainer.childElementCount) {
|
7476 | this.ngxContainer.append(domElement);
|
7477 | } else {
|
7478 | this.ngxContainer.insertBefore(domElement, this.ngxContainer.children.item(this.ngxContainerIndex));
|
7479 | }
|
7480 | this.ngxContainer = undefined;
|
7481 | const siblings = document.body.children;
|
7482 | for (let i = 0; i < siblings.length; i++) {
|
7483 | const s = siblings.item(i);
|
7484 | if (s !== domElement && s instanceof HTMLElement) {
|
7485 | if (s.classList.contains("hidden-by-fullscreen")) {
|
7486 | s.classList.remove("hidden-by-fullscreen");
|
7487 | }
|
7488 | }
|
7489 | }
|
7490 | document.getElementById("sidebarContainer").classList.remove("hidden-by-fullscreen");
|
7491 | document.getElementsByClassName("toolbar")[0].classList.remove("hidden-by-fullscreen");
|
7492 | }
|
7493 | }
|
7494 | #mouseDown(evt) {
|
7495 | if (this.contextMenuOpen) {
|
7496 | this.contextMenuOpen = false;
|
7497 | evt.preventDefault();
|
7498 | return;
|
7499 | }
|
7500 | if (evt.button !== 0) {
|
7501 | return;
|
7502 | }
|
7503 | if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) {
|
7504 | return;
|
7505 | }
|
7506 | evt.preventDefault();
|
7507 | if (evt.shiftKey) {
|
7508 | this.pdfViewer.previousPage();
|
7509 | } else {
|
7510 | this.pdfViewer.nextPage();
|
7511 | }
|
7512 | }
|
7513 | #contextMenu() {
|
7514 | this.contextMenuOpen = true;
|
7515 | }
|
7516 | #showControls() {
|
7517 | if (this.controlsTimeout) {
|
7518 | clearTimeout(this.controlsTimeout);
|
7519 | } else {
|
7520 | this.container.classList.add(CONTROLS_SELECTOR);
|
7521 | }
|
7522 | this.controlsTimeout = setTimeout(() => {
|
7523 | this.container.classList.remove(CONTROLS_SELECTOR);
|
7524 | delete this.controlsTimeout;
|
7525 | }, DELAY_BEFORE_HIDING_CONTROLS);
|
7526 | }
|
7527 | #hideControls() {
|
7528 | if (!this.controlsTimeout) {
|
7529 | return;
|
7530 | }
|
7531 | clearTimeout(this.controlsTimeout);
|
7532 | this.container.classList.remove(CONTROLS_SELECTOR);
|
7533 | delete this.controlsTimeout;
|
7534 | }
|
7535 | #resetMouseScrollState() {
|
7536 | this.mouseScrollTimeStamp = 0;
|
7537 | this.mouseScrollDelta = 0;
|
7538 | }
|
7539 | #touchSwipe(evt) {
|
7540 | if (!this.active) {
|
7541 | return;
|
7542 | }
|
7543 | if (evt.touches.length > 1) {
|
7544 | this.touchSwipeState = null;
|
7545 | return;
|
7546 | }
|
7547 | switch (evt.type) {
|
7548 | case "touchstart":
|
7549 | this.touchSwipeState = {
|
7550 | startX: evt.touches[0].pageX,
|
7551 | startY: evt.touches[0].pageY,
|
7552 | endX: evt.touches[0].pageX,
|
7553 | endY: evt.touches[0].pageY
|
7554 | };
|
7555 | break;
|
7556 | case "touchmove":
|
7557 | if (this.touchSwipeState === null) {
|
7558 | return;
|
7559 | }
|
7560 | this.touchSwipeState.endX = evt.touches[0].pageX;
|
7561 | this.touchSwipeState.endY = evt.touches[0].pageY;
|
7562 | evt.preventDefault();
|
7563 | break;
|
7564 | case "touchend":
|
7565 | if (this.touchSwipeState === null) {
|
7566 | return;
|
7567 | }
|
7568 | let delta = 0;
|
7569 | const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
|
7570 | const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
|
7571 | const absAngle = Math.abs(Math.atan2(dy, dx));
|
7572 | if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
|
7573 | delta = dx;
|
7574 | } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
|
7575 | delta = dy;
|
7576 | }
|
7577 | if (delta > 0) {
|
7578 | this.pdfViewer.previousPage();
|
7579 | } else if (delta < 0) {
|
7580 | this.pdfViewer.nextPage();
|
7581 | }
|
7582 | break;
|
7583 | }
|
7584 | }
|
7585 | #addWindowListeners() {
|
7586 | this.showControlsBind = this.#showControls.bind(this);
|
7587 | this.mouseDownBind = this.#mouseDown.bind(this);
|
7588 | this.mouseWheelBind = this.#mouseWheel.bind(this);
|
7589 | this.resetMouseScrollStateBind = this.#resetMouseScrollState.bind(this);
|
7590 | this.contextMenuBind = this.#contextMenu.bind(this);
|
7591 | this.touchSwipeBind = this.#touchSwipe.bind(this);
|
7592 | window.addEventListener("mousemove", this.showControlsBind);
|
7593 | window.addEventListener("mousedown", this.mouseDownBind);
|
7594 | window.addEventListener("wheel", this.mouseWheelBind, {
|
7595 | passive: false
|
7596 | });
|
7597 | window.addEventListener("keydown", this.resetMouseScrollStateBind);
|
7598 | window.addEventListener("contextmenu", this.contextMenuBind);
|
7599 | window.addEventListener("touchstart", this.touchSwipeBind);
|
7600 | window.addEventListener("touchmove", this.touchSwipeBind);
|
7601 | window.addEventListener("touchend", this.touchSwipeBind);
|
7602 | }
|
7603 | #removeWindowListeners() {
|
7604 | window.removeEventListener("mousemove", this.showControlsBind);
|
7605 | window.removeEventListener("mousedown", this.mouseDownBind);
|
7606 | window.removeEventListener("wheel", this.mouseWheelBind, {
|
7607 | passive: false
|
7608 | });
|
7609 | window.removeEventListener("keydown", this.resetMouseScrollStateBind);
|
7610 | window.removeEventListener("contextmenu", this.contextMenuBind);
|
7611 | window.removeEventListener("touchstart", this.touchSwipeBind);
|
7612 | window.removeEventListener("touchmove", this.touchSwipeBind);
|
7613 | window.removeEventListener("touchend", this.touchSwipeBind);
|
7614 | delete this.showControlsBind;
|
7615 | delete this.mouseDownBind;
|
7616 | delete this.mouseWheelBind;
|
7617 | delete this.resetMouseScrollStateBind;
|
7618 | delete this.contextMenuBind;
|
7619 | delete this.touchSwipeBind;
|
7620 | }
|
7621 | #fullscreenChange() {
|
7622 | if (document.fullscreenElement) {
|
7623 | this.#enter();
|
7624 | } else {
|
7625 | this.#exit();
|
7626 | }
|
7627 | }
|
7628 | #addFullscreenChangeListeners() {
|
7629 | this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
|
7630 | window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
|
7631 | }
|
7632 | #removeFullscreenChangeListeners() {
|
7633 | window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
|
7634 | delete this.fullscreenChangeBind;
|
7635 | }
|
7636 | }
|
7637 | exports.PDFPresentationMode = PDFPresentationMode;
|
7638 |
|
7639 | }),
|
7640 |
|
7641 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
7642 |
|
7643 |
|
7644 |
|
7645 | Object.defineProperty(exports, "__esModule", ({
|
7646 | value: true
|
7647 | }));
|
7648 | exports.PDFRenderingQueue = void 0;
|
7649 | var _pdfjsLib = __webpack_require__(4);
|
7650 | var _ui_utils = __webpack_require__(3);
|
7651 | const CLEANUP_TIMEOUT = 30000;
|
7652 | class PDFRenderingQueue {
|
7653 | constructor() {
|
7654 | this.pdfViewer = null;
|
7655 | this.pdfThumbnailViewer = null;
|
7656 | this.onIdle = null;
|
7657 | this.highestPriorityPage = null;
|
7658 | this.idleTimeout = null;
|
7659 | this.printing = false;
|
7660 | this.isThumbnailViewEnabled = false;
|
7661 | }
|
7662 | setViewer(pdfViewer) {
|
7663 | this.pdfViewer = pdfViewer;
|
7664 | }
|
7665 | setThumbnailViewer(pdfThumbnailViewer) {
|
7666 | this.pdfThumbnailViewer = pdfThumbnailViewer;
|
7667 | }
|
7668 | isHighestPriority(view) {
|
7669 | return this.highestPriorityPage === view.renderingId;
|
7670 | }
|
7671 | hasViewer() {
|
7672 | return !!this.pdfViewer;
|
7673 | }
|
7674 | renderHighestPriority(currentlyVisiblePages) {
|
7675 | if (this.idleTimeout) {
|
7676 | clearTimeout(this.idleTimeout);
|
7677 | this.idleTimeout = null;
|
7678 | }
|
7679 | if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
|
7680 | return;
|
7681 | }
|
7682 | if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) {
|
7683 | return;
|
7684 | }
|
7685 | if (this.printing) {
|
7686 | return;
|
7687 | }
|
7688 | if (this.onIdle) {
|
7689 | this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
|
7690 | }
|
7691 | }
|
7692 | getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
|
7693 | const visibleViews = visible.views,
|
7694 | numVisible = visibleViews.length;
|
7695 | if (numVisible === 0) {
|
7696 | return null;
|
7697 | }
|
7698 | for (let i = 0; i < numVisible; i++) {
|
7699 | const view = visibleViews[i].view;
|
7700 | if (!this.isViewFinished(view)) {
|
7701 | return view;
|
7702 | }
|
7703 | }
|
7704 | const firstId = visible.first.id,
|
7705 | lastId = visible.last.id;
|
7706 | if (lastId - firstId + 1 > numVisible) {
|
7707 | const visibleIds = visible.ids;
|
7708 | for (let i = 1, ii = lastId - firstId; i < ii; i++) {
|
7709 | const holeId = scrolledDown ? firstId + i : lastId - i;
|
7710 | if (visibleIds.has(holeId)) {
|
7711 | continue;
|
7712 | }
|
7713 | const holeView = views[holeId - 1];
|
7714 | if (!this.isViewFinished(holeView)) {
|
7715 | return holeView;
|
7716 | }
|
7717 | }
|
7718 | }
|
7719 | let preRenderIndex = scrolledDown ? lastId : firstId - 2;
|
7720 | let preRenderView = views[preRenderIndex];
|
7721 | if (preRenderView && !this.isViewFinished(preRenderView)) {
|
7722 | return preRenderView;
|
7723 | }
|
7724 | if (preRenderExtra) {
|
7725 | preRenderIndex += scrolledDown ? 1 : -1;
|
7726 | preRenderView = views[preRenderIndex];
|
7727 | if (preRenderView && !this.isViewFinished(preRenderView)) {
|
7728 | return preRenderView;
|
7729 | }
|
7730 | }
|
7731 | return null;
|
7732 | }
|
7733 | isViewFinished(view) {
|
7734 | return view.renderingState === _ui_utils.RenderingStates.FINISHED;
|
7735 | }
|
7736 | renderView(view) {
|
7737 | switch (view.renderingState) {
|
7738 | case _ui_utils.RenderingStates.FINISHED:
|
7739 | return false;
|
7740 | case _ui_utils.RenderingStates.PAUSED:
|
7741 | this.highestPriorityPage = view.renderingId;
|
7742 | view.resume();
|
7743 | break;
|
7744 | case _ui_utils.RenderingStates.RUNNING:
|
7745 | this.highestPriorityPage = view.renderingId;
|
7746 | break;
|
7747 | case _ui_utils.RenderingStates.INITIAL:
|
7748 | this.highestPriorityPage = view.renderingId;
|
7749 | view.draw().finally(() => {
|
7750 | this.renderHighestPriority();
|
7751 | }).catch(reason => {
|
7752 | if (reason instanceof _pdfjsLib.RenderingCancelledException) {
|
7753 | return;
|
7754 | }
|
7755 | Window['ngxConsole'].error(`renderView: "${reason}"`);
|
7756 | });
|
7757 | break;
|
7758 | }
|
7759 | return true;
|
7760 | }
|
7761 | }
|
7762 | exports.PDFRenderingQueue = PDFRenderingQueue;
|
7763 |
|
7764 | }),
|
7765 |
|
7766 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
7767 |
|
7768 |
|
7769 |
|
7770 | Object.defineProperty(exports, "__esModule", ({
|
7771 | value: true
|
7772 | }));
|
7773 | exports.PDFScriptingManager = void 0;
|
7774 | var _ui_utils = __webpack_require__(3);
|
7775 | var _pdfjsLib = __webpack_require__(4);
|
7776 | class PDFScriptingManager {
|
7777 | constructor({
|
7778 | eventBus,
|
7779 | sandboxBundleSrc = null,
|
7780 | scriptingFactory = null,
|
7781 | docPropertiesLookup = null
|
7782 | }) {
|
7783 | this._pdfDocument = null;
|
7784 | this._pdfViewer = null;
|
7785 | this._closeCapability = null;
|
7786 | this._destroyCapability = null;
|
7787 | this._scripting = null;
|
7788 | this._ready = false;
|
7789 | this._eventBus = eventBus;
|
7790 | this._sandboxBundleSrc = sandboxBundleSrc;
|
7791 | this._scriptingFactory = scriptingFactory;
|
7792 | this._docPropertiesLookup = docPropertiesLookup;
|
7793 | }
|
7794 | setViewer(pdfViewer) {
|
7795 | this._pdfViewer = pdfViewer;
|
7796 | }
|
7797 | async setDocument(pdfDocument) {
|
7798 | if (this._pdfDocument) {
|
7799 | await this._destroyScripting();
|
7800 | }
|
7801 | this._pdfDocument = pdfDocument;
|
7802 | if (!pdfDocument) {
|
7803 | return;
|
7804 | }
|
7805 | const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
|
7806 | if (!objects && !docActions) {
|
7807 | await this._destroyScripting();
|
7808 | return;
|
7809 | }
|
7810 | if (pdfDocument !== this._pdfDocument) {
|
7811 | return;
|
7812 | }
|
7813 | try {
|
7814 | this._scripting = this._createScripting();
|
7815 | } catch (error) {
|
7816 | Window['ngxConsole'].error(`PDFScriptingManager.setDocument: "${error?.message}".`);
|
7817 | await this._destroyScripting();
|
7818 | return;
|
7819 | }
|
7820 | this._internalEvents.set("updatefromsandbox", event => {
|
7821 | if (event?.source !== window) {
|
7822 | return;
|
7823 | }
|
7824 | this._updateFromSandbox(event.detail);
|
7825 | });
|
7826 | this._internalEvents.set("dispatcheventinsandbox", event => {
|
7827 | this._scripting?.dispatchEventInSandbox(event.detail);
|
7828 | });
|
7829 | this._internalEvents.set("pagechanging", ({
|
7830 | pageNumber,
|
7831 | previous
|
7832 | }) => {
|
7833 | if (pageNumber === previous) {
|
7834 | return;
|
7835 | }
|
7836 | this._dispatchPageClose(previous);
|
7837 | this._dispatchPageOpen(pageNumber);
|
7838 | });
|
7839 | this._internalEvents.set("pagerendered", ({
|
7840 | pageNumber
|
7841 | }) => {
|
7842 | if (!this._pageOpenPending.has(pageNumber)) {
|
7843 | return;
|
7844 | }
|
7845 | if (pageNumber !== this._pdfViewer.currentPageNumber) {
|
7846 | return;
|
7847 | }
|
7848 | this._dispatchPageOpen(pageNumber);
|
7849 | });
|
7850 | this._internalEvents.set("pagesdestroy", async event => {
|
7851 | await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
|
7852 | await this._scripting?.dispatchEventInSandbox({
|
7853 | id: "doc",
|
7854 | name: "WillClose"
|
7855 | });
|
7856 | this._closeCapability?.resolve();
|
7857 | });
|
7858 | for (const [name, listener] of this._internalEvents) {
|
7859 | this._eventBus._on(name, listener);
|
7860 | }
|
7861 | try {
|
7862 | const docProperties = await this._getDocProperties();
|
7863 | if (pdfDocument !== this._pdfDocument) {
|
7864 | return;
|
7865 | }
|
7866 | await this._scripting.createSandbox({
|
7867 | objects,
|
7868 | calculationOrder,
|
7869 | appInfo: {
|
7870 | platform: navigator.platform,
|
7871 | language: navigator.language
|
7872 | },
|
7873 | docInfo: {
|
7874 | ...docProperties,
|
7875 | actions: docActions
|
7876 | }
|
7877 | });
|
7878 | this._eventBus.dispatch("sandboxcreated", {
|
7879 | source: this
|
7880 | });
|
7881 | } catch (error) {
|
7882 | Window['ngxConsole'].error(`PDFScriptingManager.setDocument: "${error?.message}".`);
|
7883 | await this._destroyScripting();
|
7884 | return;
|
7885 | }
|
7886 | await this._scripting?.dispatchEventInSandbox({
|
7887 | id: "doc",
|
7888 | name: "Open"
|
7889 | });
|
7890 | await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
|
7891 | Promise.resolve().then(() => {
|
7892 | if (pdfDocument === this._pdfDocument) {
|
7893 | this._ready = true;
|
7894 | }
|
7895 | });
|
7896 | }
|
7897 | async dispatchWillSave(detail) {
|
7898 | return this._scripting?.dispatchEventInSandbox({
|
7899 | id: "doc",
|
7900 | name: "WillSave"
|
7901 | });
|
7902 | }
|
7903 | async dispatchDidSave(detail) {
|
7904 | return this._scripting?.dispatchEventInSandbox({
|
7905 | id: "doc",
|
7906 | name: "DidSave"
|
7907 | });
|
7908 | }
|
7909 | async dispatchWillPrint(detail) {
|
7910 | return this._scripting?.dispatchEventInSandbox({
|
7911 | id: "doc",
|
7912 | name: "WillPrint"
|
7913 | });
|
7914 | }
|
7915 | async dispatchDidPrint(detail) {
|
7916 | return this._scripting?.dispatchEventInSandbox({
|
7917 | id: "doc",
|
7918 | name: "DidPrint"
|
7919 | });
|
7920 | }
|
7921 | get destroyPromise() {
|
7922 | return this._destroyCapability?.promise || null;
|
7923 | }
|
7924 | get ready() {
|
7925 | return this._ready;
|
7926 | }
|
7927 | get _internalEvents() {
|
7928 | return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
|
7929 | }
|
7930 | get _pageOpenPending() {
|
7931 | return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
|
7932 | }
|
7933 | get _visitedPages() {
|
7934 | return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
|
7935 | }
|
7936 | async _updateFromSandbox(detail) {
|
7937 | const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
|
7938 | const {
|
7939 | id,
|
7940 | siblings,
|
7941 | command,
|
7942 | value
|
7943 | } = detail;
|
7944 | if (!id) {
|
7945 | switch (command) {
|
7946 | case "clear":
|
7947 | Window['ngxConsole'].clear();
|
7948 | break;
|
7949 | case "error":
|
7950 | Window['ngxConsole'].error(value);
|
7951 | break;
|
7952 | case "layout":
|
7953 | {
|
7954 | if (isInPresentationMode) {
|
7955 | return;
|
7956 | }
|
7957 | const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
|
7958 | this._pdfViewer.spreadMode = modes.spreadMode;
|
7959 | break;
|
7960 | }
|
7961 | case "page-num":
|
7962 | this._pdfViewer.currentPageNumber = value + 1;
|
7963 | break;
|
7964 | case "print":
|
7965 | await this._pdfViewer.pagesPromise;
|
7966 | this._eventBus.dispatch("print", {
|
7967 | source: this
|
7968 | });
|
7969 | break;
|
7970 | case "println":
|
7971 | Window['ngxConsole'].log(value);
|
7972 | break;
|
7973 | case "zoom":
|
7974 | if (isInPresentationMode) {
|
7975 | return;
|
7976 | }
|
7977 | this._pdfViewer.currentScaleValue = value;
|
7978 | break;
|
7979 | case "SaveAs":
|
7980 | this._eventBus.dispatch("download", {
|
7981 | source: this
|
7982 | });
|
7983 | break;
|
7984 | case "FirstPage":
|
7985 | this._pdfViewer.currentPageNumber = 1;
|
7986 | break;
|
7987 | case "LastPage":
|
7988 | this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
|
7989 | break;
|
7990 | case "NextPage":
|
7991 | this._pdfViewer.nextPage();
|
7992 | break;
|
7993 | case "PrevPage":
|
7994 | this._pdfViewer.previousPage();
|
7995 | break;
|
7996 | case "ZoomViewIn":
|
7997 | if (isInPresentationMode) {
|
7998 | return;
|
7999 | }
|
8000 | this._pdfViewer.increaseScale();
|
8001 | break;
|
8002 | case "ZoomViewOut":
|
8003 | if (isInPresentationMode) {
|
8004 | return;
|
8005 | }
|
8006 | this._pdfViewer.decreaseScale();
|
8007 | break;
|
8008 | }
|
8009 | return;
|
8010 | }
|
8011 | if (isInPresentationMode) {
|
8012 | if (detail.focus) {
|
8013 | return;
|
8014 | }
|
8015 | }
|
8016 | delete detail.id;
|
8017 | delete detail.siblings;
|
8018 | const ids = siblings ? [id, ...siblings] : [id];
|
8019 | for (const elementId of ids) {
|
8020 | const element = document.querySelector(`[data-element-id="${elementId}"]`);
|
8021 | if (element) {
|
8022 | element.dispatchEvent(new CustomEvent("updatefromsandbox", {
|
8023 | detail
|
8024 | }));
|
8025 | } else {
|
8026 | this._pdfDocument?.annotationStorage.setValue(elementId, undefined, detail);
|
8027 | }
|
8028 | }
|
8029 | }
|
8030 | async _dispatchPageOpen(pageNumber, initialize = false) {
|
8031 | const pdfDocument = this._pdfDocument,
|
8032 | visitedPages = this._visitedPages;
|
8033 | if (initialize) {
|
8034 | this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
|
8035 | }
|
8036 | if (!this._closeCapability) {
|
8037 | return;
|
8038 | }
|
8039 | const pageView = this._pdfViewer.getPageView(pageNumber - 1);
|
8040 | if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
|
8041 | this._pageOpenPending.add(pageNumber);
|
8042 | return;
|
8043 | }
|
8044 | this._pageOpenPending.delete(pageNumber);
|
8045 | const actionsPromise = (async () => {
|
8046 | const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
|
8047 | if (pdfDocument !== this._pdfDocument) {
|
8048 | return;
|
8049 | }
|
8050 | await this._scripting?.dispatchEventInSandbox({
|
8051 | id: "page",
|
8052 | name: "PageOpen",
|
8053 | pageNumber,
|
8054 | actions
|
8055 | });
|
8056 | })();
|
8057 | visitedPages.set(pageNumber, actionsPromise);
|
8058 | }
|
8059 | async _dispatchPageClose(pageNumber) {
|
8060 | const pdfDocument = this._pdfDocument,
|
8061 | visitedPages = this._visitedPages;
|
8062 | if (!this._closeCapability) {
|
8063 | return;
|
8064 | }
|
8065 | if (this._pageOpenPending.has(pageNumber)) {
|
8066 | return;
|
8067 | }
|
8068 | const actionsPromise = visitedPages.get(pageNumber);
|
8069 | if (!actionsPromise) {
|
8070 | return;
|
8071 | }
|
8072 | visitedPages.set(pageNumber, null);
|
8073 | await actionsPromise;
|
8074 | if (pdfDocument !== this._pdfDocument) {
|
8075 | return;
|
8076 | }
|
8077 | await this._scripting?.dispatchEventInSandbox({
|
8078 | id: "page",
|
8079 | name: "PageClose",
|
8080 | pageNumber
|
8081 | });
|
8082 | }
|
8083 | async _getDocProperties() {
|
8084 | if (this._docPropertiesLookup) {
|
8085 | return this._docPropertiesLookup(this._pdfDocument);
|
8086 | }
|
8087 | throw new Error("_getDocProperties: Unable to lookup properties.");
|
8088 | }
|
8089 | _createScripting() {
|
8090 | this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
|
8091 | if (this._scripting) {
|
8092 | throw new Error("_createScripting: Scripting already exists.");
|
8093 | }
|
8094 | if (this._scriptingFactory) {
|
8095 | return this._scriptingFactory.createScripting({
|
8096 | sandboxBundleSrc: this._sandboxBundleSrc
|
8097 | });
|
8098 | }
|
8099 | throw new Error("_createScripting: Cannot create scripting.");
|
8100 | }
|
8101 | async _destroyScripting() {
|
8102 | if (!this._scripting) {
|
8103 | this._pdfDocument = null;
|
8104 | this._destroyCapability?.resolve();
|
8105 | return;
|
8106 | }
|
8107 | if (this._closeCapability) {
|
8108 | await Promise.race([this._closeCapability.promise, new Promise(resolve => {
|
8109 | setTimeout(resolve, 1000);
|
8110 | })]).catch(reason => {});
|
8111 | this._closeCapability = null;
|
8112 | }
|
8113 | this._pdfDocument = null;
|
8114 | try {
|
8115 | await this._scripting.destroySandbox();
|
8116 | } catch (ex) {}
|
8117 | for (const [name, listener] of this._internalEvents) {
|
8118 | this._eventBus._off(name, listener);
|
8119 | }
|
8120 | this._internalEvents.clear();
|
8121 | this._pageOpenPending.clear();
|
8122 | this._visitedPages.clear();
|
8123 | this._scripting = null;
|
8124 | this._ready = false;
|
8125 | this._destroyCapability?.resolve();
|
8126 | }
|
8127 | }
|
8128 | exports.PDFScriptingManager = PDFScriptingManager;
|
8129 |
|
8130 | }),
|
8131 |
|
8132 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
8133 |
|
8134 |
|
8135 |
|
8136 | Object.defineProperty(exports, "__esModule", ({
|
8137 | value: true
|
8138 | }));
|
8139 | exports.PDFSidebar = void 0;
|
8140 | var _ui_utils = __webpack_require__(3);
|
8141 | const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
|
8142 | class PDFSidebar {
|
8143 | constructor({
|
8144 | elements,
|
8145 | pdfViewer,
|
8146 | pdfThumbnailViewer,
|
8147 | eventBus,
|
8148 | l10n
|
8149 | }) {
|
8150 | this.isOpen = false;
|
8151 | this.active = _ui_utils.SidebarView.THUMBS;
|
8152 | this.isInitialViewSet = false;
|
8153 | this.isInitialEventDispatched = false;
|
8154 | this.onToggled = null;
|
8155 | this.pdfViewer = pdfViewer;
|
8156 | this.pdfThumbnailViewer = pdfThumbnailViewer;
|
8157 | this.outerContainer = elements.outerContainer;
|
8158 | this.sidebarContainer = elements.sidebarContainer;
|
8159 | this.toggleButton = elements.toggleButton;
|
8160 | this.thumbnailButton = elements.thumbnailButton;
|
8161 | this.outlineButton = elements.outlineButton;
|
8162 | this.attachmentsButton = elements.attachmentsButton;
|
8163 | this.layersButton = elements.layersButton;
|
8164 | this.thumbnailView = elements.thumbnailView;
|
8165 | this.outlineView = elements.outlineView;
|
8166 | this.attachmentsView = elements.attachmentsView;
|
8167 | this.layersView = elements.layersView;
|
8168 | this._outlineOptionsContainer = elements.outlineOptionsContainer;
|
8169 | this._currentOutlineItemButton = elements.currentOutlineItemButton;
|
8170 | this.eventBus = eventBus;
|
8171 | this.l10n = l10n;
|
8172 | this.#addEventListeners();
|
8173 | }
|
8174 | reset() {
|
8175 | this.isInitialViewSet = false;
|
8176 | this.isInitialEventDispatched = false;
|
8177 | this.#hideUINotification(true);
|
8178 | this.switchView(_ui_utils.SidebarView.THUMBS);
|
8179 | this.outlineButton.disabled = false;
|
8180 | this.attachmentsButton.disabled = false;
|
8181 | this.layersButton.disabled = false;
|
8182 | this.outlineButton.hidden = false;
|
8183 | this.attachmentsButton.hidden = false;
|
8184 | this.layersButton.hidden = false;
|
8185 | this._currentOutlineItemButton.disabled = true;
|
8186 | }
|
8187 | get visibleView() {
|
8188 | return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
|
8189 | }
|
8190 | setInitialView(view = _ui_utils.SidebarView.NONE) {
|
8191 | if (this.isInitialViewSet) {
|
8192 | return;
|
8193 | }
|
8194 | this.isInitialViewSet = true;
|
8195 | if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
|
8196 | this.#dispatchEvent();
|
8197 | return;
|
8198 | }
|
8199 | this.switchView(view, true);
|
8200 | if (!this.isInitialEventDispatched) {
|
8201 | this.#dispatchEvent();
|
8202 | }
|
8203 | }
|
8204 | switchView(view, forceOpen = false) {
|
8205 | const isViewChanged = view !== this.active;
|
8206 | let shouldForceRendering = false;
|
8207 | switch (view) {
|
8208 | case _ui_utils.SidebarView.NONE:
|
8209 | if (this.isOpen) {
|
8210 | this.close();
|
8211 | }
|
8212 | return;
|
8213 | case _ui_utils.SidebarView.THUMBS:
|
8214 | if (this.isOpen && isViewChanged) {
|
8215 | shouldForceRendering = true;
|
8216 | }
|
8217 | break;
|
8218 | case _ui_utils.SidebarView.OUTLINE:
|
8219 | if (this.outlineButton.disabled) {
|
8220 | return;
|
8221 | }
|
8222 | break;
|
8223 | case _ui_utils.SidebarView.ATTACHMENTS:
|
8224 | if (this.attachmentsButton.disabled) {
|
8225 | return;
|
8226 | }
|
8227 | break;
|
8228 | case _ui_utils.SidebarView.LAYERS:
|
8229 | if (this.layersButton.disabled) {
|
8230 | return;
|
8231 | }
|
8232 | break;
|
8233 | default:
|
8234 | Window['ngxConsole'].error(`PDFSidebar.switchView: "${view}" is not a valid view.`);
|
8235 | return;
|
8236 | }
|
8237 | this.active = view;
|
8238 | const isThumbs = view === _ui_utils.SidebarView.THUMBS,
|
8239 | isOutline = view === _ui_utils.SidebarView.OUTLINE,
|
8240 | isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
|
8241 | isLayers = view === _ui_utils.SidebarView.LAYERS;
|
8242 | this.thumbnailButton.classList.toggle("toggled", isThumbs);
|
8243 | this.outlineButton.classList.toggle("toggled", isOutline);
|
8244 | this.attachmentsButton.classList.toggle("toggled", isAttachments);
|
8245 | this.layersButton.classList.toggle("toggled", isLayers);
|
8246 | this.thumbnailButton.setAttribute("aria-checked", isThumbs);
|
8247 | this.outlineButton.setAttribute("aria-checked", isOutline);
|
8248 | this.attachmentsButton.setAttribute("aria-checked", isAttachments);
|
8249 | this.layersButton.setAttribute("aria-checked", isLayers);
|
8250 | this.thumbnailView.classList.toggle("hidden", !isThumbs);
|
8251 | this.outlineView.classList.toggle("hidden", !isOutline);
|
8252 | this.attachmentsView.classList.toggle("hidden", !isAttachments);
|
8253 | this.layersView.classList.toggle("hidden", !isLayers);
|
8254 | this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
|
8255 | if (forceOpen && !this.isOpen) {
|
8256 | this.open();
|
8257 | return;
|
8258 | }
|
8259 | if (shouldForceRendering) {
|
8260 | this.#updateThumbnailViewer();
|
8261 | this.#forceRendering();
|
8262 | }
|
8263 | if (isViewChanged) {
|
8264 | this.#dispatchEvent();
|
8265 | }
|
8266 | }
|
8267 | open() {
|
8268 | if (this.isOpen) {
|
8269 | return;
|
8270 | }
|
8271 | this.isOpen = true;
|
8272 | this.toggleButton.classList.add("toggled");
|
8273 | this.toggleButton.setAttribute("aria-expanded", "true");
|
8274 | this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
|
8275 | if (this.active === _ui_utils.SidebarView.THUMBS) {
|
8276 | this.#updateThumbnailViewer();
|
8277 | }
|
8278 | this.#forceRendering();
|
8279 | this.#dispatchEvent();
|
8280 | this.#hideUINotification();
|
8281 | }
|
8282 | close() {
|
8283 | if (!this.isOpen) {
|
8284 | return;
|
8285 | }
|
8286 | this.isOpen = false;
|
8287 | this.toggleButton.classList.remove("toggled");
|
8288 | this.toggleButton.setAttribute("aria-expanded", "false");
|
8289 | this.outerContainer.classList.add("sidebarMoving");
|
8290 | this.outerContainer.classList.remove("sidebarOpen");
|
8291 | this.#forceRendering();
|
8292 | this.#dispatchEvent();
|
8293 | }
|
8294 | toggle() {
|
8295 | if (this.isOpen) {
|
8296 | this.close();
|
8297 | } else {
|
8298 | this.open();
|
8299 | }
|
8300 | }
|
8301 | #dispatchEvent() {
|
8302 | if (this.isInitialViewSet && !this.isInitialEventDispatched) {
|
8303 | this.isInitialEventDispatched = true;
|
8304 | }
|
8305 | this.eventBus.dispatch("sidebarviewchanged", {
|
8306 | source: this,
|
8307 | view: this.visibleView
|
8308 | });
|
8309 | }
|
8310 | #forceRendering() {
|
8311 | if (this.onToggled) {
|
8312 | this.onToggled();
|
8313 | } else {
|
8314 | this.pdfViewer.forceRendering();
|
8315 | this.pdfThumbnailViewer.forceRendering();
|
8316 | }
|
8317 | }
|
8318 | #updateThumbnailViewer() {
|
8319 | const {
|
8320 | pdfViewer,
|
8321 | pdfThumbnailViewer
|
8322 | } = this;
|
8323 | const pagesCount = pdfViewer.pagesCount;
|
8324 | for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
|
8325 | const pageView = pdfViewer.getPageView(pageIndex);
|
8326 | if (pageView?.renderingState === _ui_utils.RenderingStates.FINISHED) {
|
8327 | const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
|
8328 | thumbnailView.setImage(pageView);
|
8329 | }
|
8330 | }
|
8331 | pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
|
8332 | }
|
8333 | #showUINotification() {
|
8334 | this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar_notification2");
|
8335 | this.l10n.translate(this.toggleButton);
|
8336 | if (!this.isOpen) {
|
8337 | this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
|
8338 | }
|
8339 | }
|
8340 | #hideUINotification(reset = false) {
|
8341 | if (this.isOpen || reset) {
|
8342 | this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
|
8343 | }
|
8344 | if (reset) {
|
8345 | this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
|
8346 | this.l10n.translate(this.toggleButton);
|
8347 | }
|
8348 | }
|
8349 | #addEventListeners() {
|
8350 | this.sidebarContainer.addEventListener("transitionend", evt => {
|
8351 | if (evt.target === this.sidebarContainer) {
|
8352 | this.outerContainer.classList.remove("sidebarMoving");
|
8353 | }
|
8354 | });
|
8355 | this.toggleButton.addEventListener("click", () => {
|
8356 | this.toggle();
|
8357 | });
|
8358 | this.thumbnailButton.addEventListener("click", () => {
|
8359 | this.switchView(_ui_utils.SidebarView.THUMBS);
|
8360 | });
|
8361 | this.outlineButton.addEventListener("click", () => {
|
8362 | this.switchView(_ui_utils.SidebarView.OUTLINE);
|
8363 | });
|
8364 | this.outlineButton.addEventListener("dblclick", () => {
|
8365 | this.eventBus.dispatch("toggleoutlinetree", {
|
8366 | source: this
|
8367 | });
|
8368 | });
|
8369 | this.attachmentsButton.addEventListener("click", () => {
|
8370 | this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
|
8371 | });
|
8372 | this.layersButton.addEventListener("click", () => {
|
8373 | this.switchView(_ui_utils.SidebarView.LAYERS);
|
8374 | });
|
8375 | this.layersButton.addEventListener("dblclick", () => {
|
8376 | this.eventBus.dispatch("resetlayers", {
|
8377 | source: this
|
8378 | });
|
8379 | });
|
8380 | this._currentOutlineItemButton.addEventListener("click", () => {
|
8381 | this.eventBus.dispatch("currentoutlineitem", {
|
8382 | source: this
|
8383 | });
|
8384 | });
|
8385 | const onTreeLoaded = (count, button, view) => {
|
8386 | button.disabled = !count;
|
8387 | button.hidden = !count;
|
8388 | if (count) {
|
8389 | this.#showUINotification();
|
8390 | } else if (this.active === view) {
|
8391 | this.switchView(_ui_utils.SidebarView.THUMBS);
|
8392 | }
|
8393 | };
|
8394 | this.eventBus._on("outlineloaded", evt => {
|
8395 | onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
|
8396 | if (evt.enableCurrentOutlineItemButton) {
|
8397 | if (evt.currentOutlineItemPromise) {
|
8398 | evt.currentOutlineItemPromise.then(enabled => {
|
8399 | if (!this.isInitialViewSet) {
|
8400 | return;
|
8401 | }
|
8402 | this._currentOutlineItemButton.disabled = !enabled;
|
8403 | });
|
8404 | }
|
8405 | }
|
8406 | });
|
8407 | this.eventBus._on("attachmentsloaded", evt => {
|
8408 | onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
|
8409 | });
|
8410 | this.eventBus._on("layersloaded", evt => {
|
8411 | onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
|
8412 | });
|
8413 | this.eventBus._on("presentationmodechanged", evt => {
|
8414 | if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.visibleView === _ui_utils.SidebarView.THUMBS) {
|
8415 | this.#updateThumbnailViewer();
|
8416 | }
|
8417 | });
|
8418 | }
|
8419 | }
|
8420 | exports.PDFSidebar = PDFSidebar;
|
8421 |
|
8422 | }),
|
8423 |
|
8424 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
8425 |
|
8426 |
|
8427 |
|
8428 | Object.defineProperty(exports, "__esModule", ({
|
8429 | value: true
|
8430 | }));
|
8431 | exports.PDFSidebarResizer = void 0;
|
8432 | var _ui_utils = __webpack_require__(3);
|
8433 | const SIDEBAR_WIDTH_VAR = "--sidebar-width";
|
8434 | const SIDEBAR_MIN_WIDTH = 200;
|
8435 | const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
|
8436 | class PDFSidebarResizer {
|
8437 | constructor(options, eventBus, l10n) {
|
8438 | this.isRTL = false;
|
8439 | this.sidebarOpen = false;
|
8440 | this._width = null;
|
8441 | this._outerContainerWidth = null;
|
8442 | this._boundEvents = Object.create(null);
|
8443 | this.outerContainer = options.outerContainer;
|
8444 | this.resizer = options.resizer;
|
8445 | this.eventBus = eventBus;
|
8446 | l10n.getDirection().then(dir => {
|
8447 | this.isRTL = dir === "rtl";
|
8448 | });
|
8449 | this._addEventListeners();
|
8450 | }
|
8451 | get outerContainerWidth() {
|
8452 | return this._outerContainerWidth ||= this.outerContainer.clientWidth;
|
8453 | }
|
8454 | _updateWidth(width = 0) {
|
8455 | const maxWidth = Math.floor(this.outerContainerWidth / 2);
|
8456 | if (width > maxWidth) {
|
8457 | width = maxWidth;
|
8458 | }
|
8459 | if (width < SIDEBAR_MIN_WIDTH) {
|
8460 | width = SIDEBAR_MIN_WIDTH;
|
8461 | }
|
8462 | if (width === this._width) {
|
8463 | return false;
|
8464 | }
|
8465 | this._width = width;
|
8466 | _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
|
8467 | return true;
|
8468 | }
|
8469 | _mouseMove(evt) {
|
8470 | let width = evt.clientX;
|
8471 | if (this.isRTL) {
|
8472 | width = this.outerContainerWidth - width;
|
8473 | }
|
8474 | this._updateWidth(width);
|
8475 | }
|
8476 | _mouseUp(evt) {
|
8477 | this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
|
8478 | this.eventBus.dispatch("resize", {
|
8479 | source: this
|
8480 | });
|
8481 | const _boundEvents = this._boundEvents;
|
8482 | window.removeEventListener("mousemove", _boundEvents.mouseMove);
|
8483 | window.removeEventListener("mouseup", _boundEvents.mouseUp);
|
8484 | }
|
8485 | _addEventListeners() {
|
8486 | const _boundEvents = this._boundEvents;
|
8487 | _boundEvents.mouseMove = this._mouseMove.bind(this);
|
8488 | _boundEvents.mouseUp = this._mouseUp.bind(this);
|
8489 | this.resizer.addEventListener("mousedown", evt => {
|
8490 | if (evt.button !== 0) {
|
8491 | return;
|
8492 | }
|
8493 | this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
|
8494 | window.addEventListener("mousemove", _boundEvents.mouseMove);
|
8495 | window.addEventListener("mouseup", _boundEvents.mouseUp);
|
8496 | });
|
8497 | this.eventBus._on("sidebarviewchanged", evt => {
|
8498 | this.sidebarOpen = !!evt?.view;
|
8499 | });
|
8500 | this.eventBus._on("resize", evt => {
|
8501 | if (evt?.source !== window) {
|
8502 | return;
|
8503 | }
|
8504 | this._outerContainerWidth = null;
|
8505 | if (!this._width) {
|
8506 | return;
|
8507 | }
|
8508 | if (!this.sidebarOpen) {
|
8509 | this._updateWidth(this._width);
|
8510 | return;
|
8511 | }
|
8512 | this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
|
8513 | const updated = this._updateWidth(this._width);
|
8514 | Promise.resolve().then(() => {
|
8515 | this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
|
8516 | if (updated) {
|
8517 | this.eventBus.dispatch("resize", {
|
8518 | source: this
|
8519 | });
|
8520 | }
|
8521 | });
|
8522 | });
|
8523 | }
|
8524 | }
|
8525 | exports.PDFSidebarResizer = PDFSidebarResizer;
|
8526 |
|
8527 | }),
|
8528 |
|
8529 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
8530 |
|
8531 |
|
8532 |
|
8533 | Object.defineProperty(exports, "__esModule", ({
|
8534 | value: true
|
8535 | }));
|
8536 | exports.PDFThumbnailViewer = void 0;
|
8537 | var _ui_utils = __webpack_require__(3);
|
8538 | var _pdf_thumbnail_view = __webpack_require__(30);
|
8539 | const THUMBNAIL_SCROLL_MARGIN = -19;
|
8540 | const THUMBNAIL_SELECTED_CLASS = "selected";
|
8541 | class PDFThumbnailViewer {
|
8542 | constructor({
|
8543 | container,
|
8544 | linkService,
|
8545 | renderingQueue,
|
8546 | l10n,
|
8547 | pageColors
|
8548 | }) {
|
8549 | this.container = container;
|
8550 | this.linkService = linkService;
|
8551 | this.renderingQueue = renderingQueue;
|
8552 | this.l10n = l10n;
|
8553 | this.pageColors = pageColors || null;
|
8554 | if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
|
8555 | if (this.pageColors.background || this.pageColors.foreground) {
|
8556 | Window["ngxConsole"].warn("PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
|
8557 | }
|
8558 | this.pageColors = null;
|
8559 | }
|
8560 | this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
|
8561 | this._resetView();
|
8562 | }
|
8563 | _scrollUpdated() {
|
8564 | this.renderingQueue.renderHighestPriority();
|
8565 | }
|
8566 | getThumbnail(index) {
|
8567 | return this._thumbnails[index];
|
8568 | }
|
8569 | _getVisibleThumbs() {
|
8570 | return (0, _ui_utils.getVisibleElements)({
|
8571 | scrollEl: this.container,
|
8572 | views: this._thumbnails
|
8573 | });
|
8574 | }
|
8575 | scrollThumbnailIntoView(pageNumber) {
|
8576 | if (!this.pdfDocument) {
|
8577 | return;
|
8578 | }
|
8579 | const thumbnailView = this._thumbnails[pageNumber - 1];
|
8580 | if (!thumbnailView) {
|
8581 | Window["ngxConsole"].error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
|
8582 | return;
|
8583 | }
|
8584 | if (pageNumber !== this._currentPageNumber) {
|
8585 | const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
|
8586 | prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
|
8587 | thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
8588 | }
|
8589 | const {
|
8590 | first,
|
8591 | last,
|
8592 | views
|
8593 | } = this._getVisibleThumbs();
|
8594 | if (views.length > 0) {
|
8595 | let shouldScroll = false;
|
8596 | if (pageNumber <= first.id || pageNumber >= last.id) {
|
8597 | shouldScroll = true;
|
8598 | } else {
|
8599 | for (const {
|
8600 | id,
|
8601 | percent
|
8602 | } of views) {
|
8603 | if (id !== pageNumber) {
|
8604 | continue;
|
8605 | }
|
8606 | shouldScroll = percent < 100;
|
8607 | break;
|
8608 | }
|
8609 | }
|
8610 | if (shouldScroll) {
|
8611 | (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
|
8612 | top: THUMBNAIL_SCROLL_MARGIN
|
8613 | });
|
8614 | }
|
8615 | }
|
8616 | this._currentPageNumber = pageNumber;
|
8617 | }
|
8618 | get pagesRotation() {
|
8619 | return this._pagesRotation;
|
8620 | }
|
8621 | set pagesRotation(rotation) {
|
8622 | if (!(0, _ui_utils.isValidRotation)(rotation)) {
|
8623 | throw new Error("Invalid thumbnails rotation angle.");
|
8624 | }
|
8625 | if (!this.pdfDocument) {
|
8626 | return;
|
8627 | }
|
8628 | if (this._pagesRotation === rotation) {
|
8629 | return;
|
8630 | }
|
8631 | this._pagesRotation = rotation;
|
8632 | const updateArgs = {
|
8633 | rotation
|
8634 | };
|
8635 | for (const thumbnail of this._thumbnails) {
|
8636 | thumbnail.update(updateArgs);
|
8637 | }
|
8638 | }
|
8639 | cleanup() {
|
8640 | for (const thumbnail of this._thumbnails) {
|
8641 | if (thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED) {
|
8642 | thumbnail.reset();
|
8643 | }
|
8644 | }
|
8645 | _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
|
8646 | }
|
8647 | _resetView() {
|
8648 | this._thumbnails = [];
|
8649 | this._currentPageNumber = 1;
|
8650 | this._pageLabels = null;
|
8651 | this._pagesRotation = 0;
|
8652 | this.container.textContent = "";
|
8653 | }
|
8654 | setDocument(pdfDocument) {
|
8655 | this.initialized = false;
|
8656 | if (this.pdfDocument) {
|
8657 | this._cancelRendering();
|
8658 | this._resetView();
|
8659 | }
|
8660 | this.pdfDocument = pdfDocument;
|
8661 | if (!pdfDocument) {
|
8662 | return;
|
8663 | }
|
8664 | if (this.initialized) {
|
8665 | return;
|
8666 | }
|
8667 | this.initialized = true;
|
8668 | const firstPagePromise = pdfDocument.getPage(1);
|
8669 | const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
|
8670 | firstPagePromise.then(firstPdfPage => {
|
8671 | const pagesCount = pdfDocument.numPages;
|
8672 | const viewport = firstPdfPage.getViewport({
|
8673 | scale: 1
|
8674 | });
|
8675 | for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
8676 | const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
|
8677 | container: this.container,
|
8678 | id: pageNum,
|
8679 | defaultViewport: viewport.clone(),
|
8680 | optionalContentConfigPromise,
|
8681 | linkService: this.linkService,
|
8682 | renderingQueue: this.renderingQueue,
|
8683 | l10n: this.l10n,
|
8684 | pageColors: this.pageColors
|
8685 | });
|
8686 | this._thumbnails.push(thumbnail);
|
8687 | }
|
8688 | this._thumbnails[0]?.setPdfPage(firstPdfPage);
|
8689 | const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
|
8690 | thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
8691 | }).catch(reason => {
|
8692 | Window["ngxConsole"].error("Unable to initialize thumbnail viewer", reason);
|
8693 | });
|
8694 | }
|
8695 | _cancelRendering() {
|
8696 | for (const thumbnail of this._thumbnails) {
|
8697 | thumbnail.cancelRendering();
|
8698 | }
|
8699 | }
|
8700 | setPageLabels(labels) {
|
8701 | if (!this.pdfDocument) {
|
8702 | return;
|
8703 | }
|
8704 | if (!labels) {
|
8705 | this._pageLabels = null;
|
8706 | } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
|
8707 | this._pageLabels = null;
|
8708 | Window["ngxConsole"].error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
|
8709 | } else {
|
8710 | this._pageLabels = labels;
|
8711 | }
|
8712 | for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
8713 | this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
|
8714 | }
|
8715 | }
|
8716 | async #ensurePdfPageLoaded(thumbView) {
|
8717 | if (thumbView.pdfPage) {
|
8718 | return thumbView.pdfPage;
|
8719 | }
|
8720 | try {
|
8721 | const pdfPage = await this.pdfDocument.getPage(thumbView.id);
|
8722 | if (!thumbView.pdfPage) {
|
8723 | thumbView.setPdfPage(pdfPage);
|
8724 | }
|
8725 | return pdfPage;
|
8726 | } catch (reason) {
|
8727 | Window["ngxConsole"].error("Unable to get page for thumb view", reason);
|
8728 | return null;
|
8729 | }
|
8730 | }
|
8731 | #getScrollAhead(visible) {
|
8732 | if (visible.first?.id === 1) {
|
8733 | return true;
|
8734 | } else if (visible.last?.id === this._thumbnails.length) {
|
8735 | return false;
|
8736 | }
|
8737 | return this.scroll.down;
|
8738 | }
|
8739 | forceRendering() {
|
8740 | const visibleThumbs = this._getVisibleThumbs();
|
8741 | const scrollAhead = this.#getScrollAhead(visibleThumbs);
|
8742 | const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
|
8743 | if (thumbView) {
|
8744 | this.#ensurePdfPageLoaded(thumbView).then(() => {
|
8745 | this.renderingQueue.renderView(thumbView);
|
8746 | });
|
8747 | return true;
|
8748 | }
|
8749 | return false;
|
8750 | }
|
8751 | }
|
8752 | exports.PDFThumbnailViewer = PDFThumbnailViewer;
|
8753 |
|
8754 | }),
|
8755 |
|
8756 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
8757 |
|
8758 |
|
8759 |
|
8760 | Object.defineProperty(exports, "__esModule", ({
|
8761 | value: true
|
8762 | }));
|
8763 | exports.TempImageFactory = exports.PDFThumbnailView = void 0;
|
8764 | var _ui_utils = __webpack_require__(3);
|
8765 | var _pdfjsLib = __webpack_require__(4);
|
8766 | const DRAW_UPSCALE_FACTOR = 2;
|
8767 | const MAX_NUM_SCALING_STEPS = 3;
|
8768 | const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
|
8769 | const THUMBNAIL_WIDTH = 98;
|
8770 | class TempImageFactory {
|
8771 | static #tempCanvas = null;
|
8772 | static getCanvas(width, height) {
|
8773 | const tempCanvas = this.#tempCanvas ||= document.createElement("canvas");
|
8774 | tempCanvas.width = width;
|
8775 | tempCanvas.height = height;
|
8776 | const options1 = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {
|
8777 | willReadFrequently: true,
|
8778 | alpha: false
|
8779 | } : {
|
8780 | alpha: false
|
8781 | };
|
8782 | const options2 = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {
|
8783 | willReadFrequently: true
|
8784 | } : undefined;
|
8785 | const ctx = tempCanvas.getContext("2d", options1);
|
8786 | ctx.save();
|
8787 | ctx.fillStyle = "rgb(255, 255, 255)";
|
8788 | ctx.fillRect(0, 0, width, height);
|
8789 | ctx.restore();
|
8790 | return [tempCanvas, tempCanvas.getContext("2d", options2)];
|
8791 | }
|
8792 | static destroyCanvas() {
|
8793 | const tempCanvas = this.#tempCanvas;
|
8794 | if (tempCanvas) {
|
8795 | tempCanvas.width = 0;
|
8796 | tempCanvas.height = 0;
|
8797 | }
|
8798 | this.#tempCanvas = null;
|
8799 | }
|
8800 | }
|
8801 | exports.TempImageFactory = TempImageFactory;
|
8802 | class PDFThumbnailView {
|
8803 | constructor({
|
8804 | container,
|
8805 | id,
|
8806 | defaultViewport,
|
8807 | optionalContentConfigPromise,
|
8808 | linkService,
|
8809 | renderingQueue,
|
8810 | l10n,
|
8811 | pageColors
|
8812 | }) {
|
8813 | this.id = id;
|
8814 | this.renderingId = "thumbnail" + id;
|
8815 | this.pageLabel = null;
|
8816 | this.pdfPage = null;
|
8817 | this.rotation = 0;
|
8818 | this.viewport = defaultViewport;
|
8819 | this.pdfPageRotate = defaultViewport.rotation;
|
8820 | this._optionalContentConfigPromise = optionalContentConfigPromise || null;
|
8821 | this.pageColors = pageColors || null;
|
8822 | this.linkService = linkService;
|
8823 | this.renderingQueue = renderingQueue;
|
8824 | this.renderTask = null;
|
8825 | this.renderingState = _ui_utils.RenderingStates.INITIAL;
|
8826 | this.resume = null;
|
8827 | const pageWidth = this.viewport.width,
|
8828 | pageHeight = this.viewport.height,
|
8829 | pageRatio = pageWidth / pageHeight;
|
8830 | this.canvasWidth = THUMBNAIL_WIDTH;
|
8831 | this.canvasHeight = this.canvasWidth / pageRatio | 0;
|
8832 | this.scale = this.canvasWidth / pageWidth;
|
8833 | this.l10n = l10n;
|
8834 | if (window.pdfThumbnailGenerator) {
|
8835 | window.pdfThumbnailGenerator(this, linkService, id, container, this._thumbPageTitle);
|
8836 | } else {
|
8837 | this.createThumbnail(this, linkService, id, container, this._thumbPageTitle);
|
8838 | }
|
8839 | }
|
8840 | createThumbnail(pdfThumbnailView, linkService, id, container, thumbPageTitlePromise) {
|
8841 | const anchor = document.createElement("a");
|
8842 | anchor.href = linkService.getAnchorUrl("#page=" + id);
|
8843 | thumbPageTitlePromise.then(msg => {
|
8844 | anchor.title = msg;
|
8845 | });
|
8846 | anchor.onclick = function () {
|
8847 | linkService.goToPage(id);
|
8848 | return false;
|
8849 | };
|
8850 | pdfThumbnailView.anchor = anchor;
|
8851 | const div = document.createElement("div");
|
8852 | div.className = "thumbnail";
|
8853 | div.setAttribute("data-page-number", this.id);
|
8854 | pdfThumbnailView.div = div;
|
8855 | const ring = document.createElement("div");
|
8856 | ring.className = "thumbnailSelectionRing";
|
8857 | const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
8858 | ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
8859 | ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
8860 | pdfThumbnailView.ring = ring;
|
8861 | div.append(ring);
|
8862 | anchor.append(div);
|
8863 | container.append(anchor);
|
8864 | }
|
8865 | setPdfPage(pdfPage) {
|
8866 | this.pdfPage = pdfPage;
|
8867 | this.pdfPageRotate = pdfPage.rotate;
|
8868 | const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
8869 | this.viewport = pdfPage.getViewport({
|
8870 | scale: 1,
|
8871 | rotation: totalRotation
|
8872 | });
|
8873 | this.reset();
|
8874 | }
|
8875 | reset() {
|
8876 | this.cancelRendering();
|
8877 | this.renderingState = _ui_utils.RenderingStates.INITIAL;
|
8878 | const pageWidth = this.viewport.width,
|
8879 | pageHeight = this.viewport.height,
|
8880 | pageRatio = pageWidth / pageHeight;
|
8881 | this.canvasHeight = this.canvasWidth / pageRatio | 0;
|
8882 | this.scale = this.canvasWidth / pageWidth;
|
8883 | this.div.removeAttribute("data-loaded");
|
8884 | const ring = this.ring;
|
8885 | ring.textContent = "";
|
8886 | const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
8887 | ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
8888 | ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
8889 | if (this.canvas) {
|
8890 | this.canvas.width = 0;
|
8891 | this.canvas.height = 0;
|
8892 | delete this.canvas;
|
8893 | }
|
8894 | if (this.image) {
|
8895 | this.image.removeAttribute("src");
|
8896 | delete this.image;
|
8897 | }
|
8898 | }
|
8899 | update({
|
8900 | rotation = null
|
8901 | }) {
|
8902 | if (typeof rotation === "number") {
|
8903 | this.rotation = rotation;
|
8904 | }
|
8905 | const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
8906 | this.viewport = this.viewport.clone({
|
8907 | scale: 1,
|
8908 | rotation: totalRotation
|
8909 | });
|
8910 | this.reset();
|
8911 | }
|
8912 | cancelRendering() {
|
8913 | if (this.renderTask) {
|
8914 | this.renderTask.cancel();
|
8915 | this.renderTask = null;
|
8916 | }
|
8917 | this.resume = null;
|
8918 | }
|
8919 | _getPageDrawContext(upscaleFactor = 1) {
|
8920 | const canvas = document.createElement("canvas");
|
8921 | const options = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {
|
8922 | willReadFrequently: true,
|
8923 | alpha: false
|
8924 | } : {
|
8925 | alpha: false
|
8926 | };
|
8927 | const ctx = canvas.getContext("2d", options);
|
8928 | const outputScale = new _ui_utils.OutputScale();
|
8929 | canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
|
8930 | canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
|
8931 | const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
|
8932 | return {
|
8933 | ctx,
|
8934 | canvas,
|
8935 | transform
|
8936 | };
|
8937 | }
|
8938 | _convertCanvasToImage(canvas) {
|
8939 | if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
|
8940 | throw new Error("_convertCanvasToImage: Rendering has not finished.");
|
8941 | }
|
8942 | const reducedCanvas = this._reduceImage(canvas);
|
8943 | const image = document.createElement("img");
|
8944 | image.className = "thumbnailImage";
|
8945 | this._thumbPageCanvas.then(msg => {
|
8946 | image.setAttribute("aria-label", msg);
|
8947 | });
|
8948 | image.style.width = this.canvasWidth + "px";
|
8949 | image.style.height = this.canvasHeight + "px";
|
8950 | image.src = reducedCanvas.toDataURL();
|
8951 | this.image = image;
|
8952 | this.div.setAttribute("data-loaded", true);
|
8953 | this.ring.append(image);
|
8954 | reducedCanvas.width = 0;
|
8955 | reducedCanvas.height = 0;
|
8956 | }
|
8957 | draw() {
|
8958 | if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
|
8959 | Window['ngxConsole'].error("Must be in new state before drawing");
|
8960 | return Promise.resolve();
|
8961 | }
|
8962 | const {
|
8963 | pdfPage
|
8964 | } = this;
|
8965 | if (!pdfPage) {
|
8966 | this.renderingState = _ui_utils.RenderingStates.FINISHED;
|
8967 | return Promise.reject(new Error("pdfPage is not loaded"));
|
8968 | }
|
8969 | this.renderingState = _ui_utils.RenderingStates.RUNNING;
|
8970 | const finishRenderTask = async (error = null) => {
|
8971 | if (renderTask === this.renderTask) {
|
8972 | this.renderTask = null;
|
8973 | }
|
8974 | if (error instanceof _pdfjsLib.RenderingCancelledException) {
|
8975 | return;
|
8976 | }
|
8977 | this.renderingState = _ui_utils.RenderingStates.FINISHED;
|
8978 | this._convertCanvasToImage(canvas);
|
8979 | if (error) {
|
8980 | throw error;
|
8981 | }
|
8982 | };
|
8983 | const {
|
8984 | ctx,
|
8985 | canvas,
|
8986 | transform
|
8987 | } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
|
8988 | const drawViewport = this.viewport.clone({
|
8989 | scale: DRAW_UPSCALE_FACTOR * this.scale
|
8990 | });
|
8991 | const renderContinueCallback = cont => {
|
8992 | if (!this.renderingQueue.isHighestPriority(this)) {
|
8993 | this.renderingState = _ui_utils.RenderingStates.PAUSED;
|
8994 | this.resume = () => {
|
8995 | this.renderingState = _ui_utils.RenderingStates.RUNNING;
|
8996 | cont();
|
8997 | };
|
8998 | return;
|
8999 | }
|
9000 | cont();
|
9001 | };
|
9002 | const renderContext = {
|
9003 | canvasContext: ctx,
|
9004 | transform,
|
9005 | viewport: drawViewport,
|
9006 | optionalContentConfigPromise: this._optionalContentConfigPromise,
|
9007 | background: PDFViewerApplicationOptions.get("pdfBackgroundColor"),
|
9008 | pageColors: this.pageColors
|
9009 | };
|
9010 | const renderTask = this.renderTask = pdfPage.render(renderContext);
|
9011 | renderTask.onContinue = renderContinueCallback;
|
9012 | const resultPromise = renderTask.promise.then(function () {
|
9013 | return finishRenderTask(null);
|
9014 | }, function (error) {
|
9015 | return finishRenderTask(error);
|
9016 | });
|
9017 | resultPromise.finally(() => {
|
9018 | canvas.width = 0;
|
9019 | canvas.height = 0;
|
9020 | const pageCached = this.linkService.isPageCached(this.id);
|
9021 | if (!pageCached) {
|
9022 | this.pdfPage?.cleanup();
|
9023 | }
|
9024 | });
|
9025 | return resultPromise;
|
9026 | }
|
9027 | setImage(pageView) {
|
9028 | if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
|
9029 | return;
|
9030 | }
|
9031 | const {
|
9032 | thumbnailCanvas: canvas,
|
9033 | pdfPage,
|
9034 | scale
|
9035 | } = pageView;
|
9036 | if (!canvas) {
|
9037 | return;
|
9038 | }
|
9039 | if (!this.pdfPage) {
|
9040 | this.setPdfPage(pdfPage);
|
9041 | }
|
9042 | if (scale < this.scale) {
|
9043 | return;
|
9044 | }
|
9045 | this.renderingState = _ui_utils.RenderingStates.FINISHED;
|
9046 | this._convertCanvasToImage(canvas);
|
9047 | }
|
9048 | _reduceImage(img) {
|
9049 | const {
|
9050 | ctx,
|
9051 | canvas
|
9052 | } = this._getPageDrawContext();
|
9053 | if (img.width <= 2 * canvas.width) {
|
9054 | ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
|
9055 | return canvas;
|
9056 | }
|
9057 | let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
9058 | let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
9059 | const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
9060 | while (reducedWidth > img.width || reducedHeight > img.height) {
|
9061 | reducedWidth >>= 1;
|
9062 | reducedHeight >>= 1;
|
9063 | }
|
9064 | reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
|
9065 | while (reducedWidth > 2 * canvas.width) {
|
9066 | reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
|
9067 | reducedWidth >>= 1;
|
9068 | reducedHeight >>= 1;
|
9069 | }
|
9070 | ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
|
9071 | return canvas;
|
9072 | }
|
9073 | get _thumbPageTitle() {
|
9074 | return this.l10n.get("thumb_page_title", {
|
9075 | page: this.pageLabel ?? this.id
|
9076 | });
|
9077 | }
|
9078 | get _thumbPageCanvas() {
|
9079 | return this.l10n.get("thumb_page_canvas", {
|
9080 | page: this.pageLabel ?? this.id
|
9081 | });
|
9082 | }
|
9083 | setPageLabel(label) {
|
9084 | this.pageLabel = typeof label === "string" ? label : null;
|
9085 | this._thumbPageTitle.then(msg => {
|
9086 | this.anchor.title = msg;
|
9087 | });
|
9088 | if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
|
9089 | return;
|
9090 | }
|
9091 | this._thumbPageCanvas.then(msg => {
|
9092 | this.image?.setAttribute("aria-label", msg);
|
9093 | });
|
9094 | }
|
9095 | }
|
9096 | exports.PDFThumbnailView = PDFThumbnailView;
|
9097 |
|
9098 | }),
|
9099 |
|
9100 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
9101 |
|
9102 |
|
9103 |
|
9104 | Object.defineProperty(exports, "__esModule", ({
|
9105 | value: true
|
9106 | }));
|
9107 | exports.PagesCountLimit = exports.PDFViewer = exports.PDFPageViewBuffer = void 0;
|
9108 | var _pdfjsLib = __webpack_require__(4);
|
9109 | var _ui_utils = __webpack_require__(3);
|
9110 | var _l10n_utils = __webpack_require__(32);
|
9111 | var _pageFlipModule = __webpack_require__(33);
|
9112 | var _pdf_page_view = __webpack_require__(34);
|
9113 | var _pdf_rendering_queue = __webpack_require__(25);
|
9114 | var _pdf_link_service = __webpack_require__(7);
|
9115 | const DEFAULT_CACHE_SIZE = 10;
|
9116 | const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
|
9117 | const PagesCountLimit = {
|
9118 | FORCE_SCROLL_MODE_PAGE: 15000,
|
9119 | FORCE_LAZY_PAGE_INIT: 7500,
|
9120 | PAUSE_EAGER_PAGE_INIT: 250
|
9121 | };
|
9122 | exports.PagesCountLimit = PagesCountLimit;
|
9123 | function isValidAnnotationEditorMode(mode) {
|
9124 | return Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) && mode !== _pdfjsLib.AnnotationEditorType.DISABLE;
|
9125 | }
|
9126 | class PDFPageViewBuffer {
|
9127 | #buf = new Set();
|
9128 | #size = 0;
|
9129 | constructor(size) {
|
9130 | this.#size = size;
|
9131 | }
|
9132 | push(view) {
|
9133 | const buf = this.#buf;
|
9134 | if (buf.has(view)) {
|
9135 | buf.delete(view);
|
9136 | }
|
9137 | buf.add(view);
|
9138 | if (buf.size > this.#size) {
|
9139 | this.#destroyFirstView();
|
9140 | }
|
9141 | }
|
9142 | resize(newSize, idsToKeep = null) {
|
9143 | this.#size = newSize;
|
9144 | const buf = this.#buf;
|
9145 | if (idsToKeep) {
|
9146 | const ii = buf.size;
|
9147 | let i = 1;
|
9148 | for (const view of buf) {
|
9149 | if (idsToKeep.has(view.id)) {
|
9150 | buf.delete(view);
|
9151 | buf.add(view);
|
9152 | }
|
9153 | if (++i > ii) {
|
9154 | break;
|
9155 | }
|
9156 | }
|
9157 | }
|
9158 | while (buf.size > this.#size) {
|
9159 | this.#destroyFirstView();
|
9160 | }
|
9161 | }
|
9162 | has(view) {
|
9163 | return this.#buf.has(view);
|
9164 | }
|
9165 | [Symbol.iterator]() {
|
9166 | return this.#buf.keys();
|
9167 | }
|
9168 | #destroyFirstView() {
|
9169 | const firstView = this.#buf.keys().next().value;
|
9170 | firstView?.destroy();
|
9171 | this.#buf.delete(firstView);
|
9172 | }
|
9173 | }
|
9174 | exports.PDFPageViewBuffer = PDFPageViewBuffer;
|
9175 | class PDFViewer {
|
9176 | #buffer = null;
|
9177 | #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
|
9178 | #annotationEditorUIManager = null;
|
9179 | #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
|
9180 | #containerTopLeft = null;
|
9181 | #enablePermissions = false;
|
9182 | #previousContainerHeight = 0;
|
9183 | #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
|
9184 | #scrollModePageState = null;
|
9185 | #onVisibilityChange = null;
|
9186 | #scaleTimeoutId = null;
|
9187 | constructor(options) {
|
9188 | const viewerVersion = '3.4.493';
|
9189 | if (_pdfjsLib.version !== viewerVersion) {
|
9190 | throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
|
9191 | }
|
9192 | this.container = options.container;
|
9193 | this.viewer = options.viewer || options.container.firstElementChild;
|
9194 | this.pageViewMode = options.pageViewMode || "multiple";
|
9195 | if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
|
9196 | throw new Error("Invalid `container` and/or `viewer` option.");
|
9197 | }
|
9198 | if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
|
9199 | throw new Error("The `container` must be absolutely positioned.");
|
9200 | }
|
9201 | this.#resizeObserver.observe(this.container);
|
9202 | this.eventBus = options.eventBus;
|
9203 | this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
|
9204 | this.downloadManager = options.downloadManager || null;
|
9205 | this.findController = options.findController || null;
|
9206 | this._scriptingManager = options.scriptingManager || null;
|
9207 | this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
|
9208 | this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
|
9209 | this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
|
9210 | this.imageResourcesPath = options.imageResourcesPath || "";
|
9211 | this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
|
9212 | this.removePageBorders = options.removePageBorders || false;
|
9213 | this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
|
9214 | this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
9215 | this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
|
9216 | this.maxCanvasPixels = options.maxCanvasPixels;
|
9217 | this.l10n = options.l10n || _l10n_utils.NullL10n;
|
9218 | this.#enablePermissions = options.enablePermissions || false;
|
9219 | this.pageColors = options.pageColors || null;
|
9220 | if (this.pageColors && !(CSS.supports("color", this.pageColors.background) && CSS.supports("color", this.pageColors.foreground))) {
|
9221 | if (this.pageColors.background || this.pageColors.foreground) {
|
9222 | console.warn("PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used.");
|
9223 | }
|
9224 | this.pageColors = null;
|
9225 | }
|
9226 | this.defaultRenderingQueue = !options.renderingQueue;
|
9227 | if (this.defaultRenderingQueue) {
|
9228 | this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
|
9229 | this.renderingQueue.setViewer(this);
|
9230 | } else {
|
9231 | this.renderingQueue = options.renderingQueue;
|
9232 | }
|
9233 | this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
|
9234 | this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
|
9235 | this._onBeforeDraw = this._onAfterDraw = null;
|
9236 | this._resetView();
|
9237 | if (this.removePageBorders) {
|
9238 | this.viewer.classList.add("removePageBorders");
|
9239 | }
|
9240 | this.#updateContainerHeightCss();
|
9241 | }
|
9242 | get pagesCount() {
|
9243 | return this._pages.length;
|
9244 | }
|
9245 | getPageView(index) {
|
9246 | return this._pages[index];
|
9247 | }
|
9248 | get pageViewsReady() {
|
9249 | if (!this._pagesCapability.settled) {
|
9250 | return false;
|
9251 | }
|
9252 | return this._pages.every(function (pageView) {
|
9253 | return pageView?.pdfPage;
|
9254 | });
|
9255 | }
|
9256 | get renderForms() {
|
9257 | return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
|
9258 | }
|
9259 | get enableScripting() {
|
9260 | return !!this._scriptingManager;
|
9261 | }
|
9262 | get currentPageNumber() {
|
9263 | return this._currentPageNumber;
|
9264 | }
|
9265 | set currentPageNumber(val) {
|
9266 | if (!Number.isInteger(val)) {
|
9267 | throw new Error("Invalid page number.");
|
9268 | }
|
9269 | if (!this.pdfDocument) {
|
9270 | return;
|
9271 | }
|
9272 | const flip = Math.abs(this._currentPageNumber - val) < 2;
|
9273 | if (!this._setCurrentPageNumber(val, true)) {
|
9274 | Window["ngxConsole"].error(`currentPageNumber: "${val}" is not a valid page.`);
|
9275 | }
|
9276 | if (this.pageFlip) {
|
9277 | if (flip) {
|
9278 | Window["ngxConsole"].log("Flip");
|
9279 | this.pageFlip.flip(val - 1);
|
9280 | } else {
|
9281 | Window["ngxConsole"].log("turn to page");
|
9282 | this.pageFlip.turnToPage(val - 1);
|
9283 | }
|
9284 | }
|
9285 | }
|
9286 | hidePagesDependingOnpageViewMode() {
|
9287 | if (this.pageViewMode === "book") {
|
9288 | if (!this.pageFlip) {
|
9289 | setTimeout(() => {
|
9290 | if (!this.pageFlip) {
|
9291 | const page1 = this._pages[0].div;
|
9292 | const htmlParentElement = page1.parentElement;
|
9293 | const viewer = htmlParentElement.parentElement;
|
9294 | viewer.style.width = 2 * page1.clientWidth + "px";
|
9295 | viewer.style.overflow = "hidden";
|
9296 | viewer.style.marginLeft = "auto";
|
9297 | viewer.style.marginRight = "auto";
|
9298 | this.pageFlip = new _pageFlipModule.PageFlip(htmlParentElement, {
|
9299 | width: page1.clientWidth,
|
9300 | height: page1.clientHeight,
|
9301 | showCover: true,
|
9302 | size: "fixed"
|
9303 | });
|
9304 | this.pageFlip.loadFromHTML(document.querySelectorAll(".page"));
|
9305 | this.ensureAdjecentPagesAreLoaded();
|
9306 | this.pageFlip.on("flip", e => {
|
9307 | if (this._currentPageNumber !== e.data + 1) {
|
9308 | this._setCurrentPageNumber(e.data + 1, false);
|
9309 | }
|
9310 | });
|
9311 | }
|
9312 | }, 100);
|
9313 | }
|
9314 | }
|
9315 | }
|
9316 | _setCurrentPageNumber(val, resetCurrentPageView = false) {
|
9317 | if (this._currentPageNumber === val) {
|
9318 | if (resetCurrentPageView) {
|
9319 | this.#resetCurrentPageView();
|
9320 | }
|
9321 | return true;
|
9322 | }
|
9323 | if (!(0 < val && val <= this.pagesCount)) {
|
9324 | return false;
|
9325 | }
|
9326 | const previous = this._currentPageNumber;
|
9327 | this._currentPageNumber = val;
|
9328 | this.hidePagesDependingOnpageViewMode();
|
9329 | if (this.pageViewMode === "book" || this.pageViewMode === "infinite-scroll") {
|
9330 | const pageView = this._pages[this.currentPageNumber - 1];
|
9331 | if (pageView.div.parentElement.classList.contains("spread")) {
|
9332 | pageView.div.parentElement.childNodes.forEach(div => {
|
9333 | const pageNumber = Number(div.getAttribute("data-page-number"));
|
9334 | const pv = this._pages[pageNumber - 1];
|
9335 | this.#ensurePdfPageLoaded(pv).then(() => {
|
9336 | this.renderingQueue.renderView(pv);
|
9337 | });
|
9338 | div.style.display = "inline-block";
|
9339 | });
|
9340 | } else {
|
9341 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
9342 | this.renderingQueue.renderView(pageView);
|
9343 | });
|
9344 | if (this.pageViewMode === "book") {
|
9345 | this.ensureAdjecentPagesAreLoaded();
|
9346 | }
|
9347 | }
|
9348 | }
|
9349 | this.eventBus.dispatch("pagechanging", {
|
9350 | source: this,
|
9351 | pageNumber: val,
|
9352 | pageLabel: this._pageLabels?.[val - 1] ?? null,
|
9353 | previous
|
9354 | });
|
9355 | if (resetCurrentPageView) {
|
9356 | this.#resetCurrentPageView();
|
9357 | }
|
9358 | return true;
|
9359 | }
|
9360 | addPageToRenderQueue(pageIndex = 0) {
|
9361 | if (pageIndex >= 0 && pageIndex <= this._pages.length - 1) {
|
9362 | const pageView = this._pages[pageIndex];
|
9363 | const isLoading = pageView.div.querySelector(".loadingIcon");
|
9364 | if (isLoading) {
|
9365 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
9366 | this.renderingQueue.renderView(pageView);
|
9367 | });
|
9368 | return true;
|
9369 | }
|
9370 | }
|
9371 | return false;
|
9372 | }
|
9373 | ensureAdjecentPagesAreLoaded() {
|
9374 | if (!window.adjacentPagesLoader) {
|
9375 | window.adjacentPagesLoader = evt => {
|
9376 | Window["ngxConsole"].log("rendered", evt);
|
9377 | let pageView = this._pages[Math.min(this._pages.length - 1, this.currentPageNumber)];
|
9378 | if (pageView) {
|
9379 | let isLoading = pageView.div.querySelector(".loadingIcon");
|
9380 | if (isLoading) {
|
9381 | Window["ngxConsole"].log("asking for the next page");
|
9382 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
9383 | this.renderingQueue.renderView(pageView);
|
9384 | });
|
9385 | } else {
|
9386 | pageView = this._pages[Math.min(this._pages.length - 1, this.currentPageNumber + 1)];
|
9387 | isLoading = pageView.div.querySelector(".loadingIcon");
|
9388 | if (isLoading) {
|
9389 | Window["ngxConsole"].log("asking for the next + 1 page");
|
9390 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
9391 | this.renderingQueue.renderView(pageView);
|
9392 | });
|
9393 | } else {
|
9394 | pageView = this._pages[Math.min(this._pages.length - 1, this.currentPageNumber + 2)];
|
9395 | isLoading = pageView.div.querySelector(".loadingIcon");
|
9396 | if (isLoading) {
|
9397 | Window["ngxConsole"].log("asking for the next + 2 page");
|
9398 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
9399 | this.renderingQueue.renderView(pageView);
|
9400 | });
|
9401 | } else {
|
9402 | pageView = this._pages[Math.min(this._pages.length - 1, this.currentPageNumber + 3)];
|
9403 | isLoading = pageView.div.querySelector(".loadingIcon");
|
9404 | if (isLoading) {
|
9405 | Window["ngxConsole"].log("asking for the next + 3 page");
|
9406 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
9407 | this.renderingQueue.renderView(pageView);
|
9408 | });
|
9409 | } else {
|
9410 | pageView = this._pages[Math.max(0, this.currentPageNumber - 1)];
|
9411 | isLoading = pageView.div.querySelector(".loadingIcon");
|
9412 | if (isLoading) {
|
9413 | Window["ngxConsole"].log("asking for the current page");
|
9414 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
9415 | this.renderingQueue.renderView(pageView);
|
9416 | });
|
9417 | } else {
|
9418 | pageView = this._pages[Math.max(0, this.currentPageNumber - 2)];
|
9419 | isLoading = pageView.div.querySelector(".loadingIcon");
|
9420 | if (isLoading) {
|
9421 | Window["ngxConsole"].log("asking for the previous page");
|
9422 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
9423 | this.renderingQueue.renderView(pageView);
|
9424 | });
|
9425 | } else {
|
9426 | Window["ngxConsole"].log("Finished preloading the pages");
|
9427 | }
|
9428 | }
|
9429 | }
|
9430 | }
|
9431 | }
|
9432 | }
|
9433 | }
|
9434 | };
|
9435 | this.eventBus._on("pagerendered", window.adjacentPagesLoader);
|
9436 | }
|
9437 | window.adjacentPagesLoader();
|
9438 | }
|
9439 | get currentPageLabel() {
|
9440 | return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
|
9441 | }
|
9442 | set currentPageLabel(val) {
|
9443 | if (!this.pdfDocument) {
|
9444 | return;
|
9445 | }
|
9446 | let page = val | 0;
|
9447 | if (this._pageLabels) {
|
9448 | const i = this._pageLabels.indexOf(val);
|
9449 | if (i >= 0) {
|
9450 | page = i + 1;
|
9451 | }
|
9452 | }
|
9453 | if (!this._setCurrentPageNumber(page, true)) {
|
9454 | Window["ngxConsole"].error(`currentPageLabel: "${val}" is not a valid page.`);
|
9455 | }
|
9456 | }
|
9457 | get currentScale() {
|
9458 | return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
|
9459 | }
|
9460 | set currentScale(val) {
|
9461 | if (isNaN(val)) {
|
9462 | throw new Error("Invalid numeric scale.");
|
9463 | }
|
9464 | if (!this.pdfDocument) {
|
9465 | return;
|
9466 | }
|
9467 | this._setScale(val, {
|
9468 | noScroll: false
|
9469 | });
|
9470 | }
|
9471 | get currentScaleValue() {
|
9472 | return this._currentScaleValue;
|
9473 | }
|
9474 | set currentScaleValue(val) {
|
9475 | if (!this.pdfDocument) {
|
9476 | return;
|
9477 | }
|
9478 | this._setScale(val, {
|
9479 | noScroll: false
|
9480 | });
|
9481 | }
|
9482 | get pagesRotation() {
|
9483 | return this._pagesRotation;
|
9484 | }
|
9485 | set pagesRotation(rotation) {
|
9486 | if (!(0, _ui_utils.isValidRotation)(rotation)) {
|
9487 | throw new Error("Invalid pages rotation angle.");
|
9488 | }
|
9489 | if (!this.pdfDocument) {
|
9490 | return;
|
9491 | }
|
9492 | rotation %= 360;
|
9493 | if (rotation < 0) {
|
9494 | rotation += 360;
|
9495 | }
|
9496 | if (this._pagesRotation === rotation) {
|
9497 | return;
|
9498 | }
|
9499 | this._pagesRotation = rotation;
|
9500 | const pageNumber = this._currentPageNumber;
|
9501 | this.refresh(true, {
|
9502 | rotation
|
9503 | });
|
9504 | if (this._currentScaleValue) {
|
9505 | this._setScale(this._currentScaleValue, {
|
9506 | noScroll: true
|
9507 | });
|
9508 | }
|
9509 | this.eventBus.dispatch("rotationchanging", {
|
9510 | source: this,
|
9511 | pagesRotation: rotation,
|
9512 | pageNumber
|
9513 | });
|
9514 | if (this.defaultRenderingQueue) {
|
9515 | this.update();
|
9516 | }
|
9517 | }
|
9518 | get firstPagePromise() {
|
9519 | return this.pdfDocument ? this._firstPageCapability.promise : null;
|
9520 | }
|
9521 | get onePageRendered() {
|
9522 | return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
|
9523 | }
|
9524 | get pagesPromise() {
|
9525 | return this.pdfDocument ? this._pagesCapability.promise : null;
|
9526 | }
|
9527 | #layerProperties() {
|
9528 | const self = this;
|
9529 | return {
|
9530 | get annotationEditorUIManager() {
|
9531 | return self.#annotationEditorUIManager;
|
9532 | },
|
9533 | get annotationStorage() {
|
9534 | return self.pdfDocument?.annotationStorage;
|
9535 | },
|
9536 | get downloadManager() {
|
9537 | return self.downloadManager;
|
9538 | },
|
9539 | get enableScripting() {
|
9540 | return !!self._scriptingManager;
|
9541 | },
|
9542 | get fieldObjectsPromise() {
|
9543 | return self.pdfDocument?.getFieldObjects();
|
9544 | },
|
9545 | get findController() {
|
9546 | return self.findController;
|
9547 | },
|
9548 | get hasJSActionsPromise() {
|
9549 | return self.pdfDocument?.hasJSActions();
|
9550 | },
|
9551 | get linkService() {
|
9552 | return self.linkService;
|
9553 | }
|
9554 | };
|
9555 | }
|
9556 | #initializePermissions(permissions) {
|
9557 | const params = {
|
9558 | annotationEditorMode: this.#annotationEditorMode,
|
9559 | annotationMode: this.#annotationMode,
|
9560 | textLayerMode: this.textLayerMode
|
9561 | };
|
9562 | if (!permissions) {
|
9563 | return params;
|
9564 | }
|
9565 | if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
|
9566 | this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
|
9567 | }
|
9568 | if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
|
9569 | params.annotationEditorMode = _pdfjsLib.AnnotationEditorType.DISABLE;
|
9570 | }
|
9571 | if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(_pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS) {
|
9572 | params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
|
9573 | }
|
9574 | return params;
|
9575 | }
|
9576 | #onePageRenderedOrForceFetch() {
|
9577 | if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) {
|
9578 | return Promise.resolve();
|
9579 | }
|
9580 | const visibilityChangePromise = new Promise(resolve => {
|
9581 | this.#onVisibilityChange = () => {
|
9582 | if (document.visibilityState !== "hidden") {
|
9583 | return;
|
9584 | }
|
9585 | resolve();
|
9586 | document.removeEventListener("visibilitychange", this.#onVisibilityChange);
|
9587 | this.#onVisibilityChange = null;
|
9588 | };
|
9589 | document.addEventListener("visibilitychange", this.#onVisibilityChange);
|
9590 | });
|
9591 | return Promise.race([this._onePageRenderedCapability.promise, visibilityChangePromise]);
|
9592 | }
|
9593 | setDocument(pdfDocument) {
|
9594 | if (this.pdfDocument) {
|
9595 | this.eventBus.dispatch("pagesdestroy", {
|
9596 | source: this
|
9597 | });
|
9598 | this._cancelRendering();
|
9599 | this._resetView();
|
9600 | this.findController?.setDocument(null);
|
9601 | this._scriptingManager?.setDocument(null);
|
9602 | if (this.#annotationEditorUIManager) {
|
9603 | this.#annotationEditorUIManager.destroy();
|
9604 | this.#annotationEditorUIManager = null;
|
9605 | }
|
9606 | }
|
9607 | this.pdfDocument = pdfDocument;
|
9608 | if (!pdfDocument) {
|
9609 | return;
|
9610 | }
|
9611 | const pagesCount = pdfDocument.numPages;
|
9612 | const firstPagePromise = pdfDocument.getPage(1);
|
9613 | const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
|
9614 | const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve();
|
9615 | if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
|
9616 | console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document.");
|
9617 | const mode = this._scrollMode = _ui_utils.ScrollMode.PAGE;
|
9618 | this.eventBus.dispatch("scrollmodechanged", {
|
9619 | source: this,
|
9620 | mode
|
9621 | });
|
9622 | }
|
9623 | this._pagesCapability.promise.then(() => {
|
9624 | this.eventBus.dispatch("pagesloaded", {
|
9625 | source: this,
|
9626 | pagesCount
|
9627 | });
|
9628 | }, () => {});
|
9629 | this._onBeforeDraw = evt => {
|
9630 | const pageView = this._pages[evt.pageNumber - 1];
|
9631 | if (!pageView) {
|
9632 | return;
|
9633 | }
|
9634 | this.#buffer.push(pageView);
|
9635 | };
|
9636 | this.eventBus._on("pagerender", this._onBeforeDraw);
|
9637 | this._onAfterDraw = evt => {
|
9638 | if (evt.cssTransform || this._onePageRenderedCapability.settled) {
|
9639 | return;
|
9640 | }
|
9641 | this._onePageRenderedCapability.resolve({
|
9642 | timestamp: evt.timestamp
|
9643 | });
|
9644 | this.eventBus._off("pagerendered", this._onAfterDraw);
|
9645 | this._onAfterDraw = null;
|
9646 | if (this.#onVisibilityChange) {
|
9647 | document.removeEventListener("visibilitychange", this.#onVisibilityChange);
|
9648 | this.#onVisibilityChange = null;
|
9649 | }
|
9650 | };
|
9651 | this.eventBus._on("pagerendered", this._onAfterDraw);
|
9652 | Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
|
9653 | if (pdfDocument !== this.pdfDocument) {
|
9654 | return;
|
9655 | }
|
9656 | this._firstPageCapability.resolve(firstPdfPage);
|
9657 | this._optionalContentConfigPromise = optionalContentConfigPromise;
|
9658 | const {
|
9659 | annotationEditorMode,
|
9660 | annotationMode,
|
9661 | textLayerMode
|
9662 | } = this.#initializePermissions(permissions);
|
9663 | if (annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE) {
|
9664 | const mode = annotationEditorMode;
|
9665 | if (pdfDocument.isPureXfa) {
|
9666 | console.warn("Warning: XFA-editing is not implemented.");
|
9667 | } else if (isValidAnnotationEditorMode(mode)) {
|
9668 | this.#annotationEditorUIManager = new _pdfjsLib.AnnotationEditorUIManager(this.container, this.eventBus, pdfDocument?.annotationStorage);
|
9669 | if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
|
9670 | this.#annotationEditorUIManager.updateMode(mode);
|
9671 | }
|
9672 | } else {
|
9673 | console.error(`Invalid AnnotationEditor mode: ${mode}`);
|
9674 | }
|
9675 | }
|
9676 | const layerProperties = this.#layerProperties.bind(this);
|
9677 | const viewerElement = this._scrollMode === _ui_utils.ScrollMode.PAGE ? null : this.viewer;
|
9678 | const scale = this.currentScale;
|
9679 | const viewport = firstPdfPage.getViewport({
|
9680 | scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
|
9681 | });
|
9682 | this.viewer.style.setProperty("--scale-factor", viewport.scale);
|
9683 | for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
9684 | const pageView = new _pdf_page_view.PDFPageView({
|
9685 | container: viewerElement,
|
9686 | eventBus: this.eventBus,
|
9687 | id: pageNum,
|
9688 | scale,
|
9689 | defaultViewport: viewport.clone(),
|
9690 | optionalContentConfigPromise,
|
9691 | renderingQueue: this.renderingQueue,
|
9692 | textLayerMode,
|
9693 | annotationMode,
|
9694 | imageResourcesPath: this.imageResourcesPath,
|
9695 | removePageBorders: this.removePageBorders,
|
9696 | renderer: this.renderer,
|
9697 | useOnlyCssZoom: this.useOnlyCssZoom,
|
9698 | isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
|
9699 | maxCanvasPixels: this.maxCanvasPixels,
|
9700 | pageColors: this.pageColors,
|
9701 | l10n: this.l10n,
|
9702 | layerProperties
|
9703 | });
|
9704 | this._pages.push(pageView);
|
9705 | }
|
9706 | const firstPageView = this._pages[0];
|
9707 | if (firstPageView) {
|
9708 | firstPageView.setPdfPage(firstPdfPage);
|
9709 | this.linkService.cachePageRef(1, firstPdfPage.ref);
|
9710 | }
|
9711 | if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
|
9712 | this.#ensurePageViewVisible();
|
9713 | } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
|
9714 | this._updateSpreadMode();
|
9715 | }
|
9716 | this.#onePageRenderedOrForceFetch().then(async () => {
|
9717 | this.findController?.setDocument(pdfDocument);
|
9718 | this._scriptingManager?.setDocument(pdfDocument);
|
9719 | if (this.#annotationEditorUIManager) {
|
9720 | this.eventBus.dispatch("annotationeditormodechanged", {
|
9721 | source: this,
|
9722 | mode: this.#annotationEditorMode
|
9723 | });
|
9724 | }
|
9725 | if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) {
|
9726 | this._pagesCapability.resolve();
|
9727 | return;
|
9728 | }
|
9729 | let getPagesLeft = pagesCount - 1;
|
9730 | if (getPagesLeft <= 0) {
|
9731 | this._pagesCapability.resolve();
|
9732 | return;
|
9733 | }
|
9734 | for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
|
9735 | const promise = pdfDocument.getPage(pageNum).then(pdfPage => {
|
9736 | const pageView = this._pages[pageNum - 1];
|
9737 | if (!pageView.pdfPage) {
|
9738 | pageView.setPdfPage(pdfPage);
|
9739 | }
|
9740 | this.linkService.cachePageRef(pageNum, pdfPage.ref);
|
9741 | if (--getPagesLeft === 0) {
|
9742 | this._pagesCapability.resolve();
|
9743 | }
|
9744 | }, reason => {
|
9745 | console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
|
9746 | if (--getPagesLeft === 0) {
|
9747 | this._pagesCapability.resolve();
|
9748 | }
|
9749 | });
|
9750 | if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
|
9751 | await promise;
|
9752 | }
|
9753 | }
|
9754 | });
|
9755 | this.hidePagesDependingOnpageViewMode();
|
9756 | this.eventBus.dispatch("pagesinit", {
|
9757 | source: this
|
9758 | });
|
9759 | pdfDocument.getMetadata().then(({
|
9760 | info
|
9761 | }) => {
|
9762 | if (pdfDocument !== this.pdfDocument) {
|
9763 | return;
|
9764 | }
|
9765 | if (info.Language) {
|
9766 | this.viewer.lang = info.Language;
|
9767 | }
|
9768 | });
|
9769 | if (this.defaultRenderingQueue) {
|
9770 | this.update();
|
9771 | }
|
9772 | }).catch(reason => {
|
9773 | Window["ngxConsole"].error("Unable to initialize viewer", reason);
|
9774 | this._pagesCapability.reject(reason);
|
9775 | });
|
9776 | }
|
9777 | setPageLabels(labels) {
|
9778 | if (!this.pdfDocument) {
|
9779 | return;
|
9780 | }
|
9781 | if (!labels) {
|
9782 | this._pageLabels = null;
|
9783 | } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
|
9784 | this._pageLabels = null;
|
9785 | Window["ngxConsole"].error(`setPageLabels: Invalid page labels.`);
|
9786 | } else {
|
9787 | this._pageLabels = labels;
|
9788 | }
|
9789 | for (let i = 0, ii = this._pages.length; i < ii; i++) {
|
9790 | this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
|
9791 | }
|
9792 | }
|
9793 | _resetView() {
|
9794 | this._pages = [];
|
9795 | this._currentPageNumber = 1;
|
9796 | this._currentScale = _ui_utils.UNKNOWN_SCALE;
|
9797 | this._currentScaleValue = null;
|
9798 | this._pageLabels = null;
|
9799 | const bufferSize = Number(PDFViewerApplicationOptions.get("defaultCacheSize")) || DEFAULT_CACHE_SIZE;
|
9800 | this.#buffer = new PDFPageViewBuffer(bufferSize);
|
9801 | this._location = null;
|
9802 | this._pagesRotation = 0;
|
9803 | this._optionalContentConfigPromise = null;
|
9804 | this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
|
9805 | this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
|
9806 | this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
|
9807 | this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
|
9808 | this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
|
9809 | this._spreadMode = _ui_utils.SpreadMode.NONE;
|
9810 | this.#scrollModePageState = {
|
9811 | previousPageNumber: 1,
|
9812 | scrollDown: true,
|
9813 | pages: []
|
9814 | };
|
9815 | if (this._onBeforeDraw) {
|
9816 | this.eventBus._off("pagerender", this._onBeforeDraw);
|
9817 | this._onBeforeDraw = null;
|
9818 | }
|
9819 | if (this._onAfterDraw) {
|
9820 | this.eventBus._off("pagerendered", this._onAfterDraw);
|
9821 | this._onAfterDraw = null;
|
9822 | }
|
9823 | if (this.#onVisibilityChange) {
|
9824 | document.removeEventListener("visibilitychange", this.#onVisibilityChange);
|
9825 | this.#onVisibilityChange = null;
|
9826 | }
|
9827 | this.viewer.textContent = "";
|
9828 | this._updateScrollMode();
|
9829 | this.viewer.removeAttribute("lang");
|
9830 | this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
9831 | }
|
9832 | #ensurePageViewVisible() {
|
9833 | if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
|
9834 | throw new Error("#ensurePageViewVisible: Invalid scrollMode value.");
|
9835 | }
|
9836 | const pageNumber = this._currentPageNumber,
|
9837 | state = this.#scrollModePageState,
|
9838 | viewer = this.viewer;
|
9839 | viewer.textContent = "";
|
9840 | state.pages.length = 0;
|
9841 | if (this._spreadMode === _ui_utils.SpreadMode.NONE && !this.isInPresentationMode) {
|
9842 | const pageView = this._pages[pageNumber - 1];
|
9843 | viewer.append(pageView.div);
|
9844 | state.pages.push(pageView);
|
9845 | } else {
|
9846 | const pageIndexSet = new Set(),
|
9847 | parity = this._spreadMode - 1;
|
9848 | if (parity === -1) {
|
9849 | pageIndexSet.add(pageNumber - 1);
|
9850 | } else if (pageNumber % 2 !== parity) {
|
9851 | pageIndexSet.add(pageNumber - 1);
|
9852 | pageIndexSet.add(pageNumber);
|
9853 | } else {
|
9854 | pageIndexSet.add(pageNumber - 2);
|
9855 | pageIndexSet.add(pageNumber - 1);
|
9856 | }
|
9857 | const spread = document.createElement("div");
|
9858 | spread.className = "spread";
|
9859 | if (this.isInPresentationMode) {
|
9860 | const dummyPage = document.createElement("div");
|
9861 | dummyPage.className = "dummyPage";
|
9862 | spread.append(dummyPage);
|
9863 | }
|
9864 | for (const i of pageIndexSet) {
|
9865 | const pageView = this._pages[i];
|
9866 | if (!pageView) {
|
9867 | continue;
|
9868 | }
|
9869 | spread.append(pageView.div);
|
9870 | state.pages.push(pageView);
|
9871 | }
|
9872 | viewer.append(spread);
|
9873 | }
|
9874 | state.scrollDown = pageNumber >= state.previousPageNumber;
|
9875 | state.previousPageNumber = pageNumber;
|
9876 | }
|
9877 | _scrollUpdate() {
|
9878 | if (this.pagesCount === 0) {
|
9879 | return;
|
9880 | }
|
9881 | this.update();
|
9882 | }
|
9883 | scrollPagePosIntoView(pageNumber, pageSpot) {
|
9884 | const pageDiv = this._pages[pageNumber - 1].div;
|
9885 | if (pageSpot) {
|
9886 | const targetPageSpot = {
|
9887 | ...pageSpot
|
9888 | };
|
9889 | if (typeof targetPageSpot.top === "string") {
|
9890 | if (targetPageSpot.top.endsWith("%")) {
|
9891 | const percent = Number(targetPageSpot.top.replace("%", ""));
|
9892 | const viewerHeight = this.viewer.querySelector(".page")?.clientHeight;
|
9893 | let height = pageDiv.clientHeight ? pageDiv.clientHeight : viewerHeight;
|
9894 | const visibleWindowHeight = this.viewer.parentElement.clientHeight;
|
9895 | height = Math.max(0, height - visibleWindowHeight);
|
9896 | targetPageSpot.top = percent * height / 100;
|
9897 | }
|
9898 | }
|
9899 | if (typeof targetPageSpot.left === "string") {
|
9900 | if (targetPageSpot.left.endsWith("%")) {
|
9901 | const percent = Number(targetPageSpot.left.replace("%", ""));
|
9902 | const viewerWidth = this.viewer.querySelector(".page")?.clientWidth;
|
9903 | const width = pageDiv.clientWidth ? pageDiv.clientWidth : viewerWidth;
|
9904 | targetPageSpot.left = percent * width / 100;
|
9905 | }
|
9906 | }
|
9907 | this.#scrollIntoView({
|
9908 | div: pageDiv,
|
9909 | id: pageNumber
|
9910 | }, targetPageSpot);
|
9911 | } else {
|
9912 | this.#scrollIntoView({
|
9913 | pageDiv,
|
9914 | pageNumber
|
9915 | });
|
9916 | }
|
9917 | }
|
9918 | #scrollIntoView(pageView, pageSpot = null) {
|
9919 | if (!pageView) {
|
9920 | return;
|
9921 | }
|
9922 | const {
|
9923 | div,
|
9924 | id
|
9925 | } = pageView;
|
9926 | if (this._currentPageNumber !== id) {
|
9927 | this._setCurrentPageNumber(id);
|
9928 | }
|
9929 | if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
|
9930 | this.#ensurePageViewVisible();
|
9931 | this.update();
|
9932 | }
|
9933 | if (!pageSpot && !this.isInPresentationMode) {
|
9934 | const left = div.offsetLeft + div.clientLeft,
|
9935 | right = left + div.clientWidth;
|
9936 | const {
|
9937 | scrollLeft,
|
9938 | clientWidth
|
9939 | } = this.container;
|
9940 | if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) {
|
9941 | pageSpot = {
|
9942 | left: 0,
|
9943 | top: 0
|
9944 | };
|
9945 | }
|
9946 | }
|
9947 | (0, _ui_utils.scrollIntoView)(div, pageSpot, false, this.pageViewMode === "infinite-scroll");
|
9948 | if (!this._currentScaleValue && this._location) {
|
9949 | this._location = null;
|
9950 | }
|
9951 | }
|
9952 | #isSameScale(newScale) {
|
9953 | return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15;
|
9954 | }
|
9955 | _setScaleUpdatePages(newScale, newValue, {
|
9956 | noScroll = false,
|
9957 | preset = false,
|
9958 | drawingDelay = -1
|
9959 | }) {
|
9960 | const previousScale = isNaN(Number(this.currentScale)) ? undefined : Number(this.currentScale);
|
9961 | const previousScaleValue = this.currentScaleValue;
|
9962 | this._currentScaleValue = newValue.toString();
|
9963 | if (this.#isSameScale(newScale)) {
|
9964 | if (preset) {
|
9965 | this.eventBus.dispatch("scalechanging", {
|
9966 | source: this,
|
9967 | scale: newScale,
|
9968 | presetValue: newValue,
|
9969 | previousScale,
|
9970 | previousPresetValue: previousScaleValue
|
9971 | });
|
9972 | }
|
9973 | return;
|
9974 | }
|
9975 | this.viewer.style.setProperty("--scale-factor", newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
|
9976 | const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
|
9977 | this.refresh(true, {
|
9978 | scale: newScale,
|
9979 | drawingDelay: postponeDrawing ? drawingDelay : -1
|
9980 | });
|
9981 | if (postponeDrawing) {
|
9982 | this.#scaleTimeoutId = setTimeout(() => {
|
9983 | this.#scaleTimeoutId = null;
|
9984 | this.refresh();
|
9985 | }, drawingDelay);
|
9986 | }
|
9987 | this._currentScale = newScale;
|
9988 | if (!noScroll) {
|
9989 | let page = this._currentPageNumber,
|
9990 | dest;
|
9991 | if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
|
9992 | page = this._location.pageNumber;
|
9993 | dest = [null, {
|
9994 | name: "XYZ"
|
9995 | }, this._location.left, this._location.top, null];
|
9996 | }
|
9997 | this.scrollPageIntoView({
|
9998 | pageNumber: page,
|
9999 | destArray: dest,
|
10000 | allowNegativeOffset: true
|
10001 | });
|
10002 | }
|
10003 | this.eventBus.dispatch("scalechanging", {
|
10004 | source: this,
|
10005 | scale: newScale,
|
10006 | presetValue: preset ? newValue : undefined,
|
10007 | previousScale,
|
10008 | previousPresetValue: previousScaleValue
|
10009 | });
|
10010 | if (this.defaultRenderingQueue) {
|
10011 | this.update();
|
10012 | }
|
10013 | }
|
10014 | get _pageWidthScaleFactor() {
|
10015 | if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL) {
|
10016 | return 2;
|
10017 | }
|
10018 | return 1;
|
10019 | }
|
10020 | _setScale(value, options) {
|
10021 | if (!value) {
|
10022 | value = "auto";
|
10023 | }
|
10024 | let scale = parseFloat(value);
|
10025 | if (this._currentScale === scale) {
|
10026 | return;
|
10027 | }
|
10028 | if (scale > 0) {
|
10029 | options.preset = false;
|
10030 | this._setScaleUpdatePages(scale, value, options);
|
10031 | } else {
|
10032 | const currentPage = this._pages[this._currentPageNumber - 1];
|
10033 | if (!currentPage) {
|
10034 | return;
|
10035 | }
|
10036 | let hPadding = _ui_utils.SCROLLBAR_PADDING,
|
10037 | vPadding = _ui_utils.VERTICAL_PADDING;
|
10038 | if (this.isInPresentationMode) {
|
10039 | hPadding = vPadding = 4;
|
10040 | if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
|
10041 | hPadding *= 2;
|
10042 | }
|
10043 | } else if (this.removePageBorders) {
|
10044 | hPadding = vPadding = 0;
|
10045 | } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
|
10046 | [hPadding, vPadding] = [vPadding, hPadding];
|
10047 | }
|
10048 | const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
|
10049 | const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
|
10050 | switch (value) {
|
10051 | case "page-actual":
|
10052 | scale = 1;
|
10053 | break;
|
10054 | case "page-width":
|
10055 | scale = pageWidthScale;
|
10056 | break;
|
10057 | case "page-height":
|
10058 | scale = pageHeightScale;
|
10059 | break;
|
10060 | case "page-fit":
|
10061 | scale = Math.min(pageWidthScale, pageHeightScale);
|
10062 | break;
|
10063 | case "auto":
|
10064 | const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
|
10065 | scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
|
10066 | break;
|
10067 | default:
|
10068 | Window["ngxConsole"].error(`_setScale: "${value}" is an unknown zoom value.`);
|
10069 | return;
|
10070 | }
|
10071 | options.preset = true;
|
10072 | this._setScaleUpdatePages(scale, value, options);
|
10073 | }
|
10074 | }
|
10075 | #resetCurrentPageView() {
|
10076 | const pageView = this._pages[this._currentPageNumber - 1];
|
10077 | if (this.isInPresentationMode) {
|
10078 | this._setScale(this._currentScaleValue, {
|
10079 | noScroll: true
|
10080 | });
|
10081 | }
|
10082 | this.#scrollIntoView(pageView);
|
10083 | }
|
10084 | pageLabelToPageNumber(label) {
|
10085 | if (!this._pageLabels) {
|
10086 | return null;
|
10087 | }
|
10088 | const i = this._pageLabels.indexOf(label);
|
10089 | if (i < 0) {
|
10090 | return null;
|
10091 | }
|
10092 | return i + 1;
|
10093 | }
|
10094 | scrollPageIntoView({
|
10095 | pageNumber,
|
10096 | destArray = null,
|
10097 | allowNegativeOffset = false,
|
10098 | ignoreDestinationZoom = false
|
10099 | }) {
|
10100 | if (!this.pdfDocument) {
|
10101 | return;
|
10102 | }
|
10103 | const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
|
10104 | if (!pageView) {
|
10105 | console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`);
|
10106 | return;
|
10107 | }
|
10108 | if (this.isInPresentationMode || !destArray) {
|
10109 | this._setCurrentPageNumber(pageNumber, true);
|
10110 | return;
|
10111 | }
|
10112 | let x = 0,
|
10113 | y = 0;
|
10114 | let width = 0,
|
10115 | height = 0,
|
10116 | widthScale,
|
10117 | heightScale;
|
10118 | const changeOrientation = pageView.rotation % 180 !== 0;
|
10119 | const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
|
10120 | const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
|
10121 | let scale = 0;
|
10122 | switch (destArray[1].name) {
|
10123 | case "XYZ":
|
10124 | x = destArray[2];
|
10125 | y = destArray[3];
|
10126 | scale = destArray[4];
|
10127 | x = x !== null ? x : 0;
|
10128 | y = y !== null ? y : pageHeight;
|
10129 | break;
|
10130 | case "Fit":
|
10131 | case "FitB":
|
10132 | scale = "page-fit";
|
10133 | break;
|
10134 | case "FitH":
|
10135 | case "FitBH":
|
10136 | y = destArray[2];
|
10137 | scale = "page-width";
|
10138 | if (y === null && this._location) {
|
10139 | x = this._location.left;
|
10140 | y = this._location.top;
|
10141 | } else if (typeof y !== "number" || y < 0) {
|
10142 | y = pageHeight;
|
10143 | }
|
10144 | break;
|
10145 | case "FitV":
|
10146 | case "FitBV":
|
10147 | x = destArray[2];
|
10148 | width = pageWidth;
|
10149 | height = pageHeight;
|
10150 | scale = "page-height";
|
10151 | break;
|
10152 | case "FitR":
|
10153 | x = destArray[2];
|
10154 | y = destArray[3];
|
10155 | width = destArray[4] - x;
|
10156 | height = destArray[5] - y;
|
10157 | let hPadding = _ui_utils.SCROLLBAR_PADDING,
|
10158 | vPadding = _ui_utils.VERTICAL_PADDING;
|
10159 | if (this.removePageBorders) {
|
10160 | hPadding = vPadding = 0;
|
10161 | }
|
10162 | widthScale = (this.container.clientWidth - hPadding) / width / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
|
10163 | heightScale = (this.container.clientHeight - vPadding) / height / _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
|
10164 | scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
|
10165 | break;
|
10166 | default:
|
10167 | console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`);
|
10168 | return;
|
10169 | }
|
10170 | if (!ignoreDestinationZoom) {
|
10171 | if (scale && scale !== this._currentScale) {
|
10172 | this.currentScaleValue = scale;
|
10173 | } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
|
10174 | this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
10175 | }
|
10176 | }
|
10177 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
10178 | this.renderingQueue.renderView(pageView);
|
10179 | if (this.pageViewMode === "single") {
|
10180 | if (this.currentPageNumber !== pageNumber) {
|
10181 | this.currentPageNumber = pageNumber;
|
10182 | }
|
10183 | }
|
10184 | });
|
10185 | if (scale === "page-fit" && !destArray[4]) {
|
10186 | this.#scrollIntoView(pageView);
|
10187 | return;
|
10188 | }
|
10189 | const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
|
10190 | let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
|
10191 | let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
|
10192 | if (!allowNegativeOffset) {
|
10193 | left = Math.max(left, 0);
|
10194 | top = Math.max(top, 0);
|
10195 | }
|
10196 | this.#scrollIntoView(pageView, {
|
10197 | left,
|
10198 | top
|
10199 | });
|
10200 | }
|
10201 | _updateLocation(firstPage) {
|
10202 | const currentScale = this._currentScale;
|
10203 | const currentScaleValue = this._currentScaleValue;
|
10204 | const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
|
10205 | const pageNumber = firstPage.id;
|
10206 | const currentPageView = this._pages[pageNumber - 1];
|
10207 | const container = this.container;
|
10208 | const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
|
10209 | const intLeft = Math.round(topLeft[0]);
|
10210 | const intTop = Math.round(topLeft[1]);
|
10211 | let pdfOpenParams = `#page=${pageNumber}`;
|
10212 | if (!this.isInPresentationMode) {
|
10213 | pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
|
10214 | }
|
10215 | this._location = {
|
10216 | pageNumber,
|
10217 | scale: normalizedScaleValue,
|
10218 | top: intTop,
|
10219 | left: intLeft,
|
10220 | rotation: this._pagesRotation,
|
10221 | pdfOpenParams
|
10222 | };
|
10223 | }
|
10224 | update() {
|
10225 | if (this.scrollMode === _ui_utils.ScrollMode.PAGE) {
|
10226 | this.viewer.classList.add("singlePageView");
|
10227 | } else {
|
10228 | this.viewer.classList.remove("singlePageView");
|
10229 | }
|
10230 | const visible = this._getVisiblePages();
|
10231 | const visiblePages = visible.views,
|
10232 | numVisiblePages = visiblePages.length;
|
10233 | if (numVisiblePages === 0) {
|
10234 | return;
|
10235 | }
|
10236 | const bufferSize = Number(PDFViewerApplicationOptions.get("defaultCacheSize")) || DEFAULT_CACHE_SIZE;
|
10237 | const newCacheSize = Math.max(bufferSize, 2 * numVisiblePages + 1);
|
10238 | this.#buffer.resize(newCacheSize, visible.ids);
|
10239 | this.renderingQueue.renderHighestPriority(visible);
|
10240 | const isSimpleLayout = this._spreadMode === _ui_utils.SpreadMode.NONE && (this._scrollMode === _ui_utils.ScrollMode.PAGE || this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
|
10241 | const currentId = this._currentPageNumber;
|
10242 | let stillFullyVisible = false;
|
10243 | for (const page of visiblePages) {
|
10244 | if (page.percent < 100) {
|
10245 | break;
|
10246 | }
|
10247 | if (page.id === currentId && isSimpleLayout) {
|
10248 | stillFullyVisible = true;
|
10249 | break;
|
10250 | }
|
10251 | }
|
10252 | this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id);
|
10253 | this._updateLocation(visible.first);
|
10254 | this.eventBus.dispatch("updateviewarea", {
|
10255 | source: this,
|
10256 | location: this._location
|
10257 | });
|
10258 | this.hidePagesDependingOnpageViewMode();
|
10259 | }
|
10260 | containsElement(element) {
|
10261 | return this.container.contains(element);
|
10262 | }
|
10263 | focus() {
|
10264 | this.container.focus();
|
10265 | }
|
10266 | get _isContainerRtl() {
|
10267 | return getComputedStyle(this.container).direction === "rtl";
|
10268 | }
|
10269 | get isInPresentationMode() {
|
10270 | return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
|
10271 | }
|
10272 | get isChangingPresentationMode() {
|
10273 | return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
|
10274 | }
|
10275 | get isHorizontalScrollbarEnabled() {
|
10276 | return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
|
10277 | }
|
10278 | get isVerticalScrollbarEnabled() {
|
10279 | return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
|
10280 | }
|
10281 | _getVisiblePages() {
|
10282 | const views = this._scrollMode === _ui_utils.ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages,
|
10283 | horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
|
10284 | rtl = horizontal && this._isContainerRtl;
|
10285 | return (0, _ui_utils.getVisibleElements)({
|
10286 | scrollEl: this.container,
|
10287 | views,
|
10288 | sortByVisibility: true,
|
10289 | horizontal,
|
10290 | rtl
|
10291 | });
|
10292 | }
|
10293 | isPageVisible(pageNumber) {
|
10294 | if (!this.pdfDocument) {
|
10295 | return false;
|
10296 | }
|
10297 | if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
|
10298 | console.error(`isPageVisible: "${pageNumber}" is not a valid page.`);
|
10299 | return false;
|
10300 | }
|
10301 | return this._getVisiblePages().ids.has(pageNumber);
|
10302 | }
|
10303 | isPageCached(pageNumber) {
|
10304 | if (!this.pdfDocument) {
|
10305 | return false;
|
10306 | }
|
10307 | if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
|
10308 | console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
|
10309 | return false;
|
10310 | }
|
10311 | const pageView = this._pages[pageNumber - 1];
|
10312 | return this.#buffer.has(pageView);
|
10313 | }
|
10314 | cleanup() {
|
10315 | for (const pageView of this._pages) {
|
10316 | if (pageView.renderingState !== _ui_utils.RenderingStates.FINISHED) {
|
10317 | pageView.reset();
|
10318 | }
|
10319 | }
|
10320 | }
|
10321 | _cancelRendering() {
|
10322 | for (const pageView of this._pages) {
|
10323 | pageView.cancelRendering();
|
10324 | }
|
10325 | }
|
10326 | async #ensurePdfPageLoaded(pageView) {
|
10327 | if (pageView.pdfPage) {
|
10328 | return pageView.pdfPage;
|
10329 | }
|
10330 | try {
|
10331 | const pdfPage = await this.pdfDocument.getPage(pageView.id);
|
10332 | if (!pageView.pdfPage) {
|
10333 | pageView.setPdfPage(pdfPage);
|
10334 | }
|
10335 | if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
|
10336 | this.linkService.cachePageRef(pageView.id, pdfPage.ref);
|
10337 | }
|
10338 | return pdfPage;
|
10339 | } catch (reason) {
|
10340 | console.error("Unable to get page for page view", reason);
|
10341 | return null;
|
10342 | }
|
10343 | }
|
10344 | #getScrollAhead(visible) {
|
10345 | if (visible.first?.id === 1) {
|
10346 | return true;
|
10347 | } else if (visible.last?.id === this.pagesCount) {
|
10348 | return false;
|
10349 | }
|
10350 | switch (this._scrollMode) {
|
10351 | case _ui_utils.ScrollMode.PAGE:
|
10352 | return this.#scrollModePageState.scrollDown;
|
10353 | case _ui_utils.ScrollMode.HORIZONTAL:
|
10354 | return this.scroll.right;
|
10355 | }
|
10356 | return this.scroll.down;
|
10357 | }
|
10358 | forceRendering(currentlyVisiblePages) {
|
10359 | const visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
10360 | const scrollAhead = this.#getScrollAhead(visiblePages);
|
10361 | const preRenderExtra = this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
|
10362 | const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra);
|
10363 | if (pageView) {
|
10364 | this.#ensurePdfPageLoaded(pageView).then(() => {
|
10365 | this.renderingQueue.renderView(pageView);
|
10366 | });
|
10367 | return true;
|
10368 | }
|
10369 | return false;
|
10370 | }
|
10371 | get hasEqualPageSizes() {
|
10372 | const firstPageView = this._pages[0];
|
10373 | for (let i = 1, ii = this._pages.length; i < ii; ++i) {
|
10374 | const pageView = this._pages[i];
|
10375 | if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
|
10376 | return false;
|
10377 | }
|
10378 | }
|
10379 | return true;
|
10380 | }
|
10381 | getPagesOverview() {
|
10382 | return this._pages.map(pageView => {
|
10383 | const viewport = pageView.pdfPage.getViewport({
|
10384 | scale: 1
|
10385 | });
|
10386 | if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
|
10387 | return {
|
10388 | width: viewport.width,
|
10389 | height: viewport.height,
|
10390 | rotation: viewport.rotation
|
10391 | };
|
10392 | }
|
10393 | return {
|
10394 | width: viewport.height,
|
10395 | height: viewport.width,
|
10396 | rotation: (viewport.rotation - 90) % 360
|
10397 | };
|
10398 | });
|
10399 | }
|
10400 | get optionalContentConfigPromise() {
|
10401 | if (!this.pdfDocument) {
|
10402 | return Promise.resolve(null);
|
10403 | }
|
10404 | if (!this._optionalContentConfigPromise) {
|
10405 | console.error("optionalContentConfigPromise: Not initialized yet.");
|
10406 | return this.pdfDocument.getOptionalContentConfig();
|
10407 | }
|
10408 | return this._optionalContentConfigPromise;
|
10409 | }
|
10410 | set optionalContentConfigPromise(promise) {
|
10411 | if (!(promise instanceof Promise)) {
|
10412 | throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
|
10413 | }
|
10414 | if (!this.pdfDocument) {
|
10415 | return;
|
10416 | }
|
10417 | if (!this._optionalContentConfigPromise) {
|
10418 | return;
|
10419 | }
|
10420 | this._optionalContentConfigPromise = promise;
|
10421 | this.refresh(false, {
|
10422 | optionalContentConfigPromise: promise
|
10423 | });
|
10424 | this.eventBus.dispatch("optionalcontentconfigchanged", {
|
10425 | source: this,
|
10426 | promise
|
10427 | });
|
10428 | }
|
10429 | get scrollMode() {
|
10430 | return this._scrollMode;
|
10431 | }
|
10432 | set scrollMode(mode) {
|
10433 | if (this._scrollMode === mode) {
|
10434 | return;
|
10435 | }
|
10436 | if (!(0, _ui_utils.isValidScrollMode)(mode)) {
|
10437 | throw new Error(`Invalid scroll mode: ${mode}`);
|
10438 | }
|
10439 | if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
|
10440 | return;
|
10441 | }
|
10442 | this._previousScrollMode = this._scrollMode;
|
10443 | this._scrollMode = mode;
|
10444 | this.eventBus.dispatch("scrollmodechanged", {
|
10445 | source: this,
|
10446 | mode
|
10447 | });
|
10448 | this._updateScrollMode(this._currentPageNumber);
|
10449 | }
|
10450 | _updateScrollMode(pageNumber = null) {
|
10451 | const scrollMode = this._scrollMode,
|
10452 | viewer = this.viewer;
|
10453 | viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
|
10454 | viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
|
10455 | if (!this.pdfDocument || !pageNumber) {
|
10456 | return;
|
10457 | }
|
10458 | if (scrollMode === _ui_utils.ScrollMode.PAGE) {
|
10459 | this.#ensurePageViewVisible();
|
10460 | } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
|
10461 | this._updateSpreadMode();
|
10462 | }
|
10463 | if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
|
10464 | this._setScale(this._currentScaleValue, {
|
10465 | noScroll: true
|
10466 | });
|
10467 | }
|
10468 | this._setCurrentPageNumber(pageNumber, true);
|
10469 | this.update();
|
10470 | }
|
10471 | get spreadMode() {
|
10472 | return this._spreadMode;
|
10473 | }
|
10474 | set spreadMode(mode) {
|
10475 | if (this._spreadMode === mode) {
|
10476 | return;
|
10477 | }
|
10478 | if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
|
10479 | throw new Error(`Invalid spread mode: ${mode}`);
|
10480 | }
|
10481 | this._spreadMode = mode;
|
10482 | this.eventBus.dispatch("spreadmodechanged", {
|
10483 | source: this,
|
10484 | mode
|
10485 | });
|
10486 | this._updateSpreadMode(this._currentPageNumber);
|
10487 | }
|
10488 | _updateSpreadMode(pageNumber = null) {
|
10489 | if (!this.pdfDocument) {
|
10490 | return;
|
10491 | }
|
10492 | const viewer = this.viewer,
|
10493 | pages = this._pages;
|
10494 | if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
|
10495 | this.#ensurePageViewVisible();
|
10496 | } else {
|
10497 | viewer.textContent = "";
|
10498 | if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
|
10499 | for (const pageView of this._pages) {
|
10500 | viewer.append(pageView.div);
|
10501 | }
|
10502 | } else {
|
10503 | const parity = this._spreadMode - 1;
|
10504 | let spread = null;
|
10505 | for (let i = 0, ii = pages.length; i < ii; ++i) {
|
10506 | if (spread === null) {
|
10507 | spread = document.createElement("div");
|
10508 | spread.className = "spread";
|
10509 | viewer.append(spread);
|
10510 | } else if (i % 2 === parity) {
|
10511 | spread = spread.cloneNode(false);
|
10512 | viewer.append(spread);
|
10513 | }
|
10514 | spread.append(pages[i].div);
|
10515 | }
|
10516 | }
|
10517 | }
|
10518 | this.hidePagesDependingOnpageViewMode();
|
10519 | if (!pageNumber) {
|
10520 | return;
|
10521 | }
|
10522 | if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
|
10523 | this._setScale(this._currentScaleValue, {
|
10524 | noScroll: true
|
10525 | });
|
10526 | }
|
10527 | this._setCurrentPageNumber(pageNumber, true);
|
10528 | this.update();
|
10529 | }
|
10530 | _getPageAdvance(currentPageNumber, previous = false) {
|
10531 | switch (this._scrollMode) {
|
10532 | case _ui_utils.ScrollMode.WRAPPED:
|
10533 | {
|
10534 | const {
|
10535 | views
|
10536 | } = this._getVisiblePages(),
|
10537 | pageLayout = new Map();
|
10538 | for (const {
|
10539 | id,
|
10540 | y,
|
10541 | percent,
|
10542 | widthPercent
|
10543 | } of views) {
|
10544 | if (percent === 0 || widthPercent < 100) {
|
10545 | continue;
|
10546 | }
|
10547 | let yArray = pageLayout.get(y);
|
10548 | if (!yArray) {
|
10549 | pageLayout.set(y, yArray ||= []);
|
10550 | }
|
10551 | yArray.push(id);
|
10552 | }
|
10553 | for (const yArray of pageLayout.values()) {
|
10554 | const currentIndex = yArray.indexOf(currentPageNumber);
|
10555 | if (currentIndex === -1) {
|
10556 | continue;
|
10557 | }
|
10558 | const numPages = yArray.length;
|
10559 | if (numPages === 1) {
|
10560 | break;
|
10561 | }
|
10562 | if (previous) {
|
10563 | for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
|
10564 | const currentId = yArray[i],
|
10565 | expectedId = yArray[i + 1] - 1;
|
10566 | if (currentId < expectedId) {
|
10567 | return currentPageNumber - expectedId;
|
10568 | }
|
10569 | }
|
10570 | } else {
|
10571 | for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
|
10572 | const currentId = yArray[i],
|
10573 | expectedId = yArray[i - 1] + 1;
|
10574 | if (currentId > expectedId) {
|
10575 | return expectedId - currentPageNumber;
|
10576 | }
|
10577 | }
|
10578 | }
|
10579 | if (previous) {
|
10580 | const firstId = yArray[0];
|
10581 | if (firstId < currentPageNumber) {
|
10582 | return currentPageNumber - firstId + 1;
|
10583 | }
|
10584 | } else {
|
10585 | const lastId = yArray[numPages - 1];
|
10586 | if (lastId > currentPageNumber) {
|
10587 | return lastId - currentPageNumber + 1;
|
10588 | }
|
10589 | }
|
10590 | break;
|
10591 | }
|
10592 | break;
|
10593 | }
|
10594 | case _ui_utils.ScrollMode.HORIZONTAL:
|
10595 | {
|
10596 | break;
|
10597 | }
|
10598 | case _ui_utils.ScrollMode.PAGE:
|
10599 | case _ui_utils.ScrollMode.VERTICAL:
|
10600 | {
|
10601 | if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
|
10602 | break;
|
10603 | }
|
10604 | const parity = this._spreadMode - 1;
|
10605 | if (previous && currentPageNumber % 2 !== parity) {
|
10606 | break;
|
10607 | } else if (!previous && currentPageNumber % 2 === parity) {
|
10608 | break;
|
10609 | }
|
10610 | const {
|
10611 | views
|
10612 | } = this._getVisiblePages(),
|
10613 | expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
|
10614 | for (const {
|
10615 | id,
|
10616 | percent,
|
10617 | widthPercent
|
10618 | } of views) {
|
10619 | if (id !== expectedId) {
|
10620 | continue;
|
10621 | }
|
10622 | if (percent > 0 && widthPercent === 100) {
|
10623 | return 2;
|
10624 | }
|
10625 | break;
|
10626 | }
|
10627 | break;
|
10628 | }
|
10629 | }
|
10630 | return 1;
|
10631 | }
|
10632 | nextPage() {
|
10633 | const currentPageNumber = this._currentPageNumber,
|
10634 | pagesCount = this.pagesCount;
|
10635 | if (currentPageNumber >= pagesCount) {
|
10636 | return false;
|
10637 | }
|
10638 | const advance = this._getPageAdvance(currentPageNumber, false) || 1;
|
10639 | this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
|
10640 | return true;
|
10641 | }
|
10642 | previousPage() {
|
10643 | const currentPageNumber = this._currentPageNumber;
|
10644 | if (currentPageNumber <= 1) {
|
10645 | return false;
|
10646 | }
|
10647 | const advance = this._getPageAdvance(currentPageNumber, true) || 1;
|
10648 | this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
|
10649 | return true;
|
10650 | }
|
10651 | increaseScale(options = null) {
|
10652 | if (typeof options === "number") {
|
10653 | console.error("The `increaseScale` method-signature was updated, please use an object instead.");
|
10654 | options = {
|
10655 | steps: options
|
10656 | };
|
10657 | }
|
10658 | if (!this.pdfDocument) {
|
10659 | return;
|
10660 | }
|
10661 | options ||= Object.create(null);
|
10662 | let newScale = this._currentScale;
|
10663 | let maxScale = Number(PDFViewerApplicationOptions.get("maxZoom"));
|
10664 | if (!maxScale) {
|
10665 | maxScale = _ui_utils.MAX_SCALE;
|
10666 | }
|
10667 | if (options.scaleFactor > 1) {
|
10668 | newScale = Math.min(maxScale, Math.round(newScale * options.scaleFactor * 100) / 100);
|
10669 | } else {
|
10670 | let steps = options.steps ?? 1;
|
10671 | do {
|
10672 | newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
|
10673 | newScale = Math.ceil(newScale * 10) / 10;
|
10674 | newScale = Math.min(maxScale, newScale);
|
10675 | } while (--steps > 0 && newScale < maxScale);
|
10676 | }
|
10677 | options.noScroll = false;
|
10678 | this._setScale(newScale, options);
|
10679 | }
|
10680 | decreaseScale(options = null) {
|
10681 | if (typeof options === "number") {
|
10682 | console.error("The `decreaseScale` method-signature was updated, please use an object instead.");
|
10683 | options = {
|
10684 | steps: options
|
10685 | };
|
10686 | }
|
10687 | if (!this.pdfDocument) {
|
10688 | return;
|
10689 | }
|
10690 | options ||= Object.create(null);
|
10691 | let newScale = this._currentScale;
|
10692 | let minScale = Number(PDFViewerApplicationOptions.get("minZoom"));
|
10693 | if (!minScale) {
|
10694 | minScale = _ui_utils.MIN_SCALE;
|
10695 | }
|
10696 | if (options.scaleFactor > 0 && options.scaleFactor < 1) {
|
10697 | newScale = Math.max(minScale, Math.round(newScale * options.scaleFactor * 100) / 100);
|
10698 | } else {
|
10699 | let steps = options.steps ?? 1;
|
10700 | do {
|
10701 | newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
|
10702 | newScale = Math.floor(newScale * 10) / 10;
|
10703 | newScale = Math.max(minScale, newScale);
|
10704 | } while (--steps > 0 && newScale > minScale);
|
10705 | }
|
10706 | options.noScroll = false;
|
10707 | this._setScale(newScale, options);
|
10708 | }
|
10709 | #updateContainerHeightCss(height = this.container.clientHeight) {
|
10710 | if (height !== this.#previousContainerHeight) {
|
10711 | this.#previousContainerHeight = height;
|
10712 | _ui_utils.docStyle.setProperty("--viewer-container-height", `${height}px`);
|
10713 | }
|
10714 | }
|
10715 | #resizeObserverCallback(entries) {
|
10716 | for (const entry of entries) {
|
10717 | if (entry.target === this.container) {
|
10718 | this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize));
|
10719 | this.#containerTopLeft = null;
|
10720 | break;
|
10721 | }
|
10722 | }
|
10723 | }
|
10724 | get containerTopLeft() {
|
10725 | return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft];
|
10726 | }
|
10727 | get annotationEditorMode() {
|
10728 | return this.#annotationEditorUIManager ? this.#annotationEditorMode : _pdfjsLib.AnnotationEditorType.DISABLE;
|
10729 | }
|
10730 | set annotationEditorMode(mode) {
|
10731 | if (!this.#annotationEditorUIManager) {
|
10732 | throw new Error(`The AnnotationEditor is not enabled.`);
|
10733 | }
|
10734 | if (this.#annotationEditorMode === mode) {
|
10735 | return;
|
10736 | }
|
10737 | if (!isValidAnnotationEditorMode(mode)) {
|
10738 | throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
|
10739 | }
|
10740 | if (!this.pdfDocument) {
|
10741 | return;
|
10742 | }
|
10743 | this.#annotationEditorMode = mode;
|
10744 | this.eventBus.dispatch("annotationeditormodechanged", {
|
10745 | source: this,
|
10746 | mode
|
10747 | });
|
10748 | this.#annotationEditorUIManager.updateMode(mode);
|
10749 | }
|
10750 | set annotationEditorParams({
|
10751 | type,
|
10752 | value
|
10753 | }) {
|
10754 | if (!this.#annotationEditorUIManager) {
|
10755 | throw new Error(`The AnnotationEditor is not enabled.`);
|
10756 | }
|
10757 | this.#annotationEditorUIManager.updateParams(type, value);
|
10758 | }
|
10759 | refresh(noUpdate = false, updateArgs = Object.create(null)) {
|
10760 | if (!this.pdfDocument) {
|
10761 | return;
|
10762 | }
|
10763 | for (const pageView of this._pages) {
|
10764 | pageView.update(updateArgs);
|
10765 | }
|
10766 | if (this.#scaleTimeoutId !== null) {
|
10767 | clearTimeout(this.#scaleTimeoutId);
|
10768 | this.#scaleTimeoutId = null;
|
10769 | }
|
10770 | if (!noUpdate) {
|
10771 | this.update();
|
10772 | }
|
10773 | }
|
10774 | }
|
10775 | exports.PDFViewer = PDFViewer;
|
10776 |
|
10777 | }),
|
10778 |
|
10779 | ((__unused_webpack_module, exports) => {
|
10780 |
|
10781 |
|
10782 |
|
10783 | Object.defineProperty(exports, "__esModule", ({
|
10784 | value: true
|
10785 | }));
|
10786 | exports.NullL10n = void 0;
|
10787 | exports.fixupLangCode = fixupLangCode;
|
10788 | exports.getL10nFallback = getL10nFallback;
|
10789 | const DEFAULT_L10N_STRINGS = {
|
10790 | of_pages: "of {{pagesCount}}",
|
10791 | page_of_pages: "({{pageNumber}} of {{pagesCount}})",
|
10792 | document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
|
10793 | document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
|
10794 | document_properties_date_string: "{{date}}, {{time}}",
|
10795 | document_properties_page_size_unit_inches: "in",
|
10796 | document_properties_page_size_unit_millimeters: "mm",
|
10797 | document_properties_page_size_orientation_portrait: "portrait",
|
10798 | document_properties_page_size_orientation_landscape: "landscape",
|
10799 | document_properties_page_size_name_a3: "A3",
|
10800 | document_properties_page_size_name_a4: "A4",
|
10801 | document_properties_page_size_name_letter: "Letter",
|
10802 | document_properties_page_size_name_legal: "Legal",
|
10803 | document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
|
10804 | document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
|
10805 | document_properties_linearized_yes: "Yes",
|
10806 | document_properties_linearized_no: "No",
|
10807 | additional_layers: "Additional Layers",
|
10808 | page_landmark: "Page {{page}}",
|
10809 | thumb_page_title: "Page {{page}}",
|
10810 | thumb_page_canvas: "Thumbnail of Page {{page}}",
|
10811 | find_reached_top: "Reached top of document, continued from bottom",
|
10812 | find_reached_bottom: "Reached end of document, continued from top",
|
10813 | "find_match_count[one]": "{{current}} of {{total}} match",
|
10814 | "find_match_count[other]": "{{current}} of {{total}} matches",
|
10815 | "find_match_count_limit[one]": "More than {{limit}} match",
|
10816 | "find_match_count_limit[other]": "More than {{limit}} matches",
|
10817 | find_not_found: "Phrase not found",
|
10818 | page_scale_width: "Page Width",
|
10819 | page_scale_fit: "Page Fit",
|
10820 | page_scale_auto: "Automatic Zoom",
|
10821 | page_scale_actual: "Actual Size",
|
10822 | page_scale_percent: "{{scale}}%",
|
10823 | loading_error: "An error occurred while loading the PDF.",
|
10824 | invalid_file_error: "Invalid or corrupted PDF file.",
|
10825 | missing_file_error: "Missing PDF file.",
|
10826 | unexpected_response_error: "Unexpected server response.",
|
10827 | rendering_error: "An error occurred while rendering the page.",
|
10828 | printing_not_supported: "Warning: Printing is not fully supported by this browser.",
|
10829 | printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
|
10830 | web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts.",
|
10831 | free_text2_default_content: "Start typing…",
|
10832 | editor_free_text2_aria_label: "Text Editor",
|
10833 | editor_ink2_aria_label: "Draw Editor",
|
10834 | editor_ink_canvas_aria_label: "User-created image"
|
10835 | };
|
10836 | {
|
10837 | DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
|
10838 | }
|
10839 | function getL10nFallback(key, args) {
|
10840 | switch (key) {
|
10841 | case "find_match_count":
|
10842 | key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
|
10843 | break;
|
10844 | case "find_match_count_limit":
|
10845 | key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
|
10846 | break;
|
10847 | }
|
10848 | return DEFAULT_L10N_STRINGS[key] || "";
|
10849 | }
|
10850 | const PARTIAL_LANG_CODES = {
|
10851 | en: "en-US",
|
10852 | es: "es-ES",
|
10853 | fy: "fy-NL",
|
10854 | ga: "ga-IE",
|
10855 | gu: "gu-IN",
|
10856 | hi: "hi-IN",
|
10857 | hy: "hy-AM",
|
10858 | nb: "nb-NO",
|
10859 | ne: "ne-NP",
|
10860 | nn: "nn-NO",
|
10861 | pa: "pa-IN",
|
10862 | pt: "pt-PT",
|
10863 | sv: "sv-SE",
|
10864 | zh: "zh-CN"
|
10865 | };
|
10866 | function fixupLangCode(langCode) {
|
10867 | return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
|
10868 | }
|
10869 | function formatL10nValue(text, args) {
|
10870 | if (!args) {
|
10871 | return text;
|
10872 | }
|
10873 | return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
|
10874 | return name in args ? args[name] : "{{" + name + "}}";
|
10875 | });
|
10876 | }
|
10877 | const NullL10n = {
|
10878 | async getLanguage() {
|
10879 | return "en-us";
|
10880 | },
|
10881 | async getDirection() {
|
10882 | return "ltr";
|
10883 | },
|
10884 | async get(key, args = null, fallback = getL10nFallback(key, args)) {
|
10885 | return formatL10nValue(fallback, args);
|
10886 | },
|
10887 | async translate(element) {}
|
10888 | };
|
10889 | exports.NullL10n = NullL10n;
|
10890 |
|
10891 | }),
|
10892 |
|
10893 | ((__unused_webpack_module, exports) => {
|
10894 |
|
10895 |
|
10896 |
|
10897 | Object.defineProperty(exports, "__esModule", ({
|
10898 | value: true
|
10899 | }));
|
10900 | exports.PageFlip = void 0;
|
10901 | class Page {
|
10902 | constructor(render, density) {
|
10903 | this.state = {
|
10904 | angle: 0,
|
10905 | area: [],
|
10906 | position: {
|
10907 | x: 0,
|
10908 | y: 0
|
10909 | },
|
10910 | hardAngle: 0,
|
10911 | hardDrawingAngle: 0
|
10912 | };
|
10913 | this.createdDensity = density;
|
10914 | this.nowDrawingDensity = this.createdDensity;
|
10915 | this.render = render;
|
10916 | }
|
10917 | setDensity(density) {
|
10918 | this.createdDensity = density;
|
10919 | this.nowDrawingDensity = density;
|
10920 | }
|
10921 | setDrawingDensity(density) {
|
10922 | this.nowDrawingDensity = density;
|
10923 | }
|
10924 | setPosition(pagePos) {
|
10925 | this.state.position = pagePos;
|
10926 | }
|
10927 | setAngle(angle) {
|
10928 | this.state.angle = angle;
|
10929 | }
|
10930 | setArea(area) {
|
10931 | this.state.area = area;
|
10932 | }
|
10933 | setHardDrawingAngle(angle) {
|
10934 | this.state.hardDrawingAngle = angle;
|
10935 | }
|
10936 | setHardAngle(angle) {
|
10937 | this.state.hardAngle = angle;
|
10938 | this.state.hardDrawingAngle = angle;
|
10939 | }
|
10940 | setOrientation(orientation) {
|
10941 | this.orientation = orientation;
|
10942 | }
|
10943 | getDrawingDensity() {
|
10944 | return this.nowDrawingDensity;
|
10945 | }
|
10946 | getDensity() {
|
10947 | return this.createdDensity;
|
10948 | }
|
10949 | getHardAngle() {
|
10950 | return this.state.hardAngle;
|
10951 | }
|
10952 | }
|
10953 | class ImagePage extends Page {
|
10954 | constructor(render, href, density) {
|
10955 | super(render, density);
|
10956 | this.image = null;
|
10957 | this.isLoad = false;
|
10958 | this.loadingAngle = 0;
|
10959 | this.image = new Image();
|
10960 | this.image.src = href;
|
10961 | }
|
10962 | draw(tempDensity) {
|
10963 | const options = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {
|
10964 | willReadFrequently: true
|
10965 | } : undefined;
|
10966 | const ctx = canvas.getContext("2d", options);
|
10967 | const pagePos = this.render.convertToGlobal(this.state.position);
|
10968 | const pageWidth = this.render.getRect().pageWidth;
|
10969 | const pageHeight = this.render.getRect().height;
|
10970 | ctx.save();
|
10971 | ctx.translate(pagePos.x, pagePos.y);
|
10972 | ctx.beginPath();
|
10973 | for (let p of this.state.area) {
|
10974 | if (p !== null) {
|
10975 | p = this.render.convertToGlobal(p);
|
10976 | ctx.lineTo(p.x - pagePos.x, p.y - pagePos.y);
|
10977 | }
|
10978 | }
|
10979 | ctx.rotate(this.state.angle);
|
10980 | ctx.clip();
|
10981 | if (!this.isLoad) {
|
10982 | this.drawLoader(ctx, {
|
10983 | x: 0,
|
10984 | y: 0
|
10985 | }, pageWidth, pageHeight);
|
10986 | } else {
|
10987 | ctx.drawImage(this.image, 0, 0, pageWidth, pageHeight);
|
10988 | }
|
10989 | ctx.restore();
|
10990 | }
|
10991 | simpleDraw(orient) {
|
10992 | const rect = this.render.getRect();
|
10993 | const options = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {
|
10994 | willReadFrequently: true
|
10995 | } : undefined;
|
10996 | const ctx = canvas.getContext("2d", options);
|
10997 | const pageWidth = rect.pageWidth;
|
10998 | const pageHeight = rect.height;
|
10999 | const x = orient === 1 ? rect.left + rect.pageWidth : rect.left;
|
11000 | const y = rect.top;
|
11001 | if (!this.isLoad) {
|
11002 | this.drawLoader(ctx, {
|
11003 | x,
|
11004 | y
|
11005 | }, pageWidth, pageHeight);
|
11006 | } else {
|
11007 | ctx.drawImage(this.image, x, y, pageWidth, pageHeight);
|
11008 | }
|
11009 | }
|
11010 | drawLoader(ctx, shiftPos, pageWidth, pageHeight) {
|
11011 | ctx.beginPath();
|
11012 | ctx.strokeStyle = 'rgb(200, 200, 200)';
|
11013 | ctx.fillStyle = 'rgb(255, 255, 255)';
|
11014 | ctx.lineWidth = 1;
|
11015 | ctx.rect(shiftPos.x + 1, shiftPos.y + 1, pageWidth - 1, pageHeight - 1);
|
11016 | ctx.stroke();
|
11017 | ctx.fill();
|
11018 | const middlePoint = {
|
11019 | x: shiftPos.x + pageWidth / 2,
|
11020 | y: shiftPos.y + pageHeight / 2
|
11021 | };
|
11022 | ctx.beginPath();
|
11023 | ctx.lineWidth = 10;
|
11024 | ctx.arc(middlePoint.x, middlePoint.y, 20, this.loadingAngle, 3 * Math.PI / 2 + this.loadingAngle);
|
11025 | ctx.stroke();
|
11026 | ctx.closePath();
|
11027 | this.loadingAngle += 0.07;
|
11028 | if (this.loadingAngle >= 2 * Math.PI) {
|
11029 | this.loadingAngle = 0;
|
11030 | }
|
11031 | }
|
11032 | load() {
|
11033 | if (!this.isLoad) this.image.onload = () => {
|
11034 | this.isLoad = true;
|
11035 | };
|
11036 | }
|
11037 | newTemporaryCopy() {
|
11038 | return this;
|
11039 | }
|
11040 | getTemporaryCopy() {
|
11041 | return this;
|
11042 | }
|
11043 | hideTemporaryCopy() {}
|
11044 | }
|
11045 | class PageCollection {
|
11046 | constructor(app, render) {
|
11047 | this.pages = [];
|
11048 | this.currentPageIndex = 0;
|
11049 | this.currentSpreadIndex = 0;
|
11050 | this.landscapeSpread = [];
|
11051 | this.portraitSpread = [];
|
11052 | this.render = render;
|
11053 | this.app = app;
|
11054 | this.currentPageIndex = 0;
|
11055 | this.isShowCover = this.app.getSettings().showCover;
|
11056 | }
|
11057 | destroy() {
|
11058 | this.pages = [];
|
11059 | }
|
11060 | createSpread() {
|
11061 | this.landscapeSpread = [];
|
11062 | this.portraitSpread = [];
|
11063 | for (let i = 0; i < this.pages.length; i++) {
|
11064 | this.portraitSpread.push([i]);
|
11065 | }
|
11066 | let start = 0;
|
11067 | if (this.isShowCover) {
|
11068 | this.pages[0].setDensity("hard");
|
11069 | this.landscapeSpread.push([start]);
|
11070 | start++;
|
11071 | }
|
11072 | for (let i = start; i < this.pages.length; i += 2) {
|
11073 | if (i < this.pages.length - 1) this.landscapeSpread.push([i, i + 1]);else {
|
11074 | this.landscapeSpread.push([i]);
|
11075 | this.pages[i].setDensity("hard");
|
11076 | }
|
11077 | }
|
11078 | }
|
11079 | getSpread() {
|
11080 | return this.render.getOrientation() === "landscape" ? this.landscapeSpread : this.portraitSpread;
|
11081 | }
|
11082 | getSpreadIndexByPage(pageNum) {
|
11083 | const spread = this.getSpread();
|
11084 | for (let i = 0; i < spread.length; i++) if (pageNum === spread[i][0] || pageNum === spread[i][1]) return i;
|
11085 | return null;
|
11086 | }
|
11087 | getPageCount() {
|
11088 | return this.pages.length;
|
11089 | }
|
11090 | getPages() {
|
11091 | return this.pages;
|
11092 | }
|
11093 | getPage(pageIndex) {
|
11094 | if (pageIndex >= 0 && pageIndex < this.pages.length) {
|
11095 | return this.pages[pageIndex];
|
11096 | }
|
11097 | throw new Error('Invalid page number');
|
11098 | }
|
11099 | nextBy(current) {
|
11100 | const idx = this.pages.indexOf(current);
|
11101 | if (idx < this.pages.length - 1) return this.pages[idx + 1];
|
11102 | return null;
|
11103 | }
|
11104 | prevBy(current) {
|
11105 | const idx = this.pages.indexOf(current);
|
11106 | if (idx > 0) return this.pages[idx - 1];
|
11107 | return null;
|
11108 | }
|
11109 | getFlippingPage(direction) {
|
11110 | const current = this.currentSpreadIndex;
|
11111 | if (this.render.getOrientation() === "portrait") {
|
11112 | return direction === 0 ? this.pages[current].newTemporaryCopy() : this.pages[current - 1];
|
11113 | } else {
|
11114 | const spread = direction === 0 ? this.getSpread()[current + 1] : this.getSpread()[current - 1];
|
11115 | if (spread.length === 1) return this.pages[spread[0]];
|
11116 | return direction === 0 ? this.pages[spread[0]] : this.pages[spread[1]];
|
11117 | }
|
11118 | }
|
11119 | getBottomPage(direction) {
|
11120 | const current = this.currentSpreadIndex;
|
11121 | if (this.render.getOrientation() === "portrait") {
|
11122 | return direction === 0 ? this.pages[current + 1] : this.pages[current - 1];
|
11123 | } else {
|
11124 | const spread = direction === 0 ? this.getSpread()[current + 1] : this.getSpread()[current - 1];
|
11125 | if (spread.length === 1) return this.pages[spread[0]];
|
11126 | return direction === 0 ? this.pages[spread[1]] : this.pages[spread[0]];
|
11127 | }
|
11128 | }
|
11129 | showNext() {
|
11130 | if (this.currentSpreadIndex < this.getSpread().length) {
|
11131 | this.currentSpreadIndex++;
|
11132 | this.showSpread();
|
11133 | }
|
11134 | }
|
11135 | showPrev() {
|
11136 | if (this.currentSpreadIndex > 0) {
|
11137 | this.currentSpreadIndex--;
|
11138 | this.showSpread();
|
11139 | }
|
11140 | }
|
11141 | getCurrentPageIndex() {
|
11142 | return this.currentPageIndex;
|
11143 | }
|
11144 | show(pageNum = null) {
|
11145 | if (pageNum === null) pageNum = this.currentPageIndex;
|
11146 | if (pageNum < 0 || pageNum >= this.pages.length) return;
|
11147 | const spreadIndex = this.getSpreadIndexByPage(pageNum);
|
11148 | if (spreadIndex !== null) {
|
11149 | this.currentSpreadIndex = spreadIndex;
|
11150 | this.showSpread();
|
11151 | }
|
11152 | }
|
11153 | getCurrentSpreadIndex() {
|
11154 | return this.currentSpreadIndex;
|
11155 | }
|
11156 | setCurrentSpreadIndex(newIndex) {
|
11157 | if (newIndex >= 0 && newIndex < this.getSpread().length) {
|
11158 | this.currentSpreadIndex = newIndex;
|
11159 | } else {
|
11160 | throw new Error('Invalid page');
|
11161 | }
|
11162 | }
|
11163 | showSpread() {
|
11164 | const spread = this.getSpread()[this.currentSpreadIndex];
|
11165 | if (spread.length === 2) {
|
11166 | this.render.setLeftPage(this.pages[spread[0]]);
|
11167 | this.render.setRightPage(this.pages[spread[1]]);
|
11168 | } else {
|
11169 | if (this.render.getOrientation() === "landscape") {
|
11170 | if (spread[0] === this.pages.length - 1) {
|
11171 | this.render.setLeftPage(this.pages[spread[0]]);
|
11172 | this.render.setRightPage(null);
|
11173 | } else {
|
11174 | this.render.setLeftPage(null);
|
11175 | this.render.setRightPage(this.pages[spread[0]]);
|
11176 | }
|
11177 | } else {
|
11178 | this.render.setLeftPage(null);
|
11179 | this.render.setRightPage(this.pages[spread[0]]);
|
11180 | }
|
11181 | }
|
11182 | this.currentPageIndex = spread[0];
|
11183 | this.app.updatePageIndex(this.currentPageIndex);
|
11184 | }
|
11185 | }
|
11186 | class ImagePageCollection extends PageCollection {
|
11187 | constructor(app, render, imagesHref) {
|
11188 | super(app, render);
|
11189 | this.imagesHref = imagesHref;
|
11190 | }
|
11191 | load() {
|
11192 | for (const href of this.imagesHref) {
|
11193 | const page = new ImagePage(this.render, href, "soft");
|
11194 | page.load();
|
11195 | this.pages.push(page);
|
11196 | }
|
11197 | this.createSpread();
|
11198 | }
|
11199 | }
|
11200 | class Helper {
|
11201 | static GetDistanceBetweenTwoPoint(point1, point2) {
|
11202 | if (point1 === null || point2 === null) {
|
11203 | return Infinity;
|
11204 | }
|
11205 | return Math.sqrt(Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2));
|
11206 | }
|
11207 | static GetSegmentLength(segment) {
|
11208 | return Helper.GetDistanceBetweenTwoPoint(segment[0], segment[1]);
|
11209 | }
|
11210 | static GetAngleBetweenTwoLine(line1, line2) {
|
11211 | const A1 = line1[0].y - line1[1].y;
|
11212 | const A2 = line2[0].y - line2[1].y;
|
11213 | const B1 = line1[1].x - line1[0].x;
|
11214 | const B2 = line2[1].x - line2[0].x;
|
11215 | return Math.acos((A1 * A2 + B1 * B2) / (Math.sqrt(A1 * A1 + B1 * B1) * Math.sqrt(A2 * A2 + B2 * B2)));
|
11216 | }
|
11217 | static PointInRect(rect, pos) {
|
11218 | if (pos === null) {
|
11219 | return null;
|
11220 | }
|
11221 | if (pos.x >= rect.left && pos.x <= rect.width + rect.left && pos.y >= rect.top && pos.y <= rect.top + rect.height) {
|
11222 | return pos;
|
11223 | }
|
11224 | return null;
|
11225 | }
|
11226 | static GetRotatedPoint(transformedPoint, startPoint, angle) {
|
11227 | return {
|
11228 | x: transformedPoint.x * Math.cos(angle) + transformedPoint.y * Math.sin(angle) + startPoint.x,
|
11229 | y: transformedPoint.y * Math.cos(angle) - transformedPoint.x * Math.sin(angle) + startPoint.y
|
11230 | };
|
11231 | }
|
11232 | static LimitPointToCircle(startPoint, radius, limitedPoint) {
|
11233 | if (Helper.GetDistanceBetweenTwoPoint(startPoint, limitedPoint) <= radius) {
|
11234 | return limitedPoint;
|
11235 | }
|
11236 | const a = startPoint.x;
|
11237 | const b = startPoint.y;
|
11238 | const n = limitedPoint.x;
|
11239 | const m = limitedPoint.y;
|
11240 | let x = Math.sqrt(Math.pow(radius, 2) * Math.pow(a - n, 2) / (Math.pow(a - n, 2) + Math.pow(b - m, 2))) + a;
|
11241 | if (limitedPoint.x < 0) {
|
11242 | x *= -1;
|
11243 | }
|
11244 | let y = (x - a) * (b - m) / (a - n) + b;
|
11245 | if (a - n + b === 0) {
|
11246 | y = radius;
|
11247 | }
|
11248 | return {
|
11249 | x,
|
11250 | y
|
11251 | };
|
11252 | }
|
11253 | static GetIntersectBetweenTwoSegment(rectBorder, one, two) {
|
11254 | return Helper.PointInRect(rectBorder, Helper.GetIntersectBeetwenTwoLine(one, two));
|
11255 | }
|
11256 | static GetIntersectBeetwenTwoLine(one, two) {
|
11257 | const A1 = one[0].y - one[1].y;
|
11258 | const A2 = two[0].y - two[1].y;
|
11259 | const B1 = one[1].x - one[0].x;
|
11260 | const B2 = two[1].x - two[0].x;
|
11261 | const C1 = one[0].x * one[1].y - one[1].x * one[0].y;
|
11262 | const C2 = two[0].x * two[1].y - two[1].x * two[0].y;
|
11263 | const det1 = A1 * C2 - A2 * C1;
|
11264 | const det2 = B1 * C2 - B2 * C1;
|
11265 | const x = -((C1 * B2 - C2 * B1) / (A1 * B2 - A2 * B1));
|
11266 | const y = -((A1 * C2 - A2 * C1) / (A1 * B2 - A2 * B1));
|
11267 | if (isFinite(x) && isFinite(y)) {
|
11268 | return {
|
11269 | x,
|
11270 | y
|
11271 | };
|
11272 | } else {
|
11273 | if (Math.abs(det1 - det2) < 0.1) throw new Error('Segment included');
|
11274 | }
|
11275 | return null;
|
11276 | }
|
11277 | static GetCordsFromTwoPoint(pointOne, pointTwo) {
|
11278 | const sizeX = Math.abs(pointOne.x - pointTwo.x);
|
11279 | const sizeY = Math.abs(pointOne.y - pointTwo.y);
|
11280 | const lengthLine = Math.max(sizeX, sizeY);
|
11281 | const result = [pointOne];
|
11282 | function getCord(c1, c2, size, length, index) {
|
11283 | if (c2 > c1) {
|
11284 | return c1 + index * (size / length);
|
11285 | } else if (c2 < c1) {
|
11286 | return c1 - index * (size / length);
|
11287 | }
|
11288 | return c1;
|
11289 | }
|
11290 | for (let i = 1; i <= lengthLine; i += 1) {
|
11291 | result.push({
|
11292 | x: getCord(pointOne.x, pointTwo.x, sizeX, lengthLine, i),
|
11293 | y: getCord(pointOne.y, pointTwo.y, sizeY, lengthLine, i)
|
11294 | });
|
11295 | }
|
11296 | return result;
|
11297 | }
|
11298 | }
|
11299 | class HTMLPage extends Page {
|
11300 | constructor(render, element, density) {
|
11301 | super(render, density);
|
11302 | this.copiedElement = null;
|
11303 | this.temporaryCopy = null;
|
11304 | this.isLoad = false;
|
11305 | this.element = element;
|
11306 | this.element.classList.add('stf__item');
|
11307 | this.element.classList.add('--' + density);
|
11308 | }
|
11309 | newTemporaryCopy() {
|
11310 | if (this.nowDrawingDensity === "hard") {
|
11311 | return this;
|
11312 | }
|
11313 | if (this.temporaryCopy === null) {
|
11314 | this.copiedElement = this.element.cloneNode(true);
|
11315 | this.element.parentElement.appendChild(this.copiedElement);
|
11316 | this.temporaryCopy = new HTMLPage(this.render, this.copiedElement, this.nowDrawingDensity);
|
11317 | }
|
11318 | return this.getTemporaryCopy();
|
11319 | }
|
11320 | getTemporaryCopy() {
|
11321 | return this.temporaryCopy;
|
11322 | }
|
11323 | hideTemporaryCopy() {
|
11324 | if (this.temporaryCopy !== null) {
|
11325 | this.copiedElement.remove();
|
11326 | this.copiedElement = null;
|
11327 | this.temporaryCopy = null;
|
11328 | }
|
11329 | }
|
11330 | draw(tempDensity) {
|
11331 | const density = tempDensity ? tempDensity : this.nowDrawingDensity;
|
11332 | const pagePos = this.render.convertToGlobal(this.state.position);
|
11333 | const pageWidth = this.render.getRect().pageWidth;
|
11334 | const pageHeight = this.render.getRect().height;
|
11335 | this.element.classList.remove('--simple');
|
11336 | const commonStyle = `
|
11337 | position: absolute;
|
11338 | display: block;
|
11339 | z-index: ${this.element.style.zIndex};
|
11340 | left: 0;
|
11341 | top: 0;
|
11342 | width: ${pageWidth}px;
|
11343 | height: ${pageHeight}px;
|
11344 | `;
|
11345 | density === "hard" ? this.drawHard(commonStyle) : this.drawSoft(pagePos, commonStyle);
|
11346 | }
|
11347 | drawHard(commonStyle = '') {
|
11348 | const pos = this.render.getRect().left + this.render.getRect().width / 2;
|
11349 | const angle = this.state.hardDrawingAngle;
|
11350 | const newStyle = commonStyle + `
|
11351 | backface-visibility: hidden;
|
11352 | -webkit-backface-visibility: hidden;
|
11353 | clip-path: none;
|
11354 | -webkit-clip-path: none;
|
11355 | ` + (this.orientation === 0 ? `transform-origin: ${this.render.getRect().pageWidth}px 0;
|
11356 | transform: translate3d(0, 0, 0) rotateY(${angle}deg);` : `transform-origin: 0 0;
|
11357 | transform: translate3d(${pos}px, 0, 0) rotateY(${angle}deg);`);
|
11358 | this.element.style.cssText = newStyle;
|
11359 | }
|
11360 | drawSoft(position, commonStyle = '') {
|
11361 | let polygon = 'polygon( ';
|
11362 | for (const p of this.state.area) {
|
11363 | if (p !== null) {
|
11364 | let g = this.render.getDirection() === 1 ? {
|
11365 | x: -p.x + this.state.position.x,
|
11366 | y: p.y - this.state.position.y
|
11367 | } : {
|
11368 | x: p.x - this.state.position.x,
|
11369 | y: p.y - this.state.position.y
|
11370 | };
|
11371 | g = Helper.GetRotatedPoint(g, {
|
11372 | x: 0,
|
11373 | y: 0
|
11374 | }, this.state.angle);
|
11375 | polygon += g.x + 'px ' + g.y + 'px, ';
|
11376 | }
|
11377 | }
|
11378 | polygon = polygon.slice(0, -2);
|
11379 | polygon += ')';
|
11380 | const newStyle = commonStyle + `transform-origin: 0 0; clip-path: ${polygon}; -webkit-clip-path: ${polygon};` + (this.render.isSafari() && this.state.angle === 0 ? `transform: translate(${position.x}px, ${position.y}px);` : `transform: translate3d(${position.x}px, ${position.y}px, 0) rotate(${this.state.angle}rad);`);
|
11381 | this.element.style.cssText = newStyle;
|
11382 | }
|
11383 | simpleDraw(orient) {
|
11384 | const rect = this.render.getRect();
|
11385 | const pageWidth = rect.pageWidth;
|
11386 | const pageHeight = rect.height;
|
11387 | const x = orient === 1 ? rect.left + rect.pageWidth : rect.left;
|
11388 | const y = rect.top;
|
11389 | this.element.classList.add('--simple');
|
11390 | this.element.style.cssText = `
|
11391 | position: absolute;
|
11392 | display: block;
|
11393 | height: ${pageHeight}px;
|
11394 | left: ${x}px;
|
11395 | top: ${y}px;
|
11396 | width: ${pageWidth}px;
|
11397 | z-index: ${this.render.getSettings().startZIndex + 1};`;
|
11398 | }
|
11399 | getElement() {
|
11400 | return this.element;
|
11401 | }
|
11402 | load() {
|
11403 | this.isLoad = true;
|
11404 | }
|
11405 | setOrientation(orientation) {
|
11406 | super.setOrientation(orientation);
|
11407 | this.element.classList.remove('--left', '--right');
|
11408 | this.element.classList.add(orientation === 1 ? '--right' : '--left');
|
11409 | }
|
11410 | setDrawingDensity(density) {
|
11411 | this.element.classList.remove('--soft', '--hard');
|
11412 | this.element.classList.add('--' + density);
|
11413 | super.setDrawingDensity(density);
|
11414 | }
|
11415 | }
|
11416 | class HTMLPageCollection extends PageCollection {
|
11417 | constructor(app, render, element, items) {
|
11418 | super(app, render);
|
11419 | this.element = element;
|
11420 | this.pagesElement = items;
|
11421 | }
|
11422 | load() {
|
11423 | for (const pageElement of this.pagesElement) {
|
11424 | const page = new HTMLPage(this.render, pageElement, pageElement.dataset['density'] === 'hard' ? "hard" : "soft");
|
11425 | page.load();
|
11426 | this.pages.push(page);
|
11427 | }
|
11428 | this.createSpread();
|
11429 | }
|
11430 | }
|
11431 | class FlipCalculation {
|
11432 | constructor(direction, corner, pageWidth, pageHeight) {
|
11433 | this.direction = direction;
|
11434 | this.corner = corner;
|
11435 | this.topIntersectPoint = null;
|
11436 | this.sideIntersectPoint = null;
|
11437 | this.bottomIntersectPoint = null;
|
11438 | this.pageWidth = parseInt(pageWidth, 10);
|
11439 | this.pageHeight = parseInt(pageHeight, 10);
|
11440 | }
|
11441 | calc(localPos) {
|
11442 | try {
|
11443 | this.position = this.calcAngleAndPosition(localPos);
|
11444 | this.calculateIntersectPoint(this.position);
|
11445 | return true;
|
11446 | } catch (e) {
|
11447 | return false;
|
11448 | }
|
11449 | }
|
11450 | getFlippingClipArea() {
|
11451 | const result = [];
|
11452 | let clipBottom = false;
|
11453 | result.push(this.rect.topLeft);
|
11454 | result.push(this.topIntersectPoint);
|
11455 | if (this.sideIntersectPoint === null) {
|
11456 | clipBottom = true;
|
11457 | } else {
|
11458 | result.push(this.sideIntersectPoint);
|
11459 | if (this.bottomIntersectPoint === null) clipBottom = false;
|
11460 | }
|
11461 | result.push(this.bottomIntersectPoint);
|
11462 | if (clipBottom || this.corner === "bottom") {
|
11463 | result.push(this.rect.bottomLeft);
|
11464 | }
|
11465 | return result;
|
11466 | }
|
11467 | getBottomClipArea() {
|
11468 | const result = [];
|
11469 | result.push(this.topIntersectPoint);
|
11470 | if (this.corner === "top") {
|
11471 | result.push({
|
11472 | x: this.pageWidth,
|
11473 | y: 0
|
11474 | });
|
11475 | } else {
|
11476 | if (this.topIntersectPoint !== null) {
|
11477 | result.push({
|
11478 | x: this.pageWidth,
|
11479 | y: 0
|
11480 | });
|
11481 | }
|
11482 | result.push({
|
11483 | x: this.pageWidth,
|
11484 | y: this.pageHeight
|
11485 | });
|
11486 | }
|
11487 | if (this.sideIntersectPoint !== null) {
|
11488 | if (Helper.GetDistanceBetweenTwoPoint(this.sideIntersectPoint, this.topIntersectPoint) >= 10) result.push(this.sideIntersectPoint);
|
11489 | } else {
|
11490 | if (this.corner === "top") {
|
11491 | result.push({
|
11492 | x: this.pageWidth,
|
11493 | y: this.pageHeight
|
11494 | });
|
11495 | }
|
11496 | }
|
11497 | result.push(this.bottomIntersectPoint);
|
11498 | result.push(this.topIntersectPoint);
|
11499 | return result;
|
11500 | }
|
11501 | getAngle() {
|
11502 | if (this.direction === 0) {
|
11503 | return -this.angle;
|
11504 | }
|
11505 | return this.angle;
|
11506 | }
|
11507 | getRect() {
|
11508 | return this.rect;
|
11509 | }
|
11510 | getPosition() {
|
11511 | return this.position;
|
11512 | }
|
11513 | getActiveCorner() {
|
11514 | if (this.direction === 0) {
|
11515 | return this.rect.topLeft;
|
11516 | }
|
11517 | return this.rect.topRight;
|
11518 | }
|
11519 | getDirection() {
|
11520 | return this.direction;
|
11521 | }
|
11522 | getFlippingProgress() {
|
11523 | return Math.abs((this.position.x - this.pageWidth) / (2 * this.pageWidth) * 100);
|
11524 | }
|
11525 | getCorner() {
|
11526 | return this.corner;
|
11527 | }
|
11528 | getBottomPagePosition() {
|
11529 | if (this.direction === 1) {
|
11530 | return {
|
11531 | x: this.pageWidth,
|
11532 | y: 0
|
11533 | };
|
11534 | }
|
11535 | return {
|
11536 | x: 0,
|
11537 | y: 0
|
11538 | };
|
11539 | }
|
11540 | getShadowStartPoint() {
|
11541 | if (this.corner === "top") {
|
11542 | return this.topIntersectPoint;
|
11543 | } else {
|
11544 | if (this.sideIntersectPoint !== null) return this.sideIntersectPoint;
|
11545 | return this.topIntersectPoint;
|
11546 | }
|
11547 | }
|
11548 | getShadowAngle() {
|
11549 | const angle = Helper.GetAngleBetweenTwoLine(this.getSegmentToShadowLine(), [{
|
11550 | x: 0,
|
11551 | y: 0
|
11552 | }, {
|
11553 | x: this.pageWidth,
|
11554 | y: 0
|
11555 | }]);
|
11556 | if (this.direction === 0) {
|
11557 | return angle;
|
11558 | }
|
11559 | return Math.PI - angle;
|
11560 | }
|
11561 | calcAngleAndPosition(pos) {
|
11562 | let result = pos;
|
11563 | this.updateAngleAndGeometry(result);
|
11564 | if (this.corner === "top") {
|
11565 | result = this.checkPositionAtCenterLine(result, {
|
11566 | x: 0,
|
11567 | y: 0
|
11568 | }, {
|
11569 | x: 0,
|
11570 | y: this.pageHeight
|
11571 | });
|
11572 | } else {
|
11573 | result = this.checkPositionAtCenterLine(result, {
|
11574 | x: 0,
|
11575 | y: this.pageHeight
|
11576 | }, {
|
11577 | x: 0,
|
11578 | y: 0
|
11579 | });
|
11580 | }
|
11581 | if (Math.abs(result.x - this.pageWidth) < 1 && Math.abs(result.y) < 1) {
|
11582 | throw new Error('Point is too small');
|
11583 | }
|
11584 | return result;
|
11585 | }
|
11586 | updateAngleAndGeometry(pos) {
|
11587 | this.angle = this.calculateAngle(pos);
|
11588 | this.rect = this.getPageRect(pos);
|
11589 | }
|
11590 | calculateAngle(pos) {
|
11591 | const left = this.pageWidth - pos.x + 1;
|
11592 | const top = this.corner === "bottom" ? this.pageHeight - pos.y : pos.y;
|
11593 | let angle = 2 * Math.acos(left / Math.sqrt(top * top + left * left));
|
11594 | if (top < 0) angle = -angle;
|
11595 | const da = Math.PI - angle;
|
11596 | if (!isFinite(angle) || da >= 0 && da < 0.003) throw new Error('The G point is too small');
|
11597 | if (this.corner === "bottom") angle = -angle;
|
11598 | return angle;
|
11599 | }
|
11600 | getPageRect(localPos) {
|
11601 | if (this.corner === "top") {
|
11602 | return this.getRectFromBasePoint([{
|
11603 | x: 0,
|
11604 | y: 0
|
11605 | }, {
|
11606 | x: this.pageWidth,
|
11607 | y: 0
|
11608 | }, {
|
11609 | x: 0,
|
11610 | y: this.pageHeight
|
11611 | }, {
|
11612 | x: this.pageWidth,
|
11613 | y: this.pageHeight
|
11614 | }], localPos);
|
11615 | }
|
11616 | return this.getRectFromBasePoint([{
|
11617 | x: 0,
|
11618 | y: -this.pageHeight
|
11619 | }, {
|
11620 | x: this.pageWidth,
|
11621 | y: -this.pageHeight
|
11622 | }, {
|
11623 | x: 0,
|
11624 | y: 0
|
11625 | }, {
|
11626 | x: this.pageWidth,
|
11627 | y: 0
|
11628 | }], localPos);
|
11629 | }
|
11630 | getRectFromBasePoint(points, localPos) {
|
11631 | return {
|
11632 | topLeft: this.getRotatedPoint(points[0], localPos),
|
11633 | topRight: this.getRotatedPoint(points[1], localPos),
|
11634 | bottomLeft: this.getRotatedPoint(points[2], localPos),
|
11635 | bottomRight: this.getRotatedPoint(points[3], localPos)
|
11636 | };
|
11637 | }
|
11638 | getRotatedPoint(transformedPoint, startPoint) {
|
11639 | return {
|
11640 | x: transformedPoint.x * Math.cos(this.angle) + transformedPoint.y * Math.sin(this.angle) + startPoint.x,
|
11641 | y: transformedPoint.y * Math.cos(this.angle) - transformedPoint.x * Math.sin(this.angle) + startPoint.y
|
11642 | };
|
11643 | }
|
11644 | calculateIntersectPoint(pos) {
|
11645 | const boundRect = {
|
11646 | left: -1,
|
11647 | top: -1,
|
11648 | width: this.pageWidth + 2,
|
11649 | height: this.pageHeight + 2
|
11650 | };
|
11651 | if (this.corner === "top") {
|
11652 | this.topIntersectPoint = Helper.GetIntersectBetweenTwoSegment(boundRect, [pos, this.rect.topRight], [{
|
11653 | x: 0,
|
11654 | y: 0
|
11655 | }, {
|
11656 | x: this.pageWidth,
|
11657 | y: 0
|
11658 | }]);
|
11659 | this.sideIntersectPoint = Helper.GetIntersectBetweenTwoSegment(boundRect, [pos, this.rect.bottomLeft], [{
|
11660 | x: this.pageWidth,
|
11661 | y: 0
|
11662 | }, {
|
11663 | x: this.pageWidth,
|
11664 | y: this.pageHeight
|
11665 | }]);
|
11666 | this.bottomIntersectPoint = Helper.GetIntersectBetweenTwoSegment(boundRect, [this.rect.bottomLeft, this.rect.bottomRight], [{
|
11667 | x: 0,
|
11668 | y: this.pageHeight
|
11669 | }, {
|
11670 | x: this.pageWidth,
|
11671 | y: this.pageHeight
|
11672 | }]);
|
11673 | } else {
|
11674 | this.topIntersectPoint = Helper.GetIntersectBetweenTwoSegment(boundRect, [this.rect.topLeft, this.rect.topRight], [{
|
11675 | x: 0,
|
11676 | y: 0
|
11677 | }, {
|
11678 | x: this.pageWidth,
|
11679 | y: 0
|
11680 | }]);
|
11681 | this.sideIntersectPoint = Helper.GetIntersectBetweenTwoSegment(boundRect, [pos, this.rect.topLeft], [{
|
11682 | x: this.pageWidth,
|
11683 | y: 0
|
11684 | }, {
|
11685 | x: this.pageWidth,
|
11686 | y: this.pageHeight
|
11687 | }]);
|
11688 | this.bottomIntersectPoint = Helper.GetIntersectBetweenTwoSegment(boundRect, [this.rect.bottomLeft, this.rect.bottomRight], [{
|
11689 | x: 0,
|
11690 | y: this.pageHeight
|
11691 | }, {
|
11692 | x: this.pageWidth,
|
11693 | y: this.pageHeight
|
11694 | }]);
|
11695 | }
|
11696 | }
|
11697 | checkPositionAtCenterLine(checkedPos, centerOne, centerTwo) {
|
11698 | let result = checkedPos;
|
11699 | const tmp = Helper.LimitPointToCircle(centerOne, this.pageWidth, result);
|
11700 | if (result !== tmp) {
|
11701 | result = tmp;
|
11702 | this.updateAngleAndGeometry(result);
|
11703 | }
|
11704 | const rad = Math.sqrt(Math.pow(this.pageWidth, 2) + Math.pow(this.pageHeight, 2));
|
11705 | let checkPointOne = this.rect.bottomRight;
|
11706 | let checkPointTwo = this.rect.topLeft;
|
11707 | if (this.corner === "bottom") {
|
11708 | checkPointOne = this.rect.topRight;
|
11709 | checkPointTwo = this.rect.bottomLeft;
|
11710 | }
|
11711 | if (checkPointOne.x <= 0) {
|
11712 | const bottomPoint = Helper.LimitPointToCircle(centerTwo, rad, checkPointTwo);
|
11713 | if (bottomPoint !== result) {
|
11714 | result = bottomPoint;
|
11715 | this.updateAngleAndGeometry(result);
|
11716 | }
|
11717 | }
|
11718 | return result;
|
11719 | }
|
11720 | getSegmentToShadowLine() {
|
11721 | const first = this.getShadowStartPoint();
|
11722 | const second = first !== this.sideIntersectPoint && this.sideIntersectPoint !== null ? this.sideIntersectPoint : this.bottomIntersectPoint;
|
11723 | return [first, second];
|
11724 | }
|
11725 | }
|
11726 | class Flip {
|
11727 | constructor(render, app) {
|
11728 | this.flippingPage = null;
|
11729 | this.bottomPage = null;
|
11730 | this.calc = null;
|
11731 | this.state = "read";
|
11732 | this.render = render;
|
11733 | this.app = app;
|
11734 | }
|
11735 | fold(globalPos) {
|
11736 | this.setState("user_fold");
|
11737 | if (this.calc === null) this.start(globalPos);
|
11738 | this.do(this.render.convertToPage(globalPos));
|
11739 | }
|
11740 | flip(globalPos) {
|
11741 | if (this.app.getSettings().disableFlipByClick && !this.isPointOnCorners(globalPos)) return;
|
11742 | if (this.calc !== null) this.render.finishAnimation();
|
11743 | if (!this.start(globalPos)) return;
|
11744 | const rect = this.getBoundsRect();
|
11745 | this.setState("flipping");
|
11746 | const topMargins = rect.height / 10;
|
11747 | const yStart = this.calc.getCorner() === "bottom" ? rect.height - topMargins : topMargins;
|
11748 | const yDest = this.calc.getCorner() === "bottom" ? rect.height : 0;
|
11749 | this.calc.calc({
|
11750 | x: rect.pageWidth - topMargins,
|
11751 | y: yStart
|
11752 | });
|
11753 | this.animateFlippingTo({
|
11754 | x: rect.pageWidth - topMargins,
|
11755 | y: yStart
|
11756 | }, {
|
11757 | x: -rect.pageWidth,
|
11758 | y: yDest
|
11759 | }, true);
|
11760 | }
|
11761 | start(globalPos) {
|
11762 | this.reset();
|
11763 | const bookPos = this.render.convertToBook(globalPos);
|
11764 | const rect = this.getBoundsRect();
|
11765 | const direction = this.getDirectionByPoint(bookPos);
|
11766 | const flipCorner = bookPos.y >= rect.height / 2 ? "bottom" : "top";
|
11767 | if (!this.checkDirection(direction)) return false;
|
11768 | try {
|
11769 | this.flippingPage = this.app.getPageCollection().getFlippingPage(direction);
|
11770 | this.bottomPage = this.app.getPageCollection().getBottomPage(direction);
|
11771 | if (this.render.getOrientation() === "landscape") {
|
11772 | if (direction === 1) {
|
11773 | const nextPage = this.app.getPageCollection().nextBy(this.flippingPage);
|
11774 | if (nextPage !== null) {
|
11775 | if (this.flippingPage.getDensity() !== nextPage.getDensity()) {
|
11776 | this.flippingPage.setDrawingDensity("hard");
|
11777 | nextPage.setDrawingDensity("hard");
|
11778 | }
|
11779 | }
|
11780 | } else {
|
11781 | const prevPage = this.app.getPageCollection().prevBy(this.flippingPage);
|
11782 | if (prevPage !== null) {
|
11783 | if (this.flippingPage.getDensity() !== prevPage.getDensity()) {
|
11784 | this.flippingPage.setDrawingDensity("hard");
|
11785 | prevPage.setDrawingDensity("hard");
|
11786 | }
|
11787 | }
|
11788 | }
|
11789 | }
|
11790 | this.render.setDirection(direction);
|
11791 | this.calc = new FlipCalculation(direction, flipCorner, rect.pageWidth.toString(10), rect.height.toString(10));
|
11792 | return true;
|
11793 | } catch (e) {
|
11794 | return false;
|
11795 | }
|
11796 | }
|
11797 | do(pagePos) {
|
11798 | if (this.calc === null) return;
|
11799 | if (this.calc.calc(pagePos)) {
|
11800 | const progress = this.calc.getFlippingProgress();
|
11801 | this.bottomPage.setArea(this.calc.getBottomClipArea());
|
11802 | this.bottomPage.setPosition(this.calc.getBottomPagePosition());
|
11803 | this.bottomPage.setAngle(0);
|
11804 | this.bottomPage.setHardAngle(0);
|
11805 | this.flippingPage.setArea(this.calc.getFlippingClipArea());
|
11806 | this.flippingPage.setPosition(this.calc.getActiveCorner());
|
11807 | this.flippingPage.setAngle(this.calc.getAngle());
|
11808 | if (this.calc.getDirection() === 0) {
|
11809 | this.flippingPage.setHardAngle(90 * (200 - progress * 2) / 100);
|
11810 | } else {
|
11811 | this.flippingPage.setHardAngle(-90 * (200 - progress * 2) / 100);
|
11812 | }
|
11813 | this.render.setPageRect(this.calc.getRect());
|
11814 | this.render.setBottomPage(this.bottomPage);
|
11815 | this.render.setFlippingPage(this.flippingPage);
|
11816 | this.render.setShadowData(this.calc.getShadowStartPoint(), this.calc.getShadowAngle(), progress, this.calc.getDirection());
|
11817 | }
|
11818 | }
|
11819 | flipToPage(page, corner) {
|
11820 | const current = this.app.getPageCollection().getCurrentSpreadIndex();
|
11821 | const next = this.app.getPageCollection().getSpreadIndexByPage(page);
|
11822 | try {
|
11823 | if (next > current) {
|
11824 | this.app.getPageCollection().setCurrentSpreadIndex(next - 1);
|
11825 | this.flipNext(corner);
|
11826 | }
|
11827 | if (next < current) {
|
11828 | this.app.getPageCollection().setCurrentSpreadIndex(next + 1);
|
11829 | this.flipPrev(corner);
|
11830 | }
|
11831 | } catch (e) {}
|
11832 | }
|
11833 | flipNext(corner) {
|
11834 | this.flip({
|
11835 | x: this.render.getRect().left + this.render.getRect().pageWidth * 2 - 10,
|
11836 | y: corner === "top" ? 1 : this.render.getRect().height - 2
|
11837 | });
|
11838 | }
|
11839 | flipPrev(corner) {
|
11840 | this.flip({
|
11841 | x: 10,
|
11842 | y: corner === "top" ? 1 : this.render.getRect().height - 2
|
11843 | });
|
11844 | }
|
11845 | stopMove() {
|
11846 | if (this.calc === null) return;
|
11847 | const pos = this.calc.getPosition();
|
11848 | const rect = this.getBoundsRect();
|
11849 | const y = this.calc.getCorner() === "bottom" ? rect.height : 0;
|
11850 | if (pos.x <= 0) this.animateFlippingTo(pos, {
|
11851 | x: -rect.pageWidth,
|
11852 | y
|
11853 | }, true);else this.animateFlippingTo(pos, {
|
11854 | x: rect.pageWidth,
|
11855 | y
|
11856 | }, false);
|
11857 | }
|
11858 | showCorner(globalPos) {
|
11859 | if (!this.checkState("read", "fold_corner")) return;
|
11860 | const rect = this.getBoundsRect();
|
11861 | const pageWidth = rect.pageWidth;
|
11862 | if (this.isPointOnCorners(globalPos)) {
|
11863 | if (this.calc === null) {
|
11864 | if (!this.start(globalPos)) return;
|
11865 | this.setState("fold_corner");
|
11866 | this.calc.calc({
|
11867 | x: pageWidth - 1,
|
11868 | y: 1
|
11869 | });
|
11870 | const fixedCornerSize = 50;
|
11871 | const yStart = this.calc.getCorner() === "bottom" ? rect.height - 1 : 1;
|
11872 | const yDest = this.calc.getCorner() === "bottom" ? rect.height - fixedCornerSize : fixedCornerSize;
|
11873 | this.animateFlippingTo({
|
11874 | x: pageWidth - 1,
|
11875 | y: yStart
|
11876 | }, {
|
11877 | x: pageWidth - fixedCornerSize,
|
11878 | y: yDest
|
11879 | }, false, false);
|
11880 | } else {
|
11881 | this.do(this.render.convertToPage(globalPos));
|
11882 | }
|
11883 | } else {
|
11884 | this.setState("read");
|
11885 | this.render.finishAnimation();
|
11886 | this.stopMove();
|
11887 | }
|
11888 | }
|
11889 | animateFlippingTo(start, dest, isTurned, needReset = true) {
|
11890 | const points = Helper.GetCordsFromTwoPoint(start, dest);
|
11891 | const frames = [];
|
11892 | for (const p of points) frames.push(() => this.do(p));
|
11893 | const duration = this.getAnimationDuration(points.length);
|
11894 | this.render.startAnimation(frames, duration, () => {
|
11895 | if (!this.calc) return;
|
11896 | if (isTurned) {
|
11897 | if (this.calc.getDirection() === 1) this.app.turnToPrevPage();else this.app.turnToNextPage();
|
11898 | }
|
11899 | if (needReset) {
|
11900 | this.render.setBottomPage(null);
|
11901 | this.render.setFlippingPage(null);
|
11902 | this.render.clearShadow();
|
11903 | this.setState("read");
|
11904 | this.reset();
|
11905 | }
|
11906 | });
|
11907 | }
|
11908 | getCalculation() {
|
11909 | return this.calc;
|
11910 | }
|
11911 | getState() {
|
11912 | return this.state;
|
11913 | }
|
11914 | setState(newState) {
|
11915 | if (this.state !== newState) {
|
11916 | this.app.updateState(newState);
|
11917 | this.state = newState;
|
11918 | }
|
11919 | }
|
11920 | getDirectionByPoint(touchPos) {
|
11921 | const rect = this.getBoundsRect();
|
11922 | if (this.render.getOrientation() === "portrait") {
|
11923 | if (touchPos.x - rect.pageWidth <= rect.width / 5) {
|
11924 | return 1;
|
11925 | }
|
11926 | } else if (touchPos.x < rect.width / 2) {
|
11927 | return 1;
|
11928 | }
|
11929 | return 0;
|
11930 | }
|
11931 | getAnimationDuration(size) {
|
11932 | const defaultTime = this.app.getSettings().flippingTime;
|
11933 | if (size >= 1000) return defaultTime;
|
11934 | return size / 1000 * defaultTime;
|
11935 | }
|
11936 | checkDirection(direction) {
|
11937 | if (direction === 0) return this.app.getCurrentPageIndex() < this.app.getPageCount() - 1;
|
11938 | return this.app.getCurrentPageIndex() >= 1;
|
11939 | }
|
11940 | reset() {
|
11941 | this.calc = null;
|
11942 | this.flippingPage = null;
|
11943 | this.bottomPage = null;
|
11944 | }
|
11945 | getBoundsRect() {
|
11946 | return this.render.getRect();
|
11947 | }
|
11948 | checkState(...states) {
|
11949 | for (const state of states) {
|
11950 | if (this.state === state) return true;
|
11951 | }
|
11952 | return false;
|
11953 | }
|
11954 | isPointOnCorners(globalPos) {
|
11955 | const rect = this.getBoundsRect();
|
11956 | const pageWidth = rect.pageWidth;
|
11957 | const operatingDistance = Math.sqrt(Math.pow(pageWidth, 2) + Math.pow(rect.height, 2)) / 5;
|
11958 | const bookPos = this.render.convertToBook(globalPos);
|
11959 | return bookPos.x > 0 && bookPos.y > 0 && bookPos.x < rect.width && bookPos.y < rect.height && (bookPos.x < operatingDistance || bookPos.x > rect.width - operatingDistance) && (bookPos.y < operatingDistance || bookPos.y > rect.height - operatingDistance);
|
11960 | }
|
11961 | }
|
11962 | class Render {
|
11963 | constructor(app, setting) {
|
11964 | this.leftPage = null;
|
11965 | this.rightPage = null;
|
11966 | this.flippingPage = null;
|
11967 | this.bottomPage = null;
|
11968 | this.direction = null;
|
11969 | this.orientation = null;
|
11970 | this.shadow = null;
|
11971 | this.animation = null;
|
11972 | this.pageRect = null;
|
11973 | this.boundsRect = null;
|
11974 | this.timer = 0;
|
11975 | this.safari = false;
|
11976 | this.setting = setting;
|
11977 | this.app = app;
|
11978 | const regex = new RegExp('Version\\/[\\d\\.]+.*Safari/');
|
11979 | this.safari = regex.exec(window.navigator.userAgent) !== null;
|
11980 | }
|
11981 | render(timer) {
|
11982 | if (this.animation !== null) {
|
11983 | const frameIndex = Math.round((timer - this.animation.startedAt) / this.animation.durationFrame);
|
11984 | if (frameIndex < this.animation.frames.length) {
|
11985 | this.animation.frames[frameIndex]();
|
11986 | } else {
|
11987 | this.animation.onAnimateEnd();
|
11988 | this.animation = null;
|
11989 | }
|
11990 | }
|
11991 | this.timer = timer;
|
11992 | this.drawFrame();
|
11993 | }
|
11994 | start() {
|
11995 | this.update();
|
11996 | const loop = timer => {
|
11997 | window.ngxZone.runOutsideAngular(() => {
|
11998 | this.render(timer);
|
11999 | requestAnimationFrame(loop);
|
12000 | });
|
12001 | };
|
12002 | window.ngxZone.runOutsideAngular(() => {
|
12003 | requestAnimationFrame(loop);
|
12004 | });
|
12005 | }
|
12006 | startAnimation(frames, duration, onAnimateEnd) {
|
12007 | this.finishAnimation();
|
12008 | this.animation = {
|
12009 | frames,
|
12010 | duration,
|
12011 | durationFrame: duration / frames.length,
|
12012 | onAnimateEnd,
|
12013 | startedAt: this.timer
|
12014 | };
|
12015 | }
|
12016 | finishAnimation() {
|
12017 | if (this.animation !== null) {
|
12018 | this.animation.frames[this.animation.frames.length - 1]();
|
12019 | if (this.animation.onAnimateEnd !== null) {
|
12020 | this.animation.onAnimateEnd();
|
12021 | }
|
12022 | }
|
12023 | this.animation = null;
|
12024 | }
|
12025 | update() {
|
12026 | this.boundsRect = null;
|
12027 | const orientation = this.calculateBoundsRect();
|
12028 | if (this.orientation !== orientation) {
|
12029 | this.orientation = orientation;
|
12030 | this.app.updateOrientation(orientation);
|
12031 | }
|
12032 | }
|
12033 | calculateBoundsRect() {
|
12034 | let orientation = "landscape";
|
12035 | const blockWidth = this.getBlockWidth();
|
12036 | const middlePoint = {
|
12037 | x: blockWidth / 2,
|
12038 | y: this.getBlockHeight() / 2
|
12039 | };
|
12040 | const ratio = this.setting.width / this.setting.height;
|
12041 | let pageWidth = this.setting.width;
|
12042 | let pageHeight = this.setting.height;
|
12043 | let left = middlePoint.x - pageWidth;
|
12044 | if (this.setting.size === "stretch") {
|
12045 | if (blockWidth < this.setting.minWidth * 2 && this.app.getSettings().usePortrait) orientation = "portrait";
|
12046 | pageWidth = orientation === "portrait" ? this.getBlockWidth() : this.getBlockWidth() / 2;
|
12047 | if (pageWidth > this.setting.maxWidth) pageWidth = this.setting.maxWidth;
|
12048 | pageHeight = pageWidth / ratio;
|
12049 | if (pageHeight > this.getBlockHeight()) {
|
12050 | pageHeight = this.getBlockHeight();
|
12051 | pageWidth = pageHeight * ratio;
|
12052 | }
|
12053 | left = orientation === "portrait" ? middlePoint.x - pageWidth / 2 - pageWidth : middlePoint.x - pageWidth;
|
12054 | } else {
|
12055 | if (blockWidth < pageWidth * 2) {
|
12056 | if (this.app.getSettings().usePortrait) {
|
12057 | orientation = "portrait";
|
12058 | left = middlePoint.x - pageWidth / 2 - pageWidth;
|
12059 | }
|
12060 | }
|
12061 | }
|
12062 | this.boundsRect = {
|
12063 | left,
|
12064 | top: middlePoint.y - pageHeight / 2,
|
12065 | width: pageWidth * 2,
|
12066 | height: pageHeight,
|
12067 | pageWidth: pageWidth
|
12068 | };
|
12069 | return orientation;
|
12070 | }
|
12071 | setShadowData(pos, angle, progress, direction) {
|
12072 | if (!this.app.getSettings().drawShadow) return;
|
12073 | const maxShadowOpacity = 100 * this.getSettings().maxShadowOpacity;
|
12074 | this.shadow = {
|
12075 | pos,
|
12076 | angle,
|
12077 | width: this.getRect().pageWidth * 3 / 4 * progress / 100,
|
12078 | opacity: (100 - progress) * maxShadowOpacity / 100 / 100,
|
12079 | direction,
|
12080 | progress: progress * 2
|
12081 | };
|
12082 | }
|
12083 | clearShadow() {
|
12084 | this.shadow = null;
|
12085 | }
|
12086 | getBlockWidth() {
|
12087 | return this.app.getUI().getDistElement().offsetWidth;
|
12088 | }
|
12089 | getBlockHeight() {
|
12090 | return this.app.getUI().getDistElement().offsetHeight;
|
12091 | }
|
12092 | getDirection() {
|
12093 | return this.direction;
|
12094 | }
|
12095 | getRect() {
|
12096 | if (this.boundsRect === null) this.calculateBoundsRect();
|
12097 | return this.boundsRect;
|
12098 | }
|
12099 | getSettings() {
|
12100 | return this.app.getSettings();
|
12101 | }
|
12102 | getOrientation() {
|
12103 | return this.orientation;
|
12104 | }
|
12105 | setPageRect(pageRect) {
|
12106 | this.pageRect = pageRect;
|
12107 | }
|
12108 | setDirection(direction) {
|
12109 | this.direction = direction;
|
12110 | }
|
12111 | setRightPage(page) {
|
12112 | if (page !== null) page.setOrientation(1);
|
12113 | this.rightPage = page;
|
12114 | }
|
12115 | setLeftPage(page) {
|
12116 | if (page !== null) page.setOrientation(0);
|
12117 | this.leftPage = page;
|
12118 | }
|
12119 | setBottomPage(page) {
|
12120 | if (page !== null) page.setOrientation(this.direction === 1 ? 0 : 1);
|
12121 | this.bottomPage = page;
|
12122 | }
|
12123 | setFlippingPage(page) {
|
12124 | if (page !== null) page.setOrientation(this.direction === 0 && this.orientation !== "portrait" ? 0 : 1);
|
12125 | this.flippingPage = page;
|
12126 | }
|
12127 | convertToBook(pos) {
|
12128 | const rect = this.getRect();
|
12129 | return {
|
12130 | x: pos.x - rect.left,
|
12131 | y: pos.y - rect.top
|
12132 | };
|
12133 | }
|
12134 | isSafari() {
|
12135 | return this.safari;
|
12136 | }
|
12137 | convertToPage(pos, direction) {
|
12138 | if (!direction) direction = this.direction;
|
12139 | const rect = this.getRect();
|
12140 | const x = direction === 0 ? pos.x - rect.left - rect.width / 2 : rect.width / 2 - pos.x + rect.left;
|
12141 | return {
|
12142 | x,
|
12143 | y: pos.y - rect.top
|
12144 | };
|
12145 | }
|
12146 | convertToGlobal(pos, direction) {
|
12147 | if (!direction) direction = this.direction;
|
12148 | if (pos == null) return null;
|
12149 | const rect = this.getRect();
|
12150 | const x = direction === 0 ? pos.x + rect.left + rect.width / 2 : rect.width / 2 - pos.x + rect.left;
|
12151 | return {
|
12152 | x,
|
12153 | y: pos.y + rect.top
|
12154 | };
|
12155 | }
|
12156 | convertRectToGlobal(rect, direction) {
|
12157 | if (!direction) direction = this.direction;
|
12158 | return {
|
12159 | topLeft: this.convertToGlobal(rect.topLeft, direction),
|
12160 | topRight: this.convertToGlobal(rect.topRight, direction),
|
12161 | bottomLeft: this.convertToGlobal(rect.bottomLeft, direction),
|
12162 | bottomRight: this.convertToGlobal(rect.bottomRight, direction)
|
12163 | };
|
12164 | }
|
12165 | }
|
12166 | class CanvasRender extends Render {
|
12167 | constructor(app, setting, inCanvas) {
|
12168 | super(app, setting);
|
12169 | this.canvas = inCanvas;
|
12170 | const options = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {
|
12171 | willReadFrequently: true
|
12172 | } : undefined;
|
12173 | const ctx = canvas.getContext("2d", options);
|
12174 | }
|
12175 | getContext() {
|
12176 | return this.ctx;
|
12177 | }
|
12178 | reload() {}
|
12179 | drawFrame() {
|
12180 | this.clear();
|
12181 | if (this.orientation !== "portrait") if (this.leftPage != null) this.leftPage.simpleDraw(0);
|
12182 | if (this.rightPage != null) this.rightPage.simpleDraw(1);
|
12183 | if (this.bottomPage != null) this.bottomPage.draw();
|
12184 | this.drawBookShadow();
|
12185 | if (this.flippingPage != null) this.flippingPage.draw();
|
12186 | if (this.shadow != null) {
|
12187 | this.drawOuterShadow();
|
12188 | this.drawInnerShadow();
|
12189 | }
|
12190 | const rect = this.getRect();
|
12191 | if (this.orientation === "portrait") {
|
12192 | this.ctx.beginPath();
|
12193 | this.ctx.rect(rect.left + rect.pageWidth, rect.top, rect.width, rect.height);
|
12194 | this.ctx.clip();
|
12195 | }
|
12196 | }
|
12197 | drawBookShadow() {
|
12198 | const rect = this.getRect();
|
12199 | this.ctx.save();
|
12200 | this.ctx.beginPath();
|
12201 | const shadowSize = rect.width / 20;
|
12202 | this.ctx.rect(rect.left, rect.top, rect.width, rect.height);
|
12203 | const shadowPos = {
|
12204 | x: rect.left + rect.width / 2 - shadowSize / 2,
|
12205 | y: 0
|
12206 | };
|
12207 | this.ctx.translate(shadowPos.x, shadowPos.y);
|
12208 | const outerGradient = this.ctx.createLinearGradient(0, 0, shadowSize, 0);
|
12209 | outerGradient.addColorStop(0, 'rgba(0, 0, 0, 0)');
|
12210 | outerGradient.addColorStop(0.4, 'rgba(0, 0, 0, 0.2)');
|
12211 | outerGradient.addColorStop(0.49, 'rgba(0, 0, 0, 0.1)');
|
12212 | outerGradient.addColorStop(0.5, 'rgba(0, 0, 0, 0.5)');
|
12213 | outerGradient.addColorStop(0.51, 'rgba(0, 0, 0, 0.4)');
|
12214 | outerGradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
12215 | this.ctx.clip();
|
12216 | this.ctx.fillStyle = outerGradient;
|
12217 | this.ctx.fillRect(0, 0, shadowSize, rect.height * 2);
|
12218 | this.ctx.restore();
|
12219 | }
|
12220 | drawOuterShadow() {
|
12221 | const rect = this.getRect();
|
12222 | this.ctx.save();
|
12223 | this.ctx.beginPath();
|
12224 | this.ctx.rect(rect.left, rect.top, rect.width, rect.height);
|
12225 | const shadowPos = this.convertToGlobal({
|
12226 | x: this.shadow.pos.x,
|
12227 | y: this.shadow.pos.y
|
12228 | });
|
12229 | this.ctx.translate(shadowPos.x, shadowPos.y);
|
12230 | this.ctx.rotate(Math.PI + this.shadow.angle + Math.PI / 2);
|
12231 | const outerGradient = this.ctx.createLinearGradient(0, 0, this.shadow.width, 0);
|
12232 | if (this.shadow.direction === 0) {
|
12233 | this.ctx.translate(0, -100);
|
12234 | outerGradient.addColorStop(0, 'rgba(0, 0, 0, ' + this.shadow.opacity + ')');
|
12235 | outerGradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
12236 | } else {
|
12237 | this.ctx.translate(-this.shadow.width, -100);
|
12238 | outerGradient.addColorStop(0, 'rgba(0, 0, 0, 0)');
|
12239 | outerGradient.addColorStop(1, 'rgba(0, 0, 0, ' + this.shadow.opacity + ')');
|
12240 | }
|
12241 | this.ctx.clip();
|
12242 | this.ctx.fillStyle = outerGradient;
|
12243 | this.ctx.fillRect(0, 0, this.shadow.width, rect.height * 2);
|
12244 | this.ctx.restore();
|
12245 | }
|
12246 | drawInnerShadow() {
|
12247 | const rect = this.getRect();
|
12248 | this.ctx.save();
|
12249 | this.ctx.beginPath();
|
12250 | const shadowPos = this.convertToGlobal({
|
12251 | x: this.shadow.pos.x,
|
12252 | y: this.shadow.pos.y
|
12253 | });
|
12254 | const pageRect = this.convertRectToGlobal(this.pageRect);
|
12255 | this.ctx.moveTo(pageRect.topLeft.x, pageRect.topLeft.y);
|
12256 | this.ctx.lineTo(pageRect.topRight.x, pageRect.topRight.y);
|
12257 | this.ctx.lineTo(pageRect.bottomRight.x, pageRect.bottomRight.y);
|
12258 | this.ctx.lineTo(pageRect.bottomLeft.x, pageRect.bottomLeft.y);
|
12259 | this.ctx.translate(shadowPos.x, shadowPos.y);
|
12260 | this.ctx.rotate(Math.PI + this.shadow.angle + Math.PI / 2);
|
12261 | const isw = this.shadow.width * 3 / 4;
|
12262 | const innerGradient = this.ctx.createLinearGradient(0, 0, isw, 0);
|
12263 | if (this.shadow.direction === 0) {
|
12264 | this.ctx.translate(-isw, -100);
|
12265 | innerGradient.addColorStop(1, 'rgba(0, 0, 0, ' + this.shadow.opacity + ')');
|
12266 | innerGradient.addColorStop(0.9, 'rgba(0, 0, 0, 0.05)');
|
12267 | innerGradient.addColorStop(0.7, 'rgba(0, 0, 0, ' + this.shadow.opacity + ')');
|
12268 | innerGradient.addColorStop(0, 'rgba(0, 0, 0, 0)');
|
12269 | } else {
|
12270 | this.ctx.translate(0, -100);
|
12271 | innerGradient.addColorStop(0, 'rgba(0, 0, 0, ' + this.shadow.opacity + ')');
|
12272 | innerGradient.addColorStop(0.1, 'rgba(0, 0, 0, 0.05)');
|
12273 | innerGradient.addColorStop(0.3, 'rgba(0, 0, 0, ' + this.shadow.opacity + ')');
|
12274 | innerGradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
|
12275 | }
|
12276 | this.ctx.clip();
|
12277 | this.ctx.fillStyle = innerGradient;
|
12278 | this.ctx.fillRect(0, 0, isw, rect.height * 2);
|
12279 | this.ctx.restore();
|
12280 | }
|
12281 | clear() {
|
12282 | this.ctx.fillStyle = 'white';
|
12283 | this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
12284 | }
|
12285 | }
|
12286 | class UI {
|
12287 | constructor(inBlock, app, setting) {
|
12288 | this.touchPoint = null;
|
12289 | this.swipeTimeout = 250;
|
12290 | this.onResize = () => {
|
12291 | this.update();
|
12292 | };
|
12293 | this.onMouseDown = e => {
|
12294 | if (this.checkTarget(e.target)) {
|
12295 | const pos = this.getMousePos(e.clientX, e.clientY);
|
12296 | this.app.startUserTouch(pos);
|
12297 | e.preventDefault();
|
12298 | }
|
12299 | };
|
12300 | this.onTouchStart = e => {
|
12301 | if (this.checkTarget(e.target)) {
|
12302 | if (e.changedTouches.length > 0) {
|
12303 | const t = e.changedTouches[0];
|
12304 | const pos = this.getMousePos(t.clientX, t.clientY);
|
12305 | this.touchPoint = {
|
12306 | point: pos,
|
12307 | time: Date.now()
|
12308 | };
|
12309 | setTimeout(() => {
|
12310 | if (this.touchPoint !== null) {
|
12311 | this.app.startUserTouch(pos);
|
12312 | }
|
12313 | }, this.swipeTimeout);
|
12314 | if (!this.app.getSettings().mobileScrollSupport) e.preventDefault();
|
12315 | }
|
12316 | }
|
12317 | };
|
12318 | this.onMouseUp = e => {
|
12319 | const pos = this.getMousePos(e.clientX, e.clientY);
|
12320 | this.app.userStop(pos);
|
12321 | };
|
12322 | this.onMouseMove = e => {
|
12323 | const pos = this.getMousePos(e.clientX, e.clientY);
|
12324 | this.app.userMove(pos, false);
|
12325 | };
|
12326 | this.onTouchMove = e => {
|
12327 | if (e.changedTouches.length > 0) {
|
12328 | const t = e.changedTouches[0];
|
12329 | const pos = this.getMousePos(t.clientX, t.clientY);
|
12330 | if (this.app.getSettings().mobileScrollSupport) {
|
12331 | if (this.touchPoint !== null) {
|
12332 | if (Math.abs(this.touchPoint.point.x - pos.x) > 10 || this.app.getState() !== "read") {
|
12333 | if (e.cancelable) this.app.userMove(pos, true);
|
12334 | }
|
12335 | }
|
12336 | if (this.app.getState() !== "read") {
|
12337 | e.preventDefault();
|
12338 | }
|
12339 | } else {
|
12340 | this.app.userMove(pos, true);
|
12341 | }
|
12342 | }
|
12343 | };
|
12344 | this.onTouchEnd = e => {
|
12345 | if (e.changedTouches.length > 0) {
|
12346 | const t = e.changedTouches[0];
|
12347 | const pos = this.getMousePos(t.clientX, t.clientY);
|
12348 | let isSwipe = false;
|
12349 | if (this.touchPoint !== null) {
|
12350 | const dx = pos.x - this.touchPoint.point.x;
|
12351 | const distY = Math.abs(pos.y - this.touchPoint.point.y);
|
12352 | if (Math.abs(dx) > this.swipeDistance && distY < this.swipeDistance * 2 && Date.now() - this.touchPoint.time < this.swipeTimeout) {
|
12353 | if (dx > 0) {
|
12354 | this.app.flipPrev(this.touchPoint.point.y < this.app.getRender().getRect().height / 2 ? "top" : "bottom");
|
12355 | } else {
|
12356 | this.app.flipNext(this.touchPoint.point.y < this.app.getRender().getRect().height / 2 ? "top" : "bottom");
|
12357 | }
|
12358 | isSwipe = true;
|
12359 | }
|
12360 | this.touchPoint = null;
|
12361 | }
|
12362 | this.app.userStop(pos, isSwipe);
|
12363 | }
|
12364 | };
|
12365 | this.parentElement = inBlock;
|
12366 | inBlock.classList.add('stf__parent');
|
12367 | inBlock.insertAdjacentHTML('afterbegin', '<div class="stf__wrapper"></div>');
|
12368 | this.wrapper = inBlock.querySelector('.stf__wrapper');
|
12369 | this.app = app;
|
12370 | const k = this.app.getSettings().usePortrait ? 1 : 2;
|
12371 | inBlock.style.minWidth = setting.minWidth * k + 'px';
|
12372 | inBlock.style.minHeight = setting.minHeight + 'px';
|
12373 | if (setting.size === "fixed") {
|
12374 | inBlock.style.minWidth = setting.width * k + 'px';
|
12375 | inBlock.style.minHeight = setting.height + 'px';
|
12376 | }
|
12377 | if (setting.autoSize) {
|
12378 | inBlock.style.width = '100%';
|
12379 | inBlock.style.maxWidth = setting.maxWidth * 2 + 'px';
|
12380 | }
|
12381 | inBlock.style.display = 'block';
|
12382 | window.addEventListener('resize', this.onResize, false);
|
12383 | this.swipeDistance = setting.swipeDistance;
|
12384 | }
|
12385 | destroy() {
|
12386 | if (this.app.getSettings().useMouseEvents) this.removeHandlers();
|
12387 | this.distElement.remove();
|
12388 | this.wrapper.remove();
|
12389 | }
|
12390 | getDistElement() {
|
12391 | return this.distElement;
|
12392 | }
|
12393 | getWrapper() {
|
12394 | return this.wrapper;
|
12395 | }
|
12396 | setOrientationStyle(orientation) {
|
12397 | this.wrapper.classList.remove('--portrait', '--landscape');
|
12398 | if (orientation === "portrait") {
|
12399 | if (this.app.getSettings().autoSize) this.wrapper.style.paddingBottom = this.app.getSettings().height / this.app.getSettings().width * 100 + '%';
|
12400 | this.wrapper.classList.add('--portrait');
|
12401 | } else {
|
12402 | if (this.app.getSettings().autoSize) this.wrapper.style.paddingBottom = this.app.getSettings().height / (this.app.getSettings().width * 2) * 100 + '%';
|
12403 | this.wrapper.classList.add('--landscape');
|
12404 | }
|
12405 | this.update();
|
12406 | }
|
12407 | removeHandlers() {
|
12408 | window.removeEventListener('resize', this.onResize);
|
12409 | this.distElement.removeEventListener('mousedown', this.onMouseDown);
|
12410 | this.distElement.removeEventListener('touchstart', this.onTouchStart);
|
12411 | window.removeEventListener('mousemove', this.onMouseMove);
|
12412 | window.removeEventListener('touchmove', this.onTouchMove);
|
12413 | window.removeEventListener('mouseup', this.onMouseUp);
|
12414 | window.removeEventListener('touchend', this.onTouchEnd);
|
12415 | }
|
12416 | setHandlers() {
|
12417 | window.addEventListener('resize', this.onResize, false);
|
12418 | if (!this.app.getSettings().useMouseEvents) return;
|
12419 | this.distElement.addEventListener('mousedown', this.onMouseDown);
|
12420 | this.distElement.addEventListener('touchstart', this.onTouchStart);
|
12421 | window.addEventListener('mousemove', this.onMouseMove);
|
12422 | window.addEventListener('touchmove', this.onTouchMove, {
|
12423 | passive: !this.app.getSettings().mobileScrollSupport
|
12424 | });
|
12425 | window.addEventListener('mouseup', this.onMouseUp);
|
12426 | window.addEventListener('touchend', this.onTouchEnd);
|
12427 | }
|
12428 | getMousePos(x, y) {
|
12429 | const rect = this.distElement.getBoundingClientRect();
|
12430 | return {
|
12431 | x: x - rect.left,
|
12432 | y: y - rect.top
|
12433 | };
|
12434 | }
|
12435 | checkTarget(targer) {
|
12436 | if (!this.app.getSettings().clickEventForward) return true;
|
12437 | if (['a', 'button'].includes(targer.tagName.toLowerCase())) {
|
12438 | return false;
|
12439 | }
|
12440 | return true;
|
12441 | }
|
12442 | }
|
12443 | class HTMLUI extends UI {
|
12444 | constructor(inBlock, app, setting, items) {
|
12445 | super(inBlock, app, setting);
|
12446 | this.wrapper.insertAdjacentHTML('afterbegin', '<div class="stf__block"></div>');
|
12447 | this.distElement = inBlock.querySelector('.stf__block');
|
12448 | this.items = items;
|
12449 | for (const item of items) {
|
12450 | this.distElement.appendChild(item);
|
12451 | }
|
12452 | this.setHandlers();
|
12453 | }
|
12454 | clear() {
|
12455 | for (const item of this.items) {
|
12456 | this.parentElement.appendChild(item);
|
12457 | }
|
12458 | }
|
12459 | updateItems(items) {
|
12460 | this.removeHandlers();
|
12461 | this.distElement.innerHTML = '';
|
12462 | for (const item of items) {
|
12463 | this.distElement.appendChild(item);
|
12464 | }
|
12465 | this.items = items;
|
12466 | this.setHandlers();
|
12467 | }
|
12468 | update() {
|
12469 | this.app.getRender().update();
|
12470 | }
|
12471 | }
|
12472 | class CanvasUI extends UI {
|
12473 | constructor(inBlock, app, setting) {
|
12474 | super(inBlock, app, setting);
|
12475 | this.wrapper.innerHTML = '<canvas class="stf__canvas"></canvas>';
|
12476 | this.canvas = inBlock.querySelectorAll('canvas')[0];
|
12477 | this.distElement = this.canvas;
|
12478 | this.resizeCanvas();
|
12479 | this.setHandlers();
|
12480 | }
|
12481 | resizeCanvas() {
|
12482 | const cs = getComputedStyle(this.canvas);
|
12483 | const width = parseInt(cs.getPropertyValue('width'), 10);
|
12484 | const height = parseInt(cs.getPropertyValue('height'), 10);
|
12485 | this.canvas.width = width;
|
12486 | this.canvas.height = height;
|
12487 | }
|
12488 | getCanvas() {
|
12489 | return this.canvas;
|
12490 | }
|
12491 | update() {
|
12492 | this.resizeCanvas();
|
12493 | this.app.getRender().update();
|
12494 | }
|
12495 | }
|
12496 | class EventObject {
|
12497 | constructor() {
|
12498 | this.events = new Map();
|
12499 | }
|
12500 | on(eventName, callback) {
|
12501 | if (!this.events.has(eventName)) {
|
12502 | this.events.set(eventName, [callback]);
|
12503 | } else {
|
12504 | this.events.get(eventName).push(callback);
|
12505 | }
|
12506 | return this;
|
12507 | }
|
12508 | off(event) {
|
12509 | this.events.delete(event);
|
12510 | }
|
12511 | trigger(eventName, app, data = null) {
|
12512 | if (!this.events.has(eventName)) return;
|
12513 | for (const callback of this.events.get(eventName)) {
|
12514 | callback({
|
12515 | data,
|
12516 | object: app
|
12517 | });
|
12518 | }
|
12519 | }
|
12520 | }
|
12521 | class HTMLRender extends Render {
|
12522 | constructor(app, setting, element) {
|
12523 | super(app, setting);
|
12524 | this.outerShadow = null;
|
12525 | this.innerShadow = null;
|
12526 | this.hardShadow = null;
|
12527 | this.hardInnerShadow = null;
|
12528 | this.element = element;
|
12529 | this.createShadows();
|
12530 | }
|
12531 | createShadows() {
|
12532 | this.element.insertAdjacentHTML('beforeend', `<div class="stf__outerShadow"></div>
|
12533 | <div class="stf__innerShadow"></div>
|
12534 | <div class="stf__hardShadow"></div>
|
12535 | <div class="stf__hardInnerShadow"></div>`);
|
12536 | this.outerShadow = this.element.querySelector('.stf__outerShadow');
|
12537 | this.innerShadow = this.element.querySelector('.stf__innerShadow');
|
12538 | this.hardShadow = this.element.querySelector('.stf__hardShadow');
|
12539 | this.hardInnerShadow = this.element.querySelector('.stf__hardInnerShadow');
|
12540 | }
|
12541 | clearShadow() {
|
12542 | super.clearShadow();
|
12543 | this.outerShadow.style.cssText = 'display: none';
|
12544 | this.innerShadow.style.cssText = 'display: none';
|
12545 | this.hardShadow.style.cssText = 'display: none';
|
12546 | this.hardInnerShadow.style.cssText = 'display: none';
|
12547 | }
|
12548 | reload() {
|
12549 | const testShadow = this.element.querySelector('.stf__outerShadow');
|
12550 | if (!testShadow) {
|
12551 | this.createShadows();
|
12552 | }
|
12553 | }
|
12554 | drawHardInnerShadow() {
|
12555 | const rect = this.getRect();
|
12556 | const progress = this.shadow.progress > 100 ? 200 - this.shadow.progress : this.shadow.progress;
|
12557 | let innerShadowSize = (100 - progress) * (2.5 * rect.pageWidth) / 100 + 20;
|
12558 | if (innerShadowSize > rect.pageWidth) innerShadowSize = rect.pageWidth;
|
12559 | let newStyle = `
|
12560 | display: block;
|
12561 | z-index: ${(this.getSettings().startZIndex + 5).toString(10)};
|
12562 | width: ${innerShadowSize}px;
|
12563 | height: ${rect.height}px;
|
12564 | background: linear-gradient(to right,
|
12565 | rgba(0, 0, 0, ${this.shadow.opacity * progress / 100}) 5%,
|
12566 | rgba(0, 0, 0, 0) 100%);
|
12567 | left: ${rect.left + rect.width / 2}px;
|
12568 | transform-origin: 0 0;
|
12569 | `;
|
12570 | newStyle += this.getDirection() === 0 && this.shadow.progress > 100 || this.getDirection() === 1 && this.shadow.progress <= 100 ? `transform: translate3d(0, 0, 0);` : `transform: translate3d(0, 0, 0) rotateY(180deg);`;
|
12571 | this.hardInnerShadow.style.cssText = newStyle;
|
12572 | }
|
12573 | drawHardOuterShadow() {
|
12574 | const rect = this.getRect();
|
12575 | const progress = this.shadow.progress > 100 ? 200 - this.shadow.progress : this.shadow.progress;
|
12576 | let shadowSize = (100 - progress) * (2.5 * rect.pageWidth) / 100 + 20;
|
12577 | if (shadowSize > rect.pageWidth) shadowSize = rect.pageWidth;
|
12578 | let newStyle = `
|
12579 | display: block;
|
12580 | z-index: ${(this.getSettings().startZIndex + 4).toString(10)};
|
12581 | width: ${shadowSize}px;
|
12582 | height: ${rect.height}px;
|
12583 | background: linear-gradient(to left, rgba(0, 0, 0, ${this.shadow.opacity}) 5%, rgba(0, 0, 0, 0) 100%);
|
12584 | left: ${rect.left + rect.width / 2}px;
|
12585 | transform-origin: 0 0;
|
12586 | `;
|
12587 | newStyle += this.getDirection() === 0 && this.shadow.progress > 100 || this.getDirection() === 1 && this.shadow.progress <= 100 ? `transform: translate3d(0, 0, 0) rotateY(180deg);` : `transform: translate3d(0, 0, 0);`;
|
12588 | this.hardShadow.style.cssText = newStyle;
|
12589 | }
|
12590 | drawInnerShadow() {
|
12591 | const rect = this.getRect();
|
12592 | const innerShadowSize = this.shadow.width * 3 / 4;
|
12593 | const shadowTranslate = this.getDirection() === 0 ? innerShadowSize : 0;
|
12594 | const shadowDirection = this.getDirection() === 0 ? 'to left' : 'to right';
|
12595 | const shadowPos = this.convertToGlobal(this.shadow.pos);
|
12596 | const angle = this.shadow.angle + 3 * Math.PI / 2;
|
12597 | const clip = [this.pageRect.topLeft, this.pageRect.topRight, this.pageRect.bottomRight, this.pageRect.bottomLeft];
|
12598 | let polygon = 'polygon( ';
|
12599 | for (const p of clip) {
|
12600 | let g = this.getDirection() === 1 ? {
|
12601 | x: -p.x + this.shadow.pos.x,
|
12602 | y: p.y - this.shadow.pos.y
|
12603 | } : {
|
12604 | x: p.x - this.shadow.pos.x,
|
12605 | y: p.y - this.shadow.pos.y
|
12606 | };
|
12607 | g = Helper.GetRotatedPoint(g, {
|
12608 | x: shadowTranslate,
|
12609 | y: 100
|
12610 | }, angle);
|
12611 | polygon += g.x + 'px ' + g.y + 'px, ';
|
12612 | }
|
12613 | polygon = polygon.slice(0, -2);
|
12614 | polygon += ')';
|
12615 | const newStyle = `
|
12616 | display: block;
|
12617 | z-index: ${(this.getSettings().startZIndex + 10).toString(10)};
|
12618 | width: ${innerShadowSize}px;
|
12619 | height: ${rect.height * 2}px;
|
12620 | background: linear-gradient(${shadowDirection},
|
12621 | rgba(0, 0, 0, ${this.shadow.opacity}) 5%,
|
12622 | rgba(0, 0, 0, 0.05) 15%,
|
12623 | rgba(0, 0, 0, ${this.shadow.opacity}) 35%,
|
12624 | rgba(0, 0, 0, 0) 100%);
|
12625 | transform-origin: ${shadowTranslate}px 100px;
|
12626 | transform: translate3d(${shadowPos.x - shadowTranslate}px, ${shadowPos.y - 100}px, 0) rotate(${angle}rad);
|
12627 | clip-path: ${polygon};
|
12628 | -webkit-clip-path: ${polygon};
|
12629 | `;
|
12630 | this.innerShadow.style.cssText = newStyle;
|
12631 | }
|
12632 | drawOuterShadow() {
|
12633 | const rect = this.getRect();
|
12634 | const shadowPos = this.convertToGlobal({
|
12635 | x: this.shadow.pos.x,
|
12636 | y: this.shadow.pos.y
|
12637 | });
|
12638 | const angle = this.shadow.angle + 3 * Math.PI / 2;
|
12639 | const shadowTranslate = this.getDirection() === 1 ? this.shadow.width : 0;
|
12640 | const shadowDirection = this.getDirection() === 0 ? 'to right' : 'to left';
|
12641 | const clip = [{
|
12642 | x: 0,
|
12643 | y: 0
|
12644 | }, {
|
12645 | x: rect.pageWidth,
|
12646 | y: 0
|
12647 | }, {
|
12648 | x: rect.pageWidth,
|
12649 | y: rect.height
|
12650 | }, {
|
12651 | x: 0,
|
12652 | y: rect.height
|
12653 | }];
|
12654 | let polygon = 'polygon( ';
|
12655 | for (const p of clip) {
|
12656 | if (p !== null) {
|
12657 | let g = this.getDirection() === 1 ? {
|
12658 | x: -p.x + this.shadow.pos.x,
|
12659 | y: p.y - this.shadow.pos.y
|
12660 | } : {
|
12661 | x: p.x - this.shadow.pos.x,
|
12662 | y: p.y - this.shadow.pos.y
|
12663 | };
|
12664 | g = Helper.GetRotatedPoint(g, {
|
12665 | x: shadowTranslate,
|
12666 | y: 100
|
12667 | }, angle);
|
12668 | polygon += g.x + 'px ' + g.y + 'px, ';
|
12669 | }
|
12670 | }
|
12671 | polygon = polygon.slice(0, -2);
|
12672 | polygon += ')';
|
12673 | const newStyle = `
|
12674 | display: block;
|
12675 | z-index: ${(this.getSettings().startZIndex + 10).toString(10)};
|
12676 | width: ${this.shadow.width}px;
|
12677 | height: ${rect.height * 2}px;
|
12678 | background: linear-gradient(${shadowDirection}, rgba(0, 0, 0, ${this.shadow.opacity}), rgba(0, 0, 0, 0));
|
12679 | transform-origin: ${shadowTranslate}px 100px;
|
12680 | transform: translate3d(${shadowPos.x - shadowTranslate}px, ${shadowPos.y - 100}px, 0) rotate(${angle}rad);
|
12681 | clip-path: ${polygon};
|
12682 | -webkit-clip-path: ${polygon};
|
12683 | `;
|
12684 | this.outerShadow.style.cssText = newStyle;
|
12685 | }
|
12686 | drawLeftPage() {
|
12687 | if (this.orientation === "portrait" || this.leftPage === null) return;
|
12688 | if (this.direction === 1 && this.flippingPage !== null && this.flippingPage.getDrawingDensity() === "hard") {
|
12689 | const angle = this.flippingPage.getHardAngle();
|
12690 | if (angle < -90) {
|
12691 | this.leftPage.getElement().style.zIndex = (this.getSettings().startZIndex + 5).toString(10);
|
12692 | this.leftPage.setHardDrawingAngle(180 + this.flippingPage.getHardAngle());
|
12693 | this.leftPage.draw(this.flippingPage.getDrawingDensity());
|
12694 | } else {
|
12695 | this.leftPage.getElement().style.display = "none";
|
12696 | }
|
12697 | } else {
|
12698 | this.leftPage.simpleDraw(0);
|
12699 | }
|
12700 | }
|
12701 | drawRightPage() {
|
12702 | if (this.rightPage === null) return;
|
12703 | if (this.direction === 0 && this.flippingPage !== null && this.flippingPage.getDrawingDensity() === "hard") {
|
12704 | const angle = this.flippingPage.getHardAngle();
|
12705 | if (angle > 90) {
|
12706 | this.rightPage.getElement().style.zIndex = (this.getSettings().startZIndex + 5).toString(10);
|
12707 | this.rightPage.setHardDrawingAngle(180 + this.flippingPage.getHardAngle());
|
12708 | this.rightPage.draw(this.flippingPage.getDrawingDensity());
|
12709 | } else {
|
12710 | this.rightPage.getElement().style.display = "none";
|
12711 | }
|
12712 | } else {
|
12713 | this.rightPage.simpleDraw(1);
|
12714 | }
|
12715 | }
|
12716 | drawBottomPage() {
|
12717 | if (this.bottomPage === null) return;
|
12718 | const tempDensity = this.flippingPage != null ? this.flippingPage.getDrawingDensity() : null;
|
12719 | if (!(this.orientation === "portrait" && this.direction === 1)) {
|
12720 | this.bottomPage.getElement().style.zIndex = (this.getSettings().startZIndex + 3).toString(10);
|
12721 | this.bottomPage.draw(tempDensity);
|
12722 | }
|
12723 | }
|
12724 | drawFrame() {
|
12725 | if (this.flippingPage !== null) {
|
12726 | if (this.flippingPage.getHardAngle() === this.lastAngle) {
|
12727 | return;
|
12728 | }
|
12729 | this.lastAngle = this.flippingPage.getHardAngle();
|
12730 | } else {
|
12731 | this.lastAngle = -1234;
|
12732 | }
|
12733 | this.clear();
|
12734 | this.drawLeftPage();
|
12735 | this.drawRightPage();
|
12736 | this.drawBottomPage();
|
12737 | if (this.flippingPage != null) {
|
12738 | const angle = this.flippingPage.state.hardDrawingAngle;
|
12739 | if (angle <= 90) {
|
12740 | this.flippingPage.getElement().style.zIndex = (this.getSettings().startZIndex + 5).toString(10);
|
12741 | this.flippingPage.draw();
|
12742 | } else {
|
12743 | this.flippingPage.getElement().style.display = "none";
|
12744 | }
|
12745 | }
|
12746 | if (this.shadow != null && this.flippingPage !== null) {
|
12747 | if (this.flippingPage.getDrawingDensity() === "soft") {
|
12748 | this.drawOuterShadow();
|
12749 | this.drawInnerShadow();
|
12750 | } else {
|
12751 | this.drawHardOuterShadow();
|
12752 | this.drawHardInnerShadow();
|
12753 | }
|
12754 | }
|
12755 | }
|
12756 | clear() {
|
12757 | for (const page of this.app.getPageCollection().getPages()) {
|
12758 | if (page !== this.leftPage && page !== this.rightPage && page !== this.flippingPage && page !== this.bottomPage) {
|
12759 | const style = page.getElement().style;
|
12760 | if (style.display !== 'none') {
|
12761 | style.cssText = 'display: none';
|
12762 | }
|
12763 | }
|
12764 | if (page.getTemporaryCopy() !== this.flippingPage) {
|
12765 | page.hideTemporaryCopy();
|
12766 | }
|
12767 | }
|
12768 | }
|
12769 | update() {
|
12770 | super.update();
|
12771 | if (this.rightPage !== null) {
|
12772 | this.rightPage.setOrientation(1);
|
12773 | }
|
12774 | if (this.leftPage !== null) {
|
12775 | this.leftPage.setOrientation(0);
|
12776 | }
|
12777 | }
|
12778 | }
|
12779 | class Settings {
|
12780 | constructor() {
|
12781 | this._default = {
|
12782 | startPage: 0,
|
12783 | size: "fixed",
|
12784 | width: 0,
|
12785 | height: 0,
|
12786 | minWidth: 0,
|
12787 | maxWidth: 0,
|
12788 | minHeight: 0,
|
12789 | maxHeight: 0,
|
12790 | drawShadow: true,
|
12791 | flippingTime: 1000,
|
12792 | usePortrait: true,
|
12793 | startZIndex: 0,
|
12794 | autoSize: true,
|
12795 | maxShadowOpacity: 1,
|
12796 | showCover: false,
|
12797 | mobileScrollSupport: true,
|
12798 | swipeDistance: 30,
|
12799 | clickEventForward: true,
|
12800 | useMouseEvents: true,
|
12801 | showPageCorners: true,
|
12802 | disableFlipByClick: false
|
12803 | };
|
12804 | }
|
12805 | getSettings(userSetting) {
|
12806 | const result = this._default;
|
12807 | Object.assign(result, userSetting);
|
12808 | if (result.size !== "stretch" && result.size !== "fixed") throw new Error('Invalid size type. Available only "fixed" and "stretch" value');
|
12809 | if (result.width <= 0 || result.height <= 0) throw new Error('Invalid width or height');
|
12810 | if (result.flippingTime <= 0) throw new Error('Invalid flipping time');
|
12811 | if (result.size === "stretch") {
|
12812 | if (result.minWidth <= 0) result.minWidth = 100;
|
12813 | if (result.maxWidth < result.minWidth) result.maxWidth = 2000;
|
12814 | if (result.minHeight <= 0) result.minHeight = 100;
|
12815 | if (result.maxHeight < result.minHeight) result.maxHeight = 2000;
|
12816 | } else {
|
12817 | result.minWidth = result.width;
|
12818 | result.maxWidth = result.width;
|
12819 | result.minHeight = result.height;
|
12820 | result.maxHeight = result.height;
|
12821 | }
|
12822 | return result;
|
12823 | }
|
12824 | }
|
12825 | function styleInject(css, ref) {
|
12826 | if (ref === void 0) ref = {};
|
12827 | var insertAt = ref.insertAt;
|
12828 | if (!css || typeof document === 'undefined') {
|
12829 | return;
|
12830 | }
|
12831 | var head = document.head || document.getElementsByTagName('head')[0];
|
12832 | var style = document.createElement('style');
|
12833 | style.type = 'text/css';
|
12834 | if (insertAt === 'top') {
|
12835 | if (head.firstChild) {
|
12836 | head.insertBefore(style, head.firstChild);
|
12837 | } else {
|
12838 | head.appendChild(style);
|
12839 | }
|
12840 | } else {
|
12841 | head.appendChild(style);
|
12842 | }
|
12843 | if (style.styleSheet) {
|
12844 | style.styleSheet.cssText = css;
|
12845 | } else {
|
12846 | style.appendChild(document.createTextNode(css));
|
12847 | }
|
12848 | }
|
12849 | var css_248z = ".stf__parent {\n position: relative;\n display: block;\n box-sizing: border-box;\n transform: translateZ(0);\n\n -ms-touch-action: pan-y;\n touch-action: pan-y;\n}\n\n.sft__wrapper {\n position: relative;\n width: 100%;\n box-sizing: border-box;\n}\n\n.stf__parent canvas {\n position: absolute;\n width: 100%;\n height: 100%;\n left: 0;\n top: 0;\n}\n\n.stf__block {\n position: absolute;\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n perspective: 2000px;\n}\n\n.stf__item {\n display: none;\n position: absolute;\n transform-style: preserve-3d;\n}\n\n.stf__outerShadow {\n position: absolute;\n left: 0;\n top: 0;\n}\n\n.stf__innerShadow {\n position: absolute;\n left: 0;\n top: 0;\n}\n\n.stf__hardShadow {\n position: absolute;\n left: 0;\n top: 0;\n}\n\n.stf__hardInnerShadow {\n position: absolute;\n left: 0;\n top: 0;\n}";
|
12850 | styleInject(css_248z);
|
12851 | class PageFlip extends EventObject {
|
12852 | constructor(inBlock, setting) {
|
12853 | super();
|
12854 | this.isUserTouch = false;
|
12855 | this.isUserMove = false;
|
12856 | this.setting = null;
|
12857 | this.pages = null;
|
12858 | this.setting = new Settings().getSettings(setting);
|
12859 | this.block = inBlock;
|
12860 | }
|
12861 | destroy() {
|
12862 | this.ui.destroy();
|
12863 | this.block.remove();
|
12864 | }
|
12865 | update() {
|
12866 | this.render.update();
|
12867 | this.pages.show();
|
12868 | }
|
12869 | loadFromImages(imagesHref) {
|
12870 | this.ui = new CanvasUI(this.block, this, this.setting);
|
12871 | const canvas = this.ui.getCanvas();
|
12872 | this.render = new CanvasRender(this, this.setting, canvas);
|
12873 | this.flipController = new Flip(this.render, this);
|
12874 | this.pages = new ImagePageCollection(this, this.render, imagesHref);
|
12875 | this.pages.load();
|
12876 | this.render.start();
|
12877 | this.pages.show(this.setting.startPage);
|
12878 | setTimeout(() => {
|
12879 | this.ui.update();
|
12880 | this.trigger('init', this, {
|
12881 | page: this.setting.startPage,
|
12882 | mode: this.render.getOrientation()
|
12883 | });
|
12884 | }, 1);
|
12885 | }
|
12886 | loadFromHTML(items) {
|
12887 | this.ui = new HTMLUI(this.block, this, this.setting, items);
|
12888 | this.render = new HTMLRender(this, this.setting, this.ui.getDistElement());
|
12889 | this.flipController = new Flip(this.render, this);
|
12890 | this.pages = new HTMLPageCollection(this, this.render, this.ui.getDistElement(), items);
|
12891 | this.pages.load();
|
12892 | this.render.start();
|
12893 | this.pages.show(this.setting.startPage);
|
12894 | setTimeout(() => {
|
12895 | this.ui.update();
|
12896 | this.trigger('init', this, {
|
12897 | page: this.setting.startPage,
|
12898 | mode: this.render.getOrientation()
|
12899 | });
|
12900 | }, 1);
|
12901 | }
|
12902 | updateFromImages(imagesHref) {
|
12903 | const current = this.pages.getCurrentPageIndex();
|
12904 | this.pages.destroy();
|
12905 | this.pages = new ImagePageCollection(this, this.render, imagesHref);
|
12906 | this.pages.load();
|
12907 | this.pages.show(current);
|
12908 | this.trigger('update', this, {
|
12909 | page: current,
|
12910 | mode: this.render.getOrientation()
|
12911 | });
|
12912 | }
|
12913 | updateFromHtml(items) {
|
12914 | const current = this.pages.getCurrentPageIndex();
|
12915 | this.pages.destroy();
|
12916 | this.pages = new HTMLPageCollection(this, this.render, this.ui.getDistElement(), items);
|
12917 | this.pages.load();
|
12918 | this.ui.updateItems(items);
|
12919 | this.render.reload();
|
12920 | this.pages.show(current);
|
12921 | this.trigger('update', this, {
|
12922 | page: current,
|
12923 | mode: this.render.getOrientation()
|
12924 | });
|
12925 | }
|
12926 | clear() {
|
12927 | this.pages.destroy();
|
12928 | this.ui.clear();
|
12929 | }
|
12930 | turnToPrevPage() {
|
12931 | this.pages.showPrev();
|
12932 | }
|
12933 | turnToNextPage() {
|
12934 | this.pages.showNext();
|
12935 | }
|
12936 | turnToPage(page) {
|
12937 | this.pages.show(page);
|
12938 | }
|
12939 | flipNext(corner = "top") {
|
12940 | this.flipController.flipNext(corner);
|
12941 | }
|
12942 | flipPrev(corner = "top") {
|
12943 | this.flipController.flipPrev(corner);
|
12944 | }
|
12945 | flip(page, corner = "top") {
|
12946 | this.flipController.flipToPage(page, corner);
|
12947 | }
|
12948 | updateState(newState) {
|
12949 | this.trigger('changeState', this, newState);
|
12950 | }
|
12951 | updatePageIndex(newPage) {
|
12952 | this.trigger('flip', this, newPage);
|
12953 | }
|
12954 | updateOrientation(newOrientation) {
|
12955 | this.ui.setOrientationStyle(newOrientation);
|
12956 | this.update();
|
12957 | this.trigger('changeOrientation', this, newOrientation);
|
12958 | }
|
12959 | getPageCount() {
|
12960 | return this.pages.getPageCount();
|
12961 | }
|
12962 | getCurrentPageIndex() {
|
12963 | return this.pages.getCurrentPageIndex();
|
12964 | }
|
12965 | getPage(pageIndex) {
|
12966 | return this.pages.getPage(pageIndex);
|
12967 | }
|
12968 | getRender() {
|
12969 | return this.render;
|
12970 | }
|
12971 | getFlipController() {
|
12972 | return this.flipController;
|
12973 | }
|
12974 | getOrientation() {
|
12975 | return this.render.getOrientation();
|
12976 | }
|
12977 | getBoundsRect() {
|
12978 | return this.render.getRect();
|
12979 | }
|
12980 | getSettings() {
|
12981 | return this.setting;
|
12982 | }
|
12983 | getUI() {
|
12984 | return this.ui;
|
12985 | }
|
12986 | getState() {
|
12987 | return this.flipController.getState();
|
12988 | }
|
12989 | getPageCollection() {
|
12990 | return this.pages;
|
12991 | }
|
12992 | startUserTouch(pos) {
|
12993 | this.mousePosition = pos;
|
12994 | this.isUserTouch = true;
|
12995 | this.isUserMove = false;
|
12996 | }
|
12997 | userMove(pos, isTouch) {
|
12998 | if (!this.isUserTouch && !isTouch && this.setting.showPageCorners) {
|
12999 | this.flipController.showCorner(pos);
|
13000 | } else if (this.isUserTouch) {
|
13001 | if (Helper.GetDistanceBetweenTwoPoint(this.mousePosition, pos) > 5) {
|
13002 | this.isUserMove = true;
|
13003 | this.flipController.fold(pos);
|
13004 | }
|
13005 | }
|
13006 | }
|
13007 | userStop(pos, isSwipe = false) {
|
13008 | if (this.isUserTouch) {
|
13009 | this.isUserTouch = false;
|
13010 | if (!isSwipe) {
|
13011 | if (!this.isUserMove) this.flipController.flip(pos);else this.flipController.stopMove();
|
13012 | }
|
13013 | }
|
13014 | }
|
13015 | }
|
13016 | exports.PageFlip = PageFlip;
|
13017 |
|
13018 | /***/ }),
|
13019 | /* 34 */
|
13020 | /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
13021 |
|
13022 |
|
13023 |
|
13024 | Object.defineProperty(exports, "__esModule", ({
|
13025 | value: true
|
13026 | }));
|
13027 | exports.PDFPageView = void 0;
|
13028 | var _pdfjsLib = __webpack_require__(4);
|
13029 | var _ui_utils = __webpack_require__(3);
|
13030 | var _annotation_editor_layer_builder = __webpack_require__(35);
|
13031 | var _annotation_layer_builder = __webpack_require__(36);
|
13032 | var _app_options = __webpack_require__(5);
|
13033 | var _l10n_utils = __webpack_require__(32);
|
13034 | var _pdf_link_service = __webpack_require__(7);
|
13035 | var _struct_tree_layer_builder = __webpack_require__(37);
|
13036 | var _text_accessibility = __webpack_require__(38);
|
13037 | var _canvasSize = _interopRequireDefault(__webpack_require__(39));
|
13038 | var _util = __webpack_require__(40);
|
13039 | var _text_highlighter = __webpack_require__(41);
|
13040 | var _text_layer_builder = __webpack_require__(42);
|
13041 | var _xfa_layer_builder = __webpack_require__(43);
|
13042 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13043 | const MAX_CANVAS_PIXELS = _app_options.compatibilityParams.maxCanvasPixels || 16777216;
|
13044 | const DEFAULT_LAYER_PROPERTIES = () => {
|
13045 | return null;
|
13046 | };
|
13047 | class PDFPageView {
|
13048 | #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
|
13049 | #layerProperties = null;
|
13050 | #loadingId = null;
|
13051 | #previousRotation = null;
|
13052 | #renderingState = _ui_utils.RenderingStates.INITIAL;
|
13053 | #useThumbnailCanvas = {
|
13054 | initialOptionalContent: true,
|
13055 | regularAnnotations: true
|
13056 | };
|
13057 | constructor(options) {
|
13058 | const container = options.container;
|
13059 | const defaultViewport = options.defaultViewport;
|
13060 | this.id = options.id;
|
13061 | this.renderingId = "page" + this.id;
|
13062 | this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES;
|
13063 | this.pdfPage = null;
|
13064 | this.pageLabel = null;
|
13065 | this.rotation = 0;
|
13066 | this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
|
13067 | this.viewport = defaultViewport;
|
13068 | this.pdfPageRotate = defaultViewport.rotation;
|
13069 | this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
|
13070 | this.hasRestrictedScaling = false;
|
13071 | this.textLayerMode = options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
|
13072 | this.#annotationMode = options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
|
13073 | this.imageResourcesPath = options.imageResourcesPath || "";
|
13074 | this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
13075 | this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
|
13076 | this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
|
13077 | this.pageColors = options.pageColors || null;
|
13078 | this.eventBus = options.eventBus;
|
13079 | this.renderingQueue = options.renderingQueue;
|
13080 | this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
|
13081 | this.l10n = options.l10n || _l10n_utils.NullL10n;
|
13082 | this.paintTask = null;
|
13083 | this.paintedViewportMap = new WeakMap();
|
13084 | this.resume = null;
|
13085 | this._renderError = null;
|
13086 | this._isStandalone = !this.renderingQueue?.hasViewer();
|
13087 | this._annotationCanvasMap = null;
|
13088 | this.annotationLayer = null;
|
13089 | this.annotationEditorLayer = null;
|
13090 | this.textLayer = null;
|
13091 | this.zoomLayer = null;
|
13092 | this.xfaLayer = null;
|
13093 | this.structTreeLayer = null;
|
13094 | const div = document.createElement("div");
|
13095 | div.className = "page";
|
13096 | div.setAttribute("data-page-number", this.id);
|
13097 | div.setAttribute("role", "region");
|
13098 | this.l10n.get("page_landmark", {
|
13099 | page: this.id
|
13100 | }).then(msg => {
|
13101 | div.setAttribute("aria-label", msg);
|
13102 | });
|
13103 | this.div = div;
|
13104 | this.#setDimensions();
|
13105 | container?.append(div);
|
13106 | if (this._isStandalone) {
|
13107 | container?.style.setProperty("--scale-factor", this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS);
|
13108 | const {
|
13109 | optionalContentConfigPromise
|
13110 | } = options;
|
13111 | if (optionalContentConfigPromise) {
|
13112 | optionalContentConfigPromise.then(optionalContentConfig => {
|
13113 | if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
|
13114 | return;
|
13115 | }
|
13116 | this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
|
13117 | });
|
13118 | }
|
13119 | }
|
13120 | }
|
13121 | get renderingState() {
|
13122 | return this.#renderingState;
|
13123 | }
|
13124 | set renderingState(state) {
|
13125 | if (state === this.#renderingState) {
|
13126 | return;
|
13127 | }
|
13128 | this.#renderingState = state;
|
13129 | if (this.#loadingId) {
|
13130 | clearTimeout(this.#loadingId);
|
13131 | this.#loadingId = null;
|
13132 | }
|
13133 | switch (state) {
|
13134 | case _ui_utils.RenderingStates.PAUSED:
|
13135 | this.div.classList.remove("loading");
|
13136 | break;
|
13137 | case _ui_utils.RenderingStates.RUNNING:
|
13138 | this.div.classList.add("loadingIcon");
|
13139 | this.#loadingId = setTimeout(() => {
|
13140 | this.div.classList.add("loading");
|
13141 | this.#loadingId = null;
|
13142 | }, 0);
|
13143 | break;
|
13144 | case _ui_utils.RenderingStates.INITIAL:
|
13145 | case _ui_utils.RenderingStates.FINISHED:
|
13146 | this.div.classList.remove("loadingIcon", "loading");
|
13147 | break;
|
13148 | }
|
13149 | }
|
13150 | #setDimensions() {
|
13151 | const {
|
13152 | viewport
|
13153 | } = this;
|
13154 | if (this.pdfPage) {
|
13155 | if (this.#previousRotation === viewport.rotation) {
|
13156 | return;
|
13157 | }
|
13158 | this.#previousRotation = viewport.rotation;
|
13159 | }
|
13160 | (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
|
13161 | }
|
13162 | setPdfPage(pdfPage) {
|
13163 | this.pdfPage = pdfPage;
|
13164 | this.pdfPageRotate = pdfPage.rotate;
|
13165 | const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
13166 | this.viewport = pdfPage.getViewport({
|
13167 | scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
|
13168 | rotation: totalRotation
|
13169 | });
|
13170 | this.#setDimensions();
|
13171 | this.reset();
|
13172 | }
|
13173 | destroy() {
|
13174 | this.reset();
|
13175 | this.pdfPage?.cleanup();
|
13176 | }
|
13177 | get _textHighlighter() {
|
13178 | return (0, _pdfjsLib.shadow)(this, "_textHighlighter", new _text_highlighter.TextHighlighter({
|
13179 | pageIndex: this.id - 1,
|
13180 | eventBus: this.eventBus,
|
13181 | findController: this.#layerProperties().findController
|
13182 | }));
|
13183 | }
|
13184 | async #renderAnnotationLayer() {
|
13185 | let error = null;
|
13186 | try {
|
13187 | await this.annotationLayer.render(this.viewport, "display");
|
13188 | } catch (ex) {
|
13189 | console.error(`#renderAnnotationLayer: "${ex}".`);
|
13190 | error = ex;
|
13191 | } finally {
|
13192 | this.eventBus.dispatch("annotationlayerrendered", {
|
13193 | source: this,
|
13194 | pageNumber: this.id,
|
13195 | error
|
13196 | });
|
13197 | }
|
13198 | }
|
13199 | async #renderAnnotationEditorLayer() {
|
13200 | let error = null;
|
13201 | try {
|
13202 | await this.annotationEditorLayer.render(this.viewport, "display");
|
13203 | } catch (ex) {
|
13204 | console.error(`#renderAnnotationEditorLayer: "${ex}".`);
|
13205 | error = ex;
|
13206 | } finally {
|
13207 | this.eventBus.dispatch("annotationeditorlayerrendered", {
|
13208 | source: this,
|
13209 | pageNumber: this.id,
|
13210 | error
|
13211 | });
|
13212 | }
|
13213 | }
|
13214 | async #renderXfaLayer() {
|
13215 | let error = null;
|
13216 | try {
|
13217 | const result = await this.xfaLayer.render(this.viewport, "display");
|
13218 | if (result?.textDivs && this._textHighlighter) {
|
13219 | this.#buildXfaTextContentItems(result.textDivs);
|
13220 | }
|
13221 | } catch (ex) {
|
13222 | console.error(`#renderXfaLayer: "${ex}".`);
|
13223 | error = ex;
|
13224 | } finally {
|
13225 | this.eventBus.dispatch("xfalayerrendered", {
|
13226 | source: this,
|
13227 | pageNumber: this.id,
|
13228 | error
|
13229 | });
|
13230 | }
|
13231 | }
|
13232 | async #renderTextLayer() {
|
13233 | const {
|
13234 | pdfPage,
|
13235 | textLayer,
|
13236 | viewport
|
13237 | } = this;
|
13238 | if (!textLayer) {
|
13239 | return;
|
13240 | }
|
13241 | let error = null;
|
13242 | try {
|
13243 | if (!textLayer.renderingDone) {
|
13244 | const readableStream = pdfPage.streamTextContent({
|
13245 | includeMarkedContent: true
|
13246 | });
|
13247 | textLayer.setTextContentSource(readableStream);
|
13248 | }
|
13249 | await textLayer.render(viewport);
|
13250 | } catch (ex) {
|
13251 | if (ex instanceof _pdfjsLib.AbortException) {
|
13252 | return;
|
13253 | }
|
13254 | console.error(`#renderTextLayer: "${ex}".`);
|
13255 | error = ex;
|
13256 | }
|
13257 | this.eventBus.dispatch("textlayerrendered", {
|
13258 | source: this,
|
13259 | pageNumber: this.id,
|
13260 | numTextDivs: textLayer.numTextDivs,
|
13261 | error
|
13262 | });
|
13263 | this.#renderStructTreeLayer();
|
13264 | }
|
13265 | async #renderStructTreeLayer() {
|
13266 | if (!this.textLayer) {
|
13267 | return;
|
13268 | }
|
13269 | this.structTreeLayer ||= new _struct_tree_layer_builder.StructTreeLayerBuilder();
|
13270 | const tree = await (!this.structTreeLayer.renderingDone ? this.pdfPage.getStructTree() : null);
|
13271 | const treeDom = this.structTreeLayer?.render(tree);
|
13272 | if (treeDom) {
|
13273 | this.canvas?.append(treeDom);
|
13274 | }
|
13275 | this.structTreeLayer?.show();
|
13276 | }
|
13277 | async #buildXfaTextContentItems(textDivs) {
|
13278 | const text = await this.pdfPage.getTextContent();
|
13279 | const items = [];
|
13280 | for (const item of text.items) {
|
13281 | items.push(item.str);
|
13282 | }
|
13283 | this._textHighlighter.setTextMapping(textDivs, items);
|
13284 | this._textHighlighter.enable();
|
13285 | }
|
13286 | _resetZoomLayer(removeFromDOM = false) {
|
13287 | if (!this.zoomLayer) {
|
13288 | return;
|
13289 | }
|
13290 | const zoomLayerCanvas = this.zoomLayer.firstChild;
|
13291 | this.paintedViewportMap.delete(zoomLayerCanvas);
|
13292 | zoomLayerCanvas.width = 0;
|
13293 | zoomLayerCanvas.height = 0;
|
13294 | if (removeFromDOM) {
|
13295 | this.zoomLayer.remove();
|
13296 | }
|
13297 | this.zoomLayer = null;
|
13298 | }
|
13299 | reset({
|
13300 | keepZoomLayer = false,
|
13301 | keepAnnotationLayer = false,
|
13302 | keepAnnotationEditorLayer = false,
|
13303 | keepXfaLayer = false,
|
13304 | keepTextLayer = false
|
13305 | } = {}) {
|
13306 | this.cancelRendering({
|
13307 | keepAnnotationLayer,
|
13308 | keepAnnotationEditorLayer,
|
13309 | keepXfaLayer,
|
13310 | keepTextLayer
|
13311 | });
|
13312 | this.renderingState = _ui_utils.RenderingStates.INITIAL;
|
13313 | const div = this.div;
|
13314 | const childNodes = div.childNodes,
|
13315 | zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
|
13316 | annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
|
13317 | annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null,
|
13318 | xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null,
|
13319 | textLayerNode = keepTextLayer && this.textLayer?.div || null;
|
13320 | for (let i = childNodes.length - 1; i >= 0; i--) {
|
13321 | const node = childNodes[i];
|
13322 | switch (node) {
|
13323 | case zoomLayerNode:
|
13324 | case annotationLayerNode:
|
13325 | case annotationEditorLayerNode:
|
13326 | case xfaLayerNode:
|
13327 | case textLayerNode:
|
13328 | continue;
|
13329 | }
|
13330 | node.remove();
|
13331 | }
|
13332 | div.removeAttribute("data-loaded");
|
13333 | if (annotationLayerNode) {
|
13334 | this.annotationLayer.hide();
|
13335 | }
|
13336 | if (annotationEditorLayerNode) {
|
13337 | this.annotationEditorLayer.hide();
|
13338 | }
|
13339 | if (xfaLayerNode) {
|
13340 | this.xfaLayer.hide();
|
13341 | }
|
13342 | if (textLayerNode) {
|
13343 | this.textLayer.hide();
|
13344 | }
|
13345 | this.structTreeLayer?.hide();
|
13346 | if (!zoomLayerNode) {
|
13347 | if (this.canvas) {
|
13348 | this.paintedViewportMap.delete(this.canvas);
|
13349 | this.canvas.width = 0;
|
13350 | this.canvas.height = 0;
|
13351 | delete this.canvas;
|
13352 | }
|
13353 | this._resetZoomLayer();
|
13354 | }
|
13355 | if (this.svg) {
|
13356 | this.paintedViewportMap.delete(this.svg);
|
13357 | delete this.svg;
|
13358 | }
|
13359 | }
|
13360 | update({
|
13361 | scale = 0,
|
13362 | rotation = null,
|
13363 | optionalContentConfigPromise = null,
|
13364 | drawingDelay = -1
|
13365 | }) {
|
13366 | this.scale = scale || this.scale;
|
13367 | if (typeof rotation === "number") {
|
13368 | this.rotation = rotation;
|
13369 | }
|
13370 | if (optionalContentConfigPromise instanceof Promise) {
|
13371 | this._optionalContentConfigPromise = optionalContentConfigPromise;
|
13372 | optionalContentConfigPromise.then(optionalContentConfig => {
|
13373 | if (optionalContentConfigPromise !== this._optionalContentConfigPromise) {
|
13374 | return;
|
13375 | }
|
13376 | this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility;
|
13377 | });
|
13378 | }
|
13379 | const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
13380 | this.viewport = this.viewport.clone({
|
13381 | scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
|
13382 | rotation: totalRotation
|
13383 | });
|
13384 | this.#setDimensions();
|
13385 | if (this._isStandalone) {
|
13386 | this.div.parentNode?.style.setProperty("--scale-factor", this.viewport.scale);
|
13387 | }
|
13388 | if (this.svg) {
|
13389 | this.cssTransform({
|
13390 | target: this.svg,
|
13391 | redrawAnnotationLayer: true,
|
13392 | redrawAnnotationEditorLayer: true,
|
13393 | redrawXfaLayer: true,
|
13394 | redrawTextLayer: true
|
13395 | });
|
13396 | this.eventBus.dispatch("pagerendered", {
|
13397 | source: this,
|
13398 | pageNumber: this.id,
|
13399 | cssTransform: true,
|
13400 | timestamp: performance.now(),
|
13401 | error: this._renderError
|
13402 | });
|
13403 | return;
|
13404 | }
|
13405 | let isScalingRestricted = false;
|
13406 | if (this.canvas && this.maxCanvasPixels > 0) {
|
13407 | const outputScale = this.outputScale;
|
13408 | if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
|
13409 | isScalingRestricted = true;
|
13410 | }
|
13411 | }
|
13412 | const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
|
13413 | if (this.canvas) {
|
13414 | if (postponeDrawing || this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
|
13415 | if (postponeDrawing && this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
|
13416 | this.cancelRendering({
|
13417 | keepZoomLayer: true,
|
13418 | keepAnnotationLayer: true,
|
13419 | keepAnnotationEditorLayer: true,
|
13420 | keepXfaLayer: true,
|
13421 | keepTextLayer: true,
|
13422 | cancelExtraDelay: drawingDelay
|
13423 | });
|
13424 | this.renderingState = _ui_utils.RenderingStates.FINISHED;
|
13425 | }
|
13426 | this.cssTransform({
|
13427 | target: this.canvas,
|
13428 | redrawAnnotationLayer: true,
|
13429 | redrawAnnotationEditorLayer: true,
|
13430 | redrawXfaLayer: true,
|
13431 | redrawTextLayer: !postponeDrawing,
|
13432 | hideTextLayer: postponeDrawing
|
13433 | });
|
13434 | this.eventBus.dispatch("pagerendered", {
|
13435 | source: this,
|
13436 | pageNumber: this.id,
|
13437 | cssTransform: true,
|
13438 | timestamp: performance.now(),
|
13439 | error: this._renderError
|
13440 | });
|
13441 | return;
|
13442 | }
|
13443 | if (!this.zoomLayer && !this.canvas.hidden) {
|
13444 | this.zoomLayer = this.canvas.parentNode;
|
13445 | this.zoomLayer.style.position = "absolute";
|
13446 | }
|
13447 | }
|
13448 | if (this.zoomLayer) {
|
13449 | this.cssTransform({
|
13450 | target: this.zoomLayer.firstChild
|
13451 | });
|
13452 | }
|
13453 | this.reset({
|
13454 | keepZoomLayer: true,
|
13455 | keepAnnotationLayer: true,
|
13456 | keepAnnotationEditorLayer: true,
|
13457 | keepXfaLayer: true,
|
13458 | keepTextLayer: true
|
13459 | });
|
13460 | }
|
13461 | cancelRendering({
|
13462 | keepAnnotationLayer = false,
|
13463 | keepAnnotationEditorLayer = false,
|
13464 | keepXfaLayer = false,
|
13465 | keepTextLayer = false,
|
13466 | cancelExtraDelay = 0
|
13467 | } = {}) {
|
13468 | if (this.paintTask) {
|
13469 | this.paintTask.cancel(cancelExtraDelay);
|
13470 | this.paintTask = null;
|
13471 | }
|
13472 | this.resume = null;
|
13473 | if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
|
13474 | this.textLayer.cancel();
|
13475 | this.textLayer = null;
|
13476 | }
|
13477 | if (this.structTreeLayer && !this.textLayer) {
|
13478 | this.structTreeLayer = null;
|
13479 | }
|
13480 | if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
|
13481 | this.annotationLayer.cancel();
|
13482 | this.annotationLayer = null;
|
13483 | this._annotationCanvasMap = null;
|
13484 | }
|
13485 | if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) {
|
13486 | this.annotationEditorLayer.cancel();
|
13487 | this.annotationEditorLayer = null;
|
13488 | }
|
13489 | if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
|
13490 | this.xfaLayer.cancel();
|
13491 | this.xfaLayer = null;
|
13492 | this._textHighlighter?.disable();
|
13493 | }
|
13494 | }
|
13495 | cssTransform({
|
13496 | target,
|
13497 | redrawAnnotationLayer = false,
|
13498 | redrawAnnotationEditorLayer = false,
|
13499 | redrawXfaLayer = false,
|
13500 | redrawTextLayer = false,
|
13501 | hideTextLayer = false
|
13502 | }) {
|
13503 | if (target instanceof HTMLCanvasElement) {
|
13504 | if (!target.hasAttribute("zooming")) {
|
13505 | target.setAttribute("zooming", true);
|
13506 | const {
|
13507 | style
|
13508 | } = target;
|
13509 | style.width = style.height = "";
|
13510 | }
|
13511 | } else {
|
13512 | const div = this.div;
|
13513 | const {
|
13514 | width,
|
13515 | height
|
13516 | } = this.viewport;
|
13517 | target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
|
13518 | target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
|
13519 | }
|
13520 | const originalViewport = this.paintedViewportMap.get(target);
|
13521 | if (this.viewport !== originalViewport) {
|
13522 | const relativeRotation = this.viewport.rotation - originalViewport.rotation;
|
13523 | const absRotation = Math.abs(relativeRotation);
|
13524 | let scaleX = 1,
|
13525 | scaleY = 1;
|
13526 | if (absRotation === 90 || absRotation === 270) {
|
13527 | const {
|
13528 | width,
|
13529 | height
|
13530 | } = this.viewport;
|
13531 | scaleX = height / width;
|
13532 | scaleY = width / height;
|
13533 | }
|
13534 | if (absRotation !== 0) {
|
13535 | target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
|
13536 | }
|
13537 | }
|
13538 | if (redrawAnnotationLayer && this.annotationLayer) {
|
13539 | this.#renderAnnotationLayer();
|
13540 | }
|
13541 | if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
|
13542 | this.#renderAnnotationEditorLayer();
|
13543 | }
|
13544 | if (redrawXfaLayer && this.xfaLayer) {
|
13545 | this.#renderXfaLayer();
|
13546 | }
|
13547 | if (this.textLayer) {
|
13548 | if (hideTextLayer) {
|
13549 | this.textLayer.hide();
|
13550 | this.structTreeLayer?.hide();
|
13551 | } else if (redrawTextLayer) {
|
13552 | this.#renderTextLayer();
|
13553 | }
|
13554 | }
|
13555 | }
|
13556 | get width() {
|
13557 | return this.viewport.width;
|
13558 | }
|
13559 | get height() {
|
13560 | return this.viewport.height;
|
13561 | }
|
13562 | getPagePoint(x, y) {
|
13563 | return this.viewport.convertToPdfPoint(x, y);
|
13564 | }
|
13565 | draw() {
|
13566 | if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
|
13567 | Window['ngxConsole'].error("Must be in new state before drawing");
|
13568 | this.reset();
|
13569 | }
|
13570 | const {
|
13571 | div,
|
13572 | pdfPage
|
13573 | } = this;
|
13574 | if (!pdfPage) {
|
13575 | this.renderingState = _ui_utils.RenderingStates.FINISHED;
|
13576 | return Promise.reject(new Error("pdfPage is not loaded"));
|
13577 | }
|
13578 | this.renderingState = _ui_utils.RenderingStates.RUNNING;
|
13579 | const canvasWrapper = document.createElement("div");
|
13580 | canvasWrapper.classList.add("canvasWrapper");
|
13581 | div.append(canvasWrapper);
|
13582 | if (!this.textLayer && this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
|
13583 | this._accessibilityManager ||= new _text_accessibility.TextAccessibilityManager();
|
13584 | this.textLayer = new _text_layer_builder.TextLayerBuilder({
|
13585 | highlighter: this._textHighlighter,
|
13586 | accessibilityManager: this._accessibilityManager,
|
13587 | isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
|
13588 | });
|
13589 | div.append(this.textLayer.div);
|
13590 | }
|
13591 | if (!this.annotationLayer && this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE) {
|
13592 | const {
|
13593 | annotationStorage,
|
13594 | downloadManager,
|
13595 | enableScripting,
|
13596 | fieldObjectsPromise,
|
13597 | hasJSActionsPromise,
|
13598 | linkService
|
13599 | } = this.#layerProperties();
|
13600 | this._annotationCanvasMap ||= new Map();
|
13601 | this.annotationLayer = new _annotation_layer_builder.AnnotationLayerBuilder({
|
13602 | pageDiv: div,
|
13603 | pdfPage,
|
13604 | annotationStorage,
|
13605 | imageResourcesPath: this.imageResourcesPath,
|
13606 | renderForms: this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS,
|
13607 | linkService,
|
13608 | downloadManager,
|
13609 | l10n: this.l10n,
|
13610 | enableScripting,
|
13611 | hasJSActionsPromise,
|
13612 | fieldObjectsPromise,
|
13613 | annotationCanvasMap: this._annotationCanvasMap,
|
13614 | accessibilityManager: this._accessibilityManager
|
13615 | });
|
13616 | }
|
13617 | let renderContinueCallback = null;
|
13618 | if (this.renderingQueue) {
|
13619 | renderContinueCallback = cont => {
|
13620 | if (!this.renderingQueue.isHighestPriority(this)) {
|
13621 | this.renderingState = _ui_utils.RenderingStates.PAUSED;
|
13622 | this.resume = () => {
|
13623 | this.renderingState = _ui_utils.RenderingStates.RUNNING;
|
13624 | cont();
|
13625 | };
|
13626 | return;
|
13627 | }
|
13628 | cont();
|
13629 | };
|
13630 | }
|
13631 | const finishPaintTask = async (error = null) => {
|
13632 | if (paintTask === this.paintTask) {
|
13633 | this.paintTask = null;
|
13634 | }
|
13635 | if (error instanceof _pdfjsLib.RenderingCancelledException) {
|
13636 | this._renderError = null;
|
13637 | return;
|
13638 | }
|
13639 | this._renderError = error;
|
13640 | this.renderingState = _ui_utils.RenderingStates.FINISHED;
|
13641 | this._resetZoomLayer(true);
|
13642 | this.#useThumbnailCanvas.regularAnnotations = !paintTask.separateAnnots;
|
13643 | this.eventBus.dispatch("pagerendered", {
|
13644 | source: this,
|
13645 | pageNumber: this.id,
|
13646 | cssTransform: false,
|
13647 | timestamp: performance.now(),
|
13648 | error: this._renderError
|
13649 | });
|
13650 | if (error) {
|
13651 | throw error;
|
13652 | }
|
13653 | };
|
13654 | const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
|
13655 | paintTask.onRenderContinue = renderContinueCallback;
|
13656 | this.paintTask = paintTask;
|
13657 | const resultPromise = paintTask.promise.then(() => {
|
13658 | return finishPaintTask(null).then(async () => {
|
13659 | this.#renderTextLayer();
|
13660 | if (this.annotationLayer) {
|
13661 | await this.#renderAnnotationLayer();
|
13662 | }
|
13663 | if (!this.annotationEditorLayer) {
|
13664 | const {
|
13665 | annotationEditorUIManager
|
13666 | } = this.#layerProperties();
|
13667 | if (!annotationEditorUIManager) {
|
13668 | return;
|
13669 | }
|
13670 | this.annotationEditorLayer = new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder({
|
13671 | uiManager: annotationEditorUIManager,
|
13672 | pageDiv: div,
|
13673 | pdfPage,
|
13674 | l10n: this.l10n,
|
13675 | accessibilityManager: this._accessibilityManager
|
13676 | });
|
13677 | }
|
13678 | this.#renderAnnotationEditorLayer();
|
13679 | });
|
13680 | }, function (reason) {
|
13681 | return finishPaintTask(reason);
|
13682 | });
|
13683 | if (pdfPage.isPureXfa) {
|
13684 | if (!this.xfaLayer) {
|
13685 | const {
|
13686 | annotationStorage,
|
13687 | linkService
|
13688 | } = this.#layerProperties();
|
13689 | this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
|
13690 | pageDiv: div,
|
13691 | pdfPage,
|
13692 | annotationStorage,
|
13693 | linkService
|
13694 | });
|
13695 | } else if (this.xfaLayer.div) {
|
13696 | div.append(this.xfaLayer.div);
|
13697 | }
|
13698 | this.#renderXfaLayer();
|
13699 | }
|
13700 | div.setAttribute("data-loaded", true);
|
13701 | this.eventBus.dispatch("pagerender", {
|
13702 | source: this,
|
13703 | pageNumber: this.id
|
13704 | });
|
13705 | return resultPromise;
|
13706 | }
|
13707 | paintOnCanvas(canvasWrapper) {
|
13708 | const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
|
13709 | const result = {
|
13710 | promise: renderCapability.promise,
|
13711 | onRenderContinue(cont) {
|
13712 | cont();
|
13713 | },
|
13714 | cancel(extraDelay = 0) {
|
13715 | renderTask.cancel(extraDelay);
|
13716 | },
|
13717 | get separateAnnots() {
|
13718 | return renderTask.separateAnnots;
|
13719 | }
|
13720 | };
|
13721 | const viewport = this.viewport;
|
13722 | let {
|
13723 | width,
|
13724 | height
|
13725 | } = viewport;
|
13726 | const canvas = document.createElement("canvas");
|
13727 | canvas.setAttribute("role", "presentation");
|
13728 | canvas.hidden = true;
|
13729 | let isCanvasHidden = true;
|
13730 | const showCanvas = function () {
|
13731 | if (isCanvasHidden) {
|
13732 | canvas.hidden = false;
|
13733 | isCanvasHidden = false;
|
13734 | }
|
13735 | };
|
13736 | canvasWrapper.append(canvas);
|
13737 | this.canvas = canvas;
|
13738 | const options = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {
|
13739 | willReadFrequently: true,
|
13740 | alpha: false
|
13741 | } : {
|
13742 | alpha: false
|
13743 | };
|
13744 | const ctx = canvas.getContext("2d", options);
|
13745 | const outputScale = this.outputScale = new _ui_utils.OutputScale();
|
13746 | if (this.useOnlyCssZoom) {
|
13747 | const actualSizeViewport = viewport.clone({
|
13748 | scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
|
13749 | });
|
13750 | outputScale.sx *= actualSizeViewport.width / width;
|
13751 | outputScale.sy *= actualSizeViewport.height / height;
|
13752 | }
|
13753 | if (this.maxCanvasPixels > 0) {
|
13754 | const pixelsInViewport = width * height;
|
13755 | const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
|
13756 | if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
|
13757 | outputScale.sx = maxScale;
|
13758 | outputScale.sy = maxScale;
|
13759 | this.hasRestrictedScaling = true;
|
13760 | } else {
|
13761 | this.hasRestrictedScaling = false;
|
13762 | }
|
13763 | }
|
13764 | const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
|
13765 | const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
|
13766 | width = (0, _ui_utils.roundToDivide)(width * outputScale.sx, sfx[0]);
|
13767 | height = (0, _ui_utils.roundToDivide)(height * outputScale.sy, sfy[0]);
|
13768 | let divisor = 1;
|
13769 | if (width >= 4096 || height >= 4096) {
|
13770 | if (!!this.maxWidth || !_canvasSize.default.test({
|
13771 | width,
|
13772 | height
|
13773 | })) {
|
13774 | const max = this.determineMaxDimensions();
|
13775 | divisor = Math.max(width / max, height / max);
|
13776 | if (divisor > 1) {
|
13777 | const newScale = Math.floor(100 * this.scale / divisor) / 100;
|
13778 | divisor = this.scale / newScale;
|
13779 | viewport.width /= divisor;
|
13780 | viewport.height /= divisor;
|
13781 | (0, _util.warn)(`Page ${this.id}: Reduced the maximum zoom to ${newScale} because the browser can't render larger canvases.`);
|
13782 | } else {
|
13783 | divisor = 1;
|
13784 | }
|
13785 | }
|
13786 | }
|
13787 | canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
|
13788 | canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
|
13789 | const {
|
13790 | style
|
13791 | } = canvas;
|
13792 | style.width = (0, _ui_utils.roundToDivide)(viewport.width * divisor, sfx[1]) + "px";
|
13793 | style.height = (0, _ui_utils.roundToDivide)(viewport.height * divisor, sfy[1]) + "px";
|
13794 | this.paintedViewportMap.set(canvas, viewport);
|
13795 | const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
|
13796 | let background = PDFViewerApplicationOptions.get("pdfBackgroundColor");
|
13797 | if (typeof background === "function") {
|
13798 | const backgroundColor = background({
|
13799 | pageNumber: this.id,
|
13800 | pageLabel: this.pageLabel
|
13801 | });
|
13802 | if (backgroundColor) {
|
13803 | background = backgroundColor;
|
13804 | }
|
13805 | }
|
13806 | let backgroundColorToReplace = background ? PDFViewerApplicationOptions.get("pdfBackgroundColorToReplace") : null;
|
13807 | if (typeof backgroundColorToReplace === "function") {
|
13808 | const colorToReplace = backgroundColorToReplace({
|
13809 | pageNumber: this.id,
|
13810 | pageLabel: this.pageLabel
|
13811 | });
|
13812 | if (colorToReplace) {
|
13813 | backgroundColorToReplace = colorToReplace;
|
13814 | }
|
13815 | }
|
13816 | const renderContext = {
|
13817 | canvasContext: ctx,
|
13818 | transform,
|
13819 | viewport,
|
13820 | annotationMode: this.#annotationMode,
|
13821 | optionalContentConfigPromise: this._optionalContentConfigPromise,
|
13822 | background,
|
13823 | backgroundColorToReplace,
|
13824 | annotationCanvasMap: this._annotationCanvasMap,
|
13825 | pageColors: this.pageColors
|
13826 | };
|
13827 | const renderTask = this.pdfPage.render(renderContext);
|
13828 | renderTask.onContinue = function (cont) {
|
13829 | showCanvas();
|
13830 | if (result.onRenderContinue) {
|
13831 | result.onRenderContinue(cont);
|
13832 | } else {
|
13833 | cont();
|
13834 | }
|
13835 | };
|
13836 | renderTask.promise.then(function () {
|
13837 | showCanvas();
|
13838 | renderCapability.resolve();
|
13839 | }, function (error) {
|
13840 | if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
|
13841 | showCanvas();
|
13842 | }
|
13843 | renderCapability.reject(error);
|
13844 | });
|
13845 | return result;
|
13846 | }
|
13847 | paintOnSvg(wrapper) {
|
13848 | let cancelled = false;
|
13849 | const ensureNotCancelled = () => {
|
13850 | if (cancelled) {
|
13851 | throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
|
13852 | }
|
13853 | };
|
13854 | const pdfPage = this.pdfPage;
|
13855 | const actualSizeViewport = this.viewport.clone({
|
13856 | scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
|
13857 | });
|
13858 | const promise = pdfPage.getOperatorList({
|
13859 | annotationMode: this.#annotationMode
|
13860 | }).then(opList => {
|
13861 | ensureNotCancelled();
|
13862 | const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
|
13863 | return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
|
13864 | ensureNotCancelled();
|
13865 | this.svg = svg;
|
13866 | this.paintedViewportMap.set(svg, actualSizeViewport);
|
13867 | svg.style.width = wrapper.style.width;
|
13868 | svg.style.height = wrapper.style.height;
|
13869 | this.renderingState = _ui_utils.RenderingStates.FINISHED;
|
13870 | wrapper.append(svg);
|
13871 | });
|
13872 | });
|
13873 | return {
|
13874 | promise,
|
13875 | onRenderContinue(cont) {
|
13876 | cont();
|
13877 | },
|
13878 | cancel() {
|
13879 | cancelled = true;
|
13880 | },
|
13881 | get separateAnnots() {
|
13882 | return false;
|
13883 | }
|
13884 | };
|
13885 | }
|
13886 | setPageLabel(label) {
|
13887 | this.pageLabel = typeof label === "string" ? label : null;
|
13888 | if (this.pageLabel !== null) {
|
13889 | this.div.setAttribute("data-page-label", this.pageLabel);
|
13890 | } else {
|
13891 | this.div.removeAttribute("data-page-label");
|
13892 | }
|
13893 | }
|
13894 | determineMaxDimensions() {
|
13895 | if (this.maxWidth) {
|
13896 | return this.maxWidth;
|
13897 | }
|
13898 | const checklist = [4096, 8192, 10836, 11180, 11402, 14188, 16384];
|
13899 | for (const width of checklist) {
|
13900 | if (!_canvasSize.default.test({
|
13901 | width: width + 1,
|
13902 | height: width + 1
|
13903 | })) {
|
13904 | this.maxWidth = width;
|
13905 | return this.maxWidth;
|
13906 | }
|
13907 | }
|
13908 | return 16384;
|
13909 | }
|
13910 | get thumbnailCanvas() {
|
13911 | const {
|
13912 | initialOptionalContent,
|
13913 | regularAnnotations
|
13914 | } = this.#useThumbnailCanvas;
|
13915 | return initialOptionalContent && regularAnnotations ? this.canvas : null;
|
13916 | }
|
13917 | }
|
13918 | exports.PDFPageView = PDFPageView;
|
13919 |
|
13920 | }),
|
13921 |
|
13922 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
13923 |
|
13924 |
|
13925 |
|
13926 | Object.defineProperty(exports, "__esModule", ({
|
13927 | value: true
|
13928 | }));
|
13929 | exports.AnnotationEditorLayerBuilder = void 0;
|
13930 | var _pdfjsLib = __webpack_require__(4);
|
13931 | var _l10n_utils = __webpack_require__(32);
|
13932 | class AnnotationEditorLayerBuilder {
|
13933 | #uiManager;
|
13934 | constructor(options) {
|
13935 | this.pageDiv = options.pageDiv;
|
13936 | this.pdfPage = options.pdfPage;
|
13937 | this.accessibilityManager = options.accessibilityManager;
|
13938 | this.l10n = options.l10n || _l10n_utils.NullL10n;
|
13939 | this.annotationEditorLayer = null;
|
13940 | this.div = null;
|
13941 | this._cancelled = false;
|
13942 | this.#uiManager = options.uiManager;
|
13943 | }
|
13944 | async render(viewport, intent = "display") {
|
13945 | if (intent !== "display") {
|
13946 | return;
|
13947 | }
|
13948 | if (this._cancelled) {
|
13949 | return;
|
13950 | }
|
13951 | const clonedViewport = viewport.clone({
|
13952 | dontFlip: true
|
13953 | });
|
13954 | if (this.div) {
|
13955 | this.annotationEditorLayer.update({
|
13956 | viewport: clonedViewport
|
13957 | });
|
13958 | this.show();
|
13959 | return;
|
13960 | }
|
13961 | const div = this.div = document.createElement("div");
|
13962 | div.className = "annotationEditorLayer";
|
13963 | div.tabIndex = 0;
|
13964 | div.hidden = true;
|
13965 | this.pageDiv.append(div);
|
13966 | this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
|
13967 | uiManager: this.#uiManager,
|
13968 | div,
|
13969 | accessibilityManager: this.accessibilityManager,
|
13970 | pageIndex: this.pdfPage.pageNumber - 1,
|
13971 | l10n: this.l10n,
|
13972 | viewport: clonedViewport
|
13973 | });
|
13974 | const parameters = {
|
13975 | viewport: clonedViewport,
|
13976 | div,
|
13977 | annotations: null,
|
13978 | intent
|
13979 | };
|
13980 | this.annotationEditorLayer.render(parameters);
|
13981 | this.show();
|
13982 | }
|
13983 | cancel() {
|
13984 | this._cancelled = true;
|
13985 | if (!this.div) {
|
13986 | return;
|
13987 | }
|
13988 | this.pageDiv = null;
|
13989 | this.annotationEditorLayer.destroy();
|
13990 | this.div.remove();
|
13991 | }
|
13992 | hide() {
|
13993 | if (!this.div) {
|
13994 | return;
|
13995 | }
|
13996 | this.div.hidden = true;
|
13997 | }
|
13998 | show() {
|
13999 | if (!this.div || this.annotationEditorLayer.isEmpty) {
|
14000 | return;
|
14001 | }
|
14002 | this.div.hidden = false;
|
14003 | }
|
14004 | }
|
14005 | exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
|
14006 |
|
14007 | }),
|
14008 |
|
14009 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
14010 |
|
14011 |
|
14012 |
|
14013 | Object.defineProperty(exports, "__esModule", ({
|
14014 | value: true
|
14015 | }));
|
14016 | exports.AnnotationLayerBuilder = void 0;
|
14017 | var _pdfjsLib = __webpack_require__(4);
|
14018 | var _l10n_utils = __webpack_require__(32);
|
14019 | var _ui_utils = __webpack_require__(3);
|
14020 | class AnnotationLayerBuilder {
|
14021 | #numAnnotations = 0;
|
14022 | #onPresentationModeChanged = null;
|
14023 | constructor({
|
14024 | pageDiv,
|
14025 | pdfPage,
|
14026 | linkService,
|
14027 | downloadManager,
|
14028 | annotationStorage = null,
|
14029 | imageResourcesPath = "",
|
14030 | renderForms = true,
|
14031 | l10n = _l10n_utils.NullL10n,
|
14032 | enableScripting = false,
|
14033 | hasJSActionsPromise = null,
|
14034 | fieldObjectsPromise = null,
|
14035 | annotationCanvasMap = null,
|
14036 | accessibilityManager = null
|
14037 | }) {
|
14038 | this.pageDiv = pageDiv;
|
14039 | this.pdfPage = pdfPage;
|
14040 | this.linkService = linkService;
|
14041 | this.downloadManager = downloadManager;
|
14042 | this.imageResourcesPath = imageResourcesPath;
|
14043 | this.renderForms = renderForms;
|
14044 | this.l10n = l10n;
|
14045 | this.annotationStorage = annotationStorage;
|
14046 | this.enableScripting = enableScripting;
|
14047 | this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false);
|
14048 | this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null);
|
14049 | this._annotationCanvasMap = annotationCanvasMap;
|
14050 | this._accessibilityManager = accessibilityManager;
|
14051 | this.div = null;
|
14052 | this._cancelled = false;
|
14053 | this._eventBus = linkService.eventBus;
|
14054 | }
|
14055 | async render(viewport, intent = "display") {
|
14056 | if (this.div) {
|
14057 | if (this._cancelled || this.#numAnnotations === 0) {
|
14058 | return;
|
14059 | }
|
14060 | _pdfjsLib.AnnotationLayer.update({
|
14061 | viewport: viewport.clone({
|
14062 | dontFlip: true
|
14063 | }),
|
14064 | div: this.div,
|
14065 | annotationCanvasMap: this._annotationCanvasMap
|
14066 | });
|
14067 | return;
|
14068 | }
|
14069 | const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({
|
14070 | intent
|
14071 | }), this._hasJSActionsPromise, this._fieldObjectsPromise]);
|
14072 | if (this._cancelled) {
|
14073 | return;
|
14074 | }
|
14075 | this.#numAnnotations = annotations.length;
|
14076 | this.div = document.createElement("div");
|
14077 | this.div.className = "annotationLayer";
|
14078 | this.pageDiv.append(this.div);
|
14079 | if (this.#numAnnotations === 0) {
|
14080 | this.hide();
|
14081 | return;
|
14082 | }
|
14083 | _pdfjsLib.AnnotationLayer.render({
|
14084 | viewport: viewport.clone({
|
14085 | dontFlip: true
|
14086 | }),
|
14087 | div: this.div,
|
14088 | annotations,
|
14089 | page: this.pdfPage,
|
14090 | imageResourcesPath: this.imageResourcesPath,
|
14091 | renderForms: this.renderForms,
|
14092 | linkService: this.linkService,
|
14093 | downloadManager: this.downloadManager,
|
14094 | annotationStorage: this.annotationStorage,
|
14095 | enableScripting: this.enableScripting,
|
14096 | hasJSActions,
|
14097 | fieldObjects,
|
14098 | annotationCanvasMap: this._annotationCanvasMap,
|
14099 | accessibilityManager: this._accessibilityManager
|
14100 | });
|
14101 | this.l10n.translate(this.div);
|
14102 | if (this.linkService.isInPresentationMode) {
|
14103 | this.#updatePresentationModeState(_ui_utils.PresentationModeState.FULLSCREEN);
|
14104 | }
|
14105 | if (!this.#onPresentationModeChanged) {
|
14106 | this.#onPresentationModeChanged = evt => {
|
14107 | this.#updatePresentationModeState(evt.state);
|
14108 | };
|
14109 | this._eventBus?._on("presentationmodechanged", this.#onPresentationModeChanged);
|
14110 | }
|
14111 | }
|
14112 | cancel() {
|
14113 | this._cancelled = true;
|
14114 | if (this.#onPresentationModeChanged) {
|
14115 | this._eventBus?._off("presentationmodechanged", this.#onPresentationModeChanged);
|
14116 | this.#onPresentationModeChanged = null;
|
14117 | }
|
14118 | }
|
14119 | hide() {
|
14120 | if (!this.div) {
|
14121 | return;
|
14122 | }
|
14123 | this.div.hidden = true;
|
14124 | }
|
14125 | #updatePresentationModeState(state) {
|
14126 | if (!this.div) {
|
14127 | return;
|
14128 | }
|
14129 | let disableFormElements = false;
|
14130 | switch (state) {
|
14131 | case _ui_utils.PresentationModeState.FULLSCREEN:
|
14132 | disableFormElements = true;
|
14133 | break;
|
14134 | case _ui_utils.PresentationModeState.NORMAL:
|
14135 | break;
|
14136 | default:
|
14137 | return;
|
14138 | }
|
14139 | for (const section of this.div.childNodes) {
|
14140 | if (section.hasAttribute("data-internal-link")) {
|
14141 | continue;
|
14142 | }
|
14143 | section.inert = disableFormElements;
|
14144 | }
|
14145 | }
|
14146 | }
|
14147 | exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
|
14148 |
|
14149 | }),
|
14150 |
|
14151 | ((__unused_webpack_module, exports) => {
|
14152 |
|
14153 |
|
14154 |
|
14155 | Object.defineProperty(exports, "__esModule", ({
|
14156 | value: true
|
14157 | }));
|
14158 | exports.StructTreeLayerBuilder = void 0;
|
14159 | const PDF_ROLE_TO_HTML_ROLE = {
|
14160 | Document: null,
|
14161 | DocumentFragment: null,
|
14162 | Part: "group",
|
14163 | Sect: "group",
|
14164 | Div: "group",
|
14165 | Aside: "note",
|
14166 | NonStruct: "none",
|
14167 | P: null,
|
14168 | H: "heading",
|
14169 | Title: null,
|
14170 | FENote: "note",
|
14171 | Sub: "group",
|
14172 | Lbl: null,
|
14173 | Span: null,
|
14174 | Em: null,
|
14175 | Strong: null,
|
14176 | Link: "link",
|
14177 | Annot: "note",
|
14178 | Form: "form",
|
14179 | Ruby: null,
|
14180 | RB: null,
|
14181 | RT: null,
|
14182 | RP: null,
|
14183 | Warichu: null,
|
14184 | WT: null,
|
14185 | WP: null,
|
14186 | L: "list",
|
14187 | LI: "listitem",
|
14188 | LBody: null,
|
14189 | Table: "table",
|
14190 | TR: "row",
|
14191 | TH: "columnheader",
|
14192 | TD: "cell",
|
14193 | THead: "columnheader",
|
14194 | TBody: null,
|
14195 | TFoot: null,
|
14196 | Caption: null,
|
14197 | Figure: "figure",
|
14198 | Formula: null,
|
14199 | Artifact: null
|
14200 | };
|
14201 | const HEADING_PATTERN = /^H(\d+)$/;
|
14202 | class StructTreeLayerBuilder {
|
14203 | #treeDom = undefined;
|
14204 | get renderingDone() {
|
14205 | return this.#treeDom !== undefined;
|
14206 | }
|
14207 | render(structTree) {
|
14208 | if (this.#treeDom !== undefined) {
|
14209 | return this.#treeDom;
|
14210 | }
|
14211 | const treeDom = this.#walk(structTree);
|
14212 | treeDom?.classList.add("structTree");
|
14213 | return this.#treeDom = treeDom;
|
14214 | }
|
14215 | hide() {
|
14216 | if (this.#treeDom && !this.#treeDom.hidden) {
|
14217 | this.#treeDom.hidden = true;
|
14218 | }
|
14219 | }
|
14220 | show() {
|
14221 | if (this.#treeDom?.hidden) {
|
14222 | this.#treeDom.hidden = false;
|
14223 | }
|
14224 | }
|
14225 | #setAttributes(structElement, htmlElement) {
|
14226 | if (structElement.alt !== undefined) {
|
14227 | htmlElement.setAttribute("aria-label", structElement.alt);
|
14228 | }
|
14229 | if (structElement.id !== undefined) {
|
14230 | htmlElement.setAttribute("aria-owns", structElement.id);
|
14231 | }
|
14232 | if (structElement.lang !== undefined) {
|
14233 | htmlElement.setAttribute("lang", structElement.lang);
|
14234 | }
|
14235 | }
|
14236 | #walk(node) {
|
14237 | if (!node) {
|
14238 | return null;
|
14239 | }
|
14240 | const element = document.createElement("span");
|
14241 | if ("role" in node) {
|
14242 | const {
|
14243 | role
|
14244 | } = node;
|
14245 | const match = role.match(HEADING_PATTERN);
|
14246 | if (match) {
|
14247 | element.setAttribute("role", "heading");
|
14248 | element.setAttribute("aria-level", match[1]);
|
14249 | } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
|
14250 | element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
|
14251 | }
|
14252 | }
|
14253 | this.#setAttributes(node, element);
|
14254 | if (node.children) {
|
14255 | if (node.children.length === 1 && "id" in node.children[0]) {
|
14256 | this.#setAttributes(node.children[0], element);
|
14257 | } else {
|
14258 | for (const kid of node.children) {
|
14259 | element.append(this.#walk(kid));
|
14260 | }
|
14261 | }
|
14262 | }
|
14263 | return element;
|
14264 | }
|
14265 | }
|
14266 | exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
|
14267 |
|
14268 | }),
|
14269 |
|
14270 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
14271 |
|
14272 |
|
14273 |
|
14274 | Object.defineProperty(exports, "__esModule", ({
|
14275 | value: true
|
14276 | }));
|
14277 | exports.TextAccessibilityManager = void 0;
|
14278 | var _ui_utils = __webpack_require__(3);
|
14279 | class TextAccessibilityManager {
|
14280 | #enabled = false;
|
14281 | #textChildren = null;
|
14282 | #textNodes = new Map();
|
14283 | #waitingElements = new Map();
|
14284 | setTextMapping(textDivs) {
|
14285 | this.#textChildren = textDivs;
|
14286 | }
|
14287 | static #compareElementPositions(e1, e2) {
|
14288 | const rect1 = e1.getBoundingClientRect();
|
14289 | const rect2 = e2.getBoundingClientRect();
|
14290 | if (rect1.width === 0 && rect1.height === 0) {
|
14291 | return +1;
|
14292 | }
|
14293 | if (rect2.width === 0 && rect2.height === 0) {
|
14294 | return -1;
|
14295 | }
|
14296 | const top1 = rect1.y;
|
14297 | const bot1 = rect1.y + rect1.height;
|
14298 | const mid1 = rect1.y + rect1.height / 2;
|
14299 | const top2 = rect2.y;
|
14300 | const bot2 = rect2.y + rect2.height;
|
14301 | const mid2 = rect2.y + rect2.height / 2;
|
14302 | if (mid1 <= top2 && mid2 >= bot1) {
|
14303 | return -1;
|
14304 | }
|
14305 | if (mid2 <= top1 && mid1 >= bot2) {
|
14306 | return +1;
|
14307 | }
|
14308 | const centerX1 = rect1.x + rect1.width / 2;
|
14309 | const centerX2 = rect2.x + rect2.width / 2;
|
14310 | return centerX1 - centerX2;
|
14311 | }
|
14312 | enable() {
|
14313 | if (this.#enabled) {
|
14314 | throw new Error("TextAccessibilityManager is already enabled.");
|
14315 | }
|
14316 | if (!this.#textChildren) {
|
14317 | throw new Error("Text divs and strings have not been set.");
|
14318 | }
|
14319 | this.#enabled = true;
|
14320 | this.#textChildren = this.#textChildren.slice();
|
14321 | this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions);
|
14322 | if (this.#textNodes.size > 0) {
|
14323 | const textChildren = this.#textChildren;
|
14324 | for (const [id, nodeIndex] of this.#textNodes) {
|
14325 | const element = document.getElementById(id);
|
14326 | if (!element) {
|
14327 | this.#textNodes.delete(id);
|
14328 | continue;
|
14329 | }
|
14330 | this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
|
14331 | }
|
14332 | }
|
14333 | for (const [element, isRemovable] of this.#waitingElements) {
|
14334 | this.addPointerInTextLayer(element, isRemovable);
|
14335 | }
|
14336 | this.#waitingElements.clear();
|
14337 | }
|
14338 | disable() {
|
14339 | if (!this.#enabled) {
|
14340 | return;
|
14341 | }
|
14342 | this.#waitingElements.clear();
|
14343 | this.#textChildren = null;
|
14344 | this.#enabled = false;
|
14345 | }
|
14346 | removePointerInTextLayer(element) {
|
14347 | if (!this.#enabled) {
|
14348 | this.#waitingElements.delete(element);
|
14349 | return;
|
14350 | }
|
14351 | const children = this.#textChildren;
|
14352 | if (!children || children.length === 0) {
|
14353 | return;
|
14354 | }
|
14355 | const {
|
14356 | id
|
14357 | } = element;
|
14358 | const nodeIndex = this.#textNodes.get(id);
|
14359 | if (nodeIndex === undefined) {
|
14360 | return;
|
14361 | }
|
14362 | const node = children[nodeIndex];
|
14363 | this.#textNodes.delete(id);
|
14364 | let owns = node.getAttribute("aria-owns");
|
14365 | if (owns?.includes(id)) {
|
14366 | owns = owns.split(" ").filter(x => x !== id).join(" ");
|
14367 | if (owns) {
|
14368 | node.setAttribute("aria-owns", owns);
|
14369 | } else {
|
14370 | node.removeAttribute("aria-owns");
|
14371 | node.setAttribute("role", "presentation");
|
14372 | }
|
14373 | }
|
14374 | }
|
14375 | #addIdToAriaOwns(id, node) {
|
14376 | const owns = node.getAttribute("aria-owns");
|
14377 | if (!owns?.includes(id)) {
|
14378 | node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
|
14379 | }
|
14380 | node.removeAttribute("role");
|
14381 | }
|
14382 | addPointerInTextLayer(element, isRemovable) {
|
14383 | const {
|
14384 | id
|
14385 | } = element;
|
14386 | if (!id) {
|
14387 | return;
|
14388 | }
|
14389 | if (!this.#enabled) {
|
14390 | this.#waitingElements.set(element, isRemovable);
|
14391 | return;
|
14392 | }
|
14393 | if (isRemovable) {
|
14394 | this.removePointerInTextLayer(element);
|
14395 | }
|
14396 | const children = this.#textChildren;
|
14397 | if (!children || children.length === 0) {
|
14398 | return;
|
14399 | }
|
14400 | const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0);
|
14401 | const nodeIndex = Math.max(0, index - 1);
|
14402 | this.#addIdToAriaOwns(id, children[nodeIndex]);
|
14403 | this.#textNodes.set(id, nodeIndex);
|
14404 | }
|
14405 | moveElementInDOM(container, element, contentElement, isRemovable) {
|
14406 | this.addPointerInTextLayer(contentElement, isRemovable);
|
14407 | if (!container.hasChildNodes()) {
|
14408 | container.append(element);
|
14409 | return;
|
14410 | }
|
14411 | const children = Array.from(container.childNodes).filter(node => node !== element);
|
14412 | if (children.length === 0) {
|
14413 | return;
|
14414 | }
|
14415 | const elementToCompare = contentElement || element;
|
14416 | const index = (0, _ui_utils.binarySearchFirstItem)(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0);
|
14417 | if (index === 0) {
|
14418 | children[0].before(element);
|
14419 | } else {
|
14420 | children[index - 1].after(element);
|
14421 | }
|
14422 | }
|
14423 | }
|
14424 | exports.TextAccessibilityManager = TextAccessibilityManager;
|
14425 |
|
14426 | }),
|
14427 |
|
14428 | ((__unused_webpack_module, exports) => {
|
14429 |
|
14430 |
|
14431 |
|
14432 | Object.defineProperty(exports, "__esModule", ({
|
14433 | value: true
|
14434 | }));
|
14435 | exports["default"] = void 0;
|
14436 | function ownKeys(object, enumerableOnly) {
|
14437 | var keys = Object.keys(object);
|
14438 | if (Object.getOwnPropertySymbols) {
|
14439 | var symbols = Object.getOwnPropertySymbols(object);
|
14440 | if (enumerableOnly) {
|
14441 | symbols = symbols.filter(function (sym) {
|
14442 | return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
14443 | });
|
14444 | }
|
14445 | keys.push.apply(keys, symbols);
|
14446 | }
|
14447 | return keys;
|
14448 | }
|
14449 | function _objectSpread2(target) {
|
14450 | for (var i = 1; i < arguments.length; i++) {
|
14451 | var source = arguments[i] != null ? arguments[i] : {};
|
14452 | if (i % 2) {
|
14453 | ownKeys(Object(source), true).forEach(function (key) {
|
14454 | _defineProperty(target, key, source[key]);
|
14455 | });
|
14456 | } else if (Object.getOwnPropertyDescriptors) {
|
14457 | Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
14458 | } else {
|
14459 | ownKeys(Object(source)).forEach(function (key) {
|
14460 | Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
14461 | });
|
14462 | }
|
14463 | }
|
14464 | return target;
|
14465 | }
|
14466 | function _defineProperty(obj, key, value) {
|
14467 | if (key in obj) {
|
14468 | Object.defineProperty(obj, key, {
|
14469 | value: value,
|
14470 | enumerable: true,
|
14471 | configurable: true,
|
14472 | writable: true
|
14473 | });
|
14474 | } else {
|
14475 | obj[key] = value;
|
14476 | }
|
14477 | return obj;
|
14478 | }
|
14479 | function _objectWithoutPropertiesLoose(source, excluded) {
|
14480 | if (source == null) return {};
|
14481 | var target = {};
|
14482 | var sourceKeys = Object.keys(source);
|
14483 | var key, i;
|
14484 | for (i = 0; i < sourceKeys.length; i++) {
|
14485 | key = sourceKeys[i];
|
14486 | if (excluded.indexOf(key) >= 0) continue;
|
14487 | target[key] = source[key];
|
14488 | }
|
14489 | return target;
|
14490 | }
|
14491 | function _objectWithoutProperties(source, excluded) {
|
14492 | if (source == null) return {};
|
14493 | var target = _objectWithoutPropertiesLoose(source, excluded);
|
14494 | var key, i;
|
14495 | if (Object.getOwnPropertySymbols) {
|
14496 | var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
14497 | for (i = 0; i < sourceSymbolKeys.length; i++) {
|
14498 | key = sourceSymbolKeys[i];
|
14499 | if (excluded.indexOf(key) >= 0) continue;
|
14500 | if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
14501 | target[key] = source[key];
|
14502 | }
|
14503 | }
|
14504 | return target;
|
14505 | }
|
14506 | function _slicedToArray(arr, i) {
|
14507 | return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
14508 | }
|
14509 | function _toConsumableArray(arr) {
|
14510 | return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
14511 | }
|
14512 | function _arrayWithoutHoles(arr) {
|
14513 | if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
14514 | }
|
14515 | function _arrayWithHoles(arr) {
|
14516 | if (Array.isArray(arr)) return arr;
|
14517 | }
|
14518 | function _iterableToArray(iter) {
|
14519 | if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
14520 | }
|
14521 | function _iterableToArrayLimit(arr, i) {
|
14522 | var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
14523 | if (_i == null) return;
|
14524 | var _arr = [];
|
14525 | var _n = true;
|
14526 | var _d = false;
|
14527 | var _s, _e;
|
14528 | try {
|
14529 | for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
14530 | _arr.push(_s.value);
|
14531 | if (i && _arr.length === i) break;
|
14532 | }
|
14533 | } catch (err) {
|
14534 | _d = true;
|
14535 | _e = err;
|
14536 | } finally {
|
14537 | try {
|
14538 | if (!_n && _i["return"] != null) _i["return"]();
|
14539 | } finally {
|
14540 | if (_d) throw _e;
|
14541 | }
|
14542 | }
|
14543 | return _arr;
|
14544 | }
|
14545 | function _unsupportedIterableToArray(o, minLen) {
|
14546 | if (!o) return;
|
14547 | if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
14548 | var n = Object.prototype.toString.call(o).slice(8, -1);
|
14549 | if (n === "Object" && o.constructor) n = o.constructor.name;
|
14550 | if (n === "Map" || n === "Set") return Array.from(o);
|
14551 | if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
14552 | }
|
14553 | function _arrayLikeToArray(arr, len) {
|
14554 | if (len == null || len > arr.length) len = arr.length;
|
14555 | for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
14556 | return arr2;
|
14557 | }
|
14558 | function _nonIterableSpread() {
|
14559 | throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
14560 | }
|
14561 | function _nonIterableRest() {
|
14562 | throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
14563 | }
|
14564 | function canvasTest(settings) {
|
14565 | var size = settings.sizes.shift();
|
14566 | var width = Math.max(Math.ceil(size[0]), 1);
|
14567 | var height = Math.max(Math.ceil(size[1]), 1);
|
14568 | var fill = [width - 1, height - 1, 1, 1];
|
14569 | var job = Date.now();
|
14570 | var isWorker = typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope;
|
14571 | var cropCvs, testCvs;
|
14572 | if (isWorker) {
|
14573 | cropCvs = new OffscreenCanvas(1, 1);
|
14574 | testCvs = new OffscreenCanvas(width, height);
|
14575 | } else {
|
14576 | cropCvs = document.createElement("canvas");
|
14577 | cropCvs.width = 1;
|
14578 | cropCvs.height = 1;
|
14579 | testCvs = document.createElement("canvas");
|
14580 | testCvs.width = width;
|
14581 | testCvs.height = height;
|
14582 | }
|
14583 | var cropCtx = cropCvs.getContext("2d");
|
14584 | var testCtx = testCvs.getContext("2d");
|
14585 | if (testCtx) {
|
14586 | testCtx.fillRect.apply(testCtx, fill);
|
14587 | cropCtx.drawImage(testCvs, width - 1, height - 1, 1, 1, 0, 0, 1, 1);
|
14588 | }
|
14589 | var isTestPass = cropCtx && cropCtx.getImageData(0, 0, 1, 1).data[3] !== 0;
|
14590 | var benchmark = Date.now() - job;
|
14591 | if (isWorker) {
|
14592 | postMessage({
|
14593 | width: width,
|
14594 | height: height,
|
14595 | benchmark: benchmark,
|
14596 | isTestPass: isTestPass
|
14597 | });
|
14598 | if (!isTestPass && settings.sizes.length) {
|
14599 | canvasTest(settings);
|
14600 | }
|
14601 | } else if (isTestPass) {
|
14602 | settings.onSuccess(width, height, benchmark);
|
14603 | } else {
|
14604 | settings.onError(width, height, benchmark);
|
14605 | if (settings.sizes.length) {
|
14606 | canvasTest(settings);
|
14607 | }
|
14608 | }
|
14609 | return isTestPass;
|
14610 | }
|
14611 | var testSizes = {
|
14612 | area: [16384, 14188, 11402, 11180, 10836, 8192, 4096, 1],
|
14613 | height: [8388607, 65535, 32767, 16384, 8192, 4096, 1],
|
14614 | width: [4194303, 65535, 32767, 16384, 8192, 4096, 1]
|
14615 | };
|
14616 | var _excluded = ["onError", "onSuccess"];
|
14617 | var defaults = {
|
14618 | max: null,
|
14619 | min: 1,
|
14620 | sizes: [],
|
14621 | step: 1024,
|
14622 | usePromise: false,
|
14623 | useWorker: false,
|
14624 | onError: Function.prototype,
|
14625 | onSuccess: Function.prototype
|
14626 | };
|
14627 | var workerJobs = {};
|
14628 | function createSizesArray(settings) {
|
14629 | var isArea = settings.width === settings.height;
|
14630 | var isWidth = settings.height === 1;
|
14631 | var isHeight = settings.width === 1;
|
14632 | var sizes = [];
|
14633 | if (!settings.width || !settings.height) {
|
14634 | settings.sizes.forEach(function (testSize) {
|
14635 | var width = isArea || isWidth ? testSize : 1;
|
14636 | var height = isArea || isHeight ? testSize : 1;
|
14637 | sizes.push([width, height]);
|
14638 | });
|
14639 | } else {
|
14640 | var testMin = settings.min || defaults.min;
|
14641 | var testStep = settings.step || defaults.step;
|
14642 | var testSize = Math.max(settings.width, settings.height);
|
14643 | while (testSize >= testMin) {
|
14644 | var width = isArea || isWidth ? testSize : 1;
|
14645 | var height = isArea || isHeight ? testSize : 1;
|
14646 | sizes.push([width, height]);
|
14647 | testSize -= testStep;
|
14648 | }
|
14649 | }
|
14650 | return sizes;
|
14651 | }
|
14652 | function handleMethod(settings) {
|
14653 | var hasCanvasSupport = window && "HTMLCanvasElement" in window;
|
14654 | var hasOffscreenCanvasSupport = window && "OffscreenCanvas" in window;
|
14655 | var jobID = Date.now();
|
14656 | var _onError = settings.onError,
|
14657 | _onSuccess = settings.onSuccess,
|
14658 | settingsWithoutCallbacks = _objectWithoutProperties(settings, _excluded);
|
14659 | var worker = null;
|
14660 | if (!hasCanvasSupport) {
|
14661 | return false;
|
14662 | }
|
14663 | if (settings.useWorker && hasOffscreenCanvasSupport) {
|
14664 | var js = "\n var canvasTest = ".concat(canvasTest.toString(), ";\n onmessage = function(e) {\n canvasTest(e.data);\n };\n ");
|
14665 | var blob = new Blob([js], {
|
14666 | type: "application/javascript"
|
14667 | });
|
14668 | var blobURL = URL.createObjectURL(blob);
|
14669 | worker = new Worker(blobURL);
|
14670 | URL.revokeObjectURL(blobURL);
|
14671 | worker.onmessage = function (e) {
|
14672 | var _e$data = e.data,
|
14673 | width = _e$data.width,
|
14674 | height = _e$data.height,
|
14675 | benchmark = _e$data.benchmark,
|
14676 | isTestPass = _e$data.isTestPass;
|
14677 | if (isTestPass) {
|
14678 | workerJobs[jobID].onSuccess(width, height, benchmark);
|
14679 | delete workerJobs[jobID];
|
14680 | } else {
|
14681 | workerJobs[jobID].onError(width, height, benchmark);
|
14682 | }
|
14683 | };
|
14684 | }
|
14685 | if (settings.usePromise) {
|
14686 | return new Promise(function (resolve, reject) {
|
14687 | var promiseSettings = _objectSpread2(_objectSpread2({}, settings), {}, {
|
14688 | onError: function onError(width, height, benchmark) {
|
14689 | var isLastTest;
|
14690 | if (settings.sizes.length === 0) {
|
14691 | isLastTest = true;
|
14692 | } else {
|
14693 | var _settings$sizes$slice = settings.sizes.slice(-1),
|
14694 | _settings$sizes$slice2 = _slicedToArray(_settings$sizes$slice, 1),
|
14695 | _settings$sizes$slice3 = _slicedToArray(_settings$sizes$slice2[0], 2),
|
14696 | lastWidth = _settings$sizes$slice3[0],
|
14697 | lastHeight = _settings$sizes$slice3[1];
|
14698 | isLastTest = width === lastWidth && height === lastHeight;
|
14699 | }
|
14700 | _onError(width, height, benchmark);
|
14701 | if (isLastTest) {
|
14702 | reject({
|
14703 | width: width,
|
14704 | height: height,
|
14705 | benchmark: benchmark
|
14706 | });
|
14707 | }
|
14708 | },
|
14709 | onSuccess: function onSuccess(width, height, benchmark) {
|
14710 | _onSuccess(width, height, benchmark);
|
14711 | resolve({
|
14712 | width: width,
|
14713 | height: height,
|
14714 | benchmark: benchmark
|
14715 | });
|
14716 | }
|
14717 | });
|
14718 | if (worker) {
|
14719 | var onError = promiseSettings.onError,
|
14720 | onSuccess = promiseSettings.onSuccess;
|
14721 | workerJobs[jobID] = {
|
14722 | onError: onError,
|
14723 | onSuccess: onSuccess
|
14724 | };
|
14725 | worker.postMessage(settingsWithoutCallbacks);
|
14726 | } else {
|
14727 | canvasTest(promiseSettings);
|
14728 | }
|
14729 | });
|
14730 | } else {
|
14731 | if (worker) {
|
14732 | workerJobs[jobID] = {
|
14733 | onError: _onError,
|
14734 | onSuccess: _onSuccess
|
14735 | };
|
14736 | worker.postMessage(settingsWithoutCallbacks);
|
14737 | } else {
|
14738 | return canvasTest(settings);
|
14739 | }
|
14740 | }
|
14741 | }
|
14742 | var canvasSize = {
|
14743 | maxArea: function maxArea() {
|
14744 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
14745 | var sizes = createSizesArray({
|
14746 | width: options.max,
|
14747 | height: options.max,
|
14748 | min: options.min,
|
14749 | step: options.step,
|
14750 | sizes: _toConsumableArray(testSizes.area)
|
14751 | });
|
14752 | var settings = _objectSpread2(_objectSpread2(_objectSpread2({}, defaults), options), {}, {
|
14753 | sizes: sizes
|
14754 | });
|
14755 | return handleMethod(settings);
|
14756 | },
|
14757 | maxHeight: function maxHeight() {
|
14758 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
14759 | var sizes = createSizesArray({
|
14760 | width: 1,
|
14761 | height: options.max,
|
14762 | min: options.min,
|
14763 | step: options.step,
|
14764 | sizes: _toConsumableArray(testSizes.height)
|
14765 | });
|
14766 | var settings = _objectSpread2(_objectSpread2(_objectSpread2({}, defaults), options), {}, {
|
14767 | sizes: sizes
|
14768 | });
|
14769 | return handleMethod(settings);
|
14770 | },
|
14771 | maxWidth: function maxWidth() {
|
14772 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
14773 | var sizes = createSizesArray({
|
14774 | width: options.max,
|
14775 | height: 1,
|
14776 | min: options.min,
|
14777 | step: options.step,
|
14778 | sizes: _toConsumableArray(testSizes.width)
|
14779 | });
|
14780 | var settings = _objectSpread2(_objectSpread2(_objectSpread2({}, defaults), options), {}, {
|
14781 | sizes: sizes
|
14782 | });
|
14783 | return handleMethod(settings);
|
14784 | },
|
14785 | test: function test() {
|
14786 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
14787 | var settings = _objectSpread2(_objectSpread2({}, defaults), options);
|
14788 | settings.sizes = _toConsumableArray(settings.sizes);
|
14789 | if (settings.width && settings.height) {
|
14790 | settings.sizes = [[settings.width, settings.height]];
|
14791 | }
|
14792 | return handleMethod(settings);
|
14793 | }
|
14794 | };
|
14795 | exports["default"] = canvasSize;
|
14796 |
|
14797 | }),
|
14798 |
|
14799 | ((__unused_webpack_module, exports) => {
|
14800 |
|
14801 |
|
14802 |
|
14803 | Object.defineProperty(exports, "__esModule", ({
|
14804 | value: true
|
14805 | }));
|
14806 | exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.UNSUPPORTED_FEATURES = exports.TextRenderingMode = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.LINE_FACTOR = exports.LINE_DESCENT_FACTOR = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.BASELINE_FACTOR = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationEditorType = exports.AnnotationEditorPrefix = exports.AnnotationEditorParamsType = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
|
14807 | exports.assert = assert;
|
14808 | exports.bytesToString = bytesToString;
|
14809 | exports.createPromiseCapability = createPromiseCapability;
|
14810 | exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
|
14811 | exports.getModificationDate = getModificationDate;
|
14812 | exports.getVerbosityLevel = getVerbosityLevel;
|
14813 | exports.info = info;
|
14814 | exports.isArrayBuffer = isArrayBuffer;
|
14815 | exports.isArrayEqual = isArrayEqual;
|
14816 | exports.objectFromMap = objectFromMap;
|
14817 | exports.objectSize = objectSize;
|
14818 | exports.setVerbosityLevel = setVerbosityLevel;
|
14819 | exports.shadow = shadow;
|
14820 | exports.string32 = string32;
|
14821 | exports.stringToBytes = stringToBytes;
|
14822 | exports.stringToPDFString = stringToPDFString;
|
14823 | exports.stringToUTF8String = stringToUTF8String;
|
14824 | exports.unreachable = unreachable;
|
14825 | exports.utf8StringToString = utf8StringToString;
|
14826 | exports.warn = warn;
|
14827 | ;
|
14828 | const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
|
14829 | exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
|
14830 | const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
|
14831 | exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
|
14832 | const LINE_FACTOR = 1.35;
|
14833 | exports.LINE_FACTOR = LINE_FACTOR;
|
14834 | const LINE_DESCENT_FACTOR = 0.35;
|
14835 | exports.LINE_DESCENT_FACTOR = LINE_DESCENT_FACTOR;
|
14836 | const BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
|
14837 | exports.BASELINE_FACTOR = BASELINE_FACTOR;
|
14838 | const RenderingIntentFlag = {
|
14839 | ANY: 0x01,
|
14840 | DISPLAY: 0x02,
|
14841 | PRINT: 0x04,
|
14842 | SAVE: 0x08,
|
14843 | ANNOTATIONS_FORMS: 0x10,
|
14844 | ANNOTATIONS_STORAGE: 0x20,
|
14845 | ANNOTATIONS_DISABLE: 0x40,
|
14846 | OPLIST: 0x100
|
14847 | };
|
14848 | exports.RenderingIntentFlag = RenderingIntentFlag;
|
14849 | const AnnotationMode = {
|
14850 | DISABLE: 0,
|
14851 | ENABLE: 1,
|
14852 | ENABLE_FORMS: 2,
|
14853 | ENABLE_STORAGE: 3
|
14854 | };
|
14855 | exports.AnnotationMode = AnnotationMode;
|
14856 | const AnnotationEditorPrefix = "pdfjs_internal_editor_";
|
14857 | exports.AnnotationEditorPrefix = AnnotationEditorPrefix;
|
14858 | const AnnotationEditorType = {
|
14859 | DISABLE: -1,
|
14860 | NONE: 0,
|
14861 | FREETEXT: 3,
|
14862 | INK: 15
|
14863 | };
|
14864 | exports.AnnotationEditorType = AnnotationEditorType;
|
14865 | const AnnotationEditorParamsType = {
|
14866 | FREETEXT_SIZE: 1,
|
14867 | FREETEXT_COLOR: 2,
|
14868 | FREETEXT_OPACITY: 3,
|
14869 | INK_COLOR: 11,
|
14870 | INK_THICKNESS: 12,
|
14871 | INK_OPACITY: 13
|
14872 | };
|
14873 | exports.AnnotationEditorParamsType = AnnotationEditorParamsType;
|
14874 | const PermissionFlag = {
|
14875 | PRINT: 0x04,
|
14876 | MODIFY_CONTENTS: 0x08,
|
14877 | COPY: 0x10,
|
14878 | MODIFY_ANNOTATIONS: 0x20,
|
14879 | FILL_INTERACTIVE_FORMS: 0x100,
|
14880 | COPY_FOR_ACCESSIBILITY: 0x200,
|
14881 | ASSEMBLE: 0x400,
|
14882 | PRINT_HIGH_QUALITY: 0x800
|
14883 | };
|
14884 | exports.PermissionFlag = PermissionFlag;
|
14885 | const TextRenderingMode = {
|
14886 | FILL: 0,
|
14887 | STROKE: 1,
|
14888 | FILL_STROKE: 2,
|
14889 | INVISIBLE: 3,
|
14890 | FILL_ADD_TO_PATH: 4,
|
14891 | STROKE_ADD_TO_PATH: 5,
|
14892 | FILL_STROKE_ADD_TO_PATH: 6,
|
14893 | ADD_TO_PATH: 7,
|
14894 | FILL_STROKE_MASK: 3,
|
14895 | ADD_TO_PATH_FLAG: 4
|
14896 | };
|
14897 | exports.TextRenderingMode = TextRenderingMode;
|
14898 | const ImageKind = {
|
14899 | GRAYSCALE_1BPP: 1,
|
14900 | RGB_24BPP: 2,
|
14901 | RGBA_32BPP: 3
|
14902 | };
|
14903 | exports.ImageKind = ImageKind;
|
14904 | const AnnotationType = {
|
14905 | TEXT: 1,
|
14906 | LINK: 2,
|
14907 | FREETEXT: 3,
|
14908 | LINE: 4,
|
14909 | SQUARE: 5,
|
14910 | CIRCLE: 6,
|
14911 | POLYGON: 7,
|
14912 | POLYLINE: 8,
|
14913 | HIGHLIGHT: 9,
|
14914 | UNDERLINE: 10,
|
14915 | SQUIGGLY: 11,
|
14916 | STRIKEOUT: 12,
|
14917 | STAMP: 13,
|
14918 | CARET: 14,
|
14919 | INK: 15,
|
14920 | POPUP: 16,
|
14921 | FILEATTACHMENT: 17,
|
14922 | SOUND: 18,
|
14923 | MOVIE: 19,
|
14924 | WIDGET: 20,
|
14925 | SCREEN: 21,
|
14926 | PRINTERMARK: 22,
|
14927 | TRAPNET: 23,
|
14928 | WATERMARK: 24,
|
14929 | THREED: 25,
|
14930 | REDACT: 26
|
14931 | };
|
14932 | exports.AnnotationType = AnnotationType;
|
14933 | const AnnotationStateModelType = {
|
14934 | MARKED: "Marked",
|
14935 | REVIEW: "Review"
|
14936 | };
|
14937 | exports.AnnotationStateModelType = AnnotationStateModelType;
|
14938 | const AnnotationMarkedState = {
|
14939 | MARKED: "Marked",
|
14940 | UNMARKED: "Unmarked"
|
14941 | };
|
14942 | exports.AnnotationMarkedState = AnnotationMarkedState;
|
14943 | const AnnotationReviewState = {
|
14944 | ACCEPTED: "Accepted",
|
14945 | REJECTED: "Rejected",
|
14946 | CANCELLED: "Cancelled",
|
14947 | COMPLETED: "Completed",
|
14948 | NONE: "None"
|
14949 | };
|
14950 | exports.AnnotationReviewState = AnnotationReviewState;
|
14951 | const AnnotationReplyType = {
|
14952 | GROUP: "Group",
|
14953 | REPLY: "R"
|
14954 | };
|
14955 | exports.AnnotationReplyType = AnnotationReplyType;
|
14956 | const AnnotationFlag = {
|
14957 | INVISIBLE: 0x01,
|
14958 | HIDDEN: 0x02,
|
14959 | PRINT: 0x04,
|
14960 | NOZOOM: 0x08,
|
14961 | NOROTATE: 0x10,
|
14962 | NOVIEW: 0x20,
|
14963 | READONLY: 0x40,
|
14964 | LOCKED: 0x80,
|
14965 | TOGGLENOVIEW: 0x100,
|
14966 | LOCKEDCONTENTS: 0x200
|
14967 | };
|
14968 | exports.AnnotationFlag = AnnotationFlag;
|
14969 | const AnnotationFieldFlag = {
|
14970 | READONLY: 0x0000001,
|
14971 | REQUIRED: 0x0000002,
|
14972 | NOEXPORT: 0x0000004,
|
14973 | MULTILINE: 0x0001000,
|
14974 | PASSWORD: 0x0002000,
|
14975 | NOTOGGLETOOFF: 0x0004000,
|
14976 | RADIO: 0x0008000,
|
14977 | PUSHBUTTON: 0x0010000,
|
14978 | COMBO: 0x0020000,
|
14979 | EDIT: 0x0040000,
|
14980 | SORT: 0x0080000,
|
14981 | FILESELECT: 0x0100000,
|
14982 | MULTISELECT: 0x0200000,
|
14983 | DONOTSPELLCHECK: 0x0400000,
|
14984 | DONOTSCROLL: 0x0800000,
|
14985 | COMB: 0x1000000,
|
14986 | RICHTEXT: 0x2000000,
|
14987 | RADIOSINUNISON: 0x2000000,
|
14988 | COMMITONSELCHANGE: 0x4000000
|
14989 | };
|
14990 | exports.AnnotationFieldFlag = AnnotationFieldFlag;
|
14991 | const AnnotationBorderStyleType = {
|
14992 | SOLID: 1,
|
14993 | DASHED: 2,
|
14994 | BEVELED: 3,
|
14995 | INSET: 4,
|
14996 | UNDERLINE: 5
|
14997 | };
|
14998 | exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
|
14999 | const AnnotationActionEventType = {
|
15000 | E: "Mouse Enter",
|
15001 | X: "Mouse Exit",
|
15002 | D: "Mouse Down",
|
15003 | U: "Mouse Up",
|
15004 | Fo: "Focus",
|
15005 | Bl: "Blur",
|
15006 | PO: "PageOpen",
|
15007 | PC: "PageClose",
|
15008 | PV: "PageVisible",
|
15009 | PI: "PageInvisible",
|
15010 | K: "Keystroke",
|
15011 | F: "Format",
|
15012 | V: "Validate",
|
15013 | C: "Calculate"
|
15014 | };
|
15015 | exports.AnnotationActionEventType = AnnotationActionEventType;
|
15016 | const DocumentActionEventType = {
|
15017 | WC: "WillClose",
|
15018 | WS: "WillSave",
|
15019 | DS: "DidSave",
|
15020 | WP: "WillPrint",
|
15021 | DP: "DidPrint"
|
15022 | };
|
15023 | exports.DocumentActionEventType = DocumentActionEventType;
|
15024 | const PageActionEventType = {
|
15025 | O: "PageOpen",
|
15026 | C: "PageClose"
|
15027 | };
|
15028 | exports.PageActionEventType = PageActionEventType;
|
15029 | const VerbosityLevel = {
|
15030 | ERRORS: 0,
|
15031 | WARNINGS: 1,
|
15032 | INFOS: 5
|
15033 | };
|
15034 | exports.VerbosityLevel = VerbosityLevel;
|
15035 | const CMapCompressionType = {
|
15036 | NONE: 0,
|
15037 | BINARY: 1
|
15038 | };
|
15039 | exports.CMapCompressionType = CMapCompressionType;
|
15040 | const OPS = {
|
15041 | dependency: 1,
|
15042 | setLineWidth: 2,
|
15043 | setLineCap: 3,
|
15044 | setLineJoin: 4,
|
15045 | setMiterLimit: 5,
|
15046 | setDash: 6,
|
15047 | setRenderingIntent: 7,
|
15048 | setFlatness: 8,
|
15049 | setGState: 9,
|
15050 | save: 10,
|
15051 | restore: 11,
|
15052 | transform: 12,
|
15053 | moveTo: 13,
|
15054 | lineTo: 14,
|
15055 | curveTo: 15,
|
15056 | curveTo2: 16,
|
15057 | curveTo3: 17,
|
15058 | closePath: 18,
|
15059 | rectangle: 19,
|
15060 | stroke: 20,
|
15061 | closeStroke: 21,
|
15062 | fill: 22,
|
15063 | eoFill: 23,
|
15064 | fillStroke: 24,
|
15065 | eoFillStroke: 25,
|
15066 | closeFillStroke: 26,
|
15067 | closeEOFillStroke: 27,
|
15068 | endPath: 28,
|
15069 | clip: 29,
|
15070 | eoClip: 30,
|
15071 | beginText: 31,
|
15072 | endText: 32,
|
15073 | setCharSpacing: 33,
|
15074 | setWordSpacing: 34,
|
15075 | setHScale: 35,
|
15076 | setLeading: 36,
|
15077 | setFont: 37,
|
15078 | setTextRenderingMode: 38,
|
15079 | setTextRise: 39,
|
15080 | moveText: 40,
|
15081 | setLeadingMoveText: 41,
|
15082 | setTextMatrix: 42,
|
15083 | nextLine: 43,
|
15084 | showText: 44,
|
15085 | showSpacedText: 45,
|
15086 | nextLineShowText: 46,
|
15087 | nextLineSetSpacingShowText: 47,
|
15088 | setCharWidth: 48,
|
15089 | setCharWidthAndBounds: 49,
|
15090 | setStrokeColorSpace: 50,
|
15091 | setFillColorSpace: 51,
|
15092 | setStrokeColor: 52,
|
15093 | setStrokeColorN: 53,
|
15094 | setFillColor: 54,
|
15095 | setFillColorN: 55,
|
15096 | setStrokeGray: 56,
|
15097 | setFillGray: 57,
|
15098 | setStrokeRGBColor: 58,
|
15099 | setFillRGBColor: 59,
|
15100 | setStrokeCMYKColor: 60,
|
15101 | setFillCMYKColor: 61,
|
15102 | shadingFill: 62,
|
15103 | beginInlineImage: 63,
|
15104 | beginImageData: 64,
|
15105 | endInlineImage: 65,
|
15106 | paintXObject: 66,
|
15107 | markPoint: 67,
|
15108 | markPointProps: 68,
|
15109 | beginMarkedContent: 69,
|
15110 | beginMarkedContentProps: 70,
|
15111 | endMarkedContent: 71,
|
15112 | beginCompat: 72,
|
15113 | endCompat: 73,
|
15114 | paintFormXObjectBegin: 74,
|
15115 | paintFormXObjectEnd: 75,
|
15116 | beginGroup: 76,
|
15117 | endGroup: 77,
|
15118 | beginAnnotation: 80,
|
15119 | endAnnotation: 81,
|
15120 | paintImageMaskXObject: 83,
|
15121 | paintImageMaskXObjectGroup: 84,
|
15122 | paintImageXObject: 85,
|
15123 | paintInlineImageXObject: 86,
|
15124 | paintInlineImageXObjectGroup: 87,
|
15125 | paintImageXObjectRepeat: 88,
|
15126 | paintImageMaskXObjectRepeat: 89,
|
15127 | paintSolidColorImageMask: 90,
|
15128 | constructPath: 91
|
15129 | };
|
15130 | exports.OPS = OPS;
|
15131 | const UNSUPPORTED_FEATURES = {
|
15132 | forms: "forms",
|
15133 | javaScript: "javaScript",
|
15134 | signatures: "signatures",
|
15135 | smask: "smask",
|
15136 | shadingPattern: "shadingPattern",
|
15137 | errorTilingPattern: "errorTilingPattern",
|
15138 | errorExtGState: "errorExtGState",
|
15139 | errorXObject: "errorXObject",
|
15140 | errorFontLoadType3: "errorFontLoadType3",
|
15141 | errorFontState: "errorFontState",
|
15142 | errorFontMissing: "errorFontMissing",
|
15143 | errorFontTranslate: "errorFontTranslate",
|
15144 | errorColorSpace: "errorColorSpace",
|
15145 | errorOperatorList: "errorOperatorList",
|
15146 | errorFontToUnicode: "errorFontToUnicode",
|
15147 | errorFontLoadNative: "errorFontLoadNative",
|
15148 | errorFontBuildPath: "errorFontBuildPath",
|
15149 | errorFontGetPath: "errorFontGetPath",
|
15150 | errorMarkedContent: "errorMarkedContent",
|
15151 | errorContentSubStream: "errorContentSubStream"
|
15152 | };
|
15153 | exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
|
15154 | const PasswordResponses = {
|
15155 | NEED_PASSWORD: 1,
|
15156 | INCORRECT_PASSWORD: 2
|
15157 | };
|
15158 | exports.PasswordResponses = PasswordResponses;
|
15159 | let verbosity = VerbosityLevel.WARNINGS;
|
15160 | function setVerbosityLevel(level) {
|
15161 | if (Number.isInteger(level)) {
|
15162 | verbosity = level;
|
15163 | }
|
15164 | }
|
15165 | function getVerbosityLevel() {
|
15166 | return verbosity;
|
15167 | }
|
15168 | function info(msg) {
|
15169 | if (verbosity >= VerbosityLevel.INFOS) {
|
15170 | if (typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope) {
|
15171 | console.log(`Info: ${msg}`);
|
15172 | } else if (Window && Window['ngxConsole']) {
|
15173 | Window['ngxConsole'].log(`Info: ${msg}`);
|
15174 | } else {
|
15175 | console.log(`Info: ${msg}`);
|
15176 | }
|
15177 | }
|
15178 | }
|
15179 | function warn(msg) {
|
15180 | if (verbosity >= VerbosityLevel.WARNINGS) {
|
15181 | if (typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope) {
|
15182 | console.log(`Warning: ${msg}`);
|
15183 | } else if (Window && Window["ngxConsole"]) {
|
15184 | Window["ngxConsole"].log(`Warning: ${msg}`);
|
15185 | } else {
|
15186 | console.log(`Warning: ${msg}`);
|
15187 | }
|
15188 | }
|
15189 | }
|
15190 | function unreachable(msg) {
|
15191 | throw new Error(msg);
|
15192 | }
|
15193 | function assert(cond, msg) {
|
15194 | if (!cond) {
|
15195 | unreachable(msg);
|
15196 | }
|
15197 | }
|
15198 | function _isValidProtocol(url) {
|
15199 | if (!url) {
|
15200 | return false;
|
15201 | }
|
15202 | switch (url.protocol) {
|
15203 | case "http:":
|
15204 | case "https:":
|
15205 | case "ftp:":
|
15206 | case "mailto:":
|
15207 | case "tel:":
|
15208 | case "capacitor":
|
15209 | return true;
|
15210 | default:
|
15211 | return false;
|
15212 | }
|
15213 | }
|
15214 | function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
|
15215 | if (!url) {
|
15216 | return null;
|
15217 | }
|
15218 | try {
|
15219 | if (options && typeof url === "string") {
|
15220 | if (options.addDefaultProtocol && url.startsWith("www.")) {
|
15221 | const dots = url.match(/\./g);
|
15222 | if (dots && dots.length >= 2) {
|
15223 | url = `http://${url}`;
|
15224 | }
|
15225 | }
|
15226 | if (options.tryConvertEncoding) {
|
15227 | try {
|
15228 | url = stringToUTF8String(url);
|
15229 | } catch (ex) {}
|
15230 | }
|
15231 | }
|
15232 | const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
|
15233 | if (_isValidProtocol(absoluteUrl)) {
|
15234 | return absoluteUrl;
|
15235 | }
|
15236 | } catch (ex) {}
|
15237 | return null;
|
15238 | }
|
15239 | function shadow(obj, prop, value, nonSerializable = false) {
|
15240 | Object.defineProperty(obj, prop, {
|
15241 | value,
|
15242 | enumerable: !nonSerializable,
|
15243 | configurable: true,
|
15244 | writable: false
|
15245 | });
|
15246 | return value;
|
15247 | }
|
15248 | const BaseException = function BaseExceptionClosure() {
|
15249 | function BaseException(message, name) {
|
15250 | if (this.constructor === BaseException) {
|
15251 | unreachable("Cannot initialize BaseException.");
|
15252 | }
|
15253 | this.message = message;
|
15254 | this.name = name;
|
15255 | }
|
15256 | BaseException.prototype = new Error();
|
15257 | BaseException.constructor = BaseException;
|
15258 | return BaseException;
|
15259 | }();
|
15260 | exports.BaseException = BaseException;
|
15261 | class PasswordException extends BaseException {
|
15262 | constructor(msg, code) {
|
15263 | super(msg, "PasswordException");
|
15264 | this.code = code;
|
15265 | }
|
15266 | }
|
15267 | exports.PasswordException = PasswordException;
|
15268 | class UnknownErrorException extends BaseException {
|
15269 | constructor(msg, details) {
|
15270 | super(msg, "UnknownErrorException");
|
15271 | this.details = details;
|
15272 | }
|
15273 | }
|
15274 | exports.UnknownErrorException = UnknownErrorException;
|
15275 | class InvalidPDFException extends BaseException {
|
15276 | constructor(msg) {
|
15277 | super(msg, "InvalidPDFException");
|
15278 | }
|
15279 | }
|
15280 | exports.InvalidPDFException = InvalidPDFException;
|
15281 | class MissingPDFException extends BaseException {
|
15282 | constructor(msg) {
|
15283 | super(msg, "MissingPDFException");
|
15284 | }
|
15285 | }
|
15286 | exports.MissingPDFException = MissingPDFException;
|
15287 | class UnexpectedResponseException extends BaseException {
|
15288 | constructor(msg, status) {
|
15289 | super(msg, "UnexpectedResponseException");
|
15290 | this.status = status;
|
15291 | }
|
15292 | }
|
15293 | exports.UnexpectedResponseException = UnexpectedResponseException;
|
15294 | class FormatError extends BaseException {
|
15295 | constructor(msg) {
|
15296 | super(msg, "FormatError");
|
15297 | }
|
15298 | }
|
15299 | exports.FormatError = FormatError;
|
15300 | class AbortException extends BaseException {
|
15301 | constructor(msg) {
|
15302 | super(msg, "AbortException");
|
15303 | }
|
15304 | }
|
15305 | exports.AbortException = AbortException;
|
15306 | function bytesToString(bytes) {
|
15307 | if (typeof bytes !== "object" || bytes === null || bytes.length === undefined) {
|
15308 | unreachable("Invalid argument for bytesToString");
|
15309 | }
|
15310 | const length = bytes.length;
|
15311 | const MAX_ARGUMENT_COUNT = 8192;
|
15312 | if (length < MAX_ARGUMENT_COUNT) {
|
15313 | return String.fromCharCode.apply(null, bytes);
|
15314 | }
|
15315 | const strBuf = [];
|
15316 | for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
|
15317 | const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
|
15318 | const chunk = bytes.subarray(i, chunkEnd);
|
15319 | strBuf.push(String.fromCharCode.apply(null, chunk));
|
15320 | }
|
15321 | return strBuf.join("");
|
15322 | }
|
15323 | function stringToBytes(str) {
|
15324 | if (typeof str !== "string") {
|
15325 | unreachable("Invalid argument for stringToBytes");
|
15326 | }
|
15327 | const length = str.length;
|
15328 | const bytes = new Uint8Array(length);
|
15329 | for (let i = 0; i < length; ++i) {
|
15330 | bytes[i] = str.charCodeAt(i) & 0xff;
|
15331 | }
|
15332 | return bytes;
|
15333 | }
|
15334 | function string32(value) {
|
15335 | return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
|
15336 | }
|
15337 | function objectSize(obj) {
|
15338 | return Object.keys(obj).length;
|
15339 | }
|
15340 | function objectFromMap(map) {
|
15341 | const obj = Object.create(null);
|
15342 | for (const [key, value] of map) {
|
15343 | obj[key] = value;
|
15344 | }
|
15345 | return obj;
|
15346 | }
|
15347 | function isLittleEndian() {
|
15348 | const buffer8 = new Uint8Array(4);
|
15349 | buffer8[0] = 1;
|
15350 | const view32 = new Uint32Array(buffer8.buffer, 0, 1);
|
15351 | return view32[0] === 1;
|
15352 | }
|
15353 | function isEvalSupported() {
|
15354 | try {
|
15355 | new Function("");
|
15356 | return true;
|
15357 | } catch (e) {
|
15358 | return false;
|
15359 | }
|
15360 | }
|
15361 | class FeatureTest {
|
15362 | static get isLittleEndian() {
|
15363 | return shadow(this, "isLittleEndian", isLittleEndian());
|
15364 | }
|
15365 | static get isEvalSupported() {
|
15366 | return shadow(this, "isEvalSupported", isEvalSupported());
|
15367 | }
|
15368 | static get isOffscreenCanvasSupported() {
|
15369 | return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
|
15370 | }
|
15371 | static get platform() {
|
15372 | if (typeof navigator === "undefined") {
|
15373 | return shadow(this, "platform", {
|
15374 | isWin: false,
|
15375 | isMac: false
|
15376 | });
|
15377 | }
|
15378 | return shadow(this, "platform", {
|
15379 | isWin: navigator.platform.includes("Win"),
|
15380 | isMac: navigator.platform.includes("Mac")
|
15381 | });
|
15382 | }
|
15383 | }
|
15384 | exports.FeatureTest = FeatureTest;
|
15385 | const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
|
15386 | class Util {
|
15387 | static makeHexColor(r, g, b) {
|
15388 | return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
|
15389 | }
|
15390 | static scaleMinMax(transform, minMax) {
|
15391 | let temp;
|
15392 | if (transform[0]) {
|
15393 | if (transform[0] < 0) {
|
15394 | temp = minMax[0];
|
15395 | minMax[0] = minMax[1];
|
15396 | minMax[1] = temp;
|
15397 | }
|
15398 | minMax[0] *= transform[0];
|
15399 | minMax[1] *= transform[0];
|
15400 | if (transform[3] < 0) {
|
15401 | temp = minMax[2];
|
15402 | minMax[2] = minMax[3];
|
15403 | minMax[3] = temp;
|
15404 | }
|
15405 | minMax[2] *= transform[3];
|
15406 | minMax[3] *= transform[3];
|
15407 | } else {
|
15408 | temp = minMax[0];
|
15409 | minMax[0] = minMax[2];
|
15410 | minMax[2] = temp;
|
15411 | temp = minMax[1];
|
15412 | minMax[1] = minMax[3];
|
15413 | minMax[3] = temp;
|
15414 | if (transform[1] < 0) {
|
15415 | temp = minMax[2];
|
15416 | minMax[2] = minMax[3];
|
15417 | minMax[3] = temp;
|
15418 | }
|
15419 | minMax[2] *= transform[1];
|
15420 | minMax[3] *= transform[1];
|
15421 | if (transform[2] < 0) {
|
15422 | temp = minMax[0];
|
15423 | minMax[0] = minMax[1];
|
15424 | minMax[1] = temp;
|
15425 | }
|
15426 | minMax[0] *= transform[2];
|
15427 | minMax[1] *= transform[2];
|
15428 | }
|
15429 | minMax[0] += transform[4];
|
15430 | minMax[1] += transform[4];
|
15431 | minMax[2] += transform[5];
|
15432 | minMax[3] += transform[5];
|
15433 | }
|
15434 | static transform(m1, m2) {
|
15435 | return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
|
15436 | }
|
15437 | static applyTransform(p, m) {
|
15438 | const xt = p[0] * m[0] + p[1] * m[2] + m[4];
|
15439 | const yt = p[0] * m[1] + p[1] * m[3] + m[5];
|
15440 | return [xt, yt];
|
15441 | }
|
15442 | static applyInverseTransform(p, m) {
|
15443 | const d = m[0] * m[3] - m[1] * m[2];
|
15444 | const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
|
15445 | const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
|
15446 | return [xt, yt];
|
15447 | }
|
15448 | static getAxialAlignedBoundingBox(r, m) {
|
15449 | const p1 = Util.applyTransform(r, m);
|
15450 | const p2 = Util.applyTransform(r.slice(2, 4), m);
|
15451 | const p3 = Util.applyTransform([r[0], r[3]], m);
|
15452 | const p4 = Util.applyTransform([r[2], r[1]], m);
|
15453 | return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
|
15454 | }
|
15455 | static inverseTransform(m) {
|
15456 | const d = m[0] * m[3] - m[1] * m[2];
|
15457 | return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
|
15458 | }
|
15459 | static singularValueDecompose2dScale(m) {
|
15460 | const transpose = [m[0], m[2], m[1], m[3]];
|
15461 | const a = m[0] * transpose[0] + m[1] * transpose[2];
|
15462 | const b = m[0] * transpose[1] + m[1] * transpose[3];
|
15463 | const c = m[2] * transpose[0] + m[3] * transpose[2];
|
15464 | const d = m[2] * transpose[1] + m[3] * transpose[3];
|
15465 | const first = (a + d) / 2;
|
15466 | const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
|
15467 | const sx = first + second || 1;
|
15468 | const sy = first - second || 1;
|
15469 | return [Math.sqrt(sx), Math.sqrt(sy)];
|
15470 | }
|
15471 | static normalizeRect(rect) {
|
15472 | const r = rect.slice(0);
|
15473 | if (rect[0] > rect[2]) {
|
15474 | r[0] = rect[2];
|
15475 | r[2] = rect[0];
|
15476 | }
|
15477 | if (rect[1] > rect[3]) {
|
15478 | r[1] = rect[3];
|
15479 | r[3] = rect[1];
|
15480 | }
|
15481 | return r;
|
15482 | }
|
15483 | static intersect(rect1, rect2) {
|
15484 | const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
|
15485 | const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
|
15486 | if (xLow > xHigh) {
|
15487 | return null;
|
15488 | }
|
15489 | const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
|
15490 | const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
|
15491 | if (yLow > yHigh) {
|
15492 | return null;
|
15493 | }
|
15494 | return [xLow, yLow, xHigh, yHigh];
|
15495 | }
|
15496 | static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
|
15497 | const tvalues = [],
|
15498 | bounds = [[], []];
|
15499 | let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
|
15500 | for (let i = 0; i < 2; ++i) {
|
15501 | if (i === 0) {
|
15502 | b = 6 * x0 - 12 * x1 + 6 * x2;
|
15503 | a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
|
15504 | c = 3 * x1 - 3 * x0;
|
15505 | } else {
|
15506 | b = 6 * y0 - 12 * y1 + 6 * y2;
|
15507 | a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
|
15508 | c = 3 * y1 - 3 * y0;
|
15509 | }
|
15510 | if (Math.abs(a) < 1e-12) {
|
15511 | if (Math.abs(b) < 1e-12) {
|
15512 | continue;
|
15513 | }
|
15514 | t = -c / b;
|
15515 | if (0 < t && t < 1) {
|
15516 | tvalues.push(t);
|
15517 | }
|
15518 | continue;
|
15519 | }
|
15520 | b2ac = b * b - 4 * c * a;
|
15521 | sqrtb2ac = Math.sqrt(b2ac);
|
15522 | if (b2ac < 0) {
|
15523 | continue;
|
15524 | }
|
15525 | t1 = (-b + sqrtb2ac) / (2 * a);
|
15526 | if (0 < t1 && t1 < 1) {
|
15527 | tvalues.push(t1);
|
15528 | }
|
15529 | t2 = (-b - sqrtb2ac) / (2 * a);
|
15530 | if (0 < t2 && t2 < 1) {
|
15531 | tvalues.push(t2);
|
15532 | }
|
15533 | }
|
15534 | let j = tvalues.length,
|
15535 | mt;
|
15536 | const jlen = j;
|
15537 | while (j--) {
|
15538 | t = tvalues[j];
|
15539 | mt = 1 - t;
|
15540 | bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
|
15541 | bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
|
15542 | }
|
15543 | bounds[0][jlen] = x0;
|
15544 | bounds[1][jlen] = y0;
|
15545 | bounds[0][jlen + 1] = x3;
|
15546 | bounds[1][jlen + 1] = y3;
|
15547 | bounds[0].length = bounds[1].length = jlen + 2;
|
15548 | return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
|
15549 | }
|
15550 | }
|
15551 | exports.Util = Util;
|
15552 | const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac];
|
15553 | function stringToPDFString(str) {
|
15554 | if (str[0] >= "\xEF") {
|
15555 | let encoding;
|
15556 | if (str[0] === "\xFE" && str[1] === "\xFF") {
|
15557 | encoding = "utf-16be";
|
15558 | } else if (str[0] === "\xFF" && str[1] === "\xFE") {
|
15559 | encoding = "utf-16le";
|
15560 | } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
|
15561 | encoding = "utf-8";
|
15562 | }
|
15563 | if (encoding) {
|
15564 | try {
|
15565 | const decoder = new TextDecoder(encoding, {
|
15566 | fatal: true
|
15567 | });
|
15568 | const buffer = stringToBytes(str);
|
15569 | return decoder.decode(buffer);
|
15570 | } catch (ex) {
|
15571 | warn(`stringToPDFString: "${ex}".`);
|
15572 | }
|
15573 | }
|
15574 | }
|
15575 | const strBuf = [];
|
15576 | for (let i = 0, ii = str.length; i < ii; i++) {
|
15577 | const code = PDFStringTranslateTable[str.charCodeAt(i)];
|
15578 | strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
|
15579 | }
|
15580 | return strBuf.join("");
|
15581 | }
|
15582 | function stringToUTF8String(str) {
|
15583 | return decodeURIComponent(escape(str));
|
15584 | }
|
15585 | function utf8StringToString(str) {
|
15586 | return unescape(encodeURIComponent(str));
|
15587 | }
|
15588 | function isArrayBuffer(v) {
|
15589 | return typeof v === "object" && v !== null && v.byteLength !== undefined;
|
15590 | }
|
15591 | function isArrayEqual(arr1, arr2) {
|
15592 | if (arr1.length !== arr2.length) {
|
15593 | return false;
|
15594 | }
|
15595 | for (let i = 0, ii = arr1.length; i < ii; i++) {
|
15596 | if (arr1[i] !== arr2[i]) {
|
15597 | return false;
|
15598 | }
|
15599 | }
|
15600 | return true;
|
15601 | }
|
15602 | function getModificationDate(date = new Date()) {
|
15603 | const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
|
15604 | return buffer.join("");
|
15605 | }
|
15606 | function createPromiseCapability() {
|
15607 | const capability = Object.create(null);
|
15608 | let isSettled = false;
|
15609 | Object.defineProperty(capability, "settled", {
|
15610 | get() {
|
15611 | return isSettled;
|
15612 | }
|
15613 | });
|
15614 | capability.promise = new Promise(function (resolve, reject) {
|
15615 | capability.resolve = function (data) {
|
15616 | isSettled = true;
|
15617 | resolve(data);
|
15618 | };
|
15619 | capability.reject = function (reason) {
|
15620 | isSettled = true;
|
15621 | reject(reason);
|
15622 | };
|
15623 | });
|
15624 | return capability;
|
15625 | }
|
15626 |
|
15627 | }),
|
15628 |
|
15629 | ((__unused_webpack_module, exports) => {
|
15630 |
|
15631 |
|
15632 |
|
15633 | Object.defineProperty(exports, "__esModule", ({
|
15634 | value: true
|
15635 | }));
|
15636 | exports.TextHighlighter = void 0;
|
15637 | class TextHighlighter {
|
15638 | constructor({
|
15639 | findController,
|
15640 | eventBus,
|
15641 | pageIndex
|
15642 | }) {
|
15643 | this.findController = findController;
|
15644 | this.matches = [];
|
15645 | this.eventBus = eventBus;
|
15646 | this.pageIdx = pageIndex;
|
15647 | this._onUpdateTextLayerMatches = null;
|
15648 | this.textDivs = null;
|
15649 | this.textContentItemsStr = null;
|
15650 | this.enabled = false;
|
15651 | }
|
15652 | setTextMapping(divs, texts) {
|
15653 | this.textDivs = divs;
|
15654 | this.textContentItemsStr = texts;
|
15655 | }
|
15656 | enable() {
|
15657 | if (!this.textDivs || !this.textContentItemsStr) {
|
15658 | throw new Error("Text divs and strings have not been set.");
|
15659 | }
|
15660 | if (this.enabled) {
|
15661 | return;
|
15662 | }
|
15663 | this.enabled = true;
|
15664 | if (!this._onUpdateTextLayerMatches) {
|
15665 | this._onUpdateTextLayerMatches = evt => {
|
15666 | if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
|
15667 | this._updateMatches();
|
15668 | }
|
15669 | };
|
15670 | this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
|
15671 | }
|
15672 | this._updateMatches();
|
15673 | }
|
15674 | disable() {
|
15675 | if (!this.enabled) {
|
15676 | return;
|
15677 | }
|
15678 | this.enabled = false;
|
15679 | if (this._onUpdateTextLayerMatches) {
|
15680 | this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
|
15681 | this._onUpdateTextLayerMatches = null;
|
15682 | }
|
15683 | this._updateMatches(true);
|
15684 | }
|
15685 | _convertMatches(matches, matchesLength, matchesColor) {
|
15686 | if (!matches) {
|
15687 | return [];
|
15688 | }
|
15689 | const {
|
15690 | textContentItemsStr
|
15691 | } = this;
|
15692 | let i = 0,
|
15693 | iIndex = 0;
|
15694 | const end = textContentItemsStr.length - 1;
|
15695 | const result = [];
|
15696 | for (let m = 0, mm = matches.length; m < mm; m++) {
|
15697 | let matchIdx = matches[m];
|
15698 | while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
|
15699 | iIndex += textContentItemsStr[i].length;
|
15700 | i++;
|
15701 | }
|
15702 | if (i === textContentItemsStr.length) {
|
15703 | Window['ngxConsole'].error("Could not find a matching mapping");
|
15704 | }
|
15705 | const match = {
|
15706 | color: matchesColor ? matchesColor[m] : 0,
|
15707 | begin: {
|
15708 | divIdx: i,
|
15709 | offset: matchIdx - iIndex
|
15710 | }
|
15711 | };
|
15712 | matchIdx += matchesLength[m];
|
15713 | while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
|
15714 | iIndex += textContentItemsStr[i].length;
|
15715 | i++;
|
15716 | }
|
15717 | match.end = {
|
15718 | divIdx: i,
|
15719 | offset: matchIdx - iIndex
|
15720 | };
|
15721 | result.push(match);
|
15722 | }
|
15723 | return result;
|
15724 | }
|
15725 | _renderMatches(matches) {
|
15726 | if (matches.length === 0) {
|
15727 | return;
|
15728 | }
|
15729 | const {
|
15730 | findController,
|
15731 | pageIdx
|
15732 | } = this;
|
15733 | const {
|
15734 | textContentItemsStr,
|
15735 | textDivs
|
15736 | } = this;
|
15737 | const isSelectedPage = pageIdx === findController.selected.pageIdx;
|
15738 | const selectedMatchIdx = findController.selected.matchIdx;
|
15739 | const highlightAll = findController.state.highlightAll;
|
15740 | let prevEnd = null;
|
15741 | const infinity = {
|
15742 | divIdx: -1,
|
15743 | offset: undefined
|
15744 | };
|
15745 | function beginText(begin, className) {
|
15746 | const divIdx = begin.divIdx;
|
15747 | textDivs[divIdx].textContent = "";
|
15748 | return appendTextToDiv(divIdx, 0, begin.offset, className);
|
15749 | }
|
15750 | function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
|
15751 | let div = textDivs[divIdx];
|
15752 | if (div.nodeType === Node.TEXT_NODE) {
|
15753 | const span = document.createElement("span");
|
15754 | div.before(span);
|
15755 | span.append(div);
|
15756 | textDivs[divIdx] = span;
|
15757 | div = span;
|
15758 | }
|
15759 | const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
|
15760 | const node = document.createTextNode(content);
|
15761 | if (className) {
|
15762 | const span = document.createElement("span");
|
15763 | span.className = `${className} appended`;
|
15764 | span.append(node);
|
15765 | div.append(span);
|
15766 | return className.includes("selected") ? span.offsetLeft : 0;
|
15767 | }
|
15768 | div.append(node);
|
15769 | return 0;
|
15770 | }
|
15771 | let i0 = selectedMatchIdx,
|
15772 | i1 = i0 + 1;
|
15773 | if (highlightAll) {
|
15774 | i0 = 0;
|
15775 | i1 = matches.length;
|
15776 | } else if (!isSelectedPage) {
|
15777 | return;
|
15778 | }
|
15779 | for (let i = i0; i < i1; i++) {
|
15780 | const match = matches[i];
|
15781 | const begin = match.begin;
|
15782 | const end = match.end;
|
15783 | const isSelected = isSelectedPage && i === selectedMatchIdx;
|
15784 | const colorNumber = match.color % 5;
|
15785 | const highlightSuffix = (isSelected ? " selected" : "") + " color" + colorNumber;
|
15786 | let selectedLeft = 0;
|
15787 | if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
|
15788 | if (prevEnd !== null) {
|
15789 | appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
|
15790 | }
|
15791 | beginText(begin);
|
15792 | } else {
|
15793 | appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
|
15794 | }
|
15795 | if (begin.divIdx === end.divIdx) {
|
15796 | selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
|
15797 | } else {
|
15798 | selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
|
15799 | for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
|
15800 | textDivs[n0].className = "highlight middle" + highlightSuffix;
|
15801 | }
|
15802 | beginText(end, "highlight end" + highlightSuffix);
|
15803 | }
|
15804 | prevEnd = end;
|
15805 | if (isSelected) {
|
15806 | findController.scrollMatchIntoView({
|
15807 | element: textDivs[begin.divIdx],
|
15808 | selectedLeft,
|
15809 | pageIndex: pageIdx,
|
15810 | matchIndex: selectedMatchIdx
|
15811 | });
|
15812 | }
|
15813 | }
|
15814 | if (prevEnd) {
|
15815 | appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
|
15816 | }
|
15817 | }
|
15818 | _updateMatches(reset = false) {
|
15819 | if (!this.enabled && !reset) {
|
15820 | return;
|
15821 | }
|
15822 | const {
|
15823 | findController,
|
15824 | matches,
|
15825 | pageIdx
|
15826 | } = this;
|
15827 | const {
|
15828 | textContentItemsStr,
|
15829 | textDivs
|
15830 | } = this;
|
15831 | let clearedUntilDivIdx = -1;
|
15832 | for (const match of matches) {
|
15833 | const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
|
15834 | for (let n = begin, end = match.end.divIdx; n <= end; n++) {
|
15835 | const div = textDivs[n];
|
15836 | div.textContent = textContentItemsStr[n];
|
15837 | div.className = "";
|
15838 | }
|
15839 | clearedUntilDivIdx = match.end.divIdx + 1;
|
15840 | }
|
15841 | if (!findController?.highlightMatches || reset) {
|
15842 | return;
|
15843 | }
|
15844 | const pageMatches = findController.pageMatches[pageIdx] || null;
|
15845 | const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
|
15846 | const pageMatchesColor = findController.pageMatchesColor[pageIdx] || null;
|
15847 | this.matches = this._convertMatches(pageMatches, pageMatchesLength, pageMatchesColor);
|
15848 | this._renderMatches(this.matches);
|
15849 | }
|
15850 | }
|
15851 | exports.TextHighlighter = TextHighlighter;
|
15852 |
|
15853 | }),
|
15854 |
|
15855 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
15856 |
|
15857 |
|
15858 |
|
15859 | Object.defineProperty(exports, "__esModule", ({
|
15860 | value: true
|
15861 | }));
|
15862 | exports.TextLayerBuilder = void 0;
|
15863 | var _pdfjsLib = __webpack_require__(4);
|
15864 | class TextLayerBuilder {
|
15865 | #rotation = 0;
|
15866 | #scale = 0;
|
15867 | #textContentSource = null;
|
15868 | constructor({
|
15869 | highlighter = null,
|
15870 | accessibilityManager = null,
|
15871 | isOffscreenCanvasSupported = true
|
15872 | }) {
|
15873 | this.textContentItemsStr = [];
|
15874 | this.renderingDone = false;
|
15875 | this.textDivs = [];
|
15876 | this.textDivProperties = new WeakMap();
|
15877 | this.textLayerRenderTask = null;
|
15878 | this.highlighter = highlighter;
|
15879 | this.accessibilityManager = accessibilityManager;
|
15880 | this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
|
15881 | this.div = document.createElement("div");
|
15882 | this.div.className = "textLayer";
|
15883 | this.hide();
|
15884 | }
|
15885 | #finishRendering() {
|
15886 | this.renderingDone = true;
|
15887 | const endOfContent = document.createElement("div");
|
15888 | endOfContent.className = "endOfContent";
|
15889 | this.div.append(endOfContent);
|
15890 | this.#bindMouse();
|
15891 | }
|
15892 | get numTextDivs() {
|
15893 | return this.textDivs.length;
|
15894 | }
|
15895 | async render(viewport) {
|
15896 | if (!this.#textContentSource) {
|
15897 | throw new Error('No "textContentSource" parameter specified.');
|
15898 | }
|
15899 | const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
|
15900 | const {
|
15901 | rotation
|
15902 | } = viewport;
|
15903 | if (this.renderingDone) {
|
15904 | const mustRotate = rotation !== this.#rotation;
|
15905 | const mustRescale = scale !== this.#scale;
|
15906 | if (mustRotate || mustRescale) {
|
15907 | this.hide();
|
15908 | (0, _pdfjsLib.updateTextLayer)({
|
15909 | container: this.div,
|
15910 | viewport,
|
15911 | textDivs: this.textDivs,
|
15912 | textDivProperties: this.textDivProperties,
|
15913 | isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
|
15914 | mustRescale,
|
15915 | mustRotate
|
15916 | });
|
15917 | this.#scale = scale;
|
15918 | this.#rotation = rotation;
|
15919 | }
|
15920 | this.show();
|
15921 | return;
|
15922 | }
|
15923 | this.cancel();
|
15924 | this.highlighter?.setTextMapping(this.textDivs, this.textContentItemsStr);
|
15925 | this.accessibilityManager?.setTextMapping(this.textDivs);
|
15926 | this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
|
15927 | textContentSource: this.#textContentSource,
|
15928 | container: this.div,
|
15929 | viewport,
|
15930 | textDivs: this.textDivs,
|
15931 | textDivProperties: this.textDivProperties,
|
15932 | textContentItemsStr: this.textContentItemsStr,
|
15933 | isOffscreenCanvasSupported: this.isOffscreenCanvasSupported
|
15934 | });
|
15935 | await this.textLayerRenderTask.promise;
|
15936 | this.#finishRendering();
|
15937 | this.#scale = scale;
|
15938 | this.#rotation = rotation;
|
15939 | this.show();
|
15940 | this.accessibilityManager?.enable();
|
15941 | }
|
15942 | hide() {
|
15943 | if (!this.div.hidden) {
|
15944 | this.highlighter?.disable();
|
15945 | this.div.hidden = true;
|
15946 | }
|
15947 | }
|
15948 | show() {
|
15949 | if (this.div.hidden && this.renderingDone) {
|
15950 | this.div.hidden = false;
|
15951 | this.highlighter?.enable();
|
15952 | }
|
15953 | }
|
15954 | cancel() {
|
15955 | if (this.textLayerRenderTask) {
|
15956 | this.textLayerRenderTask.cancel();
|
15957 | this.textLayerRenderTask = null;
|
15958 | }
|
15959 | this.highlighter?.disable();
|
15960 | this.accessibilityManager?.disable();
|
15961 | this.textContentItemsStr.length = 0;
|
15962 | this.textDivs.length = 0;
|
15963 | this.textDivProperties = new WeakMap();
|
15964 | }
|
15965 | setTextContentSource(source) {
|
15966 | this.cancel();
|
15967 | this.#textContentSource = source;
|
15968 | }
|
15969 | #bindMouse() {
|
15970 | const {
|
15971 | div
|
15972 | } = this;
|
15973 | div.addEventListener("mousedown", evt => {
|
15974 | const end = div.querySelector(".endOfContent");
|
15975 | if (!end) {
|
15976 | return;
|
15977 | }
|
15978 | let adjustTop = evt.target !== div;
|
15979 | adjustTop &&= getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
|
15980 | if (adjustTop) {
|
15981 | const divBounds = div.getBoundingClientRect();
|
15982 | const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
|
15983 | end.style.top = (r * 100).toFixed(2) + "%";
|
15984 | }
|
15985 | end.classList.add("active");
|
15986 | });
|
15987 | div.addEventListener("mouseup", () => {
|
15988 | const end = div.querySelector(".endOfContent");
|
15989 | if (!end) {
|
15990 | return;
|
15991 | }
|
15992 | end.style.top = "";
|
15993 | end.classList.remove("active");
|
15994 | });
|
15995 | }
|
15996 | }
|
15997 | exports.TextLayerBuilder = TextLayerBuilder;
|
15998 |
|
15999 | }),
|
16000 |
|
16001 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
16002 |
|
16003 |
|
16004 |
|
16005 | Object.defineProperty(exports, "__esModule", ({
|
16006 | value: true
|
16007 | }));
|
16008 | exports.XfaLayerBuilder = void 0;
|
16009 | var _pdfjsLib = __webpack_require__(4);
|
16010 | class XfaLayerBuilder {
|
16011 | constructor({
|
16012 | pageDiv,
|
16013 | pdfPage,
|
16014 | annotationStorage = null,
|
16015 | linkService,
|
16016 | xfaHtml = null
|
16017 | }) {
|
16018 | this.pageDiv = pageDiv;
|
16019 | this.pdfPage = pdfPage;
|
16020 | this.annotationStorage = annotationStorage;
|
16021 | this.linkService = linkService;
|
16022 | this.xfaHtml = xfaHtml;
|
16023 | this.div = null;
|
16024 | this._cancelled = false;
|
16025 | }
|
16026 | async render(viewport, intent = "display") {
|
16027 | if (intent === "print") {
|
16028 | const parameters = {
|
16029 | viewport: viewport.clone({
|
16030 | dontFlip: true
|
16031 | }),
|
16032 | div: this.div,
|
16033 | xfaHtml: this.xfaHtml,
|
16034 | annotationStorage: this.annotationStorage,
|
16035 | linkService: this.linkService,
|
16036 | intent
|
16037 | };
|
16038 | const div = document.createElement("div");
|
16039 | this.pageDiv.append(div);
|
16040 | parameters.div = div;
|
16041 | return _pdfjsLib.XfaLayer.render(parameters);
|
16042 | }
|
16043 | const xfaHtml = await this.pdfPage.getXfa();
|
16044 | if (this._cancelled || !xfaHtml) {
|
16045 | return {
|
16046 | textDivs: []
|
16047 | };
|
16048 | }
|
16049 | const parameters = {
|
16050 | viewport: viewport.clone({
|
16051 | dontFlip: true
|
16052 | }),
|
16053 | div: this.div,
|
16054 | xfaHtml,
|
16055 | annotationStorage: this.annotationStorage,
|
16056 | linkService: this.linkService,
|
16057 | intent
|
16058 | };
|
16059 | if (this.div) {
|
16060 | return _pdfjsLib.XfaLayer.update(parameters);
|
16061 | }
|
16062 | this.div = document.createElement("div");
|
16063 | this.pageDiv.append(this.div);
|
16064 | parameters.div = this.div;
|
16065 | return _pdfjsLib.XfaLayer.render(parameters);
|
16066 | }
|
16067 | cancel() {
|
16068 | this._cancelled = true;
|
16069 | }
|
16070 | hide() {
|
16071 | if (!this.div) {
|
16072 | return;
|
16073 | }
|
16074 | this.div.hidden = true;
|
16075 | }
|
16076 | }
|
16077 | exports.XfaLayerBuilder = XfaLayerBuilder;
|
16078 |
|
16079 | }),
|
16080 |
|
16081 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
16082 |
|
16083 |
|
16084 |
|
16085 | Object.defineProperty(exports, "__esModule", ({
|
16086 | value: true
|
16087 | }));
|
16088 | exports.SecondaryToolbar = void 0;
|
16089 | var _ui_utils = __webpack_require__(3);
|
16090 | var _pdf_viewer = __webpack_require__(31);
|
16091 | class SecondaryToolbar {
|
16092 | constructor(options, eventBus, externalServices) {
|
16093 | this.toolbar = options.toolbar;
|
16094 | this.toggleButton = options.toggleButton;
|
16095 | this.buttons = [{
|
16096 | element: options.presentationModeButton,
|
16097 | eventName: "presentationmode",
|
16098 | close: true
|
16099 | }, {
|
16100 | element: options.printButton,
|
16101 | eventName: "print",
|
16102 | close: true
|
16103 | }, {
|
16104 | element: options.downloadButton,
|
16105 | eventName: "download",
|
16106 | close: true
|
16107 | }, {
|
16108 | element: options.viewBookmarkButton,
|
16109 | eventName: null,
|
16110 | close: true
|
16111 | }, {
|
16112 | element: options.firstPageButton,
|
16113 | eventName: "firstpage",
|
16114 | close: true
|
16115 | }, {
|
16116 | element: options.lastPageButton,
|
16117 | eventName: "lastpage",
|
16118 | close: true
|
16119 | }, {
|
16120 | element: options.pageRotateCwButton,
|
16121 | eventName: "rotatecw",
|
16122 | close: false
|
16123 | }, {
|
16124 | element: options.pageRotateCcwButton,
|
16125 | eventName: "rotateccw",
|
16126 | close: false
|
16127 | }, {
|
16128 | element: options.cursorSelectToolButton,
|
16129 | eventName: "switchcursortool",
|
16130 | eventDetails: {
|
16131 | tool: _ui_utils.CursorTool.SELECT
|
16132 | },
|
16133 | close: true
|
16134 | }, {
|
16135 | element: options.cursorHandToolButton,
|
16136 | eventName: "switchcursortool",
|
16137 | eventDetails: {
|
16138 | tool: _ui_utils.CursorTool.HAND
|
16139 | },
|
16140 | close: true
|
16141 | }, {
|
16142 | element: options.scrollPageButton,
|
16143 | eventName: "switchscrollmode",
|
16144 | eventDetails: {
|
16145 | mode: _ui_utils.ScrollMode.PAGE
|
16146 | },
|
16147 | close: true
|
16148 | }, {
|
16149 | element: options.scrollVerticalButton,
|
16150 | eventName: "switchscrollmode",
|
16151 | eventDetails: {
|
16152 | mode: _ui_utils.ScrollMode.VERTICAL
|
16153 | },
|
16154 | close: true
|
16155 | }, {
|
16156 | element: options.scrollHorizontalButton,
|
16157 | eventName: "switchscrollmode",
|
16158 | eventDetails: {
|
16159 | mode: _ui_utils.ScrollMode.HORIZONTAL
|
16160 | },
|
16161 | close: true
|
16162 | }, {
|
16163 | element: options.scrollWrappedButton,
|
16164 | eventName: "switchscrollmode",
|
16165 | eventDetails: {
|
16166 | mode: _ui_utils.ScrollMode.WRAPPED
|
16167 | },
|
16168 | close: true
|
16169 | }, {
|
16170 | element: options.spreadNoneButton,
|
16171 | eventName: "switchspreadmode",
|
16172 | eventDetails: {
|
16173 | mode: _ui_utils.SpreadMode.NONE
|
16174 | },
|
16175 | close: true
|
16176 | }, {
|
16177 | element: options.spreadOddButton,
|
16178 | eventName: "switchspreadmode",
|
16179 | eventDetails: {
|
16180 | mode: _ui_utils.SpreadMode.ODD
|
16181 | },
|
16182 | close: true
|
16183 | }, {
|
16184 | element: options.spreadEvenButton,
|
16185 | eventName: "switchspreadmode",
|
16186 | eventDetails: {
|
16187 | mode: _ui_utils.SpreadMode.EVEN
|
16188 | },
|
16189 | close: true
|
16190 | }, {
|
16191 | element: options.documentPropertiesButton,
|
16192 | eventName: "documentproperties",
|
16193 | close: true
|
16194 | }];
|
16195 | this.buttons.push({
|
16196 | element: options.openFileButton,
|
16197 | eventName: "openfile",
|
16198 | close: true
|
16199 | });
|
16200 | this.items = {
|
16201 | firstPage: options.firstPageButton,
|
16202 | lastPage: options.lastPageButton,
|
16203 | pageRotateCw: options.pageRotateCwButton,
|
16204 | pageRotateCcw: options.pageRotateCcwButton
|
16205 | };
|
16206 | this.eventBus = eventBus;
|
16207 | this.externalServices = externalServices;
|
16208 | this.opened = false;
|
16209 | this.#bindClickListeners();
|
16210 | this.#bindCursorToolsListener(options);
|
16211 | this.#bindScrollModeListener(options);
|
16212 | this.#bindSpreadModeListener(options);
|
16213 | this.reset();
|
16214 | }
|
16215 | get isOpen() {
|
16216 | return this.opened;
|
16217 | }
|
16218 | setPageNumber(pageNumber) {
|
16219 | this.pageNumber = pageNumber;
|
16220 | this.#updateUIState();
|
16221 | }
|
16222 | setPagesCount(pagesCount) {
|
16223 | this.pagesCount = pagesCount;
|
16224 | this.#updateUIState();
|
16225 | }
|
16226 | reset() {
|
16227 | this.pageNumber = 0;
|
16228 | this.pagesCount = 0;
|
16229 | this.#updateUIState();
|
16230 | this.eventBus.dispatch("secondarytoolbarreset", {
|
16231 | source: this
|
16232 | });
|
16233 | }
|
16234 | #updateUIState() {
|
16235 | this.items.firstPage.disabled = this.pageNumber <= 1;
|
16236 | if (document.getElementById("previousPage")) {
|
16237 | document.getElementById("previousPage").disabled = this.pageNumber <= 1;
|
16238 | }
|
16239 | this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
|
16240 | if (document.getElementById("nextPage")) {
|
16241 | document.getElementById("nextPage").disabled = this.pageNumber >= this.pagesCount;
|
16242 | }
|
16243 | this.items.pageRotateCw.disabled = this.pagesCount === 0;
|
16244 | this.items.pageRotateCcw.disabled = this.pagesCount === 0;
|
16245 | this.eventBus.dispatch("updateuistate", {
|
16246 | source: this,
|
16247 | widget: "SecondaryToolbar",
|
16248 | pageNumber: this.pageNumber,
|
16249 | pagesCount: this.pagesCount
|
16250 | });
|
16251 | }
|
16252 | #bindClickListeners() {
|
16253 | this.toggleButton.addEventListener("click", this.toggle.bind(this));
|
16254 | for (const {
|
16255 | element,
|
16256 | eventName,
|
16257 | close,
|
16258 | eventDetails
|
16259 | } of this.buttons) {
|
16260 | element?.addEventListener("click", evt => {
|
16261 | if (eventName !== null) {
|
16262 | const details = {
|
16263 | source: this
|
16264 | };
|
16265 | for (const property in eventDetails) {
|
16266 | details[property] = eventDetails[property];
|
16267 | }
|
16268 | this.eventBus.dispatch(eventName, details);
|
16269 | }
|
16270 | if (close) {
|
16271 | this.close();
|
16272 | }
|
16273 | this.externalServices.reportTelemetry({
|
16274 | type: "buttons",
|
16275 | data: {
|
16276 | id: element.id
|
16277 | }
|
16278 | });
|
16279 | });
|
16280 | }
|
16281 | }
|
16282 | #bindCursorToolsListener({
|
16283 | cursorSelectToolButton,
|
16284 | cursorHandToolButton
|
16285 | }) {
|
16286 | this.eventBus._on("cursortoolchanged", function ({
|
16287 | tool
|
16288 | }) {
|
16289 | const isSelect = tool === _ui_utils.CursorTool.SELECT,
|
16290 | isHand = tool === _ui_utils.CursorTool.HAND;
|
16291 | cursorSelectToolButton.classList.toggle("toggled", isSelect);
|
16292 | cursorHandToolButton.classList.toggle("toggled", isHand);
|
16293 | cursorSelectToolButton.setAttribute("aria-checked", isSelect);
|
16294 | cursorHandToolButton.setAttribute("aria-checked", isHand);
|
16295 | });
|
16296 | }
|
16297 | #bindScrollModeListener({
|
16298 | scrollPageButton,
|
16299 | scrollVerticalButton,
|
16300 | scrollHorizontalButton,
|
16301 | scrollWrappedButton,
|
16302 | spreadNoneButton,
|
16303 | spreadOddButton,
|
16304 | spreadEvenButton
|
16305 | }) {
|
16306 | const scrollModeChanged = ({
|
16307 | mode
|
16308 | }) => {
|
16309 | const isPage = mode === _ui_utils.ScrollMode.PAGE,
|
16310 | isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
|
16311 | isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
|
16312 | isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
|
16313 | scrollPageButton.classList.toggle("toggled", isPage);
|
16314 | scrollVerticalButton.classList.toggle("toggled", isVertical);
|
16315 | scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
|
16316 | scrollWrappedButton.classList.toggle("toggled", isWrapped);
|
16317 | scrollPageButton.setAttribute("aria-checked", isPage);
|
16318 | scrollVerticalButton.setAttribute("aria-checked", isVertical);
|
16319 | scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
|
16320 | scrollWrappedButton.setAttribute("aria-checked", isWrapped);
|
16321 | const forceScrollModePage = this.pagesCount > _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
|
16322 | scrollPageButton.disabled = forceScrollModePage;
|
16323 | scrollVerticalButton.disabled = forceScrollModePage;
|
16324 | scrollHorizontalButton.disabled = forceScrollModePage;
|
16325 | scrollWrappedButton.disabled = forceScrollModePage;
|
16326 | spreadNoneButton.disabled = isHorizontal;
|
16327 | spreadOddButton.disabled = isHorizontal;
|
16328 | spreadEvenButton.disabled = isHorizontal;
|
16329 | };
|
16330 | this.eventBus._on("scrollmodechanged", scrollModeChanged);
|
16331 | this.eventBus._on("secondarytoolbarreset", evt => {
|
16332 | if (evt.source === this) {
|
16333 | scrollModeChanged({
|
16334 | mode: _ui_utils.ScrollMode.VERTICAL
|
16335 | });
|
16336 | }
|
16337 | });
|
16338 | }
|
16339 | #bindSpreadModeListener({
|
16340 | spreadNoneButton,
|
16341 | spreadOddButton,
|
16342 | spreadEvenButton
|
16343 | }) {
|
16344 | function spreadModeChanged({
|
16345 | mode
|
16346 | }) {
|
16347 | const isNone = mode === _ui_utils.SpreadMode.NONE,
|
16348 | isOdd = mode === _ui_utils.SpreadMode.ODD,
|
16349 | isEven = mode === _ui_utils.SpreadMode.EVEN;
|
16350 | spreadNoneButton.classList.toggle("toggled", isNone);
|
16351 | spreadOddButton.classList.toggle("toggled", isOdd);
|
16352 | spreadEvenButton.classList.toggle("toggled", isEven);
|
16353 | spreadNoneButton.setAttribute("aria-checked", isNone);
|
16354 | spreadOddButton.setAttribute("aria-checked", isOdd);
|
16355 | spreadEvenButton.setAttribute("aria-checked", isEven);
|
16356 | }
|
16357 | this.eventBus._on("spreadmodechanged", spreadModeChanged);
|
16358 | this.eventBus._on("secondarytoolbarreset", evt => {
|
16359 | if (evt.source === this) {
|
16360 | spreadModeChanged({
|
16361 | mode: _ui_utils.SpreadMode.NONE
|
16362 | });
|
16363 | }
|
16364 | });
|
16365 | }
|
16366 | open() {
|
16367 | if (this.opened) {
|
16368 | return;
|
16369 | }
|
16370 | this.opened = true;
|
16371 | this.toggleButton.classList.add("toggled");
|
16372 | this.toggleButton.setAttribute("aria-expanded", "true");
|
16373 | this.toolbar.classList.remove("hidden");
|
16374 | }
|
16375 | close() {
|
16376 | if (!this.opened) {
|
16377 | return;
|
16378 | }
|
16379 | this.opened = false;
|
16380 | this.toolbar.classList.add("hidden");
|
16381 | this.toggleButton.classList.remove("toggled");
|
16382 | this.toggleButton.setAttribute("aria-expanded", "false");
|
16383 | }
|
16384 | toggle() {
|
16385 | if (this.opened) {
|
16386 | this.close();
|
16387 | } else {
|
16388 | this.open();
|
16389 | }
|
16390 | }
|
16391 | }
|
16392 | exports.SecondaryToolbar = SecondaryToolbar;
|
16393 |
|
16394 | }),
|
16395 |
|
16396 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
16397 |
|
16398 |
|
16399 |
|
16400 | Object.defineProperty(exports, "__esModule", ({
|
16401 | value: true
|
16402 | }));
|
16403 | exports.Toolbar = void 0;
|
16404 | var _ui_utils = __webpack_require__(3);
|
16405 | var _pdfjsLib = __webpack_require__(4);
|
16406 | const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
|
16407 | class Toolbar {
|
16408 | #wasLocalized = false;
|
16409 | constructor(options, eventBus, l10n) {
|
16410 | this.toolbar = options.container;
|
16411 | this.eventBus = eventBus;
|
16412 | this.l10n = l10n;
|
16413 | this.buttons = [{
|
16414 | element: options.previous,
|
16415 | eventName: "previouspage"
|
16416 | }, {
|
16417 | element: options.next,
|
16418 | eventName: "nextpage"
|
16419 | }, {
|
16420 | element: options.zoomIn,
|
16421 | eventName: "zoomin"
|
16422 | }, {
|
16423 | element: options.zoomOut,
|
16424 | eventName: "zoomout"
|
16425 | }, {
|
16426 | element: options.print,
|
16427 | eventName: "print"
|
16428 | }, {
|
16429 | element: options.download,
|
16430 | eventName: "download"
|
16431 | }, {
|
16432 | element: options.editorFreeTextButton,
|
16433 | eventName: "switchannotationeditormode",
|
16434 | eventDetails: {
|
16435 | get mode() {
|
16436 | const {
|
16437 | classList
|
16438 | } = options.editorFreeTextButton;
|
16439 | return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.FREETEXT;
|
16440 | }
|
16441 | }
|
16442 | }, {
|
16443 | element: options.editorInkButton,
|
16444 | eventName: "switchannotationeditormode",
|
16445 | eventDetails: {
|
16446 | get mode() {
|
16447 | const {
|
16448 | classList
|
16449 | } = options.editorInkButton;
|
16450 | return classList.contains("toggled") ? _pdfjsLib.AnnotationEditorType.NONE : _pdfjsLib.AnnotationEditorType.INK;
|
16451 | }
|
16452 | }
|
16453 | }];
|
16454 | this.buttons.push({
|
16455 | element: options.openFile,
|
16456 | eventName: "openfile"
|
16457 | });
|
16458 | this.items = {
|
16459 | numPages: options.numPages,
|
16460 | pageNumber: options.pageNumber,
|
16461 | scaleSelect: options.scaleSelect,
|
16462 | customScaleOption: options.customScaleOption,
|
16463 | previous: options.previous,
|
16464 | next: options.next,
|
16465 | zoomIn: options.zoomIn,
|
16466 | zoomOut: options.zoomOut
|
16467 | };
|
16468 | this.#bindListeners(options);
|
16469 | this.reset();
|
16470 | }
|
16471 | setPageNumber(pageNumber, pageLabel) {
|
16472 | this.pageNumber = pageNumber;
|
16473 | this.pageLabel = pageLabel;
|
16474 | this.#updateUIState(false);
|
16475 | }
|
16476 | setPagesCount(pagesCount, hasPageLabels) {
|
16477 | this.pagesCount = pagesCount;
|
16478 | this.hasPageLabels = hasPageLabels;
|
16479 | this.#updateUIState(true);
|
16480 | }
|
16481 | setPageScale(pageScaleValue, pageScale) {
|
16482 | this.pageScaleValue = (pageScaleValue || pageScale).toString();
|
16483 | this.pageScale = pageScale;
|
16484 | this.#updateUIState(false);
|
16485 | }
|
16486 | reset() {
|
16487 | this.pageNumber = 0;
|
16488 | this.pageLabel = null;
|
16489 | this.hasPageLabels = false;
|
16490 | this.pagesCount = 0;
|
16491 | const defaultZoomOption = PDFViewerApplicationOptions.get('defaultZoomValue');
|
16492 | if (defaultZoomOption) {
|
16493 | this.pageScaleValue = defaultZoomOption;
|
16494 | if (!!Number(defaultZoomOption)) {
|
16495 | this.pageScale = Number(defaultZoomOption);
|
16496 | }
|
16497 | } else {
|
16498 | this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
16499 | this.pageScale = _ui_utils.DEFAULT_SCALE;
|
16500 | }
|
16501 | this.#updateUIState(true);
|
16502 | this.updateLoadingIndicatorState();
|
16503 | this.eventBus.dispatch("toolbarreset", {
|
16504 | source: this
|
16505 | });
|
16506 | }
|
16507 | #bindListeners(options) {
|
16508 | const {
|
16509 | pageNumber,
|
16510 | scaleSelect
|
16511 | } = this.items;
|
16512 | const self = this;
|
16513 | for (const {
|
16514 | element,
|
16515 | eventName,
|
16516 | eventDetails
|
16517 | } of this.buttons) {
|
16518 | element?.addEventListener("click", evt => {
|
16519 | if (eventName !== null) {
|
16520 | const details = {
|
16521 | source: this
|
16522 | };
|
16523 | if (eventDetails) {
|
16524 | for (const property in eventDetails) {
|
16525 | details[property] = eventDetails[property];
|
16526 | }
|
16527 | }
|
16528 | this.eventBus.dispatch(eventName, details);
|
16529 | }
|
16530 | });
|
16531 | }
|
16532 | pageNumber.addEventListener("click", function () {
|
16533 | this.select();
|
16534 | });
|
16535 | pageNumber.addEventListener("change", function () {
|
16536 | self.eventBus.dispatch("pagenumberchanged", {
|
16537 | source: self,
|
16538 | value: this.value
|
16539 | });
|
16540 | });
|
16541 | scaleSelect.addEventListener("change", function () {
|
16542 | if (this.value === "custom") {
|
16543 | return;
|
16544 | }
|
16545 | self.eventBus.dispatch("scalechanged", {
|
16546 | source: self,
|
16547 | value: this.value
|
16548 | });
|
16549 | });
|
16550 | scaleSelect.addEventListener("click", function (evt) {
|
16551 | const target = evt.target;
|
16552 | if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
|
16553 | this.blur();
|
16554 | }
|
16555 | });
|
16556 | scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
|
16557 | this.eventBus._on("localized", () => {
|
16558 | this.#wasLocalized = true;
|
16559 | this.#adjustScaleWidth();
|
16560 | this.#updateUIState(true);
|
16561 | });
|
16562 | this.#bindEditorToolsListener(options);
|
16563 | }
|
16564 | #bindEditorToolsListener({
|
16565 | editorFreeTextButton,
|
16566 | editorFreeTextParamsToolbar,
|
16567 | editorInkButton,
|
16568 | editorInkParamsToolbar
|
16569 | }) {
|
16570 | const editorModeChanged = (evt, disableButtons = false) => {
|
16571 | const editorButtons = [{
|
16572 | mode: _pdfjsLib.AnnotationEditorType.FREETEXT,
|
16573 | button: editorFreeTextButton,
|
16574 | toolbar: editorFreeTextParamsToolbar
|
16575 | }, {
|
16576 | mode: _pdfjsLib.AnnotationEditorType.INK,
|
16577 | button: editorInkButton,
|
16578 | toolbar: editorInkParamsToolbar
|
16579 | }];
|
16580 | for (const {
|
16581 | mode,
|
16582 | button,
|
16583 | toolbar
|
16584 | } of editorButtons) {
|
16585 | const checked = mode === evt.mode;
|
16586 | button.classList.toggle("toggled", checked);
|
16587 | button.setAttribute("aria-checked", checked);
|
16588 | button.disabled = disableButtons;
|
16589 | toolbar?.classList.toggle("hidden", !checked);
|
16590 | }
|
16591 | };
|
16592 | this.eventBus._on("annotationeditormodechanged", editorModeChanged);
|
16593 | this.eventBus._on("toolbarreset", evt => {
|
16594 | if (evt.source === this) {
|
16595 | editorModeChanged({
|
16596 | mode: _pdfjsLib.AnnotationEditorType.NONE
|
16597 | }, true);
|
16598 | }
|
16599 | });
|
16600 | }
|
16601 | #updateUIState(resetNumPages = false) {
|
16602 | if (!this.#wasLocalized) {
|
16603 | return;
|
16604 | }
|
16605 | const {
|
16606 | pageNumber,
|
16607 | pagesCount,
|
16608 | pageScaleValue,
|
16609 | pageScale,
|
16610 | items
|
16611 | } = this;
|
16612 | if (resetNumPages) {
|
16613 | if (this.hasPageLabels) {
|
16614 | items.pageNumber.type = "text";
|
16615 | } else {
|
16616 | items.pageNumber.type = "number";
|
16617 | this.l10n.get("of_pages", {
|
16618 | pagesCount
|
16619 | }).then(msg => {
|
16620 | items.numPages.textContent = msg;
|
16621 | });
|
16622 | }
|
16623 | items.pageNumber.max = pagesCount;
|
16624 | }
|
16625 | if (this.hasPageLabels) {
|
16626 | items.pageNumber.value = this.pageLabel;
|
16627 | this.l10n.get("page_of_pages", {
|
16628 | pageNumber,
|
16629 | pagesCount
|
16630 | }).then(msg => {
|
16631 | items.numPages.textContent = msg;
|
16632 | });
|
16633 | } else {
|
16634 | items.pageNumber.value = pageNumber;
|
16635 | }
|
16636 | items.previous.disabled = pageNumber <= 1;
|
16637 | items.next.disabled = pageNumber >= pagesCount;
|
16638 | items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
|
16639 | items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
|
16640 | this.l10n.get("page_scale_percent", {
|
16641 | scale: Math.round(pageScale * 10000) / 100
|
16642 | }).then(msg => {
|
16643 | let predefinedValueFound = false;
|
16644 | if (items.scaleSelect.options) {
|
16645 | for (const option of items.scaleSelect.options) {
|
16646 | if (option.value !== pageScaleValue) {
|
16647 | option.selected = false;
|
16648 | continue;
|
16649 | }
|
16650 | option.selected = true;
|
16651 | predefinedValueFound = true;
|
16652 | }
|
16653 | }
|
16654 | if (!predefinedValueFound) {
|
16655 | items.customScaleOption.textContent = msg;
|
16656 | items.customScaleOption.selected = true;
|
16657 | }
|
16658 | });
|
16659 | this.eventBus.dispatch("updateuistate", {
|
16660 | source: this,
|
16661 | widget: "Toolbar",
|
16662 | pageNumber,
|
16663 | pagesCount,
|
16664 | pageScaleValue,
|
16665 | pageScale
|
16666 | });
|
16667 | }
|
16668 | updateLoadingIndicatorState(loading = false) {
|
16669 | const {
|
16670 | pageNumber
|
16671 | } = this.items;
|
16672 | pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
|
16673 | }
|
16674 | async #adjustScaleWidth() {
|
16675 | const {
|
16676 | items,
|
16677 | l10n
|
16678 | } = this;
|
16679 | const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
|
16680 | await _ui_utils.animationStarted;
|
16681 | const style = getComputedStyle(items.scaleSelect);
|
16682 | const scaleSelectWidth = parseFloat(style.getPropertyValue("--scale-select-width"));
|
16683 | const canvas = document.createElement("canvas");
|
16684 | const options = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {
|
16685 | willReadFrequently: true,
|
16686 | alpha: false
|
16687 | } : {
|
16688 | alpha: false
|
16689 | };
|
16690 | const ctx = canvas.getContext("2d", options);
|
16691 | ctx.font = `${style.fontSize} ${style.fontFamily}`;
|
16692 | let maxWidth = 0;
|
16693 | for (const predefinedValue of await predefinedValuesPromise) {
|
16694 | try {
|
16695 | const {
|
16696 | width
|
16697 | } = ctx.measureText(predefinedValue);
|
16698 | if (width > maxWidth) {
|
16699 | maxWidth = width;
|
16700 | }
|
16701 | } catch (fingerprintIsBlockedException) {}
|
16702 | }
|
16703 | maxWidth += 0.3 * scaleSelectWidth;
|
16704 | if (maxWidth > scaleSelectWidth) {
|
16705 | const container = items.scaleSelect.parentNode;
|
16706 | container.style.setProperty("--scale-select-width", `${maxWidth}px`);
|
16707 | }
|
16708 | canvas.width = 0;
|
16709 | canvas.height = 0;
|
16710 | }
|
16711 | }
|
16712 | exports.Toolbar = Toolbar;
|
16713 |
|
16714 | }),
|
16715 |
|
16716 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
16717 |
|
16718 |
|
16719 |
|
16720 | Object.defineProperty(exports, "__esModule", ({
|
16721 | value: true
|
16722 | }));
|
16723 | exports.ViewHistory = void 0;
|
16724 | var _app_options = __webpack_require__(5);
|
16725 | const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
|
16726 | class ViewHistory {
|
16727 | constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
|
16728 | this.fingerprint = fingerprint;
|
16729 | this.cacheSize = cacheSize;
|
16730 | this._initializedPromise = this._readFromStorage().then(databaseStr => {
|
16731 | const database = JSON.parse(databaseStr || "{}");
|
16732 | let index = -1;
|
16733 | if (!Array.isArray(database.files)) {
|
16734 | database.files = [];
|
16735 | } else {
|
16736 | while (database.files.length >= this.cacheSize) {
|
16737 | database.files.shift();
|
16738 | }
|
16739 | for (let i = 0, ii = database.files.length; i < ii; i++) {
|
16740 | const branch = database.files[i];
|
16741 | if (branch.fingerprint === this.fingerprint) {
|
16742 | index = i;
|
16743 | break;
|
16744 | }
|
16745 | }
|
16746 | }
|
16747 | if (index === -1) {
|
16748 | index = database.files.push({
|
16749 | fingerprint: this.fingerprint
|
16750 | }) - 1;
|
16751 | }
|
16752 | this.file = database.files[index];
|
16753 | this.database = database;
|
16754 | });
|
16755 | }
|
16756 | async _writeToStorage() {
|
16757 | if (_app_options.AppOptions.get("disableHistory")) {
|
16758 | return;
|
16759 | }
|
16760 | const databaseStr = JSON.stringify(this.database);
|
16761 | try {
|
16762 | localStorage.setItem("pdfjs.history", databaseStr);
|
16763 | } catch (safariSecurityException) {}
|
16764 | }
|
16765 | async _readFromStorage() {
|
16766 | if (_app_options.AppOptions.get("disableHistory")) {
|
16767 | return undefined;
|
16768 | }
|
16769 | try {
|
16770 | return localStorage.getItem("pdfjs.history");
|
16771 | } catch (safariSecurityException) {
|
16772 | return undefined;
|
16773 | }
|
16774 | }
|
16775 | async set(name, val) {
|
16776 | await this._initializedPromise;
|
16777 | this.file[name] = val;
|
16778 | return this._writeToStorage();
|
16779 | }
|
16780 | async setMultiple(properties) {
|
16781 | await this._initializedPromise;
|
16782 | for (const name in properties) {
|
16783 | this.file[name] = properties[name];
|
16784 | }
|
16785 | return this._writeToStorage();
|
16786 | }
|
16787 | async get(name, defaultValue) {
|
16788 | await this._initializedPromise;
|
16789 | const val = this.file[name];
|
16790 | return val !== undefined ? val : defaultValue;
|
16791 | }
|
16792 | async getMultiple(properties) {
|
16793 | await this._initializedPromise;
|
16794 | const values = Object.create(null);
|
16795 | for (const name in properties) {
|
16796 | const val = this.file[name];
|
16797 | values[name] = val !== undefined ? val : properties[name];
|
16798 | }
|
16799 | return values;
|
16800 | }
|
16801 | }
|
16802 | exports.ViewHistory = ViewHistory;
|
16803 |
|
16804 | }),
|
16805 |
|
16806 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
16807 |
|
16808 |
|
16809 |
|
16810 | Object.defineProperty(exports, "__esModule", ({
|
16811 | value: true
|
16812 | }));
|
16813 | exports.BasePreferences = void 0;
|
16814 | var _app_options = __webpack_require__(5);
|
16815 | class BasePreferences {
|
16816 | #defaults = Object.freeze({
|
16817 | "annotationEditorMode": 0,
|
16818 | "annotationMode": 2,
|
16819 | "cursorToolOnLoad": 0,
|
16820 | "defaultZoomDelay": 400,
|
16821 | "defaultZoomValue": "",
|
16822 | "disablePageLabels": false,
|
16823 | "enablePermissions": false,
|
16824 | "enablePrintAutoRotate": true,
|
16825 | "enableScripting": true,
|
16826 | "externalLinkTarget": 0,
|
16827 | "historyUpdateUrl": false,
|
16828 | "ignoreDestinationZoom": false,
|
16829 | "forcePageColors": false,
|
16830 | "pageColorsBackground": "Canvas",
|
16831 | "pageColorsForeground": "CanvasText",
|
16832 | "pdfBugEnabled": false,
|
16833 | "removePageBorders": false,
|
16834 | "sidebarViewOnLoad": -1,
|
16835 | "scrollModeOnLoad": -1,
|
16836 | "spreadModeOnLoad": -1,
|
16837 | "textLayerMode": 1,
|
16838 | "useOnlyCssZoom": false,
|
16839 | "viewerCssTheme": 0,
|
16840 | "viewOnLoad": 0,
|
16841 | "disableAutoFetch": false,
|
16842 | "disableFontFace": false,
|
16843 | "disableRange": false,
|
16844 | "disableStream": false,
|
16845 | "enableXfa": true,
|
16846 | "renderer": "canvas"
|
16847 | });
|
16848 | #prefs = Object.create(null);
|
16849 | #initializedPromise = null;
|
16850 | constructor() {
|
16851 | if (this.constructor === BasePreferences) {
|
16852 | throw new Error("Cannot initialize BasePreferences.");
|
16853 | }
|
16854 | this.#initializedPromise = this._readFromStorage(this.#defaults).then(prefs => {
|
16855 | for (const name in this.#defaults) {
|
16856 | const prefValue = prefs?.[name];
|
16857 | if (typeof prefValue === typeof this.#defaults[name]) {
|
16858 | this.#prefs[name] = prefValue;
|
16859 | }
|
16860 | }
|
16861 | });
|
16862 | }
|
16863 | async _writeToStorage(prefObj) {
|
16864 | throw new Error("Not implemented: _writeToStorage");
|
16865 | }
|
16866 | async _readFromStorage(prefObj) {
|
16867 | throw new Error("Not implemented: _readFromStorage");
|
16868 | }
|
16869 | async reset() {
|
16870 | await this.#initializedPromise;
|
16871 | const prefs = this.#prefs;
|
16872 | this.#prefs = Object.create(null);
|
16873 | return this._writeToStorage(this.#defaults).catch(reason => {
|
16874 | this.#prefs = prefs;
|
16875 | throw reason;
|
16876 | });
|
16877 | }
|
16878 | async set(name, value) {
|
16879 | await this.#initializedPromise;
|
16880 | const defaultValue = this.#defaults[name],
|
16881 | prefs = this.#prefs;
|
16882 | if (defaultValue === undefined) {
|
16883 | throw new Error(`Set preference: "${name}" is undefined.`);
|
16884 | } else if (value === undefined) {
|
16885 | throw new Error("Set preference: no value is specified.");
|
16886 | }
|
16887 | const valueType = typeof value,
|
16888 | defaultType = typeof defaultValue;
|
16889 | if (valueType !== defaultType) {
|
16890 | if (valueType === "number" && defaultType === "string") {
|
16891 | value = value.toString();
|
16892 | } else {
|
16893 | throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
|
16894 | }
|
16895 | } else {
|
16896 | if (valueType === "number" && !Number.isInteger(value)) {
|
16897 | throw new Error(`Set preference: "${value}" must be an integer.`);
|
16898 | }
|
16899 | }
|
16900 | this.#prefs[name] = value;
|
16901 | return this._writeToStorage(this.#prefs).catch(reason => {
|
16902 | this.#prefs = prefs;
|
16903 | throw reason;
|
16904 | });
|
16905 | }
|
16906 | async get(name) {
|
16907 | await this.#initializedPromise;
|
16908 | const defaultValue = this.#defaults[name];
|
16909 | if (defaultValue === undefined) {
|
16910 | throw new Error(`Get preference: "${name}" is undefined.`);
|
16911 | }
|
16912 | return this.#prefs[name] ?? defaultValue;
|
16913 | }
|
16914 | async getAll() {
|
16915 | await this.#initializedPromise;
|
16916 | const obj = Object.create(null);
|
16917 | for (const name in this.#defaults) {
|
16918 | obj[name] = this.#prefs[name] ?? this.#defaults[name];
|
16919 | }
|
16920 | return obj;
|
16921 | }
|
16922 | }
|
16923 | exports.BasePreferences = BasePreferences;
|
16924 |
|
16925 | }),
|
16926 |
|
16927 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
16928 |
|
16929 |
|
16930 |
|
16931 | Object.defineProperty(exports, "__esModule", ({
|
16932 | value: true
|
16933 | }));
|
16934 | exports.DownloadManager = void 0;
|
16935 | var _pdfjsLib = __webpack_require__(4);
|
16936 | ;
|
16937 | function download(blobUrl, filename) {
|
16938 | const a = document.createElement("a");
|
16939 | if (!a.click) {
|
16940 | throw new Error('DownloadManager: "a.click()" is not supported.');
|
16941 | }
|
16942 | a.href = blobUrl;
|
16943 | a.target = "_parent";
|
16944 | if ("download" in a) {
|
16945 | a.download = filename;
|
16946 | }
|
16947 | (document.body || document.documentElement).append(a);
|
16948 | a.click();
|
16949 | a.remove();
|
16950 | }
|
16951 | class DownloadManager {
|
16952 | #openBlobUrls = new WeakMap();
|
16953 | downloadUrl(url, filename) {
|
16954 | if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
|
16955 | Window['ngxConsole'].error(`downloadUrl - not a valid URL: ${url}`);
|
16956 | return;
|
16957 | }
|
16958 | download(url + "#pdfjs.action=download", filename);
|
16959 | }
|
16960 | downloadData(data, filename, contentType) {
|
16961 | const blobUrl = URL.createObjectURL(new Blob([data], {
|
16962 | type: contentType
|
16963 | }));
|
16964 | download(blobUrl, filename);
|
16965 | }
|
16966 | openOrDownloadData(element, data, filename) {
|
16967 | const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
|
16968 | const contentType = isPdfData ? "application/pdf" : "";
|
16969 | if (isPdfData) {
|
16970 | let blobUrl = this.#openBlobUrls.get(element);
|
16971 | if (!blobUrl) {
|
16972 | blobUrl = URL.createObjectURL(new Blob([data], {
|
16973 | type: contentType
|
16974 | }));
|
16975 | this.#openBlobUrls.set(element, blobUrl);
|
16976 | }
|
16977 | try {
|
16978 | window.open(blobUrl);
|
16979 | return true;
|
16980 | } catch (ex) {
|
16981 | Window['ngxConsole'].error(`openOrDownloadData: ${ex}`);
|
16982 | URL.revokeObjectURL(blobUrl);
|
16983 | this.#openBlobUrls.delete(element);
|
16984 | }
|
16985 | }
|
16986 | this.downloadData(data, filename, contentType);
|
16987 | return false;
|
16988 | }
|
16989 | download(blob, url, filename) {
|
16990 | const blobUrl = URL.createObjectURL(blob);
|
16991 | download(blobUrl, filename);
|
16992 | }
|
16993 | }
|
16994 | exports.DownloadManager = DownloadManager;
|
16995 |
|
16996 | }),
|
16997 |
|
16998 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
16999 |
|
17000 |
|
17001 |
|
17002 | Object.defineProperty(exports, "__esModule", ({
|
17003 | value: true
|
17004 | }));
|
17005 | exports.GenericL10n = void 0;
|
17006 | __webpack_require__(50);
|
17007 | var _l10n_utils = __webpack_require__(32);
|
17008 | const webL10n = document.webL10n;
|
17009 | class GenericL10n {
|
17010 | constructor(lang) {
|
17011 | this._lang = lang;
|
17012 | this._ready = new Promise((resolve, reject) => {
|
17013 | webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
|
17014 | resolve(webL10n);
|
17015 | });
|
17016 | });
|
17017 | }
|
17018 | async getLanguage() {
|
17019 | const l10n = await this._ready;
|
17020 | return l10n.getLanguage();
|
17021 | }
|
17022 | async getDirection() {
|
17023 | const l10n = await this._ready;
|
17024 | return l10n.getDirection();
|
17025 | }
|
17026 | async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
|
17027 | const l10n = await this._ready;
|
17028 | return l10n.get(key, args, fallback);
|
17029 | }
|
17030 | async translate(element) {
|
17031 | const l10n = await this._ready;
|
17032 | return l10n.translate(element);
|
17033 | }
|
17034 | }
|
17035 | exports.GenericL10n = GenericL10n;
|
17036 |
|
17037 | }),
|
17038 |
|
17039 | (() => {
|
17040 |
|
17041 |
|
17042 |
|
17043 | document.webL10n = function (window, document, undefined) {
|
17044 | var gL10nData = {};
|
17045 | var gTextData = "";
|
17046 | var gTextProp = "textContent";
|
17047 | var gLanguage = "";
|
17048 | var gMacros = {};
|
17049 | var gReadyState = "loading";
|
17050 | var gAsyncResourceLoading = true;
|
17051 | function getL10nResourceLinks() {
|
17052 | return document.querySelectorAll('link[type="application/l10n"]');
|
17053 | }
|
17054 | function getL10nDictionary() {
|
17055 | var script = document.querySelector('script[type="application/l10n"]');
|
17056 | return script ? JSON.parse(script.innerHTML) : null;
|
17057 | }
|
17058 | function getTranslatableChildren(element) {
|
17059 | return element ? element.querySelectorAll("*[data-l10n-id]") : [];
|
17060 | }
|
17061 | function getL10nAttributes(element) {
|
17062 | if (!element) return {};
|
17063 | var l10nId = element.getAttribute("data-l10n-id");
|
17064 | var l10nArgs = element.getAttribute("data-l10n-args");
|
17065 | var args = {};
|
17066 | if (l10nArgs) {
|
17067 | try {
|
17068 | args = JSON.parse(l10nArgs);
|
17069 | } catch (e) {
|
17070 | const PDFViewerApplicationOptions = window.PDFViewerApplicationOptions;
|
17071 | if (!PDFViewerApplicationOptions || PDFViewerApplicationOptions.get("verbosity") > 0) {
|
17072 | Window['ngxConsole'].warn("could not parse arguments for #" + l10nId);
|
17073 | }
|
17074 | }
|
17075 | }
|
17076 | return {
|
17077 | id: l10nId,
|
17078 | args: args
|
17079 | };
|
17080 | }
|
17081 | function fireL10nReadyEvent(lang) {
|
17082 | var evtObject = document.createEvent("Event");
|
17083 | evtObject.initEvent("localized", true, false);
|
17084 | evtObject.language = lang;
|
17085 | document.dispatchEvent(evtObject);
|
17086 | }
|
17087 | function xhrLoadText(url, onSuccess, onFailure) {
|
17088 | onSuccess = onSuccess || function _onSuccess(data) {};
|
17089 | onFailure = onFailure || function _onFailure() {};
|
17090 | var xhr = new XMLHttpRequest();
|
17091 | xhr.open("GET", url, gAsyncResourceLoading);
|
17092 | if (xhr.overrideMimeType) {
|
17093 | xhr.overrideMimeType("text/plain; charset=utf-8");
|
17094 | }
|
17095 | xhr.onreadystatechange = function () {
|
17096 | if (xhr.readyState == 4) {
|
17097 | if (xhr.status == 200 || xhr.status === 0) {
|
17098 | onSuccess(xhr.responseText);
|
17099 | } else {
|
17100 | onFailure();
|
17101 | }
|
17102 | }
|
17103 | };
|
17104 | xhr.onerror = onFailure;
|
17105 | xhr.ontimeout = onFailure;
|
17106 | try {
|
17107 | xhr.send(null);
|
17108 | } catch (e) {
|
17109 | onFailure();
|
17110 | }
|
17111 | }
|
17112 | function parseResource(href, lang, successCallback, failureCallback) {
|
17113 | var baseURL = href.replace(/[^\/]*$/, "") || "./";
|
17114 | function evalString(text) {
|
17115 | if (text.lastIndexOf("\\") < 0) return text;
|
17116 | return text.replace(/\\\\/g, "\\").replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, "\t").replace(/\\b/g, "\b").replace(/\\f/g, "\f").replace(/\\{/g, "{").replace(/\\}/g, "}").replace(/\\"/g, '"').replace(/\\'/g, "'");
|
17117 | }
|
17118 | function parseProperties(text, parsedPropertiesCallback) {
|
17119 | var dictionary = {};
|
17120 | var reBlank = /^\s*|\s*$/;
|
17121 | var reComment = /^\s*#|^\s*$/;
|
17122 | var reSection = /^\s*\[(.*)\]\s*$/;
|
17123 | var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
|
17124 | var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
|
17125 | function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
|
17126 | var entries = rawText.replace(reBlank, "").split(/[\r\n]+/);
|
17127 | var currentLang = "*";
|
17128 | var genericLang = lang.split("-", 1)[0];
|
17129 | var skipLang = false;
|
17130 | var match = "";
|
17131 | var languagefound = false;
|
17132 | function nextEntry() {
|
17133 | var genericMatch = undefined;
|
17134 | while (true) {
|
17135 | if (!entries.length && genericMatch) {
|
17136 | if (!languagefound) {
|
17137 | loadImport(genericMatch, nextEntry);
|
17138 | } else {
|
17139 | nextEntry();
|
17140 | }
|
17141 | return;
|
17142 | } else if (!entries.length) {
|
17143 | parsedRawLinesCallback();
|
17144 | return;
|
17145 | }
|
17146 | var line = entries.shift();
|
17147 | if (reComment.test(line)) continue;
|
17148 | if (extendedSyntax) {
|
17149 | match = reSection.exec(line);
|
17150 | if (match) {
|
17151 | currentLang = match[1].toLowerCase();
|
17152 | skipLang = currentLang !== "*" && currentLang !== lang && currentLang !== genericLang;
|
17153 | continue;
|
17154 | } else if (skipLang) {
|
17155 | continue;
|
17156 | }
|
17157 | match = reImport.exec(line);
|
17158 | if (match) {
|
17159 | if (currentLang === "*" || currentLang === lang) {
|
17160 | loadImport(baseURL + match[1], nextEntry);
|
17161 | languagefound = true;
|
17162 | return;
|
17163 | } else {
|
17164 | genericMatch = baseURL + match[1];
|
17165 | }
|
17166 | }
|
17167 | }
|
17168 | var tmp = line.match(reSplit);
|
17169 | if (tmp && tmp.length == 3) {
|
17170 | dictionary[tmp[1]] = evalString(tmp[2]);
|
17171 | }
|
17172 | }
|
17173 | }
|
17174 | nextEntry();
|
17175 | }
|
17176 | function loadImport(url, callback) {
|
17177 | xhrLoadText(url, function (content) {
|
17178 | parseRawLines(content, false, callback);
|
17179 | }, function () {
|
17180 | const PDFViewerApplicationOptions = window.PDFViewerApplicationOptions;
|
17181 | if (!PDFViewerApplicationOptions || PDFViewerApplicationOptions.get("verbosity") > 0) {
|
17182 | Window['ngxConsole'].warn(url + " not found.");
|
17183 | }
|
17184 | callback();
|
17185 | });
|
17186 | }
|
17187 | parseRawLines(text, true, function () {
|
17188 | parsedPropertiesCallback(dictionary);
|
17189 | });
|
17190 | }
|
17191 | xhrLoadText(href, function (response) {
|
17192 | gTextData += response;
|
17193 | parseProperties(response, function (data) {
|
17194 | for (var key in data) {
|
17195 | var id,
|
17196 | prop,
|
17197 | index = key.lastIndexOf(".");
|
17198 | if (index > 0) {
|
17199 | id = key.substring(0, index);
|
17200 | prop = key.substring(index + 1);
|
17201 | } else {
|
17202 | id = key;
|
17203 | prop = gTextProp;
|
17204 | }
|
17205 | if (!gL10nData[id]) {
|
17206 | gL10nData[id] = {};
|
17207 | }
|
17208 | gL10nData[id][prop] = data[key];
|
17209 | }
|
17210 | if (successCallback) {
|
17211 | successCallback();
|
17212 | }
|
17213 | });
|
17214 | }, failureCallback);
|
17215 | }
|
17216 | function loadLocale(lang, callback) {
|
17217 | let originalCaseLang = lang;
|
17218 | if (lang) {
|
17219 | lang = lang.toLowerCase();
|
17220 | }
|
17221 | callback = callback || function _callback() {};
|
17222 | clear();
|
17223 | gLanguage = lang;
|
17224 | var langLinks = getL10nResourceLinks();
|
17225 | var langCount = langLinks.length;
|
17226 | if (langCount === 0) {
|
17227 | var dict = getL10nDictionary();
|
17228 | if (dict && dict.locales && dict.default_locale) {
|
17229 | Window['ngxConsole'].log("The PDF viewer uses the pre-compiled language bundle stored in the HTML page.");
|
17230 | gL10nData = dict.locales[originalCaseLang];
|
17231 | if (!gL10nData) {
|
17232 | var defaultLocale = dict.default_locale.toLowerCase();
|
17233 | for (var anyCaseLang in dict.locales) {
|
17234 | originalCaseLang = anyCaseLang;
|
17235 | anyCaseLang = anyCaseLang.toLowerCase();
|
17236 | if (anyCaseLang === lang) {
|
17237 | gL10nData = dict.locales[originalCaseLang];
|
17238 | break;
|
17239 | } else if (anyCaseLang === defaultLocale) {
|
17240 | gL10nData = dict.locales[originalCaseLang];
|
17241 | }
|
17242 | }
|
17243 | }
|
17244 | callback();
|
17245 | } else {
|
17246 | Window['ngxConsole'].log("Could not load the translation files for the PDF viewer. Check the flag useBrowserLocale, check the locales subfolder of the assets folder, or add the locale definition to the index.html");
|
17247 | }
|
17248 | fireL10nReadyEvent(lang);
|
17249 | gReadyState = "complete";
|
17250 | return;
|
17251 | }
|
17252 | var onResourceLoaded = null;
|
17253 | var gResourceCount = 0;
|
17254 | onResourceLoaded = function () {
|
17255 | gResourceCount++;
|
17256 | if (gResourceCount >= langCount) {
|
17257 | callback();
|
17258 | fireL10nReadyEvent(lang);
|
17259 | gReadyState = "complete";
|
17260 | }
|
17261 | };
|
17262 | function L10nResourceLink(link) {
|
17263 | var href = link.href;
|
17264 | this.load = function (lang, callback) {
|
17265 | parseResource(href, lang, callback, function () {
|
17266 | const PDFViewerApplicationOptions = window.PDFViewerApplicationOptions;
|
17267 | if (!PDFViewerApplicationOptions || PDFViewerApplicationOptions.get("verbosity") > 0) {
|
17268 | Window['ngxConsole'].warn(href + " not found.");
|
17269 | Window['ngxConsole'].warn('"' + lang + '" resource not found');
|
17270 | }
|
17271 | gLanguage = "";
|
17272 | callback();
|
17273 | });
|
17274 | };
|
17275 | }
|
17276 | for (var i = 0; i < langCount; i++) {
|
17277 | var resource = new L10nResourceLink(langLinks[i]);
|
17278 | resource.load(lang, onResourceLoaded);
|
17279 | }
|
17280 | }
|
17281 | function clear() {
|
17282 | gL10nData = {};
|
17283 | gTextData = "";
|
17284 | gLanguage = "";
|
17285 | }
|
17286 | function getPluralRules(lang) {
|
17287 | var locales2rules = {
|
17288 | af: 3,
|
17289 | ak: 4,
|
17290 | am: 4,
|
17291 | ar: 1,
|
17292 | asa: 3,
|
17293 | az: 0,
|
17294 | be: 11,
|
17295 | bem: 3,
|
17296 | bez: 3,
|
17297 | bg: 3,
|
17298 | bh: 4,
|
17299 | bm: 0,
|
17300 | bn: 3,
|
17301 | bo: 0,
|
17302 | br: 20,
|
17303 | brx: 3,
|
17304 | bs: 11,
|
17305 | ca: 3,
|
17306 | cgg: 3,
|
17307 | chr: 3,
|
17308 | cs: 12,
|
17309 | cy: 17,
|
17310 | da: 3,
|
17311 | de: 3,
|
17312 | dv: 3,
|
17313 | dz: 0,
|
17314 | ee: 3,
|
17315 | el: 3,
|
17316 | en: 3,
|
17317 | eo: 3,
|
17318 | es: 3,
|
17319 | et: 3,
|
17320 | eu: 3,
|
17321 | fa: 0,
|
17322 | ff: 5,
|
17323 | fi: 3,
|
17324 | fil: 4,
|
17325 | fo: 3,
|
17326 | fr: 5,
|
17327 | fur: 3,
|
17328 | fy: 3,
|
17329 | ga: 8,
|
17330 | gd: 24,
|
17331 | gl: 3,
|
17332 | gsw: 3,
|
17333 | gu: 3,
|
17334 | guw: 4,
|
17335 | gv: 23,
|
17336 | ha: 3,
|
17337 | haw: 3,
|
17338 | he: 2,
|
17339 | hi: 4,
|
17340 | hr: 11,
|
17341 | hu: 0,
|
17342 | id: 0,
|
17343 | ig: 0,
|
17344 | ii: 0,
|
17345 | is: 3,
|
17346 | it: 3,
|
17347 | iu: 7,
|
17348 | ja: 0,
|
17349 | jmc: 3,
|
17350 | jv: 0,
|
17351 | ka: 0,
|
17352 | kab: 5,
|
17353 | kaj: 3,
|
17354 | kcg: 3,
|
17355 | kde: 0,
|
17356 | kea: 0,
|
17357 | kk: 3,
|
17358 | kl: 3,
|
17359 | km: 0,
|
17360 | kn: 0,
|
17361 | ko: 0,
|
17362 | ksb: 3,
|
17363 | ksh: 21,
|
17364 | ku: 3,
|
17365 | kw: 7,
|
17366 | lag: 18,
|
17367 | lb: 3,
|
17368 | lg: 3,
|
17369 | ln: 4,
|
17370 | lo: 0,
|
17371 | lt: 10,
|
17372 | lv: 6,
|
17373 | mas: 3,
|
17374 | mg: 4,
|
17375 | mk: 16,
|
17376 | ml: 3,
|
17377 | mn: 3,
|
17378 | mo: 9,
|
17379 | mr: 3,
|
17380 | ms: 0,
|
17381 | mt: 15,
|
17382 | my: 0,
|
17383 | nah: 3,
|
17384 | naq: 7,
|
17385 | nb: 3,
|
17386 | nd: 3,
|
17387 | ne: 3,
|
17388 | nl: 3,
|
17389 | nn: 3,
|
17390 | no: 3,
|
17391 | nr: 3,
|
17392 | nso: 4,
|
17393 | ny: 3,
|
17394 | nyn: 3,
|
17395 | om: 3,
|
17396 | or: 3,
|
17397 | pa: 3,
|
17398 | pap: 3,
|
17399 | pl: 13,
|
17400 | ps: 3,
|
17401 | pt: 3,
|
17402 | rm: 3,
|
17403 | ro: 9,
|
17404 | rof: 3,
|
17405 | ru: 11,
|
17406 | rwk: 3,
|
17407 | sah: 0,
|
17408 | saq: 3,
|
17409 | se: 7,
|
17410 | seh: 3,
|
17411 | ses: 0,
|
17412 | sg: 0,
|
17413 | sh: 11,
|
17414 | shi: 19,
|
17415 | sk: 12,
|
17416 | sl: 14,
|
17417 | sma: 7,
|
17418 | smi: 7,
|
17419 | smj: 7,
|
17420 | smn: 7,
|
17421 | sms: 7,
|
17422 | sn: 3,
|
17423 | so: 3,
|
17424 | sq: 3,
|
17425 | sr: 11,
|
17426 | ss: 3,
|
17427 | ssy: 3,
|
17428 | st: 3,
|
17429 | sv: 3,
|
17430 | sw: 3,
|
17431 | syr: 3,
|
17432 | ta: 3,
|
17433 | te: 3,
|
17434 | teo: 3,
|
17435 | th: 0,
|
17436 | ti: 4,
|
17437 | tig: 3,
|
17438 | tk: 3,
|
17439 | tl: 4,
|
17440 | tn: 3,
|
17441 | to: 0,
|
17442 | tr: 0,
|
17443 | ts: 3,
|
17444 | tzm: 22,
|
17445 | uk: 11,
|
17446 | ur: 3,
|
17447 | ve: 3,
|
17448 | vi: 0,
|
17449 | vun: 3,
|
17450 | wa: 4,
|
17451 | wae: 3,
|
17452 | wo: 0,
|
17453 | xh: 3,
|
17454 | xog: 3,
|
17455 | yo: 0,
|
17456 | zh: 0,
|
17457 | zu: 3
|
17458 | };
|
17459 | function isIn(n, list) {
|
17460 | return list.indexOf(n) !== -1;
|
17461 | }
|
17462 | function isBetween(n, start, end) {
|
17463 | return start <= n && n <= end;
|
17464 | }
|
17465 | var pluralRules = {
|
17466 | "0": function (n) {
|
17467 | return "other";
|
17468 | },
|
17469 | "1": function (n) {
|
17470 | if (isBetween(n % 100, 3, 10)) return "few";
|
17471 | if (n === 0) return "zero";
|
17472 | if (isBetween(n % 100, 11, 99)) return "many";
|
17473 | if (n == 2) return "two";
|
17474 | if (n == 1) return "one";
|
17475 | return "other";
|
17476 | },
|
17477 | "2": function (n) {
|
17478 | if (n !== 0 && n % 10 === 0) return "many";
|
17479 | if (n == 2) return "two";
|
17480 | if (n == 1) return "one";
|
17481 | return "other";
|
17482 | },
|
17483 | "3": function (n) {
|
17484 | if (n == 1) return "one";
|
17485 | return "other";
|
17486 | },
|
17487 | "4": function (n) {
|
17488 | if (isBetween(n, 0, 1)) return "one";
|
17489 | return "other";
|
17490 | },
|
17491 | "5": function (n) {
|
17492 | if (isBetween(n, 0, 2) && n != 2) return "one";
|
17493 | return "other";
|
17494 | },
|
17495 | "6": function (n) {
|
17496 | if (n === 0) return "zero";
|
17497 | if (n % 10 == 1 && n % 100 != 11) return "one";
|
17498 | return "other";
|
17499 | },
|
17500 | "7": function (n) {
|
17501 | if (n == 2) return "two";
|
17502 | if (n == 1) return "one";
|
17503 | return "other";
|
17504 | },
|
17505 | "8": function (n) {
|
17506 | if (isBetween(n, 3, 6)) return "few";
|
17507 | if (isBetween(n, 7, 10)) return "many";
|
17508 | if (n == 2) return "two";
|
17509 | if (n == 1) return "one";
|
17510 | return "other";
|
17511 | },
|
17512 | "9": function (n) {
|
17513 | if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return "few";
|
17514 | if (n == 1) return "one";
|
17515 | return "other";
|
17516 | },
|
17517 | "10": function (n) {
|
17518 | if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return "few";
|
17519 | if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return "one";
|
17520 | return "other";
|
17521 | },
|
17522 | "11": function (n) {
|
17523 | if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return "few";
|
17524 | if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return "many";
|
17525 | if (n % 10 == 1 && n % 100 != 11) return "one";
|
17526 | return "other";
|
17527 | },
|
17528 | "12": function (n) {
|
17529 | if (isBetween(n, 2, 4)) return "few";
|
17530 | if (n == 1) return "one";
|
17531 | return "other";
|
17532 | },
|
17533 | "13": function (n) {
|
17534 | if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return "few";
|
17535 | if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return "many";
|
17536 | if (n == 1) return "one";
|
17537 | return "other";
|
17538 | },
|
17539 | "14": function (n) {
|
17540 | if (isBetween(n % 100, 3, 4)) return "few";
|
17541 | if (n % 100 == 2) return "two";
|
17542 | if (n % 100 == 1) return "one";
|
17543 | return "other";
|
17544 | },
|
17545 | "15": function (n) {
|
17546 | if (n === 0 || isBetween(n % 100, 2, 10)) return "few";
|
17547 | if (isBetween(n % 100, 11, 19)) return "many";
|
17548 | if (n == 1) return "one";
|
17549 | return "other";
|
17550 | },
|
17551 | "16": function (n) {
|
17552 | if (n % 10 == 1 && n != 11) return "one";
|
17553 | return "other";
|
17554 | },
|
17555 | "17": function (n) {
|
17556 | if (n == 3) return "few";
|
17557 | if (n === 0) return "zero";
|
17558 | if (n == 6) return "many";
|
17559 | if (n == 2) return "two";
|
17560 | if (n == 1) return "one";
|
17561 | return "other";
|
17562 | },
|
17563 | "18": function (n) {
|
17564 | if (n === 0) return "zero";
|
17565 | if (isBetween(n, 0, 2) && n !== 0 && n != 2) return "one";
|
17566 | return "other";
|
17567 | },
|
17568 | "19": function (n) {
|
17569 | if (isBetween(n, 2, 10)) return "few";
|
17570 | if (isBetween(n, 0, 1)) return "one";
|
17571 | return "other";
|
17572 | },
|
17573 | "20": function (n) {
|
17574 | if ((isBetween(n % 10, 3, 4) || n % 10 == 9) && !(isBetween(n % 100, 10, 19) || isBetween(n % 100, 70, 79) || isBetween(n % 100, 90, 99))) return "few";
|
17575 | if (n % 1000000 === 0 && n !== 0) return "many";
|
17576 | if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return "two";
|
17577 | if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return "one";
|
17578 | return "other";
|
17579 | },
|
17580 | "21": function (n) {
|
17581 | if (n === 0) return "zero";
|
17582 | if (n == 1) return "one";
|
17583 | return "other";
|
17584 | },
|
17585 | "22": function (n) {
|
17586 | if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return "one";
|
17587 | return "other";
|
17588 | },
|
17589 | "23": function (n) {
|
17590 | if (isBetween(n % 10, 1, 2) || n % 20 === 0) return "one";
|
17591 | return "other";
|
17592 | },
|
17593 | "24": function (n) {
|
17594 | if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return "few";
|
17595 | if (isIn(n, [2, 12])) return "two";
|
17596 | if (isIn(n, [1, 11])) return "one";
|
17597 | return "other";
|
17598 | }
|
17599 | };
|
17600 | var index = locales2rules[lang.replace(/-.*$/, "")];
|
17601 | if (!(index in pluralRules)) {
|
17602 | const PDFViewerApplicationOptions = window.PDFViewerApplicationOptions;
|
17603 | if (!PDFViewerApplicationOptions || PDFViewerApplicationOptions.get("verbosity") > 0) {
|
17604 | Window['ngxConsole'].warn("plural form unknown for [" + lang + "]");
|
17605 | }
|
17606 | return function () {
|
17607 | return "other";
|
17608 | };
|
17609 | }
|
17610 | return pluralRules[index];
|
17611 | }
|
17612 | gMacros.plural = function (str, param, key, prop) {
|
17613 | var n = parseFloat(param);
|
17614 | if (isNaN(n)) return str;
|
17615 | if (prop != gTextProp) return str;
|
17616 | if (!gMacros._pluralRules) {
|
17617 | gMacros._pluralRules = getPluralRules(gLanguage);
|
17618 | }
|
17619 | var index = "[" + gMacros._pluralRules(n) + "]";
|
17620 | if (n === 0 && key + "[zero]" in gL10nData) {
|
17621 | str = gL10nData[key + "[zero]"][prop];
|
17622 | } else if (n == 1 && key + "[one]" in gL10nData) {
|
17623 | str = gL10nData[key + "[one]"][prop];
|
17624 | } else if (n == 2 && key + "[two]" in gL10nData) {
|
17625 | str = gL10nData[key + "[two]"][prop];
|
17626 | } else if (key + index in gL10nData) {
|
17627 | str = gL10nData[key + index][prop];
|
17628 | } else if (key + "[other]" in gL10nData) {
|
17629 | str = gL10nData[key + "[other]"][prop];
|
17630 | }
|
17631 | return str;
|
17632 | };
|
17633 | function getL10nData(key, args, fallback) {
|
17634 | var data = gL10nData[key];
|
17635 | if (!data) {
|
17636 | const PDFViewerApplicationOptions = window.PDFViewerApplicationOptions;
|
17637 | if (!PDFViewerApplicationOptions || PDFViewerApplicationOptions.get("verbosity") > 0) {
|
17638 | Window['ngxConsole'].warn("Translation for the key #" + key + " is missing.");
|
17639 | }
|
17640 | if (!fallback) {
|
17641 | return null;
|
17642 | }
|
17643 | data = fallback;
|
17644 | }
|
17645 | var rv = {};
|
17646 | for (var prop in data) {
|
17647 | var str = data[prop];
|
17648 | str = substIndexes(str, args, key, prop);
|
17649 | str = substArguments(str, args, key);
|
17650 | rv[prop] = str;
|
17651 | }
|
17652 | return rv;
|
17653 | }
|
17654 | function substIndexes(str, args, key, prop) {
|
17655 | var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
|
17656 | var reMatch = reIndex.exec(str);
|
17657 | if (!reMatch || !reMatch.length) return str;
|
17658 | var macroName = reMatch[1];
|
17659 | var paramName = reMatch[2];
|
17660 | var param;
|
17661 | if (args && paramName in args) {
|
17662 | param = args[paramName];
|
17663 | } else if (paramName in gL10nData) {
|
17664 | param = gL10nData[paramName];
|
17665 | }
|
17666 | if (macroName in gMacros) {
|
17667 | var macro = gMacros[macroName];
|
17668 | str = macro(str, param, key, prop);
|
17669 | }
|
17670 | return str;
|
17671 | }
|
17672 | function substArguments(str, args, key) {
|
17673 | var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
|
17674 | return str.replace(reArgs, function (matched_text, arg) {
|
17675 | if (args && arg in args) {
|
17676 | return args[arg];
|
17677 | }
|
17678 | if (arg in gL10nData) {
|
17679 | return gL10nData[arg];
|
17680 | }
|
17681 | Window['ngxConsole'].log("argument {{" + arg + "}} for #" + key + " is undefined.");
|
17682 | return matched_text;
|
17683 | });
|
17684 | }
|
17685 | function translateElement(element) {
|
17686 | var l10n = getL10nAttributes(element);
|
17687 | if (!l10n.id) return;
|
17688 | var data = getL10nData(l10n.id, l10n.args);
|
17689 | if (!data) {
|
17690 | const PDFViewerApplicationOptions = window.PDFViewerApplicationOptions;
|
17691 | if (!PDFViewerApplicationOptions || PDFViewerApplicationOptions.get("verbosity") > 0) {
|
17692 | Window['ngxConsole'].warn("#" + l10n.id + " is undefined.");
|
17693 | }
|
17694 | return;
|
17695 | }
|
17696 | if (data[gTextProp]) {
|
17697 | if (getChildElementCount(element) === 0) {
|
17698 | element[gTextProp] = data[gTextProp];
|
17699 | } else {
|
17700 | var children = element.childNodes;
|
17701 | var found = false;
|
17702 | for (var i = 0, l = children.length; i < l; i++) {
|
17703 | if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
|
17704 | if (found) {
|
17705 | children[i].nodeValue = "";
|
17706 | } else {
|
17707 | children[i].nodeValue = data[gTextProp];
|
17708 | found = true;
|
17709 | }
|
17710 | }
|
17711 | }
|
17712 | if (!found) {
|
17713 | var textNode = document.createTextNode(data[gTextProp]);
|
17714 | element.prepend(textNode);
|
17715 | }
|
17716 | }
|
17717 | delete data[gTextProp];
|
17718 | }
|
17719 | for (var k in data) {
|
17720 | element[k] = data[k];
|
17721 | }
|
17722 | }
|
17723 | function getChildElementCount(element) {
|
17724 | if (element.children) {
|
17725 | return element.children.length;
|
17726 | }
|
17727 | if (typeof element.childElementCount !== "undefined") {
|
17728 | return element.childElementCount;
|
17729 | }
|
17730 | var count = 0;
|
17731 | for (var i = 0; i < element.childNodes.length; i++) {
|
17732 | count += element.nodeType === 1 ? 1 : 0;
|
17733 | }
|
17734 | return count;
|
17735 | }
|
17736 | function translateFragment(element) {
|
17737 | element = element || document.documentElement;
|
17738 | var children = getTranslatableChildren(element);
|
17739 | var elementCount = children.length;
|
17740 | for (var i = 0; i < elementCount; i++) {
|
17741 | translateElement(children[i]);
|
17742 | }
|
17743 | translateElement(element);
|
17744 | }
|
17745 | return {
|
17746 | get: function (key, args, fallbackString) {
|
17747 | var index = key.lastIndexOf(".");
|
17748 | var prop = gTextProp;
|
17749 | if (index > 0) {
|
17750 | prop = key.substring(index + 1);
|
17751 | key = key.substring(0, index);
|
17752 | }
|
17753 | var fallback;
|
17754 | if (fallbackString) {
|
17755 | fallback = {};
|
17756 | fallback[prop] = fallbackString;
|
17757 | }
|
17758 | var data = getL10nData(key, args, fallback);
|
17759 | if (data && prop in data) {
|
17760 | return data[prop];
|
17761 | }
|
17762 | return "{{" + key + "}}";
|
17763 | },
|
17764 | getData: function () {
|
17765 | return gL10nData;
|
17766 | },
|
17767 | getText: function () {
|
17768 | return gTextData;
|
17769 | },
|
17770 | getLanguage: function () {
|
17771 | return gLanguage;
|
17772 | },
|
17773 | setLanguage: function (lang, callback) {
|
17774 | loadLocale(lang, function () {
|
17775 | if (callback) callback();
|
17776 | });
|
17777 | },
|
17778 | getDirection: function () {
|
17779 | var rtlList = ["ar", "he", "fa", "ps", "ur"];
|
17780 | var shortCode = gLanguage.split("-", 1)[0];
|
17781 | return rtlList.indexOf(shortCode) >= 0 ? "rtl" : "ltr";
|
17782 | },
|
17783 | translate: translateFragment,
|
17784 | getReadyState: function () {
|
17785 | return gReadyState;
|
17786 | },
|
17787 | ready: function (callback) {
|
17788 | if (!callback) {
|
17789 | return;
|
17790 | } else if (gReadyState == "complete" || gReadyState == "interactive") {
|
17791 | window.setTimeout(function () {
|
17792 | callback();
|
17793 | });
|
17794 | } else if (document.addEventListener) {
|
17795 | document.addEventListener("localized", function once() {
|
17796 | document.removeEventListener("localized", once);
|
17797 | callback();
|
17798 | });
|
17799 | }
|
17800 | }
|
17801 | };
|
17802 | }(window, document);
|
17803 |
|
17804 | }),
|
17805 |
|
17806 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
17807 |
|
17808 |
|
17809 |
|
17810 | Object.defineProperty(exports, "__esModule", ({
|
17811 | value: true
|
17812 | }));
|
17813 | exports.GenericScripting = void 0;
|
17814 | exports.docPropertiesLookup = docPropertiesLookup;
|
17815 | var _pdfjsLib = __webpack_require__(4);
|
17816 | async function docPropertiesLookup(pdfDocument) {
|
17817 | const url = "",
|
17818 | baseUrl = url.split("#")[0];
|
17819 | let {
|
17820 | info,
|
17821 | metadata,
|
17822 | contentDispositionFilename,
|
17823 | contentLength
|
17824 | } = await pdfDocument.getMetadata();
|
17825 | if (!contentLength) {
|
17826 | const {
|
17827 | length
|
17828 | } = await pdfDocument.getDownloadInfo();
|
17829 | contentLength = length;
|
17830 | }
|
17831 | return {
|
17832 | ...info,
|
17833 | baseURL: baseUrl,
|
17834 | filesize: contentLength,
|
17835 | filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
|
17836 | metadata: metadata?.getRaw(),
|
17837 | authors: metadata?.get("dc:creator"),
|
17838 | numPages: pdfDocument.numPages,
|
17839 | URL: url
|
17840 | };
|
17841 | }
|
17842 | class GenericScripting {
|
17843 | constructor(sandboxBundleSrc) {
|
17844 | this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
|
17845 | return window.pdfjsSandbox.QuickJSSandbox();
|
17846 | });
|
17847 | }
|
17848 | async createSandbox(data) {
|
17849 | const sandbox = await this._ready;
|
17850 | sandbox.create(data);
|
17851 | }
|
17852 | async dispatchEventInSandbox(event) {
|
17853 | const sandbox = await this._ready;
|
17854 | setTimeout(() => sandbox.dispatchEvent(event), 0);
|
17855 | }
|
17856 | async destroySandbox() {
|
17857 | const sandbox = await this._ready;
|
17858 | sandbox.nukeSandbox();
|
17859 | }
|
17860 | }
|
17861 | exports.GenericScripting = GenericScripting;
|
17862 |
|
17863 | }),
|
17864 |
|
17865 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
17866 |
|
17867 |
|
17868 |
|
17869 | Object.defineProperty(exports, "__esModule", ({
|
17870 | value: true
|
17871 | }));
|
17872 | exports.PDFPrintService = PDFPrintService;
|
17873 | var _pdfjsLib = __webpack_require__(4);
|
17874 | var _app = __webpack_require__(2);
|
17875 | var _canvasSize = _interopRequireDefault(__webpack_require__(39));
|
17876 | var _print_utils = __webpack_require__(53);
|
17877 | var _util = __webpack_require__(40);
|
17878 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17879 | let activeService = null;
|
17880 | let dialog = null;
|
17881 | let overlayManager = null;
|
17882 | function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) {
|
17883 | const scratchCanvas = activeService.scratchCanvas;
|
17884 | let PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
|
17885 | let scale = 1;
|
17886 | const canvasWidth = Math.floor(size.width * PRINT_UNITS);
|
17887 | const canvasHeight = Math.floor(size.height * PRINT_UNITS);
|
17888 | if (canvasWidth >= 4096 || canvasHeight >= 4096) {
|
17889 | if (!_canvasSize.default.test({
|
17890 | width: canvasWidth,
|
17891 | height: canvasHeight
|
17892 | })) {
|
17893 | const max = determineMaxDimensions();
|
17894 | scale = Math.min(max / canvasWidth, max / canvasHeight) * 0.95;
|
17895 | }
|
17896 | (0, _util.warn)("Page " + pageNumber + ": Reduced the [printResolution] to " + Math.floor(printResolution * scale) + " because the browser can't render larger canvases. If you see blank page in the print preview, reduce [printResolution] manually to a lower value.");
|
17897 | }
|
17898 | PRINT_UNITS *= scale;
|
17899 | scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
|
17900 | scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
|
17901 | const options = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {
|
17902 | willReadFrequently: true
|
17903 | } : undefined;
|
17904 | const ctx = scratchCanvas.getContext("2d", options);
|
17905 | ctx.save();
|
17906 | ctx.fillStyle = "rgb(255, 255, 255)";
|
17907 | ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
|
17908 | ctx.restore();
|
17909 | return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) {
|
17910 | const renderContext = {
|
17911 | canvasContext: ctx,
|
17912 | transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
|
17913 | viewport: pdfPage.getViewport({
|
17914 | scale: 1,
|
17915 | rotation: size.rotation
|
17916 | }),
|
17917 | intent: "print",
|
17918 | annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
|
17919 | optionalContentConfigPromise,
|
17920 | background: PDFViewerApplicationOptions.get("pdfBackgroundColor"),
|
17921 | printAnnotationStorage
|
17922 | };
|
17923 | return pdfPage.render(renderContext).promise;
|
17924 | });
|
17925 | }
|
17926 | function determineMaxDimensions() {
|
17927 | const checklist = [4096, 8192, 10836, 11180, 11402, 14188, 16384];
|
17928 | for (let width of checklist) {
|
17929 | if (!_canvasSize.default.test({
|
17930 | width: width + 1,
|
17931 | height: width + 1
|
17932 | })) {
|
17933 | return width;
|
17934 | }
|
17935 | }
|
17936 | return 16384;
|
17937 | }
|
17938 | function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, printAnnotationStoragePromise = null, l10n, eventBus) {
|
17939 | this.pdfDocument = pdfDocument;
|
17940 | this.pagesOverview = pagesOverview;
|
17941 | this.printContainer = printContainer;
|
17942 | this._printResolution = printResolution || 150;
|
17943 | this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
|
17944 | this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve();
|
17945 | this.l10n = l10n;
|
17946 | this.currentPage = -1;
|
17947 | this.scratchCanvas = document.createElement("canvas");
|
17948 | this.eventBus = eventBus;
|
17949 | }
|
17950 | PDFPrintService.prototype = {
|
17951 | layout() {
|
17952 | this.throwIfInactive();
|
17953 | const body = document.querySelector("body");
|
17954 | body.setAttribute("data-pdfjsprinting", true);
|
17955 | const html = document.querySelector("html");
|
17956 | html.setAttribute("data-pdfjsprinting", true);
|
17957 | const hasEqualPageSizes = this.pagesOverview.every(function (size) {
|
17958 | return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
|
17959 | }, this);
|
17960 | if (!hasEqualPageSizes) {
|
17961 | Window["ngxConsole"].warn("Not all pages have the same size. The printed " + "result may be incorrect!");
|
17962 | }
|
17963 | this.pageStyleSheet = document.createElement("style");
|
17964 | const pageSize = this.pagesOverview[0];
|
17965 | this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
|
17966 | body.append(this.pageStyleSheet);
|
17967 | },
|
17968 | destroy() {
|
17969 | if (activeService !== this) {
|
17970 | return;
|
17971 | }
|
17972 | this.printContainer.textContent = "";
|
17973 | const body = document.querySelector("body");
|
17974 | body.removeAttribute("data-pdfjsprinting");
|
17975 | const html = document.querySelector("html");
|
17976 | html.removeAttribute("data-pdfjsprinting");
|
17977 | if (this.pageStyleSheet) {
|
17978 | this.pageStyleSheet.remove();
|
17979 | this.pageStyleSheet = null;
|
17980 | }
|
17981 | this.scratchCanvas.width = this.scratchCanvas.height = 0;
|
17982 | this.scratchCanvas = null;
|
17983 | activeService = null;
|
17984 | ensureOverlay().then(function () {
|
17985 | if (overlayManager.active === dialog) {
|
17986 | overlayManager.close(dialog);
|
17987 | overlayManager.unregister(dialog);
|
17988 | }
|
17989 | });
|
17990 | overlayPromise = undefined;
|
17991 | },
|
17992 | renderPages() {
|
17993 | if (this.pdfDocument.isPureXfa) {
|
17994 | (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
|
17995 | return Promise.resolve();
|
17996 | }
|
17997 | const pageCount = this.pagesOverview.length;
|
17998 | const renderNextPage = (resolve, reject) => {
|
17999 | this.throwIfInactive();
|
18000 | while (true) {
|
18001 | ++this.currentPage;
|
18002 | if (this.currentPage >= pageCount) {
|
18003 | break;
|
18004 | }
|
18005 | if (!window.isInPDFPrintRange || window.isInPDFPrintRange(this.currentPage)) {
|
18006 | break;
|
18007 | }
|
18008 | }
|
18009 | if (this.currentPage >= pageCount) {
|
18010 | renderProgress(window.filteredPageCount | pageCount, window.filteredPageCount | pageCount, this.l10n, this.eventBus);
|
18011 | resolve();
|
18012 | return;
|
18013 | }
|
18014 | const index = this.currentPage;
|
18015 | renderProgress(index, window.filteredPageCount | pageCount, this.l10n, this.eventBus);
|
18016 | renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () {
|
18017 | renderNextPage(resolve, reject);
|
18018 | }, reject);
|
18019 | };
|
18020 | return new Promise(renderNextPage);
|
18021 | },
|
18022 | useRenderedPage() {
|
18023 | this.throwIfInactive();
|
18024 | const img = document.createElement("img");
|
18025 | const scratchCanvas = this.scratchCanvas;
|
18026 | if ("toBlob" in scratchCanvas) {
|
18027 | scratchCanvas.toBlob(function (blob) {
|
18028 | img.src = URL.createObjectURL(blob);
|
18029 | });
|
18030 | } else {
|
18031 | img.src = scratchCanvas.toDataURL();
|
18032 | }
|
18033 | const wrapper = document.createElement("div");
|
18034 | wrapper.className = "printedPage";
|
18035 | wrapper.append(img);
|
18036 | this.printContainer.append(wrapper);
|
18037 | return new Promise(function (resolve, reject) {
|
18038 | img.onload = resolve;
|
18039 | img.onerror = reject;
|
18040 | });
|
18041 | },
|
18042 | performPrint() {
|
18043 | this.throwIfInactive();
|
18044 | return new Promise(resolve => {
|
18045 | setTimeout(() => {
|
18046 | if (!this.active) {
|
18047 | resolve();
|
18048 | return;
|
18049 | }
|
18050 | print.call(window);
|
18051 | const isIOS = navigator.platform && ["iPad Simulator", "iPhone Simulator", "iPod Simulator", "iPad", "iPhone", "iPod"].includes(navigator.platform) || navigator.userAgent.includes("Mac") && "ontouchend" in document;
|
18052 | setTimeout(resolve, isIOS ? 1500 : 20);
|
18053 | }, 0);
|
18054 | });
|
18055 | },
|
18056 | get active() {
|
18057 | return this === activeService;
|
18058 | },
|
18059 | throwIfInactive() {
|
18060 | if (!this.active) {
|
18061 | throw new Error("This print request was cancelled or completed.");
|
18062 | }
|
18063 | }
|
18064 | };
|
18065 | const print = window.print;
|
18066 | window.printPDF = function printPdf() {
|
18067 | if (!_app.PDFViewerApplication.enablePrint) {
|
18068 | return;
|
18069 | }
|
18070 | if (activeService) {
|
18071 | Window["ngxConsole"].warn("Ignored window.printPDF() because of a pending print job.");
|
18072 | return;
|
18073 | }
|
18074 | ensureOverlay().then(function () {
|
18075 | if (activeService) {
|
18076 | overlayManager.open(dialog);
|
18077 | }
|
18078 | });
|
18079 | try {
|
18080 | dispatchEvent("beforeprint");
|
18081 | } finally {
|
18082 | if (!activeService) {
|
18083 | Window["ngxConsole"].error("Expected print service to be initialized.");
|
18084 | ensureOverlay().then(function () {
|
18085 | if (overlayManager.active === dialog) {
|
18086 | overlayManager.close(dialog);
|
18087 | }
|
18088 | });
|
18089 | return;
|
18090 | }
|
18091 | const activeServiceOnEntry = activeService;
|
18092 | activeService.renderPages().then(function () {
|
18093 | const progressIndicator = document.getElementById("printServiceDialog");
|
18094 | if (progressIndicator) {
|
18095 | progressIndicator.classList.add("hidden");
|
18096 | }
|
18097 | return activeServiceOnEntry.performPrint();
|
18098 | }).catch(function () {}).then(function () {
|
18099 | if (activeServiceOnEntry.active) {
|
18100 | abort();
|
18101 | }
|
18102 | });
|
18103 | }
|
18104 | };
|
18105 | function dispatchEvent(eventType) {
|
18106 | const event = document.createEvent("CustomEvent");
|
18107 | event.initCustomEvent(eventType, false, false, "custom");
|
18108 | window.dispatchEvent(event);
|
18109 | }
|
18110 | function abort() {
|
18111 | if (activeService) {
|
18112 | activeService.destroy();
|
18113 | dispatchEvent("afterprint");
|
18114 | }
|
18115 | }
|
18116 | function renderProgress(index, total, l10n, eventBus) {
|
18117 | dialog = document.getElementById("printServiceDialog");
|
18118 | const progress = Math.round(100 * index / total);
|
18119 | const progressBar = dialog.querySelector("progress");
|
18120 | const progressPerc = dialog.querySelector(".relative-progress");
|
18121 | progressBar.value = progress;
|
18122 | l10n.get("print_progress_percent", {
|
18123 | progress
|
18124 | }).then(msg => {
|
18125 | progressPerc.textContent = msg;
|
18126 | });
|
18127 | eventBus.dispatch("progress", {
|
18128 | source: this,
|
18129 | type: "print",
|
18130 | total,
|
18131 | page: index,
|
18132 | percent: 100 * index / total
|
18133 | });
|
18134 | }
|
18135 | window.addEventListener("keydown", function (event) {
|
18136 | if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
|
18137 | window.print();
|
18138 | event.preventDefault();
|
18139 | event.stopImmediatePropagation();
|
18140 | }
|
18141 | }, true);
|
18142 | if ("onbeforeprint" in window) {
|
18143 | const stopPropagationIfNeeded = function (event) {
|
18144 | if (event.detail !== "custom") {
|
18145 | event.stopImmediatePropagation();
|
18146 | }
|
18147 | };
|
18148 | window.addEventListener("beforeprint", stopPropagationIfNeeded);
|
18149 | window.addEventListener("afterprint", stopPropagationIfNeeded);
|
18150 | }
|
18151 | let overlayPromise;
|
18152 | function ensureOverlay() {
|
18153 | if (!overlayPromise) {
|
18154 | overlayManager = _app.PDFViewerApplication.overlayManager;
|
18155 | if (!overlayManager) {
|
18156 | throw new Error("The overlay manager has not yet been initialized.");
|
18157 | }
|
18158 | dialog = document.getElementById("printServiceDialog");
|
18159 | overlayPromise = overlayManager.register(dialog, true);
|
18160 | document.getElementById("printCancel").onclick = abort;
|
18161 | dialog.addEventListener("close", abort);
|
18162 | }
|
18163 | return overlayPromise;
|
18164 | }
|
18165 | _app.PDFPrintServiceFactory.instance = {
|
18166 | supportsPrinting: true,
|
18167 | createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n, eventBus) {
|
18168 | if (activeService) {
|
18169 | throw new Error("The print service is created and active.");
|
18170 | }
|
18171 | activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise, l10n, eventBus);
|
18172 | return activeService;
|
18173 | }
|
18174 | };
|
18175 |
|
18176 | }),
|
18177 |
|
18178 | ((__unused_webpack_module, exports, __webpack_require__) => {
|
18179 |
|
18180 |
|
18181 |
|
18182 | Object.defineProperty(exports, "__esModule", ({
|
18183 | value: true
|
18184 | }));
|
18185 | exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
|
18186 | var _pdfjsLib = __webpack_require__(4);
|
18187 | var _pdf_link_service = __webpack_require__(7);
|
18188 | var _xfa_layer_builder = __webpack_require__(43);
|
18189 | function getXfaHtmlForPrinting(printContainer, pdfDocument) {
|
18190 | const xfaHtml = pdfDocument.allXfaHtml;
|
18191 | const linkService = new _pdf_link_service.SimpleLinkService();
|
18192 | const scale = Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
|
18193 | for (const xfaPage of xfaHtml.children) {
|
18194 | const page = document.createElement("div");
|
18195 | page.className = "xfaPrintedPage";
|
18196 | printContainer.append(page);
|
18197 | const builder = new _xfa_layer_builder.XfaLayerBuilder({
|
18198 | pageDiv: page,
|
18199 | pdfPage: null,
|
18200 | annotationStorage: pdfDocument.annotationStorage,
|
18201 | linkService,
|
18202 | xfaHtml: xfaPage
|
18203 | });
|
18204 | const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
|
18205 | scale
|
18206 | });
|
18207 | builder.render(viewport, "print");
|
18208 | }
|
18209 | }
|
18210 |
|
18211 | })
|
18212 | ]);
|
18213 |
|
18214 |
|
18215 | var __webpack_module_cache__ = {};
|
18216 |
|
18217 |
|
18218 | function __webpack_require__(moduleId) {
|
18219 |
|
18220 | var cachedModule = __webpack_module_cache__[moduleId];
|
18221 | if (cachedModule !== undefined) {
|
18222 | return cachedModule.exports;
|
18223 | }
|
18224 |
|
18225 | var module = __webpack_module_cache__[moduleId] = {
|
18226 |
|
18227 |
|
18228 | exports: {}
|
18229 | };
|
18230 |
|
18231 |
|
18232 | __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
18233 |
|
18234 |
|
18235 | return module.exports;
|
18236 | }
|
18237 |
|
18238 |
|
18239 | var __webpack_exports__ = {};
|
18240 |
|
18241 | (() => {
|
18242 | var exports = __webpack_exports__;
|
18243 |
|
18244 |
|
18245 | Object.defineProperty(exports, "__esModule", ({
|
18246 | value: true
|
18247 | }));
|
18248 | Object.defineProperty(exports, "PDFViewerApplication", ({
|
18249 | enumerable: true,
|
18250 | get: function () {
|
18251 | return _app.PDFViewerApplication;
|
18252 | }
|
18253 | }));
|
18254 | exports.PDFViewerApplicationConstants = void 0;
|
18255 | Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
|
18256 | enumerable: true,
|
18257 | get: function () {
|
18258 | return _app_options.AppOptions;
|
18259 | }
|
18260 | }));
|
18261 | __webpack_require__(1);
|
18262 | __webpack_require__(52);
|
18263 | var _ui_utils = __webpack_require__(3);
|
18264 | var _app_options = __webpack_require__(5);
|
18265 | var _pdf_link_service = __webpack_require__(7);
|
18266 | var _app = __webpack_require__(2);
|
18267 | const pdfjsVersion = '3.4.493';
|
18268 | const pdfjsBuild = '7b85cf0e7';
|
18269 | const AppConstants = {
|
18270 | LinkTarget: _pdf_link_service.LinkTarget,
|
18271 | RenderingStates: _ui_utils.RenderingStates,
|
18272 | ScrollMode: _ui_utils.ScrollMode,
|
18273 | SpreadMode: _ui_utils.SpreadMode
|
18274 | };
|
18275 | exports.PDFViewerApplicationConstants = AppConstants;
|
18276 | window.PDFViewerApplication = _app.PDFViewerApplication;
|
18277 | window.PDFViewerApplicationConstants = AppConstants;
|
18278 | window.PDFViewerApplicationOptions = _app_options.AppOptions;
|
18279 | if (!HTMLCollection.prototype[Symbol.iterator]) {
|
18280 | HTMLCollection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
|
18281 | }
|
18282 | (function () {
|
18283 | if (typeof window.CustomEvent === "function") {
|
18284 | return;
|
18285 | }
|
18286 | function CustomEvent(event, params) {
|
18287 | params = params || {
|
18288 | bubbles: false,
|
18289 | cancelable: false,
|
18290 | detail: null
|
18291 | };
|
18292 | const evt = document.createEvent("CustomEvent");
|
18293 | evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
18294 | return evt;
|
18295 | }
|
18296 | window.CustomEvent = CustomEvent;
|
18297 | })();
|
18298 | function getViewerConfiguration() {
|
18299 | return {
|
18300 | appContainer: document.body,
|
18301 | mainContainer: document.getElementById("viewerContainer"),
|
18302 | viewerContainer: document.getElementById("viewer"),
|
18303 | toolbar: {
|
18304 | container: document.getElementById("toolbarViewer"),
|
18305 | numPages: document.getElementById("numPages"),
|
18306 | pageNumber: document.getElementById("pageNumber"),
|
18307 | scaleSelect: document.getElementById("scaleSelect"),
|
18308 | customScaleOption: document.getElementById("customScaleOption"),
|
18309 | previous: document.getElementById("previous"),
|
18310 | next: document.getElementById("next"),
|
18311 | zoomIn: document.getElementById("zoomIn"),
|
18312 | zoomOut: document.getElementById("zoomOut"),
|
18313 | viewFind: document.getElementById("viewFind"),
|
18314 | openFile: document.getElementById("openFile"),
|
18315 | print: document.getElementById("print"),
|
18316 | editorFreeTextButton: document.getElementById("editorFreeText"),
|
18317 | editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"),
|
18318 | editorInkButton: document.getElementById("editorInk"),
|
18319 | editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"),
|
18320 | download: document.getElementById("download")
|
18321 | },
|
18322 | secondaryToolbar: {
|
18323 | toolbar: document.getElementById("secondaryToolbar"),
|
18324 | toggleButton: document.getElementById("secondaryToolbarToggle"),
|
18325 | presentationModeButton: document.getElementById("presentationMode"),
|
18326 | openFileButton: document.getElementById("secondaryOpenFile"),
|
18327 | printButton: document.getElementById("secondaryPrint"),
|
18328 | downloadButton: document.getElementById("secondaryDownload"),
|
18329 | viewBookmarkButton: document.getElementById("viewBookmark"),
|
18330 | firstPageButton: document.getElementById("firstPage"),
|
18331 | lastPageButton: document.getElementById("lastPage"),
|
18332 | pageRotateCwButton: document.getElementById("pageRotateCw"),
|
18333 | pageRotateCcwButton: document.getElementById("pageRotateCcw"),
|
18334 | cursorSelectToolButton: document.getElementById("cursorSelectTool"),
|
18335 | cursorHandToolButton: document.getElementById("cursorHandTool"),
|
18336 | scrollPageButton: document.getElementById("scrollPage"),
|
18337 | scrollVerticalButton: document.getElementById("scrollVertical"),
|
18338 | scrollHorizontalButton: document.getElementById("scrollHorizontal"),
|
18339 | scrollWrappedButton: document.getElementById("scrollWrapped"),
|
18340 | spreadNoneButton: document.getElementById("spreadNone"),
|
18341 | spreadOddButton: document.getElementById("spreadOdd"),
|
18342 | spreadEvenButton: document.getElementById("spreadEven"),
|
18343 | documentPropertiesButton: document.getElementById("documentProperties")
|
18344 | },
|
18345 | sidebar: {
|
18346 | outerContainer: document.getElementById("outerContainer"),
|
18347 | sidebarContainer: document.getElementById("sidebarContainer"),
|
18348 | toggleButton: document.getElementById("sidebarToggle"),
|
18349 | thumbnailButton: document.getElementById("viewThumbnail"),
|
18350 | outlineButton: document.getElementById("viewOutline"),
|
18351 | attachmentsButton: document.getElementById("viewAttachments"),
|
18352 | layersButton: document.getElementById("viewLayers"),
|
18353 | thumbnailView: document.getElementById("thumbnailView"),
|
18354 | outlineView: document.getElementById("outlineView"),
|
18355 | attachmentsView: document.getElementById("attachmentsView"),
|
18356 | layersView: document.getElementById("layersView"),
|
18357 | outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
|
18358 | currentOutlineItemButton: document.getElementById("currentOutlineItem")
|
18359 | },
|
18360 | sidebarResizer: {
|
18361 | outerContainer: document.getElementById("outerContainer"),
|
18362 | resizer: document.getElementById("sidebarResizer")
|
18363 | },
|
18364 | findBar: {
|
18365 | bar: document.getElementById("findbar"),
|
18366 | toggleButton: document.getElementById("viewFind"),
|
18367 | findField: document.getElementById("findInput"),
|
18368 | findFieldMultiline: document.getElementById("findInputMultiline"),
|
18369 | highlightAllCheckbox: document.getElementById("findHighlightAll"),
|
18370 | findCurrentPageCheckbox: document.getElementById("findCurrentPage"),
|
18371 | findPageRangeField: document.getElementById("findRange"),
|
18372 | caseSensitiveCheckbox: document.getElementById("findMatchCase"),
|
18373 | matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"),
|
18374 | entireWordCheckbox: document.getElementById("findEntireWord"),
|
18375 | findMultipleSearchTextsCheckbox: document.getElementById("findMultipleSearchTexts"),
|
18376 | ignoreAccentsCheckbox: document.getElementById("findIgnoreAccents"),
|
18377 | fuzzyCheckbox: document.getElementById("findFuzzy"),
|
18378 | findMsg: document.getElementById("findMsg"),
|
18379 | findResultsCount: document.getElementById("findResultsCount"),
|
18380 | findPreviousButton: document.getElementById("findPrevious"),
|
18381 | findNextButton: document.getElementById("findNext")
|
18382 | },
|
18383 | passwordOverlay: {
|
18384 | dialog: document.getElementById("passwordDialog"),
|
18385 | label: document.getElementById("passwordText"),
|
18386 | input: document.getElementById("password"),
|
18387 | submitButton: document.getElementById("passwordSubmit"),
|
18388 | cancelButton: document.getElementById("passwordCancel")
|
18389 | },
|
18390 | documentProperties: {
|
18391 | dialog: document.getElementById("documentPropertiesDialog"),
|
18392 | closeButton: document.getElementById("documentPropertiesClose"),
|
18393 | fields: {
|
18394 | fileName: document.getElementById("fileNameField"),
|
18395 | fileSize: document.getElementById("fileSizeField"),
|
18396 | title: document.getElementById("titleField"),
|
18397 | author: document.getElementById("authorField"),
|
18398 | subject: document.getElementById("subjectField"),
|
18399 | keywords: document.getElementById("keywordsField"),
|
18400 | creationDate: document.getElementById("creationDateField"),
|
18401 | modificationDate: document.getElementById("modificationDateField"),
|
18402 | creator: document.getElementById("creatorField"),
|
18403 | producer: document.getElementById("producerField"),
|
18404 | version: document.getElementById("versionField"),
|
18405 | pageCount: document.getElementById("pageCountField"),
|
18406 | pageSize: document.getElementById("pageSizeField"),
|
18407 | linearized: document.getElementById("linearizedField")
|
18408 | }
|
18409 | },
|
18410 | annotationEditorParams: {
|
18411 | editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"),
|
18412 | editorFreeTextColor: document.getElementById("editorFreeTextColor"),
|
18413 | editorInkColor: document.getElementById("editorInkColor"),
|
18414 | editorInkThickness: document.getElementById("editorInkThickness"),
|
18415 | editorInkOpacity: document.getElementById("editorInkOpacity")
|
18416 | },
|
18417 | printContainer: document.getElementById("printContainer"),
|
18418 | openFileInput: document.getElementById("fileInput"),
|
18419 | debuggerScriptPath: "./debugger.js"
|
18420 | };
|
18421 | }
|
18422 | function webViewerLoad() {
|
18423 | const config = getViewerConfiguration();
|
18424 | const event = document.createEvent("CustomEvent");
|
18425 | event.initCustomEvent("webviewerloaded", true, true, {
|
18426 | source: window
|
18427 | });
|
18428 | try {
|
18429 | parent.document.dispatchEvent(event);
|
18430 | } catch (ex) {
|
18431 | console.error(`webviewerloaded: ${ex}`);
|
18432 | document.dispatchEvent(event);
|
18433 | }
|
18434 | _app.PDFViewerApplication.run(config);
|
18435 | }
|
18436 | document.blockUnblockOnload?.(true);
|
18437 | window.webViewerLoad = webViewerLoad;
|
18438 | })();
|
18439 |
|
18440 | })()
|
18441 | ;
|
18442 | });
|