viewer.js 335 KB

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