viewer.js 352 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486
  1. /* Copyright 2017 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. /******/ (function(modules) { // webpackBootstrap
  16. /******/ // The module cache
  17. /******/ var installedModules = {};
  18. /******/
  19. /******/ // The require function
  20. /******/ function __webpack_require__(moduleId) {
  21. /******/
  22. /******/ // Check if module is in cache
  23. /******/ if(installedModules[moduleId]) {
  24. /******/ return installedModules[moduleId].exports;
  25. /******/ }
  26. /******/ // Create a new module (and put it into the cache)
  27. /******/ var module = installedModules[moduleId] = {
  28. /******/ i: moduleId,
  29. /******/ l: false,
  30. /******/ exports: {}
  31. /******/ };
  32. /******/
  33. /******/ // Execute the module function
  34. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  35. /******/
  36. /******/ // Flag the module as loaded
  37. /******/ module.l = true;
  38. /******/
  39. /******/ // Return the exports of the module
  40. /******/ return module.exports;
  41. /******/ }
  42. /******/
  43. /******/
  44. /******/ // expose the modules object (__webpack_modules__)
  45. /******/ __webpack_require__.m = modules;
  46. /******/
  47. /******/ // expose the module cache
  48. /******/ __webpack_require__.c = installedModules;
  49. /******/
  50. /******/ // define getter function for harmony exports
  51. /******/ __webpack_require__.d = function(exports, name, getter) {
  52. /******/ if(!__webpack_require__.o(exports, name)) {
  53. /******/ Object.defineProperty(exports, name, {
  54. /******/ configurable: false,
  55. /******/ enumerable: true,
  56. /******/ get: getter
  57. /******/ });
  58. /******/ }
  59. /******/ };
  60. /******/
  61. /******/ // getDefaultExport function for compatibility with non-harmony modules
  62. /******/ __webpack_require__.n = function(module) {
  63. /******/ var getter = module && module.__esModule ?
  64. /******/ function getDefault() { return module['default']; } :
  65. /******/ function getModuleExports() { return module; };
  66. /******/ __webpack_require__.d(getter, 'a', getter);
  67. /******/ return getter;
  68. /******/ };
  69. /******/
  70. /******/ // Object.prototype.hasOwnProperty.call
  71. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  72. /******/
  73. /******/ // __webpack_public_path__
  74. /******/ __webpack_require__.p = "";
  75. /******/
  76. /******/ // Load entry module and return exports
  77. /******/ return __webpack_require__(__webpack_require__.s = 8);
  78. /******/ })
  79. /************************************************************************/
  80. /******/ ([
  81. /* 0 */
  82. /***/ (function(module, exports, __webpack_require__) {
  83. "use strict";
  84. Object.defineProperty(exports, "__esModule", {
  85. value: true
  86. });
  87. exports.waitOnEventOrTimeout = exports.WaitOnType = exports.localized = exports.animationStarted = exports.normalizeWheelEventDelta = exports.binarySearchFirstItem = exports.watchScroll = exports.scrollIntoView = exports.getOutputScale = exports.approximateFraction = exports.roundToDivide = exports.getVisibleElements = exports.parseQueryString = exports.noContextMenuHandler = exports.getPDFFileNameFromURL = exports.ProgressBar = exports.EventBus = exports.NullL10n = exports.mozL10n = exports.RendererType = exports.PresentationModeState = exports.cloneObj = exports.isValidRotation = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = undefined;
  88. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  89. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  90. var _pdfjsLib = __webpack_require__(1);
  91. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  92. var CSS_UNITS = 96.0 / 72.0;
  93. var DEFAULT_SCALE_VALUE = 'auto';
  94. var DEFAULT_SCALE = 1.0;
  95. var MIN_SCALE = 0.25;
  96. var MAX_SCALE = 10.0;
  97. var UNKNOWN_SCALE = 0;
  98. var MAX_AUTO_SCALE = 1.25;
  99. var SCROLLBAR_PADDING = 40;
  100. var VERTICAL_PADDING = 5;
  101. var PresentationModeState = {
  102. UNKNOWN: 0,
  103. NORMAL: 1,
  104. CHANGING: 2,
  105. FULLSCREEN: 3
  106. };
  107. var RendererType = {
  108. CANVAS: 'canvas',
  109. SVG: 'svg'
  110. };
  111. function formatL10nValue(text, args) {
  112. if (!args) {
  113. return text;
  114. }
  115. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, function (all, name) {
  116. return name in args ? args[name] : '{{' + name + '}}';
  117. });
  118. }
  119. var NullL10n = {
  120. get: function get(property, args, fallback) {
  121. return Promise.resolve(formatL10nValue(fallback, args));
  122. },
  123. translate: function translate(element) {
  124. return Promise.resolve();
  125. }
  126. };
  127. _pdfjsLib.PDFJS.disableFullscreen = _pdfjsLib.PDFJS.disableFullscreen === undefined ? false : _pdfjsLib.PDFJS.disableFullscreen;
  128. _pdfjsLib.PDFJS.useOnlyCssZoom = _pdfjsLib.PDFJS.useOnlyCssZoom === undefined ? false : _pdfjsLib.PDFJS.useOnlyCssZoom;
  129. _pdfjsLib.PDFJS.maxCanvasPixels = _pdfjsLib.PDFJS.maxCanvasPixels === undefined ? 16777216 : _pdfjsLib.PDFJS.maxCanvasPixels;
  130. _pdfjsLib.PDFJS.disableHistory = _pdfjsLib.PDFJS.disableHistory === undefined ? false : _pdfjsLib.PDFJS.disableHistory;
  131. _pdfjsLib.PDFJS.disableTextLayer = _pdfjsLib.PDFJS.disableTextLayer === undefined ? false : _pdfjsLib.PDFJS.disableTextLayer;
  132. _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom = _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom === undefined ? false : _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom;
  133. {
  134. _pdfjsLib.PDFJS.locale = _pdfjsLib.PDFJS.locale === undefined && typeof navigator !== 'undefined' ? navigator.language : _pdfjsLib.PDFJS.locale;
  135. }
  136. function getOutputScale(ctx) {
  137. var devicePixelRatio = window.devicePixelRatio || 1;
  138. var backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  139. var pixelRatio = devicePixelRatio / backingStoreRatio;
  140. return {
  141. sx: pixelRatio,
  142. sy: pixelRatio,
  143. scaled: pixelRatio !== 1
  144. };
  145. }
  146. function scrollIntoView(element, spot) {
  147. var skipOverflowHiddenElements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  148. var parent = element.offsetParent;
  149. if (!parent) {
  150. console.error('offsetParent is not set -- cannot scroll');
  151. return;
  152. }
  153. var offsetY = element.offsetTop + element.clientTop;
  154. var offsetX = element.offsetLeft + element.clientLeft;
  155. while (parent.clientHeight === parent.scrollHeight || skipOverflowHiddenElements && getComputedStyle(parent).overflow === 'hidden') {
  156. if (parent.dataset._scaleY) {
  157. offsetY /= parent.dataset._scaleY;
  158. offsetX /= parent.dataset._scaleX;
  159. }
  160. offsetY += parent.offsetTop;
  161. offsetX += parent.offsetLeft;
  162. parent = parent.offsetParent;
  163. if (!parent) {
  164. return;
  165. }
  166. }
  167. if (spot) {
  168. if (spot.top !== undefined) {
  169. offsetY += spot.top;
  170. }
  171. if (spot.left !== undefined) {
  172. offsetX += spot.left;
  173. parent.scrollLeft = offsetX;
  174. }
  175. }
  176. parent.scrollTop = offsetY;
  177. }
  178. function watchScroll(viewAreaElement, callback) {
  179. var debounceScroll = function debounceScroll(evt) {
  180. if (rAF) {
  181. return;
  182. }
  183. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  184. rAF = null;
  185. var currentY = viewAreaElement.scrollTop;
  186. var lastY = state.lastY;
  187. if (currentY !== lastY) {
  188. state.down = currentY > lastY;
  189. }
  190. state.lastY = currentY;
  191. callback(state);
  192. });
  193. };
  194. var state = {
  195. down: true,
  196. lastY: viewAreaElement.scrollTop,
  197. _eventHandler: debounceScroll
  198. };
  199. var rAF = null;
  200. viewAreaElement.addEventListener('scroll', debounceScroll, true);
  201. return state;
  202. }
  203. function parseQueryString(query) {
  204. var parts = query.split('&');
  205. var params = Object.create(null);
  206. for (var i = 0, ii = parts.length; i < ii; ++i) {
  207. var param = parts[i].split('=');
  208. var key = param[0].toLowerCase();
  209. var value = param.length > 1 ? param[1] : null;
  210. params[decodeURIComponent(key)] = decodeURIComponent(value);
  211. }
  212. return params;
  213. }
  214. function binarySearchFirstItem(items, condition) {
  215. var minIndex = 0;
  216. var maxIndex = items.length - 1;
  217. if (items.length === 0 || !condition(items[maxIndex])) {
  218. return items.length;
  219. }
  220. if (condition(items[minIndex])) {
  221. return minIndex;
  222. }
  223. while (minIndex < maxIndex) {
  224. var currentIndex = minIndex + maxIndex >> 1;
  225. var currentItem = items[currentIndex];
  226. if (condition(currentItem)) {
  227. maxIndex = currentIndex;
  228. } else {
  229. minIndex = currentIndex + 1;
  230. }
  231. }
  232. return minIndex;
  233. }
  234. function approximateFraction(x) {
  235. if (Math.floor(x) === x) {
  236. return [x, 1];
  237. }
  238. var xinv = 1 / x;
  239. var limit = 8;
  240. if (xinv > limit) {
  241. return [1, limit];
  242. } else if (Math.floor(xinv) === xinv) {
  243. return [1, xinv];
  244. }
  245. var x_ = x > 1 ? xinv : x;
  246. var a = 0,
  247. b = 1,
  248. c = 1,
  249. d = 1;
  250. while (true) {
  251. var p = a + c,
  252. q = b + d;
  253. if (q > limit) {
  254. break;
  255. }
  256. if (x_ <= p / q) {
  257. c = p;
  258. d = q;
  259. } else {
  260. a = p;
  261. b = q;
  262. }
  263. }
  264. var result = void 0;
  265. if (x_ - a / b < c / d - x_) {
  266. result = x_ === x ? [a, b] : [b, a];
  267. } else {
  268. result = x_ === x ? [c, d] : [d, c];
  269. }
  270. return result;
  271. }
  272. function roundToDivide(x, div) {
  273. var r = x % div;
  274. return r === 0 ? x : Math.round(x - r + div);
  275. }
  276. function getVisibleElements(scrollEl, views) {
  277. var sortByVisibility = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  278. var top = scrollEl.scrollTop,
  279. bottom = top + scrollEl.clientHeight;
  280. var left = scrollEl.scrollLeft,
  281. right = left + scrollEl.clientWidth;
  282. function isElementBottomBelowViewTop(view) {
  283. var element = view.div;
  284. var elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  285. return elementBottom > top;
  286. }
  287. var visible = [],
  288. view = void 0,
  289. element = void 0;
  290. var currentHeight = void 0,
  291. viewHeight = void 0,
  292. hiddenHeight = void 0,
  293. percentHeight = void 0;
  294. var currentWidth = void 0,
  295. viewWidth = void 0;
  296. var firstVisibleElementInd = views.length === 0 ? 0 : binarySearchFirstItem(views, isElementBottomBelowViewTop);
  297. for (var i = firstVisibleElementInd, ii = views.length; i < ii; i++) {
  298. view = views[i];
  299. element = view.div;
  300. currentHeight = element.offsetTop + element.clientTop;
  301. viewHeight = element.clientHeight;
  302. if (currentHeight > bottom) {
  303. break;
  304. }
  305. currentWidth = element.offsetLeft + element.clientLeft;
  306. viewWidth = element.clientWidth;
  307. if (currentWidth + viewWidth < left || currentWidth > right) {
  308. continue;
  309. }
  310. hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, currentHeight + viewHeight - bottom);
  311. percentHeight = (viewHeight - hiddenHeight) * 100 / viewHeight | 0;
  312. visible.push({
  313. id: view.id,
  314. x: currentWidth,
  315. y: currentHeight,
  316. view: view,
  317. percent: percentHeight
  318. });
  319. }
  320. var first = visible[0];
  321. var last = visible[visible.length - 1];
  322. if (sortByVisibility) {
  323. visible.sort(function (a, b) {
  324. var pc = a.percent - b.percent;
  325. if (Math.abs(pc) > 0.001) {
  326. return -pc;
  327. }
  328. return a.id - b.id;
  329. });
  330. }
  331. return {
  332. first: first,
  333. last: last,
  334. views: visible
  335. };
  336. }
  337. function noContextMenuHandler(evt) {
  338. evt.preventDefault();
  339. }
  340. function isDataSchema(url) {
  341. var i = 0,
  342. ii = url.length;
  343. while (i < ii && url[i].trim() === '') {
  344. i++;
  345. }
  346. return url.substr(i, 5).toLowerCase() === 'data:';
  347. }
  348. function getPDFFileNameFromURL(url) {
  349. var defaultFilename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'document.pdf';
  350. if (isDataSchema(url)) {
  351. console.warn('getPDFFileNameFromURL: ' + 'ignoring "data:" URL for performance reasons.');
  352. return defaultFilename;
  353. }
  354. var reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  355. var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  356. var splitURI = reURI.exec(url);
  357. var suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  358. if (suggestedFilename) {
  359. suggestedFilename = suggestedFilename[0];
  360. if (suggestedFilename.indexOf('%') !== -1) {
  361. try {
  362. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  363. } catch (ex) {}
  364. }
  365. }
  366. return suggestedFilename || defaultFilename;
  367. }
  368. function normalizeWheelEventDelta(evt) {
  369. var delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
  370. var angle = Math.atan2(evt.deltaY, evt.deltaX);
  371. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  372. delta = -delta;
  373. }
  374. var MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  375. var MOUSE_DOM_DELTA_LINE_MODE = 1;
  376. var MOUSE_PIXELS_PER_LINE = 30;
  377. var MOUSE_LINES_PER_PAGE = 30;
  378. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  379. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  380. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  381. delta /= MOUSE_LINES_PER_PAGE;
  382. }
  383. return delta;
  384. }
  385. function isValidRotation(angle) {
  386. return Number.isInteger(angle) && angle % 90 === 0;
  387. }
  388. function cloneObj(obj) {
  389. var result = Object.create(null);
  390. for (var i in obj) {
  391. if (Object.prototype.hasOwnProperty.call(obj, i)) {
  392. result[i] = obj[i];
  393. }
  394. }
  395. return result;
  396. }
  397. var WaitOnType = {
  398. EVENT: 'event',
  399. TIMEOUT: 'timeout'
  400. };
  401. function waitOnEventOrTimeout(_ref) {
  402. var target = _ref.target,
  403. name = _ref.name,
  404. _ref$delay = _ref.delay,
  405. delay = _ref$delay === undefined ? 0 : _ref$delay;
  406. if ((typeof target === 'undefined' ? 'undefined' : _typeof(target)) !== 'object' || !(name && typeof name === 'string') || !(Number.isInteger(delay) && delay >= 0)) {
  407. return Promise.reject(new Error('waitOnEventOrTimeout - invalid paramaters.'));
  408. }
  409. var capability = (0, _pdfjsLib.createPromiseCapability)();
  410. function handler(type) {
  411. if (target instanceof EventBus) {
  412. target.off(name, eventHandler);
  413. } else {
  414. target.removeEventListener(name, eventHandler);
  415. }
  416. if (timeout) {
  417. clearTimeout(timeout);
  418. }
  419. capability.resolve(type);
  420. }
  421. var eventHandler = handler.bind(null, WaitOnType.EVENT);
  422. if (target instanceof EventBus) {
  423. target.on(name, eventHandler);
  424. } else {
  425. target.addEventListener(name, eventHandler);
  426. }
  427. var timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  428. var timeout = setTimeout(timeoutHandler, delay);
  429. return capability.promise;
  430. }
  431. var animationStarted = new Promise(function (resolve) {
  432. window.requestAnimationFrame(resolve);
  433. });
  434. var mozL10n = void 0;
  435. var localized = Promise.resolve();
  436. var EventBus = function () {
  437. function EventBus() {
  438. _classCallCheck(this, EventBus);
  439. this._listeners = Object.create(null);
  440. }
  441. _createClass(EventBus, [{
  442. key: 'on',
  443. value: function on(eventName, listener) {
  444. var eventListeners = this._listeners[eventName];
  445. if (!eventListeners) {
  446. eventListeners = [];
  447. this._listeners[eventName] = eventListeners;
  448. }
  449. eventListeners.push(listener);
  450. }
  451. }, {
  452. key: 'off',
  453. value: function off(eventName, listener) {
  454. var eventListeners = this._listeners[eventName];
  455. var i = void 0;
  456. if (!eventListeners || (i = eventListeners.indexOf(listener)) < 0) {
  457. return;
  458. }
  459. eventListeners.splice(i, 1);
  460. }
  461. }, {
  462. key: 'dispatch',
  463. value: function dispatch(eventName) {
  464. var eventListeners = this._listeners[eventName];
  465. if (!eventListeners || eventListeners.length === 0) {
  466. return;
  467. }
  468. var args = Array.prototype.slice.call(arguments, 1);
  469. eventListeners.slice(0).forEach(function (listener) {
  470. listener.apply(null, args);
  471. });
  472. }
  473. }]);
  474. return EventBus;
  475. }();
  476. function clamp(v, min, max) {
  477. return Math.min(Math.max(v, min), max);
  478. }
  479. var ProgressBar = function () {
  480. function ProgressBar(id) {
  481. var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  482. height = _ref2.height,
  483. width = _ref2.width,
  484. units = _ref2.units;
  485. _classCallCheck(this, ProgressBar);
  486. this.visible = true;
  487. this.div = document.querySelector(id + ' .progress');
  488. this.bar = this.div.parentNode;
  489. this.height = height || 100;
  490. this.width = width || 100;
  491. this.units = units || '%';
  492. this.div.style.height = this.height + this.units;
  493. this.percent = 0;
  494. }
  495. _createClass(ProgressBar, [{
  496. key: '_updateBar',
  497. value: function _updateBar() {
  498. if (this._indeterminate) {
  499. this.div.classList.add('indeterminate');
  500. this.div.style.width = this.width + this.units;
  501. return;
  502. }
  503. this.div.classList.remove('indeterminate');
  504. var progressSize = this.width * this._percent / 100;
  505. this.div.style.width = progressSize + this.units;
  506. }
  507. }, {
  508. key: 'setWidth',
  509. value: function setWidth(viewer) {
  510. if (!viewer) {
  511. return;
  512. }
  513. var container = viewer.parentNode;
  514. var scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  515. if (scrollbarWidth > 0) {
  516. this.bar.setAttribute('style', 'width: calc(100% - ' + scrollbarWidth + 'px);');
  517. }
  518. }
  519. }, {
  520. key: 'hide',
  521. value: function hide() {
  522. if (!this.visible) {
  523. return;
  524. }
  525. this.visible = false;
  526. this.bar.classList.add('hidden');
  527. document.body.classList.remove('loadingInProgress');
  528. }
  529. }, {
  530. key: 'show',
  531. value: function show() {
  532. if (this.visible) {
  533. return;
  534. }
  535. this.visible = true;
  536. document.body.classList.add('loadingInProgress');
  537. this.bar.classList.remove('hidden');
  538. }
  539. }, {
  540. key: 'percent',
  541. get: function get() {
  542. return this._percent;
  543. },
  544. set: function set(val) {
  545. this._indeterminate = isNaN(val);
  546. this._percent = clamp(val, 0, 100);
  547. this._updateBar();
  548. }
  549. }]);
  550. return ProgressBar;
  551. }();
  552. exports.CSS_UNITS = CSS_UNITS;
  553. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  554. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  555. exports.MIN_SCALE = MIN_SCALE;
  556. exports.MAX_SCALE = MAX_SCALE;
  557. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  558. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  559. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  560. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  561. exports.isValidRotation = isValidRotation;
  562. exports.cloneObj = cloneObj;
  563. exports.PresentationModeState = PresentationModeState;
  564. exports.RendererType = RendererType;
  565. exports.mozL10n = mozL10n;
  566. exports.NullL10n = NullL10n;
  567. exports.EventBus = EventBus;
  568. exports.ProgressBar = ProgressBar;
  569. exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
  570. exports.noContextMenuHandler = noContextMenuHandler;
  571. exports.parseQueryString = parseQueryString;
  572. exports.getVisibleElements = getVisibleElements;
  573. exports.roundToDivide = roundToDivide;
  574. exports.approximateFraction = approximateFraction;
  575. exports.getOutputScale = getOutputScale;
  576. exports.scrollIntoView = scrollIntoView;
  577. exports.watchScroll = watchScroll;
  578. exports.binarySearchFirstItem = binarySearchFirstItem;
  579. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  580. exports.animationStarted = animationStarted;
  581. exports.localized = localized;
  582. exports.WaitOnType = WaitOnType;
  583. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  584. /***/ }),
  585. /* 1 */
  586. /***/ (function(module, exports, __webpack_require__) {
  587. "use strict";
  588. var pdfjsLib;
  589. if (typeof window !== 'undefined' && window['pdfjs-dist/build/pdf']) {
  590. pdfjsLib = window['pdfjs-dist/build/pdf'];
  591. } else {
  592. pdfjsLib = require('../build/pdf.js');
  593. }
  594. module.exports = pdfjsLib;
  595. /***/ }),
  596. /* 2 */
  597. /***/ (function(module, exports, __webpack_require__) {
  598. "use strict";
  599. Object.defineProperty(exports, "__esModule", {
  600. value: true
  601. });
  602. exports.getGlobalEventBus = exports.attachDOMEventsToEventBus = undefined;
  603. var _ui_utils = __webpack_require__(0);
  604. function attachDOMEventsToEventBus(eventBus) {
  605. eventBus.on('documentload', function () {
  606. var event = document.createEvent('CustomEvent');
  607. event.initCustomEvent('documentload', true, true, {});
  608. window.dispatchEvent(event);
  609. });
  610. eventBus.on('pagerendered', function (evt) {
  611. var event = document.createEvent('CustomEvent');
  612. event.initCustomEvent('pagerendered', true, true, {
  613. pageNumber: evt.pageNumber,
  614. cssTransform: evt.cssTransform
  615. });
  616. evt.source.div.dispatchEvent(event);
  617. });
  618. eventBus.on('textlayerrendered', function (evt) {
  619. var event = document.createEvent('CustomEvent');
  620. event.initCustomEvent('textlayerrendered', true, true, { pageNumber: evt.pageNumber });
  621. evt.source.textLayerDiv.dispatchEvent(event);
  622. });
  623. eventBus.on('pagechange', function (evt) {
  624. var event = document.createEvent('UIEvents');
  625. event.initUIEvent('pagechange', true, true, window, 0);
  626. event.pageNumber = evt.pageNumber;
  627. evt.source.container.dispatchEvent(event);
  628. });
  629. eventBus.on('pagesinit', function (evt) {
  630. var event = document.createEvent('CustomEvent');
  631. event.initCustomEvent('pagesinit', true, true, null);
  632. evt.source.container.dispatchEvent(event);
  633. });
  634. eventBus.on('pagesloaded', function (evt) {
  635. var event = document.createEvent('CustomEvent');
  636. event.initCustomEvent('pagesloaded', true, true, { pagesCount: evt.pagesCount });
  637. evt.source.container.dispatchEvent(event);
  638. });
  639. eventBus.on('scalechange', function (evt) {
  640. var event = document.createEvent('UIEvents');
  641. event.initUIEvent('scalechange', true, true, window, 0);
  642. event.scale = evt.scale;
  643. event.presetValue = evt.presetValue;
  644. evt.source.container.dispatchEvent(event);
  645. });
  646. eventBus.on('updateviewarea', function (evt) {
  647. var event = document.createEvent('UIEvents');
  648. event.initUIEvent('updateviewarea', true, true, window, 0);
  649. event.location = evt.location;
  650. evt.source.container.dispatchEvent(event);
  651. });
  652. eventBus.on('find', function (evt) {
  653. if (evt.source === window) {
  654. return;
  655. }
  656. var event = document.createEvent('CustomEvent');
  657. event.initCustomEvent('find' + evt.type, true, true, {
  658. query: evt.query,
  659. phraseSearch: evt.phraseSearch,
  660. caseSensitive: evt.caseSensitive,
  661. highlightAll: evt.highlightAll,
  662. findPrevious: evt.findPrevious
  663. });
  664. window.dispatchEvent(event);
  665. });
  666. eventBus.on('attachmentsloaded', function (evt) {
  667. var event = document.createEvent('CustomEvent');
  668. event.initCustomEvent('attachmentsloaded', true, true, { attachmentsCount: evt.attachmentsCount });
  669. evt.source.container.dispatchEvent(event);
  670. });
  671. eventBus.on('sidebarviewchanged', function (evt) {
  672. var event = document.createEvent('CustomEvent');
  673. event.initCustomEvent('sidebarviewchanged', true, true, { view: evt.view });
  674. evt.source.outerContainer.dispatchEvent(event);
  675. });
  676. eventBus.on('pagemode', function (evt) {
  677. var event = document.createEvent('CustomEvent');
  678. event.initCustomEvent('pagemode', true, true, { mode: evt.mode });
  679. evt.source.pdfViewer.container.dispatchEvent(event);
  680. });
  681. eventBus.on('namedaction', function (evt) {
  682. var event = document.createEvent('CustomEvent');
  683. event.initCustomEvent('namedaction', true, true, { action: evt.action });
  684. evt.source.pdfViewer.container.dispatchEvent(event);
  685. });
  686. eventBus.on('presentationmodechanged', function (evt) {
  687. var event = document.createEvent('CustomEvent');
  688. event.initCustomEvent('presentationmodechanged', true, true, {
  689. active: evt.active,
  690. switchInProgress: evt.switchInProgress
  691. });
  692. window.dispatchEvent(event);
  693. });
  694. eventBus.on('outlineloaded', function (evt) {
  695. var event = document.createEvent('CustomEvent');
  696. event.initCustomEvent('outlineloaded', true, true, { outlineCount: evt.outlineCount });
  697. evt.source.container.dispatchEvent(event);
  698. });
  699. }
  700. var globalEventBus = null;
  701. function getGlobalEventBus() {
  702. if (globalEventBus) {
  703. return globalEventBus;
  704. }
  705. globalEventBus = new _ui_utils.EventBus();
  706. attachDOMEventsToEventBus(globalEventBus);
  707. return globalEventBus;
  708. }
  709. exports.attachDOMEventsToEventBus = attachDOMEventsToEventBus;
  710. exports.getGlobalEventBus = getGlobalEventBus;
  711. /***/ }),
  712. /* 3 */
  713. /***/ (function(module, exports, __webpack_require__) {
  714. "use strict";
  715. Object.defineProperty(exports, "__esModule", {
  716. value: true
  717. });
  718. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  719. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  720. var CLEANUP_TIMEOUT = 30000;
  721. var RenderingStates = {
  722. INITIAL: 0,
  723. RUNNING: 1,
  724. PAUSED: 2,
  725. FINISHED: 3
  726. };
  727. var PDFRenderingQueue = function () {
  728. function PDFRenderingQueue() {
  729. _classCallCheck(this, PDFRenderingQueue);
  730. this.pdfViewer = null;
  731. this.pdfThumbnailViewer = null;
  732. this.onIdle = null;
  733. this.highestPriorityPage = null;
  734. this.idleTimeout = null;
  735. this.printing = false;
  736. this.isThumbnailViewEnabled = false;
  737. }
  738. _createClass(PDFRenderingQueue, [{
  739. key: "setViewer",
  740. value: function setViewer(pdfViewer) {
  741. this.pdfViewer = pdfViewer;
  742. }
  743. }, {
  744. key: "setThumbnailViewer",
  745. value: function setThumbnailViewer(pdfThumbnailViewer) {
  746. this.pdfThumbnailViewer = pdfThumbnailViewer;
  747. }
  748. }, {
  749. key: "isHighestPriority",
  750. value: function isHighestPriority(view) {
  751. return this.highestPriorityPage === view.renderingId;
  752. }
  753. }, {
  754. key: "renderHighestPriority",
  755. value: function renderHighestPriority(currentlyVisiblePages) {
  756. if (this.idleTimeout) {
  757. clearTimeout(this.idleTimeout);
  758. this.idleTimeout = null;
  759. }
  760. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  761. return;
  762. }
  763. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  764. if (this.pdfThumbnailViewer.forceRendering()) {
  765. return;
  766. }
  767. }
  768. if (this.printing) {
  769. return;
  770. }
  771. if (this.onIdle) {
  772. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  773. }
  774. }
  775. }, {
  776. key: "getHighestPriority",
  777. value: function getHighestPriority(visible, views, scrolledDown) {
  778. var visibleViews = visible.views;
  779. var numVisible = visibleViews.length;
  780. if (numVisible === 0) {
  781. return false;
  782. }
  783. for (var i = 0; i < numVisible; ++i) {
  784. var view = visibleViews[i].view;
  785. if (!this.isViewFinished(view)) {
  786. return view;
  787. }
  788. }
  789. if (scrolledDown) {
  790. var nextPageIndex = visible.last.id;
  791. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  792. return views[nextPageIndex];
  793. }
  794. } else {
  795. var previousPageIndex = visible.first.id - 2;
  796. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  797. return views[previousPageIndex];
  798. }
  799. }
  800. return null;
  801. }
  802. }, {
  803. key: "isViewFinished",
  804. value: function isViewFinished(view) {
  805. return view.renderingState === RenderingStates.FINISHED;
  806. }
  807. }, {
  808. key: "renderView",
  809. value: function renderView(view) {
  810. var _this = this;
  811. switch (view.renderingState) {
  812. case RenderingStates.FINISHED:
  813. return false;
  814. case RenderingStates.PAUSED:
  815. this.highestPriorityPage = view.renderingId;
  816. view.resume();
  817. break;
  818. case RenderingStates.RUNNING:
  819. this.highestPriorityPage = view.renderingId;
  820. break;
  821. case RenderingStates.INITIAL:
  822. this.highestPriorityPage = view.renderingId;
  823. var continueRendering = function continueRendering() {
  824. _this.renderHighestPriority();
  825. };
  826. view.draw().then(continueRendering, continueRendering);
  827. break;
  828. }
  829. return true;
  830. }
  831. }]);
  832. return PDFRenderingQueue;
  833. }();
  834. exports.RenderingStates = RenderingStates;
  835. exports.PDFRenderingQueue = PDFRenderingQueue;
  836. /***/ }),
  837. /* 4 */
  838. /***/ (function(module, exports, __webpack_require__) {
  839. "use strict";
  840. Object.defineProperty(exports, "__esModule", {
  841. value: true
  842. });
  843. exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = undefined;
  844. var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
  845. var _ui_utils = __webpack_require__(0);
  846. var _pdfjsLib = __webpack_require__(1);
  847. var _pdf_cursor_tools = __webpack_require__(6);
  848. var _pdf_rendering_queue = __webpack_require__(3);
  849. var _pdf_sidebar = __webpack_require__(10);
  850. var _dom_events = __webpack_require__(2);
  851. var _overlay_manager = __webpack_require__(11);
  852. var _password_prompt = __webpack_require__(12);
  853. var _pdf_attachment_viewer = __webpack_require__(13);
  854. var _pdf_document_properties = __webpack_require__(14);
  855. var _pdf_find_bar = __webpack_require__(15);
  856. var _pdf_find_controller = __webpack_require__(7);
  857. var _pdf_history = __webpack_require__(16);
  858. var _pdf_link_service = __webpack_require__(5);
  859. var _pdf_outline_viewer = __webpack_require__(17);
  860. var _pdf_presentation_mode = __webpack_require__(18);
  861. var _pdf_thumbnail_viewer = __webpack_require__(19);
  862. var _pdf_viewer = __webpack_require__(21);
  863. var _secondary_toolbar = __webpack_require__(26);
  864. var _toolbar = __webpack_require__(27);
  865. var _view_history = __webpack_require__(28);
  866. var DEFAULT_SCALE_DELTA = 1.1;
  867. var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  868. function configure(PDFJS) {
  869. PDFJS.imageResourcesPath = './images/';
  870. PDFJS.workerSrc = '../build/pdf.worker.js';
  871. PDFJS.cMapUrl = '../web/cmaps/';
  872. PDFJS.cMapPacked = true;
  873. }
  874. var DefaultExternalServices = {
  875. updateFindControlState: function updateFindControlState(data) {},
  876. initPassiveLoading: function initPassiveLoading(callbacks) {},
  877. fallback: function fallback(data, callback) {},
  878. reportTelemetry: function reportTelemetry(data) {},
  879. createDownloadManager: function createDownloadManager() {
  880. throw new Error('Not implemented: createDownloadManager');
  881. },
  882. createPreferences: function createPreferences() {
  883. throw new Error('Not implemented: createPreferences');
  884. },
  885. createL10n: function createL10n() {
  886. throw new Error('Not implemented: createL10n');
  887. },
  888. supportsIntegratedFind: false,
  889. supportsDocumentFonts: true,
  890. supportsDocumentColors: true,
  891. supportedMouseWheelZoomModifierKeys: {
  892. ctrlKey: true,
  893. metaKey: true
  894. }
  895. };
  896. var PDFViewerApplication = {
  897. initialBookmark: document.location.hash.substring(1),
  898. initialized: false,
  899. fellback: false,
  900. appConfig: null,
  901. pdfDocument: null,
  902. pdfLoadingTask: null,
  903. printService: null,
  904. pdfViewer: null,
  905. pdfThumbnailViewer: null,
  906. pdfRenderingQueue: null,
  907. pdfPresentationMode: null,
  908. pdfDocumentProperties: null,
  909. pdfLinkService: null,
  910. pdfHistory: null,
  911. pdfSidebar: null,
  912. pdfOutlineViewer: null,
  913. pdfAttachmentViewer: null,
  914. pdfCursorTools: null,
  915. store: null,
  916. downloadManager: null,
  917. overlayManager: null,
  918. preferences: null,
  919. toolbar: null,
  920. secondaryToolbar: null,
  921. eventBus: null,
  922. l10n: null,
  923. isInitialViewSet: false,
  924. downloadComplete: false,
  925. viewerPrefs: {
  926. sidebarViewOnLoad: _pdf_sidebar.SidebarView.NONE,
  927. pdfBugEnabled: false,
  928. showPreviousViewOnLoad: true,
  929. defaultZoomValue: '',
  930. disablePageMode: false,
  931. disablePageLabels: false,
  932. renderer: 'canvas',
  933. enhanceTextSelection: false,
  934. renderInteractiveForms: false,
  935. enablePrintAutoRotate: false
  936. },
  937. isViewerEmbedded: window.parent !== window,
  938. url: '',
  939. baseUrl: '',
  940. externalServices: DefaultExternalServices,
  941. _boundEvents: {},
  942. initialize: function initialize(appConfig) {
  943. var _this = this;
  944. this.preferences = this.externalServices.createPreferences();
  945. configure(_pdfjsLib.PDFJS);
  946. this.appConfig = appConfig;
  947. return this._readPreferences().then(function () {
  948. return _this._initializeL10n();
  949. }).then(function () {
  950. return _this._initializeViewerComponents();
  951. }).then(function () {
  952. _this.bindEvents();
  953. _this.bindWindowEvents();
  954. var appContainer = appConfig.appContainer || document.documentElement;
  955. _this.l10n.translate(appContainer).then(function () {
  956. _this.eventBus.dispatch('localized');
  957. });
  958. if (_this.isViewerEmbedded && !_pdfjsLib.PDFJS.isExternalLinkTargetSet()) {
  959. _pdfjsLib.PDFJS.externalLinkTarget = _pdfjsLib.PDFJS.LinkTarget.TOP;
  960. }
  961. _this.initialized = true;
  962. });
  963. },
  964. _readPreferences: function _readPreferences() {
  965. var preferences = this.preferences,
  966. viewerPrefs = this.viewerPrefs;
  967. return Promise.all([preferences.get('enableWebGL').then(function resolved(value) {
  968. _pdfjsLib.PDFJS.disableWebGL = !value;
  969. }), preferences.get('sidebarViewOnLoad').then(function resolved(value) {
  970. viewerPrefs['sidebarViewOnLoad'] = value;
  971. }), preferences.get('pdfBugEnabled').then(function resolved(value) {
  972. viewerPrefs['pdfBugEnabled'] = value;
  973. }), preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
  974. viewerPrefs['showPreviousViewOnLoad'] = value;
  975. }), preferences.get('defaultZoomValue').then(function resolved(value) {
  976. viewerPrefs['defaultZoomValue'] = value;
  977. }), preferences.get('enhanceTextSelection').then(function resolved(value) {
  978. viewerPrefs['enhanceTextSelection'] = value;
  979. }), preferences.get('disableTextLayer').then(function resolved(value) {
  980. if (_pdfjsLib.PDFJS.disableTextLayer === true) {
  981. return;
  982. }
  983. _pdfjsLib.PDFJS.disableTextLayer = value;
  984. }), preferences.get('disableRange').then(function resolved(value) {
  985. if (_pdfjsLib.PDFJS.disableRange === true) {
  986. return;
  987. }
  988. _pdfjsLib.PDFJS.disableRange = value;
  989. }), preferences.get('disableStream').then(function resolved(value) {
  990. if (_pdfjsLib.PDFJS.disableStream === true) {
  991. return;
  992. }
  993. _pdfjsLib.PDFJS.disableStream = value;
  994. }), preferences.get('disableAutoFetch').then(function resolved(value) {
  995. _pdfjsLib.PDFJS.disableAutoFetch = value;
  996. }), preferences.get('disableFontFace').then(function resolved(value) {
  997. if (_pdfjsLib.PDFJS.disableFontFace === true) {
  998. return;
  999. }
  1000. _pdfjsLib.PDFJS.disableFontFace = value;
  1001. }), preferences.get('useOnlyCssZoom').then(function resolved(value) {
  1002. _pdfjsLib.PDFJS.useOnlyCssZoom = value;
  1003. }), preferences.get('externalLinkTarget').then(function resolved(value) {
  1004. if (_pdfjsLib.PDFJS.isExternalLinkTargetSet()) {
  1005. return;
  1006. }
  1007. _pdfjsLib.PDFJS.externalLinkTarget = value;
  1008. }), preferences.get('renderer').then(function resolved(value) {
  1009. viewerPrefs['renderer'] = value;
  1010. }), preferences.get('renderInteractiveForms').then(function resolved(value) {
  1011. viewerPrefs['renderInteractiveForms'] = value;
  1012. }), preferences.get('disablePageMode').then(function resolved(value) {
  1013. viewerPrefs['disablePageMode'] = value;
  1014. }), preferences.get('disablePageLabels').then(function resolved(value) {
  1015. viewerPrefs['disablePageLabels'] = value;
  1016. }), preferences.get('enablePrintAutoRotate').then(function resolved(value) {
  1017. viewerPrefs['enablePrintAutoRotate'] = value;
  1018. })]).catch(function (reason) {});
  1019. },
  1020. _initializeL10n: function _initializeL10n() {
  1021. if (this.viewerPrefs['pdfBugEnabled']) {
  1022. var hash = document.location.hash.substring(1);
  1023. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  1024. if ('locale' in hashParams) {
  1025. _pdfjsLib.PDFJS.locale = hashParams['locale'];
  1026. }
  1027. }
  1028. this.l10n = this.externalServices.createL10n();
  1029. return this.l10n.getDirection().then(function (dir) {
  1030. document.getElementsByTagName('html')[0].dir = dir;
  1031. });
  1032. },
  1033. _initializeViewerComponents: function _initializeViewerComponents() {
  1034. var _this2 = this;
  1035. var appConfig = this.appConfig;
  1036. return new Promise(function (resolve, reject) {
  1037. _this2.overlayManager = new _overlay_manager.OverlayManager();
  1038. var eventBus = appConfig.eventBus || (0, _dom_events.getGlobalEventBus)();
  1039. _this2.eventBus = eventBus;
  1040. var pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  1041. pdfRenderingQueue.onIdle = _this2.cleanup.bind(_this2);
  1042. _this2.pdfRenderingQueue = pdfRenderingQueue;
  1043. var pdfLinkService = new _pdf_link_service.PDFLinkService({ eventBus: eventBus });
  1044. _this2.pdfLinkService = pdfLinkService;
  1045. var downloadManager = _this2.externalServices.createDownloadManager();
  1046. _this2.downloadManager = downloadManager;
  1047. var container = appConfig.mainContainer;
  1048. var viewer = appConfig.viewerContainer;
  1049. _this2.pdfViewer = new _pdf_viewer.PDFViewer({
  1050. container: container,
  1051. viewer: viewer,
  1052. eventBus: eventBus,
  1053. renderingQueue: pdfRenderingQueue,
  1054. linkService: pdfLinkService,
  1055. downloadManager: downloadManager,
  1056. renderer: _this2.viewerPrefs['renderer'],
  1057. l10n: _this2.l10n,
  1058. enhanceTextSelection: _this2.viewerPrefs['enhanceTextSelection'],
  1059. renderInteractiveForms: _this2.viewerPrefs['renderInteractiveForms'],
  1060. enablePrintAutoRotate: _this2.viewerPrefs['enablePrintAutoRotate']
  1061. });
  1062. pdfRenderingQueue.setViewer(_this2.pdfViewer);
  1063. pdfLinkService.setViewer(_this2.pdfViewer);
  1064. var thumbnailContainer = appConfig.sidebar.thumbnailView;
  1065. _this2.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  1066. container: thumbnailContainer,
  1067. renderingQueue: pdfRenderingQueue,
  1068. linkService: pdfLinkService,
  1069. l10n: _this2.l10n
  1070. });
  1071. pdfRenderingQueue.setThumbnailViewer(_this2.pdfThumbnailViewer);
  1072. _this2.pdfHistory = new _pdf_history.PDFHistory({
  1073. linkService: pdfLinkService,
  1074. eventBus: eventBus
  1075. });
  1076. pdfLinkService.setHistory(_this2.pdfHistory);
  1077. _this2.findController = new _pdf_find_controller.PDFFindController({ pdfViewer: _this2.pdfViewer });
  1078. _this2.findController.onUpdateResultsCount = function (matchCount) {
  1079. if (_this2.supportsIntegratedFind) {
  1080. return;
  1081. }
  1082. _this2.findBar.updateResultsCount(matchCount);
  1083. };
  1084. _this2.findController.onUpdateState = function (state, previous, matchCount) {
  1085. if (_this2.supportsIntegratedFind) {
  1086. _this2.externalServices.updateFindControlState({
  1087. result: state,
  1088. findPrevious: previous
  1089. });
  1090. } else {
  1091. _this2.findBar.updateUIState(state, previous, matchCount);
  1092. }
  1093. };
  1094. _this2.pdfViewer.setFindController(_this2.findController);
  1095. var findBarConfig = Object.create(appConfig.findBar);
  1096. findBarConfig.findController = _this2.findController;
  1097. findBarConfig.eventBus = eventBus;
  1098. _this2.findBar = new _pdf_find_bar.PDFFindBar(findBarConfig, _this2.l10n);
  1099. _this2.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, _this2.overlayManager, _this2.l10n);
  1100. _this2.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  1101. container: container,
  1102. eventBus: eventBus,
  1103. preferences: _this2.preferences
  1104. });
  1105. _this2.toolbar = new _toolbar.Toolbar(appConfig.toolbar, container, eventBus, _this2.l10n);
  1106. _this2.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  1107. if (_this2.supportsFullscreen) {
  1108. _this2.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  1109. container: container,
  1110. viewer: viewer,
  1111. pdfViewer: _this2.pdfViewer,
  1112. eventBus: eventBus,
  1113. contextMenuItems: appConfig.fullscreen
  1114. });
  1115. }
  1116. _this2.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, _this2.overlayManager, _this2.l10n);
  1117. _this2.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  1118. container: appConfig.sidebar.outlineView,
  1119. eventBus: eventBus,
  1120. linkService: pdfLinkService
  1121. });
  1122. _this2.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  1123. container: appConfig.sidebar.attachmentsView,
  1124. eventBus: eventBus,
  1125. downloadManager: downloadManager
  1126. });
  1127. var sidebarConfig = Object.create(appConfig.sidebar);
  1128. sidebarConfig.pdfViewer = _this2.pdfViewer;
  1129. sidebarConfig.pdfThumbnailViewer = _this2.pdfThumbnailViewer;
  1130. sidebarConfig.pdfOutlineViewer = _this2.pdfOutlineViewer;
  1131. sidebarConfig.eventBus = eventBus;
  1132. _this2.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig, _this2.l10n);
  1133. _this2.pdfSidebar.onToggled = _this2.forceRendering.bind(_this2);
  1134. resolve(undefined);
  1135. });
  1136. },
  1137. run: function run(config) {
  1138. this.initialize(config).then(webViewerInitialized);
  1139. },
  1140. zoomIn: function zoomIn(ticks) {
  1141. var newScale = this.pdfViewer.currentScale;
  1142. do {
  1143. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  1144. newScale = Math.ceil(newScale * 10) / 10;
  1145. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  1146. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  1147. this.pdfViewer.currentScaleValue = newScale;
  1148. },
  1149. zoomOut: function zoomOut(ticks) {
  1150. var newScale = this.pdfViewer.currentScale;
  1151. do {
  1152. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  1153. newScale = Math.floor(newScale * 10) / 10;
  1154. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  1155. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  1156. this.pdfViewer.currentScaleValue = newScale;
  1157. },
  1158. get pagesCount() {
  1159. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  1160. },
  1161. get pageRotation() {
  1162. return this.pdfViewer.pagesRotation;
  1163. },
  1164. set page(val) {
  1165. this.pdfViewer.currentPageNumber = val;
  1166. },
  1167. get page() {
  1168. return this.pdfViewer.currentPageNumber;
  1169. },
  1170. get printing() {
  1171. return !!this.printService;
  1172. },
  1173. get supportsPrinting() {
  1174. return PDFPrintServiceFactory.instance.supportsPrinting;
  1175. },
  1176. get supportsFullscreen() {
  1177. var support = void 0;
  1178. var doc = document.documentElement;
  1179. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  1180. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  1181. support = false;
  1182. }
  1183. if (support && _pdfjsLib.PDFJS.disableFullscreen === true) {
  1184. support = false;
  1185. }
  1186. return (0, _pdfjsLib.shadow)(this, 'supportsFullscreen', support);
  1187. },
  1188. get supportsIntegratedFind() {
  1189. return this.externalServices.supportsIntegratedFind;
  1190. },
  1191. get supportsDocumentFonts() {
  1192. return this.externalServices.supportsDocumentFonts;
  1193. },
  1194. get supportsDocumentColors() {
  1195. return this.externalServices.supportsDocumentColors;
  1196. },
  1197. get loadingBar() {
  1198. var bar = new _ui_utils.ProgressBar('#loadingBar');
  1199. return (0, _pdfjsLib.shadow)(this, 'loadingBar', bar);
  1200. },
  1201. get supportedMouseWheelZoomModifierKeys() {
  1202. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  1203. },
  1204. initPassiveLoading: function initPassiveLoading() {
  1205. throw new Error('Not implemented: initPassiveLoading');
  1206. },
  1207. setTitleUsingUrl: function setTitleUsingUrl(url) {
  1208. this.url = url;
  1209. this.baseUrl = url.split('#')[0];
  1210. var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
  1211. if (!title) {
  1212. try {
  1213. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  1214. } catch (ex) {
  1215. title = url;
  1216. }
  1217. }
  1218. this.setTitle(title);
  1219. },
  1220. setTitle: function setTitle(title) {
  1221. if (this.isViewerEmbedded) {
  1222. return;
  1223. }
  1224. document.title = title;
  1225. },
  1226. close: function close() {
  1227. var errorWrapper = this.appConfig.errorWrapper.container;
  1228. errorWrapper.setAttribute('hidden', 'true');
  1229. if (!this.pdfLoadingTask) {
  1230. return Promise.resolve();
  1231. }
  1232. var promise = this.pdfLoadingTask.destroy();
  1233. this.pdfLoadingTask = null;
  1234. if (this.pdfDocument) {
  1235. this.pdfDocument = null;
  1236. this.pdfThumbnailViewer.setDocument(null);
  1237. this.pdfViewer.setDocument(null);
  1238. this.pdfLinkService.setDocument(null, null);
  1239. this.pdfDocumentProperties.setDocument(null, null);
  1240. }
  1241. this.store = null;
  1242. this.isInitialViewSet = false;
  1243. this.downloadComplete = false;
  1244. this.pdfSidebar.reset();
  1245. this.pdfOutlineViewer.reset();
  1246. this.pdfAttachmentViewer.reset();
  1247. this.findController.reset();
  1248. this.findBar.reset();
  1249. this.toolbar.reset();
  1250. this.secondaryToolbar.reset();
  1251. if (typeof PDFBug !== 'undefined') {
  1252. PDFBug.cleanup();
  1253. }
  1254. return promise;
  1255. },
  1256. open: function open(file, args) {
  1257. var _this3 = this;
  1258. if (arguments.length > 2 || typeof args === 'number') {
  1259. return Promise.reject(new Error('Call of open() with obsolete signature.'));
  1260. }
  1261. if (this.pdfLoadingTask) {
  1262. return this.close().then(function () {
  1263. _this3.preferences.reload();
  1264. return _this3.open(file, args);
  1265. });
  1266. }
  1267. var parameters = Object.create(null);
  1268. if (typeof file === 'string') {
  1269. this.setTitleUsingUrl(file);
  1270. parameters.url = file;
  1271. } else if (file && 'byteLength' in file) {
  1272. parameters.data = file;
  1273. } else if (file.url && file.originalUrl) {
  1274. this.setTitleUsingUrl(file.originalUrl);
  1275. parameters.url = file.url;
  1276. }
  1277. if (args) {
  1278. for (var prop in args) {
  1279. if (!_pdfjsLib.PDFJS.pdfjsNext && prop === 'scale') {
  1280. console.error('Call of open() with obsolete "scale" argument, ' + 'please use the "defaultZoomValue" preference instead.');
  1281. continue;
  1282. } else if (prop === 'length') {
  1283. this.pdfDocumentProperties.setFileSize(args[prop]);
  1284. }
  1285. parameters[prop] = args[prop];
  1286. }
  1287. }
  1288. var loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  1289. this.pdfLoadingTask = loadingTask;
  1290. loadingTask.onPassword = function (updateCallback, reason) {
  1291. _this3.passwordPrompt.setUpdateCallback(updateCallback, reason);
  1292. _this3.passwordPrompt.open();
  1293. };
  1294. loadingTask.onProgress = function (_ref) {
  1295. var loaded = _ref.loaded,
  1296. total = _ref.total;
  1297. _this3.progress(loaded / total);
  1298. };
  1299. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  1300. return loadingTask.promise.then(function (pdfDocument) {
  1301. _this3.load(pdfDocument);
  1302. }, function (exception) {
  1303. var message = exception && exception.message;
  1304. var loadingErrorMessage = void 0;
  1305. if (exception instanceof _pdfjsLib.InvalidPDFException) {
  1306. loadingErrorMessage = _this3.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
  1307. } else if (exception instanceof _pdfjsLib.MissingPDFException) {
  1308. loadingErrorMessage = _this3.l10n.get('missing_file_error', null, 'Missing PDF file.');
  1309. } else if (exception instanceof _pdfjsLib.UnexpectedResponseException) {
  1310. loadingErrorMessage = _this3.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
  1311. } else {
  1312. loadingErrorMessage = _this3.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  1313. }
  1314. return loadingErrorMessage.then(function (msg) {
  1315. _this3.error(msg, { message: message });
  1316. throw new Error(msg);
  1317. });
  1318. });
  1319. },
  1320. download: function download() {
  1321. var _this4 = this;
  1322. function downloadByUrl() {
  1323. downloadManager.downloadUrl(url, filename);
  1324. }
  1325. var url = this.baseUrl;
  1326. var filename = (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  1327. var downloadManager = this.downloadManager;
  1328. downloadManager.onerror = function (err) {
  1329. _this4.error('PDF failed to download: ' + err);
  1330. };
  1331. if (!this.pdfDocument || !this.downloadComplete) {
  1332. downloadByUrl();
  1333. return;
  1334. }
  1335. this.pdfDocument.getData().then(function (data) {
  1336. var blob = (0, _pdfjsLib.createBlob)(data, 'application/pdf');
  1337. downloadManager.download(blob, url, filename);
  1338. }).catch(downloadByUrl);
  1339. },
  1340. fallback: function fallback(featureId) {},
  1341. error: function error(message, moreInfo) {
  1342. var moreInfoText = [this.l10n.get('error_version_info', {
  1343. version: _pdfjsLib.version || '?',
  1344. build: _pdfjsLib.build || '?'
  1345. }, 'PDF.js v{{version}} (build: {{build}})')];
  1346. if (moreInfo) {
  1347. moreInfoText.push(this.l10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}'));
  1348. if (moreInfo.stack) {
  1349. moreInfoText.push(this.l10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}'));
  1350. } else {
  1351. if (moreInfo.filename) {
  1352. moreInfoText.push(this.l10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}'));
  1353. }
  1354. if (moreInfo.lineNumber) {
  1355. moreInfoText.push(this.l10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}'));
  1356. }
  1357. }
  1358. }
  1359. var errorWrapperConfig = this.appConfig.errorWrapper;
  1360. var errorWrapper = errorWrapperConfig.container;
  1361. errorWrapper.removeAttribute('hidden');
  1362. var errorMessage = errorWrapperConfig.errorMessage;
  1363. errorMessage.textContent = message;
  1364. var closeButton = errorWrapperConfig.closeButton;
  1365. closeButton.onclick = function () {
  1366. errorWrapper.setAttribute('hidden', 'true');
  1367. };
  1368. var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1369. var moreInfoButton = errorWrapperConfig.moreInfoButton;
  1370. var lessInfoButton = errorWrapperConfig.lessInfoButton;
  1371. moreInfoButton.onclick = function () {
  1372. errorMoreInfo.removeAttribute('hidden');
  1373. moreInfoButton.setAttribute('hidden', 'true');
  1374. lessInfoButton.removeAttribute('hidden');
  1375. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
  1376. };
  1377. lessInfoButton.onclick = function () {
  1378. errorMoreInfo.setAttribute('hidden', 'true');
  1379. moreInfoButton.removeAttribute('hidden');
  1380. lessInfoButton.setAttribute('hidden', 'true');
  1381. };
  1382. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1383. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1384. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1385. moreInfoButton.removeAttribute('hidden');
  1386. lessInfoButton.setAttribute('hidden', 'true');
  1387. Promise.all(moreInfoText).then(function (parts) {
  1388. errorMoreInfo.value = parts.join('\n');
  1389. });
  1390. },
  1391. progress: function progress(level) {
  1392. var _this5 = this;
  1393. if (this.downloadComplete) {
  1394. return;
  1395. }
  1396. var percent = Math.round(level * 100);
  1397. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1398. this.loadingBar.percent = percent;
  1399. if (_pdfjsLib.PDFJS.disableAutoFetch && percent) {
  1400. if (this.disableAutoFetchLoadingBarTimeout) {
  1401. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1402. this.disableAutoFetchLoadingBarTimeout = null;
  1403. }
  1404. this.loadingBar.show();
  1405. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  1406. _this5.loadingBar.hide();
  1407. _this5.disableAutoFetchLoadingBarTimeout = null;
  1408. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1409. }
  1410. }
  1411. },
  1412. load: function load(pdfDocument) {
  1413. var _this6 = this;
  1414. this.pdfDocument = pdfDocument;
  1415. pdfDocument.getDownloadInfo().then(function () {
  1416. _this6.downloadComplete = true;
  1417. _this6.loadingBar.hide();
  1418. firstPagePromise.then(function () {
  1419. _this6.eventBus.dispatch('documentload', { source: _this6 });
  1420. });
  1421. });
  1422. var pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1423. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1424. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1425. var id = this.documentFingerprint = pdfDocument.fingerprint;
  1426. var store = this.store = new _view_history.ViewHistory(id);
  1427. var baseDocumentUrl = void 0;
  1428. baseDocumentUrl = null;
  1429. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1430. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1431. var pdfViewer = this.pdfViewer;
  1432. pdfViewer.setDocument(pdfDocument);
  1433. var firstPagePromise = pdfViewer.firstPagePromise;
  1434. var pagesPromise = pdfViewer.pagesPromise;
  1435. var onePageRendered = pdfViewer.onePageRendered;
  1436. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  1437. pdfThumbnailViewer.setDocument(pdfDocument);
  1438. firstPagePromise.then(function (pdfPage) {
  1439. _this6.loadingBar.setWidth(_this6.appConfig.viewerContainer);
  1440. if (!_pdfjsLib.PDFJS.disableHistory && !_this6.isViewerEmbedded) {
  1441. var resetHistory = !_this6.viewerPrefs['showPreviousViewOnLoad'];
  1442. _this6.pdfHistory.initialize(id, resetHistory);
  1443. if (_this6.pdfHistory.initialBookmark) {
  1444. _this6.initialBookmark = _this6.pdfHistory.initialBookmark;
  1445. _this6.initialRotation = _this6.pdfHistory.initialRotation;
  1446. }
  1447. }
  1448. var initialParams = {
  1449. bookmark: null,
  1450. hash: null
  1451. };
  1452. var storePromise = store.getMultiple({
  1453. exists: false,
  1454. page: '1',
  1455. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1456. scrollLeft: '0',
  1457. scrollTop: '0',
  1458. rotation: null,
  1459. sidebarView: _pdf_sidebar.SidebarView.NONE
  1460. }).catch(function () {});
  1461. Promise.all([storePromise, pageModePromise]).then(function (_ref2) {
  1462. var _ref3 = _slicedToArray(_ref2, 2),
  1463. _ref3$ = _ref3[0],
  1464. values = _ref3$ === undefined ? {} : _ref3$,
  1465. pageMode = _ref3[1];
  1466. var hash = _this6.viewerPrefs['defaultZoomValue'] ? 'zoom=' + _this6.viewerPrefs['defaultZoomValue'] : null;
  1467. var rotation = null;
  1468. var sidebarView = _this6.viewerPrefs['sidebarViewOnLoad'];
  1469. if (values.exists && _this6.viewerPrefs['showPreviousViewOnLoad']) {
  1470. hash = 'page=' + values.page + '&zoom=' + (_this6.viewerPrefs['defaultZoomValue'] || values.zoom) + ',' + values.scrollLeft + ',' + values.scrollTop;
  1471. rotation = parseInt(values.rotation, 10);
  1472. sidebarView = sidebarView || values.sidebarView | 0;
  1473. }
  1474. if (pageMode && !_this6.viewerPrefs['disablePageMode']) {
  1475. sidebarView = sidebarView || apiPageModeToSidebarView(pageMode);
  1476. }
  1477. return {
  1478. hash: hash,
  1479. rotation: rotation,
  1480. sidebarView: sidebarView
  1481. };
  1482. }).then(function (_ref4) {
  1483. var hash = _ref4.hash,
  1484. rotation = _ref4.rotation,
  1485. sidebarView = _ref4.sidebarView;
  1486. initialParams.bookmark = _this6.initialBookmark;
  1487. initialParams.hash = hash;
  1488. _this6.setInitialView(hash, {
  1489. rotation: rotation,
  1490. sidebarView: sidebarView
  1491. });
  1492. if (!_this6.isViewerEmbedded) {
  1493. pdfViewer.focus();
  1494. }
  1495. return pagesPromise;
  1496. }).then(function () {
  1497. if (!initialParams.bookmark && !initialParams.hash) {
  1498. return;
  1499. }
  1500. if (pdfViewer.hasEqualPageSizes) {
  1501. return;
  1502. }
  1503. _this6.initialBookmark = initialParams.bookmark;
  1504. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1505. _this6.setInitialView(initialParams.hash);
  1506. }).then(function () {
  1507. pdfViewer.update();
  1508. });
  1509. });
  1510. pdfDocument.getPageLabels().then(function (labels) {
  1511. if (!labels || _this6.viewerPrefs['disablePageLabels']) {
  1512. return;
  1513. }
  1514. var i = 0,
  1515. numLabels = labels.length;
  1516. if (numLabels !== _this6.pagesCount) {
  1517. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  1518. return;
  1519. }
  1520. while (i < numLabels && labels[i] === (i + 1).toString()) {
  1521. i++;
  1522. }
  1523. if (i === numLabels) {
  1524. return;
  1525. }
  1526. pdfViewer.setPageLabels(labels);
  1527. pdfThumbnailViewer.setPageLabels(labels);
  1528. _this6.toolbar.setPagesCount(pdfDocument.numPages, true);
  1529. _this6.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1530. });
  1531. pagesPromise.then(function () {
  1532. if (!_this6.supportsPrinting) {
  1533. return;
  1534. }
  1535. pdfDocument.getJavaScript().then(function (javaScript) {
  1536. if (javaScript.length === 0) {
  1537. return;
  1538. }
  1539. javaScript.some(function (js) {
  1540. if (!js) {
  1541. return false;
  1542. }
  1543. console.warn('Warning: JavaScript is not supported');
  1544. _this6.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1545. return true;
  1546. });
  1547. var regex = /\bprint\s*\(/;
  1548. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  1549. var js = javaScript[i];
  1550. if (js && regex.test(js)) {
  1551. setTimeout(function () {
  1552. window.print();
  1553. });
  1554. return;
  1555. }
  1556. }
  1557. });
  1558. });
  1559. Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
  1560. pdfDocument.getOutline().then(function (outline) {
  1561. _this6.pdfOutlineViewer.render({ outline: outline });
  1562. });
  1563. pdfDocument.getAttachments().then(function (attachments) {
  1564. _this6.pdfAttachmentViewer.render({ attachments: attachments });
  1565. });
  1566. });
  1567. pdfDocument.getMetadata().then(function (_ref5) {
  1568. var info = _ref5.info,
  1569. metadata = _ref5.metadata;
  1570. _this6.documentInfo = info;
  1571. _this6.metadata = metadata;
  1572. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdfjsLib.version || '-') + (!_pdfjsLib.PDFJS.disableWebGL ? ' [WebGL]' : '') + ')');
  1573. var pdfTitle = void 0;
  1574. if (metadata && metadata.has('dc:title')) {
  1575. var title = metadata.get('dc:title');
  1576. if (title !== 'Untitled') {
  1577. pdfTitle = title;
  1578. }
  1579. }
  1580. if (!pdfTitle && info && info['Title']) {
  1581. pdfTitle = info['Title'];
  1582. }
  1583. if (pdfTitle) {
  1584. _this6.setTitle(pdfTitle + ' - ' + document.title);
  1585. }
  1586. if (info.IsAcroFormPresent) {
  1587. console.warn('Warning: AcroForm/XFA is not supported');
  1588. _this6.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1589. }
  1590. });
  1591. },
  1592. setInitialView: function setInitialView(storedHash) {
  1593. var _this7 = this;
  1594. var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  1595. rotation = _ref6.rotation,
  1596. sidebarView = _ref6.sidebarView;
  1597. var setRotation = function setRotation(angle) {
  1598. if ((0, _ui_utils.isValidRotation)(angle)) {
  1599. _this7.pdfViewer.pagesRotation = angle;
  1600. }
  1601. };
  1602. this.isInitialViewSet = true;
  1603. this.pdfSidebar.setInitialView(sidebarView);
  1604. if (this.initialBookmark) {
  1605. setRotation(this.initialRotation);
  1606. delete this.initialRotation;
  1607. this.pdfLinkService.setHash(this.initialBookmark);
  1608. this.initialBookmark = null;
  1609. } else if (storedHash) {
  1610. setRotation(rotation);
  1611. this.pdfLinkService.setHash(storedHash);
  1612. }
  1613. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1614. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1615. if (!this.pdfViewer.currentScaleValue) {
  1616. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1617. }
  1618. },
  1619. cleanup: function cleanup() {
  1620. if (!this.pdfDocument) {
  1621. return;
  1622. }
  1623. this.pdfViewer.cleanup();
  1624. this.pdfThumbnailViewer.cleanup();
  1625. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  1626. this.pdfDocument.cleanup();
  1627. }
  1628. },
  1629. forceRendering: function forceRendering() {
  1630. this.pdfRenderingQueue.printing = this.printing;
  1631. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1632. this.pdfRenderingQueue.renderHighestPriority();
  1633. },
  1634. beforePrint: function beforePrint() {
  1635. var _this8 = this;
  1636. if (this.printService) {
  1637. return;
  1638. }
  1639. if (!this.supportsPrinting) {
  1640. this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
  1641. _this8.error(printMessage);
  1642. });
  1643. return;
  1644. }
  1645. if (!this.pdfViewer.pageViewsReady) {
  1646. this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
  1647. window.alert(notReadyMessage);
  1648. });
  1649. return;
  1650. }
  1651. var pagesOverview = this.pdfViewer.getPagesOverview();
  1652. var printContainer = this.appConfig.printContainer;
  1653. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
  1654. this.printService = printService;
  1655. this.forceRendering();
  1656. printService.layout();
  1657. },
  1658. afterPrint: function pdfViewSetupAfterPrint() {
  1659. if (this.printService) {
  1660. this.printService.destroy();
  1661. this.printService = null;
  1662. }
  1663. this.forceRendering();
  1664. },
  1665. rotatePages: function rotatePages(delta) {
  1666. if (!this.pdfDocument) {
  1667. return;
  1668. }
  1669. var newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
  1670. this.pdfViewer.pagesRotation = newRotation;
  1671. },
  1672. requestPresentationMode: function requestPresentationMode() {
  1673. if (!this.pdfPresentationMode) {
  1674. return;
  1675. }
  1676. this.pdfPresentationMode.request();
  1677. },
  1678. bindEvents: function bindEvents() {
  1679. var eventBus = this.eventBus,
  1680. _boundEvents = this._boundEvents;
  1681. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1682. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1683. eventBus.on('resize', webViewerResize);
  1684. eventBus.on('hashchange', webViewerHashchange);
  1685. eventBus.on('beforeprint', _boundEvents.beforePrint);
  1686. eventBus.on('afterprint', _boundEvents.afterPrint);
  1687. eventBus.on('pagerendered', webViewerPageRendered);
  1688. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  1689. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  1690. eventBus.on('pagechanging', webViewerPageChanging);
  1691. eventBus.on('scalechanging', webViewerScaleChanging);
  1692. eventBus.on('rotationchanging', webViewerRotationChanging);
  1693. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  1694. eventBus.on('pagemode', webViewerPageMode);
  1695. eventBus.on('namedaction', webViewerNamedAction);
  1696. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  1697. eventBus.on('presentationmode', webViewerPresentationMode);
  1698. eventBus.on('openfile', webViewerOpenFile);
  1699. eventBus.on('print', webViewerPrint);
  1700. eventBus.on('download', webViewerDownload);
  1701. eventBus.on('firstpage', webViewerFirstPage);
  1702. eventBus.on('lastpage', webViewerLastPage);
  1703. eventBus.on('nextpage', webViewerNextPage);
  1704. eventBus.on('previouspage', webViewerPreviousPage);
  1705. eventBus.on('zoomin', webViewerZoomIn);
  1706. eventBus.on('zoomout', webViewerZoomOut);
  1707. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  1708. eventBus.on('scalechanged', webViewerScaleChanged);
  1709. eventBus.on('rotatecw', webViewerRotateCw);
  1710. eventBus.on('rotateccw', webViewerRotateCcw);
  1711. eventBus.on('documentproperties', webViewerDocumentProperties);
  1712. eventBus.on('find', webViewerFind);
  1713. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  1714. eventBus.on('fileinputchange', webViewerFileInputChange);
  1715. },
  1716. bindWindowEvents: function bindWindowEvents() {
  1717. var eventBus = this.eventBus,
  1718. _boundEvents = this._boundEvents;
  1719. _boundEvents.windowResize = function () {
  1720. eventBus.dispatch('resize');
  1721. };
  1722. _boundEvents.windowHashChange = function () {
  1723. eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
  1724. };
  1725. _boundEvents.windowBeforePrint = function () {
  1726. eventBus.dispatch('beforeprint');
  1727. };
  1728. _boundEvents.windowAfterPrint = function () {
  1729. eventBus.dispatch('afterprint');
  1730. };
  1731. window.addEventListener('wheel', webViewerWheel);
  1732. window.addEventListener('click', webViewerClick);
  1733. window.addEventListener('keydown', webViewerKeyDown);
  1734. window.addEventListener('resize', _boundEvents.windowResize);
  1735. window.addEventListener('hashchange', _boundEvents.windowHashChange);
  1736. window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
  1737. window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
  1738. },
  1739. unbindEvents: function unbindEvents() {
  1740. var eventBus = this.eventBus,
  1741. _boundEvents = this._boundEvents;
  1742. eventBus.off('resize', webViewerResize);
  1743. eventBus.off('hashchange', webViewerHashchange);
  1744. eventBus.off('beforeprint', _boundEvents.beforePrint);
  1745. eventBus.off('afterprint', _boundEvents.afterPrint);
  1746. eventBus.off('pagerendered', webViewerPageRendered);
  1747. eventBus.off('textlayerrendered', webViewerTextLayerRendered);
  1748. eventBus.off('updateviewarea', webViewerUpdateViewarea);
  1749. eventBus.off('pagechanging', webViewerPageChanging);
  1750. eventBus.off('scalechanging', webViewerScaleChanging);
  1751. eventBus.off('rotationchanging', webViewerRotationChanging);
  1752. eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
  1753. eventBus.off('pagemode', webViewerPageMode);
  1754. eventBus.off('namedaction', webViewerNamedAction);
  1755. eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
  1756. eventBus.off('presentationmode', webViewerPresentationMode);
  1757. eventBus.off('openfile', webViewerOpenFile);
  1758. eventBus.off('print', webViewerPrint);
  1759. eventBus.off('download', webViewerDownload);
  1760. eventBus.off('firstpage', webViewerFirstPage);
  1761. eventBus.off('lastpage', webViewerLastPage);
  1762. eventBus.off('nextpage', webViewerNextPage);
  1763. eventBus.off('previouspage', webViewerPreviousPage);
  1764. eventBus.off('zoomin', webViewerZoomIn);
  1765. eventBus.off('zoomout', webViewerZoomOut);
  1766. eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
  1767. eventBus.off('scalechanged', webViewerScaleChanged);
  1768. eventBus.off('rotatecw', webViewerRotateCw);
  1769. eventBus.off('rotateccw', webViewerRotateCcw);
  1770. eventBus.off('documentproperties', webViewerDocumentProperties);
  1771. eventBus.off('find', webViewerFind);
  1772. eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
  1773. eventBus.off('fileinputchange', webViewerFileInputChange);
  1774. _boundEvents.beforePrint = null;
  1775. _boundEvents.afterPrint = null;
  1776. },
  1777. unbindWindowEvents: function unbindWindowEvents() {
  1778. var _boundEvents = this._boundEvents;
  1779. window.removeEventListener('wheel', webViewerWheel);
  1780. window.removeEventListener('click', webViewerClick);
  1781. window.removeEventListener('keydown', webViewerKeyDown);
  1782. window.removeEventListener('resize', _boundEvents.windowResize);
  1783. window.removeEventListener('hashchange', _boundEvents.windowHashChange);
  1784. window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
  1785. window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
  1786. _boundEvents.windowResize = null;
  1787. _boundEvents.windowHashChange = null;
  1788. _boundEvents.windowBeforePrint = null;
  1789. _boundEvents.windowAfterPrint = null;
  1790. }
  1791. };
  1792. var validateFileURL = void 0;
  1793. {
  1794. var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
  1795. validateFileURL = function validateFileURL(file) {
  1796. if (file === undefined) {
  1797. return;
  1798. }
  1799. try {
  1800. var viewerOrigin = new URL(window.location.href).origin || 'null';
  1801. if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) {
  1802. return;
  1803. }
  1804. var fileOrigin = new URL(file, window.location.href).origin;
  1805. if (fileOrigin !== viewerOrigin) {
  1806. throw new Error('file origin does not match viewer\'s');
  1807. }
  1808. } catch (ex) {
  1809. var message = ex && ex.message;
  1810. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
  1811. PDFViewerApplication.error(loadingErrorMessage, { message: message });
  1812. });
  1813. throw ex;
  1814. }
  1815. };
  1816. }
  1817. function loadAndEnablePDFBug(enabledTabs) {
  1818. return new Promise(function (resolve, reject) {
  1819. var appConfig = PDFViewerApplication.appConfig;
  1820. var script = document.createElement('script');
  1821. script.src = appConfig.debuggerScriptPath;
  1822. script.onload = function () {
  1823. PDFBug.enable(enabledTabs);
  1824. PDFBug.init({
  1825. PDFJS: _pdfjsLib.PDFJS,
  1826. OPS: _pdfjsLib.OPS
  1827. }, appConfig.mainContainer);
  1828. resolve();
  1829. };
  1830. script.onerror = function () {
  1831. reject(new Error('Cannot load debugger at ' + script.src));
  1832. };
  1833. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  1834. });
  1835. }
  1836. function webViewerInitialized() {
  1837. var appConfig = PDFViewerApplication.appConfig;
  1838. var file = void 0;
  1839. var queryString = document.location.search.substring(1);
  1840. var params = (0, _ui_utils.parseQueryString)(queryString);
  1841. file = 'file' in params ? params.file : appConfig.defaultUrl;
  1842. validateFileURL(file);
  1843. var waitForBeforeOpening = [];
  1844. var fileInput = document.createElement('input');
  1845. fileInput.id = appConfig.openFileInputName;
  1846. fileInput.className = 'fileInput';
  1847. fileInput.setAttribute('type', 'file');
  1848. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1849. document.body.appendChild(fileInput);
  1850. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1851. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  1852. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  1853. } else {
  1854. fileInput.value = null;
  1855. }
  1856. fileInput.addEventListener('change', function (evt) {
  1857. var files = evt.target.files;
  1858. if (!files || files.length === 0) {
  1859. return;
  1860. }
  1861. PDFViewerApplication.eventBus.dispatch('fileinputchange', { fileInput: evt.target });
  1862. });
  1863. if (PDFViewerApplication.viewerPrefs['pdfBugEnabled']) {
  1864. var hash = document.location.hash.substring(1);
  1865. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  1866. if ('disableworker' in hashParams) {
  1867. _pdfjsLib.PDFJS.disableWorker = hashParams['disableworker'] === 'true';
  1868. }
  1869. if ('disablerange' in hashParams) {
  1870. _pdfjsLib.PDFJS.disableRange = hashParams['disablerange'] === 'true';
  1871. }
  1872. if ('disablestream' in hashParams) {
  1873. _pdfjsLib.PDFJS.disableStream = hashParams['disablestream'] === 'true';
  1874. }
  1875. if ('disableautofetch' in hashParams) {
  1876. _pdfjsLib.PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
  1877. }
  1878. if ('disablefontface' in hashParams) {
  1879. _pdfjsLib.PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
  1880. }
  1881. if ('disablehistory' in hashParams) {
  1882. _pdfjsLib.PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
  1883. }
  1884. if ('webgl' in hashParams) {
  1885. _pdfjsLib.PDFJS.disableWebGL = hashParams['webgl'] !== 'true';
  1886. }
  1887. if ('useonlycsszoom' in hashParams) {
  1888. _pdfjsLib.PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
  1889. }
  1890. if ('verbosity' in hashParams) {
  1891. _pdfjsLib.PDFJS.verbosity = hashParams['verbosity'] | 0;
  1892. }
  1893. if ('ignorecurrentpositiononzoom' in hashParams) {
  1894. _pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom = hashParams['ignorecurrentpositiononzoom'] === 'true';
  1895. }
  1896. if ('textlayer' in hashParams) {
  1897. switch (hashParams['textlayer']) {
  1898. case 'off':
  1899. _pdfjsLib.PDFJS.disableTextLayer = true;
  1900. break;
  1901. case 'visible':
  1902. case 'shadow':
  1903. case 'hover':
  1904. var viewer = appConfig.viewerContainer;
  1905. viewer.classList.add('textLayer-' + hashParams['textlayer']);
  1906. break;
  1907. }
  1908. }
  1909. if ('pdfbug' in hashParams) {
  1910. _pdfjsLib.PDFJS.pdfBug = true;
  1911. var pdfBug = hashParams['pdfbug'];
  1912. var enabled = pdfBug.split(',');
  1913. waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
  1914. }
  1915. }
  1916. if (!PDFViewerApplication.supportsPrinting) {
  1917. appConfig.toolbar.print.classList.add('hidden');
  1918. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  1919. }
  1920. if (!PDFViewerApplication.supportsFullscreen) {
  1921. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  1922. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  1923. }
  1924. if (PDFViewerApplication.supportsIntegratedFind) {
  1925. appConfig.toolbar.viewFind.classList.add('hidden');
  1926. }
  1927. appConfig.sidebar.mainContainer.addEventListener('transitionend', function (evt) {
  1928. if (evt.target === this) {
  1929. PDFViewerApplication.eventBus.dispatch('resize');
  1930. }
  1931. }, true);
  1932. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  1933. PDFViewerApplication.pdfSidebar.toggle();
  1934. });
  1935. Promise.all(waitForBeforeOpening).then(function () {
  1936. webViewerOpenFileViaURL(file);
  1937. }).catch(function (reason) {
  1938. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while opening.').then(function (msg) {
  1939. PDFViewerApplication.error(msg, reason);
  1940. });
  1941. });
  1942. }
  1943. var webViewerOpenFileViaURL = void 0;
  1944. {
  1945. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  1946. if (file && file.lastIndexOf('file:', 0) === 0) {
  1947. PDFViewerApplication.setTitleUsingUrl(file);
  1948. var xhr = new XMLHttpRequest();
  1949. xhr.onload = function () {
  1950. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1951. };
  1952. try {
  1953. xhr.open('GET', file);
  1954. xhr.responseType = 'arraybuffer';
  1955. xhr.send();
  1956. } catch (ex) {
  1957. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
  1958. PDFViewerApplication.error(msg, ex);
  1959. });
  1960. }
  1961. return;
  1962. }
  1963. if (file) {
  1964. PDFViewerApplication.open(file);
  1965. }
  1966. };
  1967. }
  1968. function webViewerPageRendered(evt) {
  1969. var pageNumber = evt.pageNumber;
  1970. var pageIndex = pageNumber - 1;
  1971. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1972. if (pageNumber === PDFViewerApplication.page) {
  1973. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1974. }
  1975. if (!pageView) {
  1976. return;
  1977. }
  1978. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1979. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1980. thumbnailView.setImage(pageView);
  1981. }
  1982. if (_pdfjsLib.PDFJS.pdfBug && Stats.enabled && pageView.stats) {
  1983. Stats.add(pageNumber, pageView.stats);
  1984. }
  1985. if (pageView.error) {
  1986. PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
  1987. PDFViewerApplication.error(msg, pageView.error);
  1988. });
  1989. }
  1990. }
  1991. function webViewerTextLayerRendered(evt) {}
  1992. function webViewerPageMode(evt) {
  1993. var mode = evt.mode,
  1994. view = void 0;
  1995. switch (mode) {
  1996. case 'thumbs':
  1997. view = _pdf_sidebar.SidebarView.THUMBS;
  1998. break;
  1999. case 'bookmarks':
  2000. case 'outline':
  2001. view = _pdf_sidebar.SidebarView.OUTLINE;
  2002. break;
  2003. case 'attachments':
  2004. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  2005. break;
  2006. case 'none':
  2007. view = _pdf_sidebar.SidebarView.NONE;
  2008. break;
  2009. default:
  2010. console.error('Invalid "pagemode" hash parameter: ' + mode);
  2011. return;
  2012. }
  2013. PDFViewerApplication.pdfSidebar.switchView(view, true);
  2014. }
  2015. function webViewerNamedAction(evt) {
  2016. var action = evt.action;
  2017. switch (action) {
  2018. case 'GoToPage':
  2019. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2020. break;
  2021. case 'Find':
  2022. if (!PDFViewerApplication.supportsIntegratedFind) {
  2023. PDFViewerApplication.findBar.toggle();
  2024. }
  2025. break;
  2026. }
  2027. }
  2028. function webViewerPresentationModeChanged(evt) {
  2029. var active = evt.active,
  2030. switchInProgress = evt.switchInProgress;
  2031. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _ui_utils.PresentationModeState.CHANGING : active ? _ui_utils.PresentationModeState.FULLSCREEN : _ui_utils.PresentationModeState.NORMAL;
  2032. }
  2033. function webViewerSidebarViewChanged(evt) {
  2034. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  2035. var store = PDFViewerApplication.store;
  2036. if (store && PDFViewerApplication.isInitialViewSet) {
  2037. store.set('sidebarView', evt.view).catch(function () {});
  2038. }
  2039. }
  2040. function webViewerUpdateViewarea(evt) {
  2041. var location = evt.location,
  2042. store = PDFViewerApplication.store;
  2043. if (store && PDFViewerApplication.isInitialViewSet) {
  2044. store.setMultiple({
  2045. 'exists': true,
  2046. 'page': location.pageNumber,
  2047. 'zoom': location.scale,
  2048. 'scrollLeft': location.left,
  2049. 'scrollTop': location.top,
  2050. 'rotation': location.rotation
  2051. }).catch(function () {});
  2052. }
  2053. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  2054. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  2055. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  2056. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  2057. var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  2058. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  2059. }
  2060. function webViewerResize() {
  2061. var pdfDocument = PDFViewerApplication.pdfDocument,
  2062. pdfViewer = PDFViewerApplication.pdfViewer;
  2063. if (!pdfDocument) {
  2064. return;
  2065. }
  2066. var currentScaleValue = pdfViewer.currentScaleValue;
  2067. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  2068. pdfViewer.currentScaleValue = currentScaleValue;
  2069. }
  2070. pdfViewer.update();
  2071. }
  2072. function webViewerHashchange(evt) {
  2073. var hash = evt.hash;
  2074. if (!hash) {
  2075. return;
  2076. }
  2077. if (!PDFViewerApplication.isInitialViewSet) {
  2078. PDFViewerApplication.initialBookmark = hash;
  2079. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  2080. PDFViewerApplication.pdfLinkService.setHash(hash);
  2081. }
  2082. }
  2083. var webViewerFileInputChange = void 0;
  2084. {
  2085. webViewerFileInputChange = function webViewerFileInputChange(evt) {
  2086. var file = evt.fileInput.files[0];
  2087. if (!_pdfjsLib.PDFJS.disableCreateObjectURL && URL.createObjectURL) {
  2088. PDFViewerApplication.open(URL.createObjectURL(file));
  2089. } else {
  2090. var fileReader = new FileReader();
  2091. fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
  2092. var buffer = evt.target.result;
  2093. PDFViewerApplication.open(new Uint8Array(buffer));
  2094. };
  2095. fileReader.readAsArrayBuffer(file);
  2096. }
  2097. PDFViewerApplication.setTitleUsingUrl(file.name);
  2098. var appConfig = PDFViewerApplication.appConfig;
  2099. appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
  2100. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
  2101. appConfig.toolbar.download.setAttribute('hidden', 'true');
  2102. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  2103. };
  2104. }
  2105. function webViewerPresentationMode() {
  2106. PDFViewerApplication.requestPresentationMode();
  2107. }
  2108. function webViewerOpenFile() {
  2109. var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  2110. document.getElementById(openFileInputName).click();
  2111. }
  2112. function webViewerPrint() {
  2113. window.print();
  2114. }
  2115. function webViewerDownload() {
  2116. PDFViewerApplication.download();
  2117. }
  2118. function webViewerFirstPage() {
  2119. if (PDFViewerApplication.pdfDocument) {
  2120. PDFViewerApplication.page = 1;
  2121. }
  2122. }
  2123. function webViewerLastPage() {
  2124. if (PDFViewerApplication.pdfDocument) {
  2125. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2126. }
  2127. }
  2128. function webViewerNextPage() {
  2129. PDFViewerApplication.page++;
  2130. }
  2131. function webViewerPreviousPage() {
  2132. PDFViewerApplication.page--;
  2133. }
  2134. function webViewerZoomIn() {
  2135. PDFViewerApplication.zoomIn();
  2136. }
  2137. function webViewerZoomOut() {
  2138. PDFViewerApplication.zoomOut();
  2139. }
  2140. function webViewerPageNumberChanged(evt) {
  2141. var pdfViewer = PDFViewerApplication.pdfViewer;
  2142. pdfViewer.currentPageLabel = evt.value;
  2143. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2144. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2145. }
  2146. }
  2147. function webViewerScaleChanged(evt) {
  2148. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2149. }
  2150. function webViewerRotateCw() {
  2151. PDFViewerApplication.rotatePages(90);
  2152. }
  2153. function webViewerRotateCcw() {
  2154. PDFViewerApplication.rotatePages(-90);
  2155. }
  2156. function webViewerDocumentProperties() {
  2157. PDFViewerApplication.pdfDocumentProperties.open();
  2158. }
  2159. function webViewerFind(evt) {
  2160. PDFViewerApplication.findController.executeCommand('find' + evt.type, {
  2161. query: evt.query,
  2162. phraseSearch: evt.phraseSearch,
  2163. caseSensitive: evt.caseSensitive,
  2164. highlightAll: evt.highlightAll,
  2165. findPrevious: evt.findPrevious
  2166. });
  2167. }
  2168. function webViewerFindFromUrlHash(evt) {
  2169. PDFViewerApplication.findController.executeCommand('find', {
  2170. query: evt.query,
  2171. phraseSearch: evt.phraseSearch,
  2172. caseSensitive: false,
  2173. highlightAll: true,
  2174. findPrevious: false
  2175. });
  2176. }
  2177. function webViewerScaleChanging(evt) {
  2178. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2179. PDFViewerApplication.pdfViewer.update();
  2180. }
  2181. function webViewerRotationChanging(evt) {
  2182. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2183. PDFViewerApplication.forceRendering();
  2184. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2185. }
  2186. function webViewerPageChanging(evt) {
  2187. var page = evt.pageNumber;
  2188. PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
  2189. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  2190. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2191. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  2192. }
  2193. if (_pdfjsLib.PDFJS.pdfBug && Stats.enabled) {
  2194. var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  2195. if (pageView.stats) {
  2196. Stats.add(page, pageView.stats);
  2197. }
  2198. }
  2199. }
  2200. var zoomDisabled = false,
  2201. zoomDisabledTimeout = void 0;
  2202. function webViewerWheel(evt) {
  2203. var pdfViewer = PDFViewerApplication.pdfViewer;
  2204. if (pdfViewer.isInPresentationMode) {
  2205. return;
  2206. }
  2207. if (evt.ctrlKey || evt.metaKey) {
  2208. var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
  2209. if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
  2210. return;
  2211. }
  2212. evt.preventDefault();
  2213. if (zoomDisabled) {
  2214. return;
  2215. }
  2216. var previousScale = pdfViewer.currentScale;
  2217. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  2218. var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  2219. var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  2220. if (ticks < 0) {
  2221. PDFViewerApplication.zoomOut(-ticks);
  2222. } else {
  2223. PDFViewerApplication.zoomIn(ticks);
  2224. }
  2225. var currentScale = pdfViewer.currentScale;
  2226. if (previousScale !== currentScale) {
  2227. var scaleCorrectionFactor = currentScale / previousScale - 1;
  2228. var rect = pdfViewer.container.getBoundingClientRect();
  2229. var dx = evt.clientX - rect.left;
  2230. var dy = evt.clientY - rect.top;
  2231. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2232. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2233. }
  2234. } else {
  2235. zoomDisabled = true;
  2236. clearTimeout(zoomDisabledTimeout);
  2237. zoomDisabledTimeout = setTimeout(function () {
  2238. zoomDisabled = false;
  2239. }, 1000);
  2240. }
  2241. }
  2242. function webViewerClick(evt) {
  2243. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2244. return;
  2245. }
  2246. var appConfig = PDFViewerApplication.appConfig;
  2247. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2248. PDFViewerApplication.secondaryToolbar.close();
  2249. }
  2250. }
  2251. function webViewerKeyDown(evt) {
  2252. if (PDFViewerApplication.overlayManager.active) {
  2253. return;
  2254. }
  2255. var handled = false,
  2256. ensureViewerFocused = false;
  2257. var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2258. var pdfViewer = PDFViewerApplication.pdfViewer;
  2259. var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  2260. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2261. switch (evt.keyCode) {
  2262. case 70:
  2263. if (!PDFViewerApplication.supportsIntegratedFind) {
  2264. PDFViewerApplication.findBar.open();
  2265. handled = true;
  2266. }
  2267. break;
  2268. case 71:
  2269. if (!PDFViewerApplication.supportsIntegratedFind) {
  2270. var findState = PDFViewerApplication.findController.state;
  2271. if (findState) {
  2272. PDFViewerApplication.findController.executeCommand('findagain', {
  2273. query: findState.query,
  2274. phraseSearch: findState.phraseSearch,
  2275. caseSensitive: findState.caseSensitive,
  2276. highlightAll: findState.highlightAll,
  2277. findPrevious: cmd === 5 || cmd === 12
  2278. });
  2279. }
  2280. handled = true;
  2281. }
  2282. break;
  2283. case 61:
  2284. case 107:
  2285. case 187:
  2286. case 171:
  2287. if (!isViewerInPresentationMode) {
  2288. PDFViewerApplication.zoomIn();
  2289. }
  2290. handled = true;
  2291. break;
  2292. case 173:
  2293. case 109:
  2294. case 189:
  2295. if (!isViewerInPresentationMode) {
  2296. PDFViewerApplication.zoomOut();
  2297. }
  2298. handled = true;
  2299. break;
  2300. case 48:
  2301. case 96:
  2302. if (!isViewerInPresentationMode) {
  2303. setTimeout(function () {
  2304. pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2305. });
  2306. handled = false;
  2307. }
  2308. break;
  2309. case 38:
  2310. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2311. PDFViewerApplication.page = 1;
  2312. handled = true;
  2313. ensureViewerFocused = true;
  2314. }
  2315. break;
  2316. case 40:
  2317. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2318. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2319. handled = true;
  2320. ensureViewerFocused = true;
  2321. }
  2322. break;
  2323. }
  2324. }
  2325. if (cmd === 1 || cmd === 8) {
  2326. switch (evt.keyCode) {
  2327. case 83:
  2328. PDFViewerApplication.download();
  2329. handled = true;
  2330. break;
  2331. }
  2332. }
  2333. if (cmd === 3 || cmd === 10) {
  2334. switch (evt.keyCode) {
  2335. case 80:
  2336. PDFViewerApplication.requestPresentationMode();
  2337. handled = true;
  2338. break;
  2339. case 71:
  2340. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2341. handled = true;
  2342. break;
  2343. }
  2344. }
  2345. if (handled) {
  2346. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2347. pdfViewer.focus();
  2348. }
  2349. evt.preventDefault();
  2350. return;
  2351. }
  2352. var curElement = document.activeElement || document.querySelector(':focus');
  2353. var curElementTagName = curElement && curElement.tagName.toUpperCase();
  2354. if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
  2355. if (evt.keyCode !== 27) {
  2356. return;
  2357. }
  2358. }
  2359. if (cmd === 0) {
  2360. switch (evt.keyCode) {
  2361. case 38:
  2362. case 33:
  2363. case 8:
  2364. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  2365. break;
  2366. }
  2367. case 37:
  2368. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2369. break;
  2370. }
  2371. case 75:
  2372. case 80:
  2373. if (PDFViewerApplication.page > 1) {
  2374. PDFViewerApplication.page--;
  2375. }
  2376. handled = true;
  2377. break;
  2378. case 27:
  2379. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2380. PDFViewerApplication.secondaryToolbar.close();
  2381. handled = true;
  2382. }
  2383. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2384. PDFViewerApplication.findBar.close();
  2385. handled = true;
  2386. }
  2387. break;
  2388. case 40:
  2389. case 34:
  2390. case 32:
  2391. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  2392. break;
  2393. }
  2394. case 39:
  2395. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2396. break;
  2397. }
  2398. case 74:
  2399. case 78:
  2400. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2401. PDFViewerApplication.page++;
  2402. }
  2403. handled = true;
  2404. break;
  2405. case 36:
  2406. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2407. PDFViewerApplication.page = 1;
  2408. handled = true;
  2409. ensureViewerFocused = true;
  2410. }
  2411. break;
  2412. case 35:
  2413. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2414. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2415. handled = true;
  2416. ensureViewerFocused = true;
  2417. }
  2418. break;
  2419. case 83:
  2420. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2421. break;
  2422. case 72:
  2423. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2424. break;
  2425. case 82:
  2426. PDFViewerApplication.rotatePages(90);
  2427. break;
  2428. }
  2429. }
  2430. if (cmd === 4) {
  2431. switch (evt.keyCode) {
  2432. case 32:
  2433. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  2434. break;
  2435. }
  2436. if (PDFViewerApplication.page > 1) {
  2437. PDFViewerApplication.page--;
  2438. }
  2439. handled = true;
  2440. break;
  2441. case 82:
  2442. PDFViewerApplication.rotatePages(-90);
  2443. break;
  2444. }
  2445. }
  2446. if (!handled && !isViewerInPresentationMode) {
  2447. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
  2448. ensureViewerFocused = true;
  2449. }
  2450. }
  2451. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2452. pdfViewer.focus();
  2453. }
  2454. if (handled) {
  2455. evt.preventDefault();
  2456. }
  2457. }
  2458. function apiPageModeToSidebarView(mode) {
  2459. switch (mode) {
  2460. case 'UseNone':
  2461. return _pdf_sidebar.SidebarView.NONE;
  2462. case 'UseThumbs':
  2463. return _pdf_sidebar.SidebarView.THUMBS;
  2464. case 'UseOutlines':
  2465. return _pdf_sidebar.SidebarView.OUTLINE;
  2466. case 'UseAttachments':
  2467. return _pdf_sidebar.SidebarView.ATTACHMENTS;
  2468. case 'UseOC':
  2469. }
  2470. return _pdf_sidebar.SidebarView.NONE;
  2471. }
  2472. var PDFPrintServiceFactory = {
  2473. instance: {
  2474. supportsPrinting: false,
  2475. createPrintService: function createPrintService() {
  2476. throw new Error('Not implemented: createPrintService');
  2477. }
  2478. }
  2479. };
  2480. exports.PDFViewerApplication = PDFViewerApplication;
  2481. exports.DefaultExternalServices = DefaultExternalServices;
  2482. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2483. /***/ }),
  2484. /* 5 */
  2485. /***/ (function(module, exports, __webpack_require__) {
  2486. "use strict";
  2487. Object.defineProperty(exports, "__esModule", {
  2488. value: true
  2489. });
  2490. exports.SimpleLinkService = exports.PDFLinkService = undefined;
  2491. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2492. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  2493. var _dom_events = __webpack_require__(2);
  2494. var _ui_utils = __webpack_require__(0);
  2495. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2496. var PDFLinkService = function () {
  2497. function PDFLinkService() {
  2498. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  2499. eventBus = _ref.eventBus;
  2500. _classCallCheck(this, PDFLinkService);
  2501. this.eventBus = eventBus || (0, _dom_events.getGlobalEventBus)();
  2502. this.baseUrl = null;
  2503. this.pdfDocument = null;
  2504. this.pdfViewer = null;
  2505. this.pdfHistory = null;
  2506. this._pagesRefCache = null;
  2507. }
  2508. _createClass(PDFLinkService, [{
  2509. key: 'setDocument',
  2510. value: function setDocument(pdfDocument, baseUrl) {
  2511. this.baseUrl = baseUrl;
  2512. this.pdfDocument = pdfDocument;
  2513. this._pagesRefCache = Object.create(null);
  2514. }
  2515. }, {
  2516. key: 'setViewer',
  2517. value: function setViewer(pdfViewer) {
  2518. this.pdfViewer = pdfViewer;
  2519. }
  2520. }, {
  2521. key: 'setHistory',
  2522. value: function setHistory(pdfHistory) {
  2523. this.pdfHistory = pdfHistory;
  2524. }
  2525. }, {
  2526. key: 'navigateTo',
  2527. value: function navigateTo(dest) {
  2528. var _this = this;
  2529. var goToDestination = function goToDestination(_ref2) {
  2530. var namedDest = _ref2.namedDest,
  2531. explicitDest = _ref2.explicitDest;
  2532. var destRef = explicitDest[0],
  2533. pageNumber = void 0;
  2534. if (destRef instanceof Object) {
  2535. pageNumber = _this._cachedPageNumber(destRef);
  2536. if (pageNumber === null) {
  2537. _this.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
  2538. _this.cachePageRef(pageIndex + 1, destRef);
  2539. goToDestination({
  2540. namedDest: namedDest,
  2541. explicitDest: explicitDest
  2542. });
  2543. }).catch(function () {
  2544. console.error('PDFLinkService.navigateTo: "' + destRef + '" is not ' + ('a valid page reference, for dest="' + dest + '".'));
  2545. });
  2546. return;
  2547. }
  2548. } else if (Number.isInteger(destRef)) {
  2549. pageNumber = destRef + 1;
  2550. } else {
  2551. console.error('PDFLinkService.navigateTo: "' + destRef + '" is not ' + ('a valid destination reference, for dest="' + dest + '".'));
  2552. return;
  2553. }
  2554. if (!pageNumber || pageNumber < 1 || pageNumber > _this.pagesCount) {
  2555. console.error('PDFLinkService.navigateTo: "' + pageNumber + '" is not ' + ('a valid page number, for dest="' + dest + '".'));
  2556. return;
  2557. }
  2558. if (_this.pdfHistory) {
  2559. _this.pdfHistory.pushCurrentPosition();
  2560. _this.pdfHistory.push({
  2561. namedDest: namedDest,
  2562. explicitDest: explicitDest,
  2563. pageNumber: pageNumber
  2564. });
  2565. }
  2566. _this.pdfViewer.scrollPageIntoView({
  2567. pageNumber: pageNumber,
  2568. destArray: explicitDest
  2569. });
  2570. };
  2571. new Promise(function (resolve, reject) {
  2572. if (typeof dest === 'string') {
  2573. _this.pdfDocument.getDestination(dest).then(function (destArray) {
  2574. resolve({
  2575. namedDest: dest,
  2576. explicitDest: destArray
  2577. });
  2578. });
  2579. return;
  2580. }
  2581. resolve({
  2582. namedDest: '',
  2583. explicitDest: dest
  2584. });
  2585. }).then(function (data) {
  2586. if (!(data.explicitDest instanceof Array)) {
  2587. console.error('PDFLinkService.navigateTo: "' + data.explicitDest + '" is' + (' not a valid destination array, for dest="' + dest + '".'));
  2588. return;
  2589. }
  2590. goToDestination(data);
  2591. });
  2592. }
  2593. }, {
  2594. key: 'getDestinationHash',
  2595. value: function getDestinationHash(dest) {
  2596. if (typeof dest === 'string') {
  2597. return this.getAnchorUrl('#' + escape(dest));
  2598. }
  2599. if (dest instanceof Array) {
  2600. var str = JSON.stringify(dest);
  2601. return this.getAnchorUrl('#' + escape(str));
  2602. }
  2603. return this.getAnchorUrl('');
  2604. }
  2605. }, {
  2606. key: 'getAnchorUrl',
  2607. value: function getAnchorUrl(anchor) {
  2608. return (this.baseUrl || '') + anchor;
  2609. }
  2610. }, {
  2611. key: 'setHash',
  2612. value: function setHash(hash) {
  2613. var pageNumber = void 0,
  2614. dest = void 0;
  2615. if (hash.indexOf('=') >= 0) {
  2616. var params = (0, _ui_utils.parseQueryString)(hash);
  2617. if ('search' in params) {
  2618. this.eventBus.dispatch('findfromurlhash', {
  2619. source: this,
  2620. query: params['search'].replace(/"/g, ''),
  2621. phraseSearch: params['phrase'] === 'true'
  2622. });
  2623. }
  2624. if ('nameddest' in params) {
  2625. this.navigateTo(params.nameddest);
  2626. return;
  2627. }
  2628. if ('page' in params) {
  2629. pageNumber = params.page | 0 || 1;
  2630. }
  2631. if ('zoom' in params) {
  2632. var zoomArgs = params.zoom.split(',');
  2633. var zoomArg = zoomArgs[0];
  2634. var zoomArgNumber = parseFloat(zoomArg);
  2635. if (zoomArg.indexOf('Fit') === -1) {
  2636. dest = [null, { name: 'XYZ' }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  2637. } else {
  2638. if (zoomArg === 'Fit' || zoomArg === 'FitB') {
  2639. dest = [null, { name: zoomArg }];
  2640. } else if (zoomArg === 'FitH' || zoomArg === 'FitBH' || zoomArg === 'FitV' || zoomArg === 'FitBV') {
  2641. dest = [null, { name: zoomArg }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  2642. } else if (zoomArg === 'FitR') {
  2643. if (zoomArgs.length !== 5) {
  2644. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  2645. } else {
  2646. dest = [null, { name: zoomArg }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  2647. }
  2648. } else {
  2649. console.error('PDFLinkService.setHash: "' + zoomArg + '" is not ' + 'a valid zoom value.');
  2650. }
  2651. }
  2652. }
  2653. if (dest) {
  2654. this.pdfViewer.scrollPageIntoView({
  2655. pageNumber: pageNumber || this.page,
  2656. destArray: dest,
  2657. allowNegativeOffset: true
  2658. });
  2659. } else if (pageNumber) {
  2660. this.page = pageNumber;
  2661. }
  2662. if ('pagemode' in params) {
  2663. this.eventBus.dispatch('pagemode', {
  2664. source: this,
  2665. mode: params.pagemode
  2666. });
  2667. }
  2668. } else {
  2669. if (/^\d+$/.test(hash) && hash <= this.pagesCount) {
  2670. console.warn('PDFLinkService_setHash: specifying a page number ' + 'directly after the hash symbol (#) is deprecated, ' + ('please use the "#page=' + hash + '" form instead.'));
  2671. this.page = hash | 0;
  2672. }
  2673. dest = unescape(hash);
  2674. try {
  2675. dest = JSON.parse(dest);
  2676. if (!(dest instanceof Array)) {
  2677. dest = dest.toString();
  2678. }
  2679. } catch (ex) {}
  2680. if (typeof dest === 'string' || isValidExplicitDestination(dest)) {
  2681. this.navigateTo(dest);
  2682. return;
  2683. }
  2684. console.error('PDFLinkService.setHash: "' + unescape(hash) + '" is not ' + 'a valid destination.');
  2685. }
  2686. }
  2687. }, {
  2688. key: 'executeNamedAction',
  2689. value: function executeNamedAction(action) {
  2690. switch (action) {
  2691. case 'GoBack':
  2692. if (this.pdfHistory) {
  2693. this.pdfHistory.back();
  2694. }
  2695. break;
  2696. case 'GoForward':
  2697. if (this.pdfHistory) {
  2698. this.pdfHistory.forward();
  2699. }
  2700. break;
  2701. case 'NextPage':
  2702. if (this.page < this.pagesCount) {
  2703. this.page++;
  2704. }
  2705. break;
  2706. case 'PrevPage':
  2707. if (this.page > 1) {
  2708. this.page--;
  2709. }
  2710. break;
  2711. case 'LastPage':
  2712. this.page = this.pagesCount;
  2713. break;
  2714. case 'FirstPage':
  2715. this.page = 1;
  2716. break;
  2717. default:
  2718. break;
  2719. }
  2720. this.eventBus.dispatch('namedaction', {
  2721. source: this,
  2722. action: action
  2723. });
  2724. }
  2725. }, {
  2726. key: 'onFileAttachmentAnnotation',
  2727. value: function onFileAttachmentAnnotation(_ref3) {
  2728. var id = _ref3.id,
  2729. filename = _ref3.filename,
  2730. content = _ref3.content;
  2731. this.eventBus.dispatch('fileattachmentannotation', {
  2732. source: this,
  2733. id: id,
  2734. filename: filename,
  2735. content: content
  2736. });
  2737. }
  2738. }, {
  2739. key: 'cachePageRef',
  2740. value: function cachePageRef(pageNum, pageRef) {
  2741. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  2742. this._pagesRefCache[refStr] = pageNum;
  2743. }
  2744. }, {
  2745. key: '_cachedPageNumber',
  2746. value: function _cachedPageNumber(pageRef) {
  2747. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  2748. return this._pagesRefCache && this._pagesRefCache[refStr] || null;
  2749. }
  2750. }, {
  2751. key: 'pagesCount',
  2752. get: function get() {
  2753. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  2754. }
  2755. }, {
  2756. key: 'page',
  2757. get: function get() {
  2758. return this.pdfViewer.currentPageNumber;
  2759. },
  2760. set: function set(value) {
  2761. this.pdfViewer.currentPageNumber = value;
  2762. }
  2763. }, {
  2764. key: 'rotation',
  2765. get: function get() {
  2766. return this.pdfViewer.pagesRotation;
  2767. },
  2768. set: function set(value) {
  2769. this.pdfViewer.pagesRotation = value;
  2770. }
  2771. }]);
  2772. return PDFLinkService;
  2773. }();
  2774. function isValidExplicitDestination(dest) {
  2775. if (!(dest instanceof Array)) {
  2776. return false;
  2777. }
  2778. var destLength = dest.length,
  2779. allowNull = true;
  2780. if (destLength < 2) {
  2781. return false;
  2782. }
  2783. var page = dest[0];
  2784. if (!((typeof page === 'undefined' ? 'undefined' : _typeof(page)) === 'object' && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  2785. return false;
  2786. }
  2787. var zoom = dest[1];
  2788. if (!((typeof zoom === 'undefined' ? 'undefined' : _typeof(zoom)) === 'object' && typeof zoom.name === 'string')) {
  2789. return false;
  2790. }
  2791. switch (zoom.name) {
  2792. case 'XYZ':
  2793. if (destLength !== 5) {
  2794. return false;
  2795. }
  2796. break;
  2797. case 'Fit':
  2798. case 'FitB':
  2799. return destLength === 2;
  2800. case 'FitH':
  2801. case 'FitBH':
  2802. case 'FitV':
  2803. case 'FitBV':
  2804. if (destLength !== 3) {
  2805. return false;
  2806. }
  2807. break;
  2808. case 'FitR':
  2809. if (destLength !== 6) {
  2810. return false;
  2811. }
  2812. allowNull = false;
  2813. break;
  2814. default:
  2815. return false;
  2816. }
  2817. for (var i = 2; i < destLength; i++) {
  2818. var param = dest[i];
  2819. if (!(typeof param === 'number' || allowNull && param === null)) {
  2820. return false;
  2821. }
  2822. }
  2823. return true;
  2824. }
  2825. var SimpleLinkService = function () {
  2826. function SimpleLinkService() {
  2827. _classCallCheck(this, SimpleLinkService);
  2828. }
  2829. _createClass(SimpleLinkService, [{
  2830. key: 'navigateTo',
  2831. value: function navigateTo(dest) {}
  2832. }, {
  2833. key: 'getDestinationHash',
  2834. value: function getDestinationHash(dest) {
  2835. return '#';
  2836. }
  2837. }, {
  2838. key: 'getAnchorUrl',
  2839. value: function getAnchorUrl(hash) {
  2840. return '#';
  2841. }
  2842. }, {
  2843. key: 'setHash',
  2844. value: function setHash(hash) {}
  2845. }, {
  2846. key: 'executeNamedAction',
  2847. value: function executeNamedAction(action) {}
  2848. }, {
  2849. key: 'onFileAttachmentAnnotation',
  2850. value: function onFileAttachmentAnnotation(_ref4) {
  2851. var id = _ref4.id,
  2852. filename = _ref4.filename,
  2853. content = _ref4.content;
  2854. }
  2855. }, {
  2856. key: 'cachePageRef',
  2857. value: function cachePageRef(pageNum, pageRef) {}
  2858. }, {
  2859. key: 'page',
  2860. get: function get() {
  2861. return 0;
  2862. },
  2863. set: function set(value) {}
  2864. }, {
  2865. key: 'rotation',
  2866. get: function get() {
  2867. return 0;
  2868. },
  2869. set: function set(value) {}
  2870. }]);
  2871. return SimpleLinkService;
  2872. }();
  2873. exports.PDFLinkService = PDFLinkService;
  2874. exports.SimpleLinkService = SimpleLinkService;
  2875. /***/ }),
  2876. /* 6 */
  2877. /***/ (function(module, exports, __webpack_require__) {
  2878. "use strict";
  2879. Object.defineProperty(exports, "__esModule", {
  2880. value: true
  2881. });
  2882. exports.PDFCursorTools = exports.CursorTool = undefined;
  2883. var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
  2884. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  2885. var _grab_to_pan = __webpack_require__(9);
  2886. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2887. var CursorTool = {
  2888. SELECT: 0,
  2889. HAND: 1,
  2890. ZOOM: 2
  2891. };
  2892. var PDFCursorTools = function () {
  2893. function PDFCursorTools(_ref) {
  2894. var _this = this;
  2895. var container = _ref.container,
  2896. eventBus = _ref.eventBus,
  2897. preferences = _ref.preferences;
  2898. _classCallCheck(this, PDFCursorTools);
  2899. this.container = container;
  2900. this.eventBus = eventBus;
  2901. this.active = CursorTool.SELECT;
  2902. this.activeBeforePresentationMode = null;
  2903. this.handTool = new _grab_to_pan.GrabToPan({ element: this.container });
  2904. this._addEventListeners();
  2905. Promise.all([preferences.get('cursorToolOnLoad'), preferences.get('enableHandToolOnLoad')]).then(function (_ref2) {
  2906. var _ref3 = _slicedToArray(_ref2, 2),
  2907. cursorToolPref = _ref3[0],
  2908. handToolPref = _ref3[1];
  2909. if (handToolPref === true) {
  2910. preferences.set('enableHandToolOnLoad', false);
  2911. if (cursorToolPref === CursorTool.SELECT) {
  2912. cursorToolPref = CursorTool.HAND;
  2913. preferences.set('cursorToolOnLoad', cursorToolPref).catch(function () {});
  2914. }
  2915. }
  2916. _this.switchTool(cursorToolPref);
  2917. }).catch(function () {});
  2918. }
  2919. _createClass(PDFCursorTools, [{
  2920. key: 'switchTool',
  2921. value: function switchTool(tool) {
  2922. var _this2 = this;
  2923. if (this.activeBeforePresentationMode !== null) {
  2924. return;
  2925. }
  2926. if (tool === this.active) {
  2927. return;
  2928. }
  2929. var disableActiveTool = function disableActiveTool() {
  2930. switch (_this2.active) {
  2931. case CursorTool.SELECT:
  2932. break;
  2933. case CursorTool.HAND:
  2934. _this2.handTool.deactivate();
  2935. break;
  2936. case CursorTool.ZOOM:
  2937. }
  2938. };
  2939. switch (tool) {
  2940. case CursorTool.SELECT:
  2941. disableActiveTool();
  2942. break;
  2943. case CursorTool.HAND:
  2944. disableActiveTool();
  2945. this.handTool.activate();
  2946. break;
  2947. case CursorTool.ZOOM:
  2948. default:
  2949. console.error('switchTool: "' + tool + '" is an unsupported value.');
  2950. return;
  2951. }
  2952. this.active = tool;
  2953. this._dispatchEvent();
  2954. }
  2955. }, {
  2956. key: '_dispatchEvent',
  2957. value: function _dispatchEvent() {
  2958. this.eventBus.dispatch('cursortoolchanged', {
  2959. source: this,
  2960. tool: this.active
  2961. });
  2962. }
  2963. }, {
  2964. key: '_addEventListeners',
  2965. value: function _addEventListeners() {
  2966. var _this3 = this;
  2967. this.eventBus.on('switchcursortool', function (evt) {
  2968. _this3.switchTool(evt.tool);
  2969. });
  2970. this.eventBus.on('presentationmodechanged', function (evt) {
  2971. if (evt.switchInProgress) {
  2972. return;
  2973. }
  2974. var previouslyActive = void 0;
  2975. if (evt.active) {
  2976. previouslyActive = _this3.active;
  2977. _this3.switchTool(CursorTool.SELECT);
  2978. _this3.activeBeforePresentationMode = previouslyActive;
  2979. } else {
  2980. previouslyActive = _this3.activeBeforePresentationMode;
  2981. _this3.activeBeforePresentationMode = null;
  2982. _this3.switchTool(previouslyActive);
  2983. }
  2984. });
  2985. }
  2986. }, {
  2987. key: 'activeTool',
  2988. get: function get() {
  2989. return this.active;
  2990. }
  2991. }]);
  2992. return PDFCursorTools;
  2993. }();
  2994. exports.CursorTool = CursorTool;
  2995. exports.PDFCursorTools = PDFCursorTools;
  2996. /***/ }),
  2997. /* 7 */
  2998. /***/ (function(module, exports, __webpack_require__) {
  2999. "use strict";
  3000. Object.defineProperty(exports, "__esModule", {
  3001. value: true
  3002. });
  3003. exports.PDFFindController = exports.FindState = undefined;
  3004. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3005. var _pdfjsLib = __webpack_require__(1);
  3006. var _ui_utils = __webpack_require__(0);
  3007. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3008. var FindState = {
  3009. FOUND: 0,
  3010. NOT_FOUND: 1,
  3011. WRAPPED: 2,
  3012. PENDING: 3
  3013. };
  3014. var FIND_SCROLL_OFFSET_TOP = -50;
  3015. var FIND_SCROLL_OFFSET_LEFT = -400;
  3016. var FIND_TIMEOUT = 250;
  3017. var CHARACTERS_TO_NORMALIZE = {
  3018. '\u2018': '\'',
  3019. '\u2019': '\'',
  3020. '\u201A': '\'',
  3021. '\u201B': '\'',
  3022. '\u201C': '"',
  3023. '\u201D': '"',
  3024. '\u201E': '"',
  3025. '\u201F': '"',
  3026. '\xBC': '1/4',
  3027. '\xBD': '1/2',
  3028. '\xBE': '3/4'
  3029. };
  3030. var PDFFindController = function () {
  3031. function PDFFindController(_ref) {
  3032. var pdfViewer = _ref.pdfViewer;
  3033. _classCallCheck(this, PDFFindController);
  3034. this.pdfViewer = pdfViewer;
  3035. this.onUpdateResultsCount = null;
  3036. this.onUpdateState = null;
  3037. this.reset();
  3038. var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
  3039. this.normalizationRegex = new RegExp('[' + replace + ']', 'g');
  3040. }
  3041. _createClass(PDFFindController, [{
  3042. key: 'reset',
  3043. value: function reset() {
  3044. var _this = this;
  3045. this.startedTextExtraction = false;
  3046. this.extractTextPromises = [];
  3047. this.pendingFindMatches = Object.create(null);
  3048. this.active = false;
  3049. this.pageContents = [];
  3050. this.pageMatches = [];
  3051. this.pageMatchesLength = null;
  3052. this.matchCount = 0;
  3053. this.selected = {
  3054. pageIdx: -1,
  3055. matchIdx: -1
  3056. };
  3057. this.offset = {
  3058. pageIdx: null,
  3059. matchIdx: null
  3060. };
  3061. this.pagesToSearch = null;
  3062. this.resumePageIdx = null;
  3063. this.state = null;
  3064. this.dirtyMatch = false;
  3065. this.findTimeout = null;
  3066. this._firstPagePromise = new Promise(function (resolve) {
  3067. _this.resolveFirstPage = resolve;
  3068. });
  3069. }
  3070. }, {
  3071. key: 'normalize',
  3072. value: function normalize(text) {
  3073. return text.replace(this.normalizationRegex, function (ch) {
  3074. return CHARACTERS_TO_NORMALIZE[ch];
  3075. });
  3076. }
  3077. }, {
  3078. key: '_prepareMatches',
  3079. value: function _prepareMatches(matchesWithLength, matches, matchesLength) {
  3080. function isSubTerm(matchesWithLength, currentIndex) {
  3081. var currentElem = matchesWithLength[currentIndex];
  3082. var nextElem = matchesWithLength[currentIndex + 1];
  3083. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  3084. currentElem.skipped = true;
  3085. return true;
  3086. }
  3087. for (var i = currentIndex - 1; i >= 0; i--) {
  3088. var prevElem = matchesWithLength[i];
  3089. if (prevElem.skipped) {
  3090. continue;
  3091. }
  3092. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  3093. break;
  3094. }
  3095. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  3096. currentElem.skipped = true;
  3097. return true;
  3098. }
  3099. }
  3100. return false;
  3101. }
  3102. matchesWithLength.sort(function (a, b) {
  3103. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  3104. });
  3105. for (var i = 0, len = matchesWithLength.length; i < len; i++) {
  3106. if (isSubTerm(matchesWithLength, i)) {
  3107. continue;
  3108. }
  3109. matches.push(matchesWithLength[i].match);
  3110. matchesLength.push(matchesWithLength[i].matchLength);
  3111. }
  3112. }
  3113. }, {
  3114. key: 'calcFindPhraseMatch',
  3115. value: function calcFindPhraseMatch(query, pageIndex, pageContent) {
  3116. var matches = [];
  3117. var queryLen = query.length;
  3118. var matchIdx = -queryLen;
  3119. while (true) {
  3120. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  3121. if (matchIdx === -1) {
  3122. break;
  3123. }
  3124. matches.push(matchIdx);
  3125. }
  3126. this.pageMatches[pageIndex] = matches;
  3127. }
  3128. }, {
  3129. key: 'calcFindWordMatch',
  3130. value: function calcFindWordMatch(query, pageIndex, pageContent) {
  3131. var matchesWithLength = [];
  3132. var queryArray = query.match(/\S+/g);
  3133. for (var i = 0, len = queryArray.length; i < len; i++) {
  3134. var subquery = queryArray[i];
  3135. var subqueryLen = subquery.length;
  3136. var matchIdx = -subqueryLen;
  3137. while (true) {
  3138. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  3139. if (matchIdx === -1) {
  3140. break;
  3141. }
  3142. matchesWithLength.push({
  3143. match: matchIdx,
  3144. matchLength: subqueryLen,
  3145. skipped: false
  3146. });
  3147. }
  3148. }
  3149. if (!this.pageMatchesLength) {
  3150. this.pageMatchesLength = [];
  3151. }
  3152. this.pageMatchesLength[pageIndex] = [];
  3153. this.pageMatches[pageIndex] = [];
  3154. this._prepareMatches(matchesWithLength, this.pageMatches[pageIndex], this.pageMatchesLength[pageIndex]);
  3155. }
  3156. }, {
  3157. key: 'calcFindMatch',
  3158. value: function calcFindMatch(pageIndex) {
  3159. var pageContent = this.normalize(this.pageContents[pageIndex]);
  3160. var query = this.normalize(this.state.query);
  3161. var caseSensitive = this.state.caseSensitive;
  3162. var phraseSearch = this.state.phraseSearch;
  3163. var queryLen = query.length;
  3164. if (queryLen === 0) {
  3165. return;
  3166. }
  3167. if (!caseSensitive) {
  3168. pageContent = pageContent.toLowerCase();
  3169. query = query.toLowerCase();
  3170. }
  3171. if (phraseSearch) {
  3172. this.calcFindPhraseMatch(query, pageIndex, pageContent);
  3173. } else {
  3174. this.calcFindWordMatch(query, pageIndex, pageContent);
  3175. }
  3176. this.updatePage(pageIndex);
  3177. if (this.resumePageIdx === pageIndex) {
  3178. this.resumePageIdx = null;
  3179. this.nextPageMatch();
  3180. }
  3181. if (this.pageMatches[pageIndex].length > 0) {
  3182. this.matchCount += this.pageMatches[pageIndex].length;
  3183. this.updateUIResultsCount();
  3184. }
  3185. }
  3186. }, {
  3187. key: 'extractText',
  3188. value: function extractText() {
  3189. var _this2 = this;
  3190. if (this.startedTextExtraction) {
  3191. return;
  3192. }
  3193. this.startedTextExtraction = true;
  3194. this.pageContents.length = 0;
  3195. var promise = Promise.resolve();
  3196. var _loop = function _loop(i, ii) {
  3197. var extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  3198. _this2.extractTextPromises[i] = extractTextCapability.promise;
  3199. promise = promise.then(function () {
  3200. return _this2.pdfViewer.getPageTextContent(i).then(function (textContent) {
  3201. var textItems = textContent.items;
  3202. var strBuf = [];
  3203. for (var j = 0, jj = textItems.length; j < jj; j++) {
  3204. strBuf.push(textItems[j].str);
  3205. }
  3206. _this2.pageContents[i] = strBuf.join('');
  3207. extractTextCapability.resolve(i);
  3208. }, function (reason) {
  3209. console.error('Unable to get page ' + (i + 1) + ' text content', reason);
  3210. _this2.pageContents[i] = '';
  3211. extractTextCapability.resolve(i);
  3212. });
  3213. });
  3214. };
  3215. for (var i = 0, ii = this.pdfViewer.pagesCount; i < ii; i++) {
  3216. _loop(i, ii);
  3217. }
  3218. }
  3219. }, {
  3220. key: 'executeCommand',
  3221. value: function executeCommand(cmd, state) {
  3222. var _this3 = this;
  3223. if (this.state === null || cmd !== 'findagain') {
  3224. this.dirtyMatch = true;
  3225. }
  3226. this.state = state;
  3227. this.updateUIState(FindState.PENDING);
  3228. this._firstPagePromise.then(function () {
  3229. _this3.extractText();
  3230. clearTimeout(_this3.findTimeout);
  3231. if (cmd === 'find') {
  3232. _this3.findTimeout = setTimeout(_this3.nextMatch.bind(_this3), FIND_TIMEOUT);
  3233. } else {
  3234. _this3.nextMatch();
  3235. }
  3236. });
  3237. }
  3238. }, {
  3239. key: 'updatePage',
  3240. value: function updatePage(index) {
  3241. if (this.selected.pageIdx === index) {
  3242. this.pdfViewer.currentPageNumber = index + 1;
  3243. }
  3244. var page = this.pdfViewer.getPageView(index);
  3245. if (page.textLayer) {
  3246. page.textLayer.updateMatches();
  3247. }
  3248. }
  3249. }, {
  3250. key: 'nextMatch',
  3251. value: function nextMatch() {
  3252. var _this4 = this;
  3253. var previous = this.state.findPrevious;
  3254. var currentPageIndex = this.pdfViewer.currentPageNumber - 1;
  3255. var numPages = this.pdfViewer.pagesCount;
  3256. this.active = true;
  3257. if (this.dirtyMatch) {
  3258. this.dirtyMatch = false;
  3259. this.selected.pageIdx = this.selected.matchIdx = -1;
  3260. this.offset.pageIdx = currentPageIndex;
  3261. this.offset.matchIdx = null;
  3262. this.hadMatch = false;
  3263. this.resumePageIdx = null;
  3264. this.pageMatches = [];
  3265. this.matchCount = 0;
  3266. this.pageMatchesLength = null;
  3267. for (var i = 0; i < numPages; i++) {
  3268. this.updatePage(i);
  3269. if (!(i in this.pendingFindMatches)) {
  3270. this.pendingFindMatches[i] = true;
  3271. this.extractTextPromises[i].then(function (pageIdx) {
  3272. delete _this4.pendingFindMatches[pageIdx];
  3273. _this4.calcFindMatch(pageIdx);
  3274. });
  3275. }
  3276. }
  3277. }
  3278. if (this.state.query === '') {
  3279. this.updateUIState(FindState.FOUND);
  3280. return;
  3281. }
  3282. if (this.resumePageIdx) {
  3283. return;
  3284. }
  3285. var offset = this.offset;
  3286. this.pagesToSearch = numPages;
  3287. if (offset.matchIdx !== null) {
  3288. var numPageMatches = this.pageMatches[offset.pageIdx].length;
  3289. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  3290. this.hadMatch = true;
  3291. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  3292. this.updateMatch(true);
  3293. return;
  3294. }
  3295. this.advanceOffsetPage(previous);
  3296. }
  3297. this.nextPageMatch();
  3298. }
  3299. }, {
  3300. key: 'matchesReady',
  3301. value: function matchesReady(matches) {
  3302. var offset = this.offset;
  3303. var numMatches = matches.length;
  3304. var previous = this.state.findPrevious;
  3305. if (numMatches) {
  3306. this.hadMatch = true;
  3307. offset.matchIdx = previous ? numMatches - 1 : 0;
  3308. this.updateMatch(true);
  3309. return true;
  3310. }
  3311. this.advanceOffsetPage(previous);
  3312. if (offset.wrapped) {
  3313. offset.matchIdx = null;
  3314. if (this.pagesToSearch < 0) {
  3315. this.updateMatch(false);
  3316. return true;
  3317. }
  3318. }
  3319. return false;
  3320. }
  3321. }, {
  3322. key: 'updateMatchPosition',
  3323. value: function updateMatchPosition(pageIndex, matchIndex, elements, beginIdx) {
  3324. if (this.selected.matchIdx === matchIndex && this.selected.pageIdx === pageIndex) {
  3325. var spot = {
  3326. top: FIND_SCROLL_OFFSET_TOP,
  3327. left: FIND_SCROLL_OFFSET_LEFT
  3328. };
  3329. (0, _ui_utils.scrollIntoView)(elements[beginIdx], spot, true);
  3330. }
  3331. }
  3332. }, {
  3333. key: 'nextPageMatch',
  3334. value: function nextPageMatch() {
  3335. if (this.resumePageIdx !== null) {
  3336. console.error('There can only be one pending page.');
  3337. }
  3338. var matches = null;
  3339. do {
  3340. var pageIdx = this.offset.pageIdx;
  3341. matches = this.pageMatches[pageIdx];
  3342. if (!matches) {
  3343. this.resumePageIdx = pageIdx;
  3344. break;
  3345. }
  3346. } while (!this.matchesReady(matches));
  3347. }
  3348. }, {
  3349. key: 'advanceOffsetPage',
  3350. value: function advanceOffsetPage(previous) {
  3351. var offset = this.offset;
  3352. var numPages = this.extractTextPromises.length;
  3353. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  3354. offset.matchIdx = null;
  3355. this.pagesToSearch--;
  3356. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  3357. offset.pageIdx = previous ? numPages - 1 : 0;
  3358. offset.wrapped = true;
  3359. }
  3360. }
  3361. }, {
  3362. key: 'updateMatch',
  3363. value: function updateMatch() {
  3364. var found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  3365. var state = FindState.NOT_FOUND;
  3366. var wrapped = this.offset.wrapped;
  3367. this.offset.wrapped = false;
  3368. if (found) {
  3369. var previousPage = this.selected.pageIdx;
  3370. this.selected.pageIdx = this.offset.pageIdx;
  3371. this.selected.matchIdx = this.offset.matchIdx;
  3372. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  3373. if (previousPage !== -1 && previousPage !== this.selected.pageIdx) {
  3374. this.updatePage(previousPage);
  3375. }
  3376. }
  3377. this.updateUIState(state, this.state.findPrevious);
  3378. if (this.selected.pageIdx !== -1) {
  3379. this.updatePage(this.selected.pageIdx);
  3380. }
  3381. }
  3382. }, {
  3383. key: 'updateUIResultsCount',
  3384. value: function updateUIResultsCount() {
  3385. if (this.onUpdateResultsCount) {
  3386. this.onUpdateResultsCount(this.matchCount);
  3387. }
  3388. }
  3389. }, {
  3390. key: 'updateUIState',
  3391. value: function updateUIState(state, previous) {
  3392. if (this.onUpdateState) {
  3393. this.onUpdateState(state, previous, this.matchCount);
  3394. }
  3395. }
  3396. }]);
  3397. return PDFFindController;
  3398. }();
  3399. exports.FindState = FindState;
  3400. exports.PDFFindController = PDFFindController;
  3401. /***/ }),
  3402. /* 8 */
  3403. /***/ (function(module, exports, __webpack_require__) {
  3404. "use strict";
  3405. var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';
  3406. ;
  3407. var pdfjsWebApp = void 0;
  3408. {
  3409. pdfjsWebApp = __webpack_require__(4);
  3410. }
  3411. ;
  3412. {
  3413. __webpack_require__(29);
  3414. }
  3415. ;
  3416. {
  3417. __webpack_require__(34);
  3418. }
  3419. function getViewerConfiguration() {
  3420. return {
  3421. appContainer: document.body,
  3422. mainContainer: document.getElementById('viewerContainer'),
  3423. viewerContainer: document.getElementById('viewer'),
  3424. eventBus: null,
  3425. toolbar: {
  3426. container: document.getElementById('toolbarViewer'),
  3427. numPages: document.getElementById('numPages'),
  3428. pageNumber: document.getElementById('pageNumber'),
  3429. scaleSelectContainer: document.getElementById('scaleSelectContainer'),
  3430. scaleSelect: document.getElementById('scaleSelect'),
  3431. customScaleOption: document.getElementById('customScaleOption'),
  3432. previous: document.getElementById('previous'),
  3433. next: document.getElementById('next'),
  3434. zoomIn: document.getElementById('zoomIn'),
  3435. zoomOut: document.getElementById('zoomOut'),
  3436. viewFind: document.getElementById('viewFind'),
  3437. openFile: document.getElementById('openFile'),
  3438. print: document.getElementById('print'),
  3439. presentationModeButton: document.getElementById('presentationMode'),
  3440. download: document.getElementById('download'),
  3441. viewBookmark: document.getElementById('viewBookmark')
  3442. },
  3443. secondaryToolbar: {
  3444. toolbar: document.getElementById('secondaryToolbar'),
  3445. toggleButton: document.getElementById('secondaryToolbarToggle'),
  3446. toolbarButtonContainer: document.getElementById('secondaryToolbarButtonContainer'),
  3447. presentationModeButton: document.getElementById('secondaryPresentationMode'),
  3448. openFileButton: document.getElementById('secondaryOpenFile'),
  3449. printButton: document.getElementById('secondaryPrint'),
  3450. downloadButton: document.getElementById('secondaryDownload'),
  3451. viewBookmarkButton: document.getElementById('secondaryViewBookmark'),
  3452. firstPageButton: document.getElementById('firstPage'),
  3453. lastPageButton: document.getElementById('lastPage'),
  3454. pageRotateCwButton: document.getElementById('pageRotateCw'),
  3455. pageRotateCcwButton: document.getElementById('pageRotateCcw'),
  3456. cursorSelectToolButton: document.getElementById('cursorSelectTool'),
  3457. cursorHandToolButton: document.getElementById('cursorHandTool'),
  3458. documentPropertiesButton: document.getElementById('documentProperties')
  3459. },
  3460. fullscreen: {
  3461. contextFirstPage: document.getElementById('contextFirstPage'),
  3462. contextLastPage: document.getElementById('contextLastPage'),
  3463. contextPageRotateCw: document.getElementById('contextPageRotateCw'),
  3464. contextPageRotateCcw: document.getElementById('contextPageRotateCcw')
  3465. },
  3466. sidebar: {
  3467. mainContainer: document.getElementById('mainContainer'),
  3468. outerContainer: document.getElementById('outerContainer'),
  3469. toggleButton: document.getElementById('sidebarToggle'),
  3470. thumbnailButton: document.getElementById('viewThumbnail'),
  3471. outlineButton: document.getElementById('viewOutline'),
  3472. attachmentsButton: document.getElementById('viewAttachments'),
  3473. thumbnailView: document.getElementById('thumbnailView'),
  3474. outlineView: document.getElementById('outlineView'),
  3475. attachmentsView: document.getElementById('attachmentsView')
  3476. },
  3477. findBar: {
  3478. bar: document.getElementById('findbar'),
  3479. toggleButton: document.getElementById('viewFind'),
  3480. findField: document.getElementById('findInput'),
  3481. highlightAllCheckbox: document.getElementById('findHighlightAll'),
  3482. caseSensitiveCheckbox: document.getElementById('findMatchCase'),
  3483. findMsg: document.getElementById('findMsg'),
  3484. findResultsCount: document.getElementById('findResultsCount'),
  3485. findStatusIcon: document.getElementById('findStatusIcon'),
  3486. findPreviousButton: document.getElementById('findPrevious'),
  3487. findNextButton: document.getElementById('findNext')
  3488. },
  3489. passwordOverlay: {
  3490. overlayName: 'passwordOverlay',
  3491. container: document.getElementById('passwordOverlay'),
  3492. label: document.getElementById('passwordText'),
  3493. input: document.getElementById('password'),
  3494. submitButton: document.getElementById('passwordSubmit'),
  3495. cancelButton: document.getElementById('passwordCancel')
  3496. },
  3497. documentProperties: {
  3498. overlayName: 'documentPropertiesOverlay',
  3499. container: document.getElementById('documentPropertiesOverlay'),
  3500. closeButton: document.getElementById('documentPropertiesClose'),
  3501. fields: {
  3502. 'fileName': document.getElementById('fileNameField'),
  3503. 'fileSize': document.getElementById('fileSizeField'),
  3504. 'title': document.getElementById('titleField'),
  3505. 'author': document.getElementById('authorField'),
  3506. 'subject': document.getElementById('subjectField'),
  3507. 'keywords': document.getElementById('keywordsField'),
  3508. 'creationDate': document.getElementById('creationDateField'),
  3509. 'modificationDate': document.getElementById('modificationDateField'),
  3510. 'creator': document.getElementById('creatorField'),
  3511. 'producer': document.getElementById('producerField'),
  3512. 'version': document.getElementById('versionField'),
  3513. 'pageCount': document.getElementById('pageCountField')
  3514. }
  3515. },
  3516. errorWrapper: {
  3517. container: document.getElementById('errorWrapper'),
  3518. errorMessage: document.getElementById('errorMessage'),
  3519. closeButton: document.getElementById('errorClose'),
  3520. errorMoreInfo: document.getElementById('errorMoreInfo'),
  3521. moreInfoButton: document.getElementById('errorShowMore'),
  3522. lessInfoButton: document.getElementById('errorShowLess')
  3523. },
  3524. printContainer: document.getElementById('printContainer'),
  3525. openFileInputName: 'fileInput',
  3526. debuggerScriptPath: './debugger.js',
  3527. defaultUrl: DEFAULT_URL
  3528. };
  3529. }
  3530. function webViewerLoad() {
  3531. var config = getViewerConfiguration();
  3532. window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
  3533. pdfjsWebApp.PDFViewerApplication.run(config);
  3534. }
  3535. if (document.readyState === 'interactive' || document.readyState === 'complete') {
  3536. webViewerLoad();
  3537. } else {
  3538. document.addEventListener('DOMContentLoaded', webViewerLoad, true);
  3539. }
  3540. /***/ }),
  3541. /* 9 */
  3542. /***/ (function(module, exports, __webpack_require__) {
  3543. "use strict";
  3544. Object.defineProperty(exports, "__esModule", {
  3545. value: true
  3546. });
  3547. function GrabToPan(options) {
  3548. this.element = options.element;
  3549. this.document = options.element.ownerDocument;
  3550. if (typeof options.ignoreTarget === 'function') {
  3551. this.ignoreTarget = options.ignoreTarget;
  3552. }
  3553. this.onActiveChanged = options.onActiveChanged;
  3554. this.activate = this.activate.bind(this);
  3555. this.deactivate = this.deactivate.bind(this);
  3556. this.toggle = this.toggle.bind(this);
  3557. this._onmousedown = this._onmousedown.bind(this);
  3558. this._onmousemove = this._onmousemove.bind(this);
  3559. this._endPan = this._endPan.bind(this);
  3560. var overlay = this.overlay = document.createElement('div');
  3561. overlay.className = 'grab-to-pan-grabbing';
  3562. }
  3563. GrabToPan.prototype = {
  3564. CSS_CLASS_GRAB: 'grab-to-pan-grab',
  3565. activate: function GrabToPan_activate() {
  3566. if (!this.active) {
  3567. this.active = true;
  3568. this.element.addEventListener('mousedown', this._onmousedown, true);
  3569. this.element.classList.add(this.CSS_CLASS_GRAB);
  3570. if (this.onActiveChanged) {
  3571. this.onActiveChanged(true);
  3572. }
  3573. }
  3574. },
  3575. deactivate: function GrabToPan_deactivate() {
  3576. if (this.active) {
  3577. this.active = false;
  3578. this.element.removeEventListener('mousedown', this._onmousedown, true);
  3579. this._endPan();
  3580. this.element.classList.remove(this.CSS_CLASS_GRAB);
  3581. if (this.onActiveChanged) {
  3582. this.onActiveChanged(false);
  3583. }
  3584. }
  3585. },
  3586. toggle: function GrabToPan_toggle() {
  3587. if (this.active) {
  3588. this.deactivate();
  3589. } else {
  3590. this.activate();
  3591. }
  3592. },
  3593. ignoreTarget: function GrabToPan_ignoreTarget(node) {
  3594. return node[matchesSelector]('a[href], a[href] *, input, textarea, button, button *, select, option');
  3595. },
  3596. _onmousedown: function GrabToPan__onmousedown(event) {
  3597. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3598. return;
  3599. }
  3600. if (event.originalTarget) {
  3601. try {
  3602. event.originalTarget.tagName;
  3603. } catch (e) {
  3604. return;
  3605. }
  3606. }
  3607. this.scrollLeftStart = this.element.scrollLeft;
  3608. this.scrollTopStart = this.element.scrollTop;
  3609. this.clientXStart = event.clientX;
  3610. this.clientYStart = event.clientY;
  3611. this.document.addEventListener('mousemove', this._onmousemove, true);
  3612. this.document.addEventListener('mouseup', this._endPan, true);
  3613. this.element.addEventListener('scroll', this._endPan, true);
  3614. event.preventDefault();
  3615. event.stopPropagation();
  3616. var focusedElement = document.activeElement;
  3617. if (focusedElement && !focusedElement.contains(event.target)) {
  3618. focusedElement.blur();
  3619. }
  3620. },
  3621. _onmousemove: function GrabToPan__onmousemove(event) {
  3622. this.element.removeEventListener('scroll', this._endPan, true);
  3623. if (isLeftMouseReleased(event)) {
  3624. this._endPan();
  3625. return;
  3626. }
  3627. var xDiff = event.clientX - this.clientXStart;
  3628. var yDiff = event.clientY - this.clientYStart;
  3629. var scrollTop = this.scrollTopStart - yDiff;
  3630. var scrollLeft = this.scrollLeftStart - xDiff;
  3631. if (this.element.scrollTo) {
  3632. this.element.scrollTo({
  3633. top: scrollTop,
  3634. left: scrollLeft,
  3635. behavior: 'instant'
  3636. });
  3637. } else {
  3638. this.element.scrollTop = scrollTop;
  3639. this.element.scrollLeft = scrollLeft;
  3640. }
  3641. if (!this.overlay.parentNode) {
  3642. document.body.appendChild(this.overlay);
  3643. }
  3644. },
  3645. _endPan: function GrabToPan__endPan() {
  3646. this.element.removeEventListener('scroll', this._endPan, true);
  3647. this.document.removeEventListener('mousemove', this._onmousemove, true);
  3648. this.document.removeEventListener('mouseup', this._endPan, true);
  3649. this.overlay.remove();
  3650. }
  3651. };
  3652. var matchesSelector;
  3653. ['webkitM', 'mozM', 'msM', 'oM', 'm'].some(function (prefix) {
  3654. var name = prefix + 'atches';
  3655. if (name in document.documentElement) {
  3656. matchesSelector = name;
  3657. }
  3658. name += 'Selector';
  3659. if (name in document.documentElement) {
  3660. matchesSelector = name;
  3661. }
  3662. return matchesSelector;
  3663. });
  3664. var isNotIEorIsIE10plus = !document.documentMode || document.documentMode > 9;
  3665. var chrome = window.chrome;
  3666. var isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  3667. var isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  3668. function isLeftMouseReleased(event) {
  3669. if ('buttons' in event && isNotIEorIsIE10plus) {
  3670. return !(event.buttons & 1);
  3671. }
  3672. if (isChrome15OrOpera15plus || isSafari6plus) {
  3673. return event.which === 0;
  3674. }
  3675. }
  3676. exports.GrabToPan = GrabToPan;
  3677. /***/ }),
  3678. /* 10 */
  3679. /***/ (function(module, exports, __webpack_require__) {
  3680. "use strict";
  3681. Object.defineProperty(exports, "__esModule", {
  3682. value: true
  3683. });
  3684. exports.PDFSidebar = exports.SidebarView = undefined;
  3685. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3686. var _ui_utils = __webpack_require__(0);
  3687. var _pdf_rendering_queue = __webpack_require__(3);
  3688. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3689. var UI_NOTIFICATION_CLASS = 'pdfSidebarNotification';
  3690. var SidebarView = {
  3691. NONE: 0,
  3692. THUMBS: 1,
  3693. OUTLINE: 2,
  3694. ATTACHMENTS: 3
  3695. };
  3696. var PDFSidebar = function () {
  3697. function PDFSidebar(options) {
  3698. var l10n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _ui_utils.NullL10n;
  3699. _classCallCheck(this, PDFSidebar);
  3700. this.isOpen = false;
  3701. this.active = SidebarView.THUMBS;
  3702. this.isInitialViewSet = false;
  3703. this.onToggled = null;
  3704. this.pdfViewer = options.pdfViewer;
  3705. this.pdfThumbnailViewer = options.pdfThumbnailViewer;
  3706. this.pdfOutlineViewer = options.pdfOutlineViewer;
  3707. this.mainContainer = options.mainContainer;
  3708. this.outerContainer = options.outerContainer;
  3709. this.eventBus = options.eventBus;
  3710. this.toggleButton = options.toggleButton;
  3711. this.thumbnailButton = options.thumbnailButton;
  3712. this.outlineButton = options.outlineButton;
  3713. this.attachmentsButton = options.attachmentsButton;
  3714. this.thumbnailView = options.thumbnailView;
  3715. this.outlineView = options.outlineView;
  3716. this.attachmentsView = options.attachmentsView;
  3717. this.disableNotification = options.disableNotification || false;
  3718. this.l10n = l10n;
  3719. this._addEventListeners();
  3720. }
  3721. _createClass(PDFSidebar, [{
  3722. key: 'reset',
  3723. value: function reset() {
  3724. this.isInitialViewSet = false;
  3725. this._hideUINotification(null);
  3726. this.switchView(SidebarView.THUMBS);
  3727. this.outlineButton.disabled = false;
  3728. this.attachmentsButton.disabled = false;
  3729. }
  3730. }, {
  3731. key: 'setInitialView',
  3732. value: function setInitialView() {
  3733. var view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SidebarView.NONE;
  3734. if (this.isInitialViewSet) {
  3735. return;
  3736. }
  3737. this.isInitialViewSet = true;
  3738. if (this.isOpen && view === SidebarView.NONE) {
  3739. this._dispatchEvent();
  3740. return;
  3741. }
  3742. var isViewPreserved = view === this.visibleView;
  3743. this.switchView(view, true);
  3744. if (isViewPreserved) {
  3745. this._dispatchEvent();
  3746. }
  3747. }
  3748. }, {
  3749. key: 'switchView',
  3750. value: function switchView(view) {
  3751. var forceOpen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  3752. if (view === SidebarView.NONE) {
  3753. this.close();
  3754. return;
  3755. }
  3756. var isViewChanged = view !== this.active;
  3757. var shouldForceRendering = false;
  3758. switch (view) {
  3759. case SidebarView.THUMBS:
  3760. this.thumbnailButton.classList.add('toggled');
  3761. this.outlineButton.classList.remove('toggled');
  3762. this.attachmentsButton.classList.remove('toggled');
  3763. this.thumbnailView.classList.remove('hidden');
  3764. this.outlineView.classList.add('hidden');
  3765. this.attachmentsView.classList.add('hidden');
  3766. if (this.isOpen && isViewChanged) {
  3767. this._updateThumbnailViewer();
  3768. shouldForceRendering = true;
  3769. }
  3770. break;
  3771. case SidebarView.OUTLINE:
  3772. if (this.outlineButton.disabled) {
  3773. return;
  3774. }
  3775. this.thumbnailButton.classList.remove('toggled');
  3776. this.outlineButton.classList.add('toggled');
  3777. this.attachmentsButton.classList.remove('toggled');
  3778. this.thumbnailView.classList.add('hidden');
  3779. this.outlineView.classList.remove('hidden');
  3780. this.attachmentsView.classList.add('hidden');
  3781. break;
  3782. case SidebarView.ATTACHMENTS:
  3783. if (this.attachmentsButton.disabled) {
  3784. return;
  3785. }
  3786. this.thumbnailButton.classList.remove('toggled');
  3787. this.outlineButton.classList.remove('toggled');
  3788. this.attachmentsButton.classList.add('toggled');
  3789. this.thumbnailView.classList.add('hidden');
  3790. this.outlineView.classList.add('hidden');
  3791. this.attachmentsView.classList.remove('hidden');
  3792. break;
  3793. default:
  3794. console.error('PDFSidebar_switchView: "' + view + '" is an unsupported value.');
  3795. return;
  3796. }
  3797. this.active = view | 0;
  3798. if (forceOpen && !this.isOpen) {
  3799. this.open();
  3800. return;
  3801. }
  3802. if (shouldForceRendering) {
  3803. this._forceRendering();
  3804. }
  3805. if (isViewChanged) {
  3806. this._dispatchEvent();
  3807. }
  3808. this._hideUINotification(this.active);
  3809. }
  3810. }, {
  3811. key: 'open',
  3812. value: function open() {
  3813. if (this.isOpen) {
  3814. return;
  3815. }
  3816. this.isOpen = true;
  3817. this.toggleButton.classList.add('toggled');
  3818. this.outerContainer.classList.add('sidebarMoving');
  3819. this.outerContainer.classList.add('sidebarOpen');
  3820. if (this.active === SidebarView.THUMBS) {
  3821. this._updateThumbnailViewer();
  3822. }
  3823. this._forceRendering();
  3824. this._dispatchEvent();
  3825. this._hideUINotification(this.active);
  3826. }
  3827. }, {
  3828. key: 'close',
  3829. value: function close() {
  3830. if (!this.isOpen) {
  3831. return;
  3832. }
  3833. this.isOpen = false;
  3834. this.toggleButton.classList.remove('toggled');
  3835. this.outerContainer.classList.add('sidebarMoving');
  3836. this.outerContainer.classList.remove('sidebarOpen');
  3837. this._forceRendering();
  3838. this._dispatchEvent();
  3839. }
  3840. }, {
  3841. key: 'toggle',
  3842. value: function toggle() {
  3843. if (this.isOpen) {
  3844. this.close();
  3845. } else {
  3846. this.open();
  3847. }
  3848. }
  3849. }, {
  3850. key: '_dispatchEvent',
  3851. value: function _dispatchEvent() {
  3852. this.eventBus.dispatch('sidebarviewchanged', {
  3853. source: this,
  3854. view: this.visibleView
  3855. });
  3856. }
  3857. }, {
  3858. key: '_forceRendering',
  3859. value: function _forceRendering() {
  3860. if (this.onToggled) {
  3861. this.onToggled();
  3862. } else {
  3863. this.pdfViewer.forceRendering();
  3864. this.pdfThumbnailViewer.forceRendering();
  3865. }
  3866. }
  3867. }, {
  3868. key: '_updateThumbnailViewer',
  3869. value: function _updateThumbnailViewer() {
  3870. var pdfViewer = this.pdfViewer,
  3871. pdfThumbnailViewer = this.pdfThumbnailViewer;
  3872. var pagesCount = pdfViewer.pagesCount;
  3873. for (var pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  3874. var pageView = pdfViewer.getPageView(pageIndex);
  3875. if (pageView && pageView.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
  3876. var thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  3877. thumbnailView.setImage(pageView);
  3878. }
  3879. }
  3880. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  3881. }
  3882. }, {
  3883. key: '_showUINotification',
  3884. value: function _showUINotification(view) {
  3885. var _this = this;
  3886. if (this.disableNotification) {
  3887. return;
  3888. }
  3889. this.l10n.get('toggle_sidebar_notification.title', null, 'Toggle Sidebar (document contains outline/attachments)').then(function (msg) {
  3890. _this.toggleButton.title = msg;
  3891. });
  3892. if (!this.isOpen) {
  3893. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  3894. } else if (view === this.active) {
  3895. return;
  3896. }
  3897. switch (view) {
  3898. case SidebarView.OUTLINE:
  3899. this.outlineButton.classList.add(UI_NOTIFICATION_CLASS);
  3900. break;
  3901. case SidebarView.ATTACHMENTS:
  3902. this.attachmentsButton.classList.add(UI_NOTIFICATION_CLASS);
  3903. break;
  3904. }
  3905. }
  3906. }, {
  3907. key: '_hideUINotification',
  3908. value: function _hideUINotification(view) {
  3909. var _this2 = this;
  3910. if (this.disableNotification) {
  3911. return;
  3912. }
  3913. var removeNotification = function removeNotification(view) {
  3914. switch (view) {
  3915. case SidebarView.OUTLINE:
  3916. _this2.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
  3917. break;
  3918. case SidebarView.ATTACHMENTS:
  3919. _this2.attachmentsButton.classList.remove(UI_NOTIFICATION_CLASS);
  3920. break;
  3921. }
  3922. };
  3923. if (!this.isOpen && view !== null) {
  3924. return;
  3925. }
  3926. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  3927. if (view !== null) {
  3928. removeNotification(view);
  3929. return;
  3930. }
  3931. for (view in SidebarView) {
  3932. removeNotification(SidebarView[view]);
  3933. }
  3934. this.l10n.get('toggle_sidebar.title', null, 'Toggle Sidebar').then(function (msg) {
  3935. _this2.toggleButton.title = msg;
  3936. });
  3937. }
  3938. }, {
  3939. key: '_addEventListeners',
  3940. value: function _addEventListeners() {
  3941. var _this3 = this;
  3942. this.mainContainer.addEventListener('transitionend', function (evt) {
  3943. if (evt.target === _this3.mainContainer) {
  3944. _this3.outerContainer.classList.remove('sidebarMoving');
  3945. }
  3946. });
  3947. this.thumbnailButton.addEventListener('click', function () {
  3948. _this3.switchView(SidebarView.THUMBS);
  3949. });
  3950. this.outlineButton.addEventListener('click', function () {
  3951. _this3.switchView(SidebarView.OUTLINE);
  3952. });
  3953. this.outlineButton.addEventListener('dblclick', function () {
  3954. _this3.pdfOutlineViewer.toggleOutlineTree();
  3955. });
  3956. this.attachmentsButton.addEventListener('click', function () {
  3957. _this3.switchView(SidebarView.ATTACHMENTS);
  3958. });
  3959. this.eventBus.on('outlineloaded', function (evt) {
  3960. var outlineCount = evt.outlineCount;
  3961. _this3.outlineButton.disabled = !outlineCount;
  3962. if (outlineCount) {
  3963. _this3._showUINotification(SidebarView.OUTLINE);
  3964. } else if (_this3.active === SidebarView.OUTLINE) {
  3965. _this3.switchView(SidebarView.THUMBS);
  3966. }
  3967. });
  3968. this.eventBus.on('attachmentsloaded', function (evt) {
  3969. if (evt.attachmentsCount) {
  3970. _this3.attachmentsButton.disabled = false;
  3971. _this3._showUINotification(SidebarView.ATTACHMENTS);
  3972. return;
  3973. }
  3974. Promise.resolve().then(function () {
  3975. if (_this3.attachmentsView.hasChildNodes()) {
  3976. return;
  3977. }
  3978. _this3.attachmentsButton.disabled = true;
  3979. if (_this3.active === SidebarView.ATTACHMENTS) {
  3980. _this3.switchView(SidebarView.THUMBS);
  3981. }
  3982. });
  3983. });
  3984. this.eventBus.on('presentationmodechanged', function (evt) {
  3985. if (!evt.active && !evt.switchInProgress && _this3.isThumbnailViewVisible) {
  3986. _this3._updateThumbnailViewer();
  3987. }
  3988. });
  3989. }
  3990. }, {
  3991. key: 'visibleView',
  3992. get: function get() {
  3993. return this.isOpen ? this.active : SidebarView.NONE;
  3994. }
  3995. }, {
  3996. key: 'isThumbnailViewVisible',
  3997. get: function get() {
  3998. return this.isOpen && this.active === SidebarView.THUMBS;
  3999. }
  4000. }, {
  4001. key: 'isOutlineViewVisible',
  4002. get: function get() {
  4003. return this.isOpen && this.active === SidebarView.OUTLINE;
  4004. }
  4005. }, {
  4006. key: 'isAttachmentsViewVisible',
  4007. get: function get() {
  4008. return this.isOpen && this.active === SidebarView.ATTACHMENTS;
  4009. }
  4010. }]);
  4011. return PDFSidebar;
  4012. }();
  4013. exports.SidebarView = SidebarView;
  4014. exports.PDFSidebar = PDFSidebar;
  4015. /***/ }),
  4016. /* 11 */
  4017. /***/ (function(module, exports, __webpack_require__) {
  4018. "use strict";
  4019. Object.defineProperty(exports, "__esModule", {
  4020. value: true
  4021. });
  4022. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4023. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4024. var OverlayManager = function () {
  4025. function OverlayManager() {
  4026. _classCallCheck(this, OverlayManager);
  4027. this._overlays = {};
  4028. this._active = null;
  4029. this._keyDownBound = this._keyDown.bind(this);
  4030. }
  4031. _createClass(OverlayManager, [{
  4032. key: 'register',
  4033. value: function register(name, element) {
  4034. var _this = this;
  4035. var callerCloseMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  4036. var canForceClose = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  4037. return new Promise(function (resolve) {
  4038. var container = void 0;
  4039. if (!name || !element || !(container = element.parentNode)) {
  4040. throw new Error('Not enough parameters.');
  4041. } else if (_this._overlays[name]) {
  4042. throw new Error('The overlay is already registered.');
  4043. }
  4044. _this._overlays[name] = {
  4045. element: element,
  4046. container: container,
  4047. callerCloseMethod: callerCloseMethod,
  4048. canForceClose: canForceClose
  4049. };
  4050. resolve();
  4051. });
  4052. }
  4053. }, {
  4054. key: 'unregister',
  4055. value: function unregister(name) {
  4056. var _this2 = this;
  4057. return new Promise(function (resolve) {
  4058. if (!_this2._overlays[name]) {
  4059. throw new Error('The overlay does not exist.');
  4060. } else if (_this2._active === name) {
  4061. throw new Error('The overlay cannot be removed while it is active.');
  4062. }
  4063. delete _this2._overlays[name];
  4064. resolve();
  4065. });
  4066. }
  4067. }, {
  4068. key: 'open',
  4069. value: function open(name) {
  4070. var _this3 = this;
  4071. return new Promise(function (resolve) {
  4072. if (!_this3._overlays[name]) {
  4073. throw new Error('The overlay does not exist.');
  4074. } else if (_this3._active) {
  4075. if (_this3._overlays[name].canForceClose) {
  4076. _this3._closeThroughCaller();
  4077. } else if (_this3._active === name) {
  4078. throw new Error('The overlay is already active.');
  4079. } else {
  4080. throw new Error('Another overlay is currently active.');
  4081. }
  4082. }
  4083. _this3._active = name;
  4084. _this3._overlays[_this3._active].element.classList.remove('hidden');
  4085. _this3._overlays[_this3._active].container.classList.remove('hidden');
  4086. window.addEventListener('keydown', _this3._keyDownBound);
  4087. resolve();
  4088. });
  4089. }
  4090. }, {
  4091. key: 'close',
  4092. value: function close(name) {
  4093. var _this4 = this;
  4094. return new Promise(function (resolve) {
  4095. if (!_this4._overlays[name]) {
  4096. throw new Error('The overlay does not exist.');
  4097. } else if (!_this4._active) {
  4098. throw new Error('The overlay is currently not active.');
  4099. } else if (_this4._active !== name) {
  4100. throw new Error('Another overlay is currently active.');
  4101. }
  4102. _this4._overlays[_this4._active].container.classList.add('hidden');
  4103. _this4._overlays[_this4._active].element.classList.add('hidden');
  4104. _this4._active = null;
  4105. window.removeEventListener('keydown', _this4._keyDownBound);
  4106. resolve();
  4107. });
  4108. }
  4109. }, {
  4110. key: '_keyDown',
  4111. value: function _keyDown(evt) {
  4112. if (this._active && evt.keyCode === 27) {
  4113. this._closeThroughCaller();
  4114. evt.preventDefault();
  4115. }
  4116. }
  4117. }, {
  4118. key: '_closeThroughCaller',
  4119. value: function _closeThroughCaller() {
  4120. if (this._overlays[this._active].callerCloseMethod) {
  4121. this._overlays[this._active].callerCloseMethod();
  4122. }
  4123. if (this._active) {
  4124. this.close(this._active);
  4125. }
  4126. }
  4127. }, {
  4128. key: 'active',
  4129. get: function get() {
  4130. return this._active;
  4131. }
  4132. }]);
  4133. return OverlayManager;
  4134. }();
  4135. exports.OverlayManager = OverlayManager;
  4136. /***/ }),
  4137. /* 12 */
  4138. /***/ (function(module, exports, __webpack_require__) {
  4139. "use strict";
  4140. Object.defineProperty(exports, "__esModule", {
  4141. value: true
  4142. });
  4143. exports.PasswordPrompt = undefined;
  4144. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4145. var _ui_utils = __webpack_require__(0);
  4146. var _pdfjsLib = __webpack_require__(1);
  4147. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4148. var PasswordPrompt = function () {
  4149. function PasswordPrompt(options, overlayManager) {
  4150. var _this = this;
  4151. var l10n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ui_utils.NullL10n;
  4152. _classCallCheck(this, PasswordPrompt);
  4153. this.overlayName = options.overlayName;
  4154. this.container = options.container;
  4155. this.label = options.label;
  4156. this.input = options.input;
  4157. this.submitButton = options.submitButton;
  4158. this.cancelButton = options.cancelButton;
  4159. this.overlayManager = overlayManager;
  4160. this.l10n = l10n;
  4161. this.updateCallback = null;
  4162. this.reason = null;
  4163. this.submitButton.addEventListener('click', this.verify.bind(this));
  4164. this.cancelButton.addEventListener('click', this.close.bind(this));
  4165. this.input.addEventListener('keydown', function (e) {
  4166. if (e.keyCode === 13) {
  4167. _this.verify();
  4168. }
  4169. });
  4170. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  4171. }
  4172. _createClass(PasswordPrompt, [{
  4173. key: 'open',
  4174. value: function open() {
  4175. var _this2 = this;
  4176. this.overlayManager.open(this.overlayName).then(function () {
  4177. _this2.input.focus();
  4178. var promptString = void 0;
  4179. if (_this2.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
  4180. promptString = _this2.l10n.get('password_invalid', null, 'Invalid password. Please try again.');
  4181. } else {
  4182. promptString = _this2.l10n.get('password_label', null, 'Enter the password to open this PDF file.');
  4183. }
  4184. promptString.then(function (msg) {
  4185. _this2.label.textContent = msg;
  4186. });
  4187. });
  4188. }
  4189. }, {
  4190. key: 'close',
  4191. value: function close() {
  4192. var _this3 = this;
  4193. this.overlayManager.close(this.overlayName).then(function () {
  4194. _this3.input.value = '';
  4195. });
  4196. }
  4197. }, {
  4198. key: 'verify',
  4199. value: function verify() {
  4200. var password = this.input.value;
  4201. if (password && password.length > 0) {
  4202. this.close();
  4203. return this.updateCallback(password);
  4204. }
  4205. }
  4206. }, {
  4207. key: 'setUpdateCallback',
  4208. value: function setUpdateCallback(updateCallback, reason) {
  4209. this.updateCallback = updateCallback;
  4210. this.reason = reason;
  4211. }
  4212. }]);
  4213. return PasswordPrompt;
  4214. }();
  4215. exports.PasswordPrompt = PasswordPrompt;
  4216. /***/ }),
  4217. /* 13 */
  4218. /***/ (function(module, exports, __webpack_require__) {
  4219. "use strict";
  4220. Object.defineProperty(exports, "__esModule", {
  4221. value: true
  4222. });
  4223. exports.PDFAttachmentViewer = undefined;
  4224. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4225. var _pdfjsLib = __webpack_require__(1);
  4226. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4227. var PDFAttachmentViewer = function () {
  4228. function PDFAttachmentViewer(_ref) {
  4229. var container = _ref.container,
  4230. eventBus = _ref.eventBus,
  4231. downloadManager = _ref.downloadManager;
  4232. _classCallCheck(this, PDFAttachmentViewer);
  4233. this.container = container;
  4234. this.eventBus = eventBus;
  4235. this.downloadManager = downloadManager;
  4236. this.reset();
  4237. this.eventBus.on('fileattachmentannotation', this._appendAttachment.bind(this));
  4238. }
  4239. _createClass(PDFAttachmentViewer, [{
  4240. key: 'reset',
  4241. value: function reset() {
  4242. var keepRenderedCapability = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  4243. this.attachments = null;
  4244. this.container.textContent = '';
  4245. if (!keepRenderedCapability) {
  4246. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4247. }
  4248. }
  4249. }, {
  4250. key: '_dispatchEvent',
  4251. value: function _dispatchEvent(attachmentsCount) {
  4252. this._renderedCapability.resolve();
  4253. this.eventBus.dispatch('attachmentsloaded', {
  4254. source: this,
  4255. attachmentsCount: attachmentsCount
  4256. });
  4257. }
  4258. }, {
  4259. key: '_bindPdfLink',
  4260. value: function _bindPdfLink(button, content, filename) {
  4261. if (_pdfjsLib.PDFJS.disableCreateObjectURL) {
  4262. throw new Error('bindPdfLink: ' + 'Unsupported "PDFJS.disableCreateObjectURL" value.');
  4263. }
  4264. var blobUrl = void 0;
  4265. button.onclick = function () {
  4266. if (!blobUrl) {
  4267. blobUrl = (0, _pdfjsLib.createObjectURL)(content, 'application/pdf');
  4268. }
  4269. var viewerUrl = void 0;
  4270. viewerUrl = '?file=' + encodeURIComponent(blobUrl + '#' + filename);
  4271. window.open(viewerUrl);
  4272. return false;
  4273. };
  4274. }
  4275. }, {
  4276. key: '_bindLink',
  4277. value: function _bindLink(button, content, filename) {
  4278. var _this = this;
  4279. button.onclick = function () {
  4280. _this.downloadManager.downloadData(content, filename, '');
  4281. return false;
  4282. };
  4283. }
  4284. }, {
  4285. key: 'render',
  4286. value: function render(_ref2) {
  4287. var attachments = _ref2.attachments,
  4288. _ref2$keepRenderedCap = _ref2.keepRenderedCapability,
  4289. keepRenderedCapability = _ref2$keepRenderedCap === undefined ? false : _ref2$keepRenderedCap;
  4290. var attachmentsCount = 0;
  4291. if (this.attachments) {
  4292. this.reset(keepRenderedCapability === true);
  4293. }
  4294. this.attachments = attachments || null;
  4295. if (!attachments) {
  4296. this._dispatchEvent(attachmentsCount);
  4297. return;
  4298. }
  4299. var names = Object.keys(attachments).sort(function (a, b) {
  4300. return a.toLowerCase().localeCompare(b.toLowerCase());
  4301. });
  4302. attachmentsCount = names.length;
  4303. for (var i = 0; i < attachmentsCount; i++) {
  4304. var item = attachments[names[i]];
  4305. var filename = (0, _pdfjsLib.removeNullCharacters)((0, _pdfjsLib.getFilenameFromUrl)(item.filename));
  4306. var div = document.createElement('div');
  4307. div.className = 'attachmentsItem';
  4308. var button = document.createElement('button');
  4309. button.textContent = filename;
  4310. if (/\.pdf$/i.test(filename) && !_pdfjsLib.PDFJS.disableCreateObjectURL) {
  4311. this._bindPdfLink(button, item.content, filename);
  4312. } else {
  4313. this._bindLink(button, item.content, filename);
  4314. }
  4315. div.appendChild(button);
  4316. this.container.appendChild(div);
  4317. }
  4318. this._dispatchEvent(attachmentsCount);
  4319. }
  4320. }, {
  4321. key: '_appendAttachment',
  4322. value: function _appendAttachment(_ref3) {
  4323. var _this2 = this;
  4324. var id = _ref3.id,
  4325. filename = _ref3.filename,
  4326. content = _ref3.content;
  4327. this._renderedCapability.promise.then(function () {
  4328. var attachments = _this2.attachments;
  4329. if (!attachments) {
  4330. attachments = Object.create(null);
  4331. } else {
  4332. for (var name in attachments) {
  4333. if (id === name) {
  4334. return;
  4335. }
  4336. }
  4337. }
  4338. attachments[id] = {
  4339. filename: filename,
  4340. content: content
  4341. };
  4342. _this2.render({
  4343. attachments: attachments,
  4344. keepRenderedCapability: true
  4345. });
  4346. });
  4347. }
  4348. }]);
  4349. return PDFAttachmentViewer;
  4350. }();
  4351. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4352. /***/ }),
  4353. /* 14 */
  4354. /***/ (function(module, exports, __webpack_require__) {
  4355. "use strict";
  4356. Object.defineProperty(exports, "__esModule", {
  4357. value: true
  4358. });
  4359. exports.PDFDocumentProperties = undefined;
  4360. var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
  4361. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4362. var _ui_utils = __webpack_require__(0);
  4363. var _pdfjsLib = __webpack_require__(1);
  4364. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4365. var DEFAULT_FIELD_CONTENT = '-';
  4366. var PDFDocumentProperties = function () {
  4367. function PDFDocumentProperties(_ref, overlayManager) {
  4368. var overlayName = _ref.overlayName,
  4369. fields = _ref.fields,
  4370. container = _ref.container,
  4371. closeButton = _ref.closeButton;
  4372. var l10n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ui_utils.NullL10n;
  4373. _classCallCheck(this, PDFDocumentProperties);
  4374. this.overlayName = overlayName;
  4375. this.fields = fields;
  4376. this.container = container;
  4377. this.overlayManager = overlayManager;
  4378. this.l10n = l10n;
  4379. this._reset();
  4380. if (closeButton) {
  4381. closeButton.addEventListener('click', this.close.bind(this));
  4382. }
  4383. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  4384. }
  4385. _createClass(PDFDocumentProperties, [{
  4386. key: 'open',
  4387. value: function open() {
  4388. var _this = this;
  4389. var freezeFieldData = function freezeFieldData(data) {
  4390. Object.defineProperty(_this, 'fieldData', {
  4391. value: Object.freeze(data),
  4392. writable: false,
  4393. enumerable: true,
  4394. configurable: true
  4395. });
  4396. };
  4397. Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(function () {
  4398. if (_this.fieldData) {
  4399. _this._updateUI();
  4400. return;
  4401. }
  4402. _this.pdfDocument.getMetadata().then(function (_ref2) {
  4403. var info = _ref2.info,
  4404. metadata = _ref2.metadata;
  4405. return Promise.all([info, metadata, _this._parseFileSize(_this.maybeFileSize), _this._parseDate(info.CreationDate), _this._parseDate(info.ModDate)]);
  4406. }).then(function (_ref3) {
  4407. var _ref4 = _slicedToArray(_ref3, 5),
  4408. info = _ref4[0],
  4409. metadata = _ref4[1],
  4410. fileSize = _ref4[2],
  4411. creationDate = _ref4[3],
  4412. modificationDate = _ref4[4];
  4413. freezeFieldData({
  4414. 'fileName': (0, _ui_utils.getPDFFileNameFromURL)(_this.url),
  4415. 'fileSize': fileSize,
  4416. 'title': info.Title,
  4417. 'author': info.Author,
  4418. 'subject': info.Subject,
  4419. 'keywords': info.Keywords,
  4420. 'creationDate': creationDate,
  4421. 'modificationDate': modificationDate,
  4422. 'creator': info.Creator,
  4423. 'producer': info.Producer,
  4424. 'version': info.PDFFormatVersion,
  4425. 'pageCount': _this.pdfDocument.numPages
  4426. });
  4427. _this._updateUI();
  4428. return _this.pdfDocument.getDownloadInfo();
  4429. }).then(function (_ref5) {
  4430. var length = _ref5.length;
  4431. return _this._parseFileSize(length);
  4432. }).then(function (fileSize) {
  4433. var data = (0, _ui_utils.cloneObj)(_this.fieldData);
  4434. data['fileSize'] = fileSize;
  4435. freezeFieldData(data);
  4436. _this._updateUI();
  4437. });
  4438. });
  4439. }
  4440. }, {
  4441. key: 'close',
  4442. value: function close() {
  4443. this.overlayManager.close(this.overlayName);
  4444. }
  4445. }, {
  4446. key: 'setDocument',
  4447. value: function setDocument(pdfDocument, url) {
  4448. if (this.pdfDocument) {
  4449. this._reset();
  4450. this._updateUI(true);
  4451. }
  4452. if (!pdfDocument) {
  4453. return;
  4454. }
  4455. this.pdfDocument = pdfDocument;
  4456. this.url = url;
  4457. this._dataAvailableCapability.resolve();
  4458. }
  4459. }, {
  4460. key: 'setFileSize',
  4461. value: function setFileSize(fileSize) {
  4462. if (typeof fileSize === 'number' && fileSize > 0) {
  4463. this.maybeFileSize = fileSize;
  4464. }
  4465. }
  4466. }, {
  4467. key: '_reset',
  4468. value: function _reset() {
  4469. this.pdfDocument = null;
  4470. this.url = null;
  4471. this.maybeFileSize = 0;
  4472. delete this.fieldData;
  4473. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4474. }
  4475. }, {
  4476. key: '_updateUI',
  4477. value: function _updateUI() {
  4478. var reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  4479. if (reset || !this.fieldData) {
  4480. for (var id in this.fields) {
  4481. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4482. }
  4483. return;
  4484. }
  4485. if (this.overlayManager.active !== this.overlayName) {
  4486. return;
  4487. }
  4488. for (var _id in this.fields) {
  4489. var content = this.fieldData[_id];
  4490. this.fields[_id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4491. }
  4492. }
  4493. }, {
  4494. key: '_parseFileSize',
  4495. value: function _parseFileSize() {
  4496. var fileSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  4497. var kb = fileSize / 1024;
  4498. if (!kb) {
  4499. return Promise.resolve(undefined);
  4500. } else if (kb < 1024) {
  4501. return this.l10n.get('document_properties_kb', {
  4502. size_kb: (+kb.toPrecision(3)).toLocaleString(),
  4503. size_b: fileSize.toLocaleString()
  4504. }, '{{size_kb}} KB ({{size_b}} bytes)');
  4505. }
  4506. return this.l10n.get('document_properties_mb', {
  4507. size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
  4508. size_b: fileSize.toLocaleString()
  4509. }, '{{size_mb}} MB ({{size_b}} bytes)');
  4510. }
  4511. }, {
  4512. key: '_parseDate',
  4513. value: function _parseDate(inputDate) {
  4514. if (!inputDate) {
  4515. return;
  4516. }
  4517. var dateToParse = inputDate;
  4518. if (dateToParse.substring(0, 2) === 'D:') {
  4519. dateToParse = dateToParse.substring(2);
  4520. }
  4521. var year = parseInt(dateToParse.substring(0, 4), 10);
  4522. var month = parseInt(dateToParse.substring(4, 6), 10) - 1;
  4523. var day = parseInt(dateToParse.substring(6, 8), 10);
  4524. var hours = parseInt(dateToParse.substring(8, 10), 10);
  4525. var minutes = parseInt(dateToParse.substring(10, 12), 10);
  4526. var seconds = parseInt(dateToParse.substring(12, 14), 10);
  4527. var utRel = dateToParse.substring(14, 15);
  4528. var offsetHours = parseInt(dateToParse.substring(15, 17), 10);
  4529. var offsetMinutes = parseInt(dateToParse.substring(18, 20), 10);
  4530. if (utRel === '-') {
  4531. hours += offsetHours;
  4532. minutes += offsetMinutes;
  4533. } else if (utRel === '+') {
  4534. hours -= offsetHours;
  4535. minutes -= offsetMinutes;
  4536. }
  4537. var date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
  4538. var dateString = date.toLocaleDateString();
  4539. var timeString = date.toLocaleTimeString();
  4540. return this.l10n.get('document_properties_date_string', {
  4541. date: dateString,
  4542. time: timeString
  4543. }, '{{date}}, {{time}}');
  4544. }
  4545. }]);
  4546. return PDFDocumentProperties;
  4547. }();
  4548. exports.PDFDocumentProperties = PDFDocumentProperties;
  4549. /***/ }),
  4550. /* 15 */
  4551. /***/ (function(module, exports, __webpack_require__) {
  4552. "use strict";
  4553. Object.defineProperty(exports, "__esModule", {
  4554. value: true
  4555. });
  4556. exports.PDFFindBar = undefined;
  4557. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4558. var _pdf_find_controller = __webpack_require__(7);
  4559. var _ui_utils = __webpack_require__(0);
  4560. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4561. var PDFFindBar = function () {
  4562. function PDFFindBar(options) {
  4563. var _this = this;
  4564. var l10n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _ui_utils.NullL10n;
  4565. _classCallCheck(this, PDFFindBar);
  4566. this.opened = false;
  4567. this.bar = options.bar || null;
  4568. this.toggleButton = options.toggleButton || null;
  4569. this.findField = options.findField || null;
  4570. this.highlightAll = options.highlightAllCheckbox || null;
  4571. this.caseSensitive = options.caseSensitiveCheckbox || null;
  4572. this.findMsg = options.findMsg || null;
  4573. this.findResultsCount = options.findResultsCount || null;
  4574. this.findStatusIcon = options.findStatusIcon || null;
  4575. this.findPreviousButton = options.findPreviousButton || null;
  4576. this.findNextButton = options.findNextButton || null;
  4577. this.findController = options.findController || null;
  4578. this.eventBus = options.eventBus;
  4579. this.l10n = l10n;
  4580. if (this.findController === null) {
  4581. throw new Error('PDFFindBar cannot be used without a ' + 'PDFFindController instance.');
  4582. }
  4583. this.toggleButton.addEventListener('click', function () {
  4584. _this.toggle();
  4585. });
  4586. this.findField.addEventListener('input', function () {
  4587. _this.dispatchEvent('');
  4588. });
  4589. this.bar.addEventListener('keydown', function (e) {
  4590. switch (e.keyCode) {
  4591. case 13:
  4592. if (e.target === _this.findField) {
  4593. _this.dispatchEvent('again', e.shiftKey);
  4594. }
  4595. break;
  4596. case 27:
  4597. _this.close();
  4598. break;
  4599. }
  4600. });
  4601. this.findPreviousButton.addEventListener('click', function () {
  4602. _this.dispatchEvent('again', true);
  4603. });
  4604. this.findNextButton.addEventListener('click', function () {
  4605. _this.dispatchEvent('again', false);
  4606. });
  4607. this.highlightAll.addEventListener('click', function () {
  4608. _this.dispatchEvent('highlightallchange');
  4609. });
  4610. this.caseSensitive.addEventListener('click', function () {
  4611. _this.dispatchEvent('casesensitivitychange');
  4612. });
  4613. this.eventBus.on('resize', this._adjustWidth.bind(this));
  4614. }
  4615. _createClass(PDFFindBar, [{
  4616. key: 'reset',
  4617. value: function reset() {
  4618. this.updateUIState();
  4619. }
  4620. }, {
  4621. key: 'dispatchEvent',
  4622. value: function dispatchEvent(type, findPrev) {
  4623. this.eventBus.dispatch('find', {
  4624. source: this,
  4625. type: type,
  4626. query: this.findField.value,
  4627. caseSensitive: this.caseSensitive.checked,
  4628. phraseSearch: true,
  4629. highlightAll: this.highlightAll.checked,
  4630. findPrevious: findPrev
  4631. });
  4632. }
  4633. }, {
  4634. key: 'updateUIState',
  4635. value: function updateUIState(state, previous, matchCount) {
  4636. var _this2 = this;
  4637. var notFound = false;
  4638. var findMsg = '';
  4639. var status = '';
  4640. switch (state) {
  4641. case _pdf_find_controller.FindState.FOUND:
  4642. break;
  4643. case _pdf_find_controller.FindState.PENDING:
  4644. status = 'pending';
  4645. break;
  4646. case _pdf_find_controller.FindState.NOT_FOUND:
  4647. findMsg = this.l10n.get('find_not_found', null, 'Phrase not found');
  4648. notFound = true;
  4649. break;
  4650. case _pdf_find_controller.FindState.WRAPPED:
  4651. if (previous) {
  4652. findMsg = this.l10n.get('find_reached_top', null, 'Reached top of document, continued from bottom');
  4653. } else {
  4654. findMsg = this.l10n.get('find_reached_bottom', null, 'Reached end of document, continued from top');
  4655. }
  4656. break;
  4657. }
  4658. if (notFound) {
  4659. this.findField.classList.add('notFound');
  4660. } else {
  4661. this.findField.classList.remove('notFound');
  4662. }
  4663. this.findField.setAttribute('data-status', status);
  4664. Promise.resolve(findMsg).then(function (msg) {
  4665. _this2.findMsg.textContent = msg;
  4666. _this2._adjustWidth();
  4667. });
  4668. this.updateResultsCount(matchCount);
  4669. }
  4670. }, {
  4671. key: 'updateResultsCount',
  4672. value: function updateResultsCount(matchCount) {
  4673. if (!this.findResultsCount) {
  4674. return;
  4675. }
  4676. if (!matchCount) {
  4677. this.findResultsCount.classList.add('hidden');
  4678. this.findResultsCount.textContent = '';
  4679. } else {
  4680. this.findResultsCount.textContent = matchCount.toLocaleString();
  4681. this.findResultsCount.classList.remove('hidden');
  4682. }
  4683. this._adjustWidth();
  4684. }
  4685. }, {
  4686. key: 'open',
  4687. value: function open() {
  4688. if (!this.opened) {
  4689. this.opened = true;
  4690. this.toggleButton.classList.add('toggled');
  4691. this.bar.classList.remove('hidden');
  4692. }
  4693. this.findField.select();
  4694. this.findField.focus();
  4695. this._adjustWidth();
  4696. }
  4697. }, {
  4698. key: 'close',
  4699. value: function close() {
  4700. if (!this.opened) {
  4701. return;
  4702. }
  4703. this.opened = false;
  4704. this.toggleButton.classList.remove('toggled');
  4705. this.bar.classList.add('hidden');
  4706. this.findController.active = false;
  4707. }
  4708. }, {
  4709. key: 'toggle',
  4710. value: function toggle() {
  4711. if (this.opened) {
  4712. this.close();
  4713. } else {
  4714. this.open();
  4715. }
  4716. }
  4717. }, {
  4718. key: '_adjustWidth',
  4719. value: function _adjustWidth() {
  4720. if (!this.opened) {
  4721. return;
  4722. }
  4723. this.bar.classList.remove('wrapContainers');
  4724. var findbarHeight = this.bar.clientHeight;
  4725. var inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4726. if (findbarHeight > inputContainerHeight) {
  4727. this.bar.classList.add('wrapContainers');
  4728. }
  4729. }
  4730. }]);
  4731. return PDFFindBar;
  4732. }();
  4733. exports.PDFFindBar = PDFFindBar;
  4734. /***/ }),
  4735. /* 16 */
  4736. /***/ (function(module, exports, __webpack_require__) {
  4737. "use strict";
  4738. Object.defineProperty(exports, "__esModule", {
  4739. value: true
  4740. });
  4741. exports.isDestArraysEqual = exports.isDestHashesEqual = exports.PDFHistory = undefined;
  4742. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  4743. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4744. var _ui_utils = __webpack_require__(0);
  4745. var _dom_events = __webpack_require__(2);
  4746. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4747. var HASH_CHANGE_TIMEOUT = 1000;
  4748. var POSITION_UPDATED_THRESHOLD = 50;
  4749. var UPDATE_VIEWAREA_TIMEOUT = 1000;
  4750. function getCurrentHash() {
  4751. return document.location.hash;
  4752. }
  4753. function parseCurrentHash(linkService) {
  4754. var hash = unescape(getCurrentHash()).substring(1);
  4755. var params = (0, _ui_utils.parseQueryString)(hash);
  4756. var page = params.page | 0;
  4757. if (!(Number.isInteger(page) && page > 0 && page <= linkService.pagesCount)) {
  4758. page = null;
  4759. }
  4760. return {
  4761. hash: hash,
  4762. page: page,
  4763. rotation: linkService.rotation
  4764. };
  4765. }
  4766. var PDFHistory = function () {
  4767. function PDFHistory(_ref) {
  4768. var _this = this;
  4769. var linkService = _ref.linkService,
  4770. eventBus = _ref.eventBus;
  4771. _classCallCheck(this, PDFHistory);
  4772. this.linkService = linkService;
  4773. this.eventBus = eventBus || (0, _dom_events.getGlobalEventBus)();
  4774. this.initialized = false;
  4775. this.initialBookmark = null;
  4776. this.initialRotation = null;
  4777. this._boundEvents = Object.create(null);
  4778. this._isViewerInPresentationMode = false;
  4779. this._isPagesLoaded = false;
  4780. this.eventBus.on('presentationmodechanged', function (evt) {
  4781. _this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
  4782. });
  4783. this.eventBus.on('pagesloaded', function (evt) {
  4784. _this._isPagesLoaded = !!evt.pagesCount;
  4785. });
  4786. }
  4787. _createClass(PDFHistory, [{
  4788. key: 'initialize',
  4789. value: function initialize(fingerprint) {
  4790. var resetHistory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  4791. if (!fingerprint || typeof fingerprint !== 'string') {
  4792. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  4793. return;
  4794. }
  4795. var reInitialized = this.initialized && this.fingerprint !== fingerprint;
  4796. this.fingerprint = fingerprint;
  4797. if (!this.initialized) {
  4798. this._bindEvents();
  4799. }
  4800. var state = window.history.state;
  4801. this.initialized = true;
  4802. this.initialBookmark = null;
  4803. this.initialRotation = null;
  4804. this._popStateInProgress = false;
  4805. this._blockHashChange = 0;
  4806. this._currentHash = getCurrentHash();
  4807. this._numPositionUpdates = 0;
  4808. this._uid = this._maxUid = 0;
  4809. this._destination = null;
  4810. this._position = null;
  4811. if (!this._isValidState(state) || resetHistory) {
  4812. var _parseCurrentHash = parseCurrentHash(this.linkService),
  4813. hash = _parseCurrentHash.hash,
  4814. page = _parseCurrentHash.page,
  4815. rotation = _parseCurrentHash.rotation;
  4816. if (!hash || reInitialized || resetHistory) {
  4817. this._pushOrReplaceState(null, true);
  4818. return;
  4819. }
  4820. this._pushOrReplaceState({
  4821. hash: hash,
  4822. page: page,
  4823. rotation: rotation
  4824. }, true);
  4825. return;
  4826. }
  4827. var destination = state.destination;
  4828. this._updateInternalState(destination, state.uid, true);
  4829. if (destination.rotation !== undefined) {
  4830. this.initialRotation = destination.rotation;
  4831. }
  4832. if (destination.dest) {
  4833. this.initialBookmark = JSON.stringify(destination.dest);
  4834. this._destination.page = null;
  4835. } else if (destination.hash) {
  4836. this.initialBookmark = destination.hash;
  4837. } else if (destination.page) {
  4838. this.initialBookmark = 'page=' + destination.page;
  4839. }
  4840. }
  4841. }, {
  4842. key: 'push',
  4843. value: function push(_ref2) {
  4844. var _this2 = this;
  4845. var namedDest = _ref2.namedDest,
  4846. explicitDest = _ref2.explicitDest,
  4847. pageNumber = _ref2.pageNumber;
  4848. if (!this.initialized) {
  4849. return;
  4850. }
  4851. if (namedDest && typeof namedDest !== 'string' || !(explicitDest instanceof Array) || !(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
  4852. console.error('PDFHistory.push: Invalid parameters.');
  4853. return;
  4854. }
  4855. var hash = namedDest || JSON.stringify(explicitDest);
  4856. if (!hash) {
  4857. return;
  4858. }
  4859. var forceReplace = false;
  4860. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  4861. if (this._destination.page) {
  4862. return;
  4863. }
  4864. forceReplace = true;
  4865. }
  4866. if (this._popStateInProgress && !forceReplace) {
  4867. return;
  4868. }
  4869. this._pushOrReplaceState({
  4870. dest: explicitDest,
  4871. hash: hash,
  4872. page: pageNumber,
  4873. rotation: this.linkService.rotation
  4874. }, forceReplace);
  4875. if (!this._popStateInProgress) {
  4876. this._popStateInProgress = true;
  4877. Promise.resolve().then(function () {
  4878. _this2._popStateInProgress = false;
  4879. });
  4880. }
  4881. }
  4882. }, {
  4883. key: 'pushCurrentPosition',
  4884. value: function pushCurrentPosition() {
  4885. if (!this.initialized || this._popStateInProgress) {
  4886. return;
  4887. }
  4888. this._tryPushCurrentPosition();
  4889. }
  4890. }, {
  4891. key: 'back',
  4892. value: function back() {
  4893. if (!this.initialized || this._popStateInProgress) {
  4894. return;
  4895. }
  4896. var state = window.history.state;
  4897. if (this._isValidState(state) && state.uid > 0) {
  4898. window.history.back();
  4899. }
  4900. }
  4901. }, {
  4902. key: 'forward',
  4903. value: function forward() {
  4904. if (!this.initialized || this._popStateInProgress) {
  4905. return;
  4906. }
  4907. var state = window.history.state;
  4908. if (this._isValidState(state) && state.uid < this._maxUid) {
  4909. window.history.forward();
  4910. }
  4911. }
  4912. }, {
  4913. key: '_pushOrReplaceState',
  4914. value: function _pushOrReplaceState(destination) {
  4915. var forceReplace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  4916. var shouldReplace = forceReplace || !this._destination;
  4917. var newState = {
  4918. fingerprint: this.fingerprint,
  4919. uid: shouldReplace ? this._uid : this._uid + 1,
  4920. destination: destination
  4921. };
  4922. this._updateInternalState(destination, newState.uid);
  4923. if (shouldReplace) {
  4924. window.history.replaceState(newState, '', document.URL);
  4925. } else {
  4926. this._maxUid = this._uid;
  4927. window.history.pushState(newState, '', document.URL);
  4928. }
  4929. }
  4930. }, {
  4931. key: '_tryPushCurrentPosition',
  4932. value: function _tryPushCurrentPosition() {
  4933. var temporary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  4934. if (!this._position) {
  4935. return;
  4936. }
  4937. var position = this._position;
  4938. if (temporary) {
  4939. position = (0, _ui_utils.cloneObj)(this._position);
  4940. position.temporary = true;
  4941. }
  4942. if (!this._destination) {
  4943. this._pushOrReplaceState(position);
  4944. return;
  4945. }
  4946. if (this._destination.temporary) {
  4947. this._pushOrReplaceState(position, true);
  4948. return;
  4949. }
  4950. if (this._destination.hash === position.hash) {
  4951. return;
  4952. }
  4953. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  4954. return;
  4955. }
  4956. var forceReplace = false;
  4957. if (this._destination.page === position.first || this._destination.page === position.page) {
  4958. if (this._destination.dest || !this._destination.first) {
  4959. return;
  4960. }
  4961. forceReplace = true;
  4962. }
  4963. this._pushOrReplaceState(position, forceReplace);
  4964. }
  4965. }, {
  4966. key: '_isValidState',
  4967. value: function _isValidState(state) {
  4968. if (!state) {
  4969. return false;
  4970. }
  4971. if (state.fingerprint !== this.fingerprint) {
  4972. return false;
  4973. }
  4974. if (!Number.isInteger(state.uid) || state.uid < 0) {
  4975. return false;
  4976. }
  4977. if (state.destination === null || _typeof(state.destination) !== 'object') {
  4978. return false;
  4979. }
  4980. return true;
  4981. }
  4982. }, {
  4983. key: '_updateInternalState',
  4984. value: function _updateInternalState(destination, uid) {
  4985. var removeTemporary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  4986. if (this._updateViewareaTimeout) {
  4987. clearTimeout(this._updateViewareaTimeout);
  4988. this._updateViewareaTimeout = null;
  4989. }
  4990. if (removeTemporary && destination && destination.temporary) {
  4991. delete destination.temporary;
  4992. }
  4993. this._destination = destination;
  4994. this._uid = uid;
  4995. this._numPositionUpdates = 0;
  4996. }
  4997. }, {
  4998. key: '_updateViewarea',
  4999. value: function _updateViewarea(_ref3) {
  5000. var _this3 = this;
  5001. var location = _ref3.location;
  5002. if (this._updateViewareaTimeout) {
  5003. clearTimeout(this._updateViewareaTimeout);
  5004. this._updateViewareaTimeout = null;
  5005. }
  5006. this._position = {
  5007. hash: this._isViewerInPresentationMode ? 'page=' + location.pageNumber : location.pdfOpenParams.substring(1),
  5008. page: this.linkService.page,
  5009. first: location.pageNumber,
  5010. rotation: location.rotation
  5011. };
  5012. if (this._popStateInProgress) {
  5013. return;
  5014. }
  5015. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5016. this._numPositionUpdates++;
  5017. }
  5018. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5019. this._updateViewareaTimeout = setTimeout(function () {
  5020. if (!_this3._popStateInProgress) {
  5021. _this3._tryPushCurrentPosition(true);
  5022. }
  5023. _this3._updateViewareaTimeout = null;
  5024. }, UPDATE_VIEWAREA_TIMEOUT);
  5025. }
  5026. }
  5027. }, {
  5028. key: '_popState',
  5029. value: function _popState(_ref4) {
  5030. var _this4 = this;
  5031. var state = _ref4.state;
  5032. var newHash = getCurrentHash(),
  5033. hashChanged = this._currentHash !== newHash;
  5034. this._currentHash = newHash;
  5035. if (!state || false) {
  5036. this._uid++;
  5037. var _parseCurrentHash2 = parseCurrentHash(this.linkService),
  5038. hash = _parseCurrentHash2.hash,
  5039. page = _parseCurrentHash2.page,
  5040. rotation = _parseCurrentHash2.rotation;
  5041. this._pushOrReplaceState({
  5042. hash: hash,
  5043. page: page,
  5044. rotation: rotation
  5045. }, true);
  5046. return;
  5047. }
  5048. if (!this._isValidState(state)) {
  5049. return;
  5050. }
  5051. this._popStateInProgress = true;
  5052. if (hashChanged) {
  5053. this._blockHashChange++;
  5054. (0, _ui_utils.waitOnEventOrTimeout)({
  5055. target: window,
  5056. name: 'hashchange',
  5057. delay: HASH_CHANGE_TIMEOUT
  5058. }).then(function () {
  5059. _this4._blockHashChange--;
  5060. });
  5061. }
  5062. var destination = state.destination;
  5063. this._updateInternalState(destination, state.uid, true);
  5064. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5065. this.linkService.rotation = destination.rotation;
  5066. }
  5067. if (destination.dest) {
  5068. this.linkService.navigateTo(destination.dest);
  5069. } else if (destination.hash) {
  5070. this.linkService.setHash(destination.hash);
  5071. } else if (destination.page) {
  5072. this.linkService.page = destination.page;
  5073. }
  5074. Promise.resolve().then(function () {
  5075. _this4._popStateInProgress = false;
  5076. });
  5077. }
  5078. }, {
  5079. key: '_bindEvents',
  5080. value: function _bindEvents() {
  5081. var _this5 = this;
  5082. var _boundEvents = this._boundEvents,
  5083. eventBus = this.eventBus;
  5084. _boundEvents.updateViewarea = this._updateViewarea.bind(this);
  5085. _boundEvents.popState = this._popState.bind(this);
  5086. _boundEvents.pageHide = function (evt) {
  5087. if (!_this5._destination) {
  5088. _this5._tryPushCurrentPosition();
  5089. }
  5090. };
  5091. eventBus.on('updateviewarea', _boundEvents.updateViewarea);
  5092. window.addEventListener('popstate', _boundEvents.popState);
  5093. window.addEventListener('pagehide', _boundEvents.pageHide);
  5094. }
  5095. }, {
  5096. key: 'popStateInProgress',
  5097. get: function get() {
  5098. return this.initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5099. }
  5100. }]);
  5101. return PDFHistory;
  5102. }();
  5103. function isDestHashesEqual(destHash, pushHash) {
  5104. if (typeof destHash !== 'string' || typeof pushHash !== 'string') {
  5105. return false;
  5106. }
  5107. if (destHash === pushHash) {
  5108. return true;
  5109. }
  5110. var _parseQueryString = (0, _ui_utils.parseQueryString)(destHash),
  5111. nameddest = _parseQueryString.nameddest;
  5112. if (nameddest === pushHash) {
  5113. return true;
  5114. }
  5115. return false;
  5116. }
  5117. function isDestArraysEqual(firstDest, secondDest) {
  5118. function isEntryEqual(first, second) {
  5119. if ((typeof first === 'undefined' ? 'undefined' : _typeof(first)) !== (typeof second === 'undefined' ? 'undefined' : _typeof(second))) {
  5120. return false;
  5121. }
  5122. if (first instanceof Array || second instanceof Array) {
  5123. return false;
  5124. }
  5125. if (first !== null && (typeof first === 'undefined' ? 'undefined' : _typeof(first)) === 'object' && second !== null) {
  5126. if (Object.keys(first).length !== Object.keys(second).length) {
  5127. return false;
  5128. }
  5129. for (var key in first) {
  5130. if (!isEntryEqual(first[key], second[key])) {
  5131. return false;
  5132. }
  5133. }
  5134. return true;
  5135. }
  5136. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5137. }
  5138. if (!(firstDest instanceof Array && secondDest instanceof Array)) {
  5139. return false;
  5140. }
  5141. if (firstDest.length !== secondDest.length) {
  5142. return false;
  5143. }
  5144. for (var i = 0, ii = firstDest.length; i < ii; i++) {
  5145. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5146. return false;
  5147. }
  5148. }
  5149. return true;
  5150. }
  5151. exports.PDFHistory = PDFHistory;
  5152. exports.isDestHashesEqual = isDestHashesEqual;
  5153. exports.isDestArraysEqual = isDestArraysEqual;
  5154. /***/ }),
  5155. /* 17 */
  5156. /***/ (function(module, exports, __webpack_require__) {
  5157. "use strict";
  5158. Object.defineProperty(exports, "__esModule", {
  5159. value: true
  5160. });
  5161. exports.PDFOutlineViewer = undefined;
  5162. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  5163. var _pdfjsLib = __webpack_require__(1);
  5164. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5165. var DEFAULT_TITLE = '\u2013';
  5166. var PDFOutlineViewer = function () {
  5167. function PDFOutlineViewer(_ref) {
  5168. var container = _ref.container,
  5169. linkService = _ref.linkService,
  5170. eventBus = _ref.eventBus;
  5171. _classCallCheck(this, PDFOutlineViewer);
  5172. this.container = container;
  5173. this.linkService = linkService;
  5174. this.eventBus = eventBus;
  5175. this.reset();
  5176. }
  5177. _createClass(PDFOutlineViewer, [{
  5178. key: 'reset',
  5179. value: function reset() {
  5180. this.outline = null;
  5181. this.lastToggleIsShow = true;
  5182. this.container.textContent = '';
  5183. this.container.classList.remove('outlineWithDeepNesting');
  5184. }
  5185. }, {
  5186. key: '_dispatchEvent',
  5187. value: function _dispatchEvent(outlineCount) {
  5188. this.eventBus.dispatch('outlineloaded', {
  5189. source: this,
  5190. outlineCount: outlineCount
  5191. });
  5192. }
  5193. }, {
  5194. key: '_bindLink',
  5195. value: function _bindLink(element, item) {
  5196. var _this = this;
  5197. if (item.url) {
  5198. (0, _pdfjsLib.addLinkAttributes)(element, {
  5199. url: item.url,
  5200. target: item.newWindow ? _pdfjsLib.PDFJS.LinkTarget.BLANK : undefined
  5201. });
  5202. return;
  5203. }
  5204. var destination = item.dest;
  5205. element.href = this.linkService.getDestinationHash(destination);
  5206. element.onclick = function () {
  5207. if (destination) {
  5208. _this.linkService.navigateTo(destination);
  5209. }
  5210. return false;
  5211. };
  5212. }
  5213. }, {
  5214. key: '_setStyles',
  5215. value: function _setStyles(element, item) {
  5216. var styleStr = '';
  5217. if (item.bold) {
  5218. styleStr += 'font-weight: bold;';
  5219. }
  5220. if (item.italic) {
  5221. styleStr += 'font-style: italic;';
  5222. }
  5223. if (styleStr) {
  5224. element.setAttribute('style', styleStr);
  5225. }
  5226. }
  5227. }, {
  5228. key: '_addToggleButton',
  5229. value: function _addToggleButton(div) {
  5230. var _this2 = this;
  5231. var toggler = document.createElement('div');
  5232. toggler.className = 'outlineItemToggler';
  5233. toggler.onclick = function (evt) {
  5234. evt.stopPropagation();
  5235. toggler.classList.toggle('outlineItemsHidden');
  5236. if (evt.shiftKey) {
  5237. var shouldShowAll = !toggler.classList.contains('outlineItemsHidden');
  5238. _this2._toggleOutlineItem(div, shouldShowAll);
  5239. }
  5240. };
  5241. div.insertBefore(toggler, div.firstChild);
  5242. }
  5243. }, {
  5244. key: '_toggleOutlineItem',
  5245. value: function _toggleOutlineItem(root, show) {
  5246. this.lastToggleIsShow = show;
  5247. var togglers = root.querySelectorAll('.outlineItemToggler');
  5248. for (var i = 0, ii = togglers.length; i < ii; ++i) {
  5249. togglers[i].classList[show ? 'remove' : 'add']('outlineItemsHidden');
  5250. }
  5251. }
  5252. }, {
  5253. key: 'toggleOutlineTree',
  5254. value: function toggleOutlineTree() {
  5255. if (!this.outline) {
  5256. return;
  5257. }
  5258. this._toggleOutlineItem(this.container, !this.lastToggleIsShow);
  5259. }
  5260. }, {
  5261. key: 'render',
  5262. value: function render(_ref2) {
  5263. var outline = _ref2.outline;
  5264. var outlineCount = 0;
  5265. if (this.outline) {
  5266. this.reset();
  5267. }
  5268. this.outline = outline || null;
  5269. if (!outline) {
  5270. this._dispatchEvent(outlineCount);
  5271. return;
  5272. }
  5273. var fragment = document.createDocumentFragment();
  5274. var queue = [{
  5275. parent: fragment,
  5276. items: this.outline
  5277. }];
  5278. var hasAnyNesting = false;
  5279. while (queue.length > 0) {
  5280. var levelData = queue.shift();
  5281. for (var i = 0, len = levelData.items.length; i < len; i++) {
  5282. var item = levelData.items[i];
  5283. var div = document.createElement('div');
  5284. div.className = 'outlineItem';
  5285. var element = document.createElement('a');
  5286. this._bindLink(element, item);
  5287. this._setStyles(element, item);
  5288. element.textContent = (0, _pdfjsLib.removeNullCharacters)(item.title) || DEFAULT_TITLE;
  5289. div.appendChild(element);
  5290. if (item.items.length > 0) {
  5291. hasAnyNesting = true;
  5292. this._addToggleButton(div);
  5293. var itemsDiv = document.createElement('div');
  5294. itemsDiv.className = 'outlineItems';
  5295. div.appendChild(itemsDiv);
  5296. queue.push({
  5297. parent: itemsDiv,
  5298. items: item.items
  5299. });
  5300. }
  5301. levelData.parent.appendChild(div);
  5302. outlineCount++;
  5303. }
  5304. }
  5305. if (hasAnyNesting) {
  5306. this.container.classList.add('outlineWithDeepNesting');
  5307. }
  5308. this.container.appendChild(fragment);
  5309. this._dispatchEvent(outlineCount);
  5310. }
  5311. }]);
  5312. return PDFOutlineViewer;
  5313. }();
  5314. exports.PDFOutlineViewer = PDFOutlineViewer;
  5315. /***/ }),
  5316. /* 18 */
  5317. /***/ (function(module, exports, __webpack_require__) {
  5318. "use strict";
  5319. Object.defineProperty(exports, "__esModule", {
  5320. value: true
  5321. });
  5322. exports.PDFPresentationMode = undefined;
  5323. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  5324. var _ui_utils = __webpack_require__(0);
  5325. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5326. var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  5327. var DELAY_BEFORE_HIDING_CONTROLS = 3000;
  5328. var ACTIVE_SELECTOR = 'pdfPresentationMode';
  5329. var CONTROLS_SELECTOR = 'pdfPresentationModeControls';
  5330. var MOUSE_SCROLL_COOLDOWN_TIME = 50;
  5331. var PAGE_SWITCH_THRESHOLD = 0.1;
  5332. var SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  5333. var SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  5334. var PDFPresentationMode = function () {
  5335. function PDFPresentationMode(_ref) {
  5336. var _this = this;
  5337. var container = _ref.container,
  5338. _ref$viewer = _ref.viewer,
  5339. viewer = _ref$viewer === undefined ? null : _ref$viewer,
  5340. pdfViewer = _ref.pdfViewer,
  5341. eventBus = _ref.eventBus,
  5342. _ref$contextMenuItems = _ref.contextMenuItems,
  5343. contextMenuItems = _ref$contextMenuItems === undefined ? null : _ref$contextMenuItems;
  5344. _classCallCheck(this, PDFPresentationMode);
  5345. this.container = container;
  5346. this.viewer = viewer || container.firstElementChild;
  5347. this.pdfViewer = pdfViewer;
  5348. this.eventBus = eventBus;
  5349. this.active = false;
  5350. this.args = null;
  5351. this.contextMenuOpen = false;
  5352. this.mouseScrollTimeStamp = 0;
  5353. this.mouseScrollDelta = 0;
  5354. this.touchSwipeState = null;
  5355. if (contextMenuItems) {
  5356. contextMenuItems.contextFirstPage.addEventListener('click', function () {
  5357. _this.contextMenuOpen = false;
  5358. _this.eventBus.dispatch('firstpage');
  5359. });
  5360. contextMenuItems.contextLastPage.addEventListener('click', function () {
  5361. _this.contextMenuOpen = false;
  5362. _this.eventBus.dispatch('lastpage');
  5363. });
  5364. contextMenuItems.contextPageRotateCw.addEventListener('click', function () {
  5365. _this.contextMenuOpen = false;
  5366. _this.eventBus.dispatch('rotatecw');
  5367. });
  5368. contextMenuItems.contextPageRotateCcw.addEventListener('click', function () {
  5369. _this.contextMenuOpen = false;
  5370. _this.eventBus.dispatch('rotateccw');
  5371. });
  5372. }
  5373. }
  5374. _createClass(PDFPresentationMode, [{
  5375. key: 'request',
  5376. value: function request() {
  5377. if (this.switchInProgress || this.active || !this.viewer.hasChildNodes()) {
  5378. return false;
  5379. }
  5380. this._addFullscreenChangeListeners();
  5381. this._setSwitchInProgress();
  5382. this._notifyStateChange();
  5383. if (this.container.requestFullscreen) {
  5384. this.container.requestFullscreen();
  5385. } else if (this.container.mozRequestFullScreen) {
  5386. this.container.mozRequestFullScreen();
  5387. } else if (this.container.webkitRequestFullscreen) {
  5388. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  5389. } else if (this.container.msRequestFullscreen) {
  5390. this.container.msRequestFullscreen();
  5391. } else {
  5392. return false;
  5393. }
  5394. this.args = {
  5395. page: this.pdfViewer.currentPageNumber,
  5396. previousScale: this.pdfViewer.currentScaleValue
  5397. };
  5398. return true;
  5399. }
  5400. }, {
  5401. key: '_mouseWheel',
  5402. value: function _mouseWheel(evt) {
  5403. if (!this.active) {
  5404. return;
  5405. }
  5406. evt.preventDefault();
  5407. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  5408. var currentTime = new Date().getTime();
  5409. var storedTime = this.mouseScrollTimeStamp;
  5410. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  5411. return;
  5412. }
  5413. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  5414. this._resetMouseScrollState();
  5415. }
  5416. this.mouseScrollDelta += delta;
  5417. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  5418. var totalDelta = this.mouseScrollDelta;
  5419. this._resetMouseScrollState();
  5420. var success = totalDelta > 0 ? this._goToPreviousPage() : this._goToNextPage();
  5421. if (success) {
  5422. this.mouseScrollTimeStamp = currentTime;
  5423. }
  5424. }
  5425. }
  5426. }, {
  5427. key: '_goToPreviousPage',
  5428. value: function _goToPreviousPage() {
  5429. var page = this.pdfViewer.currentPageNumber;
  5430. if (page <= 1) {
  5431. return false;
  5432. }
  5433. this.pdfViewer.currentPageNumber = page - 1;
  5434. return true;
  5435. }
  5436. }, {
  5437. key: '_goToNextPage',
  5438. value: function _goToNextPage() {
  5439. var page = this.pdfViewer.currentPageNumber;
  5440. if (page >= this.pdfViewer.pagesCount) {
  5441. return false;
  5442. }
  5443. this.pdfViewer.currentPageNumber = page + 1;
  5444. return true;
  5445. }
  5446. }, {
  5447. key: '_notifyStateChange',
  5448. value: function _notifyStateChange() {
  5449. this.eventBus.dispatch('presentationmodechanged', {
  5450. source: this,
  5451. active: this.active,
  5452. switchInProgress: !!this.switchInProgress
  5453. });
  5454. }
  5455. }, {
  5456. key: '_setSwitchInProgress',
  5457. value: function _setSwitchInProgress() {
  5458. var _this2 = this;
  5459. if (this.switchInProgress) {
  5460. clearTimeout(this.switchInProgress);
  5461. }
  5462. this.switchInProgress = setTimeout(function () {
  5463. _this2._removeFullscreenChangeListeners();
  5464. delete _this2.switchInProgress;
  5465. _this2._notifyStateChange();
  5466. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  5467. }
  5468. }, {
  5469. key: '_resetSwitchInProgress',
  5470. value: function _resetSwitchInProgress() {
  5471. if (this.switchInProgress) {
  5472. clearTimeout(this.switchInProgress);
  5473. delete this.switchInProgress;
  5474. }
  5475. }
  5476. }, {
  5477. key: '_enter',
  5478. value: function _enter() {
  5479. var _this3 = this;
  5480. this.active = true;
  5481. this._resetSwitchInProgress();
  5482. this._notifyStateChange();
  5483. this.container.classList.add(ACTIVE_SELECTOR);
  5484. setTimeout(function () {
  5485. _this3.pdfViewer.currentPageNumber = _this3.args.page;
  5486. _this3.pdfViewer.currentScaleValue = 'page-fit';
  5487. }, 0);
  5488. this._addWindowListeners();
  5489. this._showControls();
  5490. this.contextMenuOpen = false;
  5491. this.container.setAttribute('contextmenu', 'viewerContextMenu');
  5492. window.getSelection().removeAllRanges();
  5493. }
  5494. }, {
  5495. key: '_exit',
  5496. value: function _exit() {
  5497. var _this4 = this;
  5498. var page = this.pdfViewer.currentPageNumber;
  5499. this.container.classList.remove(ACTIVE_SELECTOR);
  5500. setTimeout(function () {
  5501. _this4.active = false;
  5502. _this4._removeFullscreenChangeListeners();
  5503. _this4._notifyStateChange();
  5504. _this4.pdfViewer.currentScaleValue = _this4.args.previousScale;
  5505. _this4.pdfViewer.currentPageNumber = page;
  5506. _this4.args = null;
  5507. }, 0);
  5508. this._removeWindowListeners();
  5509. this._hideControls();
  5510. this._resetMouseScrollState();
  5511. this.container.removeAttribute('contextmenu');
  5512. this.contextMenuOpen = false;
  5513. }
  5514. }, {
  5515. key: '_mouseDown',
  5516. value: function _mouseDown(evt) {
  5517. if (this.contextMenuOpen) {
  5518. this.contextMenuOpen = false;
  5519. evt.preventDefault();
  5520. return;
  5521. }
  5522. if (evt.button === 0) {
  5523. var isInternalLink = evt.target.href && evt.target.classList.contains('internalLink');
  5524. if (!isInternalLink) {
  5525. evt.preventDefault();
  5526. if (evt.shiftKey) {
  5527. this._goToPreviousPage();
  5528. } else {
  5529. this._goToNextPage();
  5530. }
  5531. }
  5532. }
  5533. }
  5534. }, {
  5535. key: '_contextMenu',
  5536. value: function _contextMenu() {
  5537. this.contextMenuOpen = true;
  5538. }
  5539. }, {
  5540. key: '_showControls',
  5541. value: function _showControls() {
  5542. var _this5 = this;
  5543. if (this.controlsTimeout) {
  5544. clearTimeout(this.controlsTimeout);
  5545. } else {
  5546. this.container.classList.add(CONTROLS_SELECTOR);
  5547. }
  5548. this.controlsTimeout = setTimeout(function () {
  5549. _this5.container.classList.remove(CONTROLS_SELECTOR);
  5550. delete _this5.controlsTimeout;
  5551. }, DELAY_BEFORE_HIDING_CONTROLS);
  5552. }
  5553. }, {
  5554. key: '_hideControls',
  5555. value: function _hideControls() {
  5556. if (!this.controlsTimeout) {
  5557. return;
  5558. }
  5559. clearTimeout(this.controlsTimeout);
  5560. this.container.classList.remove(CONTROLS_SELECTOR);
  5561. delete this.controlsTimeout;
  5562. }
  5563. }, {
  5564. key: '_resetMouseScrollState',
  5565. value: function _resetMouseScrollState() {
  5566. this.mouseScrollTimeStamp = 0;
  5567. this.mouseScrollDelta = 0;
  5568. }
  5569. }, {
  5570. key: '_touchSwipe',
  5571. value: function _touchSwipe(evt) {
  5572. if (!this.active) {
  5573. return;
  5574. }
  5575. if (evt.touches.length > 1) {
  5576. this.touchSwipeState = null;
  5577. return;
  5578. }
  5579. switch (evt.type) {
  5580. case 'touchstart':
  5581. this.touchSwipeState = {
  5582. startX: evt.touches[0].pageX,
  5583. startY: evt.touches[0].pageY,
  5584. endX: evt.touches[0].pageX,
  5585. endY: evt.touches[0].pageY
  5586. };
  5587. break;
  5588. case 'touchmove':
  5589. if (this.touchSwipeState === null) {
  5590. return;
  5591. }
  5592. this.touchSwipeState.endX = evt.touches[0].pageX;
  5593. this.touchSwipeState.endY = evt.touches[0].pageY;
  5594. evt.preventDefault();
  5595. break;
  5596. case 'touchend':
  5597. if (this.touchSwipeState === null) {
  5598. return;
  5599. }
  5600. var delta = 0;
  5601. var dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  5602. var dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  5603. var absAngle = Math.abs(Math.atan2(dy, dx));
  5604. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  5605. delta = dx;
  5606. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  5607. delta = dy;
  5608. }
  5609. if (delta > 0) {
  5610. this._goToPreviousPage();
  5611. } else if (delta < 0) {
  5612. this._goToNextPage();
  5613. }
  5614. break;
  5615. }
  5616. }
  5617. }, {
  5618. key: '_addWindowListeners',
  5619. value: function _addWindowListeners() {
  5620. this.showControlsBind = this._showControls.bind(this);
  5621. this.mouseDownBind = this._mouseDown.bind(this);
  5622. this.mouseWheelBind = this._mouseWheel.bind(this);
  5623. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  5624. this.contextMenuBind = this._contextMenu.bind(this);
  5625. this.touchSwipeBind = this._touchSwipe.bind(this);
  5626. window.addEventListener('mousemove', this.showControlsBind);
  5627. window.addEventListener('mousedown', this.mouseDownBind);
  5628. window.addEventListener('wheel', this.mouseWheelBind);
  5629. window.addEventListener('keydown', this.resetMouseScrollStateBind);
  5630. window.addEventListener('contextmenu', this.contextMenuBind);
  5631. window.addEventListener('touchstart', this.touchSwipeBind);
  5632. window.addEventListener('touchmove', this.touchSwipeBind);
  5633. window.addEventListener('touchend', this.touchSwipeBind);
  5634. }
  5635. }, {
  5636. key: '_removeWindowListeners',
  5637. value: function _removeWindowListeners() {
  5638. window.removeEventListener('mousemove', this.showControlsBind);
  5639. window.removeEventListener('mousedown', this.mouseDownBind);
  5640. window.removeEventListener('wheel', this.mouseWheelBind);
  5641. window.removeEventListener('keydown', this.resetMouseScrollStateBind);
  5642. window.removeEventListener('contextmenu', this.contextMenuBind);
  5643. window.removeEventListener('touchstart', this.touchSwipeBind);
  5644. window.removeEventListener('touchmove', this.touchSwipeBind);
  5645. window.removeEventListener('touchend', this.touchSwipeBind);
  5646. delete this.showControlsBind;
  5647. delete this.mouseDownBind;
  5648. delete this.mouseWheelBind;
  5649. delete this.resetMouseScrollStateBind;
  5650. delete this.contextMenuBind;
  5651. delete this.touchSwipeBind;
  5652. }
  5653. }, {
  5654. key: '_fullscreenChange',
  5655. value: function _fullscreenChange() {
  5656. if (this.isFullscreen) {
  5657. this._enter();
  5658. } else {
  5659. this._exit();
  5660. }
  5661. }
  5662. }, {
  5663. key: '_addFullscreenChangeListeners',
  5664. value: function _addFullscreenChangeListeners() {
  5665. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  5666. window.addEventListener('fullscreenchange', this.fullscreenChangeBind);
  5667. window.addEventListener('mozfullscreenchange', this.fullscreenChangeBind);
  5668. window.addEventListener('webkitfullscreenchange', this.fullscreenChangeBind);
  5669. window.addEventListener('MSFullscreenChange', this.fullscreenChangeBind);
  5670. }
  5671. }, {
  5672. key: '_removeFullscreenChangeListeners',
  5673. value: function _removeFullscreenChangeListeners() {
  5674. window.removeEventListener('fullscreenchange', this.fullscreenChangeBind);
  5675. window.removeEventListener('mozfullscreenchange', this.fullscreenChangeBind);
  5676. window.removeEventListener('webkitfullscreenchange', this.fullscreenChangeBind);
  5677. window.removeEventListener('MSFullscreenChange', this.fullscreenChangeBind);
  5678. delete this.fullscreenChangeBind;
  5679. }
  5680. }, {
  5681. key: 'isFullscreen',
  5682. get: function get() {
  5683. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement);
  5684. }
  5685. }]);
  5686. return PDFPresentationMode;
  5687. }();
  5688. exports.PDFPresentationMode = PDFPresentationMode;
  5689. /***/ }),
  5690. /* 19 */
  5691. /***/ (function(module, exports, __webpack_require__) {
  5692. "use strict";
  5693. Object.defineProperty(exports, "__esModule", {
  5694. value: true
  5695. });
  5696. exports.PDFThumbnailViewer = undefined;
  5697. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  5698. var _ui_utils = __webpack_require__(0);
  5699. var _pdf_thumbnail_view = __webpack_require__(20);
  5700. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5701. var THUMBNAIL_SCROLL_MARGIN = -19;
  5702. var PDFThumbnailViewer = function () {
  5703. function PDFThumbnailViewer(_ref) {
  5704. var container = _ref.container,
  5705. linkService = _ref.linkService,
  5706. renderingQueue = _ref.renderingQueue,
  5707. _ref$l10n = _ref.l10n,
  5708. l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n;
  5709. _classCallCheck(this, PDFThumbnailViewer);
  5710. this.container = container;
  5711. this.linkService = linkService;
  5712. this.renderingQueue = renderingQueue;
  5713. this.l10n = l10n;
  5714. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  5715. this._resetView();
  5716. }
  5717. _createClass(PDFThumbnailViewer, [{
  5718. key: '_scrollUpdated',
  5719. value: function _scrollUpdated() {
  5720. this.renderingQueue.renderHighestPriority();
  5721. }
  5722. }, {
  5723. key: 'getThumbnail',
  5724. value: function getThumbnail(index) {
  5725. return this._thumbnails[index];
  5726. }
  5727. }, {
  5728. key: '_getVisibleThumbs',
  5729. value: function _getVisibleThumbs() {
  5730. return (0, _ui_utils.getVisibleElements)(this.container, this._thumbnails);
  5731. }
  5732. }, {
  5733. key: 'scrollThumbnailIntoView',
  5734. value: function scrollThumbnailIntoView(page) {
  5735. var selected = document.querySelector('.thumbnail.selected');
  5736. if (selected) {
  5737. selected.classList.remove('selected');
  5738. }
  5739. var thumbnail = document.querySelector('div.thumbnail[data-page-number="' + page + '"]');
  5740. if (thumbnail) {
  5741. thumbnail.classList.add('selected');
  5742. }
  5743. var visibleThumbs = this._getVisibleThumbs();
  5744. var numVisibleThumbs = visibleThumbs.views.length;
  5745. if (numVisibleThumbs > 0) {
  5746. var first = visibleThumbs.first.id;
  5747. var last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
  5748. if (page <= first || page >= last) {
  5749. (0, _ui_utils.scrollIntoView)(thumbnail, { top: THUMBNAIL_SCROLL_MARGIN });
  5750. }
  5751. }
  5752. }
  5753. }, {
  5754. key: 'cleanup',
  5755. value: function cleanup() {
  5756. _pdf_thumbnail_view.PDFThumbnailView.cleanup();
  5757. }
  5758. }, {
  5759. key: '_resetView',
  5760. value: function _resetView() {
  5761. this._thumbnails = [];
  5762. this._pageLabels = null;
  5763. this._pagesRotation = 0;
  5764. this._pagesRequests = [];
  5765. this.container.textContent = '';
  5766. }
  5767. }, {
  5768. key: 'setDocument',
  5769. value: function setDocument(pdfDocument) {
  5770. var _this = this;
  5771. if (this.pdfDocument) {
  5772. this._cancelRendering();
  5773. this._resetView();
  5774. }
  5775. this.pdfDocument = pdfDocument;
  5776. if (!pdfDocument) {
  5777. return;
  5778. }
  5779. pdfDocument.getPage(1).then(function (firstPage) {
  5780. var pagesCount = pdfDocument.numPages;
  5781. var viewport = firstPage.getViewport(1.0);
  5782. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  5783. var thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  5784. container: _this.container,
  5785. id: pageNum,
  5786. defaultViewport: viewport.clone(),
  5787. linkService: _this.linkService,
  5788. renderingQueue: _this.renderingQueue,
  5789. disableCanvasToImageConversion: false,
  5790. l10n: _this.l10n
  5791. });
  5792. _this._thumbnails.push(thumbnail);
  5793. }
  5794. }).catch(function (reason) {
  5795. console.error('Unable to initialize thumbnail viewer', reason);
  5796. });
  5797. }
  5798. }, {
  5799. key: '_cancelRendering',
  5800. value: function _cancelRendering() {
  5801. for (var i = 0, ii = this._thumbnails.length; i < ii; i++) {
  5802. if (this._thumbnails[i]) {
  5803. this._thumbnails[i].cancelRendering();
  5804. }
  5805. }
  5806. }
  5807. }, {
  5808. key: 'setPageLabels',
  5809. value: function setPageLabels(labels) {
  5810. if (!this.pdfDocument) {
  5811. return;
  5812. }
  5813. if (!labels) {
  5814. this._pageLabels = null;
  5815. } else if (!(labels instanceof Array && this.pdfDocument.numPages === labels.length)) {
  5816. this._pageLabels = null;
  5817. console.error('PDFThumbnailViewer_setPageLabels: Invalid page labels.');
  5818. } else {
  5819. this._pageLabels = labels;
  5820. }
  5821. for (var i = 0, ii = this._thumbnails.length; i < ii; i++) {
  5822. var label = this._pageLabels && this._pageLabels[i];
  5823. this._thumbnails[i].setPageLabel(label);
  5824. }
  5825. }
  5826. }, {
  5827. key: '_ensurePdfPageLoaded',
  5828. value: function _ensurePdfPageLoaded(thumbView) {
  5829. var _this2 = this;
  5830. if (thumbView.pdfPage) {
  5831. return Promise.resolve(thumbView.pdfPage);
  5832. }
  5833. var pageNumber = thumbView.id;
  5834. if (this._pagesRequests[pageNumber]) {
  5835. return this._pagesRequests[pageNumber];
  5836. }
  5837. var promise = this.pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  5838. thumbView.setPdfPage(pdfPage);
  5839. _this2._pagesRequests[pageNumber] = null;
  5840. return pdfPage;
  5841. }).catch(function (reason) {
  5842. console.error('Unable to get page for thumb view', reason);
  5843. _this2._pagesRequests[pageNumber] = null;
  5844. });
  5845. this._pagesRequests[pageNumber] = promise;
  5846. return promise;
  5847. }
  5848. }, {
  5849. key: 'forceRendering',
  5850. value: function forceRendering() {
  5851. var _this3 = this;
  5852. var visibleThumbs = this._getVisibleThumbs();
  5853. var thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
  5854. if (thumbView) {
  5855. this._ensurePdfPageLoaded(thumbView).then(function () {
  5856. _this3.renderingQueue.renderView(thumbView);
  5857. });
  5858. return true;
  5859. }
  5860. return false;
  5861. }
  5862. }, {
  5863. key: 'pagesRotation',
  5864. get: function get() {
  5865. return this._pagesRotation;
  5866. },
  5867. set: function set(rotation) {
  5868. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  5869. throw new Error('Invalid thumbnails rotation angle.');
  5870. }
  5871. if (!this.pdfDocument) {
  5872. return;
  5873. }
  5874. if (this._pagesRotation === rotation) {
  5875. return;
  5876. }
  5877. this._pagesRotation = rotation;
  5878. for (var i = 0, ii = this._thumbnails.length; i < ii; i++) {
  5879. this._thumbnails[i].update(rotation);
  5880. }
  5881. }
  5882. }]);
  5883. return PDFThumbnailViewer;
  5884. }();
  5885. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  5886. /***/ }),
  5887. /* 20 */
  5888. /***/ (function(module, exports, __webpack_require__) {
  5889. "use strict";
  5890. Object.defineProperty(exports, "__esModule", {
  5891. value: true
  5892. });
  5893. exports.PDFThumbnailView = undefined;
  5894. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  5895. var _pdfjsLib = __webpack_require__(1);
  5896. var _ui_utils = __webpack_require__(0);
  5897. var _pdf_rendering_queue = __webpack_require__(3);
  5898. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5899. var MAX_NUM_SCALING_STEPS = 3;
  5900. var THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  5901. var THUMBNAIL_WIDTH = 98;
  5902. var TempImageFactory = function TempImageFactoryClosure() {
  5903. var tempCanvasCache = null;
  5904. return {
  5905. getCanvas: function getCanvas(width, height) {
  5906. var tempCanvas = tempCanvasCache;
  5907. if (!tempCanvas) {
  5908. tempCanvas = document.createElement('canvas');
  5909. tempCanvasCache = tempCanvas;
  5910. }
  5911. tempCanvas.width = width;
  5912. tempCanvas.height = height;
  5913. tempCanvas.mozOpaque = true;
  5914. var ctx = tempCanvas.getContext('2d', { alpha: false });
  5915. ctx.save();
  5916. ctx.fillStyle = 'rgb(255, 255, 255)';
  5917. ctx.fillRect(0, 0, width, height);
  5918. ctx.restore();
  5919. return tempCanvas;
  5920. },
  5921. destroyCanvas: function destroyCanvas() {
  5922. var tempCanvas = tempCanvasCache;
  5923. if (tempCanvas) {
  5924. tempCanvas.width = 0;
  5925. tempCanvas.height = 0;
  5926. }
  5927. tempCanvasCache = null;
  5928. }
  5929. };
  5930. }();
  5931. var PDFThumbnailView = function () {
  5932. function PDFThumbnailView(_ref) {
  5933. var container = _ref.container,
  5934. id = _ref.id,
  5935. defaultViewport = _ref.defaultViewport,
  5936. linkService = _ref.linkService,
  5937. renderingQueue = _ref.renderingQueue,
  5938. _ref$disableCanvasToI = _ref.disableCanvasToImageConversion,
  5939. disableCanvasToImageConversion = _ref$disableCanvasToI === undefined ? false : _ref$disableCanvasToI,
  5940. _ref$l10n = _ref.l10n,
  5941. l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n;
  5942. _classCallCheck(this, PDFThumbnailView);
  5943. this.id = id;
  5944. this.renderingId = 'thumbnail' + id;
  5945. this.pageLabel = null;
  5946. this.pdfPage = null;
  5947. this.rotation = 0;
  5948. this.viewport = defaultViewport;
  5949. this.pdfPageRotate = defaultViewport.rotation;
  5950. this.linkService = linkService;
  5951. this.renderingQueue = renderingQueue;
  5952. this.renderTask = null;
  5953. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  5954. this.resume = null;
  5955. this.disableCanvasToImageConversion = disableCanvasToImageConversion;
  5956. this.pageWidth = this.viewport.width;
  5957. this.pageHeight = this.viewport.height;
  5958. this.pageRatio = this.pageWidth / this.pageHeight;
  5959. this.canvasWidth = THUMBNAIL_WIDTH;
  5960. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  5961. this.scale = this.canvasWidth / this.pageWidth;
  5962. this.l10n = l10n;
  5963. var anchor = document.createElement('a');
  5964. anchor.href = linkService.getAnchorUrl('#page=' + id);
  5965. this.l10n.get('thumb_page_title', { page: id }, 'Page {{page}}').then(function (msg) {
  5966. anchor.title = msg;
  5967. });
  5968. anchor.onclick = function () {
  5969. linkService.page = id;
  5970. return false;
  5971. };
  5972. this.anchor = anchor;
  5973. var div = document.createElement('div');
  5974. div.className = 'thumbnail';
  5975. div.setAttribute('data-page-number', this.id);
  5976. this.div = div;
  5977. if (id === 1) {
  5978. div.classList.add('selected');
  5979. }
  5980. var ring = document.createElement('div');
  5981. ring.className = 'thumbnailSelectionRing';
  5982. var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  5983. ring.style.width = this.canvasWidth + borderAdjustment + 'px';
  5984. ring.style.height = this.canvasHeight + borderAdjustment + 'px';
  5985. this.ring = ring;
  5986. div.appendChild(ring);
  5987. anchor.appendChild(div);
  5988. container.appendChild(anchor);
  5989. }
  5990. _createClass(PDFThumbnailView, [{
  5991. key: 'setPdfPage',
  5992. value: function setPdfPage(pdfPage) {
  5993. this.pdfPage = pdfPage;
  5994. this.pdfPageRotate = pdfPage.rotate;
  5995. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  5996. this.viewport = pdfPage.getViewport(1, totalRotation);
  5997. this.reset();
  5998. }
  5999. }, {
  6000. key: 'reset',
  6001. value: function reset() {
  6002. this.cancelRendering();
  6003. this.pageWidth = this.viewport.width;
  6004. this.pageHeight = this.viewport.height;
  6005. this.pageRatio = this.pageWidth / this.pageHeight;
  6006. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  6007. this.scale = this.canvasWidth / this.pageWidth;
  6008. this.div.removeAttribute('data-loaded');
  6009. var ring = this.ring;
  6010. var childNodes = ring.childNodes;
  6011. for (var i = childNodes.length - 1; i >= 0; i--) {
  6012. ring.removeChild(childNodes[i]);
  6013. }
  6014. var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  6015. ring.style.width = this.canvasWidth + borderAdjustment + 'px';
  6016. ring.style.height = this.canvasHeight + borderAdjustment + 'px';
  6017. if (this.canvas) {
  6018. this.canvas.width = 0;
  6019. this.canvas.height = 0;
  6020. delete this.canvas;
  6021. }
  6022. if (this.image) {
  6023. this.image.removeAttribute('src');
  6024. delete this.image;
  6025. }
  6026. }
  6027. }, {
  6028. key: 'update',
  6029. value: function update(rotation) {
  6030. if (typeof rotation !== 'undefined') {
  6031. this.rotation = rotation;
  6032. }
  6033. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  6034. this.viewport = this.viewport.clone({
  6035. scale: 1,
  6036. rotation: totalRotation
  6037. });
  6038. this.reset();
  6039. }
  6040. }, {
  6041. key: 'cancelRendering',
  6042. value: function cancelRendering() {
  6043. if (this.renderTask) {
  6044. this.renderTask.cancel();
  6045. this.renderTask = null;
  6046. }
  6047. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  6048. this.resume = null;
  6049. }
  6050. }, {
  6051. key: '_getPageDrawContext',
  6052. value: function _getPageDrawContext() {
  6053. var noCtxScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  6054. var canvas = document.createElement('canvas');
  6055. this.canvas = canvas;
  6056. canvas.mozOpaque = true;
  6057. var ctx = canvas.getContext('2d', { alpha: false });
  6058. var outputScale = (0, _ui_utils.getOutputScale)(ctx);
  6059. canvas.width = this.canvasWidth * outputScale.sx | 0;
  6060. canvas.height = this.canvasHeight * outputScale.sy | 0;
  6061. canvas.style.width = this.canvasWidth + 'px';
  6062. canvas.style.height = this.canvasHeight + 'px';
  6063. if (!noCtxScale && outputScale.scaled) {
  6064. ctx.scale(outputScale.sx, outputScale.sy);
  6065. }
  6066. return ctx;
  6067. }
  6068. }, {
  6069. key: '_convertCanvasToImage',
  6070. value: function _convertCanvasToImage() {
  6071. var _this = this;
  6072. if (!this.canvas) {
  6073. return;
  6074. }
  6075. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6076. return;
  6077. }
  6078. var id = this.renderingId;
  6079. var className = 'thumbnailImage';
  6080. if (this.disableCanvasToImageConversion) {
  6081. this.canvas.id = id;
  6082. this.canvas.className = className;
  6083. this.l10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}').then(function (msg) {
  6084. _this.canvas.setAttribute('aria-label', msg);
  6085. });
  6086. this.div.setAttribute('data-loaded', true);
  6087. this.ring.appendChild(this.canvas);
  6088. return;
  6089. }
  6090. var image = document.createElement('img');
  6091. image.id = id;
  6092. image.className = className;
  6093. this.l10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}').then(function (msg) {
  6094. image.setAttribute('aria-label', msg);
  6095. });
  6096. image.style.width = this.canvasWidth + 'px';
  6097. image.style.height = this.canvasHeight + 'px';
  6098. image.src = this.canvas.toDataURL();
  6099. this.image = image;
  6100. this.div.setAttribute('data-loaded', true);
  6101. this.ring.appendChild(image);
  6102. this.canvas.width = 0;
  6103. this.canvas.height = 0;
  6104. delete this.canvas;
  6105. }
  6106. }, {
  6107. key: 'draw',
  6108. value: function draw() {
  6109. var _this2 = this;
  6110. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  6111. console.error('Must be in new state before drawing');
  6112. return Promise.resolve(undefined);
  6113. }
  6114. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  6115. var renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  6116. var finishRenderTask = function finishRenderTask(error) {
  6117. if (renderTask === _this2.renderTask) {
  6118. _this2.renderTask = null;
  6119. }
  6120. if (error === 'cancelled' || error instanceof _pdfjsLib.RenderingCancelledException) {
  6121. renderCapability.resolve(undefined);
  6122. return;
  6123. }
  6124. _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  6125. _this2._convertCanvasToImage();
  6126. if (!error) {
  6127. renderCapability.resolve(undefined);
  6128. } else {
  6129. renderCapability.reject(error);
  6130. }
  6131. };
  6132. var ctx = this._getPageDrawContext();
  6133. var drawViewport = this.viewport.clone({ scale: this.scale });
  6134. var renderContinueCallback = function renderContinueCallback(cont) {
  6135. if (!_this2.renderingQueue.isHighestPriority(_this2)) {
  6136. _this2.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  6137. _this2.resume = function () {
  6138. _this2.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  6139. cont();
  6140. };
  6141. return;
  6142. }
  6143. cont();
  6144. };
  6145. var renderContext = {
  6146. canvasContext: ctx,
  6147. viewport: drawViewport
  6148. };
  6149. var renderTask = this.renderTask = this.pdfPage.render(renderContext);
  6150. renderTask.onContinue = renderContinueCallback;
  6151. renderTask.promise.then(function () {
  6152. finishRenderTask(null);
  6153. }, function (error) {
  6154. finishRenderTask(error);
  6155. });
  6156. return renderCapability.promise;
  6157. }
  6158. }, {
  6159. key: 'setImage',
  6160. value: function setImage(pageView) {
  6161. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  6162. return;
  6163. }
  6164. var img = pageView.canvas;
  6165. if (!img) {
  6166. return;
  6167. }
  6168. if (!this.pdfPage) {
  6169. this.setPdfPage(pageView.pdfPage);
  6170. }
  6171. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  6172. var ctx = this._getPageDrawContext(true);
  6173. var canvas = ctx.canvas;
  6174. if (img.width <= 2 * canvas.width) {
  6175. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  6176. this._convertCanvasToImage();
  6177. return;
  6178. }
  6179. var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  6180. var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  6181. var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  6182. var reducedImageCtx = reducedImage.getContext('2d');
  6183. while (reducedWidth > img.width || reducedHeight > img.height) {
  6184. reducedWidth >>= 1;
  6185. reducedHeight >>= 1;
  6186. }
  6187. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  6188. while (reducedWidth > 2 * canvas.width) {
  6189. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  6190. reducedWidth >>= 1;
  6191. reducedHeight >>= 1;
  6192. }
  6193. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  6194. this._convertCanvasToImage();
  6195. }
  6196. }, {
  6197. key: 'setPageLabel',
  6198. value: function setPageLabel(label) {
  6199. var _this3 = this;
  6200. this.pageLabel = typeof label === 'string' ? label : null;
  6201. this.l10n.get('thumb_page_title', { page: this.pageId }, 'Page {{page}}').then(function (msg) {
  6202. _this3.anchor.title = msg;
  6203. });
  6204. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6205. return;
  6206. }
  6207. this.l10n.get('thumb_page_canvas', { page: this.pageId }, 'Thumbnail of Page {{page}}').then(function (ariaLabel) {
  6208. if (_this3.image) {
  6209. _this3.image.setAttribute('aria-label', ariaLabel);
  6210. } else if (_this3.disableCanvasToImageConversion && _this3.canvas) {
  6211. _this3.canvas.setAttribute('aria-label', ariaLabel);
  6212. }
  6213. });
  6214. }
  6215. }, {
  6216. key: 'pageId',
  6217. get: function get() {
  6218. return this.pageLabel !== null ? this.pageLabel : this.id;
  6219. }
  6220. }], [{
  6221. key: 'cleanup',
  6222. value: function cleanup() {
  6223. TempImageFactory.destroyCanvas();
  6224. }
  6225. }]);
  6226. return PDFThumbnailView;
  6227. }();
  6228. exports.PDFThumbnailView = PDFThumbnailView;
  6229. /***/ }),
  6230. /* 21 */
  6231. /***/ (function(module, exports, __webpack_require__) {
  6232. "use strict";
  6233. Object.defineProperty(exports, "__esModule", {
  6234. value: true
  6235. });
  6236. exports.PDFViewer = undefined;
  6237. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6238. var _ui_utils = __webpack_require__(0);
  6239. var _base_viewer = __webpack_require__(22);
  6240. var _pdfjsLib = __webpack_require__(1);
  6241. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6242. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6243. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6244. var PDFViewer = function (_BaseViewer) {
  6245. _inherits(PDFViewer, _BaseViewer);
  6246. function PDFViewer() {
  6247. _classCallCheck(this, PDFViewer);
  6248. return _possibleConstructorReturn(this, (PDFViewer.__proto__ || Object.getPrototypeOf(PDFViewer)).apply(this, arguments));
  6249. }
  6250. _createClass(PDFViewer, [{
  6251. key: '_scrollIntoView',
  6252. value: function _scrollIntoView(_ref) {
  6253. var pageDiv = _ref.pageDiv,
  6254. _ref$pageSpot = _ref.pageSpot,
  6255. pageSpot = _ref$pageSpot === undefined ? null : _ref$pageSpot;
  6256. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  6257. }
  6258. }, {
  6259. key: '_getVisiblePages',
  6260. value: function _getVisiblePages() {
  6261. if (!this.isInPresentationMode) {
  6262. return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true);
  6263. }
  6264. var currentPage = this._pages[this._currentPageNumber - 1];
  6265. var visible = [{
  6266. id: currentPage.id,
  6267. view: currentPage
  6268. }];
  6269. return {
  6270. first: currentPage,
  6271. last: currentPage,
  6272. views: visible
  6273. };
  6274. }
  6275. }, {
  6276. key: 'update',
  6277. value: function update() {
  6278. var visible = this._getVisiblePages();
  6279. var visiblePages = visible.views,
  6280. numVisiblePages = visiblePages.length;
  6281. if (numVisiblePages === 0) {
  6282. return;
  6283. }
  6284. this._resizeBuffer(numVisiblePages);
  6285. this.renderingQueue.renderHighestPriority(visible);
  6286. var currentId = this._currentPageNumber;
  6287. var stillFullyVisible = false;
  6288. for (var i = 0; i < numVisiblePages; ++i) {
  6289. var page = visiblePages[i];
  6290. if (page.percent < 100) {
  6291. break;
  6292. }
  6293. if (page.id === currentId) {
  6294. stillFullyVisible = true;
  6295. break;
  6296. }
  6297. }
  6298. if (!stillFullyVisible) {
  6299. currentId = visiblePages[0].id;
  6300. }
  6301. if (!this.isInPresentationMode) {
  6302. this._setCurrentPageNumber(currentId);
  6303. }
  6304. this._updateLocation(visible.first);
  6305. this.eventBus.dispatch('updateviewarea', {
  6306. source: this,
  6307. location: this._location
  6308. });
  6309. }
  6310. }, {
  6311. key: '_setDocumentViewerElement',
  6312. get: function get() {
  6313. return (0, _pdfjsLib.shadow)(this, '_setDocumentViewerElement', this.viewer);
  6314. }
  6315. }]);
  6316. return PDFViewer;
  6317. }(_base_viewer.BaseViewer);
  6318. exports.PDFViewer = PDFViewer;
  6319. /***/ }),
  6320. /* 22 */
  6321. /***/ (function(module, exports, __webpack_require__) {
  6322. "use strict";
  6323. Object.defineProperty(exports, "__esModule", {
  6324. value: true
  6325. });
  6326. exports.BaseViewer = undefined;
  6327. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6328. var _pdfjsLib = __webpack_require__(1);
  6329. var _ui_utils = __webpack_require__(0);
  6330. var _pdf_rendering_queue = __webpack_require__(3);
  6331. var _annotation_layer_builder = __webpack_require__(23);
  6332. var _dom_events = __webpack_require__(2);
  6333. var _pdf_page_view = __webpack_require__(24);
  6334. var _pdf_link_service = __webpack_require__(5);
  6335. var _text_layer_builder = __webpack_require__(25);
  6336. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6337. var DEFAULT_CACHE_SIZE = 10;
  6338. function PDFPageViewBuffer(size) {
  6339. var data = [];
  6340. this.push = function (view) {
  6341. var i = data.indexOf(view);
  6342. if (i >= 0) {
  6343. data.splice(i, 1);
  6344. }
  6345. data.push(view);
  6346. if (data.length > size) {
  6347. data.shift().destroy();
  6348. }
  6349. };
  6350. this.resize = function (newSize) {
  6351. size = newSize;
  6352. while (data.length > size) {
  6353. data.shift().destroy();
  6354. }
  6355. };
  6356. }
  6357. function isSameScale(oldScale, newScale) {
  6358. if (newScale === oldScale) {
  6359. return true;
  6360. }
  6361. if (Math.abs(newScale - oldScale) < 1e-15) {
  6362. return true;
  6363. }
  6364. return false;
  6365. }
  6366. function isPortraitOrientation(size) {
  6367. return size.width <= size.height;
  6368. }
  6369. var BaseViewer = function () {
  6370. function BaseViewer(options) {
  6371. _classCallCheck(this, BaseViewer);
  6372. if (this.constructor === BaseViewer) {
  6373. throw new Error('Cannot initialize BaseViewer.');
  6374. }
  6375. this._name = this.constructor.name;
  6376. this.container = options.container;
  6377. this.viewer = options.viewer || options.container.firstElementChild;
  6378. this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
  6379. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  6380. this.downloadManager = options.downloadManager || null;
  6381. this.removePageBorders = options.removePageBorders || false;
  6382. this.enhanceTextSelection = options.enhanceTextSelection || false;
  6383. this.renderInteractiveForms = options.renderInteractiveForms || false;
  6384. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  6385. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  6386. this.l10n = options.l10n || _ui_utils.NullL10n;
  6387. this.defaultRenderingQueue = !options.renderingQueue;
  6388. if (this.defaultRenderingQueue) {
  6389. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  6390. this.renderingQueue.setViewer(this);
  6391. } else {
  6392. this.renderingQueue = options.renderingQueue;
  6393. }
  6394. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  6395. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  6396. this._resetView();
  6397. if (this.removePageBorders) {
  6398. this.viewer.classList.add('removePageBorders');
  6399. }
  6400. }
  6401. _createClass(BaseViewer, [{
  6402. key: 'getPageView',
  6403. value: function getPageView(index) {
  6404. return this._pages[index];
  6405. }
  6406. }, {
  6407. key: '_setCurrentPageNumber',
  6408. value: function _setCurrentPageNumber(val) {
  6409. var resetCurrentPageView = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  6410. if (this._currentPageNumber === val) {
  6411. if (resetCurrentPageView) {
  6412. this._resetCurrentPageView();
  6413. }
  6414. return;
  6415. }
  6416. if (!(0 < val && val <= this.pagesCount)) {
  6417. console.error(this._name + '._setCurrentPageNumber: "' + val + '" is out of bounds.');
  6418. return;
  6419. }
  6420. var arg = {
  6421. source: this,
  6422. pageNumber: val,
  6423. pageLabel: this._pageLabels && this._pageLabels[val - 1]
  6424. };
  6425. this._currentPageNumber = val;
  6426. this.eventBus.dispatch('pagechanging', arg);
  6427. this.eventBus.dispatch('pagechange', arg);
  6428. if (resetCurrentPageView) {
  6429. this._resetCurrentPageView();
  6430. }
  6431. }
  6432. }, {
  6433. key: 'setDocument',
  6434. value: function setDocument(pdfDocument) {
  6435. var _this = this;
  6436. if (this.pdfDocument) {
  6437. this._cancelRendering();
  6438. this._resetView();
  6439. }
  6440. this.pdfDocument = pdfDocument;
  6441. if (!pdfDocument) {
  6442. return;
  6443. }
  6444. var pagesCount = pdfDocument.numPages;
  6445. var pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  6446. this.pagesPromise = pagesCapability.promise;
  6447. pagesCapability.promise.then(function () {
  6448. _this._pageViewsReady = true;
  6449. _this.eventBus.dispatch('pagesloaded', {
  6450. source: _this,
  6451. pagesCount: pagesCount
  6452. });
  6453. });
  6454. var isOnePageRenderedResolved = false;
  6455. var onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  6456. this.onePageRendered = onePageRenderedCapability.promise;
  6457. var bindOnAfterAndBeforeDraw = function bindOnAfterAndBeforeDraw(pageView) {
  6458. pageView.onBeforeDraw = function () {
  6459. _this._buffer.push(pageView);
  6460. };
  6461. pageView.onAfterDraw = function () {
  6462. if (!isOnePageRenderedResolved) {
  6463. isOnePageRenderedResolved = true;
  6464. onePageRenderedCapability.resolve();
  6465. }
  6466. };
  6467. };
  6468. var firstPagePromise = pdfDocument.getPage(1);
  6469. this.firstPagePromise = firstPagePromise;
  6470. firstPagePromise.then(function (pdfPage) {
  6471. var scale = _this.currentScale;
  6472. var viewport = pdfPage.getViewport(scale * _ui_utils.CSS_UNITS);
  6473. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  6474. var textLayerFactory = null;
  6475. if (!_pdfjsLib.PDFJS.disableTextLayer) {
  6476. textLayerFactory = _this;
  6477. }
  6478. var pageView = new _pdf_page_view.PDFPageView({
  6479. container: _this._setDocumentViewerElement,
  6480. eventBus: _this.eventBus,
  6481. id: pageNum,
  6482. scale: scale,
  6483. defaultViewport: viewport.clone(),
  6484. renderingQueue: _this.renderingQueue,
  6485. textLayerFactory: textLayerFactory,
  6486. annotationLayerFactory: _this,
  6487. enhanceTextSelection: _this.enhanceTextSelection,
  6488. renderInteractiveForms: _this.renderInteractiveForms,
  6489. renderer: _this.renderer,
  6490. l10n: _this.l10n
  6491. });
  6492. bindOnAfterAndBeforeDraw(pageView);
  6493. _this._pages.push(pageView);
  6494. }
  6495. onePageRenderedCapability.promise.then(function () {
  6496. if (_pdfjsLib.PDFJS.disableAutoFetch) {
  6497. pagesCapability.resolve();
  6498. return;
  6499. }
  6500. var getPagesLeft = pagesCount;
  6501. var _loop = function _loop(_pageNum) {
  6502. pdfDocument.getPage(_pageNum).then(function (pdfPage) {
  6503. var pageView = _this._pages[_pageNum - 1];
  6504. if (!pageView.pdfPage) {
  6505. pageView.setPdfPage(pdfPage);
  6506. }
  6507. _this.linkService.cachePageRef(_pageNum, pdfPage.ref);
  6508. if (--getPagesLeft === 0) {
  6509. pagesCapability.resolve();
  6510. }
  6511. }, function (reason) {
  6512. console.error('Unable to get page ' + _pageNum + ' to initialize viewer', reason);
  6513. if (--getPagesLeft === 0) {
  6514. pagesCapability.resolve();
  6515. }
  6516. });
  6517. };
  6518. for (var _pageNum = 1; _pageNum <= pagesCount; ++_pageNum) {
  6519. _loop(_pageNum);
  6520. }
  6521. });
  6522. _this.eventBus.dispatch('pagesinit', { source: _this });
  6523. if (_this.defaultRenderingQueue) {
  6524. _this.update();
  6525. }
  6526. if (_this.findController) {
  6527. _this.findController.resolveFirstPage();
  6528. }
  6529. }).catch(function (reason) {
  6530. console.error('Unable to initialize viewer', reason);
  6531. });
  6532. }
  6533. }, {
  6534. key: 'setPageLabels',
  6535. value: function setPageLabels(labels) {
  6536. if (!this.pdfDocument) {
  6537. return;
  6538. }
  6539. if (!labels) {
  6540. this._pageLabels = null;
  6541. } else if (!(labels instanceof Array && this.pdfDocument.numPages === labels.length)) {
  6542. this._pageLabels = null;
  6543. console.error(this._name + '.setPageLabels: Invalid page labels.');
  6544. } else {
  6545. this._pageLabels = labels;
  6546. }
  6547. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  6548. var pageView = this._pages[i];
  6549. var label = this._pageLabels && this._pageLabels[i];
  6550. pageView.setPageLabel(label);
  6551. }
  6552. }
  6553. }, {
  6554. key: '_resetView',
  6555. value: function _resetView() {
  6556. this._pages = [];
  6557. this._currentPageNumber = 1;
  6558. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  6559. this._currentScaleValue = null;
  6560. this._pageLabels = null;
  6561. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  6562. this._location = null;
  6563. this._pagesRotation = 0;
  6564. this._pagesRequests = [];
  6565. this._pageViewsReady = false;
  6566. this.viewer.textContent = '';
  6567. }
  6568. }, {
  6569. key: '_scrollUpdate',
  6570. value: function _scrollUpdate() {
  6571. if (this.pagesCount === 0) {
  6572. return;
  6573. }
  6574. this.update();
  6575. }
  6576. }, {
  6577. key: '_scrollIntoView',
  6578. value: function _scrollIntoView(_ref) {
  6579. var pageDiv = _ref.pageDiv,
  6580. _ref$pageSpot = _ref.pageSpot,
  6581. pageSpot = _ref$pageSpot === undefined ? null : _ref$pageSpot,
  6582. _ref$pageNumber = _ref.pageNumber,
  6583. pageNumber = _ref$pageNumber === undefined ? null : _ref$pageNumber;
  6584. throw new Error('Not implemented: _scrollIntoView');
  6585. }
  6586. }, {
  6587. key: '_setScaleDispatchEvent',
  6588. value: function _setScaleDispatchEvent(newScale, newValue) {
  6589. var preset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  6590. var arg = {
  6591. source: this,
  6592. scale: newScale,
  6593. presetValue: preset ? newValue : undefined
  6594. };
  6595. this.eventBus.dispatch('scalechanging', arg);
  6596. this.eventBus.dispatch('scalechange', arg);
  6597. }
  6598. }, {
  6599. key: '_setScaleUpdatePages',
  6600. value: function _setScaleUpdatePages(newScale, newValue) {
  6601. var noScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  6602. var preset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  6603. this._currentScaleValue = newValue.toString();
  6604. if (isSameScale(this._currentScale, newScale)) {
  6605. if (preset) {
  6606. this._setScaleDispatchEvent(newScale, newValue, true);
  6607. }
  6608. return;
  6609. }
  6610. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  6611. this._pages[i].update(newScale);
  6612. }
  6613. this._currentScale = newScale;
  6614. if (!noScroll) {
  6615. var page = this._currentPageNumber,
  6616. dest = void 0;
  6617. if (this._location && !_pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  6618. page = this._location.pageNumber;
  6619. dest = [null, { name: 'XYZ' }, this._location.left, this._location.top, null];
  6620. }
  6621. this.scrollPageIntoView({
  6622. pageNumber: page,
  6623. destArray: dest,
  6624. allowNegativeOffset: true
  6625. });
  6626. }
  6627. this._setScaleDispatchEvent(newScale, newValue, preset);
  6628. if (this.defaultRenderingQueue) {
  6629. this.update();
  6630. }
  6631. }
  6632. }, {
  6633. key: '_setScale',
  6634. value: function _setScale(value) {
  6635. var noScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  6636. var scale = parseFloat(value);
  6637. if (scale > 0) {
  6638. this._setScaleUpdatePages(scale, value, noScroll, false);
  6639. } else {
  6640. var currentPage = this._pages[this._currentPageNumber - 1];
  6641. if (!currentPage) {
  6642. return;
  6643. }
  6644. var hPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  6645. var vPadding = this.isInPresentationMode || this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  6646. var pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale;
  6647. var pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  6648. switch (value) {
  6649. case 'page-actual':
  6650. scale = 1;
  6651. break;
  6652. case 'page-width':
  6653. scale = pageWidthScale;
  6654. break;
  6655. case 'page-height':
  6656. scale = pageHeightScale;
  6657. break;
  6658. case 'page-fit':
  6659. scale = Math.min(pageWidthScale, pageHeightScale);
  6660. break;
  6661. case 'auto':
  6662. var isLandscape = currentPage.width > currentPage.height;
  6663. var horizontalScale = isLandscape ? Math.min(pageHeightScale, pageWidthScale) : pageWidthScale;
  6664. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  6665. break;
  6666. default:
  6667. console.error(this._name + '._setScale: "' + value + '" is an unknown zoom value.');
  6668. return;
  6669. }
  6670. this._setScaleUpdatePages(scale, value, noScroll, true);
  6671. }
  6672. }
  6673. }, {
  6674. key: '_resetCurrentPageView',
  6675. value: function _resetCurrentPageView() {
  6676. if (this.isInPresentationMode) {
  6677. this._setScale(this._currentScaleValue, true);
  6678. }
  6679. var pageView = this._pages[this._currentPageNumber - 1];
  6680. this._scrollIntoView({ pageDiv: pageView.div });
  6681. }
  6682. }, {
  6683. key: 'scrollPageIntoView',
  6684. value: function scrollPageIntoView(params) {
  6685. if (arguments.length > 1 || typeof params === 'number') {
  6686. console.error('Call of scrollPageIntoView() with obsolete signature.');
  6687. return;
  6688. }
  6689. if (!this.pdfDocument) {
  6690. return;
  6691. }
  6692. var pageNumber = params.pageNumber || 0;
  6693. var dest = params.destArray || null;
  6694. var allowNegativeOffset = params.allowNegativeOffset || false;
  6695. if (this.isInPresentationMode || !dest) {
  6696. this._setCurrentPageNumber(pageNumber, true);
  6697. return;
  6698. }
  6699. var pageView = this._pages[pageNumber - 1];
  6700. if (!pageView) {
  6701. console.error(this._name + '.scrollPageIntoView: Invalid "pageNumber" parameter.');
  6702. return;
  6703. }
  6704. var x = 0,
  6705. y = 0;
  6706. var width = 0,
  6707. height = 0,
  6708. widthScale = void 0,
  6709. heightScale = void 0;
  6710. var changeOrientation = pageView.rotation % 180 === 0 ? false : true;
  6711. var pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  6712. var pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  6713. var scale = 0;
  6714. switch (dest[1].name) {
  6715. case 'XYZ':
  6716. x = dest[2];
  6717. y = dest[3];
  6718. scale = dest[4];
  6719. x = x !== null ? x : 0;
  6720. y = y !== null ? y : pageHeight;
  6721. break;
  6722. case 'Fit':
  6723. case 'FitB':
  6724. scale = 'page-fit';
  6725. break;
  6726. case 'FitH':
  6727. case 'FitBH':
  6728. y = dest[2];
  6729. scale = 'page-width';
  6730. if (y === null && this._location) {
  6731. x = this._location.left;
  6732. y = this._location.top;
  6733. }
  6734. break;
  6735. case 'FitV':
  6736. case 'FitBV':
  6737. x = dest[2];
  6738. width = pageWidth;
  6739. height = pageHeight;
  6740. scale = 'page-height';
  6741. break;
  6742. case 'FitR':
  6743. x = dest[2];
  6744. y = dest[3];
  6745. width = dest[4] - x;
  6746. height = dest[5] - y;
  6747. var hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  6748. var vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  6749. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  6750. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  6751. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  6752. break;
  6753. default:
  6754. console.error(this._name + '.scrollPageIntoView: "' + dest[1].name + '" ' + 'is not a valid destination type.');
  6755. return;
  6756. }
  6757. if (scale && scale !== this._currentScale) {
  6758. this.currentScaleValue = scale;
  6759. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  6760. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  6761. }
  6762. if (scale === 'page-fit' && !dest[4]) {
  6763. this._scrollIntoView({
  6764. pageDiv: pageView.div,
  6765. pageNumber: pageNumber
  6766. });
  6767. return;
  6768. }
  6769. var boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  6770. var left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  6771. var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  6772. if (!allowNegativeOffset) {
  6773. left = Math.max(left, 0);
  6774. top = Math.max(top, 0);
  6775. }
  6776. this._scrollIntoView({
  6777. pageDiv: pageView.div,
  6778. pageSpot: {
  6779. left: left,
  6780. top: top
  6781. },
  6782. pageNumber: pageNumber
  6783. });
  6784. }
  6785. }, {
  6786. key: '_resizeBuffer',
  6787. value: function _resizeBuffer(numVisiblePages) {
  6788. var suggestedCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  6789. this._buffer.resize(suggestedCacheSize);
  6790. }
  6791. }, {
  6792. key: '_updateLocation',
  6793. value: function _updateLocation(firstPage) {
  6794. var currentScale = this._currentScale;
  6795. var currentScaleValue = this._currentScaleValue;
  6796. var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  6797. var pageNumber = firstPage.id;
  6798. var pdfOpenParams = '#page=' + pageNumber;
  6799. pdfOpenParams += '&zoom=' + normalizedScaleValue;
  6800. var currentPageView = this._pages[pageNumber - 1];
  6801. var container = this.container;
  6802. var topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  6803. var intLeft = Math.round(topLeft[0]);
  6804. var intTop = Math.round(topLeft[1]);
  6805. pdfOpenParams += ',' + intLeft + ',' + intTop;
  6806. this._location = {
  6807. pageNumber: pageNumber,
  6808. scale: normalizedScaleValue,
  6809. top: intTop,
  6810. left: intLeft,
  6811. rotation: this._pagesRotation,
  6812. pdfOpenParams: pdfOpenParams
  6813. };
  6814. }
  6815. }, {
  6816. key: 'update',
  6817. value: function update() {
  6818. throw new Error('Not implemented: update');
  6819. }
  6820. }, {
  6821. key: 'containsElement',
  6822. value: function containsElement(element) {
  6823. return this.container.contains(element);
  6824. }
  6825. }, {
  6826. key: 'focus',
  6827. value: function focus() {
  6828. this.container.focus();
  6829. }
  6830. }, {
  6831. key: '_getVisiblePages',
  6832. value: function _getVisiblePages() {
  6833. throw new Error('Not implemented: _getVisiblePages');
  6834. }
  6835. }, {
  6836. key: 'cleanup',
  6837. value: function cleanup() {
  6838. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  6839. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6840. this._pages[i].reset();
  6841. }
  6842. }
  6843. }
  6844. }, {
  6845. key: '_cancelRendering',
  6846. value: function _cancelRendering() {
  6847. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  6848. if (this._pages[i]) {
  6849. this._pages[i].cancelRendering();
  6850. }
  6851. }
  6852. }
  6853. }, {
  6854. key: '_ensurePdfPageLoaded',
  6855. value: function _ensurePdfPageLoaded(pageView) {
  6856. var _this2 = this;
  6857. if (pageView.pdfPage) {
  6858. return Promise.resolve(pageView.pdfPage);
  6859. }
  6860. var pageNumber = pageView.id;
  6861. if (this._pagesRequests[pageNumber]) {
  6862. return this._pagesRequests[pageNumber];
  6863. }
  6864. var promise = this.pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  6865. if (!pageView.pdfPage) {
  6866. pageView.setPdfPage(pdfPage);
  6867. }
  6868. _this2._pagesRequests[pageNumber] = null;
  6869. return pdfPage;
  6870. }).catch(function (reason) {
  6871. console.error('Unable to get page for page view', reason);
  6872. _this2._pagesRequests[pageNumber] = null;
  6873. });
  6874. this._pagesRequests[pageNumber] = promise;
  6875. return promise;
  6876. }
  6877. }, {
  6878. key: 'forceRendering',
  6879. value: function forceRendering(currentlyVisiblePages) {
  6880. var _this3 = this;
  6881. var visiblePages = currentlyVisiblePages || this._getVisiblePages();
  6882. var pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, this.scroll.down);
  6883. if (pageView) {
  6884. this._ensurePdfPageLoaded(pageView).then(function () {
  6885. _this3.renderingQueue.renderView(pageView);
  6886. });
  6887. return true;
  6888. }
  6889. return false;
  6890. }
  6891. }, {
  6892. key: 'getPageTextContent',
  6893. value: function getPageTextContent(pageIndex) {
  6894. return this.pdfDocument.getPage(pageIndex + 1).then(function (page) {
  6895. return page.getTextContent({ normalizeWhitespace: true });
  6896. });
  6897. }
  6898. }, {
  6899. key: 'createTextLayerBuilder',
  6900. value: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
  6901. var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  6902. return new _text_layer_builder.TextLayerBuilder({
  6903. textLayerDiv: textLayerDiv,
  6904. eventBus: this.eventBus,
  6905. pageIndex: pageIndex,
  6906. viewport: viewport,
  6907. findController: this.isInPresentationMode ? null : this.findController,
  6908. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  6909. });
  6910. }
  6911. }, {
  6912. key: 'createAnnotationLayerBuilder',
  6913. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  6914. var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  6915. var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
  6916. return new _annotation_layer_builder.AnnotationLayerBuilder({
  6917. pageDiv: pageDiv,
  6918. pdfPage: pdfPage,
  6919. renderInteractiveForms: renderInteractiveForms,
  6920. linkService: this.linkService,
  6921. downloadManager: this.downloadManager,
  6922. l10n: l10n
  6923. });
  6924. }
  6925. }, {
  6926. key: 'setFindController',
  6927. value: function setFindController(findController) {
  6928. this.findController = findController;
  6929. }
  6930. }, {
  6931. key: 'getPagesOverview',
  6932. value: function getPagesOverview() {
  6933. var pagesOverview = this._pages.map(function (pageView) {
  6934. var viewport = pageView.pdfPage.getViewport(1);
  6935. return {
  6936. width: viewport.width,
  6937. height: viewport.height,
  6938. rotation: viewport.rotation
  6939. };
  6940. });
  6941. if (!this.enablePrintAutoRotate) {
  6942. return pagesOverview;
  6943. }
  6944. var isFirstPagePortrait = isPortraitOrientation(pagesOverview[0]);
  6945. return pagesOverview.map(function (size) {
  6946. if (isFirstPagePortrait === isPortraitOrientation(size)) {
  6947. return size;
  6948. }
  6949. return {
  6950. width: size.height,
  6951. height: size.width,
  6952. rotation: (size.rotation + 90) % 360
  6953. };
  6954. });
  6955. }
  6956. }, {
  6957. key: 'pagesCount',
  6958. get: function get() {
  6959. return this._pages.length;
  6960. }
  6961. }, {
  6962. key: 'pageViewsReady',
  6963. get: function get() {
  6964. return this._pageViewsReady;
  6965. }
  6966. }, {
  6967. key: 'currentPageNumber',
  6968. get: function get() {
  6969. return this._currentPageNumber;
  6970. },
  6971. set: function set(val) {
  6972. if (!Number.isInteger(val)) {
  6973. throw new Error('Invalid page number.');
  6974. }
  6975. if (!this.pdfDocument) {
  6976. return;
  6977. }
  6978. this._setCurrentPageNumber(val, true);
  6979. }
  6980. }, {
  6981. key: 'currentPageLabel',
  6982. get: function get() {
  6983. return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
  6984. },
  6985. set: function set(val) {
  6986. var pageNumber = val | 0;
  6987. if (this._pageLabels) {
  6988. var i = this._pageLabels.indexOf(val);
  6989. if (i >= 0) {
  6990. pageNumber = i + 1;
  6991. }
  6992. }
  6993. this.currentPageNumber = pageNumber;
  6994. }
  6995. }, {
  6996. key: 'currentScale',
  6997. get: function get() {
  6998. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  6999. },
  7000. set: function set(val) {
  7001. if (isNaN(val)) {
  7002. throw new Error('Invalid numeric scale');
  7003. }
  7004. if (!this.pdfDocument) {
  7005. return;
  7006. }
  7007. this._setScale(val, false);
  7008. }
  7009. }, {
  7010. key: 'currentScaleValue',
  7011. get: function get() {
  7012. return this._currentScaleValue;
  7013. },
  7014. set: function set(val) {
  7015. if (!this.pdfDocument) {
  7016. return;
  7017. }
  7018. this._setScale(val, false);
  7019. }
  7020. }, {
  7021. key: 'pagesRotation',
  7022. get: function get() {
  7023. return this._pagesRotation;
  7024. },
  7025. set: function set(rotation) {
  7026. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7027. throw new Error('Invalid pages rotation angle.');
  7028. }
  7029. if (!this.pdfDocument) {
  7030. return;
  7031. }
  7032. if (this._pagesRotation === rotation) {
  7033. return;
  7034. }
  7035. this._pagesRotation = rotation;
  7036. var pageNumber = this._currentPageNumber;
  7037. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  7038. var pageView = this._pages[i];
  7039. pageView.update(pageView.scale, rotation);
  7040. }
  7041. if (this._currentScaleValue) {
  7042. this._setScale(this._currentScaleValue, true);
  7043. }
  7044. this.eventBus.dispatch('rotationchanging', {
  7045. source: this,
  7046. pagesRotation: rotation,
  7047. pageNumber: pageNumber
  7048. });
  7049. if (this.defaultRenderingQueue) {
  7050. this.update();
  7051. }
  7052. }
  7053. }, {
  7054. key: '_setDocumentViewerElement',
  7055. get: function get() {
  7056. throw new Error('Not implemented: _setDocumentViewerElement');
  7057. }
  7058. }, {
  7059. key: 'isInPresentationMode',
  7060. get: function get() {
  7061. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  7062. }
  7063. }, {
  7064. key: 'isChangingPresentationMode',
  7065. get: function get() {
  7066. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  7067. }
  7068. }, {
  7069. key: 'isHorizontalScrollbarEnabled',
  7070. get: function get() {
  7071. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  7072. }
  7073. }, {
  7074. key: 'hasEqualPageSizes',
  7075. get: function get() {
  7076. var firstPageView = this._pages[0];
  7077. for (var i = 1, ii = this._pages.length; i < ii; ++i) {
  7078. var pageView = this._pages[i];
  7079. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  7080. return false;
  7081. }
  7082. }
  7083. return true;
  7084. }
  7085. }]);
  7086. return BaseViewer;
  7087. }();
  7088. exports.BaseViewer = BaseViewer;
  7089. /***/ }),
  7090. /* 23 */
  7091. /***/ (function(module, exports, __webpack_require__) {
  7092. "use strict";
  7093. Object.defineProperty(exports, "__esModule", {
  7094. value: true
  7095. });
  7096. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = undefined;
  7097. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  7098. var _pdfjsLib = __webpack_require__(1);
  7099. var _ui_utils = __webpack_require__(0);
  7100. var _pdf_link_service = __webpack_require__(5);
  7101. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7102. var AnnotationLayerBuilder = function () {
  7103. function AnnotationLayerBuilder(_ref) {
  7104. var pageDiv = _ref.pageDiv,
  7105. pdfPage = _ref.pdfPage,
  7106. linkService = _ref.linkService,
  7107. downloadManager = _ref.downloadManager,
  7108. _ref$renderInteractiv = _ref.renderInteractiveForms,
  7109. renderInteractiveForms = _ref$renderInteractiv === undefined ? false : _ref$renderInteractiv,
  7110. _ref$l10n = _ref.l10n,
  7111. l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n;
  7112. _classCallCheck(this, AnnotationLayerBuilder);
  7113. this.pageDiv = pageDiv;
  7114. this.pdfPage = pdfPage;
  7115. this.linkService = linkService;
  7116. this.downloadManager = downloadManager;
  7117. this.renderInteractiveForms = renderInteractiveForms;
  7118. this.l10n = l10n;
  7119. this.div = null;
  7120. this._cancelled = false;
  7121. }
  7122. _createClass(AnnotationLayerBuilder, [{
  7123. key: 'render',
  7124. value: function render(viewport) {
  7125. var _this = this;
  7126. var intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'display';
  7127. this.pdfPage.getAnnotations({ intent: intent }).then(function (annotations) {
  7128. if (_this._cancelled) {
  7129. return;
  7130. }
  7131. var parameters = {
  7132. viewport: viewport.clone({ dontFlip: true }),
  7133. div: _this.div,
  7134. annotations: annotations,
  7135. page: _this.pdfPage,
  7136. renderInteractiveForms: _this.renderInteractiveForms,
  7137. linkService: _this.linkService,
  7138. downloadManager: _this.downloadManager
  7139. };
  7140. if (_this.div) {
  7141. _pdfjsLib.AnnotationLayer.update(parameters);
  7142. } else {
  7143. if (annotations.length === 0) {
  7144. return;
  7145. }
  7146. _this.div = document.createElement('div');
  7147. _this.div.className = 'annotationLayer';
  7148. _this.pageDiv.appendChild(_this.div);
  7149. parameters.div = _this.div;
  7150. _pdfjsLib.AnnotationLayer.render(parameters);
  7151. _this.l10n.translate(_this.div);
  7152. }
  7153. });
  7154. }
  7155. }, {
  7156. key: 'cancel',
  7157. value: function cancel() {
  7158. this._cancelled = true;
  7159. }
  7160. }, {
  7161. key: 'hide',
  7162. value: function hide() {
  7163. if (!this.div) {
  7164. return;
  7165. }
  7166. this.div.setAttribute('hidden', 'true');
  7167. }
  7168. }]);
  7169. return AnnotationLayerBuilder;
  7170. }();
  7171. var DefaultAnnotationLayerFactory = function () {
  7172. function DefaultAnnotationLayerFactory() {
  7173. _classCallCheck(this, DefaultAnnotationLayerFactory);
  7174. }
  7175. _createClass(DefaultAnnotationLayerFactory, [{
  7176. key: 'createAnnotationLayerBuilder',
  7177. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  7178. var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  7179. var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
  7180. return new AnnotationLayerBuilder({
  7181. pageDiv: pageDiv,
  7182. pdfPage: pdfPage,
  7183. renderInteractiveForms: renderInteractiveForms,
  7184. linkService: new _pdf_link_service.SimpleLinkService(),
  7185. l10n: l10n
  7186. });
  7187. }
  7188. }]);
  7189. return DefaultAnnotationLayerFactory;
  7190. }();
  7191. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  7192. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  7193. /***/ }),
  7194. /* 24 */
  7195. /***/ (function(module, exports, __webpack_require__) {
  7196. "use strict";
  7197. Object.defineProperty(exports, "__esModule", {
  7198. value: true
  7199. });
  7200. exports.PDFPageView = undefined;
  7201. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  7202. var _ui_utils = __webpack_require__(0);
  7203. var _pdfjsLib = __webpack_require__(1);
  7204. var _dom_events = __webpack_require__(2);
  7205. var _pdf_rendering_queue = __webpack_require__(3);
  7206. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7207. var PDFPageView = function () {
  7208. function PDFPageView(options) {
  7209. _classCallCheck(this, PDFPageView);
  7210. var container = options.container;
  7211. var defaultViewport = options.defaultViewport;
  7212. this.id = options.id;
  7213. this.renderingId = 'page' + this.id;
  7214. this.pdfPage = null;
  7215. this.pageLabel = null;
  7216. this.rotation = 0;
  7217. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  7218. this.viewport = defaultViewport;
  7219. this.pdfPageRotate = defaultViewport.rotation;
  7220. this.hasRestrictedScaling = false;
  7221. this.enhanceTextSelection = options.enhanceTextSelection || false;
  7222. this.renderInteractiveForms = options.renderInteractiveForms || false;
  7223. this.eventBus = options.eventBus || (0, _dom_events.getGlobalEventBus)();
  7224. this.renderingQueue = options.renderingQueue;
  7225. this.textLayerFactory = options.textLayerFactory;
  7226. this.annotationLayerFactory = options.annotationLayerFactory;
  7227. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7228. this.l10n = options.l10n || _ui_utils.NullL10n;
  7229. this.paintTask = null;
  7230. this.paintedViewportMap = new WeakMap();
  7231. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7232. this.resume = null;
  7233. this.error = null;
  7234. this.onBeforeDraw = null;
  7235. this.onAfterDraw = null;
  7236. this.annotationLayer = null;
  7237. this.textLayer = null;
  7238. this.zoomLayer = null;
  7239. var div = document.createElement('div');
  7240. div.className = 'page';
  7241. div.style.width = Math.floor(this.viewport.width) + 'px';
  7242. div.style.height = Math.floor(this.viewport.height) + 'px';
  7243. div.setAttribute('data-page-number', this.id);
  7244. this.div = div;
  7245. container.appendChild(div);
  7246. }
  7247. _createClass(PDFPageView, [{
  7248. key: 'setPdfPage',
  7249. value: function setPdfPage(pdfPage) {
  7250. this.pdfPage = pdfPage;
  7251. this.pdfPageRotate = pdfPage.rotate;
  7252. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7253. this.viewport = pdfPage.getViewport(this.scale * _ui_utils.CSS_UNITS, totalRotation);
  7254. this.stats = pdfPage.stats;
  7255. this.reset();
  7256. }
  7257. }, {
  7258. key: 'destroy',
  7259. value: function destroy() {
  7260. this.reset();
  7261. if (this.pdfPage) {
  7262. this.pdfPage.cleanup();
  7263. }
  7264. }
  7265. }, {
  7266. key: '_resetZoomLayer',
  7267. value: function _resetZoomLayer() {
  7268. var removeFromDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  7269. if (!this.zoomLayer) {
  7270. return;
  7271. }
  7272. var zoomLayerCanvas = this.zoomLayer.firstChild;
  7273. this.paintedViewportMap.delete(zoomLayerCanvas);
  7274. zoomLayerCanvas.width = 0;
  7275. zoomLayerCanvas.height = 0;
  7276. if (removeFromDOM) {
  7277. this.zoomLayer.remove();
  7278. }
  7279. this.zoomLayer = null;
  7280. }
  7281. }, {
  7282. key: 'reset',
  7283. value: function reset() {
  7284. var keepZoomLayer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  7285. var keepAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  7286. this.cancelRendering(keepAnnotations);
  7287. var div = this.div;
  7288. div.style.width = Math.floor(this.viewport.width) + 'px';
  7289. div.style.height = Math.floor(this.viewport.height) + 'px';
  7290. var childNodes = div.childNodes;
  7291. var currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  7292. var currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
  7293. for (var i = childNodes.length - 1; i >= 0; i--) {
  7294. var node = childNodes[i];
  7295. if (currentZoomLayerNode === node || currentAnnotationNode === node) {
  7296. continue;
  7297. }
  7298. div.removeChild(node);
  7299. }
  7300. div.removeAttribute('data-loaded');
  7301. if (currentAnnotationNode) {
  7302. this.annotationLayer.hide();
  7303. } else if (this.annotationLayer) {
  7304. this.annotationLayer.cancel();
  7305. this.annotationLayer = null;
  7306. }
  7307. if (!currentZoomLayerNode) {
  7308. if (this.canvas) {
  7309. this.paintedViewportMap.delete(this.canvas);
  7310. this.canvas.width = 0;
  7311. this.canvas.height = 0;
  7312. delete this.canvas;
  7313. }
  7314. this._resetZoomLayer();
  7315. }
  7316. if (this.svg) {
  7317. this.paintedViewportMap.delete(this.svg);
  7318. delete this.svg;
  7319. }
  7320. this.loadingIconDiv = document.createElement('div');
  7321. this.loadingIconDiv.className = 'loadingIcon';
  7322. div.appendChild(this.loadingIconDiv);
  7323. }
  7324. }, {
  7325. key: 'update',
  7326. value: function update(scale, rotation) {
  7327. this.scale = scale || this.scale;
  7328. if (typeof rotation !== 'undefined') {
  7329. this.rotation = rotation;
  7330. }
  7331. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7332. this.viewport = this.viewport.clone({
  7333. scale: this.scale * _ui_utils.CSS_UNITS,
  7334. rotation: totalRotation
  7335. });
  7336. if (this.svg) {
  7337. this.cssTransform(this.svg, true);
  7338. this.eventBus.dispatch('pagerendered', {
  7339. source: this,
  7340. pageNumber: this.id,
  7341. cssTransform: true
  7342. });
  7343. return;
  7344. }
  7345. var isScalingRestricted = false;
  7346. if (this.canvas && _pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  7347. var outputScale = this.outputScale;
  7348. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > _pdfjsLib.PDFJS.maxCanvasPixels) {
  7349. isScalingRestricted = true;
  7350. }
  7351. }
  7352. if (this.canvas) {
  7353. if (_pdfjsLib.PDFJS.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  7354. this.cssTransform(this.canvas, true);
  7355. this.eventBus.dispatch('pagerendered', {
  7356. source: this,
  7357. pageNumber: this.id,
  7358. cssTransform: true
  7359. });
  7360. return;
  7361. }
  7362. if (!this.zoomLayer && !this.canvas.hasAttribute('hidden')) {
  7363. this.zoomLayer = this.canvas.parentNode;
  7364. this.zoomLayer.style.position = 'absolute';
  7365. }
  7366. }
  7367. if (this.zoomLayer) {
  7368. this.cssTransform(this.zoomLayer.firstChild);
  7369. }
  7370. this.reset(true, true);
  7371. }
  7372. }, {
  7373. key: 'cancelRendering',
  7374. value: function cancelRendering() {
  7375. var keepAnnotations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  7376. if (this.paintTask) {
  7377. this.paintTask.cancel();
  7378. this.paintTask = null;
  7379. }
  7380. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7381. this.resume = null;
  7382. if (this.textLayer) {
  7383. this.textLayer.cancel();
  7384. this.textLayer = null;
  7385. }
  7386. if (!keepAnnotations && this.annotationLayer) {
  7387. this.annotationLayer.cancel();
  7388. this.annotationLayer = null;
  7389. }
  7390. }
  7391. }, {
  7392. key: 'cssTransform',
  7393. value: function cssTransform(target) {
  7394. var redrawAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  7395. var width = this.viewport.width;
  7396. var height = this.viewport.height;
  7397. var div = this.div;
  7398. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + 'px';
  7399. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + 'px';
  7400. var relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  7401. var absRotation = Math.abs(relativeRotation);
  7402. var scaleX = 1,
  7403. scaleY = 1;
  7404. if (absRotation === 90 || absRotation === 270) {
  7405. scaleX = height / width;
  7406. scaleY = width / height;
  7407. }
  7408. var cssTransform = 'rotate(' + relativeRotation + 'deg) ' + 'scale(' + scaleX + ',' + scaleY + ')';
  7409. _pdfjsLib.CustomStyle.setProp('transform', target, cssTransform);
  7410. if (this.textLayer) {
  7411. var textLayerViewport = this.textLayer.viewport;
  7412. var textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  7413. var textAbsRotation = Math.abs(textRelativeRotation);
  7414. var scale = width / textLayerViewport.width;
  7415. if (textAbsRotation === 90 || textAbsRotation === 270) {
  7416. scale = width / textLayerViewport.height;
  7417. }
  7418. var textLayerDiv = this.textLayer.textLayerDiv;
  7419. var transX = void 0,
  7420. transY = void 0;
  7421. switch (textAbsRotation) {
  7422. case 0:
  7423. transX = transY = 0;
  7424. break;
  7425. case 90:
  7426. transX = 0;
  7427. transY = '-' + textLayerDiv.style.height;
  7428. break;
  7429. case 180:
  7430. transX = '-' + textLayerDiv.style.width;
  7431. transY = '-' + textLayerDiv.style.height;
  7432. break;
  7433. case 270:
  7434. transX = '-' + textLayerDiv.style.width;
  7435. transY = 0;
  7436. break;
  7437. default:
  7438. console.error('Bad rotation value.');
  7439. break;
  7440. }
  7441. _pdfjsLib.CustomStyle.setProp('transform', textLayerDiv, 'rotate(' + textAbsRotation + 'deg) ' + 'scale(' + scale + ', ' + scale + ') ' + 'translate(' + transX + ', ' + transY + ')');
  7442. _pdfjsLib.CustomStyle.setProp('transformOrigin', textLayerDiv, '0% 0%');
  7443. }
  7444. if (redrawAnnotations && this.annotationLayer) {
  7445. this.annotationLayer.render(this.viewport, 'display');
  7446. }
  7447. }
  7448. }, {
  7449. key: 'getPagePoint',
  7450. value: function getPagePoint(x, y) {
  7451. return this.viewport.convertToPdfPoint(x, y);
  7452. }
  7453. }, {
  7454. key: 'draw',
  7455. value: function draw() {
  7456. var _this = this;
  7457. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7458. console.error('Must be in new state before drawing');
  7459. this.reset();
  7460. }
  7461. if (!this.pdfPage) {
  7462. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7463. return Promise.reject(new Error('Page is not loaded'));
  7464. }
  7465. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7466. var pdfPage = this.pdfPage;
  7467. var div = this.div;
  7468. var canvasWrapper = document.createElement('div');
  7469. canvasWrapper.style.width = div.style.width;
  7470. canvasWrapper.style.height = div.style.height;
  7471. canvasWrapper.classList.add('canvasWrapper');
  7472. if (this.annotationLayer && this.annotationLayer.div) {
  7473. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  7474. } else {
  7475. div.appendChild(canvasWrapper);
  7476. }
  7477. var textLayer = null;
  7478. if (this.textLayerFactory) {
  7479. var textLayerDiv = document.createElement('div');
  7480. textLayerDiv.className = 'textLayer';
  7481. textLayerDiv.style.width = canvasWrapper.style.width;
  7482. textLayerDiv.style.height = canvasWrapper.style.height;
  7483. if (this.annotationLayer && this.annotationLayer.div) {
  7484. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  7485. } else {
  7486. div.appendChild(textLayerDiv);
  7487. }
  7488. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.enhanceTextSelection);
  7489. }
  7490. this.textLayer = textLayer;
  7491. var renderContinueCallback = null;
  7492. if (this.renderingQueue) {
  7493. renderContinueCallback = function renderContinueCallback(cont) {
  7494. if (!_this.renderingQueue.isHighestPriority(_this)) {
  7495. _this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  7496. _this.resume = function () {
  7497. _this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7498. cont();
  7499. };
  7500. return;
  7501. }
  7502. cont();
  7503. };
  7504. }
  7505. var finishPaintTask = function finishPaintTask(error) {
  7506. if (paintTask === _this.paintTask) {
  7507. _this.paintTask = null;
  7508. }
  7509. if (error === 'cancelled' || error instanceof _pdfjsLib.RenderingCancelledException) {
  7510. _this.error = null;
  7511. return Promise.resolve(undefined);
  7512. }
  7513. _this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7514. if (_this.loadingIconDiv) {
  7515. div.removeChild(_this.loadingIconDiv);
  7516. delete _this.loadingIconDiv;
  7517. }
  7518. _this._resetZoomLayer(true);
  7519. _this.error = error;
  7520. _this.stats = pdfPage.stats;
  7521. if (_this.onAfterDraw) {
  7522. _this.onAfterDraw();
  7523. }
  7524. _this.eventBus.dispatch('pagerendered', {
  7525. source: _this,
  7526. pageNumber: _this.id,
  7527. cssTransform: false
  7528. });
  7529. if (error) {
  7530. return Promise.reject(error);
  7531. }
  7532. return Promise.resolve(undefined);
  7533. };
  7534. var paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  7535. paintTask.onRenderContinue = renderContinueCallback;
  7536. this.paintTask = paintTask;
  7537. var resultPromise = paintTask.promise.then(function () {
  7538. return finishPaintTask(null).then(function () {
  7539. if (textLayer) {
  7540. var readableStream = pdfPage.streamTextContent({ normalizeWhitespace: true });
  7541. textLayer.setTextContentStream(readableStream);
  7542. textLayer.render();
  7543. }
  7544. });
  7545. }, function (reason) {
  7546. return finishPaintTask(reason);
  7547. });
  7548. if (this.annotationLayerFactory) {
  7549. if (!this.annotationLayer) {
  7550. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.renderInteractiveForms, this.l10n);
  7551. }
  7552. this.annotationLayer.render(this.viewport, 'display');
  7553. }
  7554. div.setAttribute('data-loaded', true);
  7555. if (this.onBeforeDraw) {
  7556. this.onBeforeDraw();
  7557. }
  7558. return resultPromise;
  7559. }
  7560. }, {
  7561. key: 'paintOnCanvas',
  7562. value: function paintOnCanvas(canvasWrapper) {
  7563. var renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  7564. var result = {
  7565. promise: renderCapability.promise,
  7566. onRenderContinue: function onRenderContinue(cont) {
  7567. cont();
  7568. },
  7569. cancel: function cancel() {
  7570. renderTask.cancel();
  7571. }
  7572. };
  7573. var viewport = this.viewport;
  7574. var canvas = document.createElement('canvas');
  7575. canvas.id = this.renderingId;
  7576. canvas.setAttribute('hidden', 'hidden');
  7577. var isCanvasHidden = true;
  7578. var showCanvas = function showCanvas() {
  7579. if (isCanvasHidden) {
  7580. canvas.removeAttribute('hidden');
  7581. isCanvasHidden = false;
  7582. }
  7583. };
  7584. canvasWrapper.appendChild(canvas);
  7585. this.canvas = canvas;
  7586. canvas.mozOpaque = true;
  7587. var ctx = canvas.getContext('2d', { alpha: false });
  7588. var outputScale = (0, _ui_utils.getOutputScale)(ctx);
  7589. this.outputScale = outputScale;
  7590. if (_pdfjsLib.PDFJS.useOnlyCssZoom) {
  7591. var actualSizeViewport = viewport.clone({ scale: _ui_utils.CSS_UNITS });
  7592. outputScale.sx *= actualSizeViewport.width / viewport.width;
  7593. outputScale.sy *= actualSizeViewport.height / viewport.height;
  7594. outputScale.scaled = true;
  7595. }
  7596. if (_pdfjsLib.PDFJS.maxCanvasPixels > 0) {
  7597. var pixelsInViewport = viewport.width * viewport.height;
  7598. var maxScale = Math.sqrt(_pdfjsLib.PDFJS.maxCanvasPixels / pixelsInViewport);
  7599. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  7600. outputScale.sx = maxScale;
  7601. outputScale.sy = maxScale;
  7602. outputScale.scaled = true;
  7603. this.hasRestrictedScaling = true;
  7604. } else {
  7605. this.hasRestrictedScaling = false;
  7606. }
  7607. }
  7608. var sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  7609. var sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  7610. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  7611. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  7612. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + 'px';
  7613. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + 'px';
  7614. this.paintedViewportMap.set(canvas, viewport);
  7615. var transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  7616. var renderContext = {
  7617. canvasContext: ctx,
  7618. transform: transform,
  7619. viewport: this.viewport,
  7620. renderInteractiveForms: this.renderInteractiveForms
  7621. };
  7622. var renderTask = this.pdfPage.render(renderContext);
  7623. renderTask.onContinue = function (cont) {
  7624. showCanvas();
  7625. if (result.onRenderContinue) {
  7626. result.onRenderContinue(cont);
  7627. } else {
  7628. cont();
  7629. }
  7630. };
  7631. renderTask.promise.then(function () {
  7632. showCanvas();
  7633. renderCapability.resolve(undefined);
  7634. }, function (error) {
  7635. showCanvas();
  7636. renderCapability.reject(error);
  7637. });
  7638. return result;
  7639. }
  7640. }, {
  7641. key: 'paintOnSvg',
  7642. value: function paintOnSvg(wrapper) {
  7643. var _this2 = this;
  7644. var cancelled = false;
  7645. var ensureNotCancelled = function ensureNotCancelled() {
  7646. if (cancelled) {
  7647. if (_pdfjsLib.PDFJS.pdfjsNext) {
  7648. throw new _pdfjsLib.RenderingCancelledException('Rendering cancelled, page ' + _this2.id, 'svg');
  7649. } else {
  7650. throw 'cancelled';
  7651. }
  7652. }
  7653. };
  7654. var pdfPage = this.pdfPage;
  7655. var actualSizeViewport = this.viewport.clone({ scale: _ui_utils.CSS_UNITS });
  7656. var promise = pdfPage.getOperatorList().then(function (opList) {
  7657. ensureNotCancelled();
  7658. var svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  7659. return svgGfx.getSVG(opList, actualSizeViewport).then(function (svg) {
  7660. ensureNotCancelled();
  7661. _this2.svg = svg;
  7662. _this2.paintedViewportMap.set(svg, actualSizeViewport);
  7663. svg.style.width = wrapper.style.width;
  7664. svg.style.height = wrapper.style.height;
  7665. _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7666. wrapper.appendChild(svg);
  7667. });
  7668. });
  7669. return {
  7670. promise: promise,
  7671. onRenderContinue: function onRenderContinue(cont) {
  7672. cont();
  7673. },
  7674. cancel: function cancel() {
  7675. cancelled = true;
  7676. }
  7677. };
  7678. }
  7679. }, {
  7680. key: 'setPageLabel',
  7681. value: function setPageLabel(label) {
  7682. this.pageLabel = typeof label === 'string' ? label : null;
  7683. if (this.pageLabel !== null) {
  7684. this.div.setAttribute('data-page-label', this.pageLabel);
  7685. } else {
  7686. this.div.removeAttribute('data-page-label');
  7687. }
  7688. }
  7689. }, {
  7690. key: 'width',
  7691. get: function get() {
  7692. return this.viewport.width;
  7693. }
  7694. }, {
  7695. key: 'height',
  7696. get: function get() {
  7697. return this.viewport.height;
  7698. }
  7699. }]);
  7700. return PDFPageView;
  7701. }();
  7702. exports.PDFPageView = PDFPageView;
  7703. /***/ }),
  7704. /* 25 */
  7705. /***/ (function(module, exports, __webpack_require__) {
  7706. "use strict";
  7707. Object.defineProperty(exports, "__esModule", {
  7708. value: true
  7709. });
  7710. exports.DefaultTextLayerFactory = exports.TextLayerBuilder = undefined;
  7711. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  7712. var _dom_events = __webpack_require__(2);
  7713. var _pdfjsLib = __webpack_require__(1);
  7714. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7715. var EXPAND_DIVS_TIMEOUT = 300;
  7716. var TextLayerBuilder = function () {
  7717. function TextLayerBuilder(_ref) {
  7718. var textLayerDiv = _ref.textLayerDiv,
  7719. eventBus = _ref.eventBus,
  7720. pageIndex = _ref.pageIndex,
  7721. viewport = _ref.viewport,
  7722. _ref$findController = _ref.findController,
  7723. findController = _ref$findController === undefined ? null : _ref$findController,
  7724. _ref$enhanceTextSelec = _ref.enhanceTextSelection,
  7725. enhanceTextSelection = _ref$enhanceTextSelec === undefined ? false : _ref$enhanceTextSelec;
  7726. _classCallCheck(this, TextLayerBuilder);
  7727. this.textLayerDiv = textLayerDiv;
  7728. this.eventBus = eventBus || (0, _dom_events.getGlobalEventBus)();
  7729. this.textContent = null;
  7730. this.textContentItemsStr = [];
  7731. this.textContentStream = null;
  7732. this.renderingDone = false;
  7733. this.pageIdx = pageIndex;
  7734. this.pageNumber = this.pageIdx + 1;
  7735. this.matches = [];
  7736. this.viewport = viewport;
  7737. this.textDivs = [];
  7738. this.findController = findController;
  7739. this.textLayerRenderTask = null;
  7740. this.enhanceTextSelection = enhanceTextSelection;
  7741. this._bindMouse();
  7742. }
  7743. _createClass(TextLayerBuilder, [{
  7744. key: '_finishRendering',
  7745. value: function _finishRendering() {
  7746. this.renderingDone = true;
  7747. if (!this.enhanceTextSelection) {
  7748. var endOfContent = document.createElement('div');
  7749. endOfContent.className = 'endOfContent';
  7750. this.textLayerDiv.appendChild(endOfContent);
  7751. }
  7752. this.eventBus.dispatch('textlayerrendered', {
  7753. source: this,
  7754. pageNumber: this.pageNumber,
  7755. numTextDivs: this.textDivs.length
  7756. });
  7757. }
  7758. }, {
  7759. key: 'render',
  7760. value: function render() {
  7761. var _this = this;
  7762. var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  7763. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  7764. return;
  7765. }
  7766. this.cancel();
  7767. this.textDivs = [];
  7768. var textLayerFrag = document.createDocumentFragment();
  7769. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  7770. textContent: this.textContent,
  7771. textContentStream: this.textContentStream,
  7772. container: textLayerFrag,
  7773. viewport: this.viewport,
  7774. textDivs: this.textDivs,
  7775. textContentItemsStr: this.textContentItemsStr,
  7776. timeout: timeout,
  7777. enhanceTextSelection: this.enhanceTextSelection
  7778. });
  7779. this.textLayerRenderTask.promise.then(function () {
  7780. _this.textLayerDiv.appendChild(textLayerFrag);
  7781. _this._finishRendering();
  7782. _this.updateMatches();
  7783. }, function (reason) {});
  7784. }
  7785. }, {
  7786. key: 'cancel',
  7787. value: function cancel() {
  7788. if (this.textLayerRenderTask) {
  7789. this.textLayerRenderTask.cancel();
  7790. this.textLayerRenderTask = null;
  7791. }
  7792. }
  7793. }, {
  7794. key: 'setTextContentStream',
  7795. value: function setTextContentStream(readableStream) {
  7796. this.cancel();
  7797. this.textContentStream = readableStream;
  7798. }
  7799. }, {
  7800. key: 'setTextContent',
  7801. value: function setTextContent(textContent) {
  7802. this.cancel();
  7803. this.textContent = textContent;
  7804. }
  7805. }, {
  7806. key: 'convertMatches',
  7807. value: function convertMatches(matches, matchesLength) {
  7808. var i = 0;
  7809. var iIndex = 0;
  7810. var textContentItemsStr = this.textContentItemsStr;
  7811. var end = textContentItemsStr.length - 1;
  7812. var queryLen = this.findController === null ? 0 : this.findController.state.query.length;
  7813. var ret = [];
  7814. if (!matches) {
  7815. return ret;
  7816. }
  7817. for (var m = 0, len = matches.length; m < len; m++) {
  7818. var matchIdx = matches[m];
  7819. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  7820. iIndex += textContentItemsStr[i].length;
  7821. i++;
  7822. }
  7823. if (i === textContentItemsStr.length) {
  7824. console.error('Could not find a matching mapping');
  7825. }
  7826. var match = {
  7827. begin: {
  7828. divIdx: i,
  7829. offset: matchIdx - iIndex
  7830. }
  7831. };
  7832. if (matchesLength) {
  7833. matchIdx += matchesLength[m];
  7834. } else {
  7835. matchIdx += queryLen;
  7836. }
  7837. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  7838. iIndex += textContentItemsStr[i].length;
  7839. i++;
  7840. }
  7841. match.end = {
  7842. divIdx: i,
  7843. offset: matchIdx - iIndex
  7844. };
  7845. ret.push(match);
  7846. }
  7847. return ret;
  7848. }
  7849. }, {
  7850. key: 'renderMatches',
  7851. value: function renderMatches(matches) {
  7852. if (matches.length === 0) {
  7853. return;
  7854. }
  7855. var textContentItemsStr = this.textContentItemsStr;
  7856. var textDivs = this.textDivs;
  7857. var prevEnd = null;
  7858. var pageIdx = this.pageIdx;
  7859. var isSelectedPage = this.findController === null ? false : pageIdx === this.findController.selected.pageIdx;
  7860. var selectedMatchIdx = this.findController === null ? -1 : this.findController.selected.matchIdx;
  7861. var highlightAll = this.findController === null ? false : this.findController.state.highlightAll;
  7862. var infinity = {
  7863. divIdx: -1,
  7864. offset: undefined
  7865. };
  7866. function beginText(begin, className) {
  7867. var divIdx = begin.divIdx;
  7868. textDivs[divIdx].textContent = '';
  7869. appendTextToDiv(divIdx, 0, begin.offset, className);
  7870. }
  7871. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  7872. var div = textDivs[divIdx];
  7873. var content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  7874. var node = document.createTextNode(content);
  7875. if (className) {
  7876. var span = document.createElement('span');
  7877. span.className = className;
  7878. span.appendChild(node);
  7879. div.appendChild(span);
  7880. return;
  7881. }
  7882. div.appendChild(node);
  7883. }
  7884. var i0 = selectedMatchIdx,
  7885. i1 = i0 + 1;
  7886. if (highlightAll) {
  7887. i0 = 0;
  7888. i1 = matches.length;
  7889. } else if (!isSelectedPage) {
  7890. return;
  7891. }
  7892. for (var i = i0; i < i1; i++) {
  7893. var match = matches[i];
  7894. var begin = match.begin;
  7895. var end = match.end;
  7896. var isSelected = isSelectedPage && i === selectedMatchIdx;
  7897. var highlightSuffix = isSelected ? ' selected' : '';
  7898. if (this.findController) {
  7899. this.findController.updateMatchPosition(pageIdx, i, textDivs, begin.divIdx);
  7900. }
  7901. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  7902. if (prevEnd !== null) {
  7903. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  7904. }
  7905. beginText(begin);
  7906. } else {
  7907. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  7908. }
  7909. if (begin.divIdx === end.divIdx) {
  7910. appendTextToDiv(begin.divIdx, begin.offset, end.offset, 'highlight' + highlightSuffix);
  7911. } else {
  7912. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, 'highlight begin' + highlightSuffix);
  7913. for (var n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  7914. textDivs[n0].className = 'highlight middle' + highlightSuffix;
  7915. }
  7916. beginText(end, 'highlight end' + highlightSuffix);
  7917. }
  7918. prevEnd = end;
  7919. }
  7920. if (prevEnd) {
  7921. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  7922. }
  7923. }
  7924. }, {
  7925. key: 'updateMatches',
  7926. value: function updateMatches() {
  7927. if (!this.renderingDone) {
  7928. return;
  7929. }
  7930. var matches = this.matches;
  7931. var textDivs = this.textDivs;
  7932. var textContentItemsStr = this.textContentItemsStr;
  7933. var clearedUntilDivIdx = -1;
  7934. for (var i = 0, len = matches.length; i < len; i++) {
  7935. var match = matches[i];
  7936. var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  7937. for (var n = begin, end = match.end.divIdx; n <= end; n++) {
  7938. var div = textDivs[n];
  7939. div.textContent = textContentItemsStr[n];
  7940. div.className = '';
  7941. }
  7942. clearedUntilDivIdx = match.end.divIdx + 1;
  7943. }
  7944. if (this.findController === null || !this.findController.active) {
  7945. return;
  7946. }
  7947. var pageMatches = void 0,
  7948. pageMatchesLength = void 0;
  7949. if (this.findController !== null) {
  7950. pageMatches = this.findController.pageMatches[this.pageIdx] || null;
  7951. pageMatchesLength = this.findController.pageMatchesLength ? this.findController.pageMatchesLength[this.pageIdx] || null : null;
  7952. }
  7953. this.matches = this.convertMatches(pageMatches, pageMatchesLength);
  7954. this.renderMatches(this.matches);
  7955. }
  7956. }, {
  7957. key: '_bindMouse',
  7958. value: function _bindMouse() {
  7959. var _this2 = this;
  7960. var div = this.textLayerDiv;
  7961. var expandDivsTimer = null;
  7962. div.addEventListener('mousedown', function (evt) {
  7963. if (_this2.enhanceTextSelection && _this2.textLayerRenderTask) {
  7964. _this2.textLayerRenderTask.expandTextDivs(true);
  7965. if (expandDivsTimer) {
  7966. clearTimeout(expandDivsTimer);
  7967. expandDivsTimer = null;
  7968. }
  7969. return;
  7970. }
  7971. var end = div.querySelector('.endOfContent');
  7972. if (!end) {
  7973. return;
  7974. }
  7975. var adjustTop = evt.target !== div;
  7976. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue('-moz-user-select') !== 'none';
  7977. if (adjustTop) {
  7978. var divBounds = div.getBoundingClientRect();
  7979. var r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  7980. end.style.top = (r * 100).toFixed(2) + '%';
  7981. }
  7982. end.classList.add('active');
  7983. });
  7984. div.addEventListener('mouseup', function () {
  7985. if (_this2.enhanceTextSelection && _this2.textLayerRenderTask) {
  7986. expandDivsTimer = setTimeout(function () {
  7987. if (_this2.textLayerRenderTask) {
  7988. _this2.textLayerRenderTask.expandTextDivs(false);
  7989. }
  7990. expandDivsTimer = null;
  7991. }, EXPAND_DIVS_TIMEOUT);
  7992. return;
  7993. }
  7994. var end = div.querySelector('.endOfContent');
  7995. if (!end) {
  7996. return;
  7997. }
  7998. end.style.top = '';
  7999. end.classList.remove('active');
  8000. });
  8001. }
  8002. }]);
  8003. return TextLayerBuilder;
  8004. }();
  8005. var DefaultTextLayerFactory = function () {
  8006. function DefaultTextLayerFactory() {
  8007. _classCallCheck(this, DefaultTextLayerFactory);
  8008. }
  8009. _createClass(DefaultTextLayerFactory, [{
  8010. key: 'createTextLayerBuilder',
  8011. value: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
  8012. var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  8013. return new TextLayerBuilder({
  8014. textLayerDiv: textLayerDiv,
  8015. pageIndex: pageIndex,
  8016. viewport: viewport,
  8017. enhanceTextSelection: enhanceTextSelection
  8018. });
  8019. }
  8020. }]);
  8021. return DefaultTextLayerFactory;
  8022. }();
  8023. exports.TextLayerBuilder = TextLayerBuilder;
  8024. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  8025. /***/ }),
  8026. /* 26 */
  8027. /***/ (function(module, exports, __webpack_require__) {
  8028. "use strict";
  8029. Object.defineProperty(exports, "__esModule", {
  8030. value: true
  8031. });
  8032. exports.SecondaryToolbar = undefined;
  8033. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  8034. var _pdf_cursor_tools = __webpack_require__(6);
  8035. var _ui_utils = __webpack_require__(0);
  8036. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8037. var SecondaryToolbar = function () {
  8038. function SecondaryToolbar(options, mainContainer, eventBus) {
  8039. _classCallCheck(this, SecondaryToolbar);
  8040. this.toolbar = options.toolbar;
  8041. this.toggleButton = options.toggleButton;
  8042. this.toolbarButtonContainer = options.toolbarButtonContainer;
  8043. this.buttons = [{
  8044. element: options.presentationModeButton,
  8045. eventName: 'presentationmode',
  8046. close: true
  8047. }, {
  8048. element: options.openFileButton,
  8049. eventName: 'openfile',
  8050. close: true
  8051. }, {
  8052. element: options.printButton,
  8053. eventName: 'print',
  8054. close: true
  8055. }, {
  8056. element: options.downloadButton,
  8057. eventName: 'download',
  8058. close: true
  8059. }, {
  8060. element: options.viewBookmarkButton,
  8061. eventName: null,
  8062. close: true
  8063. }, {
  8064. element: options.firstPageButton,
  8065. eventName: 'firstpage',
  8066. close: true
  8067. }, {
  8068. element: options.lastPageButton,
  8069. eventName: 'lastpage',
  8070. close: true
  8071. }, {
  8072. element: options.pageRotateCwButton,
  8073. eventName: 'rotatecw',
  8074. close: false
  8075. }, {
  8076. element: options.pageRotateCcwButton,
  8077. eventName: 'rotateccw',
  8078. close: false
  8079. }, {
  8080. element: options.cursorSelectToolButton,
  8081. eventName: 'switchcursortool',
  8082. eventDetails: { tool: _pdf_cursor_tools.CursorTool.SELECT },
  8083. close: true
  8084. }, {
  8085. element: options.cursorHandToolButton,
  8086. eventName: 'switchcursortool',
  8087. eventDetails: { tool: _pdf_cursor_tools.CursorTool.HAND },
  8088. close: true
  8089. }, {
  8090. element: options.documentPropertiesButton,
  8091. eventName: 'documentproperties',
  8092. close: true
  8093. }];
  8094. this.items = {
  8095. firstPage: options.firstPageButton,
  8096. lastPage: options.lastPageButton,
  8097. pageRotateCw: options.pageRotateCwButton,
  8098. pageRotateCcw: options.pageRotateCcwButton
  8099. };
  8100. this.mainContainer = mainContainer;
  8101. this.eventBus = eventBus;
  8102. this.opened = false;
  8103. this.containerHeight = null;
  8104. this.previousContainerHeight = null;
  8105. this.reset();
  8106. this._bindClickListeners();
  8107. this._bindCursorToolsListener(options);
  8108. this.eventBus.on('resize', this._setMaxHeight.bind(this));
  8109. }
  8110. _createClass(SecondaryToolbar, [{
  8111. key: 'setPageNumber',
  8112. value: function setPageNumber(pageNumber) {
  8113. this.pageNumber = pageNumber;
  8114. this._updateUIState();
  8115. }
  8116. }, {
  8117. key: 'setPagesCount',
  8118. value: function setPagesCount(pagesCount) {
  8119. this.pagesCount = pagesCount;
  8120. this._updateUIState();
  8121. }
  8122. }, {
  8123. key: 'reset',
  8124. value: function reset() {
  8125. this.pageNumber = 0;
  8126. this.pagesCount = 0;
  8127. this._updateUIState();
  8128. }
  8129. }, {
  8130. key: '_updateUIState',
  8131. value: function _updateUIState() {
  8132. this.items.firstPage.disabled = this.pageNumber <= 1;
  8133. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  8134. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  8135. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  8136. }
  8137. }, {
  8138. key: '_bindClickListeners',
  8139. value: function _bindClickListeners() {
  8140. var _this = this;
  8141. this.toggleButton.addEventListener('click', this.toggle.bind(this));
  8142. var _loop = function _loop(button) {
  8143. var _buttons$button = _this.buttons[button],
  8144. element = _buttons$button.element,
  8145. eventName = _buttons$button.eventName,
  8146. close = _buttons$button.close,
  8147. eventDetails = _buttons$button.eventDetails;
  8148. element.addEventListener('click', function (evt) {
  8149. if (eventName !== null) {
  8150. var details = { source: _this };
  8151. for (var property in eventDetails) {
  8152. details[property] = eventDetails[property];
  8153. }
  8154. _this.eventBus.dispatch(eventName, details);
  8155. }
  8156. if (close) {
  8157. _this.close();
  8158. }
  8159. });
  8160. };
  8161. for (var button in this.buttons) {
  8162. _loop(button);
  8163. }
  8164. }
  8165. }, {
  8166. key: '_bindCursorToolsListener',
  8167. value: function _bindCursorToolsListener(buttons) {
  8168. this.eventBus.on('cursortoolchanged', function (evt) {
  8169. buttons.cursorSelectToolButton.classList.remove('toggled');
  8170. buttons.cursorHandToolButton.classList.remove('toggled');
  8171. switch (evt.tool) {
  8172. case _pdf_cursor_tools.CursorTool.SELECT:
  8173. buttons.cursorSelectToolButton.classList.add('toggled');
  8174. break;
  8175. case _pdf_cursor_tools.CursorTool.HAND:
  8176. buttons.cursorHandToolButton.classList.add('toggled');
  8177. break;
  8178. }
  8179. });
  8180. }
  8181. }, {
  8182. key: 'open',
  8183. value: function open() {
  8184. if (this.opened) {
  8185. return;
  8186. }
  8187. this.opened = true;
  8188. this._setMaxHeight();
  8189. this.toggleButton.classList.add('toggled');
  8190. this.toolbar.classList.remove('hidden');
  8191. }
  8192. }, {
  8193. key: 'close',
  8194. value: function close() {
  8195. if (!this.opened) {
  8196. return;
  8197. }
  8198. this.opened = false;
  8199. this.toolbar.classList.add('hidden');
  8200. this.toggleButton.classList.remove('toggled');
  8201. }
  8202. }, {
  8203. key: 'toggle',
  8204. value: function toggle() {
  8205. if (this.opened) {
  8206. this.close();
  8207. } else {
  8208. this.open();
  8209. }
  8210. }
  8211. }, {
  8212. key: '_setMaxHeight',
  8213. value: function _setMaxHeight() {
  8214. if (!this.opened) {
  8215. return;
  8216. }
  8217. this.containerHeight = this.mainContainer.clientHeight;
  8218. if (this.containerHeight === this.previousContainerHeight) {
  8219. return;
  8220. }
  8221. this.toolbarButtonContainer.setAttribute('style', 'max-height: ' + (this.containerHeight - _ui_utils.SCROLLBAR_PADDING) + 'px;');
  8222. this.previousContainerHeight = this.containerHeight;
  8223. }
  8224. }, {
  8225. key: 'isOpen',
  8226. get: function get() {
  8227. return this.opened;
  8228. }
  8229. }]);
  8230. return SecondaryToolbar;
  8231. }();
  8232. exports.SecondaryToolbar = SecondaryToolbar;
  8233. /***/ }),
  8234. /* 27 */
  8235. /***/ (function(module, exports, __webpack_require__) {
  8236. "use strict";
  8237. Object.defineProperty(exports, "__esModule", {
  8238. value: true
  8239. });
  8240. exports.Toolbar = undefined;
  8241. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  8242. var _ui_utils = __webpack_require__(0);
  8243. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8244. var PAGE_NUMBER_LOADING_INDICATOR = 'visiblePageIsLoading';
  8245. var SCALE_SELECT_CONTAINER_PADDING = 8;
  8246. var SCALE_SELECT_PADDING = 22;
  8247. var Toolbar = function () {
  8248. function Toolbar(options, mainContainer, eventBus) {
  8249. var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
  8250. _classCallCheck(this, Toolbar);
  8251. this.toolbar = options.container;
  8252. this.mainContainer = mainContainer;
  8253. this.eventBus = eventBus;
  8254. this.l10n = l10n;
  8255. this.items = options;
  8256. this._wasLocalized = false;
  8257. this.reset();
  8258. this._bindListeners();
  8259. }
  8260. _createClass(Toolbar, [{
  8261. key: 'setPageNumber',
  8262. value: function setPageNumber(pageNumber, pageLabel) {
  8263. this.pageNumber = pageNumber;
  8264. this.pageLabel = pageLabel;
  8265. this._updateUIState(false);
  8266. }
  8267. }, {
  8268. key: 'setPagesCount',
  8269. value: function setPagesCount(pagesCount, hasPageLabels) {
  8270. this.pagesCount = pagesCount;
  8271. this.hasPageLabels = hasPageLabels;
  8272. this._updateUIState(true);
  8273. }
  8274. }, {
  8275. key: 'setPageScale',
  8276. value: function setPageScale(pageScaleValue, pageScale) {
  8277. this.pageScaleValue = pageScaleValue;
  8278. this.pageScale = pageScale;
  8279. this._updateUIState(false);
  8280. }
  8281. }, {
  8282. key: 'reset',
  8283. value: function reset() {
  8284. this.pageNumber = 0;
  8285. this.pageLabel = null;
  8286. this.hasPageLabels = false;
  8287. this.pagesCount = 0;
  8288. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8289. this.pageScale = _ui_utils.DEFAULT_SCALE;
  8290. this._updateUIState(true);
  8291. }
  8292. }, {
  8293. key: '_bindListeners',
  8294. value: function _bindListeners() {
  8295. var _this = this;
  8296. var eventBus = this.eventBus,
  8297. items = this.items;
  8298. var self = this;
  8299. items.previous.addEventListener('click', function () {
  8300. eventBus.dispatch('previouspage');
  8301. });
  8302. items.next.addEventListener('click', function () {
  8303. eventBus.dispatch('nextpage');
  8304. });
  8305. items.zoomIn.addEventListener('click', function () {
  8306. eventBus.dispatch('zoomin');
  8307. });
  8308. items.zoomOut.addEventListener('click', function () {
  8309. eventBus.dispatch('zoomout');
  8310. });
  8311. items.pageNumber.addEventListener('click', function () {
  8312. this.select();
  8313. });
  8314. items.pageNumber.addEventListener('change', function () {
  8315. eventBus.dispatch('pagenumberchanged', {
  8316. source: self,
  8317. value: this.value
  8318. });
  8319. });
  8320. items.scaleSelect.addEventListener('change', function () {
  8321. if (this.value === 'custom') {
  8322. return;
  8323. }
  8324. eventBus.dispatch('scalechanged', {
  8325. source: self,
  8326. value: this.value
  8327. });
  8328. });
  8329. items.presentationModeButton.addEventListener('click', function () {
  8330. eventBus.dispatch('presentationmode');
  8331. });
  8332. items.openFile.addEventListener('click', function () {
  8333. eventBus.dispatch('openfile');
  8334. });
  8335. items.print.addEventListener('click', function () {
  8336. eventBus.dispatch('print');
  8337. });
  8338. items.download.addEventListener('click', function () {
  8339. eventBus.dispatch('download');
  8340. });
  8341. items.scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  8342. eventBus.on('localized', function () {
  8343. _this._localized();
  8344. });
  8345. }
  8346. }, {
  8347. key: '_localized',
  8348. value: function _localized() {
  8349. this._wasLocalized = true;
  8350. this._adjustScaleWidth();
  8351. this._updateUIState(true);
  8352. }
  8353. }, {
  8354. key: '_updateUIState',
  8355. value: function _updateUIState() {
  8356. var resetNumPages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  8357. if (!this._wasLocalized) {
  8358. return;
  8359. }
  8360. var pageNumber = this.pageNumber,
  8361. pagesCount = this.pagesCount,
  8362. items = this.items;
  8363. var scaleValue = (this.pageScaleValue || this.pageScale).toString();
  8364. var scale = this.pageScale;
  8365. if (resetNumPages) {
  8366. if (this.hasPageLabels) {
  8367. items.pageNumber.type = 'text';
  8368. } else {
  8369. items.pageNumber.type = 'number';
  8370. this.l10n.get('of_pages', { pagesCount: pagesCount }, 'of {{pagesCount}}').then(function (msg) {
  8371. items.numPages.textContent = msg;
  8372. });
  8373. }
  8374. items.pageNumber.max = pagesCount;
  8375. }
  8376. if (this.hasPageLabels) {
  8377. items.pageNumber.value = this.pageLabel;
  8378. this.l10n.get('page_of_pages', {
  8379. pageNumber: pageNumber,
  8380. pagesCount: pagesCount
  8381. }, '({{pageNumber}} of {{pagesCount}})').then(function (msg) {
  8382. items.numPages.textContent = msg;
  8383. });
  8384. } else {
  8385. items.pageNumber.value = pageNumber;
  8386. }
  8387. items.previous.disabled = pageNumber <= 1;
  8388. items.next.disabled = pageNumber >= pagesCount;
  8389. items.zoomOut.disabled = scale <= _ui_utils.MIN_SCALE;
  8390. items.zoomIn.disabled = scale >= _ui_utils.MAX_SCALE;
  8391. var customScale = Math.round(scale * 10000) / 100;
  8392. this.l10n.get('page_scale_percent', { scale: customScale }, '{{scale}}%').then(function (msg) {
  8393. var options = items.scaleSelect.options;
  8394. var predefinedValueFound = false;
  8395. for (var i = 0, ii = options.length; i < ii; i++) {
  8396. var option = options[i];
  8397. if (option.value !== scaleValue) {
  8398. option.selected = false;
  8399. continue;
  8400. }
  8401. option.selected = true;
  8402. predefinedValueFound = true;
  8403. }
  8404. if (!predefinedValueFound) {
  8405. items.customScaleOption.textContent = msg;
  8406. items.customScaleOption.selected = true;
  8407. }
  8408. });
  8409. }
  8410. }, {
  8411. key: 'updateLoadingIndicatorState',
  8412. value: function updateLoadingIndicatorState() {
  8413. var loading = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  8414. var pageNumberInput = this.items.pageNumber;
  8415. if (loading) {
  8416. pageNumberInput.classList.add(PAGE_NUMBER_LOADING_INDICATOR);
  8417. } else {
  8418. pageNumberInput.classList.remove(PAGE_NUMBER_LOADING_INDICATOR);
  8419. }
  8420. }
  8421. }, {
  8422. key: '_adjustScaleWidth',
  8423. value: function _adjustScaleWidth() {
  8424. var container = this.items.scaleSelectContainer;
  8425. var select = this.items.scaleSelect;
  8426. _ui_utils.animationStarted.then(function () {
  8427. if (container.clientWidth === 0) {
  8428. container.setAttribute('style', 'display: inherit;');
  8429. }
  8430. if (container.clientWidth > 0) {
  8431. select.setAttribute('style', 'min-width: inherit;');
  8432. var width = select.clientWidth + SCALE_SELECT_CONTAINER_PADDING;
  8433. select.setAttribute('style', 'min-width: ' + (width + SCALE_SELECT_PADDING) + 'px;');
  8434. container.setAttribute('style', 'min-width: ' + width + 'px; ' + 'max-width: ' + width + 'px;');
  8435. }
  8436. });
  8437. }
  8438. }]);
  8439. return Toolbar;
  8440. }();
  8441. exports.Toolbar = Toolbar;
  8442. /***/ }),
  8443. /* 28 */
  8444. /***/ (function(module, exports, __webpack_require__) {
  8445. "use strict";
  8446. Object.defineProperty(exports, "__esModule", {
  8447. value: true
  8448. });
  8449. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  8450. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8451. var DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  8452. var ViewHistory = function () {
  8453. function ViewHistory(fingerprint) {
  8454. var _this = this;
  8455. var cacheSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_VIEW_HISTORY_CACHE_SIZE;
  8456. _classCallCheck(this, ViewHistory);
  8457. this.fingerprint = fingerprint;
  8458. this.cacheSize = cacheSize;
  8459. this._initializedPromise = this._readFromStorage().then(function (databaseStr) {
  8460. var database = JSON.parse(databaseStr || '{}');
  8461. if (!('files' in database)) {
  8462. database.files = [];
  8463. }
  8464. if (database.files.length >= _this.cacheSize) {
  8465. database.files.shift();
  8466. }
  8467. var index = void 0;
  8468. for (var i = 0, length = database.files.length; i < length; i++) {
  8469. var branch = database.files[i];
  8470. if (branch.fingerprint === _this.fingerprint) {
  8471. index = i;
  8472. break;
  8473. }
  8474. }
  8475. if (typeof index !== 'number') {
  8476. index = database.files.push({ fingerprint: _this.fingerprint }) - 1;
  8477. }
  8478. _this.file = database.files[index];
  8479. _this.database = database;
  8480. });
  8481. }
  8482. _createClass(ViewHistory, [{
  8483. key: '_writeToStorage',
  8484. value: function _writeToStorage() {
  8485. var _this2 = this;
  8486. return new Promise(function (resolve) {
  8487. var databaseStr = JSON.stringify(_this2.database);
  8488. localStorage.setItem('pdfjs.history', databaseStr);
  8489. resolve();
  8490. });
  8491. }
  8492. }, {
  8493. key: '_readFromStorage',
  8494. value: function _readFromStorage() {
  8495. return new Promise(function (resolve) {
  8496. resolve(localStorage.getItem('pdfjs.history'));
  8497. });
  8498. }
  8499. }, {
  8500. key: 'set',
  8501. value: function set(name, val) {
  8502. var _this3 = this;
  8503. return this._initializedPromise.then(function () {
  8504. _this3.file[name] = val;
  8505. return _this3._writeToStorage();
  8506. });
  8507. }
  8508. }, {
  8509. key: 'setMultiple',
  8510. value: function setMultiple(properties) {
  8511. var _this4 = this;
  8512. return this._initializedPromise.then(function () {
  8513. for (var name in properties) {
  8514. _this4.file[name] = properties[name];
  8515. }
  8516. return _this4._writeToStorage();
  8517. });
  8518. }
  8519. }, {
  8520. key: 'get',
  8521. value: function get(name, defaultValue) {
  8522. var _this5 = this;
  8523. return this._initializedPromise.then(function () {
  8524. var val = _this5.file[name];
  8525. return val !== undefined ? val : defaultValue;
  8526. });
  8527. }
  8528. }, {
  8529. key: 'getMultiple',
  8530. value: function getMultiple(properties) {
  8531. var _this6 = this;
  8532. return this._initializedPromise.then(function () {
  8533. var values = Object.create(null);
  8534. for (var name in properties) {
  8535. var val = _this6.file[name];
  8536. values[name] = val !== undefined ? val : properties[name];
  8537. }
  8538. return values;
  8539. });
  8540. }
  8541. }]);
  8542. return ViewHistory;
  8543. }();
  8544. exports.ViewHistory = ViewHistory;
  8545. /***/ }),
  8546. /* 29 */
  8547. /***/ (function(module, exports, __webpack_require__) {
  8548. "use strict";
  8549. Object.defineProperty(exports, "__esModule", {
  8550. value: true
  8551. });
  8552. exports.GenericCom = undefined;
  8553. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  8554. var _app = __webpack_require__(4);
  8555. var _preferences = __webpack_require__(30);
  8556. var _download_manager = __webpack_require__(31);
  8557. var _genericl10n = __webpack_require__(32);
  8558. var _pdfjsLib = __webpack_require__(1);
  8559. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8560. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  8561. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  8562. ;
  8563. var GenericCom = {};
  8564. var GenericPreferences = function (_BasePreferences) {
  8565. _inherits(GenericPreferences, _BasePreferences);
  8566. function GenericPreferences() {
  8567. _classCallCheck(this, GenericPreferences);
  8568. return _possibleConstructorReturn(this, (GenericPreferences.__proto__ || Object.getPrototypeOf(GenericPreferences)).apply(this, arguments));
  8569. }
  8570. _createClass(GenericPreferences, [{
  8571. key: '_writeToStorage',
  8572. value: function _writeToStorage(prefObj) {
  8573. return new Promise(function (resolve) {
  8574. localStorage.setItem('pdfjs.preferences', JSON.stringify(prefObj));
  8575. resolve();
  8576. });
  8577. }
  8578. }, {
  8579. key: '_readFromStorage',
  8580. value: function _readFromStorage(prefObj) {
  8581. return new Promise(function (resolve) {
  8582. var readPrefs = JSON.parse(localStorage.getItem('pdfjs.preferences'));
  8583. resolve(readPrefs);
  8584. });
  8585. }
  8586. }]);
  8587. return GenericPreferences;
  8588. }(_preferences.BasePreferences);
  8589. var GenericExternalServices = Object.create(_app.DefaultExternalServices);
  8590. GenericExternalServices.createDownloadManager = function () {
  8591. return new _download_manager.DownloadManager();
  8592. };
  8593. GenericExternalServices.createPreferences = function () {
  8594. return new GenericPreferences();
  8595. };
  8596. GenericExternalServices.createL10n = function () {
  8597. return new _genericl10n.GenericL10n(_pdfjsLib.PDFJS.locale);
  8598. };
  8599. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  8600. exports.GenericCom = GenericCom;
  8601. /***/ }),
  8602. /* 30 */
  8603. /***/ (function(module, exports, __webpack_require__) {
  8604. "use strict";
  8605. Object.defineProperty(exports, "__esModule", {
  8606. value: true
  8607. });
  8608. exports.BasePreferences = undefined;
  8609. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  8610. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  8611. var _ui_utils = __webpack_require__(0);
  8612. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8613. var defaultPreferences = null;
  8614. function getDefaultPreferences() {
  8615. if (!defaultPreferences) {
  8616. defaultPreferences = Promise.resolve({
  8617. "showPreviousViewOnLoad": true,
  8618. "defaultZoomValue": "",
  8619. "sidebarViewOnLoad": 0,
  8620. "enableHandToolOnLoad": false,
  8621. "cursorToolOnLoad": 0,
  8622. "enableWebGL": false,
  8623. "pdfBugEnabled": false,
  8624. "disableRange": false,
  8625. "disableStream": false,
  8626. "disableAutoFetch": false,
  8627. "disableFontFace": false,
  8628. "disableTextLayer": false,
  8629. "useOnlyCssZoom": false,
  8630. "externalLinkTarget": 0,
  8631. "enhanceTextSelection": false,
  8632. "renderer": "canvas",
  8633. "renderInteractiveForms": false,
  8634. "enablePrintAutoRotate": false,
  8635. "disablePageMode": false,
  8636. "disablePageLabels": false
  8637. });
  8638. }
  8639. return defaultPreferences;
  8640. }
  8641. var BasePreferences = function () {
  8642. function BasePreferences() {
  8643. var _this = this;
  8644. _classCallCheck(this, BasePreferences);
  8645. if (this.constructor === BasePreferences) {
  8646. throw new Error('Cannot initialize BasePreferences.');
  8647. }
  8648. this.prefs = null;
  8649. this._initializedPromise = getDefaultPreferences().then(function (defaults) {
  8650. Object.defineProperty(_this, 'defaults', {
  8651. value: Object.freeze(defaults),
  8652. writable: false,
  8653. enumerable: true,
  8654. configurable: false
  8655. });
  8656. _this.prefs = (0, _ui_utils.cloneObj)(defaults);
  8657. return _this._readFromStorage(defaults);
  8658. }).then(function (prefObj) {
  8659. if (prefObj) {
  8660. _this.prefs = prefObj;
  8661. }
  8662. });
  8663. }
  8664. _createClass(BasePreferences, [{
  8665. key: "_writeToStorage",
  8666. value: function _writeToStorage(prefObj) {
  8667. return Promise.reject(new Error('Not implemented: _writeToStorage'));
  8668. }
  8669. }, {
  8670. key: "_readFromStorage",
  8671. value: function _readFromStorage(prefObj) {
  8672. return Promise.reject(new Error('Not implemented: _readFromStorage'));
  8673. }
  8674. }, {
  8675. key: "reset",
  8676. value: function reset() {
  8677. var _this2 = this;
  8678. return this._initializedPromise.then(function () {
  8679. _this2.prefs = (0, _ui_utils.cloneObj)(_this2.defaults);
  8680. return _this2._writeToStorage(_this2.defaults);
  8681. });
  8682. }
  8683. }, {
  8684. key: "reload",
  8685. value: function reload() {
  8686. var _this3 = this;
  8687. return this._initializedPromise.then(function () {
  8688. return _this3._readFromStorage(_this3.defaults);
  8689. }).then(function (prefObj) {
  8690. if (prefObj) {
  8691. _this3.prefs = prefObj;
  8692. }
  8693. });
  8694. }
  8695. }, {
  8696. key: "set",
  8697. value: function set(name, value) {
  8698. var _this4 = this;
  8699. return this._initializedPromise.then(function () {
  8700. if (_this4.defaults[name] === undefined) {
  8701. throw new Error("Set preference: \"" + name + "\" is undefined.");
  8702. } else if (value === undefined) {
  8703. throw new Error('Set preference: no value is specified.');
  8704. }
  8705. var valueType = typeof value === "undefined" ? "undefined" : _typeof(value);
  8706. var defaultType = _typeof(_this4.defaults[name]);
  8707. if (valueType !== defaultType) {
  8708. if (valueType === 'number' && defaultType === 'string') {
  8709. value = value.toString();
  8710. } else {
  8711. throw new Error("Set preference: \"" + value + "\" is a " + valueType + ", " + ("expected a " + defaultType + "."));
  8712. }
  8713. } else {
  8714. if (valueType === 'number' && !Number.isInteger(value)) {
  8715. throw new Error("Set preference: \"" + value + "\" must be an integer.");
  8716. }
  8717. }
  8718. _this4.prefs[name] = value;
  8719. return _this4._writeToStorage(_this4.prefs);
  8720. });
  8721. }
  8722. }, {
  8723. key: "get",
  8724. value: function get(name) {
  8725. var _this5 = this;
  8726. return this._initializedPromise.then(function () {
  8727. var defaultValue = _this5.defaults[name];
  8728. if (defaultValue === undefined) {
  8729. throw new Error("Get preference: \"" + name + "\" is undefined.");
  8730. } else {
  8731. var prefValue = _this5.prefs[name];
  8732. if (prefValue !== undefined) {
  8733. return prefValue;
  8734. }
  8735. }
  8736. return defaultValue;
  8737. });
  8738. }
  8739. }]);
  8740. return BasePreferences;
  8741. }();
  8742. exports.BasePreferences = BasePreferences;
  8743. /***/ }),
  8744. /* 31 */
  8745. /***/ (function(module, exports, __webpack_require__) {
  8746. "use strict";
  8747. Object.defineProperty(exports, "__esModule", {
  8748. value: true
  8749. });
  8750. exports.DownloadManager = undefined;
  8751. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  8752. var _pdfjsLib = __webpack_require__(1);
  8753. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8754. ;
  8755. function _download(blobUrl, filename) {
  8756. var a = document.createElement('a');
  8757. if (a.click) {
  8758. a.href = blobUrl;
  8759. a.target = '_parent';
  8760. if ('download' in a) {
  8761. a.download = filename;
  8762. }
  8763. (document.body || document.documentElement).appendChild(a);
  8764. a.click();
  8765. a.parentNode.removeChild(a);
  8766. } else {
  8767. if (window.top === window && blobUrl.split('#')[0] === window.location.href.split('#')[0]) {
  8768. var padCharacter = blobUrl.indexOf('?') === -1 ? '?' : '&';
  8769. blobUrl = blobUrl.replace(/#|$/, padCharacter + '$&');
  8770. }
  8771. window.open(blobUrl, '_parent');
  8772. }
  8773. }
  8774. var DownloadManager = function () {
  8775. function DownloadManager() {
  8776. _classCallCheck(this, DownloadManager);
  8777. }
  8778. _createClass(DownloadManager, [{
  8779. key: 'downloadUrl',
  8780. value: function downloadUrl(url, filename) {
  8781. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, 'http://example.com')) {
  8782. return;
  8783. }
  8784. _download(url + '#pdfjs.action=download', filename);
  8785. }
  8786. }, {
  8787. key: 'downloadData',
  8788. value: function downloadData(data, filename, contentType) {
  8789. if (navigator.msSaveBlob) {
  8790. return navigator.msSaveBlob(new Blob([data], { type: contentType }), filename);
  8791. }
  8792. var blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _pdfjsLib.PDFJS.disableCreateObjectURL);
  8793. _download(blobUrl, filename);
  8794. }
  8795. }, {
  8796. key: 'download',
  8797. value: function download(blob, url, filename) {
  8798. if (navigator.msSaveBlob) {
  8799. if (!navigator.msSaveBlob(blob, filename)) {
  8800. this.downloadUrl(url, filename);
  8801. }
  8802. return;
  8803. }
  8804. if (_pdfjsLib.PDFJS.disableCreateObjectURL) {
  8805. this.downloadUrl(url, filename);
  8806. return;
  8807. }
  8808. var blobUrl = URL.createObjectURL(blob);
  8809. _download(blobUrl, filename);
  8810. }
  8811. }]);
  8812. return DownloadManager;
  8813. }();
  8814. exports.DownloadManager = DownloadManager;
  8815. /***/ }),
  8816. /* 32 */
  8817. /***/ (function(module, exports, __webpack_require__) {
  8818. "use strict";
  8819. Object.defineProperty(exports, "__esModule", {
  8820. value: true
  8821. });
  8822. exports.GenericL10n = undefined;
  8823. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  8824. __webpack_require__(33);
  8825. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8826. var webL10n = document.webL10n;
  8827. var GenericL10n = function () {
  8828. function GenericL10n(lang) {
  8829. _classCallCheck(this, GenericL10n);
  8830. this._lang = lang;
  8831. this._ready = new Promise(function (resolve, reject) {
  8832. webL10n.setLanguage(lang, function () {
  8833. resolve(webL10n);
  8834. });
  8835. });
  8836. }
  8837. _createClass(GenericL10n, [{
  8838. key: 'getDirection',
  8839. value: function getDirection() {
  8840. return this._ready.then(function (l10n) {
  8841. return l10n.getDirection();
  8842. });
  8843. }
  8844. }, {
  8845. key: 'get',
  8846. value: function get(property, args, fallback) {
  8847. return this._ready.then(function (l10n) {
  8848. return l10n.get(property, args, fallback);
  8849. });
  8850. }
  8851. }, {
  8852. key: 'translate',
  8853. value: function translate(element) {
  8854. return this._ready.then(function (l10n) {
  8855. return l10n.translate(element);
  8856. });
  8857. }
  8858. }]);
  8859. return GenericL10n;
  8860. }();
  8861. exports.GenericL10n = GenericL10n;
  8862. /***/ }),
  8863. /* 33 */
  8864. /***/ (function(module, exports, __webpack_require__) {
  8865. "use strict";
  8866. document.webL10n = function (window, document, undefined) {
  8867. var gL10nData = {};
  8868. var gTextData = '';
  8869. var gTextProp = 'textContent';
  8870. var gLanguage = '';
  8871. var gMacros = {};
  8872. var gReadyState = 'loading';
  8873. var gAsyncResourceLoading = true;
  8874. function getL10nResourceLinks() {
  8875. return document.querySelectorAll('link[type="application/l10n"]');
  8876. }
  8877. function getL10nDictionary() {
  8878. var script = document.querySelector('script[type="application/l10n"]');
  8879. return script ? JSON.parse(script.innerHTML) : null;
  8880. }
  8881. function getTranslatableChildren(element) {
  8882. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  8883. }
  8884. function getL10nAttributes(element) {
  8885. if (!element) return {};
  8886. var l10nId = element.getAttribute('data-l10n-id');
  8887. var l10nArgs = element.getAttribute('data-l10n-args');
  8888. var args = {};
  8889. if (l10nArgs) {
  8890. try {
  8891. args = JSON.parse(l10nArgs);
  8892. } catch (e) {
  8893. console.warn('could not parse arguments for #' + l10nId);
  8894. }
  8895. }
  8896. return {
  8897. id: l10nId,
  8898. args: args
  8899. };
  8900. }
  8901. function fireL10nReadyEvent(lang) {
  8902. var evtObject = document.createEvent('Event');
  8903. evtObject.initEvent('localized', true, false);
  8904. evtObject.language = lang;
  8905. document.dispatchEvent(evtObject);
  8906. }
  8907. function xhrLoadText(url, onSuccess, onFailure) {
  8908. onSuccess = onSuccess || function _onSuccess(data) {};
  8909. onFailure = onFailure || function _onFailure() {};
  8910. var xhr = new XMLHttpRequest();
  8911. xhr.open('GET', url, gAsyncResourceLoading);
  8912. if (xhr.overrideMimeType) {
  8913. xhr.overrideMimeType('text/plain; charset=utf-8');
  8914. }
  8915. xhr.onreadystatechange = function () {
  8916. if (xhr.readyState == 4) {
  8917. if (xhr.status == 200 || xhr.status === 0) {
  8918. onSuccess(xhr.responseText);
  8919. } else {
  8920. onFailure();
  8921. }
  8922. }
  8923. };
  8924. xhr.onerror = onFailure;
  8925. xhr.ontimeout = onFailure;
  8926. try {
  8927. xhr.send(null);
  8928. } catch (e) {
  8929. onFailure();
  8930. }
  8931. }
  8932. function parseResource(href, lang, successCallback, failureCallback) {
  8933. var baseURL = href.replace(/[^\/]*$/, '') || './';
  8934. function evalString(text) {
  8935. if (text.lastIndexOf('\\') < 0) return text;
  8936. return text.replace(/\\\\/g, '\\').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\t/g, '\t').replace(/\\b/g, '\b').replace(/\\f/g, '\f').replace(/\\{/g, '{').replace(/\\}/g, '}').replace(/\\"/g, '"').replace(/\\'/g, "'");
  8937. }
  8938. function parseProperties(text, parsedPropertiesCallback) {
  8939. var dictionary = {};
  8940. var reBlank = /^\s*|\s*$/;
  8941. var reComment = /^\s*#|^\s*$/;
  8942. var reSection = /^\s*\[(.*)\]\s*$/;
  8943. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  8944. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  8945. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  8946. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  8947. var currentLang = '*';
  8948. var genericLang = lang.split('-', 1)[0];
  8949. var skipLang = false;
  8950. var match = '';
  8951. function nextEntry() {
  8952. while (true) {
  8953. if (!entries.length) {
  8954. parsedRawLinesCallback();
  8955. return;
  8956. }
  8957. var line = entries.shift();
  8958. if (reComment.test(line)) continue;
  8959. if (extendedSyntax) {
  8960. match = reSection.exec(line);
  8961. if (match) {
  8962. currentLang = match[1].toLowerCase();
  8963. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  8964. continue;
  8965. } else if (skipLang) {
  8966. continue;
  8967. }
  8968. match = reImport.exec(line);
  8969. if (match) {
  8970. loadImport(baseURL + match[1], nextEntry);
  8971. return;
  8972. }
  8973. }
  8974. var tmp = line.match(reSplit);
  8975. if (tmp && tmp.length == 3) {
  8976. dictionary[tmp[1]] = evalString(tmp[2]);
  8977. }
  8978. }
  8979. }
  8980. nextEntry();
  8981. }
  8982. function loadImport(url, callback) {
  8983. xhrLoadText(url, function (content) {
  8984. parseRawLines(content, false, callback);
  8985. }, function () {
  8986. console.warn(url + ' not found.');
  8987. callback();
  8988. });
  8989. }
  8990. parseRawLines(text, true, function () {
  8991. parsedPropertiesCallback(dictionary);
  8992. });
  8993. }
  8994. xhrLoadText(href, function (response) {
  8995. gTextData += response;
  8996. parseProperties(response, function (data) {
  8997. for (var key in data) {
  8998. var id,
  8999. prop,
  9000. index = key.lastIndexOf('.');
  9001. if (index > 0) {
  9002. id = key.substring(0, index);
  9003. prop = key.substr(index + 1);
  9004. } else {
  9005. id = key;
  9006. prop = gTextProp;
  9007. }
  9008. if (!gL10nData[id]) {
  9009. gL10nData[id] = {};
  9010. }
  9011. gL10nData[id][prop] = data[key];
  9012. }
  9013. if (successCallback) {
  9014. successCallback();
  9015. }
  9016. });
  9017. }, failureCallback);
  9018. }
  9019. function loadLocale(lang, callback) {
  9020. if (lang) {
  9021. lang = lang.toLowerCase();
  9022. }
  9023. callback = callback || function _callback() {};
  9024. clear();
  9025. gLanguage = lang;
  9026. var langLinks = getL10nResourceLinks();
  9027. var langCount = langLinks.length;
  9028. if (langCount === 0) {
  9029. var dict = getL10nDictionary();
  9030. if (dict && dict.locales && dict.default_locale) {
  9031. console.log('using the embedded JSON directory, early way out');
  9032. gL10nData = dict.locales[lang];
  9033. if (!gL10nData) {
  9034. var defaultLocale = dict.default_locale.toLowerCase();
  9035. for (var anyCaseLang in dict.locales) {
  9036. anyCaseLang = anyCaseLang.toLowerCase();
  9037. if (anyCaseLang === lang) {
  9038. gL10nData = dict.locales[lang];
  9039. break;
  9040. } else if (anyCaseLang === defaultLocale) {
  9041. gL10nData = dict.locales[defaultLocale];
  9042. }
  9043. }
  9044. }
  9045. callback();
  9046. } else {
  9047. console.log('no resource to load, early way out');
  9048. }
  9049. fireL10nReadyEvent(lang);
  9050. gReadyState = 'complete';
  9051. return;
  9052. }
  9053. var onResourceLoaded = null;
  9054. var gResourceCount = 0;
  9055. onResourceLoaded = function onResourceLoaded() {
  9056. gResourceCount++;
  9057. if (gResourceCount >= langCount) {
  9058. callback();
  9059. fireL10nReadyEvent(lang);
  9060. gReadyState = 'complete';
  9061. }
  9062. };
  9063. function L10nResourceLink(link) {
  9064. var href = link.href;
  9065. this.load = function (lang, callback) {
  9066. parseResource(href, lang, callback, function () {
  9067. console.warn(href + ' not found.');
  9068. console.warn('"' + lang + '" resource not found');
  9069. gLanguage = '';
  9070. callback();
  9071. });
  9072. };
  9073. }
  9074. for (var i = 0; i < langCount; i++) {
  9075. var resource = new L10nResourceLink(langLinks[i]);
  9076. resource.load(lang, onResourceLoaded);
  9077. }
  9078. }
  9079. function clear() {
  9080. gL10nData = {};
  9081. gTextData = '';
  9082. gLanguage = '';
  9083. }
  9084. function getPluralRules(lang) {
  9085. var locales2rules = {
  9086. 'af': 3,
  9087. 'ak': 4,
  9088. 'am': 4,
  9089. 'ar': 1,
  9090. 'asa': 3,
  9091. 'az': 0,
  9092. 'be': 11,
  9093. 'bem': 3,
  9094. 'bez': 3,
  9095. 'bg': 3,
  9096. 'bh': 4,
  9097. 'bm': 0,
  9098. 'bn': 3,
  9099. 'bo': 0,
  9100. 'br': 20,
  9101. 'brx': 3,
  9102. 'bs': 11,
  9103. 'ca': 3,
  9104. 'cgg': 3,
  9105. 'chr': 3,
  9106. 'cs': 12,
  9107. 'cy': 17,
  9108. 'da': 3,
  9109. 'de': 3,
  9110. 'dv': 3,
  9111. 'dz': 0,
  9112. 'ee': 3,
  9113. 'el': 3,
  9114. 'en': 3,
  9115. 'eo': 3,
  9116. 'es': 3,
  9117. 'et': 3,
  9118. 'eu': 3,
  9119. 'fa': 0,
  9120. 'ff': 5,
  9121. 'fi': 3,
  9122. 'fil': 4,
  9123. 'fo': 3,
  9124. 'fr': 5,
  9125. 'fur': 3,
  9126. 'fy': 3,
  9127. 'ga': 8,
  9128. 'gd': 24,
  9129. 'gl': 3,
  9130. 'gsw': 3,
  9131. 'gu': 3,
  9132. 'guw': 4,
  9133. 'gv': 23,
  9134. 'ha': 3,
  9135. 'haw': 3,
  9136. 'he': 2,
  9137. 'hi': 4,
  9138. 'hr': 11,
  9139. 'hu': 0,
  9140. 'id': 0,
  9141. 'ig': 0,
  9142. 'ii': 0,
  9143. 'is': 3,
  9144. 'it': 3,
  9145. 'iu': 7,
  9146. 'ja': 0,
  9147. 'jmc': 3,
  9148. 'jv': 0,
  9149. 'ka': 0,
  9150. 'kab': 5,
  9151. 'kaj': 3,
  9152. 'kcg': 3,
  9153. 'kde': 0,
  9154. 'kea': 0,
  9155. 'kk': 3,
  9156. 'kl': 3,
  9157. 'km': 0,
  9158. 'kn': 0,
  9159. 'ko': 0,
  9160. 'ksb': 3,
  9161. 'ksh': 21,
  9162. 'ku': 3,
  9163. 'kw': 7,
  9164. 'lag': 18,
  9165. 'lb': 3,
  9166. 'lg': 3,
  9167. 'ln': 4,
  9168. 'lo': 0,
  9169. 'lt': 10,
  9170. 'lv': 6,
  9171. 'mas': 3,
  9172. 'mg': 4,
  9173. 'mk': 16,
  9174. 'ml': 3,
  9175. 'mn': 3,
  9176. 'mo': 9,
  9177. 'mr': 3,
  9178. 'ms': 0,
  9179. 'mt': 15,
  9180. 'my': 0,
  9181. 'nah': 3,
  9182. 'naq': 7,
  9183. 'nb': 3,
  9184. 'nd': 3,
  9185. 'ne': 3,
  9186. 'nl': 3,
  9187. 'nn': 3,
  9188. 'no': 3,
  9189. 'nr': 3,
  9190. 'nso': 4,
  9191. 'ny': 3,
  9192. 'nyn': 3,
  9193. 'om': 3,
  9194. 'or': 3,
  9195. 'pa': 3,
  9196. 'pap': 3,
  9197. 'pl': 13,
  9198. 'ps': 3,
  9199. 'pt': 3,
  9200. 'rm': 3,
  9201. 'ro': 9,
  9202. 'rof': 3,
  9203. 'ru': 11,
  9204. 'rwk': 3,
  9205. 'sah': 0,
  9206. 'saq': 3,
  9207. 'se': 7,
  9208. 'seh': 3,
  9209. 'ses': 0,
  9210. 'sg': 0,
  9211. 'sh': 11,
  9212. 'shi': 19,
  9213. 'sk': 12,
  9214. 'sl': 14,
  9215. 'sma': 7,
  9216. 'smi': 7,
  9217. 'smj': 7,
  9218. 'smn': 7,
  9219. 'sms': 7,
  9220. 'sn': 3,
  9221. 'so': 3,
  9222. 'sq': 3,
  9223. 'sr': 11,
  9224. 'ss': 3,
  9225. 'ssy': 3,
  9226. 'st': 3,
  9227. 'sv': 3,
  9228. 'sw': 3,
  9229. 'syr': 3,
  9230. 'ta': 3,
  9231. 'te': 3,
  9232. 'teo': 3,
  9233. 'th': 0,
  9234. 'ti': 4,
  9235. 'tig': 3,
  9236. 'tk': 3,
  9237. 'tl': 4,
  9238. 'tn': 3,
  9239. 'to': 0,
  9240. 'tr': 0,
  9241. 'ts': 3,
  9242. 'tzm': 22,
  9243. 'uk': 11,
  9244. 'ur': 3,
  9245. 've': 3,
  9246. 'vi': 0,
  9247. 'vun': 3,
  9248. 'wa': 4,
  9249. 'wae': 3,
  9250. 'wo': 0,
  9251. 'xh': 3,
  9252. 'xog': 3,
  9253. 'yo': 0,
  9254. 'zh': 0,
  9255. 'zu': 3
  9256. };
  9257. function isIn(n, list) {
  9258. return list.indexOf(n) !== -1;
  9259. }
  9260. function isBetween(n, start, end) {
  9261. return start <= n && n <= end;
  9262. }
  9263. var pluralRules = {
  9264. '0': function _(n) {
  9265. return 'other';
  9266. },
  9267. '1': function _(n) {
  9268. if (isBetween(n % 100, 3, 10)) return 'few';
  9269. if (n === 0) return 'zero';
  9270. if (isBetween(n % 100, 11, 99)) return 'many';
  9271. if (n == 2) return 'two';
  9272. if (n == 1) return 'one';
  9273. return 'other';
  9274. },
  9275. '2': function _(n) {
  9276. if (n !== 0 && n % 10 === 0) return 'many';
  9277. if (n == 2) return 'two';
  9278. if (n == 1) return 'one';
  9279. return 'other';
  9280. },
  9281. '3': function _(n) {
  9282. if (n == 1) return 'one';
  9283. return 'other';
  9284. },
  9285. '4': function _(n) {
  9286. if (isBetween(n, 0, 1)) return 'one';
  9287. return 'other';
  9288. },
  9289. '5': function _(n) {
  9290. if (isBetween(n, 0, 2) && n != 2) return 'one';
  9291. return 'other';
  9292. },
  9293. '6': function _(n) {
  9294. if (n === 0) return 'zero';
  9295. if (n % 10 == 1 && n % 100 != 11) return 'one';
  9296. return 'other';
  9297. },
  9298. '7': function _(n) {
  9299. if (n == 2) return 'two';
  9300. if (n == 1) return 'one';
  9301. return 'other';
  9302. },
  9303. '8': function _(n) {
  9304. if (isBetween(n, 3, 6)) return 'few';
  9305. if (isBetween(n, 7, 10)) return 'many';
  9306. if (n == 2) return 'two';
  9307. if (n == 1) return 'one';
  9308. return 'other';
  9309. },
  9310. '9': function _(n) {
  9311. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  9312. if (n == 1) return 'one';
  9313. return 'other';
  9314. },
  9315. '10': function _(n) {
  9316. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  9317. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  9318. return 'other';
  9319. },
  9320. '11': function _(n) {
  9321. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  9322. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  9323. if (n % 10 == 1 && n % 100 != 11) return 'one';
  9324. return 'other';
  9325. },
  9326. '12': function _(n) {
  9327. if (isBetween(n, 2, 4)) return 'few';
  9328. if (n == 1) return 'one';
  9329. return 'other';
  9330. },
  9331. '13': function _(n) {
  9332. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  9333. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  9334. if (n == 1) return 'one';
  9335. return 'other';
  9336. },
  9337. '14': function _(n) {
  9338. if (isBetween(n % 100, 3, 4)) return 'few';
  9339. if (n % 100 == 2) return 'two';
  9340. if (n % 100 == 1) return 'one';
  9341. return 'other';
  9342. },
  9343. '15': function _(n) {
  9344. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  9345. if (isBetween(n % 100, 11, 19)) return 'many';
  9346. if (n == 1) return 'one';
  9347. return 'other';
  9348. },
  9349. '16': function _(n) {
  9350. if (n % 10 == 1 && n != 11) return 'one';
  9351. return 'other';
  9352. },
  9353. '17': function _(n) {
  9354. if (n == 3) return 'few';
  9355. if (n === 0) return 'zero';
  9356. if (n == 6) return 'many';
  9357. if (n == 2) return 'two';
  9358. if (n == 1) return 'one';
  9359. return 'other';
  9360. },
  9361. '18': function _(n) {
  9362. if (n === 0) return 'zero';
  9363. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  9364. return 'other';
  9365. },
  9366. '19': function _(n) {
  9367. if (isBetween(n, 2, 10)) return 'few';
  9368. if (isBetween(n, 0, 1)) return 'one';
  9369. return 'other';
  9370. },
  9371. '20': function _(n) {
  9372. if ((isBetween(n % 10, 3, 4) || n % 10 == 9) && !(isBetween(n % 100, 10, 19) || isBetween(n % 100, 70, 79) || isBetween(n % 100, 90, 99))) return 'few';
  9373. if (n % 1000000 === 0 && n !== 0) return 'many';
  9374. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  9375. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  9376. return 'other';
  9377. },
  9378. '21': function _(n) {
  9379. if (n === 0) return 'zero';
  9380. if (n == 1) return 'one';
  9381. return 'other';
  9382. },
  9383. '22': function _(n) {
  9384. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  9385. return 'other';
  9386. },
  9387. '23': function _(n) {
  9388. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  9389. return 'other';
  9390. },
  9391. '24': function _(n) {
  9392. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  9393. if (isIn(n, [2, 12])) return 'two';
  9394. if (isIn(n, [1, 11])) return 'one';
  9395. return 'other';
  9396. }
  9397. };
  9398. var index = locales2rules[lang.replace(/-.*$/, '')];
  9399. if (!(index in pluralRules)) {
  9400. console.warn('plural form unknown for [' + lang + ']');
  9401. return function () {
  9402. return 'other';
  9403. };
  9404. }
  9405. return pluralRules[index];
  9406. }
  9407. gMacros.plural = function (str, param, key, prop) {
  9408. var n = parseFloat(param);
  9409. if (isNaN(n)) return str;
  9410. if (prop != gTextProp) return str;
  9411. if (!gMacros._pluralRules) {
  9412. gMacros._pluralRules = getPluralRules(gLanguage);
  9413. }
  9414. var index = '[' + gMacros._pluralRules(n) + ']';
  9415. if (n === 0 && key + '[zero]' in gL10nData) {
  9416. str = gL10nData[key + '[zero]'][prop];
  9417. } else if (n == 1 && key + '[one]' in gL10nData) {
  9418. str = gL10nData[key + '[one]'][prop];
  9419. } else if (n == 2 && key + '[two]' in gL10nData) {
  9420. str = gL10nData[key + '[two]'][prop];
  9421. } else if (key + index in gL10nData) {
  9422. str = gL10nData[key + index][prop];
  9423. } else if (key + '[other]' in gL10nData) {
  9424. str = gL10nData[key + '[other]'][prop];
  9425. }
  9426. return str;
  9427. };
  9428. function getL10nData(key, args, fallback) {
  9429. var data = gL10nData[key];
  9430. if (!data) {
  9431. console.warn('#' + key + ' is undefined.');
  9432. if (!fallback) {
  9433. return null;
  9434. }
  9435. data = fallback;
  9436. }
  9437. var rv = {};
  9438. for (var prop in data) {
  9439. var str = data[prop];
  9440. str = substIndexes(str, args, key, prop);
  9441. str = substArguments(str, args, key);
  9442. rv[prop] = str;
  9443. }
  9444. return rv;
  9445. }
  9446. function substIndexes(str, args, key, prop) {
  9447. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  9448. var reMatch = reIndex.exec(str);
  9449. if (!reMatch || !reMatch.length) return str;
  9450. var macroName = reMatch[1];
  9451. var paramName = reMatch[2];
  9452. var param;
  9453. if (args && paramName in args) {
  9454. param = args[paramName];
  9455. } else if (paramName in gL10nData) {
  9456. param = gL10nData[paramName];
  9457. }
  9458. if (macroName in gMacros) {
  9459. var macro = gMacros[macroName];
  9460. str = macro(str, param, key, prop);
  9461. }
  9462. return str;
  9463. }
  9464. function substArguments(str, args, key) {
  9465. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  9466. return str.replace(reArgs, function (matched_text, arg) {
  9467. if (args && arg in args) {
  9468. return args[arg];
  9469. }
  9470. if (arg in gL10nData) {
  9471. return gL10nData[arg];
  9472. }
  9473. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  9474. return matched_text;
  9475. });
  9476. }
  9477. function translateElement(element) {
  9478. var l10n = getL10nAttributes(element);
  9479. if (!l10n.id) return;
  9480. var data = getL10nData(l10n.id, l10n.args);
  9481. if (!data) {
  9482. console.warn('#' + l10n.id + ' is undefined.');
  9483. return;
  9484. }
  9485. if (data[gTextProp]) {
  9486. if (getChildElementCount(element) === 0) {
  9487. element[gTextProp] = data[gTextProp];
  9488. } else {
  9489. var children = element.childNodes;
  9490. var found = false;
  9491. for (var i = 0, l = children.length; i < l; i++) {
  9492. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  9493. if (found) {
  9494. children[i].nodeValue = '';
  9495. } else {
  9496. children[i].nodeValue = data[gTextProp];
  9497. found = true;
  9498. }
  9499. }
  9500. }
  9501. if (!found) {
  9502. var textNode = document.createTextNode(data[gTextProp]);
  9503. element.insertBefore(textNode, element.firstChild);
  9504. }
  9505. }
  9506. delete data[gTextProp];
  9507. }
  9508. for (var k in data) {
  9509. element[k] = data[k];
  9510. }
  9511. }
  9512. function getChildElementCount(element) {
  9513. if (element.children) {
  9514. return element.children.length;
  9515. }
  9516. if (typeof element.childElementCount !== 'undefined') {
  9517. return element.childElementCount;
  9518. }
  9519. var count = 0;
  9520. for (var i = 0; i < element.childNodes.length; i++) {
  9521. count += element.nodeType === 1 ? 1 : 0;
  9522. }
  9523. return count;
  9524. }
  9525. function translateFragment(element) {
  9526. element = element || document.documentElement;
  9527. var children = getTranslatableChildren(element);
  9528. var elementCount = children.length;
  9529. for (var i = 0; i < elementCount; i++) {
  9530. translateElement(children[i]);
  9531. }
  9532. translateElement(element);
  9533. }
  9534. return {
  9535. get: function get(key, args, fallbackString) {
  9536. var index = key.lastIndexOf('.');
  9537. var prop = gTextProp;
  9538. if (index > 0) {
  9539. prop = key.substr(index + 1);
  9540. key = key.substring(0, index);
  9541. }
  9542. var fallback;
  9543. if (fallbackString) {
  9544. fallback = {};
  9545. fallback[prop] = fallbackString;
  9546. }
  9547. var data = getL10nData(key, args, fallback);
  9548. if (data && prop in data) {
  9549. return data[prop];
  9550. }
  9551. return '{{' + key + '}}';
  9552. },
  9553. getData: function getData() {
  9554. return gL10nData;
  9555. },
  9556. getText: function getText() {
  9557. return gTextData;
  9558. },
  9559. getLanguage: function getLanguage() {
  9560. return gLanguage;
  9561. },
  9562. setLanguage: function setLanguage(lang, callback) {
  9563. loadLocale(lang, function () {
  9564. if (callback) callback();
  9565. });
  9566. },
  9567. getDirection: function getDirection() {
  9568. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  9569. var shortCode = gLanguage.split('-', 1)[0];
  9570. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  9571. },
  9572. translate: translateFragment,
  9573. getReadyState: function getReadyState() {
  9574. return gReadyState;
  9575. },
  9576. ready: function ready(callback) {
  9577. if (!callback) {
  9578. return;
  9579. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  9580. window.setTimeout(function () {
  9581. callback();
  9582. });
  9583. } else if (document.addEventListener) {
  9584. document.addEventListener('localized', function once() {
  9585. document.removeEventListener('localized', once);
  9586. callback();
  9587. });
  9588. }
  9589. }
  9590. };
  9591. }(window, document);
  9592. /***/ }),
  9593. /* 34 */
  9594. /***/ (function(module, exports, __webpack_require__) {
  9595. "use strict";
  9596. Object.defineProperty(exports, "__esModule", {
  9597. value: true
  9598. });
  9599. exports.PDFPrintService = undefined;
  9600. var _ui_utils = __webpack_require__(0);
  9601. var _app = __webpack_require__(4);
  9602. var _pdfjsLib = __webpack_require__(1);
  9603. var activeService = null;
  9604. var overlayManager = null;
  9605. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size) {
  9606. var scratchCanvas = activeService.scratchCanvas;
  9607. var PRINT_RESOLUTION = 150;
  9608. var PRINT_UNITS = PRINT_RESOLUTION / 72.0;
  9609. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  9610. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  9611. var width = Math.floor(size.width * _ui_utils.CSS_UNITS) + 'px';
  9612. var height = Math.floor(size.height * _ui_utils.CSS_UNITS) + 'px';
  9613. var ctx = scratchCanvas.getContext('2d');
  9614. ctx.save();
  9615. ctx.fillStyle = 'rgb(255, 255, 255)';
  9616. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  9617. ctx.restore();
  9618. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  9619. var renderContext = {
  9620. canvasContext: ctx,
  9621. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  9622. viewport: pdfPage.getViewport(1, size.rotation),
  9623. intent: 'print'
  9624. };
  9625. return pdfPage.render(renderContext).promise;
  9626. }).then(function () {
  9627. return {
  9628. width: width,
  9629. height: height
  9630. };
  9631. });
  9632. }
  9633. function PDFPrintService(pdfDocument, pagesOverview, printContainer, l10n) {
  9634. this.pdfDocument = pdfDocument;
  9635. this.pagesOverview = pagesOverview;
  9636. this.printContainer = printContainer;
  9637. this.l10n = l10n || _ui_utils.NullL10n;
  9638. this.currentPage = -1;
  9639. this.scratchCanvas = document.createElement('canvas');
  9640. }
  9641. PDFPrintService.prototype = {
  9642. layout: function layout() {
  9643. this.throwIfInactive();
  9644. var body = document.querySelector('body');
  9645. body.setAttribute('data-pdfjsprinting', true);
  9646. var hasEqualPageSizes = this.pagesOverview.every(function (size) {
  9647. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  9648. }, this);
  9649. if (!hasEqualPageSizes) {
  9650. console.warn('Not all pages have the same size. The printed ' + 'result may be incorrect!');
  9651. }
  9652. this.pageStyleSheet = document.createElement('style');
  9653. var pageSize = this.pagesOverview[0];
  9654. this.pageStyleSheet.textContent = '@supports ((size:A4) and (size:1pt 1pt)) {' + '@page { size: ' + pageSize.width + 'pt ' + pageSize.height + 'pt;}' + '}';
  9655. body.appendChild(this.pageStyleSheet);
  9656. },
  9657. destroy: function destroy() {
  9658. if (activeService !== this) {
  9659. return;
  9660. }
  9661. this.printContainer.textContent = '';
  9662. if (this.pageStyleSheet && this.pageStyleSheet.parentNode) {
  9663. this.pageStyleSheet.parentNode.removeChild(this.pageStyleSheet);
  9664. this.pageStyleSheet = null;
  9665. }
  9666. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  9667. this.scratchCanvas = null;
  9668. activeService = null;
  9669. ensureOverlay().then(function () {
  9670. if (overlayManager.active !== 'printServiceOverlay') {
  9671. return;
  9672. }
  9673. overlayManager.close('printServiceOverlay');
  9674. });
  9675. },
  9676. renderPages: function renderPages() {
  9677. var _this = this;
  9678. var pageCount = this.pagesOverview.length;
  9679. var renderNextPage = function renderNextPage(resolve, reject) {
  9680. _this.throwIfInactive();
  9681. if (++_this.currentPage >= pageCount) {
  9682. renderProgress(pageCount, pageCount, _this.l10n);
  9683. resolve();
  9684. return;
  9685. }
  9686. var index = _this.currentPage;
  9687. renderProgress(index, pageCount, _this.l10n);
  9688. renderPage(_this, _this.pdfDocument, index + 1, _this.pagesOverview[index]).then(_this.useRenderedPage.bind(_this)).then(function () {
  9689. renderNextPage(resolve, reject);
  9690. }, reject);
  9691. };
  9692. return new Promise(renderNextPage);
  9693. },
  9694. useRenderedPage: function useRenderedPage(printItem) {
  9695. this.throwIfInactive();
  9696. var img = document.createElement('img');
  9697. img.style.width = printItem.width;
  9698. img.style.height = printItem.height;
  9699. var scratchCanvas = this.scratchCanvas;
  9700. if ('toBlob' in scratchCanvas && !_pdfjsLib.PDFJS.disableCreateObjectURL) {
  9701. scratchCanvas.toBlob(function (blob) {
  9702. img.src = URL.createObjectURL(blob);
  9703. });
  9704. } else {
  9705. img.src = scratchCanvas.toDataURL();
  9706. }
  9707. var wrapper = document.createElement('div');
  9708. wrapper.appendChild(img);
  9709. this.printContainer.appendChild(wrapper);
  9710. return new Promise(function (resolve, reject) {
  9711. img.onload = resolve;
  9712. img.onerror = reject;
  9713. });
  9714. },
  9715. performPrint: function performPrint() {
  9716. var _this2 = this;
  9717. this.throwIfInactive();
  9718. return new Promise(function (resolve) {
  9719. setTimeout(function () {
  9720. if (!_this2.active) {
  9721. resolve();
  9722. return;
  9723. }
  9724. print.call(window);
  9725. setTimeout(resolve, 20);
  9726. }, 0);
  9727. });
  9728. },
  9729. get active() {
  9730. return this === activeService;
  9731. },
  9732. throwIfInactive: function throwIfInactive() {
  9733. if (!this.active) {
  9734. throw new Error('This print request was cancelled or completed.');
  9735. }
  9736. }
  9737. };
  9738. var print = window.print;
  9739. window.print = function print() {
  9740. if (activeService) {
  9741. console.warn('Ignored window.print() because of a pending print job.');
  9742. return;
  9743. }
  9744. ensureOverlay().then(function () {
  9745. if (activeService) {
  9746. overlayManager.open('printServiceOverlay');
  9747. }
  9748. });
  9749. try {
  9750. dispatchEvent('beforeprint');
  9751. } finally {
  9752. if (!activeService) {
  9753. console.error('Expected print service to be initialized.');
  9754. ensureOverlay().then(function () {
  9755. if (overlayManager.active === 'printServiceOverlay') {
  9756. overlayManager.close('printServiceOverlay');
  9757. }
  9758. });
  9759. return;
  9760. }
  9761. var activeServiceOnEntry = activeService;
  9762. activeService.renderPages().then(function () {
  9763. return activeServiceOnEntry.performPrint();
  9764. }).catch(function () {}).then(function () {
  9765. if (activeServiceOnEntry.active) {
  9766. abort();
  9767. }
  9768. });
  9769. }
  9770. };
  9771. function dispatchEvent(eventType) {
  9772. var event = document.createEvent('CustomEvent');
  9773. event.initCustomEvent(eventType, false, false, 'custom');
  9774. window.dispatchEvent(event);
  9775. }
  9776. function abort() {
  9777. if (activeService) {
  9778. activeService.destroy();
  9779. dispatchEvent('afterprint');
  9780. }
  9781. }
  9782. function renderProgress(index, total, l10n) {
  9783. var progressContainer = document.getElementById('printServiceOverlay');
  9784. var progress = Math.round(100 * index / total);
  9785. var progressBar = progressContainer.querySelector('progress');
  9786. var progressPerc = progressContainer.querySelector('.relative-progress');
  9787. progressBar.value = progress;
  9788. l10n.get('print_progress_percent', { progress: progress }, progress + '%').then(function (msg) {
  9789. progressPerc.textContent = msg;
  9790. });
  9791. }
  9792. var hasAttachEvent = !!document.attachEvent;
  9793. window.addEventListener('keydown', function (event) {
  9794. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  9795. window.print();
  9796. if (hasAttachEvent) {
  9797. return;
  9798. }
  9799. event.preventDefault();
  9800. if (event.stopImmediatePropagation) {
  9801. event.stopImmediatePropagation();
  9802. } else {
  9803. event.stopPropagation();
  9804. }
  9805. return;
  9806. }
  9807. }, true);
  9808. if (hasAttachEvent) {
  9809. document.attachEvent('onkeydown', function (event) {
  9810. event = event || window.event;
  9811. if (event.keyCode === 80 && event.ctrlKey) {
  9812. event.keyCode = 0;
  9813. return false;
  9814. }
  9815. });
  9816. }
  9817. if ('onbeforeprint' in window) {
  9818. var stopPropagationIfNeeded = function stopPropagationIfNeeded(event) {
  9819. if (event.detail !== 'custom' && event.stopImmediatePropagation) {
  9820. event.stopImmediatePropagation();
  9821. }
  9822. };
  9823. window.addEventListener('beforeprint', stopPropagationIfNeeded);
  9824. window.addEventListener('afterprint', stopPropagationIfNeeded);
  9825. }
  9826. var overlayPromise = void 0;
  9827. function ensureOverlay() {
  9828. if (!overlayPromise) {
  9829. overlayManager = _app.PDFViewerApplication.overlayManager;
  9830. if (!overlayManager) {
  9831. throw new Error('The overlay manager has not yet been initialized.');
  9832. }
  9833. overlayPromise = overlayManager.register('printServiceOverlay', document.getElementById('printServiceOverlay'), abort, true);
  9834. document.getElementById('printCancel').onclick = abort;
  9835. }
  9836. return overlayPromise;
  9837. }
  9838. _app.PDFPrintServiceFactory.instance = {
  9839. supportsPrinting: true,
  9840. createPrintService: function createPrintService(pdfDocument, pagesOverview, printContainer, l10n) {
  9841. if (activeService) {
  9842. throw new Error('The print service is created and active.');
  9843. }
  9844. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, l10n);
  9845. return activeService;
  9846. }
  9847. };
  9848. exports.PDFPrintService = PDFPrintService;
  9849. /***/ })
  9850. /******/ ]);
  9851. //# sourceMappingURL=viewer.js.map