@progress/kendo-pdfviewer-common 0.3.0-dev.202409251459 → 0.3.0-dev.202410100645

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/es/annotations/annotation-editor-layer-builder.js +139 -0
  2. package/dist/es/annotations/annotation-editor-layer.js +780 -0
  3. package/dist/es/annotations/annotation-editor-ui-manager.js +1690 -0
  4. package/dist/es/annotations/annotation-layer-builder.js +217 -0
  5. package/dist/es/annotations/annotation-layer.js +2793 -0
  6. package/dist/es/annotations/draw-layer-builder.js +65 -0
  7. package/dist/es/annotations/draw-layer.js +220 -0
  8. package/dist/es/annotations/editors/annotation-editor.js +1519 -0
  9. package/dist/es/annotations/editors/free-text-editor.js +783 -0
  10. package/dist/es/annotations/editors/highlight-editor.js +717 -0
  11. package/dist/es/annotations/editors/outliner.js +747 -0
  12. package/dist/es/annotations/helpers/annotation-storage.js +294 -0
  13. package/dist/es/annotations/helpers/color-manager.js +72 -0
  14. package/dist/es/annotations/helpers/command-manager.js +133 -0
  15. package/dist/es/annotations/helpers/id-manager.js +34 -0
  16. package/dist/es/annotations/helpers/image-manager.js +176 -0
  17. package/dist/es/annotations/helpers/text-accessibility-manager.js +212 -0
  18. package/dist/es/annotations/helpers/tools.js +19 -0
  19. package/dist/es/annotations/shared/display_utils.js +1024 -0
  20. package/dist/es/annotations/shared/event_utils.js +213 -0
  21. package/dist/es/annotations/shared/murmurhash3.js +126 -0
  22. package/dist/es/annotations/shared/scripting_utils.js +90 -0
  23. package/dist/es/annotations/shared/ui_utils.js +823 -0
  24. package/dist/es/annotations/shared/utils.js +909 -0
  25. package/dist/es/common/component.js +33 -0
  26. package/dist/es/common/core.js +91 -0
  27. package/dist/es/common/dom.js +11 -0
  28. package/dist/es/common/main.js +4 -0
  29. package/dist/es/common/math.js +1 -0
  30. package/dist/es/enums/PdfViewerInteractionMode.js +6 -0
  31. package/dist/es/links/link-service.js +505 -0
  32. package/dist/es/main.js +2 -0
  33. package/dist/es/scroller.js +29 -30
  34. package/dist/es/text/text-layer-builder.js +288 -0
  35. package/dist/es/utils.js +5 -5
  36. package/dist/es/widget/page.js +762 -0
  37. package/dist/es/widget/pdfviewer.js +1659 -0
  38. package/dist/es2015/annotations/annotation-editor-layer-builder.js +139 -0
  39. package/dist/es2015/annotations/annotation-editor-layer.js +780 -0
  40. package/dist/es2015/annotations/annotation-editor-ui-manager.js +1690 -0
  41. package/dist/es2015/annotations/annotation-layer-builder.js +217 -0
  42. package/dist/es2015/annotations/annotation-layer.js +2793 -0
  43. package/dist/es2015/annotations/draw-layer-builder.js +65 -0
  44. package/dist/es2015/annotations/draw-layer.js +220 -0
  45. package/dist/es2015/annotations/editors/annotation-editor.js +1519 -0
  46. package/dist/es2015/annotations/editors/free-text-editor.js +783 -0
  47. package/dist/es2015/annotations/editors/highlight-editor.js +717 -0
  48. package/dist/es2015/annotations/editors/outliner.js +747 -0
  49. package/dist/es2015/annotations/helpers/annotation-storage.js +294 -0
  50. package/dist/es2015/annotations/helpers/color-manager.js +72 -0
  51. package/dist/es2015/annotations/helpers/command-manager.js +133 -0
  52. package/dist/es2015/annotations/helpers/id-manager.js +34 -0
  53. package/dist/es2015/annotations/helpers/image-manager.js +176 -0
  54. package/dist/es2015/annotations/helpers/text-accessibility-manager.js +212 -0
  55. package/dist/es2015/annotations/helpers/tools.js +19 -0
  56. package/dist/es2015/annotations/shared/display_utils.js +1024 -0
  57. package/dist/es2015/annotations/shared/event_utils.js +213 -0
  58. package/dist/es2015/annotations/shared/murmurhash3.js +126 -0
  59. package/dist/es2015/annotations/shared/scripting_utils.js +90 -0
  60. package/dist/es2015/annotations/shared/ui_utils.js +823 -0
  61. package/dist/es2015/annotations/shared/utils.js +909 -0
  62. package/dist/es2015/common/component.js +33 -0
  63. package/dist/es2015/common/core.js +91 -0
  64. package/dist/es2015/common/dom.js +11 -0
  65. package/dist/es2015/common/main.js +4 -0
  66. package/dist/es2015/common/math.js +1 -0
  67. package/dist/es2015/enums/PdfViewerInteractionMode.js +6 -0
  68. package/dist/es2015/links/link-service.js +505 -0
  69. package/dist/es2015/main.js +2 -0
  70. package/dist/es2015/scroller.js +29 -30
  71. package/dist/es2015/text/text-layer-builder.js +288 -0
  72. package/dist/es2015/utils.js +5 -5
  73. package/dist/es2015/widget/page.js +762 -0
  74. package/dist/es2015/widget/pdfviewer.js +1659 -0
  75. package/dist/npm/annotations/annotation-editor-layer-builder.d.ts +39 -0
  76. package/dist/npm/annotations/annotation-editor-layer-builder.js +142 -0
  77. package/dist/npm/annotations/annotation-editor-layer.d.ts +196 -0
  78. package/dist/npm/annotations/annotation-editor-layer.js +783 -0
  79. package/dist/npm/annotations/annotation-editor-ui-manager.d.ts +281 -0
  80. package/dist/npm/annotations/annotation-editor-ui-manager.js +1694 -0
  81. package/dist/npm/annotations/annotation-layer-builder.d.ts +58 -0
  82. package/dist/npm/annotations/annotation-layer-builder.js +220 -0
  83. package/dist/npm/annotations/annotation-layer.d.ts +134 -0
  84. package/dist/npm/annotations/annotation-layer.js +2794 -0
  85. package/dist/npm/annotations/draw-layer-builder.d.ts +21 -0
  86. package/dist/npm/annotations/draw-layer-builder.js +68 -0
  87. package/dist/npm/annotations/draw-layer.d.ts +33 -0
  88. package/dist/npm/annotations/draw-layer.js +223 -0
  89. package/dist/npm/annotations/editors/annotation-editor.d.ts +349 -0
  90. package/dist/npm/annotations/editors/annotation-editor.js +1523 -0
  91. package/dist/npm/annotations/editors/free-text-editor.d.ts +108 -0
  92. package/dist/npm/annotations/editors/free-text-editor.js +786 -0
  93. package/dist/npm/annotations/editors/highlight-editor.d.ts +114 -0
  94. package/dist/npm/annotations/editors/highlight-editor.js +717 -0
  95. package/dist/npm/annotations/editors/outliner.d.ts +51 -0
  96. package/dist/npm/annotations/editors/outliner.js +750 -0
  97. package/dist/npm/annotations/helpers/annotation-storage.d.ts +98 -0
  98. package/dist/npm/annotations/helpers/annotation-storage.js +299 -0
  99. package/dist/npm/annotations/helpers/color-manager.d.ts +6 -0
  100. package/dist/npm/annotations/helpers/color-manager.js +76 -0
  101. package/dist/npm/annotations/helpers/command-manager.d.ts +42 -0
  102. package/dist/npm/annotations/helpers/command-manager.js +137 -0
  103. package/dist/npm/annotations/helpers/id-manager.d.ts +6 -0
  104. package/dist/npm/annotations/helpers/id-manager.js +38 -0
  105. package/dist/npm/annotations/helpers/image-manager.d.ts +18 -0
  106. package/dist/npm/annotations/helpers/image-manager.js +180 -0
  107. package/dist/npm/annotations/helpers/text-accessibility-manager.d.ts +36 -0
  108. package/dist/npm/annotations/helpers/text-accessibility-manager.js +215 -0
  109. package/dist/npm/annotations/helpers/tools.d.ts +1 -0
  110. package/dist/npm/annotations/helpers/tools.js +23 -0
  111. package/dist/npm/annotations/shared/display_utils.d.ts +6 -0
  112. package/dist/npm/annotations/shared/display_utils.js +1030 -0
  113. package/dist/npm/annotations/shared/event_utils.d.ts +33 -0
  114. package/dist/npm/annotations/shared/event_utils.js +165 -0
  115. package/dist/npm/annotations/shared/murmurhash3.d.ts +8 -0
  116. package/dist/npm/annotations/shared/murmurhash3.js +129 -0
  117. package/dist/npm/annotations/shared/scripting_utils.d.ts +17 -0
  118. package/dist/npm/annotations/shared/scripting_utils.js +93 -0
  119. package/dist/npm/annotations/shared/ui_utils.d.ts +54 -0
  120. package/dist/npm/annotations/shared/ui_utils.js +250 -0
  121. package/dist/npm/annotations/shared/utils.d.ts +148 -0
  122. package/dist/npm/annotations/shared/utils.js +872 -0
  123. package/dist/npm/common/component.d.ts +9 -0
  124. package/dist/npm/common/component.js +37 -0
  125. package/dist/npm/common/core.d.ts +18 -0
  126. package/dist/npm/common/core.js +112 -0
  127. package/dist/npm/common/dom.d.ts +3 -0
  128. package/dist/npm/common/dom.js +17 -0
  129. package/dist/npm/common/main.d.ts +4 -0
  130. package/dist/npm/common/main.js +7 -0
  131. package/dist/npm/common/math.d.ts +1 -0
  132. package/dist/npm/common/math.js +5 -0
  133. package/dist/npm/enums/PdfViewerInteractionMode.d.ts +4 -0
  134. package/dist/npm/enums/PdfViewerInteractionMode.js +9 -0
  135. package/dist/npm/links/link-service.d.ts +116 -0
  136. package/dist/npm/links/link-service.js +501 -0
  137. package/dist/npm/main.d.ts +2 -0
  138. package/dist/npm/main.js +2 -0
  139. package/dist/npm/scroller.d.ts +7 -3
  140. package/dist/npm/scroller.js +32 -32
  141. package/dist/npm/text/text-layer-builder.d.ts +30 -0
  142. package/dist/npm/text/text-layer-builder.js +291 -0
  143. package/dist/npm/utils.d.ts +20 -2
  144. package/dist/npm/utils.js +11 -8
  145. package/dist/npm/widget/page.d.ts +75 -0
  146. package/dist/npm/widget/page.js +763 -0
  147. package/dist/npm/widget/pdfviewer.d.ts +222 -0
  148. package/dist/npm/widget/pdfviewer.js +1663 -0
  149. package/package.json +13 -9
@@ -0,0 +1,1659 @@
1
+ var _PdfViewer_instances, _PdfViewer_annotationEditorMode, _PdfViewer_switchAnnotationEditorModeTimeoutId, _PdfViewer_eventAbortController, _PdfViewer_onPageRenderedCallback, _PdfViewer_switchToEditAnnotationMode, _PdfViewer_scrollIntoView;
2
+ import { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ import { deepExtend, Component, isString, toArray, noop, hasValue, toClassSelector, addClass, removeClass, mousewheelDelta, convertToHtml, clamp, createPromise } from "../common/main";
4
+ import { currentPage, parsePdfFromBase64String, scale as getScale, adjustCanvasSize, createElement } from "../utils";
5
+ import { SearchService } from "../search";
6
+ import { Scroller } from "../scroller";
7
+ import { throttle } from "../scroller";
8
+ import { saveAs } from "@progress/kendo-file-saver";
9
+ import { getDocument, AnnotationEditorParamsType, AnnotationEditorType, PixelsPerInch, shadow, } from "pdfjs-dist/legacy/build/pdf.mjs";
10
+ import { AnnotationEditorUIManager } from "../annotations/annotation-editor-ui-manager";
11
+ import { EventBus } from '../annotations/shared/event_utils';
12
+ import { Page } from "./page";
13
+ import { AnnotationMode } from "../annotations/shared/utils";
14
+ import { scrollIntoView, TextLayerMode, ScrollMode } from "../annotations/shared/ui_utils";
15
+ import { AnnotationStorage } from "../annotations/helpers/annotation-storage";
16
+ import { LinkTarget, PDFLinkService } from "../links/link-service";
17
+ import { PdfViewerInteractionMode } from "../enums/PdfViewerInteractionMode";
18
+ const PDF_JS = "pdfjs";
19
+ const ERROR = "error";
20
+ const ZOOM_START = "zoomStart";
21
+ const ZOOM_END = "zoomEnd";
22
+ const PAGES_LOAD = "pagesLoad";
23
+ const PRINT_END = "printEnd";
24
+ const SCROLL = "scroll";
25
+ const DOWNLOAD = "download";
26
+ const ANNOTATION_EDITOR_TOOLBAR_SHOW = "annotationEditorToolBarShow";
27
+ const ANNOTATION_EDITOR_TOOLBAR_HIDE = "annotationEditorToolBarHide";
28
+ const DEFAULT_ZOOM_LEVEL = 1.25;
29
+ const FRAMES_PER_SECOND = 1000 / 60;
30
+ export class PdfViewer extends Component {
31
+ constructor(element, options) {
32
+ super(element, options);
33
+ _PdfViewer_instances.add(this);
34
+ this.options = {
35
+ pdfServiceType: PDF_JS,
36
+ // this is a flag used mainly in tests as CSSStyleSheet.replaceSync
37
+ // fails with jsdom
38
+ // a better solution is not to load a stylesheet in setHiddenCanvasStyles
39
+ // but rather create a class like "k-hidden-canvas-element"
40
+ // and override the rendering from pdf.js
41
+ pdfjsSetHiddenCanvasStyles: true,
42
+ fileData: [],
43
+ page: 1,
44
+ fileDescriptor: null,
45
+ downloadFileName: "Document",
46
+ minZoom: 0.5,
47
+ maxZoom: 4,
48
+ zoomRate: 0.25,
49
+ zoomLevel: DEFAULT_ZOOM_LEVEL,
50
+ zoomBeforePrint: false,
51
+ zoomLevelForPrint: 3,
52
+ searchMatchScrollLeftOffset: 0,
53
+ // add some default offset, so that the found match
54
+ // does not appear on the top edge of the page when navigated to
55
+ searchMatchScrollTopOffset: -64,
56
+ // what percentage of the page should be scrolled,
57
+ // so that the page is considered to be changed to the next one
58
+ pageChangeScrollThreshold: 0.85,
59
+ // values higher than 200ms can result in browser zoom
60
+ pageWheelThrottleDelay: 200,
61
+ // ported from pdf.js
62
+ printResolution: 150,
63
+ loadOnDemand: false,
64
+ loadOnDemandPageSize: 2,
65
+ messages: {
66
+ freeTextEditorPlaceholder: "Start typing",
67
+ errorMessages: {
68
+ parseError: "PDF file fails to process.",
69
+ notFound: "File is not found.",
70
+ popupBlocked: "Popup is blocked."
71
+ }
72
+ },
73
+ annotations: {
74
+ highlight: {
75
+ color: "#ffff00"
76
+ }
77
+ },
78
+ elementSelectors: {
79
+ pageSelector: "k-page:not(.k-blank-page)",
80
+ pagesContainerClass: "k-pdf-viewer-pages",
81
+ pageCanvasWrapper: "k-canvas-wrapper",
82
+ documentContainerClass: "k-pdf-viewer-canvas",
83
+ textLayerClass: "k-text-layer",
84
+ searchHighlightClass: "k-search-highlight",
85
+ searchHighlightMarkClass: "k-search-highlight-mark",
86
+ charClass: "k-text-char",
87
+ textElementSelector: "span[role='presentation']",
88
+ renderedPageSelector: "k-page[data-page-number]",
89
+ enabledTextSelectionClass: "k-enable-text-select",
90
+ enabledPanningClass: "k-enable-panning"
91
+ },
92
+ events: {
93
+ [PAGES_LOAD]: noop,
94
+ [PRINT_END]: noop,
95
+ [ZOOM_START]: noop,
96
+ [ZOOM_END]: noop,
97
+ [ERROR]: noop,
98
+ [SCROLL]: noop,
99
+ [ANNOTATION_EDITOR_TOOLBAR_SHOW]: noop,
100
+ [ANNOTATION_EDITOR_TOOLBAR_HIDE]: noop
101
+ }
102
+ };
103
+ // todo: props
104
+ // isPageEditing = null;
105
+ this.interactionMode = PdfViewerInteractionMode.TextSelection;
106
+ this.printContainer = null;
107
+ // todo: props ported from pdf.js
108
+ this._scrollMode = ScrollMode.PAGE;
109
+ this.isInPresentationMode = false;
110
+ this._currentPageNumber = 1;
111
+ this.linkService = null;
112
+ this.annotationStorage = null;
113
+ this._annotationStorageModified = false;
114
+ this._hasAnnotationEditors = false;
115
+ _PdfViewer_annotationEditorMode.set(this, AnnotationEditorType.NONE);
116
+ this.annotationEditorUIManager = null;
117
+ _PdfViewer_switchAnnotationEditorModeTimeoutId.set(this, null);
118
+ // #buffer = null;
119
+ // #altTextManager = null;
120
+ // #annotationEditorHighlightColors = null;
121
+ // #annotationEditorMode = AnnotationEditorType.NONE;
122
+ // #annotationEditorUIManager = null;
123
+ // #annotationMode = AnnotationMode.ENABLE_FORMS;
124
+ // #containerTopLeft = null;
125
+ // #enableHWA = false;
126
+ // #enableHighlightFloatingButton = false;
127
+ // #enablePermissions = false;
128
+ // #enableUpdatedAddImage = false;
129
+ // #enableNewAltTextWhenAddingImage = false;
130
+ _PdfViewer_eventAbortController.set(this, null);
131
+ // #mlManager = null;
132
+ _PdfViewer_onPageRenderedCallback.set(this, null);
133
+ // #switchAnnotationEditorModeTimeoutId = null;
134
+ // #getAllTextInProgress = false;
135
+ // #hiddenCopyElement = null;
136
+ // #interruptCopyCondition = false;
137
+ // #previousContainerHeight = 0;
138
+ // #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
139
+ // #scrollModePageState = null;
140
+ // #scaleTimeoutId = null;
141
+ // #textLayerMode = TextLayerMode.ENABLE;
142
+ // todo: props
143
+ this.state = {};
144
+ this.pdfDocument = null;
145
+ this.pages = [];
146
+ this.triggerError = (e) => {
147
+ this.trigger(ERROR, {
148
+ error: e
149
+ });
150
+ };
151
+ this.triggerPrintEnd = (e) => {
152
+ this.trigger(PRINT_END, e);
153
+ };
154
+ this.onPagesLoad = (args) => {
155
+ this.state.pdfDocument = args.pdfDoc;
156
+ this.state.pdfPages = args.pdfPages;
157
+ this.clearSearch();
158
+ this.initSearchService();
159
+ this.enableDocumentScrollEventsTracking();
160
+ this.triggerPagesLoad(args);
161
+ };
162
+ this.onDocumentScrollerScroll = (e) => {
163
+ const currentPageIndex = this.getCurrentPageIndex();
164
+ const pages = this.pages;
165
+ const page = pages[currentPageIndex];
166
+ const nextPage = pages[currentPageIndex + 1];
167
+ const previousPage = pages[currentPageIndex - 1];
168
+ if (page && page.isBlank()) {
169
+ this.drawPageAsync({ pageIndex: currentPageIndex });
170
+ }
171
+ if (nextPage && nextPage.isBlank()) {
172
+ this.drawPageAsync({ pageIndex: currentPageIndex + 1 });
173
+ }
174
+ if (previousPage && previousPage.isBlank()) {
175
+ this.drawPageAsync({ pageIndex: currentPageIndex - 1 });
176
+ }
177
+ this.tryTriggerScroll(e);
178
+ };
179
+ // this is mainly used by blazor to track the page number
180
+ // as this can only be obtained by JS
181
+ this.tryTriggerScroll = (e) => {
182
+ let isPageChanged = false;
183
+ const pageNumber = currentPage(this.element) + 1;
184
+ if (pageNumber !== this.state.activePageNumber && (pageNumber >= 1 && pageNumber <= this.state.pdfDocument.numPagesh)) {
185
+ isPageChanged = true;
186
+ this.state.activePageNumber = pageNumber;
187
+ }
188
+ if (this.shouldPreventScroll) {
189
+ this.shouldPreventScroll = false;
190
+ }
191
+ else {
192
+ this.trigger(SCROLL, {
193
+ scrollLeft: e.scrollLeft,
194
+ scrollTop: e.scrollTop,
195
+ pageNumber: this.state.activePageNumber,
196
+ isPageChanged: isPageChanged
197
+ });
198
+ }
199
+ };
200
+ this.printDocumentAsync = () => {
201
+ this.initPrintContainer();
202
+ const pagePrintPromises = this.getPagesPrintContentAsync(this.printContainer);
203
+ const printPromise = createPromise();
204
+ Promise.all(pagePrintPromises)
205
+ .then(() => {
206
+ // print the document during next render task
207
+ setTimeout(() => {
208
+ this.openPrintDialog();
209
+ // @ts-expect-error TS()
210
+ printPromise.resolve();
211
+ }, FRAMES_PER_SECOND);
212
+ });
213
+ return printPromise;
214
+ };
215
+ this.onDocumentWheel = (e) => {
216
+ if (!e.ctrlKey && !e.metaKey) {
217
+ return;
218
+ }
219
+ e.preventDefault();
220
+ const wheelDelta = mousewheelDelta(e);
221
+ const zoomModifier = wheelDelta < 0 ? 1 : -1;
222
+ const zoomLevel = this.state.zoomLevel + (zoomModifier * this.options.zoomRate);
223
+ this.triggerZoomStart({
224
+ zoomLevel: zoomLevel
225
+ });
226
+ this.zoom({
227
+ zoomLevel: zoomLevel
228
+ });
229
+ this.triggerZoomEnd({
230
+ zoomLevel: zoomLevel
231
+ });
232
+ };
233
+ this.extendOptions(options);
234
+ this.throwIfInvalidOptions();
235
+ this.wrapper = this.element;
236
+ this.initEventBus();
237
+ __classPrivateFieldSet(this, _PdfViewer_eventAbortController, new AbortController(), "f");
238
+ this.resetState();
239
+ this.bindEvents();
240
+ this.initLinkService();
241
+ this.initDocumentContainer();
242
+ this.loadFile(this.options.fileDescriptor || {
243
+ data: this.options.fileData,
244
+ page: this.options.page
245
+ });
246
+ }
247
+ destroy() {
248
+ this.destroyEventBus();
249
+ this.unbindEvents();
250
+ this.destroySearchService();
251
+ this.destroyAnnotationEditorUIManager();
252
+ this.destroyDocumentScroller();
253
+ }
254
+ throwIfInvalidOptions() {
255
+ if (this.options.minZoom > this.options.maxZoom) {
256
+ throw new Error("The min zoom should be greater than max zoom");
257
+ }
258
+ }
259
+ set annotationEditorParams({ type, value }) {
260
+ if (!this.annotationEditorUIManager) {
261
+ return;
262
+ }
263
+ this.annotationEditorUIManager.updateParams(type, value);
264
+ }
265
+ get annotationEditorMode() {
266
+ return this.annotationEditorUIManager
267
+ ? __classPrivateFieldGet(this, _PdfViewer_annotationEditorMode, "f")
268
+ : AnnotationEditorType.DISABLE;
269
+ }
270
+ // @ts-expect-error(TS)
271
+ set annotationEditorMode({ mode, editId = null, isFromKeyboard = false }) {
272
+ // todo: set isFromKeyboard intentionally to allow editor creation
273
+ // set annotationEditorMode({ mode, editId = null, isFromKeyboard = true }) {
274
+ if (!this.annotationEditorUIManager) {
275
+ // throw new Error(`The AnnotationEditor is not enabled.`);
276
+ }
277
+ if (__classPrivateFieldGet(this, _PdfViewer_annotationEditorMode, "f") === mode) {
278
+ return; // The AnnotationEditor mode didn't change.
279
+ }
280
+ if (!this.isValidAnnotationEditorMode(mode)) {
281
+ // throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
282
+ return;
283
+ }
284
+ if (!this.pdfDocument) {
285
+ return;
286
+ }
287
+ if (mode === AnnotationEditorType.STAMP) {
288
+ // this.#mlManager?.loadModel("altText");
289
+ }
290
+ const { eventBus } = this;
291
+ const updater = () => {
292
+ this.cleanupSwitchAnnotationEditorMode();
293
+ __classPrivateFieldSet(this, _PdfViewer_annotationEditorMode, mode, "f");
294
+ this.annotationEditorUIManager.updateMode(mode, editId, isFromKeyboard);
295
+ eventBus.dispatch("annotationeditormodechanged", {
296
+ source: this,
297
+ mode,
298
+ });
299
+ };
300
+ // // todo: fix
301
+ // const isEditingPage = (this.pages || []).some(x => x.isEditing);
302
+ if (mode === AnnotationEditorType.NONE || __classPrivateFieldGet(this, _PdfViewer_annotationEditorMode, "f") === AnnotationEditorType.NONE) {
303
+ const isEditing = mode !== AnnotationEditorType.NONE;
304
+ if (!isEditing) {
305
+ this.pdfDocument.annotationStorage.resetModifiedIds();
306
+ }
307
+ for (const pageView of this.pages) {
308
+ pageView.toggleEditingMode(isEditing);
309
+ }
310
+ // We must call #switchToEditAnnotationMode unconditionally to ensure that
311
+ // page is rendered if it's useful or not.
312
+ const idsToRefresh = __classPrivateFieldGet(this, _PdfViewer_instances, "m", _PdfViewer_switchToEditAnnotationMode).call(this);
313
+ if (isEditing && idsToRefresh) {
314
+ // We're editing so we must switch to editing mode when the rendering is
315
+ // done.
316
+ this.cleanupSwitchAnnotationEditorMode();
317
+ __classPrivateFieldSet(this, _PdfViewer_onPageRenderedCallback, ({ pageNumber }) => {
318
+ idsToRefresh.delete(pageNumber);
319
+ if (idsToRefresh.size === 0) {
320
+ __classPrivateFieldSet(this, _PdfViewer_switchAnnotationEditorModeTimeoutId, setTimeout(updater, 0), "f");
321
+ }
322
+ }, "f");
323
+ const { signal } = __classPrivateFieldGet(this, _PdfViewer_eventAbortController, "f");
324
+ eventBus._on("pagerendered", __classPrivateFieldGet(this, _PdfViewer_onPageRenderedCallback, "f"), { signal });
325
+ }
326
+ }
327
+ updater();
328
+ }
329
+ extendOptions(options) {
330
+ this.options = deepExtend(this.options, options);
331
+ }
332
+ setOptions(options) {
333
+ this.options = options;
334
+ }
335
+ bindEvents() {
336
+ this.bindPagesWheel();
337
+ }
338
+ bindPagesWheel() {
339
+ const documentContainer = this.getDocumentContainer();
340
+ if (!documentContainer) {
341
+ return;
342
+ }
343
+ if (this.options.pageWheelThrottleDelay > 0) {
344
+ // @ts-expect-error TS(2339): Property 'throttledPagesWheel' does not exist on t... Remove this comment to see the full error message
345
+ this.throttledPagesWheel = throttle(this.onDocumentWheel, this.options.pageWheelThrottleDelay);
346
+ }
347
+ else {
348
+ // @ts-expect-error TS(2339): Property 'throttledPagesWheel' does not exist on t... Remove this comment to see the full error message
349
+ this.throttledPagesWheel = this.onDocumentWheel;
350
+ }
351
+ // @ts-expect-error TS(2339): Property 'throttledPagesWheel' does not exist on t... Remove this comment to see the full error message
352
+ documentContainer.addEventListener("wheel", this.throttledPagesWheel);
353
+ }
354
+ unbindEvents() {
355
+ this.unbindPagesWheel();
356
+ }
357
+ unbindPagesWheel() {
358
+ const documentContainer = this.getDocumentContainer();
359
+ if (!documentContainer) {
360
+ return;
361
+ }
362
+ // @ts-expect-error TS(2339): Property 'throttledPagesWheel' does not exist on t... Remove this comment to see the full error message
363
+ if (this.throttledPagesWheel && this.throttledPagesWheel.cancel) {
364
+ // @ts-expect-error TS(2339): Property 'throttledPagesWheel' does not exist on t... Remove this comment to see the full error message
365
+ this.throttledPagesWheel.cancel();
366
+ }
367
+ // @ts-expect-error TS(2339): Property 'throttledPagesWheel' does not exist on t... Remove this comment to see the full error message
368
+ documentContainer.removeEventListener("wheel", this.throttledPagesWheel);
369
+ }
370
+ setState(newState) {
371
+ this.state = deepExtend(this.state || {}, newState);
372
+ }
373
+ resetState() {
374
+ this.setState({
375
+ activePageNumber: 1,
376
+ visiblePagesCount: 1,
377
+ pagePromises: [],
378
+ downloadFilePromise: null,
379
+ pdfDocument: null,
380
+ zoomLevel: this.options.zoomLevel,
381
+ zoomLevelType: this.options.zoomLevelType,
382
+ zoomLevelBeforePrint: null
383
+ });
384
+ }
385
+ initEventBus() {
386
+ this.eventBus = new EventBus();
387
+ }
388
+ destroyEventBus() {
389
+ }
390
+ initLinkService() {
391
+ var _a;
392
+ this.linkService = new PDFLinkService({
393
+ eventBus: this.eventBus,
394
+ externalLinkTarget: LinkTarget.BLANK,
395
+ externalLinkRel: "noopener noreferrer nofollow",
396
+ ignoreDestinationZoom: false,
397
+ });
398
+ (_a = this.linkService) === null || _a === void 0 ? void 0 : _a.setViewer(this);
399
+ }
400
+ initAnnotationEditorUIManager() {
401
+ this.annotationEditorUIManager = new AnnotationEditorUIManager({
402
+ container: this.getDocumentContainer(),
403
+ // todo: pdf.js expects a dom element and not a component
404
+ viewer: this.element,
405
+ pdfViewer: this,
406
+ pdfDocument: this.state.pdfDocument,
407
+ eventBus: this.eventBus
408
+ });
409
+ this.setAnnotationEditorUIManagerScale();
410
+ }
411
+ setAnnotationEditorUIManagerScale() {
412
+ var _a;
413
+ // this is required when loading a new document
414
+ // so that annotation editors have correct positions during dragging
415
+ (_a = this.annotationEditorUIManager) === null || _a === void 0 ? void 0 : _a.onScaleChanging({
416
+ scale: this.options.zoomLevel
417
+ });
418
+ }
419
+ destroyAnnotationEditorUIManager() {
420
+ var _a;
421
+ (_a = this.annotationEditorUIManager) === null || _a === void 0 ? void 0 : _a.destroy();
422
+ }
423
+ bindEventBusAnnotationsEvents() {
424
+ const eventBus = this.eventBus = this.eventBus || new EventBus();
425
+ eventBus._on("switchannotationeditorparams", (evt) => {
426
+ this.annotationEditorParams = evt;
427
+ }
428
+ // { signal }
429
+ );
430
+ eventBus._on("switchannotationeditormode", evt => {
431
+ // todo: inline the call to this.annotationEditorMode = evt;
432
+ // this.annotationEditorMode = evt;
433
+ this.annotationEditorUIManager.updateParams(evt.type, evt.value);
434
+ const { mode, editId, isFromKeyboard } = evt;
435
+ this.annotationEditorUIManager.annotationEditorMode = evt;
436
+ this.annotationEditorUIManager.updateMode(mode, editId, isFromKeyboard);
437
+ eventBus.dispatch("annotationeditormodechanged", {
438
+ source: this,
439
+ mode,
440
+ });
441
+ }
442
+ // { signal }
443
+ );
444
+ eventBus._on("kendoAnnotationEditorToolBarShow", (evt) => {
445
+ var _a;
446
+ if (!evt) {
447
+ return;
448
+ }
449
+ const annotationEditorMode = this.annotationEditorUIManager.getMode();
450
+ if (annotationEditorMode === AnnotationEditorType.HIGHLIGHT ||
451
+ annotationEditorMode === AnnotationEditorType.FREETEXT) {
452
+ if (annotationEditorMode === AnnotationEditorType.HIGHLIGHT) {
453
+ this.addHighlightAnnotation();
454
+ }
455
+ this.triggerAnnotationEditorToolBarShow(Object.assign(Object.assign({}, evt), { annotationEditorMode: annotationEditorMode === AnnotationEditorType.HIGHLIGHT ? "highlight" : "freeText", anchor: evt.anchor || ((_a = this.annotationEditorUIManager.firstSelectedEditor) === null || _a === void 0 ? void 0 : _a.div) }));
456
+ }
457
+ }
458
+ // { signal }
459
+ );
460
+ eventBus._on("kendoAnnotationEditorToolBarHide", (evt) => {
461
+ if (!evt) {
462
+ return;
463
+ }
464
+ const annotationEditorMode = this.annotationEditorUIManager.getMode();
465
+ if (annotationEditorMode === AnnotationEditorType.HIGHLIGHT ||
466
+ annotationEditorMode === AnnotationEditorType.FREETEXT) {
467
+ this.triggerAnnotationEditorToolBarHide(Object.assign(Object.assign({}, evt), { annotationEditorMode: annotationEditorMode === AnnotationEditorType.HIGHLIGHT ? "highlight" : "freeText" }));
468
+ }
469
+ }
470
+ // { signal }
471
+ );
472
+ eventBus._on("showannotationeditorui", (evt) => {
473
+ switch (evt.mode) {
474
+ case AnnotationEditorType.HIGHLIGHT:
475
+ // editorHighlightButton.click();
476
+ eventBus.dispatch("switchannotationeditormode", {
477
+ source: this,
478
+ mode: AnnotationEditorType.HIGHLIGHT,
479
+ // {},...eventDetails,
480
+ // evt.detail is the number of clicks.
481
+ // isFromKeyboard: evt.detail === 0,
482
+ isFromKeyboard: false
483
+ });
484
+ break;
485
+ default: break;
486
+ }
487
+ }
488
+ // { signal }
489
+ );
490
+ }
491
+ unbindEventBusAnnotationsEvents() {
492
+ // this.eventBus.off();
493
+ }
494
+ loadFile(args) {
495
+ const fileData = args.data;
496
+ const loadFileOptions = {
497
+ data: null,
498
+ url: "",
499
+ arrayBuffer: null,
500
+ typedArray: null
501
+ };
502
+ if (fileData && (fileData.buffer instanceof ArrayBuffer || fileData instanceof ArrayBuffer)) {
503
+ loadFileOptions.arrayBuffer = fileData.buffer || fileData;
504
+ }
505
+ else if (isString(fileData) && fileData !== "") {
506
+ loadFileOptions.data = fileData;
507
+ loadFileOptions.url = null;
508
+ }
509
+ else if (isString(args.url) && args.url !== "") {
510
+ loadFileOptions.data = null;
511
+ loadFileOptions.url = args.url;
512
+ }
513
+ else if (args.typedArray) {
514
+ loadFileOptions.typedArray = args.typedArray;
515
+ }
516
+ if (args.data || args.url || args.arrayBuffer || args.typedArray) {
517
+ const readOptions = Object.assign({ dom: this.getPagesContainer(), zoom: this.options.zoomLevel }, loadFileOptions);
518
+ this.disableDocumentScrollEventsTracking();
519
+ this.clearDocument();
520
+ this.loadDocument(readOptions);
521
+ this.setScaleFactor(this.options.zoomLevel);
522
+ }
523
+ }
524
+ loadDocument(options) {
525
+ const params = this.getDocumentParameters(options);
526
+ const { zoom } = options;
527
+ this.clearDocumentState();
528
+ getDocument(params)
529
+ .promise.then((pdfDoc) => {
530
+ var _a;
531
+ (_a = this.linkService) === null || _a === void 0 ? void 0 : _a.setDocument(pdfDoc);
532
+ this.initDocumentAnnotationStorage(pdfDoc);
533
+ this.initAnnotationEditorUIManager();
534
+ this.bindEventBusAnnotationsEvents();
535
+ const pagesPromises = [];
536
+ for (let i = 1; i <= pdfDoc.numPages; i++) {
537
+ pagesPromises.push(pdfDoc.getPage(i));
538
+ }
539
+ return { pagesPromises: pagesPromises, pdfDoc };
540
+ })
541
+ .then(({ pagesPromises: pagesPromises, pdfDoc }) => {
542
+ this.state.pagesPromises = pagesPromises;
543
+ this.destroyPageComponents();
544
+ return this.drawPagesFromPromisesAsync(pagesPromises)
545
+ .then((pdfPages) => {
546
+ this.setHiddenCanvasStyles();
547
+ this.onPagesLoad({ pdfPages, pdfDoc, zoom });
548
+ })
549
+ .catch((e) => {
550
+ this.triggerError(e);
551
+ });
552
+ })
553
+ .catch((e) => {
554
+ this.triggerError(e);
555
+ });
556
+ }
557
+ initDocumentAnnotationStorage(pdfDocument) {
558
+ this.state.pdfDocument = pdfDocument;
559
+ this.pdfDocument = pdfDocument;
560
+ this.annotationStorage = new AnnotationStorage();
561
+ // todo: intentionally override the default value
562
+ // as it relies on checks like "instanceof <something>"
563
+ // but the classes from pdf.js are not exported
564
+ // and thus they are migrated, see https://github.com/mozilla/pdf.js/issues/18656
565
+ // Object.defineProperty(Object.getPrototypeOf(this.pdfDocument), 'annotationStorage', {
566
+ // get: () => {
567
+ // if (this.state.isPrintingInProgress) {
568
+ // return this.annotationStorage?.print;
569
+ // } else {
570
+ // return this.annotationStorage;
571
+ // }
572
+ // },
573
+ // set: (value) => {
574
+ // this.annotationStorage = value;
575
+ // },
576
+ // // this is required
577
+ // configurable: true
578
+ // });
579
+ Object.defineProperty(Object.getPrototypeOf(this.pdfDocument._transport), 'annotationStorage', {
580
+ get: () => {
581
+ var _a;
582
+ if (this.state.isPrintingInProgress) {
583
+ return (_a = this.annotationStorage) === null || _a === void 0 ? void 0 : _a.print;
584
+ }
585
+ else {
586
+ return this.annotationStorage;
587
+ }
588
+ },
589
+ set: (value) => {
590
+ this.annotationStorage = value;
591
+ },
592
+ // this is required
593
+ configurable: true
594
+ });
595
+ this._initializeAnnotationStorageCallbacks(pdfDocument);
596
+ }
597
+ _initializeAnnotationStorageCallbacks(pdfDocument) {
598
+ if (pdfDocument !== this.pdfDocument) {
599
+ return;
600
+ }
601
+ const { annotationStorage } = pdfDocument;
602
+ annotationStorage.onSetModified = () => {
603
+ // window.addEventListener("beforeunload", beforeUnload);
604
+ // if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
605
+ this._annotationStorageModified = true;
606
+ // }
607
+ };
608
+ annotationStorage.onResetModified = () => {
609
+ // window.removeEventListener("beforeunload", beforeUnload);
610
+ // if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
611
+ delete this._annotationStorageModified;
612
+ // }
613
+ };
614
+ annotationStorage.onAnnotationEditor = typeStr => {
615
+ this._hasAnnotationEditors = !!typeStr;
616
+ // this.setTitle();
617
+ };
618
+ }
619
+ drawPagesFromPromisesAsync(pagesPromises) {
620
+ return Promise.all(pagesPromises)
621
+ .then((pdfPages) => __awaiter(this, void 0, void 0, function* () {
622
+ const pages = yield Promise.all(this.drawPagesAsync(pdfPages));
623
+ this.appendPages(pages);
624
+ return pdfPages;
625
+ }));
626
+ }
627
+ drawPagesAsync(pdfPages) {
628
+ pdfPages = pdfPages || this.state.pdfPages;
629
+ const hasPages = (this.pages || []).length > 0;
630
+ if (!hasPages) {
631
+ this.initPageComponents(pdfPages);
632
+ }
633
+ else {
634
+ for (let i = 0; i < this.pages.length; i++) {
635
+ const pageViewport = this.pages[i].getViewport({
636
+ scale: this.state.zoomLevel
637
+ });
638
+ // todo: adjust page viewport manually
639
+ // otherwise, loading a document with links to the document
640
+ // will not scroll to the specific page on click
641
+ // pdf.js handles this in a more complex way
642
+ // that will require porting more code
643
+ this.pages[i].viewport = pageViewport;
644
+ }
645
+ }
646
+ const pageRenderPromises = [];
647
+ pdfPages.map((pdfPage, pageIndex) => __awaiter(this, void 0, void 0, function* () {
648
+ const page = this.pages[pageIndex];
649
+ if (this.options.loadOnDemand &&
650
+ pageIndex >= this.options.loadOnDemandPageSize &&
651
+ !page.element) {
652
+ const blankPageElements = this.createBlankPageElements({ pdfPage, zoom: this.state.zoomLevel });
653
+ if (page && !page.element) {
654
+ page.element = blankPageElements.pageElement;
655
+ page.setBlank(true);
656
+ }
657
+ const pageRenderPromise = createPromise();
658
+ pageRenderPromises.push(pageRenderPromise);
659
+ pageRenderPromise.then((renderedPage) => {
660
+ return renderedPage;
661
+ });
662
+ pageRenderPromise.resolve(page.element);
663
+ }
664
+ else if (this.options.loadOnDemand && page.isBlank()) {
665
+ // keep blank pages on reload
666
+ const pageRenderPromise = createPromise();
667
+ pageRenderPromises.push(pageRenderPromise);
668
+ pageRenderPromise.then((renderedPage) => {
669
+ return renderedPage;
670
+ });
671
+ pageRenderPromise.resolve(page.element);
672
+ }
673
+ else {
674
+ const pageRenderPromise = this.drawPageAsync({ pageIndex });
675
+ pageRenderPromises.push(pageRenderPromise);
676
+ pageRenderPromise.then((renderedPage) => {
677
+ return renderedPage;
678
+ });
679
+ }
680
+ }));
681
+ return pageRenderPromises;
682
+ }
683
+ createBlankPageElements({ pdfPage, zoom }) {
684
+ const pageElements = this.createPageElements({ pdfPage, zoom });
685
+ pageElements.canvasWrapper.appendChild(pageElements.canvas);
686
+ pageElements.pageElement.appendChild(pageElements.canvasWrapper);
687
+ return pageElements;
688
+ }
689
+ getDocumentParameters(options) {
690
+ let params = {
691
+ verbosity: 0,
692
+ isEvalSupported: true
693
+ };
694
+ if (typeof options.data === 'string' && options.data !== "") {
695
+ params.data = parsePdfFromBase64String(options.data);
696
+ }
697
+ else if (typeof options.url === 'string' && options.url !== "") {
698
+ params.url = options.url;
699
+ }
700
+ else if (options.arrayBuffer instanceof ArrayBuffer) {
701
+ params = options.arrayBuffer;
702
+ }
703
+ else if (options.typedArray) {
704
+ params = options.typedArray;
705
+ }
706
+ return params;
707
+ }
708
+ appendPages(pages) {
709
+ pages.forEach(page => this.appendPage(page));
710
+ }
711
+ appendPage(page, pageIndex = null) {
712
+ const pagesContainer = this.getPagesContainer();
713
+ if (hasValue(pageIndex)) {
714
+ pagesContainer === null || pagesContainer === void 0 ? void 0 : pagesContainer.insertBefore(page, pagesContainer.children[pageIndex]);
715
+ }
716
+ else {
717
+ pagesContainer === null || pagesContainer === void 0 ? void 0 : pagesContainer.appendChild(page);
718
+ }
719
+ }
720
+ drawPageAsync({ pageIndex = 0 }) {
721
+ var _a;
722
+ const index = clamp(pageIndex, 0, Math.max(0, this.state.pdfDocument.numPages - 1));
723
+ return (_a = this.pages[index]) === null || _a === void 0 ? void 0 : _a.draw().then(() => {
724
+ return this.pages[index].element;
725
+ });
726
+ }
727
+ createPageElements({ pdfPage = null, zoom = 1, }) {
728
+ if (zoom <= 0) {
729
+ return;
730
+ }
731
+ const viewportScale = getScale();
732
+ const scaleNum = zoom || viewportScale;
733
+ const viewport = pdfPage === null || pdfPage === void 0 ? void 0 : pdfPage.getViewport({ scale: viewportScale });
734
+ const { adjustedWidth, adjustedHeight, adjustRatio } = adjustCanvasSize(viewport.width, viewport.height);
735
+ // const styles = {
736
+ // width: Math.floor(viewport.width / scaleNum) * zoom + 'pt',
737
+ // height: Math.floor(viewport.height / scaleNum) * zoom + 'pt'
738
+ // };
739
+ // use PageView.setLayerDimensions
740
+ const { pageWidth, pageHeight } = viewport.rawDims;
741
+ const styles = {
742
+ // "round" is supported in all browsers since May 2024
743
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/round#browser_compatibility
744
+ width: `round(var(--scale-factor) * ${pageWidth}px, 1px)`,
745
+ height: `round(var(--scale-factor) * ${pageHeight}px, 1px)`
746
+ };
747
+ const pageElement = createElement("div", "k-page", styles);
748
+ const canvas = createElement("canvas", '', {
749
+ width: "100%",
750
+ height: "100%"
751
+ });
752
+ canvas.height = adjustedHeight;
753
+ canvas.width = adjustedWidth;
754
+ const canvasContext = canvas.getContext("2d");
755
+ const canvasWrapper = convertToHtml(`
756
+ <div class="${this.options.elementSelectors.pageCanvasWrapper}"></div>
757
+ `);
758
+ // canvasWrapper.appendChild(canvas);
759
+ // pageElement.appendChild(canvasWrapper);
760
+ const adjustedScale = adjustRatio * scaleNum;
761
+ viewport.width = adjustedWidth;
762
+ viewport.height = adjustedHeight;
763
+ viewport.scale = adjustedScale;
764
+ return {
765
+ canvasContext,
766
+ canvasWrapper,
767
+ canvas,
768
+ viewport,
769
+ scaleNum,
770
+ pageElement,
771
+ styles,
772
+ };
773
+ }
774
+ triggerPagesLoad(e) {
775
+ this.trigger(PAGES_LOAD, e);
776
+ }
777
+ triggerZoomStart(e) {
778
+ this.trigger(ZOOM_START, e);
779
+ }
780
+ triggerZoomEnd(e) {
781
+ this.trigger(ZOOM_END, e);
782
+ }
783
+ triggerDownload(e) {
784
+ return this.trigger(DOWNLOAD, e);
785
+ }
786
+ triggerAnnotationEditorToolBarShow(e) {
787
+ this.trigger(ANNOTATION_EDITOR_TOOLBAR_SHOW, e);
788
+ }
789
+ triggerAnnotationEditorToolBarHide(e) {
790
+ this.trigger(ANNOTATION_EDITOR_TOOLBAR_HIDE, e);
791
+ }
792
+ clearDocument() {
793
+ var _a;
794
+ this.clearPagesElements();
795
+ this.clearDocumentState();
796
+ (_a = this.linkService) === null || _a === void 0 ? void 0 : _a.setDocument(null);
797
+ }
798
+ clearDocumentState() {
799
+ this.state.pdfDocument = null;
800
+ this.state.pdfPages = [];
801
+ this.pages.forEach(x => x.destroy());
802
+ this.pages = [];
803
+ }
804
+ initPageComponents(pdfPages) {
805
+ // const scale = this.currentScale;
806
+ // const currentScale = scale();
807
+ const currentScale = this.options.zoomLevel;
808
+ const viewport = pdfPages[0].getViewport({
809
+ scale: currentScale * PixelsPerInch.PDF_TO_CSS_UNITS,
810
+ });
811
+ for (let pageNum = 1; pageNum <= pdfPages.length; pageNum++) {
812
+ const pageIndex = pageNum - 1;
813
+ const pageView = new Page(null, {
814
+ pdfViewer: this,
815
+ container: this.element,
816
+ eventBus: this.eventBus,
817
+ id: pageNum,
818
+ scale: currentScale,
819
+ viewport: viewport,
820
+ defaultViewport: viewport,
821
+ // optionalContentConfigPromise,
822
+ // renderingQueue: this.renderingQueue,
823
+ textLayerMode: TextLayerMode.ENABLE,
824
+ annotationMode: AnnotationMode.ENABLE,
825
+ // imageResourcesPath: this.imageResourcesPath,
826
+ // maxCanvasPixels: this.maxCanvasPixels,
827
+ // pageColors,
828
+ // l10n: this.l10n,
829
+ layerProperties: this._layerProperties,
830
+ // enableHWA: this.#enableHWA,
831
+ });
832
+ this.pages.push(pageView);
833
+ this.pages[pageIndex].setPdfPage(pdfPages[pageIndex]);
834
+ }
835
+ }
836
+ destroyPageComponents() {
837
+ this.pages.forEach(x => x.destroy());
838
+ this.pages = [];
839
+ }
840
+ clearPagesElements() {
841
+ const documentContainer = this.getDocumentContainer();
842
+ const pagesContainer = this.getPagesContainer();
843
+ if (!documentContainer || !pagesContainer || !this.hasDocument()) {
844
+ return;
845
+ }
846
+ const pages = this.getPagesElements();
847
+ pages.forEach(page => {
848
+ // @ts-expect-error TS(2345): Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
849
+ pagesContainer.removeChild(page);
850
+ });
851
+ }
852
+ initDocumentContainer() {
853
+ if (this.documentContainer) {
854
+ return;
855
+ }
856
+ this.documentContainer = this.getDocumentContainer();
857
+ this.initDocumentScroller(this.documentContainer);
858
+ }
859
+ initDocumentScroller(element) {
860
+ if (this.documentScroller || !element) {
861
+ return;
862
+ }
863
+ this.documentScroller = this.createDocumentScroller(element, {
864
+ filter: toClassSelector(this.options.elementSelectors.pageSelector),
865
+ events: {
866
+ [SCROLL]: this.onDocumentScrollerScroll
867
+ }
868
+ });
869
+ }
870
+ createDocumentScroller(element, options) {
871
+ return new Scroller(element, options);
872
+ }
873
+ destroyDocumentScroller() {
874
+ if (!this.documentScroller) {
875
+ return;
876
+ }
877
+ this.documentScroller.destroy();
878
+ this.documentScroller = null;
879
+ }
880
+ enableDocumentScrollEventsTracking() {
881
+ var _a;
882
+ (_a = this.documentScroller) === null || _a === void 0 ? void 0 : _a.enableScrollEventsTracking();
883
+ }
884
+ disableDocumentScrollEventsTracking() {
885
+ var _a;
886
+ (_a = this.documentScroller) === null || _a === void 0 ? void 0 : _a.disableScrollEventsTracking();
887
+ }
888
+ getCurrentPageIndex() {
889
+ return currentPage(this.element) || 0;
890
+ }
891
+ downloadFile({ fileName, saveOptions = {} }) {
892
+ this.downloadDocument({
893
+ options: {
894
+ pdf: this.state.pdfDocument
895
+ },
896
+ fileName: fileName || this.options.downloadFileName,
897
+ saveOptions: saveOptions
898
+ });
899
+ }
900
+ downloadDocument({ options, fileName = "Document", saveOptions = {}, }) {
901
+ if (options.pdf) {
902
+ let exportMethod = options.pdf.getData.bind(options.pdf);
903
+ let serializedAnnotationStorage = {};
904
+ let originalAnnotationStorage = {};
905
+ if (options.pdf.annotationStorage.size > 0) {
906
+ exportMethod = options.pdf.saveDocument.bind(options.pdf);
907
+ // saveDocument() has checks that test "editor instanceof AnnotationEditor", but they fail
908
+ // because AnnotationEditor from "pdfjs-dist/legacy/build/pdf.mjs" is not exported
909
+ // thus replace instances of editors with their serialized version
910
+ // and then revert
911
+ serializedAnnotationStorage = {};
912
+ originalAnnotationStorage = options.pdf.annotationStorage.getAll();
913
+ Object.keys(originalAnnotationStorage).forEach((key) => {
914
+ serializedAnnotationStorage[key] = originalAnnotationStorage[key].toJSON();
915
+ });
916
+ Object.keys(originalAnnotationStorage).forEach((key) => {
917
+ options.pdf.annotationStorage.remove(key);
918
+ });
919
+ Object.keys(serializedAnnotationStorage).forEach((key) => {
920
+ options.pdf.annotationStorage.setValue(key, serializedAnnotationStorage[key]);
921
+ });
922
+ }
923
+ exportMethod()
924
+ .then((data) => {
925
+ return new Blob([data], { type: 'application/pdf' });
926
+ })
927
+ .then((blob) => {
928
+ if (!this.triggerDownload({ blob, fileName, saveOptions })) {
929
+ this.saveFile(blob, fileName, saveOptions);
930
+ }
931
+ })
932
+ .catch((e) => {
933
+ this.triggerError(e);
934
+ })
935
+ .finally(() => {
936
+ var _a;
937
+ if (((_a = options.pdf) === null || _a === void 0 ? void 0 : _a.annotationStorage.size) <= 0) {
938
+ return;
939
+ }
940
+ const currentAnnotationStorage = options.pdf.annotationStorage.getAll();
941
+ Object.keys(currentAnnotationStorage).forEach((key) => {
942
+ options.pdf.annotationStorage.remove(key);
943
+ });
944
+ Object.keys(originalAnnotationStorage).forEach((key) => {
945
+ options.pdf.annotationStorage.setValue(key, originalAnnotationStorage[key]);
946
+ });
947
+ });
948
+ }
949
+ }
950
+ ;
951
+ saveFile(blob, fileName, saveOptions) {
952
+ try {
953
+ saveAs(blob, fileName, saveOptions);
954
+ }
955
+ catch (_a) {
956
+ return false;
957
+ }
958
+ return true;
959
+ }
960
+ hasDocument() {
961
+ return hasValue(this.state.pdfDocument);
962
+ }
963
+ zoom(args) {
964
+ args.zoomLevel = this.calculateZoomLevel({
965
+ zoomLevel: args.zoomLevel,
966
+ zoomLevelType: args.zoomLevelType,
967
+ currentZoom: this.options.zoomLevel,
968
+ });
969
+ this.options.zoomLevel = args.zoomLevel;
970
+ this.state.zoomLevel = args.zoomLevel;
971
+ this.eventBus.dispatch("scalechanging", {
972
+ source: this,
973
+ scale: this.options.zoomLevel,
974
+ });
975
+ this.reloadFile(this.state.pdfDocument);
976
+ }
977
+ calculateZoomLevel({ zoomLevel, zoomLevelType, currentZoom }) {
978
+ const documentContainer = this.getDocumentContainer();
979
+ const page = documentContainer.querySelector(toClassSelector(this.options.elementSelectors.pageSelector));
980
+ const pageSize = { width: page.offsetWidth, height: page.offsetHeight };
981
+ let calculatedZoomLevel = clamp(zoomLevel || DEFAULT_ZOOM_LEVEL, this.options.minZoom, this.options.maxZoom);
982
+ if (zoomLevelType === "ActualWidth" || zoomLevelType === "actualWidth") {
983
+ calculatedZoomLevel = 1;
984
+ }
985
+ else if (zoomLevelType === "FitToWidth" || zoomLevelType === "fitToWidth") {
986
+ calculatedZoomLevel = documentContainer.offsetWidth / (pageSize.width / currentZoom);
987
+ }
988
+ else if (zoomLevelType === "FitToPage" || zoomLevelType === "fitToPage") {
989
+ calculatedZoomLevel = documentContainer.offsetHeight / (pageSize.height / currentZoom);
990
+ }
991
+ return calculatedZoomLevel;
992
+ }
993
+ reloadFile(pdfDoc) {
994
+ const pagesPromises = [];
995
+ for (let i = 1; i <= pdfDoc.numPages; i++) {
996
+ pagesPromises.push(pdfDoc.getPage(i));
997
+ }
998
+ this.disableDocumentScrollEventsTracking();
999
+ this.drawPagesFromPromisesAsync(pagesPromises)
1000
+ .then((pdfPages) => {
1001
+ this.setHiddenCanvasStyles();
1002
+ this.onPagesLoad({ pdfPages, pdfDoc });
1003
+ })
1004
+ .catch((e) => {
1005
+ this.triggerError(e);
1006
+ });
1007
+ this.setScaleFactor(this.state.zoomLevel);
1008
+ }
1009
+ setHiddenCanvasStyles() {
1010
+ if (!this.options.pdfjsSetHiddenCanvasStyles) {
1011
+ return;
1012
+ }
1013
+ // required after pdf.js 4.x version
1014
+ const sheet = new CSSStyleSheet();
1015
+ sheet.replaceSync(`.hiddenCanvasElement {
1016
+ position: absolute;
1017
+ top: 0;
1018
+ left: 0;
1019
+ width: 0;
1020
+ height: 0;
1021
+ display: none;
1022
+ }`);
1023
+ this.getPagesContainer().ownerDocument.adoptedStyleSheets = [sheet];
1024
+ }
1025
+ printFile() {
1026
+ if (!this.hasDocument()) {
1027
+ return;
1028
+ }
1029
+ this.setState({
1030
+ isPrintingInProgress: true
1031
+ });
1032
+ if (this.options.zoomBeforePrint) {
1033
+ // such option existed in the Kendo jQuery version internally
1034
+ this.cacheZoomLevelBeforePrint();
1035
+ this.loadDocumentForPrintAsync({
1036
+ zoomLevel: this.options.zoomLevelBeforePrint,
1037
+ force: true
1038
+ })
1039
+ .then(() => {
1040
+ this.printDocumentAsync()
1041
+ .then(() => {
1042
+ this.trigger(PRINT_END);
1043
+ });
1044
+ })
1045
+ .catch(this.triggerError)
1046
+ .finally(() => {
1047
+ this.setState({
1048
+ isPrintingInProgress: false
1049
+ });
1050
+ this.restoreZoomLevelBeforePrint();
1051
+ });
1052
+ }
1053
+ else {
1054
+ this.loadDocumentForPrintAsync({
1055
+ zoomLevel: this.state.zoomLevel,
1056
+ force: true
1057
+ })
1058
+ .then(() => {
1059
+ this.printDocumentAsync()
1060
+ .then(() => {
1061
+ this.trigger(PRINT_END);
1062
+ });
1063
+ })
1064
+ .catch(this.triggerError)
1065
+ .finally(() => {
1066
+ this.setState({
1067
+ isPrintingInProgress: false
1068
+ });
1069
+ });
1070
+ }
1071
+ }
1072
+ loadDocumentForPrintAsync({ zoomLevel = DEFAULT_ZOOM_LEVEL, force = false }) {
1073
+ const pages = this.pages;
1074
+ const pageLoadPromises = [];
1075
+ const loadPromise = createPromise();
1076
+ for (let i = 0; i < pages.length; i++) {
1077
+ const pageLoadPromise = pages[i].loadForPrintAsync({
1078
+ zoomLevel: zoomLevel,
1079
+ force: force
1080
+ });
1081
+ pageLoadPromises.push(pageLoadPromise);
1082
+ }
1083
+ Promise.all(pageLoadPromises)
1084
+ .then(() => {
1085
+ // @ts-expect-error TS()
1086
+ loadPromise.resolve();
1087
+ });
1088
+ return loadPromise;
1089
+ }
1090
+ getPagesPrintContentAsync(printContainer) {
1091
+ const pages = this.pages;
1092
+ const pagePrintPromises = [];
1093
+ for (let i = 0; i < pages.length; i++) {
1094
+ const pagePrintPromise = pages[i].getPrintContentAsync();
1095
+ pagePrintPromise.then((pagePrintContent) => {
1096
+ const pageWrapper = convertToHtml(`<div></div>`);
1097
+ pageWrapper.appendChild(pagePrintContent);
1098
+ printContainer.appendChild(pageWrapper);
1099
+ });
1100
+ pagePrintPromises.push(pagePrintPromise);
1101
+ }
1102
+ return pagePrintPromises;
1103
+ }
1104
+ initPrintContainer() {
1105
+ this.printContainer = convertToHtml(`<div></div>`);
1106
+ }
1107
+ openPrintDialog() {
1108
+ const pages = this.pages;
1109
+ const width = pages[0].rawWidth;
1110
+ const height = pages[0].rawHeight;
1111
+ const printDialog = window.open('', '', 'innerWidth=' + width + ',innerHeight=' + height + 'location=no,titlebar=no,toolbar=no');
1112
+ if (!printDialog || !printDialog.document) {
1113
+ this.triggerError({
1114
+ message: this.options.messages.errorMessages.popupBlocked
1115
+ });
1116
+ return;
1117
+ }
1118
+ printDialog.document.body.style.margin = '0';
1119
+ printDialog.document.body.appendChild(this.printContainer);
1120
+ const afterPrintHandler = () => {
1121
+ printDialog.removeEventListener("afterprint", afterPrintHandler);
1122
+ printDialog.close();
1123
+ };
1124
+ printDialog.addEventListener("afterprint", afterPrintHandler);
1125
+ printDialog.focus();
1126
+ printDialog.print();
1127
+ // setTimeout(() => {
1128
+ // printDialog.print();
1129
+ // done();
1130
+ // });
1131
+ }
1132
+ cacheZoomLevelBeforePrint() {
1133
+ this.setState({
1134
+ zoomLevelBeforePrint: this.state.zoomLevel
1135
+ });
1136
+ }
1137
+ restoreZoomLevelBeforePrint() {
1138
+ if (this.state.zoomLevelBeforePrint === this.state.zoomLevel) {
1139
+ return;
1140
+ }
1141
+ this.zoom({
1142
+ zoomLevel: this.state.zoomLevelBeforePrint,
1143
+ zoomLevelType: this.state.zoomLevelType,
1144
+ currentZoom: this.state.zoomLevel
1145
+ });
1146
+ }
1147
+ searchText(options = { text: "", matchCase: false }) {
1148
+ var _a;
1149
+ this.initSearchService();
1150
+ return (_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(options);
1151
+ }
1152
+ clearSearch() {
1153
+ this.destroySearchService();
1154
+ }
1155
+ initSearchService() {
1156
+ if (this.searchService) {
1157
+ return;
1158
+ }
1159
+ const pagesTextLayers = this.wrapper.querySelectorAll(toClassSelector(this.options.elementSelectors.textLayerClass));
1160
+ this.searchService = new SearchService({
1161
+ textContainers: pagesTextLayers || [],
1162
+ highlightClass: this.options.elementSelectors.searchHighlightClass,
1163
+ highlightMarkClass: this.options.elementSelectors.searchHighlightMarkClass,
1164
+ charClass: this.options.elementSelectors.charClass
1165
+ });
1166
+ }
1167
+ destroySearchService() {
1168
+ if (!this.searchService) {
1169
+ return;
1170
+ }
1171
+ this.searchService.destroy();
1172
+ this.searchService = null;
1173
+ }
1174
+ getPagesContainer() {
1175
+ return this.element.querySelector(toClassSelector(this.options.elementSelectors.pagesContainerClass));
1176
+ }
1177
+ getDocumentContainer() {
1178
+ return this.wrapper.querySelector(toClassSelector(this.options.elementSelectors.documentContainerClass));
1179
+ }
1180
+ getPagesElements() {
1181
+ const documentContainer = this.getDocumentContainer();
1182
+ if (!documentContainer) {
1183
+ return [];
1184
+ }
1185
+ return toArray(documentContainer.querySelectorAll(toClassSelector(this.options.elementSelectors.pageSelector)));
1186
+ }
1187
+ goToNextSearchMatch() {
1188
+ if (!this.searchService) {
1189
+ return;
1190
+ }
1191
+ this.searchService.markNextMatch();
1192
+ const matchElement = this.searchService.getActiveMatchElement();
1193
+ this.scrollToSearchMatch(matchElement);
1194
+ }
1195
+ goToPreviousSearchMatch() {
1196
+ if (!this.searchService) {
1197
+ return;
1198
+ }
1199
+ this.searchService.markPreviousMatch();
1200
+ const matchElement = this.searchService.getActiveMatchElement();
1201
+ this.scrollToSearchMatch(matchElement);
1202
+ }
1203
+ scrollToSearchMatch(matchElement) {
1204
+ if (!matchElement) {
1205
+ return;
1206
+ }
1207
+ const closestCharElement = matchElement.closest('.k-text-char');
1208
+ const closestTextElement = closestCharElement
1209
+ ? closestCharElement.closest('span[role="presentation"]')
1210
+ : null;
1211
+ if (!closestTextElement) {
1212
+ return;
1213
+ }
1214
+ const closestPageElement = closestTextElement.closest('.k-page');
1215
+ if (!closestPageElement) {
1216
+ return;
1217
+ }
1218
+ const scrollLeft = closestPageElement.offsetLeft +
1219
+ -1 * this.documentScroller.element.offsetLeft +
1220
+ closestTextElement.offsetLeft +
1221
+ this.options.searchMatchScrollLeftOffset;
1222
+ const scrollTop = closestPageElement.offsetTop +
1223
+ -1 * this.documentScroller.element.offsetTop +
1224
+ closestTextElement.offsetTop +
1225
+ this.options.searchMatchScrollTopOffset;
1226
+ this.documentScroller.scrollTo(scrollLeft, scrollTop, { trackScrollEvent: false });
1227
+ }
1228
+ resetInteractionMode() {
1229
+ this.setInteractionMode({
1230
+ mode: PdfViewerInteractionMode.TextSelection
1231
+ });
1232
+ }
1233
+ setInteractionMode(args) {
1234
+ this.interactionMode = args.mode;
1235
+ if (this.interactionMode === PdfViewerInteractionMode.TextSelection) {
1236
+ this.disableScrollerEventsTracking();
1237
+ addClass(this.options.elementSelectors.enabledTextSelectionClass, this.documentScroller.element);
1238
+ removeClass(this.options.elementSelectors.enabledPanningClass, this.documentScroller.element);
1239
+ }
1240
+ else if (this.interactionMode === PdfViewerInteractionMode.Pan) {
1241
+ this.enableScrollerEventsTracking();
1242
+ removeClass(this.options.elementSelectors.enabledTextSelectionClass, this.documentScroller.element);
1243
+ addClass(this.options.elementSelectors.enabledPanningClass, this.documentScroller.element);
1244
+ }
1245
+ }
1246
+ enableScrollerEventsTracking() {
1247
+ if (!this.documentScroller) {
1248
+ return;
1249
+ }
1250
+ this.documentScroller.enablePanEventsTracking();
1251
+ }
1252
+ disableScrollerEventsTracking() {
1253
+ if (!this.documentScroller) {
1254
+ return;
1255
+ }
1256
+ this.documentScroller.disablePanEventsTracking();
1257
+ }
1258
+ setScaleFactor(scaleFactor) {
1259
+ this.element.style.setProperty('--scale-factor', String(scaleFactor * PixelsPerInch.PDF_TO_CSS_UNITS));
1260
+ }
1261
+ activatePageNumber(pageNumber) {
1262
+ const page = this.getPageByNumber(pageNumber);
1263
+ if (!page) {
1264
+ return;
1265
+ }
1266
+ const pageIndex = pageNumber - 1;
1267
+ if (this.state.activePageNumber === pageNumber) {
1268
+ return;
1269
+ }
1270
+ this.state.activePageNumber = pageNumber;
1271
+ if (page.isBlank()) {
1272
+ this.drawPageAsync({ pageIndex: pageIndex })
1273
+ .then(() => {
1274
+ this.scrollToPage({
1275
+ pageNumber
1276
+ });
1277
+ });
1278
+ }
1279
+ else {
1280
+ this.scrollToPage({
1281
+ pageNumber
1282
+ });
1283
+ }
1284
+ }
1285
+ scrollToPage({ pageNumber }) {
1286
+ const { left, top } = this.getPageNumberScrollOffset(pageNumber);
1287
+ this.scrollDocument({
1288
+ left: left,
1289
+ top: top
1290
+ });
1291
+ }
1292
+ scrollDocument({ left, top }) {
1293
+ var _a;
1294
+ (_a = this.documentScroller) === null || _a === void 0 ? void 0 : _a.scrollTo(left, top, {
1295
+ // as we are manually scrolling to the page
1296
+ // we want to ignore the scroller's element scroll event
1297
+ // to avoid double handling of the scrolling
1298
+ trackScrollEvent: false
1299
+ });
1300
+ }
1301
+ getPageNumberScrollOffset(pageNumber) {
1302
+ const page = this.getPageByNumber(pageNumber);
1303
+ if (!page) {
1304
+ return {
1305
+ left: 0,
1306
+ top: 0
1307
+ };
1308
+ }
1309
+ // pages might have different sizes
1310
+ // although pdf.js does not fully support this
1311
+ const previousPages = this.pages.slice(0, Math.max(0, pageNumber - 1));
1312
+ const previousPagesScrollOffset = previousPages
1313
+ .map(x => {
1314
+ const pageScrollOffset = this.getPageScrollOffset(x);
1315
+ return pageScrollOffset;
1316
+ })
1317
+ .reduce((sum, pageScrollOffset) => sum + pageScrollOffset, 0);
1318
+ return {
1319
+ left: 0,
1320
+ top: previousPagesScrollOffset
1321
+ };
1322
+ }
1323
+ getPageScrollOffset(page) {
1324
+ var _a;
1325
+ const pageHeight = ((_a = page === null || page === void 0 ? void 0 : page.element) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height) || 0;
1326
+ const computedStyles = getComputedStyle(page.element);
1327
+ const pageMarginTop = parseFloat(computedStyles.marginTop) || 0;
1328
+ return pageHeight + pageMarginTop;
1329
+ }
1330
+ getPageByNumber(pageNumber) {
1331
+ const page = this.pages && this.pages[pageNumber - 1];
1332
+ return page;
1333
+ }
1334
+ addHighlightAnnotation() {
1335
+ var _a;
1336
+ (_a = this.annotationEditorUIManager) === null || _a === void 0 ? void 0 : _a.highlightSelection();
1337
+ }
1338
+ setHighlightColor(color) {
1339
+ this.executeAnnotationCommand({
1340
+ commandType: AnnotationEditorParamsType.HIGHLIGHT_COLOR,
1341
+ commandValue: color
1342
+ });
1343
+ }
1344
+ deleteAnnotation() {
1345
+ var _a;
1346
+ (_a = this.annotationEditorUIManager) === null || _a === void 0 ? void 0 : _a.delete();
1347
+ }
1348
+ resetAnnotationEditorMode() {
1349
+ this.setAnnotationEditorMode({
1350
+ mode: AnnotationEditorType.NONE,
1351
+ editId: null,
1352
+ isFromKeyboard: false
1353
+ });
1354
+ }
1355
+ setAnnotationEditorMode(modeDescriptor) {
1356
+ this.annotationEditorMode = modeDescriptor;
1357
+ }
1358
+ setFreeTextColor(color) {
1359
+ this.executeAnnotationCommand({
1360
+ commandType: AnnotationEditorParamsType.FREETEXT_COLOR,
1361
+ commandValue: color
1362
+ });
1363
+ }
1364
+ setFreeTextFontSize(fontSize) {
1365
+ this.executeAnnotationCommand({
1366
+ commandType: AnnotationEditorParamsType.FREETEXT_SIZE,
1367
+ commandValue: parseFloat(fontSize)
1368
+ });
1369
+ }
1370
+ executeAnnotationCommand({ commandType, commandValue }) {
1371
+ this.eventBus.dispatch("switchannotationeditorparams", {
1372
+ source: this,
1373
+ type: commandType,
1374
+ value: commandValue
1375
+ });
1376
+ }
1377
+ // todo: ported from pdf.js
1378
+ isValidAnnotationEditorMode(mode) {
1379
+ return Object.values(AnnotationEditorType).includes(mode) && mode !== AnnotationEditorType.DISABLE;
1380
+ }
1381
+ cleanupSwitchAnnotationEditorMode() {
1382
+ if (__classPrivateFieldGet(this, _PdfViewer_onPageRenderedCallback, "f")) {
1383
+ this.eventBus._off("pagerendered", __classPrivateFieldGet(this, _PdfViewer_onPageRenderedCallback, "f"));
1384
+ __classPrivateFieldSet(this, _PdfViewer_onPageRenderedCallback, null, "f");
1385
+ }
1386
+ if (__classPrivateFieldGet(this, _PdfViewer_switchAnnotationEditorModeTimeoutId, "f") !== null) {
1387
+ clearTimeout(__classPrivateFieldGet(this, _PdfViewer_switchAnnotationEditorModeTimeoutId, "f"));
1388
+ __classPrivateFieldSet(this, _PdfViewer_switchAnnotationEditorModeTimeoutId, null, "f");
1389
+ }
1390
+ }
1391
+ _getVisiblePages() {
1392
+ // const views =
1393
+ // this._scrollMode === ScrollMode.PAGE
1394
+ // ? this.#scrollModePageState.pages
1395
+ // : this._pages,
1396
+ // horizontal = this._scrollMode === ScrollMode.HORIZONTAL,
1397
+ // rtl = horizontal && this._isContainerRtl;
1398
+ // return getVisibleElements({
1399
+ // scrollEl: this.container,
1400
+ // views,
1401
+ // sortByVisibility: true,
1402
+ // horizontal,
1403
+ // rtl,
1404
+ // });
1405
+ return this.pages;
1406
+ }
1407
+ get _layerProperties() {
1408
+ const self = this;
1409
+ return shadow(this, "_layerProperties", {
1410
+ get annotationEditorUIManager() {
1411
+ return self.annotationEditorUIManager;
1412
+ },
1413
+ get annotationStorage() {
1414
+ var _a;
1415
+ return (_a = self.pdfDocument) === null || _a === void 0 ? void 0 : _a.annotationStorage;
1416
+ },
1417
+ // get downloadManager() {
1418
+ // return self.downloadManager;
1419
+ // },
1420
+ // get enableScripting() {
1421
+ // return !!self._scriptingManager;
1422
+ // },
1423
+ // get fieldObjectsPromise() {
1424
+ // return self.pdfDocument?.getFieldObjects();
1425
+ // },
1426
+ // get findController() {
1427
+ // return self.findController;
1428
+ // },
1429
+ // get hasJSActionsPromise() {
1430
+ // return self.pdfDocument?.hasJSActions();
1431
+ // },
1432
+ get linkService() {
1433
+ return self.linkService;
1434
+ },
1435
+ });
1436
+ }
1437
+ /**
1438
+ * Scrolls page into view.
1439
+ * @param {ScrollPageIntoViewParameters} params
1440
+ */
1441
+ scrollPageIntoView({ pageNumber, destArray = null, allowNegativeOffset = false, ignoreDestinationZoom = false, }) {
1442
+ if (!this.pdfDocument) {
1443
+ return;
1444
+ }
1445
+ const pageView = Number.isInteger(pageNumber) && this.pages[pageNumber - 1];
1446
+ if (!pageView) {
1447
+ // console.error(
1448
+ // `scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`
1449
+ // );
1450
+ return;
1451
+ }
1452
+ if (this.isInPresentationMode || !destArray) {
1453
+ this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
1454
+ return;
1455
+ }
1456
+ let x = 0, y = 0;
1457
+ const width = 0, height = 0;
1458
+ // widthScale,
1459
+ // heightScale;
1460
+ const changeOrientation = pageView.rotation % 180 !== 0;
1461
+ // const pageWidth =
1462
+ // (changeOrientation ? pageView.height : pageView.width) /
1463
+ // pageView.scale /
1464
+ // PixelsPerInch.PDF_TO_CSS_UNITS;
1465
+ const pageHeight = (changeOrientation ? pageView.rawWidth : pageView.rawHeight) /
1466
+ pageView.scale /
1467
+ PixelsPerInch.PDF_TO_CSS_UNITS;
1468
+ // let scale: any = 0;
1469
+ switch (destArray[1].name) {
1470
+ case "XYZ":
1471
+ x = destArray[2];
1472
+ y = destArray[3];
1473
+ // scale = destArray[4];
1474
+ // If x and/or y coordinates are not supplied, default to
1475
+ // _top_ left of the page (not the obvious bottom left,
1476
+ // since aligning the bottom of the intended page with the
1477
+ // top of the window is rarely helpful).
1478
+ x = x !== null ? x : 0;
1479
+ y = y !== null ? y : pageHeight;
1480
+ break;
1481
+ // case "Fit":
1482
+ // case "FitB":
1483
+ // scale = "page-fit";
1484
+ // break;
1485
+ // case "FitH":
1486
+ // case "FitBH":
1487
+ // y = destArray[2];
1488
+ // scale = "page-width";
1489
+ // // According to the PDF spec, section 12.3.2.2, a `null` value in the
1490
+ // // parameter should maintain the position relative to the new page.
1491
+ // if (y === null && this._location) {
1492
+ // x = this._location.left;
1493
+ // y = this._location.top;
1494
+ // } else if (typeof y !== "number" || y < 0) {
1495
+ // // The "top" value isn't optional, according to the spec, however some
1496
+ // // bad PDF generators will pretend that it is (fixes bug 1663390).
1497
+ // y = pageHeight;
1498
+ // }
1499
+ // break;
1500
+ // case "FitV":
1501
+ // case "FitBV":
1502
+ // x = destArray[2];
1503
+ // width = pageWidth;
1504
+ // height = pageHeight;
1505
+ // scale = "page-height";
1506
+ // break;
1507
+ // case "FitR":
1508
+ // x = destArray[2];
1509
+ // y = destArray[3];
1510
+ // width = destArray[4] - x;
1511
+ // height = destArray[5] - y;
1512
+ // let hPadding = SCROLLBAR_PADDING,
1513
+ // vPadding = VERTICAL_PADDING;
1514
+ // if (
1515
+ // (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
1516
+ // this.removePageBorders
1517
+ // ) {
1518
+ // hPadding = vPadding = 0;
1519
+ // }
1520
+ // widthScale =
1521
+ // (this.container.clientWidth - hPadding) /
1522
+ // width /
1523
+ // PixelsPerInch.PDF_TO_CSS_UNITS;
1524
+ // heightScale =
1525
+ // (this.container.clientHeight - vPadding) /
1526
+ // height /
1527
+ // PixelsPerInch.PDF_TO_CSS_UNITS;
1528
+ // scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
1529
+ // break;
1530
+ default:
1531
+ // console.error(
1532
+ // `scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`
1533
+ // );
1534
+ return;
1535
+ }
1536
+ if (!ignoreDestinationZoom) {
1537
+ // if (scale && scale !== this.options.zoomLevel) {
1538
+ // }
1539
+ // if (scale && scale !== this._currentScale) {
1540
+ // this.currentScaleValue = scale;
1541
+ // } else if (this._currentScale === UNKNOWN_SCALE) {
1542
+ // this.currentScaleValue = DEFAULT_SCALE_VALUE;
1543
+ // }
1544
+ }
1545
+ // if (scale === "page-fit" && !destArray[4]) {
1546
+ // this.#scrollIntoView(pageView);
1547
+ // return;
1548
+ // }
1549
+ const boundingRect = [
1550
+ pageView.viewport.convertToViewportPoint(x, y),
1551
+ pageView.viewport.convertToViewportPoint(x + width, y + height),
1552
+ ];
1553
+ let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
1554
+ let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
1555
+ if (!allowNegativeOffset) {
1556
+ // Some bad PDF generators will create destinations with e.g. top values
1557
+ // that exceeds the page height. Ensure that offsets are not negative,
1558
+ // to prevent a previous page from becoming visible (fixes bug 874482).
1559
+ left = Math.max(left, 0);
1560
+ top = Math.max(top, 0);
1561
+ }
1562
+ // left *= scale || this.state.zoomLevel;
1563
+ // top *= scale || this.state.zoomLevel;
1564
+ __classPrivateFieldGet(this, _PdfViewer_instances, "m", _PdfViewer_scrollIntoView).call(this, pageView, /* pageSpot = */ { left, top });
1565
+ }
1566
+ /**
1567
+ * @returns {boolean} Whether the pageNumber is valid (within bounds).
1568
+ * @private
1569
+ */
1570
+ _setCurrentPageNumber(val, resetCurrentPageView = false) {
1571
+ if (this._currentPageNumber === val) {
1572
+ if (resetCurrentPageView) {
1573
+ // this.#resetCurrentPageView();
1574
+ }
1575
+ return true;
1576
+ }
1577
+ // if (!(0 < val && val <= this.pagesCount)) {
1578
+ if (!(0 < val && val <= this.state.pdfDocument.numPages)) {
1579
+ return false;
1580
+ }
1581
+ const previous = this._currentPageNumber;
1582
+ this._currentPageNumber = val;
1583
+ this.eventBus.dispatch("pagechanging", {
1584
+ source: this,
1585
+ pageNumber: val,
1586
+ // pageLabel: this._pageLabels?.[val - 1] ?? null,
1587
+ previous,
1588
+ });
1589
+ // if (resetCurrentPageView) {
1590
+ // this.#resetCurrentPageView();
1591
+ // }
1592
+ return true;
1593
+ }
1594
+ }
1595
+ _PdfViewer_annotationEditorMode = new WeakMap(), _PdfViewer_switchAnnotationEditorModeTimeoutId = new WeakMap(), _PdfViewer_eventAbortController = new WeakMap(), _PdfViewer_onPageRenderedCallback = new WeakMap(), _PdfViewer_instances = new WeakSet(), _PdfViewer_switchToEditAnnotationMode = function _PdfViewer_switchToEditAnnotationMode() {
1596
+ // const visible = this._getVisiblePages();
1597
+ // const visible = this._getVisiblePages();
1598
+ const pagesToRefresh = [];
1599
+ // const { ids, views } = visible;
1600
+ // for (const page of views) {
1601
+ const ids = new Set();
1602
+ this.pages.forEach(x => {
1603
+ ids.add(x.id);
1604
+ });
1605
+ for (const page of this.pages) {
1606
+ // const { view } = page;
1607
+ const view = page;
1608
+ if (!view.hasEditableAnnotations()) {
1609
+ ids.delete(view.id);
1610
+ continue;
1611
+ }
1612
+ pagesToRefresh.push(page);
1613
+ }
1614
+ if (pagesToRefresh.length === 0) {
1615
+ return null;
1616
+ }
1617
+ // this.renderingQueue.renderHighestPriority({
1618
+ // first: pagesToRefresh[0],
1619
+ // last: pagesToRefresh.at(-1),
1620
+ // views: pagesToRefresh,
1621
+ // ids,
1622
+ // });
1623
+ // todo: render pages instead of using renderingQueue
1624
+ // as this will require porting more code
1625
+ this.drawPagesAsync(this.state.pdfPages);
1626
+ return ids;
1627
+ }, _PdfViewer_scrollIntoView = function _PdfViewer_scrollIntoView(pageView, pageSpot = null) {
1628
+ const { div, id } = pageView;
1629
+ // Ensure that `this._currentPageNumber` is correct, when `#scrollIntoView`
1630
+ // is called directly (and not from `#resetCurrentPageView`).
1631
+ if (this._currentPageNumber !== id) {
1632
+ this._setCurrentPageNumber(id);
1633
+ }
1634
+ // if (this._scrollMode === ScrollMode.PAGE) {
1635
+ // this.#ensurePageViewVisible();
1636
+ // // Ensure that rendering always occurs, to avoid showing a blank page,
1637
+ // // even if the current position doesn't change when the page is scrolled.
1638
+ // this.update();
1639
+ // }
1640
+ if (!pageSpot && !this.isInPresentationMode) {
1641
+ const left = div.offsetLeft + div.clientLeft, right = left + div.clientWidth;
1642
+ // const { scrollLeft, clientWidth } = this.container;
1643
+ const { scrollLeft, clientWidth } = this.element;
1644
+ if (this._scrollMode === ScrollMode.HORIZONTAL ||
1645
+ left < scrollLeft ||
1646
+ right > scrollLeft + clientWidth) {
1647
+ pageSpot = { left: 0, top: 0 };
1648
+ }
1649
+ }
1650
+ scrollIntoView(div, pageSpot);
1651
+ // // Ensure that the correct *initial* document position is set, when any
1652
+ // // OpenParameters are used, for documents with non-default Scroll/Spread
1653
+ // // modes (fixes issue 15695). This is necessary since the scroll-handler
1654
+ // // invokes the `update`-method asynchronously, and `this._location` could
1655
+ // // thus be wrong when the initial zooming occurs in the default viewer.
1656
+ // if (!this._currentScaleValue && this._location) {
1657
+ // this._location = null;
1658
+ // }
1659
+ };