@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,501 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright 2015 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 _a, _PDFLinkService_isValidExplicitDest;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.PDFLinkService = exports.LinkTarget = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const ui_utils_1 = require("../annotations/shared/ui_utils");
|
|
21
|
+
const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
|
|
22
|
+
const LinkTarget = {
|
|
23
|
+
NONE: 0, // Default value.
|
|
24
|
+
SELF: 1,
|
|
25
|
+
BLANK: 2,
|
|
26
|
+
PARENT: 3,
|
|
27
|
+
TOP: 4,
|
|
28
|
+
};
|
|
29
|
+
exports.LinkTarget = LinkTarget;
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {Object} PDFLinkServiceOptions
|
|
32
|
+
* @property {EventBus} eventBus - The application event bus.
|
|
33
|
+
* @property {number} [externalLinkTarget] - Specifies the `target` attribute
|
|
34
|
+
* for external links. Must use one of the values from {LinkTarget}.
|
|
35
|
+
* Defaults to using no target.
|
|
36
|
+
* @property {string} [externalLinkRel] - Specifies the `rel` attribute for
|
|
37
|
+
* external links. Defaults to stripping the referrer.
|
|
38
|
+
* @property {boolean} [ignoreDestinationZoom] - Ignores the zoom argument,
|
|
39
|
+
* thus preserving the current zoom level in the viewer, when navigating
|
|
40
|
+
* to internal destinations. The default value is `false`.
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Performs navigation functions inside PDF, such as opening specified page,
|
|
44
|
+
* or destination.
|
|
45
|
+
* @implements {IPDFLinkService}
|
|
46
|
+
*/
|
|
47
|
+
class PDFLinkService {
|
|
48
|
+
/**
|
|
49
|
+
* @param {PDFLinkServiceOptions} options
|
|
50
|
+
*/
|
|
51
|
+
constructor({ eventBus = null, externalLinkTarget = null, externalLinkRel = null, ignoreDestinationZoom = false, } = {}) {
|
|
52
|
+
// todo: props
|
|
53
|
+
this.eventBus = null;
|
|
54
|
+
this.externalLinkTarget = null;
|
|
55
|
+
this.externalLinkRel = null;
|
|
56
|
+
this._ignoreDestinationZoom = null;
|
|
57
|
+
this.baseUrl = null;
|
|
58
|
+
this.pdfDocument = null;
|
|
59
|
+
this.pdfViewer = null;
|
|
60
|
+
this.pdfHistory = null;
|
|
61
|
+
// todo: props
|
|
62
|
+
this.externalLinkEnabled = true;
|
|
63
|
+
this.eventBus = eventBus;
|
|
64
|
+
this.externalLinkTarget = externalLinkTarget;
|
|
65
|
+
this.externalLinkRel = externalLinkRel;
|
|
66
|
+
this._ignoreDestinationZoom = ignoreDestinationZoom;
|
|
67
|
+
this.baseUrl = null;
|
|
68
|
+
this.pdfDocument = null;
|
|
69
|
+
this.pdfViewer = null;
|
|
70
|
+
this.pdfHistory = null;
|
|
71
|
+
}
|
|
72
|
+
setDocument(pdfDocument, baseUrl = null) {
|
|
73
|
+
this.baseUrl = baseUrl;
|
|
74
|
+
this.pdfDocument = pdfDocument;
|
|
75
|
+
}
|
|
76
|
+
setViewer(pdfViewer) {
|
|
77
|
+
this.pdfViewer = pdfViewer;
|
|
78
|
+
}
|
|
79
|
+
setHistory(pdfHistory) {
|
|
80
|
+
this.pdfHistory = pdfHistory;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @type {number}
|
|
84
|
+
*/
|
|
85
|
+
get pagesCount() {
|
|
86
|
+
return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @type {number}
|
|
90
|
+
*/
|
|
91
|
+
get page() {
|
|
92
|
+
return this.pdfDocument ? this.pdfViewer.currentPageNumber : 1;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @param {number} value
|
|
96
|
+
*/
|
|
97
|
+
set page(value) {
|
|
98
|
+
if (this.pdfDocument) {
|
|
99
|
+
this.pdfViewer.currentPageNumber = value;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @type {number}
|
|
104
|
+
*/
|
|
105
|
+
get rotation() {
|
|
106
|
+
return this.pdfDocument ? this.pdfViewer.pagesRotation : 0;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @param {number} value
|
|
110
|
+
*/
|
|
111
|
+
set rotation(value) {
|
|
112
|
+
if (this.pdfDocument) {
|
|
113
|
+
this.pdfViewer.pagesRotation = value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @type {boolean}
|
|
118
|
+
*/
|
|
119
|
+
get isInPresentationMode() {
|
|
120
|
+
return this.pdfDocument ? this.pdfViewer.isInPresentationMode : false;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* This method will, when available, also update the browser history.
|
|
124
|
+
*
|
|
125
|
+
* @param {string|Array} dest - The named, or explicit, PDF destination.
|
|
126
|
+
*/
|
|
127
|
+
goToDestination(dest) {
|
|
128
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
if (!this.pdfDocument) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let namedDest, explicitDest, pageNumber;
|
|
133
|
+
if (typeof dest === "string") {
|
|
134
|
+
namedDest = dest;
|
|
135
|
+
explicitDest = yield this.pdfDocument.getDestination(dest);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
namedDest = null;
|
|
139
|
+
explicitDest = yield dest;
|
|
140
|
+
}
|
|
141
|
+
if (!Array.isArray(explicitDest)) {
|
|
142
|
+
// console.error(
|
|
143
|
+
// `goToDestination: "${explicitDest}" is not a valid destination array, for dest="${dest}".`
|
|
144
|
+
// );
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
|
|
148
|
+
const [destRef] = explicitDest;
|
|
149
|
+
if (destRef && typeof destRef === "object") {
|
|
150
|
+
pageNumber = this.pdfDocument.cachedPageNumber(destRef);
|
|
151
|
+
if (!pageNumber) {
|
|
152
|
+
// Fetch the page reference if it's not yet available. This could
|
|
153
|
+
// only occur during loading, before all pages have been resolved.
|
|
154
|
+
try {
|
|
155
|
+
pageNumber = (yield this.pdfDocument.getPageIndex(destRef)) + 1;
|
|
156
|
+
}
|
|
157
|
+
catch (_b) {
|
|
158
|
+
console.error(`goToDestination: "${destRef}" is not a valid page reference, for dest="${dest}".`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (Number.isInteger(destRef)) {
|
|
164
|
+
pageNumber = destRef + 1;
|
|
165
|
+
}
|
|
166
|
+
if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
|
|
167
|
+
console.error(`goToDestination: "${pageNumber}" is not a valid page number, for dest="${dest}".`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (this.pdfHistory) {
|
|
171
|
+
// Update the browser history before scrolling the new destination into
|
|
172
|
+
// view, to be able to accurately capture the current document position.
|
|
173
|
+
this.pdfHistory.pushCurrentPosition();
|
|
174
|
+
this.pdfHistory.push({ namedDest, explicitDest, pageNumber });
|
|
175
|
+
}
|
|
176
|
+
this.pdfViewer.scrollPageIntoView({
|
|
177
|
+
pageNumber,
|
|
178
|
+
destArray: explicitDest,
|
|
179
|
+
ignoreDestinationZoom: this._ignoreDestinationZoom,
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* This method will, when available, also update the browser history.
|
|
185
|
+
*
|
|
186
|
+
* @param {number|string} val - The page number, or page label.
|
|
187
|
+
*/
|
|
188
|
+
goToPage(val) {
|
|
189
|
+
if (!this.pdfDocument) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const pageNumber = (typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val)) ||
|
|
193
|
+
val | 0;
|
|
194
|
+
if (!(Number.isInteger(pageNumber) &&
|
|
195
|
+
pageNumber > 0 &&
|
|
196
|
+
pageNumber <= this.pagesCount)) {
|
|
197
|
+
console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (this.pdfHistory) {
|
|
201
|
+
// Update the browser history before scrolling the new page into view,
|
|
202
|
+
// to be able to accurately capture the current document position.
|
|
203
|
+
this.pdfHistory.pushCurrentPosition();
|
|
204
|
+
this.pdfHistory.pushPage(pageNumber);
|
|
205
|
+
}
|
|
206
|
+
this.pdfViewer.scrollPageIntoView({ pageNumber });
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Adds various attributes (href, title, target, rel) to hyperlinks.
|
|
210
|
+
* @param {HTMLAnchorElement} link
|
|
211
|
+
* @param {string} url
|
|
212
|
+
* @param {boolean} [newWindow]
|
|
213
|
+
*/
|
|
214
|
+
addLinkAttributes(link, url, newWindow = false) {
|
|
215
|
+
if (!url || typeof url !== "string") {
|
|
216
|
+
throw new Error('A valid "url" parameter must provided.');
|
|
217
|
+
}
|
|
218
|
+
const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget, rel = this.externalLinkRel;
|
|
219
|
+
if (this.externalLinkEnabled) {
|
|
220
|
+
link.href = link.title = url;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
link.href = "";
|
|
224
|
+
link.title = `Disabled: ${url}`;
|
|
225
|
+
link.onclick = () => false;
|
|
226
|
+
}
|
|
227
|
+
let targetStr = ""; // LinkTarget.NONE
|
|
228
|
+
switch (target) {
|
|
229
|
+
case LinkTarget.NONE:
|
|
230
|
+
break;
|
|
231
|
+
case LinkTarget.SELF:
|
|
232
|
+
targetStr = "_self";
|
|
233
|
+
break;
|
|
234
|
+
case LinkTarget.BLANK:
|
|
235
|
+
targetStr = "_blank";
|
|
236
|
+
break;
|
|
237
|
+
case LinkTarget.PARENT:
|
|
238
|
+
targetStr = "_parent";
|
|
239
|
+
break;
|
|
240
|
+
case LinkTarget.TOP:
|
|
241
|
+
targetStr = "_top";
|
|
242
|
+
break;
|
|
243
|
+
default: break;
|
|
244
|
+
}
|
|
245
|
+
link.target = targetStr;
|
|
246
|
+
link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* @param {string|Array} dest - The PDF destination object.
|
|
250
|
+
* @returns {string} The hyperlink to the PDF object.
|
|
251
|
+
*/
|
|
252
|
+
getDestinationHash(dest) {
|
|
253
|
+
if (typeof dest === "string") {
|
|
254
|
+
if (dest.length > 0) {
|
|
255
|
+
return this.getAnchorUrl("#" + escape(dest));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
else if (Array.isArray(dest)) {
|
|
259
|
+
const str = JSON.stringify(dest);
|
|
260
|
+
if (str.length > 0) {
|
|
261
|
+
return this.getAnchorUrl("#" + escape(str));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return this.getAnchorUrl("");
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Prefix the full url on anchor links to make sure that links are resolved
|
|
268
|
+
* relative to the current URL instead of the one defined in <base href>.
|
|
269
|
+
* @param {string} anchor - The anchor hash, including the #.
|
|
270
|
+
* @returns {string} The hyperlink to the PDF object.
|
|
271
|
+
*/
|
|
272
|
+
getAnchorUrl(anchor) {
|
|
273
|
+
return this.baseUrl ? this.baseUrl + anchor : anchor;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* @param {string} hash
|
|
277
|
+
*/
|
|
278
|
+
setHash(hash) {
|
|
279
|
+
if (!this.pdfDocument) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
let pageNumber, dest;
|
|
283
|
+
if (hash.includes("=")) {
|
|
284
|
+
const params = (0, ui_utils_1.parseQueryString)(hash);
|
|
285
|
+
if (params.has("search")) {
|
|
286
|
+
const query = params.get("search").replaceAll('"', ""), phrase = params.get("phrase") === "true";
|
|
287
|
+
this.eventBus.dispatch("findfromurlhash", {
|
|
288
|
+
source: this,
|
|
289
|
+
query: phrase ? query : query.match(/\S+/g),
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
// borrowing syntax from "Parameters for Opening PDF Files"
|
|
293
|
+
if (params.has("page")) {
|
|
294
|
+
pageNumber = params.get("page") | 0 || 1;
|
|
295
|
+
}
|
|
296
|
+
if (params.has("zoom")) {
|
|
297
|
+
// Build the destination array.
|
|
298
|
+
const zoomArgs = params.get("zoom").split(","); // scale,left,top
|
|
299
|
+
const zoomArg = zoomArgs[0];
|
|
300
|
+
const zoomArgNumber = parseFloat(zoomArg);
|
|
301
|
+
if (!zoomArg.includes("Fit")) {
|
|
302
|
+
// If the zoomArg is a number, it has to get divided by 100. If it's
|
|
303
|
+
// a string, it should stay as it is.
|
|
304
|
+
dest = [
|
|
305
|
+
null,
|
|
306
|
+
{ name: "XYZ" },
|
|
307
|
+
zoomArgs.length > 1 ? zoomArgs[1] | 0 : null,
|
|
308
|
+
zoomArgs.length > 2 ? zoomArgs[2] | 0 : null,
|
|
309
|
+
zoomArgNumber ? zoomArgNumber / 100 : zoomArg,
|
|
310
|
+
];
|
|
311
|
+
}
|
|
312
|
+
else if (zoomArg === "Fit" || zoomArg === "FitB") {
|
|
313
|
+
dest = [null, { name: zoomArg }];
|
|
314
|
+
}
|
|
315
|
+
else if (zoomArg === "FitH" ||
|
|
316
|
+
zoomArg === "FitBH" ||
|
|
317
|
+
zoomArg === "FitV" ||
|
|
318
|
+
zoomArg === "FitBV") {
|
|
319
|
+
dest = [
|
|
320
|
+
null,
|
|
321
|
+
{ name: zoomArg },
|
|
322
|
+
zoomArgs.length > 1 ? zoomArgs[1] | 0 : null,
|
|
323
|
+
];
|
|
324
|
+
}
|
|
325
|
+
else if (zoomArg === "FitR") {
|
|
326
|
+
if (zoomArgs.length !== 5) {
|
|
327
|
+
console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
dest = [
|
|
331
|
+
null,
|
|
332
|
+
{ name: zoomArg },
|
|
333
|
+
zoomArgs[1] | 0,
|
|
334
|
+
zoomArgs[2] | 0,
|
|
335
|
+
zoomArgs[3] | 0,
|
|
336
|
+
zoomArgs[4] | 0,
|
|
337
|
+
];
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (dest) {
|
|
345
|
+
this.pdfViewer.scrollPageIntoView({
|
|
346
|
+
pageNumber: pageNumber || this.page,
|
|
347
|
+
destArray: dest,
|
|
348
|
+
allowNegativeOffset: true,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
else if (pageNumber) {
|
|
352
|
+
this.page = pageNumber; // simple page
|
|
353
|
+
}
|
|
354
|
+
if (params.has("pagemode")) {
|
|
355
|
+
this.eventBus.dispatch("pagemode", {
|
|
356
|
+
source: this,
|
|
357
|
+
mode: params.get("pagemode"),
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
// Ensure that this parameter is *always* handled last, in order to
|
|
361
|
+
// guarantee that it won't be overridden (e.g. by the "page" parameter).
|
|
362
|
+
if (params.has("nameddest")) {
|
|
363
|
+
this.goToDestination(params.get("nameddest"));
|
|
364
|
+
}
|
|
365
|
+
// if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
|
366
|
+
return;
|
|
367
|
+
// }
|
|
368
|
+
// // Support opening of PDF attachments in the Firefox PDF Viewer,
|
|
369
|
+
// // which uses a couple of non-standard hash parameters; refer to
|
|
370
|
+
// // `DownloadManager.openOrDownloadData` in the firefoxcom.js file.
|
|
371
|
+
// if (!params.has("filename") || !params.has("filedest")) {
|
|
372
|
+
// return;
|
|
373
|
+
// }
|
|
374
|
+
// hash = params.get("filedest");
|
|
375
|
+
}
|
|
376
|
+
// Named (or explicit) destination.
|
|
377
|
+
dest = unescape(hash);
|
|
378
|
+
try {
|
|
379
|
+
dest = JSON.parse(dest);
|
|
380
|
+
if (!Array.isArray(dest)) {
|
|
381
|
+
// Avoid incorrectly rejecting a valid named destination, such as
|
|
382
|
+
// e.g. "4.3" or "true", because `JSON.parse` converted its type.
|
|
383
|
+
dest = dest.toString();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
catch (e) {
|
|
387
|
+
if (!e) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (typeof dest === "string" || tslib_1.__classPrivateFieldGet(_a, _a, "m", _PDFLinkService_isValidExplicitDest).call(_a, dest)) {
|
|
392
|
+
this.goToDestination(dest);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
// console.error(
|
|
396
|
+
// `PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`
|
|
397
|
+
// );
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* @param {string} action
|
|
401
|
+
*/
|
|
402
|
+
executeNamedAction(action) {
|
|
403
|
+
var _b, _c;
|
|
404
|
+
if (!this.pdfDocument) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
// See PDF reference, table 8.45 - Named action
|
|
408
|
+
switch (action) {
|
|
409
|
+
case "GoBack":
|
|
410
|
+
(_b = this.pdfHistory) === null || _b === void 0 ? void 0 : _b.back();
|
|
411
|
+
break;
|
|
412
|
+
case "GoForward":
|
|
413
|
+
(_c = this.pdfHistory) === null || _c === void 0 ? void 0 : _c.forward();
|
|
414
|
+
break;
|
|
415
|
+
case "NextPage":
|
|
416
|
+
this.pdfViewer.nextPage();
|
|
417
|
+
break;
|
|
418
|
+
case "PrevPage":
|
|
419
|
+
this.pdfViewer.previousPage();
|
|
420
|
+
break;
|
|
421
|
+
case "LastPage":
|
|
422
|
+
this.page = this.pagesCount;
|
|
423
|
+
break;
|
|
424
|
+
case "FirstPage":
|
|
425
|
+
this.page = 1;
|
|
426
|
+
break;
|
|
427
|
+
default:
|
|
428
|
+
break; // No action according to spec
|
|
429
|
+
}
|
|
430
|
+
this.eventBus.dispatch("namedaction", {
|
|
431
|
+
source: this,
|
|
432
|
+
action,
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* @param {Object} action
|
|
437
|
+
*/
|
|
438
|
+
executeSetOCGState(action) {
|
|
439
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
440
|
+
if (!this.pdfDocument) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
const pdfDocument = this.pdfDocument, optionalContentConfig = yield this.pdfViewer.optionalContentConfigPromise;
|
|
444
|
+
if (pdfDocument !== this.pdfDocument) {
|
|
445
|
+
return; // The document was closed while the optional content resolved.
|
|
446
|
+
}
|
|
447
|
+
optionalContentConfig.setOCGState(action);
|
|
448
|
+
this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
exports.PDFLinkService = PDFLinkService;
|
|
453
|
+
_a = PDFLinkService, _PDFLinkService_isValidExplicitDest = function _PDFLinkService_isValidExplicitDest(dest) {
|
|
454
|
+
if (!Array.isArray(dest) || dest.length < 2) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
const [page, zoom, ...args] = dest;
|
|
458
|
+
if (!(typeof page === "object" &&
|
|
459
|
+
Number.isInteger(page === null || page === void 0 ? void 0 : page.num) &&
|
|
460
|
+
Number.isInteger(page === null || page === void 0 ? void 0 : page.gen)) &&
|
|
461
|
+
!Number.isInteger(page)) {
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
if (!(typeof zoom === "object" && typeof (zoom === null || zoom === void 0 ? void 0 : zoom.name) === "string")) {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
const argsLen = args.length;
|
|
468
|
+
let allowNull = true;
|
|
469
|
+
switch (zoom.name) {
|
|
470
|
+
case "XYZ":
|
|
471
|
+
if (argsLen < 2 || argsLen > 3) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
break;
|
|
475
|
+
case "Fit":
|
|
476
|
+
case "FitB":
|
|
477
|
+
return argsLen === 0;
|
|
478
|
+
case "FitH":
|
|
479
|
+
case "FitBH":
|
|
480
|
+
case "FitV":
|
|
481
|
+
case "FitBV":
|
|
482
|
+
if (argsLen > 1) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
break;
|
|
486
|
+
case "FitR":
|
|
487
|
+
if (argsLen !== 4) {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
allowNull = false;
|
|
491
|
+
break;
|
|
492
|
+
default:
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
for (const arg of args) {
|
|
496
|
+
if (!(typeof arg === "number" || (allowNull && arg === null))) {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return true;
|
|
501
|
+
};
|
package/dist/npm/main.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './scroller';
|
|
2
2
|
export * from './search';
|
|
3
3
|
export * from './utils';
|
|
4
|
+
export * from './widget/pdfviewer';
|
|
5
|
+
export * from './enums/PdfViewerInteractionMode';
|
|
4
6
|
export { PDFDocumentProxy } from 'pdfjs-dist';
|
|
5
7
|
export { TypedArray } from 'pdfjs-dist/types/src/display/api';
|
package/dist/npm/main.js
CHANGED
|
@@ -4,3 +4,5 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./scroller"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./search"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./utils"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./widget/pdfviewer"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./enums/PdfViewerInteractionMode"), exports);
|
package/dist/npm/scroller.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { Component } from './common/component';
|
|
2
|
+
export declare const throttle: (func: Function, wait: number, options?: any) => Function;
|
|
1
3
|
/**
|
|
2
4
|
* @hidden
|
|
3
5
|
*/
|
|
4
|
-
export declare class Scroller {
|
|
6
|
+
export declare class Scroller extends Component {
|
|
5
7
|
options: any;
|
|
6
8
|
state: any;
|
|
7
9
|
element: any;
|
|
@@ -23,8 +25,10 @@ export declare class Scroller {
|
|
|
23
25
|
enablePanEventsTracking(): void;
|
|
24
26
|
disablePanEventsTracking(): void;
|
|
25
27
|
shouldTrackPanEvents(): boolean;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
enableScrollEventsTracking(): void;
|
|
29
|
+
disableScrollEventsTracking(): void;
|
|
30
|
+
shouldTrackScrollEvents(): boolean;
|
|
31
|
+
onElementScroll: (e: any) => void;
|
|
28
32
|
onDragStart: (e: any) => void;
|
|
29
33
|
onDrag: (e: any) => void;
|
|
30
34
|
onDragEnd: () => void;
|
package/dist/npm/scroller.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Scroller = void 0;
|
|
3
|
+
exports.Scroller = exports.throttle = void 0;
|
|
4
4
|
const kendo_draggable_1 = require("@progress/kendo-draggable");
|
|
5
|
-
const
|
|
5
|
+
const component_1 = require("./common/component");
|
|
6
|
+
const core_1 = require("./common/core");
|
|
6
7
|
const throttle = function (func, wait, options = {}) {
|
|
7
8
|
let timeout, context, args, result;
|
|
8
9
|
let previous = 0;
|
|
@@ -40,6 +41,7 @@ const throttle = function (func, wait, options = {}) {
|
|
|
40
41
|
};
|
|
41
42
|
return throttled;
|
|
42
43
|
};
|
|
44
|
+
exports.throttle = throttle;
|
|
43
45
|
const preventDefault = (e) => {
|
|
44
46
|
if (e.preventDefault) {
|
|
45
47
|
e.preventDefault();
|
|
@@ -55,15 +57,16 @@ const matchesElementSelector = (element, selector) => {
|
|
|
55
57
|
return element.closest(selector);
|
|
56
58
|
};
|
|
57
59
|
const FRAMES_PER_SECOND = 1000 / 60;
|
|
58
|
-
const SCROLL =
|
|
60
|
+
const SCROLL = "scroll";
|
|
59
61
|
/**
|
|
60
62
|
* @hidden
|
|
61
63
|
*/
|
|
62
|
-
class Scroller {
|
|
64
|
+
class Scroller extends component_1.Component {
|
|
63
65
|
constructor(element, options) {
|
|
66
|
+
super(element, options);
|
|
64
67
|
this.options = {
|
|
65
68
|
events: {
|
|
66
|
-
[SCROLL]:
|
|
69
|
+
[SCROLL]: core_1.noop,
|
|
67
70
|
},
|
|
68
71
|
filter: '',
|
|
69
72
|
// throttle the scroll events to get a more similar experience
|
|
@@ -73,10 +76,13 @@ class Scroller {
|
|
|
73
76
|
// the drag directions are actually reversed, e.g.
|
|
74
77
|
// dragging to the right actually moves the document to the left
|
|
75
78
|
scrollDirectionModifier: -1,
|
|
76
|
-
scrollThrottleDelay: FRAMES_PER_SECOND
|
|
79
|
+
scrollThrottleDelay: FRAMES_PER_SECOND,
|
|
77
80
|
};
|
|
78
|
-
this.onElementScroll = () => {
|
|
81
|
+
this.onElementScroll = (e) => {
|
|
79
82
|
const element = this.element;
|
|
83
|
+
if (!this.shouldTrackScrollEvents()) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
80
86
|
if (this.state.trackNextElementScroll) {
|
|
81
87
|
this.scrollTo(element.scrollLeft, element.scrollTop);
|
|
82
88
|
}
|
|
@@ -84,21 +90,9 @@ class Scroller {
|
|
|
84
90
|
// reset the state, so that consecutive scroll events can be handled
|
|
85
91
|
this.state.trackNextElementScroll = true;
|
|
86
92
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
throw new Error(e);
|
|
91
|
-
};
|
|
92
|
-
// Render the current and surrounding pages if they have not been rendered already.
|
|
93
|
-
if (page && !pageInfo.rendered && !pageInfo.renderInProgress) {
|
|
94
|
-
(0, utils_1.renderPage)(page, pageInfo.emptyPage, error);
|
|
95
|
-
}
|
|
96
|
-
if (nextPage && !nextPageInfo.rendered && !nextPageInfo.renderInProgress) {
|
|
97
|
-
(0, utils_1.renderPage)(nextPage, nextPageInfo.emptyPage, error);
|
|
98
|
-
}
|
|
99
|
-
if (previousPage && !previousPageInfo.rendered && !previousPageInfo.renderInProgress) {
|
|
100
|
-
(0, utils_1.renderPage)(previousPage, previousPageInfo.emptyPage, error);
|
|
101
|
-
}
|
|
93
|
+
this.trigger(SCROLL, {
|
|
94
|
+
originalEvent: e
|
|
95
|
+
});
|
|
102
96
|
};
|
|
103
97
|
this.onDragStart = (e) => {
|
|
104
98
|
this.state.dragStarted = false;
|
|
@@ -146,8 +140,7 @@ class Scroller {
|
|
|
146
140
|
return;
|
|
147
141
|
}
|
|
148
142
|
};
|
|
149
|
-
this.
|
|
150
|
-
this.options = Object.assign({}, this.options, options);
|
|
143
|
+
this.extendOptions(options);
|
|
151
144
|
this.resetState();
|
|
152
145
|
this.bindEvents();
|
|
153
146
|
}
|
|
@@ -157,7 +150,7 @@ class Scroller {
|
|
|
157
150
|
initDraggable() {
|
|
158
151
|
this.destroyDraggable();
|
|
159
152
|
if (this.options.panScrollThrottleDelay > 0) {
|
|
160
|
-
this.throttledOnDrag = throttle(this.onDrag, this.options.panScrollThrottleDelay);
|
|
153
|
+
this.throttledOnDrag = (0, exports.throttle)(this.onDrag, this.options.panScrollThrottleDelay);
|
|
161
154
|
}
|
|
162
155
|
else {
|
|
163
156
|
this.throttledOnDrag = this.onDrag;
|
|
@@ -188,15 +181,12 @@ class Scroller {
|
|
|
188
181
|
}
|
|
189
182
|
bindElementScroll() {
|
|
190
183
|
if (this.options.scrollThrottleDelay > 0) {
|
|
191
|
-
this.throttledOnElementScroll = throttle(this.onElementScroll, this.options.scrollThrottleDelay);
|
|
184
|
+
this.throttledOnElementScroll = (0, exports.throttle)(this.onElementScroll, this.options.scrollThrottleDelay);
|
|
192
185
|
}
|
|
193
186
|
else {
|
|
194
187
|
this.throttledOnElementScroll = this.onElementScroll;
|
|
195
188
|
}
|
|
196
189
|
this.element.addEventListener(SCROLL, this.throttledOnElementScroll);
|
|
197
|
-
if (this.options.loadOnDemand) {
|
|
198
|
-
this.element.addEventListener(SCROLL, this.onDemandScroll);
|
|
199
|
-
}
|
|
200
190
|
}
|
|
201
191
|
unbindEvents() {
|
|
202
192
|
this.unbindElementScroll();
|
|
@@ -211,9 +201,6 @@ class Scroller {
|
|
|
211
201
|
this.throttledOnElementScroll.cancel();
|
|
212
202
|
this.throttledOnElementScroll = null;
|
|
213
203
|
}
|
|
214
|
-
if (this.options.loadOnDemand) {
|
|
215
|
-
this.element.removeEventListener(SCROLL, this.onDemandScroll);
|
|
216
|
-
}
|
|
217
204
|
this.element.removeEventListener(SCROLL, this.throttledOnElementScroll);
|
|
218
205
|
}
|
|
219
206
|
setState(newState) {
|
|
@@ -222,6 +209,7 @@ class Scroller {
|
|
|
222
209
|
resetState() {
|
|
223
210
|
this.setState({
|
|
224
211
|
trackPanEvents: false,
|
|
212
|
+
trackScrollEvents: false,
|
|
225
213
|
trackNextElementScroll: false,
|
|
226
214
|
location: { pageX: 0, pageY: 0 },
|
|
227
215
|
locationDelta: { x: 0, y: 0 }
|
|
@@ -238,6 +226,18 @@ class Scroller {
|
|
|
238
226
|
shouldTrackPanEvents() {
|
|
239
227
|
return this.state.trackPanEvents;
|
|
240
228
|
}
|
|
229
|
+
enableScrollEventsTracking() {
|
|
230
|
+
this.state.trackScrollEvents = true;
|
|
231
|
+
this.unbindElementScroll();
|
|
232
|
+
this.bindElementScroll();
|
|
233
|
+
}
|
|
234
|
+
disableScrollEventsTracking() {
|
|
235
|
+
this.unbindElementScroll();
|
|
236
|
+
this.state.trackScrollEvents = false;
|
|
237
|
+
}
|
|
238
|
+
shouldTrackScrollEvents() {
|
|
239
|
+
return this.state.trackScrollEvents;
|
|
240
|
+
}
|
|
241
241
|
calculateEventLocationDelta(e) {
|
|
242
242
|
this.state.locationDelta = {
|
|
243
243
|
x: e.pageX - this.state.location.pageX,
|