@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,763 @@
1
+ "use strict";
2
+ var _Page_instances, _Page_annotationMode, _Page_isEditing, _Page_layerProperties, _Page_previousRotation, _Page_renderingState, _Page_textLayerMode, _Page_viewportMap, _Page_layers, _Page_addLayer, _Page_setDimensions, _Page_dispatchLayerRendered, _Page_renderAnnotationLayer, _Page_renderAnnotationEditorLayer, _Page_renderDrawLayer, _Page_renderTextLayer, _Page_finishRenderTask;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Page = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const pdf_mjs_1 = require("pdfjs-dist/legacy/build/pdf.mjs");
7
+ const text_accessibility_manager_1 = require("../annotations/helpers/text-accessibility-manager");
8
+ const component_1 = require("../common/component");
9
+ const core_1 = require("../common/core");
10
+ const text_layer_builder_1 = require("../text/text-layer-builder");
11
+ const ui_utils_1 = require("../annotations/shared/ui_utils");
12
+ const annotation_layer_builder_1 = require("../annotations/annotation-layer-builder");
13
+ const draw_layer_builder_1 = require("../annotations/draw-layer-builder");
14
+ const annotation_editor_layer_builder_1 = require("../annotations/annotation-editor-layer-builder");
15
+ const DEFAULT_ZOOM_LEVEL = 1.25;
16
+ const DEFAULT_LAYER_PROPERTIES = {
17
+ annotationEditorUIManager: null,
18
+ annotationStorage: null,
19
+ downloadManager: null,
20
+ enableScripting: false,
21
+ fieldObjectsPromise: null,
22
+ findController: null,
23
+ hasJSActionsPromise: null,
24
+ get linkService() {
25
+ // return new SimpleLinkService();
26
+ return null;
27
+ },
28
+ };
29
+ const LAYERS_ORDER = new Map([
30
+ ["canvasWrapper", 0],
31
+ ["textLayer", 1],
32
+ ["annotationLayer", 2],
33
+ ["annotationEditorLayer", 3],
34
+ ["xfaLayer", 3],
35
+ ]);
36
+ class Page extends component_1.Component {
37
+ constructor(element, options) {
38
+ super(element, options);
39
+ _Page_instances.add(this);
40
+ // todo: props
41
+ this.eventBus = null;
42
+ this.zoomLayer = null;
43
+ this.div = null;
44
+ this.viewport = null;
45
+ this.id = 1;
46
+ this._accessibilityManager = null;
47
+ this._annotationCanvasMap = new Map();
48
+ this.renderTask = null;
49
+ this.pdfPageRotate = null;
50
+ this.rotation = null;
51
+ this.scale = null;
52
+ this.pdfViewer = null;
53
+ // todo: props
54
+ // todo: props ported from pdf.js
55
+ this.xfaLayer = null;
56
+ _Page_annotationMode.set(this, pdf_mjs_1.AnnotationMode.ENABLE_FORMS);
57
+ // #enableHWA = false;
58
+ // #hasRestrictedScaling = false;
59
+ // // @ts-expect-error(TS)
60
+ _Page_isEditing.set(this, false);
61
+ _Page_layerProperties.set(this, null);
62
+ // #loadingId = null;
63
+ _Page_previousRotation.set(this, null);
64
+ // #renderError = null;
65
+ _Page_renderingState.set(this, ui_utils_1.RenderingStates.INITIAL);
66
+ _Page_textLayerMode.set(this, ui_utils_1.TextLayerMode.ENABLE);
67
+ // #useThumbnailCanvas = {
68
+ // directDrawing: true,
69
+ // initialOptionalContent: true,
70
+ // regularAnnotations: true,
71
+ // };
72
+ _Page_viewportMap.set(this, new WeakMap());
73
+ _Page_layers.set(this, [null, null, null, null]);
74
+ // textLayer: HTMLDivElement;
75
+ this.textLayer = null;
76
+ this.textLayerBuilder = null;
77
+ this.textAccessibilityManager = null;
78
+ this.annotationLayer = null;
79
+ this.drawLayer = null;
80
+ this.annotationEditorLayer = null;
81
+ this.options = {};
82
+ this.state = {};
83
+ this.pdfPage = null;
84
+ this.extendOptions(options);
85
+ // todo: ported from pdf.js
86
+ this.div = element;
87
+ this.viewport = this.options.viewport;
88
+ this.id = this.options.id || this.options.number || 1;
89
+ tslib_1.__classPrivateFieldSet(this, _Page_layerProperties, options.layerProperties || DEFAULT_LAYER_PROPERTIES, "f");
90
+ this.eventBus = options.eventBus;
91
+ this.initScale();
92
+ // todo: ported from pdf.js
93
+ this.pdfViewer = options.pdfViewer;
94
+ this.pdfPage = options.pdfPage;
95
+ this.resetState();
96
+ }
97
+ destroy() {
98
+ this.destroyTextLayer();
99
+ }
100
+ get isEditing() {
101
+ return tslib_1.__classPrivateFieldGet(this, _Page_isEditing, "f");
102
+ }
103
+ get rawWidth() {
104
+ var _a, _b;
105
+ return (_b = (_a = this.viewport) === null || _a === void 0 ? void 0 : _a.rawDims) === null || _b === void 0 ? void 0 : _b.pageWidth;
106
+ }
107
+ get rawHeight() {
108
+ var _a, _b;
109
+ return (_b = (_a = this.viewport) === null || _a === void 0 ? void 0 : _a.rawDims) === null || _b === void 0 ? void 0 : _b.pageWidth;
110
+ }
111
+ setState(newState) {
112
+ this.state = (0, core_1.deepExtend)(this.state || {}, newState);
113
+ }
114
+ resetState() {
115
+ this.setState({});
116
+ }
117
+ initScale() {
118
+ this.scale = this.options.zoomLevel || this.options.scale || ui_utils_1.DEFAULT_SCALE;
119
+ }
120
+ createPromise() {
121
+ return (0, core_1.createPromise)();
122
+ }
123
+ getViewport(options = { scale: 1 }) {
124
+ const viewport = this.pdfPage ? this.pdfPage.getViewport(options) : { width: 0, height: 0 };
125
+ return viewport;
126
+ }
127
+ destroyTextLayer() {
128
+ this.removeTextLayer();
129
+ }
130
+ removeTextLayer() {
131
+ var _a, _b;
132
+ if (this.textLayer && ((_a = this.textLayer.div) === null || _a === void 0 ? void 0 : _a.parentNode)) {
133
+ (_b = this.textLayer.div) === null || _b === void 0 ? void 0 : _b.parentNode.removeChild(this.textLayer.div);
134
+ }
135
+ }
136
+ getPrintContentAsync() {
137
+ const canvas = this.canvasForPrint;
138
+ const printContentLoadPromise = this.createPromise();
139
+ const printContent = new Image();
140
+ const viewportRawDimensions = this.viewport.rawDims;
141
+ const pageWidth = viewportRawDimensions.pageWidth;
142
+ const pageHeight = viewportRawDimensions.pageHeight;
143
+ // const pageWidth = this.viewport.width;
144
+ // const pageHeight = this.viewport.height;
145
+ printContent.src = canvas.toDataURL();
146
+ printContent.width = pageWidth;
147
+ printContent.height = pageHeight;
148
+ printContent.onload = () => {
149
+ // @ts-expect-error TS(2339):
150
+ printContentLoadPromise.resolve(printContent);
151
+ };
152
+ return printContentLoadPromise;
153
+ }
154
+ loadForPrintAsync({ zoomLevel = DEFAULT_ZOOM_LEVEL, force = false }) {
155
+ const that = this;
156
+ const pageLoadPromise = this.createPromise();
157
+ const pageZoomLevel = this.pdfViewer.state.zoomLevel;
158
+ if (this.pdfPage && pageZoomLevel === zoomLevel && !force) {
159
+ // @ts-expect-error TS(2339): Property 'resolve' does not exist on type 'Promise... Remove this comment to see the full error message
160
+ return pageLoadPromise.resolve(that);
161
+ }
162
+ else if (this.pdfPage && pageZoomLevel && (pageZoomLevel !== zoomLevel || force)) {
163
+ this.renderForPrintAsync()
164
+ .then(() => {
165
+ this.setState({
166
+ isPrintingInProgress: false
167
+ });
168
+ // @ts-expect-error TS(2339): Property 'resolve' does not exist on type 'Promise... Remove this comment to see the full error message
169
+ pageLoadPromise.resolve(that);
170
+ });
171
+ return pageLoadPromise;
172
+ }
173
+ const pageIndex = Math.max(0, this.pdfPage._pageIndex);
174
+ const pagePromise = this.pdfViewer.state.pdfDocument.getPage(pageIndex + 1);
175
+ pagePromise.then(() => {
176
+ this.renderForPrintAsync()
177
+ .then(() => {
178
+ this.setState({
179
+ isPrintingInProgress: false
180
+ });
181
+ // @ts-expect-error TS(2339): Property 'resolve' does not exist on type 'Promise... Remove this comment to see the full error message
182
+ pageLoadPromise.resolve(that);
183
+ });
184
+ });
185
+ return pageLoadPromise;
186
+ }
187
+ renderForPrintAsync() {
188
+ var _a, _b;
189
+ const { canvasContext, canvas,
190
+ // canvasWrapper,
191
+ // viewport,
192
+ // pageElement,
193
+ // _styles
194
+ } = this.pdfViewer.createPageElements({
195
+ pdfPage: this.pdfPage,
196
+ zoom: this.pdfViewer.options.zoomLevel || 1,
197
+ });
198
+ this.canvasForPrint = canvas;
199
+ // canvasWrapper.appendChild(canvas);
200
+ // pageElement.appendChild(canvasWrapper);
201
+ this.setState({
202
+ isPrintingInProgress: true
203
+ });
204
+ const printUnits = this.pdfViewer.options.printResolution / pdf_mjs_1.PixelsPerInch.PDF;
205
+ const optionalContentConfigPromise = this.pdfViewer.state.pdfDocument.getOptionalContentConfig({
206
+ intent: "print",
207
+ });
208
+ const renderContext = {
209
+ canvasContext: canvasContext,
210
+ transform: [printUnits, 0, 0, printUnits, 0, 0],
211
+ // viewport: this.pdfPage.getViewport({ scale: 1, rotation: size.rotation }),
212
+ viewport: this.pdfPage.getViewport({ scale: 1, rotation: this.viewport.rotation }),
213
+ intent: "print",
214
+ annotationMode: pdf_mjs_1.AnnotationMode.ENABLE_STORAGE,
215
+ optionalContentConfigPromise,
216
+ printAnnotationStorage: (_b = (_a = this.pdfViewer) === null || _a === void 0 ? void 0 : _a.annotationStorage) === null || _b === void 0 ? void 0 : _b.print
217
+ };
218
+ const renderTask = this.pdfPage.render(renderContext);
219
+ const resultPromise = renderTask.promise;
220
+ return resultPromise;
221
+ }
222
+ isBlank() {
223
+ return this.element && this.element.getAttribute("data-blank");
224
+ }
225
+ setBlank(isBlank) {
226
+ if (!this.element) {
227
+ return;
228
+ }
229
+ if (isBlank) {
230
+ this.element.setAttribute("data-blank", true.toString());
231
+ }
232
+ else {
233
+ this.element.removeAttribute("data-blank");
234
+ }
235
+ }
236
+ get renderingState() {
237
+ return tslib_1.__classPrivateFieldGet(this, _Page_renderingState, "f");
238
+ }
239
+ setPdfPage(pdfPage) {
240
+ // if (
241
+ // (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
242
+ // this._isStandalone &&
243
+ // (this.pageColors?.foreground === "CanvasText" ||
244
+ // this.pageColors?.background === "Canvas")
245
+ // ) {
246
+ // this._container?.style.setProperty(
247
+ // "--hcm-highlight-filter",
248
+ // pdfPage.filterFactory.addHighlightHCMFilter(
249
+ // "highlight",
250
+ // "CanvasText",
251
+ // "Canvas",
252
+ // "HighlightText",
253
+ // "Highlight"
254
+ // )
255
+ // );
256
+ // this._container?.style.setProperty(
257
+ // "--hcm-highlight-selected-filter",
258
+ // pdfPage.filterFactory.addHighlightHCMFilter(
259
+ // "highlight_selected",
260
+ // "CanvasText",
261
+ // "Canvas",
262
+ // "HighlightText",
263
+ // "Highlight"
264
+ // )
265
+ // );
266
+ // }
267
+ this.pdfPage = pdfPage;
268
+ this.pdfPageRotate = pdfPage.rotate;
269
+ const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
270
+ this.viewport = pdfPage.getViewport({
271
+ scale: this.scale * pdf_mjs_1.PixelsPerInch.PDF_TO_CSS_UNITS,
272
+ rotation: totalRotation,
273
+ });
274
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_setDimensions).call(this);
275
+ this.reset();
276
+ }
277
+ hasEditableAnnotations() {
278
+ var _a;
279
+ return !!((_a = this.annotationLayer) === null || _a === void 0 ? void 0 : _a.hasEditableAnnotations());
280
+ }
281
+ // /**
282
+ // * The structure tree is currently only supported when the text layer is
283
+ // * enabled and a canvas is used for rendering.
284
+ // *
285
+ // * The structure tree must be generated after the text layer for the
286
+ // * aria-owns to work.
287
+ // */
288
+ // async #renderStructTreeLayer() {
289
+ // if (!this.textLayer) {
290
+ // return;
291
+ // }
292
+ // this.structTreeLayer ||= new StructTreeLayerBuilder();
293
+ // const tree = await (!this.structTreeLayer.renderingDone
294
+ // ? this.pdfPage.getStructTree()
295
+ // : null);
296
+ // const treeDom = this.structTreeLayer?.render(tree);
297
+ // if (treeDom) {
298
+ // // Pause translation when inserting the structTree in the DOM.
299
+ // this.l10n.pause();
300
+ // this.canvas?.append(treeDom);
301
+ // this.l10n.resume();
302
+ // }
303
+ // this.structTreeLayer?.show();
304
+ // }
305
+ // async #buildXfaTextContentItems(textDivs) {
306
+ // const text = await this.pdfPage.getTextContent();
307
+ // const items = [];
308
+ // for (const item of text.items) {
309
+ // items.push(item.str);
310
+ // }
311
+ // this._textHighlighter.setTextMapping(textDivs, items);
312
+ // this._textHighlighter.enable();
313
+ // }
314
+ _resetZoomLayer(removeFromDOM = false) {
315
+ if (!this.zoomLayer) {
316
+ return;
317
+ }
318
+ const zoomLayerCanvas = this.zoomLayer.firstChild;
319
+ tslib_1.__classPrivateFieldGet(this, _Page_viewportMap, "f").delete(zoomLayerCanvas);
320
+ // Zeroing the width and height causes Firefox to release graphics
321
+ // resources immediately, which can greatly reduce memory consumption.
322
+ zoomLayerCanvas.width = 0;
323
+ zoomLayerCanvas.height = 0;
324
+ if (removeFromDOM) {
325
+ // Note: `ChildNode.remove` doesn't throw if the parent node is undefined.
326
+ this.zoomLayer.remove();
327
+ }
328
+ this.zoomLayer = null;
329
+ }
330
+ reset({ keepZoomLayer = false, keepAnnotationLayer = false, keepAnnotationEditorLayer = false, keepXfaLayer = false, keepTextLayer = false, } = {}) {
331
+ // this.cancelRendering({
332
+ // keepAnnotationLayer,
333
+ // keepAnnotationEditorLayer,
334
+ // keepXfaLayer,
335
+ // keepTextLayer,
336
+ // });
337
+ // this.renderingState = RenderingStates.INITIAL;
338
+ var _a, _b, _c, _d, _e, _f, _g, _h;
339
+ const div = this.div;
340
+ if (!div) {
341
+ return;
342
+ }
343
+ const childNodes = div.childNodes, zoomLayerNode = (keepZoomLayer && this.zoomLayer) || null, annotationLayerNode = (keepAnnotationLayer && ((_a = this.annotationLayer) === null || _a === void 0 ? void 0 : _a.div)) || null, annotationEditorLayerNode = (keepAnnotationEditorLayer && ((_b = this.annotationEditorLayer) === null || _b === void 0 ? void 0 : _b.div)) || null, xfaLayerNode = (keepXfaLayer && ((_c = this.xfaLayer) === null || _c === void 0 ? void 0 : _c.div)) || null, textLayerNode = (keepTextLayer && ((_d = this.textLayer) === null || _d === void 0 ? void 0 : _d.div)) || null;
344
+ for (let i = childNodes.length - 1; i >= 0; i--) {
345
+ const node = childNodes[i];
346
+ switch (node) {
347
+ case zoomLayerNode:
348
+ case annotationLayerNode:
349
+ case annotationEditorLayerNode:
350
+ case xfaLayerNode:
351
+ case textLayerNode:
352
+ continue;
353
+ default: break;
354
+ }
355
+ node.remove();
356
+ const layerIndex = tslib_1.__classPrivateFieldGet(this, _Page_layers, "f").indexOf(node);
357
+ if (layerIndex >= 0) {
358
+ tslib_1.__classPrivateFieldGet(this, _Page_layers, "f")[layerIndex] = null;
359
+ }
360
+ }
361
+ div.removeAttribute("data-loaded");
362
+ if (annotationLayerNode) {
363
+ // Hide the annotation layer until all elements are resized
364
+ // so they are not displayed on the already resized page.
365
+ (_e = this.annotationLayer) === null || _e === void 0 ? void 0 : _e.hide();
366
+ }
367
+ if (annotationEditorLayerNode) {
368
+ (_f = this.annotationEditorLayer) === null || _f === void 0 ? void 0 : _f.hide();
369
+ }
370
+ if (xfaLayerNode) {
371
+ // Hide the XFA layer until all elements are resized
372
+ // so they are not displayed on the already resized page.
373
+ (_g = this.xfaLayer) === null || _g === void 0 ? void 0 : _g.hide();
374
+ }
375
+ if (textLayerNode) {
376
+ (_h = this.textLayer) === null || _h === void 0 ? void 0 : _h.hide();
377
+ }
378
+ // this.structTreeLayer?.hide();
379
+ if (!zoomLayerNode) {
380
+ if (this.canvas) {
381
+ tslib_1.__classPrivateFieldGet(this, _Page_viewportMap, "f").delete(this.canvas);
382
+ // Zeroing the width and height causes Firefox to release graphics
383
+ // resources immediately, which can greatly reduce memory consumption.
384
+ this.canvas.width = 0;
385
+ this.canvas.height = 0;
386
+ delete this.canvas;
387
+ }
388
+ this._resetZoomLayer();
389
+ }
390
+ }
391
+ toggleEditingMode(isEditing) {
392
+ if (!this.hasEditableAnnotations()) {
393
+ return;
394
+ }
395
+ tslib_1.__classPrivateFieldSet(this, _Page_isEditing, isEditing, "f");
396
+ this.reset({
397
+ keepZoomLayer: true,
398
+ keepAnnotationLayer: true,
399
+ keepAnnotationEditorLayer: true,
400
+ keepXfaLayer: true,
401
+ keepTextLayer: true,
402
+ });
403
+ }
404
+ draw() {
405
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
406
+ // if (this.renderingState !== RenderingStates.INITIAL) {
407
+ // console.error("Must be in new state before drawing");
408
+ // this.reset(); // Ensure that we reset all state to prevent issues.
409
+ // }
410
+ // const { div, l10n, pageColors, pdfPage: pdfPage, viewport } = this;
411
+ // if (!pdfPage) {
412
+ // this.renderingState = RenderingStates.FINISHED;
413
+ // throw new Error("pdfPage is not loaded");
414
+ // }
415
+ // this.renderingState = RenderingStates.RUNNING;
416
+ const { canvasContext, canvas, canvasWrapper, viewport, pageElement, styles } = this.pdfViewer.createPageElements({
417
+ pdfPage: this.pdfPage,
418
+ zoom: this.pdfViewer.options.zoomLevel || 1,
419
+ });
420
+ if (this.isBlank()) {
421
+ this.element.replaceWith(pageElement);
422
+ this.element = this.div = pageElement;
423
+ this.canvas = canvas;
424
+ }
425
+ else {
426
+ this.element = this.div = this.element || this.div || pageElement;
427
+ this.canvas = this.canvas || canvas;
428
+ }
429
+ this.options.styles = styles;
430
+ // Wrap the canvas so that if it has a CSS transform for high DPI the
431
+ // overflow will be hidden in Firefox.
432
+ // const canvasWrapper = document.createElement("div");
433
+ // canvasWrapper.classList.add("canvasWrapper");
434
+ canvasWrapper.appendChild(canvas);
435
+ this.element.appendChild(canvasWrapper);
436
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_addLayer).call(this, canvasWrapper, "canvasWrapper");
437
+ const { div,
438
+ // l10n,
439
+ // pageColors,
440
+ pdfPage,
441
+ // viewport
442
+ } = this;
443
+ if (!this.textLayer && tslib_1.__classPrivateFieldGet(this, _Page_textLayerMode, "f") !== ui_utils_1.TextLayerMode.DISABLE && !pdfPage.isPureXfa) {
444
+ this._accessibilityManager || (this._accessibilityManager = new text_accessibility_manager_1.TextAccessibilityManager());
445
+ this.textLayer = new text_layer_builder_1.TextLayerBuilder({
446
+ // todo: not part of pdf.js
447
+ styles: this.options.styles,
448
+ pdfPage,
449
+ // highlighter: this._textHighlighter,
450
+ accessibilityManager: this._accessibilityManager,
451
+ // enablePermissions: this.#textLayerMode === TextLayerMode.ENABLE_PERMISSIONS,
452
+ onAppend: textLayerDiv => {
453
+ // Pause translation when inserting the textLayer in the DOM.
454
+ // this.l10n.pause();
455
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_addLayer).call(this, textLayerDiv, "textLayer");
456
+ // this.l10n.resume();
457
+ },
458
+ });
459
+ }
460
+ if (!this.annotationLayer && tslib_1.__classPrivateFieldGet(this, _Page_annotationMode, "f") !== pdf_mjs_1.AnnotationMode.DISABLE) {
461
+ const { annotationStorage, annotationEditorUIManager,
462
+ // downloadManager,
463
+ // enableScripting,
464
+ // fieldObjectsPromise,
465
+ // hasJSActionsPromise,
466
+ linkService, } = tslib_1.__classPrivateFieldGet(this, _Page_layerProperties, "f");
467
+ this._annotationCanvasMap || (this._annotationCanvasMap = new Map());
468
+ this.annotationLayer = new annotation_layer_builder_1.AnnotationLayerBuilder({
469
+ pdfPage,
470
+ eventBus: this.eventBus || this.pdfViewer.eventBus,
471
+ annotationStorage,
472
+ // imageResourcesPath: this.imageResourcesPath,
473
+ // renderForms: this.#annotationMode === AnnotationMode.ENABLE_FORMS,
474
+ linkService,
475
+ // downloadManager,
476
+ // enableScripting,
477
+ // hasJSActionsPromise,
478
+ // fieldObjectsPromise,
479
+ annotationCanvasMap: this._annotationCanvasMap,
480
+ accessibilityManager: this._accessibilityManager,
481
+ annotationEditorUIManager,
482
+ onAppend: annotationLayerDiv => {
483
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_addLayer).call(this, annotationLayerDiv, "annotationLayer");
484
+ },
485
+ });
486
+ }
487
+ // const renderContinueCallback = cont => {
488
+ // showCanvas?.(false);
489
+ // if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) {
490
+ // this.renderingState = RenderingStates.PAUSED;
491
+ // this.resume = () => {
492
+ // this.renderingState = RenderingStates.RUNNING;
493
+ // cont();
494
+ // };
495
+ // return;
496
+ // }
497
+ // cont();
498
+ // };
499
+ // const { width, height } = viewport;
500
+ // const canvas = document.createElement("canvas");
501
+ // canvas.setAttribute("role", "presentation");
502
+ // // Keep the canvas hidden until the first draw callback, or until drawing
503
+ // // is complete when `!this.renderingQueue`, to prevent black flickering.
504
+ // canvas.hidden = true;
505
+ // const hasHCM = !!(pageColors?.background && pageColors?.foreground);
506
+ // let showCanvas = isLastShow => {
507
+ // // In HCM, a final filter is applied on the canvas which means that
508
+ // // before it's applied we've normal colors. Consequently, to avoid to have
509
+ // // a final flash we just display it once all the drawing is done.
510
+ // if (!hasHCM || isLastShow) {
511
+ // canvas.hidden = false;
512
+ // showCanvas = null; // Only invoke the function once.
513
+ // }
514
+ // };
515
+ // canvasWrapper.append(canvas);
516
+ // this.canvas = canvas;
517
+ // const ctx = canvas.getContext("2d", {
518
+ // alpha: false,
519
+ // willReadFrequently: !this.#enableHWA,
520
+ // });
521
+ // const ctx = canvas.getContext("2d");
522
+ // const outputScale = (this.outputScale = new OutputScale());
523
+ // if (
524
+ // (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
525
+ // this.maxCanvasPixels === 0
526
+ // ) {
527
+ // const invScale = 1 / this.scale;
528
+ // // Use a scale that makes the canvas have the originally intended size
529
+ // // of the page.
530
+ // outputScale.sx *= invScale;
531
+ // outputScale.sy *= invScale;
532
+ // this.#hasRestrictedScaling = true;
533
+ // } else if (this.maxCanvasPixels > 0) {
534
+ // const pixelsInViewport = width * height;
535
+ // const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
536
+ // if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
537
+ // outputScale.sx = maxScale;
538
+ // outputScale.sy = maxScale;
539
+ // this.#hasRestrictedScaling = true;
540
+ // } else {
541
+ // this.#hasRestrictedScaling = false;
542
+ // }
543
+ // }
544
+ // const sfx = approximateFraction(outputScale.sx);
545
+ // const sfy = approximateFraction(outputScale.sy);
546
+ // canvas.width = floorToDivide(width * outputScale.sx, sfx[0]);
547
+ // canvas.height = floorToDivide(height * outputScale.sy, sfy[0]);
548
+ // const { style } = canvas;
549
+ // style.width = floorToDivide(width, sfx[1]) + "px";
550
+ // style.height = floorToDivide(height, sfy[1]) + "px";
551
+ // Add the viewport so it's known what it was originally drawn with.
552
+ tslib_1.__classPrivateFieldGet(this, _Page_viewportMap, "f").set(canvas, viewport);
553
+ // // Rendering area
554
+ // const transform = outputScale.scaled
555
+ // ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
556
+ // : null;
557
+ const renderContext = {
558
+ canvasContext: canvasContext,
559
+ // transform,
560
+ viewport,
561
+ annotationMode: tslib_1.__classPrivateFieldGet(this, _Page_annotationMode, "f"),
562
+ // optionalContentConfigPromise: this._optionalContentConfigPromise,
563
+ annotationCanvasMap: this._annotationCanvasMap,
564
+ // pageColors,
565
+ isEditing: tslib_1.__classPrivateFieldGet(this, _Page_isEditing, "f"),
566
+ };
567
+ // pdfPage.render(renderContext)
568
+ const renderTask = (this.renderTask = pdfPage.render(renderContext));
569
+ // renderTask.onContinue = renderContinueCallback;
570
+ const resultPromise = renderTask.promise.then(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
571
+ var _a;
572
+ // showCanvas?.(true);
573
+ yield tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_finishRenderTask).call(this, renderTask);
574
+ // todo: awaiting this breaks text nodes positioning after zoom
575
+ // if "includeMarkedContent": true is set in TextLayerBuilder
576
+ // await this.#renderTextLayer();
577
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_renderTextLayer).call(this);
578
+ if (this.annotationLayer) {
579
+ yield tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_renderAnnotationLayer).call(this);
580
+ }
581
+ const { annotationEditorUIManager } = tslib_1.__classPrivateFieldGet(this, _Page_layerProperties, "f");
582
+ if (!annotationEditorUIManager) {
583
+ return;
584
+ }
585
+ this.drawLayer || (this.drawLayer = new draw_layer_builder_1.DrawLayerBuilder({
586
+ pageIndex: this.id,
587
+ }));
588
+ yield tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_renderDrawLayer).call(this);
589
+ this.drawLayer.setParent(canvasWrapper);
590
+ if (!this.annotationEditorLayer) {
591
+ this.annotationEditorLayer = new annotation_editor_layer_builder_1.AnnotationEditorLayerBuilder({
592
+ uiManager: annotationEditorUIManager,
593
+ pdfPage,
594
+ // l10n,
595
+ accessibilityManager: this._accessibilityManager,
596
+ annotationLayer: (_a = this.annotationLayer) === null || _a === void 0 ? void 0 : _a.annotationLayer,
597
+ textLayer: this.textLayer,
598
+ drawLayer: this.drawLayer.getDrawLayer(),
599
+ onAppend: annotationEditorLayerDiv => {
600
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_addLayer).call(this, annotationEditorLayerDiv, "annotationEditorLayer");
601
+ },
602
+ });
603
+ }
604
+ // todo: this is not awaited in pdf.js
605
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_renderAnnotationEditorLayer).call(this);
606
+ // await this.#renderAnnotationEditorLayer();
607
+ }), error => {
608
+ // When zooming with a `drawingDelay` set, avoid temporarily showing
609
+ // a black canvas if rendering was cancelled before the `onContinue`-
610
+ // callback had been invoked at least once.
611
+ // if (!(error instanceof RenderingCancelledException)) {
612
+ // showCanvas?.(true);
613
+ // }
614
+ // return this.#finishRenderTask(renderTask, error);
615
+ if (!error) {
616
+ return;
617
+ }
618
+ });
619
+ if (pdfPage.isPureXfa) {
620
+ // if (!this.xfaLayer) {
621
+ // const { annotationStorage, linkService } = this.#layerProperties;
622
+ // this.xfaLayer = new XfaLayerBuilder({
623
+ // pdfPage,
624
+ // annotationStorage,
625
+ // linkService,
626
+ // });
627
+ // }
628
+ // this.#renderXfaLayer();
629
+ }
630
+ div.setAttribute("data-loaded", true);
631
+ this.eventBus.dispatch("pagerender", {
632
+ source: this,
633
+ pageNumber: this.id,
634
+ });
635
+ return resultPromise;
636
+ });
637
+ }
638
+ }
639
+ exports.Page = Page;
640
+ _Page_annotationMode = new WeakMap(), _Page_isEditing = new WeakMap(), _Page_layerProperties = new WeakMap(), _Page_previousRotation = new WeakMap(), _Page_renderingState = new WeakMap(), _Page_textLayerMode = new WeakMap(), _Page_viewportMap = new WeakMap(), _Page_layers = new WeakMap(), _Page_instances = new WeakSet(), _Page_addLayer = function _Page_addLayer(div, name) {
641
+ const pos = LAYERS_ORDER.get(name);
642
+ const oldDiv = tslib_1.__classPrivateFieldGet(this, _Page_layers, "f")[pos];
643
+ tslib_1.__classPrivateFieldGet(this, _Page_layers, "f")[pos] = div;
644
+ if (oldDiv) {
645
+ oldDiv.replaceWith(div);
646
+ return;
647
+ }
648
+ for (let i = pos - 1; i >= 0; i--) {
649
+ const layer = tslib_1.__classPrivateFieldGet(this, _Page_layers, "f")[i];
650
+ if (layer) {
651
+ layer.after(div);
652
+ return;
653
+ }
654
+ }
655
+ this.div.prepend(div);
656
+ }, _Page_setDimensions = function _Page_setDimensions() {
657
+ const { viewport } = this;
658
+ if (this.pdfPage) {
659
+ if (tslib_1.__classPrivateFieldGet(this, _Page_previousRotation, "f") === viewport.rotation) {
660
+ return;
661
+ }
662
+ tslib_1.__classPrivateFieldSet(this, _Page_previousRotation, viewport.rotation, "f");
663
+ }
664
+ if (!this.div || !viewport) {
665
+ return;
666
+ }
667
+ (0, pdf_mjs_1.setLayerDimensions)(this.div, viewport,
668
+ /* mustFlip = */ true,
669
+ /* mustRotate = */ false);
670
+ }, _Page_dispatchLayerRendered = function _Page_dispatchLayerRendered(name, error) {
671
+ this.eventBus.dispatch(name, {
672
+ source: this,
673
+ pageNumber: this.id,
674
+ error,
675
+ });
676
+ }, _Page_renderAnnotationLayer = function _Page_renderAnnotationLayer() {
677
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
678
+ let error = null;
679
+ try {
680
+ yield this.annotationLayer.render(this.viewport, "display");
681
+ }
682
+ catch (ex) {
683
+ console.error(`#renderAnnotationLayer: "${ex}".`);
684
+ error = ex;
685
+ }
686
+ finally {
687
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_dispatchLayerRendered).call(this, "annotationlayerrendered", error);
688
+ }
689
+ });
690
+ }, _Page_renderAnnotationEditorLayer = function _Page_renderAnnotationEditorLayer() {
691
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
692
+ let error = null;
693
+ try {
694
+ // await this.annotationEditorLayer.render(this.viewport, "display");
695
+ yield this.annotationEditorLayer.render(this.viewport);
696
+ }
697
+ catch (ex) {
698
+ // console.error(`#renderAnnotationEditorLayer: "${ex}".`);
699
+ error = ex;
700
+ }
701
+ finally {
702
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_dispatchLayerRendered).call(this, "annotationeditorlayerrendered", error);
703
+ }
704
+ });
705
+ }, _Page_renderDrawLayer = function _Page_renderDrawLayer() {
706
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
707
+ try {
708
+ yield this.drawLayer.render("display");
709
+ }
710
+ catch (ex) {
711
+ // console.error(`#renderDrawLayer: "${ex}".`);
712
+ }
713
+ });
714
+ }, _Page_renderTextLayer = function _Page_renderTextLayer() {
715
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
716
+ if (!this.textLayer) {
717
+ return;
718
+ }
719
+ let error = null;
720
+ try {
721
+ yield this.textLayer.render(this.viewport);
722
+ }
723
+ catch (ex) {
724
+ if (ex instanceof pdf_mjs_1.AbortException) {
725
+ return;
726
+ }
727
+ // console.error(`#renderTextLayer: "${ex}".`);
728
+ error = ex;
729
+ }
730
+ tslib_1.__classPrivateFieldGet(this, _Page_instances, "m", _Page_dispatchLayerRendered).call(this, "textlayerrendered", error);
731
+ // this.#renderStructTreeLayer();
732
+ });
733
+ }, _Page_finishRenderTask = function _Page_finishRenderTask(renderTask) {
734
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
735
+ // The renderTask may have been replaced by a new one, so only remove
736
+ // the reference to the renderTask if it matches the one that is
737
+ // triggering this callback.
738
+ if (renderTask === this.renderTask) {
739
+ this.renderTask = null;
740
+ }
741
+ // if (error instanceof RenderingCancelledException) {
742
+ // this.#renderError = null;
743
+ // return;
744
+ // }
745
+ // this.#renderError = error;
746
+ // this.renderingState = RenderingStates.FINISHED;
747
+ this._resetZoomLayer(/* removeFromDOM = */ true);
748
+ // // Ensure that the thumbnails won't become partially (or fully) blank,
749
+ // // for documents that contain interactive form elements.
750
+ // this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots;
751
+ this.eventBus.dispatch("pagerendered", {
752
+ source: this,
753
+ pageNumber: this.id,
754
+ cssTransform: false,
755
+ timestamp: performance.now(),
756
+ // error: this.#renderError,
757
+ error: "page render error",
758
+ });
759
+ // if (error) {
760
+ // throw error;
761
+ // }
762
+ });
763
+ };