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