viewer.js 335 KB

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