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.
- package/CODE_OF_CONDUCT.md +15 -0
- package/bower.json +1 -1
- package/build/pdf.js +18515 -11402
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +48266 -37137
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/external/url/url-lib.js +627 -0
- package/image_decoders/pdf.image_decoders.js +11350 -0
- package/image_decoders/pdf.image_decoders.js.map +1 -0
- package/image_decoders/pdf.image_decoders.min.js +1 -0
- package/lib/core/annotation.js +587 -242
- package/lib/core/arithmetic_decoder.js +275 -245
- package/lib/core/bidi.js +65 -6
- package/lib/core/ccitt.js +173 -18
- package/lib/core/ccitt_stream.js +15 -6
- package/lib/core/cff_parser.js +433 -61
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +400 -152
- package/lib/core/cmap.js +326 -87
- package/lib/core/colorspace.js +874 -594
- package/lib/core/core_utils.js +147 -0
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +560 -268
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +1005 -360
- package/lib/core/font_renderer.js +331 -97
- package/lib/core/fonts.js +812 -195
- package/lib/core/function.js +284 -71
- package/lib/core/glyphlist.js +4 -3
- package/lib/core/image.js +169 -62
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +479 -66
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +253 -29
- package/lib/core/jpx.js +396 -6
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +15 -15
- package/lib/core/murmurhash3.js +56 -34
- package/lib/core/obj.js +1354 -488
- package/lib/core/operator_list.js +144 -31
- package/lib/core/parser.js +539 -191
- package/lib/core/pattern.js +148 -14
- package/lib/core/pdf_manager.js +323 -133
- package/lib/core/primitives.js +111 -24
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +17 -17
- package/lib/core/stream.js +313 -34
- package/lib/core/type1_parser.js +143 -13
- package/lib/core/unicode.js +32 -5
- package/lib/core/worker.js +217 -190
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +450 -133
- package/lib/display/api.js +1597 -784
- package/lib/display/api_compatibility.js +11 -13
- package/lib/display/canvas.js +360 -44
- package/lib/display/content_disposition.js +83 -32
- package/lib/display/display_utils.js +747 -0
- package/lib/display/fetch_stream.js +221 -90
- package/lib/display/font_loader.js +468 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +635 -428
- package/lib/display/network_utils.js +32 -19
- package/lib/display/node_stream.js +367 -175
- package/lib/display/pattern_helper.js +81 -31
- package/lib/display/svg.js +1235 -519
- package/lib/display/text_layer.js +153 -29
- package/lib/display/transport_stream.js +345 -94
- package/lib/display/webgl.js +64 -18
- package/lib/display/worker_options.js +5 -4
- package/lib/display/xml_parser.js +166 -53
- package/lib/examples/node/domstubs.js +60 -4
- package/lib/pdf.js +36 -14
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +158 -564
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +521 -0
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/url_polyfill.js +56 -0
- package/lib/shared/util.js +243 -710
- package/lib/test/unit/annotation_spec.js +870 -401
- package/lib/test/unit/api_spec.js +657 -345
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +54 -11
- package/lib/test/unit/clitests_helper.js +10 -8
- package/lib/test/unit/cmap_spec.js +95 -41
- package/lib/test/unit/colorspace_spec.js +115 -63
- package/lib/test/unit/core_utils_spec.js +191 -0
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +43 -55
- package/lib/test/unit/display_svg_spec.js +34 -18
- package/lib/test/unit/display_utils_spec.js +273 -0
- package/lib/test/unit/document_spec.js +8 -13
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +38 -15
- package/lib/test/unit/fetch_stream_spec.js +109 -0
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +33 -20
- package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
- package/lib/test/unit/metadata_spec.js +71 -11
- package/lib/test/unit/murmurhash3_spec.js +3 -3
- package/lib/test/unit/network_spec.js +19 -54
- package/lib/test/unit/network_utils_spec.js +91 -14
- package/lib/test/unit/node_stream_spec.js +56 -32
- package/lib/test/unit/parser_spec.js +162 -71
- package/lib/test/unit/pdf_find_controller_spec.js +230 -0
- package/lib/test/unit/pdf_find_utils_spec.js +63 -0
- package/lib/test/unit/pdf_history_spec.js +21 -9
- package/lib/test/unit/primitives_spec.js +53 -20
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +273 -56
- package/lib/test/unit/testreporter.js +21 -3
- package/lib/test/unit/type1_parser_spec.js +8 -6
- package/lib/test/unit/ui_utils_spec.js +454 -16
- package/lib/test/unit/unicode_spec.js +18 -15
- package/lib/test/unit/util_spec.js +87 -128
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1290 -588
- package/lib/web/app_options.js +100 -62
- package/lib/web/base_viewer.js +511 -182
- package/lib/web/chromecom.js +261 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +32 -13
- package/lib/web/firefox_print_service.js +20 -10
- package/lib/web/firefoxcom.js +315 -80
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +28 -4
- package/lib/web/interfaces.js +170 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +22 -14
- package/lib/web/pdf_attachment_viewer.js +38 -18
- package/lib/web/pdf_cursor_tools.js +39 -16
- package/lib/web/pdf_document_properties.js +255 -136
- package/lib/web/pdf_find_bar.js +84 -40
- package/lib/web/pdf_find_controller.js +495 -184
- package/lib/web/pdf_find_utils.js +111 -0
- package/lib/web/pdf_history.js +190 -53
- package/lib/web/pdf_link_service.js +138 -77
- package/lib/web/pdf_outline_viewer.js +122 -46
- package/lib/web/pdf_page_view.js +191 -67
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +61 -13
- package/lib/web/pdf_rendering_queue.js +28 -9
- package/lib/web/pdf_sidebar.js +141 -81
- package/lib/web/pdf_sidebar_resizer.js +42 -16
- package/lib/web/pdf_single_page_viewer.js +74 -66
- package/lib/web/pdf_thumbnail_view.js +104 -33
- package/lib/web/pdf_thumbnail_viewer.js +66 -26
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +91 -52
- package/lib/web/preferences.js +284 -89
- package/lib/web/secondary_toolbar.js +165 -40
- package/lib/web/text_layer_builder.js +134 -59
- package/lib/web/toolbar.js +78 -43
- package/lib/web/ui_utils.js +462 -136
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +4 -13
- package/package.json +5 -4
- package/web/pdf_viewer.css +79 -11
- package/web/pdf_viewer.js +6107 -3748
- package/web/pdf_viewer.js.map +1 -1
- package/lib/display/dom_utils.js +0 -309
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/test/unit/fonts_spec.js +0 -81
- 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
|
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
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.PDFFindController = exports.FindState =
|
27
|
+
exports.PDFFindController = exports.FindState = void 0;
|
28
28
|
|
29
|
-
var
|
29
|
+
var _ui_utils = require("./ui_utils");
|
30
30
|
|
31
|
-
var _pdf = require(
|
31
|
+
var _pdf = require("../pdf");
|
32
32
|
|
33
|
-
var
|
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
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
"\u2018": '\'',
|
53
|
+
"\u2019": '\'',
|
54
|
+
"\u201A": '\'',
|
55
|
+
"\u201B": '\'',
|
56
|
+
"\u201C": '"',
|
57
|
+
"\u201D": '"',
|
58
|
+
"\u201E": '"',
|
59
|
+
"\u201F": '"',
|
60
|
+
"\xBC": '1/4',
|
61
|
+
"\xBD": '1/2',
|
62
|
+
"\xBE": '3/4'
|
58
63
|
};
|
64
|
+
var normalizationRegex = null;
|
65
|
+
|
66
|
+
function normalize(text) {
|
67
|
+
if (!normalizationRegex) {
|
68
|
+
var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
|
69
|
+
normalizationRegex = new RegExp("[".concat(replace, "]"), 'g');
|
70
|
+
}
|
71
|
+
|
72
|
+
return text.replace(normalizationRegex, function (ch) {
|
73
|
+
return CHARACTERS_TO_NORMALIZE[ch];
|
74
|
+
});
|
75
|
+
}
|
59
76
|
|
60
|
-
var PDFFindController =
|
77
|
+
var PDFFindController =
|
78
|
+
/*#__PURE__*/
|
79
|
+
function () {
|
61
80
|
function PDFFindController(_ref) {
|
62
|
-
var
|
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.
|
67
|
-
this.
|
68
|
-
|
69
|
-
this.
|
70
|
-
|
71
|
-
|
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:
|
76
|
-
value: function
|
77
|
-
|
96
|
+
key: "setDocument",
|
97
|
+
value: function setDocument(pdfDocument) {
|
98
|
+
if (this._pdfDocument) {
|
99
|
+
this._reset();
|
100
|
+
}
|
78
101
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
this.
|
84
|
-
|
85
|
-
this.
|
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:
|
111
|
+
key: "executeCommand",
|
106
112
|
value: function executeCommand(cmd, state) {
|
107
|
-
var
|
113
|
+
var _this = this;
|
108
114
|
|
109
|
-
if (
|
110
|
-
|
115
|
+
if (!state) {
|
116
|
+
return;
|
111
117
|
}
|
112
|
-
|
113
|
-
this.
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
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
|
-
|
169
|
+
_this._nextMatch();
|
121
170
|
}
|
122
171
|
});
|
123
172
|
}
|
124
173
|
}, {
|
125
|
-
key:
|
126
|
-
value: function
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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:
|
137
|
-
value: function
|
138
|
-
|
139
|
-
|
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:
|
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:
|
180
|
-
value: function
|
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
|
-
|
342
|
+
|
343
|
+
this._pageMatches[pageIndex] = matches;
|
192
344
|
}
|
193
345
|
}, {
|
194
|
-
key:
|
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
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
this.
|
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:
|
381
|
+
key: "_calculateMatch",
|
223
382
|
value: function _calculateMatch(pageIndex) {
|
224
|
-
var pageContent = this.
|
225
|
-
var query = this.
|
226
|
-
var
|
227
|
-
|
228
|
-
|
229
|
-
|
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
|
-
|
242
|
-
if (this.
|
243
|
-
this.
|
408
|
+
|
409
|
+
if (this._resumePageIdx === pageIndex) {
|
410
|
+
this._resumePageIdx = null;
|
411
|
+
|
244
412
|
this._nextPageMatch();
|
245
413
|
}
|
246
|
-
|
247
|
-
|
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:
|
424
|
+
key: "_extractText",
|
253
425
|
value: function _extractText() {
|
254
|
-
var
|
426
|
+
var _this2 = this;
|
255
427
|
|
256
|
-
if (this.
|
428
|
+
if (this._extractTextPromises.length > 0) {
|
257
429
|
return;
|
258
430
|
}
|
259
|
-
|
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
|
-
|
436
|
+
_this2._extractTextPromises[i] = extractTextCapability.promise;
|
266
437
|
promise = promise.then(function () {
|
267
|
-
return
|
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
|
-
|
449
|
+
|
450
|
+
_this2._pageContents[i] = normalize(strBuf.join(''));
|
274
451
|
extractTextCapability.resolve(i);
|
275
452
|
}, function (reason) {
|
276
|
-
console.error(
|
277
|
-
|
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.
|
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:
|
465
|
+
key: "_updatePage",
|
289
466
|
value: function _updatePage(index) {
|
290
|
-
if (this.
|
291
|
-
this.
|
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:
|
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
|
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.
|
319
|
-
|
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
|
-
|
521
|
+
|
522
|
+
if (this._query === '') {
|
329
523
|
this._updateUIState(FindState.FOUND);
|
524
|
+
|
330
525
|
return;
|
331
526
|
}
|
332
|
-
|
527
|
+
|
528
|
+
if (this._resumePageIdx) {
|
333
529
|
return;
|
334
530
|
}
|
335
|
-
|
336
|
-
|
531
|
+
|
532
|
+
var offset = this._offset;
|
533
|
+
this._pagesToSearch = numPages;
|
534
|
+
|
337
535
|
if (offset.matchIdx !== null) {
|
338
|
-
var numPageMatches = this.
|
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:
|
552
|
+
key: "_matchesReady",
|
351
553
|
value: function _matchesReady(matches) {
|
352
|
-
var offset = this.
|
554
|
+
var offset = this._offset;
|
353
555
|
var numMatches = matches.length;
|
354
|
-
var previous = this.
|
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
|
-
|
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:
|
581
|
+
key: "_nextPageMatch",
|
373
582
|
value: function _nextPageMatch() {
|
374
|
-
if (this.
|
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.
|
380
|
-
matches = this.
|
590
|
+
var pageIdx = this._offset.pageIdx;
|
591
|
+
matches = this._pageMatches[pageIdx];
|
592
|
+
|
381
593
|
if (!matches) {
|
382
|
-
this.
|
594
|
+
this._resumePageIdx = pageIdx;
|
383
595
|
break;
|
384
596
|
}
|
385
597
|
} while (!this._matchesReady(matches));
|
386
598
|
}
|
387
599
|
}, {
|
388
|
-
key:
|
600
|
+
key: "_advanceOffsetPage",
|
389
601
|
value: function _advanceOffsetPage(previous) {
|
390
|
-
var offset = this.
|
391
|
-
var numPages = this.
|
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.
|
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:
|
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.
|
407
|
-
this.
|
618
|
+
var wrapped = this._offset.wrapped;
|
619
|
+
this._offset.wrapped = false;
|
620
|
+
|
408
621
|
if (found) {
|
409
|
-
var previousPage = this.
|
410
|
-
this.
|
411
|
-
this.
|
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
|
-
|
626
|
+
|
627
|
+
if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
|
414
628
|
this._updatePage(previousPage);
|
415
629
|
}
|
416
630
|
}
|
417
|
-
|
418
|
-
|
419
|
-
|
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:
|
424
|
-
value: function
|
425
|
-
|
426
|
-
|
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:
|
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
|
-
|
433
|
-
this
|
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;
|