pdfjs-dist 2.0.489 → 2.2.228

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