viewer.js 335 KB

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