@progress/kendo-pdfviewer-common 0.3.0-dev.202409251137 → 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.
- package/dist/es/annotations/annotation-editor-layer-builder.js +139 -0
- package/dist/es/annotations/annotation-editor-layer.js +780 -0
- package/dist/es/annotations/annotation-editor-ui-manager.js +1690 -0
- package/dist/es/annotations/annotation-layer-builder.js +217 -0
- package/dist/es/annotations/annotation-layer.js +2793 -0
- package/dist/es/annotations/draw-layer-builder.js +65 -0
- package/dist/es/annotations/draw-layer.js +220 -0
- package/dist/es/annotations/editors/annotation-editor.js +1519 -0
- package/dist/es/annotations/editors/free-text-editor.js +783 -0
- package/dist/es/annotations/editors/highlight-editor.js +717 -0
- package/dist/es/annotations/editors/outliner.js +747 -0
- package/dist/es/annotations/helpers/annotation-storage.js +294 -0
- package/dist/es/annotations/helpers/color-manager.js +72 -0
- package/dist/es/annotations/helpers/command-manager.js +133 -0
- package/dist/es/annotations/helpers/id-manager.js +34 -0
- package/dist/es/annotations/helpers/image-manager.js +176 -0
- package/dist/es/annotations/helpers/text-accessibility-manager.js +212 -0
- package/dist/es/annotations/helpers/tools.js +19 -0
- package/dist/es/annotations/shared/display_utils.js +1024 -0
- package/dist/es/annotations/shared/event_utils.js +213 -0
- package/dist/es/annotations/shared/murmurhash3.js +126 -0
- package/dist/es/annotations/shared/scripting_utils.js +90 -0
- package/dist/es/annotations/shared/ui_utils.js +823 -0
- package/dist/es/annotations/shared/utils.js +909 -0
- package/dist/es/annotations.js +68 -0
- package/dist/es/common/component.js +33 -0
- package/dist/es/common/core.js +91 -0
- package/dist/es/common/dom.js +11 -0
- package/dist/es/common/main.js +4 -0
- package/dist/es/common/math.js +1 -0
- package/dist/es/enums/PdfViewerInteractionMode.js +6 -0
- package/dist/es/links/link-service.js +505 -0
- package/dist/es/main.js +2 -0
- package/dist/es/scroller.js +29 -30
- package/dist/es/text/text-layer-builder.js +288 -0
- package/dist/es/utils.js +42 -14
- package/dist/es/widget/page.js +762 -0
- package/dist/es/widget/pdfviewer.js +1659 -0
- package/dist/es2015/annotations/annotation-editor-layer-builder.js +139 -0
- package/dist/es2015/annotations/annotation-editor-layer.js +780 -0
- package/dist/es2015/annotations/annotation-editor-ui-manager.js +1690 -0
- package/dist/es2015/annotations/annotation-layer-builder.js +217 -0
- package/dist/es2015/annotations/annotation-layer.js +2793 -0
- package/dist/es2015/annotations/draw-layer-builder.js +65 -0
- package/dist/es2015/annotations/draw-layer.js +220 -0
- package/dist/es2015/annotations/editors/annotation-editor.js +1519 -0
- package/dist/es2015/annotations/editors/free-text-editor.js +783 -0
- package/dist/es2015/annotations/editors/highlight-editor.js +717 -0
- package/dist/es2015/annotations/editors/outliner.js +747 -0
- package/dist/es2015/annotations/helpers/annotation-storage.js +294 -0
- package/dist/es2015/annotations/helpers/color-manager.js +72 -0
- package/dist/es2015/annotations/helpers/command-manager.js +133 -0
- package/dist/es2015/annotations/helpers/id-manager.js +34 -0
- package/dist/es2015/annotations/helpers/image-manager.js +176 -0
- package/dist/es2015/annotations/helpers/text-accessibility-manager.js +212 -0
- package/dist/es2015/annotations/helpers/tools.js +19 -0
- package/dist/es2015/annotations/shared/display_utils.js +1024 -0
- package/dist/es2015/annotations/shared/event_utils.js +213 -0
- package/dist/es2015/annotations/shared/murmurhash3.js +126 -0
- package/dist/es2015/annotations/shared/scripting_utils.js +90 -0
- package/dist/es2015/annotations/shared/ui_utils.js +823 -0
- package/dist/es2015/annotations/shared/utils.js +909 -0
- package/dist/es2015/annotations.js +68 -0
- package/dist/es2015/common/component.js +33 -0
- package/dist/es2015/common/core.js +91 -0
- package/dist/es2015/common/dom.js +11 -0
- package/dist/es2015/common/main.js +4 -0
- package/dist/es2015/common/math.js +1 -0
- package/dist/es2015/enums/PdfViewerInteractionMode.js +6 -0
- package/dist/es2015/links/link-service.js +505 -0
- package/dist/es2015/main.js +2 -0
- package/dist/es2015/scroller.js +29 -30
- package/dist/es2015/text/text-layer-builder.js +288 -0
- package/dist/es2015/utils.js +42 -14
- package/dist/es2015/widget/page.js +762 -0
- package/dist/es2015/widget/pdfviewer.js +1659 -0
- package/dist/npm/annotations/annotation-editor-layer-builder.d.ts +39 -0
- package/dist/npm/annotations/annotation-editor-layer-builder.js +142 -0
- package/dist/npm/annotations/annotation-editor-layer.d.ts +196 -0
- package/dist/npm/annotations/annotation-editor-layer.js +783 -0
- package/dist/npm/annotations/annotation-editor-ui-manager.d.ts +281 -0
- package/dist/npm/annotations/annotation-editor-ui-manager.js +1694 -0
- package/dist/npm/annotations/annotation-layer-builder.d.ts +58 -0
- package/dist/npm/annotations/annotation-layer-builder.js +220 -0
- package/dist/npm/annotations/annotation-layer.d.ts +134 -0
- package/dist/npm/annotations/annotation-layer.js +2794 -0
- package/dist/npm/annotations/draw-layer-builder.d.ts +21 -0
- package/dist/npm/annotations/draw-layer-builder.js +68 -0
- package/dist/npm/annotations/draw-layer.d.ts +33 -0
- package/dist/npm/annotations/draw-layer.js +223 -0
- package/dist/npm/annotations/editors/annotation-editor.d.ts +349 -0
- package/dist/npm/annotations/editors/annotation-editor.js +1523 -0
- package/dist/npm/annotations/editors/free-text-editor.d.ts +108 -0
- package/dist/npm/annotations/editors/free-text-editor.js +786 -0
- package/dist/npm/annotations/editors/highlight-editor.d.ts +114 -0
- package/dist/npm/annotations/editors/highlight-editor.js +717 -0
- package/dist/npm/annotations/editors/outliner.d.ts +51 -0
- package/dist/npm/annotations/editors/outliner.js +750 -0
- package/dist/npm/annotations/helpers/annotation-storage.d.ts +98 -0
- package/dist/npm/annotations/helpers/annotation-storage.js +299 -0
- package/dist/npm/annotations/helpers/color-manager.d.ts +6 -0
- package/dist/npm/annotations/helpers/color-manager.js +76 -0
- package/dist/npm/annotations/helpers/command-manager.d.ts +42 -0
- package/dist/npm/annotations/helpers/command-manager.js +137 -0
- package/dist/npm/annotations/helpers/id-manager.d.ts +6 -0
- package/dist/npm/annotations/helpers/id-manager.js +38 -0
- package/dist/npm/annotations/helpers/image-manager.d.ts +18 -0
- package/dist/npm/annotations/helpers/image-manager.js +180 -0
- package/dist/npm/annotations/helpers/text-accessibility-manager.d.ts +36 -0
- package/dist/npm/annotations/helpers/text-accessibility-manager.js +215 -0
- package/dist/npm/annotations/helpers/tools.d.ts +1 -0
- package/dist/npm/annotations/helpers/tools.js +23 -0
- package/dist/npm/annotations/shared/display_utils.d.ts +6 -0
- package/dist/npm/annotations/shared/display_utils.js +1030 -0
- package/dist/npm/annotations/shared/event_utils.d.ts +33 -0
- package/dist/npm/annotations/shared/event_utils.js +165 -0
- package/dist/npm/annotations/shared/murmurhash3.d.ts +8 -0
- package/dist/npm/annotations/shared/murmurhash3.js +129 -0
- package/dist/npm/annotations/shared/scripting_utils.d.ts +17 -0
- package/dist/npm/annotations/shared/scripting_utils.js +93 -0
- package/dist/npm/annotations/shared/ui_utils.d.ts +54 -0
- package/dist/npm/annotations/shared/ui_utils.js +250 -0
- package/dist/npm/annotations/shared/utils.d.ts +148 -0
- package/dist/npm/annotations/shared/utils.js +872 -0
- package/dist/npm/annotations.d.ts +23 -0
- package/dist/npm/annotations.js +72 -0
- package/dist/npm/common/component.d.ts +9 -0
- package/dist/npm/common/component.js +37 -0
- package/dist/npm/common/core.d.ts +18 -0
- package/dist/npm/common/core.js +112 -0
- package/dist/npm/common/dom.d.ts +3 -0
- package/dist/npm/common/dom.js +17 -0
- package/dist/npm/common/main.d.ts +4 -0
- package/dist/npm/common/main.js +7 -0
- package/dist/npm/common/math.d.ts +1 -0
- package/dist/npm/common/math.js +5 -0
- package/dist/npm/enums/PdfViewerInteractionMode.d.ts +4 -0
- package/dist/npm/enums/PdfViewerInteractionMode.js +9 -0
- package/dist/npm/links/link-service.d.ts +116 -0
- package/dist/npm/links/link-service.js +501 -0
- package/dist/npm/main.d.ts +2 -0
- package/dist/npm/main.js +2 -0
- package/dist/npm/scroller.d.ts +7 -3
- package/dist/npm/scroller.js +32 -32
- package/dist/npm/text/text-layer-builder.d.ts +30 -0
- package/dist/npm/text/text-layer-builder.js +291 -0
- package/dist/npm/utils.d.ts +27 -3
- package/dist/npm/utils.js +51 -19
- package/dist/npm/widget/page.d.ts +75 -0
- package/dist/npm/widget/page.js +763 -0
- package/dist/npm/widget/pdfviewer.d.ts +222 -0
- package/dist/npm/widget/pdfviewer.js +1663 -0
- package/package.json +13 -9
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/* Copyright 2012 Mozilla Foundation
|
|
2
|
+
*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
var _TextLayerBuilder_instances, _a, _TextLayerBuilder_onAppend, _TextLayerBuilder_textLayer, _TextLayerBuilder_textLayers, _TextLayerBuilder_selectionChangeAbortController, _TextLayerBuilder_bindMouse, _TextLayerBuilder_removeGlobalSelectionListener, _TextLayerBuilder_enableGlobalSelectionListener;
|
|
16
|
+
import { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
17
|
+
import { TextLayer } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
18
|
+
import { addClass } from "../common/dom";
|
|
19
|
+
/**
|
|
20
|
+
* The text layer builder provides text selection functionality for the PDF.
|
|
21
|
+
* It does this by creating overlay divs over the PDF's text. These divs
|
|
22
|
+
* contain text that matches the PDF text they are overlaying.
|
|
23
|
+
*/
|
|
24
|
+
class TextLayerBuilder {
|
|
25
|
+
constructor({ pdfPage,
|
|
26
|
+
// highlighter = null,
|
|
27
|
+
accessibilityManager,
|
|
28
|
+
// enablePermissions = false,
|
|
29
|
+
// todo: fix styles
|
|
30
|
+
styles, onAppend = null, }) {
|
|
31
|
+
_TextLayerBuilder_instances.add(this);
|
|
32
|
+
// todo: props
|
|
33
|
+
this.pdfPage = null;
|
|
34
|
+
// highlighter = null;
|
|
35
|
+
this.div = null;
|
|
36
|
+
this.accessibilityManager = null;
|
|
37
|
+
// todo: props
|
|
38
|
+
// #enablePermissions = false;
|
|
39
|
+
_TextLayerBuilder_onAppend.set(this, null);
|
|
40
|
+
// #renderingDone = false;
|
|
41
|
+
_TextLayerBuilder_textLayer.set(this, null);
|
|
42
|
+
this.pdfPage = pdfPage;
|
|
43
|
+
// this.highlighter = highlighter;
|
|
44
|
+
this.accessibilityManager = accessibilityManager;
|
|
45
|
+
// this.#enablePermissions = enablePermissions === true;
|
|
46
|
+
__classPrivateFieldSet(this, _TextLayerBuilder_onAppend, onAppend, "f");
|
|
47
|
+
this.div = document.createElement("div");
|
|
48
|
+
this.div.tabIndex = 0;
|
|
49
|
+
// this.div.className = "textLayer";
|
|
50
|
+
// todo: fix classes
|
|
51
|
+
this.div.classList.add("k-text-layer");
|
|
52
|
+
// todo: fix styles
|
|
53
|
+
Object.keys(styles).forEach((key) => (this.div.style[key] = styles[key]));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Renders the text layer.
|
|
57
|
+
* @param {PageViewport} viewport
|
|
58
|
+
* @param {Object} [textContentParams]
|
|
59
|
+
*/
|
|
60
|
+
render(viewport_1) {
|
|
61
|
+
return __awaiter(this, arguments, void 0, function* (viewport, textContentParams = null) {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
// if (this.#renderingDone && this.#textLayer) {
|
|
64
|
+
if (__classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f")) {
|
|
65
|
+
__classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f").update({
|
|
66
|
+
viewport,
|
|
67
|
+
onBefore: this.hide.bind(this),
|
|
68
|
+
});
|
|
69
|
+
this.show();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.cancel();
|
|
73
|
+
__classPrivateFieldSet(this, _TextLayerBuilder_textLayer, new TextLayer({
|
|
74
|
+
textContentSource: this.pdfPage.streamTextContent(textContentParams || {
|
|
75
|
+
// includeMarkedContent: true,
|
|
76
|
+
// setting this to false requires removing "await"
|
|
77
|
+
// in page.ts when calling this.#renderTextLayer()
|
|
78
|
+
includeMarkedContent: false,
|
|
79
|
+
disableNormalization: true,
|
|
80
|
+
}),
|
|
81
|
+
container: this.div,
|
|
82
|
+
viewport,
|
|
83
|
+
}), "f");
|
|
84
|
+
// const { textDivs, textContentItemsStr } = this.#textLayer;
|
|
85
|
+
const { textDivs } = __classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f");
|
|
86
|
+
// this.highlighter?.setTextMapping(textDivs, textContentItemsStr);
|
|
87
|
+
(_a = this.accessibilityManager) === null || _a === void 0 ? void 0 : _a.setTextMapping(textDivs);
|
|
88
|
+
yield __classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f").render();
|
|
89
|
+
// this.#renderingDone = true;
|
|
90
|
+
// todo: manually add "k-marked-content" class
|
|
91
|
+
// as pdf.js text layer cannot render it
|
|
92
|
+
const markedContentElements = Array.from(this.div.querySelectorAll(".markedContent") || []) || [];
|
|
93
|
+
markedContentElements.forEach(x => addClass("k-marked-content", x));
|
|
94
|
+
if (markedContentElements && markedContentElements.length > 0) {
|
|
95
|
+
const endOfContent = document.createElement("div");
|
|
96
|
+
endOfContent.className = "endOfContent";
|
|
97
|
+
this.div.append(endOfContent);
|
|
98
|
+
__classPrivateFieldGet(this, _TextLayerBuilder_instances, "m", _TextLayerBuilder_bindMouse).call(this, endOfContent);
|
|
99
|
+
}
|
|
100
|
+
// Ensure that the textLayer is appended to the DOM *before* handling
|
|
101
|
+
// e.g. a pending search operation.
|
|
102
|
+
(_b = __classPrivateFieldGet(this, _TextLayerBuilder_onAppend, "f")) === null || _b === void 0 ? void 0 : _b.call(this, this.div);
|
|
103
|
+
// this.highlighter?.enable();
|
|
104
|
+
(_c = this.accessibilityManager) === null || _c === void 0 ? void 0 : _c.enable();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
hide() {
|
|
108
|
+
// if (!this.div.hidden && this.#renderingDone) {
|
|
109
|
+
if (!this.div.hidden) {
|
|
110
|
+
// We turn off the highlighter in order to avoid to scroll into view an
|
|
111
|
+
// element of the text layer which could be hidden.
|
|
112
|
+
// this.highlighter?.disable();
|
|
113
|
+
this.div.hidden = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
show() {
|
|
117
|
+
// if (this.div.hidden && this.#renderingDone) {
|
|
118
|
+
if (this.div.hidden) {
|
|
119
|
+
this.div.hidden = false;
|
|
120
|
+
// this.highlighter?.enable();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Cancel rendering of the text layer.
|
|
125
|
+
*/
|
|
126
|
+
cancel() {
|
|
127
|
+
var _b, _c;
|
|
128
|
+
(_b = __classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f")) === null || _b === void 0 ? void 0 : _b.cancel();
|
|
129
|
+
__classPrivateFieldSet(this, _TextLayerBuilder_textLayer, null, "f");
|
|
130
|
+
// this.highlighter?.disable();
|
|
131
|
+
(_c = this.accessibilityManager) === null || _c === void 0 ? void 0 : _c.disable();
|
|
132
|
+
__classPrivateFieldGet(_a, _a, "m", _TextLayerBuilder_removeGlobalSelectionListener).call(_a, this.div);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
_a = TextLayerBuilder, _TextLayerBuilder_onAppend = new WeakMap(), _TextLayerBuilder_textLayer = new WeakMap(), _TextLayerBuilder_instances = new WeakSet(), _TextLayerBuilder_bindMouse = function _TextLayerBuilder_bindMouse(end) {
|
|
136
|
+
const { div } = this;
|
|
137
|
+
// div.addEventListener("mousedown", () => {
|
|
138
|
+
// div.classList.add("selecting");
|
|
139
|
+
// });
|
|
140
|
+
// div.addEventListener("copy", event => {
|
|
141
|
+
// if (!this.#enablePermissions) {
|
|
142
|
+
// const selection = document.getSelection();
|
|
143
|
+
// event.clipboardData.setData(
|
|
144
|
+
// "text/plain",
|
|
145
|
+
// removeNullCharacters(normalizeUnicode(selection.toString()))
|
|
146
|
+
// );
|
|
147
|
+
// }
|
|
148
|
+
// event.preventDefault();
|
|
149
|
+
// event.stopPropagation();
|
|
150
|
+
// });
|
|
151
|
+
__classPrivateFieldGet(_a, _a, "f", _TextLayerBuilder_textLayers).set(div, end);
|
|
152
|
+
__classPrivateFieldGet(_a, _a, "m", _TextLayerBuilder_enableGlobalSelectionListener).call(_a);
|
|
153
|
+
}, _TextLayerBuilder_removeGlobalSelectionListener = function _TextLayerBuilder_removeGlobalSelectionListener(textLayerDiv) {
|
|
154
|
+
var _b;
|
|
155
|
+
__classPrivateFieldGet(this, _a, "f", _TextLayerBuilder_textLayers).delete(textLayerDiv);
|
|
156
|
+
if (__classPrivateFieldGet(this, _a, "f", _TextLayerBuilder_textLayers).size === 0) {
|
|
157
|
+
(_b = __classPrivateFieldGet(this, _a, "f", _TextLayerBuilder_selectionChangeAbortController)) === null || _b === void 0 ? void 0 : _b.abort();
|
|
158
|
+
__classPrivateFieldSet(this, _a, null, "f", _TextLayerBuilder_selectionChangeAbortController);
|
|
159
|
+
}
|
|
160
|
+
}, _TextLayerBuilder_enableGlobalSelectionListener = function _TextLayerBuilder_enableGlobalSelectionListener() {
|
|
161
|
+
// if (this.#selectionChangeAbortController) {
|
|
162
|
+
// // document-level event listeners already installed
|
|
163
|
+
// return;
|
|
164
|
+
// }
|
|
165
|
+
// this.#selectionChangeAbortController = new AbortController();
|
|
166
|
+
// const { signal } = this.#selectionChangeAbortController;
|
|
167
|
+
// const reset = (end, textLayer) => {
|
|
168
|
+
// if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
|
169
|
+
// textLayer.append(end);
|
|
170
|
+
// end.style.width = "";
|
|
171
|
+
// end.style.height = "";
|
|
172
|
+
// }
|
|
173
|
+
// textLayer.classList.remove("selecting");
|
|
174
|
+
// };
|
|
175
|
+
// let isPointerDown = false;
|
|
176
|
+
// document.addEventListener(
|
|
177
|
+
// "pointerdown",
|
|
178
|
+
// () => {
|
|
179
|
+
// isPointerDown = true;
|
|
180
|
+
// },
|
|
181
|
+
// { signal }
|
|
182
|
+
// );
|
|
183
|
+
// document.addEventListener(
|
|
184
|
+
// "pointerup",
|
|
185
|
+
// () => {
|
|
186
|
+
// isPointerDown = false;
|
|
187
|
+
// this.#textLayers.forEach(reset);
|
|
188
|
+
// },
|
|
189
|
+
// { signal }
|
|
190
|
+
// );
|
|
191
|
+
// window.addEventListener(
|
|
192
|
+
// "blur",
|
|
193
|
+
// () => {
|
|
194
|
+
// isPointerDown = false;
|
|
195
|
+
// this.#textLayers.forEach(reset);
|
|
196
|
+
// },
|
|
197
|
+
// { signal }
|
|
198
|
+
// );
|
|
199
|
+
// document.addEventListener(
|
|
200
|
+
// "keyup",
|
|
201
|
+
// () => {
|
|
202
|
+
// if (!isPointerDown) {
|
|
203
|
+
// this.#textLayers.forEach(reset);
|
|
204
|
+
// }
|
|
205
|
+
// },
|
|
206
|
+
// { signal }
|
|
207
|
+
// );
|
|
208
|
+
// if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
|
209
|
+
// // eslint-disable-next-line no-var
|
|
210
|
+
// var isFirefox, prevRange;
|
|
211
|
+
// }
|
|
212
|
+
// document.addEventListener(
|
|
213
|
+
// "selectionchange",
|
|
214
|
+
// () => {
|
|
215
|
+
// const selection = document.getSelection();
|
|
216
|
+
// if (selection.rangeCount === 0) {
|
|
217
|
+
// this.#textLayers.forEach(reset);
|
|
218
|
+
// return;
|
|
219
|
+
// }
|
|
220
|
+
// // Even though the spec says that .rangeCount should be 0 or 1, Firefox
|
|
221
|
+
// // creates multiple ranges when selecting across multiple pages.
|
|
222
|
+
// // Make sure to collect all the .textLayer elements where the selection
|
|
223
|
+
// // is happening.
|
|
224
|
+
// const activeTextLayers = new Set();
|
|
225
|
+
// for (let i = 0; i < selection.rangeCount; i++) {
|
|
226
|
+
// const range = selection.getRangeAt(i);
|
|
227
|
+
// for (const textLayerDiv of this.#textLayers.keys()) {
|
|
228
|
+
// if (
|
|
229
|
+
// !activeTextLayers.has(textLayerDiv) &&
|
|
230
|
+
// range.intersectsNode(textLayerDiv)
|
|
231
|
+
// ) {
|
|
232
|
+
// activeTextLayers.add(textLayerDiv);
|
|
233
|
+
// }
|
|
234
|
+
// }
|
|
235
|
+
// }
|
|
236
|
+
// for (const [textLayerDiv, endDiv] of this.#textLayers) {
|
|
237
|
+
// if (activeTextLayers.has(textLayerDiv)) {
|
|
238
|
+
// textLayerDiv.classList.add("selecting");
|
|
239
|
+
// } else {
|
|
240
|
+
// reset(endDiv, textLayerDiv);
|
|
241
|
+
// }
|
|
242
|
+
// }
|
|
243
|
+
// if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|
244
|
+
// return;
|
|
245
|
+
// }
|
|
246
|
+
// if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) {
|
|
247
|
+
// isFirefox ??=
|
|
248
|
+
// getComputedStyle(
|
|
249
|
+
// this.#textLayers.values().next().value
|
|
250
|
+
// ).getPropertyValue("-moz-user-select") === "none";
|
|
251
|
+
// if (isFirefox) {
|
|
252
|
+
// return;
|
|
253
|
+
// }
|
|
254
|
+
// }
|
|
255
|
+
// // In non-Firefox browsers, when hovering over an empty space (thus,
|
|
256
|
+
// // on .endOfContent), the selection will expand to cover all the
|
|
257
|
+
// // text between the current selection and .endOfContent. By moving
|
|
258
|
+
// // .endOfContent to right after (or before, depending on which side
|
|
259
|
+
// // of the selection the user is moving), we limit the selection jump
|
|
260
|
+
// // to at most cover the enteirety of the <span> where the selection
|
|
261
|
+
// // is being modified.
|
|
262
|
+
// const range = selection.getRangeAt(0);
|
|
263
|
+
// const modifyStart =
|
|
264
|
+
// prevRange &&
|
|
265
|
+
// (range.compareBoundaryPoints(Range.END_TO_END, prevRange) === 0 ||
|
|
266
|
+
// range.compareBoundaryPoints(Range.START_TO_END, prevRange) === 0);
|
|
267
|
+
// let anchor = modifyStart ? range.startContainer : range.endContainer;
|
|
268
|
+
// if (anchor.nodeType === Node.TEXT_NODE) {
|
|
269
|
+
// anchor = anchor.parentNode;
|
|
270
|
+
// }
|
|
271
|
+
// const parentTextLayer = anchor.parentElement.closest(".textLayer");
|
|
272
|
+
// const endDiv = this.#textLayers.get(parentTextLayer);
|
|
273
|
+
// if (endDiv) {
|
|
274
|
+
// endDiv.style.width = parentTextLayer.style.width;
|
|
275
|
+
// endDiv.style.height = parentTextLayer.style.height;
|
|
276
|
+
// anchor.parentElement.insertBefore(
|
|
277
|
+
// endDiv,
|
|
278
|
+
// modifyStart ? anchor : anchor.nextSibling
|
|
279
|
+
// );
|
|
280
|
+
// }
|
|
281
|
+
// prevRange = range.cloneRange();
|
|
282
|
+
// },
|
|
283
|
+
// { signal }
|
|
284
|
+
// );
|
|
285
|
+
};
|
|
286
|
+
_TextLayerBuilder_textLayers = { value: new Map() };
|
|
287
|
+
_TextLayerBuilder_selectionChangeAbortController = { value: null };
|
|
288
|
+
export { TextLayerBuilder };
|
package/dist/es2015/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { saveAs } from '@progress/kendo-file-saver';
|
|
2
2
|
import { detectDesktopBrowser, detectMobileOS } from '@progress/kendo-common';
|
|
3
|
-
import { getDocument, TextLayer } from
|
|
3
|
+
import { getDocument, TextLayer } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
4
|
+
import { LinkAnnotation } from './annotations';
|
|
4
5
|
const MAX_CANVAS_WIDTH_HEIGHT_CHROME = 65535;
|
|
5
6
|
const MAX_CANVAS_AREA_CHROME_SAFARI = 268435456;
|
|
6
7
|
const MAX_CANVAS_WIDTH_HEIGHT_FIREFOX = 32767;
|
|
@@ -23,8 +24,8 @@ const isFirefox = (userAgent) => {
|
|
|
23
24
|
* @hidden
|
|
24
25
|
*/
|
|
25
26
|
export const DEFAULT_ZOOM_LEVEL = 1.25;
|
|
26
|
-
const scale = () => (isIOS() ? devicePixelRatio : devicePixelRatio * 3);
|
|
27
|
-
const parsePdfFromBase64String = (base64String) => {
|
|
27
|
+
export const scale = () => (isIOS() ? devicePixelRatio : devicePixelRatio * 3);
|
|
28
|
+
export const parsePdfFromBase64String = (base64String) => {
|
|
28
29
|
return atob(base64String.replace(/^(data:application\/pdf;base64,)/gi, ''));
|
|
29
30
|
};
|
|
30
31
|
const getDocumentParameters = (options) => {
|
|
@@ -83,7 +84,7 @@ export const download = (options, fileName = 'Document', saveOptions = {}, onDow
|
|
|
83
84
|
*/
|
|
84
85
|
export const loadPDF = (options) => {
|
|
85
86
|
const params = getDocumentParameters(options);
|
|
86
|
-
const { dom, zoom, done, error } = options;
|
|
87
|
+
const { dom, zoom, done, error, rootElement, enableAnnotations } = options;
|
|
87
88
|
const loadOnDemandPageSize = options.loadOnDemandPageSize || 2;
|
|
88
89
|
getDocument(params)
|
|
89
90
|
.promise.then((pdfDoc) => {
|
|
@@ -95,7 +96,7 @@ export const loadPDF = (options) => {
|
|
|
95
96
|
}).then(({ pages, pdfDoc }) => {
|
|
96
97
|
Promise.all(pages)
|
|
97
98
|
.then((all) => all.map((page, i) => {
|
|
98
|
-
const emptyPage = createEmptyPage(page, zoom);
|
|
99
|
+
const emptyPage = createEmptyPage(page, zoom, pdfDoc, enableAnnotations, rootElement);
|
|
99
100
|
appendPage(dom, emptyPage.pageElement, i);
|
|
100
101
|
if (options.loadOnDemand) {
|
|
101
102
|
// If LOD is enabled, render the first two(default) or X pages initially.
|
|
@@ -134,7 +135,7 @@ export const loadPDF = (options) => {
|
|
|
134
135
|
* @hidden
|
|
135
136
|
*/
|
|
136
137
|
export const reloadDocument = (params) => {
|
|
137
|
-
const { pdfDoc, zoom, dom, done, error, loadOnDemand, rootElement } = params;
|
|
138
|
+
const { pdfDoc, zoom, dom, done, error, loadOnDemand, rootElement, enableAnnotations } = params;
|
|
138
139
|
const pages = [];
|
|
139
140
|
let currentPageIndex = 0;
|
|
140
141
|
// Save the index of the current page in view before we reload the document.
|
|
@@ -148,7 +149,7 @@ export const reloadDocument = (params) => {
|
|
|
148
149
|
.then((all) => all.map((page, i) => {
|
|
149
150
|
// Set 'rendered' back to false so that the pages can be re-rendered when scrolling.
|
|
150
151
|
page._pageInfo.rendered = false;
|
|
151
|
-
const emptyPage = createEmptyPage(page, zoom);
|
|
152
|
+
const emptyPage = createEmptyPage(page, zoom, pdfDoc, enableAnnotations, rootElement);
|
|
152
153
|
appendPage(dom, emptyPage.pageElement, i);
|
|
153
154
|
// If on demand is not enabled, proceed as usual.
|
|
154
155
|
if (!loadOnDemand) {
|
|
@@ -211,13 +212,17 @@ const openPrintDialog = (dom, width, height, done, onError) => {
|
|
|
211
212
|
printDialog.addEventListener('afterprint', onAfterPrint);
|
|
212
213
|
}
|
|
213
214
|
};
|
|
214
|
-
const createEmptyPage = (page, zoom) => {
|
|
215
|
+
const createEmptyPage = (page, zoom, pdfDoc, enableAnnotations, rootElement) => {
|
|
215
216
|
const { canvasContext, viewport, pageElement, styles } = createCanvas(page, zoom, 'k-page');
|
|
216
217
|
return {
|
|
217
218
|
canvasContext,
|
|
218
219
|
viewport,
|
|
219
220
|
pageElement,
|
|
220
|
-
styles
|
|
221
|
+
styles,
|
|
222
|
+
zoom,
|
|
223
|
+
pdfDoc,
|
|
224
|
+
enableAnnotations,
|
|
225
|
+
rootElement
|
|
221
226
|
};
|
|
222
227
|
};
|
|
223
228
|
const renderCanvas = (page, done, error) => {
|
|
@@ -235,7 +240,7 @@ const renderCanvas = (page, done, error) => {
|
|
|
235
240
|
.catch(error);
|
|
236
241
|
return viewport;
|
|
237
242
|
};
|
|
238
|
-
const createElement = function (name, className, styles) {
|
|
243
|
+
export const createElement = function (name, className, styles) {
|
|
239
244
|
const element = document.createElement(name);
|
|
240
245
|
if (className) {
|
|
241
246
|
element.className = className;
|
|
@@ -243,14 +248,14 @@ const createElement = function (name, className, styles) {
|
|
|
243
248
|
Object.keys(styles).forEach((key) => (element.style[key] = styles[key]));
|
|
244
249
|
return element;
|
|
245
250
|
};
|
|
246
|
-
const transforms = {
|
|
251
|
+
export const transforms = {
|
|
247
252
|
'0': '',
|
|
248
253
|
'90': 'rotate(90deg) translateY(-100%)',
|
|
249
254
|
'180': 'rotate(180deg) translate(-100%, -100%)',
|
|
250
255
|
'270': 'rotate(270deg) translateX(-100%)'
|
|
251
256
|
};
|
|
252
257
|
export const renderPage = (page, emptyPage, error) => {
|
|
253
|
-
const { canvasContext, viewport, pageElement, styles } = emptyPage;
|
|
258
|
+
const { canvasContext, viewport, pageElement, styles, zoom, pdfDoc, enableAnnotations, rootElement } = emptyPage;
|
|
254
259
|
page._pageInfo.renderInProgress = true;
|
|
255
260
|
page.render({ canvasContext, viewport })
|
|
256
261
|
.promise.then(() => {
|
|
@@ -273,9 +278,32 @@ export const renderPage = (page, emptyPage, error) => {
|
|
|
273
278
|
el.style.fontSize = el.style.fontSize.replace(/px/g, 'pt');
|
|
274
279
|
}
|
|
275
280
|
});
|
|
276
|
-
pageElement.
|
|
281
|
+
pageElement.prepend(textLayer); // Use prepend to ensure the element is always inserted before the annotation layer.
|
|
277
282
|
}).catch(error);
|
|
278
283
|
});
|
|
284
|
+
if (enableAnnotations) {
|
|
285
|
+
page.getAnnotations({ intent: 'display' }).then((annotations) => {
|
|
286
|
+
const annotationLayer = createElement('div', 'k-annotations-layer', {
|
|
287
|
+
position: 'absolute',
|
|
288
|
+
top: '0',
|
|
289
|
+
left: '0',
|
|
290
|
+
overflow: 'hidden',
|
|
291
|
+
height: styles.height,
|
|
292
|
+
width: styles.width,
|
|
293
|
+
pointerEvents: 'none'
|
|
294
|
+
});
|
|
295
|
+
pageElement.appendChild(annotationLayer);
|
|
296
|
+
for (const annotation of annotations) {
|
|
297
|
+
switch (annotation.subtype) {
|
|
298
|
+
case 'Link':
|
|
299
|
+
new LinkAnnotation(annotationLayer, viewport, annotation, pdfDoc, zoom, rootElement);
|
|
300
|
+
break;
|
|
301
|
+
default:
|
|
302
|
+
null;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
279
307
|
})
|
|
280
308
|
.then(() => {
|
|
281
309
|
page._pageInfo.rendered = true;
|
|
@@ -389,7 +417,7 @@ export const currentPage = (rootElement) => {
|
|
|
389
417
|
* if initial size after scaling is greater than browser limits,
|
|
390
418
|
* we are limiting it to the limits, then halving it for performance.
|
|
391
419
|
*/
|
|
392
|
-
const adjustCanvasSize = (targetWidth, targetHeight) => {
|
|
420
|
+
export const adjustCanvasSize = (targetWidth, targetHeight) => {
|
|
393
421
|
const { maxWidth, maxHeight, maxArea } = isFirefox(navigator.userAgent) ?
|
|
394
422
|
{ maxWidth: MAX_CANVAS_WIDTH_HEIGHT_FIREFOX, maxHeight: MAX_CANVAS_WIDTH_HEIGHT_FIREFOX, maxArea: MAX_CANVAS_AREA_FIREFOX } :
|
|
395
423
|
isSafari(navigator.userAgent) ?
|