pdfjs-dist 2.2.228 → 2.6.347
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/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8816 -19300
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +1144 -927
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +289 -233
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +220 -58
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/web/images/texture.png +0 -0
@@ -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 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");
|
30
|
-
|
31
29
|
var _pdf = require("../pdf");
|
32
30
|
|
33
|
-
var _pdf_find_utils = require("./pdf_find_utils");
|
34
|
-
|
35
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
31
|
+
var _pdf_find_utils = require("./pdf_find_utils.js");
|
36
32
|
|
37
|
-
|
33
|
+
var _ui_utils = require("./ui_utils.js");
|
38
34
|
|
39
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
"\
|
61
|
-
"\
|
62
|
-
"\
|
54
|
+
"\u00BC": "1/4",
|
55
|
+
"\u00BD": "1/2",
|
56
|
+
"\u00BE": "3/4"
|
63
57
|
};
|
64
|
-
|
58
|
+
let normalizationRegex = null;
|
65
59
|
|
66
60
|
function normalize(text) {
|
67
61
|
if (!normalizationRegex) {
|
68
|
-
|
69
|
-
normalizationRegex = new RegExp(
|
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,630 @@ function normalize(text) {
|
|
74
68
|
});
|
75
69
|
}
|
76
70
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
77
|
this._eventBus = eventBus;
|
89
78
|
|
90
79
|
this._reset();
|
91
80
|
|
92
|
-
eventBus.
|
81
|
+
eventBus._on("findbarclose", this._onFindBarClose.bind(this));
|
93
82
|
}
|
94
83
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
if (this._pdfDocument) {
|
99
|
-
this._reset();
|
100
|
-
}
|
84
|
+
get highlightMatches() {
|
85
|
+
return this._highlightMatches;
|
86
|
+
}
|
101
87
|
|
102
|
-
|
103
|
-
|
104
|
-
|
88
|
+
get pageMatches() {
|
89
|
+
return this._pageMatches;
|
90
|
+
}
|
91
|
+
|
92
|
+
get pageMatchesLength() {
|
93
|
+
return this._pageMatchesLength;
|
94
|
+
}
|
105
95
|
|
106
|
-
|
96
|
+
get selected() {
|
97
|
+
return this._selected;
|
98
|
+
}
|
99
|
+
|
100
|
+
get state() {
|
101
|
+
return this._state;
|
102
|
+
}
|
107
103
|
|
108
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
109
|
+
if (!pdfDocument) {
|
110
|
+
return;
|
111
|
+
}
|
118
112
|
|
119
|
-
|
113
|
+
this._pdfDocument = pdfDocument;
|
120
114
|
|
121
|
-
|
122
|
-
|
123
|
-
}
|
115
|
+
this._firstPageCapability.resolve();
|
116
|
+
}
|
124
117
|
|
125
|
-
|
118
|
+
executeCommand(cmd, state) {
|
119
|
+
if (!state) {
|
120
|
+
return;
|
121
|
+
}
|
126
122
|
|
127
|
-
|
128
|
-
this._updateUIState(FindState.PENDING);
|
129
|
-
}
|
123
|
+
const pdfDocument = this._pdfDocument;
|
130
124
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
}
|
125
|
+
if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
|
126
|
+
this._dirtyMatch = true;
|
127
|
+
}
|
135
128
|
|
136
|
-
|
129
|
+
this._state = state;
|
137
130
|
|
138
|
-
|
139
|
-
|
131
|
+
if (cmd !== "findhighlightallchange") {
|
132
|
+
this._updateUIState(FindState.PENDING);
|
133
|
+
}
|
140
134
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
135
|
+
this._firstPageCapability.promise.then(() => {
|
136
|
+
if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
|
137
|
+
return;
|
138
|
+
}
|
145
139
|
|
146
|
-
|
147
|
-
_this._findTimeout = setTimeout(function () {
|
148
|
-
_this._nextMatch();
|
140
|
+
this._extractText();
|
149
141
|
|
150
|
-
|
151
|
-
|
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
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
-
|
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
|
-
|
168
|
+
this._highlightMatches = true;
|
170
169
|
}
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
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
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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
|
-
|
240
|
-
|
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
|
-
|
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
|
-
|
246
|
-
|
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
|
-
|
259
|
-
|
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
|
-
|
264
|
-
var prevElem = matchesWithLength[i];
|
250
|
+
return false;
|
265
251
|
|
266
|
-
|
267
|
-
|
268
|
-
|
252
|
+
case "findhighlightallchange":
|
253
|
+
return false;
|
254
|
+
}
|
269
255
|
|
270
|
-
|
271
|
-
|
272
|
-
}
|
256
|
+
return true;
|
257
|
+
}
|
273
258
|
|
274
|
-
|
275
|
-
|
276
|
-
|
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
|
-
|
264
|
+
if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
|
265
|
+
currentElem.skipped = true;
|
266
|
+
return true;
|
281
267
|
}
|
282
268
|
|
283
|
-
|
284
|
-
|
285
|
-
});
|
269
|
+
for (let i = currentIndex - 1; i >= 0; i--) {
|
270
|
+
const prevElem = matchesWithLength[i];
|
286
271
|
|
287
|
-
|
288
|
-
if (isSubTerm(matchesWithLength, i)) {
|
272
|
+
if (prevElem.skipped) {
|
289
273
|
continue;
|
290
274
|
}
|
291
275
|
|
292
|
-
|
293
|
-
|
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 (
|
304
|
-
|
280
|
+
if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
|
281
|
+
currentElem.skipped = true;
|
282
|
+
return true;
|
305
283
|
}
|
306
284
|
}
|
307
285
|
|
308
|
-
|
286
|
+
return false;
|
287
|
+
}
|
309
288
|
|
310
|
-
|
311
|
-
|
289
|
+
matchesWithLength.sort(function (a, b) {
|
290
|
+
return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
|
291
|
+
});
|
312
292
|
|
313
|
-
|
293
|
+
for (let i = 0, len = matchesWithLength.length; i < len; i++) {
|
294
|
+
if (isSubTerm(i)) {
|
295
|
+
continue;
|
296
|
+
}
|
314
297
|
|
315
|
-
|
316
|
-
|
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
|
-
|
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
|
-
|
330
|
-
|
324
|
+
return true;
|
325
|
+
}
|
331
326
|
|
332
|
-
|
333
|
-
|
334
|
-
|
327
|
+
_calculatePhraseMatch(query, pageIndex, pageContent, entireWord) {
|
328
|
+
const matches = [];
|
329
|
+
const queryLen = query.length;
|
330
|
+
let matchIdx = -queryLen;
|
335
331
|
|
336
|
-
|
337
|
-
|
338
|
-
}
|
332
|
+
while (true) {
|
333
|
+
matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
|
339
334
|
|
340
|
-
|
335
|
+
if (matchIdx === -1) {
|
336
|
+
break;
|
341
337
|
}
|
342
338
|
|
343
|
-
this.
|
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
|
-
|
352
|
-
|
353
|
-
var subqueryLen = subquery.length;
|
354
|
-
var matchIdx = -subqueryLen;
|
346
|
+
this._pageMatches[pageIndex] = matches;
|
347
|
+
}
|
355
348
|
|
356
|
-
|
357
|
-
|
349
|
+
_calculateWordMatch(query, pageIndex, pageContent, entireWord) {
|
350
|
+
const matchesWithLength = [];
|
351
|
+
const queryArray = query.match(/\S+/g);
|
358
352
|
|
359
|
-
|
360
|
-
|
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
|
-
|
364
|
-
|
365
|
-
}
|
358
|
+
while (true) {
|
359
|
+
matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
|
366
360
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
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
|
-
|
376
|
-
|
377
|
+
this._pageMatchesLength[pageIndex] = [];
|
378
|
+
this._pageMatches[pageIndex] = [];
|
377
379
|
|
378
|
-
|
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
|
-
|
391
|
-
|
392
|
-
|
396
|
+
if (!caseSensitive) {
|
397
|
+
pageContent = pageContent.toLowerCase();
|
398
|
+
query = query.toLowerCase();
|
399
|
+
}
|
393
400
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
401
|
+
if (phraseSearch) {
|
402
|
+
this._calculatePhraseMatch(query, pageIndex, pageContent, entireWord);
|
403
|
+
} else {
|
404
|
+
this._calculateWordMatch(query, pageIndex, pageContent, entireWord);
|
405
|
+
}
|
398
406
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
this._calculateWordMatch(query, pageIndex, pageContent, entireWord);
|
403
|
-
}
|
407
|
+
if (this._state.highlightAll) {
|
408
|
+
this._updatePage(pageIndex);
|
409
|
+
}
|
404
410
|
|
405
|
-
|
406
|
-
|
407
|
-
}
|
411
|
+
if (this._resumePageIdx === pageIndex) {
|
412
|
+
this._resumePageIdx = null;
|
408
413
|
|
409
|
-
|
410
|
-
|
414
|
+
this._nextPageMatch();
|
415
|
+
}
|
411
416
|
|
412
|
-
|
413
|
-
}
|
417
|
+
const pageMatchesCount = this._pageMatches[pageIndex].length;
|
414
418
|
|
415
|
-
|
419
|
+
if (pageMatchesCount > 0) {
|
420
|
+
this._matchesCountTotal += pageMatchesCount;
|
416
421
|
|
417
|
-
|
418
|
-
|
422
|
+
this._updateUIResultsCount();
|
423
|
+
}
|
424
|
+
}
|
419
425
|
|
420
|
-
|
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
|
-
|
429
|
-
return;
|
430
|
-
}
|
431
|
+
let promise = Promise.resolve();
|
431
432
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
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
|
-
|
461
|
-
|
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
|
-
|
472
|
-
|
473
|
-
|
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
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
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
|
-
|
465
|
+
this._eventBus.dispatch("updatetextlayermatches", {
|
466
|
+
source: this,
|
467
|
+
pageIndex: index
|
468
|
+
});
|
469
|
+
}
|
506
470
|
|
507
|
-
|
508
|
-
|
509
|
-
|
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
|
-
|
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
|
-
|
515
|
-
delete _this3._pendingFindMatches[pageIdx];
|
495
|
+
this._updateAllPages();
|
516
496
|
|
517
|
-
|
518
|
-
|
497
|
+
for (let i = 0; i < numPages; i++) {
|
498
|
+
if (this._pendingFindMatches[i] === true) {
|
499
|
+
continue;
|
519
500
|
}
|
520
|
-
}
|
521
501
|
|
522
|
-
|
523
|
-
this._updateUIState(FindState.FOUND);
|
502
|
+
this._pendingFindMatches[i] = true;
|
524
503
|
|
525
|
-
|
526
|
-
|
504
|
+
this._extractTextPromises[i].then(pageIdx => {
|
505
|
+
delete this._pendingFindMatches[pageIdx];
|
527
506
|
|
528
|
-
|
529
|
-
|
507
|
+
this._calculateMatch(pageIdx);
|
508
|
+
});
|
530
509
|
}
|
510
|
+
}
|
531
511
|
|
532
|
-
|
533
|
-
this.
|
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
|
-
|
515
|
+
return;
|
516
|
+
}
|
542
517
|
|
543
|
-
|
544
|
-
|
518
|
+
if (this._resumePageIdx) {
|
519
|
+
return;
|
520
|
+
}
|
545
521
|
|
546
|
-
|
547
|
-
|
522
|
+
const offset = this._offset;
|
523
|
+
this._pagesToSearch = numPages;
|
548
524
|
|
549
|
-
|
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 (
|
559
|
-
offset.matchIdx = previous ?
|
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
|
533
|
+
return;
|
564
534
|
}
|
565
535
|
|
566
536
|
this._advanceOffsetPage(previous);
|
537
|
+
}
|
567
538
|
|
568
|
-
|
569
|
-
|
539
|
+
this._nextPageMatch();
|
540
|
+
}
|
570
541
|
|
571
|
-
|
572
|
-
|
542
|
+
_matchesReady(matches) {
|
543
|
+
const offset = this._offset;
|
544
|
+
const numMatches = matches.length;
|
545
|
+
const previous = this._state.findPrevious;
|
573
546
|
|
574
|
-
|
575
|
-
|
576
|
-
}
|
547
|
+
if (numMatches) {
|
548
|
+
offset.matchIdx = previous ? numMatches - 1 : 0;
|
577
549
|
|
578
|
-
|
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
|
-
|
552
|
+
return true;
|
553
|
+
}
|
588
554
|
|
589
|
-
|
590
|
-
var pageIdx = this._offset.pageIdx;
|
591
|
-
matches = this._pageMatches[pageIdx];
|
555
|
+
this._advanceOffsetPage(previous);
|
592
556
|
|
593
|
-
|
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 (
|
609
|
-
|
610
|
-
|
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
|
-
|
622
|
-
|
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
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
570
|
+
_nextPageMatch() {
|
571
|
+
if (this._resumePageIdx !== null) {
|
572
|
+
console.error("There can only be one pending page.");
|
573
|
+
}
|
631
574
|
|
632
|
-
|
575
|
+
let matches = null;
|
633
576
|
|
634
|
-
|
635
|
-
|
577
|
+
do {
|
578
|
+
const pageIdx = this._offset.pageIdx;
|
579
|
+
matches = this._pageMatches[pageIdx];
|
636
580
|
|
637
|
-
|
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
|
-
|
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
|
-
|
648
|
-
|
649
|
-
|
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
|
-
|
653
|
-
|
654
|
-
|
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
|
-
|
658
|
-
|
659
|
-
|
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
|
-
|
612
|
+
if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
|
613
|
+
this._updatePage(previousPage);
|
614
|
+
}
|
615
|
+
}
|
663
616
|
|
664
|
-
|
617
|
+
this._updateUIState(state, this._state.findPrevious);
|
665
618
|
|
666
|
-
|
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
|
-
|
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 (
|
687
|
-
|
634
|
+
if (this._findTimeout) {
|
635
|
+
clearTimeout(this._findTimeout);
|
636
|
+
this._findTimeout = null;
|
688
637
|
}
|
689
638
|
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
}
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
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
|
-
|
665
|
+
current += matchIdx + 1;
|
666
|
+
}
|
667
|
+
|
668
|
+
if (current < 1 || current > total) {
|
669
|
+
current = total = 0;
|
747
670
|
}
|
748
|
-
}]);
|
749
671
|
|
750
|
-
|
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
|
+
rawQuery: this._state ? this._state.query : null
|
692
|
+
});
|
693
|
+
}
|
694
|
+
|
695
|
+
}
|
752
696
|
|
753
697
|
exports.PDFFindController = PDFFindController;
|