|
@@ -2097,6 +2097,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
});
|
|
|
exports.PDFFindController = exports.FindStates = undefined;
|
|
|
|
|
|
+var _pdfjs = __w_pdfjs_require__(0);
|
|
|
+
|
|
|
var _ui_utils = __w_pdfjs_require__(1);
|
|
|
|
|
|
var FindStates = {
|
|
@@ -2267,38 +2269,39 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
this.updateUIResultsCount();
|
|
|
}
|
|
|
},
|
|
|
- extractText: function PDFFindController_extractText() {
|
|
|
+ extractText: function extractText() {
|
|
|
+ var _this2 = this;
|
|
|
+
|
|
|
if (this.startedTextExtraction) {
|
|
|
return;
|
|
|
}
|
|
|
this.startedTextExtraction = true;
|
|
|
- this.pageContents = [];
|
|
|
- var extractTextPromisesResolves = [];
|
|
|
- var numPages = this.pdfViewer.pagesCount;
|
|
|
- for (var i = 0; i < numPages; i++) {
|
|
|
- this.extractTextPromises.push(new Promise(function (resolve) {
|
|
|
- extractTextPromisesResolves.push(resolve);
|
|
|
- }));
|
|
|
- }
|
|
|
- var self = this;
|
|
|
- function extractPageText(pageIndex) {
|
|
|
- self.pdfViewer.getPageTextContent(pageIndex).then(function textContentResolved(textContent) {
|
|
|
- var textItems = textContent.items;
|
|
|
- var str = [];
|
|
|
- for (var i = 0, len = textItems.length; i < len; i++) {
|
|
|
- str.push(textItems[i].str);
|
|
|
- }
|
|
|
- self.pageContents.push(str.join(''));
|
|
|
- extractTextPromisesResolves[pageIndex](pageIndex);
|
|
|
- if (pageIndex + 1 < self.pdfViewer.pagesCount) {
|
|
|
- extractPageText(pageIndex + 1);
|
|
|
- }
|
|
|
+ this.pageContents.length = 0;
|
|
|
+ var promise = Promise.resolve();
|
|
|
+
|
|
|
+ var _loop = function _loop(i, ii) {
|
|
|
+ var extractTextCapability = (0, _pdfjs.createPromiseCapability)();
|
|
|
+ _this2.extractTextPromises[i] = extractTextCapability.promise;
|
|
|
+ promise = promise.then(function () {
|
|
|
+ return _this2.pdfViewer.getPageTextContent(i).then(function (textContent) {
|
|
|
+ var textItems = textContent.items;
|
|
|
+ var strBuf = [];
|
|
|
+ for (var j = 0, jj = textItems.length; j < jj; j++) {
|
|
|
+ strBuf.push(textItems[j].str);
|
|
|
+ }
|
|
|
+ _this2.pageContents[i] = strBuf.join('');
|
|
|
+ extractTextCapability.resolve(i);
|
|
|
+ });
|
|
|
});
|
|
|
+ };
|
|
|
+
|
|
|
+ for (var i = 0, ii = this.pdfViewer.pagesCount; i < ii; i++) {
|
|
|
+ _loop(i, ii);
|
|
|
}
|
|
|
- extractPageText(0);
|
|
|
},
|
|
|
+
|
|
|
executeCommand: function PDFFindController_executeCommand(cmd, state) {
|
|
|
- var _this2 = this;
|
|
|
+ var _this3 = this;
|
|
|
|
|
|
if (this.state === null || cmd !== 'findagain') {
|
|
|
this.dirtyMatch = true;
|
|
@@ -2306,12 +2309,12 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
this.state = state;
|
|
|
this.updateUIState(FindStates.FIND_PENDING);
|
|
|
this._firstPagePromise.then(function () {
|
|
|
- _this2.extractText();
|
|
|
- clearTimeout(_this2.findTimeout);
|
|
|
+ _this3.extractText();
|
|
|
+ clearTimeout(_this3.findTimeout);
|
|
|
if (cmd === 'find') {
|
|
|
- _this2.findTimeout = setTimeout(_this2.nextMatch.bind(_this2), 250);
|
|
|
+ _this3.findTimeout = setTimeout(_this3.nextMatch.bind(_this3), 250);
|
|
|
} else {
|
|
|
- _this2.nextMatch();
|
|
|
+ _this3.nextMatch();
|
|
|
}
|
|
|
});
|
|
|
},
|
|
@@ -2325,6 +2328,8 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
}
|
|
|
},
|
|
|
nextMatch: function PDFFindController_nextMatch() {
|
|
|
+ var _this4 = this;
|
|
|
+
|
|
|
var previous = this.state.findPrevious;
|
|
|
var currentPageIndex = this.pdfViewer.currentPageNumber - 1;
|
|
|
var numPages = this.pdfViewer.pagesCount;
|
|
@@ -2339,14 +2344,13 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
this.pageMatches = [];
|
|
|
this.matchCount = 0;
|
|
|
this.pageMatchesLength = null;
|
|
|
- var self = this;
|
|
|
for (var i = 0; i < numPages; i++) {
|
|
|
this.updatePage(i);
|
|
|
if (!(i in this.pendingFindMatches)) {
|
|
|
this.pendingFindMatches[i] = true;
|
|
|
this.extractTextPromises[i].then(function (pageIdx) {
|
|
|
- delete self.pendingFindMatches[pageIdx];
|
|
|
- self.calcFindMatch(pageIdx);
|
|
|
+ delete _this4.pendingFindMatches[pageIdx];
|
|
|
+ _this4.calcFindMatch(pageIdx);
|
|
|
});
|
|
|
}
|
|
|
}
|