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.

Files changed (192) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8286 -14230
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +57878 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. 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 2018 Mozilla Foundation
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
- '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.js");
30
30
 
31
- var _pdf = require('../pdf');
31
+ var _pdf = require("../pdf");
32
32
 
33
- var _pdf_find_utils = require('./pdf_find_utils');
33
+ var _pdf_find_utils = require("./pdf_find_utils.js");
34
34
 
35
- var _dom_events = require('./dom_events');
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
- var FIND_TIMEOUT = 250;
46
- 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'
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
- var PDFFindController = function () {
61
- function PDFFindController(_ref) {
62
- var linkService = _ref.linkService,
63
- _ref$eventBus = _ref.eventBus,
64
- eventBus = _ref$eventBus === undefined ? (0, _dom_events.getGlobalEventBus)() : _ref$eventBus;
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
- _classCallCheck(this, PDFFindController);
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
- eventBus.on('findbarclose', this._onFindBarClose.bind(this));
72
- var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
73
- this._normalizationRegex = new RegExp('[' + replace + ']', 'g');
80
+
81
+ eventBus._on("findbarclose", this._onFindBarClose.bind(this));
74
82
  }
75
83
 
76
- _createClass(PDFFindController, [{
77
- key: 'setDocument',
78
- value: function setDocument(pdfDocument) {
79
- if (this._pdfDocument) {
80
- this._reset();
81
- }
82
- if (!pdfDocument) {
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
- var pdfDocument = this._pdfDocument;
94
- if (this._state === null || cmd !== 'findagain') {
95
- this._dirtyMatch = true;
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
- this._state = state;
98
- this._updateUIState(FindState.PENDING);
99
- this._firstPageCapability.promise.then(function () {
100
- if (!_this._pdfDocument || pdfDocument && _this._pdfDocument !== pdfDocument) {
101
- return;
102
- }
103
- _this._extractText();
104
- if (_this._findTimeout) {
105
- clearTimeout(_this._findTimeout);
106
- _this._findTimeout = null;
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
- if (cmd === 'find') {
109
- _this._findTimeout = setTimeout(function () {
110
- _this._nextMatch();
111
- _this._findTimeout = null;
112
- }, FIND_TIMEOUT);
164
+ } else if (cmd === "findhighlightallchange") {
165
+ if (pendingTimeout) {
166
+ this._nextMatch();
113
167
  } else {
114
- _this._nextMatch();
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
- key: '_reset',
120
- value: function _reset() {
121
- this._highlightMatches = false;
122
- this._pdfDocument = null;
123
- this._pageMatches = [];
124
- this._pageMatchesLength = null;
125
- this._state = null;
126
- this._selected = {
127
- pageIdx: -1,
128
- matchIdx: -1
129
- };
130
- this._offset = {
131
- pageIdx: null,
132
- matchIdx: null
133
- };
134
- this._extractTextPromises = [];
135
- this._pageContents = [];
136
- this._matchesCountTotal = 0;
137
- this._pagesToSearch = null;
138
- this._pendingFindMatches = Object.create(null);
139
- this._resumePageIdx = null;
140
- this._dirtyMatch = false;
141
- clearTimeout(this._findTimeout);
142
- this._findTimeout = null;
143
- this._firstPageCapability = (0, _pdf.createPromiseCapability)();
144
- }
145
- }, {
146
- key: '_normalize',
147
- value: function _normalize(text) {
148
- return text.replace(this._normalizationRegex, function (ch) {
149
- return CHARACTERS_TO_NORMALIZE[ch];
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
- key: '_prepareMatches',
154
- value: function _prepareMatches(matchesWithLength, matches, matchesLength) {
155
- function isSubTerm(matchesWithLength, currentIndex) {
156
- var currentElem = matchesWithLength[currentIndex];
157
- var nextElem = matchesWithLength[currentIndex + 1];
158
- if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
159
- currentElem.skipped = true;
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
- for (var i = currentIndex - 1; i >= 0; i--) {
163
- var prevElem = matchesWithLength[i];
164
- if (prevElem.skipped) {
165
- continue;
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
- matchesWithLength.sort(function (a, b) {
178
- return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
179
- });
180
- for (var i = 0, len = matchesWithLength.length; i < len; i++) {
181
- if (isSubTerm(matchesWithLength, i)) {
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
- matches.push(matchesWithLength[i].match);
185
- matchesLength.push(matchesWithLength[i].matchLength);
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
- key: '_isEntireWord',
190
- value: function _isEntireWord(content, startIdx, length) {
191
- if (startIdx > 0) {
192
- var first = content.charCodeAt(startIdx);
193
- var limit = content.charCodeAt(startIdx - 1);
194
- if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
195
- return false;
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
- var endIdx = startIdx + length - 1;
199
- if (endIdx < content.length - 1) {
200
- var last = content.charCodeAt(endIdx);
201
- var _limit = content.charCodeAt(endIdx + 1);
202
- if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(_limit)) {
203
- return false;
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
- key: '_calculatePhraseMatch',
210
- value: function _calculatePhraseMatch(query, pageIndex, pageContent, entireWord) {
211
- var matches = [];
212
- var queryLen = query.length;
213
- var matchIdx = -queryLen;
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(query, matchIdx + queryLen);
359
+ matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
360
+
216
361
  if (matchIdx === -1) {
217
362
  break;
218
363
  }
219
- if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
364
+
365
+ if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
220
366
  continue;
221
367
  }
222
- matches.push(matchIdx);
223
- }
224
- this._pageMatches[pageIndex] = matches;
225
- }
226
- }, {
227
- key: '_calculateWordMatch',
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
- if (this._extractTextPromises.length > 0) {
296
- return;
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
- for (var i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
323
- _loop(i, ii);
324
- }
414
+ this._nextPageMatch();
325
415
  }
326
- }, {
327
- key: '_updatePage',
328
- value: function _updatePage(index) {
329
- if (this._selected.pageIdx === index) {
330
- this._linkService.page = index + 1;
331
- }
332
- this._eventBus.dispatch('updatetextlayermatches', {
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
- key: '_nextMatch',
339
- value: function _nextMatch() {
340
- var _this3 = this;
341
-
342
- var previous = this._state.findPrevious;
343
- var currentPageIndex = this._linkService.page - 1;
344
- var numPages = this._linkService.pagesCount;
345
- this._highlightMatches = true;
346
- if (this._dirtyMatch) {
347
- this._dirtyMatch = false;
348
- this._selected.pageIdx = this._selected.matchIdx = -1;
349
- this._offset.pageIdx = currentPageIndex;
350
- this._offset.matchIdx = null;
351
- this._resumePageIdx = null;
352
- this._pageMatches.length = 0;
353
- this._pageMatchesLength = null;
354
- this._matchesCountTotal = 0;
355
- 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
- });
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
- key: '_matchesReady',
388
- value: function _matchesReady(matches) {
389
- var offset = this._offset;
390
- var numMatches = matches.length;
391
- var previous = this._state.findPrevious;
392
- if (numMatches) {
393
- offset.matchIdx = previous ? numMatches - 1 : 0;
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
- return true;
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
- key: '_nextPageMatch',
409
- value: function _nextPageMatch() {
410
- if (this._resumePageIdx !== null) {
411
- console.error('There can only be one pending page.');
412
- }
413
- var matches = null;
414
- do {
415
- var pageIdx = this._offset.pageIdx;
416
- matches = this._pageMatches[pageIdx];
417
- if (!matches) {
418
- this._resumePageIdx = pageIdx;
419
- break;
420
- }
421
- } while (!this._matchesReady(matches));
422
- }
423
- }, {
424
- key: '_advanceOffsetPage',
425
- value: function _advanceOffsetPage(previous) {
426
- var offset = this._offset;
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
- this._pagesToSearch--;
431
- if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
432
- offset.pageIdx = previous ? numPages - 1 : 0;
433
- offset.wrapped = true;
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
- var state = FindState.NOT_FOUND;
442
- var wrapped = this._offset.wrapped;
443
- this._offset.wrapped = false;
444
- if (found) {
445
- var previousPage = this._selected.pageIdx;
446
- this._selected.pageIdx = this._offset.pageIdx;
447
- this._selected.matchIdx = this._offset.matchIdx;
448
- state = wrapped ? FindState.WRAPPED : FindState.FOUND;
449
- if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
450
- this._updatePage(previousPage);
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
- this._updateUIState(state, this._state.findPrevious);
454
- if (this._selected.pageIdx !== -1) {
455
- this._updatePage(this._selected.pageIdx);
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
- var pdfDocument = this._pdfDocument;
464
- this._firstPageCapability.promise.then(function () {
465
- if (!_this4._pdfDocument || pdfDocument && _this4._pdfDocument !== pdfDocument) {
466
- return;
467
- }
468
- if (_this4._findTimeout) {
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
- key: '_requestMatchesCount',
482
- value: function _requestMatchesCount() {
483
- var _selected = this._selected,
484
- pageIdx = _selected.pageIdx,
485
- matchIdx = _selected.matchIdx;
486
-
487
- var current = 0,
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
- if (current < 1 || current > total) {
496
- current = total = 0;
633
+
634
+ if (this._findTimeout) {
635
+ clearTimeout(this._findTimeout);
636
+ this._findTimeout = null;
497
637
  }
498
- return {
499
- current: current,
500
- total: total
501
- };
502
- }
503
- }, {
504
- key: '_updateUIResultsCount',
505
- value: function _updateUIResultsCount() {
506
- this._eventBus.dispatch('updatefindmatchescount', {
507
- source: this,
508
- matchesCount: this._requestMatchesCount()
509
- });
510
- }
511
- }, {
512
- key: '_updateUIState',
513
- value: function _updateUIState(state, previous) {
514
- this._eventBus.dispatch('updatefindcontrolstate', {
515
- source: this,
516
- state: state,
517
- previous: previous,
518
- matchesCount: this._requestMatchesCount()
519
- });
520
- }
521
- }, {
522
- key: 'highlightMatches',
523
- get: function get() {
524
- return this._highlightMatches;
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
- key: 'state',
543
- get: function get() {
544
- return this._state;
667
+
668
+ if (current < 1 || current > total) {
669
+ current = total = 0;
545
670
  }
546
- }]);
547
671
 
548
- return PDFFindController;
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;