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