@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.
- 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/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 +5 -5
- 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/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 +5 -5
- 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/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 +20 -2
- package/dist/npm/utils.js +11 -8
- 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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The text layer builder provides text selection functionality for the PDF.
|
|
3
|
+
* It does this by creating overlay divs over the PDF's text. These divs
|
|
4
|
+
* contain text that matches the PDF text they are overlaying.
|
|
5
|
+
*/
|
|
6
|
+
declare class TextLayerBuilder {
|
|
7
|
+
#private;
|
|
8
|
+
pdfPage: any;
|
|
9
|
+
div: any;
|
|
10
|
+
accessibilityManager: any;
|
|
11
|
+
constructor({ pdfPage, accessibilityManager, styles, onAppend, }: {
|
|
12
|
+
pdfPage: any;
|
|
13
|
+
accessibilityManager: any;
|
|
14
|
+
styles: any;
|
|
15
|
+
onAppend?: any;
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Renders the text layer.
|
|
19
|
+
* @param {PageViewport} viewport
|
|
20
|
+
* @param {Object} [textContentParams]
|
|
21
|
+
*/
|
|
22
|
+
render(viewport: any, textContentParams?: any): Promise<void>;
|
|
23
|
+
hide(): void;
|
|
24
|
+
show(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Cancel rendering of the text layer.
|
|
27
|
+
*/
|
|
28
|
+
cancel(): void;
|
|
29
|
+
}
|
|
30
|
+
export { TextLayerBuilder };
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright 2012 Mozilla Foundation
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
var _TextLayerBuilder_instances, _a, _TextLayerBuilder_onAppend, _TextLayerBuilder_textLayer, _TextLayerBuilder_textLayers, _TextLayerBuilder_selectionChangeAbortController, _TextLayerBuilder_bindMouse, _TextLayerBuilder_removeGlobalSelectionListener, _TextLayerBuilder_enableGlobalSelectionListener;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.TextLayerBuilder = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const pdf_mjs_1 = require("pdfjs-dist/legacy/build/pdf.mjs");
|
|
21
|
+
const dom_1 = require("../common/dom");
|
|
22
|
+
/**
|
|
23
|
+
* The text layer builder provides text selection functionality for the PDF.
|
|
24
|
+
* It does this by creating overlay divs over the PDF's text. These divs
|
|
25
|
+
* contain text that matches the PDF text they are overlaying.
|
|
26
|
+
*/
|
|
27
|
+
class TextLayerBuilder {
|
|
28
|
+
constructor({ pdfPage,
|
|
29
|
+
// highlighter = null,
|
|
30
|
+
accessibilityManager,
|
|
31
|
+
// enablePermissions = false,
|
|
32
|
+
// todo: fix styles
|
|
33
|
+
styles, onAppend = null, }) {
|
|
34
|
+
_TextLayerBuilder_instances.add(this);
|
|
35
|
+
// todo: props
|
|
36
|
+
this.pdfPage = null;
|
|
37
|
+
// highlighter = null;
|
|
38
|
+
this.div = null;
|
|
39
|
+
this.accessibilityManager = null;
|
|
40
|
+
// todo: props
|
|
41
|
+
// #enablePermissions = false;
|
|
42
|
+
_TextLayerBuilder_onAppend.set(this, null);
|
|
43
|
+
// #renderingDone = false;
|
|
44
|
+
_TextLayerBuilder_textLayer.set(this, null);
|
|
45
|
+
this.pdfPage = pdfPage;
|
|
46
|
+
// this.highlighter = highlighter;
|
|
47
|
+
this.accessibilityManager = accessibilityManager;
|
|
48
|
+
// this.#enablePermissions = enablePermissions === true;
|
|
49
|
+
tslib_1.__classPrivateFieldSet(this, _TextLayerBuilder_onAppend, onAppend, "f");
|
|
50
|
+
this.div = document.createElement("div");
|
|
51
|
+
this.div.tabIndex = 0;
|
|
52
|
+
// this.div.className = "textLayer";
|
|
53
|
+
// todo: fix classes
|
|
54
|
+
this.div.classList.add("k-text-layer");
|
|
55
|
+
// todo: fix styles
|
|
56
|
+
Object.keys(styles).forEach((key) => (this.div.style[key] = styles[key]));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Renders the text layer.
|
|
60
|
+
* @param {PageViewport} viewport
|
|
61
|
+
* @param {Object} [textContentParams]
|
|
62
|
+
*/
|
|
63
|
+
render(viewport_1) {
|
|
64
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (viewport, textContentParams = null) {
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
// if (this.#renderingDone && this.#textLayer) {
|
|
67
|
+
if (tslib_1.__classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f")) {
|
|
68
|
+
tslib_1.__classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f").update({
|
|
69
|
+
viewport,
|
|
70
|
+
onBefore: this.hide.bind(this),
|
|
71
|
+
});
|
|
72
|
+
this.show();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.cancel();
|
|
76
|
+
tslib_1.__classPrivateFieldSet(this, _TextLayerBuilder_textLayer, new pdf_mjs_1.TextLayer({
|
|
77
|
+
textContentSource: this.pdfPage.streamTextContent(textContentParams || {
|
|
78
|
+
// includeMarkedContent: true,
|
|
79
|
+
// setting this to false requires removing "await"
|
|
80
|
+
// in page.ts when calling this.#renderTextLayer()
|
|
81
|
+
includeMarkedContent: false,
|
|
82
|
+
disableNormalization: true,
|
|
83
|
+
}),
|
|
84
|
+
container: this.div,
|
|
85
|
+
viewport,
|
|
86
|
+
}), "f");
|
|
87
|
+
// const { textDivs, textContentItemsStr } = this.#textLayer;
|
|
88
|
+
const { textDivs } = tslib_1.__classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f");
|
|
89
|
+
// this.highlighter?.setTextMapping(textDivs, textContentItemsStr);
|
|
90
|
+
(_a = this.accessibilityManager) === null || _a === void 0 ? void 0 : _a.setTextMapping(textDivs);
|
|
91
|
+
yield tslib_1.__classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f").render();
|
|
92
|
+
// this.#renderingDone = true;
|
|
93
|
+
// todo: manually add "k-marked-content" class
|
|
94
|
+
// as pdf.js text layer cannot render it
|
|
95
|
+
const markedContentElements = Array.from(this.div.querySelectorAll(".markedContent") || []) || [];
|
|
96
|
+
markedContentElements.forEach(x => (0, dom_1.addClass)("k-marked-content", x));
|
|
97
|
+
if (markedContentElements && markedContentElements.length > 0) {
|
|
98
|
+
const endOfContent = document.createElement("div");
|
|
99
|
+
endOfContent.className = "endOfContent";
|
|
100
|
+
this.div.append(endOfContent);
|
|
101
|
+
tslib_1.__classPrivateFieldGet(this, _TextLayerBuilder_instances, "m", _TextLayerBuilder_bindMouse).call(this, endOfContent);
|
|
102
|
+
}
|
|
103
|
+
// Ensure that the textLayer is appended to the DOM *before* handling
|
|
104
|
+
// e.g. a pending search operation.
|
|
105
|
+
(_b = tslib_1.__classPrivateFieldGet(this, _TextLayerBuilder_onAppend, "f")) === null || _b === void 0 ? void 0 : _b.call(this, this.div);
|
|
106
|
+
// this.highlighter?.enable();
|
|
107
|
+
(_c = this.accessibilityManager) === null || _c === void 0 ? void 0 : _c.enable();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
hide() {
|
|
111
|
+
// if (!this.div.hidden && this.#renderingDone) {
|
|
112
|
+
if (!this.div.hidden) {
|
|
113
|
+
// We turn off the highlighter in order to avoid to scroll into view an
|
|
114
|
+
// element of the text layer which could be hidden.
|
|
115
|
+
// this.highlighter?.disable();
|
|
116
|
+
this.div.hidden = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
show() {
|
|
120
|
+
// if (this.div.hidden && this.#renderingDone) {
|
|
121
|
+
if (this.div.hidden) {
|
|
122
|
+
this.div.hidden = false;
|
|
123
|
+
// this.highlighter?.enable();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Cancel rendering of the text layer.
|
|
128
|
+
*/
|
|
129
|
+
cancel() {
|
|
130
|
+
var _b, _c;
|
|
131
|
+
(_b = tslib_1.__classPrivateFieldGet(this, _TextLayerBuilder_textLayer, "f")) === null || _b === void 0 ? void 0 : _b.cancel();
|
|
132
|
+
tslib_1.__classPrivateFieldSet(this, _TextLayerBuilder_textLayer, null, "f");
|
|
133
|
+
// this.highlighter?.disable();
|
|
134
|
+
(_c = this.accessibilityManager) === null || _c === void 0 ? void 0 : _c.disable();
|
|
135
|
+
tslib_1.__classPrivateFieldGet(_a, _a, "m", _TextLayerBuilder_removeGlobalSelectionListener).call(_a, this.div);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.TextLayerBuilder = TextLayerBuilder;
|
|
139
|
+
_a = TextLayerBuilder, _TextLayerBuilder_onAppend = new WeakMap(), _TextLayerBuilder_textLayer = new WeakMap(), _TextLayerBuilder_instances = new WeakSet(), _TextLayerBuilder_bindMouse = function _TextLayerBuilder_bindMouse(end) {
|
|
140
|
+
const { div } = this;
|
|
141
|
+
// div.addEventListener("mousedown", () => {
|
|
142
|
+
// div.classList.add("selecting");
|
|
143
|
+
// });
|
|
144
|
+
// div.addEventListener("copy", event => {
|
|
145
|
+
// if (!this.#enablePermissions) {
|
|
146
|
+
// const selection = document.getSelection();
|
|
147
|
+
// event.clipboardData.setData(
|
|
148
|
+
// "text/plain",
|
|
149
|
+
// removeNullCharacters(normalizeUnicode(selection.toString()))
|
|
150
|
+
// );
|
|
151
|
+
// }
|
|
152
|
+
// event.preventDefault();
|
|
153
|
+
// event.stopPropagation();
|
|
154
|
+
// });
|
|
155
|
+
tslib_1.__classPrivateFieldGet(_a, _a, "f", _TextLayerBuilder_textLayers).set(div, end);
|
|
156
|
+
tslib_1.__classPrivateFieldGet(_a, _a, "m", _TextLayerBuilder_enableGlobalSelectionListener).call(_a);
|
|
157
|
+
}, _TextLayerBuilder_removeGlobalSelectionListener = function _TextLayerBuilder_removeGlobalSelectionListener(textLayerDiv) {
|
|
158
|
+
var _b;
|
|
159
|
+
tslib_1.__classPrivateFieldGet(this, _a, "f", _TextLayerBuilder_textLayers).delete(textLayerDiv);
|
|
160
|
+
if (tslib_1.__classPrivateFieldGet(this, _a, "f", _TextLayerBuilder_textLayers).size === 0) {
|
|
161
|
+
(_b = tslib_1.__classPrivateFieldGet(this, _a, "f", _TextLayerBuilder_selectionChangeAbortController)) === null || _b === void 0 ? void 0 : _b.abort();
|
|
162
|
+
tslib_1.__classPrivateFieldSet(this, _a, null, "f", _TextLayerBuilder_selectionChangeAbortController);
|
|
163
|
+
}
|
|
164
|
+
}, _TextLayerBuilder_enableGlobalSelectionListener = function _TextLayerBuilder_enableGlobalSelectionListener() {
|
|
165
|
+
// if (this.#selectionChangeAbortController) {
|
|
166
|
+
// // document-level event listeners already installed
|
|
167
|
+
// return;
|
|
168
|
+
// }
|
|
169
|
+
// this.#selectionChangeAbortController = new AbortController();
|
|
170
|
+
// const { signal } = this.#selectionChangeAbortController;
|
|
171
|
+
// const reset = (end, textLayer) => {
|
|
172
|
+
// if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
|
173
|
+
// textLayer.append(end);
|
|
174
|
+
// end.style.width = "";
|
|
175
|
+
// end.style.height = "";
|
|
176
|
+
// }
|
|
177
|
+
// textLayer.classList.remove("selecting");
|
|
178
|
+
// };
|
|
179
|
+
// let isPointerDown = false;
|
|
180
|
+
// document.addEventListener(
|
|
181
|
+
// "pointerdown",
|
|
182
|
+
// () => {
|
|
183
|
+
// isPointerDown = true;
|
|
184
|
+
// },
|
|
185
|
+
// { signal }
|
|
186
|
+
// );
|
|
187
|
+
// document.addEventListener(
|
|
188
|
+
// "pointerup",
|
|
189
|
+
// () => {
|
|
190
|
+
// isPointerDown = false;
|
|
191
|
+
// this.#textLayers.forEach(reset);
|
|
192
|
+
// },
|
|
193
|
+
// { signal }
|
|
194
|
+
// );
|
|
195
|
+
// window.addEventListener(
|
|
196
|
+
// "blur",
|
|
197
|
+
// () => {
|
|
198
|
+
// isPointerDown = false;
|
|
199
|
+
// this.#textLayers.forEach(reset);
|
|
200
|
+
// },
|
|
201
|
+
// { signal }
|
|
202
|
+
// );
|
|
203
|
+
// document.addEventListener(
|
|
204
|
+
// "keyup",
|
|
205
|
+
// () => {
|
|
206
|
+
// if (!isPointerDown) {
|
|
207
|
+
// this.#textLayers.forEach(reset);
|
|
208
|
+
// }
|
|
209
|
+
// },
|
|
210
|
+
// { signal }
|
|
211
|
+
// );
|
|
212
|
+
// if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
|
213
|
+
// // eslint-disable-next-line no-var
|
|
214
|
+
// var isFirefox, prevRange;
|
|
215
|
+
// }
|
|
216
|
+
// document.addEventListener(
|
|
217
|
+
// "selectionchange",
|
|
218
|
+
// () => {
|
|
219
|
+
// const selection = document.getSelection();
|
|
220
|
+
// if (selection.rangeCount === 0) {
|
|
221
|
+
// this.#textLayers.forEach(reset);
|
|
222
|
+
// return;
|
|
223
|
+
// }
|
|
224
|
+
// // Even though the spec says that .rangeCount should be 0 or 1, Firefox
|
|
225
|
+
// // creates multiple ranges when selecting across multiple pages.
|
|
226
|
+
// // Make sure to collect all the .textLayer elements where the selection
|
|
227
|
+
// // is happening.
|
|
228
|
+
// const activeTextLayers = new Set();
|
|
229
|
+
// for (let i = 0; i < selection.rangeCount; i++) {
|
|
230
|
+
// const range = selection.getRangeAt(i);
|
|
231
|
+
// for (const textLayerDiv of this.#textLayers.keys()) {
|
|
232
|
+
// if (
|
|
233
|
+
// !activeTextLayers.has(textLayerDiv) &&
|
|
234
|
+
// range.intersectsNode(textLayerDiv)
|
|
235
|
+
// ) {
|
|
236
|
+
// activeTextLayers.add(textLayerDiv);
|
|
237
|
+
// }
|
|
238
|
+
// }
|
|
239
|
+
// }
|
|
240
|
+
// for (const [textLayerDiv, endDiv] of this.#textLayers) {
|
|
241
|
+
// if (activeTextLayers.has(textLayerDiv)) {
|
|
242
|
+
// textLayerDiv.classList.add("selecting");
|
|
243
|
+
// } else {
|
|
244
|
+
// reset(endDiv, textLayerDiv);
|
|
245
|
+
// }
|
|
246
|
+
// }
|
|
247
|
+
// if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
|
248
|
+
// return;
|
|
249
|
+
// }
|
|
250
|
+
// if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) {
|
|
251
|
+
// isFirefox ??=
|
|
252
|
+
// getComputedStyle(
|
|
253
|
+
// this.#textLayers.values().next().value
|
|
254
|
+
// ).getPropertyValue("-moz-user-select") === "none";
|
|
255
|
+
// if (isFirefox) {
|
|
256
|
+
// return;
|
|
257
|
+
// }
|
|
258
|
+
// }
|
|
259
|
+
// // In non-Firefox browsers, when hovering over an empty space (thus,
|
|
260
|
+
// // on .endOfContent), the selection will expand to cover all the
|
|
261
|
+
// // text between the current selection and .endOfContent. By moving
|
|
262
|
+
// // .endOfContent to right after (or before, depending on which side
|
|
263
|
+
// // of the selection the user is moving), we limit the selection jump
|
|
264
|
+
// // to at most cover the enteirety of the <span> where the selection
|
|
265
|
+
// // is being modified.
|
|
266
|
+
// const range = selection.getRangeAt(0);
|
|
267
|
+
// const modifyStart =
|
|
268
|
+
// prevRange &&
|
|
269
|
+
// (range.compareBoundaryPoints(Range.END_TO_END, prevRange) === 0 ||
|
|
270
|
+
// range.compareBoundaryPoints(Range.START_TO_END, prevRange) === 0);
|
|
271
|
+
// let anchor = modifyStart ? range.startContainer : range.endContainer;
|
|
272
|
+
// if (anchor.nodeType === Node.TEXT_NODE) {
|
|
273
|
+
// anchor = anchor.parentNode;
|
|
274
|
+
// }
|
|
275
|
+
// const parentTextLayer = anchor.parentElement.closest(".textLayer");
|
|
276
|
+
// const endDiv = this.#textLayers.get(parentTextLayer);
|
|
277
|
+
// if (endDiv) {
|
|
278
|
+
// endDiv.style.width = parentTextLayer.style.width;
|
|
279
|
+
// endDiv.style.height = parentTextLayer.style.height;
|
|
280
|
+
// anchor.parentElement.insertBefore(
|
|
281
|
+
// endDiv,
|
|
282
|
+
// modifyStart ? anchor : anchor.nextSibling
|
|
283
|
+
// );
|
|
284
|
+
// }
|
|
285
|
+
// prevRange = range.cloneRange();
|
|
286
|
+
// },
|
|
287
|
+
// { signal }
|
|
288
|
+
// );
|
|
289
|
+
};
|
|
290
|
+
_TextLayerBuilder_textLayers = { value: new Map() };
|
|
291
|
+
_TextLayerBuilder_selectionChangeAbortController = { value: null };
|
package/dist/npm/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SaveOptions } from '@progress/kendo-file-saver';
|
|
2
|
-
import { PDFPageProxy, PDFDocumentProxy } from
|
|
3
|
-
import { TypedArray } from
|
|
2
|
+
import { PDFPageProxy, PDFDocumentProxy } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
3
|
+
import { TypedArray } from "pdfjs-dist/types/src/display/api";
|
|
4
4
|
/**
|
|
5
5
|
* @hidden
|
|
6
6
|
*/
|
|
@@ -52,6 +52,8 @@ export interface PDFReloadParameters {
|
|
|
52
52
|
* @hidden
|
|
53
53
|
*/
|
|
54
54
|
export declare const DEFAULT_ZOOM_LEVEL = 1.25;
|
|
55
|
+
export declare const scale: () => number;
|
|
56
|
+
export declare const parsePdfFromBase64String: (base64String: string) => string;
|
|
55
57
|
/**
|
|
56
58
|
* @hidden
|
|
57
59
|
*/
|
|
@@ -78,6 +80,9 @@ export declare const print: (pages: PDFPageProxy[], done: () => void, error: Err
|
|
|
78
80
|
export declare const createElement: <T>(name: string, className: string, styles: {
|
|
79
81
|
[key: string]: string;
|
|
80
82
|
}) => T;
|
|
83
|
+
export declare const transforms: {
|
|
84
|
+
[rotation: string]: string;
|
|
85
|
+
};
|
|
81
86
|
export declare const renderPage: (page: PDFPageProxy, emptyPage: any, error: ErrorFn) => any;
|
|
82
87
|
/**
|
|
83
88
|
* @hidden
|
|
@@ -105,3 +110,16 @@ export declare const scrollToPage: (rootElement: HTMLElement, pageNumber: number
|
|
|
105
110
|
* @returns The page number.
|
|
106
111
|
*/
|
|
107
112
|
export declare const currentPage: (rootElement: HTMLElement) => number;
|
|
113
|
+
/**
|
|
114
|
+
* @hidden
|
|
115
|
+
*
|
|
116
|
+
* related to https://github.com/telerik/kendo-pdfviewer-common/issues/6
|
|
117
|
+
* the bigger the canvas size, the worse the performance;
|
|
118
|
+
* if initial size after scaling is greater than browser limits,
|
|
119
|
+
* we are limiting it to the limits, then halving it for performance.
|
|
120
|
+
*/
|
|
121
|
+
export declare const adjustCanvasSize: (targetWidth: number, targetHeight: number) => {
|
|
122
|
+
adjustedWidth: number;
|
|
123
|
+
adjustedHeight: number;
|
|
124
|
+
adjustRatio: number;
|
|
125
|
+
};
|
package/dist/npm/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.currentPage = exports.scrollToPage = exports.calculateZoomLevel = exports.goToPreviousSearchMatch = exports.goToNextSearchMatch = exports.renderPage = exports.createElement = exports.print = exports.reloadDocument = exports.loadPDF = exports.download = exports.removeChildren = exports.DEFAULT_ZOOM_LEVEL = void 0;
|
|
3
|
+
exports.adjustCanvasSize = exports.currentPage = exports.scrollToPage = exports.calculateZoomLevel = exports.goToPreviousSearchMatch = exports.goToNextSearchMatch = exports.renderPage = exports.transforms = exports.createElement = exports.print = exports.reloadDocument = exports.loadPDF = exports.download = exports.removeChildren = exports.parsePdfFromBase64String = exports.scale = exports.DEFAULT_ZOOM_LEVEL = void 0;
|
|
4
4
|
const kendo_file_saver_1 = require("@progress/kendo-file-saver");
|
|
5
5
|
const kendo_common_1 = require("@progress/kendo-common");
|
|
6
6
|
const pdf_mjs_1 = require("pdfjs-dist/legacy/build/pdf.mjs");
|
|
@@ -28,16 +28,18 @@ const isFirefox = (userAgent) => {
|
|
|
28
28
|
*/
|
|
29
29
|
exports.DEFAULT_ZOOM_LEVEL = 1.25;
|
|
30
30
|
const scale = () => (isIOS() ? devicePixelRatio : devicePixelRatio * 3);
|
|
31
|
+
exports.scale = scale;
|
|
31
32
|
const parsePdfFromBase64String = (base64String) => {
|
|
32
33
|
return atob(base64String.replace(/^(data:application\/pdf;base64,)/gi, ''));
|
|
33
34
|
};
|
|
35
|
+
exports.parsePdfFromBase64String = parsePdfFromBase64String;
|
|
34
36
|
const getDocumentParameters = (options) => {
|
|
35
37
|
let params = {
|
|
36
38
|
verbosity: 0,
|
|
37
39
|
isEvalSupported: false
|
|
38
40
|
};
|
|
39
41
|
if (typeof options.data === 'string') {
|
|
40
|
-
params.data = parsePdfFromBase64String(options.data);
|
|
42
|
+
params.data = (0, exports.parsePdfFromBase64String)(options.data);
|
|
41
43
|
}
|
|
42
44
|
else if (typeof options.url === 'string') {
|
|
43
45
|
params.url = options.url;
|
|
@@ -183,7 +185,7 @@ exports.reloadDocument = reloadDocument;
|
|
|
183
185
|
const print = (pages, done, error) => {
|
|
184
186
|
const dom = document.createElement('div');
|
|
185
187
|
const allDone = pages.map(() => false);
|
|
186
|
-
const scaleNum = scale();
|
|
188
|
+
const scaleNum = (0, exports.scale)();
|
|
187
189
|
pages.forEach((page, index) => {
|
|
188
190
|
const viewport = renderCanvas(page, (el) => {
|
|
189
191
|
dom.appendChild(el);
|
|
@@ -257,7 +259,7 @@ const createElement = function (name, className, styles) {
|
|
|
257
259
|
return element;
|
|
258
260
|
};
|
|
259
261
|
exports.createElement = createElement;
|
|
260
|
-
|
|
262
|
+
exports.transforms = {
|
|
261
263
|
'0': '',
|
|
262
264
|
'90': 'rotate(90deg) translateY(-100%)',
|
|
263
265
|
'180': 'rotate(180deg) translate(-100%, -100%)',
|
|
@@ -278,8 +280,8 @@ const renderPage = (page, emptyPage, error) => {
|
|
|
278
280
|
textLayer.style.width = textLayer.style.width.replace(/px/g, 'pt');
|
|
279
281
|
textLayer.style.height = textLayer.style.height.replace(/px/g, 'pt');
|
|
280
282
|
const rotation = textLayer.getAttribute('data-main-rotation') || '0';
|
|
281
|
-
if (transforms[rotation]) {
|
|
282
|
-
textLayer.style.transform = transforms[rotation];
|
|
283
|
+
if (exports.transforms[rotation]) {
|
|
284
|
+
textLayer.style.transform = exports.transforms[rotation];
|
|
283
285
|
textLayer.style.transformOrigin = 'top left';
|
|
284
286
|
}
|
|
285
287
|
textLayer.querySelectorAll('span').forEach((el) => {
|
|
@@ -470,10 +472,11 @@ const adjustCanvasSize = (targetWidth, targetHeight) => {
|
|
|
470
472
|
adjustRatio: adjustRatio !== 1 ? adjustRatio / 2 : 1
|
|
471
473
|
};
|
|
472
474
|
};
|
|
475
|
+
exports.adjustCanvasSize = adjustCanvasSize;
|
|
473
476
|
const createCanvas = (page, zoom = 1, cssClass = '') => {
|
|
474
|
-
const scaleNum = scale();
|
|
477
|
+
const scaleNum = (0, exports.scale)();
|
|
475
478
|
const viewport = page.getViewport({ scale: scaleNum });
|
|
476
|
-
const { adjustedWidth, adjustedHeight, adjustRatio } = adjustCanvasSize(viewport.width, viewport.height);
|
|
479
|
+
const { adjustedWidth, adjustedHeight, adjustRatio } = (0, exports.adjustCanvasSize)(viewport.width, viewport.height);
|
|
477
480
|
const styles = {
|
|
478
481
|
width: Math.floor(viewport.width / scaleNum) * zoom + 'pt',
|
|
479
482
|
height: Math.floor(viewport.height / scaleNum) * zoom + 'pt'
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { PDFPageProxy } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
2
|
+
import { TextAccessibilityManager } from "../annotations/helpers/text-accessibility-manager";
|
|
3
|
+
import { Component } from "../common/component";
|
|
4
|
+
import { TextLayerBuilder } from "../text/text-layer-builder";
|
|
5
|
+
import { AnnotationLayerBuilder } from "../annotations/annotation-layer-builder";
|
|
6
|
+
import { DrawLayerBuilder } from "../annotations/draw-layer-builder";
|
|
7
|
+
import { AnnotationEditorLayerBuilder } from "../annotations/annotation-editor-layer-builder";
|
|
8
|
+
import { PdfViewer } from "./pdfviewer";
|
|
9
|
+
import { EventBus } from "../annotations/shared/event_utils";
|
|
10
|
+
export declare class Page extends Component {
|
|
11
|
+
#private;
|
|
12
|
+
eventBus: EventBus;
|
|
13
|
+
zoomLayer: any;
|
|
14
|
+
div: any;
|
|
15
|
+
viewport: any;
|
|
16
|
+
id: any;
|
|
17
|
+
_accessibilityManager: TextAccessibilityManager;
|
|
18
|
+
_annotationCanvasMap: any;
|
|
19
|
+
renderTask: any;
|
|
20
|
+
pdfPageRotate: any;
|
|
21
|
+
rotation: any;
|
|
22
|
+
scale: number;
|
|
23
|
+
pdfViewer: PdfViewer;
|
|
24
|
+
xfaLayer: any;
|
|
25
|
+
element: HTMLDivElement;
|
|
26
|
+
canvas: any;
|
|
27
|
+
canvasForPrint: any;
|
|
28
|
+
textLayer: TextLayerBuilder;
|
|
29
|
+
textLayerBuilder: TextLayerBuilder;
|
|
30
|
+
textAccessibilityManager: TextAccessibilityManager;
|
|
31
|
+
annotationLayer: AnnotationLayerBuilder;
|
|
32
|
+
drawLayer: DrawLayerBuilder;
|
|
33
|
+
annotationEditorLayer: AnnotationEditorLayerBuilder;
|
|
34
|
+
options: any;
|
|
35
|
+
state: any;
|
|
36
|
+
pdfPage: PDFPageProxy;
|
|
37
|
+
constructor(element: any, options: any);
|
|
38
|
+
destroy(): void;
|
|
39
|
+
get isEditing(): boolean;
|
|
40
|
+
get rawWidth(): any;
|
|
41
|
+
get rawHeight(): any;
|
|
42
|
+
setState(newState: any): void;
|
|
43
|
+
resetState(): void;
|
|
44
|
+
initScale(): void;
|
|
45
|
+
createPromise(): Promise<any>;
|
|
46
|
+
getViewport(options?: {
|
|
47
|
+
scale: number;
|
|
48
|
+
}): import("pdfjs-dist/types/src/display/display_utils").PageViewport | {
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
};
|
|
52
|
+
destroyTextLayer(): void;
|
|
53
|
+
removeTextLayer(): void;
|
|
54
|
+
getPrintContentAsync(): Promise<any>;
|
|
55
|
+
loadForPrintAsync({ zoomLevel, force }: {
|
|
56
|
+
zoomLevel?: number;
|
|
57
|
+
force?: boolean;
|
|
58
|
+
}): any;
|
|
59
|
+
renderForPrintAsync(): Promise<void>;
|
|
60
|
+
isBlank(): string;
|
|
61
|
+
setBlank(isBlank: any): void;
|
|
62
|
+
get renderingState(): number;
|
|
63
|
+
setPdfPage(pdfPage: any): void;
|
|
64
|
+
hasEditableAnnotations(): boolean;
|
|
65
|
+
_resetZoomLayer(removeFromDOM?: boolean): void;
|
|
66
|
+
reset({ keepZoomLayer, keepAnnotationLayer, keepAnnotationEditorLayer, keepXfaLayer, keepTextLayer, }?: {
|
|
67
|
+
keepZoomLayer?: boolean;
|
|
68
|
+
keepAnnotationLayer?: boolean;
|
|
69
|
+
keepAnnotationEditorLayer?: boolean;
|
|
70
|
+
keepXfaLayer?: boolean;
|
|
71
|
+
keepTextLayer?: boolean;
|
|
72
|
+
}): void;
|
|
73
|
+
toggleEditingMode(isEditing: any): void;
|
|
74
|
+
draw(): Promise<void>;
|
|
75
|
+
}
|