pdf_viewer.js 183 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 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 webpackUniversalModuleDefinition(root, factory) {
  23. if(typeof exports === 'object' && typeof module === 'object')
  24. module.exports = factory();
  25. else if(typeof define === 'function' && define.amd)
  26. define("pdfjs-dist/web/pdf_viewer", [], factory);
  27. else if(typeof exports === 'object')
  28. exports["pdfjs-dist/web/pdf_viewer"] = factory();
  29. else
  30. root["pdfjs-dist/web/pdf_viewer"] = root.pdfjsViewer = factory();
  31. })(this, function() {
  32. return /******/ (() => { // webpackBootstrap
  33. /******/ "use strict";
  34. /******/ var __webpack_modules__ = ([
  35. /* 0 */,
  36. /* 1 */
  37. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  38. Object.defineProperty(exports, "__esModule", ({
  39. value: true
  40. }));
  41. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
  42. var _pdfjsLib = __w_pdfjs_require__(2);
  43. var _l10n_utils = __w_pdfjs_require__(3);
  44. var _pdf_link_service = __w_pdfjs_require__(4);
  45. class AnnotationLayerBuilder {
  46. constructor({
  47. pageDiv,
  48. pdfPage,
  49. linkService,
  50. downloadManager,
  51. annotationStorage = null,
  52. imageResourcesPath = "",
  53. renderInteractiveForms = true,
  54. l10n = _l10n_utils.NullL10n,
  55. enableScripting = false,
  56. hasJSActionsPromise = null,
  57. mouseState = null
  58. }) {
  59. this.pageDiv = pageDiv;
  60. this.pdfPage = pdfPage;
  61. this.linkService = linkService;
  62. this.downloadManager = downloadManager;
  63. this.imageResourcesPath = imageResourcesPath;
  64. this.renderInteractiveForms = renderInteractiveForms;
  65. this.l10n = l10n;
  66. this.annotationStorage = annotationStorage;
  67. this.enableScripting = enableScripting;
  68. this._hasJSActionsPromise = hasJSActionsPromise;
  69. this._mouseState = mouseState;
  70. this.div = null;
  71. this._cancelled = false;
  72. }
  73. render(viewport, intent = "display") {
  74. return Promise.all([this.pdfPage.getAnnotations({
  75. intent
  76. }), this._hasJSActionsPromise]).then(([annotations, hasJSActions = false]) => {
  77. if (this._cancelled) {
  78. return;
  79. }
  80. if (annotations.length === 0) {
  81. return;
  82. }
  83. const parameters = {
  84. viewport: viewport.clone({
  85. dontFlip: true
  86. }),
  87. div: this.div,
  88. annotations,
  89. page: this.pdfPage,
  90. imageResourcesPath: this.imageResourcesPath,
  91. renderInteractiveForms: this.renderInteractiveForms,
  92. linkService: this.linkService,
  93. downloadManager: this.downloadManager,
  94. annotationStorage: this.annotationStorage,
  95. enableScripting: this.enableScripting,
  96. hasJSActions,
  97. mouseState: this._mouseState
  98. };
  99. if (this.div) {
  100. _pdfjsLib.AnnotationLayer.update(parameters);
  101. } else {
  102. this.div = document.createElement("div");
  103. this.div.className = "annotationLayer";
  104. this.pageDiv.appendChild(this.div);
  105. parameters.div = this.div;
  106. _pdfjsLib.AnnotationLayer.render(parameters);
  107. this.l10n.translate(this.div);
  108. }
  109. });
  110. }
  111. cancel() {
  112. this._cancelled = true;
  113. }
  114. hide() {
  115. if (!this.div) {
  116. return;
  117. }
  118. this.div.hidden = true;
  119. }
  120. }
  121. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  122. class DefaultAnnotationLayerFactory {
  123. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = true, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
  124. return new AnnotationLayerBuilder({
  125. pageDiv,
  126. pdfPage,
  127. imageResourcesPath,
  128. renderInteractiveForms,
  129. linkService: new _pdf_link_service.SimpleLinkService(),
  130. l10n,
  131. annotationStorage,
  132. enableScripting,
  133. hasJSActionsPromise,
  134. mouseState
  135. });
  136. }
  137. }
  138. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  139. /***/ }),
  140. /* 2 */
  141. /***/ ((module) => {
  142. let pdfjsLib;
  143. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  144. pdfjsLib = window["pdfjs-dist/build/pdf"];
  145. } else {
  146. pdfjsLib = require("../build/pdf.js");
  147. }
  148. module.exports = pdfjsLib;
  149. /***/ }),
  150. /* 3 */
  151. /***/ ((__unused_webpack_module, exports) => {
  152. Object.defineProperty(exports, "__esModule", ({
  153. value: true
  154. }));
  155. exports.getL10nFallback = getL10nFallback;
  156. exports.NullL10n = void 0;
  157. const DEFAULT_L10N_STRINGS = {
  158. of_pages: "of {{pagesCount}}",
  159. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  160. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  161. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  162. document_properties_date_string: "{{date}}, {{time}}",
  163. document_properties_page_size_unit_inches: "in",
  164. document_properties_page_size_unit_millimeters: "mm",
  165. document_properties_page_size_orientation_portrait: "portrait",
  166. document_properties_page_size_orientation_landscape: "landscape",
  167. document_properties_page_size_name_a3: "A3",
  168. document_properties_page_size_name_a4: "A4",
  169. document_properties_page_size_name_letter: "Letter",
  170. document_properties_page_size_name_legal: "Legal",
  171. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  172. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  173. document_properties_linearized_yes: "Yes",
  174. document_properties_linearized_no: "No",
  175. print_progress_percent: "{{progress}}%",
  176. "toggle_sidebar.title": "Toggle Sidebar",
  177. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  178. additional_layers: "Additional Layers",
  179. page_landmark: "Page {{page}}",
  180. thumb_page_title: "Page {{page}}",
  181. thumb_page_canvas: "Thumbnail of Page {{page}}",
  182. find_reached_top: "Reached top of document, continued from bottom",
  183. find_reached_bottom: "Reached end of document, continued from top",
  184. "find_match_count[one]": "{{current}} of {{total}} match",
  185. "find_match_count[other]": "{{current}} of {{total}} matches",
  186. "find_match_count_limit[one]": "More than {{limit}} match",
  187. "find_match_count_limit[other]": "More than {{limit}} matches",
  188. find_not_found: "Phrase not found",
  189. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  190. error_message: "Message: {{message}}",
  191. error_stack: "Stack: {{stack}}",
  192. error_file: "File: {{file}}",
  193. error_line: "Line: {{line}}",
  194. rendering_error: "An error occurred while rendering the page.",
  195. page_scale_width: "Page Width",
  196. page_scale_fit: "Page Fit",
  197. page_scale_auto: "Automatic Zoom",
  198. page_scale_actual: "Actual Size",
  199. page_scale_percent: "{{scale}}%",
  200. loading: "Loading…",
  201. loading_error: "An error occurred while loading the PDF.",
  202. invalid_file_error: "Invalid or corrupted PDF file.",
  203. missing_file_error: "Missing PDF file.",
  204. unexpected_response_error: "Unexpected server response.",
  205. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  206. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  207. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  208. };
  209. function getL10nFallback(key, args) {
  210. switch (key) {
  211. case "find_match_count":
  212. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  213. break;
  214. case "find_match_count_limit":
  215. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  216. break;
  217. }
  218. return DEFAULT_L10N_STRINGS[key] || "";
  219. }
  220. function formatL10nValue(text, args) {
  221. if (!args) {
  222. return text;
  223. }
  224. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  225. return name in args ? args[name] : "{{" + name + "}}";
  226. });
  227. }
  228. const NullL10n = {
  229. async getLanguage() {
  230. return "en-us";
  231. },
  232. async getDirection() {
  233. return "ltr";
  234. },
  235. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  236. return formatL10nValue(fallback, args);
  237. },
  238. async translate(element) {}
  239. };
  240. exports.NullL10n = NullL10n;
  241. /***/ }),
  242. /* 4 */
  243. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  244. Object.defineProperty(exports, "__esModule", ({
  245. value: true
  246. }));
  247. exports.SimpleLinkService = exports.PDFLinkService = void 0;
  248. var _ui_utils = __w_pdfjs_require__(5);
  249. class PDFLinkService {
  250. constructor({
  251. eventBus,
  252. externalLinkTarget = null,
  253. externalLinkRel = null,
  254. externalLinkEnabled = true,
  255. ignoreDestinationZoom = false
  256. } = {}) {
  257. this.eventBus = eventBus;
  258. this.externalLinkTarget = externalLinkTarget;
  259. this.externalLinkRel = externalLinkRel;
  260. this.externalLinkEnabled = externalLinkEnabled;
  261. this._ignoreDestinationZoom = ignoreDestinationZoom;
  262. this.baseUrl = null;
  263. this.pdfDocument = null;
  264. this.pdfViewer = null;
  265. this.pdfHistory = null;
  266. this._pagesRefCache = null;
  267. }
  268. setDocument(pdfDocument, baseUrl = null) {
  269. this.baseUrl = baseUrl;
  270. this.pdfDocument = pdfDocument;
  271. this._pagesRefCache = Object.create(null);
  272. }
  273. setViewer(pdfViewer) {
  274. this.pdfViewer = pdfViewer;
  275. }
  276. setHistory(pdfHistory) {
  277. this.pdfHistory = pdfHistory;
  278. }
  279. get pagesCount() {
  280. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  281. }
  282. get page() {
  283. return this.pdfViewer.currentPageNumber;
  284. }
  285. set page(value) {
  286. this.pdfViewer.currentPageNumber = value;
  287. }
  288. get rotation() {
  289. return this.pdfViewer.pagesRotation;
  290. }
  291. set rotation(value) {
  292. this.pdfViewer.pagesRotation = value;
  293. }
  294. navigateTo(dest) {
  295. console.error("Deprecated method: `navigateTo`, use `goToDestination` instead.");
  296. this.goToDestination(dest);
  297. }
  298. _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  299. const destRef = explicitDest[0];
  300. let pageNumber;
  301. if (destRef instanceof Object) {
  302. pageNumber = this._cachedPageNumber(destRef);
  303. if (pageNumber === null) {
  304. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  305. this.cachePageRef(pageIndex + 1, destRef);
  306. this._goToDestinationHelper(rawDest, namedDest, explicitDest);
  307. }).catch(() => {
  308. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  309. });
  310. return;
  311. }
  312. } else if (Number.isInteger(destRef)) {
  313. pageNumber = destRef + 1;
  314. } else {
  315. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  316. return;
  317. }
  318. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  319. console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  320. return;
  321. }
  322. if (this.pdfHistory) {
  323. this.pdfHistory.pushCurrentPosition();
  324. this.pdfHistory.push({
  325. namedDest,
  326. explicitDest,
  327. pageNumber
  328. });
  329. }
  330. this.pdfViewer.scrollPageIntoView({
  331. pageNumber,
  332. destArray: explicitDest,
  333. ignoreDestinationZoom: this._ignoreDestinationZoom
  334. });
  335. }
  336. async goToDestination(dest) {
  337. if (!this.pdfDocument) {
  338. return;
  339. }
  340. let namedDest, explicitDest;
  341. if (typeof dest === "string") {
  342. namedDest = dest;
  343. explicitDest = await this.pdfDocument.getDestination(dest);
  344. } else {
  345. namedDest = null;
  346. explicitDest = await dest;
  347. }
  348. if (!Array.isArray(explicitDest)) {
  349. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  350. return;
  351. }
  352. this._goToDestinationHelper(dest, namedDest, explicitDest);
  353. }
  354. goToPage(val) {
  355. if (!this.pdfDocument) {
  356. return;
  357. }
  358. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  359. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  360. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  361. return;
  362. }
  363. if (this.pdfHistory) {
  364. this.pdfHistory.pushCurrentPosition();
  365. this.pdfHistory.pushPage(pageNumber);
  366. }
  367. this.pdfViewer.scrollPageIntoView({
  368. pageNumber
  369. });
  370. }
  371. getDestinationHash(dest) {
  372. if (typeof dest === "string") {
  373. if (dest.length > 0) {
  374. return this.getAnchorUrl("#" + escape(dest));
  375. }
  376. } else if (Array.isArray(dest)) {
  377. const str = JSON.stringify(dest);
  378. if (str.length > 0) {
  379. return this.getAnchorUrl("#" + escape(str));
  380. }
  381. }
  382. return this.getAnchorUrl("");
  383. }
  384. getAnchorUrl(anchor) {
  385. return (this.baseUrl || "") + anchor;
  386. }
  387. setHash(hash) {
  388. if (!this.pdfDocument) {
  389. return;
  390. }
  391. let pageNumber, dest;
  392. if (hash.includes("=")) {
  393. const params = (0, _ui_utils.parseQueryString)(hash);
  394. if ("search" in params) {
  395. this.eventBus.dispatch("findfromurlhash", {
  396. source: this,
  397. query: params.search.replace(/"/g, ""),
  398. phraseSearch: params.phrase === "true"
  399. });
  400. }
  401. if ("page" in params) {
  402. pageNumber = params.page | 0 || 1;
  403. }
  404. if ("zoom" in params) {
  405. const zoomArgs = params.zoom.split(",");
  406. const zoomArg = zoomArgs[0];
  407. const zoomArgNumber = parseFloat(zoomArg);
  408. if (!zoomArg.includes("Fit")) {
  409. dest = [null, {
  410. name: "XYZ"
  411. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  412. } else {
  413. if (zoomArg === "Fit" || zoomArg === "FitB") {
  414. dest = [null, {
  415. name: zoomArg
  416. }];
  417. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  418. dest = [null, {
  419. name: zoomArg
  420. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  421. } else if (zoomArg === "FitR") {
  422. if (zoomArgs.length !== 5) {
  423. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  424. } else {
  425. dest = [null, {
  426. name: zoomArg
  427. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  428. }
  429. } else {
  430. console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
  431. }
  432. }
  433. }
  434. if (dest) {
  435. this.pdfViewer.scrollPageIntoView({
  436. pageNumber: pageNumber || this.page,
  437. destArray: dest,
  438. allowNegativeOffset: true
  439. });
  440. } else if (pageNumber) {
  441. this.page = pageNumber;
  442. }
  443. if ("pagemode" in params) {
  444. this.eventBus.dispatch("pagemode", {
  445. source: this,
  446. mode: params.pagemode
  447. });
  448. }
  449. if ("nameddest" in params) {
  450. this.goToDestination(params.nameddest);
  451. }
  452. } else {
  453. dest = unescape(hash);
  454. try {
  455. dest = JSON.parse(dest);
  456. if (!Array.isArray(dest)) {
  457. dest = dest.toString();
  458. }
  459. } catch (ex) {}
  460. if (typeof dest === "string" || isValidExplicitDestination(dest)) {
  461. this.goToDestination(dest);
  462. return;
  463. }
  464. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
  465. }
  466. }
  467. executeNamedAction(action) {
  468. switch (action) {
  469. case "GoBack":
  470. if (this.pdfHistory) {
  471. this.pdfHistory.back();
  472. }
  473. break;
  474. case "GoForward":
  475. if (this.pdfHistory) {
  476. this.pdfHistory.forward();
  477. }
  478. break;
  479. case "NextPage":
  480. this.pdfViewer.nextPage();
  481. break;
  482. case "PrevPage":
  483. this.pdfViewer.previousPage();
  484. break;
  485. case "LastPage":
  486. this.page = this.pagesCount;
  487. break;
  488. case "FirstPage":
  489. this.page = 1;
  490. break;
  491. default:
  492. break;
  493. }
  494. this.eventBus.dispatch("namedaction", {
  495. source: this,
  496. action
  497. });
  498. }
  499. cachePageRef(pageNum, pageRef) {
  500. if (!pageRef) {
  501. return;
  502. }
  503. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  504. this._pagesRefCache[refStr] = pageNum;
  505. }
  506. _cachedPageNumber(pageRef) {
  507. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  508. return this._pagesRefCache?.[refStr] || null;
  509. }
  510. isPageVisible(pageNumber) {
  511. return this.pdfViewer.isPageVisible(pageNumber);
  512. }
  513. isPageCached(pageNumber) {
  514. return this.pdfViewer.isPageCached(pageNumber);
  515. }
  516. }
  517. exports.PDFLinkService = PDFLinkService;
  518. function isValidExplicitDestination(dest) {
  519. if (!Array.isArray(dest)) {
  520. return false;
  521. }
  522. const destLength = dest.length;
  523. if (destLength < 2) {
  524. return false;
  525. }
  526. const page = dest[0];
  527. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  528. return false;
  529. }
  530. const zoom = dest[1];
  531. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  532. return false;
  533. }
  534. let allowNull = true;
  535. switch (zoom.name) {
  536. case "XYZ":
  537. if (destLength !== 5) {
  538. return false;
  539. }
  540. break;
  541. case "Fit":
  542. case "FitB":
  543. return destLength === 2;
  544. case "FitH":
  545. case "FitBH":
  546. case "FitV":
  547. case "FitBV":
  548. if (destLength !== 3) {
  549. return false;
  550. }
  551. break;
  552. case "FitR":
  553. if (destLength !== 6) {
  554. return false;
  555. }
  556. allowNull = false;
  557. break;
  558. default:
  559. return false;
  560. }
  561. for (let i = 2; i < destLength; i++) {
  562. const param = dest[i];
  563. if (!(typeof param === "number" || allowNull && param === null)) {
  564. return false;
  565. }
  566. }
  567. return true;
  568. }
  569. class SimpleLinkService {
  570. constructor() {
  571. this.externalLinkTarget = null;
  572. this.externalLinkRel = null;
  573. this.externalLinkEnabled = true;
  574. this._ignoreDestinationZoom = false;
  575. }
  576. get pagesCount() {
  577. return 0;
  578. }
  579. get page() {
  580. return 0;
  581. }
  582. set page(value) {}
  583. get rotation() {
  584. return 0;
  585. }
  586. set rotation(value) {}
  587. async goToDestination(dest) {}
  588. goToPage(val) {}
  589. getDestinationHash(dest) {
  590. return "#";
  591. }
  592. getAnchorUrl(hash) {
  593. return "#";
  594. }
  595. setHash(hash) {}
  596. executeNamedAction(action) {}
  597. cachePageRef(pageNum, pageRef) {}
  598. isPageVisible(pageNumber) {
  599. return true;
  600. }
  601. isPageCached(pageNumber) {
  602. return true;
  603. }
  604. }
  605. exports.SimpleLinkService = SimpleLinkService;
  606. /***/ }),
  607. /* 5 */
  608. /***/ ((__unused_webpack_module, exports) => {
  609. Object.defineProperty(exports, "__esModule", ({
  610. value: true
  611. }));
  612. exports.apiPageLayoutToSpreadMode = apiPageLayoutToSpreadMode;
  613. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  614. exports.approximateFraction = approximateFraction;
  615. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  616. exports.binarySearchFirstItem = binarySearchFirstItem;
  617. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  618. exports.getOutputScale = getOutputScale;
  619. exports.getPageSizeInches = getPageSizeInches;
  620. exports.getVisibleElements = getVisibleElements;
  621. exports.isPortraitOrientation = isPortraitOrientation;
  622. exports.isValidRotation = isValidRotation;
  623. exports.isValidScrollMode = isValidScrollMode;
  624. exports.isValidSpreadMode = isValidSpreadMode;
  625. exports.moveToEndOfArray = moveToEndOfArray;
  626. exports.noContextMenuHandler = noContextMenuHandler;
  627. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  628. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  629. exports.parseQueryString = parseQueryString;
  630. exports.roundToDivide = roundToDivide;
  631. exports.scrollIntoView = scrollIntoView;
  632. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  633. exports.watchScroll = watchScroll;
  634. exports.WaitOnType = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.EventBus = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE = exports.CSS_UNITS = exports.AutoPrintRegExp = exports.animationStarted = void 0;
  635. const CSS_UNITS = 96.0 / 72.0;
  636. exports.CSS_UNITS = CSS_UNITS;
  637. const DEFAULT_SCALE_VALUE = "auto";
  638. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  639. const DEFAULT_SCALE = 1.0;
  640. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  641. const MIN_SCALE = 0.1;
  642. exports.MIN_SCALE = MIN_SCALE;
  643. const MAX_SCALE = 10.0;
  644. exports.MAX_SCALE = MAX_SCALE;
  645. const UNKNOWN_SCALE = 0;
  646. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  647. const MAX_AUTO_SCALE = 1.25;
  648. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  649. const SCROLLBAR_PADDING = 40;
  650. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  651. const VERTICAL_PADDING = 5;
  652. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  653. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  654. const PresentationModeState = {
  655. UNKNOWN: 0,
  656. NORMAL: 1,
  657. CHANGING: 2,
  658. FULLSCREEN: 3
  659. };
  660. exports.PresentationModeState = PresentationModeState;
  661. const SidebarView = {
  662. UNKNOWN: -1,
  663. NONE: 0,
  664. THUMBS: 1,
  665. OUTLINE: 2,
  666. ATTACHMENTS: 3,
  667. LAYERS: 4
  668. };
  669. exports.SidebarView = SidebarView;
  670. const RendererType = {
  671. CANVAS: "canvas",
  672. SVG: "svg"
  673. };
  674. exports.RendererType = RendererType;
  675. const TextLayerMode = {
  676. DISABLE: 0,
  677. ENABLE: 1,
  678. ENABLE_ENHANCE: 2
  679. };
  680. exports.TextLayerMode = TextLayerMode;
  681. const ScrollMode = {
  682. UNKNOWN: -1,
  683. VERTICAL: 0,
  684. HORIZONTAL: 1,
  685. WRAPPED: 2
  686. };
  687. exports.ScrollMode = ScrollMode;
  688. const SpreadMode = {
  689. UNKNOWN: -1,
  690. NONE: 0,
  691. ODD: 1,
  692. EVEN: 2
  693. };
  694. exports.SpreadMode = SpreadMode;
  695. const AutoPrintRegExp = /\bprint\s*\(/;
  696. exports.AutoPrintRegExp = AutoPrintRegExp;
  697. function getOutputScale(ctx) {
  698. const devicePixelRatio = window.devicePixelRatio || 1;
  699. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  700. const pixelRatio = devicePixelRatio / backingStoreRatio;
  701. return {
  702. sx: pixelRatio,
  703. sy: pixelRatio,
  704. scaled: pixelRatio !== 1
  705. };
  706. }
  707. function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
  708. let parent = element.offsetParent;
  709. if (!parent) {
  710. console.error("offsetParent is not set -- cannot scroll");
  711. return;
  712. }
  713. let offsetY = element.offsetTop + element.clientTop;
  714. let offsetX = element.offsetLeft + element.clientLeft;
  715. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
  716. if (parent.dataset._scaleY) {
  717. offsetY /= parent.dataset._scaleY;
  718. offsetX /= parent.dataset._scaleX;
  719. }
  720. offsetY += parent.offsetTop;
  721. offsetX += parent.offsetLeft;
  722. parent = parent.offsetParent;
  723. if (!parent) {
  724. return;
  725. }
  726. }
  727. if (spot) {
  728. if (spot.top !== undefined) {
  729. offsetY += spot.top;
  730. }
  731. if (spot.left !== undefined) {
  732. offsetX += spot.left;
  733. parent.scrollLeft = offsetX;
  734. }
  735. }
  736. parent.scrollTop = offsetY;
  737. }
  738. function watchScroll(viewAreaElement, callback) {
  739. const debounceScroll = function (evt) {
  740. if (rAF) {
  741. return;
  742. }
  743. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  744. rAF = null;
  745. const currentX = viewAreaElement.scrollLeft;
  746. const lastX = state.lastX;
  747. if (currentX !== lastX) {
  748. state.right = currentX > lastX;
  749. }
  750. state.lastX = currentX;
  751. const currentY = viewAreaElement.scrollTop;
  752. const lastY = state.lastY;
  753. if (currentY !== lastY) {
  754. state.down = currentY > lastY;
  755. }
  756. state.lastY = currentY;
  757. callback(state);
  758. });
  759. };
  760. const state = {
  761. right: true,
  762. down: true,
  763. lastX: viewAreaElement.scrollLeft,
  764. lastY: viewAreaElement.scrollTop,
  765. _eventHandler: debounceScroll
  766. };
  767. let rAF = null;
  768. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  769. return state;
  770. }
  771. function parseQueryString(query) {
  772. const parts = query.split("&");
  773. const params = Object.create(null);
  774. for (let i = 0, ii = parts.length; i < ii; ++i) {
  775. const param = parts[i].split("=");
  776. const key = param[0].toLowerCase();
  777. const value = param.length > 1 ? param[1] : null;
  778. params[decodeURIComponent(key)] = decodeURIComponent(value);
  779. }
  780. return params;
  781. }
  782. function binarySearchFirstItem(items, condition) {
  783. let minIndex = 0;
  784. let maxIndex = items.length - 1;
  785. if (maxIndex < 0 || !condition(items[maxIndex])) {
  786. return items.length;
  787. }
  788. if (condition(items[minIndex])) {
  789. return minIndex;
  790. }
  791. while (minIndex < maxIndex) {
  792. const currentIndex = minIndex + maxIndex >> 1;
  793. const currentItem = items[currentIndex];
  794. if (condition(currentItem)) {
  795. maxIndex = currentIndex;
  796. } else {
  797. minIndex = currentIndex + 1;
  798. }
  799. }
  800. return minIndex;
  801. }
  802. function approximateFraction(x) {
  803. if (Math.floor(x) === x) {
  804. return [x, 1];
  805. }
  806. const xinv = 1 / x;
  807. const limit = 8;
  808. if (xinv > limit) {
  809. return [1, limit];
  810. } else if (Math.floor(xinv) === xinv) {
  811. return [1, xinv];
  812. }
  813. const x_ = x > 1 ? xinv : x;
  814. let a = 0,
  815. b = 1,
  816. c = 1,
  817. d = 1;
  818. while (true) {
  819. const p = a + c,
  820. q = b + d;
  821. if (q > limit) {
  822. break;
  823. }
  824. if (x_ <= p / q) {
  825. c = p;
  826. d = q;
  827. } else {
  828. a = p;
  829. b = q;
  830. }
  831. }
  832. let result;
  833. if (x_ - a / b < c / d - x_) {
  834. result = x_ === x ? [a, b] : [b, a];
  835. } else {
  836. result = x_ === x ? [c, d] : [d, c];
  837. }
  838. return result;
  839. }
  840. function roundToDivide(x, div) {
  841. const r = x % div;
  842. return r === 0 ? x : Math.round(x - r + div);
  843. }
  844. function getPageSizeInches({
  845. view,
  846. userUnit,
  847. rotate
  848. }) {
  849. const [x1, y1, x2, y2] = view;
  850. const changeOrientation = rotate % 180 !== 0;
  851. const width = (x2 - x1) / 72 * userUnit;
  852. const height = (y2 - y1) / 72 * userUnit;
  853. return {
  854. width: changeOrientation ? height : width,
  855. height: changeOrientation ? width : height
  856. };
  857. }
  858. function backtrackBeforeAllVisibleElements(index, views, top) {
  859. if (index < 2) {
  860. return index;
  861. }
  862. let elt = views[index].div;
  863. let pageTop = elt.offsetTop + elt.clientTop;
  864. if (pageTop >= top) {
  865. elt = views[index - 1].div;
  866. pageTop = elt.offsetTop + elt.clientTop;
  867. }
  868. for (let i = index - 2; i >= 0; --i) {
  869. elt = views[i].div;
  870. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  871. break;
  872. }
  873. index = i;
  874. }
  875. return index;
  876. }
  877. function getVisibleElements({
  878. scrollEl,
  879. views,
  880. sortByVisibility = false,
  881. horizontal = false,
  882. rtl = false
  883. }) {
  884. const top = scrollEl.scrollTop,
  885. bottom = top + scrollEl.clientHeight;
  886. const left = scrollEl.scrollLeft,
  887. right = left + scrollEl.clientWidth;
  888. function isElementBottomAfterViewTop(view) {
  889. const element = view.div;
  890. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  891. return elementBottom > top;
  892. }
  893. function isElementNextAfterViewHorizontally(view) {
  894. const element = view.div;
  895. const elementLeft = element.offsetLeft + element.clientLeft;
  896. const elementRight = elementLeft + element.clientWidth;
  897. return rtl ? elementLeft < right : elementRight > left;
  898. }
  899. const visible = [],
  900. numViews = views.length;
  901. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  902. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  903. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  904. }
  905. let lastEdge = horizontal ? right : -1;
  906. for (let i = firstVisibleElementInd; i < numViews; i++) {
  907. const view = views[i],
  908. element = view.div;
  909. const currentWidth = element.offsetLeft + element.clientLeft;
  910. const currentHeight = element.offsetTop + element.clientTop;
  911. const viewWidth = element.clientWidth,
  912. viewHeight = element.clientHeight;
  913. const viewRight = currentWidth + viewWidth;
  914. const viewBottom = currentHeight + viewHeight;
  915. if (lastEdge === -1) {
  916. if (viewBottom >= bottom) {
  917. lastEdge = viewBottom;
  918. }
  919. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  920. break;
  921. }
  922. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  923. continue;
  924. }
  925. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  926. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  927. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  928. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  929. const percent = fractionHeight * fractionWidth * 100 | 0;
  930. visible.push({
  931. id: view.id,
  932. x: currentWidth,
  933. y: currentHeight,
  934. view,
  935. percent,
  936. widthPercent: fractionWidth * 100 | 0
  937. });
  938. }
  939. const first = visible[0],
  940. last = visible[visible.length - 1];
  941. if (sortByVisibility) {
  942. visible.sort(function (a, b) {
  943. const pc = a.percent - b.percent;
  944. if (Math.abs(pc) > 0.001) {
  945. return -pc;
  946. }
  947. return a.id - b.id;
  948. });
  949. }
  950. return {
  951. first,
  952. last,
  953. views: visible
  954. };
  955. }
  956. function noContextMenuHandler(evt) {
  957. evt.preventDefault();
  958. }
  959. function normalizeWheelEventDirection(evt) {
  960. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  961. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  962. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  963. delta = -delta;
  964. }
  965. return delta;
  966. }
  967. function normalizeWheelEventDelta(evt) {
  968. let delta = normalizeWheelEventDirection(evt);
  969. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  970. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  971. const MOUSE_PIXELS_PER_LINE = 30;
  972. const MOUSE_LINES_PER_PAGE = 30;
  973. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  974. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  975. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  976. delta /= MOUSE_LINES_PER_PAGE;
  977. }
  978. return delta;
  979. }
  980. function isValidRotation(angle) {
  981. return Number.isInteger(angle) && angle % 90 === 0;
  982. }
  983. function isValidScrollMode(mode) {
  984. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  985. }
  986. function isValidSpreadMode(mode) {
  987. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  988. }
  989. function isPortraitOrientation(size) {
  990. return size.width <= size.height;
  991. }
  992. const WaitOnType = {
  993. EVENT: "event",
  994. TIMEOUT: "timeout"
  995. };
  996. exports.WaitOnType = WaitOnType;
  997. function waitOnEventOrTimeout({
  998. target,
  999. name,
  1000. delay = 0
  1001. }) {
  1002. return new Promise(function (resolve, reject) {
  1003. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  1004. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  1005. }
  1006. function handler(type) {
  1007. if (target instanceof EventBus) {
  1008. target._off(name, eventHandler);
  1009. } else {
  1010. target.removeEventListener(name, eventHandler);
  1011. }
  1012. if (timeout) {
  1013. clearTimeout(timeout);
  1014. }
  1015. resolve(type);
  1016. }
  1017. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  1018. if (target instanceof EventBus) {
  1019. target._on(name, eventHandler);
  1020. } else {
  1021. target.addEventListener(name, eventHandler);
  1022. }
  1023. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  1024. const timeout = setTimeout(timeoutHandler, delay);
  1025. });
  1026. }
  1027. const animationStarted = new Promise(function (resolve) {
  1028. window.requestAnimationFrame(resolve);
  1029. });
  1030. exports.animationStarted = animationStarted;
  1031. function dispatchDOMEvent(eventName, args = null) {
  1032. throw new Error("Not implemented: dispatchDOMEvent");
  1033. }
  1034. class EventBus {
  1035. constructor(options) {
  1036. this._listeners = Object.create(null);
  1037. }
  1038. on(eventName, listener, options = null) {
  1039. this._on(eventName, listener, {
  1040. external: true,
  1041. once: options?.once
  1042. });
  1043. }
  1044. off(eventName, listener, options = null) {
  1045. this._off(eventName, listener, {
  1046. external: true,
  1047. once: options?.once
  1048. });
  1049. }
  1050. dispatch(eventName) {
  1051. const eventListeners = this._listeners[eventName];
  1052. if (!eventListeners || eventListeners.length === 0) {
  1053. return;
  1054. }
  1055. const args = Array.prototype.slice.call(arguments, 1);
  1056. let externalListeners;
  1057. eventListeners.slice(0).forEach(({
  1058. listener,
  1059. external,
  1060. once
  1061. }) => {
  1062. if (once) {
  1063. this._off(eventName, listener);
  1064. }
  1065. if (external) {
  1066. (externalListeners || (externalListeners = [])).push(listener);
  1067. return;
  1068. }
  1069. listener.apply(null, args);
  1070. });
  1071. if (externalListeners) {
  1072. externalListeners.forEach(listener => {
  1073. listener.apply(null, args);
  1074. });
  1075. externalListeners = null;
  1076. }
  1077. }
  1078. _on(eventName, listener, options = null) {
  1079. var _this$_listeners;
  1080. const eventListeners = (_this$_listeners = this._listeners)[eventName] || (_this$_listeners[eventName] = []);
  1081. eventListeners.push({
  1082. listener,
  1083. external: options?.external === true,
  1084. once: options?.once === true
  1085. });
  1086. }
  1087. _off(eventName, listener, options = null) {
  1088. const eventListeners = this._listeners[eventName];
  1089. if (!eventListeners) {
  1090. return;
  1091. }
  1092. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  1093. if (eventListeners[i].listener === listener) {
  1094. eventListeners.splice(i, 1);
  1095. return;
  1096. }
  1097. }
  1098. }
  1099. }
  1100. exports.EventBus = EventBus;
  1101. function clamp(v, min, max) {
  1102. return Math.min(Math.max(v, min), max);
  1103. }
  1104. class ProgressBar {
  1105. constructor(id, {
  1106. height,
  1107. width,
  1108. units
  1109. } = {}) {
  1110. this.visible = true;
  1111. this.div = document.querySelector(id + " .progress");
  1112. this.bar = this.div.parentNode;
  1113. this.height = height || 100;
  1114. this.width = width || 100;
  1115. this.units = units || "%";
  1116. this.div.style.height = this.height + this.units;
  1117. this.percent = 0;
  1118. }
  1119. _updateBar() {
  1120. if (this._indeterminate) {
  1121. this.div.classList.add("indeterminate");
  1122. this.div.style.width = this.width + this.units;
  1123. return;
  1124. }
  1125. this.div.classList.remove("indeterminate");
  1126. const progressSize = this.width * this._percent / 100;
  1127. this.div.style.width = progressSize + this.units;
  1128. }
  1129. get percent() {
  1130. return this._percent;
  1131. }
  1132. set percent(val) {
  1133. this._indeterminate = isNaN(val);
  1134. this._percent = clamp(val, 0, 100);
  1135. this._updateBar();
  1136. }
  1137. setWidth(viewer) {
  1138. if (!viewer) {
  1139. return;
  1140. }
  1141. const container = viewer.parentNode;
  1142. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  1143. if (scrollbarWidth > 0) {
  1144. const doc = document.documentElement;
  1145. doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  1146. }
  1147. }
  1148. hide() {
  1149. if (!this.visible) {
  1150. return;
  1151. }
  1152. this.visible = false;
  1153. this.bar.classList.add("hidden");
  1154. }
  1155. show() {
  1156. if (this.visible) {
  1157. return;
  1158. }
  1159. this.visible = true;
  1160. this.bar.classList.remove("hidden");
  1161. }
  1162. }
  1163. exports.ProgressBar = ProgressBar;
  1164. function moveToEndOfArray(arr, condition) {
  1165. const moved = [],
  1166. len = arr.length;
  1167. let write = 0;
  1168. for (let read = 0; read < len; ++read) {
  1169. if (condition(arr[read])) {
  1170. moved.push(arr[read]);
  1171. } else {
  1172. arr[write] = arr[read];
  1173. ++write;
  1174. }
  1175. }
  1176. for (let read = 0; write < len; ++read, ++write) {
  1177. arr[write] = moved[read];
  1178. }
  1179. }
  1180. function getActiveOrFocusedElement() {
  1181. let curRoot = document;
  1182. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  1183. while (curActiveOrFocused?.shadowRoot) {
  1184. curRoot = curActiveOrFocused.shadowRoot;
  1185. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  1186. }
  1187. return curActiveOrFocused;
  1188. }
  1189. function apiPageLayoutToSpreadMode(layout) {
  1190. switch (layout) {
  1191. case "SinglePage":
  1192. case "OneColumn":
  1193. return SpreadMode.NONE;
  1194. case "TwoColumnLeft":
  1195. case "TwoPageLeft":
  1196. return SpreadMode.ODD;
  1197. case "TwoColumnRight":
  1198. case "TwoPageRight":
  1199. return SpreadMode.EVEN;
  1200. }
  1201. return SpreadMode.NONE;
  1202. }
  1203. function apiPageModeToSidebarView(mode) {
  1204. switch (mode) {
  1205. case "UseNone":
  1206. return SidebarView.NONE;
  1207. case "UseThumbs":
  1208. return SidebarView.THUMBS;
  1209. case "UseOutlines":
  1210. return SidebarView.OUTLINE;
  1211. case "UseAttachments":
  1212. return SidebarView.ATTACHMENTS;
  1213. case "UseOC":
  1214. return SidebarView.LAYERS;
  1215. }
  1216. return SidebarView.NONE;
  1217. }
  1218. /***/ }),
  1219. /* 6 */
  1220. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1221. Object.defineProperty(exports, "__esModule", ({
  1222. value: true
  1223. }));
  1224. exports.TextLayerBuilder = exports.DefaultTextLayerFactory = void 0;
  1225. var _pdfjsLib = __w_pdfjs_require__(2);
  1226. const EXPAND_DIVS_TIMEOUT = 300;
  1227. class TextLayerBuilder {
  1228. constructor({
  1229. textLayerDiv,
  1230. eventBus,
  1231. pageIndex,
  1232. viewport,
  1233. findController = null,
  1234. enhanceTextSelection = false
  1235. }) {
  1236. this.textLayerDiv = textLayerDiv;
  1237. this.eventBus = eventBus;
  1238. this.textContent = null;
  1239. this.textContentItemsStr = [];
  1240. this.textContentStream = null;
  1241. this.renderingDone = false;
  1242. this.pageIdx = pageIndex;
  1243. this.pageNumber = this.pageIdx + 1;
  1244. this.matches = [];
  1245. this.viewport = viewport;
  1246. this.textDivs = [];
  1247. this.findController = findController;
  1248. this.textLayerRenderTask = null;
  1249. this.enhanceTextSelection = enhanceTextSelection;
  1250. this._onUpdateTextLayerMatches = null;
  1251. this._bindMouse();
  1252. }
  1253. _finishRendering() {
  1254. this.renderingDone = true;
  1255. if (!this.enhanceTextSelection) {
  1256. const endOfContent = document.createElement("div");
  1257. endOfContent.className = "endOfContent";
  1258. this.textLayerDiv.appendChild(endOfContent);
  1259. }
  1260. this.eventBus.dispatch("textlayerrendered", {
  1261. source: this,
  1262. pageNumber: this.pageNumber,
  1263. numTextDivs: this.textDivs.length
  1264. });
  1265. }
  1266. render(timeout = 0) {
  1267. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  1268. return;
  1269. }
  1270. this.cancel();
  1271. this.textDivs = [];
  1272. const textLayerFrag = document.createDocumentFragment();
  1273. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  1274. textContent: this.textContent,
  1275. textContentStream: this.textContentStream,
  1276. container: textLayerFrag,
  1277. viewport: this.viewport,
  1278. textDivs: this.textDivs,
  1279. textContentItemsStr: this.textContentItemsStr,
  1280. timeout,
  1281. enhanceTextSelection: this.enhanceTextSelection
  1282. });
  1283. this.textLayerRenderTask.promise.then(() => {
  1284. this.textLayerDiv.appendChild(textLayerFrag);
  1285. this._finishRendering();
  1286. this._updateMatches();
  1287. }, function (reason) {});
  1288. if (!this._onUpdateTextLayerMatches) {
  1289. this._onUpdateTextLayerMatches = evt => {
  1290. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  1291. this._updateMatches();
  1292. }
  1293. };
  1294. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  1295. }
  1296. }
  1297. cancel() {
  1298. if (this.textLayerRenderTask) {
  1299. this.textLayerRenderTask.cancel();
  1300. this.textLayerRenderTask = null;
  1301. }
  1302. if (this._onUpdateTextLayerMatches) {
  1303. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  1304. this._onUpdateTextLayerMatches = null;
  1305. }
  1306. }
  1307. setTextContentStream(readableStream) {
  1308. this.cancel();
  1309. this.textContentStream = readableStream;
  1310. }
  1311. setTextContent(textContent) {
  1312. this.cancel();
  1313. this.textContent = textContent;
  1314. }
  1315. _convertMatches(matches, matchesLength) {
  1316. if (!matches) {
  1317. return [];
  1318. }
  1319. const {
  1320. textContentItemsStr
  1321. } = this;
  1322. let i = 0,
  1323. iIndex = 0;
  1324. const end = textContentItemsStr.length - 1;
  1325. const result = [];
  1326. for (let m = 0, mm = matches.length; m < mm; m++) {
  1327. let matchIdx = matches[m];
  1328. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  1329. iIndex += textContentItemsStr[i].length;
  1330. i++;
  1331. }
  1332. if (i === textContentItemsStr.length) {
  1333. console.error("Could not find a matching mapping");
  1334. }
  1335. const match = {
  1336. begin: {
  1337. divIdx: i,
  1338. offset: matchIdx - iIndex
  1339. }
  1340. };
  1341. matchIdx += matchesLength[m];
  1342. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  1343. iIndex += textContentItemsStr[i].length;
  1344. i++;
  1345. }
  1346. match.end = {
  1347. divIdx: i,
  1348. offset: matchIdx - iIndex
  1349. };
  1350. result.push(match);
  1351. }
  1352. return result;
  1353. }
  1354. _renderMatches(matches) {
  1355. if (matches.length === 0) {
  1356. return;
  1357. }
  1358. const {
  1359. findController,
  1360. pageIdx,
  1361. textContentItemsStr,
  1362. textDivs
  1363. } = this;
  1364. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  1365. const selectedMatchIdx = findController.selected.matchIdx;
  1366. const highlightAll = findController.state.highlightAll;
  1367. let prevEnd = null;
  1368. const infinity = {
  1369. divIdx: -1,
  1370. offset: undefined
  1371. };
  1372. function beginText(begin, className) {
  1373. const divIdx = begin.divIdx;
  1374. textDivs[divIdx].textContent = "";
  1375. appendTextToDiv(divIdx, 0, begin.offset, className);
  1376. }
  1377. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  1378. const div = textDivs[divIdx];
  1379. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  1380. const node = document.createTextNode(content);
  1381. if (className) {
  1382. const span = document.createElement("span");
  1383. span.className = className;
  1384. span.appendChild(node);
  1385. div.appendChild(span);
  1386. return;
  1387. }
  1388. div.appendChild(node);
  1389. }
  1390. let i0 = selectedMatchIdx,
  1391. i1 = i0 + 1;
  1392. if (highlightAll) {
  1393. i0 = 0;
  1394. i1 = matches.length;
  1395. } else if (!isSelectedPage) {
  1396. return;
  1397. }
  1398. for (let i = i0; i < i1; i++) {
  1399. const match = matches[i];
  1400. const begin = match.begin;
  1401. const end = match.end;
  1402. const isSelected = isSelectedPage && i === selectedMatchIdx;
  1403. const highlightSuffix = isSelected ? " selected" : "";
  1404. if (isSelected) {
  1405. findController.scrollMatchIntoView({
  1406. element: textDivs[begin.divIdx],
  1407. pageIndex: pageIdx,
  1408. matchIndex: selectedMatchIdx
  1409. });
  1410. }
  1411. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  1412. if (prevEnd !== null) {
  1413. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  1414. }
  1415. beginText(begin);
  1416. } else {
  1417. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  1418. }
  1419. if (begin.divIdx === end.divIdx) {
  1420. appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  1421. } else {
  1422. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  1423. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  1424. textDivs[n0].className = "highlight middle" + highlightSuffix;
  1425. }
  1426. beginText(end, "highlight end" + highlightSuffix);
  1427. }
  1428. prevEnd = end;
  1429. }
  1430. if (prevEnd) {
  1431. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  1432. }
  1433. }
  1434. _updateMatches() {
  1435. if (!this.renderingDone) {
  1436. return;
  1437. }
  1438. const {
  1439. findController,
  1440. matches,
  1441. pageIdx,
  1442. textContentItemsStr,
  1443. textDivs
  1444. } = this;
  1445. let clearedUntilDivIdx = -1;
  1446. for (let i = 0, ii = matches.length; i < ii; i++) {
  1447. const match = matches[i];
  1448. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  1449. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  1450. const div = textDivs[n];
  1451. div.textContent = textContentItemsStr[n];
  1452. div.className = "";
  1453. }
  1454. clearedUntilDivIdx = match.end.divIdx + 1;
  1455. }
  1456. if (!findController?.highlightMatches) {
  1457. return;
  1458. }
  1459. const pageMatches = findController.pageMatches[pageIdx] || null;
  1460. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  1461. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  1462. this._renderMatches(this.matches);
  1463. }
  1464. _bindMouse() {
  1465. const div = this.textLayerDiv;
  1466. let expandDivsTimer = null;
  1467. div.addEventListener("mousedown", evt => {
  1468. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  1469. this.textLayerRenderTask.expandTextDivs(true);
  1470. if (expandDivsTimer) {
  1471. clearTimeout(expandDivsTimer);
  1472. expandDivsTimer = null;
  1473. }
  1474. return;
  1475. }
  1476. const end = div.querySelector(".endOfContent");
  1477. if (!end) {
  1478. return;
  1479. }
  1480. let adjustTop = evt.target !== div;
  1481. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  1482. if (adjustTop) {
  1483. const divBounds = div.getBoundingClientRect();
  1484. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  1485. end.style.top = (r * 100).toFixed(2) + "%";
  1486. }
  1487. end.classList.add("active");
  1488. });
  1489. div.addEventListener("mouseup", () => {
  1490. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  1491. expandDivsTimer = setTimeout(() => {
  1492. if (this.textLayerRenderTask) {
  1493. this.textLayerRenderTask.expandTextDivs(false);
  1494. }
  1495. expandDivsTimer = null;
  1496. }, EXPAND_DIVS_TIMEOUT);
  1497. return;
  1498. }
  1499. const end = div.querySelector(".endOfContent");
  1500. if (!end) {
  1501. return;
  1502. }
  1503. end.style.top = "";
  1504. end.classList.remove("active");
  1505. });
  1506. }
  1507. }
  1508. exports.TextLayerBuilder = TextLayerBuilder;
  1509. class DefaultTextLayerFactory {
  1510. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  1511. return new TextLayerBuilder({
  1512. textLayerDiv,
  1513. pageIndex,
  1514. viewport,
  1515. enhanceTextSelection,
  1516. eventBus
  1517. });
  1518. }
  1519. }
  1520. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  1521. /***/ }),
  1522. /* 7 */
  1523. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1524. Object.defineProperty(exports, "__esModule", ({
  1525. value: true
  1526. }));
  1527. exports.DownloadManager = void 0;
  1528. var _pdfjsLib = __w_pdfjs_require__(2);
  1529. var _viewer_compatibility = __w_pdfjs_require__(8);
  1530. ;
  1531. function download(blobUrl, filename) {
  1532. const a = document.createElement("a");
  1533. if (!a.click) {
  1534. throw new Error('DownloadManager: "a.click()" is not supported.');
  1535. }
  1536. a.href = blobUrl;
  1537. a.target = "_parent";
  1538. if ("download" in a) {
  1539. a.download = filename;
  1540. }
  1541. (document.body || document.documentElement).appendChild(a);
  1542. a.click();
  1543. a.remove();
  1544. }
  1545. class DownloadManager {
  1546. constructor() {
  1547. this._openBlobUrls = new WeakMap();
  1548. }
  1549. downloadUrl(url, filename) {
  1550. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  1551. return;
  1552. }
  1553. download(url + "#pdfjs.action=download", filename);
  1554. }
  1555. downloadData(data, filename, contentType) {
  1556. const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  1557. download(blobUrl, filename);
  1558. }
  1559. openOrDownloadData(element, data, filename) {
  1560. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  1561. const contentType = isPdfData ? "application/pdf" : "";
  1562. if (isPdfData && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  1563. let blobUrl = this._openBlobUrls.get(element);
  1564. if (!blobUrl) {
  1565. blobUrl = URL.createObjectURL(new Blob([data], {
  1566. type: contentType
  1567. }));
  1568. this._openBlobUrls.set(element, blobUrl);
  1569. }
  1570. let viewerUrl;
  1571. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  1572. try {
  1573. window.open(viewerUrl);
  1574. return true;
  1575. } catch (ex) {
  1576. console.error(`openOrDownloadData: ${ex}`);
  1577. URL.revokeObjectURL(blobUrl);
  1578. this._openBlobUrls.delete(element);
  1579. }
  1580. }
  1581. this.downloadData(data, filename, contentType);
  1582. return false;
  1583. }
  1584. download(blob, url, filename, sourceEventType = "download") {
  1585. if (_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  1586. this.downloadUrl(url, filename);
  1587. return;
  1588. }
  1589. const blobUrl = URL.createObjectURL(blob);
  1590. download(blobUrl, filename);
  1591. }
  1592. }
  1593. exports.DownloadManager = DownloadManager;
  1594. /***/ }),
  1595. /* 8 */
  1596. /***/ ((__unused_webpack_module, exports) => {
  1597. Object.defineProperty(exports, "__esModule", ({
  1598. value: true
  1599. }));
  1600. exports.viewerCompatibilityParams = void 0;
  1601. const compatibilityParams = Object.create(null);
  1602. {
  1603. const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
  1604. const platform = typeof navigator !== "undefined" && navigator.platform || "";
  1605. const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
  1606. const isAndroid = /Android/.test(userAgent);
  1607. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  1608. const isIOSChrome = /CriOS/.test(userAgent);
  1609. (function checkOnBlobSupport() {
  1610. if (isIOSChrome) {
  1611. compatibilityParams.disableCreateObjectURL = true;
  1612. }
  1613. })();
  1614. (function checkCanvasSizeLimitation() {
  1615. if (isIOS || isAndroid) {
  1616. compatibilityParams.maxCanvasPixels = 5242880;
  1617. }
  1618. })();
  1619. }
  1620. const viewerCompatibilityParams = Object.freeze(compatibilityParams);
  1621. exports.viewerCompatibilityParams = viewerCompatibilityParams;
  1622. /***/ }),
  1623. /* 9 */
  1624. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  1625. Object.defineProperty(exports, "__esModule", ({
  1626. value: true
  1627. }));
  1628. exports.GenericL10n = void 0;
  1629. __w_pdfjs_require__(10);
  1630. var _l10n_utils = __w_pdfjs_require__(3);
  1631. const webL10n = document.webL10n;
  1632. class GenericL10n {
  1633. constructor(lang) {
  1634. this._lang = lang;
  1635. this._ready = new Promise((resolve, reject) => {
  1636. webL10n.setLanguage(lang, () => {
  1637. resolve(webL10n);
  1638. });
  1639. });
  1640. }
  1641. async getLanguage() {
  1642. const l10n = await this._ready;
  1643. return l10n.getLanguage();
  1644. }
  1645. async getDirection() {
  1646. const l10n = await this._ready;
  1647. return l10n.getDirection();
  1648. }
  1649. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  1650. const l10n = await this._ready;
  1651. return l10n.get(key, args, fallback);
  1652. }
  1653. async translate(element) {
  1654. const l10n = await this._ready;
  1655. return l10n.translate(element);
  1656. }
  1657. }
  1658. exports.GenericL10n = GenericL10n;
  1659. /***/ }),
  1660. /* 10 */
  1661. /***/ (() => {
  1662. document.webL10n = function (window, document, undefined) {
  1663. var gL10nData = {};
  1664. var gTextData = '';
  1665. var gTextProp = 'textContent';
  1666. var gLanguage = '';
  1667. var gMacros = {};
  1668. var gReadyState = 'loading';
  1669. var gAsyncResourceLoading = true;
  1670. function getL10nResourceLinks() {
  1671. return document.querySelectorAll('link[type="application/l10n"]');
  1672. }
  1673. function getL10nDictionary() {
  1674. var script = document.querySelector('script[type="application/l10n"]');
  1675. return script ? JSON.parse(script.innerHTML) : null;
  1676. }
  1677. function getTranslatableChildren(element) {
  1678. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  1679. }
  1680. function getL10nAttributes(element) {
  1681. if (!element) return {};
  1682. var l10nId = element.getAttribute('data-l10n-id');
  1683. var l10nArgs = element.getAttribute('data-l10n-args');
  1684. var args = {};
  1685. if (l10nArgs) {
  1686. try {
  1687. args = JSON.parse(l10nArgs);
  1688. } catch (e) {
  1689. console.warn('could not parse arguments for #' + l10nId);
  1690. }
  1691. }
  1692. return {
  1693. id: l10nId,
  1694. args: args
  1695. };
  1696. }
  1697. function xhrLoadText(url, onSuccess, onFailure) {
  1698. onSuccess = onSuccess || function _onSuccess(data) {};
  1699. onFailure = onFailure || function _onFailure() {};
  1700. var xhr = new XMLHttpRequest();
  1701. xhr.open('GET', url, gAsyncResourceLoading);
  1702. if (xhr.overrideMimeType) {
  1703. xhr.overrideMimeType('text/plain; charset=utf-8');
  1704. }
  1705. xhr.onreadystatechange = function () {
  1706. if (xhr.readyState == 4) {
  1707. if (xhr.status == 200 || xhr.status === 0) {
  1708. onSuccess(xhr.responseText);
  1709. } else {
  1710. onFailure();
  1711. }
  1712. }
  1713. };
  1714. xhr.onerror = onFailure;
  1715. xhr.ontimeout = onFailure;
  1716. try {
  1717. xhr.send(null);
  1718. } catch (e) {
  1719. onFailure();
  1720. }
  1721. }
  1722. function parseResource(href, lang, successCallback, failureCallback) {
  1723. var baseURL = href.replace(/[^\/]*$/, '') || './';
  1724. function evalString(text) {
  1725. if (text.lastIndexOf('\\') < 0) return text;
  1726. 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, "'");
  1727. }
  1728. function parseProperties(text, parsedPropertiesCallback) {
  1729. var dictionary = {};
  1730. var reBlank = /^\s*|\s*$/;
  1731. var reComment = /^\s*#|^\s*$/;
  1732. var reSection = /^\s*\[(.*)\]\s*$/;
  1733. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  1734. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  1735. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  1736. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  1737. var currentLang = '*';
  1738. var genericLang = lang.split('-', 1)[0];
  1739. var skipLang = false;
  1740. var match = '';
  1741. function nextEntry() {
  1742. while (true) {
  1743. if (!entries.length) {
  1744. parsedRawLinesCallback();
  1745. return;
  1746. }
  1747. var line = entries.shift();
  1748. if (reComment.test(line)) continue;
  1749. if (extendedSyntax) {
  1750. match = reSection.exec(line);
  1751. if (match) {
  1752. currentLang = match[1].toLowerCase();
  1753. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  1754. continue;
  1755. } else if (skipLang) {
  1756. continue;
  1757. }
  1758. match = reImport.exec(line);
  1759. if (match) {
  1760. loadImport(baseURL + match[1], nextEntry);
  1761. return;
  1762. }
  1763. }
  1764. var tmp = line.match(reSplit);
  1765. if (tmp && tmp.length == 3) {
  1766. dictionary[tmp[1]] = evalString(tmp[2]);
  1767. }
  1768. }
  1769. }
  1770. nextEntry();
  1771. }
  1772. function loadImport(url, callback) {
  1773. xhrLoadText(url, function (content) {
  1774. parseRawLines(content, false, callback);
  1775. }, function () {
  1776. console.warn(url + ' not found.');
  1777. callback();
  1778. });
  1779. }
  1780. parseRawLines(text, true, function () {
  1781. parsedPropertiesCallback(dictionary);
  1782. });
  1783. }
  1784. xhrLoadText(href, function (response) {
  1785. gTextData += response;
  1786. parseProperties(response, function (data) {
  1787. for (var key in data) {
  1788. var id,
  1789. prop,
  1790. index = key.lastIndexOf('.');
  1791. if (index > 0) {
  1792. id = key.substring(0, index);
  1793. prop = key.substring(index + 1);
  1794. } else {
  1795. id = key;
  1796. prop = gTextProp;
  1797. }
  1798. if (!gL10nData[id]) {
  1799. gL10nData[id] = {};
  1800. }
  1801. gL10nData[id][prop] = data[key];
  1802. }
  1803. if (successCallback) {
  1804. successCallback();
  1805. }
  1806. });
  1807. }, failureCallback);
  1808. }
  1809. function loadLocale(lang, callback) {
  1810. if (lang) {
  1811. lang = lang.toLowerCase();
  1812. }
  1813. callback = callback || function _callback() {};
  1814. clear();
  1815. gLanguage = lang;
  1816. var langLinks = getL10nResourceLinks();
  1817. var langCount = langLinks.length;
  1818. if (langCount === 0) {
  1819. var dict = getL10nDictionary();
  1820. if (dict && dict.locales && dict.default_locale) {
  1821. console.log('using the embedded JSON directory, early way out');
  1822. gL10nData = dict.locales[lang];
  1823. if (!gL10nData) {
  1824. var defaultLocale = dict.default_locale.toLowerCase();
  1825. for (var anyCaseLang in dict.locales) {
  1826. anyCaseLang = anyCaseLang.toLowerCase();
  1827. if (anyCaseLang === lang) {
  1828. gL10nData = dict.locales[lang];
  1829. break;
  1830. } else if (anyCaseLang === defaultLocale) {
  1831. gL10nData = dict.locales[defaultLocale];
  1832. }
  1833. }
  1834. }
  1835. callback();
  1836. } else {
  1837. console.log('no resource to load, early way out');
  1838. }
  1839. gReadyState = 'complete';
  1840. return;
  1841. }
  1842. var onResourceLoaded = null;
  1843. var gResourceCount = 0;
  1844. onResourceLoaded = function () {
  1845. gResourceCount++;
  1846. if (gResourceCount >= langCount) {
  1847. callback();
  1848. gReadyState = 'complete';
  1849. }
  1850. };
  1851. function L10nResourceLink(link) {
  1852. var href = link.href;
  1853. this.load = function (lang, callback) {
  1854. parseResource(href, lang, callback, function () {
  1855. console.warn(href + ' not found.');
  1856. console.warn('"' + lang + '" resource not found');
  1857. gLanguage = '';
  1858. callback();
  1859. });
  1860. };
  1861. }
  1862. for (var i = 0; i < langCount; i++) {
  1863. var resource = new L10nResourceLink(langLinks[i]);
  1864. resource.load(lang, onResourceLoaded);
  1865. }
  1866. }
  1867. function clear() {
  1868. gL10nData = {};
  1869. gTextData = '';
  1870. gLanguage = '';
  1871. }
  1872. function getPluralRules(lang) {
  1873. var locales2rules = {
  1874. 'af': 3,
  1875. 'ak': 4,
  1876. 'am': 4,
  1877. 'ar': 1,
  1878. 'asa': 3,
  1879. 'az': 0,
  1880. 'be': 11,
  1881. 'bem': 3,
  1882. 'bez': 3,
  1883. 'bg': 3,
  1884. 'bh': 4,
  1885. 'bm': 0,
  1886. 'bn': 3,
  1887. 'bo': 0,
  1888. 'br': 20,
  1889. 'brx': 3,
  1890. 'bs': 11,
  1891. 'ca': 3,
  1892. 'cgg': 3,
  1893. 'chr': 3,
  1894. 'cs': 12,
  1895. 'cy': 17,
  1896. 'da': 3,
  1897. 'de': 3,
  1898. 'dv': 3,
  1899. 'dz': 0,
  1900. 'ee': 3,
  1901. 'el': 3,
  1902. 'en': 3,
  1903. 'eo': 3,
  1904. 'es': 3,
  1905. 'et': 3,
  1906. 'eu': 3,
  1907. 'fa': 0,
  1908. 'ff': 5,
  1909. 'fi': 3,
  1910. 'fil': 4,
  1911. 'fo': 3,
  1912. 'fr': 5,
  1913. 'fur': 3,
  1914. 'fy': 3,
  1915. 'ga': 8,
  1916. 'gd': 24,
  1917. 'gl': 3,
  1918. 'gsw': 3,
  1919. 'gu': 3,
  1920. 'guw': 4,
  1921. 'gv': 23,
  1922. 'ha': 3,
  1923. 'haw': 3,
  1924. 'he': 2,
  1925. 'hi': 4,
  1926. 'hr': 11,
  1927. 'hu': 0,
  1928. 'id': 0,
  1929. 'ig': 0,
  1930. 'ii': 0,
  1931. 'is': 3,
  1932. 'it': 3,
  1933. 'iu': 7,
  1934. 'ja': 0,
  1935. 'jmc': 3,
  1936. 'jv': 0,
  1937. 'ka': 0,
  1938. 'kab': 5,
  1939. 'kaj': 3,
  1940. 'kcg': 3,
  1941. 'kde': 0,
  1942. 'kea': 0,
  1943. 'kk': 3,
  1944. 'kl': 3,
  1945. 'km': 0,
  1946. 'kn': 0,
  1947. 'ko': 0,
  1948. 'ksb': 3,
  1949. 'ksh': 21,
  1950. 'ku': 3,
  1951. 'kw': 7,
  1952. 'lag': 18,
  1953. 'lb': 3,
  1954. 'lg': 3,
  1955. 'ln': 4,
  1956. 'lo': 0,
  1957. 'lt': 10,
  1958. 'lv': 6,
  1959. 'mas': 3,
  1960. 'mg': 4,
  1961. 'mk': 16,
  1962. 'ml': 3,
  1963. 'mn': 3,
  1964. 'mo': 9,
  1965. 'mr': 3,
  1966. 'ms': 0,
  1967. 'mt': 15,
  1968. 'my': 0,
  1969. 'nah': 3,
  1970. 'naq': 7,
  1971. 'nb': 3,
  1972. 'nd': 3,
  1973. 'ne': 3,
  1974. 'nl': 3,
  1975. 'nn': 3,
  1976. 'no': 3,
  1977. 'nr': 3,
  1978. 'nso': 4,
  1979. 'ny': 3,
  1980. 'nyn': 3,
  1981. 'om': 3,
  1982. 'or': 3,
  1983. 'pa': 3,
  1984. 'pap': 3,
  1985. 'pl': 13,
  1986. 'ps': 3,
  1987. 'pt': 3,
  1988. 'rm': 3,
  1989. 'ro': 9,
  1990. 'rof': 3,
  1991. 'ru': 11,
  1992. 'rwk': 3,
  1993. 'sah': 0,
  1994. 'saq': 3,
  1995. 'se': 7,
  1996. 'seh': 3,
  1997. 'ses': 0,
  1998. 'sg': 0,
  1999. 'sh': 11,
  2000. 'shi': 19,
  2001. 'sk': 12,
  2002. 'sl': 14,
  2003. 'sma': 7,
  2004. 'smi': 7,
  2005. 'smj': 7,
  2006. 'smn': 7,
  2007. 'sms': 7,
  2008. 'sn': 3,
  2009. 'so': 3,
  2010. 'sq': 3,
  2011. 'sr': 11,
  2012. 'ss': 3,
  2013. 'ssy': 3,
  2014. 'st': 3,
  2015. 'sv': 3,
  2016. 'sw': 3,
  2017. 'syr': 3,
  2018. 'ta': 3,
  2019. 'te': 3,
  2020. 'teo': 3,
  2021. 'th': 0,
  2022. 'ti': 4,
  2023. 'tig': 3,
  2024. 'tk': 3,
  2025. 'tl': 4,
  2026. 'tn': 3,
  2027. 'to': 0,
  2028. 'tr': 0,
  2029. 'ts': 3,
  2030. 'tzm': 22,
  2031. 'uk': 11,
  2032. 'ur': 3,
  2033. 've': 3,
  2034. 'vi': 0,
  2035. 'vun': 3,
  2036. 'wa': 4,
  2037. 'wae': 3,
  2038. 'wo': 0,
  2039. 'xh': 3,
  2040. 'xog': 3,
  2041. 'yo': 0,
  2042. 'zh': 0,
  2043. 'zu': 3
  2044. };
  2045. function isIn(n, list) {
  2046. return list.indexOf(n) !== -1;
  2047. }
  2048. function isBetween(n, start, end) {
  2049. return start <= n && n <= end;
  2050. }
  2051. var pluralRules = {
  2052. '0': function (n) {
  2053. return 'other';
  2054. },
  2055. '1': function (n) {
  2056. if (isBetween(n % 100, 3, 10)) return 'few';
  2057. if (n === 0) return 'zero';
  2058. if (isBetween(n % 100, 11, 99)) return 'many';
  2059. if (n == 2) return 'two';
  2060. if (n == 1) return 'one';
  2061. return 'other';
  2062. },
  2063. '2': function (n) {
  2064. if (n !== 0 && n % 10 === 0) return 'many';
  2065. if (n == 2) return 'two';
  2066. if (n == 1) return 'one';
  2067. return 'other';
  2068. },
  2069. '3': function (n) {
  2070. if (n == 1) return 'one';
  2071. return 'other';
  2072. },
  2073. '4': function (n) {
  2074. if (isBetween(n, 0, 1)) return 'one';
  2075. return 'other';
  2076. },
  2077. '5': function (n) {
  2078. if (isBetween(n, 0, 2) && n != 2) return 'one';
  2079. return 'other';
  2080. },
  2081. '6': function (n) {
  2082. if (n === 0) return 'zero';
  2083. if (n % 10 == 1 && n % 100 != 11) return 'one';
  2084. return 'other';
  2085. },
  2086. '7': function (n) {
  2087. if (n == 2) return 'two';
  2088. if (n == 1) return 'one';
  2089. return 'other';
  2090. },
  2091. '8': function (n) {
  2092. if (isBetween(n, 3, 6)) return 'few';
  2093. if (isBetween(n, 7, 10)) return 'many';
  2094. if (n == 2) return 'two';
  2095. if (n == 1) return 'one';
  2096. return 'other';
  2097. },
  2098. '9': function (n) {
  2099. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  2100. if (n == 1) return 'one';
  2101. return 'other';
  2102. },
  2103. '10': function (n) {
  2104. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  2105. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  2106. return 'other';
  2107. },
  2108. '11': function (n) {
  2109. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  2110. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  2111. if (n % 10 == 1 && n % 100 != 11) return 'one';
  2112. return 'other';
  2113. },
  2114. '12': function (n) {
  2115. if (isBetween(n, 2, 4)) return 'few';
  2116. if (n == 1) return 'one';
  2117. return 'other';
  2118. },
  2119. '13': function (n) {
  2120. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  2121. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  2122. if (n == 1) return 'one';
  2123. return 'other';
  2124. },
  2125. '14': function (n) {
  2126. if (isBetween(n % 100, 3, 4)) return 'few';
  2127. if (n % 100 == 2) return 'two';
  2128. if (n % 100 == 1) return 'one';
  2129. return 'other';
  2130. },
  2131. '15': function (n) {
  2132. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  2133. if (isBetween(n % 100, 11, 19)) return 'many';
  2134. if (n == 1) return 'one';
  2135. return 'other';
  2136. },
  2137. '16': function (n) {
  2138. if (n % 10 == 1 && n != 11) return 'one';
  2139. return 'other';
  2140. },
  2141. '17': function (n) {
  2142. if (n == 3) return 'few';
  2143. if (n === 0) return 'zero';
  2144. if (n == 6) return 'many';
  2145. if (n == 2) return 'two';
  2146. if (n == 1) return 'one';
  2147. return 'other';
  2148. },
  2149. '18': function (n) {
  2150. if (n === 0) return 'zero';
  2151. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  2152. return 'other';
  2153. },
  2154. '19': function (n) {
  2155. if (isBetween(n, 2, 10)) return 'few';
  2156. if (isBetween(n, 0, 1)) return 'one';
  2157. return 'other';
  2158. },
  2159. '20': function (n) {
  2160. 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';
  2161. if (n % 1000000 === 0 && n !== 0) return 'many';
  2162. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  2163. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  2164. return 'other';
  2165. },
  2166. '21': function (n) {
  2167. if (n === 0) return 'zero';
  2168. if (n == 1) return 'one';
  2169. return 'other';
  2170. },
  2171. '22': function (n) {
  2172. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  2173. return 'other';
  2174. },
  2175. '23': function (n) {
  2176. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  2177. return 'other';
  2178. },
  2179. '24': function (n) {
  2180. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  2181. if (isIn(n, [2, 12])) return 'two';
  2182. if (isIn(n, [1, 11])) return 'one';
  2183. return 'other';
  2184. }
  2185. };
  2186. var index = locales2rules[lang.replace(/-.*$/, '')];
  2187. if (!(index in pluralRules)) {
  2188. console.warn('plural form unknown for [' + lang + ']');
  2189. return function () {
  2190. return 'other';
  2191. };
  2192. }
  2193. return pluralRules[index];
  2194. }
  2195. gMacros.plural = function (str, param, key, prop) {
  2196. var n = parseFloat(param);
  2197. if (isNaN(n)) return str;
  2198. if (prop != gTextProp) return str;
  2199. if (!gMacros._pluralRules) {
  2200. gMacros._pluralRules = getPluralRules(gLanguage);
  2201. }
  2202. var index = '[' + gMacros._pluralRules(n) + ']';
  2203. if (n === 0 && key + '[zero]' in gL10nData) {
  2204. str = gL10nData[key + '[zero]'][prop];
  2205. } else if (n == 1 && key + '[one]' in gL10nData) {
  2206. str = gL10nData[key + '[one]'][prop];
  2207. } else if (n == 2 && key + '[two]' in gL10nData) {
  2208. str = gL10nData[key + '[two]'][prop];
  2209. } else if (key + index in gL10nData) {
  2210. str = gL10nData[key + index][prop];
  2211. } else if (key + '[other]' in gL10nData) {
  2212. str = gL10nData[key + '[other]'][prop];
  2213. }
  2214. return str;
  2215. };
  2216. function getL10nData(key, args, fallback) {
  2217. var data = gL10nData[key];
  2218. if (!data) {
  2219. console.warn('#' + key + ' is undefined.');
  2220. if (!fallback) {
  2221. return null;
  2222. }
  2223. data = fallback;
  2224. }
  2225. var rv = {};
  2226. for (var prop in data) {
  2227. var str = data[prop];
  2228. str = substIndexes(str, args, key, prop);
  2229. str = substArguments(str, args, key);
  2230. rv[prop] = str;
  2231. }
  2232. return rv;
  2233. }
  2234. function substIndexes(str, args, key, prop) {
  2235. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  2236. var reMatch = reIndex.exec(str);
  2237. if (!reMatch || !reMatch.length) return str;
  2238. var macroName = reMatch[1];
  2239. var paramName = reMatch[2];
  2240. var param;
  2241. if (args && paramName in args) {
  2242. param = args[paramName];
  2243. } else if (paramName in gL10nData) {
  2244. param = gL10nData[paramName];
  2245. }
  2246. if (macroName in gMacros) {
  2247. var macro = gMacros[macroName];
  2248. str = macro(str, param, key, prop);
  2249. }
  2250. return str;
  2251. }
  2252. function substArguments(str, args, key) {
  2253. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  2254. return str.replace(reArgs, function (matched_text, arg) {
  2255. if (args && arg in args) {
  2256. return args[arg];
  2257. }
  2258. if (arg in gL10nData) {
  2259. return gL10nData[arg];
  2260. }
  2261. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  2262. return matched_text;
  2263. });
  2264. }
  2265. function translateElement(element) {
  2266. var l10n = getL10nAttributes(element);
  2267. if (!l10n.id) return;
  2268. var data = getL10nData(l10n.id, l10n.args);
  2269. if (!data) {
  2270. console.warn('#' + l10n.id + ' is undefined.');
  2271. return;
  2272. }
  2273. if (data[gTextProp]) {
  2274. if (getChildElementCount(element) === 0) {
  2275. element[gTextProp] = data[gTextProp];
  2276. } else {
  2277. var children = element.childNodes;
  2278. var found = false;
  2279. for (var i = 0, l = children.length; i < l; i++) {
  2280. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  2281. if (found) {
  2282. children[i].nodeValue = '';
  2283. } else {
  2284. children[i].nodeValue = data[gTextProp];
  2285. found = true;
  2286. }
  2287. }
  2288. }
  2289. if (!found) {
  2290. var textNode = document.createTextNode(data[gTextProp]);
  2291. element.insertBefore(textNode, element.firstChild);
  2292. }
  2293. }
  2294. delete data[gTextProp];
  2295. }
  2296. for (var k in data) {
  2297. element[k] = data[k];
  2298. }
  2299. }
  2300. function getChildElementCount(element) {
  2301. if (element.children) {
  2302. return element.children.length;
  2303. }
  2304. if (typeof element.childElementCount !== 'undefined') {
  2305. return element.childElementCount;
  2306. }
  2307. var count = 0;
  2308. for (var i = 0; i < element.childNodes.length; i++) {
  2309. count += element.nodeType === 1 ? 1 : 0;
  2310. }
  2311. return count;
  2312. }
  2313. function translateFragment(element) {
  2314. element = element || document.documentElement;
  2315. var children = getTranslatableChildren(element);
  2316. var elementCount = children.length;
  2317. for (var i = 0; i < elementCount; i++) {
  2318. translateElement(children[i]);
  2319. }
  2320. translateElement(element);
  2321. }
  2322. return {
  2323. get: function (key, args, fallbackString) {
  2324. var index = key.lastIndexOf('.');
  2325. var prop = gTextProp;
  2326. if (index > 0) {
  2327. prop = key.substring(index + 1);
  2328. key = key.substring(0, index);
  2329. }
  2330. var fallback;
  2331. if (fallbackString) {
  2332. fallback = {};
  2333. fallback[prop] = fallbackString;
  2334. }
  2335. var data = getL10nData(key, args, fallback);
  2336. if (data && prop in data) {
  2337. return data[prop];
  2338. }
  2339. return '{{' + key + '}}';
  2340. },
  2341. getData: function () {
  2342. return gL10nData;
  2343. },
  2344. getText: function () {
  2345. return gTextData;
  2346. },
  2347. getLanguage: function () {
  2348. return gLanguage;
  2349. },
  2350. setLanguage: function (lang, callback) {
  2351. loadLocale(lang, function () {
  2352. if (callback) callback();
  2353. });
  2354. },
  2355. getDirection: function () {
  2356. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  2357. var shortCode = gLanguage.split('-', 1)[0];
  2358. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  2359. },
  2360. translate: translateFragment,
  2361. getReadyState: function () {
  2362. return gReadyState;
  2363. },
  2364. ready: function (callback) {
  2365. if (!callback) {
  2366. return;
  2367. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  2368. window.setTimeout(function () {
  2369. callback();
  2370. });
  2371. } else if (document.addEventListener) {
  2372. document.addEventListener('localized', function once() {
  2373. document.removeEventListener('localized', once);
  2374. callback();
  2375. });
  2376. }
  2377. }
  2378. };
  2379. }(window, document);
  2380. /***/ }),
  2381. /* 11 */
  2382. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  2383. Object.defineProperty(exports, "__esModule", ({
  2384. value: true
  2385. }));
  2386. exports.PDFFindController = exports.FindState = void 0;
  2387. var _pdfjsLib = __w_pdfjs_require__(2);
  2388. var _pdf_find_utils = __w_pdfjs_require__(12);
  2389. var _ui_utils = __w_pdfjs_require__(5);
  2390. const FindState = {
  2391. FOUND: 0,
  2392. NOT_FOUND: 1,
  2393. WRAPPED: 2,
  2394. PENDING: 3
  2395. };
  2396. exports.FindState = FindState;
  2397. const FIND_TIMEOUT = 250;
  2398. const MATCH_SCROLL_OFFSET_TOP = -50;
  2399. const MATCH_SCROLL_OFFSET_LEFT = -400;
  2400. const CHARACTERS_TO_NORMALIZE = {
  2401. "\u2018": "'",
  2402. "\u2019": "'",
  2403. "\u201A": "'",
  2404. "\u201B": "'",
  2405. "\u201C": '"',
  2406. "\u201D": '"',
  2407. "\u201E": '"',
  2408. "\u201F": '"',
  2409. "\u00BC": "1/4",
  2410. "\u00BD": "1/2",
  2411. "\u00BE": "3/4"
  2412. };
  2413. let normalizationRegex = null;
  2414. function normalize(text) {
  2415. if (!normalizationRegex) {
  2416. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  2417. normalizationRegex = new RegExp(`[${replace}]`, "g");
  2418. }
  2419. let diffs = null;
  2420. const normalizedText = text.replace(normalizationRegex, function (ch, index) {
  2421. const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
  2422. diff = normalizedCh.length - ch.length;
  2423. if (diff !== 0) {
  2424. (diffs || (diffs = [])).push([index, diff]);
  2425. }
  2426. return normalizedCh;
  2427. });
  2428. return [normalizedText, diffs];
  2429. }
  2430. function getOriginalIndex(matchIndex, diffs = null) {
  2431. if (!diffs) {
  2432. return matchIndex;
  2433. }
  2434. let totalDiff = 0;
  2435. for (const [index, diff] of diffs) {
  2436. const currentIndex = index + totalDiff;
  2437. if (currentIndex >= matchIndex) {
  2438. break;
  2439. }
  2440. if (currentIndex + diff > matchIndex) {
  2441. totalDiff += matchIndex - currentIndex;
  2442. break;
  2443. }
  2444. totalDiff += diff;
  2445. }
  2446. return matchIndex - totalDiff;
  2447. }
  2448. class PDFFindController {
  2449. constructor({
  2450. linkService,
  2451. eventBus
  2452. }) {
  2453. this._linkService = linkService;
  2454. this._eventBus = eventBus;
  2455. this._reset();
  2456. eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  2457. }
  2458. get highlightMatches() {
  2459. return this._highlightMatches;
  2460. }
  2461. get pageMatches() {
  2462. return this._pageMatches;
  2463. }
  2464. get pageMatchesLength() {
  2465. return this._pageMatchesLength;
  2466. }
  2467. get selected() {
  2468. return this._selected;
  2469. }
  2470. get state() {
  2471. return this._state;
  2472. }
  2473. setDocument(pdfDocument) {
  2474. if (this._pdfDocument) {
  2475. this._reset();
  2476. }
  2477. if (!pdfDocument) {
  2478. return;
  2479. }
  2480. this._pdfDocument = pdfDocument;
  2481. this._firstPageCapability.resolve();
  2482. }
  2483. executeCommand(cmd, state) {
  2484. if (!state) {
  2485. return;
  2486. }
  2487. const pdfDocument = this._pdfDocument;
  2488. if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
  2489. this._dirtyMatch = true;
  2490. }
  2491. this._state = state;
  2492. if (cmd !== "findhighlightallchange") {
  2493. this._updateUIState(FindState.PENDING);
  2494. }
  2495. this._firstPageCapability.promise.then(() => {
  2496. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  2497. return;
  2498. }
  2499. this._extractText();
  2500. const findbarClosed = !this._highlightMatches;
  2501. const pendingTimeout = !!this._findTimeout;
  2502. if (this._findTimeout) {
  2503. clearTimeout(this._findTimeout);
  2504. this._findTimeout = null;
  2505. }
  2506. if (cmd === "find") {
  2507. this._findTimeout = setTimeout(() => {
  2508. this._nextMatch();
  2509. this._findTimeout = null;
  2510. }, FIND_TIMEOUT);
  2511. } else if (this._dirtyMatch) {
  2512. this._nextMatch();
  2513. } else if (cmd === "findagain") {
  2514. this._nextMatch();
  2515. if (findbarClosed && this._state.highlightAll) {
  2516. this._updateAllPages();
  2517. }
  2518. } else if (cmd === "findhighlightallchange") {
  2519. if (pendingTimeout) {
  2520. this._nextMatch();
  2521. } else {
  2522. this._highlightMatches = true;
  2523. }
  2524. this._updateAllPages();
  2525. } else {
  2526. this._nextMatch();
  2527. }
  2528. });
  2529. }
  2530. scrollMatchIntoView({
  2531. element = null,
  2532. pageIndex = -1,
  2533. matchIndex = -1
  2534. }) {
  2535. if (!this._scrollMatches || !element) {
  2536. return;
  2537. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  2538. return;
  2539. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  2540. return;
  2541. }
  2542. this._scrollMatches = false;
  2543. const spot = {
  2544. top: MATCH_SCROLL_OFFSET_TOP,
  2545. left: MATCH_SCROLL_OFFSET_LEFT
  2546. };
  2547. (0, _ui_utils.scrollIntoView)(element, spot, true);
  2548. }
  2549. _reset() {
  2550. this._highlightMatches = false;
  2551. this._scrollMatches = false;
  2552. this._pdfDocument = null;
  2553. this._pageMatches = [];
  2554. this._pageMatchesLength = [];
  2555. this._state = null;
  2556. this._selected = {
  2557. pageIdx: -1,
  2558. matchIdx: -1
  2559. };
  2560. this._offset = {
  2561. pageIdx: null,
  2562. matchIdx: null,
  2563. wrapped: false
  2564. };
  2565. this._extractTextPromises = [];
  2566. this._pageContents = [];
  2567. this._pageDiffs = [];
  2568. this._matchesCountTotal = 0;
  2569. this._pagesToSearch = null;
  2570. this._pendingFindMatches = Object.create(null);
  2571. this._resumePageIdx = null;
  2572. this._dirtyMatch = false;
  2573. clearTimeout(this._findTimeout);
  2574. this._findTimeout = null;
  2575. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  2576. }
  2577. get _query() {
  2578. if (this._state.query !== this._rawQuery) {
  2579. this._rawQuery = this._state.query;
  2580. [this._normalizedQuery] = normalize(this._state.query);
  2581. }
  2582. return this._normalizedQuery;
  2583. }
  2584. _shouldDirtyMatch(cmd, state) {
  2585. if (state.query !== this._state.query) {
  2586. return true;
  2587. }
  2588. switch (cmd) {
  2589. case "findagain":
  2590. const pageNumber = this._selected.pageIdx + 1;
  2591. const linkService = this._linkService;
  2592. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  2593. return true;
  2594. }
  2595. return false;
  2596. case "findhighlightallchange":
  2597. return false;
  2598. }
  2599. return true;
  2600. }
  2601. _prepareMatches(matchesWithLength, matches, matchesLength) {
  2602. function isSubTerm(currentIndex) {
  2603. const currentElem = matchesWithLength[currentIndex];
  2604. const nextElem = matchesWithLength[currentIndex + 1];
  2605. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  2606. currentElem.skipped = true;
  2607. return true;
  2608. }
  2609. for (let i = currentIndex - 1; i >= 0; i--) {
  2610. const prevElem = matchesWithLength[i];
  2611. if (prevElem.skipped) {
  2612. continue;
  2613. }
  2614. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  2615. break;
  2616. }
  2617. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  2618. currentElem.skipped = true;
  2619. return true;
  2620. }
  2621. }
  2622. return false;
  2623. }
  2624. matchesWithLength.sort(function (a, b) {
  2625. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  2626. });
  2627. for (let i = 0, len = matchesWithLength.length; i < len; i++) {
  2628. if (isSubTerm(i)) {
  2629. continue;
  2630. }
  2631. matches.push(matchesWithLength[i].match);
  2632. matchesLength.push(matchesWithLength[i].matchLength);
  2633. }
  2634. }
  2635. _isEntireWord(content, startIdx, length) {
  2636. if (startIdx > 0) {
  2637. const first = content.charCodeAt(startIdx);
  2638. const limit = content.charCodeAt(startIdx - 1);
  2639. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  2640. return false;
  2641. }
  2642. }
  2643. const endIdx = startIdx + length - 1;
  2644. if (endIdx < content.length - 1) {
  2645. const last = content.charCodeAt(endIdx);
  2646. const limit = content.charCodeAt(endIdx + 1);
  2647. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  2648. return false;
  2649. }
  2650. }
  2651. return true;
  2652. }
  2653. _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  2654. const matches = [],
  2655. matchesLength = [];
  2656. const queryLen = query.length;
  2657. let matchIdx = -queryLen;
  2658. while (true) {
  2659. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  2660. if (matchIdx === -1) {
  2661. break;
  2662. }
  2663. if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  2664. continue;
  2665. }
  2666. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  2667. matchEnd = matchIdx + queryLen - 1,
  2668. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  2669. matches.push(originalMatchIdx);
  2670. matchesLength.push(originalQueryLen);
  2671. }
  2672. this._pageMatches[pageIndex] = matches;
  2673. this._pageMatchesLength[pageIndex] = matchesLength;
  2674. }
  2675. _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  2676. const matchesWithLength = [];
  2677. const queryArray = query.match(/\S+/g);
  2678. for (let i = 0, len = queryArray.length; i < len; i++) {
  2679. const subquery = queryArray[i];
  2680. const subqueryLen = subquery.length;
  2681. let matchIdx = -subqueryLen;
  2682. while (true) {
  2683. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  2684. if (matchIdx === -1) {
  2685. break;
  2686. }
  2687. if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  2688. continue;
  2689. }
  2690. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  2691. matchEnd = matchIdx + subqueryLen - 1,
  2692. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  2693. matchesWithLength.push({
  2694. match: originalMatchIdx,
  2695. matchLength: originalQueryLen,
  2696. skipped: false
  2697. });
  2698. }
  2699. }
  2700. this._pageMatchesLength[pageIndex] = [];
  2701. this._pageMatches[pageIndex] = [];
  2702. this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  2703. }
  2704. _calculateMatch(pageIndex) {
  2705. let pageContent = this._pageContents[pageIndex];
  2706. const pageDiffs = this._pageDiffs[pageIndex];
  2707. let query = this._query;
  2708. const {
  2709. caseSensitive,
  2710. entireWord,
  2711. phraseSearch
  2712. } = this._state;
  2713. if (query.length === 0) {
  2714. return;
  2715. }
  2716. if (!caseSensitive) {
  2717. pageContent = pageContent.toLowerCase();
  2718. query = query.toLowerCase();
  2719. }
  2720. if (phraseSearch) {
  2721. this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  2722. } else {
  2723. this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  2724. }
  2725. if (this._state.highlightAll) {
  2726. this._updatePage(pageIndex);
  2727. }
  2728. if (this._resumePageIdx === pageIndex) {
  2729. this._resumePageIdx = null;
  2730. this._nextPageMatch();
  2731. }
  2732. const pageMatchesCount = this._pageMatches[pageIndex].length;
  2733. if (pageMatchesCount > 0) {
  2734. this._matchesCountTotal += pageMatchesCount;
  2735. this._updateUIResultsCount();
  2736. }
  2737. }
  2738. _extractText() {
  2739. if (this._extractTextPromises.length > 0) {
  2740. return;
  2741. }
  2742. let promise = Promise.resolve();
  2743. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  2744. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  2745. this._extractTextPromises[i] = extractTextCapability.promise;
  2746. promise = promise.then(() => {
  2747. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  2748. return pdfPage.getTextContent({
  2749. normalizeWhitespace: true
  2750. });
  2751. }).then(textContent => {
  2752. const textItems = textContent.items;
  2753. const strBuf = [];
  2754. for (let j = 0, jj = textItems.length; j < jj; j++) {
  2755. strBuf.push(textItems[j].str);
  2756. }
  2757. [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
  2758. extractTextCapability.resolve(i);
  2759. }, reason => {
  2760. console.error(`Unable to get text content for page ${i + 1}`, reason);
  2761. this._pageContents[i] = "";
  2762. this._pageDiffs[i] = null;
  2763. extractTextCapability.resolve(i);
  2764. });
  2765. });
  2766. }
  2767. }
  2768. _updatePage(index) {
  2769. if (this._scrollMatches && this._selected.pageIdx === index) {
  2770. this._linkService.page = index + 1;
  2771. }
  2772. this._eventBus.dispatch("updatetextlayermatches", {
  2773. source: this,
  2774. pageIndex: index
  2775. });
  2776. }
  2777. _updateAllPages() {
  2778. this._eventBus.dispatch("updatetextlayermatches", {
  2779. source: this,
  2780. pageIndex: -1
  2781. });
  2782. }
  2783. _nextMatch() {
  2784. const previous = this._state.findPrevious;
  2785. const currentPageIndex = this._linkService.page - 1;
  2786. const numPages = this._linkService.pagesCount;
  2787. this._highlightMatches = true;
  2788. if (this._dirtyMatch) {
  2789. this._dirtyMatch = false;
  2790. this._selected.pageIdx = this._selected.matchIdx = -1;
  2791. this._offset.pageIdx = currentPageIndex;
  2792. this._offset.matchIdx = null;
  2793. this._offset.wrapped = false;
  2794. this._resumePageIdx = null;
  2795. this._pageMatches.length = 0;
  2796. this._pageMatchesLength.length = 0;
  2797. this._matchesCountTotal = 0;
  2798. this._updateAllPages();
  2799. for (let i = 0; i < numPages; i++) {
  2800. if (this._pendingFindMatches[i] === true) {
  2801. continue;
  2802. }
  2803. this._pendingFindMatches[i] = true;
  2804. this._extractTextPromises[i].then(pageIdx => {
  2805. delete this._pendingFindMatches[pageIdx];
  2806. this._calculateMatch(pageIdx);
  2807. });
  2808. }
  2809. }
  2810. if (this._query === "") {
  2811. this._updateUIState(FindState.FOUND);
  2812. return;
  2813. }
  2814. if (this._resumePageIdx) {
  2815. return;
  2816. }
  2817. const offset = this._offset;
  2818. this._pagesToSearch = numPages;
  2819. if (offset.matchIdx !== null) {
  2820. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  2821. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  2822. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  2823. this._updateMatch(true);
  2824. return;
  2825. }
  2826. this._advanceOffsetPage(previous);
  2827. }
  2828. this._nextPageMatch();
  2829. }
  2830. _matchesReady(matches) {
  2831. const offset = this._offset;
  2832. const numMatches = matches.length;
  2833. const previous = this._state.findPrevious;
  2834. if (numMatches) {
  2835. offset.matchIdx = previous ? numMatches - 1 : 0;
  2836. this._updateMatch(true);
  2837. return true;
  2838. }
  2839. this._advanceOffsetPage(previous);
  2840. if (offset.wrapped) {
  2841. offset.matchIdx = null;
  2842. if (this._pagesToSearch < 0) {
  2843. this._updateMatch(false);
  2844. return true;
  2845. }
  2846. }
  2847. return false;
  2848. }
  2849. _nextPageMatch() {
  2850. if (this._resumePageIdx !== null) {
  2851. console.error("There can only be one pending page.");
  2852. }
  2853. let matches = null;
  2854. do {
  2855. const pageIdx = this._offset.pageIdx;
  2856. matches = this._pageMatches[pageIdx];
  2857. if (!matches) {
  2858. this._resumePageIdx = pageIdx;
  2859. break;
  2860. }
  2861. } while (!this._matchesReady(matches));
  2862. }
  2863. _advanceOffsetPage(previous) {
  2864. const offset = this._offset;
  2865. const numPages = this._linkService.pagesCount;
  2866. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  2867. offset.matchIdx = null;
  2868. this._pagesToSearch--;
  2869. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  2870. offset.pageIdx = previous ? numPages - 1 : 0;
  2871. offset.wrapped = true;
  2872. }
  2873. }
  2874. _updateMatch(found = false) {
  2875. let state = FindState.NOT_FOUND;
  2876. const wrapped = this._offset.wrapped;
  2877. this._offset.wrapped = false;
  2878. if (found) {
  2879. const previousPage = this._selected.pageIdx;
  2880. this._selected.pageIdx = this._offset.pageIdx;
  2881. this._selected.matchIdx = this._offset.matchIdx;
  2882. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  2883. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  2884. this._updatePage(previousPage);
  2885. }
  2886. }
  2887. this._updateUIState(state, this._state.findPrevious);
  2888. if (this._selected.pageIdx !== -1) {
  2889. this._scrollMatches = true;
  2890. this._updatePage(this._selected.pageIdx);
  2891. }
  2892. }
  2893. _onFindBarClose(evt) {
  2894. const pdfDocument = this._pdfDocument;
  2895. this._firstPageCapability.promise.then(() => {
  2896. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  2897. return;
  2898. }
  2899. if (this._findTimeout) {
  2900. clearTimeout(this._findTimeout);
  2901. this._findTimeout = null;
  2902. }
  2903. if (this._resumePageIdx) {
  2904. this._resumePageIdx = null;
  2905. this._dirtyMatch = true;
  2906. }
  2907. this._updateUIState(FindState.FOUND);
  2908. this._highlightMatches = false;
  2909. this._updateAllPages();
  2910. });
  2911. }
  2912. _requestMatchesCount() {
  2913. const {
  2914. pageIdx,
  2915. matchIdx
  2916. } = this._selected;
  2917. let current = 0,
  2918. total = this._matchesCountTotal;
  2919. if (matchIdx !== -1) {
  2920. for (let i = 0; i < pageIdx; i++) {
  2921. current += this._pageMatches[i]?.length || 0;
  2922. }
  2923. current += matchIdx + 1;
  2924. }
  2925. if (current < 1 || current > total) {
  2926. current = total = 0;
  2927. }
  2928. return {
  2929. current,
  2930. total
  2931. };
  2932. }
  2933. _updateUIResultsCount() {
  2934. this._eventBus.dispatch("updatefindmatchescount", {
  2935. source: this,
  2936. matchesCount: this._requestMatchesCount()
  2937. });
  2938. }
  2939. _updateUIState(state, previous) {
  2940. this._eventBus.dispatch("updatefindcontrolstate", {
  2941. source: this,
  2942. state,
  2943. previous,
  2944. matchesCount: this._requestMatchesCount(),
  2945. rawQuery: this._state?.query ?? null
  2946. });
  2947. }
  2948. }
  2949. exports.PDFFindController = PDFFindController;
  2950. /***/ }),
  2951. /* 12 */
  2952. /***/ ((__unused_webpack_module, exports) => {
  2953. Object.defineProperty(exports, "__esModule", ({
  2954. value: true
  2955. }));
  2956. exports.getCharacterType = getCharacterType;
  2957. exports.CharacterType = void 0;
  2958. const CharacterType = {
  2959. SPACE: 0,
  2960. ALPHA_LETTER: 1,
  2961. PUNCT: 2,
  2962. HAN_LETTER: 3,
  2963. KATAKANA_LETTER: 4,
  2964. HIRAGANA_LETTER: 5,
  2965. HALFWIDTH_KATAKANA_LETTER: 6,
  2966. THAI_LETTER: 7
  2967. };
  2968. exports.CharacterType = CharacterType;
  2969. function isAlphabeticalScript(charCode) {
  2970. return charCode < 0x2e80;
  2971. }
  2972. function isAscii(charCode) {
  2973. return (charCode & 0xff80) === 0;
  2974. }
  2975. function isAsciiAlpha(charCode) {
  2976. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  2977. }
  2978. function isAsciiDigit(charCode) {
  2979. return charCode >= 0x30 && charCode <= 0x39;
  2980. }
  2981. function isAsciiSpace(charCode) {
  2982. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  2983. }
  2984. function isHan(charCode) {
  2985. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  2986. }
  2987. function isKatakana(charCode) {
  2988. return charCode >= 0x30a0 && charCode <= 0x30ff;
  2989. }
  2990. function isHiragana(charCode) {
  2991. return charCode >= 0x3040 && charCode <= 0x309f;
  2992. }
  2993. function isHalfwidthKatakana(charCode) {
  2994. return charCode >= 0xff60 && charCode <= 0xff9f;
  2995. }
  2996. function isThai(charCode) {
  2997. return (charCode & 0xff80) === 0x0e00;
  2998. }
  2999. function getCharacterType(charCode) {
  3000. if (isAlphabeticalScript(charCode)) {
  3001. if (isAscii(charCode)) {
  3002. if (isAsciiSpace(charCode)) {
  3003. return CharacterType.SPACE;
  3004. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  3005. return CharacterType.ALPHA_LETTER;
  3006. }
  3007. return CharacterType.PUNCT;
  3008. } else if (isThai(charCode)) {
  3009. return CharacterType.THAI_LETTER;
  3010. } else if (charCode === 0xa0) {
  3011. return CharacterType.SPACE;
  3012. }
  3013. return CharacterType.ALPHA_LETTER;
  3014. }
  3015. if (isHan(charCode)) {
  3016. return CharacterType.HAN_LETTER;
  3017. } else if (isKatakana(charCode)) {
  3018. return CharacterType.KATAKANA_LETTER;
  3019. } else if (isHiragana(charCode)) {
  3020. return CharacterType.HIRAGANA_LETTER;
  3021. } else if (isHalfwidthKatakana(charCode)) {
  3022. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  3023. }
  3024. return CharacterType.ALPHA_LETTER;
  3025. }
  3026. /***/ }),
  3027. /* 13 */
  3028. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3029. Object.defineProperty(exports, "__esModule", ({
  3030. value: true
  3031. }));
  3032. exports.isDestArraysEqual = isDestArraysEqual;
  3033. exports.isDestHashesEqual = isDestHashesEqual;
  3034. exports.PDFHistory = void 0;
  3035. var _ui_utils = __w_pdfjs_require__(5);
  3036. const HASH_CHANGE_TIMEOUT = 1000;
  3037. const POSITION_UPDATED_THRESHOLD = 50;
  3038. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  3039. function getCurrentHash() {
  3040. return document.location.hash;
  3041. }
  3042. class PDFHistory {
  3043. constructor({
  3044. linkService,
  3045. eventBus
  3046. }) {
  3047. this.linkService = linkService;
  3048. this.eventBus = eventBus;
  3049. this._initialized = false;
  3050. this._fingerprint = "";
  3051. this.reset();
  3052. this._boundEvents = null;
  3053. this._isViewerInPresentationMode = false;
  3054. this.eventBus._on("presentationmodechanged", evt => {
  3055. this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
  3056. });
  3057. this.eventBus._on("pagesinit", () => {
  3058. this._isPagesLoaded = false;
  3059. this.eventBus._on("pagesloaded", evt => {
  3060. this._isPagesLoaded = !!evt.pagesCount;
  3061. }, {
  3062. once: true
  3063. });
  3064. });
  3065. }
  3066. initialize({
  3067. fingerprint,
  3068. resetHistory = false,
  3069. updateUrl = false
  3070. }) {
  3071. if (!fingerprint || typeof fingerprint !== "string") {
  3072. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  3073. return;
  3074. }
  3075. if (this._initialized) {
  3076. this.reset();
  3077. }
  3078. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  3079. this._fingerprint = fingerprint;
  3080. this._updateUrl = updateUrl === true;
  3081. this._initialized = true;
  3082. this._bindEvents();
  3083. const state = window.history.state;
  3084. this._popStateInProgress = false;
  3085. this._blockHashChange = 0;
  3086. this._currentHash = getCurrentHash();
  3087. this._numPositionUpdates = 0;
  3088. this._uid = this._maxUid = 0;
  3089. this._destination = null;
  3090. this._position = null;
  3091. if (!this._isValidState(state, true) || resetHistory) {
  3092. const {
  3093. hash,
  3094. page,
  3095. rotation
  3096. } = this._parseCurrentHash(true);
  3097. if (!hash || reInitialized || resetHistory) {
  3098. this._pushOrReplaceState(null, true);
  3099. return;
  3100. }
  3101. this._pushOrReplaceState({
  3102. hash,
  3103. page,
  3104. rotation
  3105. }, true);
  3106. return;
  3107. }
  3108. const destination = state.destination;
  3109. this._updateInternalState(destination, state.uid, true);
  3110. if (destination.rotation !== undefined) {
  3111. this._initialRotation = destination.rotation;
  3112. }
  3113. if (destination.dest) {
  3114. this._initialBookmark = JSON.stringify(destination.dest);
  3115. this._destination.page = null;
  3116. } else if (destination.hash) {
  3117. this._initialBookmark = destination.hash;
  3118. } else if (destination.page) {
  3119. this._initialBookmark = `page=${destination.page}`;
  3120. }
  3121. }
  3122. reset() {
  3123. if (this._initialized) {
  3124. this._pageHide();
  3125. this._initialized = false;
  3126. this._unbindEvents();
  3127. }
  3128. if (this._updateViewareaTimeout) {
  3129. clearTimeout(this._updateViewareaTimeout);
  3130. this._updateViewareaTimeout = null;
  3131. }
  3132. this._initialBookmark = null;
  3133. this._initialRotation = null;
  3134. }
  3135. push({
  3136. namedDest = null,
  3137. explicitDest,
  3138. pageNumber
  3139. }) {
  3140. if (!this._initialized) {
  3141. return;
  3142. }
  3143. if (namedDest && typeof namedDest !== "string") {
  3144. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  3145. return;
  3146. } else if (!Array.isArray(explicitDest)) {
  3147. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  3148. return;
  3149. } else if (!this._isValidPage(pageNumber)) {
  3150. if (pageNumber !== null || this._destination) {
  3151. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  3152. return;
  3153. }
  3154. }
  3155. const hash = namedDest || JSON.stringify(explicitDest);
  3156. if (!hash) {
  3157. return;
  3158. }
  3159. let forceReplace = false;
  3160. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  3161. if (this._destination.page) {
  3162. return;
  3163. }
  3164. forceReplace = true;
  3165. }
  3166. if (this._popStateInProgress && !forceReplace) {
  3167. return;
  3168. }
  3169. this._pushOrReplaceState({
  3170. dest: explicitDest,
  3171. hash,
  3172. page: pageNumber,
  3173. rotation: this.linkService.rotation
  3174. }, forceReplace);
  3175. if (!this._popStateInProgress) {
  3176. this._popStateInProgress = true;
  3177. Promise.resolve().then(() => {
  3178. this._popStateInProgress = false;
  3179. });
  3180. }
  3181. }
  3182. pushPage(pageNumber) {
  3183. if (!this._initialized) {
  3184. return;
  3185. }
  3186. if (!this._isValidPage(pageNumber)) {
  3187. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  3188. return;
  3189. }
  3190. if (this._destination?.page === pageNumber) {
  3191. return;
  3192. }
  3193. if (this._popStateInProgress) {
  3194. return;
  3195. }
  3196. this._pushOrReplaceState({
  3197. dest: null,
  3198. hash: `page=${pageNumber}`,
  3199. page: pageNumber,
  3200. rotation: this.linkService.rotation
  3201. });
  3202. if (!this._popStateInProgress) {
  3203. this._popStateInProgress = true;
  3204. Promise.resolve().then(() => {
  3205. this._popStateInProgress = false;
  3206. });
  3207. }
  3208. }
  3209. pushCurrentPosition() {
  3210. if (!this._initialized || this._popStateInProgress) {
  3211. return;
  3212. }
  3213. this._tryPushCurrentPosition();
  3214. }
  3215. back() {
  3216. if (!this._initialized || this._popStateInProgress) {
  3217. return;
  3218. }
  3219. const state = window.history.state;
  3220. if (this._isValidState(state) && state.uid > 0) {
  3221. window.history.back();
  3222. }
  3223. }
  3224. forward() {
  3225. if (!this._initialized || this._popStateInProgress) {
  3226. return;
  3227. }
  3228. const state = window.history.state;
  3229. if (this._isValidState(state) && state.uid < this._maxUid) {
  3230. window.history.forward();
  3231. }
  3232. }
  3233. get popStateInProgress() {
  3234. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  3235. }
  3236. get initialBookmark() {
  3237. return this._initialized ? this._initialBookmark : null;
  3238. }
  3239. get initialRotation() {
  3240. return this._initialized ? this._initialRotation : null;
  3241. }
  3242. _pushOrReplaceState(destination, forceReplace = false) {
  3243. const shouldReplace = forceReplace || !this._destination;
  3244. const newState = {
  3245. fingerprint: this._fingerprint,
  3246. uid: shouldReplace ? this._uid : this._uid + 1,
  3247. destination
  3248. };
  3249. this._updateInternalState(destination, newState.uid);
  3250. let newUrl;
  3251. if (this._updateUrl && destination?.hash) {
  3252. const baseUrl = document.location.href.split("#")[0];
  3253. if (!baseUrl.startsWith("file://")) {
  3254. newUrl = `${baseUrl}#${destination.hash}`;
  3255. }
  3256. }
  3257. if (shouldReplace) {
  3258. window.history.replaceState(newState, "", newUrl);
  3259. } else {
  3260. window.history.pushState(newState, "", newUrl);
  3261. }
  3262. }
  3263. _tryPushCurrentPosition(temporary = false) {
  3264. if (!this._position) {
  3265. return;
  3266. }
  3267. let position = this._position;
  3268. if (temporary) {
  3269. position = Object.assign(Object.create(null), this._position);
  3270. position.temporary = true;
  3271. }
  3272. if (!this._destination) {
  3273. this._pushOrReplaceState(position);
  3274. return;
  3275. }
  3276. if (this._destination.temporary) {
  3277. this._pushOrReplaceState(position, true);
  3278. return;
  3279. }
  3280. if (this._destination.hash === position.hash) {
  3281. return;
  3282. }
  3283. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  3284. return;
  3285. }
  3286. let forceReplace = false;
  3287. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  3288. if (this._destination.dest !== undefined || !this._destination.first) {
  3289. return;
  3290. }
  3291. forceReplace = true;
  3292. }
  3293. this._pushOrReplaceState(position, forceReplace);
  3294. }
  3295. _isValidPage(val) {
  3296. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  3297. }
  3298. _isValidState(state, checkReload = false) {
  3299. if (!state) {
  3300. return false;
  3301. }
  3302. if (state.fingerprint !== this._fingerprint) {
  3303. if (checkReload) {
  3304. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  3305. return false;
  3306. }
  3307. const [perfEntry] = performance.getEntriesByType("navigation");
  3308. if (perfEntry?.type !== "reload") {
  3309. return false;
  3310. }
  3311. } else {
  3312. return false;
  3313. }
  3314. }
  3315. if (!Number.isInteger(state.uid) || state.uid < 0) {
  3316. return false;
  3317. }
  3318. if (state.destination === null || typeof state.destination !== "object") {
  3319. return false;
  3320. }
  3321. return true;
  3322. }
  3323. _updateInternalState(destination, uid, removeTemporary = false) {
  3324. if (this._updateViewareaTimeout) {
  3325. clearTimeout(this._updateViewareaTimeout);
  3326. this._updateViewareaTimeout = null;
  3327. }
  3328. if (removeTemporary && destination?.temporary) {
  3329. delete destination.temporary;
  3330. }
  3331. this._destination = destination;
  3332. this._uid = uid;
  3333. this._maxUid = Math.max(this._maxUid, uid);
  3334. this._numPositionUpdates = 0;
  3335. }
  3336. _parseCurrentHash(checkNameddest = false) {
  3337. const hash = unescape(getCurrentHash()).substring(1);
  3338. const params = (0, _ui_utils.parseQueryString)(hash);
  3339. const nameddest = params.nameddest || "";
  3340. let page = params.page | 0;
  3341. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  3342. page = null;
  3343. }
  3344. return {
  3345. hash,
  3346. page,
  3347. rotation: this.linkService.rotation
  3348. };
  3349. }
  3350. _updateViewarea({
  3351. location
  3352. }) {
  3353. if (this._updateViewareaTimeout) {
  3354. clearTimeout(this._updateViewareaTimeout);
  3355. this._updateViewareaTimeout = null;
  3356. }
  3357. this._position = {
  3358. hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
  3359. page: this.linkService.page,
  3360. first: location.pageNumber,
  3361. rotation: location.rotation
  3362. };
  3363. if (this._popStateInProgress) {
  3364. return;
  3365. }
  3366. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  3367. this._numPositionUpdates++;
  3368. }
  3369. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  3370. this._updateViewareaTimeout = setTimeout(() => {
  3371. if (!this._popStateInProgress) {
  3372. this._tryPushCurrentPosition(true);
  3373. }
  3374. this._updateViewareaTimeout = null;
  3375. }, UPDATE_VIEWAREA_TIMEOUT);
  3376. }
  3377. }
  3378. _popState({
  3379. state
  3380. }) {
  3381. const newHash = getCurrentHash(),
  3382. hashChanged = this._currentHash !== newHash;
  3383. this._currentHash = newHash;
  3384. if (!state) {
  3385. this._uid++;
  3386. const {
  3387. hash,
  3388. page,
  3389. rotation
  3390. } = this._parseCurrentHash();
  3391. this._pushOrReplaceState({
  3392. hash,
  3393. page,
  3394. rotation
  3395. }, true);
  3396. return;
  3397. }
  3398. if (!this._isValidState(state)) {
  3399. return;
  3400. }
  3401. this._popStateInProgress = true;
  3402. if (hashChanged) {
  3403. this._blockHashChange++;
  3404. (0, _ui_utils.waitOnEventOrTimeout)({
  3405. target: window,
  3406. name: "hashchange",
  3407. delay: HASH_CHANGE_TIMEOUT
  3408. }).then(() => {
  3409. this._blockHashChange--;
  3410. });
  3411. }
  3412. const destination = state.destination;
  3413. this._updateInternalState(destination, state.uid, true);
  3414. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  3415. this.linkService.rotation = destination.rotation;
  3416. }
  3417. if (destination.dest) {
  3418. this.linkService.goToDestination(destination.dest);
  3419. } else if (destination.hash) {
  3420. this.linkService.setHash(destination.hash);
  3421. } else if (destination.page) {
  3422. this.linkService.page = destination.page;
  3423. }
  3424. Promise.resolve().then(() => {
  3425. this._popStateInProgress = false;
  3426. });
  3427. }
  3428. _pageHide() {
  3429. if (!this._destination || this._destination.temporary) {
  3430. this._tryPushCurrentPosition();
  3431. }
  3432. }
  3433. _bindEvents() {
  3434. if (this._boundEvents) {
  3435. return;
  3436. }
  3437. this._boundEvents = {
  3438. updateViewarea: this._updateViewarea.bind(this),
  3439. popState: this._popState.bind(this),
  3440. pageHide: this._pageHide.bind(this)
  3441. };
  3442. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  3443. window.addEventListener("popstate", this._boundEvents.popState);
  3444. window.addEventListener("pagehide", this._boundEvents.pageHide);
  3445. }
  3446. _unbindEvents() {
  3447. if (!this._boundEvents) {
  3448. return;
  3449. }
  3450. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  3451. window.removeEventListener("popstate", this._boundEvents.popState);
  3452. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  3453. this._boundEvents = null;
  3454. }
  3455. }
  3456. exports.PDFHistory = PDFHistory;
  3457. function isDestHashesEqual(destHash, pushHash) {
  3458. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  3459. return false;
  3460. }
  3461. if (destHash === pushHash) {
  3462. return true;
  3463. }
  3464. const {
  3465. nameddest
  3466. } = (0, _ui_utils.parseQueryString)(destHash);
  3467. if (nameddest === pushHash) {
  3468. return true;
  3469. }
  3470. return false;
  3471. }
  3472. function isDestArraysEqual(firstDest, secondDest) {
  3473. function isEntryEqual(first, second) {
  3474. if (typeof first !== typeof second) {
  3475. return false;
  3476. }
  3477. if (Array.isArray(first) || Array.isArray(second)) {
  3478. return false;
  3479. }
  3480. if (first !== null && typeof first === "object" && second !== null) {
  3481. if (Object.keys(first).length !== Object.keys(second).length) {
  3482. return false;
  3483. }
  3484. for (const key in first) {
  3485. if (!isEntryEqual(first[key], second[key])) {
  3486. return false;
  3487. }
  3488. }
  3489. return true;
  3490. }
  3491. return first === second || Number.isNaN(first) && Number.isNaN(second);
  3492. }
  3493. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  3494. return false;
  3495. }
  3496. if (firstDest.length !== secondDest.length) {
  3497. return false;
  3498. }
  3499. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  3500. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  3501. return false;
  3502. }
  3503. }
  3504. return true;
  3505. }
  3506. /***/ }),
  3507. /* 14 */
  3508. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  3509. Object.defineProperty(exports, "__esModule", ({
  3510. value: true
  3511. }));
  3512. exports.PDFPageView = void 0;
  3513. var _ui_utils = __w_pdfjs_require__(5);
  3514. var _pdfjsLib = __w_pdfjs_require__(2);
  3515. var _l10n_utils = __w_pdfjs_require__(3);
  3516. var _pdf_rendering_queue = __w_pdfjs_require__(15);
  3517. var _viewer_compatibility = __w_pdfjs_require__(8);
  3518. const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
  3519. class PDFPageView {
  3520. constructor(options) {
  3521. const container = options.container;
  3522. const defaultViewport = options.defaultViewport;
  3523. this.id = options.id;
  3524. this.renderingId = "page" + this.id;
  3525. this.pdfPage = null;
  3526. this.pageLabel = null;
  3527. this.rotation = 0;
  3528. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  3529. this.viewport = defaultViewport;
  3530. this.pdfPageRotate = defaultViewport.rotation;
  3531. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  3532. this.hasRestrictedScaling = false;
  3533. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  3534. this.imageResourcesPath = options.imageResourcesPath || "";
  3535. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  3536. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  3537. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  3538. this.eventBus = options.eventBus;
  3539. this.renderingQueue = options.renderingQueue;
  3540. this.textLayerFactory = options.textLayerFactory;
  3541. this.annotationLayerFactory = options.annotationLayerFactory;
  3542. this.xfaLayerFactory = options.xfaLayerFactory;
  3543. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  3544. this.enableWebGL = options.enableWebGL || false;
  3545. this.l10n = options.l10n || _l10n_utils.NullL10n;
  3546. this.enableScripting = options.enableScripting === true;
  3547. this.paintTask = null;
  3548. this.paintedViewportMap = new WeakMap();
  3549. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  3550. this.resume = null;
  3551. this._renderError = null;
  3552. this.annotationLayer = null;
  3553. this.textLayer = null;
  3554. this.zoomLayer = null;
  3555. this.xfaLayer = null;
  3556. const div = document.createElement("div");
  3557. div.className = "page";
  3558. div.style.width = Math.floor(this.viewport.width) + "px";
  3559. div.style.height = Math.floor(this.viewport.height) + "px";
  3560. div.setAttribute("data-page-number", this.id);
  3561. div.setAttribute("role", "region");
  3562. this.l10n.get("page_landmark", {
  3563. page: this.id
  3564. }).then(msg => {
  3565. div.setAttribute("aria-label", msg);
  3566. });
  3567. this.div = div;
  3568. container.appendChild(div);
  3569. }
  3570. setPdfPage(pdfPage) {
  3571. this.pdfPage = pdfPage;
  3572. this.pdfPageRotate = pdfPage.rotate;
  3573. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  3574. this.viewport = pdfPage.getViewport({
  3575. scale: this.scale * _ui_utils.CSS_UNITS,
  3576. rotation: totalRotation
  3577. });
  3578. this.reset();
  3579. }
  3580. destroy() {
  3581. this.reset();
  3582. if (this.pdfPage) {
  3583. this.pdfPage.cleanup();
  3584. }
  3585. }
  3586. async _renderAnnotationLayer() {
  3587. let error = null;
  3588. try {
  3589. await this.annotationLayer.render(this.viewport, "display");
  3590. } catch (ex) {
  3591. error = ex;
  3592. } finally {
  3593. this.eventBus.dispatch("annotationlayerrendered", {
  3594. source: this,
  3595. pageNumber: this.id,
  3596. error
  3597. });
  3598. }
  3599. }
  3600. async _renderXfaLayer() {
  3601. let error = null;
  3602. try {
  3603. await this.xfaLayer.render(this.viewport, "display");
  3604. } catch (ex) {
  3605. error = ex;
  3606. } finally {
  3607. this.eventBus.dispatch("xfalayerrendered", {
  3608. source: this,
  3609. pageNumber: this.id,
  3610. error
  3611. });
  3612. }
  3613. }
  3614. _resetZoomLayer(removeFromDOM = false) {
  3615. if (!this.zoomLayer) {
  3616. return;
  3617. }
  3618. const zoomLayerCanvas = this.zoomLayer.firstChild;
  3619. this.paintedViewportMap.delete(zoomLayerCanvas);
  3620. zoomLayerCanvas.width = 0;
  3621. zoomLayerCanvas.height = 0;
  3622. if (removeFromDOM) {
  3623. this.zoomLayer.remove();
  3624. }
  3625. this.zoomLayer = null;
  3626. }
  3627. reset(keepZoomLayer = false, keepAnnotations = false) {
  3628. this.cancelRendering(keepAnnotations);
  3629. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  3630. const div = this.div;
  3631. div.style.width = Math.floor(this.viewport.width) + "px";
  3632. div.style.height = Math.floor(this.viewport.height) + "px";
  3633. const childNodes = div.childNodes;
  3634. const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  3635. const currentAnnotationNode = keepAnnotations && this.annotationLayer?.div || null;
  3636. const currentXfaLayerNode = this.xfaLayer?.div || null;
  3637. for (let i = childNodes.length - 1; i >= 0; i--) {
  3638. const node = childNodes[i];
  3639. if (currentZoomLayerNode === node || currentAnnotationNode === node || currentXfaLayerNode === node) {
  3640. continue;
  3641. }
  3642. div.removeChild(node);
  3643. }
  3644. div.removeAttribute("data-loaded");
  3645. if (currentAnnotationNode) {
  3646. this.annotationLayer.hide();
  3647. } else if (this.annotationLayer) {
  3648. this.annotationLayer.cancel();
  3649. this.annotationLayer = null;
  3650. }
  3651. if (!currentZoomLayerNode) {
  3652. if (this.canvas) {
  3653. this.paintedViewportMap.delete(this.canvas);
  3654. this.canvas.width = 0;
  3655. this.canvas.height = 0;
  3656. delete this.canvas;
  3657. }
  3658. this._resetZoomLayer();
  3659. }
  3660. if (this.svg) {
  3661. this.paintedViewportMap.delete(this.svg);
  3662. delete this.svg;
  3663. }
  3664. this.loadingIconDiv = document.createElement("div");
  3665. this.loadingIconDiv.className = "loadingIcon";
  3666. this.loadingIconDiv.setAttribute("role", "img");
  3667. this.l10n.get("loading").then(msg => {
  3668. this.loadingIconDiv?.setAttribute("aria-label", msg);
  3669. });
  3670. div.appendChild(this.loadingIconDiv);
  3671. }
  3672. update(scale, rotation, optionalContentConfigPromise = null) {
  3673. this.scale = scale || this.scale;
  3674. if (typeof rotation !== "undefined") {
  3675. this.rotation = rotation;
  3676. }
  3677. if (optionalContentConfigPromise instanceof Promise) {
  3678. this._optionalContentConfigPromise = optionalContentConfigPromise;
  3679. }
  3680. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  3681. this.viewport = this.viewport.clone({
  3682. scale: this.scale * _ui_utils.CSS_UNITS,
  3683. rotation: totalRotation
  3684. });
  3685. if (this.svg) {
  3686. this.cssTransform(this.svg, true);
  3687. this.eventBus.dispatch("pagerendered", {
  3688. source: this,
  3689. pageNumber: this.id,
  3690. cssTransform: true,
  3691. timestamp: performance.now(),
  3692. error: this._renderError
  3693. });
  3694. return;
  3695. }
  3696. let isScalingRestricted = false;
  3697. if (this.canvas && this.maxCanvasPixels > 0) {
  3698. const outputScale = this.outputScale;
  3699. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  3700. isScalingRestricted = true;
  3701. }
  3702. }
  3703. if (this.canvas) {
  3704. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  3705. this.cssTransform(this.canvas, true);
  3706. this.eventBus.dispatch("pagerendered", {
  3707. source: this,
  3708. pageNumber: this.id,
  3709. cssTransform: true,
  3710. timestamp: performance.now(),
  3711. error: this._renderError
  3712. });
  3713. return;
  3714. }
  3715. if (!this.zoomLayer && !this.canvas.hidden) {
  3716. this.zoomLayer = this.canvas.parentNode;
  3717. this.zoomLayer.style.position = "absolute";
  3718. }
  3719. }
  3720. if (this.zoomLayer) {
  3721. this.cssTransform(this.zoomLayer.firstChild);
  3722. }
  3723. this.reset(true, true);
  3724. }
  3725. cancelRendering(keepAnnotations = false) {
  3726. if (this.paintTask) {
  3727. this.paintTask.cancel();
  3728. this.paintTask = null;
  3729. }
  3730. this.resume = null;
  3731. if (this.textLayer) {
  3732. this.textLayer.cancel();
  3733. this.textLayer = null;
  3734. }
  3735. if (!keepAnnotations && this.annotationLayer) {
  3736. this.annotationLayer.cancel();
  3737. this.annotationLayer = null;
  3738. }
  3739. }
  3740. cssTransform(target, redrawAnnotations = false) {
  3741. const width = this.viewport.width;
  3742. const height = this.viewport.height;
  3743. const div = this.div;
  3744. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  3745. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  3746. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  3747. const absRotation = Math.abs(relativeRotation);
  3748. let scaleX = 1,
  3749. scaleY = 1;
  3750. if (absRotation === 90 || absRotation === 270) {
  3751. scaleX = height / width;
  3752. scaleY = width / height;
  3753. }
  3754. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  3755. if (this.textLayer) {
  3756. const textLayerViewport = this.textLayer.viewport;
  3757. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  3758. const textAbsRotation = Math.abs(textRelativeRotation);
  3759. let scale = width / textLayerViewport.width;
  3760. if (textAbsRotation === 90 || textAbsRotation === 270) {
  3761. scale = width / textLayerViewport.height;
  3762. }
  3763. const textLayerDiv = this.textLayer.textLayerDiv;
  3764. let transX, transY;
  3765. switch (textAbsRotation) {
  3766. case 0:
  3767. transX = transY = 0;
  3768. break;
  3769. case 90:
  3770. transX = 0;
  3771. transY = "-" + textLayerDiv.style.height;
  3772. break;
  3773. case 180:
  3774. transX = "-" + textLayerDiv.style.width;
  3775. transY = "-" + textLayerDiv.style.height;
  3776. break;
  3777. case 270:
  3778. transX = "-" + textLayerDiv.style.width;
  3779. transY = 0;
  3780. break;
  3781. default:
  3782. console.error("Bad rotation value.");
  3783. break;
  3784. }
  3785. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  3786. textLayerDiv.style.transformOrigin = "0% 0%";
  3787. }
  3788. if (redrawAnnotations && this.annotationLayer) {
  3789. this._renderAnnotationLayer();
  3790. }
  3791. if (this.xfaLayer) {
  3792. this._renderXfaLayer();
  3793. }
  3794. }
  3795. get width() {
  3796. return this.viewport.width;
  3797. }
  3798. get height() {
  3799. return this.viewport.height;
  3800. }
  3801. getPagePoint(x, y) {
  3802. return this.viewport.convertToPdfPoint(x, y);
  3803. }
  3804. draw() {
  3805. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  3806. console.error("Must be in new state before drawing");
  3807. this.reset();
  3808. }
  3809. const {
  3810. div,
  3811. pdfPage
  3812. } = this;
  3813. if (!pdfPage) {
  3814. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  3815. if (this.loadingIconDiv) {
  3816. div.removeChild(this.loadingIconDiv);
  3817. delete this.loadingIconDiv;
  3818. }
  3819. return Promise.reject(new Error("pdfPage is not loaded"));
  3820. }
  3821. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  3822. const canvasWrapper = document.createElement("div");
  3823. canvasWrapper.style.width = div.style.width;
  3824. canvasWrapper.style.height = div.style.height;
  3825. canvasWrapper.classList.add("canvasWrapper");
  3826. if (this.annotationLayer?.div) {
  3827. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  3828. } else {
  3829. div.appendChild(canvasWrapper);
  3830. }
  3831. let textLayer = null;
  3832. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  3833. const textLayerDiv = document.createElement("div");
  3834. textLayerDiv.className = "textLayer";
  3835. textLayerDiv.style.width = canvasWrapper.style.width;
  3836. textLayerDiv.style.height = canvasWrapper.style.height;
  3837. if (this.annotationLayer?.div) {
  3838. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  3839. } else {
  3840. div.appendChild(textLayerDiv);
  3841. }
  3842. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
  3843. }
  3844. this.textLayer = textLayer;
  3845. let renderContinueCallback = null;
  3846. if (this.renderingQueue) {
  3847. renderContinueCallback = cont => {
  3848. if (!this.renderingQueue.isHighestPriority(this)) {
  3849. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  3850. this.resume = () => {
  3851. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  3852. cont();
  3853. };
  3854. return;
  3855. }
  3856. cont();
  3857. };
  3858. }
  3859. const finishPaintTask = async (error = null) => {
  3860. if (paintTask === this.paintTask) {
  3861. this.paintTask = null;
  3862. }
  3863. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  3864. this._renderError = null;
  3865. return;
  3866. }
  3867. this._renderError = error;
  3868. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  3869. if (this.loadingIconDiv) {
  3870. div.removeChild(this.loadingIconDiv);
  3871. delete this.loadingIconDiv;
  3872. }
  3873. this._resetZoomLayer(true);
  3874. this.eventBus.dispatch("pagerendered", {
  3875. source: this,
  3876. pageNumber: this.id,
  3877. cssTransform: false,
  3878. timestamp: performance.now(),
  3879. error: this._renderError
  3880. });
  3881. if (error) {
  3882. throw error;
  3883. }
  3884. };
  3885. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  3886. paintTask.onRenderContinue = renderContinueCallback;
  3887. this.paintTask = paintTask;
  3888. const resultPromise = paintTask.promise.then(function () {
  3889. return finishPaintTask(null).then(function () {
  3890. if (textLayer) {
  3891. const readableStream = pdfPage.streamTextContent({
  3892. normalizeWhitespace: true
  3893. });
  3894. textLayer.setTextContentStream(readableStream);
  3895. textLayer.render();
  3896. }
  3897. });
  3898. }, function (reason) {
  3899. return finishPaintTask(reason);
  3900. });
  3901. if (this.annotationLayerFactory) {
  3902. if (!this.annotationLayer) {
  3903. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.renderInteractiveForms, this.l10n, this.enableScripting, null, null);
  3904. }
  3905. this._renderAnnotationLayer();
  3906. }
  3907. if (this.xfaLayerFactory) {
  3908. if (!this.xfaLayer) {
  3909. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage);
  3910. }
  3911. this._renderXfaLayer();
  3912. }
  3913. div.setAttribute("data-loaded", true);
  3914. this.eventBus.dispatch("pagerender", {
  3915. source: this,
  3916. pageNumber: this.id
  3917. });
  3918. return resultPromise;
  3919. }
  3920. paintOnCanvas(canvasWrapper) {
  3921. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  3922. const result = {
  3923. promise: renderCapability.promise,
  3924. onRenderContinue(cont) {
  3925. cont();
  3926. },
  3927. cancel() {
  3928. renderTask.cancel();
  3929. }
  3930. };
  3931. const viewport = this.viewport;
  3932. const canvas = document.createElement("canvas");
  3933. canvas.hidden = true;
  3934. let isCanvasHidden = true;
  3935. const showCanvas = function () {
  3936. if (isCanvasHidden) {
  3937. canvas.hidden = false;
  3938. isCanvasHidden = false;
  3939. }
  3940. };
  3941. canvasWrapper.appendChild(canvas);
  3942. this.canvas = canvas;
  3943. canvas.mozOpaque = true;
  3944. const ctx = canvas.getContext("2d", {
  3945. alpha: false
  3946. });
  3947. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  3948. this.outputScale = outputScale;
  3949. if (this.useOnlyCssZoom) {
  3950. const actualSizeViewport = viewport.clone({
  3951. scale: _ui_utils.CSS_UNITS
  3952. });
  3953. outputScale.sx *= actualSizeViewport.width / viewport.width;
  3954. outputScale.sy *= actualSizeViewport.height / viewport.height;
  3955. outputScale.scaled = true;
  3956. }
  3957. if (this.maxCanvasPixels > 0) {
  3958. const pixelsInViewport = viewport.width * viewport.height;
  3959. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  3960. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  3961. outputScale.sx = maxScale;
  3962. outputScale.sy = maxScale;
  3963. outputScale.scaled = true;
  3964. this.hasRestrictedScaling = true;
  3965. } else {
  3966. this.hasRestrictedScaling = false;
  3967. }
  3968. }
  3969. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  3970. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  3971. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  3972. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  3973. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  3974. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  3975. this.paintedViewportMap.set(canvas, viewport);
  3976. const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  3977. const renderContext = {
  3978. canvasContext: ctx,
  3979. transform,
  3980. viewport: this.viewport,
  3981. enableWebGL: this.enableWebGL,
  3982. renderInteractiveForms: this.renderInteractiveForms,
  3983. optionalContentConfigPromise: this._optionalContentConfigPromise
  3984. };
  3985. const renderTask = this.pdfPage.render(renderContext);
  3986. renderTask.onContinue = function (cont) {
  3987. showCanvas();
  3988. if (result.onRenderContinue) {
  3989. result.onRenderContinue(cont);
  3990. } else {
  3991. cont();
  3992. }
  3993. };
  3994. renderTask.promise.then(function () {
  3995. showCanvas();
  3996. renderCapability.resolve(undefined);
  3997. }, function (error) {
  3998. showCanvas();
  3999. renderCapability.reject(error);
  4000. });
  4001. return result;
  4002. }
  4003. paintOnSvg(wrapper) {
  4004. let cancelled = false;
  4005. const ensureNotCancelled = () => {
  4006. if (cancelled) {
  4007. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  4008. }
  4009. };
  4010. const pdfPage = this.pdfPage;
  4011. const actualSizeViewport = this.viewport.clone({
  4012. scale: _ui_utils.CSS_UNITS
  4013. });
  4014. const promise = pdfPage.getOperatorList().then(opList => {
  4015. ensureNotCancelled();
  4016. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  4017. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  4018. ensureNotCancelled();
  4019. this.svg = svg;
  4020. this.paintedViewportMap.set(svg, actualSizeViewport);
  4021. svg.style.width = wrapper.style.width;
  4022. svg.style.height = wrapper.style.height;
  4023. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  4024. wrapper.appendChild(svg);
  4025. });
  4026. });
  4027. return {
  4028. promise,
  4029. onRenderContinue(cont) {
  4030. cont();
  4031. },
  4032. cancel() {
  4033. cancelled = true;
  4034. }
  4035. };
  4036. }
  4037. setPageLabel(label) {
  4038. this.pageLabel = typeof label === "string" ? label : null;
  4039. if (this.pageLabel !== null) {
  4040. this.div.setAttribute("data-page-label", this.pageLabel);
  4041. } else {
  4042. this.div.removeAttribute("data-page-label");
  4043. }
  4044. }
  4045. }
  4046. exports.PDFPageView = PDFPageView;
  4047. /***/ }),
  4048. /* 15 */
  4049. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4050. Object.defineProperty(exports, "__esModule", ({
  4051. value: true
  4052. }));
  4053. exports.RenderingStates = exports.PDFRenderingQueue = void 0;
  4054. var _pdfjsLib = __w_pdfjs_require__(2);
  4055. const CLEANUP_TIMEOUT = 30000;
  4056. const RenderingStates = {
  4057. INITIAL: 0,
  4058. RUNNING: 1,
  4059. PAUSED: 2,
  4060. FINISHED: 3
  4061. };
  4062. exports.RenderingStates = RenderingStates;
  4063. class PDFRenderingQueue {
  4064. constructor() {
  4065. this.pdfViewer = null;
  4066. this.pdfThumbnailViewer = null;
  4067. this.onIdle = null;
  4068. this.highestPriorityPage = null;
  4069. this.idleTimeout = null;
  4070. this.printing = false;
  4071. this.isThumbnailViewEnabled = false;
  4072. }
  4073. setViewer(pdfViewer) {
  4074. this.pdfViewer = pdfViewer;
  4075. }
  4076. setThumbnailViewer(pdfThumbnailViewer) {
  4077. this.pdfThumbnailViewer = pdfThumbnailViewer;
  4078. }
  4079. isHighestPriority(view) {
  4080. return this.highestPriorityPage === view.renderingId;
  4081. }
  4082. renderHighestPriority(currentlyVisiblePages) {
  4083. if (this.idleTimeout) {
  4084. clearTimeout(this.idleTimeout);
  4085. this.idleTimeout = null;
  4086. }
  4087. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  4088. return;
  4089. }
  4090. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  4091. if (this.pdfThumbnailViewer.forceRendering()) {
  4092. return;
  4093. }
  4094. }
  4095. if (this.printing) {
  4096. return;
  4097. }
  4098. if (this.onIdle) {
  4099. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  4100. }
  4101. }
  4102. getHighestPriority(visible, views, scrolledDown) {
  4103. const visibleViews = visible.views;
  4104. const numVisible = visibleViews.length;
  4105. if (numVisible === 0) {
  4106. return null;
  4107. }
  4108. for (let i = 0; i < numVisible; ++i) {
  4109. const view = visibleViews[i].view;
  4110. if (!this.isViewFinished(view)) {
  4111. return view;
  4112. }
  4113. }
  4114. if (scrolledDown) {
  4115. const nextPageIndex = visible.last.id;
  4116. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  4117. return views[nextPageIndex];
  4118. }
  4119. } else {
  4120. const previousPageIndex = visible.first.id - 2;
  4121. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  4122. return views[previousPageIndex];
  4123. }
  4124. }
  4125. return null;
  4126. }
  4127. isViewFinished(view) {
  4128. return view.renderingState === RenderingStates.FINISHED;
  4129. }
  4130. renderView(view) {
  4131. switch (view.renderingState) {
  4132. case RenderingStates.FINISHED:
  4133. return false;
  4134. case RenderingStates.PAUSED:
  4135. this.highestPriorityPage = view.renderingId;
  4136. view.resume();
  4137. break;
  4138. case RenderingStates.RUNNING:
  4139. this.highestPriorityPage = view.renderingId;
  4140. break;
  4141. case RenderingStates.INITIAL:
  4142. this.highestPriorityPage = view.renderingId;
  4143. view.draw().finally(() => {
  4144. this.renderHighestPriority();
  4145. }).catch(reason => {
  4146. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  4147. return;
  4148. }
  4149. console.error(`renderView: "${reason}"`);
  4150. });
  4151. break;
  4152. }
  4153. return true;
  4154. }
  4155. }
  4156. exports.PDFRenderingQueue = PDFRenderingQueue;
  4157. /***/ }),
  4158. /* 16 */
  4159. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4160. Object.defineProperty(exports, "__esModule", ({
  4161. value: true
  4162. }));
  4163. exports.PDFScriptingManager = void 0;
  4164. var _pdfjsLib = __w_pdfjs_require__(2);
  4165. var _ui_utils = __w_pdfjs_require__(5);
  4166. var _pdf_rendering_queue = __w_pdfjs_require__(15);
  4167. class PDFScriptingManager {
  4168. constructor({
  4169. eventBus,
  4170. sandboxBundleSrc = null,
  4171. scriptingFactory = null,
  4172. docPropertiesLookup = null
  4173. }) {
  4174. this._pdfDocument = null;
  4175. this._pdfViewer = null;
  4176. this._closeCapability = null;
  4177. this._destroyCapability = null;
  4178. this._scripting = null;
  4179. this._mouseState = Object.create(null);
  4180. this._pageEventsReady = false;
  4181. this._ready = false;
  4182. this._eventBus = eventBus;
  4183. this._sandboxBundleSrc = sandboxBundleSrc;
  4184. this._scriptingFactory = scriptingFactory;
  4185. this._docPropertiesLookup = docPropertiesLookup;
  4186. if (!this._scriptingFactory) {
  4187. window.addEventListener("updatefromsandbox", event => {
  4188. this._eventBus.dispatch("updatefromsandbox", {
  4189. source: window,
  4190. detail: event.detail
  4191. });
  4192. });
  4193. }
  4194. }
  4195. setViewer(pdfViewer) {
  4196. this._pdfViewer = pdfViewer;
  4197. }
  4198. async setDocument(pdfDocument) {
  4199. if (this._pdfDocument) {
  4200. await this._destroyScripting();
  4201. }
  4202. this._pdfDocument = pdfDocument;
  4203. if (!pdfDocument) {
  4204. return;
  4205. }
  4206. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  4207. if (!objects && !docActions) {
  4208. await this._destroyScripting();
  4209. return;
  4210. }
  4211. if (pdfDocument !== this._pdfDocument) {
  4212. return;
  4213. }
  4214. this._scripting = this._createScripting();
  4215. this._internalEvents.set("updatefromsandbox", event => {
  4216. if (event?.source !== window) {
  4217. return;
  4218. }
  4219. this._updateFromSandbox(event.detail);
  4220. });
  4221. this._internalEvents.set("dispatcheventinsandbox", event => {
  4222. this._scripting?.dispatchEventInSandbox(event.detail);
  4223. });
  4224. this._internalEvents.set("pagechanging", ({
  4225. pageNumber,
  4226. previous
  4227. }) => {
  4228. if (pageNumber === previous) {
  4229. return;
  4230. }
  4231. this._dispatchPageClose(previous);
  4232. this._dispatchPageOpen(pageNumber);
  4233. });
  4234. this._internalEvents.set("pagerendered", ({
  4235. pageNumber
  4236. }) => {
  4237. if (!this._pageOpenPending.has(pageNumber)) {
  4238. return;
  4239. }
  4240. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  4241. return;
  4242. }
  4243. this._dispatchPageOpen(pageNumber);
  4244. });
  4245. this._internalEvents.set("pagesdestroy", async event => {
  4246. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  4247. await this._scripting?.dispatchEventInSandbox({
  4248. id: "doc",
  4249. name: "WillClose"
  4250. });
  4251. this._closeCapability?.resolve();
  4252. });
  4253. this._domEvents.set("mousedown", event => {
  4254. this._mouseState.isDown = true;
  4255. });
  4256. this._domEvents.set("mouseup", event => {
  4257. this._mouseState.isDown = false;
  4258. });
  4259. for (const [name, listener] of this._internalEvents) {
  4260. this._eventBus._on(name, listener);
  4261. }
  4262. for (const [name, listener] of this._domEvents) {
  4263. window.addEventListener(name, listener);
  4264. }
  4265. try {
  4266. const docProperties = await this._getDocProperties();
  4267. if (pdfDocument !== this._pdfDocument) {
  4268. return;
  4269. }
  4270. await this._scripting.createSandbox({
  4271. objects,
  4272. calculationOrder,
  4273. appInfo: {
  4274. platform: navigator.platform,
  4275. language: navigator.language
  4276. },
  4277. docInfo: { ...docProperties,
  4278. actions: docActions
  4279. }
  4280. });
  4281. this._eventBus.dispatch("sandboxcreated", {
  4282. source: this
  4283. });
  4284. } catch (error) {
  4285. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  4286. await this._destroyScripting();
  4287. return;
  4288. }
  4289. await this._scripting?.dispatchEventInSandbox({
  4290. id: "doc",
  4291. name: "Open"
  4292. });
  4293. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  4294. Promise.resolve().then(() => {
  4295. if (pdfDocument === this._pdfDocument) {
  4296. this._ready = true;
  4297. }
  4298. });
  4299. }
  4300. async dispatchWillSave(detail) {
  4301. return this._scripting?.dispatchEventInSandbox({
  4302. id: "doc",
  4303. name: "WillSave"
  4304. });
  4305. }
  4306. async dispatchDidSave(detail) {
  4307. return this._scripting?.dispatchEventInSandbox({
  4308. id: "doc",
  4309. name: "DidSave"
  4310. });
  4311. }
  4312. async dispatchWillPrint(detail) {
  4313. return this._scripting?.dispatchEventInSandbox({
  4314. id: "doc",
  4315. name: "WillPrint"
  4316. });
  4317. }
  4318. async dispatchDidPrint(detail) {
  4319. return this._scripting?.dispatchEventInSandbox({
  4320. id: "doc",
  4321. name: "DidPrint"
  4322. });
  4323. }
  4324. get mouseState() {
  4325. return this._mouseState;
  4326. }
  4327. get destroyPromise() {
  4328. return this._destroyCapability?.promise || null;
  4329. }
  4330. get ready() {
  4331. return this._ready;
  4332. }
  4333. get _internalEvents() {
  4334. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  4335. }
  4336. get _domEvents() {
  4337. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  4338. }
  4339. get _pageOpenPending() {
  4340. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  4341. }
  4342. get _visitedPages() {
  4343. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  4344. }
  4345. async _updateFromSandbox(detail) {
  4346. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  4347. const {
  4348. id,
  4349. command,
  4350. value
  4351. } = detail;
  4352. if (!id) {
  4353. switch (command) {
  4354. case "clear":
  4355. console.clear();
  4356. break;
  4357. case "error":
  4358. console.error(value);
  4359. break;
  4360. case "layout":
  4361. this._pdfViewer.spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(value);
  4362. break;
  4363. case "page-num":
  4364. this._pdfViewer.currentPageNumber = value + 1;
  4365. break;
  4366. case "print":
  4367. await this._pdfViewer.pagesPromise;
  4368. this._eventBus.dispatch("print", {
  4369. source: this
  4370. });
  4371. break;
  4372. case "println":
  4373. console.log(value);
  4374. break;
  4375. case "zoom":
  4376. if (isInPresentationMode) {
  4377. return;
  4378. }
  4379. this._pdfViewer.currentScaleValue = value;
  4380. break;
  4381. }
  4382. return;
  4383. }
  4384. if (isInPresentationMode) {
  4385. if (detail.focus) {
  4386. return;
  4387. }
  4388. }
  4389. const element = document.getElementById(id);
  4390. if (element) {
  4391. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  4392. detail
  4393. }));
  4394. } else {
  4395. delete detail.id;
  4396. this._pdfDocument?.annotationStorage.setValue(id, detail);
  4397. }
  4398. }
  4399. async _dispatchPageOpen(pageNumber, initialize = false) {
  4400. const pdfDocument = this._pdfDocument,
  4401. visitedPages = this._visitedPages;
  4402. if (initialize) {
  4403. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  4404. this._pageEventsReady = true;
  4405. }
  4406. if (!this._pageEventsReady) {
  4407. return;
  4408. }
  4409. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  4410. if (pageView?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  4411. this._pageOpenPending.add(pageNumber);
  4412. return;
  4413. }
  4414. this._pageOpenPending.delete(pageNumber);
  4415. const actionsPromise = (async () => {
  4416. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  4417. if (pdfDocument !== this._pdfDocument) {
  4418. return;
  4419. }
  4420. await this._scripting?.dispatchEventInSandbox({
  4421. id: "page",
  4422. name: "PageOpen",
  4423. pageNumber,
  4424. actions
  4425. });
  4426. })();
  4427. visitedPages.set(pageNumber, actionsPromise);
  4428. }
  4429. async _dispatchPageClose(pageNumber) {
  4430. const pdfDocument = this._pdfDocument,
  4431. visitedPages = this._visitedPages;
  4432. if (!this._pageEventsReady) {
  4433. return;
  4434. }
  4435. if (this._pageOpenPending.has(pageNumber)) {
  4436. return;
  4437. }
  4438. const actionsPromise = visitedPages.get(pageNumber);
  4439. if (!actionsPromise) {
  4440. return;
  4441. }
  4442. visitedPages.set(pageNumber, null);
  4443. await actionsPromise;
  4444. if (pdfDocument !== this._pdfDocument) {
  4445. return;
  4446. }
  4447. await this._scripting?.dispatchEventInSandbox({
  4448. id: "page",
  4449. name: "PageClose",
  4450. pageNumber
  4451. });
  4452. }
  4453. async _getDocProperties() {
  4454. if (this._docPropertiesLookup) {
  4455. return this._docPropertiesLookup(this._pdfDocument);
  4456. }
  4457. const {
  4458. docPropertiesLookup
  4459. } = __w_pdfjs_require__(17);
  4460. return docPropertiesLookup(this._pdfDocument);
  4461. }
  4462. _createScripting() {
  4463. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  4464. if (this._scripting) {
  4465. throw new Error("_createScripting: Scripting already exists.");
  4466. }
  4467. if (this._scriptingFactory) {
  4468. return this._scriptingFactory.createScripting({
  4469. sandboxBundleSrc: this._sandboxBundleSrc
  4470. });
  4471. }
  4472. const {
  4473. GenericScripting
  4474. } = __w_pdfjs_require__(17);
  4475. return new GenericScripting(this._sandboxBundleSrc);
  4476. }
  4477. async _destroyScripting() {
  4478. if (!this._scripting) {
  4479. this._pdfDocument = null;
  4480. this._destroyCapability?.resolve();
  4481. return;
  4482. }
  4483. if (this._closeCapability) {
  4484. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  4485. setTimeout(resolve, 1000);
  4486. })]).catch(reason => {});
  4487. this._closeCapability = null;
  4488. }
  4489. this._pdfDocument = null;
  4490. try {
  4491. await this._scripting.destroySandbox();
  4492. } catch (ex) {}
  4493. for (const [name, listener] of this._internalEvents) {
  4494. this._eventBus._off(name, listener);
  4495. }
  4496. this._internalEvents.clear();
  4497. for (const [name, listener] of this._domEvents) {
  4498. window.removeEventListener(name, listener);
  4499. }
  4500. this._domEvents.clear();
  4501. this._pageOpenPending.clear();
  4502. this._visitedPages.clear();
  4503. this._scripting = null;
  4504. delete this._mouseState.isDown;
  4505. this._pageEventsReady = false;
  4506. this._ready = false;
  4507. this._destroyCapability?.resolve();
  4508. }
  4509. }
  4510. exports.PDFScriptingManager = PDFScriptingManager;
  4511. /***/ }),
  4512. /* 17 */
  4513. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4514. Object.defineProperty(exports, "__esModule", ({
  4515. value: true
  4516. }));
  4517. exports.docPropertiesLookup = docPropertiesLookup;
  4518. exports.GenericScripting = void 0;
  4519. var _pdfjsLib = __w_pdfjs_require__(2);
  4520. async function docPropertiesLookup(pdfDocument) {
  4521. const url = "",
  4522. baseUrl = url.split("#")[0];
  4523. let {
  4524. info,
  4525. metadata,
  4526. contentDispositionFilename,
  4527. contentLength
  4528. } = await pdfDocument.getMetadata();
  4529. if (!contentLength) {
  4530. const {
  4531. length
  4532. } = await pdfDocument.getDownloadInfo();
  4533. contentLength = length;
  4534. }
  4535. return { ...info,
  4536. baseURL: baseUrl,
  4537. filesize: contentLength,
  4538. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  4539. metadata: metadata?.getRaw(),
  4540. authors: metadata?.get("dc:creator"),
  4541. numPages: pdfDocument.numPages,
  4542. URL: url
  4543. };
  4544. }
  4545. class GenericScripting {
  4546. constructor(sandboxBundleSrc) {
  4547. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  4548. return window.pdfjsSandbox.QuickJSSandbox();
  4549. });
  4550. }
  4551. async createSandbox(data) {
  4552. const sandbox = await this._ready;
  4553. sandbox.create(data);
  4554. }
  4555. async dispatchEventInSandbox(event) {
  4556. const sandbox = await this._ready;
  4557. sandbox.dispatchEvent(event);
  4558. }
  4559. async destroySandbox() {
  4560. const sandbox = await this._ready;
  4561. sandbox.nukeSandbox();
  4562. }
  4563. }
  4564. exports.GenericScripting = GenericScripting;
  4565. /***/ }),
  4566. /* 18 */
  4567. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4568. Object.defineProperty(exports, "__esModule", ({
  4569. value: true
  4570. }));
  4571. exports.PDFSinglePageViewer = void 0;
  4572. var _base_viewer = __w_pdfjs_require__(19);
  4573. var _pdfjsLib = __w_pdfjs_require__(2);
  4574. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  4575. constructor(options) {
  4576. super(options);
  4577. this.eventBus._on("pagesinit", evt => {
  4578. this._ensurePageViewVisible();
  4579. });
  4580. }
  4581. get _viewerElement() {
  4582. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this._shadowViewer);
  4583. }
  4584. get _pageWidthScaleFactor() {
  4585. return 1;
  4586. }
  4587. _resetView() {
  4588. super._resetView();
  4589. this._previousPageNumber = 1;
  4590. this._shadowViewer = document.createDocumentFragment();
  4591. this._updateScrollDown = null;
  4592. }
  4593. _ensurePageViewVisible() {
  4594. const pageView = this._pages[this._currentPageNumber - 1];
  4595. const previousPageView = this._pages[this._previousPageNumber - 1];
  4596. const viewerNodes = this.viewer.childNodes;
  4597. switch (viewerNodes.length) {
  4598. case 0:
  4599. this.viewer.appendChild(pageView.div);
  4600. break;
  4601. case 1:
  4602. if (viewerNodes[0] !== previousPageView.div) {
  4603. throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
  4604. }
  4605. if (pageView === previousPageView) {
  4606. break;
  4607. }
  4608. this._shadowViewer.appendChild(previousPageView.div);
  4609. this.viewer.appendChild(pageView.div);
  4610. this.container.scrollTop = 0;
  4611. break;
  4612. default:
  4613. throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
  4614. }
  4615. this._previousPageNumber = this._currentPageNumber;
  4616. }
  4617. _scrollUpdate() {
  4618. if (this._updateScrollDown) {
  4619. this._updateScrollDown();
  4620. }
  4621. super._scrollUpdate();
  4622. }
  4623. _scrollIntoView({
  4624. pageDiv,
  4625. pageSpot = null,
  4626. pageNumber = null
  4627. }) {
  4628. if (pageNumber) {
  4629. this._setCurrentPageNumber(pageNumber);
  4630. }
  4631. const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
  4632. this._ensurePageViewVisible();
  4633. this.update();
  4634. super._scrollIntoView({
  4635. pageDiv,
  4636. pageSpot,
  4637. pageNumber
  4638. });
  4639. this._updateScrollDown = () => {
  4640. this.scroll.down = scrolledDown;
  4641. this._updateScrollDown = null;
  4642. };
  4643. }
  4644. _getVisiblePages() {
  4645. return this._getCurrentVisiblePage();
  4646. }
  4647. _updateHelper(visiblePages) {}
  4648. get _isScrollModeHorizontal() {
  4649. return (0, _pdfjsLib.shadow)(this, "_isScrollModeHorizontal", false);
  4650. }
  4651. _updateScrollMode() {}
  4652. _updateSpreadMode() {}
  4653. _getPageAdvance() {
  4654. return 1;
  4655. }
  4656. }
  4657. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  4658. /***/ }),
  4659. /* 19 */
  4660. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  4661. Object.defineProperty(exports, "__esModule", ({
  4662. value: true
  4663. }));
  4664. exports.BaseViewer = void 0;
  4665. var _pdfjsLib = __w_pdfjs_require__(2);
  4666. var _ui_utils = __w_pdfjs_require__(5);
  4667. var _pdf_rendering_queue = __w_pdfjs_require__(15);
  4668. var _annotation_layer_builder = __w_pdfjs_require__(1);
  4669. var _l10n_utils = __w_pdfjs_require__(3);
  4670. var _pdf_page_view = __w_pdfjs_require__(14);
  4671. var _pdf_link_service = __w_pdfjs_require__(4);
  4672. var _text_layer_builder = __w_pdfjs_require__(6);
  4673. var _xfa_layer_builder = __w_pdfjs_require__(20);
  4674. const DEFAULT_CACHE_SIZE = 10;
  4675. function PDFPageViewBuffer(size) {
  4676. const data = [];
  4677. this.push = function (view) {
  4678. const i = data.indexOf(view);
  4679. if (i >= 0) {
  4680. data.splice(i, 1);
  4681. }
  4682. data.push(view);
  4683. if (data.length > size) {
  4684. data.shift().destroy();
  4685. }
  4686. };
  4687. this.resize = function (newSize, pagesToKeep) {
  4688. size = newSize;
  4689. if (pagesToKeep) {
  4690. const pageIdsToKeep = new Set();
  4691. for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
  4692. pageIdsToKeep.add(pagesToKeep[i].id);
  4693. }
  4694. (0, _ui_utils.moveToEndOfArray)(data, function (page) {
  4695. return pageIdsToKeep.has(page.id);
  4696. });
  4697. }
  4698. while (data.length > size) {
  4699. data.shift().destroy();
  4700. }
  4701. };
  4702. this.has = function (view) {
  4703. return data.includes(view);
  4704. };
  4705. }
  4706. function isSameScale(oldScale, newScale) {
  4707. if (newScale === oldScale) {
  4708. return true;
  4709. }
  4710. if (Math.abs(newScale - oldScale) < 1e-15) {
  4711. return true;
  4712. }
  4713. return false;
  4714. }
  4715. class BaseViewer {
  4716. constructor(options) {
  4717. if (this.constructor === BaseViewer) {
  4718. throw new Error("Cannot initialize BaseViewer.");
  4719. }
  4720. const viewerVersion = '2.8.335';
  4721. if (_pdfjsLib.version !== viewerVersion) {
  4722. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  4723. }
  4724. this._name = this.constructor.name;
  4725. this.container = options.container;
  4726. this.viewer = options.viewer || options.container.firstElementChild;
  4727. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  4728. throw new Error("Invalid `container` and/or `viewer` option.");
  4729. }
  4730. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  4731. throw new Error("The `container` must be absolutely positioned.");
  4732. }
  4733. this.eventBus = options.eventBus;
  4734. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  4735. this.downloadManager = options.downloadManager || null;
  4736. this.findController = options.findController || null;
  4737. this._scriptingManager = options.scriptingManager || null;
  4738. this.removePageBorders = options.removePageBorders || false;
  4739. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  4740. this.imageResourcesPath = options.imageResourcesPath || "";
  4741. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  4742. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  4743. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  4744. this.enableWebGL = options.enableWebGL || false;
  4745. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  4746. this.maxCanvasPixels = options.maxCanvasPixels;
  4747. this.l10n = options.l10n || _l10n_utils.NullL10n;
  4748. this.enableScripting = options.enableScripting === true && !!this._scriptingManager;
  4749. this.defaultRenderingQueue = !options.renderingQueue;
  4750. if (this.defaultRenderingQueue) {
  4751. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  4752. this.renderingQueue.setViewer(this);
  4753. } else {
  4754. this.renderingQueue = options.renderingQueue;
  4755. }
  4756. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  4757. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  4758. this._onBeforeDraw = this._onAfterDraw = null;
  4759. this._resetView();
  4760. if (this.removePageBorders) {
  4761. this.viewer.classList.add("removePageBorders");
  4762. }
  4763. Promise.resolve().then(() => {
  4764. this.eventBus.dispatch("baseviewerinit", {
  4765. source: this
  4766. });
  4767. });
  4768. }
  4769. get pagesCount() {
  4770. return this._pages.length;
  4771. }
  4772. getPageView(index) {
  4773. return this._pages[index];
  4774. }
  4775. get pageViewsReady() {
  4776. if (!this._pagesCapability.settled) {
  4777. return false;
  4778. }
  4779. return this._pages.every(function (pageView) {
  4780. return pageView?.pdfPage;
  4781. });
  4782. }
  4783. get currentPageNumber() {
  4784. return this._currentPageNumber;
  4785. }
  4786. set currentPageNumber(val) {
  4787. if (!Number.isInteger(val)) {
  4788. throw new Error("Invalid page number.");
  4789. }
  4790. if (!this.pdfDocument) {
  4791. return;
  4792. }
  4793. if (!this._setCurrentPageNumber(val, true)) {
  4794. console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
  4795. }
  4796. }
  4797. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  4798. if (this._currentPageNumber === val) {
  4799. if (resetCurrentPageView) {
  4800. this._resetCurrentPageView();
  4801. }
  4802. return true;
  4803. }
  4804. if (!(0 < val && val <= this.pagesCount)) {
  4805. return false;
  4806. }
  4807. const previous = this._currentPageNumber;
  4808. this._currentPageNumber = val;
  4809. this.eventBus.dispatch("pagechanging", {
  4810. source: this,
  4811. pageNumber: val,
  4812. pageLabel: this._pageLabels?.[val - 1] ?? null,
  4813. previous
  4814. });
  4815. if (resetCurrentPageView) {
  4816. this._resetCurrentPageView();
  4817. }
  4818. return true;
  4819. }
  4820. get currentPageLabel() {
  4821. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  4822. }
  4823. set currentPageLabel(val) {
  4824. if (!this.pdfDocument) {
  4825. return;
  4826. }
  4827. let page = val | 0;
  4828. if (this._pageLabels) {
  4829. const i = this._pageLabels.indexOf(val);
  4830. if (i >= 0) {
  4831. page = i + 1;
  4832. }
  4833. }
  4834. if (!this._setCurrentPageNumber(page, true)) {
  4835. console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
  4836. }
  4837. }
  4838. get currentScale() {
  4839. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  4840. }
  4841. set currentScale(val) {
  4842. if (isNaN(val)) {
  4843. throw new Error("Invalid numeric scale.");
  4844. }
  4845. if (!this.pdfDocument) {
  4846. return;
  4847. }
  4848. this._setScale(val, false);
  4849. }
  4850. get currentScaleValue() {
  4851. return this._currentScaleValue;
  4852. }
  4853. set currentScaleValue(val) {
  4854. if (!this.pdfDocument) {
  4855. return;
  4856. }
  4857. this._setScale(val, false);
  4858. }
  4859. get pagesRotation() {
  4860. return this._pagesRotation;
  4861. }
  4862. set pagesRotation(rotation) {
  4863. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  4864. throw new Error("Invalid pages rotation angle.");
  4865. }
  4866. if (!this.pdfDocument) {
  4867. return;
  4868. }
  4869. rotation %= 360;
  4870. if (rotation < 0) {
  4871. rotation += 360;
  4872. }
  4873. if (this._pagesRotation === rotation) {
  4874. return;
  4875. }
  4876. this._pagesRotation = rotation;
  4877. const pageNumber = this._currentPageNumber;
  4878. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  4879. const pageView = this._pages[i];
  4880. pageView.update(pageView.scale, rotation);
  4881. }
  4882. if (this._currentScaleValue) {
  4883. this._setScale(this._currentScaleValue, true);
  4884. }
  4885. this.eventBus.dispatch("rotationchanging", {
  4886. source: this,
  4887. pagesRotation: rotation,
  4888. pageNumber
  4889. });
  4890. if (this.defaultRenderingQueue) {
  4891. this.update();
  4892. }
  4893. }
  4894. get firstPagePromise() {
  4895. return this.pdfDocument ? this._firstPageCapability.promise : null;
  4896. }
  4897. get onePageRendered() {
  4898. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  4899. }
  4900. get pagesPromise() {
  4901. return this.pdfDocument ? this._pagesCapability.promise : null;
  4902. }
  4903. get _viewerElement() {
  4904. throw new Error("Not implemented: _viewerElement");
  4905. }
  4906. _onePageRenderedOrForceFetch() {
  4907. if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  4908. return Promise.resolve();
  4909. }
  4910. return this._onePageRenderedCapability.promise;
  4911. }
  4912. setDocument(pdfDocument) {
  4913. if (this.pdfDocument) {
  4914. this.eventBus.dispatch("pagesdestroy", {
  4915. source: this
  4916. });
  4917. this._cancelRendering();
  4918. this._resetView();
  4919. if (this.findController) {
  4920. this.findController.setDocument(null);
  4921. }
  4922. if (this._scriptingManager) {
  4923. this._scriptingManager.setDocument(null);
  4924. }
  4925. }
  4926. this.pdfDocument = pdfDocument;
  4927. if (!pdfDocument) {
  4928. return;
  4929. }
  4930. const isPureXfa = pdfDocument.isPureXfa;
  4931. const pagesCount = pdfDocument.numPages;
  4932. const firstPagePromise = pdfDocument.getPage(1);
  4933. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  4934. this._pagesCapability.promise.then(() => {
  4935. this.eventBus.dispatch("pagesloaded", {
  4936. source: this,
  4937. pagesCount
  4938. });
  4939. });
  4940. this._onBeforeDraw = evt => {
  4941. const pageView = this._pages[evt.pageNumber - 1];
  4942. if (!pageView) {
  4943. return;
  4944. }
  4945. this._buffer.push(pageView);
  4946. };
  4947. this.eventBus._on("pagerender", this._onBeforeDraw);
  4948. this._onAfterDraw = evt => {
  4949. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  4950. return;
  4951. }
  4952. this._onePageRenderedCapability.resolve();
  4953. this.eventBus._off("pagerendered", this._onAfterDraw);
  4954. this._onAfterDraw = null;
  4955. };
  4956. this.eventBus._on("pagerendered", this._onAfterDraw);
  4957. firstPagePromise.then(firstPdfPage => {
  4958. this._firstPageCapability.resolve(firstPdfPage);
  4959. this._optionalContentConfigPromise = optionalContentConfigPromise;
  4960. const scale = this.currentScale;
  4961. const viewport = firstPdfPage.getViewport({
  4962. scale: scale * _ui_utils.CSS_UNITS
  4963. });
  4964. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
  4965. const xfaLayerFactory = isPureXfa ? this : null;
  4966. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  4967. const pageView = new _pdf_page_view.PDFPageView({
  4968. container: this._viewerElement,
  4969. eventBus: this.eventBus,
  4970. id: pageNum,
  4971. scale,
  4972. defaultViewport: viewport.clone(),
  4973. optionalContentConfigPromise,
  4974. renderingQueue: this.renderingQueue,
  4975. textLayerFactory,
  4976. textLayerMode: this.textLayerMode,
  4977. annotationLayerFactory: this,
  4978. xfaLayerFactory,
  4979. imageResourcesPath: this.imageResourcesPath,
  4980. renderInteractiveForms: this.renderInteractiveForms,
  4981. renderer: this.renderer,
  4982. enableWebGL: this.enableWebGL,
  4983. useOnlyCssZoom: this.useOnlyCssZoom,
  4984. maxCanvasPixels: this.maxCanvasPixels,
  4985. l10n: this.l10n,
  4986. enableScripting: this.enableScripting
  4987. });
  4988. this._pages.push(pageView);
  4989. }
  4990. const firstPageView = this._pages[0];
  4991. if (firstPageView) {
  4992. firstPageView.setPdfPage(firstPdfPage);
  4993. this.linkService.cachePageRef(1, firstPdfPage.ref);
  4994. }
  4995. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  4996. this._updateSpreadMode();
  4997. }
  4998. this._onePageRenderedOrForceFetch().then(() => {
  4999. if (this.findController) {
  5000. this.findController.setDocument(pdfDocument);
  5001. }
  5002. if (this.enableScripting) {
  5003. this._scriptingManager.setDocument(pdfDocument);
  5004. }
  5005. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > 7500) {
  5006. this._pagesCapability.resolve();
  5007. return;
  5008. }
  5009. let getPagesLeft = pagesCount - 1;
  5010. if (getPagesLeft <= 0) {
  5011. this._pagesCapability.resolve();
  5012. return;
  5013. }
  5014. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  5015. pdfDocument.getPage(pageNum).then(pdfPage => {
  5016. const pageView = this._pages[pageNum - 1];
  5017. if (!pageView.pdfPage) {
  5018. pageView.setPdfPage(pdfPage);
  5019. }
  5020. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  5021. if (--getPagesLeft === 0) {
  5022. this._pagesCapability.resolve();
  5023. }
  5024. }, reason => {
  5025. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  5026. if (--getPagesLeft === 0) {
  5027. this._pagesCapability.resolve();
  5028. }
  5029. });
  5030. }
  5031. });
  5032. this.eventBus.dispatch("pagesinit", {
  5033. source: this
  5034. });
  5035. if (this.defaultRenderingQueue) {
  5036. this.update();
  5037. }
  5038. }).catch(reason => {
  5039. console.error("Unable to initialize viewer", reason);
  5040. });
  5041. }
  5042. setPageLabels(labels) {
  5043. if (!this.pdfDocument) {
  5044. return;
  5045. }
  5046. if (!labels) {
  5047. this._pageLabels = null;
  5048. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  5049. this._pageLabels = null;
  5050. console.error(`${this._name}.setPageLabels: Invalid page labels.`);
  5051. } else {
  5052. this._pageLabels = labels;
  5053. }
  5054. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  5055. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  5056. }
  5057. }
  5058. _resetView() {
  5059. this._pages = [];
  5060. this._currentPageNumber = 1;
  5061. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  5062. this._currentScaleValue = null;
  5063. this._pageLabels = null;
  5064. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  5065. this._location = null;
  5066. this._pagesRotation = 0;
  5067. this._optionalContentConfigPromise = null;
  5068. this._pagesRequests = new WeakMap();
  5069. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  5070. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  5071. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  5072. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  5073. this._spreadMode = _ui_utils.SpreadMode.NONE;
  5074. if (this._onBeforeDraw) {
  5075. this.eventBus._off("pagerender", this._onBeforeDraw);
  5076. this._onBeforeDraw = null;
  5077. }
  5078. if (this._onAfterDraw) {
  5079. this.eventBus._off("pagerendered", this._onAfterDraw);
  5080. this._onAfterDraw = null;
  5081. }
  5082. this.viewer.textContent = "";
  5083. this._updateScrollMode();
  5084. }
  5085. _scrollUpdate() {
  5086. if (this.pagesCount === 0) {
  5087. return;
  5088. }
  5089. this.update();
  5090. }
  5091. _scrollIntoView({
  5092. pageDiv,
  5093. pageSpot = null,
  5094. pageNumber = null
  5095. }) {
  5096. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  5097. }
  5098. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  5099. this._currentScaleValue = newValue.toString();
  5100. if (isSameScale(this._currentScale, newScale)) {
  5101. if (preset) {
  5102. this.eventBus.dispatch("scalechanging", {
  5103. source: this,
  5104. scale: newScale,
  5105. presetValue: newValue
  5106. });
  5107. }
  5108. return;
  5109. }
  5110. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  5111. this._pages[i].update(newScale);
  5112. }
  5113. this._currentScale = newScale;
  5114. if (!noScroll) {
  5115. let page = this._currentPageNumber,
  5116. dest;
  5117. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  5118. page = this._location.pageNumber;
  5119. dest = [null, {
  5120. name: "XYZ"
  5121. }, this._location.left, this._location.top, null];
  5122. }
  5123. this.scrollPageIntoView({
  5124. pageNumber: page,
  5125. destArray: dest,
  5126. allowNegativeOffset: true
  5127. });
  5128. }
  5129. this.eventBus.dispatch("scalechanging", {
  5130. source: this,
  5131. scale: newScale,
  5132. presetValue: preset ? newValue : undefined
  5133. });
  5134. if (this.defaultRenderingQueue) {
  5135. this.update();
  5136. }
  5137. }
  5138. get _pageWidthScaleFactor() {
  5139. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL && !this.isInPresentationMode) {
  5140. return 2;
  5141. }
  5142. return 1;
  5143. }
  5144. _setScale(value, noScroll = false) {
  5145. let scale = parseFloat(value);
  5146. if (scale > 0) {
  5147. this._setScaleUpdatePages(scale, value, noScroll, false);
  5148. } else {
  5149. const currentPage = this._pages[this._currentPageNumber - 1];
  5150. if (!currentPage) {
  5151. return;
  5152. }
  5153. const noPadding = this.isInPresentationMode || this.removePageBorders;
  5154. let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
  5155. let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
  5156. if (!noPadding && this._isScrollModeHorizontal) {
  5157. [hPadding, vPadding] = [vPadding, hPadding];
  5158. }
  5159. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  5160. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  5161. switch (value) {
  5162. case "page-actual":
  5163. scale = 1;
  5164. break;
  5165. case "page-width":
  5166. scale = pageWidthScale;
  5167. break;
  5168. case "page-height":
  5169. scale = pageHeightScale;
  5170. break;
  5171. case "page-fit":
  5172. scale = Math.min(pageWidthScale, pageHeightScale);
  5173. break;
  5174. case "auto":
  5175. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  5176. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  5177. break;
  5178. default:
  5179. console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
  5180. return;
  5181. }
  5182. this._setScaleUpdatePages(scale, value, noScroll, true);
  5183. }
  5184. }
  5185. _resetCurrentPageView() {
  5186. if (this.isInPresentationMode) {
  5187. this._setScale(this._currentScaleValue, true);
  5188. }
  5189. const pageView = this._pages[this._currentPageNumber - 1];
  5190. this._scrollIntoView({
  5191. pageDiv: pageView.div
  5192. });
  5193. }
  5194. pageLabelToPageNumber(label) {
  5195. if (!this._pageLabels) {
  5196. return null;
  5197. }
  5198. const i = this._pageLabels.indexOf(label);
  5199. if (i < 0) {
  5200. return null;
  5201. }
  5202. return i + 1;
  5203. }
  5204. scrollPageIntoView({
  5205. pageNumber,
  5206. destArray = null,
  5207. allowNegativeOffset = false,
  5208. ignoreDestinationZoom = false
  5209. }) {
  5210. if (!this.pdfDocument) {
  5211. return;
  5212. }
  5213. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  5214. if (!pageView) {
  5215. console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5216. return;
  5217. }
  5218. if (this.isInPresentationMode || !destArray) {
  5219. this._setCurrentPageNumber(pageNumber, true);
  5220. return;
  5221. }
  5222. let x = 0,
  5223. y = 0;
  5224. let width = 0,
  5225. height = 0,
  5226. widthScale,
  5227. heightScale;
  5228. const changeOrientation = pageView.rotation % 180 !== 0;
  5229. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  5230. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  5231. let scale = 0;
  5232. switch (destArray[1].name) {
  5233. case "XYZ":
  5234. x = destArray[2];
  5235. y = destArray[3];
  5236. scale = destArray[4];
  5237. x = x !== null ? x : 0;
  5238. y = y !== null ? y : pageHeight;
  5239. break;
  5240. case "Fit":
  5241. case "FitB":
  5242. scale = "page-fit";
  5243. break;
  5244. case "FitH":
  5245. case "FitBH":
  5246. y = destArray[2];
  5247. scale = "page-width";
  5248. if (y === null && this._location) {
  5249. x = this._location.left;
  5250. y = this._location.top;
  5251. } else if (typeof y !== "number") {
  5252. y = pageHeight;
  5253. }
  5254. break;
  5255. case "FitV":
  5256. case "FitBV":
  5257. x = destArray[2];
  5258. width = pageWidth;
  5259. height = pageHeight;
  5260. scale = "page-height";
  5261. break;
  5262. case "FitR":
  5263. x = destArray[2];
  5264. y = destArray[3];
  5265. width = destArray[4] - x;
  5266. height = destArray[5] - y;
  5267. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  5268. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  5269. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  5270. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  5271. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  5272. break;
  5273. default:
  5274. console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
  5275. return;
  5276. }
  5277. if (!ignoreDestinationZoom) {
  5278. if (scale && scale !== this._currentScale) {
  5279. this.currentScaleValue = scale;
  5280. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  5281. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  5282. }
  5283. }
  5284. if (scale === "page-fit" && !destArray[4]) {
  5285. this._scrollIntoView({
  5286. pageDiv: pageView.div,
  5287. pageNumber
  5288. });
  5289. return;
  5290. }
  5291. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  5292. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  5293. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  5294. if (!allowNegativeOffset) {
  5295. left = Math.max(left, 0);
  5296. top = Math.max(top, 0);
  5297. }
  5298. this._scrollIntoView({
  5299. pageDiv: pageView.div,
  5300. pageSpot: {
  5301. left,
  5302. top
  5303. },
  5304. pageNumber
  5305. });
  5306. }
  5307. _updateLocation(firstPage) {
  5308. const currentScale = this._currentScale;
  5309. const currentScaleValue = this._currentScaleValue;
  5310. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  5311. const pageNumber = firstPage.id;
  5312. let pdfOpenParams = "#page=" + pageNumber;
  5313. pdfOpenParams += "&zoom=" + normalizedScaleValue;
  5314. const currentPageView = this._pages[pageNumber - 1];
  5315. const container = this.container;
  5316. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  5317. const intLeft = Math.round(topLeft[0]);
  5318. const intTop = Math.round(topLeft[1]);
  5319. pdfOpenParams += "," + intLeft + "," + intTop;
  5320. this._location = {
  5321. pageNumber,
  5322. scale: normalizedScaleValue,
  5323. top: intTop,
  5324. left: intLeft,
  5325. rotation: this._pagesRotation,
  5326. pdfOpenParams
  5327. };
  5328. }
  5329. _updateHelper(visiblePages) {
  5330. throw new Error("Not implemented: _updateHelper");
  5331. }
  5332. update() {
  5333. const visible = this._getVisiblePages();
  5334. const visiblePages = visible.views,
  5335. numVisiblePages = visiblePages.length;
  5336. if (numVisiblePages === 0) {
  5337. return;
  5338. }
  5339. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  5340. this._buffer.resize(newCacheSize, visiblePages);
  5341. this.renderingQueue.renderHighestPriority(visible);
  5342. this._updateHelper(visiblePages);
  5343. this._updateLocation(visible.first);
  5344. this.eventBus.dispatch("updateviewarea", {
  5345. source: this,
  5346. location: this._location
  5347. });
  5348. }
  5349. containsElement(element) {
  5350. return this.container.contains(element);
  5351. }
  5352. focus() {
  5353. this.container.focus();
  5354. }
  5355. get _isScrollModeHorizontal() {
  5356. return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
  5357. }
  5358. get _isContainerRtl() {
  5359. return getComputedStyle(this.container).direction === "rtl";
  5360. }
  5361. get isInPresentationMode() {
  5362. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  5363. }
  5364. get isChangingPresentationMode() {
  5365. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  5366. }
  5367. get isHorizontalScrollbarEnabled() {
  5368. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  5369. }
  5370. get isVerticalScrollbarEnabled() {
  5371. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  5372. }
  5373. _getCurrentVisiblePage() {
  5374. if (!this.pagesCount) {
  5375. return {
  5376. views: []
  5377. };
  5378. }
  5379. const pageView = this._pages[this._currentPageNumber - 1];
  5380. const element = pageView.div;
  5381. const view = {
  5382. id: pageView.id,
  5383. x: element.offsetLeft + element.clientLeft,
  5384. y: element.offsetTop + element.clientTop,
  5385. view: pageView
  5386. };
  5387. return {
  5388. first: view,
  5389. last: view,
  5390. views: [view]
  5391. };
  5392. }
  5393. _getVisiblePages() {
  5394. return (0, _ui_utils.getVisibleElements)({
  5395. scrollEl: this.container,
  5396. views: this._pages,
  5397. sortByVisibility: true,
  5398. horizontal: this._isScrollModeHorizontal,
  5399. rtl: this._isScrollModeHorizontal && this._isContainerRtl
  5400. });
  5401. }
  5402. isPageVisible(pageNumber) {
  5403. if (!this.pdfDocument) {
  5404. return false;
  5405. }
  5406. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  5407. console.error(`${this._name}.isPageVisible: "${pageNumber}" is not a valid page.`);
  5408. return false;
  5409. }
  5410. return this._getVisiblePages().views.some(function (view) {
  5411. return view.id === pageNumber;
  5412. });
  5413. }
  5414. isPageCached(pageNumber) {
  5415. if (!this.pdfDocument || !this._buffer) {
  5416. return false;
  5417. }
  5418. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  5419. console.error(`${this._name}.isPageCached: "${pageNumber}" is not a valid page.`);
  5420. return false;
  5421. }
  5422. const pageView = this._pages[pageNumber - 1];
  5423. if (!pageView) {
  5424. return false;
  5425. }
  5426. return this._buffer.has(pageView);
  5427. }
  5428. cleanup() {
  5429. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  5430. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  5431. this._pages[i].reset();
  5432. }
  5433. }
  5434. }
  5435. _cancelRendering() {
  5436. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  5437. if (this._pages[i]) {
  5438. this._pages[i].cancelRendering();
  5439. }
  5440. }
  5441. }
  5442. _ensurePdfPageLoaded(pageView) {
  5443. if (pageView.pdfPage) {
  5444. return Promise.resolve(pageView.pdfPage);
  5445. }
  5446. if (this._pagesRequests.has(pageView)) {
  5447. return this._pagesRequests.get(pageView);
  5448. }
  5449. const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
  5450. if (!pageView.pdfPage) {
  5451. pageView.setPdfPage(pdfPage);
  5452. }
  5453. this._pagesRequests.delete(pageView);
  5454. return pdfPage;
  5455. }).catch(reason => {
  5456. console.error("Unable to get page for page view", reason);
  5457. this._pagesRequests.delete(pageView);
  5458. });
  5459. this._pagesRequests.set(pageView, promise);
  5460. return promise;
  5461. }
  5462. forceRendering(currentlyVisiblePages) {
  5463. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  5464. const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
  5465. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
  5466. if (pageView) {
  5467. this._ensurePdfPageLoaded(pageView).then(() => {
  5468. this.renderingQueue.renderView(pageView);
  5469. });
  5470. return true;
  5471. }
  5472. return false;
  5473. }
  5474. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  5475. return new _text_layer_builder.TextLayerBuilder({
  5476. textLayerDiv,
  5477. eventBus,
  5478. pageIndex,
  5479. viewport,
  5480. findController: this.isInPresentationMode ? null : this.findController,
  5481. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  5482. });
  5483. }
  5484. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = false, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
  5485. return new _annotation_layer_builder.AnnotationLayerBuilder({
  5486. pageDiv,
  5487. pdfPage,
  5488. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  5489. imageResourcesPath,
  5490. renderInteractiveForms,
  5491. linkService: this.linkService,
  5492. downloadManager: this.downloadManager,
  5493. l10n,
  5494. enableScripting,
  5495. hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
  5496. mouseState: mouseState || this._scriptingManager?.mouseState
  5497. });
  5498. }
  5499. createXfaLayerBuilder(pageDiv, pdfPage) {
  5500. return new _xfa_layer_builder.XfaLayerBuilder({
  5501. pageDiv,
  5502. pdfPage
  5503. });
  5504. }
  5505. get hasEqualPageSizes() {
  5506. const firstPageView = this._pages[0];
  5507. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  5508. const pageView = this._pages[i];
  5509. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  5510. return false;
  5511. }
  5512. }
  5513. return true;
  5514. }
  5515. getPagesOverview() {
  5516. return this._pages.map(pageView => {
  5517. const viewport = pageView.pdfPage.getViewport({
  5518. scale: 1
  5519. });
  5520. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  5521. return {
  5522. width: viewport.width,
  5523. height: viewport.height,
  5524. rotation: viewport.rotation
  5525. };
  5526. }
  5527. return {
  5528. width: viewport.height,
  5529. height: viewport.width,
  5530. rotation: (viewport.rotation - 90) % 360
  5531. };
  5532. });
  5533. }
  5534. get optionalContentConfigPromise() {
  5535. if (!this.pdfDocument) {
  5536. return Promise.resolve(null);
  5537. }
  5538. if (!this._optionalContentConfigPromise) {
  5539. return this.pdfDocument.getOptionalContentConfig();
  5540. }
  5541. return this._optionalContentConfigPromise;
  5542. }
  5543. set optionalContentConfigPromise(promise) {
  5544. if (!(promise instanceof Promise)) {
  5545. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  5546. }
  5547. if (!this.pdfDocument) {
  5548. return;
  5549. }
  5550. if (!this._optionalContentConfigPromise) {
  5551. return;
  5552. }
  5553. this._optionalContentConfigPromise = promise;
  5554. for (const pageView of this._pages) {
  5555. pageView.update(pageView.scale, pageView.rotation, promise);
  5556. }
  5557. this.update();
  5558. this.eventBus.dispatch("optionalcontentconfigchanged", {
  5559. source: this,
  5560. promise
  5561. });
  5562. }
  5563. get scrollMode() {
  5564. return this._scrollMode;
  5565. }
  5566. set scrollMode(mode) {
  5567. if (this._scrollMode === mode) {
  5568. return;
  5569. }
  5570. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  5571. throw new Error(`Invalid scroll mode: ${mode}`);
  5572. }
  5573. this._scrollMode = mode;
  5574. this.eventBus.dispatch("scrollmodechanged", {
  5575. source: this,
  5576. mode
  5577. });
  5578. this._updateScrollMode(this._currentPageNumber);
  5579. }
  5580. _updateScrollMode(pageNumber = null) {
  5581. const scrollMode = this._scrollMode,
  5582. viewer = this.viewer;
  5583. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  5584. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  5585. if (!this.pdfDocument || !pageNumber) {
  5586. return;
  5587. }
  5588. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  5589. this._setScale(this._currentScaleValue, true);
  5590. }
  5591. this._setCurrentPageNumber(pageNumber, true);
  5592. this.update();
  5593. }
  5594. get spreadMode() {
  5595. return this._spreadMode;
  5596. }
  5597. set spreadMode(mode) {
  5598. if (this._spreadMode === mode) {
  5599. return;
  5600. }
  5601. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  5602. throw new Error(`Invalid spread mode: ${mode}`);
  5603. }
  5604. this._spreadMode = mode;
  5605. this.eventBus.dispatch("spreadmodechanged", {
  5606. source: this,
  5607. mode
  5608. });
  5609. this._updateSpreadMode(this._currentPageNumber);
  5610. }
  5611. _updateSpreadMode(pageNumber = null) {
  5612. if (!this.pdfDocument) {
  5613. return;
  5614. }
  5615. const viewer = this.viewer,
  5616. pages = this._pages;
  5617. viewer.textContent = "";
  5618. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  5619. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  5620. viewer.appendChild(pages[i].div);
  5621. }
  5622. } else {
  5623. const parity = this._spreadMode - 1;
  5624. let spread = null;
  5625. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  5626. if (spread === null) {
  5627. spread = document.createElement("div");
  5628. spread.className = "spread";
  5629. viewer.appendChild(spread);
  5630. } else if (i % 2 === parity) {
  5631. spread = spread.cloneNode(false);
  5632. viewer.appendChild(spread);
  5633. }
  5634. spread.appendChild(pages[i].div);
  5635. }
  5636. }
  5637. if (!pageNumber) {
  5638. return;
  5639. }
  5640. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  5641. this._setScale(this._currentScaleValue, true);
  5642. }
  5643. this._setCurrentPageNumber(pageNumber, true);
  5644. this.update();
  5645. }
  5646. _getPageAdvance(currentPageNumber, previous = false) {
  5647. if (this.isInPresentationMode) {
  5648. return 1;
  5649. }
  5650. switch (this._scrollMode) {
  5651. case _ui_utils.ScrollMode.WRAPPED:
  5652. {
  5653. const {
  5654. views
  5655. } = this._getVisiblePages(),
  5656. pageLayout = new Map();
  5657. for (const {
  5658. id,
  5659. y,
  5660. percent,
  5661. widthPercent
  5662. } of views) {
  5663. if (percent === 0 || widthPercent < 100) {
  5664. continue;
  5665. }
  5666. let yArray = pageLayout.get(y);
  5667. if (!yArray) {
  5668. pageLayout.set(y, yArray || (yArray = []));
  5669. }
  5670. yArray.push(id);
  5671. }
  5672. for (const yArray of pageLayout.values()) {
  5673. const currentIndex = yArray.indexOf(currentPageNumber);
  5674. if (currentIndex === -1) {
  5675. continue;
  5676. }
  5677. const numPages = yArray.length;
  5678. if (numPages === 1) {
  5679. break;
  5680. }
  5681. if (previous) {
  5682. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  5683. const currentId = yArray[i],
  5684. expectedId = yArray[i + 1] - 1;
  5685. if (currentId < expectedId) {
  5686. return currentPageNumber - expectedId;
  5687. }
  5688. }
  5689. } else {
  5690. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  5691. const currentId = yArray[i],
  5692. expectedId = yArray[i - 1] + 1;
  5693. if (currentId > expectedId) {
  5694. return expectedId - currentPageNumber;
  5695. }
  5696. }
  5697. }
  5698. if (previous) {
  5699. const firstId = yArray[0];
  5700. if (firstId < currentPageNumber) {
  5701. return currentPageNumber - firstId + 1;
  5702. }
  5703. } else {
  5704. const lastId = yArray[numPages - 1];
  5705. if (lastId > currentPageNumber) {
  5706. return lastId - currentPageNumber + 1;
  5707. }
  5708. }
  5709. break;
  5710. }
  5711. break;
  5712. }
  5713. case _ui_utils.ScrollMode.HORIZONTAL:
  5714. {
  5715. break;
  5716. }
  5717. case _ui_utils.ScrollMode.VERTICAL:
  5718. {
  5719. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  5720. break;
  5721. }
  5722. const parity = this._spreadMode - 1;
  5723. if (previous && currentPageNumber % 2 !== parity) {
  5724. break;
  5725. } else if (!previous && currentPageNumber % 2 === parity) {
  5726. break;
  5727. }
  5728. const {
  5729. views
  5730. } = this._getVisiblePages(),
  5731. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  5732. for (const {
  5733. id,
  5734. percent,
  5735. widthPercent
  5736. } of views) {
  5737. if (id !== expectedId) {
  5738. continue;
  5739. }
  5740. if (percent > 0 && widthPercent === 100) {
  5741. return 2;
  5742. }
  5743. break;
  5744. }
  5745. break;
  5746. }
  5747. }
  5748. return 1;
  5749. }
  5750. nextPage() {
  5751. const currentPageNumber = this._currentPageNumber,
  5752. pagesCount = this.pagesCount;
  5753. if (currentPageNumber >= pagesCount) {
  5754. return false;
  5755. }
  5756. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  5757. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  5758. return true;
  5759. }
  5760. previousPage() {
  5761. const currentPageNumber = this._currentPageNumber;
  5762. if (currentPageNumber <= 1) {
  5763. return false;
  5764. }
  5765. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  5766. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  5767. return true;
  5768. }
  5769. }
  5770. exports.BaseViewer = BaseViewer;
  5771. /***/ }),
  5772. /* 20 */
  5773. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5774. Object.defineProperty(exports, "__esModule", ({
  5775. value: true
  5776. }));
  5777. exports.XfaLayerBuilder = exports.DefaultXfaLayerFactory = void 0;
  5778. var _pdfjsLib = __w_pdfjs_require__(2);
  5779. class XfaLayerBuilder {
  5780. constructor({
  5781. pageDiv,
  5782. pdfPage
  5783. }) {
  5784. this.pageDiv = pageDiv;
  5785. this.pdfPage = pdfPage;
  5786. this.div = null;
  5787. this._cancelled = false;
  5788. }
  5789. render(viewport, intent = "display") {
  5790. return this.pdfPage.getXfa().then(xfa => {
  5791. if (this._cancelled) {
  5792. return;
  5793. }
  5794. const parameters = {
  5795. viewport: viewport.clone({
  5796. dontFlip: true
  5797. }),
  5798. div: this.div,
  5799. xfa,
  5800. page: this.pdfPage
  5801. };
  5802. if (this.div) {
  5803. _pdfjsLib.XfaLayer.update(parameters);
  5804. } else {
  5805. this.div = document.createElement("div");
  5806. this.pageDiv.appendChild(this.div);
  5807. parameters.div = this.div;
  5808. _pdfjsLib.XfaLayer.render(parameters);
  5809. }
  5810. });
  5811. }
  5812. cancel() {
  5813. this._cancelled = true;
  5814. }
  5815. hide() {
  5816. if (!this.div) {
  5817. return;
  5818. }
  5819. this.div.hidden = true;
  5820. }
  5821. }
  5822. exports.XfaLayerBuilder = XfaLayerBuilder;
  5823. class DefaultXfaLayerFactory {
  5824. createXfaLayerBuilder(pageDiv, pdfPage) {
  5825. return new XfaLayerBuilder({
  5826. pageDiv,
  5827. pdfPage
  5828. });
  5829. }
  5830. }
  5831. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
  5832. /***/ }),
  5833. /* 21 */
  5834. /***/ ((__unused_webpack_module, exports, __w_pdfjs_require__) => {
  5835. Object.defineProperty(exports, "__esModule", ({
  5836. value: true
  5837. }));
  5838. exports.PDFViewer = void 0;
  5839. var _ui_utils = __w_pdfjs_require__(5);
  5840. var _base_viewer = __w_pdfjs_require__(19);
  5841. var _pdfjsLib = __w_pdfjs_require__(2);
  5842. class PDFViewer extends _base_viewer.BaseViewer {
  5843. get _viewerElement() {
  5844. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this.viewer);
  5845. }
  5846. _scrollIntoView({
  5847. pageDiv,
  5848. pageSpot = null,
  5849. pageNumber = null
  5850. }) {
  5851. if (!pageSpot && !this.isInPresentationMode) {
  5852. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  5853. const right = left + pageDiv.clientWidth;
  5854. const {
  5855. scrollLeft,
  5856. clientWidth
  5857. } = this.container;
  5858. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  5859. pageSpot = {
  5860. left: 0,
  5861. top: 0
  5862. };
  5863. }
  5864. }
  5865. super._scrollIntoView({
  5866. pageDiv,
  5867. pageSpot,
  5868. pageNumber
  5869. });
  5870. }
  5871. _getVisiblePages() {
  5872. if (this.isInPresentationMode) {
  5873. return this._getCurrentVisiblePage();
  5874. }
  5875. return super._getVisiblePages();
  5876. }
  5877. _updateHelper(visiblePages) {
  5878. if (this.isInPresentationMode) {
  5879. return;
  5880. }
  5881. let currentId = this._currentPageNumber;
  5882. let stillFullyVisible = false;
  5883. for (const page of visiblePages) {
  5884. if (page.percent < 100) {
  5885. break;
  5886. }
  5887. if (page.id === currentId && this._scrollMode === _ui_utils.ScrollMode.VERTICAL && this._spreadMode === _ui_utils.SpreadMode.NONE) {
  5888. stillFullyVisible = true;
  5889. break;
  5890. }
  5891. }
  5892. if (!stillFullyVisible) {
  5893. currentId = visiblePages[0].id;
  5894. }
  5895. this._setCurrentPageNumber(currentId);
  5896. }
  5897. }
  5898. exports.PDFViewer = PDFViewer;
  5899. /***/ })
  5900. /******/ ]);
  5901. /************************************************************************/
  5902. /******/ // The module cache
  5903. /******/ var __webpack_module_cache__ = {};
  5904. /******/
  5905. /******/ // The require function
  5906. /******/ function __w_pdfjs_require__(moduleId) {
  5907. /******/ // Check if module is in cache
  5908. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  5909. /******/ if (cachedModule !== undefined) {
  5910. /******/ return cachedModule.exports;
  5911. /******/ }
  5912. /******/ // Create a new module (and put it into the cache)
  5913. /******/ var module = __webpack_module_cache__[moduleId] = {
  5914. /******/ // no module.id needed
  5915. /******/ // no module.loaded needed
  5916. /******/ exports: {}
  5917. /******/ };
  5918. /******/
  5919. /******/ // Execute the module function
  5920. /******/ __webpack_modules__[moduleId](module, module.exports, __w_pdfjs_require__);
  5921. /******/
  5922. /******/ // Return the exports of the module
  5923. /******/ return module.exports;
  5924. /******/ }
  5925. /******/
  5926. /************************************************************************/
  5927. var __webpack_exports__ = {};
  5928. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  5929. (() => {
  5930. var exports = __webpack_exports__;
  5931. Object.defineProperty(exports, "__esModule", ({
  5932. value: true
  5933. }));
  5934. Object.defineProperty(exports, "AnnotationLayerBuilder", ({
  5935. enumerable: true,
  5936. get: function () {
  5937. return _annotation_layer_builder.AnnotationLayerBuilder;
  5938. }
  5939. }));
  5940. Object.defineProperty(exports, "DefaultAnnotationLayerFactory", ({
  5941. enumerable: true,
  5942. get: function () {
  5943. return _annotation_layer_builder.DefaultAnnotationLayerFactory;
  5944. }
  5945. }));
  5946. Object.defineProperty(exports, "DefaultTextLayerFactory", ({
  5947. enumerable: true,
  5948. get: function () {
  5949. return _text_layer_builder.DefaultTextLayerFactory;
  5950. }
  5951. }));
  5952. Object.defineProperty(exports, "TextLayerBuilder", ({
  5953. enumerable: true,
  5954. get: function () {
  5955. return _text_layer_builder.TextLayerBuilder;
  5956. }
  5957. }));
  5958. Object.defineProperty(exports, "EventBus", ({
  5959. enumerable: true,
  5960. get: function () {
  5961. return _ui_utils.EventBus;
  5962. }
  5963. }));
  5964. Object.defineProperty(exports, "ProgressBar", ({
  5965. enumerable: true,
  5966. get: function () {
  5967. return _ui_utils.ProgressBar;
  5968. }
  5969. }));
  5970. Object.defineProperty(exports, "PDFLinkService", ({
  5971. enumerable: true,
  5972. get: function () {
  5973. return _pdf_link_service.PDFLinkService;
  5974. }
  5975. }));
  5976. Object.defineProperty(exports, "SimpleLinkService", ({
  5977. enumerable: true,
  5978. get: function () {
  5979. return _pdf_link_service.SimpleLinkService;
  5980. }
  5981. }));
  5982. Object.defineProperty(exports, "DownloadManager", ({
  5983. enumerable: true,
  5984. get: function () {
  5985. return _download_manager.DownloadManager;
  5986. }
  5987. }));
  5988. Object.defineProperty(exports, "GenericL10n", ({
  5989. enumerable: true,
  5990. get: function () {
  5991. return _genericl10n.GenericL10n;
  5992. }
  5993. }));
  5994. Object.defineProperty(exports, "NullL10n", ({
  5995. enumerable: true,
  5996. get: function () {
  5997. return _l10n_utils.NullL10n;
  5998. }
  5999. }));
  6000. Object.defineProperty(exports, "PDFFindController", ({
  6001. enumerable: true,
  6002. get: function () {
  6003. return _pdf_find_controller.PDFFindController;
  6004. }
  6005. }));
  6006. Object.defineProperty(exports, "PDFHistory", ({
  6007. enumerable: true,
  6008. get: function () {
  6009. return _pdf_history.PDFHistory;
  6010. }
  6011. }));
  6012. Object.defineProperty(exports, "PDFPageView", ({
  6013. enumerable: true,
  6014. get: function () {
  6015. return _pdf_page_view.PDFPageView;
  6016. }
  6017. }));
  6018. Object.defineProperty(exports, "PDFScriptingManager", ({
  6019. enumerable: true,
  6020. get: function () {
  6021. return _pdf_scripting_manager.PDFScriptingManager;
  6022. }
  6023. }));
  6024. Object.defineProperty(exports, "PDFSinglePageViewer", ({
  6025. enumerable: true,
  6026. get: function () {
  6027. return _pdf_single_page_viewer.PDFSinglePageViewer;
  6028. }
  6029. }));
  6030. Object.defineProperty(exports, "PDFViewer", ({
  6031. enumerable: true,
  6032. get: function () {
  6033. return _pdf_viewer.PDFViewer;
  6034. }
  6035. }));
  6036. var _annotation_layer_builder = __w_pdfjs_require__(1);
  6037. var _text_layer_builder = __w_pdfjs_require__(6);
  6038. var _ui_utils = __w_pdfjs_require__(5);
  6039. var _pdf_link_service = __w_pdfjs_require__(4);
  6040. var _download_manager = __w_pdfjs_require__(7);
  6041. var _genericl10n = __w_pdfjs_require__(9);
  6042. var _l10n_utils = __w_pdfjs_require__(3);
  6043. var _pdf_find_controller = __w_pdfjs_require__(11);
  6044. var _pdf_history = __w_pdfjs_require__(13);
  6045. var _pdf_page_view = __w_pdfjs_require__(14);
  6046. var _pdf_scripting_manager = __w_pdfjs_require__(16);
  6047. var _pdf_single_page_viewer = __w_pdfjs_require__(18);
  6048. var _pdf_viewer = __w_pdfjs_require__(21);
  6049. const pdfjsVersion = '2.8.335';
  6050. const pdfjsBuild = '228adbf67';
  6051. })();
  6052. /******/ return __webpack_exports__;
  6053. /******/ })()
  6054. ;
  6055. });
  6056. //# sourceMappingURL=pdf_viewer.js.map