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.

Files changed (159) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15329 -11095
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +12497 -4184
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/image_decoders/pdf.image_decoders.js +3438 -1209
  9. package/image_decoders/pdf.image_decoders.js.map +1 -1
  10. package/image_decoders/pdf.image_decoders.min.js +1 -1
  11. package/lib/core/annotation.js +335 -109
  12. package/lib/core/arithmetic_decoder.js +274 -244
  13. package/lib/core/bidi.js +64 -5
  14. package/lib/core/ccitt.js +172 -17
  15. package/lib/core/ccitt_stream.js +14 -5
  16. package/lib/core/cff_parser.js +304 -28
  17. package/lib/core/charsets.js +4 -3
  18. package/lib/core/chunked_stream.js +379 -149
  19. package/lib/core/cmap.js +210 -40
  20. package/lib/core/colorspace.js +332 -187
  21. package/lib/core/crypto.js +289 -44
  22. package/lib/core/document.js +508 -249
  23. package/lib/core/encodings.js +18 -9
  24. package/lib/core/evaluator.js +657 -119
  25. package/lib/core/font_renderer.js +217 -34
  26. package/lib/core/fonts.js +632 -41
  27. package/lib/core/function.js +252 -26
  28. package/lib/core/glyphlist.js +2 -1
  29. package/lib/core/image.js +124 -27
  30. package/lib/core/jbig2.js +425 -65
  31. package/lib/core/jbig2_stream.js +18 -7
  32. package/lib/core/jpeg_stream.js +24 -8
  33. package/lib/core/jpg.js +208 -16
  34. package/lib/core/jpx.js +395 -5
  35. package/lib/core/jpx_stream.js +17 -5
  36. package/lib/core/metrics.js +3 -3
  37. package/lib/core/murmurhash3.js +23 -5
  38. package/lib/core/obj.js +625 -132
  39. package/lib/core/operator_list.js +104 -3
  40. package/lib/core/parser.js +262 -25
  41. package/lib/core/pattern.js +144 -12
  42. package/lib/core/pdf_manager.js +104 -70
  43. package/lib/core/primitives.js +74 -21
  44. package/lib/core/ps_parser.js +133 -44
  45. package/lib/core/standard_fonts.js +9 -9
  46. package/lib/core/stream.js +283 -31
  47. package/lib/core/type1_parser.js +138 -6
  48. package/lib/core/unicode.js +28 -1
  49. package/lib/core/worker.js +192 -57
  50. package/lib/display/annotation_layer.js +303 -123
  51. package/lib/display/api.js +1073 -574
  52. package/lib/display/api_compatibility.js +4 -1
  53. package/lib/display/canvas.js +314 -18
  54. package/lib/display/content_disposition.js +70 -23
  55. package/lib/display/dom_utils.js +112 -59
  56. package/lib/display/fetch_stream.js +95 -50
  57. package/lib/display/font_loader.js +250 -132
  58. package/lib/display/metadata.js +37 -15
  59. package/lib/display/network.js +123 -34
  60. package/lib/display/network_utils.js +23 -10
  61. package/lib/display/node_stream.js +162 -65
  62. package/lib/display/pattern_helper.js +57 -6
  63. package/lib/display/svg.js +194 -18
  64. package/lib/display/text_layer.js +128 -14
  65. package/lib/display/transport_stream.js +83 -27
  66. package/lib/display/webgl.js +63 -17
  67. package/lib/display/worker_options.js +4 -3
  68. package/lib/display/xml_parser.js +162 -52
  69. package/lib/examples/node/domstubs.js +56 -3
  70. package/lib/pdf.js +15 -2
  71. package/lib/pdf.worker.js +4 -2
  72. package/lib/shared/compatibility.js +129 -26
  73. package/lib/shared/global_scope.js +1 -1
  74. package/lib/shared/is_node.js +3 -3
  75. package/lib/shared/message_handler.js +103 -45
  76. package/lib/shared/streams_polyfill.js +20 -16
  77. package/lib/shared/url_polyfill.js +8 -2
  78. package/lib/shared/util.js +246 -84
  79. package/lib/test/unit/annotation_spec.js +99 -73
  80. package/lib/test/unit/api_spec.js +347 -113
  81. package/lib/test/unit/bidi_spec.js +6 -6
  82. package/lib/test/unit/cff_parser_spec.js +17 -5
  83. package/lib/test/unit/clitests_helper.js +7 -8
  84. package/lib/test/unit/cmap_spec.js +79 -25
  85. package/lib/test/unit/colorspace_spec.js +65 -18
  86. package/lib/test/unit/crypto_spec.js +16 -4
  87. package/lib/test/unit/custom_spec.js +40 -52
  88. package/lib/test/unit/display_svg_spec.js +32 -16
  89. package/lib/test/unit/document_spec.js +2 -2
  90. package/lib/test/unit/dom_utils_spec.js +8 -8
  91. package/lib/test/unit/encodings_spec.js +24 -44
  92. package/lib/test/unit/evaluator_spec.js +15 -8
  93. package/lib/test/unit/function_spec.js +16 -4
  94. package/lib/test/unit/jasmine-boot.js +29 -16
  95. package/lib/test/unit/message_handler_spec.js +19 -6
  96. package/lib/test/unit/metadata_spec.js +64 -11
  97. package/lib/test/unit/murmurhash3_spec.js +2 -2
  98. package/lib/test/unit/network_spec.js +19 -4
  99. package/lib/test/unit/network_utils_spec.js +6 -4
  100. package/lib/test/unit/node_stream_spec.js +50 -26
  101. package/lib/test/unit/parser_spec.js +13 -29
  102. package/lib/test/unit/pdf_find_controller_spec.js +144 -32
  103. package/lib/test/unit/pdf_find_utils_spec.js +10 -9
  104. package/lib/test/unit/pdf_history_spec.js +20 -8
  105. package/lib/test/unit/primitives_spec.js +23 -3
  106. package/lib/test/unit/stream_spec.js +8 -3
  107. package/lib/test/unit/test_utils.js +89 -26
  108. package/lib/test/unit/testreporter.js +19 -1
  109. package/lib/test/unit/type1_parser_spec.js +7 -5
  110. package/lib/test/unit/ui_utils_spec.js +162 -38
  111. package/lib/test/unit/unicode_spec.js +13 -10
  112. package/lib/test/unit/util_spec.js +89 -9
  113. package/lib/web/annotation_layer_builder.js +38 -21
  114. package/lib/web/app.js +610 -245
  115. package/lib/web/app_options.js +54 -34
  116. package/lib/web/base_viewer.js +359 -162
  117. package/lib/web/chromecom.js +159 -80
  118. package/lib/web/debugger.js +161 -17
  119. package/lib/web/download_manager.js +29 -11
  120. package/lib/web/firefox_print_service.js +16 -8
  121. package/lib/web/firefoxcom.js +127 -91
  122. package/lib/web/genericcom.js +50 -31
  123. package/lib/web/genericl10n.js +46 -34
  124. package/lib/web/grab_to_pan.js +25 -3
  125. package/lib/web/interfaces.js +108 -61
  126. package/lib/web/overlay_manager.js +67 -45
  127. package/lib/web/password_prompt.js +20 -12
  128. package/lib/web/pdf_attachment_viewer.js +37 -17
  129. package/lib/web/pdf_cursor_tools.js +38 -15
  130. package/lib/web/pdf_document_properties.js +65 -24
  131. package/lib/web/pdf_find_bar.js +48 -20
  132. package/lib/web/pdf_find_controller.js +290 -89
  133. package/lib/web/pdf_find_utils.js +19 -3
  134. package/lib/web/pdf_history.js +186 -49
  135. package/lib/web/pdf_link_service.js +127 -52
  136. package/lib/web/pdf_outline_viewer.js +71 -21
  137. package/lib/web/pdf_page_view.js +188 -63
  138. package/lib/web/pdf_presentation_mode.js +98 -33
  139. package/lib/web/pdf_print_service.js +54 -10
  140. package/lib/web/pdf_rendering_queue.js +26 -4
  141. package/lib/web/pdf_sidebar.js +116 -62
  142. package/lib/web/pdf_sidebar_resizer.js +41 -15
  143. package/lib/web/pdf_single_page_viewer.js +65 -68
  144. package/lib/web/pdf_thumbnail_view.js +102 -31
  145. package/lib/web/pdf_thumbnail_viewer.js +62 -22
  146. package/lib/web/pdf_viewer.component.js +111 -31
  147. package/lib/web/pdf_viewer.js +80 -60
  148. package/lib/web/preferences.js +61 -39
  149. package/lib/web/secondary_toolbar.js +101 -82
  150. package/lib/web/text_layer_builder.js +124 -69
  151. package/lib/web/toolbar.js +67 -27
  152. package/lib/web/ui_utils.js +284 -128
  153. package/lib/web/view_history.js +75 -51
  154. package/lib/web/viewer_compatibility.js +2 -1
  155. package/package.json +1 -1
  156. package/web/pdf_viewer.css +1 -1
  157. package/web/pdf_viewer.js +2200 -973
  158. package/web/pdf_viewer.js.map +1 -1
  159. 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
- 'use strict';
22
+ "use strict";
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.PDFFindController = exports.FindState = undefined;
27
+ exports.PDFFindController = exports.FindState = void 0;
28
28
 
29
- var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
29
+ var _ui_utils = require("./ui_utils");
30
30
 
31
- var _pdf = require('../pdf');
31
+ var _pdf = require("../pdf");
32
32
 
33
- var _pdf_find_utils = require('./pdf_find_utils');
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
- '\u2018': '\'',
48
- '\u2019': '\'',
49
- '\u201A': '\'',
50
- '\u201B': '\'',
51
- '\u201C': '"',
52
- '\u201D': '"',
53
- '\u201E': '"',
54
- '\u201F': '"',
55
- '\xBC': '1/4',
56
- '\xBD': '1/2',
57
- '\xBE': '3/4'
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 = function () {
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 === undefined ? (0, _dom_events.getGlobalEventBus)() : _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: 'setDocument',
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: 'executeCommand',
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
- if (this._state === null || cmd !== 'findagain') {
120
+
121
+ if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
95
122
  this._dirtyMatch = true;
96
123
  }
124
+
97
125
  this._state = state;
98
- this._updateUIState(FindState.PENDING);
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: '_reset',
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 = null;
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: '_normalize',
147
- value: function _normalize(text) {
148
- return text.replace(this._normalizationRegex, function (ch) {
149
- return CHARACTERS_TO_NORMALIZE[ch];
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: '_prepareMatches',
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: '_isEntireWord',
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: '_calculatePhraseMatch',
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: '_calculateWordMatch',
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
- if (!this._pageMatchesLength) {
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: '_calculateMatch',
381
+ key: "_calculateMatch",
259
382
  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;
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
- this._updatePage(pageIndex);
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: '_extractText',
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({ normalizeWhitespace: true });
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
- _this2._pageContents[i] = strBuf.join('');
449
+
450
+ _this2._pageContents[i] = normalize(strBuf.join(''));
313
451
  extractTextCapability.resolve(i);
314
452
  }, function (reason) {
315
- console.error('Unable to get text content for page ' + (i + 1), reason);
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: '_updatePage',
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: '_nextMatch',
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 = null;
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._updatePage(i);
357
- if (!(i in this._pendingFindMatches)) {
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
- if (this._state.query === '') {
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: '_matchesReady',
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: '_nextPageMatch',
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: '_advanceOffsetPage',
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: '_updateMatch',
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: '_onFindBarClose',
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
- _this4._eventBus.dispatch('updatetextlayermatches', {
475
- source: _this4,
476
- pageIndex: -1
477
- });
665
+
666
+ _this4._updateAllPages();
478
667
  });
479
668
  }
480
669
  }, {
481
- key: '_requestMatchesCount',
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: '_updateUIResultsCount',
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: '_updateUIState',
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: 'highlightMatches',
714
+ key: "highlightMatches",
523
715
  get: function get() {
524
716
  return this._highlightMatches;
525
717
  }
526
718
  }, {
527
- key: 'pageMatches',
719
+ key: "pageMatches",
528
720
  get: function get() {
529
721
  return this._pageMatches;
530
722
  }
531
723
  }, {
532
- key: 'pageMatchesLength',
724
+ key: "pageMatchesLength",
533
725
  get: function get() {
534
726
  return this._pageMatchesLength;
535
727
  }
536
728
  }, {
537
- key: 'selected',
729
+ key: "selected",
538
730
  get: function get() {
539
731
  return this._selected;
540
732
  }
541
733
  }, {
542
- key: 'state',
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;