|
|
@ -4139,8 +4139,39 @@ var PDFFindController = function () { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'normalize', |
|
|
|
key: 'executeCommand', |
|
|
|
value: function normalize(text) { |
|
|
|
value: function executeCommand(cmd, state) { |
|
|
|
|
|
|
|
var _this2 = this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.state === null || cmd !== 'findagain') { |
|
|
|
|
|
|
|
this.dirtyMatch = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.state = state; |
|
|
|
|
|
|
|
this._updateUIState(FindState.PENDING); |
|
|
|
|
|
|
|
this._firstPagePromise.then(function () { |
|
|
|
|
|
|
|
_this2._extractText(); |
|
|
|
|
|
|
|
clearTimeout(_this2.findTimeout); |
|
|
|
|
|
|
|
if (cmd === 'find') { |
|
|
|
|
|
|
|
_this2.findTimeout = setTimeout(_this2._nextMatch.bind(_this2), FIND_TIMEOUT); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_this2._nextMatch(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'updateMatchPosition', |
|
|
|
|
|
|
|
value: function updateMatchPosition(pageIndex, matchIndex, elements, beginIdx) { |
|
|
|
|
|
|
|
if (this.selected.matchIdx === matchIndex && this.selected.pageIdx === pageIndex) { |
|
|
|
|
|
|
|
var spot = { |
|
|
|
|
|
|
|
top: FIND_SCROLL_OFFSET_TOP, |
|
|
|
|
|
|
|
left: FIND_SCROLL_OFFSET_LEFT |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
(0, _ui_utils.scrollIntoView)(elements[beginIdx], spot, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
key: '_normalize', |
|
|
|
|
|
|
|
value: function _normalize(text) { |
|
|
|
return text.replace(this.normalizationRegex, function (ch) { |
|
|
|
return text.replace(this.normalizationRegex, function (ch) { |
|
|
|
return CHARACTERS_TO_NORMALIZE[ch]; |
|
|
|
return CHARACTERS_TO_NORMALIZE[ch]; |
|
|
|
}); |
|
|
|
}); |
|
|
@ -4182,8 +4213,8 @@ var PDFFindController = function () { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'calcFindPhraseMatch', |
|
|
|
key: '_calculatePhraseMatch', |
|
|
|
value: function calcFindPhraseMatch(query, pageIndex, pageContent) { |
|
|
|
value: function _calculatePhraseMatch(query, pageIndex, pageContent) { |
|
|
|
var matches = []; |
|
|
|
var matches = []; |
|
|
|
var queryLen = query.length; |
|
|
|
var queryLen = query.length; |
|
|
|
var matchIdx = -queryLen; |
|
|
|
var matchIdx = -queryLen; |
|
|
@ -4197,8 +4228,8 @@ var PDFFindController = function () { |
|
|
|
this.pageMatches[pageIndex] = matches; |
|
|
|
this.pageMatches[pageIndex] = matches; |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'calcFindWordMatch', |
|
|
|
key: '_calculateWordMatch', |
|
|
|
value: function calcFindWordMatch(query, pageIndex, pageContent) { |
|
|
|
value: function _calculateWordMatch(query, pageIndex, pageContent) { |
|
|
|
var matchesWithLength = []; |
|
|
|
var matchesWithLength = []; |
|
|
|
var queryArray = query.match(/\S+/g); |
|
|
|
var queryArray = query.match(/\S+/g); |
|
|
|
for (var i = 0, len = queryArray.length; i < len; i++) { |
|
|
|
for (var i = 0, len = queryArray.length; i < len; i++) { |
|
|
@ -4225,10 +4256,10 @@ var PDFFindController = function () { |
|
|
|
this._prepareMatches(matchesWithLength, this.pageMatches[pageIndex], this.pageMatchesLength[pageIndex]); |
|
|
|
this._prepareMatches(matchesWithLength, this.pageMatches[pageIndex], this.pageMatchesLength[pageIndex]); |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'calcFindMatch', |
|
|
|
key: '_calculateMatch', |
|
|
|
value: function calcFindMatch(pageIndex) { |
|
|
|
value: function _calculateMatch(pageIndex) { |
|
|
|
var pageContent = this.normalize(this.pageContents[pageIndex]); |
|
|
|
var pageContent = this._normalize(this.pageContents[pageIndex]); |
|
|
|
var query = this.normalize(this.state.query); |
|
|
|
var query = this._normalize(this.state.query); |
|
|
|
var caseSensitive = this.state.caseSensitive; |
|
|
|
var caseSensitive = this.state.caseSensitive; |
|
|
|
var phraseSearch = this.state.phraseSearch; |
|
|
|
var phraseSearch = this.state.phraseSearch; |
|
|
|
var queryLen = query.length; |
|
|
|
var queryLen = query.length; |
|
|
@ -4240,24 +4271,24 @@ var PDFFindController = function () { |
|
|
|
query = query.toLowerCase(); |
|
|
|
query = query.toLowerCase(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (phraseSearch) { |
|
|
|
if (phraseSearch) { |
|
|
|
this.calcFindPhraseMatch(query, pageIndex, pageContent); |
|
|
|
this._calculatePhraseMatch(query, pageIndex, pageContent); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.calcFindWordMatch(query, pageIndex, pageContent); |
|
|
|
this._calculateWordMatch(query, pageIndex, pageContent); |
|
|
|
} |
|
|
|
} |
|
|
|
this.updatePage(pageIndex); |
|
|
|
this._updatePage(pageIndex); |
|
|
|
if (this.resumePageIdx === pageIndex) { |
|
|
|
if (this.resumePageIdx === pageIndex) { |
|
|
|
this.resumePageIdx = null; |
|
|
|
this.resumePageIdx = null; |
|
|
|
this.nextPageMatch(); |
|
|
|
this._nextPageMatch(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.pageMatches[pageIndex].length > 0) { |
|
|
|
if (this.pageMatches[pageIndex].length > 0) { |
|
|
|
this.matchCount += this.pageMatches[pageIndex].length; |
|
|
|
this.matchCount += this.pageMatches[pageIndex].length; |
|
|
|
this.updateUIResultsCount(); |
|
|
|
this._updateUIResultsCount(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'extractText', |
|
|
|
key: '_extractText', |
|
|
|
value: function extractText() { |
|
|
|
value: function _extractText() { |
|
|
|
var _this2 = this; |
|
|
|
var _this3 = this; |
|
|
|
|
|
|
|
|
|
|
|
if (this.startedTextExtraction) { |
|
|
|
if (this.startedTextExtraction) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -4268,19 +4299,19 @@ var PDFFindController = function () { |
|
|
|
|
|
|
|
|
|
|
|
var _loop = function _loop(i, ii) { |
|
|
|
var _loop = function _loop(i, ii) { |
|
|
|
var extractTextCapability = (0, _pdfjsLib.createPromiseCapability)(); |
|
|
|
var extractTextCapability = (0, _pdfjsLib.createPromiseCapability)(); |
|
|
|
_this2.extractTextPromises[i] = extractTextCapability.promise; |
|
|
|
_this3.extractTextPromises[i] = extractTextCapability.promise; |
|
|
|
promise = promise.then(function () { |
|
|
|
promise = promise.then(function () { |
|
|
|
return _this2.pdfViewer.getPageTextContent(i).then(function (textContent) { |
|
|
|
return _this3.pdfViewer.getPageTextContent(i).then(function (textContent) { |
|
|
|
var textItems = textContent.items; |
|
|
|
var textItems = textContent.items; |
|
|
|
var strBuf = []; |
|
|
|
var strBuf = []; |
|
|
|
for (var j = 0, jj = textItems.length; j < jj; j++) { |
|
|
|
for (var j = 0, jj = textItems.length; j < jj; j++) { |
|
|
|
strBuf.push(textItems[j].str); |
|
|
|
strBuf.push(textItems[j].str); |
|
|
|
} |
|
|
|
} |
|
|
|
_this2.pageContents[i] = strBuf.join(''); |
|
|
|
_this3.pageContents[i] = strBuf.join(''); |
|
|
|
extractTextCapability.resolve(i); |
|
|
|
extractTextCapability.resolve(i); |
|
|
|
}, function (reason) { |
|
|
|
}, function (reason) { |
|
|
|
console.error('Unable to get page ' + (i + 1) + ' text content', reason); |
|
|
|
console.error('Unable to get page ' + (i + 1) + ' text content', reason); |
|
|
|
_this2.pageContents[i] = ''; |
|
|
|
_this3.pageContents[i] = ''; |
|
|
|
extractTextCapability.resolve(i); |
|
|
|
extractTextCapability.resolve(i); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -4291,28 +4322,8 @@ var PDFFindController = function () { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'executeCommand', |
|
|
|
key: '_updatePage', |
|
|
|
value: function executeCommand(cmd, state) { |
|
|
|
value: function _updatePage(index) { |
|
|
|
var _this3 = this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.state === null || cmd !== 'findagain') { |
|
|
|
|
|
|
|
this.dirtyMatch = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.state = state; |
|
|
|
|
|
|
|
this.updateUIState(FindState.PENDING); |
|
|
|
|
|
|
|
this._firstPagePromise.then(function () { |
|
|
|
|
|
|
|
_this3.extractText(); |
|
|
|
|
|
|
|
clearTimeout(_this3.findTimeout); |
|
|
|
|
|
|
|
if (cmd === 'find') { |
|
|
|
|
|
|
|
_this3.findTimeout = setTimeout(_this3.nextMatch.bind(_this3), FIND_TIMEOUT); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_this3.nextMatch(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'updatePage', |
|
|
|
|
|
|
|
value: function updatePage(index) { |
|
|
|
|
|
|
|
if (this.selected.pageIdx === index) { |
|
|
|
if (this.selected.pageIdx === index) { |
|
|
|
this.pdfViewer.currentPageNumber = index + 1; |
|
|
|
this.pdfViewer.currentPageNumber = index + 1; |
|
|
|
} |
|
|
|
} |
|
|
@ -4322,8 +4333,8 @@ var PDFFindController = function () { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'nextMatch', |
|
|
|
key: '_nextMatch', |
|
|
|
value: function nextMatch() { |
|
|
|
value: function _nextMatch() { |
|
|
|
var _this4 = this; |
|
|
|
var _this4 = this; |
|
|
|
|
|
|
|
|
|
|
|
var previous = this.state.findPrevious; |
|
|
|
var previous = this.state.findPrevious; |
|
|
@ -4341,18 +4352,18 @@ var PDFFindController = function () { |
|
|
|
this.matchCount = 0; |
|
|
|
this.matchCount = 0; |
|
|
|
this.pageMatchesLength = null; |
|
|
|
this.pageMatchesLength = null; |
|
|
|
for (var i = 0; i < numPages; i++) { |
|
|
|
for (var i = 0; i < numPages; i++) { |
|
|
|
this.updatePage(i); |
|
|
|
this._updatePage(i); |
|
|
|
if (!(i in this.pendingFindMatches)) { |
|
|
|
if (!(i in this.pendingFindMatches)) { |
|
|
|
this.pendingFindMatches[i] = true; |
|
|
|
this.pendingFindMatches[i] = true; |
|
|
|
this.extractTextPromises[i].then(function (pageIdx) { |
|
|
|
this.extractTextPromises[i].then(function (pageIdx) { |
|
|
|
delete _this4.pendingFindMatches[pageIdx]; |
|
|
|
delete _this4.pendingFindMatches[pageIdx]; |
|
|
|
_this4.calcFindMatch(pageIdx); |
|
|
|
_this4._calculateMatch(pageIdx); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.state.query === '') { |
|
|
|
if (this.state.query === '') { |
|
|
|
this.updateUIState(FindState.FOUND); |
|
|
|
this._updateUIState(FindState.FOUND); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.resumePageIdx) { |
|
|
|
if (this.resumePageIdx) { |
|
|
@ -4365,49 +4376,38 @@ var PDFFindController = function () { |
|
|
|
if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) { |
|
|
|
if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) { |
|
|
|
this.hadMatch = true; |
|
|
|
this.hadMatch = true; |
|
|
|
offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1; |
|
|
|
offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1; |
|
|
|
this.updateMatch(true); |
|
|
|
this._updateMatch(true); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
this.advanceOffsetPage(previous); |
|
|
|
this._advanceOffsetPage(previous); |
|
|
|
} |
|
|
|
} |
|
|
|
this.nextPageMatch(); |
|
|
|
this._nextPageMatch(); |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'matchesReady', |
|
|
|
key: '_matchesReady', |
|
|
|
value: function matchesReady(matches) { |
|
|
|
value: function _matchesReady(matches) { |
|
|
|
var offset = this.offset; |
|
|
|
var offset = this.offset; |
|
|
|
var numMatches = matches.length; |
|
|
|
var numMatches = matches.length; |
|
|
|
var previous = this.state.findPrevious; |
|
|
|
var previous = this.state.findPrevious; |
|
|
|
if (numMatches) { |
|
|
|
if (numMatches) { |
|
|
|
this.hadMatch = true; |
|
|
|
this.hadMatch = true; |
|
|
|
offset.matchIdx = previous ? numMatches - 1 : 0; |
|
|
|
offset.matchIdx = previous ? numMatches - 1 : 0; |
|
|
|
this.updateMatch(true); |
|
|
|
this._updateMatch(true); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
this.advanceOffsetPage(previous); |
|
|
|
this._advanceOffsetPage(previous); |
|
|
|
if (offset.wrapped) { |
|
|
|
if (offset.wrapped) { |
|
|
|
offset.matchIdx = null; |
|
|
|
offset.matchIdx = null; |
|
|
|
if (this.pagesToSearch < 0) { |
|
|
|
if (this.pagesToSearch < 0) { |
|
|
|
this.updateMatch(false); |
|
|
|
this._updateMatch(false); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'updateMatchPosition', |
|
|
|
key: '_nextPageMatch', |
|
|
|
value: function updateMatchPosition(pageIndex, matchIndex, elements, beginIdx) { |
|
|
|
value: function _nextPageMatch() { |
|
|
|
if (this.selected.matchIdx === matchIndex && this.selected.pageIdx === pageIndex) { |
|
|
|
|
|
|
|
var spot = { |
|
|
|
|
|
|
|
top: FIND_SCROLL_OFFSET_TOP, |
|
|
|
|
|
|
|
left: FIND_SCROLL_OFFSET_LEFT |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
(0, _ui_utils.scrollIntoView)(elements[beginIdx], spot, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'nextPageMatch', |
|
|
|
|
|
|
|
value: function nextPageMatch() { |
|
|
|
|
|
|
|
if (this.resumePageIdx !== null) { |
|
|
|
if (this.resumePageIdx !== null) { |
|
|
|
console.error('There can only be one pending page.'); |
|
|
|
console.error('There can only be one pending page.'); |
|
|
|
} |
|
|
|
} |
|
|
@ -4419,11 +4419,11 @@ var PDFFindController = function () { |
|
|
|
this.resumePageIdx = pageIdx; |
|
|
|
this.resumePageIdx = pageIdx; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} while (!this.matchesReady(matches)); |
|
|
|
} while (!this._matchesReady(matches)); |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'advanceOffsetPage', |
|
|
|
key: '_advanceOffsetPage', |
|
|
|
value: function advanceOffsetPage(previous) { |
|
|
|
value: function _advanceOffsetPage(previous) { |
|
|
|
var offset = this.offset; |
|
|
|
var offset = this.offset; |
|
|
|
var numPages = this.extractTextPromises.length; |
|
|
|
var numPages = this.extractTextPromises.length; |
|
|
|
offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1; |
|
|
|
offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1; |
|
|
@ -4435,8 +4435,8 @@ var PDFFindController = function () { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'updateMatch', |
|
|
|
key: '_updateMatch', |
|
|
|
value: function updateMatch() { |
|
|
|
value: function _updateMatch() { |
|
|
|
var found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; |
|
|
|
var found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; |
|
|
|
|
|
|
|
|
|
|
|
var state = FindState.NOT_FOUND; |
|
|
|
var state = FindState.NOT_FOUND; |
|
|
@ -4448,24 +4448,24 @@ var PDFFindController = function () { |
|
|
|
this.selected.matchIdx = this.offset.matchIdx; |
|
|
|
this.selected.matchIdx = this.offset.matchIdx; |
|
|
|
state = wrapped ? FindState.WRAPPED : FindState.FOUND; |
|
|
|
state = wrapped ? FindState.WRAPPED : FindState.FOUND; |
|
|
|
if (previousPage !== -1 && previousPage !== this.selected.pageIdx) { |
|
|
|
if (previousPage !== -1 && previousPage !== this.selected.pageIdx) { |
|
|
|
this.updatePage(previousPage); |
|
|
|
this._updatePage(previousPage); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
this.updateUIState(state, this.state.findPrevious); |
|
|
|
this._updateUIState(state, this.state.findPrevious); |
|
|
|
if (this.selected.pageIdx !== -1) { |
|
|
|
if (this.selected.pageIdx !== -1) { |
|
|
|
this.updatePage(this.selected.pageIdx); |
|
|
|
this._updatePage(this.selected.pageIdx); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'updateUIResultsCount', |
|
|
|
key: '_updateUIResultsCount', |
|
|
|
value: function updateUIResultsCount() { |
|
|
|
value: function _updateUIResultsCount() { |
|
|
|
if (this.onUpdateResultsCount) { |
|
|
|
if (this.onUpdateResultsCount) { |
|
|
|
this.onUpdateResultsCount(this.matchCount); |
|
|
|
this.onUpdateResultsCount(this.matchCount); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
key: 'updateUIState', |
|
|
|
key: '_updateUIState', |
|
|
|
value: function updateUIState(state, previous) { |
|
|
|
value: function _updateUIState(state, previous) { |
|
|
|
if (this.onUpdateState) { |
|
|
|
if (this.onUpdateState) { |
|
|
|
this.onUpdateState(state, previous, this.matchCount); |
|
|
|
this.onUpdateState(state, previous, this.matchCount); |
|
|
|
} |
|
|
|
} |
|
|
|