viewer.js 336 KB

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