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