|
@@ -2207,20 +2207,25 @@ exports.GenericL10n = GenericL10n;
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
value: true
|
|
|
});
|
|
|
-exports.PDFFindController = exports.FindStates = undefined;
|
|
|
+exports.PDFFindController = exports.FindState = undefined;
|
|
|
+
|
|
|
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
|
|
|
var _pdfjsLib = __w_pdfjs_require__(0);
|
|
|
|
|
|
var _ui_utils = __w_pdfjs_require__(1);
|
|
|
|
|
|
-var FindStates = {
|
|
|
- FIND_FOUND: 0,
|
|
|
- FIND_NOTFOUND: 1,
|
|
|
- FIND_WRAPPED: 2,
|
|
|
- FIND_PENDING: 3
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
+
|
|
|
+var FindState = {
|
|
|
+ FOUND: 0,
|
|
|
+ NOT_FOUND: 1,
|
|
|
+ WRAPPED: 2,
|
|
|
+ PENDING: 3
|
|
|
};
|
|
|
var FIND_SCROLL_OFFSET_TOP = -50;
|
|
|
var FIND_SCROLL_OFFSET_LEFT = -400;
|
|
|
+var FIND_TIMEOUT = 250;
|
|
|
var CHARACTERS_TO_NORMALIZE = {
|
|
|
'\u2018': '\'',
|
|
|
'\u2019': '\'',
|
|
@@ -2234,17 +2239,24 @@ var CHARACTERS_TO_NORMALIZE = {
|
|
|
'\xBD': '1/2',
|
|
|
'\xBE': '3/4'
|
|
|
};
|
|
|
-var PDFFindController = function PDFFindControllerClosure() {
|
|
|
- function PDFFindController(options) {
|
|
|
- this.pdfViewer = options.pdfViewer || null;
|
|
|
+
|
|
|
+var PDFFindController = function () {
|
|
|
+ function PDFFindController(_ref) {
|
|
|
+ var pdfViewer = _ref.pdfViewer;
|
|
|
+
|
|
|
+ _classCallCheck(this, PDFFindController);
|
|
|
+
|
|
|
+ this.pdfViewer = pdfViewer;
|
|
|
this.onUpdateResultsCount = null;
|
|
|
this.onUpdateState = null;
|
|
|
this.reset();
|
|
|
var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
|
|
|
this.normalizationRegex = new RegExp('[' + replace + ']', 'g');
|
|
|
}
|
|
|
- PDFFindController.prototype = {
|
|
|
- reset: function PDFFindController_reset() {
|
|
|
+
|
|
|
+ _createClass(PDFFindController, [{
|
|
|
+ key: 'reset',
|
|
|
+ value: function reset() {
|
|
|
var _this = this;
|
|
|
|
|
|
this.startedTextExtraction = false;
|
|
@@ -2271,23 +2283,26 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
this._firstPagePromise = new Promise(function (resolve) {
|
|
|
_this.resolveFirstPage = resolve;
|
|
|
});
|
|
|
- },
|
|
|
- normalize: function PDFFindController_normalize(text) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'normalize',
|
|
|
+ value: function normalize(text) {
|
|
|
return text.replace(this.normalizationRegex, function (ch) {
|
|
|
return CHARACTERS_TO_NORMALIZE[ch];
|
|
|
});
|
|
|
- },
|
|
|
- _prepareMatches: function PDFFindController_prepareMatches(matchesWithLength, matches, matchesLength) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: '_prepareMatches',
|
|
|
+ value: function _prepareMatches(matchesWithLength, matches, matchesLength) {
|
|
|
function isSubTerm(matchesWithLength, currentIndex) {
|
|
|
- var currentElem, prevElem, nextElem;
|
|
|
- currentElem = matchesWithLength[currentIndex];
|
|
|
- nextElem = matchesWithLength[currentIndex + 1];
|
|
|
+ var currentElem = matchesWithLength[currentIndex];
|
|
|
+ var nextElem = matchesWithLength[currentIndex + 1];
|
|
|
if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
|
|
|
currentElem.skipped = true;
|
|
|
return true;
|
|
|
}
|
|
|
for (var i = currentIndex - 1; i >= 0; i--) {
|
|
|
- prevElem = matchesWithLength[i];
|
|
|
+ var prevElem = matchesWithLength[i];
|
|
|
if (prevElem.skipped) {
|
|
|
continue;
|
|
|
}
|
|
@@ -2301,19 +2316,20 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
- var i, len;
|
|
|
matchesWithLength.sort(function (a, b) {
|
|
|
return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
|
|
|
});
|
|
|
- for (i = 0, len = matchesWithLength.length; i < len; i++) {
|
|
|
+ for (var i = 0, len = matchesWithLength.length; i < len; i++) {
|
|
|
if (isSubTerm(matchesWithLength, i)) {
|
|
|
continue;
|
|
|
}
|
|
|
matches.push(matchesWithLength[i].match);
|
|
|
matchesLength.push(matchesWithLength[i].matchLength);
|
|
|
}
|
|
|
- },
|
|
|
- calcFindPhraseMatch: function PDFFindController_calcFindPhraseMatch(query, pageIndex, pageContent) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'calcFindPhraseMatch',
|
|
|
+ value: function calcFindPhraseMatch(query, pageIndex, pageContent) {
|
|
|
var matches = [];
|
|
|
var queryLen = query.length;
|
|
|
var matchIdx = -queryLen;
|
|
@@ -2325,15 +2341,16 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
matches.push(matchIdx);
|
|
|
}
|
|
|
this.pageMatches[pageIndex] = matches;
|
|
|
- },
|
|
|
- calcFindWordMatch: function PDFFindController_calcFindWordMatch(query, pageIndex, pageContent) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'calcFindWordMatch',
|
|
|
+ value: function calcFindWordMatch(query, pageIndex, pageContent) {
|
|
|
var matchesWithLength = [];
|
|
|
var queryArray = query.match(/\S+/g);
|
|
|
- var subquery, subqueryLen, matchIdx;
|
|
|
for (var i = 0, len = queryArray.length; i < len; i++) {
|
|
|
- subquery = queryArray[i];
|
|
|
- subqueryLen = subquery.length;
|
|
|
- matchIdx = -subqueryLen;
|
|
|
+ var subquery = queryArray[i];
|
|
|
+ var subqueryLen = subquery.length;
|
|
|
+ var matchIdx = -subqueryLen;
|
|
|
while (true) {
|
|
|
matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
|
|
|
if (matchIdx === -1) {
|
|
@@ -2352,8 +2369,10 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
this.pageMatchesLength[pageIndex] = [];
|
|
|
this.pageMatches[pageIndex] = [];
|
|
|
this._prepareMatches(matchesWithLength, this.pageMatches[pageIndex], this.pageMatchesLength[pageIndex]);
|
|
|
- },
|
|
|
- calcFindMatch: function PDFFindController_calcFindMatch(pageIndex) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'calcFindMatch',
|
|
|
+ value: function calcFindMatch(pageIndex) {
|
|
|
var pageContent = this.normalize(this.pageContents[pageIndex]);
|
|
|
var query = this.normalize(this.state.query);
|
|
|
var caseSensitive = this.state.caseSensitive;
|
|
@@ -2380,8 +2399,10 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
this.matchCount += this.pageMatches[pageIndex].length;
|
|
|
this.updateUIResultsCount();
|
|
|
}
|
|
|
- },
|
|
|
- extractText: function extractText() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'extractText',
|
|
|
+ value: function extractText() {
|
|
|
var _this2 = this;
|
|
|
|
|
|
if (this.startedTextExtraction) {
|
|
@@ -2410,27 +2431,30 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
for (var i = 0, ii = this.pdfViewer.pagesCount; i < ii; i++) {
|
|
|
_loop(i, ii);
|
|
|
}
|
|
|
- },
|
|
|
-
|
|
|
- executeCommand: function PDFFindController_executeCommand(cmd, state) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'executeCommand',
|
|
|
+ value: function executeCommand(cmd, state) {
|
|
|
var _this3 = this;
|
|
|
|
|
|
if (this.state === null || cmd !== 'findagain') {
|
|
|
this.dirtyMatch = true;
|
|
|
}
|
|
|
this.state = state;
|
|
|
- this.updateUIState(FindStates.FIND_PENDING);
|
|
|
+ this.updateUIState(FindState.PENDING);
|
|
|
this._firstPagePromise.then(function () {
|
|
|
_this3.extractText();
|
|
|
clearTimeout(_this3.findTimeout);
|
|
|
if (cmd === 'find') {
|
|
|
- _this3.findTimeout = setTimeout(_this3.nextMatch.bind(_this3), 250);
|
|
|
+ _this3.findTimeout = setTimeout(_this3.nextMatch.bind(_this3), FIND_TIMEOUT);
|
|
|
} else {
|
|
|
_this3.nextMatch();
|
|
|
}
|
|
|
});
|
|
|
- },
|
|
|
- updatePage: function PDFFindController_updatePage(index) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'updatePage',
|
|
|
+ value: function updatePage(index) {
|
|
|
if (this.selected.pageIdx === index) {
|
|
|
this.pdfViewer.currentPageNumber = index + 1;
|
|
|
}
|
|
@@ -2438,8 +2462,10 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
if (page.textLayer) {
|
|
|
page.textLayer.updateMatches();
|
|
|
}
|
|
|
- },
|
|
|
- nextMatch: function PDFFindController_nextMatch() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'nextMatch',
|
|
|
+ value: function nextMatch() {
|
|
|
var _this4 = this;
|
|
|
|
|
|
var previous = this.state.findPrevious;
|
|
@@ -2468,7 +2494,7 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
}
|
|
|
}
|
|
|
if (this.state.query === '') {
|
|
|
- this.updateUIState(FindStates.FIND_FOUND);
|
|
|
+ this.updateUIState(FindState.FOUND);
|
|
|
return;
|
|
|
}
|
|
|
if (this.resumePageIdx) {
|
|
@@ -2487,8 +2513,10 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
this.advanceOffsetPage(previous);
|
|
|
}
|
|
|
this.nextPageMatch();
|
|
|
- },
|
|
|
- matchesReady: function PDFFindController_matchesReady(matches) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'matchesReady',
|
|
|
+ value: function matchesReady(matches) {
|
|
|
var offset = this.offset;
|
|
|
var numMatches = matches.length;
|
|
|
var previous = this.state.findPrevious;
|
|
@@ -2507,30 +2535,37 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
- },
|
|
|
- updateMatchPosition: function PDFFindController_updateMatchPosition(pageIndex, index, elements, beginIdx) {
|
|
|
- if (this.selected.matchIdx === index && this.selected.pageIdx === pageIndex) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ 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);
|
|
|
}
|
|
|
- },
|
|
|
- nextPageMatch: function PDFFindController_nextPageMatch() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'nextPageMatch',
|
|
|
+ value: function nextPageMatch() {
|
|
|
if (this.resumePageIdx !== null) {
|
|
|
console.error('There can only be one pending page.');
|
|
|
}
|
|
|
+ var matches = null;
|
|
|
do {
|
|
|
var pageIdx = this.offset.pageIdx;
|
|
|
- var matches = this.pageMatches[pageIdx];
|
|
|
+ matches = this.pageMatches[pageIdx];
|
|
|
if (!matches) {
|
|
|
this.resumePageIdx = pageIdx;
|
|
|
break;
|
|
|
}
|
|
|
} while (!this.matchesReady(matches));
|
|
|
- },
|
|
|
- advanceOffsetPage: function PDFFindController_advanceOffsetPage(previous) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'advanceOffsetPage',
|
|
|
+ value: function advanceOffsetPage(previous) {
|
|
|
var offset = this.offset;
|
|
|
var numPages = this.extractTextPromises.length;
|
|
|
offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
|
|
@@ -2540,16 +2575,20 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
offset.pageIdx = previous ? numPages - 1 : 0;
|
|
|
offset.wrapped = true;
|
|
|
}
|
|
|
- },
|
|
|
- updateMatch: function PDFFindController_updateMatch(found) {
|
|
|
- var state = FindStates.FIND_NOTFOUND;
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'updateMatch',
|
|
|
+ value: function updateMatch() {
|
|
|
+ var found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
+
|
|
|
+ var state = FindState.NOT_FOUND;
|
|
|
var wrapped = this.offset.wrapped;
|
|
|
this.offset.wrapped = false;
|
|
|
if (found) {
|
|
|
var previousPage = this.selected.pageIdx;
|
|
|
this.selected.pageIdx = this.offset.pageIdx;
|
|
|
this.selected.matchIdx = this.offset.matchIdx;
|
|
|
- state = wrapped ? FindStates.FIND_WRAPPED : FindStates.FIND_FOUND;
|
|
|
+ state = wrapped ? FindState.WRAPPED : FindState.FOUND;
|
|
|
if (previousPage !== -1 && previousPage !== this.selected.pageIdx) {
|
|
|
this.updatePage(previousPage);
|
|
|
}
|
|
@@ -2558,21 +2597,27 @@ var PDFFindController = function PDFFindControllerClosure() {
|
|
|
if (this.selected.pageIdx !== -1) {
|
|
|
this.updatePage(this.selected.pageIdx);
|
|
|
}
|
|
|
- },
|
|
|
- updateUIResultsCount: function PDFFindController_updateUIResultsCount() {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'updateUIResultsCount',
|
|
|
+ value: function updateUIResultsCount() {
|
|
|
if (this.onUpdateResultsCount) {
|
|
|
this.onUpdateResultsCount(this.matchCount);
|
|
|
}
|
|
|
- },
|
|
|
- updateUIState: function PDFFindController_updateUIState(state, previous) {
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'updateUIState',
|
|
|
+ value: function updateUIState(state, previous) {
|
|
|
if (this.onUpdateState) {
|
|
|
this.onUpdateState(state, previous, this.matchCount);
|
|
|
}
|
|
|
}
|
|
|
- };
|
|
|
+ }]);
|
|
|
+
|
|
|
return PDFFindController;
|
|
|
}();
|
|
|
-exports.FindStates = FindStates;
|
|
|
+
|
|
|
+exports.FindState = FindState;
|
|
|
exports.PDFFindController = PDFFindController;
|
|
|
|
|
|
/***/ }),
|