@vaadin-component-factory/vcf-pdf-viewer 3.1.0 → 4.0.0
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/README.md +2 -1
- package/package.json +56 -52
- package/pdfjs/dist/display_utils.js +609 -714
- package/pdfjs/dist/fetch_stream.js +239 -293
- package/pdfjs/dist/l10n_utils.js +113 -122
- package/pdfjs/dist/message_handler.js +451 -524
- package/pdfjs/dist/network.js +441 -552
- package/pdfjs/dist/network_utils.js +262 -309
- package/pdfjs/dist/node_stream.js +383 -481
- package/pdfjs/dist/pdf.js +9883 -11687
- package/pdfjs/dist/pdf_link_service.js +440 -534
- package/pdfjs/dist/pdf_rendering_queue.js +134 -154
- package/pdfjs/dist/pdf_thumbnail_viewer.js +620 -738
- package/pdfjs/dist/pdf_viewer.js +2667 -3207
- package/pdfjs/dist/ui_utils.js +762 -881
- package/pdfjs/dist/util.js +867 -991
- package/pdfjs/dist/worker.js +51434 -60846
- package/src/vcf-pdf-viewer.js +999 -886
- package/theme/base/vcf-pdf-viewer-styles.js +144 -0
- package/theme/base/vcf-pdf-viewer-toolbar-icons-styles.js +39 -0
- package/theme/base/vcf-pdf-viewer.js +3 -0
- package/vcf-pdf-viewer.js +1 -1
- package/theme/lumo/vcf-pdf-viewer-styles.js +0 -153
- package/theme/lumo/vcf-pdf-viewer-toolbar-icons-styles.js +0 -35
- package/theme/lumo/vcf-pdf-viewer.js +0 -3
- package/theme/material/baseline-keyboard_arrow_down-24px.svg +0 -1
- package/theme/material/baseline-keyboard_arrow_up-24px.svg +0 -1
- package/theme/material/vcf-pdf-viewer-styles.js +0 -123
- package/theme/material/vcf-pdf-viewer.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { parseQueryString } from './ui_utils.js';
|
|
2
|
-
|
|
1
|
+
import { parseQueryString } from './ui_utils.js';
|
|
2
|
+
|
|
3
3
|
/* Copyright 2015 Mozilla Foundation
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -13,7 +13,9 @@ import { parseQueryString } from './ui_utils.js';
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
17
19
|
/**
|
|
18
20
|
* @typedef {Object} PDFLinkServiceOptions
|
|
19
21
|
* @property {EventBus} eventBus - The application event bus.
|
|
@@ -25,614 +27,518 @@ import { parseQueryString } from './ui_utils.js';
|
|
|
25
27
|
* @property {boolean} [ignoreDestinationZoom] - Ignores the zoom argument,
|
|
26
28
|
* thus preserving the current zoom level in the viewer, when navigating
|
|
27
29
|
* to internal destinations. The default value is `false`.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
+
*/
|
|
31
|
+
|
|
30
32
|
/**
|
|
31
33
|
* Performs navigation functions inside PDF, such as opening specified page,
|
|
32
34
|
* or destination.
|
|
33
35
|
* @implements {IPDFLinkService}
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
class PDFLinkService {
|
|
36
|
+
*/
|
|
37
|
+
class PDFLinkService {
|
|
37
38
|
/**
|
|
38
39
|
* @param {PDFLinkServiceOptions} options
|
|
39
|
-
*/
|
|
40
|
-
constructor({
|
|
41
|
-
eventBus,
|
|
42
|
-
externalLinkTarget = null,
|
|
43
|
-
externalLinkRel = null,
|
|
44
|
-
ignoreDestinationZoom = false
|
|
45
|
-
} = {}) {
|
|
46
|
-
this.eventBus = eventBus;
|
|
47
|
-
this.externalLinkTarget = externalLinkTarget;
|
|
48
|
-
this.externalLinkRel = externalLinkRel;
|
|
49
|
-
this.externalLinkEnabled = true;
|
|
50
|
-
this._ignoreDestinationZoom = ignoreDestinationZoom;
|
|
51
|
-
this.baseUrl = null;
|
|
52
|
-
this.pdfDocument = null;
|
|
53
|
-
this.pdfViewer = null;
|
|
54
|
-
this.pdfHistory = null;
|
|
55
|
-
this._pagesRefCache = null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.pdfHistory = pdfHistory;
|
|
70
|
-
}
|
|
40
|
+
*/
|
|
41
|
+
constructor({
|
|
42
|
+
eventBus,
|
|
43
|
+
externalLinkTarget = null,
|
|
44
|
+
externalLinkRel = null,
|
|
45
|
+
ignoreDestinationZoom = false
|
|
46
|
+
} = {}) {
|
|
47
|
+
this.eventBus = eventBus;
|
|
48
|
+
this.externalLinkTarget = externalLinkTarget;
|
|
49
|
+
this.externalLinkRel = externalLinkRel;
|
|
50
|
+
this.externalLinkEnabled = true;
|
|
51
|
+
this._ignoreDestinationZoom = ignoreDestinationZoom;
|
|
52
|
+
this.baseUrl = null;
|
|
53
|
+
this.pdfDocument = null;
|
|
54
|
+
this.pdfViewer = null;
|
|
55
|
+
this.pdfHistory = null;
|
|
56
|
+
this._pagesRefCache = null;
|
|
57
|
+
}
|
|
58
|
+
setDocument(pdfDocument, baseUrl = null) {
|
|
59
|
+
this.baseUrl = baseUrl;
|
|
60
|
+
this.pdfDocument = pdfDocument;
|
|
61
|
+
this._pagesRefCache = Object.create(null);
|
|
62
|
+
}
|
|
63
|
+
setViewer(pdfViewer) {
|
|
64
|
+
this.pdfViewer = pdfViewer;
|
|
65
|
+
}
|
|
66
|
+
setHistory(pdfHistory) {
|
|
67
|
+
this.pdfHistory = pdfHistory;
|
|
68
|
+
}
|
|
69
|
+
|
|
71
70
|
/**
|
|
72
71
|
* @type {number}
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
72
|
+
*/
|
|
73
|
+
get pagesCount() {
|
|
74
|
+
return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
79
77
|
/**
|
|
80
78
|
* @type {number}
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
79
|
+
*/
|
|
80
|
+
get page() {
|
|
81
|
+
return this.pdfViewer.currentPageNumber;
|
|
82
|
+
}
|
|
83
|
+
|
|
87
84
|
/**
|
|
88
85
|
* @param {number} value
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
86
|
+
*/
|
|
87
|
+
set page(value) {
|
|
88
|
+
this.pdfViewer.currentPageNumber = value;
|
|
89
|
+
}
|
|
90
|
+
|
|
95
91
|
/**
|
|
96
92
|
* @type {number}
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
93
|
+
*/
|
|
94
|
+
get rotation() {
|
|
95
|
+
return this.pdfViewer.pagesRotation;
|
|
96
|
+
}
|
|
97
|
+
|
|
103
98
|
/**
|
|
104
99
|
* @param {number} value
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
100
|
+
*/
|
|
101
|
+
set rotation(value) {
|
|
102
|
+
this.pdfViewer.pagesRotation = value;
|
|
103
|
+
}
|
|
104
|
+
|
|
111
105
|
/**
|
|
112
106
|
* @private
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.pdfViewer.scrollPageIntoView({
|
|
160
|
-
pageNumber,
|
|
161
|
-
destArray: explicitDest,
|
|
162
|
-
ignoreDestinationZoom: this._ignoreDestinationZoom
|
|
163
|
-
});
|
|
164
|
-
}
|
|
107
|
+
*/
|
|
108
|
+
_goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
|
|
109
|
+
// Dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
|
|
110
|
+
const destRef = explicitDest[0];
|
|
111
|
+
let pageNumber;
|
|
112
|
+
if (typeof destRef === "object" && destRef !== null) {
|
|
113
|
+
pageNumber = this._cachedPageNumber(destRef);
|
|
114
|
+
if (pageNumber === null) {
|
|
115
|
+
// Fetch the page reference if it's not yet available. This could
|
|
116
|
+
// only occur during loading, before all pages have been resolved.
|
|
117
|
+
this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
|
|
118
|
+
this.cachePageRef(pageIndex + 1, destRef);
|
|
119
|
+
this._goToDestinationHelper(rawDest, namedDest, explicitDest);
|
|
120
|
+
}).catch(() => {
|
|
121
|
+
console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
|
|
122
|
+
});
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
} else if (Number.isInteger(destRef)) {
|
|
126
|
+
pageNumber = destRef + 1;
|
|
127
|
+
} else {
|
|
128
|
+
console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
|
|
132
|
+
console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (this.pdfHistory) {
|
|
136
|
+
// Update the browser history before scrolling the new destination into
|
|
137
|
+
// view, to be able to accurately capture the current document position.
|
|
138
|
+
this.pdfHistory.pushCurrentPosition();
|
|
139
|
+
this.pdfHistory.push({
|
|
140
|
+
namedDest,
|
|
141
|
+
explicitDest,
|
|
142
|
+
pageNumber
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
this.pdfViewer.scrollPageIntoView({
|
|
146
|
+
pageNumber,
|
|
147
|
+
destArray: explicitDest,
|
|
148
|
+
ignoreDestinationZoom: this._ignoreDestinationZoom
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
165
152
|
/**
|
|
166
153
|
* This method will, when available, also update the browser history.
|
|
167
154
|
*
|
|
168
155
|
* @param {string|Array} dest - The named, or explicit, PDF destination.
|
|
169
|
-
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
this._goToDestinationHelper(dest, namedDest, explicitDest);
|
|
193
|
-
}
|
|
156
|
+
*/
|
|
157
|
+
async goToDestination(dest) {
|
|
158
|
+
if (!this.pdfDocument) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
let namedDest, explicitDest;
|
|
162
|
+
if (typeof dest === "string") {
|
|
163
|
+
namedDest = dest;
|
|
164
|
+
explicitDest = await this.pdfDocument.getDestination(dest);
|
|
165
|
+
} else {
|
|
166
|
+
namedDest = null;
|
|
167
|
+
explicitDest = await dest;
|
|
168
|
+
}
|
|
169
|
+
if (!Array.isArray(explicitDest)) {
|
|
170
|
+
console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this._goToDestinationHelper(dest, namedDest, explicitDest);
|
|
174
|
+
}
|
|
175
|
+
|
|
194
176
|
/**
|
|
195
177
|
* This method will, when available, also update the browser history.
|
|
196
178
|
*
|
|
197
179
|
* @param {number|string} val - The page number, or page label.
|
|
198
|
-
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
this.pdfViewer.scrollPageIntoView({
|
|
221
|
-
pageNumber
|
|
222
|
-
});
|
|
223
|
-
}
|
|
180
|
+
*/
|
|
181
|
+
goToPage(val) {
|
|
182
|
+
if (!this.pdfDocument) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
|
|
186
|
+
if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
|
|
187
|
+
console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (this.pdfHistory) {
|
|
191
|
+
// Update the browser history before scrolling the new page into view,
|
|
192
|
+
// to be able to accurately capture the current document position.
|
|
193
|
+
this.pdfHistory.pushCurrentPosition();
|
|
194
|
+
this.pdfHistory.pushPage(pageNumber);
|
|
195
|
+
}
|
|
196
|
+
this.pdfViewer.scrollPageIntoView({
|
|
197
|
+
pageNumber
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
224
201
|
/**
|
|
225
202
|
* @param {string|Array} dest - The PDF destination object.
|
|
226
203
|
* @returns {string} The hyperlink to the PDF object.
|
|
227
|
-
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return this.getAnchorUrl("");
|
|
244
|
-
}
|
|
204
|
+
*/
|
|
205
|
+
getDestinationHash(dest) {
|
|
206
|
+
if (typeof dest === "string") {
|
|
207
|
+
if (dest.length > 0) {
|
|
208
|
+
return this.getAnchorUrl("#" + escape(dest));
|
|
209
|
+
}
|
|
210
|
+
} else if (Array.isArray(dest)) {
|
|
211
|
+
const str = JSON.stringify(dest);
|
|
212
|
+
if (str.length > 0) {
|
|
213
|
+
return this.getAnchorUrl("#" + escape(str));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return this.getAnchorUrl("");
|
|
217
|
+
}
|
|
218
|
+
|
|
245
219
|
/**
|
|
246
220
|
* Prefix the full url on anchor links to make sure that links are resolved
|
|
247
221
|
* relative to the current URL instead of the one defined in <base href>.
|
|
248
222
|
* @param {string} anchor - The anchor hash, including the #.
|
|
249
223
|
* @returns {string} The hyperlink to the PDF object.
|
|
250
|
-
*/
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
224
|
+
*/
|
|
225
|
+
getAnchorUrl(anchor) {
|
|
226
|
+
return (this.baseUrl || "") + anchor;
|
|
227
|
+
}
|
|
228
|
+
|
|
256
229
|
/**
|
|
257
230
|
* @param {string} hash
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (!Array.isArray(dest)) {
|
|
350
|
-
// Avoid incorrectly rejecting a valid named destination, such as
|
|
351
|
-
// e.g. "4.3" or "true", because `JSON.parse` converted its type.
|
|
352
|
-
dest = dest.toString();
|
|
353
|
-
}
|
|
354
|
-
} catch (ex) {}
|
|
355
|
-
|
|
356
|
-
if (typeof dest === "string" || isValidExplicitDestination(dest)) {
|
|
357
|
-
this.goToDestination(dest);
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
|
|
362
|
-
}
|
|
363
|
-
}
|
|
231
|
+
*/
|
|
232
|
+
setHash(hash) {
|
|
233
|
+
if (!this.pdfDocument) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
let pageNumber, dest;
|
|
237
|
+
if (hash.includes("=")) {
|
|
238
|
+
const params = parseQueryString(hash);
|
|
239
|
+
if ("search" in params) {
|
|
240
|
+
this.eventBus.dispatch("findfromurlhash", {
|
|
241
|
+
source: this,
|
|
242
|
+
query: params.search.replace(/"/g, ""),
|
|
243
|
+
phraseSearch: params.phrase === "true"
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
// borrowing syntax from "Parameters for Opening PDF Files"
|
|
247
|
+
if ("page" in params) {
|
|
248
|
+
pageNumber = params.page | 0 || 1;
|
|
249
|
+
}
|
|
250
|
+
if ("zoom" in params) {
|
|
251
|
+
// Build the destination array.
|
|
252
|
+
const zoomArgs = params.zoom.split(","); // scale,left,top
|
|
253
|
+
const zoomArg = zoomArgs[0];
|
|
254
|
+
const zoomArgNumber = parseFloat(zoomArg);
|
|
255
|
+
if (!zoomArg.includes("Fit")) {
|
|
256
|
+
// If the zoomArg is a number, it has to get divided by 100. If it's
|
|
257
|
+
// a string, it should stay as it is.
|
|
258
|
+
dest = [null, {
|
|
259
|
+
name: "XYZ"
|
|
260
|
+
}, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
|
|
261
|
+
} else {
|
|
262
|
+
if (zoomArg === "Fit" || zoomArg === "FitB") {
|
|
263
|
+
dest = [null, {
|
|
264
|
+
name: zoomArg
|
|
265
|
+
}];
|
|
266
|
+
} else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
|
|
267
|
+
dest = [null, {
|
|
268
|
+
name: zoomArg
|
|
269
|
+
}, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
|
|
270
|
+
} else if (zoomArg === "FitR") {
|
|
271
|
+
if (zoomArgs.length !== 5) {
|
|
272
|
+
console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
|
|
273
|
+
} else {
|
|
274
|
+
dest = [null, {
|
|
275
|
+
name: zoomArg
|
|
276
|
+
}, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (dest) {
|
|
284
|
+
this.pdfViewer.scrollPageIntoView({
|
|
285
|
+
pageNumber: pageNumber || this.page,
|
|
286
|
+
destArray: dest,
|
|
287
|
+
allowNegativeOffset: true
|
|
288
|
+
});
|
|
289
|
+
} else if (pageNumber) {
|
|
290
|
+
this.page = pageNumber; // simple page
|
|
291
|
+
}
|
|
292
|
+
if ("pagemode" in params) {
|
|
293
|
+
this.eventBus.dispatch("pagemode", {
|
|
294
|
+
source: this,
|
|
295
|
+
mode: params.pagemode
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// Ensure that this parameter is *always* handled last, in order to
|
|
299
|
+
// guarantee that it won't be overridden (e.g. by the "page" parameter).
|
|
300
|
+
if ("nameddest" in params) {
|
|
301
|
+
this.goToDestination(params.nameddest);
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
// Named (or explicit) destination.
|
|
305
|
+
dest = unescape(hash);
|
|
306
|
+
try {
|
|
307
|
+
dest = JSON.parse(dest);
|
|
308
|
+
if (!Array.isArray(dest)) {
|
|
309
|
+
// Avoid incorrectly rejecting a valid named destination, such as
|
|
310
|
+
// e.g. "4.3" or "true", because `JSON.parse` converted its type.
|
|
311
|
+
dest = dest.toString();
|
|
312
|
+
}
|
|
313
|
+
} catch (ex) {}
|
|
314
|
+
if (typeof dest === "string" || isValidExplicitDestination(dest)) {
|
|
315
|
+
this.goToDestination(dest);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
364
322
|
/**
|
|
365
323
|
* @param {string} action
|
|
366
|
-
*/
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
case "
|
|
387
|
-
this.
|
|
388
|
-
break;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
break;
|
|
401
|
-
// No action according to spec
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
this.eventBus.dispatch("namedaction", {
|
|
405
|
-
source: this,
|
|
406
|
-
action
|
|
407
|
-
});
|
|
408
|
-
}
|
|
324
|
+
*/
|
|
325
|
+
executeNamedAction(action) {
|
|
326
|
+
// See PDF reference, table 8.45 - Named action
|
|
327
|
+
switch (action) {
|
|
328
|
+
case "GoBack":
|
|
329
|
+
if (this.pdfHistory) {
|
|
330
|
+
this.pdfHistory.back();
|
|
331
|
+
}
|
|
332
|
+
break;
|
|
333
|
+
case "GoForward":
|
|
334
|
+
if (this.pdfHistory) {
|
|
335
|
+
this.pdfHistory.forward();
|
|
336
|
+
}
|
|
337
|
+
break;
|
|
338
|
+
case "NextPage":
|
|
339
|
+
this.pdfViewer.nextPage();
|
|
340
|
+
break;
|
|
341
|
+
case "PrevPage":
|
|
342
|
+
this.pdfViewer.previousPage();
|
|
343
|
+
break;
|
|
344
|
+
case "LastPage":
|
|
345
|
+
this.page = this.pagesCount;
|
|
346
|
+
break;
|
|
347
|
+
case "FirstPage":
|
|
348
|
+
this.page = 1;
|
|
349
|
+
break;
|
|
350
|
+
// No action according to spec
|
|
351
|
+
}
|
|
352
|
+
this.eventBus.dispatch("namedaction", {
|
|
353
|
+
source: this,
|
|
354
|
+
action
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
409
358
|
/**
|
|
410
359
|
* @param {number} pageNum - page number.
|
|
411
360
|
* @param {Object} pageRef - reference to the page.
|
|
412
|
-
*/
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
this._pagesRefCache[refStr] = pageNum;
|
|
422
|
-
}
|
|
361
|
+
*/
|
|
362
|
+
cachePageRef(pageNum, pageRef) {
|
|
363
|
+
if (!pageRef) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
|
|
367
|
+
this._pagesRefCache[refStr] = pageNum;
|
|
368
|
+
}
|
|
369
|
+
|
|
423
370
|
/**
|
|
424
371
|
* @private
|
|
425
|
-
*/
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
return ((_this$_pagesRefCache = this._pagesRefCache) === null || _this$_pagesRefCache === void 0 ? void 0 : _this$_pagesRefCache[refStr]) || null;
|
|
433
|
-
}
|
|
372
|
+
*/
|
|
373
|
+
_cachedPageNumber(pageRef) {
|
|
374
|
+
var _this$_pagesRefCache;
|
|
375
|
+
const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
|
|
376
|
+
return ((_this$_pagesRefCache = this._pagesRefCache) === null || _this$_pagesRefCache === void 0 ? void 0 : _this$_pagesRefCache[refStr]) || null;
|
|
377
|
+
}
|
|
378
|
+
|
|
434
379
|
/**
|
|
435
380
|
* @param {number} pageNumber
|
|
436
|
-
*/
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
381
|
+
*/
|
|
382
|
+
isPageVisible(pageNumber) {
|
|
383
|
+
return this.pdfViewer.isPageVisible(pageNumber);
|
|
384
|
+
}
|
|
385
|
+
|
|
442
386
|
/**
|
|
443
387
|
* @param {number} pageNumber
|
|
444
|
-
*/
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if (
|
|
455
|
-
return false;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (destLength !== 6) {
|
|
502
|
-
return false;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
allowNull = false;
|
|
506
|
-
break;
|
|
507
|
-
|
|
508
|
-
default:
|
|
509
|
-
return false;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
for (let i = 2; i < destLength; i++) {
|
|
513
|
-
const param = dest[i];
|
|
514
|
-
|
|
515
|
-
if (!(typeof param === "number" || allowNull && param === null)) {
|
|
516
|
-
return false;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
return true;
|
|
521
|
-
}
|
|
388
|
+
*/
|
|
389
|
+
isPageCached(pageNumber) {
|
|
390
|
+
return this.pdfViewer.isPageCached(pageNumber);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function isValidExplicitDestination(dest) {
|
|
394
|
+
if (!Array.isArray(dest)) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
const destLength = dest.length;
|
|
398
|
+
if (destLength < 2) {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
const page = dest[0];
|
|
402
|
+
if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
const zoom = dest[1];
|
|
406
|
+
if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
let allowNull = true;
|
|
410
|
+
switch (zoom.name) {
|
|
411
|
+
case "XYZ":
|
|
412
|
+
if (destLength !== 5) {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
break;
|
|
416
|
+
case "Fit":
|
|
417
|
+
case "FitB":
|
|
418
|
+
return destLength === 2;
|
|
419
|
+
case "FitH":
|
|
420
|
+
case "FitBH":
|
|
421
|
+
case "FitV":
|
|
422
|
+
case "FitBV":
|
|
423
|
+
if (destLength !== 3) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
break;
|
|
427
|
+
case "FitR":
|
|
428
|
+
if (destLength !== 6) {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
allowNull = false;
|
|
432
|
+
break;
|
|
433
|
+
default:
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
for (let i = 2; i < destLength; i++) {
|
|
437
|
+
const param = dest[i];
|
|
438
|
+
if (!(typeof param === "number" || allowNull && param === null)) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
|
|
522
445
|
/**
|
|
523
446
|
* @implements {IPDFLinkService}
|
|
524
|
-
*/
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
this.
|
|
530
|
-
this.
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
447
|
+
*/
|
|
448
|
+
class SimpleLinkService {
|
|
449
|
+
constructor() {
|
|
450
|
+
this.externalLinkTarget = null;
|
|
451
|
+
this.externalLinkRel = null;
|
|
452
|
+
this.externalLinkEnabled = true;
|
|
453
|
+
this._ignoreDestinationZoom = false;
|
|
454
|
+
}
|
|
455
|
+
|
|
534
456
|
/**
|
|
535
457
|
* @type {number}
|
|
536
|
-
*/
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
458
|
+
*/
|
|
459
|
+
get pagesCount() {
|
|
460
|
+
return 0;
|
|
461
|
+
}
|
|
462
|
+
|
|
542
463
|
/**
|
|
543
464
|
* @type {number}
|
|
544
|
-
*/
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
465
|
+
*/
|
|
466
|
+
get page() {
|
|
467
|
+
return 0;
|
|
468
|
+
}
|
|
469
|
+
|
|
550
470
|
/**
|
|
551
471
|
* @param {number} value
|
|
552
|
-
*/
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
set page(value) {}
|
|
472
|
+
*/
|
|
473
|
+
set page(value) {}
|
|
474
|
+
|
|
556
475
|
/**
|
|
557
476
|
* @type {number}
|
|
558
|
-
*/
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
477
|
+
*/
|
|
478
|
+
get rotation() {
|
|
479
|
+
return 0;
|
|
480
|
+
}
|
|
481
|
+
|
|
564
482
|
/**
|
|
565
483
|
* @param {number} value
|
|
566
|
-
*/
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
set rotation(value) {}
|
|
484
|
+
*/
|
|
485
|
+
set rotation(value) {}
|
|
486
|
+
|
|
570
487
|
/**
|
|
571
488
|
* @param {string|Array} dest - The named, or explicit, PDF destination.
|
|
572
|
-
*/
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
async goToDestination(dest) {}
|
|
489
|
+
*/
|
|
490
|
+
async goToDestination(dest) {}
|
|
491
|
+
|
|
576
492
|
/**
|
|
577
493
|
* @param {number|string} val - The page number, or page label.
|
|
578
|
-
*/
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
goToPage(val) {}
|
|
494
|
+
*/
|
|
495
|
+
goToPage(val) {}
|
|
496
|
+
|
|
582
497
|
/**
|
|
583
498
|
* @param dest - The PDF destination object.
|
|
584
499
|
* @returns {string} The hyperlink to the PDF object.
|
|
585
|
-
*/
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
}
|
|
500
|
+
*/
|
|
501
|
+
getDestinationHash(dest) {
|
|
502
|
+
return "#";
|
|
503
|
+
}
|
|
504
|
+
|
|
591
505
|
/**
|
|
592
506
|
* @param hash - The PDF parameters/hash.
|
|
593
507
|
* @returns {string} The hyperlink to the PDF object.
|
|
594
|
-
*/
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
508
|
+
*/
|
|
509
|
+
getAnchorUrl(hash) {
|
|
510
|
+
return "#";
|
|
511
|
+
}
|
|
512
|
+
|
|
600
513
|
/**
|
|
601
514
|
* @param {string} hash
|
|
602
|
-
*/
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
setHash(hash) {}
|
|
515
|
+
*/
|
|
516
|
+
setHash(hash) {}
|
|
517
|
+
|
|
606
518
|
/**
|
|
607
519
|
* @param {string} action
|
|
608
|
-
*/
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
executeNamedAction(action) {}
|
|
520
|
+
*/
|
|
521
|
+
executeNamedAction(action) {}
|
|
522
|
+
|
|
612
523
|
/**
|
|
613
524
|
* @param {number} pageNum - page number.
|
|
614
525
|
* @param {Object} pageRef - reference to the page.
|
|
615
|
-
*/
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
cachePageRef(pageNum, pageRef) {}
|
|
526
|
+
*/
|
|
527
|
+
cachePageRef(pageNum, pageRef) {}
|
|
528
|
+
|
|
619
529
|
/**
|
|
620
530
|
* @param {number} pageNumber
|
|
621
|
-
*/
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
}
|
|
531
|
+
*/
|
|
532
|
+
isPageVisible(pageNumber) {
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
|
|
627
536
|
/**
|
|
628
537
|
* @param {number} pageNumber
|
|
629
|
-
*/
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
export { PDFLinkService, SimpleLinkService };
|
|
538
|
+
*/
|
|
539
|
+
isPageCached(pageNumber) {
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export { PDFLinkService, SimpleLinkService };
|