Browse Source

PDF.js version 2.0.357 - See mozilla/pdf.js@be2674a0e8d4bf239e08eb33a42d1f4d15fde7ee

master v2.0.357
pdfjsbot 7 years ago
parent
commit
0d219a1c55
  1. 2
      bower.json
  2. 14
      build/pdf.js
  3. 2
      build/pdf.js.map
  4. 2
      build/pdf.min.js
  5. 6
      build/pdf.worker.js
  6. 2
      build/pdf.worker.js.map
  7. 2
      build/pdf.worker.min.js
  8. 2
      lib/core/worker.js
  9. 6
      lib/display/api.js
  10. 4
      lib/display/global.js
  11. 4
      lib/pdf.js
  12. 4
      lib/pdf.worker.js
  13. 164
      lib/web/pdf_find_controller.js
  14. 2
      package.json
  15. 164
      web/pdf_viewer.js
  16. 2
      web/pdf_viewer.js.map

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "2.0.354", "version": "2.0.357",
"main": [ "main": [
"build/pdf.js", "build/pdf.js",
"build/pdf.worker.js" "build/pdf.worker.js"

14
build/pdf.js

@ -3299,7 +3299,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
if (worker.destroyed) { if (worker.destroyed) {
return Promise.reject(new Error('Worker was destroyed')); return Promise.reject(new Error('Worker was destroyed'));
} }
var apiVersion = '2.0.354'; var apiVersion = '2.0.357';
source.disableRange = (0, _dom_utils.getDefaultSetting)('disableRange'); source.disableRange = (0, _dom_utils.getDefaultSetting)('disableRange');
source.disableAutoFetch = (0, _dom_utils.getDefaultSetting)('disableAutoFetch'); source.disableAutoFetch = (0, _dom_utils.getDefaultSetting)('disableAutoFetch');
source.disableStream = (0, _dom_utils.getDefaultSetting)('disableStream'); source.disableStream = (0, _dom_utils.getDefaultSetting)('disableStream');
@ -4698,8 +4698,8 @@ var InternalRenderTask = function InternalRenderTaskClosure() {
}(); }();
var version, build; var version, build;
{ {
exports.version = version = '2.0.354'; exports.version = version = '2.0.357';
exports.build = build = 'b3557483'; exports.build = build = 'be2674a0';
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort; exports.LoopbackPort = LoopbackPort;
@ -7457,8 +7457,8 @@ exports.SVGGraphics = SVGGraphics;
"use strict"; "use strict";
var pdfjsVersion = '2.0.354'; var pdfjsVersion = '2.0.357';
var pdfjsBuild = 'b3557483'; var pdfjsBuild = 'be2674a0';
var pdfjsSharedUtil = __w_pdfjs_require__(0); var pdfjsSharedUtil = __w_pdfjs_require__(0);
var pdfjsDisplayGlobal = __w_pdfjs_require__(120); var pdfjsDisplayGlobal = __w_pdfjs_require__(120);
var pdfjsDisplayAPI = __w_pdfjs_require__(58); var pdfjsDisplayAPI = __w_pdfjs_require__(58);
@ -12743,8 +12743,8 @@ if (!_global_scope2.default.PDFJS) {
} }
var PDFJS = _global_scope2.default.PDFJS; var PDFJS = _global_scope2.default.PDFJS;
{ {
PDFJS.version = '2.0.354'; PDFJS.version = '2.0.357';
PDFJS.build = 'b3557483'; PDFJS.build = 'be2674a0';
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {

2
build/pdf.js.map

File diff suppressed because one or more lines are too long

2
build/pdf.min.js vendored

File diff suppressed because one or more lines are too long

6
build/pdf.worker.js vendored

@ -22295,8 +22295,8 @@ exports.PostScriptCompiler = PostScriptCompiler;
"use strict"; "use strict";
var pdfjsVersion = '2.0.354'; var pdfjsVersion = '2.0.357';
var pdfjsBuild = 'b3557483'; var pdfjsBuild = 'be2674a0';
var pdfjsCoreWorker = __w_pdfjs_require__(74); var pdfjsCoreWorker = __w_pdfjs_require__(74);
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler; exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;
@ -22509,7 +22509,7 @@ var WorkerMessageHandler = {
var cancelXHRs = null; var cancelXHRs = null;
var WorkerTasks = []; var WorkerTasks = [];
var apiVersion = docParams.apiVersion; var apiVersion = docParams.apiVersion;
var workerVersion = '2.0.354'; var workerVersion = '2.0.357';
if (apiVersion !== null && apiVersion !== workerVersion) { if (apiVersion !== null && apiVersion !== workerVersion) {
throw new Error('The API version "' + apiVersion + '" does not match ' + ('the Worker version "' + workerVersion + '".')); throw new Error('The API version "' + apiVersion + '" does not match ' + ('the Worker version "' + workerVersion + '".'));
} }

2
build/pdf.worker.js.map vendored

File diff suppressed because one or more lines are too long

2
build/pdf.worker.min.js vendored

File diff suppressed because one or more lines are too long

2
lib/core/worker.js

@ -223,7 +223,7 @@ var WorkerMessageHandler = {
var cancelXHRs = null; var cancelXHRs = null;
var WorkerTasks = []; var WorkerTasks = [];
var apiVersion = docParams.apiVersion; var apiVersion = docParams.apiVersion;
var workerVersion = '2.0.354'; var workerVersion = '2.0.357';
if (apiVersion !== null && apiVersion !== workerVersion) { if (apiVersion !== null && apiVersion !== workerVersion) {
throw new Error('The API version "' + apiVersion + '" does not match ' + ('the Worker version "' + workerVersion + '".')); throw new Error('The API version "' + apiVersion + '" does not match ' + ('the Worker version "' + workerVersion + '".'));
} }

6
lib/display/api.js

@ -178,7 +178,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
if (worker.destroyed) { if (worker.destroyed) {
return Promise.reject(new Error('Worker was destroyed')); return Promise.reject(new Error('Worker was destroyed'));
} }
var apiVersion = '2.0.354'; var apiVersion = '2.0.357';
source.disableRange = (0, _dom_utils.getDefaultSetting)('disableRange'); source.disableRange = (0, _dom_utils.getDefaultSetting)('disableRange');
source.disableAutoFetch = (0, _dom_utils.getDefaultSetting)('disableAutoFetch'); source.disableAutoFetch = (0, _dom_utils.getDefaultSetting)('disableAutoFetch');
source.disableStream = (0, _dom_utils.getDefaultSetting)('disableStream'); source.disableStream = (0, _dom_utils.getDefaultSetting)('disableStream');
@ -1577,8 +1577,8 @@ var InternalRenderTask = function InternalRenderTaskClosure() {
}(); }();
var version, build; var version, build;
{ {
exports.version = version = '2.0.354'; exports.version = version = '2.0.357';
exports.build = build = 'b3557483'; exports.build = build = 'be2674a0';
} }
exports.getDocument = getDocument; exports.getDocument = getDocument;
exports.LoopbackPort = LoopbackPort; exports.LoopbackPort = LoopbackPort;

4
lib/display/global.js

@ -51,8 +51,8 @@ if (!_global_scope2.default.PDFJS) {
} }
var PDFJS = _global_scope2.default.PDFJS; var PDFJS = _global_scope2.default.PDFJS;
{ {
PDFJS.version = '2.0.354'; PDFJS.version = '2.0.357';
PDFJS.build = 'b3557483'; PDFJS.build = 'be2674a0';
} }
PDFJS.pdfBug = false; PDFJS.pdfBug = false;
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {

4
lib/pdf.js

@ -21,8 +21,8 @@
*/ */
'use strict'; 'use strict';
var pdfjsVersion = '2.0.354'; var pdfjsVersion = '2.0.357';
var pdfjsBuild = 'b3557483'; var pdfjsBuild = 'be2674a0';
var pdfjsSharedUtil = require('./shared/util.js'); var pdfjsSharedUtil = require('./shared/util.js');
var pdfjsDisplayGlobal = require('./display/global.js'); var pdfjsDisplayGlobal = require('./display/global.js');
var pdfjsDisplayAPI = require('./display/api.js'); var pdfjsDisplayAPI = require('./display/api.js');

4
lib/pdf.worker.js vendored

@ -21,7 +21,7 @@
*/ */
'use strict'; 'use strict';
var pdfjsVersion = '2.0.354'; var pdfjsVersion = '2.0.357';
var pdfjsBuild = 'b3557483'; var pdfjsBuild = 'be2674a0';
var pdfjsCoreWorker = require('./core/worker.js'); var pdfjsCoreWorker = require('./core/worker.js');
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler; exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;

164
lib/web/pdf_find_controller.js

@ -102,8 +102,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];
}); });
@ -145,8 +176,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;
@ -160,8 +191,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++) {
@ -188,10 +219,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;
@ -203,24 +234,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;
@ -231,19 +262,19 @@ var PDFFindController = function () {
var _loop = function _loop(i, ii) { var _loop = function _loop(i, ii) {
var extractTextCapability = (0, _pdf.createPromiseCapability)(); var extractTextCapability = (0, _pdf.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);
}); });
}); });
@ -254,28 +285,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;
} }
@ -285,8 +296,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;
@ -304,18 +315,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) {
@ -328,49 +339,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.');
} }
@ -382,11 +382,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;
@ -398,8 +398,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;
@ -411,24 +411,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);
} }

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "2.0.354", "version": "2.0.357",
"main": "build/pdf.js", "main": "build/pdf.js",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [

164
web/pdf_viewer.js

@ -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);
} }

2
web/pdf_viewer.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save