pdfjs-dist 2.0.943 → 2.4.456
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.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,534 +19,678 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.PDFFindController = exports.FindState =
|
27
|
+
exports.PDFFindController = exports.FindState = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _ui_utils = require("./ui_utils.js");
|
30
30
|
|
31
|
-
var _pdf = require(
|
31
|
+
var _pdf = require("../pdf");
|
32
32
|
|
33
|
-
var _pdf_find_utils = require(
|
33
|
+
var _pdf_find_utils = require("./pdf_find_utils.js");
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
38
|
-
|
39
|
-
var FindState = {
|
35
|
+
const FindState = {
|
40
36
|
FOUND: 0,
|
41
37
|
NOT_FOUND: 1,
|
42
38
|
WRAPPED: 2,
|
43
39
|
PENDING: 3
|
44
40
|
};
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
41
|
+
exports.FindState = FindState;
|
42
|
+
const FIND_TIMEOUT = 250;
|
43
|
+
const MATCH_SCROLL_OFFSET_TOP = -50;
|
44
|
+
const MATCH_SCROLL_OFFSET_LEFT = -400;
|
45
|
+
const CHARACTERS_TO_NORMALIZE = {
|
46
|
+
"\u2018": "'",
|
47
|
+
"\u2019": "'",
|
48
|
+
"\u201A": "'",
|
49
|
+
"\u201B": "'",
|
50
|
+
"\u201C": '"',
|
51
|
+
"\u201D": '"',
|
52
|
+
"\u201E": '"',
|
53
|
+
"\u201F": '"',
|
54
|
+
"\u00BC": "1/4",
|
55
|
+
"\u00BD": "1/2",
|
56
|
+
"\u00BE": "3/4"
|
58
57
|
};
|
58
|
+
let normalizationRegex = null;
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
function normalize(text) {
|
61
|
+
if (!normalizationRegex) {
|
62
|
+
const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
|
63
|
+
normalizationRegex = new RegExp(`[${replace}]`, "g");
|
64
|
+
}
|
65
65
|
|
66
|
-
|
66
|
+
return text.replace(normalizationRegex, function (ch) {
|
67
|
+
return CHARACTERS_TO_NORMALIZE[ch];
|
68
|
+
});
|
69
|
+
}
|
67
70
|
|
71
|
+
class PDFFindController {
|
72
|
+
constructor({
|
73
|
+
linkService,
|
74
|
+
eventBus
|
75
|
+
}) {
|
68
76
|
this._linkService = linkService;
|
69
|
-
this._eventBus = eventBus;
|
77
|
+
this._eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
|
78
|
+
|
70
79
|
this._reset();
|
71
|
-
|
72
|
-
|
73
|
-
this._normalizationRegex = new RegExp('[' + replace + ']', 'g');
|
80
|
+
|
81
|
+
eventBus._on("findbarclose", this._onFindBarClose.bind(this));
|
74
82
|
}
|
75
83
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
84
|
+
get highlightMatches() {
|
85
|
+
return this._highlightMatches;
|
86
|
+
}
|
87
|
+
|
88
|
+
get pageMatches() {
|
89
|
+
return this._pageMatches;
|
90
|
+
}
|
91
|
+
|
92
|
+
get pageMatchesLength() {
|
93
|
+
return this._pageMatchesLength;
|
94
|
+
}
|
95
|
+
|
96
|
+
get selected() {
|
97
|
+
return this._selected;
|
98
|
+
}
|
99
|
+
|
100
|
+
get state() {
|
101
|
+
return this._state;
|
102
|
+
}
|
103
|
+
|
104
|
+
setDocument(pdfDocument) {
|
105
|
+
if (this._pdfDocument) {
|
106
|
+
this._reset();
|
107
|
+
}
|
108
|
+
|
109
|
+
if (!pdfDocument) {
|
110
|
+
return;
|
111
|
+
}
|
112
|
+
|
113
|
+
this._pdfDocument = pdfDocument;
|
114
|
+
|
115
|
+
this._firstPageCapability.resolve();
|
116
|
+
}
|
117
|
+
|
118
|
+
executeCommand(cmd, state) {
|
119
|
+
if (!state) {
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
|
123
|
+
const pdfDocument = this._pdfDocument;
|
124
|
+
|
125
|
+
if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
|
126
|
+
this._dirtyMatch = true;
|
127
|
+
}
|
128
|
+
|
129
|
+
this._state = state;
|
130
|
+
|
131
|
+
if (cmd !== "findhighlightallchange") {
|
132
|
+
this._updateUIState(FindState.PENDING);
|
133
|
+
}
|
134
|
+
|
135
|
+
this._firstPageCapability.promise.then(() => {
|
136
|
+
if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
|
83
137
|
return;
|
84
138
|
}
|
85
|
-
this._pdfDocument = pdfDocument;
|
86
|
-
this._firstPageCapability.resolve();
|
87
|
-
}
|
88
|
-
}, {
|
89
|
-
key: 'executeCommand',
|
90
|
-
value: function executeCommand(cmd, state) {
|
91
|
-
var _this = this;
|
92
139
|
|
93
|
-
|
94
|
-
|
95
|
-
|
140
|
+
this._extractText();
|
141
|
+
|
142
|
+
const findbarClosed = !this._highlightMatches;
|
143
|
+
const pendingTimeout = !!this._findTimeout;
|
144
|
+
|
145
|
+
if (this._findTimeout) {
|
146
|
+
clearTimeout(this._findTimeout);
|
147
|
+
this._findTimeout = null;
|
96
148
|
}
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
149
|
+
|
150
|
+
if (cmd === "find") {
|
151
|
+
this._findTimeout = setTimeout(() => {
|
152
|
+
this._nextMatch();
|
153
|
+
|
154
|
+
this._findTimeout = null;
|
155
|
+
}, FIND_TIMEOUT);
|
156
|
+
} else if (this._dirtyMatch) {
|
157
|
+
this._nextMatch();
|
158
|
+
} else if (cmd === "findagain") {
|
159
|
+
this._nextMatch();
|
160
|
+
|
161
|
+
if (findbarClosed && this._state.highlightAll) {
|
162
|
+
this._updateAllPages();
|
107
163
|
}
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
_this._findTimeout = null;
|
112
|
-
}, FIND_TIMEOUT);
|
164
|
+
} else if (cmd === "findhighlightallchange") {
|
165
|
+
if (pendingTimeout) {
|
166
|
+
this._nextMatch();
|
113
167
|
} else {
|
114
|
-
|
168
|
+
this._highlightMatches = true;
|
115
169
|
}
|
116
|
-
|
170
|
+
|
171
|
+
this._updateAllPages();
|
172
|
+
} else {
|
173
|
+
this._nextMatch();
|
174
|
+
}
|
175
|
+
});
|
176
|
+
}
|
177
|
+
|
178
|
+
scrollMatchIntoView({
|
179
|
+
element = null,
|
180
|
+
pageIndex = -1,
|
181
|
+
matchIndex = -1
|
182
|
+
}) {
|
183
|
+
if (!this._scrollMatches || !element) {
|
184
|
+
return;
|
185
|
+
} else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
|
186
|
+
return;
|
187
|
+
} else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
|
188
|
+
return;
|
117
189
|
}
|
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
|
-
|
190
|
+
|
191
|
+
this._scrollMatches = false;
|
192
|
+
const spot = {
|
193
|
+
top: MATCH_SCROLL_OFFSET_TOP,
|
194
|
+
left: MATCH_SCROLL_OFFSET_LEFT
|
195
|
+
};
|
196
|
+
(0, _ui_utils.scrollIntoView)(element, spot, true);
|
197
|
+
}
|
198
|
+
|
199
|
+
_reset() {
|
200
|
+
this._highlightMatches = false;
|
201
|
+
this._scrollMatches = false;
|
202
|
+
this._pdfDocument = null;
|
203
|
+
this._pageMatches = [];
|
204
|
+
this._pageMatchesLength = [];
|
205
|
+
this._state = null;
|
206
|
+
this._selected = {
|
207
|
+
pageIdx: -1,
|
208
|
+
matchIdx: -1
|
209
|
+
};
|
210
|
+
this._offset = {
|
211
|
+
pageIdx: null,
|
212
|
+
matchIdx: null,
|
213
|
+
wrapped: false
|
214
|
+
};
|
215
|
+
this._extractTextPromises = [];
|
216
|
+
this._pageContents = [];
|
217
|
+
this._matchesCountTotal = 0;
|
218
|
+
this._pagesToSearch = null;
|
219
|
+
this._pendingFindMatches = Object.create(null);
|
220
|
+
this._resumePageIdx = null;
|
221
|
+
this._dirtyMatch = false;
|
222
|
+
clearTimeout(this._findTimeout);
|
223
|
+
this._findTimeout = null;
|
224
|
+
this._firstPageCapability = (0, _pdf.createPromiseCapability)();
|
225
|
+
}
|
226
|
+
|
227
|
+
get _query() {
|
228
|
+
if (this._state.query !== this._rawQuery) {
|
229
|
+
this._rawQuery = this._state.query;
|
230
|
+
this._normalizedQuery = normalize(this._state.query);
|
151
231
|
}
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
232
|
+
|
233
|
+
return this._normalizedQuery;
|
234
|
+
}
|
235
|
+
|
236
|
+
_shouldDirtyMatch(cmd, state) {
|
237
|
+
if (state.query !== this._state.query) {
|
238
|
+
return true;
|
239
|
+
}
|
240
|
+
|
241
|
+
switch (cmd) {
|
242
|
+
case "findagain":
|
243
|
+
const pageNumber = this._selected.pageIdx + 1;
|
244
|
+
const linkService = this._linkService;
|
245
|
+
|
246
|
+
if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
|
160
247
|
return true;
|
161
248
|
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
}
|
167
|
-
if (prevElem.match + prevElem.matchLength < currentElem.match) {
|
168
|
-
break;
|
169
|
-
}
|
170
|
-
if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
|
171
|
-
currentElem.skipped = true;
|
172
|
-
return true;
|
173
|
-
}
|
174
|
-
}
|
249
|
+
|
250
|
+
return false;
|
251
|
+
|
252
|
+
case "findhighlightallchange":
|
175
253
|
return false;
|
254
|
+
}
|
255
|
+
|
256
|
+
return true;
|
257
|
+
}
|
258
|
+
|
259
|
+
_prepareMatches(matchesWithLength, matches, matchesLength) {
|
260
|
+
function isSubTerm(currentIndex) {
|
261
|
+
const currentElem = matchesWithLength[currentIndex];
|
262
|
+
const nextElem = matchesWithLength[currentIndex + 1];
|
263
|
+
|
264
|
+
if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
|
265
|
+
currentElem.skipped = true;
|
266
|
+
return true;
|
176
267
|
}
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
if (
|
268
|
+
|
269
|
+
for (let i = currentIndex - 1; i >= 0; i--) {
|
270
|
+
const prevElem = matchesWithLength[i];
|
271
|
+
|
272
|
+
if (prevElem.skipped) {
|
182
273
|
continue;
|
183
274
|
}
|
184
|
-
|
185
|
-
|
275
|
+
|
276
|
+
if (prevElem.match + prevElem.matchLength < currentElem.match) {
|
277
|
+
break;
|
278
|
+
}
|
279
|
+
|
280
|
+
if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
|
281
|
+
currentElem.skipped = true;
|
282
|
+
return true;
|
283
|
+
}
|
186
284
|
}
|
285
|
+
|
286
|
+
return false;
|
187
287
|
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
}
|
288
|
+
|
289
|
+
matchesWithLength.sort(function (a, b) {
|
290
|
+
return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
|
291
|
+
});
|
292
|
+
|
293
|
+
for (let i = 0, len = matchesWithLength.length; i < len; i++) {
|
294
|
+
if (isSubTerm(i)) {
|
295
|
+
continue;
|
197
296
|
}
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
297
|
+
|
298
|
+
matches.push(matchesWithLength[i].match);
|
299
|
+
matchesLength.push(matchesWithLength[i].matchLength);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
_isEntireWord(content, startIdx, length) {
|
304
|
+
if (startIdx > 0) {
|
305
|
+
const first = content.charCodeAt(startIdx);
|
306
|
+
const limit = content.charCodeAt(startIdx - 1);
|
307
|
+
|
308
|
+
if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
|
309
|
+
return false;
|
205
310
|
}
|
206
|
-
return true;
|
207
311
|
}
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
312
|
+
|
313
|
+
const endIdx = startIdx + length - 1;
|
314
|
+
|
315
|
+
if (endIdx < content.length - 1) {
|
316
|
+
const last = content.charCodeAt(endIdx);
|
317
|
+
const limit = content.charCodeAt(endIdx + 1);
|
318
|
+
|
319
|
+
if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
|
320
|
+
return false;
|
321
|
+
}
|
322
|
+
}
|
323
|
+
|
324
|
+
return true;
|
325
|
+
}
|
326
|
+
|
327
|
+
_calculatePhraseMatch(query, pageIndex, pageContent, entireWord) {
|
328
|
+
const matches = [];
|
329
|
+
const queryLen = query.length;
|
330
|
+
let matchIdx = -queryLen;
|
331
|
+
|
332
|
+
while (true) {
|
333
|
+
matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
|
334
|
+
|
335
|
+
if (matchIdx === -1) {
|
336
|
+
break;
|
337
|
+
}
|
338
|
+
|
339
|
+
if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
|
340
|
+
continue;
|
341
|
+
}
|
342
|
+
|
343
|
+
matches.push(matchIdx);
|
344
|
+
}
|
345
|
+
|
346
|
+
this._pageMatches[pageIndex] = matches;
|
347
|
+
}
|
348
|
+
|
349
|
+
_calculateWordMatch(query, pageIndex, pageContent, entireWord) {
|
350
|
+
const matchesWithLength = [];
|
351
|
+
const queryArray = query.match(/\S+/g);
|
352
|
+
|
353
|
+
for (let i = 0, len = queryArray.length; i < len; i++) {
|
354
|
+
const subquery = queryArray[i];
|
355
|
+
const subqueryLen = subquery.length;
|
356
|
+
let matchIdx = -subqueryLen;
|
357
|
+
|
214
358
|
while (true) {
|
215
|
-
matchIdx = pageContent.indexOf(
|
359
|
+
matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
|
360
|
+
|
216
361
|
if (matchIdx === -1) {
|
217
362
|
break;
|
218
363
|
}
|
219
|
-
|
364
|
+
|
365
|
+
if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
|
220
366
|
continue;
|
221
367
|
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
value: function _calculateWordMatch(query, pageIndex, pageContent, entireWord) {
|
229
|
-
var matchesWithLength = [];
|
230
|
-
var queryArray = query.match(/\S+/g);
|
231
|
-
for (var i = 0, len = queryArray.length; i < len; i++) {
|
232
|
-
var subquery = queryArray[i];
|
233
|
-
var subqueryLen = subquery.length;
|
234
|
-
var matchIdx = -subqueryLen;
|
235
|
-
while (true) {
|
236
|
-
matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
|
237
|
-
if (matchIdx === -1) {
|
238
|
-
break;
|
239
|
-
}
|
240
|
-
if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
|
241
|
-
continue;
|
242
|
-
}
|
243
|
-
matchesWithLength.push({
|
244
|
-
match: matchIdx,
|
245
|
-
matchLength: subqueryLen,
|
246
|
-
skipped: false
|
247
|
-
});
|
248
|
-
}
|
249
|
-
}
|
250
|
-
if (!this._pageMatchesLength) {
|
251
|
-
this._pageMatchesLength = [];
|
252
|
-
}
|
253
|
-
this._pageMatchesLength[pageIndex] = [];
|
254
|
-
this._pageMatches[pageIndex] = [];
|
255
|
-
this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
|
256
|
-
}
|
257
|
-
}, {
|
258
|
-
key: '_calculateMatch',
|
259
|
-
value: function _calculateMatch(pageIndex) {
|
260
|
-
var pageContent = this._normalize(this._pageContents[pageIndex]);
|
261
|
-
var query = this._normalize(this._state.query);
|
262
|
-
var _state = this._state,
|
263
|
-
caseSensitive = _state.caseSensitive,
|
264
|
-
entireWord = _state.entireWord,
|
265
|
-
phraseSearch = _state.phraseSearch;
|
266
|
-
|
267
|
-
if (query.length === 0) {
|
268
|
-
return;
|
269
|
-
}
|
270
|
-
if (!caseSensitive) {
|
271
|
-
pageContent = pageContent.toLowerCase();
|
272
|
-
query = query.toLowerCase();
|
273
|
-
}
|
274
|
-
if (phraseSearch) {
|
275
|
-
this._calculatePhraseMatch(query, pageIndex, pageContent, entireWord);
|
276
|
-
} else {
|
277
|
-
this._calculateWordMatch(query, pageIndex, pageContent, entireWord);
|
368
|
+
|
369
|
+
matchesWithLength.push({
|
370
|
+
match: matchIdx,
|
371
|
+
matchLength: subqueryLen,
|
372
|
+
skipped: false
|
373
|
+
});
|
278
374
|
}
|
375
|
+
}
|
376
|
+
|
377
|
+
this._pageMatchesLength[pageIndex] = [];
|
378
|
+
this._pageMatches[pageIndex] = [];
|
379
|
+
|
380
|
+
this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
|
381
|
+
}
|
382
|
+
|
383
|
+
_calculateMatch(pageIndex) {
|
384
|
+
let pageContent = this._pageContents[pageIndex];
|
385
|
+
let query = this._query;
|
386
|
+
const {
|
387
|
+
caseSensitive,
|
388
|
+
entireWord,
|
389
|
+
phraseSearch
|
390
|
+
} = this._state;
|
391
|
+
|
392
|
+
if (query.length === 0) {
|
393
|
+
return;
|
394
|
+
}
|
395
|
+
|
396
|
+
if (!caseSensitive) {
|
397
|
+
pageContent = pageContent.toLowerCase();
|
398
|
+
query = query.toLowerCase();
|
399
|
+
}
|
400
|
+
|
401
|
+
if (phraseSearch) {
|
402
|
+
this._calculatePhraseMatch(query, pageIndex, pageContent, entireWord);
|
403
|
+
} else {
|
404
|
+
this._calculateWordMatch(query, pageIndex, pageContent, entireWord);
|
405
|
+
}
|
406
|
+
|
407
|
+
if (this._state.highlightAll) {
|
279
408
|
this._updatePage(pageIndex);
|
280
|
-
if (this._resumePageIdx === pageIndex) {
|
281
|
-
this._resumePageIdx = null;
|
282
|
-
this._nextPageMatch();
|
283
|
-
}
|
284
|
-
var pageMatchesCount = this._pageMatches[pageIndex].length;
|
285
|
-
if (pageMatchesCount > 0) {
|
286
|
-
this._matchesCountTotal += pageMatchesCount;
|
287
|
-
this._updateUIResultsCount();
|
288
|
-
}
|
289
409
|
}
|
290
|
-
}, {
|
291
|
-
key: '_extractText',
|
292
|
-
value: function _extractText() {
|
293
|
-
var _this2 = this;
|
294
410
|
|
295
|
-
|
296
|
-
|
297
|
-
}
|
298
|
-
var promise = Promise.resolve();
|
299
|
-
|
300
|
-
var _loop = function _loop(i, ii) {
|
301
|
-
var extractTextCapability = (0, _pdf.createPromiseCapability)();
|
302
|
-
_this2._extractTextPromises[i] = extractTextCapability.promise;
|
303
|
-
promise = promise.then(function () {
|
304
|
-
return _this2._pdfDocument.getPage(i + 1).then(function (pdfPage) {
|
305
|
-
return pdfPage.getTextContent({ normalizeWhitespace: true });
|
306
|
-
}).then(function (textContent) {
|
307
|
-
var textItems = textContent.items;
|
308
|
-
var strBuf = [];
|
309
|
-
for (var j = 0, jj = textItems.length; j < jj; j++) {
|
310
|
-
strBuf.push(textItems[j].str);
|
311
|
-
}
|
312
|
-
_this2._pageContents[i] = strBuf.join('');
|
313
|
-
extractTextCapability.resolve(i);
|
314
|
-
}, function (reason) {
|
315
|
-
console.error('Unable to get text content for page ' + (i + 1), reason);
|
316
|
-
_this2._pageContents[i] = '';
|
317
|
-
extractTextCapability.resolve(i);
|
318
|
-
});
|
319
|
-
});
|
320
|
-
};
|
411
|
+
if (this._resumePageIdx === pageIndex) {
|
412
|
+
this._resumePageIdx = null;
|
321
413
|
|
322
|
-
|
323
|
-
_loop(i, ii);
|
324
|
-
}
|
414
|
+
this._nextPageMatch();
|
325
415
|
}
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
this.
|
333
|
-
source: this,
|
334
|
-
pageIndex: index
|
335
|
-
});
|
416
|
+
|
417
|
+
const pageMatchesCount = this._pageMatches[pageIndex].length;
|
418
|
+
|
419
|
+
if (pageMatchesCount > 0) {
|
420
|
+
this._matchesCountTotal += pageMatchesCount;
|
421
|
+
|
422
|
+
this._updateUIResultsCount();
|
336
423
|
}
|
337
|
-
}
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
this.
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
delete _this3._pendingFindMatches[pageIdx];
|
361
|
-
_this3._calculateMatch(pageIdx);
|
362
|
-
});
|
424
|
+
}
|
425
|
+
|
426
|
+
_extractText() {
|
427
|
+
if (this._extractTextPromises.length > 0) {
|
428
|
+
return;
|
429
|
+
}
|
430
|
+
|
431
|
+
let promise = Promise.resolve();
|
432
|
+
|
433
|
+
for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
|
434
|
+
const extractTextCapability = (0, _pdf.createPromiseCapability)();
|
435
|
+
this._extractTextPromises[i] = extractTextCapability.promise;
|
436
|
+
promise = promise.then(() => {
|
437
|
+
return this._pdfDocument.getPage(i + 1).then(pdfPage => {
|
438
|
+
return pdfPage.getTextContent({
|
439
|
+
normalizeWhitespace: true
|
440
|
+
});
|
441
|
+
}).then(textContent => {
|
442
|
+
const textItems = textContent.items;
|
443
|
+
const strBuf = [];
|
444
|
+
|
445
|
+
for (let j = 0, jj = textItems.length; j < jj; j++) {
|
446
|
+
strBuf.push(textItems[j].str);
|
363
447
|
}
|
448
|
+
|
449
|
+
this._pageContents[i] = normalize(strBuf.join(""));
|
450
|
+
extractTextCapability.resolve(i);
|
451
|
+
}, reason => {
|
452
|
+
console.error(`Unable to get text content for page ${i + 1}`, reason);
|
453
|
+
this._pageContents[i] = "";
|
454
|
+
extractTextCapability.resolve(i);
|
455
|
+
});
|
456
|
+
});
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|
460
|
+
_updatePage(index) {
|
461
|
+
if (this._scrollMatches && this._selected.pageIdx === index) {
|
462
|
+
this._linkService.page = index + 1;
|
463
|
+
}
|
464
|
+
|
465
|
+
this._eventBus.dispatch("updatetextlayermatches", {
|
466
|
+
source: this,
|
467
|
+
pageIndex: index
|
468
|
+
});
|
469
|
+
}
|
470
|
+
|
471
|
+
_updateAllPages() {
|
472
|
+
this._eventBus.dispatch("updatetextlayermatches", {
|
473
|
+
source: this,
|
474
|
+
pageIndex: -1
|
475
|
+
});
|
476
|
+
}
|
477
|
+
|
478
|
+
_nextMatch() {
|
479
|
+
const previous = this._state.findPrevious;
|
480
|
+
const currentPageIndex = this._linkService.page - 1;
|
481
|
+
const numPages = this._linkService.pagesCount;
|
482
|
+
this._highlightMatches = true;
|
483
|
+
|
484
|
+
if (this._dirtyMatch) {
|
485
|
+
this._dirtyMatch = false;
|
486
|
+
this._selected.pageIdx = this._selected.matchIdx = -1;
|
487
|
+
this._offset.pageIdx = currentPageIndex;
|
488
|
+
this._offset.matchIdx = null;
|
489
|
+
this._offset.wrapped = false;
|
490
|
+
this._resumePageIdx = null;
|
491
|
+
this._pageMatches.length = 0;
|
492
|
+
this._pageMatchesLength.length = 0;
|
493
|
+
this._matchesCountTotal = 0;
|
494
|
+
|
495
|
+
this._updateAllPages();
|
496
|
+
|
497
|
+
for (let i = 0; i < numPages; i++) {
|
498
|
+
if (this._pendingFindMatches[i] === true) {
|
499
|
+
continue;
|
364
500
|
}
|
501
|
+
|
502
|
+
this._pendingFindMatches[i] = true;
|
503
|
+
|
504
|
+
this._extractTextPromises[i].then(pageIdx => {
|
505
|
+
delete this._pendingFindMatches[pageIdx];
|
506
|
+
|
507
|
+
this._calculateMatch(pageIdx);
|
508
|
+
});
|
365
509
|
}
|
366
|
-
if (this._state.query === '') {
|
367
|
-
this._updateUIState(FindState.FOUND);
|
368
|
-
return;
|
369
|
-
}
|
370
|
-
if (this._resumePageIdx) {
|
371
|
-
return;
|
372
|
-
}
|
373
|
-
var offset = this._offset;
|
374
|
-
this._pagesToSearch = numPages;
|
375
|
-
if (offset.matchIdx !== null) {
|
376
|
-
var numPageMatches = this._pageMatches[offset.pageIdx].length;
|
377
|
-
if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
|
378
|
-
offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
|
379
|
-
this._updateMatch(true);
|
380
|
-
return;
|
381
|
-
}
|
382
|
-
this._advanceOffsetPage(previous);
|
383
|
-
}
|
384
|
-
this._nextPageMatch();
|
385
510
|
}
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
511
|
+
|
512
|
+
if (this._query === "") {
|
513
|
+
this._updateUIState(FindState.FOUND);
|
514
|
+
|
515
|
+
return;
|
516
|
+
}
|
517
|
+
|
518
|
+
if (this._resumePageIdx) {
|
519
|
+
return;
|
520
|
+
}
|
521
|
+
|
522
|
+
const offset = this._offset;
|
523
|
+
this._pagesToSearch = numPages;
|
524
|
+
|
525
|
+
if (offset.matchIdx !== null) {
|
526
|
+
const numPageMatches = this._pageMatches[offset.pageIdx].length;
|
527
|
+
|
528
|
+
if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
|
529
|
+
offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
|
530
|
+
|
394
531
|
this._updateMatch(true);
|
395
|
-
|
532
|
+
|
533
|
+
return;
|
396
534
|
}
|
535
|
+
|
397
536
|
this._advanceOffsetPage(previous);
|
398
|
-
if (offset.wrapped) {
|
399
|
-
offset.matchIdx = null;
|
400
|
-
if (this._pagesToSearch < 0) {
|
401
|
-
this._updateMatch(false);
|
402
|
-
return true;
|
403
|
-
}
|
404
|
-
}
|
405
|
-
return false;
|
406
537
|
}
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
}
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
var numPages = this._linkService.pagesCount;
|
428
|
-
offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
|
538
|
+
|
539
|
+
this._nextPageMatch();
|
540
|
+
}
|
541
|
+
|
542
|
+
_matchesReady(matches) {
|
543
|
+
const offset = this._offset;
|
544
|
+
const numMatches = matches.length;
|
545
|
+
const previous = this._state.findPrevious;
|
546
|
+
|
547
|
+
if (numMatches) {
|
548
|
+
offset.matchIdx = previous ? numMatches - 1 : 0;
|
549
|
+
|
550
|
+
this._updateMatch(true);
|
551
|
+
|
552
|
+
return true;
|
553
|
+
}
|
554
|
+
|
555
|
+
this._advanceOffsetPage(previous);
|
556
|
+
|
557
|
+
if (offset.wrapped) {
|
429
558
|
offset.matchIdx = null;
|
430
|
-
|
431
|
-
if (
|
432
|
-
|
433
|
-
|
559
|
+
|
560
|
+
if (this._pagesToSearch < 0) {
|
561
|
+
this._updateMatch(false);
|
562
|
+
|
563
|
+
return true;
|
434
564
|
}
|
435
565
|
}
|
436
|
-
}, {
|
437
|
-
key: '_updateMatch',
|
438
|
-
value: function _updateMatch() {
|
439
|
-
var found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
440
566
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
567
|
+
return false;
|
568
|
+
}
|
569
|
+
|
570
|
+
_nextPageMatch() {
|
571
|
+
if (this._resumePageIdx !== null) {
|
572
|
+
console.error("There can only be one pending page.");
|
573
|
+
}
|
574
|
+
|
575
|
+
let matches = null;
|
576
|
+
|
577
|
+
do {
|
578
|
+
const pageIdx = this._offset.pageIdx;
|
579
|
+
matches = this._pageMatches[pageIdx];
|
580
|
+
|
581
|
+
if (!matches) {
|
582
|
+
this._resumePageIdx = pageIdx;
|
583
|
+
break;
|
452
584
|
}
|
453
|
-
|
454
|
-
|
455
|
-
|
585
|
+
} while (!this._matchesReady(matches));
|
586
|
+
}
|
587
|
+
|
588
|
+
_advanceOffsetPage(previous) {
|
589
|
+
const offset = this._offset;
|
590
|
+
const numPages = this._linkService.pagesCount;
|
591
|
+
offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
|
592
|
+
offset.matchIdx = null;
|
593
|
+
this._pagesToSearch--;
|
594
|
+
|
595
|
+
if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
|
596
|
+
offset.pageIdx = previous ? numPages - 1 : 0;
|
597
|
+
offset.wrapped = true;
|
598
|
+
}
|
599
|
+
}
|
600
|
+
|
601
|
+
_updateMatch(found = false) {
|
602
|
+
let state = FindState.NOT_FOUND;
|
603
|
+
const wrapped = this._offset.wrapped;
|
604
|
+
this._offset.wrapped = false;
|
605
|
+
|
606
|
+
if (found) {
|
607
|
+
const previousPage = this._selected.pageIdx;
|
608
|
+
this._selected.pageIdx = this._offset.pageIdx;
|
609
|
+
this._selected.matchIdx = this._offset.matchIdx;
|
610
|
+
state = wrapped ? FindState.WRAPPED : FindState.FOUND;
|
611
|
+
|
612
|
+
if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
|
613
|
+
this._updatePage(previousPage);
|
456
614
|
}
|
457
615
|
}
|
458
|
-
}, {
|
459
|
-
key: '_onFindBarClose',
|
460
|
-
value: function _onFindBarClose(evt) {
|
461
|
-
var _this4 = this;
|
462
616
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
clearTimeout(_this4._findTimeout);
|
470
|
-
_this4._findTimeout = null;
|
471
|
-
_this4._updateUIState(FindState.FOUND);
|
472
|
-
}
|
473
|
-
_this4._highlightMatches = false;
|
474
|
-
_this4._eventBus.dispatch('updatetextlayermatches', {
|
475
|
-
source: _this4,
|
476
|
-
pageIndex: -1
|
477
|
-
});
|
478
|
-
});
|
617
|
+
this._updateUIState(state, this._state.findPrevious);
|
618
|
+
|
619
|
+
if (this._selected.pageIdx !== -1) {
|
620
|
+
this._scrollMatches = true;
|
621
|
+
|
622
|
+
this._updatePage(this._selected.pageIdx);
|
479
623
|
}
|
480
|
-
}
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
total = this._matchesCountTotal;
|
489
|
-
if (matchIdx !== -1) {
|
490
|
-
for (var i = 0; i < pageIdx; i++) {
|
491
|
-
current += this._pageMatches[i] && this._pageMatches[i].length || 0;
|
492
|
-
}
|
493
|
-
current += matchIdx + 1;
|
624
|
+
}
|
625
|
+
|
626
|
+
_onFindBarClose(evt) {
|
627
|
+
const pdfDocument = this._pdfDocument;
|
628
|
+
|
629
|
+
this._firstPageCapability.promise.then(() => {
|
630
|
+
if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
|
631
|
+
return;
|
494
632
|
}
|
495
|
-
|
496
|
-
|
633
|
+
|
634
|
+
if (this._findTimeout) {
|
635
|
+
clearTimeout(this._findTimeout);
|
636
|
+
this._findTimeout = null;
|
497
637
|
}
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
this.
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
}, {
|
527
|
-
key: 'pageMatches',
|
528
|
-
get: function get() {
|
529
|
-
return this._pageMatches;
|
530
|
-
}
|
531
|
-
}, {
|
532
|
-
key: 'pageMatchesLength',
|
533
|
-
get: function get() {
|
534
|
-
return this._pageMatchesLength;
|
535
|
-
}
|
536
|
-
}, {
|
537
|
-
key: 'selected',
|
538
|
-
get: function get() {
|
539
|
-
return this._selected;
|
638
|
+
|
639
|
+
if (this._resumePageIdx) {
|
640
|
+
this._resumePageIdx = null;
|
641
|
+
this._dirtyMatch = true;
|
642
|
+
}
|
643
|
+
|
644
|
+
this._updateUIState(FindState.FOUND);
|
645
|
+
|
646
|
+
this._highlightMatches = false;
|
647
|
+
|
648
|
+
this._updateAllPages();
|
649
|
+
});
|
650
|
+
}
|
651
|
+
|
652
|
+
_requestMatchesCount() {
|
653
|
+
const {
|
654
|
+
pageIdx,
|
655
|
+
matchIdx
|
656
|
+
} = this._selected;
|
657
|
+
let current = 0,
|
658
|
+
total = this._matchesCountTotal;
|
659
|
+
|
660
|
+
if (matchIdx !== -1) {
|
661
|
+
for (let i = 0; i < pageIdx; i++) {
|
662
|
+
current += this._pageMatches[i] && this._pageMatches[i].length || 0;
|
663
|
+
}
|
664
|
+
|
665
|
+
current += matchIdx + 1;
|
540
666
|
}
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
return this._state;
|
667
|
+
|
668
|
+
if (current < 1 || current > total) {
|
669
|
+
current = total = 0;
|
545
670
|
}
|
546
|
-
}]);
|
547
671
|
|
548
|
-
|
549
|
-
|
672
|
+
return {
|
673
|
+
current,
|
674
|
+
total
|
675
|
+
};
|
676
|
+
}
|
677
|
+
|
678
|
+
_updateUIResultsCount() {
|
679
|
+
this._eventBus.dispatch("updatefindmatchescount", {
|
680
|
+
source: this,
|
681
|
+
matchesCount: this._requestMatchesCount()
|
682
|
+
});
|
683
|
+
}
|
684
|
+
|
685
|
+
_updateUIState(state, previous) {
|
686
|
+
this._eventBus.dispatch("updatefindcontrolstate", {
|
687
|
+
source: this,
|
688
|
+
state,
|
689
|
+
previous,
|
690
|
+
matchesCount: this._requestMatchesCount()
|
691
|
+
});
|
692
|
+
}
|
693
|
+
|
694
|
+
}
|
550
695
|
|
551
|
-
exports.FindState = FindState;
|
552
696
|
exports.PDFFindController = PDFFindController;
|