@ -4139,8 +4139,39 @@ var PDFFindController = function () {
@@ -4139,8 +4139,39 @@ var PDFFindController = function () {
} ) ;
}
} , {
key : 'normalize' ,
value : function normalize ( text ) {
key : 'executeCommand' ,
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 CHARACTERS _TO _NORMALIZE [ ch ] ;
} ) ;
@ -4182,8 +4213,8 @@ var PDFFindController = function () {
@@ -4182,8 +4213,8 @@ var PDFFindController = function () {
}
}
} , {
key : 'calcFind PhraseMatch' ,
value : function calcFind PhraseMatch( query , pageIndex , pageContent ) {
key : '_calculate PhraseMatch' ,
value : function _calculate PhraseMatch( query , pageIndex , pageContent ) {
var matches = [ ] ;
var queryLen = query . length ;
var matchIdx = - queryLen ;
@ -4197,8 +4228,8 @@ var PDFFindController = function () {
@@ -4197,8 +4228,8 @@ var PDFFindController = function () {
this . pageMatches [ pageIndex ] = matches ;
}
} , {
key : 'calcFind WordMatch' ,
value : function calcFind WordMatch( query , pageIndex , pageContent ) {
key : '_calculate WordMatch' ,
value : function _calculate WordMatch( query , pageIndex , pageContent ) {
var matchesWithLength = [ ] ;
var queryArray = query . match ( /\S+/g ) ;
for ( var i = 0 , len = queryArray . length ; i < len ; i ++ ) {
@ -4225,10 +4256,10 @@ var PDFFindController = function () {
@@ -4225,10 +4256,10 @@ var PDFFindController = function () {
this . _prepareMatches ( matchesWithLength , this . pageMatches [ pageIndex ] , this . pageMatchesLength [ pageIndex ] ) ;
}
} , {
key : 'calcFind Match' ,
value : function calcFind Match( pageIndex ) {
var pageContent = this . normalize ( this . pageContents [ pageIndex ] ) ;
var query = this . normalize ( this . state . query ) ;
key : '_calculate Match' ,
value : function _calculate Match( pageIndex ) {
var pageContent = this . _ normalize( this . pageContents [ pageIndex ] ) ;
var query = this . _ normalize( this . state . query ) ;
var caseSensitive = this . state . caseSensitive ;
var phraseSearch = this . state . phraseSearch ;
var queryLen = query . length ;
@ -4240,24 +4271,24 @@ var PDFFindController = function () {
@@ -4240,24 +4271,24 @@ var PDFFindController = function () {
query = query . toLowerCase ( ) ;
}
if ( phraseSearch ) {
this . calcFind PhraseMatch( query , pageIndex , pageContent ) ;
this . _calculate PhraseMatch( query , pageIndex , pageContent ) ;
} else {
this . calcFind WordMatch( query , pageIndex , pageContent ) ;
this . _calculate WordMatch( query , pageIndex , pageContent ) ;
}
this . updatePage ( pageIndex ) ;
this . _ updatePage( pageIndex ) ;
if ( this . resumePageIdx === pageIndex ) {
this . resumePageIdx = null ;
this . nextPageMatch ( ) ;
this . _ nextPageMatch( ) ;
}
if ( this . pageMatches [ pageIndex ] . length > 0 ) {
this . matchCount += this . pageMatches [ pageIndex ] . length ;
this . updateUIResultsCount ( ) ;
this . _ updateUIResultsCount( ) ;
}
}
} , {
key : 'extractText' ,
value : function extractText ( ) {
var _this2 = this ;
key : '_ extractText' ,
value : function _ extractText( ) {
var _this3 = this ;
if ( this . startedTextExtraction ) {
return ;
@ -4268,19 +4299,19 @@ var PDFFindController = function () {
@@ -4268,19 +4299,19 @@ var PDFFindController = function () {
var _loop = function _loop ( i , ii ) {
var extractTextCapability = ( 0 , _pdfjsLib . createPromiseCapability ) ( ) ;
_this2 . extractTextPromises [ i ] = extractTextCapability . promise ;
_this3 . extractTextPromises [ i ] = extractTextCapability . promise ;
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 strBuf = [ ] ;
for ( var j = 0 , jj = textItems . length ; j < jj ; j ++ ) {
strBuf . push ( textItems [ j ] . str ) ;
}
_this2 . pageContents [ i ] = strBuf . join ( '' ) ;
_this3 . pageContents [ i ] = strBuf . join ( '' ) ;
extractTextCapability . resolve ( i ) ;
} , function ( reason ) {
console . error ( 'Unable to get page ' + ( i + 1 ) + ' text content' , reason ) ;
_this2 . pageContents [ i ] = '' ;
_this3 . pageContents [ i ] = '' ;
extractTextCapability . resolve ( i ) ;
} ) ;
} ) ;
@ -4291,28 +4322,8 @@ var PDFFindController = function () {
@@ -4291,28 +4322,8 @@ var PDFFindController = function () {
}
}
} , {
key : 'executeCommand' ,
value : function executeCommand ( cmd , state ) {
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 ) {
key : '_updatePage' ,
value : function _updatePage ( index ) {
if ( this . selected . pageIdx === index ) {
this . pdfViewer . currentPageNumber = index + 1 ;
}
@ -4322,8 +4333,8 @@ var PDFFindController = function () {
@@ -4322,8 +4333,8 @@ var PDFFindController = function () {
}
}
} , {
key : 'nextMatch' ,
value : function nextMatch ( ) {
key : '_ nextMatch' ,
value : function _ nextMatch( ) {
var _this4 = this ;
var previous = this . state . findPrevious ;
@ -4341,18 +4352,18 @@ var PDFFindController = function () {
@@ -4341,18 +4352,18 @@ var PDFFindController = function () {
this . matchCount = 0 ;
this . pageMatchesLength = null ;
for ( var i = 0 ; i < numPages ; i ++ ) {
this . updatePage ( i ) ;
this . _ updatePage( i ) ;
if ( ! ( i in this . pendingFindMatches ) ) {
this . pendingFindMatches [ i ] = true ;
this . extractTextPromises [ i ] . then ( function ( pageIdx ) {
delete _this4 . pendingFindMatches [ pageIdx ] ;
_this4 . calcFind Match( pageIdx ) ;
_this4 . _calculate Match( pageIdx ) ;
} ) ;
}
}
}
if ( this . state . query === '' ) {
this . updateUIState ( FindState . FOUND ) ;
this . _ updateUIState( FindState . FOUND ) ;
return ;
}
if ( this . resumePageIdx ) {
@ -4365,49 +4376,38 @@ var PDFFindController = function () {
@@ -4365,49 +4376,38 @@ var PDFFindController = function () {
if ( ! previous && offset . matchIdx + 1 < numPageMatches || previous && offset . matchIdx > 0 ) {
this . hadMatch = true ;
offset . matchIdx = previous ? offset . matchIdx - 1 : offset . matchIdx + 1 ;
this . updateMatch ( true ) ;
this . _ updateMatch( true ) ;
return ;
}
this . advanceOffsetPage ( previous ) ;
this . _ advanceOffsetPage( previous ) ;
}
this . nextPageMatch ( ) ;
this . _ nextPageMatch( ) ;
}
} , {
key : 'matchesReady' ,
value : function matchesReady ( matches ) {
key : '_ matchesReady' ,
value : function _ matchesReady( matches ) {
var offset = this . offset ;
var numMatches = matches . length ;
var previous = this . state . findPrevious ;
if ( numMatches ) {
this . hadMatch = true ;
offset . matchIdx = previous ? numMatches - 1 : 0 ;
this . updateMatch ( true ) ;
this . _ updateMatch( true ) ;
return true ;
}
this . advanceOffsetPage ( previous ) ;
this . _ advanceOffsetPage( previous ) ;
if ( offset . wrapped ) {
offset . matchIdx = null ;
if ( this . pagesToSearch < 0 ) {
this . updateMatch ( false ) ;
this . _ updateMatch( false ) ;
return true ;
}
}
return false ;
}
} , {
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 : 'nextPageMatch' ,
value : function nextPageMatch ( ) {
key : '_nextPageMatch' ,
value : function _nextPageMatch ( ) {
if ( this . resumePageIdx !== null ) {
console . error ( 'There can only be one pending page.' ) ;
}
@ -4419,11 +4419,11 @@ var PDFFindController = function () {
@@ -4419,11 +4419,11 @@ var PDFFindController = function () {
this . resumePageIdx = pageIdx ;
break ;
}
} while ( ! this . matchesReady ( matches ) ) ;
} while ( ! this . _ matchesReady( matches ) ) ;
}
} , {
key : 'advanceOffsetPage' ,
value : function 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 ;
@ -4435,8 +4435,8 @@ var PDFFindController = function () {
@@ -4435,8 +4435,8 @@ var PDFFindController = function () {
}
}
} , {
key : 'updateMatch' ,
value : function updateMatch ( ) {
key : '_ updateMatch' ,
value : function _ updateMatch( ) {
var found = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : false ;
var state = FindState . NOT _FOUND ;
@ -4448,24 +4448,24 @@ var PDFFindController = function () {
@@ -4448,24 +4448,24 @@ var PDFFindController = function () {
this . selected . matchIdx = this . offset . matchIdx ;
state = wrapped ? FindState . WRAPPED : FindState . FOUND ;
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 ) {
this . updatePage ( this . selected . pageIdx ) ;
this . _ updatePage( this . selected . pageIdx ) ;
}
}
} , {
key : 'updateUIResultsCount' ,
value : function updateUIResultsCount ( ) {
key : '_ updateUIResultsCount' ,
value : function _ updateUIResultsCount( ) {
if ( this . onUpdateResultsCount ) {
this . onUpdateResultsCount ( this . matchCount ) ;
}
}
} , {
key : 'updateUIState' ,
value : function updateUIState ( state , previous ) {
key : '_ updateUIState' ,
value : function _ updateUIState( state , previous ) {
if ( this . onUpdateState ) {
this . onUpdateState ( state , previous , this . matchCount ) ;
}