viewer.js 264 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490
  1. /* Copyright 2016 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. ;
  17. var pdfjsWebLibs;
  18. {
  19. pdfjsWebLibs = { pdfjsWebPDFJS: window.pdfjsDistBuildPdf };
  20. (function () {
  21. (function (root, factory) {
  22. factory(root.pdfjsWebGrabToPan = {});
  23. }(this, function (exports) {
  24. function GrabToPan(options) {
  25. this.element = options.element;
  26. this.document = options.element.ownerDocument;
  27. if (typeof options.ignoreTarget === 'function') {
  28. this.ignoreTarget = options.ignoreTarget;
  29. }
  30. this.onActiveChanged = options.onActiveChanged;
  31. this.activate = this.activate.bind(this);
  32. this.deactivate = this.deactivate.bind(this);
  33. this.toggle = this.toggle.bind(this);
  34. this._onmousedown = this._onmousedown.bind(this);
  35. this._onmousemove = this._onmousemove.bind(this);
  36. this._endPan = this._endPan.bind(this);
  37. var overlay = this.overlay = document.createElement('div');
  38. overlay.className = 'grab-to-pan-grabbing';
  39. }
  40. GrabToPan.prototype = {
  41. CSS_CLASS_GRAB: 'grab-to-pan-grab',
  42. activate: function GrabToPan_activate() {
  43. if (!this.active) {
  44. this.active = true;
  45. this.element.addEventListener('mousedown', this._onmousedown, true);
  46. this.element.classList.add(this.CSS_CLASS_GRAB);
  47. if (this.onActiveChanged) {
  48. this.onActiveChanged(true);
  49. }
  50. }
  51. },
  52. deactivate: function GrabToPan_deactivate() {
  53. if (this.active) {
  54. this.active = false;
  55. this.element.removeEventListener('mousedown', this._onmousedown, true);
  56. this._endPan();
  57. this.element.classList.remove(this.CSS_CLASS_GRAB);
  58. if (this.onActiveChanged) {
  59. this.onActiveChanged(false);
  60. }
  61. }
  62. },
  63. toggle: function GrabToPan_toggle() {
  64. if (this.active) {
  65. this.deactivate();
  66. } else {
  67. this.activate();
  68. }
  69. },
  70. ignoreTarget: function GrabToPan_ignoreTarget(node) {
  71. return node[matchesSelector]('a[href], a[href] *, input, textarea, button, button *, select, option');
  72. },
  73. _onmousedown: function GrabToPan__onmousedown(event) {
  74. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  75. return;
  76. }
  77. if (event.originalTarget) {
  78. try {
  79. event.originalTarget.tagName;
  80. } catch (e) {
  81. return;
  82. }
  83. }
  84. this.scrollLeftStart = this.element.scrollLeft;
  85. this.scrollTopStart = this.element.scrollTop;
  86. this.clientXStart = event.clientX;
  87. this.clientYStart = event.clientY;
  88. this.document.addEventListener('mousemove', this._onmousemove, true);
  89. this.document.addEventListener('mouseup', this._endPan, true);
  90. this.element.addEventListener('scroll', this._endPan, true);
  91. event.preventDefault();
  92. event.stopPropagation();
  93. var focusedElement = document.activeElement;
  94. if (focusedElement && !focusedElement.contains(event.target)) {
  95. focusedElement.blur();
  96. }
  97. },
  98. _onmousemove: function GrabToPan__onmousemove(event) {
  99. this.element.removeEventListener('scroll', this._endPan, true);
  100. if (isLeftMouseReleased(event)) {
  101. this._endPan();
  102. return;
  103. }
  104. var xDiff = event.clientX - this.clientXStart;
  105. var yDiff = event.clientY - this.clientYStart;
  106. var scrollTop = this.scrollTopStart - yDiff;
  107. var scrollLeft = this.scrollLeftStart - xDiff;
  108. if (this.element.scrollTo) {
  109. this.element.scrollTo({
  110. top: scrollTop,
  111. left: scrollLeft,
  112. behavior: 'instant'
  113. });
  114. } else {
  115. this.element.scrollTop = scrollTop;
  116. this.element.scrollLeft = scrollLeft;
  117. }
  118. if (!this.overlay.parentNode) {
  119. document.body.appendChild(this.overlay);
  120. }
  121. },
  122. _endPan: function GrabToPan__endPan() {
  123. this.element.removeEventListener('scroll', this._endPan, true);
  124. this.document.removeEventListener('mousemove', this._onmousemove, true);
  125. this.document.removeEventListener('mouseup', this._endPan, true);
  126. if (this.overlay.parentNode) {
  127. this.overlay.parentNode.removeChild(this.overlay);
  128. }
  129. }
  130. };
  131. var matchesSelector;
  132. [
  133. 'webkitM',
  134. 'mozM',
  135. 'msM',
  136. 'oM',
  137. 'm'
  138. ].some(function (prefix) {
  139. var name = prefix + 'atches';
  140. if (name in document.documentElement) {
  141. matchesSelector = name;
  142. }
  143. name += 'Selector';
  144. if (name in document.documentElement) {
  145. matchesSelector = name;
  146. }
  147. return matchesSelector;
  148. });
  149. var isNotIEorIsIE10plus = !document.documentMode || document.documentMode > 9;
  150. var chrome = window.chrome;
  151. var isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  152. var isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  153. function isLeftMouseReleased(event) {
  154. if ('buttons' in event && isNotIEorIsIE10plus) {
  155. return !(event.buttons & 1);
  156. }
  157. if (isChrome15OrOpera15plus || isSafari6plus) {
  158. return event.which === 0;
  159. }
  160. }
  161. exports.GrabToPan = GrabToPan;
  162. }));
  163. (function (root, factory) {
  164. factory(root.pdfjsWebOverlayManager = {});
  165. }(this, function (exports) {
  166. var OverlayManager = {
  167. overlays: {},
  168. active: null,
  169. register: function overlayManagerRegister(name, element, callerCloseMethod, canForceClose) {
  170. return new Promise(function (resolve) {
  171. var container;
  172. if (!name || !element || !(container = element.parentNode)) {
  173. throw new Error('Not enough parameters.');
  174. } else if (this.overlays[name]) {
  175. throw new Error('The overlay is already registered.');
  176. }
  177. this.overlays[name] = {
  178. element: element,
  179. container: container,
  180. callerCloseMethod: callerCloseMethod || null,
  181. canForceClose: canForceClose || false
  182. };
  183. resolve();
  184. }.bind(this));
  185. },
  186. unregister: function overlayManagerUnregister(name) {
  187. return new Promise(function (resolve) {
  188. if (!this.overlays[name]) {
  189. throw new Error('The overlay does not exist.');
  190. } else if (this.active === name) {
  191. throw new Error('The overlay cannot be removed while it is active.');
  192. }
  193. delete this.overlays[name];
  194. resolve();
  195. }.bind(this));
  196. },
  197. open: function overlayManagerOpen(name) {
  198. return new Promise(function (resolve) {
  199. if (!this.overlays[name]) {
  200. throw new Error('The overlay does not exist.');
  201. } else if (this.active) {
  202. if (this.overlays[name].canForceClose) {
  203. this._closeThroughCaller();
  204. } else if (this.active === name) {
  205. throw new Error('The overlay is already active.');
  206. } else {
  207. throw new Error('Another overlay is currently active.');
  208. }
  209. }
  210. this.active = name;
  211. this.overlays[this.active].element.classList.remove('hidden');
  212. this.overlays[this.active].container.classList.remove('hidden');
  213. window.addEventListener('keydown', this._keyDown);
  214. resolve();
  215. }.bind(this));
  216. },
  217. close: function overlayManagerClose(name) {
  218. return new Promise(function (resolve) {
  219. if (!this.overlays[name]) {
  220. throw new Error('The overlay does not exist.');
  221. } else if (!this.active) {
  222. throw new Error('The overlay is currently not active.');
  223. } else if (this.active !== name) {
  224. throw new Error('Another overlay is currently active.');
  225. }
  226. this.overlays[this.active].container.classList.add('hidden');
  227. this.overlays[this.active].element.classList.add('hidden');
  228. this.active = null;
  229. window.removeEventListener('keydown', this._keyDown);
  230. resolve();
  231. }.bind(this));
  232. },
  233. _keyDown: function overlayManager_keyDown(evt) {
  234. var self = OverlayManager;
  235. if (self.active && evt.keyCode === 27) {
  236. self._closeThroughCaller();
  237. evt.preventDefault();
  238. }
  239. },
  240. _closeThroughCaller: function overlayManager_closeThroughCaller() {
  241. if (this.overlays[this.active].callerCloseMethod) {
  242. this.overlays[this.active].callerCloseMethod();
  243. }
  244. if (this.active) {
  245. this.close(this.active);
  246. }
  247. }
  248. };
  249. exports.OverlayManager = OverlayManager;
  250. }));
  251. (function (root, factory) {
  252. factory(root.pdfjsWebPDFRenderingQueue = {});
  253. }(this, function (exports) {
  254. var CLEANUP_TIMEOUT = 30000;
  255. var RenderingStates = {
  256. INITIAL: 0,
  257. RUNNING: 1,
  258. PAUSED: 2,
  259. FINISHED: 3
  260. };
  261. var PDFRenderingQueue = function PDFRenderingQueueClosure() {
  262. function PDFRenderingQueue() {
  263. this.pdfViewer = null;
  264. this.pdfThumbnailViewer = null;
  265. this.onIdle = null;
  266. this.highestPriorityPage = null;
  267. this.idleTimeout = null;
  268. this.printing = false;
  269. this.isThumbnailViewEnabled = false;
  270. }
  271. PDFRenderingQueue.prototype = {
  272. setViewer: function PDFRenderingQueue_setViewer(pdfViewer) {
  273. this.pdfViewer = pdfViewer;
  274. },
  275. setThumbnailViewer: function PDFRenderingQueue_setThumbnailViewer(pdfThumbnailViewer) {
  276. this.pdfThumbnailViewer = pdfThumbnailViewer;
  277. },
  278. isHighestPriority: function PDFRenderingQueue_isHighestPriority(view) {
  279. return this.highestPriorityPage === view.renderingId;
  280. },
  281. renderHighestPriority: function PDFRenderingQueue_renderHighestPriority(currentlyVisiblePages) {
  282. if (this.idleTimeout) {
  283. clearTimeout(this.idleTimeout);
  284. this.idleTimeout = null;
  285. }
  286. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  287. return;
  288. }
  289. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  290. if (this.pdfThumbnailViewer.forceRendering()) {
  291. return;
  292. }
  293. }
  294. if (this.printing) {
  295. return;
  296. }
  297. if (this.onIdle) {
  298. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  299. }
  300. },
  301. getHighestPriority: function PDFRenderingQueue_getHighestPriority(visible, views, scrolledDown) {
  302. var visibleViews = visible.views;
  303. var numVisible = visibleViews.length;
  304. if (numVisible === 0) {
  305. return false;
  306. }
  307. for (var i = 0; i < numVisible; ++i) {
  308. var view = visibleViews[i].view;
  309. if (!this.isViewFinished(view)) {
  310. return view;
  311. }
  312. }
  313. if (scrolledDown) {
  314. var nextPageIndex = visible.last.id;
  315. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  316. return views[nextPageIndex];
  317. }
  318. } else {
  319. var previousPageIndex = visible.first.id - 2;
  320. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  321. return views[previousPageIndex];
  322. }
  323. }
  324. return null;
  325. },
  326. isViewFinished: function PDFRenderingQueue_isViewFinished(view) {
  327. return view.renderingState === RenderingStates.FINISHED;
  328. },
  329. renderView: function PDFRenderingQueue_renderView(view) {
  330. var state = view.renderingState;
  331. switch (state) {
  332. case RenderingStates.FINISHED:
  333. return false;
  334. case RenderingStates.PAUSED:
  335. this.highestPriorityPage = view.renderingId;
  336. view.resume();
  337. break;
  338. case RenderingStates.RUNNING:
  339. this.highestPriorityPage = view.renderingId;
  340. break;
  341. case RenderingStates.INITIAL:
  342. this.highestPriorityPage = view.renderingId;
  343. var continueRendering = function () {
  344. this.renderHighestPriority();
  345. }.bind(this);
  346. view.draw().then(continueRendering, continueRendering);
  347. break;
  348. }
  349. return true;
  350. }
  351. };
  352. return PDFRenderingQueue;
  353. }();
  354. exports.RenderingStates = RenderingStates;
  355. exports.PDFRenderingQueue = PDFRenderingQueue;
  356. }));
  357. (function (root, factory) {
  358. factory(root.pdfjsWebPreferences = {});
  359. }(this, function (exports) {
  360. var defaultPreferences = null;
  361. function getDefaultPreferences() {
  362. if (!defaultPreferences) {
  363. defaultPreferences = Promise.resolve({
  364. "showPreviousViewOnLoad": true,
  365. "defaultZoomValue": "",
  366. "sidebarViewOnLoad": 0,
  367. "enableHandToolOnLoad": false,
  368. "enableWebGL": false,
  369. "pdfBugEnabled": false,
  370. "disableRange": false,
  371. "disableStream": false,
  372. "disableAutoFetch": false,
  373. "disableFontFace": false,
  374. "disableTextLayer": false,
  375. "useOnlyCssZoom": false,
  376. "externalLinkTarget": 0,
  377. "enhanceTextSelection": false,
  378. "renderer": "canvas",
  379. "renderInteractiveForms": false,
  380. "disablePageLabels": false
  381. });
  382. }
  383. return defaultPreferences;
  384. }
  385. function cloneObj(obj) {
  386. var result = {};
  387. for (var i in obj) {
  388. if (Object.prototype.hasOwnProperty.call(obj, i)) {
  389. result[i] = obj[i];
  390. }
  391. }
  392. return result;
  393. }
  394. var Preferences = {
  395. prefs: null,
  396. isInitializedPromiseResolved: false,
  397. initializedPromise: null,
  398. initialize: function preferencesInitialize() {
  399. return this.initializedPromise = getDefaultPreferences().then(function (defaults) {
  400. Object.defineProperty(this, 'defaults', {
  401. value: Object.freeze(defaults),
  402. writable: false,
  403. enumerable: true,
  404. configurable: false
  405. });
  406. this.prefs = cloneObj(defaults);
  407. return this._readFromStorage(defaults);
  408. }.bind(this)).then(function (prefObj) {
  409. this.isInitializedPromiseResolved = true;
  410. if (prefObj) {
  411. this.prefs = prefObj;
  412. }
  413. }.bind(this));
  414. },
  415. _writeToStorage: function preferences_writeToStorage(prefObj) {
  416. return Promise.resolve();
  417. },
  418. _readFromStorage: function preferences_readFromStorage(prefObj) {
  419. return Promise.resolve();
  420. },
  421. reset: function preferencesReset() {
  422. return this.initializedPromise.then(function () {
  423. this.prefs = cloneObj(this.defaults);
  424. return this._writeToStorage(this.defaults);
  425. }.bind(this));
  426. },
  427. reload: function preferencesReload() {
  428. return this.initializedPromise.then(function () {
  429. this._readFromStorage(this.defaults).then(function (prefObj) {
  430. if (prefObj) {
  431. this.prefs = prefObj;
  432. }
  433. }.bind(this));
  434. }.bind(this));
  435. },
  436. set: function preferencesSet(name, value) {
  437. return this.initializedPromise.then(function () {
  438. if (this.defaults[name] === undefined) {
  439. throw new Error('preferencesSet: \'' + name + '\' is undefined.');
  440. } else if (value === undefined) {
  441. throw new Error('preferencesSet: no value is specified.');
  442. }
  443. var valueType = typeof value;
  444. var defaultType = typeof this.defaults[name];
  445. if (valueType !== defaultType) {
  446. if (valueType === 'number' && defaultType === 'string') {
  447. value = value.toString();
  448. } else {
  449. throw new Error('Preferences_set: \'' + value + '\' is a \"' + valueType + '\", expected \"' + defaultType + '\".');
  450. }
  451. } else {
  452. if (valueType === 'number' && (value | 0) !== value) {
  453. throw new Error('Preferences_set: \'' + value + '\' must be an \"integer\".');
  454. }
  455. }
  456. this.prefs[name] = value;
  457. return this._writeToStorage(this.prefs);
  458. }.bind(this));
  459. },
  460. get: function preferencesGet(name) {
  461. return this.initializedPromise.then(function () {
  462. var defaultValue = this.defaults[name];
  463. if (defaultValue === undefined) {
  464. throw new Error('preferencesGet: \'' + name + '\' is undefined.');
  465. } else {
  466. var prefValue = this.prefs[name];
  467. if (prefValue !== undefined) {
  468. return prefValue;
  469. }
  470. }
  471. return defaultValue;
  472. }.bind(this));
  473. }
  474. };
  475. Preferences._writeToStorage = function (prefObj) {
  476. return new Promise(function (resolve) {
  477. localStorage.setItem('pdfjs.preferences', JSON.stringify(prefObj));
  478. resolve();
  479. });
  480. };
  481. Preferences._readFromStorage = function (prefObj) {
  482. return new Promise(function (resolve) {
  483. var readPrefs = JSON.parse(localStorage.getItem('pdfjs.preferences'));
  484. resolve(readPrefs);
  485. });
  486. };
  487. exports.Preferences = Preferences;
  488. }));
  489. (function (root, factory) {
  490. factory(root.pdfjsWebViewHistory = {});
  491. }(this, function (exports) {
  492. var DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  493. var ViewHistory = function ViewHistoryClosure() {
  494. function ViewHistory(fingerprint, cacheSize) {
  495. this.fingerprint = fingerprint;
  496. this.cacheSize = cacheSize || DEFAULT_VIEW_HISTORY_CACHE_SIZE;
  497. this.isInitializedPromiseResolved = false;
  498. this.initializedPromise = this._readFromStorage().then(function (databaseStr) {
  499. this.isInitializedPromiseResolved = true;
  500. var database = JSON.parse(databaseStr || '{}');
  501. if (!('files' in database)) {
  502. database.files = [];
  503. }
  504. if (database.files.length >= this.cacheSize) {
  505. database.files.shift();
  506. }
  507. var index;
  508. for (var i = 0, length = database.files.length; i < length; i++) {
  509. var branch = database.files[i];
  510. if (branch.fingerprint === this.fingerprint) {
  511. index = i;
  512. break;
  513. }
  514. }
  515. if (typeof index !== 'number') {
  516. index = database.files.push({ fingerprint: this.fingerprint }) - 1;
  517. }
  518. this.file = database.files[index];
  519. this.database = database;
  520. }.bind(this));
  521. }
  522. ViewHistory.prototype = {
  523. _writeToStorage: function ViewHistory_writeToStorage() {
  524. return new Promise(function (resolve) {
  525. var databaseStr = JSON.stringify(this.database);
  526. localStorage.setItem('pdfjs.history', databaseStr);
  527. resolve();
  528. }.bind(this));
  529. },
  530. _readFromStorage: function ViewHistory_readFromStorage() {
  531. return new Promise(function (resolve) {
  532. var value = localStorage.getItem('pdfjs.history');
  533. if (!value) {
  534. var databaseStr = localStorage.getItem('database');
  535. if (databaseStr) {
  536. try {
  537. var database = JSON.parse(databaseStr);
  538. if (typeof database.files[0].fingerprint === 'string') {
  539. localStorage.setItem('pdfjs.history', databaseStr);
  540. localStorage.removeItem('database');
  541. value = databaseStr;
  542. }
  543. } catch (ex) {
  544. }
  545. }
  546. }
  547. resolve(value);
  548. });
  549. },
  550. set: function ViewHistory_set(name, val) {
  551. if (!this.isInitializedPromiseResolved) {
  552. return;
  553. }
  554. this.file[name] = val;
  555. return this._writeToStorage();
  556. },
  557. setMultiple: function ViewHistory_setMultiple(properties) {
  558. if (!this.isInitializedPromiseResolved) {
  559. return;
  560. }
  561. for (var name in properties) {
  562. this.file[name] = properties[name];
  563. }
  564. return this._writeToStorage();
  565. },
  566. get: function ViewHistory_get(name, defaultValue) {
  567. if (!this.isInitializedPromiseResolved) {
  568. return defaultValue;
  569. }
  570. return this.file[name] || defaultValue;
  571. }
  572. };
  573. return ViewHistory;
  574. }();
  575. exports.ViewHistory = ViewHistory;
  576. }));
  577. (function (root, factory) {
  578. factory(root.pdfjsWebDownloadManager = {}, root.pdfjsWebPDFJS);
  579. }(this, function (exports, pdfjsLib) {
  580. function download(blobUrl, filename) {
  581. var a = document.createElement('a');
  582. if (a.click) {
  583. a.href = blobUrl;
  584. a.target = '_parent';
  585. if ('download' in a) {
  586. a.download = filename;
  587. }
  588. (document.body || document.documentElement).appendChild(a);
  589. a.click();
  590. a.parentNode.removeChild(a);
  591. } else {
  592. if (window.top === window && blobUrl.split('#')[0] === window.location.href.split('#')[0]) {
  593. var padCharacter = blobUrl.indexOf('?') === -1 ? '?' : '&';
  594. blobUrl = blobUrl.replace(/#|$/, padCharacter + '$&');
  595. }
  596. window.open(blobUrl, '_parent');
  597. }
  598. }
  599. function DownloadManager() {
  600. }
  601. DownloadManager.prototype = {
  602. downloadUrl: function DownloadManager_downloadUrl(url, filename) {
  603. if (!pdfjsLib.createValidAbsoluteUrl(url, 'http://example.com')) {
  604. return;
  605. }
  606. download(url + '#pdfjs.action=download', filename);
  607. },
  608. downloadData: function DownloadManager_downloadData(data, filename, contentType) {
  609. if (navigator.msSaveBlob) {
  610. return navigator.msSaveBlob(new Blob([data], { type: contentType }), filename);
  611. }
  612. var blobUrl = pdfjsLib.createObjectURL(data, contentType, pdfjsLib.PDFJS.disableCreateObjectURL);
  613. download(blobUrl, filename);
  614. },
  615. download: function DownloadManager_download(blob, url, filename) {
  616. if (!URL) {
  617. this.downloadUrl(url, filename);
  618. return;
  619. }
  620. if (navigator.msSaveBlob) {
  621. if (!navigator.msSaveBlob(blob, filename)) {
  622. this.downloadUrl(url, filename);
  623. }
  624. return;
  625. }
  626. var blobUrl = URL.createObjectURL(blob);
  627. download(blobUrl, filename);
  628. }
  629. };
  630. exports.DownloadManager = DownloadManager;
  631. }));
  632. (function (root, factory) {
  633. factory(root.pdfjsWebPDFAttachmentViewer = {}, root.pdfjsWebPDFJS);
  634. }(this, function (exports, pdfjsLib) {
  635. var PDFAttachmentViewer = function PDFAttachmentViewerClosure() {
  636. function PDFAttachmentViewer(options) {
  637. this.attachments = null;
  638. this.container = options.container;
  639. this.eventBus = options.eventBus;
  640. this.downloadManager = options.downloadManager;
  641. }
  642. PDFAttachmentViewer.prototype = {
  643. reset: function PDFAttachmentViewer_reset() {
  644. this.attachments = null;
  645. var container = this.container;
  646. while (container.firstChild) {
  647. container.removeChild(container.firstChild);
  648. }
  649. },
  650. _dispatchEvent: function PDFAttachmentViewer_dispatchEvent(attachmentsCount) {
  651. this.eventBus.dispatch('attachmentsloaded', {
  652. source: this,
  653. attachmentsCount: attachmentsCount
  654. });
  655. },
  656. _bindLink: function PDFAttachmentViewer_bindLink(button, content, filename) {
  657. button.onclick = function downloadFile(e) {
  658. this.downloadManager.downloadData(content, filename, '');
  659. return false;
  660. }.bind(this);
  661. },
  662. render: function PDFAttachmentViewer_render(params) {
  663. var attachments = params && params.attachments || null;
  664. var attachmentsCount = 0;
  665. if (this.attachments) {
  666. this.reset();
  667. }
  668. this.attachments = attachments;
  669. if (!attachments) {
  670. this._dispatchEvent(attachmentsCount);
  671. return;
  672. }
  673. var names = Object.keys(attachments).sort(function (a, b) {
  674. return a.toLowerCase().localeCompare(b.toLowerCase());
  675. });
  676. attachmentsCount = names.length;
  677. for (var i = 0; i < attachmentsCount; i++) {
  678. var item = attachments[names[i]];
  679. var filename = pdfjsLib.getFilenameFromUrl(item.filename);
  680. var div = document.createElement('div');
  681. div.className = 'attachmentsItem';
  682. var button = document.createElement('button');
  683. this._bindLink(button, item.content, filename);
  684. button.textContent = pdfjsLib.removeNullCharacters(filename);
  685. div.appendChild(button);
  686. this.container.appendChild(div);
  687. }
  688. this._dispatchEvent(attachmentsCount);
  689. }
  690. };
  691. return PDFAttachmentViewer;
  692. }();
  693. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  694. }));
  695. (function (root, factory) {
  696. factory(root.pdfjsWebPDFOutlineViewer = {}, root.pdfjsWebPDFJS);
  697. }(this, function (exports, pdfjsLib) {
  698. var PDFJS = pdfjsLib.PDFJS;
  699. var DEFAULT_TITLE = '\u2013';
  700. var PDFOutlineViewer = function PDFOutlineViewerClosure() {
  701. function PDFOutlineViewer(options) {
  702. this.outline = null;
  703. this.lastToggleIsShow = true;
  704. this.container = options.container;
  705. this.linkService = options.linkService;
  706. this.eventBus = options.eventBus;
  707. }
  708. PDFOutlineViewer.prototype = {
  709. reset: function PDFOutlineViewer_reset() {
  710. this.outline = null;
  711. this.lastToggleIsShow = true;
  712. var container = this.container;
  713. while (container.firstChild) {
  714. container.removeChild(container.firstChild);
  715. }
  716. },
  717. _dispatchEvent: function PDFOutlineViewer_dispatchEvent(outlineCount) {
  718. this.eventBus.dispatch('outlineloaded', {
  719. source: this,
  720. outlineCount: outlineCount
  721. });
  722. },
  723. _bindLink: function PDFOutlineViewer_bindLink(element, item) {
  724. if (item.url) {
  725. pdfjsLib.addLinkAttributes(element, {
  726. url: item.url,
  727. target: item.newWindow ? PDFJS.LinkTarget.BLANK : undefined
  728. });
  729. return;
  730. }
  731. var self = this, destination = item.dest;
  732. element.href = self.linkService.getDestinationHash(destination);
  733. element.onclick = function () {
  734. if (destination) {
  735. self.linkService.navigateTo(destination);
  736. }
  737. return false;
  738. };
  739. },
  740. _setStyles: function PDFOutlineViewer_setStyles(element, item) {
  741. var styleStr = '';
  742. if (item.bold) {
  743. styleStr += 'font-weight: bold;';
  744. }
  745. if (item.italic) {
  746. styleStr += 'font-style: italic;';
  747. }
  748. if (styleStr) {
  749. element.setAttribute('style', styleStr);
  750. }
  751. },
  752. _addToggleButton: function PDFOutlineViewer_addToggleButton(div) {
  753. var toggler = document.createElement('div');
  754. toggler.className = 'outlineItemToggler';
  755. toggler.onclick = function (event) {
  756. event.stopPropagation();
  757. toggler.classList.toggle('outlineItemsHidden');
  758. if (event.shiftKey) {
  759. var shouldShowAll = !toggler.classList.contains('outlineItemsHidden');
  760. this._toggleOutlineItem(div, shouldShowAll);
  761. }
  762. }.bind(this);
  763. div.insertBefore(toggler, div.firstChild);
  764. },
  765. _toggleOutlineItem: function PDFOutlineViewer_toggleOutlineItem(root, show) {
  766. this.lastToggleIsShow = show;
  767. var togglers = root.querySelectorAll('.outlineItemToggler');
  768. for (var i = 0, ii = togglers.length; i < ii; ++i) {
  769. togglers[i].classList[show ? 'remove' : 'add']('outlineItemsHidden');
  770. }
  771. },
  772. toggleOutlineTree: function PDFOutlineViewer_toggleOutlineTree() {
  773. if (!this.outline) {
  774. return;
  775. }
  776. this._toggleOutlineItem(this.container, !this.lastToggleIsShow);
  777. },
  778. render: function PDFOutlineViewer_render(params) {
  779. var outline = params && params.outline || null;
  780. var outlineCount = 0;
  781. if (this.outline) {
  782. this.reset();
  783. }
  784. this.outline = outline;
  785. if (!outline) {
  786. this._dispatchEvent(outlineCount);
  787. return;
  788. }
  789. var fragment = document.createDocumentFragment();
  790. var queue = [{
  791. parent: fragment,
  792. items: this.outline
  793. }];
  794. var hasAnyNesting = false;
  795. while (queue.length > 0) {
  796. var levelData = queue.shift();
  797. for (var i = 0, len = levelData.items.length; i < len; i++) {
  798. var item = levelData.items[i];
  799. var div = document.createElement('div');
  800. div.className = 'outlineItem';
  801. var element = document.createElement('a');
  802. this._bindLink(element, item);
  803. this._setStyles(element, item);
  804. element.textContent = pdfjsLib.removeNullCharacters(item.title) || DEFAULT_TITLE;
  805. div.appendChild(element);
  806. if (item.items.length > 0) {
  807. hasAnyNesting = true;
  808. this._addToggleButton(div);
  809. var itemsDiv = document.createElement('div');
  810. itemsDiv.className = 'outlineItems';
  811. div.appendChild(itemsDiv);
  812. queue.push({
  813. parent: itemsDiv,
  814. items: item.items
  815. });
  816. }
  817. levelData.parent.appendChild(div);
  818. outlineCount++;
  819. }
  820. }
  821. if (hasAnyNesting) {
  822. this.container.classList.add('outlineWithDeepNesting');
  823. }
  824. this.container.appendChild(fragment);
  825. this._dispatchEvent(outlineCount);
  826. }
  827. };
  828. return PDFOutlineViewer;
  829. }();
  830. exports.PDFOutlineViewer = PDFOutlineViewer;
  831. }));
  832. (function (root, factory) {
  833. factory(root.pdfjsWebPDFSidebar = {}, root.pdfjsWebPDFRenderingQueue);
  834. }(this, function (exports, pdfRenderingQueue) {
  835. var RenderingStates = pdfRenderingQueue.RenderingStates;
  836. var SidebarView = {
  837. NONE: 0,
  838. THUMBS: 1,
  839. OUTLINE: 2,
  840. ATTACHMENTS: 3
  841. };
  842. var PDFSidebar = function PDFSidebarClosure() {
  843. function PDFSidebar(options) {
  844. this.isOpen = false;
  845. this.active = SidebarView.THUMBS;
  846. this.isInitialViewSet = false;
  847. this.onToggled = null;
  848. this.pdfViewer = options.pdfViewer;
  849. this.pdfThumbnailViewer = options.pdfThumbnailViewer;
  850. this.pdfOutlineViewer = options.pdfOutlineViewer;
  851. this.mainContainer = options.mainContainer;
  852. this.outerContainer = options.outerContainer;
  853. this.eventBus = options.eventBus;
  854. this.toggleButton = options.toggleButton;
  855. this.thumbnailButton = options.thumbnailButton;
  856. this.outlineButton = options.outlineButton;
  857. this.attachmentsButton = options.attachmentsButton;
  858. this.thumbnailView = options.thumbnailView;
  859. this.outlineView = options.outlineView;
  860. this.attachmentsView = options.attachmentsView;
  861. this._addEventListeners();
  862. }
  863. PDFSidebar.prototype = {
  864. reset: function PDFSidebar_reset() {
  865. this.isInitialViewSet = false;
  866. this.close();
  867. this.switchView(SidebarView.THUMBS);
  868. this.outlineButton.disabled = false;
  869. this.attachmentsButton.disabled = false;
  870. },
  871. get visibleView() {
  872. return this.isOpen ? this.active : SidebarView.NONE;
  873. },
  874. get isThumbnailViewVisible() {
  875. return this.isOpen && this.active === SidebarView.THUMBS;
  876. },
  877. get isOutlineViewVisible() {
  878. return this.isOpen && this.active === SidebarView.OUTLINE;
  879. },
  880. get isAttachmentsViewVisible() {
  881. return this.isOpen && this.active === SidebarView.ATTACHMENTS;
  882. },
  883. setInitialView: function PDFSidebar_setInitialView(view) {
  884. if (this.isInitialViewSet) {
  885. return;
  886. }
  887. this.isInitialViewSet = true;
  888. if (this.isOpen && view === SidebarView.NONE) {
  889. this._dispatchEvent();
  890. return;
  891. }
  892. var isViewPreserved = view === this.visibleView;
  893. this.switchView(view, true);
  894. if (isViewPreserved) {
  895. this._dispatchEvent();
  896. }
  897. },
  898. switchView: function PDFSidebar_switchView(view, forceOpen) {
  899. if (view === SidebarView.NONE) {
  900. this.close();
  901. return;
  902. }
  903. var isViewChanged = view !== this.active;
  904. var shouldForceRendering = false;
  905. switch (view) {
  906. case SidebarView.THUMBS:
  907. this.thumbnailButton.classList.add('toggled');
  908. this.outlineButton.classList.remove('toggled');
  909. this.attachmentsButton.classList.remove('toggled');
  910. this.thumbnailView.classList.remove('hidden');
  911. this.outlineView.classList.add('hidden');
  912. this.attachmentsView.classList.add('hidden');
  913. if (this.isOpen && isViewChanged) {
  914. this._updateThumbnailViewer();
  915. shouldForceRendering = true;
  916. }
  917. break;
  918. case SidebarView.OUTLINE:
  919. if (this.outlineButton.disabled) {
  920. return;
  921. }
  922. this.thumbnailButton.classList.remove('toggled');
  923. this.outlineButton.classList.add('toggled');
  924. this.attachmentsButton.classList.remove('toggled');
  925. this.thumbnailView.classList.add('hidden');
  926. this.outlineView.classList.remove('hidden');
  927. this.attachmentsView.classList.add('hidden');
  928. break;
  929. case SidebarView.ATTACHMENTS:
  930. if (this.attachmentsButton.disabled) {
  931. return;
  932. }
  933. this.thumbnailButton.classList.remove('toggled');
  934. this.outlineButton.classList.remove('toggled');
  935. this.attachmentsButton.classList.add('toggled');
  936. this.thumbnailView.classList.add('hidden');
  937. this.outlineView.classList.add('hidden');
  938. this.attachmentsView.classList.remove('hidden');
  939. break;
  940. default:
  941. console.error('PDFSidebar_switchView: "' + view + '" is an unsupported value.');
  942. return;
  943. }
  944. this.active = view | 0;
  945. if (forceOpen && !this.isOpen) {
  946. this.open();
  947. return;
  948. }
  949. if (shouldForceRendering) {
  950. this._forceRendering();
  951. }
  952. if (isViewChanged) {
  953. this._dispatchEvent();
  954. }
  955. },
  956. open: function PDFSidebar_open() {
  957. if (this.isOpen) {
  958. return;
  959. }
  960. this.isOpen = true;
  961. this.toggleButton.classList.add('toggled');
  962. this.outerContainer.classList.add('sidebarMoving');
  963. this.outerContainer.classList.add('sidebarOpen');
  964. if (this.active === SidebarView.THUMBS) {
  965. this._updateThumbnailViewer();
  966. }
  967. this._forceRendering();
  968. this._dispatchEvent();
  969. },
  970. close: function PDFSidebar_close() {
  971. if (!this.isOpen) {
  972. return;
  973. }
  974. this.isOpen = false;
  975. this.toggleButton.classList.remove('toggled');
  976. this.outerContainer.classList.add('sidebarMoving');
  977. this.outerContainer.classList.remove('sidebarOpen');
  978. this._forceRendering();
  979. this._dispatchEvent();
  980. },
  981. toggle: function PDFSidebar_toggle() {
  982. if (this.isOpen) {
  983. this.close();
  984. } else {
  985. this.open();
  986. }
  987. },
  988. _dispatchEvent: function PDFSidebar_dispatchEvent() {
  989. this.eventBus.dispatch('sidebarviewchanged', {
  990. source: this,
  991. view: this.visibleView
  992. });
  993. },
  994. _forceRendering: function PDFSidebar_forceRendering() {
  995. if (this.onToggled) {
  996. this.onToggled();
  997. } else {
  998. this.pdfViewer.forceRendering();
  999. this.pdfThumbnailViewer.forceRendering();
  1000. }
  1001. },
  1002. _updateThumbnailViewer: function PDFSidebar_updateThumbnailViewer() {
  1003. var pdfViewer = this.pdfViewer;
  1004. var thumbnailViewer = this.pdfThumbnailViewer;
  1005. var pagesCount = pdfViewer.pagesCount;
  1006. for (var pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  1007. var pageView = pdfViewer.getPageView(pageIndex);
  1008. if (pageView && pageView.renderingState === RenderingStates.FINISHED) {
  1009. var thumbnailView = thumbnailViewer.getThumbnail(pageIndex);
  1010. thumbnailView.setImage(pageView);
  1011. }
  1012. }
  1013. thumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  1014. },
  1015. _addEventListeners: function PDFSidebar_addEventListeners() {
  1016. var self = this;
  1017. self.mainContainer.addEventListener('transitionend', function (evt) {
  1018. if (evt.target === this) {
  1019. self.outerContainer.classList.remove('sidebarMoving');
  1020. }
  1021. });
  1022. self.thumbnailButton.addEventListener('click', function () {
  1023. self.switchView(SidebarView.THUMBS);
  1024. });
  1025. self.outlineButton.addEventListener('click', function () {
  1026. self.switchView(SidebarView.OUTLINE);
  1027. });
  1028. self.outlineButton.addEventListener('dblclick', function () {
  1029. self.pdfOutlineViewer.toggleOutlineTree();
  1030. });
  1031. self.attachmentsButton.addEventListener('click', function () {
  1032. self.switchView(SidebarView.ATTACHMENTS);
  1033. });
  1034. self.eventBus.on('outlineloaded', function (e) {
  1035. var outlineCount = e.outlineCount;
  1036. self.outlineButton.disabled = !outlineCount;
  1037. if (!outlineCount && self.active === SidebarView.OUTLINE) {
  1038. self.switchView(SidebarView.THUMBS);
  1039. }
  1040. });
  1041. self.eventBus.on('attachmentsloaded', function (e) {
  1042. var attachmentsCount = e.attachmentsCount;
  1043. self.attachmentsButton.disabled = !attachmentsCount;
  1044. if (!attachmentsCount && self.active === SidebarView.ATTACHMENTS) {
  1045. self.switchView(SidebarView.THUMBS);
  1046. }
  1047. });
  1048. self.eventBus.on('presentationmodechanged', function (e) {
  1049. if (!e.active && !e.switchInProgress && self.isThumbnailViewVisible) {
  1050. self._updateThumbnailViewer();
  1051. }
  1052. });
  1053. }
  1054. };
  1055. return PDFSidebar;
  1056. }();
  1057. exports.SidebarView = SidebarView;
  1058. exports.PDFSidebar = PDFSidebar;
  1059. }));
  1060. (function (root, factory) {
  1061. factory(root.pdfjsWebUIUtils = {}, root.pdfjsWebPDFJS);
  1062. }(this, function (exports, pdfjsLib) {
  1063. var CSS_UNITS = 96.0 / 72.0;
  1064. var DEFAULT_SCALE_VALUE = 'auto';
  1065. var DEFAULT_SCALE = 1.0;
  1066. var MIN_SCALE = 0.25;
  1067. var MAX_SCALE = 10.0;
  1068. var UNKNOWN_SCALE = 0;
  1069. var MAX_AUTO_SCALE = 1.25;
  1070. var SCROLLBAR_PADDING = 40;
  1071. var VERTICAL_PADDING = 5;
  1072. var RendererType = {
  1073. CANVAS: 'canvas',
  1074. SVG: 'svg'
  1075. };
  1076. var mozL10n = document.mozL10n || document.webL10n;
  1077. var PDFJS = pdfjsLib.PDFJS;
  1078. PDFJS.disableFullscreen = PDFJS.disableFullscreen === undefined ? false : PDFJS.disableFullscreen;
  1079. PDFJS.useOnlyCssZoom = PDFJS.useOnlyCssZoom === undefined ? false : PDFJS.useOnlyCssZoom;
  1080. PDFJS.maxCanvasPixels = PDFJS.maxCanvasPixels === undefined ? 16777216 : PDFJS.maxCanvasPixels;
  1081. PDFJS.disableHistory = PDFJS.disableHistory === undefined ? false : PDFJS.disableHistory;
  1082. PDFJS.disableTextLayer = PDFJS.disableTextLayer === undefined ? false : PDFJS.disableTextLayer;
  1083. PDFJS.ignoreCurrentPositionOnZoom = PDFJS.ignoreCurrentPositionOnZoom === undefined ? false : PDFJS.ignoreCurrentPositionOnZoom;
  1084. PDFJS.locale = PDFJS.locale === undefined ? navigator.language : PDFJS.locale;
  1085. function getOutputScale(ctx) {
  1086. var devicePixelRatio = window.devicePixelRatio || 1;
  1087. var backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  1088. var pixelRatio = devicePixelRatio / backingStoreRatio;
  1089. return {
  1090. sx: pixelRatio,
  1091. sy: pixelRatio,
  1092. scaled: pixelRatio !== 1
  1093. };
  1094. }
  1095. function scrollIntoView(element, spot, skipOverflowHiddenElements) {
  1096. var parent = element.offsetParent;
  1097. if (!parent) {
  1098. console.error('offsetParent is not set -- cannot scroll');
  1099. return;
  1100. }
  1101. var checkOverflow = skipOverflowHiddenElements || false;
  1102. var offsetY = element.offsetTop + element.clientTop;
  1103. var offsetX = element.offsetLeft + element.clientLeft;
  1104. while (parent.clientHeight === parent.scrollHeight || checkOverflow && getComputedStyle(parent).overflow === 'hidden') {
  1105. if (parent.dataset._scaleY) {
  1106. offsetY /= parent.dataset._scaleY;
  1107. offsetX /= parent.dataset._scaleX;
  1108. }
  1109. offsetY += parent.offsetTop;
  1110. offsetX += parent.offsetLeft;
  1111. parent = parent.offsetParent;
  1112. if (!parent) {
  1113. return;
  1114. }
  1115. }
  1116. if (spot) {
  1117. if (spot.top !== undefined) {
  1118. offsetY += spot.top;
  1119. }
  1120. if (spot.left !== undefined) {
  1121. offsetX += spot.left;
  1122. parent.scrollLeft = offsetX;
  1123. }
  1124. }
  1125. parent.scrollTop = offsetY;
  1126. }
  1127. function watchScroll(viewAreaElement, callback) {
  1128. var debounceScroll = function debounceScroll(evt) {
  1129. if (rAF) {
  1130. return;
  1131. }
  1132. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  1133. rAF = null;
  1134. var currentY = viewAreaElement.scrollTop;
  1135. var lastY = state.lastY;
  1136. if (currentY !== lastY) {
  1137. state.down = currentY > lastY;
  1138. }
  1139. state.lastY = currentY;
  1140. callback(state);
  1141. });
  1142. };
  1143. var state = {
  1144. down: true,
  1145. lastY: viewAreaElement.scrollTop,
  1146. _eventHandler: debounceScroll
  1147. };
  1148. var rAF = null;
  1149. viewAreaElement.addEventListener('scroll', debounceScroll, true);
  1150. return state;
  1151. }
  1152. function parseQueryString(query) {
  1153. var parts = query.split('&');
  1154. var params = {};
  1155. for (var i = 0, ii = parts.length; i < ii; ++i) {
  1156. var param = parts[i].split('=');
  1157. var key = param[0].toLowerCase();
  1158. var value = param.length > 1 ? param[1] : null;
  1159. params[decodeURIComponent(key)] = decodeURIComponent(value);
  1160. }
  1161. return params;
  1162. }
  1163. function binarySearchFirstItem(items, condition) {
  1164. var minIndex = 0;
  1165. var maxIndex = items.length - 1;
  1166. if (items.length === 0 || !condition(items[maxIndex])) {
  1167. return items.length;
  1168. }
  1169. if (condition(items[minIndex])) {
  1170. return minIndex;
  1171. }
  1172. while (minIndex < maxIndex) {
  1173. var currentIndex = minIndex + maxIndex >> 1;
  1174. var currentItem = items[currentIndex];
  1175. if (condition(currentItem)) {
  1176. maxIndex = currentIndex;
  1177. } else {
  1178. minIndex = currentIndex + 1;
  1179. }
  1180. }
  1181. return minIndex;
  1182. }
  1183. function approximateFraction(x) {
  1184. if (Math.floor(x) === x) {
  1185. return [
  1186. x,
  1187. 1
  1188. ];
  1189. }
  1190. var xinv = 1 / x;
  1191. var limit = 8;
  1192. if (xinv > limit) {
  1193. return [
  1194. 1,
  1195. limit
  1196. ];
  1197. } else if (Math.floor(xinv) === xinv) {
  1198. return [
  1199. 1,
  1200. xinv
  1201. ];
  1202. }
  1203. var x_ = x > 1 ? xinv : x;
  1204. var a = 0, b = 1, c = 1, d = 1;
  1205. while (true) {
  1206. var p = a + c, q = b + d;
  1207. if (q > limit) {
  1208. break;
  1209. }
  1210. if (x_ <= p / q) {
  1211. c = p;
  1212. d = q;
  1213. } else {
  1214. a = p;
  1215. b = q;
  1216. }
  1217. }
  1218. var result;
  1219. if (x_ - a / b < c / d - x_) {
  1220. result = x_ === x ? [
  1221. a,
  1222. b
  1223. ] : [
  1224. b,
  1225. a
  1226. ];
  1227. } else {
  1228. result = x_ === x ? [
  1229. c,
  1230. d
  1231. ] : [
  1232. d,
  1233. c
  1234. ];
  1235. }
  1236. return result;
  1237. }
  1238. function roundToDivide(x, div) {
  1239. var r = x % div;
  1240. return r === 0 ? x : Math.round(x - r + div);
  1241. }
  1242. function getVisibleElements(scrollEl, views, sortByVisibility) {
  1243. var top = scrollEl.scrollTop, bottom = top + scrollEl.clientHeight;
  1244. var left = scrollEl.scrollLeft, right = left + scrollEl.clientWidth;
  1245. function isElementBottomBelowViewTop(view) {
  1246. var element = view.div;
  1247. var elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  1248. return elementBottom > top;
  1249. }
  1250. var visible = [], view, element;
  1251. var currentHeight, viewHeight, hiddenHeight, percentHeight;
  1252. var currentWidth, viewWidth;
  1253. var firstVisibleElementInd = views.length === 0 ? 0 : binarySearchFirstItem(views, isElementBottomBelowViewTop);
  1254. for (var i = firstVisibleElementInd, ii = views.length; i < ii; i++) {
  1255. view = views[i];
  1256. element = view.div;
  1257. currentHeight = element.offsetTop + element.clientTop;
  1258. viewHeight = element.clientHeight;
  1259. if (currentHeight > bottom) {
  1260. break;
  1261. }
  1262. currentWidth = element.offsetLeft + element.clientLeft;
  1263. viewWidth = element.clientWidth;
  1264. if (currentWidth + viewWidth < left || currentWidth > right) {
  1265. continue;
  1266. }
  1267. hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, currentHeight + viewHeight - bottom);
  1268. percentHeight = (viewHeight - hiddenHeight) * 100 / viewHeight | 0;
  1269. visible.push({
  1270. id: view.id,
  1271. x: currentWidth,
  1272. y: currentHeight,
  1273. view: view,
  1274. percent: percentHeight
  1275. });
  1276. }
  1277. var first = visible[0];
  1278. var last = visible[visible.length - 1];
  1279. if (sortByVisibility) {
  1280. visible.sort(function (a, b) {
  1281. var pc = a.percent - b.percent;
  1282. if (Math.abs(pc) > 0.001) {
  1283. return -pc;
  1284. }
  1285. return a.id - b.id;
  1286. });
  1287. }
  1288. return {
  1289. first: first,
  1290. last: last,
  1291. views: visible
  1292. };
  1293. }
  1294. function noContextMenuHandler(e) {
  1295. e.preventDefault();
  1296. }
  1297. function getPDFFileNameFromURL(url) {
  1298. var reURI = /^(?:([^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  1299. var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  1300. var splitURI = reURI.exec(url);
  1301. var suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  1302. if (suggestedFilename) {
  1303. suggestedFilename = suggestedFilename[0];
  1304. if (suggestedFilename.indexOf('%') !== -1) {
  1305. try {
  1306. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  1307. } catch (e) {
  1308. }
  1309. }
  1310. }
  1311. return suggestedFilename || 'document.pdf';
  1312. }
  1313. function normalizeWheelEventDelta(evt) {
  1314. var delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
  1315. var angle = Math.atan2(evt.deltaY, evt.deltaX);
  1316. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  1317. delta = -delta;
  1318. }
  1319. var MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  1320. var MOUSE_DOM_DELTA_LINE_MODE = 1;
  1321. var MOUSE_PIXELS_PER_LINE = 30;
  1322. var MOUSE_LINES_PER_PAGE = 30;
  1323. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  1324. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  1325. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  1326. delta /= MOUSE_LINES_PER_PAGE;
  1327. }
  1328. return delta;
  1329. }
  1330. var animationStarted = new Promise(function (resolve) {
  1331. window.requestAnimationFrame(resolve);
  1332. });
  1333. var localized = new Promise(function (resolve, reject) {
  1334. if (!mozL10n) {
  1335. resolve();
  1336. return;
  1337. }
  1338. if (mozL10n.getReadyState() !== 'loading') {
  1339. resolve();
  1340. return;
  1341. }
  1342. window.addEventListener('localized', function localized(evt) {
  1343. resolve();
  1344. });
  1345. });
  1346. var EventBus = function EventBusClosure() {
  1347. function EventBus() {
  1348. this._listeners = Object.create(null);
  1349. }
  1350. EventBus.prototype = {
  1351. on: function EventBus_on(eventName, listener) {
  1352. var eventListeners = this._listeners[eventName];
  1353. if (!eventListeners) {
  1354. eventListeners = [];
  1355. this._listeners[eventName] = eventListeners;
  1356. }
  1357. eventListeners.push(listener);
  1358. },
  1359. off: function EventBus_on(eventName, listener) {
  1360. var eventListeners = this._listeners[eventName];
  1361. var i;
  1362. if (!eventListeners || (i = eventListeners.indexOf(listener)) < 0) {
  1363. return;
  1364. }
  1365. eventListeners.splice(i, 1);
  1366. },
  1367. dispatch: function EventBus_dispath(eventName) {
  1368. var eventListeners = this._listeners[eventName];
  1369. if (!eventListeners || eventListeners.length === 0) {
  1370. return;
  1371. }
  1372. var args = Array.prototype.slice.call(arguments, 1);
  1373. eventListeners.slice(0).forEach(function (listener) {
  1374. listener.apply(null, args);
  1375. });
  1376. }
  1377. };
  1378. return EventBus;
  1379. }();
  1380. var ProgressBar = function ProgressBarClosure() {
  1381. function clamp(v, min, max) {
  1382. return Math.min(Math.max(v, min), max);
  1383. }
  1384. function ProgressBar(id, opts) {
  1385. this.visible = true;
  1386. this.div = document.querySelector(id + ' .progress');
  1387. this.bar = this.div.parentNode;
  1388. this.height = opts.height || 100;
  1389. this.width = opts.width || 100;
  1390. this.units = opts.units || '%';
  1391. this.div.style.height = this.height + this.units;
  1392. this.percent = 0;
  1393. }
  1394. ProgressBar.prototype = {
  1395. updateBar: function ProgressBar_updateBar() {
  1396. if (this._indeterminate) {
  1397. this.div.classList.add('indeterminate');
  1398. this.div.style.width = this.width + this.units;
  1399. return;
  1400. }
  1401. this.div.classList.remove('indeterminate');
  1402. var progressSize = this.width * this._percent / 100;
  1403. this.div.style.width = progressSize + this.units;
  1404. },
  1405. get percent() {
  1406. return this._percent;
  1407. },
  1408. set percent(val) {
  1409. this._indeterminate = isNaN(val);
  1410. this._percent = clamp(val, 0, 100);
  1411. this.updateBar();
  1412. },
  1413. setWidth: function ProgressBar_setWidth(viewer) {
  1414. if (viewer) {
  1415. var container = viewer.parentNode;
  1416. var scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  1417. if (scrollbarWidth > 0) {
  1418. this.bar.setAttribute('style', 'width: calc(100% - ' + scrollbarWidth + 'px);');
  1419. }
  1420. }
  1421. },
  1422. hide: function ProgressBar_hide() {
  1423. if (!this.visible) {
  1424. return;
  1425. }
  1426. this.visible = false;
  1427. this.bar.classList.add('hidden');
  1428. document.body.classList.remove('loadingInProgress');
  1429. },
  1430. show: function ProgressBar_show() {
  1431. if (this.visible) {
  1432. return;
  1433. }
  1434. this.visible = true;
  1435. document.body.classList.add('loadingInProgress');
  1436. this.bar.classList.remove('hidden');
  1437. }
  1438. };
  1439. return ProgressBar;
  1440. }();
  1441. exports.CSS_UNITS = CSS_UNITS;
  1442. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  1443. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  1444. exports.MIN_SCALE = MIN_SCALE;
  1445. exports.MAX_SCALE = MAX_SCALE;
  1446. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  1447. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  1448. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  1449. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  1450. exports.RendererType = RendererType;
  1451. exports.mozL10n = mozL10n;
  1452. exports.EventBus = EventBus;
  1453. exports.ProgressBar = ProgressBar;
  1454. exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
  1455. exports.noContextMenuHandler = noContextMenuHandler;
  1456. exports.parseQueryString = parseQueryString;
  1457. exports.getVisibleElements = getVisibleElements;
  1458. exports.roundToDivide = roundToDivide;
  1459. exports.approximateFraction = approximateFraction;
  1460. exports.getOutputScale = getOutputScale;
  1461. exports.scrollIntoView = scrollIntoView;
  1462. exports.watchScroll = watchScroll;
  1463. exports.binarySearchFirstItem = binarySearchFirstItem;
  1464. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  1465. exports.animationStarted = animationStarted;
  1466. exports.localized = localized;
  1467. }));
  1468. (function (root, factory) {
  1469. factory(root.pdfjsWebDOMEvents = {}, root.pdfjsWebUIUtils);
  1470. }(this, function (exports, uiUtils) {
  1471. var EventBus = uiUtils.EventBus;
  1472. function attachDOMEventsToEventBus(eventBus) {
  1473. eventBus.on('documentload', function () {
  1474. var event = document.createEvent('CustomEvent');
  1475. event.initCustomEvent('documentload', true, true, {});
  1476. window.dispatchEvent(event);
  1477. });
  1478. eventBus.on('pagerendered', function (e) {
  1479. var event = document.createEvent('CustomEvent');
  1480. event.initCustomEvent('pagerendered', true, true, {
  1481. pageNumber: e.pageNumber,
  1482. cssTransform: e.cssTransform
  1483. });
  1484. e.source.div.dispatchEvent(event);
  1485. });
  1486. eventBus.on('textlayerrendered', function (e) {
  1487. var event = document.createEvent('CustomEvent');
  1488. event.initCustomEvent('textlayerrendered', true, true, { pageNumber: e.pageNumber });
  1489. e.source.textLayerDiv.dispatchEvent(event);
  1490. });
  1491. eventBus.on('pagechange', function (e) {
  1492. var event = document.createEvent('UIEvents');
  1493. event.initUIEvent('pagechange', true, true, window, 0);
  1494. event.pageNumber = e.pageNumber;
  1495. e.source.container.dispatchEvent(event);
  1496. });
  1497. eventBus.on('pagesinit', function (e) {
  1498. var event = document.createEvent('CustomEvent');
  1499. event.initCustomEvent('pagesinit', true, true, null);
  1500. e.source.container.dispatchEvent(event);
  1501. });
  1502. eventBus.on('pagesloaded', function (e) {
  1503. var event = document.createEvent('CustomEvent');
  1504. event.initCustomEvent('pagesloaded', true, true, { pagesCount: e.pagesCount });
  1505. e.source.container.dispatchEvent(event);
  1506. });
  1507. eventBus.on('scalechange', function (e) {
  1508. var event = document.createEvent('UIEvents');
  1509. event.initUIEvent('scalechange', true, true, window, 0);
  1510. event.scale = e.scale;
  1511. event.presetValue = e.presetValue;
  1512. e.source.container.dispatchEvent(event);
  1513. });
  1514. eventBus.on('updateviewarea', function (e) {
  1515. var event = document.createEvent('UIEvents');
  1516. event.initUIEvent('updateviewarea', true, true, window, 0);
  1517. event.location = e.location;
  1518. e.source.container.dispatchEvent(event);
  1519. });
  1520. eventBus.on('find', function (e) {
  1521. if (e.source === window) {
  1522. return;
  1523. }
  1524. var event = document.createEvent('CustomEvent');
  1525. event.initCustomEvent('find' + e.type, true, true, {
  1526. query: e.query,
  1527. phraseSearch: e.phraseSearch,
  1528. caseSensitive: e.caseSensitive,
  1529. highlightAll: e.highlightAll,
  1530. findPrevious: e.findPrevious
  1531. });
  1532. window.dispatchEvent(event);
  1533. });
  1534. eventBus.on('attachmentsloaded', function (e) {
  1535. var event = document.createEvent('CustomEvent');
  1536. event.initCustomEvent('attachmentsloaded', true, true, { attachmentsCount: e.attachmentsCount });
  1537. e.source.container.dispatchEvent(event);
  1538. });
  1539. eventBus.on('sidebarviewchanged', function (e) {
  1540. var event = document.createEvent('CustomEvent');
  1541. event.initCustomEvent('sidebarviewchanged', true, true, { view: e.view });
  1542. e.source.outerContainer.dispatchEvent(event);
  1543. });
  1544. eventBus.on('pagemode', function (e) {
  1545. var event = document.createEvent('CustomEvent');
  1546. event.initCustomEvent('pagemode', true, true, { mode: e.mode });
  1547. e.source.pdfViewer.container.dispatchEvent(event);
  1548. });
  1549. eventBus.on('namedaction', function (e) {
  1550. var event = document.createEvent('CustomEvent');
  1551. event.initCustomEvent('namedaction', true, true, { action: e.action });
  1552. e.source.pdfViewer.container.dispatchEvent(event);
  1553. });
  1554. eventBus.on('presentationmodechanged', function (e) {
  1555. var event = document.createEvent('CustomEvent');
  1556. event.initCustomEvent('presentationmodechanged', true, true, {
  1557. active: e.active,
  1558. switchInProgress: e.switchInProgress
  1559. });
  1560. window.dispatchEvent(event);
  1561. });
  1562. eventBus.on('outlineloaded', function (e) {
  1563. var event = document.createEvent('CustomEvent');
  1564. event.initCustomEvent('outlineloaded', true, true, { outlineCount: e.outlineCount });
  1565. e.source.container.dispatchEvent(event);
  1566. });
  1567. }
  1568. var globalEventBus = null;
  1569. function getGlobalEventBus() {
  1570. if (globalEventBus) {
  1571. return globalEventBus;
  1572. }
  1573. globalEventBus = new EventBus();
  1574. attachDOMEventsToEventBus(globalEventBus);
  1575. return globalEventBus;
  1576. }
  1577. exports.attachDOMEventsToEventBus = attachDOMEventsToEventBus;
  1578. exports.getGlobalEventBus = getGlobalEventBus;
  1579. }));
  1580. (function (root, factory) {
  1581. factory(root.pdfjsWebHandTool = {}, root.pdfjsWebGrabToPan, root.pdfjsWebPreferences, root.pdfjsWebUIUtils);
  1582. }(this, function (exports, grabToPan, preferences, uiUtils) {
  1583. var GrabToPan = grabToPan.GrabToPan;
  1584. var Preferences = preferences.Preferences;
  1585. var localized = uiUtils.localized;
  1586. var HandTool = function HandToolClosure() {
  1587. function HandTool(options) {
  1588. this.container = options.container;
  1589. this.eventBus = options.eventBus;
  1590. this.wasActive = false;
  1591. this.handTool = new GrabToPan({
  1592. element: this.container,
  1593. onActiveChanged: function (isActive) {
  1594. this.eventBus.dispatch('handtoolchanged', { isActive: isActive });
  1595. }.bind(this)
  1596. });
  1597. this.eventBus.on('togglehandtool', this.toggle.bind(this));
  1598. Promise.all([
  1599. localized,
  1600. Preferences.get('enableHandToolOnLoad')
  1601. ]).then(function resolved(values) {
  1602. if (values[1] === true) {
  1603. this.handTool.activate();
  1604. }
  1605. }.bind(this)).catch(function rejected(reason) {
  1606. });
  1607. this.eventBus.on('presentationmodechanged', function (e) {
  1608. if (e.switchInProgress) {
  1609. return;
  1610. }
  1611. if (e.active) {
  1612. this.enterPresentationMode();
  1613. } else {
  1614. this.exitPresentationMode();
  1615. }
  1616. }.bind(this));
  1617. }
  1618. HandTool.prototype = {
  1619. get isActive() {
  1620. return !!this.handTool.active;
  1621. },
  1622. toggle: function HandTool_toggle() {
  1623. this.handTool.toggle();
  1624. },
  1625. enterPresentationMode: function HandTool_enterPresentationMode() {
  1626. if (this.isActive) {
  1627. this.wasActive = true;
  1628. this.handTool.deactivate();
  1629. }
  1630. },
  1631. exitPresentationMode: function HandTool_exitPresentationMode() {
  1632. if (this.wasActive) {
  1633. this.wasActive = false;
  1634. this.handTool.activate();
  1635. }
  1636. }
  1637. };
  1638. return HandTool;
  1639. }();
  1640. exports.HandTool = HandTool;
  1641. }));
  1642. (function (root, factory) {
  1643. factory(root.pdfjsWebPasswordPrompt = {}, root.pdfjsWebUIUtils, root.pdfjsWebOverlayManager, root.pdfjsWebPDFJS);
  1644. }(this, function (exports, uiUtils, overlayManager, pdfjsLib) {
  1645. var mozL10n = uiUtils.mozL10n;
  1646. var OverlayManager = overlayManager.OverlayManager;
  1647. var PasswordPrompt = function PasswordPromptClosure() {
  1648. function PasswordPrompt(options) {
  1649. this.overlayName = options.overlayName;
  1650. this.container = options.container;
  1651. this.label = options.label;
  1652. this.input = options.input;
  1653. this.submitButton = options.submitButton;
  1654. this.cancelButton = options.cancelButton;
  1655. this.updateCallback = null;
  1656. this.reason = null;
  1657. this.submitButton.addEventListener('click', this.verify.bind(this));
  1658. this.cancelButton.addEventListener('click', this.close.bind(this));
  1659. this.input.addEventListener('keydown', function (e) {
  1660. if (e.keyCode === 13) {
  1661. this.verify();
  1662. }
  1663. }.bind(this));
  1664. OverlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  1665. }
  1666. PasswordPrompt.prototype = {
  1667. open: function PasswordPrompt_open() {
  1668. OverlayManager.open(this.overlayName).then(function () {
  1669. this.input.type = 'password';
  1670. this.input.focus();
  1671. var promptString = mozL10n.get('password_label', null, 'Enter the password to open this PDF file.');
  1672. if (this.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
  1673. promptString = mozL10n.get('password_invalid', null, 'Invalid password. Please try again.');
  1674. }
  1675. this.label.textContent = promptString;
  1676. }.bind(this));
  1677. },
  1678. close: function PasswordPrompt_close() {
  1679. OverlayManager.close(this.overlayName).then(function () {
  1680. this.input.value = '';
  1681. this.input.type = '';
  1682. }.bind(this));
  1683. },
  1684. verify: function PasswordPrompt_verify() {
  1685. var password = this.input.value;
  1686. if (password && password.length > 0) {
  1687. this.close();
  1688. return this.updateCallback(password);
  1689. }
  1690. },
  1691. setUpdateCallback: function PasswordPrompt_setUpdateCallback(updateCallback, reason) {
  1692. this.updateCallback = updateCallback;
  1693. this.reason = reason;
  1694. }
  1695. };
  1696. return PasswordPrompt;
  1697. }();
  1698. exports.PasswordPrompt = PasswordPrompt;
  1699. }));
  1700. (function (root, factory) {
  1701. factory(root.pdfjsWebPDFDocumentProperties = {}, root.pdfjsWebUIUtils, root.pdfjsWebOverlayManager);
  1702. }(this, function (exports, uiUtils, overlayManager) {
  1703. var getPDFFileNameFromURL = uiUtils.getPDFFileNameFromURL;
  1704. var mozL10n = uiUtils.mozL10n;
  1705. var OverlayManager = overlayManager.OverlayManager;
  1706. var PDFDocumentProperties = function PDFDocumentPropertiesClosure() {
  1707. function PDFDocumentProperties(options) {
  1708. this.fields = options.fields;
  1709. this.overlayName = options.overlayName;
  1710. this.container = options.container;
  1711. this.rawFileSize = 0;
  1712. this.url = null;
  1713. this.pdfDocument = null;
  1714. if (options.closeButton) {
  1715. options.closeButton.addEventListener('click', this.close.bind(this));
  1716. }
  1717. this.dataAvailablePromise = new Promise(function (resolve) {
  1718. this.resolveDataAvailable = resolve;
  1719. }.bind(this));
  1720. OverlayManager.register(this.overlayName, this.container, this.close.bind(this));
  1721. }
  1722. PDFDocumentProperties.prototype = {
  1723. open: function PDFDocumentProperties_open() {
  1724. Promise.all([
  1725. OverlayManager.open(this.overlayName),
  1726. this.dataAvailablePromise
  1727. ]).then(function () {
  1728. this._getProperties();
  1729. }.bind(this));
  1730. },
  1731. close: function PDFDocumentProperties_close() {
  1732. OverlayManager.close(this.overlayName);
  1733. },
  1734. setFileSize: function PDFDocumentProperties_setFileSize(fileSize) {
  1735. if (fileSize > 0) {
  1736. this.rawFileSize = fileSize;
  1737. }
  1738. },
  1739. setDocumentAndUrl: function PDFDocumentProperties_setDocumentAndUrl(pdfDocument, url) {
  1740. this.pdfDocument = pdfDocument;
  1741. this.url = url;
  1742. this.resolveDataAvailable();
  1743. },
  1744. _getProperties: function PDFDocumentProperties_getProperties() {
  1745. if (!OverlayManager.active) {
  1746. return;
  1747. }
  1748. this.pdfDocument.getDownloadInfo().then(function (data) {
  1749. if (data.length === this.rawFileSize) {
  1750. return;
  1751. }
  1752. this.setFileSize(data.length);
  1753. this._updateUI(this.fields['fileSize'], this._parseFileSize());
  1754. }.bind(this));
  1755. this.pdfDocument.getMetadata().then(function (data) {
  1756. var content = {
  1757. 'fileName': getPDFFileNameFromURL(this.url),
  1758. 'fileSize': this._parseFileSize(),
  1759. 'title': data.info.Title,
  1760. 'author': data.info.Author,
  1761. 'subject': data.info.Subject,
  1762. 'keywords': data.info.Keywords,
  1763. 'creationDate': this._parseDate(data.info.CreationDate),
  1764. 'modificationDate': this._parseDate(data.info.ModDate),
  1765. 'creator': data.info.Creator,
  1766. 'producer': data.info.Producer,
  1767. 'version': data.info.PDFFormatVersion,
  1768. 'pageCount': this.pdfDocument.numPages
  1769. };
  1770. for (var identifier in content) {
  1771. this._updateUI(this.fields[identifier], content[identifier]);
  1772. }
  1773. }.bind(this));
  1774. },
  1775. _updateUI: function PDFDocumentProperties_updateUI(field, content) {
  1776. if (field && content !== undefined && content !== '') {
  1777. field.textContent = content;
  1778. }
  1779. },
  1780. _parseFileSize: function PDFDocumentProperties_parseFileSize() {
  1781. var fileSize = this.rawFileSize, kb = fileSize / 1024;
  1782. if (!kb) {
  1783. return;
  1784. } else if (kb < 1024) {
  1785. return mozL10n.get('document_properties_kb', {
  1786. size_kb: (+kb.toPrecision(3)).toLocaleString(),
  1787. size_b: fileSize.toLocaleString()
  1788. }, '{{size_kb}} KB ({{size_b}} bytes)');
  1789. }
  1790. return mozL10n.get('document_properties_mb', {
  1791. size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
  1792. size_b: fileSize.toLocaleString()
  1793. }, '{{size_mb}} MB ({{size_b}} bytes)');
  1794. },
  1795. _parseDate: function PDFDocumentProperties_parseDate(inputDate) {
  1796. var dateToParse = inputDate;
  1797. if (dateToParse === undefined) {
  1798. return '';
  1799. }
  1800. if (dateToParse.substring(0, 2) === 'D:') {
  1801. dateToParse = dateToParse.substring(2);
  1802. }
  1803. var year = parseInt(dateToParse.substring(0, 4), 10);
  1804. var month = parseInt(dateToParse.substring(4, 6), 10) - 1;
  1805. var day = parseInt(dateToParse.substring(6, 8), 10);
  1806. var hours = parseInt(dateToParse.substring(8, 10), 10);
  1807. var minutes = parseInt(dateToParse.substring(10, 12), 10);
  1808. var seconds = parseInt(dateToParse.substring(12, 14), 10);
  1809. var utRel = dateToParse.substring(14, 15);
  1810. var offsetHours = parseInt(dateToParse.substring(15, 17), 10);
  1811. var offsetMinutes = parseInt(dateToParse.substring(18, 20), 10);
  1812. if (utRel === '-') {
  1813. hours += offsetHours;
  1814. minutes += offsetMinutes;
  1815. } else if (utRel === '+') {
  1816. hours -= offsetHours;
  1817. minutes -= offsetMinutes;
  1818. }
  1819. var date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
  1820. var dateString = date.toLocaleDateString();
  1821. var timeString = date.toLocaleTimeString();
  1822. return mozL10n.get('document_properties_date_string', {
  1823. date: dateString,
  1824. time: timeString
  1825. }, '{{date}}, {{time}}');
  1826. }
  1827. };
  1828. return PDFDocumentProperties;
  1829. }();
  1830. exports.PDFDocumentProperties = PDFDocumentProperties;
  1831. }));
  1832. (function (root, factory) {
  1833. factory(root.pdfjsWebPDFFindController = {}, root.pdfjsWebUIUtils);
  1834. }(this, function (exports, uiUtils) {
  1835. var scrollIntoView = uiUtils.scrollIntoView;
  1836. var FindStates = {
  1837. FIND_FOUND: 0,
  1838. FIND_NOTFOUND: 1,
  1839. FIND_WRAPPED: 2,
  1840. FIND_PENDING: 3
  1841. };
  1842. var FIND_SCROLL_OFFSET_TOP = -50;
  1843. var FIND_SCROLL_OFFSET_LEFT = -400;
  1844. var CHARACTERS_TO_NORMALIZE = {
  1845. '\u2018': '\'',
  1846. '\u2019': '\'',
  1847. '\u201A': '\'',
  1848. '\u201B': '\'',
  1849. '\u201C': '"',
  1850. '\u201D': '"',
  1851. '\u201E': '"',
  1852. '\u201F': '"',
  1853. '\u00BC': '1/4',
  1854. '\u00BD': '1/2',
  1855. '\u00BE': '3/4'
  1856. };
  1857. var PDFFindController = function PDFFindControllerClosure() {
  1858. function PDFFindController(options) {
  1859. this.pdfViewer = options.pdfViewer || null;
  1860. this.onUpdateResultsCount = null;
  1861. this.onUpdateState = null;
  1862. this.reset();
  1863. var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
  1864. this.normalizationRegex = new RegExp('[' + replace + ']', 'g');
  1865. }
  1866. PDFFindController.prototype = {
  1867. reset: function PDFFindController_reset() {
  1868. this.startedTextExtraction = false;
  1869. this.extractTextPromises = [];
  1870. this.pendingFindMatches = Object.create(null);
  1871. this.active = false;
  1872. this.pageContents = [];
  1873. this.pageMatches = [];
  1874. this.pageMatchesLength = null;
  1875. this.matchCount = 0;
  1876. this.selected = {
  1877. pageIdx: -1,
  1878. matchIdx: -1
  1879. };
  1880. this.offset = {
  1881. pageIdx: null,
  1882. matchIdx: null
  1883. };
  1884. this.pagesToSearch = null;
  1885. this.resumePageIdx = null;
  1886. this.state = null;
  1887. this.dirtyMatch = false;
  1888. this.findTimeout = null;
  1889. this.firstPagePromise = new Promise(function (resolve) {
  1890. this.resolveFirstPage = resolve;
  1891. }.bind(this));
  1892. },
  1893. normalize: function PDFFindController_normalize(text) {
  1894. return text.replace(this.normalizationRegex, function (ch) {
  1895. return CHARACTERS_TO_NORMALIZE[ch];
  1896. });
  1897. },
  1898. _prepareMatches: function PDFFindController_prepareMatches(matchesWithLength, matches, matchesLength) {
  1899. function isSubTerm(matchesWithLength, currentIndex) {
  1900. var currentElem, prevElem, nextElem;
  1901. currentElem = matchesWithLength[currentIndex];
  1902. nextElem = matchesWithLength[currentIndex + 1];
  1903. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  1904. currentElem.skipped = true;
  1905. return true;
  1906. }
  1907. for (var i = currentIndex - 1; i >= 0; i--) {
  1908. prevElem = matchesWithLength[i];
  1909. if (prevElem.skipped) {
  1910. continue;
  1911. }
  1912. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  1913. break;
  1914. }
  1915. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  1916. currentElem.skipped = true;
  1917. return true;
  1918. }
  1919. }
  1920. return false;
  1921. }
  1922. var i, len;
  1923. matchesWithLength.sort(function (a, b) {
  1924. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  1925. });
  1926. for (i = 0, len = matchesWithLength.length; i < len; i++) {
  1927. if (isSubTerm(matchesWithLength, i)) {
  1928. continue;
  1929. }
  1930. matches.push(matchesWithLength[i].match);
  1931. matchesLength.push(matchesWithLength[i].matchLength);
  1932. }
  1933. },
  1934. calcFindPhraseMatch: function PDFFindController_calcFindPhraseMatch(query, pageIndex, pageContent) {
  1935. var matches = [];
  1936. var queryLen = query.length;
  1937. var matchIdx = -queryLen;
  1938. while (true) {
  1939. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  1940. if (matchIdx === -1) {
  1941. break;
  1942. }
  1943. matches.push(matchIdx);
  1944. }
  1945. this.pageMatches[pageIndex] = matches;
  1946. },
  1947. calcFindWordMatch: function PDFFindController_calcFindWordMatch(query, pageIndex, pageContent) {
  1948. var matchesWithLength = [];
  1949. var queryArray = query.match(/\S+/g);
  1950. var subquery, subqueryLen, matchIdx;
  1951. for (var i = 0, len = queryArray.length; i < len; i++) {
  1952. subquery = queryArray[i];
  1953. subqueryLen = subquery.length;
  1954. matchIdx = -subqueryLen;
  1955. while (true) {
  1956. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  1957. if (matchIdx === -1) {
  1958. break;
  1959. }
  1960. matchesWithLength.push({
  1961. match: matchIdx,
  1962. matchLength: subqueryLen,
  1963. skipped: false
  1964. });
  1965. }
  1966. }
  1967. if (!this.pageMatchesLength) {
  1968. this.pageMatchesLength = [];
  1969. }
  1970. this.pageMatchesLength[pageIndex] = [];
  1971. this.pageMatches[pageIndex] = [];
  1972. this._prepareMatches(matchesWithLength, this.pageMatches[pageIndex], this.pageMatchesLength[pageIndex]);
  1973. },
  1974. calcFindMatch: function PDFFindController_calcFindMatch(pageIndex) {
  1975. var pageContent = this.normalize(this.pageContents[pageIndex]);
  1976. var query = this.normalize(this.state.query);
  1977. var caseSensitive = this.state.caseSensitive;
  1978. var phraseSearch = this.state.phraseSearch;
  1979. var queryLen = query.length;
  1980. if (queryLen === 0) {
  1981. return;
  1982. }
  1983. if (!caseSensitive) {
  1984. pageContent = pageContent.toLowerCase();
  1985. query = query.toLowerCase();
  1986. }
  1987. if (phraseSearch) {
  1988. this.calcFindPhraseMatch(query, pageIndex, pageContent);
  1989. } else {
  1990. this.calcFindWordMatch(query, pageIndex, pageContent);
  1991. }
  1992. this.updatePage(pageIndex);
  1993. if (this.resumePageIdx === pageIndex) {
  1994. this.resumePageIdx = null;
  1995. this.nextPageMatch();
  1996. }
  1997. if (this.pageMatches[pageIndex].length > 0) {
  1998. this.matchCount += this.pageMatches[pageIndex].length;
  1999. this.updateUIResultsCount();
  2000. }
  2001. },
  2002. extractText: function PDFFindController_extractText() {
  2003. if (this.startedTextExtraction) {
  2004. return;
  2005. }
  2006. this.startedTextExtraction = true;
  2007. this.pageContents = [];
  2008. var extractTextPromisesResolves = [];
  2009. var numPages = this.pdfViewer.pagesCount;
  2010. for (var i = 0; i < numPages; i++) {
  2011. this.extractTextPromises.push(new Promise(function (resolve) {
  2012. extractTextPromisesResolves.push(resolve);
  2013. }));
  2014. }
  2015. var self = this;
  2016. function extractPageText(pageIndex) {
  2017. self.pdfViewer.getPageTextContent(pageIndex).then(function textContentResolved(textContent) {
  2018. var textItems = textContent.items;
  2019. var str = [];
  2020. for (var i = 0, len = textItems.length; i < len; i++) {
  2021. str.push(textItems[i].str);
  2022. }
  2023. self.pageContents.push(str.join(''));
  2024. extractTextPromisesResolves[pageIndex](pageIndex);
  2025. if (pageIndex + 1 < self.pdfViewer.pagesCount) {
  2026. extractPageText(pageIndex + 1);
  2027. }
  2028. });
  2029. }
  2030. extractPageText(0);
  2031. },
  2032. executeCommand: function PDFFindController_executeCommand(cmd, state) {
  2033. if (this.state === null || cmd !== 'findagain') {
  2034. this.dirtyMatch = true;
  2035. }
  2036. this.state = state;
  2037. this.updateUIState(FindStates.FIND_PENDING);
  2038. this.firstPagePromise.then(function () {
  2039. this.extractText();
  2040. clearTimeout(this.findTimeout);
  2041. if (cmd === 'find') {
  2042. this.findTimeout = setTimeout(this.nextMatch.bind(this), 250);
  2043. } else {
  2044. this.nextMatch();
  2045. }
  2046. }.bind(this));
  2047. },
  2048. updatePage: function PDFFindController_updatePage(index) {
  2049. if (this.selected.pageIdx === index) {
  2050. this.pdfViewer.currentPageNumber = index + 1;
  2051. }
  2052. var page = this.pdfViewer.getPageView(index);
  2053. if (page.textLayer) {
  2054. page.textLayer.updateMatches();
  2055. }
  2056. },
  2057. nextMatch: function PDFFindController_nextMatch() {
  2058. var previous = this.state.findPrevious;
  2059. var currentPageIndex = this.pdfViewer.currentPageNumber - 1;
  2060. var numPages = this.pdfViewer.pagesCount;
  2061. this.active = true;
  2062. if (this.dirtyMatch) {
  2063. this.dirtyMatch = false;
  2064. this.selected.pageIdx = this.selected.matchIdx = -1;
  2065. this.offset.pageIdx = currentPageIndex;
  2066. this.offset.matchIdx = null;
  2067. this.hadMatch = false;
  2068. this.resumePageIdx = null;
  2069. this.pageMatches = [];
  2070. this.matchCount = 0;
  2071. this.pageMatchesLength = null;
  2072. var self = this;
  2073. for (var i = 0; i < numPages; i++) {
  2074. this.updatePage(i);
  2075. if (!(i in this.pendingFindMatches)) {
  2076. this.pendingFindMatches[i] = true;
  2077. this.extractTextPromises[i].then(function (pageIdx) {
  2078. delete self.pendingFindMatches[pageIdx];
  2079. self.calcFindMatch(pageIdx);
  2080. });
  2081. }
  2082. }
  2083. }
  2084. if (this.state.query === '') {
  2085. this.updateUIState(FindStates.FIND_FOUND);
  2086. return;
  2087. }
  2088. if (this.resumePageIdx) {
  2089. return;
  2090. }
  2091. var offset = this.offset;
  2092. this.pagesToSearch = numPages;
  2093. if (offset.matchIdx !== null) {
  2094. var numPageMatches = this.pageMatches[offset.pageIdx].length;
  2095. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  2096. this.hadMatch = true;
  2097. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  2098. this.updateMatch(true);
  2099. return;
  2100. }
  2101. this.advanceOffsetPage(previous);
  2102. }
  2103. this.nextPageMatch();
  2104. },
  2105. matchesReady: function PDFFindController_matchesReady(matches) {
  2106. var offset = this.offset;
  2107. var numMatches = matches.length;
  2108. var previous = this.state.findPrevious;
  2109. if (numMatches) {
  2110. this.hadMatch = true;
  2111. offset.matchIdx = previous ? numMatches - 1 : 0;
  2112. this.updateMatch(true);
  2113. return true;
  2114. }
  2115. this.advanceOffsetPage(previous);
  2116. if (offset.wrapped) {
  2117. offset.matchIdx = null;
  2118. if (this.pagesToSearch < 0) {
  2119. this.updateMatch(false);
  2120. return true;
  2121. }
  2122. }
  2123. return false;
  2124. },
  2125. updateMatchPosition: function PDFFindController_updateMatchPosition(pageIndex, index, elements, beginIdx) {
  2126. if (this.selected.matchIdx === index && this.selected.pageIdx === pageIndex) {
  2127. var spot = {
  2128. top: FIND_SCROLL_OFFSET_TOP,
  2129. left: FIND_SCROLL_OFFSET_LEFT
  2130. };
  2131. scrollIntoView(elements[beginIdx], spot, true);
  2132. }
  2133. },
  2134. nextPageMatch: function PDFFindController_nextPageMatch() {
  2135. if (this.resumePageIdx !== null) {
  2136. console.error('There can only be one pending page.');
  2137. }
  2138. do {
  2139. var pageIdx = this.offset.pageIdx;
  2140. var matches = this.pageMatches[pageIdx];
  2141. if (!matches) {
  2142. this.resumePageIdx = pageIdx;
  2143. break;
  2144. }
  2145. } while (!this.matchesReady(matches));
  2146. },
  2147. advanceOffsetPage: function PDFFindController_advanceOffsetPage(previous) {
  2148. var offset = this.offset;
  2149. var numPages = this.extractTextPromises.length;
  2150. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  2151. offset.matchIdx = null;
  2152. this.pagesToSearch--;
  2153. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  2154. offset.pageIdx = previous ? numPages - 1 : 0;
  2155. offset.wrapped = true;
  2156. }
  2157. },
  2158. updateMatch: function PDFFindController_updateMatch(found) {
  2159. var state = FindStates.FIND_NOTFOUND;
  2160. var wrapped = this.offset.wrapped;
  2161. this.offset.wrapped = false;
  2162. if (found) {
  2163. var previousPage = this.selected.pageIdx;
  2164. this.selected.pageIdx = this.offset.pageIdx;
  2165. this.selected.matchIdx = this.offset.matchIdx;
  2166. state = wrapped ? FindStates.FIND_WRAPPED : FindStates.FIND_FOUND;
  2167. if (previousPage !== -1 && previousPage !== this.selected.pageIdx) {
  2168. this.updatePage(previousPage);
  2169. }
  2170. }
  2171. this.updateUIState(state, this.state.findPrevious);
  2172. if (this.selected.pageIdx !== -1) {
  2173. this.updatePage(this.selected.pageIdx);
  2174. }
  2175. },
  2176. updateUIResultsCount: function PDFFindController_updateUIResultsCount() {
  2177. if (this.onUpdateResultsCount) {
  2178. this.onUpdateResultsCount(this.matchCount);
  2179. }
  2180. },
  2181. updateUIState: function PDFFindController_updateUIState(state, previous) {
  2182. if (this.onUpdateState) {
  2183. this.onUpdateState(state, previous, this.matchCount);
  2184. }
  2185. }
  2186. };
  2187. return PDFFindController;
  2188. }();
  2189. exports.FindStates = FindStates;
  2190. exports.PDFFindController = PDFFindController;
  2191. }));
  2192. (function (root, factory) {
  2193. factory(root.pdfjsWebPDFPresentationMode = {}, root.pdfjsWebUIUtils);
  2194. }(this, function (exports, uiUtils) {
  2195. var normalizeWheelEventDelta = uiUtils.normalizeWheelEventDelta;
  2196. var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  2197. var DELAY_BEFORE_HIDING_CONTROLS = 3000;
  2198. var ACTIVE_SELECTOR = 'pdfPresentationMode';
  2199. var CONTROLS_SELECTOR = 'pdfPresentationModeControls';
  2200. var PDFPresentationMode = function PDFPresentationModeClosure() {
  2201. function PDFPresentationMode(options) {
  2202. this.container = options.container;
  2203. this.viewer = options.viewer || options.container.firstElementChild;
  2204. this.pdfViewer = options.pdfViewer;
  2205. this.eventBus = options.eventBus;
  2206. var contextMenuItems = options.contextMenuItems || null;
  2207. this.active = false;
  2208. this.args = null;
  2209. this.contextMenuOpen = false;
  2210. this.mouseScrollTimeStamp = 0;
  2211. this.mouseScrollDelta = 0;
  2212. this.touchSwipeState = null;
  2213. if (contextMenuItems) {
  2214. contextMenuItems.contextFirstPage.addEventListener('click', function PDFPresentationMode_contextFirstPageClick(e) {
  2215. this.contextMenuOpen = false;
  2216. this.eventBus.dispatch('firstpage');
  2217. }.bind(this));
  2218. contextMenuItems.contextLastPage.addEventListener('click', function PDFPresentationMode_contextLastPageClick(e) {
  2219. this.contextMenuOpen = false;
  2220. this.eventBus.dispatch('lastpage');
  2221. }.bind(this));
  2222. contextMenuItems.contextPageRotateCw.addEventListener('click', function PDFPresentationMode_contextPageRotateCwClick(e) {
  2223. this.contextMenuOpen = false;
  2224. this.eventBus.dispatch('rotatecw');
  2225. }.bind(this));
  2226. contextMenuItems.contextPageRotateCcw.addEventListener('click', function PDFPresentationMode_contextPageRotateCcwClick(e) {
  2227. this.contextMenuOpen = false;
  2228. this.eventBus.dispatch('rotateccw');
  2229. }.bind(this));
  2230. }
  2231. }
  2232. PDFPresentationMode.prototype = {
  2233. request: function PDFPresentationMode_request() {
  2234. if (this.switchInProgress || this.active || !this.viewer.hasChildNodes()) {
  2235. return false;
  2236. }
  2237. this._addFullscreenChangeListeners();
  2238. this._setSwitchInProgress();
  2239. this._notifyStateChange();
  2240. if (this.container.requestFullscreen) {
  2241. this.container.requestFullscreen();
  2242. } else if (this.container.mozRequestFullScreen) {
  2243. this.container.mozRequestFullScreen();
  2244. } else if (this.container.webkitRequestFullscreen) {
  2245. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  2246. } else if (this.container.msRequestFullscreen) {
  2247. this.container.msRequestFullscreen();
  2248. } else {
  2249. return false;
  2250. }
  2251. this.args = {
  2252. page: this.pdfViewer.currentPageNumber,
  2253. previousScale: this.pdfViewer.currentScaleValue
  2254. };
  2255. return true;
  2256. },
  2257. _mouseWheel: function PDFPresentationMode_mouseWheel(evt) {
  2258. if (!this.active) {
  2259. return;
  2260. }
  2261. evt.preventDefault();
  2262. var delta = normalizeWheelEventDelta(evt);
  2263. var MOUSE_SCROLL_COOLDOWN_TIME = 50;
  2264. var PAGE_SWITCH_THRESHOLD = 0.1;
  2265. var currentTime = new Date().getTime();
  2266. var storedTime = this.mouseScrollTimeStamp;
  2267. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  2268. return;
  2269. }
  2270. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  2271. this._resetMouseScrollState();
  2272. }
  2273. this.mouseScrollDelta += delta;
  2274. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  2275. var totalDelta = this.mouseScrollDelta;
  2276. this._resetMouseScrollState();
  2277. var success = totalDelta > 0 ? this._goToPreviousPage() : this._goToNextPage();
  2278. if (success) {
  2279. this.mouseScrollTimeStamp = currentTime;
  2280. }
  2281. }
  2282. },
  2283. get isFullscreen() {
  2284. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement);
  2285. },
  2286. _goToPreviousPage: function PDFPresentationMode_goToPreviousPage() {
  2287. var page = this.pdfViewer.currentPageNumber;
  2288. if (page <= 1) {
  2289. return false;
  2290. }
  2291. this.pdfViewer.currentPageNumber = page - 1;
  2292. return true;
  2293. },
  2294. _goToNextPage: function PDFPresentationMode_goToNextPage() {
  2295. var page = this.pdfViewer.currentPageNumber;
  2296. if (page >= this.pdfViewer.pagesCount) {
  2297. return false;
  2298. }
  2299. this.pdfViewer.currentPageNumber = page + 1;
  2300. return true;
  2301. },
  2302. _notifyStateChange: function PDFPresentationMode_notifyStateChange() {
  2303. this.eventBus.dispatch('presentationmodechanged', {
  2304. source: this,
  2305. active: this.active,
  2306. switchInProgress: !!this.switchInProgress
  2307. });
  2308. },
  2309. _setSwitchInProgress: function PDFPresentationMode_setSwitchInProgress() {
  2310. if (this.switchInProgress) {
  2311. clearTimeout(this.switchInProgress);
  2312. }
  2313. this.switchInProgress = setTimeout(function switchInProgressTimeout() {
  2314. this._removeFullscreenChangeListeners();
  2315. delete this.switchInProgress;
  2316. this._notifyStateChange();
  2317. }.bind(this), DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  2318. },
  2319. _resetSwitchInProgress: function PDFPresentationMode_resetSwitchInProgress() {
  2320. if (this.switchInProgress) {
  2321. clearTimeout(this.switchInProgress);
  2322. delete this.switchInProgress;
  2323. }
  2324. },
  2325. _enter: function PDFPresentationMode_enter() {
  2326. this.active = true;
  2327. this._resetSwitchInProgress();
  2328. this._notifyStateChange();
  2329. this.container.classList.add(ACTIVE_SELECTOR);
  2330. setTimeout(function enterPresentationModeTimeout() {
  2331. this.pdfViewer.currentPageNumber = this.args.page;
  2332. this.pdfViewer.currentScaleValue = 'page-fit';
  2333. }.bind(this), 0);
  2334. this._addWindowListeners();
  2335. this._showControls();
  2336. this.contextMenuOpen = false;
  2337. this.container.setAttribute('contextmenu', 'viewerContextMenu');
  2338. window.getSelection().removeAllRanges();
  2339. },
  2340. _exit: function PDFPresentationMode_exit() {
  2341. var page = this.pdfViewer.currentPageNumber;
  2342. this.container.classList.remove(ACTIVE_SELECTOR);
  2343. setTimeout(function exitPresentationModeTimeout() {
  2344. this.active = false;
  2345. this._removeFullscreenChangeListeners();
  2346. this._notifyStateChange();
  2347. this.pdfViewer.currentScaleValue = this.args.previousScale;
  2348. this.pdfViewer.currentPageNumber = page;
  2349. this.args = null;
  2350. }.bind(this), 0);
  2351. this._removeWindowListeners();
  2352. this._hideControls();
  2353. this._resetMouseScrollState();
  2354. this.container.removeAttribute('contextmenu');
  2355. this.contextMenuOpen = false;
  2356. },
  2357. _mouseDown: function PDFPresentationMode_mouseDown(evt) {
  2358. if (this.contextMenuOpen) {
  2359. this.contextMenuOpen = false;
  2360. evt.preventDefault();
  2361. return;
  2362. }
  2363. if (evt.button === 0) {
  2364. var isInternalLink = evt.target.href && evt.target.classList.contains('internalLink');
  2365. if (!isInternalLink) {
  2366. evt.preventDefault();
  2367. this.pdfViewer.currentPageNumber += evt.shiftKey ? -1 : 1;
  2368. }
  2369. }
  2370. },
  2371. _contextMenu: function PDFPresentationMode_contextMenu() {
  2372. this.contextMenuOpen = true;
  2373. },
  2374. _showControls: function PDFPresentationMode_showControls() {
  2375. if (this.controlsTimeout) {
  2376. clearTimeout(this.controlsTimeout);
  2377. } else {
  2378. this.container.classList.add(CONTROLS_SELECTOR);
  2379. }
  2380. this.controlsTimeout = setTimeout(function showControlsTimeout() {
  2381. this.container.classList.remove(CONTROLS_SELECTOR);
  2382. delete this.controlsTimeout;
  2383. }.bind(this), DELAY_BEFORE_HIDING_CONTROLS);
  2384. },
  2385. _hideControls: function PDFPresentationMode_hideControls() {
  2386. if (!this.controlsTimeout) {
  2387. return;
  2388. }
  2389. clearTimeout(this.controlsTimeout);
  2390. this.container.classList.remove(CONTROLS_SELECTOR);
  2391. delete this.controlsTimeout;
  2392. },
  2393. _resetMouseScrollState: function PDFPresentationMode_resetMouseScrollState() {
  2394. this.mouseScrollTimeStamp = 0;
  2395. this.mouseScrollDelta = 0;
  2396. },
  2397. _touchSwipe: function PDFPresentationMode_touchSwipe(evt) {
  2398. if (!this.active) {
  2399. return;
  2400. }
  2401. var SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  2402. var SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  2403. if (evt.touches.length > 1) {
  2404. this.touchSwipeState = null;
  2405. return;
  2406. }
  2407. switch (evt.type) {
  2408. case 'touchstart':
  2409. this.touchSwipeState = {
  2410. startX: evt.touches[0].pageX,
  2411. startY: evt.touches[0].pageY,
  2412. endX: evt.touches[0].pageX,
  2413. endY: evt.touches[0].pageY
  2414. };
  2415. break;
  2416. case 'touchmove':
  2417. if (this.touchSwipeState === null) {
  2418. return;
  2419. }
  2420. this.touchSwipeState.endX = evt.touches[0].pageX;
  2421. this.touchSwipeState.endY = evt.touches[0].pageY;
  2422. evt.preventDefault();
  2423. break;
  2424. case 'touchend':
  2425. if (this.touchSwipeState === null) {
  2426. return;
  2427. }
  2428. var delta = 0;
  2429. var dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  2430. var dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  2431. var absAngle = Math.abs(Math.atan2(dy, dx));
  2432. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  2433. delta = dx;
  2434. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  2435. delta = dy;
  2436. }
  2437. if (delta > 0) {
  2438. this._goToPreviousPage();
  2439. } else if (delta < 0) {
  2440. this._goToNextPage();
  2441. }
  2442. break;
  2443. }
  2444. },
  2445. _addWindowListeners: function PDFPresentationMode_addWindowListeners() {
  2446. this.showControlsBind = this._showControls.bind(this);
  2447. this.mouseDownBind = this._mouseDown.bind(this);
  2448. this.mouseWheelBind = this._mouseWheel.bind(this);
  2449. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  2450. this.contextMenuBind = this._contextMenu.bind(this);
  2451. this.touchSwipeBind = this._touchSwipe.bind(this);
  2452. window.addEventListener('mousemove', this.showControlsBind);
  2453. window.addEventListener('mousedown', this.mouseDownBind);
  2454. window.addEventListener('wheel', this.mouseWheelBind);
  2455. window.addEventListener('keydown', this.resetMouseScrollStateBind);
  2456. window.addEventListener('contextmenu', this.contextMenuBind);
  2457. window.addEventListener('touchstart', this.touchSwipeBind);
  2458. window.addEventListener('touchmove', this.touchSwipeBind);
  2459. window.addEventListener('touchend', this.touchSwipeBind);
  2460. },
  2461. _removeWindowListeners: function PDFPresentationMode_removeWindowListeners() {
  2462. window.removeEventListener('mousemove', this.showControlsBind);
  2463. window.removeEventListener('mousedown', this.mouseDownBind);
  2464. window.removeEventListener('wheel', this.mouseWheelBind);
  2465. window.removeEventListener('keydown', this.resetMouseScrollStateBind);
  2466. window.removeEventListener('contextmenu', this.contextMenuBind);
  2467. window.removeEventListener('touchstart', this.touchSwipeBind);
  2468. window.removeEventListener('touchmove', this.touchSwipeBind);
  2469. window.removeEventListener('touchend', this.touchSwipeBind);
  2470. delete this.showControlsBind;
  2471. delete this.mouseDownBind;
  2472. delete this.mouseWheelBind;
  2473. delete this.resetMouseScrollStateBind;
  2474. delete this.contextMenuBind;
  2475. delete this.touchSwipeBind;
  2476. },
  2477. _fullscreenChange: function PDFPresentationMode_fullscreenChange() {
  2478. if (this.isFullscreen) {
  2479. this._enter();
  2480. } else {
  2481. this._exit();
  2482. }
  2483. },
  2484. _addFullscreenChangeListeners: function PDFPresentationMode_addFullscreenChangeListeners() {
  2485. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  2486. window.addEventListener('fullscreenchange', this.fullscreenChangeBind);
  2487. window.addEventListener('mozfullscreenchange', this.fullscreenChangeBind);
  2488. window.addEventListener('webkitfullscreenchange', this.fullscreenChangeBind);
  2489. window.addEventListener('MSFullscreenChange', this.fullscreenChangeBind);
  2490. },
  2491. _removeFullscreenChangeListeners: function PDFPresentationMode_removeFullscreenChangeListeners() {
  2492. window.removeEventListener('fullscreenchange', this.fullscreenChangeBind);
  2493. window.removeEventListener('mozfullscreenchange', this.fullscreenChangeBind);
  2494. window.removeEventListener('webkitfullscreenchange', this.fullscreenChangeBind);
  2495. window.removeEventListener('MSFullscreenChange', this.fullscreenChangeBind);
  2496. delete this.fullscreenChangeBind;
  2497. }
  2498. };
  2499. return PDFPresentationMode;
  2500. }();
  2501. exports.PDFPresentationMode = PDFPresentationMode;
  2502. }));
  2503. (function (root, factory) {
  2504. factory(root.pdfjsWebPDFThumbnailView = {}, root.pdfjsWebUIUtils, root.pdfjsWebPDFRenderingQueue);
  2505. }(this, function (exports, uiUtils, pdfRenderingQueue) {
  2506. var mozL10n = uiUtils.mozL10n;
  2507. var getOutputScale = uiUtils.getOutputScale;
  2508. var RenderingStates = pdfRenderingQueue.RenderingStates;
  2509. var THUMBNAIL_WIDTH = 98;
  2510. var THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  2511. var PDFThumbnailView = function PDFThumbnailViewClosure() {
  2512. function getTempCanvas(width, height) {
  2513. var tempCanvas = PDFThumbnailView.tempImageCache;
  2514. if (!tempCanvas) {
  2515. tempCanvas = document.createElement('canvas');
  2516. PDFThumbnailView.tempImageCache = tempCanvas;
  2517. }
  2518. tempCanvas.width = width;
  2519. tempCanvas.height = height;
  2520. tempCanvas.mozOpaque = true;
  2521. var ctx = tempCanvas.getContext('2d', { alpha: false });
  2522. ctx.save();
  2523. ctx.fillStyle = 'rgb(255, 255, 255)';
  2524. ctx.fillRect(0, 0, width, height);
  2525. ctx.restore();
  2526. return tempCanvas;
  2527. }
  2528. function PDFThumbnailView(options) {
  2529. var container = options.container;
  2530. var id = options.id;
  2531. var defaultViewport = options.defaultViewport;
  2532. var linkService = options.linkService;
  2533. var renderingQueue = options.renderingQueue;
  2534. var disableCanvasToImageConversion = options.disableCanvasToImageConversion || false;
  2535. this.id = id;
  2536. this.renderingId = 'thumbnail' + id;
  2537. this.pageLabel = null;
  2538. this.pdfPage = null;
  2539. this.rotation = 0;
  2540. this.viewport = defaultViewport;
  2541. this.pdfPageRotate = defaultViewport.rotation;
  2542. this.linkService = linkService;
  2543. this.renderingQueue = renderingQueue;
  2544. this.renderTask = null;
  2545. this.renderingState = RenderingStates.INITIAL;
  2546. this.resume = null;
  2547. this.disableCanvasToImageConversion = disableCanvasToImageConversion;
  2548. this.pageWidth = this.viewport.width;
  2549. this.pageHeight = this.viewport.height;
  2550. this.pageRatio = this.pageWidth / this.pageHeight;
  2551. this.canvasWidth = THUMBNAIL_WIDTH;
  2552. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  2553. this.scale = this.canvasWidth / this.pageWidth;
  2554. var anchor = document.createElement('a');
  2555. anchor.href = linkService.getAnchorUrl('#page=' + id);
  2556. anchor.title = mozL10n.get('thumb_page_title', { page: id }, 'Page {{page}}');
  2557. anchor.onclick = function stopNavigation() {
  2558. linkService.page = id;
  2559. return false;
  2560. };
  2561. this.anchor = anchor;
  2562. var div = document.createElement('div');
  2563. div.className = 'thumbnail';
  2564. div.setAttribute('data-page-number', this.id);
  2565. this.div = div;
  2566. if (id === 1) {
  2567. div.classList.add('selected');
  2568. }
  2569. var ring = document.createElement('div');
  2570. ring.className = 'thumbnailSelectionRing';
  2571. var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  2572. ring.style.width = this.canvasWidth + borderAdjustment + 'px';
  2573. ring.style.height = this.canvasHeight + borderAdjustment + 'px';
  2574. this.ring = ring;
  2575. div.appendChild(ring);
  2576. anchor.appendChild(div);
  2577. container.appendChild(anchor);
  2578. }
  2579. PDFThumbnailView.prototype = {
  2580. setPdfPage: function PDFThumbnailView_setPdfPage(pdfPage) {
  2581. this.pdfPage = pdfPage;
  2582. this.pdfPageRotate = pdfPage.rotate;
  2583. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  2584. this.viewport = pdfPage.getViewport(1, totalRotation);
  2585. this.reset();
  2586. },
  2587. reset: function PDFThumbnailView_reset() {
  2588. this.cancelRendering();
  2589. this.pageWidth = this.viewport.width;
  2590. this.pageHeight = this.viewport.height;
  2591. this.pageRatio = this.pageWidth / this.pageHeight;
  2592. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  2593. this.scale = this.canvasWidth / this.pageWidth;
  2594. this.div.removeAttribute('data-loaded');
  2595. var ring = this.ring;
  2596. var childNodes = ring.childNodes;
  2597. for (var i = childNodes.length - 1; i >= 0; i--) {
  2598. ring.removeChild(childNodes[i]);
  2599. }
  2600. var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  2601. ring.style.width = this.canvasWidth + borderAdjustment + 'px';
  2602. ring.style.height = this.canvasHeight + borderAdjustment + 'px';
  2603. if (this.canvas) {
  2604. this.canvas.width = 0;
  2605. this.canvas.height = 0;
  2606. delete this.canvas;
  2607. }
  2608. if (this.image) {
  2609. this.image.removeAttribute('src');
  2610. delete this.image;
  2611. }
  2612. },
  2613. update: function PDFThumbnailView_update(rotation) {
  2614. if (typeof rotation !== 'undefined') {
  2615. this.rotation = rotation;
  2616. }
  2617. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  2618. this.viewport = this.viewport.clone({
  2619. scale: 1,
  2620. rotation: totalRotation
  2621. });
  2622. this.reset();
  2623. },
  2624. cancelRendering: function PDFThumbnailView_cancelRendering() {
  2625. if (this.renderTask) {
  2626. this.renderTask.cancel();
  2627. this.renderTask = null;
  2628. }
  2629. this.renderingState = RenderingStates.INITIAL;
  2630. this.resume = null;
  2631. },
  2632. _getPageDrawContext: function PDFThumbnailView_getPageDrawContext(noCtxScale) {
  2633. var canvas = document.createElement('canvas');
  2634. this.canvas = canvas;
  2635. canvas.mozOpaque = true;
  2636. var ctx = canvas.getContext('2d', { alpha: false });
  2637. var outputScale = getOutputScale(ctx);
  2638. canvas.width = this.canvasWidth * outputScale.sx | 0;
  2639. canvas.height = this.canvasHeight * outputScale.sy | 0;
  2640. canvas.style.width = this.canvasWidth + 'px';
  2641. canvas.style.height = this.canvasHeight + 'px';
  2642. if (!noCtxScale && outputScale.scaled) {
  2643. ctx.scale(outputScale.sx, outputScale.sy);
  2644. }
  2645. return ctx;
  2646. },
  2647. _convertCanvasToImage: function PDFThumbnailView_convertCanvasToImage() {
  2648. if (!this.canvas) {
  2649. return;
  2650. }
  2651. if (this.renderingState !== RenderingStates.FINISHED) {
  2652. return;
  2653. }
  2654. var id = this.renderingId;
  2655. var className = 'thumbnailImage';
  2656. var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}');
  2657. if (this.disableCanvasToImageConversion) {
  2658. this.canvas.id = id;
  2659. this.canvas.className = className;
  2660. this.canvas.setAttribute('aria-label', ariaLabel);
  2661. this.div.setAttribute('data-loaded', true);
  2662. this.ring.appendChild(this.canvas);
  2663. return;
  2664. }
  2665. var image = document.createElement('img');
  2666. image.id = id;
  2667. image.className = className;
  2668. image.setAttribute('aria-label', ariaLabel);
  2669. image.style.width = this.canvasWidth + 'px';
  2670. image.style.height = this.canvasHeight + 'px';
  2671. image.src = this.canvas.toDataURL();
  2672. this.image = image;
  2673. this.div.setAttribute('data-loaded', true);
  2674. this.ring.appendChild(image);
  2675. this.canvas.width = 0;
  2676. this.canvas.height = 0;
  2677. delete this.canvas;
  2678. },
  2679. draw: function PDFThumbnailView_draw() {
  2680. if (this.renderingState !== RenderingStates.INITIAL) {
  2681. console.error('Must be in new state before drawing');
  2682. return Promise.resolve(undefined);
  2683. }
  2684. this.renderingState = RenderingStates.RUNNING;
  2685. var resolveRenderPromise, rejectRenderPromise;
  2686. var promise = new Promise(function (resolve, reject) {
  2687. resolveRenderPromise = resolve;
  2688. rejectRenderPromise = reject;
  2689. });
  2690. var self = this;
  2691. function thumbnailDrawCallback(error) {
  2692. if (renderTask === self.renderTask) {
  2693. self.renderTask = null;
  2694. }
  2695. if (error === 'cancelled') {
  2696. rejectRenderPromise(error);
  2697. return;
  2698. }
  2699. self.renderingState = RenderingStates.FINISHED;
  2700. self._convertCanvasToImage();
  2701. if (!error) {
  2702. resolveRenderPromise(undefined);
  2703. } else {
  2704. rejectRenderPromise(error);
  2705. }
  2706. }
  2707. var ctx = this._getPageDrawContext();
  2708. var drawViewport = this.viewport.clone({ scale: this.scale });
  2709. var renderContinueCallback = function renderContinueCallback(cont) {
  2710. if (!self.renderingQueue.isHighestPriority(self)) {
  2711. self.renderingState = RenderingStates.PAUSED;
  2712. self.resume = function resumeCallback() {
  2713. self.renderingState = RenderingStates.RUNNING;
  2714. cont();
  2715. };
  2716. return;
  2717. }
  2718. cont();
  2719. };
  2720. var renderContext = {
  2721. canvasContext: ctx,
  2722. viewport: drawViewport
  2723. };
  2724. var renderTask = this.renderTask = this.pdfPage.render(renderContext);
  2725. renderTask.onContinue = renderContinueCallback;
  2726. renderTask.promise.then(function pdfPageRenderCallback() {
  2727. thumbnailDrawCallback(null);
  2728. }, function pdfPageRenderError(error) {
  2729. thumbnailDrawCallback(error);
  2730. });
  2731. return promise;
  2732. },
  2733. setImage: function PDFThumbnailView_setImage(pageView) {
  2734. if (this.renderingState !== RenderingStates.INITIAL) {
  2735. return;
  2736. }
  2737. var img = pageView.canvas;
  2738. if (!img) {
  2739. return;
  2740. }
  2741. if (!this.pdfPage) {
  2742. this.setPdfPage(pageView.pdfPage);
  2743. }
  2744. this.renderingState = RenderingStates.FINISHED;
  2745. var ctx = this._getPageDrawContext(true);
  2746. var canvas = ctx.canvas;
  2747. if (img.width <= 2 * canvas.width) {
  2748. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  2749. this._convertCanvasToImage();
  2750. return;
  2751. }
  2752. var MAX_NUM_SCALING_STEPS = 3;
  2753. var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  2754. var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  2755. var reducedImage = getTempCanvas(reducedWidth, reducedHeight);
  2756. var reducedImageCtx = reducedImage.getContext('2d');
  2757. while (reducedWidth > img.width || reducedHeight > img.height) {
  2758. reducedWidth >>= 1;
  2759. reducedHeight >>= 1;
  2760. }
  2761. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  2762. while (reducedWidth > 2 * canvas.width) {
  2763. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  2764. reducedWidth >>= 1;
  2765. reducedHeight >>= 1;
  2766. }
  2767. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  2768. this._convertCanvasToImage();
  2769. },
  2770. get pageId() {
  2771. return this.pageLabel !== null ? this.pageLabel : this.id;
  2772. },
  2773. setPageLabel: function PDFThumbnailView_setPageLabel(label) {
  2774. this.pageLabel = typeof label === 'string' ? label : null;
  2775. this.anchor.title = mozL10n.get('thumb_page_title', { page: this.pageId }, 'Page {{page}}');
  2776. if (this.renderingState !== RenderingStates.FINISHED) {
  2777. return;
  2778. }
  2779. var ariaLabel = mozL10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}');
  2780. if (this.image) {
  2781. this.image.setAttribute('aria-label', ariaLabel);
  2782. } else if (this.disableCanvasToImageConversion && this.canvas) {
  2783. this.canvas.setAttribute('aria-label', ariaLabel);
  2784. }
  2785. }
  2786. };
  2787. return PDFThumbnailView;
  2788. }();
  2789. PDFThumbnailView.tempImageCache = null;
  2790. exports.PDFThumbnailView = PDFThumbnailView;
  2791. }));
  2792. (function (root, factory) {
  2793. factory(root.pdfjsWebSecondaryToolbar = {}, root.pdfjsWebUIUtils);
  2794. }(this, function (exports, uiUtils) {
  2795. var SCROLLBAR_PADDING = uiUtils.SCROLLBAR_PADDING;
  2796. var mozL10n = uiUtils.mozL10n;
  2797. var SecondaryToolbar = function SecondaryToolbarClosure() {
  2798. function SecondaryToolbar(options, mainContainer, eventBus) {
  2799. this.toolbar = options.toolbar;
  2800. this.toggleButton = options.toggleButton;
  2801. this.toolbarButtonContainer = options.toolbarButtonContainer;
  2802. this.buttons = [
  2803. {
  2804. element: options.presentationModeButton,
  2805. eventName: 'presentationmode',
  2806. close: true
  2807. },
  2808. {
  2809. element: options.openFileButton,
  2810. eventName: 'openfile',
  2811. close: true
  2812. },
  2813. {
  2814. element: options.printButton,
  2815. eventName: 'print',
  2816. close: true
  2817. },
  2818. {
  2819. element: options.downloadButton,
  2820. eventName: 'download',
  2821. close: true
  2822. },
  2823. {
  2824. element: options.viewBookmarkButton,
  2825. eventName: null,
  2826. close: true
  2827. },
  2828. {
  2829. element: options.firstPageButton,
  2830. eventName: 'firstpage',
  2831. close: true
  2832. },
  2833. {
  2834. element: options.lastPageButton,
  2835. eventName: 'lastpage',
  2836. close: true
  2837. },
  2838. {
  2839. element: options.pageRotateCwButton,
  2840. eventName: 'rotatecw',
  2841. close: false
  2842. },
  2843. {
  2844. element: options.pageRotateCcwButton,
  2845. eventName: 'rotateccw',
  2846. close: false
  2847. },
  2848. {
  2849. element: options.toggleHandToolButton,
  2850. eventName: 'togglehandtool',
  2851. close: true
  2852. },
  2853. {
  2854. element: options.documentPropertiesButton,
  2855. eventName: 'documentproperties',
  2856. close: true
  2857. }
  2858. ];
  2859. this.items = {
  2860. firstPage: options.firstPageButton,
  2861. lastPage: options.lastPageButton,
  2862. pageRotateCw: options.pageRotateCwButton,
  2863. pageRotateCcw: options.pageRotateCcwButton
  2864. };
  2865. this.mainContainer = mainContainer;
  2866. this.eventBus = eventBus;
  2867. this.opened = false;
  2868. this.containerHeight = null;
  2869. this.previousContainerHeight = null;
  2870. this.reset();
  2871. this._bindClickListeners();
  2872. this._bindHandToolListener(options.toggleHandToolButton);
  2873. this.eventBus.on('resize', this._setMaxHeight.bind(this));
  2874. }
  2875. SecondaryToolbar.prototype = {
  2876. get isOpen() {
  2877. return this.opened;
  2878. },
  2879. setPageNumber: function SecondaryToolbar_setPageNumber(pageNumber) {
  2880. this.pageNumber = pageNumber;
  2881. this._updateUIState();
  2882. },
  2883. setPagesCount: function SecondaryToolbar_setPagesCount(pagesCount) {
  2884. this.pagesCount = pagesCount;
  2885. this._updateUIState();
  2886. },
  2887. reset: function SecondaryToolbar_reset() {
  2888. this.pageNumber = 0;
  2889. this.pagesCount = 0;
  2890. this._updateUIState();
  2891. },
  2892. _updateUIState: function SecondaryToolbar_updateUIState() {
  2893. var items = this.items;
  2894. items.firstPage.disabled = this.pageNumber <= 1;
  2895. items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  2896. items.pageRotateCw.disabled = this.pagesCount === 0;
  2897. items.pageRotateCcw.disabled = this.pagesCount === 0;
  2898. },
  2899. _bindClickListeners: function SecondaryToolbar_bindClickListeners() {
  2900. this.toggleButton.addEventListener('click', this.toggle.bind(this));
  2901. for (var button in this.buttons) {
  2902. var element = this.buttons[button].element;
  2903. var eventName = this.buttons[button].eventName;
  2904. var close = this.buttons[button].close;
  2905. element.addEventListener('click', function (eventName, close) {
  2906. if (eventName !== null) {
  2907. this.eventBus.dispatch(eventName, { source: this });
  2908. }
  2909. if (close) {
  2910. this.close();
  2911. }
  2912. }.bind(this, eventName, close));
  2913. }
  2914. },
  2915. _bindHandToolListener: function SecondaryToolbar_bindHandToolListener(toggleHandToolButton) {
  2916. var isHandToolActive = false;
  2917. this.eventBus.on('handtoolchanged', function (e) {
  2918. if (isHandToolActive === e.isActive) {
  2919. return;
  2920. }
  2921. isHandToolActive = e.isActive;
  2922. if (isHandToolActive) {
  2923. toggleHandToolButton.title = mozL10n.get('hand_tool_disable.title', null, 'Disable hand tool');
  2924. toggleHandToolButton.firstElementChild.textContent = mozL10n.get('hand_tool_disable_label', null, 'Disable hand tool');
  2925. } else {
  2926. toggleHandToolButton.title = mozL10n.get('hand_tool_enable.title', null, 'Enable hand tool');
  2927. toggleHandToolButton.firstElementChild.textContent = mozL10n.get('hand_tool_enable_label', null, 'Enable hand tool');
  2928. }
  2929. });
  2930. },
  2931. open: function SecondaryToolbar_open() {
  2932. if (this.opened) {
  2933. return;
  2934. }
  2935. this.opened = true;
  2936. this._setMaxHeight();
  2937. this.toggleButton.classList.add('toggled');
  2938. this.toolbar.classList.remove('hidden');
  2939. },
  2940. close: function SecondaryToolbar_close() {
  2941. if (!this.opened) {
  2942. return;
  2943. }
  2944. this.opened = false;
  2945. this.toolbar.classList.add('hidden');
  2946. this.toggleButton.classList.remove('toggled');
  2947. },
  2948. toggle: function SecondaryToolbar_toggle() {
  2949. if (this.opened) {
  2950. this.close();
  2951. } else {
  2952. this.open();
  2953. }
  2954. },
  2955. _setMaxHeight: function SecondaryToolbar_setMaxHeight() {
  2956. if (!this.opened) {
  2957. return;
  2958. }
  2959. this.containerHeight = this.mainContainer.clientHeight;
  2960. if (this.containerHeight === this.previousContainerHeight) {
  2961. return;
  2962. }
  2963. this.toolbarButtonContainer.setAttribute('style', 'max-height: ' + (this.containerHeight - SCROLLBAR_PADDING) + 'px;');
  2964. this.previousContainerHeight = this.containerHeight;
  2965. }
  2966. };
  2967. return SecondaryToolbar;
  2968. }();
  2969. exports.SecondaryToolbar = SecondaryToolbar;
  2970. }));
  2971. (function (root, factory) {
  2972. factory(root.pdfjsWebToolbar = {}, root.pdfjsWebUIUtils);
  2973. }(this, function (exports, uiUtils) {
  2974. var mozL10n = uiUtils.mozL10n;
  2975. var noContextMenuHandler = uiUtils.noContextMenuHandler;
  2976. var animationStarted = uiUtils.animationStarted;
  2977. var localized = uiUtils.localized;
  2978. var DEFAULT_SCALE_VALUE = uiUtils.DEFAULT_SCALE_VALUE;
  2979. var DEFAULT_SCALE = uiUtils.DEFAULT_SCALE;
  2980. var MIN_SCALE = uiUtils.MIN_SCALE;
  2981. var MAX_SCALE = uiUtils.MAX_SCALE;
  2982. var PAGE_NUMBER_LOADING_INDICATOR = 'visiblePageIsLoading';
  2983. var SCALE_SELECT_CONTAINER_PADDING = 8;
  2984. var SCALE_SELECT_PADDING = 22;
  2985. var Toolbar = function ToolbarClosure() {
  2986. function Toolbar(options, mainContainer, eventBus) {
  2987. this.toolbar = options.container;
  2988. this.mainContainer = mainContainer;
  2989. this.eventBus = eventBus;
  2990. this.items = options;
  2991. this._wasLocalized = false;
  2992. this.reset();
  2993. this._bindListeners();
  2994. }
  2995. Toolbar.prototype = {
  2996. setPageNumber: function (pageNumber, pageLabel) {
  2997. this.pageNumber = pageNumber;
  2998. this.pageLabel = pageLabel;
  2999. this._updateUIState(false);
  3000. },
  3001. setPagesCount: function (pagesCount, hasPageLabels) {
  3002. this.pagesCount = pagesCount;
  3003. this.hasPageLabels = hasPageLabels;
  3004. this._updateUIState(true);
  3005. },
  3006. setPageScale: function (pageScaleValue, pageScale) {
  3007. this.pageScaleValue = pageScaleValue;
  3008. this.pageScale = pageScale;
  3009. this._updateUIState(false);
  3010. },
  3011. reset: function () {
  3012. this.pageNumber = 0;
  3013. this.pageLabel = null;
  3014. this.hasPageLabels = false;
  3015. this.pagesCount = 0;
  3016. this.pageScaleValue = DEFAULT_SCALE_VALUE;
  3017. this.pageScale = DEFAULT_SCALE;
  3018. this._updateUIState(true);
  3019. },
  3020. _bindListeners: function Toolbar_bindClickListeners() {
  3021. var eventBus = this.eventBus;
  3022. var self = this;
  3023. var items = this.items;
  3024. items.previous.addEventListener('click', function () {
  3025. eventBus.dispatch('previouspage');
  3026. });
  3027. items.next.addEventListener('click', function () {
  3028. eventBus.dispatch('nextpage');
  3029. });
  3030. items.zoomIn.addEventListener('click', function () {
  3031. eventBus.dispatch('zoomin');
  3032. });
  3033. items.zoomOut.addEventListener('click', function () {
  3034. eventBus.dispatch('zoomout');
  3035. });
  3036. items.pageNumber.addEventListener('click', function () {
  3037. this.select();
  3038. });
  3039. items.pageNumber.addEventListener('change', function () {
  3040. eventBus.dispatch('pagenumberchanged', {
  3041. source: self,
  3042. value: this.value
  3043. });
  3044. });
  3045. items.scaleSelect.addEventListener('change', function () {
  3046. if (this.value === 'custom') {
  3047. return;
  3048. }
  3049. eventBus.dispatch('scalechanged', {
  3050. source: self,
  3051. value: this.value
  3052. });
  3053. });
  3054. items.presentationModeButton.addEventListener('click', function (e) {
  3055. eventBus.dispatch('presentationmode');
  3056. });
  3057. items.openFile.addEventListener('click', function (e) {
  3058. eventBus.dispatch('openfile');
  3059. });
  3060. items.print.addEventListener('click', function (e) {
  3061. eventBus.dispatch('print');
  3062. });
  3063. items.download.addEventListener('click', function (e) {
  3064. eventBus.dispatch('download');
  3065. });
  3066. items.scaleSelect.oncontextmenu = noContextMenuHandler;
  3067. localized.then(this._localized.bind(this));
  3068. },
  3069. _localized: function Toolbar_localized() {
  3070. this._wasLocalized = true;
  3071. this._adjustScaleWidth();
  3072. this._updateUIState(true);
  3073. },
  3074. _updateUIState: function Toolbar_updateUIState(resetNumPages) {
  3075. function selectScaleOption(value, scale) {
  3076. var options = items.scaleSelect.options;
  3077. var predefinedValueFound = false;
  3078. for (var i = 0, ii = options.length; i < ii; i++) {
  3079. var option = options[i];
  3080. if (option.value !== value) {
  3081. option.selected = false;
  3082. continue;
  3083. }
  3084. option.selected = true;
  3085. predefinedValueFound = true;
  3086. }
  3087. if (!predefinedValueFound) {
  3088. var customScale = Math.round(scale * 10000) / 100;
  3089. items.customScaleOption.textContent = mozL10n.get('page_scale_percent', { scale: customScale }, '{{scale}}%');
  3090. items.customScaleOption.selected = true;
  3091. }
  3092. }
  3093. if (!this._wasLocalized) {
  3094. return;
  3095. }
  3096. var pageNumber = this.pageNumber;
  3097. var scaleValue = (this.pageScaleValue || this.pageScale).toString();
  3098. var scale = this.pageScale;
  3099. var items = this.items;
  3100. var pagesCount = this.pagesCount;
  3101. if (resetNumPages) {
  3102. if (this.hasPageLabels) {
  3103. items.pageNumber.type = 'text';
  3104. } else {
  3105. items.pageNumber.type = 'number';
  3106. items.numPages.textContent = mozL10n.get('of_pages', { pagesCount: pagesCount }, 'of {{pagesCount}}');
  3107. }
  3108. items.pageNumber.max = pagesCount;
  3109. }
  3110. if (this.hasPageLabels) {
  3111. items.pageNumber.value = this.pageLabel;
  3112. items.numPages.textContent = mozL10n.get('page_of_pages', {
  3113. pageNumber: pageNumber,
  3114. pagesCount: pagesCount
  3115. }, '({{pageNumber}} of {{pagesCount}})');
  3116. } else {
  3117. items.pageNumber.value = pageNumber;
  3118. }
  3119. items.previous.disabled = pageNumber <= 1;
  3120. items.next.disabled = pageNumber >= pagesCount;
  3121. items.zoomOut.disabled = scale <= MIN_SCALE;
  3122. items.zoomIn.disabled = scale >= MAX_SCALE;
  3123. selectScaleOption(scaleValue, scale);
  3124. },
  3125. updateLoadingIndicatorState: function Toolbar_updateLoadingIndicatorState(loading) {
  3126. var pageNumberInput = this.items.pageNumber;
  3127. if (loading) {
  3128. pageNumberInput.classList.add(PAGE_NUMBER_LOADING_INDICATOR);
  3129. } else {
  3130. pageNumberInput.classList.remove(PAGE_NUMBER_LOADING_INDICATOR);
  3131. }
  3132. },
  3133. _adjustScaleWidth: function Toolbar_adjustScaleWidth() {
  3134. var container = this.items.scaleSelectContainer;
  3135. var select = this.items.scaleSelect;
  3136. animationStarted.then(function () {
  3137. if (container.clientWidth === 0) {
  3138. container.setAttribute('style', 'display: inherit;');
  3139. }
  3140. if (container.clientWidth > 0) {
  3141. select.setAttribute('style', 'min-width: inherit;');
  3142. var width = select.clientWidth + SCALE_SELECT_CONTAINER_PADDING;
  3143. select.setAttribute('style', 'min-width: ' + (width + SCALE_SELECT_PADDING) + 'px;');
  3144. container.setAttribute('style', 'min-width: ' + width + 'px; ' + 'max-width: ' + width + 'px;');
  3145. }
  3146. });
  3147. }
  3148. };
  3149. return Toolbar;
  3150. }();
  3151. exports.Toolbar = Toolbar;
  3152. }));
  3153. (function (root, factory) {
  3154. factory(root.pdfjsWebPDFFindBar = {}, root.pdfjsWebUIUtils, root.pdfjsWebPDFFindController);
  3155. }(this, function (exports, uiUtils, pdfFindController) {
  3156. var mozL10n = uiUtils.mozL10n;
  3157. var FindStates = pdfFindController.FindStates;
  3158. var PDFFindBar = function PDFFindBarClosure() {
  3159. function PDFFindBar(options) {
  3160. this.opened = false;
  3161. this.bar = options.bar || null;
  3162. this.toggleButton = options.toggleButton || null;
  3163. this.findField = options.findField || null;
  3164. this.highlightAll = options.highlightAllCheckbox || null;
  3165. this.caseSensitive = options.caseSensitiveCheckbox || null;
  3166. this.findMsg = options.findMsg || null;
  3167. this.findResultsCount = options.findResultsCount || null;
  3168. this.findStatusIcon = options.findStatusIcon || null;
  3169. this.findPreviousButton = options.findPreviousButton || null;
  3170. this.findNextButton = options.findNextButton || null;
  3171. this.findController = options.findController || null;
  3172. this.eventBus = options.eventBus;
  3173. if (this.findController === null) {
  3174. throw new Error('PDFFindBar cannot be used without a ' + 'PDFFindController instance.');
  3175. }
  3176. var self = this;
  3177. this.toggleButton.addEventListener('click', function () {
  3178. self.toggle();
  3179. });
  3180. this.findField.addEventListener('input', function () {
  3181. self.dispatchEvent('');
  3182. });
  3183. this.bar.addEventListener('keydown', function (evt) {
  3184. switch (evt.keyCode) {
  3185. case 13:
  3186. if (evt.target === self.findField) {
  3187. self.dispatchEvent('again', evt.shiftKey);
  3188. }
  3189. break;
  3190. case 27:
  3191. self.close();
  3192. break;
  3193. }
  3194. });
  3195. this.findPreviousButton.addEventListener('click', function () {
  3196. self.dispatchEvent('again', true);
  3197. });
  3198. this.findNextButton.addEventListener('click', function () {
  3199. self.dispatchEvent('again', false);
  3200. });
  3201. this.highlightAll.addEventListener('click', function () {
  3202. self.dispatchEvent('highlightallchange');
  3203. });
  3204. this.caseSensitive.addEventListener('click', function () {
  3205. self.dispatchEvent('casesensitivitychange');
  3206. });
  3207. }
  3208. PDFFindBar.prototype = {
  3209. reset: function PDFFindBar_reset() {
  3210. this.updateUIState();
  3211. },
  3212. dispatchEvent: function PDFFindBar_dispatchEvent(type, findPrev) {
  3213. this.eventBus.dispatch('find', {
  3214. source: this,
  3215. type: type,
  3216. query: this.findField.value,
  3217. caseSensitive: this.caseSensitive.checked,
  3218. phraseSearch: true,
  3219. highlightAll: this.highlightAll.checked,
  3220. findPrevious: findPrev
  3221. });
  3222. },
  3223. updateUIState: function PDFFindBar_updateUIState(state, previous, matchCount) {
  3224. var notFound = false;
  3225. var findMsg = '';
  3226. var status = '';
  3227. switch (state) {
  3228. case FindStates.FIND_FOUND:
  3229. break;
  3230. case FindStates.FIND_PENDING:
  3231. status = 'pending';
  3232. break;
  3233. case FindStates.FIND_NOTFOUND:
  3234. findMsg = mozL10n.get('find_not_found', null, 'Phrase not found');
  3235. notFound = true;
  3236. break;
  3237. case FindStates.FIND_WRAPPED:
  3238. if (previous) {
  3239. findMsg = mozL10n.get('find_reached_top', null, 'Reached top of document, continued from bottom');
  3240. } else {
  3241. findMsg = mozL10n.get('find_reached_bottom', null, 'Reached end of document, continued from top');
  3242. }
  3243. break;
  3244. }
  3245. if (notFound) {
  3246. this.findField.classList.add('notFound');
  3247. } else {
  3248. this.findField.classList.remove('notFound');
  3249. }
  3250. this.findField.setAttribute('data-status', status);
  3251. this.findMsg.textContent = findMsg;
  3252. this.updateResultsCount(matchCount);
  3253. },
  3254. updateResultsCount: function (matchCount) {
  3255. if (!this.findResultsCount) {
  3256. return;
  3257. }
  3258. if (!matchCount) {
  3259. this.findResultsCount.classList.add('hidden');
  3260. return;
  3261. }
  3262. this.findResultsCount.textContent = matchCount.toLocaleString();
  3263. this.findResultsCount.classList.remove('hidden');
  3264. },
  3265. open: function PDFFindBar_open() {
  3266. if (!this.opened) {
  3267. this.opened = true;
  3268. this.toggleButton.classList.add('toggled');
  3269. this.bar.classList.remove('hidden');
  3270. }
  3271. this.findField.select();
  3272. this.findField.focus();
  3273. },
  3274. close: function PDFFindBar_close() {
  3275. if (!this.opened) {
  3276. return;
  3277. }
  3278. this.opened = false;
  3279. this.toggleButton.classList.remove('toggled');
  3280. this.bar.classList.add('hidden');
  3281. this.findController.active = false;
  3282. },
  3283. toggle: function PDFFindBar_toggle() {
  3284. if (this.opened) {
  3285. this.close();
  3286. } else {
  3287. this.open();
  3288. }
  3289. }
  3290. };
  3291. return PDFFindBar;
  3292. }();
  3293. exports.PDFFindBar = PDFFindBar;
  3294. }));
  3295. (function (root, factory) {
  3296. factory(root.pdfjsWebPDFHistory = {}, root.pdfjsWebDOMEvents);
  3297. }(this, function (exports, domEvents) {
  3298. function PDFHistory(options) {
  3299. this.linkService = options.linkService;
  3300. this.eventBus = options.eventBus || domEvents.getGlobalEventBus();
  3301. this.initialized = false;
  3302. this.initialDestination = null;
  3303. this.initialBookmark = null;
  3304. }
  3305. PDFHistory.prototype = {
  3306. initialize: function pdfHistoryInitialize(fingerprint) {
  3307. this.initialized = true;
  3308. this.reInitialized = false;
  3309. this.allowHashChange = true;
  3310. this.historyUnlocked = true;
  3311. this.isViewerInPresentationMode = false;
  3312. this.previousHash = window.location.hash.substring(1);
  3313. this.currentBookmark = '';
  3314. this.currentPage = 0;
  3315. this.updatePreviousBookmark = false;
  3316. this.previousBookmark = '';
  3317. this.previousPage = 0;
  3318. this.nextHashParam = '';
  3319. this.fingerprint = fingerprint;
  3320. this.currentUid = this.uid = 0;
  3321. this.current = {};
  3322. var state = window.history.state;
  3323. if (this._isStateObjectDefined(state)) {
  3324. if (state.target.dest) {
  3325. this.initialDestination = state.target.dest;
  3326. } else {
  3327. this.initialBookmark = state.target.hash;
  3328. }
  3329. this.currentUid = state.uid;
  3330. this.uid = state.uid + 1;
  3331. this.current = state.target;
  3332. } else {
  3333. if (state && state.fingerprint && this.fingerprint !== state.fingerprint) {
  3334. this.reInitialized = true;
  3335. }
  3336. this._pushOrReplaceState({ fingerprint: this.fingerprint }, true);
  3337. }
  3338. var self = this;
  3339. window.addEventListener('popstate', function pdfHistoryPopstate(evt) {
  3340. if (!self.historyUnlocked) {
  3341. return;
  3342. }
  3343. if (evt.state) {
  3344. self._goTo(evt.state);
  3345. return;
  3346. }
  3347. if (self.uid === 0) {
  3348. var previousParams = self.previousHash && self.currentBookmark && self.previousHash !== self.currentBookmark ? {
  3349. hash: self.currentBookmark,
  3350. page: self.currentPage
  3351. } : { page: 1 };
  3352. replacePreviousHistoryState(previousParams, function () {
  3353. updateHistoryWithCurrentHash();
  3354. });
  3355. } else {
  3356. updateHistoryWithCurrentHash();
  3357. }
  3358. });
  3359. function updateHistoryWithCurrentHash() {
  3360. self.previousHash = window.location.hash.slice(1);
  3361. self._pushToHistory({ hash: self.previousHash }, false, true);
  3362. self._updatePreviousBookmark();
  3363. }
  3364. function replacePreviousHistoryState(params, callback) {
  3365. self.historyUnlocked = false;
  3366. self.allowHashChange = false;
  3367. window.addEventListener('popstate', rewriteHistoryAfterBack);
  3368. history.back();
  3369. function rewriteHistoryAfterBack() {
  3370. window.removeEventListener('popstate', rewriteHistoryAfterBack);
  3371. window.addEventListener('popstate', rewriteHistoryAfterForward);
  3372. self._pushToHistory(params, false, true);
  3373. history.forward();
  3374. }
  3375. function rewriteHistoryAfterForward() {
  3376. window.removeEventListener('popstate', rewriteHistoryAfterForward);
  3377. self.allowHashChange = true;
  3378. self.historyUnlocked = true;
  3379. callback();
  3380. }
  3381. }
  3382. function pdfHistoryBeforeUnload() {
  3383. var previousParams = self._getPreviousParams(null, true);
  3384. if (previousParams) {
  3385. var replacePrevious = !self.current.dest && self.current.hash !== self.previousHash;
  3386. self._pushToHistory(previousParams, false, replacePrevious);
  3387. self._updatePreviousBookmark();
  3388. }
  3389. window.removeEventListener('beforeunload', pdfHistoryBeforeUnload);
  3390. }
  3391. window.addEventListener('beforeunload', pdfHistoryBeforeUnload);
  3392. window.addEventListener('pageshow', function pdfHistoryPageShow(evt) {
  3393. window.addEventListener('beforeunload', pdfHistoryBeforeUnload);
  3394. });
  3395. self.eventBus.on('presentationmodechanged', function (e) {
  3396. self.isViewerInPresentationMode = e.active;
  3397. });
  3398. },
  3399. clearHistoryState: function pdfHistory_clearHistoryState() {
  3400. this._pushOrReplaceState(null, true);
  3401. },
  3402. _isStateObjectDefined: function pdfHistory_isStateObjectDefined(state) {
  3403. return state && state.uid >= 0 && state.fingerprint && this.fingerprint === state.fingerprint && state.target && state.target.hash ? true : false;
  3404. },
  3405. _pushOrReplaceState: function pdfHistory_pushOrReplaceState(stateObj, replace) {
  3406. if (replace) {
  3407. window.history.replaceState(stateObj, '', document.URL);
  3408. } else {
  3409. window.history.pushState(stateObj, '', document.URL);
  3410. }
  3411. },
  3412. get isHashChangeUnlocked() {
  3413. if (!this.initialized) {
  3414. return true;
  3415. }
  3416. return this.allowHashChange;
  3417. },
  3418. _updatePreviousBookmark: function pdfHistory_updatePreviousBookmark() {
  3419. if (this.updatePreviousBookmark && this.currentBookmark && this.currentPage) {
  3420. this.previousBookmark = this.currentBookmark;
  3421. this.previousPage = this.currentPage;
  3422. this.updatePreviousBookmark = false;
  3423. }
  3424. },
  3425. updateCurrentBookmark: function pdfHistoryUpdateCurrentBookmark(bookmark, pageNum) {
  3426. if (this.initialized) {
  3427. this.currentBookmark = bookmark.substring(1);
  3428. this.currentPage = pageNum | 0;
  3429. this._updatePreviousBookmark();
  3430. }
  3431. },
  3432. updateNextHashParam: function pdfHistoryUpdateNextHashParam(param) {
  3433. if (this.initialized) {
  3434. this.nextHashParam = param;
  3435. }
  3436. },
  3437. push: function pdfHistoryPush(params, isInitialBookmark) {
  3438. if (!(this.initialized && this.historyUnlocked)) {
  3439. return;
  3440. }
  3441. if (params.dest && !params.hash) {
  3442. params.hash = this.current.hash && this.current.dest && this.current.dest === params.dest ? this.current.hash : this.linkService.getDestinationHash(params.dest).split('#')[1];
  3443. }
  3444. if (params.page) {
  3445. params.page |= 0;
  3446. }
  3447. if (isInitialBookmark) {
  3448. var target = window.history.state.target;
  3449. if (!target) {
  3450. this._pushToHistory(params, false);
  3451. this.previousHash = window.location.hash.substring(1);
  3452. }
  3453. this.updatePreviousBookmark = this.nextHashParam ? false : true;
  3454. if (target) {
  3455. this._updatePreviousBookmark();
  3456. }
  3457. return;
  3458. }
  3459. if (this.nextHashParam) {
  3460. if (this.nextHashParam === params.hash) {
  3461. this.nextHashParam = null;
  3462. this.updatePreviousBookmark = true;
  3463. return;
  3464. }
  3465. this.nextHashParam = null;
  3466. }
  3467. if (params.hash) {
  3468. if (this.current.hash) {
  3469. if (this.current.hash !== params.hash) {
  3470. this._pushToHistory(params, true);
  3471. } else {
  3472. if (!this.current.page && params.page) {
  3473. this._pushToHistory(params, false, true);
  3474. }
  3475. this.updatePreviousBookmark = true;
  3476. }
  3477. } else {
  3478. this._pushToHistory(params, true);
  3479. }
  3480. } else if (this.current.page && params.page && this.current.page !== params.page) {
  3481. this._pushToHistory(params, true);
  3482. }
  3483. },
  3484. _getPreviousParams: function pdfHistory_getPreviousParams(onlyCheckPage, beforeUnload) {
  3485. if (!(this.currentBookmark && this.currentPage)) {
  3486. return null;
  3487. } else if (this.updatePreviousBookmark) {
  3488. this.updatePreviousBookmark = false;
  3489. }
  3490. if (this.uid > 0 && !(this.previousBookmark && this.previousPage)) {
  3491. return null;
  3492. }
  3493. if (!this.current.dest && !onlyCheckPage || beforeUnload) {
  3494. if (this.previousBookmark === this.currentBookmark) {
  3495. return null;
  3496. }
  3497. } else if (this.current.page || onlyCheckPage) {
  3498. if (this.previousPage === this.currentPage) {
  3499. return null;
  3500. }
  3501. } else {
  3502. return null;
  3503. }
  3504. var params = {
  3505. hash: this.currentBookmark,
  3506. page: this.currentPage
  3507. };
  3508. if (this.isViewerInPresentationMode) {
  3509. params.hash = null;
  3510. }
  3511. return params;
  3512. },
  3513. _stateObj: function pdfHistory_stateObj(params) {
  3514. return {
  3515. fingerprint: this.fingerprint,
  3516. uid: this.uid,
  3517. target: params
  3518. };
  3519. },
  3520. _pushToHistory: function pdfHistory_pushToHistory(params, addPrevious, overwrite) {
  3521. if (!this.initialized) {
  3522. return;
  3523. }
  3524. if (!params.hash && params.page) {
  3525. params.hash = 'page=' + params.page;
  3526. }
  3527. if (addPrevious && !overwrite) {
  3528. var previousParams = this._getPreviousParams();
  3529. if (previousParams) {
  3530. var replacePrevious = !this.current.dest && this.current.hash !== this.previousHash;
  3531. this._pushToHistory(previousParams, false, replacePrevious);
  3532. }
  3533. }
  3534. this._pushOrReplaceState(this._stateObj(params), overwrite || this.uid === 0);
  3535. this.currentUid = this.uid++;
  3536. this.current = params;
  3537. this.updatePreviousBookmark = true;
  3538. },
  3539. _goTo: function pdfHistory_goTo(state) {
  3540. if (!(this.initialized && this.historyUnlocked && this._isStateObjectDefined(state))) {
  3541. return;
  3542. }
  3543. if (!this.reInitialized && state.uid < this.currentUid) {
  3544. var previousParams = this._getPreviousParams(true);
  3545. if (previousParams) {
  3546. this._pushToHistory(this.current, false);
  3547. this._pushToHistory(previousParams, false);
  3548. this.currentUid = state.uid;
  3549. window.history.back();
  3550. return;
  3551. }
  3552. }
  3553. this.historyUnlocked = false;
  3554. if (state.target.dest) {
  3555. this.linkService.navigateTo(state.target.dest);
  3556. } else {
  3557. this.linkService.setHash(state.target.hash);
  3558. }
  3559. this.currentUid = state.uid;
  3560. if (state.uid > this.uid) {
  3561. this.uid = state.uid;
  3562. }
  3563. this.current = state.target;
  3564. this.updatePreviousBookmark = true;
  3565. var currentHash = window.location.hash.substring(1);
  3566. if (this.previousHash !== currentHash) {
  3567. this.allowHashChange = false;
  3568. }
  3569. this.previousHash = currentHash;
  3570. this.historyUnlocked = true;
  3571. },
  3572. back: function pdfHistoryBack() {
  3573. this.go(-1);
  3574. },
  3575. forward: function pdfHistoryForward() {
  3576. this.go(1);
  3577. },
  3578. go: function pdfHistoryGo(direction) {
  3579. if (this.initialized && this.historyUnlocked) {
  3580. var state = window.history.state;
  3581. if (direction === -1 && state && state.uid > 0) {
  3582. window.history.back();
  3583. } else if (direction === 1 && state && state.uid < this.uid - 1) {
  3584. window.history.forward();
  3585. }
  3586. }
  3587. }
  3588. };
  3589. exports.PDFHistory = PDFHistory;
  3590. }));
  3591. (function (root, factory) {
  3592. factory(root.pdfjsWebPDFLinkService = {}, root.pdfjsWebUIUtils, root.pdfjsWebDOMEvents);
  3593. }(this, function (exports, uiUtils, domEvents) {
  3594. var parseQueryString = uiUtils.parseQueryString;
  3595. var PageNumberRegExp = /^\d+$/;
  3596. function isPageNumber(str) {
  3597. return PageNumberRegExp.test(str);
  3598. }
  3599. var PDFLinkService = function PDFLinkServiceClosure() {
  3600. function PDFLinkService(options) {
  3601. options = options || {};
  3602. this.eventBus = options.eventBus || domEvents.getGlobalEventBus();
  3603. this.baseUrl = null;
  3604. this.pdfDocument = null;
  3605. this.pdfViewer = null;
  3606. this.pdfHistory = null;
  3607. this._pagesRefCache = null;
  3608. }
  3609. PDFLinkService.prototype = {
  3610. setDocument: function PDFLinkService_setDocument(pdfDocument, baseUrl) {
  3611. this.baseUrl = baseUrl;
  3612. this.pdfDocument = pdfDocument;
  3613. this._pagesRefCache = Object.create(null);
  3614. },
  3615. setViewer: function PDFLinkService_setViewer(pdfViewer) {
  3616. this.pdfViewer = pdfViewer;
  3617. },
  3618. setHistory: function PDFLinkService_setHistory(pdfHistory) {
  3619. this.pdfHistory = pdfHistory;
  3620. },
  3621. get pagesCount() {
  3622. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  3623. },
  3624. get page() {
  3625. return this.pdfViewer.currentPageNumber;
  3626. },
  3627. set page(value) {
  3628. this.pdfViewer.currentPageNumber = value;
  3629. },
  3630. navigateTo: function PDFLinkService_navigateTo(dest) {
  3631. var destString = '';
  3632. var self = this;
  3633. var goToDestination = function (destRef) {
  3634. var pageNumber;
  3635. if (destRef instanceof Object) {
  3636. pageNumber = self._cachedPageNumber(destRef);
  3637. } else if ((destRef | 0) === destRef) {
  3638. pageNumber = destRef + 1;
  3639. } else {
  3640. console.error('PDFLinkService_navigateTo: "' + destRef + '" is not a valid destination reference.');
  3641. return;
  3642. }
  3643. if (pageNumber) {
  3644. if (pageNumber < 1 || pageNumber > self.pagesCount) {
  3645. console.error('PDFLinkService_navigateTo: "' + pageNumber + '" is a non-existent page number.');
  3646. return;
  3647. }
  3648. self.pdfViewer.scrollPageIntoView({
  3649. pageNumber: pageNumber,
  3650. destArray: dest
  3651. });
  3652. if (self.pdfHistory) {
  3653. self.pdfHistory.push({
  3654. dest: dest,
  3655. hash: destString,
  3656. page: pageNumber
  3657. });
  3658. }
  3659. } else {
  3660. self.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
  3661. self.cachePageRef(pageIndex + 1, destRef);
  3662. goToDestination(destRef);
  3663. }).catch(function () {
  3664. console.error('PDFLinkService_navigateTo: "' + destRef + '" is not a valid page reference.');
  3665. });
  3666. }
  3667. };
  3668. var destinationPromise;
  3669. if (typeof dest === 'string') {
  3670. destString = dest;
  3671. destinationPromise = this.pdfDocument.getDestination(dest);
  3672. } else {
  3673. destinationPromise = Promise.resolve(dest);
  3674. }
  3675. destinationPromise.then(function (destination) {
  3676. dest = destination;
  3677. if (!(destination instanceof Array)) {
  3678. console.error('PDFLinkService_navigateTo: "' + destination + '" is not a valid destination array.');
  3679. return;
  3680. }
  3681. goToDestination(destination[0]);
  3682. });
  3683. },
  3684. getDestinationHash: function PDFLinkService_getDestinationHash(dest) {
  3685. if (typeof dest === 'string') {
  3686. return this.getAnchorUrl('#' + (isPageNumber(dest) ? 'nameddest=' : '') + escape(dest));
  3687. }
  3688. if (dest instanceof Array) {
  3689. var str = JSON.stringify(dest);
  3690. return this.getAnchorUrl('#' + escape(str));
  3691. }
  3692. return this.getAnchorUrl('');
  3693. },
  3694. getAnchorUrl: function PDFLinkService_getAnchorUrl(anchor) {
  3695. return (this.baseUrl || '') + anchor;
  3696. },
  3697. setHash: function PDFLinkService_setHash(hash) {
  3698. var pageNumber, dest;
  3699. if (hash.indexOf('=') >= 0) {
  3700. var params = parseQueryString(hash);
  3701. if ('search' in params) {
  3702. this.eventBus.dispatch('findfromurlhash', {
  3703. source: this,
  3704. query: params['search'].replace(/"/g, ''),
  3705. phraseSearch: params['phrase'] === 'true'
  3706. });
  3707. }
  3708. if ('nameddest' in params) {
  3709. if (this.pdfHistory) {
  3710. this.pdfHistory.updateNextHashParam(params.nameddest);
  3711. }
  3712. this.navigateTo(params.nameddest);
  3713. return;
  3714. }
  3715. if ('page' in params) {
  3716. pageNumber = params.page | 0 || 1;
  3717. }
  3718. if ('zoom' in params) {
  3719. var zoomArgs = params.zoom.split(',');
  3720. var zoomArg = zoomArgs[0];
  3721. var zoomArgNumber = parseFloat(zoomArg);
  3722. if (zoomArg.indexOf('Fit') === -1) {
  3723. dest = [
  3724. null,
  3725. { name: 'XYZ' },
  3726. zoomArgs.length > 1 ? zoomArgs[1] | 0 : null,
  3727. zoomArgs.length > 2 ? zoomArgs[2] | 0 : null,
  3728. zoomArgNumber ? zoomArgNumber / 100 : zoomArg
  3729. ];
  3730. } else {
  3731. if (zoomArg === 'Fit' || zoomArg === 'FitB') {
  3732. dest = [
  3733. null,
  3734. { name: zoomArg }
  3735. ];
  3736. } else if (zoomArg === 'FitH' || zoomArg === 'FitBH' || (zoomArg === 'FitV' || zoomArg === 'FitBV')) {
  3737. dest = [
  3738. null,
  3739. { name: zoomArg },
  3740. zoomArgs.length > 1 ? zoomArgs[1] | 0 : null
  3741. ];
  3742. } else if (zoomArg === 'FitR') {
  3743. if (zoomArgs.length !== 5) {
  3744. console.error('PDFLinkService_setHash: ' + 'Not enough parameters for \'FitR\'.');
  3745. } else {
  3746. dest = [
  3747. null,
  3748. { name: zoomArg },
  3749. zoomArgs[1] | 0,
  3750. zoomArgs[2] | 0,
  3751. zoomArgs[3] | 0,
  3752. zoomArgs[4] | 0
  3753. ];
  3754. }
  3755. } else {
  3756. console.error('PDFLinkService_setHash: \'' + zoomArg + '\' is not a valid zoom value.');
  3757. }
  3758. }
  3759. }
  3760. if (dest) {
  3761. this.pdfViewer.scrollPageIntoView({
  3762. pageNumber: pageNumber || this.page,
  3763. destArray: dest,
  3764. allowNegativeOffset: true
  3765. });
  3766. } else if (pageNumber) {
  3767. this.page = pageNumber;
  3768. }
  3769. if ('pagemode' in params) {
  3770. this.eventBus.dispatch('pagemode', {
  3771. source: this,
  3772. mode: params.pagemode
  3773. });
  3774. }
  3775. } else {
  3776. if (isPageNumber(hash) && hash <= this.pagesCount) {
  3777. console.warn('PDFLinkService_setHash: specifying a page number ' + 'directly after the hash symbol (#) is deprecated, ' + 'please use the "#page=' + hash + '" form instead.');
  3778. this.page = hash | 0;
  3779. }
  3780. dest = unescape(hash);
  3781. try {
  3782. dest = JSON.parse(dest);
  3783. if (!(dest instanceof Array)) {
  3784. dest = dest.toString();
  3785. }
  3786. } catch (ex) {
  3787. }
  3788. if (typeof dest === 'string' || isValidExplicitDestination(dest)) {
  3789. if (this.pdfHistory) {
  3790. this.pdfHistory.updateNextHashParam(dest);
  3791. }
  3792. this.navigateTo(dest);
  3793. return;
  3794. }
  3795. console.error('PDFLinkService_setHash: \'' + unescape(hash) + '\' is not a valid destination.');
  3796. }
  3797. },
  3798. executeNamedAction: function PDFLinkService_executeNamedAction(action) {
  3799. switch (action) {
  3800. case 'GoBack':
  3801. if (this.pdfHistory) {
  3802. this.pdfHistory.back();
  3803. }
  3804. break;
  3805. case 'GoForward':
  3806. if (this.pdfHistory) {
  3807. this.pdfHistory.forward();
  3808. }
  3809. break;
  3810. case 'NextPage':
  3811. if (this.page < this.pagesCount) {
  3812. this.page++;
  3813. }
  3814. break;
  3815. case 'PrevPage':
  3816. if (this.page > 1) {
  3817. this.page--;
  3818. }
  3819. break;
  3820. case 'LastPage':
  3821. this.page = this.pagesCount;
  3822. break;
  3823. case 'FirstPage':
  3824. this.page = 1;
  3825. break;
  3826. default:
  3827. break;
  3828. }
  3829. this.eventBus.dispatch('namedaction', {
  3830. source: this,
  3831. action: action
  3832. });
  3833. },
  3834. cachePageRef: function PDFLinkService_cachePageRef(pageNum, pageRef) {
  3835. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  3836. this._pagesRefCache[refStr] = pageNum;
  3837. },
  3838. _cachedPageNumber: function PDFLinkService_cachedPageNumber(pageRef) {
  3839. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  3840. return this._pagesRefCache && this._pagesRefCache[refStr] || null;
  3841. }
  3842. };
  3843. function isValidExplicitDestination(dest) {
  3844. if (!(dest instanceof Array)) {
  3845. return false;
  3846. }
  3847. var destLength = dest.length, allowNull = true;
  3848. if (destLength < 2) {
  3849. return false;
  3850. }
  3851. var page = dest[0];
  3852. if (!(typeof page === 'object' && typeof page.num === 'number' && (page.num | 0) === page.num && typeof page.gen === 'number' && (page.gen | 0) === page.gen) && !(typeof page === 'number' && (page | 0) === page && page >= 0)) {
  3853. return false;
  3854. }
  3855. var zoom = dest[1];
  3856. if (!(typeof zoom === 'object' && typeof zoom.name === 'string')) {
  3857. return false;
  3858. }
  3859. switch (zoom.name) {
  3860. case 'XYZ':
  3861. if (destLength !== 5) {
  3862. return false;
  3863. }
  3864. break;
  3865. case 'Fit':
  3866. case 'FitB':
  3867. return destLength === 2;
  3868. case 'FitH':
  3869. case 'FitBH':
  3870. case 'FitV':
  3871. case 'FitBV':
  3872. if (destLength !== 3) {
  3873. return false;
  3874. }
  3875. break;
  3876. case 'FitR':
  3877. if (destLength !== 6) {
  3878. return false;
  3879. }
  3880. allowNull = false;
  3881. break;
  3882. default:
  3883. return false;
  3884. }
  3885. for (var i = 2; i < destLength; i++) {
  3886. var param = dest[i];
  3887. if (!(typeof param === 'number' || allowNull && param === null)) {
  3888. return false;
  3889. }
  3890. }
  3891. return true;
  3892. }
  3893. return PDFLinkService;
  3894. }();
  3895. var SimpleLinkService = function SimpleLinkServiceClosure() {
  3896. function SimpleLinkService() {
  3897. }
  3898. SimpleLinkService.prototype = {
  3899. get page() {
  3900. return 0;
  3901. },
  3902. set page(value) {
  3903. },
  3904. navigateTo: function (dest) {
  3905. },
  3906. getDestinationHash: function (dest) {
  3907. return '#';
  3908. },
  3909. getAnchorUrl: function (hash) {
  3910. return '#';
  3911. },
  3912. setHash: function (hash) {
  3913. },
  3914. executeNamedAction: function (action) {
  3915. },
  3916. cachePageRef: function (pageNum, pageRef) {
  3917. }
  3918. };
  3919. return SimpleLinkService;
  3920. }();
  3921. exports.PDFLinkService = PDFLinkService;
  3922. exports.SimpleLinkService = SimpleLinkService;
  3923. }));
  3924. (function (root, factory) {
  3925. factory(root.pdfjsWebPDFPageView = {}, root.pdfjsWebUIUtils, root.pdfjsWebPDFRenderingQueue, root.pdfjsWebDOMEvents, root.pdfjsWebPDFJS);
  3926. }(this, function (exports, uiUtils, pdfRenderingQueue, domEvents, pdfjsLib) {
  3927. var CSS_UNITS = uiUtils.CSS_UNITS;
  3928. var DEFAULT_SCALE = uiUtils.DEFAULT_SCALE;
  3929. var getOutputScale = uiUtils.getOutputScale;
  3930. var approximateFraction = uiUtils.approximateFraction;
  3931. var roundToDivide = uiUtils.roundToDivide;
  3932. var RendererType = uiUtils.RendererType;
  3933. var RenderingStates = pdfRenderingQueue.RenderingStates;
  3934. var TEXT_LAYER_RENDER_DELAY = 200;
  3935. var PDFPageView = function PDFPageViewClosure() {
  3936. function PDFPageView(options) {
  3937. var container = options.container;
  3938. var id = options.id;
  3939. var scale = options.scale;
  3940. var defaultViewport = options.defaultViewport;
  3941. var renderingQueue = options.renderingQueue;
  3942. var textLayerFactory = options.textLayerFactory;
  3943. var annotationLayerFactory = options.annotationLayerFactory;
  3944. var enhanceTextSelection = options.enhanceTextSelection || false;
  3945. var renderInteractiveForms = options.renderInteractiveForms || false;
  3946. this.id = id;
  3947. this.renderingId = 'page' + id;
  3948. this.pageLabel = null;
  3949. this.rotation = 0;
  3950. this.scale = scale || DEFAULT_SCALE;
  3951. this.viewport = defaultViewport;
  3952. this.pdfPageRotate = defaultViewport.rotation;
  3953. this.hasRestrictedScaling = false;
  3954. this.enhanceTextSelection = enhanceTextSelection;
  3955. this.renderInteractiveForms = renderInteractiveForms;
  3956. this.eventBus = options.eventBus || domEvents.getGlobalEventBus();
  3957. this.renderingQueue = renderingQueue;
  3958. this.textLayerFactory = textLayerFactory;
  3959. this.annotationLayerFactory = annotationLayerFactory;
  3960. this.renderer = options.renderer || RendererType.CANVAS;
  3961. this.paintTask = null;
  3962. this.paintedViewportMap = new WeakMap();
  3963. this.renderingState = RenderingStates.INITIAL;
  3964. this.resume = null;
  3965. this.error = null;
  3966. this.onBeforeDraw = null;
  3967. this.onAfterDraw = null;
  3968. this.textLayer = null;
  3969. this.zoomLayer = null;
  3970. this.annotationLayer = null;
  3971. var div = document.createElement('div');
  3972. div.className = 'page';
  3973. div.style.width = Math.floor(this.viewport.width) + 'px';
  3974. div.style.height = Math.floor(this.viewport.height) + 'px';
  3975. div.setAttribute('data-page-number', this.id);
  3976. this.div = div;
  3977. container.appendChild(div);
  3978. }
  3979. PDFPageView.prototype = {
  3980. setPdfPage: function PDFPageView_setPdfPage(pdfPage) {
  3981. this.pdfPage = pdfPage;
  3982. this.pdfPageRotate = pdfPage.rotate;
  3983. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  3984. this.viewport = pdfPage.getViewport(this.scale * CSS_UNITS, totalRotation);
  3985. this.stats = pdfPage.stats;
  3986. this.reset();
  3987. },
  3988. destroy: function PDFPageView_destroy() {
  3989. this.zoomLayer = null;
  3990. this.reset();
  3991. if (this.pdfPage) {
  3992. this.pdfPage.cleanup();
  3993. }
  3994. },
  3995. reset: function PDFPageView_reset(keepZoomLayer, keepAnnotations) {
  3996. this.cancelRendering();
  3997. var div = this.div;
  3998. div.style.width = Math.floor(this.viewport.width) + 'px';
  3999. div.style.height = Math.floor(this.viewport.height) + 'px';
  4000. var childNodes = div.childNodes;
  4001. var currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  4002. var currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
  4003. for (var i = childNodes.length - 1; i >= 0; i--) {
  4004. var node = childNodes[i];
  4005. if (currentZoomLayerNode === node || currentAnnotationNode === node) {
  4006. continue;
  4007. }
  4008. div.removeChild(node);
  4009. }
  4010. div.removeAttribute('data-loaded');
  4011. if (currentAnnotationNode) {
  4012. this.annotationLayer.hide();
  4013. } else {
  4014. this.annotationLayer = null;
  4015. }
  4016. if (this.canvas && !currentZoomLayerNode) {
  4017. this.paintedViewportMap.delete(this.canvas);
  4018. this.canvas.width = 0;
  4019. this.canvas.height = 0;
  4020. delete this.canvas;
  4021. }
  4022. if (this.svg) {
  4023. this.paintedViewportMap.delete(this.svg);
  4024. delete this.svg;
  4025. }
  4026. this.loadingIconDiv = document.createElement('div');
  4027. this.loadingIconDiv.className = 'loadingIcon';
  4028. div.appendChild(this.loadingIconDiv);
  4029. },
  4030. update: function PDFPageView_update(scale, rotation) {
  4031. this.scale = scale || this.scale;
  4032. if (typeof rotation !== 'undefined') {
  4033. this.rotation = rotation;
  4034. }
  4035. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  4036. this.viewport = this.viewport.clone({
  4037. scale: this.scale * CSS_UNITS,
  4038. rotation: totalRotation
  4039. });
  4040. if (this.svg) {
  4041. this.cssTransform(this.svg, true);
  4042. this.eventBus.dispatch('pagerendered', {
  4043. source: this,
  4044. pageNumber: this.id,
  4045. cssTransform: true
  4046. });
  4047. return;
  4048. }
  4049. var isScalingRestricted = false;
  4050. if (this.canvas && pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  4051. var outputScale = this.outputScale;
  4052. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > pdfjsLib.PDFJS.maxCanvasPixels) {
  4053. isScalingRestricted = true;
  4054. }
  4055. }
  4056. if (this.canvas) {
  4057. if (pdfjsLib.PDFJS.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  4058. this.cssTransform(this.canvas, true);
  4059. this.eventBus.dispatch('pagerendered', {
  4060. source: this,
  4061. pageNumber: this.id,
  4062. cssTransform: true
  4063. });
  4064. return;
  4065. }
  4066. if (!this.zoomLayer) {
  4067. this.zoomLayer = this.canvas.parentNode;
  4068. this.zoomLayer.style.position = 'absolute';
  4069. }
  4070. }
  4071. if (this.zoomLayer) {
  4072. this.cssTransform(this.zoomLayer.firstChild);
  4073. }
  4074. this.reset(true, true);
  4075. },
  4076. cancelRendering: function PDFPageView_cancelRendering() {
  4077. if (this.paintTask) {
  4078. this.paintTask.cancel();
  4079. this.paintTask = null;
  4080. }
  4081. this.renderingState = RenderingStates.INITIAL;
  4082. this.resume = null;
  4083. if (this.textLayer) {
  4084. this.textLayer.cancel();
  4085. this.textLayer = null;
  4086. }
  4087. },
  4088. updatePosition: function PDFPageView_updatePosition() {
  4089. if (this.textLayer) {
  4090. this.textLayer.render(TEXT_LAYER_RENDER_DELAY);
  4091. }
  4092. },
  4093. cssTransform: function PDFPageView_transform(target, redrawAnnotations) {
  4094. var CustomStyle = pdfjsLib.CustomStyle;
  4095. var width = this.viewport.width;
  4096. var height = this.viewport.height;
  4097. var div = this.div;
  4098. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + 'px';
  4099. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + 'px';
  4100. var relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  4101. var absRotation = Math.abs(relativeRotation);
  4102. var scaleX = 1, scaleY = 1;
  4103. if (absRotation === 90 || absRotation === 270) {
  4104. scaleX = height / width;
  4105. scaleY = width / height;
  4106. }
  4107. var cssTransform = 'rotate(' + relativeRotation + 'deg) ' + 'scale(' + scaleX + ',' + scaleY + ')';
  4108. CustomStyle.setProp('transform', target, cssTransform);
  4109. if (this.textLayer) {
  4110. var textLayerViewport = this.textLayer.viewport;
  4111. var textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  4112. var textAbsRotation = Math.abs(textRelativeRotation);
  4113. var scale = width / textLayerViewport.width;
  4114. if (textAbsRotation === 90 || textAbsRotation === 270) {
  4115. scale = width / textLayerViewport.height;
  4116. }
  4117. var textLayerDiv = this.textLayer.textLayerDiv;
  4118. var transX, transY;
  4119. switch (textAbsRotation) {
  4120. case 0:
  4121. transX = transY = 0;
  4122. break;
  4123. case 90:
  4124. transX = 0;
  4125. transY = '-' + textLayerDiv.style.height;
  4126. break;
  4127. case 180:
  4128. transX = '-' + textLayerDiv.style.width;
  4129. transY = '-' + textLayerDiv.style.height;
  4130. break;
  4131. case 270:
  4132. transX = '-' + textLayerDiv.style.width;
  4133. transY = 0;
  4134. break;
  4135. default:
  4136. console.error('Bad rotation value.');
  4137. break;
  4138. }
  4139. CustomStyle.setProp('transform', textLayerDiv, 'rotate(' + textAbsRotation + 'deg) ' + 'scale(' + scale + ', ' + scale + ') ' + 'translate(' + transX + ', ' + transY + ')');
  4140. CustomStyle.setProp('transformOrigin', textLayerDiv, '0% 0%');
  4141. }
  4142. if (redrawAnnotations && this.annotationLayer) {
  4143. this.annotationLayer.render(this.viewport, 'display');
  4144. }
  4145. },
  4146. get width() {
  4147. return this.viewport.width;
  4148. },
  4149. get height() {
  4150. return this.viewport.height;
  4151. },
  4152. getPagePoint: function PDFPageView_getPagePoint(x, y) {
  4153. return this.viewport.convertToPdfPoint(x, y);
  4154. },
  4155. draw: function PDFPageView_draw() {
  4156. if (this.renderingState !== RenderingStates.INITIAL) {
  4157. console.error('Must be in new state before drawing');
  4158. this.reset();
  4159. }
  4160. this.renderingState = RenderingStates.RUNNING;
  4161. var self = this;
  4162. var pdfPage = this.pdfPage;
  4163. var viewport = this.viewport;
  4164. var div = this.div;
  4165. var canvasWrapper = document.createElement('div');
  4166. canvasWrapper.style.width = div.style.width;
  4167. canvasWrapper.style.height = div.style.height;
  4168. canvasWrapper.classList.add('canvasWrapper');
  4169. if (this.annotationLayer && this.annotationLayer.div) {
  4170. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  4171. } else {
  4172. div.appendChild(canvasWrapper);
  4173. }
  4174. var textLayerDiv = null;
  4175. var textLayer = null;
  4176. if (this.textLayerFactory) {
  4177. textLayerDiv = document.createElement('div');
  4178. textLayerDiv.className = 'textLayer';
  4179. textLayerDiv.style.width = canvasWrapper.style.width;
  4180. textLayerDiv.style.height = canvasWrapper.style.height;
  4181. if (this.annotationLayer && this.annotationLayer.div) {
  4182. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  4183. } else {
  4184. div.appendChild(textLayerDiv);
  4185. }
  4186. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.enhanceTextSelection);
  4187. }
  4188. this.textLayer = textLayer;
  4189. var renderContinueCallback = null;
  4190. if (this.renderingQueue) {
  4191. renderContinueCallback = function renderContinueCallback(cont) {
  4192. if (!self.renderingQueue.isHighestPriority(self)) {
  4193. self.renderingState = RenderingStates.PAUSED;
  4194. self.resume = function resumeCallback() {
  4195. self.renderingState = RenderingStates.RUNNING;
  4196. cont();
  4197. };
  4198. return;
  4199. }
  4200. cont();
  4201. };
  4202. }
  4203. var finishPaintTask = function finishPaintTask(error) {
  4204. if (paintTask === self.paintTask) {
  4205. self.paintTask = null;
  4206. }
  4207. if (error === 'cancelled') {
  4208. self.error = null;
  4209. return Promise.resolve(undefined);
  4210. }
  4211. self.renderingState = RenderingStates.FINISHED;
  4212. if (self.loadingIconDiv) {
  4213. div.removeChild(self.loadingIconDiv);
  4214. delete self.loadingIconDiv;
  4215. }
  4216. if (self.zoomLayer) {
  4217. var zoomLayerCanvas = self.zoomLayer.firstChild;
  4218. self.paintedViewportMap.delete(zoomLayerCanvas);
  4219. zoomLayerCanvas.width = 0;
  4220. zoomLayerCanvas.height = 0;
  4221. if (div.contains(self.zoomLayer)) {
  4222. div.removeChild(self.zoomLayer);
  4223. }
  4224. self.zoomLayer = null;
  4225. }
  4226. self.error = error;
  4227. self.stats = pdfPage.stats;
  4228. if (self.onAfterDraw) {
  4229. self.onAfterDraw();
  4230. }
  4231. self.eventBus.dispatch('pagerendered', {
  4232. source: self,
  4233. pageNumber: self.id,
  4234. cssTransform: false
  4235. });
  4236. if (error) {
  4237. return Promise.reject(error);
  4238. }
  4239. return Promise.resolve(undefined);
  4240. };
  4241. var paintTask = this.renderer === RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  4242. paintTask.onRenderContinue = renderContinueCallback;
  4243. this.paintTask = paintTask;
  4244. var resultPromise = paintTask.promise.then(function () {
  4245. return finishPaintTask(null).then(function () {
  4246. if (textLayer) {
  4247. pdfPage.getTextContent({ normalizeWhitespace: true }).then(function textContentResolved(textContent) {
  4248. textLayer.setTextContent(textContent);
  4249. textLayer.render(TEXT_LAYER_RENDER_DELAY);
  4250. });
  4251. }
  4252. });
  4253. }, function (reason) {
  4254. return finishPaintTask(reason);
  4255. });
  4256. if (this.annotationLayerFactory) {
  4257. if (!this.annotationLayer) {
  4258. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.renderInteractiveForms);
  4259. }
  4260. this.annotationLayer.render(this.viewport, 'display');
  4261. }
  4262. div.setAttribute('data-loaded', true);
  4263. if (this.onBeforeDraw) {
  4264. this.onBeforeDraw();
  4265. }
  4266. return resultPromise;
  4267. },
  4268. paintOnCanvas: function (canvasWrapper) {
  4269. var resolveRenderPromise, rejectRenderPromise;
  4270. var promise = new Promise(function (resolve, reject) {
  4271. resolveRenderPromise = resolve;
  4272. rejectRenderPromise = reject;
  4273. });
  4274. var result = {
  4275. promise: promise,
  4276. onRenderContinue: function (cont) {
  4277. cont();
  4278. },
  4279. cancel: function () {
  4280. renderTask.cancel();
  4281. }
  4282. };
  4283. var self = this;
  4284. var pdfPage = this.pdfPage;
  4285. var viewport = this.viewport;
  4286. var canvas = document.createElement('canvas');
  4287. canvas.id = 'page' + this.id;
  4288. canvas.setAttribute('hidden', 'hidden');
  4289. var isCanvasHidden = true;
  4290. var showCanvas = function () {
  4291. if (isCanvasHidden) {
  4292. canvas.removeAttribute('hidden');
  4293. isCanvasHidden = false;
  4294. }
  4295. };
  4296. canvasWrapper.appendChild(canvas);
  4297. this.canvas = canvas;
  4298. canvas.mozOpaque = true;
  4299. var ctx = canvas.getContext('2d', { alpha: false });
  4300. var outputScale = getOutputScale(ctx);
  4301. this.outputScale = outputScale;
  4302. if (pdfjsLib.PDFJS.useOnlyCssZoom) {
  4303. var actualSizeViewport = viewport.clone({ scale: CSS_UNITS });
  4304. outputScale.sx *= actualSizeViewport.width / viewport.width;
  4305. outputScale.sy *= actualSizeViewport.height / viewport.height;
  4306. outputScale.scaled = true;
  4307. }
  4308. if (pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  4309. var pixelsInViewport = viewport.width * viewport.height;
  4310. var maxScale = Math.sqrt(pdfjsLib.PDFJS.maxCanvasPixels / pixelsInViewport);
  4311. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  4312. outputScale.sx = maxScale;
  4313. outputScale.sy = maxScale;
  4314. outputScale.scaled = true;
  4315. this.hasRestrictedScaling = true;
  4316. } else {
  4317. this.hasRestrictedScaling = false;
  4318. }
  4319. }
  4320. var sfx = approximateFraction(outputScale.sx);
  4321. var sfy = approximateFraction(outputScale.sy);
  4322. canvas.width = roundToDivide(viewport.width * outputScale.sx, sfx[0]);
  4323. canvas.height = roundToDivide(viewport.height * outputScale.sy, sfy[0]);
  4324. canvas.style.width = roundToDivide(viewport.width, sfx[1]) + 'px';
  4325. canvas.style.height = roundToDivide(viewport.height, sfy[1]) + 'px';
  4326. this.paintedViewportMap.set(canvas, viewport);
  4327. var transform = !outputScale.scaled ? null : [
  4328. outputScale.sx,
  4329. 0,
  4330. 0,
  4331. outputScale.sy,
  4332. 0,
  4333. 0
  4334. ];
  4335. var renderContext = {
  4336. canvasContext: ctx,
  4337. transform: transform,
  4338. viewport: this.viewport,
  4339. renderInteractiveForms: this.renderInteractiveForms
  4340. };
  4341. var renderTask = this.pdfPage.render(renderContext);
  4342. renderTask.onContinue = function (cont) {
  4343. showCanvas();
  4344. if (result.onRenderContinue) {
  4345. result.onRenderContinue(cont);
  4346. } else {
  4347. cont();
  4348. }
  4349. };
  4350. renderTask.promise.then(function pdfPageRenderCallback() {
  4351. showCanvas();
  4352. resolveRenderPromise(undefined);
  4353. }, function pdfPageRenderError(error) {
  4354. showCanvas();
  4355. rejectRenderPromise(error);
  4356. });
  4357. return result;
  4358. },
  4359. paintOnSvg: function PDFPageView_paintOnSvg(wrapper) {
  4360. var cancelled = false;
  4361. var ensureNotCancelled = function () {
  4362. if (cancelled) {
  4363. throw 'cancelled';
  4364. }
  4365. };
  4366. var self = this;
  4367. var pdfPage = this.pdfPage;
  4368. var SVGGraphics = pdfjsLib.SVGGraphics;
  4369. var actualSizeViewport = this.viewport.clone({ scale: CSS_UNITS });
  4370. var promise = pdfPage.getOperatorList().then(function (opList) {
  4371. ensureNotCancelled();
  4372. var svgGfx = new SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  4373. return svgGfx.getSVG(opList, actualSizeViewport).then(function (svg) {
  4374. ensureNotCancelled();
  4375. self.svg = svg;
  4376. self.paintedViewportMap.set(svg, actualSizeViewport);
  4377. svg.style.width = wrapper.style.width;
  4378. svg.style.height = wrapper.style.height;
  4379. self.renderingState = RenderingStates.FINISHED;
  4380. wrapper.appendChild(svg);
  4381. });
  4382. });
  4383. return {
  4384. promise: promise,
  4385. onRenderContinue: function (cont) {
  4386. cont();
  4387. },
  4388. cancel: function () {
  4389. cancelled = true;
  4390. }
  4391. };
  4392. },
  4393. setPageLabel: function PDFView_setPageLabel(label) {
  4394. this.pageLabel = typeof label === 'string' ? label : null;
  4395. if (this.pageLabel !== null) {
  4396. this.div.setAttribute('data-page-label', this.pageLabel);
  4397. } else {
  4398. this.div.removeAttribute('data-page-label');
  4399. }
  4400. }
  4401. };
  4402. return PDFPageView;
  4403. }();
  4404. exports.PDFPageView = PDFPageView;
  4405. }));
  4406. (function (root, factory) {
  4407. factory(root.pdfjsWebPDFThumbnailViewer = {}, root.pdfjsWebUIUtils, root.pdfjsWebPDFThumbnailView);
  4408. }(this, function (exports, uiUtils, pdfThumbnailView) {
  4409. var watchScroll = uiUtils.watchScroll;
  4410. var getVisibleElements = uiUtils.getVisibleElements;
  4411. var scrollIntoView = uiUtils.scrollIntoView;
  4412. var PDFThumbnailView = pdfThumbnailView.PDFThumbnailView;
  4413. var THUMBNAIL_SCROLL_MARGIN = -19;
  4414. var PDFThumbnailViewer = function PDFThumbnailViewerClosure() {
  4415. function PDFThumbnailViewer(options) {
  4416. this.container = options.container;
  4417. this.renderingQueue = options.renderingQueue;
  4418. this.linkService = options.linkService;
  4419. this.scroll = watchScroll(this.container, this._scrollUpdated.bind(this));
  4420. this._resetView();
  4421. }
  4422. PDFThumbnailViewer.prototype = {
  4423. _scrollUpdated: function PDFThumbnailViewer_scrollUpdated() {
  4424. this.renderingQueue.renderHighestPriority();
  4425. },
  4426. getThumbnail: function PDFThumbnailViewer_getThumbnail(index) {
  4427. return this.thumbnails[index];
  4428. },
  4429. _getVisibleThumbs: function PDFThumbnailViewer_getVisibleThumbs() {
  4430. return getVisibleElements(this.container, this.thumbnails);
  4431. },
  4432. scrollThumbnailIntoView: function PDFThumbnailViewer_scrollThumbnailIntoView(page) {
  4433. var selected = document.querySelector('.thumbnail.selected');
  4434. if (selected) {
  4435. selected.classList.remove('selected');
  4436. }
  4437. var thumbnail = document.querySelector('div.thumbnail[data-page-number="' + page + '"]');
  4438. if (thumbnail) {
  4439. thumbnail.classList.add('selected');
  4440. }
  4441. var visibleThumbs = this._getVisibleThumbs();
  4442. var numVisibleThumbs = visibleThumbs.views.length;
  4443. if (numVisibleThumbs > 0) {
  4444. var first = visibleThumbs.first.id;
  4445. var last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
  4446. if (page <= first || page >= last) {
  4447. scrollIntoView(thumbnail, { top: THUMBNAIL_SCROLL_MARGIN });
  4448. }
  4449. }
  4450. },
  4451. get pagesRotation() {
  4452. return this._pagesRotation;
  4453. },
  4454. set pagesRotation(rotation) {
  4455. this._pagesRotation = rotation;
  4456. for (var i = 0, l = this.thumbnails.length; i < l; i++) {
  4457. var thumb = this.thumbnails[i];
  4458. thumb.update(rotation);
  4459. }
  4460. },
  4461. cleanup: function PDFThumbnailViewer_cleanup() {
  4462. var tempCanvas = PDFThumbnailView.tempImageCache;
  4463. if (tempCanvas) {
  4464. tempCanvas.width = 0;
  4465. tempCanvas.height = 0;
  4466. }
  4467. PDFThumbnailView.tempImageCache = null;
  4468. },
  4469. _resetView: function PDFThumbnailViewer_resetView() {
  4470. this.thumbnails = [];
  4471. this._pageLabels = null;
  4472. this._pagesRotation = 0;
  4473. this._pagesRequests = [];
  4474. this.container.textContent = '';
  4475. },
  4476. setDocument: function PDFThumbnailViewer_setDocument(pdfDocument) {
  4477. if (this.pdfDocument) {
  4478. this._cancelRendering();
  4479. this._resetView();
  4480. }
  4481. this.pdfDocument = pdfDocument;
  4482. if (!pdfDocument) {
  4483. return Promise.resolve();
  4484. }
  4485. return pdfDocument.getPage(1).then(function (firstPage) {
  4486. var pagesCount = pdfDocument.numPages;
  4487. var viewport = firstPage.getViewport(1.0);
  4488. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  4489. var thumbnail = new PDFThumbnailView({
  4490. container: this.container,
  4491. id: pageNum,
  4492. defaultViewport: viewport.clone(),
  4493. linkService: this.linkService,
  4494. renderingQueue: this.renderingQueue,
  4495. disableCanvasToImageConversion: false
  4496. });
  4497. this.thumbnails.push(thumbnail);
  4498. }
  4499. }.bind(this));
  4500. },
  4501. _cancelRendering: function PDFThumbnailViewer_cancelRendering() {
  4502. for (var i = 0, ii = this.thumbnails.length; i < ii; i++) {
  4503. if (this.thumbnails[i]) {
  4504. this.thumbnails[i].cancelRendering();
  4505. }
  4506. }
  4507. },
  4508. setPageLabels: function PDFThumbnailViewer_setPageLabels(labels) {
  4509. if (!this.pdfDocument) {
  4510. return;
  4511. }
  4512. if (!labels) {
  4513. this._pageLabels = null;
  4514. } else if (!(labels instanceof Array && this.pdfDocument.numPages === labels.length)) {
  4515. this._pageLabels = null;
  4516. console.error('PDFThumbnailViewer_setPageLabels: Invalid page labels.');
  4517. } else {
  4518. this._pageLabels = labels;
  4519. }
  4520. for (var i = 0, ii = this.thumbnails.length; i < ii; i++) {
  4521. var thumbnailView = this.thumbnails[i];
  4522. var label = this._pageLabels && this._pageLabels[i];
  4523. thumbnailView.setPageLabel(label);
  4524. }
  4525. },
  4526. _ensurePdfPageLoaded: function PDFThumbnailViewer_ensurePdfPageLoaded(thumbView) {
  4527. if (thumbView.pdfPage) {
  4528. return Promise.resolve(thumbView.pdfPage);
  4529. }
  4530. var pageNumber = thumbView.id;
  4531. if (this._pagesRequests[pageNumber]) {
  4532. return this._pagesRequests[pageNumber];
  4533. }
  4534. var promise = this.pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  4535. thumbView.setPdfPage(pdfPage);
  4536. this._pagesRequests[pageNumber] = null;
  4537. return pdfPage;
  4538. }.bind(this));
  4539. this._pagesRequests[pageNumber] = promise;
  4540. return promise;
  4541. },
  4542. forceRendering: function () {
  4543. var visibleThumbs = this._getVisibleThumbs();
  4544. var thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this.thumbnails, this.scroll.down);
  4545. if (thumbView) {
  4546. this._ensurePdfPageLoaded(thumbView).then(function () {
  4547. this.renderingQueue.renderView(thumbView);
  4548. }.bind(this));
  4549. return true;
  4550. }
  4551. return false;
  4552. }
  4553. };
  4554. return PDFThumbnailViewer;
  4555. }();
  4556. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  4557. }));
  4558. (function (root, factory) {
  4559. factory(root.pdfjsWebTextLayerBuilder = {}, root.pdfjsWebDOMEvents, root.pdfjsWebPDFJS);
  4560. }(this, function (exports, domEvents, pdfjsLib) {
  4561. var EXPAND_DIVS_TIMEOUT = 300;
  4562. var TextLayerBuilder = function TextLayerBuilderClosure() {
  4563. function TextLayerBuilder(options) {
  4564. this.textLayerDiv = options.textLayerDiv;
  4565. this.eventBus = options.eventBus || domEvents.getGlobalEventBus();
  4566. this.textContent = null;
  4567. this.renderingDone = false;
  4568. this.pageIdx = options.pageIndex;
  4569. this.pageNumber = this.pageIdx + 1;
  4570. this.matches = [];
  4571. this.viewport = options.viewport;
  4572. this.textDivs = [];
  4573. this.findController = options.findController || null;
  4574. this.textLayerRenderTask = null;
  4575. this.enhanceTextSelection = options.enhanceTextSelection;
  4576. this._bindMouse();
  4577. }
  4578. TextLayerBuilder.prototype = {
  4579. _finishRendering: function TextLayerBuilder_finishRendering() {
  4580. this.renderingDone = true;
  4581. if (!this.enhanceTextSelection) {
  4582. var endOfContent = document.createElement('div');
  4583. endOfContent.className = 'endOfContent';
  4584. this.textLayerDiv.appendChild(endOfContent);
  4585. }
  4586. this.eventBus.dispatch('textlayerrendered', {
  4587. source: this,
  4588. pageNumber: this.pageNumber,
  4589. numTextDivs: this.textDivs.length
  4590. });
  4591. },
  4592. render: function TextLayerBuilder_render(timeout) {
  4593. if (!this.textContent || this.renderingDone) {
  4594. return;
  4595. }
  4596. this.cancel();
  4597. this.textDivs = [];
  4598. var textLayerFrag = document.createDocumentFragment();
  4599. this.textLayerRenderTask = pdfjsLib.renderTextLayer({
  4600. textContent: this.textContent,
  4601. container: textLayerFrag,
  4602. viewport: this.viewport,
  4603. textDivs: this.textDivs,
  4604. timeout: timeout,
  4605. enhanceTextSelection: this.enhanceTextSelection
  4606. });
  4607. this.textLayerRenderTask.promise.then(function () {
  4608. this.textLayerDiv.appendChild(textLayerFrag);
  4609. this._finishRendering();
  4610. this.updateMatches();
  4611. }.bind(this), function (reason) {
  4612. });
  4613. },
  4614. cancel: function TextLayerBuilder_cancel() {
  4615. if (this.textLayerRenderTask) {
  4616. this.textLayerRenderTask.cancel();
  4617. this.textLayerRenderTask = null;
  4618. }
  4619. },
  4620. setTextContent: function TextLayerBuilder_setTextContent(textContent) {
  4621. this.cancel();
  4622. this.textContent = textContent;
  4623. },
  4624. convertMatches: function TextLayerBuilder_convertMatches(matches, matchesLength) {
  4625. var i = 0;
  4626. var iIndex = 0;
  4627. var bidiTexts = this.textContent.items;
  4628. var end = bidiTexts.length - 1;
  4629. var queryLen = this.findController === null ? 0 : this.findController.state.query.length;
  4630. var ret = [];
  4631. if (!matches) {
  4632. return ret;
  4633. }
  4634. for (var m = 0, len = matches.length; m < len; m++) {
  4635. var matchIdx = matches[m];
  4636. while (i !== end && matchIdx >= iIndex + bidiTexts[i].str.length) {
  4637. iIndex += bidiTexts[i].str.length;
  4638. i++;
  4639. }
  4640. if (i === bidiTexts.length) {
  4641. console.error('Could not find a matching mapping');
  4642. }
  4643. var match = {
  4644. begin: {
  4645. divIdx: i,
  4646. offset: matchIdx - iIndex
  4647. }
  4648. };
  4649. if (matchesLength) {
  4650. matchIdx += matchesLength[m];
  4651. } else {
  4652. matchIdx += queryLen;
  4653. }
  4654. while (i !== end && matchIdx > iIndex + bidiTexts[i].str.length) {
  4655. iIndex += bidiTexts[i].str.length;
  4656. i++;
  4657. }
  4658. match.end = {
  4659. divIdx: i,
  4660. offset: matchIdx - iIndex
  4661. };
  4662. ret.push(match);
  4663. }
  4664. return ret;
  4665. },
  4666. renderMatches: function TextLayerBuilder_renderMatches(matches) {
  4667. if (matches.length === 0) {
  4668. return;
  4669. }
  4670. var bidiTexts = this.textContent.items;
  4671. var textDivs = this.textDivs;
  4672. var prevEnd = null;
  4673. var pageIdx = this.pageIdx;
  4674. var isSelectedPage = this.findController === null ? false : pageIdx === this.findController.selected.pageIdx;
  4675. var selectedMatchIdx = this.findController === null ? -1 : this.findController.selected.matchIdx;
  4676. var highlightAll = this.findController === null ? false : this.findController.state.highlightAll;
  4677. var infinity = {
  4678. divIdx: -1,
  4679. offset: undefined
  4680. };
  4681. function beginText(begin, className) {
  4682. var divIdx = begin.divIdx;
  4683. textDivs[divIdx].textContent = '';
  4684. appendTextToDiv(divIdx, 0, begin.offset, className);
  4685. }
  4686. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  4687. var div = textDivs[divIdx];
  4688. var content = bidiTexts[divIdx].str.substring(fromOffset, toOffset);
  4689. var node = document.createTextNode(content);
  4690. if (className) {
  4691. var span = document.createElement('span');
  4692. span.className = className;
  4693. span.appendChild(node);
  4694. div.appendChild(span);
  4695. return;
  4696. }
  4697. div.appendChild(node);
  4698. }
  4699. var i0 = selectedMatchIdx, i1 = i0 + 1;
  4700. if (highlightAll) {
  4701. i0 = 0;
  4702. i1 = matches.length;
  4703. } else if (!isSelectedPage) {
  4704. return;
  4705. }
  4706. for (var i = i0; i < i1; i++) {
  4707. var match = matches[i];
  4708. var begin = match.begin;
  4709. var end = match.end;
  4710. var isSelected = isSelectedPage && i === selectedMatchIdx;
  4711. var highlightSuffix = isSelected ? ' selected' : '';
  4712. if (this.findController) {
  4713. this.findController.updateMatchPosition(pageIdx, i, textDivs, begin.divIdx);
  4714. }
  4715. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  4716. if (prevEnd !== null) {
  4717. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  4718. }
  4719. beginText(begin);
  4720. } else {
  4721. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  4722. }
  4723. if (begin.divIdx === end.divIdx) {
  4724. appendTextToDiv(begin.divIdx, begin.offset, end.offset, 'highlight' + highlightSuffix);
  4725. } else {
  4726. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, 'highlight begin' + highlightSuffix);
  4727. for (var n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  4728. textDivs[n0].className = 'highlight middle' + highlightSuffix;
  4729. }
  4730. beginText(end, 'highlight end' + highlightSuffix);
  4731. }
  4732. prevEnd = end;
  4733. }
  4734. if (prevEnd) {
  4735. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  4736. }
  4737. },
  4738. updateMatches: function TextLayerBuilder_updateMatches() {
  4739. if (!this.renderingDone) {
  4740. return;
  4741. }
  4742. var matches = this.matches;
  4743. var textDivs = this.textDivs;
  4744. var bidiTexts = this.textContent.items;
  4745. var clearedUntilDivIdx = -1;
  4746. for (var i = 0, len = matches.length; i < len; i++) {
  4747. var match = matches[i];
  4748. var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  4749. for (var n = begin, end = match.end.divIdx; n <= end; n++) {
  4750. var div = textDivs[n];
  4751. div.textContent = bidiTexts[n].str;
  4752. div.className = '';
  4753. }
  4754. clearedUntilDivIdx = match.end.divIdx + 1;
  4755. }
  4756. if (this.findController === null || !this.findController.active) {
  4757. return;
  4758. }
  4759. var pageMatches, pageMatchesLength;
  4760. if (this.findController !== null) {
  4761. pageMatches = this.findController.pageMatches[this.pageIdx] || null;
  4762. pageMatchesLength = this.findController.pageMatchesLength ? this.findController.pageMatchesLength[this.pageIdx] || null : null;
  4763. }
  4764. this.matches = this.convertMatches(pageMatches, pageMatchesLength);
  4765. this.renderMatches(this.matches);
  4766. },
  4767. _bindMouse: function TextLayerBuilder_bindMouse() {
  4768. var div = this.textLayerDiv;
  4769. var self = this;
  4770. var expandDivsTimer = null;
  4771. div.addEventListener('mousedown', function (e) {
  4772. if (self.enhanceTextSelection && self.textLayerRenderTask) {
  4773. self.textLayerRenderTask.expandTextDivs(true);
  4774. if (expandDivsTimer) {
  4775. clearTimeout(expandDivsTimer);
  4776. expandDivsTimer = null;
  4777. }
  4778. return;
  4779. }
  4780. var end = div.querySelector('.endOfContent');
  4781. if (!end) {
  4782. return;
  4783. }
  4784. var adjustTop = e.target !== div;
  4785. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue('-moz-user-select') !== 'none';
  4786. if (adjustTop) {
  4787. var divBounds = div.getBoundingClientRect();
  4788. var r = Math.max(0, (e.pageY - divBounds.top) / divBounds.height);
  4789. end.style.top = (r * 100).toFixed(2) + '%';
  4790. }
  4791. end.classList.add('active');
  4792. });
  4793. div.addEventListener('mouseup', function (e) {
  4794. if (self.enhanceTextSelection && self.textLayerRenderTask) {
  4795. expandDivsTimer = setTimeout(function () {
  4796. if (self.textLayerRenderTask) {
  4797. self.textLayerRenderTask.expandTextDivs(false);
  4798. }
  4799. expandDivsTimer = null;
  4800. }, EXPAND_DIVS_TIMEOUT);
  4801. return;
  4802. }
  4803. var end = div.querySelector('.endOfContent');
  4804. if (!end) {
  4805. return;
  4806. }
  4807. end.style.top = '';
  4808. end.classList.remove('active');
  4809. });
  4810. }
  4811. };
  4812. return TextLayerBuilder;
  4813. }();
  4814. function DefaultTextLayerFactory() {
  4815. }
  4816. DefaultTextLayerFactory.prototype = {
  4817. createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport, enhanceTextSelection) {
  4818. return new TextLayerBuilder({
  4819. textLayerDiv: textLayerDiv,
  4820. pageIndex: pageIndex,
  4821. viewport: viewport,
  4822. enhanceTextSelection: enhanceTextSelection
  4823. });
  4824. }
  4825. };
  4826. exports.TextLayerBuilder = TextLayerBuilder;
  4827. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  4828. }));
  4829. (function (root, factory) {
  4830. factory(root.pdfjsWebAnnotationLayerBuilder = {}, root.pdfjsWebUIUtils, root.pdfjsWebPDFLinkService, root.pdfjsWebPDFJS);
  4831. }(this, function (exports, uiUtils, pdfLinkService, pdfjsLib) {
  4832. var mozL10n = uiUtils.mozL10n;
  4833. var SimpleLinkService = pdfLinkService.SimpleLinkService;
  4834. var AnnotationLayerBuilder = function AnnotationLayerBuilderClosure() {
  4835. function AnnotationLayerBuilder(options) {
  4836. this.pageDiv = options.pageDiv;
  4837. this.pdfPage = options.pdfPage;
  4838. this.renderInteractiveForms = options.renderInteractiveForms;
  4839. this.linkService = options.linkService;
  4840. this.downloadManager = options.downloadManager;
  4841. this.div = null;
  4842. }
  4843. AnnotationLayerBuilder.prototype = {
  4844. render: function AnnotationLayerBuilder_render(viewport, intent) {
  4845. var self = this;
  4846. var parameters = { intent: intent === undefined ? 'display' : intent };
  4847. this.pdfPage.getAnnotations(parameters).then(function (annotations) {
  4848. viewport = viewport.clone({ dontFlip: true });
  4849. parameters = {
  4850. viewport: viewport,
  4851. div: self.div,
  4852. annotations: annotations,
  4853. page: self.pdfPage,
  4854. renderInteractiveForms: self.renderInteractiveForms,
  4855. linkService: self.linkService,
  4856. downloadManager: self.downloadManager
  4857. };
  4858. if (self.div) {
  4859. pdfjsLib.AnnotationLayer.update(parameters);
  4860. } else {
  4861. if (annotations.length === 0) {
  4862. return;
  4863. }
  4864. self.div = document.createElement('div');
  4865. self.div.className = 'annotationLayer';
  4866. self.pageDiv.appendChild(self.div);
  4867. parameters.div = self.div;
  4868. pdfjsLib.AnnotationLayer.render(parameters);
  4869. if (typeof mozL10n !== 'undefined') {
  4870. mozL10n.translate(self.div);
  4871. }
  4872. }
  4873. });
  4874. },
  4875. hide: function AnnotationLayerBuilder_hide() {
  4876. if (!this.div) {
  4877. return;
  4878. }
  4879. this.div.setAttribute('hidden', 'true');
  4880. }
  4881. };
  4882. return AnnotationLayerBuilder;
  4883. }();
  4884. function DefaultAnnotationLayerFactory() {
  4885. }
  4886. DefaultAnnotationLayerFactory.prototype = {
  4887. createAnnotationLayerBuilder: function (pageDiv, pdfPage, renderInteractiveForms) {
  4888. return new AnnotationLayerBuilder({
  4889. pageDiv: pageDiv,
  4890. pdfPage: pdfPage,
  4891. renderInteractiveForms: renderInteractiveForms,
  4892. linkService: new SimpleLinkService()
  4893. });
  4894. }
  4895. };
  4896. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  4897. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  4898. }));
  4899. (function (root, factory) {
  4900. factory(root.pdfjsWebPDFViewer = {}, root.pdfjsWebUIUtils, root.pdfjsWebPDFPageView, root.pdfjsWebPDFRenderingQueue, root.pdfjsWebTextLayerBuilder, root.pdfjsWebAnnotationLayerBuilder, root.pdfjsWebPDFLinkService, root.pdfjsWebDOMEvents, root.pdfjsWebPDFJS);
  4901. }(this, function (exports, uiUtils, pdfPageView, pdfRenderingQueue, textLayerBuilder, annotationLayerBuilder, pdfLinkService, domEvents, pdfjsLib) {
  4902. var UNKNOWN_SCALE = uiUtils.UNKNOWN_SCALE;
  4903. var SCROLLBAR_PADDING = uiUtils.SCROLLBAR_PADDING;
  4904. var VERTICAL_PADDING = uiUtils.VERTICAL_PADDING;
  4905. var MAX_AUTO_SCALE = uiUtils.MAX_AUTO_SCALE;
  4906. var CSS_UNITS = uiUtils.CSS_UNITS;
  4907. var DEFAULT_SCALE = uiUtils.DEFAULT_SCALE;
  4908. var DEFAULT_SCALE_VALUE = uiUtils.DEFAULT_SCALE_VALUE;
  4909. var RendererType = uiUtils.RendererType;
  4910. var scrollIntoView = uiUtils.scrollIntoView;
  4911. var watchScroll = uiUtils.watchScroll;
  4912. var getVisibleElements = uiUtils.getVisibleElements;
  4913. var PDFPageView = pdfPageView.PDFPageView;
  4914. var RenderingStates = pdfRenderingQueue.RenderingStates;
  4915. var PDFRenderingQueue = pdfRenderingQueue.PDFRenderingQueue;
  4916. var TextLayerBuilder = textLayerBuilder.TextLayerBuilder;
  4917. var AnnotationLayerBuilder = annotationLayerBuilder.AnnotationLayerBuilder;
  4918. var SimpleLinkService = pdfLinkService.SimpleLinkService;
  4919. var PresentationModeState = {
  4920. UNKNOWN: 0,
  4921. NORMAL: 1,
  4922. CHANGING: 2,
  4923. FULLSCREEN: 3
  4924. };
  4925. var DEFAULT_CACHE_SIZE = 10;
  4926. var PDFViewer = function pdfViewer() {
  4927. function PDFPageViewBuffer(size) {
  4928. var data = [];
  4929. this.push = function cachePush(view) {
  4930. var i = data.indexOf(view);
  4931. if (i >= 0) {
  4932. data.splice(i, 1);
  4933. }
  4934. data.push(view);
  4935. if (data.length > size) {
  4936. data.shift().destroy();
  4937. }
  4938. };
  4939. this.resize = function (newSize) {
  4940. size = newSize;
  4941. while (data.length > size) {
  4942. data.shift().destroy();
  4943. }
  4944. };
  4945. }
  4946. function isSameScale(oldScale, newScale) {
  4947. if (newScale === oldScale) {
  4948. return true;
  4949. }
  4950. if (Math.abs(newScale - oldScale) < 1e-15) {
  4951. return true;
  4952. }
  4953. return false;
  4954. }
  4955. function PDFViewer(options) {
  4956. this.container = options.container;
  4957. this.viewer = options.viewer || options.container.firstElementChild;
  4958. this.eventBus = options.eventBus || domEvents.getGlobalEventBus();
  4959. this.linkService = options.linkService || new SimpleLinkService();
  4960. this.downloadManager = options.downloadManager || null;
  4961. this.removePageBorders = options.removePageBorders || false;
  4962. this.enhanceTextSelection = options.enhanceTextSelection || false;
  4963. this.renderInteractiveForms = options.renderInteractiveForms || false;
  4964. this.renderer = options.renderer || RendererType.CANVAS;
  4965. this.defaultRenderingQueue = !options.renderingQueue;
  4966. if (this.defaultRenderingQueue) {
  4967. this.renderingQueue = new PDFRenderingQueue();
  4968. this.renderingQueue.setViewer(this);
  4969. } else {
  4970. this.renderingQueue = options.renderingQueue;
  4971. }
  4972. this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this));
  4973. this.presentationModeState = PresentationModeState.UNKNOWN;
  4974. this._resetView();
  4975. if (this.removePageBorders) {
  4976. this.viewer.classList.add('removePageBorders');
  4977. }
  4978. }
  4979. PDFViewer.prototype = {
  4980. get pagesCount() {
  4981. return this._pages.length;
  4982. },
  4983. getPageView: function (index) {
  4984. return this._pages[index];
  4985. },
  4986. get pageViewsReady() {
  4987. return this._pageViewsReady;
  4988. },
  4989. get currentPageNumber() {
  4990. return this._currentPageNumber;
  4991. },
  4992. set currentPageNumber(val) {
  4993. if ((val | 0) !== val) {
  4994. throw new Error('Invalid page number.');
  4995. }
  4996. if (!this.pdfDocument) {
  4997. this._currentPageNumber = val;
  4998. return;
  4999. }
  5000. this._setCurrentPageNumber(val, true);
  5001. },
  5002. _setCurrentPageNumber: function PDFViewer_setCurrentPageNumber(val, resetCurrentPageView) {
  5003. if (this._currentPageNumber === val) {
  5004. if (resetCurrentPageView) {
  5005. this._resetCurrentPageView();
  5006. }
  5007. return;
  5008. }
  5009. if (!(0 < val && val <= this.pagesCount)) {
  5010. console.error('PDFViewer_setCurrentPageNumber: "' + val + '" is out of bounds.');
  5011. return;
  5012. }
  5013. var arg = {
  5014. source: this,
  5015. pageNumber: val,
  5016. pageLabel: this._pageLabels && this._pageLabels[val - 1]
  5017. };
  5018. this._currentPageNumber = val;
  5019. this.eventBus.dispatch('pagechanging', arg);
  5020. this.eventBus.dispatch('pagechange', arg);
  5021. if (resetCurrentPageView) {
  5022. this._resetCurrentPageView();
  5023. }
  5024. },
  5025. get currentPageLabel() {
  5026. return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
  5027. },
  5028. set currentPageLabel(val) {
  5029. var pageNumber = val | 0;
  5030. if (this._pageLabels) {
  5031. var i = this._pageLabels.indexOf(val);
  5032. if (i >= 0) {
  5033. pageNumber = i + 1;
  5034. }
  5035. }
  5036. this.currentPageNumber = pageNumber;
  5037. },
  5038. get currentScale() {
  5039. return this._currentScale !== UNKNOWN_SCALE ? this._currentScale : DEFAULT_SCALE;
  5040. },
  5041. set currentScale(val) {
  5042. if (isNaN(val)) {
  5043. throw new Error('Invalid numeric scale');
  5044. }
  5045. if (!this.pdfDocument) {
  5046. this._currentScale = val;
  5047. this._currentScaleValue = val !== UNKNOWN_SCALE ? val.toString() : null;
  5048. return;
  5049. }
  5050. this._setScale(val, false);
  5051. },
  5052. get currentScaleValue() {
  5053. return this._currentScaleValue;
  5054. },
  5055. set currentScaleValue(val) {
  5056. if (!this.pdfDocument) {
  5057. this._currentScale = isNaN(val) ? UNKNOWN_SCALE : val;
  5058. this._currentScaleValue = val.toString();
  5059. return;
  5060. }
  5061. this._setScale(val, false);
  5062. },
  5063. get pagesRotation() {
  5064. return this._pagesRotation;
  5065. },
  5066. set pagesRotation(rotation) {
  5067. if (!(typeof rotation === 'number' && rotation % 90 === 0)) {
  5068. throw new Error('Invalid pages rotation angle.');
  5069. }
  5070. this._pagesRotation = rotation;
  5071. if (!this.pdfDocument) {
  5072. return;
  5073. }
  5074. for (var i = 0, l = this._pages.length; i < l; i++) {
  5075. var pageView = this._pages[i];
  5076. pageView.update(pageView.scale, rotation);
  5077. }
  5078. this._setScale(this._currentScaleValue, true);
  5079. if (this.defaultRenderingQueue) {
  5080. this.update();
  5081. }
  5082. },
  5083. setDocument: function (pdfDocument) {
  5084. if (this.pdfDocument) {
  5085. this._cancelRendering();
  5086. this._resetView();
  5087. }
  5088. this.pdfDocument = pdfDocument;
  5089. if (!pdfDocument) {
  5090. return;
  5091. }
  5092. var pagesCount = pdfDocument.numPages;
  5093. var self = this;
  5094. var resolvePagesPromise;
  5095. var pagesPromise = new Promise(function (resolve) {
  5096. resolvePagesPromise = resolve;
  5097. });
  5098. this.pagesPromise = pagesPromise;
  5099. pagesPromise.then(function () {
  5100. self._pageViewsReady = true;
  5101. self.eventBus.dispatch('pagesloaded', {
  5102. source: self,
  5103. pagesCount: pagesCount
  5104. });
  5105. });
  5106. var isOnePageRenderedResolved = false;
  5107. var resolveOnePageRendered = null;
  5108. var onePageRendered = new Promise(function (resolve) {
  5109. resolveOnePageRendered = resolve;
  5110. });
  5111. this.onePageRendered = onePageRendered;
  5112. var bindOnAfterAndBeforeDraw = function (pageView) {
  5113. pageView.onBeforeDraw = function pdfViewLoadOnBeforeDraw() {
  5114. self._buffer.push(this);
  5115. };
  5116. pageView.onAfterDraw = function pdfViewLoadOnAfterDraw() {
  5117. if (!isOnePageRenderedResolved) {
  5118. isOnePageRenderedResolved = true;
  5119. resolveOnePageRendered();
  5120. }
  5121. };
  5122. };
  5123. var firstPagePromise = pdfDocument.getPage(1);
  5124. this.firstPagePromise = firstPagePromise;
  5125. return firstPagePromise.then(function (pdfPage) {
  5126. var scale = this.currentScale;
  5127. var viewport = pdfPage.getViewport(scale * CSS_UNITS);
  5128. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  5129. var textLayerFactory = null;
  5130. if (!pdfjsLib.PDFJS.disableTextLayer) {
  5131. textLayerFactory = this;
  5132. }
  5133. var pageView = new PDFPageView({
  5134. container: this.viewer,
  5135. eventBus: this.eventBus,
  5136. id: pageNum,
  5137. scale: scale,
  5138. defaultViewport: viewport.clone(),
  5139. renderingQueue: this.renderingQueue,
  5140. textLayerFactory: textLayerFactory,
  5141. annotationLayerFactory: this,
  5142. enhanceTextSelection: this.enhanceTextSelection,
  5143. renderInteractiveForms: this.renderInteractiveForms,
  5144. renderer: this.renderer
  5145. });
  5146. bindOnAfterAndBeforeDraw(pageView);
  5147. this._pages.push(pageView);
  5148. }
  5149. var linkService = this.linkService;
  5150. onePageRendered.then(function () {
  5151. if (!pdfjsLib.PDFJS.disableAutoFetch) {
  5152. var getPagesLeft = pagesCount;
  5153. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  5154. pdfDocument.getPage(pageNum).then(function (pageNum, pdfPage) {
  5155. var pageView = self._pages[pageNum - 1];
  5156. if (!pageView.pdfPage) {
  5157. pageView.setPdfPage(pdfPage);
  5158. }
  5159. linkService.cachePageRef(pageNum, pdfPage.ref);
  5160. getPagesLeft--;
  5161. if (!getPagesLeft) {
  5162. resolvePagesPromise();
  5163. }
  5164. }.bind(null, pageNum));
  5165. }
  5166. } else {
  5167. resolvePagesPromise();
  5168. }
  5169. });
  5170. self.eventBus.dispatch('pagesinit', { source: self });
  5171. if (this.defaultRenderingQueue) {
  5172. this.update();
  5173. }
  5174. if (this.findController) {
  5175. this.findController.resolveFirstPage();
  5176. }
  5177. }.bind(this));
  5178. },
  5179. setPageLabels: function PDFViewer_setPageLabels(labels) {
  5180. if (!this.pdfDocument) {
  5181. return;
  5182. }
  5183. if (!labels) {
  5184. this._pageLabels = null;
  5185. } else if (!(labels instanceof Array && this.pdfDocument.numPages === labels.length)) {
  5186. this._pageLabels = null;
  5187. console.error('PDFViewer_setPageLabels: Invalid page labels.');
  5188. } else {
  5189. this._pageLabels = labels;
  5190. }
  5191. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  5192. var pageView = this._pages[i];
  5193. var label = this._pageLabels && this._pageLabels[i];
  5194. pageView.setPageLabel(label);
  5195. }
  5196. },
  5197. _resetView: function () {
  5198. this._pages = [];
  5199. this._currentPageNumber = 1;
  5200. this._currentScale = UNKNOWN_SCALE;
  5201. this._currentScaleValue = null;
  5202. this._pageLabels = null;
  5203. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  5204. this._location = null;
  5205. this._pagesRotation = 0;
  5206. this._pagesRequests = [];
  5207. this._pageViewsReady = false;
  5208. this.viewer.textContent = '';
  5209. },
  5210. _scrollUpdate: function PDFViewer_scrollUpdate() {
  5211. if (this.pagesCount === 0) {
  5212. return;
  5213. }
  5214. this.update();
  5215. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  5216. this._pages[i].updatePosition();
  5217. }
  5218. },
  5219. _setScaleDispatchEvent: function pdfViewer_setScaleDispatchEvent(newScale, newValue, preset) {
  5220. var arg = {
  5221. source: this,
  5222. scale: newScale,
  5223. presetValue: preset ? newValue : undefined
  5224. };
  5225. this.eventBus.dispatch('scalechanging', arg);
  5226. this.eventBus.dispatch('scalechange', arg);
  5227. },
  5228. _setScaleUpdatePages: function pdfViewer_setScaleUpdatePages(newScale, newValue, noScroll, preset) {
  5229. this._currentScaleValue = newValue.toString();
  5230. if (isSameScale(this._currentScale, newScale)) {
  5231. if (preset) {
  5232. this._setScaleDispatchEvent(newScale, newValue, true);
  5233. }
  5234. return;
  5235. }
  5236. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  5237. this._pages[i].update(newScale);
  5238. }
  5239. this._currentScale = newScale;
  5240. if (!noScroll) {
  5241. var page = this._currentPageNumber, dest;
  5242. if (this._location && !pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  5243. page = this._location.pageNumber;
  5244. dest = [
  5245. null,
  5246. { name: 'XYZ' },
  5247. this._location.left,
  5248. this._location.top,
  5249. null
  5250. ];
  5251. }
  5252. this.scrollPageIntoView({
  5253. pageNumber: page,
  5254. destArray: dest,
  5255. allowNegativeOffset: true
  5256. });
  5257. }
  5258. this._setScaleDispatchEvent(newScale, newValue, preset);
  5259. if (this.defaultRenderingQueue) {
  5260. this.update();
  5261. }
  5262. },
  5263. _setScale: function PDFViewer_setScale(value, noScroll) {
  5264. var scale = parseFloat(value);
  5265. if (scale > 0) {
  5266. this._setScaleUpdatePages(scale, value, noScroll, false);
  5267. } else {
  5268. var currentPage = this._pages[this._currentPageNumber - 1];
  5269. if (!currentPage) {
  5270. return;
  5271. }
  5272. var hPadding = this.isInPresentationMode || this.removePageBorders ? 0 : SCROLLBAR_PADDING;
  5273. var vPadding = this.isInPresentationMode || this.removePageBorders ? 0 : VERTICAL_PADDING;
  5274. var pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale;
  5275. var pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  5276. switch (value) {
  5277. case 'page-actual':
  5278. scale = 1;
  5279. break;
  5280. case 'page-width':
  5281. scale = pageWidthScale;
  5282. break;
  5283. case 'page-height':
  5284. scale = pageHeightScale;
  5285. break;
  5286. case 'page-fit':
  5287. scale = Math.min(pageWidthScale, pageHeightScale);
  5288. break;
  5289. case 'auto':
  5290. var isLandscape = currentPage.width > currentPage.height;
  5291. var horizontalScale = isLandscape ? Math.min(pageHeightScale, pageWidthScale) : pageWidthScale;
  5292. scale = Math.min(MAX_AUTO_SCALE, horizontalScale);
  5293. break;
  5294. default:
  5295. console.error('PDFViewer_setScale: "' + value + '" is an unknown zoom value.');
  5296. return;
  5297. }
  5298. this._setScaleUpdatePages(scale, value, noScroll, true);
  5299. }
  5300. },
  5301. _resetCurrentPageView: function () {
  5302. if (this.isInPresentationMode) {
  5303. this._setScale(this._currentScaleValue, true);
  5304. }
  5305. var pageView = this._pages[this._currentPageNumber - 1];
  5306. scrollIntoView(pageView.div);
  5307. },
  5308. scrollPageIntoView: function PDFViewer_scrollPageIntoView(params) {
  5309. if (!this.pdfDocument) {
  5310. return;
  5311. }
  5312. if (arguments.length > 1 || typeof params === 'number') {
  5313. console.warn('Call of scrollPageIntoView() with obsolete signature.');
  5314. var paramObj = {};
  5315. if (typeof params === 'number') {
  5316. paramObj.pageNumber = params;
  5317. }
  5318. if (arguments[1] instanceof Array) {
  5319. paramObj.destArray = arguments[1];
  5320. }
  5321. params = paramObj;
  5322. }
  5323. var pageNumber = params.pageNumber || 0;
  5324. var dest = params.destArray || null;
  5325. var allowNegativeOffset = params.allowNegativeOffset || false;
  5326. if (this.isInPresentationMode || !dest) {
  5327. this._setCurrentPageNumber(pageNumber, true);
  5328. return;
  5329. }
  5330. var pageView = this._pages[pageNumber - 1];
  5331. if (!pageView) {
  5332. console.error('PDFViewer_scrollPageIntoView: ' + 'Invalid "pageNumber" parameter.');
  5333. return;
  5334. }
  5335. var x = 0, y = 0;
  5336. var width = 0, height = 0, widthScale, heightScale;
  5337. var changeOrientation = pageView.rotation % 180 === 0 ? false : true;
  5338. var pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / CSS_UNITS;
  5339. var pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / CSS_UNITS;
  5340. var scale = 0;
  5341. switch (dest[1].name) {
  5342. case 'XYZ':
  5343. x = dest[2];
  5344. y = dest[3];
  5345. scale = dest[4];
  5346. x = x !== null ? x : 0;
  5347. y = y !== null ? y : pageHeight;
  5348. break;
  5349. case 'Fit':
  5350. case 'FitB':
  5351. scale = 'page-fit';
  5352. break;
  5353. case 'FitH':
  5354. case 'FitBH':
  5355. y = dest[2];
  5356. scale = 'page-width';
  5357. if (y === null && this._location) {
  5358. x = this._location.left;
  5359. y = this._location.top;
  5360. }
  5361. break;
  5362. case 'FitV':
  5363. case 'FitBV':
  5364. x = dest[2];
  5365. width = pageWidth;
  5366. height = pageHeight;
  5367. scale = 'page-height';
  5368. break;
  5369. case 'FitR':
  5370. x = dest[2];
  5371. y = dest[3];
  5372. width = dest[4] - x;
  5373. height = dest[5] - y;
  5374. var hPadding = this.removePageBorders ? 0 : SCROLLBAR_PADDING;
  5375. var vPadding = this.removePageBorders ? 0 : VERTICAL_PADDING;
  5376. widthScale = (this.container.clientWidth - hPadding) / width / CSS_UNITS;
  5377. heightScale = (this.container.clientHeight - vPadding) / height / CSS_UNITS;
  5378. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  5379. break;
  5380. default:
  5381. console.error('PDFViewer_scrollPageIntoView: \'' + dest[1].name + '\' is not a valid destination type.');
  5382. return;
  5383. }
  5384. if (scale && scale !== this._currentScale) {
  5385. this.currentScaleValue = scale;
  5386. } else if (this._currentScale === UNKNOWN_SCALE) {
  5387. this.currentScaleValue = DEFAULT_SCALE_VALUE;
  5388. }
  5389. if (scale === 'page-fit' && !dest[4]) {
  5390. scrollIntoView(pageView.div);
  5391. return;
  5392. }
  5393. var boundingRect = [
  5394. pageView.viewport.convertToViewportPoint(x, y),
  5395. pageView.viewport.convertToViewportPoint(x + width, y + height)
  5396. ];
  5397. var left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  5398. var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  5399. if (!allowNegativeOffset) {
  5400. left = Math.max(left, 0);
  5401. top = Math.max(top, 0);
  5402. }
  5403. scrollIntoView(pageView.div, {
  5404. left: left,
  5405. top: top
  5406. });
  5407. },
  5408. _updateLocation: function (firstPage) {
  5409. var currentScale = this._currentScale;
  5410. var currentScaleValue = this._currentScaleValue;
  5411. var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  5412. var pageNumber = firstPage.id;
  5413. var pdfOpenParams = '#page=' + pageNumber;
  5414. pdfOpenParams += '&zoom=' + normalizedScaleValue;
  5415. var currentPageView = this._pages[pageNumber - 1];
  5416. var container = this.container;
  5417. var topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  5418. var intLeft = Math.round(topLeft[0]);
  5419. var intTop = Math.round(topLeft[1]);
  5420. pdfOpenParams += ',' + intLeft + ',' + intTop;
  5421. this._location = {
  5422. pageNumber: pageNumber,
  5423. scale: normalizedScaleValue,
  5424. top: intTop,
  5425. left: intLeft,
  5426. pdfOpenParams: pdfOpenParams
  5427. };
  5428. },
  5429. update: function PDFViewer_update() {
  5430. var visible = this._getVisiblePages();
  5431. var visiblePages = visible.views;
  5432. if (visiblePages.length === 0) {
  5433. return;
  5434. }
  5435. var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * visiblePages.length + 1);
  5436. this._buffer.resize(suggestedCacheSize);
  5437. this.renderingQueue.renderHighestPriority(visible);
  5438. var currentId = this._currentPageNumber;
  5439. var firstPage = visible.first;
  5440. for (var i = 0, ii = visiblePages.length, stillFullyVisible = false; i < ii; ++i) {
  5441. var page = visiblePages[i];
  5442. if (page.percent < 100) {
  5443. break;
  5444. }
  5445. if (page.id === currentId) {
  5446. stillFullyVisible = true;
  5447. break;
  5448. }
  5449. }
  5450. if (!stillFullyVisible) {
  5451. currentId = visiblePages[0].id;
  5452. }
  5453. if (!this.isInPresentationMode) {
  5454. this._setCurrentPageNumber(currentId);
  5455. }
  5456. this._updateLocation(firstPage);
  5457. this.eventBus.dispatch('updateviewarea', {
  5458. source: this,
  5459. location: this._location
  5460. });
  5461. },
  5462. containsElement: function (element) {
  5463. return this.container.contains(element);
  5464. },
  5465. focus: function () {
  5466. this.container.focus();
  5467. },
  5468. get isInPresentationMode() {
  5469. return this.presentationModeState === PresentationModeState.FULLSCREEN;
  5470. },
  5471. get isChangingPresentationMode() {
  5472. return this.presentationModeState === PresentationModeState.CHANGING;
  5473. },
  5474. get isHorizontalScrollbarEnabled() {
  5475. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  5476. },
  5477. _getVisiblePages: function () {
  5478. if (!this.isInPresentationMode) {
  5479. return getVisibleElements(this.container, this._pages, true);
  5480. }
  5481. var visible = [];
  5482. var currentPage = this._pages[this._currentPageNumber - 1];
  5483. visible.push({
  5484. id: currentPage.id,
  5485. view: currentPage
  5486. });
  5487. return {
  5488. first: currentPage,
  5489. last: currentPage,
  5490. views: visible
  5491. };
  5492. },
  5493. cleanup: function () {
  5494. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  5495. if (this._pages[i] && this._pages[i].renderingState !== RenderingStates.FINISHED) {
  5496. this._pages[i].reset();
  5497. }
  5498. }
  5499. },
  5500. _cancelRendering: function PDFViewer_cancelRendering() {
  5501. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  5502. if (this._pages[i]) {
  5503. this._pages[i].cancelRendering();
  5504. }
  5505. }
  5506. },
  5507. _ensurePdfPageLoaded: function (pageView) {
  5508. if (pageView.pdfPage) {
  5509. return Promise.resolve(pageView.pdfPage);
  5510. }
  5511. var pageNumber = pageView.id;
  5512. if (this._pagesRequests[pageNumber]) {
  5513. return this._pagesRequests[pageNumber];
  5514. }
  5515. var promise = this.pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  5516. pageView.setPdfPage(pdfPage);
  5517. this._pagesRequests[pageNumber] = null;
  5518. return pdfPage;
  5519. }.bind(this));
  5520. this._pagesRequests[pageNumber] = promise;
  5521. return promise;
  5522. },
  5523. forceRendering: function (currentlyVisiblePages) {
  5524. var visiblePages = currentlyVisiblePages || this._getVisiblePages();
  5525. var pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, this.scroll.down);
  5526. if (pageView) {
  5527. this._ensurePdfPageLoaded(pageView).then(function () {
  5528. this.renderingQueue.renderView(pageView);
  5529. }.bind(this));
  5530. return true;
  5531. }
  5532. return false;
  5533. },
  5534. getPageTextContent: function (pageIndex) {
  5535. return this.pdfDocument.getPage(pageIndex + 1).then(function (page) {
  5536. return page.getTextContent({ normalizeWhitespace: true });
  5537. });
  5538. },
  5539. createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport, enhanceTextSelection) {
  5540. return new TextLayerBuilder({
  5541. textLayerDiv: textLayerDiv,
  5542. eventBus: this.eventBus,
  5543. pageIndex: pageIndex,
  5544. viewport: viewport,
  5545. findController: this.isInPresentationMode ? null : this.findController,
  5546. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  5547. });
  5548. },
  5549. createAnnotationLayerBuilder: function (pageDiv, pdfPage, renderInteractiveForms) {
  5550. return new AnnotationLayerBuilder({
  5551. pageDiv: pageDiv,
  5552. pdfPage: pdfPage,
  5553. renderInteractiveForms: renderInteractiveForms,
  5554. linkService: this.linkService,
  5555. downloadManager: this.downloadManager
  5556. });
  5557. },
  5558. setFindController: function (findController) {
  5559. this.findController = findController;
  5560. },
  5561. getPagesOverview: function () {
  5562. return this._pages.map(function (pageView) {
  5563. var viewport = pageView.pdfPage.getViewport(1);
  5564. return {
  5565. width: viewport.width,
  5566. height: viewport.height
  5567. };
  5568. });
  5569. }
  5570. };
  5571. return PDFViewer;
  5572. }();
  5573. exports.PresentationModeState = PresentationModeState;
  5574. exports.PDFViewer = PDFViewer;
  5575. }));
  5576. (function (root, factory) {
  5577. factory(root.pdfjsWebApp = {}, root.pdfjsWebUIUtils, root.pdfjsWebDownloadManager, root.pdfjsWebPDFHistory, root.pdfjsWebPreferences, root.pdfjsWebPDFSidebar, root.pdfjsWebViewHistory, root.pdfjsWebPDFThumbnailViewer, root.pdfjsWebToolbar, root.pdfjsWebSecondaryToolbar, root.pdfjsWebPasswordPrompt, root.pdfjsWebPDFPresentationMode, root.pdfjsWebPDFDocumentProperties, root.pdfjsWebHandTool, root.pdfjsWebPDFViewer, root.pdfjsWebPDFRenderingQueue, root.pdfjsWebPDFLinkService, root.pdfjsWebPDFOutlineViewer, root.pdfjsWebOverlayManager, root.pdfjsWebPDFAttachmentViewer, root.pdfjsWebPDFFindController, root.pdfjsWebPDFFindBar, root.pdfjsWebDOMEvents, root.pdfjsWebPDFJS);
  5578. }(this, function (exports, uiUtilsLib, downloadManagerLib, pdfHistoryLib, preferencesLib, pdfSidebarLib, viewHistoryLib, pdfThumbnailViewerLib, toolbarLib, secondaryToolbarLib, passwordPromptLib, pdfPresentationModeLib, pdfDocumentPropertiesLib, handToolLib, pdfViewerLib, pdfRenderingQueueLib, pdfLinkServiceLib, pdfOutlineViewerLib, overlayManagerLib, pdfAttachmentViewerLib, pdfFindControllerLib, pdfFindBarLib, domEventsLib, pdfjsLib) {
  5579. var UNKNOWN_SCALE = uiUtilsLib.UNKNOWN_SCALE;
  5580. var DEFAULT_SCALE_VALUE = uiUtilsLib.DEFAULT_SCALE_VALUE;
  5581. var MIN_SCALE = uiUtilsLib.MIN_SCALE;
  5582. var MAX_SCALE = uiUtilsLib.MAX_SCALE;
  5583. var ProgressBar = uiUtilsLib.ProgressBar;
  5584. var getPDFFileNameFromURL = uiUtilsLib.getPDFFileNameFromURL;
  5585. var noContextMenuHandler = uiUtilsLib.noContextMenuHandler;
  5586. var mozL10n = uiUtilsLib.mozL10n;
  5587. var parseQueryString = uiUtilsLib.parseQueryString;
  5588. var PDFHistory = pdfHistoryLib.PDFHistory;
  5589. var Preferences = preferencesLib.Preferences;
  5590. var SidebarView = pdfSidebarLib.SidebarView;
  5591. var PDFSidebar = pdfSidebarLib.PDFSidebar;
  5592. var ViewHistory = viewHistoryLib.ViewHistory;
  5593. var PDFThumbnailViewer = pdfThumbnailViewerLib.PDFThumbnailViewer;
  5594. var Toolbar = toolbarLib.Toolbar;
  5595. var SecondaryToolbar = secondaryToolbarLib.SecondaryToolbar;
  5596. var PasswordPrompt = passwordPromptLib.PasswordPrompt;
  5597. var PDFPresentationMode = pdfPresentationModeLib.PDFPresentationMode;
  5598. var PDFDocumentProperties = pdfDocumentPropertiesLib.PDFDocumentProperties;
  5599. var HandTool = handToolLib.HandTool;
  5600. var PresentationModeState = pdfViewerLib.PresentationModeState;
  5601. var PDFViewer = pdfViewerLib.PDFViewer;
  5602. var RenderingStates = pdfRenderingQueueLib.RenderingStates;
  5603. var PDFRenderingQueue = pdfRenderingQueueLib.PDFRenderingQueue;
  5604. var PDFLinkService = pdfLinkServiceLib.PDFLinkService;
  5605. var PDFOutlineViewer = pdfOutlineViewerLib.PDFOutlineViewer;
  5606. var OverlayManager = overlayManagerLib.OverlayManager;
  5607. var PDFAttachmentViewer = pdfAttachmentViewerLib.PDFAttachmentViewer;
  5608. var PDFFindController = pdfFindControllerLib.PDFFindController;
  5609. var PDFFindBar = pdfFindBarLib.PDFFindBar;
  5610. var getGlobalEventBus = domEventsLib.getGlobalEventBus;
  5611. var normalizeWheelEventDelta = uiUtilsLib.normalizeWheelEventDelta;
  5612. var animationStarted = uiUtilsLib.animationStarted;
  5613. var localized = uiUtilsLib.localized;
  5614. var RendererType = uiUtilsLib.RendererType;
  5615. var DEFAULT_SCALE_DELTA = 1.1;
  5616. var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  5617. var DefaultExernalServices = {
  5618. updateFindControlState: function (data) {
  5619. },
  5620. initPassiveLoading: function (callbacks) {
  5621. },
  5622. fallback: function (data, callback) {
  5623. },
  5624. reportTelemetry: function (data) {
  5625. },
  5626. createDownloadManager: function () {
  5627. return new downloadManagerLib.DownloadManager();
  5628. },
  5629. supportsIntegratedFind: false,
  5630. supportsDocumentFonts: true,
  5631. supportsDocumentColors: true,
  5632. supportedMouseWheelZoomModifierKeys: {
  5633. ctrlKey: true,
  5634. metaKey: true
  5635. }
  5636. };
  5637. var PDFViewerApplication = {
  5638. initialBookmark: document.location.hash.substring(1),
  5639. initialDestination: null,
  5640. initialized: false,
  5641. fellback: false,
  5642. appConfig: null,
  5643. pdfDocument: null,
  5644. pdfLoadingTask: null,
  5645. printService: null,
  5646. pdfViewer: null,
  5647. pdfThumbnailViewer: null,
  5648. pdfRenderingQueue: null,
  5649. pdfPresentationMode: null,
  5650. pdfDocumentProperties: null,
  5651. pdfLinkService: null,
  5652. pdfHistory: null,
  5653. pdfSidebar: null,
  5654. pdfOutlineViewer: null,
  5655. pdfAttachmentViewer: null,
  5656. store: null,
  5657. downloadManager: null,
  5658. toolbar: null,
  5659. secondaryToolbar: null,
  5660. eventBus: null,
  5661. pageRotation: 0,
  5662. isInitialViewSet: false,
  5663. viewerPrefs: {
  5664. sidebarViewOnLoad: SidebarView.NONE,
  5665. pdfBugEnabled: false,
  5666. showPreviousViewOnLoad: true,
  5667. defaultZoomValue: '',
  5668. disablePageLabels: false,
  5669. renderer: 'canvas',
  5670. enhanceTextSelection: false,
  5671. renderInteractiveForms: false
  5672. },
  5673. isViewerEmbedded: window.parent !== window,
  5674. url: '',
  5675. baseUrl: '',
  5676. externalServices: DefaultExernalServices,
  5677. initialize: function pdfViewInitialize(appConfig) {
  5678. var self = this;
  5679. var PDFJS = pdfjsLib.PDFJS;
  5680. Preferences.initialize();
  5681. this.preferences = Preferences;
  5682. configure(PDFJS);
  5683. this.appConfig = appConfig;
  5684. return this._readPreferences().then(function () {
  5685. return self._initializeViewerComponents();
  5686. }).then(function () {
  5687. self.bindEvents();
  5688. self.bindWindowEvents();
  5689. localized.then(function () {
  5690. self.eventBus.dispatch('localized');
  5691. });
  5692. if (self.isViewerEmbedded && !PDFJS.isExternalLinkTargetSet()) {
  5693. PDFJS.externalLinkTarget = PDFJS.LinkTarget.TOP;
  5694. }
  5695. self.initialized = true;
  5696. });
  5697. },
  5698. _readPreferences: function () {
  5699. var self = this;
  5700. var PDFJS = pdfjsLib.PDFJS;
  5701. return Promise.all([
  5702. Preferences.get('enableWebGL').then(function resolved(value) {
  5703. PDFJS.disableWebGL = !value;
  5704. }),
  5705. Preferences.get('sidebarViewOnLoad').then(function resolved(value) {
  5706. self.viewerPrefs['sidebarViewOnLoad'] = value;
  5707. }),
  5708. Preferences.get('pdfBugEnabled').then(function resolved(value) {
  5709. self.viewerPrefs['pdfBugEnabled'] = value;
  5710. }),
  5711. Preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
  5712. self.viewerPrefs['showPreviousViewOnLoad'] = value;
  5713. }),
  5714. Preferences.get('defaultZoomValue').then(function resolved(value) {
  5715. self.viewerPrefs['defaultZoomValue'] = value;
  5716. }),
  5717. Preferences.get('enhanceTextSelection').then(function resolved(value) {
  5718. self.viewerPrefs['enhanceTextSelection'] = value;
  5719. }),
  5720. Preferences.get('disableTextLayer').then(function resolved(value) {
  5721. if (PDFJS.disableTextLayer === true) {
  5722. return;
  5723. }
  5724. PDFJS.disableTextLayer = value;
  5725. }),
  5726. Preferences.get('disableRange').then(function resolved(value) {
  5727. if (PDFJS.disableRange === true) {
  5728. return;
  5729. }
  5730. PDFJS.disableRange = value;
  5731. }),
  5732. Preferences.get('disableStream').then(function resolved(value) {
  5733. if (PDFJS.disableStream === true) {
  5734. return;
  5735. }
  5736. PDFJS.disableStream = value;
  5737. }),
  5738. Preferences.get('disableAutoFetch').then(function resolved(value) {
  5739. PDFJS.disableAutoFetch = value;
  5740. }),
  5741. Preferences.get('disableFontFace').then(function resolved(value) {
  5742. if (PDFJS.disableFontFace === true) {
  5743. return;
  5744. }
  5745. PDFJS.disableFontFace = value;
  5746. }),
  5747. Preferences.get('useOnlyCssZoom').then(function resolved(value) {
  5748. PDFJS.useOnlyCssZoom = value;
  5749. }),
  5750. Preferences.get('externalLinkTarget').then(function resolved(value) {
  5751. if (PDFJS.isExternalLinkTargetSet()) {
  5752. return;
  5753. }
  5754. PDFJS.externalLinkTarget = value;
  5755. }),
  5756. Preferences.get('renderer').then(function resolved(value) {
  5757. self.viewerPrefs['renderer'] = value;
  5758. }),
  5759. Preferences.get('renderInteractiveForms').then(function resolved(value) {
  5760. self.viewerPrefs['renderInteractiveForms'] = value;
  5761. }),
  5762. Preferences.get('disablePageLabels').then(function resolved(value) {
  5763. self.viewerPrefs['disablePageLabels'] = value;
  5764. })
  5765. ]).catch(function (reason) {
  5766. });
  5767. },
  5768. _initializeViewerComponents: function () {
  5769. var self = this;
  5770. var appConfig = this.appConfig;
  5771. return new Promise(function (resolve, reject) {
  5772. var eventBus = appConfig.eventBus || getGlobalEventBus();
  5773. self.eventBus = eventBus;
  5774. var pdfRenderingQueue = new PDFRenderingQueue();
  5775. pdfRenderingQueue.onIdle = self.cleanup.bind(self);
  5776. self.pdfRenderingQueue = pdfRenderingQueue;
  5777. var pdfLinkService = new PDFLinkService({ eventBus: eventBus });
  5778. self.pdfLinkService = pdfLinkService;
  5779. var downloadManager = self.externalServices.createDownloadManager();
  5780. self.downloadManager = downloadManager;
  5781. var container = appConfig.mainContainer;
  5782. var viewer = appConfig.viewerContainer;
  5783. self.pdfViewer = new PDFViewer({
  5784. container: container,
  5785. viewer: viewer,
  5786. eventBus: eventBus,
  5787. renderingQueue: pdfRenderingQueue,
  5788. linkService: pdfLinkService,
  5789. downloadManager: downloadManager,
  5790. renderer: self.viewerPrefs['renderer'],
  5791. enhanceTextSelection: self.viewerPrefs['enhanceTextSelection'],
  5792. renderInteractiveForms: self.viewerPrefs['renderInteractiveForms']
  5793. });
  5794. pdfRenderingQueue.setViewer(self.pdfViewer);
  5795. pdfLinkService.setViewer(self.pdfViewer);
  5796. var thumbnailContainer = appConfig.sidebar.thumbnailView;
  5797. self.pdfThumbnailViewer = new PDFThumbnailViewer({
  5798. container: thumbnailContainer,
  5799. renderingQueue: pdfRenderingQueue,
  5800. linkService: pdfLinkService
  5801. });
  5802. pdfRenderingQueue.setThumbnailViewer(self.pdfThumbnailViewer);
  5803. self.pdfHistory = new PDFHistory({
  5804. linkService: pdfLinkService,
  5805. eventBus: eventBus
  5806. });
  5807. pdfLinkService.setHistory(self.pdfHistory);
  5808. self.findController = new PDFFindController({ pdfViewer: self.pdfViewer });
  5809. self.findController.onUpdateResultsCount = function (matchCount) {
  5810. if (self.supportsIntegratedFind) {
  5811. return;
  5812. }
  5813. self.findBar.updateResultsCount(matchCount);
  5814. };
  5815. self.findController.onUpdateState = function (state, previous, matchCount) {
  5816. if (self.supportsIntegratedFind) {
  5817. self.externalServices.updateFindControlState({
  5818. result: state,
  5819. findPrevious: previous
  5820. });
  5821. } else {
  5822. self.findBar.updateUIState(state, previous, matchCount);
  5823. }
  5824. };
  5825. self.pdfViewer.setFindController(self.findController);
  5826. var findBarConfig = Object.create(appConfig.findBar);
  5827. findBarConfig.findController = self.findController;
  5828. findBarConfig.eventBus = eventBus;
  5829. self.findBar = new PDFFindBar(findBarConfig);
  5830. self.overlayManager = OverlayManager;
  5831. self.handTool = new HandTool({
  5832. container: container,
  5833. eventBus: eventBus
  5834. });
  5835. self.pdfDocumentProperties = new PDFDocumentProperties(appConfig.documentProperties);
  5836. self.toolbar = new Toolbar(appConfig.toolbar, container, eventBus);
  5837. self.secondaryToolbar = new SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  5838. if (self.supportsFullscreen) {
  5839. self.pdfPresentationMode = new PDFPresentationMode({
  5840. container: container,
  5841. viewer: viewer,
  5842. pdfViewer: self.pdfViewer,
  5843. eventBus: eventBus,
  5844. contextMenuItems: appConfig.fullscreen
  5845. });
  5846. }
  5847. self.passwordPrompt = new PasswordPrompt(appConfig.passwordOverlay);
  5848. self.pdfOutlineViewer = new PDFOutlineViewer({
  5849. container: appConfig.sidebar.outlineView,
  5850. eventBus: eventBus,
  5851. linkService: pdfLinkService
  5852. });
  5853. self.pdfAttachmentViewer = new PDFAttachmentViewer({
  5854. container: appConfig.sidebar.attachmentsView,
  5855. eventBus: eventBus,
  5856. downloadManager: downloadManager
  5857. });
  5858. var sidebarConfig = Object.create(appConfig.sidebar);
  5859. sidebarConfig.pdfViewer = self.pdfViewer;
  5860. sidebarConfig.pdfThumbnailViewer = self.pdfThumbnailViewer;
  5861. sidebarConfig.pdfOutlineViewer = self.pdfOutlineViewer;
  5862. sidebarConfig.eventBus = eventBus;
  5863. self.pdfSidebar = new PDFSidebar(sidebarConfig);
  5864. self.pdfSidebar.onToggled = self.forceRendering.bind(self);
  5865. resolve(undefined);
  5866. });
  5867. },
  5868. run: function pdfViewRun(config) {
  5869. this.initialize(config).then(webViewerInitialized);
  5870. },
  5871. zoomIn: function pdfViewZoomIn(ticks) {
  5872. var newScale = this.pdfViewer.currentScale;
  5873. do {
  5874. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  5875. newScale = Math.ceil(newScale * 10) / 10;
  5876. newScale = Math.min(MAX_SCALE, newScale);
  5877. } while (--ticks > 0 && newScale < MAX_SCALE);
  5878. this.pdfViewer.currentScaleValue = newScale;
  5879. },
  5880. zoomOut: function pdfViewZoomOut(ticks) {
  5881. var newScale = this.pdfViewer.currentScale;
  5882. do {
  5883. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  5884. newScale = Math.floor(newScale * 10) / 10;
  5885. newScale = Math.max(MIN_SCALE, newScale);
  5886. } while (--ticks > 0 && newScale > MIN_SCALE);
  5887. this.pdfViewer.currentScaleValue = newScale;
  5888. },
  5889. get pagesCount() {
  5890. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  5891. },
  5892. set page(val) {
  5893. this.pdfViewer.currentPageNumber = val;
  5894. },
  5895. get page() {
  5896. return this.pdfViewer.currentPageNumber;
  5897. },
  5898. get printing() {
  5899. return !!this.printService;
  5900. },
  5901. get supportsPrinting() {
  5902. return PDFPrintServiceFactory.instance.supportsPrinting;
  5903. },
  5904. get supportsFullscreen() {
  5905. var support;
  5906. var doc = document.documentElement;
  5907. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  5908. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  5909. support = false;
  5910. }
  5911. if (support && pdfjsLib.PDFJS.disableFullscreen === true) {
  5912. support = false;
  5913. }
  5914. return pdfjsLib.shadow(this, 'supportsFullscreen', support);
  5915. },
  5916. get supportsIntegratedFind() {
  5917. return this.externalServices.supportsIntegratedFind;
  5918. },
  5919. get supportsDocumentFonts() {
  5920. return this.externalServices.supportsDocumentFonts;
  5921. },
  5922. get supportsDocumentColors() {
  5923. return this.externalServices.supportsDocumentColors;
  5924. },
  5925. get loadingBar() {
  5926. var bar = new ProgressBar('#loadingBar', {});
  5927. return pdfjsLib.shadow(this, 'loadingBar', bar);
  5928. },
  5929. get supportedMouseWheelZoomModifierKeys() {
  5930. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  5931. },
  5932. initPassiveLoading: function pdfViewInitPassiveLoading() {
  5933. throw new Error('Not implemented: initPassiveLoading');
  5934. },
  5935. setTitleUsingUrl: function pdfViewSetTitleUsingUrl(url) {
  5936. this.url = url;
  5937. this.baseUrl = url.split('#')[0];
  5938. try {
  5939. this.setTitle(decodeURIComponent(pdfjsLib.getFilenameFromUrl(url)) || url);
  5940. } catch (e) {
  5941. this.setTitle(url);
  5942. }
  5943. },
  5944. setTitle: function pdfViewSetTitle(title) {
  5945. if (this.isViewerEmbedded) {
  5946. return;
  5947. }
  5948. document.title = title;
  5949. },
  5950. close: function pdfViewClose() {
  5951. var errorWrapper = this.appConfig.errorWrapper.container;
  5952. errorWrapper.setAttribute('hidden', 'true');
  5953. if (!this.pdfLoadingTask) {
  5954. return Promise.resolve();
  5955. }
  5956. var promise = this.pdfLoadingTask.destroy();
  5957. this.pdfLoadingTask = null;
  5958. if (this.pdfDocument) {
  5959. this.pdfDocument = null;
  5960. this.pdfThumbnailViewer.setDocument(null);
  5961. this.pdfViewer.setDocument(null);
  5962. this.pdfLinkService.setDocument(null, null);
  5963. }
  5964. this.store = null;
  5965. this.isInitialViewSet = false;
  5966. this.pdfSidebar.reset();
  5967. this.pdfOutlineViewer.reset();
  5968. this.pdfAttachmentViewer.reset();
  5969. this.findController.reset();
  5970. this.findBar.reset();
  5971. this.toolbar.reset();
  5972. this.secondaryToolbar.reset();
  5973. if (typeof PDFBug !== 'undefined') {
  5974. PDFBug.cleanup();
  5975. }
  5976. return promise;
  5977. },
  5978. open: function pdfViewOpen(file, args) {
  5979. if (arguments.length > 2 || typeof args === 'number') {
  5980. return Promise.reject(new Error('Call of open() with obsolete signature.'));
  5981. }
  5982. if (this.pdfLoadingTask) {
  5983. return this.close().then(function () {
  5984. Preferences.reload();
  5985. return this.open(file, args);
  5986. }.bind(this));
  5987. }
  5988. var parameters = Object.create(null), scale;
  5989. if (typeof file === 'string') {
  5990. this.setTitleUsingUrl(file);
  5991. parameters.url = file;
  5992. } else if (file && 'byteLength' in file) {
  5993. parameters.data = file;
  5994. } else if (file.url && file.originalUrl) {
  5995. this.setTitleUsingUrl(file.originalUrl);
  5996. parameters.url = file.url;
  5997. }
  5998. if (args) {
  5999. for (var prop in args) {
  6000. parameters[prop] = args[prop];
  6001. }
  6002. if (args.scale) {
  6003. scale = args.scale;
  6004. }
  6005. if (args.length) {
  6006. this.pdfDocumentProperties.setFileSize(args.length);
  6007. }
  6008. }
  6009. var self = this;
  6010. self.downloadComplete = false;
  6011. var loadingTask = pdfjsLib.getDocument(parameters);
  6012. this.pdfLoadingTask = loadingTask;
  6013. loadingTask.onPassword = function passwordNeeded(updateCallback, reason) {
  6014. self.passwordPrompt.setUpdateCallback(updateCallback, reason);
  6015. self.passwordPrompt.open();
  6016. };
  6017. loadingTask.onProgress = function getDocumentProgress(progressData) {
  6018. self.progress(progressData.loaded / progressData.total);
  6019. };
  6020. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  6021. return loadingTask.promise.then(function getDocumentCallback(pdfDocument) {
  6022. self.load(pdfDocument, scale);
  6023. }, function getDocumentError(exception) {
  6024. var message = exception && exception.message;
  6025. var loadingErrorMessage = mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  6026. if (exception instanceof pdfjsLib.InvalidPDFException) {
  6027. loadingErrorMessage = mozL10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
  6028. } else if (exception instanceof pdfjsLib.MissingPDFException) {
  6029. loadingErrorMessage = mozL10n.get('missing_file_error', null, 'Missing PDF file.');
  6030. } else if (exception instanceof pdfjsLib.UnexpectedResponseException) {
  6031. loadingErrorMessage = mozL10n.get('unexpected_response_error', null, 'Unexpected server response.');
  6032. }
  6033. var moreInfo = { message: message };
  6034. self.error(loadingErrorMessage, moreInfo);
  6035. throw new Error(loadingErrorMessage);
  6036. });
  6037. },
  6038. download: function pdfViewDownload() {
  6039. function downloadByUrl() {
  6040. downloadManager.downloadUrl(url, filename);
  6041. }
  6042. var url = this.baseUrl;
  6043. var filename = getPDFFileNameFromURL(url);
  6044. var downloadManager = this.downloadManager;
  6045. downloadManager.onerror = function (err) {
  6046. PDFViewerApplication.error('PDF failed to download.');
  6047. };
  6048. if (!this.pdfDocument) {
  6049. downloadByUrl();
  6050. return;
  6051. }
  6052. if (!this.downloadComplete) {
  6053. downloadByUrl();
  6054. return;
  6055. }
  6056. this.pdfDocument.getData().then(function getDataSuccess(data) {
  6057. var blob = pdfjsLib.createBlob(data, 'application/pdf');
  6058. downloadManager.download(blob, url, filename);
  6059. }, downloadByUrl).then(null, downloadByUrl);
  6060. },
  6061. fallback: function pdfViewFallback(featureId) {
  6062. },
  6063. error: function pdfViewError(message, moreInfo) {
  6064. var moreInfoText = mozL10n.get('error_version_info', {
  6065. version: pdfjsLib.version || '?',
  6066. build: pdfjsLib.build || '?'
  6067. }, 'PDF.js v{{version}} (build: {{build}})') + '\n';
  6068. if (moreInfo) {
  6069. moreInfoText += mozL10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}');
  6070. if (moreInfo.stack) {
  6071. moreInfoText += '\n' + mozL10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}');
  6072. } else {
  6073. if (moreInfo.filename) {
  6074. moreInfoText += '\n' + mozL10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}');
  6075. }
  6076. if (moreInfo.lineNumber) {
  6077. moreInfoText += '\n' + mozL10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}');
  6078. }
  6079. }
  6080. }
  6081. var errorWrapperConfig = this.appConfig.errorWrapper;
  6082. var errorWrapper = errorWrapperConfig.container;
  6083. errorWrapper.removeAttribute('hidden');
  6084. var errorMessage = errorWrapperConfig.errorMessage;
  6085. errorMessage.textContent = message;
  6086. var closeButton = errorWrapperConfig.closeButton;
  6087. closeButton.onclick = function () {
  6088. errorWrapper.setAttribute('hidden', 'true');
  6089. };
  6090. var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  6091. var moreInfoButton = errorWrapperConfig.moreInfoButton;
  6092. var lessInfoButton = errorWrapperConfig.lessInfoButton;
  6093. moreInfoButton.onclick = function () {
  6094. errorMoreInfo.removeAttribute('hidden');
  6095. moreInfoButton.setAttribute('hidden', 'true');
  6096. lessInfoButton.removeAttribute('hidden');
  6097. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
  6098. };
  6099. lessInfoButton.onclick = function () {
  6100. errorMoreInfo.setAttribute('hidden', 'true');
  6101. moreInfoButton.removeAttribute('hidden');
  6102. lessInfoButton.setAttribute('hidden', 'true');
  6103. };
  6104. moreInfoButton.oncontextmenu = noContextMenuHandler;
  6105. lessInfoButton.oncontextmenu = noContextMenuHandler;
  6106. closeButton.oncontextmenu = noContextMenuHandler;
  6107. moreInfoButton.removeAttribute('hidden');
  6108. lessInfoButton.setAttribute('hidden', 'true');
  6109. errorMoreInfo.value = moreInfoText;
  6110. },
  6111. progress: function pdfViewProgress(level) {
  6112. var percent = Math.round(level * 100);
  6113. if (percent > this.loadingBar.percent || isNaN(percent)) {
  6114. this.loadingBar.percent = percent;
  6115. if (pdfjsLib.PDFJS.disableAutoFetch && percent) {
  6116. if (this.disableAutoFetchLoadingBarTimeout) {
  6117. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  6118. this.disableAutoFetchLoadingBarTimeout = null;
  6119. }
  6120. this.loadingBar.show();
  6121. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  6122. this.loadingBar.hide();
  6123. this.disableAutoFetchLoadingBarTimeout = null;
  6124. }.bind(this), DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  6125. }
  6126. }
  6127. },
  6128. load: function pdfViewLoad(pdfDocument, scale) {
  6129. var self = this;
  6130. scale = scale || UNKNOWN_SCALE;
  6131. this.pdfDocument = pdfDocument;
  6132. this.pdfDocumentProperties.setDocumentAndUrl(pdfDocument, this.url);
  6133. var downloadedPromise = pdfDocument.getDownloadInfo().then(function () {
  6134. self.downloadComplete = true;
  6135. self.loadingBar.hide();
  6136. });
  6137. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  6138. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  6139. var id = this.documentFingerprint = pdfDocument.fingerprint;
  6140. var store = this.store = new ViewHistory(id);
  6141. var baseDocumentUrl;
  6142. baseDocumentUrl = null;
  6143. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  6144. var pdfViewer = this.pdfViewer;
  6145. pdfViewer.currentScale = scale;
  6146. pdfViewer.setDocument(pdfDocument);
  6147. var firstPagePromise = pdfViewer.firstPagePromise;
  6148. var pagesPromise = pdfViewer.pagesPromise;
  6149. var onePageRendered = pdfViewer.onePageRendered;
  6150. this.pageRotation = 0;
  6151. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  6152. pdfThumbnailViewer.setDocument(pdfDocument);
  6153. firstPagePromise.then(function (pdfPage) {
  6154. downloadedPromise.then(function () {
  6155. self.eventBus.dispatch('documentload', { source: self });
  6156. });
  6157. self.loadingBar.setWidth(self.appConfig.viewerContainer);
  6158. if (!pdfjsLib.PDFJS.disableHistory && !self.isViewerEmbedded) {
  6159. if (!self.viewerPrefs['showPreviousViewOnLoad']) {
  6160. self.pdfHistory.clearHistoryState();
  6161. }
  6162. self.pdfHistory.initialize(self.documentFingerprint);
  6163. if (self.pdfHistory.initialDestination) {
  6164. self.initialDestination = self.pdfHistory.initialDestination;
  6165. } else if (self.pdfHistory.initialBookmark) {
  6166. self.initialBookmark = self.pdfHistory.initialBookmark;
  6167. }
  6168. }
  6169. var initialParams = {
  6170. destination: self.initialDestination,
  6171. bookmark: self.initialBookmark,
  6172. hash: null
  6173. };
  6174. store.initializedPromise.then(function resolved() {
  6175. var storedHash = null, sidebarView = null;
  6176. if (self.viewerPrefs['showPreviousViewOnLoad'] && store.get('exists', false)) {
  6177. var pageNum = store.get('page', '1');
  6178. var zoom = self.viewerPrefs['defaultZoomValue'] || store.get('zoom', DEFAULT_SCALE_VALUE);
  6179. var left = store.get('scrollLeft', '0');
  6180. var top = store.get('scrollTop', '0');
  6181. storedHash = 'page=' + pageNum + '&zoom=' + zoom + ',' + left + ',' + top;
  6182. sidebarView = store.get('sidebarView', SidebarView.NONE);
  6183. } else if (self.viewerPrefs['defaultZoomValue']) {
  6184. storedHash = 'page=1&zoom=' + self.viewerPrefs['defaultZoomValue'];
  6185. }
  6186. self.setInitialView(storedHash, {
  6187. scale: scale,
  6188. sidebarView: sidebarView
  6189. });
  6190. initialParams.hash = storedHash;
  6191. if (!self.isViewerEmbedded) {
  6192. self.pdfViewer.focus();
  6193. }
  6194. }, function rejected(reason) {
  6195. console.error(reason);
  6196. self.setInitialView(null, { scale: scale });
  6197. });
  6198. pagesPromise.then(function resolved() {
  6199. if (!initialParams.destination && !initialParams.bookmark && !initialParams.hash) {
  6200. return;
  6201. }
  6202. if (self.hasEqualPageSizes) {
  6203. return;
  6204. }
  6205. self.initialDestination = initialParams.destination;
  6206. self.initialBookmark = initialParams.bookmark;
  6207. self.pdfViewer.currentScaleValue = self.pdfViewer.currentScaleValue;
  6208. self.setInitialView(initialParams.hash);
  6209. });
  6210. });
  6211. pdfDocument.getPageLabels().then(function (labels) {
  6212. if (!labels || self.viewerPrefs['disablePageLabels']) {
  6213. return;
  6214. }
  6215. var i = 0, numLabels = labels.length;
  6216. if (numLabels !== self.pagesCount) {
  6217. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  6218. return;
  6219. }
  6220. while (i < numLabels && labels[i] === (i + 1).toString()) {
  6221. i++;
  6222. }
  6223. if (i === numLabels) {
  6224. return;
  6225. }
  6226. pdfViewer.setPageLabels(labels);
  6227. pdfThumbnailViewer.setPageLabels(labels);
  6228. self.toolbar.setPagesCount(pdfDocument.numPages, true);
  6229. self.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  6230. });
  6231. pagesPromise.then(function () {
  6232. if (self.supportsPrinting) {
  6233. pdfDocument.getJavaScript().then(function (javaScript) {
  6234. if (javaScript.length) {
  6235. console.warn('Warning: JavaScript is not supported');
  6236. self.fallback(pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  6237. }
  6238. var regex = /\bprint\s*\(/;
  6239. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  6240. var js = javaScript[i];
  6241. if (js && regex.test(js)) {
  6242. setTimeout(function () {
  6243. window.print();
  6244. });
  6245. return;
  6246. }
  6247. }
  6248. });
  6249. }
  6250. });
  6251. Promise.all([
  6252. onePageRendered,
  6253. animationStarted
  6254. ]).then(function () {
  6255. pdfDocument.getOutline().then(function (outline) {
  6256. self.pdfOutlineViewer.render({ outline: outline });
  6257. });
  6258. pdfDocument.getAttachments().then(function (attachments) {
  6259. self.pdfAttachmentViewer.render({ attachments: attachments });
  6260. });
  6261. });
  6262. pdfDocument.getMetadata().then(function (data) {
  6263. var info = data.info, metadata = data.metadata;
  6264. self.documentInfo = info;
  6265. self.metadata = metadata;
  6266. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (pdfjsLib.version || '-') + (!pdfjsLib.PDFJS.disableWebGL ? ' [WebGL]' : '') + ')');
  6267. var pdfTitle;
  6268. if (metadata && metadata.has('dc:title')) {
  6269. var title = metadata.get('dc:title');
  6270. if (title !== 'Untitled') {
  6271. pdfTitle = title;
  6272. }
  6273. }
  6274. if (!pdfTitle && info && info['Title']) {
  6275. pdfTitle = info['Title'];
  6276. }
  6277. if (pdfTitle) {
  6278. self.setTitle(pdfTitle + ' - ' + document.title);
  6279. }
  6280. if (info.IsAcroFormPresent) {
  6281. console.warn('Warning: AcroForm/XFA is not supported');
  6282. self.fallback(pdfjsLib.UNSUPPORTED_FEATURES.forms);
  6283. }
  6284. });
  6285. },
  6286. setInitialView: function pdfViewSetInitialView(storedHash, options) {
  6287. var scale = options && options.scale;
  6288. var sidebarView = options && options.sidebarView;
  6289. this.isInitialViewSet = true;
  6290. this.pdfSidebar.setInitialView(this.viewerPrefs['sidebarViewOnLoad'] || sidebarView | 0);
  6291. if (this.initialDestination) {
  6292. this.pdfLinkService.navigateTo(this.initialDestination);
  6293. this.initialDestination = null;
  6294. } else if (this.initialBookmark) {
  6295. this.pdfLinkService.setHash(this.initialBookmark);
  6296. this.pdfHistory.push({ hash: this.initialBookmark }, true);
  6297. this.initialBookmark = null;
  6298. } else if (storedHash) {
  6299. this.pdfLinkService.setHash(storedHash);
  6300. } else if (scale) {
  6301. this.pdfViewer.currentScaleValue = scale;
  6302. this.page = 1;
  6303. }
  6304. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  6305. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  6306. if (!this.pdfViewer.currentScaleValue) {
  6307. this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
  6308. }
  6309. },
  6310. cleanup: function pdfViewCleanup() {
  6311. if (!this.pdfDocument) {
  6312. return;
  6313. }
  6314. this.pdfViewer.cleanup();
  6315. this.pdfThumbnailViewer.cleanup();
  6316. if (this.pdfViewer.renderer !== RendererType.SVG) {
  6317. this.pdfDocument.cleanup();
  6318. }
  6319. },
  6320. forceRendering: function pdfViewForceRendering() {
  6321. this.pdfRenderingQueue.printing = this.printing;
  6322. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  6323. this.pdfRenderingQueue.renderHighestPriority();
  6324. },
  6325. beforePrint: function pdfViewSetupBeforePrint() {
  6326. if (this.printService) {
  6327. return;
  6328. }
  6329. if (!this.supportsPrinting) {
  6330. var printMessage = mozL10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by this browser.');
  6331. this.error(printMessage);
  6332. return;
  6333. }
  6334. if (!this.pdfViewer.pageViewsReady) {
  6335. var notReadyMessage = mozL10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.');
  6336. window.alert(notReadyMessage);
  6337. return;
  6338. }
  6339. var pagesOverview = this.pdfViewer.getPagesOverview();
  6340. var printContainer = this.appConfig.printContainer;
  6341. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer);
  6342. this.printService = printService;
  6343. this.forceRendering();
  6344. printService.layout();
  6345. },
  6346. get hasEqualPageSizes() {
  6347. var firstPage = this.pdfViewer.getPageView(0);
  6348. for (var i = 1, ii = this.pagesCount; i < ii; ++i) {
  6349. var pageView = this.pdfViewer.getPageView(i);
  6350. if (pageView.width !== firstPage.width || pageView.height !== firstPage.height) {
  6351. return false;
  6352. }
  6353. }
  6354. return true;
  6355. },
  6356. afterPrint: function pdfViewSetupAfterPrint() {
  6357. if (this.printService) {
  6358. this.printService.destroy();
  6359. this.printService = null;
  6360. }
  6361. this.forceRendering();
  6362. },
  6363. rotatePages: function pdfViewRotatePages(delta) {
  6364. var pageNumber = this.page;
  6365. this.pageRotation = (this.pageRotation + 360 + delta) % 360;
  6366. this.pdfViewer.pagesRotation = this.pageRotation;
  6367. this.pdfThumbnailViewer.pagesRotation = this.pageRotation;
  6368. this.forceRendering();
  6369. this.pdfViewer.currentPageNumber = pageNumber;
  6370. },
  6371. requestPresentationMode: function pdfViewRequestPresentationMode() {
  6372. if (!this.pdfPresentationMode) {
  6373. return;
  6374. }
  6375. this.pdfPresentationMode.request();
  6376. },
  6377. bindEvents: function pdfViewBindEvents() {
  6378. var eventBus = this.eventBus;
  6379. eventBus.on('resize', webViewerResize);
  6380. eventBus.on('hashchange', webViewerHashchange);
  6381. eventBus.on('beforeprint', this.beforePrint.bind(this));
  6382. eventBus.on('afterprint', this.afterPrint.bind(this));
  6383. eventBus.on('pagerendered', webViewerPageRendered);
  6384. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  6385. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  6386. eventBus.on('pagechanging', webViewerPageChanging);
  6387. eventBus.on('scalechanging', webViewerScaleChanging);
  6388. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  6389. eventBus.on('pagemode', webViewerPageMode);
  6390. eventBus.on('namedaction', webViewerNamedAction);
  6391. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  6392. eventBus.on('presentationmode', webViewerPresentationMode);
  6393. eventBus.on('openfile', webViewerOpenFile);
  6394. eventBus.on('print', webViewerPrint);
  6395. eventBus.on('download', webViewerDownload);
  6396. eventBus.on('firstpage', webViewerFirstPage);
  6397. eventBus.on('lastpage', webViewerLastPage);
  6398. eventBus.on('nextpage', webViewerNextPage);
  6399. eventBus.on('previouspage', webViewerPreviousPage);
  6400. eventBus.on('zoomin', webViewerZoomIn);
  6401. eventBus.on('zoomout', webViewerZoomOut);
  6402. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  6403. eventBus.on('scalechanged', webViewerScaleChanged);
  6404. eventBus.on('rotatecw', webViewerRotateCw);
  6405. eventBus.on('rotateccw', webViewerRotateCcw);
  6406. eventBus.on('documentproperties', webViewerDocumentProperties);
  6407. eventBus.on('find', webViewerFind);
  6408. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  6409. eventBus.on('fileinputchange', webViewerFileInputChange);
  6410. },
  6411. bindWindowEvents: function pdfViewBindWindowEvents() {
  6412. var eventBus = this.eventBus;
  6413. window.addEventListener('wheel', webViewerWheel);
  6414. window.addEventListener('click', webViewerClick);
  6415. window.addEventListener('keydown', webViewerKeyDown);
  6416. window.addEventListener('resize', function windowResize() {
  6417. eventBus.dispatch('resize');
  6418. });
  6419. window.addEventListener('hashchange', function windowHashChange() {
  6420. eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
  6421. });
  6422. window.addEventListener('beforeprint', function windowBeforePrint() {
  6423. eventBus.dispatch('beforeprint');
  6424. });
  6425. window.addEventListener('afterprint', function windowAfterPrint() {
  6426. eventBus.dispatch('afterprint');
  6427. });
  6428. window.addEventListener('change', function windowChange(evt) {
  6429. var files = evt.target.files;
  6430. if (!files || files.length === 0) {
  6431. return;
  6432. }
  6433. eventBus.dispatch('fileinputchange', { fileInput: evt.target });
  6434. });
  6435. }
  6436. };
  6437. var validateFileURL;
  6438. var HOSTED_VIEWER_ORIGINS = [
  6439. 'null',
  6440. 'http://mozilla.github.io',
  6441. 'https://mozilla.github.io'
  6442. ];
  6443. validateFileURL = function validateFileURL(file) {
  6444. try {
  6445. var viewerOrigin = new URL(window.location.href).origin || 'null';
  6446. if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
  6447. return;
  6448. }
  6449. var fileOrigin = new URL(file, window.location.href).origin;
  6450. if (fileOrigin !== viewerOrigin) {
  6451. throw new Error('file origin does not match viewer\'s');
  6452. }
  6453. } catch (e) {
  6454. var message = e && e.message;
  6455. var loadingErrorMessage = mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  6456. var moreInfo = { message: message };
  6457. PDFViewerApplication.error(loadingErrorMessage, moreInfo);
  6458. throw e;
  6459. }
  6460. };
  6461. function loadAndEnablePDFBug(enabledTabs) {
  6462. return new Promise(function (resolve, reject) {
  6463. var appConfig = PDFViewerApplication.appConfig;
  6464. var script = document.createElement('script');
  6465. script.src = appConfig.debuggerScriptPath;
  6466. script.onload = function () {
  6467. PDFBug.enable(enabledTabs);
  6468. PDFBug.init(pdfjsLib, appConfig.mainContainer);
  6469. resolve();
  6470. };
  6471. script.onerror = function () {
  6472. reject(new Error('Cannot load debugger at ' + script.src));
  6473. };
  6474. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  6475. });
  6476. }
  6477. function webViewerInitialized() {
  6478. var file;
  6479. var queryString = document.location.search.substring(1);
  6480. var params = parseQueryString(queryString);
  6481. file = 'file' in params ? params.file : DEFAULT_URL;
  6482. validateFileURL(file);
  6483. var waitForBeforeOpening = [];
  6484. var appConfig = PDFViewerApplication.appConfig;
  6485. var fileInput = document.createElement('input');
  6486. fileInput.id = appConfig.openFileInputName;
  6487. fileInput.className = 'fileInput';
  6488. fileInput.setAttribute('type', 'file');
  6489. fileInput.oncontextmenu = noContextMenuHandler;
  6490. document.body.appendChild(fileInput);
  6491. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  6492. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  6493. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  6494. } else {
  6495. fileInput.value = null;
  6496. }
  6497. var PDFJS = pdfjsLib.PDFJS;
  6498. if (PDFViewerApplication.viewerPrefs['pdfBugEnabled']) {
  6499. var hash = document.location.hash.substring(1);
  6500. var hashParams = parseQueryString(hash);
  6501. if ('disableworker' in hashParams) {
  6502. PDFJS.disableWorker = hashParams['disableworker'] === 'true';
  6503. }
  6504. if ('disablerange' in hashParams) {
  6505. PDFJS.disableRange = hashParams['disablerange'] === 'true';
  6506. }
  6507. if ('disablestream' in hashParams) {
  6508. PDFJS.disableStream = hashParams['disablestream'] === 'true';
  6509. }
  6510. if ('disableautofetch' in hashParams) {
  6511. PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
  6512. }
  6513. if ('disablefontface' in hashParams) {
  6514. PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
  6515. }
  6516. if ('disablehistory' in hashParams) {
  6517. PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
  6518. }
  6519. if ('webgl' in hashParams) {
  6520. PDFJS.disableWebGL = hashParams['webgl'] !== 'true';
  6521. }
  6522. if ('useonlycsszoom' in hashParams) {
  6523. PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
  6524. }
  6525. if ('verbosity' in hashParams) {
  6526. PDFJS.verbosity = hashParams['verbosity'] | 0;
  6527. }
  6528. if ('ignorecurrentpositiononzoom' in hashParams) {
  6529. PDFJS.ignoreCurrentPositionOnZoom = hashParams['ignorecurrentpositiononzoom'] === 'true';
  6530. }
  6531. if ('locale' in hashParams) {
  6532. PDFJS.locale = hashParams['locale'];
  6533. }
  6534. if ('textlayer' in hashParams) {
  6535. switch (hashParams['textlayer']) {
  6536. case 'off':
  6537. PDFJS.disableTextLayer = true;
  6538. break;
  6539. case 'visible':
  6540. case 'shadow':
  6541. case 'hover':
  6542. var viewer = appConfig.viewerContainer;
  6543. viewer.classList.add('textLayer-' + hashParams['textlayer']);
  6544. break;
  6545. }
  6546. }
  6547. if ('pdfbug' in hashParams) {
  6548. PDFJS.pdfBug = true;
  6549. var pdfBug = hashParams['pdfbug'];
  6550. var enabled = pdfBug.split(',');
  6551. waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
  6552. }
  6553. }
  6554. mozL10n.setLanguage(PDFJS.locale);
  6555. if (!PDFViewerApplication.supportsPrinting) {
  6556. appConfig.toolbar.print.classList.add('hidden');
  6557. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  6558. }
  6559. if (!PDFViewerApplication.supportsFullscreen) {
  6560. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  6561. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  6562. }
  6563. if (PDFViewerApplication.supportsIntegratedFind) {
  6564. appConfig.toolbar.viewFind.classList.add('hidden');
  6565. }
  6566. appConfig.sidebar.mainContainer.addEventListener('transitionend', function (e) {
  6567. if (e.target === this) {
  6568. PDFViewerApplication.eventBus.dispatch('resize');
  6569. }
  6570. }, true);
  6571. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  6572. PDFViewerApplication.pdfSidebar.toggle();
  6573. });
  6574. Promise.all(waitForBeforeOpening).then(function () {
  6575. webViewerOpenFileViaURL(file);
  6576. }).catch(function (reason) {
  6577. PDFViewerApplication.error(mozL10n.get('loading_error', null, 'An error occurred while opening.'), reason);
  6578. });
  6579. }
  6580. var webViewerOpenFileViaURL;
  6581. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  6582. if (file && file.lastIndexOf('file:', 0) === 0) {
  6583. PDFViewerApplication.setTitleUsingUrl(file);
  6584. var xhr = new XMLHttpRequest();
  6585. xhr.onload = function () {
  6586. PDFViewerApplication.open(new Uint8Array(xhr.response));
  6587. };
  6588. try {
  6589. xhr.open('GET', file);
  6590. xhr.responseType = 'arraybuffer';
  6591. xhr.send();
  6592. } catch (e) {
  6593. PDFViewerApplication.error(mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.'), e);
  6594. }
  6595. return;
  6596. }
  6597. if (file) {
  6598. PDFViewerApplication.open(file);
  6599. }
  6600. };
  6601. function webViewerPageRendered(e) {
  6602. var pageNumber = e.pageNumber;
  6603. var pageIndex = pageNumber - 1;
  6604. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  6605. if (pageNumber === PDFViewerApplication.page) {
  6606. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  6607. }
  6608. if (!pageView) {
  6609. return;
  6610. }
  6611. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  6612. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  6613. thumbnailView.setImage(pageView);
  6614. }
  6615. if (pdfjsLib.PDFJS.pdfBug && Stats.enabled && pageView.stats) {
  6616. Stats.add(pageNumber, pageView.stats);
  6617. }
  6618. if (pageView.error) {
  6619. PDFViewerApplication.error(mozL10n.get('rendering_error', null, 'An error occurred while rendering the page.'), pageView.error);
  6620. }
  6621. }
  6622. function webViewerTextLayerRendered(e) {
  6623. }
  6624. function webViewerPageMode(e) {
  6625. var mode = e.mode, view;
  6626. switch (mode) {
  6627. case 'thumbs':
  6628. view = SidebarView.THUMBS;
  6629. break;
  6630. case 'bookmarks':
  6631. case 'outline':
  6632. view = SidebarView.OUTLINE;
  6633. break;
  6634. case 'attachments':
  6635. view = SidebarView.ATTACHMENTS;
  6636. break;
  6637. case 'none':
  6638. view = SidebarView.NONE;
  6639. break;
  6640. default:
  6641. console.error('Invalid "pagemode" hash parameter: ' + mode);
  6642. return;
  6643. }
  6644. PDFViewerApplication.pdfSidebar.switchView(view, true);
  6645. }
  6646. function webViewerNamedAction(e) {
  6647. var action = e.action;
  6648. switch (action) {
  6649. case 'GoToPage':
  6650. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  6651. break;
  6652. case 'Find':
  6653. if (!PDFViewerApplication.supportsIntegratedFind) {
  6654. PDFViewerApplication.findBar.toggle();
  6655. }
  6656. break;
  6657. }
  6658. }
  6659. function webViewerPresentationModeChanged(e) {
  6660. var active = e.active;
  6661. var switchInProgress = e.switchInProgress;
  6662. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? PresentationModeState.CHANGING : active ? PresentationModeState.FULLSCREEN : PresentationModeState.NORMAL;
  6663. }
  6664. function webViewerSidebarViewChanged(e) {
  6665. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  6666. var store = PDFViewerApplication.store;
  6667. if (!store || !PDFViewerApplication.isInitialViewSet) {
  6668. return;
  6669. }
  6670. store.initializedPromise.then(function () {
  6671. store.set('sidebarView', e.view).catch(function () {
  6672. });
  6673. });
  6674. }
  6675. function webViewerUpdateViewarea(e) {
  6676. var location = e.location, store = PDFViewerApplication.store;
  6677. if (store) {
  6678. store.initializedPromise.then(function () {
  6679. store.setMultiple({
  6680. 'exists': true,
  6681. 'page': location.pageNumber,
  6682. 'zoom': location.scale,
  6683. 'scrollLeft': location.left,
  6684. 'scrollTop': location.top
  6685. }).catch(function () {
  6686. });
  6687. });
  6688. }
  6689. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  6690. //PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  6691. //PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  6692. //PDFViewerApplication.pdfHistory.updateCurrentBookmark(location.pdfOpenParams, location.pageNumber);
  6693. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  6694. var loading = currentPage.renderingState !== RenderingStates.FINISHED;
  6695. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  6696. }
  6697. function webViewerResize() {
  6698. var currentScaleValue = PDFViewerApplication.pdfViewer.currentScaleValue;
  6699. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  6700. PDFViewerApplication.pdfViewer.currentScaleValue = currentScaleValue;
  6701. } else if (!currentScaleValue) {
  6702. PDFViewerApplication.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
  6703. }
  6704. PDFViewerApplication.pdfViewer.update();
  6705. }
  6706. function webViewerHashchange(e) {
  6707. if (PDFViewerApplication.pdfHistory.isHashChangeUnlocked) {
  6708. var hash = e.hash;
  6709. if (!hash) {
  6710. return;
  6711. }
  6712. if (!PDFViewerApplication.isInitialViewSet) {
  6713. PDFViewerApplication.initialBookmark = hash;
  6714. } else {
  6715. PDFViewerApplication.pdfLinkService.setHash(hash);
  6716. }
  6717. }
  6718. }
  6719. var webViewerFileInputChange;
  6720. webViewerFileInputChange = function webViewerFileInputChange(e) {
  6721. var file = e.fileInput.files[0];
  6722. if (!pdfjsLib.PDFJS.disableCreateObjectURL && typeof URL !== 'undefined' && URL.createObjectURL) {
  6723. PDFViewerApplication.open(URL.createObjectURL(file));
  6724. } else {
  6725. var fileReader = new FileReader();
  6726. fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
  6727. var buffer = evt.target.result;
  6728. var uint8Array = new Uint8Array(buffer);
  6729. PDFViewerApplication.open(uint8Array);
  6730. };
  6731. fileReader.readAsArrayBuffer(file);
  6732. }
  6733. PDFViewerApplication.setTitleUsingUrl(file.name);
  6734. var appConfig = PDFViewerApplication.appConfig;
  6735. appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
  6736. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
  6737. appConfig.toolbar.download.setAttribute('hidden', 'true');
  6738. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  6739. };
  6740. function webViewerPresentationMode() {
  6741. PDFViewerApplication.requestPresentationMode();
  6742. }
  6743. function webViewerOpenFile() {
  6744. var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  6745. document.getElementById(openFileInputName).click();
  6746. }
  6747. function webViewerPrint() {
  6748. window.print();
  6749. }
  6750. function webViewerDownload() {
  6751. PDFViewerApplication.download();
  6752. }
  6753. function webViewerFirstPage() {
  6754. if (PDFViewerApplication.pdfDocument) {
  6755. PDFViewerApplication.page = 1;
  6756. }
  6757. }
  6758. function webViewerLastPage() {
  6759. if (PDFViewerApplication.pdfDocument) {
  6760. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  6761. }
  6762. }
  6763. function webViewerNextPage() {
  6764. PDFViewerApplication.page++;
  6765. }
  6766. function webViewerPreviousPage() {
  6767. PDFViewerApplication.page--;
  6768. }
  6769. function webViewerZoomIn() {
  6770. PDFViewerApplication.zoomIn();
  6771. }
  6772. function webViewerZoomOut() {
  6773. PDFViewerApplication.zoomOut();
  6774. }
  6775. function webViewerPageNumberChanged(e) {
  6776. var pdfViewer = PDFViewerApplication.pdfViewer;
  6777. pdfViewer.currentPageLabel = e.value;
  6778. if (e.value !== pdfViewer.currentPageNumber.toString() && e.value !== pdfViewer.currentPageLabel) {
  6779. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  6780. }
  6781. }
  6782. function webViewerScaleChanged(e) {
  6783. PDFViewerApplication.pdfViewer.currentScaleValue = e.value;
  6784. }
  6785. function webViewerRotateCw() {
  6786. PDFViewerApplication.rotatePages(90);
  6787. }
  6788. function webViewerRotateCcw() {
  6789. PDFViewerApplication.rotatePages(-90);
  6790. }
  6791. function webViewerDocumentProperties() {
  6792. PDFViewerApplication.pdfDocumentProperties.open();
  6793. }
  6794. function webViewerFind(e) {
  6795. PDFViewerApplication.findController.executeCommand('find' + e.type, {
  6796. query: e.query,
  6797. phraseSearch: e.phraseSearch,
  6798. caseSensitive: e.caseSensitive,
  6799. highlightAll: e.highlightAll,
  6800. findPrevious: e.findPrevious
  6801. });
  6802. }
  6803. function webViewerFindFromUrlHash(e) {
  6804. PDFViewerApplication.findController.executeCommand('find', {
  6805. query: e.query,
  6806. phraseSearch: e.phraseSearch,
  6807. caseSensitive: false,
  6808. highlightAll: true,
  6809. findPrevious: false
  6810. });
  6811. }
  6812. function webViewerScaleChanging(e) {
  6813. PDFViewerApplication.toolbar.setPageScale(e.presetValue, e.scale);
  6814. PDFViewerApplication.pdfViewer.update();
  6815. }
  6816. function webViewerPageChanging(e) {
  6817. var page = e.pageNumber;
  6818. PDFViewerApplication.toolbar.setPageNumber(page, e.pageLabel || null);
  6819. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  6820. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  6821. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  6822. }
  6823. if (pdfjsLib.PDFJS.pdfBug && Stats.enabled) {
  6824. var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  6825. if (pageView.stats) {
  6826. Stats.add(page, pageView.stats);
  6827. }
  6828. }
  6829. }
  6830. var zoomDisabled = false, zoomDisabledTimeout;
  6831. function webViewerWheel(evt) {
  6832. var pdfViewer = PDFViewerApplication.pdfViewer;
  6833. if (pdfViewer.isInPresentationMode) {
  6834. return;
  6835. }
  6836. if (evt.ctrlKey || evt.metaKey) {
  6837. var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
  6838. if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
  6839. return;
  6840. }
  6841. evt.preventDefault();
  6842. if (zoomDisabled) {
  6843. return;
  6844. }
  6845. var previousScale = pdfViewer.currentScale;
  6846. var delta = normalizeWheelEventDelta(evt);
  6847. var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  6848. var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  6849. if (ticks < 0) {
  6850. PDFViewerApplication.zoomOut(-ticks);
  6851. } else {
  6852. PDFViewerApplication.zoomIn(ticks);
  6853. }
  6854. var currentScale = pdfViewer.currentScale;
  6855. if (previousScale !== currentScale) {
  6856. var scaleCorrectionFactor = currentScale / previousScale - 1;
  6857. var rect = pdfViewer.container.getBoundingClientRect();
  6858. var dx = evt.clientX - rect.left;
  6859. var dy = evt.clientY - rect.top;
  6860. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  6861. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  6862. }
  6863. } else {
  6864. zoomDisabled = true;
  6865. clearTimeout(zoomDisabledTimeout);
  6866. zoomDisabledTimeout = setTimeout(function () {
  6867. zoomDisabled = false;
  6868. }, 1000);
  6869. }
  6870. }
  6871. function webViewerClick(evt) {
  6872. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  6873. return;
  6874. }
  6875. var appConfig = PDFViewerApplication.appConfig;
  6876. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  6877. PDFViewerApplication.secondaryToolbar.close();
  6878. }
  6879. }
  6880. function webViewerKeyDown(evt) {
  6881. if (OverlayManager.active) {
  6882. return;
  6883. }
  6884. var handled = false, ensureViewerFocused = false;
  6885. var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  6886. var pdfViewer = PDFViewerApplication.pdfViewer;
  6887. var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  6888. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  6889. switch (evt.keyCode) {
  6890. case 70:
  6891. if (!PDFViewerApplication.supportsIntegratedFind) {
  6892. PDFViewerApplication.findBar.open();
  6893. handled = true;
  6894. }
  6895. break;
  6896. case 71:
  6897. if (!PDFViewerApplication.supportsIntegratedFind) {
  6898. var findState = PDFViewerApplication.findController.state;
  6899. if (findState) {
  6900. PDFViewerApplication.findController.executeCommand('findagain', {
  6901. query: findState.query,
  6902. phraseSearch: findState.phraseSearch,
  6903. caseSensitive: findState.caseSensitive,
  6904. highlightAll: findState.highlightAll,
  6905. findPrevious: cmd === 5 || cmd === 12
  6906. });
  6907. }
  6908. handled = true;
  6909. }
  6910. break;
  6911. case 61:
  6912. case 107:
  6913. case 187:
  6914. case 171:
  6915. if (!isViewerInPresentationMode) {
  6916. PDFViewerApplication.zoomIn();
  6917. }
  6918. handled = true;
  6919. break;
  6920. case 173:
  6921. case 109:
  6922. case 189:
  6923. if (!isViewerInPresentationMode) {
  6924. PDFViewerApplication.zoomOut();
  6925. }
  6926. handled = true;
  6927. break;
  6928. case 48:
  6929. case 96:
  6930. if (!isViewerInPresentationMode) {
  6931. setTimeout(function () {
  6932. pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
  6933. });
  6934. handled = false;
  6935. }
  6936. break;
  6937. case 38:
  6938. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  6939. PDFViewerApplication.page = 1;
  6940. handled = true;
  6941. ensureViewerFocused = true;
  6942. }
  6943. break;
  6944. case 40:
  6945. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  6946. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  6947. handled = true;
  6948. ensureViewerFocused = true;
  6949. }
  6950. break;
  6951. }
  6952. }
  6953. if (cmd === 1 || cmd === 8) {
  6954. switch (evt.keyCode) {
  6955. case 83:
  6956. PDFViewerApplication.download();
  6957. handled = true;
  6958. break;
  6959. }
  6960. }
  6961. if (cmd === 3 || cmd === 10) {
  6962. switch (evt.keyCode) {
  6963. case 80:
  6964. PDFViewerApplication.requestPresentationMode();
  6965. handled = true;
  6966. break;
  6967. case 71:
  6968. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  6969. handled = true;
  6970. break;
  6971. }
  6972. }
  6973. if (handled) {
  6974. if (ensureViewerFocused && !isViewerInPresentationMode) {
  6975. pdfViewer.focus();
  6976. }
  6977. evt.preventDefault();
  6978. return;
  6979. }
  6980. var curElement = document.activeElement || document.querySelector(':focus');
  6981. var curElementTagName = curElement && curElement.tagName.toUpperCase();
  6982. if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
  6983. if (evt.keyCode !== 27) {
  6984. return;
  6985. }
  6986. }
  6987. if (cmd === 0) {
  6988. switch (evt.keyCode) {
  6989. case 38:
  6990. case 33:
  6991. case 8:
  6992. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  6993. break;
  6994. }
  6995. case 37:
  6996. if (pdfViewer.isHorizontalScrollbarEnabled) {
  6997. break;
  6998. }
  6999. case 75:
  7000. case 80:
  7001. if (PDFViewerApplication.page > 1) {
  7002. PDFViewerApplication.page--;
  7003. }
  7004. handled = true;
  7005. break;
  7006. case 27:
  7007. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  7008. PDFViewerApplication.secondaryToolbar.close();
  7009. handled = true;
  7010. }
  7011. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  7012. PDFViewerApplication.findBar.close();
  7013. handled = true;
  7014. }
  7015. break;
  7016. case 40:
  7017. case 34:
  7018. case 32:
  7019. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  7020. break;
  7021. }
  7022. case 39:
  7023. if (pdfViewer.isHorizontalScrollbarEnabled) {
  7024. break;
  7025. }
  7026. case 74:
  7027. case 78:
  7028. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  7029. PDFViewerApplication.page++;
  7030. }
  7031. handled = true;
  7032. break;
  7033. case 36:
  7034. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  7035. PDFViewerApplication.page = 1;
  7036. handled = true;
  7037. ensureViewerFocused = true;
  7038. }
  7039. break;
  7040. case 35:
  7041. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  7042. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  7043. handled = true;
  7044. ensureViewerFocused = true;
  7045. }
  7046. break;
  7047. case 72:
  7048. if (!isViewerInPresentationMode) {
  7049. PDFViewerApplication.handTool.toggle();
  7050. }
  7051. break;
  7052. case 82:
  7053. PDFViewerApplication.rotatePages(90);
  7054. break;
  7055. }
  7056. }
  7057. if (cmd === 4) {
  7058. switch (evt.keyCode) {
  7059. case 32:
  7060. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  7061. break;
  7062. }
  7063. if (PDFViewerApplication.page > 1) {
  7064. PDFViewerApplication.page--;
  7065. }
  7066. handled = true;
  7067. break;
  7068. case 82:
  7069. PDFViewerApplication.rotatePages(-90);
  7070. break;
  7071. }
  7072. }
  7073. if (!handled && !isViewerInPresentationMode) {
  7074. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
  7075. ensureViewerFocused = true;
  7076. }
  7077. }
  7078. if (cmd === 2) {
  7079. switch (evt.keyCode) {
  7080. case 37:
  7081. if (isViewerInPresentationMode) {
  7082. PDFViewerApplication.pdfHistory.back();
  7083. handled = true;
  7084. }
  7085. break;
  7086. case 39:
  7087. if (isViewerInPresentationMode) {
  7088. PDFViewerApplication.pdfHistory.forward();
  7089. handled = true;
  7090. }
  7091. break;
  7092. }
  7093. }
  7094. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  7095. pdfViewer.focus();
  7096. }
  7097. if (handled) {
  7098. evt.preventDefault();
  7099. }
  7100. }
  7101. localized.then(function webViewerLocalized() {
  7102. document.getElementsByTagName('html')[0].dir = mozL10n.getDirection();
  7103. });
  7104. var PDFPrintServiceFactory = {
  7105. instance: {
  7106. supportsPrinting: false,
  7107. createPrintService: function () {
  7108. throw new Error('Not implemented: createPrintService');
  7109. }
  7110. }
  7111. };
  7112. exports.PDFViewerApplication = PDFViewerApplication;
  7113. exports.DefaultExernalServices = DefaultExernalServices;
  7114. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  7115. }));
  7116. (function (root, factory) {
  7117. factory(root.pdfjsWebPDFPrintService = {}, root.pdfjsWebUIUtils, root.pdfjsWebOverlayManager, root.pdfjsWebApp, root.pdfjsWebPDFJS);
  7118. }(this, function (exports, uiUtils, overlayManager, app, pdfjsLib) {
  7119. var mozL10n = uiUtils.mozL10n;
  7120. var CSS_UNITS = uiUtils.CSS_UNITS;
  7121. var PDFPrintServiceFactory = app.PDFPrintServiceFactory;
  7122. var OverlayManager = overlayManager.OverlayManager;
  7123. var activeService = null;
  7124. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size) {
  7125. var scratchCanvas = activeService.scratchCanvas;
  7126. var PRINT_RESOLUTION = 150;
  7127. var PRINT_UNITS = PRINT_RESOLUTION / 72.0;
  7128. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  7129. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  7130. var width = Math.floor(size.width * CSS_UNITS) + 'px';
  7131. var height = Math.floor(size.height * CSS_UNITS) + 'px';
  7132. var ctx = scratchCanvas.getContext('2d');
  7133. ctx.save();
  7134. ctx.fillStyle = 'rgb(255, 255, 255)';
  7135. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  7136. ctx.restore();
  7137. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  7138. var renderContext = {
  7139. canvasContext: ctx,
  7140. transform: [
  7141. PRINT_UNITS,
  7142. 0,
  7143. 0,
  7144. PRINT_UNITS,
  7145. 0,
  7146. 0
  7147. ],
  7148. viewport: pdfPage.getViewport(1),
  7149. intent: 'print'
  7150. };
  7151. return pdfPage.render(renderContext).promise;
  7152. }).then(function () {
  7153. return {
  7154. width: width,
  7155. height: height
  7156. };
  7157. });
  7158. }
  7159. function PDFPrintService(pdfDocument, pagesOverview, printContainer) {
  7160. this.pdfDocument = pdfDocument;
  7161. this.pagesOverview = pagesOverview;
  7162. this.printContainer = printContainer;
  7163. this.currentPage = -1;
  7164. this.scratchCanvas = document.createElement('canvas');
  7165. }
  7166. PDFPrintService.prototype = {
  7167. layout: function () {
  7168. this.throwIfInactive();
  7169. var pdfDocument = this.pdfDocument;
  7170. var body = document.querySelector('body');
  7171. body.setAttribute('data-pdfjsprinting', true);
  7172. var hasEqualPageSizes = this.pagesOverview.every(function (size) {
  7173. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  7174. }, this);
  7175. if (!hasEqualPageSizes) {
  7176. console.warn('Not all pages have the same size. The printed ' + 'result may be incorrect!');
  7177. }
  7178. this.pageStyleSheet = document.createElement('style');
  7179. var pageSize = this.pagesOverview[0];
  7180. this.pageStyleSheet.textContent = '@supports ((size:A4) and (size:1pt 1pt)) {' + '@page { size: ' + pageSize.width + 'pt ' + pageSize.height + 'pt;}' + '}';
  7181. body.appendChild(this.pageStyleSheet);
  7182. },
  7183. destroy: function () {
  7184. if (activeService !== this) {
  7185. return;
  7186. }
  7187. this.printContainer.textContent = '';
  7188. if (this.pageStyleSheet && this.pageStyleSheet.parentNode) {
  7189. this.pageStyleSheet.parentNode.removeChild(this.pageStyleSheet);
  7190. this.pageStyleSheet = null;
  7191. }
  7192. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  7193. this.scratchCanvas = null;
  7194. activeService = null;
  7195. ensureOverlay().then(function () {
  7196. if (OverlayManager.active !== 'printServiceOverlay') {
  7197. return;
  7198. }
  7199. OverlayManager.close('printServiceOverlay');
  7200. });
  7201. },
  7202. renderPages: function () {
  7203. var pageCount = this.pagesOverview.length;
  7204. var renderNextPage = function (resolve, reject) {
  7205. this.throwIfInactive();
  7206. if (++this.currentPage >= pageCount) {
  7207. renderProgress(pageCount, pageCount);
  7208. resolve();
  7209. return;
  7210. }
  7211. var index = this.currentPage;
  7212. renderProgress(index, pageCount);
  7213. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index]).then(this.useRenderedPage.bind(this)).then(function () {
  7214. renderNextPage(resolve, reject);
  7215. }, reject);
  7216. }.bind(this);
  7217. return new Promise(renderNextPage);
  7218. },
  7219. useRenderedPage: function (printItem) {
  7220. this.throwIfInactive();
  7221. var img = document.createElement('img');
  7222. img.style.width = printItem.width;
  7223. img.style.height = printItem.height;
  7224. var scratchCanvas = this.scratchCanvas;
  7225. if ('toBlob' in scratchCanvas && !pdfjsLib.PDFJS.disableCreateObjectURL) {
  7226. scratchCanvas.toBlob(function (blob) {
  7227. img.src = URL.createObjectURL(blob);
  7228. });
  7229. } else {
  7230. img.src = scratchCanvas.toDataURL();
  7231. }
  7232. var wrapper = document.createElement('div');
  7233. wrapper.appendChild(img);
  7234. this.printContainer.appendChild(wrapper);
  7235. return new Promise(function (resolve, reject) {
  7236. img.onload = resolve;
  7237. img.onerror = reject;
  7238. });
  7239. },
  7240. performPrint: function () {
  7241. this.throwIfInactive();
  7242. return new Promise(function (resolve) {
  7243. setTimeout(function () {
  7244. if (!this.active) {
  7245. resolve();
  7246. return;
  7247. }
  7248. print.call(window);
  7249. setTimeout(resolve, 20);
  7250. }.bind(this), 0);
  7251. }.bind(this));
  7252. },
  7253. get active() {
  7254. return this === activeService;
  7255. },
  7256. throwIfInactive: function () {
  7257. if (!this.active) {
  7258. throw new Error('This print request was cancelled or completed.');
  7259. }
  7260. }
  7261. };
  7262. var print = window.print;
  7263. window.print = function print() {
  7264. if (activeService) {
  7265. console.warn('Ignored window.print() because of a pending print job.');
  7266. return;
  7267. }
  7268. ensureOverlay().then(function () {
  7269. if (activeService) {
  7270. OverlayManager.open('printServiceOverlay');
  7271. }
  7272. });
  7273. try {
  7274. dispatchEvent('beforeprint');
  7275. } finally {
  7276. if (!activeService) {
  7277. console.error('Expected print service to be initialized.');
  7278. if (OverlayManager.active === 'printServiceOverlay') {
  7279. OverlayManager.close('printServiceOverlay');
  7280. }
  7281. return;
  7282. }
  7283. var activeServiceOnEntry = activeService;
  7284. activeService.renderPages().then(function () {
  7285. return activeServiceOnEntry.performPrint();
  7286. }).catch(function () {
  7287. }).then(function () {
  7288. if (activeServiceOnEntry.active) {
  7289. abort();
  7290. }
  7291. });
  7292. }
  7293. };
  7294. function dispatchEvent(eventType) {
  7295. var event = document.createEvent('CustomEvent');
  7296. event.initCustomEvent(eventType, false, false, 'custom');
  7297. window.dispatchEvent(event);
  7298. }
  7299. function abort() {
  7300. if (activeService) {
  7301. activeService.destroy();
  7302. dispatchEvent('afterprint');
  7303. }
  7304. }
  7305. function renderProgress(index, total) {
  7306. var progressContainer = document.getElementById('printServiceOverlay');
  7307. var progress = Math.round(100 * index / total);
  7308. var progressBar = progressContainer.querySelector('progress');
  7309. var progressPerc = progressContainer.querySelector('.relative-progress');
  7310. progressBar.value = progress;
  7311. progressPerc.textContent = mozL10n.get('print_progress_percent', { progress: progress }, progress + '%');
  7312. }
  7313. var hasAttachEvent = !!document.attachEvent;
  7314. window.addEventListener('keydown', function (event) {
  7315. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  7316. window.print();
  7317. if (hasAttachEvent) {
  7318. return;
  7319. }
  7320. event.preventDefault();
  7321. if (event.stopImmediatePropagation) {
  7322. event.stopImmediatePropagation();
  7323. } else {
  7324. event.stopPropagation();
  7325. }
  7326. return;
  7327. }
  7328. }, true);
  7329. if (hasAttachEvent) {
  7330. document.attachEvent('onkeydown', function (event) {
  7331. event = event || window.event;
  7332. if (event.keyCode === 80 && event.ctrlKey) {
  7333. event.keyCode = 0;
  7334. return false;
  7335. }
  7336. });
  7337. }
  7338. if ('onbeforeprint' in window) {
  7339. var stopPropagationIfNeeded = function (event) {
  7340. if (event.detail !== 'custom' && event.stopImmediatePropagation) {
  7341. event.stopImmediatePropagation();
  7342. }
  7343. };
  7344. window.addEventListener('beforeprint', stopPropagationIfNeeded);
  7345. window.addEventListener('afterprint', stopPropagationIfNeeded);
  7346. }
  7347. var overlayPromise;
  7348. function ensureOverlay() {
  7349. if (!overlayPromise) {
  7350. overlayPromise = OverlayManager.register('printServiceOverlay', document.getElementById('printServiceOverlay'), abort, true);
  7351. document.getElementById('printCancel').onclick = abort;
  7352. }
  7353. return overlayPromise;
  7354. }
  7355. PDFPrintServiceFactory.instance = {
  7356. supportsPrinting: true,
  7357. createPrintService: function (pdfDocument, pagesOverview, printContainer) {
  7358. if (activeService) {
  7359. throw new Error('The print service is created and active.');
  7360. }
  7361. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer);
  7362. return activeService;
  7363. }
  7364. };
  7365. exports.PDFPrintService = PDFPrintService;
  7366. }));
  7367. }.call(pdfjsWebLibs));
  7368. }
  7369. ;
  7370. function getViewerConfiguration() {
  7371. return {
  7372. appContainer: document.body,
  7373. mainContainer: document.getElementById('viewerContainer'),
  7374. viewerContainer: document.getElementById('viewer'),
  7375. eventBus: null,
  7376. toolbar: {
  7377. container: document.getElementById('toolbarViewer'),
  7378. numPages: document.getElementById('numPages'),
  7379. pageNumber: document.getElementById('pageNumber'),
  7380. scaleSelectContainer: document.getElementById('scaleSelectContainer'),
  7381. scaleSelect: document.getElementById('scaleSelect'),
  7382. customScaleOption: document.getElementById('customScaleOption'),
  7383. previous: document.getElementById('previous'),
  7384. next: document.getElementById('next'),
  7385. zoomIn: document.getElementById('zoomIn'),
  7386. zoomOut: document.getElementById('zoomOut'),
  7387. viewFind: document.getElementById('viewFind'),
  7388. openFile: document.getElementById('openFile'),
  7389. print: document.getElementById('print'),
  7390. presentationModeButton: document.getElementById('presentationMode'),
  7391. download: document.getElementById('download'),
  7392. viewBookmark: document.getElementById('viewBookmark')
  7393. },
  7394. secondaryToolbar: {
  7395. toolbar: document.getElementById('secondaryToolbar'),
  7396. toggleButton: document.getElementById('secondaryToolbarToggle'),
  7397. toolbarButtonContainer: document.getElementById('secondaryToolbarButtonContainer'),
  7398. presentationModeButton: document.getElementById('secondaryPresentationMode'),
  7399. openFileButton: document.getElementById('secondaryOpenFile'),
  7400. printButton: document.getElementById('secondaryPrint'),
  7401. downloadButton: document.getElementById('secondaryDownload'),
  7402. viewBookmarkButton: document.getElementById('secondaryViewBookmark'),
  7403. firstPageButton: document.getElementById('firstPage'),
  7404. lastPageButton: document.getElementById('lastPage'),
  7405. pageRotateCwButton: document.getElementById('pageRotateCw'),
  7406. pageRotateCcwButton: document.getElementById('pageRotateCcw'),
  7407. toggleHandToolButton: document.getElementById('toggleHandTool'),
  7408. documentPropertiesButton: document.getElementById('documentProperties')
  7409. },
  7410. fullscreen: {
  7411. contextFirstPage: document.getElementById('contextFirstPage'),
  7412. contextLastPage: document.getElementById('contextLastPage'),
  7413. contextPageRotateCw: document.getElementById('contextPageRotateCw'),
  7414. contextPageRotateCcw: document.getElementById('contextPageRotateCcw')
  7415. },
  7416. sidebar: {
  7417. mainContainer: document.getElementById('mainContainer'),
  7418. outerContainer: document.getElementById('outerContainer'),
  7419. toggleButton: document.getElementById('sidebarToggle'),
  7420. thumbnailButton: document.getElementById('viewThumbnail'),
  7421. outlineButton: document.getElementById('viewOutline'),
  7422. attachmentsButton: document.getElementById('viewAttachments'),
  7423. thumbnailView: document.getElementById('thumbnailView'),
  7424. outlineView: document.getElementById('outlineView'),
  7425. attachmentsView: document.getElementById('attachmentsView')
  7426. },
  7427. findBar: {
  7428. bar: document.getElementById('findbar'),
  7429. toggleButton: document.getElementById('viewFind'),
  7430. findField: document.getElementById('findInput'),
  7431. highlightAllCheckbox: document.getElementById('findHighlightAll'),
  7432. caseSensitiveCheckbox: document.getElementById('findMatchCase'),
  7433. findMsg: document.getElementById('findMsg'),
  7434. findResultsCount: document.getElementById('findResultsCount'),
  7435. findStatusIcon: document.getElementById('findStatusIcon'),
  7436. findPreviousButton: document.getElementById('findPrevious'),
  7437. findNextButton: document.getElementById('findNext')
  7438. },
  7439. passwordOverlay: {
  7440. overlayName: 'passwordOverlay',
  7441. container: document.getElementById('passwordOverlay'),
  7442. label: document.getElementById('passwordText'),
  7443. input: document.getElementById('password'),
  7444. submitButton: document.getElementById('passwordSubmit'),
  7445. cancelButton: document.getElementById('passwordCancel')
  7446. },
  7447. documentProperties: {
  7448. overlayName: 'documentPropertiesOverlay',
  7449. container: document.getElementById('documentPropertiesOverlay'),
  7450. closeButton: document.getElementById('documentPropertiesClose'),
  7451. fields: {
  7452. 'fileName': document.getElementById('fileNameField'),
  7453. 'fileSize': document.getElementById('fileSizeField'),
  7454. 'title': document.getElementById('titleField'),
  7455. 'author': document.getElementById('authorField'),
  7456. 'subject': document.getElementById('subjectField'),
  7457. 'keywords': document.getElementById('keywordsField'),
  7458. 'creationDate': document.getElementById('creationDateField'),
  7459. 'modificationDate': document.getElementById('modificationDateField'),
  7460. 'creator': document.getElementById('creatorField'),
  7461. 'producer': document.getElementById('producerField'),
  7462. 'version': document.getElementById('versionField'),
  7463. 'pageCount': document.getElementById('pageCountField')
  7464. }
  7465. },
  7466. errorWrapper: {
  7467. container: document.getElementById('errorWrapper'),
  7468. errorMessage: document.getElementById('errorMessage'),
  7469. closeButton: document.getElementById('errorClose'),
  7470. errorMoreInfo: document.getElementById('errorMoreInfo'),
  7471. moreInfoButton: document.getElementById('errorShowMore'),
  7472. lessInfoButton: document.getElementById('errorShowLess')
  7473. },
  7474. printContainer: document.getElementById('printContainer'),
  7475. openFileInputName: 'fileInput',
  7476. debuggerScriptPath: './debugger.js'
  7477. };
  7478. }
  7479. function webViewerLoad() {
  7480. var config = getViewerConfiguration();
  7481. window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication;
  7482. pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication.run(config);
  7483. }
  7484. if (document.readyState === 'interactive' || document.readyState === 'complete') {
  7485. webViewerLoad();
  7486. } else {
  7487. document.addEventListener('DOMContentLoaded', webViewerLoad, true);
  7488. }